diff options
Diffstat (limited to 'llvm/include')
-rw-r--r-- | llvm/include/llvm/CodeGen/GlobalISel/Localizer.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/CodeGen/GlobalISel/Utils.h | 6 | ||||
-rw-r--r-- | llvm/include/llvm/CodeGen/MachineFrameInfo.h | 33 | ||||
-rw-r--r-- | llvm/include/llvm/CodeGen/StackProtector.h | 26 |
4 files changed, 46 insertions, 21 deletions
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/Localizer.h b/llvm/include/llvm/CodeGen/GlobalISel/Localizer.h index 0a46eb9e784..1e2d4763e5e 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/Localizer.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/Localizer.h @@ -70,6 +70,8 @@ public: .set(MachineFunctionProperties::Property::RegBankSelected); } + void getAnalysisUsage(AnalysisUsage &AU) const override; + bool runOnMachineFunction(MachineFunction &MF) override; }; diff --git a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h index 837035f5bb1..51e3a273297 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h @@ -19,6 +19,7 @@ namespace llvm { +class AnalysisUsage; class MachineFunction; class MachineInstr; class MachineOperand; @@ -102,5 +103,10 @@ MachineInstr *getOpcodeDef(unsigned Opcode, unsigned Reg, /// Returns an APFloat from Val converted to the appropriate size. APFloat getAPFloatFromSize(double Val, unsigned Size); + +/// Modify analysis usage so it preserves passes required for the SelectionDAG +/// fallback. +void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU); + } // End namespace llvm. #endif diff --git a/llvm/include/llvm/CodeGen/MachineFrameInfo.h b/llvm/include/llvm/CodeGen/MachineFrameInfo.h index 48ee077161d..2d6081f3577 100644 --- a/llvm/include/llvm/CodeGen/MachineFrameInfo.h +++ b/llvm/include/llvm/CodeGen/MachineFrameInfo.h @@ -87,7 +87,21 @@ public: /// /// Abstract Stack Frame Information class MachineFrameInfo { +public: + /// Stack Smashing Protection (SSP) rules require that vulnerable stack + /// allocations are located close the stack protector. + enum SSPLayoutKind { + SSPLK_None, ///< Did not trigger a stack protector. No effect on data + ///< layout. + SSPLK_LargeArray, ///< Array or nested array >= SSP-buffer-size. Closest + ///< to the stack protector. + SSPLK_SmallArray, ///< Array or nested array < SSP-buffer-size. 2nd closest + ///< to the stack protector. + SSPLK_AddrOf ///< The address of this allocation is exposed and + ///< triggered protection. 3rd closest to the protector. + }; +private: // Represent a single object allocated on the stack. struct StackObject { // The offset of this object from the stack pointer on entry to @@ -148,12 +162,15 @@ class MachineFrameInfo { /// If true, the object has been zero-extended. bool isSExt = false; + uint8_t SSPLayout; + StackObject(uint64_t Size, unsigned Alignment, int64_t SPOffset, bool IsImmutable, bool IsSpillSlot, const AllocaInst *Alloca, bool IsAliased, uint8_t StackID = 0) : SPOffset(SPOffset), Size(Size), Alignment(Alignment), isImmutable(IsImmutable), isSpillSlot(IsSpillSlot), - StackID(StackID), Alloca(Alloca), isAliased(IsAliased) {} + StackID(StackID), Alloca(Alloca), isAliased(IsAliased), + SSPLayout(SSPLK_None) {} }; /// The alignment of the stack. @@ -488,6 +505,20 @@ public: Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset; } + SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const { + assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && + "Invalid Object Idx!"); + return (SSPLayoutKind)Objects[ObjectIdx+NumFixedObjects].SSPLayout; + } + + void setObjectSSPLayout(int ObjectIdx, SSPLayoutKind Kind) { + assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && + "Invalid Object Idx!"); + assert(!isDeadObjectIndex(ObjectIdx) && + "Setting SSP layout for a dead object?"); + Objects[ObjectIdx+NumFixedObjects].SSPLayout = Kind; + } + /// Return the number of bytes that must be allocated to hold /// all of the fixed size frame objects. This is only valid after /// Prolog/Epilog code insertion has finalized the stack frame layout. diff --git a/llvm/include/llvm/CodeGen/StackProtector.h b/llvm/include/llvm/CodeGen/StackProtector.h index 0fe2688a68b..a506ac636a1 100644 --- a/llvm/include/llvm/CodeGen/StackProtector.h +++ b/llvm/include/llvm/CodeGen/StackProtector.h @@ -19,6 +19,7 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/Triple.h" +#include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/ValueMap.h" #include "llvm/Pass.h" @@ -35,24 +36,11 @@ class TargetMachine; class Type; class StackProtector : public FunctionPass { -public: - /// SSPLayoutKind. Stack Smashing Protection (SSP) rules require that - /// vulnerable stack allocations are located close the stack protector. - enum SSPLayoutKind { - SSPLK_None, ///< Did not trigger a stack protector. No effect on data - ///< layout. - SSPLK_LargeArray, ///< Array or nested array >= SSP-buffer-size. Closest - ///< to the stack protector. - SSPLK_SmallArray, ///< Array or nested array < SSP-buffer-size. 2nd closest - ///< to the stack protector. - SSPLK_AddrOf ///< The address of this allocation is exposed and - ///< triggered protection. 3rd closest to the protector. - }; - +private: /// A mapping of AllocaInsts to their required SSP layout. - using SSPLayoutMap = ValueMap<const AllocaInst *, SSPLayoutKind>; + using SSPLayoutMap = DenseMap<const AllocaInst *, + MachineFrameInfo::SSPLayoutKind>; -private: const TargetMachine *TM = nullptr; /// TLI - Keep a pointer of a TargetLowering to consult for determining @@ -123,14 +111,12 @@ public: void getAnalysisUsage(AnalysisUsage &AU) const override; - SSPLayoutKind getSSPLayout(const AllocaInst *AI) const; - // Return true if StackProtector is supposed to be handled by SelectionDAG. bool shouldEmitSDCheck(const BasicBlock &BB) const; - void adjustForColoring(const AllocaInst *From, const AllocaInst *To); - bool runOnFunction(Function &Fn) override; + + void copyToMachineFrameInfo(MachineFrameInfo &MFI) const; }; } // end namespace llvm |