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] Fix i386/x86_64 legitimize_pic_address (PR target/29198)


Hi!

The middle-end can throw arbitrary RTLs at legitimize_address, and we
were checking only for the two most common occurences of TLS symbols in them
(when x is a TLS SYMBOL_REF or CONST PLUS SYMBOL_REF + offset).
While in most of legitimize_address that doesn't matter, all that happens
if a TLS SYMBOL_REF is hidden somewhere deeper is that the possibly slightly
reorganized RTL returned will not be recognized as valid address and split,
legitimize_pic_address seems to surround even TLS symbols in its UNSPECs
and at that point we loose (as the GOT/GOTOFF/etc. UNSPECs are assumed valid by
the memory address validation, no matter what is inside).
The following patch makes sure legitimize_pic_address won't wrap TLS
SYMBOL_REFs inside of its UNSPECs.  I have checked all uses of
local_symbolic_operand (except two they are all in legitimize_pic_address
btw) and in none of the uses we really want to accept a TLS SYMBOL_REF.

Ok for trunk/4.1?

2006-09-29  Jakub Jelinek  <jakub@redhat.com>

	PR target/29198
	* config/i386/i386.c (legitimize_pic_address): Reject TLS symbols.
	* config/i386/predicates.md (local_symbolic_operand): Likewise.

	* gcc.dg/tls/opt-12.c: New test.

--- gcc/config/i386/predicates.md.jj	2006-08-28 12:59:54.000000000 +0200
+++ gcc/config/i386/predicates.md	2006-09-29 13:23:23.000000000 +0200
@@ -447,6 +447,9 @@
   if (GET_CODE (op) != SYMBOL_REF)
     return 0;
 
+  if (SYMBOL_REF_TLS_MODEL (op) != 0)
+    return 0;
+
   if (SYMBOL_REF_LOCAL_P (op))
     return 1;
 
--- gcc/config/i386/i386.c.jj	2006-09-29 13:07:26.000000000 +0200
+++ gcc/config/i386/i386.c	2006-09-29 13:24:31.000000000 +0200
@@ -6623,7 +6623,7 @@ legitimize_pic_address (rtx orig, rtx re
 	  new = reg;
 	}
     }
-  else if (GET_CODE (addr) == SYMBOL_REF)
+  else if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
     {
       if (TARGET_64BIT)
 	{
--- gcc/testsuite/gcc.dg/tls/opt-12.c.jj	2006-09-29 13:44:56.000000000 +0200
+++ gcc/testsuite/gcc.dg/tls/opt-12.c	2006-09-29 13:47:11.000000000 +0200
@@ -0,0 +1,50 @@
+/* PR target/29198 */
+/* { dg-do run } */
+/* { dg-options "-O2 -fpic" } */
+/* { dg-require-effective-target tls_runtime } */
+/* { dg-require-effective-target fpic } */
+
+extern void abort (void);
+
+int f2 (int, int, int, int);
+struct s { char b[4]; };
+__thread struct s thra[2];
+
+void
+__attribute__((noinline))
+f1 (int a1, int a2)
+{
+  int i, j;
+  for (i = 0; i < 4; i++)
+    {
+      int tot = 0;
+      for (j = 0; j < 4; j++)
+	tot += f2 (a1, a2, i, j);
+      *(&thra[0].b[0] + i) = tot;
+    }
+}
+
+int
+__attribute__((noinline))
+f2 (int a, int b, int c, int d)
+{
+  return a + b + c + d;
+}
+
+int
+main (void)
+{
+  f1 (0, 0);
+  if (thra[0].b[0] != 6
+      || thra[0].b[1] != 10
+      || thra[0].b[2] != 14
+      || thra[0].b[3] != 18)
+    abort ();
+  f1 (2, 3);
+  if (thra[0].b[0] != 26
+      || thra[0].b[1] != 30
+      || thra[0].b[2] != 34
+      || thra[0].b[3] != 38)
+    abort ();
+  return 0;
+}

	Jakub


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