r289005 - [Driver][Darwin] Disable default stack protector levels in freestanding mode.
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 7 16:22:06 PST 2016
Author: bruno
Date: Wed Dec 7 18:22:06 2016
New Revision: 289005
URL: http://llvm.org/viewvc/llvm-project?rev=289005&view=rev
Log:
[Driver][Darwin] Disable default stack protector levels in freestanding mode.
Currently -fstack-protector is on by default when using -ffreestanding.
Change the default behavior to have it off when using -ffreestanding.
rdar://problem/14089363
Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/stack-protector.c
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=289005&r1=289004&r2=289005&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Dec 7 18:22:06 2016
@@ -5279,9 +5279,12 @@ void Clang::ConstructJob(Compilation &C,
Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
// -fhosted is default.
+ bool IsHosted = true;
if (Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted, false) ||
- KernelOrKext)
+ KernelOrKext) {
CmdArgs.push_back("-ffreestanding");
+ IsHosted = false;
+ }
// Forward -f (flag) options which we can pass directly.
Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
@@ -5414,6 +5417,10 @@ void Clang::ConstructJob(Compilation &C,
} else {
StackProtectorLevel =
getToolChain().GetDefaultStackProtectorLevel(KernelOrKext);
+ // Only use a default stack protector on Darwin in case -ffreestanding
+ // is not specified.
+ if (Triple.isOSDarwin() && !IsHosted)
+ StackProtectorLevel = 0;
}
if (StackProtectorLevel) {
CmdArgs.push_back("-stack-protector");
Modified: cfe/trunk/test/Driver/stack-protector.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/stack-protector.c?rev=289005&r1=289004&r2=289005&view=diff
==============================================================================
--- cfe/trunk/test/Driver/stack-protector.c (original)
+++ cfe/trunk/test/Driver/stack-protector.c Wed Dec 7 18:22:06 2016
@@ -47,3 +47,16 @@
// SSP_MACOSX_KERNEL-NOT: "-stack-protector"
// RUN: %clang -target x86_64-apple-darwin10 -mmacosx-version-min=10.6 -### %s 2>&1 | FileCheck %s -check-prefix=SSP_MACOSX_10_6_KERNEL
// SSP_MACOSX_10_6_KERNEL: "-stack-protector" "1"
+
+// Test default stack protector values for Darwin platforms with -ffreestanding
+
+// RUN: %clang -ffreestanding -target armv7k-apple-watchos2.0 -### %s 2>&1 | FileCheck %s -check-prefix=SSP_FREE_WATCHOS
+// SSP_FREE_WATCHOS-NOT: "-stack-protector"
+// RUN: %clang -ffreestanding -target arm64-apple-ios8.0.0 -### %s 2>&1 | FileCheck %s -check-prefix=SSP_FREE_IOS
+// SSP_FREE_IOS-NOT: "-stack-protector"
+// RUN: %clang -ffreestanding -target x86_64-apple-darwin10 -mmacosx-version-min=10.6 -### %s 2>&1 | FileCheck %s -check-prefix=SSP_FREE_MACOSX
+// SSP_FREE_MACOSX-NOT: "-stack-protector"
+// RUN: %clang -ffreestanding -target x86_64-apple-darwin10 -mmacosx-version-min=10.5 -### %s 2>&1 | FileCheck %s -check-prefix=SSP_FREE_MACOSX_10_5
+// SSP_FREE_MACOSX_10_5-NOT: "-stack-protector"
+// RUN: %clang -ffreestanding -target x86_64-apple-darwin10 -mmacosx-version-min=10.6 -### %s 2>&1 | FileCheck %s -check-prefix=SSP_FREE_MACOSX_10_6_KERNEL
+// SSP_FREE_MACOSX_10_6_KERNEL-NOT: "-stack-protector"
More information about the cfe-commits
mailing list