[PATCH,V4 7/9] ld: bfd: sframe: fix incorrect r_offset in RELA entries

Jan Beulich jbeulich@suse.com
Fri Jun 27 07:53:03 GMT 2025


On 19.06.2025 08:24, Indu Bhagat wrote:
> PR/32666  Incorrect .rela.sframe when using ld -r
> 
> Input SFrame sections are merged using _bfd_elf_merge_section_sframe (),
> which clubs all SFrame FDEs together in one blob and all SFrame FREs in
> another.  This, of course, means the offset of an SFrame FDE in the output
> section cannot be simply derived from the output_offset of the sections.
> 
> Fix this by providing _bfd_elf_sframe_section_offset () which returns
> the new offset of the SFrame FDE in the merged SFrame section.
> 
> Unlike EH_Frame sections, which also use the _bfd_elf_section_offset (),
> to update the r_offset, SFrame sections have distinct merging semantics.
> In case of SFrame, the SFrame FDE will not simply sit at location
> "sec->output_offset + offset of SFrame FDE in sec".  Recall that information
> layout in an SFrame section is as follows:
>    SFrame Header
>    SFrame FDE 1
>    SFrame FDE 2
>    ...
>    SFrame FDEn
>    SFrame FREs (Frame Row Entries)
> Note how the SFrame FDEs and SFrame FREs are clubber together in groups
> of their own.
> 
> Next, also note how the elf_link_input_bfd () does a:
>             irela->r_offset += o->output_offset;
> This, however, needs to be avoided for SFrame sections because the
> placement of all FDEs is at the beginning of the section.  So, rather than
> conditionalizing this as follows:
>           if (o->sec_info_type != SEC_INFO_TYPE_SFRAME)
>             irela->r_offset += o->output_offset;
> the implementation in _bfd_elf_sframe_section_offset () does a reverse
> adjustment, so that the generic parts of the linking process in
> elf_link_input_bfd () are not made to do SFrame specific adjustments.
> 
> Add a new enum to track the current state of the SFrame input section
> during the linking process (SFRAME_SEC_DECODED, SFRAME_SEC_MERGED) for
> each input SFrame section.  This is then used to assert an assumption
> that _bfd_elf_sframe_section_offset () is being used on an input SFrame
> sections which have not been merged (via
> _bfd_elf_merge_section_sframe ()) yet.
> 
> bfd/
>         * elf-bfd.h: New declaration.
>         * elf-sframe.c (_bfd_elf_sframe_section_offset): New definition.
>         * elf.c (_bfd_elf_section_offset): Adjust offset if SFrame
> 	section.
> ld/testsuite/
>         * ld-x86-64/x86-64.exp: New test.
>         * ld-x86-64/sframe-reloc-1.d: New test.

While I continue to not be happy about this kind of change, with us having
largely agreed on it being unavoidable, and with ...

> [No changes in V4]
> [No changes in V3]
> [No changes in V2]

... apparently no-one else feeling like approving this: Okay(-ish).

Jan


More information about the Binutils mailing list