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 "
44 "X86 Load Value Injection (LVI) Ret-Hardening";
49 StringRef getPassName()
const override {
return X86LVIRetPassName; }
50 bool runOnMachineFunction(MachineFunction &MF)
override;
57char X86LoadValueInjectionRetHardeningLegacy::ID = 0;
61 if (!Subtarget->useLVIControlFlowIntegrity() || !Subtarget->is64Bit())
66 ++NumFunctionsConsidered;
71 for (
auto &
MBB : MF) {
73 if (
MBBI->getOpcode() != X86::RET64)
76 unsigned ClobberReg =
TRI->findDeadCallerSavedReg(
MBB,
MBBI);
77 if (ClobberReg != X86::NoRegister) {
105 ++NumFunctionsMitigated;
109bool X86LoadValueInjectionRetHardeningLegacy::runOnMachineFunction(
114 if (!
F.hasOptNone() && skipFunction(
F))
129 "X86 LVI ret hardener",
false,
false)
132 return new X86LoadValueInjectionRetHardeningLegacy();
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
Register 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)
static bool runX86LoadValueInjectionRetHardening(MachineFunction &MF)
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
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.
LLVM_ABI bool addRegisterDead(Register Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
StringRef - Represent a constant reference to a string, i.e.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createX86LoadValueInjectionRetHardeningLegacyPass()
static const MachineInstrBuilder & addRegOffset(const MachineInstrBuilder &MIB, Register Reg, bool isKill, int Offset)
addRegOffset - This function is used to add a memory reference of the form [Reg + Offset],...