]>
Commit | Line | Data |
---|---|---|
6f2750fe | 1 | # Copyright (C) 1993-2016 Free Software Foundation, Inc. |
f3097f33 RS |
2 | # |
3 | # This file is part of the GNU Binutils. | |
4 | # | |
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. | |
9 | # | |
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. | |
14 | # | |
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, | |
18 | # MA 02110-1301, USA. | |
19 | ||
20 | # True if the object format is known to be ELF. | |
21 | # | |
22 | proc is_elf_format {} { | |
b3066ae8 AM |
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-*] } { | |
27 | return 1; | |
28 | } | |
29 | ||
4a85cc09 | 30 | if { ![istarget *-*-eabi*] |
f3097f33 | 31 | && ![istarget *-*-elf*] |
4a85cc09 | 32 | && ![istarget *-*-freebsd*] |
f3097f33 | 33 | && ![istarget *-*-gnu*] |
f3097f33 RS |
34 | && ![istarget *-*-irix5*] |
35 | && ![istarget *-*-irix6*] | |
4a85cc09 SKS |
36 | && ![istarget *-*-linux*] |
37 | && ![istarget *-*-nacl*] | |
f3097f33 RS |
38 | && ![istarget *-*-netbsd*] |
39 | && ![istarget *-*-openbsd*] | |
4a85cc09 SKS |
40 | && ![istarget *-*-rtems*] |
41 | && ![istarget *-*-solaris2*] | |
42 | && ![istarget *-*-sysv4*] | |
43 | && ![istarget *-*-unixware*] | |
44 | && ![istarget avr-*-*] | |
45 | && ![istarget bfin-*-uclinux] | |
46 | && ![istarget frv-*-uclinux*] | |
47 | && ![istarget hppa*64*-*-hpux*] | |
48 | && ![istarget ia64-*-hpux*] | |
49 | && ![istarget sh*-*-uclinux*] | |
50 | && ![istarget tic6x*-*-uclinux*] } { | |
f3097f33 RS |
51 | return 0 |
52 | } | |
53 | ||
4a85cc09 | 54 | if { [istarget *-*-linux*aout*] |
df26367c | 55 | || [istarget *-*-linux*ecoff*] |
f3097f33 | 56 | || [istarget *-*-linux*oldld*] |
4a85cc09 | 57 | || [istarget *-*-rtemscoff*] |
f3097f33 | 58 | || [istarget h8500-*-rtems*] |
4a85cc09 SKS |
59 | || [istarget i?86-*-freebsd\[12\].*] |
60 | || [istarget i960-*-rtems*] } { | |
f3097f33 RS |
61 | return 0 |
62 | } | |
63 | ||
64 | if { ![istarget *-*-netbsdelf*] | |
4a85cc09 | 65 | && ( [istarget *-*-netbsd*aout*] |
f3097f33 RS |
66 | || [istarget *-*-netbsdpe*] |
67 | || [istarget arm*-*-netbsd*] | |
68 | || [istarget sparc-*-netbsd*] | |
69 | || [istarget i*86-*-netbsd*] | |
70 | || [istarget m68*-*-netbsd*] | |
71 | || [istarget vax-*-netbsd*] | |
72 | || [istarget ns32k-*-netbsd*]) } { | |
73 | return 0 | |
74 | } | |
75 | ||
4a85cc09 | 76 | if { [istarget arm-*-openbsd*] |
f3097f33 RS |
77 | || [istarget i386-*-openbsd\[0-2\].*] |
78 | || [istarget i386-*-openbsd3.\[0-2\]] | |
79 | || [istarget m68*-*-openbsd*] | |
80 | || [istarget ns32k-*-openbsd*] | |
81 | || [istarget sparc-*-openbsd\[0-2\].*] | |
82 | || [istarget sparc-*-openbsd3.\[0-1\]] | |
83 | || [istarget vax-*-openbsd*] } { | |
84 | return 0 | |
85 | } | |
86 | ||
87 | return 1 | |
88 | } | |
89 | ||
90 | # True if the object format is known to be a.out. | |
91 | # | |
92 | proc is_aout_format {} { | |
93 | if { [istarget *-*-netbsdelf] | |
94 | || [istarget sparc64-*-netbsd*] | |
95 | || [istarget sparc64-*-openbsd*] } { | |
96 | return 0 | |
97 | } | |
98 | if { [istarget *-*-*\[ab\]out*] | |
99 | || [istarget *-*-linux*oldld*] | |
100 | || [istarget *-*-bsd*] | |
101 | || [istarget *-*-msdos*] | |
102 | || [istarget arm-*-netbsd*] | |
103 | || [istarget arm-*-openbsd*] | |
104 | || [istarget arm-*-riscix*] | |
7e16ef34 | 105 | || [istarget i?86-*-freebsd\[12\].*] |
f3097f33 RS |
106 | || [istarget i?86-*-netbsd*] |
107 | || [istarget i?86-*-openbsd\[0-2\]*] | |
108 | || [istarget i?86-*-openbsd3.\[0-2\]*] | |
109 | || [istarget i?86-*-vsta] | |
110 | || [istarget i?86-*-mach*] | |
111 | || [istarget m68*-*-netbsd*] | |
112 | || [istarget m68*-*-openbsd*] | |
113 | || [istarget ns32k-*-*] | |
114 | || [istarget pdp11-*-*] | |
115 | || [istarget sparc*-*-sunos4*] | |
116 | || [istarget sparc*-*-netbsd*] | |
117 | || [istarget sparc*-*-openbsd\[0-2\]*] | |
118 | || [istarget sparc*-*-openbsd3.\[0-1\]*] | |
119 | || [istarget sparc*-fujitsu-none] | |
120 | || [istarget vax-dec-ultrix*] | |
121 | || [istarget vax-*-netbsd] } { | |
122 | return 1 | |
123 | } | |
124 | return 0 | |
125 | } | |
126 | ||
127 | # True if the object format is known to be PE COFF. | |
128 | # | |
129 | proc is_pecoff_format {} { | |
130 | if { ![istarget *-*-mingw*] | |
131 | && ![istarget *-*-cygwin*] | |
132 | && ![istarget *-*-cegcc*] | |
133 | && ![istarget *-*-pe*] } { | |
134 | return 0 | |
135 | } | |
136 | ||
137 | return 1 | |
138 | } | |
139 | ||
140 | # True if the object format is known to be 64-bit ELF. | |
141 | # | |
142 | proc is_elf64 { binary_file } { | |
143 | global READELF | |
144 | global READELFFLAGS | |
145 | ||
146 | set readelf_size "" | |
147 | catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got | |
148 | ||
149 | if ![string match "" $got] then { | |
150 | return 0 | |
151 | } | |
152 | ||
153 | if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \ | |
154 | [file_contents readelf.out] nil readelf_size] } { | |
155 | return 0 | |
156 | } | |
157 | ||
158 | if { $readelf_size == "64" } { | |
159 | return 1 | |
160 | } | |
161 | ||
162 | return 0 | |
163 | } | |
eb22018c | 164 | |
a43942db MR |
165 | # True if the ELF target supports STB_GNU_UNIQUE with the ELF header's |
166 | # OSABI field set to ELFOSABI_GNU. | |
167 | # | |
168 | # This generally depends on the target OS only, however there are a | |
169 | # number of exceptions for bare metal targets as follows. The MSP430 | |
170 | # and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot | |
171 | # support STB_GNU_UNIQUE. Likewise non-EABI ARM targets set OSABI to | |
172 | # ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*. Finally | |
173 | # rather than `bfd_elf_final_link' AM33/2.0, D30V, DLX, i960, and | |
174 | # picoJava targets use `_bfd_generic_final_link', which does not | |
175 | # support STB_GNU_UNIQUE symbol binding causing assertion failures. | |
176 | # | |
177 | proc supports_gnu_unique {} { | |
178 | if { [istarget *-*-gnu*] | |
179 | || [istarget *-*-linux*] | |
180 | || [istarget *-*-nacl*] } { | |
181 | return 1 | |
182 | } | |
183 | if { [istarget "arm*-*-*eabi*"] } { | |
184 | return 1 | |
185 | } | |
186 | if { ![istarget "*-*-elf*"] } { | |
187 | return 0 | |
188 | } | |
189 | if { [istarget "arm*-*-*"] | |
190 | || [istarget "msp430-*-*"] | |
191 | || [istarget "tic6x-*-*"] | |
192 | || [istarget "visium-*-*"] } { | |
193 | return 0 | |
194 | } | |
195 | if { [istarget "am33_2.0-*-*"] | |
196 | || [istarget "d30v-*-*"] | |
197 | || [istarget "dlx-*-*"] | |
198 | || [istarget "i960-*-*"] | |
199 | || [istarget "pj*-*-*"] } { | |
200 | return 0 | |
201 | } | |
202 | return 1 | |
203 | } | |
204 | ||
eb22018c RS |
205 | # Compare two files line-by-line. FILE_1 is the actual output and FILE_2 |
206 | # is the expected output. Ignore blank lines in either file. | |
207 | # | |
208 | # FILE_2 is a series of regexps, comments and # directives. The directives | |
209 | # are: | |
210 | # | |
211 | # #pass | |
212 | # Treat the test as a PASS if everything up till this point has | |
213 | # matched. Ignore any remaining lines in either FILE_1 or FILE_2. | |
214 | # | |
215 | # #failif | |
216 | # Reverse the sense of the test: expect differences to exist. | |
217 | # | |
218 | # #... | |
219 | # REGEXP | |
220 | # Skip all lines in FILE_1 until the first that matches REGEXP. | |
221 | # | |
738f4d98 MR |
222 | # Other # lines are comments. Regexp lines starting with the `!' character |
223 | # specify inverse matching (use `\!' for literal matching against a leading | |
224 | # `!'). Skip empty lines in both files. | |
eb22018c RS |
225 | # |
226 | # The first optional argument is a list of regexp substitutions of the form: | |
227 | # | |
228 | # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ... | |
229 | # | |
230 | # This tells the function to apply each regexp substitution EXPi->SUBSPECi | |
231 | # in order to every line of FILE_2. | |
232 | # | |
233 | # Return nonzero if differences exist. | |
234 | proc regexp_diff { file_1 file_2 args } { | |
235 | set eof -1 | |
236 | set end_1 0 | |
237 | set end_2 0 | |
238 | set differences 0 | |
239 | set diff_pass 0 | |
240 | set fail_if_match 0 | |
241 | set ref_subst "" | |
242 | if { [llength $args] > 0 } { | |
243 | set ref_subst [lindex $args 0] | |
244 | } | |
245 | if { [llength $args] > 1 } { | |
246 | perror "Too many arguments to regexp_diff" | |
247 | return 1 | |
248 | } | |
249 | ||
250 | if [file exists $file_1] then { | |
251 | set file_a [open $file_1 r] | |
252 | } else { | |
253 | perror "$file_1 doesn't exist" | |
254 | return 1 | |
255 | } | |
256 | ||
257 | if [file exists $file_2] then { | |
258 | set file_b [open $file_2 r] | |
259 | } else { | |
260 | perror "$file_2 doesn't exist" | |
261 | close $file_a | |
262 | return 1 | |
263 | } | |
264 | ||
265 | verbose " Regexp-diff'ing: $file_1 $file_2" 2 | |
266 | ||
267 | while { 1 } { | |
268 | set line_a "" | |
269 | set line_b "" | |
270 | while { [string length $line_a] == 0 } { | |
271 | # Ignore blank line in FILE_1. | |
272 | if { [gets $file_a line_a] == $eof } { | |
273 | set end_1 1 | |
274 | break | |
275 | } | |
276 | } | |
277 | while { [string length $line_b] == 0 || [string match "#*" $line_b] } { | |
278 | if { [string match "#pass" $line_b] } { | |
279 | set end_2 1 | |
280 | set diff_pass 1 | |
281 | break | |
282 | } elseif { [string match "#failif" $line_b] } { | |
283 | send_log "fail if no difference\n" | |
284 | verbose "fail if no difference" 3 | |
285 | set fail_if_match 1 | |
286 | } elseif { [string match "#..." $line_b] } { | |
287 | if { [gets $file_b line_b] == $eof } { | |
288 | set end_2 1 | |
289 | set diff_pass 1 | |
290 | break | |
291 | } | |
47a50e5b | 292 | set negated [expr { [string index $line_b 0] == "!" }] |
738f4d98 MR |
293 | set line_bx [string range $line_b $negated end] |
294 | set n [expr { $negated ? "! " : "" }] | |
eb22018c RS |
295 | # Substitute on the reference. |
296 | foreach {name value} $ref_subst { | |
738f4d98 | 297 | regsub -- $name $line_bx $value line_bx |
eb22018c | 298 | } |
738f4d98 MR |
299 | verbose "looking for $n\"^$line_bx$\"" 3 |
300 | while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } { | |
eb22018c RS |
301 | verbose "skipping \"$line_a\"" 3 |
302 | if { [gets $file_a line_a] == $eof } { | |
303 | set end_1 1 | |
304 | break | |
305 | } | |
306 | } | |
307 | break | |
308 | } | |
309 | if { [gets $file_b line_b] == $eof } { | |
310 | set end_2 1 | |
311 | break | |
312 | } | |
313 | } | |
314 | ||
315 | if { $diff_pass } { | |
316 | break | |
317 | } elseif { $end_1 && $end_2 } { | |
318 | break | |
319 | } elseif { $end_1 } { | |
320 | send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n" | |
321 | verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3 | |
322 | set differences 1 | |
323 | break | |
324 | } elseif { $end_2 } { | |
325 | send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" | |
326 | verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3 | |
327 | set differences 1 | |
328 | break | |
329 | } else { | |
47a50e5b | 330 | set negated [expr { [string index $line_b 0] == "!" }] |
738f4d98 MR |
331 | set line_bx [string range $line_b $negated end] |
332 | set n [expr { $negated ? "! " : "" }] | |
333 | set s [expr { $negated ? " " : "" }] | |
eb22018c RS |
334 | # Substitute on the reference. |
335 | foreach {name value} $ref_subst { | |
738f4d98 | 336 | regsub -- $name $line_bx $value line_bx |
eb22018c | 337 | } |
738f4d98 MR |
338 | verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3 |
339 | if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } { | |
eb22018c | 340 | send_log "regexp_diff match failure\n" |
738f4d98 | 341 | send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n" |
eb22018c RS |
342 | verbose "regexp_diff match failure\n" 3 |
343 | set differences 1 | |
344 | } | |
345 | } | |
346 | } | |
347 | ||
348 | if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } { | |
349 | send_log "$file_1 and $file_2 are different lengths\n" | |
350 | verbose "$file_1 and $file_2 are different lengths" 3 | |
351 | set differences 1 | |
352 | } | |
353 | ||
354 | if { $fail_if_match } { | |
355 | if { $differences == 0 } { | |
356 | set differences 1 | |
357 | } else { | |
358 | set differences 0 | |
359 | } | |
360 | } | |
361 | ||
362 | close $file_a | |
363 | close $file_b | |
364 | ||
365 | return $differences | |
366 | } |