From patchwork Wed Mar 1 13:07:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 62896 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3619448wrd; Wed, 1 Mar 2023 05:07:50 -0800 (PST) X-Google-Smtp-Source: AK7set/cuVStwaltdOfvMMSmChM1vELDa6h6k1GcWCvjvHmyJidb2ribKkGYFF0ilDiTts6cLGnN X-Received: by 2002:aa7:dd48:0:b0:4b0:f559:ed3d with SMTP id o8-20020aa7dd48000000b004b0f559ed3dmr7111938edw.5.1677676070592; Wed, 01 Mar 2023 05:07:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677676070; cv=none; d=google.com; s=arc-20160816; b=NMnyqTH6pYn4Ho3H21T2ljkc3rKCI2QvOM3yXyi3MVtl4Qm5K4zlYZxi8myXY5DymL oqiFzJ5Vc8KtaP3MV5WbIPlx0t6A2X+gWMLOlIrA9iPdqp5dq4xhqZrExPRY6snGlKGv 4qXsoD6vmjBolHdytSmscACJAmwyuBZhWUhlC9/G9ART8D2OMXyu44Bh4N5bomS84VYu WnoAWPK4D+fqgn/BHfghXkKpqSNSnNv3uw9CYbSrx1zXVaX9eHryT53fPSelh4zkzWqJ +RfFzv6Zw9VLA+jQBzjHje1ldabDJSPY28PXbImO7KBUrzFE4iXMOdMgP7o8UOkHMHkY DFZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=wjkR2vdRFJh76v4Iy/LWXm8rEaPv8ezxtT1wJkzPfs4=; b=zJZcYyHMF7pNS0uBABZkiV54lbwezuIrxAi/0J9KeBvJZ8bRTUsBYuREdN274TVA9h dDvJf4AEAvYlJwkK8lCTylZfPbt9nIwgktOcmMRj6erZY1+tSeE+fhGZUY3nX8gew6LD uTIzbHatkAZGa0LToaTeRIKXrlQ8HX+RdWJneQO+tdJbtkCgIigaCDai8cMmZCVB9tmt zOe70z0RMDvHRL5l54E6YkAHIR9LPjnIyJXMzD+ML+cOMuuChSDdK3fIvTAPo4LWK4vC 8QFKIXwryZyFyyt+7El4JXNcFDagNTmI3oGEewK/wcZXMy/EgZ46d4WY6tWLav0sD45x pvtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cbv2Xpo4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k6-20020aa7c386000000b004ac8358be51si14468192edq.464.2023.03.01.05.07.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 05:07:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cbv2Xpo4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A7B03858401 for ; Wed, 1 Mar 2023 13:07:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A7B03858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677676069; bh=wjkR2vdRFJh76v4Iy/LWXm8rEaPv8ezxtT1wJkzPfs4=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=cbv2Xpo4qYS8zl8N85CO0FgFhwU+1AnqYeikVJC9ncNdVOt+STPVSJOyBrGygMCT4 GoPTvf87b7YoA55b4MdPZL0/qSnNVNlydbXpe9WR4Ufx++BUf2yrTlTGnTBmQyadf0 0KkhjtkS5BCAvb9uj4H8Zpf2N8SJv9kVrerTEiN0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 8F91C3858D33 for ; Wed, 1 Mar 2023 13:07:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F91C3858D33 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 8F3191FE15; Wed, 1 Mar 2023 13:07:02 +0000 (UTC) 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 4CD822C141; Wed, 1 Mar 2023 13:07:02 +0000 (UTC) Date: Wed, 1 Mar 2023 13:07:02 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek , jason@redhat.com Subject: [PATCH] debug/108772 - ICE with late debug generated with -flto User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230301130749.9A7B03858401@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759170863273219009?= X-GMAIL-MSGID: =?utf-8?q?1759170863273219009?= 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). 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. --- gcc/dwarf2out.cc | 12 ++++++- gcc/testsuite/g++.dg/lto/pr108772_0.C | 46 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/lto/pr108772_0.C diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 1f39df3b1e2..6f457ed4472 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -27283,7 +27283,17 @@ dwarf2out_late_global_decl (tree decl) was not enabled at compile-time or the target doesn't support the LTO early debug scheme. */ if (! die && in_lto_p) - dwarf2out_decl (decl); + { + /* Avoid relying on the ability to force context DIEs for + local entities. Instead if the function context was not + instantiated yet defer to it producing its local DIEs. + See PR108772. */ + dw_die_ref context_die = comp_unit_die (); + if (local_function_static (decl)) + context_die = lookup_decl_die (DECL_CONTEXT (decl)); + if (context_die) + dwarf2out_decl (decl); + } else if (die) { /* We get called via the symtab code invoking late_global_decl diff --git a/gcc/testsuite/g++.dg/lto/pr108772_0.C b/gcc/testsuite/g++.dg/lto/pr108772_0.C new file mode 100644 index 00000000000..81f15a90a3e --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/pr108772_0.C @@ -0,0 +1,46 @@ +// { dg-lto-do link } +// { dg-require-effective-target shared } +// { dg-require-effective-target fpic } +// { dg-lto-options { "-flto -fPIC -shared -O1 -fimplicit-constexpr -g1" } } +// { dg-extra-ld-options "-shared" } + +namespace std { +struct _Sp_counted_base { + virtual void *_M_get_deleter(const int &); +}; +bool _S_eq(int); +struct _Sp_make_shared_tag { + static const int &_S_ti() { + static constexpr char __tag{}; + return reinterpret_cast(__tag); + } +}; +struct _Impl { + _Impl(int); +}; +int _Sp_counted_ptr_inplace___a; +struct _Sp_counted_ptr_inplace : _Sp_counted_base { + _Sp_counted_ptr_inplace() : _M_impl(_Sp_counted_ptr_inplace___a) {} + void *_M_get_deleter(const int &__ti) { + auto __ptr(_M_ptr()); + &__ti == &_Sp_make_shared_tag::_S_ti() || _S_eq(__ti); + return __ptr; + } + int *_M_ptr(); + _Impl _M_impl; +}; +struct __shared_count { + __shared_count(int, int) { _Sp_counted_ptr_inplace(); } +}; +int _M_ptr; +struct __shared_ptr { + template + __shared_ptr(_Alloc __tag) : _M_refcount(_M_ptr, __tag) {} + __shared_count _M_refcount; +}; +int shared_ptr___tag; +struct shared_ptr : __shared_ptr { + shared_ptr() : __shared_ptr(shared_ptr___tag) {} +}; +void ArgEq() { shared_ptr(); } +} // namespace std