[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
This commit is contained in:
Lang Hames 2015-04-01 04:42:56 +00:00
parent 000e1b22e4
commit 96bdb6594c
2 changed files with 21 additions and 1 deletions

View File

@ -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<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");

View File

@ -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) {