[llvm] r233786 - [Orc] Reflect process symbols into the LLI Orc-lazy JIT.
Lang Hames
lhames at gmail.com
Tue Mar 31 21:42:56 PDT 2015
Author: lhames
Date: Tue Mar 31 23:42:56 2015
New Revision: 233786
URL: http://llvm.org/viewvc/llvm-project?rev=233786&view=rev
Log:
[Orc] Reflect process symbols into the LLI Orc-lazy JIT.
This makes symbol resolution essentially identical between MCJIT and the LLI
Orc-lazy JIT.
Modified:
llvm/trunk/tools/lli/OrcLazyJIT.cpp
llvm/trunk/tools/lli/OrcLazyJIT.h
Modified: llvm/trunk/tools/lli/OrcLazyJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/OrcLazyJIT.cpp?rev=233786&r1=233785&r2=233786&view=diff
==============================================================================
--- llvm/trunk/tools/lli/OrcLazyJIT.cpp (original)
+++ llvm/trunk/tools/lli/OrcLazyJIT.cpp Tue Mar 31 23:42:56 2015
@@ -9,6 +9,7 @@
#include "OrcLazyJIT.h"
#include "llvm/ExecutionEngine/Orc/OrcTargetSupport.h"
+#include "llvm/Support/DynamicLibrary.h"
using namespace llvm;
@@ -29,19 +30,31 @@ OrcLazyJIT::createCallbackManagerBuilder
}
int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) {
+ // Add the program's symbols into the JIT's search space.
+ if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) {
+ errs() << "Error loading program symbols.\n";
+ return 1;
+ }
+
+ // Grab a target machine and try to build a factory function for the
+ // target-specific Orc callback manager.
auto TM = std::unique_ptr<TargetMachine>(EngineBuilder().selectTarget());
auto &Context = getGlobalContext();
auto CallbackMgrBuilder =
OrcLazyJIT::createCallbackManagerBuilder(Triple(TM->getTargetTriple()));
+ // If we couldn't build the factory function then there must not be a callback
+ // manager for this target. Bail out.
if (!CallbackMgrBuilder) {
errs() << "No callback manager available for target '"
<< TM->getTargetTriple() << "'.\n";
return 1;
}
+ // Everything looks good. Build the JIT.
OrcLazyJIT J(std::move(TM), Context, CallbackMgrBuilder);
+ // Add the module, look up main and run it.
auto MainHandle = J.addModule(std::move(M));
auto MainSym = J.findSymbolIn(MainHandle, "main");
Modified: llvm/trunk/tools/lli/OrcLazyJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/OrcLazyJIT.h?rev=233786&r1=233785&r2=233786&view=diff
==============================================================================
--- llvm/trunk/tools/lli/OrcLazyJIT.h (original)
+++ llvm/trunk/tools/lli/OrcLazyJIT.h Tue Mar 31 23:42:56 2015
@@ -21,6 +21,7 @@
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/IR/LLVMContext.h"
namespace llvm {
@@ -61,7 +62,13 @@ public:
std::vector<std::unique_ptr<Module>> S;
S.push_back(std::move(M));
- return CODLayer.addModuleSet(std::move(S));
+ auto FallbackLookup =
+ [](const std::string &Name) {
+ if (auto Addr = RTDyldMemoryManager::getSymbolAddressInProcess(Name))
+ return RuntimeDyld::SymbolInfo(Addr, JITSymbolFlags::Exported);
+ return RuntimeDyld::SymbolInfo(nullptr);
+ };
+ return CODLayer.addModuleSet(std::move(S), std::move(FallbackLookup));
}
orc::JITSymbol findSymbol(const std::string &Name) {
More information about the llvm-commits
mailing list