1 # Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004, 2006, 2007,
2 # 2009, 2010, 2011 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
6 # This file is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 # True if the object format is known to be ELF.
23 proc is_elf_format {} {
24 if { ![istarget *-*-sysv4*]
25 && ![istarget *-*-unixware*]
26 && ![istarget *-*-elf*]
27 && ![istarget *-*-eabi*]
28 && ![istarget *-*-rtems*]
29 && ![istarget hppa*64*-*-hpux*]
30 && ![istarget ia64-*-hpux*]
31 && ![istarget *-*-linux*]
32 && ![istarget *-*-gnu*]
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*oldld*]
47 || [istarget h8500-*-rtems*]
48 || [istarget i960-*-rtems*]
49 || [istarget *-*-rtemscoff*] } {
53 if { ![istarget *-*-netbsdelf*]
54 && ([istarget *-*-netbsd*aout*]
55 || [istarget *-*-netbsdpe*]
56 || [istarget arm*-*-netbsd*]
57 || [istarget sparc-*-netbsd*]
58 || [istarget i*86-*-netbsd*]
59 || [istarget m68*-*-netbsd*]
60 || [istarget vax-*-netbsd*]
61 || [istarget ns32k-*-netbsd*]) } {
65 if { [istarget arm-*-openbsd*]
66 || [istarget i386-*-openbsd\[0-2\].*]
67 || [istarget i386-*-openbsd3.\[0-2\]]
68 || [istarget m68*-*-openbsd*]
69 || [istarget ns32k-*-openbsd*]
70 || [istarget sparc-*-openbsd\[0-2\].*]
71 || [istarget sparc-*-openbsd3.\[0-1\]]
72 || [istarget vax-*-openbsd*] } {
79 # True if the object format is known to be a.out.
81 proc is_aout_format {} {
82 if { [istarget *-*-netbsdelf]
83 || [istarget sparc64-*-netbsd*]
84 || [istarget sparc64-*-openbsd*] } {
87 if { [istarget *-*-*\[ab\]out*]
88 || [istarget *-*-linux*oldld*]
89 || [istarget *-*-bsd*]
90 || [istarget *-*-msdos*]
91 || [istarget arm-*-netbsd*]
92 || [istarget arm-*-openbsd*]
93 || [istarget arm-*-riscix*]
94 || [istarget i?86-*-freebsd\[12\]*]
95 || [istarget i?86-*-netbsd*]
96 || [istarget i?86-*-openbsd\[0-2\]*]
97 || [istarget i?86-*-openbsd3.\[0-2\]*]
98 || [istarget i?86-*-vsta]
99 || [istarget i?86-*-mach*]
100 || [istarget m68*-*-netbsd*]
101 || [istarget m68*-*-openbsd*]
102 || [istarget ns32k-*-*]
103 || [istarget pdp11-*-*]
104 || [istarget sparc*-*-sunos4*]
105 || [istarget sparc*-*-netbsd*]
106 || [istarget sparc*-*-openbsd\[0-2\]*]
107 || [istarget sparc*-*-openbsd3.\[0-1\]*]
108 || [istarget sparc*-fujitsu-none]
109 || [istarget vax-dec-ultrix*]
110 || [istarget vax-*-netbsd] } {
116 # True if the object format is known to be PE COFF.
118 proc is_pecoff_format {} {
119 if { ![istarget *-*-mingw*]
120 && ![istarget *-*-cygwin*]
121 && ![istarget *-*-cegcc*]
122 && ![istarget *-*-pe*] } {
129 # True if the object format is known to be 64-bit ELF.
131 proc is_elf64 { binary_file } {
136 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
138 if ![string match "" $got] then {
142 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
143 [file_contents readelf.out] nil readelf_size] } {
147 if { $readelf_size == "64" } {
154 # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
155 # is the expected output. Ignore blank lines in either file.
157 # FILE_2 is a series of regexps, comments and # directives. The directives
161 # Treat the test as a PASS if everything up till this point has
162 # matched. Ignore any remaining lines in either FILE_1 or FILE_2.
165 # Reverse the sense of the test: expect differences to exist.
169 # Skip all lines in FILE_1 until the first that matches REGEXP.
171 # Other # lines are comments. Regexp lines starting with the `!' character
172 # specify inverse matching (use `\!' for literal matching against a leading
173 # `!'). Skip empty lines in both files.
175 # The first optional argument is a list of regexp substitutions of the form:
177 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
179 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
180 # in order to every line of FILE_2.
182 # Return nonzero if differences exist.
183 proc regexp_diff { file_1 file_2 args } {
191 if { [llength $args] > 0 } {
192 set ref_subst [lindex $args 0]
194 if { [llength $args] > 1 } {
195 perror "Too many arguments to regexp_diff"
199 if [file exists $file_1] then {
200 set file_a [open $file_1 r]
202 perror "$file_1 doesn't exist"
206 if [file exists $file_2] then {
207 set file_b [open $file_2 r]
209 perror "$file_2 doesn't exist"
214 verbose " Regexp-diff'ing: $file_1 $file_2" 2
219 while { [string length $line_a] == 0 } {
220 # Ignore blank line in FILE_1.
221 if { [gets $file_a line_a] == $eof } {
226 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
227 if { [string match "#pass" $line_b] } {
231 } elseif { [string match "#failif" $line_b] } {
232 send_log "fail if no difference\n"
233 verbose "fail if no difference" 3
235 } elseif { [string match "#..." $line_b] } {
236 if { [gets $file_b line_b] == $eof } {
241 set negated [expr { [string index $line_b 0] == "!" }]
242 set line_bx [string range $line_b $negated end]
243 set n [expr { $negated ? "! " : "" }]
244 # Substitute on the reference.
245 foreach {name value} $ref_subst {
246 regsub -- $name $line_bx $value line_bx
248 verbose "looking for $n\"^$line_bx$\"" 3
249 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
250 verbose "skipping \"$line_a\"" 3
251 if { [gets $file_a line_a] == $eof } {
258 if { [gets $file_b line_b] == $eof } {
266 } elseif { $end_1 && $end_2 } {
268 } elseif { $end_1 } {
269 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
270 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
273 } elseif { $end_2 } {
274 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
275 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
279 set negated [expr { [string index $line_b 0] == "!" }]
280 set line_bx [string range $line_b $negated end]
281 set n [expr { $negated ? "! " : "" }]
282 set s [expr { $negated ? " " : "" }]
283 # Substitute on the reference.
284 foreach {name value} $ref_subst {
285 regsub -- $name $line_bx $value line_bx
287 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
288 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
289 send_log "regexp_diff match failure\n"
290 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
291 verbose "regexp_diff match failure\n" 3
297 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
298 send_log "$file_1 and $file_2 are different lengths\n"
299 verbose "$file_1 and $file_2 are different lengths" 3
303 if { $fail_if_match } {
304 if { $differences == 0 } {