From patchwork Thu Sep 5 12:44:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 1981234 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=wdbsuTBz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WzzbL4Q4tz1yfv for ; Thu, 5 Sep 2024 22:45:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7667E384C2C4 for ; Thu, 5 Sep 2024 12:45:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 4FCDF385843B for ; Thu, 5 Sep 2024 12:44:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FCDF385843B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4FCDF385843B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725540276; cv=none; b=WxHEzA6Miw2LJsOLK4C2shBsg/mcOo/4gxUdmR7G9ChJPEspqRX6O75w4QvYDxrAu8YVT4T5L2y9+P7we/7NnH0Rs2PH3x4gidjVAW7cHMhbDmDtQPziM9cGuCpshJla1u/VUuZOJE3zslAo/gvrCgtpS8suyR8roUGCBLCz86M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725540276; c=relaxed/simple; bh=XRNLZBPSQYvcExuGYk4GqwYJNZImQhj3I8yVg+MLF0Y=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=m0ATN9zrJajK0qxq3LxRubp3isA5F/O+rIQn/cAFL6h6SKJr3IoMNsJrFbEvpHIpCPuuHaX6ULbE/45pQFH5E9DLDDmzIhz4vFDe3ZYIvpsfFH/nayuX+LOetM3HwAPIahcA0cZeWrzk5+5y/vEJnMZFqcXjG3GHtQByUQJYi9I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-374c1120a32so419307f8f.1 for ; Thu, 05 Sep 2024 05:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725540272; x=1726145072; darn=gcc.gnu.org; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:to:from:from:to:cc:subject:date:message-id:reply-to; bh=y8eg9hN6n+oA+tyU/5CF1Stau4andvuYceHh3EAMTyc=; b=wdbsuTBz0xRDvJj2u6/JMM3a6tWyIRHc4NeCphN1lzqKUko6aLulRyJvsqOEkJcJn9 DatWl7nJG13NMXQCH/uGDSpRGvNKohMnDHLxDxYU5y2cj+exjAKN5bEDiXwKdl52lWbi tjd1hxXb0aIoWL+2xEml1+d6dapyg1AmrKW5P64wZ8sUPJ5RQWBk8f5Gyp7CqIt2cR1x 3saU7iyotEKqOTsZH3Csm33kns8X5erncekZYsOJrwd6NBxGjAdCrS5NCdUX6PqBycew H10OHPPTBztrO0u57j6hop/moq7NdwNp8Wp/idAKs4v3ag1P2mgSqaHLyQhPJPekAWlk N6OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725540272; x=1726145072; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=y8eg9hN6n+oA+tyU/5CF1Stau4andvuYceHh3EAMTyc=; b=qxSvLY46NES+oOCy7tEZoNaKClGWLBOGgdR3p+cQFuk0BHL0Hcqh+YJEhUVmpUjGu7 Leo/HYbacq1lFteW1sRAtwkuzyM1/J6TnMUgvJ9H01rCC5/fBkqNILscHqzgjs9e/Ylm 1Le4BPuvUqdhtl1dD+V5m6uTSrDaCNAg4KcovZivFklLKnGbSkLHyY6NhOeujIU9O5N3 qamURXXvBkCjuDhl6QnWezk8JMslRrbLr79hx3opB5nchd6oIRX2Uz44MgADd0C0ZQ1I NDABc+6gq8kBT9f2uoplM+nSqkuN2ofvUvRJYucjPMYtMX7lWDVa8dcLtF2FvZ6VPRGG HRAQ== X-Forwarded-Encrypted: i=1; AJvYcCWQUS62XdbZCxQpcQ/mFDMq6mBba0dIItX3MhK0mMO356IMs98klZvqDngYch/M/QNykW6dAkpL79cyPQ==@gcc.gnu.org X-Gm-Message-State: AOJu0Yzyx1vr0r8iHr5bMrQGg8v/q0KvL7knQm/ibUpSX008cRDzfnY/ /2C/SbRD7JvYCWoOgDigFwWJDahLkg1mTwtcFHr/DG6NQfKnIJ/A0Vy9s4yynr0= X-Google-Smtp-Source: AGHT+IH+ZV8N79ORq0QAJJ6fh9OT4QNwQm3d9s60WYwnr7Ayl+7hGxZnmybIUdxNSsjC21/2pKxAeA== X-Received: by 2002:a5d:5e0e:0:b0:378:80ab:9968 with SMTP id ffacd0b85a97d-37880ab9a7dmr1349831f8f.17.1725540271832; Thu, 05 Sep 2024 05:44:31 -0700 (PDT) Received: from euler.schwinge.ddns.net (p200300c8b733b9005e8fc6f38b6af531.dip0.t-ipconnect.de. [2003:c8:b733:b900:5e8f:c6f3:8b6a:f531]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-374b5e3511dsm16467959f8f.34.2024.09.05.05.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 05:44:31 -0700 (PDT) From: Thomas Schwinge To: Tom de Vries , gcc-patches@gcc.gnu.org Subject: nvptx: Emit DECL and DEF linker markers for aliases [PR104957] (was: Add 'g++.target/nvptx/alias-g++.dg_init_dtor2-1.C' (was: Enhance 'gcc.target/nvptx/alias-*.c' assembler scanning (was: [committed][nvptx] Use .alias directive for mptx >= 6.3))) In-Reply-To: <87zfomz2zr.fsf@euler.schwinge.ddns.net> References: <20220322134144.GA32400@delia.home> <875xra1dll.fsf@euler.schwinge.ddns.net> <8734me1dgt.fsf@euler.schwinge.ddns.net> <87zfomz2zr.fsf@euler.schwinge.ddns.net> User-Agent: Notmuch/0.30+8~g47a4bad (https://notmuchmail.org) Emacs/29.4 (x86_64-pc-linux-gnu) Date: Thu, 05 Sep 2024 14:44:24 +0200 Message-ID: <87wmjqz2vr.fsf@euler.schwinge.ddns.net> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! On 2024-09-05T14:42:00+0200, I wrote: > On 2024-09-05T14:39:46+0200, I wrote: >> On 2024-09-05T14:36:54+0200, I wrote: >>> On 2022-03-22T14:41:46+0100, Tom de Vries via Gcc-patches wrote: >>>> [nvptx] Use .alias directive for mptx >= 6.3 >>> >>>> --- a/gcc/config/nvptx/nvptx.cc >>>> +++ b/gcc/config/nvptx/nvptx.cc >>> >>>> @@ -968,7 +969,8 @@ static void >>>> write_fn_proto_1 (std::stringstream &s, bool is_defn, >>>> const char *name, const_tree decl) >>>> { >>>> - write_fn_marker (s, is_defn, TREE_PUBLIC (decl), name); >>>> + if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) == NULL) >>>> + write_fn_marker (s, is_defn, TREE_PUBLIC (decl), name); >>> >>> This non-emitting of DECL and DEF linker markers for aliases is >>> problematic, as I'll discuss in the following. >> >> First, to show what currently is (not) happening, I've pushed to trunk >> branch commit d0f02538494ded78cac12c63f5708a53f5a77bda >> "Enhance 'gcc.target/nvptx/alias-*.c' assembler scanning", see attached. > > Then, commit a1865fd33897bc6c6e0109df0a12ee73ce386315 > "Add 'g++.target/nvptx/alias-g++.dg_init_dtor2-1.C'", see attached, as > one representative example of C++ code where the current behavior is an > actual problem. Finally, commit 8f5aade15e595b288a2c4ec60ddde8dc80df1a80 "nvptx: Emit DECL and DEF linker markers for aliases [PR104957]", see attached, to address this issue. Grüße Thomas From 8f5aade15e595b288a2c4ec60ddde8dc80df1a80 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Wed, 17 Jul 2024 23:56:25 +0200 Subject: [PATCH] nvptx: Emit DECL and DEF linker markers for aliases [PR104957] With nvptx '-malias' enabled (as implemented in commit f8b15e177155960017ac0c5daef8780d1127f91c "[nvptx] Use .alias directive for mptx >= 6.3"), the C++ front end in certain cases does 'write_fn_proto' before an eventual 'alias' attribute has been added. In that case, we do emit (via 'write_fn_marker') a DECL linker marker, but then never emit a corresponding DEF linker marker for the alias. This causes hundreds of instances of link-time 'unresolved symbol [alias]' across the C++ test suite, which are regressions compared to a test run with (default) '-mno-alias' (in which case the respective functions get duplicated). PR target/104957 gcc/ * config/nvptx/nvptx.cc (write_fn_proto_1): Revert 2022-03-22 change; 'write_fn_marker' also for alias DECL. (nvptx_asm_output_def_from_decls): 'write_fn_marker' for alias DEF. gcc/testsuite/ * g++.target/nvptx/alias-g++.dg_init_dtor2-1.C: Un-XFAIL. * gcc.target/nvptx/alias-1.c: Likewise. * gcc.target/nvptx/alias-3.c: Likewise. * gcc.target/nvptx/alias-to-alias-1.c: Likewise. --- gcc/config/nvptx/nvptx.cc | 6 ++++-- .../g++.target/nvptx/alias-g++.dg_init_dtor2-1.C | 4 ++-- gcc/testsuite/gcc.target/nvptx/alias-1.c | 4 ++-- gcc/testsuite/gcc.target/nvptx/alias-3.c | 4 ++-- gcc/testsuite/gcc.target/nvptx/alias-to-alias-1.c | 8 ++++---- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc index 144b8d0c874..4a7c64f05eb 100644 --- a/gcc/config/nvptx/nvptx.cc +++ b/gcc/config/nvptx/nvptx.cc @@ -997,8 +997,7 @@ static void write_fn_proto_1 (std::stringstream &s, bool is_defn, const char *name, const_tree decl, bool force_public) { - if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) == NULL) - write_fn_marker (s, is_defn, TREE_PUBLIC (decl) || force_public, name); + write_fn_marker (s, is_defn, TREE_PUBLIC (decl) || force_public, name); /* PTX declaration. */ if (DECL_EXTERNAL (decl)) @@ -7627,6 +7626,9 @@ nvptx_asm_output_def_from_decls (FILE *stream, tree name, tree value) fputs (s.str ().c_str (), stream); tree id = DECL_ASSEMBLER_NAME (name); + std::stringstream s_def; + write_fn_marker (s_def, true, TREE_PUBLIC (name), IDENTIFIER_POINTER (id)); + fputs (s_def.str ().c_str (), stream); NVPTX_ASM_OUTPUT_DEF (stream, IDENTIFIER_POINTER (id), IDENTIFIER_POINTER (value)); } diff --git a/gcc/testsuite/g++.target/nvptx/alias-g++.dg_init_dtor2-1.C b/gcc/testsuite/g++.target/nvptx/alias-g++.dg_init_dtor2-1.C index 747656d51d6..a30f99af308 100644 --- a/gcc/testsuite/g++.target/nvptx/alias-g++.dg_init_dtor2-1.C +++ b/gcc/testsuite/g++.target/nvptx/alias-g++.dg_init_dtor2-1.C @@ -1,6 +1,6 @@ /* Reduced from 'g++.dg/init/dtor2.C'. */ -/* { dg-do compile } */ +/* { dg-do link } */ /* { dg-add-options nvptx_alias_ptx } */ /* { dg-additional-options -save-temps } */ /* Via the magic string "-std=*++" indicate that testing one (the default) C++ standard is sufficient. */ @@ -26,7 +26,7 @@ int main() /* { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DECL: _ZN1BD1Ev$} 1 } } { dg-final { scan-assembler-times {(?n)^\.visible \.func _ZN1BD1Ev \(\.param\.u64 %in_ar0\);$} 1 } } - { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: _ZN1BD1Ev$} 1 { xfail *-*-* } } } + { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: _ZN1BD1Ev$} 1 } } { dg-final { scan-assembler-times {(?n)^\.alias _ZN1BD1Ev,_ZN1BD2Ev;$} 1 } } */ /* { dg-final { scan-assembler-times {(?n)\tcall _ZN1BD1Ev, \(} 1 } } diff --git a/gcc/testsuite/gcc.target/nvptx/alias-1.c b/gcc/testsuite/gcc.target/nvptx/alias-1.c index 0fb06495f67..f2aeff36e69 100644 --- a/gcc/testsuite/gcc.target/nvptx/alias-1.c +++ b/gcc/testsuite/gcc.target/nvptx/alias-1.c @@ -28,9 +28,9 @@ main (void) { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: __f$} 1 } } { dg-final { scan-assembler-times {(?n)^\.visible \.func __f$} 1 } } */ -/* { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DECL: f$} 1 { xfail *-*-* } } } +/* { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DECL: f$} 1 } } { dg-final { scan-assembler-times {(?n)^\.visible \.func f;$} 1 } } - { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: f$} 1 { xfail *-*-* } } } + { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: f$} 1 } } { dg-final { scan-assembler-times {(?n)^\.alias f,__f;$} 1 } } */ /* { dg-final { scan-assembler-times {(?n)\tcall __f;$} 0 } } diff --git a/gcc/testsuite/gcc.target/nvptx/alias-3.c b/gcc/testsuite/gcc.target/nvptx/alias-3.c index 1906607f95f..01a44e2e424 100644 --- a/gcc/testsuite/gcc.target/nvptx/alias-3.c +++ b/gcc/testsuite/gcc.target/nvptx/alias-3.c @@ -30,9 +30,9 @@ main (void) { dg-final { scan-assembler-times {(?n)^// BEGIN FUNCTION DEF: __f$} 1 } } { dg-final { scan-assembler-times {(?n)^\.func __f$} 1 } } */ -/* { dg-final { scan-assembler-times {(?n)^// BEGIN FUNCTION DECL: f$} 1 { xfail *-*-* } } } +/* { dg-final { scan-assembler-times {(?n)^// BEGIN FUNCTION DECL: f$} 1 } } { dg-final { scan-assembler-times {(?n)^\.func f;$} 1 } } - { dg-final { scan-assembler-times {(?n)^// BEGIN FUNCTION DEF: f$} 1 { xfail *-*-* } } } + { dg-final { scan-assembler-times {(?n)^// BEGIN FUNCTION DEF: f$} 1 } } { dg-final { scan-assembler-times {(?n)^\.alias f,__f;$} 1 } } */ /* { dg-final { scan-assembler-times {(?n)\tcall __f;$} 0 } } diff --git a/gcc/testsuite/gcc.target/nvptx/alias-to-alias-1.c b/gcc/testsuite/gcc.target/nvptx/alias-to-alias-1.c index ebd62e11964..7bce7a358c7 100644 --- a/gcc/testsuite/gcc.target/nvptx/alias-to-alias-1.c +++ b/gcc/testsuite/gcc.target/nvptx/alias-to-alias-1.c @@ -24,14 +24,14 @@ main (void) { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: foo$} 1 } } { dg-final { scan-assembler-times {(?n)^\.visible \.func foo$} 1 } } */ -/* { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DECL: bar$} 1 { xfail *-*-* } } } +/* { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DECL: bar$} 1 } } { dg-final { scan-assembler-times {(?n)^\.visible \.func bar;$} 1 } } - { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: bar$} 1 { xfail *-*-* } } } + { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: bar$} 1 } } { dg-final { scan-assembler-times {(?n)^\.alias bar,foo;$} 1 } } */ -/* { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DECL: baz$} 1 { xfail *-*-* } } } +/* { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DECL: baz$} 1 } } { dg-final { scan-assembler-times {(?n)^\.visible \.func baz;$} 1 } } - { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: baz$} 1 { xfail *-*-* } } } + { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: baz$} 1 } } { dg-final { scan-assembler-times {(?n)^\.alias baz,bar;$} 1 } } */ /* { dg-final { scan-assembler-times {(?n)\tcall foo;$} 0 } } -- 2.34.1