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_TARGET_PLT_H 10 #define MCLD_TARGET_PLT_H 11 12 #include <mcld/LD/LDSection.h> 13 #include <mcld/LD/SectionData.h> 14 #include <mcld/Fragment/TargetFragment.h> 15 16 namespace mcld { 17 18 class LDSection; 19 class ResolveInfo; 20 21 /** \class PLTEntryDefaultBase 22 * \brief PLTEntryDefaultBase provides the default interface for PLT Entry 23 */ 24 class PLTEntryBase : public TargetFragment 25 { 26 public: PLTEntryBase(SectionData & pParent)27 PLTEntryBase(SectionData& pParent) 28 : TargetFragment(Fragment::Target, &pParent), m_pValue(NULL) 29 {} 30 ~PLTEntryBase()31 virtual ~PLTEntryBase() 32 { 33 free(m_pValue); 34 } 35 setValue(unsigned char * pValue)36 void setValue(unsigned char* pValue) 37 { m_pValue = pValue; } 38 getValue()39 const unsigned char* getValue() const 40 { return m_pValue; } 41 42 //Used by llvm::cast<>. classof(const Fragment * O)43 static bool classof(const Fragment *O) 44 { return true; } 45 46 protected: 47 unsigned char* m_pValue; 48 }; 49 50 /** \class PLT 51 * \brief Procedure linkage table 52 */ 53 class PLT 54 { 55 public: 56 typedef SectionData::iterator iterator; 57 typedef SectionData::const_iterator const_iterator; 58 59 template<size_t SIZE, typename EntryBase = PLTEntryBase> 60 class Entry : public EntryBase 61 { 62 public: 63 enum { EntrySize = SIZE }; 64 65 public: Entry(SectionData & pParent)66 Entry(SectionData& pParent) 67 : EntryBase(pParent) 68 {} 69 ~Entry()70 virtual ~Entry() {} 71 size()72 size_t size() const 73 { return EntrySize; } 74 }; 75 76 public: 77 PLT(LDSection& pSection); 78 79 virtual ~PLT(); 80 81 // finalizeSectionSize - set LDSection size 82 virtual void finalizeSectionSize() = 0; 83 addr()84 uint64_t addr() const { return m_Section.addr(); } 85 begin()86 const_iterator begin() const { return m_pSectionData->begin(); } begin()87 iterator begin() { return m_pSectionData->begin(); } end()88 const_iterator end () const { return m_pSectionData->end(); } end()89 iterator end () { return m_pSectionData->end(); } 90 91 protected: 92 LDSection& m_Section; 93 SectionData* m_pSectionData; 94 }; 95 96 } // namespace of mcld 97 98 #endif 99 100