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 | d970ea3eac465d36b925b3b173d51d77681f32d2 (patch) | |
tree | 3d22f836cf195ec60e901144d8d981847ef8d793 /llvm/lib/CodeGen/PrologEpilogInserter.cpp | |
parent | b870fd887437c8cd94905b275595af6378017e19 (diff) | |
download | bcm5719-llvm-d970ea3eac465d36b925b3b173d51d77681f32d2.tar.gz bcm5719-llvm-d970ea3eac465d36b925b3b173d51d77681f32d2.zip |
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.
llvm-svn: 58791
Diffstat (limited to 'llvm/lib/CodeGen/PrologEpilogInserter.cpp')
-rw-r--r-- | llvm/lib/CodeGen/PrologEpilogInserter.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index d3b0b11c705..e118dd2449f 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/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) { |