@@ -108,7 +108,8 @@ void MipsAbiFlagsSection<ELFT>::writeTo(Ctx &ctx, uint8_t *buf) {
108
108
}
109
109
110
110
template <class ELFT >
111
- std::unique_ptr<MipsAbiFlagsSection<ELFT>> MipsAbiFlagsSection<ELFT>::create() {
111
+ std::unique_ptr<MipsAbiFlagsSection<ELFT>>
112
+ MipsAbiFlagsSection<ELFT>::create(Ctx &ctx) {
112
113
Elf_Mips_ABIFlags flags = {};
113
114
bool create = false ;
114
115
@@ -175,7 +176,8 @@ void MipsOptionsSection<ELFT>::writeTo(Ctx &ctx, uint8_t *buf) {
175
176
}
176
177
177
178
template <class ELFT >
178
- std::unique_ptr<MipsOptionsSection<ELFT>> MipsOptionsSection<ELFT>::create() {
179
+ std::unique_ptr<MipsOptionsSection<ELFT>>
180
+ MipsOptionsSection<ELFT>::create(Ctx &ctx) {
179
181
// N64 ABI only.
180
182
if (!ELFT::Is64Bits)
181
183
return nullptr ;
@@ -233,7 +235,8 @@ void MipsReginfoSection<ELFT>::writeTo(Ctx &ctx, uint8_t *buf) {
233
235
}
234
236
235
237
template <class ELFT >
236
- std::unique_ptr<MipsReginfoSection<ELFT>> MipsReginfoSection<ELFT>::create() {
238
+ std::unique_ptr<MipsReginfoSection<ELFT>>
239
+ MipsReginfoSection<ELFT>::create(Ctx &ctx) {
237
240
// Section should be alive for O32 and N32 ABIs only.
238
241
if (ELFT::Is64Bits)
239
242
return nullptr ;
@@ -712,7 +715,7 @@ void GotSection::finalizeContents(Ctx &) {
712
715
size = numEntries * ctx.arg .wordsize ;
713
716
}
714
717
715
- bool GotSection::isNeeded () const {
718
+ bool GotSection::isNeeded (Ctx &ctx ) const {
716
719
// Needed if the GOT symbol is used or the number of entries is more than just
717
720
// the header. A GOT with just the header may not be needed.
718
721
return hasGotOffRel || numEntries > ctx.target ->gotHeaderEntriesNum ;
@@ -872,9 +875,9 @@ bool MipsGotSection::tryMergeGots(FileGot &dst, FileGot &src, bool isPrimary) {
872
875
return true ;
873
876
}
874
877
875
- void MipsGotSection::finalizeContents (Ctx &) { updateAllocSize (); }
878
+ void MipsGotSection::finalizeContents (Ctx &) { updateAllocSize (ctx ); }
876
879
877
- bool MipsGotSection::updateAllocSize () {
880
+ bool MipsGotSection::updateAllocSize (Ctx &ctx ) {
878
881
size = headerEntriesNum * ctx.arg .wordsize ;
879
882
for (const FileGot &g : gots)
880
883
size += g.getEntriesNum () * ctx.arg .wordsize ;
@@ -1084,7 +1087,7 @@ void MipsGotSection::build() {
1084
1087
}
1085
1088
}
1086
1089
1087
- bool MipsGotSection::isNeeded () const {
1090
+ bool MipsGotSection::isNeeded (Ctx &ctx ) const {
1088
1091
// We add the .got section to the result for dynamic MIPS target because
1089
1092
// its address and properties are mentioned in the .dynamic section.
1090
1093
return !ctx.arg .relocatable ;
@@ -1197,7 +1200,7 @@ void GotPltSection::writeTo(Ctx &ctx, uint8_t *buf) {
1197
1200
}
1198
1201
}
1199
1202
1200
- bool GotPltSection::isNeeded () const {
1203
+ bool GotPltSection::isNeeded (Ctx & ) const {
1201
1204
// We need to emit GOTPLT even if it's empty if there's a relocation relative
1202
1205
// to it.
1203
1206
return !entries.empty () || hasGotPltOffRel;
@@ -1400,7 +1403,7 @@ DynamicSection<ELFT>::computeContents() {
1400
1403
if (!ctx.arg .shared && !ctx.arg .relocatable && !ctx.arg .zRodynamic )
1401
1404
addInt (DT_DEBUG, 0 );
1402
1405
1403
- if (part.relaDyn ->isNeeded ()) {
1406
+ if (part.relaDyn ->isNeeded (ctx )) {
1404
1407
addInSec (part.relaDyn ->dynamicTag , *part.relaDyn );
1405
1408
entries.emplace_back (part.relaDyn ->sizeDynamicTag ,
1406
1409
addRelaSz (*part.relaDyn ));
@@ -1433,7 +1436,7 @@ DynamicSection<ELFT>::computeContents() {
1433
1436
addInt (DT_AARCH64_AUTH_RELRSZ, part.relrAuthDyn ->getParent ()->size );
1434
1437
addInt (DT_AARCH64_AUTH_RELRENT, sizeof (Elf_Relr));
1435
1438
}
1436
- if (isMain && ctx.in .relaPlt ->isNeeded ()) {
1439
+ if (isMain && ctx.in .relaPlt ->isNeeded (ctx )) {
1437
1440
addInSec (DT_JMPREL, *ctx.in .relaPlt );
1438
1441
entries.emplace_back (DT_PLTRELSZ, addPltRelSz ());
1439
1442
switch (ctx.arg .emachine ) {
@@ -1478,7 +1481,7 @@ DynamicSection<ELFT>::computeContents() {
1478
1481
addInt (DT_AARCH64_MEMTAG_MODE, ctx.arg .androidMemtagMode == NT_MEMTAG_LEVEL_ASYNC);
1479
1482
addInt (DT_AARCH64_MEMTAG_HEAP, ctx.arg .androidMemtagHeap );
1480
1483
addInt (DT_AARCH64_MEMTAG_STACK, ctx.arg .androidMemtagStack );
1481
- if (ctx.mainPart ->memtagGlobalDescriptors ->isNeeded ()) {
1484
+ if (ctx.mainPart ->memtagGlobalDescriptors ->isNeeded (ctx )) {
1482
1485
addInSec (DT_AARCH64_MEMTAG_GLOBALS,
1483
1486
*ctx.mainPart ->memtagGlobalDescriptors );
1484
1487
addInt (DT_AARCH64_MEMTAG_GLOBALSSZ,
@@ -1520,13 +1523,13 @@ DynamicSection<ELFT>::computeContents() {
1520
1523
addInt (DT_FINI, b->getVA ());
1521
1524
}
1522
1525
1523
- if (part.verSym && part.verSym ->isNeeded ())
1526
+ if (part.verSym && part.verSym ->isNeeded (ctx ))
1524
1527
addInSec (DT_VERSYM, *part.verSym );
1525
1528
if (part.verDef && part.verDef ->isLive ()) {
1526
1529
addInSec (DT_VERDEF, *part.verDef );
1527
1530
addInt (DT_VERDEFNUM, getVerDefNum ());
1528
1531
}
1529
- if (part.verNeed && part.verNeed ->isNeeded ()) {
1532
+ if (part.verNeed && part.verNeed ->isNeeded (ctx )) {
1530
1533
addInSec (DT_VERNEED, *part.verNeed );
1531
1534
unsigned needNum = 0 ;
1532
1535
for (SharedFile *f : ctx.sharedFiles )
@@ -1563,7 +1566,7 @@ DynamicSection<ELFT>::computeContents() {
1563
1566
addInSec (DT_PPC_GOT, *ctx.in .got );
1564
1567
1565
1568
// Glink dynamic tag is required by the V2 abi if the plt section isn't empty.
1566
- if (ctx.arg .emachine == EM_PPC64 && ctx.in .plt ->isNeeded ()) {
1569
+ if (ctx.arg .emachine == EM_PPC64 && ctx.in .plt ->isNeeded (ctx )) {
1567
1570
// The Glink tag points to 32 bytes before the first lazy symbol resolution
1568
1571
// stub, which starts directly after the header.
1569
1572
addInt (DT_PPC64_GLINK,
@@ -1780,7 +1783,7 @@ AndroidPackedRelocationSection<ELFT>::AndroidPackedRelocationSection(
1780
1783
}
1781
1784
1782
1785
template <class ELFT >
1783
- bool AndroidPackedRelocationSection<ELFT>::updateAllocSize() {
1786
+ bool AndroidPackedRelocationSection<ELFT>::updateAllocSize(Ctx &ctx ) {
1784
1787
// This function computes the contents of an Android-format packed relocation
1785
1788
// section.
1786
1789
//
@@ -2028,7 +2031,7 @@ RelrSection<ELFT>::RelrSection(unsigned concurrency, bool isAArch64Auth)
2028
2031
this ->entsize = ctx.arg .wordsize ;
2029
2032
}
2030
2033
2031
- template <class ELFT > bool RelrSection<ELFT>::updateAllocSize() {
2034
+ template <class ELFT > bool RelrSection<ELFT>::updateAllocSize(Ctx &ctx ) {
2032
2035
// This function computes the contents of an SHT_RELR packed relocation
2033
2036
// section.
2034
2037
//
@@ -2344,7 +2347,7 @@ void SymtabShndxSection::writeTo(Ctx &ctx, uint8_t *buf) {
2344
2347
}
2345
2348
}
2346
2349
2347
- bool SymtabShndxSection::isNeeded () const {
2350
+ bool SymtabShndxSection::isNeeded (Ctx &ctx ) const {
2348
2351
// SHT_SYMTAB can hold symbols with section indices values up to
2349
2352
// SHN_LORESERVE. If we need more, we want to use extension SHT_SYMTAB_SHNDX
2350
2353
// section. Problem is that we reveal the final section indices a bit too
@@ -2587,9 +2590,10 @@ size_t PltSection::getSize(Ctx &ctx) const {
2587
2590
return headerSize + entries.size () * ctx.target ->pltEntrySize ;
2588
2591
}
2589
2592
2590
- bool PltSection::isNeeded () const {
2593
+ bool PltSection::isNeeded (Ctx &ctx ) const {
2591
2594
// For -z retpolineplt, .iplt needs the .plt header.
2592
- return !entries.empty () || (ctx.arg .zRetpolineplt && ctx.in .iplt ->isNeeded ());
2595
+ return !entries.empty () ||
2596
+ (ctx.arg .zRetpolineplt && ctx.in .iplt ->isNeeded (ctx));
2593
2597
}
2594
2598
2595
2599
// Used by ARM to add mapping symbols in the PLT section, which aid
@@ -2722,7 +2726,9 @@ size_t IBTPltSection::getSize(Ctx &ctx) const {
2722
2726
return 16 + ctx.in .plt ->getNumEntries () * ctx.target ->pltEntrySize ;
2723
2727
}
2724
2728
2725
- bool IBTPltSection::isNeeded () const { return ctx.in .plt ->getNumEntries () > 0 ; }
2729
+ bool IBTPltSection::isNeeded (Ctx &ctx) const {
2730
+ return ctx.in .plt ->getNumEntries () > 0 ;
2731
+ }
2726
2732
2727
2733
RelroPaddingSection::RelroPaddingSection ()
2728
2734
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_NOBITS, 1 , " .relro_padding" ) {
@@ -3624,7 +3630,7 @@ void GdbIndexSection::writeTo(Ctx &ctx, uint8_t *buf) {
3624
3630
}
3625
3631
}
3626
3632
3627
- bool GdbIndexSection::isNeeded () const { return !chunks.empty (); }
3633
+ bool GdbIndexSection::isNeeded (Ctx & ) const { return !chunks.empty (); }
3628
3634
3629
3635
EhFrameHeader::EhFrameHeader ()
3630
3636
: SyntheticSection(SHF_ALLOC, SHT_PROGBITS, 4 , " .eh_frame_hdr" ) {}
@@ -3667,8 +3673,8 @@ size_t EhFrameHeader::getSize(Ctx &ctx) const {
3667
3673
return 12 + getPartition ().ehFrame ->numFdes * 8 ;
3668
3674
}
3669
3675
3670
- bool EhFrameHeader::isNeeded () const {
3671
- return isLive () && getPartition ().ehFrame ->isNeeded ();
3676
+ bool EhFrameHeader::isNeeded (Ctx &ctx ) const {
3677
+ return isLive () && getPartition ().ehFrame ->isNeeded (ctx );
3672
3678
}
3673
3679
3674
3680
VersionDefinitionSection::VersionDefinitionSection ()
@@ -3760,9 +3766,9 @@ void VersionTableSection::writeTo(Ctx &ctx, uint8_t *buf) {
3760
3766
}
3761
3767
}
3762
3768
3763
- bool VersionTableSection::isNeeded () const {
3769
+ bool VersionTableSection::isNeeded (Ctx &ctx ) const {
3764
3770
return isLive () &&
3765
- (getPartition ().verDef || getPartition ().verNeed ->isNeeded ());
3771
+ (getPartition ().verDef || getPartition ().verNeed ->isNeeded (ctx ));
3766
3772
}
3767
3773
3768
3774
void elf::addVerneed (Symbol *ss) {
@@ -3857,7 +3863,7 @@ template <class ELFT> size_t VersionNeedSection<ELFT>::getSize(Ctx &ctx) const {
3857
3863
SharedFile::vernauxNum * sizeof (Elf_Vernaux);
3858
3864
}
3859
3865
3860
- template <class ELFT > bool VersionNeedSection<ELFT>::isNeeded() const {
3866
+ template <class ELFT > bool VersionNeedSection<ELFT>::isNeeded(Ctx & ) const {
3861
3867
return isLive () && SharedFile::vernauxNum != 0 ;
3862
3868
}
3863
3869
@@ -4216,7 +4222,7 @@ void ARMExidxSyntheticSection::writeTo(Ctx &ctx, uint8_t *buf) {
4216
4222
assert (size == offset + 8 );
4217
4223
}
4218
4224
4219
- bool ARMExidxSyntheticSection::isNeeded () const {
4225
+ bool ARMExidxSyntheticSection::isNeeded (Ctx & ) const {
4220
4226
return llvm::any_of (exidxSections,
4221
4227
[](InputSection *isec) { return isec->isLive (); });
4222
4228
}
@@ -4268,7 +4274,7 @@ bool ThunkSection::assignOffsets() {
4268
4274
PPC32Got2Section::PPC32Got2Section ()
4269
4275
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, 4 , " .got2" ) {}
4270
4276
4271
- bool PPC32Got2Section::isNeeded () const {
4277
+ bool PPC32Got2Section::isNeeded (Ctx & ) const {
4272
4278
// See the comment below. This is not needed if there is no other
4273
4279
// InputSection.
4274
4280
for (SectionCommand *cmd : getParent ()->commands )
@@ -4341,7 +4347,7 @@ void PPC64LongBranchTargetSection::writeTo(Ctx &ctx, uint8_t *buf) {
4341
4347
}
4342
4348
}
4343
4349
4344
- bool PPC64LongBranchTargetSection::isNeeded () const {
4350
+ bool PPC64LongBranchTargetSection::isNeeded (Ctx & ) const {
4345
4351
// `removeUnusedSyntheticSections()` is called before thunk allocation which
4346
4352
// is too early to determine if this section will be empty or not. We need
4347
4353
// Finalized to keep the section alive until after thunk creation. Finalized
@@ -4622,7 +4628,7 @@ createMemtagGlobalDescriptors(const SmallVector<const Symbol *, 0> &symbols,
4622
4628
return sectionSize;
4623
4629
}
4624
4630
4625
- bool MemtagGlobalDescriptors::updateAllocSize () {
4631
+ bool MemtagGlobalDescriptors::updateAllocSize (Ctx &ctx ) {
4626
4632
size_t oldSize = getSize (ctx);
4627
4633
std::stable_sort (symbols.begin (), symbols.end (),
4628
4634
[](const Symbol *s1, const Symbol *s2) {
@@ -4704,11 +4710,11 @@ template <class ELFT> void elf::createSyntheticSections(Ctx &ctx) {
4704
4710
ctx.in .mipsRldMap = std::make_unique<MipsRldMapSection>();
4705
4711
add (*ctx.in .mipsRldMap );
4706
4712
}
4707
- if ((ctx.in .mipsAbiFlags = MipsAbiFlagsSection<ELFT>::create ()))
4713
+ if ((ctx.in .mipsAbiFlags = MipsAbiFlagsSection<ELFT>::create (ctx )))
4708
4714
add (*ctx.in .mipsAbiFlags );
4709
- if ((ctx.in .mipsOptions = MipsOptionsSection<ELFT>::create ()))
4715
+ if ((ctx.in .mipsOptions = MipsOptionsSection<ELFT>::create (ctx )))
4710
4716
add (*ctx.in .mipsOptions );
4711
- if ((ctx.in .mipsReginfo = MipsReginfoSection<ELFT>::create ()))
4717
+ if ((ctx.in .mipsReginfo = MipsReginfoSection<ELFT>::create (ctx )))
4712
4718
add (*ctx.in .mipsReginfo );
4713
4719
}
4714
4720
0 commit comments