MacOS adds an extra "_" in front of symbol names.

This commit is contained in:
Axel Naumann 2015-02-11 11:45:01 +01:00 committed by sftnight
parent ebacb03d18
commit 1001c65f99

View File

@ -182,14 +182,21 @@ IncrementalJIT::IncrementalJIT(IncrementalExecutor& exe,
uint64_t IncrementalJIT::getSymbolAddressWithoutMangling(llvm::StringRef Name) { uint64_t IncrementalJIT::getSymbolAddressWithoutMangling(llvm::StringRef Name) {
if (Name == "__cxa_atexit") { #ifdef __APPLE__
// Apple adds an extra '_'
# define MANGLE_PREFIX "_"
#else
# define MANGLE_PREFIX ""
#endif
if (Name == MANGLE_PREFIX "__cxa_atexit") {
// Rewire __cxa_atexit to ~Interpreter(), thus also global destruction // Rewire __cxa_atexit to ~Interpreter(), thus also global destruction
// coming from the JIT. // coming from the JIT.
return (uint64_t)&local_cxa_atexit; return (uint64_t)&local_cxa_atexit;
} else if (Name == "__dso_handle") { } else if (Name == MANGLE_PREFIX "__dso_handle") {
// Provide IncrementalExecutor as the third argument to __cxa_atexit. // Provide IncrementalExecutor as the third argument to __cxa_atexit.
return (uint64_t)&m_Parent; return (uint64_t)&m_Parent;
} }
#undef MANGLE_PREFIX
if (uint64_t Addr = m_ExeMM->getSymbolAddress(Name)) if (uint64_t Addr = m_ExeMM->getSymbolAddress(Name))
return Addr; return Addr;
if (uint64_t Addr = m_LazyEmitLayer.getSymbolAddress(Name, false)) if (uint64_t Addr = m_LazyEmitLayer.getSymbolAddress(Name, false))