[PATCH v2] bfd: Retrieve dynamic relocations in SHT_RELR section

H.J. Lu hjl.tools@gmail.com
Wed Feb 26 00:00:42 GMT 2025


> This is for consistency.  BFD library provides
>
> bfd_get_dynamic_reloc_upper_bound
> bfd_canonicalize_dynamic_reloc
>
> They should cover all dynamic relocations.  objdump is just one of
> users of BFD library.
>

Here is the v2 patch with the updated commit message.

The BFD library provides:

1. bfd_get_dynamic_reloc_upper_bound to count dynamic relocations.
2. bfd_canonicalize_dynamic_reloc to retrieve dynamic relocations.

But they don't include relocations in SHT_RELR section.  One symptom is
that "objdump -R" doesn't display RELR relocations.

Update _bfd_elf_get_dynamic_reloc_upper_bound to count relocations in
SHT_RELR section and update _bfd_elf_canonicalize_dynamic_reloc to slurp
them.  A backend only needs to define elf_dt_relr_reloc_howto for the
pointer to reloc_howto_type for RELR relocation type which typically
is R_*_RELATIVE.

bfd/

PR binutils/32459
* elf-bfd.h (elf_size_info): Add count_relr_relocs and
slurp_relr_reloc_table.
(elf_backend_data): Add dt_relr_reloc_howto.
(elf_obj_tdata): Add dt_relr_entsize, dt_relr_nentries and
dt_relr_reloc_count.
(_bfd_elf_dt_relr_fill_relent): New.
(bfd_elf32_count_relr_relocs): Likewise.
(bfd_elf32_slurp_relr_reloc_table): Likewise.
(bfd_elf64_count_relr_relocs): Likewise.
(bfd_elf64_slurp_relr_reloc_table): Likewise.
* elf.c (_bfd_elf_get_dynamic_reloc_upper_bound): Count SHT_RELR
section.
(_bfd_elf_canonicalize_dynamic_reloc): Slurp SHT_RELR section.
(_bfd_elf_dt_relr_fill_relent): New.
* elf32-arc.c (arc_elf32_size_info): Add
bfd_elf32_count_relr_relocs and bfd_elf32_slurp_relr_reloc_table.
* elf32-arm.c (elf32_arm_size_info): Likewise.
* elf32-i386.c (elf_dt_relr_reloc_howto): New.
* elf64-alpha.c (alpha_elf_size_info): Add
bfd_elf64_count_relr_relocs and bfd_elf64_slurp_relr_reloc_table.
* elf64-hppa.c (hppa64_elf_size_info): Likewise.
* elf64-ia64-vms.c (elf64_ia64_vms_size_info): Likewise.
* elf64-mips.c (mips_elf64_size_info): Likewise.
* elf64-s390.c (s390_elf64_size_info): Likewise.
* elf64-sparc.c (elf64_sparc_size_info): Likewise.
* elf64-x86-64.c (elf_dt_relr_reloc_howto): New.
* elfcode.h (Elf_External_Relr): New.
(elf_count_relr_relocs): Likewise.
(elf_slurp_relr_reloc_table): Likewise.
(NUM_BITS_IN_ENTRY): Likewise.
(NAME(_bfd_elf,size_info)): Add elf_count_relr_relocs and
elf_slurp_relr_reloc_table.
* elfnn-aarch64.c (elfNN_aarch64_size_info): Add
bfd_elfNN_count_relr_relocs and bfd_elfNN_slurp_relr_reloc_table.
* elfxx-target.h (elf_dt_relr_reloc_howto): New.
(elfNN_bed): Add elf_dt_relr_reloc_howto.

binutils/

PR binutils/32459
* doc/binutils.texi: Remove objdump RELR note.
* objdump.c (dump_reloc_set): Restore the unused dummy argument.
(is_relr_section): Removed.
(contains_relr_relocs): Likewise.
(dump_relocs): Remove the RELR message.
(dump_dynamic_relocs): Remove the RELR check.

ld/

PR binutils/32459
* testsuite/ld-i386/dt-relr-1c.d: New file.
* testsuite/ld-i386/i386.exp: Run dt-relr-1c.
* testsuite/ld-x86-64/dt-relr-1c-x32.d: New file.
* testsuite/ld-x86-64/dt-relr-1c.d: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run dt-relr-1c and
dt-relr-1c-x32.

-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2-0001-bfd-Retrieve-dynamic-relocations-in-SHT_RELR-sect.patch
Type: text/x-patch
Size: 30222 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20250226/5d67c8a4/attachment-0001.bin>


More information about the Binutils mailing list