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]

[lto][patch] Output references to variables used only in initializers of static variables


I missed the case of initializers of static variables in my previous
patch. The attached patch fixes it. For example, in

extern int flag_exceptions;
static int *foo = &flag_exceptions

we were not producing an undefined reference to flag_exceptions.

OK if bootstraps and tests are ok?

2010-01-08  Rafael Avila de Espindola  <espindola@google.com>

	* lto-streamer-out.c (output_unreferenced_globals): Output static
	variables.

2010-01-08  Rafael Avila de Espindola  <espindola@google.com>

	* gcc.dg/lto/20100108_0.c: New.


Cheers,
-- 
Rafael Ãvila de EspÃndola
diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
index b27bbdd..fe43dce 100644
--- a/gcc/lto-streamer-out.c
+++ b/gcc/lto-streamer-out.c
@@ -1973,12 +1973,15 @@ output_unreferenced_globals (cgraph_node_set set)
     {
       tree var = vnode->decl;
 
-      if (TREE_CODE (var) == VAR_DECL && TREE_PUBLIC (var))
+      if (TREE_CODE (var) == VAR_DECL)
         {
-          /* Outputting just the reference will not output the object itself
-             or references it might have.*/
+          /* Output the object in order to output references used in the
+             initialization. */
           lto_output_tree (ob, var, true);
-          lto_output_tree_ref (ob, var);
+
+          /* If it is public we also need a reference to the object itself. */
+          if (TREE_PUBLIC (var))
+            lto_output_tree_ref (ob, var);
         }
     }
 
diff --git a/gcc/testsuite/gcc.dg/lto/20100108_0.c b/gcc/testsuite/gcc.dg/lto/20100108_0.c
new file mode 100644
index 0000000..932c203
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/20100108_0.c
@@ -0,0 +1,8 @@
+/* { dg-lto-do assemble } */
+/* The problem with this testcase is that we were missing an undefined
+   reference to flag_exceptions. This can be tested with
+   GNUTARGET=plugin nm --plugin liblto_plugin.so 20100108_0.o
+   but we don't have support in the testsuite for doing it. */
+
+extern int flag_exceptions;
+static int *foo = &flag_exceptions;

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