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