[PATCH] bfd: include: sframe: fix PR ld/32789

Indu Bhagat indu.bhagat@oracle.com
Thu Dec 18 09:57:35 GMT 2025
On 12/17/25 4:25 AM, Jens Remus wrote:
> On 12/16/2025 11:52 PM, Indu Bhagat wrote:
>> Currently, when SFrame sections are emitted after linking the input
>> SFrame sections, the SFrame FDEs are sorted on start PC.  Doing so for
>> relocatable links has no effect (SFrame FDEs remain in place), because
>> the start PC is unrelocated data.  For relocatable links, then, the
>> emitted SFrame FDEs in the output section remain in the same order as
>> that in the respective input BFD.
>>
>> The assembler does not guarantee the emission of SFrame FDEs in the same
>> order as the placement of the associated .text* sections,
>> (SFRAME_F_FDE_SORTED is not set by ET_REL generated by GAS).  This means
>> setting SFRAME_F_FDE_SORTED by the linker was wrong when:
>>    - doing relocatable link, and
>>    - the input bfds contain multiple .text sections, say .text.hot,
>>      .text.init, .text.unlikely etc.
>>
>> For relocatable links, skip sorting the SFrame FDEs.  Do not set
>> SFRAME_F_FDE_SORTED for relocatable links.
>>
>> This is achieved by adding an explicit argument (bool sort_fde_p) to the
>> sframe_encoder_write API.  Move the API from 2.0 to the 2.1 node as this
>> is an ABI-incompatible change.  Skip bumping the "current" in
>> libsframe/libtool-version ATM, we will do so closer to release.
>>
>> When writing of SFrame data for PLT entries, indicate sort_fde_p to
>> false: these sections are like the other SFrame sections for any other
>> ET_REL binary.
>>
>> Add a test in ld/testsuite/ld-sframe/sframe.exp, these tests are run for
>> all ABIs supported for SFrame.  In this test, for object file generated
>> for pr32789-1a.c:
>>    - the emitted SFrame FDEs by GAS are in the order of the .text* in the
>>      input assembly (i.e., .text.init, .text, .text.exit)
>>    - the emitted .text* sections by GAS are placed in the following order
>>      .text, .text.init, .text.exit.
>>    - GAS does not set SFRAME_F_FDE_SORTED, as expected.
>>
>> TBD:
>>    - The testcase is more for documentation purpose than ascertaining a
>>      specific order of the emitted .text.* sections/relas.
>>      Compiler/assembler are free to emit the .text* in any order.  So in
>>      that sense, the testcase may not be appropriate ?
> 
> Maybe only test that neither pr32789-1a.o, pr32789-1b.o, nor pr32789-1.o
> (produced by relocatable link of the former) have SFRAME_F_FDE_SORTED set?
> 

We already have many tests in gas (that check no SFRAME_F_FDE_SORTED for 
ET_REL). So then may be we only check that ld -r output does not set 
SFRAME_F_FDE_SORTED.  But then we lose the documentation side of this 
issue..

FWIW, I checked with clang (although we dont have .sframe support in 
llvm yet), the section order check should not barf.

>>
>> bfd/
>> 	PR ld/32789
>> 	* elf-sframe.c (_bfd_elf_write_section_sframe): Skip sorting the
>> 	SFrame FDEs for relocatable links.
>> 	* elf64-s390.c (_bfd_s390_elf_write_sframe_plt): Additional
>> 	argument to sframe_encoder_write.
>> 	* elfxx-x86.c (_bfd_x86_elf_write_sframe_plt): Likewise.
>> libsframe/
>> 	* libsframe.ver: Move from 2.0 node to 2.1.
>> 	* sframe.c (sframe_encoder_write_sframe): Conditionalize based
>> 	on argument sort_fde_p.
>> 	(sframe_encoder_write): New argument to indicate whether SFrame
>> 	FDEs are to be sorted in output.
>> include/
>> 	* sframe-api.h (sframe_encoder_write): New argument.
>> ld/testsuite/
>> 	PR ld/32789
>> 	* ld/testsuite/ld-sframe/sframe.exp: New test.
>> 	* ld/testsuite/ld-sframe/pr32789-1.rd: New test.
>> 	* ld/testsuite/ld-sframe/pr32789-1.sd: New test.
>> 	* ld/testsuite/ld-sframe/pr32789-1a.c: New test.
>> 	* ld/testsuite/ld-sframe/pr32789-1b.c: New test.
>> 	* ld/testsuite/ld-x86-64/sframe-reloc-1.d: Remove
>> 	SFRAME_F_FDE_SORTED.
>> ---
>>   bfd/elf-sframe.c                        |  3 ++-
>>   bfd/elf64-s390.c                        |  2 +-
>>   bfd/elfxx-x86.c                         |  2 +-
>>   include/sframe-api.h                    |  8 ++++----
>>   ld/testsuite/ld-sframe/pr32789-1.rd     |  9 +++++++++
>>   ld/testsuite/ld-sframe/pr32789-1.sd     |  4 ++++
>>   ld/testsuite/ld-sframe/pr32789-1a.c     | 22 ++++++++++++++++++++++
>>   ld/testsuite/ld-sframe/pr32789-1b.c     | 12 ++++++++++++
>>   ld/testsuite/ld-sframe/sframe.exp       | 16 ++++++++++++++++
>>   ld/testsuite/ld-x86-64/sframe-reloc-1.d |  3 +--
>>   libsframe/libsframe.ver                 |  2 +-
>>   libsframe/sframe.c                      | 23 ++++++++++++-----------
>>   12 files changed, 85 insertions(+), 21 deletions(-)
>>   create mode 100644 ld/testsuite/ld-sframe/pr32789-1.rd
>>   create mode 100644 ld/testsuite/ld-sframe/pr32789-1.sd
>>   create mode 100644 ld/testsuite/ld-sframe/pr32789-1a.c
>>   create mode 100644 ld/testsuite/ld-sframe/pr32789-1b.c
> 
> Reviewed-by: Jens Remus <jremus@linux.ibm.com>
> 
> Regards,
> Jens



More information about the Binutils mailing list