aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Hsieh <andrewhsieh@google.com>2013-04-02 19:26:45 +0800
committerAndrew Hsieh <andrewhsieh@google.com>2013-04-02 20:35:08 +0800
commit6ed152e45f2815670b2b7323ee067c36fd997339 (patch)
treeae64b46942039051517a705ed2ba5205dd5a9cf6
parent9fc377fd2c2dce50298e33e578d7065e285171e0 (diff)
downloadtoolchain_gcc-6ed152e45f2815670b2b7323ee067c36fd997339.tar.gz
toolchain_gcc-6ed152e45f2815670b2b7323ee067c36fd997339.tar.bz2
toolchain_gcc-6ed152e45f2815670b2b7323ee067c36fd997339.zip
[4.8] Add -mstack-protector-guard= to x86 compilers
To choose between "global" (default) and "tls" (new) for -fstack-protector, -fstack-protector-all, and -fstack-protector-strong (GCC 4.6+). Note that this alone doesn't enable any -fstack-protector* For NDK: The default "global" generates code backward compatible with older bionic For AOSP: build may add "-mstack-protector-guard=tls" to build platform code with new bionic (*1) Related CL: ad88a0863110798cef5169dcf917e18b967a7cf6 (*1) e804643b6dfcfb5842dea4b714601c6dd89f4944 Change-Id: I341c9022530b37ca289d94e1174dfa86a8eaa1bf
-rw-r--r--gcc-4.8/gcc/config/i386/i386-opts.h5
-rw-r--r--gcc-4.8/gcc/config/i386/i386.c6
-rw-r--r--gcc-4.8/gcc/config/i386/i386.md8
-rw-r--r--gcc-4.8/gcc/config/i386/i386.opt14
4 files changed, 29 insertions, 4 deletions
diff --git a/gcc-4.8/gcc/config/i386/i386-opts.h b/gcc-4.8/gcc/config/i386/i386-opts.h
index 11c08457d..3f3ce13be 100644
--- a/gcc-4.8/gcc/config/i386/i386-opts.h
+++ b/gcc-4.8/gcc/config/i386/i386-opts.h
@@ -85,4 +85,9 @@ enum ix86_veclibabi {
ix86_veclibabi_type_acml
};
+enum stack_protector_guard {
+ SSP_TLS, /* per-thread canary at %gs:20 */
+ SSP_GLOBAL, /* global canary */
+};
+
#endif
diff --git a/gcc-4.8/gcc/config/i386/i386.c b/gcc-4.8/gcc/config/i386/i386.c
index b835c5da2..a8212f54b 100644
--- a/gcc-4.8/gcc/config/i386/i386.c
+++ b/gcc-4.8/gcc/config/i386/i386.c
@@ -3922,6 +3922,12 @@ ix86_option_override_internal (bool main_args_p)
if (main_args_p)
target_option_default_node = target_option_current_node
= build_target_option_node ();
+
+ /* Handle stack protector */
+ if (!global_options_set.x_ix86_stack_protector_guard)
+ {
+ ix86_stack_protector_guard = TARGET_HAS_BIONIC? SSP_GLOBAL : SSP_TLS;
+ }
}
/* Implement the TARGET_OPTION_OVERRIDE hook. */
diff --git a/gcc-4.8/gcc/config/i386/i386.md b/gcc-4.8/gcc/config/i386/i386.md
index 24d1012d5..247e6f9ec 100644
--- a/gcc-4.8/gcc/config/i386/i386.md
+++ b/gcc-4.8/gcc/config/i386/i386.md
@@ -17599,7 +17599,7 @@
(define_expand "stack_protect_set"
[(match_operand 0 "memory_operand")
(match_operand 1 "memory_operand")]
- "!TARGET_HAS_BIONIC"
+ "ix86_stack_protector_guard == SSP_TLS"
{
rtx (*insn)(rtx, rtx);
@@ -17624,7 +17624,7 @@
UNSPEC_SP_SET))
(set (match_scratch:PTR 2 "=&r") (const_int 0))
(clobber (reg:CC FLAGS_REG))]
- "!TARGET_HAS_BIONIC"
+ "ix86_stack_protector_guard == SSP_TLS"
"mov{<imodesuffix>}\t{%1, %2|%2, %1}\;mov{<imodesuffix>}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
[(set_attr "type" "multi")])
@@ -17642,7 +17642,7 @@
[(match_operand 0 "memory_operand")
(match_operand 1 "memory_operand")
(match_operand 2)]
- "!TARGET_HAS_BIONIC"
+ "ix86_stack_protector_guard == SSP_TLS"
{
rtx flags = gen_rtx_REG (CCZmode, FLAGS_REG);
@@ -17672,7 +17672,7 @@
(match_operand:PTR 2 "memory_operand" "m")]
UNSPEC_SP_TEST))
(clobber (match_scratch:PTR 3 "=&r"))]
- "!TARGET_HAS_BIONIC"
+ "ix86_stack_protector_guard == SSP_TLS"
"mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%2, %3|%3, %2}"
[(set_attr "type" "multi")])
diff --git a/gcc-4.8/gcc/config/i386/i386.opt b/gcc-4.8/gcc/config/i386/i386.opt
index 084a24863..f5ad69e26 100644
--- a/gcc-4.8/gcc/config/i386/i386.opt
+++ b/gcc-4.8/gcc/config/i386/i386.opt
@@ -626,3 +626,17 @@ Split 32-byte AVX unaligned store
mrtm
Target Report Mask(ISA_RTM) Var(ix86_isa_flags) Save
Support RTM built-in functions and code generation
+
+mstack-protector-guard=
+Target RejectNegative Joined Enum(stack_protector_guard) Var(ix86_stack_protector_guard) Init(SSP_TLS)
+Use given stack-protector guard
+
+Enum
+Name(stack_protector_guard) Type(enum stack_protector_guard)
+Known stack protector guard (for use with the -mstack-protector-guard= option):
+
+EnumValue
+Enum(stack_protector_guard) String(tls) Value(SSP_TLS)
+
+EnumValue
+Enum(stack_protector_guard) String(global) Value(SSP_GLOBAL)