[PATCH,V2 4/4] gas: sframe: handle .cfi_same_value

Jens Remus jremus@linux.ibm.com
Fri May 16 16:02:20 GMT 2025


Hello Indu!

On 15.05.2025 23:06, Indu Bhagat wrote:
> Fix PR gas/32953 - sframe: incorrect handling of .cfi_same_value in gas
> 
> As per documentation, .cfi_same_value indicates that the current value
> of register is the same like in the previous frame, i.e. no restoration
> needed.
> 
> In some cases, SFrame has no means to encode this information.  Warn and
> skip generating the SFrame FDE in those cases.

> diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c

> +   SFrame based stacktracers will implement CFA-based SP recovery for all ABIs:
> +   SP for previous frame is based on the applicable CFA-rule.  There is no
> +   representation in SFrame to indicate "no restoration needed" for REG_SP.  So
> +   skip generating the SFrame FDE if DW_CFA_same_value is seen for
> +   SFRAME_CFA_SP_REG.

I think SFrame should treat .cfi_same_value <SP> the same way as
.cfi_restore <SP>.  That is ignore, as a SFrame based stack tracer will
restore SP using the implicit CFA-rule anyway.  At least SFrame should
treat both in the same way (either ignore or skip emitting the FDE).

This is different from .cfi_same_value <RA>, which resets any previous rule
for RA, as for SP there is always the implicit rule.

Another argument to ignore is that SFrame does also ignore
.cfi_offset <SP>, <offset>, which would define a rule for SP that SFrame
cannot represent.  But given the implicit CFA-rule it can safely ignore it.

> +static int
> +sframe_xlate_do_same_value (const struct sframe_xlate_ctx *xlate_ctx,
> +			    const struct cfi_insn_data *cfi_insn)
> +{
> +  /* For some cases, SFrame cannot encode such information.  */
> +  if (cfi_insn->u.r == SFRAME_CFA_SP_REG
> +      || (!sframe_ra_tracking_p () && cfi_insn->u.r == SFRAME_CFA_RA_REG))
> +    {
> +      as_warn (_("no SFrame FDE emitted; %s reg %u in .cfi_same_value"),
> +	       sframe_register_name (cfi_insn->u.r), cfi_insn->u.r);
> +      return SFRAME_XLATE_ERR_NOTREPRESENTED; /* Not represented.  */
> +    }

Regards,
Jens
-- 
Jens Remus
Linux on Z Development (D3303)
+49-7031-16-1128 Office
jremus@de.ibm.com

IBM

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/



More information about the Binutils mailing list