aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/include/llvm/CodeGen/StackProtector.h
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/include/llvm/CodeGen/StackProtector.h')
-rw-r--r--contrib/llvm-project/llvm/include/llvm/CodeGen/StackProtector.h93
1 files changed, 63 insertions, 30 deletions
diff --git a/contrib/llvm-project/llvm/include/llvm/CodeGen/StackProtector.h b/contrib/llvm-project/llvm/include/llvm/CodeGen/StackProtector.h
index 57cb7a1c85ae..eb5d9d0caebc 100644
--- a/contrib/llvm-project/llvm/include/llvm/CodeGen/StackProtector.h
+++ b/contrib/llvm-project/llvm/include/llvm/CodeGen/StackProtector.h
@@ -19,6 +19,7 @@
#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
#include "llvm/TargetParser/Triple.h"
@@ -30,25 +31,15 @@ class Module;
class TargetLoweringBase;
class TargetMachine;
-class StackProtector : public FunctionPass {
-private:
+class SSPLayoutInfo {
+ friend class StackProtectorPass;
+ friend class SSPLayoutAnalysis;
+ friend class StackProtector;
static constexpr unsigned DefaultSSPBufferSize = 8;
/// A mapping of AllocaInsts to their required SSP layout.
- using SSPLayoutMap = DenseMap<const AllocaInst *,
- MachineFrameInfo::SSPLayoutKind>;
-
- const TargetMachine *TM = nullptr;
-
- /// TLI - Keep a pointer of a TargetLowering to consult for determining
- /// target type sizes.
- const TargetLoweringBase *TLI = nullptr;
- Triple Trip;
-
- Function *F = nullptr;
- Module *M = nullptr;
-
- std::optional<DomTreeUpdater> DTU;
+ using SSPLayoutMap =
+ DenseMap<const AllocaInst *, MachineFrameInfo::SSPLayoutKind>;
/// Layout - Mapping of allocations to the required SSPLayoutKind.
/// StackProtector analysis will update this map when determining if an
@@ -59,23 +50,59 @@ private:
/// protection when -fstack-protection is used.
unsigned SSPBufferSize = DefaultSSPBufferSize;
+ bool RequireStackProtector = false;
+
// A prologue is generated.
bool HasPrologue = false;
// IR checking code is generated.
bool HasIRCheck = false;
- /// InsertStackProtectors - Insert code into the prologue and epilogue of
- /// the function.
- ///
- /// - The prologue code loads and stores the stack guard onto the stack.
- /// - The epilogue checks the value stored in the prologue against the
- /// original value. It calls __stack_chk_fail if they differ.
- bool InsertStackProtectors();
+public:
+ // Return true if StackProtector is supposed to be handled by SelectionDAG.
+ bool shouldEmitSDCheck(const BasicBlock &BB) const;
+
+ void copyToMachineFrameInfo(MachineFrameInfo &MFI) const;
+};
+
+class SSPLayoutAnalysis : public AnalysisInfoMixin<SSPLayoutAnalysis> {
+ friend AnalysisInfoMixin<SSPLayoutAnalysis>;
+ using SSPLayoutMap = SSPLayoutInfo::SSPLayoutMap;
+
+ static AnalysisKey Key;
+
+public:
+ using Result = SSPLayoutInfo;
+
+ Result run(Function &F, FunctionAnalysisManager &FAM);
- /// CreateFailBB - Create a basic block to jump to when the stack protector
- /// check fails.
- BasicBlock *CreateFailBB();
+ /// Check whether or not \p F needs a stack protector based upon the stack
+ /// protector level.
+ static bool requiresStackProtector(Function *F,
+ SSPLayoutMap *Layout = nullptr);
+};
+
+class StackProtectorPass : public PassInfoMixin<StackProtectorPass> {
+ const TargetMachine *TM;
+
+public:
+ explicit StackProtectorPass(const TargetMachine *TM) : TM(TM) {}
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
+};
+
+class StackProtector : public FunctionPass {
+private:
+ /// A mapping of AllocaInsts to their required SSP layout.
+ using SSPLayoutMap = SSPLayoutInfo::SSPLayoutMap;
+
+ const TargetMachine *TM = nullptr;
+
+ Function *F = nullptr;
+ Module *M = nullptr;
+
+ std::optional<DomTreeUpdater> DTU;
+
+ SSPLayoutInfo LayoutInfo;
public:
static char ID; // Pass identification, replacement for typeid.
@@ -85,16 +112,22 @@ public:
void getAnalysisUsage(AnalysisUsage &AU) const override;
// Return true if StackProtector is supposed to be handled by SelectionDAG.
- bool shouldEmitSDCheck(const BasicBlock &BB) const;
+ bool shouldEmitSDCheck(const BasicBlock &BB) const {
+ return LayoutInfo.shouldEmitSDCheck(BB);
+ }
bool runOnFunction(Function &Fn) override;
- void copyToMachineFrameInfo(MachineFrameInfo &MFI) const;
+ void copyToMachineFrameInfo(MachineFrameInfo &MFI) const {
+ LayoutInfo.copyToMachineFrameInfo(MFI);
+ }
/// Check whether or not \p F needs a stack protector based upon the stack
/// protector level.
- static bool requiresStackProtector(Function *F, SSPLayoutMap *Layout = nullptr);
-
+ static bool requiresStackProtector(Function *F,
+ SSPLayoutMap *Layout = nullptr) {
+ return SSPLayoutAnalysis::requiresStackProtector(F, Layout);
+ }
};
} // end namespace llvm