Skip to content

Commit 4af7185

Browse files
Fix demangle
1 parent f55485a commit 4af7185

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
@@ -3552,15 +3552,23 @@ namespace Cpp {
35523552
static inline std::string DemangleNameForDlsym(const std::string& name) {
35533553
std::string nameForDlsym = name;
35543554

3555-
#if defined(R__MACOSX) || defined(R__WIN32)
3555+
static bool is_demangle_active = false;
3556+
static bool demangle = false;
3557+
if (!is_demangle_active) {
3558+
auto& I = getInterp();
3559+
llvm::orc::LLJIT& EE = *compat::getExecutionEngine(I);
3560+
auto t = EE.getTargetMachine().getTargetTriple();
3561+
demangle = t.isOSDarwin() || t.isWindows();
3562+
is_demangle_active = true;
3563+
}
3564+
35563565
// The JIT gives us a mangled name which has an additional leading underscore
35573566
// on macOS and Windows, for instance __ZN8TRandom34RndmEv. However, dlsym
35583567
// requires us to remove it.
35593568
// FIXME: get this information from the DataLayout via getGlobalPrefix()!
3560-
if (nameForDlsym[0] == '_')
3569+
if (demangle && nameForDlsym[0] == '_')
35613570
nameForDlsym.erase(0, 1);
3562-
#endif //R__MACOSX
3563-
3571+
}
35643572
return nameForDlsym;
35653573
}
35663574

0 commit comments

Comments
 (0)