]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR 33718 objcopy and strip of Solaris binaries
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 27 Dec 2025 01:00:08 +0000 (09:00 +0800)
committerAlan Modra <amodra@gmail.com>
Wed, 28 Jan 2026 01:20:47 +0000 (11:50 +1030)
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.

binutils/objcopy.c

index fdd8bd11799618678a778d84e2f089776db19c61..2098c7b5b3e44f3146a42ed345752a1a8995dbe8 100644 (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;