binutils-gdb/ld/testsuite/ld-sh/sh.exp
Alan Modra ad77db1c02 CC_FOR_TARGET et al
The top level Makefile, the ld Makefile and others, define
CC_FOR_TARGET to be a compiler for the binutils target machine.  This
is the compiler that should be used for almost all tests with C
source.  There are _FOR_TARGET versions of CFLAGS, CXX, and CXXFLAGS
too.  This was all supposed to work with the testsuite .exp files
using CC for the target compiler, and CC_FOR_HOST for the host
compiler, with the makefiles passing CC=$CC_FOR_TARGET and
CC_FOR_HOST=$CC to the runtest invocation.

One exception to the rule of using CC_FOR_TARGET is the native-only ld
bootstrap test, which uses the newly built ld to link a copy of
itself.  Since the files being linked were created with the host
compiler, the boostrap test should use CC and CFLAGS, in case some
host compiler option provides needed libraries automatically.
However, bootstrap.exp used CC where it should have used CC_FOR_HOST.
I set about fixing that problem, then decided that playing games in
the makefiles with CC was a bad idea.  Not only is it confusing, but
other dejagnu code knows about CC_FOR_TARGET.  See dejagnu/target.exp.

So this patch gets rid of the makefile variable renaming and changes
all the .exp files to use the correct _FOR_TARGET variables.
CC_FOR_HOST and CFLAGS_FOR_HOST disappear.  A followup patch will
correct bootstrap.exp to use CFLAGS, and a number of other things I
noticed.

binutils/
	* testsuite/lib/binutils-common.exp (run_dump_test): Use
	CC_FOR_TARGET and CFLAGS_FOR_TARGET rather than CC and CFLAGS.
ld/
	* Makefile.am (check-DEJAGNU): Don't set CC to CC_FOR_TARGET
	and similar.  Pass variables with unchanged names.  Don't set
	CC_FOR_HOST or CFLAGS_FOR_HOST.
	* Makefile.in: Regenerate.
	* testsuite/config/default.exp: Update default CC and similar.
	(compiler_supports, plug_opt): Use CC_FOR_TARGET.
	* testsuite/ld-cdtest/cdtest.exp: Replace all uses of CC with
	CC_FOR_TARGET, and similarly for CFLAGS, CXX and CXXFLAGS.
	* testsuite/ld-auto-import/auto-import.exp: Likewise.
	* testsuite/ld-cygwin/exe-export.exp: Likewise.
	* testsuite/ld-elf/dwarf.exp: Likewise.
	* testsuite/ld-elf/indirect.exp: Likewise.
	* testsuite/ld-elf/shared.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-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-selective/selective.exp: Likewise.
	* testsuite/ld-sh/sh.exp: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.
	* testsuite/ld-srec/srec.exp: Likewise.
	* testsuite/ld-undefined/undefined.exp: Likewise.
	* testsuite/ld-unique/unique.exp: Likewise.
	* testsuite/ld-x86-64/tls.exp: Likewise.
	* testsuite/lib/ld-lib.exp: Likewise.
libctf/
	* Makefile.am (check-DEJAGNU): Don't set CC to CC_FOR_TARGET.
	Pass CC and CC_FOR_TARGET.  Don't set CC_FOR_HOST.
	* Makefile.in: Regenerate.
	* testsuite/config/default.exp: Update default CC and similar.
	* testsuite/lib/ctf-lib.exp (run_native_host_cmd): Use CC rather
	than CC_FOR_HOST.
	(run_lookup_test): Use CC_FOR_TARGET and CFLAGS_FOR_TARGET.
2021-09-03 16:26:09 +09:30

184 lines
5.4 KiB
Plaintext

# Expect script for ld-sh tests
# Copyright (C) 1995-2021 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 Ian Lance Taylor (ian@cygnus.com)
#
# Test SH relaxing. This tests the compiler and assembler as well as
# the linker.
if ![istarget sh*-*-*] {
return
}
set testsimple "SH simple relaxing"
if { ![is_elf_format] } {
unsupported $testsimple
} elseif { ![ld_assemble $as "-relax $srcdir/$subdir/sh1.s" tmpdir/sh1.o] } {
fail $testsimple
} elseif { ![ld_link $ld tmpdir/sh1 "-relax tmpdir/sh1.o"] } {
fail $testsimple
} elseif { ![ld_nm $nm "" tmpdir/sh1] } {
fail $testsimple
} elseif { ![info exists nm_output(bar)]
|| ![info exists nm_output(foo)]} {
send_log "bad output from nm\n"
verbose "bad output from nm"
fail $testsimple
} elseif {$nm_output(bar) != $nm_output(foo) + 0xc} {
send_log "foo == $nm_output(foo)\n"
verbose "foo == $nm_output(foo)"
send_log "bar == $nm_output(bar)\n"
verbose "bar == $nm_output(bar)"
fail $testsimple
} else {
pass $testsimple
}
set testsrec "SH relaxing to S-records"
if { ![remote_file host exists tmpdir/sh1] } {
unsupported $testsrec
} else {
if { [istarget sh*-linux-*] || [istarget sh-*-vxworks] } {
# On these "non-embedded" targets, the default ELF and srec start
# addresses will be SIZEOF_HEADERS bytes apart. Ensure consistency
# by feeding the ELF start address to the srec link line.
catch "exec $objdump -x tmpdir/sh1 | grep start\\ address | sed s/start\\ address//" entry_addr
set srec_relax_arg "-Ttext $entry_addr -relax --oformat srec tmpdir/sh1.o"
} else {
set srec_relax_arg "-relax --oformat srec tmpdir/sh1.o"
}
if ![ld_link $ld tmpdir/sh1.s1 $srec_relax_arg ] {
fail $testsrec
} else {
# The file name is embedded in the S-records, so create both
# files with the same name.
catch "exec rm -f tmpdir/sh1.s2" exec_output
send_log "mv tmpdir/sh1.s1 tmpdir/sh1.s2\n"
verbose "mv tmpdir/sh1.s1 tmpdir/sh1.s2"
catch "exec mv tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output
if ![string match "" $exec_output] {
send_log "$exec_output\n"
verbose "$exec_output"
fail $testsrec
} else {
send_log "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1\n"
verbose "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1"
catch "exec $objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1" exec_output
if ![string match "" $exec_output] {
send_log "$exec_output\n"
verbose "$exec_output"
fail $testsrec
} else {
send_log "cmp tmpdir/sh1.s1 tmpdir/sh1.s2\n"
verbose "cmp tmpdir/sh1.s1 tmpdir/sh1.s2"
catch "exec cmp tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output
set exec_output [prune_warnings $exec_output]
if ![string match "" $exec_output] {
send_log "$exec_output\n"
verbose "$exec_output"
fail $testsrec
} else {
pass $testsrec
}
}
}
}
}
set testadjsw8 "SH switch8 adjustment after relax"
if { ![is_elf_format] } {
unsupported $testadjsw8
} elseif { ![ld_assemble $as "-relax $srcdir/$subdir/adjsw8.s" tmpdir/adjsw8.o] } {
fail $testadjsw8
} elseif { ![ld_link $ld tmpdir/adjsw8 "-relax tmpdir/adjsw8.o"] } {
fail $testadjsw8
} else {
send_log "exec $objdump -s tmpdir/adjsw8\n"
verbose "exec $objdump -s tmpdir/adjsw8"
catch "exec $objdump -s tmpdir/adjsw8" exec_output
if [string match "*04080c00*" $exec_output] {
pass $testadjsw8
} else {
send_log "bad switch table\n"
verbose "bad switch table"
fail $testadjsw8
}
}
set testlink "SH relaxing"
set testjsr "SH confirm relaxing"
set testrun "SH relaxing execution"
if { ![check_compiler_available] } {
untested $testlink
untested $testjsr
untested $testrun
return
}
if [istarget sh*-*linux*] {
exec sed -e s/_main/main/ -e s/_trap/trap/ -e s/_stack/stack/ \
< $srcdir/$subdir/start.s >tmpdir/start.s
} else {
exec cp $srcdir/$subdir/start.s tmpdir/start.s
}
if {![ld_assemble $as "-relax tmpdir/start.s" tmpdir/start.o] \
|| ![ld_compile $CC_FOR_TARGET "-O -mrelax -foptimize-sibling-calls $srcdir/$subdir/sh2.c" tmpdir/sh2.o]} {
unsupported $testlink
unsupported $testjsr
unsupported $testrun
return
}
if ![ld_link $ld tmpdir/sh2 "-relax tmpdir/start.o tmpdir/sh2.o"] {
fail $testlink
unsupported $testjsr
unsupported $testrun
return
}
pass $testlink
send_log "$objdump -d tmpdir/sh2\n"
verbose "$objdump -d tmpdir/sh2"
catch "exec $objdump -d tmpdir/sh2" exec_output
if {[string match "*jsr*" $exec_output]
|| [string match "*jmp*" $exec_output]} {
fail $testjsr
} else {
pass $testjsr
}
if { ![info exists SIM] || [which $SIM] == 0 } {
untested $testrun
return
}
set status [catch "exec $SIM tmpdir/sh2" exec_output]
if { $status == 0 } {
pass $testrun
} else {
fail $testrun
}