1 //===- X86Relocator.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 X86_RELOCATION_FACTORY_H 10 #define X86_RELOCATION_FACTORY_H 11 #ifdef ENABLE_UNITTEST 12 #include <gtest.h> 13 #endif 14 15 #include <mcld/LD/Relocator.h> 16 #include <mcld/Target/GOT.h> 17 #include <mcld/Target/PLT.h> 18 #include <mcld/Target/SymbolEntryMap.h> 19 #include "X86LDBackend.h" 20 21 namespace mcld { 22 23 class ResolveInfo; 24 25 /** \class X86Relocator 26 * \brief X86Relocator creates and destroys the X86 relocations. 27 * 28 */ 29 class X86Relocator : public Relocator 30 { 31 public: 32 typedef SymbolEntryMap<PLTEntryBase> SymPLTMap; 33 34 public: 35 X86Relocator(); 36 ~X86Relocator(); 37 38 virtual Result applyRelocation(Relocation& pRelocation) = 0; 39 40 virtual const char* getName(Relocation::Type pType) const = 0; 41 getSymPLTMap()42 const SymPLTMap& getSymPLTMap() const { return m_SymPLTMap; } getSymPLTMap()43 SymPLTMap& getSymPLTMap() { return m_SymPLTMap; } 44 45 private: 46 SymPLTMap m_SymPLTMap; 47 }; 48 49 /** \class X86_32Relocator 50 * \brief X86_32Relocator creates and destroys the X86-32 relocations. 51 * 52 */ 53 class X86_32Relocator : public X86Relocator 54 { 55 public: 56 typedef SymbolEntryMap<X86_32GOTEntry> SymGOTMap; 57 typedef SymbolEntryMap<X86_32GOTEntry> SymGOTPLTMap; 58 59 enum { 60 R_386_TLS_OPT = 44 // mcld internal relocation type 61 }; 62 63 public: 64 X86_32Relocator(X86_32GNULDBackend& pParent); 65 66 Result applyRelocation(Relocation& pRelocation); 67 getTarget()68 X86_32GNULDBackend& getTarget() 69 { return m_Target; } 70 getTarget()71 const X86_32GNULDBackend& getTarget() const 72 { return m_Target; } 73 74 const char* getName(Relocation::Type pType) const; 75 76 Size getSize(Relocation::Type pType) const; 77 getSymGOTMap()78 const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; } getSymGOTMap()79 SymGOTMap& getSymGOTMap() { return m_SymGOTMap; } 80 getSymGOTPLTMap()81 const SymGOTPLTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; } getSymGOTPLTMap()82 SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; } 83 84 private: 85 X86_32GNULDBackend& m_Target; 86 SymGOTMap m_SymGOTMap; 87 SymGOTPLTMap m_SymGOTPLTMap; 88 }; 89 90 /** \class X86_64Relocator 91 * \brief X86_64Relocator creates and destroys the X86-64 relocations. 92 * 93 */ 94 class X86_64Relocator : public X86Relocator 95 { 96 public: 97 typedef SymbolEntryMap<X86_64GOTEntry> SymGOTMap; 98 typedef SymbolEntryMap<X86_64GOTEntry> SymGOTPLTMap; 99 100 public: 101 X86_64Relocator(X86_64GNULDBackend& pParent); 102 103 Result applyRelocation(Relocation& pRelocation); 104 getTarget()105 X86_64GNULDBackend& getTarget() 106 { return m_Target; } 107 getTarget()108 const X86_64GNULDBackend& getTarget() const 109 { return m_Target; } 110 111 const char* getName(Relocation::Type pType) const; 112 113 Size getSize(Relocation::Type pType) const; 114 getSymGOTMap()115 const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; } getSymGOTMap()116 SymGOTMap& getSymGOTMap() { return m_SymGOTMap; } 117 getSymGOTPLTMap()118 const SymGOTPLTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; } getSymGOTPLTMap()119 SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; } 120 121 private: 122 X86_64GNULDBackend& m_Target; 123 SymGOTMap m_SymGOTMap; 124 SymGOTPLTMap m_SymGOTPLTMap; 125 }; 126 127 } // namespace of mcld 128 129 #endif 130 131