[PATCH] ELF: Properly copy and strip Solaris binaries

H.J. Lu hjl.tools@gmail.com
Sat Dec 27 02:14:03 GMT 2025


Generic ELF binutils copy and strip Solaris binaries without error nor
warning.  But they generate incorrect Solaris output:

1. The SHF_STRINGS bit in sh_flags on SHT_STRTAB sections isn't set.
2. The sh_info and sh_link fields of some Solaris specific sections, like
SHT_SUNW_symsort and SHT_SUNW_symnsort aren't properly set.
3. non-SHF_ALLOC SHT_SUNW_symsort and SHT_SUNW_symnsort sections aren't
removed when all symbols are removed.

Properly copy and strip Solaris binaries:

1. Add the elf_target_os field to struct bfd and set it based on the
EI_OSABI field so that Solaris binaries can be marked.
2. Remove elf_strtab_flags in elf_backend_data and check the target_os
field in elf_backend_data and the elf_target_os field in bfd instead.
3. Update strip to strip non-SHF_ALLOC SHT_SUNW_symsort and
SHT_SUNW_symnsort sections in Solaris binaries when all symbols are
removed.

bfd/

PR binutils/33718
* bfd-in2.h: Regenerated.
* bfd.c (bfd_elf_target_os): New.
(bfd): Add elf_target_os.
* elf-bfd.h (elf_target_os): Removed.
(elf_link_hash_table): Replace "enum elf_target_os" with
"enum bfd_elf_target_os".
(elf_backend_data): Likewise.  Remove elf_strtab_flags.
(_bfd_elf_get_strtab_flags): New.
* elf.c (_bfd_elf_compute_section_file_positions): Replace
bed->elf_strtab_flags with _bfd_elf_get_strtab_flags.
(swap_out_syms): Likewise.
(_bfd_elf_solaris_copy_special_section_fields): New.
* elf32-i386.c (elf_backend_strtab_flags): Removed.
* elf32-sparc.c (elf_backend_strtab_flags): Likewise.
* elf64-sparc.c (elf_backend_strtab_flags): Likewise.
* elf64-x86-64.c (elf_backend_strtab_flags): Likewise.
* elfcode.h (elf_object_p): Set elf_target_os for
ELFOSABI_SOLARIS.
* elflink.c (bfd_elf_final_link): Call _bfd_elf_get_strtab_flags
to get sh_flags.
* elfxx-target.h (elf_backend_strtab_flags): Removed.
(elfNN_bed): Remove elf_backend_strtab_flags.

binutils/

PR binutils/33718
* objcopy.c (is_strip_section_1): Remove non-SHF_ALLOC
SHT_SUNW_symsort and SHT_SUNW_symnsort sections linked with
non-SHF_ALLOC SHT_SYMTAB section for STRIP_ALL on Solaris
binary.
(copy_object): Copy elf_target_os for ELF binary.
* testsuite/binutils-all/x86-64/solaris-objcopy.rd: New file.
* testsuite/binutils-all/x86-64/solaris-strip.rd: Likewise.
* testsuite/binutils-all/x86-64/solaris.so.bz2: Likewise.
* testsuite/binutils-all/x86-64/x86-64.exp (run_solaris_test):
New.
Run Solaris tests.

ld/

PR binutils/33718
* testsuite/ld-i386/i386.exp: Run solaris-1 if -melf_i386_sol2
is supported.
* testsuite/ld-i386/solaris-1.d: New file.
* testsuite/ld-x86-64/solaris-1.d: Likewise.
* testsuite/ld-x86-64/solaris-1.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run solaris-1 if elf_x86_64_sol2
is supported.


-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ELF-Properly-copy-and-strip-Solaris-binaries.patch
Type: text/x-patch
Size: 31724 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20251227/9eaf9c99/attachment-0001.bin>


More information about the Binutils mailing list