Merging r242885:
------------------------------------------------------------------------
r242885 | atanasyan | 2015-07-22 03:32:19 -0700 (Wed, 22 Jul 2015) | 4 lines

[ELF] Protect write access to the ELFLinkingContext::_cidentSections by a mutex

The _cidentSections container is filled during files parsing so we need to
serialize a concurrent access to it.
------------------------------------------------------------------------


git-svn-id: https://llvm.org/svn/llvm-project/lld/branches/release_37@243022 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/lld/ReaderWriter/ELFLinkingContext.h b/include/lld/ReaderWriter/ELFLinkingContext.h
index b59d360..9cfc2f8 100644
--- a/include/lld/ReaderWriter/ELFLinkingContext.h
+++ b/include/lld/ReaderWriter/ELFLinkingContext.h
@@ -408,6 +408,7 @@
   std::map<std::string, uint64_t> _absoluteSymbols;
   llvm::StringSet<> _dynamicallyExportedSymbols;
   std::unique_ptr<File> _resolver;
+  std::mutex _cidentMutex;
   llvm::StringSet<> _cidentSections;
 
   // The linker script semantic object, which owns all script ASTs, is stored
diff --git a/lib/ReaderWriter/ELF/ELFLinkingContext.cpp b/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
index 70ed30a..8c76a78 100644
--- a/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
+++ b/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
@@ -254,8 +254,10 @@
   if (name.find_first_not_of("0123456789"
                              "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                              "abcdefghijklmnopqrstuvwxyz"
-                             "_") == StringRef::npos)
+                             "_") == StringRef::npos) {
+    std::lock_guard<std::mutex> lock(_cidentMutex);
     _cidentSections.insert(name);
+  }
 }
 
 } // end namespace lld