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