Skip to content

Commit 7a5b9ef

Browse files
committed
[ELF] Pass Ctx & to SyntheticSection::writeTo
1 parent 1f391a7 commit 7a5b9ef

File tree

10 files changed

+113
-105
lines changed

10 files changed

+113
-105
lines changed

lld/ELF/AArch64ErrataFix.cpp

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

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

379379
size_t getSize() const override { return 8; }
380380

@@ -407,7 +407,7 @@ uint64_t Patch843419Section::getLDSTAddr() const {
407407
return patchee->getVA(patcheeOffset);
408408
}
409409

410-
void Patch843419Section::writeTo(uint8_t *buf) {
410+
void Patch843419Section::writeTo(Ctx &ctx, 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class elf::Patch657417Section final : public SyntheticSection {
7272
public:
7373
Patch657417Section(InputSection *p, uint64_t off, uint32_t instr, bool isARM);
7474

75-
void writeTo(uint8_t *buf) override;
75+
void writeTo(Ctx &, uint8_t *buf) override;
7676

7777
size_t getSize() const override { return 4; }
7878

@@ -174,7 +174,7 @@ static uint64_t getThumbDestAddr(uint64_t sourceAddr, uint32_t instr) {
174174
return sourceAddr + offset + 4;
175175
}
176176

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

lld/ELF/Arch/ARM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ void ArmCmseSGSection::addSGVeneer(Symbol *acleSeSym, Symbol *sym) {
13801380
sgVeneers.emplace_back(ss);
13811381
}
13821382

1383-
void ArmCmseSGSection::writeTo(uint8_t *buf) {
1383+
void ArmCmseSGSection::writeTo(Ctx &ctx, uint8_t *buf) {
13841384
for (ArmCmseSGVeneer *s : sgVeneers) {
13851385
uint8_t *p = buf + s->offset;
13861386
write16(p + 0, 0xe97f); // SG
@@ -1525,7 +1525,7 @@ template <typename ELFT> void elf::writeARMCmseImportLib() {
15251525
{
15261526
parallel::TaskGroup tg;
15271527
for (auto &[osec, _] : osIsPairs)
1528-
osec->template writeTo<ELFT>(buf + osec->offset, tg);
1528+
osec->template writeTo<ELFT>(ctx, buf + osec->offset, tg);
15291529
}
15301530

15311531
if (auto e = buffer->commit())

lld/ELF/Arch/RISCV.cpp

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

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

10531053
static constexpr StringRef vendor = "riscv";
10541054
DenseMap<unsigned, unsigned> intAttr;
@@ -1276,7 +1276,7 @@ mergeAttributesSection(const SmallVector<InputSectionBase *, 0> &sections) {
12761276
return &merged;
12771277
}
12781278

1279-
void RISCVAttributesSection::writeTo(uint8_t *buf) {
1279+
void RISCVAttributesSection::writeTo(Ctx &ctx, uint8_t *buf) {
12801280
const size_t size = getSize();
12811281
uint8_t *const end = buf + size;
12821282
*buf = ELFAttrs::Format_Version;

lld/ELF/InputSection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class SyntheticSection : public InputSection {
484484
// thunks are added, update the section size.
485485
virtual bool isNeeded() const { return true; }
486486
virtual void finalizeContents(Ctx &) {}
487-
virtual void writeTo(uint8_t *buf) = 0;
487+
virtual void writeTo(Ctx &, uint8_t *buf) = 0;
488488

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

lld/ELF/OutputSections.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ template <class ELFT> void OutputSection::maybeCompress(Ctx &ctx) {
368368
// Write uncompressed data to a temporary zero-initialized buffer.
369369
{
370370
parallel::TaskGroup tg;
371-
writeTo<ELFT>(buf.get(), tg);
371+
writeTo<ELFT>(ctx, buf.get(), tg);
372372
}
373373
// The generic ABI specifies "The sh_size and sh_addralign fields of the
374374
// section header for a compressed section reflect the requirements of the
@@ -469,7 +469,7 @@ static void writeInt(uint8_t *buf, uint64_t data, uint64_t size) {
469469
}
470470

471471
template <class ELFT>
472-
void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
472+
void OutputSection::writeTo(Ctx &ctx, uint8_t *buf, parallel::TaskGroup &tg) {
473473
llvm::TimeTraceScope timeScope("Write sections", name);
474474
if (type == SHT_NOBITS)
475475
return;
@@ -519,12 +519,12 @@ void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
519519
return;
520520
}
521521

522-
auto fn = [=](size_t begin, size_t end) {
522+
auto fn = [=, &ctx](size_t begin, size_t end) {
523523
size_t numSections = sections.size();
524524
for (size_t i = begin; i != end; ++i) {
525525
InputSection *isec = sections[i];
526526
if (auto *s = dyn_cast<SyntheticSection>(isec))
527-
s->writeTo(buf + isec->outSecOff);
527+
s->writeTo(ctx, buf + isec->outSecOff);
528528
else
529529
isec->writeTo<ELFT>(buf + isec->outSecOff);
530530

@@ -911,13 +911,13 @@ template void OutputSection::writeHeaderTo<ELF32BE>(ELF32BE::Shdr *Shdr);
911911
template void OutputSection::writeHeaderTo<ELF64LE>(ELF64LE::Shdr *Shdr);
912912
template void OutputSection::writeHeaderTo<ELF64BE>(ELF64BE::Shdr *Shdr);
913913

914-
template void OutputSection::writeTo<ELF32LE>(uint8_t *,
914+
template void OutputSection::writeTo<ELF32LE>(Ctx &, uint8_t *,
915915
llvm::parallel::TaskGroup &);
916-
template void OutputSection::writeTo<ELF32BE>(uint8_t *,
916+
template void OutputSection::writeTo<ELF32BE>(Ctx &, uint8_t *,
917917
llvm::parallel::TaskGroup &);
918-
template void OutputSection::writeTo<ELF64LE>(uint8_t *,
918+
template void OutputSection::writeTo<ELF64LE>(Ctx &, uint8_t *,
919919
llvm::parallel::TaskGroup &);
920-
template void OutputSection::writeTo<ELF64BE>(uint8_t *,
920+
template void OutputSection::writeTo<ELF64BE>(Ctx &, uint8_t *,
921921
llvm::parallel::TaskGroup &);
922922

923923
template void OutputSection::maybeCompress<ELF32LE>(Ctx &);

lld/ELF/OutputSections.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class OutputSection final : public SectionBase {
114114
template <bool is64> void finalizeNonAllocCrel(Ctx &);
115115
void finalize(Ctx &);
116116
template <class ELFT>
117-
void writeTo(uint8_t *buf, llvm::parallel::TaskGroup &tg);
117+
void writeTo(Ctx &, uint8_t *buf, llvm::parallel::TaskGroup &tg);
118118
// Check that the addends for dynamic relocations were written correctly.
119119
void checkDynRelAddends(Ctx &);
120120
template <class ELFT> void maybeCompress(Ctx &);

0 commit comments

Comments
 (0)