[RFC PATCH 05/17] msp430: give SYM_DIFF relocations no field
Harshit Kumar
harshit7kr@gmail.com
Mon Nov 16 18:43:21 GMT 2026
MSP430 describes a symbol difference as R_MSP430_SYM_DIFF (or
R_MSP430X_SYM_DIFF), which only computes a value, followed at the same
offset by the relocation that writes the field, which may be 1 or 2
octets. The SYM_DIFF howto size is 4, so a relocation offset check
that took it would reject a difference such as ".byte foo - bar" in the
last octets of a section. Give SYM_DIFF a field size of 0.
bfd/
* elf32-msp430.c (uses_msp430x_relocs): Take a const bfd.
(msp430_elf_reloc_field_size): New function.
(elf_backend_reloc_field_size): Define.
Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
bfd/elf32-msp430.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
index 6948fd3a1f..e8a22619cb 100644
--- a/bfd/elf32-msp430.c
+++ b/bfd/elf32-msp430.c
@@ -660,7 +660,7 @@ static const struct msp430_reloc_map msp430x_reloc_map[] =
};
static inline bool
-uses_msp430x_relocs (bfd * abfd)
+uses_msp430x_relocs (const bfd * abfd)
{
extern const bfd_target msp430_elf32_ti_vec;
@@ -2917,11 +2917,29 @@ elf32_msp430_eh_frame_address_size (bfd *abfd,
#define ELF_OSABI ELFOSABI_STANDALONE
#define ELF_OSABI_EXACT 1
+/* R_MSP430_SYM_DIFF and R_MSP430X_SYM_DIFF only compute a value for the
+ next relocation at the same offset, which writes the field. Their
+ howto size is 4, but that field may be smaller and end the section. */
+
+static bool
+msp430_elf_reloc_field_size (const bfd *abfd,
+ unsigned int r_type,
+ bool rel_p ATTRIBUTE_UNUSED,
+ unsigned int *size)
+{
+ if (r_type != (uses_msp430x_relocs (abfd)
+ ? R_MSP430X_SYM_DIFF : R_MSP430_SYM_DIFF))
+ return false;
+ *size = 0;
+ return true;
+}
+
#define TARGET_LITTLE_SYM msp430_elf32_vec
#define TARGET_LITTLE_NAME "elf32-msp430"
#define elf_info_to_howto msp430_info_to_howto_rela
#define elf_info_to_howto_rel NULL
+#define elf_backend_reloc_field_size msp430_elf_reloc_field_size
#define elf_backend_relocate_section elf32_msp430_relocate_section
#define elf_backend_can_gc_sections 1
#define elf_backend_final_write_processing bfd_elf_msp430_final_write_processing
--
2.55.0
More information about the Binutils
mailing list