1 //===- EhFrameHdr.h -------------------------------------------------------===//
2 //
3 //                     The MCLinker Project
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #ifndef MCLD_LD_EHFRAMEHDR_H_
10 #define MCLD_LD_EHFRAMEHDR_H_
11 #include "mcld/ADT/SizeTraits.h"
12 #include "mcld/LD/EhFrame.h"
13 #include "mcld/Support/FileOutputBuffer.h"
14 
15 #include <cassert>
16 namespace mcld {
17 
18 class LDSection;
19 class FileOutputBuffer;
20 
21 /** \class EhFrameHdr
22  *  \brief EhFrameHdr represents .eh_frame_hdr section.
23  *
24  *  @ref lsb core generic 4.1
25  *  .eh_frame_hdr section format
26  *  uint8_t : version
27  *  uint8_t : eh_frame_ptr_enc
28  *  uint8_t : fde_count_enc
29  *  uint8_t : table_enc
30  *  uint32_t : eh_frame_ptr
31  *  uint32_t : fde_count
32  *  __________________________ when fde_count > 0
33  *  <uint32_t, uint32_t>+ : binary search table
34  */
35 class EhFrameHdr {
36  public:
37   EhFrameHdr(LDSection& pEhFrameHdr, const LDSection& pEhFrame);
38 
39   ~EhFrameHdr();
40 
41   /// sizeOutput - base on the fde count to size output
42   void sizeOutput();
43 
44   /// emitOutput - write out eh_frame_hdr
45   template <size_t size>
emitOutput(FileOutputBuffer & pOutput)46   void emitOutput(FileOutputBuffer& pOutput) {
47     assert(false && "Call invalid EhFrameHdr::emitOutput");
48   }
49 
50  private:
51   /// computePCBegin - return the address of FDE's pc
52   uint32_t computePCBegin(const EhFrame::FDE& pFDE,
53                           const MemoryRegion& pEhFrameRegion);
54 
55  private:
56   /// .eh_frame_hdr section
57   LDSection& m_EhFrameHdr;
58 
59   /// eh_frame
60   const LDSection& m_EhFrame;
61 };
62 
63 //===----------------------------------------------------------------------===//
64 // Template Specification Functions
65 //===----------------------------------------------------------------------===//
66 /// emitOutput - write out eh_frame_hdr
67 template <>
68 void EhFrameHdr::emitOutput<32>(FileOutputBuffer& pOutput);
69 
70 }  // namespace mcld
71 
72 #endif  // MCLD_LD_EHFRAMEHDR_H_
73