* [PATCH] Remove unused extern variables from debug (PR debug/86964)
@ 2019-02-19 12:51 Johan Carlsson
2019-02-21 19:22 ` Jeff Law
2019-03-25 21:22 ` Jeff Law
0 siblings, 2 replies; 5+ messages in thread
From: Johan Carlsson @ 2019-02-19 12:51 UTC (permalink / raw)
To: gcc-patches; +Cc: rguenther
Adding so that the DIEs of unused external variables can be removed from the output when
using -feliminate-unused-debug-symbols.
Tested on x86_64-elf, aarch64-elf, powerpc-eabi, powerpc64-elf and arm-eabi.
2019-02-18 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.
* gcc.dg/debug/dwarf2/pr86964.c: New testcase.
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c (revision 268977)
+++ gcc/dwarf2out.c (working copy)
@@ -22658,6 +22658,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. */
@@ -29264,6 +29279,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;
@@ -29390,6 +29418,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: gcc/testsuite/gcc.dg/debug/dwarf2/pr86964.c
===================================================================
--- gcc/testsuite/gcc.dg/debug/dwarf2/pr86964.c (nonexistent)
+++ gcc/testsuite/gcc.dg/debug/dwarf2/pr86964.c (working copy)
@@ -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" } } */
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Remove unused extern variables from debug (PR debug/86964)
2019-02-19 12:51 [PATCH] Remove unused extern variables from debug (PR debug/86964) Johan Carlsson
@ 2019-02-21 19:22 ` Jeff Law
2019-02-21 19:50 ` Richard Biener
2019-03-25 21:22 ` Jeff Law
1 sibling, 1 reply; 5+ messages in thread
From: Jeff Law @ 2019-02-21 19:22 UTC (permalink / raw)
To: Johan Carlsson, gcc-patches; +Cc: rguenther
On 2/19/19 5:51 AM, Johan Carlsson wrote:
> Adding so that the DIEs of unused external variables can be removed from the output when
> using -feliminate-unused-debug-symbols.
>
> Tested on x86_64-elf, aarch64-elf, powerpc-eabi, powerpc64-elf and arm-eabi.
>
>
> 2019-02-18 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.
>
> * gcc.dg/debug/dwarf2/pr86964.c: New testcase.
Just a note, we're addressing regression bugfixes only at this point in
GCC development. I've queued this for gcc-10.
jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Remove unused extern variables from debug (PR debug/86964)
2019-02-21 19:22 ` Jeff Law
@ 2019-02-21 19:50 ` Richard Biener
2019-02-21 21:45 ` Jeff Law
0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2019-02-21 19:50 UTC (permalink / raw)
To: Jeff Law, Johan Carlsson, gcc-patches
On February 21, 2019 8:06:05 PM GMT+01:00, Jeff Law <law@redhat.com> wrote:
>On 2/19/19 5:51 AM, Johan Carlsson wrote:
>> Adding so that the DIEs of unused external variables can be removed
>from the output when
>> using -feliminate-unused-debug-symbols.
>>
>> Tested on x86_64-elf, aarch64-elf, powerpc-eabi, powerpc64-elf and
>arm-eabi.
>>
>>
>> 2019-02-18 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.
>>
>> * gcc.dg/debug/dwarf2/pr86964.c: New testcase.
>Just a note, we're addressing regression bugfixes only at this point in
>GCC development. I've queued this for gcc-10.
Note that technically this is a regression from pre-early-debug.
Richard.
>jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Remove unused extern variables from debug (PR debug/86964)
2019-02-21 19:50 ` Richard Biener
@ 2019-02-21 21:45 ` Jeff Law
0 siblings, 0 replies; 5+ messages in thread
From: Jeff Law @ 2019-02-21 21:45 UTC (permalink / raw)
To: Richard Biener, Johan Carlsson, gcc-patches
On 2/21/19 12:22 PM, Richard Biener wrote:
> On February 21, 2019 8:06:05 PM GMT+01:00, Jeff Law <law@redhat.com> wrote:
>> On 2/19/19 5:51 AM, Johan Carlsson wrote:
>>> Adding so that the DIEs of unused external variables can be removed
>>from the output when
>>> using -feliminate-unused-debug-symbols.
>>>
>>> Tested on x86_64-elf, aarch64-elf, powerpc-eabi, powerpc64-elf and
>> arm-eabi.
>>>
>>>
>>> 2019-02-18 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.
>>>
>>> * gcc.dg/debug/dwarf2/pr86964.c: New testcase.
>> Just a note, we're addressing regression bugfixes only at this point in
>> GCC development. I've queued this for gcc-10.
>
> Note that technically this is a regression from pre-early-debug.
ACK. I've updated the BZ appropriately.
jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Remove unused extern variables from debug (PR debug/86964)
2019-02-19 12:51 [PATCH] Remove unused extern variables from debug (PR debug/86964) Johan Carlsson
2019-02-21 19:22 ` Jeff Law
@ 2019-03-25 21:22 ` Jeff Law
1 sibling, 0 replies; 5+ messages in thread
From: Jeff Law @ 2019-03-25 21:22 UTC (permalink / raw)
To: Johan Carlsson, gcc-patches; +Cc: rguenther
On 2/19/19 5:51 AM, Johan Carlsson wrote:
> 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.
THanks. I've installed this on the trunk.
jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-03-25 21:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-19 12:51 [PATCH] Remove unused extern variables from debug (PR debug/86964) Johan Carlsson
2019-02-21 19:22 ` Jeff Law
2019-02-21 19:50 ` Richard Biener
2019-02-21 21:45 ` Jeff Law
2019-03-25 21:22 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).