1 # Expect script for ld-sh tests
2 # Copyright (C) 2001, 2002, 2003, 2004, 2007 Free Software Foundation
4 # This file is part of the GNU Binutils.
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.
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.
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,
22 # Test SH reloc failures - that is, cases that ld must not allow.
24 if ![istarget sh64-*-*] {
28 if [istarget sh64-*-linux*] {
29 set emul32 "shlelf32_linux"
30 set oformat32 "elf32-sh64-linux"
33 } elseif { [istarget sh64*-*-netbsd*] || [istarget sh5*-*-netbsd*] } then {
34 set emul32 "shelf32_nbsd"
35 set oformat32 "elf32-sh64-nbsd"
36 set startsym "__start"
38 set emul64 "shelf64_nbsd"
39 set oformat64 "elf64-sh64-nbsd"
42 set oformat32 "elf32-sh64"
46 set oformat64 "elf64-sh64"
49 # opcode, asflags, ldflags, expected or "" for fail
50 # opcode blank means rebuild relfail.o and set default as/ld options
52 set sh64abi32relfailtests {
54 { "" "-isa=shcompact -abi=32" "-m $emul32 -Ttext 0x1000 --oformat $oformat32" "" }
55 { "mov.l lab,r0;.align 3;lab:nop" "" "" "mov.l 1008" }
56 { "mov.l to0,r0" "" "" "mov.l 1010" }
57 { "mov.l to1,r0" "" "" "" }
58 { "mov.l to2,r0" "" "" "" }
59 { "mov.l to3,r0" "" "" "" }
60 { "mov.l to4,r0" "" "" "mov.l 1014" }
62 { "" "-isa=shmedia -abi=32 -no-expand" "-m $emul32 -Ttext 0x1000 --oformat $oformat32" "" }
63 { "pta lab,tr0;.align 3;lab:nop" "" "" "pta.*1008" }
65 { "ld.q r0,datalabel to0 - 0x1000,r0" "" "" "ld.q.*,16," }
66 { "ld.q r0,datalabel to1 - 0x1000,r0" "" "" "" }
67 { "ld.q r0,datalabel to2 - 0x1000,r0" "" "" "" }
68 { "ld.q r0,datalabel to3 - 0x1000,r0" "" "" "" }
69 { "ld.q r0,datalabel to4 - 0x1000,r0" "" "" "" }
71 { "ld.l r0,datalabel to0 - 0x1000,r0" "" "" "ld.l.*,16," }
72 { "ld.l r0,datalabel to1 - 0x1000,r0" "" "" "" }
73 { "ld.l r0,datalabel to2 - 0x1000,r0" "" "" "" }
74 { "ld.l r0,datalabel to3 - 0x1000,r0" "" "" "" }
75 { "ld.l r0,datalabel to4 - 0x1000,r0" "" "" "ld.l.*,20," }
77 { "ld.w r0,datalabel to0 - 0x1000,r0" "" "" "ld.w.*,16," }
78 { "ld.w r0,datalabel to1 - 0x1000,r0" "" "" "" }
79 { "ld.w r0,datalabel to2 - 0x1000,r0" "" "" "ld.w.*,18," }
80 { "ld.w r0,datalabel to3 - 0x1000,r0" "" "" "" }
81 { "ld.w r0,datalabel to4 - 0x1000,r0" "" "" "ld.w.*,20," }
85 set sh64abi64relfailtests {
87 { "" "-isa=shmedia -abi=64 -no-expand" "-m $emul64 -Ttext 0x1000 --oformat $oformat64" "" }
88 { "pta lab,tr0;.align 3;lab:nop" "" "" "pta.*1008" }
89 { "pta datalabel to0,tr0" "" "" "pta.*1010" }
90 { "pta datalabel to1,tr0" "" "" "pta.*1011" }
91 { "pta datalabel to2,tr0" "" "" "" }
92 { "pta datalabel to3,tr0" "" "" "" }
93 { "pta datalabel to4,tr0" "" "" "pta.*1014" }
95 { "ld.q r0,datalabel to0 - 0x1000,r0" "" "" "ld.q.*,16," }
96 { "ld.q r0,datalabel to1 - 0x1000,r0" "" "" "" }
97 { "ld.q r0,datalabel to2 - 0x1000,r0" "" "" "" }
98 { "ld.q r0,datalabel to3 - 0x1000,r0" "" "" "" }
99 { "ld.q r0,datalabel to4 - 0x1000,r0" "" "" "" }
101 { "ld.l r0,datalabel to0 - 0x1000,r0" "" "" "ld.l.*,16," }
102 { "ld.l r0,datalabel to1 - 0x1000,r0" "" "" "" }
103 { "ld.l r0,datalabel to2 - 0x1000,r0" "" "" "" }
104 { "ld.l r0,datalabel to3 - 0x1000,r0" "" "" "" }
105 { "ld.l r0,datalabel to4 - 0x1000,r0" "" "" "ld.l.*,20," }
107 { "ld.w r0,datalabel to0 - 0x1000,r0" "" "" "ld.w.*,16," }
108 { "ld.w r0,datalabel to1 - 0x1000,r0" "" "" "" }
109 { "ld.w r0,datalabel to2 - 0x1000,r0" "" "" "ld.w.*,18," }
110 { "ld.w r0,datalabel to3 - 0x1000,r0" "" "" "" }
111 { "ld.w r0,datalabel to4 - 0x1000,r0" "" "" "ld.w.*,20," }
115 proc run_sh64relfailtests {sh64relfailtests} {
132 foreach testentry $sh64relfailtests {
133 set opcode [lindex $testentry 0]
134 set as_options [lindex $testentry 1]
135 set ld_options [subst [lindex $testentry 2]]
136 set expect_fail [lindex $testentry 3]
138 set testname "SH64 relfail $opcode $as_options $ld_options"
145 set def_as_options $as_options
146 set def_ld_options $ld_options
148 set baseobj "tmpdir/relfail-$testindex.o"
149 if ![ld_assemble $as "$as_options $srcdir/$subdir/relfail.s" $baseobj] {
155 if {$as_options == ""} {
156 set as_options $def_as_options
158 if {$ld_options == ""} {
159 set ld_options $def_ld_options
162 if { $is_unresolved } {
167 set asm [open "tmpdir/relfail-$testindex.s" "w"]
169 puts $asm " .global $startsym"
170 puts $asm "$startsym:"
174 if ![ld_assemble $as "$as_options tmpdir/relfail-$testindex.s" "tmpdir/relfail-$testindex.o"] {
179 set binfile "tmpdir/relfail-$testindex.x"
182 set objects "tmpdir/relfail-$testindex.o $baseobj"
183 set result [ld_simple_link $ld $binfile "--no-warn-mismatch $ld_options $objects"]
185 set exists [file exists $binfile]
186 if {$exists && $expect_fail == ""} {
187 verbose "$testname: file $binfile exists when it shouldn't" 1
188 catch "exec $objdump -d $binfile" objdump_output
189 verbose $objdump_output 1
190 fail "$testname (file exists)"
193 if {!$exists && $expect_fail != ""} {
194 verbose "$testname: file $binfile doesn't exist when it should" 1
195 fail "$testname (file missing)"
200 catch "exec $objdump -d $binfile" objdump_output
201 regsub -all {[ ][ ]*} $objdump_output " " objdump_short
202 if ![regexp $expect_fail $objdump_short junk] {
203 verbose $objdump_output 1
204 fail "$testname (incorrect reloc)"
209 file delete "tmpdir/relfail-$testindex.s"
210 file delete "tmpdir/relfail-$testindex.o"
216 run_sh64relfailtests $sh64abi32relfailtests
218 run_sh64relfailtests $sh64abi64relfailtests