[PATCH v2] gas: sframe: Represent .cfi_undefined RA as SFrame FDE without FREs

Indu Bhagat indu.bhagat@oracle.com
Wed Jul 23 05:09:21 GMT 2025


On 7/22/25 8:05 PM, Indu Bhagat wrote:
> On 7/22/25 9:08 AM, Jens Remus wrote:
>> Hello Indu!
>>
>> On 22.07.2025 16:31, Jens Remus wrote:
>>> On 22.07.2025 05:00, Indu Bhagat via Binutils wrote:
>>>> On 7/21/25 9:23 AM, Jens Remus wrote:
>>>>> In DWARF CFI an "undefined" register rule for the return address (RA)
>>>>> register indicates that there is no return address and the stack trace
>>>>> is complete.  Represent DW_CFA_undefined as SFrame FDE without any 
>>>>> FREs,
>>>>> so that a stack tracer implementation can use this as indication that
>>>>> an outermost frame has been reached and the trace is complete.
>>>>>
>>>>> This representation is backwards compatible, as existing stack tracers
>>>>> should already deal with the case, that an SFrame FDE has a FRE 
>>>>> count of
>>>>> zero and stop the trace.
>>>
>>>> While representing the construct "DW_CFA_undefined RA" with an SFrame
>>>> FDE with 0 FREs is OK, I think using this as an unambiguous marker for
>>>> outermost frame may be not be
>>>>
>>>> I think of case when, say, we may need to carry some function-specific
>>>> information in the SFrame FDE, but cannot represent the stack trace
>>>> informtion in SFrame format (for various reasons).  In such a case, we
>>>> may want an SFrame FDE with 0 FREs (with markers on FDE as necessary).
>>>> Yes that implcitly indicates that one cannot stack trace beyond this
>>>> function (as there is no information for stacktracing), but is that
>>>> necessarily the outermost frame? May be not.
>>>>
>>>> Which is why I think for a stack tracer, using "SFrame FDE with 0 FREs"
>>>> _together_ with a marker like FP is zero on AMD64 and FP/LR are zero on
>>>> AArch64 is still reasonable.  If a similar check is not possible for
>>>> s390x as you point out (although I have a question on that, posted on
>>>> the thread on libc-alpha), an option is to use the spare bit in FDE
>>>> func info to unambiguously mark outermost frame along with an SFrame
>>>> FDE with 0 FREs.
>>>
>>> As replied in the other thread on libc-aplha there is no such indication
>>> on s390x (s390 64-bit).  I'll post a V3 of this patch, which introduces
>>> a SFrame FDE infor word flag "ra_undefined".
>>
>> An attempt to build Glibc with my Binutils patch applied fails due to
>> one or more relocation(s) out or range during link.  I guess the .sframe
>> merge logic chokes on a FDE without any FREs.
>>
>> Please let me know if you gave any guess, where I should start.  I will
>> continue tomorrow.
>>
> 
> Jens,
> 
> Sorry havent been able to debug this one yet.  Will try to find some 
> time later tonight..
> 

A possible reason (not confirmed by debugging): In 
sframe_encoder_write_sframe, we do not emit SFrame section if there are 
no FREs:

   if (fr_info == NULL)
     return sframe_set_errno (&err, SFRAME_ERR_FRE_INVAL);

This would cause us to emit no SFrame section, when now we want to emit 
an SFrame section with possibly zero FREs.  In the link you run into 
problems with, there was likely only one object with its .sframe section 
having one SFrame FDE with no FREs among all the inputs.





More information about the Binutils mailing list