public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] RISC-V: PR31733, Change initial CFI operation from DW_CFA_def_cfa_register to DW_CFA_def_cfa
@ 2024-05-20  2:52 Nelson Chu
  0 siblings, 0 replies; only message in thread
From: Nelson Chu @ 2024-05-20  2:52 UTC (permalink / raw)
  To: binutils-cvs

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

commit 3ce12d6d4adb0e3dbdf90628a3e0d37a6ea21512
Author: Sung-hun Kim <sfoon.kim@samsung.com>
Date:   Mon May 13 17:11:49 2024 +0900

    RISC-V: PR31733, Change initial CFI operation from DW_CFA_def_cfa_register to DW_CFA_def_cfa
    
    The DWARF specification (especially, DWARF4 and 5 [1,2]) states that
    DW_CFA_def_cfa_register cannot be used as the first CFI operation.
    It said DW_CFA_def_cfa_register as follows:
    
      ... This operation is valid only if the current CFA rule is defined
      to use a register and offset.
    
    So, DW_CFA_def_cfa_register can be used after that other definition
    operation such as DW_CFA_def_cfa is called. However, the current gas
    code emits DW_CFA_def_cfa_register as an initial CFI operation for RISCV.
    
    In the libgcc, the unwinding function does not care about it, so it can
    unwind the call stack. However, on the third party library such as
    libunwindstack in Android, it causes a fatal error.
    
    This patch changes the initial CFI operation to DW_CFA_def_cfa with
    offset 0. It works as same as the previous one, but it does not have
    any limitation so it satisfies the DWARF spec. This change resolves
    the compatibility issue while preserving the original behaviour.
    
    [1] DWARF4 specification, https://dwarfstd.org/doc/DWARF4.pdf
    [2] DWARF5 specification, https://dwarfstd.org/doc/DWARF5.pdf
    
    Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
    Reviewed-By: Andrew Burgess <aburgess@redhat.com>
    Approved-By: Nelson Chu <nelson@rivosinc.com>
    
    gas/
            PR 31733
            config/tc-riscv.c (riscv_cfi_frame_initial_instructions): Use
            DW_CFA_def_cfa rather than DW_CFA_def_cfa_register.

Diff:
---
 gas/config/tc-riscv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 1757ff6e9e2..8d749581c1d 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -5209,7 +5209,7 @@ RISC-V options:\n\
 void
 riscv_cfi_frame_initial_instructions (void)
 {
-  cfi_add_CFA_def_cfa_register (X_SP);
+  cfi_add_CFA_def_cfa (X_SP, 0);
 }
 
 int

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-20  2:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-20  2:52 [binutils-gdb] RISC-V: PR31733, Change initial CFI operation from DW_CFA_def_cfa_register to DW_CFA_def_cfa Nelson Chu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).