1 # Copyright
1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004, 2006, 2007,
2 #
2009, 2010 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
*-*-irix5
*]
37 && ![istarget
*-*-irix6
*]
38 && ![istarget
*-*-netbsd
*]
39 && ![istarget
*-*-openbsd
*]
40 && ![istarget
*-*-solaris2
*] } {
44 if { [istarget
*-*-linux
*aout
*]
45 ||
[istarget
*-*-linux
*oldld
*]
46 ||
[istarget h8500
-*-rtems
*]
47 ||
[istarget i960
-*-rtems
*]
48 ||
[istarget
*-*-rtemscoff
*] } {
52 if { ![istarget
*-*-netbsdelf
*]
53 && ([istarget
*-*-netbsd
*aout
*]
54 ||
[istarget
*-*-netbsdpe
*]
55 ||
[istarget arm
*-*-netbsd
*]
56 ||
[istarget sparc
-*-netbsd
*]
57 ||
[istarget i
*86-*-netbsd
*]
58 ||
[istarget m68
*-*-netbsd
*]
59 ||
[istarget vax
-*-netbsd
*]
60 ||
[istarget ns32k
-*-netbsd
*]) } {
64 if { [istarget arm
-*-openbsd
*]
65 ||
[istarget i386
-*-openbsd\
[0-2\
].
*]
66 ||
[istarget i386
-*-openbsd3.\
[0-2\
]]
67 ||
[istarget m68
*-*-openbsd
*]
68 ||
[istarget ns32k
-*-openbsd
*]
69 ||
[istarget sparc
-*-openbsd\
[0-2\
].
*]
70 ||
[istarget sparc
-*-openbsd3.\
[0-1\
]]
71 ||
[istarget vax
-*-openbsd
*] } {
78 # True
if the object format is known to be a.out.
80 proc is_aout_format
{} {
81 if { [istarget
*-*-netbsdelf
]
82 ||
[istarget sparc64
-*-netbsd
*]
83 ||
[istarget sparc64
-*-openbsd
*] } {
86 if { [istarget
*-*-*\
[ab\
]out
*]
87 ||
[istarget
*-*-linux
*oldld
*]
88 ||
[istarget
*-*-bsd
*]
89 ||
[istarget
*-*-msdos
*]
90 ||
[istarget arm
-*-netbsd
*]
91 ||
[istarget arm
-*-openbsd
*]
92 ||
[istarget arm
-*-riscix
*]
93 ||
[istarget i?
86-*-freebsd\
[12\
]*]
94 ||
[istarget i?
86-*-netbsd
*]
95 ||
[istarget i?
86-*-openbsd\
[0-2\
]*]
96 ||
[istarget i?
86-*-openbsd3.\
[0-2\
]*]
97 ||
[istarget i?
86-*-vsta
]
98 ||
[istarget i?
86-*-mach
*]
99 ||
[istarget m68
*-*-netbsd
*]
100 ||
[istarget m68
*-*-openbsd
*]
101 ||
[istarget ns32k
-*-*]
102 ||
[istarget pdp11
-*-*]
103 ||
[istarget sparc
*-*-sunos4
*]
104 ||
[istarget sparc
*-*-netbsd
*]
105 ||
[istarget sparc
*-*-openbsd\
[0-2\
]*]
106 ||
[istarget sparc
*-*-openbsd3.\
[0-1\
]*]
107 ||
[istarget sparc
*-fujitsu
-none]
108 ||
[istarget vax
-dec
-ultrix
*]
109 ||
[istarget vax
-*-netbsd
] } {
115 # True
if the object format is known to be PE COFF.
117 proc is_pecoff_format
{} {
118 if { ![istarget
*-*-mingw
*]
119 && ![istarget
*-*-cygwin
*]
120 && ![istarget
*-*-cegcc
*]
121 && ![istarget
*-*-pe
*] } {
128 # True
if the object format is known to be
64-bit ELF.
130 proc is_elf64
{ binary_file
} {
135 catch
"exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
137 if ![string match
"" $got] then {
141 if { ![regexp
"\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
142 [file_contents readelf.out
] nil readelf_size
] } {
146 if { $readelf_size
== "64" } {
153 # Compare two files line
-by
-line. FILE_1 is the actual output and FILE_2
154 # is the expected output. Ignore
blank lines in either file.
156 # FILE_2 is a series of regexps
, comments and # directives. The directives
160 # Treat the test as a PASS
if everything up till this point has
161 # matched. Ignore
any remaining lines in either FILE_1 or FILE_2.
164 # Reverse the sense of the test
: expect differences to exist.
168 # Skip all lines in FILE_1 until the first that matches REGEXP.
170 # Other # lines are comments. Regexp lines starting with the `
!' character
171 # specify inverse matching (use `\!' for literal matching against a leading
172 # `
!'). Skip empty lines in both files.
174 # The first optional argument is a list of regexp substitutions of the form:
176 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
178 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
179 # in order to every line of FILE_2.
181 # Return nonzero if differences exist.
182 proc regexp_diff { file_1 file_2 args } {
190 if { [llength $args] > 0 } {
191 set ref_subst [lindex $args 0]
193 if { [llength $args] > 1 } {
194 perror "Too many arguments to regexp_diff"
198 if [file exists $file_1] then {
199 set file_a [open $file_1 r]
201 perror "$file_1 doesn't exist
"
205 if [file
exists $file_2
] then {
206 set file_b
[open $file_2 r
]
208 perror
"$file_2 doesn't exist"
213 verbose
" Regexp-diff'ing: $file_1 $file_2" 2
218 while { [string length $line_a
] == 0 } {
219 # Ignore
blank line in FILE_1.
220 if { [gets $file_a line_a
] == $eof
} {
225 while { [string length $line_b
] == 0 ||
[string match
"#*" $line_b] } {
226 if { [string match
"#pass" $line_b] } {
230 } elseif
{ [string match
"#failif" $line_b] } {
231 send_log
"fail if no difference\n"
232 verbose
"fail if no difference" 3
234 } elseif
{ [string match
"#..." $line_b] } {
235 if { [gets $file_b line_b
] == $eof
} {
240 set negated
[expr
{ [string index $line_b
0] eq
"!" }]
241 set line_bx
[string range $line_b $negated end
]
242 set n
[expr
{ $negated ?
"! " : "" }]
243 # Substitute
on the reference.
244 foreach
{name value
} $ref_subst
{
245 regsub
-- $
name $line_bx $value line_bx
247 verbose
"looking for $n\"^$line_bx$\"" 3
248 while { [expr
[regexp
"^$line_bx$" "$line_a"] == $negated] } {
249 verbose
"skipping \"$line_a\"" 3
250 if { [gets $file_a line_a
] == $eof
} {
257 if { [gets $file_b line_b
] == $eof
} {
265 } elseif
{ $end_1
&& $end_2
} {
267 } elseif
{ $end_1
} {
268 send_log
"extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
269 verbose
"extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
272 } elseif
{ $end_2
} {
273 send_log
"extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
274 verbose
"extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
278 set negated
[expr
{ [string index $line_b
0] eq
"!" }]
279 set line_bx
[string range $line_b $negated end
]
280 set n
[expr
{ $negated ?
"! " : "" }]
281 set s
[expr
{ $negated ?
" " : "" }]
282 # Substitute
on the reference.
283 foreach
{name value
} $ref_subst
{
284 regsub
-- $
name $line_bx $value line_bx
286 verbose
"regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
287 if { [expr
[regexp
"^$line_bx$" "$line_a"] == $negated] } {
288 send_log
"regexp_diff match failure\n"
289 send_log
"regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
290 verbose
"regexp_diff match failure\n" 3
296 if { $differences
== 0 && !$diff_pass
&& [eof $file_a
] != [eof $file_b
] } {
297 send_log
"$file_1 and $file_2 are different lengths\n"
298 verbose
"$file_1 and $file_2 are different lengths" 3
302 if { $fail_if_match
} {
303 if { $differences
== 0 } {