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