[PATCH] ld: Estimate output section layout before sizing dynamic sections

Alan Modra amodra@gmail.com
Sun Feb 2 22:29:06 GMT 2025


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.

>  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.

-- 
Alan Modra


More information about the Binutils mailing list