• 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_PROCEDURE_LINKAGE_TABLE_H
10 #define MCLD_PROCEDURE_LINKAGE_TABLE_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 
19 namespace mcld {
20 
21 class LDSection;
22 class ResolveInfo;
23 
24 /** \class PLTEntryDefaultBase
25  *  \brief PLTEntryDefaultBase provides the default interface for PLE Entry
26  */
27 class PLTEntryBase : public TargetFragment
28 {
29 public:
PLTEntryBase(SectionData & pParent)30   PLTEntryBase(SectionData& pParent)
31     : TargetFragment(Fragment::Target, &pParent), m_pValue(NULL)
32   {}
33 
~PLTEntryBase()34   virtual ~PLTEntryBase()
35   {
36     delete m_pValue;
37   }
38 
setValue(unsigned char * pValue)39   void setValue(unsigned char* pValue)
40   { m_pValue = pValue; }
41 
getValue()42   const unsigned char* getValue() const
43   { return m_pValue; }
44 
45   //Used by llvm::cast<>.
classof(const Fragment * O)46   static bool classof(const Fragment *O)
47   { return true; }
48 
49 protected:
50   unsigned char* m_pValue;
51 };
52 
53 /** \class PLT
54  *  \brief Procedure linkage table
55  */
56 class PLT
57 {
58 public:
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:
Entry(SectionData & pParent)69     Entry(SectionData& pParent)
70       : EntryBase(pParent)
71     {}
72 
~Entry()73     virtual ~Entry() {}
74 
size()75     size_t size() const
76     { return EntrySize; }
77   };
78 
79 public:
80   PLT(LDSection& pSection);
81 
82   virtual ~PLT();
83 
84   /// reserveEntry - reseve the number of pNum of empty entries
85   /// The empty entris are reserved for layout to adjust the fragment offset.
86   virtual void reserveEntry(size_t pNum = 1) = 0;
87 
88   // finalizeSectionSize - set LDSection size
89   virtual void finalizeSectionSize() = 0;
90 
addr()91   uint64_t addr() const { return m_Section.addr(); }
92 
begin()93   const_iterator begin() const { return m_SectionData->begin(); }
begin()94   iterator       begin()       { return m_SectionData->begin(); }
end()95   const_iterator end  () const { return m_SectionData->end();   }
end()96   iterator       end  ()       { return m_SectionData->end();   }
97 
98 protected:
99   LDSection& m_Section;
100   SectionData* m_SectionData;
101 };
102 
103 } // namespace of mcld
104 
105 #endif
106 
107