[PECOFF] Acquire mutex before accessing shared objects.
authorRui Ueyama <ruiu@google.com>
Tue, 20 May 2014 23:05:09 +0000 (23:05 +0000)
committerRui Ueyama <ruiu@google.com>
Tue, 20 May 2014 23:05:09 +0000 (23:05 +0000)
addResolvableSymbols() queues input files, and readAllSymbols() reads
from them. In practice it's currently safe because they are called from
a single thread. But it's not guaranteed.

Also, acquiring the same mutex is needed not to see inconsistent memory
contents that is allowed in the C++ memory model.

llvm-svn: 209254

lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h

index 29faa39..68b696e 100644 (file)
@@ -219,6 +219,7 @@ private:
   // Files are read lazily, so that it has no runtime overhead if
   // there's no dllexported stdcall functions.
   void readAllSymbols() const {
+    std::lock_guard<std::mutex> lock(_mutex);
     for (File *file : _queue) {
       if (auto *archive = dyn_cast<ArchiveLibraryFile>(file)) {
         for (const std::string &sym : archive->getDefinedSymbols())