[RFC PATCH 07/17] mips: give the field size of ELF64 relocations
Harshit Kumar
harshit7kr@gmail.com
Mon Nov 16 18:43:23 GMT 2026
A relocation offset check that took the field size from the howto that
elf_info_to_howto returns would skip every MIPS ELF64 relocation, as
mips_elf64_info_to_howto_rela refuses them all:
mips_elf64_slurp_one_reloc_table converts them itself. Give the field
size through elf_backend_reloc_field_size instead. Split the howto
lookup out of mips_elf64_rtype_to_howto, which reports an unknown type,
so that the hook covers the same types, including R_MIPS_PC32,
R_MIPS_EH and R_MIPS_GNU_REL16_S2, which are not in the howto tables.
There is no test for those: gas refuses to emit them at an offset whose
field does not fit in the section.
bfd/
* elf64-mips.c (mips_elf64_lookup_howto): New function, split out
of ...
(mips_elf64_rtype_to_howto): ... here. Use it.
(mips_elf64_reloc_field_size): New function.
(elf_backend_reloc_field_size): Define.
Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
bfd/elf64-mips.c | 45 +++++++++++++++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 6 deletions(-)
diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c
index 0f543fb2db..4870786318 100644
--- a/bfd/elf64-mips.c
+++ b/bfd/elf64-mips.c
@@ -3909,10 +3909,11 @@ bfd_elf64_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
return NULL;
}
-/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
+/* Return the howto of relocation type R_TYPE, or NULL if there is
+ none. */
static reloc_howto_type *
-mips_elf64_rtype_to_howto (bfd *abfd, unsigned int r_type, bool rela_p)
+mips_elf64_lookup_howto (unsigned int r_type, bool rela_p)
{
reloc_howto_type *howto = NULL;
@@ -3961,14 +3962,26 @@ mips_elf64_rtype_to_howto (bfd *abfd, unsigned int r_type, bool rela_p)
}
if (howto != NULL && howto->name != NULL)
return howto;
-
- _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
- abfd, r_type);
- bfd_set_error (bfd_error_bad_value);
return NULL;
}
}
+/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
+
+static reloc_howto_type *
+mips_elf64_rtype_to_howto (bfd *abfd, unsigned int r_type, bool rela_p)
+{
+ reloc_howto_type *howto = mips_elf64_lookup_howto (r_type, rela_p);
+
+ if (howto != NULL)
+ return howto;
+
+ _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+ abfd, r_type);
+ bfd_set_error (bfd_error_bad_value);
+ return NULL;
+}
+
/* Prevent relocation handling by bfd for MIPS ELF64. */
static bool
@@ -3984,6 +3997,25 @@ mips_elf64_info_to_howto_rela (bfd *abfd,
return false;
}
+/* Give the field size of every relocation, for the linker's relocation
+ offset check. The generic check cannot use
+ mips_elf64_info_to_howto_rela, which refuses every relocation, so
+ look the howto up here, without reporting an unknown type. */
+
+static bool
+mips_elf64_reloc_field_size (const bfd *abfd ATTRIBUTE_UNUSED,
+ unsigned int r_type, bool rel_p,
+ unsigned int *size)
+{
+ reloc_howto_type *howto = mips_elf64_lookup_howto (r_type, !rel_p);
+
+ if (howto == NULL || howto->dst_mask == 0)
+ *size = 0;
+ else
+ *size = bfd_get_reloc_size (howto);
+ return true;
+}
+
/* Since each entry in an SHT_REL or SHT_RELA section can represent up
to three relocs, we must tell the user to allocate more space. */
@@ -4731,6 +4763,7 @@ static const struct elf_size_info mips_elf64_size_info =
_bfd_mips_elf_gc_mark_extra_sections
#define elf_info_to_howto mips_elf64_info_to_howto_rela
#define elf_info_to_howto_rel mips_elf64_info_to_howto_rela
+#define elf_backend_reloc_field_size mips_elf64_reloc_field_size
#define elf_backend_object_p mips_elf64_object_p
#define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
#define elf_backend_section_processing _bfd_mips_elf_section_processing
--
2.55.0
More information about the Binutils
mailing list