@@ -78,7 +78,7 @@ OutputSection::OutputSection(StringRef name, uint32_t type, uint64_t flags)
78
78
//
79
79
// NOTE: clang since rL252300 emits SHT_X86_64_UNWIND .eh_frame sections. Allow
80
80
// them to be merged into SHT_PROGBITS .eh_frame (GNU as .cfi_*).
81
- static bool canMergeToProgbits (unsigned type) {
81
+ static bool canMergeToProgbits (Ctx &ctx, unsigned type) {
82
82
return type == SHT_NOBITS || type == SHT_PROGBITS || type == SHT_INIT_ARRAY ||
83
83
type == SHT_PREINIT_ARRAY || type == SHT_FINI_ARRAY ||
84
84
type == SHT_NOTE ||
@@ -105,7 +105,7 @@ void OutputSection::recordSection(InputSectionBase *isec) {
105
105
// Update fields (type, flags, alignment, etc) according to the InputSection
106
106
// isec. Also check whether the InputSection flags and type are consistent with
107
107
// other InputSections.
108
- void OutputSection::commitSection (InputSection *isec) {
108
+ void OutputSection::commitSection (Ctx &ctx, InputSection *isec) {
109
109
if (LLVM_UNLIKELY (type != isec->type )) {
110
110
if (!hasInputSections && !typeIsSet) {
111
111
type = isec->type ;
@@ -120,8 +120,8 @@ void OutputSection::commitSection(InputSection *isec) {
120
120
name = saver ().save (" .crel" + name);
121
121
}
122
122
} else {
123
- if (typeIsSet || !canMergeToProgbits (type) ||
124
- !canMergeToProgbits (isec->type )) {
123
+ if (typeIsSet || !canMergeToProgbits (ctx, type) ||
124
+ !canMergeToProgbits (ctx, isec->type )) {
125
125
// The (NOLOAD) changes the section type to SHT_NOBITS, the intention is
126
126
// that the contents at that address is provided by some other means.
127
127
// Some projects (e.g.
@@ -172,7 +172,7 @@ void OutputSection::commitSection(InputSection *isec) {
172
172
entsize = 0 ;
173
173
}
174
174
175
- static MergeSyntheticSection *createMergeSynthetic (StringRef name,
175
+ static MergeSyntheticSection *createMergeSynthetic (Ctx &ctx, StringRef name,
176
176
uint32_t type,
177
177
uint64_t flags,
178
178
uint32_t addralign) {
@@ -188,7 +188,8 @@ static MergeSyntheticSection *createMergeSynthetic(StringRef name,
188
188
// new synthetic sections at the location of the first input section
189
189
// that it replaces. It then finalizes each synthetic section in order
190
190
// to compute an output offset for each piece of each input section.
191
- void OutputSection::finalizeInputSections (LinkerScript *script) {
191
+ void OutputSection::finalizeInputSections (Ctx &ctx) {
192
+ auto *script = ctx.script ;
192
193
std::vector<MergeSyntheticSection *> mergeSections;
193
194
for (SectionCommand *cmd : commands) {
194
195
auto *isd = dyn_cast<InputSectionDescription>(cmd);
@@ -222,8 +223,8 @@ void OutputSection::finalizeInputSections(LinkerScript *script) {
222
223
(sec->addralign == ms->addralign || !(sec->flags & SHF_STRINGS));
223
224
});
224
225
if (i == mergeSections.end ()) {
225
- MergeSyntheticSection *syn =
226
- createMergeSynthetic ( s->name , ms->type , ms->flags , ms->addralign );
226
+ MergeSyntheticSection *syn = createMergeSynthetic (
227
+ ctx, s->name , ms->type , ms->flags , ms->addralign );
227
228
mergeSections.push_back (syn);
228
229
i = std::prev (mergeSections.end ());
229
230
syn->entsize = ms->entsize ;
@@ -243,7 +244,7 @@ void OutputSection::finalizeInputSections(LinkerScript *script) {
243
244
244
245
// Some input sections may be removed from the list after ICF.
245
246
for (InputSection *s : isd->sections )
246
- commitSection (s);
247
+ commitSection (ctx, s);
247
248
}
248
249
for (auto *ms : mergeSections)
249
250
ms->finalizeContents ();
@@ -260,7 +261,7 @@ static void sortByOrder(MutableArrayRef<InputSection *> in,
260
261
in[i] = v[i].second ;
261
262
}
262
263
263
- uint64_t elf::getHeaderSize () {
264
+ uint64_t elf::getHeaderSize (Ctx &ctx ) {
264
265
if (ctx.arg .oFormatBinary )
265
266
return 0 ;
266
267
return ctx.out .elfHeader ->size + ctx.out .programHeaders ->size ;
@@ -273,7 +274,7 @@ void OutputSection::sort(llvm::function_ref<int(InputSectionBase *s)> order) {
273
274
sortByOrder (isd->sections , order);
274
275
}
275
276
276
- static void nopInstrFill (uint8_t *buf, size_t size) {
277
+ static void nopInstrFill (Ctx &ctx, uint8_t *buf, size_t size) {
277
278
if (size == 0 )
278
279
return ;
279
280
unsigned i = 0 ;
@@ -341,7 +342,7 @@ static SmallVector<uint8_t, 0> deflateShard(ArrayRef<uint8_t> in, int level,
341
342
//
342
343
// * (if --compress-debug-sections is specified) non-empty .debug_* sections
343
344
// * (if --compress-sections is specified) matched sections
344
- template <class ELFT > void OutputSection::maybeCompress () {
345
+ template <class ELFT > void OutputSection::maybeCompress (Ctx &ctx ) {
345
346
using Elf_Chdr = typename ELFT::Chdr;
346
347
(void )sizeof (Elf_Chdr);
347
348
@@ -507,7 +508,7 @@ void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
507
508
508
509
// Write leading padding.
509
510
ArrayRef<InputSection *> sections = getInputSections (*this , storage);
510
- std::array<uint8_t , 4 > filler = getFiller ();
511
+ std::array<uint8_t , 4 > filler = getFiller (ctx );
511
512
bool nonZeroFiller = read32 (filler.data ()) != 0 ;
512
513
if (nonZeroFiller)
513
514
fill (buf, sections.empty () ? size : sections[0 ]->outSecOff , filler);
@@ -543,7 +544,7 @@ void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
543
544
end = buf + sections[i + 1 ]->outSecOff ;
544
545
if (isec->nopFiller ) {
545
546
assert (ctx.target ->nopInstrs );
546
- nopInstrFill (start, end - start);
547
+ nopInstrFill (ctx, start, end - start);
547
548
} else
548
549
fill (start, end - start, filler);
549
550
}
@@ -582,7 +583,8 @@ void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
582
583
}
583
584
}
584
585
585
- static void finalizeShtGroup (OutputSection *os, InputSection *section) {
586
+ static void finalizeShtGroup (Ctx &ctx, OutputSection *os,
587
+ InputSection *section) {
586
588
// sh_link field for SHT_GROUP sections should contain the section index of
587
589
// the symbol table.
588
590
os->link = ctx.in .symTab ->getParent ()->sectionIndex ;
@@ -668,7 +670,7 @@ static size_t relToCrel(raw_svector_ostream &os, Elf_Crel<ELFT::Is64Bits> &out,
668
670
669
671
// Compute the content of a non-alloc CREL section due to -r or --emit-relocs.
670
672
// Input CREL sections are decoded while REL[A] need to be converted.
671
- template <bool is64> void OutputSection::finalizeNonAllocCrel () {
673
+ template <bool is64> void OutputSection::finalizeNonAllocCrel (Ctx &ctx ) {
672
674
using uint = typename Elf_Crel_Impl<is64>::uint;
673
675
raw_svector_ostream os (crelBody);
674
676
uint64_t totalCount = 0 ;
@@ -702,7 +704,7 @@ template <bool is64> void OutputSection::finalizeNonAllocCrel() {
702
704
size = getULEB128Size (crelHeader) + crelBody.size ();
703
705
}
704
706
705
- void OutputSection::finalize () {
707
+ void OutputSection::finalize (Ctx &ctx ) {
706
708
InputSection *first = getFirstInputSection (this );
707
709
708
710
if (flags & SHF_LINK_ORDER) {
@@ -718,7 +720,7 @@ void OutputSection::finalize() {
718
720
}
719
721
720
722
if (type == SHT_GROUP) {
721
- finalizeShtGroup (this , first);
723
+ finalizeShtGroup (ctx, this , first);
722
724
return ;
723
725
}
724
726
@@ -741,9 +743,9 @@ void OutputSection::finalize() {
741
743
// Finalize the content of non-alloc CREL.
742
744
if (type == SHT_CREL) {
743
745
if (ctx.arg .is64 )
744
- finalizeNonAllocCrel<true >();
746
+ finalizeNonAllocCrel<true >(ctx );
745
747
else
746
- finalizeNonAllocCrel<false >();
748
+ finalizeNonAllocCrel<false >(ctx );
747
749
}
748
750
}
749
751
@@ -854,15 +856,15 @@ void OutputSection::sortInitFini() {
854
856
sort ([](InputSectionBase *s) { return getPriority (s->name ); });
855
857
}
856
858
857
- std::array<uint8_t , 4 > OutputSection::getFiller () {
859
+ std::array<uint8_t , 4 > OutputSection::getFiller (Ctx &ctx ) {
858
860
if (filler)
859
861
return *filler;
860
862
if (flags & SHF_EXECINSTR)
861
863
return ctx.target ->trapInstr ;
862
864
return {0 , 0 , 0 , 0 };
863
865
}
864
866
865
- void OutputSection::checkDynRelAddends (const uint8_t *bufStart ) {
867
+ void OutputSection::checkDynRelAddends (Ctx &ctx ) {
866
868
assert (ctx.arg .writeAddends && ctx.arg .checkDynamicRelocs );
867
869
assert (isStaticRelSecType (type));
868
870
SmallVector<InputSection *, 0 > storage;
@@ -885,8 +887,8 @@ void OutputSection::checkDynRelAddends(const uint8_t *bufStart) {
885
887
(rel.inputSec == ctx.in .ppc64LongBranchTarget .get () ||
886
888
rel.inputSec == ctx.in .igotPlt .get ()))
887
889
continue ;
888
- const uint8_t *relocTarget =
889
- bufStart + relOsec-> offset + rel.inputSec ->getOffset (rel.offsetInSec );
890
+ const uint8_t *relocTarget = ctx. bufferStart + relOsec-> offset +
891
+ rel.inputSec ->getOffset (rel.offsetInSec );
890
892
// For SHT_NOBITS the written addend is always zero.
891
893
int64_t writtenAddend =
892
894
relOsec->type == SHT_NOBITS
@@ -918,7 +920,7 @@ template void OutputSection::writeTo<ELF64LE>(uint8_t *,
918
920
template void OutputSection::writeTo<ELF64BE>(uint8_t *,
919
921
llvm::parallel::TaskGroup &);
920
922
921
- template void OutputSection::maybeCompress<ELF32LE>();
922
- template void OutputSection::maybeCompress<ELF32BE>();
923
- template void OutputSection::maybeCompress<ELF64LE>();
924
- template void OutputSection::maybeCompress<ELF64BE>();
923
+ template void OutputSection::maybeCompress<ELF32LE>(Ctx & );
924
+ template void OutputSection::maybeCompress<ELF32BE>(Ctx & );
925
+ template void OutputSection::maybeCompress<ELF64LE>(Ctx & );
926
+ template void OutputSection::maybeCompress<ELF64BE>(Ctx & );
0 commit comments