summaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-sh/sh.exp
blob: b6762aa56024c54efaad03492fe946f4ceb8c255 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Expect script for ld-sh tests
#   Copyright (C) 1995-2018 Free Software Foundation, Inc.
#
# This file is part of the GNU Binutils.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# Written by Ian Lance Taylor (ian@cygnus.com)
#

# Test SH relaxing.  This tests the compiler and assembler as well as
# the linker.

if ![istarget sh*-*-*] {
    return
}

if { ([istarget sh64*-*-*] || [istarget sh5*-*-*])} {
    # relaxing not supported on sh64 yet.
    return
}

set testsimple "SH simple relaxing"

if ![ld_assemble $as "-relax $srcdir/$subdir/sh1.s" tmpdir/sh1.o] {
    unresolved $testsimple
} else { if ![ld_link $ld tmpdir/sh1 "-relax tmpdir/sh1.o"] {
    fail $testsimple
} else {
    if ![ld_nm $nm "" tmpdir/sh1] {
	unresolved $testsimple
    } else {
	if {![info exists nm_output(bar)] \
	     || ![info exists nm_output(foo)]} {
	    send_log "bad output from nm\n"
	    verbose "bad output from nm"
	    fail $testsimple
	} else {
	    if {$nm_output(bar) != $nm_output(foo) + 0xc} {
		send_log "foo == $nm_output(foo)\n"
		verbose "foo == $nm_output(foo)"
		send_log "bar == $nm_output(bar)\n"
		verbose "bar == $nm_output(bar)"
		fail $testsimple
	    } else {
		pass $testsimple
	    }
	}
    }
} }

set testsrec "SH relaxing to S-records"

if { [istarget sh*-linux-*] || [istarget sh-*-vxworks] } {
    # On these "non-embedded" targets, the default ELF and srec start
    # addresses will be SIZEOF_HEADERS bytes apart.  Ensure consistency
    # by feeding the ELF start address to the srec link line.
    catch "exec $objdump -x tmpdir/sh1 | grep start\\ address | sed s/start\\ address//" entry_addr
    set srec_relax_arg "-Ttext $entry_addr -relax --oformat srec tmpdir/sh1.o"
} else {
    set srec_relax_arg "-relax --oformat srec tmpdir/sh1.o"
}
if ![ld_link $ld tmpdir/sh1.s1 $srec_relax_arg ] {
    fail $testsrec
} else {
    # The file name is embedded in the S-records, so create both
    # files with the same name.
    catch "exec rm -f tmpdir/sh1.s2" exec_output
    send_log "mv tmpdir/sh1.s1 tmpdir/sh1.s2\n"
    verbose "mv tmpdir/sh1.s1 tmpdir/sh1.s2"
    catch "exec mv tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output
    if ![string match "" $exec_output] {
	send_log "$exec_output\n"
	verbose "$exec_output"
	unresolved $testsrec
    } else {
	send_log "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1\n"
	verbose "$objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1"
	catch "exec $objcopy -O srec tmpdir/sh1 tmpdir/sh1.s1" exec_output
	if ![string match "" $exec_output] {
	    send_log "$exec_output\n"
	    verbose "$exec_output"
	    unresolved $testsrec
	} else {
	    send_log "cmp tmpdir/sh1.s1 tmpdir/sh1.s2\n"
	    verbose "cmp tmpdir/sh1.s1 tmpdir/sh1.s2"
	    catch "exec cmp tmpdir/sh1.s1 tmpdir/sh1.s2" exec_output
	    set exec_output [prune_warnings $exec_output]
	    if ![string match "" $exec_output] {
		send_log "$exec_output\n"
		verbose "$exec_output"
		fail $testsrec
	    } else {
		pass $testsrec
	    }
	}
    }
}

set testadjsw8 "SH switch8 adjustment after relax"
if ![ld_assemble $as "-relax $srcdir/$subdir/adjsw8.s" tmpdir/adjsw8.o] {
    unresolved $testadjsw8
} else {
    if ![ld_link $ld tmpdir/adjsw8 "-relax tmpdir/adjsw8.o"] {
	fail $testadjsw8
    } else {
	send_log "exec $objdump -s tmpdir/adjsw8\n"
	verbose "exec $objdump -s tmpdir/adjsw8"
	catch "exec $objdump -s tmpdir/adjsw8" exec_output
	if [string match "*04080c00*" $exec_output] {
	    pass $testadjsw8
	} else {
	    send_log "bad switch table\n"
	    verbose "bad switch table"
	    fail $testadjsw8
	}
    }
}

set testlink "SH relaxing"
set testjsr "SH confirm relaxing"
set testrun "SH relaxing execution"

if { [which $CC] == 0 } {
    untested $testlink
    untested $testjsr
    untested $testrun
    return
}

if [istarget sh*-*linux*] {
    exec sed -e s/_main/main/ -e s/_trap/trap/ -e s/_stack/stack/ \
	    < $srcdir/$subdir/start.s >tmpdir/start.s
} else {
    exec cp $srcdir/$subdir/start.s tmpdir/start.s
}

if {![ld_assemble $as "-relax tmpdir/start.s" tmpdir/start.o] \
    || ![ld_compile $CC "-O -mrelax -foptimize-sibling-calls $srcdir/$subdir/sh2.c" tmpdir/sh2.o]} {
    unresolved $testlink
    unresolved $testjsr
    unresolved $testrun
    return
}

if ![ld_link $ld tmpdir/sh2 "-relax tmpdir/start.o tmpdir/sh2.o"] {
    fail $testlink
    unresolved $testjsr
    unresolved $testrun
    return
}

pass $testlink

send_log "$objdump -d tmpdir/sh2\n"
verbose "$objdump -d tmpdir/sh2"
catch "exec $objdump -d tmpdir/sh2" exec_output
if {[string match "*jsr*" $exec_output]
    || [string match "*jmp*" $exec_output]} {
    fail $testjsr
} else {
    pass $testjsr
}

if { ![info exists SIM] || [which $SIM] == 0 } {
    untested $testrun
    return
}

set status [catch "exec $SIM tmpdir/sh2" exec_output]
if { $status == 0 } {
    pass $testrun
} else {
    fail $testrun
}