diff --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h --- a/lld/MachO/SyntheticSections.h +++ b/lld/MachO/SyntheticSections.h @@ -56,6 +56,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. @@ -155,7 +157,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; @@ -182,7 +184,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; @@ -218,7 +220,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(); @@ -327,7 +329,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; @@ -348,7 +350,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; @@ -362,7 +364,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; @@ -411,7 +413,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(); @@ -453,7 +455,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();