Skip to content

Commit 25e1b55

Browse files
Fix demangle
1 parent 3d42cd8 commit 25e1b55

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
@@ -3520,15 +3520,23 @@ namespace Cpp {
35203520
static inline std::string DemangleNameForDlsym(const std::string& name) {
35213521
std::string nameForDlsym = name;
35223522

3523-
#if defined(R__MACOSX) || defined(R__WIN32)
3523+
static bool is_demangle_active = false;
3524+
static bool demangle = false;
3525+
if (!is_demangle_active) {
3526+
auto& I = getInterp();
3527+
llvm::orc::LLJIT& EE = *compat::getExecutionEngine(I);
3528+
auto t = EE.getTargetMachine().getTargetTriple();
3529+
demangle = t.isOSDarwin() || t.isWindows();
3530+
is_demangle_active = true;
3531+
}
3532+
35243533
// The JIT gives us a mangled name which has an additional leading underscore
35253534
// on macOS and Windows, for instance __ZN8TRandom34RndmEv. However, dlsym
35263535
// requires us to remove it.
35273536
// FIXME: get this information from the DataLayout via getGlobalPrefix()!
3528-
if (nameForDlsym[0] == '_')
3537+
if (demangle && nameForDlsym[0] == '_')
35293538
nameForDlsym.erase(0, 1);
3530-
#endif //R__MACOSX
3531-
3539+
}
35323540
return nameForDlsym;
35333541
}
35343542

0 commit comments

Comments
 (0)