]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
s390: gas: sframe: do not reject .cfi_register REG_SP, REG
authorJens Remus <jremus@linux.ibm.com>
Fri, 16 Jan 2026 00:44:12 +0000 (16:44 -0800)
committerIndu Bhagat <indu.bhagat@oracle.com>
Fri, 16 Jan 2026 01:02:28 +0000 (17:02 -0800)
On s390 64-bit (s390x) compilers may save the SP, FP, and RA registers,
which are of interest in SFrame, in other registers, such as floating-
point registers, for instance when in a leaf function.

SFrame does not explicitly track the SP.  Instead SFrame relies on the
architecture-specific CFA definition to recover the SP.  The s390x ELF
ABI [1] defines the CFA as SP at call site + 160, which results in the
implicit SP recovery rule SP = CFA - 160.

Assuming that CFI on s390 64-bit (s390x) adheres to the CFA definition,
it is safe to ignore any CFI directives, that specify the SP register at
entry to be saved either on the stack or in another register, as the SP
can then always be recovered using the implicit SP recovery rule.

[1]: s390x ELF ABI, https://github.com/IBM/s390x-abi/releases

Committed-by: Indu Bhagat <indu.bhagat@oracle.com>
gas/
* gen-sframe.c (sframe_xlate_do_register): Ignore .cfi_register SP
on s390x.

gas/testsuite/
* gas/cfi-sframe/cfi-sframe.exp (cfi-sframe-s390x-err-4): Rename
test to cfi-sframe-s390x-sp-register.
* gas/cfi-sframe/cfi-sframe-s390x-err-4.d: Rename to ...
* gas/cfi-sframe/cfi-sframe-s390x-err-4.s: Likewise.
* gas/cfi-sframe/cfi-sframe-s390x-sp-register.d: This.  Test
that .cfi_register SP is ignored.
* gas/cfi-sframe/cfi-sframe-s390x-sp-register.s: Likewise.  Add
minimal assembler sample.

gas/gen-sframe.c
gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-4.s [deleted file]
gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-sp-register.d [moved from gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-4.d with 53% similarity]
gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-sp-register.s [new file with mode: 0644]
gas/testsuite/gas/cfi-sframe/cfi-sframe.exp

index 931c14c4b02a244e260b60117f5e2d6f198209b0..0241d4424b6d23de6bb44233bf1c8614f1d503ac 100644 (file)
@@ -1536,7 +1536,8 @@ sframe_xlate_do_register (struct sframe_xlate_ctx *xlate_ctx,
 
   if (cfi_insn->u.rr.reg1 == SFRAME_CFA_RA_REG
       /* SFrame does not track SP explicitly.  */
-      || cfi_insn->u.rr.reg1 == SFRAME_CFA_SP_REG
+      || (cfi_insn->u.rr.reg1 == SFRAME_CFA_SP_REG
+         && sframe_get_abi_arch () != SFRAME_ABI_S390X_ENDIAN_BIG)
       || cfi_insn->u.rr.reg1 == SFRAME_CFA_FP_REG)
     {
       as_warn (_("no SFrame FDE emitted; %s register %u in .cfi_register"),
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-4.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-4.s
deleted file mode 100644 (file)
index 7c0beda..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-       .cfi_sections .sframe
-       .cfi_startproc
-       .cfi_register r15, r5
-       br      %r7
-       .cfi_endproc
similarity index 53%
rename from gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-err-4.d
rename to gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-sp-register.d
index 1703d817ea955f3d52e6dc641be93817138c7954..5203f6dc6538ee3843f0042e857e4b904839a5f5 100644 (file)
@@ -1,6 +1,5 @@
 #name: SFrame generation on s390x - .cfi_register with SP
 #as: --gsframe
-#warning: SP register 15 in \.cfi\_register
 #objdump: --sframe=.sframe
 #...
 Contents of the SFrame section .sframe:
@@ -9,7 +8,14 @@ Contents of the SFrame section .sframe:
 
     Version: SFRAME_VERSION_3
     Flags: SFRAME_F_FDE_FUNC_START_PCREL
-    Num FDEs: 0
-    Num FREs: 0
+    Num FDEs: 1
+    Num FREs: 3
 
+  Function Index :
+
+    func idx \[0\]: pc = 0x0, size = 16 bytes
+    STARTPC +CFA +FP +RA +
+    0+0000 +sp\+160 +u +u +
+    0+000a +sp\+320 +u +u +
+    0+000e +sp\+160 +u +u +
 #pass
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-sp-register.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-s390x-sp-register.s
new file mode 100644 (file)
index 0000000..223588f
--- /dev/null
@@ -0,0 +1,11 @@
+       .cfi_sections .sframe
+       .cfi_startproc
+       ldgr    %f1,%r15
+       .cfi_register r15, f1
+       lay     %r15,-160(%r15)
+       .cfi_adjust_cfa_offset 160
+       lgdr    %r15,%f1
+       .cfi_restore r15
+       .cfi_adjust_cfa_offset -160
+       br      %r14
+       .cfi_endproc
index 3f246d2da243c1586b4a64fe5d981aa0f39337bc..2e0942657ae9e6d05f82cc00633a139bd8da9ff0 100644 (file)
@@ -100,11 +100,11 @@ if { [istarget "s390x*-*-*"] && [gas_sframe_check] } then {
     run_dump_test "cfi-sframe-s390x-2"
     run_dump_test "cfi-sframe-s390x-3"
     run_dump_test "cfi-sframe-s390x-err-3"
-    run_dump_test "cfi-sframe-s390x-err-4"
     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-sp-register"
     run_dump_test "cfi-sframe-s390x-ra-undefined-1"
     run_dump_test "cfi-sframe-s390x-pr33756"
     run_dump_test "cfi-sframe-s390x-non-spfp-cfa-1"