diff options
Diffstat (limited to 'llvm/lib/ExecutionEngine/RTDyldMemoryManager.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/RTDyldMemoryManager.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/llvm/lib/ExecutionEngine/RTDyldMemoryManager.cpp b/llvm/lib/ExecutionEngine/RTDyldMemoryManager.cpp index 1646937e816..9cbcd2fa814 100644 --- a/llvm/lib/ExecutionEngine/RTDyldMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/RTDyldMemoryManager.cpp @@ -253,19 +253,20 @@ uint64_t RTDyldMemoryManager::getSymbolAddress(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(); - void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr); - if (Ptr) - return (uint64_t)Ptr; - // If it wasn't found and if it starts with an underscore ('_') character, - // try again without the underscore. - if (NameStr[0] == '_') { - Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1); - if (Ptr) + if (NameStr[0] == '_') + if (void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr + 1)) return (uint64_t)Ptr; - } - return 0; + + // If we Name did not require demangling, or we failed to find the demangled + // name, try again without demangling. + if (void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr)) + return (uint64_t)Ptr; } void *RTDyldMemoryManager::getPointerToNamedFunction(const std::string &Name, |