WIP MachO binutils port assisted by AI I may consider upstreaming this in the future.
0

Configure Feed

Select the types of activity you want to include in your feed.

BFD: Make `bfd_finalize_section_relocs' return status

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.

Maciej W. Rozycki (Jan 14, 2026, 10:28 PM UTC) ca2186f9 e9499dfe

+54 -26
+2 -2
bfd/bfd-in2.h
··· 2613 2613 long bfd_canonicalize_reloc 2614 2614 (bfd *abfd, asection *sec, arelent **loc, asymbol **syms); 2615 2615 2616 - void bfd_finalize_section_relocs 2616 + bool bfd_finalize_section_relocs 2617 2617 (bfd *abfd, asection *sec, arelent **rel, unsigned int count); 2618 2618 2619 2619 #define bfd_finalize_section_relocs(abfd, asect, location, count) \ ··· 7664 7664 long (*_get_reloc_upper_bound) (bfd *, sec_ptr); 7665 7665 long (*_bfd_canonicalize_reloc) (bfd *, sec_ptr, arelent **, 7666 7666 struct bfd_symbol **); 7667 - void (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **, 7667 + bool (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **, 7668 7668 unsigned int); 7669 7669 /* See documentation on reloc types. */ 7670 7670 reloc_howto_type *
+1 -1
bfd/bfd.c
··· 2202 2202 bfd_finalize_section_relocs 2203 2203 2204 2204 SYNOPSIS 2205 - void bfd_finalize_section_relocs 2205 + bool bfd_finalize_section_relocs 2206 2206 (bfd *abfd, asection *sec, arelent **rel, unsigned int count); 2207 2207 2208 2208 DESCRIPTION
+2 -1
bfd/elf64-sparc.c
··· 314 314 315 315 /* Install a new set of internal relocs. */ 316 316 317 - static void 317 + static bool 318 318 elf64_sparc_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED, 319 319 asection *asect, 320 320 arelent **location, ··· 326 326 asect->flags |= SEC_RELOC; 327 327 else 328 328 asect->flags &= ~SEC_RELOC; 329 + return true; 329 330 } 330 331 331 332 /* Write out the relocs. */
+1 -1
bfd/libbfd-in.h
··· 447 447 (bfd *, asection *) ATTRIBUTE_HIDDEN; 448 448 extern long _bfd_norelocs_canonicalize_reloc 449 449 (bfd *, asection *, arelent **, asymbol **) ATTRIBUTE_HIDDEN; 450 - extern void _bfd_norelocs_finalize_section_relocs 450 + extern bool _bfd_norelocs_finalize_section_relocs 451 451 (bfd *, asection *, arelent **, unsigned int) ATTRIBUTE_HIDDEN; 452 452 extern reloc_howto_type *_bfd_norelocs_bfd_reloc_type_lookup 453 453 (bfd *, bfd_reloc_code_real_type) ATTRIBUTE_HIDDEN;
+2 -2
bfd/libbfd.c
··· 199 199 return 0; 200 200 } 201 201 202 - void 202 + bool 203 203 _bfd_norelocs_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED, 204 204 asection *sec ATTRIBUTE_UNUSED, 205 205 arelent **relptr ATTRIBUTE_UNUSED, 206 206 unsigned int count ATTRIBUTE_UNUSED) 207 207 { 208 - /* Do nothing. */ 208 + return true; 209 209 } 210 210 211 211 bool
+2 -2
bfd/libbfd.h
··· 453 453 (bfd *, asection *) ATTRIBUTE_HIDDEN; 454 454 extern long _bfd_norelocs_canonicalize_reloc 455 455 (bfd *, asection *, arelent **, asymbol **) ATTRIBUTE_HIDDEN; 456 - extern void _bfd_norelocs_finalize_section_relocs 456 + extern bool _bfd_norelocs_finalize_section_relocs 457 457 (bfd *, asection *, arelent **, unsigned int) ATTRIBUTE_HIDDEN; 458 458 extern reloc_howto_type *_bfd_norelocs_bfd_reloc_type_lookup 459 459 (bfd *, bfd_reloc_code_real_type) ATTRIBUTE_HIDDEN; ··· 3530 3530 bool relocatable, 3531 3531 asymbol **symbols) ATTRIBUTE_HIDDEN; 3532 3532 3533 - void _bfd_generic_finalize_section_relocs 3533 + bool _bfd_generic_finalize_section_relocs 3534 3534 (bfd *abfd, 3535 3535 sec_ptr section, 3536 3536 arelent **relptr,
+3 -2
bfd/reloc.c
··· 8365 8365 _bfd_generic_finalize_section_relocs 8366 8366 8367 8367 SYNOPSIS 8368 - void _bfd_generic_finalize_section_relocs 8368 + bool _bfd_generic_finalize_section_relocs 8369 8369 (bfd *abfd, 8370 8370 sec_ptr section, 8371 8371 arelent **relptr, ··· 8375 8375 Installs a new set of internal relocations in SECTION. 8376 8376 */ 8377 8377 8378 - void 8378 + bool 8379 8379 _bfd_generic_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED, 8380 8380 sec_ptr section, 8381 8381 arelent **relptr, ··· 8387 8387 section->flags |= SEC_RELOC; 8388 8388 else 8389 8389 section->flags &= ~SEC_RELOC; 8390 + return true; 8390 8391 } 8391 8392 8392 8393 /*
+1 -1
bfd/targets.c
··· 438 438 . long (*_get_reloc_upper_bound) (bfd *, sec_ptr); 439 439 . long (*_bfd_canonicalize_reloc) (bfd *, sec_ptr, arelent **, 440 440 . struct bfd_symbol **); 441 - . void (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **, 441 + . bool (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **, 442 442 . unsigned int); 443 443 . {* See documentation on reloc types. *} 444 444 . reloc_howto_type *
+8 -3
binutils/objcopy.c
··· 4555 4555 } 4556 4556 4557 4557 if (relsize == 0) 4558 - bfd_finalize_section_relocs (obfd, osection, NULL, 0); 4558 + { 4559 + if (!bfd_finalize_section_relocs (obfd, osection, NULL, 0)) 4560 + return false; 4561 + } 4559 4562 else 4560 4563 { 4561 4564 if (isection->orelocation != NULL) ··· 4596 4599 *w_relpp = 0; 4597 4600 } 4598 4601 4599 - bfd_finalize_section_relocs (obfd, osection, 4600 - relcount == 0 ? NULL : relpp, relcount); 4602 + if (!bfd_finalize_section_relocs (obfd, osection, 4603 + relcount == 0 ? NULL : relpp, 4604 + relcount)) 4605 + return false; 4601 4606 } 4602 4607 return true; 4603 4608 }
+7 -1
binutils/rescoff.c
··· 685 685 return false; 686 686 } 687 687 688 - bfd_finalize_section_relocs (abfd, sec, cwi.relocs, cwi.reloc_count); 688 + if (!bfd_finalize_section_relocs (abfd, sec, cwi.relocs, cwi.reloc_count)) 689 + { 690 + bfd_nonfatal ("bfd_finalize_section_relocs"); 691 + bfd_close_all_done (abfd); 692 + free (cwi.relocs); 693 + return false; 694 + } 689 695 690 696 offset = 0; 691 697 for (d = cwi.dirs.d; d != NULL; d = d->next)
+4 -2
gas/config/obj-coff.c
··· 1517 1517 /* Set relocations for the section and then store the number of relocations 1518 1518 in its aux entry. */ 1519 1519 1520 - void 1520 + bool 1521 1521 obj_coff_finalize_section_relocs (asection *sec, arelent **relocs, 1522 1522 unsigned int n) 1523 1523 { 1524 1524 symbolS *sect_sym; 1525 1525 1526 - bfd_finalize_section_relocs (stdoutput, sec, n ? relocs : NULL, n); 1526 + if (!bfd_finalize_section_relocs (stdoutput, sec, n ? relocs : NULL, n)) 1527 + return false; 1527 1528 sect_sym = section_symbol (sec); 1528 1529 #ifdef OBJ_XCOFF 1529 1530 if (S_GET_STORAGE_CLASS (sect_sym) == C_DWARF) ··· 1531 1532 else 1532 1533 #endif 1533 1534 SA_SET_SCN_NRELOC (sect_sym, n); 1535 + return true; 1534 1536 } 1535 1537 1536 1538 /* Implement the .section pseudo op:
+1 -1
gas/config/obj-coff.h
··· 296 296 /* We need to store the number of relocations in the section aux entry. */ 297 297 #define FINALIZE_SECTION_RELOCS(sec, relocs, n) \ 298 298 obj_coff_finalize_section_relocs (sec, relocs, n) 299 - extern void obj_coff_finalize_section_relocs (asection *, arelent **, 299 + extern bool obj_coff_finalize_section_relocs (asection *, arelent **, 300 300 unsigned int); 301 301 302 302 extern int S_SET_DATA_TYPE (symbolS *, int);
+2 -2
gas/config/obj-macho.c
··· 1879 1879 1880 1880 /* Reverse relocations order to make ld happy. */ 1881 1881 1882 - void 1882 + bool 1883 1883 obj_mach_o_reorder_section_relocs (asection *sec, arelent **rels, unsigned int n) 1884 1884 { 1885 1885 unsigned int i; ··· 1891 1891 rels[i] = rels[n - i - 1]; 1892 1892 rels[n - i - 1] = r; 1893 1893 } 1894 - bfd_finalize_section_relocs (stdoutput, sec, rels, n); 1894 + return bfd_finalize_section_relocs (stdoutput, sec, rels, n); 1895 1895 } 1896 1896 1897 1897 /* Relocation rules are different in frame sections. */
+1 -1
gas/config/obj-macho.h
··· 101 101 102 102 #define FINALIZE_SECTION_RELOCS(sec, relocs, n) \ 103 103 obj_mach_o_reorder_section_relocs (sec, relocs, n) 104 - extern void obj_mach_o_reorder_section_relocs (asection *, arelent **, 104 + extern bool obj_mach_o_reorder_section_relocs (asection *, arelent **, 105 105 unsigned int); 106 106 107 107 /* Emit relocs for local subtracts, to cater for subsections-via-symbols. */
+2 -1
gas/write.c
··· 1419 1419 } 1420 1420 #endif 1421 1421 1422 - FINALIZE_SECTION_RELOCS (sec, relocs, n); 1422 + if (!FINALIZE_SECTION_RELOCS (sec, relocs, n)) 1423 + as_bad (_("%s: unable to finalize relocations"), sec->name); 1423 1424 1424 1425 #ifdef DEBUG3 1425 1426 {
+15 -3
ld/ldlang.c
··· 10640 10640 } 10641 10641 10642 10642 if (relsize == 0) 10643 - bfd_finalize_section_relocs (obfd, osection, NULL, 0); 10643 + { 10644 + if (!bfd_finalize_section_relocs (obfd, osection, NULL, 0)) 10645 + { 10646 + err = _("unable to finalize relocations"); 10647 + goto loser; 10648 + } 10649 + } 10644 10650 else 10645 10651 { 10646 10652 relpp = (arelent **) xmalloc (relsize); ··· 10651 10657 goto loser; 10652 10658 } 10653 10659 10654 - bfd_finalize_section_relocs (obfd, osection, 10655 - relcount == 0 ? NULL : relpp, relcount); 10660 + if (!bfd_finalize_section_relocs (obfd, osection, 10661 + relcount == 0 ? NULL : relpp, 10662 + relcount)) 10663 + { 10664 + free (relpp); 10665 + err = _("unable to finalize relocations"); 10666 + goto loser; 10667 + } 10656 10668 if (relcount == 0) 10657 10669 free (relpp); 10658 10670 }