1 //===- Relocation.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_FRAGMENT_RELOCATION_H 10 #define MCLD_FRAGMENT_RELOCATION_H 11 #include <mcld/Config/Config.h> 12 #include <mcld/Fragment/FragmentRef.h> 13 #include <mcld/Support/GCFactoryListTraits.h> 14 15 #include <llvm/ADT/ilist_node.h> 16 #include <llvm/Support/DataTypes.h> 17 18 namespace mcld { 19 20 class ResolveInfo; 21 class Relocator; 22 class LinkerConfig; 23 24 class Relocation : public llvm::ilist_node<Relocation> 25 { 26 friend class RelocationFactory; 27 friend class GCFactoryListTraits<Relocation>; 28 friend class Chunk<Relocation, MCLD_RELOCATIONS_PER_INPUT>; 29 30 public: 31 typedef uint64_t Address; // FIXME: use SizeTrait<T>::Address instead 32 typedef uint64_t DWord; // FIXME: use SizeTrait<T>::Word instead 33 typedef int64_t SWord; // FIXME: use SizeTrait<T>::SWord instead 34 typedef uint32_t Type; 35 typedef uint32_t Size; 36 37 private: 38 Relocation(); 39 40 Relocation(Type pType, 41 FragmentRef* pTargetRef, 42 Address pAddend, 43 DWord pTargetData); 44 45 ~Relocation(); 46 47 public: 48 /// Initialize - set up the relocation factory 49 static void SetUp(const LinkerConfig& pConfig); 50 51 /// Clear - Clean up the relocation factory 52 static void Clear(); 53 54 /// Create - produce an empty relocation entry 55 static Relocation* Create(); 56 57 /// Create - produce a relocation entry 58 /// @param pType [in] the type of the relocation entry 59 /// @param pFragRef [in] the place to apply the relocation 60 /// @param pAddend [in] the addend of the relocation entry 61 static Relocation* Create(Type pType, FragmentRef& pFragRef, 62 Address pAddend = 0); 63 64 /// Destroy - destroy a relocation entry 65 static void Destroy(Relocation*& pRelocation); 66 67 /// type - relocation type type()68 Type type() const 69 { return m_Type; } 70 71 /// symValue - S value - the symbol address 72 Address symValue() const; 73 74 /// addend - A value addend()75 Address addend() const 76 { return m_Addend; } 77 78 /// place - P value - address of the place being relocated 79 Address place() const; 80 81 /// size - the size of the relocation in bit 82 Size size(Relocator& pRelocator) const; 83 84 /// symbol info - binding, type symInfo()85 const ResolveInfo* symInfo() const { return m_pSymInfo; } symInfo()86 ResolveInfo* symInfo() { return m_pSymInfo; } 87 88 /// target - the target data to relocate target()89 const DWord& target() const { return m_TargetData; } target()90 DWord& target() { return m_TargetData; } 91 92 /// targetRef - the reference of the target data targetRef()93 const FragmentRef& targetRef() const { return m_TargetAddress; } targetRef()94 FragmentRef& targetRef() { return m_TargetAddress; } 95 96 void apply(Relocator& pRelocator); 97 98 /// updateAddend - A relocation with a section symbol must update addend 99 /// before reading its value. 100 void updateAddend(); 101 102 /// ----- modifiers ----- /// 103 void setType(Type pType); 104 105 void setAddend(Address pAddend); 106 107 void setSymInfo(ResolveInfo* pSym); 108 109 private: 110 /// m_Type - the type of the relocation entries 111 Type m_Type; 112 113 /// m_TargetData - target data of the place being relocated 114 DWord m_TargetData; 115 116 /// m_pSymInfo - resolved symbol info of relocation target symbol 117 ResolveInfo* m_pSymInfo; 118 119 /// m_TargetAddress - FragmentRef of the place being relocated 120 FragmentRef m_TargetAddress; 121 122 /// m_Addend - the addend 123 Address m_Addend; 124 }; 125 126 } // namespace of mcld 127 128 #endif 129 130