binutils-gdb/ld/testsuite/ld-srec/srec.exp
Alan Modra d981640286 Run more ld tests when not native
Many of the ld tests are not run for cross builds, in some cases
because the test needs to run a newly linked executable, and in others
simply because it was easier to write the test for native only.  Even
when a test needs to run, it's good to compile and link to exercise
the linker.  So that's what this patch does.  I've also rid us of
the old ld_link procedure with all the HOSTING_CRT0 etc. setup.  It's
much simpler to just link with $CC.

This does mean that a cross build with cross-compiler installed but
no cross C-library will give lots of failures.  If that turns out to
be too annoying, I guess we can write a tcl procedure to detect it and
not run all the extra tests.

	* Makefile.am (bootstrap): Delete rule.
	(ld-partial, ld1, ld1-full, ld2, ld3): Likewise.
	(HOSTING_CRT0, HOSTING_SCRT0): Don't define.
	(HOSTING_LIBS, HOSTING_SLIBS, HOSTING_EMU): Likewise.
	* configure.ac (HOSTING_CRT0, HOSTING_SCRT0): Don't define.
	(HOSTING_LIBS, HOSTING_SLIBS): Likewise.
	* configure.host (HOSTING_CRT0, HOSTING_LIBS): Don't define.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* testsuite/config/default.exp (get_link_files): Delete.
	(HOSTING_CRT0, HOSTING_SCRT0, HOSTING_LIBS, HOSTING_SLIBS): Don't
	define.
	(ld_simple_link): Delete.
	* testsuite/lib/ld-lib.exp (default_ld_link): Delete
	(default_ld_simple_link): Rename to default_ld_link.
	(ld_simple_link_defsyms): Rename to ld_link_defsyms.
	(run_ld_link_tests): Use ld_link, not ld_simple_link.
	(run_cc_link_tests): Likewise.
	(run_ld_link_exec_tests): Use $CC or $CXX to link, not $ld.
	Don't run exe when not native, and return unsupported.
	* testsuite/ld-bootstrap/bootstrap.exp: Create gccld1 etc. dirs.
	Link ld1 etc. using $CC.
	* testsuite/ld-cdtest/cdtest.exp: Link cdtest using $CC.
	* testsuite/ld-checks/checks.exp: Use ld_link, not ld_simple_link.
	* testsuite/ld-cygwin/exe-export.exp: Likewise.
	* testsuite/ld-elf/binutils.exp: Likewise.
	* testsuite/ld-elf/eh-group.exp: Likewise.
	* testsuite/ld-elf/exclude.exp: Likewise.
	* testsuite/ld-elf/frame.exp: Likewise.
	* testsuite/ld-elf/sec-to-seg.exp: Likewise.
	* testsuite/ld-elf/tls_common.exp: Likewise.
	* testsuite/ld-elfcomm/elfcomm.exp: Likewise.
	* testsuite/ld-fastcall/fastcall.exp: Likewise.
	* testsuite/ld-gc/gc.exp: Likewise.
	* testsuite/ld-ifunc/binutils.exp: Likewise.
	* testsuite/ld-mep/mep.exp: Likewise.
	* testsuite/ld-mips-elf/mips-elf-flags.exp: Likewise.
	* testsuite/ld-mn10300/mn10300.exp: Likewise.
	* testsuite/ld-nios2/nios2.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-plugin/plugin.exp: Likewise.
	* testsuite/ld-scripts/align.exp: Likewise.
	* testsuite/ld-scripts/alignof.exp: Likewise.
	* testsuite/ld-scripts/assert.exp: Likewise.
	* testsuite/ld-scripts/defined.exp: Likewise.
	* testsuite/ld-scripts/extern.exp: Likewise.
	* testsuite/ld-scripts/log2.exp: Likewise.
	* testsuite/ld-scripts/map-address.exp: Likewise.
	* testsuite/ld-scripts/phdrs.exp: Likewise.
	* testsuite/ld-scripts/phdrs2.exp: Likewise.
	* testsuite/ld-scripts/script.exp: Likewise.
	* testsuite/ld-scripts/section-flags.exp: Likewise.
	* testsuite/ld-scripts/sizeof.exp: Likewise.
	* testsuite/ld-scripts/sysroot-prefix.exp: Likewise.
	* testsuite/ld-scripts/weak.exp: Likewise.
	* testsuite/ld-selective/selective.exp: Likewise.
	* testsuite/ld-sh/sh.exp: Likewise.
	* testsuite/ld-sh/sh64/relax.exp: Likewise.
	* testsuite/ld-sh/sh64/relfail.exp: Likewise.
	* testsuite/ld-srec/srec.exp: Likewise.
	* testsuite/ld-tic6x/tic6x.exp: Likewise.
	* testsuite/ld-undefined/weak-undef.exp: Likewise.
	* testsuite/ld-versados/versados.exp: Likewise.
	* testsuite/ld-x86-64/dwarfreloc.exp: Likewise.
	* testsuite/ld-xtensa/coalesce.exp: Likewise.
	* testsuite/ld-xtensa/diff_overflow.exp: Likewise.
	* testsuite/ld-xtensa/lcall.exp: Likewise.
	* testsuite/ld-elf/audit.exp: Run non-native too.
	* testsuite/ld-elf/compress.exp: Likewise.  Replace ld options with
	gcc -Wl, options.
	* testsuite/ld-elf/dwarf.exp: Run non-native too.  Use ld_link,
	not ld_simple_link.  Add -Wl,--no-as-needed to some tests.
	* testsuite/ld-elf/elf.exp: Run non-native too.  Formatting.
	* testsuite/ld-elf/indirect.exp: Run non-native too.  Add
	-Wl,--no-as-needed to most tests.
	* testsuite/ld-elf/shared.exp: Run non-native too.  Use braces
	to simplify quoting.  Set run_tests using [list] rather than
	brace assignment to expand $extralibs.  Add -Wl,--no-as-needed
	to many test.  Prefix ld options with -Wl,.
	(mix_pic_and_non_pic): Don't run exe if not native.
	* testsuite/ld-elf/wrap.exp: Run non-native too.  Add
	-Wl,--no-as-needed and prefix ld options with -Wl,.
	* testsuite/ld-elfvers/vers.exp: Run non-native too.  Use ld_link,
	not ld_simple_link.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	(visibility_test): Don't run exe if not native.
	* testsuite/ld-elfweak/elfweak.exp: Run non-native too.  Use ld_link,
	not ld_simple_link.
	(build_exec): Don't run exe if not native.
	* testsuite/ld-ifunc/ifunc.exp: Run non-native too.  Use ld_link,
	not ld_simple_link.  Link using $CC.  Add -Wl,--no-as-needed
	to some tests and prefix ld options with -Wl,.  Expect GNU
	for hppa-linux even when no ifuncs.  Delete cleanup.
	* testsuite/ld-pie/pie.exp: Run non-native too.
	* testsuite/ld-plugin/lto.exp: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.  Use ld_link,
	not ld_simple_link.
	(shared_test): Don't run exe if not native.
	* testsuite/ld-size/size.exp: Run non-native too.  Add
	-Wl,--no-as-needed to some tests.  Prefix ld options with -Wl,.
	* testsuite/ld-unique/unique.exp: Run non-native too.  Use ld_link,
	not ld_simple_link.  Link using $CC.  Add -Wl,--no-as-needed
	to some tests and prefix ld options with -Wl,.  Expect GNU
	for hppa-linux even when no unique syms.  Delete cleanup.
	* testsuite/ld-x86-64/tls.exp: Add -Wl,--no-as-needed to some
	tests and prefix ld options with -Wl,.
	* testsuite/ld-x86-64/x86-64.exp: Use ld_link, not ld_simple_link.
	Add -Wl,--no-as-needed to some tests.  Prefix ld options with -Wl,.
2017-01-02 23:48:08 +10:30

462 lines
12 KiB
Plaintext

# Test linking directly to S-records.
# By Ian Lance Taylor, Cygnus Support.
# Copyright (C) 1999-2017 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.
# Get the offset from an S-record line to the start of the data.
proc srec_off { l } {
if [string match "S1*" $l] {
return 8
} else { if [string match "S2*" $l] {
return 10
} else { if [string match "S3*" $l] {
return 12
} else {
return -1
} } }
}
# See if an S-record line contains only zero data.
proc srec_zero { l } {
if [string match "S\[0789\]*" $l] {
return 1
}
# Strip the address and checksum.
if [string match "S\[123\]*" $l] {
set l [string range $l [srec_off $l] [expr [string length $l] - 3]]
} else {
return 0
}
# The rest must be zero.
return [string match "" [string trim $l "0"]]
}
# Get the address of an S-record line.
proc srec_addr { l } {
if [string match "S\[123\]*" $l] {
set addr [string range $l 4 [expr [srec_off $l] - 1]]
} else {
return -1
}
return "0x$addr"
}
# Get the number of data bytes in an S-record line.
proc srec_len { l } {
if ![string match "S\[123\]*" $l] {
return 0
}
return [expr "0x[string range $l 2 3]" - ([srec_off $l] - 4) / 2 - 1]
}
# Extract bytes from an S-record line.
proc srec_extract { l start len } {
set off [srec_off $l]
set rlen [srec_len $l]
set stop [expr $start + $len]
if { $stop > $rlen } {
set stop [expr $rlen]
}
set start [expr $start * 2 + $off]
set stop [expr $stop * 2 + $off - 1]
return [string range $l $start $stop]
}
# See if a range of bytes in an S-record line is all zeroes.
proc srec_zero_range { l start len } {
return [string match "" [string trim [srec_extract $l $start $len] "0"]]
}
# Trim an S-record line such that the specified number of bytes remain
# at the end.
proc srec_trim { l leave } {
set off [srec_off $l]
set addr [srec_addr $l]
set len [srec_len $l]
if { $leave >= $len } {
return $l
}
set s1 [string range $l 0 1]
set s2 [format "%02x" [expr ($off - 4) / 2 + $leave + 1]]
set s3 [format "%0[expr $off - 4]x" [expr $addr + $len - $leave]]
set s4 [string range $l [expr [string length $l] - ($leave * 2) - 2] end]
set s "${s1}${s2}${s3}${s4}"
verbose "srec_trim { '$l' $leave } returning '$s'" 2
return $s
}
# Report failure when comparing S-record lines
proc srec_compare_fail { which l1 l2 } {
send_log "comparison failure $which:\n$l1\n$l2\n"
verbose "comparison failure $which:\n$l1\n$l2"
}
# Compare S-record files. We don't want to fuss about things like
# extra zeroes. Note that BFD always sorts S-records by address.
proc srec_compare { f1 f2 } {
set e1 [gets $f1 l1]
set e2 [gets $f2 l2]
while { $e1 != -1 } {
set l1 [string trimright $l1 "\r\n"]
set l2 [string trimright $l2 "\r\n"]
if { $e2 == -1 } {
# If l1 contains data, it must be zero.
if ![srec_zero $l1] {
send_log "data after EOF: $l1\n"
verbose "data after EOF: $l1"
return 0
}
} else { if { [string compare $l1 $l2] == 0 } {
set e1 [gets $f1 l1]
set e2 [gets $f2 l2]
} else { if { [srec_zero $l1] } {
set e1 [gets $f1 l1]
} else { if { [srec_zero $l2] } {
set e2 [gets $f2 l2]
} else {
# The strings are not the same, and neither is all zeroes.
set a1 [srec_addr $l1]
set n1 [srec_len $l1]
set a2 [srec_addr $l2]
set n2 [srec_len $l2]
if { $a1 < $a2 && ![srec_zero_range $l1 0 [expr $a2 - $a1]] } {
verbose "$a1 $a2 [srec_extract $l1 0 [expr $a2 - $a1]]" 2
srec_compare_fail 1 $l1 $l2
return 0
}
if { $a2 < $a1 && ![srec_zero_range $l2 0 [expr $a1 - $a2]] } {
srec_compare_fail 2 $l1 $l2
return 0
}
# Here we know that any initial data in both lines is
# zero. Now make sure that any overlapping data matches.
if { $a1 < $a2 } {
set os1 [expr $a2 - $a1]
set os2 0
} else {
set os1 0
set os2 [expr $a1 - $a2]
}
if { $a1 + $n1 < $a2 + $n2 } {
set ol [expr $n1 - $os1]
} else {
set ol [expr $n2 - $os2]
}
set x1 [srec_extract $l1 $os1 $ol]
set x2 [srec_extract $l2 $os2 $ol]
if { [string compare $x1 $x2] != 0 } {
verbose "$os1 $ol $x1" 2
verbose "$os2 $ol $x2" 2
srec_compare_fail 3 $l1 $l2
return 0
}
# These strings match. Trim the data from the larger
# string, read a new copy of the smaller string, and
# continue.
if { $a1 + $n1 < $a2 + $n2 } {
set l2 [srec_trim $l2 [expr ($a2 + $n2) - ($a1 + $n1)]]
set e1 [gets $f1 l1]
} else { if { $a1 + $n1 > $a2 + $n2 } {
set l1 [srec_trim $l1 [expr ($a1 + $n1) - ($a2 + $n2)]]
set e2 [gets $f2 l2]
} else {
set e1 [gets $f1 l1]
set e2 [gets $f2 l2]
} }
} } } }
}
# We've reached the end of the first file. The remainder of the
# second file must contain only zeroes.
while { $e2 != -1 } {
set l2 [string trimright $l2 "\r\n"]
if ![srec_zero $l2] {
send_log "data after EOF: $l2\n"
verbose "data after EOF: $l2"
return 0
}
set e2 [gets $f2 l2]
}
return 1
}
# Link twice, objcopy, and compare
proc run_srec_test { test objs } {
global ld
global objcopy
global sizeof_headers
global host_triplet
# Tell the ELF linker to not do anything clever with .eh_frame,
# not to put anything in small data, and define various symbols.
set flags "--traditional-format -G 0 "
append flags [ld_link_defsyms]
# If the linker script uses SIZEOF_HEADERS, use a -Ttext argument
# to force both the normal link and the S-record link to be put in
# the same place. We don't always use -Ttext because it interacts
# poorly with a.out.
if { $sizeof_headers } {
set flags "$flags -Ttext 0x1000"
}
# ARM targets cannot convert format in the linker
# using the --oformat command line switch
if {[istarget aarch64*-*-*] || \
[istarget arm*-*-*]} {
setup_xfail "aarch64-*-*"
setup_xfail "aarch64_be-*-*"
setup_xfail "arm*-*-*"
}
# The AVR target does not correctly process
# relocs when output format is not ELF.
if [istarget avr-*-*] {
setup_xfail "avr-*-*"
}
# Epiphany needs some help too
if [istarget epiphany*-*-*] {
set flags "$flags --defsym _start=00000060"
setup_xfail "epiphany*-*-*"
}
if [istarget m681*-*-*] {
set flags "$flags --defsym _start=0xc000"
setup_xfail "m681*-*-*"
}
if [istarget m68hc1*-*-*] {
set flags "$flags --defsym _start=0xc000"
setup_xfail "m68hc1*-*-*"
}
if [istarget m9s12x*-*-*] {
set flags "$flags --defsym _start=0xc000"
setup_xfail "m9s12x*-*-*"
}
# MSP430 targets always relax.
if [istarget msp430*-*-*] {
setup_xfail "msp430*-*-*"
}
# SH64 targets cannot convert format in the linker
# using the -oformat command line switch.
if [istarget sh64*-*-elf] {
# This is what gcc passes to ld by default.
set flags "$flags -mshelf32"
setup_xfail "sh64*-*-*"
}
# V850 targets need libgcc.a
if [istarget v850*-*-elf] {
set objs "$objs -L ../gcc -lgcc"
}
# Xtensa ELF targets relax by default; S-Record linker does not
if [istarget xtensa*-*-*] {
set flags "$flags -no-relax"
}
# PRU ELF target relaxes by default; S-Record linker does not
if [istarget pru*-*-*] {
set flags "$flags -no-relax"
}
if { ![ld_link $ld tmpdir/sr1 "$flags $objs"] \
|| ![ld_link $ld tmpdir/sr2.sr "$flags --oformat srec $objs"] } {
fail $test
return
}
send_log "$objcopy -O srec tmpdir/sr1 tmpdir/sr1.sr\n"
set exec_output [run_host_cmd "$objcopy" "-O srec tmpdir/sr1 tmpdir/sr1.sr"]
set exec_output [prune_warnings $exec_output]
if ![string match "" $exec_output] {
send_log "$exec_output\n"
verbose "$exec_output"
unresolved $test
return
}
set f1 [open tmpdir/sr1.sr r]
set f2 [open tmpdir/sr2.sr r]
if [srec_compare $f1 $f2] {
pass $test
} else {
fail $test
}
close $f1
close $f2
}
set test1 "S-records"
set test2 "S-records with constructors"
# See whether the default linker script uses SIZEOF_HEADERS.
set exec_output [run_host_cmd "$ld" "--verbose"]
set sizeof_headers [string match "*SIZEOF_HEADERS*" $exec_output]
# First test linking a C program. We don't require any libraries. We
# link it normally, and objcopy to the S-record format, and then link
# directly to the S-record format, and require that the two files
# contain the same data.
if { ![is_remote host] && [which $CC] == 0 } {
untested $test1
untested $test2
return
}
# Pass -fplt to CC and CXX since -fno-plt doesn't work with S-records
# tests.
global PLT_CFLAGS
set old_CC "$CC"
set CC "$CC $PLT_CFLAGS"
set old_CXX "$CXX"
set CXX "$CXX $PLT_CFLAGS"
if { ![ld_compile $CC $srcdir/$subdir/sr1.c tmpdir/sr1.o] \
|| ![ld_compile $CC $srcdir/$subdir/sr2.c tmpdir/sr2.o] } {
unresolved $test1
unresolved $test2
set CC "$old_CC"
set CXX "$old_CXX"
return
}
# The i386-aout target is confused: the linker does not put the
# sections where objdump finds them. I don't know which is wrong.
setup_xfail "i*86-*-aout*"
# These tests fail on the native MIPS ELF targets because the GP value
# in the .reginfo section is not updated when the S-record version is
# written out. The mips-elf target itself does not use a .reginfo section.
setup_xfail "mips*-*-irix5*" "mips*-*-irix6*" "mips*-*-linux*"
# The S-record linker doesn't do the magic TOC handling that XCOFF
# linkers do.
setup_xfail "*-*-aix*" "*-*-xcoff*"
# The S-record linker is not supported for ARC.
setup_xfail "arc*-*-*"
# The S-record linker doesn't build ARM/Thumb stubs.
setup_xfail "arm-*-coff"
setup_xfail "arm-*-pe*"
# setup_xfail "arm-*elf*"
setup_xfail "arm*-*-linux*"
# The S-record linker doesn't include the .{zda} sections.
setup_xfail "v850*-*-elf"
# The S-record linker doesn't handle Alpha Elf relaxation.
setup_xfail "alpha*-*-elf*" "alpha*-*-linux-*" "alpha*-*-gnu*"
setup_xfail "alpha*-*-netbsd*"
# The S-record linker hasn't any hope of coping with HPPA relocs.
# Or MeP complex relocs.
setup_xfail "hppa*-*-*" "mep-*-*"
# The S-record linker doesn't handle IA64 Elf relaxation.
setup_xfail "ia64-*-*"
# The S-record linker doesn't support the special PE headers - the PE
# emulation tries to write pe-specific information to the PE headers
# in the output bfd, but it's not a PE bfd (it's an srec bfd)
setup_xfail "*-*-cygwin*" "*-*-mingw*" "*-*-pe*" "*-*-winnt*"
setup_xfail "score-*-*"
# The S-record linker doesn't support Blackfin ELF FDPIC ABI.
setup_xfail "bfin-*-linux-uclibc"
# On tile, we appear to be getting some random-seeming zeroing or 24-bit
# rightshifts (!) in the output when directly generating S-records from
# the linker. Not clear what could be causing this but we don't
# anticipate creating s-records (and could always use objcopy to
# generate the format if need be).
setup_xfail "tile*-*-*"
run_srec_test $test1 "tmpdir/sr1.o tmpdir/sr2.o"
# Now try linking a C++ program with global constructors and
# destructors. Note that since we are not linking against any
# libraries, this program won't actually work or anything.
if { ![is_remote host] && [which $CXX] == 0 } {
untested $test2
set CC "$old_CC"
set CXX "$old_CXX"
return
}
if ![ld_compile "$CXX $CXXFLAGS -fno-exceptions" $srcdir/$subdir/sr3.cc tmpdir/sr3.o] {
unresolved $test2
set CC "$old_CC"
set CXX "$old_CXX"
return
}
# See above.
setup_xfail "i*86-*-aout*"
setup_xfail "mips*-*-irix5*" "mips*-*-irix6*" "mips*-*-linux*"
setup_xfail "*-*-aix*" "*-*-xcoff*"
setup_xfail "arc*-*-*"
setup_xfail "arm*-*-*"
setup_xfail "v850*-*-elf"
setup_xfail "alpha*-*-elf*" "alpha*-*-linux-*" "alpha*-*-gnu*"
setup_xfail "alpha*-*-netbsd*"
setup_xfail "hppa*-*-*" "mep-*-*"
setup_xfail "ia64-*-*"
setup_xfail "*-*-cygwin*" "*-*-mingw*" "*-*-pe*" "*-*-winnt*"
setup_xfail "score-*-*"
setup_xfail "bfin-*-linux-uclibc"
setup_xfail "tile*-*-*"
run_srec_test $test2 "tmpdir/sr3.o"
set CC "$old_CC"
set CXX "$old_CXX"