PLT.h revision 22add6ff3426df1a85089fe6a6e1597ee3b6f300
1//===- PLT.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_PROCEDURE_LINKAGE_TABLE_H 10#define MCLD_PROCEDURE_LINKAGE_TABLE_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14 15#include <mcld/LD/LDSection.h> 16#include <mcld/LD/SectionData.h> 17#include <mcld/Fragment/TargetFragment.h> 18 19namespace mcld { 20 21class LDSection; 22class ResolveInfo; 23 24/** \class PLT 25 * \brief Procedure linkage table 26 */ 27class PLT 28{ 29public: 30 typedef SectionData::iterator iterator; 31 typedef SectionData::const_iterator const_iterator; 32 33 class Entry : public TargetFragment 34 { 35 public: 36 Entry(size_t pSize, SectionData& pParent); 37 virtual ~Entry(); 38 39 size_t getEntrySize() const 40 { return m_EntrySize; } 41 42 void setContent(unsigned char* pContent) 43 { m_pContent = pContent; } 44 45 const unsigned char* getContent() const 46 { return m_pContent; } 47 48 //Used by llvm::cast<>. 49 static bool classof(const Fragment *O) 50 { return true; } 51 52 size_t size() const 53 { return m_EntrySize; } 54 55 protected: 56 size_t m_EntrySize; 57 unsigned char* m_pContent; 58 }; 59 60public: 61 PLT(LDSection& pSection); 62 63 virtual ~PLT(); 64 65 /// reserveEntry - reseve the number of pNum of empty entries 66 /// The empty entris are reserved for layout to adjust the fragment offset. 67 virtual void reserveEntry(size_t pNum = 1) = 0; 68 69 // finalizeSectionSize - set LDSection size 70 virtual void finalizeSectionSize() = 0; 71 72 uint64_t addr() const { return m_Section.addr(); } 73 74 const_iterator begin() const { return m_SectionData->begin(); } 75 iterator begin() { return m_SectionData->begin(); } 76 const_iterator end () const { return m_SectionData->end(); } 77 iterator end () { return m_SectionData->end(); } 78 79protected: 80 LDSection& m_Section; 81 SectionData* m_SectionData; 82}; 83 84} // namespace of mcld 85 86#endif 87 88