summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/COFF/InputFiles.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index 87efd07e68c..6bdfd4faa82 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -18,6 +18,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/raw_ostream.h"
+#include <mutex>
using namespace llvm::object;
using namespace llvm::support::endian;
@@ -76,7 +77,9 @@ std::error_code ArchiveFile::parse() {
}
// Returns a buffer pointing to a member file containing a given symbol.
+// This function is thread-safe.
ErrorOr<MemoryBufferRef> ArchiveFile::getMember(const Archive::Symbol *Sym) {
+ static std::mutex Mu;
auto ItOrErr = Sym->getMember();
if (auto EC = ItOrErr.getError())
return EC;
@@ -84,7 +87,9 @@ ErrorOr<MemoryBufferRef> ArchiveFile::getMember(const Archive::Symbol *Sym) {
// Return an empty buffer if we have already returned the same buffer.
const char *StartAddr = It->getBuffer().data();
+ Mu.lock();
auto Pair = Seen.insert(StartAddr);
+ Mu.unlock();
if (!Pair.second)
return MemoryBufferRef();
return It->getMemoryBufferRef();
OpenPOWER on IntegriCloud