1//===- MipsGOT.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_MIPS_GOT_H 10#define MCLD_MIPS_GOT_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14 15#include <llvm/ADT/DenseMap.h> 16 17#include <mcld/Target/GOT.h> 18#include <mcld/LD/SectionData.h> 19 20namespace mcld 21{ 22class LDSection; 23class MemoryRegion; 24 25/** \class MipsGOT 26 * \brief Mips Global Offset Table. 27 */ 28class MipsGOT : public GOT 29{ 30private: 31 typedef llvm::DenseMap<const ResolveInfo*, GOTEntry*> SymbolIndexMapType; 32 typedef llvm::DenseMap<const ResolveInfo*, bool> SymbolTypeMapType; 33 34public: 35 typedef SectionData::iterator iterator; 36 typedef SectionData::const_iterator const_iterator; 37 38public: 39 MipsGOT(LDSection& pSection, SectionData& pSectionData); 40 41 iterator begin(); 42 iterator end(); 43 44 const_iterator begin() const; 45 const_iterator end() const; 46 47 uint64_t emit(MemoryRegion& pRegion); 48 49 void reserveLocalEntry(); 50 void reserveGlobalEntry(); 51 52 GOTEntry* getEntry(const ResolveInfo& pInfo, bool& pExist); 53 54 size_t getTotalNum() const; 55 size_t getLocalNum() const; 56 57 void setLocal(const ResolveInfo* pInfo) { 58 m_GOTTypeMap[pInfo] = false; 59 } 60 61 void setGlobal(const ResolveInfo* pInfo) { 62 m_GOTTypeMap[pInfo] = true; 63 } 64 65 bool isLocal(const ResolveInfo* pInfo) { 66 return m_GOTTypeMap[pInfo] == false; 67 } 68 69 bool isGlobal(const ResolveInfo* pInfo) { 70 return m_GOTTypeMap[pInfo] == true; 71 } 72 73private: 74 SymbolIndexMapType m_GeneralGOTMap; // Map ResolveInfo* to GOTEntry *. 75 SymbolTypeMapType m_GOTTypeMap; 76 77 iterator m_LocalGOTIterator; // last local GOT entries 78 iterator m_GlobalGOTIterator; // last global GOT entries 79 size_t m_pLocalNum; 80 81private: 82 // Use reserveLocalEntry()/reserveGlobalEntry() instead of this routine. 83 void reserveEntry(size_t pNum = 1); 84}; 85 86} // namespace of mcld 87 88#endif 89 90