[PATCH 6/15] arm: Add pointer authentication for stack-unwinding runtime
authorAndrea Corallo <andrea.corallo@arm.com>
Mon, 6 Dec 2021 10:42:11 +0000 (11:42 +0100)
committerAndrea Corallo <andrea.corallo@arm.com>
Mon, 23 Jan 2023 10:28:11 +0000 (11:28 +0100)
commit7161afc778699b90edafbcd750b2e185a1de00a6
treea70f35995eac4ee621970c49e84c3105c56b46ee
parentdffcafd88ced273fb0b2e8b754b44472d73458f7
[PATCH 6/15] arm: Add pointer authentication for stack-unwinding runtime

This patch adds authentication for when the stack is unwound when an
exception is taken.  All the changes here are done to the runtime code
in libgcc's unwinder code for Arm target. All the changes are guarded
under defined (__ARM_FEATURE_PAC_DEFAULT) and activated only if the
+pacbti feature is switched on for the architecture. This means that
switching on the target feature via -march or -mcpu is sufficient and
-mbranch-protection need not be enabled. This ensures that the
unwinder is authenticated only if the PACBTI instructions are
available in the non-NOP space as it uses AUTG.  Just generating
PAC/AUT instructions using -mbranch-protection will not enable
authentication on the unwinder.

Pre-approved with the requested changes here
<https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586555.html>.

gcc/ChangeLog:

* ginclude/unwind-arm-common.h (_Unwind_VRS_RegClass): Introduce
new pseudo register class _UVRSC_PAC.

libgcc/ChangeLog:
* config/arm/pr-support.c (__gnu_unwind_execute): Decode
exception opcode (0xb4) for saving RA_AUTH_CODE and authenticate
with AUTG if found.
* config/arm/unwind-arm.c (struct pseudo_regs): New.
(phase1_vrs): Introduce new field to store pseudo-reg state.
(phase2_vrs): Likewise.
(_Unwind_VRS_Get): Load pseudo register state from virtual reg set.
(_Unwind_VRS_Set): Store pseudo register state to virtual reg set.
(_Unwind_VRS_Pop): Load pseudo register value from stack into VRS.

Co-Authored-By: Tejas Belagod <tbelagod@arm.com>
Co-Authored-By: Srinath Parvathaneni <srinath.parvathaneni@arm.com>
gcc/ginclude/unwind-arm-common.h
libgcc/config/arm/pr-support.c
libgcc/config/arm/unwind-arm.c