[lli] Add a '-dlopen <library-path>' option to lli.

Passing '-dlopen <library-path>' to lli will cause the specified library to be
loaded (via llvm::sys::DynamicLibrary::LoadLibraryPermanently) before JIT'd code
is executed, making the library's symbols accessible to JIT'd code.
This commit is contained in:
Lang Hames 2020-02-14 14:22:59 -08:00
parent 1228d42dda
commit b7be6b480b
1 changed files with 17 additions and 0 deletions

View File

@ -115,6 +115,10 @@ namespace {
cl::desc("Specifies the JITDylib to be used for any subsequent "
"-extra-module arguments."));
cl::list<std::string>
Dylibs("dlopen", cl::desc("Dynamic libraries to load before linking"),
cl::ZeroOrMore);
// The MCJIT supports building for a target address space separate from
// the JIT compilation process. Use a forked process and a copying
// memory manager with IPC to execute using this functionality.
@ -355,6 +359,7 @@ static void reportError(SMDiagnostic Err, const char *ProgName) {
exit(1);
}
Error loadDylibs();
int runOrcLazyJIT(const char *ProgName);
void disallowOrcOptions();
@ -380,6 +385,8 @@ int main(int argc, char **argv, char * const *envp) {
if (DisableCoreFiles)
sys::Process::PreventCoreFiles();
ExitOnErr(loadDylibs());
if (UseJITKind == JITKind::OrcLazy)
return runOrcLazyJIT(argv[0]);
else
@ -743,6 +750,16 @@ static std::function<void(Module &)> createDebugDumper() {
llvm_unreachable("Unknown DumpKind");
}
Error loadDylibs() {
for (const auto &Dylib : Dylibs) {
std::string ErrMsg;
if (sys::DynamicLibrary::LoadLibraryPermanently(Dylib.c_str(), &ErrMsg))
return make_error<StringError>(ErrMsg, inconvertibleErrorCode());
}
return Error::success();
}
static void exitOnLazyCallThroughFailure() { exit(1); }
int runOrcLazyJIT(const char *ProgName) {