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 <llvm/Support/Dwarf.h> 15#include <llvm/Support/DataTypes.h> 16#include <mcld/ADT/SizeTraits.h> 17#include <mcld/Support/MemoryArea.h> 18#include <mcld/Support/MemoryRegion.h> 19#include <mcld/MC/MCLDOutput.h> 20#include <mcld/MC/MCLinker.h> 21#include <mcld/LD/EhFrame.h> 22#include <mcld/LD/LDSection.h> 23#include <mcld/LD/CIE.h> 24#include <mcld/LD/FDE.h> 25#include <mcld/LD/Layout.h> 26 27namespace mcld 28{ 29class EhFrame; 30class LDSection; 31class Output; 32class FDE; 33class MCLinker; 34 35/** \class EhFrameHdr 36 * \brief EhFrameHdr represents .eh_frame_hdr section. 37 */ 38class EhFrameHdr 39{ 40public: 41 EhFrameHdr(const EhFrame& pEhFrameData, 42 const LDSection& pEhFrameSect, 43 LDSection& pEhFrameHdrSect); 44 45 ~EhFrameHdr(); 46 47 /// sizeOutput - base on the fde count to size output 48 void sizeOutput(); 49 50 /// emitOutput - write out eh_frame_hdr 51 template<size_t size> 52 void emitOutput(Output& pOutput, MCLinker& pLinker); 53 54private: 55 /// getFDEPC - return the address of FDE's pc 56 /// @param pFDE - FDE 57 /// @param pOffset - the output offset of FDE 58 template<size_t size> 59 typename SizeTraits<size>::Address 60 getFDEPC(const FDE& pFDE, 61 typename SizeTraits<size>::Offset pOffset, 62 const MemoryRegion& pEhFrameRegion); 63 64 template<size_t size> 65 class BSTEntry 66 { 67 public: 68 typedef std::pair<typename SizeTraits<size>::Address, 69 typename SizeTraits<size>::Address> EntryType; 70 }; 71 72 template<size_t size> 73 struct BSTEntryCompare 74 : public std::binary_function<const typename BSTEntry<size>::EntryType&, 75 const typename BSTEntry<size>::EntryType&, 76 bool> 77 { 78 bool operator()(const typename BSTEntry<size>::EntryType& X, 79 const typename BSTEntry<size>::EntryType& Y) const 80 { return X.first < Y.first; } 81 }; 82 83private: 84 /// eh_frame data 85 const EhFrame& m_EhFrameData; 86 87 /// .eh_frame section 88 const LDSection& m_EhFrameSect; 89 90 /// .eh_frame_hdr section 91 LDSection& m_EhFrameHdrSect; 92}; 93 94#include "EhFrameHdr.tcc" 95 96} // namespace of mcld 97 98#endif 99 100