1 # Copyright
(C
) 1993-2017 Free Software Foundation
, Inc.
3 # This file is part of the GNU Binutils.
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.
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.
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
,
20 # True
if the object format is known to be ELF.
22 proc is_elf_format
{} {
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
-*] } {
30 if { ![istarget
*-*-eabi
*]
31 && ![istarget
*-*-elf
*]
32 && ![istarget
*-*-freebsd
*]
33 && ![istarget
*-*-gnu
*]
34 && ![istarget
*-*-irix5
*]
35 && ![istarget
*-*-irix6
*]
36 && ![istarget
*-*-linux
*]
37 && ![istarget
*-*-nacl
*]
38 && ![istarget
*-*-netbsd
*]
39 && ![istarget
*-*-openbsd
*]
40 && ![istarget
*-*-rtems
*]
41 && ![istarget
*-*-solaris2
*]
42 && ![istarget
*-*-sysv4
*]
43 && ![istarget
*-*-unixware
*]
44 && ![istarget
*-*-wasm32
*]
45 && ![istarget avr
-*-*]
46 && ![istarget bfin
-*-uclinux
]
47 && ![istarget frv
-*-uclinux
*]
48 && ![istarget hppa
*64*-*-hpux
*]
49 && ![istarget ia64
-*-hpux
*]
50 && ![istarget sh
*-*-uclinux
*]
51 && ![istarget tic6x
*-*-uclinux
*] } {
55 if { [istarget
*-*-linux
*aout
*]
56 ||
[istarget
*-*-linux
*ecoff
*]
57 ||
[istarget
*-*-linux
*oldld
*]
58 ||
[istarget
*-*-rtemscoff
*]
59 ||
[istarget h8500
-*-rtems
*]
60 ||
[istarget i?
86-*-freebsd\
[12\
].
*]
61 ||
[istarget i960
-*-rtems
*] } {
65 if { ![istarget
*-*-netbsdelf
*]
66 && ( [istarget
*-*-netbsd
*aout
*]
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
*]) } {
77 if { [istarget arm
-*-openbsd
*]
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
*] } {
91 # True
if the object format is known to be a.out.
93 proc is_aout_format
{} {
94 if { [istarget
*-*-netbsdelf
]
95 ||
[istarget sparc64
-*-netbsd
*]
96 ||
[istarget sparc64
-*-openbsd
*] } {
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
*]
106 ||
[istarget i?
86-*-freebsd\
[12\
].
*]
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
] } {
128 # True
if the object format is known to be PE COFF.
130 proc is_pecoff_format
{} {
131 if { ![istarget
*-*-mingw
*]
132 && ![istarget
*-*-cygwin
*]
133 && ![istarget
*-*-cegcc
*]
134 && ![istarget
*-*-pe
*] } {
141 # True
if the object format is known to be
64-bit ELF.
143 proc is_elf64
{ binary_file
} {
148 catch
"exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
150 if ![string match
"" $got] then {
154 if { ![regexp
"\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
155 [file_contents readelf.out
] nil readelf_size
] } {
159 if { $readelf_size
== "64" } {
166 # True
if the ELF target supports STB_GNU_UNIQUE with the ELF header
's
167 # OSABI field set to ELFOSABI_GNU.
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
174 # rather than `bfd_elf_final_link' AM33
/2.0, D30V
, DLX
, i960
, and
175 # picoJava targets use `_bfd_generic_final_link
', which does not
176 # support STB_GNU_UNIQUE symbol binding causing assertion failures.
178 proc supports_gnu_unique {} {
179 if { [istarget *-*-gnu*]
180 || [istarget *-*-linux*]
181 || [istarget *-*-nacl*] } {
184 if { [istarget "arm*-*-*eabi*"] } {
187 if { [istarget "wasm32*-*-*"] } {
190 if { ![istarget "*-*-elf*"] } {
193 if { [istarget "arm*-*-*"]
194 || [istarget "msp430-*-*"]
195 || [istarget "tic6x-*-*"]
196 || [istarget "visium-*-*"] } {
199 if { [istarget "am33_2.0-*-*"]
200 || [istarget "d30v-*-*"]
201 || [istarget "dlx-*-*"]
202 || [istarget "i960-*-*"]
203 || [istarget "pj*-*-*"] } {
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.
214 proc is_bad_symtab
{} {
215 if { ![istarget
"mips*-*-*"] } {
218 if { [istarget
"*-*-chorus*"]
219 ||
[istarget
"*-*-irix5*"]
220 ||
[istarget
"*-*-irix6*"]
221 ||
[istarget
"*-*-none"]
222 ||
[istarget
"*-*-rtems*"]
223 ||
[istarget
"*-*-windiss"] } {
226 if { [istarget
"*-*-elf*"]
227 && ![istarget
"*-sde-*"]
228 && ![istarget
"*-mti-*"]
229 && ![istarget
"*-img-*"] } {
232 if { [istarget
"*-*-openbsd*"]
233 && ![istarget
"mips64*-*-*"] } {
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.
242 # FILE_2 is a series of regexps
, comments and # directives. The directives
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.
250 # Reverse the sense of the test
: expect differences to exist.
254 # Skip all lines in FILE_1 until the first that matches REGEXP.
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.
260 # The first optional argument is a list of regexp substitutions of the form:
262 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
264 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
265 # in order to every line of FILE_2.
267 # Return nonzero if differences exist.
268 proc regexp_diff { file_1 file_2 args } {
276 if { [llength $args] > 0 } {
277 set ref_subst [lindex $args 0]
279 if { [llength $args] > 1 } {
280 perror "Too many arguments to regexp_diff"
284 if [file exists $file_1] then {
285 set file_a [open $file_1 r]
287 perror "$file_1 doesn't exist
"
291 if [file
exists $file_2
] then {
292 set file_b
[open $file_2 r
]
294 perror
"$file_2 doesn't exist"
299 verbose
" Regexp-diff'ing: $file_1 $file_2" 2
304 while { [string length $line_a
] == 0 } {
305 # Ignore
blank line in FILE_1.
306 if { [gets $file_a line_a
] == $eof
} {
311 while { [string length $line_b
] == 0 ||
[string match
"#*" $line_b] } {
312 if { [string match
"#pass" $line_b] } {
316 } elseif
{ [string match
"#failif" $line_b] } {
317 send_log
"fail if no difference\n"
318 verbose
"fail if no difference" 3
320 } elseif
{ [string match
"#..." $line_b] } {
321 if { [gets $file_b line_b
] == $eof
} {
326 set negated
[expr
{ [string index $line_b
0] == "!" }]
327 set line_bx
[string range $line_b $negated end
]
328 set n
[expr
{ $negated ?
"! " : "" }]
329 # Substitute
on the reference.
330 foreach
{name value
} $ref_subst
{
331 regsub
-- $
name $line_bx $value line_bx
333 verbose
"looking for $n\"^$line_bx$\"" 3
334 while { [expr
[regexp
"^$line_bx$" "$line_a"] == $negated] } {
335 verbose
"skipping \"$line_a\"" 3
336 if { [gets $file_a line_a
] == $eof
} {
343 if { [gets $file_b line_b
] == $eof
} {
351 } elseif
{ $end_1
&& $end_2
} {
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
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
364 set negated
[expr
{ [string index $line_b
0] == "!" }]
365 set line_bx
[string range $line_b $negated end
]
366 set n
[expr
{ $negated ?
"! " : "" }]
367 set s
[expr
{ $negated ?
" " : "" }]
368 # Substitute
on the reference.
369 foreach
{name value
} $ref_subst
{
370 regsub
-- $
name $line_bx $value line_bx
372 verbose
"regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
373 if { [expr
[regexp
"^$line_bx$" "$line_a"] == $negated] } {
374 send_log
"regexp_diff match failure\n"
375 send_log
"regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
376 verbose
"regexp_diff match failure\n" 3
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
388 if { $fail_if_match
} {
389 if { $differences
== 0 } {