[PATCH v2] ld: Check ELF relocs before allocation

Alan Modra amodra@gmail.com
Tue Jan 4 23:43:29 GMT 2022


On Wed, Dec 29, 2021 at 02:14:31PM -0800, H.J. Lu via Binutils wrote:
> bfd/
> 
> 	* elf-bfd.h (elf_backend_data): Add make_reloc_section.

No, none of the elf-bfd.h, elflink.c, elfxx-target.h, bfdlink.h,
ldlang.c or any other general linker files need changing to support an
x86 separation of check_relocs into two pieces.  You do not need new
linker infrastructure.  You already have that capability by defining
an x86 specific LDEMUL_AFTER_ALLOCATION in elf-x86.em.  Perhaps you
might need to duplicate elf_x86.em into two files, one for 32-bit and
one for 64-bit, or otherwise arrange to call different functions for
x86_64 and ix86.

Doing the x86 DT_RELR support that way will make it easier to port the
support to other architectures.  aarch64, arm, avr, csky, hppa,
m68hc1x, metag, nios2, ppc64, ppc32, all have existing
after_allocation functions that size stubs.  You need something
similar to size the DT_RELR section, after all linker inputs are
seen and symbols resolved, and if you want to minimize DT_RELR size,
a preliminary layout can be done.  It would also be possible to size
DT_RELR in before_allocation, but then you'd need to assume an
address/offset word is emitted whenever changing sections.  That would
be entirely reasonable too.  Either way, I don't see any need to
invent a new way of switching between target functions when you
already have that via LDEMUL_*.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list