https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104416
Bug ID: 104416
Summary: 'lto-wrapper' invoking 'mkoffload's with duplicated
command-line options
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: other
Assignee: unassigned at gcc dot gnu.org
Reporter: tschwinge at gcc dot gnu.org
CC: jakub at gcc dot gnu.org
Target Milestone: ---
If you compile offloading code for example with
'-foffload=nvptx-none=-Wl,foo.o\ -Wl,bar.o' where these '*.o' files intend to
override things from GCC target libraries, you'll get duplicate symbols errors
(at run time in case of nvptx offloading). The reason is these options end up
twice on the nvptx offloading compilation command line.
Per '-v -save-temps', we see the 'lto-wrapper' invoke '[...]/mkoffload
@./a.offload_args', and 'a.offload_args' ends with:
[...]
-dumpbase
./a.xnvptx-none
-Wl,foo.o
-Wl,bar.o
-Wl,foo.o
-Wl,bar.o
That's (I suppose) not a problem for flags (because even if a later one
overrides an earlier, the same then happens again for the duplicated set of
flags), but it may be problematic for other options, as per above.
These command-line options are built in
'gcc/lto-wrapper.cc:compile_offload_image':
[...]
obstack_ptr_grow (&argv_obstack, "-dumpbase");
obstack_ptr_grow (&argv_obstack, dumpbase);
/* Append options specified by -foffload last. In case of conflicting
options we expect offload compiler to choose the latest. */
append_offload_options (&argv_obstack, target, compiler_opts);
append_offload_options (&argv_obstack, target, linker_opts);
obstack_ptr_grow (&argv_obstack, NULL);
argv = XOBFINISH (&argv_obstack, char **);
fork_execute (argv[0], argv, true, "offload_args");
[...]
I have not yet looked into 'compiler_opts', 'linker_opts'.
Per a quick check, this problem also exists for GCC 11, 10, 9, 8.