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