[binutils-gdb] gas: sframe: fix handling of .cfi_def_cfa_register

Indu Bhagat ibhagat@sourceware.org
Thu Apr 24 15:37:20 GMT 2025


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

commit 3602da6fa285d6b22d87bcc39056e919e939ef07
Author: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Date:   Tue Apr 15 12:20:40 2025 +0300

    gas: sframe: fix handling of .cfi_def_cfa_register
    
    Fix PR gas/32879 sframe: Assembler internal error when translating
    cfi_def_cfa_register
    
    As per the documentation, .cfi_def_cfa_register modifies a rule for
    computing CFA; the register is updated, but the offset remains the same.
    
    While translating .cfi_def_cfa_register into SFrame context, we use the
    information from last translated FRE to set the CFA offset. However,
    there may be cases when the last translated FRE is empty.  Use last FRE
    only if available.
    
    Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
    Signed-off-by: Indu Bhagat <indu.bhagat@oracle.com>

Diff:
---
 gas/gen-sframe.c                                   |  4 +++-
 gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.d | 21 +++++++++++++++++++++
 gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.s |  4 ++++
 gas/testsuite/gas/cfi-sframe/cfi-sframe.exp        |  1 +
 4 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index 5b5e7b14b3a..5c8c7ebb175 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -1038,7 +1038,9 @@ sframe_xlate_do_def_cfa_register (struct sframe_xlate_ctx *xlate_ctx,
       return SFRAME_XLATE_ERR_NOTREPRESENTED; /* Not represented.  */
     }
   sframe_fre_set_cfa_base_reg (cur_fre, cfi_insn->u.r);
-  sframe_fre_set_cfa_offset (cur_fre, last_fre->cfa_offset);
+  if (last_fre)
+    sframe_fre_set_cfa_offset (cur_fre, last_fre->cfa_offset);
+
   cur_fre->merge_candidate = false;
 
   return SFRAME_XLATE_OK;
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.d
new file mode 100644
index 00000000000..d779b6d126e
--- /dev/null
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.d
@@ -0,0 +1,21 @@
+#as: --gsframe
+#objdump: --sframe=.sframe
+#name: Check .cfi_def_cfa_register with no previous offset
+#...
+Contents of the SFrame section .sframe:
+
+  Header :
+
+    Version: SFRAME_VERSION_2
+    Flags: NONE
+#?    CFA fixed FP offset: \-?\d+
+#?    CFA fixed RA offset: \-?\d+
+    Num FDEs: 1
+    Num FREs: 1
+
+  Function Index :
+
+    func idx \[0\]: pc = 0x0, size = 0 bytes
+    STARTPC +CFA +FP +RA +
+    0+0000 +fp\+8 +u +f +
+#pass
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.s
new file mode 100644
index 00000000000..f3f985985e1
--- /dev/null
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.s
@@ -0,0 +1,4 @@
+# Although not a useful construct by itself, ensure graceful handling.
+	.cfi_startproc
+	.cfi_def_cfa_register 6
+	.cfi_endproc
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
index a09946635c2..b353e27ce56 100644
--- a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
@@ -90,6 +90,7 @@ if { [istarget "x86_64-*-*"] && [gas_sframe_check] } then {
     if { [gas_x86_64_check] } then {
 	set ASFLAGS "$ASFLAGS --64"
 	run_dump_test "cfi-sframe-x86_64-1"
+	run_dump_test "cfi-sframe-x86_64-2"
 	run_dump_test "cfi-sframe-x86_64-empty-1"
 	run_dump_test "cfi-sframe-x86_64-empty-2"
 	run_dump_test "cfi-sframe-x86_64-empty-3"


More information about the Binutils-cvs mailing list