1 # Copyright (C) 1993-2018 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 *-*-lynxos*]
38 && ![istarget *-*-nacl*]
39 && ![istarget *-*-netbsd*]
40 && ![istarget *-*-openbsd*]
41 && ![istarget *-*-rtems*]
42 && ![istarget *-*-solaris2*]
43 && ![istarget *-*-symbianelf*]
44 && ![istarget *-*-sysv4*]
45 && ![istarget *-*-unixware*]
46 && ![istarget *-*-wasm32*]
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*] } {
57 if { [istarget *-*-linux*aout*]
58 || [istarget *-*-linux*ecoff*]
59 || [istarget *-*-linux*oldld*]
60 || [istarget *-*-rtemscoff*]
61 || [istarget i?86-*-freebsd\[12\].*] } {
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 vax-*-netbsd*]
72 || [istarget ns32k-*-netbsd*]) } {
76 if { [istarget arm-*-openbsd*]
77 || [istarget i386-*-openbsd\[0-2\].*]
78 || [istarget i386-*-openbsd3.\[0-2\]]
79 || [istarget ns32k-*-openbsd*]
80 || [istarget sparc-*-openbsd\[0-2\].*]
81 || [istarget sparc-*-openbsd3.\[0-1\]]
82 || [istarget vax-*-openbsd*] } {
89 # True if the object format is known to be a.out.
91 proc is_aout_format {} {
92 if { [istarget *-*-netbsdelf]
93 || [istarget sparc64-*-netbsd*]
94 || [istarget sparc64-*-openbsd*] } {
97 if { [istarget *-*-*\[ab\]out*]
98 || [istarget *-*-linux*oldld*]
99 || [istarget *-*-bsd*]
100 || [istarget *-*-msdos*]
101 || [istarget arm-*-netbsd*]
102 || [istarget arm-*-openbsd*]
103 || [istarget arm-*-riscix*]
104 || [istarget i?86-*-freebsd\[12\].*]
105 || [istarget i?86-*-netbsd*]
106 || [istarget i?86-*-openbsd\[0-2\]*]
107 || [istarget i?86-*-openbsd3.\[0-2\]*]
108 || [istarget i?86-*-vsta]
109 || [istarget i?86-*-mach*]
110 || [istarget ns32k-*-*]
111 || [istarget pdp11-*-*]
112 || [istarget sparc*-*-sunos4*]
113 || [istarget sparc*-*-netbsd*]
114 || [istarget sparc*-*-openbsd\[0-2\]*]
115 || [istarget sparc*-*-openbsd3.\[0-1\]*]
116 || [istarget sparc*-fujitsu-none]
117 || [istarget vax-dec-ultrix*]
118 || [istarget vax-*-netbsd] } {
124 # True if the object format is known to be PE COFF.
126 proc is_pecoff_format {} {
127 if { ![istarget *-*-mingw*]
128 && ![istarget *-*-cygwin*]
129 && ![istarget *-*-cegcc*]
130 && ![istarget *-*-pe*] } {
137 # True if the object format is known to be 64-bit ELF.
139 proc is_elf64 { binary_file } {
144 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
146 if ![string match "" $got] then {
150 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
151 [file_contents readelf.out] nil readelf_size] } {
155 if { $readelf_size == "64" } {
162 # True if the ELF target supports STB_GNU_UNIQUE with the ELF header's
163 # OSABI field set to ELFOSABI_GNU.
165 # This generally depends on the target OS only, however there are a
166 # number of exceptions for bare metal targets as follows. The MSP430
167 # and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot
168 # support STB_GNU_UNIQUE. Likewise non-EABI ARM targets set OSABI to
169 # ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*. Finally
170 # rather than `bfd_elf_final_link' AM33/2.0, D30V, DLX, and
171 # picoJava targets use `_bfd_generic_final_link', which does not
172 # support STB_GNU_UNIQUE symbol binding causing assertion failures.
174 proc supports_gnu_unique {} {
175 if { [istarget *-*-gnu*]
176 || [istarget *-*-linux*]
177 || [istarget *-*-nacl*] } {
180 if { [istarget "arm*-*-*eabi*"] } {
183 if { [istarget "wasm32*-*-*"] } {
186 if { ![istarget "*-*-elf*"] } {
189 if { [istarget "arm*-*-*"]
190 || [istarget "msp430-*-*"]
191 || [istarget "tic6x-*-*"]
192 || [istarget "visium-*-*"] } {
195 if { [istarget "am33_2.0-*-*"]
196 || [istarget "d30v-*-*"]
197 || [istarget "dlx-*-*"]
198 || [istarget "pj*-*-*"] } {
204 # True for targets that do not sort .symtab as per the ELF standard.
205 # ie. any that have mips_elf32_be_vec, mips_elf32_le_vec,
206 # mips_elf32_n_be_vec or mips_elf32_n_le_vec as the primary bfd target
207 # vector in config.bfd. When syncing with config.bfd, don't forget that
208 # earlier case-matches trump later ones.
209 proc is_bad_symtab {} {
210 if { ![istarget "mips*-*-*"] } {
213 if { [istarget "*-*-chorus*"]
214 || [istarget "*-*-irix5*"]
215 || [istarget "*-*-irix6*"]
216 || [istarget "*-*-none"]
217 || [istarget "*-*-rtems*"]
218 || [istarget "*-*-windiss"] } {
221 if { [istarget "*-*-elf*"]
222 && ![istarget "*-sde-*"]
223 && ![istarget "*-mti-*"]
224 && ![istarget "*-img-*"] } {
227 if { [istarget "*-*-openbsd*"]
228 && ![istarget "mips64*-*-*"] } {
234 # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
235 # is the expected output. Ignore blank lines in either file.
237 # FILE_2 is a series of regexps, comments and # directives. The directives
241 # Treat the test as a PASS if everything up till this point has
242 # matched. Ignore any remaining lines in either FILE_1 or FILE_2.
245 # Reverse the sense of the test: expect differences to exist.
249 # Skip all lines in FILE_1 until the first that matches REGEXP.
251 # Other # lines are comments. Regexp lines starting with the `!' character
252 # specify inverse matching (use `\!' for literal matching against a leading
253 # `!'). Skip empty lines in both files.
255 # The first optional argument is a list of regexp substitutions of the form:
257 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
259 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
260 # in order to every line of FILE_2.
262 # Return nonzero if differences exist.
263 proc regexp_diff { file_1 file_2 args } {
271 if { [llength $args] > 0 } {
272 set ref_subst [lindex $args 0]
274 if { [llength $args] > 1 } {
275 perror "Too many arguments to regexp_diff"
279 if [file exists $file_1] then {
280 set file_a [open $file_1 r]
282 perror "$file_1 doesn't exist"
286 if [file exists $file_2] then {
287 set file_b [open $file_2 r]
289 perror "$file_2 doesn't exist"
294 verbose " Regexp-diff'ing: $file_1 $file_2" 2
299 while { [string length $line_a] == 0 } {
300 # Ignore blank line in FILE_1.
301 if { [gets $file_a line_a] == $eof } {
306 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
307 if { [string match "#pass" $line_b] } {
311 } elseif { [string match "#failif" $line_b] } {
312 send_log "fail if no difference\n"
313 verbose "fail if no difference" 3
315 } elseif { [string match "#..." $line_b] } {
316 if { [gets $file_b line_b] == $eof } {
321 set negated [expr { [string index $line_b 0] == "!" }]
322 set line_bx [string range $line_b $negated end]
323 set n [expr { $negated ? "! " : "" }]
324 # Substitute on the reference.
325 foreach {name value} $ref_subst {
326 regsub -- $name $line_bx $value line_bx
328 verbose "looking for $n\"^$line_bx$\"" 3
329 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
330 verbose "skipping \"$line_a\"" 3
331 if { [gets $file_a line_a] == $eof } {
338 if { [gets $file_b line_b] == $eof } {
346 } elseif { $end_1 && $end_2 } {
348 } elseif { $end_1 } {
349 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
350 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
353 } elseif { $end_2 } {
354 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
355 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
359 set negated [expr { [string index $line_b 0] == "!" }]
360 set line_bx [string range $line_b $negated end]
361 set n [expr { $negated ? "! " : "" }]
362 set s [expr { $negated ? " " : "" }]
363 # Substitute on the reference.
364 foreach {name value} $ref_subst {
365 regsub -- $name $line_bx $value line_bx
367 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
368 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
369 send_log "regexp_diff match failure\n"
370 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
371 verbose "regexp_diff match failure\n" 3
377 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
378 send_log "$file_1 and $file_2 are different lengths\n"
379 verbose "$file_1 and $file_2 are different lengths" 3
383 if { $fail_if_match } {
384 if { $differences == 0 } {