1# Expect script for ld-sh tests 2# Copyright (C) 1995-2020 Free Software Foundation, Inc. 3# 4# This file is part of the GNU Binutils. 5# 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 3 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, write to the Free Software 18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19# MA 02110-1301, USA. 20# 21# Written by Ian Lance Taylor (ian@cygnus.com) 22# 23 24# Test SH relaxing. This tests the compiler and assembler as well as 25# the linker. 26 27if ![istarget sh*-*-*] { 28 return 29} 30 31set testsimple "SH simple relaxing" 32 33if { ![is_elf_format] } { 34 unresolved $testsimple 35} elseif { ![ld_assemble $as "-relax $srcdir/$subdir/sh1.s" tmpdir/sh1.o] } { 36 fail $testsimple 37} elseif { ![ld_link $ld tmpdir/sh1 "-relax tmpdir/sh1.o"] } { 38 fail $testsimple 39} elseif { ![ld_nm $nm "" tmpdir/sh1] } { 40 fail $testsimple 41} elseif { ![info exists nm_output(bar)] 42 || ![info exists nm_output(foo)]} { 43 send_log "bad output from nm\n" 44 verbose "bad output from nm" 45 fail $testsimple 46} elseif {$nm_output(bar) != $nm_output(foo) + 0xc} { 47 send_log "foo == $nm_output(foo)\n" 48 verbose "foo == $nm_output(foo)" 49 send_log "bar == $nm_output(bar)\n" 50 verbose "bar == $nm_output(bar)" 51 fail $testsimple 52} else { 53 pass $testsimple 54} 55 56set testsrec "SH relaxing to S-records" 57 58if { ![remote_file host exists tmpdir/sh1] } { 59 unresolved $testsrec 60} else { 61 if { [istarget sh*-linux-*] || [istarget sh-*-vxworks] } { 62 # On these "non-embedded" targets, the default ELF and srec start 63 # addresses will be SIZEOF_HEADERS bytes apart. Ensure consistency 64 # by feeding the ELF start address to the srec link line. 65 catch "exec $objdump -x tmpdir/sh1 | grep start\\ address | sed s/start\\ address//" entry_addr 66 set srec_relax_arg "-Ttext $entry_addr -relax --oformat srec tmpdir/sh1.o" 67 } else { 68 set srec_relax_arg "-relax --oformat srec tmpdir/sh1.o" 69 } 70 if ![ld_link $ld tmpdir/sh1.s1 $srec_relax_arg ] { 71 fail $testsrec 72 } else { 73 # The file name is embedded in the S-records, so create both 74 # files with the same name. 75 catch "exec rm -f tmpdir/sh1.s2" exec_output 76 send_log "mv tmpdir/sh1.s1 tmpdir/sh1.s2\n" 77 verbose "mv tmpdir/sh1.s1 tmpdir/sh1.s2" 78 catch "exec mv tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output 79 if ![string match "" $exec_output] { 80 send_log "$exec_output\n" 81 verbose "$exec_output" 82 unresolved $testsrec 83 } else { 84 send_log "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1\n" 85 verbose "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1" 86 catch "exec $objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1" exec_output 87 if ![string match "" $exec_output] { 88 send_log "$exec_output\n" 89 verbose "$exec_output" 90 unresolved $testsrec 91 } else { 92 send_log "cmp tmpdir/sh1.s1 tmpdir/sh1.s2\n" 93 verbose "cmp tmpdir/sh1.s1 tmpdir/sh1.s2" 94 catch "exec cmp tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output 95 set exec_output [prune_warnings $exec_output] 96 if ![string match "" $exec_output] { 97 send_log "$exec_output\n" 98 verbose "$exec_output" 99 fail $testsrec 100 } else { 101 pass $testsrec 102 } 103 } 104 } 105 } 106} 107 108set testadjsw8 "SH switch8 adjustment after relax" 109if { ![is_elf_format] } { 110 unresolved $testadjsw8 111} elseif { ![ld_assemble $as "-relax $srcdir/$subdir/adjsw8.s" tmpdir/adjsw8.o] } { 112 fail $testadjsw8 113} elseif { ![ld_link $ld tmpdir/adjsw8 "-relax tmpdir/adjsw8.o"] } { 114 fail $testadjsw8 115} else { 116 send_log "exec $objdump -s tmpdir/adjsw8\n" 117 verbose "exec $objdump -s tmpdir/adjsw8" 118 catch "exec $objdump -s tmpdir/adjsw8" exec_output 119 if [string match "*04080c00*" $exec_output] { 120 pass $testadjsw8 121 } else { 122 send_log "bad switch table\n" 123 verbose "bad switch table" 124 fail $testadjsw8 125 } 126} 127 128set testlink "SH relaxing" 129set testjsr "SH confirm relaxing" 130set testrun "SH relaxing execution" 131 132if { ![check_compiler_available] } { 133 untested $testlink 134 untested $testjsr 135 untested $testrun 136 return 137} 138 139if [istarget sh*-*linux*] { 140 exec sed -e s/_main/main/ -e s/_trap/trap/ -e s/_stack/stack/ \ 141 < $srcdir/$subdir/start.s >tmpdir/start.s 142} else { 143 exec cp $srcdir/$subdir/start.s tmpdir/start.s 144} 145 146if {![ld_assemble $as "-relax tmpdir/start.s" tmpdir/start.o] \ 147 || ![ld_compile $CC "-O -mrelax -foptimize-sibling-calls $srcdir/$subdir/sh2.c" tmpdir/sh2.o]} { 148 unresolved $testlink 149 unresolved $testjsr 150 unresolved $testrun 151 return 152} 153 154if ![ld_link $ld tmpdir/sh2 "-relax tmpdir/start.o tmpdir/sh2.o"] { 155 fail $testlink 156 unresolved $testjsr 157 unresolved $testrun 158 return 159} 160 161pass $testlink 162 163send_log "$objdump -d tmpdir/sh2\n" 164verbose "$objdump -d tmpdir/sh2" 165catch "exec $objdump -d tmpdir/sh2" exec_output 166if {[string match "*jsr*" $exec_output] 167 || [string match "*jmp*" $exec_output]} { 168 fail $testjsr 169} else { 170 pass $testjsr 171} 172 173if { ![info exists SIM] || [which $SIM] == 0 } { 174 untested $testrun 175 return 176} 177 178set status [catch "exec $SIM tmpdir/sh2" exec_output] 179if { $status == 0 } { 180 pass $testrun 181} else { 182 fail $testrun 183} 184