654f8ae76c73a338172cd25e0b740cad25bbf92a
[deliverable/binutils-gdb.git] / ld / testsuite / ld-mips-elf / mips-elf-flags.exp
1 # Copyright (C) 2003-2018 Free Software Foundation, Inc.
2 #
3 # This file is part of the GNU Binutils.
4 #
5 # This program 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 3 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,
18 # MA 02110-1301, USA.
19
20 if {![istarget mips*-*-*] || ![is_elf_format]} {
21 return
22 }
23
24 global ldemul
25 if {[istarget mips*-*-irix6*]} {
26 set ldemul "-melf32bsmip"
27 } elseif {[istarget mips*el-*-linux*]} {
28 set ldemul "-melf32ltsmip"
29 } elseif {[istarget mips*-*-linux*]} {
30 set ldemul "-melf32btsmip"
31 } elseif {[istarget mips*el-*-*freebsd*]} {
32 set ldemul "-melf32ltsmip_fbsd"
33 } elseif {[istarget mips*-*-*freebsd*]} {
34 set ldemul "-melf32btsmip_fbsd"
35 } else {
36 set ldemul ""
37 }
38
39 # Assemble jr.s using each of the argument lists in ARGLIST. Return the
40 # list of object files on success and an empty list on failure.
41 proc assemble_for_flags {arglist} {
42 global as srcdir subdir
43
44 set objs {}
45 set index 1
46
47 foreach args $arglist {
48 set obj "tmpdir/mips-flags-${index}.o"
49 if {![ld_assemble $as "$args $srcdir/$subdir/jr.s" $obj]} {
50 return ""
51 }
52 lappend objs $obj
53 incr index
54 }
55 return $objs
56 }
57
58 # Assemble a file using each set of arguments in ARGLIST. Check that
59 # the objects can be linked together and that the `readelf -h' output
60 # includes each flag named in FLAGS. Additional one or more arguments
61 # request the addition of the `-A' option to `readelf' invocation. In
62 # this case check MIPS ABI Flags reported for the ISA to match the
63 # first of these arguments, the ISA Extension to match the second, and
64 # the ASEs listed are exactly the same as those listed in the third,
65 # passed as a TCL list.
66 proc good_combination {arglist flags args} {
67 global ld ldemul READELF
68
69 set finalobj "tmpdir/mips-flags.o"
70 set testname "MIPS compatible objects: $arglist"
71 set objs [assemble_for_flags $arglist]
72
73 if {$objs == ""} {
74 unresolved $testname
75 } elseif {![ld_link "$ld $ldemul" $finalobj "-r $objs"]} {
76 fail $testname
77 } else {
78 set A [expr {[llength $args] > 0} ? {"A"} : {""}]
79 set cmd "$READELF -h$A $finalobj"
80 send_log "$cmd\n"
81 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]]]
82 set output [lindex $cmdret 1]
83 set cmdret [lindex $cmdret 0]
84 if {$cmdret != 0 \
85 || ![regexp "Flags: *(\[^\n\r\]*)" $output full gotflags]} {
86 unresolved $testname
87 } else {
88 set failed 0
89
90 # GOTFLAGS is a list of flags separated by ", ".
91 # Convert it to a tcl list.
92 regsub -all ", " $gotflags "," gotflags
93 set gotflags [split $gotflags ","]
94
95 foreach flag $flags {
96 if {[lsearch -exact $gotflags $flag] < 0} {
97 set failed 1
98 }
99 }
100
101 set isa [string trim [lindex $args 0]]
102 if {$isa != ""
103 && (![regexp "ISA: *(\[^\n\r\]*)" $output full gotisa]
104 || ![string match $isa $gotisa])} {
105 set failed 1
106 }
107
108 set ext [string trim [lindex $args 1]]
109 if {$ext != ""
110 && (![regexp "ISA Extension: *(\[^\n\r\]*)" \
111 $output full gotext]
112 || ![string match $ext $gotext])} {
113 set failed 1
114 }
115
116 set ases [string trim [lindex $args 2]]
117 if {[llength $ases] > 0} {
118 if {![regexp "ASEs:\[\n\r\]+((?:\t\[^\n\r\]*\[\n\r\]+)*)" \
119 $output full gotases]} {
120 set failed 1
121 } else {
122 # GOTASES is a list of strings separated by tab and
123 # line separator characters. Convert it to a TCL list.
124 regsub -all "\[\n\r\t\]+" $gotases "\n" gotases
125 set gotases [split [string trim $gotases] "\n"]
126
127 foreach ase $ases {
128 set aseidx [lsearch -exact $gotases $ase]
129 if {$aseidx >= 0} {
130 set gotases [lreplace $gotases $aseidx $aseidx]
131 } else {
132 set failed 1
133 }
134 }
135 if {[llength $gotases] > 0} {
136 set failed 1
137 }
138 }
139 }
140
141 if {$failed} {
142 fail $testname
143 } else {
144 pass $testname
145 }
146 }
147 }
148 }
149
150 # Like good_combination, but check that the objects can't be linked
151 # together successfully and that the output includes MESSAGE.
152 proc bad_combination {arglist message} {
153 global link_output ld ldemul
154
155 set finalobj "tmpdir/mips-flags.o"
156 set testname "MIPS incompatible objects: $arglist"
157 set objs [assemble_for_flags $arglist]
158
159 if {$objs == ""} {
160 unresolved $testname
161 } elseif {[ld_link "$ld $ldemul" $finalobj "-r $objs"]
162 || [string first $message $link_output] < 0} {
163 fail $testname
164 } else {
165 pass $testname
166 }
167 }
168
169 # Routines to check for various kinds of incompatibility.
170
171 proc abi_conflict {arglist firstabi secondabi} {
172 bad_combination $arglist \
173 "linking $secondabi module with previous $firstabi modules"
174 }
175
176 proc isa_conflict {arglist firstisa secondisa} {
177 bad_combination $arglist \
178 "linking mips:$secondisa module with previous mips:$firstisa modules"
179 }
180
181 proc regsize_conflict {arglist} {
182 bad_combination $arglist \
183 "linking 32-bit code with 64-bit code"
184 }
185
186 abi_conflict { "-mabi=eabi -mgp32" "-mips4 -mabi=32" } EABI32 O32
187 abi_conflict { "-mips4 -mabi=o64" "-mips3 -mabi=eabi" } O64 EABI64
188
189 isa_conflict { "-march=vr5500 -32" "-march=sb1 -32" } 5500 sb1
190 isa_conflict { "-march=vr5400 -32" "-march=4120 -32" } 5400 4120
191 isa_conflict { "-march=r3900 -32" "-march=r6000 -32" } 3900 6000
192 isa_conflict { "-march=r4010 -32" "-march=r4650 -32" } 4010 4650
193 isa_conflict { "-mips3 -mgp32 -32" "-mips32 -32" } 4000 isa32
194 isa_conflict { "-march=sb1 -mgp32 -32" "-mips32r2 -32" } sb1 isa32r2
195 isa_conflict { "-march=sb1 -32" "-mips64r2 -32" } sb1 isa64r2
196
197 isa_conflict { "-march=vr4100 -32" "-march=r10000 -32" } 4100 8000
198 isa_conflict { "-march=r5900 -32" "-march=vr4111 -32" } 5900 4111
199 isa_conflict { "-march=loongson2e -32" "-march=loongson2f -32" } loongson_2e loongson_2f
200 isa_conflict { "-march=loongson3a -32" "-march=loongson2f -32" } loongson_3a loongson_2f
201
202 isa_conflict { "-march=interaptiv-mr2 -32" \
203 "-march=r4010 -32" } interaptiv-mr2 4010
204 isa_conflict { "-march=interaptiv-mr2 -mnan=2008 -mfp64 -32" \
205 "-mips32r6 -32" } interaptiv-mr2 isa32r6
206 isa_conflict { "-march=interaptiv-mr2 -32" \
207 "-mips3 -32" } interaptiv-mr2 4000
208 isa_conflict { "-march=interaptiv-mr2 -32" \
209 "-mips64r2 -32" } interaptiv-mr2 isa64r2
210 isa_conflict { "-march=interaptiv-mr2 -32" \
211 "-march=octeon -32" } interaptiv-mr2 octeon
212
213 regsize_conflict { "-mips4 -mgp64 -mabi=o64" "-mips2 -32" }
214 regsize_conflict { "-mips4 -mabi=o64" "-mips4 -mabi=32" }
215 regsize_conflict { "-mips4 -mabi=eabi -mgp32" "-mips4 -mabi=eabi -mgp64" }
216 regsize_conflict { "-march=vr5000 -mgp64 -mabi=o64" "-march=vr5000 -mgp32 -32" }
217 regsize_conflict { "-mips32 -32" "-mips64 -mabi=o64" }
218 regsize_conflict { "-mips32r2 -32" "-mips64 -mabi=o64" }
219 regsize_conflict { "-mips32r2 -32" "-mips64r2 -mabi=o64" }
220
221 good_combination { "-mips4 -mgp32 -32" "-mips2 -32" } { mips4 o32 }
222 good_combination { "-mips4 -mabi=32" "-mips2 -32" } { mips4 o32 }
223 good_combination { "-mips2 -32" "-mips4 -mabi=32" } { mips4 o32 }
224 good_combination { "-mips2 -mabi=eabi" "-mips4 -mabi=eabi -mgp32" } { mips4 eabi32 }
225 good_combination { "-mips2 -32" "-mips32 -32" "-mips32r2 -32" } { mips32r2 }
226 good_combination { "-mips1 -32" "-mips32r2 -32" "-mips32 -32" } { mips32r2 }
227
228 good_combination { "-march=vr4100 -32" "-march=vr4120 -32" } { 4120 }
229 good_combination { "-march=vr5400 -32" "-march=vr5500 -32" "-mips4 -32" } { 5500 }
230 good_combination { "-mips3 -32" "-mips4 -32" "-march=sb1 -32" "-mips5 -32" } { sb1 }
231 good_combination { "-mips1 -32" "-march=3900 -32" } { 3900 }
232 good_combination { "-mips3 -32" "-mips64r2 -32" " -mips64 -32" } { mips64r2 }
233
234 good_combination { "-march=vr4120 -mabi=32" "-mips3 -mabi=32" } { 4120 o32 }
235 good_combination { "-march=sb1 -mgp32 -32" "-march=4000 -mgp32 -32" } { sb1 o32 }
236 good_combination { "-mips32 -mabi=32" "-march=sb1 -mabi=32" } { sb1 o32 }
237 good_combination { "-mips64r2 -mabi=32" "-mips32 -mabi=32" } { mips64r2 o32 }
238 good_combination { "-mips5 -mabi=o64" "-mips64r2 -mabi=o64" } { mips64r2 o64 }
239
240 good_combination { "-march=interaptiv-mr2 -32" "-mips1 -32" } \
241 { mips32r2 interaptiv-mr2 } \
242 MIPS32r3 "Imagination interAptiv MR2" \
243 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
244 good_combination { "-march=interaptiv-mr2 -32" "-mips32r2 -32" } \
245 { mips32r2 interaptiv-mr2 } \
246 MIPS32r3 "Imagination interAptiv MR2" \
247 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
248 good_combination { "-march=interaptiv-mr2 -32" "-march=interaptiv -32" } \
249 { mips32r2 interaptiv-mr2 } \
250 MIPS32r3 "Imagination interAptiv MR2" \
251 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
252 good_combination { "-march=interaptiv-mr2 -32" "-mips32r3 -32" } \
253 { mips32r2 interaptiv-mr2 } \
254 MIPS32r3 "Imagination interAptiv MR2" \
255 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
256 good_combination { "-march=interaptiv-mr2 -32" "-mips32r3 -mips16 -32" } \
257 { mips32r2 interaptiv-mr2 } \
258 MIPS32r3 "Imagination interAptiv MR2" \
259 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" "MIPS16 ASE" }
260 good_combination { "-march=interaptiv-mr2 -mips16 -32" "-mips32r3 -32" } \
261 { mips32r2 interaptiv-mr2 } \
262 MIPS32r3 "Imagination interAptiv MR2" \
263 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" \
264 "MIPS16 ASE" "MIPS16e2 ASE" }
265 good_combination { "-march=interaptiv-mr2 -32" "-mips32r5 -32" } \
266 { mips32r2 interaptiv-mr2 } \
267 MIPS32r5 "Imagination interAptiv MR2" \
268 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
269 good_combination { "-march=interaptiv-mr2 -32" "-march=m5100 -32" } \
270 { mips32r2 interaptiv-mr2 } \
271 MIPS32r5 "Imagination interAptiv MR2" \
272 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
This page took 0.03559 seconds and 4 git commands to generate.