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 4b4956e9ccc99c5a1fe33bca5d0bba63b382d902..a62a6c548b1b889ef599c5480ed97d5b88d61614 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..
index 5acab06329132470e263281b41d9df142cce4d36..ce52919e796abd98662b92532fce32a26d6217d2 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 {
-    if { [which $CC] != 0 } {
+    if { [check_compiler_available] } {
        # 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 {
-    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] {
@@ -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 {
-    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] {
@@ -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 {
-    if { [which $CC] != 0 } {
+    if { [check_compiler_available] } {
        # 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 {
-    if { [which $CC] != 0 } {
+    if { [check_compiler_available] } {
        # 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 {
-    if { [which $CC] != 0 } {
+    if { [check_compiler_available] } {
        # Check if gcc supports -static-pie.
        set flags ""
        if [board_info [target_info name] exists cflags] {
index d9ac6cf32f8e5899720c407ff2125c1b5ffe4bd6..d5a0dccbc6a8cb374cbcc344752346e19d72e581 100644 (file)
@@ -67,7 +67,7 @@ if [istarget *-pc-mingw*] {
 }
 
 # No compiler, no test.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested "Auto import test (compiler not found)"
     return
 }
index 258949eac8b9379ba4cad949f21c678589aa8fb0..5436332be5d38de63c8cc027fb8f58189a1a9185 100644 (file)
@@ -29,7 +29,7 @@ if {![istarget *-pc-cygwin]} {
 }\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
index 3514176f0daa0907997bccba7cb0826d3981bd0c..5cc044ba7efed4a7cfe5b37a2a7ba38a3bce861e 100644 (file)
@@ -32,7 +32,7 @@ if ![check_shared_lib_support] {
 }
 
 # Check if compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 6bdc92182885d4aa6a3cbccfd52cb000f2cc4914..90b6c6e6612bc54a37a211d45a0039dcdbd652cb 100644 (file)
@@ -32,7 +32,7 @@ if ![check_shared_lib_support] {
 }
 
 # Check if compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index bc3cbb219b32c2cc2ac65ed386e7cdca8d6be4cf..233a2a87872b93acc7135b6bcd08b1931fc391bb 100644 (file)
@@ -36,7 +36,7 @@ if ![check_shared_lib_support] {
 }
 
 # Check if compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 4686870916455213476410a8743827b5bd9ebdf4..9121936c2101bacf79668153cb133a8bd83b2e6f 100644 (file)
@@ -182,7 +182,7 @@ set LDFLAGS $old_ldflags
 set ASFLAGS $old_asflags
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index b1a2c6c86a99590547d1f1118261c0d8120ff324..1acb556dba0529a8950c956d5cf3eb34d5ef9ed5 100644 (file)
@@ -33,7 +33,7 @@ if ![check_shared_lib_support] {
 }
 
 # Check if compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index b1cad615eb59b2625ab5c48ec705209a8d86defc..6b0f23f48e81fb080f5d266c02d98fbda494c8e1 100644 (file)
@@ -20,7 +20,7 @@
 #
 
 # 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*"]) } {
index b5a01c9379bd6c22fe1830796857ec9b09c32ab1..f27fa2401d047153fdeb0841b7faf85536d5e533 100644 (file)
@@ -498,7 +498,7 @@ if { [istarget *-*-linux*]
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 1b26f8b24e18a28a90effc32f551cc09df2eaf55..4daddc7509312da5edeccbb67fa5ac79d7bcbb97 100644 (file)
@@ -29,7 +29,7 @@ if { ![istarget *-*-linux*]
 }
 
 # Check to see if the C compiler works.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 3293231dba7e3bec1c9eadcb52ebe43a908255c2..1a9fa7c3a2919996b34917cfc82a6488075b805c 100644 (file)
@@ -32,7 +32,7 @@ if ![check_shared_lib_support] {
 }
 
 # Check if compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 69eb0bc0a108fbb81817fca24a2296a5585e1ddc..6052e8f7539ec45cc32743a98d7e75983ca8b33e 100644 (file)
@@ -107,7 +107,7 @@ set test1w2 "$test1 (warning 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
index 83b23a7fdf781bdc4ac32af52a53eff3a1d418b8..ebaaa785320ccc709fce7c645a9513d71c96ef0f 100644 (file)
@@ -23,7 +23,7 @@
 #
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 0c1e962765c4d1a69180587b2cb0fc9918365617..bf0747a18cea406668f5767f7d0d91c8547d4f7c 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
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 4bc27ca38a23c7ab0460b564f85cb67d2fbc9a3f..183f190cd2156464932ce98f104797e58927210a 100644 (file)
@@ -23,7 +23,7 @@
 #
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 422c3c31209087bb49636d20cd6f89f0f3ebceee..fe50f31cda9de50490673dddef89609e89b11926 100644 (file)
@@ -39,7 +39,7 @@ if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] } {
     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
 }
 
@@ -130,7 +130,7 @@ if { [is_elf_format] && [check_shared_lib_support] } then {
     set LDFLAGS $old_ldflags
 }
 
-if { [is_remote host] || [which $CC] != 0 } {
+if { [check_compiler_available] } {
     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"
 }
 
-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"
 }
 
-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] \
-     && ([is_remote host] || [which $CC] != 0) } {
+     && [check_compiler_available] } {
     run_cc_link_tests [list \
        [list \
            "Build libpr20306.so" \
index 9579df653ea31340505eae33975240b247741363..3a1fd8b3cfebc57760fdb4e23a825133dec59538 100644 (file)
@@ -581,7 +581,7 @@ global PLT_CFLAGS
 # 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" \
@@ -1193,7 +1193,7 @@ global NOPIE_CFLAGS NOPIE_LDFLAGS
 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" \
@@ -1310,7 +1310,7 @@ if { [isnative]
 # 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" \
index 21040a15177e19dea628c85d446dc9b20c4b12e9..6a75a04d974bb67ca08c59a1114863fc707992d8 100644 (file)
@@ -35,7 +35,7 @@ if ![istarget "i?86-*-*"] {
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 79c6d9a45c3418d08dfe0fd3c52c0a0db1669b41..1587de67045d7347a82b6f48ba6e4c54b4b8f56e 100644 (file)
@@ -32,7 +32,7 @@ if ![istarget "i?86-*-linux*"] {
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index e13b5615ff3e645a846f29ac4eab42eb981fa416..3fd616ac69ab3f1eaca57e11b70e62b3a84f8e59 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).
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     verbose "IFUNC tests not run - no compiler available"
     return
 }
index d7c6c45fc6f72ad94646ec87b5b8d76c86e97c79..b78ef55965d2d7f842bcf5075b91a7967069c5b8 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."
 
-    if {![is_remote host] && [which $CC] == 0} then {
+    if { ![check_compiler_available] } then {
        return
     }
 
index e6154c5863b817bc8a721a44e0bd618c51a44d1d..84098f654f2c68a5de58e421edfd1f54d09bee76 100644 (file)
@@ -26,7 +26,7 @@ if {![is_pecoff_format]} {
 }
 
 # 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.
index 1f06b7abe2e22901c100ab639af0f4123dddc5da..ae91b612be8ceb7fa89599f1c6d742ab6c6392a8 100644 (file)
@@ -54,7 +54,7 @@ if {![is_pecoff_format]} {
 }
 
 # No compiler, no test.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested "Direct linking to dll test"
     return
 }
index af45915bdcc74c93502eef83deca36b496c56fcf..4ae239f67157f58781f94797ab6c67850ab23949 100644 (file)
@@ -56,7 +56,7 @@ if {![is_pecoff_format]} {
 }
 
 # No compiler, no test.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested "Direct linking to dll fastcall/stdcall test"
     return
 }
index 778a94460046a67960ea5dba8c3cd61b0f166d84..39c72056ac16dacc71f5a6a53eedc2325d1ec5d4 100644 (file)
@@ -26,7 +26,7 @@ if { ![istarget *-*-linux*]
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index d097f063236767d9c84aa41a3ebf4633cbcd6392..3449a076ab91b84222d6506ef76abfda4626d1df 100644 (file)
@@ -19,7 +19,7 @@
 # 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
 }
 
index 8b0ea9c1e36041f5426f4dd233f967ffc0fa767e..ee193e93f1004b4a97c171a4c7e86ccac59e922a 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"
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
   # Don't fail immediately, 
   set can_compile 0
   set failure_kind "unsupported"
index 9aa216ea227c8c8fcd382d99c4c77eadf93c0363..35573cd10562a8f0b4199316d1d1a9bea0cde6ff 100644 (file)
@@ -27,7 +27,7 @@ set test5 "NOCROSSREFS_TO 2"
 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
index 09263bb4533b1423421c4ec462f60e4338070c0b..1fca64d861225e517fc121c8372d29526a0bb7bd 100644 (file)
@@ -129,7 +129,7 @@ set testlink "SH relaxing"
 set testjsr "SH confirm relaxing"
 set testrun "SH relaxing execution"
 
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested $testlink
     untested $testjsr
     untested $testrun
index 0e3d75e9d160d3fcd427faf5a8943a4464042fd3..ed17b93690869721e35d44d07014c7188d02a5c6 100644 (file)
@@ -26,7 +26,7 @@
 # bootstrap test.
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 804ae11249af9548d3fb3c2d0463e635186081d6..c3493d21cf12bd85732ed30fa274128df2d9c950 100644 (file)
@@ -48,7 +48,7 @@ foreach t $test_list {
 }
 
 # We need a working compiler.
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     verbose "Native size relocation tests not run - no compiler available"
     return
 }
index afb1729c24400a8a2f066bd2aebd95dbaa0963e9..944e0a71567e8259cf1d894c5203819abeefcd0c 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.
 
-if { ![is_remote host] && [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     untested $test1
     untested $test2
     return
index 83433f351d7ac8851107bbdcf6cc21d086dfc488..8a8e8655910a5671fb02b197ce83b23d2c4133b4 100644 (file)
@@ -24,7 +24,7 @@ set testund "undefined"
 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
index 2cda1335a36d20934ee55bd11cb912265d7f5f4c..eb2110834488fbdb49fdb59caa137e7117cf0382 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).
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     verbose "UNIQUE compiled tests not run - no compiler available"
     return
 }
index 64740845ca8eae0424417c22f5687cdfd0cfbd7f..4e63039cc14d033aa582f67ed86b443dd2e0ca93 100644 (file)
@@ -32,7 +32,7 @@ if ![istarget "x86_64-*-linux*"] {
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 77c90b1483cf9193b63433df56a2b6cada8fc281..74093456219e614b84ea00649b91e98b6677b2c0 100644 (file)
@@ -35,7 +35,7 @@ if ![istarget "x86_64-*-*"] {
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index b3b8a8316590802620cd18ffe6c0ff37489777c3..0b9f5c57164d303264a04280dcddc562c6ff2e80 100644 (file)
@@ -32,7 +32,7 @@ if ![istarget "x86_64-*-linux*"] {
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
index 98aa4b04d8bee13afda8deafa7713153fa2b383e..23f202017cadf7378d9e2d411ed4ab1fdca78c94 100644 (file)
@@ -731,7 +731,7 @@ global PLT_CFLAGS
 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"}
index dc55dc803439d6742e0441458b509eaf5a13512c..0ff51c952614164f4223c01e1983fb0e65721da3 100644 (file)
@@ -688,6 +688,11 @@ proc run_ld_link_exec_tests { ldtests args } {
        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"
@@ -840,6 +845,11 @@ proc run_cc_link_tests { ldtests } {
        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"
@@ -1140,6 +1150,49 @@ proc check_sysroot_available { } {
     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
@@ -1327,7 +1380,7 @@ proc check_ifunc_available { } {
     global CC
 
     if {![info exists ifunc_available_saved]} {
-        if { [which $CC] == 0 } {
+        if { ![check_compiler_available] } {
            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]} {
-        if { [which $CC] == 0 } {
+        if { ![check_compiler_available] } {
            set ifunc_attribute_available_saved 0
            return 0
        }
@@ -1423,7 +1476,7 @@ proc check_libdl_available { } {
     global CC
 
     if {![info exists libdl_available_saved]} {
-        if { [which $CC] == 0 } {
+        if { ![check_compiler_available] } {
            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]} {
-        if { [which $CC] == 0 || "$GNU2_CFLAGS" == "" } {
+        if { ![check_compiler_available] || "$GNU2_CFLAGS" == "" } {
            set gnu2_tls_available_saved 0
            return 0
        }
This page took 0.046542 seconds and 4 git commands to generate.