From 24c7f063333b0654fb3d6667d0096ce97141b82e Mon Sep 17 00:00:00 2001 From: Josh Magee Date: Sat, 1 Feb 2014 01:36:16 +0000 Subject: [stackprotector] Implement the sspstrong rules for stack layout. This changes the PrologueEpilogInserter and LocalStackSlotAllocation passes to follow the extended stack layout rules for sspstrong and sspreq. The sspstrong layout rules are: 1. Large arrays and structures containing large arrays (>= ssp-buffer-size) are closest to the stack protector. 2. Small arrays and structures containing small arrays (< ssp-buffer-size) are 2nd closest to the protector. 3. Variables that have had their address taken are 3rd closest to the protector. Differential Revision: http://llvm-reviews.chandlerc.com/D2546 llvm-svn: 200601 --- llvm/lib/CodeGen/LocalStackSlotAllocation.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'llvm/lib/CodeGen/LocalStackSlotAllocation.cpp') diff --git a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp index f521548b213..08f0cc2f011 100644 --- a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp +++ b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp @@ -194,6 +194,9 @@ void LocalStackSlotPass::calculateFrameObjectOffsets(MachineFunction &Fn) { SmallSet ProtectedObjs; if (MFI->getStackProtectorIndex() >= 0) { StackObjSet LargeArrayObjs; + StackObjSet SmallArrayObjs; + StackObjSet AddrOfObjs; + AdjustStackOffset(MFI, MFI->getStackProtectorIndex(), Offset, StackGrowsDown, MaxAlign); @@ -206,8 +209,12 @@ void LocalStackSlotPass::calculateFrameObjectOffsets(MachineFunction &Fn) { switch (SP->getSSPLayout(MFI->getObjectAllocation(i))) { case StackProtector::SSPLK_None: + continue; case StackProtector::SSPLK_SmallArray: + SmallArrayObjs.insert(i); + continue; case StackProtector::SSPLK_AddrOf: + AddrOfObjs.insert(i); continue; case StackProtector::SSPLK_LargeArray: LargeArrayObjs.insert(i); @@ -218,6 +225,10 @@ void LocalStackSlotPass::calculateFrameObjectOffsets(MachineFunction &Fn) { AssignProtectedObjSet(LargeArrayObjs, ProtectedObjs, MFI, StackGrowsDown, Offset, MaxAlign); + AssignProtectedObjSet(SmallArrayObjs, ProtectedObjs, MFI, StackGrowsDown, + Offset, MaxAlign); + AssignProtectedObjSet(AddrOfObjs, ProtectedObjs, MFI, StackGrowsDown, + Offset, MaxAlign); } // Then assign frame offsets to stack objects that are not used to spill -- cgit v1.2.3