Upload Tizen:Base source
[external/binutils.git] / ld / testsuite / ld-sh / sh64 / relax.exp
1 # Expect script for ld-sh tests
2 #   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation
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
22 # Test SH relaxing - that is, that it's disabled when SHmedia sections
23 # are present.
24
25 if ![istarget sh64-*-*] {
26     return
27 }
28
29 # There are four source files: the first is SHcompact only, the second
30 # is SHmedia only, the third has both, and the fourth has only a
31 # .cranges section.  The table below has:
32 #   Title
33 #   as flags for first source (else "n/a" to skip)
34 #   ditto, other three files
35 #   ld flags
36 #   1/0 whether relaxing should have been done or not, or -1 if we expect
37 #     the linker to not produce an output file.
38
39 if [istarget sh64*-*-linux*] {
40     set emul32 "shlelf32_linux"
41 } elseif { [istarget sh64*-*-netbsd*] || [istarget sh5*-*-netbsd*] } {
42     set emul32 "shelf32_nbsd"
43 } else {
44     set emul32 "shelf32"
45 }
46
47 set sh64relaxtests {
48     {"SH64 not relaxing, shcompact"
49       {"-relax -isa shcompact" "n/a" "n/a" "n/a"} "-m$emul32" 0}
50     {"SH64 relaxing, shcompact"
51       {"-relax -isa shcompact" "n/a" "n/a" "n/a"} "-relax -m$emul32" 1}
52     {"SH64 relaxing, shcompacts"
53       {"-relax -isa shcompact" "-isa shcompact" "n/a" "n/a"} "-relax -m$emul32" 1}
54     {"SH64 relaxing disabled, shmedia"
55       {"-relax -isa shcompact" "-isa shmedia -no-mix" "n/a" "n/a"} "-relax -m$emul32" 0}
56     {"SH64 relaxing disabled, mixed"
57       {"-relax -isa shcompact" "n/a" "-isa shcompact" "n/a"} "-relax -m$emul32" 0}
58     {"SH64 relaxing disabled, cranges"
59       {"-relax -isa shcompact" "n/a" "n/a" ""} "-relax -m$emul32" 0}
60 }
61
62 proc run_sh64relaxtest {sh64relaxtests} {
63     global ld
64     global as
65     global nm
66     global objdump
67     global readelf
68     global srcdir
69     global subdir
70     global emul32
71
72     set testindex 0
73     
74     set sh64relaxfiles {
75         "relax1.s" "relax2.s" "relax3.s" "relax4.s"
76     }
77     
78     foreach testentry $sh64relaxtests {
79         set testname [lindex $testentry 0]
80         set as_options [lindex $testentry 1]
81         set ld_options [subst [lindex $testentry 2]]
82         set expect_relaxed [lindex $testentry 3]
83         
84         set is_unresolved 0
85         set objfiles {}
86         
87         incr testindex
88         
89         # Assemble each file in the test.
90         for {set i 0} {$i < 4} {incr i} {
91             set as_file [lindex $sh64relaxfiles $i]
92             set as_opt [lindex $as_options $i]
93             if { [string compare $as_opt "n/a"] != 0 } {
94                 set objfile "tmpdir/[file rootname $as_file]-$testindex.o"
95                 lappend objfiles $objfile
96                 
97                 if ![ld_assemble $as "$as_opt $srcdir/$subdir/$as_file" $objfile] {
98                     set is_unresolved 1
99                     break
100                 }
101             }
102         }
103         
104         # Catch assembler errors.
105         if { $is_unresolved != 0 } {
106             unresolved $testname
107             continue
108         }
109         
110         set binfile "tmpdir/relax-$testindex.x"
111         
112         # We're not interested in the pass/fail of the linker as much
113         # as we're interested in whether or not relaxing got properly
114         # disabled.  Hence the lax checking here.
115         
116         file delete $binfile
117         set result [ld_simple_link $ld $binfile " --no-warn-mismatch $ld_options $objfiles"]
118         if ![file exists $binfile] {
119             
120             if {$expect_relaxed == -1} {
121                 pass $testname
122                 continue
123             }
124             
125             verbose "$testname: file $binfile doesn't exist" 1
126             fail $testname
127             continue
128         }
129         
130         catch "exec $objdump -d $binfile" objdump_output
131         
132         regexp "\[ \t](jsr|bsr)\[ \t]" $objdump_output ignore calltype
133         
134         if [string match $calltype "bsr"] {
135             set relaxed 1
136         } elseif [string match $calltype "jsr"] {
137             set relaxed 0
138         } else {
139             verbose "$testname: neither jsr nor bsr found" 1
140             verbose $objdump_output 2
141             fail $testname
142             continue
143         }
144         
145         if {$relaxed != $expect_relaxed} {
146             verbose $objdump_output 2
147             fail $testname
148             exit
149         } else {
150             pass $testname
151         }
152     }
153 }
154
155 run_sh64relaxtest $sh64relaxtests