]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
BFD: Make `bfd_finalize_section_relocs' return status
authorMaciej W. Rozycki <macro@orcam.me.uk>
Wed, 14 Jan 2026 22:28:43 +0000 (22:28 +0000)
committerMaciej W. Rozycki <macro@orcam.me.uk>
Wed, 14 Jan 2026 22:28:43 +0000 (22:28 +0000)
Update `bfd_finalize_section_relocs' to return status so that backends
can fail in this interface and propagate that to the respective callers.
Add suitable error reporting there.  No failure cases in the existing
handlers though.

16 files changed:
bfd/bfd-in2.h
bfd/bfd.c
bfd/elf64-sparc.c
bfd/libbfd-in.h
bfd/libbfd.c
bfd/libbfd.h
bfd/reloc.c
bfd/targets.c
binutils/objcopy.c
binutils/rescoff.c
gas/config/obj-coff.c
gas/config/obj-coff.h
gas/config/obj-macho.c
gas/config/obj-macho.h
gas/write.c
ld/ldlang.c

index 131e969a083e898dc3c3eb065bf7c8fbea49afec..d4e4f8e43757765d7d5ae3dff37fd957e80bfabd 100644 (file)
@@ -2613,7 +2613,7 @@ long bfd_get_reloc_upper_bound (bfd *abfd, asection *sect);
 long bfd_canonicalize_reloc
    (bfd *abfd, asection *sec, arelent **loc, asymbol **syms);
 
-void bfd_finalize_section_relocs
+bool bfd_finalize_section_relocs
    (bfd *abfd, asection *sec, arelent **rel, unsigned int count);
 
 #define bfd_finalize_section_relocs(abfd, asect, location, count) \
@@ -7664,7 +7664,7 @@ typedef struct bfd_target
   long (*_get_reloc_upper_bound) (bfd *, sec_ptr);
   long (*_bfd_canonicalize_reloc) (bfd *, sec_ptr, arelent **,
                                   struct bfd_symbol **);
-  void (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **,
+  bool (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **,
                                        unsigned int);
   /* See documentation on reloc types.  */
   reloc_howto_type *
index 0c97a495e2f225c429e30045b9feff1b172dbd62..35669075da229a8aafcf111929ea0cfb98e0c89c 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2202,7 +2202,7 @@ FUNCTION
        bfd_finalize_section_relocs
 
 SYNOPSIS
-       void bfd_finalize_section_relocs
+       bool bfd_finalize_section_relocs
          (bfd *abfd, asection *sec, arelent **rel, unsigned int count);
 
 DESCRIPTION
index 2a192ddabc91bd1839e859c3411d1778b3ad1aab..c73f2934edfaade7c96cdef25e35ca4d8e693939 100644 (file)
@@ -314,7 +314,7 @@ elf64_sparc_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage,
 
 /* Install a new set of internal relocs.  */
 
-static void
+static bool
 elf64_sparc_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED,
                                     asection *asect,
                                     arelent **location,
@@ -326,6 +326,7 @@ elf64_sparc_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED,
     asect->flags |= SEC_RELOC;
   else
     asect->flags &= ~SEC_RELOC;
+  return true;
 }
 
 /* Write out the relocs.  */
index b9a1ca44224a80b7c50fd4dece0476f58f42149c..a5186b5e6f0f4044c334458359b381633c5aecd9 100644 (file)
@@ -447,7 +447,7 @@ extern long _bfd_norelocs_get_reloc_upper_bound
   (bfd *, asection *) ATTRIBUTE_HIDDEN;
 extern long _bfd_norelocs_canonicalize_reloc
   (bfd *, asection *, arelent **, asymbol **) ATTRIBUTE_HIDDEN;
-extern void _bfd_norelocs_finalize_section_relocs
+extern bool _bfd_norelocs_finalize_section_relocs
   (bfd *, asection *, arelent **, unsigned int) ATTRIBUTE_HIDDEN;
 extern reloc_howto_type *_bfd_norelocs_bfd_reloc_type_lookup
   (bfd *, bfd_reloc_code_real_type) ATTRIBUTE_HIDDEN;
index 8be826653424ae04de179b395c40cc28ebd9ff2e..6311ef49f6e359bda85242f2682afd0d49a93ff3 100644 (file)
@@ -199,13 +199,13 @@ _bfd_norelocs_canonicalize_reloc (bfd *abfd ATTRIBUTE_UNUSED,
   return 0;
 }
 
-void
+bool
 _bfd_norelocs_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED,
                                       asection *sec ATTRIBUTE_UNUSED,
                                       arelent **relptr ATTRIBUTE_UNUSED,
                                       unsigned int count ATTRIBUTE_UNUSED)
 {
-  /* Do nothing.  */
+  return true;
 }
 
 bool
index 5d39478523659b05eb94ca5a2066a4ef96fca8a3..a27134dcd788b083f80af0b654bc27246a635e1b 100644 (file)
@@ -453,7 +453,7 @@ extern long _bfd_norelocs_get_reloc_upper_bound
   (bfd *, asection *) ATTRIBUTE_HIDDEN;
 extern long _bfd_norelocs_canonicalize_reloc
   (bfd *, asection *, arelent **, asymbol **) ATTRIBUTE_HIDDEN;
-extern void _bfd_norelocs_finalize_section_relocs
+extern bool _bfd_norelocs_finalize_section_relocs
   (bfd *, asection *, arelent **, unsigned int) ATTRIBUTE_HIDDEN;
 extern reloc_howto_type *_bfd_norelocs_bfd_reloc_type_lookup
   (bfd *, bfd_reloc_code_real_type) ATTRIBUTE_HIDDEN;
@@ -3530,7 +3530,7 @@ bfd_byte *bfd_generic_get_relocated_section_contents
     bool relocatable,
     asymbol **symbols) ATTRIBUTE_HIDDEN;
 
-void _bfd_generic_finalize_section_relocs
+bool _bfd_generic_finalize_section_relocs
    (bfd *abfd,
     sec_ptr section,
     arelent **relptr,
index aea90fbc32761ab457a43f9e7a8aa37290b8095c..98343696a3348a58804e96f4e1ced8fc9c151b0c 100644 (file)
@@ -8365,7 +8365,7 @@ INTERNAL_FUNCTION
        _bfd_generic_finalize_section_relocs
 
 SYNOPSIS
-       void _bfd_generic_finalize_section_relocs
+       bool _bfd_generic_finalize_section_relocs
          (bfd *abfd,
           sec_ptr section,
           arelent **relptr,
@@ -8375,7 +8375,7 @@ DESCRIPTION
        Installs a new set of internal relocations in SECTION.
 */
 
-void
+bool
 _bfd_generic_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED,
                                      sec_ptr section,
                                      arelent **relptr,
@@ -8387,6 +8387,7 @@ _bfd_generic_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED,
     section->flags |= SEC_RELOC;
   else
     section->flags &= ~SEC_RELOC;
+  return true;
 }
 
 /*
index 864ff625f55fb1db04dc143a94c66a4c7f8fe7a1..dce4b88a20cc28f41b6ebd12271a08d9dd30bda6 100644 (file)
@@ -438,7 +438,7 @@ BFD_JUMP_TABLE macros.
 .  long        (*_get_reloc_upper_bound) (bfd *, sec_ptr);
 .  long        (*_bfd_canonicalize_reloc) (bfd *, sec_ptr, arelent **,
 .                                  struct bfd_symbol **);
-.  void        (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **,
+.  bool (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **,
 .                                       unsigned int);
 .  {* See documentation on reloc types.  *}
 .  reloc_howto_type *
index aea69ba886a9c3985c2560983671320095250ff3..5f44c6295f2db5e2a9d8d082bb8808dc0c1d4a7b 100644 (file)
@@ -4555,7 +4555,10 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, bfd *obfd)
     }
 
   if (relsize == 0)
-    bfd_finalize_section_relocs (obfd, osection, NULL, 0);
+    {
+      if (!bfd_finalize_section_relocs (obfd, osection, NULL, 0))
+       return false;
+    }
   else
     {
       if (isection->orelocation != NULL)
@@ -4596,8 +4599,10 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, bfd *obfd)
          *w_relpp = 0;
        }
 
-      bfd_finalize_section_relocs (obfd, osection,
-                                  relcount == 0 ? NULL : relpp, relcount);
+      if (!bfd_finalize_section_relocs (obfd, osection,
+                                       relcount == 0 ? NULL : relpp,
+                                       relcount))
+       return false;
     }
   return true;
 }
index afeadf161c1b8446710b9ca07c25ce8c04b26e49..6b07ddd2bcbb80acc1a4cd73619b13cb59ea3cc1 100644 (file)
@@ -685,7 +685,13 @@ write_coff_file (const char *filename, const char *target,
       return false;
     }
 
-  bfd_finalize_section_relocs (abfd, sec, cwi.relocs, cwi.reloc_count);
+  if (!bfd_finalize_section_relocs (abfd, sec, cwi.relocs, cwi.reloc_count))
+    {
+      bfd_nonfatal ("bfd_finalize_section_relocs");
+      bfd_close_all_done (abfd);
+      free (cwi.relocs);
+      return false;
+    }
 
   offset = 0;
   for (d = cwi.dirs.d; d != NULL; d = d->next)
index b01ef97576389c6adbd4f46c301475b6f79af231..30e3ca2e2c89272faa278fc8afd746443acc6fb7 100644 (file)
@@ -1517,13 +1517,14 @@ coff_frob_file_after_relocs (void)
 /* Set relocations for the section and then store the number of relocations
    in its aux entry.  */
 
-void
+bool
 obj_coff_finalize_section_relocs (asection *sec, arelent **relocs,
                                  unsigned int n)
 {
   symbolS *sect_sym;
 
-  bfd_finalize_section_relocs (stdoutput, sec, n ? relocs : NULL, n);
+  if (!bfd_finalize_section_relocs (stdoutput, sec, n ? relocs : NULL, n))
+    return false;
   sect_sym = section_symbol (sec);
 #ifdef OBJ_XCOFF
   if (S_GET_STORAGE_CLASS (sect_sym) == C_DWARF)
@@ -1531,6 +1532,7 @@ obj_coff_finalize_section_relocs (asection *sec, arelent **relocs,
   else
 #endif
     SA_SET_SCN_NRELOC (sect_sym, n);
+  return true;
 }
 
 /* Implement the .section pseudo op:
index 8fb39dbfcd2854386bb46e2ba449c66761945c67..0b933f467b2dcfb525c30a01142ac69f9b2da825 100644 (file)
@@ -296,7 +296,7 @@ extern void coff_pop_insert (void);
 /* We need to store the number of relocations in the section aux entry.  */
 #define FINALIZE_SECTION_RELOCS(sec, relocs, n) \
   obj_coff_finalize_section_relocs (sec, relocs, n)
-extern void obj_coff_finalize_section_relocs (asection *, arelent **,
+extern bool obj_coff_finalize_section_relocs (asection *, arelent **,
                                              unsigned int);
 
 extern int  S_SET_DATA_TYPE              (symbolS *, int);
index 06ace7a0756c2f31e5ff9de16eb4b93cf4ac7293..5b16e7512b4872fe48ce8d3a8357bde33c918014 100644 (file)
@@ -1879,7 +1879,7 @@ obj_mach_o_frob_file_after_relocs (void)
 
 /* Reverse relocations order to make ld happy.  */
 
-void
+bool
 obj_mach_o_reorder_section_relocs (asection *sec, arelent **rels, unsigned int n)
 {
   unsigned int i;
@@ -1891,7 +1891,7 @@ obj_mach_o_reorder_section_relocs (asection *sec, arelent **rels, unsigned int n
       rels[i] = rels[n - i - 1];
       rels[n - i - 1] = r;
     }
-  bfd_finalize_section_relocs (stdoutput, sec, rels, n);
+  return bfd_finalize_section_relocs (stdoutput, sec, rels, n);
 }
 
 /* Relocation rules are different in frame sections.  */
index 40dd9fb0c1572da30c4fd8d5d083138d0ad5edd4..6e4b7b6d17837939a23717dbcba08934c3645c2f 100644 (file)
@@ -101,7 +101,7 @@ extern void obj_mach_o_frob_file_after_relocs (void);
 
 #define FINALIZE_SECTION_RELOCS(sec, relocs, n) \
   obj_mach_o_reorder_section_relocs (sec, relocs, n)
-extern void obj_mach_o_reorder_section_relocs (asection *, arelent **,
+extern bool obj_mach_o_reorder_section_relocs (asection *, arelent **,
                                               unsigned int);
 
 /* Emit relocs for local subtracts, to cater for subsections-via-symbols.  */
index b3427145571283f5ce09c2a077c2227e29cd7b69..3494871270a1f4c76624d8eb3715e35575695c8f 100644 (file)
@@ -1419,7 +1419,8 @@ write_relocs (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
   }
 #endif
 
-  FINALIZE_SECTION_RELOCS (sec, relocs, n);
+  if (!FINALIZE_SECTION_RELOCS (sec, relocs, n))
+    as_bad (_("%s: unable to finalize relocations"), sec->name);
 
 #ifdef DEBUG3
   {
index c5a128072ed5c68551863470638d14e5c81ec132..a0368ecbe42665624ca120b1b8c8ec0dba88d3de 100644 (file)
@@ -10640,7 +10640,13 @@ copy_section (bfd *ibfd, sec_ptr isection, void *p)
     }
 
   if (relsize == 0)
-    bfd_finalize_section_relocs (obfd, osection, NULL, 0);
+    {
+      if (!bfd_finalize_section_relocs (obfd, osection, NULL, 0))
+       {
+         err = _("unable to finalize relocations");
+         goto loser;
+       }
+    }
   else
     {
       relpp = (arelent **) xmalloc (relsize);
@@ -10651,8 +10657,14 @@ copy_section (bfd *ibfd, sec_ptr isection, void *p)
          goto loser;
        }
 
-      bfd_finalize_section_relocs (obfd, osection,
-                                  relcount == 0 ? NULL : relpp, relcount);
+      if (!bfd_finalize_section_relocs (obfd, osection,
+                                       relcount == 0 ? NULL : relpp,
+                                       relcount))
+       {
+         free (relpp);
+         err = _("unable to finalize relocations");
+         goto loser;
+       }
       if (relcount == 0)
        free (relpp);
     }