LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions | Variables
StackProtector.cpp File Reference
#include "llvm/CodeGen/StackProtector.h"
#include "llvm/CodeGen/Analysis.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/CommandLine.h"
#include <cstdlib>
Include dependency graph for StackProtector.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "stack-protector"
 

Functions

 STATISTIC (NumFunProtected,"Number of functions protected")
 
 STATISTIC (NumAddrTaken,"Number of local variables that have their address"" taken.")
 
 INITIALIZE_PASS (StackProtector,"stack-protector","Insert stack protectors", false, true) FunctionPass *llvm
 
static bool InstructionWillNotHaveChain (const Instruction *I)
 
static CallInstFindPotentialTailCall (BasicBlock *BB, ReturnInst *RI, const TargetLoweringBase *TLI)
 
static bool CreatePrologue (Function *F, Module *M, ReturnInst *RI, const TargetLoweringBase *TLI, const Triple &Trip, AllocaInst *&AI, Value *&StackGuardVar)
 

Variables

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

Macro Definition Documentation

#define DEBUG_TYPE   "stack-protector"

Definition at line 17 of file StackProtector.cpp.

Function Documentation

static bool CreatePrologue ( Function F,
Module M,
ReturnInst RI,
const TargetLoweringBase TLI,
const Triple Trip,
AllocaInst *&  AI,
Value *&  StackGuardVar 
)
static

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

entry: StackGuardSlot = alloca i8* StackGuard = load __stack_chk_guard call void .stackprotect.create(StackGuard, StackGuardSlot)

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

Definition at line 315 of file StackProtector.cpp.

References llvm::BasicBlock::front(), llvm::ConstantInt::get(), llvm::PointerType::get(), llvm::Value::getContext(), llvm::Intrinsic::getDeclaration(), llvm::Function::getEntryBlock(), llvm::Type::getInt32Ty(), llvm::Type::getInt8PtrTy(), llvm::ConstantExpr::getIntToPtr(), llvm::Module::getOrInsertGlobal(), llvm::Triple::getOS(), llvm::TargetLoweringBase::getStackCookieLocation(), llvm::GlobalValue::HiddenVisibility, LI, llvm::Triple::OpenBSD, and llvm::Intrinsic::stackprotector.

static CallInst* FindPotentialTailCall ( BasicBlock BB,
ReturnInst RI,
const TargetLoweringBase TLI 
)
static

Identify if RI has a previous instruction in the "Tail Position" and return it. Otherwise return 0.

This is based off of the code in llvm::isInTailCallPosition. The difference is that it inverts the first part of llvm::isInTailCallPosition since isInTailCallPosition is checking if a call is in a tail call position, and we are searching for an unknown tail call that might be in the tail call position. Once we find the call though, the code uses the same refactored code, returnTypeIsEligibleForTailCall.

Definition at line 256 of file StackProtector.cpp.

References llvm::BasicBlock::getParent(), I, InstructionWillNotHaveChain(), llvm::next(), llvm::BasicBlock::rbegin(), llvm::BasicBlock::rend(), and llvm::returnTypeIsEligibleForTailCall().

INITIALIZE_PASS ( StackProtector  ,
"stack-protector"  ,
"Insert stack protectors"  ,
false  ,
true   
)

Definition at line 49 of file StackProtector.cpp.

static bool InstructionWillNotHaveChain ( const Instruction I)
static
STATISTIC ( NumFunProtected  ,
"Number of functions protected"   
)
STATISTIC ( NumAddrTaken  ,
"Number of local variables that have their address"" taken."   
)

Variable Documentation

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