sh.exp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. # Expect script for ld-sh tests
  2. # Copyright (C) 1995-2022 Free Software Foundation, Inc.
  3. #
  4. # This file is part of the GNU Binutils.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  19. # MA 02110-1301, USA.
  20. #
  21. # Written by Ian Lance Taylor (ian@cygnus.com)
  22. #
  23. # Test SH relaxing. This tests the compiler and assembler as well as
  24. # the linker.
  25. if ![istarget sh*-*-*] {
  26. return
  27. }
  28. set testsimple "SH simple relaxing"
  29. if { ![is_elf_format] } {
  30. unsupported $testsimple
  31. } elseif { ![ld_assemble $as "-relax $srcdir/$subdir/sh1.s" tmpdir/sh1.o] } {
  32. fail $testsimple
  33. } elseif { ![ld_link $ld tmpdir/sh1 "-relax tmpdir/sh1.o"] } {
  34. fail $testsimple
  35. } elseif { ![ld_nm $nm "" tmpdir/sh1] } {
  36. fail $testsimple
  37. } elseif { ![info exists nm_output(bar)]
  38. || ![info exists nm_output(foo)]} {
  39. send_log "bad output from nm\n"
  40. verbose "bad output from nm"
  41. fail $testsimple
  42. } elseif {$nm_output(bar) != $nm_output(foo) + 0xc} {
  43. send_log "foo == $nm_output(foo)\n"
  44. verbose "foo == $nm_output(foo)"
  45. send_log "bar == $nm_output(bar)\n"
  46. verbose "bar == $nm_output(bar)"
  47. fail $testsimple
  48. } else {
  49. pass $testsimple
  50. }
  51. set testsrec "SH relaxing to S-records"
  52. if { ![remote_file host exists tmpdir/sh1] } {
  53. unsupported $testsrec
  54. } else {
  55. if { [istarget sh*-linux-*] || [istarget sh-*-vxworks] } {
  56. # On these "non-embedded" targets, the default ELF and srec start
  57. # addresses will be SIZEOF_HEADERS bytes apart. Ensure consistency
  58. # by feeding the ELF start address to the srec link line.
  59. catch "exec $objdump -x tmpdir/sh1 | grep start\\ address | sed s/start\\ address//" entry_addr
  60. set srec_relax_arg "-Ttext $entry_addr -relax --oformat srec tmpdir/sh1.o"
  61. } else {
  62. set srec_relax_arg "-relax --oformat srec tmpdir/sh1.o"
  63. }
  64. if ![ld_link $ld tmpdir/sh1.s1 $srec_relax_arg ] {
  65. fail $testsrec
  66. } else {
  67. # The file name is embedded in the S-records, so create both
  68. # files with the same name.
  69. catch "exec rm -f tmpdir/sh1.s2" exec_output
  70. send_log "mv tmpdir/sh1.s1 tmpdir/sh1.s2\n"
  71. verbose "mv tmpdir/sh1.s1 tmpdir/sh1.s2"
  72. catch "exec mv tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output
  73. if ![string match "" $exec_output] {
  74. send_log "$exec_output\n"
  75. verbose "$exec_output"
  76. fail $testsrec
  77. } else {
  78. send_log "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1\n"
  79. verbose "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1"
  80. catch "exec $objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1" exec_output
  81. if ![string match "" $exec_output] {
  82. send_log "$exec_output\n"
  83. verbose "$exec_output"
  84. fail $testsrec
  85. } else {
  86. send_log "cmp tmpdir/sh1.s1 tmpdir/sh1.s2\n"
  87. verbose "cmp tmpdir/sh1.s1 tmpdir/sh1.s2"
  88. catch "exec cmp tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output
  89. set exec_output [prune_warnings $exec_output]
  90. if ![string match "" $exec_output] {
  91. send_log "$exec_output\n"
  92. verbose "$exec_output"
  93. fail $testsrec
  94. } else {
  95. pass $testsrec
  96. }
  97. }
  98. }
  99. }
  100. }
  101. set testadjsw8 "SH switch8 adjustment after relax"
  102. if { ![is_elf_format] } {
  103. unsupported $testadjsw8
  104. } elseif { ![ld_assemble $as "-relax $srcdir/$subdir/adjsw8.s" tmpdir/adjsw8.o] } {
  105. fail $testadjsw8
  106. } elseif { ![ld_link $ld tmpdir/adjsw8 "-relax tmpdir/adjsw8.o"] } {
  107. fail $testadjsw8
  108. } else {
  109. send_log "exec $objdump -s tmpdir/adjsw8\n"
  110. verbose "exec $objdump -s tmpdir/adjsw8"
  111. catch "exec $objdump -s tmpdir/adjsw8" exec_output
  112. if [string match "*04080c00*" $exec_output] {
  113. pass $testadjsw8
  114. } else {
  115. send_log "bad switch table\n"
  116. verbose "bad switch table"
  117. fail $testadjsw8
  118. }
  119. }
  120. set testlink "SH relaxing"
  121. set testjsr "SH confirm relaxing"
  122. set testrun "SH relaxing execution"
  123. if { ![check_compiler_available] } {
  124. untested $testlink
  125. untested $testjsr
  126. untested $testrun
  127. return
  128. }
  129. if [istarget sh*-*linux*] {
  130. exec sed -e s/_main/main/ -e s/_trap/trap/ -e s/_stack/stack/ \
  131. < $srcdir/$subdir/start.s >tmpdir/start.s
  132. } else {
  133. exec cp $srcdir/$subdir/start.s tmpdir/start.s
  134. }
  135. if {![ld_assemble $as "-relax tmpdir/start.s" tmpdir/start.o] \
  136. || ![ld_compile $CC_FOR_TARGET "-O -mrelax -foptimize-sibling-calls $srcdir/$subdir/sh2.c" tmpdir/sh2.o]} {
  137. unsupported $testlink
  138. unsupported $testjsr
  139. unsupported $testrun
  140. return
  141. }
  142. if ![ld_link $ld tmpdir/sh2 "-relax tmpdir/start.o tmpdir/sh2.o"] {
  143. fail $testlink
  144. unsupported $testjsr
  145. unsupported $testrun
  146. return
  147. }
  148. pass $testlink
  149. send_log "$objdump -d tmpdir/sh2\n"
  150. verbose "$objdump -d tmpdir/sh2"
  151. catch "exec $objdump -d tmpdir/sh2" exec_output
  152. if {[string match "*jsr*" $exec_output]
  153. || [string match "*jmp*" $exec_output]} {
  154. fail $testjsr
  155. } else {
  156. pass $testjsr
  157. }
  158. if { ![info exists SIM] || [which $SIM] == 0 } {
  159. untested $testrun
  160. return
  161. }
  162. set status [catch "exec $SIM tmpdir/sh2" exec_output]
  163. if { $status == 0 } {
  164. pass $testrun
  165. } else {
  166. fail $testrun
  167. }