[PATCH v2] elf: Keep section symbols for Solaris binary

Ali Bahrami Ali.Bahrami@Oracle.COM
Sat Dec 6 16:31:56 GMT 2025


On 12/5/25 20:04, H.J. Lu wrote:
> On Fri, Dec 5, 2025 at 1:31 AM Ali Bahrami <Ali.Bahrami@oracle.com> wrote:
>>
>> [I've dropped the binutils alias for the moment]
>>
>> On 12/4/25 02:36, Jan Beulich wrote:
>>> On 04.12.2025 02:20, 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 linkers no longer generate unused section symbols.  But Solaris
>>>> symbol sort sections generated by Solaris linker use section symbols.
>>>> When objcopy removes section symbols, it corrupts Solaris symbol sort
>>>> sections.  Add section_symbol_used to bfd and set it when Solaris symbol
>>>> sort sections are used.  Keep section symbols if section_symbol_used is
>>>> set.
>>>>
>>>> PR binutils/33684
>>>> * bfd-in2.h: Regenerated.
>>>> * bfd.c (bfd): Add section_symbol_used.
>>>> * elf.c (_bfd_elf_copy_private_section_data): Set
>>>> section_symbol_used if there are Solaris symbol sort sections.
>>>> * targets.c (bfd_keep_unused_section_symbols): Also return true
>>>> if section_symbol_used is set.
>>>
>>> This looks okay to me, but I'd like to ask Ali or Rainer to confirm.
>>>
>>> Jan
>>
>>
>>      As you'll see on the bug thread, I was pushing for
>> a different solution last night that doesn't specifically
>> check for the sort sections, but simply keys off the
>> ELFOSABI_SOLARIS setting in the ELF header.
>>
>>       https://urldefense.com/v3/__https://sourceware.org/bugzilla/show_bug.cgi?id=33684__;!!ACWV5N9M2RV99hQ!JbrcfZ8ogu1uw3OkfNSJv-CLQ98-0w7fe4BHqaRp7w7nBPQA-tO6RHrRmsaoAXd8fUiCYgAU4U6Y2tWYtBo$
>>
>> I understand that removing the section symbols is an x86
>> binutils optimization, and I don't have a problem with that,
>> but it's breaking expectations in our world, and I think it
>> would be simpler to disable it, rather than maintain code
>> that looks for specific sections. The OSABI setting is an
>> easy way to recognize Solaris objects, and opt them out.
>>
>> I did however just apply the patch as it stands. While it
>> applies cleanly, the result doesn't build on Solaris. I
>> don't build binutils often, and may have botched something,
>> so I'll ask Rainer to double check.
>>
> 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.
> 

    I added the patch for this latest version, which
takes the osabi approach, and built binutils for Solaris.
The resulting objcopy preserves the section symbol and
appears to resolve the issue. Thank You.

- Ali



More information about the Binutils mailing list