Skip to content

Commit 3b7ebc6

Browse files
Fix demangle
1 parent dd158a2 commit 3b7ebc6

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
@@ -3362,15 +3362,23 @@ namespace Cpp {
33623362
static inline std::string DemangleNameForDlsym(const std::string& name) {
33633363
std::string nameForDlsym = name;
33643364

3365-
#if defined(R__MACOSX) || defined(R__WIN32)
3365+
static bool is_demangle_active = false;
3366+
static bool demangle = false;
3367+
if (!is_demangle_active) {
3368+
auto& I = getInterp();
3369+
llvm::orc::LLJIT& EE = *compat::getExecutionEngine(I);
3370+
auto t = EE.getTargetMachine().getTargetTriple();
3371+
demangle = t.isOSDarwin() || t.isWindows();
3372+
is_demangle_active = true;
3373+
}
3374+
33663375
// The JIT gives us a mangled name which has an additional leading underscore
33673376
// on macOS and Windows, for instance __ZN8TRandom34RndmEv. However, dlsym
33683377
// requires us to remove it.
33693378
// FIXME: get this information from the DataLayout via getGlobalPrefix()!
3370-
if (nameForDlsym[0] == '_')
3379+
if (demangle && nameForDlsym[0] == '_')
33713380
nameForDlsym.erase(0, 1);
3372-
#endif //R__MACOSX
3373-
3381+
}
33743382
return nameForDlsym;
33753383
}
33763384

0 commit comments

Comments
 (0)