llvm.org GIT mirror llvm / e846db6
Add a new flag that disables symbol lookup with dlsym when set. This allows a JIT client to completely control symbol lookup with the LazyFunctionCreator interface. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52335 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
2 changed file(s) with 49 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
6464 const TargetData *TD;
6565 ExecutionEngineState state;
6666 bool LazyCompilationDisabled;
67 bool SymbolSearchingDisabled;
6768
6869 protected:
6970 /// Modules - This is a list of ModuleProvider's that we are JIT'ing from. We
242243 }
243244
244245 /// DisableLazyCompilation - If called, the JIT will abort if lazy compilation
245 // is ever attempted.
246 void DisableLazyCompilation() {
247 LazyCompilationDisabled = true;
246 /// is ever attempted.
247 void DisableLazyCompilation(bool Disabled = true) {
248 LazyCompilationDisabled = Disabled;
248249 }
249250 bool isLazyCompilationDisabled() const {
250251 return LazyCompilationDisabled;
252 }
253 /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
254 /// symbols with dlsym. A client can still use InstallLazyFunctionCreator to
255 /// resolve symbols in a custom way.
256 void DisableSymbolSearching(bool Disabled = true) {
257 SymbolSearchingDisabled = Disabled;
258 }
259 bool isSymbolSearchingDisabled() const {
260 return SymbolSearchingDisabled;
251261 }
252262
253263
9090 /// for resolving library symbols, not code generated symbols.
9191 ///
9292 void *JIT::getPointerToNamedFunction(const std::string &Name) {
93 // Check to see if this is one of the functions we want to intercept. Note,
94 // we cast to intptr_t here to silence a -pedantic warning that complains
95 // about casting a function pointer to a normal pointer.
96 if (Name == "exit") return (void*)(intptr_t)&jit_exit;
97 if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
93 if (!isSymbolSearchingDisabled()) {
94 // Check to see if this is one of the functions we want to intercept. Note,
95 // we cast to intptr_t here to silence a -pedantic warning that complains
96 // about casting a function pointer to a normal pointer.
97 if (Name == "exit") return (void*)(intptr_t)&jit_exit;
98 if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
9899
99 const char *NameStr = Name.c_str();
100 // If this is an asm specifier, skip the sentinal.
101 if (NameStr[0] == 1) ++NameStr;
102
103 // If it's an external function, look it up in the process image...
104 void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
105 if (Ptr) return Ptr;
106
107 // If it wasn't found and if it starts with an underscore ('_') character, and
108 // has an asm specifier, try again without the underscore.
109 if (Name[0] == 1 && NameStr[0] == '_') {
110 Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
100 const char *NameStr = Name.c_str();
101 // If this is an asm specifier, skip the sentinal.
102 if (NameStr[0] == 1) ++NameStr;
103
104 // If it's an external function, look it up in the process image...
105 void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
111106 if (Ptr) return Ptr;
107
108 // If it wasn't found and if it starts with an underscore ('_') character,
109 // and has an asm specifier, try again without the underscore.
110 if (Name[0] == 1 && NameStr[0] == '_') {
111 Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
112 if (Ptr) return Ptr;
113 }
114
115 // Darwin/PPC adds $LDBLStub suffixes to various symbols like printf. These
116 // are references to hidden visibility symbols that dlsym cannot resolve.
117 // If we have one of these, strip off $LDBLStub and try again.
118 #if defined(__APPLE__) && defined(__ppc__)
119 if (Name.size() > 9 && Name[Name.size()-9] == '$' &&
120 memcmp(&Name[Name.size()-8], "LDBLStub", 8) == 0) {
121 // First try turning $LDBLStub into $LDBL128. If that fails, strip it off.
122 // This mirrors logic in libSystemStubs.a.
123 std::string Prefix = std::string(Name.begin(), Name.end()-9);
124 if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128"))
125 return Ptr;
126 if (void *Ptr = getPointerToNamedFunction(Prefix))
127 return Ptr;
128 }
129 #endif
112130 }
113131
114 // darwin/ppc adds $LDBLStub suffixes to various symbols like printf. These
115 // are references to hidden visibility symbols that dlsym cannot resolve. If
116 // we have one of these, strip off $LDBLStub and try again.
117 #if defined(__APPLE__) && defined(__ppc__)
118 if (Name.size() > 9 && Name[Name.size()-9] == '$' &&
119 memcmp(&Name[Name.size()-8], "LDBLStub", 8) == 0) {
120 // First try turning $LDBLStub into $LDBL128. If that fails, strip it off.
121 // This mirrors logic in libSystemStubs.a.
122 std::string Prefix = std::string(Name.begin(), Name.end()-9);
123 if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128"))
124 return Ptr;
125 if (void *Ptr = getPointerToNamedFunction(Prefix))
126 return Ptr;
127 }
128 #endif
129
130 /// If a LazyFunctionCreator is installed, use it to get/create the function.
132 /// If a LazyFunctionCreator is installed, use it to get/create the function.
131133 if (LazyFunctionCreator)
132134 if (void *RP = LazyFunctionCreator(Name))
133135 return RP;