From: H.J. Lu Date: Sat, 27 Dec 2025 01:00:08 +0000 (+0800) Subject: PR 33718 objcopy and strip of Solaris binaries X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f6f7f5083f6ff3fdc25d1a8b84bb3e34a5ea9db;p=thirdparty%2Fbinutils-gdb.git PR 33718 objcopy and strip of Solaris binaries non-SHF_ALLOC SHT_SUNW_symsort and SHT_SUNW_symnsort sections aren't removed when all symbols are removed. Fix that. PR 33718 PR 33684 * objcopy.c (is_strip_section_1): Handle SHT_SUNW_symsort and SHT_SUNW_symnsort sections. --- diff --git a/binutils/objcopy.c b/binutils/objcopy.c index fdd8bd11799..2098c7b5b3e 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -1346,8 +1346,39 @@ is_mergeable_note_section (bfd * abfd, asection * sec) /* See if a non-group section is being removed. */ static bool -is_strip_section_1 (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) +is_strip_section_1 (bfd *abfd, asection *sec) { + if (strip_symbols == STRIP_ALL + && bfd_get_flavour (abfd) == bfd_target_elf_flavour + && elf_elfheader (abfd)->e_ident[EI_OSABI] == ELFOSABI_SOLARIS) + { + struct bfd_elf_section_data *e = elf_section_data (sec); + Elf_Internal_Shdr **sections = elf_elfsections (abfd); + switch (e->this_hdr.sh_type) + { + case SHT_SUNW_symsort: + case SHT_SUNW_symnsort: + /* On Solaris, non-SHF_ALLOC SHT_SUNW_symsort and + SHT_SUNW_symnsort sections are linked with a non-SHF_ALLOC + SHT_SYMTAB section. Since strip removes non-SHF_ALLOC + SHT_SYMTAB section with STRIP_ALL, also remove non-SHF_ALLOC + SHT_SUNW_symsort and SHT_SUNW_symnsort sections. */ + if ((e->this_hdr.sh_flags & SHF_ALLOC) == 0 + && sections != NULL + && e->this_hdr.sh_link < elf_numsections (abfd)) + { + Elf_Internal_Shdr *l = sections[e->this_hdr.sh_link]; + if (l->sh_type == SHT_SYMTAB + && (l->sh_flags & SHF_ALLOC) == 0) + return true; + } + break; + + default: + break; + } + } + if (find_section_list (bfd_section_name (sec), false, SECTION_CONTEXT_KEEP) != NULL) return false;