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