[ORC] Add a TargetProcessControl-based dynamic library search generator.
TPCDynamicLibrarySearchGenerator uses a TargetProcessControl instance to load libraries and search for symbol addresses in a target process. It can be used in place of a DynamicLibrarySearchGenerator to enable target-process agnostic lookup.
This commit is contained in:
1 parent
bd9b223770
commit
13ad00be98
6 files changed
+217
-4
No files matched your search
+21
-3
@@ -25,6 +25,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TPCIndirectionUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
@@ -51,17 +52,23 @@ ExitOnError ExitOnErr;
|
||||
|
||||
const llvm::StringRef FooMod =
|
||||
R"(
|
||||
declare i32 @return1()
|
||||
|
||||
define i32 @foo_body() {
|
||||
entry:
|
||||
ret i32 1
|
||||
%0 = call i32 @return1()
|
||||
ret i32 %0
|
||||
}
|
||||
)";
|
||||
|
||||
const llvm::StringRef BarMod =
|
||||
R"(
|
||||
declare i32 @return2()
|
||||
|
||||
define i32 @bar_body() {
|
||||
entry:
|
||||
ret i32 2
|
||||
%0 = call i32 @return2()
|
||||
ret i32 %0
|
||||
}
|
||||
)";
|
||||
|
||||
@@ -91,6 +98,9 @@ const llvm::StringRef MainMod =
|
||||
declare i32 @bar()
|
||||
)";
|
||||
|
||||
extern "C" int32_t return1() { return 1; }
|
||||
extern "C" int32_t return2() { return 2; }
|
||||
|
||||
static void *reenter(void *Ctx, void *TrampolineAddr) {
|
||||
std::promise<void *> LandingAddressP;
|
||||
auto LandingAddressF = LandingAddressP.get_future();
|
||||
@@ -105,6 +115,11 @@ static void *reenter(void *Ctx, void *TrampolineAddr) {
|
||||
return LandingAddressF.get();
|
||||
}
|
||||
|
||||
static void reportErrorAndExit() {
|
||||
errs() << "Unable to lazily compile function. Exiting.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cl::list<std::string> InputArgv(cl::Positional,
|
||||
cl::desc("<program arguments>..."));
|
||||
|
||||
@@ -135,8 +150,11 @@ int main(int argc, char *argv[]) {
|
||||
auto TPCIU = ExitOnErr(TPCIndirectionUtils::Create(*TPC));
|
||||
ExitOnErr(TPCIU->writeResolverBlock(pointerToJITTargetAddress(&reenter),
|
||||
pointerToJITTargetAddress(TPCIU.get())));
|
||||
TPCIU->createLazyCallThroughManager(J->getExecutionSession(), 0);
|
||||
TPCIU->createLazyCallThroughManager(
|
||||
J->getExecutionSession(), pointerToJITTargetAddress(&reportErrorAndExit));
|
||||
auto ISM = TPCIU->createIndirectStubsManager();
|
||||
J->getMainJITDylib().addGenerator(
|
||||
ExitOnErr(TPCDynamicLibrarySearchGenerator::GetForTargetProcess(*TPC)));
|
||||
|
||||
// (4) Add modules.
|
||||
ExitOnErr(J->addIRModule(ExitOnErr(parseExampleModule(FooMod, "foo-mod"))));
|
||||
|
||||
Reference in new issue
Block a user