Skip to content

Commit

Permalink
[ELF] Pass Ctx & to SyntheticSection::writeTo
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Oct 4, 2024
1 parent 1f391a7 commit 7a5b9ef
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 105 deletions.
4 changes: 2 additions & 2 deletions lld/ELF/AArch64ErrataFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class elf::Patch843419Section final : public SyntheticSection {
public:
Patch843419Section(InputSection *p, uint64_t off);

void writeTo(uint8_t *buf) override;
void writeTo(Ctx &, uint8_t *buf) override;

size_t getSize() const override { return 8; }

Expand Down Expand Up @@ -407,7 +407,7 @@ uint64_t Patch843419Section::getLDSTAddr() const {
return patchee->getVA(patcheeOffset);
}

void Patch843419Section::writeTo(uint8_t *buf) {
void Patch843419Section::writeTo(Ctx &ctx, uint8_t *buf) {
// Copy the instruction that we will be replacing with a branch in the
// patchee Section.
write32le(buf, read32le(patchee->content().begin() + patcheeOffset));
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/ARMErrataFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class elf::Patch657417Section final : public SyntheticSection {
public:
Patch657417Section(InputSection *p, uint64_t off, uint32_t instr, bool isARM);

void writeTo(uint8_t *buf) override;
void writeTo(Ctx &, uint8_t *buf) override;

size_t getSize() const override { return 4; }

Expand Down Expand Up @@ -174,7 +174,7 @@ static uint64_t getThumbDestAddr(uint64_t sourceAddr, uint32_t instr) {
return sourceAddr + offset + 4;
}

void Patch657417Section::writeTo(uint8_t *buf) {
void Patch657417Section::writeTo(Ctx &ctx, uint8_t *buf) {
// The base instruction of the patch is always a 32-bit unconditional branch.
if (isARM)
write32le(buf, 0xea000000);
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/Arch/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ void ArmCmseSGSection::addSGVeneer(Symbol *acleSeSym, Symbol *sym) {
sgVeneers.emplace_back(ss);
}

void ArmCmseSGSection::writeTo(uint8_t *buf) {
void ArmCmseSGSection::writeTo(Ctx &ctx, uint8_t *buf) {
for (ArmCmseSGVeneer *s : sgVeneers) {
uint8_t *p = buf + s->offset;
write16(p + 0, 0xe97f); // SG
Expand Down Expand Up @@ -1525,7 +1525,7 @@ template <typename ELFT> void elf::writeARMCmseImportLib() {
{
parallel::TaskGroup tg;
for (auto &[osec, _] : osIsPairs)
osec->template writeTo<ELFT>(buf + osec->offset, tg);
osec->template writeTo<ELFT>(ctx, buf + osec->offset, tg);
}

if (auto e = buffer->commit())
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/Arch/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ class RISCVAttributesSection final : public SyntheticSection {
: SyntheticSection(0, SHT_RISCV_ATTRIBUTES, 1, ".riscv.attributes") {}

size_t getSize() const override { return size; }
void writeTo(uint8_t *buf) override;
void writeTo(Ctx &, uint8_t *buf) override;

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

void RISCVAttributesSection::writeTo(uint8_t *buf) {
void RISCVAttributesSection::writeTo(Ctx &ctx, uint8_t *buf) {
const size_t size = getSize();
uint8_t *const end = buf + size;
*buf = ELFAttrs::Format_Version;
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/InputSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ class SyntheticSection : public InputSection {
// thunks are added, update the section size.
virtual bool isNeeded() const { return true; }
virtual void finalizeContents(Ctx &) {}
virtual void writeTo(uint8_t *buf) = 0;
virtual void writeTo(Ctx &, uint8_t *buf) = 0;

static bool classof(const SectionBase *sec) {
return sec->kind() == InputSectionBase::Synthetic;
Expand Down
16 changes: 8 additions & 8 deletions lld/ELF/OutputSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ template <class ELFT> void OutputSection::maybeCompress(Ctx &ctx) {
// Write uncompressed data to a temporary zero-initialized buffer.
{
parallel::TaskGroup tg;
writeTo<ELFT>(buf.get(), tg);
writeTo<ELFT>(ctx, buf.get(), tg);
}
// The generic ABI specifies "The sh_size and sh_addralign fields of the
// section header for a compressed section reflect the requirements of the
Expand Down Expand Up @@ -469,7 +469,7 @@ static void writeInt(uint8_t *buf, uint64_t data, uint64_t size) {
}

template <class ELFT>
void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
void OutputSection::writeTo(Ctx &ctx, uint8_t *buf, parallel::TaskGroup &tg) {
llvm::TimeTraceScope timeScope("Write sections", name);
if (type == SHT_NOBITS)
return;
Expand Down Expand Up @@ -519,12 +519,12 @@ void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
return;
}

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

Expand Down Expand Up @@ -911,13 +911,13 @@ template void OutputSection::writeHeaderTo<ELF32BE>(ELF32BE::Shdr *Shdr);
template void OutputSection::writeHeaderTo<ELF64LE>(ELF64LE::Shdr *Shdr);
template void OutputSection::writeHeaderTo<ELF64BE>(ELF64BE::Shdr *Shdr);

template void OutputSection::writeTo<ELF32LE>(uint8_t *,
template void OutputSection::writeTo<ELF32LE>(Ctx &, uint8_t *,
llvm::parallel::TaskGroup &);
template void OutputSection::writeTo<ELF32BE>(uint8_t *,
template void OutputSection::writeTo<ELF32BE>(Ctx &, uint8_t *,
llvm::parallel::TaskGroup &);
template void OutputSection::writeTo<ELF64LE>(uint8_t *,
template void OutputSection::writeTo<ELF64LE>(Ctx &, uint8_t *,
llvm::parallel::TaskGroup &);
template void OutputSection::writeTo<ELF64BE>(uint8_t *,
template void OutputSection::writeTo<ELF64BE>(Ctx &, uint8_t *,
llvm::parallel::TaskGroup &);

template void OutputSection::maybeCompress<ELF32LE>(Ctx &);
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/OutputSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class OutputSection final : public SectionBase {
template <bool is64> void finalizeNonAllocCrel(Ctx &);
void finalize(Ctx &);
template <class ELFT>
void writeTo(uint8_t *buf, llvm::parallel::TaskGroup &tg);
void writeTo(Ctx &, uint8_t *buf, llvm::parallel::TaskGroup &tg);
// Check that the addends for dynamic relocations were written correctly.
void checkDynRelAddends(Ctx &);
template <class ELFT> void maybeCompress(Ctx &);
Expand Down
Loading

0 comments on commit 7a5b9ef

Please sign in to comment.