@@ -213,32 +213,35 @@ void elf::addReservedSymbols(Ctx &ctx) {
213213
214214 s->resolve (ctx, Defined{ctx, ctx.internalFile , StringRef (), STB_GLOBAL,
215215 STV_HIDDEN, STT_NOTYPE, gotOff, /* size=*/ 0 ,
216- ctx.out .elfHeader });
216+ ctx.out .elfHeader . get () });
217217 ctx.sym .globalOffsetTable = cast<Defined>(s);
218218 }
219219
220220 // __ehdr_start is the location of ELF file headers. Note that we define
221221 // this symbol unconditionally even when using a linker script, which
222222 // differs from the behavior implemented by GNU linker which only define
223223 // this symbol if ELF headers are in the memory mapped segment.
224- addOptionalRegular (ctx, " __ehdr_start" , ctx.out .elfHeader , 0 , STV_HIDDEN);
224+ addOptionalRegular (ctx, " __ehdr_start" , ctx.out .elfHeader .get (), 0 ,
225+ STV_HIDDEN);
225226
226227 // __executable_start is not documented, but the expectation of at
227228 // least the Android libc is that it points to the ELF header.
228- addOptionalRegular (ctx, " __executable_start" , ctx.out .elfHeader , 0 ,
229+ addOptionalRegular (ctx, " __executable_start" , ctx.out .elfHeader . get () , 0 ,
229230 STV_HIDDEN);
230231
231232 // __dso_handle symbol is passed to cxa_finalize as a marker to identify
232233 // each DSO. The address of the symbol doesn't matter as long as they are
233234 // different in different DSOs, so we chose the start address of the DSO.
234- addOptionalRegular (ctx, " __dso_handle" , ctx.out .elfHeader , 0 , STV_HIDDEN);
235+ addOptionalRegular (ctx, " __dso_handle" , ctx.out .elfHeader .get (), 0 ,
236+ STV_HIDDEN);
235237
236238 // If linker script do layout we do not need to create any standard symbols.
237239 if (ctx.script ->hasSectionsCommand )
238240 return ;
239241
240242 auto add = [&](StringRef s, int64_t pos) {
241- return addOptionalRegular (ctx, s, ctx.out .elfHeader , pos, STV_DEFAULT);
243+ return addOptionalRegular (ctx, s, ctx.out .elfHeader .get (), pos,
244+ STV_DEFAULT);
242245 };
243246
244247 ctx.sym .bss = add (" __bss_start" , 0 );
@@ -815,10 +818,10 @@ template <class ELFT> void Writer<ELFT>::addRelIpltSymbols() {
815818 // .rela.dyn will be present in the output.
816819 std::string name = ctx.arg .isRela ? " __rela_iplt_start" : " __rel_iplt_start" ;
817820 ctx.sym .relaIpltStart =
818- addOptionalRegular (ctx, name, ctx.out .elfHeader , 0 , STV_HIDDEN);
821+ addOptionalRegular (ctx, name, ctx.out .elfHeader . get () , 0 , STV_HIDDEN);
819822 name.replace (name.size () - 5 , 5 , " end" );
820823 ctx.sym .relaIpltEnd =
821- addOptionalRegular (ctx, name, ctx.out .elfHeader , 0 , STV_HIDDEN);
824+ addOptionalRegular (ctx, name, ctx.out .elfHeader . get () , 0 , STV_HIDDEN);
822825}
823826
824827// This function generates assignments for predefined symbols (e.g. _end or
@@ -1751,7 +1754,8 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
17511754 if (!ctx.arg .shared ) {
17521755 OutputSection *sec = findSection (ctx, " .sdata" );
17531756 addOptionalRegular (ctx, " __global_pointer$" ,
1754- sec ? sec : ctx.out .elfHeader , 0x800 , STV_DEFAULT);
1757+ sec ? sec : ctx.out .elfHeader .get (), 0x800 ,
1758+ STV_DEFAULT);
17551759 // Set riscvGlobalPointer to be used by the optional global pointer
17561760 // relaxation.
17571761 if (ctx.arg .relaxGP ) {
@@ -2128,8 +2132,8 @@ template <class ELFT> void Writer<ELFT>::addStartEndSymbols() {
21282132 if (startSym || stopSym)
21292133 os->usedInExpression = true ;
21302134 } else {
2131- addOptionalRegular (ctx, start, ctx.out .elfHeader , 0 );
2132- addOptionalRegular (ctx, end, ctx.out .elfHeader , 0 );
2135+ addOptionalRegular (ctx, start, ctx.out .elfHeader . get () , 0 );
2136+ addOptionalRegular (ctx, end, ctx.out .elfHeader . get () , 0 );
21332137 }
21342138 };
21352139
@@ -2206,7 +2210,7 @@ SmallVector<PhdrEntry *, 0> Writer<ELFT>::createPhdrs(Partition &part) {
22062210 // The first phdr entry is PT_PHDR which describes the program header
22072211 // itself.
22082212 if (isMain)
2209- addHdr (PT_PHDR, PF_R)->add (ctx.out .programHeaders );
2213+ addHdr (PT_PHDR, PF_R)->add (ctx.out .programHeaders . get () );
22102214 else
22112215 addHdr (PT_PHDR, PF_R)->add (part.programHeaders ->getParent ());
22122216
@@ -2219,8 +2223,8 @@ SmallVector<PhdrEntry *, 0> Writer<ELFT>::createPhdrs(Partition &part) {
22192223 // need to be added here.
22202224 if (isMain) {
22212225 load = addHdr (PT_LOAD, flags);
2222- load->add (ctx.out .elfHeader );
2223- load->add (ctx.out .programHeaders );
2226+ load->add (ctx.out .elfHeader . get () );
2227+ load->add (ctx.out .programHeaders . get () );
22242228 }
22252229 }
22262230
@@ -2292,7 +2296,7 @@ SmallVector<PhdrEntry *, 0> Writer<ELFT>::createPhdrs(Partition &part) {
22922296 load && !sec->lmaExpr && sec->lmaRegion == load->firstSec ->lmaRegion ;
22932297 if (load && sec != relroEnd &&
22942298 sec->memRegion == load->firstSec ->memRegion &&
2295- (sameLMARegion || load->lastSec == ctx.out .programHeaders ) &&
2299+ (sameLMARegion || load->lastSec == ctx.out .programHeaders . get () ) &&
22962300 (ctx.script ->hasSectionsCommand || sec->type == SHT_NOBITS ||
22972301 load->lastSec ->type != SHT_NOBITS)) {
22982302 load->p_flags |= newFlags;
0 commit comments