[committed] MIPS: Correct HI/LO rela reloc howto special_function entries

Maciej W. Rozycki macro@orcam.me.uk
Sun Jul 6 18:25:17 GMT 2025


From: Alan Modra <amodra@gmail.com>

The patch corrects the mips16 and micromips rela tables to *not*
use _bfd_mips_elf_{hi,lo}16_reloc.  These special functions are
inappropriate for RELA relocs where addends are in the reloc rather
than in the section contents.  See corresponding rela R_MIPS howtos.

bfd/
	* elf64-mips.c (mips16_elf64_howto_table_rela)
	<R_MIPS16_HI16, R_MIPS16_LO16>: Use _bfd_mips_elf_generic_reloc
	special_function.
	(micromips_elf64_howto_table_rela)
	<R_MICROMIPS_HI16, R_MICROMIPS_LO16>: Similarly.
	* elfn32-mips.c: As for elf64-mips.c.
---
 bfd/elf64-mips.c  |    8 ++++----
 bfd/elfn32-mips.c |    8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

binutils-amodra-mips-hilo16-howto-rela.diff
Index: binutils-gdb/bfd/elf64-mips.c
===================================================================
--- binutils-gdb.orig/bfd/elf64-mips.c
+++ binutils-gdb/bfd/elf64-mips.c
@@ -1961,7 +1961,7 @@ static reloc_howto_type mips16_elf64_how
 	 false,			/* pc_relative */
 	 0,			/* bitpos */
 	 complain_overflow_dont, /* complain_on_overflow */
-	 _bfd_mips_elf_hi16_reloc, /* special_function */
+	 _bfd_mips_elf_generic_reloc, /* special_function */
 	 "R_MIPS16_HI16",	/* name */
 	 false,			/* partial_inplace */
 	 0,			/* src_mask */
@@ -1976,7 +1976,7 @@ static reloc_howto_type mips16_elf64_how
 	 false,			/* pc_relative */
 	 0,			/* bitpos */
 	 complain_overflow_dont, /* complain_on_overflow */
-	 _bfd_mips_elf_lo16_reloc, /* special_function */
+	 _bfd_mips_elf_generic_reloc, /* special_function */
 	 "R_MIPS16_LO16",	/* name */
 	 false,			/* partial_inplace */
 	 0,			/* src_mask */
@@ -2615,7 +2615,7 @@ static reloc_howto_type micromips_elf64_
 	 false,			/* pc_relative */
 	 0,			/* bitpos */
 	 complain_overflow_dont, /* complain_on_overflow */
-	 _bfd_mips_elf_hi16_reloc, /* special_function */
+	 _bfd_mips_elf_generic_reloc, /* special_function */
 	 "R_MICROMIPS_HI16",	/* name */
 	 false,			/* partial_inplace */
 	 0,			/* src_mask */
@@ -2630,7 +2630,7 @@ static reloc_howto_type micromips_elf64_
 	 false,			/* pc_relative */
 	 0,			/* bitpos */
 	 complain_overflow_dont, /* complain_on_overflow */
-	 _bfd_mips_elf_lo16_reloc, /* special_function */
+	 _bfd_mips_elf_generic_reloc, /* special_function */
 	 "R_MICROMIPS_LO16",	/* name */
 	 false,			/* partial_inplace */
 	 0,			/* src_mask */
Index: binutils-gdb/bfd/elfn32-mips.c
===================================================================
--- binutils-gdb.orig/bfd/elfn32-mips.c
+++ binutils-gdb/bfd/elfn32-mips.c
@@ -1941,7 +1941,7 @@ static reloc_howto_type elf_mips16_howto
 	 false,			/* pc_relative */
 	 0,			/* bitpos */
 	 complain_overflow_dont, /* complain_on_overflow */
-	 _bfd_mips_elf_hi16_reloc, /* special_function */
+	 _bfd_mips_elf_generic_reloc, /* special_function */
 	 "R_MIPS16_HI16",	/* name */
 	 false,			/* partial_inplace */
 	 0,			/* src_mask */
@@ -1956,7 +1956,7 @@ static reloc_howto_type elf_mips16_howto
 	 false,			/* pc_relative */
 	 0,			/* bitpos */
 	 complain_overflow_dont, /* complain_on_overflow */
-	 _bfd_mips_elf_lo16_reloc, /* special_function */
+	 _bfd_mips_elf_generic_reloc, /* special_function */
 	 "R_MIPS16_LO16",	/* name */
 	 false,			/* partial_inplace */
 	 0,			/* src_mask */
@@ -2595,7 +2595,7 @@ static reloc_howto_type elf_micromips_ho
 	 false,			/* pc_relative */
 	 0,			/* bitpos */
 	 complain_overflow_dont, /* complain_on_overflow */
-	 _bfd_mips_elf_hi16_reloc, /* special_function */
+	 _bfd_mips_elf_generic_reloc, /* special_function */
 	 "R_MICROMIPS_HI16",	/* name */
 	 false,			/* partial_inplace */
 	 0,			/* src_mask */
@@ -2610,7 +2610,7 @@ static reloc_howto_type elf_micromips_ho
 	 false,			/* pc_relative */
 	 0,			/* bitpos */
 	 complain_overflow_dont, /* complain_on_overflow */
-	 _bfd_mips_elf_lo16_reloc, /* special_function */
+	 _bfd_mips_elf_generic_reloc, /* special_function */
 	 "R_MICROMIPS_LO16",	/* name */
 	 false,			/* partial_inplace */
 	 0,			/* src_mask */


More information about the Binutils mailing list