Skip to content

Commit cf90527

Browse files
[Orc] Allow LLJITBuilder's CreateObjectLinkingLayer to return errors
It can be useful for an ObjectLinkingLayerCreator to allow callee errors to get propagated to the builder. Specifically, this is the case when the ObjectLayer uses the EHFrameRegistrationPlugin, because it requires a TPCEHFrameRegistrar and instantiation for it may fail (e.g. if the required registration symbols are missing in the target process). Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D94690
1 parent a5eb9df commit cf90527

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
7878
// Make sure the debug info sections aren't stripped.
7979
ObjLinkingLayer->setProcessAllSections(true);
8080

81-
return ObjLinkingLayer;
81+
return std::move(ObjLinkingLayer);
8282
})
8383
.create());
8484

llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int main(int argc, char *argv[]) {
147147
ES, std::make_unique<jitlink::InProcessMemoryManager>());
148148
// Add an instance of our plugin.
149149
ObjLinkingLayer->addPlugin(std::make_unique<MyPlugin>());
150-
return ObjLinkingLayer;
150+
return std::move(ObjLinkingLayer);
151151
})
152152
.create());
153153

llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class LLJIT {
186186
}
187187

188188
protected:
189-
static std::unique_ptr<ObjectLayer>
189+
static Expected<std::unique_ptr<ObjectLayer>>
190190
createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES);
191191

192192
static Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>
@@ -250,8 +250,9 @@ class LLLazyJIT : public LLJIT {
250250

251251
class LLJITBuilderState {
252252
public:
253-
using ObjectLinkingLayerCreator = std::function<std::unique_ptr<ObjectLayer>(
254-
ExecutionSession &, const Triple &TT)>;
253+
using ObjectLinkingLayerCreator =
254+
std::function<Expected<std::unique_ptr<ObjectLayer>>(ExecutionSession &,
255+
const Triple &)>;
255256

256257
using CompileFunctionCreator =
257258
std::function<Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>(

llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,9 @@ Error LLJITBuilderState::prepareForConstruction() {
954954
JTMB->setRelocationModel(Reloc::PIC_);
955955
JTMB->setCodeModel(CodeModel::Small);
956956
CreateObjectLinkingLayer =
957-
[TPC = this->TPC](ExecutionSession &ES,
958-
const Triple &) -> std::unique_ptr<ObjectLayer> {
957+
[TPC = this->TPC](
958+
ExecutionSession &ES,
959+
const Triple &) -> Expected<std::unique_ptr<ObjectLayer>> {
959960
std::unique_ptr<ObjectLinkingLayer> ObjLinkingLayer;
960961
if (TPC)
961962
ObjLinkingLayer =
@@ -1011,7 +1012,7 @@ Expected<JITEvaluatedSymbol> LLJIT::lookupLinkerMangled(JITDylib &JD,
10111012
makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols), Name);
10121013
}
10131014

1014-
std::unique_ptr<ObjectLayer>
1015+
Expected<std::unique_ptr<ObjectLayer>>
10151016
LLJIT::createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES) {
10161017

10171018
// If the config state provided an ObjectLinkingLayer factory then use it.
@@ -1057,8 +1058,7 @@ LLJIT::createCompileFunction(LLJITBuilderState &S,
10571058

10581059
LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
10591060
: ES(S.ES ? std::move(S.ES) : std::make_unique<ExecutionSession>()), Main(),
1060-
DL(""), TT(S.JTMB->getTargetTriple()),
1061-
ObjLinkingLayer(createObjectLinkingLayer(S, *ES)) {
1061+
DL(""), TT(S.JTMB->getTargetTriple()) {
10621062

10631063
ErrorAsOutParameter _(&Err);
10641064

@@ -1078,6 +1078,12 @@ LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
10781078
return;
10791079
}
10801080

1081+
auto ObjLayer = createObjectLinkingLayer(S, *ES);
1082+
if (!ObjLayer) {
1083+
Err = ObjLayer.takeError();
1084+
return;
1085+
}
1086+
ObjLinkingLayer = std::move(*ObjLayer);
10811087
ObjTransformLayer =
10821088
std::make_unique<ObjectTransformLayer>(*ES, *ObjLinkingLayer);
10831089

0 commit comments

Comments
 (0)