[PATCH v3 3/3] gas: sframe: Represent .cfi_undefined RA

Indu Bhagat indu.bhagat@oracle.com
Fri Jul 25 00:26:23 GMT 2025


On 7/23/25 6:17 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.
> 
> Introduce a SFrame FDE info word flag "RA undefined".  Represent
> DW_CFA_undefined as SFrame FDE without any FREs and FDE info word flag
> "RA undefined" set, so that a stack tracer implementation can use this
> as indication that an outermost frame has been reached and the stack
> trace is complete.
> 
> This representation is backward 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.  Furthermore the new FDE info word flag
> "RA undefined" was previously unused and therefore not set.  Stack
> tracers can therefore rely on FDE without FREs and RA undefined set
> as indication for an outermost frame.
> 
> include/
> 	* sframe.h (FDE info word): New RA undefined flag.
> 	(SFRAME_V2_FUNC_RA_UNDEF, SFRAME_V2_FUNC_INFO_UPDATE_RA_UNDEF):
> 	New macros to get and set the RA undefined flag.
> 
> gas/
> 	* gen-sframe.h (struct sframe_func_entry): Add ra_undefined
> 	flag.
> 	(struct sframe_xlate_ctx): Likewise.
> 	(enum sframe_xlate_err): Add SFRAME_XLATE_RA_UNDEFINED.
> 	(struct sframe_version_ops): Add parameter for ra_undefined to
> 	set_func_info.
> 	* gen-sframe.c (sframe_xlate_ctx_init): Initialize ra_undefined
> 	flag to not set.
> 	(sframe_xlate_ctx_finalize): Copy ra_undefined flag from
> 	translation context to SFrame FDE.
> 	(sframe_v1_set_func_info): Rename to ...
> 	(sframe_v2_set_func_info): ... this, require new parameter
> 	ra_undefined, and use its value to set SFrame FDE info word flag
> 	"RA undefined".
> 	(sframe_set_version): Wire sframe_v2_set_func_info as versioned
> 	operation set_func_info
> 	(sframe_set_func_info): Require new parameter ra_undefined and
> 	pass it to versioned operation set_func_info.
> 	(output_sframe_funcdesc): Pass RA undefined flag to
> 	sframe_set_func_info.
> 	(sframe_xlate_do_cfi_undefined): Represent
> 	DW_CFA_undefined RA as SFrame FDE without and SFrame FREs and
> 	RA undefined flag set, and return SFRAME_XLATE_RA_UNDEFINED to
> 	stop any further processing of DWARF CFI.
> 	(sframe_do_fde): Add comment that RA undefined stops processing
> 	of further DWARF FREs.
> 	(create_sframe_all): Handle SFRAME_XLATE_RA_UNDEFINED with
> 	zero FREs as good case.
> 	(output_sframe_funcdesc): For FDEs without any FREs set the
> 	start FRE offset to zero.
> 
> libsframe/
> 	* doc/sframe-spec.texi (Changes from Version 1 to Version 2):
> 	Mention that a SFrame FDE without any FREs and RA undefined
> 	flag indicates an outermost frame with an "undefined" RA
> 	register rule.
> 	(sfde_func_num_fres): Document that a FRE count of zero in
> 	combination with the RA undefined flag indicates an outermost
> 	frame with an "undefined" RA register rule.
> 	(The SFrame FDE Info Word): Document RA undefined flag.
> 	* sframe-dump.c (dump_sframe_func_with_fres): Dump RA undefined
> 	flag.
> 
> gas/testsuite/
> 	* gas/cfi-sframe/cfi-sframe.exp: Run tests for .cfi_undefined RA
> 	on AArch64, s390x, and x86-64.
> 	* gas/cfi-sframe/cfi-sframe-aarch64-ra-undefined-1.d: Add test
> 	for .cfi_undefined RA on AArch64.
> 	* gas/cfi-sframe/cfi-sframe-aarch64-ra-undefined-1.s: Likewise.
> 	* as/cfi-sframe/cfi-sframe-s390x-ra-undefined-1.d: Add test
> 	for .cfi_undefined RA on s390x.
> 	* gas/cfi-sframe/cfi-sframe-s390x-ra-undefined-1.s: Likewise.
> 	* gas/cfi-sframe/cfi-sframe-x86_64-ra-undefined-1.d: Add test
> 	for .cfi_undefined RA on x86-64.
> 	* gas/cfi-sframe/cfi-sframe-x86_64-ra-undefined-1.s: Likewise.
> 
> Signed-off-by: Jens Remus <jremus@linux.ibm.com>
> ---
> 
> Notes (jremus):
>      Changes in V3:
>      - Introduce a FDE info word flag ra_undefined.  Represent RA undefined
>        as FDE without any FREs and the ra_undefined flag set. (Indu)
>      - Set sfde_func_start_fre_off to zero, if FDE without any FREs.
>      - In x86-64 tests use spaces to separate mnemonic from operands. (Indu)
>      - Reword commit subject, commit message, and GNU ChangeLog.
>      
>      An alternative to introducing a FDE info word flag ra_undefined would
>      be to repurpose the FRE offset in the FDE to carry indications, if
>      the FRE count is zero.  While that would be easy in the assembler to
>      generate and easy for a stack tracer to process it would require
>      a few modifications in libsframe to preserve those special FRE offset
>      values.
>      
>      Wouldn't it make sense to remove the half baked versioned operations
>      (see struct sframe_version_ops) with a preparatory cleanup patch?  I
>      don't see how the current implementation would work in the future.
>      The operations would otherwise probably need to be split up into
>      smaller ones: fde_info_init(fde_type, fre_type), fde_info_set_pauth_key,
>      fde_info_set_ra_undefined, ... .
>      
>      Changes in V2:
>      - Use sframe_xlate_ctx_init to re-initialize translation context.
>      - Reword comment on sframe_xlate_do_cfi_escape.
>      - Reword comment in sframe_do_fde for SFRAME_XLATE_RA_UNDEFINED.
>      - Reword comment in create_sframe_all for SFRAME_XLATE_RA_UNDEFINED.
>      
>      Representing .cfi_undefined RA as SFrame FDE without any FREs is a
>      simplification compared to DWARF CFI, as the latter can represent
>      RA undefined for a range of PCs within a DWARF FDE.  An alternative
>      would have been to represent .cfi_undefined RA as SFrame FRE without
>      any offsets, which would have provided the same versatility.  Note
>      that the current choice to represent this at a SFrame FDE level
>      does not prevent to represent it at a SFrame FRE level in addition
>      in the future.
> 

Looks like SFrame FRE with 0 offsets has merits over SFrame FDE with 0 
FREs after all.  They are not "equivalent" in terms of conveyance of 
information we thought previously.  We know better now that SFrame FDE 
with 0 FREs will need to be accompanied with an additional bit in the 
SFrame FDE func info.  But SFrame FRE with 0 offsets seems more 
reasonable now because we at least save the precious bit in SFrame FDE 
func info.  Does it make more sense to you to go with SFrame FRE with 0 
offsets rather ?

If we chose SFrame FRE with 0 offsets, we dont need to indicate any 
further in the FRE func info word either.


More information about the Binutils mailing list