From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B8C733857818 for ; Tue, 30 Nov 2021 16:25:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B8C733857818 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-emdQgpLgNe66x-SbJGdPZw-1; Tue, 30 Nov 2021 11:25:35 -0500 X-MC-Unique: emdQgpLgNe66x-SbJGdPZw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 48CBD1B18BD8; Tue, 30 Nov 2021 16:24:54 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.188]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D1AE46060F; Tue, 30 Nov 2021 16:24:53 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1AUGOo2q2950464 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 30 Nov 2021 17:24:51 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1AUGOnrA2950463; Tue, 30 Nov 2021 17:24:49 +0100 Date: Tue, 30 Nov 2021 17:24:49 +0100 From: Jakub Jelinek To: Andrew Stubbs Cc: "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH] OpenMP: Ensure that offloaded variables are public Message-ID: <20211130162449.GP2646553@tucnak> Reply-To: Jakub Jelinek References: <6843a549-0d4d-0ca7-ae34-929a15e0fa98@codesourcery.com> MIME-Version: 1.0 In-Reply-To: <6843a549-0d4d-0ca7-ae34-929a15e0fa98@codesourcery.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Tue, 30 Nov 2021 16:25:41 -0000 On Tue, Nov 16, 2021 at 11:49:18AM +0000, Andrew Stubbs wrote: > This patch is needed for AMD GCN offloading when we use the assembler from > LLVM 13+. > > The GCN runtime (libgomp+ROCm) requires that the location of all variables > in the offloaded variables table are discoverable at runtime (using the > "hsa_executable_symbol_get_info" API), and this only works when the symbols > are exported from the binary. Previously we solved this by having mkoffload > insert ".global" directives into the assembler text, but newer LLVM > assemblers emit an error if we do this when then variable was previously > declared ".local" (which happens when a variable is zero-initialized and > placed in the BSS). > > Since we can no longer easily fix them up after the fact, this patch fixes > them up during OMP lowering. I'm confused, how can that ever work reliably? The !TREE_PUBLIC offload_vars can be static locals or static globals or static anon namespace vars, but their names can very easily clash with either static or non-static variables from other TUs. Consider in one TU static int a = 5; static int baz (void) { static int b; #pragma omp declare target to (b) return ++b; } int foo (void) { return ++a + baz (); } #pragma omp declare target to (a, foo) and static int a = 5; static int baz (void) { static int b; #pragma omp declare target to (b) return ++b; } int bar (void) { return ++a + baz (); } #pragma omp declare target to (a, bar) int main () { int v; #pragma omp target (from: v) v = foo () + bar (); } in another one. This has .quad a .quad 4 .quad b.0 .quad 4 in .offload_var_table. I'd guess this must fail to link or load with GCN if it makes them forcibly TREE_PUBLIC. Why does the GCN plugin or runtime need to know those vars? It needs to know the single array that contains their addresses of course... Jakub