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>
Sun, 9 Feb 2020 08:35:42 +0000 (09:35 +0100)
commit0fd51a4554f5f4f90342f40afd35b077f6d88213
treefab8ee1b034bf2a2d8f78d581385667a0732bc3c
parent1732f50ee06f6ac3fc21046f4c486108e86d3a49
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 proper LiveIn
declaration, better option handling and more portable testing.

Differential Revision: https://reviews.llvm.org/D68720
30 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/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]