[PATCH, V2 3/9] include: libsframe: add APIs for offsetof FDE func start addr field
Indu Bhagat
indu.bhagat@oracle.com
Sat Jun 7 05:32:57 GMT 2025
On 6/6/25 2:49 AM, Jan Beulich wrote:
> On 04.06.2025 09:08, Indu Bhagat via Binutils wrote:
>> @@ -1016,6 +1017,29 @@ sframe_decoder_get_fixed_ra_offset (sframe_decoder_ctx *ctx)
>> return dhp->sfh_cfa_fixed_ra_offset;
>> }
>>
>> +/* Get the offset of the sfde_func_start_address field (from the start of the
>> + on-disk layout of the SFrame section) of the FDE at FUNC_IDX in the decoder
>> + context DCTX.
>> +
>> + If FUNC_IDX is more than the number of SFrame FDEs in the section, sets
>> + error code in ERRP, but returns the (hypothetical) offset. This is useful
>> + for the linker when arranging input FDEs into the output section to be
>> + emitted. */
>
> Is this somewhat odd behavior really needed for both encoder and decoder sides?
>
Speaking abstractly, such behavior should be necessary only for an
SFrame encoder object, one that is used when creating a new output
section where SFrame FDEs are being placed. Because one would need to
know the (hypothetical) offsetof_fde_start_addr to adjust the
fde_start_addr value _before_ passing to:
int
sframe_encoder_add_funcdesc_v2 (sframe_encoder_ctx *encoder,
int32_t start_addr,
uint32_t func_size,
unsigned char func_info,
uint8_t rep_block_size,
uint32_t num_fres);
Which then updates the number of SFrame FDEs in the encoder object.
The behavior of returning the (hypothetical if applicable) offset on the
SFrame decoder side had to be done because for the _first_ input SFrame
section, at the time when we invoke _bfd_elf_section_offset () (which
then invokes _bfd_elf_sframe_section_offset () to get the new offset),
an SFrame encoder object is not yet setup.
ATM, an SFrame encoder object is first setup when an SFrame section is
ready for linking (after relocation). At this time, in
_bfd_elf_merge_section_sframe (), encoder context object is created if
it is NULL. This is a good time I think, especially because all the
_bfd_elf_discard_section_sframe () are done by now. All this to say
that if the initialization of the SFrame encoder is at its desirable
location, there cannot be a sframe_encoder_ctx* at the time of
_bfd_elf_discard_section_sframe.
The option then would be to do it selectively in
_bfd_elf_discard_section_sframe. Something to the likes of:
if (!sfe_ctx)
new_offset = sframe_decoder_get_offsetof_fde_start_addr (sfd_ctx,
out_num_fdes -1);
else
new_offset = sframe_encoder_get_offsetof_fde_start_addr (sfe_ctx,
out_num_fdes - 1,
NULL);
Then we can get rid of the behavior of returning hypothetical offset in
sframe_decoder_get_offsetof_fde_start_addr.
But I thought, making the two APIs behave similarly wasnt too bad
either. Hence the choice.
More information about the Binutils
mailing list