PLT.h revision f33f6de54db174aa679a4b6d1e040d37e95541c0
1//===- PLT.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_PLT_H
10#define MCLD_TARGET_PLT_H
11#ifdef ENABLE_UNITTEST
12#include <gtest.h>
13#endif
14
15#include <mcld/LD/LDSection.h>
16#include <mcld/LD/SectionData.h>
17#include <mcld/Fragment/TargetFragment.h>
18
19namespace mcld {
20
21class LDSection;
22class ResolveInfo;
23
24/** \class PLTEntryDefaultBase
25 *  \brief PLTEntryDefaultBase provides the default interface for PLT Entry
26 */
27class PLTEntryBase : public TargetFragment
28{
29public:
30  PLTEntryBase(SectionData& pParent)
31    : TargetFragment(Fragment::Target, &pParent), m_pValue(NULL)
32  {}
33
34  virtual ~PLTEntryBase()
35  {
36    free(m_pValue);
37  }
38
39  void setValue(unsigned char* pValue)
40  { m_pValue = pValue; }
41
42  const unsigned char* getValue() const
43  { return m_pValue; }
44
45  //Used by llvm::cast<>.
46  static bool classof(const Fragment *O)
47  { return true; }
48
49protected:
50  unsigned char* m_pValue;
51};
52
53/** \class PLT
54 *  \brief Procedure linkage table
55 */
56class PLT
57{
58public:
59  typedef SectionData::iterator iterator;
60  typedef SectionData::const_iterator const_iterator;
61
62  template<size_t SIZE, typename EntryBase = PLTEntryBase>
63  class Entry : public EntryBase
64  {
65  public:
66    enum { EntrySize = SIZE };
67
68  public:
69    Entry(SectionData& pParent)
70      : EntryBase(pParent)
71    {}
72
73    virtual ~Entry() {}
74
75    size_t size() const
76    { return EntrySize; }
77  };
78
79public:
80  PLT(LDSection& pSection);
81
82  virtual ~PLT();
83
84  // finalizeSectionSize - set LDSection size
85  virtual void finalizeSectionSize() = 0;
86
87  uint64_t addr() const { return m_Section.addr(); }
88
89  const_iterator begin() const { return m_SectionData->begin(); }
90  iterator       begin()       { return m_SectionData->begin(); }
91  const_iterator end  () const { return m_SectionData->end();   }
92  iterator       end  ()       { return m_SectionData->end();   }
93
94protected:
95  LDSection& m_Section;
96  SectionData* m_SectionData;
97};
98
99} // namespace of mcld
100
101#endif
102
103