Relocation.h revision 22add6ff3426df1a85089fe6a6e1597ee3b6f300
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#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14#include <llvm/Support/DataTypes.h> 15 16#include <mcld/Fragment/Fragment.h> 17#include <mcld/Fragment/FragmentRef.h> 18 19namespace mcld { 20 21class ResolveInfo; 22class RelocationFactory; 23class LinkerConfig; 24 25class Relocation : public Fragment 26{ 27friend class RelocationFactory; 28 29public: 30 typedef uint64_t Address; // FIXME: use SizeTrait<T>::Address instead 31 typedef uint64_t DWord; // FIXME: use SizeTrait<T>::Word instead 32 typedef int64_t SWord; // FIXME: use SizeTrait<T>::SWord instead 33 typedef uint8_t Type; 34 35private: 36 Relocation(Type pType, 37 FragmentRef* pTargetRef, 38 Address pAddend, 39 DWord pTargetData); 40 41public: 42 ~Relocation(); 43 44 /// type - relocation type 45 Type type() const 46 { return m_Type; } 47 48 /// symValue - S value - the symbol address 49 Address symValue() const; 50 51 /// addend - A value 52 Address addend() const 53 { return m_Addend; } 54 55 /// place - P value - address of the place being relocated 56 Address place() const; 57 58 /// symbol info - binding, type 59 const ResolveInfo* symInfo() const { return m_pSymInfo; } 60 ResolveInfo* symInfo() { return m_pSymInfo; } 61 62 /// target - the target data to relocate 63 const DWord& target() const { return m_TargetData; } 64 DWord& target() { return m_TargetData; } 65 66 /// targetRef - the reference of the target data 67 const FragmentRef& targetRef() const { return m_TargetAddress; } 68 FragmentRef& targetRef() { return m_TargetAddress; } 69 70 71 void apply(RelocationFactory& pRelocFactory); 72 73 /// updateAddend - A relocation with a section symbol must update addend 74 /// before reading its value. 75 void updateAddend(); 76 77 /// ----- modifiers ----- /// 78 void setType(Type pType); 79 80 void setAddend(Address pAddend); 81 82 void setSymInfo(ResolveInfo* pSym); 83 84 // Relocation is a kind of Fragment with type of FT_Reloc 85 static bool classof(const Fragment *F) 86 { return F->getKind() == Fragment::Relocation; } 87 88 static bool classof(const Relocation *) 89 { return true; } 90 91 size_t size() const; 92 93private: 94 /// m_Type - the type of the relocation entries 95 Type m_Type; 96 97 /// m_TargetData - target data of the place being relocated 98 DWord m_TargetData; 99 100 /// m_pSymInfo - resolved symbol info of relocation target symbol 101 ResolveInfo* m_pSymInfo; 102 103 /// m_TargetAddress - FragmentRef of the place being relocated 104 FragmentRef m_TargetAddress; 105 106 /// m_Addend - the addend 107 Address m_Addend; 108}; 109 110} // namespace of mcld 111 112#endif 113 114