Index: lib/Support/ManagedStatic.cpp =================================================================== --- lib/Support/ManagedStatic.cpp +++ lib/Support/ManagedStatic.cpp @@ -20,12 +20,14 @@ using namespace llvm; static const ManagedStaticBase *StaticList = nullptr; +static sys::Mutex *ManagedStaticMutex = nullptr; -static sys::Mutex& getManagedStaticMutex() { +static sys::Mutex* getManagedStaticMutex() { // We need to use a function local static here, since this can get called // during a static constructor and we need to guarantee that it's initialized // correctly. - static sys::Mutex ManagedStaticMutex; + if (nullptr == ManagedStaticMutex) + ManagedStaticMutex = new sys::Mutex(); return ManagedStaticMutex; } @@ -33,7 +35,7 @@ void (*Deleter)(void*)) const { assert(Creator); if (llvm_is_multithreaded()) { - MutexGuard Lock(getManagedStaticMutex()); + MutexGuard Lock(*getManagedStaticMutex()); if (!Ptr) { void* tmp = Creator(); @@ -83,8 +85,13 @@ /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables. void llvm::llvm_shutdown() { - MutexGuard Lock(getManagedStaticMutex()); + { + MutexGuard Lock(*getManagedStaticMutex()); - while (StaticList) - StaticList->destroy(); + while (StaticList) + StaticList->destroy(); + } + + delete ManagedStaticMutex; + ManagedStaticMutex = nullptr; }