diff --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h --- a/lld/MachO/SyntheticSections.h +++ b/lld/MachO/SyntheticSections.h @@ -57,6 +57,8 @@ align = target->wordSize; } + virtual void finalizeContents() {} + // Sections in __LINKEDIT are special: their offsets are recorded in the // load commands like LC_DYLD_INFO_ONLY and LC_SYMTAB, instead of in section // headers. @@ -156,7 +158,7 @@ class RebaseSection : public LinkEditSection { public: RebaseSection(); - void finalizeContents(); + void finalizeContents() override; uint64_t getRawSize() const override { return contents.size(); } bool isNeeded() const override { return !locations.empty(); } void writeTo(uint8_t *buf) const override; @@ -183,7 +185,7 @@ class BindingSection : public LinkEditSection { public: BindingSection(); - void finalizeContents(); + void finalizeContents() override; uint64_t getRawSize() const override { return contents.size(); } bool isNeeded() const override { return !bindings.empty(); } void writeTo(uint8_t *buf) const override; @@ -219,7 +221,7 @@ class WeakBindingSection : public LinkEditSection { public: WeakBindingSection(); - void finalizeContents(); + void finalizeContents() override; uint64_t getRawSize() const override { return contents.size(); } bool isNeeded() const override { return !bindings.empty() || !definitions.empty(); @@ -328,7 +330,7 @@ class LazyBindingSection : public LinkEditSection { public: LazyBindingSection(); - void finalizeContents(); + void finalizeContents() override; uint64_t getRawSize() const override { return contents.size(); } bool isNeeded() const override { return !entries.empty(); } void writeTo(uint8_t *buf) const override; @@ -349,7 +351,7 @@ class ExportSection : public LinkEditSection { public: ExportSection(); - void finalizeContents(); + void finalizeContents() override; uint64_t getRawSize() const override { return size; } void writeTo(uint8_t *buf) const override; @@ -363,7 +365,7 @@ class FunctionStartsSection : public LinkEditSection { public: FunctionStartsSection(); - void finalizeContents(); + void finalizeContents() override; uint64_t getRawSize() const override { return contents.size(); } void writeTo(uint8_t *buf) const override; @@ -409,7 +411,7 @@ // range (start index and total number) of those symbols in the symbol table. class SymtabSection : public LinkEditSection { public: - void finalizeContents(); + void finalizeContents() override; uint32_t getNumSymbols() const; uint32_t getNumLocalSymbols() const { return stabs.size() + localSymbols.size(); @@ -451,7 +453,7 @@ class IndirectSymtabSection : public LinkEditSection { public: IndirectSymtabSection(); - void finalizeContents(); + void finalizeContents() override; uint32_t getNumSymbols() const; uint64_t getRawSize() const override { return getNumSymbols() * sizeof(uint32_t); diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -51,7 +51,7 @@ void scanSymbols(); template void createOutputSections(); template void createLoadCommands(); - void finalizeAddressses(); + void finalizeAddresses(); void finalizeLinkEditSegment(); void assignAddresses(OutputSegment *); @@ -852,7 +852,7 @@ linkEditSegment = getOrCreateOutputSegment(segment_names::linkEdit); } -void Writer::finalizeAddressses() { +void Writer::finalizeAddresses() { TimeTraceScope timeScope("Finalize addresses"); // Ensure that segments (and the sections they contain) are allocated // addresses in ascending order, which dyld requires. @@ -870,16 +870,14 @@ void Writer::finalizeLinkEditSegment() { TimeTraceScope timeScope("Finalize __LINKEDIT segment"); // Fill __LINKEDIT contents. - in.rebase->finalizeContents(); - in.binding->finalizeContents(); - in.weakBinding->finalizeContents(); - in.lazyBinding->finalizeContents(); - in.exports->finalizeContents(); - symtabSection->finalizeContents(); - indirectSymtabSection->finalizeContents(); - - if (functionStartsSection) - functionStartsSection->finalizeContents(); + std::vector linkEditSections{ + in.rebase, in.binding, in.weakBinding, in.lazyBinding, + in.exports, symtabSection, indirectSymtabSection, functionStartsSection, + }; + parallelForEach(linkEditSections, [](LinkEditSection *osec) { + if (osec) + osec->finalizeContents(); + }); // Now that __LINKEDIT is filled out, do a proper calculation of its // addresses and offsets. @@ -972,7 +970,7 @@ // No more sections nor segments are created beyond this point. sortSegmentsAndSections(); createLoadCommands(); - finalizeAddressses(); + finalizeAddresses(); finalizeLinkEditSegment(); writeMapFile(); writeOutputFile();