@@ -63,7 +63,7 @@ static uint64_t readUint(Ctx &ctx, uint8_t *buf) {
6363 return ctx.arg .is64 ? read64 (buf) : read32 (buf);
6464}
6565
66- static void writeUint (uint8_t *buf, uint64_t val) {
66+ static void writeUint (Ctx &ctx, uint8_t *buf, uint64_t val) {
6767 if (ctx.arg .is64 )
6868 write64 (buf, val);
6969 else
@@ -264,7 +264,7 @@ MipsReginfoSection<ELFT>::create(Ctx &ctx) {
264264 return std::make_unique<MipsReginfoSection<ELFT>>(ctx, reginfo);
265265}
266266
267- InputSection *elf::createInterpSection (Ctx &) {
267+ InputSection *elf::createInterpSection (Ctx &ctx ) {
268268 // StringSaver guarantees that the returned string ends with '\0'.
269269 StringRef s = saver ().save (ctx.arg .dynamicLinker );
270270 ArrayRef<uint8_t > contents = {(const uint8_t *)s.data (), s.size () + 1 };
@@ -273,8 +273,9 @@ InputSection *elf::createInterpSection(Ctx &) {
273273 contents, " .interp" );
274274}
275275
276- Defined *elf::addSyntheticLocal (StringRef name, uint8_t type, uint64_t value,
277- uint64_t size, InputSectionBase §ion) {
276+ Defined *elf::addSyntheticLocal (Ctx &ctx, StringRef name, uint8_t type,
277+ uint64_t value, uint64_t size,
278+ InputSectionBase §ion) {
278279 Defined *s = makeDefined (section.file , name, STB_LOCAL, STV_DEFAULT, type,
279280 value, size, §ion);
280281 if (ctx.in .symTab )
@@ -1117,13 +1118,14 @@ void MipsGotSection::writeTo(uint8_t *buf) {
11171118 // we've been doing this for years, it is probably a safe bet to
11181119 // keep doing this for now. We really need to revisit this to see
11191120 // if we had to do this.
1120- writeUint (buf + ctx.arg .wordsize , (uint64_t )1 << (ctx.arg .wordsize * 8 - 1 ));
1121+ writeUint (ctx, buf + ctx.arg .wordsize ,
1122+ (uint64_t )1 << (ctx.arg .wordsize * 8 - 1 ));
11211123 for (const FileGot &g : gots) {
11221124 auto write = [&](size_t i, const Symbol *s, int64_t a) {
11231125 uint64_t va = a;
11241126 if (s)
11251127 va = s->getVA (a);
1126- writeUint (buf + i * ctx.arg .wordsize , va);
1128+ writeUint (ctx, buf + i * ctx.arg .wordsize , va);
11271129 };
11281130 // Write 'page address' entries to the local part of the GOT.
11291131 for (const std::pair<const OutputSection *, FileGot::PageBlock> &l :
@@ -1304,7 +1306,7 @@ DynamicSection<ELFT>::DynamicSection(Ctx &ctx)
13041306// .rela.dyn
13051307//
13061308// DT_RELASZ is the total size of the included sections.
1307- static uint64_t addRelaSz (const RelocationBaseSection &relaDyn) {
1309+ static uint64_t addRelaSz (Ctx &ctx, const RelocationBaseSection &relaDyn) {
13081310 size_t size = relaDyn.getSize ();
13091311 if (ctx.in .relaPlt ->getParent () == relaDyn.getParent ())
13101312 size += ctx.in .relaPlt ->getSize ();
@@ -1315,7 +1317,7 @@ static uint64_t addRelaSz(const RelocationBaseSection &relaDyn) {
13151317// output section. When this occurs we cannot just use the OutputSection
13161318// Size. Moreover the [DT_JMPREL, DT_JMPREL + DT_PLTRELSZ) is permitted to
13171319// overlap with the [DT_RELA, DT_RELA + DT_RELASZ).
1318- static uint64_t addPltRelSz () { return ctx.in .relaPlt ->getSize (); }
1320+ static uint64_t addPltRelSz (Ctx &ctx ) { return ctx.in .relaPlt ->getSize (); }
13191321
13201322// Add remaining entries to complete .dynamic contents.
13211323template <class ELFT >
@@ -1405,7 +1407,7 @@ DynamicSection<ELFT>::computeContents() {
14051407 if (part.relaDyn ->isNeeded ()) {
14061408 addInSec (part.relaDyn ->dynamicTag , *part.relaDyn );
14071409 entries.emplace_back (part.relaDyn ->sizeDynamicTag ,
1408- addRelaSz (*part.relaDyn ));
1410+ addRelaSz (ctx, *part.relaDyn ));
14091411
14101412 bool isRela = ctx.arg .isRela ;
14111413 addInt (isRela ? DT_RELAENT : DT_RELENT,
@@ -1437,7 +1439,7 @@ DynamicSection<ELFT>::computeContents() {
14371439 }
14381440 if (isMain && ctx.in .relaPlt ->isNeeded ()) {
14391441 addInSec (DT_JMPREL, *ctx.in .relaPlt );
1440- entries.emplace_back (DT_PLTRELSZ, addPltRelSz ());
1442+ entries.emplace_back (DT_PLTRELSZ, addPltRelSz (ctx ));
14411443 switch (ctx.arg .emachine ) {
14421444 case EM_MIPS:
14431445 addInSec (DT_MIPS_PLTGOT, *ctx.in .gotPlt );
@@ -2126,15 +2128,18 @@ SymbolTableBaseSection::SymbolTableBaseSection(Ctx &ctx,
21262128// See "Global Offset Table" in Chapter 5 in the following document
21272129// for detailed description:
21282130// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
2129- static bool sortMipsSymbols (const SymbolTableEntry &l,
2130- const SymbolTableEntry &r) {
2131- // Sort entries related to non-local preemptible symbols by GOT indexes.
2132- // All other entries go to the beginning of a dynsym in arbitrary order.
2133- if (l.sym ->isInGot (ctx) && r.sym ->isInGot (ctx))
2134- return l.sym ->getGotIdx (ctx) < r.sym ->getGotIdx (ctx);
2135- if (!l.sym ->isInGot (ctx) && !r.sym ->isInGot (ctx))
2136- return false ;
2137- return !l.sym ->isInGot (ctx);
2131+ static void sortMipsSymbols (Ctx &ctx, SmallVector<SymbolTableEntry, 0 > &syms) {
2132+ llvm::stable_sort (syms,
2133+ [&](const SymbolTableEntry &l, const SymbolTableEntry &r) {
2134+ // Sort entries related to non-local preemptible symbols
2135+ // by GOT indexes. All other entries go to the beginning
2136+ // of a dynsym in arbitrary order.
2137+ if (l.sym ->isInGot (ctx) && r.sym ->isInGot (ctx))
2138+ return l.sym ->getGotIdx (ctx) < r.sym ->getGotIdx (ctx);
2139+ if (!l.sym ->isInGot (ctx) && !r.sym ->isInGot (ctx))
2140+ return false ;
2141+ return !l.sym ->isInGot (ctx);
2142+ });
21382143}
21392144
21402145void SymbolTableBaseSection::finalizeContents () {
@@ -2157,7 +2162,7 @@ void SymbolTableBaseSection::finalizeContents() {
21572162 // NB: It also sorts Symbols to meet the GNU hash table requirements.
21582163 getPartition ().gnuHashTab ->addSymbols (symbols);
21592164 } else if (ctx.arg .emachine == EM_MIPS) {
2160- llvm::stable_sort (symbols, sortMipsSymbols );
2165+ sortMipsSymbols (ctx, symbols );
21612166 }
21622167
21632168 // Only the main partition's dynsym indexes are stored in the symbols
@@ -2440,7 +2445,7 @@ void GnuHashTableSection::writeTo(uint8_t *buf) {
24402445 uint64_t val = readUint (ctx, buf + i * ctx.arg .wordsize );
24412446 val |= uint64_t (1 ) << (sym.hash % c);
24422447 val |= uint64_t (1 ) << ((sym.hash >> Shift2) % c);
2443- writeUint (buf + i * ctx.arg .wordsize , val);
2448+ writeUint (ctx, buf + i * ctx.arg .wordsize , val);
24442449 }
24452450 buf += ctx.arg .wordsize * maskWords;
24462451
0 commit comments