-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[NFC][ELF] Move mergeRels/partitionRels into finalizeContents #171203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: users/jrtc27/spr/main.nfcelf-move-mergerelspartitionrels-into-finalizecontents
Are you sure you want to change the base?
Conversation
Created using spr 1.3.5
|
@llvm/pr-subscribers-lld-elf Author: Jessica Clarke (jrtc27) ChangesOther than the ordering requirements that remain between sections, this Note that isNeeded already checks relocsVec for both section types, so Full diff: https://github.com/llvm/llvm-project/pull/171203.diff 3 Files Affected:
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index d6e214f9d0f48..c81f649861a73 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1707,6 +1707,9 @@ void RelocationBaseSection::partitionRels() {
}
void RelocationBaseSection::finalizeContents() {
+ mergeRels();
+ // Compute DT_RELACOUNT to be used by part.dynamic.
+ partitionRels();
SymbolTableBaseSection *symTab = getPartition(ctx).dynSymTab.get();
// When linking glibc statically, .rel{,a}.plt contains R_*_IRELATIVE
@@ -1796,6 +1799,8 @@ void RelrBaseSection::mergeRels() {
relocsVec.clear();
}
+void RelrBaseSection::finalizeContents() { mergeRels(); }
+
template <class ELFT>
AndroidPackedRelocationSection<ELFT>::AndroidPackedRelocationSection(
Ctx &ctx, StringRef name, unsigned concurrency)
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 2b5897c9a40b0..8971d5f6c2349 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -530,14 +530,14 @@ class RelocationBaseSection : public SyntheticSection {
}
size_t getSize() const override { return relocs.size() * this->entsize; }
size_t getRelativeRelocCount() const { return numRelativeRelocs; }
- void mergeRels();
- void partitionRels();
void finalizeContents() override;
int32_t dynamicTag, sizeDynamicTag;
SmallVector<DynamicReloc, 0> relocs;
protected:
+ void mergeRels();
+ void partitionRels();
void computeRels();
// Used when parallel relocation scanning adds relocations. The elements
// will be moved into relocs by mergeRel().
@@ -608,14 +608,15 @@ class RelrBaseSection : public SyntheticSection {
isec.addReloc({expr, addendRelType, offsetInSec, addend, &sym});
addReloc<shard>({&isec, isec.relocs().size() - 1});
}
- void mergeRels();
bool isNeeded() const override {
return !relocs.empty() ||
llvm::any_of(relocsVec, [](auto &v) { return !v.empty(); });
}
+ void finalizeContents() override;
SmallVector<RelativeReloc, 0> relocs;
protected:
+ void mergeRels();
SmallVector<SmallVector<RelativeReloc, 0>, 0> relocsVec;
};
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index db5626e701ad6..57202f42cce5b 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2111,20 +2111,9 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// Dynamic section must be the last one in this list and dynamic
// symbol table section (dynSymTab) must be the first one.
for (Partition &part : ctx.partitions) {
- if (part.relaDyn) {
- part.relaDyn->mergeRels();
- // Compute DT_RELACOUNT to be used by part.dynamic.
- part.relaDyn->partitionRels();
- finalizeSynthetic(ctx, part.relaDyn.get());
- }
- if (part.relrDyn) {
- part.relrDyn->mergeRels();
- finalizeSynthetic(ctx, part.relrDyn.get());
- }
- if (part.relrAuthDyn) {
- part.relrAuthDyn->mergeRels();
- finalizeSynthetic(ctx, part.relrAuthDyn.get());
- }
+ finalizeSynthetic(ctx, part.relaDyn.get());
+ finalizeSynthetic(ctx, part.relrDyn.get());
+ finalizeSynthetic(ctx, part.relrAuthDyn.get());
finalizeSynthetic(ctx, part.dynSymTab.get());
finalizeSynthetic(ctx, part.gnuHashTab.get());
|
|
@llvm/pr-subscribers-lld Author: Jessica Clarke (jrtc27) ChangesOther than the ordering requirements that remain between sections, this Note that isNeeded already checks relocsVec for both section types, so Full diff: https://github.com/llvm/llvm-project/pull/171203.diff 3 Files Affected:
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index d6e214f9d0f48..c81f649861a73 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1707,6 +1707,9 @@ void RelocationBaseSection::partitionRels() {
}
void RelocationBaseSection::finalizeContents() {
+ mergeRels();
+ // Compute DT_RELACOUNT to be used by part.dynamic.
+ partitionRels();
SymbolTableBaseSection *symTab = getPartition(ctx).dynSymTab.get();
// When linking glibc statically, .rel{,a}.plt contains R_*_IRELATIVE
@@ -1796,6 +1799,8 @@ void RelrBaseSection::mergeRels() {
relocsVec.clear();
}
+void RelrBaseSection::finalizeContents() { mergeRels(); }
+
template <class ELFT>
AndroidPackedRelocationSection<ELFT>::AndroidPackedRelocationSection(
Ctx &ctx, StringRef name, unsigned concurrency)
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 2b5897c9a40b0..8971d5f6c2349 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -530,14 +530,14 @@ class RelocationBaseSection : public SyntheticSection {
}
size_t getSize() const override { return relocs.size() * this->entsize; }
size_t getRelativeRelocCount() const { return numRelativeRelocs; }
- void mergeRels();
- void partitionRels();
void finalizeContents() override;
int32_t dynamicTag, sizeDynamicTag;
SmallVector<DynamicReloc, 0> relocs;
protected:
+ void mergeRels();
+ void partitionRels();
void computeRels();
// Used when parallel relocation scanning adds relocations. The elements
// will be moved into relocs by mergeRel().
@@ -608,14 +608,15 @@ class RelrBaseSection : public SyntheticSection {
isec.addReloc({expr, addendRelType, offsetInSec, addend, &sym});
addReloc<shard>({&isec, isec.relocs().size() - 1});
}
- void mergeRels();
bool isNeeded() const override {
return !relocs.empty() ||
llvm::any_of(relocsVec, [](auto &v) { return !v.empty(); });
}
+ void finalizeContents() override;
SmallVector<RelativeReloc, 0> relocs;
protected:
+ void mergeRels();
SmallVector<SmallVector<RelativeReloc, 0>, 0> relocsVec;
};
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index db5626e701ad6..57202f42cce5b 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2111,20 +2111,9 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// Dynamic section must be the last one in this list and dynamic
// symbol table section (dynSymTab) must be the first one.
for (Partition &part : ctx.partitions) {
- if (part.relaDyn) {
- part.relaDyn->mergeRels();
- // Compute DT_RELACOUNT to be used by part.dynamic.
- part.relaDyn->partitionRels();
- finalizeSynthetic(ctx, part.relaDyn.get());
- }
- if (part.relrDyn) {
- part.relrDyn->mergeRels();
- finalizeSynthetic(ctx, part.relrDyn.get());
- }
- if (part.relrAuthDyn) {
- part.relrAuthDyn->mergeRels();
- finalizeSynthetic(ctx, part.relrAuthDyn.get());
- }
+ finalizeSynthetic(ctx, part.relaDyn.get());
+ finalizeSynthetic(ctx, part.relrDyn.get());
+ finalizeSynthetic(ctx, part.relrAuthDyn.get());
finalizeSynthetic(ctx, part.dynSymTab.get());
finalizeSynthetic(ctx, part.gnuHashTab.get());
|
Other than the ordering requirements that remain between sections, this
abstracts the details of how these sections are implemented.
Note that isNeeded already checks relocsVec for both section types, so
finalizeSynthetic can call it before mergeRels just fine.