Updated stack-clash implementation supporting 64k probes.
authorJeff Law <law@redhat.com>
Mon, 1 Oct 2018 12:49:35 +0000 (06:49 -0600)
committerTamar Christina <tnfchris@gcc.gnu.org>
Mon, 1 Oct 2018 12:49:35 +0000 (12:49 +0000)
commitcd1bef27d286a40b2709a9ded77fed5a33a461c5
tree7e0089f09fdfa1bc6e63bc11b4c0ed2848643b8a
parent041bfa6f07787752743e8c32c7a75a47015ba65a
Updated stack-clash implementation supporting 64k probes.

This patch implements the use of the stack clash mitigation for aarch64.
In Aarch64 we expect both the probing interval and the guard size to be 64KB
and we enforce them to always be equal.

We also probe up by 1024 bytes in the general case when a probe is required.

AArch64 has the following probing conditions:

 1a) Any initial adjustment less than 63KB requires no probing.  An ABI defined
     safe buffer of 1Kbytes is used and a page size of 64k is assumed.

  b) Any final adjustment residual requires a probe at SP + 1KB.
     We know this to be safe since you would have done at least one page worth
     of allocations already to get to that point.

  c) Any final adjustment more than remainder (total allocation amount) larger
     than 1K - LR offset requires a probe at SP.

  safe buffer mentioned in 1a is maintained by the storing of FP/LR.
  In the case of -fomit-frame-pointer we can still count on LR being stored
  if the function makes a call, even if it's a tail call.  The AArch64 frame
  layout code guarantees this and tests have been added to check against
  this particular case.

 2) Any allocations larger than 1 page size, is done in increments of page size
    and probed up by 1KB leaving the residuals.

 3a) Any residual for initial adjustment that is less than guard-size - 1KB
     requires no probing.  Essentially this is a sliding window.  The probing
     range determines the ABI safe buffer, and the amount to be probed up.

Incrementally allocating less than the probing thresholds, e.g. recursive functions will
not be an issue as the storing of LR counts as a probe.

                            +-------------------+
                            |  ABI SAFE REGION  |
                  +------------------------------
                  |         |                   |
                  |         |                   |
                  |         |                   |
                  |         |                   |
                  |         |                   |
                  |         |                   |
 maximum amount   |         |                   |
 not needing a    |         |                   |
 probe            |         |                   |
                  |         |                   |
                  |         |                   |
                  |         |                   |
                  |         |                   |        Probe offset when
                  |         ---------------------------- probe is required
                  |         |                   |
                  +-------- +-------------------+ --------  Point of first probe
                            |  ABI SAFE REGION  |
                            ---------------------
                            |                   |
                            |                   |
                            |                   |

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
Target was tested with stack clash on and off by default.

GLIBC testsuite also ran with stack clash on by default and no new
regressions.

Co-Authored-By: Richard Sandiford <richard.sandiford@linaro.org>
Co-Authored-By: Tamar Christina <tamar.christina@arm.com>
From-SVN: r264747
26 files changed:
gcc/ChangeLog
gcc/config/aarch64/aarch64.c
gcc/config/aarch64/aarch64.h
gcc/config/aarch64/aarch64.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/stack-check-12.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-13.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-cfa-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-cfa-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-10.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-11.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-12.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-13.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-14.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-15.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-5.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-6.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-7.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-8.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-9.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/stack-check-prologue.h [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp