Use better test for usable compiler in ld testsuite.
authorSandra Loosemore <sandra@codesourcery.com>
Wed, 24 Apr 2019 19:14:56 +0000 (12:14 -0700)
committerSandra Loosemore <sandra@codesourcery.com>
Wed, 24 Apr 2019 19:14:56 +0000 (12:14 -0700)
The ld testsuite includes numerous tests that depend on being able to
compile and link programs with the C compiler.  Some of these tests
use [which $CC] to check for the presence of the compiler before
proceeding with the test, but run_ld_link_exec_tests and run_cc_link_tests
give ERRORs if compilation fails.  Also, even if $CC is defined and present,
it may not be usable due to missing libraries, etc.

This patch adds a new procedure check_compiler_available that attempts
to build an empty program and caches the result.  Uses of [which $CC]
are replaced with calls to this procedure, and run_ld_link_exec_tests
and run_cc_link_tests now also guard attempts to use $CC.

2019-04-24  Sandra Loosemore  <sandra@codesourcery.com>

ld/
* testsuite/config/default.exp: Use [check_compiler_available]
instead of [which $CC].
* testsuite/ld-auto-import/auto-import.exp: Likewise.
* testsuite/ld-cygwin/exe-export.exp: Likewise.
* testsuite/ld-elf/audit.exp: Likewise.
* testsuite/ld-elf/compress.exp: Likewise.
* testsuite/ld-elf/dwarf.exp: Likewise.
* testsuite/ld-elf/elf.exp: Likewise.
* testsuite/ld-elf/indirect.exp: Likewise.
* testsuite/ld-elf/linux-x86.exp: Likewise.
* testsuite/ld-elf/shared.exp: Likewise.
* testsuite/ld-elf/tls.exp: Likewise.
* testsuite/ld-elf/wrap.exp: Likewise.
* testsuite/ld-elfcomm/elfcomm.exp: Likewise.
* testsuite/ld-elfvers/vers.exp: Likewise.
* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
* testsuite/ld-elfweak/elfweak.exp: Likewise.
* testsuite/ld-gc/gc.exp: Likewise.
* testsuite/ld-i386/i386.exp: Likewise.
* testsuite/ld-i386/no-plt.exp: Likewise.
* testsuite/ld-i386/tls.exp: Likewise.
* testsuite/ld-ifunc/ifunc.exp: Likewise.
* testsuite/ld-mn10300/mn10300.exp: Likewise.
* testsuite/ld-pe/pe-compile.exp: Likewise.
* testsuite/ld-pe/pe-run.exp: Likewise.
* testsuite/ld-pe/pe-run2.exp: Likewise.
* testsuite/ld-pie/pie.exp: Likewise.
* testsuite/ld-plugin/lto.exp: Likewise.
* testsuite/ld-plugin/plugin.exp: Likewise.
* testsuite/ld-scripts/crossref.exp: Likewise.
* testsuite/ld-sh/sh.exp: Likewise.
* testsuite/ld-shared/shared.exp: Likewise.
* testsuite/ld-size/size.exp: Likewise.
* testsuite/ld-srec/srec.exp: Likewise.
* testsuite/ld-undefined/undefined.exp: Likewise.
* testsuite/ld-unique/unique.exp: Likewise.
* testsuite/ld-x86-64/mpx.exp: Likewise.
* testsuite/ld-x86-64/no-plt.exp: Likewise.
* testsuite/ld-x86-64/tls.exp: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Call
check_compiler_available before trying to use the compiler.
(run_cc_link_tests): Likewise.
(check_compiler_available): New.  Use it instead of [which $CC].

41 files changed:
ld/ChangeLog
ld/testsuite/config/default.exp
ld/testsuite/ld-auto-import/auto-import.exp
ld/testsuite/ld-cygwin/exe-export.exp
ld/testsuite/ld-elf/audit.exp
ld/testsuite/ld-elf/compress.exp
ld/testsuite/ld-elf/dwarf.exp
ld/testsuite/ld-elf/elf.exp
ld/testsuite/ld-elf/indirect.exp
ld/testsuite/ld-elf/linux-x86.exp
ld/testsuite/ld-elf/shared.exp
ld/testsuite/ld-elf/tls.exp
ld/testsuite/ld-elf/wrap.exp
ld/testsuite/ld-elfcomm/elfcomm.exp
ld/testsuite/ld-elfvers/vers.exp
ld/testsuite/ld-elfvsb/elfvsb.exp
ld/testsuite/ld-elfweak/elfweak.exp
ld/testsuite/ld-gc/gc.exp
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/no-plt.exp
ld/testsuite/ld-i386/tls.exp
ld/testsuite/ld-ifunc/ifunc.exp
ld/testsuite/ld-mn10300/mn10300.exp
ld/testsuite/ld-pe/pe-compile.exp
ld/testsuite/ld-pe/pe-run.exp
ld/testsuite/ld-pe/pe-run2.exp
ld/testsuite/ld-pie/pie.exp
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/plugin.exp
ld/testsuite/ld-scripts/crossref.exp
ld/testsuite/ld-sh/sh.exp
ld/testsuite/ld-shared/shared.exp
ld/testsuite/ld-size/size.exp
ld/testsuite/ld-srec/srec.exp
ld/testsuite/ld-undefined/undefined.exp
ld/testsuite/ld-unique/unique.exp
ld/testsuite/ld-x86-64/mpx.exp
ld/testsuite/ld-x86-64/no-plt.exp
ld/testsuite/ld-x86-64/tls.exp
ld/testsuite/ld-x86-64/x86-64.exp
ld/testsuite/lib/ld-lib.exp

index 4b4956e..a62a6c5 100644 (file)
@@ -1,3 +1,50 @@
+2019-04-24  Sandra Loosemore  <sandra@codesourcery.com>
+
+       * testsuite/config/default.exp: Use [check_compiler_available]
+       instead of [which $CC].
+       * testsuite/ld-auto-import/auto-import.exp: Likewise.
+       * testsuite/ld-cygwin/exe-export.exp: Likewise.
+       * testsuite/ld-elf/audit.exp: Likewise.
+       * testsuite/ld-elf/compress.exp: Likewise.
+       * testsuite/ld-elf/dwarf.exp: Likewise.
+       * testsuite/ld-elf/elf.exp: Likewise.
+       * testsuite/ld-elf/indirect.exp: Likewise.
+       * testsuite/ld-elf/linux-x86.exp: Likewise.
+       * testsuite/ld-elf/shared.exp: Likewise.
+       * testsuite/ld-elf/tls.exp: Likewise.
+       * testsuite/ld-elf/wrap.exp: Likewise.
+       * testsuite/ld-elfcomm/elfcomm.exp: Likewise.
+       * testsuite/ld-elfvers/vers.exp: Likewise.
+       * testsuite/ld-elfvsb/elfvsb.exp: Likewise.
+       * testsuite/ld-elfweak/elfweak.exp: Likewise.
+       * testsuite/ld-gc/gc.exp: Likewise.
+       * testsuite/ld-i386/i386.exp: Likewise.
+       * testsuite/ld-i386/no-plt.exp: Likewise.
+       * testsuite/ld-i386/tls.exp: Likewise.
+       * testsuite/ld-ifunc/ifunc.exp: Likewise.
+       * testsuite/ld-mn10300/mn10300.exp: Likewise.
+       * testsuite/ld-pe/pe-compile.exp: Likewise.
+       * testsuite/ld-pe/pe-run.exp: Likewise.
+       * testsuite/ld-pe/pe-run2.exp: Likewise.
+       * testsuite/ld-pie/pie.exp: Likewise.
+       * testsuite/ld-plugin/lto.exp: Likewise.
+       * testsuite/ld-plugin/plugin.exp: Likewise.
+       * testsuite/ld-scripts/crossref.exp: Likewise.
+       * testsuite/ld-sh/sh.exp: Likewise.
+       * testsuite/ld-shared/shared.exp: Likewise.
+       * testsuite/ld-size/size.exp: Likewise.
+       * testsuite/ld-srec/srec.exp: Likewise.
+       * testsuite/ld-undefined/undefined.exp: Likewise.
+       * testsuite/ld-unique/unique.exp: Likewise.
+       * testsuite/ld-x86-64/mpx.exp: Likewise.
+       * testsuite/ld-x86-64/no-plt.exp: Likewise.
+       * testsuite/ld-x86-64/tls.exp: Likewise.
+       * testsuite/ld-x86-64/x86-64.exp: Likewise.
+       * testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Call
+       check_compiler_available before trying to use the compiler.
+       (run_cc_link_tests): Likewise.
+       (check_compiler_available): New.  Use it instead of [which $CC].
+
 2019-04-23  Alan Modra  <amodra@gmail.com>
 
        * Makefile.am (GENDEPDIR): New var, used..
 2019-04-23  Alan Modra  <amodra@gmail.com>
 
        * Makefile.am (GENDEPDIR): New var, used..
index 5acab06..ce52919 100644 (file)
@@ -269,7 +269,7 @@ if { ![info exists LD_CLASS] } then {
 # Set PLT_CFLAGS to "-fplt" if target compiler supports it.
 
 if { ![info exists PLT_CFLAGS] } then {
 # Set PLT_CFLAGS to "-fplt" if target compiler supports it.
 
 if { ![info exists PLT_CFLAGS] } then {
-    if { [which $CC] != 0 } {
+    if { [check_compiler_available] } {
        # Check if gcc supports -fplt
        set flags ""
        if [board_info [target_info name] exists cflags] {
        # Check if gcc supports -fplt
        set flags ""
        if [board_info [target_info name] exists cflags] {
@@ -307,7 +307,7 @@ if { ![info exists PLT_CFLAGS] } then {
 # target compiler supports them.
 
 if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
 # target compiler supports them.
 
 if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
-    if { [which $CC] != 0 } {
+    if { [check_compiler_available] } {
        # Check if gcc supports -fno-PIE -no-pie.
        set flags ""
        if [board_info [target_info name] exists cflags] {
        # Check if gcc supports -fno-PIE -no-pie.
        set flags ""
        if [board_info [target_info name] exists cflags] {
@@ -347,7 +347,7 @@ if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
 # Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
 
 if { ![info exists GNU2_CFLAGS] } then {
 # Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
 
 if { ![info exists GNU2_CFLAGS] } then {
-    if { [which $CC] != 0 } {
+    if { [check_compiler_available] } {
        # Check if gcc supports -mtls-dialect=gnu2
        set flags ""
        if [board_info [target_info name] exists cflags] {
        # Check if gcc supports -mtls-dialect=gnu2
        set flags ""
        if [board_info [target_info name] exists cflags] {
@@ -384,7 +384,7 @@ if { ![info exists GNU2_CFLAGS] } then {
 # Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
 
 if { ![info exists INT128_CFLAGS] } then {
 # Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
 
 if { ![info exists INT128_CFLAGS] } then {
-    if { [which $CC] != 0 } {
+    if { [check_compiler_available] } {
        # Check if gcc supports __int128.
        set flags ""
        if [board_info [target_info name] exists cflags] {
        # Check if gcc supports __int128.
        set flags ""
        if [board_info [target_info name] exists cflags] {
@@ -421,7 +421,7 @@ if { ![info exists INT128_CFLAGS] } then {
 # Set STATIC_LDFLAGS to "-static" if target compiler supports it.
 
 if { ![info exists STATIC_LDFLAGS] } then {
 # Set STATIC_LDFLAGS to "-static" if target compiler supports it.
 
 if { ![info exists STATIC_LDFLAGS] } then {
-    if { [which $CC] != 0 } {
+    if { [check_compiler_available] } {
        # Check if gcc supports -static.
        set flags ""
        if [board_info [target_info name] exists cflags] {
        # Check if gcc supports -static.
        set flags ""
        if [board_info [target_info name] exists cflags] {
@@ -458,7 +458,7 @@ if { ![info exists STATIC_LDFLAGS] } then {
 # Set STATIC_PIE_LDFLAGS to "-static-pie" if target compiler supports it.
 
 if { ![info exists STATIC_PIE_LDFLAGS] } then {
 # Set STATIC_PIE_LDFLAGS to "-static-pie" if target compiler supports it.
 
 if { ![info exists STATIC_PIE_LDFLAGS] } then {
-    if { [which $CC] != 0 } {
+    if { [check_compiler_available] } {
        # Check if gcc supports -static-pie.
        set flags ""
        if [board_info [target_info name] exists cflags] {
        # Check if gcc supports -static-pie.
        set flags ""
        if [board_info [target_info name] exists cflags] {
index d9ac6cf..d5a0dcc 100644 (file)
@@ -67,7 +67,7 @@ if [istarget *-pc-mingw*] {
 }
 
 # No compiler, no test.
 }
 
 # No compiler, no test.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested "Auto import test (compiler not found)"
     return
 }
     untested "Auto import test (compiler not found)"
     return
 }
index 258949e..5436332 100644 (file)
@@ -29,7 +29,7 @@ if {![istarget *-pc-cygwin]} {
 }\r
 \r
 # No compiler, no test.\r
 }\r
 \r
 # No compiler, no test.\r
-if { [which $CC] == 0 } {\r
+if { ![check_compiler_available] } {\r
     untested "Exe export test (no compiler available)"\r
     return\r
 }\r
     untested "Exe export test (no compiler available)"\r
     return\r
 }\r
index 3514176..5cc044b 100644 (file)
@@ -32,7 +32,7 @@ if ![check_shared_lib_support] {
 }
 
 # Check if compiler works
 }
 
 # Check if compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 6bdc921..90b6c6e 100644 (file)
@@ -32,7 +32,7 @@ if ![check_shared_lib_support] {
 }
 
 # Check if compiler works
 }
 
 # Check if compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index bc3cbb2..233a2a8 100644 (file)
@@ -36,7 +36,7 @@ if ![check_shared_lib_support] {
 }
 
 # Check if compiler works
 }
 
 # Check if compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 4686870..9121936 100644 (file)
@@ -182,7 +182,7 @@ set LDFLAGS $old_ldflags
 set ASFLAGS $old_asflags
 
 # Check to see if the C compiler works
 set ASFLAGS $old_asflags
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index b1a2c6c..1acb556 100644 (file)
@@ -33,7 +33,7 @@ if ![check_shared_lib_support] {
 }
 
 # Check if compiler works
 }
 
 # Check if compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index b1cad61..6b0f23f 100644 (file)
@@ -20,7 +20,7 @@
 #
 
 # Test very simple native Linux/x86 programs with linux-x86.S.
 #
 
 # Test very simple native Linux/x86 programs with linux-x86.S.
-if { ![isnative] || [which $CC] == 0 \
+if { ![isnative] || ![check_compiler_available] \
      || (![istarget "i?86-*-linux*"] \
          && ![istarget "x86_64-*-linux*"] \
          && ![istarget "amd64-*-linux*"]) } {
      || (![istarget "i?86-*-linux*"] \
          && ![istarget "x86_64-*-linux*"] \
          && ![istarget "amd64-*-linux*"]) } {
index b5a01c9..f27fa24 100644 (file)
@@ -498,7 +498,7 @@ if { [istarget *-*-linux*]
 }
 
 # Check to see if the C compiler works
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 1b26f8b..4daddc7 100644 (file)
@@ -29,7 +29,7 @@ if { ![istarget *-*-linux*]
 }
 
 # Check to see if the C compiler works.
 }
 
 # Check to see if the C compiler works.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 3293231..1a9fa7c 100644 (file)
@@ -32,7 +32,7 @@ if ![check_shared_lib_support] {
 }
 
 # Check if compiler works
 }
 
 # Check if compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 69eb0bc..6052e8f 100644 (file)
@@ -107,7 +107,7 @@ set test1w2 "$test1 (warning 2)"
 set test1c1    "$test1 (change 1)"
 set test1c2    "$test1 (change 2)"
 
 set test1c1    "$test1 (change 1)"
 set test1c2    "$test1 (change 2)"
 
-if { ![is_remote host] && [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested $test1w1
     untested $test1w2
     untested $test1c1
     untested $test1w1
     untested $test1w2
     untested $test1c1
index 83b23a7..ebaaa78 100644 (file)
@@ -23,7 +23,7 @@
 #
 
 # Check to see if the C compiler works
 #
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 0c1e962..bf0747a 100644 (file)
@@ -25,7 +25,7 @@
 # Make sure that ld can generate ELF shared libraries with visibility.
 
 # Check to see if the C compiler works
 # Make sure that ld can generate ELF shared libraries with visibility.
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 4bc27ca..183f190 100644 (file)
@@ -23,7 +23,7 @@
 #
 
 # Check to see if the C compiler works
 #
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 422c3c3..fe50f31 100644 (file)
@@ -39,7 +39,7 @@ if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] } {
     set cflags "$cflags -fomit-frame-pointer -mshort"
 }
 
     set cflags "$cflags -fomit-frame-pointer -mshort"
 }
 
-if { [is_remote host] || [which $CC] != 0 } {
+if { [check_compiler_available] } {
     ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/gc.c $objfile
 }
 
     ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/gc.c $objfile
 }
 
@@ -130,7 +130,7 @@ if { [is_elf_format] && [check_shared_lib_support] } then {
     set LDFLAGS $old_ldflags
 }
 
     set LDFLAGS $old_ldflags
 }
 
-if { [is_remote host] || [which $CC] != 0 } {
+if { [check_compiler_available] } {
     if { [istarget "*-*-linux*"]
         || [istarget "*-*-nacl*"]
         || [istarget "*-*-gnu*"] } {
     if { [istarget "*-*-linux*"]
         || [istarget "*-*-nacl*"]
         || [istarget "*-*-gnu*"] } {
@@ -141,24 +141,24 @@ if { [is_remote host] || [which $CC] != 0 } {
     }
 }
 
     }
 }
 
-if { [is_remote host] || [which $CC] != 0 } {
+if { [check_compiler_available] } {
        ld_compile "$CC $CFLAGS $cflags" $srcdir/$subdir/pr13683.c tmpdir/pr13683.o
        run_dump_test "pr13683"
 }
 
        ld_compile "$CC $CFLAGS $cflags" $srcdir/$subdir/pr13683.c tmpdir/pr13683.o
        run_dump_test "pr13683"
 }
 
-if { [is_remote host] || [which $CC] != 0 } {
+if { [check_compiler_available] } {
     ld_compile "$CC $CFLAGS $cflags $NOPIE_CFLAGS" $srcdir/$subdir/pr14265.c tmpdir/pr14265.o
     run_dump_test "pr14265"
 }
 
     ld_compile "$CC $CFLAGS $cflags $NOPIE_CFLAGS" $srcdir/$subdir/pr14265.c tmpdir/pr14265.o
     run_dump_test "pr14265"
 }
 
-if { [is_remote host] || [which $CC] != 0 } {
+if { [check_compiler_available] } {
     ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-1.c tmpdir/pr19161-1.o
     ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-2.c tmpdir/pr19161-2.o
     run_dump_test "pr19161"
 }
 
 if { [is_elf_format] && [check_shared_lib_support] \
     ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-1.c tmpdir/pr19161-1.o
     ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-2.c tmpdir/pr19161-2.o
     run_dump_test "pr19161"
 }
 
 if { [is_elf_format] && [check_shared_lib_support] \
-     && ([is_remote host] || [which $CC] != 0) } {
+     && [check_compiler_available] } {
     run_cc_link_tests [list \
        [list \
            "Build libpr20306.so" \
     run_cc_link_tests [list \
        [list \
            "Build libpr20306.so" \
index 9579df6..3a1fd8b 100644 (file)
@@ -581,7 +581,7 @@ global PLT_CFLAGS
 # Must be Linux native with the C compiler
 if { [isnative]
      && [istarget "i?86-*-linux*"]
 # Must be Linux native with the C compiler
 if { [isnative]
      && [istarget "i?86-*-linux*"]
-     && [which $CC] != 0 } {
+     && [check_compiler_available] } {
     run_cc_link_tests [list \
        [list \
            "Build plt-lib.so" \
     run_cc_link_tests [list \
        [list \
            "Build plt-lib.so" \
@@ -1193,7 +1193,7 @@ global NOPIE_CFLAGS NOPIE_LDFLAGS
 if { [isnative]
      && [check_ifunc_available]
      && [istarget "i?86-*-*"]
 if { [isnative]
      && [check_ifunc_available]
      && [istarget "i?86-*-*"]
-     && [which $CC] != 0 } {
+     && [check_compiler_available] } {
     run_cc_link_tests [list \
        [list \
            "Build ifunc-1a.o ifunc-1b.o ifunc-1c.o ifunc-1d.o" \
     run_cc_link_tests [list \
        [list \
            "Build ifunc-1a.o ifunc-1b.o ifunc-1c.o ifunc-1d.o" \
@@ -1310,7 +1310,7 @@ if { [isnative]
 # Must be native with the C compiler.
 if { [isnative]
      && [istarget "i?86-*-*"]
 # Must be native with the C compiler.
 if { [isnative]
      && [istarget "i?86-*-*"]
-     && [which $CC] != 0 } {
+     && [check_compiler_available] } {
     run_cc_link_tests [list \
        [list \
            "Build pr22001-1.so" \
     run_cc_link_tests [list \
        [list \
            "Build pr22001-1.so" \
index 21040a1..6a75a04 100644 (file)
@@ -35,7 +35,7 @@ if ![istarget "i?86-*-*"] {
 }
 
 # Check to see if the C compiler works
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 79c6d9a..1587de6 100644 (file)
@@ -32,7 +32,7 @@ if ![istarget "i?86-*-linux*"] {
 }
 
 # Check to see if the C compiler works
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index e13b561..3fd616a 100644 (file)
@@ -63,7 +63,7 @@ foreach t $test_list {
 
 # We need a working compiler.  (Strictly speaking this is
 # not true, we could use target specific assembler files).
 
 # We need a working compiler.  (Strictly speaking this is
 # not true, we could use target specific assembler files).
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     verbose "IFUNC tests not run - no compiler available"
     return
 }
     verbose "IFUNC tests not run - no compiler available"
     return
 }
index d7c6c45..b78ef55 100644 (file)
@@ -134,7 +134,7 @@ proc i126256-test { } {
     set tmpdir tmpdir
     set testname "Seg fault whilst linking one shared library into another when relaxation is enabled."
 
     set tmpdir tmpdir
     set testname "Seg fault whilst linking one shared library into another when relaxation is enabled."
 
-    if {![is_remote host] && [which $CC] == 0} then {
+    if { ![check_compiler_available] } then {
        return
     }
 
        return
     }
 
index e6154c5..84098f6 100644 (file)
@@ -26,7 +26,7 @@ if {![is_pecoff_format]} {
 }
 
 # No compiler, no test.
 }
 
 # No compiler, no test.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested "PE version scripts"
     untested "aligned common tests"
     # Add more "untested" directives here when adding more tests below.
     untested "PE version scripts"
     untested "aligned common tests"
     # Add more "untested" directives here when adding more tests below.
index 1f06b7a..ae91b61 100644 (file)
@@ -54,7 +54,7 @@ if {![is_pecoff_format]} {
 }
 
 # No compiler, no test.
 }
 
 # No compiler, no test.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested "Direct linking to dll test"
     return
 }
     untested "Direct linking to dll test"
     return
 }
index af45915..4ae239f 100644 (file)
@@ -56,7 +56,7 @@ if {![is_pecoff_format]} {
 }
 
 # No compiler, no test.
 }
 
 # No compiler, no test.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested "Direct linking to dll fastcall/stdcall test"
     return
 }
     untested "Direct linking to dll fastcall/stdcall test"
     return
 }
index 778a944..39c7205 100644 (file)
@@ -26,7 +26,7 @@ if { ![istarget *-*-linux*]
 }
 
 # Check to see if the C compiler works
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index d097f06..3449a07 100644 (file)
@@ -19,7 +19,7 @@
 # MA 02110-1301, USA.
 
 # Check to see if the C and C++ compilers work
 # MA 02110-1301, USA.
 
 # Check to see if the C and C++ compilers work
-if { [which $CC] == 0 || [which $CXX] == 0 } {
+if { ![check_compiler_available] || [which $CXX] == 0 } {
     return
 }
 
     return
 }
 
index 8b0ea9c..ee193e9 100644 (file)
@@ -26,7 +26,7 @@ if ![check_plugin_api_available] {
 # And a compiler to be available.
 set can_compile 1
 set failure_kind "unresolved"
 # And a compiler to be available.
 set can_compile 1
 set failure_kind "unresolved"
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
   # Don't fail immediately, 
   set can_compile 0
   set failure_kind "unsupported"
   # Don't fail immediately, 
   set can_compile 0
   set failure_kind "unsupported"
index 9aa216e..35573cd 100644 (file)
@@ -27,7 +27,7 @@ set test5 "NOCROSSREFS_TO 2"
 set test6 "NOCROSSREFS_TO 3"
 set test7 "NOCROSSREFS_TO 4"
 
 set test6 "NOCROSSREFS_TO 3"
 set test7 "NOCROSSREFS_TO 4"
 
-if { ![is_remote host] && [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested $test1
     untested $test2
     untested $test3
     untested $test1
     untested $test2
     untested $test3
index 09263bb..1fca64d 100644 (file)
@@ -129,7 +129,7 @@ set testlink "SH relaxing"
 set testjsr "SH confirm relaxing"
 set testrun "SH relaxing execution"
 
 set testjsr "SH confirm relaxing"
 set testrun "SH relaxing execution"
 
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested $testlink
     untested $testjsr
     untested $testrun
     untested $testlink
     untested $testjsr
     untested $testrun
index 0e3d75e..ed17b93 100644 (file)
@@ -26,7 +26,7 @@
 # bootstrap test.
 
 # Check to see if the C compiler works
 # bootstrap test.
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 804ae11..c3493d2 100644 (file)
@@ -48,7 +48,7 @@ foreach t $test_list {
 }
 
 # We need a working compiler.
 }
 
 # We need a working compiler.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     verbose "Native size relocation tests not run - no compiler available"
     return
 }
     verbose "Native size relocation tests not run - no compiler available"
     return
 }
index afb1729..944e0a7 100644 (file)
@@ -342,7 +342,7 @@ set sizeof_headers [string match "*SIZEOF_HEADERS*" $exec_output]
 # directly to the S-record format, and require that the two files
 # contain the same data.
 
 # directly to the S-record format, and require that the two files
 # contain the same data.
 
-if { ![is_remote host] && [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested $test1
     untested $test2
     return
     untested $test1
     untested $test2
     return
index 83433f3..8a8e865 100644 (file)
@@ -24,7 +24,7 @@ set testund "undefined"
 set testfn "undefined function"
 set testline "undefined line"
 
 set testfn "undefined function"
 set testline "undefined line"
 
-if { ![is_remote host] && [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     verbose "Could not find C compiler!" 1
     untested $testund
     untested $testfn
     verbose "Could not find C compiler!" 1
     untested $testund
     untested $testfn
index 2cda133..eb21108 100644 (file)
@@ -44,7 +44,7 @@ foreach t $test_list {
 
 # We need a working compiler.  (Strictly speaking this is
 # not true, we could use target specific assembler files).
 
 # We need a working compiler.  (Strictly speaking this is
 # not true, we could use target specific assembler files).
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     verbose "UNIQUE compiled tests not run - no compiler available"
     return
 }
     verbose "UNIQUE compiled tests not run - no compiler available"
     return
 }
index 6474084..4e63039 100644 (file)
@@ -32,7 +32,7 @@ if ![istarget "x86_64-*-linux*"] {
 }
 
 # Check to see if the C compiler works
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 77c90b1..7409345 100644 (file)
@@ -35,7 +35,7 @@ if ![istarget "x86_64-*-*"] {
 }
 
 # Check to see if the C compiler works
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index b3b8a83..0b9f5c5 100644 (file)
@@ -32,7 +32,7 @@ if ![istarget "x86_64-*-linux*"] {
 }
 
 # Check to see if the C compiler works
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
     return
 }
 
index 98aa4b0..23f2020 100644 (file)
@@ -731,7 +731,7 @@ global PLT_CFLAGS
 global NOPIE_CFLAGS NOPIE_LDFLAGS
 
 # Must be native with the C compiler
 global NOPIE_CFLAGS NOPIE_LDFLAGS
 
 # Must be native with the C compiler
-if { [isnative] && [which $CC] != 0 } {
+if { [isnative] && [check_compiler_available] } {
     run_cc_link_tests {
        {"Helper X32 DSO from x86-64 object" "" "-m64 -fPIC -g"
         {simple.c} {} "libsimple.a"}
     run_cc_link_tests {
        {"Helper X32 DSO from x86-64 object" "" "-m64 -fPIC -g"
         {simple.c} {} "libsimple.a"}
index dc55dc8..0ff51c9 100644 (file)
@@ -688,6 +688,11 @@ proc run_ld_link_exec_tests { ldtests args } {
        set objfiles {}
        set failed 0
 
        set objfiles {}
        set failed 0
 
+       if { ![check_compiler_available] } {
+           unsupported $testname
+           continue
+       }
+
 #      verbose -log "Testname is $testname"
 #      verbose -log "ld_options is $ld_options"
 #      verbose -log "as_options is $as_options"
 #      verbose -log "Testname is $testname"
 #      verbose -log "ld_options is $ld_options"
 #      verbose -log "as_options is $as_options"
@@ -840,6 +845,11 @@ proc run_cc_link_tests { ldtests } {
        set check_ld(terminal) 0
        set check_ld(source) ""
 
        set check_ld(terminal) 0
        set check_ld(source) ""
 
+       if { ![check_compiler_available] } {
+           unsupported $testname
+           continue
+       }
+
        #verbose -log "testname  is $testname"
        #verbose -log "ldflags   is $ldflags"
        #verbose -log "cflags    is $cflags"
        #verbose -log "testname  is $testname"
        #verbose -log "ldflags   is $ldflags"
        #verbose -log "cflags    is $cflags"
@@ -1140,6 +1150,49 @@ proc check_sysroot_available { } {
     return $ld_sysroot_available_saved
 }
 
     return $ld_sysroot_available_saved
 }
 
+# Return true if we can build a program with the compiler.
+# On some targets, CC might be defined, but libraries and startup
+# code might be missing or require special options that the ld test
+# harness doesn't know about.
+
+proc check_compiler_available { } {
+    global compiler_available_saved
+    global CC
+
+    if {![info exists compiler_available_saved]} {
+        if { [which $CC] == 0 } {
+           set compiler_available_saved 0
+           return 0
+       }
+
+       set flags ""
+       if [board_info [target_info name] exists cflags] {
+           append flags " [board_info [target_info name] cflags]"
+       }
+       if [board_info [target_info name] exists ldflags] {
+           append flags " [board_info [target_info name] ldflags]"
+       }
+
+       set basename "tmpdir/compiler[pid]"
+       set src ${basename}.c
+       set output ${basename}.out
+       set f [open $src "w"]
+       puts $f "int main (void)"
+       puts $f "{"
+       puts $f "  return 0; "
+       puts $f "}"
+       close $f
+       if [is_remote host] {
+           set src [remote_download host $src]
+       }
+       set compiler_available_saved [run_host_cmd_yesno "$CC" "$flags $src -o $output"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+    }
+    return $compiler_available_saved
+}
+
 # Returns 1 if plugin is enabled in gcc.  Returns 0 otherwise.
 proc check_gcc_plugin_enabled { } {
     global CC
 # Returns 1 if plugin is enabled in gcc.  Returns 0 otherwise.
 proc check_gcc_plugin_enabled { } {
     global CC
@@ -1327,7 +1380,7 @@ proc check_ifunc_available { } {
     global CC
 
     if {![info exists ifunc_available_saved]} {
     global CC
 
     if {![info exists ifunc_available_saved]} {
-        if { [which $CC] == 0 } {
+        if { ![check_compiler_available] } {
            set ifunc_available_saved 0
            return 0
        }
            set ifunc_available_saved 0
            return 0
        }
@@ -1376,7 +1429,7 @@ proc check_ifunc_attribute_available { } {
     global CC
 
     if {![info exists ifunc_attribute_available_saved]} {
     global CC
 
     if {![info exists ifunc_attribute_available_saved]} {
-        if { [which $CC] == 0 } {
+        if { ![check_compiler_available] } {
            set ifunc_attribute_available_saved 0
            return 0
        }
            set ifunc_attribute_available_saved 0
            return 0
        }
@@ -1423,7 +1476,7 @@ proc check_libdl_available { } {
     global CC
 
     if {![info exists libdl_available_saved]} {
     global CC
 
     if {![info exists libdl_available_saved]} {
-        if { [which $CC] == 0 } {
+        if { ![check_compiler_available] } {
            set libdl_available_saved 0
            return 0
        }
            set libdl_available_saved 0
            return 0
        }
@@ -1459,7 +1512,7 @@ proc check_gnu2_tls_available { } {
     global GNU2_CFLAGS
 
     if {![info exists gnu2_tls_available_saved]} {
     global GNU2_CFLAGS
 
     if {![info exists gnu2_tls_available_saved]} {
-        if { [which $CC] == 0 || "$GNU2_CFLAGS" == "" } {
+        if { ![check_compiler_available] || "$GNU2_CFLAGS" == "" } {
            set gnu2_tls_available_saved 0
            return 0
        }
            set gnu2_tls_available_saved 0
            return 0
        }