]> granicus.if.org Git - clang/commitdiff
enable -fstack-protector on 10.5 for usermode binaries by default.
authorNico Weber <nicolasweber@gmx.de>
Tue, 23 Aug 2011 07:38:27 +0000 (07:38 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 23 Aug 2011 07:38:27 +0000 (07:38 +0000)
This matches gcc's behavior.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138324 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/ToolChain.h
lib/Driver/ToolChains.h
lib/Driver/Tools.cpp

index eaa11727236f32936564bdbc59012c1f47648836..767b7439bfb32886bb297c7921e8a061a563febd 100644 (file)
@@ -139,7 +139,9 @@ public:
 
   /// GetDefaultStackProtectorLevel - Get the default stack protector level for
   /// this tool chain (0=off, 1=on, 2=all).
-  virtual unsigned GetDefaultStackProtectorLevel() const { return 0; }
+  virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
+    return 0;
+  }
 
   /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
   /// by default.
index 24545ec4b79f89842fc08d7240b14e011009ec5e..cfb8869f47ef66670a26344bfbf9e1c0988383fc 100644 (file)
@@ -237,9 +237,12 @@ public:
     return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
   }
   virtual bool IsUnwindTablesDefault() const;
-  virtual unsigned GetDefaultStackProtectorLevel() const {
-    // Stack protectors default to on for 10.6 and beyond.
-    return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
+  virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
+    // Stack protectors default to on for user code on 10.5,
+    // and for everything in 10.6 and beyond
+    return !isTargetIPhoneOS() &&
+      (!isMacosxVersionLT(10, 6) ||
+         (!isMacosxVersionLT(10, 5) && !KernelOrKext));
   }
   virtual const char *GetDefaultRelocationModel() const;
   virtual const char *GetForcedPicModel() const;
index 160c0062632b1358b5a44730263723f4e4617e1a..e147c05ffe6f269fa63340ceb1ae8237aeeb951f 100644 (file)
@@ -1671,8 +1671,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
       StackProtectorLevel = 1;
     else if (A->getOption().matches(options::OPT_fstack_protector_all))
       StackProtectorLevel = 2;
-  } else
-    StackProtectorLevel = getToolChain().GetDefaultStackProtectorLevel();
+  } else {
+    StackProtectorLevel =
+      getToolChain().GetDefaultStackProtectorLevel(KernelOrKext);
+  }
   if (StackProtectorLevel) {
     CmdArgs.push_back("-stack-protector");
     CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));