• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- MipsRelocator.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 MIPS_RELOCATION_FACTORY_H
10 #define MIPS_RELOCATION_FACTORY_H
11 #ifdef ENABLE_UNITTEST
12 #include <gtest.h>
13 #endif
14 
15 #include <mcld/LD/Relocator.h>
16 #include <mcld/Support/GCFactory.h>
17 #include "MipsLDBackend.h"
18 
19 namespace mcld {
20 
21 /** \class MipsRelocator
22  *  \brief MipsRelocator creates and destroys the Mips relocations.
23  */
24 class MipsRelocator : public Relocator
25 {
26 public:
27   enum ReservedEntryType {
28     None          = 0,  // no reserved entry
29     ReserveRel    = 1,  // reserve a dynamic relocation entry
30     ReserveGot    = 2,  // reserve a GOT entry
31     ReserveGpDisp = 8   // reserve _gp_disp symbol
32   };
33 
34 public:
35   MipsRelocator(MipsGNULDBackend& pParent, const LinkerConfig& pConfig);
36 
37   /// scanRelocation - determine the empty entries are needed or not and
38   /// create the empty entries if needed.
39   /// For Mips, the GOT, GP, and dynamic relocation entries are check to create.
40   void scanRelocation(Relocation& pReloc,
41                       IRBuilder& pBuilder,
42                       Module& pModule,
43                       LDSection& pSection);
44 
45   /// initializeScan - do initialization before scan relocations in pInput
46   /// @return - return true for initialization success
47   bool initializeScan(Input& pInput);
48 
49   /// finalizeScan - do finalization after scan relocations in pInput
50   /// @return - return true for finalization success
51   bool finalizeScan(Input& pInput);
52 
53   /// initializeApply - do initialization before apply relocations in pInput
54   /// @return - return true for initialization success
55   bool initializeApply(Input& pInput);
56 
57   /// finalizeApply - do finalization after apply relocations in pInput
58   /// @return - return true for finalization success
59   bool finalizeApply(Input& pInput);
60 
61   Result applyRelocation(Relocation& pRelocation);
62 
getApplyingInput()63   const Input& getApplyingInput() const
64   { return *m_pApplyingInput; }
65 
getTarget()66   MipsGNULDBackend& getTarget()
67   { return m_Target; }
68 
getTarget()69   const MipsGNULDBackend& getTarget() const
70   { return m_Target; }
71 
72   // Get last calculated AHL.
getAHL()73   int32_t getAHL() const
74   { return m_AHL; }
75 
76   // Set last calculated AHL.
setAHL(int32_t pAHL)77   void setAHL(int32_t pAHL)
78   { m_AHL = pAHL; }
79 
80   const char* getName(Relocation::Type pType) const;
81 
82   Size getSize(Relocation::Type pType) const;
83 
84 private:
85   void scanLocalReloc(Relocation& pReloc,
86                       IRBuilder& pBuilder,
87                       const LDSection& pSection);
88 
89   void scanGlobalReloc(Relocation& pReloc,
90                        IRBuilder& pBuilder,
91                        const LDSection& pSection);
92 
93 private:
94   MipsGNULDBackend& m_Target;
95   Input* m_pApplyingInput;
96   int32_t m_AHL;
97 };
98 
99 } // namespace of mcld
100 
101 #endif
102