Commit | Line | Data |
---|---|---|
82704155 | 1 | # Copyright (C) 2003-2019 Free Software Foundation, Inc. |
64543e1a | 2 | # |
f96b4a7b NC |
3 | # This file is part of the GNU Binutils. |
4 | # | |
5 | # This program is free software; you can redistribute it and/or modify | |
64543e1a | 6 | # it under the terms of the GNU General Public License as published by |
f96b4a7b | 7 | # the Free Software Foundation; either version 3 of the License, or |
64543e1a RS |
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 | |
f96b4a7b NC |
17 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
18 | # MA 02110-1301, USA. | |
64543e1a RS |
19 | |
20 | if {![istarget mips*-*-*] || ![is_elf_format]} { | |
21 | return | |
22 | } | |
23 | ||
697380b3 AO |
24 | global ldemul |
25 | if {[istarget mips*-*-irix6*]} { | |
0c29b4cc | 26 | set ldemul "-melf32bsmip" |
697380b3 AO |
27 | } elseif {[istarget mips*el-*-linux*]} { |
28 | set ldemul "-melf32ltsmip" | |
29 | } elseif {[istarget mips*-*-linux*]} { | |
30 | set ldemul "-melf32btsmip" | |
aeffff67 RS |
31 | } elseif {[istarget mips*el-*-*freebsd*]} { |
32 | set ldemul "-melf32ltsmip_fbsd" | |
33 | } elseif {[istarget mips*-*-*freebsd*]} { | |
34 | set ldemul "-melf32btsmip_fbsd" | |
697380b3 AO |
35 | } else { |
36 | set ldemul "" | |
37 | } | |
38 | ||
3da65cd2 CX |
39 | # Check is ld supported 32bit emulations. |
40 | proc check_ld_support_32bit { } { | |
41 | global ld | |
42 | global echo | |
43 | ||
44 | set ld_output [remote_exec host $ld "-V"] | |
45 | if [string match "*elf32*" $ld_output] then { | |
46 | return 1 | |
47 | } else { | |
48 | return 0 | |
49 | } | |
50 | } | |
51 | ||
52 | # Check args is 32bit abis. | |
53 | proc check_is_32bit_args {arg} { | |
54 | ||
55 | if { [string match "*-32*" $arg] | |
56 | || [string match "*-mabi=32*" $arg] | |
57 | || [string match "*-mabi=o64*" $arg] | |
58 | || [string match "*-mgp32*" $arg] } { | |
59 | return 1 | |
60 | } else { | |
61 | return 0 | |
62 | } | |
63 | } | |
64 | ||
64543e1a RS |
65 | # Assemble jr.s using each of the argument lists in ARGLIST. Return the |
66 | # list of object files on success and an empty list on failure. | |
67 | proc assemble_for_flags {arglist} { | |
68 | global as srcdir subdir | |
69 | ||
70 | set objs {} | |
71 | set index 1 | |
72 | ||
73 | foreach args $arglist { | |
74 | set obj "tmpdir/mips-flags-${index}.o" | |
75 | if {![ld_assemble $as "$args $srcdir/$subdir/jr.s" $obj]} { | |
76 | return "" | |
77 | } | |
78 | lappend objs $obj | |
79 | incr index | |
80 | } | |
81 | return $objs | |
82 | } | |
83 | ||
84 | # Assemble a file using each set of arguments in ARGLIST. Check that | |
b1a2d7a0 | 85 | # the objects can be linked together and that the `readelf -h' output |
7575e6a7 MR |
86 | # includes each flag named in FLAGS. Additional one or more arguments |
87 | # request the addition of the `-A' option to `readelf' invocation. In | |
88 | # this case check MIPS ABI Flags reported for the ISA to match the | |
89 | # first of these arguments, the ISA Extension to match the second, and | |
90 | # the ASEs listed are exactly the same as those listed in the third, | |
91 | # passed as a TCL list. | |
92 | proc good_combination {arglist flags args} { | |
697380b3 | 93 | global ld ldemul READELF |
64543e1a RS |
94 | |
95 | set finalobj "tmpdir/mips-flags.o" | |
96 | set testname "MIPS compatible objects: $arglist" | |
97 | set objs [assemble_for_flags $arglist] | |
98 | ||
3da65cd2 CX |
99 | foreach argsl $arglist { |
100 | if { [check_is_32bit_args $argsl] && ![check_ld_support_32bit] } { | |
101 | unsupported $testname | |
102 | return 0 | |
103 | } | |
104 | } | |
105 | ||
64543e1a RS |
106 | if {$objs == ""} { |
107 | unresolved $testname | |
d9816402 | 108 | } elseif {![ld_link "$ld $ldemul" $finalobj "-r $objs"]} { |
64543e1a RS |
109 | fail $testname |
110 | } else { | |
7575e6a7 MR |
111 | set A [expr {[llength $args] > 0} ? {"A"} : {""}] |
112 | set cmd "$READELF -h$A $finalobj" | |
1284e99a MR |
113 | send_log "$cmd\n" |
114 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]]] | |
115 | set output [lindex $cmdret 1] | |
116 | set cmdret [lindex $cmdret 0] | |
117 | if {$cmdret != 0 \ | |
118 | || ![regexp "Flags: *(\[^\n\r\]*)" $output full gotflags]} { | |
64543e1a RS |
119 | unresolved $testname |
120 | } else { | |
121 | set failed 0 | |
122 | ||
123 | # GOTFLAGS is a list of flags separated by ", ". | |
124 | # Convert it to a tcl list. | |
125 | regsub -all ", " $gotflags "," gotflags | |
126 | set gotflags [split $gotflags ","] | |
127 | ||
128 | foreach flag $flags { | |
129 | if {[lsearch -exact $gotflags $flag] < 0} { | |
bc672693 CX |
130 | # The mips*-*-irix* not use o32 flags. |
131 | if {[istarget mips*-*-irix*] && $flag == "o32"} { | |
132 | set failed 0 | |
133 | } else { | |
134 | set failed 1 | |
135 | } | |
64543e1a RS |
136 | } |
137 | } | |
7575e6a7 MR |
138 | |
139 | set isa [string trim [lindex $args 0]] | |
140 | if {$isa != "" | |
141 | && (![regexp "ISA: *(\[^\n\r\]*)" $output full gotisa] | |
142 | || ![string match $isa $gotisa])} { | |
143 | set failed 1 | |
144 | } | |
145 | ||
146 | set ext [string trim [lindex $args 1]] | |
147 | if {$ext != "" | |
148 | && (![regexp "ISA Extension: *(\[^\n\r\]*)" \ | |
149 | $output full gotext] | |
150 | || ![string match $ext $gotext])} { | |
151 | set failed 1 | |
152 | } | |
153 | ||
154 | set ases [string trim [lindex $args 2]] | |
155 | if {[llength $ases] > 0} { | |
156 | if {![regexp "ASEs:\[\n\r\]+((?:\t\[^\n\r\]*\[\n\r\]+)*)" \ | |
157 | $output full gotases]} { | |
158 | set failed 1 | |
159 | } else { | |
160 | # GOTASES is a list of strings separated by tab and | |
161 | # line separator characters. Convert it to a TCL list. | |
162 | regsub -all "\[\n\r\t\]+" $gotases "\n" gotases | |
163 | set gotases [split [string trim $gotases] "\n"] | |
164 | ||
165 | foreach ase $ases { | |
166 | set aseidx [lsearch -exact $gotases $ase] | |
167 | if {$aseidx >= 0} { | |
168 | set gotases [lreplace $gotases $aseidx $aseidx] | |
169 | } else { | |
170 | set failed 1 | |
171 | } | |
172 | } | |
173 | if {[llength $gotases] > 0} { | |
174 | set failed 1 | |
175 | } | |
176 | } | |
177 | } | |
178 | ||
64543e1a RS |
179 | if {$failed} { |
180 | fail $testname | |
181 | } else { | |
182 | pass $testname | |
183 | } | |
184 | } | |
185 | } | |
186 | } | |
187 | ||
188 | # Like good_combination, but check that the objects can't be linked | |
189 | # together successfully and that the output includes MESSAGE. | |
190 | proc bad_combination {arglist message} { | |
697380b3 | 191 | global link_output ld ldemul |
64543e1a RS |
192 | |
193 | set finalobj "tmpdir/mips-flags.o" | |
194 | set testname "MIPS incompatible objects: $arglist" | |
195 | set objs [assemble_for_flags $arglist] | |
196 | ||
3da65cd2 CX |
197 | foreach argsl $arglist { |
198 | if { [check_is_32bit_args $argsl] && ![check_ld_support_32bit] } { | |
199 | unsupported $testname | |
200 | return 0 | |
201 | } | |
202 | } | |
203 | ||
64543e1a RS |
204 | if {$objs == ""} { |
205 | unresolved $testname | |
d9816402 | 206 | } elseif {[ld_link "$ld $ldemul" $finalobj "-r $objs"] |
64543e1a RS |
207 | || [string first $message $link_output] < 0} { |
208 | fail $testname | |
209 | } else { | |
210 | pass $testname | |
211 | } | |
212 | } | |
213 | ||
214 | # Routines to check for various kinds of incompatibility. | |
215 | ||
216 | proc abi_conflict {arglist firstabi secondabi} { | |
217 | bad_combination $arglist \ | |
218 | "linking $secondabi module with previous $firstabi modules" | |
219 | } | |
220 | ||
221 | proc isa_conflict {arglist firstisa secondisa} { | |
222 | bad_combination $arglist \ | |
223 | "linking mips:$secondisa module with previous mips:$firstisa modules" | |
224 | } | |
225 | ||
226 | proc regsize_conflict {arglist} { | |
227 | bad_combination $arglist \ | |
228 | "linking 32-bit code with 64-bit code" | |
229 | } | |
230 | ||
231 | abi_conflict { "-mabi=eabi -mgp32" "-mips4 -mabi=32" } EABI32 O32 | |
c97c330b | 232 | abi_conflict { "-mips4 -mabi=o64" "-mips3 -mabi=eabi" } O64 EABI64 |
64543e1a | 233 | |
c97c330b MF |
234 | isa_conflict { "-march=vr5500 -32" "-march=sb1 -32" } 5500 sb1 |
235 | isa_conflict { "-march=vr5400 -32" "-march=4120 -32" } 5400 4120 | |
236 | isa_conflict { "-march=r3900 -32" "-march=r6000 -32" } 3900 6000 | |
237 | isa_conflict { "-march=r4010 -32" "-march=r4650 -32" } 4010 4650 | |
238 | isa_conflict { "-mips3 -mgp32 -32" "-mips32 -32" } 4000 isa32 | |
697380b3 | 239 | isa_conflict { "-march=sb1 -mgp32 -32" "-mips32r2 -32" } sb1 isa32r2 |
c97c330b MF |
240 | isa_conflict { "-march=sb1 -32" "-mips64r2 -32" } sb1 isa64r2 |
241 | ||
242 | isa_conflict { "-march=vr4100 -32" "-march=r10000 -32" } 4100 8000 | |
243 | isa_conflict { "-march=r5900 -32" "-march=vr4111 -32" } 5900 4111 | |
244 | isa_conflict { "-march=loongson2e -32" "-march=loongson2f -32" } loongson_2e loongson_2f | |
ac8cb70f | 245 | isa_conflict { "-march=gs464 -32" "-march=loongson2f -32" } gs464 loongson_2f |
c97c330b | 246 | |
819e1f86 MR |
247 | isa_conflict { "-march=interaptiv-mr2 -32" \ |
248 | "-march=r4010 -32" } interaptiv-mr2 4010 | |
249 | isa_conflict { "-march=interaptiv-mr2 -mnan=2008 -mfp64 -32" \ | |
250 | "-mips32r6 -32" } interaptiv-mr2 isa32r6 | |
251 | isa_conflict { "-march=interaptiv-mr2 -32" \ | |
252 | "-mips3 -32" } interaptiv-mr2 4000 | |
253 | isa_conflict { "-march=interaptiv-mr2 -32" \ | |
254 | "-mips64r2 -32" } interaptiv-mr2 isa64r2 | |
255 | isa_conflict { "-march=interaptiv-mr2 -32" \ | |
256 | "-march=octeon -32" } interaptiv-mr2 octeon | |
257 | ||
c97c330b MF |
258 | regsize_conflict { "-mips4 -mgp64 -mabi=o64" "-mips2 -32" } |
259 | regsize_conflict { "-mips4 -mabi=o64" "-mips4 -mabi=32" } | |
260 | regsize_conflict { "-mips4 -mabi=eabi -mgp32" "-mips4 -mabi=eabi -mgp64" } | |
261 | regsize_conflict { "-march=vr5000 -mgp64 -mabi=o64" "-march=vr5000 -mgp32 -32" } | |
262 | regsize_conflict { "-mips32 -32" "-mips64 -mabi=o64" } | |
263 | regsize_conflict { "-mips32r2 -32" "-mips64 -mabi=o64" } | |
264 | regsize_conflict { "-mips32r2 -32" "-mips64r2 -mabi=o64" } | |
265 | ||
266 | good_combination { "-mips4 -mgp32 -32" "-mips2 -32" } { mips4 o32 } | |
267 | good_combination { "-mips4 -mabi=32" "-mips2 -32" } { mips4 o32 } | |
268 | good_combination { "-mips2 -32" "-mips4 -mabi=32" } { mips4 o32 } | |
269 | good_combination { "-mips2 -mabi=eabi" "-mips4 -mabi=eabi -mgp32" } { mips4 eabi32 } | |
270 | good_combination { "-mips2 -32" "-mips32 -32" "-mips32r2 -32" } { mips32r2 } | |
271 | good_combination { "-mips1 -32" "-mips32r2 -32" "-mips32 -32" } { mips32r2 } | |
272 | ||
273 | good_combination { "-march=vr4100 -32" "-march=vr4120 -32" } { 4120 } | |
274 | good_combination { "-march=vr5400 -32" "-march=vr5500 -32" "-mips4 -32" } { 5500 } | |
275 | good_combination { "-mips3 -32" "-mips4 -32" "-march=sb1 -32" "-mips5 -32" } { sb1 } | |
276 | good_combination { "-mips1 -32" "-march=3900 -32" } { 3900 } | |
277 | good_combination { "-mips3 -32" "-mips64r2 -32" " -mips64 -32" } { mips64r2 } | |
278 | ||
279 | good_combination { "-march=vr4120 -mabi=32" "-mips3 -mabi=32" } { 4120 o32 } | |
280 | good_combination { "-march=sb1 -mgp32 -32" "-march=4000 -mgp32 -32" } { sb1 o32 } | |
281 | good_combination { "-mips32 -mabi=32" "-march=sb1 -mabi=32" } { sb1 o32 } | |
282 | good_combination { "-mips64r2 -mabi=32" "-mips32 -mabi=32" } { mips64r2 o32 } | |
283 | good_combination { "-mips5 -mabi=o64" "-mips64r2 -mabi=o64" } { mips64r2 o64 } | |
819e1f86 MR |
284 | |
285 | good_combination { "-march=interaptiv-mr2 -32" "-mips1 -32" } \ | |
286 | { mips32r2 interaptiv-mr2 } \ | |
287 | MIPS32r3 "Imagination interAptiv MR2" \ | |
288 | { "DSP ASE" "Enhanced VA Scheme" "MT ASE" } | |
289 | good_combination { "-march=interaptiv-mr2 -32" "-mips32r2 -32" } \ | |
290 | { mips32r2 interaptiv-mr2 } \ | |
291 | MIPS32r3 "Imagination interAptiv MR2" \ | |
292 | { "DSP ASE" "Enhanced VA Scheme" "MT ASE" } | |
293 | good_combination { "-march=interaptiv-mr2 -32" "-march=interaptiv -32" } \ | |
294 | { mips32r2 interaptiv-mr2 } \ | |
295 | MIPS32r3 "Imagination interAptiv MR2" \ | |
296 | { "DSP ASE" "Enhanced VA Scheme" "MT ASE" } | |
297 | good_combination { "-march=interaptiv-mr2 -32" "-mips32r3 -32" } \ | |
298 | { mips32r2 interaptiv-mr2 } \ | |
299 | MIPS32r3 "Imagination interAptiv MR2" \ | |
300 | { "DSP ASE" "Enhanced VA Scheme" "MT ASE" } | |
301 | good_combination { "-march=interaptiv-mr2 -32" "-mips32r3 -mips16 -32" } \ | |
302 | { mips32r2 interaptiv-mr2 } \ | |
303 | MIPS32r3 "Imagination interAptiv MR2" \ | |
304 | { "DSP ASE" "Enhanced VA Scheme" "MT ASE" "MIPS16 ASE" } | |
305 | good_combination { "-march=interaptiv-mr2 -mips16 -32" "-mips32r3 -32" } \ | |
306 | { mips32r2 interaptiv-mr2 } \ | |
307 | MIPS32r3 "Imagination interAptiv MR2" \ | |
308 | { "DSP ASE" "Enhanced VA Scheme" "MT ASE" \ | |
309 | "MIPS16 ASE" "MIPS16e2 ASE" } | |
310 | good_combination { "-march=interaptiv-mr2 -32" "-mips32r5 -32" } \ | |
311 | { mips32r2 interaptiv-mr2 } \ | |
312 | MIPS32r5 "Imagination interAptiv MR2" \ | |
313 | { "DSP ASE" "Enhanced VA Scheme" "MT ASE" } | |
314 | good_combination { "-march=interaptiv-mr2 -32" "-march=m5100 -32" } \ | |
315 | { mips32r2 interaptiv-mr2 } \ | |
316 | MIPS32r5 "Imagination interAptiv MR2" \ | |
317 | { "DSP ASE" "Enhanced VA Scheme" "MT ASE" } | |
bd782c07 CX |
318 | |
319 | good_combination { "-march=gs464 -32" "-march=gs464e -32" } \ | |
320 | { gs464e o32 } \ | |
321 | MIPS64r2 "None" \ | |
322 | { "Loongson MMI ASE" "Loongson CAM ASE" "Loongson EXT ASE" "Loongson EXT2 ASE" } | |
9108bc33 CX |
323 | good_combination { "-march=gs264e -32" "-march=gs464e -32" } \ |
324 | { gs264e o32 } \ | |
325 | MIPS64r2 "None" \ | |
326 | { "Loongson MMI ASE" "Loongson CAM ASE" "Loongson EXT ASE" "Loongson EXT2 ASE" } |