From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29872 invoked by alias); 26 Jan 2015 08:53:29 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 29834 invoked by uid 89); 26 Jan 2015 08:53:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,FREEMAIL_FROM,KAM_STOCKGEN,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ob0-f171.google.com Received: from mail-ob0-f171.google.com (HELO mail-ob0-f171.google.com) (209.85.214.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 26 Jan 2015 08:53:22 +0000 Received: by mail-ob0-f171.google.com with SMTP id va2so6676579obc.2 for ; Mon, 26 Jan 2015 00:53:20 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.60.124.194 with SMTP id mk2mr11952817oeb.79.1422262400325; Mon, 26 Jan 2015 00:53:20 -0800 (PST) Received: by 10.76.18.49 with HTTP; Mon, 26 Jan 2015 00:53:20 -0800 (PST) In-Reply-To: <54C296B5.4050506@redhat.com> References: <54B87E5B.1090502@redhat.com> <54B88149.1040906@redhat.com> <54B94F4D.4040009@redhat.com> <54B97854.7040007@redhat.com> <54C296B5.4050506@redhat.com> Date: Mon, 26 Jan 2015 09:21:00 -0000 Message-ID: Subject: Re: [debug-early] C++ clones and limbo DIEs From: Richard Biener To: Aldy Hernandez Cc: Jason Merrill , gcc-patches , Jan Hubicka Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-01/txt/msg02235.txt.bz2 On Fri, Jan 23, 2015 at 7:45 PM, Aldy Hernandez wrote: > Phew... ok, I'm a little stuck here with the interaction between dwarf2out > and LTO, and I'm hoping y'all can shed some light. Please bear with me > through the verbosity, it gets clearer (I hope) near the end. > > > On 01/16/2015 12:45 PM, Jason Merrill wrote: >> >> On 01/16/2015 12:50 PM, Aldy Hernandez wrote: >>>> >>>> Can you remove the first flush and just do it in the second place? >>> >>> >>> If I only flush the limbo list in the second place, that's basically >>> what mainline does, albeit abstracted into a function. I thought the >>> whole point was to get rid of the limbo list, or at least keep it from >>> being a structure that has to go through LTO streaming. >> >> >> It would expect it to be before free_lang_data and LTO streaming. > > > The reason this wouldn't make a difference is because, as it stands, dwarf > for the clones are not generated until final.c: > > if (!DECL_IGNORED_P (current_function_decl)) > debug_hooks->function_decl (current_function_decl); > > which happens after free_lang_data. > > However, we can generate early dwarf for the clones right from the parser, > and things _mostly_ work: I think that is the correct thing to do. > diff --git a/gcc/cp/optimize.c b/gcc/cp/optimize.c > index 62e32d2..5539244 100644 > --- a/gcc/cp/optimize.c > +++ b/gcc/cp/optimize.c > @@ -539,6 +539,11 @@ maybe_clone_body (tree fn) > /* Start processing the function. */ > start_preparsed_function (clone, NULL_TREE, SF_PRE_PARSED); > > + /* Generate early dwarf for the clone now that we have a body > + for it. */ > + debug_hooks->early_global_decl (clone); > + > /* Tell cgraph if both ctors or both dtors are known to have > the same body. */ > if (can_alias > > And I say _mostly_ work, because now local statics will have the > DECL_ABSTRACT_P bit set, making LTO think that things live in another > partition, and are no longer trivially needed. For instance: > > struct TYPE { TYPE (int); } ; > > TYPE::TYPE (int some_argument) > { > static int static_p = 5; > } > > With the above patch, early dwarf generation will call gen_decl_die, which > eventually does: > > /* If we're emitting a clone, emit info for the abstract instance. */ > if (origin || DECL_ORIGIN (decl) != decl) > dwarf2out_abstract_function (origin > ? DECL_ORIGIN (origin) > : DECL_ABSTRACT_ORIGIN (decl)); > > Where decl and DECL_ABSTRACT_ORIGIN(decl) are: > (gdb) p decl > $87 = > (gdb) p decl.decl_common.abstract_origin > $88 = > > Now dwarf2out_abstract_function() will set DECL_ABSTRACT_P for all the > children of the abstract origin: > > was_abstract = DECL_ABSTRACT_P (decl); > set_decl_abstract_flags (decl, 1); > dwarf2out_decl (decl); > if (! was_abstract) > set_decl_abstract_flags (decl, 0); > > Unfortunately, this sets DECL_ABSTRACT_P for the "static_p" above, and > refuses to unset it after the call to dwarf2out_decl. I think the C++ FE does sth odd here by having an abstract origin that is not abstract (If I understand you correctly here). That is, the dwarf2out.c code above should be able to do gcc_assert (was_abstract); instead of setting abstract flags here. Otherwise the abstract origin wasn't and abstract origin. Or I am completely missing something - which means LTO is wrong to interpret DECL_ABSTRACT as it does: /* Nonzero for a given ..._DECL node means that this node represents an "abstract instance" of the given declaration (e.g. in the original declaration of an inline function). When generating symbolic debugging information, we mustn't try to generate any address information for nodes marked as "abstract instances" because we don't actually generate any code or allocate any data space for such instances. */ #define DECL_ABSTRACT_P(NODE) \ (DECL_COMMON_CHECK (NODE)->decl_common.abstract_flag) The above suggests LTO is correct in not outputting the decl. So it is either the C++ FE that is wrong in declaring this an abstract origin or dwarf2out.c is wrong in simply making all abstract origins (and its chilren) abstract because being an abstract origin doesn't require being abstract. Jason? > Through some miraculous gymnastics, LTO streams out symbols without the > "analyzed" bit set if things are not "in partition", which happens because > symtab_node::get_partitioning_class() returns SYMBOL_EXTERNAL (ahem, not in > partition) when the DECL_ABSTRACT_P bit is set. > > So... dwarf2out_abstract_function() sets the DECL_ABSTRACT_P bit, and LTO > thinks that local statics in a clone are in another partition, which causes > the analyzed bit to be dropped on the floor, which causes > symbol_table::remove_unreferenced_decls() to no longer think that local > statics are trivially needed. And if the local static is no longer needed, > varpool will not output its definition in the assembly file. > > I am very uncomfortable with a call to dwarf2out_abstract_function() > changing the behavior of the LTO streamer (and the optimizers), but it looks > like twiddling the DECL_ABSTRACT_P flag (and refusing to reset it) is by > design. > > I am all ears on solutions on either the LTO or the dwarf side. > > Thanks. > Aldy