[lld] d9065fe - [lld-macho] Parallelize __LINKEDIT generation
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 7 16:56:03 PDT 2021
Author: Jez Ng
Date: 2021-04-07T19:55:52-04:00
New Revision: d9065fe8ea643bd889821c0dc4c7dbec0469c28e
URL: https://github.com/llvm/llvm-project/commit/d9065fe8ea643bd889821c0dc4c7dbec0469c28e
DIFF: https://github.com/llvm/llvm-project/commit/d9065fe8ea643bd889821c0dc4c7dbec0469c28e.diff
LOG: [lld-macho] Parallelize __LINKEDIT generation
Benchmarking chromium_framework on a 3.2 GHz 16-Core Intel Xeon W Mac Pro:
N Min Max Median Avg Stddev
x 20 4.33 4.42 4.37 4.37 0.021026299
+ 20 4.12 4.23 4.18 4.175 0.035318103
Difference at 95.0% confidence
-0.195 +/- 0.0186025
-4.46224% +/- 0.425686%
(Student's t, pooled s = 0.0290644)
Reviewed By: #lld-macho, gkm
Differential Revision: https://reviews.llvm.org/D99998
Added:
Modified:
lld/MachO/SyntheticSections.h
lld/MachO/Writer.cpp
Removed:
################################################################################
diff --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h
index cf9e2cac95ab..eaad8aa3455f 100644
--- a/lld/MachO/SyntheticSections.h
+++ b/lld/MachO/SyntheticSections.h
@@ -56,6 +56,8 @@ class LinkEditSection : public SyntheticSection {
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 @@ struct Location {
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 @@ struct BindingEntry {
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 @@ struct WeakBindingEntry {
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 LazyPointerSection : public SyntheticSection {
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 LazyBindingSection : public LinkEditSection {
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 ExportSection : public LinkEditSection {
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 @@ struct StabsEntry {
// 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 @@ template <class LP> SymtabSection *makeSymtabSection(StringTableSection &);
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
index f37322bb3ca4..8b10e176bf89 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -51,7 +51,7 @@ class Writer {
void scanSymbols();
template <class LP> void createOutputSections();
template <class LP> void createLoadCommands();
- void finalizeAddressses();
+ void finalizeAddresses();
void finalizeLinkEditSegment();
void assignAddresses(OutputSegment *);
@@ -852,7 +852,7 @@ template <class LP> void Writer::createOutputSections() {
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::finalizeAddressses() {
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<LinkEditSection *> 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 @@ template <class LP> void Writer::run() {
// No more sections nor segments are created beyond this point.
sortSegmentsAndSections();
createLoadCommands<LP>();
- finalizeAddressses();
+ finalizeAddresses();
finalizeLinkEditSegment();
writeMapFile();
writeOutputFile();
More information about the llvm-commits
mailing list