Skip to content

Commit b45bc66

Browse files
Fix demangle
1 parent 04344f9 commit b45bc66

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
@@ -3278,15 +3278,23 @@ namespace Cpp {
32783278
static inline std::string DemangleNameForDlsym(const std::string& name) {
32793279
std::string nameForDlsym = name;
32803280

3281-
#if defined(R__MACOSX) || defined(R__WIN32)
3281+
static bool is_demangle_active = false;
3282+
static bool demangle = false;
3283+
if (!is_demangle_active) {
3284+
auto& I = getInterp();
3285+
llvm::orc::LLJIT& EE = *compat::getExecutionEngine(I);
3286+
auto t = EE.getTargetMachine().getTargetTriple();
3287+
demangle = t.isOSDarwin() || t.isWindows();
3288+
is_demangle_active = true;
3289+
}
3290+
32823291
// The JIT gives us a mangled name which has an additional leading underscore
32833292
// on macOS and Windows, for instance __ZN8TRandom34RndmEv. However, dlsym
32843293
// requires us to remove it.
32853294
// FIXME: get this information from the DataLayout via getGlobalPrefix()!
3286-
if (nameForDlsym[0] == '_')
3295+
if (demangle && nameForDlsym[0] == '_')
32873296
nameForDlsym.erase(0, 1);
3288-
#endif //R__MACOSX
3289-
3297+
}
32903298
return nameForDlsym;
32913299
}
32923300

0 commit comments

Comments
 (0)