From 96bdb6594ca63946e9755aec25d42dfd904d0e97 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Wed, 1 Apr 2015 04:42:56 +0000 Subject: [PATCH] [Orc] Reflect process symbols into the LLI Orc-lazy JIT. This makes symbol resolution essentially identical between MCJIT and the LLI Orc-lazy JIT. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233786 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lli/OrcLazyJIT.cpp | 13 +++++++++++++ tools/lli/OrcLazyJIT.h | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/lli/OrcLazyJIT.cpp b/tools/lli/OrcLazyJIT.cpp index 0e4e2a579b6..d08008da6e0 100644 --- a/tools/lli/OrcLazyJIT.cpp +++ b/tools/lli/OrcLazyJIT.cpp @@ -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(Triple T) { } int llvm::runOrcLazyJIT(std::unique_ptr 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(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"); diff --git a/tools/lli/OrcLazyJIT.h b/tools/lli/OrcLazyJIT.h index 89dfa6ba927..e323714646b 100644 --- a/tools/lli/OrcLazyJIT.h +++ b/tools/lli/OrcLazyJIT.h @@ -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> 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) {