From: Jordy Rose Date: Mon, 22 Aug 2011 19:01:52 +0000 (+0000) Subject: Make DynamicLibrary thread-safe w/r/t call to dlerror() after dlopen(). PR10718 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=eeb37f1a568185c46f600fb34769ec376bf5bfaf;p=oota-llvm.git Make DynamicLibrary thread-safe w/r/t call to dlerror() after dlopen(). PR10718 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138260 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/DynamicLibrary.cpp b/lib/Support/DynamicLibrary.cpp index 5ee6a82ad7b..fb02c07e4af 100644 --- a/lib/Support/DynamicLibrary.cpp +++ b/lib/Support/DynamicLibrary.cpp @@ -72,6 +72,8 @@ static DenseSet *OpenedHandles = 0; DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename, std::string *errMsg) { + SmartScopedLock lock(getMutex()); + void *handle = dlopen(filename, RTLD_LAZY|RTLD_GLOBAL); if (handle == 0) { if (errMsg) *errMsg = dlerror(); @@ -85,7 +87,6 @@ DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename, handle = RTLD_DEFAULT; #endif - SmartScopedLock lock(getMutex()); if (OpenedHandles == 0) OpenedHandles = new DenseSet(); diff --git a/lib/Support/Windows/DynamicLibrary.inc b/lib/Support/Windows/DynamicLibrary.inc index 5a0b2491f00..83da82a949c 100644 --- a/lib/Support/Windows/DynamicLibrary.inc +++ b/lib/Support/Windows/DynamicLibrary.inc @@ -71,9 +71,10 @@ extern "C" { DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename, std::string *errMsg) { + SmartScopedLock lock(getMutex()); + if (!filename) { // When no file is specified, enumerate all DLLs and EXEs in the process. - SmartScopedLock lock(getMutex()); if (OpenedHandles == 0) OpenedHandles = new DenseSet(); @@ -90,7 +91,6 @@ DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename, return DynamicLibrary(); } - SmartScopedLock lock(getMutex()); if (OpenedHandles == 0) OpenedHandles = new DenseSet();