[binutils-gdb] Add r_ignore to coff internal_reloc

Alan Modra via Binutils-cvs <[email protected]> Sat, 25 Jul 2026 12:07:41 +0000 (GMT)
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D2b0b52883eb8=
560691be00815a49a87e1d5870f2

commit 2b0b52883eb8560691be00815a49a87e1d5870f2
Author: Alan Modra <[email protected]>
Date:   Sat Jul 25 10:33:33 2026 +0930

    Add r_ignore to coff internal_reloc
   =20
    Add a means of controlling _bfd_coff_generic_relocate_section for
    cases where a backend relocate_section has already handled the reloc.
   =20
    include/
            * coff/internal.h (struct internal_reloc): Reorganise.  Make
            r_type, r_size and r_extern bitfields.  Add r_ignore bitfield.
    bfd/
            * coff-alpha.c (alpha_ecoff_swap_reloc_in): Init all fields of
            struct internal_reloc.
            * coff-mips.c (mips_ecoff_swap_reloc_in): Likewise.  Remove
            unnecessary casts.
            * coffswap.h (coff_swap_reloc_in): Likewise.
            * peicode.h (coff_swap_reloc_in): Likewise.
            * coffcode.h (coff_slurp_reloc_table): Don't clear r_offset.
            * cofflink.c (_bfd_coff_generic_relocate_section): Skip relocs
            with r_ignore set.

Diff:
---
 bfd/coff-alpha.c        | 1 +
 bfd/coff-mips.c         | 3 ++-
 bfd/coffcode.h          | 1 -
 bfd/cofflink.c          | 3 +++
 bfd/coffswap.h          | 5 +++--
 bfd/peicode.h           | 5 +++--
 include/coff/internal.h | 7 ++++---
 7 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/bfd/coff-alpha.c b/bfd/coff-alpha.c
index f0823cdcaa9..dd1208ab064 100644
--- a/bfd/coff-alpha.c
+++ b/bfd/coff-alpha.c
@@ -496,6 +496,7 @@ alpha_ecoff_swap_reloc_in (bfd *abfd,
 {
   const RELOC *ext =3D ext_ptr;
=20
+  memset (intern, 0, sizeof (*intern));
   intern->r_vaddr =3D H_GET_64 (abfd, ext->r_vaddr);
   intern->r_symndx =3D H_GET_32 (abfd, ext->r_symndx);
=20
diff --git a/bfd/coff-mips.c b/bfd/coff-mips.c
index da7a666cebc..d5fc416bf58 100644
--- a/bfd/coff-mips.c
+++ b/bfd/coff-mips.c
@@ -272,8 +272,9 @@ mips_ecoff_swap_reloc_in (bfd *  abfd,
 			  void * ext_ptr,
 			  struct internal_reloc *intern)
 {
-  const RELOC *ext =3D (RELOC *) ext_ptr;
+  const RELOC *ext =3D ext_ptr;
=20
+  memset (intern, 0, sizeof (*intern));
   intern->r_vaddr =3D H_GET_32 (abfd, ext->r_vaddr);
   if (bfd_header_big_endian (abfd))
     {
diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index 267c6ce2782..964d2c3e173 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -5315,7 +5315,6 @@ coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, as=
ymbol ** symbols)
       cache_ptr =3D reloc_cache + idx;
       src =3D native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
=20
-      dst.r_offset =3D 0;
       bfd_coff_swap_reloc_in (abfd, src, &dst);
=20
 #ifdef RELOC_PROCESSING
diff --git a/bfd/cofflink.c b/bfd/cofflink.c
index d029bec1678..ae03ba855b2 100644
--- a/bfd/cofflink.c
+++ b/bfd/cofflink.c
@@ -3113,6 +3113,9 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd,
       reloc_howto_type *howto;
       bfd_reloc_status_type rstat;
=20
+      if (rel->r_ignore)
+	continue;
+
       symndx =3D rel->r_symndx;
=20
       if (symndx =3D=3D -1)
diff --git a/bfd/coffswap.h b/bfd/coffswap.h
index ffc662036b7..655a4b4817f 100644
--- a/bfd/coffswap.h
+++ b/bfd/coffswap.h
@@ -214,9 +214,10 @@
 static void
 coff_swap_reloc_in (bfd * abfd, void * src, void * dst)
 {
-  RELOC *reloc_src =3D (RELOC *) src;
-  struct internal_reloc *reloc_dst =3D (struct internal_reloc *) dst;
+  RELOC *reloc_src =3D src;
+  struct internal_reloc *reloc_dst =3D dst;
=20
+  memset (reloc_dst, 0, sizeof (*reloc_dst));
   reloc_dst->r_vaddr  =3D GET_RELOC_VADDR (abfd, reloc_src->r_vaddr);
   reloc_dst->r_symndx =3D H_GET_S32 (abfd, reloc_src->r_symndx);
   reloc_dst->r_type   =3D H_GET_16 (abfd, reloc_src->r_type);
diff --git a/bfd/peicode.h b/bfd/peicode.h
index 441652622b2..e858632312f 100644
--- a/bfd/peicode.h
+++ b/bfd/peicode.h
@@ -134,9 +134,10 @@ bfd_cleanup coff_real_object_p
 static void
 coff_swap_reloc_in (bfd *abfd, void *src, void *dst)
 {
-  RELOC *reloc_src =3D (RELOC *) src;
-  struct internal_reloc *reloc_dst =3D (struct internal_reloc *) dst;
+  RELOC *reloc_src =3D src;
+  struct internal_reloc *reloc_dst =3D dst;
=20
+  memset (reloc_dst, 0, sizeof (*reloc_dst));
   reloc_dst->r_vaddr  =3D H_GET_32 (abfd, reloc_src->r_vaddr);
   reloc_dst->r_symndx =3D H_GET_S32 (abfd, reloc_src->r_symndx);
   reloc_dst->r_type   =3D H_GET_16 (abfd, reloc_src->r_type);
diff --git a/include/coff/internal.h b/include/coff/internal.h
index f466d25f779..0191add5aea 100644
--- a/include/coff/internal.h
+++ b/include/coff/internal.h
@@ -680,10 +680,11 @@ struct internal_reloc
 {
   bfd_vma r_vaddr;		/* Virtual address of reference */
   long r_symndx;		/* Index into symbol table	*/
-  unsigned short r_type;	/* Relocation type		*/
-  unsigned char r_size;		/* Used by RS/6000 and ECOFF	*/
-  unsigned char r_extern;	/* Used by ECOFF		*/
   unsigned long r_offset;	/* Used by Alpha ECOFF, SPARC, others */
+  unsigned int r_type:16;	/* Relocation type		*/
+  unsigned int r_size:8;	/* Used by RS/6000 and ECOFF	*/
+  unsigned int r_extern:1;	/* Used by ECOFF		*/
+  unsigned int r_ignore:1;	/* Control _bfd_coff_generic_relocate_section */
 };
=20
 #define IMAGE_REL_BASED_ABSOLUTE		0