binutils-gdb/ld/testsuite/ld-cygwin/exe-export.exp
Sandra Loosemore 44ed80923a 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  <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].
2019-04-24 12:14:56 -07:00

154 lines
4.6 KiB
Plaintext

# Expect script for export table in executables tests
# Copyright (C) 2003-2019 Free Software Foundation, Inc.
#
# This file is part of the GNU Binutils.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# Written by Fabrizio Gennari <fabrizio.ge@tiscalinet.it>
# Based on auto-import.exp by Ralf.Habacker@freenet.de
#
# This test can only be run on a cygwin platforms.
if {![istarget *-pc-cygwin]} {
verbose "Not a cygwin target."
return
}
# No compiler, no test.
if { ![check_compiler_available] } {
untested "Exe export test (no compiler available)"
return
}
proc run_dlltool { lib_file def_file } {
global dlltool
global base_dir
global as
if ![info exists dlltool] then {
set dlltool [findfile $base_dir/../binutils/dlltool]
}
if { [which $dlltool] == 0 } then {
verbose "$dlltool does not exist"
return 0
}
verbose "$dlltool --as $as -l $lib_file -d $def_file"
catch "exec $dlltool --as $as -l $lib_file -d $def_file" dlltool_output
#remove empty lines
regsub -all "\n+" $dlltool_output "" dlltool_output
if [string match "" $dlltool_output] then {
return 1
}
verbose -log "$dlltool_output"
return 0
}
# ld_special_link
# A copy of ld_link (from ld-lib.exp) with extra
# code to strip warnings about creating libraries.
#
proc ld_special_link { ld target objects } {
global host_triplet
global link_output
if { [which $ld] == 0 } then {
verbose "$ld does not exist"
return 0
}
if [is_endian_output_format $objects] then {
set flags [big_or_little_endian]
} else {
set flags ""
}
verbose -log "$ld $flags -o $target $objects"
catch "exec $ld $flags -o $target $objects" link_output
set exec_output [prune_warnings $link_output]
# We don't care if we get a warning about a non-existent start
# symbol, since the default linker script might use ENTRY.
regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
# We don't care if we get a message about creating a library file.
regsub -all "(^|\n)(Creating library file\[^\n\]*\n?)" $exec_output "\\1" exec_output
if [string match "" $exec_output] then {
return 1
}
verbose -log "$exec_output"
return 0
}
set tmpdir tmpdir
# Set some libs needed for cygwin.
set MYLDFLAGS "-Wl,--out-implib,$tmpdir/testexe.lib -nostartfiles -nostdlib"
# Build an export library for testdll
if ![run_dlltool $tmpdir/testdll.lib $srcdir/$subdir/testdll.def] {
fail "building an export library for the shared lib"
return
}
# Compile the executable.
if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/testexe.c $tmpdir/testexe.o] {
fail "compiling executable"
return
}
if ![ld_special_link "$CC $LDFLAGS $MYLDFLAGS -e _testexe_main@16" $tmpdir/testexe.exe "$tmpdir/testexe.o $srcdir/$subdir/testexe.def $tmpdir/testdll.lib -lkernel32"] {
fail "linking executable"
return
}
# Compile the dll.
if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/testdll.c $tmpdir/testdll.o] {
fail "compiling shared lib"
return
}
if ![ld_special_link "$CC $LDFLAGS -nostartfiles -nostdlib -e _testdll_main@12" $tmpdir/testdll.dll "$tmpdir/testdll.o $srcdir/$subdir/testdll.def $tmpdir/testexe.lib"] {
fail "linking shared lib"
return
}
# This is as far as we can go with a cross-compiler
if ![isnative] then {
verbose "Not running natively, so cannot execute binary"
pass "Compile and link and executable with an export table"
return
}
verbose -log "executing $tmpdir/testexe.exe"
catch "exec $tmpdir/testexe.exe" prog_output
set expected ""
if [string match $expected $prog_output] then {
pass "export table in executable"
} else {
verbose $prog_output
fail "Output does not match expected string $expected"
}