@@ -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