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