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,13 @@ 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); + append_range(osecs, seg->getSections()); + + 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, diff --git a/lld/test/MachO/invalid/range-check.s b/lld/test/MachO/invalid/range-check.s --- a/lld/test/MachO/invalid/range-check.s +++ b/lld/test/MachO/invalid/range-check.s @@ -6,11 +6,11 @@ # RUN: %lld -dylib %t/bar.o -o %t/libbar.dylib # RUN: not %lld -lSystem -o /dev/null %t/libbar.dylib %t/test.o 2>&1 | FileCheck %s -# CHECK: error: {{.*}}test.o:(symbol _main+0xd): relocation UNSIGNED is out of range: [[#]] is not in [0, 4294967295]; references _foo -# CHECK: error: {{.*}}test.o:(symbol _main+0x3): relocation GOT_LOAD is out of range: [[#]] is not in [-2147483648, 2147483647]; references _foo -# CHECK: error: stub is out of range: [[#]] is not in [-2147483648, 2147483647]; references _bar -# CHECK: error: stub helper header is out of range: [[#]] is not in [-2147483648, 2147483647] -# CHECK: error: stub helper header is out of range: [[#]] is not in [-2147483648, 2147483647] +# CHECK-DAG: error: {{.*}}test.o:(symbol _main+0xd): relocation UNSIGNED is out of range: [[#]] is not in [0, 4294967295]; references _foo +# CHECK-DAG: error: {{.*}}test.o:(symbol _main+0x3): relocation GOT_LOAD is out of range: [[#]] is not in [-2147483648, 2147483647]; references _foo +# CHECK-DAG: error: stub is out of range: [[#]] is not in [-2147483648, 2147483647]; references _bar +# CHECK-DAG: error: stub helper header is out of range: [[#]] is not in [-2147483648, 2147483647] +# CHECK-DAG: error: stub helper header is out of range: [[#]] is not in [-2147483648, 2147483647] #--- bar.s .globl _bar