[PATCH v3] elf: Keep unused section symbols for Solaris binary

Jan Beulich jbeulich@suse.com
Tue Dec 9 07:31:10 GMT 2025


On 09.12.2025 08:18, H.J. Lu wrote:
> On Mon, Dec 8, 2025 at 3:52 PM Jan Beulich <jbeulich@suse.com> wrote:
>>
>> On 06.12.2025 04:04, H.J. Lu wrote:
>>> After
>>>
>>> commit d1bcae833b32f1408485ce69f844dcd7ded093a8
>>> Author: H.J. Lu <hjl.tools@gmail.com>
>>> Date:   Thu Jan 7 06:42:00 2021 -0800
>>>
>>>     ELF: Don't generate unused section symbols
>>>
>>> x86 ELF binutils tools no longer generate unused section symbols.  But
>>> Solaris binary generated by Solaris linker may include symbol sort
>>> sections which hold indexes of data and function symbols, sorted by name
>>> or by address.  When objcopy removes section symbols, it corrupts Solaris
>>> symbol sort sections since symbol indexes are changed.  Keep section
>>> symbols for Solaris binary.
>>>
>>> PR binutils/33684
>>> * objcopy.c (copy_object): Keep section symbols if input is a
>>> Solaris binary and output target is the same as input target.
>>
>> Hmm, an open-coded OSABI check in objcopy. I was expecting change in libbfd
>> to e.g. make bfd_keep_unused_section_symbols() on ibfd true for Solaris, to
>> then copy that property to obfd. Is there a reason to not try to somewhat
>> abstract what is wanted / needed?
> 
> Here is the v3 patch with the updated bfd_keep_unused_section_symbols.
> 
> After
> 
> commit d1bcae833b32f1408485ce69f844dcd7ded093a8
> Author: H.J. Lu <hjl.tools@gmail.com>
> Date:   Thu Jan 7 06:42:00 2021 -0800
> 
>     ELF: Don't generate unused section symbols
> 
> x86 ELF binutils tools no longer generate unused section symbols.  But
> Solaris binary generated by Solaris linker may include symbol sort
> sections which hold indexes of data and function symbols, sorted by name
> or by address.  When objcopy removes section symbols, it corrupts Solaris
> symbol sort sections since symbol indexes are changed.
> 
> 1. Update bfd_keep_unused_section_symbols to return true for Solaris
> binary.
> 2. Keep section symbols if input section symbols should be kept and
> output target is the same as input target.

This is okay afaic, but please give Rainer and/or Ali a chance to comment.

Irrespective I have a question here, though (perhaps also to Alan and Nick):
Isn't it wrong for objcopy to remove _any_ symbols (including section ones)
without an explicit request to do so? IOW shouldn't objcopy without any
specific options largely generate an output identical to the input?

Jan


More information about the Binutils mailing list