Revert a series of commits to MCJIT to get the build working in CMake
[oota-llvm.git] / lib / ExecutionEngine / RuntimeDyld / RuntimeDyldELF.h
1 //===-- RuntimeDyldELF.h - Run-time dynamic linker for MC-JIT ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // ELF support for MC-JIT runtime dynamic linker.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_RUNTIME_DYLD_ELF_H
15 #define LLVM_RUNTIME_DYLD_ELF_H
16
17 #include "RuntimeDyldImpl.h"
18
19 using namespace llvm;
20
21
22 namespace llvm {
23 class RuntimeDyldELF : public RuntimeDyldImpl {
24     // For each symbol, keep a list of relocations based on it. Anytime
25     // its address is reassigned (the JIT re-compiled the function, e.g.),
26     // the relocations get re-resolved.
27     struct RelocationEntry {
28       // Function or section this relocation is contained in.
29       std::string Target;
30       // Offset into the target function or section for the relocation.
31       uint32_t    Offset;
32       // Relocation type
33       uint32_t    Type;
34       // Addend encoded in the instruction itself, if any.
35       int32_t     Addend;
36       // Has the relocation been recalcuated as an offset within a function?
37       bool        IsFunctionRelative;
38       // Has this relocation been resolved previously?
39       bool        isResolved;
40
41       RelocationEntry(StringRef t,
42                       uint32_t offset,
43                       uint32_t type,
44                       int32_t addend,
45                       bool isFunctionRelative)
46         : Target(t)
47         , Offset(offset)
48         , Type(type)
49         , Addend(addend)
50         , IsFunctionRelative(isFunctionRelative)
51         , isResolved(false) { }
52     };
53     typedef SmallVector<RelocationEntry, 4> RelocationList;
54     StringMap<RelocationList> Relocations;
55     unsigned Arch;
56
57     void resolveRelocations();
58
59     void resolveX86_64Relocation(StringRef Name,
60                                  uint8_t *Addr,
61                                  const RelocationEntry &RE);
62
63     void resolveX86Relocation(StringRef Name,
64                               uint8_t *Addr,
65                               const RelocationEntry &RE);
66
67     void resolveArmRelocation(StringRef Name,
68                               uint8_t *Addr,
69                               const RelocationEntry &RE);
70
71     void resolveRelocation(StringRef Name,
72                            uint8_t *Addr,
73                            const RelocationEntry &RE);
74
75 public:
76   RuntimeDyldELF(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
77
78   bool loadObject(MemoryBuffer *InputBuffer);
79
80   void reassignSymbolAddress(StringRef Name, uint8_t *Addr);
81   void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
82
83   bool isCompatibleFormat(const MemoryBuffer *InputBuffer) const;
84 };
85
86 } // end namespace llvm
87
88 #endif 
89
90 //===-- RuntimeDyldELF.h - Run-time dynamic linker for MC-JIT ---*- C++ -*-===//
91 //
92 //                     The LLVM Compiler Infrastructure
93 //
94 // This file is distributed under the University of Illinois Open Source
95 // License. See LICENSE.TXT for details.
96 //
97 //===----------------------------------------------------------------------===//
98 //
99 // ELF support for MC-JIT runtime dynamic linker.
100 //
101 //===----------------------------------------------------------------------===//
102
103 #ifndef LLVM_RUNTIME_DYLD_ELF_H
104 #define LLVM_RUNTIME_DYLD_ELF_H
105
106 #include "RuntimeDyldImpl.h"
107
108 using namespace llvm;
109
110
111 namespace llvm {
112 class RuntimeDyldELF : public RuntimeDyldImpl {
113     // For each symbol, keep a list of relocations based on it. Anytime
114     // its address is reassigned (the JIT re-compiled the function, e.g.),
115     // the relocations get re-resolved.
116     struct RelocationEntry {
117       // Function or section this relocation is contained in.
118       std::string Target;
119       // Offset into the target function or section for the relocation.
120       uint32_t    Offset;
121       // Relocation type
122       uint32_t    Type;
123       // Addend encoded in the instruction itself, if any.
124       int32_t     Addend;
125       // Has the relocation been recalcuated as an offset within a function?
126       bool        IsFunctionRelative;
127       // Has this relocation been resolved previously?
128       bool        isResolved;
129
130       RelocationEntry(StringRef t,
131                       uint32_t offset,
132                       uint32_t type,
133                       int32_t addend,
134                       bool isFunctionRelative)
135         : Target(t)
136         , Offset(offset)
137         , Type(type)
138         , Addend(addend)
139         , IsFunctionRelative(isFunctionRelative)
140         , isResolved(false) { }
141     };
142     typedef SmallVector<RelocationEntry, 4> RelocationList;
143     StringMap<RelocationList> Relocations;
144     unsigned Arch;
145
146     void resolveRelocations();
147
148     void resolveX86_64Relocation(StringRef Name,
149                                  uint8_t *Addr,
150                                  const RelocationEntry &RE);
151
152     void resolveX86Relocation(StringRef Name,
153                               uint8_t *Addr,
154                               const RelocationEntry &RE);
155
156     void resolveArmRelocation(StringRef Name,
157                               uint8_t *Addr,
158                               const RelocationEntry &RE);
159
160     void resolveRelocation(StringRef Name,
161                            uint8_t *Addr,
162                            const RelocationEntry &RE);
163
164 public:
165   RuntimeDyldELF(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
166
167   bool loadObject(MemoryBuffer *InputBuffer);
168
169   void reassignSymbolAddress(StringRef Name, uint8_t *Addr);
170   void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
171
172   bool isCompatibleFormat(const MemoryBuffer *InputBuffer) const;
173 };
174
175 } // end namespace llvm
176
177 #endif 
178