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