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 <cassert>
13 
14 #include <mcld/LD/EhFrame.h>
15 #include <mcld/Support/FileOutputBuffer.h>
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 {
37 public:
38   EhFrameHdr(LDSection& pEhFrameHdr, const LDSection& pEhFrame);
39 
40   ~EhFrameHdr();
41 
42   /// sizeOutput - base on the fde count to size output
43   void sizeOutput();
44 
45   /// emitOutput - write out eh_frame_hdr
46   template<size_t size>
emitOutput(FileOutputBuffer & pOutput)47   void emitOutput(FileOutputBuffer& pOutput)
48   { assert(false && "Call invalid EhFrameHdr::emitOutput"); }
49 
50 private:
51   /// computePCBegin - return the address of FDE's pc
52   /// @ref binutils gold: ehframe.cc:222
53   uint32_t computePCBegin(const EhFrame::FDE& pFDE,
54                           const MemoryRegion& pEhFrameRegion);
55 
56 private:
57   /// .eh_frame_hdr section
58   LDSection& m_EhFrameHdr;
59 
60   /// eh_frame
61   const LDSection& m_EhFrame;
62 };
63 
64 //===----------------------------------------------------------------------===//
65 // Template Specification Functions
66 //===----------------------------------------------------------------------===//
67 /// emitOutput - write out eh_frame_hdr
68 template<>
69 void EhFrameHdr::emitOutput<32>(FileOutputBuffer& pOutput);
70 
71 } // namespace of mcld
72 
73 #endif
74 
75