Add support for SVE stack clash probing

Programming / Compilers / GCC - tnfchris [138bc75d-0d04-0410-961f-82ee72b054a4] - 1 October 2018 12:56 EDT

This patch adds basic support for SVE stack clash protection. It is a first implementation and will use a loop to do the probing and stack adjustments.

An example sequence is:

.cfi_startproc mov x15, sp cntb x16, all, mul #11 add x16, x16, 304 .cfi_def_cfa_register 15 .SVLPSPL0: cmp x16, 61440 b.lt .SVLPEND0 sub sp, sp, 61440 str xzr, [sp, 0] sub x16, x16, 61440 b .SVLPSPL0 .SVLPEND0: sub sp, sp, x16 .cfi_escape 0xf,0xc,0x8f,0,0x92,0x2e,0,0x8,0x58,0x1e,0x23,0xb0,0x2,0x22

for a 64KB guard size, and for a 4KB guard size

.cfi_startproc mov x15, sp cntb x16, all, mul #11 add x16, x16, 304 .cfi_def_cfa_register 15 .SVLPSPL0: cmp x16, 3072 b.lt .SVLPEND0 sub sp, sp, 3072 str xzr, [sp, 0] sub x16, x16, 3072 b .SVLPSPL0 .SVLPEND0: sub sp, sp, x16 .cfi_escape 0xf,0xc,0x8f,0,0x92,0x2e,0,0x8,0x58,0x1e,0x23,0xb0,0x2,0x22

This has about the same semantics as alloca, except we prioritize the common case where no probe is required. We also change the amount we adjust the stack and the probing interval to be the nearest value to `guard size - abi buffer` that fits in the 12-bit shifted immediate used by cmp.

While this would mean we probe a bit more often than we require, in practice the amount of SVE vectors you'd need to spill is significant. Even more so to enter the loop more than once.


gcc/

PR target/86486
- config/aarch64/aarch64-protos.h (aarch64_output_probe_sve_stack_clash): New.
- config/aarch64/aarch64.c (aarch64_output_probe_sve_stack_clash, aarch64_clamp_to_uimm12_shift): New. (aarch64_allocate_and_probe_stack_space): Add SVE specific section.
- config/aarch64/aarch64.md (probe_sve_stack_clash): New.

gcc/testsuite/

PR target/86486
- gcc.target/aarch64/stack-check-prologue-16.c: New test
- gcc.target/aarch64/stack-check-cfa-3.c: New test.
- gcc.target/aarch64/sve/struct_vect_24.c: New test.
- gcc.target/aarch64/sve/struct_vect_24_run.c: New test.

a79985f5ac7 Add support for SVE stack clash probing.
gcc/ChangeLog | 9 ++
gcc/config/aarch64/aarch64-protos.h | 1 +
gcc/config/aarch64/aarch64.c | 155 ++++++++++++++++++++-
gcc/config/aarch64/aarch64.md | 19 +++
gcc/testsuite/ChangeLog | 8 ++
.../gcc.target/aarch64/stack-check-cfa-3.c | 13 ++
.../gcc.target/aarch64/stack-check-prologue-16.c | 32 +++++
.../gcc.target/aarch64/sve/struct_vect_24.c | 48 +++++++
.../gcc.target/aarch64/sve/struct_vect_24_run.c | 37 +++++
9 files changed, 317 insertions(+), 5 deletions(-)

Upstream: gcc.gnu.org


  • Share