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*ecoff*]
58 || [istarget *-*-rtemscoff*] } {
62 if { ![istarget *-*-netbsdelf*]
63 && ( [istarget vax-*-netbsd*]
64 || [istarget ns32k-*-netbsd*]) } {
68 if { [istarget arm-*-openbsd*]
69 || [istarget ns32k-*-openbsd*]
70 || [istarget vax-*-openbsd*] } {
77 # True if the object format is known to be a.out.
79 proc is_aout_format {} {
80 if { [istarget *-*-*aout*]
81 || [istarget *-*-bsd*]
82 || [istarget *-*-msdos*]
83 || [istarget ns32k-*-*]
84 || [istarget pdp11-*-*]
85 || [istarget vax-*-netbsd] } {
91 # True if the object format is known to be PE COFF.
93 proc is_pecoff_format {} {
94 if { ![istarget *-*-mingw*]
95 && ![istarget *-*-cygwin*]
96 && ![istarget *-*-cegcc*]
97 && ![istarget *-*-pe*] } {
104 # True if the object format is known to be 64-bit ELF.
106 proc is_elf64 { binary_file } {
111 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
113 if ![string match "" $got] then {
117 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
118 [file_contents readelf.out] nil readelf_size] } {
122 if { $readelf_size == "64" } {
129 # True if the ELF target supports STB_GNU_UNIQUE with the ELF header's
130 # OSABI field set to ELFOSABI_GNU.
132 # This generally depends on the target OS only, however there are a
133 # number of exceptions for bare metal targets as follows. The MSP430
134 # and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot
135 # support STB_GNU_UNIQUE. Likewise non-EABI ARM targets set OSABI to
136 # ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*. Finally
137 # rather than `bfd_elf_final_link' AM33/2.0, D30V, DLX, and
138 # picoJava targets use `_bfd_generic_final_link', which does not
139 # support STB_GNU_UNIQUE symbol binding causing assertion failures.
141 proc supports_gnu_unique {} {
142 if { [istarget *-*-gnu*]
143 || [istarget *-*-linux*]
144 || [istarget *-*-nacl*] } {
147 if { [istarget "arm*-*-*eabi*"] } {
150 if { [istarget "wasm32*-*-*"] } {
153 if { ![istarget "*-*-elf*"] } {
156 if { [istarget "arm*-*-*"]
157 || [istarget "msp430-*-*"]
158 || [istarget "tic6x-*-*"]
159 || [istarget "visium-*-*"] } {
162 if { [istarget "am33_2.0-*-*"]
163 || [istarget "d30v-*-*"]
164 || [istarget "dlx-*-*"]
165 || [istarget "pj*-*-*"] } {
171 # True for targets that do not sort .symtab as per the ELF standard.
172 # ie. any that have mips_elf32_be_vec, mips_elf32_le_vec,
173 # mips_elf32_n_be_vec or mips_elf32_n_le_vec as the primary bfd target
174 # vector in config.bfd. When syncing with config.bfd, don't forget that
175 # earlier case-matches trump later ones.
176 proc is_bad_symtab {} {
177 if { ![istarget "mips*-*-*"] } {
180 if { [istarget "*-*-chorus*"]
181 || [istarget "*-*-irix5*"]
182 || [istarget "*-*-irix6*"]
183 || [istarget "*-*-none"]
184 || [istarget "*-*-rtems*"]
185 || [istarget "*-*-windiss"] } {
188 if { [istarget "*-*-elf*"]
189 && ![istarget "*-sde-*"]
190 && ![istarget "*-mti-*"]
191 && ![istarget "*-img-*"] } {
194 if { [istarget "*-*-openbsd*"]
195 && ![istarget "mips64*-*-*"] } {
201 # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
202 # is the expected output. Ignore blank lines in either file.
204 # FILE_2 is a series of regexps, comments and # directives. The directives
208 # Treat the test as a PASS if everything up till this point has
209 # matched. Ignore any remaining lines in either FILE_1 or FILE_2.
212 # Reverse the sense of the test: expect differences to exist.
216 # Skip all lines in FILE_1 until the first that matches REGEXP.
218 # Other # lines are comments. Regexp lines starting with the `!' character
219 # specify inverse matching (use `\!' for literal matching against a leading
220 # `!'). Skip empty lines in both files.
222 # The first optional argument is a list of regexp substitutions of the form:
224 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
226 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
227 # in order to every line of FILE_2.
229 # Return nonzero if differences exist.
230 proc regexp_diff { file_1 file_2 args } {
238 if { [llength $args] > 0 } {
239 set ref_subst [lindex $args 0]
241 if { [llength $args] > 1 } {
242 perror "Too many arguments to regexp_diff"
246 if [file exists $file_1] then {
247 set file_a [open $file_1 r]
249 perror "$file_1 doesn't exist"
253 if [file exists $file_2] then {
254 set file_b [open $file_2 r]
256 perror "$file_2 doesn't exist"
261 verbose " Regexp-diff'ing: $file_1 $file_2" 2
266 while { [string length $line_a] == 0 } {
267 # Ignore blank line in FILE_1.
268 if { [gets $file_a line_a] == $eof } {
273 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
274 if { [string match "#pass" $line_b] } {
278 } elseif { [string match "#failif" $line_b] } {
279 send_log "fail if no difference\n"
280 verbose "fail if no difference" 3
282 } elseif { [string match "#..." $line_b] } {
283 if { [gets $file_b line_b] == $eof } {
288 set negated [expr { [string index $line_b 0] == "!" }]
289 set line_bx [string range $line_b $negated end]
290 set n [expr { $negated ? "! " : "" }]
291 # Substitute on the reference.
292 foreach {name value} $ref_subst {
293 regsub -- $name $line_bx $value line_bx
295 verbose "looking for $n\"^$line_bx$\"" 3
296 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
297 verbose "skipping \"$line_a\"" 3
298 if { [gets $file_a line_a] == $eof } {
305 if { [gets $file_b line_b] == $eof } {
313 } elseif { $end_1 && $end_2 } {
315 } elseif { $end_1 } {
316 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
317 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
320 } elseif { $end_2 } {
321 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
322 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
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 set s [expr { $negated ? " " : "" }]
330 # Substitute on the reference.
331 foreach {name value} $ref_subst {
332 regsub -- $name $line_bx $value line_bx
334 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
335 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
336 send_log "regexp_diff match failure\n"
337 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
338 verbose "regexp_diff match failure\n" 3
344 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
345 send_log "$file_1 and $file_2 are different lengths\n"
346 verbose "$file_1 and $file_2 are different lengths" 3
350 if { $fail_if_match } {
351 if { $differences == 0 } {