[PATCH] D51096: [LLD] [COFF] Don't exit the process while writing section data in parallel

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 22 04:18:43 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: ruiu, pcc, rnk.

This is an alternative solution to PR38647.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D51096

Files:
  COFF/Writer.cpp


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() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51096.161917.patch
Type: text/x-patch
Size: 1076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180822/95c750a9/attachment.bin>


More information about the llvm-commits mailing list