1 # Copyright (C) 1993-2015 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 if { ![istarget *-*-sysv4*]
24 && ![istarget *-*-unixware*]
25 && ![istarget *-*-elf*]
26 && ![istarget *-*-eabi*]
27 && ![istarget *-*-rtems*]
28 && ![istarget hppa*64*-*-hpux*]
29 && ![istarget ia64-*-hpux*]
30 && ![istarget *-*-linux*]
31 && ![istarget *-*-gnu*]
32 && ![istarget *-*-nacl*]
33 && ![istarget frv-*-uclinux*]
34 && ![istarget bfin-*-uclinux]
35 && ![istarget sh*-*-uclinux*]
36 && ![istarget tic6x*-*-uclinux*]
37 && ![istarget *-*-irix5*]
38 && ![istarget *-*-irix6*]
39 && ![istarget *-*-netbsd*]
40 && ![istarget *-*-openbsd*]
41 && ![istarget *-*-solaris2*] } {
45 if { [istarget *-*-linux*aout*]
46 || [istarget *-*-linux*ecoff*]
47 || [istarget *-*-linux*oldld*]
48 || [istarget h8500-*-rtems*]
49 || [istarget i960-*-rtems*]
50 || [istarget *-*-rtemscoff*] } {
54 if { ![istarget *-*-netbsdelf*]
55 && ([istarget *-*-netbsd*aout*]
56 || [istarget *-*-netbsdpe*]
57 || [istarget arm*-*-netbsd*]
58 || [istarget sparc-*-netbsd*]
59 || [istarget i*86-*-netbsd*]
60 || [istarget m68*-*-netbsd*]
61 || [istarget vax-*-netbsd*]
62 || [istarget ns32k-*-netbsd*]) } {
66 if { [istarget arm-*-openbsd*]
67 || [istarget i386-*-openbsd\[0-2\].*]
68 || [istarget i386-*-openbsd3.\[0-2\]]
69 || [istarget m68*-*-openbsd*]
70 || [istarget ns32k-*-openbsd*]
71 || [istarget sparc-*-openbsd\[0-2\].*]
72 || [istarget sparc-*-openbsd3.\[0-1\]]
73 || [istarget vax-*-openbsd*] } {
80 # True if the object format is known to be a.out.
82 proc is_aout_format {} {
83 if { [istarget *-*-netbsdelf]
84 || [istarget sparc64-*-netbsd*]
85 || [istarget sparc64-*-openbsd*] } {
88 if { [istarget *-*-*\[ab\]out*]
89 || [istarget *-*-linux*oldld*]
90 || [istarget *-*-bsd*]
91 || [istarget *-*-msdos*]
92 || [istarget arm-*-netbsd*]
93 || [istarget arm-*-openbsd*]
94 || [istarget arm-*-riscix*]
95 || [istarget i?86-*-freebsd\[12\]*]
96 || [istarget i?86-*-netbsd*]
97 || [istarget i?86-*-openbsd\[0-2\]*]
98 || [istarget i?86-*-openbsd3.\[0-2\]*]
99 || [istarget i?86-*-vsta]
100 || [istarget i?86-*-mach*]
101 || [istarget m68*-*-netbsd*]
102 || [istarget m68*-*-openbsd*]
103 || [istarget ns32k-*-*]
104 || [istarget pdp11-*-*]
105 || [istarget sparc*-*-sunos4*]
106 || [istarget sparc*-*-netbsd*]
107 || [istarget sparc*-*-openbsd\[0-2\]*]
108 || [istarget sparc*-*-openbsd3.\[0-1\]*]
109 || [istarget sparc*-fujitsu-none]
110 || [istarget vax-dec-ultrix*]
111 || [istarget vax-*-netbsd] } {
117 # True if the object format is known to be PE COFF.
119 proc is_pecoff_format {} {
120 if { ![istarget *-*-mingw*]
121 && ![istarget *-*-cygwin*]
122 && ![istarget *-*-cegcc*]
123 && ![istarget *-*-pe*] } {
130 # True if the object format is known to be 64-bit ELF.
132 proc is_elf64 { binary_file } {
137 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
139 if ![string match "" $got] then {
143 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
144 [file_contents readelf.out] nil readelf_size] } {
148 if { $readelf_size == "64" } {
155 # True if the build supports zlib compression.
156 proc is_zlib_supported {} {
160 # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
161 # is the expected output. Ignore blank lines in either file.
163 # FILE_2 is a series of regexps, comments and # directives. The directives
167 # Treat the test as a PASS if everything up till this point has
168 # matched. Ignore any remaining lines in either FILE_1 or FILE_2.
171 # Reverse the sense of the test: expect differences to exist.
175 # Skip all lines in FILE_1 until the first that matches REGEXP.
177 # Other # lines are comments. Regexp lines starting with the `!' character
178 # specify inverse matching (use `\!' for literal matching against a leading
179 # `!'). Skip empty lines in both files.
181 # The first optional argument is a list of regexp substitutions of the form:
183 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
185 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
186 # in order to every line of FILE_2.
188 # Return nonzero if differences exist.
189 proc regexp_diff { file_1 file_2 args } {
197 if { [llength $args] > 0 } {
198 set ref_subst [lindex $args 0]
200 if { [llength $args] > 1 } {
201 perror "Too many arguments to regexp_diff"
205 if [file exists $file_1] then {
206 set file_a [open $file_1 r]
208 perror "$file_1 doesn't exist"
212 if [file exists $file_2] then {
213 set file_b [open $file_2 r]
215 perror "$file_2 doesn't exist"
220 verbose " Regexp-diff'ing: $file_1 $file_2" 2
225 while { [string length $line_a] == 0 } {
226 # Ignore blank line in FILE_1.
227 if { [gets $file_a line_a] == $eof } {
232 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
233 if { [string match "#pass" $line_b] } {
237 } elseif { [string match "#failif" $line_b] } {
238 send_log "fail if no difference\n"
239 verbose "fail if no difference" 3
241 } elseif { [string match "#..." $line_b] } {
242 if { [gets $file_b line_b] == $eof } {
247 set negated [expr { [string index $line_b 0] == "!" }]
248 set line_bx [string range $line_b $negated end]
249 set n [expr { $negated ? "! " : "" }]
250 # Substitute on the reference.
251 foreach {name value} $ref_subst {
252 regsub -- $name $line_bx $value line_bx
254 verbose "looking for $n\"^$line_bx$\"" 3
255 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
256 verbose "skipping \"$line_a\"" 3
257 if { [gets $file_a line_a] == $eof } {
264 if { [gets $file_b line_b] == $eof } {
272 } elseif { $end_1 && $end_2 } {
274 } elseif { $end_1 } {
275 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
276 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
279 } elseif { $end_2 } {
280 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
281 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
285 set negated [expr { [string index $line_b 0] == "!" }]
286 set line_bx [string range $line_b $negated end]
287 set n [expr { $negated ? "! " : "" }]
288 set s [expr { $negated ? " " : "" }]
289 # Substitute on the reference.
290 foreach {name value} $ref_subst {
291 regsub -- $name $line_bx $value line_bx
293 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
294 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
295 send_log "regexp_diff match failure\n"
296 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
297 verbose "regexp_diff match failure\n" 3
303 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
304 send_log "$file_1 and $file_2 are different lengths\n"
305 verbose "$file_1 and $file_2 are different lengths" 3
309 if { $fail_if_match } {
310 if { $differences == 0 } {