Skip to content

Commit 1f391a7

Browse files
committed
[ELF] Pass Ctx & to SyntheticSection::finalizeContents
1 parent e9b7a09 commit 1f391a7

File tree

6 files changed

+43
-43
lines changed

6 files changed

+43
-43
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ size_t ArmCmseSGSection::getSize() const {
14041404
return entries.size() * entsize;
14051405
}
14061406

1407-
void ArmCmseSGSection::finalizeContents() {
1407+
void ArmCmseSGSection::finalizeContents(Ctx &) {
14081408
if (sgVeneers.empty())
14091409
return;
14101410

@@ -1472,7 +1472,7 @@ template <typename ELFT> void elf::writeARMCmseImportLib() {
14721472
osec->finalizeInputSections(ctx);
14731473
osec->shName = shstrtab->addString(osec->name);
14741474
osec->size = isec->getSize();
1475-
isec->finalizeContents();
1475+
isec->finalizeContents(ctx);
14761476
osec->offset = alignToPowerOf2(off, osec->addralign);
14771477
off = osec->offset + osec->size;
14781478
}

lld/ELF/InputSection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class SyntheticSection : public InputSection {
483483
// If the section has the SHF_ALLOC flag and the size may be changed if
484484
// thunks are added, update the section size.
485485
virtual bool isNeeded() const { return true; }
486-
virtual void finalizeContents() {}
486+
virtual void finalizeContents(Ctx &) {}
487487
virtual void writeTo(uint8_t *buf) = 0;
488488

489489
static bool classof(const SectionBase *sec) {

lld/ELF/OutputSections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void OutputSection::finalizeInputSections(Ctx &ctx) {
247247
commitSection(ctx, s);
248248
}
249249
for (auto *ms : mergeSections)
250-
ms->finalizeContents();
250+
ms->finalizeContents(ctx);
251251
}
252252

253253
static void sortByOrder(MutableArrayRef<InputSection *> in,

lld/ELF/SyntheticSections.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static void writeCieFde(uint8_t *buf, ArrayRef<uint8_t> d) {
505505
write32(buf, d.size() - 4);
506506
}
507507

508-
void EhFrameSection::finalizeContents() {
508+
void EhFrameSection::finalizeContents(Ctx &) {
509509
assert(!this->size); // Not finalized.
510510

511511
switch (ctx.arg.ekind) {
@@ -700,7 +700,7 @@ uint64_t GotSection::getGlobalDynOffset(const Symbol &b) const {
700700
return b.getTlsGdIdx() * ctx.arg.wordsize;
701701
}
702702

703-
void GotSection::finalizeContents() {
703+
void GotSection::finalizeContents(Ctx &) {
704704
if (ctx.arg.emachine == EM_PPC64 &&
705705
numEntries <= ctx.target->gotHeaderEntriesNum &&
706706
!ctx.sym.globalOffsetTable)
@@ -869,7 +869,7 @@ bool MipsGotSection::tryMergeGots(FileGot &dst, FileGot &src, bool isPrimary) {
869869
return true;
870870
}
871871

872-
void MipsGotSection::finalizeContents() { updateAllocSize(); }
872+
void MipsGotSection::finalizeContents(Ctx &) { updateAllocSize(); }
873873

874874
bool MipsGotSection::updateAllocSize() {
875875
size = headerEntriesNum * ctx.arg.wordsize;
@@ -1574,7 +1574,7 @@ DynamicSection<ELFT>::computeContents() {
15741574
return entries;
15751575
}
15761576

1577-
template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
1577+
template <class ELFT> void DynamicSection<ELFT>::finalizeContents(Ctx &) {
15781578
if (OutputSection *sec = getPartition().dynStrTab->getParent())
15791579
getParent()->link = sec->sectionIndex;
15801580
this->size = computeContents().size() * this->entsize;
@@ -1675,7 +1675,7 @@ void RelocationBaseSection::partitionRels() {
16751675
relocs.begin();
16761676
}
16771677

1678-
void RelocationBaseSection::finalizeContents() {
1678+
void RelocationBaseSection::finalizeContents(Ctx &) {
16791679
SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
16801680

16811681
// When linking glibc statically, .rel{,a}.plt contains R_*_IRELATIVE
@@ -2127,7 +2127,7 @@ static bool sortMipsSymbols(const SymbolTableEntry &l,
21272127
return !l.sym->isInGot();
21282128
}
21292129

2130-
void SymbolTableBaseSection::finalizeContents() {
2130+
void SymbolTableBaseSection::finalizeContents(Ctx &) {
21312131
if (OutputSection *sec = strTabSec.getParent())
21322132
getParent()->link = sec->sectionIndex;
21332133

@@ -2351,7 +2351,7 @@ bool SymtabShndxSection::isNeeded() const {
23512351
return size >= SHN_LORESERVE;
23522352
}
23532353

2354-
void SymtabShndxSection::finalizeContents() {
2354+
void SymtabShndxSection::finalizeContents(Ctx &) {
23552355
getParent()->link = ctx.in.symTab->getParent()->sectionIndex;
23562356
}
23572357

@@ -2393,7 +2393,7 @@ GnuHashTableSection::GnuHashTableSection()
23932393
: SyntheticSection(SHF_ALLOC, SHT_GNU_HASH, ctx.arg.wordsize, ".gnu.hash") {
23942394
}
23952395

2396-
void GnuHashTableSection::finalizeContents() {
2396+
void GnuHashTableSection::finalizeContents(Ctx &) {
23972397
if (OutputSection *sec = getPartition().dynSymTab->getParent())
23982398
getParent()->link = sec->sectionIndex;
23992399

@@ -2503,7 +2503,7 @@ HashTableSection::HashTableSection()
25032503
this->entsize = 4;
25042504
}
25052505

2506-
void HashTableSection::finalizeContents() {
2506+
void HashTableSection::finalizeContents(Ctx &) {
25072507
SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
25082508

25092509
if (OutputSection *sec = symTab->getParent())
@@ -3217,7 +3217,7 @@ void DebugNamesSection<ELFT>::getNameRelocs(
32173217
}
32183218
}
32193219

3220-
template <class ELFT> void DebugNamesSection<ELFT>::finalizeContents() {
3220+
template <class ELFT> void DebugNamesSection<ELFT>::finalizeContents(Ctx &) {
32213221
// Get relocations of .debug_names sections.
32223222
auto relocs = std::make_unique<DenseMap<uint32_t, uint32_t>[]>(numChunks);
32233223
parallelFor(0, numChunks, [&](size_t i) {
@@ -3676,7 +3676,7 @@ StringRef VersionDefinitionSection::getFileDefName() {
36763676
return ctx.arg.outputFile;
36773677
}
36783678

3679-
void VersionDefinitionSection::finalizeContents() {
3679+
void VersionDefinitionSection::finalizeContents(Ctx &) {
36803680
fileDefNameOff = getPartition().dynStrTab->addString(getFileDefName());
36813681
for (const VersionDefinition &v : namedVersionDefs())
36823682
verDefNameOffs.push_back(getPartition().dynStrTab->addString(v.name));
@@ -3732,7 +3732,7 @@ VersionTableSection::VersionTableSection()
37323732
this->entsize = 2;
37333733
}
37343734

3735-
void VersionTableSection::finalizeContents() {
3735+
void VersionTableSection::finalizeContents(Ctx &) {
37363736
// At the moment of june 2016 GNU docs does not mention that sh_link field
37373737
// should be set, but Sun docs do. Also readelf relies on this field.
37383738
getParent()->link = getPartition().dynSymTab->getParent()->sectionIndex;
@@ -3781,7 +3781,7 @@ VersionNeedSection<ELFT>::VersionNeedSection()
37813781
: SyntheticSection(SHF_ALLOC, SHT_GNU_verneed, sizeof(uint32_t),
37823782
".gnu.version_r") {}
37833783

3784-
template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents() {
3784+
template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents(Ctx &) {
37853785
for (SharedFile *f : ctx.sharedFiles) {
37863786
if (f->vernauxs.empty())
37873787
continue;
@@ -3869,7 +3869,7 @@ size_t MergeTailSection::getSize() const { return builder.getSize(); }
38693869

38703870
void MergeTailSection::writeTo(uint8_t *buf) { builder.write(buf); }
38713871

3872-
void MergeTailSection::finalizeContents() {
3872+
void MergeTailSection::finalizeContents(Ctx &) {
38733873
// Add all string pieces to the string table builder to create section
38743874
// contents.
38753875
for (MergeInputSection *sec : sections)
@@ -3902,7 +3902,7 @@ void MergeNoTailSection::writeTo(uint8_t *buf) {
39023902
// value is different from T's. If that's the case, we can safely put S and
39033903
// T into different string builders without worrying about merge misses.
39043904
// We do it in parallel.
3905-
void MergeNoTailSection::finalizeContents() {
3905+
void MergeNoTailSection::finalizeContents(Ctx &) {
39063906
// Initializes string table builders.
39073907
for (size_t i = 0; i < numShards; ++i)
39083908
shards.emplace_back(StringTableBuilder::RAW, llvm::Align(addralign));
@@ -4084,7 +4084,7 @@ static bool isDuplicateArmExidxSec(InputSection *prev, InputSection *cur) {
40844084
// must be sorted in ascending order of address, Sentinel is set to the
40854085
// InputSection with the highest address and any InputSections that have
40864086
// mergeable .ARM.exidx table entries are removed from it.
4087-
void ARMExidxSyntheticSection::finalizeContents() {
4087+
void ARMExidxSyntheticSection::finalizeContents(Ctx &) {
40884088
// Ensure that any fixed-point iterations after the first see the original set
40894089
// of sections.
40904090
if (!originalExecutableSections.empty())
@@ -4271,7 +4271,7 @@ bool PPC32Got2Section::isNeeded() const {
42714271
return false;
42724272
}
42734273

4274-
void PPC32Got2Section::finalizeContents() {
4274+
void PPC32Got2Section::finalizeContents(Ctx &) {
42754275
// PPC32 may create multiple GOT sections for -fPIC/-fPIE, one per file in
42764276
// .got2 . This function computes outSecOff of each .got2 to be used in
42774277
// PPC32PltCallStub::writeTo(). The purpose of this empty synthetic section is
@@ -4441,7 +4441,7 @@ size_t PartitionIndexSection::getSize() const {
44414441
return 12 * (ctx.partitions.size() - 1);
44424442
}
44434443

4444-
void PartitionIndexSection::finalizeContents() {
4444+
void PartitionIndexSection::finalizeContents(Ctx &) {
44454445
for (size_t i = 1; i != ctx.partitions.size(); ++i)
44464446
ctx.partitions[i].nameStrTab =
44474447
ctx.mainPart->dynStrTab->addString(ctx.partitions[i].name);

lld/ELF/SyntheticSections.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class EhFrameSection final : public SyntheticSection {
5252
public:
5353
EhFrameSection();
5454
void writeTo(uint8_t *buf) override;
55-
void finalizeContents() override;
55+
void finalizeContents(Ctx &) override;
5656
bool isNeeded() const override { return !sections.empty(); }
5757
size_t getSize() const override { return size; }
5858

@@ -106,7 +106,7 @@ class GotSection final : public SyntheticSection {
106106
public:
107107
GotSection();
108108
size_t getSize() const override { return size; }
109-
void finalizeContents() override;
109+
void finalizeContents(Ctx &) override;
110110
bool isNeeded() const override;
111111
void writeTo(uint8_t *buf) override;
112112

@@ -186,7 +186,7 @@ class MipsGotSection final : public SyntheticSection {
186186
void writeTo(uint8_t *buf) override;
187187
size_t getSize() const override { return size; }
188188
bool updateAllocSize() override;
189-
void finalizeContents() override;
189+
void finalizeContents(Ctx &) override;
190190
bool isNeeded() const override;
191191

192192
// Join separate GOTs built for each input file to generate
@@ -484,7 +484,7 @@ template <class ELFT> class DynamicSection final : public SyntheticSection {
484484

485485
public:
486486
DynamicSection();
487-
void finalizeContents() override;
487+
void finalizeContents(Ctx &) override;
488488
void writeTo(uint8_t *buf) override;
489489
size_t getSize() const override { return size; }
490490

@@ -545,7 +545,7 @@ class RelocationBaseSection : public SyntheticSection {
545545
size_t getRelativeRelocCount() const { return numRelativeRelocs; }
546546
void mergeRels();
547547
void partitionRels();
548-
void finalizeContents() override;
548+
void finalizeContents(Ctx &) override;
549549
static bool classof(const SectionBase *d) {
550550
return SyntheticSection::classof(d) &&
551551
(d->type == llvm::ELF::SHT_RELA || d->type == llvm::ELF::SHT_REL ||
@@ -647,7 +647,7 @@ struct SymbolTableEntry {
647647
class SymbolTableBaseSection : public SyntheticSection {
648648
public:
649649
SymbolTableBaseSection(StringTableSection &strTabSec);
650-
void finalizeContents() override;
650+
void finalizeContents(Ctx &) override;
651651
size_t getSize() const override { return getNumSymbols() * entsize; }
652652
void addSymbol(Symbol *sym);
653653
unsigned getNumSymbols() const { return symbols.size() + 1; }
@@ -683,15 +683,15 @@ class SymtabShndxSection final : public SyntheticSection {
683683
void writeTo(uint8_t *buf) override;
684684
size_t getSize() const override;
685685
bool isNeeded() const override;
686-
void finalizeContents() override;
686+
void finalizeContents(Ctx &) override;
687687
};
688688

689689
// Outputs GNU Hash section. For detailed explanation see:
690690
// https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
691691
class GnuHashTableSection final : public SyntheticSection {
692692
public:
693693
GnuHashTableSection();
694-
void finalizeContents() override;
694+
void finalizeContents(Ctx &) override;
695695
void writeTo(uint8_t *buf) override;
696696
size_t getSize() const override { return size; }
697697

@@ -719,7 +719,7 @@ class GnuHashTableSection final : public SyntheticSection {
719719
class HashTableSection final : public SyntheticSection {
720720
public:
721721
HashTableSection();
722-
void finalizeContents() override;
722+
void finalizeContents(Ctx &) override;
723723
void writeTo(uint8_t *buf) override;
724724
size_t getSize() const override { return size; }
725725

@@ -913,7 +913,7 @@ template <class ELFT>
913913
class DebugNamesSection final : public DebugNamesBaseSection {
914914
public:
915915
DebugNamesSection();
916-
void finalizeContents() override;
916+
void finalizeContents(Ctx &) override;
917917
void writeTo(uint8_t *buf) override;
918918

919919
template <class RelTy>
@@ -1016,7 +1016,7 @@ class EhFrameHeader final : public SyntheticSection {
10161016
class VersionDefinitionSection final : public SyntheticSection {
10171017
public:
10181018
VersionDefinitionSection();
1019-
void finalizeContents() override;
1019+
void finalizeContents(Ctx &) override;
10201020
size_t getSize() const override;
10211021
void writeTo(uint8_t *buf) override;
10221022

@@ -1038,7 +1038,7 @@ class VersionDefinitionSection final : public SyntheticSection {
10381038
class VersionTableSection final : public SyntheticSection {
10391039
public:
10401040
VersionTableSection();
1041-
void finalizeContents() override;
1041+
void finalizeContents(Ctx &) override;
10421042
size_t getSize() const override;
10431043
void writeTo(uint8_t *buf) override;
10441044
bool isNeeded() const override;
@@ -1069,7 +1069,7 @@ class VersionNeedSection final : public SyntheticSection {
10691069

10701070
public:
10711071
VersionNeedSection();
1072-
void finalizeContents() override;
1072+
void finalizeContents(Ctx &) override;
10731073
void writeTo(uint8_t *buf) override;
10741074
size_t getSize() const override;
10751075
bool isNeeded() const override;
@@ -1097,7 +1097,7 @@ class MergeTailSection final : public MergeSyntheticSection {
10971097

10981098
size_t getSize() const override;
10991099
void writeTo(uint8_t *buf) override;
1100-
void finalizeContents() override;
1100+
void finalizeContents(Ctx &) override;
11011101

11021102
private:
11031103
llvm::StringTableBuilder builder;
@@ -1111,7 +1111,7 @@ class MergeNoTailSection final : public MergeSyntheticSection {
11111111

11121112
size_t getSize() const override { return size; }
11131113
void writeTo(uint8_t *buf) override;
1114-
void finalizeContents() override;
1114+
void finalizeContents(Ctx &) override;
11151115

11161116
private:
11171117
// We use the most significant bits of a hash as a shard ID.
@@ -1240,7 +1240,7 @@ class ARMExidxSyntheticSection : public SyntheticSection {
12401240
void writeTo(uint8_t *buf) override;
12411241
bool isNeeded() const override;
12421242
// Sort and remove duplicate entries.
1243-
void finalizeContents() override;
1243+
void finalizeContents(Ctx &) override;
12441244
InputSection *getLinkOrderDep() const;
12451245

12461246
static bool classof(const SectionBase *sec) {
@@ -1313,7 +1313,7 @@ class ArmCmseSGSection final : public SyntheticSection {
13131313
void writeTo(uint8_t *buf) override;
13141314
void addSGVeneer(Symbol *sym, Symbol *ext_sym);
13151315
void addMappingSymbol();
1316-
void finalizeContents() override;
1316+
void finalizeContents(Ctx &) override;
13171317
void exportEntries(SymbolTableBaseSection *symTab);
13181318
uint64_t impLibMaxAddr = 0;
13191319

@@ -1330,7 +1330,7 @@ class PPC32Got2Section final : public SyntheticSection {
13301330
PPC32Got2Section();
13311331
size_t getSize() const override { return 0; }
13321332
bool isNeeded() const override;
1333-
void finalizeContents() override;
1333+
void finalizeContents(Ctx &) override;
13341334
void writeTo(uint8_t *buf) override {}
13351335
};
13361336

@@ -1347,7 +1347,7 @@ class PPC64LongBranchTargetSection final : public SyntheticSection {
13471347
size_t getSize() const override;
13481348
void writeTo(uint8_t *buf) override;
13491349
bool isNeeded() const override;
1350-
void finalizeContents() override { finalized = true; }
1350+
void finalizeContents(Ctx &) override { finalized = true; }
13511351

13521352
private:
13531353
SmallVector<std::pair<const Symbol *, int64_t>, 0> entries;
@@ -1375,7 +1375,7 @@ class PartitionIndexSection final : public SyntheticSection {
13751375
public:
13761376
PartitionIndexSection();
13771377
size_t getSize() const override;
1378-
void finalizeContents() override;
1378+
void finalizeContents(Ctx &) override;
13791379
void writeTo(uint8_t *buf) override;
13801380
};
13811381

lld/ELF/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ template <class ELFT> void Writer<ELFT>::resolveShfLinkOrder() {
14271427
static void finalizeSynthetic(SyntheticSection *sec) {
14281428
if (sec && sec->isNeeded() && sec->getParent()) {
14291429
llvm::TimeTraceScope timeScope("Finalize synthetic sections", sec->name);
1430-
sec->finalizeContents();
1430+
sec->finalizeContents(ctx);
14311431
}
14321432
}
14331433

0 commit comments

Comments
 (0)