Skip to content

Commit 81bd712

Browse files
committed
[ELF] Revert Ctx & parameters from SyntheticSection
Since Ctx &ctx is a member variable, 1f391a7 7a5b9ef e2f0ec3 can be reverted.
1 parent d656b20 commit 81bd712

12 files changed

+283
-301
lines changed

lld/ELF/AArch64ErrataFix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ class elf::Patch843419Section final : public SyntheticSection {
374374
public:
375375
Patch843419Section(Ctx &, InputSection *p, uint64_t off);
376376

377-
void writeTo(Ctx &, uint8_t *buf) override;
377+
void writeTo(uint8_t *buf) override;
378378

379-
size_t getSize(Ctx &) const override { return 8; }
379+
size_t getSize() const override { return 8; }
380380

381381
uint64_t getLDSTAddr() const;
382382

@@ -399,15 +399,15 @@ Patch843419Section::Patch843419Section(Ctx &ctx, InputSection *p, uint64_t off)
399399
this->parent = p->getParent();
400400
patchSym = addSyntheticLocal(
401401
saver().save("__CortexA53843419_" + utohexstr(getLDSTAddr())), STT_FUNC,
402-
0, getSize(ctx), *this);
402+
0, getSize(), *this);
403403
addSyntheticLocal(saver().save("$x"), STT_NOTYPE, 0, 0, *this);
404404
}
405405

406406
uint64_t Patch843419Section::getLDSTAddr() const {
407407
return patchee->getVA(patcheeOffset);
408408
}
409409

410-
void Patch843419Section::writeTo(Ctx &ctx, uint8_t *buf) {
410+
void Patch843419Section::writeTo(uint8_t *buf) {
411411
// Copy the instruction that we will be replacing with a branch in the
412412
// patchee Section.
413413
write32le(buf, read32le(patchee->content().begin() + patcheeOffset));

lld/ELF/ARMErrataFix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ class elf::Patch657417Section final : public SyntheticSection {
7373
Patch657417Section(Ctx &, InputSection *p, uint64_t off, uint32_t instr,
7474
bool isARM);
7575

76-
void writeTo(Ctx &, uint8_t *buf) override;
76+
void writeTo(uint8_t *buf) override;
7777

78-
size_t getSize(Ctx &) const override { return 4; }
78+
size_t getSize() const override { return 4; }
7979

8080
// Get the virtual address of the branch instruction at patcheeOffset.
8181
uint64_t getBranchAddr() const;
@@ -142,7 +142,7 @@ Patch657417Section::Patch657417Section(Ctx &ctx, InputSection *p, uint64_t off,
142142
parent = p->getParent();
143143
patchSym = addSyntheticLocal(
144144
saver().save("__CortexA8657417_" + utohexstr(getBranchAddr())), STT_FUNC,
145-
isARM ? 0 : 1, getSize(ctx), *this);
145+
isARM ? 0 : 1, getSize(), *this);
146146
addSyntheticLocal(saver().save(isARM ? "$a" : "$t"), STT_NOTYPE, 0, 0, *this);
147147
}
148148

@@ -176,7 +176,7 @@ static uint64_t getThumbDestAddr(Ctx &ctx, uint64_t sourceAddr,
176176
return sourceAddr + offset + 4;
177177
}
178178

179-
void Patch657417Section::writeTo(Ctx &ctx, uint8_t *buf) {
179+
void Patch657417Section::writeTo(uint8_t *buf) {
180180
// The base instruction of the patch is always a 32-bit unconditional branch.
181181
if (isARM)
182182
write32le(buf, 0xea000000);

lld/ELF/Arch/ARM.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,7 @@ class elf::ArmCmseSGVeneer {
13331333
ArmCmseSGSection::ArmCmseSGSection(Ctx &ctx)
13341334
: SyntheticSection(ctx, llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
13351335
llvm::ELF::SHT_PROGBITS,
1336-
/*alignment=*/32, ".gnu.sgstubs"),
1337-
ctx(ctx) {
1336+
/*alignment=*/32, ".gnu.sgstubs") {
13381337
entsize = ACLESESYM_SIZE;
13391338
// The range of addresses used in the CMSE import library should be fixed.
13401339
for (auto &[_, sym] : ctx.symtab->cmseImportLib) {
@@ -1384,7 +1383,7 @@ void ArmCmseSGSection::addSGVeneer(Symbol *acleSeSym, Symbol *sym) {
13841383
sgVeneers.emplace_back(ss);
13851384
}
13861385

1387-
void ArmCmseSGSection::writeTo(Ctx &ctx, uint8_t *buf) {
1386+
void ArmCmseSGSection::writeTo(uint8_t *buf) {
13881387
for (ArmCmseSGVeneer *s : sgVeneers) {
13891388
uint8_t *p = buf + s->offset;
13901389
write16(p + 0, 0xe97f); // SG
@@ -1401,14 +1400,14 @@ void ArmCmseSGSection::addMappingSymbol() {
14011400
addSyntheticLocal("$t", STT_NOTYPE, /*off=*/0, /*size=*/0, *this);
14021401
}
14031402

1404-
size_t ArmCmseSGSection::getSize(Ctx &) const {
1403+
size_t ArmCmseSGSection::getSize() const {
14051404
if (sgVeneers.empty())
14061405
return (impLibMaxAddr ? impLibMaxAddr - getVA() : 0) + newEntries * entsize;
14071406

14081407
return entries.size() * entsize;
14091408
}
14101409

1411-
void ArmCmseSGSection::finalizeContents(Ctx &) {
1410+
void ArmCmseSGSection::finalizeContents() {
14121411
if (sgVeneers.empty())
14131412
return;
14141413

@@ -1476,8 +1475,8 @@ template <typename ELFT> void elf::writeARMCmseImportLib(Ctx &ctx) {
14761475
osec->recordSection(isec);
14771476
osec->finalizeInputSections(ctx);
14781477
osec->shName = shstrtab->addString(osec->name);
1479-
osec->size = isec->getSize(ctx);
1480-
isec->finalizeContents(ctx);
1478+
osec->size = isec->getSize();
1479+
isec->finalizeContents();
14811480
osec->offset = alignToPowerOf2(off, osec->addralign);
14821481
off = osec->offset + osec->size;
14831482
}

lld/ELF/Arch/RISCV.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,8 @@ class RISCVAttributesSection final : public SyntheticSection {
10481048
: SyntheticSection(ctx, 0, SHT_RISCV_ATTRIBUTES, 1, ".riscv.attributes") {
10491049
}
10501050

1051-
size_t getSize(Ctx &) const override { return size; }
1052-
void writeTo(Ctx &, uint8_t *buf) override;
1051+
size_t getSize() const override { return size; }
1052+
void writeTo(uint8_t *buf) override;
10531053

10541054
static constexpr StringRef vendor = "riscv";
10551055
DenseMap<unsigned, unsigned> intAttr;
@@ -1278,8 +1278,8 @@ mergeAttributesSection(Ctx &ctx,
12781278
return &merged;
12791279
}
12801280

1281-
void RISCVAttributesSection::writeTo(Ctx &ctx, uint8_t *buf) {
1282-
const size_t size = getSize(ctx);
1281+
void RISCVAttributesSection::writeTo(uint8_t *buf) {
1282+
const size_t size = getSize();
12831283
uint8_t *const end = buf + size;
12841284
*buf = ELFAttrs::Format_Version;
12851285
write32(buf + 1, size - 1);

lld/ELF/InputSection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
101101

102102
size_t InputSectionBase::getSize() const {
103103
if (auto *s = dyn_cast<SyntheticSection>(this))
104-
return s->getSize(ctx);
104+
return s->getSize();
105105
return size - bytesDropped;
106106
}
107107

lld/ELF/InputSection.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,13 @@ class SyntheticSection : public InputSection {
480480
ctx(ctx) {}
481481

482482
virtual ~SyntheticSection() = default;
483-
virtual size_t getSize(Ctx &) const = 0;
483+
virtual size_t getSize() const = 0;
484484
virtual bool updateAllocSize(Ctx &) { return false; }
485485
// If the section has the SHF_ALLOC flag and the size may be changed if
486486
// thunks are added, update the section size.
487-
virtual bool isNeeded(Ctx &) const { return true; }
488-
virtual void finalizeContents(Ctx &) {}
489-
virtual void writeTo(Ctx &, uint8_t *buf) = 0;
487+
virtual bool isNeeded() const { return true; }
488+
virtual void finalizeContents() {}
489+
virtual void writeTo(uint8_t *buf) = 0;
490490

491491
static bool classof(const SectionBase *sec) {
492492
return sec->kind() == InputSectionBase::Synthetic;

lld/ELF/LinkerScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ void LinkerScript::diagnoseOrphanHandling() const {
10581058
}
10591059

10601060
void LinkerScript::diagnoseMissingSGSectionAddress() const {
1061-
if (!ctx.arg.cmseImplib || !ctx.in.armCmseSGSection->isNeeded(ctx))
1061+
if (!ctx.arg.cmseImplib || !ctx.in.armCmseSGSection->isNeeded())
10621062
return;
10631063

10641064
OutputSection *sec = findByName(sectionCommands, ".gnu.sgstubs");

lld/ELF/OutputSections.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void OutputSection::finalizeInputSections(Ctx &ctx) {
248248
commitSection(ctx, s);
249249
}
250250
for (auto *ms : mergeSections)
251-
ms->finalizeContents(ctx);
251+
ms->finalizeContents();
252252
}
253253

254254
static void sortByOrder(MutableArrayRef<InputSection *> in,
@@ -525,7 +525,7 @@ void OutputSection::writeTo(Ctx &ctx, uint8_t *buf, parallel::TaskGroup &tg) {
525525
for (size_t i = begin; i != end; ++i) {
526526
InputSection *isec = sections[i];
527527
if (auto *s = dyn_cast<SyntheticSection>(isec))
528-
s->writeTo(ctx, buf + isec->outSecOff);
528+
s->writeTo(buf + isec->outSecOff);
529529
else
530530
isec->writeTo<ELFT>(buf + isec->outSecOff);
531531

lld/ELF/Relocations.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,15 +2020,14 @@ static void forEachInputSectionDescription(
20202020
// This may invalidate any output section offsets stored outside of InputSection
20212021
void ThunkCreator::mergeThunks(ArrayRef<OutputSection *> outputSections) {
20222022
forEachInputSectionDescription(
2023-
outputSections,
2024-
[&, &ctx = ctx](OutputSection *os, InputSectionDescription *isd) {
2023+
outputSections, [&](OutputSection *os, InputSectionDescription *isd) {
20252024
if (isd->thunkSections.empty())
20262025
return;
20272026

20282027
// Remove any zero sized precreated Thunks.
20292028
llvm::erase_if(isd->thunkSections,
2030-
[&ctx](const std::pair<ThunkSection *, uint32_t> &ts) {
2031-
return ts.first->getSize(ctx) == 0;
2029+
[](const std::pair<ThunkSection *, uint32_t> &ts) {
2030+
return ts.first->getSize() == 0;
20322031
});
20332032

20342033
// ISD->ThunkSections contains all created ThunkSections, including
@@ -2081,7 +2080,7 @@ ThunkSection *ThunkCreator::getISDThunkSec(OutputSection *os,
20812080
for (std::pair<ThunkSection *, uint32_t> tp : isd->thunkSections) {
20822081
ThunkSection *ts = tp.first;
20832082
uint64_t tsBase = os->addr + ts->outSecOff - pcBias;
2084-
uint64_t tsLimit = tsBase + ts->getSize(ctx);
2083+
uint64_t tsLimit = tsBase + ts->getSize();
20852084
if (ctx.target->inBranchRange(rel.type, src,
20862085
(src > tsLimit) ? tsBase : tsLimit))
20872086
return ts;

0 commit comments

Comments
 (0)