@@ -563,7 +563,7 @@ SmallVector<EhFrameSection::FdeData, 0> EhFrameSection::getFdeData() const {
563563 uint8_t *buf = ctx.bufferStart + getParent ()->offset + outSecOff;
564564 SmallVector<FdeData, 0 > ret;
565565
566- uint64_t va = getPartition ().ehFrameHdr ->getVA ();
566+ uint64_t va = getPartition (ctx ).ehFrameHdr ->getVA ();
567567 for (CieRecord *rec : cieRecords) {
568568 uint8_t enc = getFdeEncoding (rec->cie );
569569 for (EhSectionPiece *fde : rec->fdes ) {
@@ -650,8 +650,8 @@ void EhFrameSection::writeTo(uint8_t *buf) {
650650 for (EhInputSection *s : sections)
651651 ctx.target ->relocateAlloc (*s, buf);
652652
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 ();
655655}
656656
657657GotSection::GotSection (Ctx &ctx)
@@ -1325,7 +1325,7 @@ static uint64_t addPltRelSz(Ctx &ctx) { return ctx.in.relaPlt->getSize(); }
13251325template <class ELFT >
13261326std::vector<std::pair<int32_t , uint64_t >>
13271327DynamicSection<ELFT>::computeContents() {
1328- elf::Partition &part = getPartition ();
1328+ elf::Partition &part = getPartition (ctx );
13291329 bool isMain = part.name .empty ();
13301330 std::vector<std::pair<int32_t , uint64_t >> entries;
13311331
@@ -1586,7 +1586,7 @@ DynamicSection<ELFT>::computeContents() {
15861586}
15871587
15881588template <class ELFT > void DynamicSection<ELFT>::finalizeContents() {
1589- if (OutputSection *sec = getPartition ().dynStrTab ->getParent ())
1589+ if (OutputSection *sec = getPartition (ctx ).dynStrTab ->getParent ())
15901590 getParent ()->link = sec->sectionIndex ;
15911591 this ->size = computeContents ().size () * this ->entsize ;
15921592}
@@ -1688,7 +1688,7 @@ void RelocationBaseSection::partitionRels() {
16881688}
16891689
16901690void RelocationBaseSection::finalizeContents () {
1691- SymbolTableBaseSection *symTab = getPartition ().dynSymTab .get ();
1691+ SymbolTableBaseSection *symTab = getPartition (ctx ).dynSymTab .get ();
16921692
16931693 // When linking glibc statically, .rel{,a}.plt contains R_*_IRELATIVE
16941694 // 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) {
17121712}
17131713
17141714void RelocationBaseSection::computeRels () {
1715- SymbolTableBaseSection *symTab = getPartition ().dynSymTab .get ();
1715+ SymbolTableBaseSection *symTab = getPartition (ctx ).dynSymTab .get ();
17161716 parallelForEach (relocs, [&ctx = ctx, symTab](DynamicReloc &rel) {
17171717 rel.computeRaw (ctx, symTab);
17181718 });
@@ -1852,7 +1852,7 @@ bool AndroidPackedRelocationSection<ELFT>::updateAllocSize(Ctx &ctx) {
18521852 for (const DynamicReloc &rel : relocs) {
18531853 Elf_Rela r;
18541854 r.r_offset = rel.getOffset ();
1855- r.setSymbolAndType (rel.getSymIndex (getPartition ().dynSymTab .get ()),
1855+ r.setSymbolAndType (rel.getSymIndex (getPartition (ctx ).dynSymTab .get ()),
18561856 rel.type , false );
18571857 r.r_addend = ctx.arg .isRela ? rel.computeAddend (ctx) : 0 ;
18581858
@@ -2162,9 +2162,9 @@ void SymbolTableBaseSection::finalizeContents() {
21622162 // Because the first symbol entry is a null entry, 1 is the first.
21632163 getParent ()->info = 1 ;
21642164
2165- if (getPartition ().gnuHashTab ) {
2165+ if (getPartition (ctx ).gnuHashTab ) {
21662166 // NB: It also sorts Symbols to meet the GNU hash table requirements.
2167- getPartition ().gnuHashTab ->addSymbols (symbols);
2167+ getPartition (ctx ).gnuHashTab ->addSymbols (symbols);
21682168 } else if (ctx.arg .emachine == EM_MIPS) {
21692169 sortMipsSymbols (ctx, symbols);
21702170 }
@@ -2416,7 +2416,7 @@ GnuHashTableSection::GnuHashTableSection(Ctx &ctx)
24162416 " .gnu.hash" ) {}
24172417
24182418void GnuHashTableSection::finalizeContents () {
2419- if (OutputSection *sec = getPartition ().dynSymTab ->getParent ())
2419+ if (OutputSection *sec = getPartition (ctx ).dynSymTab ->getParent ())
24202420 getParent ()->link = sec->sectionIndex ;
24212421
24222422 // Computes bloom filter size in word size. We want to allocate 12
@@ -2438,7 +2438,7 @@ void GnuHashTableSection::writeTo(uint8_t *buf) {
24382438 // Write a header.
24392439 write32 (ctx, buf, nBuckets);
24402440 write32 (ctx, buf + 4 ,
2441- getPartition ().dynSymTab ->getNumSymbols () - symbols.size ());
2441+ getPartition (ctx ).dynSymTab ->getNumSymbols () - symbols.size ());
24422442 write32 (ctx, buf + 8 , maskWords);
24432443 write32 (ctx, buf + 12 , Shift2);
24442444 buf += 16 ;
@@ -2474,7 +2474,7 @@ void GnuHashTableSection::writeTo(uint8_t *buf) {
24742474 // Write a hash bucket. Hash buckets contain indices in the following hash
24752475 // value table.
24762476 write32 (ctx, buckets + i->bucketIdx ,
2477- getPartition ().dynSymTab ->getSymbolIndex (*i->sym ));
2477+ getPartition (ctx ).dynSymTab ->getSymbolIndex (*i->sym ));
24782478 oldBucket = i->bucketIdx ;
24792479 }
24802480}
@@ -2527,7 +2527,7 @@ HashTableSection::HashTableSection(Ctx &ctx)
25272527}
25282528
25292529void HashTableSection::finalizeContents () {
2530- SymbolTableBaseSection *symTab = getPartition ().dynSymTab .get ();
2530+ SymbolTableBaseSection *symTab = getPartition (ctx ).dynSymTab .get ();
25312531
25322532 if (OutputSection *sec = symTab->getParent ())
25332533 getParent ()->link = sec->sectionIndex ;
@@ -2541,7 +2541,7 @@ void HashTableSection::finalizeContents() {
25412541}
25422542
25432543void HashTableSection::writeTo (uint8_t *buf) {
2544- SymbolTableBaseSection *symTab = getPartition ().dynSymTab .get ();
2544+ SymbolTableBaseSection *symTab = getPartition (ctx ).dynSymTab .get ();
25452545 unsigned numSymbols = symTab->getNumSymbols ();
25462546
25472547 uint32_t *p = reinterpret_cast <uint32_t *>(buf);
@@ -3667,14 +3667,14 @@ void EhFrameHeader::writeTo(uint8_t *buf) {
36673667void EhFrameHeader::write () {
36683668 uint8_t *buf = ctx.bufferStart + getParent ()->offset + outSecOff;
36693669 using FdeData = EhFrameSection::FdeData;
3670- SmallVector<FdeData, 0 > fdes = getPartition ().ehFrame ->getFdeData ();
3670+ SmallVector<FdeData, 0 > fdes = getPartition (ctx ).ehFrame ->getFdeData ();
36713671
36723672 buf[0 ] = 1 ;
36733673 buf[1 ] = DW_EH_PE_pcrel | DW_EH_PE_sdata4;
36743674 buf[2 ] = DW_EH_PE_udata4;
36753675 buf[3 ] = DW_EH_PE_datarel | DW_EH_PE_sdata4;
36763676 write32 (ctx, buf + 4 ,
3677- getPartition ().ehFrame ->getParent ()->addr - this ->getVA () - 4 );
3677+ getPartition (ctx ).ehFrame ->getParent ()->addr - this ->getVA () - 4 );
36783678 write32 (ctx, buf + 8 , fdes.size ());
36793679 buf += 12 ;
36803680
@@ -3687,31 +3687,31 @@ void EhFrameHeader::write() {
36873687
36883688size_t EhFrameHeader::getSize () const {
36893689 // .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 ;
36913691}
36923692
36933693bool EhFrameHeader::isNeeded () const {
3694- return isLive () && getPartition ().ehFrame ->isNeeded ();
3694+ return isLive () && getPartition (ctx ).ehFrame ->isNeeded ();
36953695}
36963696
36973697VersionDefinitionSection::VersionDefinitionSection (Ctx &ctx)
36983698 : SyntheticSection(ctx, SHF_ALLOC, SHT_GNU_verdef, sizeof (uint32_t ),
36993699 ".gnu.version_d") {}
37003700
37013701StringRef VersionDefinitionSection::getFileDefName () {
3702- if (!getPartition ().name .empty ())
3703- return getPartition ().name ;
3702+ if (!getPartition (ctx ).name .empty ())
3703+ return getPartition (ctx ).name ;
37043704 if (!ctx.arg .soName .empty ())
37053705 return ctx.arg .soName ;
37063706 return ctx.arg .outputFile ;
37073707}
37083708
37093709void VersionDefinitionSection::finalizeContents () {
3710- fileDefNameOff = getPartition ().dynStrTab ->addString (getFileDefName ());
3710+ fileDefNameOff = getPartition (ctx ).dynStrTab ->addString (getFileDefName ());
37113711 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 ));
37133713
3714- if (OutputSection *sec = getPartition ().dynStrTab ->getParent ())
3714+ if (OutputSection *sec = getPartition (ctx ).dynStrTab ->getParent ())
37153715 getParent ()->link = sec->sectionIndex ;
37163716
37173717 // sh_info should be set to the number of definitions. This fact is missed in
@@ -3765,16 +3765,16 @@ VersionTableSection::VersionTableSection(Ctx &ctx)
37653765void VersionTableSection::finalizeContents () {
37663766 // At the moment of june 2016 GNU docs does not mention that sh_link field
37673767 // 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 ;
37693769}
37703770
37713771size_t VersionTableSection::getSize () const {
3772- return (getPartition ().dynSymTab ->getSymbols ().size () + 1 ) * 2 ;
3772+ return (getPartition (ctx ).dynSymTab ->getSymbols ().size () + 1 ) * 2 ;
37733773}
37743774
37753775void VersionTableSection::writeTo (uint8_t *buf) {
37763776 buf += 2 ;
3777- for (const SymbolTableEntry &s : getPartition ().dynSymTab ->getSymbols ()) {
3777+ for (const SymbolTableEntry &s : getPartition (ctx ).dynSymTab ->getSymbols ()) {
37783778 // For an unextracted lazy symbol (undefined weak), it must have been
37793779 // converted to Undefined and have VER_NDX_GLOBAL version here.
37803780 assert (!s.sym ->isLazy ());
@@ -3785,7 +3785,7 @@ void VersionTableSection::writeTo(uint8_t *buf) {
37853785
37863786bool VersionTableSection::isNeeded () const {
37873787 return isLive () &&
3788- (getPartition ().verDef || getPartition ().verNeed ->isNeeded ());
3788+ (getPartition (ctx ).verDef || getPartition (ctx ).verNeed ->isNeeded ());
37893789}
37903790
37913791void elf::addVerneed (Ctx &ctx, Symbol &ss) {
@@ -3817,7 +3817,7 @@ template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents() {
38173817 continue ;
38183818 verneeds.emplace_back ();
38193819 Verneed &vn = verneeds.back ();
3820- vn.nameStrTab = getPartition ().dynStrTab ->addString (f->soName );
3820+ vn.nameStrTab = getPartition (ctx ).dynStrTab ->addString (f->soName );
38213821 bool isLibc = ctx.arg .relrGlibc && f->soName .starts_with (" libc.so." );
38223822 bool isGlibc2 = false ;
38233823 for (unsigned i = 0 ; i != f->vernauxs .size (); ++i) {
@@ -3829,17 +3829,17 @@ template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents() {
38293829 if (isLibc && ver.starts_with (" GLIBC_2." ))
38303830 isGlibc2 = true ;
38313831 vn.vernauxs .push_back ({verdef->vd_hash , f->vernauxs [i],
3832- getPartition ().dynStrTab ->addString (ver)});
3832+ getPartition (ctx ).dynStrTab ->addString (ver)});
38333833 }
38343834 if (isGlibc2) {
38353835 const char *ver = " GLIBC_ABI_DT_RELR" ;
38363836 vn.vernauxs .push_back ({hashSysV (ver),
38373837 ++SharedFile::vernauxNum + getVerDefNum (ctx),
3838- getPartition ().dynStrTab ->addString (ver)});
3838+ getPartition (ctx ).dynStrTab ->addString (ver)});
38393839 }
38403840 }
38413841
3842- if (OutputSection *sec = getPartition ().dynStrTab ->getParent ())
3842+ if (OutputSection *sec = getPartition (ctx ).dynStrTab ->getParent ())
38433843 getParent ()->link = sec->sectionIndex ;
38443844 getParent ()->info = verneeds.size ();
38453845}
@@ -3995,7 +3995,7 @@ template <class ELFT> void elf::splitSections(Ctx &ctx) {
39953995void elf::combineEhSections (Ctx &ctx) {
39963996 llvm::TimeTraceScope timeScope (" Combine EH sections" );
39973997 for (EhInputSection *sec : ctx.ehInputSections ) {
3998- EhFrameSection &eh = *sec->getPartition ().ehFrame ;
3998+ EhFrameSection &eh = *sec->getPartition (ctx ).ehFrame ;
39993999 sec->parent = &eh;
40004000 eh.addralign = std::max (eh.addralign , sec->addralign );
40014001 eh.sections .push_back (sec);
@@ -4004,12 +4004,12 @@ void elf::combineEhSections(Ctx &ctx) {
40044004
40054005 if (!ctx.mainPart ->armExidx )
40064006 return ;
4007- llvm::erase_if (ctx.inputSections , [](InputSectionBase *s) {
4007+ llvm::erase_if (ctx.inputSections , [& ](InputSectionBase *s) {
40084008 // Ignore dead sections and the partition end marker (.part.end),
40094009 // whose partition number is out of bounds.
40104010 if (!s->isLive () || s->partition == 255 )
40114011 return false ;
4012- Partition &part = s->getPartition ();
4012+ Partition &part = s->getPartition (ctx );
40134013 return s->kind () == SectionBase::Regular && part.armExidx &&
40144014 part.armExidx ->addSection (cast<InputSection>(s));
40154015 });
@@ -4447,7 +4447,7 @@ size_t PartitionElfHeaderSection<ELFT>::getSize() const {
44474447
44484448template <typename ELFT>
44494449void PartitionElfHeaderSection<ELFT>::writeTo(uint8_t *buf) {
4450- writeEhdr<ELFT>(ctx, buf, getPartition ());
4450+ writeEhdr<ELFT>(ctx, buf, getPartition (ctx ));
44514451
44524452 // Loadable partitions are always ET_DYN.
44534453 auto *eHdr = reinterpret_cast <typename ELFT::Ehdr *>(buf);
@@ -4460,12 +4460,12 @@ PartitionProgramHeadersSection<ELFT>::PartitionProgramHeadersSection(Ctx &ctx)
44604460
44614461template <typename ELFT>
44624462size_t PartitionProgramHeadersSection<ELFT>::getSize() const {
4463- return sizeof (typename ELFT::Phdr) * getPartition ().phdrs .size ();
4463+ return sizeof (typename ELFT::Phdr) * getPartition (ctx ).phdrs .size ();
44644464}
44654465
44664466template <typename ELFT>
44674467void PartitionProgramHeadersSection<ELFT>::writeTo(uint8_t *buf) {
4468- writePhdrs<ELFT>(buf, getPartition ());
4468+ writePhdrs<ELFT>(buf, getPartition (ctx ));
44694469}
44704470
44714471PartitionIndexSection::PartitionIndexSection (Ctx &ctx)
@@ -4747,7 +4747,7 @@ template <class ELFT> void elf::createSyntheticSections(Ctx &ctx) {
47474747 const unsigned threadCount = ctx.arg .threadCount ;
47484748 for (Partition &part : ctx.partitions ) {
47494749 auto add = [&](SyntheticSection &sec) {
4750- sec.partition = part.getNumber ();
4750+ sec.partition = part.getNumber (ctx );
47514751 ctx.inputSections .push_back (&sec);
47524752 };
47534753
0 commit comments