29#define DEBUG_TYPE "cfguard-longjmp"
32 "Number of Control Flow Guard longjmp targets");
44 StringRef getPassName()
const override {
45 return "Control Flow Guard longjmp targets";
48 bool runOnMachineFunction(MachineFunction &MF)
override;
53char CFGuardLongjmp::ID = 0;
56 "Insert symbols at valid longjmp targets for /guard:cf",
false,
64 ControlFlowGuardMode::Disabled)
71 SmallVector<MachineInstr *, 8> SetjmpCalls;
75 for (MachineBasicBlock &
MBB : MF) {
76 for (MachineInstr &
MI :
MBB) {
79 if (!
MI.isCall() ||
MI.getNumOperands() < 1)
83 for (MachineOperand &MO :
MI.operands()) {
93 if (
F->hasFnAttribute(Attribute::ReturnsTwice)) {
101 if (SetjmpCalls.
empty())
104 unsigned SetjmpNum = 0;
109 for (MachineInstr *Setjmp : SetjmpCalls) {
111 raw_svector_ostream(SymbolName) <<
"$cfgsj_" << MF.getName() << SetjmpNum++;
112 MCSymbol *SjSymbol = MF.getContext().getOrCreateSymbol(SymbolName);
114 Setjmp->setPostInstrSymbol(MF, SjSymbol);
115 MF.addLongjmpTarget(SjSymbol);
116 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.
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 FunctionPass * createCFGuardLongjmpPass()
Creates CFGuard longjmp target identification pass.