Skip to content

Commit 5c33424

Browse files
committed
[ELF] Pass Ctx & to MarkLive
1 parent 04e69ad commit 5c33424

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
31473147
splitSections<ELFT>();
31483148

31493149
// Garbage collection and removal of shared symbols from unused shared objects.
3150-
markLive<ELFT>();
3150+
markLive<ELFT>(ctx);
31513151

31523152
// Make copies of any input sections that need to be copied into each
31533153
// partition.

lld/ELF/MarkLive.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using namespace lld::elf;
4444
namespace {
4545
template <class ELFT> class MarkLive {
4646
public:
47-
MarkLive(unsigned partition) : partition(partition) {}
47+
MarkLive(Ctx &ctx, unsigned partition) : ctx(ctx), partition(partition) {}
4848

4949
void run();
5050
void moveToMain();
@@ -60,6 +60,7 @@ template <class ELFT> class MarkLive {
6060
template <class RelTy>
6161
void scanEhFrameSection(EhInputSection &eh, ArrayRef<RelTy> rels);
6262

63+
Ctx &ctx;
6364
// The index of the partition that we are currently processing.
6465
unsigned partition;
6566

@@ -73,21 +74,21 @@ template <class ELFT> class MarkLive {
7374
} // namespace
7475

7576
template <class ELFT>
76-
static uint64_t getAddend(InputSectionBase &sec,
77+
static uint64_t getAddend(Ctx &ctx, InputSectionBase &sec,
7778
const typename ELFT::Rel &rel) {
7879
return ctx.target->getImplicitAddend(sec.content().begin() + rel.r_offset,
7980
rel.getType(ctx.arg.isMips64EL));
8081
}
8182

8283
template <class ELFT>
83-
static uint64_t getAddend(InputSectionBase &sec,
84+
static uint64_t getAddend(Ctx &, InputSectionBase &sec,
8485
const typename ELFT::Rela &rel) {
8586
return rel.r_addend;
8687
}
8788

8889
// Currently, we assume all input CREL relocations have an explicit addend.
8990
template <class ELFT>
90-
static uint64_t getAddend(InputSectionBase &sec,
91+
static uint64_t getAddend(Ctx &, InputSectionBase &sec,
9192
const typename ELFT::Crel &rel) {
9293
return rel.r_addend;
9394
}
@@ -107,7 +108,7 @@ void MarkLive<ELFT>::resolveReloc(InputSectionBase &sec, RelTy &rel,
107108

108109
uint64_t offset = d->value;
109110
if (d->isSection())
110-
offset += getAddend<ELFT>(sec, rel);
111+
offset += getAddend<ELFT>(ctx, sec, rel);
111112

112113
// fromFDE being true means this is referenced by a FDE in a .eh_frame
113114
// piece. The relocation points to the described function or to a LSDA. We
@@ -361,7 +362,7 @@ template <class ELFT> void MarkLive<ELFT>::moveToMain() {
361362
// Before calling this function, Live bits are off for all
362363
// input sections. This function make some or all of them on
363364
// so that they are emitted to the output file.
364-
template <class ELFT> void elf::markLive() {
365+
template <class ELFT> void elf::markLive(Ctx &ctx) {
365366
llvm::TimeTraceScope timeScope("markLive");
366367
// If --gc-sections is not given, retain all input sections.
367368
if (!ctx.arg.gcSections) {
@@ -378,13 +379,13 @@ template <class ELFT> void elf::markLive() {
378379

379380
// Follow the graph to mark all live sections.
380381
for (unsigned i = 1, e = ctx.partitions.size(); i <= e; ++i)
381-
MarkLive<ELFT>(i).run();
382+
MarkLive<ELFT>(ctx, i).run();
382383

383384
// If we have multiple partitions, some sections need to live in the main
384385
// partition even if they were allocated to a loadable partition. Move them
385386
// there now.
386387
if (ctx.partitions.size() != 1)
387-
MarkLive<ELFT>(1).moveToMain();
388+
MarkLive<ELFT>(ctx, 1).moveToMain();
388389

389390
// Report garbage-collected sections.
390391
if (ctx.arg.printGcSections)
@@ -393,7 +394,7 @@ template <class ELFT> void elf::markLive() {
393394
message("removing unused section " + toString(sec));
394395
}
395396

396-
template void elf::markLive<ELF32LE>();
397-
template void elf::markLive<ELF32BE>();
398-
template void elf::markLive<ELF64LE>();
399-
template void elf::markLive<ELF64BE>();
397+
template void elf::markLive<ELF32LE>(Ctx &);
398+
template void elf::markLive<ELF32BE>(Ctx &);
399+
template void elf::markLive<ELF64LE>(Ctx &);
400+
template void elf::markLive<ELF64BE>(Ctx &);

lld/ELF/MarkLive.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define LLD_ELF_MARKLIVE_H
1111

1212
namespace lld::elf {
13+
struct Ctx;
1314

14-
template <class ELFT> void markLive();
15-
15+
template <class ELFT> void markLive(Ctx &);
1616
}
1717

1818
#endif // LLD_ELF_MARKLIVE_H

0 commit comments

Comments
 (0)