Go to the documentation of this file.
34 #define PASS_KEY "x86-lvi-ret"
35 #define DEBUG_TYPE PASS_KEY
37 STATISTIC(NumFences,
"Number of LFENCEs inserted for LVI mitigation");
38 STATISTIC(NumFunctionsConsidered,
"Number of functions analyzed");
39 STATISTIC(NumFunctionsMitigated,
"Number of functions for which mitigations "
48 return "X86 Load Value Injection (LVI) Ret-Hardening";
59 bool X86LoadValueInjectionRetHardeningPass::runOnMachineFunction(
64 if (!Subtarget->useLVIControlFlowIntegrity() || !Subtarget->is64Bit())
69 if (!
F.hasOptNone() && skipFunction(
F))
72 ++NumFunctionsConsidered;
77 for (
auto &
MBB : MF) {
79 if (
MBBI->getOpcode() != X86::RET64)
82 unsigned ClobberReg =
TRI->findDeadCallerSavedReg(
MBB,
MBBI);
83 if (ClobberReg != X86::NoRegister) {
111 ++NumFunctionsMitigated;
116 "X86 LVI ret hardener",
false,
false)
119 return new X86LoadValueInjectionRetHardeningPass();
bool addRegisterDead(Register Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
This is an optimization pass for GlobalISel generic memory operations.
const X86InstrInfo * getInstrInfo() const override
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
static const MachineInstrBuilder & addRegOffset(const MachineInstrBuilder &MIB, unsigned Reg, bool isKill, int Offset)
addRegOffset - This function is used to add a memory reference of the form [Reg + Offset],...
unsigned const TargetRegisterInfo * TRI
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const X86RegisterInfo * getRegisterInfo() const override
const HexagonInstrInfo * TII
STATISTIC(NumFunctions, "Total number of functions")
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
FunctionPass * createX86LoadValueInjectionRetHardeningPass()
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
Representation of each machine instruction.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
StringRef - Represent a constant reference to a string, i.e.
MachineBasicBlock MachineBasicBlock::iterator MBBI
Function & getFunction()
Return the LLVM function that this machine code represents.
@ Define
Register definition.
INITIALIZE_PASS(X86LoadValueInjectionRetHardeningPass, PASS_KEY, "X86 LVI ret hardener", false, false) FunctionPass *llvm
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass class - This class is used to implement most global optimizations.