home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / ld / testsuite / ld-empic / empic.exp next >
Text File  |  1996-09-28  |  8KB  |  264 lines

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