mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-23 11:38:38 +00:00
Make DynamicLibrary use ManagedStatic. This is pretty simple and should just work as
advertised - but it does have the caveat that calls to DynamicLibrary::AddSymbol will "reset" if you shutdown llvm and try to come back for seconds. This is a subtle behavior change, but I'm assuming that nobody is affected by it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190921 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4284855391
commit
e77ea6b07e
@ -14,6 +14,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Support/DynamicLibrary.h"
|
#include "llvm/Support/DynamicLibrary.h"
|
||||||
|
#include "llvm/Support/ManagedStatic.h"
|
||||||
#include "llvm/ADT/DenseSet.h"
|
#include "llvm/ADT/DenseSet.h"
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/config.h"
|
||||||
@ -22,31 +23,12 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
// Collection of symbol name/value pairs to be searched prior to any libraries.
|
// Collection of symbol name/value pairs to be searched prior to any libraries.
|
||||||
static llvm::StringMap<void *> *ExplicitSymbols = 0;
|
static llvm::ManagedStatic<llvm::StringMap<void *> > ExplicitSymbols;
|
||||||
|
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > SymbolsMutex;
|
||||||
namespace {
|
|
||||||
|
|
||||||
struct ExplicitSymbolsDeleter {
|
|
||||||
~ExplicitSymbolsDeleter() {
|
|
||||||
delete ExplicitSymbols;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static ExplicitSymbolsDeleter Dummy;
|
|
||||||
|
|
||||||
|
|
||||||
static llvm::sys::SmartMutex<true>& getMutex() {
|
|
||||||
static llvm::sys::SmartMutex<true> HandlesMutex;
|
|
||||||
return HandlesMutex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void llvm::sys::DynamicLibrary::AddSymbol(StringRef symbolName,
|
void llvm::sys::DynamicLibrary::AddSymbol(StringRef symbolName,
|
||||||
void *symbolValue) {
|
void *symbolValue) {
|
||||||
SmartScopedLock<true> lock(getMutex());
|
SmartScopedLock<true> lock(*SymbolsMutex);
|
||||||
if (ExplicitSymbols == 0)
|
|
||||||
ExplicitSymbols = new StringMap<void*>();
|
|
||||||
(*ExplicitSymbols)[symbolName] = symbolValue;
|
(*ExplicitSymbols)[symbolName] = symbolValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +54,7 @@ static DenseSet<void *> *OpenedHandles = 0;
|
|||||||
|
|
||||||
DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename,
|
DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename,
|
||||||
std::string *errMsg) {
|
std::string *errMsg) {
|
||||||
SmartScopedLock<true> lock(getMutex());
|
SmartScopedLock<true> lock(*SymbolsMutex);
|
||||||
|
|
||||||
void *handle = dlopen(filename, RTLD_LAZY|RTLD_GLOBAL);
|
void *handle = dlopen(filename, RTLD_LAZY|RTLD_GLOBAL);
|
||||||
if (handle == 0) {
|
if (handle == 0) {
|
||||||
@ -126,10 +108,10 @@ void *SearchForAddressOfSpecialSymbol(const char* symbolName);
|
|||||||
}
|
}
|
||||||
|
|
||||||
void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) {
|
void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) {
|
||||||
SmartScopedLock<true> Lock(getMutex());
|
SmartScopedLock<true> Lock(*SymbolsMutex);
|
||||||
|
|
||||||
// First check symbols added via AddSymbol().
|
// First check symbols added via AddSymbol().
|
||||||
if (ExplicitSymbols) {
|
if (ExplicitSymbols.isConstructed()) {
|
||||||
StringMap<void *>::iterator i = ExplicitSymbols->find(symbolName);
|
StringMap<void *>::iterator i = ExplicitSymbols->find(symbolName);
|
||||||
|
|
||||||
if (i != ExplicitSymbols->end())
|
if (i != ExplicitSymbols->end())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user