1 # Copyright (C) 1993-2019 Free Software Foundation, Inc.
3 # This file is part of the GNU Binutils.
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.
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.
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,
20 # True if the object format is known to be ELF.
22 proc is_elf_format {} {
23 # config.sub for these targets curiously transforms a target doublet
24 # ending in -elf to -none. eg. m68hc12-elf to m68hc12-unknown-none
25 # They are always elf.
26 if { [istarget m68hc1*-*] || [istarget s12z*-*] || [istarget xgate-*] } {
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*]
34 if { ![istarget *-*-chorus*]
35 && ![istarget *-*-cloudabi*]
36 && ![istarget *-*-eabi*]
37 && ![istarget *-*-*elf*]
38 && ![istarget *-*-*freebsd*]
39 && ![istarget *-*-fuchsia*]
40 && ![istarget *-*-gnu*]
41 && ![istarget *-*-irix5*]
42 && ![istarget *-*-irix6*]
43 && ![istarget *-*-kaos*]
44 && ![istarget *-*-*linux*]
45 && ![istarget *-*-lynxos*]
46 && ![istarget *-*-nacl*]
47 && ![istarget *-*-netbsd*]
48 && ![istarget *-*-nto*]
49 && ![istarget *-*-openbsd*]
50 && ![istarget *-*-rtems*]
51 && ![istarget *-*-solaris2*]
52 && ![istarget *-*-sysv4*]
53 && ![istarget *-*-unixware*]
54 && ![istarget *-*-wasm32*]
55 && ![istarget avr-*-*]
56 && ![istarget hppa*64*-*-hpux*]
57 && ![istarget ia64-*-hpux*] } {
61 if { [istarget *-*-linux*ecoff*]
62 || [istarget *-*-rtemscoff*] } {
66 if { ![istarget *-*-netbsdelf*]
67 && ( [istarget vax-*-netbsd*]
68 || [istarget ns32k-*-netbsd*]) } {
72 if { [istarget arm-*-openbsd*]
73 || [istarget ns32k-*-openbsd*]
74 || [istarget vax-*-openbsd*] } {
81 # True if the object format is known to be a.out.
83 proc is_aout_format {} {
84 if { [istarget *-*-*aout*]
85 || [istarget *-*-bsd*]
86 || [istarget *-*-msdos*]
87 || [istarget ns32k-*-*]
88 || [istarget pdp11-*-*]
89 || [istarget vax-*-netbsd] } {
95 # True if the object format is known to be PE COFF.
97 proc is_pecoff_format {} {
98 if { ![istarget *-*-mingw*]
99 && ![istarget *-*-cygwin*]
100 && ![istarget *-*-cegcc*]
101 && ![istarget *-*-pe*] } {
108 proc is_som_format {} {
109 if { ![istarget hppa*-*-*] || [istarget hppa*64*-*-*] } {
112 if { [istarget *-*-osf*] \
113 || [istarget {*-*-h[ip]ux*}] \
114 || [istarget *-*-mpeix*] \
115 || [istarget *-*-bsd*] } {
121 # True if the object format is known to be 64-bit ELF.
123 proc is_elf64 { binary_file } {
127 set tmpfile [file dirname $binary_file]/readelf.out
129 catch "exec $READELF $READELFFLAGS -h $binary_file > $tmpfile" got
131 if ![string match "" $got] then {
135 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
136 [file_contents $tmpfile] nil readelf_size] } {
140 if { $readelf_size == "64" } {
147 # True if the object format is known to use RELA relocations.
149 proc is_rela { binary_file } {
153 set tmpfile [file dirname $binary_file]/readelf.out
154 catch "exec $READELF $READELFFLAGS -S $binary_file > $tmpfile" got
156 if ![string match "" $got] then {
160 if { ![regexp "RELA" [file_contents $tmpfile]] } {
167 # True if the target matches TARGET, specified as a TCL procedure if
168 # in square brackets or as machine triplet otherwise.
170 proc match_target { target } {
171 if [string match {\[*\]} $target] {
174 return [istarget $target]
178 # True if the ELF target supports STB_GNU_UNIQUE with the ELF header's
179 # OSABI field set to ELFOSABI_GNU.
181 # This generally depends on the target OS only, however there are a
182 # number of exceptions for bare metal targets as follows. The MSP430
183 # and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot
184 # support STB_GNU_UNIQUE. Likewise non-EABI ARM targets set OSABI to
185 # ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*. Finally
186 # rather than `bfd_elf_final_link' AM33/2.0, D30V, DLX, and
187 # picoJava targets use `_bfd_generic_final_link', which does not
188 # support STB_GNU_UNIQUE symbol binding causing assertion failures.
190 proc supports_gnu_unique {} {
191 if { [istarget *-*-gnu*]
192 || [istarget *-*-linux*]
193 || [istarget *-*-nacl*] } {
196 if { [istarget "arm*-*-*eabi*"] } {
199 if { [istarget "wasm32*-*-*"] } {
202 if { ![istarget "*-*-elf*"] } {
205 if { [istarget "arm*-*-*"]
206 || [istarget "msp430-*-*"]
207 || [istarget "tic6x-*-*"]
208 || [istarget "visium-*-*"] } {
211 if { [istarget "am33_2.0-*-*"]
212 || [istarget "d30v-*-*"]
213 || [istarget "dlx-*-*"]
214 || [istarget "pj*-*-*"]
215 || [istarget "xgate-*-*"] } {
221 # True for targets that do not sort .symtab as per the ELF standard.
222 # ie. any that have mips_elf32_be_vec, mips_elf32_le_vec,
223 # mips_elf32_n_be_vec or mips_elf32_n_le_vec as the primary bfd target
224 # vector in config.bfd. When syncing with config.bfd, don't forget that
225 # earlier case-matches trump later ones.
226 proc is_bad_symtab {} {
227 if { ![istarget "mips*-*-*"] } {
230 if { [istarget "*-*-chorus*"]
231 || [istarget "*-*-irix5*"]
232 || [istarget "*-*-irix6*"]
233 || [istarget "*-*-none"]
234 || [istarget "*-*-rtems*"]
235 || [istarget "*-*-windiss"] } {
238 if { [istarget "*-*-elf*"]
239 && ![istarget "*-sde-*"]
240 && ![istarget "*-mti-*"]
241 && ![istarget "*-img-*"] } {
244 if { [istarget "*-*-openbsd*"]
245 && ![istarget "mips64*-*-*"] } {
251 # Returns true if -shared is supported on the target
253 proc check_shared_lib_support { } {
254 global shared_available_saved
257 if {![info exists shared_available_saved]} {
258 set ld_output [remote_exec host $ld "-shared"]
259 if { [ string first "not supported" $ld_output ] >= 0 } {
260 set shared_available_saved 0
262 set shared_available_saved 1
265 return $shared_available_saved
268 # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
269 # is the expected output. Ignore blank lines in either file.
271 # FILE_2 is a series of regexps, comments and # directives. The directives
275 # Treat the test as a PASS if everything up till this point has
276 # matched. Ignore any remaining lines in either FILE_1 or FILE_2.
279 # Reverse the sense of the test: expect differences to exist.
283 # Skip all lines in FILE_1 until the first that matches REGEXP.
285 # Other # lines are comments. Regexp lines starting with the `!' character
286 # specify inverse matching (use `\!' for literal matching against a leading
287 # `!'). Skip empty lines in both files.
289 # The first optional argument is a list of regexp substitutions of the form:
291 # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
293 # This tells the function to apply each regexp substitution EXPi->SUBSPECi
294 # in order to every line of FILE_2.
296 # Return nonzero if differences exist.
297 proc regexp_diff { file_1 file_2 args } {
305 if { [llength $args] > 0 } {
306 set ref_subst [lindex $args 0]
308 if { [llength $args] > 1 } {
309 perror "Too many arguments to regexp_diff"
313 if [file exists $file_1] then {
314 set file_a [open $file_1 r]
316 perror "$file_1 doesn't exist"
320 if [file exists $file_2] then {
321 set file_b [open $file_2 r]
323 perror "$file_2 doesn't exist"
328 verbose " Regexp-diff'ing: $file_1 $file_2" 2
333 while { [string length $line_a] == 0 } {
334 # Ignore blank line in FILE_1.
335 if { [gets $file_a line_a] == $eof } {
340 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
341 if { [string match "#pass" $line_b] } {
345 } elseif { [string match "#failif" $line_b] } {
346 send_log "fail if no difference\n"
347 verbose "fail if no difference" 3
349 } elseif { [string match "#..." $line_b] } {
350 if { [gets $file_b line_b] == $eof } {
355 set negated [expr { [string index $line_b 0] == "!" }]
356 set line_bx [string range $line_b $negated end]
357 set n [expr { $negated ? "! " : "" }]
358 # Substitute on the reference.
359 foreach {name value} $ref_subst {
360 regsub -- $name $line_bx $value line_bx
362 verbose "looking for $n\"^$line_bx$\"" 3
363 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
364 verbose "skipping \"$line_a\"" 3
365 if { [gets $file_a line_a] == $eof } {
372 if { [gets $file_b line_b] == $eof } {
380 } elseif { $end_1 && $end_2 } {
382 } elseif { $end_1 } {
383 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
384 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
387 } elseif { $end_2 } {
388 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
389 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
393 set negated [expr { [string index $line_b 0] == "!" }]
394 set line_bx [string range $line_b $negated end]
395 set n [expr { $negated ? "! " : "" }]
396 set s [expr { $negated ? " " : "" }]
397 # Substitute on the reference.
398 foreach {name value} $ref_subst {
399 regsub -- $name $line_bx $value line_bx
401 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
402 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
403 send_log "regexp_diff match failure\n"
404 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
405 verbose "regexp_diff match failure\n" 3
411 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
412 send_log "$file_1 and $file_2 are different lengths\n"
413 verbose "$file_1 and $file_2 are different lengths" 3
417 if { $fail_if_match } {
418 if { $differences == 0 } {
431 # prune_warnings_extra -- delete extra warnings from TEXT.
434 # ld: warning: /lib64/ld-linux-x86-64.so.2: unsupported GNU_PROPERTY_TYPE (5) type : 0xc0010001
435 proc prune_warnings_extra { text } {
437 # Warnings are only pruned from non-experimental code (ie code not
438 # on a release branch). For experimental code we want the warnings
439 # as they indicate that the sources need to be updated to recognise
440 # the new properties.
441 if { "$experimental" == "false" } {
442 # The "\\1" is to try to preserve a "\n" but only if necessary.
443 regsub -all "(^|\n)(\[^\n\]*: warning:\[^\n\]*unsupported GNU_PROPERTY_TYPE\[^\n\]*\n?)+" $text "\\1" text
445 # PR binutils/23898: It is OK to have gaps in build notes.
446 regsub -all "(^|\n)(\[^\n\]*: Warning: Gap in build notes detected from\[^\n\]*\n?)+" $text "\\1" text
450 # This definition is taken from an unreleased version of DejaGnu. Once
451 # that version gets released, and has been out in the world for a few
452 # months at least, it may be safe to delete this copy.
453 if ![string length [info proc prune_warnings]] {
455 # prune_warnings -- delete various system verbosities from TEXT
458 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
460 # Sites with particular verbose os's may wish to override this in site.exp.
462 proc prune_warnings { text } {
463 # This is from sun4's. Do it for all machines for now.
464 # The "\\1" is to try to preserve a "\n" but only if necessary.
465 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
466 # It might be tempting to get carried away and delete blank lines, etc.
467 # Just delete *exactly* what we're ask to, and that's it.
468 set text [prune_warnings_extra $text]
471 } elseif { [info procs saved-prune_warnings] == [list] } {
472 rename prune_warnings saved-prune_warnings
473 proc prune_warnings { text } {
474 set text [saved-prune_warnings $text]
475 set text [prune_warnings_extra $text]
480 # run_dump_test FILE (optional:) EXTRA_OPTIONS
482 # Assemble a .s file, then run some utility on it and check the output.
484 # There should be an assembly language file named FILE.s in the test
485 # suite directory, and a pattern file called FILE.d. run_dump_test
486 # will assemble FILE.s, optionally run objcopy on the object file,
487 # optionally run ld, optionally run another objcopy, optionally run
488 # another tool under test specified by PROG, then run a dump tool like
489 # addr2line, nm, objdump, readelf or size on the object file to produce
490 # textual output, and then analyze that with regexps.
491 # The FILE.d file specifies what program to run, and what to expect in
494 # The FILE.d file begins with zero or more option lines, which specify
495 # flags to pass to the assembler, the program to run to dump the
496 # assembler's output, and the options it wants. The option lines have
501 # OPTION is the name of some option, like "name" or "objdump", and
502 # VALUE is OPTION's value. The valid options are described below.
503 # Whitespace is ignored everywhere, except within VALUE. The option
504 # list ends with the first line that doesn't match the above syntax.
505 # However, a line within the options that begins with a #, but doesn't
506 # have a recognizable option name followed by a colon, is considered a
507 # comment and entirely ignored.
509 # The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of
510 # two-element lists. The first element of each is an option name, and
511 # the second additional arguments to be added on to the end of the
512 # option list as given in FILE.d. (If omitted, no additional options
515 # The interesting options are:
518 # The name of this test, passed to DejaGNU's `pass' and `fail'
519 # commands. If omitted, this defaults to FILE, the root of the
520 # .s and .d files' names.
523 # When assembling, pass FLAGS to the assembler.
524 # If assembling several files, you can pass different assembler
525 # options in the "source" directives. See below.
528 # Link assembled files using FLAGS, in the order of the "source"
529 # directives, when using multiple files.
531 # ld_after_inputfiles: FLAGS
532 # Similar to "ld", but put FLAGS after all input files.
534 # objcopy_objects: FLAGS
535 # Run objcopy with the specified flags after assembling any source
536 # that has the special marker RUN_OBJCOPY in the source specific
539 # objcopy_linked_file: FLAGS
540 # Run objcopy on the linked file with the specified flags.
541 # This lets you transform the linked file using objcopy, before the
542 # result is analyzed by an analyzer program specified below.
545 # The name of a program under test, to run to modify or analyze the
546 # .o file produced by the assembler. Recognised names are: ar,
547 # elfedit, nm, objcopy, ranlib, strings, and strip.
549 # DUMPPROG: PROGRAM-NAME
550 # The name of the program to run to analyze the file produced
551 # by the assembler or the linker. This can be omitted;
552 # run_dump_test will guess which program to run from which of
553 # the flags options below is present.
560 # Use the specified program to analyze the output file, and pass it
561 # FLAGS, in addition to the output name. Note that they are run
562 # with LC_ALL=C in the environment to give consistent sorting of
563 # symbols. If no FLAGS are needed then you can use:
564 # DUMPPROG: [nm objdump readelf addr2line]
565 # instead, or just pass a flag that happens to be the default.
566 # If objdump is the dump tool and we're not dumping binary, nor
567 # have run ld, then the standard section names (.text, .data and
568 # .bss) are replaced by target ones if any (eg. rx-elf uses "P"
569 # instead of .text). The substition is done for both the
570 # objdump options (eg: "-j .text" is replaced by "-j P") and the
573 # source: SOURCE [FLAGS]
574 # Assemble the file SOURCE.s using the flags in the "as" directive
575 # and the (optional) FLAGS. If omitted, the source defaults to
577 # This is useful if several .d files want to share a .s file.
578 # More than one "source" directive can be given, which is useful
579 # when testing linking.
582 # Match against DUMP.d. If omitted, this defaults to FILE.d. This
583 # is useful if several .d files differ by options only. Options are
584 # always read from FILE.d.
586 # target: GLOB|PROC ...
587 # Run this test only on a specified list of targets. More precisely,
588 # in the space-separated list each glob is passed to "istarget" and
589 # each proc is called as a TCL procedure. List items are interpreted
590 # such that procs are denoted by surrounding square brackets, and any
591 # other items are consired globs. If the call evaluates true for any
592 # of them, the test will be run, otherwise it will be marked
595 # notarget: GLOB|PROC ...
596 # Do not run this test on a specified list of targets. Again, each
597 # glob in the space-separated list is passed to "istarget" and each
598 # proc is called as a TCL procedure, and the test is run if it
599 # evaluates *false* for *all* of them. Otherwise it will be marked
602 # alltargets: GLOB|PROC ...
603 # Run this test on a specified list of targets. Again, each
604 # glob in the space-separated list is passed to "istarget" and each
605 # proc is called as a TCL procedure, and the test is run if it
606 # evaluates *true* for *all* of them. Otherwise it will be marked
609 # skip: GLOB|PROC ...
610 # anyskip: GLOB|PROC ...
611 # noskip: GLOB|PROC ...
612 # These are exactly the same as "notarget", "alltargets" and
613 # "target" respectively, except that they do nothing at all if the
614 # check fails. They should only be used in groups, to construct a
615 # single test which is run on all targets but with variant options
616 # or expected output on some targets. (For example, see
617 # gas/arm/inst.d and gas/arm/wince_inst.d.)
619 # xfail: GLOB|PROC ...
620 # Run this test and it is is expected to fail on a specified list
624 # An error with message matching REGEX must be emitted for the test
625 # to pass. The DUMPPROG, addr2line, nm, objdump, readelf and size
626 # options have no meaning and need not supplied if this is present.
627 # Multiple "error" directives append to the expected error message.
630 # Means the same as 'error', except the regular expression lines
631 # are contains in FILE.
634 # Expect a warning matching REGEX. It is an error to issue
635 # both "error" and "warning". Multiple "warning" directives
636 # append to the expected warning message.
638 # warning_output: FILE
639 # Means the same as 'warning', except the regular expression
640 # lines are contains in FILE.
643 # Adding this option will cause the linker to generate a linker
644 # map file, using the -Map=MAPFILE command line option. If
645 # there is no -Map=MAPFILE in the 'ld: FLAGS' then one will be
646 # added to the linker command line. The contents of the
647 # generated MAPFILE are then compared against the regexp lines
648 # in FILE using `regexp_diff' (see below for details).
651 # Means that the section substitution for objdump is disabled.
653 # Each option may occur at most once unless otherwise mentioned.
655 # After the option lines come regexp lines. run_dump_test calls
656 # regexp_diff to compare the output of the dumping tool against the
659 proc run_dump_test { name {extra_options {}} } {
660 global ADDR2LINE ADDR2LINEFLAGS AS ASFLAGS ELFEDIT ELFEDITFLAGS LD LDFLAGS
661 global NM NMFLAGS OBJCOPY OBJCOPYFLAGS OBJDUMP OBJDUMPFLAGS
662 global READELF READELFFLAGS STRIP STRIPFLAGS
663 global copyfile env ld_elf_shared_opt runtests srcdir subdir verbose
665 if [string match "*/*" $name] {
667 set name [file tail $name]
669 set file "$srcdir/$subdir/$name"
672 if ![runtest_file_p $runtests $name] then {
676 set opt_array [slurp_options "${file}.d"]
677 if { $opt_array == -1 } {
678 perror "error reading options from $file.d"
679 unresolved $subdir/$name
682 set dumpfile tmpdir/dump.out
687 set opts(DUMPPROG) {}
688 set opts(addr2line) {}
689 set opts(alltargets) {}
696 set opts(error_output) {}
698 set opts(ld_after_inputfiles) {}
703 set opts(notarget) {}
705 set opts(objcopy_linked_file) {}
706 set opts(objcopy_objects) {}
710 set opts(section_subst) {}
719 set opts(warning_output) {}
723 foreach i [concat $opt_array {{} {}} $extra_options] {
724 set opt_name [lindex $i 0]
725 set opt_val [lindex $i 1]
726 if { $opt_name == "" } {
730 if ![info exists opts($opt_name)] {
731 perror "unknown option $opt_name in file $file.d"
732 unresolved $subdir/$name
736 # Allow more substitutions, including tcl functions, for as and ld.
737 # Not done in general because extra quoting is needed for glob
738 # args used for example in binutils-all/remove-relocs-04.d.
739 if { $opt_name == "as" || $opt_name == "ld" } {
740 set opt_val [subst $opt_val]
742 # Just substitute $srcdir and $subdir
743 regsub -all {\$srcdir} "$opt_val" "$srcdir" opt_val
744 regsub -all {\$subdir} "$opt_val" "$subdir" opt_val
747 switch -- $opt_name {
758 # Move any source-specific as-flags to a separate list to
759 # simplify processing.
760 if { [llength $opt_val] > 1 } {
761 lappend asflags [lrange $opt_val 1 end]
762 set opt_val [lindex $opt_val 0]
767 # Create the object file name based on nothing but the source
770 [concat tmpdir/[file rootname [file tail [lindex $opt_val 0]]].o]
771 # But, sometimes, we have the exact same source filename in
772 # different directories (foo/src.s bar/src.s) which would lead
773 # us to try and create two src.o files. We detect this
774 # conflict here, and instead create src.o and src1.o.
776 while { [lsearch $objfile_names $new_objfile] != -1 } {
779 [concat tmpdir/[file rootname [file tail [lindex $opt_val 0]]]${j}.o]
781 lappend objfile_names $new_objfile
784 if { !$in_extra && [string length $opts($opt_name)] } {
785 perror "option $opt_name multiply set in $file.d"
786 unresolved $subdir/$name
790 # A single "#ld:" with no options should do the right thing.
791 if { $opt_name == "ld" } {
794 # Likewise objcopy_linked_file.
795 if { $opt_name == "objcopy_linked_file" } {
801 # Append differently whether it's a message (without space) or
802 # an option or list (with space).
803 switch -- $opt_name {
806 append opts($opt_name) $opt_val
809 set opts($opt_name) [concat $opts($opt_name) $opt_val]
814 foreach opt { as ld } {
815 regsub {\[big_or_little_endian\]} $opts($opt) \
816 [big_or_little_endian] opts($opt)
819 if { $opts(name) == "" } {
820 set testname "$subdir/$name"
822 set testname $opts(name)
826 foreach opt { warning error warning_output error_output } {
827 if { $opts($opt) != "" } {
829 perror "$testname: bad mix of warning and error test directives"
837 # Decide early whether we should run the test for this target.
838 if { [llength $opts(noskip)] > 0 } {
840 foreach targ $opts(noskip) {
841 if [match_target $targ] {
846 if { $targmatch == 0 } {
850 foreach targ $opts(anyskip) {
851 if ![match_target $targ] {
855 foreach targ $opts(skip) {
856 if [match_target $targ] {
860 if { [llength $opts(target)] > 0 } {
862 foreach targ $opts(target) {
863 if [match_target $targ] {
868 if { $targmatch == 0 } {
869 unsupported $testname
873 foreach targ $opts(alltargets) {
874 if ![match_target $targ] {
875 unsupported $testname
879 foreach targ $opts(notarget) {
880 if [match_target $targ] {
881 unsupported $testname
887 # It's meaningless to require an output-testing method when we
889 if { $opts(error) == "" && $opts(error_output) == "" } {
890 if { $opts(DUMPPROG) != "" } {
891 switch -- $opts(DUMPPROG) {
892 addr2line { set dumpprogram addr2line }
893 nm { set dumpprogram nm }
894 objdump { set dumpprogram objdump }
895 readelf { set dumpprogram readelf }
896 size { set dumpprogram size }
898 perror "unrecognized DUMPPROG option $opts(DUMPPROG) in $file.d"
904 # Guess which program to run, by seeing which option was specified.
905 foreach p {addr2line nm objdump readelf size} {
906 if {$opts($p) != ""} {
907 if {$dumpprogram != ""} {
908 perror "ambiguous dump program in $file.d"
917 if { $dumpprogram == "" && $opts(map) == "" && !$err_warn } {
918 perror "dump program unspecified in $file.d"
924 if { $opts(source) == "" } {
925 set sourcefiles [list ${file}.s]
926 set asflags [list ""]
927 set objfile_names [list tmpdir/[file tail ${file}].o]
930 foreach sf $opts(source) {
931 if { [string match "/*" $sf] } {
932 lappend sourcefiles "$sf"
934 lappend sourcefiles "$srcdir/$subdir/$sf"
939 if { $opts(dump) == "" } {
942 set dfile $srcdir/$subdir/$opts(dump)
945 # Time to setup xfailures.
946 foreach targ $opts(xfail) {
950 # Assemble each file.
952 for { set i 0 } { $i < [llength $sourcefiles] } { incr i } {
953 set sourcefile [lindex $sourcefiles $i]
954 set sourceasflags [lindex $asflags $i]
955 set run_objcopy_objects 0
957 if { [string match "*RUN_OBJCOPY*" $sourceasflags] } {
958 set run_objcopy_objects 1
960 regsub "RUN_OBJCOPY" $sourceasflags "" sourceasflags
962 set objfile [lindex $objfile_names $i]
963 catch "exec rm -f $objfile" exec_output
964 lappend objfiles $objfile
966 if { $opts(as) == "binary" } {
967 while {[file type $sourcefile] eq "link"} {
968 set newfile [file readlink $sourcefile]
969 if {[string index $newfile 0] ne "/"} {
970 set newfile [file dirname $sourcefile]/$newfile
972 set sourcefile $newfile
974 set newfile [remote_download host $sourcefile $objfile]
976 if { $newfile == "" } {
980 if { [istarget "hppa*-*-*"] \
981 && ![istarget "*-*-linux*"] \
982 && ![istarget "*-*-netbsd*" ] } {
983 set cmd "sed -e 's/^\[ \]*\.comm \\(\[^,\]*\\),\\(.*\\)/\\1 .comm \\2/' < $sourcefile > tmpdir/asm.s"
985 set cmdret [remote_exec host [concat sh -c [list "$cmd"]]]
986 set cmdret [lindex $cmdret 0]
987 if { $cmdret != 0 } {
992 set sourcefile tmpdir/asm.s
994 set cmd "$AS $ASFLAGS $opts(as) $sourceasflags -o $objfile $sourcefile"
997 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "dump.tmp"]
998 remote_upload host "dump.tmp"
999 set comp_output [prune_warnings [file_contents "dump.tmp"]]
1000 remote_file host delete "dump.tmp"
1001 remote_file build delete "dump.tmp"
1002 set cmdret [lindex $cmdret 0]
1004 if { $cmdret == 0 && $run_objcopy_objects } {
1005 set cmd "$OBJCOPY $opts(objcopy_objects) $objfile"
1008 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] \
1009 "" "/dev/null" "dump.tmp"]
1010 remote_upload host "dump.tmp"
1011 append comp_output [prune_warnings [file_contents "dump.tmp"]]
1012 remote_file host delete "dump.tmp"
1013 remote_file build delete "dump.tmp"
1014 set cmdret [lindex $cmdret 0]
1018 # Perhaps link the file(s).
1019 if { $cmdret == 0 && $run_ld } {
1020 set objfile "tmpdir/dump"
1021 catch "exec rm -f $objfile" exec_output
1026 if { [is_elf_format] && [check_shared_lib_support] } {
1027 set ld_extra_opt "$ld_elf_shared_opt"
1030 # Add -L$srcdir/$subdir so that the linker command can use
1031 # linker scripts in the source directory.
1032 set cmd "$LD $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
1033 $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
1035 # If needed then check for, or add a -Map option.
1037 if { $opts(map) != "" } then {
1038 if { [regexp -- "-Map=(\[^ \]+)" $cmd all mapfile] } then {
1039 # Found existing mapfile option
1040 verbose -log "Existing mapfile '$mapfile' found"
1042 # No mapfile option.
1043 set mapfile "tmpdir/dump.map"
1044 verbose -log "Adding mapfile '$mapfile'"
1045 set cmd "$cmd -Map=$mapfile"
1050 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "dump.tmp"]
1051 remote_upload host "dump.tmp"
1052 append comp_output [file_contents "dump.tmp"]
1053 remote_file host delete "dump.tmp"
1054 remote_file build delete "dump.tmp"
1055 set cmdret [lindex $cmdret 0]
1057 if { $cmdret == 0 && $run_objcopy } {
1059 set objfile "tmpdir/dump1"
1060 remote_file host delete $objfile
1062 # Note that we don't use OBJCOPYFLAGS here; any flags must be
1063 # explicitly specified.
1064 set cmd "$OBJCOPY $opts(objcopy_linked_file) $infile $objfile"
1067 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "dump.tmp"]
1068 remote_upload host "dump.tmp"
1069 append comp_output [file_contents "dump.tmp"]
1070 remote_file host delete "dump.tmp"
1071 remote_file build delete "dump.tmp"
1072 set cmdret [lindex $cmdret 0]
1075 set objfile [lindex $objfiles 0]
1078 if { $cmdret == 0 && $opts(PROG) != "" } {
1079 set destopt ${copyfile}.o
1080 switch -- $opts(PROG) {
1081 ar { set program ar }
1086 nm { set program nm }
1087 objcopy { set program objcopy }
1088 ranlib { set program ranlib }
1089 strings { set program strings }
1092 set destopt "-o $destopt"
1095 perror "unrecognized PROG option $opts(PROG) in $file.d"
1096 unresolved $testname
1101 set progopts1 $opts($program)
1102 eval set progopts \$[string toupper $program]FLAGS
1103 eval set binary \$[string toupper $program]
1105 if { ![is_remote host] && [which $binary] == 0 } {
1110 verbose "running $binary $progopts $progopts1" 3
1111 set cmd "$binary $progopts $progopts1 $objfile $destopt"
1113 # Ensure consistent sorting of symbols
1114 if {[info exists env(LC_ALL)]} {
1115 set old_lc_all $env(LC_ALL)
1119 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>dump.tmp"]] "" "/dev/null"]
1120 set cmdret [lindex $cmdret 0]
1121 remote_upload host "dump.tmp"
1122 append comp_output [prune_warnings [file_contents "dump.tmp"]]
1123 remote_file host delete "dump.tmp"
1124 remote_file build delete "dump.tmp"
1125 if {[info exists old_lc_all]} {
1126 set env(LC_ALL) $old_lc_all
1130 if { $destopt != "" } {
1131 set objfile ${copyfile}.o
1135 set want_out(source) ""
1136 set want_out(terminal) 0
1138 if { $opts(error) != "" || $opts(error_output) != "" } {
1139 set want_out(terminal) 1
1142 if { $opts(error) != "" || $opts(warning) != "" } {
1143 set want_out(source) "regex"
1144 if { $opts(error) != "" } {
1145 set want_out(regex) $opts(error)
1147 set want_out(regex) $opts(warning)
1150 set want_out(source) "file"
1151 if { $opts(error_output) != "" } {
1152 set want_out(file) $opts(error_output)
1154 set want_out(file) $opts(warning_output)
1159 regsub "\n$" $comp_output "" comp_output
1160 if { $cmdret != 0 || $comp_output != "" || $want_out(source) != "" } {
1161 set exitstat "succeeded"
1162 if { $cmdret != 0 } { set exitstat "failed" }
1164 if { $want_out(source) == "regex" } {
1165 verbose -log "$exitstat with: <$comp_output>, expected: <$want_out(regex)>"
1166 } elseif { $want_out(source) == "file" } {
1167 verbose -log "$exitstat with: <$comp_output>, expected in file $want_out(file)"
1168 set_file_contents "tmpdir/ld.messages" "$comp_output"
1170 verbose -log "$exitstat with: <$comp_output>, no expected output"
1173 if { (($want_out(source) == "") == ($comp_output == "")) \
1174 && (($cmdret == 0) == ($want_out(terminal) == 0)) \
1175 && ((($want_out(source) == "regex") \
1176 && [regexp -- $want_out(regex) $comp_output]) \
1177 || (($want_out(source) == "file") \
1178 && (![regexp_diff "tmpdir/ld.messages" "$srcdir/$subdir/$want_out(file)"]))) } {
1179 # We have the expected output.
1180 if { $want_out(terminal) || $dumpprogram == "" } {
1190 # We must not have expected failure if we get here.
1191 if { $opts(error) != "" } {
1196 if { $opts(map) != "" } then {
1197 # Check the map file matches.
1198 set map_pattern_file $srcdir/$subdir/$opts(map)
1199 verbose -log "Compare '$mapfile' against '$map_pattern_file'"
1200 if { [regexp_diff $mapfile $map_pattern_file] } then {
1201 fail "$testname (map file check)"
1203 pass "$testname (map file check)"
1206 if { $dumpprogram == "" } then {
1211 set progopts1 $opts($dumpprogram)
1212 eval set progopts \$[string toupper $dumpprogram]FLAGS
1213 eval set binary \$[string toupper $dumpprogram]
1215 if { ![is_remote host] && [which $binary] == 0 } {
1220 # For objdump of gas output, automatically translate standard section names
1222 if { !$run_ld && $dumpprogram == "objdump" \
1223 && $opts(section_subst) != "no" \
1224 && ![string match "*-b binary*" $progopts1] } {
1225 set sect_names [get_standard_section_names]
1226 if { $sect_names != ""} {
1227 regsub -- "\\.text" $progopts1 "[lindex $sect_names 0]" progopts1
1228 regsub -- "\\.data" $progopts1 "[lindex $sect_names 1]" progopts1
1229 regsub -- "\\.bss" $progopts1 "[lindex $sect_names 2]" progopts1
1233 if { $progopts1 == "" } { set $progopts1 "-r" }
1234 verbose "running $binary $progopts $progopts1" 3
1236 set cmd "$binary $progopts $progopts1 $objfile > $dumpfile"
1238 # Ensure consistent sorting of symbols
1239 if {[info exists env(LC_ALL)]} {
1240 set old_lc_all $env(LC_ALL)
1244 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>dump.tmp"]] "" "/dev/null"]
1245 set cmdret [lindex $cmdret 0]
1246 remote_upload host "dump.tmp"
1247 set comp_output [prune_warnings [file_contents "dump.tmp"]]
1248 remote_file host delete "dump.tmp"
1249 remote_file build delete "dump.tmp"
1250 if {[info exists old_lc_all]} {
1251 set env(LC_ALL) $old_lc_all
1255 if { $cmdret != 0 || $comp_output != "" } {
1256 send_log "exited abnormally with $cmdret, output:$comp_output\n"
1261 if { $verbose > 2 } then { verbose "output is [file_contents $dumpfile]" 3 }
1263 # Create the substition list for objdump output.
1265 if { $sect_names != "" } {
1266 set regexp_subst [list "\\\\?\\.text" [lindex $sect_names 0] \
1267 "\\\\?\\.data" [lindex $sect_names 1] \
1268 "\\\\?\\.bss" [lindex $sect_names 2] ]
1271 if { [regexp_diff $dumpfile "${dfile}" $regexp_subst] } then {
1273 if { $verbose == 2 } then { verbose "output is [file_contents $dumpfile]" 2 }
1280 proc slurp_options { file } {
1281 # If options_regsub(foo) is set to {a b}, then the contents of a
1282 # "#foo:" line will have regsub -all applied to replace a with b.
1283 global options_regsub
1285 if [catch { set f [open $file r] } x] {
1286 #perror "couldn't open `$file': $x"
1291 # whitespace expression
1294 # whitespace is ignored anywhere except within the options list;
1295 # option names are alphanumeric plus underscore.
1296 set pat "^#${ws}(\[a-zA-Z0-9_\]*)$ws:${ws}(.*)$ws\$"
1297 while { [gets $f line] != -1 } {
1298 set line [string trim $line]
1299 # Whitespace here is space-tab.
1300 if [regexp $pat $line xxx opt_name opt_val] {
1302 if [info exists options_regsub($opt_name)] {
1303 set subst $options_regsub($opt_name)
1304 regsub -all -- [lindex $subst 0] $opt_val [lindex $subst 1] \
1307 lappend opt_array [list $opt_name $opt_val]
1308 } elseif {![regexp "^#" $line ]} {
1316 proc file_contents { filename } {
1317 set file [open $filename r]
1318 set contents [read $file]
1323 proc set_file_contents { filename contents } {
1324 set file [open $filename w]
1325 puts $file "$contents"
1329 # Look for big-endian or little-endian switches in the multlib
1330 # options and translate these into a -EB or -EL switch. Note
1331 # we cannot rely upon proc process_multilib_options to do this
1332 # for us because for some targets the compiler does not support
1333 # -EB/-EL but it does support -mbig-endian/-mlittle-endian, and
1334 # the site.exp file will include the switch "-mbig-endian"
1335 # (rather than "big-endian") which is not detected by proc
1336 # process_multilib_options.
1338 proc big_or_little_endian {} {
1340 if [board_info [target_info name] exists multilib_flags] {
1341 set tmp_flags " [board_info [target_info name] multilib_flags]"
1343 foreach x $tmp_flags {
1345 {*big*endian eb EB -eb -EB -mb -meb} {
1349 {*little*endian el EL -el -EL -ml -mel} {
1361 # Internal procedure: return the names of the standard sections
1363 proc get_standard_section_names {} {
1364 if [istarget "rx-*-elf"] {
1365 return { "P" "D_1" "B_1" }
1367 if { [istarget "alpha*-*-*vms*"] || [is_som_format] } {
1368 return { {\$CODE\$} {\$DATA\$} {\$BSS\$} }