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: 75310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1363563vqo; Mon, 27 Mar 2023 01:54:18 -0700 (PDT) X-Google-Smtp-Source: AKy350YfrQMtQkld30JclRGFgrav6UigNgfwId2KltkjzlI53Gg2W9Rbn1DhvSHysXfkukqI111G X-Received: by 2002:a17:906:c20e:b0:920:388c:5c60 with SMTP id d14-20020a170906c20e00b00920388c5c60mr12408783ejz.41.1679907258674; Mon, 27 Mar 2023 01:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679907258; cv=none; d=google.com; s=arc-20160816; b=uM8kjv5GaOAAKXy+Q/Ufz6CgBx0Ol9WTMpVC2JFPWe2qFt065X39YyfG3sKvtVQl9G vulS2b+vS90jl+gzlmt9BelizajuTB5UEnSCM8H3gdv0vOGhlmJyyWIfx2rWKwuhN+tx V/wYLi/xjCm7C4xdwAZ5w+fShPxenCvjZzp+Y2E/mn1yr8vu+yqxhC+6nZm6e+aXpc/p oQjCRcysYuVG81fin2I8H2RaZDSyUBJZnG+YMyrz7ggEKMmxkjYWjGUUcO/eFZGhtHIY mG3Uw2zXJhurdxiBfVEZY00pFZ2Xl1aZ7tulY57Zxph9FAdI8iWW2bLW1VzxThqh8MNJ dyFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=x0nl4EYGwE2PooRle3M4asEEBI6kxlVykznxgsXBhK0=; b=mYfRTJhS/zG4xFXJiq21cu41mRxOwAl0zVEvsUhR9RQ2s0WR9cpvXXdv3a2misTeOV ZxAXdJKyys6T2GdtyfybYgfBstkMWOpMLsn7V9iPH6++n9/gI8tzMu4x+sABFP+7Nxak WJkO0z1oVG7Y565OBZugxXDCDAY9biW407XpuqBLRK16P4zFRvjBX7H8Fb5cm6j0ue0Q yGg+i23D3jlDsPp0IQo1S+H2ltU3JAZi4FeJogaJkzh8do+PJle1V8uLSLtYY27j2RRM U4F7EaFL4eA8biVvXLKdNxCP8ipjN2HIRx29rmMTcXq+ZqaTy0k02NWekkEr+ym/9vpY Si6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=y4lUsH5B; 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 sb1-20020a1709076d8100b009256ac76f98si25284621ejc.676.2023.03.27.01.54.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 01:54:18 -0700 (PDT) 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=y4lUsH5B; 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 D0A2E38555A1 for ; Mon, 27 Mar 2023 08:54:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0A2E38555A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679907249; bh=x0nl4EYGwE2PooRle3M4asEEBI6kxlVykznxgsXBhK0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=y4lUsH5BJzequ7UQfJyI5S0sDxxv6zMp8dITpf02SyL55cqtPgG+BHBC1dM0sFca4 FIxnuAmD/naf5kZw0ePcdCLn6Jn7795O5fRY4tY4u2l5SSqmWoTB47Fksid7UP83XU SbCq9G9BkM/16cE/pUtNouI2w8N1Ca6MGZMOQrts= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761510433721801773?= X-GMAIL-MSGID: =?utf-8?q?1761510433721801773?= 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)