[llvm] r296774 - Reland r296442 with modifications reverted in r296463.
Vassil Vassilev via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 2 09:56:46 PST 2017
Author: vvassilev
Date: Thu Mar 2 11:56:45 2017
New Revision: 296774
URL: http://llvm.org/viewvc/llvm-project?rev=296774&view=rev
Log:
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)!"
Modified:
llvm/trunk/include/llvm/Support/DynamicLibrary.h
llvm/trunk/lib/Support/DynamicLibrary.cpp
llvm/trunk/lib/Support/Windows/DynamicLibrary.inc
Modified: llvm/trunk/include/llvm/Support/DynamicLibrary.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/DynamicLibrary.h?rev=296774&r1=296773&r2=296774&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/DynamicLibrary.h (original)
+++ llvm/trunk/include/llvm/Support/DynamicLibrary.h Thu Mar 2 11:56:45 2017
@@ -14,6 +14,8 @@
#ifndef LLVM_SUPPORT_DYNAMICLIBRARY_H
#define LLVM_SUPPORT_DYNAMICLIBRARY_H
+#include "llvm/Support/Mutex.h"
+
#include <string>
namespace llvm {
@@ -68,6 +70,15 @@ namespace sys {
static DynamicLibrary getPermanentLibrary(const char *filename,
std::string *errMsg = nullptr);
+ /// Registers an externally loaded library. The library will be unloaded
+ /// when the program terminates.
+ ///
+ /// It is safe to call this function multiple times for the same library.
+ ///
+ /// \returns An empty \p DynamicLibrary if the library was already loaded.
+ static DynamicLibrary addPermanentLibrary(void *handle,
+ std::string *errMsg = nullptr);
+
/// 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.
Modified: llvm/trunk/lib/Support/DynamicLibrary.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DynamicLibrary.cpp?rev=296774&r1=296773&r2=296774&view=diff
==============================================================================
--- llvm/trunk/lib/Support/DynamicLibrary.cpp (original)
+++ llvm/trunk/lib/Support/DynamicLibrary.cpp Thu Mar 2 11:56:45 2017
@@ -76,6 +76,18 @@ DynamicLibrary DynamicLibrary::getPerman
return DynamicLibrary(handle);
}
+DynamicLibrary DynamicLibrary::addPermanentLibrary(void *handle,
+ std::string *errMsg) {
+ SmartScopedLock<true> lock(*SymbolsMutex);
+ // If we've already loaded this library, tell the caller.
+ if (!OpenedHandles->insert(handle).second) {
+ if (errMsg) *errMsg = "Library already loaded";
+ return DynamicLibrary();
+ }
+
+ return DynamicLibrary(handle);
+}
+
void *DynamicLibrary::getAddressOfSymbol(const char *symbolName) {
if (!isValid())
return nullptr;
Modified: llvm/trunk/lib/Support/Windows/DynamicLibrary.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/DynamicLibrary.inc?rev=296774&r1=296773&r2=296774&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/DynamicLibrary.inc (original)
+++ llvm/trunk/lib/Support/Windows/DynamicLibrary.inc Thu Mar 2 11:56:45 2017
@@ -92,6 +92,18 @@ DynamicLibrary DynamicLibrary::getPerman
return DynamicLibrary(a_handle);
}
+DynamicLibrary DynamicLibrary::addPermanentLibrary(void *handle,
+ std::string *errMsg) {
+ SmartScopedLock<true> lock(*SymbolsMutex);
+ // If we've already loaded this library, tell the caller.
+ if (!OpenedHandles->insert(handle).second) {
+ MakeErrMsg(errMsg, "Library already loaded");
+ return DynamicLibrary();
+ }
+
+ return DynamicLibrary(handle);
+}
+
// Stack probing routines are in the support library (e.g. libgcc), but we don't
// have dynamic linking on windows. Provide a hook.
#define EXPLICIT_SYMBOL(SYM) \
More information about the llvm-commits
mailing list