[COMMITTED] hppa: Fix register extraction logic for ldil instruction

John David Anglin dave.anglin@bell.net
Mon Nov 9 22:04:44 GMT 2026


Tested on hppa-unknown-linux-gnu with no regressions.  Committed to trunk.

Dave
---

hppa: Fix register extraction logic for ldil instruction

This fixes two issues in the code to handle converting the relocation
in ldil+addl sequences.  I extracted the target address of the ldil
instruction from the wrong bit position.  Secondly as with addil, we
need to accept any base register in the R_PARISC_DLTIND21L conversion
to R_PARISC_DPREL21L.

2026-11-09  John David Anglin  <danglin@gcc.gnu.org>

bfd/ChangeLog:

	* elf32-hppa.c (final_link_relocate): Fix register extraction logic
	for ldil instruction by shifting to extract the source/base field
	instead of the lower bits.  Update addl instruction bitmask in
	DLTIND to DPREL relocation conversion path to support arbitrary
	target registers emitted under LRA.

diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
index b7c84d26481..8083dc8aaef 100644
--- a/bfd/elf32-hppa.c
+++ b/bfd/elf32-hppa.c
@@ -3225,17 +3225,19 @@ final_link_relocate (asection *input_section,
 		insn = ADDIL_DP;
 	      else
 		{
-		  /* We must have a ldil instruction.  In general, it's
-		     hard to find and convert the associated add instruction.
+		  /* We must have a ldil instruction.  In general, it's hard
+		     to find and convert the associated add instruction.
 		     However, gcc emits the addl immediately after the ldil.
-		     So if the next instruction is an r19 addl, convert it
+		     As with addil, gcc sometimes changes the base in the
+		     addl.  So if the next instruction is an addl with r1
+		     matching the target register of the ldil, convert it
 		     to use dp.  Otherwise, issue an error.  */
 		  unsigned int next = bfd_get_32 (input_bfd, hit_data + 4);
 
-		  /* Check for "addl %r0,%r19,%r0" and ldil/addl
+		  /* Check for "addl %r0,%r0,%r0" and ldil/addl
 		     target/input register match.  */
-		  if ((next & 0xffe0ffe0) == 0x0a600a00
-		      && ((next >> 16) & 0x1f) == (insn & 0x1f))
+		  if ((next & 0xfc00ffe0) == 0x08000a00
+		      && ((next >> 16) & 0x1f) == ((insn >> 21) & 0x1f))
 		    {
 		      /* Change register to dp.  */
 		      next = (next & 0xfc1fffff) | (27 << 21);
@@ -3285,7 +3287,7 @@ final_link_relocate (asection *input_section,
 	      /* Check for "addl %r0,%dp,%r0" and ldil/addl
 		 target/input register match.  */
 	      if ((next & 0xffe0ffe0) == 0x0b600a00
-		  && ((next >> 16) & 0x1f) == (insn & 0x1f))
+		  && ((next >> 16) & 0x1f) == ((insn >> 21) & 0x1f))
 		{
 		  /* Change dp register in addl to r0.  */
 		  next &= ~ (0x1f << 21);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20261109/bbbbf82a/attachment-0001.sig>


More information about the Binutils mailing list