28#define DEBUG_TYPE "x86-win-fixup-bscheck"
39 return "X86 Windows Fixup Buffer Security Check";
44 std::pair<MachineBasicBlock *, MachineInstr *>
57 std::pair<MachineInstr *, MachineInstr *>
63char X86WinFixupBufferSecurityCheckPass::ID = 0;
69 return new X86WinFixupBufferSecurityCheckPass();
72void X86WinFixupBufferSecurityCheckPass::SplitBasicBlock(
75 NewRetMBB->
splice(NewRetMBB->
end(), CurMBB, SplitIt, CurMBB->
end());
78std::pair<MachineBasicBlock *, MachineInstr *>
79X86WinFixupBufferSecurityCheckPass::getSecurityCheckerBasicBlock(
86 if (
MI.getOpcode() == X86::CALL64pcrel32 &&
87 MI.getNumExplicitOperands() == 1) {
88 auto MO =
MI.getOperand(0);
90 auto Callee = dyn_cast<Function>(MO.getGlobal());
91 if (Callee &&
Callee->getName() ==
"__security_check_cookie") {
92 return std::make_pair(&
MBB, &
MI);
99 return std::make_pair(
nullptr,
nullptr);
102void X86WinFixupBufferSecurityCheckPass::getGuardCheckSequence(
114 SeqMI[3] = CheckCall;
125 for (; XIt != CurMBB->
rbegin(); ++XIt) {
127 if ((CI.getOpcode() == X86::XOR64_FP) || (CI.getOpcode() == X86::XOR32_FP))
133std::pair<MachineInstr *, MachineInstr *>
134X86WinFixupBufferSecurityCheckPass::CreateFailCheckSequence(
142 assert(GV &&
" Security Cookie was not installed!");
165 return std::make_pair(CMI.getInstr(), JMI.getInstr());
173void X86WinFixupBufferSecurityCheckPass::FinishFunction(
181 FinishBlock(FailMBB);
182 FinishBlock(NewRetMBB);
185bool X86WinFixupBufferSecurityCheckPass::runOnMachineFunction(
187 bool Changed =
false;
202 auto [CurMBB, CheckCall] = getSecurityCheckerBasicBlock(MF);
214 getGuardCheckSequence(CurMBB, CheckCall, SeqMI);
217 auto FailSeqRange = CreateFailCheckSequence(CurMBB, FailMBB, SeqMI);
224 SplitBasicBlock(CurMBB, NewRetMBB, SplitIt);
230 FailMBB->
splice(FailMBB->
end(), CurMBB, U1It, U2It);
235 JMI.addMBB(NewRetMBB);
238 if (SplicePt != CurMBB->
end())
239 NewRetMBB->
splice(NewRetMBB->
end(), CurMBB, SplicePt);
245 FinishFunction(FailMBB, NewRetMBB);
const HexagonInstrInfo * TII
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
FunctionPass class - This class is used to implement most global optimizations.
Module * getParent()
Get the module that this global value is contained inside of...
A set of physical registers with utility functions to track liveness when walking backward/forward th...
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
reverse_iterator rbegin()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
Register getReg() const
getReg - Returns the register number.
A Module instance is used to store all the information related to an LLVM module.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
virtual const TargetInstrInfo * getInstrInfo() const
bool isTargetWindowsMSVC() const
bool isTargetWindowsItanium() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
auto reverse(ContainerTy &&C)
void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)
Convenience function combining computeLiveIns() and addLiveIns().
FunctionPass * createX86WinFixupBufferSecurityCheckPass()
Return a pass that transform inline buffer security check into seperate bb.