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