diff --git a/llvm/examples/OrcV2Examples/LLJITWithCustomObjectLinkingLayer/LLJITWithCustomObjectLinkingLayer.cpp b/llvm/examples/OrcV2Examples/LLJITWithCustomObjectLinkingLayer/LLJITWithCustomObjectLinkingLayer.cpp --- a/llvm/examples/OrcV2Examples/LLJITWithCustomObjectLinkingLayer/LLJITWithCustomObjectLinkingLayer.cpp +++ b/llvm/examples/OrcV2Examples/LLJITWithCustomObjectLinkingLayer/LLJITWithCustomObjectLinkingLayer.cpp @@ -45,7 +45,7 @@ LLJITBuilder() .setJITTargetMachineBuilder(std::move(JTMB)) .setObjectLinkingLayerCreator( - [&](ExecutionSession &ES, const Triple &TT) { + [&](ExecutionSession &ES, const Triple &TT, Error &Err) { return std::make_unique( ES, std::make_unique()); }) diff --git a/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp b/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp --- a/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp +++ b/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp @@ -63,7 +63,8 @@ ExitOnErr(LLJITBuilder() .setJITTargetMachineBuilder(std::move(JTMB)) .setObjectLinkingLayerCreator([&](ExecutionSession &ES, - const Triple &TT) { + const Triple &TT, + Error &Err) { auto GetMemMgr = []() { return std::make_unique(); }; diff --git a/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp b/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp --- a/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp +++ b/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp @@ -141,7 +141,7 @@ LLJITBuilder() .setJITTargetMachineBuilder(std::move(JTMB)) .setObjectLinkingLayerCreator( - [&](ExecutionSession &ES, const Triple &TT) { + [&](ExecutionSession &ES, const Triple &TT, Error &Err) { // Create ObjectLinkingLayer. auto ObjLinkingLayer = std::make_unique( ES, std::make_unique()); diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h --- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h @@ -186,7 +186,7 @@ } protected: - static std::unique_ptr + static Expected> createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES); static Expected> @@ -251,7 +251,7 @@ class LLJITBuilderState { public: using ObjectLinkingLayerCreator = std::function( - ExecutionSession &, const Triple &TT)>; + ExecutionSession &, const Triple &, Error &)>; using CompileFunctionCreator = std::function>( diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -954,8 +954,8 @@ JTMB->setRelocationModel(Reloc::PIC_); JTMB->setCodeModel(CodeModel::Small); CreateObjectLinkingLayer = - [TPC = this->TPC](ExecutionSession &ES, - const Triple &) -> std::unique_ptr { + [TPC = this->TPC](ExecutionSession &ES, const Triple &, + Error &Err) -> std::unique_ptr { std::unique_ptr ObjLinkingLayer; if (TPC) ObjLinkingLayer = @@ -1011,12 +1011,18 @@ makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols), Name); } -std::unique_ptr +Expected> LLJIT::createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES) { // If the config state provided an ObjectLinkingLayer factory then use it. - if (S.CreateObjectLinkingLayer) - return S.CreateObjectLinkingLayer(ES, S.JTMB->getTargetTriple()); + if (S.CreateObjectLinkingLayer) { + Error Err = Error::success(); + std::unique_ptr ObjLayer = + S.CreateObjectLinkingLayer(ES, S.JTMB->getTargetTriple(), Err); + if (Err) + return std::move(Err); + return std::move(ObjLayer); + } // Otherwise default to creating an RTDyldObjectLinkingLayer that constructs // a new SectionMemoryManager for each object. @@ -1057,8 +1063,7 @@ LLJIT::LLJIT(LLJITBuilderState &S, Error &Err) : ES(S.ES ? std::move(S.ES) : std::make_unique()), Main(), - DL(""), TT(S.JTMB->getTargetTriple()), - ObjLinkingLayer(createObjectLinkingLayer(S, *ES)) { + DL(""), TT(S.JTMB->getTargetTriple()) { ErrorAsOutParameter _(&Err); @@ -1078,6 +1083,12 @@ return; } + auto ObjLayer = createObjectLinkingLayer(S, *ES); + if (!ObjLayer) { + Err = ObjLayer.takeError(); + return; + } + ObjLinkingLayer = std::move(*ObjLayer); ObjTransformLayer = std::make_unique(*ES, *ObjLinkingLayer); diff --git a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp --- a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp +++ b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp @@ -414,7 +414,7 @@ LLVMOrcLLJITBuilderRef Builder, LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction F, void *Ctx) { unwrap(Builder)->setObjectLinkingLayerCreator( - [=](ExecutionSession &ES, const Triple &TT) { + [=](ExecutionSession &ES, const Triple &TT, Error &Err) { auto TTStr = TT.str(); return std::unique_ptr( unwrap(F(Ctx, wrap(&ES), TTStr.c_str())));