Fix PR8441, a thread unsafe static variable in our dynamic library loading facilities.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118463 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson
2010-11-09 00:36:06 +00:00
parent 5e559a22c1
commit 9ac18d562d

View File

@@ -15,6 +15,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/System/DynamicLibrary.h" #include "llvm/System/DynamicLibrary.h"
#include "llvm/System/Mutex.h"
#include "llvm/Config/config.h" #include "llvm/Config/config.h"
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@@ -60,6 +61,7 @@ using namespace llvm::sys;
//=== independent code. //=== independent code.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
static SmartMutex<true> HandlesMutex;
static std::vector<void *> *OpenedHandles = 0; static std::vector<void *> *OpenedHandles = 0;
@@ -76,6 +78,7 @@ bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,
if (Filename == NULL) if (Filename == NULL)
H = RTLD_DEFAULT; H = RTLD_DEFAULT;
#endif #endif
SmartScopedLock<true> Lock(HandlesMutex);
if (OpenedHandles == 0) if (OpenedHandles == 0)
OpenedHandles = new std::vector<void *>(); OpenedHandles = new std::vector<void *>();
OpenedHandles->push_back(H); OpenedHandles->push_back(H);
@@ -110,6 +113,7 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
#if HAVE_DLFCN_H #if HAVE_DLFCN_H
// Now search the libraries. // Now search the libraries.
SmartScopedLock<true> Lock(HandlesMutex);
if (OpenedHandles) { if (OpenedHandles) {
for (std::vector<void *>::iterator I = OpenedHandles->begin(), for (std::vector<void *>::iterator I = OpenedHandles->begin(),
E = OpenedHandles->end(); I != E; ++I) { E = OpenedHandles->end(); I != E; ++I) {