From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id B00D33858D3C for ; Thu, 2 Mar 2023 07:43:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B00D33858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id B8EF021A97; Thu, 2 Mar 2023 07:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677742994; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Q3hw9n8jSsOxkrmkjzOfChfOv+Ri/3LsPYJCjpdt5HM=; b=njBJ9GfTezdJlgP6cXtowYPHL7OiAAFbhNxILxr6ucCkpmnWaEscv5BH+Aqm2DCCL2VGjf t0Ezfh+yuInU4kXjarPn3FH1DiUQu+LuGbX918T5gvqE4OrQSi6rDPMtQnjtsJ8IMy9jKI UCCbc22hEj6miRppoiI3bFLv5ecCwqM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677742994; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Q3hw9n8jSsOxkrmkjzOfChfOv+Ri/3LsPYJCjpdt5HM=; b=xBICyRqBblVBmgAUqtigU7X3KXL0QEX4tTvXkNOLreaKCQSV3ZdqF3h8P9XFhtKy2ThEBY ybYYaJTNjyXKmiBg== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id A9FBC2C141; Thu, 2 Mar 2023 07:43:14 +0000 (UTC) Date: Thu, 2 Mar 2023 07:43:14 +0000 (UTC) From: Richard Biener To: Jason Merrill cc: Jakub Jelinek , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] debug/108772 - ICE with late debug generated with -flto In-Reply-To: <51ff85c2-faaa-4943-8d91-db9c681a172d@redhat.com> Message-ID: References: <01327.123030108070400465@us-mta-295.us.mimecast.lan> <51ff85c2-faaa-4943-8d91-db9c681a172d@redhat.com> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 1 Mar 2023, Jason Merrill wrote: > On 3/1/23 08:09, Jakub Jelinek wrote: > > On Wed, Mar 01, 2023 at 01:07:02PM +0000, Richard Biener wrote: > >> When combining -g1 with -flto we run into the DIE location annotation > >> machinery for globals calling dwarf2out_late_global_decl but not > >> having any early generated DIE for function scope statics. In > >> this process we'd generate a limbo DIE since also the function scope > >> doesn't have any early generated DIE. The limbo handling then tries > >> to force a DIE for the context chain which ultimatively fails and > >> ICEs at the std namespace decl because at -g1 we don't represent that. > >> > >> The following avoids this situation by making sure to never generate > >> any limbo DIEs from dwarf2out_late_global_decl in the in_lto_p path > >> but instead for function scope globals rely on DIE generation for > >> the function to output a DIE for the local static (which doesn't > >> happen for -g1). > > So the issue is that we're trying to force out a DIE for a decl that we > wouldn't have generated without -flto? How is it avoided in the non-LTO case? When we go rest_of_decl_compilation for this decl we defer to the containing function to generate an early DIE but that doesn't (because of -g1). The call to late_global_decl that's done by assemble_decl then does nothing because there's no early DIE. But with -flto we cannot completely rely on early DIE presence (not even without, in case of cloning - but we don't clone global variables), esp. because there's still the "supported" non-early-LTO path for non-ELF targets. So at this point it seems to be the best thing to mimic what rest_of_decl_compilation does and defer to dwarf2out of the containing function to generate the DIE (or not). For the reason of the least amount of changes at this point in stage4 I went for querying the DECL_CONTEXT DIE instead of right-out not handling local_function_static () decls in this path. If you'd prefer that, so if (! die && in_lto_p /* Function scope variables are emitted when emitting the DIE for the function. */ && ! local_function_static (decl)) dwarf2out_decl (decl); then I can test that variant as well which feels a bit more consistent. Thanks, Richard. > >> I explored a lot of other options to fix this but in the end this > >> seems to be the most spot-on fix with the least risk of unwanted > >> effects. > >> > >> LTO bootstrapped on x86_64-unknown-linux-gnu (running into PR108984), > >> bootstrapped and tested on x86_64-unknown-linux-gnu. > >> > >> OK? > >> > >> Thanks, > >> Richard. > >> > >> PR debug/108772 > >> * dwarf2out.cc (dwarf2out_late_global_decl): Do not > >> generate a DIE for a function scope static when we do > >> not have a DIE for the function already. > >> > >> * g++.dg/lto/pr108772_0.C: New testcase. > > > > LGTM, but please give Jason a day to chime in if he disagrees. > > > > Jakub > > > > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)