RelocationFactory.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_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/Fragment/Relocation.h>
16
17namespace mcld {
18
19class LDSymbol;
20class ResolveInfo;
21class FragmentRef;
22class FragmentLinker;
23class Layout;
24class GOT;
25class TargetLDBackend;
26class LinkerConfig;
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  typedef Relocation::SWord SWord;
40
41  enum Result {
42    OK,
43    BadReloc,
44    Overflow,
45    Unsupport,
46    Unknown
47  };
48
49public:
50  explicit RelocationFactory(size_t pNum);
51
52  virtual ~RelocationFactory();
53
54  /// apply - general apply function
55  virtual Result applyRelocation(Relocation& pRelocation) = 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 setFragmentLinker(const FragmentLinker& pLinker);
73
74  // ------ observers -----//
75  const FragmentLinker& getFragmentLinker() const;
76
77  bool hasFragmentLinker() const;
78
79  virtual TargetLDBackend& getTarget() = 0;
80
81  virtual const TargetLDBackend& getTarget() const = 0;
82
83  virtual const char* getName(Type pType) const = 0;
84
85private:
86  const FragmentLinker* m_pLinker;
87
88};
89
90} // namespace of mcld
91
92#endif
93
94