From: Sandra Loosemore Date: Wed, 24 Apr 2019 19:14:56 +0000 (-0700) Subject: Use better test for usable compiler in ld testsuite. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=44ed80923ab89e141120defa8c1209b69869a7ac;p=binutils-gdb.git Use better test for usable compiler in ld testsuite. 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 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]. --- diff --git a/ld/ChangeLog b/ld/ChangeLog index 4b4956e9ccc..a62a6c548b1 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,50 @@ +2019-04-24 Sandra Loosemore + + * 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 * Makefile.am (GENDEPDIR): New var, used.. diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp index 5acab063291..ce52919e796 100644 --- a/ld/testsuite/config/default.exp +++ b/ld/testsuite/config/default.exp @@ -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] { diff --git a/ld/testsuite/ld-auto-import/auto-import.exp b/ld/testsuite/ld-auto-import/auto-import.exp index d9ac6cf32f8..d5a0dccbc6a 100644 --- a/ld/testsuite/ld-auto-import/auto-import.exp +++ b/ld/testsuite/ld-auto-import/auto-import.exp @@ -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 } diff --git a/ld/testsuite/ld-cygwin/exe-export.exp b/ld/testsuite/ld-cygwin/exe-export.exp index 258949eac8b..5436332be5d 100644 --- a/ld/testsuite/ld-cygwin/exe-export.exp +++ b/ld/testsuite/ld-cygwin/exe-export.exp @@ -29,7 +29,7 @@ if {![istarget *-pc-cygwin]} { } # No compiler, no test. -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { untested "Exe export test (no compiler available)" return } diff --git a/ld/testsuite/ld-elf/audit.exp b/ld/testsuite/ld-elf/audit.exp index 3514176f0da..5cc044ba7ef 100644 --- a/ld/testsuite/ld-elf/audit.exp +++ b/ld/testsuite/ld-elf/audit.exp @@ -32,7 +32,7 @@ if ![check_shared_lib_support] { } # Check if compiler works -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-elf/compress.exp b/ld/testsuite/ld-elf/compress.exp index 6bdc9218288..90b6c6e6612 100644 --- a/ld/testsuite/ld-elf/compress.exp +++ b/ld/testsuite/ld-elf/compress.exp @@ -32,7 +32,7 @@ if ![check_shared_lib_support] { } # Check if compiler works -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-elf/dwarf.exp b/ld/testsuite/ld-elf/dwarf.exp index bc3cbb219b3..233a2a87872 100644 --- a/ld/testsuite/ld-elf/dwarf.exp +++ b/ld/testsuite/ld-elf/dwarf.exp @@ -36,7 +36,7 @@ if ![check_shared_lib_support] { } # Check if compiler works -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp index 46868709164..9121936c210 100644 --- a/ld/testsuite/ld-elf/elf.exp +++ b/ld/testsuite/ld-elf/elf.exp @@ -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 } diff --git a/ld/testsuite/ld-elf/indirect.exp b/ld/testsuite/ld-elf/indirect.exp index b1a2c6c86a9..1acb556dba0 100644 --- a/ld/testsuite/ld-elf/indirect.exp +++ b/ld/testsuite/ld-elf/indirect.exp @@ -33,7 +33,7 @@ if ![check_shared_lib_support] { } # Check if compiler works -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp index b1cad615eb5..6b0f23f48e8 100644 --- a/ld/testsuite/ld-elf/linux-x86.exp +++ b/ld/testsuite/ld-elf/linux-x86.exp @@ -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*"]) } { diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index b5a01c9379b..f27fa2401d0 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -498,7 +498,7 @@ if { [istarget *-*-linux*] } # Check to see if the C compiler works -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-elf/tls.exp b/ld/testsuite/ld-elf/tls.exp index 1b26f8b24e1..4daddc75093 100644 --- a/ld/testsuite/ld-elf/tls.exp +++ b/ld/testsuite/ld-elf/tls.exp @@ -29,7 +29,7 @@ if { ![istarget *-*-linux*] } # Check to see if the C compiler works. -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-elf/wrap.exp b/ld/testsuite/ld-elf/wrap.exp index 3293231dba7..1a9fa7c3a29 100644 --- a/ld/testsuite/ld-elf/wrap.exp +++ b/ld/testsuite/ld-elf/wrap.exp @@ -32,7 +32,7 @@ if ![check_shared_lib_support] { } # Check if compiler works -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-elfcomm/elfcomm.exp b/ld/testsuite/ld-elfcomm/elfcomm.exp index 69eb0bc0a10..6052e8f7539 100644 --- a/ld/testsuite/ld-elfcomm/elfcomm.exp +++ b/ld/testsuite/ld-elfcomm/elfcomm.exp @@ -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 diff --git a/ld/testsuite/ld-elfvers/vers.exp b/ld/testsuite/ld-elfvers/vers.exp index 83b23a7fdf7..ebaaa785320 100644 --- a/ld/testsuite/ld-elfvers/vers.exp +++ b/ld/testsuite/ld-elfvers/vers.exp @@ -23,7 +23,7 @@ # # Check to see if the C compiler works -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-elfvsb/elfvsb.exp b/ld/testsuite/ld-elfvsb/elfvsb.exp index 0c1e962765c..bf0747a18ce 100644 --- a/ld/testsuite/ld-elfvsb/elfvsb.exp +++ b/ld/testsuite/ld-elfvsb/elfvsb.exp @@ -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 } diff --git a/ld/testsuite/ld-elfweak/elfweak.exp b/ld/testsuite/ld-elfweak/elfweak.exp index 4bc27ca38a2..183f190cd21 100644 --- a/ld/testsuite/ld-elfweak/elfweak.exp +++ b/ld/testsuite/ld-elfweak/elfweak.exp @@ -23,7 +23,7 @@ # # Check to see if the C compiler works -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp index 422c3c31209..fe50f31cda9 100644 --- a/ld/testsuite/ld-gc/gc.exp +++ b/ld/testsuite/ld-gc/gc.exp @@ -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" \ diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index 9579df653ea..3a1fd8b3cfe 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -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" \ diff --git a/ld/testsuite/ld-i386/no-plt.exp b/ld/testsuite/ld-i386/no-plt.exp index 21040a15177..6a75a04d974 100644 --- a/ld/testsuite/ld-i386/no-plt.exp +++ b/ld/testsuite/ld-i386/no-plt.exp @@ -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 } diff --git a/ld/testsuite/ld-i386/tls.exp b/ld/testsuite/ld-i386/tls.exp index 79c6d9a45c3..1587de67045 100644 --- a/ld/testsuite/ld-i386/tls.exp +++ b/ld/testsuite/ld-i386/tls.exp @@ -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 } diff --git a/ld/testsuite/ld-ifunc/ifunc.exp b/ld/testsuite/ld-ifunc/ifunc.exp index e13b5615ff3..3fd616ac69a 100644 --- a/ld/testsuite/ld-ifunc/ifunc.exp +++ b/ld/testsuite/ld-ifunc/ifunc.exp @@ -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 } diff --git a/ld/testsuite/ld-mn10300/mn10300.exp b/ld/testsuite/ld-mn10300/mn10300.exp index d7c6c45fc6f..b78ef55965d 100644 --- a/ld/testsuite/ld-mn10300/mn10300.exp +++ b/ld/testsuite/ld-mn10300/mn10300.exp @@ -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 } diff --git a/ld/testsuite/ld-pe/pe-compile.exp b/ld/testsuite/ld-pe/pe-compile.exp index e6154c5863b..84098f654f2 100644 --- a/ld/testsuite/ld-pe/pe-compile.exp +++ b/ld/testsuite/ld-pe/pe-compile.exp @@ -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. diff --git a/ld/testsuite/ld-pe/pe-run.exp b/ld/testsuite/ld-pe/pe-run.exp index 1f06b7abe2e..ae91b612be8 100644 --- a/ld/testsuite/ld-pe/pe-run.exp +++ b/ld/testsuite/ld-pe/pe-run.exp @@ -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 } diff --git a/ld/testsuite/ld-pe/pe-run2.exp b/ld/testsuite/ld-pe/pe-run2.exp index af45915bdcc..4ae239f6715 100644 --- a/ld/testsuite/ld-pe/pe-run2.exp +++ b/ld/testsuite/ld-pe/pe-run2.exp @@ -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 } diff --git a/ld/testsuite/ld-pie/pie.exp b/ld/testsuite/ld-pie/pie.exp index 778a9446004..39c72056ac1 100644 --- a/ld/testsuite/ld-pie/pie.exp +++ b/ld/testsuite/ld-pie/pie.exp @@ -26,7 +26,7 @@ if { ![istarget *-*-linux*] } # Check to see if the C compiler works -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp index d097f063236..3449a076ab9 100644 --- a/ld/testsuite/ld-plugin/lto.exp +++ b/ld/testsuite/ld-plugin/lto.exp @@ -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 } diff --git a/ld/testsuite/ld-plugin/plugin.exp b/ld/testsuite/ld-plugin/plugin.exp index 8b0ea9c1e36..ee193e93f10 100644 --- a/ld/testsuite/ld-plugin/plugin.exp +++ b/ld/testsuite/ld-plugin/plugin.exp @@ -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" diff --git a/ld/testsuite/ld-scripts/crossref.exp b/ld/testsuite/ld-scripts/crossref.exp index 9aa216ea227..35573cd1056 100644 --- a/ld/testsuite/ld-scripts/crossref.exp +++ b/ld/testsuite/ld-scripts/crossref.exp @@ -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 diff --git a/ld/testsuite/ld-sh/sh.exp b/ld/testsuite/ld-sh/sh.exp index 09263bb4533..1fca64d8612 100644 --- a/ld/testsuite/ld-sh/sh.exp +++ b/ld/testsuite/ld-sh/sh.exp @@ -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 diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp index 0e3d75e9d16..ed17b936908 100644 --- a/ld/testsuite/ld-shared/shared.exp +++ b/ld/testsuite/ld-shared/shared.exp @@ -26,7 +26,7 @@ # bootstrap test. # Check to see if the C compiler works -if { [which $CC] == 0 } { +if { ![check_compiler_available] } { return } diff --git a/ld/testsuite/ld-size/size.exp b/ld/testsuite/ld-size/size.exp index 804ae11249a..c3493d21cf1 100644 --- a/ld/testsuite/ld-size/size.exp +++ b/ld/testsuite/ld-size/size.exp @@ -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 } diff --git a/ld/testsuite/ld-srec/srec.exp b/ld/testsuite/ld-srec/srec.exp index afb1729c244..944e0a71567 100644 --- a/ld/testsuite/ld-srec/srec.exp +++ b/ld/testsuite/ld-srec/srec.exp @@ -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 diff --git a/ld/testsuite/ld-undefined/undefined.exp b/ld/testsuite/ld-undefined/undefined.exp index 83433f351d7..8a8e8655910 100644 --- a/ld/testsuite/ld-undefined/undefined.exp +++ b/ld/testsuite/ld-undefined/undefined.exp @@ -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 diff --git a/ld/testsuite/ld-unique/unique.exp b/ld/testsuite/ld-unique/unique.exp index 2cda1335a36..eb211083448 100644 --- a/ld/testsuite/ld-unique/unique.exp +++ b/ld/testsuite/ld-unique/unique.exp @@ -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 } diff --git a/ld/testsuite/ld-x86-64/mpx.exp b/ld/testsuite/ld-x86-64/mpx.exp index 64740845ca8..4e63039cc14 100644 --- a/ld/testsuite/ld-x86-64/mpx.exp +++ b/ld/testsuite/ld-x86-64/mpx.exp @@ -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 } diff --git a/ld/testsuite/ld-x86-64/no-plt.exp b/ld/testsuite/ld-x86-64/no-plt.exp index 77c90b1483c..74093456219 100644 --- a/ld/testsuite/ld-x86-64/no-plt.exp +++ b/ld/testsuite/ld-x86-64/no-plt.exp @@ -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 } diff --git a/ld/testsuite/ld-x86-64/tls.exp b/ld/testsuite/ld-x86-64/tls.exp index b3b8a831659..0b9f5c57164 100644 --- a/ld/testsuite/ld-x86-64/tls.exp +++ b/ld/testsuite/ld-x86-64/tls.exp @@ -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 } diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 98aa4b04d8b..23f202017ca 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -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"} diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp index dc55dc80343..0ff51c95261 100644 --- a/ld/testsuite/lib/ld-lib.exp +++ b/ld/testsuite/lib/ld-lib.exp @@ -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 }