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 arm*-*-uclinuxfdpiceabi]
48 && ![istarget avr-*-*]
49 && ![istarget bfin-*-uclinux]
50 && ![istarget frv-*-uclinux*]
51 && ![istarget hppa*64*-*-hpux*]
52 && ![istarget ia64-*-hpux*]
53 && ![istarget sh*-*-uclinux*]
54 && ![istarget tic6x*-*-uclinux*] } {
58 if { [istarget *-*-linux*ecoff*]
59 || [istarget *-*-rtemscoff*] } {
63 if { ![istarget *-*-netbsdelf*]
64 && ( [istarget vax-*-netbsd*]
65 || [istarget ns32k-*-netbsd*]) } {
69 if { [istarget arm-*-openbsd*]
70 || [istarget ns32k-*-openbsd*]
71 || [istarget vax-*-openbsd*] } {
78 # True if the object format is known to be a.out.
80 proc is_aout_format {} {
81 if { [istarget *-*-*aout*]
82 || [istarget *-*-bsd*]
83 || [istarget *-*-msdos*]
84 || [istarget ns32k-*-*]
85 || [istarget pdp11-*-*]
86 || [istarget vax-*-netbsd] } {
92 # True if the object format is known to be PE COFF.
94 proc is_pecoff_format {} {
95 if { ![istarget *-*-mingw*]
96 && ![istarget *-*-cygwin*]
97 && ![istarget *-*-cegcc*]
98 && ![istarget *-*-pe*] } {
105 # True if the object format is known to be 64-bit ELF.
107 proc is_elf64 { binary_file } {
112 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
114 if ![string match "" $got] then {
118 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
119 [file_contents readelf.out] nil readelf_size] } {
123 if { $readelf_size == "64" } {
130 # True if the target matches TARGET, specified as a TCL procedure if
131 # in square brackets or as machine triplet otherwise.
133 proc match_target { target } {
134 if [string match {\[*\]} $target] {
137 return [istarget $target]
141 # True if the ELF target supports STB_GNU_UNIQUE with the ELF header's
142 # OSABI field set to ELFOSABI_GNU.
144 # This generally depends on the target OS only, however there are a
145 # number of exceptions for bare metal targets as follows. The MSP430
146 # and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot
147 # support STB_GNU_UNIQUE. Likewise non-EABI ARM targets set OSABI to
148 # ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*. Finally
149 # rather than `bfd_elf_final_link' AM33/2.0, D30V, DLX, and
150 # picoJava targets use `_bfd_generic_final_link', which does not
151 # support STB_GNU_UNIQUE symbol binding causing assertion failures.
153 proc supports_gnu_unique {} {
154 if { [istarget *-*-gnu*]
155 || [istarget *-*-linux*]
156 || [istarget *-*-nacl*] } {
159 if { [istarget "arm*-*-*eabi*"] } {
162 if { [istarget "wasm32*-*-*"] } {
165 if { ![istarget "*-*-elf*"] } {
168 if { [istarget "arm*-*-*"]
169 || [istarget "msp430-*-*"]
170 || [istarget "tic6x-*-*"]
171 || [istarget "visium-*-*"] } {
174 if { [istarget "am33_2.0-*-*"]
175 || [istarget "d30v-*-*"]
176 || [istarget "dlx-*-*"]
177 || [istarget "pj*-*-*"] } {
183 # True for targets that do not sort .symtab as per the ELF standard.
184 # ie. any that have mips_elf32_be_vec, mips_elf32_le_vec,
185 # mips_elf32_n_be_vec or mips_elf32_n_le_vec as the primary bfd target
186 # vector in config.bfd. When syncing with config.bfd, don't forget that
187 # earlier case-matches trump later ones.
188 proc is_bad_symtab {} {
189 if { ![istarget "mips*-*-*"] } {
192 if { [istarget "*-*-chorus*"]
193 || [istarget "*-*-irix5*"]
194 || [istarget "*-*-irix6*"]
195 || [istarget "*-*-none"]
196 || [istarget "*-*-rtems*"]
197 || [istarget "*-*-windiss"] } {
200 if { [istarget "*-*-elf*"]
201 && ![istarget "*-sde-*"]
202 && ![istarget "*-mti-*"]
203 && ![istarget "*-img-*"] } {
206 if { [istarget "*-*-openbsd*"]
207 && ![istarget "mips64*-*-*"] } {
213 # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
214 # is the expected output. Ignore blank lines in either file.
216 # FILE_2 is a series of regexps, comments and # directives. The directives
220 # Treat the test as a PASS if everything up till this point has
221 # matched. Ignore any remaining lines in either FILE_1 or FILE_2.
224 # Reverse the sense of the test: expect differences to exist.
228 # Skip all lines in FILE_1 until the first that matches REGEXP.
230 # Other # lines are comments. Regexp lines starting with the `!' character
231 # specify inverse matching (use `\!' for literal matching against a leading
232 # `!'). Skip empty lines in both files.
234 # The first optional argument is a list of regexp substitutions of the form:
236 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
238 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
239 # in order to every line of FILE_2.
241 # Return nonzero if differences exist.
242 proc regexp_diff { file_1 file_2 args } {
250 if { [llength $args] > 0 } {
251 set ref_subst [lindex $args 0]
253 if { [llength $args] > 1 } {
254 perror "Too many arguments to regexp_diff"
258 if [file exists $file_1] then {
259 set file_a [open $file_1 r]
261 perror "$file_1 doesn't exist"
265 if [file exists $file_2] then {
266 set file_b [open $file_2 r]
268 perror "$file_2 doesn't exist"
273 verbose " Regexp-diff'ing: $file_1 $file_2" 2
278 while { [string length $line_a] == 0 } {
279 # Ignore blank line in FILE_1.
280 if { [gets $file_a line_a] == $eof } {
285 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
286 if { [string match "#pass" $line_b] } {
290 } elseif { [string match "#failif" $line_b] } {
291 send_log "fail if no difference\n"
292 verbose "fail if no difference" 3
294 } elseif { [string match "#..." $line_b] } {
295 if { [gets $file_b line_b] == $eof } {
300 set negated [expr { [string index $line_b 0] == "!" }]
301 set line_bx [string range $line_b $negated end]
302 set n [expr { $negated ? "! " : "" }]
303 # Substitute on the reference.
304 foreach {name value} $ref_subst {
305 regsub -- $name $line_bx $value line_bx
307 verbose "looking for $n\"^$line_bx$\"" 3
308 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
309 verbose "skipping \"$line_a\"" 3
310 if { [gets $file_a line_a] == $eof } {
317 if { [gets $file_b line_b] == $eof } {
325 } elseif { $end_1 && $end_2 } {
327 } elseif { $end_1 } {
328 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
329 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
332 } elseif { $end_2 } {
333 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
334 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
338 set negated [expr { [string index $line_b 0] == "!" }]
339 set line_bx [string range $line_b $negated end]
340 set n [expr { $negated ? "! " : "" }]
341 set s [expr { $negated ? " " : "" }]
342 # Substitute on the reference.
343 foreach {name value} $ref_subst {
344 regsub -- $name $line_bx $value line_bx
346 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
347 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
348 send_log "regexp_diff match failure\n"
349 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
350 verbose "regexp_diff match failure\n" 3
356 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
357 send_log "$file_1 and $file_2 are different lengths\n"
358 verbose "$file_1 and $file_2 are different lengths" 3
362 if { $fail_if_match } {
363 if { $differences == 0 } {