[PATCH] D29955: Allow externally dlopen-ed libraries to be registered as permanent libraries.

Vassil Vassilev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 14 11:40:28 PST 2017


v.g.vassilev created this revision.

This is very helpful when we want a specific library to be dlopen-ed with different flags.


Repository:
  rL LLVM

https://reviews.llvm.org/D29955

Files:
  include/llvm/Support/DynamicLibrary.h
  lib/Support/DynamicLibrary.cpp
  lib/Support/Windows/DynamicLibrary.inc


Index: lib/Support/Windows/DynamicLibrary.inc
===================================================================
--- lib/Support/Windows/DynamicLibrary.inc
+++ lib/Support/Windows/DynamicLibrary.inc
@@ -179,4 +179,17 @@
   return (void *)(intptr_t)GetProcAddress((HMODULE)Data, symbolName);
 }
 
+DynamicLibrary DynamicLibrary::addPermanentLibrary(void *handle) {
+  if (OpenedHandles == 0)
+    OpenedHandles = new DenseSet<HMODULE>();
+
+  // If we've already loaded this library, dlclose() the handle in order to
+  // keep the internal refcount at +1.
+  if (!OpenedHandles->insert((const HMODULE)handle).second)
+    FreeLibrary((HMODULE)handle);
+
+  return DynamicLibrary((HMODULE)handle);
+}
+
+
 }
Index: lib/Support/DynamicLibrary.cpp
===================================================================
--- lib/Support/DynamicLibrary.cpp
+++ lib/Support/DynamicLibrary.cpp
@@ -69,7 +69,10 @@
   if (!filename)
     handle = RTLD_DEFAULT;
 #endif
+  return addPermanentLibrary(handle);
+}
 
+DynamicLibrary DynamicLibrary::addPermanentLibrary(void *handle) {
   if (!OpenedHandles)
     OpenedHandles = new DenseSet<void *>();
 
Index: include/llvm/Support/DynamicLibrary.h
===================================================================
--- include/llvm/Support/DynamicLibrary.h
+++ include/llvm/Support/DynamicLibrary.h
@@ -68,6 +68,8 @@
     static DynamicLibrary getPermanentLibrary(const char *filename,
                                               std::string *errMsg = nullptr);
 
+    static DynamicLibrary addPermanentLibrary(void *handle);
+
     /// This function permanently loads the dynamic library at the given path.
     /// Use this instead of getPermanentLibrary() when you won't need to get
     /// symbols from the library itself.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29955.88408.patch
Type: text/x-patch
Size: 1768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170214/e82c4488/attachment.bin>


More information about the llvm-commits mailing list