RISCV: gas: Change initial CFI operation from DW_CFA_def_cfa_register to DW_CFA_def_cfa 41/309541/1 accepted/tizen_base_toolchain accepted/tizen_base_x tizen_base_dev accepted/tizen/base/toolchain/20240424.234636 accepted/tizen/base/x/20240417.051715
authorSung-hun Kim <sfoon.kim@samsung.com>
Tue, 26 Mar 2024 07:09:06 +0000 (16:09 +0900)
committerSung-hun Kim <sfoon.kim@samsung.com>
Fri, 12 Apr 2024 04:56:55 +0000 (13:56 +0900)
commita5588a56ce8874e37be66482855b690109d877e3
tree5ea1cf753b1593328afa3ef08e338ec10c7a1885
parent1c6dad168d6badf2f7ce6aae771572dd43f53eb5
RISCV: gas: 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

Change-Id: Ic83af38002d3790de4041c07f2e5d317c4358a1c
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
gas/config/tc-riscv.c