26#define DEBUG_TYPE "x86-win-fixup-bscheck"
37 return "X86 Windows Fixup Buffer Security Check";
42 std::pair<MachineBasicBlock *, MachineInstr *>
55 std::pair<MachineInstr *, MachineInstr *>
61char X86WinFixupBufferSecurityCheckPass::ID = 0;
67 return new X86WinFixupBufferSecurityCheckPass();
70void X86WinFixupBufferSecurityCheckPass::SplitBasicBlock(
73 NewRetMBB->
splice(NewRetMBB->
end(), CurMBB, SplitIt, CurMBB->
end());
76std::pair<MachineBasicBlock *, MachineInstr *>
77X86WinFixupBufferSecurityCheckPass::getSecurityCheckerBasicBlock(
84 if (
MI.getOpcode() == X86::CALL64pcrel32 &&
85 MI.getNumExplicitOperands() == 1) {
86 auto MO =
MI.getOperand(0);
88 auto Callee = dyn_cast<Function>(MO.getGlobal());
89 if (Callee &&
Callee->getName() ==
"__security_check_cookie") {
90 return std::make_pair(&
MBB, &
MI);
97 return std::make_pair(
nullptr,
nullptr);
100void X86WinFixupBufferSecurityCheckPass::getGuardCheckSequence(
112 SeqMI[3] = CheckCall;
123 for (; XIt != CurMBB->
rbegin(); ++XIt) {
125 if ((CI.getOpcode() == X86::XOR64_FP) || (CI.getOpcode() == X86::XOR32_FP))
131std::pair<MachineInstr *, MachineInstr *>
132X86WinFixupBufferSecurityCheckPass::CreateFailCheckSequence(
140 assert(GV &&
" Security Cookie was not installed!");
163 return std::make_pair(CMI.getInstr(), JMI.getInstr());
171void X86WinFixupBufferSecurityCheckPass::FinishFunction(
179 FinishBlock(FailMBB);
180 FinishBlock(NewRetMBB);
183bool X86WinFixupBufferSecurityCheckPass::runOnMachineFunction(
185 bool Changed =
false;
200 auto [CurMBB, CheckCall] = getSecurityCheckerBasicBlock(MF);
212 getGuardCheckSequence(CurMBB, CheckCall, SeqMI);
215 auto FailSeqRange = CreateFailCheckSequence(CurMBB, FailMBB, SeqMI);
222 SplitBasicBlock(CurMBB, NewRetMBB, SplitIt);
228 FailMBB->
splice(FailMBB->
end(), CurMBB, U1It, U2It);
233 JMI.addMBB(NewRetMBB);
236 if (SplicePt != CurMBB->
end())
237 NewRetMBB->
splice(NewRetMBB->
end(), CurMBB, SplicePt);
243 FinishFunction(FailMBB, NewRetMBB);
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#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.