Hi Richard, After differing NUM_POLY_INT_COEFFS fix for AArch64/nvptx offloading, the following minimal test:
int main() { int x; #pragma omp target map(x) x = 5; return x; } compiled with -fopenmp -foffload=nvptx-none now fails with: gcc: error: unrecognized command-line option '-m64' nvptx mkoffload: fatal error: ../install/bin/gcc returned 1 exit status compilation terminated. As mentioned in RFC email, this happens because nvptx/mkoffload.cc:compile_native passes -m64/-m32 to host compiler depending on whether offload_abi is OFFLOAD_ABI_LP64 or OFFLOAD_ABI_ILP32, and aarch64 backend doesn't recognize these options. Based on your suggestion in: https://gcc.gnu.org/pipermail/gcc/2024-July/244470.html, The attached patch generates new macro HOST_MULTILIB derived from $enable_as_accelerator_for, and in mkoffload.cc it gates passing -m32/-m64 to host_compiler on HOST_MULTILIB. I verified that the macro is set to 0 for aarch64 host (and thus avoids above unrecognized command line option error), and is set to 1 for x86_64 host. Does the patch look OK ? Signed-off-by: Prathamesh Kulkarni <prathame...@nvidia.com> Thanks, Prathamesh
[nvptx] Pass -m32/-m64 to host_compiler if it has multilib support. gcc/ChangeLog: * configure.ac: Generate new macro HOST_MULTILIB. * config.in: Regenerate. * configure: Likewise. * config/nvptx/mkoffload.cc (compile_native): Gate appending "-m32"/"-m64" to argv_obstack on HOST_MULTILIB. (main): Likewise. Signed-off-by: Prathamesh Kulkarni <prathame...@nvidia.com> diff --git a/gcc/config.in b/gcc/config.in index 7fcabbe5061..3c509356f0a 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -2270,6 +2270,12 @@ #endif +/* Define if host has multilib support. */ +#ifndef USED_FOR_TARGET +#undef HOST_MULTILIB +#endif + + /* Define which stat syscall is able to handle 64bit indodes. */ #ifndef USED_FOR_TARGET #undef HOST_STAT_FOR_64BIT_INODES diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc index 503b1abcefd..f7d29bd5215 100644 --- a/gcc/config/nvptx/mkoffload.cc +++ b/gcc/config/nvptx/mkoffload.cc @@ -607,17 +607,18 @@ compile_native (const char *infile, const char *outfile, const char *compiler, obstack_ptr_grow (&argv_obstack, ptx_dumpbase); obstack_ptr_grow (&argv_obstack, "-dumpbase-ext"); obstack_ptr_grow (&argv_obstack, ".c"); - switch (offload_abi) - { - case OFFLOAD_ABI_LP64: - obstack_ptr_grow (&argv_obstack, "-m64"); - break; - case OFFLOAD_ABI_ILP32: - obstack_ptr_grow (&argv_obstack, "-m32"); - break; - default: - gcc_unreachable (); - } + if (HOST_MULTILIB) + switch (offload_abi) + { + case OFFLOAD_ABI_LP64: + obstack_ptr_grow (&argv_obstack, "-m64"); + break; + case OFFLOAD_ABI_ILP32: + obstack_ptr_grow (&argv_obstack, "-m32"); + break; + default: + gcc_unreachable (); + } obstack_ptr_grow (&argv_obstack, infile); obstack_ptr_grow (&argv_obstack, "-c"); obstack_ptr_grow (&argv_obstack, "-o"); @@ -761,17 +762,18 @@ main (int argc, char **argv) if (verbose) obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-xlto"); - switch (offload_abi) - { - case OFFLOAD_ABI_LP64: - obstack_ptr_grow (&argv_obstack, "-m64"); - break; - case OFFLOAD_ABI_ILP32: - obstack_ptr_grow (&argv_obstack, "-m32"); - break; - default: - gcc_unreachable (); - } + if (HOST_MULTILIB) + switch (offload_abi) + { + case OFFLOAD_ABI_LP64: + obstack_ptr_grow (&argv_obstack, "-m64"); + break; + case OFFLOAD_ABI_ILP32: + obstack_ptr_grow (&argv_obstack, "-m32"); + break; + default: + gcc_unreachable (); + } if (fopenmp) obstack_ptr_grow (&argv_obstack, "-mgomp"); diff --git a/gcc/configure b/gcc/configure index 557ea5fa3ac..cdfa06f0c80 100755 --- a/gcc/configure +++ b/gcc/configure @@ -931,6 +931,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -1115,6 +1116,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE}' @@ -1367,6 +1369,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1504,7 +1515,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1657,6 +1668,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -6227,7 +6239,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -6273,7 +6285,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -6297,7 +6309,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -6342,7 +6354,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -6366,7 +6378,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -8308,6 +8320,21 @@ $as_echo "#define ACCEL_COMPILER 1" >>confdefs.h program_transform_name=`echo $program_transform_name | sed $sedscript` accel_dir_suffix=/accel/${target_noncanonical} real_target_noncanonical=${enable_as_accelerator_for} + + case $real_target_noncanonical in + aarch64*) + host_multilib=0 + ;; + *) + host_multilib=1 + ;; + esac + + +cat >>confdefs.h <<_ACEOF +#define HOST_MULTILIB $host_multilib +_ACEOF + fi @@ -21406,7 +21433,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21409 "configure" +#line 21436 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -21512,7 +21539,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21515 "configure" +#line 21542 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/gcc/configure.ac b/gcc/configure.ac index eaa01d0d7e5..c20646c2f80 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -1153,6 +1153,18 @@ if test x"$enable_as_accelerator_for" != x; then program_transform_name=`echo $program_transform_name | sed $sedscript` accel_dir_suffix=/accel/${target_noncanonical} real_target_noncanonical=${enable_as_accelerator_for} + + case $real_target_noncanonical in + aarch64*) + host_multilib=0 + ;; + *) + host_multilib=1 + ;; + esac + + AC_DEFINE_UNQUOTED(HOST_MULTILIB, $host_multilib, + [Define if host has multilib support.]) fi AC_SUBST(enable_as_accelerator) AC_SUBST(real_target_noncanonical)