1//===- GOT.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_TARGET_GOT_H_
10#define MCLD_TARGET_GOT_H_
11
12#include "mcld/Fragment/TargetFragment.h"
13#include "mcld/LD/LDSection.h"
14#include "mcld/LD/SectionData.h"
15
16namespace mcld {
17
18class GOT;
19class LDSection;
20class ResolveInfo;
21
22/** \class GOT
23 *  \brief The Global Offset Table
24 */
25class GOT {
26 protected:
27  explicit GOT(LDSection& pSection);
28
29 public:
30  typedef SectionData::iterator iterator;
31  typedef SectionData::const_iterator const_iterator;
32
33  template <size_t SIZE>
34  class Entry : public TargetFragment {
35   public:
36    enum { EntrySize = SIZE };
37
38   public:
39    Entry(uint64_t pValue, SectionData* pParent)
40        : TargetFragment(Fragment::Target, pParent), f_Value(pValue) {}
41
42    virtual ~Entry() {}
43
44    uint64_t getValue() const { return f_Value; }
45
46    void setValue(uint64_t pValue) { f_Value = pValue; }
47
48    // Override pure virtual function
49    size_t size() const { return EntrySize; }
50
51   protected:
52    uint64_t f_Value;
53  };
54
55 public:
56  virtual ~GOT();
57
58  // ----- observers -----//
59  uint64_t addr() const { return m_Section.addr(); }
60  uint64_t size() const { return m_Section.size(); }
61
62  const_iterator begin() const { return m_SectionData->begin(); }
63  iterator begin() { return m_SectionData->begin(); }
64  const_iterator end() const { return m_SectionData->end(); }
65  iterator end() { return m_SectionData->end(); }
66
67  bool empty() const { return m_SectionData->empty(); }
68
69  // finalizeSectionSize - set LDSection size
70  virtual void finalizeSectionSize();
71
72 protected:
73  LDSection& m_Section;
74  SectionData* m_SectionData;
75};
76
77}  // namespace mcld
78
79#endif  // MCLD_TARGET_GOT_H_
80