From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id E45103856DDA for ; Fri, 12 May 2023 09:35:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E45103856DDA 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.99,269,1677571200"; d="scan'208";a="5665206" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 12 May 2023 01:35:09 -0800 IronPort-SDR: vrz5iJasWsJf3+ckREmET9K0gQwSZumGU5S8y0vedKCH5rM5g04PWB5nUZZ18uApc0HJD9FjqI bos321T8hWIkGsW7um35ThmGAMZb5aPtruQWG1BbKbCODjiQXViiKJtdgakfFygg7DNM+sNQvL G5ncZcdLzVOTNP2Ek62bvyH0MWsfnEamPg3xQ6DE3ne1cGafWpmwleicivIBEvooHZLe8016CO 1eVJ9YZy5GL+YmnmceAQDoXkmgm7rsFOcaAoAMTfS0ahnlXIS3SgBO7vBT6mZ8U2IRZ9LpwRhu 3+U= From: Thomas Schwinge To: , , Subject: Re: [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni' In-Reply-To: <20221219204007.2818567-2-thomas@codesourcery.com> References: <20221219204007.2818567-1-thomas@codesourcery.com> <20221219204007.2818567-2-thomas@codesourcery.com> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Fri, 12 May 2023 11:34:58 +0200 Message-ID: <87bkipzyd9.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,KAM_SHORT,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi! On 2022-12-19T21:40:07+0100, Thomas Schwinge wrot= e: > As I have reported to Nvidia in 2022-12-01 'NVIDIA Incident Report (38917= 04): > 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 '__nv= ptx_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 '.stati= c'" > 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)? Since my report, this had its 'Status changed [...] to "Closed - Fixed"' (2023-01-28), with comment: | [...] fix should be available in a later release. | The compiler was modified to allow duplicate declaration of extern symbol= . You will not see an error for this case. | The documentation is also being changed to reflect this new change. I've not yet verified the CUDA/'ptxas'-level fix, but I suggest to retract my GCC-level proposed change: > --- a/gcc/config/nvptx/nvptx.cc > +++ b/gcc/config/nvptx/nvptx.cc > +static bool have_softstack_decl; > +static bool have_unisimt_decl; > @@ -2571,6 +2573,13 @@ nvptx_assemble_undefined_decl (FILE *file, const c= har *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 =3D get_identifier ("__nvptx_stacks"); > + static tree unisimt_id =3D get_identifier ("__nvptx_uni"); > + if (DECL_NAME (decl) =3D=3D softstack_id) > + have_softstack_decl =3D true; > + else if (DECL_NAME (decl) =3D=3D unisimt_id) > + have_unisimt_decl =3D true; > } > @@ -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_s= ize); > > - 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"); ..., and suggest that we instead fix up duplicate declarations in the nvptx-tools 'as', and once GCC depends on a nvptx-tools version with that addressed, we still change the test cases from "compile" to "assemble" as proposed: > --- 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)); > --- 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)); ..., but (obviously) without the following changes: > --- a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c > +++ b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c > -/* 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 } } > --- a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c > +++ b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c > -/* 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 o= f > + '__nvptx_uni', only one is emitted: > + { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];= } 1 } } Gr=C3=BC=C3=9Fe Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955