Relocation.h revision 87f34658dec9097d987d254a990ea7f311bfc95f
15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- Relocation.h ----------------------------------------------------===// 25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// The MCLinker Project 45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source 65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details. 75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===// 922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#ifndef MCLD_FRAGMENT_RELOCATION_H 1022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#define MCLD_FRAGMENT_RELOCATION_H 115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#ifdef ENABLE_UNITTEST 125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <gtest.h> 135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif 14d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao#include <mcld/Config/Config.h> 1522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#include <mcld/Fragment/FragmentRef.h> 16d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao#include <mcld/Support/GCFactoryListTraits.h> 17d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao 18d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao#include <llvm/ADT/ilist_node.h> 19d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao#include <llvm/Support/DataTypes.h> 205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 2122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaonamespace mcld { 225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 2322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaoclass ResolveInfo; 24d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liaoclass Relocator; 2522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaoclass LinkerConfig; 265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 27d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liaoclass Relocation : public llvm::ilist_node<Relocation> 285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{ 295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaofriend class RelocationFactory; 30d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liaofriend class GCFactoryListTraits<Relocation>; 31d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liaofriend class Chunk<Relocation, MCLD_RELOCATIONS_PER_INPUT>; 325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic: 345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao typedef uint64_t Address; // FIXME: use SizeTrait<T>::Address instead 356f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines typedef uint64_t DWord; // FIXME: use SizeTrait<T>::Word instead 366f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines typedef int64_t SWord; // FIXME: use SizeTrait<T>::SWord instead 3787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines typedef uint32_t Type; 386f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines typedef uint32_t Size; 395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate: 41d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao Relocation(); 42d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao 435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao Relocation(Type pType, 44cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao FragmentRef* pTargetRef, 455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao Address pAddend, 465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao DWord pTargetData); 475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 485460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ~Relocation(); 495460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 50d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liaopublic: 51d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao /// Initialize - set up the relocation factory 52d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao static void SetUp(const LinkerConfig& pConfig); 53d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao 54d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao /// Clear - Clean up the relocation factory 55d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao static void Clear(); 56d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao 57d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao /// Create - produce an empty relocation entry 58d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao static Relocation* Create(); 59d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao 60d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao /// Create - produce a relocation entry 61d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao /// @param pType [in] the type of the relocation entry 62d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao /// @param pFragRef [in] the place to apply the relocation 63d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao /// @param pAddend [in] the addend of the relocation entry 64d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao static Relocation* Create(Type pType, FragmentRef& pFragRef, 65d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao Address pAddend = 0); 66d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao 67d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao /// Destroy - destroy a relocation entry 68d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao static void Destroy(Relocation*& pRelocation); 69d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao 705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// type - relocation type 715460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao Type type() const 725460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao { return m_Type; } 735460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 745460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// symValue - S value - the symbol address 755460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao Address symValue() const; 765460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 775460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// addend - A value 785460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao Address addend() const 795460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao { return m_Addend; } 805460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 815460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// place - P value - address of the place being relocated 8222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao Address place() const; 835460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 846f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines /// size - the size of the relocation in bit 856f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines Size size(Relocator& pRelocator) const; 866f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines 875460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// symbol info - binding, type 8822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao const ResolveInfo* symInfo() const { return m_pSymInfo; } 8922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao ResolveInfo* symInfo() { return m_pSymInfo; } 905460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 915460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// target - the target data to relocate 9222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao const DWord& target() const { return m_TargetData; } 9322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao DWord& target() { return m_TargetData; } 945460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 955460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// targetRef - the reference of the target data 9622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao const FragmentRef& targetRef() const { return m_TargetAddress; } 9722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao FragmentRef& targetRef() { return m_TargetAddress; } 985460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 99d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao void apply(Relocator& pRelocator); 10022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao 10122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao /// updateAddend - A relocation with a section symbol must update addend 10222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao /// before reading its value. 10322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao void updateAddend(); 1045460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1055460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// ----- modifiers ----- /// 1065460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao void setType(Type pType); 1075460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1085460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao void setAddend(Address pAddend); 1095460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao void setSymInfo(ResolveInfo* pSym); 1115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate: 1135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// m_Type - the type of the relocation entries 1145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao Type m_Type; 1155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// m_TargetData - target data of the place being relocated 1175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao DWord m_TargetData; 1185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// m_pSymInfo - resolved symbol info of relocation target symbol 1205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ResolveInfo* m_pSymInfo; 1215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 122cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao /// m_TargetAddress - FragmentRef of the place being relocated 123cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao FragmentRef m_TargetAddress; 1245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// m_Addend - the addend 1265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao Address m_Addend; 1275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}; 1285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} // namespace of mcld 1305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif 132affc150dc44fab1911775a49636d0ce85333b634Zonr Chang 133