[PATCH 2/4] gas: sframe: i386: have the backend specify the RA too

Jan Beulich jbeulich@suse.com
Tue May 13 12:57:00 GMT 2025
On 11.05.2025 09:35, Indu Bhagat wrote:
> To process some CFI directives like .cfi_undefined and .cfi_same_value,
> it is necessary for correctness to detect all cases when the register
> used is one of SP, FP or RA.
> 
> Currently, the backends needed to specify the RA only in the case of
> those ABIs where RA tracking was necessary, e.g. AArch64.  For AMD64,
> since the return address is always at a fixed offset from the CFA, RA
> tracking was disabled.  That now needs to change as we should detect the
> cases when RA is used like so:
>    .cfi_undefined <RA>
> or,
>    .cfi_same_value <RA>

I can't really make sense of this: As you say, the return address on x86
is on the stack, not in a register. Yet both directives want a register
specified. See also below. (In fact it's unclear to me what

	.cfi_same_value rip

would actually mean: %rip is neither preserved nor can it remain
unmodified.)

> @@ -3656,6 +3657,7 @@ md_begin (void)
>  #ifdef OBJ_ELF
>        x86_sframe_cfa_sp_reg = REG_SP;
>        x86_sframe_cfa_fp_reg = REG_FP;
> +      x86_sframe_cfa_ra_reg = 16;

Along the lines of the earlier comment asking to have a #define for this
number - what would the identifier be? Not REG_RA, I would say, as that's
not appropriate on x86, where there's conceptually no such register. Yet
REG_IP also doesn't look right, as you're after the return address here.

> --- a/gas/config/tc-i386.h
> +++ b/gas/config/tc-i386.h
> @@ -462,6 +462,12 @@ extern unsigned int x86_sframe_cfa_sp_reg;
>  extern unsigned int x86_sframe_cfa_fp_reg;
>  #define SFRAME_CFA_FP_REG x86_sframe_cfa_fp_reg
>  
> +/* The return address DWARF register number for SFrame purposes.  Although for
> +   AMD64, RA tracking is disabled, specific constructs, like for indicating
> +   the _start function, may use it.  */
> +extern unsigned int x86_sframe_cfa_ra_reg;
> +#define SFRAME_CFA_RA_REG x86_sframe_cfa_ra_reg

Why is it, btw, that this needs a variable which never changes? IOW why
not simply

#define SFRAME_CFA_RA_REG REG_<whatever>

? Same actually goes for x86_sframe_cfa_{fp,sp}_reg as well.

Jan


More information about the Binutils mailing list