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 s12z*-*] || [istarget xgate-*] } {
29 # vxworks (and windiss) excluded due to number of ELF tests that need
30 # modifying to pass on those targets.
31 # && ![istarget *-*-vxworks*]
32 # && ![istarget *-*-windiss*]
34 if { ![istarget *-*-chorus*]
35 && ![istarget *-*-cloudabi*]
36 && ![istarget *-*-eabi*]
37 && ![istarget *-*-*elf*]
38 && ![istarget *-*-*freebsd*]
39 && ![istarget *-*-fuchsia*]
40 && ![istarget *-*-gnu*]
41 && ![istarget *-*-irix5*]
42 && ![istarget *-*-irix6*]
43 && ![istarget *-*-kaos*]
44 && ![istarget *-*-*linux*]
45 && ![istarget *-*-lynxos*]
46 && ![istarget *-*-nacl*]
47 && ![istarget *-*-netbsd*]
48 && ![istarget *-*-nto*]
49 && ![istarget *-*-openbsd*]
50 && ![istarget *-*-rtems*]
51 && ![istarget *-*-solaris2*]
52 && ![istarget *-*-sysv4*]
53 && ![istarget *-*-unixware*]
54 && ![istarget *-*-wasm32*]
55 && ![istarget avr-*-*]
56 && ![istarget hppa*64*-*-hpux*]
57 && ![istarget ia64-*-hpux*] } {
61 if { [istarget *-*-linux*ecoff*]
62 || [istarget *-*-rtemscoff*] } {
66 if { ![istarget *-*-netbsdelf*]
67 && ( [istarget vax-*-netbsd*]
68 || [istarget ns32k-*-netbsd*]) } {
72 if { [istarget arm-*-openbsd*]
73 || [istarget ns32k-*-openbsd*]
74 || [istarget vax-*-openbsd*] } {
81 # True if the object format is known to be a.out.
83 proc is_aout_format {} {
84 if { [istarget *-*-*aout*]
85 || [istarget *-*-bsd*]
86 || [istarget *-*-msdos*]
87 || [istarget ns32k-*-*]
88 || [istarget pdp11-*-*]
89 || [istarget vax-*-netbsd] } {
95 # True if the object format is known to be PE COFF.
97 proc is_pecoff_format {} {
98 if { ![istarget *-*-mingw*]
99 && ![istarget *-*-cygwin*]
100 && ![istarget *-*-cegcc*]
101 && ![istarget *-*-pe*] } {
108 # True if the object format is known to be 64-bit ELF.
110 proc is_elf64 { binary_file } {
115 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
117 if ![string match "" $got] then {
121 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
122 [file_contents readelf.out] nil readelf_size] } {
126 if { $readelf_size == "64" } {
133 # True if the target matches TARGET, specified as a TCL procedure if
134 # in square brackets or as machine triplet otherwise.
136 proc match_target { target } {
137 if [string match {\[*\]} $target] {
140 return [istarget $target]
144 # True if the ELF target supports STB_GNU_UNIQUE with the ELF header's
145 # OSABI field set to ELFOSABI_GNU.
147 # This generally depends on the target OS only, however there are a
148 # number of exceptions for bare metal targets as follows. The MSP430
149 # and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot
150 # support STB_GNU_UNIQUE. Likewise non-EABI ARM targets set OSABI to
151 # ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*. Finally
152 # rather than `bfd_elf_final_link' AM33/2.0, D30V, DLX, and
153 # picoJava targets use `_bfd_generic_final_link', which does not
154 # support STB_GNU_UNIQUE symbol binding causing assertion failures.
156 proc supports_gnu_unique {} {
157 if { [istarget *-*-gnu*]
158 || [istarget *-*-linux*]
159 || [istarget *-*-nacl*] } {
162 if { [istarget "arm*-*-*eabi*"] } {
165 if { [istarget "wasm32*-*-*"] } {
168 if { ![istarget "*-*-elf*"] } {
171 if { [istarget "arm*-*-*"]
172 || [istarget "msp430-*-*"]
173 || [istarget "tic6x-*-*"]
174 || [istarget "visium-*-*"] } {
177 if { [istarget "am33_2.0-*-*"]
178 || [istarget "d30v-*-*"]
179 || [istarget "dlx-*-*"]
180 || [istarget "pj*-*-*"] } {
186 # True for targets that do not sort .symtab as per the ELF standard.
187 # ie. any that have mips_elf32_be_vec, mips_elf32_le_vec,
188 # mips_elf32_n_be_vec or mips_elf32_n_le_vec as the primary bfd target
189 # vector in config.bfd. When syncing with config.bfd, don't forget that
190 # earlier case-matches trump later ones.
191 proc is_bad_symtab {} {
192 if { ![istarget "mips*-*-*"] } {
195 if { [istarget "*-*-chorus*"]
196 || [istarget "*-*-irix5*"]
197 || [istarget "*-*-irix6*"]
198 || [istarget "*-*-none"]
199 || [istarget "*-*-rtems*"]
200 || [istarget "*-*-windiss"] } {
203 if { [istarget "*-*-elf*"]
204 && ![istarget "*-sde-*"]
205 && ![istarget "*-mti-*"]
206 && ![istarget "*-img-*"] } {
209 if { [istarget "*-*-openbsd*"]
210 && ![istarget "mips64*-*-*"] } {
216 # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
217 # is the expected output. Ignore blank lines in either file.
219 # FILE_2 is a series of regexps, comments and # directives. The directives
223 # Treat the test as a PASS if everything up till this point has
224 # matched. Ignore any remaining lines in either FILE_1 or FILE_2.
227 # Reverse the sense of the test: expect differences to exist.
231 # Skip all lines in FILE_1 until the first that matches REGEXP.
233 # Other # lines are comments. Regexp lines starting with the `!' character
234 # specify inverse matching (use `\!' for literal matching against a leading
235 # `!'). Skip empty lines in both files.
237 # The first optional argument is a list of regexp substitutions of the form:
239 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
241 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
242 # in order to every line of FILE_2.
244 # Return nonzero if differences exist.
245 proc regexp_diff { file_1 file_2 args } {
253 if { [llength $args] > 0 } {
254 set ref_subst [lindex $args 0]
256 if { [llength $args] > 1 } {
257 perror "Too many arguments to regexp_diff"
261 if [file exists $file_1] then {
262 set file_a [open $file_1 r]
264 perror "$file_1 doesn't exist"
268 if [file exists $file_2] then {
269 set file_b [open $file_2 r]
271 perror "$file_2 doesn't exist"
276 verbose " Regexp-diff'ing: $file_1 $file_2" 2
281 while { [string length $line_a] == 0 } {
282 # Ignore blank line in FILE_1.
283 if { [gets $file_a line_a] == $eof } {
288 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
289 if { [string match "#pass" $line_b] } {
293 } elseif { [string match "#failif" $line_b] } {
294 send_log "fail if no difference\n"
295 verbose "fail if no difference" 3
297 } elseif { [string match "#..." $line_b] } {
298 if { [gets $file_b line_b] == $eof } {
303 set negated [expr { [string index $line_b 0] == "!" }]
304 set line_bx [string range $line_b $negated end]
305 set n [expr { $negated ? "! " : "" }]
306 # Substitute on the reference.
307 foreach {name value} $ref_subst {
308 regsub -- $name $line_bx $value line_bx
310 verbose "looking for $n\"^$line_bx$\"" 3
311 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
312 verbose "skipping \"$line_a\"" 3
313 if { [gets $file_a line_a] == $eof } {
320 if { [gets $file_b line_b] == $eof } {
328 } elseif { $end_1 && $end_2 } {
330 } elseif { $end_1 } {
331 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
332 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
335 } elseif { $end_2 } {
336 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
337 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
341 set negated [expr { [string index $line_b 0] == "!" }]
342 set line_bx [string range $line_b $negated end]
343 set n [expr { $negated ? "! " : "" }]
344 set s [expr { $negated ? " " : "" }]
345 # Substitute on the reference.
346 foreach {name value} $ref_subst {
347 regsub -- $name $line_bx $value line_bx
349 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
350 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
351 send_log "regexp_diff match failure\n"
352 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
353 verbose "regexp_diff match failure\n" 3
359 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
360 send_log "$file_1 and $file_2 are different lengths\n"
361 verbose "$file_1 and $file_2 are different lengths" 3
365 if { $fail_if_match } {
366 if { $differences == 0 } {