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]

[patch] Take 3: HEAD patch to add -fstack-protector support for x86-64 kernels


Hi,

The patch below (bootstrapped) adds support for (linux) kernel-side use
of -fstack-protector. The kernel uses a different segment register (gs
instead of fs) for the local storage, so for this to work gcc needs to
emit gs: relative code for -fstack-protector for the -mcmodel=kernel
code. I've also attached a testcase for this patch to go with this. The
patch is against the SVN tree from about 2 hours ago.
Please consider applying.

With a lot of thanks to Paolo Bonzini for suggesting a much simpler solution

2006-03-21  Arjan van de Ven <arjan@linux.intel.com>
	* config/i386/i386.md: add conditonal for kernel side
	stack-protector

--- gcc/gcc/config/i386/i386.md.org	2006-03-21 10:19:23.000000000 +0100
+++ gcc/gcc/config/i386/i386.md	2006-03-21 13:50:21.000000000 +0100
@@ -20402,7 +20402,12 @@
    (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"
+  {  
+     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"
@@ -20470,7 +20475,12 @@
 		    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}"
+  {
+     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")

/* { dg-do compile { target x86_64-*-linux* } } */
/* { 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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]