1 # Expect script for ld-empic tests
2 # Copyright (C) 1994,1995, 1996, 1997 Free Software Foundation
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.
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.
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*] {
32 if { [which $CC] == 0 } {
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] } {
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"] {
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] {
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"
80 set file [open tmpdir/relax.dis r]
81 while { [gets $file line] != -1 } {
84 if ![string match "*bal*" $line] {
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"
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)" {
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 } {
120 if [string match "*sll*" $l] {
123 if ![regexp "lui (\[\$a-z0-9\]+),(\[0-9a-fA-Fx\]+)" $l whole reg upper] {
131 if { [gets $file l] == -1 } {
138 if ![regexp "addiu \\$reg,\\$reg,(\[-0-9\]+)" $l whole lower] {
142 send_log "addiu \\$reg,\\$reg,(\[-0-9\]+)\n"
147 if { [gets $file l] == -1 } {
154 if ![regexp "addu \\$reg,\\$reg,\\\$ra" $l] {
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 } {
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) } {
182 set dest [expr ($upper << 16) + $lower]
183 if ![regexp "<(\[.a-z\]+)\\+(\[0-9a-fA-F\]+)>" $label whole base offset] {
190 if { $base == ".foo" } {
191 set offset [expr $offset - ($nm_output(foo) - 0x30)]
193 if { $offset + 8 != - $dest } {
209 verbose "$balcnt bal instructions"
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*] {
221 if ![ishost mips*-*-irix*] {
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"
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] } {
247 if ![ld_simple_link $ld tmpdir/runtest "--embedded-relocs tmpdir/runtesti.o tmpdir/runtest1.o tmpdir/runtest2.o"] {
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"
259 send_log "$exec_output\n"
260 verbose "$exec_output"