@@ -479,7 +479,7 @@ static void sortSections(MutableArrayRef<InputSectionBase *> vec,
479479// --sort-section is handled as an inner SORT command.
480480// 3. If one SORT command is given, and if it is SORT_NONE, don't sort.
481481// 4. If no SORT command is given, sort according to --sort-section.
482- static void sortInputSections (MutableArrayRef<InputSectionBase *> vec,
482+ static void sortInputSections (Ctx &ctx, MutableArrayRef<InputSectionBase *> vec,
483483 SortSectionPolicy outer,
484484 SortSectionPolicy inner) {
485485 if (outer == SortSectionPolicy::None)
@@ -517,6 +517,7 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd,
517517 for (size_t i = begin; i != end; ++i)
518518 ret[i] = sections[indexes[i]];
519519 sortInputSections (
520+ ctx,
520521 MutableArrayRef<InputSectionBase *>(ret).slice (begin, end - begin),
521522 ctx.arg .sortSection , SortSectionPolicy::None);
522523 };
@@ -584,6 +585,7 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd,
584585 // ret[sizeBeforeCurrPat,ret.size()) are already in the input order, so we
585586 // just sort by sortOuter and sortInner.
586587 sortInputSections (
588+ ctx,
587589 MutableArrayRef<InputSectionBase *>(ret).slice (sizeBeforeCurrPat),
588590 pat.sortOuter , pat.sortInner );
589591 sizeAfterPrevSort = ret.size ();
@@ -865,7 +867,8 @@ static OutputDesc *createSection(InputSectionBase *isec, StringRef outsecName) {
865867 return osd;
866868}
867869
868- static OutputDesc *addInputSec (StringMap<TinyPtrVector<OutputSection *>> &map,
870+ static OutputDesc *addInputSec (Ctx &ctx,
871+ StringMap<TinyPtrVector<OutputSection *>> &map,
869872 InputSectionBase *isec, StringRef outsecName) {
870873 // Sections with SHT_GROUP or SHF_GROUP attributes reach here only when the -r
871874 // option is given. A section with SHT_GROUP defines a "section group", and
@@ -983,7 +986,7 @@ void LinkerScript::addOrphanSections() {
983986 } else if (OutputSection *sec = findByName (sectionCommands, name)) {
984987 sec->recordSection (s);
985988 } else {
986- if (OutputDesc *osd = addInputSec (map, s, name))
989+ if (OutputDesc *osd = addInputSec (ctx, map, s, name))
987990 v.push_back (osd);
988991 assert (isa<MergeInputSection>(s) ||
989992 s->getOutputSection ()->sectionIndex == UINT32_MAX);
@@ -1114,7 +1117,7 @@ LinkerScript::findMemoryRegion(OutputSection *sec, MemoryRegion *hint) {
11141117 return {nullptr , nullptr };
11151118}
11161119
1117- static OutputSection *findFirstSection (PhdrEntry *load) {
1120+ static OutputSection *findFirstSection (Ctx &ctx, PhdrEntry *load) {
11181121 for (OutputSection *sec : ctx.outputSections )
11191122 if (sec->ptLoad == load)
11201123 return sec;
@@ -1187,7 +1190,7 @@ bool LinkerScript::assignOffsets(OutputSection *sec) {
11871190
11881191 // Propagate state->lmaOffset to the first "non-header" section.
11891192 if (PhdrEntry *l = sec->ptLoad )
1190- if (sec == findFirstSection (l))
1193+ if (sec == findFirstSection (ctx, l))
11911194 l->lmaOffset = state->lmaOffset ;
11921195
11931196 // We can call this method multiple times during the creation of
@@ -1462,7 +1465,7 @@ void LinkerScript::allocateHeaders(SmallVector<PhdrEntry *, 0> &phdrs) {
14621465
14631466 ctx.out .elfHeader ->ptLoad = nullptr ;
14641467 ctx.out .programHeaders ->ptLoad = nullptr ;
1465- firstPTLoad->firstSec = findFirstSection (firstPTLoad);
1468+ firstPTLoad->firstSec = findFirstSection (ctx, firstPTLoad);
14661469
14671470 llvm::erase_if (phdrs,
14681471 [](const PhdrEntry *e) { return e->p_type == PT_PHDR; });
0 commit comments