diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -20,6 +20,7 @@ #include "SyntheticSections.h" #include "Target.h" #include "UnwindInfoSection.h" +#include "llvm/Support/Parallel.h" #include "lld/Common/Arrays.h" #include "lld/Common/CommonLinkerContext.h" @@ -1081,9 +1082,15 @@ void Writer::writeSections() { uint8_t *buf = buffer->getBufferStart(); - for (const OutputSegment *seg : outputSegments) - for (const OutputSection *osec : seg->getSections()) - osec->writeTo(buf + osec->fileOff); + std::vector osecs; + for (const OutputSegment *seg : outputSegments) { + const std::vector §ions = seg->getSections(); + osecs.insert(osecs.end(), sections.begin(), sections.end()); + } + + parallelForEach(osecs.begin(), osecs.end(), [&](const OutputSection *osec) { + osec->writeTo(buf + osec->fileOff); + }); } // In order to utilize multiple cores, we first split the buffer into chunks,