Remove i860, i960, bout and aout-adobe targets
[deliverable/binutils-gdb.git] / binutils / testsuite / lib / binutils-common.exp
CommitLineData
219d1afa 1# Copyright (C) 1993-2018 Free Software Foundation, Inc.
f3097f33
RS
2#
3# This file is part of the GNU Binutils.
4#
5# This file 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# True if the object format is known to be ELF.
21#
22proc is_elf_format {} {
b3066ae8
AM
23 # config.sub for these targets curiously transforms a target doublet
24 # ending in -elf to -none. eg. m68hc12-elf to m68hc12-unknown-none
25 # They are always elf.
26 if { [istarget m68hc1*-*] || [istarget xgate-*] } {
27 return 1;
28 }
29
4a85cc09 30 if { ![istarget *-*-eabi*]
f3097f33 31 && ![istarget *-*-elf*]
4a85cc09 32 && ![istarget *-*-freebsd*]
f3097f33 33 && ![istarget *-*-gnu*]
f3097f33
RS
34 && ![istarget *-*-irix5*]
35 && ![istarget *-*-irix6*]
4a85cc09 36 && ![istarget *-*-linux*]
c43b2c54 37 && ![istarget *-*-lynxos*]
4a85cc09 38 && ![istarget *-*-nacl*]
f3097f33
RS
39 && ![istarget *-*-netbsd*]
40 && ![istarget *-*-openbsd*]
4a85cc09
SKS
41 && ![istarget *-*-rtems*]
42 && ![istarget *-*-solaris2*]
c43b2c54 43 && ![istarget *-*-symbianelf*]
4a85cc09
SKS
44 && ![istarget *-*-sysv4*]
45 && ![istarget *-*-unixware*]
f96bd6c2 46 && ![istarget *-*-wasm32*]
4a85cc09
SKS
47 && ![istarget avr-*-*]
48 && ![istarget bfin-*-uclinux]
49 && ![istarget frv-*-uclinux*]
50 && ![istarget hppa*64*-*-hpux*]
51 && ![istarget ia64-*-hpux*]
52 && ![istarget sh*-*-uclinux*]
53 && ![istarget tic6x*-*-uclinux*] } {
f3097f33
RS
54 return 0
55 }
56
4a85cc09 57 if { [istarget *-*-linux*aout*]
df26367c 58 || [istarget *-*-linux*ecoff*]
f3097f33 59 || [istarget *-*-linux*oldld*]
4a85cc09 60 || [istarget *-*-rtemscoff*]
f3097f33 61 || [istarget h8500-*-rtems*]
a8eb42a8 62 || [istarget i?86-*-freebsd\[12\].*] } {
f3097f33
RS
63 return 0
64 }
65
66 if { ![istarget *-*-netbsdelf*]
4a85cc09 67 && ( [istarget *-*-netbsd*aout*]
f3097f33
RS
68 || [istarget *-*-netbsdpe*]
69 || [istarget arm*-*-netbsd*]
70 || [istarget sparc-*-netbsd*]
71 || [istarget i*86-*-netbsd*]
72 || [istarget m68*-*-netbsd*]
73 || [istarget vax-*-netbsd*]
74 || [istarget ns32k-*-netbsd*]) } {
75 return 0
76 }
77
4a85cc09 78 if { [istarget arm-*-openbsd*]
f3097f33
RS
79 || [istarget i386-*-openbsd\[0-2\].*]
80 || [istarget i386-*-openbsd3.\[0-2\]]
81 || [istarget m68*-*-openbsd*]
82 || [istarget ns32k-*-openbsd*]
83 || [istarget sparc-*-openbsd\[0-2\].*]
84 || [istarget sparc-*-openbsd3.\[0-1\]]
85 || [istarget vax-*-openbsd*] } {
86 return 0
87 }
88
89 return 1
90}
91
92# True if the object format is known to be a.out.
93#
94proc is_aout_format {} {
95 if { [istarget *-*-netbsdelf]
96 || [istarget sparc64-*-netbsd*]
97 || [istarget sparc64-*-openbsd*] } {
98 return 0
99 }
100 if { [istarget *-*-*\[ab\]out*]
101 || [istarget *-*-linux*oldld*]
102 || [istarget *-*-bsd*]
103 || [istarget *-*-msdos*]
104 || [istarget arm-*-netbsd*]
105 || [istarget arm-*-openbsd*]
106 || [istarget arm-*-riscix*]
7e16ef34 107 || [istarget i?86-*-freebsd\[12\].*]
f3097f33
RS
108 || [istarget i?86-*-netbsd*]
109 || [istarget i?86-*-openbsd\[0-2\]*]
110 || [istarget i?86-*-openbsd3.\[0-2\]*]
111 || [istarget i?86-*-vsta]
112 || [istarget i?86-*-mach*]
113 || [istarget m68*-*-netbsd*]
114 || [istarget m68*-*-openbsd*]
115 || [istarget ns32k-*-*]
116 || [istarget pdp11-*-*]
117 || [istarget sparc*-*-sunos4*]
118 || [istarget sparc*-*-netbsd*]
119 || [istarget sparc*-*-openbsd\[0-2\]*]
120 || [istarget sparc*-*-openbsd3.\[0-1\]*]
121 || [istarget sparc*-fujitsu-none]
122 || [istarget vax-dec-ultrix*]
123 || [istarget vax-*-netbsd] } {
124 return 1
125 }
126 return 0
127}
128
129# True if the object format is known to be PE COFF.
130#
131proc is_pecoff_format {} {
132 if { ![istarget *-*-mingw*]
133 && ![istarget *-*-cygwin*]
134 && ![istarget *-*-cegcc*]
135 && ![istarget *-*-pe*] } {
136 return 0
137 }
138
139 return 1
140}
141
142# True if the object format is known to be 64-bit ELF.
143#
144proc is_elf64 { binary_file } {
145 global READELF
146 global READELFFLAGS
147
148 set readelf_size ""
149 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
150
151 if ![string match "" $got] then {
152 return 0
153 }
154
155 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
156 [file_contents readelf.out] nil readelf_size] } {
157 return 0
158 }
159
160 if { $readelf_size == "64" } {
161 return 1
162 }
163
164 return 0
165}
eb22018c 166
a43942db
MR
167# True if the ELF target supports STB_GNU_UNIQUE with the ELF header's
168# OSABI field set to ELFOSABI_GNU.
169#
170# This generally depends on the target OS only, however there are a
171# number of exceptions for bare metal targets as follows. The MSP430
172# and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot
173# support STB_GNU_UNIQUE. Likewise non-EABI ARM targets set OSABI to
174# ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*. Finally
a8eb42a8 175# rather than `bfd_elf_final_link' AM33/2.0, D30V, DLX, and
a43942db
MR
176# picoJava targets use `_bfd_generic_final_link', which does not
177# support STB_GNU_UNIQUE symbol binding causing assertion failures.
178#
179proc supports_gnu_unique {} {
180 if { [istarget *-*-gnu*]
181 || [istarget *-*-linux*]
182 || [istarget *-*-nacl*] } {
183 return 1
184 }
185 if { [istarget "arm*-*-*eabi*"] } {
186 return 1
187 }
f96bd6c2
PC
188 if { [istarget "wasm32*-*-*"] } {
189 return 1
190 }
a43942db
MR
191 if { ![istarget "*-*-elf*"] } {
192 return 0
193 }
194 if { [istarget "arm*-*-*"]
195 || [istarget "msp430-*-*"]
196 || [istarget "tic6x-*-*"]
197 || [istarget "visium-*-*"] } {
198 return 0
199 }
200 if { [istarget "am33_2.0-*-*"]
201 || [istarget "d30v-*-*"]
202 || [istarget "dlx-*-*"]
a43942db
MR
203 || [istarget "pj*-*-*"] } {
204 return 0
205 }
206 return 1
207}
208
9cc0123f
AM
209# True for targets that do not sort .symtab as per the ELF standard.
210# ie. any that have mips_elf32_be_vec, mips_elf32_le_vec,
211# mips_elf32_n_be_vec or mips_elf32_n_le_vec as the primary bfd target
212# vector in config.bfd. When syncing with config.bfd, don't forget that
213# earlier case-matches trump later ones.
214proc is_bad_symtab {} {
215 if { ![istarget "mips*-*-*"] } {
216 return 0;
217 }
218 if { [istarget "*-*-chorus*"]
219 || [istarget "*-*-irix5*"]
220 || [istarget "*-*-irix6*"]
221 || [istarget "*-*-none"]
222 || [istarget "*-*-rtems*"]
223 || [istarget "*-*-windiss"] } {
224 return 1;
225 }
226 if { [istarget "*-*-elf*"]
227 && ![istarget "*-sde-*"]
228 && ![istarget "*-mti-*"]
229 && ![istarget "*-img-*"] } {
230 return 1;
231 }
232 if { [istarget "*-*-openbsd*"]
233 && ![istarget "mips64*-*-*"] } {
234 return 1;
235 }
236 return 0;
237}
238
eb22018c
RS
239# Compare two files line-by-line. FILE_1 is the actual output and FILE_2
240# is the expected output. Ignore blank lines in either file.
241#
242# FILE_2 is a series of regexps, comments and # directives. The directives
243# are:
244#
245# #pass
246# Treat the test as a PASS if everything up till this point has
247# matched. Ignore any remaining lines in either FILE_1 or FILE_2.
248#
249# #failif
250# Reverse the sense of the test: expect differences to exist.
251#
252# #...
253# REGEXP
254# Skip all lines in FILE_1 until the first that matches REGEXP.
255#
738f4d98
MR
256# Other # lines are comments. Regexp lines starting with the `!' character
257# specify inverse matching (use `\!' for literal matching against a leading
258# `!'). Skip empty lines in both files.
eb22018c
RS
259#
260# The first optional argument is a list of regexp substitutions of the form:
261#
262# EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
263#
264# This tells the function to apply each regexp substitution EXPi->SUBSPECi
265# in order to every line of FILE_2.
266#
267# Return nonzero if differences exist.
268proc regexp_diff { file_1 file_2 args } {
269 set eof -1
270 set end_1 0
271 set end_2 0
272 set differences 0
273 set diff_pass 0
274 set fail_if_match 0
275 set ref_subst ""
276 if { [llength $args] > 0 } {
277 set ref_subst [lindex $args 0]
278 }
279 if { [llength $args] > 1 } {
280 perror "Too many arguments to regexp_diff"
281 return 1
282 }
283
284 if [file exists $file_1] then {
285 set file_a [open $file_1 r]
286 } else {
287 perror "$file_1 doesn't exist"
288 return 1
289 }
290
291 if [file exists $file_2] then {
292 set file_b [open $file_2 r]
293 } else {
294 perror "$file_2 doesn't exist"
295 close $file_a
296 return 1
297 }
298
299 verbose " Regexp-diff'ing: $file_1 $file_2" 2
300
301 while { 1 } {
302 set line_a ""
303 set line_b ""
304 while { [string length $line_a] == 0 } {
305 # Ignore blank line in FILE_1.
306 if { [gets $file_a line_a] == $eof } {
307 set end_1 1
308 break
309 }
310 }
311 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
312 if { [string match "#pass" $line_b] } {
313 set end_2 1
314 set diff_pass 1
315 break
316 } elseif { [string match "#failif" $line_b] } {
317 send_log "fail if no difference\n"
318 verbose "fail if no difference" 3
319 set fail_if_match 1
320 } elseif { [string match "#..." $line_b] } {
321 if { [gets $file_b line_b] == $eof } {
322 set end_2 1
323 set diff_pass 1
324 break
325 }
47a50e5b 326 set negated [expr { [string index $line_b 0] == "!" }]
738f4d98
MR
327 set line_bx [string range $line_b $negated end]
328 set n [expr { $negated ? "! " : "" }]
eb22018c
RS
329 # Substitute on the reference.
330 foreach {name value} $ref_subst {
738f4d98 331 regsub -- $name $line_bx $value line_bx
eb22018c 332 }
738f4d98
MR
333 verbose "looking for $n\"^$line_bx$\"" 3
334 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
eb22018c
RS
335 verbose "skipping \"$line_a\"" 3
336 if { [gets $file_a line_a] == $eof } {
337 set end_1 1
338 break
339 }
340 }
341 break
342 }
343 if { [gets $file_b line_b] == $eof } {
344 set end_2 1
345 break
346 }
347 }
348
349 if { $diff_pass } {
350 break
351 } elseif { $end_1 && $end_2 } {
352 break
353 } elseif { $end_1 } {
354 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
355 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
356 set differences 1
357 break
358 } elseif { $end_2 } {
359 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
360 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
361 set differences 1
362 break
363 } else {
47a50e5b 364 set negated [expr { [string index $line_b 0] == "!" }]
738f4d98
MR
365 set line_bx [string range $line_b $negated end]
366 set n [expr { $negated ? "! " : "" }]
367 set s [expr { $negated ? " " : "" }]
eb22018c
RS
368 # Substitute on the reference.
369 foreach {name value} $ref_subst {
738f4d98 370 regsub -- $name $line_bx $value line_bx
eb22018c 371 }
738f4d98
MR
372 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
373 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
eb22018c 374 send_log "regexp_diff match failure\n"
738f4d98 375 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
eb22018c
RS
376 verbose "regexp_diff match failure\n" 3
377 set differences 1
378 }
379 }
380 }
381
382 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
383 send_log "$file_1 and $file_2 are different lengths\n"
384 verbose "$file_1 and $file_2 are different lengths" 3
385 set differences 1
386 }
387
388 if { $fail_if_match } {
389 if { $differences == 0 } {
390 set differences 1
391 } else {
392 set differences 0
393 }
394 }
395
396 close $file_a
397 close $file_b
398
399 return $differences
400}
This page took 0.347263 seconds and 4 git commands to generate.