https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97179
Bug ID: 97179 Summary: [LTO][Offloading] LTO's ltrans partiitioning causes link errors for offload_vars + offload_funcs ("undefined reference") Product: gcc Version: 11.0 Status: UNCONFIRMED Keywords: openmp Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org CC: jakub at gcc dot gnu.org, marxin at gcc dot gnu.org Target Milestone: --- Offloading creates two tables – which always have to be output (force_output = 1) and have to match between host and offloading device. The table contains function/variable pointers. When compiling a larger offloading project with -flto, the host code gets partitioned at the WPA stage. This can cause that the offload tables .gnu.offload_vars .gnu.offload_funcs end up in, e.g., a.ltrans0.o — While the function/variable ends up in, e.g., a.ltrans1.o This gives errors such as: ./a.ltrans0.ltrans.o:(.gnu.offload_vars+0x4a0): undefined reference to `yycon2' and nm shows for a.ltrans0.ltrans.o U yycon2 and for a.ltrans1.ltrans.o 0000000000003e58 b yycon2 Likewise for functions ("U" and "t" instead of "T"). Solution: * Either make it visible for cross-file linkage * or place all in the same ltrans partition. For functions – but not for variables – the following patch helps: --- a/gcc/lto-cgraph.c +++ b/gcc/lto-cgraph.c @@ -1793,6 +1794,9 @@ input_offload_tables (bool do_force_output) LTO mode. */ if (do_force_output) cgraph_node::get (fn_decl)->mark_force_output (); + /* ltrans might partition those such that they are in different + partions; to avoid link errors mark them as public. */ + TREE_PUBLIC (fn_decl) = 1; } else if (tag == LTO_symtab_variable) {