[PATCH v2] x86-64: Estimate output section layout before sizing dynamic sections

H.J. Lu hjl.tools@gmail.com
Mon Feb 3 08:51:51 GMT 2025


On Mon, Feb 3, 2025 at 3:24 PM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 03.02.2025 02:50, 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 ldelf_before_allocation to take
> > a function pointer argument and run it before sizing dynamic sections
> > if it isn't NULL.  Update the x86-64 ELF linker to estimate output
> > section layout before sizing dynamic sections and use the preliminary
> > section layout info to skip the GOTPCREL relocation conversion if the
> > converted relocation overflows.
> >
> > NB: We can't estimate the __ehdr_start value before allocation since it
> > is computed in assign_file_positions_for_load_sections during the final
> > link.
>
> Isn't this aspect alone already sufficient indication that this is the
> wrong approach to the issue at hand (as indicated before)?

I will address the __ehdr_start issue in the updated patch.

> Jan
>


-- 
H.J.


More information about the Binutils mailing list