29#define DEBUG_TYPE "cfguard-longjmp"
32 "Number of Control Flow Guard longjmp targets");
46 StringRef getPassName()
const override {
47 return "Control Flow Guard longjmp targets";
50 bool runOnMachineFunction(MachineFunction &MF)
override;
55char CFGuardLongjmp::ID = 0;
58 "Insert symbols at valid longjmp targets for /guard:cf",
false,
66 ControlFlowGuardMode::Disabled)
73 SmallVector<MachineInstr *, 8> SetjmpCalls;
77 for (MachineBasicBlock &
MBB : MF) {
78 for (MachineInstr &
MI :
MBB) {
81 if (!
MI.isCall() ||
MI.getNumOperands() < 1)
85 for (MachineOperand &MO :
MI.operands()) {
95 if (
F->hasFnAttribute(Attribute::ReturnsTwice)) {
103 if (SetjmpCalls.
empty())
106 unsigned SetjmpNum = 0;
111 for (MachineInstr *Setjmp : SetjmpCalls) {
113 raw_svector_ostream(SymbolName) <<
"$cfgsj_" << MF.getName() << SetjmpNum++;
114 MCSymbol *SjSymbol = MF.getContext().getOrCreateSymbol(SymbolName);
116 Setjmp->setPostInstrSymbol(MF, SjSymbol);
117 MF.addLongjmpTarget(SjSymbol);
118 CFGuardLongjmpTargets++;
Module.h This file contains the declarations for the Module class.
#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.
bool callsFunctionThatReturnsTwice() const
callsFunctionThatReturnsTwice - Return true if the function has a call to setjmp or other function th...
Module * getParent()
Get the module that this global value is contained inside of...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Function & getFunction()
Return the LLVM function that this machine code represents.
ControlFlowGuardMode getControlFlowGuardMode() const
Gets the Control Flow Guard mode.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void push_back(const T &Elt)
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void initializeCFGuardLongjmpPass(PassRegistry &)
LLVM_ABI FunctionPass * createCFGuardLongjmpPass()
Creates CFGuard longjmp target identification pass.