This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] for PR 28281: enable -fstack-protector for the x86_64 linux kernel



2006-07-06 Arjan van de Ven <arjan@linux.intel.com>

  	* config/i386/i386.md (stack_tls_protect_set_di,
  	stack_tls_protect_test_di): Use %gs rather than %fs for
  	-mcmodel=kernel.

* gcc.target/i386/stack-prot-kernel.c: New test.

This is OK if you add a comment to the two insns you are modifying in i386.md which explains why the kernel uses a different segment register (one insn can simply refer to the other insns if you like). E.g., /* The kernel uses a different segment register for performance reasons: a system call will not have to trash the userspace segment register, which would be expensive. */

Approved with that change.

patch with added comments below


2006-07-06 Arjan van de Ven <arjan@linux.intel.com>

     * config/i386/i386.md (stack_tls_protect_set_di,
     stack_tls_protect_test_di): Use %gs rather than %fs for
     -mcmodel=kernel.

* gcc.target/i386/stack-prot-kernel.c: New test.


Index: gcc/testsuite/gcc.target/i386/stack-prot-kernel.c =================================================================== --- gcc/testsuite/gcc.target/i386/stack-prot-kernel.c (revision 0) +++ gcc/testsuite/gcc.target/i386/stack-prot-kernel.c (revision 0) @@ -0,0 +1,12 @@ +/* { dg-do compile { target lp64 } } */ +/* { dg-options "-O2 -fstack-protector-all -mcmodel=kernel" } */ + +void test1 (int x) +{ + char p[40]; + int i; + for (i=0; i<40; i++) + p[i] = x; +} + +/* { dg-final { scan-assembler-not "%fs" } } */ Index: gcc/config/i386/i386.md =================================================================== --- gcc/config/i386/i386.md (revision 115220) +++ gcc/config/i386/i386.md (working copy) @@ -20393,7 +20393,14 @@ (set (match_scratch:DI 2 "=&r") (const_int 0)) (clobber (reg:CC FLAGS_REG))] "TARGET_64BIT" - "mov{q}\t{%%fs:%P1, %2|%2, QWORD PTR %%fs:%P1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2" + { + /* The kernel uses a different segment register for performance reasons; a system call + would not have to trash the userspace segment register, which would be expensive */ + if (ix86_cmodel != CM_KERNEL) + return "mov{q}\t{%%fs:%P1, %2|%2, QWORD PTR %%fs:%P1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"; + else + return "mov{q}\t{%%gs:%P1, %2|%2, QWORD PTR %%gs:%P1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"; + } [(set_attr "type" "multi")])

 (define_expand "stack_protect_test"
@@ -20461,7 +20468,14 @@
 		    UNSPEC_SP_TLS_TEST))
    (clobber (match_scratch:DI 3 "=r"))]
   "TARGET_64BIT"
-  "mov{q}\t{%1, %3|%3, %1}\;xor{q}\t{%%fs:%P2, %3|%3, QWORD PTR %%fs:%P2}"
+  {
+     /* The kernel uses a different segment register for performance reasons; a system call
+        would not have to trash the userspace segment register, which would be expensive */
+     if (ix86_cmodel != CM_KERNEL)
+        return "mov{q}\t{%1, %3|%3, %1}\;xor{q}\t{%%fs:%P2, %3|%3, QWORD PTR %%fs:%P2}";
+     else
+        return "mov{q}\t{%1, %3|%3, %1}\;xor{q}\t{%%gs:%P2, %3|%3, QWORD PTR %%gs:%P2}";
+  }
   [(set_attr "type" "multi")])

(include "sse.md")


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]