From: Thomas Schwinge Date: Tue, 19 Jul 2022 13:42:17 +0000 (+0200) Subject: driver: Forward '-lstdc++' to offloading compilation [PR101544] X-Git-Tag: basepoints/gcc-16~623 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b36e96b575b493a21510c877b273608113108ed;p=thirdparty%2Fgcc.git driver: Forward '-lstdc++' to offloading compilation [PR101544] ..., so that users don't manually need to specify '-foffload-options=-lstdc++' in addition to '-lstdc++' (specified manually, or implicitly by the driver). Do like commit 4bcb46b3ade1796c5a57b294f5cca25f00671cac "driver: Forward '-lgfortran', '-lm' to offloading compilation". PR driver/101544 gcc/ * gcc.cc (driver_handle_option): Forward host '-lstdc++' to offloading compilation. * config/gcn/mkoffload.cc (main): Adjust. * config/nvptx/mkoffload.cc (main): Likewise. libgomp/ * testsuite/libgomp.c++/pr101544-1-O0.C: Remove '-foffload-options=-lstdc++'. * testsuite/libgomp.c++/pr101544-1.C: Likewise. * testsuite/libgomp.oacc-c++/pr101544-1.C: Likewise. --- diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index fbd68a6cd8c..f5b89c9fee7 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -1070,7 +1070,8 @@ main (int argc, char **argv) #undef STR /* Translate host into offloading libraries. */ else if (strcmp (argv[i], "-l_GCC_gfortran") == 0 - || strcmp (argv[i], "-l_GCC_m") == 0) + || strcmp (argv[i], "-l_GCC_m") == 0 + || strcmp (argv[i], "-l_GCC_stdc++") == 0) { /* Elide '_GCC_'. */ size_t i_dst = strlen ("-l"); diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc index 958e16f3918..bdfe7f58b16 100644 --- a/gcc/config/nvptx/mkoffload.cc +++ b/gcc/config/nvptx/mkoffload.cc @@ -741,7 +741,8 @@ main (int argc, char **argv) dumppfx = argv[++i]; /* Translate host into offloading libraries. */ else if (strcmp (argv[i], "-l_GCC_gfortran") == 0 - || strcmp (argv[i], "-l_GCC_m") == 0) + || strcmp (argv[i], "-l_GCC_m") == 0 + || strcmp (argv[i], "-l_GCC_stdc++") == 0) { /* Elide '_GCC_'. */ size_t i_dst = strlen ("-l"); diff --git a/gcc/gcc.cc b/gcc/gcc.cc index c7b2aa6df16..3edd21fb09e 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -4154,7 +4154,8 @@ forward_offload_option (size_t opt_index, const char *arg, bool validated) are injected by default in offloading compilation, and therefore not forwarded here. */ /* GCC libraries. */ - if (/* '-lgfortran' */ strcmp (arg, "gfortran") == 0 ) + if (/* '-lgfortran' */ strcmp (arg, "gfortran") == 0 + || /* '-lstdc++' */ strcmp (arg, "stdc++") == 0) save_switch (concat ("-foffload-options=-l_GCC_", arg, NULL), 0, NULL, validated, true); /* Other libraries. */ diff --git a/libgomp/testsuite/libgomp.c++/pr101544-1-O0.C b/libgomp/testsuite/libgomp.c++/pr101544-1-O0.C index 19a8cad2328..c8a73dcfa19 100644 --- a/libgomp/testsuite/libgomp.c++/pr101544-1-O0.C +++ b/libgomp/testsuite/libgomp.c++/pr101544-1-O0.C @@ -1,4 +1,3 @@ -// { dg-additional-options -foffload-options=-lstdc++ } // { dg-additional-options -O0 } #include "pr101544-1.C" diff --git a/libgomp/testsuite/libgomp.c++/pr101544-1.C b/libgomp/testsuite/libgomp.c++/pr101544-1.C index 8ea70a242bc..fcd3e970bd8 100644 --- a/libgomp/testsuite/libgomp.c++/pr101544-1.C +++ b/libgomp/testsuite/libgomp.c++/pr101544-1.C @@ -1,4 +1,3 @@ -// { dg-additional-options -foffload-options=-lstdc++ } // See also '../libgomp.oacc-c++/pr101544-1.C'. #ifndef ALWAYS_INLINE # define ALWAYS_INLINE diff --git a/libgomp/testsuite/libgomp.oacc-c++/pr101544-1.C b/libgomp/testsuite/libgomp.oacc-c++/pr101544-1.C index 004cd49353b..d4d28a61159 100644 --- a/libgomp/testsuite/libgomp.oacc-c++/pr101544-1.C +++ b/libgomp/testsuite/libgomp.oacc-c++/pr101544-1.C @@ -1,4 +1,3 @@ -// { dg-additional-options -foffload-options=-lstdc++ } // { dg-additional-options -fno-inline } for stable results regarding OpenACC 'routine'. // But actually, as none of the '#pragma acc routine' syntax is accepted, force inlining: #define ALWAYS_INLINE __attribute__((always_inline))