From ebb0ebff4b78e4a1de410cfc86597885d58a3e86 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 19 Sep 2015 23:14:51 +0000 Subject: [PATCH] COFF: Fix thread-safety bug. LTOModule doesn't seem to be thread-safe, so guard that with mutex. llvm-svn: 248102 --- lld/COFF/InputFiles.cpp | 5 +++++ lld/COFF/InputFiles.h | 2 ++ 2 files changed, 7 insertions(+) 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