fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / binutils / ld / testsuite / ld-empic / empic.exp
blobf72b1f36c1c5d23a33dbddc473cf694fd96e115f
1 # Expect script for ld-empic tests
2 # Copyright 1994, 1995, 1996 Free Software Foundation, Inc.
4 # This file is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Written by Ian Lance Taylor (ian@cygnus.com)
21 # Test the handling of MIPS embedded PIC code. This test essentially
22 # tests the compiler and assembler as well as the linker, since MIPS
23 # embedded PIC is a GNU enhancement to standard MIPS tools.
25 # Embedded PIC is only supported for MIPS ECOFF targets.
26 if ![istarget mips*-*-ecoff*] {
27 return
30 set testname relax
32 if { [which $CC] == 0 } {
33 untested $testname
34 return
37 # Test that relaxation works correctly. This testsuite was composed
38 # (by experimentation) to force the linker to relax twice--that is,
39 # the first relaxation pass will force another call to be out of
40 # range, requiring a second relaxation pass.
41 if { ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir/$subdir/relax1.c tmpdir/relax1.o]
42 || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir/$subdir/relax2.c tmpdir/relax2.o]
43 || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir/$subdir/relax3.c tmpdir/relax3.o]
44 || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir/$subdir/relax4.c tmpdir/relax4.o] } {
45 unresolved $testname
46 return
49 if ![ld_simple_link $ld tmpdir/relax "--relax -T $srcdir/$subdir/relax.t tmpdir/relax1.o tmpdir/relax2.o tmpdir/relax3.o tmpdir/relax4.o"] {
50 fail $testname
51 } else {
52 # Check that the relaxation produced the correct result. Check
53 # each bal instruction. Some will go directly to the start of a
54 # function, which is OK. Some will form part of the five
55 # instruction expanded call sequence, in which case we compute the
56 # real destination and make sure it is the start of a function.
57 # Some bal instructions are used to locate the start of the
58 # function in order to do position independent addressing into the
59 # text section, in which case we just check that it correctly
60 # computes the start of the function.
62 # Get the symbol table.
63 if ![ld_nm $nm "" tmpdir/relax] {
64 unresolved $testname
65 return
68 # Get a disassembly.
69 send_log "$objdump -d tmpdir/relax >tmpdir/relax.dis\n"
70 verbose "$objdump -d tmpdir/relax >tmpdir/relax.dis"
71 catch "exec $objdump -d tmpdir/relax >tmpdir/relax.dis" exec_output
72 if ![string match "" $exec_output] {
73 send_log "$exec_output\n"
74 verbose $exec_output
75 unresolved $testname
76 return
79 set balcnt 0
80 set file [open tmpdir/relax.dis r]
81 while { [gets $file line] != -1 } {
82 verbose "$line" 2
84 if ![string match "*bal*" $line] {
85 continue
88 verbose "$line"
90 incr balcnt
92 if ![regexp "^(\[0-9a-fA-F\]+) (<\[a-z+0-9A-Z.\]+>)? bal (\[0-9a-fA-F\]+)" $line whole addr label dest] {
93 perror "unrecognized format for $line"
94 unresolved $testname
95 return
98 if "0x$addr + 8 != 0x$dest" {
99 # This is a straight function call. All function calls in
100 # this example are to either foo or bar.
101 if "0x$dest != $nm_output(foo) && 0x$dest != $nm_output(bar)" {
102 send_log "fail 1\n"
103 send_log "$line\n"
104 fail $testname
105 return
107 } else {
108 # Pick up the next line. If it is sll, this is a switch
109 # prologue, and there is not much we can do to test it.
110 # Otherwise, it should be lui, and the next instruction
111 # should be an addiu, followed by an addu to $31.
112 if { [gets $file l] == -1 } {
113 send_log "fail 2\n"
114 send_log "$line\n"
115 fail $testname
116 return
118 verbose $l
120 if [string match "*sll*" $l] {
121 continue
123 if ![regexp "lui (\[\$a-z0-9\]+),(\[0-9a-fA-Fx\]+)" $l whole reg upper] {
124 send_log "fail 3\n"
125 send_log "$line\n"
126 send_log "$l\n"
127 fail $testname
128 return
131 if { [gets $file l] == -1 } {
132 send_log "fail 4\n"
133 send_log "$line\n"
134 fail $testname
135 return
137 verbose "$l"
138 if ![regexp "addiu \\$reg,\\$reg,(\[-0-9\]+)" $l whole lower] {
139 send_log "fail 5\n"
140 send_log "$line\n"
141 send_log "$l\n"
142 send_log "addiu \\$reg,\\$reg,(\[-0-9\]+)\n"
143 fail $testname
144 return
147 if { [gets $file l] == -1 } {
148 send_log "fail 6\n"
149 send_log "$line\n"
150 fail $testname
151 return
153 verbose "$l"
154 if ![regexp "addu \\$reg,\\$reg,\\\$ra" $l] {
155 send_log "fail 7\n"
156 send_log "$line\n"
157 send_log "$l\n"
158 fail $testname
159 return
162 # The next line will be jalr in the case of an expanded
163 # call. Otherwise, the code is getting the start of the
164 # function, and the next line can be anything.
166 if { [gets $file l] == -1 } {
167 send_log "fail 8\n"
168 send_log "$line\n"
169 fail $testname
170 return
172 verbose "$l"
173 if [string match "*jalr*" $l] {
174 set dest [expr 0x$addr + 8 + ($upper << 16) + $lower]
175 if { $dest != $nm_output(foo) && $dest != $nm_output(bar) } {
176 send_log "fail 9\n"
177 send_log "$line\n"
178 fail $testname
179 return
181 } else {
182 set dest [expr ($upper << 16) + $lower]
183 if ![regexp "<(\[.a-z\]+)\\+(\[0-9a-fA-F\]+)>" $label whole base offset] {
184 send_log "fail 10\n"
185 send_log "$line\n"
186 fail $testname
187 return
189 set offset 0x$offset
190 if { $base == ".foo" } {
191 set offset [expr $offset - ($nm_output(foo) - 0x30)]
193 if { $offset + 8 != - $dest } {
194 send_log "fail 11\n"
195 send_log "$line\n"
196 fail $testname
197 return
203 close $file
205 if {$balcnt < 10} {
206 send_log "fail 12\n"
207 fail $testname
208 } else {
209 verbose "$balcnt bal instructions"
210 pass $testname
214 # We now test actually running embedded MIPS PIC code. This can only
215 # be done on a MIPS host with the same endianness as our target.
216 if [istarget mipsel-*-*] {
217 if ![ishost mips*-*-ultrix*] {
218 return
220 } else {
221 if ![ishost mips*-*-irix*] {
222 return
226 set testname "run embedded PIC code"
228 # Compile the program which will run the test. This code must be
229 # compiled for the host, not the target.
230 send_log "$CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir/$subdir/run.c\n"
231 verbose "$CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir/$subdir/run.c"
232 catch "exec $CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir/$subdir/run.c" exec_output
233 if ![string match "" $exec_output] {
234 send_log "$exec_output\n"
235 verbose "$exec_output"
236 unresolved $testname
237 return
240 # Compile and link the test.
241 if { ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir/$subdir/runtesti.s tmpdir/runtesti.o]
242 || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir/$subdir/runtest1.c tmpdir/runtest1.o]
243 || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir/$subdir/runtest2.c tmpdir/runtest2.o] } {
244 unresolved $testname
245 return
247 if ![ld_simple_link $ld tmpdir/runtest "--embedded-relocs tmpdir/runtesti.o tmpdir/runtest1.o tmpdir/runtest2.o"] {
248 fail $testname
249 } else {
250 # Now run the test.
251 send_log "tmpdir/run tmpdir/runtest\n"
252 verbose "tmpdir/run tmpdir/runtest"
253 catch "exec tmpdir/run tmpdir/runtest" exec_output
254 if [string match "*ran and returned 0*" $exec_output] {
255 send_log "$exec_output\n"
256 verbose "$exec_output"
257 pass $testname
258 } else {
259 send_log "$exec_output\n"
260 verbose "$exec_output"
261 fail $testname