]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | # Expect script for ld-sh tests |
82704155 | 2 | # Copyright (C) 1995-2019 Free Software Foundation, Inc. |
252b5132 | 3 | # |
f96b4a7b NC |
4 | # This file is part of the GNU Binutils. |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
252b5132 | 7 | # it under the terms of the GNU General Public License as published by |
f96b4a7b | 8 | # the Free Software Foundation; either version 3 of the License, or |
252b5132 | 9 | # (at your option) any later version. |
f96b4a7b | 10 | # |
252b5132 RH |
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. | |
f96b4a7b | 15 | # |
252b5132 RH |
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 | |
f96b4a7b NC |
18 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | # MA 02110-1301, USA. | |
252b5132 RH |
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 | ||
27 | if ![istarget sh*-*-*] { | |
28 | return | |
29 | } | |
30 | ||
31 | set testsimple "SH simple relaxing" | |
32 | ||
33 | if ![ld_assemble $as "-relax $srcdir/$subdir/sh1.s" tmpdir/sh1.o] { | |
34 | unresolved $testsimple | |
d9816402 | 35 | } else { if ![ld_link $ld tmpdir/sh1 "-relax tmpdir/sh1.o"] { |
252b5132 RH |
36 | fail $testsimple |
37 | } else { | |
992c450d | 38 | if ![ld_nm $nm "" tmpdir/sh1] { |
252b5132 RH |
39 | unresolved $testsimple |
40 | } else { | |
41 | if {![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 | } else { | |
8c784016 | 47 | if {$nm_output(bar) != $nm_output(foo) + 0xc} { |
252b5132 RH |
48 | send_log "foo == $nm_output(foo)\n" |
49 | verbose "foo == $nm_output(foo)" | |
50 | send_log "bar == $nm_output(bar)\n" | |
51 | verbose "bar == $nm_output(bar)" | |
52 | fail $testsimple | |
53 | } else { | |
54 | pass $testsimple | |
55 | } | |
56 | } | |
57 | } | |
58 | } } | |
59 | ||
60 | set testsrec "SH relaxing to S-records" | |
61 | ||
55e6e397 RS |
62 | if { [istarget sh*-linux-*] || [istarget sh-*-vxworks] } { |
63 | # On these "non-embedded" targets, the default ELF and srec start | |
64 | # addresses will be SIZEOF_HEADERS bytes apart. Ensure consistency | |
65 | # by feeding the ELF start address to the srec link line. | |
1e329ce6 NC |
66 | catch "exec $objdump -x tmpdir/sh1 | grep start\\ address | sed s/start\\ address//" entry_addr |
67 | set srec_relax_arg "-Ttext $entry_addr -relax --oformat srec tmpdir/sh1.o" | |
68 | } else { | |
69 | set srec_relax_arg "-relax --oformat srec tmpdir/sh1.o" | |
70 | } | |
d9816402 | 71 | if ![ld_link $ld tmpdir/sh1.s1 $srec_relax_arg ] { |
252b5132 RH |
72 | fail $testsrec |
73 | } else { | |
74 | # The file name is embedded in the S-records, so create both | |
75 | # files with the same name. | |
76 | catch "exec rm -f tmpdir/sh1.s2" exec_output | |
77 | send_log "mv tmpdir/sh1.s1 tmpdir/sh1.s2\n" | |
78 | verbose "mv tmpdir/sh1.s1 tmpdir/sh1.s2" | |
79 | catch "exec mv tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output | |
80 | if ![string match "" $exec_output] { | |
81 | send_log "$exec_output\n" | |
82 | verbose "$exec_output" | |
83 | unresolved $testsrec | |
84 | } else { | |
d898aefb | 85 | send_log "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1\n" |
252b5132 RH |
86 | verbose "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1" |
87 | catch "exec $objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1" exec_output | |
88 | if ![string match "" $exec_output] { | |
89 | send_log "$exec_output\n" | |
90 | verbose "$exec_output" | |
91 | unresolved $testsrec | |
92 | } else { | |
93 | send_log "cmp tmpdir/sh1.s1 tmpdir/sh1.s2\n" | |
94 | verbose "cmp tmpdir/sh1.s1 tmpdir/sh1.s2" | |
95 | catch "exec cmp tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output | |
96 | set exec_output [prune_warnings $exec_output] | |
97 | if ![string match "" $exec_output] { | |
98 | send_log "$exec_output\n" | |
99 | verbose "$exec_output" | |
100 | fail $testsrec | |
101 | } else { | |
102 | pass $testsrec | |
103 | } | |
104 | } | |
105 | } | |
106 | } | |
107 | ||
b131d1fc KK |
108 | set testadjsw8 "SH switch8 adjustment after relax" |
109 | if ![ld_assemble $as "-relax $srcdir/$subdir/adjsw8.s" tmpdir/adjsw8.o] { | |
110 | unresolved $testadjsw8 | |
111 | } else { | |
d9816402 | 112 | if ![ld_link $ld tmpdir/adjsw8 "-relax tmpdir/adjsw8.o"] { |
b131d1fc KK |
113 | fail $testadjsw8 |
114 | } else { | |
115 | send_log "exec $objdump -s tmpdir/adjsw8\n" | |
116 | verbose "exec $objdump -s tmpdir/adjsw8" | |
117 | catch "exec $objdump -s tmpdir/adjsw8" exec_output | |
118 | if [string match "*04080c00*" $exec_output] { | |
119 | pass $testadjsw8 | |
120 | } else { | |
121 | send_log "bad switch table\n" | |
122 | verbose "bad switch table" | |
123 | fail $testadjsw8 | |
124 | } | |
125 | } | |
126 | } | |
127 | ||
252b5132 RH |
128 | set testlink "SH relaxing" |
129 | set testjsr "SH confirm relaxing" | |
130 | set testrun "SH relaxing execution" | |
131 | ||
132 | if { [which $CC] == 0 } { | |
133 | untested $testlink | |
134 | untested $testjsr | |
135 | untested $testrun | |
136 | return | |
137 | } | |
138 | ||
8e45593f | 139 | if [istarget sh*-*linux*] { |
dc5e727b NC |
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 { | |
8b8c5dbd | 143 | exec cp $srcdir/$subdir/start.s tmpdir/start.s |
dc5e727b NC |
144 | } |
145 | ||
146 | if {![ld_assemble $as "-relax tmpdir/start.s" tmpdir/start.o] \ | |
8c784016 | 147 | || ![ld_compile $CC "-O -mrelax -foptimize-sibling-calls $srcdir/$subdir/sh2.c" tmpdir/sh2.o]} { |
252b5132 RH |
148 | unresolved $testlink |
149 | unresolved $testjsr | |
150 | unresolved $testrun | |
151 | return | |
152 | } | |
153 | ||
d9816402 | 154 | if ![ld_link $ld tmpdir/sh2 "-relax tmpdir/start.o tmpdir/sh2.o"] { |
252b5132 RH |
155 | fail $testlink |
156 | unresolved $testjsr | |
157 | unresolved $testrun | |
158 | return | |
159 | } | |
160 | ||
161 | pass $testlink | |
162 | ||
163 | send_log "$objdump -d tmpdir/sh2\n" | |
164 | verbose "$objdump -d tmpdir/sh2" | |
165 | catch "exec $objdump -d tmpdir/sh2" exec_output | |
8c784016 KK |
166 | if {[string match "*jsr*" $exec_output] |
167 | || [string match "*jmp*" $exec_output]} { | |
252b5132 RH |
168 | fail $testjsr |
169 | } else { | |
170 | pass $testjsr | |
171 | } | |
172 | ||
173 | if { ![info exists SIM] || [which $SIM] == 0 } { | |
174 | untested $testrun | |
175 | return | |
176 | } | |
177 | ||
178 | set status [catch "exec $SIM tmpdir/sh2" exec_output] | |
179 | if { $status == 0 } { | |
180 | pass $testrun | |
181 | } else { | |
182 | fail $testrun | |
183 | } |