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.
This commit is contained in:
H.J. Lu
2026-01-28 11:50:47 +10:30
committed by Alan Modra
parent e8108cc5e6
commit 1f6f7f5083
+32 -1
View File
@@ -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;