From patchwork Thu Apr 12 11:29:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 897618 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476260-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=intel.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="i6dKhDmD"; 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 40MJbR27T4z9s32 for ; Thu, 12 Apr 2018 21:29:37 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=fioDRAuvYrnklygSGex3ujZustriZ Eu9RkZjgNFGilkIRTuVVGykyiCTrmzmm8wo+yk3KSrmfPOOQ0eDlYqb4Kt1Ur5+C 14RTRWETrPzoLRq9UCLXqbJBnAJ0ZnY2+nA5snfQ/3Cg+vhJhZSYdZq1ThCj84QD v//CZuTysdOZJQ= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=Cuo+qH5waMfM9Zjehz59Rr+1C6E=; b=i6d KhDmD3KLF2KbIX121B7dwYrQG+bHcOE2RhAiFvbn1LkkLfJaCqBAzrpsuptPS6hD N13MhYYCoXSsADaSUn/RrJKiDmLPJVKPmsnbarSLYkPdPz5wFoPbx7+st+kJy1dN 0omazlTuFSQ5WOFS2z+yRo85DSpuQW2VZ7wnAmQQ= Received: (qmail 514 invoked by alias); 12 Apr 2018 11:29:29 -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 500 invoked by uid 89); 12 Apr 2018 11:29:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM autolearn=ham version=3.3.2 spammy= X-HELO: mga14.intel.com Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Apr 2018 11:29:27 +0000 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Apr 2018 04:29:26 -0700 X-ExtLoop1: 1 Received: from gnu-skx-1.sc.intel.com ([172.25.70.206]) by fmsmga002.fm.intel.com with ESMTP; 12 Apr 2018 04:29:26 -0700 Received: by gnu-skx-1.sc.intel.com (Postfix, from userid 1000) id 0539BE014A; Thu, 12 Apr 2018 04:29:26 -0700 (PDT) Date: Thu, 12 Apr 2018 04:29:25 -0700 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: Jan Hubicka Subject: [PATCH] Don't mark IFUNC resolver as only called directly Message-ID: <20180412112925.GA222547@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) Since IFUNC resolver is called indirectly, don't mark IFUNC resolver as only called directly. OK for trunk? H.J. --- gcc/ PR target/85345 * cgraph.h: Include stringpool.h" and "attribs.h". (cgraph_node::only_called_directly_or_aliased_p): Return false for IFUNC resolver. gcc/testsuite/ PR target/85345 * gcc.target/i386/pr85345.c: New test. --- gcc/cgraph.h | 5 +++- gcc/testsuite/gcc.target/i386/pr85345.c | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr85345.c diff --git a/gcc/cgraph.h b/gcc/cgraph.h index d1ef8408497..9e195824fcc 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -24,6 +24,8 @@ along with GCC; see the file COPYING3. If not see #include "profile-count.h" #include "ipa-ref.h" #include "plugin-api.h" +#include "stringpool.h" +#include "attribs.h" class ipa_opt_pass_d; typedef ipa_opt_pass_d *ipa_opt_pass; @@ -2894,7 +2896,8 @@ cgraph_node::only_called_directly_or_aliased_p (void) && !DECL_STATIC_CONSTRUCTOR (decl) && !DECL_STATIC_DESTRUCTOR (decl) && !used_from_object_file_p () - && !externally_visible); + && !externally_visible + && !lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl))); } /* Return true when function can be removed from callgraph diff --git a/gcc/testsuite/gcc.target/i386/pr85345.c b/gcc/testsuite/gcc.target/i386/pr85345.c new file mode 100644 index 00000000000..63f771294ad --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr85345.c @@ -0,0 +1,44 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection -mcet" } */ +/* { dg-final { scan-assembler-times {\mendbr} 4 } } */ + +int resolver_fn = 0; +int resolved_fn = 0; + +static inline void +do_it_right_at_runtime_A (void) +{ + resolved_fn++; +} + +static inline void +do_it_right_at_runtime_B (void) +{ + resolved_fn++; +} + +static inline void do_it_right_at_runtime (void); + +void do_it_right_at_runtime (void) + __attribute__ ((ifunc ("resolve_do_it_right_at_runtime"))); + +extern int r; +static void (*resolve_do_it_right_at_runtime (void)) (void) +{ + resolver_fn++; + + typeof(do_it_right_at_runtime) *func; + if (r & 1) + func = do_it_right_at_runtime_A; + else + func = do_it_right_at_runtime_B; + + return (void *) func; +} + +int +main () +{ + do_it_right_at_runtime (); + return 0; +}