summaryrefslogtreecommitdiff
path: root/lib/Target/Mips/MipsGOT.h
blob: 2f04ef46fa68600eb4164f1bb3524d377be2ebde (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
//===- MipsGOT.h ----------------------------------------------------------===//
//
//                     The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef MCLD_MIPS_GOT_H
#define MCLD_MIPS_GOT_H
#ifdef ENABLE_UNITTEST
#include <gtest.h>
#endif

#include <mcld/Target/GOT.h>

namespace mcld
{
class LDSection;
class MemoryRegion;

/** \class MipsGOT
 *  \brief Mips Global Offset Table.
 */
class MipsGOT : public GOT
{
private:
  typedef llvm::DenseMap<const ResolveInfo*, GOTEntry*> SymbolIndexMapType;
  typedef llvm::DenseMap<const ResolveInfo*, bool> SymbolTypeMapType;

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

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

  iterator begin();
  iterator end();

  const_iterator begin() const;
  const_iterator end() const;

  uint64_t emit(MemoryRegion& pRegion);

  void reserveLocalEntry();
  void reserveGlobalEntry();

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

  size_t getTotalNum() const;
  size_t getLocalNum() const;

  void setLocal(const ResolveInfo* pInfo) {
    m_GOTTypeMap[pInfo] = false;
  }

  void setGlobal(const ResolveInfo* pInfo) {
    m_GOTTypeMap[pInfo] = true;
  }

  bool isLocal(const ResolveInfo* pInfo) {
    return m_GOTTypeMap[pInfo] == false;
  }

  bool isGlobal(const ResolveInfo* pInfo) {
    return m_GOTTypeMap[pInfo] == true;
  }

private:
  SymbolIndexMapType m_GeneralGOTMap; // Map ResolveInfo* to GOTEntry *.
  SymbolTypeMapType m_GOTTypeMap;

  iterator m_LocalGOTIterator;  // last local GOT entries
  iterator m_GlobalGOTIterator; // last global GOT entries
  size_t m_pLocalNum;

private:
  // Use reserveLocalEntry()/reserveGlobalEntry() instead of this routine.
  void reserveEntry(size_t pNum = 1);
};

} // namespace of mcld

#endif