As found out by Jeremy, compiling with -save-temps failed when using a --dumpdir which is neither the current directory nor an absolute pathname. By default, the dumpdir is the output directory, i.e. '-save-temps -o out/myprog' will use 'out/' and trigger the issue, which looks like:
$ gcc -fopenmp foo.c -save-temps -o out/a.out --dumpdir our/ our/xamdgcn-amdhsa.c:21:8: fatal error: our/xamdgcn-amdhsa.mkoffload.hsaco: No such file or directory 21 | #embed "our/xamdgcn-amdhsa.mkoffload.hsaco" if_empty (error_file_is_empty) The problem is that 'our/xamdgcn-amdhsa.c' is already in the dump directory - and not in a "our/" subdirectory of it. Solution: use the basename for #embed, which is what the attached patch does. OK for mainline? How about backporting to GCC 16? Tobias
gcn/mkoffload: Fix -save-temps with dump-dir/output dir other than CWD When compiling for offloading with -save-temps, the device-side object file is created in the --dumpdir directory (defaulting to the output directory of the binary). This object file is included in a host-side C file using #embed. Before this commit, the object file name was used for #embed as is - such that the dumpdir directory name appeared in the #embed file name, which failed as the host C file was already in that directory (except for CWD or for an absolute pathname). Solution: Use lbasename on the file name for the #embed file name. Co-authored-by: Jeremy Robinson <[email protected]> gcc/ChangeLog: * config/gcn/mkoffload.cc (process_obj): Use lbasename on the gcn_o_name file name. gcc/config/gcn/mkoffload.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 1fb58683778..b3b9c30c7c9 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -740,7 +740,7 @@ process_obj (const char *fname_in, FILE *cfile, uint32_t omp_requires) fprintf (cfile, "static unsigned char gcn_code[] = {\n" "#embed \"%s\" if_empty (error_file_is_empty)\n" - "};\n\n", fname_in); + "};\n\n", lbasename (fname_in)); fprintf (cfile, "static const struct gcn_image {\n"
