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

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 14 15:01:49 PST 2020


Author: Lang Hames
Date: 2020-02-14T15:01:40-08:00
New Revision: b7be6b480b8681902e4b7aa4eb479ccedbde1990

URL: https://github.com/llvm/llvm-project/commit/b7be6b480b8681902e4b7aa4eb479ccedbde1990
DIFF: https://github.com/llvm/llvm-project/commit/b7be6b480b8681902e4b7aa4eb479ccedbde1990.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/tools/lli/lli.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index a0d7a8c1d06a..e7251b12f7fc 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -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) {


        


More information about the llvm-commits mailing list