[PATCH] ld: Estimate output section layout before sizing dynamic sections
Alan Modra
amodra@gmail.com
Mon Feb 3 02:00:49 GMT 2025
On Mon, Feb 03, 2025 at 08:14:59AM +0800, H.J. Lu wrote:
> On Mon, Feb 3, 2025 at 8:05 AM Alan Modra <amodra@gmail.com> wrote:
> >
> > On Mon, Feb 03, 2025 at 07:34:01AM +0800, H.J. Lu wrote:
> > > On Mon, Feb 3, 2025 at 6:29 AM Alan Modra <amodra@gmail.com> wrote:
> > > >
> > > > On Sat, Feb 01, 2025 at 04:53:30PM +0800, H.J. Lu wrote:
> > > > > When sizing dynamic sections, elf_x86_64_scan_relocs converts GOTPCREL
> > > > > relocations to R_X86_64_PC32, R_X86_64_32S or R_X86_64_32 for local
> > > > > symbols. But at that time, since the output section layout is unknown,
> > > > > the local symbol values can't be determined. Later linker issues an
> > > > > error if the converted relocation overflows when resolving relocations
> > > > > against these local symbols. Update the linker so that an ELF target
> > > > > can opt-in to estimate output section layout before sizing dynamic
> > > > > sections.
> > > >
> > > > I think that is the wrong way to go. A single backend_data bit
> > > > controlling prelim sizing is likely not flexible enough. It's far
> > > > better I think to implement an x86 before_allocation override hook
> > > > rather than trying to put the code in ldelf_before_allocation.
> > >
> > > This means that the x86_64 backend needs to duplicate the whole
> > > function so that it can do prelim sizing just before sizing dynamic sections.
> > > It can be easily out of sync when ldelf_before_allocation is changed.
> > > Is there a way to avoid it?
> >
> > Why would you need to duplicate the whole function? Just call it.
> > See emultemp/ppc64elf.em.
>
> It doesn't work for x86-64 since prelim sizing must be done just before
> sizing dynamic sections. How about this
Explain "doesn't work". How do the very few things that happen in
ldelf_before_allocation before the place you want to add another hook,
affect prelim sizing?
--
Alan Modra
More information about the Binutils
mailing list