33#define PASS_KEY "x86-lvi-ret"
34#define DEBUG_TYPE PASS_KEY
36STATISTIC(NumFences,
"Number of LFENCEs inserted for LVI mitigation");
37STATISTIC(NumFunctionsConsidered,
"Number of functions analyzed");
38STATISTIC(NumFunctionsMitigated,
"Number of functions for which mitigations "
47 return "X86 Load Value Injection (LVI) Ret-Hardening";
56char X86LoadValueInjectionRetHardeningPass::ID = 0;
58bool X86LoadValueInjectionRetHardeningPass::runOnMachineFunction(
63 if (!Subtarget->useLVIControlFlowIntegrity() || !Subtarget->is64Bit())
68 if (!
F.hasOptNone() && skipFunction(
F))
71 ++NumFunctionsConsidered;
76 for (
auto &
MBB : MF) {
78 if (
MBBI->getOpcode() != X86::RET64)
81 unsigned ClobberReg =
TRI->findDeadCallerSavedReg(
MBB,
MBBI);
82 if (ClobberReg != X86::NoRegister) {
110 ++NumFunctionsMitigated;
115 "X86 LVI ret hardener",
false,
false)
118 return new X86LoadValueInjectionRetHardeningPass();
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
FunctionPass class - This class is used to implement most global optimizations.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
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.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
bool addRegisterDead(Register Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
StringRef - Represent a constant reference to a string, i.e.
const X86InstrInfo * getInstrInfo() const override
const X86RegisterInfo * getRegisterInfo() const override
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ Define
Register definition.
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.
FunctionPass * createX86LoadValueInjectionRetHardeningPass()
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],...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.