[RFC PATCH 14/17] rx: give the field size of relocations wider than their howto

Harshit Kumar harshit7kr@gmail.com
Mon Nov 16 18:43:30 GMT 2026


rx_elf_relocate_section writes 4 octets for R_RX_DIR32_REV, whose
howto size is 2, and 2 octets for R_RX_RH_ABS5p5B, W and L and 1 for
R_RX_RH_ABS5p8B, W and L, R_RX_RH_UIMM4p8 and R_RX_RH_UNEG4p8, which
have no dst_mask.  Give the relocation offset check these sizes.  The
R_RX_RH_* relocations are made by relaxation, so this only matters for
objects that contain them already.

bfd/
	* elf32-rx.c (rx_elf_reloc_field_size): Give the field size of
	R_RX_DIR32_REV and the R_RX_RH_ABS5p*, R_RX_RH_UIMM4p8 and
	R_RX_RH_UNEG4p8 relocations.

ld/
	* testsuite/ld-elf/reloc-field-rx-dir32-rev.d: New test.
	* testsuite/ld-elf/reloc-field-rx-dir32-rev.s: New file.

Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
 bfd/elf32-rx.c                                | 31 ++++++++++++++++---
 .../ld-elf/reloc-field-rx-dir32-rev.d         |  4 +++
 .../ld-elf/reloc-field-rx-dir32-rev.s         |  8 +++++
 3 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/reloc-field-rx-dir32-rev.d
 create mode 100644 ld/testsuite/ld-elf/reloc-field-rx-dir32-rev.s

diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
index 4e4a88f034..1edbf17358 100644
--- a/bfd/elf32-rx.c
+++ b/bfd/elf32-rx.c
@@ -4097,7 +4097,9 @@ rx_additional_link_map_text (bfd *obfd, struct bfd_link_info *info, FILE *mapfil
    relocation stack and write nothing; only the relocation that pops the
    stack writes a field.  Their howto size is 4, and the assembler puts
    them at the offset of that field, which may be smaller and end the
-   section.  */
+   section.  R_RX_DIR32_REV writes 4 octets and the R_RX_RH_ABS5p*,
+   R_RX_RH_UIMM4p8 and R_RX_RH_UNEG4p8 relocations 1 or 2, although
+   their howto size is smaller.  */
 
 static bool
 rx_elf_reloc_field_size (const bfd *abfd ATTRIBUTE_UNUSED,
@@ -4105,10 +4107,29 @@ rx_elf_reloc_field_size (const bfd *abfd ATTRIBUTE_UNUSED,
 			 bool rel_p ATTRIBUTE_UNUSED,
 			 unsigned int *size)
 {
-  if (r_type < R_RX_SYM || r_type > R_RX_OPramtop)
-    return false;
-  *size = 0;
-  return true;
+  switch (r_type)
+    {
+    case R_RX_DIR32_REV:
+      *size = 4;
+      return true;
+    case R_RX_RH_ABS5p5B:
+    case R_RX_RH_ABS5p5W:
+    case R_RX_RH_ABS5p5L:
+      *size = 2;
+      return true;
+    case R_RX_RH_ABS5p8B:
+    case R_RX_RH_ABS5p8W:
+    case R_RX_RH_ABS5p8L:
+    case R_RX_RH_UIMM4p8:
+    case R_RX_RH_UNEG4p8:
+      *size = 1;
+      return true;
+    default:
+      if (r_type < R_RX_SYM || r_type > R_RX_OPramtop)
+	return false;
+      *size = 0;
+      return true;
+    }
 }
 
 #define TARGET_BIG_SYM		rx_elf32_be_vec
diff --git a/ld/testsuite/ld-elf/reloc-field-rx-dir32-rev.d b/ld/testsuite/ld-elf/reloc-field-rx-dir32-rev.d
new file mode 100644
index 0000000000..280a20825f
--- /dev/null
+++ b/ld/testsuite/ld-elf/reloc-field-rx-dir32-rev.d
@@ -0,0 +1,4 @@
+#name: RX DIR32_REV field size for the relocation offset check
+#target: rx-*-*
+#ld:
+#error: .*bad reloc offset \(0 \+ 0x4 > 0x2\) for section `\.probe'
diff --git a/ld/testsuite/ld-elf/reloc-field-rx-dir32-rev.s b/ld/testsuite/ld-elf/reloc-field-rx-dir32-rev.s
new file mode 100644
index 0000000000..be5d807722
--- /dev/null
+++ b/ld/testsuite/ld-elf/reloc-field-rx-dir32-rev.s
@@ -0,0 +1,8 @@
+	.text
+	.globl _start
+_start:
+	.section .probe,"",@progbits
+	.byte 0, 0
+	/* R_RX_DIR32_REV writes 4 octets, which would end past this
+	   2-octet section.  */
+	.reloc 0, R_RX_DIR32_REV, _start
-- 
2.55.0




More information about the Binutils mailing list