1
- // ===- AArch64WinFixupBufferSecurityCheck.cpp Fix Buffer Security Check Call
2
- // -===//
1
+ // ===- AArch64WinFixupBufferSecurityCheck.cpp Fixup Buffer Security Check -===//
3
2
//
4
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
4
// See https://llvm.org/LICENSE.txt for license information.
@@ -50,12 +49,9 @@ class AArch64WinFixupBufferSecurityCheckPass : public MachineFunctionPass {
50
49
void getGuardCheckSequence (MachineBasicBlock *CurMBB, MachineInstr *CheckCall,
51
50
MachineInstr *SeqMI[5 ]);
52
51
53
- void SplitBasicBlock (MachineBasicBlock *CurMBB, MachineBasicBlock *NewRetMBB,
54
- MachineBasicBlock::iterator SplitIt);
52
+ void finishBlock (MachineBasicBlock *MBB);
55
53
56
- void FinishBlock (MachineBasicBlock *MBB);
57
-
58
- void FinishFunction (MachineBasicBlock *FailMBB, MachineBasicBlock *NewRetMBB);
54
+ void finishFunction (MachineBasicBlock *FailMBB, MachineBasicBlock *NewRetMBB);
59
55
};
60
56
} // end anonymous namespace
61
57
@@ -68,24 +64,17 @@ FunctionPass *llvm::createAArch64WinFixupBufferSecurityCheckPass() {
68
64
return new AArch64WinFixupBufferSecurityCheckPass ();
69
65
}
70
66
71
- void AArch64WinFixupBufferSecurityCheckPass::SplitBasicBlock (
72
- MachineBasicBlock *CurMBB, MachineBasicBlock *NewRetMBB,
73
- MachineBasicBlock::iterator SplitIt) {
74
- NewRetMBB->splice (NewRetMBB->end (), CurMBB, SplitIt, CurMBB->end ());
75
- }
76
-
77
67
std::pair<MachineBasicBlock *, MachineInstr *>
78
68
AArch64WinFixupBufferSecurityCheckPass::getSecurityCheckerBasicBlock (
79
69
MachineFunction &MF) {
80
70
for (auto &MBB : MF) {
81
71
for (auto &MI : MBB) {
82
- if (MI.getOpcode () == AArch64::BL && MI.getNumExplicitOperands () == 1 ) {
72
+ if (MI.isCall () && MI.getNumExplicitOperands () == 1 ) {
83
73
auto MO = MI.getOperand (0 );
84
74
if (MO.isGlobal ()) {
85
75
auto Callee = dyn_cast<Function>(MO.getGlobal ());
86
76
if (Callee && Callee->getName () == " __security_check_cookie" ) {
87
77
return std::make_pair (&MBB, &MI);
88
- break ;
89
78
}
90
79
}
91
80
}
@@ -164,22 +153,22 @@ void AArch64WinFixupBufferSecurityCheckPass::getGuardCheckSequence(
164
153
SeqMI[0 ] = &*DIt;
165
154
}
166
155
167
- void AArch64WinFixupBufferSecurityCheckPass::FinishBlock (
156
+ void AArch64WinFixupBufferSecurityCheckPass::finishBlock (
168
157
MachineBasicBlock *MBB) {
169
158
LivePhysRegs LiveRegs;
170
159
computeAndAddLiveIns (LiveRegs, *MBB);
171
160
}
172
161
173
- void AArch64WinFixupBufferSecurityCheckPass::FinishFunction (
162
+ void AArch64WinFixupBufferSecurityCheckPass::finishFunction (
174
163
MachineBasicBlock *FailMBB, MachineBasicBlock *NewRetMBB) {
175
164
FailMBB->getParent ()->RenumberBlocks ();
176
165
// FailMBB includes call to MSCV RT where __security_check_cookie
177
166
// function is called. This function uses regcall and it expects cookie
178
167
// value from stack slot.( even if this is modified)
179
168
// Before going further we compute back livein for this block to make sure
180
169
// it is live and provided.
181
- FinishBlock (FailMBB);
182
- FinishBlock (NewRetMBB);
170
+ finishBlock (FailMBB);
171
+ finishBlock (NewRetMBB);
183
172
}
184
173
185
174
bool AArch64WinFixupBufferSecurityCheckPass::runOnMachineFunction (
@@ -269,7 +258,7 @@ bool AArch64WinFixupBufferSecurityCheckPass::runOnMachineFunction(
269
258
CurMBB->addSuccessor (NewRetMBB);
270
259
CurMBB->addSuccessor (FailMBB);
271
260
272
- FinishFunction (FailMBB, NewRetMBB);
261
+ finishFunction (FailMBB, NewRetMBB);
273
262
274
263
return !Changed;
275
264
}
0 commit comments