Created attachment 41187 [details] dce-vs-offloading.c With "-O1" and higher, and "-fopenacc" or "-fopenmp", different passes (see below) that optimize away dead code, remove the libgomp calls to invoke the offloaded functions. But: the latter ones are still being referenced later on (have not yet worked on figuring out, why/where exactly), and then things explode: With "-foffload=disable": /tmp/ccXNDvkg.o:(.gnu.offload_funcs+0x0): undefined reference to `main._omp_fn.0' /tmp/ccXNDvkg.o:(.gnu.offload_funcs+0x8): undefined reference to `main._omp_fn.1' collect2: error: ld returned 1 exit status With "-foffload=nvptx-none": lto1: internal compiler error: Segmentation fault 0x104a7f93 crash_signal [...]/gcc/toplev.c:333 0x1037bdc8 input_offload_tables [...]/gcc/lto-cgraph.c:2024 0x1037bdc8 input_offload_data(bool) [...]/gcc/lto-cgraph.c:1932 0x1005ba93 read_cgraph_and_symbols [...]/gcc/lto/lto.c:2861 0x1005ba93 lto_main() [...]/gcc/lto/lto.c:3341 On trunk as of r246724, can use "-O2 -fno-tree-ccp -fno-tree-forwprop -fno-tree-fre -fno-tree-vrp" to make this compile/link.
They are probably referenced in the global tables we build for offloading? The symtab code isn't made aware of those references though. .offload_var_table: .section .gnu.offload_funcs,"aw",@progbits .align 8 .type .offload_func_table, @object .size .offload_func_table, 16 .offload_func_table: .quad main._omp_fn.0 .quad main._omp_fn.1 .comm __gnu_lto_v1,1,1 not sure where we emit the above.
So, do we want to force output of everything we reference from the offload tables, like untested: --- gcc/omp-offload.c.jj 2017-03-29 07:11:21.000000000 +0200 +++ gcc/omp-offload.c 2017-04-18 14:08:25.154650257 +0200 @@ -152,6 +152,11 @@ add_decls_addresses_to_decl_constructor CONSTRUCTOR_APPEND_ELT (v_ctor, NULL_TREE, addr); if (is_var) CONSTRUCTOR_APPEND_ELT (v_ctor, NULL_TREE, size); + + if (is_var) + varpool_node::get (it)->force_output = 1; + else + cgraph_node::get (it)->mark_force_output (); } } ? Note I have no idea why the cgraph/symtab code doesn't see those table ctors and figure this out from those.
Dup. *** This bug has been marked as a duplicate of bug 83046 ***