diff options
author | Bill Wendling <isanbard@gmail.com> | 2008-11-06 02:29:10 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2008-11-06 02:29:10 +0000 |
commit | b2a4298ce41e7ef80cd75a3c1dfa6433f0759a1a (patch) | |
tree | 90348b042f4b796ea7643d4966ccb2207a5bfdfa /lib/CodeGen/PrologEpilogInserter.cpp | |
parent | 9092213a5e50d4991f900d2df009d27bddfd9941 (diff) |
Implement the stack protector stack accesses via intrinsics:
- stackprotector_prologue creates a stack object and stores the guard there.
- stackprotector_epilogue reads the stack guard from the stack position created
by stackprotector_prologue.
- The PrologEpilogInserter was changed to make sure that the stack guard is
first on the stack frame.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58791 91177308-0d34-0410-b5e6-96231b3b80d8
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) { |