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