summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2013-07-22 20:15:21 +0000
committerBill Wendling <isanbard@gmail.com>2013-07-22 20:15:21 +0000
commit0dcba2fadb990ba2298ba43d76372c754b240cee (patch)
tree76012f758dae9930ac7399a79185468e9769ad9f
parent9a05b98ef9ec58c52f35ce04677f24ef62a79701 (diff)
downloadllvm-0dcba2fadb990ba2298ba43d76372c754b240cee.tar.gz
llvm-0dcba2fadb990ba2298ba43d76372c754b240cee.tar.bz2
llvm-0dcba2fadb990ba2298ba43d76372c754b240cee.tar.xz
Recommit r186217 with testcase fix:
Use the function attributes to pass along the stack protector buffer size. Now that we have robust function attributes, don't use a command line option to specify the stack protecto buffer size. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186863 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/CodeGen/CommandFlags.h4
-rw-r--r--include/llvm/Target/TargetOptions.h7
-rw-r--r--lib/CodeGen/StackProtector.cpp26
-rw-r--r--test/DebugInfo/X86/dbg_value_direct.ll6
-rw-r--r--tools/llc/llc.cpp1
-rw-r--r--tools/lto/LTOModule.cpp6
-rw-r--r--tools/opt/opt.cpp1
7 files changed, 23 insertions, 28 deletions
diff --git a/include/llvm/CodeGen/CommandFlags.h b/include/llvm/CodeGen/CommandFlags.h
index 9a27661b51..fd1d67bdcd 100644
--- a/include/llvm/CodeGen/CommandFlags.h
+++ b/include/llvm/CodeGen/CommandFlags.h
@@ -220,8 +220,4 @@ cl::opt<std::string> StartAfter("start-after",
cl::value_desc("pass-name"),
cl::init(""));
-cl::opt<unsigned>
-SSPBufferSize("stack-protector-buffer-size", cl::init(8),
- cl::desc("Lower bound for a buffer to be considered for "
- "stack protection"));
#endif
diff --git a/include/llvm/Target/TargetOptions.h b/include/llvm/Target/TargetOptions.h
index e240a9aeed..04b2080106 100644
--- a/include/llvm/Target/TargetOptions.h
+++ b/include/llvm/Target/TargetOptions.h
@@ -48,7 +48,7 @@ namespace llvm {
UseSoftFloat(false), NoZerosInBSS(false),
JITEmitDebugInfo(false), JITEmitDebugInfoToDisk(false),
GuaranteedTailCallOpt(false), DisableTailCalls(false),
- StackAlignmentOverride(0), RealignStack(true), SSPBufferSize(0),
+ StackAlignmentOverride(0), RealignStack(true),
EnableFastISel(false), PositionIndependentExecutable(false),
EnableSegmentedStacks(false), UseInitArray(false), TrapFuncName(""),
FloatABIType(FloatABI::Default), AllowFPOpFusion(FPOpFusion::Standard)
@@ -151,10 +151,6 @@ namespace llvm {
/// automatically realigned, if needed.
unsigned RealignStack : 1;
- /// SSPBufferSize - The minimum size of buffers that will receive stack
- /// smashing protection when -fstack-protection is used.
- unsigned SSPBufferSize;
-
/// EnableFastISel - This flag enables fast-path instruction selection
/// which trades away generated code quality in favor of reducing
/// compile time.
@@ -224,7 +220,6 @@ inline bool operator==(const TargetOptions &LHS,
ARE_EQUAL(DisableTailCalls) &&
ARE_EQUAL(StackAlignmentOverride) &&
ARE_EQUAL(RealignStack) &&
- ARE_EQUAL(SSPBufferSize) &&
ARE_EQUAL(EnableFastISel) &&
ARE_EQUAL(PositionIndependentExecutable) &&
ARE_EQUAL(EnableSegmentedStacks) &&
diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp
index 1f673ab037..9ec7daca96 100644
--- a/lib/CodeGen/StackProtector.cpp
+++ b/lib/CodeGen/StackProtector.cpp
@@ -33,6 +33,7 @@
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetLowering.h"
+#include <cstdlib>
using namespace llvm;
STATISTIC(NumFunProtected, "Number of functions protected");
@@ -53,6 +54,10 @@ namespace {
DominatorTree *DT;
+ /// \brief The minimum size of buffers that will receive stack smashing
+ /// protection when -fstack-protection is used.
+ unsigned SSPBufferSize;
+
/// VisitedPHIs - The set of PHI nodes visited when determining
/// if a variable's reference has been taken. This set
/// is maintained to ensure we don't visit the same PHI node multiple
@@ -85,11 +90,12 @@ namespace {
bool RequiresStackProtector();
public:
static char ID; // Pass identification, replacement for typeid.
- StackProtector() : FunctionPass(ID), TM(0), TLI(0) {
+ StackProtector() : FunctionPass(ID), TM(0), TLI(0), SSPBufferSize(0) {
initializeStackProtectorPass(*PassRegistry::getPassRegistry());
}
StackProtector(const TargetMachine *TM)
- : FunctionPass(ID), TM(TM), TLI(0), Trip(TM->getTargetTriple()) {
+ : FunctionPass(ID), TM(TM), TLI(0), Trip(TM->getTargetTriple()),
+ SSPBufferSize(8) {
initializeStackProtectorPass(*PassRegistry::getPassRegistry());
}
@@ -117,6 +123,12 @@ bool StackProtector::runOnFunction(Function &Fn) {
if (!RequiresStackProtector()) return false;
+ Attribute Attr =
+ Fn.getAttributes().getAttribute(AttributeSet::FunctionIndex,
+ "stack-protector-buffer-size");
+ if (Attr.isStringAttribute())
+ SSPBufferSize = atoi(Attr.getValueAsString().data());
+
++NumFunProtected;
return InsertStackProtectors();
}
@@ -132,7 +144,6 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool Strong,
// protector
if (Strong)
return true;
- const TargetMachine &TM = TLI->getTargetMachine();
if (!AT->getElementType()->isIntegerTy(8)) {
// If we're on a non-Darwin platform or we're inside of a structure, don't
// add stack protectors unless the array is a character array.
@@ -142,7 +153,7 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool Strong,
// If an array has more than SSPBufferSize bytes of allocated space, then we
// emit stack protectors.
- if (TM.Options.SSPBufferSize <= TLI->getDataLayout()->getTypeAllocSize(AT))
+ if (SSPBufferSize <= TLI->getDataLayout()->getTypeAllocSize(AT))
return true;
}
@@ -230,13 +241,14 @@ bool StackProtector::RequiresStackProtector() {
if (const ConstantInt *CI =
dyn_cast<ConstantInt>(AI->getArraySize())) {
- unsigned BufferSize = TLI->getTargetMachine().Options.SSPBufferSize;
- if (CI->getLimitedValue(BufferSize) >= BufferSize)
+ if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize)
// A call to alloca with size >= SSPBufferSize requires
// stack protectors.
return true;
- } else // A call to alloca with a variable size requires protectors.
+ } else {
+ // A call to alloca with a variable size requires protectors.
return true;
+ }
}
if (ContainsProtectableArray(AI->getAllocatedType(), Strong))
diff --git a/test/DebugInfo/X86/dbg_value_direct.ll b/test/DebugInfo/X86/dbg_value_direct.ll
index f095ece2e0..9a40d59b77 100644
--- a/test/DebugInfo/X86/dbg_value_direct.ll
+++ b/test/DebugInfo/X86/dbg_value_direct.ll
@@ -1,4 +1,4 @@
-; RUN: llc -filetype=obj -O0 -stack-protector-buffer-size=1 < %s
+; RUN: llc -filetype=obj -O0 < %s
; Test that we handle DBG_VALUEs in a register without crashing.
;
; Generated from clang with -fsanitize=address:
@@ -23,7 +23,7 @@ target triple = "x86_64-unknown-linux-gnu"
@__asan_gen_ = private unnamed_addr constant [16 x i8] c"1 32 4 5 .addr \00", align 1
; Function Attrs: sanitize_address uwtable
-define void @_Z4funci(%struct.A* noalias sret %agg.result, i32) #0 {
+define void @_Z4funci(%struct.A* noalias sret %agg.result, i32) #0 "stack-protector-buffer-size"="1" {
entry:
%MyAlloca = alloca [96 x i8], align 32
%1 = ptrtoint [96 x i8]* %MyAlloca to i64
@@ -89,7 +89,7 @@ declare void @llvm.dbg.declare(metadata, metadata) #1
declare void @_ZN1AC1Ev(%struct.A*) #2
-define internal void @asan.module_ctor() {
+define internal void @asan.module_ctor() "stack-protector-buffer-size"="1" {
call void @__asan_init_v3()
%1 = load volatile i64* @__asan_mapping_offset
%2 = load volatile i64* @__asan_mapping_scale
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index b5852aad11..b62f41aec8 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -281,7 +281,6 @@ static int compileModule(char **argv, LLVMContext &Context) {
Options.PositionIndependentExecutable = EnablePIE;
Options.EnableSegmentedStacks = SegmentedStacks;
Options.UseInitArray = UseInitArray;
- Options.SSPBufferSize = SSPBufferSize;
OwningPtr<TargetMachine>
target(TheTarget->createTargetMachine(TheTriple.getTriple(),
diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp
index 6220dd1c56..5ee43ba022 100644
--- a/tools/lto/LTOModule.cpp
+++ b/tools/lto/LTOModule.cpp
@@ -151,11 +151,6 @@ UseInitArray("use-init-array",
cl::desc("Use .init_array instead of .ctors."),
cl::init(false));
-static cl::opt<unsigned>
-SSPBufferSize("stack-protector-buffer-size", cl::init(8),
- cl::desc("Lower bound for a buffer to be considered for "
- "stack protection"));
-
LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
: _module(m), _target(t),
_context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL),
@@ -261,7 +256,6 @@ void LTOModule::getTargetOptions(TargetOptions &Options) {
Options.PositionIndependentExecutable = EnablePIE;
Options.EnableSegmentedStacks = SegmentedStacks;
Options.UseInitArray = UseInitArray;
- Options.SSPBufferSize = SSPBufferSize;
}
LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index bb8d143e81..23acefafbe 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -510,7 +510,6 @@ static TargetOptions GetTargetOptions() {
Options.PositionIndependentExecutable = EnablePIE;
Options.EnableSegmentedStacks = SegmentedStacks;
Options.UseInitArray = UseInitArray;
- Options.SSPBufferSize = SSPBufferSize;
return Options;
}