[binutils-gdb] hppa: Fix register extraction logic for ldil instruction

John David Anglin danglin@sourceware.org
Mon Nov 9 22:01:49 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e46ba3ac3d9611c6ff5c4a4e7dcc7b99b3f0c82c

commit e46ba3ac3d9611c6ff5c4a4e7dcc7b99b3f0c82c
Author: John David Anglin <danglin@gcc.gnu.org>
Date:   Mon Nov 9 17:01:10 2026 -0500

    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:
---
 bfd/elf32-hppa.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

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);


More information about the Binutils-cvs mailing list