From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31547 invoked by alias); 30 Jun 2017 08:48:05 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 31354 invoked by uid 89); 30 Jun 2017 08:48:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy= X-Spam-User: qpsmtpd, 2 recipients 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; Fri, 30 Jun 2017 08:47:59 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 62CD0AE56; Fri, 30 Jun 2017 08:47:57 +0000 (UTC) From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Fix ifunc and resolver (PR ipa/81213). To: gcc-patches@gcc.gnu.org Cc: meissner@gcc.gnu.org Message-ID: <425959b6-dd44-42af-7ed0-34970b2b5a10@suse.cz> Date: Fri, 30 Jun 2017 08:48:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------E081982D2779F020A203883F" X-IsSubscribed: yes X-SW-Source: 2017-06/txt/msg02361.txt.bz2 This is a multi-part message in MIME format. --------------E081982D2779F020A203883F Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 814 Hello. Following patch does refactoring of make_resolver_func where ifunc alias and resolver were probably confused. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. i386.exp tests work on x86_64-linux-gnu. Ready to be installed? Martin gcc/ChangeLog: 2017-06-29 Martin Liska PR ipa/81213 * config/i386/i386.c (make_resolver_func): Do complete refactoring of the function. gcc/testsuite/ChangeLog: 2017-06-29 Martin Liska PR ipa/81213 * gcc.target/i386/pr81213.c: New test. --- gcc/config/i386/i386.c | 37 ++++++++++++++++----------------- gcc/testsuite/gcc.target/i386/pr81213.c | 19 +++++++++++++++++ 2 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr81213.c --------------E081982D2779F020A203883F Content-Type: text/x-patch; name="0001-Fix-ifunc-and-resolver-PR-ipa-81213.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-ifunc-and-resolver-PR-ipa-81213.patch" Content-length: 3984 diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 9d53a6c869c..e90ae249b96 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -33816,30 +33816,30 @@ ix86_get_function_versions_dispatcher (void *decl) } /* Make the resolver function decl to dispatch the versions of - a multi-versioned function, DEFAULT_DECL. Create an + a multi-versioned function, DEFAULT_DECL. IFUNC_ALIAS_DECL is + ifunc alias that will point to the created resolver. Create an empty basic block in the resolver and store the pointer in EMPTY_BB. Return the decl of the resolver function. */ static tree make_resolver_func (const tree default_decl, - const tree dispatch_decl, + const tree ifunc_alias_decl, basic_block *empty_bb) { char *resolver_name; tree decl, type, decl_name, t; - bool is_uniq = false; /* IFUNC's have to be globally visible. So, if the default_decl is not, then the name of the IFUNC should be made unique. */ if (TREE_PUBLIC (default_decl) == 0) - is_uniq = true; + { + char *ifunc_name = make_unique_name (default_decl, "ifunc", true); + symtab->change_decl_assembler_name (ifunc_alias_decl, + get_identifier (ifunc_name)); + XDELETEVEC (ifunc_name); + } - /* Append the filename to the resolver function if the versions are - not externally visible. This is because the resolver function has - to be externally visible for the loader to find it. So, appending - the filename will prevent conflicts with a resolver function from - another module which is based on the same version name. */ - resolver_name = make_unique_name (default_decl, "resolver", is_uniq); + resolver_name = make_unique_name (default_decl, "resolver", false); /* The resolver function should return a (void *). */ type = build_function_type_list (ptr_type_node, NULL_TREE); @@ -33852,13 +33852,12 @@ make_resolver_func (const tree default_decl, TREE_USED (decl) = 1; DECL_ARTIFICIAL (decl) = 1; DECL_IGNORED_P (decl) = 0; - /* IFUNC resolvers have to be externally visible. */ - TREE_PUBLIC (decl) = 1; + TREE_PUBLIC (decl) = 0; DECL_UNINLINABLE (decl) = 1; /* Resolver is not external, body is generated. */ DECL_EXTERNAL (decl) = 0; - DECL_EXTERNAL (dispatch_decl) = 0; + DECL_EXTERNAL (ifunc_alias_decl) = 0; DECL_CONTEXT (decl) = NULL_TREE; DECL_INITIAL (decl) = make_node (BLOCK); @@ -33889,14 +33888,14 @@ make_resolver_func (const tree default_decl, pop_cfun (); - gcc_assert (dispatch_decl != NULL); - /* Mark dispatch_decl as "ifunc" with resolver as resolver_name. */ - DECL_ATTRIBUTES (dispatch_decl) - = make_attribute ("ifunc", resolver_name, DECL_ATTRIBUTES (dispatch_decl)); + gcc_assert (ifunc_alias_decl != NULL); + /* Mark ifunc_alias_decl as "ifunc" with resolver as resolver_name. */ + DECL_ATTRIBUTES (ifunc_alias_decl) + = make_attribute ("ifunc", resolver_name, + DECL_ATTRIBUTES (ifunc_alias_decl)); /* Create the alias for dispatch to resolver here. */ - /*cgraph_create_function_alias (dispatch_decl, decl);*/ - cgraph_node::create_same_body_alias (dispatch_decl, decl); + cgraph_node::create_same_body_alias (ifunc_alias_decl, decl); XDELETEVEC (resolver_name); return decl; } diff --git a/gcc/testsuite/gcc.target/i386/pr81213.c b/gcc/testsuite/gcc.target/i386/pr81213.c new file mode 100644 index 00000000000..13e15d5fef0 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr81213.c @@ -0,0 +1,19 @@ +/* PR ipa/81214. */ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ + +__attribute__((target_clones("avx","arch=slm","arch=core-avx2","default"))) +static int +foo () +{ + return -2; +} + +int main() +{ + return foo(); +} + +/* { dg-final { scan-assembler "\t.globl\tfoo\\..*\\.ifunc" } } */ +/* { dg-final { scan-assembler "foo.resolver:" } } */ +/* { dg-final { scan-assembler "foo\\..*\\.ifunc, @gnu_indirect_function" } } */ --------------E081982D2779F020A203883F--