[PATCH] Allow for changing the stack protector level for -fstack-protector
Brad Smith
brad at comstyle.com
Thu May 22 13:17:04 PDT 2014
Looking at allowing for the Clang Driver to allow overriding the stack protector level
for -fstack-protector to match OpenBSD base OS compiler and ports/packages compilers.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
-------------- next part --------------
Index: include/clang/Driver/ToolChain.h
===================================================================
--- include/clang/Driver/ToolChain.h (revision 209462)
+++ include/clang/Driver/ToolChain.h (working copy)
@@ -206,6 +206,12 @@
return 0;
}
+ /// GetStackProtectorLevel - Get the stack protector level for this tool
+ /// chain (1=on, 2=strong, 3=all).
+ virtual unsigned GetStackProtectorLevel(bool KernelOrKext) const {
+ return 1;
+ }
+
/// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
virtual RuntimeLibType GetDefaultRuntimeLibType() const {
return ToolChain::RLT_Libgcc;
Index: lib/Driver/ToolChains.h
===================================================================
--- lib/Driver/ToolChains.h (revision 209462)
+++ lib/Driver/ToolChains.h (working copy)
@@ -537,6 +537,10 @@
return 2;
}
+ unsigned GetStackProtectorLevel(bool KernelOrKext) const override {
+ return 2;
+ }
+
protected:
Tool *buildAssembler() const override;
Tool *buildLinker() const override;
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp (revision 209462)
+++ lib/Driver/Tools.cpp (working copy)
@@ -3378,9 +3378,10 @@
options::OPT_fstack_protector_all,
options::OPT_fstack_protector_strong,
options::OPT_fstack_protector)) {
- if (A->getOption().matches(options::OPT_fstack_protector))
- StackProtectorLevel = LangOptions::SSPOn;
- else if (A->getOption().matches(options::OPT_fstack_protector_strong))
+ if (A->getOption().matches(options::OPT_fstack_protector)) {
+ StackProtectorLevel =
+ getToolChain().GetStackProtectorLevel(KernelOrKext);
+ } else if (A->getOption().matches(options::OPT_fstack_protector_strong))
StackProtectorLevel = LangOptions::SSPStrong;
else if (A->getOption().matches(options::OPT_fstack_protector_all))
StackProtectorLevel = LangOptions::SSPReq;
Index: test/Driver/stack-protector.c
===================================================================
--- test/Driver/stack-protector.c (revision 209462)
+++ test/Driver/stack-protector.c (working copy)
@@ -13,6 +13,9 @@
// RUN: %clang -target i386-pc-openbsd -### %s 2>&1 | FileCheck %s -check-prefix=OPENBSD
// OPENBSD: "-stack-protector" "2"
+// RUN: %clang -target i386-pc-openbsd -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=OPENBSD_SPS
+// OPENBSD_SPS: "-stack-protector" "2"
+
// RUN: %clang -target i386-pc-openbsd -fno-stack-protector -### %s 2>&1 | FileCheck %s -check-prefix=OPENBSD_OFF
// OPENBSD_OFF-NOT: "-stack-protector"
More information about the cfe-commits
mailing list