Automatic date update in version.in
[deliverable/binutils-gdb.git] / ld / testsuite / ld-mips-elf / mips-elf-flags.exp
CommitLineData
219d1afa 1# Copyright (C) 2003-2018 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
20if {![istarget mips*-*-*] || ![is_elf_format]} {
21 return
22}
23
697380b3
AO
24global ldemul
25if {[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.
40proc 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.
53proc 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.
67proc 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.
92proc 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} {
130 set failed 1
131 }
132 }
7575e6a7
MR
133
134 set isa [string trim [lindex $args 0]]
135 if {$isa != ""
136 && (![regexp "ISA: *(\[^\n\r\]*)" $output full gotisa]
137 || ![string match $isa $gotisa])} {
138 set failed 1
139 }
140
141 set ext [string trim [lindex $args 1]]
142 if {$ext != ""
143 && (![regexp "ISA Extension: *(\[^\n\r\]*)" \
144 $output full gotext]
145 || ![string match $ext $gotext])} {
146 set failed 1
147 }
148
149 set ases [string trim [lindex $args 2]]
150 if {[llength $ases] > 0} {
151 if {![regexp "ASEs:\[\n\r\]+((?:\t\[^\n\r\]*\[\n\r\]+)*)" \
152 $output full gotases]} {
153 set failed 1
154 } else {
155 # GOTASES is a list of strings separated by tab and
156 # line separator characters. Convert it to a TCL list.
157 regsub -all "\[\n\r\t\]+" $gotases "\n" gotases
158 set gotases [split [string trim $gotases] "\n"]
159
160 foreach ase $ases {
161 set aseidx [lsearch -exact $gotases $ase]
162 if {$aseidx >= 0} {
163 set gotases [lreplace $gotases $aseidx $aseidx]
164 } else {
165 set failed 1
166 }
167 }
168 if {[llength $gotases] > 0} {
169 set failed 1
170 }
171 }
172 }
173
64543e1a
RS
174 if {$failed} {
175 fail $testname
176 } else {
177 pass $testname
178 }
179 }
180 }
181}
182
183# Like good_combination, but check that the objects can't be linked
184# together successfully and that the output includes MESSAGE.
185proc bad_combination {arglist message} {
697380b3 186 global link_output ld ldemul
64543e1a
RS
187
188 set finalobj "tmpdir/mips-flags.o"
189 set testname "MIPS incompatible objects: $arglist"
190 set objs [assemble_for_flags $arglist]
191
3da65cd2
CX
192 foreach argsl $arglist {
193 if { [check_is_32bit_args $argsl] && ![check_ld_support_32bit] } {
194 unsupported $testname
195 return 0
196 }
197 }
198
64543e1a
RS
199 if {$objs == ""} {
200 unresolved $testname
d9816402 201 } elseif {[ld_link "$ld $ldemul" $finalobj "-r $objs"]
64543e1a
RS
202 || [string first $message $link_output] < 0} {
203 fail $testname
204 } else {
205 pass $testname
206 }
207}
208
209# Routines to check for various kinds of incompatibility.
210
211proc abi_conflict {arglist firstabi secondabi} {
212 bad_combination $arglist \
213 "linking $secondabi module with previous $firstabi modules"
214}
215
216proc isa_conflict {arglist firstisa secondisa} {
217 bad_combination $arglist \
218 "linking mips:$secondisa module with previous mips:$firstisa modules"
219}
220
221proc regsize_conflict {arglist} {
222 bad_combination $arglist \
223 "linking 32-bit code with 64-bit code"
224}
225
226abi_conflict { "-mabi=eabi -mgp32" "-mips4 -mabi=32" } EABI32 O32
c97c330b 227abi_conflict { "-mips4 -mabi=o64" "-mips3 -mabi=eabi" } O64 EABI64
64543e1a 228
c97c330b
MF
229isa_conflict { "-march=vr5500 -32" "-march=sb1 -32" } 5500 sb1
230isa_conflict { "-march=vr5400 -32" "-march=4120 -32" } 5400 4120
231isa_conflict { "-march=r3900 -32" "-march=r6000 -32" } 3900 6000
232isa_conflict { "-march=r4010 -32" "-march=r4650 -32" } 4010 4650
233isa_conflict { "-mips3 -mgp32 -32" "-mips32 -32" } 4000 isa32
697380b3 234isa_conflict { "-march=sb1 -mgp32 -32" "-mips32r2 -32" } sb1 isa32r2
c97c330b
MF
235isa_conflict { "-march=sb1 -32" "-mips64r2 -32" } sb1 isa64r2
236
237isa_conflict { "-march=vr4100 -32" "-march=r10000 -32" } 4100 8000
238isa_conflict { "-march=r5900 -32" "-march=vr4111 -32" } 5900 4111
239isa_conflict { "-march=loongson2e -32" "-march=loongson2f -32" } loongson_2e loongson_2f
240isa_conflict { "-march=loongson3a -32" "-march=loongson2f -32" } loongson_3a loongson_2f
241
819e1f86
MR
242isa_conflict { "-march=interaptiv-mr2 -32" \
243 "-march=r4010 -32" } interaptiv-mr2 4010
244isa_conflict { "-march=interaptiv-mr2 -mnan=2008 -mfp64 -32" \
245 "-mips32r6 -32" } interaptiv-mr2 isa32r6
246isa_conflict { "-march=interaptiv-mr2 -32" \
247 "-mips3 -32" } interaptiv-mr2 4000
248isa_conflict { "-march=interaptiv-mr2 -32" \
249 "-mips64r2 -32" } interaptiv-mr2 isa64r2
250isa_conflict { "-march=interaptiv-mr2 -32" \
251 "-march=octeon -32" } interaptiv-mr2 octeon
252
c97c330b
MF
253regsize_conflict { "-mips4 -mgp64 -mabi=o64" "-mips2 -32" }
254regsize_conflict { "-mips4 -mabi=o64" "-mips4 -mabi=32" }
255regsize_conflict { "-mips4 -mabi=eabi -mgp32" "-mips4 -mabi=eabi -mgp64" }
256regsize_conflict { "-march=vr5000 -mgp64 -mabi=o64" "-march=vr5000 -mgp32 -32" }
257regsize_conflict { "-mips32 -32" "-mips64 -mabi=o64" }
258regsize_conflict { "-mips32r2 -32" "-mips64 -mabi=o64" }
259regsize_conflict { "-mips32r2 -32" "-mips64r2 -mabi=o64" }
260
261good_combination { "-mips4 -mgp32 -32" "-mips2 -32" } { mips4 o32 }
262good_combination { "-mips4 -mabi=32" "-mips2 -32" } { mips4 o32 }
263good_combination { "-mips2 -32" "-mips4 -mabi=32" } { mips4 o32 }
264good_combination { "-mips2 -mabi=eabi" "-mips4 -mabi=eabi -mgp32" } { mips4 eabi32 }
265good_combination { "-mips2 -32" "-mips32 -32" "-mips32r2 -32" } { mips32r2 }
266good_combination { "-mips1 -32" "-mips32r2 -32" "-mips32 -32" } { mips32r2 }
267
268good_combination { "-march=vr4100 -32" "-march=vr4120 -32" } { 4120 }
269good_combination { "-march=vr5400 -32" "-march=vr5500 -32" "-mips4 -32" } { 5500 }
270good_combination { "-mips3 -32" "-mips4 -32" "-march=sb1 -32" "-mips5 -32" } { sb1 }
271good_combination { "-mips1 -32" "-march=3900 -32" } { 3900 }
272good_combination { "-mips3 -32" "-mips64r2 -32" " -mips64 -32" } { mips64r2 }
273
274good_combination { "-march=vr4120 -mabi=32" "-mips3 -mabi=32" } { 4120 o32 }
275good_combination { "-march=sb1 -mgp32 -32" "-march=4000 -mgp32 -32" } { sb1 o32 }
276good_combination { "-mips32 -mabi=32" "-march=sb1 -mabi=32" } { sb1 o32 }
277good_combination { "-mips64r2 -mabi=32" "-mips32 -mabi=32" } { mips64r2 o32 }
278good_combination { "-mips5 -mabi=o64" "-mips64r2 -mabi=o64" } { mips64r2 o64 }
819e1f86
MR
279
280good_combination { "-march=interaptiv-mr2 -32" "-mips1 -32" } \
281 { mips32r2 interaptiv-mr2 } \
282 MIPS32r3 "Imagination interAptiv MR2" \
283 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
284good_combination { "-march=interaptiv-mr2 -32" "-mips32r2 -32" } \
285 { mips32r2 interaptiv-mr2 } \
286 MIPS32r3 "Imagination interAptiv MR2" \
287 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
288good_combination { "-march=interaptiv-mr2 -32" "-march=interaptiv -32" } \
289 { mips32r2 interaptiv-mr2 } \
290 MIPS32r3 "Imagination interAptiv MR2" \
291 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
292good_combination { "-march=interaptiv-mr2 -32" "-mips32r3 -32" } \
293 { mips32r2 interaptiv-mr2 } \
294 MIPS32r3 "Imagination interAptiv MR2" \
295 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
296good_combination { "-march=interaptiv-mr2 -32" "-mips32r3 -mips16 -32" } \
297 { mips32r2 interaptiv-mr2 } \
298 MIPS32r3 "Imagination interAptiv MR2" \
299 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" "MIPS16 ASE" }
300good_combination { "-march=interaptiv-mr2 -mips16 -32" "-mips32r3 -32" } \
301 { mips32r2 interaptiv-mr2 } \
302 MIPS32r3 "Imagination interAptiv MR2" \
303 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" \
304 "MIPS16 ASE" "MIPS16e2 ASE" }
305good_combination { "-march=interaptiv-mr2 -32" "-mips32r5 -32" } \
306 { mips32r2 interaptiv-mr2 } \
307 MIPS32r5 "Imagination interAptiv MR2" \
308 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
309good_combination { "-march=interaptiv-mr2 -32" "-march=m5100 -32" } \
310 { mips32r2 interaptiv-mr2 } \
311 MIPS32r5 "Imagination interAptiv MR2" \
312 { "DSP ASE" "Enhanced VA Scheme" "MT ASE" }
This page took 0.663221 seconds and 4 git commands to generate.