Skip to content

Commit c0e4b1d

Browse files
MaskRayDanielCChen
authored andcommitted
[ELF] Pass Ctx & to SyntheticSections
1 parent b1a0ec3 commit c0e4b1d

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

lld/ELF/InputSection.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,12 @@ static_assert(sizeof(InputSection) <= 160, "InputSection is too big");
472472

473473
class SyntheticSection : public InputSection {
474474
public:
475+
Ctx &ctx;
475476
SyntheticSection(Ctx &ctx, uint64_t flags, uint32_t type, uint32_t addralign,
476477
StringRef name)
477478
: InputSection(ctx.internalFile, flags, type, addralign, {}, name,
478-
InputSectionBase::Synthetic) {}
479+
InputSectionBase::Synthetic),
480+
ctx(ctx) {}
479481

480482
virtual ~SyntheticSection() = default;
481483
virtual size_t getSize(Ctx &) const = 0;

lld/ELF/SyntheticSections.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ using llvm::support::endian::write64le;
5959

6060
constexpr size_t MergeNoTailSection::numShards;
6161

62-
static uint64_t readUint(uint8_t *buf) {
62+
static uint64_t readUint(Ctx &ctx, uint8_t *buf) {
6363
return ctx.arg.is64 ? read64(buf) : read32(buf);
6464
}
6565

@@ -267,7 +267,7 @@ MipsReginfoSection<ELFT>::create(Ctx &ctx) {
267267
return std::make_unique<MipsReginfoSection<ELFT>>(ctx, reginfo);
268268
}
269269

270-
InputSection *elf::createInterpSection() {
270+
InputSection *elf::createInterpSection(Ctx &) {
271271
// StringSaver guarantees that the returned string ends with '\0'.
272272
StringRef s = saver().save(ctx.arg.dynamicLinker);
273273
ArrayRef<uint8_t> contents = {(const uint8_t *)s.data(), s.size() + 1};
@@ -609,7 +609,7 @@ static uint64_t readFdeAddr(uint8_t *buf, int size) {
609609
case DW_EH_PE_sdata8:
610610
return read64(buf);
611611
case DW_EH_PE_absptr:
612-
return readUint(buf);
612+
return readUint(ctx, buf);
613613
}
614614
fatal("unknown FDE size encoding");
615615
}
@@ -1452,15 +1452,17 @@ DynamicSection<ELFT>::computeContents() {
14521452
addInSec(DT_PLTGOT, *ctx.in.plt);
14531453
break;
14541454
case EM_AARCH64:
1455-
if (llvm::find_if(ctx.in.relaPlt->relocs, [](const DynamicReloc &r) {
1455+
if (llvm::find_if(ctx.in.relaPlt->relocs, [&ctx = ctx](
1456+
const DynamicReloc &r) {
14561457
return r.type == ctx.target->pltRel &&
14571458
r.sym->stOther & STO_AARCH64_VARIANT_PCS;
14581459
}) != ctx.in.relaPlt->relocs.end())
14591460
addInt(DT_AARCH64_VARIANT_PCS, 0);
14601461
addInSec(DT_PLTGOT, *ctx.in.gotPlt);
14611462
break;
14621463
case EM_RISCV:
1463-
if (llvm::any_of(ctx.in.relaPlt->relocs, [](const DynamicReloc &r) {
1464+
if (llvm::any_of(ctx.in.relaPlt->relocs, [&ctx = ctx](
1465+
const DynamicReloc &r) {
14641466
return r.type == ctx.target->pltRel &&
14651467
(r.sym->stOther & STO_RISCV_VARIANT_CC);
14661468
}))
@@ -2441,7 +2443,7 @@ void GnuHashTableSection::writeTo(Ctx &ctx, uint8_t *buf) {
24412443
// When C = 64, we choose a word with bits [6:...] and set 1 to two bits in
24422444
// the word using bits [0:5] and [26:31].
24432445
size_t i = (sym.hash / c) & (maskWords - 1);
2444-
uint64_t val = readUint(buf + i * ctx.arg.wordsize);
2446+
uint64_t val = readUint(ctx, buf + i * ctx.arg.wordsize);
24452447
val |= uint64_t(1) << (sym.hash % c);
24462448
val |= uint64_t(1) << ((sym.hash >> Shift2) % c);
24472449
writeUint(buf + i * ctx.arg.wordsize, val);
@@ -3513,7 +3515,7 @@ createSymbols(
35133515

35143516
// Returns a newly-created .gdb_index section.
35153517
template <class ELFT>
3516-
std::unique_ptr<GdbIndexSection> GdbIndexSection::create(Ctx &) {
3518+
std::unique_ptr<GdbIndexSection> GdbIndexSection::create(Ctx &ctx) {
35173519
llvm::TimeTraceScope timeScope("Create gdb index");
35183520

35193521
// Collect InputFiles with .debug_info. See the comment in
@@ -4684,7 +4686,7 @@ template <class ELFT> void elf::createSyntheticSections(Ctx &ctx) {
46844686
// SyntheticSections coming last.
46854687
if (needsInterpSection(ctx)) {
46864688
for (size_t i = 1; i <= ctx.partitions.size(); ++i) {
4687-
InputSection *sec = createInterpSection();
4689+
InputSection *sec = createInterpSection(ctx);
46884690
sec->partition = i;
46894691
ctx.inputSections.push_back(sec);
46904692
}

lld/ELF/SyntheticSections.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ class RelocationBaseSection : public SyntheticSection {
554554
(d->type == llvm::ELF::SHT_RELA || d->type == llvm::ELF::SHT_REL ||
555555
d->type == llvm::ELF::SHT_RELR ||
556556
(d->type == llvm::ELF::SHT_AARCH64_AUTH_RELR &&
557-
ctx.arg.emachine == llvm::ELF::EM_AARCH64));
557+
elf::ctx.arg.emachine == llvm::ELF::EM_AARCH64));
558558
}
559559
int32_t dynamicTag, sizeDynamicTag;
560560
SmallVector<DynamicReloc, 0> relocs;
@@ -1433,7 +1433,7 @@ class MemtagGlobalDescriptors final : public SyntheticSection {
14331433
};
14341434

14351435
template <class ELFT> void createSyntheticSections(Ctx &);
1436-
InputSection *createInterpSection();
1436+
InputSection *createInterpSection(Ctx &);
14371437
MergeInputSection *createCommentSection();
14381438
template <class ELFT> void splitSections(Ctx &);
14391439
void combineEhSections(Ctx &);

0 commit comments

Comments
 (0)