[lld] e2f0ec3 - [ELF] Pass Ctx & to SyntheticSection::getSize
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 22:53:14 PDT 2024
Author: Fangrui Song
Date: 2024-10-03T22:53:07-07:00
New Revision: e2f0ec3a3a8a2981be8a1aac2004cfb9064c61e8
URL: https://github.com/llvm/llvm-project/commit/e2f0ec3a3a8a2981be8a1aac2004cfb9064c61e8
DIFF: https://github.com/llvm/llvm-project/commit/e2f0ec3a3a8a2981be8a1aac2004cfb9064c61e8.diff
LOG: [ELF] Pass Ctx & to SyntheticSection::getSize
Added:
Modified:
lld/ELF/AArch64ErrataFix.cpp
lld/ELF/ARMErrataFix.cpp
lld/ELF/Arch/ARM.cpp
lld/ELF/Arch/RISCV.cpp
lld/ELF/InputSection.cpp
lld/ELF/InputSection.h
lld/ELF/Relocations.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/AArch64ErrataFix.cpp b/lld/ELF/AArch64ErrataFix.cpp
index 789711983140bb..01873cbc1e5c10 100644
--- a/lld/ELF/AArch64ErrataFix.cpp
+++ b/lld/ELF/AArch64ErrataFix.cpp
@@ -376,7 +376,7 @@ class elf::Patch843419Section final : public SyntheticSection {
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override { return 8; }
+ size_t getSize(Ctx &) const override { return 8; }
uint64_t getLDSTAddr() const;
@@ -399,7 +399,7 @@ Patch843419Section::Patch843419Section(InputSection *p, uint64_t off)
this->parent = p->getParent();
patchSym = addSyntheticLocal(
saver().save("__CortexA53843419_" + utohexstr(getLDSTAddr())), STT_FUNC,
- 0, getSize(), *this);
+ 0, getSize(ctx), *this);
addSyntheticLocal(saver().save("$x"), STT_NOTYPE, 0, 0, *this);
}
diff --git a/lld/ELF/ARMErrataFix.cpp b/lld/ELF/ARMErrataFix.cpp
index ebc79bb33af3ef..03feabe6d676f2 100644
--- a/lld/ELF/ARMErrataFix.cpp
+++ b/lld/ELF/ARMErrataFix.cpp
@@ -74,7 +74,7 @@ class elf::Patch657417Section final : public SyntheticSection {
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override { return 4; }
+ size_t getSize(Ctx &) const override { return 4; }
// Get the virtual address of the branch instruction at patcheeOffset.
uint64_t getBranchAddr() const;
@@ -141,7 +141,7 @@ Patch657417Section::Patch657417Section(InputSection *p, uint64_t off,
parent = p->getParent();
patchSym = addSyntheticLocal(
saver().save("__CortexA8657417_" + utohexstr(getBranchAddr())), STT_FUNC,
- isARM ? 0 : 1, getSize(), *this);
+ isARM ? 0 : 1, getSize(ctx), *this);
addSyntheticLocal(saver().save(isARM ? "$a" : "$t"), STT_NOTYPE, 0, 0, *this);
}
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index 6969a9cab7e7b5..d22ac540c92a1e 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -1397,7 +1397,7 @@ void ArmCmseSGSection::addMappingSymbol() {
addSyntheticLocal("$t", STT_NOTYPE, /*off=*/0, /*size=*/0, *this);
}
-size_t ArmCmseSGSection::getSize() const {
+size_t ArmCmseSGSection::getSize(Ctx &) const {
if (sgVeneers.empty())
return (impLibMaxAddr ? impLibMaxAddr - getVA() : 0) + newEntries * entsize;
@@ -1471,7 +1471,7 @@ template <typename ELFT> void elf::writeARMCmseImportLib() {
osec->recordSection(isec);
osec->finalizeInputSections(ctx);
osec->shName = shstrtab->addString(osec->name);
- osec->size = isec->getSize();
+ osec->size = isec->getSize(ctx);
isec->finalizeContents(ctx);
osec->offset = alignToPowerOf2(off, osec->addralign);
off = osec->offset + osec->size;
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index ea20613070097f..f13000fcadec2b 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1047,7 +1047,7 @@ class RISCVAttributesSection final : public SyntheticSection {
RISCVAttributesSection()
: SyntheticSection(0, SHT_RISCV_ATTRIBUTES, 1, ".riscv.attributes") {}
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &) const override { return size; }
void writeTo(Ctx &, uint8_t *buf) override;
static constexpr StringRef vendor = "riscv";
@@ -1277,7 +1277,7 @@ mergeAttributesSection(const SmallVector<InputSectionBase *, 0> §ions) {
}
void RISCVAttributesSection::writeTo(Ctx &ctx, uint8_t *buf) {
- const size_t size = getSize();
+ const size_t size = getSize(ctx);
uint8_t *const end = buf + size;
*buf = ELFAttrs::Format_Version;
write32(buf + 1, size - 1);
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 54a214e01b0892..7c8da8944e502e 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -101,7 +101,7 @@ InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
size_t InputSectionBase::getSize() const {
if (auto *s = dyn_cast<SyntheticSection>(this))
- return s->getSize();
+ return s->getSize(ctx);
return size - bytesDropped;
}
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 5e5457812c275d..c368ed4dc2e9c2 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -478,7 +478,7 @@ class SyntheticSection : public InputSection {
InputSectionBase::Synthetic) {}
virtual ~SyntheticSection() = default;
- virtual size_t getSize() const = 0;
+ virtual size_t getSize(Ctx &) const = 0;
virtual bool updateAllocSize() { return false; }
// If the section has the SHF_ALLOC flag and the size may be changed if
// thunks are added, update the section size.
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 01bb2e6b718126..7bb657822ee192 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -2019,14 +2019,15 @@ static void forEachInputSectionDescription(
// This may invalidate any output section offsets stored outside of InputSection
void ThunkCreator::mergeThunks(ArrayRef<OutputSection *> outputSections) {
forEachInputSectionDescription(
- outputSections, [&](OutputSection *os, InputSectionDescription *isd) {
+ outputSections,
+ [&, &ctx = ctx](OutputSection *os, InputSectionDescription *isd) {
if (isd->thunkSections.empty())
return;
// Remove any zero sized precreated Thunks.
llvm::erase_if(isd->thunkSections,
- [](const std::pair<ThunkSection *, uint32_t> &ts) {
- return ts.first->getSize() == 0;
+ [&ctx](const std::pair<ThunkSection *, uint32_t> &ts) {
+ return ts.first->getSize(ctx) == 0;
});
// ISD->ThunkSections contains all created ThunkSections, including
@@ -2079,7 +2080,7 @@ ThunkSection *ThunkCreator::getISDThunkSec(OutputSection *os,
for (std::pair<ThunkSection *, uint32_t> tp : isd->thunkSections) {
ThunkSection *ts = tp.first;
uint64_t tsBase = os->addr + ts->outSecOff - pcBias;
- uint64_t tsLimit = tsBase + ts->getSize();
+ uint64_t tsLimit = tsBase + ts->getSize(ctx);
if (ctx.target->inBranchRange(rel.type, src,
(src > tsLimit) ? tsBase : tsLimit))
return ts;
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 1c34adff724b25..521873f4cb141e 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -167,7 +167,7 @@ template <class ELFT>
void MipsOptionsSection<ELFT>::writeTo(Ctx &ctx, uint8_t *buf) {
auto *options = reinterpret_cast<Elf_Mips_Options *>(buf);
options->kind = ODK_REGINFO;
- options->size = getSize();
+ options->size = getSize(ctx);
if (!ctx.arg.relocatable)
reginfo.ri_gp_value = ctx.in.mipsGot->getGp();
@@ -322,7 +322,7 @@ GnuPropertySection::GnuPropertySection()
void GnuPropertySection::writeTo(Ctx &ctx, uint8_t *buf) {
write32(buf, 4); // Name size
- write32(buf + 4, getSize() - 16); // Content size
+ write32(buf + 4, getSize(ctx) - 16); // Content size
write32(buf + 8, NT_GNU_PROPERTY_TYPE_0); // Type
memcpy(buf + 12, "GNU", 4); // Name string
@@ -348,7 +348,7 @@ void GnuPropertySection::writeTo(Ctx &ctx, uint8_t *buf) {
}
}
-size_t GnuPropertySection::getSize() const {
+size_t GnuPropertySection::getSize(Ctx &ctx) const {
uint32_t contentSize = 0;
if (ctx.arg.andFeatures != 0)
contentSize += ctx.arg.is64 ? 16 : 12;
@@ -1183,7 +1183,7 @@ void GotPltSection::addEntry(Symbol &sym) {
entries.push_back(&sym);
}
-size_t GotPltSection::getSize() const {
+size_t GotPltSection::getSize(Ctx &ctx) const {
return (ctx.target->gotPltHeaderEntriesNum + entries.size()) *
ctx.target->gotEntrySize;
}
@@ -1228,7 +1228,7 @@ void IgotPltSection::addEntry(Symbol &sym) {
entries.push_back(&sym);
}
-size_t IgotPltSection::getSize() const {
+size_t IgotPltSection::getSize(Ctx &ctx) const {
return entries.size() * ctx.target->gotEntrySize;
}
@@ -1303,9 +1303,9 @@ DynamicSection<ELFT>::DynamicSection()
//
// DT_RELASZ is the total size of the included sections.
static uint64_t addRelaSz(const RelocationBaseSection &relaDyn) {
- size_t size = relaDyn.getSize();
+ size_t size = relaDyn.getSize(ctx);
if (ctx.in.relaPlt->getParent() == relaDyn.getParent())
- size += ctx.in.relaPlt->getSize();
+ size += ctx.in.relaPlt->getSize(ctx);
return size;
}
@@ -1313,7 +1313,7 @@ static uint64_t addRelaSz(const RelocationBaseSection &relaDyn) {
// output section. When this occurs we cannot just use the OutputSection
// Size. Moreover the [DT_JMPREL, DT_JMPREL + DT_PLTRELSZ) is permitted to
// overlap with the [DT_RELA, DT_RELA + DT_RELASZ).
-static uint64_t addPltRelSz() { return ctx.in.relaPlt->getSize(); }
+static uint64_t addPltRelSz() { return ctx.in.relaPlt->getSize(ctx); }
// Add remaining entries to complete .dynamic contents.
template <class ELFT>
@@ -1482,7 +1482,7 @@ DynamicSection<ELFT>::computeContents() {
addInSec(DT_AARCH64_MEMTAG_GLOBALS,
*ctx.mainPart->memtagGlobalDescriptors);
addInt(DT_AARCH64_MEMTAG_GLOBALSSZ,
- ctx.mainPart->memtagGlobalDescriptors->getSize());
+ ctx.mainPart->memtagGlobalDescriptors->getSize(ctx));
}
}
}
@@ -1490,7 +1490,7 @@ DynamicSection<ELFT>::computeContents() {
addInSec(DT_SYMTAB, *part.dynSymTab);
addInt(DT_SYMENT, sizeof(Elf_Sym));
addInSec(DT_STRTAB, *part.dynStrTab);
- addInt(DT_STRSZ, part.dynStrTab->getSize());
+ addInt(DT_STRSZ, part.dynStrTab->getSize(ctx));
if (!ctx.arg.zText)
addInt(DT_TEXTREL, 0);
if (part.gnuHashTab && part.gnuHashTab->getParent())
@@ -2361,7 +2361,7 @@ void SymtabShndxSection::finalizeContents(Ctx &) {
getParent()->link = ctx.in.symTab->getParent()->sectionIndex;
}
-size_t SymtabShndxSection::getSize() const {
+size_t SymtabShndxSection::getSize(Ctx &ctx) const {
return ctx.in.symTab->getNumSymbols() * 4;
}
@@ -2583,7 +2583,7 @@ void PltSection::addEntry(Symbol &sym) {
entries.push_back(&sym);
}
-size_t PltSection::getSize() const {
+size_t PltSection::getSize(Ctx &ctx) const {
return headerSize + entries.size() * ctx.target->pltEntrySize;
}
@@ -2620,7 +2620,7 @@ void IpltSection::writeTo(Ctx &ctx, uint8_t *buf) {
}
}
-size_t IpltSection::getSize() const {
+size_t IpltSection::getSize(Ctx &ctx) const {
return entries.size() * ctx.target->ipltEntrySize;
}
@@ -2648,7 +2648,7 @@ void PPC32GlinkSection::writeTo(Ctx &ctx, uint8_t *buf) {
writePPC32GlinkSection(buf, entries.size());
}
-size_t PPC32GlinkSection::getSize() const {
+size_t PPC32GlinkSection::getSize(Ctx &ctx) const {
return headerSize + entries.size() * ctx.target->pltEntrySize + footerSize;
}
@@ -2717,7 +2717,7 @@ void IBTPltSection::writeTo(Ctx &ctx, uint8_t *buf) {
ctx.target->writeIBTPlt(buf, ctx.in.plt->getNumEntries());
}
-size_t IBTPltSection::getSize() const {
+size_t IBTPltSection::getSize(Ctx &ctx) const {
// 16 is the header size of .plt.
return 16 + ctx.in.plt->getNumEntries() * ctx.target->pltEntrySize;
}
@@ -3662,7 +3662,7 @@ void EhFrameHeader::write() {
}
}
-size_t EhFrameHeader::getSize() const {
+size_t EhFrameHeader::getSize(Ctx &ctx) const {
// .eh_frame_hdr has a 12 bytes header followed by an array of FDEs.
return 12 + getPartition().ehFrame->numFdes * 8;
}
@@ -3728,7 +3728,7 @@ void VersionDefinitionSection::writeTo(Ctx &ctx, uint8_t *buf) {
write32(buf + 16, 0); // vd_next
}
-size_t VersionDefinitionSection::getSize() const {
+size_t VersionDefinitionSection::getSize(Ctx &ctx) const {
return EntrySize * getVerDefNum();
}
@@ -3745,7 +3745,7 @@ void VersionTableSection::finalizeContents(Ctx &) {
getParent()->link = getPartition().dynSymTab->getParent()->sectionIndex;
}
-size_t VersionTableSection::getSize() const {
+size_t VersionTableSection::getSize(Ctx &ctx) const {
return (getPartition().dynSymTab->getSymbols().size() + 1) * 2;
}
@@ -3852,7 +3852,7 @@ void VersionNeedSection<ELFT>::writeTo(Ctx &ctx, uint8_t *buf) {
verneed[-1].vn_next = 0;
}
-template <class ELFT> size_t VersionNeedSection<ELFT>::getSize() const {
+template <class ELFT> size_t VersionNeedSection<ELFT>::getSize(Ctx &ctx) const {
return verneeds.size() * sizeof(Elf_Verneed) +
SharedFile::vernauxNum * sizeof(Elf_Vernaux);
}
@@ -3873,9 +3873,9 @@ MergeTailSection::MergeTailSection(StringRef name, uint32_t type,
: MergeSyntheticSection(name, type, flags, alignment),
builder(StringTableBuilder::RAW, llvm::Align(alignment)) {}
-size_t MergeTailSection::getSize() const { return builder.getSize(); }
+size_t MergeTailSection::getSize(Ctx &) const { return builder.getSize(); }
-void MergeTailSection::writeTo(Ctx &ctx, uint8_t *buf) { builder.write(buf); }
+void MergeTailSection::writeTo(Ctx &, uint8_t *buf) { builder.write(buf); }
void MergeTailSection::finalizeContents(Ctx &) {
// Add all string pieces to the string table builder to create section
@@ -4228,7 +4228,7 @@ ThunkSection::ThunkSection(OutputSection *os, uint64_t off)
this->outSecOff = off;
}
-size_t ThunkSection::getSize() const {
+size_t ThunkSection::getSize(Ctx &) const {
if (roundUpSizeForErrata)
return alignTo(size, 4096);
return size;
@@ -4318,7 +4318,7 @@ PPC64LongBranchTargetSection::addEntry(const Symbol *sym, int64_t addend) {
return res.first->second;
}
-size_t PPC64LongBranchTargetSection::getSize() const {
+size_t PPC64LongBranchTargetSection::getSize(Ctx &ctx) const {
return entries.size() * 8;
}
@@ -4415,7 +4415,7 @@ PartitionElfHeaderSection<ELFT>::PartitionElfHeaderSection()
: SyntheticSection(SHF_ALLOC, SHT_LLVM_PART_EHDR, 1, "") {}
template <typename ELFT>
-size_t PartitionElfHeaderSection<ELFT>::getSize() const {
+size_t PartitionElfHeaderSection<ELFT>::getSize(Ctx &ctx) const {
return sizeof(typename ELFT::Ehdr);
}
@@ -4433,7 +4433,7 @@ PartitionProgramHeadersSection<ELFT>::PartitionProgramHeadersSection()
: SyntheticSection(SHF_ALLOC, SHT_LLVM_PART_PHDR, 1, ".phdrs") {}
template <typename ELFT>
-size_t PartitionProgramHeadersSection<ELFT>::getSize() const {
+size_t PartitionProgramHeadersSection<ELFT>::getSize(Ctx &ctx) const {
return sizeof(typename ELFT::Phdr) * getPartition().phdrs.size();
}
@@ -4445,7 +4445,7 @@ void PartitionProgramHeadersSection<ELFT>::writeTo(Ctx &ctx, uint8_t *buf) {
PartitionIndexSection::PartitionIndexSection()
: SyntheticSection(SHF_ALLOC, SHT_PROGBITS, 4, ".rodata") {}
-size_t PartitionIndexSection::getSize() const {
+size_t PartitionIndexSection::getSize(Ctx &ctx) const {
return 12 * (ctx.partitions.size() - 1);
}
@@ -4548,7 +4548,7 @@ void MemtagAndroidNote::writeTo(Ctx &ctx, uint8_t *buf) {
write32(buf, value); // note value
}
-size_t MemtagAndroidNote::getSize() const {
+size_t MemtagAndroidNote::getSize(Ctx &ctx) const {
return sizeof(llvm::ELF::Elf64_Nhdr) +
/*namesz=*/alignTo(sizeof(kMemtagAndroidNoteName), 4) +
/*descsz=*/sizeof(uint32_t);
@@ -4563,7 +4563,7 @@ void PackageMetadataNote::writeTo(Ctx &ctx, uint8_t *buf) {
ctx.arg.packageMetadata.size());
}
-size_t PackageMetadataNote::getSize() const {
+size_t PackageMetadataNote::getSize(Ctx &ctx) const {
return sizeof(llvm::ELF::Elf64_Nhdr) + 4 +
alignTo(ctx.arg.packageMetadata.size() + 1, 4);
}
@@ -4623,19 +4623,19 @@ createMemtagGlobalDescriptors(const SmallVector<const Symbol *, 0> &symbols,
}
bool MemtagGlobalDescriptors::updateAllocSize() {
- size_t oldSize = getSize();
+ size_t oldSize = getSize(ctx);
std::stable_sort(symbols.begin(), symbols.end(),
[](const Symbol *s1, const Symbol *s2) {
return s1->getVA() < s2->getVA();
});
- return oldSize != getSize();
+ return oldSize != getSize(ctx);
}
void MemtagGlobalDescriptors::writeTo(Ctx &ctx, uint8_t *buf) {
createMemtagGlobalDescriptors(symbols, buf);
}
-size_t MemtagGlobalDescriptors::getSize() const {
+size_t MemtagGlobalDescriptors::getSize(Ctx &ctx) const {
return createMemtagGlobalDescriptors(symbols);
}
@@ -4831,7 +4831,7 @@ template <class ELFT> void elf::createSyntheticSections(Ctx &ctx) {
ctx.in.partIndex = std::make_unique<PartitionIndexSection>();
addOptionalRegular("__part_index_begin", ctx.in.partIndex.get(), 0);
addOptionalRegular("__part_index_end", ctx.in.partIndex.get(),
- ctx.in.partIndex->getSize());
+ ctx.in.partIndex->getSize(ctx));
add(*ctx.in.partIndex);
}
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 12417da80b7b4d..37724d783162c5 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -54,7 +54,7 @@ class EhFrameSection final : public SyntheticSection {
void writeTo(Ctx &, uint8_t *buf) override;
void finalizeContents(Ctx &) override;
bool isNeeded() const override { return !sections.empty(); }
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
static bool classof(const SectionBase *d) {
return SyntheticSection::classof(d) && d->name == ".eh_frame";
@@ -105,7 +105,7 @@ class EhFrameSection final : public SyntheticSection {
class GotSection final : public SyntheticSection {
public:
GotSection();
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
void finalizeContents(Ctx &) override;
bool isNeeded() const override;
void writeTo(Ctx &, uint8_t *buf) override;
@@ -139,14 +139,14 @@ class GnuStackSection : public SyntheticSection {
GnuStackSection()
: SyntheticSection(0, llvm::ELF::SHT_PROGBITS, 1, ".note.GNU-stack") {}
void writeTo(Ctx &, uint8_t *buf) override {}
- size_t getSize() const override { return 0; }
+ size_t getSize(Ctx &ctx) const override { return 0; }
};
class GnuPropertySection final : public SyntheticSection {
public:
GnuPropertySection();
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
};
// .note.gnu.build-id section.
@@ -158,7 +158,7 @@ class BuildIdSection : public SyntheticSection {
const size_t hashSize;
BuildIdSection();
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override { return headerSize + hashSize; }
+ size_t getSize(Ctx &ctx) const override { return headerSize + hashSize; }
void writeBuildId(llvm::ArrayRef<uint8_t> buf);
private:
@@ -174,7 +174,7 @@ class BssSection final : public SyntheticSection {
BssSection(StringRef name, uint64_t size, uint32_t addralign);
void writeTo(Ctx &, uint8_t *) override {}
bool isNeeded() const override { return size != 0; }
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
static bool classof(const SectionBase *s) { return s->bss; }
uint64_t size;
@@ -184,7 +184,7 @@ class MipsGotSection final : public SyntheticSection {
public:
MipsGotSection();
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
bool updateAllocSize() override;
void finalizeContents(Ctx &) override;
bool isNeeded() const override;
@@ -361,7 +361,7 @@ class GotPltSection final : public SyntheticSection {
public:
GotPltSection();
void addEntry(Symbol &sym);
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void writeTo(Ctx &, uint8_t *buf) override;
bool isNeeded() const override;
@@ -381,7 +381,7 @@ class IgotPltSection final : public SyntheticSection {
public:
IgotPltSection();
void addEntry(Symbol &sym);
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void writeTo(Ctx &, uint8_t *buf) override;
bool isNeeded() const override { return !entries.empty(); }
@@ -394,7 +394,7 @@ class StringTableSection final : public SyntheticSection {
StringTableSection(StringRef name, bool dynamic);
unsigned addString(StringRef s, bool hashIt = true);
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
bool isDynamic() const { return dynamic; }
private:
@@ -486,7 +486,7 @@ template <class ELFT> class DynamicSection final : public SyntheticSection {
DynamicSection();
void finalizeContents(Ctx &) override;
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
private:
std::vector<std::pair<int32_t, uint64_t>> computeContents();
@@ -541,7 +541,9 @@ class RelocationBaseSection : public SyntheticSection {
return !relocs.empty() ||
llvm::any_of(relocsVec, [](auto &v) { return !v.empty(); });
}
- size_t getSize() const override { return relocs.size() * this->entsize; }
+ size_t getSize(Ctx &ctx) const override {
+ return relocs.size() * this->entsize;
+ }
size_t getRelativeRelocCount() const { return numRelativeRelocs; }
void mergeRels();
void partitionRels();
@@ -589,7 +591,7 @@ class AndroidPackedRelocationSection final : public RelocationBaseSection {
AndroidPackedRelocationSection(StringRef name, unsigned concurrency);
bool updateAllocSize() override;
- size_t getSize() const override { return relocData.size(); }
+ size_t getSize(Ctx &ctx) const override { return relocData.size(); }
void writeTo(Ctx &, uint8_t *buf) override {
memcpy(buf, relocData.data(), relocData.size());
}
@@ -630,9 +632,11 @@ template <class ELFT> class RelrSection final : public RelrBaseSection {
RelrSection(unsigned concurrency, bool isAArch64Auth = false);
bool updateAllocSize() override;
- size_t getSize() const override { return relrRelocs.size() * this->entsize; }
- void writeTo(Ctx &, uint8_t *buf) override {
- memcpy(buf, relrRelocs.data(), getSize());
+ size_t getSize(Ctx &ctx) const override {
+ return relrRelocs.size() * this->entsize;
+ }
+ void writeTo(Ctx &ctx, uint8_t *buf) override {
+ memcpy(buf, relrRelocs.data(), getSize(ctx));
}
private:
@@ -648,7 +652,7 @@ class SymbolTableBaseSection : public SyntheticSection {
public:
SymbolTableBaseSection(StringTableSection &strTabSec);
void finalizeContents(Ctx &) override;
- size_t getSize() const override { return getNumSymbols() * entsize; }
+ size_t getSize(Ctx &ctx) const override { return getNumSymbols() * entsize; }
void addSymbol(Symbol *sym);
unsigned getNumSymbols() const { return symbols.size() + 1; }
size_t getSymbolIndex(const Symbol &sym);
@@ -681,7 +685,7 @@ class SymtabShndxSection final : public SyntheticSection {
SymtabShndxSection();
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
bool isNeeded() const override;
void finalizeContents(Ctx &) override;
};
@@ -693,7 +697,7 @@ class GnuHashTableSection final : public SyntheticSection {
GnuHashTableSection();
void finalizeContents(Ctx &) override;
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
// Adds symbols to the hash table.
// Sorts the input to satisfy GNU hash section requirements.
@@ -721,7 +725,7 @@ class HashTableSection final : public SyntheticSection {
HashTableSection();
void finalizeContents(Ctx &) override;
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
private:
size_t size = 0;
@@ -742,7 +746,7 @@ class PltSection : public SyntheticSection {
public:
PltSection();
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
bool isNeeded() const override;
void addSymbols();
void addEntry(Symbol &sym);
@@ -763,7 +767,7 @@ class IpltSection final : public SyntheticSection {
public:
IpltSection();
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
bool isNeeded() const override { return !entries.empty(); }
void addSymbols();
void addEntry(Symbol &sym);
@@ -773,7 +777,7 @@ class PPC32GlinkSection : public PltSection {
public:
PPC32GlinkSection();
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
SmallVector<const Symbol *, 0> canonical_plts;
static constexpr size_t footerSize = 64;
@@ -785,7 +789,7 @@ class IBTPltSection : public SyntheticSection {
IBTPltSection();
void writeTo(Ctx &, uint8_t *Buf) override;
bool isNeeded() const override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
};
// Used to align the end of the PT_GNU_RELRO segment and the associated PT_LOAD
@@ -794,7 +798,7 @@ class IBTPltSection : public SyntheticSection {
class RelroPaddingSection final : public SyntheticSection {
public:
RelroPaddingSection();
- size_t getSize() const override { return 0; }
+ size_t getSize(Ctx &ctx) const override { return 0; }
void writeTo(Ctx &, uint8_t *buf) override {}
};
@@ -869,7 +873,7 @@ class DebugNamesBaseSection : public SyntheticSection {
};
DebugNamesBaseSection();
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
bool isNeeded() const override { return numChunks > 0; }
protected:
@@ -962,7 +966,7 @@ class GdbIndexSection final : public SyntheticSection {
GdbIndexSection();
template <typename ELFT> static std::unique_ptr<GdbIndexSection> create();
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
bool isNeeded() const override;
private:
@@ -1001,7 +1005,7 @@ class EhFrameHeader final : public SyntheticSection {
EhFrameHeader();
void write();
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
bool isNeeded() const override;
};
@@ -1017,7 +1021,7 @@ class VersionDefinitionSection final : public SyntheticSection {
public:
VersionDefinitionSection();
void finalizeContents(Ctx &) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void writeTo(Ctx &, uint8_t *buf) override;
private:
@@ -1039,7 +1043,7 @@ class VersionTableSection final : public SyntheticSection {
public:
VersionTableSection();
void finalizeContents(Ctx &) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void writeTo(Ctx &, uint8_t *buf) override;
bool isNeeded() const override;
};
@@ -1071,7 +1075,7 @@ class VersionNeedSection final : public SyntheticSection {
VersionNeedSection();
void finalizeContents(Ctx &) override;
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
bool isNeeded() const override;
};
@@ -1095,7 +1099,7 @@ class MergeTailSection final : public MergeSyntheticSection {
MergeTailSection(StringRef name, uint32_t type, uint64_t flags,
uint32_t addralign);
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void writeTo(Ctx &, uint8_t *buf) override;
void finalizeContents(Ctx &) override;
@@ -1109,7 +1113,7 @@ class MergeNoTailSection final : public MergeSyntheticSection {
uint32_t addralign)
: MergeSyntheticSection(name, type, flags, addralign) {}
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
void writeTo(Ctx &, uint8_t *buf) override;
void finalizeContents(Ctx &) override;
@@ -1142,7 +1146,7 @@ class MipsAbiFlagsSection final : public SyntheticSection {
static std::unique_ptr<MipsAbiFlagsSection> create();
MipsAbiFlagsSection(Elf_Mips_ABIFlags flags);
- size_t getSize() const override { return sizeof(Elf_Mips_ABIFlags); }
+ size_t getSize(Ctx &ctx) const override { return sizeof(Elf_Mips_ABIFlags); }
void writeTo(Ctx &, uint8_t *buf) override;
private:
@@ -1160,7 +1164,7 @@ template <class ELFT> class MipsOptionsSection final : public SyntheticSection {
MipsOptionsSection(Elf_Mips_RegInfo reginfo);
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override {
+ size_t getSize(Ctx &ctx) const override {
return sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo);
}
@@ -1176,7 +1180,7 @@ template <class ELFT> class MipsReginfoSection final : public SyntheticSection {
static std::unique_ptr<MipsReginfoSection> create();
MipsReginfoSection(Elf_Mips_RegInfo reginfo);
- size_t getSize() const override { return sizeof(Elf_Mips_RegInfo); }
+ size_t getSize(Ctx &ctx) const override { return sizeof(Elf_Mips_RegInfo); }
void writeTo(Ctx &, uint8_t *buf) override;
private:
@@ -1190,7 +1194,7 @@ template <class ELFT> class MipsReginfoSection final : public SyntheticSection {
class MipsRldMapSection final : public SyntheticSection {
public:
MipsRldMapSection();
- size_t getSize() const override { return ctx.arg.wordsize; }
+ size_t getSize(Ctx &ctx) const override { return ctx.arg.wordsize; }
void writeTo(Ctx &, uint8_t *buf) override {}
};
@@ -1236,7 +1240,7 @@ class ARMExidxSyntheticSection : public SyntheticSection {
// section needs to be removed from the main input section list.
bool addSection(InputSection *isec);
- size_t getSize() const override { return size; }
+ size_t getSize(Ctx &ctx) const override { return size; }
void writeTo(Ctx &, uint8_t *buf) override;
bool isNeeded() const override;
// Sort and remove duplicate entries.
@@ -1284,7 +1288,7 @@ class ThunkSection final : public SyntheticSection {
// Thunk defines a symbol in this InputSection that can be used as target
// of a relocation
void addThunk(Thunk *t);
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void writeTo(Ctx &, uint8_t *buf) override;
InputSection *getTargetInputSection() const;
bool assignOffsets();
@@ -1309,7 +1313,7 @@ class ArmCmseSGSection final : public SyntheticSection {
public:
ArmCmseSGSection();
bool isNeeded() const override { return !entries.empty(); }
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void writeTo(Ctx &, uint8_t *buf) override;
void addSGVeneer(Symbol *sym, Symbol *ext_sym);
void addMappingSymbol();
@@ -1328,7 +1332,7 @@ class ArmCmseSGSection final : public SyntheticSection {
class PPC32Got2Section final : public SyntheticSection {
public:
PPC32Got2Section();
- size_t getSize() const override { return 0; }
+ size_t getSize(Ctx &ctx) const override { return 0; }
bool isNeeded() const override;
void finalizeContents(Ctx &) override;
void writeTo(Ctx &, uint8_t *buf) override {}
@@ -1344,7 +1348,7 @@ class PPC64LongBranchTargetSection final : public SyntheticSection {
PPC64LongBranchTargetSection();
uint64_t getEntryVA(const Symbol *sym, int64_t addend);
std::optional<uint32_t> addEntry(const Symbol *sym, int64_t addend);
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void writeTo(Ctx &, uint8_t *buf) override;
bool isNeeded() const override;
void finalizeContents(Ctx &) override { finalized = true; }
@@ -1359,7 +1363,7 @@ template <typename ELFT>
class PartitionElfHeaderSection final : public SyntheticSection {
public:
PartitionElfHeaderSection();
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void writeTo(Ctx &, uint8_t *buf) override;
};
@@ -1367,14 +1371,14 @@ template <typename ELFT>
class PartitionProgramHeadersSection final : public SyntheticSection {
public:
PartitionProgramHeadersSection();
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void writeTo(Ctx &, uint8_t *buf) override;
};
class PartitionIndexSection final : public SyntheticSection {
public:
PartitionIndexSection();
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
void finalizeContents(Ctx &) override;
void writeTo(Ctx &, uint8_t *buf) override;
};
@@ -1388,7 +1392,7 @@ class MemtagAndroidNote final : public SyntheticSection {
: SyntheticSection(llvm::ELF::SHF_ALLOC, llvm::ELF::SHT_NOTE,
/*alignment=*/4, ".note.android.memtag") {}
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
};
class PackageMetadataNote final : public SyntheticSection {
@@ -1397,7 +1401,7 @@ class PackageMetadataNote final : public SyntheticSection {
: SyntheticSection(llvm::ELF::SHF_ALLOC, llvm::ELF::SHT_NOTE,
/*alignment=*/4, ".note.package") {}
void writeTo(Ctx &, uint8_t *buf) override;
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
};
class MemtagGlobalDescriptors final : public SyntheticSection {
@@ -1411,7 +1415,7 @@ class MemtagGlobalDescriptors final : public SyntheticSection {
// synthetized, because the section's contents contain a sorted
// varint-compressed list of pointers to global variables. We only know the
// final size after `finalizeAddressDependentContent()`.
- size_t getSize() const override;
+ size_t getSize(Ctx &) const override;
bool updateAllocSize() override;
void addSymbol(const Symbol &sym) {
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index f909e026a91ffc..c413ebd349e6d3 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -840,7 +840,7 @@ template <class ELFT> void Writer<ELFT>::setReservedSymbolSections() {
if (ctx.sym.relaIpltStart && ctx.mainPart->relaDyn->isNeeded()) {
ctx.sym.relaIpltStart->section = ctx.mainPart->relaDyn.get();
ctx.sym.relaIpltEnd->section = ctx.mainPart->relaDyn.get();
- ctx.sym.relaIpltEnd->value = ctx.mainPart->relaDyn->getSize();
+ ctx.sym.relaIpltEnd->value = ctx.mainPart->relaDyn->getSize(ctx);
}
PhdrEntry *last = nullptr;
@@ -2574,8 +2574,8 @@ template <class ELFT> void Writer<ELFT>::setPhdrs(Partition &part) {
// output section. We always want to describe just the
// SyntheticSection.
if (part.armExidx && p->p_type == PT_ARM_EXIDX) {
- p->p_filesz = part.armExidx->getSize();
- p->p_memsz = part.armExidx->getSize();
+ p->p_filesz = part.armExidx->getSize(ctx);
+ p->p_memsz = p->p_filesz;
p->p_offset = first->offset + part.armExidx->outSecOff;
p->p_vaddr = first->addr + part.armExidx->outSecOff;
p->p_align = part.armExidx->addralign;
More information about the llvm-commits
mailing list