EhFrame.h revision affc150dc44fab1911775a49636d0ce85333b634
1//===- EhFrame.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_EXCEPTION_HANDLING_FRAME_H 10#define MCLD_EXCEPTION_HANDLING_FRAME_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14#include <vector> 15 16#include <mcld/ADT/TypeTraits.h> 17#include <mcld/LD/CIE.h> 18#include <mcld/LD/FDE.h> 19#include <mcld/MC/MCRegionFragment.h> 20#include <mcld/Support/GCFactory.h> 21 22namespace mcld 23{ 24/** \class EhFrame 25 * \brief EhFrame represents .eh_frame section 26 * EhFrame is responsible to parse the input eh_frame sections and create 27 * the corresponding CIE and FDE entries. 28 */ 29 30class TargetLDBackend; 31 32class EhFrame 33{ 34public: 35 typedef ConstTraits<unsigned char>::pointer ConstAddress; 36 typedef std::vector<CIE*> CIEListType; 37 typedef std::vector<FDE*> FDEListType; 38 typedef CIEListType::iterator cie_iterator; 39 typedef CIEListType::const_iterator const_cie_iterator; 40 typedef FDEListType::iterator fde_iterator; 41 typedef FDEListType::const_iterator const_fde_iterator; 42 43public: 44 EhFrame(); 45 ~EhFrame(); 46 47 /// readEhFrame - read an .eh_frame section and create the corresponding 48 /// CIEs and FDEs 49 /// @param pSD - the MCSectionData of this input eh_frame 50 /// @param pSection - the input eh_frame 51 /// @param pArea - the memory area which pSection is within. 52 /// @ return - size of this eh_frame section, 0 if we do not recognize 53 /// this eh_frame or this is an empty section 54 uint64_t readEhFrame(Layout& pLayout, 55 const TargetLDBackend& pBackend, 56 llvm::MCSectionData& pSD, 57 LDSection& pSection, 58 MemoryArea& pArea); 59 60 // ----- observers ----- // 61 cie_iterator cie_begin() 62 { return m_CIEs.begin(); } 63 64 const_cie_iterator cie_begin() const 65 { return m_CIEs.begin(); } 66 67 cie_iterator cie_end() 68 { return m_CIEs.end(); } 69 70 const_cie_iterator cie_end() const 71 { return m_CIEs.end(); } 72 73 fde_iterator fde_begin() 74 { return m_FDEs.begin(); } 75 76 const_fde_iterator fde_begin() const 77 { return m_FDEs.begin(); } 78 79 fde_iterator fde_end() 80 { return m_FDEs.end(); } 81 82 const_fde_iterator fde_end() const 83 { return m_FDEs.end(); } 84 85 /// getFDECount - the number of FDE entries 86 size_t getFDECount() 87 { return m_FDEs.size(); } 88 89 size_t getFDECount() const 90 { return m_FDEs.size(); } 91 92 /// canRecognizeAllEhFrame - return if we are able to parse all input 93 /// eh_frame sections 94 /// @return false - if there is any input .eh_frame section that 95 /// we are not able to recognize 96 bool canRecognizeAllEhFrame() 97 { return m_fCanRecognizeAll; } 98 99 bool canRecognizeAllEhFrame() const 100 { return m_fCanRecognizeAll; } 101 102private: 103 typedef std::vector<llvm::MCFragment*> FragListType; 104 105private: 106 /// addCIE - parse and create a CIE entry 107 /// @return false - cannot recognize this CIE 108 bool addCIE(MemoryRegion& pFrag, 109 const TargetLDBackend& pBackend, 110 FragListType& pFragList); 111 112 /// addFDE - parse and create an FDE entry 113 /// @return false - cannot recognize this FDE 114 bool addFDE(MemoryRegion& pFrag, 115 const TargetLDBackend& pBackend, 116 FragListType& pFragList); 117 118 /// readVal - read a 32 bit data from pAddr, swap it if needed 119 uint32_t readVal(ConstAddress pAddr, bool pIsTargetLittleEndian); 120 121 /// skipLEB128 - skip the first LEB128 encoded value from *pp, update *pp 122 /// to the next character. 123 /// @return - false if we ran off the end of the string. 124 /// @ref - GNU gold 1.11, ehframe.h, Eh_frame::skip_leb128. 125 bool skipLEB128(ConstAddress* pp, ConstAddress pend); 126 127 /// deleteFragments - release the MemoryRegion and delete MCFragments in pList 128 void deleteFragments(FragListType& pList, MemoryArea& pArea); 129 130private: 131 CIEListType m_CIEs; 132 FDEListType m_FDEs; 133 134 bool m_fCanRecognizeAll; 135}; 136 137} // namespace of mcld 138 139#endif 140 141