From 9fff0be2f849b84e4c427bdd7a4716158b80a511 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Fri, 7 Jun 2024 10:14:23 +0200 Subject: [PATCH] go: Fix gccgo -v on Solaris with ld The Go testsuite's go.sum file ends in Couldn't determine version of /var/gcc/regression/master/11.4-gcc-64/build/gcc/gccgo on Solaris. It turns out this happens because gccgo -v is confused: [...] gcc version 15.0.0 20240531 (experimental) [master a0d60660f2aae2d79685f73d568facb2397582d8] (GCC) COMPILER_PATH=./:/usr/ccs/bin/ LIBRARY_PATH=./:/lib/amd64/:/usr/lib/amd64/:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-g1' '-B' './' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.' ./collect2 -V -M ./libgcc-unwind.map -Qy /usr/lib/amd64/crt1.o ./crtp.o /usr/lib/amd64/crti.o /usr/lib/amd64/values-Xa.o /usr/lib/amd64/values-xpg6.o ./crtbegin.o -L. -L/lib/amd64 -L/usr/lib/amd64 -t -lgcc_s -lgcc -lc -lgcc_s -lgcc ./crtend.o /usr/lib/amd64/crtn.o ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.3297 Undefined first referenced symbol in file main /usr/lib/amd64/crt1.o ld: fatal: symbol referencing errors collect2: error: ld returned 1 exit status trying to invoke the linker without adding any object file. This only happens when Solaris ld is in use. gccgo passes -t to the linker in that case, but does it unconditionally, even with -v. When configured to use GNU ld, gccgo -v is fine instead. This patch avoids this by restricting the -t to actually linking. Tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11 (ld and gld). 2024-06-05 Rainer Orth gcc/go: * gospec.cc (lang_specific_driver) [TARGET_SOLARIS !USE_GLD]: Only add -t if linking. --- gcc/go/gospec.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/go/gospec.cc b/gcc/go/gospec.cc index b866d47a942..a3da23dfa3a 100644 --- a/gcc/go/gospec.cc +++ b/gcc/go/gospec.cc @@ -443,8 +443,11 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, using the GNU linker, the Solaris linker needs an option to not warn about this. Everything works without this option, but you get unsightly warnings at link time. */ - generate_option (OPT_Wl_, "-t", 1, CL_DRIVER, &new_decoded_options[j]); - j++; + if (library > 0) + { + generate_option (OPT_Wl_, "-t", 1, CL_DRIVER, &new_decoded_options[j]); + j++; + } #endif *in_decoded_options_count = j;