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/SelectionDAG/SelectionDAGBuild.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/SelectionDAG/SelectionDAGBuild.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 6a2f2760ee9..267ae369086 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -25,6 +25,7 @@ #include "llvm/Instructions.h" #include "llvm/Intrinsics.h" #include "llvm/IntrinsicInst.h" +#include "llvm/Module.h" #include "llvm/CodeGen/FastISel.h" #include "llvm/CodeGen/GCStrategy.h" #include "llvm/CodeGen/GCMetadata.h" @@ -34,6 +35,7 @@ #include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h" +#include "llvm/CodeGen/PseudoSourceValue.h" #include "llvm/CodeGen/SelectionDAG.h" #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetData.h" @@ -3793,6 +3795,47 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { DAG.setRoot(DAG.getNode(ISD::STACKRESTORE, MVT::Other, getRoot(), Tmp)); return 0; } + case Intrinsic::stackprotector_prologue: { + // Emit code into the DAG to store the stack guard onto the stack. + MachineFunction &MF = DAG.getMachineFunction(); + MachineFrameInfo *MFI = MF.getFrameInfo(); + MVT PtrTy = TLI.getPointerTy(); + + // Retrieve the stack protector guard's value. + SDValue Src = getValue(I.getOperand(1)); + + // Create a slot on the stack for the stack protector. It should go first + // before local variables are allocated. + unsigned Align = + TLI.getTargetData()->getPrefTypeAlignment(PtrTy.getTypeForMVT()); + int FI = MFI->CreateStackObject(PtrTy.getSizeInBits() / 8, Align); + + MFI->setStackProtector(true); + MFI->setStackProtectorIndex(FI); + + SDValue FIN = DAG.getFrameIndex(FI, PtrTy); + + // Store the stack protector onto the stack. + SDValue Result = DAG.getStore(getRoot(), Src, FIN, + PseudoSourceValue::getFixedStack(FI), + 0, true); + setValue(&I, Result); + DAG.setRoot(Result); + return 0; + } + case Intrinsic::stackprotector_epilogue: { + // Emit code into the DAG to retrieve the stack guard off of the stack. + MachineFunction &MF = DAG.getMachineFunction(); + MachineFrameInfo *MFI = MF.getFrameInfo(); + MVT PtrTy = TLI.getPointerTy(); + + // Load the value stored on the stack. + int FI = MFI->getStackProtectorIndex(); + SDValue FIN = DAG.getFrameIndex(MFI->getStackProtectorIndex(), PtrTy); + setValue(&I, DAG.getLoad(PtrTy, getRoot(), FIN, + PseudoSourceValue::getFixedStack(FI), 0, true)); + return 0; + } case Intrinsic::var_annotation: // Discard annotate attributes return 0; |