diff options
Diffstat (limited to 'lib/CodeGen/PrologEpilogInserter.cpp')
-rw-r--r-- | lib/CodeGen/PrologEpilogInserter.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/CodeGen/PrologEpilogInserter.cpp b/lib/CodeGen/PrologEpilogInserter.cpp index d3b0b11c70..e118dd2449 100644 --- a/lib/CodeGen/PrologEpilogInserter.cpp +++ b/lib/CodeGen/PrologEpilogInserter.cpp @@ -406,6 +406,33 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { } } + // Make sure that the stack protector comes before the local variables on the + // stack. + if (FFI->hasStackProtector()) { + int FI = FFI->getStackProtectorIndex(); + + // If stack grows down, we need to add size of find the lowest + // address of the object. + if (StackGrowsDown) + Offset += FFI->getObjectSize(FI); + + unsigned Align = FFI->getObjectAlignment(FI); + + // If the alignment of this object is greater than that of the stack, then + // increase the stack alignment to match. + MaxAlign = std::max(MaxAlign, Align); + + // Adjust to alignment boundary. + Offset = (Offset + Align - 1) / Align * Align; + + if (StackGrowsDown) { + FFI->setObjectOffset(FI, -Offset); // Set the computed offset + } else { + FFI->setObjectOffset(FI, Offset); + Offset += FFI->getObjectSize(FI); + } + } + // Then assign frame offsets to stack objects that are not used to spill // callee saved registers. for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) { |