diff mbox

[Android] Runtime stack protector enabling for Android target

Message ID CAKdSQZmRs6eBguf=nfKikn4mZPGs4EppbbvfjRNd1GCyM4m8rg@mail.gmail.com
State New
Headers show

Commit Message

Igor Zamyatin July 6, 2012, 7:49 a.m. UTC
Hi!

For runtime stack protector enabling on x86 for Android we have to
disable current glibc-based implementation and turn on default one
since bionic doesn't use value from gs:0x14.

Tested in android environment(x86_64-*-linux-android), also
bootstrapped and regtested on x86_64-unknown-linux-gnu and i686-linux.
Ok for trunk?

Thanks,
Igor


ChangeLog:

2012-07-05 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.


@@ -17997,7 +17997,7 @@
   [(match_operand 0 "memory_operand" "")
    (match_operand 1 "memory_operand" "")
    (match_operand 2 "" "")]
-  ""
+  "!ANDROID_DEFAULT"
 {
   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"))]
-  ""
+  "!ANDROID_DEFAULT"
   "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%2, %3|%3, %2}"
   [(set_attr "type" "multi")])

Comments

Andrew Pinski July 6, 2012, 8:13 a.m. UTC | #1
On Fri, Jul 6, 2012 at 12:49 AM, Igor Zamyatin <izamyatin@gmail.com> wrote:
> Hi!
>
> For runtime stack protector enabling on x86 for Android we have to
> disable current glibc-based implementation and turn on default one
> since bionic doesn't use value from gs:0x14.
>
> Tested in android environment(x86_64-*-linux-android), also
> bootstrapped and regtested on x86_64-unknown-linux-gnu and i686-linux.
> Ok for trunk?



I think you want flag_android and not ANDROID_DEFAULT since you could
use -mno-android .

Thanks,
Andrew



>
> Thanks,
> Igor
>
>
> ChangeLog:
>
> 2012-07-05 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..fe0009d 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" "")]
> -  ""
> +  "!ANDROID_DEFAULT"
>  {
>    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))]
> -  ""
> +  "!ANDROID_DEFAULT"
>    "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 "" "")]
> -  ""
> +  "!ANDROID_DEFAULT"
>  {
>    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"))]
> -  ""
> +  "!ANDROID_DEFAULT"
>    "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%2, %3|%3, %2}"
>    [(set_attr "type" "multi")])
Igor Zamyatin July 6, 2012, 12:54 p.m. UTC | #2
Right, flag_android looks better, thanks.
Probably it's even better to check also bionic (OPTION_BIONIC)

On Fri, Jul 6, 2012 at 12:13 PM, Andrew Pinski <pinskia@gmail.com> wrote:
> On Fri, Jul 6, 2012 at 12:49 AM, Igor Zamyatin <izamyatin@gmail.com> wrote:
>> Hi!
>>
>> For runtime stack protector enabling on x86 for Android we have to
>> disable current glibc-based implementation and turn on default one
>> since bionic doesn't use value from gs:0x14.
>>
>> Tested in android environment(x86_64-*-linux-android), also
>> bootstrapped and regtested on x86_64-unknown-linux-gnu and i686-linux.
>> Ok for trunk?
>
>
>
> I think you want flag_android and not ANDROID_DEFAULT since you could
> use -mno-android .
>
> Thanks,
> Andrew
>
>
>
>>
>> Thanks,
>> Igor
>>
>>
>> ChangeLog:
>>
>> 2012-07-05 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..fe0009d 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" "")]
>> -  ""
>> +  "!ANDROID_DEFAULT"
>>  {
>>    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))]
>> -  ""
>> +  "!ANDROID_DEFAULT"
>>    "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 "" "")]
>> -  ""
>> +  "!ANDROID_DEFAULT"
>>  {
>>    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"))]
>> -  ""
>> +  "!ANDROID_DEFAULT"
>>    "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%2, %3|%3, %2}"
>>    [(set_attr "type" "multi")])
diff mbox

Patch

diff --git a/gcc-4.6/gcc/config/i386/i386.md b/gcc-4.6/gcc/config/i386/i386.md
index b1d7e5e..fe0009d 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" "")]
-  ""
+  "!ANDROID_DEFAULT"
 {
   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))]
-  ""
+  "!ANDROID_DEFAULT"
   "mov{<imodesuffix>}\t{%1, %2|%2, %1}\;mov{<imodesuffix>}\t{%2,
%0|%0, %2}\;xor{l}\t%k2, %k2"
   [(set_attr "type" "multi")])