1 # Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004, 2006, 2007,
2 # 2009, 2010, 2011, 2012 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 *-*-nacl*]
34 && ![istarget frv-*-uclinux*]
35 && ![istarget bfin-*-uclinux]
36 && ![istarget sh*-*-uclinux*]
37 && ![istarget tic6x*-*-uclinux*]
38 && ![istarget *-*-irix5*]
39 && ![istarget *-*-irix6*]
40 && ![istarget *-*-netbsd*]
41 && ![istarget *-*-openbsd*]
42 && ![istarget *-*-solaris2*] } {
46 if { [istarget *-*-linux*aout*]
47 || [istarget *-*-linux*ecoff*]
48 || [istarget *-*-linux*oldld*]
49 || [istarget h8500-*-rtems*]
50 || [istarget i960-*-rtems*]
51 || [istarget *-*-rtemscoff*] } {
55 if { ![istarget *-*-netbsdelf*]
56 && ([istarget *-*-netbsd*aout*]
57 || [istarget *-*-netbsdpe*]
58 || [istarget arm*-*-netbsd*]
59 || [istarget sparc-*-netbsd*]
60 || [istarget i*86-*-netbsd*]
61 || [istarget m68*-*-netbsd*]
62 || [istarget vax-*-netbsd*]
63 || [istarget ns32k-*-netbsd*]) } {
67 if { [istarget arm-*-openbsd*]
68 || [istarget i386-*-openbsd\[0-2\].*]
69 || [istarget i386-*-openbsd3.\[0-2\]]
70 || [istarget m68*-*-openbsd*]
71 || [istarget ns32k-*-openbsd*]
72 || [istarget sparc-*-openbsd\[0-2\].*]
73 || [istarget sparc-*-openbsd3.\[0-1\]]
74 || [istarget vax-*-openbsd*] } {
81 # True if the object format is known to be a.out.
83 proc is_aout_format {} {
84 if { [istarget *-*-netbsdelf]
85 || [istarget sparc64-*-netbsd*]
86 || [istarget sparc64-*-openbsd*] } {
89 if { [istarget *-*-*\[ab\]out*]
90 || [istarget *-*-linux*oldld*]
91 || [istarget *-*-bsd*]
92 || [istarget *-*-msdos*]
93 || [istarget arm-*-netbsd*]
94 || [istarget arm-*-openbsd*]
95 || [istarget arm-*-riscix*]
96 || [istarget i?86-*-freebsd\[12\]*]
97 || [istarget i?86-*-netbsd*]
98 || [istarget i?86-*-openbsd\[0-2\]*]
99 || [istarget i?86-*-openbsd3.\[0-2\]*]
100 || [istarget i?86-*-vsta]
101 || [istarget i?86-*-mach*]
102 || [istarget m68*-*-netbsd*]
103 || [istarget m68*-*-openbsd*]
104 || [istarget ns32k-*-*]
105 || [istarget pdp11-*-*]
106 || [istarget sparc*-*-sunos4*]
107 || [istarget sparc*-*-netbsd*]
108 || [istarget sparc*-*-openbsd\[0-2\]*]
109 || [istarget sparc*-*-openbsd3.\[0-1\]*]
110 || [istarget sparc*-fujitsu-none]
111 || [istarget vax-dec-ultrix*]
112 || [istarget vax-*-netbsd] } {
118 # True if the object format is known to be PE COFF.
120 proc is_pecoff_format {} {
121 if { ![istarget *-*-mingw*]
122 && ![istarget *-*-cygwin*]
123 && ![istarget *-*-cegcc*]
124 && ![istarget *-*-pe*] } {
131 # True if the object format is known to be 64-bit ELF.
133 proc is_elf64 { binary_file } {
138 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
140 if ![string match "" $got] then {
144 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
145 [file_contents readelf.out] nil readelf_size] } {
149 if { $readelf_size == "64" } {
156 # True if the build supports zlib compression.
157 proc is_zlib_supported {} {
159 # This replicates the AS selection logic of dejagnu's target_assemble.
161 if [info exists AS_FOR_TARGET] {
162 set AS $AS_FOR_TARGET
164 if {![board_info target exists assembler]} {
167 set AS [board_info target assembler]
171 set as_output [remote_exec host "$AS --help"]
174 if {[string first "--compress-debug-sections" $as_output] >= 0} {
181 # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
182 # is the expected output. Ignore blank lines in either file.
184 # FILE_2 is a series of regexps, comments and # directives. The directives
188 # Treat the test as a PASS if everything up till this point has
189 # matched. Ignore any remaining lines in either FILE_1 or FILE_2.
192 # Reverse the sense of the test: expect differences to exist.
196 # Skip all lines in FILE_1 until the first that matches REGEXP.
198 # Other # lines are comments. Regexp lines starting with the `!' character
199 # specify inverse matching (use `\!' for literal matching against a leading
200 # `!'). Skip empty lines in both files.
202 # The first optional argument is a list of regexp substitutions of the form:
204 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
206 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
207 # in order to every line of FILE_2.
209 # Return nonzero if differences exist.
210 proc regexp_diff { file_1 file_2 args } {
218 if { [llength $args] > 0 } {
219 set ref_subst [lindex $args 0]
221 if { [llength $args] > 1 } {
222 perror "Too many arguments to regexp_diff"
226 if [file exists $file_1] then {
227 set file_a [open $file_1 r]
229 perror "$file_1 doesn't exist"
233 if [file exists $file_2] then {
234 set file_b [open $file_2 r]
236 perror "$file_2 doesn't exist"
241 verbose " Regexp-diff'ing: $file_1 $file_2" 2
246 while { [string length $line_a] == 0 } {
247 # Ignore blank line in FILE_1.
248 if { [gets $file_a line_a] == $eof } {
253 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
254 if { [string match "#pass" $line_b] } {
258 } elseif { [string match "#failif" $line_b] } {
259 send_log "fail if no difference\n"
260 verbose "fail if no difference" 3
262 } elseif { [string match "#..." $line_b] } {
263 if { [gets $file_b line_b] == $eof } {
268 set negated [expr { [string index $line_b 0] == "!" }]
269 set line_bx [string range $line_b $negated end]
270 set n [expr { $negated ? "! " : "" }]
271 # Substitute on the reference.
272 foreach {name value} $ref_subst {
273 regsub -- $name $line_bx $value line_bx
275 verbose "looking for $n\"^$line_bx$\"" 3
276 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
277 verbose "skipping \"$line_a\"" 3
278 if { [gets $file_a line_a] == $eof } {
285 if { [gets $file_b line_b] == $eof } {
293 } elseif { $end_1 && $end_2 } {
295 } elseif { $end_1 } {
296 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
297 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
300 } elseif { $end_2 } {
301 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
302 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
306 set negated [expr { [string index $line_b 0] == "!" }]
307 set line_bx [string range $line_b $negated end]
308 set n [expr { $negated ? "! " : "" }]
309 set s [expr { $negated ? " " : "" }]
310 # Substitute on the reference.
311 foreach {name value} $ref_subst {
312 regsub -- $name $line_bx $value line_bx
314 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
315 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
316 send_log "regexp_diff match failure\n"
317 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
318 verbose "regexp_diff match failure\n" 3
324 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
325 send_log "$file_1 and $file_2 are different lengths\n"
326 verbose "$file_1 and $file_2 are different lengths" 3
330 if { $fail_if_match } {
331 if { $differences == 0 } {