diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index df92c432b6a9..6fdb8e265352 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -310,6 +310,9 @@ void ImportFile::parse() { } void BitcodeFile::parse() { + // Usually parse() is thread-safe, but bitcode file is an exception. + std::lock_guard Lock(Mu); + std::string Err; M.reset(LTOModule::createFromBuffer(MB.getBufferStart(), MB.getBufferSize(), @@ -356,5 +359,7 @@ MachineTypes BitcodeFile::getMachineType() { } } +std::mutex BitcodeFile::Mu; + } // namespace coff } // namespace lld diff --git a/lld/COFF/InputFiles.h b/lld/COFF/InputFiles.h index 4f93a6749dfc..ca9ed3f5ddb4 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 +#include #include #include @@ -213,6 +214,7 @@ private: std::vector SymbolBodies; llvm::BumpPtrAllocator Alloc; std::unique_ptr M; + static std::mutex Mu; }; } // namespace coff