@@ -65,10 +65,12 @@ void OutputSection::writeHeaderTo(typename ELFT::Shdr *shdr) {
6565 shdr->sh_name = shName;
6666}
6767
68- OutputSection::OutputSection (StringRef name, uint32_t type, uint64_t flags)
68+ OutputSection::OutputSection (Ctx &ctx, StringRef name, uint32_t type,
69+ uint64_t flags)
6970 : SectionBase(Output, ctx.internalFile, name, flags, /* entsize=*/ 0 ,
7071 /* addralign=*/ 1 , type,
71- /* info=*/ 0 , /* link=*/ 0 ) {}
72+ /* info=*/ 0 , /* link=*/ 0 ),
73+ ctx(ctx) {}
7274
7375// We allow sections of types listed below to merged into a
7476// single progbits section. This is typically done by linker
@@ -106,7 +108,7 @@ void OutputSection::recordSection(InputSectionBase *isec) {
106108// Update fields (type, flags, alignment, etc) according to the InputSection
107109// isec. Also check whether the InputSection flags and type are consistent with
108110// other InputSections.
109- void OutputSection::commitSection (Ctx &ctx, InputSection *isec) {
111+ void OutputSection::commitSection (InputSection *isec) {
110112 if (LLVM_UNLIKELY (type != isec->type )) {
111113 if (!hasInputSections && !typeIsSet) {
112114 type = isec->type ;
@@ -189,7 +191,7 @@ static MergeSyntheticSection *createMergeSynthetic(Ctx &ctx, StringRef name,
189191// new synthetic sections at the location of the first input section
190192// that it replaces. It then finalizes each synthetic section in order
191193// to compute an output offset for each piece of each input section.
192- void OutputSection::finalizeInputSections (Ctx &ctx ) {
194+ void OutputSection::finalizeInputSections () {
193195 auto *script = ctx.script ;
194196 std::vector<MergeSyntheticSection *> mergeSections;
195197 for (SectionCommand *cmd : commands) {
@@ -245,7 +247,7 @@ void OutputSection::finalizeInputSections(Ctx &ctx) {
245247
246248 // Some input sections may be removed from the list after ICF.
247249 for (InputSection *s : isd->sections )
248- commitSection (ctx, s);
250+ commitSection (s);
249251 }
250252 for (auto *ms : mergeSections)
251253 ms->finalizeContents ();
@@ -610,8 +612,9 @@ static void finalizeShtGroup(Ctx &ctx, OutputSection *os,
610612
611613template <class uint >
612614LLVM_ATTRIBUTE_ALWAYS_INLINE static void
613- encodeOneCrel (raw_svector_ostream &os, Elf_Crel<sizeof (uint) == 8> &out,
614- uint offset, const Symbol &sym, uint32_t type, uint addend) {
615+ encodeOneCrel (Ctx &ctx, raw_svector_ostream &os,
616+ Elf_Crel<sizeof (uint) == 8> &out, uint offset, const Symbol &sym,
617+ uint32_t type, uint addend) {
615618 const auto deltaOffset = static_cast <uint64_t >(offset - out.r_offset );
616619 out.r_offset = offset;
617620 int64_t symidx = ctx.in .symTab ->getSymbolIndex (sym);
@@ -652,8 +655,9 @@ encodeOneCrel(raw_svector_ostream &os, Elf_Crel<sizeof(uint) == 8> &out,
652655}
653656
654657template <class ELFT >
655- static size_t relToCrel (raw_svector_ostream &os, Elf_Crel<ELFT::Is64Bits> &out,
656- InputSection *relSec, InputSectionBase *sec) {
658+ static size_t relToCrel (Ctx &ctx, raw_svector_ostream &os,
659+ Elf_Crel<ELFT::Is64Bits> &out, InputSection *relSec,
660+ InputSectionBase *sec) {
657661 const auto &file = *cast<ELFFileBase>(relSec->file );
658662 if (relSec->type == SHT_REL) {
659663 // REL conversion is complex and unsupported yet.
@@ -663,7 +667,7 @@ static size_t relToCrel(raw_svector_ostream &os, Elf_Crel<ELFT::Is64Bits> &out,
663667 auto rels = relSec->getDataAs <typename ELFT::Rela>();
664668 for (auto rel : rels) {
665669 encodeOneCrel<typename ELFT::uint>(
666- os, out, sec->getVA (rel.r_offset ), file.getRelocTargetSym (rel),
670+ ctx, os, out, sec->getVA (rel.r_offset ), file.getRelocTargetSym (rel),
667671 rel.getType (ctx.arg .isMips64EL ), getAddend<ELFT>(rel));
668672 }
669673 return rels.size ();
@@ -685,19 +689,21 @@ template <bool is64> void OutputSection::finalizeNonAllocCrel(Ctx &ctx) {
685689 RelocsCrel<is64> entries (relSec->content_ );
686690 totalCount += entries.size ();
687691 for (Elf_Crel_Impl<is64> r : entries) {
688- encodeOneCrel<uint>(os, out, uint (sec->getVA (r.r_offset )),
692+ encodeOneCrel<uint>(ctx, os, out, uint (sec->getVA (r.r_offset )),
689693 file.getSymbol (r.r_symidx ), r.r_type , r.r_addend );
690694 }
691695 continue ;
692696 }
693697
694698 // Convert REL[A] to CREL.
695699 if constexpr (is64) {
696- totalCount += ctx.arg .isLE ? relToCrel<ELF64LE>(os, out, relSec, sec)
697- : relToCrel<ELF64BE>(os, out, relSec, sec);
700+ totalCount += ctx.arg .isLE
701+ ? relToCrel<ELF64LE>(ctx, os, out, relSec, sec)
702+ : relToCrel<ELF64BE>(ctx, os, out, relSec, sec);
698703 } else {
699- totalCount += ctx.arg .isLE ? relToCrel<ELF32LE>(os, out, relSec, sec)
700- : relToCrel<ELF32BE>(os, out, relSec, sec);
704+ totalCount += ctx.arg .isLE
705+ ? relToCrel<ELF32LE>(ctx, os, out, relSec, sec)
706+ : relToCrel<ELF32BE>(ctx, os, out, relSec, sec);
701707 }
702708 }
703709
0 commit comments