Support -fstack-clash-protection for x86
authorserge_sans_paille <sguelton@redhat.com>
Mon, 9 Sep 2019 14:59:34 +0000 (16:59 +0200)
committerserge-sans-paille <sguelton@redhat.com>
Fri, 7 Feb 2020 18:54:39 +0000 (19:54 +0100)
commit4a1a0690ad6813a4c8cdb8dc20ea6337aa1f61e0
tree6b9b4ba6201031022276a77f1928174c0932ac28
parentd06dd29e09b6b03a834ec0639d57446fb8515d12
Support -fstack-clash-protection for x86

Implement protection against the stack clash attack [0] through inline stack
probing.

Probe stack allocation every PAGE_SIZE during frame lowering or dynamic
allocation to make sure the page guard, if any, is touched when touching the
stack, in a similar manner to GCC[1].

This extends the existing `probe-stack' mechanism with a special value `inline-asm'.
Technically the former uses function call before stack allocation while this
patch provides inlined stack probes and chunk allocation.

Only implemented for x86.

[0] https://www.qualys.com/2017/06/19/stack-clash/stack-clash.txt
[1] https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00556.html

This a recommit of 39f50da2a357a8f685b3540246c5d762734e035f with correct option
flags set.

Differential Revision: https://reviews.llvm.org/D68720
31 files changed:
clang/docs/ClangCommandLineReference.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/TargetInfo.h
clang/include/clang/Driver/CC1Options.td
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/stack-clash-protection.c [new file with mode: 0644]
clang/test/Driver/stack-clash-protection.c [new file with mode: 0644]
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/lib/Target/X86/X86CallFrameOptimization.cpp
llvm/lib/Target/X86/X86FrameLowering.cpp
llvm/lib/Target/X86/X86FrameLowering.h
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86ISelLowering.h
llvm/lib/Target/X86/X86InstrCompiler.td
llvm/lib/Target/X86/X86InstrInfo.td
llvm/test/CodeGen/X86/stack-clash-dynamic-alloca.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/stack-clash-large.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/stack-clash-medium-natural-probes-mutliple-objects.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/stack-clash-medium-natural-probes.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/stack-clash-medium.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/stack-clash-no-free-probe.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/stack-clash-small.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/stack-clash-unknown-call.ll [new file with mode: 0644]