RelocationFactory.h revision cedee4b38f4786845183be7f5916dd520a170ae0
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_LD_RELOCATION_FACTORY_H 10#define MCLD_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 FragmentRef; 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 40 enum Result { 41 OK, 42 BadReloc, 43 Overflow, 44 Unsupport, 45 Unknown 46 }; 47 48public: 49 explicit RelocationFactory(size_t pNum); 50 51 virtual ~RelocationFactory(); 52 53 /// apply - general apply function 54 virtual Result applyRelocation(Relocation& pRelocation, 55 const MCLDInfo& pLDInfo) = 0; 56 57 // ----- production ----- // 58 /// produce - produce a relocation entry 59 /// @param pType - the type of the relocation entry 60 /// @param pFragRef - the place to apply the relocation 61 /// @param pAddend - the addend of the relocation entry 62 Relocation* produce(Type pType, 63 FragmentRef& pFragRef, 64 Address pAddend = 0); 65 66 /// produceEmptyEntry - produce an empty relocation which 67 /// occupied memory space but all contents set to zero. 68 Relocation* produceEmptyEntry(); 69 70 void destroy(Relocation* pRelocation); 71 72 void setLayout(const Layout& pLayout); 73 74 // ------ observers -----// 75 const Layout& getLayout() const; 76 77 virtual TargetLDBackend& getTarget() = 0; 78 79 virtual const TargetLDBackend& getTarget() const = 0; 80 81 virtual const char* getName(Type pType) const = 0; 82 83private: 84 const Layout* m_pLayout; 85 86}; 87 88} // namespace of mcld 89 90#endif 91 92