From 32dc367249e85ecb2449d4be8cafc8e3fc2f359f Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sun, 20 Oct 2024 17:13:31 +1030 Subject: [PATCH] Report bfd_merge_sections error PR 32260 bfd/ * elfxx-target.h (bfd_elfNN_bfd_merge_sections): Default to bfd_generic_merge_sections when using the generic linker. * elflink.c (_bfd_elf_merge_sections): Return error from _bfd_merge_sections. Abort on wrong hash table. ld/ * ldlang.c (lang_process): Report bfd_merge_sections error. --- bfd/elflink.c | 8 ++++---- bfd/elfxx-target.h | 11 ++++++----- ld/ldlang.c | 3 ++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/bfd/elflink.c b/bfd/elflink.c index bcac35a49d7..ef159dafd55 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -8109,8 +8109,8 @@ _bfd_elf_merge_sections (bfd *obfd, struct bfd_link_info *info) bfd *ibfd; asection *sec; - if (!is_elf_hash_table (info->hash)) - return false; + if (ENABLE_CHECKING && !is_elf_hash_table (info->hash)) + abort (); for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) if ((ibfd->flags & DYNAMIC) == 0 @@ -8133,8 +8133,8 @@ _bfd_elf_merge_sections (bfd *obfd, struct bfd_link_info *info) } if (elf_hash_table (info)->merge_info != NULL) - _bfd_merge_sections (obfd, info, elf_hash_table (info)->merge_info, - merge_sections_remove_hook); + return _bfd_merge_sections (obfd, info, elf_hash_table (info)->merge_info, + merge_sections_remove_hook); return true; } diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index 075f1bdd433..d10391dcb43 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -187,11 +187,6 @@ #define bfd_elfNN_bfd_gc_sections bfd_elf_gc_sections #endif -#ifndef bfd_elfNN_bfd_merge_sections -#define bfd_elfNN_bfd_merge_sections \ - _bfd_elf_merge_sections -#endif - #ifndef bfd_elfNN_bfd_is_group_section #define bfd_elfNN_bfd_is_group_section bfd_elf_is_group_section #endif @@ -287,6 +282,9 @@ #ifndef bfd_elfNN_bfd_final_link #define bfd_elfNN_bfd_final_link bfd_elf_final_link #endif +#ifndef bfd_elfNN_bfd_merge_sections +#define bfd_elfNN_bfd_merge_sections _bfd_elf_merge_sections +#endif #else /* ! defined (elf_backend_relocate_section) */ /* If no backend relocate_section routine, use the generic linker. Note - this will prevent the port from being able to use some of @@ -310,6 +308,9 @@ #ifndef bfd_elfNN_bfd_final_link #define bfd_elfNN_bfd_final_link _bfd_generic_final_link #endif +#ifndef bfd_elfNN_bfd_merge_sections +#define bfd_elfNN_bfd_merge_sections bfd_generic_merge_sections +#endif #endif /* ! defined (elf_backend_relocate_section) */ #ifndef bfd_elfNN_bfd_link_just_syms diff --git a/ld/ldlang.c b/ld/ldlang.c index 343c4de53f4..00b214411d6 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -8426,7 +8426,8 @@ lang_process (void) sections, so that GCed sections are not merged, but before assigning dynamic symbols, since removing whole input sections is hard then. */ - bfd_merge_sections (link_info.output_bfd, &link_info); + if (!bfd_merge_sections (link_info.output_bfd, &link_info)) + einfo (_("%F%P: bfd_merge_sections failed: %E\n")); /* Look for a text section and set the readonly attribute in it. */ found = bfd_get_section_by_name (link_info.output_bfd, ".text");