From: H.J. Lu Date: Wed, 5 Aug 2026 08:43:05 +0000 (+0800) Subject: ld: Check input section garbage collection error X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;ds=inline;p=thirdparty%2Fbinutils-gdb.git ld: Check input section garbage collection error The ELF backend gc_mark_extra_sections function may return false for error and bfd_gc_sections may return false on invalid input: ld: pr34448-bug_18.o: bad reloc symbol index (0xf2000005 >= 0x13) for offset 0x4 in section `.text.get_tls[get_tls]' Change bfd_elf_gc_sections to return false if gc_mark_extra_sections return false. Change lang_gc_sections to check bfd_gc_sections return and report the fatal error. bfd/ PR ld/34448 * elflink.c (bfd_elf_gc_sections): Return false if gc_mark_extra_sections return false. ld/ PR ld/34448 * ldlang.c (lang_gc_sections): Check bfd_gc_sections return and report the fatal error. Signed-off-by: H.J. Lu --- diff --git a/bfd/elflink.c b/bfd/elflink.c index 11da9a744e2..cc29b99ba56 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -14764,7 +14764,8 @@ bfd_elf_gc_sections (bfd *obfd, struct bfd_link_info *info) } /* Allow the backend to mark additional target specific sections. */ - obed->gc_mark_extra_sections (info, gc_mark_hook); + if (!obed->gc_mark_extra_sections (info, gc_mark_hook)) + return false; /* ... and mark SEC_EXCLUDE for those that go. */ return elf_gc_sweep (obfd, info); diff --git a/ld/ldlang.c b/ld/ldlang.c index 886c49a1861..65494acca00 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -8165,8 +8165,9 @@ lang_gc_sections (void) } } - if (link_info.gc_sections) - bfd_gc_sections (link_info.output_bfd, &link_info); + if (link_info.gc_sections + && !bfd_gc_sections (link_info.output_bfd, &link_info)) + fatal (_("%P: --gc-sections failed: %E\n")); } /* Worker for lang_find_relro_sections_1. */