fsf address update, but not in COPYING files
[deliverable/binutils-gdb.git] / ld / testsuite / ld-empic / empic.exp
CommitLineData
3c247606 1# Expect script for ld-empic tests
2a056eaf 2# Copyright (C) 1994,1995 Free Software Foundation
3c247606
ILT
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
943fbd5b 16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
3c247606
ILT
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.
2a056eaf
ILT
26if ![istarget mips*-*-ecoff*] {
27 return
28}
29
30set testname relax
3c247606
ILT
31
32# Test that relaxation works correctly. This testsuite was composed
33# (by experimentation) to force the linker to relax twice--that is,
34# the first relaxation pass will force another call to be out of
35# range, requiring a second relaxation pass.
2a056eaf
ILT
36if { ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax1.c tmpdir/relax1.o]
37 || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax2.c tmpdir/relax2.o]
38 || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax3.c tmpdir/relax3.o]
39 || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax4.c tmpdir/relax4.o] } {
40 unresolved $testname
3c247606
ILT
41 return
42}
43
44if ![ld_simple_link $ld tmpdir/relax "--relax -T $srcdir$subdir/relax.t tmpdir/relax1.o tmpdir/relax2.o tmpdir/relax3.o tmpdir/relax4.o"] {
2a056eaf 45 fail $testname
3c247606
ILT
46} else {
47 # Check that the relaxation produced the correct result. Check
48 # each bal instruction. Some will go directly to the start of a
49 # function, which is OK. Some will form part of the five
50 # instruction expanded call sequence, in which case we compute the
51 # real destination and make sure it is the start of a function.
52 # Some bal instructions are used to locate the start of the
53 # function in order to do position independent addressing into the
54 # text section, in which case we just check that it correctly
55 # computes the start of the function.
56
57 # Get the symbol table.
58 if ![ld_nm $nm tmpdir/relax] {
2a056eaf 59 unresolved $testname
3c247606
ILT
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
2a056eaf 70 unresolved $testname
3c247606
ILT
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"
2a056eaf 89 unresolved $testname
3c247606
ILT
90 return
91 }
92
93 if "0x$addr + 8 != 0x$dest" {
94 # This is a straight function call. All function calls in
95 # this example are to either foo or bar.
96 if "0x$dest != $nm_output(foo) && 0x$dest != $nm_output(bar)" {
97 send_log "$line\n"
2a056eaf 98 fail $testname
3c247606
ILT
99 return
100 }
101 } else {
102 # Pick up the next line. If it is sll, this is a switch
103 # prologue, and there is not much we can do to test it.
104 # Otherwise, it should be lui, and the next instruction
105 # should be an addiu, followed by an addu to $31.
106 if { [gets $file l] == -1 } {
107 send_log "$line\n"
2a056eaf 108 fail $testname
3c247606
ILT
109 return
110 }
111 verbose $l
112
113 if [string match "*sll*" $l] {
114 continue
115 }
116 if ![regexp "lui (\[\$a-z0-9\]+),(\[0-9\]+)" $l whole reg upper] {
117 send_log "$line\n"
118 send_log "$l\n"
2a056eaf 119 fail $testname
3c247606
ILT
120 return
121 }
122
123 if { [gets $file l] == -1 } {
124 send_log "$line\n"
2a056eaf 125 fail $testname
3c247606
ILT
126 return
127 }
128 verbose "$l"
129 if ![regexp "addiu \\$reg,\\$reg,(\[-0-9\]+)" $l whole lower] {
130 send_log "$line\n"
131 send_log "$l\n"
132 send_log "addiu \\$reg,\\$reg,(\[-0-9\]+)\n"
2a056eaf 133 fail $testname
3c247606
ILT
134 return
135 }
136
137 if { [gets $file l] == -1 } {
138 send_log "$line\n"
2a056eaf 139 fail $testname
3c247606
ILT
140 return
141 }
142 verbose "$l"
143 if ![regexp "addu \\$reg,\\$reg,\\\$ra" $l] {
144 send_log "$line\n"
145 send_log "$l\n"
2a056eaf 146 fail $testname
3c247606
ILT
147 return
148 }
149
150 # The next line will be jalr in the case of an expanded
151 # call. Otherwise, the code is getting the start of the
152 # function, and the next line can be anything.
153
154 if { [gets $file l] == -1 } {
155 send_log "$line\n"
2a056eaf 156 fail $testname
3c247606
ILT
157 return
158 }
159
160 if [string match "*jalr*" $l] {
161 set dest [expr 0x$addr + 8 + ($upper << 16) + $lower]
162 if { $dest != $nm_output(foo) && $dest != $nm_output(bar) } {
163 send_log "$line\n"
2a056eaf 164 fail $testname
3c247606
ILT
165 return
166 }
167 } else {
168 set dest [expr ($upper << 16) + $lower]
169 if ![regexp "<\[a-z\]+\\+(\[0-9a-fA-F\]+)>" $label whole offset] {
170 send_log "$line\n"
2a056eaf 171 fail $testname
3c247606
ILT
172 return
173 }
174 if "0x$offset + 8 != - $dest" {
175 send_log "$line\n"
2a056eaf 176 fail $testname
3c247606
ILT
177 return
178 }
179 }
180 }
181 }
182
183 close $file
184
185 if {$balcnt < 10} {
2a056eaf 186 fail $testname
3c247606
ILT
187 } else {
188 verbose "$balcnt bal instructions"
2a056eaf 189 pass $testname
3c247606
ILT
190 }
191}
192
193# We now test actually running embedded MIPS PIC code. This can only
194# be done on a MIPS host with the same endianness as our target.
195if [istarget mipsel-*-*] {
196 if ![ishost mips*-*-ultrix*] {
197 return
198 }
199} else {
200 if ![ishost mips*-*-irix*] {
201 return
202 }
203}
204
2a056eaf
ILT
205set testname "run embedded PIC code"
206
3c247606
ILT
207# Compile the program which will run the test. This code must be
208# compiled for the host, not the target.
209send_log "$CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir$subdir/run.c\n"
210verbose "$CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir$subdir/run.c"
211catch "exec $CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir$subdir/run.c" exec_output
212if ![string match "" $exec_output] {
213 send_log "$exec_output\n"
214 verbose "$exec_output"
2a056eaf 215 unresolved $testname
3c247606
ILT
216 return
217}
218
219# Compile and link the test.
2a056eaf
ILT
220if { ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtesti.s tmpdir/runtesti.o]
221 || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtest1.c tmpdir/runtest1.o]
222 || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtest2.c tmpdir/runtest2.o] } {
223 unresolved $testname
3c247606
ILT
224 return
225}
226if ![ld_simple_link $ld tmpdir/runtest "--embedded-relocs tmpdir/runtesti.o tmpdir/runtest1.o tmpdir/runtest2.o"] {
2a056eaf 227 fail $testname
3c247606
ILT
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"
2a056eaf 236 pass $testname
3c247606
ILT
237 } else {
238 send_log "$exec_output\n"
239 verbose "$exec_output"
2a056eaf 240 fail $testname
3c247606
ILT
241 }
242}
This page took 0.045356 seconds and 4 git commands to generate.