diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 81f79266254d..af9fc98e8e86 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -3147,7 +3147,7 @@ template void LinkerDriver::link(opt::InputArgList &args) { splitSections(); // Garbage collection and removal of shared symbols from unused shared objects. - markLive(); + markLive(ctx); // Make copies of any input sections that need to be copied into each // partition. diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index b9a4e392a507..23e235949137 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -44,7 +44,7 @@ using namespace lld::elf; namespace { template class MarkLive { public: - MarkLive(unsigned partition) : partition(partition) {} + MarkLive(Ctx &ctx, unsigned partition) : ctx(ctx), partition(partition) {} void run(); void moveToMain(); @@ -60,6 +60,7 @@ private: template void scanEhFrameSection(EhInputSection &eh, ArrayRef rels); + Ctx &ctx; // The index of the partition that we are currently processing. unsigned partition; @@ -73,21 +74,21 @@ private: } // namespace template -static uint64_t getAddend(InputSectionBase &sec, +static uint64_t getAddend(Ctx &ctx, InputSectionBase &sec, const typename ELFT::Rel &rel) { return ctx.target->getImplicitAddend(sec.content().begin() + rel.r_offset, rel.getType(ctx.arg.isMips64EL)); } template -static uint64_t getAddend(InputSectionBase &sec, +static uint64_t getAddend(Ctx &, InputSectionBase &sec, const typename ELFT::Rela &rel) { return rel.r_addend; } // Currently, we assume all input CREL relocations have an explicit addend. template -static uint64_t getAddend(InputSectionBase &sec, +static uint64_t getAddend(Ctx &, InputSectionBase &sec, const typename ELFT::Crel &rel) { return rel.r_addend; } @@ -107,7 +108,7 @@ void MarkLive::resolveReloc(InputSectionBase &sec, RelTy &rel, uint64_t offset = d->value; if (d->isSection()) - offset += getAddend(sec, rel); + offset += getAddend(ctx, sec, rel); // fromFDE being true means this is referenced by a FDE in a .eh_frame // piece. The relocation points to the described function or to a LSDA. We @@ -361,7 +362,7 @@ template void MarkLive::moveToMain() { // Before calling this function, Live bits are off for all // input sections. This function make some or all of them on // so that they are emitted to the output file. -template void elf::markLive() { +template void elf::markLive(Ctx &ctx) { llvm::TimeTraceScope timeScope("markLive"); // If --gc-sections is not given, retain all input sections. if (!ctx.arg.gcSections) { @@ -378,13 +379,13 @@ template void elf::markLive() { // Follow the graph to mark all live sections. for (unsigned i = 1, e = ctx.partitions.size(); i <= e; ++i) - MarkLive(i).run(); + MarkLive(ctx, i).run(); // If we have multiple partitions, some sections need to live in the main // partition even if they were allocated to a loadable partition. Move them // there now. if (ctx.partitions.size() != 1) - MarkLive(1).moveToMain(); + MarkLive(ctx, 1).moveToMain(); // Report garbage-collected sections. if (ctx.arg.printGcSections) @@ -393,7 +394,7 @@ template void elf::markLive() { message("removing unused section " + toString(sec)); } -template void elf::markLive(); -template void elf::markLive(); -template void elf::markLive(); -template void elf::markLive(); +template void elf::markLive(Ctx &); +template void elf::markLive(Ctx &); +template void elf::markLive(Ctx &); +template void elf::markLive(Ctx &); diff --git a/lld/ELF/MarkLive.h b/lld/ELF/MarkLive.h index ef62fdf964e4..a614646e25c9 100644 --- a/lld/ELF/MarkLive.h +++ b/lld/ELF/MarkLive.h @@ -10,9 +10,9 @@ #define LLD_ELF_MARKLIVE_H namespace lld::elf { +struct Ctx; -template void markLive(); - +template void markLive(Ctx &); } #endif // LLD_ELF_MARKLIVE_H