re PR debug/86964 (Too many debug symbols included, especially for extern globals)
authorJohan Karlsson <johan.karlsson@enea.com>
Mon, 25 Mar 2019 21:19:09 +0000 (21:19 +0000)
committerJeff Law <law@gcc.gnu.org>
Mon, 25 Mar 2019 21:19:09 +0000 (15:19 -0600)
PR debug/86964
* dwarf2out.c (premark_used_variables): New function.
(prune_unused_types_walk): Do not mark not premarked external
variables.
(prune_unused_types): Call premark_used_variables.

* gcc.dg/debug/dwarf2/pr86964.c: New testcase.

From-SVN: r269925

gcc/ChangeLog
gcc/dwarf2out.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/debug/dwarf2/pr86964.c [new file with mode: 0644]

index 2075480ca2beefc0ae7260ed2cf598c7beaf6e78..cdce539ac6f4234ccb80ac50244cf4d14995db07 100644 (file)
@@ -1,3 +1,11 @@
+2019-03-25  Johan Karlsson <johan.karlsson@enea.com>
+
+       PR debug/86964
+       * dwarf2out.c (premark_used_variables): New function.
+       (prune_unused_types_walk): Do not mark not premarked external
+       variables.
+       (prune_unused_types): Call premark_used_variables.
+
 2019-03-25  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR rtl-optimization/89676
index ae8bdee99818e7a59a4c961026897cb7d8c13918..b9a624e1ac7fadffbdd82c12d18a3785b6483e20 100644 (file)
@@ -22732,6 +22732,21 @@ premark_types_used_by_global_vars (void)
       ->traverse<void *, premark_types_used_by_global_vars_helper> (NULL);
 }
 
+/* Mark all variables used by the symtab as perennial.  */
+
+static void
+premark_used_variables (void)
+{
+  /* Mark DIEs in the symtab as used.  */
+  varpool_node *var;
+  FOR_EACH_VARIABLE (var)
+    {
+      dw_die_ref die = lookup_decl_die (var->decl);
+      if (die)
+       die->die_perennial_p = 1;
+    }
+}
+
 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
    for CA_LOC call arg loc node.  */
 
@@ -29394,6 +29409,19 @@ prune_unused_types_walk (dw_die_ref die)
 
       return;
 
+    case DW_TAG_variable:
+      if (flag_debug_only_used_symbols)
+       {
+         if (die->die_perennial_p)
+           break;
+
+         /* premark_used_variables marks external variables --- don't mark
+            them here.  */
+         if (get_AT (die, DW_AT_external))
+           return;
+       }
+      /* FALLTHROUGH */
+
     default:
       /* Mark everything else.  */
       break;
@@ -29520,6 +29548,10 @@ prune_unused_types (void)
   /* Mark types that are used in global variables.  */
   premark_types_used_by_global_vars ();
 
+  /* Mark variables used in the symtab.  */
+  if (flag_debug_only_used_symbols)
+    premark_used_variables ();
+
   /* Set the mark on nodes that are actually used.  */
   prune_unused_types_walk (comp_unit_die ());
   for (node = limbo_die_list; node; node = node->next)
index 00d17404dda3f9430d3130c1477bf1090d22f39c..7a0c4bc5edc35e1019ea55ca37f304ad3cb2351b 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-25  Johan Karlsson <johan.karlsson@enea.com>
+
+       PR debug/86964
+       * gcc.dg/debug/dwarf2/pr86964.c: New testcase.
+
 2019-03-25  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/84661
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr86964.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr86964.c
new file mode 100644 (file)
index 0000000..b52a06e
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -gdwarf -feliminate-unused-debug-symbols -dA" } */
+
+struct S { int i; };
+extern struct S x;
+int y;
+int main()
+{
+  return y;
+}
+
+/* We should elide the DIEs for x and S but not y.  */
+/* { dg-final { scan-assembler-times "DW_TAG_variable" 2 } } */
+/* { dg-final { scan-assembler-not "DW_TAG_structure_type" } } */