aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Driver/CC1Options.td2
-rw-r--r--include/clang/Frontend/CodeGenOptions.h4
-rw-r--r--lib/CodeGen/BackendUtil.cpp1
-rw-r--r--lib/Driver/Tools.cpp12
-rw-r--r--lib/Frontend/CompilerInvocation.cpp2
-rw-r--r--test/Driver/stack-protector.c11
6 files changed, 32 insertions, 0 deletions
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 6e4d7f2d31..86b9bdec6c 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -415,6 +415,8 @@ def static_define : Flag<"-static-define">,
HelpText<"Should __STATIC__ be defined">;
def stack_protector : Separate<"-stack-protector">,
HelpText<"Enable stack protectors">;
+def stack_protector_buffer_size : Separate<"-stack-protector-buffer-size">,
+ HelpText<"Lower bound for a buffer to be considered for stack protection">;
def fvisibility : Separate<"-fvisibility">,
HelpText<"Default symbol visibility">;
def ftemplate_depth : Separate<"-ftemplate-depth">,
diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h
index 3e34093352..8610b8a89b 100644
--- a/include/clang/Frontend/CodeGenOptions.h
+++ b/include/clang/Frontend/CodeGenOptions.h
@@ -185,6 +185,9 @@ public:
/// The run-time penalty for bounds checking, or 0 to disable.
unsigned char BoundsChecking;
+ /// The lower bound for a buffer to be considered for stack protection.
+ unsigned SSPBufferSize;
+
/// The default TLS model to use.
TLSModel DefaultTLSModel;
@@ -241,6 +244,7 @@ public:
StackRealignment = 0;
StackAlignment = 0;
BoundsChecking = 0;
+ SSPBufferSize = 8;
UseInitArray = 0;
DebugInfo = NoDebugInfo;
diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp
index 0a1915b485..36b244ba33 100644
--- a/lib/CodeGen/BackendUtil.cpp
+++ b/lib/CodeGen/BackendUtil.cpp
@@ -375,6 +375,7 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action,
Options.DisableTailCalls = CodeGenOpts.DisableTailCalls;
Options.TrapFuncName = CodeGenOpts.TrapFuncName;
Options.PositionIndependentExecutable = LangOpts.PIELevel != 0;
+ Options.SSPBufferSize = CodeGenOpts.SSPBufferSize;
TargetMachine *TM = TheTarget->createTargetMachine(Triple, TargetOpts.CPU,
FeaturesStr, Options,
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index e9f1aab90b..11429131d7 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -2353,6 +2353,18 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (StackProtectorLevel) {
CmdArgs.push_back("-stack-protector");
CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
+
+ // --param ssp-buffer-size=
+ for (arg_iterator it = Args.filtered_begin(options::OPT__param),
+ ie = Args.filtered_end(); it != ie; ++it) {
+ StringRef Str((*it)->getValue(Args));
+ if (Str.startswith("ssp-buffer-size=")) {
+ CmdArgs.push_back("-stack-protector-buffer-size");
+ // FIXME: Verify the argument is a valid integer.
+ CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16)));
+ (*it)->claim();
+ }
+ }
}
// Translate -mstackrealign
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index d90bd92b9d..09e95ce693 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1267,6 +1267,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file);
Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file);
+ Opts.SSPBufferSize =
+ Args.getLastArgIntValue(OPT_stack_protector_buffer_size, 8, Diags);
Opts.StackRealignment = Args.hasArg(OPT_mstackrealign);
if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) {
StringRef Val = A->getValue(Args);
diff --git a/test/Driver/stack-protector.c b/test/Driver/stack-protector.c
new file mode 100644
index 0000000000..5f3d679c1a
--- /dev/null
+++ b/test/Driver/stack-protector.c
@@ -0,0 +1,11 @@
+// RUN: %clang -fno-stack-protector -### %s 2>&1 | FileCheck %s -check-prefix=NOSSP
+// NOSSP-NOT: "-stack-protector" "1"
+// NOSSP-NOT: "-stack-protector-buffer-size"
+
+// RUN: %clang -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=SSP
+// SSP: "-stack-protector" "1"
+// SSP-NOT: "-stack-protector-buffer-size"
+
+// RUN: %clang -fstack-protector --param ssp-buffer-size=16 -### %s 2>&1 | FileCheck %s -check-prefix=SSP-BUF
+// SSP-BUF: "-stack-protector" "1"
+// SSP-BUF: "-stack-protector-buffer-size" "16"