From patchwork Sat Nov 6 22:40:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1551822 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=bYuI/TbM; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hmsmv3Vcyz9sfG for ; Sun, 7 Nov 2021 09:41:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E07A3857810 for ; Sat, 6 Nov 2021 22:41:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E07A3857810 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636238488; bh=97LN+C3znXUSU1NOHaxJblhyYbLpq5jNhcC85UkPO/c=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bYuI/TbMXIZfZ44WzJ3zcGosNQ4PRwHy/Yp0A+wyjXN/drXd3oY7HWDqO9/zzbdp8 Z0txBMPu/5RwauvXEj7iyE+K9YzgyJy9fiNfp4ARoDaA4GwlFLTpulUKtOag2VUYUb 0dAzW5M/8cv6u0k11b1MKqNip5Nlo9lMPcltnOzA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 733903858401 for ; Sat, 6 Nov 2021 22:40:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 733903858401 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id B56D5281D88; Sat, 6 Nov 2021 23:40:43 +0100 (CET) Date: Sat, 6 Nov 2021 23:40:43 +0100 To: gcc-patches@gcc.gnu.org Subject: Fix can_be_discarded_p wrt partitioned functions Message-ID: <20211106224043.GH4548@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, can_be_discarded_p is testing DECL_EXTERNAL flag to see if the symbol can be discarded by linker if unreachable. This is meant to catch extern inline functions (which is bit side case and it is intded to avoid gcc from producing new references to them if there were no refernces before) but it mistakely also matches partitioned functions during LTO. This led to the ICE with sanity check I added to gimple_call_static_chain_flags since we suddenly got interposable nested functions. This is fixed by the patch and I checked I can build the failing testcases with the sanity check re-instatiated which I plan to do after some more testing. ltobootstrapped/regtested x86_64. Comitte. Honza gcc/ChangeLog: * cgraph.h (cgraph_node::can_be_discarded_p): Do not return true on functions from other partition. gcc/lto/ChangeLog: PR ipa/103070 PR ipa/103058 * lto-partition.c (must_not_rename): Update comment. (promote_symbol): Set resolution to LDPR_PREVAILING_DEF_IRONLY. diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 4cdb3738b4d..0a1f7c8960e 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -404,7 +404,8 @@ public: inline bool can_be_discarded_p (void) { - return (DECL_EXTERNAL (decl) + return ((DECL_EXTERNAL (decl) + && !in_other_partition) || ((get_comdat_group () || DECL_COMMON (decl) || (DECL_SECTION_NAME (decl) && DECL_WEAK (decl))) diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c index 15761ac9eb5..bee40218159 100644 --- a/gcc/lto/lto-partition.c +++ b/gcc/lto/lto-partition.c @@ -852,7 +852,9 @@ must_not_rename (symtab_node *node, const char *name) /* Avoid mangling of already mangled clones. ??? should have a flag whether a symbol has a 'private' name already, since we produce some symbols like that i.e. for global constructors - that are not really clones. */ + that are not really clones. + ??? it is what unique_name means. We only need to set it when doing + private symbols. */ if (node->unique_name) { if (dump_file) @@ -995,6 +997,10 @@ promote_symbol (symtab_node *node) defined by the non-LTO part. */ privatize_symbol_name (node); TREE_PUBLIC (node->decl) = 1; + /* After privatization the node should not conflict with any other symbol, + so it is prevailing. This is important to keep binds_to_current_def_p + to work across partitions. */ + node->resolution = LDPR_PREVAILING_DEF_IRONLY; DECL_VISIBILITY (node->decl) = VISIBILITY_HIDDEN; DECL_VISIBILITY_SPECIFIED (node->decl) = true; if (dump_file)