RelocationFactory.h revision d8a752331fe7a30ce41835f139aa8a4c675ad07a
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 LD_RELOCATION_FACTORY_H 10#define LD_RELOCATION_FACTORY_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14#include <mcld/Support/GCFactory.h> 15#include <mcld/LD/Relocation.h> 16 17namespace mcld 18{ 19 20class LDSymbol; 21class ResolveInfo; 22class MCFragmentRef; 23class Layout; 24class GOT; 25class TargetLDBackend; 26class MCLDInfo; 27 28/** \class RelocationFactory 29 * \brief RelocationFactory provides the interface for generating target 30 * relocation 31 * 32 */ 33class RelocationFactory : public GCFactory<Relocation, 0> 34{ 35public: 36 typedef Relocation::Type Type; 37 typedef Relocation::Address Address; 38 typedef Relocation::DWord DWord; 39 40public: 41 explicit RelocationFactory(size_t pNum); 42 43 virtual ~RelocationFactory(); 44 45 /// apply - general apply function 46 virtual void applyRelocation(Relocation& pRelocation, 47 const MCLDInfo& pLDInfo) = 0; 48 49 // ----- production ----- // 50 /// produce - produce a relocation entry 51 /// @param pType - the type of the relocation entry 52 /// @param pFragRef - the place to apply the relocation 53 /// @param pAddend - the addend of the relocation entry 54 Relocation* produce(Type pType, 55 MCFragmentRef& pFragRef, 56 Address pAddend = 0); 57 58 /// produceEmptyEntry - produce an empty relocation which 59 /// occupied memory space but all contents set to zero. 60 Relocation* produceEmptyEntry(); 61 62 void destroy(Relocation* pRelocation); 63 64 void setLayout(const Layout& pLayout); 65 66 // ------ observers -----// 67 const Layout& getLayout() const; 68 69 virtual TargetLDBackend& getTarget() = 0; 70 71 virtual const TargetLDBackend& getTarget() const = 0; 72 73private: 74 const Layout* m_pLayout; 75 76}; 77 78} // namespace of mcld 79 80#endif 81