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,14 @@ void Writer::writeSections() { uint8_t *buf = buffer->getBufferStart(); + std::vector osecs; for (const OutputSegment *seg : outputSegments) for (const OutputSection *osec : seg->getSections()) - osec->writeTo(buf + osec->fileOff); + osecs.emplace_back(osec); + + 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,