diff options
author | Andrew Hsieh <andrewhsieh@google.com> | 2012-10-31 21:02:46 -0700 |
---|---|---|
committer | Andrew Hsieh <andrewhsieh@google.com> | 2012-11-01 15:47:39 -0700 |
commit | 56ee0e6d36e35bbd4a1cda777359dcb7eaadb232 (patch) | |
tree | a9d6d744a3f8059b59d1b13d55779ea25ac8789d /gcc-4.6/gcc/config/i386 | |
parent | efb5994e8cb17f9b2347baff9d731af0338e5d5e (diff) | |
download | toolchain_gcc-56ee0e6d36e35bbd4a1cda777359dcb7eaadb232.tar.gz toolchain_gcc-56ee0e6d36e35bbd4a1cda777359dcb7eaadb232.tar.bz2 toolchain_gcc-56ee0e6d36e35bbd4a1cda777359dcb7eaadb232.zip |
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
Diffstat (limited to 'gcc-4.6/gcc/config/i386')
-rw-r--r-- | gcc-4.6/gcc/config/i386/i386.c | 19 | ||||
-rw-r--r-- | gcc-4.6/gcc/config/i386/i386.h | 6 | ||||
-rw-r--r-- | gcc-4.6/gcc/config/i386/i386.md | 8 | ||||
-rw-r--r-- | gcc-4.6/gcc/config/i386/i386.opt | 4 |
4 files changed, 33 insertions, 4 deletions
diff --git a/gcc-4.6/gcc/config/i386/i386.c b/gcc-4.6/gcc/config/i386/i386.c index b99d31150..6e7eb6183 100644 --- a/gcc-4.6/gcc/config/i386/i386.c +++ b/gcc-4.6/gcc/config/i386/i386.c @@ -2369,6 +2369,9 @@ static int ix86_regparm; static const char ix86_force_align_arg_pointer_string[] = "force_align_arg_pointer"; +/* Stack protector option. */ +enum stack_protector_guard ix86_stack_protector_guard; + static rtx (*ix86_gen_leave) (void); static rtx (*ix86_gen_add3) (rtx, rtx, rtx); static rtx (*ix86_gen_sub3) (rtx, rtx, rtx); @@ -4360,6 +4363,22 @@ ix86_option_override_internal (bool main_args_p) } free (token); } + + /* Handle stack protector */ + if (ix86_stack_protector_guard_string != 0) + { + if (!strcmp (ix86_stack_protector_guard_string, "tls")) + ix86_stack_protector_guard = SSP_TLS; + else if (!strcmp (ix86_stack_protector_guard_string, "global")) + ix86_stack_protector_guard = SSP_GLOBAL; + else + error ("bad value (%s) for %sstack-protector-guard=%s %s", + ix86_stack_protector_guard, prefix, suffix, sw); + } + else + { + 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.6/gcc/config/i386/i386.h b/gcc-4.6/gcc/config/i386/i386.h index 678071f27..d7714f7e4 100644 --- a/gcc-4.6/gcc/config/i386/i386.h +++ b/gcc-4.6/gcc/config/i386/i386.h @@ -2378,6 +2378,12 @@ extern void debug_dispatch_window (int); #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \ ((VALUE) = GET_MODE_BITSIZE (MODE), TARGET_BMI) +enum stack_protector_guard { + SSP_TLS, /* per-thread canary at %gs:20 */ + SSP_GLOBAL, /* global canary */ +}; + +extern enum stack_protector_guard ix86_stack_protector_guard; /* Local variables: diff --git a/gcc-4.6/gcc/config/i386/i386.md b/gcc-4.6/gcc/config/i386/i386.md index b1d7e5eba..dcc2a21b2 100644 --- a/gcc-4.6/gcc/config/i386/i386.md +++ b/gcc-4.6/gcc/config/i386/i386.md @@ -17955,7 +17955,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); @@ -17979,7 +17979,7 @@ (unspec:P [(match_operand:P 1 "memory_operand" "m")] UNSPEC_SP_SET)) (set (match_scratch:P 2 "=&r") (const_int 0)) (clobber (reg:CC FLAGS_REG))] - "" + "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")]) @@ -17997,7 +17997,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); @@ -18027,7 +18027,7 @@ (match_operand:P 2 "memory_operand" "m")] UNSPEC_SP_TEST)) (clobber (match_scratch:P 3 "=&r"))] - "" + "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.6/gcc/config/i386/i386.opt b/gcc-4.6/gcc/config/i386/i386.opt index 9deba3e01..3f0e3f718 100644 --- a/gcc-4.6/gcc/config/i386/i386.opt +++ b/gcc-4.6/gcc/config/i386/i386.opt @@ -435,3 +435,7 @@ 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 Var(ix86_stack_protector_guard_string) +Use given stack-protector guard |