[RFC PATCH 01/17] bfd: add ELF hooks for a relocation field size check
Harshit Kumar
harshit7kr@gmail.com
Mon Nov 16 18:43:17 GMT 2026
Add two elf_backend_data members for the relocation offset check that
a later patch adds to the linker, so that backends can describe their
relocations before the check is turned on:
- elf_backend_reloc_field_size gives the number of octets that a
relocation type may read or write at r_offset, where the howto does
not give it, or 0 for a type with no field.
- relocs_compose_at_offset says that relocate_section treats
consecutive relocations at one offset as one composed relocation,
of which only the last writes the field.
Nothing uses them yet.
bfd/
* elf-bfd.h (struct elf_backend_data): Add
elf_backend_reloc_field_size and relocs_compose_at_offset.
* elfxx-target.h (elf_backend_reloc_field_size)
(elf_backend_relocs_compose_at_offset): Define.
(elfNN_bed): Initialize them.
Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
bfd/elf-bfd.h | 19 +++++++++++++++++++
bfd/elfxx-target.h | 9 +++++++++
2 files changed, 28 insertions(+)
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index b9260529a6..3e96b2a3cc 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -1057,6 +1057,16 @@ struct elf_backend_data
bool (*elf_info_to_howto_rel)
(bfd *, arelent *, Elf_Internal_Rela *);
+ /* For a relocation of type R_TYPE whose howto does not give the
+ number of octets it may read or write at its r_offset, set *SIZE to
+ that number, or to 0 if it has no field, and return true. Return
+ false to use the howto. REL_P is true for a relocation from a
+ SHT_REL section. The linker uses this to check that the field lies
+ inside the section, and remembers the result per relocation type of
+ an input bfd. */
+ bool (*elf_backend_reloc_field_size)
+ (const bfd *, unsigned int, bool, unsigned int *);
+
/* A function to determine whether a symbol is global when
partitioning the symbol table into local and global symbols.
This should be NULL for most targets, in which case the correct
@@ -1833,6 +1843,15 @@ struct elf_backend_data
static binaries. */
unsigned always_renumber_dynsyms : 1;
+ /* True if relocate_section treats consecutive relocations at the same
+ offset as one composed relocation: each one but the last passes its
+ result to the next as the addend, and only the last one writes the
+ field. The relocation offset check then skips a relocation that is
+ followed, at the same offset, by one that has a field. Do not set
+ it if the backend writes, or reads without its own bounds check, at
+ any relocation of a sequence but the last. */
+ unsigned relocs_compose_at_offset : 1;
+
/* True if the 32-bit Linux PRPSINFO structure's `pr_uid' and `pr_gid'
members use a 16-bit data type. */
unsigned linux_prpsinfo32_ugid16 : 1;
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index 503b4b4674..9d511da937 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -140,6 +140,9 @@
#ifndef elf_backend_always_renumber_dynsyms
#define elf_backend_always_renumber_dynsyms false
#endif
+#ifndef elf_backend_relocs_compose_at_offset
+#define elf_backend_relocs_compose_at_offset false
+#endif
#ifndef elf_backend_linux_prpsinfo32_ugid16
#define elf_backend_linux_prpsinfo32_ugid16 false
#endif
@@ -359,6 +362,10 @@
#define elf_info_to_howto_rel NULL
#endif
+#ifndef elf_backend_reloc_field_size
+#define elf_backend_reloc_field_size NULL
+#endif
+
#ifndef elf_backend_arch_data
#define elf_backend_arch_data NULL
#endif
@@ -868,6 +875,7 @@ static const struct elf_backend_data elfNN_bed =
elf_backend_arch_data,
elf_info_to_howto,
elf_info_to_howto_rel,
+ elf_backend_reloc_field_size,
elf_backend_sym_is_global,
elf_backend_object_p,
elf_backend_symbol_processing,
@@ -1020,6 +1028,7 @@ static const struct elf_backend_data elfNN_bed =
elf_backend_caches_rawsize,
elf_backend_extern_protected_data,
elf_backend_always_renumber_dynsyms,
+ elf_backend_relocs_compose_at_offset,
elf_backend_linux_prpsinfo32_ugid16,
elf_backend_linux_prpsinfo64_ugid16,
elf_backend_use_mmap
--
2.55.0
More information about the Binutils
mailing list