Skip to content

Commit 33fc684

Browse files
alexander-penevmcbarton
authored andcommitted
Fix demangle
1 parent bde824b commit 33fc684

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
@@ -3388,15 +3388,23 @@ namespace Cpp {
33883388
static inline std::string DemangleNameForDlsym(const std::string& name) {
33893389
std::string nameForDlsym = name;
33903390

3391-
#if defined(R__MACOSX) || defined(R__WIN32)
3391+
static bool is_demangle_active = false;
3392+
static bool demangle = false;
3393+
if (!is_demangle_active) {
3394+
auto& I = getInterp();
3395+
llvm::orc::LLJIT& EE = *compat::getExecutionEngine(I);
3396+
auto t = EE.getTargetMachine().getTargetTriple();
3397+
demangle = t.isOSDarwin() || t.isWindows();
3398+
is_demangle_active = true;
3399+
}
3400+
33923401
// The JIT gives us a mangled name which has an additional leading underscore
33933402
// on macOS and Windows, for instance __ZN8TRandom34RndmEv. However, dlsym
33943403
// requires us to remove it.
33953404
// FIXME: get this information from the DataLayout via getGlobalPrefix()!
3396-
if (nameForDlsym[0] == '_')
3405+
if (demangle && nameForDlsym[0] == '_')
33973406
nameForDlsym.erase(0, 1);
3398-
#endif //R__MACOSX
3399-
3407+
}
34003408
return nameForDlsym;
34013409
}
34023410

0 commit comments

Comments
 (0)