LLVM: lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#include "llvm/Config/config.h"
18#include
19
20#ifdef __linux__
21
22
23#include <fcntl.h>
24#include <sys/stat.h>
25#include <unistd.h>
26#endif
27
28namespace llvm {
29
31
32#if defined(HAVE_REGISTER_FRAME) && defined(HAVE_DEREGISTER_FRAME) && \
33 !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
36#else
37
38
39
40
42 static bool Searched = false;
43 static void (*rf)(void *) = 0;
44
45 if (!Searched) {
46 Searched = true;
47 *(void **)&rf =
49 }
50 if (rf)
51 rf(p);
52}
53
55 static bool Searched = false;
56 static void (*df)(void *) = 0;
57
58 if (!Searched) {
59 Searched = true;
61 "__deregister_frame");
62 }
63 if (df)
64 df(p);
65}
66#endif
67
68
69
70#if defined(HAVE_UNW_ADD_DYNAMIC_FDE) || defined(__APPLE__)
71
72static const char *processFDE(const char *Entry, bool isDeregister) {
74 uint32_t Length = *((const uint32_t *)P);
75 P += 4;
76 uint32_t Offset = *((const uint32_t *)P);
78 if (isDeregister)
80 else
82 }
84}
85
86
87
88
90 size_t Size) {
91
92
93
94 const char *P = (const char *)Addr;
95 const char *End = P + Size;
96 while (P != End)
98}
99
101 size_t Size) {
102 const char *P = (const char *)Addr;
103 const char *End = P + Size;
104 while (P != End)
106}
107
108#else
109
111 size_t Size) {
112
113
114
115
116
118}
119
124
125#endif
126
132
138
142
143
144
145
146#if defined(__BIONIC__) && defined(__arm__)
147
148
149
150
151
152
153#define ARM_MATH_IMPORTS(PP) \
154 PP(__aeabi_d2f) \
155 PP(__aeabi_d2iz) \
156 PP(__aeabi_d2lz) \
157 PP(__aeabi_d2uiz) \
158 PP(__aeabi_d2ulz) \
159 PP(__aeabi_dadd) \
160 PP(__aeabi_dcmpeq) \
161 PP(__aeabi_dcmpge) \
162 PP(__aeabi_dcmpgt) \
163 PP(__aeabi_dcmple) \
164 PP(__aeabi_dcmplt) \
165 PP(__aeabi_dcmpun) \
166 PP(__aeabi_ddiv) \
167 PP(__aeabi_dmul) \
168 PP(__aeabi_dsub) \
169 PP(__aeabi_f2d) \
170 PP(__aeabi_f2iz) \
171 PP(__aeabi_f2lz) \
172 PP(__aeabi_f2uiz) \
173 PP(__aeabi_f2ulz) \
174 PP(__aeabi_fadd) \
175 PP(__aeabi_fcmpeq) \
176 PP(__aeabi_fcmpge) \
177 PP(__aeabi_fcmpgt) \
178 PP(__aeabi_fcmple) \
179 PP(__aeabi_fcmplt) \
180 PP(__aeabi_fcmpun) \
181 PP(__aeabi_fdiv) \
182 PP(__aeabi_fmul) \
183 PP(__aeabi_fsub) \
184 PP(__aeabi_i2d) \
185 PP(__aeabi_i2f) \
186 PP(__aeabi_idiv) \
187 PP(__aeabi_idivmod) \
188 PP(__aeabi_l2d) \
189 PP(__aeabi_l2f) \
190 PP(__aeabi_lasr) \
191 PP(__aeabi_ldivmod) \
192 PP(__aeabi_llsl) \
193 PP(__aeabi_llsr) \
194 PP(__aeabi_lmul) \
195 PP(__aeabi_ui2d) \
196 PP(__aeabi_ui2f) \
197 PP(__aeabi_uidiv) \
198 PP(__aeabi_uidivmod) \
199 PP(__aeabi_ul2d) \
200 PP(__aeabi_ul2f) \
201 PP(__aeabi_uldivmod)
202
203
204
205
206
207
208#define ARM_MATH_DECL(name) extern "C" void name();
209ARM_MATH_IMPORTS(ARM_MATH_DECL)
210#undef ARM_MATH_DECL
211#endif
212
213#if defined(__linux__) && defined(__GLIBC__) && \
214 (defined(__i386__) || defined(__x86_64__))
216#endif
217
220
221
222
223#if defined(__linux__) && defined(__GLIBC__)
224
225
226
227
228
229
230
231
232
233 if (Name == "stat") return (uint64_t)&stat;
234 if (Name == "fstat") return (uint64_t)&fstat;
235 if (Name == "lstat") return (uint64_t)&lstat;
236 if (Name == "stat64") return (uint64_t)&stat64;
237 if (Name == "fstat64") return (uint64_t)&fstat64;
238 if (Name == "lstat64") return (uint64_t)&lstat64;
239 if (Name == "atexit") return (uint64_t)&atexit;
240 if (Name == "mknod") return (uint64_t)&mknod;
241
242#if defined(__i386__) || defined(__x86_64__)
243
244 if (&__morestack && Name == "__morestack")
245 return (uint64_t)&__morestack;
246#endif
247#endif
248
249
250#if defined(__BIONIC__) && defined(__arm__)
251 if (Name.compare(0, 8, "__aeabi_") == 0) {
252
253
254#define ARM_MATH_CHECK(fn) if (Name == #fn) return (uint64_t)&fn;
255 ARM_MATH_IMPORTS(ARM_MATH_CHECK)
256#undef ARM_MATH_CHECK
257 }
258#endif
259
260
261
262
263
264
265
267
268 const char *NameStr = Name.c_str();
269
270
271
272#ifdef __APPLE__
273 if (NameStr[0] == '_')
274 ++NameStr;
275#endif
276
278}
279
281 bool AbortOnFailure) {
283
284 if (!Addr && AbortOnFailure)
286 "' which could not be resolved!");
287
288 return (void*)Addr;
289}
290
291void RTDyldMemoryManager::anchor() {}
292void MCJITMemoryManager::anchor() {}
293}
#define LLVM_ATTRIBUTE_WEAK
static void deregisterEHFramesInProcess(uint8_t *Addr, size_t Size)
Deregister EH frames in the current process.
Definition RTDyldMemoryManager.cpp:120
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override
Register the EH frames with the runtime so that c++ exceptions work.
Definition RTDyldMemoryManager.cpp:127
virtual void * getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure=true)
This method returns the address of the specified function.
Definition RTDyldMemoryManager.cpp:280
virtual uint64_t getSymbolAddress(const std::string &Name)
Legacy symbol lookup - DEPRECATED!
static uint64_t getSymbolAddressInProcess(const std::string &Name)
This method returns the address of the specified function or variable in the current process.
Definition RTDyldMemoryManager.cpp:219
static void registerEHFramesInProcess(uint8_t *Addr, size_t Size)
Register EH frames in the current process.
Definition RTDyldMemoryManager.cpp:110
~RTDyldMemoryManager() override
void deregisterEHFrames() override
Definition RTDyldMemoryManager.cpp:133
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static LLVM_ABI void * SearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName.
This is an optimization pass for GlobalISel generic memory operations.
static int jit_noop()
Definition RTDyldMemoryManager.cpp:139
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
void __register_frame(void *)
void __deregister_frame(void *)