COFF: Fix thread-safety bug.
LTOModule doesn't seem to be thread-safe, so guard that with mutex.
llvm-svn: 248102
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index df92c43..6fdb8e2 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -310,6 +310,9 @@
}
void BitcodeFile::parse() {
+ // Usually parse() is thread-safe, but bitcode file is an exception.
+ std::lock_guard<std::mutex> Lock(Mu);
+
std::string Err;
M.reset(LTOModule::createFromBuffer(MB.getBufferStart(),
MB.getBufferSize(),
@@ -356,5 +359,7 @@
}
}
+std::mutex BitcodeFile::Mu;
+
} // namespace coff
} // namespace lld
diff --git a/lld/COFF/InputFiles.h b/lld/COFF/InputFiles.h
index 4f93a67..ca9ed3f 100644
--- a/lld/COFF/InputFiles.h
+++ b/lld/COFF/InputFiles.h
@@ -17,6 +17,7 @@
#include "llvm/Object/COFF.h"
#include "llvm/Support/StringSaver.h"
#include <memory>
+#include <mutex>
#include <set>
#include <vector>
@@ -213,6 +214,7 @@
std::vector<SymbolBody *> SymbolBodies;
llvm::BumpPtrAllocator Alloc;
std::unique_ptr<LTOModule> M;
+ static std::mutex Mu;
};
} // namespace coff