diff options
author | serge_sans_paille <sguelton@redhat.com> | 2019-09-09 16:59:34 +0200 |
---|---|---|
committer | serge-sans-paille <sguelton@redhat.com> | 2020-02-09 09:35:42 +0100 |
commit | 0fd51a4554f5f4f90342f40afd35b077f6d88213 (patch) | |
tree | fab8ee1b034bf2a2d8f78d581385667a0732bc3c /llvm/lib/Target/X86/X86CallFrameOptimization.cpp | |
parent | 1732f50ee06f6ac3fc21046f4c486108e86d3a49 (diff) | |
download | llvm-0fd51a4554f5f4f90342f40afd35b077f6d88213.zip llvm-0fd51a4554f5f4f90342f40afd35b077f6d88213.tar.gz llvm-0fd51a4554f5f4f90342f40afd35b077f6d88213.tar.bz2 |
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
Diffstat (limited to 'llvm/lib/Target/X86/X86CallFrameOptimization.cpp')
-rw-r--r-- | llvm/lib/Target/X86/X86CallFrameOptimization.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/llvm/lib/Target/X86/X86CallFrameOptimization.cpp b/llvm/lib/Target/X86/X86CallFrameOptimization.cpp index f8faa57..467d243 100644 --- a/llvm/lib/Target/X86/X86CallFrameOptimization.cpp +++ b/llvm/lib/Target/X86/X86CallFrameOptimization.cpp @@ -162,14 +162,13 @@ bool X86CallFrameOptimization::isLegal(MachineFunction &MF) { // memory for arguments. unsigned FrameSetupOpcode = TII->getCallFrameSetupOpcode(); unsigned FrameDestroyOpcode = TII->getCallFrameDestroyOpcode(); - bool UseStackProbe = - !STI->getTargetLowering()->getStackProbeSymbolName(MF).empty(); + bool EmitStackProbeCall = STI->getTargetLowering()->hasStackProbeSymbol(MF); unsigned StackProbeSize = STI->getTargetLowering()->getStackProbeSize(MF); for (MachineBasicBlock &BB : MF) { bool InsideFrameSequence = false; for (MachineInstr &MI : BB) { if (MI.getOpcode() == FrameSetupOpcode) { - if (TII->getFrameSize(MI) >= StackProbeSize && UseStackProbe) + if (TII->getFrameSize(MI) >= StackProbeSize && EmitStackProbeCall) return false; if (InsideFrameSequence) return false; |