Skip to content

Commit e09cef7

Browse files
Fix demangle
1 parent 1da60a6 commit e09cef7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,15 +3441,23 @@ namespace Cpp {
34413441
static inline std::string DemangleNameForDlsym(const std::string& name) {
34423442
std::string nameForDlsym = name;
34433443

3444-
#if defined(R__MACOSX) || defined(R__WIN32)
3444+
static bool is_demangle_active = false;
3445+
static bool demangle = false;
3446+
if (!is_demangle_active) {
3447+
auto& I = getInterp();
3448+
llvm::orc::LLJIT& EE = *compat::getExecutionEngine(I);
3449+
auto t = EE.getTargetMachine().getTargetTriple();
3450+
demangle = t.isOSDarwin() || t.isWindows();
3451+
is_demangle_active = true;
3452+
}
3453+
34453454
// The JIT gives us a mangled name which has an additional leading underscore
34463455
// on macOS and Windows, for instance __ZN8TRandom34RndmEv. However, dlsym
34473456
// requires us to remove it.
34483457
// FIXME: get this information from the DataLayout via getGlobalPrefix()!
3449-
if (nameForDlsym[0] == '_')
3458+
if (demangle && nameForDlsym[0] == '_')
34503459
nameForDlsym.erase(0, 1);
3451-
#endif //R__MACOSX
3452-
3460+
}
34533461
return nameForDlsym;
34543462
}
34553463

0 commit comments

Comments
 (0)