summaryrefslogtreecommitdiff
path: root/lib/Target/X86/X86GOT.h
blob: 018aa24086943cec55bc4ed5bb4d4e717192c333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//===- X86GOT.h -----------------------------------------------------------===//
//
//                     The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef MCLD_X86_GOT_H
#define MCLD_X86_GOT_H
#ifdef ENABLE_UNITTEST
#include <gtest.h>
#endif

#include "X86PLT.h"
#include <mcld/Target/GOT.h>

namespace mcld
{
class LDSection;

/** \class X86GOT
 *  \brief X86 Global Offset Table.
 */

const unsigned int X86GOT0Num = 3;

class X86GOT : public GOT
{
  friend void mcld::X86PLT::reserveEntry(size_t pNum);

  friend mcld::PLTEntry* mcld::X86PLT::getPLTEntry(
         const mcld::ResolveInfo& pSymbol,bool& pExist);

  friend mcld::GOTEntry* mcld::X86PLT::getGOTPLTEntry(
         const mcld::ResolveInfo& pSymbol,bool& pExist);

  typedef llvm::DenseMap<const ResolveInfo*, GOTEntry*> SymbolIndexMapType;

public:
  typedef llvm::MCSectionData::iterator iterator;
  typedef llvm::MCSectionData::const_iterator const_iterator;

public:
  X86GOT(LDSection& pSection, llvm::MCSectionData& pSectionData);

  ~X86GOT();

  //Reserve general GOT entries.
  void reserveEntry(size_t pNum = 1);

  GOTEntry* getEntry(const ResolveInfo& pSymbol, bool& pExist);

  void applyGOT0(uint64_t pAddress);

  iterator begin();

  const_iterator begin() const;

  iterator end();

  const_iterator end() const;

  unsigned int getGOTPLTNum() const;

  iterator getLastGOT0();

  const iterator getLastGOT0() const;

private:

  unsigned int m_GeneralGOTNum;
  unsigned int m_GOTPLTNum;

  // Used by getGeneralGOTEntry()
  iterator m_GeneralGOTIterator;

  // Used by getGOTPLTEntry()
  iterator m_GOTPLTIterator;

  // The last GOT0 entry
  iterator m_LastGOT0;

  SymbolIndexMapType m_GOTPLTMap;
  SymbolIndexMapType m_GeneralGOTMap;
};

} // namespace of mcld

#endif