X86GOT.h revision abe0db302735bbdf9cd84caee2a36e6c4538fc4d
1//===- X86GOT.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_X86_GOT_H
10#define MCLD_X86_GOT_H
11#ifdef ENABLE_UNITTEST
12#include <gtest.h>
13#endif
14
15#include "X86PLT.h"
16#include <mcld/Target/GOT.h>
17
18namespace mcld
19{
20class LDSection;
21
22/** \class X86GOT
23 *  \brief X86 Global Offset Table.
24 */
25
26const unsigned int X86GOT0Num = 3;
27
28class X86GOT : public GOT
29{
30  friend void mcld::X86PLT::reserveEntry(size_t pNum);
31
32  friend mcld::PLTEntry* mcld::X86PLT::getPLTEntry(
33         const mcld::ResolveInfo& pSymbol,bool& pExist);
34
35  friend mcld::GOTEntry* mcld::X86PLT::getGOTPLTEntry(
36         const mcld::ResolveInfo& pSymbol,bool& pExist);
37
38  typedef llvm::DenseMap<const ResolveInfo*, GOTEntry*> SymbolIndexMapType;
39
40public:
41  typedef llvm::MCSectionData::iterator iterator;
42  typedef llvm::MCSectionData::const_iterator const_iterator;
43
44public:
45  X86GOT(LDSection& pSection, llvm::MCSectionData& pSectionData);
46
47  ~X86GOT();
48
49  //Reserve general GOT entries.
50  void reserveEntry(size_t pNum = 1);
51
52  GOTEntry* getEntry(const ResolveInfo& pSymbol, bool& pExist);
53
54  void applyGOT0(uint64_t pAddress);
55
56  iterator begin();
57
58  const_iterator begin() const;
59
60  iterator end();
61
62  const_iterator end() const;
63
64  unsigned int getGOTPLTNum() const;
65
66  iterator getLastGOT0();
67
68  const iterator getLastGOT0() const;
69
70private:
71
72  unsigned int m_GeneralGOTNum;
73  unsigned int m_GOTPLTNum;
74
75  // Used by getGeneralGOTEntry()
76  iterator m_GeneralGOTIterator;
77
78  // Used by getGOTPLTEntry()
79  iterator m_GOTPLTIterator;
80
81  // The last GOT0 entry
82  iterator m_LastGOT0;
83
84  SymbolIndexMapType m_GOTPLTMap;
85  SymbolIndexMapType m_GeneralGOTMap;
86};
87
88} // namespace of mcld
89
90#endif
91