]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
aarch64 SFrame: use preferred CFI directive for AArch64 PAC
authorMatthieu Longo <matthieu.longo@arm.com>
Thu, 21 Nov 2024 18:40:41 +0000 (18:40 +0000)
committerMatthieu Longo <matthieu.longo@arm.com>
Tue, 14 Jan 2025 10:53:21 +0000 (10:53 +0000)
ARMv8.3 addded support for a new security feature named Pointer
Authentication. Support for this feature in SFrame already exists.

In GCC 14 and older, the Sparc DWARF extension .cfi_gnu_window_save
is emitted instead of .cfi_negate_ra_state.
GCC 15 fixed this issue, but this behavior is preserved for backward
compatibility.

The existing sframe test for AArch64 PAC was using .cfi_gnu_window_save.
This patch replaces this CFI in the existing test by the preferred one,
and adds a new test to check for backward compatibility when using
.cfi_gnu_window_save.

Approved-by: Indu Bhagat <indu.bhagat@oracle.com>
gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-3.d [new file with mode: 0644]
gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-3.s [new file with mode: 0644]
gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-pac-ab-key-1.s
gas/testsuite/gas/cfi-sframe/cfi-sframe.exp

diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-3.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-3.d
new file mode 100644 (file)
index 0000000..f72b70a
--- /dev/null
@@ -0,0 +1,20 @@
+#as: --gsframe
+#objdump: --sframe=.sframe
+#name: SFrame cfi_negate_ra_state test (using cfi_window_save)
+#...
+Contents of the SFrame section .sframe:
+
+  Header :
+
+    Version: SFRAME_VERSION_2
+    Flags: NONE
+    Num FDEs: 1
+    Num FREs: 2
+
+  Function Index :
+    func idx \[0\]: pc = 0x0, size = 8 bytes
+    STARTPC + CFA + FP + RA +
+#...
+    0+0004 +sp\+16 +u +u\[s\] +
+
+#pass
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-3.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-aarch64-3.s
new file mode 100644 (file)
index 0000000..de96b20
--- /dev/null
@@ -0,0 +1,26 @@
+## ARMv8.3 adds support for a new security feature named Pointer Authentication.
+## The main idea behind this is to use the unused bits in the pointer values.
+## Each pointer is patched with a PAC before writing to memory, and is verified
+## before using it.
+## When the pointers are mangled, the stack trace generator needs to know so it
+## can mask off the PAC from the pointer value to recover the return address,
+## and conversely, skip doing so if the pointers are not mangled.
+##
+## .cfi_negate_ra_state CFI directive is usually used to convey this information.
+## .cfi_negate_ra_state and .cfi_window_save are both in the processor-specific
+## numbering space, but use the same code value in the dwarf tables.
+## In GCC 14 and older, the Sparc DWARF extension .cfi_window_save is emitted
+## instead of .cfi_negate_ra_state, but it mapped to the same value. GCC 15 fixed
+## this naming issue and there is no change to the object file created when the
+## source is assembled. Nevertheless the support for the SPARC directive is
+## preserved in binutils for backward compatibility with existing GCC releases,
+## hence this test.
+##
+## SFrame has support for this. This testcase ensures that the directive
+## is interpreted successfully.
+       .cfi_startproc
+       .long 0
+       .cfi_def_cfa_offset 16
+       .cfi_window_save // really .cfi_negate_ra_state
+       .long 0
+       .cfi_endproc
index d9a408c668c43c943c9caaa10119183a24fa13cc..84230a99e3cf2cfbc3e73f3a5e5d5bf86670eede 100644 (file)
@@ -8,12 +8,12 @@ _Z5foo_av:
 .LFB0:
        .cfi_startproc
        hint    25 // paciasp
-       .cfi_window_save
+       .cfi_negate_ra_state
        stp     x29, x30, [sp, -16]!
        .cfi_def_cfa_offset 16
        .cfi_offset 29, -16
        .cfi_offset 30, -8
-        ret
+       ret
        .cfi_endproc
 .LFE0:
        .size   _Z5foo_av, .-_Z5foo_av
@@ -25,12 +25,12 @@ _Z5foo_bv:
        .cfi_startproc
        .cfi_b_key_frame
        hint    27 // pacibsp
-       .cfi_window_save
+       .cfi_negate_ra_state
        stp     x29, x30, [sp, -16]!
        .cfi_def_cfa_offset 16
        .cfi_offset 29, -16
        .cfi_offset 30, -8
        nop
        nop
-        ret
+       ret
        .cfi_endproc
index 48eb0ed2182ad12e20a58b66bf48f909403a26a5..1de2c9f8037e38dfc2eed7d2b8f7491661ce87ec 100644 (file)
@@ -97,5 +97,6 @@ if { [istarget "x86_64-*-*"] && [gas_sframe_check] } then {
 if { [istarget "aarch64*-*-*"] && [gas_sframe_check] } then {
     run_dump_test "cfi-sframe-aarch64-1"
     run_dump_test "cfi-sframe-aarch64-2"
+    run_dump_test "cfi-sframe-aarch64-3"
     run_dump_test "cfi-sframe-aarch64-pac-ab-key-1"
 }