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 19namespace mcld 20{ 21class LDSection; 22class MemoryRegion; 23 24/** \class MipsGOTEntry 25 * \brief GOT Entry with size of 4 bytes 26 */ 27class MipsGOTEntry : public GOT::Entry<4> 28{ 29public: 30 MipsGOTEntry(uint64_t pContent, SectionData* pParent) 31 : GOT::Entry<4>(pContent, pParent) 32 {} 33}; 34 35/** \class MipsGOT 36 * \brief Mips Global Offset Table. 37 */ 38class MipsGOT : public GOT 39{ 40public: 41 MipsGOT(LDSection& pSection); 42 43 uint64_t emit(MemoryRegion& pRegion); 44 45 void reserve(size_t pNum = 1); 46 void reserveLocalEntry(); 47 void reserveGlobalEntry(); 48 49 size_t getTotalNum() const; 50 size_t getLocalNum() const; 51 52 MipsGOTEntry* consume(); 53 MipsGOTEntry* consumeLocal(); 54 MipsGOTEntry* consumeGlobal(); 55 56 void setLocal(const ResolveInfo* pInfo) { 57 m_GOTTypeMap[pInfo] = false; 58 } 59 60 void setGlobal(const ResolveInfo* pInfo) { 61 m_GOTTypeMap[pInfo] = true; 62 } 63 64 bool isLocal(const ResolveInfo* pInfo) { 65 return m_GOTTypeMap[pInfo] == false; 66 } 67 68 bool isGlobal(const ResolveInfo* pInfo) { 69 return m_GOTTypeMap[pInfo] == true; 70 } 71 72 /// hasGOT1 - return if this got section has any GOT1 entry 73 bool hasGOT1() const; 74 75private: 76 typedef llvm::DenseMap<const ResolveInfo*, bool> SymbolTypeMapType; 77 78private: 79 SymbolTypeMapType m_GOTTypeMap; 80 81 iterator m_LocalGOTIterator; // last local GOT entries 82 iterator m_GlobalGOTIterator; // last global GOT entries 83 size_t m_pLocalNum; 84 85 MipsGOTEntry* m_pLast; ///< the last consumed entry 86}; 87 88} // namespace of mcld 89 90#endif 91 92