mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-10 04:33:40 +00:00
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
This commit is contained in:
parent
16228c08b4
commit
e846db6675
@ -65,6 +65,7 @@ class ExecutionEngine {
|
|||||||
const TargetData *TD;
|
const TargetData *TD;
|
||||||
ExecutionEngineState state;
|
ExecutionEngineState state;
|
||||||
bool LazyCompilationDisabled;
|
bool LazyCompilationDisabled;
|
||||||
|
bool SymbolSearchingDisabled;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Modules - This is a list of ModuleProvider's that we are JIT'ing from. We
|
/// Modules - This is a list of ModuleProvider's that we are JIT'ing from. We
|
||||||
@ -243,13 +244,22 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// DisableLazyCompilation - If called, the JIT will abort if lazy compilation
|
/// DisableLazyCompilation - If called, the JIT will abort if lazy compilation
|
||||||
// is ever attempted.
|
/// is ever attempted.
|
||||||
void DisableLazyCompilation() {
|
void DisableLazyCompilation(bool Disabled = true) {
|
||||||
LazyCompilationDisabled = true;
|
LazyCompilationDisabled = Disabled;
|
||||||
}
|
}
|
||||||
bool isLazyCompilationDisabled() const {
|
bool isLazyCompilationDisabled() const {
|
||||||
return LazyCompilationDisabled;
|
return LazyCompilationDisabled;
|
||||||
}
|
}
|
||||||
|
/// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
|
||||||
|
/// symbols with dlsym. A client can still use InstallLazyFunctionCreator to
|
||||||
|
/// resolve symbols in a custom way.
|
||||||
|
void DisableSymbolSearching(bool Disabled = true) {
|
||||||
|
SymbolSearchingDisabled = Disabled;
|
||||||
|
}
|
||||||
|
bool isSymbolSearchingDisabled() const {
|
||||||
|
return SymbolSearchingDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// InstallLazyFunctionCreator - If an unknown function is needed, the
|
/// InstallLazyFunctionCreator - If an unknown function is needed, the
|
||||||
|
@ -91,44 +91,46 @@ static int jit_atexit(void (*Fn)(void)) {
|
|||||||
/// for resolving library symbols, not code generated symbols.
|
/// for resolving library symbols, not code generated symbols.
|
||||||
///
|
///
|
||||||
void *JIT::getPointerToNamedFunction(const std::string &Name) {
|
void *JIT::getPointerToNamedFunction(const std::string &Name) {
|
||||||
// Check to see if this is one of the functions we want to intercept. Note,
|
if (!isSymbolSearchingDisabled()) {
|
||||||
// we cast to intptr_t here to silence a -pedantic warning that complains
|
// Check to see if this is one of the functions we want to intercept. Note,
|
||||||
// about casting a function pointer to a normal pointer.
|
// we cast to intptr_t here to silence a -pedantic warning that complains
|
||||||
if (Name == "exit") return (void*)(intptr_t)&jit_exit;
|
// about casting a function pointer to a normal pointer.
|
||||||
if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
|
if (Name == "exit") return (void*)(intptr_t)&jit_exit;
|
||||||
|
if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
|
||||||
|
|
||||||
const char *NameStr = Name.c_str();
|
const char *NameStr = Name.c_str();
|
||||||
// If this is an asm specifier, skip the sentinal.
|
// If this is an asm specifier, skip the sentinal.
|
||||||
if (NameStr[0] == 1) ++NameStr;
|
if (NameStr[0] == 1) ++NameStr;
|
||||||
|
|
||||||
// If it's an external function, look it up in the process image...
|
// If it's an external function, look it up in the process image...
|
||||||
void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
|
void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
|
||||||
if (Ptr) return Ptr;
|
|
||||||
|
|
||||||
// If it wasn't found and if it starts with an underscore ('_') character, and
|
|
||||||
// has an asm specifier, try again without the underscore.
|
|
||||||
if (Name[0] == 1 && NameStr[0] == '_') {
|
|
||||||
Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
|
|
||||||
if (Ptr) return Ptr;
|
if (Ptr) return Ptr;
|
||||||
}
|
|
||||||
|
// If it wasn't found and if it starts with an underscore ('_') character,
|
||||||
// darwin/ppc adds $LDBLStub suffixes to various symbols like printf. These
|
// and has an asm specifier, try again without the underscore.
|
||||||
// are references to hidden visibility symbols that dlsym cannot resolve. If
|
if (Name[0] == 1 && NameStr[0] == '_') {
|
||||||
// we have one of these, strip off $LDBLStub and try again.
|
Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
|
||||||
|
if (Ptr) return Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Darwin/PPC adds $LDBLStub suffixes to various symbols like printf. These
|
||||||
|
// are references to hidden visibility symbols that dlsym cannot resolve.
|
||||||
|
// If we have one of these, strip off $LDBLStub and try again.
|
||||||
#if defined(__APPLE__) && defined(__ppc__)
|
#if defined(__APPLE__) && defined(__ppc__)
|
||||||
if (Name.size() > 9 && Name[Name.size()-9] == '$' &&
|
if (Name.size() > 9 && Name[Name.size()-9] == '$' &&
|
||||||
memcmp(&Name[Name.size()-8], "LDBLStub", 8) == 0) {
|
memcmp(&Name[Name.size()-8], "LDBLStub", 8) == 0) {
|
||||||
// First try turning $LDBLStub into $LDBL128. If that fails, strip it off.
|
// First try turning $LDBLStub into $LDBL128. If that fails, strip it off.
|
||||||
// This mirrors logic in libSystemStubs.a.
|
// This mirrors logic in libSystemStubs.a.
|
||||||
std::string Prefix = std::string(Name.begin(), Name.end()-9);
|
std::string Prefix = std::string(Name.begin(), Name.end()-9);
|
||||||
if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128"))
|
if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128"))
|
||||||
return Ptr;
|
return Ptr;
|
||||||
if (void *Ptr = getPointerToNamedFunction(Prefix))
|
if (void *Ptr = getPointerToNamedFunction(Prefix))
|
||||||
return Ptr;
|
return Ptr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/// If a LazyFunctionCreator is installed, use it to get/create the function.
|
/// If a LazyFunctionCreator is installed, use it to get/create the function.
|
||||||
if (LazyFunctionCreator)
|
if (LazyFunctionCreator)
|
||||||
if (void *RP = LazyFunctionCreator(Name))
|
if (void *RP = LazyFunctionCreator(Name))
|
||||||
return RP;
|
return RP;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user