@@ -563,7 +563,7 @@ SmallVector<EhFrameSection::FdeData, 0> EhFrameSection::getFdeData() const {
563
563
uint8_t *buf = ctx.bufferStart + getParent ()->offset + outSecOff;
564
564
SmallVector<FdeData, 0 > ret;
565
565
566
- uint64_t va = getPartition ().ehFrameHdr ->getVA ();
566
+ uint64_t va = getPartition (ctx ).ehFrameHdr ->getVA ();
567
567
for (CieRecord *rec : cieRecords) {
568
568
uint8_t enc = getFdeEncoding (rec->cie );
569
569
for (EhSectionPiece *fde : rec->fdes ) {
@@ -650,8 +650,8 @@ void EhFrameSection::writeTo(uint8_t *buf) {
650
650
for (EhInputSection *s : sections)
651
651
ctx.target ->relocateAlloc (*s, buf);
652
652
653
- if (getPartition ().ehFrameHdr && getPartition ().ehFrameHdr ->getParent ())
654
- getPartition ().ehFrameHdr ->write ();
653
+ if (getPartition (ctx ).ehFrameHdr && getPartition (ctx ).ehFrameHdr ->getParent ())
654
+ getPartition (ctx ).ehFrameHdr ->write ();
655
655
}
656
656
657
657
GotSection::GotSection (Ctx &ctx)
@@ -1325,7 +1325,7 @@ static uint64_t addPltRelSz(Ctx &ctx) { return ctx.in.relaPlt->getSize(); }
1325
1325
template <class ELFT >
1326
1326
std::vector<std::pair<int32_t , uint64_t >>
1327
1327
DynamicSection<ELFT>::computeContents() {
1328
- elf::Partition &part = getPartition ();
1328
+ elf::Partition &part = getPartition (ctx );
1329
1329
bool isMain = part.name .empty ();
1330
1330
std::vector<std::pair<int32_t , uint64_t >> entries;
1331
1331
@@ -1586,7 +1586,7 @@ DynamicSection<ELFT>::computeContents() {
1586
1586
}
1587
1587
1588
1588
template <class ELFT > void DynamicSection<ELFT>::finalizeContents() {
1589
- if (OutputSection *sec = getPartition ().dynStrTab ->getParent ())
1589
+ if (OutputSection *sec = getPartition (ctx ).dynStrTab ->getParent ())
1590
1590
getParent ()->link = sec->sectionIndex ;
1591
1591
this ->size = computeContents ().size () * this ->entsize ;
1592
1592
}
@@ -1688,7 +1688,7 @@ void RelocationBaseSection::partitionRels() {
1688
1688
}
1689
1689
1690
1690
void RelocationBaseSection::finalizeContents () {
1691
- SymbolTableBaseSection *symTab = getPartition ().dynSymTab .get ();
1691
+ SymbolTableBaseSection *symTab = getPartition (ctx ).dynSymTab .get ();
1692
1692
1693
1693
// When linking glibc statically, .rel{,a}.plt contains R_*_IRELATIVE
1694
1694
// relocations due to IFUNC (e.g. strcpy). sh_link will be set to 0 in that
@@ -1712,7 +1712,7 @@ void DynamicReloc::computeRaw(Ctx &ctx, SymbolTableBaseSection *symt) {
1712
1712
}
1713
1713
1714
1714
void RelocationBaseSection::computeRels () {
1715
- SymbolTableBaseSection *symTab = getPartition ().dynSymTab .get ();
1715
+ SymbolTableBaseSection *symTab = getPartition (ctx ).dynSymTab .get ();
1716
1716
parallelForEach (relocs, [&ctx = ctx, symTab](DynamicReloc &rel) {
1717
1717
rel.computeRaw (ctx, symTab);
1718
1718
});
@@ -1852,7 +1852,7 @@ bool AndroidPackedRelocationSection<ELFT>::updateAllocSize(Ctx &ctx) {
1852
1852
for (const DynamicReloc &rel : relocs) {
1853
1853
Elf_Rela r;
1854
1854
r.r_offset = rel.getOffset ();
1855
- r.setSymbolAndType (rel.getSymIndex (getPartition ().dynSymTab .get ()),
1855
+ r.setSymbolAndType (rel.getSymIndex (getPartition (ctx ).dynSymTab .get ()),
1856
1856
rel.type , false );
1857
1857
r.r_addend = ctx.arg .isRela ? rel.computeAddend (ctx) : 0 ;
1858
1858
@@ -2162,9 +2162,9 @@ void SymbolTableBaseSection::finalizeContents() {
2162
2162
// Because the first symbol entry is a null entry, 1 is the first.
2163
2163
getParent ()->info = 1 ;
2164
2164
2165
- if (getPartition ().gnuHashTab ) {
2165
+ if (getPartition (ctx ).gnuHashTab ) {
2166
2166
// NB: It also sorts Symbols to meet the GNU hash table requirements.
2167
- getPartition ().gnuHashTab ->addSymbols (symbols);
2167
+ getPartition (ctx ).gnuHashTab ->addSymbols (symbols);
2168
2168
} else if (ctx.arg .emachine == EM_MIPS) {
2169
2169
sortMipsSymbols (ctx, symbols);
2170
2170
}
@@ -2416,7 +2416,7 @@ GnuHashTableSection::GnuHashTableSection(Ctx &ctx)
2416
2416
" .gnu.hash" ) {}
2417
2417
2418
2418
void GnuHashTableSection::finalizeContents () {
2419
- if (OutputSection *sec = getPartition ().dynSymTab ->getParent ())
2419
+ if (OutputSection *sec = getPartition (ctx ).dynSymTab ->getParent ())
2420
2420
getParent ()->link = sec->sectionIndex ;
2421
2421
2422
2422
// Computes bloom filter size in word size. We want to allocate 12
@@ -2438,7 +2438,7 @@ void GnuHashTableSection::writeTo(uint8_t *buf) {
2438
2438
// Write a header.
2439
2439
write32 (ctx, buf, nBuckets);
2440
2440
write32 (ctx, buf + 4 ,
2441
- getPartition ().dynSymTab ->getNumSymbols () - symbols.size ());
2441
+ getPartition (ctx ).dynSymTab ->getNumSymbols () - symbols.size ());
2442
2442
write32 (ctx, buf + 8 , maskWords);
2443
2443
write32 (ctx, buf + 12 , Shift2);
2444
2444
buf += 16 ;
@@ -2474,7 +2474,7 @@ void GnuHashTableSection::writeTo(uint8_t *buf) {
2474
2474
// Write a hash bucket. Hash buckets contain indices in the following hash
2475
2475
// value table.
2476
2476
write32 (ctx, buckets + i->bucketIdx ,
2477
- getPartition ().dynSymTab ->getSymbolIndex (*i->sym ));
2477
+ getPartition (ctx ).dynSymTab ->getSymbolIndex (*i->sym ));
2478
2478
oldBucket = i->bucketIdx ;
2479
2479
}
2480
2480
}
@@ -2527,7 +2527,7 @@ HashTableSection::HashTableSection(Ctx &ctx)
2527
2527
}
2528
2528
2529
2529
void HashTableSection::finalizeContents () {
2530
- SymbolTableBaseSection *symTab = getPartition ().dynSymTab .get ();
2530
+ SymbolTableBaseSection *symTab = getPartition (ctx ).dynSymTab .get ();
2531
2531
2532
2532
if (OutputSection *sec = symTab->getParent ())
2533
2533
getParent ()->link = sec->sectionIndex ;
@@ -2541,7 +2541,7 @@ void HashTableSection::finalizeContents() {
2541
2541
}
2542
2542
2543
2543
void HashTableSection::writeTo (uint8_t *buf) {
2544
- SymbolTableBaseSection *symTab = getPartition ().dynSymTab .get ();
2544
+ SymbolTableBaseSection *symTab = getPartition (ctx ).dynSymTab .get ();
2545
2545
unsigned numSymbols = symTab->getNumSymbols ();
2546
2546
2547
2547
uint32_t *p = reinterpret_cast <uint32_t *>(buf);
@@ -3667,14 +3667,14 @@ void EhFrameHeader::writeTo(uint8_t *buf) {
3667
3667
void EhFrameHeader::write () {
3668
3668
uint8_t *buf = ctx.bufferStart + getParent ()->offset + outSecOff;
3669
3669
using FdeData = EhFrameSection::FdeData;
3670
- SmallVector<FdeData, 0 > fdes = getPartition ().ehFrame ->getFdeData ();
3670
+ SmallVector<FdeData, 0 > fdes = getPartition (ctx ).ehFrame ->getFdeData ();
3671
3671
3672
3672
buf[0 ] = 1 ;
3673
3673
buf[1 ] = DW_EH_PE_pcrel | DW_EH_PE_sdata4;
3674
3674
buf[2 ] = DW_EH_PE_udata4;
3675
3675
buf[3 ] = DW_EH_PE_datarel | DW_EH_PE_sdata4;
3676
3676
write32 (ctx, buf + 4 ,
3677
- getPartition ().ehFrame ->getParent ()->addr - this ->getVA () - 4 );
3677
+ getPartition (ctx ).ehFrame ->getParent ()->addr - this ->getVA () - 4 );
3678
3678
write32 (ctx, buf + 8 , fdes.size ());
3679
3679
buf += 12 ;
3680
3680
@@ -3687,31 +3687,31 @@ void EhFrameHeader::write() {
3687
3687
3688
3688
size_t EhFrameHeader::getSize () const {
3689
3689
// .eh_frame_hdr has a 12 bytes header followed by an array of FDEs.
3690
- return 12 + getPartition ().ehFrame ->numFdes * 8 ;
3690
+ return 12 + getPartition (ctx ).ehFrame ->numFdes * 8 ;
3691
3691
}
3692
3692
3693
3693
bool EhFrameHeader::isNeeded () const {
3694
- return isLive () && getPartition ().ehFrame ->isNeeded ();
3694
+ return isLive () && getPartition (ctx ).ehFrame ->isNeeded ();
3695
3695
}
3696
3696
3697
3697
VersionDefinitionSection::VersionDefinitionSection (Ctx &ctx)
3698
3698
: SyntheticSection(ctx, SHF_ALLOC, SHT_GNU_verdef, sizeof (uint32_t ),
3699
3699
".gnu.version_d") {}
3700
3700
3701
3701
StringRef VersionDefinitionSection::getFileDefName () {
3702
- if (!getPartition ().name .empty ())
3703
- return getPartition ().name ;
3702
+ if (!getPartition (ctx ).name .empty ())
3703
+ return getPartition (ctx ).name ;
3704
3704
if (!ctx.arg .soName .empty ())
3705
3705
return ctx.arg .soName ;
3706
3706
return ctx.arg .outputFile ;
3707
3707
}
3708
3708
3709
3709
void VersionDefinitionSection::finalizeContents () {
3710
- fileDefNameOff = getPartition ().dynStrTab ->addString (getFileDefName ());
3710
+ fileDefNameOff = getPartition (ctx ).dynStrTab ->addString (getFileDefName ());
3711
3711
for (const VersionDefinition &v : namedVersionDefs (ctx))
3712
- verDefNameOffs.push_back (getPartition ().dynStrTab ->addString (v.name ));
3712
+ verDefNameOffs.push_back (getPartition (ctx ).dynStrTab ->addString (v.name ));
3713
3713
3714
- if (OutputSection *sec = getPartition ().dynStrTab ->getParent ())
3714
+ if (OutputSection *sec = getPartition (ctx ).dynStrTab ->getParent ())
3715
3715
getParent ()->link = sec->sectionIndex ;
3716
3716
3717
3717
// sh_info should be set to the number of definitions. This fact is missed in
@@ -3765,16 +3765,16 @@ VersionTableSection::VersionTableSection(Ctx &ctx)
3765
3765
void VersionTableSection::finalizeContents () {
3766
3766
// At the moment of june 2016 GNU docs does not mention that sh_link field
3767
3767
// should be set, but Sun docs do. Also readelf relies on this field.
3768
- getParent ()->link = getPartition ().dynSymTab ->getParent ()->sectionIndex ;
3768
+ getParent ()->link = getPartition (ctx ).dynSymTab ->getParent ()->sectionIndex ;
3769
3769
}
3770
3770
3771
3771
size_t VersionTableSection::getSize () const {
3772
- return (getPartition ().dynSymTab ->getSymbols ().size () + 1 ) * 2 ;
3772
+ return (getPartition (ctx ).dynSymTab ->getSymbols ().size () + 1 ) * 2 ;
3773
3773
}
3774
3774
3775
3775
void VersionTableSection::writeTo (uint8_t *buf) {
3776
3776
buf += 2 ;
3777
- for (const SymbolTableEntry &s : getPartition ().dynSymTab ->getSymbols ()) {
3777
+ for (const SymbolTableEntry &s : getPartition (ctx ).dynSymTab ->getSymbols ()) {
3778
3778
// For an unextracted lazy symbol (undefined weak), it must have been
3779
3779
// converted to Undefined and have VER_NDX_GLOBAL version here.
3780
3780
assert (!s.sym ->isLazy ());
@@ -3785,7 +3785,7 @@ void VersionTableSection::writeTo(uint8_t *buf) {
3785
3785
3786
3786
bool VersionTableSection::isNeeded () const {
3787
3787
return isLive () &&
3788
- (getPartition ().verDef || getPartition ().verNeed ->isNeeded ());
3788
+ (getPartition (ctx ).verDef || getPartition (ctx ).verNeed ->isNeeded ());
3789
3789
}
3790
3790
3791
3791
void elf::addVerneed (Ctx &ctx, Symbol &ss) {
@@ -3817,7 +3817,7 @@ template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents() {
3817
3817
continue ;
3818
3818
verneeds.emplace_back ();
3819
3819
Verneed &vn = verneeds.back ();
3820
- vn.nameStrTab = getPartition ().dynStrTab ->addString (f->soName );
3820
+ vn.nameStrTab = getPartition (ctx ).dynStrTab ->addString (f->soName );
3821
3821
bool isLibc = ctx.arg .relrGlibc && f->soName .starts_with (" libc.so." );
3822
3822
bool isGlibc2 = false ;
3823
3823
for (unsigned i = 0 ; i != f->vernauxs .size (); ++i) {
@@ -3829,17 +3829,17 @@ template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents() {
3829
3829
if (isLibc && ver.starts_with (" GLIBC_2." ))
3830
3830
isGlibc2 = true ;
3831
3831
vn.vernauxs .push_back ({verdef->vd_hash , f->vernauxs [i],
3832
- getPartition ().dynStrTab ->addString (ver)});
3832
+ getPartition (ctx ).dynStrTab ->addString (ver)});
3833
3833
}
3834
3834
if (isGlibc2) {
3835
3835
const char *ver = " GLIBC_ABI_DT_RELR" ;
3836
3836
vn.vernauxs .push_back ({hashSysV (ver),
3837
3837
++SharedFile::vernauxNum + getVerDefNum (ctx),
3838
- getPartition ().dynStrTab ->addString (ver)});
3838
+ getPartition (ctx ).dynStrTab ->addString (ver)});
3839
3839
}
3840
3840
}
3841
3841
3842
- if (OutputSection *sec = getPartition ().dynStrTab ->getParent ())
3842
+ if (OutputSection *sec = getPartition (ctx ).dynStrTab ->getParent ())
3843
3843
getParent ()->link = sec->sectionIndex ;
3844
3844
getParent ()->info = verneeds.size ();
3845
3845
}
@@ -3995,7 +3995,7 @@ template <class ELFT> void elf::splitSections(Ctx &ctx) {
3995
3995
void elf::combineEhSections (Ctx &ctx) {
3996
3996
llvm::TimeTraceScope timeScope (" Combine EH sections" );
3997
3997
for (EhInputSection *sec : ctx.ehInputSections ) {
3998
- EhFrameSection &eh = *sec->getPartition ().ehFrame ;
3998
+ EhFrameSection &eh = *sec->getPartition (ctx ).ehFrame ;
3999
3999
sec->parent = &eh;
4000
4000
eh.addralign = std::max (eh.addralign , sec->addralign );
4001
4001
eh.sections .push_back (sec);
@@ -4004,12 +4004,12 @@ void elf::combineEhSections(Ctx &ctx) {
4004
4004
4005
4005
if (!ctx.mainPart ->armExidx )
4006
4006
return ;
4007
- llvm::erase_if (ctx.inputSections , [](InputSectionBase *s) {
4007
+ llvm::erase_if (ctx.inputSections , [& ](InputSectionBase *s) {
4008
4008
// Ignore dead sections and the partition end marker (.part.end),
4009
4009
// whose partition number is out of bounds.
4010
4010
if (!s->isLive () || s->partition == 255 )
4011
4011
return false ;
4012
- Partition &part = s->getPartition ();
4012
+ Partition &part = s->getPartition (ctx );
4013
4013
return s->kind () == SectionBase::Regular && part.armExidx &&
4014
4014
part.armExidx ->addSection (cast<InputSection>(s));
4015
4015
});
@@ -4447,7 +4447,7 @@ size_t PartitionElfHeaderSection<ELFT>::getSize() const {
4447
4447
4448
4448
template <typename ELFT>
4449
4449
void PartitionElfHeaderSection<ELFT>::writeTo(uint8_t *buf) {
4450
- writeEhdr<ELFT>(ctx, buf, getPartition ());
4450
+ writeEhdr<ELFT>(ctx, buf, getPartition (ctx ));
4451
4451
4452
4452
// Loadable partitions are always ET_DYN.
4453
4453
auto *eHdr = reinterpret_cast <typename ELFT::Ehdr *>(buf);
@@ -4460,12 +4460,12 @@ PartitionProgramHeadersSection<ELFT>::PartitionProgramHeadersSection(Ctx &ctx)
4460
4460
4461
4461
template <typename ELFT>
4462
4462
size_t PartitionProgramHeadersSection<ELFT>::getSize() const {
4463
- return sizeof (typename ELFT::Phdr) * getPartition ().phdrs .size ();
4463
+ return sizeof (typename ELFT::Phdr) * getPartition (ctx ).phdrs .size ();
4464
4464
}
4465
4465
4466
4466
template <typename ELFT>
4467
4467
void PartitionProgramHeadersSection<ELFT>::writeTo(uint8_t *buf) {
4468
- writePhdrs<ELFT>(buf, getPartition ());
4468
+ writePhdrs<ELFT>(buf, getPartition (ctx ));
4469
4469
}
4470
4470
4471
4471
PartitionIndexSection::PartitionIndexSection (Ctx &ctx)
@@ -4747,7 +4747,7 @@ template <class ELFT> void elf::createSyntheticSections(Ctx &ctx) {
4747
4747
const unsigned threadCount = ctx.arg .threadCount ;
4748
4748
for (Partition &part : ctx.partitions ) {
4749
4749
auto add = [&](SyntheticSection &sec) {
4750
- sec.partition = part.getNumber ();
4750
+ sec.partition = part.getNumber (ctx );
4751
4751
ctx.inputSections .push_back (&sec);
4752
4752
};
4753
4753
0 commit comments