[PATCH v4 3/4] gas: sframe: Represent .cfi_undefined RA as FRE without offsets
Indu Bhagat
indu.bhagat@oracle.com
Wed Jul 30 17:50:31 GMT 2025
On 7/30/25 5:38 AM, Jens Remus wrote:
> On 7/30/2025 10:30 AM, Indu Bhagat wrote:
>> On 7/29/25 4:19 AM, Jens Remus wrote:
>
>>> My intend was to set as much of the FRE info word zero as possible,
>>> to make it easier for humans to parse SFrame data for debugging
>>> purposes. I did not touch mangled_ra_p, as I was unsure whether
>>> that can also be unconditionally set to zero. But I guess that
>>> would be fine?
>>>
>>> I used zero, to denote that this is about setting the field to zero
>>> instead of a specific value with an assigned meaning, like
>>> SFRAME_BASE_REG_SP.
>>>
>>> What if I reverted all the changes to the SFrame helpers and did the
>>> following change to output_sframe_row_entry instead, to make that
>>> more explicit?
>>>
>>> /* Create the fre_info using the CFA base register, number of offsets and max
>>> - size of offset in this frame row entry. */
>>> - fre_base_reg = get_fre_base_reg_id (sframe_fre);
>>> - fre_num_offsets = get_fre_num_offsets (sframe_fre);
>>> - fre_offset_size = sframe_get_fre_offset_size (sframe_fre);
>>> + size of offset in this frame row entry. RA undefined is represented
>>> + as FRE without any offsets and all FRE info word fields zeroed. */
>>> + if (sframe_fre->ra_undefined)
>>> + {
>>> + fre_base_reg = 0;
>>> + fre_num_offsets = 0;
>>> + fre_offset_size = 0;
>>> + fre_mangled_ra_p = 0;
>>> + }
>>> + else
>>> + {
>>> + fre_base_reg = get_fre_base_reg_id (sframe_fre);
>>> + fre_num_offsets = get_fre_num_offsets (sframe_fre);
>>> + fre_offset_size = sframe_get_fre_offset_size (sframe_fre);
>>> + fre_mangled_ra_p = sframe_fre->mangled_ra_p;
>>> + }
>>> fre_info = sframe_set_fre_info (fre_base_reg, fre_num_offsets,
>>> - fre_offset_size, sframe_fre->mangled_ra_p);
>>> + fre_offset_size, fre_mangled_ra_p);
>>> out_one (fre_info);
>>>
>>> /* Represent RA undefined as FRE without any offsets. */
>>>
>>> Alternatively:
>>>
>>> fre_info = 0;
>>
>> How about we reset the state of cur_fre when handling the case in
>> sframe_xlate_do_cfi_undefined () itself. Then this handling in
>> output_sframe_row_entry will not be necessary.
>
> Do you happen to know how this is handled in objdump -WF for DWARF?
> I guess it only affects the RA register (return column register).
> So we should not alter any other register rules, such as CFA base
> register, CFA offset, and FP offset. In theory the next FRE could
> define a valid rule for the RA register, no?
>
IIUC, for DWARF, this only affects the RA register rule.
RE: can next FRE define a new valid rule
In theory, the next insns could define a valid rule, yes. But for what
register? For RA, it doesnt make sense to me. For other registers (CFA,
FP), may be ... but again, why and whats the usecase... So, the question
is whether supporting the additional complexity necessary in SFrame ? Is
there a usecase to having a function which is the outermost frame in a
subset of IPs, and not outermost in the other subset ?
My opinion is to not complicate the implementation at this time. I
think for DWARF we know it makes sense, because it is quite flexible and
allows DW_CFA_undefined for any register. But for SFrame, we are
interested in representing a specific case "DW_CFA_undefined RA" which
has a very specific meaning especially if the context is limited to
stack tracing (and not register restoration or stack unwinding). Hence,
we can keep the implementation simple too.
What do you think about:
- When processing a "DW_CFA_undefined RA", we simply skip processing
any further cfi_insn, by returning an error code from
sframe_xlate_do_cfi_undefined (), and then the handling it in
sframe_do_fde to just emit the FDE. Something like:
In sframe_xlate_do_cfi_undefined ():
if (cfi_insn->u.r == SFRAME_CFA_RA_REG)
{
...
return SFRAME_XLATE_ERR_OUTERMOST_FRAME;
}
In sframe_do_fde (), handle the error code to do what is necessary (any
cleanup, linking FDE etc).
So IIRC, similar to what you were doing in your initial patches for
"SFrame FDE with no FREs"
More information about the Binutils
mailing list