From 56ee0e6d36e35bbd4a1cda777359dcb7eaadb232 Mon Sep 17 00:00:00 2001 From: Andrew Hsieh Date: Wed, 31 Oct 2012 21:02:46 -0700 Subject: 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: https://android-review.googlesource.com/#/c/45416 (*1) https://android-review.googlesource.com/#/c/45784 Change-Id: Iedf5b7ae5148572db2e35f0add93bc3d13511304 --- gcc-4.7/gcc/config/i386/i386-opts.h | 5 +++++ gcc-4.7/gcc/config/i386/i386.c | 6 ++++++ gcc-4.7/gcc/config/i386/i386.md | 8 ++++---- gcc-4.7/gcc/config/i386/i386.opt | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) (limited to 'gcc-4.7') diff --git a/gcc-4.7/gcc/config/i386/i386-opts.h b/gcc-4.7/gcc/config/i386/i386-opts.h index 3cc2253c3..8904491de 100644 --- a/gcc-4.7/gcc/config/i386/i386-opts.h +++ b/gcc-4.7/gcc/config/i386/i386-opts.h @@ -82,4 +82,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.7/gcc/config/i386/i386.c b/gcc-4.7/gcc/config/i386/i386.c index adf911c64..c21cb81c1 100644 --- a/gcc-4.7/gcc/config/i386/i386.c +++ b/gcc-4.7/gcc/config/i386/i386.c @@ -3890,6 +3890,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; + } } /* Return TRUE if VAL is passed in register with 256bit AVX modes. */ diff --git a/gcc-4.7/gcc/config/i386/i386.md b/gcc-4.7/gcc/config/i386/i386.md index d8deee8da..e006cc8fb 100644 --- a/gcc-4.7/gcc/config/i386/i386.md +++ b/gcc-4.7/gcc/config/i386/i386.md @@ -17722,7 +17722,7 @@ (define_expand "stack_protect_set" [(match_operand 0 "memory_operand" "") (match_operand 1 "memory_operand" "")] - "" + "ix86_stack_protector_guard == SSP_TLS" { rtx (*insn)(rtx, rtx); @@ -17747,7 +17747,7 @@ UNSPEC_SP_SET)) (set (match_scratch:PTR 2 "=&r") (const_int 0)) (clobber (reg:CC FLAGS_REG))] - "" + "ix86_stack_protector_guard == SSP_TLS" "mov{}\t{%1, %2|%2, %1}\;mov{}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2" [(set_attr "type" "multi")]) @@ -17765,7 +17765,7 @@ [(match_operand 0 "memory_operand" "") (match_operand 1 "memory_operand" "") (match_operand 2 "" "")] - "" + "ix86_stack_protector_guard == SSP_TLS" { rtx flags = gen_rtx_REG (CCZmode, FLAGS_REG); @@ -17795,7 +17795,7 @@ (match_operand:PTR 2 "memory_operand" "m")] UNSPEC_SP_TEST)) (clobber (match_scratch:PTR 3 "=&r"))] - "" + "ix86_stack_protector_guard == SSP_TLS" "mov{}\t{%1, %3|%3, %1}\;xor{}\t{%2, %3|%3, %2}" [(set_attr "type" "multi")]) diff --git a/gcc-4.7/gcc/config/i386/i386.opt b/gcc-4.7/gcc/config/i386/i386.opt index 4008fd0fe..492490f14 100644 --- a/gcc-4.7/gcc/config/i386/i386.opt +++ b/gcc-4.7/gcc/config/i386/i386.opt @@ -581,3 +581,18 @@ Split 32-byte AVX unaligned load mavx256-split-unaligned-store Target Report Mask(AVX256_SPLIT_UNALIGNED_STORE) Save Split 32-byte AVX unaligned store + +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) + -- cgit v1.2.3