In testing for wide-int, we discovered that someone seems to have blown pch.  
The problem is that the optabs field is not a string.  It's size is not 
determined by strlen.  strlen are the semantics gty attaches to unsigned char * 
data.  By defeating the type of optabs to being any other type, then the length 
is determined by the ggc subsystem which just knows the length of the data (2K 
on my system).

I don't really like the type lying going on.  I'd prefer if a tree-core person 
would get honest with the types.

Another style of fix would be to decide that atomic in this case means 
something else, then, we'd have to have a gty person implement the new 
semantics.  Until that is done, this problem is so bad, that the below should 
go in until someone can fix gty, if someone doesn't want to be honest with the 
type system.

This bug comes across as a random memory smasher and is incredibly annoying to 
track down.  There is non-determinism in the process and will causes 
non-deterministic memory crashes, but, only on pch use.  To track down why, you 
have to trace back through the pch writing process and realize the data in 
memory is completely valid, is it only the meta information about that data 
that pch uses from the GTY world that causes any problem.

Ok?

Index: optabs.c
===================================================================
--- optabs.c    (revision 206086)
+++ optabs.c    (working copy)
@@ -6242,7 +6242,7 @@
 
   /* If the optabs changed, record it.  */
   if (memcmp (tmp_optabs, this_target_optabs, sizeof (struct target_optabs)))
-    TREE_OPTIMIZATION_OPTABS (optnode) = (unsigned char *) tmp_optabs;
+    TREE_OPTIMIZATION_OPTABS (optnode) = (struct target_optabs_S *) tmp_optabs;
   else
     {
       TREE_OPTIMIZATION_OPTABS (optnode) = NULL;
Index: tree-core.h
===================================================================
--- tree-core.h (revision 206086)
+++ tree-core.h (working copy)
@@ -1559,6 +1559,9 @@
   struct tree_statement_list_node *tail;
 };
 
+struct GTY(()) target_optabs_S {
+  unsigned char e[1];
+};
 
 /* Optimization options used by a function.  */
 
@@ -1570,7 +1573,7 @@
 
   /* Target optabs for this set of optimization options.  This is of
      type `struct target_optabs *'.  */
-  unsigned char *GTY ((atomic)) optabs;
+  struct target_optabs_S *GTY((atomic)) optabs;
 
   /* The value of this_target_optabs against which the optabs above were
      generated.  */

Reply via email to