1- // ===- AArch64WinFixupBufferSecurityCheck.cpp Fix Buffer Security Check Call
2- // -===//
1+ // ===- AArch64WinFixupBufferSecurityCheck.cpp Fixup Buffer Security Check -===//
32//
43// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
54// See https://llvm.org/LICENSE.txt for license information.
@@ -50,12 +49,9 @@ class AArch64WinFixupBufferSecurityCheckPass : public MachineFunctionPass {
5049 void getGuardCheckSequence (MachineBasicBlock *CurMBB, MachineInstr *CheckCall,
5150 MachineInstr *SeqMI[5 ]);
5251
53- void SplitBasicBlock (MachineBasicBlock *CurMBB, MachineBasicBlock *NewRetMBB,
54- MachineBasicBlock::iterator SplitIt);
52+ void finishBlock (MachineBasicBlock *MBB);
5553
56- void FinishBlock (MachineBasicBlock *MBB);
57-
58- void FinishFunction (MachineBasicBlock *FailMBB, MachineBasicBlock *NewRetMBB);
54+ void finishFunction (MachineBasicBlock *FailMBB, MachineBasicBlock *NewRetMBB);
5955};
6056} // end anonymous namespace
6157
@@ -68,24 +64,17 @@ FunctionPass *llvm::createAArch64WinFixupBufferSecurityCheckPass() {
6864 return new AArch64WinFixupBufferSecurityCheckPass ();
6965}
7066
71- void AArch64WinFixupBufferSecurityCheckPass::SplitBasicBlock (
72- MachineBasicBlock *CurMBB, MachineBasicBlock *NewRetMBB,
73- MachineBasicBlock::iterator SplitIt) {
74- NewRetMBB->splice (NewRetMBB->end (), CurMBB, SplitIt, CurMBB->end ());
75- }
76-
7767std::pair<MachineBasicBlock *, MachineInstr *>
7868AArch64WinFixupBufferSecurityCheckPass::getSecurityCheckerBasicBlock (
7969 MachineFunction &MF) {
8070 for (auto &MBB : MF) {
8171 for (auto &MI : MBB) {
82- if (MI.getOpcode () == AArch64::BL && MI.getNumExplicitOperands () == 1 ) {
72+ if (MI.isCall () && MI.getNumExplicitOperands () == 1 ) {
8373 auto MO = MI.getOperand (0 );
8474 if (MO.isGlobal ()) {
8575 auto Callee = dyn_cast<Function>(MO.getGlobal ());
8676 if (Callee && Callee->getName () == " __security_check_cookie" ) {
8777 return std::make_pair (&MBB, &MI);
88- break ;
8978 }
9079 }
9180 }
@@ -164,22 +153,22 @@ void AArch64WinFixupBufferSecurityCheckPass::getGuardCheckSequence(
164153 SeqMI[0 ] = &*DIt;
165154}
166155
167- void AArch64WinFixupBufferSecurityCheckPass::FinishBlock (
156+ void AArch64WinFixupBufferSecurityCheckPass::finishBlock (
168157 MachineBasicBlock *MBB) {
169158 LivePhysRegs LiveRegs;
170159 computeAndAddLiveIns (LiveRegs, *MBB);
171160}
172161
173- void AArch64WinFixupBufferSecurityCheckPass::FinishFunction (
162+ void AArch64WinFixupBufferSecurityCheckPass::finishFunction (
174163 MachineBasicBlock *FailMBB, MachineBasicBlock *NewRetMBB) {
175164 FailMBB->getParent ()->RenumberBlocks ();
176165 // FailMBB includes call to MSCV RT where __security_check_cookie
177166 // function is called. This function uses regcall and it expects cookie
178167 // value from stack slot.( even if this is modified)
179168 // Before going further we compute back livein for this block to make sure
180169 // it is live and provided.
181- FinishBlock (FailMBB);
182- FinishBlock (NewRetMBB);
170+ finishBlock (FailMBB);
171+ finishBlock (NewRetMBB);
183172}
184173
185174bool AArch64WinFixupBufferSecurityCheckPass::runOnMachineFunction (
@@ -269,7 +258,7 @@ bool AArch64WinFixupBufferSecurityCheckPass::runOnMachineFunction(
269258 CurMBB->addSuccessor (NewRetMBB);
270259 CurMBB->addSuccessor (FailMBB);
271260
272- FinishFunction (FailMBB, NewRetMBB);
261+ finishFunction (FailMBB, NewRetMBB);
273262
274263 return !Changed;
275264}
0 commit comments