From 84e89ff06f74e85ac7a7c677d60f14e9c4e07865 Mon Sep 17 00:00:00 2001 From: Petr Pavlu Date: Mon, 10 Dec 2018 15:15:05 +0000 Subject: [PATCH] [GlobalISel] Set stack protector index when translating Intrinsic::stackprotector Record the stack protector index in MachineFrameInfo when translating Intrinsic::stackprotector similarly as is done by SelectionDAG when processing the same intrinsic. Setting this index allows the Prologue/Epilogue Insertion to recognize that the stack protection is enabled. The pass can then make sure that the stack protector comes before local variables on the stack and assigns potentially vulnerable objects first so they are close to the stack protector slot. Differential Revision: https://reviews.llvm.org/D55418 llvm-svn: 348761 --- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 12 +++++++----- .../AArch64/GlobalISel/arm64-irtranslator-stackprotect.ll | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index 7a39883..dc1e7c3 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -973,13 +973,15 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID, getStackGuard(GuardVal, MIRBuilder); AllocaInst *Slot = cast(CI.getArgOperand(1)); + int FI = getOrCreateFrameIndex(*Slot); + MF->getFrameInfo().setStackProtectorIndex(FI); + MIRBuilder.buildStore( GuardVal, getOrCreateVReg(*Slot), - *MF->getMachineMemOperand( - MachinePointerInfo::getFixedStack(*MF, - getOrCreateFrameIndex(*Slot)), - MachineMemOperand::MOStore | MachineMemOperand::MOVolatile, - PtrTy.getSizeInBits() / 8, 8)); + *MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(*MF, FI), + MachineMemOperand::MOStore | + MachineMemOperand::MOVolatile, + PtrTy.getSizeInBits() / 8, 8)); return true; } case Intrinsic::cttz: diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator-stackprotect.ll b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator-stackprotect.ll index 62abf3d..ad01264 100644 --- a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator-stackprotect.ll +++ b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator-stackprotect.ll @@ -3,6 +3,9 @@ ; CHECK: name: test_stack_guard +; CHECK: frameInfo: +; CHECK: stackProtector: '%stack.0.StackGuardSlot' + ; CHECK: stack: ; CHECK: - { id: 0, name: StackGuardSlot, type: default, offset: 0, size: 8, alignment: 8, ; CHECK-NOT: id: 1 -- 2.7.4