[binutils-gdb/jremus/sframe-v3-s390x] s390: sframe: gas: Represent .cfi_def_cfa[_register] for non-SP/FP reg. using FLEX_TOPMOST_FRAME

Jens Remus jremus@sourceware.org
Mon Dec 15 16:26:02 GMT 2025


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

commit b4e5e9e6700aec17a36c189f19ae587ded31640c
Author: Jens Remus <jremus@linux.ibm.com>
Date:   Fri Dec 12 16:03:33 2025 +0100

    s390: sframe: gas: Represent .cfi_def_cfa[_register] for non-SP/FP reg. using FLEX_TOPMOST_FRAME
    
    Signed-off-by: Jens Remus <jremus@linux.ibm.com>

Diff:
---
 gas/gen-sframe.c                                   | 17 +++++++--------
 .../gas/cfi-sframe/cfi-sframe-s390x-err-1.d        | 15 --------------
 .../gas/cfi-sframe/cfi-sframe-s390x-err-2.d        | 15 --------------
 .../cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-1.d   | 24 ++++++++++++++++++++++
 ...x-err-1.s => cfi-sframe-s390x-non-spfp-cfa-1.s} |  0
 .../cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-2.d   | 24 ++++++++++++++++++++++
 ...x-err-2.s => cfi-sframe-s390x-non-spfp-cfa-2.s} |  0
 gas/testsuite/gas/cfi-sframe/cfi-sframe.exp        |  4 ++--
 8 files changed, 59 insertions(+), 40 deletions(-)

diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index f00811adfc3..af656eda4e1 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -1259,15 +1259,15 @@ sframe_xlate_do_def_cfa (struct sframe_xlate_ctx *xlate_ctx,
      SFrame V3 specification, if the CFA register is not FP/SP, SFrame FDE type
      SFRAME_FDE_TYPE_FLEX_TOPMOST_FRAME type may be used.
 
-     ATM however, GAS implements non-SP/FP based CFA only for AMD64, where such
-     a CFA pattern may be seen (e.g., DRAP, stack alignment).  On s390x, this
-     may be seen for (GCC) generated code for static stack clash protection.
-     This remains sufficiently rare and is currently unimplemented for s390x.
-     */
+     ATM however, GAS implements non-SP/FP based CFA only for:
+     - AMD64, where such a CFA pattern may be seen (e.g., DRAP, stack alignment).
+     - s390x, where this may be seen for (GCC) generated code for static stack
+       clash protection.  */
   if (cfi_insn->u.ri.reg != SFRAME_CFA_SP_REG
       && cfi_insn->u.ri.reg != SFRAME_CFA_FP_REG)
     {
-      if (sframe_get_abi_arch () != SFRAME_ABI_AMD64_ENDIAN_LITTLE
+      if ((sframe_get_abi_arch () != SFRAME_ABI_AMD64_ENDIAN_LITTLE
+	   && sframe_get_abi_arch () != SFRAME_ABI_S390X_ENDIAN_BIG)
 	  || !sframe_fre_reg_encodable_p (cfi_insn->u.ri.reg))
 	{
 	  as_warn (_("no SFrame FDE emitted; "
@@ -1305,7 +1305,8 @@ sframe_xlate_do_def_cfa_register (struct sframe_xlate_ctx *xlate_ctx,
   if (cfi_insn->u.r != SFRAME_CFA_SP_REG
       && cfi_insn->u.r != SFRAME_CFA_FP_REG)
     {
-      if (sframe_get_abi_arch () != SFRAME_ABI_AMD64_ENDIAN_LITTLE)
+      if (sframe_get_abi_arch () != SFRAME_ABI_AMD64_ENDIAN_LITTLE
+	  && sframe_get_abi_arch () != SFRAME_ABI_S390X_ENDIAN_BIG)
 	{
 	  as_warn (_("no SFrame FDE emitted; "
 		     "non-SP/FP register %u in .cfi_def_cfa_register"),
@@ -1314,7 +1315,7 @@ sframe_xlate_do_def_cfa_register (struct sframe_xlate_ctx *xlate_ctx,
 	}
       else
 	/* Currently, SFRAME_FDE_TYPE_FLEX_TOPMOST_FRAME is generated for AMD64
-	   only.  */
+	   and s390x only.  */
 	xlate_ctx->flex_topmost_p = true;
     }
 
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-1.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-1.d
deleted file mode 100644
index 5cd31c7da00..00000000000
--- a/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-1.d
+++ /dev/null
@@ -1,15 +0,0 @@
-#name: SFrame generation on s390x - .cfi_def_cfa_register with non-SP/FP register
-#as: --gsframe
-#warning: non-SP/FP register 10 in \.cfi_def_cfa_register
-#objdump: --sframe=.sframe
-#...
-Contents of the SFrame section .sframe:
-
-  Header :
-
-    Version: SFRAME_VERSION_3
-    Flags: SFRAME_F_FDE_FUNC_START_PCREL
-    Num FDEs: 0
-    Num FREs: 0
-
-#pass
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-2.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-2.d
deleted file mode 100644
index 0397cd84c05..00000000000
--- a/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-2.d
+++ /dev/null
@@ -1,15 +0,0 @@
-#name: SFrame generation on s390x - .cfi_def_cfa with non-SP/FP register
-#as: --gsframe
-#warning: non-SP/FP register 10 in \.cfi_def_cfa
-#objdump: --sframe=.sframe
-#...
-Contents of the SFrame section .sframe:
-
-  Header :
-
-    Version: SFRAME_VERSION_3
-    Flags: SFRAME_F_FDE_FUNC_START_PCREL
-    Num FDEs: 0
-    Num FREs: 0
-
-#pass
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-1.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-1.d
new file mode 100644
index 00000000000..cda55cdef40
--- /dev/null
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-1.d
@@ -0,0 +1,24 @@
+#name: SFrame generation on s390x - .cfi_def_cfa_register with non-SP/FP register
+#as: --gsframe
+#objdump: --sframe=.sframe
+#...
+Contents of the SFrame section .sframe:
+
+  Header :
+
+    Version: SFRAME_VERSION_3
+    Flags: SFRAME_F_FDE_FUNC_START_PCREL
+    Num FDEs: 1
+    Num FREs: 6
+
+  Function Index :
+
+    func idx \[0\]: pc = 0x0, size = 40 bytes
+    STARTPC +CFA +FP +RA +
+    0+0000 +sp\+160 +u +u +
+    0+0006 +sp\+160 +c\-72 +c\-48 +
+    0+000c +sp\+320 +c\-72 +c\-48 +
+    0+0010 +r10\+320 +c\-72 +c\-48 +
+    0+001c +sp\+160 +u +u +
+    0+001e +r10\+320 +c\-72 +c\-48 +
+#pass
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-1.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-1.s
similarity index 100%
rename from gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-1.s
rename to gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-1.s
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-2.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-2.d
new file mode 100644
index 00000000000..b750bfd03fe
--- /dev/null
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-2.d
@@ -0,0 +1,24 @@
+#name: SFrame generation on s390x - .cfi_def_cfa with non-SP/FP register
+#as: --gsframe
+#objdump: --sframe=.sframe
+#...
+Contents of the SFrame section .sframe:
+
+  Header :
+
+    Version: SFRAME_VERSION_3
+    Flags: SFRAME_F_FDE_FUNC_START_PCREL
+    Num FDEs: 1
+    Num FREs: 6
+
+  Function Index :
+
+    func idx \[0\]: pc = 0x0, size = 40 bytes
+    STARTPC +CFA +FP +RA +
+    0+0000 +sp\+160 +u +u +
+    0+0006 +sp\+160 +c\-72 +c\-48 +
+    0+000c +sp\+320 +c\-72 +c\-48 +
+    0+0010 +r10\+320 +c\-72 +c\-48 +
+    0+001c +sp\+160 +u +u +
+    0+001e +r10\+320 +c\-72 +c\-48 +
+#pass
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-2.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-2.s
similarity index 100%
rename from gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-2.s
rename to gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-2.s
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
index aefa4c91d49..754e9a52488 100644
--- a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
@@ -93,12 +93,12 @@ if { [istarget "s390x*-*-*"] && [gas_sframe_check] } then {
     run_dump_test "cfi-sframe-s390x-1"
     run_dump_test "cfi-sframe-s390x-2"
     run_dump_test "cfi-sframe-s390x-3"
-    run_dump_test "cfi-sframe-s390x-err-1"
-    run_dump_test "cfi-sframe-s390x-err-2"
     run_dump_test "cfi-sframe-s390x-err-3"
     run_dump_test "cfi-sframe-s390x-fpra-offset-1"
     run_dump_test "cfi-sframe-s390x-fpra-offset-2"
     run_dump_test "cfi-sframe-s390x-fpra-register-1"
     run_dump_test "cfi-sframe-s390x-fpra-register-2"
     run_dump_test "cfi-sframe-s390x-ra-undefined-1"
+    run_dump_test "cfi-sframe-s390x-non-spfp-cfa-1"
+    run_dump_test "cfi-sframe-s390x-non-spfp-cfa-2"
 }


More information about the Binutils-cvs mailing list