aboutsummaryrefslogtreecommitdiff
path: root/tools/lli
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lli')
-rw-r--r--tools/lli/OrcLazyJIT.cpp23
-rw-r--r--tools/lli/OrcLazyJIT.h29
-rw-r--r--tools/lli/RemoteJITUtils.h4
-rw-r--r--tools/lli/lli.cpp2
4 files changed, 35 insertions, 23 deletions
diff --git a/tools/lli/OrcLazyJIT.cpp b/tools/lli/OrcLazyJIT.cpp
index 2e15894152f9..f1a752e0790d 100644
--- a/tools/lli/OrcLazyJIT.cpp
+++ b/tools/lli/OrcLazyJIT.cpp
@@ -148,18 +148,19 @@ int llvm::runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms,
// Add the module, look up main and run it.
for (auto &M : Ms)
- J.addModule(std::shared_ptr<Module>(std::move(M)));
- auto MainSym = J.findSymbol("main");
+ cantFail(J.addModule(std::shared_ptr<Module>(std::move(M))));
- if (!MainSym) {
+ if (auto MainSym = J.findSymbol("main")) {
+ typedef int (*MainFnPtr)(int, const char*[]);
+ std::vector<const char *> ArgV;
+ for (auto &Arg : Args)
+ ArgV.push_back(Arg.c_str());
+ auto Main = fromTargetAddress<MainFnPtr>(cantFail(MainSym.getAddress()));
+ return Main(ArgV.size(), (const char**)ArgV.data());
+ } else if (auto Err = MainSym.takeError())
+ logAllUnhandledErrors(std::move(Err), llvm::errs(), "");
+ else
errs() << "Could not find main function.\n";
- return 1;
- }
- using MainFnPtr = int (*)(int, const char*[]);
- std::vector<const char *> ArgV;
- for (auto &Arg : Args)
- ArgV.push_back(Arg.c_str());
- auto Main = fromTargetAddress<MainFnPtr>(MainSym.getAddress());
- return Main(ArgV.size(), (const char**)ArgV.data());
+ return 1;
}
diff --git a/tools/lli/OrcLazyJIT.h b/tools/lli/OrcLazyJIT.h
index fc02a10b514e..47a2acc4d7e6 100644
--- a/tools/lli/OrcLazyJIT.h
+++ b/tools/lli/OrcLazyJIT.h
@@ -61,7 +61,8 @@ public:
IndirectStubsManagerBuilder IndirectStubsMgrBuilder,
bool InlineStubs)
: TM(std::move(TM)), DL(this->TM->createDataLayout()),
- CCMgr(std::move(CCMgr)),
+ CCMgr(std::move(CCMgr)),
+ ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
IRDumpLayer(CompileLayer, createDebugDumper()),
CODLayer(IRDumpLayer, extractSingleFunction, *this->CCMgr,
@@ -74,10 +75,14 @@ public:
CXXRuntimeOverrides.runDestructors();
// Run any IR destructors.
for (auto &DtorRunner : IRStaticDestructorRunners)
- DtorRunner.runViaLayer(CODLayer);
+ if (auto Err = DtorRunner.runViaLayer(CODLayer)) {
+ // FIXME: OrcLazyJIT should probably take a "shutdownError" callback to
+ // report these errors on.
+ report_fatal_error(std::move(Err));
+ }
}
- void addModule(std::shared_ptr<Module> M) {
+ Error addModule(std::shared_ptr<Module> M) {
if (M->getDataLayout().isDefault())
M->setDataLayout(DL);
@@ -124,21 +129,27 @@ public:
);
// Add the module to the JIT.
- ModulesHandle =
- CODLayer.addModule(std::move(M),
- llvm::make_unique<SectionMemoryManager>(),
- std::move(Resolver));
+ if (auto ModulesHandleOrErr =
+ CODLayer.addModule(std::move(M), std::move(Resolver)))
+ ModulesHandle = std::move(*ModulesHandleOrErr);
+ else
+ return ModulesHandleOrErr.takeError();
+
} else
- CODLayer.addExtraModule(ModulesHandle, std::move(M));
+ if (auto Err = CODLayer.addExtraModule(ModulesHandle, std::move(M)))
+ return Err;
// Run the static constructors, and save the static destructor runner for
// execution when the JIT is torn down.
orc::CtorDtorRunner<CODLayerT> CtorRunner(std::move(CtorNames),
ModulesHandle);
- CtorRunner.runViaLayer(CODLayer);
+ if (auto Err = CtorRunner.runViaLayer(CODLayer))
+ return Err;
IRStaticDestructorRunners.emplace_back(std::move(DtorNames),
ModulesHandle);
+
+ return Error::success();
}
JITSymbol findSymbol(const std::string &Name) {
diff --git a/tools/lli/RemoteJITUtils.h b/tools/lli/RemoteJITUtils.h
index 3c82f73ff072..4e948413865c 100644
--- a/tools/lli/RemoteJITUtils.h
+++ b/tools/lli/RemoteJITUtils.h
@@ -84,7 +84,7 @@ public:
this->MemMgr = std::move(MemMgr);
}
- void setResolver(std::unique_ptr<JITSymbolResolver> Resolver) {
+ void setResolver(std::shared_ptr<JITSymbolResolver> Resolver) {
this->Resolver = std::move(Resolver);
}
@@ -145,7 +145,7 @@ public:
private:
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr;
- std::unique_ptr<JITSymbolResolver> Resolver;
+ std::shared_ptr<JITSymbolResolver> Resolver;
};
}
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index f228a3619457..091ca22b4e82 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -646,7 +646,7 @@ int main(int argc, char **argv, char * const *envp) {
// else == "if (RemoteMCJIT)"
// Remote target MCJIT doesn't (yet) support static constructors. No reason
- // it couldn't. This is a limitation of the LLI implemantation, not the
+ // it couldn't. This is a limitation of the LLI implementation, not the
// MCJIT itself. FIXME.
// Lanch the remote process and get a channel to it.