[PATCH, Android] Runtime stack protector enabling for Android target

Maxim Kuvyrkov maxim@codesourcery.com
Mon Jul 9 22:40:00 GMT 2012


On 10/07/2012, at 8:51 AM, Igor Zamyatin wrote:

> Let's try with this patch then. Is it ok for trunk after all
> appropriate testing is done?

Sorry for the late reply, I've been down with a virus last week.

Uros,

Would you please approve this patch for i386 provided my review below?

> 
> ChangeLog:
> 
> 2012-07-09 Sergey Melnikov <sergey.melnikov@intel.com>
> 
>         * config/i386/i386.md (stack_protect_set): Disable the pattern
>         for Android since Android libc (bionic) does not provide random
>         value for stack protection guard at gs:0x14. Guard value
>         will be provided from external symbol (default implementation).
>         (stack_protect_set_<mode>): Likewise.
>         (stack_protect_test): Likewise.
>         (stack_protect_test_<mode>): Likewise.
> 
> 
> diff --git a/gcc-4.6/gcc/config/i386/i386.md b/gcc-4.6/gcc/config/i386/i386.md
> index b1d7e5e..c4dd6e3 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" "")]
> -  ""
> +  "!(flag_android && OPTION_BIONIC)"

This should be just !OPTION_BIONIC, no flag_android.  Same applies below.

OK with that change.

-mandroid, which sets flag_android, tells the compiler to use compilation mode suitable for Android, like don't use C++ exceptions.  The particular implementation of stack protector, on the other hand, is a feature related to the C library.

> {
>   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))]
> -  ""
> +  "!(flag_android && OPTION_BIONIC)"
>   "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 "" "")]
> -  ""
> +  "!(flag_android && OPTION_BIONIC)"
> {
>   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"))]
> -  ""
> +  "!(flag_android && OPTION_BIONIC)"
>   "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%2, %3|%3, %2}"
>   [(set_attr "type" "multi")])

Thanks,

--
Maxim Kuvyrkov
CodeSourcery / Mentor Graphics





More information about the Gcc-patches mailing list