[lld] 1f391a7 - [ELF] Pass Ctx & to SyntheticSection::finalizeContents
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 20:45:45 PDT 2024
Author: Fangrui Song
Date: 2024-10-03T20:45:40-07:00
New Revision: 1f391a75af8685e6bba89421443d72ac6a186599
URL: https://github.com/llvm/llvm-project/commit/1f391a75af8685e6bba89421443d72ac6a186599
DIFF: https://github.com/llvm/llvm-project/commit/1f391a75af8685e6bba89421443d72ac6a186599.diff
LOG: [ELF] Pass Ctx & to SyntheticSection::finalizeContents
Added:
Modified:
lld/ELF/Arch/ARM.cpp
lld/ELF/InputSection.h
lld/ELF/OutputSections.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index 368b72e687a4ca..bd24e423841ac8 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -1404,7 +1404,7 @@ size_t ArmCmseSGSection::getSize() const {
return entries.size() * entsize;
}
-void ArmCmseSGSection::finalizeContents() {
+void ArmCmseSGSection::finalizeContents(Ctx &) {
if (sgVeneers.empty())
return;
@@ -1472,7 +1472,7 @@ template <typename ELFT> void elf::writeARMCmseImportLib() {
osec->finalizeInputSections(ctx);
osec->shName = shstrtab->addString(osec->name);
osec->size = isec->getSize();
- isec->finalizeContents();
+ isec->finalizeContents(ctx);
osec->offset = alignToPowerOf2(off, osec->addralign);
off = osec->offset + osec->size;
}
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 53dbaf0784b910..4d022ee1e44def 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -483,7 +483,7 @@ class SyntheticSection : public InputSection {
// If the section has the SHF_ALLOC flag and the size may be changed if
// thunks are added, update the section size.
virtual bool isNeeded() const { return true; }
- virtual void finalizeContents() {}
+ virtual void finalizeContents(Ctx &) {}
virtual void writeTo(uint8_t *buf) = 0;
static bool classof(const SectionBase *sec) {
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index e65ed110e098d7..ac07af1649e918 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -247,7 +247,7 @@ void OutputSection::finalizeInputSections(Ctx &ctx) {
commitSection(ctx, s);
}
for (auto *ms : mergeSections)
- ms->finalizeContents();
+ ms->finalizeContents(ctx);
}
static void sortByOrder(MutableArrayRef<InputSection *> in,
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 8298420b8b01dc..cddd5ccddfea6f 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -505,7 +505,7 @@ static void writeCieFde(uint8_t *buf, ArrayRef<uint8_t> d) {
write32(buf, d.size() - 4);
}
-void EhFrameSection::finalizeContents() {
+void EhFrameSection::finalizeContents(Ctx &) {
assert(!this->size); // Not finalized.
switch (ctx.arg.ekind) {
@@ -700,7 +700,7 @@ uint64_t GotSection::getGlobalDynOffset(const Symbol &b) const {
return b.getTlsGdIdx() * ctx.arg.wordsize;
}
-void GotSection::finalizeContents() {
+void GotSection::finalizeContents(Ctx &) {
if (ctx.arg.emachine == EM_PPC64 &&
numEntries <= ctx.target->gotHeaderEntriesNum &&
!ctx.sym.globalOffsetTable)
@@ -869,7 +869,7 @@ bool MipsGotSection::tryMergeGots(FileGot &dst, FileGot &src, bool isPrimary) {
return true;
}
-void MipsGotSection::finalizeContents() { updateAllocSize(); }
+void MipsGotSection::finalizeContents(Ctx &) { updateAllocSize(); }
bool MipsGotSection::updateAllocSize() {
size = headerEntriesNum * ctx.arg.wordsize;
@@ -1574,7 +1574,7 @@ DynamicSection<ELFT>::computeContents() {
return entries;
}
-template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
+template <class ELFT> void DynamicSection<ELFT>::finalizeContents(Ctx &) {
if (OutputSection *sec = getPartition().dynStrTab->getParent())
getParent()->link = sec->sectionIndex;
this->size = computeContents().size() * this->entsize;
@@ -1675,7 +1675,7 @@ void RelocationBaseSection::partitionRels() {
relocs.begin();
}
-void RelocationBaseSection::finalizeContents() {
+void RelocationBaseSection::finalizeContents(Ctx &) {
SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
// When linking glibc statically, .rel{,a}.plt contains R_*_IRELATIVE
@@ -2127,7 +2127,7 @@ static bool sortMipsSymbols(const SymbolTableEntry &l,
return !l.sym->isInGot();
}
-void SymbolTableBaseSection::finalizeContents() {
+void SymbolTableBaseSection::finalizeContents(Ctx &) {
if (OutputSection *sec = strTabSec.getParent())
getParent()->link = sec->sectionIndex;
@@ -2351,7 +2351,7 @@ bool SymtabShndxSection::isNeeded() const {
return size >= SHN_LORESERVE;
}
-void SymtabShndxSection::finalizeContents() {
+void SymtabShndxSection::finalizeContents(Ctx &) {
getParent()->link = ctx.in.symTab->getParent()->sectionIndex;
}
@@ -2393,7 +2393,7 @@ GnuHashTableSection::GnuHashTableSection()
: SyntheticSection(SHF_ALLOC, SHT_GNU_HASH, ctx.arg.wordsize, ".gnu.hash") {
}
-void GnuHashTableSection::finalizeContents() {
+void GnuHashTableSection::finalizeContents(Ctx &) {
if (OutputSection *sec = getPartition().dynSymTab->getParent())
getParent()->link = sec->sectionIndex;
@@ -2503,7 +2503,7 @@ HashTableSection::HashTableSection()
this->entsize = 4;
}
-void HashTableSection::finalizeContents() {
+void HashTableSection::finalizeContents(Ctx &) {
SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
if (OutputSection *sec = symTab->getParent())
@@ -3217,7 +3217,7 @@ void DebugNamesSection<ELFT>::getNameRelocs(
}
}
-template <class ELFT> void DebugNamesSection<ELFT>::finalizeContents() {
+template <class ELFT> void DebugNamesSection<ELFT>::finalizeContents(Ctx &) {
// Get relocations of .debug_names sections.
auto relocs = std::make_unique<DenseMap<uint32_t, uint32_t>[]>(numChunks);
parallelFor(0, numChunks, [&](size_t i) {
@@ -3676,7 +3676,7 @@ StringRef VersionDefinitionSection::getFileDefName() {
return ctx.arg.outputFile;
}
-void VersionDefinitionSection::finalizeContents() {
+void VersionDefinitionSection::finalizeContents(Ctx &) {
fileDefNameOff = getPartition().dynStrTab->addString(getFileDefName());
for (const VersionDefinition &v : namedVersionDefs())
verDefNameOffs.push_back(getPartition().dynStrTab->addString(v.name));
@@ -3732,7 +3732,7 @@ VersionTableSection::VersionTableSection()
this->entsize = 2;
}
-void VersionTableSection::finalizeContents() {
+void VersionTableSection::finalizeContents(Ctx &) {
// At the moment of june 2016 GNU docs does not mention that sh_link field
// should be set, but Sun docs do. Also readelf relies on this field.
getParent()->link = getPartition().dynSymTab->getParent()->sectionIndex;
@@ -3781,7 +3781,7 @@ VersionNeedSection<ELFT>::VersionNeedSection()
: SyntheticSection(SHF_ALLOC, SHT_GNU_verneed, sizeof(uint32_t),
".gnu.version_r") {}
-template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents() {
+template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents(Ctx &) {
for (SharedFile *f : ctx.sharedFiles) {
if (f->vernauxs.empty())
continue;
@@ -3869,7 +3869,7 @@ size_t MergeTailSection::getSize() const { return builder.getSize(); }
void MergeTailSection::writeTo(uint8_t *buf) { builder.write(buf); }
-void MergeTailSection::finalizeContents() {
+void MergeTailSection::finalizeContents(Ctx &) {
// Add all string pieces to the string table builder to create section
// contents.
for (MergeInputSection *sec : sections)
@@ -3902,7 +3902,7 @@ void MergeNoTailSection::writeTo(uint8_t *buf) {
// value is
diff erent from T's. If that's the case, we can safely put S and
// T into
diff erent string builders without worrying about merge misses.
// We do it in parallel.
-void MergeNoTailSection::finalizeContents() {
+void MergeNoTailSection::finalizeContents(Ctx &) {
// Initializes string table builders.
for (size_t i = 0; i < numShards; ++i)
shards.emplace_back(StringTableBuilder::RAW, llvm::Align(addralign));
@@ -4084,7 +4084,7 @@ static bool isDuplicateArmExidxSec(InputSection *prev, InputSection *cur) {
// must be sorted in ascending order of address, Sentinel is set to the
// InputSection with the highest address and any InputSections that have
// mergeable .ARM.exidx table entries are removed from it.
-void ARMExidxSyntheticSection::finalizeContents() {
+void ARMExidxSyntheticSection::finalizeContents(Ctx &) {
// Ensure that any fixed-point iterations after the first see the original set
// of sections.
if (!originalExecutableSections.empty())
@@ -4271,7 +4271,7 @@ bool PPC32Got2Section::isNeeded() const {
return false;
}
-void PPC32Got2Section::finalizeContents() {
+void PPC32Got2Section::finalizeContents(Ctx &) {
// PPC32 may create multiple GOT sections for -fPIC/-fPIE, one per file in
// .got2 . This function computes outSecOff of each .got2 to be used in
// PPC32PltCallStub::writeTo(). The purpose of this empty synthetic section is
@@ -4441,7 +4441,7 @@ size_t PartitionIndexSection::getSize() const {
return 12 * (ctx.partitions.size() - 1);
}
-void PartitionIndexSection::finalizeContents() {
+void PartitionIndexSection::finalizeContents(Ctx &) {
for (size_t i = 1; i != ctx.partitions.size(); ++i)
ctx.partitions[i].nameStrTab =
ctx.mainPart->dynStrTab->addString(ctx.partitions[i].name);
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 759a908b202a94..2fc78759b62ec0 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -52,7 +52,7 @@ class EhFrameSection final : public SyntheticSection {
public:
EhFrameSection();
void writeTo(uint8_t *buf) override;
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
bool isNeeded() const override { return !sections.empty(); }
size_t getSize() const override { return size; }
@@ -106,7 +106,7 @@ class GotSection final : public SyntheticSection {
public:
GotSection();
size_t getSize() const override { return size; }
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
bool isNeeded() const override;
void writeTo(uint8_t *buf) override;
@@ -186,7 +186,7 @@ class MipsGotSection final : public SyntheticSection {
void writeTo(uint8_t *buf) override;
size_t getSize() const override { return size; }
bool updateAllocSize() override;
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
bool isNeeded() const override;
// Join separate GOTs built for each input file to generate
@@ -484,7 +484,7 @@ template <class ELFT> class DynamicSection final : public SyntheticSection {
public:
DynamicSection();
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
void writeTo(uint8_t *buf) override;
size_t getSize() const override { return size; }
@@ -545,7 +545,7 @@ class RelocationBaseSection : public SyntheticSection {
size_t getRelativeRelocCount() const { return numRelativeRelocs; }
void mergeRels();
void partitionRels();
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
static bool classof(const SectionBase *d) {
return SyntheticSection::classof(d) &&
(d->type == llvm::ELF::SHT_RELA || d->type == llvm::ELF::SHT_REL ||
@@ -647,7 +647,7 @@ struct SymbolTableEntry {
class SymbolTableBaseSection : public SyntheticSection {
public:
SymbolTableBaseSection(StringTableSection &strTabSec);
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
size_t getSize() const override { return getNumSymbols() * entsize; }
void addSymbol(Symbol *sym);
unsigned getNumSymbols() const { return symbols.size() + 1; }
@@ -683,7 +683,7 @@ class SymtabShndxSection final : public SyntheticSection {
void writeTo(uint8_t *buf) override;
size_t getSize() const override;
bool isNeeded() const override;
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
};
// Outputs GNU Hash section. For detailed explanation see:
@@ -691,7 +691,7 @@ class SymtabShndxSection final : public SyntheticSection {
class GnuHashTableSection final : public SyntheticSection {
public:
GnuHashTableSection();
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
void writeTo(uint8_t *buf) override;
size_t getSize() const override { return size; }
@@ -719,7 +719,7 @@ class GnuHashTableSection final : public SyntheticSection {
class HashTableSection final : public SyntheticSection {
public:
HashTableSection();
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
void writeTo(uint8_t *buf) override;
size_t getSize() const override { return size; }
@@ -913,7 +913,7 @@ template <class ELFT>
class DebugNamesSection final : public DebugNamesBaseSection {
public:
DebugNamesSection();
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
void writeTo(uint8_t *buf) override;
template <class RelTy>
@@ -1016,7 +1016,7 @@ class EhFrameHeader final : public SyntheticSection {
class VersionDefinitionSection final : public SyntheticSection {
public:
VersionDefinitionSection();
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
size_t getSize() const override;
void writeTo(uint8_t *buf) override;
@@ -1038,7 +1038,7 @@ class VersionDefinitionSection final : public SyntheticSection {
class VersionTableSection final : public SyntheticSection {
public:
VersionTableSection();
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
size_t getSize() const override;
void writeTo(uint8_t *buf) override;
bool isNeeded() const override;
@@ -1069,7 +1069,7 @@ class VersionNeedSection final : public SyntheticSection {
public:
VersionNeedSection();
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
void writeTo(uint8_t *buf) override;
size_t getSize() const override;
bool isNeeded() const override;
@@ -1097,7 +1097,7 @@ class MergeTailSection final : public MergeSyntheticSection {
size_t getSize() const override;
void writeTo(uint8_t *buf) override;
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
private:
llvm::StringTableBuilder builder;
@@ -1111,7 +1111,7 @@ class MergeNoTailSection final : public MergeSyntheticSection {
size_t getSize() const override { return size; }
void writeTo(uint8_t *buf) override;
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
private:
// We use the most significant bits of a hash as a shard ID.
@@ -1240,7 +1240,7 @@ class ARMExidxSyntheticSection : public SyntheticSection {
void writeTo(uint8_t *buf) override;
bool isNeeded() const override;
// Sort and remove duplicate entries.
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
InputSection *getLinkOrderDep() const;
static bool classof(const SectionBase *sec) {
@@ -1313,7 +1313,7 @@ class ArmCmseSGSection final : public SyntheticSection {
void writeTo(uint8_t *buf) override;
void addSGVeneer(Symbol *sym, Symbol *ext_sym);
void addMappingSymbol();
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
void exportEntries(SymbolTableBaseSection *symTab);
uint64_t impLibMaxAddr = 0;
@@ -1330,7 +1330,7 @@ class PPC32Got2Section final : public SyntheticSection {
PPC32Got2Section();
size_t getSize() const override { return 0; }
bool isNeeded() const override;
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
void writeTo(uint8_t *buf) override {}
};
@@ -1347,7 +1347,7 @@ class PPC64LongBranchTargetSection final : public SyntheticSection {
size_t getSize() const override;
void writeTo(uint8_t *buf) override;
bool isNeeded() const override;
- void finalizeContents() override { finalized = true; }
+ void finalizeContents(Ctx &) override { finalized = true; }
private:
SmallVector<std::pair<const Symbol *, int64_t>, 0> entries;
@@ -1375,7 +1375,7 @@ class PartitionIndexSection final : public SyntheticSection {
public:
PartitionIndexSection();
size_t getSize() const override;
- void finalizeContents() override;
+ void finalizeContents(Ctx &) override;
void writeTo(uint8_t *buf) override;
};
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 4c28f3e2d1845b..a1ce347a92009d 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1427,7 +1427,7 @@ template <class ELFT> void Writer<ELFT>::resolveShfLinkOrder() {
static void finalizeSynthetic(SyntheticSection *sec) {
if (sec && sec->isNeeded() && sec->getParent()) {
llvm::TimeTraceScope timeScope("Finalize synthetic sections", sec->name);
- sec->finalizeContents();
+ sec->finalizeContents(ctx);
}
}
More information about the llvm-commits
mailing list