]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
nvptx: Gracefully handle '-mptx=3.1' if neither sm_30 nor sm_35 multilib variant...
authorThomas Schwinge <tschwinge@baylibre.com>
Fri, 17 Jan 2025 20:45:42 +0000 (21:45 +0100)
committerThomas Schwinge <tschwinge@baylibre.com>
Mon, 20 Jan 2025 11:04:06 +0000 (12:04 +0100)
For example, for GCC/nvptx built with '--with-arch=sm_52' (current default)
and '--without-multilib-list', neither a sm_30 nor a sm_35 multilib variant
is built, and thus no '-mptx=3.1' sub-variant either.  Such a configuration
is possible as of commit 86b3a7532d56f74fcd1c362f2da7f95e8cc4e4a6
"nvptx: Support '--with-multilib-list'", but currently results in the
following bogus behavior:

    [...]/xgcc -print-multi-directory -mgomp -march=sm_52
    mgomp
    [...]/xgcc -print-multi-directory -mgomp -march=sm_35
    mgomp
    [...]/xgcc -print-multi-directory -mgomp -march=sm_30
    mgomp
    [...]/xgcc -print-multi-directory -mgomp -march=sm_35 -mptx=3.1
    .
    [...]/xgcc -print-multi-directory -mgomp -march=sm_30 -mptx=3.1
    .

The latter two '.' are unexpected; linking OpenMP/nvptx offloading code
like this fails with: 'unresolved symbol __nvptx_uni', for example.
Instead of '.', the latter two should print 'mgomp', too.  To achieve that,
we must not set up the '-mptx=3.1' multilib axis if no '-mptx=3.1'
sub-variant is built.

gcc/
* config/nvptx/t-nvptx (MULTILIB_OPTIONS): Don't add 'mptx=3.1' if
neither sm_30 nor sm_35 multilib variant is built.

gcc/config/nvptx/t-nvptx

index 563c7b30dab2c4739af2a7350fc9b89e51b658f8..b77f63bde8ff0f4b4c8792b8d355c19e59b9c04b 100644 (file)
@@ -66,11 +66,14 @@ MULTILIB_MATCHES += $(multilib_matches)
 # ..., and don't actually build what's the default '-misa':
 MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
 
+# Build '-mptx=3.1' sub-variants, if applicable.  Per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm':
+# only for sm_30, sm_35.
+ifneq ($(filter sm_30 sm_35,$(multilib_options_isa_list)),)
 MULTILIB_OPTIONS += mptx=3.1
-# Filter out invalid '-misa'/'-mptx=3.1' combinations; per 'nvptx-sm.def',
-# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm'
-# (that is, '-mptx=3.1' only for sm_30, sm_35 variants):
+# Filter out invalid '-misa'/'-mptx=3.1' combinations:
 MULTILIB_EXCEPTIONS += $(foreach misa,$(filter-out %=sm_30 %=sm_35,$(multilib_options_misa_list)),*$(misa)/mptx=3.1)
 # ..., and special care has to be taken if '-mptx=3.1' is invalid for the
 # default variant:
 MULTILIB_EXCEPTIONS += $(if $(filter-out sm_30 sm_35,$(multilib_options_isa_default)),mgomp/mptx=3.1 mptx=3.1)
+endif