From patchwork Mon Dec 19 20:40:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 34762 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2605199wrn; Mon, 19 Dec 2022 12:41:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf4k2s4OoBnaUBqK4MQXRkOdSHy9kVwgu4TkbQSgg/j7eGiXa70j/HkKcRFXAPmCtTAht9xe X-Received: by 2002:a17:907:c586:b0:7c1:700:9c4b with SMTP id tr6-20020a170907c58600b007c107009c4bmr47529520ejc.75.1671482497226; Mon, 19 Dec 2022 12:41:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671482497; cv=none; d=google.com; s=arc-20160816; b=N3YoOhJfGTiyCKrlcnH5KnijYTO7v9jY92arxXBFTmcja86DplmuEY/giPFACOdvUz WTNOzZodVMTOmUHIjZhQA/ZzaY9YDyG4W66VLfJInx/UbPVkI5n/gYxHh7CIPrrBbYn/ kPYrjTj1WCtNRX6QnOIdpeXPJOPZ/KjwCPT6KB1zNrlKm8WZkopBoaXmpOtN94iY5znp PaSK8a8yEcZI3S5G+crCqthYG0CJa+5uX/AW2lTTbp8Wx84oPlZL6vaMFu4nfv6KD69g TtHQah+NkK26eu8O+g0pZ4mGmAo4C0z4AmdVxsEi+BdUBNKa5sp8cZ2p6wLamBizk7NV /Kvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:ironport-sdr:dmarc-filter:delivered-to; bh=NlVq0tbSaNeQ4sM9Arq0khbA3lUZsx7qqcZPoz7lKFI=; b=A0l1IoRfSo5NtCcV/DVgRZzkU4TQtNmrEkzxoXsBJ7fTTNbCDO4qi0D5B0RbsnlbYQ FLOBTsRKWXGK/6JC5zmHeFAfvfCVv0kLRCBx0faqKLehL4Hi4WtRxKNM8gIoEMxL4iL7 Onc20bx+p63onf9UR7bKeWZsIjVSx0WEfpE7GOcH7vdMJFRHYQXB6up9GY0BWdMV5u6v obSQcfr36uhZOvtfvJz/KAs9GL0Egh1ooIbMfuHfbN6xMBoCYhDJNKtUst/Zob509/yM 0XTdWjhE3dP2y+So50LU5kwRAAAQ/rnlqvcpxo7/Lr+4qZLrL3tVIIOQ3xOaGbToUHW2 POBw== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id lh5-20020a170906f8c500b007c0e7a8af31si8144274ejb.939.2022.12.19.12.41.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 12:41:37 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 429813850F29 for ; Mon, 19 Dec 2022 20:40:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 057BC385840E for ; Mon, 19 Dec 2022 20:40:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 057BC385840E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.96,257,1665475200"; d="scan'208";a="90850154" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 19 Dec 2022 12:40:30 -0800 IronPort-SDR: 8K+nfYAFQj39pgfK61zjrXH//642HQvBluqMRJ3tdNeikUyjCYrDQn7jC9/30PVojHExmtO3wT v4bc+WE++wG+CQuaI5bap1QG4fFNjKdGEEWGCRkcQv+dMq73OmIKT7I5lSsITHpnUMim1odN0o m/NKICXnEeZSfECu8KnvcszMyINxsqdlUrz9JcEkzgKMjkmkYH2qF/WBvkPArwaytK7nxb2M/q 8w2whD0Dnfsk+pqond+G9/FUEe0r6DsZ67L320sxZhN6pqbYzOFyNITfO8HzZsNX1GHW9YDo/Y 0N8= From: Thomas Schwinge To: , , CC: Thomas Schwinge Subject: [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni' Date: Mon, 19 Dec 2022 21:40:07 +0100 Message-ID: <20221219204007.2818567-2-thomas@codesourcery.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221219204007.2818567-1-thomas@codesourcery.com> References: <20221219204007.2818567-1-thomas@codesourcery.com> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-15.mgc.mentorg.com (139.181.222.15) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP 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.29 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752676431210409448?= X-GMAIL-MSGID: =?utf-8?q?1752676431210409448?= As I have reported to Nvidia in 2022-12-01 'NVIDIA Incident Report (3891704): ptxas: Duplicate declaration error: "cannot be resolved by a '.static'"', 'ptxas' has an inscrutable error mode for duplicate declarations: ptxas softstack-decl-1.o, line 11; error : '.extern' variable '__nvptx_stacks' cannot be resolved by a '.static' ptxas fatal : Ptx assembly aborted due to errors nvptx-as: ptxas returned 255 exit status ptxas uniform-simt-decl-1.o, line 12; error : '.extern' variable '__nvptx_uni' cannot be resolved by a '.static' ptxas fatal : Ptx assembly aborted due to errors nvptx-as: ptxas returned 255 exit status This is inscrutable, because (a) what is "cannot be resolved by a '.static'" supposed to tell me (there is no '.static' in PTX?), and (b) why arent't repeated declaration just verified to match the first, but otherwise a no-op (like in other programming languages)? gcc/ * config/nvptx/nvptx.cc (nvptx_assemble_undefined_decl): Notice '__nvptx_stacks', '__nvptx_uni' declarations. (nvptx_file_end): Don't emit duplicate declarations for those. gcc/testsuite/ * gcc.target/nvptx/softstack-decl-1.c: Make 'dg-do assemble', adjust. * gcc.target/nvptx/uniform-simt-decl-1.c: Likewise. --- gcc/config/nvptx/nvptx.cc | 14 ++++++++++++-- gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c | 8 ++++---- .../gcc.target/nvptx/uniform-simt-decl-1.c | 8 ++++---- 3 files changed, 20 insertions(+), 10 deletions(-) -- 2.25.1 ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc index 8e49dd9c647..b93a253ab31 100644 --- a/gcc/config/nvptx/nvptx.cc +++ b/gcc/config/nvptx/nvptx.cc @@ -180,9 +180,11 @@ static GTY(()) tree global_lock_var; /* True if any function references __nvptx_stacks. */ static bool need_softstack_decl; +static bool have_softstack_decl; /* True if any function references __nvptx_uni. */ static bool need_unisimt_decl; +static bool have_unisimt_decl; static int nvptx_mach_max_workers (); @@ -2571,6 +2573,13 @@ nvptx_assemble_undefined_decl (FILE *file, const char *name, const_tree decl) TREE_TYPE (decl), size ? tree_to_shwi (size) : 0, DECL_ALIGN (decl), true); nvptx_assemble_decl_end (); + + static tree softstack_id = get_identifier ("__nvptx_stacks"); + static tree unisimt_id = get_identifier ("__nvptx_uni"); + if (DECL_NAME (decl) == softstack_id) + have_softstack_decl = true; + else if (DECL_NAME (decl) == unisimt_id) + have_unisimt_decl = true; } /* Output a pattern for a move instruction. */ @@ -6002,7 +6011,7 @@ nvptx_file_end (void) write_shared_buffer (asm_out_file, gang_private_shared_sym, gang_private_shared_align, gang_private_shared_size); - if (need_softstack_decl) + if (need_softstack_decl && !have_softstack_decl) { write_var_marker (asm_out_file, false, true, "__nvptx_stacks"); /* 32 is the maximum number of warps in a block. Even though it's an @@ -6011,7 +6020,8 @@ nvptx_file_end (void) fprintf (asm_out_file, ".extern .shared .u%d __nvptx_stacks[32];\n", POINTER_SIZE); } - if (need_unisimt_decl) + + if (need_unisimt_decl && !have_unisimt_decl) { write_var_marker (asm_out_file, false, true, "__nvptx_uni"); fprintf (asm_out_file, ".extern .shared .u32 __nvptx_uni[32];\n"); diff --git a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c index c502eacc1b3..2415f6adb1f 100644 --- a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c +++ b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c @@ -1,4 +1,4 @@ -/* { dg-do compile } */ +/* { dg-do assemble } */ /* { dg-options {-save-temps -O0 -msoft-stack} } */ extern void *__nvptx_stacks[32] __attribute__((shared,nocommon)); @@ -14,7 +14,7 @@ void *f() return stack_array[5]; } -/* The implicit (via 'need_softstack_decl') and explicit declarations of - '__nvptx_stacks' are both emitted: - { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 2 } } +/* Of the implicit (via 'need_softstack_decl') and explicit declarations of + '__nvptx_stacks', only one is emitted: + { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 1 } } */ diff --git a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c index 486456ab243..5a975bdb269 100644 --- a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c +++ b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c @@ -1,4 +1,4 @@ -/* { dg-do compile } */ +/* { dg-do assemble } */ /* { dg-options {-save-temps -O0 -muniform-simt} } */ extern unsigned __nvptx_uni[32] __attribute__((shared,nocommon)); @@ -23,7 +23,7 @@ int f (void) MEMMODEL_RELAXED); } -/* The implicit (via 'need_unisimt_decl') and explicit declarations of - '__nvptx_uni' are both emitted: - { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 2 } } +/* Of the implicit (via 'need_unisimt_decl') and explicit declarations of + '__nvptx_uni', only one is emitted: + { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 1 } } */