LLVM 22.0.0git
StackProtector.cpp File Reference

Go to the source code of this file.

Classes

struct  PhiInfo
 Maximum remaining allocation size observed for a phi node, and how often the allocation size has already been decreased. More...

Macros

#define DEBUG_TYPE   "stack-protector"

Typedefs

using PhiMap = SmallDenseMap<const PHINode *, PhiInfo, 16>

Functions

 STATISTIC (NumFunProtected, "Number of functions protected")
 STATISTIC (NumAddrTaken, "Number of local variables that have their address" " taken.")
static bool InsertStackProtectors (const TargetMachine *TM, Function *F, DomTreeUpdater *DTU, bool &HasPrologue, bool &HasIRCheck)
 InsertStackProtectors - Insert code into the prologue and epilogue of the function.
static BasicBlockCreateFailBB (Function *F, const TargetLowering &TLI)
 CreateFailBB - Create a basic block to jump to when the stack protector check fails.
 INITIALIZE_PASS_BEGIN (StackProtector, DEBUG_TYPE, "Insert stack protectors", false, true) INITIALIZE_PASS_END(StackProtector
static bool ContainsProtectableArray (Type *Ty, Module *M, unsigned SSPBufferSize, bool &IsLarge, bool Strong, bool InStruct)
static bool HasAddressTaken (const Instruction *AI, TypeSize AllocSize, Module *M, PhiMap &VisitedPHIs)
 Check whether a stack allocation has its address taken.
static const CallInstfindStackProtectorIntrinsic (Function &F)
 Search for the first call to the llvm.stackprotector intrinsic and return it if present.
static ValuegetStackGuard (const TargetLoweringBase *TLI, Module *M, IRBuilder<> &B, bool *SupportsSelectionDAGSP=nullptr)
 Create a stack guard loading and populate whether SelectionDAG SSP is supported.
static bool CreatePrologue (Function *F, Module *M, Instruction *CheckLoc, const TargetLoweringBase *TLI, AllocaInst *&AI)
 Insert code into the entry block that stores the stack guard variable onto the stack:

Variables

static cl::opt< boolEnableSelectionDAGSP ("enable-selectiondag-sp", cl::init(true), cl::Hidden)
static cl::opt< boolDisableCheckNoReturn ("disable-check-noreturn-call", cl::init(false), cl::Hidden)
 DEBUG_TYPE
Insert stack protectors
Insert stack false

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "stack-protector"

Definition at line 56 of file StackProtector.cpp.

Typedef Documentation

◆ PhiMap

Definition at line 264 of file StackProtector.cpp.

Function Documentation

◆ ContainsProtectableArray()

bool ContainsProtectableArray ( Type * Ty,
Module * M,
unsigned SSPBufferSize,
bool & IsLarge,
bool Strong,
bool InStruct )
static
Parameters
[out]IsLargeis set to true if a protectable array is found and it is "large" ( >= ssp-buffer-size). In the case of a structure with multiple arrays, this gets set if any of them is large.

Definition at line 210 of file StackProtector.cpp.

References ContainsProtectableArray(), and llvm::dyn_cast().

Referenced by ContainsProtectableArray(), and llvm::SSPLayoutAnalysis::requiresStackProtector().

◆ CreateFailBB()

BasicBlock * CreateFailBB ( Function * F,
const TargetLowering & TLI )
static

CreateFailBB - Create a basic block to jump to when the stack protector check fails.

Definition at line 717 of file StackProtector.cpp.

References B(), Call, llvm::BasicBlock::Create(), F, llvm::MDNode::get(), llvm::TargetLoweringBase::getLibcallName(), llvm::PointerType::getUnqual(), and llvm::Type::getVoidTy().

Referenced by InsertStackProtectors().

◆ CreatePrologue()

bool CreatePrologue ( Function * F,
Module * M,
Instruction * CheckLoc,
const TargetLoweringBase * TLI,
AllocaInst *& AI )
static

Insert code into the entry block that stores the stack guard variable onto the stack:

entry: StackGuardSlot = alloca i8* StackGuard = <stack guard> call void @llvm.stackprotector(StackGuard, StackGuardSlot)

Returns true if the platform/triple supports the stackprotectorcreate pseudo node.

Definition at line 558 of file StackProtector.cpp.

References B(), F, getStackGuard(), and llvm::PointerType::getUnqual().

Referenced by InsertStackProtectors().

◆ findStackProtectorIntrinsic()

const CallInst * findStackProtectorIntrinsic ( Function & F)
static

Search for the first call to the llvm.stackprotector intrinsic and return it if present.

Definition at line 372 of file StackProtector.cpp.

References llvm::dyn_cast(), F, I, and II.

Referenced by InsertStackProtectors().

◆ getStackGuard()

Value * getStackGuard ( const TargetLoweringBase * TLI,
Module * M,
IRBuilder<> & B,
bool * SupportsSelectionDAGSP = nullptr )
static

Create a stack guard loading and populate whether SelectionDAG SSP is supported.

Definition at line 523 of file StackProtector.cpp.

References B(), llvm::StringRef::empty(), llvm::TargetLoweringBase::getIRStackGuard(), and llvm::TargetLoweringBase::insertSSPDeclarations().

Referenced by CreatePrologue(), and InsertStackProtectors().

◆ HasAddressTaken()

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( StackProtector ,
DEBUG_TYPE ,
"Insert stack protectors" ,
false ,
true  )

◆ InsertStackProtectors()

bool InsertStackProtectors ( const TargetMachine * TM,
Function * F,
DomTreeUpdater * DTU,
bool & HasPrologue,
bool & HasIRCheck )
static

◆ STATISTIC() [1/2]

STATISTIC ( NumAddrTaken ,
"Number of local variables that have their address" " taken."  )

◆ STATISTIC() [2/2]

STATISTIC ( NumFunProtected ,
"Number of functions protected"  )

Variable Documentation

◆ DEBUG_TYPE

DEBUG_TYPE

Definition at line 162 of file StackProtector.cpp.

◆ DisableCheckNoReturn

cl::opt< bool > DisableCheckNoReturn("disable-check-noreturn-call", cl::init(false), cl::Hidden) ( "disable-check-noreturn-call" ,
cl::init(false) ,
cl::Hidden  )
static

Referenced by InsertStackProtectors().

◆ EnableSelectionDAGSP

cl::opt< bool > EnableSelectionDAGSP("enable-selectiondag-sp", cl::init(true), cl::Hidden) ( "enable-selectiondag-sp" ,
cl::init(true) ,
cl::Hidden  )
static

Referenced by InsertStackProtectors().

◆ false

Insert stack false

Definition at line 163 of file StackProtector.cpp.

◆ protectors

Insert stack protectors

Definition at line 163 of file StackProtector.cpp.