Index: COFF/Writer.cpp =================================================================== --- COFF/Writer.cpp +++ COFF/Writer.cpp @@ -1158,6 +1158,12 @@ // against absolute symbols. See applySecIdx in Chunks.cpp.. DefinedAbsolute::NumOutputSections = OutputSections.size(); + bool OrigExitEarly = errorHandler().ExitEarly; + // Don't exit when reaching the error count limit while running multiple + // parallel threads; the thread that exits will try to close the output buffer + // that other threads still may be touching. + errorHandler().ExitEarly = false; + uint8_t *Buf = Buffer->getBufferStart(); for (OutputSection *Sec : OutputSections) { uint8_t *SecBuf = Buf + Sec->getFileOff(); @@ -1169,6 +1175,11 @@ for_each(parallel::par, Sec->getChunks().begin(), Sec->getChunks().end(), [&](Chunk *C) { C->writeTo(SecBuf); }); } + + errorHandler().ExitEarly = OrigExitEarly; + if (errorHandler().ExitEarly && + errorHandler().ErrorCount >= errorHandler().ErrorLimit) + exitLld(1); } void Writer::writeBuildId() {