[binutils-gdb] gas: sframe: Fix non-SP/FP CFA base register if flexible FDE

Jens Remus jremus@sourceware.org
Wed Aug 12 12:40:43 GMT 2026


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

commit 87027fd2372d79a3f44605efdeba8a4d7c41093a
Author: Jens Remus <jremus@linux.ibm.com>
Date:   Wed Aug 12 14:39:50 2026 +0200

    gas: sframe: Fix non-SP/FP CFA base register if flexible FDE
    
    .cfi_def_cfa_offset modifies the current CFA rule to use the provided
    offset but keep the current CFA base register.  It therefore requires
    a CFA base register to be in effect.  Relax the check to simply test
    for whether a CFA base register is in effect instead of restricting
    it to SP/FP.  The latter is checked when the CFA base register is
    modified.
    
    This enables .cfi_def_cfa_offset with non-SP/FP CFA base register for
    targets that support SFrame flexible FDE.
    
    While at it simplify the logic to test for error cases first.
    
    gas/
            * gen-sframe.c (sframe_xlate_do_def_cfa_offset): Allow non-SP/FP
            CFA base register if flexible FDE.
    
    Signed-off-by: Jens Remus <jremus@linux.ibm.com>

Diff:
---
 gas/gen-sframe.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index 7b8c2f2f20e..031421d8ab7 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -1362,31 +1362,23 @@ sframe_xlate_do_def_cfa_offset (struct sframe_xlate_ctx *xlate_ctx,
 
   gas_assert (cur_fre);
   /*  Define the current CFA rule to use the provided offset (but to keep
-      the old register).  However, if the old register is not FP/SP,
+      the old register).  However, if the old register is invalid,
       skip creating SFrame stack trace info for the function.  */
-  if (cur_cfa_reg == SFRAME_CFA_FP_REG || cur_cfa_reg == SFRAME_CFA_SP_REG)
+  if (cur_cfa_reg == SFRAME_FRE_REG_INVALID)
     {
-      if (sframe_fre_stack_offset_bound_p (cfi_insn->u.i, true))
-	{
-	  sframe_fre_set_cfa_offset (cur_fre, cfi_insn->u.i);
-	  cur_fre->merge_candidate = false;
-	}
-      else
-	{
-	  as_warn (_("no SFrame FDE emitted; "
-		     ".cfi_def_cfa_offset with unsupported offset value"));
-	  return SFRAME_XLATE_ERR_NOTREPRESENTED;
-	}
+      as_warn (_("no SFrame FDE emitted; "
+		 ".cfi_def_cfa_offset without CFA base register in effect"));
+      return SFRAME_XLATE_ERR_NOTREPRESENTED;
     }
-  else
+
+  if (!sframe_fre_stack_offset_bound_p (cfi_insn->u.i, true))
     {
-      /* No CFA base register in effect.  Non-SP/FP CFA base register should
-	 not occur, as sframe_xlate_do_def_cfa[_register] would detect this.  */
       as_warn (_("no SFrame FDE emitted; "
-		 ".cfi_def_cfa_offset without CFA base register in effect"));
+		 ".cfi_def_cfa_offset with unsupported offset value"));
       return SFRAME_XLATE_ERR_NOTREPRESENTED;
     }
 
+  sframe_fre_set_cfa_offset (cur_fre, cfi_insn->u.i);
   return SFRAME_XLATE_OK;
 }


More information about the Binutils-cvs mailing list