Add stack protector support to clang. This generates the 'ssp' and 'sspreq'
function attributes. There are predefined macros that are defined when stack
protectors are used: __SSP__=1 with -fstack-protector and __SSP_ALL__=2 with
-fstack-protector-all.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74405 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index bfc247a..ac07906 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -498,6 +498,18 @@
   Args.AddLastArg(CmdArgs, options::OPT_fvisibility_EQ);
   Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings);
 
+  // Forward stack protector flags.
+  if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
+                               options::OPT_fstack_protector_all,
+                               options::OPT_fstack_protector)) {
+    if (A->getOption().matches(options::OPT_fno_stack_protector))
+      CmdArgs.push_back("--stack-protector=0");
+    else if (A->getOption().matches(options::OPT_fstack_protector))
+      CmdArgs.push_back("--stack-protector=1");
+    else
+      CmdArgs.push_back("--stack-protector=2");
+  }
+
   // Forward -f options with positive and negative forms; we translate
   // these by hand.