[PATCH] D96004: [AArch64] Stack probing for function prologues

Oliver Stannard (Linaro) via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 4 02:27:42 PST 2021


ostannard created this revision.
ostannard added reviewers: serge-sans-paille, jnspaulsson, bzEq, tnfchris.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls.
ostannard requested review of this revision.
Herald added a project: LLVM.

This adds code to AArch64 function prologues to protect against stack
clash attacks by probing (writing to) the stack at regular enough
intervals to ensure that the guard page cannot be skipped over.

There are multiple probing sequences that can be emitted, depending on
the size of the stack allocation:

- A straight-line sequence of subtracts and stores, used when the allocation size is smaller than 3 guard pages.
- A loop allocating and probing one page size per iteration, plus a single probe to deal with the remainder, used when the allocation size is larger but still known at compile time.
- A loop which moves the SP down to the target value held in a register, used when the allocation size is not known at compile-time, such as when allocating space for SVE values, or when over-aligning the stack. This is emitted in AArch64InstrInfo because it will also be used for dynamic allocas in a future patch.

By default, the stack guard size is 4KiB, which is a safe default as this is
the smallest possible page size for AArch64. Linux uses a 64KiB guard for
AArch64, so this can be overridden by the stack-probe-size function attribute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96004

Files:
  llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
  llvm/lib/Target/AArch64/AArch64FrameLowering.h
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
  llvm/lib/Target/AArch64/AArch64InstrInfo.h
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/test/CodeGen/AArch64/stack-probing-64k.ll
  llvm/test/CodeGen/AArch64/stack-probing-sve.ll
  llvm/test/CodeGen/AArch64/stack-probing.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96004.321352.patch
Type: text/x-patch
Size: 60153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210204/6259222f/attachment.bin>


More information about the llvm-commits mailing list