Home | History | Annotate | Download | only in LD
      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_EHFRAMEHDR_H
     10 #define MCLD_EHFRAMEHDR_H
     11 #ifdef ENABLE_UNITTEST
     12 #include <gtest.h>
     13 #endif
     14 #include <mcld/ADT/SizeTraits.h>
     15 #include <cassert>
     16 
     17 #include <mcld/LD/EhFrame.h>
     18 namespace mcld {
     19 
     20 class LDSection;
     21 class MemoryArea;
     22 class MemoryRegion;
     23 
     24 /** \class EhFrameHdr
     25  *  \brief EhFrameHdr represents .eh_frame_hdr section.
     26  *
     27  *  @ref lsb core generic 4.1
     28  *  .eh_frame_hdr section format
     29  *  uint8_t : version
     30  *  uint8_t : eh_frame_ptr_enc
     31  *  uint8_t : fde_count_enc
     32  *  uint8_t : table_enc
     33  *  uint32_t : eh_frame_ptr
     34  *  uint32_t : fde_count
     35  *  __________________________ when fde_count > 0
     36  *  <uint32_t, uint32_t>+ : binary search table
     37  */
     38 class EhFrameHdr
     39 {
     40 public:
     41   EhFrameHdr(LDSection& pEhFrameHdr, const LDSection& pEhFrame);
     42 
     43   ~EhFrameHdr();
     44 
     45   /// sizeOutput - base on the fde count to size output
     46   void sizeOutput();
     47 
     48   /// emitOutput - write out eh_frame_hdr
     49   template<size_t size>
     50   void emitOutput(MemoryArea& pOutput)
     51   { assert(false && "Call invalid EhFrameHdr::emitOutput"); }
     52 
     53 private:
     54   /// computePCBegin - return the address of FDE's pc
     55   /// @ref binutils gold: ehframe.cc:222
     56   uint32_t computePCBegin(const EhFrame::FDE& pFDE, const MemoryRegion& pEhFrameRegion);
     57 
     58 private:
     59   /// .eh_frame_hdr section
     60   LDSection& m_EhFrameHdr;
     61 
     62   /// eh_frame
     63   const LDSection& m_EhFrame;
     64 };
     65 
     66 //===----------------------------------------------------------------------===//
     67 // Template Specification Functions
     68 //===----------------------------------------------------------------------===//
     69 /// emitOutput - write out eh_frame_hdr
     70 template<>
     71 void EhFrameHdr::emitOutput<32>(MemoryArea& pOutput);
     72 
     73 } // namespace of mcld
     74 
     75 #endif
     76 
     77