1 # Expect script for ld-empic tests
2 # Copyright (C) 1994,1995 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. */
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*] {
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.
36 if { ![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] } {
44 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"] {
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.
57 # Get the symbol table.
58 if ![ld_nm $nm tmpdir/relax] {
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"
75 set file [open tmpdir/relax.dis r]
76 while { [gets $file line] != -1 } {
79 if ![string match "*bal*" $line] {
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"
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)" {
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 } {
113 if [string match "*sll*" $l] {
116 if ![regexp "lui (\[\$a-z0-9\]+),(\[0-9\]+)" $l whole reg upper] {
123 if { [gets $file l] == -1 } {
129 if ![regexp "addiu \\$reg,\\$reg,(\[-0-9\]+)" $l whole lower] {
132 send_log "addiu \\$reg,\\$reg,(\[-0-9\]+)\n"
137 if { [gets $file l] == -1 } {
143 if ![regexp "addu \\$reg,\\$reg,\\\$ra" $l] {
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.
154 if { [gets $file l] == -1 } {
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) } {
168 set dest [expr ($upper << 16) + $lower]
169 if ![regexp "<\[a-z\]+\\+(\[0-9a-fA-F\]+)>" $label whole offset] {
174 if "0x$offset + 8 != - $dest" {
188 verbose "$balcnt bal instructions"
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.
195 if [istarget mipsel-*-*] {
196 if ![ishost mips*-*-ultrix*] {
200 if ![ishost mips*-*-irix*] {
205 set testname "run embedded PIC code"
207 # Compile the program which will run the test. This code must be
208 # compiled for the host, not the target.
209 send_log "$CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir$subdir/run.c\n"
210 verbose "$CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir$subdir/run.c"
211 catch "exec $CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir$subdir/run.c" exec_output
212 if ![string match "" $exec_output] {
213 send_log "$exec_output\n"
214 verbose "$exec_output"
219 # Compile and link the test.
220 if { ![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] } {
226 if ![ld_simple_link $ld tmpdir/runtest "--embedded-relocs tmpdir/runtesti.o tmpdir/runtest1.o tmpdir/runtest2.o"] {
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"
238 send_log "$exec_output\n"
239 verbose "$exec_output"