Skip to content

Commit 72c549e

Browse files
hahnjodevajithvs
authored andcommitted
[cling] Replace symbols in platform Dylib
LLVM now defines multiple Dylibs, and __cxa_atexit is provided in the <Platform> library.
1 parent 4565a9d commit 72c549e

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

interpreter/cling/lib/Interpreter/IncrementalJIT.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,14 +657,28 @@ IncrementalJIT::addOrReplaceDefinition(StringRef Name,
657657
ExecutorSymbolDef(KnownAddr, JITSymbolFlags::Exported));
658658
assert(Inserted && "Why wasn't this found in the initial Jit lookup?");
659659

660-
JITDylib& DyLib = Jit->getMainJITDylib();
661-
// We want to replace a symbol with a custom provided one.
662-
llvm::consumeError(DyLib.remove({It->first}));
660+
bool Defined = false;
661+
for (auto* Dylib :
662+
{&Jit->getMainJITDylib(), Jit->getPlatformJITDylib().get()}) {
663+
if (Dylib->remove({It->first})) {
664+
continue;
665+
}
663666

664-
if (Error Err = DyLib.define(absoluteSymbols({*It}))) {
665-
logAllUnhandledErrors(std::move(Err), errs(),
666-
"[IncrementalJIT] define() failed: ");
667-
return orc::ExecutorAddr();
667+
if (Error Err = Dylib->define(absoluteSymbols({*It}))) {
668+
logAllUnhandledErrors(std::move(Err), errs(),
669+
"[IncrementalJIT] define() failed: ");
670+
return orc::ExecutorAddr();
671+
}
672+
Defined = true;
673+
}
674+
675+
if (!Defined) {
676+
// Symbol was not found, just define it in the main library.
677+
if (Error Err = Jit->getMainJITDylib().define(absoluteSymbols({*It}))) {
678+
logAllUnhandledErrors(std::move(Err), errs(),
679+
"[IncrementalJIT] define() failed: ");
680+
return orc::ExecutorAddr();
681+
}
668682
}
669683

670684
return KnownAddr;

0 commit comments

Comments
 (0)