GOT.h revision d0fbbb227051be16931a1aa9b4a7722ac039c698
1//===- GOT.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_GLOBAL_OFFSET_TABLE_H 10#define MCLD_GLOBAL_OFFSET_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 GOT; 22class LDSection; 23class ResolveInfo; 24 25/** \class GOT 26 * \brief The Global Offset Table 27 */ 28class GOT 29{ 30protected: 31 GOT(LDSection& pSection); 32 33public: 34 typedef SectionData::iterator iterator; 35 typedef SectionData::const_iterator const_iterator; 36 37 template<size_t SIZE> 38 class Entry : public TargetFragment 39 { 40 public: 41 enum { EntrySize = SIZE }; 42 43 public: 44 Entry(uint64_t pValue, SectionData* pParent) 45 : TargetFragment(Fragment::Target, pParent), 46 f_Value(pValue) { 47 } 48 49 virtual ~Entry() {} 50 51 uint64_t getValue() const 52 { return f_Value; } 53 54 void setValue(uint64_t pValue) 55 { f_Value = pValue; } 56 57 // Override pure virtual function 58 size_t size() const 59 { return EntrySize; } 60 61 protected: 62 uint64_t f_Value; 63 }; 64 65public: 66 virtual ~GOT(); 67 68 // ----- observers -----// 69 uint64_t addr() const { return m_Section.addr(); } 70 71 const_iterator begin() const { return m_SectionData->begin(); } 72 iterator begin() { return m_SectionData->begin(); } 73 const_iterator end () const { return m_SectionData->end(); } 74 iterator end () { return m_SectionData->end(); } 75 76 bool empty() const 77 { return m_SectionData->empty(); } 78 79 // finalizeSectionSize - set LDSection size 80 virtual void finalizeSectionSize(); 81 82 /// reserve - reseve number of pNum of empty entries 83 /// Before layout, we scan all relocations to determine if GOT entries are 84 /// needed. If an entry is needed, the empty entry is reserved for layout 85 /// to adjust the fragment offset. After that, we fill up the entries when 86 /// applying relocations. 87 virtual void reserve(size_t pNum = 1) = 0; 88 89protected: 90 LDSection& m_Section; 91 SectionData* m_SectionData; 92}; 93 94} // namespace of mcld 95 96#endif 97 98