[binutils-gdb] PR 33718 objcopy and strip of Solaris binaries

Alan Modra amodra@sourceware.org
Wed Jan 28 01:32:22 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1f6f7f5083f6ff3fdc25d1a8b84bb3e34a5ea9db

commit 1f6f7f5083f6ff3fdc25d1a8b84bb3e34a5ea9db
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat Dec 27 09:00:08 2025 +0800

    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:
---
 binutils/objcopy.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

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;


More information about the Binutils-cvs mailing list