[binutils-gdb] Make use of coff internal_reloc r_ignore

Alan Modra amodra@sourceware.org
Sat Jul 25 12:07:46 GMT 2026


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

commit bc2ea90d5d53d2f95f5d50979945b3ef9eee39a3
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Jul 25 10:34:09 2026 +0930

    Make use of coff internal_reloc r_ignore
    
    Set r_ignore on relocs already handled by a backend relocate_section,
    rather than choosing a "do nothing" r_type.  This avoids bugs in all
    three targets with in_reloc_p, which resulted in addresses being
    emitted for dynamic relocs at all of these "do nothing" relocs.
    
            * coff-aarch64.c (coff_pe_aarch64_relocate_section): Leave r_type
            unchanged on relocs handled here.  Set r_ignore instead.
            * coff-i386.c (coff_pe_i386_relocate_section): Likewise.
            * coff-x86_64.c (coff_pe_amd64_relocate_section): Likewise.
            Cosmetic fix in r_type handled here.  Formatting.

Diff:
---
 bfd/coff-aarch64.c | 22 +++++++++++-----------
 bfd/coff-i386.c    |  2 +-
 bfd/coff-x86_64.c  |  8 +++++---
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/bfd/coff-aarch64.c b/bfd/coff-aarch64.c
index c00448efc82..d889359a6fc 100644
--- a/bfd/coff-aarch64.c
+++ b/bfd/coff-aarch64.c
@@ -578,7 +578,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 		input_section, rel->r_vaddr - input_section->vma);
 
 	    bfd_putl32 (val, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
@@ -613,7 +613,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 	    opcode |= val & 0x3ffffff;
 
 	    bfd_putl32 (opcode, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
@@ -648,7 +648,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 	    opcode |= (val & 0x7ffff) << 5;
 
 	    bfd_putl32 (opcode, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
@@ -683,7 +683,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 	    opcode |= (val & 0x3fff) << 5;
 
 	    bfd_putl32 (opcode, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
@@ -720,7 +720,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 	    opcode |= (val & 0x1ffffc) << 3;
 
 	    bfd_putl32 (opcode, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
@@ -757,7 +757,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 	    opcode |= (val & 0x1ffffc) << 3;
 
 	    bfd_putl32 (opcode, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
@@ -786,7 +786,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 		input_section, rel->r_vaddr - input_section->vma);
 
 	    bfd_putl32 (val, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
@@ -831,7 +831,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 	    opcode |= val << 10;
 
 	    bfd_putl32 (opcode, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
@@ -854,7 +854,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 	    opcode |= val << 10;
 
 	    bfd_putl32 (opcode, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
@@ -875,7 +875,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 		input_section, rel->r_vaddr - input_section->vma);
 
 	    bfd_putl32 (val, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
@@ -900,7 +900,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 
 
 	    bfd_putl16 (idx, contents + rel->r_vaddr);
-	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+	    rel->r_ignore = 1;
 
 	    break;
 	  }
diff --git a/bfd/coff-i386.c b/bfd/coff-i386.c
index d9177c51c79..0e296a3400b 100644
--- a/bfd/coff-i386.c
+++ b/bfd/coff-i386.c
@@ -459,7 +459,7 @@ coff_pe_i386_relocate_section (bfd *output_bfd,
 
       /* Make sure that _bfd_coff_generic_relocate_section won't parse
          this reloc after us.  */
-      rel->r_type = 0;
+      rel->r_ignore = 1;
 
       symndx = rel->r_symndx;
 
diff --git a/bfd/coff-x86_64.c b/bfd/coff-x86_64.c
index 78836a5c267..2c434624052 100644
--- a/bfd/coff-x86_64.c
+++ b/bfd/coff-x86_64.c
@@ -591,12 +591,12 @@ coff_pe_amd64_relocate_section (bfd *output_bfd,
       asection *sec, *s;
       uint16_t idx = 0, i = 1;
 
-      if (rel->r_type != R_SECTION)
+      if (rel->r_type != R_AMD64_SECTION)
 	continue;
 
       /* Make sure that _bfd_coff_generic_relocate_section won't parse
          this reloc after us.  */
-      rel->r_type = 0;
+      rel->r_ignore = 1;
 
       symndx = rel->r_symndx;
 
@@ -647,7 +647,9 @@ coff_pe_amd64_relocate_section (bfd *output_bfd,
       bfd_putl16 (idx, contents + rel->r_vaddr - input_section->vma);
     }
 
-  return _bfd_coff_generic_relocate_section (output_bfd, info, input_bfd,input_section, contents,relocs, syms, sections);
+  return _bfd_coff_generic_relocate_section (output_bfd, info, input_bfd,
+					     input_section, contents,
+					     relocs, syms, sections);
 }
 
 #define coff_relocate_section coff_pe_amd64_relocate_section


More information about the Binutils-cvs mailing list