From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id EF2E33858439 for ; Tue, 19 Jul 2022 08:30:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EF2E33858439 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4670F349ED for ; Tue, 19 Jul 2022 08:30:27 +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 41D2D2C141 for ; Tue, 19 Jul 2022 08:30:27 +0000 (UTC) Date: Tue, 19 Jul 2022 08:30:27 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] lto/106334 - relax assert during WPA tree merging 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=-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-List-Received-Date: Tue, 19 Jul 2022 08:30:30 -0000 Message-ID: <20220719083027.epEwXaDhl7FbAljhy9x1UAMUndiR7NLrqu-qXnfe88A@z> The dwarf2out map of tree to symbol + offset is populated too early when streaming in trees so that when WPA tree merging decides to recycle them the mapping prevails and if we are unlucky the same address is used for another tree with a symbol + offset DIE to record. The following mitigates the resulting ICE by relaxing the assert, allowing re-use of a slot during WPA. Delaying the register would be better but it's already somewhat hairy and uglifying this further doesn't look too important right now. Bootstrap / regtest running on x86_64-unknown-linux-gnu. * dwarf2out.cc (dwarf2out_register_external_die): Allow map entry re-use during WPA. --- gcc/dwarf2out.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index e3920c898f5..3ac39c1a5b0 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -6069,7 +6069,11 @@ dwarf2out_register_external_die (tree decl, const char *sym, if (!external_die_map) external_die_map = hash_map::create_ggc (1000); - gcc_checking_assert (!external_die_map->get (decl)); + /* When we do tree merging during WPA we can end up re-using GC memory + as there's currently no way to unregister external DIEs. Ideally + we'd register them only after merging finished but allowing override + here is easiest. See PR106334. */ + gcc_checking_assert (flag_wpa || !external_die_map->get (decl)); sym_off_pair p = { IDENTIFIER_POINTER (get_identifier (sym)), off }; external_die_map->put (decl, p); } -- 2.35.3