[PATCH 4/5] libsframe: make flip_header version aware
Indu Bhagat
indu.bhagat@oracle.com
Fri Oct 17 18:50:33 GMT 2025
On 10/17/25 4:00 AM, Jens Remus wrote:
> Hello Indu!
>
> On 10/17/2025 9:05 AM, Indu Bhagat via Binutils wrote:
>> Future versions of the format may have alternative representation of an
>> FDE. As the format evolves, endian flipping will need to be version
>> aware.
>>
>> flip_header now takes the SFrame version as argument. Currently unused,
>> this argument will be used later when we introduce SFrame V3.
>>
>> SFrame encoder, at the momemnt, writes the SFrame data in the most recent
>> format version by default.
>>
>> libsframe/
>> * sframe.c (flip_header): Make version aware.
>> (sframe_decode): Adjust usage of flup_header.
>> (sframe_encoder_write): Likewise.
>
>> diff --git a/libsframe/sframe.c b/libsframe/sframe.c
>
>> +static int
>> +flip_header (char *buf, uint8_t ver ATTRIBUTE_UNUSED)
>
> flip_header (char *buf, size_t size, uint8_t ver ATTRIBUTE_UNUSED)
>
The decoder logic already checks this before invoking flipping.
Similarly for encoder too, the malloc'd buffer does account for hdr
size. So, I think this is not necessary.
> Btw. how is passing VER into the helper expected to work? Wouldn't it
> only be known in advance when encoding. How would it work for decoding?
>
I guess I just added the extra arg to flip_header for consistency and I
thought its more flexible that way...
For decoder, we will indeed be passing the version value from the buffer
as "flip_header (tempbuf, sfp->sfp_version))". Similarly on the encoder
side: even though we pass SFRAME_VERSION, this will be the same value as
that in encoder header.
If the additional arg ver looks confusing for flip_header, we can remove
it...
>> +{
>> + /* SFrame header binary format has remained the same in SFRAME_VERSION_1,
>> + SFRAME_VERSION_2. */
>> + sframe_header *sfh = (sframe_header *) buf;
>
> if (size < sizeof (sframe_header))
> return SFRAME_ERR;
>
> Or SFRAME_ERR_BUF_INVAL or the like.
>
>> + swap_thing (sfh->sfh_preamble.sfp_magic);
>> + swap_thing (sfh->sfh_preamble.sfp_version);
>> + swap_thing (sfh->sfh_preamble.sfp_flags);
>> + swap_thing (sfh->sfh_abi_arch);
>> + swap_thing (sfh->sfh_cfa_fixed_fp_offset);
>> + swap_thing (sfh->sfh_cfa_fixed_ra_offset);
>> + swap_thing (sfh->sfh_auxhdr_len);
>> + swap_thing (sfh->sfh_num_fdes);
>> + swap_thing (sfh->sfh_num_fres);
>> + swap_thing (sfh->sfh_fre_len);
>> + swap_thing (sfh->sfh_fdeoff);
>> + swap_thing (sfh->sfh_freoff);
>> +
>> + /* Alert for missing functionatlity. Auxiliary header, if present, needs to
>> + flipped based on per abi/arch semantics. */
>> + if (sfh->sfh_auxhdr_len)
>> + return SFRAME_ERR;
>> +
>> + return 0;
>> }
> Thanks and regards,
> Jens
More information about the Binutils
mailing list