[PATCH] ld: Estimate output section layout before sizing dynamic sections
H.J. Lu
hjl.tools@gmail.com
Sun Feb 2 23:34:01 GMT 2025
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?
> > The linker created sections are excluded when estimating
> > output section layout as sizing dynamic sections may change linker
> > created sections.
>
> This logic also ought to go in the x86 backend to handle whatever
> peculiarities are necessary for x86 linker created sections.
I will drop this change.
> --
> Alan Modra
--
H.J.
More information about the Binutils
mailing list