[lld] r305718 - Fix a threading bug.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 10:47:04 PDT 2017


Author: ruiu
Date: Mon Jun 19 12:47:04 2017
New Revision: 305718

URL: http://llvm.org/viewvc/llvm-project?rev=305718&view=rev
Log:
Fix a threading bug.

Modified:
    lld/trunk/COFF/Strings.cpp

Modified: lld/trunk/COFF/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Strings.cpp?rev=305718&r1=305717&r2=305718&view=diff
==============================================================================
--- lld/trunk/COFF/Strings.cpp (original)
+++ lld/trunk/COFF/Strings.cpp Mon Jun 19 12:47:04 2017
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Strings.h"
+#include <mutex>
 
 #if defined(_MSC_VER)
 #include <Windows.h>
@@ -21,6 +22,10 @@ using namespace llvm;
 
 Optional<std::string> coff::demangle(StringRef S) {
 #if defined(_MSC_VER)
+  // UnDecorateSymbolName is not thread-safe, so we need a mutex.
+  static std::mutex Mu;
+  std::lock_guard<std::mutex> Lock(mu);
+
   char Buf[4096];
   if (S.startswith("?"))
     if (size_t Len = UnDecorateSymbolName(S.str().c_str(), Buf, sizeof(Buf), 0))




More information about the llvm-commits mailing list