diff options
author | Lang Hames <lhames@gmail.com> | 2016-03-03 21:23:15 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-03-03 21:23:15 +0000 |
commit | 3b514554a2ab643813c91f161d69c5a5c305efcf (patch) | |
tree | 9d4c90086d2f8914b1a2f10ff9b3402675a9d747 /llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp | |
parent | 30138256fa629a78da3bcc587a0885dd4a8bdd7a (diff) | |
download | llvm-3b514554a2ab643813c91f161d69c5a5c305efcf.zip llvm-3b514554a2ab643813c91f161d69c5a5c305efcf.tar.gz llvm-3b514554a2ab643813c91f161d69c5a5c305efcf.tar.bz2 |
[RuntimeDyld] Fix '_' stripping in RTDyldMemoryManager::getSymbolAddressInProcess.
The RTDyldMemoryManager::getSymbolAddressInProcess method accepts a
linker-mangled symbol name, but it calls through to dlsym to do the lookup (via
DynamicLibrary::SearchForAddressOfSymbol), and dlsym expects an unmangled
symbol name.
Historically we've attempted to "demangle" by removing leading '_'s on all
platforms, and fallen back to an extra search if that failed. That's broken, as
it can cause symbols to resolve incorrectly on platforms that don't do mangling
if you query '_foo' and the process also happens to contain a 'foo'.
Fix this by demangling conditionally based on the host platform. That's safe
here because this function is specifically for symbols in the host process, so
the usual cross-process JIT looking concerns don't apply.
M unittests/ExecutionEngine/ExecutionEngineTest.cpp
M lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
llvm-svn: 262657
Diffstat (limited to 'llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp index a9f8ab7..e39acc7 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp @@ -262,18 +262,15 @@ RTDyldMemoryManager::getSymbolAddressInProcess(const std::string &Name) { // is called before ExecutionEngine::runFunctionAsMain() is called. if (Name == "__main") return (uint64_t)&jit_noop; - // Try to demangle Name before looking it up in the process, otherwise symbol - // '_<Name>' (if present) will shadow '<Name>', and there will be no way to - // refer to the latter. - const char *NameStr = Name.c_str(); + // DynamicLibrary::SearchForAddresOfSymbol expects an unmangled 'C' symbol + // name so ff we're on Darwin, strip the leading '_' off. +#ifdef __APPLE__ if (NameStr[0] == '_') - if (void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr + 1)) - return (uint64_t)Ptr; + ++NameStr; +#endif - // If we Name did not require demangling, or we failed to find the demangled - // name, try again without demangling. return (uint64_t)sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr); } @@ -284,6 +281,7 @@ void *RTDyldMemoryManager::getPointerToNamedFunction(const std::string &Name, if (!Addr && AbortOnFailure) report_fatal_error("Program used external function '" + Name + "' which could not be resolved!"); + return (void*)Addr; } |