[v1,0/4] aarch64: add DWARF and SFrame support for new CFI directive used for PAuth_LR

Message ID 20241125162846.94691-1-matthieu.longo@arm.com
Headers
Series aarch64: add DWARF and SFrame support for new CFI directive used for PAuth_LR |

Message

Matthieu Longo Nov. 25, 2024, 4:28 p.m. UTC
  This patch series is based on the feedback obtained from a previous review [1].
This is in no way a complete implementation of PAuth_LR, and only focuses on DWARF and SFrame.

## Context:

The Pointer Authentication (PAuth) feature provides instructions that enable software to sign an address using SP as a diversifier. This form of PAC instruction is typically used for signing return addresses that are stored on the stack.
The new Armv9.5-A architecture introduces an enhancement of the previous PAuth feature, called PAuth_LR. It aims at hardening the PAC in a signed return address. When signing the return address in LR, the PC is used as a diversifier, in addition to the SP to generate the PAC code.

## Details

1. Patches 1/4 and 2/4 clarify which CFI directive should be used on AArch64 for PAuth. In GCC 14 and older, the AArch64 GCC backend emits a directive corresponding to a Sparc DWARF extension (".cfi_gnu_window_save" instead of ".cfi_negate_ra_state"). This behavior contradicts the document for DWARF extensions on AArch64 (see [2]). In practice, this behavior didn't have any consequence as the two CFI directives share the same binary encoding (0x2d), but from a developer perspective, created confusion when looking at the generated assembly. This issue was fixed in GCC 15 [3], but this behavior is preserved in binutils for backward compatibility with older versions of GCC.
2. Patch 3/4 defines the new CFI directive .cfi_negate_ra_state_with_pc for PAuth_LR, and adds support for it into DWARF.
3. Patch 4/4 skips the new CFI directive and emits a warning, before failing to generate the FDE entry.

Regression tested on aarch64-none-linux-gnu, and no regression found.

Ok for binutils-master?

Regards,
Matthieu.

[1]: https://inbox.sourceware.org/binutils/20241108152505.3554049-1-matthieu.longo@arm.com/
[2]: https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst#id1
[3]: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=9e1c71bab50d51a1a8ec1a75080ffde6ca3d854c

Matthieu Longo (4):
  aarch64: make explicit that CFI gnu_window_save is for Sparc, not
    AArch64
  aarch64 SFrame: use preferred CFI directive for AArch64 PAC
  aarch64 DWARF: add new CFI directive for PAuth_LR
  aarch64 SFrame: skip with warning new CFI directive used with pauth_lr

 bfd/elf-eh-frame.c                            |  1 +
 binutils/dwarf.c                              |  5 ++++
 gas/dw2gencfi.c                               | 10 +++++++
 gas/gen-sframe.c                              | 24 ++++++++++++++++-
 gas/scfidw2gen.c                              |  1 +
 gas/testsuite/gas/aarch64/pac_ab_key.s        |  4 +--
 .../gas/aarch64/pac_compat_cfi_window_save.d  | 26 +++++++++++++++++++
 .../gas/aarch64/pac_compat_cfi_window_save.s  | 20 ++++++++++++++
 .../gas/cfi-sframe/cfi-sframe-aarch64-3.d     | 20 ++++++++++++++
 .../gas/cfi-sframe/cfi-sframe-aarch64-3.s     | 21 +++++++++++++++
 .../gas/cfi-sframe/cfi-sframe-aarch64-4.d     | 25 ++++++++++++++++++
 .../gas/cfi-sframe/cfi-sframe-aarch64-4.s     | 23 ++++++++++++++++
 .../cfi-sframe-aarch64-pac-ab-key-1.s         |  8 +++---
 gas/testsuite/gas/cfi-sframe/cfi-sframe.exp   |  2 ++
 include/dwarf2.def                            |  4 ++-
 15 files changed, 186 insertions(+), 8 deletions(-)
 create mode 100644 gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.d
 create mode 100644 gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.s
 create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-3.d
 create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-3.s
 create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-4.d
 create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-4.s