Commit | Line | Data |
---|---|---|
3c247606 ILT |
1 | # Expect script for ld-empic tests |
2 | # Copyright (C) 1994 Free Software Foundation | |
3 | # | |
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. | |
13 | # | |
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., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
17 | # | |
18 | # Written by Ian Lance Taylor (ian@cygnus.com) | |
19 | # | |
20 | ||
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. | |
24 | ||
25 | # Embedded PIC is only supported for MIPS ECOFF targets. | |
26 | if ![istarget mips*-*-ecoff*] { return } | |
27 | ||
28 | # Test that relaxation works correctly. This testsuite was composed | |
29 | # (by experimentation) to force the linker to relax twice--that is, | |
30 | # the first relaxation pass will force another call to be out of | |
31 | # range, requiring a second relaxation pass. | |
32 | if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax1.c tmpdir/relax1.o] { | |
33 | return | |
34 | } | |
35 | if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax2.c tmpdir/relax2.o] { | |
36 | return | |
37 | } | |
38 | if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax3.c tmpdir/relax3.o] { | |
39 | return | |
40 | } | |
41 | if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax4.c tmpdir/relax4.o] { | |
42 | return | |
43 | } | |
44 | ||
45 | 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"] { | |
46 | fail relax | |
47 | } else { | |
48 | # Check that the relaxation produced the correct result. Check | |
49 | # each bal instruction. Some will go directly to the start of a | |
50 | # function, which is OK. Some will form part of the five | |
51 | # instruction expanded call sequence, in which case we compute the | |
52 | # real destination and make sure it is the start of a function. | |
53 | # Some bal instructions are used to locate the start of the | |
54 | # function in order to do position independent addressing into the | |
55 | # text section, in which case we just check that it correctly | |
56 | # computes the start of the function. | |
57 | ||
58 | # Get the symbol table. | |
59 | if ![ld_nm $nm tmpdir/relax] { | |
60 | return | |
61 | } | |
62 | ||
63 | # Get a disassembly. | |
64 | send_log "$objdump -d tmpdir/relax >tmpdir/relax.dis\n" | |
65 | verbose "$objdump -d tmpdir/relax >tmpdir/relax.dis" | |
66 | catch "exec $objdump -d tmpdir/relax >tmpdir/relax.dis" exec_output | |
67 | if ![string match "" $exec_output] { | |
68 | send_log "$exec_output\n" | |
69 | verbose $exec_output | |
70 | perror "tmpdir/relax: objdump failed" | |
71 | return | |
72 | } | |
73 | ||
74 | set balcnt 0 | |
75 | set file [open tmpdir/relax.dis r] | |
76 | while { [gets $file line] != -1 } { | |
77 | verbose "$line" 2 | |
78 | ||
79 | if ![string match "*bal*" $line] { | |
80 | continue | |
81 | } | |
82 | ||
83 | verbose "$line" | |
84 | ||
85 | incr balcnt | |
86 | ||
87 | if ![regexp "^(\[0-9a-fA-F\]+) (<\[a-z+0-9A-Z\]+>)? bal (\[0-9a-fA-F\]+)" $line whole addr label dest] { | |
88 | perror "unrecognized format for $line" | |
89 | return | |
90 | } | |
91 | ||
92 | if "0x$addr + 8 != 0x$dest" { | |
93 | # This is a straight function call. All function calls in | |
94 | # this example are to either foo or bar. | |
95 | if "0x$dest != $nm_output(foo) && 0x$dest != $nm_output(bar)" { | |
96 | send_log "$line\n" | |
97 | fail "relax (bad direct function call)" | |
98 | return | |
99 | } | |
100 | } else { | |
101 | # Pick up the next line. If it is sll, this is a switch | |
102 | # prologue, and there is not much we can do to test it. | |
103 | # Otherwise, it should be lui, and the next instruction | |
104 | # should be an addiu, followed by an addu to $31. | |
105 | if { [gets $file l] == -1 } { | |
106 | send_log "$line\n" | |
107 | fail "relax (unexpected EOF after bal)" | |
108 | return | |
109 | } | |
110 | verbose $l | |
111 | ||
112 | if [string match "*sll*" $l] { | |
113 | continue | |
114 | } | |
115 | if ![regexp "lui (\[\$a-z0-9\]+),(\[0-9\]+)" $l whole reg upper] { | |
116 | send_log "$line\n" | |
117 | send_log "$l\n" | |
118 | fail "relax (could not find expected lui)" | |
119 | return | |
120 | } | |
121 | ||
122 | if { [gets $file l] == -1 } { | |
123 | send_log "$line\n" | |
124 | fail "relax (unexpected EOF after lui)" | |
125 | return | |
126 | } | |
127 | verbose "$l" | |
128 | if ![regexp "addiu \\$reg,\\$reg,(\[-0-9\]+)" $l whole lower] { | |
129 | send_log "$line\n" | |
130 | send_log "$l\n" | |
131 | send_log "addiu \\$reg,\\$reg,(\[-0-9\]+)\n" | |
132 | fail "relax (could not find expected addiu)" | |
133 | return | |
134 | } | |
135 | ||
136 | if { [gets $file l] == -1 } { | |
137 | send_log "$line\n" | |
138 | fail "relax (unexpected EOF after addiu)" | |
139 | return | |
140 | } | |
141 | verbose "$l" | |
142 | if ![regexp "addu \\$reg,\\$reg,\\\$ra" $l] { | |
143 | send_log "$line\n" | |
144 | send_log "$l\n" | |
145 | fail "relax (could not find expected addu)" | |
146 | return | |
147 | } | |
148 | ||
149 | # The next line will be jalr in the case of an expanded | |
150 | # call. Otherwise, the code is getting the start of the | |
151 | # function, and the next line can be anything. | |
152 | ||
153 | if { [gets $file l] == -1 } { | |
154 | send_log "$line\n" | |
155 | fail "relax (unexpected EOF after addu)" | |
156 | return | |
157 | } | |
158 | ||
159 | if [string match "*jalr*" $l] { | |
160 | set dest [expr 0x$addr + 8 + ($upper << 16) + $lower] | |
161 | if { $dest != $nm_output(foo) && $dest != $nm_output(bar) } { | |
162 | send_log "$line\n" | |
163 | fail "relax (bad expanded function call)" | |
164 | return | |
165 | } | |
166 | } else { | |
167 | set dest [expr ($upper << 16) + $lower] | |
168 | if ![regexp "<\[a-z\]+\\+(\[0-9a-fA-F\]+)>" $label whole offset] { | |
169 | send_log "$line\n" | |
170 | fail "relax (unrecognized label)" | |
171 | return | |
172 | } | |
173 | if "0x$offset + 8 != - $dest" { | |
174 | send_log "$line\n" | |
175 | fail "relax (bad function start: 0x$offset + 8 != - $dest)" | |
176 | return | |
177 | } | |
178 | } | |
179 | } | |
180 | } | |
181 | ||
182 | close $file | |
183 | ||
184 | if {$balcnt < 10} { | |
185 | fail "relax (not enough branches)" | |
186 | } else { | |
187 | verbose "$balcnt bal instructions" | |
188 | pass relax | |
189 | } | |
190 | } | |
191 | ||
192 | # We now test actually running embedded MIPS PIC code. This can only | |
193 | # be done on a MIPS host with the same endianness as our target. | |
194 | if [istarget mipsel-*-*] { | |
195 | if ![ishost mips*-*-ultrix*] { | |
196 | return | |
197 | } | |
198 | } else { | |
199 | if ![ishost mips*-*-irix*] { | |
200 | return | |
201 | } | |
202 | } | |
203 | ||
204 | # Compile the program which will run the test. This code must be | |
205 | # compiled for the host, not the target. | |
206 | send_log "$CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir$subdir/run.c\n" | |
207 | verbose "$CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir$subdir/run.c" | |
208 | catch "exec $CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir$subdir/run.c" exec_output | |
209 | if ![string match "" $exec_output] { | |
210 | send_log "$exec_output\n" | |
211 | verbose "$exec_output" | |
212 | perror "$srcdir$subdir/run.c: compilation failed" | |
213 | return | |
214 | } | |
215 | ||
216 | # Compile and link the test. | |
217 | if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtesti.s tmpdir/runtesti.o] { | |
218 | return | |
219 | } | |
220 | if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtest1.c tmpdir/runtest1.o] { | |
221 | return | |
222 | } | |
223 | if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtest2.c tmpdir/runtest2.o] { | |
224 | return | |
225 | } | |
226 | if ![ld_simple_link $ld tmpdir/runtest "--embedded-relocs tmpdir/runtesti.o tmpdir/runtest1.o tmpdir/runtest2.o"] { | |
227 | fail "run embedded PIC code (link)" | |
228 | } else { | |
229 | # Now run the test. | |
230 | send_log "tmpdir/run tmpdir/runtest\n" | |
231 | verbose "tmpdir/run tmpdir/runtest" | |
232 | catch "exec tmpdir/run tmpdir/runtest" exec_output | |
233 | if [string match "*ran and returned 0*" $exec_output] { | |
234 | send_log "$exec_output\n" | |
235 | verbose "$exec_output" | |
236 | pass "run embedded PIC code" | |
237 | } else { | |
238 | send_log "$exec_output\n" | |
239 | verbose "$exec_output" | |
240 | fail "run embedded PIC code" | |
241 | } | |
242 | } |