Hi!

As discussed in the PR, similarly to dwarf2out.c's reference_to_unused
and late removal of unreferenced symbols, this patch will make sure we don't
reference static symbols that were optimized away.
So far all dbxout was using was give up if DECL_RTL wasn't set, but DECL_RTL
can be set e.g. for const hashing.

Bootstrapped/regtested on x86_64-linux, i686-linux, additionally i686-linux
with hacked up DBX_DEBUG as PREFERRED_DEBUGGING_TYPE.  The new return NULL
hasn't been hit during the last bootstrap/regtest but on the new testcase,
so I think it doesn't really degrade -gstabs debug info quality (if we
can speak about debug info quality in case of stabs at all).

Ok for trunk/4.6?

2011-05-20  Jakub Jelinek  <ja...@redhat.com>

        PR debug/49032
        * dbxout.c: Include cgraph.h.
        (dbxout_expand_expr): If a VAR_DECL is TREE_STATIC, not written
        and without value expr, return NULL if no varpool node exists for
        it or if it is not needed.
        * Makefile.in (dbxout.o): Depend on $(CGRAPH_H).

        * gcc.dg/debug/pr49032.c: New test.

--- gcc/dbxout.c.jj     2011-04-06 16:33:29.000000000 +0200
+++ gcc/dbxout.c        2011-05-20 11:51:23.000000000 +0200
@@ -91,6 +91,7 @@ along with GCC; see the file COPYING3.  
 #include "langhooks.h"
 #include "obstack.h"
 #include "expr.h"
+#include "cgraph.h"
 
 #ifdef XCOFF_DEBUGGING_INFO
 #include "xcoffout.h"
@@ -2470,6 +2471,20 @@ dbxout_expand_expr (tree expr)
         disable debug info for these variables.  */
       if (!targetm.have_tls && DECL_THREAD_LOCAL_P (expr))
        return NULL;
+      if (TREE_STATIC (expr)
+         && !TREE_ASM_WRITTEN (expr)
+         && !DECL_HAS_VALUE_EXPR_P (expr)
+         && !TREE_PUBLIC (expr)
+         && DECL_RTL_SET_P (expr)
+         && MEM_P (DECL_RTL (expr)))
+       {
+         /* If this is a var that might not be actually output,
+            return NULL, otherwise stabs might reference an undefined
+            symbol.  */
+         struct varpool_node *node = varpool_get_node (expr);
+         if (!node || !node->needed)
+           return NULL;
+       }
       /* FALLTHRU */
 
     case PARM_DECL:
--- gcc/Makefile.in.jj  2011-05-11 19:39:04.000000000 +0200
+++ gcc/Makefile.in     2011-05-19 18:55:09.000000000 +0200
@@ -2956,7 +2956,8 @@ optabs.o : optabs.c $(CONFIG_H) $(SYSTEM
 dbxout.o : dbxout.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
    $(RTL_H) $(FLAGS_H) $(REGS_H) debug.h $(TM_P_H) $(TARGET_H) $(FUNCTION_H) \
    langhooks.h insn-config.h reload.h $(GSTAB_H) xcoffout.h output.h dbxout.h \
-   toplev.h $(DIAGNOSTIC_CORE_H) $(GGC_H) $(OBSTACK_H) $(EXPR_H) gt-dbxout.h
+   toplev.h $(DIAGNOSTIC_CORE_H) $(GGC_H) $(OBSTACK_H) $(EXPR_H) $(CGRAPH_H) \
+   gt-dbxout.h
 debug.o : debug.c debug.h $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H)
 sdbout.o : sdbout.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) debug.h \
    $(TREE_H) $(GGC_H) $(RTL_H) $(REGS_H) $(FLAGS_H) insn-config.h \
--- gcc/testsuite/gcc.dg/debug/pr49032.c.jj     2011-05-19 18:53:02.000000000 
+0200
+++ gcc/testsuite/gcc.dg/debug/pr49032.c        2011-05-19 18:52:41.000000000 
+0200
@@ -0,0 +1,11 @@
+/* PR debug/49032 */
+/* { dg-do link } */
+
+static int s = 42;
+
+int
+main ()
+{
+  int *l[18] = { &s, &s, &s, &s, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+  return 0;
+}

        Jakub

Reply via email to