]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | # Expect script for ld-sh tests |
2571583a | 2 | # Copyright (C) 1995-2017 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 | ||
f19ae42f | 31 | if { ([istarget sh64*-*-*] || [istarget sh5*-*-*])} { |
1b19eb81 AO |
32 | # relaxing not supported on sh64 yet. |
33 | return | |
34 | } | |
35 | ||
252b5132 RH |
36 | set testsimple "SH simple relaxing" |
37 | ||
38 | if ![ld_assemble $as "-relax $srcdir/$subdir/sh1.s" tmpdir/sh1.o] { | |
39 | unresolved $testsimple | |
d9816402 | 40 | } else { if ![ld_link $ld tmpdir/sh1 "-relax tmpdir/sh1.o"] { |
252b5132 RH |
41 | fail $testsimple |
42 | } else { | |
992c450d | 43 | if ![ld_nm $nm "" tmpdir/sh1] { |
252b5132 RH |
44 | unresolved $testsimple |
45 | } else { | |
46 | if {![info exists nm_output(bar)] \ | |
47 | || ![info exists nm_output(foo)]} { | |
48 | send_log "bad output from nm\n" | |
49 | verbose "bad output from nm" | |
50 | fail $testsimple | |
51 | } else { | |
8c784016 | 52 | if {$nm_output(bar) != $nm_output(foo) + 0xc} { |
252b5132 RH |
53 | send_log "foo == $nm_output(foo)\n" |
54 | verbose "foo == $nm_output(foo)" | |
55 | send_log "bar == $nm_output(bar)\n" | |
56 | verbose "bar == $nm_output(bar)" | |
57 | fail $testsimple | |
58 | } else { | |
59 | pass $testsimple | |
60 | } | |
61 | } | |
62 | } | |
63 | } } | |
64 | ||
65 | set testsrec "SH relaxing to S-records" | |
66 | ||
55e6e397 RS |
67 | if { [istarget sh*-linux-*] || [istarget sh-*-vxworks] } { |
68 | # On these "non-embedded" targets, the default ELF and srec start | |
69 | # addresses will be SIZEOF_HEADERS bytes apart. Ensure consistency | |
70 | # by feeding the ELF start address to the srec link line. | |
1e329ce6 NC |
71 | catch "exec $objdump -x tmpdir/sh1 | grep start\\ address | sed s/start\\ address//" entry_addr |
72 | set srec_relax_arg "-Ttext $entry_addr -relax --oformat srec tmpdir/sh1.o" | |
73 | } else { | |
74 | set srec_relax_arg "-relax --oformat srec tmpdir/sh1.o" | |
75 | } | |
d9816402 | 76 | if ![ld_link $ld tmpdir/sh1.s1 $srec_relax_arg ] { |
252b5132 RH |
77 | fail $testsrec |
78 | } else { | |
79 | # The file name is embedded in the S-records, so create both | |
80 | # files with the same name. | |
81 | catch "exec rm -f tmpdir/sh1.s2" exec_output | |
82 | send_log "mv tmpdir/sh1.s1 tmpdir/sh1.s2\n" | |
83 | verbose "mv tmpdir/sh1.s1 tmpdir/sh1.s2" | |
84 | catch "exec mv tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output | |
85 | if ![string match "" $exec_output] { | |
86 | send_log "$exec_output\n" | |
87 | verbose "$exec_output" | |
88 | unresolved $testsrec | |
89 | } else { | |
d898aefb | 90 | send_log "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1\n" |
252b5132 RH |
91 | verbose "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1" |
92 | catch "exec $objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1" exec_output | |
93 | if ![string match "" $exec_output] { | |
94 | send_log "$exec_output\n" | |
95 | verbose "$exec_output" | |
96 | unresolved $testsrec | |
97 | } else { | |
98 | send_log "cmp tmpdir/sh1.s1 tmpdir/sh1.s2\n" | |
99 | verbose "cmp tmpdir/sh1.s1 tmpdir/sh1.s2" | |
100 | catch "exec cmp tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output | |
101 | set exec_output [prune_warnings $exec_output] | |
102 | if ![string match "" $exec_output] { | |
103 | send_log "$exec_output\n" | |
104 | verbose "$exec_output" | |
105 | fail $testsrec | |
106 | } else { | |
107 | pass $testsrec | |
108 | } | |
109 | } | |
110 | } | |
111 | } | |
112 | ||
b131d1fc KK |
113 | set testadjsw8 "SH switch8 adjustment after relax" |
114 | if ![ld_assemble $as "-relax $srcdir/$subdir/adjsw8.s" tmpdir/adjsw8.o] { | |
115 | unresolved $testadjsw8 | |
116 | } else { | |
d9816402 | 117 | if ![ld_link $ld tmpdir/adjsw8 "-relax tmpdir/adjsw8.o"] { |
b131d1fc KK |
118 | fail $testadjsw8 |
119 | } else { | |
120 | send_log "exec $objdump -s tmpdir/adjsw8\n" | |
121 | verbose "exec $objdump -s tmpdir/adjsw8" | |
122 | catch "exec $objdump -s tmpdir/adjsw8" exec_output | |
123 | if [string match "*04080c00*" $exec_output] { | |
124 | pass $testadjsw8 | |
125 | } else { | |
126 | send_log "bad switch table\n" | |
127 | verbose "bad switch table" | |
128 | fail $testadjsw8 | |
129 | } | |
130 | } | |
131 | } | |
132 | ||
252b5132 RH |
133 | set testlink "SH relaxing" |
134 | set testjsr "SH confirm relaxing" | |
135 | set testrun "SH relaxing execution" | |
136 | ||
137 | if { [which $CC] == 0 } { | |
138 | untested $testlink | |
139 | untested $testjsr | |
140 | untested $testrun | |
141 | return | |
142 | } | |
143 | ||
8e45593f | 144 | if [istarget sh*-*linux*] { |
dc5e727b NC |
145 | exec sed -e s/_main/main/ -e s/_trap/trap/ -e s/_stack/stack/ \ |
146 | < $srcdir/$subdir/start.s >tmpdir/start.s | |
147 | } else { | |
8b8c5dbd | 148 | exec cp $srcdir/$subdir/start.s tmpdir/start.s |
dc5e727b NC |
149 | } |
150 | ||
151 | if {![ld_assemble $as "-relax tmpdir/start.s" tmpdir/start.o] \ | |
8c784016 | 152 | || ![ld_compile $CC "-O -mrelax -foptimize-sibling-calls $srcdir/$subdir/sh2.c" tmpdir/sh2.o]} { |
252b5132 RH |
153 | unresolved $testlink |
154 | unresolved $testjsr | |
155 | unresolved $testrun | |
156 | return | |
157 | } | |
158 | ||
d9816402 | 159 | if ![ld_link $ld tmpdir/sh2 "-relax tmpdir/start.o tmpdir/sh2.o"] { |
252b5132 RH |
160 | fail $testlink |
161 | unresolved $testjsr | |
162 | unresolved $testrun | |
163 | return | |
164 | } | |
165 | ||
166 | pass $testlink | |
167 | ||
168 | send_log "$objdump -d tmpdir/sh2\n" | |
169 | verbose "$objdump -d tmpdir/sh2" | |
170 | catch "exec $objdump -d tmpdir/sh2" exec_output | |
8c784016 KK |
171 | if {[string match "*jsr*" $exec_output] |
172 | || [string match "*jmp*" $exec_output]} { | |
252b5132 RH |
173 | fail $testjsr |
174 | } else { | |
175 | pass $testjsr | |
176 | } | |
177 | ||
178 | if { ![info exists SIM] || [which $SIM] == 0 } { | |
179 | untested $testrun | |
180 | return | |
181 | } | |
182 | ||
183 | set status [catch "exec $SIM tmpdir/sh2" exec_output] | |
184 | if { $status == 0 } { | |
185 | pass $testrun | |
186 | } else { | |
187 | fail $testrun | |
188 | } |