Actually working patch attached.

As mentioned, just using TREE_PUBLIC in input_offload_tables
works for functions but for variables this gets overridden.

The externally_visible is set to avoid running into the
promote_symbol code (→ visibility hidden) later in the
function.

On 9/23/20 5:47 PM, Tobias Burnus wrote:
...
On 9/23/20 4:23 PM, Tobias Burnus wrote:
On 9/23/20 3:10 PM, Richard Biener wrote:

On Wed, 23 Sep 2020, Richard Biener wrote:
LTRANS usually makes the symbols hidden, not local.
Could also be – whatever the 'nm' output means.
So are you
sure this isn't a target bug (hidden symbols not implemented
but the host compiler obviously having checked that but assuming
the target behaves the same as the host) or a linker bug?

Unlikely, I assume the Linux x86-64 linker is rather well tested.
As written this is the host – just the offloading symbol table is
device specific.

See lto/lto-partition.c:promote_symbol btw.

Thanks for the pointer; it pointed me to node->externally_visible,

...

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
LTO: Force externally_visible+tree_public for offload_vars/funcs (PR97179)

gcc/ChangeLog:

	PR lto/97179
	* lto-cgraph.c (input_offload_tables):

diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c
index 8e0488a..52f4811 100644
--- a/gcc/lto/lto-partition.c
+++ b/gcc/lto/lto-partition.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ipa-fnsummary.h"
 #include "lto-partition.h"
 #include "sreal.h"
+#include "omp-offload.h"  /* For offload_funcs and offload_vars.  */
 
 vec<ltrans_partition> ltrans_partitions;
 
@@ -1120,6 +1121,7 @@ void
 lto_promote_cross_file_statics (void)
 {
   unsigned i, n_sets;
+  tree decl;
 
   gcc_assert (flag_wpa);
 
@@ -1135,6 +1137,20 @@ lto_promote_cross_file_statics (void)
       part->encoder = compute_ltrans_boundary (part->encoder);
     }
 
+  /* Ensure that all offload table referenced vars/funcs are available. */
+  if (offload_funcs)
+    FOR_EACH_VEC_ELT (*offload_funcs, i, decl)
+      {
+	cgraph_node::get (decl)->externally_visible = 1;
+	TREE_PUBLIC (decl) = 1;
+      }
+  if (offload_vars)
+    FOR_EACH_VEC_ELT (*offload_vars, i, decl)
+      {
+	varpool_node::get (decl)->externally_visible = 1;
+	TREE_PUBLIC (decl) = 1;
+      }
+
   lto_clone_numbers = new hash_map<const char *, unsigned>;
 
   /* Look at boundaries and promote symbols as needed.  */

Reply via email to