1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[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
This commit is contained in:
Stefan Gränitz 2021-01-15 12:26:04 +01:00
parent ff70fba453
commit 9bbc173276
4 changed files with 17 additions and 10 deletions

View File

@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
// Make sure the debug info sections aren't stripped.
ObjLinkingLayer->setProcessAllSections(true);
return ObjLinkingLayer;
return std::move(ObjLinkingLayer);
})
.create());

View File

@ -147,7 +147,7 @@ int main(int argc, char *argv[]) {
ES, std::make_unique<jitlink::InProcessMemoryManager>());
// Add an instance of our plugin.
ObjLinkingLayer->addPlugin(std::make_unique<MyPlugin>());
return ObjLinkingLayer;
return std::move(ObjLinkingLayer);
})
.create());

View File

@ -186,7 +186,7 @@ public:
}
protected:
static std::unique_ptr<ObjectLayer>
static Expected<std::unique_ptr<ObjectLayer>>
createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES);
static Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>
@ -250,8 +250,9 @@ private:
class LLJITBuilderState {
public:
using ObjectLinkingLayerCreator = std::function<std::unique_ptr<ObjectLayer>(
ExecutionSession &, const Triple &TT)>;
using ObjectLinkingLayerCreator =
std::function<Expected<std::unique_ptr<ObjectLayer>>(ExecutionSession &,
const Triple &)>;
using CompileFunctionCreator =
std::function<Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>(

View File

@ -954,8 +954,9 @@ Error LLJITBuilderState::prepareForConstruction() {
JTMB->setRelocationModel(Reloc::PIC_);
JTMB->setCodeModel(CodeModel::Small);
CreateObjectLinkingLayer =
[TPC = this->TPC](ExecutionSession &ES,
const Triple &) -> std::unique_ptr<ObjectLayer> {
[TPC = this->TPC](
ExecutionSession &ES,
const Triple &) -> Expected<std::unique_ptr<ObjectLayer>> {
std::unique_ptr<ObjectLinkingLayer> ObjLinkingLayer;
if (TPC)
ObjLinkingLayer =
@ -1011,7 +1012,7 @@ Expected<JITEvaluatedSymbol> LLJIT::lookupLinkerMangled(JITDylib &JD,
makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols), Name);
}
std::unique_ptr<ObjectLayer>
Expected<std::unique_ptr<ObjectLayer>>
LLJIT::createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES) {
// If the config state provided an ObjectLinkingLayer factory then use it.
@ -1057,8 +1058,7 @@ LLJIT::createCompileFunction(LLJITBuilderState &S,
LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
: ES(S.ES ? std::move(S.ES) : std::make_unique<ExecutionSession>()), Main(),
DL(""), TT(S.JTMB->getTargetTriple()),
ObjLinkingLayer(createObjectLinkingLayer(S, *ES)) {
DL(""), TT(S.JTMB->getTargetTriple()) {
ErrorAsOutParameter _(&Err);
@ -1078,6 +1078,12 @@ LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
return;
}
auto ObjLayer = createObjectLinkingLayer(S, *ES);
if (!ObjLayer) {
Err = ObjLayer.takeError();
return;
}
ObjLinkingLayer = std::move(*ObjLayer);
ObjTransformLayer =
std::make_unique<ObjectTransformLayer>(*ES, *ObjLinkingLayer);