llvm.org GIT mirror llvm / 3983dc2
Reland r296442 with modifications reverted in r296463. Original commit message: "Allow externally dlopen-ed libraries to be registered as permanent libraries. This is also useful in cases when llvm is in a shared library. First we dlopen the llvm shared library and then we register it as a permanent library in order to keep the JIT and other services working. Patch reviewed by Vedant Kumar (D29955)!" git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296774 91177308-0d34-0410-b5e6-96231b3b80d8 Vassil Vassilev 3 years ago
3 changed file(s) with 35 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1212
1313 #ifndef LLVM_SUPPORT_DYNAMICLIBRARY_H
1414 #define LLVM_SUPPORT_DYNAMICLIBRARY_H
15
16 #include "llvm/Support/Mutex.h"
1517
1618 #include
1719
6769 static DynamicLibrary getPermanentLibrary(const char *filename,
6870 std::string *errMsg = nullptr);
6971
72 /// Registers an externally loaded library. The library will be unloaded
73 /// when the program terminates.
74 ///
75 /// It is safe to call this function multiple times for the same library.
76 ///
77 /// \returns An empty \p DynamicLibrary if the library was already loaded.
78 static DynamicLibrary addPermanentLibrary(void *handle,
79 std::string *errMsg = nullptr);
80
7081 /// This function permanently loads the dynamic library at the given path.
7182 /// Use this instead of getPermanentLibrary() when you won't need to get
7283 /// symbols from the library itself.
7171 // keep the internal refcount at +1.
7272 if (!OpenedHandles->insert(handle).second)
7373 dlclose(handle);
74
75 return DynamicLibrary(handle);
76 }
77
78 DynamicLibrary DynamicLibrary::addPermanentLibrary(void *handle,
79 std::string *errMsg) {
80 SmartScopedLock lock(*SymbolsMutex);
81 // If we've already loaded this library, tell the caller.
82 if (!OpenedHandles->insert(handle).second) {
83 if (errMsg) *errMsg = "Library already loaded";
84 return DynamicLibrary();
85 }
7486
7587 return DynamicLibrary(handle);
7688 }
9191 return DynamicLibrary(a_handle);
9292 }
9393
94 DynamicLibrary DynamicLibrary::addPermanentLibrary(void *handle,
95 std::string *errMsg) {
96 SmartScopedLock lock(*SymbolsMutex);
97 // If we've already loaded this library, tell the caller.
98 if (!OpenedHandles->insert(handle).second) {
99 MakeErrMsg(errMsg, "Library already loaded");
100 return DynamicLibrary();
101 }
102
103 return DynamicLibrary(handle);
104 }
105
94106 // Stack probing routines are in the support library (e.g. libgcc), but we don't
95107 // have dynamic linking on windows. Provide a hook.
96108 #define EXPLICIT_SYMBOL(SYM) \