[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.
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index a0d7a8c..e7251b1 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -115,6 +115,10 @@
                 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 @@
   exit(1);
 }
 
+Error loadDylibs();
 int runOrcLazyJIT(const char *ProgName);
 void disallowOrcOptions();
 
@@ -380,6 +385,8 @@
   if (DisableCoreFiles)
     sys::Process::PreventCoreFiles();
 
+  ExitOnErr(loadDylibs());
+
   if (UseJITKind == JITKind::OrcLazy)
     return runOrcLazyJIT(argv[0]);
   else
@@ -743,6 +750,16 @@
   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) {