From patchwork Thu Nov 28 15:23:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1202131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514774-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LDv8IR1r"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47P1d55TXyz9s3Z for ; Fri, 29 Nov 2019 02:23:51 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=gMbkVW0/uIhlGYAHmsoPCbZ6b3QbCd1drxLJ8D6Uv/q+9yO36i vLINF7LWlVveMUmMlFVZ7C8uhg7KW8hWdY3Px+vL6GRtxdTEZWifx7DKzoSahTUQ AlhhRLxivl9Prrxy0kdgeD3Q2BG+6dlO8h+Y+SxWvcaO0BzPEghujOy8I= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=rur158sJjIp5yEHYitD03gktneY=; b=LDv8IR1rFehLZMIjdWgp qxOwetvs1xetf2PUqwuvnED8+tUCm+eym8rCM2qj470K0pQaaxK4iaJOwT3G+wzP M4BvQsNR0Hulk5pWRt2jhaiize5OzMjvR9X/lKcIHiCmduKHLF1pIZWmB+bxsdao sQi7TYttrT+jQ9+CluwcQ0c= Received: (qmail 74143 invoked by alias); 28 Nov 2019 15:23:43 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 74134 invoked by uid 89); 28 Nov 2019 15:23:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:cgraph_, UD:cgraph.c, cgraphc, cgraph.c X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Nov 2019 15:23:41 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1A944AEC6 for ; Thu, 28 Nov 2019 15:23:39 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH] cgraph: ifunc resolvers cannot be made local (PR 92697) User-Agent: Notmuch/0.29.2 (https://notmuchmail.org) Emacs/26.3 (x86_64-suse-linux-gnu) Date: Thu, 28 Nov 2019 16:23:38 +0100 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi, In the attached testcase, IPA-SRA thinks that an ifunc resolver (meanwhile IPA-split into two functions) function can be changed and so goes ahead. The cgraph machinery then however throws away the new clone of the caller instead of the "old" caller and inliner inlines the clone of the ".part" function into the original resolver, which results into an interesting miscompilation because IPA-SRA counted on that both the caller and the callee are modified. Fixed by making cgraph_node::can_be_local_p return false for ifunc resolvers, as it should. The patch also adds dumping of the symtab_node flag. Bootstrapped and tested on x86_64-linux, OK for trunk? Thanks, Martin 2019-11-27 Martin Jambor PR ipa/92697 * cgraph.c (cgraph_node_cannot_be_local_p_1): Return true for ifunc_resolvers. * symtab.c (symtab_node::dump_base): Dump ifunc_resolver flag. Removed trailig whitespace. testsuite/ * g++.dg/ipa/pr92697.C: New. --- gcc/cgraph.c | 1 + gcc/symtab.c | 4 ++- gcc/testsuite/g++.dg/ipa/pr92697.C | 51 ++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ipa/pr92697.C diff --git a/gcc/cgraph.c b/gcc/cgraph.c index 1f7a5c58d98..dd07516b83e 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -2227,6 +2227,7 @@ static bool cgraph_node_cannot_be_local_p_1 (cgraph_node *node, void *) { return !(!node->force_output + && !node->ifunc_resolver && ((DECL_COMDAT (node->decl) && !node->forced_by_abi && !node->used_from_object_file_p () diff --git a/gcc/symtab.c b/gcc/symtab.c index 3e634e22c86..5a3122fc8bb 100644 --- a/gcc/symtab.c +++ b/gcc/symtab.c @@ -914,8 +914,10 @@ symtab_node::dump_base (FILE *f) if (DECL_STATIC_DESTRUCTOR (decl)) fprintf (f, " destructor"); } + if (ifunc_resolver) + fprintf (f, " ifunc_resolver"); fprintf (f, "\n"); - + if (same_comdat_group) fprintf (f, " Same comdat group as: %s\n", same_comdat_group->dump_asm_name ()); diff --git a/gcc/testsuite/g++.dg/ipa/pr92697.C b/gcc/testsuite/g++.dg/ipa/pr92697.C new file mode 100644 index 00000000000..8958bd0dcf2 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr92697.C @@ -0,0 +1,51 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O2 -fdump-ipa-sra" } */ + +extern int have_avx2; +extern int have_ssse3; + +namespace NTL +{ + + static void randomstream_impl_init_base () + { + __builtin_printf ("Frob1\n"); + } + + static void // __attribute__ ((target ("ssse3"))) + randomstream_impl_init_ssse3 () + { + __builtin_printf ("Frob2\n"); + } + + static void + //__attribute__ ((target ("avx2,fma,avx,pclmul,ssse3"))) + randomstream_impl_init_avx2 () + { + __builtin_printf ("Frob3\n"); + } + + extern "C" + { + static void (*resolve_randomstream_impl_init (void)) () + { + if (have_avx2) + return &randomstream_impl_init_avx2; + if (have_ssse3) + return &randomstream_impl_init_ssse3; + return &randomstream_impl_init_base; + } + } + static void + __attribute__ ((ifunc ("resolve_" "randomstream_impl_init"))) + randomstream_impl_init (); + void foo () + { + randomstream_impl_init (); + } + +} + + +/* { dg-final { scan-ipa-dump-not "Created new node" "sra" } } */