[binutils-gdb] gas: sframe: ignore .cfi_offset for RA selectively

Indu Bhagat ibhagat@sourceware.org
Tue Dec 23 22:59:45 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=18af14d5ef44e200a41a14493be1f1f5ea4e038a

commit 18af14d5ef44e200a41a14493be1f1f5ea4e038a
Author: Indu Bhagat <indu.bhagat@oracle.com>
Date:   Tue Dec 23 14:59:09 2025 -0800

    gas: sframe: ignore .cfi_offset for RA selectively
    
    For ABIs not tracking RA (e.g., AMD64), the return address is expected
    to be in a specific location (usually a fixed offset from CFA on stack).
    Explicit manourvering to a different offset may be non-representable in
    SFrame, and should not be simply ignored.
    
    Although such patterns are not usually seen in the wild, it is more
    correct to catch them if at all they manifest.
    
    Reviewed-by: Jens Remus <jremus@linux.ibm.com>
    
    gas/
            * gen-sframe.c (sframe_xlate_do_offset): Do not ignore
            .cfi_offset for RA all the time.

Diff:
---
 gas/gen-sframe.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index 5b1b1ba23ea..61afd36f105 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -1185,8 +1185,19 @@ sframe_xlate_do_offset (struct sframe_xlate_ctx *xlate_ctx,
      being interpreted.  This FRE eventually gets linked in into the
      list of FREs for the specific function.  */
   struct sframe_row_entry *cur_fre = xlate_ctx->cur_fre;
-
   gas_assert (cur_fre);
+
+  /* For ABIs not tracking RA, the return address is expected to be in a
+     specific location.  Explicit manourvering to a different offset (than the
+     default offset) is non-representable in SFrame.  */
+  if (!sframe_ra_tracking_p () && cfi_insn->u.ri.reg == SFRAME_CFA_RA_REG
+      && cfi_insn->u.ri.offset != sframe_cfa_ra_offset ())
+    {
+      as_warn (_("no SFrame FDE emitted; %s register %u in .cfi_offset"),
+	       sframe_register_name (cfi_insn->u.ri.reg), cfi_insn->u.ri.reg);
+      return SFRAME_XLATE_ERR_NOTREPRESENTED;  /* Not represented.  */
+    }
+
   /* Change the rule for the register indicated by the register number to
      be the specified offset.  */
   /* Ignore SP reg, as it can be recovered from the CFA tracking info.  */


More information about the Binutils-cvs mailing list