[v1,0/4] dwarf2: add hooks for architecture-specific CFIs

Message ID 20240806140744.1082602-1-matthieu.longo@arm.com
Headers
Series dwarf2: add hooks for architecture-specific CFIs |

Message

Matthieu Longo Aug. 6, 2024, 2:07 p.m. UTC
  Architecture-specific CFI directives are currently declared an processed among others architecture-independent CFI directives in gcc/dwarf2* files. This approach creates confusion, specifically in the case of DWARF instructions in the vendor space and using the same instruction code.
Such a clash currently happen between DW_CFA_GNU_window_save (used on SPARC) and DW_CFA_AARCH64_negate_ra_state (used on AArch64), and both having the same instruction code 0x2d. Then AArch64 compilers generates a SPARC CFI directive (.cfi_window_save) instead of .cfi_negate_ra_state, contrarily to what is expected in [1].

1. Rename REG_CFA_TOGGLE_RA_MANGLE to REG_CFA_NEGATE_RA_STATE

This patch renames:
- dwarf2out_frame_debug_cfa_toggle_ra_mangle to dwarf2out_frame_debug_cfa_negate_ra_state,
- REG_CFA_TOGGLE_RA_MANGLE to REG_CFA_NEGATE_RA_STATE,
as the naming was misleading.
The word "toggle" suggested a binary state, whereas this register stores the mangling state (that can be more than 2 states) for the return address on AArch64.

2. dwarf2: add hooks for architecture-specific CFIs

This refactoring does not solve completely the problem, but improve the situation by moving some of the processing of those directives (more specifically their output in the assembly) to the backend via 2 target hooks:
- DW_CFI_OPRND1_DESC: parse the first operand of the directive (if any).
- OUTPUT_CFI_DIRECTIVE: output the CFI directive as a string.
Only AArch64's and SPARC's backend are impacted.

3. aarch64 testsuite: explain expectections for pr94515*
PR94515's tests in AArch64 G++ testsuite were lacking documentation. They are now thoroughly documented.

4. dwarf2: store the RA state in CFI row

On AArch64, the RA state informs the unwinder whether the return address is mangled and how, or not. This information is encoded in a boolean in the CFI row. This binary approach prevents from expressing more complex configuration, as it is the case with PAuth_LR introduced in Armv9.5-A.
This patch addresses this limitation by replacing the boolean by an enum.


References:
[1] DWARF for the Arm 64-bit Architecture (AArch64) --> https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst

## Testing

Built for target aarch64-unknown-linux-gnu and ran GCC's & G++'s testsuites for AArch64.
Built GCC stage 1 for target sparc64-unknown-linux-gnu.


Ok for master? I don't have commit access so I need someone to commit on my behalf.

Regards,
Matthieu.


Matthieu Longo (4):
  Rename REG_CFA_TOGGLE_RA_MANGLE to REG_CFA_NEGATE_RA_STATE
  dwarf2: add hooks for architecture-specific CFIs
  aarch64 testsuite: explain expectections for pr94515* tests
  dwarf2: store the RA state in CFI row

 gcc/combine-stack-adj.cc                     |  2 +-
 gcc/config/aarch64/aarch64.cc                | 36 ++++++++++++-
 gcc/config/sparc/sparc.cc                    | 36 +++++++++++++
 gcc/coretypes.h                              |  6 +++
 gcc/doc/tm.texi                              | 28 ++++++++++
 gcc/doc/tm.texi.in                           | 17 ++++++
 gcc/dwarf2cfi.cc                             | 57 ++++++++++----------
 gcc/dwarf2out.cc                             | 13 +++--
 gcc/dwarf2out.h                              | 10 ++--
 gcc/reg-notes.def                            |  8 +--
 gcc/target.def                               | 20 +++++++
 gcc/testsuite/g++.target/aarch64/pr94515-1.C | 14 +++--
 gcc/testsuite/g++.target/aarch64/pr94515-2.C | 30 ++++++++---
 libffi/include/ffi_cfi.h                     |  2 +
 libgcc/config/aarch64/aarch64-asm.h          |  4 +-
 libitm/config/aarch64/sjlj.S                 | 10 ++--
 16 files changed, 233 insertions(+), 60 deletions(-)