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