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 @@ -78,7 +78,7 @@ // Make sure the debug info sections aren't stripped. ObjLinkingLayer->setProcessAllSections(true); - return ObjLinkingLayer; + return std::move(ObjLinkingLayer); }) .create()); 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 @@ -147,7 +147,7 @@ ES, std::make_unique()); // Add an instance of our plugin. ObjLinkingLayer->addPlugin(std::make_unique()); - return ObjLinkingLayer; + return std::move(ObjLinkingLayer); }) .create()); 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> @@ -250,8 +250,9 @@ class LLJITBuilderState { public: - using ObjectLinkingLayerCreator = std::function( - ExecutionSession &, const Triple &TT)>; + using ObjectLinkingLayerCreator = + std::function>(ExecutionSession &, + const Triple &)>; 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,9 @@ 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 &) -> Expected> { std::unique_ptr ObjLinkingLayer; if (TPC) ObjLinkingLayer = @@ -1011,7 +1012,7 @@ 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. @@ -1057,8 +1058,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 +1078,12 @@ return; } + auto ObjLayer = createObjectLinkingLayer(S, *ES); + if (!ObjLayer) { + Err = ObjLayer.takeError(); + return; + } + ObjLinkingLayer = std::move(*ObjLayer); ObjTransformLayer = std::make_unique(*ES, *ObjLinkingLayer);