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