]> git.ipfire.org Git - thirdparty/gcc.git/commit
aarch64: Add GCS support for nonlocal stack save
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 14 Nov 2024 16:15:08 +0000 (16:15 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Thu, 14 Nov 2024 16:15:08 +0000 (16:15 +0000)
commit41479351d638ed469bd6d8975dcacc4e72e503b3
tree66e3d3457254c722e830e621cab7e6199d48e20d
parentbca0fc1410bc6759365ef974974dc40915333734
aarch64: Add GCS support for nonlocal stack save

Nonlocal stack save and restore has to also save and restore the GCS
pointer. This is used in __builtin_setjmp/longjmp and nonlocal goto.

The GCS specific code is only emitted if GCS branch-protection is
enabled and the code always checks at runtime if GCS is enabled.

The new -mbranch-protection=gcs and old -mbranch-protection=none code
are ABI compatible: jmpbuf for __builtin_setjmp has space for 5
pointers, the layout is

  old layout: fp, pc, sp, unused, unused
  new layout: fp, pc, sp, gcsp, unused

Note: the ILP32 code generation is wrong as it saves the pointers with
Pmode (i.e. 8 bytes per pointer), but the user supplied buffer size is
for 5 pointers (4 bytes per pointer), this is not fixed.

The nonlocal goto has no ABI compatibility issues as the goto and its
destination are in the same translation unit.

We use CDImode to allow extra space for GCS without the effect of 16-byte
alignment.

gcc/ChangeLog:

* config/aarch64/aarch64.h (STACK_SAVEAREA_MODE): Make space for gcs.
* config/aarch64/aarch64.md (save_stack_nonlocal): New.
(restore_stack_nonlocal): New.
* tree-nested.cc (get_nl_goto_field): Updated.
gcc/config/aarch64/aarch64.h
gcc/config/aarch64/aarch64.md
gcc/tree-nested.cc