From patchwork Wed Nov 8 16:42:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 163105 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp1039980vqo; Wed, 8 Nov 2023 08:43:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYpYW4Kk4HseYGpBw9z7mxhVoYivAnWngXU25EWx4kZJ4sU81RGRX4NfVq7m7bi0/t4c8+ X-Received: by 2002:a05:620a:4620:b0:777:7214:44d with SMTP id br32-20020a05620a462000b007777214044dmr2989482qkb.23.1699461800507; Wed, 08 Nov 2023 08:43:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699461800; cv=pass; d=google.com; s=arc-20160816; b=XhPf40My/htuEMEd5gG/OmI+JKIr/lODWFt91jqkiUDp5mG5uEkx+6TV41tMLO+jBe gclcL591eP04VghOqJ532XlbilzGrqK7DPQGEMKyQTXwQHwzRU6t+zF5VYMt9dswCP+4 9MWnTqxlRur4eBDqs2aK39KCq0eJYhTE/FWpb4CJ3dAtfJ2eCqnp4pJG99LDX4oSIXM/ K5ebRhN8jQw41g/zBi7xHMn1U6najTb5iJBzwvb3+nMAyKVvM9yWwlSQS4chzOn9UuzC uh/+UAGXAlh5jZ/etp8sGzU/ZgIXxbGm44UjDsQWQXmEd+2SWBcrDPitl/lGjaCjRf0x 6FYw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:date:organization:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=4FuND202w5P2+dMGypuinf+AddDmHsPrpQ6p9QZMD00=; fh=O0AWNgiT2/mxAiDz8ccK6QOzXFBCZlQNsrm3ENe/YGc=; b=Z/PBYDPi/o4uAyLkBlH+8JWMJO/1zQUH8lUxl5ZntOYRj0n9Oi1C4Hp10ckgeIatJw QQnGm6LtER3GUO2hSPmufPPw+Qv1ZSdF/fdjjoTEp1glNSQ0jJpvkGRzdwXYCeF1uhhy 94cbqMMKILv+n2eUVQsS8x7HO7opf08C8GWB6iHN3CxnchqiWi8zg1BY6KzH8ZXcq/Hi vXxpxEm3sLOw0PCRh2U5GLO4UpCHEPGfJ/wfT6y+7JeKCkfHuxHvIda0GtqFnVdF3R3Z PQL5b71pURcZc4qhjSn2b7Gaar1/lMWZtNrt39f374hccw6ThSP+SfOCnR2UfdUa8Gxi W1jw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=gFTKe4bF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y10-20020a05620a44ca00b00776f2642d26si1550912qkp.729.2023.11.08.08.43.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 08:43:20 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=gFTKe4bF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CBF7385C6F8 for ; Wed, 8 Nov 2023 16:43:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by sourceware.org (Postfix) with ESMTPS id B91CF3858C54 for ; Wed, 8 Nov 2023 16:42:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B91CF3858C54 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B91CF3858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::82d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699461776; cv=none; b=fls/jLdQV/uvr+Q6o4AHEnp0i8590QbMm3tbiW6aaq/rech4FyzbvYWi6pDaYGfE10wsve2AN0V9/YrMyny3+e4zrqQTG0u81f4GiCzVnxZ9U+FUrRYcXYWeqUbKsqsaJg179UhhzxiEenG1rHv86poQ9sFXygAc5JyDzs/kugc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699461776; c=relaxed/simple; bh=ZcCMsLH+eHy12oJqq4bGIXivgpbK3A6SX4BXZisZV7I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=w7inkh0puPBlhLUg8EUOTYH+A4D5JMhsCE1FzEPPLR/NHlcljLgVfA47pLPrHMvv9r2romO/1zI9dfC+23PNdbxdlBTjAQxXgTsDnMxK+eta1/HTtZfAg7c8opQ8bEZDQoU7skc4FJA48yQ6/aYCLipL2sel7mi8wy18xHQ8CXk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-41feb963f60so8803431cf.1 for ; Wed, 08 Nov 2023 08:42:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1699461774; x=1700066574; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=4FuND202w5P2+dMGypuinf+AddDmHsPrpQ6p9QZMD00=; b=gFTKe4bFZlk23xUTACjbtIcRMB6q5Jkgy2e+bv4NNDio+pdBxBrFDUqNSZv7HBELxy J1ibJ8smHsFEyxhy38No8baCOL46MgrZRhiyNkKRvAN3qqBFZlXmDD8PmgGKkla4S9Bk k0hdMLRIyDPMQLsve/9gCR11dm42CpxHaOlYhokn2GuK+RvEiSWAegtWAWG8+iRIpoig pIRaPsin4YYifsFG1VM4m4lBX6hJ5nAvO/jDqmyBcUPPe1BNOVR0Bd3TlLQfuabHFbNg oXCzMUN9tovldMFVZYFysruYk9JmN2QqyTqUxufEZH6RROhCw5Pk1yhWE3WmFszvKnAf CJdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699461774; x=1700066574; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4FuND202w5P2+dMGypuinf+AddDmHsPrpQ6p9QZMD00=; b=GQn9dhaVyXUeGjt3X11S0Aa6nlJfnX/Xy7cmyn0+EaFmUOYTzuYIXDi4rXD/wErKy4 g4dU/KZ7Giz+IusOPDSrjoAyOWXc3d6Ovzi8iHXvNKEv2Ismwu60vr/I36s98fCpVFPG +gpMM8ivt3WDlRhQQHYPwIrxd0ZKr9+3ZZUKQDtFb9WW3uSXdhTSNK5BGPlEoo+m/p+w XHt+TeD/No7k9lH1xOUS0xOmCwm4UepOW7aAn5vDiGur4IvxhZdwN6y1hok5eXFemCDe 79t92ojVjmYmIGrW+BOKT0MUUhLkM8G2WuNKxJkpzC8F7hIPNNz3v6RVDi/Lxtc+zmtV 9F8A== X-Gm-Message-State: AOJu0Yxkue1ZzxUMJDWlOir179b8sqxF4KLWQWu+q6v5iLWgIbqy/c1e N/pxRu+JcHl2hp/RzwhfDu2YN7C+tF56ukBd2mzZPg== X-Received: by 2002:ac8:5895:0:b0:419:65f8:1cb8 with SMTP id t21-20020ac85895000000b0041965f81cb8mr3023198qta.10.1699461774087; Wed, 08 Nov 2023 08:42:54 -0800 (PST) Received: from free.home ([2804:7f1:2080:e9c8:ff5e:88e8:a900:d7b4]) by smtp.gmail.com with ESMTPSA id f14-20020ac8464e000000b0041b3a1462fbsm1060341qto.37.2023.11.08.08.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 08:42:53 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3A8Ggjis2216150 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 8 Nov 2023 13:42:45 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: Rainer Orth , Mike Stump , Jan Hubicka , Uros Bizjak Subject: [PATCH v2] [PR83782] ifunc: back-propagate ifunc_resolver to aliases Organization: Free thinker, does not speak for AdaCore Date: Wed, 08 Nov 2023 13:42:45 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_QUOTING 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782014857086085189 X-GMAIL-MSGID: 1782014857086085189 Ping? https://gcc.gnu.org/pipermail/gcc-patches/2022-August/599453.html gcc.target/i386/mvc10.c fails with -fPIE on ia32 because we omit the @PLT mark when calling an alias to an indirect function. Such aliases aren't marked as ifunc_resolvers in the cgraph, so the test that would have forced the PLT call fails. I've arranged for ifunc_resolver to be back-propagated to aliases, and relaxed the test that required the ifunc attribute to be attached to directly the decl, rather than taken from an aliased decl, when the ifunc_resolver bit is set. Regstrapped on x86_64-linux-gnu, also tested with gcc-13 on i686- and x86_64-. Ok to install? (in the initial patchset for PR83782 and mvc10, I also needed https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598873.html but I'm not getting that fail any more with gcc-13, apparently because a different patch was put in to address that part) for gcc/ChangeLog PR target/83782 * cgraph.h (symtab_node::set_ifunc_resolver): New, overloaded. Back-propagate flag to aliases. * cgraph.cc (cgraph_node::create): Use set_ifunc_resolver. (cgraph_node::create_alias): Likewise. * lto-cgraph.cc (input_node): Likewise. * multiple_target.cc (create_dispatcher_calls): Propagate to aliases when redirecting them. * symtab.cc (symtab_node::verify_base): Accept ifunc_resolver set in an alias to another ifunc_resolver nodes. (symtab_node::resolve_alias): Propagate ifunc_resolver from resolved target to alias. * varasm.cc (do_assemble_alias): Checking for the attribute. --- gcc/cgraph.cc | 4 ++-- gcc/cgraph.h | 13 +++++++++++++ gcc/lto-cgraph.cc | 2 +- gcc/multiple_target.cc | 2 ++ gcc/symtab.cc | 15 ++++++++++++++- gcc/varasm.cc | 5 ++++- 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index e41e5ad3ae74d..046dadf53af93 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -518,7 +518,7 @@ cgraph_node::create (tree decl) } if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl))) - node->ifunc_resolver = true; + node->set_ifunc_resolver (); node->register_symbol (); maybe_record_nested_function (node); @@ -576,7 +576,7 @@ cgraph_node::create_alias (tree alias, tree target) if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias)) != NULL) alias_node->transparent_alias = alias_node->weakref = true; if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (alias))) - alias_node->ifunc_resolver = true; + alias_node->set_ifunc_resolver (); return alias_node; } diff --git a/gcc/cgraph.h b/gcc/cgraph.h index cedaaac3a45b7..e118ac75121ac 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -471,6 +471,19 @@ public: return decl->decl_with_vis.symtab_node; } + /* Worked for the nonstatic set_ifunc_resolver, to vback-propagate + ifunc_resolver in the alias chain. */ + static bool set_ifunc_resolver (symtab_node *n, void * = NULL) + { + n->ifunc_resolver = true; + return false; + } + + /* Set the ifunc_resolver bit in this node and in any aliases thereof. */ + void set_ifunc_resolver () { + call_for_symbol_and_aliases (set_ifunc_resolver, NULL, true); + } + /* Try to find a symtab node for declaration DECL and if it does not exist or if it corresponds to an inline clone, create a new one. */ static inline symtab_node * get_create (tree node); diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc index 32c0f5ac6dbc1..e7f77ca72242a 100644 --- a/gcc/lto-cgraph.cc +++ b/gcc/lto-cgraph.cc @@ -1294,7 +1294,7 @@ input_node (struct lto_file_decl_data *file_data, node = symtab->create_empty (); node->decl = fn_decl; if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (fn_decl))) - node->ifunc_resolver = 1; + node->set_ifunc_resolver (); node->register_symbol (); } diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc index a2ed048d7dd28..26c73d6a1e4cf 100644 --- a/gcc/multiple_target.cc +++ b/gcc/multiple_target.cc @@ -160,6 +160,8 @@ create_dispatcher_calls (struct cgraph_node *node) source->create_reference (inode, IPA_REF_ALIAS); if (inode->get_comdat_group ()) source->add_to_same_comdat_group (inode); + if (!source->ifunc_resolver) + source->set_ifunc_resolver (); } else gcc_unreachable (); diff --git a/gcc/symtab.cc b/gcc/symtab.cc index 0470509a98d2a..b35b879028def 100644 --- a/gcc/symtab.cc +++ b/gcc/symtab.cc @@ -1109,9 +1109,19 @@ symtab_node::verify_base (void) error ("function symbol is not function"); error_found = true; } + /* If the ifunc attribute is present, the node must be marked as + ifunc_resolver, but it may also be marked on a node that + doesn't have the attribute, if it's an alias to another + marked node. The resolver node itself is an alias to the + function that performs the resolution proper, and that + function is not marked, but here we test other kinds of + aliases, that alias the indirect function. */ else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)) != NULL) - != dyn_cast (this)->ifunc_resolver) + ? !ifunc_resolver + : ifunc_resolver + ? !get_alias_target ()->ifunc_resolver + : (alias && analyzed && get_alias_target ()->ifunc_resolver)) { error ("inconsistent % attribute"); error_found = true; @@ -1879,6 +1889,9 @@ symtab_node::resolve_alias (symtab_node *target, bool transparent) if (target->implicit_section) call_for_symbol_and_aliases (set_implicit_section, NULL, true); + if (target->ifunc_resolver && !ifunc_resolver) + set_ifunc_resolver (); + /* Alias targets become redundant after alias is resolved into an reference. We do not want to keep it around or we would have to mind updating them when renaming symbols. */ diff --git a/gcc/varasm.cc b/gcc/varasm.cc index 6ae35edc5aed9..c6aa7c1745d49 100644 --- a/gcc/varasm.cc +++ b/gcc/varasm.cc @@ -6262,7 +6262,10 @@ do_assemble_alias (tree decl, tree target) maybe_assemble_visibility (decl); } if (TREE_CODE (decl) == FUNCTION_DECL - && cgraph_node::get (decl)->ifunc_resolver) + && cgraph_node::get (decl)->ifunc_resolver + /* Aliases to the ifunc decl will also have the ifunc_resolver + bit set, so check that this is the ifunc declaration. */ + && lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl))) { #if defined (ASM_OUTPUT_TYPE_DIRECTIVE) if (targetm.has_ifunc_p ())