From patchwork Mon Mar 27 08:52:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xionghu Luo X-Patchwork-Id: 66926 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 665633858C2F for ; Mon, 27 Mar 2023 08:53:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 665633858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679907234; bh=x0nl4EYGwE2PooRle3M4asEEBI6kxlVykznxgsXBhK0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=nDwVIVXliuRMB6+dWq3GdlrMFrhMB687do7IARkptybqDDNBWN4EkLU4vHnQoIzIm PZMiDy6ImcYKEE51rCuo/FXBy2orzZme1P3hEeulupgxEjAQ5fKq9d5QF0Rk5wop4C QJuj/hINBg/JGO7UkJILil2kj98WB68AZucDvztU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from VM-122-127-centos.localdomain (unknown [43.132.141.3]) by sourceware.org (Postfix) with ESMTPS id 9BC8D3858CDA; Mon, 27 Mar 2023 08:53:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BC8D3858CDA Received: by VM-122-127-centos.localdomain (Postfix, from userid 1009) id 0230E41057; Mon, 27 Mar 2023 16:53:01 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: luoxhu@gcc.gnu.org, hubicka@ucw.cz, rguenther@suse.de, sandra@codesourcery.com, Xionghu Luo Subject: [RFC PATCH] ipa-visibility: Fix ICE in lto-partition caused by incorrect comdat group solving in ipa-visibility Date: Mon, 27 Mar 2023 16:52:52 +0800 Message-Id: <20230327085252.3390790-1-xionghuluo@tencent.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, NO_DNS_FOR_FROM, RCVD_IN_PBL, SPF_HELO_NONE, SPF_NONE, 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: Xionghu Luo via Gcc-patches From: Xionghu Luo Reply-To: Xionghu Luo Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" I have a case ICE in lto-partion.c:158 not easy to reduce, this ICE appears some time ago from link: https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586290.html. I tried the proposed patch but it doesn't work for me. Then I did some hack and finally got a successful lto link to compare with a ICE lto link. It seems to me that the ICE in add_symbol_to_partition_1, at lto/lto-partition.c:158 is caused by not dissovle comdat_group_list correctly in update_visibility_by_resolution_info. The ICE node is a preempted_reg '__dt_del' function with same_comdat_group linked to '__dt_base' function, succeeded by '__dt_comp' function. Success resolution is: 2420 f75f1945 PREVAILING_DEF _ZN6google8protobuf8internal16FunctionClosure1IPKNS0_15FieldDescriptorEED2Ev/81027 2422 f75f1945 PREVAILING_DEF _ZN6google8protobuf8internal16FunctionClosure1IPKNS0_15FieldDescriptorEED1Ev/81028 2424 f75f1945 PREEMPTED_REG _ZN6google8protobuf8internal16FunctionClosure1IPKNS0_15FieldDescriptorEED0Ev/81029 with FOR_EACH_FUNCTION access order: 81029(__dt_del) -> 81028(__dt_comp) -> 81027(__dt_base) 81029 is accessed first, and it is markded externally_visable false, then accessing 81028 removed all the same_comdat_groups as expected. ICE resolution is: 2362 f75f1945 PREEMPTED_REG _ZN6google8protobuf8internal16FunctionClosure1IPKNS0_15FieldDescriptorEED0Ev/81029 2365 f75f1945 PREVAILING_DEF _ZN6google8protobuf8internal16FunctionClosure1IPKNS0_15FieldDescriptorEED2Ev/81027 2367 f75f1945 PREVAILING_DEF _ZN6google8protobuf8internal16FunctionClosure1IPKNS0_15FieldDescriptorEED1Ev/81028 with FOR_EACH_FUNCTION access order: 81028(__dt_comp) -> 81027(__dt_base) -> 81029(__dt_del) 81028 is accessed firstly, and node 81029's externally_visible is still true, when calling 81028's update_visibility_by_resolution_info, it early returns as 'same_def' is false then fail to dissolve same_comdat_group list. So the point here is if PREEMPTED_REG node is not accessed first, the externallay_visable variable won't be updated on time when accessing PREVAILING_DEF nodes first. This patch using *function check* instead of *variable check* to eliminate the resolution sequence influence. Not sure whether this patch could also fix Sandra's ICE either? gcc/ChangeLog: * ipa-visibility.cc (update_visibility_by_resolution_info): Check node's externally_visiable with function instead of variable. (function_and_variable_visibility): New parameter whole_program. Signed-off-by: Xionghu Luo --- gcc/ipa-visibility.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gcc/ipa-visibility.cc b/gcc/ipa-visibility.cc index 8ec82bb333e..1ebc584ffd9 100644 --- a/gcc/ipa-visibility.cc +++ b/gcc/ipa-visibility.cc @@ -393,7 +393,7 @@ update_vtable_references (tree *tp, int *walk_subtrees, resolution info. */ static void -update_visibility_by_resolution_info (symtab_node * node) +update_visibility_by_resolution_info (symtab_node * node, bool whole_program) { bool define; @@ -412,7 +412,12 @@ update_visibility_by_resolution_info (symtab_node * node) for (symtab_node *next = node->same_comdat_group; next != node; next = next->same_comdat_group) { - if (!next->externally_visible || next->transparent_alias) + if ((is_a (next) + && !dyn_cast (next)->externally_visible_p ()) + || (is_a (next) + && !cgraph_externally_visible_p (dyn_cast (next), + whole_program)) + || next->transparent_alias) continue; bool same_def @@ -750,7 +755,7 @@ function_and_variable_visibility (bool whole_program) DECL_EXTERNAL (node->decl) = 1; } - update_visibility_by_resolution_info (node); + update_visibility_by_resolution_info (node, whole_program); if (node->weakref) optimize_weakref (node); } @@ -842,7 +847,7 @@ function_and_variable_visibility (bool whole_program) && !DECL_EXTERNAL (vnode->decl)) localize_node (whole_program, vnode); - update_visibility_by_resolution_info (vnode); + update_visibility_by_resolution_info (vnode, whole_program); /* Update virtual tables to point to local aliases where possible. */ if (DECL_VIRTUAL_P (vnode->decl)