Go to the documentation of this file.
29 #define DEBUG_TYPE "x86-indirect-branch-tracking"
33 cl::desc(
"Enable X86 indirect branch tracking pass."));
35 STATISTIC(NumEndBranchAdded,
"Number of ENDBR instructions added");
43 return "X86 Indirect Branch Tracking";
55 unsigned int EndbrOpcode = 0;
69 return new X86IndirectBranchTrackingPass();
72 bool X86IndirectBranchTrackingPass::addENDBR(
74 assert(
TII &&
"Target instruction info was not initialized");
75 assert((X86::ENDBR64 == EndbrOpcode || X86::ENDBR32 == EndbrOpcode) &&
76 "Unexpected Endbr opcode");
80 if (
I ==
MBB.
end() ||
I->getOpcode() != EndbrOpcode) {
91 auto *CalleeFn = dyn_cast<Function>(MOp.
getGlobal());
95 return Attrs.hasFnAttr(Attribute::ReturnsTwice);
102 if (
F.doesNoCfCheck())
107 Metadata *IBTSeal =
M->getModuleFlag(
"ibt-seal");
109 switch (
TM->getCodeModel()) {
118 return F.hasAddressTaken();
124 return (
F.hasAddressTaken() || !
F.hasLocalLinkage());
128 bool X86IndirectBranchTrackingPass::runOnMachineFunction(
MachineFunction &MF) {
133 Metadata *isCFProtectionSupported =
M->getModuleFlag(
"cf-protection-branch");
140 bool isJITwithCET =
TM->isJIT();
142 bool isJITwithCET =
false;
148 bool Changed =
false;
151 EndbrOpcode = SubTarget.is64Bit() ? X86::ENDBR64 : X86::ENDBR32;
159 for (
auto &
MBB : MF) {
166 if (
I->isCall() &&
I->getNumOperands() > 0 &&
168 Changed |= addENDBR(
MBB, std::next(
I));
179 if (
I->isDebugInstr())
181 Changed |= addENDBR(
MBB,
I);
183 }
else if (
I->isEHLabel()) {
186 MCSymbol *Sym =
I->getOperand(0).getMCSymbol();
187 if (!MF.hasCallSiteLandingPad(Sym))
189 Changed |= addENDBR(
MBB, std::next(
I));
197 Changed |= addENDBR(
MBB, std::next(
I));
This is an optimization pass for GlobalISel generic memory operations.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
@ SjLj
setjmp/longjmp based exceptions
const GlobalValue * getGlobal() const
const X86InstrInfo * getInstrInfo() const override
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions.
const HexagonInstrInfo * TII
MachineOperand class - Representation of each machine instruction operand.
STATISTIC(NumFunctions, "Total number of functions")
static bool IsCallReturnTwice(llvm::MachineOperand &MOp)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
AttributeList getAttributes() const
Return the attribute list for this Function.
MachineModuleInfo & getMMI() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
initializer< Ty > init(const Ty &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A Module instance is used to store all the information related to an LLVM module.
bool isEHPad() const
Returns true if the block is a landing pad.
StringRef - Represent a constant reference to a string, i.e.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Function & getFunction()
Return the LLVM function that this machine code represents.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
static bool needsPrologueENDBR(MachineFunction &MF, const Module *M)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createX86IndirectBranchTrackingPass()
This pass inserts ENDBR instructions before indirect jump/call destinations as part of CET IBT mechan...
const char LLVMTargetMachineRef TM
FunctionPass class - This class is used to implement most global optimizations.
const Module * getModule() const
cl::opt< bool > IndirectBranchTracking("x86-indirect-branch-tracking", cl::init(false), cl::Hidden, cl::desc("Enable X86 indirect branch tracking pass."))
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.