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,
72 SmallVector<MachineInstr *, 8> SetjmpCalls;
76 for (MachineBasicBlock &
MBB : MF) {
77 for (MachineInstr &
MI :
MBB) {
80 if (!
MI.isCall() ||
MI.getNumOperands() < 1)
84 for (MachineOperand &MO :
MI.operands()) {
94 if (
F->hasFnAttribute(Attribute::ReturnsTwice)) {
102 if (SetjmpCalls.
empty())
105 unsigned SetjmpNum = 0;
110 for (MachineInstr *Setjmp : SetjmpCalls) {
112 raw_svector_ostream(SymbolName) <<
"$cfgsj_" << MF.getName() << SetjmpNum++;
113 MCSymbol *SjSymbol = MF.getContext().getOrCreateSymbol(SymbolName);
115 Setjmp->setPostInstrSymbol(MF, SjSymbol);
116 MF.addLongjmpTarget(SjSymbol);
117 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.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
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.