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 PROCEDURE_LINKAGE_TABLE_H 10 #define PROCEDURE_LINKAGE_TABLE_H 11 #ifdef ENABLE_UNITTEST 12 #include <gtest.h> 13 #endif 14 15 #include <mcld/LD/LDSection.h> 16 #include <mcld/MC/MCTargetFragment.h> 17 #include <llvm/ADT/ilist.h> 18 19 namespace mcld 20 { 21 22 class ResolveInfo; 23 24 /** \class PLTEntry 25 */ 26 class PLTEntry : public MCTargetFragment 27 { 28 public: 29 PLTEntry(size_t pSize, llvm::MCSectionData* pParent); 30 virtual ~PLTEntry(); 31 getEntrySize()32 size_t getEntrySize() const 33 { return m_EntrySize; } 34 setContent(unsigned char * pContent)35 void setContent(unsigned char* pContent) 36 { m_pContent = pContent; } 37 getContent()38 const unsigned char* getContent() const 39 { return m_pContent; } 40 41 //Used by llvm::cast<>. classof(const MCFragment * O)42 static bool classof(const MCFragment *O) 43 { return true; } 44 getSize()45 size_t getSize() const 46 { return m_EntrySize; } 47 48 protected: 49 size_t m_EntrySize; 50 unsigned char* m_pContent; 51 }; 52 53 /** \class PLT 54 * \brief Procedure linkage table 55 */ 56 class PLT 57 { 58 public: 59 PLT(LDSection& pSection, llvm::MCSectionData& pSectionData); 60 virtual ~PLT(); 61 getSection()62 const LDSection& getSection() const 63 { return m_Section; } 64 getSectionData()65 const llvm::MCSectionData& getSectionData() const 66 { return m_SectionData; } 67 68 public: 69 /// reserveEntry - reseve the number of pNum of empty entries 70 /// The empty entris are reserved for layout to adjust the fragment offset. 71 virtual void reserveEntry(size_t pNum = 1) = 0; 72 73 /// getPLTEntry - get an empty entry or an exitsted filled entry with pSymbol. 74 /// @param pSymbol - the target symbol 75 /// @param pExist - ture if the a filled entry with pSymbol existed, otherwise false. 76 virtual PLTEntry* getPLTEntry(const ResolveInfo& pSymbol, bool& pExist) = 0; 77 78 protected: 79 LDSection& m_Section; 80 llvm::MCSectionData& m_SectionData; 81 }; 82 83 } // namespace of mcld 84 85 #endif 86 87