AArch64GOT.h revision 551ae4ebd3e9d137ea668fb83ae4a55b8cfba451
1//===- AArch64GOT.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 TARGET_AARCH64_AARCH64GOT_H 10#define TARGET_AARCH64_AARCH64GOT_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14 15#include <mcld/Support/MemoryRegion.h> 16#include <mcld/Target/GOT.h> 17 18#include <llvm/ADT/DenseMap.h> 19 20#include <vector> 21 22namespace mcld { 23 24class LDSection; 25 26/** \class AArch64GOTEntry 27 * \brief GOT Entry with size of 8 bytes 28 */ 29class AArch64GOTEntry : public GOT::Entry<8> 30{ 31public: 32 AArch64GOTEntry(uint64_t pContent, SectionData* pParent) 33 : GOT::Entry<8>(pContent, pParent) 34 {} 35}; 36 37/** \class AArch64GOT 38 * \brief AArch64 Global Offset Table. 39 * 40 * AArch64 GOT integrates traditional .got.plt and .got sections into one. 41 * Traditional .got.plt is placed in the front part of GOT (PLTGOT), and 42 * traditional .got is placed in the rear part of GOT (GOT). When -z now and 43 * -z relro are given, the got section layout will be as below. Otherwise, 44 * there will be two seperated sections, .got and .got.plt. 45 * 46 * This class may be used as .got (with no GOTPLT entry), .got.plt (with only 47 * GOTPLT entries) or .got (with GOTPLT and normal GOT entries) 48 * 49 * AArch64 .got 50 * +--------------+ 51 * | GOT0 | 52 * +--------------+ 53 * | GOTPLT | 54 * +--------------+ 55 * | GOT | 56 * +--------------+ 57 * 58 */ 59class AArch64GOT : public GOT 60{ 61public: 62 AArch64GOT(LDSection &pSection); 63 64 ~AArch64GOT(); 65 66 /// createGOT0 - create the defualt GOT0 entries. This function called when 67 /// it's a .got section (with GOTPLT entries and normal GOT entry) or it's a 68 /// .got.plt section 69 void createGOT0(); 70 71 AArch64GOTEntry* createGOT(); 72 AArch64GOTEntry* createGOTPLT(); 73 74 void finalizeSectionSize(); 75 76 uint64_t emit(MemoryRegion& pRegion); 77 78 void applyGOT0(uint64_t pAddress); 79 80 void applyGOTPLT(uint64_t pPLTBase); 81 82 bool hasGOT1() const; 83 84private: 85 typedef std::vector<AArch64GOTEntry*> EntryListType; 86 typedef EntryListType::iterator entry_iterator; 87 typedef EntryListType::const_iterator const_entry_iterator; 88 89private: 90 AArch64GOTEntry* m_pGOTPLTFront; 91 AArch64GOTEntry* m_pGOTFront; 92 93 /// m_GOTPLTEntries - a list of gotplt entries 94 EntryListType m_GOTPLT; 95 96 /// m_GOTEntris - a list of got entries 97 EntryListType m_GOT; 98}; 99 100} // namespace of mcld 101 102#endif 103 104