Commit | Line | Data |
---|---|---|
b3adc24a | 1 | # Copyright (C) 1993-2020 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 {} { | |
5b537ffc AM |
98 | if { [istarget *-*-beospe*] |
99 | || [istarget *-*-cegcc*] | |
100 | || [istarget *-*-cygwin*] | |
101 | || [istarget *-*-interix*] | |
102 | || [istarget *-*-mingw*] | |
103 | || [istarget *-*-netbsdpe*] | |
104 | || [istarget *-*-pe*] | |
105 | || [istarget *-*-winnt*] } { | |
106 | return 1 | |
f3097f33 | 107 | } |
5b537ffc | 108 | return 0 |
f3097f33 RS |
109 | } |
110 | ||
0b1352e0 AM |
111 | proc is_som_format {} { |
112 | if { ![istarget hppa*-*-*] || [istarget hppa*64*-*-*] } { | |
113 | return 0; | |
114 | } | |
115 | if { [istarget *-*-osf*] \ | |
116 | || [istarget {*-*-h[ip]ux*}] \ | |
117 | || [istarget *-*-mpeix*] \ | |
118 | || [istarget *-*-bsd*] } { | |
119 | return 1; | |
120 | } | |
121 | return 0; | |
122 | } | |
123 | ||
f3097f33 RS |
124 | # True if the object format is known to be 64-bit ELF. |
125 | # | |
126 | proc is_elf64 { binary_file } { | |
127 | global READELF | |
128 | global READELFFLAGS | |
129 | ||
506b86a4 | 130 | set tmpfile [file dirname $binary_file]/readelf.out |
f3097f33 | 131 | set readelf_size "" |
506b86a4 | 132 | catch "exec $READELF $READELFFLAGS -h $binary_file > $tmpfile" got |
f3097f33 RS |
133 | |
134 | if ![string match "" $got] then { | |
135 | return 0 | |
136 | } | |
137 | ||
138 | if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \ | |
506b86a4 | 139 | [file_contents $tmpfile] nil readelf_size] } { |
f3097f33 RS |
140 | return 0 |
141 | } | |
142 | ||
143 | if { $readelf_size == "64" } { | |
144 | return 1 | |
145 | } | |
146 | ||
147 | return 0 | |
148 | } | |
eb22018c | 149 | |
506b86a4 AM |
150 | # True if the object format is known to use RELA relocations. |
151 | # | |
152 | proc is_rela { binary_file } { | |
153 | global READELF | |
154 | global READELFFLAGS | |
155 | ||
156 | set tmpfile [file dirname $binary_file]/readelf.out | |
157 | catch "exec $READELF $READELFFLAGS -S $binary_file > $tmpfile" got | |
158 | ||
159 | if ![string match "" $got] then { | |
160 | return 0 | |
161 | } | |
162 | ||
163 | if { ![regexp "RELA" [file_contents $tmpfile]] } { | |
164 | return 0 | |
165 | } | |
166 | ||
167 | return 1 | |
168 | } | |
169 | ||
6d9dabbb MR |
170 | # True if the target matches TARGET, specified as a TCL procedure if |
171 | # in square brackets or as machine triplet otherwise. | |
172 | # | |
173 | proc match_target { target } { | |
02e0be69 | 174 | if [regexp {^!?\[.*\]$} $target] { |
6d9dabbb MR |
175 | return $target |
176 | } else { | |
177 | return [istarget $target] | |
178 | } | |
179 | } | |
180 | ||
02e0be69 AM |
181 | # True if the ELF target supports setting the ELF header OSABI field |
182 | # to ELFOSABI_GNU or ELFOSABI_FREEBSD, a requirement for STT_GNU_IFUNC | |
183 | # symbol and SHF_GNU_MBIND section support. | |
a43942db MR |
184 | # |
185 | # This generally depends on the target OS only, however there are a | |
186 | # number of exceptions for bare metal targets as follows. The MSP430 | |
02e0be69 AM |
187 | # and Visium targets set OSABI to ELFOSABI_STANDALONE. Likewise |
188 | # non-EABI ARM targets set OSABI to ELFOSABI_ARM | |
a43942db | 189 | # |
02e0be69 AM |
190 | # Note that some TI C6X targets use ELFOSABI_C6000_* but one doesn't, |
191 | # so we don't try to sort out tic6x here. (The effect is that linker | |
192 | # testcases will generally need to exclude tic6x or use a -m option.) | |
193 | # | |
194 | proc supports_gnu_osabi {} { | |
a43942db MR |
195 | if { [istarget *-*-gnu*] |
196 | || [istarget *-*-linux*] | |
02e0be69 AM |
197 | || [istarget *-*-nacl*] |
198 | || ( [istarget *-*-*bsd*] && ![istarget arm*-*-netbsd*] ) | |
199 | || [istarget *-*-symbianelf] | |
200 | || [istarget *-*-lynxos] | |
201 | || ( [istarget *-*-nto*] && ![istarget arm*-*-*] ) | |
202 | || [istarget *-*-irix*] | |
203 | || [istarget *-*-*eabi*] | |
204 | || [istarget *-*-rtems*] | |
205 | || [istarget *-*-solaris*] } { | |
a43942db MR |
206 | return 1 |
207 | } | |
f96bd6c2 PC |
208 | if { [istarget "wasm32*-*-*"] } { |
209 | return 1 | |
210 | } | |
a43942db MR |
211 | if { ![istarget "*-*-elf*"] } { |
212 | return 0 | |
213 | } | |
214 | if { [istarget "arm*-*-*"] | |
215 | || [istarget "msp430-*-*"] | |
a43942db MR |
216 | || [istarget "visium-*-*"] } { |
217 | return 0 | |
218 | } | |
02e0be69 AM |
219 | return 1 |
220 | } | |
221 | ||
222 | # Return true if target uses the generic_link_hash_table linker. | |
223 | proc is_generic { } { | |
224 | if { [istarget "d30v-*-*"] | |
a43942db | 225 | || [istarget "dlx-*-*"] |
be570f06 | 226 | || [istarget "pj*-*-*"] |
6ff185b8 | 227 | || [istarget "s12z-*-*"] |
be570f06 | 228 | || [istarget "xgate-*-*"] } { |
02e0be69 AM |
229 | return 1 |
230 | } | |
231 | return 0 | |
232 | } | |
233 | ||
234 | # True if the ELF target supports STB_GNU_UNIQUE. | |
235 | # | |
236 | # This require ELFOSABI_GNU, and `bfd_elf_final_link'. | |
237 | # | |
238 | proc supports_gnu_unique {} { | |
239 | if { [istarget *-*-freebsd*] } { | |
a43942db MR |
240 | return 0 |
241 | } | |
02e0be69 AM |
242 | if { [supports_gnu_osabi] && ![is_generic] } { |
243 | return 1 | |
244 | } | |
245 | return 0 | |
a43942db MR |
246 | } |
247 | ||
9cc0123f AM |
248 | # True for targets that do not sort .symtab as per the ELF standard. |
249 | # ie. any that have mips_elf32_be_vec, mips_elf32_le_vec, | |
250 | # mips_elf32_n_be_vec or mips_elf32_n_le_vec as the primary bfd target | |
251 | # vector in config.bfd. When syncing with config.bfd, don't forget that | |
252 | # earlier case-matches trump later ones. | |
253 | proc is_bad_symtab {} { | |
254 | if { ![istarget "mips*-*-*"] } { | |
255 | return 0; | |
256 | } | |
257 | if { [istarget "*-*-chorus*"] | |
258 | || [istarget "*-*-irix5*"] | |
259 | || [istarget "*-*-irix6*"] | |
260 | || [istarget "*-*-none"] | |
261 | || [istarget "*-*-rtems*"] | |
262 | || [istarget "*-*-windiss"] } { | |
263 | return 1; | |
264 | } | |
265 | if { [istarget "*-*-elf*"] | |
266 | && ![istarget "*-sde-*"] | |
267 | && ![istarget "*-mti-*"] | |
268 | && ![istarget "*-img-*"] } { | |
269 | return 1; | |
270 | } | |
271 | if { [istarget "*-*-openbsd*"] | |
272 | && ![istarget "mips64*-*-*"] } { | |
273 | return 1; | |
274 | } | |
275 | return 0; | |
276 | } | |
277 | ||
33ea299c TP |
278 | # Returns true if -shared is supported on the target |
279 | ||
280 | proc check_shared_lib_support { } { | |
281 | global shared_available_saved | |
282 | global ld | |
283 | ||
284 | if {![info exists shared_available_saved]} { | |
285 | set ld_output [remote_exec host $ld "-shared"] | |
286 | if { [ string first "not supported" $ld_output ] >= 0 } { | |
287 | set shared_available_saved 0 | |
288 | } else { | |
289 | set shared_available_saved 1 | |
290 | } | |
291 | } | |
292 | return $shared_available_saved | |
293 | } | |
294 | ||
eb22018c RS |
295 | # Compare two files line-by-line. FILE_1 is the actual output and FILE_2 |
296 | # is the expected output. Ignore blank lines in either file. | |
297 | # | |
298 | # FILE_2 is a series of regexps, comments and # directives. The directives | |
299 | # are: | |
300 | # | |
301 | # #pass | |
302 | # Treat the test as a PASS if everything up till this point has | |
303 | # matched. Ignore any remaining lines in either FILE_1 or FILE_2. | |
304 | # | |
305 | # #failif | |
306 | # Reverse the sense of the test: expect differences to exist. | |
307 | # | |
308 | # #... | |
309 | # REGEXP | |
310 | # Skip all lines in FILE_1 until the first that matches REGEXP. | |
311 | # | |
bc754168 AM |
312 | # #?REGEXP |
313 | # Optionally match REGEXP against line from FILE_1. If the REGEXP | |
314 | # does not match then the next line from FILE_2 is tried. | |
315 | # | |
738f4d98 MR |
316 | # Other # lines are comments. Regexp lines starting with the `!' character |
317 | # specify inverse matching (use `\!' for literal matching against a leading | |
318 | # `!'). Skip empty lines in both files. | |
eb22018c RS |
319 | # |
320 | # The first optional argument is a list of regexp substitutions of the form: | |
321 | # | |
322 | # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ... | |
323 | # | |
324 | # This tells the function to apply each regexp substitution EXPi->SUBSPECi | |
325 | # in order to every line of FILE_2. | |
326 | # | |
327 | # Return nonzero if differences exist. | |
328 | proc regexp_diff { file_1 file_2 args } { | |
329 | set eof -1 | |
330 | set end_1 0 | |
331 | set end_2 0 | |
332 | set differences 0 | |
333 | set diff_pass 0 | |
334 | set fail_if_match 0 | |
335 | set ref_subst "" | |
336 | if { [llength $args] > 0 } { | |
337 | set ref_subst [lindex $args 0] | |
338 | } | |
339 | if { [llength $args] > 1 } { | |
340 | perror "Too many arguments to regexp_diff" | |
341 | return 1 | |
342 | } | |
343 | ||
344 | if [file exists $file_1] then { | |
345 | set file_a [open $file_1 r] | |
346 | } else { | |
347 | perror "$file_1 doesn't exist" | |
348 | return 1 | |
349 | } | |
350 | ||
351 | if [file exists $file_2] then { | |
352 | set file_b [open $file_2 r] | |
353 | } else { | |
354 | perror "$file_2 doesn't exist" | |
355 | close $file_a | |
356 | return 1 | |
357 | } | |
358 | ||
359 | verbose " Regexp-diff'ing: $file_1 $file_2" 2 | |
360 | ||
361 | while { 1 } { | |
362 | set line_a "" | |
363 | set line_b "" | |
364 | while { [string length $line_a] == 0 } { | |
365 | # Ignore blank line in FILE_1. | |
366 | if { [gets $file_a line_a] == $eof } { | |
367 | set end_1 1 | |
368 | break | |
369 | } | |
370 | } | |
371 | while { [string length $line_b] == 0 || [string match "#*" $line_b] } { | |
372 | if { [string match "#pass" $line_b] } { | |
373 | set end_2 1 | |
374 | set diff_pass 1 | |
375 | break | |
376 | } elseif { [string match "#failif" $line_b] } { | |
377 | send_log "fail if no difference\n" | |
378 | verbose "fail if no difference" 3 | |
379 | set fail_if_match 1 | |
380 | } elseif { [string match "#..." $line_b] } { | |
381 | if { [gets $file_b line_b] == $eof } { | |
382 | set end_2 1 | |
383 | set diff_pass 1 | |
384 | break | |
385 | } | |
47a50e5b | 386 | set negated [expr { [string index $line_b 0] == "!" }] |
738f4d98 MR |
387 | set line_bx [string range $line_b $negated end] |
388 | set n [expr { $negated ? "! " : "" }] | |
eb22018c RS |
389 | # Substitute on the reference. |
390 | foreach {name value} $ref_subst { | |
738f4d98 | 391 | regsub -- $name $line_bx $value line_bx |
eb22018c | 392 | } |
738f4d98 MR |
393 | verbose "looking for $n\"^$line_bx$\"" 3 |
394 | while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } { | |
eb22018c RS |
395 | verbose "skipping \"$line_a\"" 3 |
396 | if { [gets $file_a line_a] == $eof } { | |
397 | set end_1 1 | |
398 | break | |
399 | } | |
400 | } | |
401 | break | |
bc754168 AM |
402 | } elseif { [string match "#\\?*" $line_b] } { |
403 | if { ! $end_1 } { | |
404 | set line_b [string replace $line_b 0 1] | |
405 | set negated [expr { [string index $line_b 0] == "!" }] | |
406 | set line_bx [string range $line_b $negated end] | |
407 | set n [expr { $negated ? "! " : "" }] | |
408 | # Substitute on the reference. | |
409 | foreach {name value} $ref_subst { | |
410 | regsub -- $name $line_bx $value line_bx | |
411 | } | |
412 | verbose "optional match for $n\"^$line_bx$\"" 3 | |
413 | if { [expr [regexp "^$line_bx$" "$line_a"] != $negated] } { | |
414 | break | |
415 | } | |
416 | } | |
eb22018c RS |
417 | } |
418 | if { [gets $file_b line_b] == $eof } { | |
419 | set end_2 1 | |
420 | break | |
421 | } | |
422 | } | |
423 | ||
424 | if { $diff_pass } { | |
425 | break | |
426 | } elseif { $end_1 && $end_2 } { | |
427 | break | |
428 | } elseif { $end_1 } { | |
429 | send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n" | |
430 | verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3 | |
431 | set differences 1 | |
432 | break | |
433 | } elseif { $end_2 } { | |
434 | send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" | |
435 | verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3 | |
436 | set differences 1 | |
437 | break | |
438 | } else { | |
47a50e5b | 439 | set negated [expr { [string index $line_b 0] == "!" }] |
738f4d98 MR |
440 | set line_bx [string range $line_b $negated end] |
441 | set n [expr { $negated ? "! " : "" }] | |
442 | set s [expr { $negated ? " " : "" }] | |
eb22018c RS |
443 | # Substitute on the reference. |
444 | foreach {name value} $ref_subst { | |
738f4d98 | 445 | regsub -- $name $line_bx $value line_bx |
eb22018c | 446 | } |
738f4d98 MR |
447 | verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3 |
448 | if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } { | |
eb22018c | 449 | send_log "regexp_diff match failure\n" |
738f4d98 | 450 | send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n" |
eb22018c RS |
451 | verbose "regexp_diff match failure\n" 3 |
452 | set differences 1 | |
453 | } | |
454 | } | |
455 | } | |
456 | ||
457 | if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } { | |
458 | send_log "$file_1 and $file_2 are different lengths\n" | |
459 | verbose "$file_1 and $file_2 are different lengths" 3 | |
460 | set differences 1 | |
461 | } | |
462 | ||
463 | if { $fail_if_match } { | |
464 | if { $differences == 0 } { | |
465 | set differences 1 | |
466 | } else { | |
467 | set differences 0 | |
468 | } | |
469 | } | |
470 | ||
471 | close $file_a | |
472 | close $file_b | |
473 | ||
474 | return $differences | |
475 | } | |
7dd36a6f L |
476 | |
477 | # prune_warnings_extra -- delete extra warnings from TEXT. | |
478 | # | |
479 | # An example is: | |
480 | # ld: warning: /lib64/ld-linux-x86-64.so.2: unsupported GNU_PROPERTY_TYPE (5) type : 0xc0010001 | |
481 | proc prune_warnings_extra { text } { | |
482 | global experimental | |
483 | # Warnings are only pruned from non-experimental code (ie code not | |
484 | # on a release branch). For experimental code we want the warnings | |
485 | # as they indicate that the sources need to be updated to recognise | |
486 | # the new properties. | |
487 | if { "$experimental" == "false" } { | |
488 | # The "\\1" is to try to preserve a "\n" but only if necessary. | |
489 | regsub -all "(^|\n)(\[^\n\]*: warning:\[^\n\]*unsupported GNU_PROPERTY_TYPE\[^\n\]*\n?)+" $text "\\1" text | |
490 | } | |
f92f9e87 L |
491 | # PR binutils/23898: It is OK to have gaps in build notes. |
492 | regsub -all "(^|\n)(\[^\n\]*: Warning: Gap in build notes detected from\[^\n\]*\n?)+" $text "\\1" text | |
7dd36a6f L |
493 | return $text |
494 | } | |
495 | ||
496 | # This definition is taken from an unreleased version of DejaGnu. Once | |
497 | # that version gets released, and has been out in the world for a few | |
498 | # months at least, it may be safe to delete this copy. | |
499 | if ![string length [info proc prune_warnings]] { | |
500 | # | |
501 | # prune_warnings -- delete various system verbosities from TEXT | |
502 | # | |
503 | # An example is: | |
504 | # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9 | |
505 | # | |
506 | # Sites with particular verbose os's may wish to override this in site.exp. | |
507 | # | |
508 | proc prune_warnings { text } { | |
509 | # This is from sun4's. Do it for all machines for now. | |
510 | # The "\\1" is to try to preserve a "\n" but only if necessary. | |
511 | regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text | |
512 | # It might be tempting to get carried away and delete blank lines, etc. | |
513 | # Just delete *exactly* what we're ask to, and that's it. | |
514 | set text [prune_warnings_extra $text] | |
515 | return $text | |
516 | } | |
517 | } elseif { [info procs saved-prune_warnings] == [list] } { | |
518 | rename prune_warnings saved-prune_warnings | |
519 | proc prune_warnings { text } { | |
520 | set text [saved-prune_warnings $text] | |
521 | set text [prune_warnings_extra $text] | |
522 | return $text | |
523 | } | |
524 | } | |
8ffb70eb AM |
525 | |
526 | # run_dump_test FILE (optional:) EXTRA_OPTIONS | |
527 | # | |
528 | # Assemble a .s file, then run some utility on it and check the output. | |
529 | # | |
530 | # There should be an assembly language file named FILE.s in the test | |
531 | # suite directory, and a pattern file called FILE.d. run_dump_test | |
532 | # will assemble FILE.s, optionally run objcopy on the object file, | |
533 | # optionally run ld, optionally run another objcopy, optionally run | |
534 | # another tool under test specified by PROG, then run a dump tool like | |
535 | # addr2line, nm, objdump, readelf or size on the object file to produce | |
536 | # textual output, and then analyze that with regexps. | |
537 | # The FILE.d file specifies what program to run, and what to expect in | |
538 | # its output. | |
539 | # | |
540 | # The FILE.d file begins with zero or more option lines, which specify | |
541 | # flags to pass to the assembler, the program to run to dump the | |
542 | # assembler's output, and the options it wants. The option lines have | |
543 | # the syntax: | |
544 | # | |
545 | # # OPTION: VALUE | |
546 | # | |
547 | # OPTION is the name of some option, like "name" or "objdump", and | |
548 | # VALUE is OPTION's value. The valid options are described below. | |
549 | # Whitespace is ignored everywhere, except within VALUE. The option | |
550 | # list ends with the first line that doesn't match the above syntax. | |
551 | # However, a line within the options that begins with a #, but doesn't | |
552 | # have a recognizable option name followed by a colon, is considered a | |
553 | # comment and entirely ignored. | |
554 | # | |
555 | # The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of | |
556 | # two-element lists. The first element of each is an option name, and | |
557 | # the second additional arguments to be added on to the end of the | |
558 | # option list as given in FILE.d. (If omitted, no additional options | |
559 | # are added.) | |
560 | # | |
561 | # The interesting options are: | |
562 | # | |
563 | # name: TEST-NAME | |
564 | # The name of this test, passed to DejaGNU's `pass' and `fail' | |
565 | # commands. If omitted, this defaults to FILE, the root of the | |
566 | # .s and .d files' names. | |
567 | # | |
568 | # as: FLAGS | |
569 | # When assembling, pass FLAGS to the assembler. | |
570 | # If assembling several files, you can pass different assembler | |
571 | # options in the "source" directives. See below. | |
52d6f3ee MM |
572 | # Multiple instances of this directive tells run_dump_test to run the test |
573 | # multiple times -- one time with each set of flags provided. | |
574 | # Each instance will run exactly as a file with a single "as" line, it is | |
575 | # not possible to condition any behaviour on which set of "as" flags is | |
576 | # used. That means that the "source" specific options are appended to | |
577 | # the "as" flags for their corresponding files, and any extra processing | |
578 | # (e.g. with "ld" and "objcopy") is repeated for each test. | |
8ffb70eb AM |
579 | # |
580 | # ld: FLAGS | |
581 | # Link assembled files using FLAGS, in the order of the "source" | |
582 | # directives, when using multiple files. | |
583 | # | |
584 | # ld_after_inputfiles: FLAGS | |
585 | # Similar to "ld", but put FLAGS after all input files. | |
586 | # | |
587 | # objcopy_objects: FLAGS | |
588 | # Run objcopy with the specified flags after assembling any source | |
589 | # that has the special marker RUN_OBJCOPY in the source specific | |
590 | # flags. | |
591 | # | |
592 | # objcopy_linked_file: FLAGS | |
593 | # Run objcopy on the linked file with the specified flags. | |
594 | # This lets you transform the linked file using objcopy, before the | |
595 | # result is analyzed by an analyzer program specified below. | |
596 | # | |
597 | # PROG: PROGRAM-NAME | |
598 | # The name of a program under test, to run to modify or analyze the | |
599 | # .o file produced by the assembler. Recognised names are: ar, | |
600 | # elfedit, nm, objcopy, ranlib, strings, and strip. | |
601 | # | |
602 | # DUMPPROG: PROGRAM-NAME | |
603 | # The name of the program to run to analyze the file produced | |
604 | # by the assembler or the linker. This can be omitted; | |
605 | # run_dump_test will guess which program to run from which of | |
606 | # the flags options below is present. | |
607 | # | |
608 | # addr2line: FLAGS | |
609 | # nm: FLAGS | |
610 | # objdump: FLAGS | |
611 | # readelf: FLAGS | |
612 | # size: FLAGS | |
613 | # Use the specified program to analyze the output file, and pass it | |
614 | # FLAGS, in addition to the output name. Note that they are run | |
615 | # with LC_ALL=C in the environment to give consistent sorting of | |
616 | # symbols. If no FLAGS are needed then you can use: | |
617 | # DUMPPROG: [nm objdump readelf addr2line] | |
618 | # instead, or just pass a flag that happens to be the default. | |
619 | # If objdump is the dump tool and we're not dumping binary, nor | |
620 | # have run ld, then the standard section names (.text, .data and | |
621 | # .bss) are replaced by target ones if any (eg. rx-elf uses "P" | |
622 | # instead of .text). The substition is done for both the | |
623 | # objdump options (eg: "-j .text" is replaced by "-j P") and the | |
624 | # reference file. | |
625 | # | |
626 | # source: SOURCE [FLAGS] | |
627 | # Assemble the file SOURCE.s using the flags in the "as" directive | |
628 | # and the (optional) FLAGS. If omitted, the source defaults to | |
629 | # FILE.s. | |
630 | # This is useful if several .d files want to share a .s file. | |
631 | # More than one "source" directive can be given, which is useful | |
632 | # when testing linking. | |
633 | # | |
634 | # dump: DUMP | |
635 | # Match against DUMP.d. If omitted, this defaults to FILE.d. This | |
636 | # is useful if several .d files differ by options only. Options are | |
637 | # always read from FILE.d. | |
638 | # | |
639 | # target: GLOB|PROC ... | |
640 | # Run this test only on a specified list of targets. More precisely, | |
641 | # in the space-separated list each glob is passed to "istarget" and | |
642 | # each proc is called as a TCL procedure. List items are interpreted | |
643 | # such that procs are denoted by surrounding square brackets, and any | |
644 | # other items are consired globs. If the call evaluates true for any | |
645 | # of them, the test will be run, otherwise it will be marked | |
646 | # unsupported. | |
647 | # | |
648 | # notarget: GLOB|PROC ... | |
649 | # Do not run this test on a specified list of targets. Again, each | |
650 | # glob in the space-separated list is passed to "istarget" and each | |
651 | # proc is called as a TCL procedure, and the test is run if it | |
652 | # evaluates *false* for *all* of them. Otherwise it will be marked | |
653 | # unsupported. | |
654 | # | |
655 | # alltargets: GLOB|PROC ... | |
656 | # Run this test on a specified list of targets. Again, each | |
657 | # glob in the space-separated list is passed to "istarget" and each | |
658 | # proc is called as a TCL procedure, and the test is run if it | |
659 | # evaluates *true* for *all* of them. Otherwise it will be marked | |
660 | # unsupported. | |
661 | # | |
662 | # skip: GLOB|PROC ... | |
663 | # anyskip: GLOB|PROC ... | |
664 | # noskip: GLOB|PROC ... | |
665 | # These are exactly the same as "notarget", "alltargets" and | |
666 | # "target" respectively, except that they do nothing at all if the | |
667 | # check fails. They should only be used in groups, to construct a | |
668 | # single test which is run on all targets but with variant options | |
669 | # or expected output on some targets. (For example, see | |
670 | # gas/arm/inst.d and gas/arm/wince_inst.d.) | |
671 | # | |
672 | # xfail: GLOB|PROC ... | |
673 | # Run this test and it is is expected to fail on a specified list | |
674 | # of targets. | |
675 | # | |
676 | # error: REGEX | |
677 | # An error with message matching REGEX must be emitted for the test | |
678 | # to pass. The DUMPPROG, addr2line, nm, objdump, readelf and size | |
679 | # options have no meaning and need not supplied if this is present. | |
680 | # Multiple "error" directives append to the expected error message. | |
681 | # | |
682 | # error_output: FILE | |
683 | # Means the same as 'error', except the regular expression lines | |
684 | # are contains in FILE. | |
685 | # | |
686 | # warning: REGEX | |
687 | # Expect a warning matching REGEX. It is an error to issue | |
688 | # both "error" and "warning". Multiple "warning" directives | |
689 | # append to the expected warning message. | |
690 | # | |
691 | # warning_output: FILE | |
692 | # Means the same as 'warning', except the regular expression | |
693 | # lines are contains in FILE. | |
694 | # | |
695 | # map: FILE | |
696 | # Adding this option will cause the linker to generate a linker | |
697 | # map file, using the -Map=MAPFILE command line option. If | |
698 | # there is no -Map=MAPFILE in the 'ld: FLAGS' then one will be | |
699 | # added to the linker command line. The contents of the | |
700 | # generated MAPFILE are then compared against the regexp lines | |
701 | # in FILE using `regexp_diff' (see below for details). | |
702 | # | |
703 | # section_subst: no | |
704 | # Means that the section substitution for objdump is disabled. | |
705 | # | |
706 | # Each option may occur at most once unless otherwise mentioned. | |
707 | # | |
708 | # After the option lines come regexp lines. run_dump_test calls | |
709 | # regexp_diff to compare the output of the dumping tool against the | |
710 | # regexps in FILE.d. | |
711 | # | |
712 | proc run_dump_test { name {extra_options {}} } { | |
713 | global ADDR2LINE ADDR2LINEFLAGS AS ASFLAGS ELFEDIT ELFEDITFLAGS LD LDFLAGS | |
714 | global NM NMFLAGS OBJCOPY OBJCOPYFLAGS OBJDUMP OBJDUMPFLAGS | |
715 | global READELF READELFFLAGS STRIP STRIPFLAGS | |
716 | global copyfile env ld_elf_shared_opt runtests srcdir subdir verbose | |
717 | ||
718 | if [string match "*/*" $name] { | |
719 | set file $name | |
720 | set name [file tail $name] | |
721 | } else { | |
722 | set file "$srcdir/$subdir/$name" | |
723 | } | |
724 | ||
725 | if ![runtest_file_p $runtests $name] then { | |
726 | return | |
727 | } | |
728 | ||
729 | set opt_array [slurp_options "${file}.d"] | |
730 | if { $opt_array == -1 } { | |
731 | perror "error reading options from $file.d" | |
732 | unresolved $subdir/$name | |
733 | return | |
734 | } | |
735 | set dumpfile tmpdir/dump.out | |
736 | set run_ld 0 | |
737 | set run_objcopy 0 | |
738 | set objfile_names {} | |
739 | set opts(PROG) {} | |
740 | set opts(DUMPPROG) {} | |
741 | set opts(addr2line) {} | |
742 | set opts(alltargets) {} | |
743 | set opts(anyskip) {} | |
744 | set opts(ar) {} | |
745 | set opts(as) {} | |
52d6f3ee MM |
746 | set as_final_flags {} |
747 | set as_additional_flags {} | |
8ffb70eb AM |
748 | set opts(dump) {} |
749 | set opts(elfedit) {} | |
750 | set opts(error) {} | |
751 | set opts(error_output) {} | |
752 | set opts(ld) {} | |
753 | set opts(ld_after_inputfiles) {} | |
754 | set opts(map) {} | |
755 | set opts(name) {} | |
756 | set opts(nm) {} | |
757 | set opts(noskip) {} | |
758 | set opts(notarget) {} | |
759 | set opts(objcopy) {} | |
760 | set opts(objcopy_linked_file) {} | |
761 | set opts(objcopy_objects) {} | |
762 | set opts(objdump) {} | |
763 | set opts(ranlib) {} | |
764 | set opts(readelf) {} | |
765 | set opts(section_subst) {} | |
766 | set opts(size) {} | |
767 | set opts(strings) {} | |
768 | set opts(strip) {} | |
769 | set opts(skip) {} | |
770 | set opts(source) {} | |
771 | set opts(strip) {} | |
772 | set opts(target) {} | |
773 | set opts(warning) {} | |
774 | set opts(warning_output) {} | |
775 | set opts(xfail) {} | |
776 | ||
777 | set in_extra 0 | |
778 | foreach i [concat $opt_array {{} {}} $extra_options] { | |
779 | set opt_name [lindex $i 0] | |
780 | set opt_val [lindex $i 1] | |
781 | if { $opt_name == "" } { | |
782 | set in_extra 1 | |
783 | continue | |
784 | } | |
785 | if ![info exists opts($opt_name)] { | |
786 | perror "unknown option $opt_name in file $file.d" | |
787 | unresolved $subdir/$name | |
788 | return | |
789 | } | |
790 | ||
791 | # Allow more substitutions, including tcl functions, for as and ld. | |
792 | # Not done in general because extra quoting is needed for glob | |
793 | # args used for example in binutils-all/remove-relocs-04.d. | |
794 | if { $opt_name == "as" || $opt_name == "ld" } { | |
795 | set opt_val [subst $opt_val] | |
796 | } else { | |
797 | # Just substitute $srcdir and $subdir | |
798 | regsub -all {\$srcdir} "$opt_val" "$srcdir" opt_val | |
799 | regsub -all {\$subdir} "$opt_val" "$subdir" opt_val | |
800 | } | |
801 | ||
802 | switch -- $opt_name { | |
803 | xfail {} | |
804 | target {} | |
805 | alltargets {} | |
806 | notarget {} | |
807 | skip {} | |
808 | anyskip {} | |
809 | noskip {} | |
810 | warning {} | |
811 | error {} | |
812 | source { | |
813 | # Move any source-specific as-flags to a separate list to | |
814 | # simplify processing. | |
815 | if { [llength $opt_val] > 1 } { | |
816 | lappend asflags [lrange $opt_val 1 end] | |
817 | set opt_val [lindex $opt_val 0] | |
818 | } else { | |
819 | lappend asflags {} | |
820 | } | |
821 | ||
822 | # Create the object file name based on nothing but the source | |
823 | # file name. | |
824 | set new_objfile \ | |
825 | [concat tmpdir/[file rootname [file tail [lindex $opt_val 0]]].o] | |
826 | # But, sometimes, we have the exact same source filename in | |
827 | # different directories (foo/src.s bar/src.s) which would lead | |
828 | # us to try and create two src.o files. We detect this | |
829 | # conflict here, and instead create src.o and src1.o. | |
830 | set j 0 | |
831 | while { [lsearch $objfile_names $new_objfile] != -1 } { | |
832 | incr j | |
833 | set new_objfile \ | |
834 | [concat tmpdir/[file rootname [file tail [lindex $opt_val 0]]]${j}.o] | |
835 | } | |
836 | lappend objfile_names $new_objfile | |
837 | } | |
838 | default { | |
52d6f3ee MM |
839 | if { !$in_extra |
840 | && [string length $opts($opt_name)] | |
841 | && $opt_name != "as" } { | |
8ffb70eb AM |
842 | perror "option $opt_name multiply set in $file.d" |
843 | unresolved $subdir/$name | |
844 | return | |
845 | } | |
846 | ||
847 | # A single "#ld:" with no options should do the right thing. | |
848 | if { $opt_name == "ld" } { | |
849 | set run_ld 1 | |
850 | } | |
851 | # Likewise objcopy_linked_file. | |
852 | if { $opt_name == "objcopy_linked_file" } { | |
853 | set run_objcopy 1 | |
854 | } | |
855 | } | |
856 | } | |
857 | ||
858 | # Append differently whether it's a message (without space) or | |
859 | # an option or list (with space). | |
860 | switch -- $opt_name { | |
861 | warning - | |
862 | error { | |
863 | append opts($opt_name) $opt_val | |
864 | } | |
52d6f3ee MM |
865 | as { |
866 | if { $in_extra } { | |
867 | set as_additional_flags [concat $as_additional_flags $opt_val] | |
868 | } else { | |
869 | lappend opts(as) $opt_val | |
870 | } | |
871 | } | |
8ffb70eb AM |
872 | default { |
873 | set opts($opt_name) [concat $opts($opt_name) $opt_val] | |
874 | } | |
875 | } | |
876 | } | |
877 | ||
093f70cc | 878 | # Ensure there is something in $opts(as) for the foreach loop below. |
52d6f3ee MM |
879 | if { [llength $opts(as)] == 0 } { |
880 | set opts(as) [list " "] | |
8ffb70eb | 881 | } |
093f70cc | 882 | foreach x $opts(as) { |
52d6f3ee MM |
883 | if { [string length $x] && [string length $as_additional_flags] } { |
884 | append x " " | |
885 | } | |
886 | append x $as_additional_flags | |
887 | regsub {\[big_or_little_endian\]} $x \ | |
888 | [big_or_little_endian] x | |
093f70cc MM |
889 | lappend as_final_flags $x |
890 | } | |
52d6f3ee MM |
891 | |
892 | regsub {\[big_or_little_endian\]} $opts(ld) \ | |
893 | [big_or_little_endian] opts(ld) | |
8ffb70eb AM |
894 | |
895 | if { $opts(name) == "" } { | |
896 | set testname "$subdir/$name" | |
897 | } else { | |
898 | set testname $opts(name) | |
899 | } | |
900 | ||
901 | set err_warn 0 | |
902 | foreach opt { warning error warning_output error_output } { | |
903 | if { $opts($opt) != "" } { | |
904 | if { $err_warn } { | |
905 | perror "$testname: bad mix of warning and error test directives" | |
906 | unresolved $testname | |
907 | return | |
908 | } | |
909 | set err_warn 1 | |
910 | } | |
911 | } | |
912 | ||
913 | # Decide early whether we should run the test for this target. | |
914 | if { [llength $opts(noskip)] > 0 } { | |
915 | set targmatch 0 | |
916 | foreach targ $opts(noskip) { | |
917 | if [match_target $targ] { | |
918 | set targmatch 1 | |
919 | break | |
920 | } | |
921 | } | |
922 | if { $targmatch == 0 } { | |
923 | return | |
924 | } | |
925 | } | |
926 | foreach targ $opts(anyskip) { | |
927 | if ![match_target $targ] { | |
928 | return | |
929 | } | |
930 | } | |
931 | foreach targ $opts(skip) { | |
932 | if [match_target $targ] { | |
933 | return | |
934 | } | |
935 | } | |
936 | if { [llength $opts(target)] > 0 } { | |
937 | set targmatch 0 | |
938 | foreach targ $opts(target) { | |
939 | if [match_target $targ] { | |
940 | set targmatch 1 | |
941 | break | |
942 | } | |
943 | } | |
944 | if { $targmatch == 0 } { | |
945 | unsupported $testname | |
946 | return | |
947 | } | |
948 | } | |
949 | foreach targ $opts(alltargets) { | |
950 | if ![match_target $targ] { | |
951 | unsupported $testname | |
952 | return | |
953 | } | |
954 | } | |
955 | foreach targ $opts(notarget) { | |
956 | if [match_target $targ] { | |
957 | unsupported $testname | |
958 | return | |
959 | } | |
960 | } | |
961 | ||
962 | set dumpprogram "" | |
963 | # It's meaningless to require an output-testing method when we | |
964 | # expect an error. | |
965 | if { $opts(error) == "" && $opts(error_output) == "" } { | |
966 | if { $opts(DUMPPROG) != "" } { | |
967 | switch -- $opts(DUMPPROG) { | |
968 | addr2line { set dumpprogram addr2line } | |
969 | nm { set dumpprogram nm } | |
970 | objdump { set dumpprogram objdump } | |
971 | readelf { set dumpprogram readelf } | |
972 | size { set dumpprogram size } | |
973 | default { | |
974 | perror "unrecognized DUMPPROG option $opts(DUMPPROG) in $file.d" | |
975 | unresolved $testname | |
976 | return | |
977 | } | |
978 | } | |
979 | } else { | |
980 | # Guess which program to run, by seeing which option was specified. | |
981 | foreach p {addr2line nm objdump readelf size} { | |
982 | if {$opts($p) != ""} { | |
983 | if {$dumpprogram != ""} { | |
984 | perror "ambiguous dump program in $file.d" | |
985 | unresolved $testname | |
986 | return | |
987 | } else { | |
988 | set dumpprogram $p | |
989 | } | |
990 | } | |
991 | } | |
992 | } | |
993 | if { $dumpprogram == "" && $opts(map) == "" && !$err_warn } { | |
994 | perror "dump program unspecified in $file.d" | |
995 | unresolved $testname | |
996 | return | |
997 | } | |
998 | } | |
999 | ||
1000 | if { $opts(source) == "" } { | |
1001 | set sourcefiles [list ${file}.s] | |
1002 | set asflags [list ""] | |
1003 | set objfile_names [list tmpdir/[file tail ${file}].o] | |
1004 | } else { | |
1005 | set sourcefiles {} | |
1006 | foreach sf $opts(source) { | |
171b8e19 | 1007 | if { [string match "./*" $sf] } { |
8ffb70eb AM |
1008 | lappend sourcefiles "$sf" |
1009 | } else { | |
1010 | lappend sourcefiles "$srcdir/$subdir/$sf" | |
1011 | } | |
1012 | } | |
1013 | } | |
1014 | ||
1015 | if { $opts(dump) == "" } { | |
1016 | set dfile ${file}.d | |
1017 | } else { | |
1018 | set dfile $srcdir/$subdir/$opts(dump) | |
1019 | } | |
1020 | ||
1021 | # Time to setup xfailures. | |
1022 | foreach targ $opts(xfail) { | |
1336939d AM |
1023 | if [match_target $targ] { |
1024 | setup_xfail "*-*-*" | |
1025 | break | |
1026 | } | |
8ffb70eb AM |
1027 | } |
1028 | ||
52d6f3ee MM |
1029 | foreach as_flags $as_final_flags { |
1030 | # Assemble each file. | |
1031 | set objfiles {} | |
1032 | for { set i 0 } { $i < [llength $sourcefiles] } { incr i } { | |
1033 | set sourcefile [lindex $sourcefiles $i] | |
1034 | set sourceasflags [lindex $asflags $i] | |
1035 | set run_objcopy_objects 0 | |
1036 | ||
1037 | if { [string match "*RUN_OBJCOPY*" $sourceasflags] } { | |
1038 | set run_objcopy_objects 1 | |
1039 | } | |
1040 | regsub "RUN_OBJCOPY" $sourceasflags "" sourceasflags | |
1041 | ||
1042 | set objfile [lindex $objfile_names $i] | |
1043 | catch "exec rm -f $objfile" exec_output | |
1044 | lappend objfiles $objfile | |
1045 | ||
1046 | if { $as_flags == "binary" } { | |
1047 | while {[file type $sourcefile] eq "link"} { | |
1048 | set newfile [file readlink $sourcefile] | |
1049 | if {[string index $newfile 0] ne "/"} { | |
1050 | set newfile [file dirname $sourcefile]/$newfile | |
1051 | } | |
1052 | set sourcefile $newfile | |
1053 | } | |
1054 | set newfile [remote_download host $sourcefile $objfile] | |
1055 | set cmdret 0 | |
1056 | if { $newfile == "" } { | |
1057 | set cmdret 1 | |
1058 | } | |
1059 | } else { | |
1060 | if { [istarget "hppa*-*-*"] \ | |
1061 | && ![istarget "*-*-linux*"] \ | |
1062 | && ![istarget "*-*-netbsd*" ] } { | |
1063 | set cmd "sed -e 's/^\[ \]*\.comm \\(\[^,\]*\\),\\(.*\\)/\\1 .comm \\2/' < $sourcefile > tmpdir/asm.s" | |
1064 | send_log "$cmd\n" | |
1065 | set cmdret [remote_exec host [concat sh -c [list "$cmd"]]] | |
1066 | set cmdret [lindex $cmdret 0] | |
1067 | if { $cmdret != 0 } { | |
1068 | perror "sed failure" | |
1069 | unresolved $testname | |
1070 | continue | |
1071 | } | |
1072 | set sourcefile tmpdir/asm.s | |
1073 | } | |
1074 | set cmd "$AS $ASFLAGS $as_flags $sourceasflags -o $objfile $sourcefile" | |
1075 | ||
1076 | send_log "$cmd\n" | |
1077 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "dump.tmp"] | |
1078 | remote_upload host "dump.tmp" | |
1079 | set comp_output [prune_warnings [file_contents "dump.tmp"]] | |
1080 | remote_file host delete "dump.tmp" | |
1081 | remote_file build delete "dump.tmp" | |
1082 | set cmdret [lindex $cmdret 0] | |
1083 | } | |
1084 | if { $cmdret == 0 && $run_objcopy_objects } { | |
1085 | set cmd "$OBJCOPY $opts(objcopy_objects) $objfile" | |
1086 | ||
1087 | send_log "$cmd\n" | |
1088 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] \ | |
1089 | "" "/dev/null" "dump.tmp"] | |
1090 | remote_upload host "dump.tmp" | |
1091 | append comp_output [prune_warnings [file_contents "dump.tmp"]] | |
1092 | remote_file host delete "dump.tmp" | |
1093 | remote_file build delete "dump.tmp" | |
1094 | set cmdret [lindex $cmdret 0] | |
1095 | } | |
1096 | } | |
1097 | ||
1098 | # Perhaps link the file(s). | |
1099 | if { $cmdret == 0 && $run_ld } { | |
1100 | set objfile "tmpdir/dump" | |
1101 | catch "exec rm -f $objfile" exec_output | |
1102 | ||
1103 | set ld_extra_opt "" | |
1104 | global ld | |
1105 | set ld "$LD" | |
1106 | if { [is_elf_format] && [check_shared_lib_support] } { | |
1107 | set ld_extra_opt "$ld_elf_shared_opt" | |
1108 | } | |
1109 | ||
1110 | # Add -L$srcdir/$subdir so that the linker command can use | |
1111 | # linker scripts in the source directory. | |
1112 | set cmd "$LD $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \ | |
8ffb70eb AM |
1113 | $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)" |
1114 | ||
52d6f3ee MM |
1115 | # If needed then check for, or add a -Map option. |
1116 | set mapfile "" | |
1117 | if { $opts(map) != "" } then { | |
1118 | if { [regexp -- "-Map=(\[^ \]+)" $cmd all mapfile] } then { | |
1119 | # Found existing mapfile option | |
1120 | verbose -log "Existing mapfile '$mapfile' found" | |
1121 | } else { | |
1122 | # No mapfile option. | |
1123 | set mapfile "tmpdir/dump.map" | |
1124 | verbose -log "Adding mapfile '$mapfile'" | |
1125 | set cmd "$cmd -Map=$mapfile" | |
1126 | } | |
1127 | } | |
1128 | ||
1129 | send_log "$cmd\n" | |
1130 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "dump.tmp"] | |
1131 | remote_upload host "dump.tmp" | |
1132 | append comp_output [file_contents "dump.tmp"] | |
1133 | remote_file host delete "dump.tmp" | |
1134 | remote_file build delete "dump.tmp" | |
1135 | set cmdret [lindex $cmdret 0] | |
1136 | ||
1137 | if { $cmdret == 0 && $run_objcopy } { | |
1138 | set infile $objfile | |
1139 | set objfile "tmpdir/dump1" | |
1140 | remote_file host delete $objfile | |
1141 | ||
1142 | # Note that we don't use OBJCOPYFLAGS here; any flags must be | |
1143 | # explicitly specified. | |
1144 | set cmd "$OBJCOPY $opts(objcopy_linked_file) $infile $objfile" | |
1145 | ||
1146 | send_log "$cmd\n" | |
1147 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "dump.tmp"] | |
1148 | remote_upload host "dump.tmp" | |
1149 | append comp_output [file_contents "dump.tmp"] | |
1150 | remote_file host delete "dump.tmp" | |
1151 | remote_file build delete "dump.tmp" | |
1152 | set cmdret [lindex $cmdret 0] | |
1153 | } | |
1154 | } else { | |
1155 | set objfile [lindex $objfiles 0] | |
1156 | } | |
1157 | ||
1158 | if { $cmdret == 0 && $opts(PROG) != "" } { | |
1159 | set destopt ${copyfile}.o | |
1160 | switch -- $opts(PROG) { | |
1161 | ar { set program ar } | |
1162 | elfedit { | |
1163 | set program elfedit | |
1164 | set destopt "" | |
1165 | } | |
1166 | nm { set program nm } | |
1167 | objcopy { set program objcopy } | |
1168 | ranlib { set program ranlib } | |
1169 | strings { set program strings } | |
1170 | strip { | |
1171 | set program strip | |
1172 | set destopt "-o $destopt" | |
1173 | } | |
1174 | default { | |
1175 | perror "unrecognized PROG option $opts(PROG) in $file.d" | |
1176 | unresolved $testname | |
1177 | continue | |
1178 | } | |
1179 | } | |
1180 | ||
1181 | set progopts1 $opts($program) | |
1182 | eval set progopts \$[string toupper $program]FLAGS | |
1183 | eval set binary \$[string toupper $program] | |
1184 | ||
1185 | if { ![is_remote host] && [which $binary] == 0 } { | |
1186 | untested $testname | |
1187 | continue | |
1188 | } | |
1189 | ||
1190 | verbose "running $binary $progopts $progopts1" 3 | |
1191 | set cmd "$binary $progopts $progopts1 $objfile $destopt" | |
1192 | ||
1193 | # Ensure consistent sorting of symbols | |
1194 | if {[info exists env(LC_ALL)]} { | |
1195 | set old_lc_all $env(LC_ALL) | |
1196 | } | |
1197 | set env(LC_ALL) "C" | |
1198 | send_log "$cmd\n" | |
1199 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>dump.tmp"]] "" "/dev/null"] | |
1200 | set cmdret [lindex $cmdret 0] | |
1201 | remote_upload host "dump.tmp" | |
1202 | append comp_output [prune_warnings [file_contents "dump.tmp"]] | |
1203 | remote_file host delete "dump.tmp" | |
1204 | remote_file build delete "dump.tmp" | |
1205 | if {[info exists old_lc_all]} { | |
1206 | set env(LC_ALL) $old_lc_all | |
1207 | } else { | |
1208 | unset env(LC_ALL) | |
1209 | } | |
1210 | if { $destopt != "" } { | |
1211 | set objfile ${copyfile}.o | |
1212 | } | |
1213 | } | |
1214 | ||
1215 | set want_out(source) "" | |
1216 | set want_out(terminal) 0 | |
1217 | if { $err_warn } { | |
1218 | if { $opts(error) != "" || $opts(error_output) != "" } { | |
1219 | set want_out(terminal) 1 | |
1220 | } | |
1221 | ||
1222 | if { $opts(error) != "" || $opts(warning) != "" } { | |
1223 | set want_out(source) "regex" | |
1224 | if { $opts(error) != "" } { | |
1225 | set want_out(regex) $opts(error) | |
1226 | } else { | |
1227 | set want_out(regex) $opts(warning) | |
1228 | } | |
1229 | } else { | |
1230 | set want_out(source) "file" | |
1231 | if { $opts(error_output) != "" } { | |
1232 | set want_out(file) $opts(error_output) | |
1233 | } else { | |
1234 | set want_out(file) $opts(warning_output) | |
1235 | } | |
1236 | } | |
1237 | } | |
1238 | ||
1239 | regsub "\n$" $comp_output "" comp_output | |
1240 | if { $cmdret != 0 || $comp_output != "" || $want_out(source) != "" } { | |
1241 | set exitstat "succeeded" | |
1242 | if { $cmdret != 0 } { set exitstat "failed" } | |
1243 | ||
1244 | if { $want_out(source) == "regex" } { | |
1245 | verbose -log "$exitstat with: <$comp_output>, expected: <$want_out(regex)>" | |
1246 | } elseif { $want_out(source) == "file" } { | |
1247 | verbose -log "$exitstat with: <$comp_output>, expected in file $want_out(file)" | |
1248 | set_file_contents "tmpdir/ld.messages" "$comp_output" | |
1249 | } else { | |
1250 | verbose -log "$exitstat with: <$comp_output>, no expected output" | |
1251 | } | |
1252 | ||
1253 | if { (($want_out(source) == "") == ($comp_output == "")) \ | |
1254 | && (($cmdret == 0) == ($want_out(terminal) == 0)) \ | |
1255 | && ((($want_out(source) == "regex") \ | |
1256 | && [regexp -- $want_out(regex) $comp_output]) \ | |
1257 | || (($want_out(source) == "file") \ | |
1258 | && (![regexp_diff "tmpdir/ld.messages" "$srcdir/$subdir/$want_out(file)"]))) } { | |
1259 | # We have the expected output. | |
1260 | if { $want_out(terminal) || $dumpprogram == "" } { | |
1261 | pass $testname | |
1262 | continue | |
1263 | } | |
1264 | } else { | |
1265 | fail $testname | |
1266 | continue | |
1267 | } | |
1268 | } | |
1269 | ||
1270 | # We must not have expected failure if we get here. | |
1271 | if { $opts(error) != "" } { | |
1272 | fail $testname | |
1273 | continue | |
1274 | } | |
1275 | ||
1276 | if { $opts(map) != "" } then { | |
1277 | # Check the map file matches. | |
1278 | set map_pattern_file $srcdir/$subdir/$opts(map) | |
1279 | verbose -log "Compare '$mapfile' against '$map_pattern_file'" | |
1280 | if { [regexp_diff $mapfile $map_pattern_file] } then { | |
1281 | fail "$testname (map file check)" | |
1282 | } else { | |
1283 | pass "$testname (map file check)" | |
1284 | } | |
1285 | ||
1286 | if { $dumpprogram == "" } then { | |
1287 | continue | |
1288 | } | |
1289 | } | |
1290 | ||
1291 | set progopts1 $opts($dumpprogram) | |
1292 | eval set progopts \$[string toupper $dumpprogram]FLAGS | |
1293 | eval set binary \$[string toupper $dumpprogram] | |
1294 | ||
1295 | if { ![is_remote host] && [which $binary] == 0 } { | |
1296 | untested $testname | |
1297 | continue | |
1298 | } | |
1299 | ||
1300 | # For objdump of gas output, automatically translate standard section names | |
1301 | set sect_names "" | |
1302 | if { !$run_ld && $dumpprogram == "objdump" \ | |
1303 | && $opts(section_subst) != "no" \ | |
1304 | && ![string match "*-b binary*" $progopts1] } { | |
1305 | set sect_names [get_standard_section_names] | |
1306 | if { $sect_names != ""} { | |
1307 | regsub -- "\\.text" $progopts1 "[lindex $sect_names 0]" progopts1 | |
1308 | regsub -- "\\.data" $progopts1 "[lindex $sect_names 1]" progopts1 | |
1309 | regsub -- "\\.bss" $progopts1 "[lindex $sect_names 2]" progopts1 | |
1310 | } | |
1311 | } | |
1312 | ||
1313 | if { $progopts1 == "" } { set $progopts1 "-r" } | |
1314 | verbose "running $binary $progopts $progopts1" 3 | |
1315 | ||
1316 | set cmd "$binary $progopts $progopts1 $objfile > $dumpfile" | |
1317 | ||
1318 | # Ensure consistent sorting of symbols | |
1319 | if {[info exists env(LC_ALL)]} { | |
1320 | set old_lc_all $env(LC_ALL) | |
1321 | } | |
1322 | set env(LC_ALL) "C" | |
1323 | send_log "$cmd\n" | |
1324 | set cmdret [remote_exec host [concat sh -c [list "$cmd 2>dump.tmp"]] "" "/dev/null"] | |
1325 | set cmdret [lindex $cmdret 0] | |
1326 | remote_upload host "dump.tmp" | |
1327 | set comp_output [prune_warnings [file_contents "dump.tmp"]] | |
1328 | remote_file host delete "dump.tmp" | |
1329 | remote_file build delete "dump.tmp" | |
1330 | if {[info exists old_lc_all]} { | |
1331 | set env(LC_ALL) $old_lc_all | |
1332 | } else { | |
1333 | unset env(LC_ALL) | |
1334 | } | |
1335 | if { $cmdret != 0 || $comp_output != "" } { | |
1336 | send_log "exited abnormally with $cmdret, output:$comp_output\n" | |
1337 | fail $testname | |
1338 | continue | |
1339 | } | |
1340 | ||
1341 | if { $verbose > 2 } then { verbose "output is [file_contents $dumpfile]" 3 } | |
1342 | ||
1343 | # Create the substition list for objdump output. | |
1344 | set regexp_subst "" | |
1345 | if { $sect_names != "" } { | |
1346 | set regexp_subst [list "\\\\?\\.text" [lindex $sect_names 0] \ | |
1347 | "\\\\?\\.data" [lindex $sect_names 1] \ | |
1348 | "\\\\?\\.bss" [lindex $sect_names 2] ] | |
1349 | } | |
1350 | ||
1351 | if { [regexp_diff $dumpfile "${dfile}" $regexp_subst] } then { | |
1352 | fail $testname | |
1353 | if { $verbose == 2 } then { verbose "output is [file_contents $dumpfile]" 2 } | |
1354 | continue | |
1355 | } | |
1356 | ||
1357 | pass $testname | |
8ffb70eb | 1358 | } |
8ffb70eb AM |
1359 | } |
1360 | ||
1361 | proc slurp_options { file } { | |
1362 | # If options_regsub(foo) is set to {a b}, then the contents of a | |
1363 | # "#foo:" line will have regsub -all applied to replace a with b. | |
1364 | global options_regsub | |
1365 | ||
1366 | if [catch { set f [open $file r] } x] { | |
1367 | #perror "couldn't open `$file': $x" | |
1368 | perror "$x" | |
1369 | return -1 | |
1370 | } | |
1371 | set opt_array {} | |
1372 | # whitespace expression | |
1373 | set ws {[ ]*} | |
1374 | set nws {[^ ]*} | |
1375 | # whitespace is ignored anywhere except within the options list; | |
1376 | # option names are alphanumeric plus underscore. | |
1377 | set pat "^#${ws}(\[a-zA-Z0-9_\]*)$ws:${ws}(.*)$ws\$" | |
1378 | while { [gets $f line] != -1 } { | |
1379 | set line [string trim $line] | |
1380 | # Whitespace here is space-tab. | |
1381 | if [regexp $pat $line xxx opt_name opt_val] { | |
1382 | # match! | |
1383 | if [info exists options_regsub($opt_name)] { | |
1384 | set subst $options_regsub($opt_name) | |
1385 | regsub -all -- [lindex $subst 0] $opt_val [lindex $subst 1] \ | |
1386 | opt_val | |
1387 | } | |
1388 | lappend opt_array [list $opt_name $opt_val] | |
1389 | } elseif {![regexp "^#" $line ]} { | |
1390 | break | |
1391 | } | |
1392 | } | |
1393 | close $f | |
1394 | return $opt_array | |
1395 | } | |
1396 | ||
1397 | proc file_contents { filename } { | |
1398 | set file [open $filename r] | |
1399 | set contents [read $file] | |
1400 | close $file | |
1401 | return $contents | |
1402 | } | |
1403 | ||
1404 | proc set_file_contents { filename contents } { | |
1405 | set file [open $filename w] | |
1406 | puts $file "$contents" | |
1407 | close $file | |
1408 | } | |
1409 | ||
1410 | # Look for big-endian or little-endian switches in the multlib | |
1411 | # options and translate these into a -EB or -EL switch. Note | |
1412 | # we cannot rely upon proc process_multilib_options to do this | |
1413 | # for us because for some targets the compiler does not support | |
1414 | # -EB/-EL but it does support -mbig-endian/-mlittle-endian, and | |
1415 | # the site.exp file will include the switch "-mbig-endian" | |
1416 | # (rather than "big-endian") which is not detected by proc | |
1417 | # process_multilib_options. | |
1418 | # | |
1419 | proc big_or_little_endian {} { | |
1420 | ||
1421 | if [board_info [target_info name] exists multilib_flags] { | |
1422 | set tmp_flags " [board_info [target_info name] multilib_flags]" | |
1423 | ||
1424 | foreach x $tmp_flags { | |
e3696f67 AM |
1425 | switch -glob $x { |
1426 | *big*endian - | |
1427 | eb - | |
1428 | EB - | |
1429 | -eb - | |
1430 | -EB - | |
1431 | -mb - | |
1432 | -meb { | |
8ffb70eb AM |
1433 | set flags " -EB" |
1434 | return $flags | |
1435 | } | |
e3696f67 AM |
1436 | *little*endian - |
1437 | el - | |
1438 | EL - | |
1439 | -el - | |
1440 | -EL - | |
1441 | -ml - | |
1442 | -mel { | |
8ffb70eb AM |
1443 | set flags " -EL" |
1444 | return $flags | |
1445 | } | |
1446 | } | |
1447 | } | |
1448 | } | |
1449 | ||
1450 | set flags "" | |
1451 | return $flags | |
1452 | } | |
1453 | ||
1454 | # Internal procedure: return the names of the standard sections | |
1455 | # | |
1456 | proc get_standard_section_names {} { | |
8d3c78e4 | 1457 | if [istarget "rx-*-elf"] { |
8ffb70eb AM |
1458 | return { "P" "D_1" "B_1" } |
1459 | } | |
0b1352e0 AM |
1460 | if { [istarget "alpha*-*-*vms*"] || [is_som_format] } { |
1461 | return { {\$CODE\$} {\$DATA\$} {\$BSS\$} } | |
8ffb70eb AM |
1462 | } |
1463 | return | |
1464 | } |