diff mbox

[testsuite] Fix linker detection in check_gc_sections_available

Message ID yddinsf32n1.fsf@CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth Oct. 26, 2016, 9:01 a.m. UTC
When testing gcc on Solaris, configured to use /usr/ccs/bin/ld, but with
/usr/gnu/bin/ld in PATH, the gcsec* tests are FAILing:

FAIL: g++.dg/eh/gcsec1.C  -std=gnu++11 (test for excess errors)
WARNING: g++.dg/eh/gcsec1.C  -std=gnu++11 compilation failed to produce executable
FAIL: g++.dg/eh/gcsec1.C  -std=gnu++14 (test for excess errors)
WARNING: g++.dg/eh/gcsec1.C  -std=gnu++14 compilation failed to produce executable
FAIL: g++.dg/eh/gcsec1.C  -std=gnu++98 (test for excess errors)
WARNING: g++.dg/eh/gcsec1.C  -std=gnu++98 compilation failed to produce executable

Excess errors:
ld: fatal: unrecognized option '--'
ld: fatal: use the '-z help' option for usage information

It turned out that gcc/testsuite/lib/target-supports.exp
(check_gc_sections_available) has a strange way of finding the
configured linker:

        # Check if the ld used by gcc supports --gc-sections.
        set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
        regsub ".*\n\\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker

On Solaris, collect2 is used here:

*linker:
collect2

thus

        set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]

gcc -print-prog-name=collect2
collect2

        set ld_output [remote_exec host "$gcc_ld" "--help"]

Here, collect2 uses PATH to find ld, despite the compiler default.  It
turns out that either COMPILER_PATH is used to locate the program, which
is set by gcc to include /usr/ccs/bin early, but not when collect2 is
invoked directly, in which case it falls back to searching PATH.

With GNU ld, --gc-sections support is found

        if { [ string first "--gc-sections" $ld_output ] >= 0 } {
            set gc_sections_available_saved 1

but the compiler proper invokes /usr/ccs/bin/ld instead, leading to the
observed failures.

Some digging discovered that this strange way was introduced in r87040
for NetWare support, but not mentioned in ChangeLog:

------------------------------------------------------------------------
r87040 | rth | 2004-09-03 20:10:08 +0200 (Fri, 03 Sep 2004) | 55 lines
[...]
gcc/testsuite/
[...]
        * lib/target-supports.exp (check_visibility_available): Exclude
        NetWare.

Since NetWare support is long gone and many other places in the compiler
(like configure scripts) use the expected (and working)
-print-prog-name=ld instead, this seems to be the way to go.  This is
what the following patch does, which fixes the spurious failures on
i386-pc-solaris2.12 and sparc-sun-solaris2.12.  I plan to apply it to
all active branches after more widespread testing, unless Mike (or
someone else) finds fault with my argument.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2016-10-25  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* lib/target-supports.exp (check_gc_sections_available): Use
	-print-prog-name=ld to determine linker used.
diff mbox

Patch

# HG changeset patch
# Parent  fc195b51be36e044b45302ca1e60063a57ad6060
Fix linker detection in check_gc_sections_available

diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -462,9 +462,7 @@  proc check_gc_sections_available { } {
 	}
 
 	# Check if the ld used by gcc supports --gc-sections.
-	set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
-	regsub ".*\n\\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
-	set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
+	set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=ld" "" "none" ""] 0]
 	set ld_output [remote_exec host "$gcc_ld" "--help"]
 	if { [ string first "--gc-sections" $ld_output ] >= 0 } {
 	    set gc_sections_available_saved 1