# Expect script for ld-empic tests
-# Copyright (C) 1994 Free Software Foundation
+# Copyright (C) 1994,1995 Free Software Foundation
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# embedded PIC is a GNU enhancement to standard MIPS tools.
# Embedded PIC is only supported for MIPS ECOFF targets.
-if ![istarget mips*-*-ecoff*] { return }
+if ![istarget mips*-*-ecoff*] {
+ return
+}
+
+set testname relax
# Test that relaxation works correctly. This testsuite was composed
# (by experimentation) to force the linker to relax twice--that is,
# the first relaxation pass will force another call to be out of
# range, requiring a second relaxation pass.
-if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax1.c tmpdir/relax1.o] {
- return
-}
-if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax2.c tmpdir/relax2.o] {
- return
-}
-if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax3.c tmpdir/relax3.o] {
- return
-}
-if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax4.c tmpdir/relax4.o] {
+if { ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax1.c tmpdir/relax1.o]
+ || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax2.c tmpdir/relax2.o]
+ || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax3.c tmpdir/relax3.o]
+ || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/relax4.c tmpdir/relax4.o] } {
+ unresolved $testname
return
}
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"] {
- fail relax
+ fail $testname
} else {
# Check that the relaxation produced the correct result. Check
# each bal instruction. Some will go directly to the start of a
# Get the symbol table.
if ![ld_nm $nm tmpdir/relax] {
+ unresolved $testname
return
}
if ![string match "" $exec_output] {
send_log "$exec_output\n"
verbose $exec_output
- perror "tmpdir/relax: objdump failed"
+ unresolved $testname
return
}
if ![regexp "^(\[0-9a-fA-F\]+) (<\[a-z+0-9A-Z\]+>)? bal (\[0-9a-fA-F\]+)" $line whole addr label dest] {
perror "unrecognized format for $line"
+ unresolved $testname
return
}
# this example are to either foo or bar.
if "0x$dest != $nm_output(foo) && 0x$dest != $nm_output(bar)" {
send_log "$line\n"
- fail "relax (bad direct function call)"
+ fail $testname
return
}
} else {
# should be an addiu, followed by an addu to $31.
if { [gets $file l] == -1 } {
send_log "$line\n"
- fail "relax (unexpected EOF after bal)"
+ fail $testname
return
}
verbose $l
if ![regexp "lui (\[\$a-z0-9\]+),(\[0-9\]+)" $l whole reg upper] {
send_log "$line\n"
send_log "$l\n"
- fail "relax (could not find expected lui)"
+ fail $testname
return
}
if { [gets $file l] == -1 } {
send_log "$line\n"
- fail "relax (unexpected EOF after lui)"
+ fail $testname
return
}
verbose "$l"
send_log "$line\n"
send_log "$l\n"
send_log "addiu \\$reg,\\$reg,(\[-0-9\]+)\n"
- fail "relax (could not find expected addiu)"
+ fail $testname
return
}
if { [gets $file l] == -1 } {
send_log "$line\n"
- fail "relax (unexpected EOF after addiu)"
+ fail $testname
return
}
verbose "$l"
if ![regexp "addu \\$reg,\\$reg,\\\$ra" $l] {
send_log "$line\n"
send_log "$l\n"
- fail "relax (could not find expected addu)"
+ fail $testname
return
}
if { [gets $file l] == -1 } {
send_log "$line\n"
- fail "relax (unexpected EOF after addu)"
+ fail $testname
return
}
set dest [expr 0x$addr + 8 + ($upper << 16) + $lower]
if { $dest != $nm_output(foo) && $dest != $nm_output(bar) } {
send_log "$line\n"
- fail "relax (bad expanded function call)"
+ fail $testname
return
}
} else {
set dest [expr ($upper << 16) + $lower]
if ![regexp "<\[a-z\]+\\+(\[0-9a-fA-F\]+)>" $label whole offset] {
send_log "$line\n"
- fail "relax (unrecognized label)"
+ fail $testname
return
}
if "0x$offset + 8 != - $dest" {
send_log "$line\n"
- fail "relax (bad function start: 0x$offset + 8 != - $dest)"
+ fail $testname
return
}
}
close $file
if {$balcnt < 10} {
- fail "relax (not enough branches)"
+ fail $testname
} else {
verbose "$balcnt bal instructions"
- pass relax
+ pass $testname
}
}
}
}
+set testname "run embedded PIC code"
+
# Compile the program which will run the test. This code must be
# compiled for the host, not the target.
send_log "$CC_FOR_HOST $CFLAGS_FOR_HOST -o tmpdir/run $srcdir$subdir/run.c\n"
if ![string match "" $exec_output] {
send_log "$exec_output\n"
verbose "$exec_output"
- perror "$srcdir$subdir/run.c: compilation failed"
+ unresolved $testname
return
}
# Compile and link the test.
-if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtesti.s tmpdir/runtesti.o] {
- return
-}
-if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtest1.c tmpdir/runtest1.o] {
- return
-}
-if ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtest2.c tmpdir/runtest2.o] {
+if { ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtesti.s tmpdir/runtesti.o]
+ || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtest1.c tmpdir/runtest1.o]
+ || ![ld_compile "$CC $CFLAGS -membedded-pic" $srcdir$subdir/runtest2.c tmpdir/runtest2.o] } {
+ unresolved $testname
return
}
if ![ld_simple_link $ld tmpdir/runtest "--embedded-relocs tmpdir/runtesti.o tmpdir/runtest1.o tmpdir/runtest2.o"] {
- fail "run embedded PIC code (link)"
+ fail $testname
} else {
# Now run the test.
send_log "tmpdir/run tmpdir/runtest\n"
if [string match "*ran and returned 0*" $exec_output] {
send_log "$exec_output\n"
verbose "$exec_output"
- pass "run embedded PIC code"
+ pass $testname
} else {
send_log "$exec_output\n"
verbose "$exec_output"
- fail "run embedded PIC code"
+ fail $testname
}
}