* lib/ld-lib.exp (check_shared_lib_support): Also exclude
[deliverable/binutils-gdb.git] / ld / testsuite / lib / ld-lib.exp
1 # Support routines for LD testsuite.
2 # Copyright 1994-2013 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This file is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20
21 proc load_common_lib { name } {
22 global srcdir
23 load_file $srcdir/../../binutils/testsuite/lib/$name
24 }
25
26 load_common_lib binutils-common.exp
27
28 # Returns 1 if the gcc for the target is at least version MAJOR.MINOR
29 # Returns 0 otherwise.
30 #
31 proc at_least_gcc_version { major minor } {
32
33 if {![info exists CC]} {
34 set CC [find_gcc]
35 }
36 if { $CC == "" } {
37 return 0
38 }
39 set state [remote_exec host $CC --version]
40 set tmp "[lindex $state 1]\n"
41 # Look for (eg) 4.6.1 in the version output.
42 set ver_re "\[^\\.0-9\]+(\[1-9\]\[0-9\]*)\\.(\[0-9\]+)(?:\\.\[0-9\]+)?"
43 regexp $ver_re $tmp fred maj min
44 verbose "gcc version: $tmp"
45 if { ![info exists maj] || ![info exists min] } then {
46 perror "can't decipher gcc version number, fix the framework!"
47 return 0
48 }
49 verbose "major gcc version is $maj, want at least $major"
50 if { $maj == $major } then {
51 verbose "minor gcc version is $min, want at least $minor"
52 return [expr $min >= $minor]
53 } else {
54 return [expr $maj > $major]
55 }
56 }
57
58 # Extract and print the version number of ld.
59 #
60 proc default_ld_version { ld } {
61 global host_triplet
62
63 if { ![is_remote host] && [which $ld] == 0 } then {
64 perror "$ld does not exist"
65 exit 1
66 }
67
68 remote_exec host "$ld --version" "" "/dev/null" "ld.version"
69 remote_upload host "ld.version"
70 set tmp [prune_warnings [file_contents "ld.version"]]
71 remote_file build delete "ld.version"
72 remote_file host delete "ld.version"
73
74 regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" $tmp version cyg number
75 if [info exists number] then {
76 clone_output "$ld $number\n"
77 }
78 }
79
80 proc run_host_cmd { prog command } {
81 global link_output
82
83 if { ![is_remote host] && [which "$prog"] == 0 } then {
84 perror "$prog does not exist"
85 return 0
86 }
87
88 verbose -log "$prog $command"
89 set status [remote_exec host [concat sh -c [list "$prog $command 2>&1"]] "" "/dev/null" "ld.tmp"]
90 remote_upload host "ld.tmp"
91 set link_output [file_contents "ld.tmp"]
92 regsub "\n$" $link_output "" link_output
93 if { [lindex $status 0] != 0 && [string match "" $link_output] } then {
94 append link_output "child process exited abnormally"
95 }
96 remote_file build delete ld.tmp
97 remote_file host delete ld.tmp
98
99 if [string match "" $link_output] then {
100 return ""
101 }
102
103 verbose -log "$link_output"
104 return "$link_output"
105 }
106
107 proc run_host_cmd_yesno { prog command } {
108 global exec_output
109
110 set exec_output [prune_warnings [run_host_cmd "$prog" "$command"]]
111 if [string match "" $exec_output] then {
112 return 1;
113 }
114 return 0;
115 }
116
117 # Link an object using relocation.
118 #
119 proc default_ld_relocate { ld target objects } {
120 global HOSTING_EMU
121
122 remote_file host delete $target
123 return [run_host_cmd_yesno "$ld" "$HOSTING_EMU -o $target -r $objects"]
124 }
125
126 # Check to see if ld is being invoked with a non-endian output format
127 #
128 proc is_endian_output_format { object_flags } {
129
130 if {[string match "*-oformat binary*" $object_flags] || \
131 [string match "*-oformat ieee*" $object_flags] || \
132 [string match "*-oformat ihex*" $object_flags] || \
133 [string match "*-oformat netbsd-core*" $object_flags] || \
134 [string match "*-oformat srec*" $object_flags] || \
135 [string match "*-oformat tekhex*" $object_flags] || \
136 [string match "*-oformat trad-core*" $object_flags] } then {
137 return 0
138 } else {
139 return 1
140 }
141 }
142
143 # Look for big-endian or little-endian switches in the multlib
144 # options and translate these into a -EB or -EL switch. Note
145 # we cannot rely upon proc process_multilib_options to do this
146 # for us because for some targets the compiler does not support
147 # -EB/-EL but it does support -mbig-endian/-mlittle-endian, and
148 # the site.exp file will include the switch "-mbig-endian"
149 # (rather than "big-endian") which is not detected by proc
150 # process_multilib_options.
151 #
152 proc big_or_little_endian {} {
153
154 if [board_info [target_info name] exists multilib_flags] {
155 set tmp_flags " [board_info [target_info name] multilib_flags]"
156
157 foreach x $tmp_flags {
158 case $x in {
159 {*big*endian eb EB -eb -EB -mb -meb} {
160 set flags " -EB"
161 return $flags
162 }
163 {*little*endian el EL -el -EL -ml -mel} {
164 set flags " -EL"
165 return $flags
166 }
167 }
168 }
169 }
170
171 set flags ""
172 return $flags
173 }
174
175 # Link a program using ld.
176 #
177 proc default_ld_link { ld target objects } {
178 global HOSTING_EMU
179 global HOSTING_CRT0
180 global HOSTING_SCRT0
181 global HOSTING_LIBS
182 global LIBS
183 global host_triplet
184 global link_output
185 global exec_output
186
187 if { [ string match "* -pie *" $objects ] } {
188 set objs "$HOSTING_SCRT0 $objects"
189 } else {
190 set objs "$HOSTING_CRT0 $objects"
191 }
192 set libs "$LIBS $HOSTING_LIBS"
193
194 if [is_endian_output_format $objects] then {
195 set flags [big_or_little_endian]
196 } else {
197 set flags ""
198 }
199
200 remote_file host delete $target
201
202 return [run_host_cmd_yesno "$ld" "$HOSTING_EMU $flags -o $target $objs $libs"]
203 }
204
205 # Link a program using ld, without including any libraries.
206 #
207 proc default_ld_simple_link { ld target objects } {
208 global host_triplet
209 global gcc_ld_flag
210 global exec_output
211
212 if [is_endian_output_format $objects] then {
213 set flags [big_or_little_endian]
214 } else {
215 set flags ""
216 }
217
218 # If we are compiling with gcc, we want to add gcc_ld_flag to
219 # flags. Rather than determine this in some complex way, we guess
220 # based on the name of the compiler.
221 set ldexe $ld
222 set ldparm [string first " " $ld]
223 set ldflags ""
224 if { $ldparm > 0 } then {
225 set ldflags [string range $ld $ldparm end]
226 set ldexe [string range $ld 0 $ldparm]
227 set ld $ldexe
228 }
229 set ldexe [string replace $ldexe 0 [string last "/" $ldexe] ""]
230 if {[string match "*gcc*" $ldexe] || [string match "*++*" $ldexe]} then {
231 set ldflags "$gcc_ld_flag $ldflags"
232 }
233
234 remote_file host delete $target
235
236 set exec_output [run_host_cmd "$ld" "$ldflags $flags -o $target $objects"]
237 set exec_output [prune_warnings $exec_output]
238
239 # We don't care if we get a warning about a non-existent start
240 # symbol, since the default linker script might use ENTRY.
241 regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
242
243 if [string match "" $exec_output] then {
244 return 1
245 } else {
246 return 0
247 }
248 }
249
250 # Compile an object using cc.
251 #
252 proc default_ld_compile { cc source object } {
253 global CFLAGS
254 global CXXFLAGS
255 global srcdir
256 global subdir
257 global host_triplet
258 global gcc_gas_flag
259
260 set cc_prog $cc
261 if {[llength $cc_prog] > 1} then {
262 set cc_prog [lindex $cc_prog 0]
263 }
264 if {![is_remote host] && [which $cc_prog] == 0} then {
265 perror "$cc_prog does not exist"
266 return 0
267 }
268
269 remote_file build delete "$object"
270 remote_file host delete "$object"
271
272 set flags "-I$srcdir/$subdir"
273
274 # If we are compiling with gcc, we want to add gcc_gas_flag to
275 # flags. Rather than determine this in some complex way, we guess
276 # based on the name of the compiler.
277 set ccexe $cc
278 set ccparm [string first " " $cc]
279 set ccflags ""
280 if { $ccparm > 0 } then {
281 set ccflags [string range $cc $ccparm end]
282 set ccexe [string range $cc 0 $ccparm]
283 set cc $ccexe
284 }
285 set ccexe [string replace $ccexe 0 [string last "/" $ccexe] ""]
286 if {[string match "*gcc*" $ccexe] || [string match "*++*" $ccexe]} then {
287 set flags "$gcc_gas_flag $flags"
288 }
289
290 if {[string match "*++*" $ccexe]} {
291 set flags "$flags $CXXFLAGS"
292 } else {
293 set flags "$flags $CFLAGS"
294 }
295
296 if [board_info [target_info name] exists multilib_flags] {
297 append flags " [board_info [target_info name] multilib_flags]"
298 }
299
300 verbose -log "$cc $flags $ccflags -c $source -o $object"
301
302 set status [remote_exec host [concat sh -c [list "$cc $flags $ccflags -c $source -o $object 2>&1"]] "" "/dev/null" "ld.tmp"]
303 remote_upload host "ld.tmp"
304 set exec_output [file_contents "ld.tmp"]
305 remote_file build delete "ld.tmp"
306 remote_file host delete "ld.tmp"
307 set exec_output [prune_warnings $exec_output]
308 if [string match "" $exec_output] then {
309 if {![file exists $object]} then {
310 regexp ".*/(\[^/\]*)$" $source all dobj
311 regsub "\\.c" $dobj ".o" realobj
312 verbose "looking for $realobj"
313 if {[remote_file host exists $realobj]} then {
314 verbose -log "mv $realobj $object"
315 remote_upload "$realobj" "$object"
316 } else {
317 perror "$object not found after compilation"
318 return 0
319 }
320 }
321 return 1
322 } else {
323 verbose -log "$exec_output"
324 perror "$source: compilation failed"
325 return 0
326 }
327 }
328
329 # Assemble a file.
330 #
331 proc default_ld_assemble { as in_flags source object } {
332 global ASFLAGS
333 global host_triplet
334
335 if ![info exists ASFLAGS] { set ASFLAGS "" }
336
337 set flags [big_or_little_endian]
338 set exec_output [run_host_cmd "$as" "$flags $in_flags $ASFLAGS -o $object $source"]
339 set exec_output [prune_warnings $exec_output]
340 if [string match "" $exec_output] then {
341 return 1
342 } else {
343 perror "$source: assembly failed"
344 return 0
345 }
346 }
347
348 # Run nm on a file, putting the result in the array nm_output.
349 #
350 proc default_ld_nm { nm nmflags object } {
351 global NMFLAGS
352 global nm_output
353 global host_triplet
354
355 if {[info exists nm_output]} {
356 unset nm_output
357 }
358
359 if ![info exists NMFLAGS] { set NMFLAGS "" }
360
361 # Ensure consistent sorting of symbols
362 if {[info exists env(LC_ALL)]} {
363 set old_lc_all $env(LC_ALL)
364 }
365 set env(LC_ALL) "C"
366
367 verbose -log "$nm $NMFLAGS $nmflags $object >tmpdir/nm.out"
368
369 set status [remote_exec host [concat sh -c [list "$nm $NMFLAGS $nmflags $object 2>ld.stderr"]] "" "/dev/null" "tmpdir/nm.out"]
370 if {[info exists old_lc_all]} {
371 set env(LC_ALL) $old_lc_all
372 } else {
373 unset env(LC_ALL)
374 }
375 remote_upload host "ld.stderr"
376 remote_upload host "tmpdir/nm.out" "tmpdir/nm.out"
377 set exec_output [prune_warnings [file_contents "ld.stderr"]]
378 remote_file host delete "ld.stderr"
379 remote_file build delete "ld.stderr"
380 if [string match "" $exec_output] then {
381 set file [open tmpdir/nm.out r]
382 while { [gets $file line] != -1 } {
383 verbose "$line" 2
384 if [regexp "^(\[0-9a-fA-F\]+) \[a-zA-Z0-9\] \\.*(.+)$" $line whole value name] {
385 set name [string trimleft $name "_"]
386 verbose "Setting nm_output($name) to 0x$value" 2
387 set nm_output($name) 0x$value
388 }
389 }
390 close $file
391 return 1
392 } else {
393 verbose -log "$exec_output"
394 perror "$object: nm failed"
395 return 0
396 }
397 }
398
399 # Define various symbols needed when not linking against all
400 # target libs.
401 proc ld_simple_link_defsyms {} {
402
403 set flags "--defsym __stack_chk_fail=0"
404
405 # ARM targets call __gccmain
406 if {[istarget arm*-*-*]} {
407 append flags " --defsym __gccmain=0"
408 }
409
410 # Windows targets need __main, prefixed with underscore.
411 if {[istarget *-*-cygwin* ] || [istarget *-*-mingw*]} {
412 append flags " --defsym ___main=0"
413 }
414
415 # PowerPC EABI code calls __eabi.
416 if {[istarget powerpc*-*-eabi*] || [istarget powerpc*-*-rtems*]} {
417 append flags " --defsym __eabi=0"
418 }
419
420 # mn10200 code calls __truncsipsi2_d0_d2.
421 if {[istarget mn10200*-*-*]} then {
422 append flags " --defsym __truncsipsi2_d0_d2=0"
423 }
424
425 # m6811/m6812 code has references to soft registers.
426 if {[istarget m6811-*-*] || [istarget m6812-*-*] || [istarget m68hc1*-*-*]} {
427 append flags " --defsym _.frame=0 --defsym _.d1=0 --defsym _.d2=0"
428 append flags " --defsym _.d3=0 --defsym _.d4=0"
429 append flags " --defsym _.tmp=0 --defsym _.xy=0 --defsym _.z=0"
430 }
431
432 # Some OpenBSD targets have ProPolice and reference __guard and
433 # __stack_smash_handler.
434 if [istarget *-*-openbsd*] {
435 append flags " --defsym __guard=0"
436 append flags " --defsym __stack_smash_handler=0"
437 }
438
439 return $flags
440 }
441
442 # run_dump_test FILE (optional:) EXTRA_OPTIONS
443 # Copied from gas testsuite, tweaked and further extended.
444 #
445 # Assemble a .s file, then run some utility on it and check the output.
446 #
447 # There should be an assembly language file named FILE.s in the test
448 # suite directory, and a pattern file called FILE.d. `run_dump_test'
449 # will assemble FILE.s, run some tool like `objdump', `objcopy', or
450 # `nm' on the .o file to produce textual output, and then analyze that
451 # with regexps. The FILE.d file specifies what program to run, and
452 # what to expect in its output.
453 #
454 # The FILE.d file begins with zero or more option lines, which specify
455 # flags to pass to the assembler, the program to run to dump the
456 # assembler's output, and the options it wants. The option lines have
457 # the syntax:
458 #
459 # # OPTION: VALUE
460 #
461 # OPTION is the name of some option, like "name" or "objdump", and
462 # VALUE is OPTION's value. The valid options are described below.
463 # Whitespace is ignored everywhere, except within VALUE. The option
464 # list ends with the first line that doesn't match the above syntax
465 # (hmm, not great for error detection).
466 #
467 # The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of
468 # two-element lists. The first element of each is an option name, and
469 # the second additional arguments to be added on to the end of the
470 # option list as given in FILE.d. (If omitted, no additional options
471 # are added.)
472 #
473 # The interesting options are:
474 #
475 # name: TEST-NAME
476 # The name of this test, passed to DejaGNU's `pass' and `fail'
477 # commands. If omitted, this defaults to FILE, the root of the
478 # .s and .d files' names.
479 #
480 # as: FLAGS
481 # When assembling, pass FLAGS to the assembler.
482 # If assembling several files, you can pass different assembler
483 # options in the "source" directives. See below.
484 #
485 # ld: FLAGS
486 # Link assembled files using FLAGS, in the order of the "source"
487 # directives, when using multiple files.
488 #
489 # ld_after_inputfiles: FLAGS
490 # Similar to "ld", but put after all input files.
491 #
492 # objcopy_linked_file: FLAGS
493 # Run objcopy on the linked file with the specified flags.
494 # This lets you transform the linked file using objcopy, before the
495 # result is analyzed by an analyzer program specified below (which
496 # may in turn *also* be objcopy).
497 #
498 # PROG: PROGRAM-NAME
499 # The name of the program to run to analyze the .o file produced
500 # by the assembler or the linker output. This can be omitted;
501 # run_dump_test will guess which program to run by seeing which of
502 # the flags options below is present.
503 #
504 # objdump: FLAGS
505 # nm: FLAGS
506 # objcopy: FLAGS
507 # Use the specified program to analyze the assembler or linker
508 # output file, and pass it FLAGS, in addition to the output name.
509 # Note that they are run with LC_ALL=C in the environment to give
510 # consistent sorting of symbols.
511 #
512 # source: SOURCE [FLAGS]
513 # Assemble the file SOURCE.s using the flags in the "as" directive
514 # and the (optional) FLAGS. If omitted, the source defaults to
515 # FILE.s.
516 # This is useful if several .d files want to share a .s file.
517 # More than one "source" directive can be given, which is useful
518 # when testing linking.
519 #
520 # dump: DUMP
521 # Match against DUMP.d. If omitted, this defaults to FILE.d. This
522 # is useful if several .d files differ by options only. Options are
523 # always read from FILE.d.
524 #
525 # xfail: TARGET
526 # The test is expected to fail on TARGET. This may occur more than
527 # once.
528 #
529 # target: TARGET
530 # Only run the test for TARGET. This may occur more than once; the
531 # target being tested must match at least one. You may provide target
532 # name "cfi" for any target supporting the CFI statements.
533 #
534 # notarget: TARGET
535 # Do not run the test for TARGET. This may occur more than once;
536 # the target being tested must not match any of them.
537 #
538 # error: REGEX
539 # An error with message matching REGEX must be emitted for the test
540 # to pass. The PROG, objdump, nm and objcopy options have no
541 # meaning and need not supplied if this is present. Multiple "error"
542 # directives append to the expected linker error message.
543 #
544 # warning: REGEX
545 # Expect a linker warning matching REGEX. It is an error to issue
546 # both "error" and "warning". Multiple "warning" directives
547 # append to the expected linker warning message.
548 #
549 # Each option may occur at most once unless otherwise mentioned.
550 #
551 # After the option lines come regexp lines. `run_dump_test' calls
552 # `regexp_diff' to compare the output of the dumping tool against the
553 # regexps in FILE.d. `regexp_diff' is defined in binutils-common.exp;
554 # see further comments there.
555 #
556 proc run_dump_test { name {extra_options {}} } {
557 global subdir srcdir
558 global OBJDUMP NM AS OBJCOPY READELF LD
559 global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS LDFLAGS
560 global host_triplet runtests
561 global env verbose
562
563 if [string match "*/*" $name] {
564 set file $name
565 set name [file tail $name]
566 } else {
567 set file "$srcdir/$subdir/$name"
568 }
569
570 if ![runtest_file_p $runtests $name] then {
571 return
572 }
573
574 set opt_array [slurp_options "${file}.d"]
575 if { $opt_array == -1 } {
576 perror "error reading options from $file.d"
577 unresolved $subdir/$name
578 return
579 }
580 set dumpfile tmpdir/dump.out
581 set run_ld 0
582 set run_objcopy 0
583 set opts(as) {}
584 set opts(ld) {}
585 set opts(ld_after_inputfiles) {}
586 set opts(xfail) {}
587 set opts(target) {}
588 set opts(notarget) {}
589 set opts(objdump) {}
590 set opts(nm) {}
591 set opts(objcopy) {}
592 set opts(readelf) {}
593 set opts(name) {}
594 set opts(PROG) {}
595 set opts(source) {}
596 set opts(dump) {}
597 set opts(error) {}
598 set opts(warning) {}
599 set opts(objcopy_linked_file) {}
600
601 foreach i $opt_array {
602 set opt_name [lindex $i 0]
603 set opt_val [lindex $i 1]
604 if ![info exists opts($opt_name)] {
605 perror "unknown option $opt_name in file $file.d"
606 unresolved $subdir/$name
607 return
608 }
609
610 switch -- $opt_name {
611 xfail {}
612 target {}
613 notarget {}
614 warning {}
615 error {}
616 source {
617 # Move any source-specific as-flags to a separate list to
618 # simplify processing.
619 if { [llength $opt_val] > 1 } {
620 lappend asflags [lrange $opt_val 1 end]
621 set opt_val [lindex $opt_val 0]
622 } else {
623 lappend asflags {}
624 }
625 }
626 default {
627 if [string length $opts($opt_name)] {
628 perror "option $opt_name multiply set in $file.d"
629 unresolved $subdir/$name
630 return
631 }
632
633 # A single "# ld:" with no options should do the right thing.
634 if { $opt_name == "ld" } {
635 set run_ld 1
636 }
637 # Likewise objcopy_linked_file.
638 if { $opt_name == "objcopy_linked_file" } {
639 set run_objcopy 1
640 }
641 }
642 }
643 if { $opt_name == "as" || $opt_name == "ld" } {
644 set opt_val [subst $opt_val]
645 }
646
647 # Append differently whether it's a message (without space) or
648 # an option or list (with space).
649 switch -- $opt_name {
650 warning -
651 error {
652 append opts($opt_name) $opt_val
653 }
654 default {
655 set opts($opt_name) [concat $opts($opt_name) $opt_val]
656 }
657 }
658 }
659
660 foreach i $extra_options {
661 set opt_name [lindex $i 0]
662 set opt_val [lindex $i 1]
663 if ![info exists opts($opt_name)] {
664 perror "unknown option $opt_name given in extra_opts"
665 unresolved $subdir/$name
666 return
667 }
668 # Add extra option to end of existing option, adding space
669 # if necessary.
670 if { ![regexp "warning|error" $opt_name]
671 && [string length $opts($opt_name)] } {
672 append opts($opt_name) " "
673 }
674 append opts($opt_name) $opt_val
675 }
676
677 foreach opt { as ld } {
678 regsub {\[big_or_little_endian\]} $opts($opt) \
679 [big_or_little_endian] opts($opt)
680 }
681
682 # Decide early whether we should run the test for this target.
683 if { [llength $opts(target)] > 0 } {
684 set targmatch 0
685 foreach targ $opts(target) {
686 if [istarget $targ] {
687 set targmatch 1
688 break
689 }
690 }
691 if { $targmatch == 0 } {
692 return
693 }
694 }
695 foreach targ $opts(notarget) {
696 if [istarget $targ] {
697 return
698 }
699 }
700
701 set program ""
702 # It's meaningless to require an output-testing method when we
703 # expect an error.
704 if { $opts(error) == "" } {
705 if {$opts(PROG) != ""} {
706 switch -- $opts(PROG) {
707 objdump { set program objdump }
708 nm { set program nm }
709 objcopy { set program objcopy }
710 readelf { set program readelf }
711 default
712 { perror "unrecognized program option $opts(PROG) in $file.d"
713 unresolved $subdir/$name
714 return }
715 }
716 } else {
717 # Guess which program to run, by seeing which option was specified.
718 foreach p {objdump objcopy nm readelf} {
719 if {$opts($p) != ""} {
720 if {$program != ""} {
721 perror "ambiguous dump program in $file.d"
722 unresolved $subdir/$name
723 return
724 } else {
725 set program $p
726 }
727 }
728 }
729 }
730 if { $program == "" && $opts(warning) == "" } {
731 perror "dump program unspecified in $file.d"
732 unresolved $subdir/$name
733 return
734 }
735 }
736
737 if { $opts(name) == "" } {
738 set testname "$subdir/$name"
739 } else {
740 set testname $opts(name)
741 }
742
743 if { $opts(source) == "" } {
744 set sourcefiles [list ${file}.s]
745 set asflags [list ""]
746 } else {
747 set sourcefiles {}
748 foreach sf $opts(source) {
749 if { [string match "/*" $sf] } {
750 lappend sourcefiles "$sf"
751 } else {
752 lappend sourcefiles "$srcdir/$subdir/$sf"
753 }
754 }
755 }
756
757 if { $opts(dump) == "" } {
758 set dfile ${file}.d
759 } else {
760 set dfile $srcdir/$subdir/$opts(dump)
761 }
762
763 if { [string match "*--compress-debug-sections*" $opts(as)] \
764 && ![is_zlib_supported] } {
765 unsupported $testname
766 return
767 }
768
769 # Time to setup xfailures.
770 foreach targ $opts(xfail) {
771 setup_xfail $targ
772 }
773
774 # Assemble each file.
775 set objfiles {}
776 for { set i 0 } { $i < [llength $sourcefiles] } { incr i } {
777 set sourcefile [lindex $sourcefiles $i]
778 set sourceasflags [lindex $asflags $i]
779
780 set objfile "tmpdir/dump$i.o"
781 catch "exec rm -f $objfile" exec_output
782 lappend objfiles $objfile
783 set cmd "$AS $ASFLAGS $opts(as) $sourceasflags -o $objfile $sourcefile"
784
785 send_log "$cmd\n"
786 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
787 remote_upload host "ld.tmp"
788 set comp_output [prune_warnings [file_contents "ld.tmp"]]
789 remote_file host delete "ld.tmp"
790 remote_file build delete "ld.tmp"
791
792 if { [lindex $cmdret 0] != 0 || ![string match "" $comp_output] } then {
793 send_log "$comp_output\n"
794 verbose "$comp_output" 3
795
796 set exitstat "succeeded"
797 if { $cmdret != 0 } { set exitstat "failed" }
798 verbose -log "$exitstat with: <$comp_output>"
799 fail $testname
800 return
801 }
802 }
803
804 set expmsg $opts(error)
805 if { $opts(warning) != "" } {
806 if { $expmsg != "" } {
807 perror "$testname: mixing error and warning test-directives"
808 return
809 }
810 set expmsg $opts(warning)
811 }
812
813 # Perhaps link the file(s).
814 if { $run_ld } {
815 set objfile "tmpdir/dump"
816 catch "exec rm -f $objfile" exec_output
817
818 # Add -L$srcdir/$subdir so that the linker command can use
819 # linker scripts in the source directory.
820 set cmd "$LD $LDFLAGS -L$srcdir/$subdir \
821 $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
822
823 send_log "$cmd\n"
824 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
825 remote_upload host "ld.tmp"
826 set comp_output [file_contents "ld.tmp"]
827 remote_file host delete "ld.tmp"
828 remote_file build delete "ld.tmp"
829 set cmdret [lindex $cmdret 0]
830
831 if { $cmdret == 0 && $run_objcopy } {
832 set infile $objfile
833 set objfile "tmpdir/dump1"
834 remote_file host delete $objfile
835
836 # Note that we don't use OBJCOPYFLAGS here; any flags must be
837 # explicitly specified.
838 set cmd "$OBJCOPY $opts(objcopy_linked_file) $infile $objfile"
839
840 send_log "$cmd\n"
841 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
842 remote_upload host "ld.tmp"
843 append comp_output [file_contents "ld.tmp"]
844 remote_file host delete "ld.tmp"
845 remote_file build delete "ld.tmp"
846 set cmdret [lindex $cmdret 0]
847 }
848
849 regsub "\n$" $comp_output "" comp_output
850 if { $cmdret != 0 || $comp_output != "" || $expmsg != "" } then {
851 set exitstat "succeeded"
852 if { $cmdret != 0 } { set exitstat "failed" }
853 verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>"
854 send_log "$comp_output\n"
855 verbose "$comp_output" 3
856
857 if { ($expmsg == "") == ($comp_output == "") \
858 && [regexp $expmsg $comp_output] \
859 && (($cmdret == 0) == ($opts(error) == "")) } {
860 # We have the expected output from ld.
861 if { $opts(error) != "" || $program == "" } {
862 pass $testname
863 return
864 }
865 } else {
866 verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>"
867 fail $testname
868 return
869 }
870 }
871 } else {
872 set objfile "tmpdir/dump0.o"
873 }
874
875 # We must not have expected failure if we get here.
876 if { $opts(error) != "" } {
877 fail $testname
878 return
879 }
880
881 set progopts1 $opts($program)
882 eval set progopts \$[string toupper $program]FLAGS
883 eval set binary \$[string toupper $program]
884
885 if { ![is_remote host] && [which $binary] == 0 } {
886 untested $testname
887 return
888 }
889
890 if { $progopts1 == "" } { set $progopts1 "-r" }
891 verbose "running $binary $progopts $progopts1" 3
892
893 # Objcopy, unlike the other two, won't send its output to stdout,
894 # so we have to run it specially.
895 set cmd "$binary $progopts $progopts1 $objfile > $dumpfile"
896 if { $program == "objcopy" } {
897 set cmd "$binary $progopts $progopts1 $objfile $dumpfile"
898 }
899
900 # Ensure consistent sorting of symbols
901 if {[info exists env(LC_ALL)]} {
902 set old_lc_all $env(LC_ALL)
903 }
904 set env(LC_ALL) "C"
905 send_log "$cmd\n"
906 set cmdret [remote_exec host [concat sh -c [list "$cmd 2>ld.tmp"]] "" "/dev/null"]
907 set cmdret [lindex $cmdret 0]
908 remote_upload host "ld.tmp"
909 set comp_output [prune_warnings [file_contents "ld.tmp"]]
910 remote_file host delete "ld.tmp"
911 remote_file build delete "ld.tmp"
912 if {[info exists old_lc_all]} {
913 set env(LC_ALL) $old_lc_all
914 } else {
915 unset env(LC_ALL)
916 }
917 if { $cmdret != 0 || $comp_output != "" } {
918 send_log "exited abnormally with $cmdret, output:$comp_output\n"
919 fail $testname
920 return
921 }
922
923 if { $verbose > 2 } then { verbose "output is [file_contents $dumpfile]" 3 }
924 if { [regexp_diff $dumpfile "${dfile}"] } then {
925 fail $testname
926 if { $verbose == 2 } then { verbose "output is [file_contents $dumpfile]" 2 }
927 return
928 }
929
930 pass $testname
931 }
932
933 proc slurp_options { file } {
934 # If options_regsub(foo) is set to {a b}, then the contents of a
935 # "#foo:" line will have regsub -all applied to replace a with b.
936 global options_regsub
937
938 if [catch { set f [open $file r] } x] {
939 #perror "couldn't open `$file': $x"
940 perror "$x"
941 return -1
942 }
943 set opt_array {}
944 # whitespace expression
945 set ws {[ ]*}
946 set nws {[^ ]*}
947 # whitespace is ignored anywhere except within the options list;
948 # option names are alphabetic plus underscore only.
949 set pat "^#${ws}(\[a-zA-Z_\]*)$ws:${ws}(.*)$ws\$"
950 while { [gets $f line] != -1 } {
951 set line [string trim $line]
952 # Whitespace here is space-tab.
953 if [regexp $pat $line xxx opt_name opt_val] {
954 # match!
955 if [info exists options_regsub($opt_name)] {
956 set subst $options_regsub($opt_name)
957 regsub -all -- [lindex $subst 0] $opt_val [lindex $subst 1] \
958 opt_val
959 }
960 lappend opt_array [list $opt_name $opt_val]
961 } else {
962 break
963 }
964 }
965 close $f
966 return $opt_array
967 }
968
969 proc file_contents { filename } {
970 set file [open $filename r]
971 set contents [read $file]
972 close $file
973 return $contents
974 }
975
976 proc set_file_contents { filename contents } {
977 set file [open $filename w]
978 puts $file "$contents"
979 close $file
980 }
981
982 # Create an archive using ar
983 #
984 proc ar_simple_create { ar aropts target objects } {
985 remote_file host delete $target
986
987 set exec_output [run_host_cmd "$ar" "$aropts -rc $target $objects"]
988 set exec_output [prune_warnings $exec_output]
989
990 if [string match "" $exec_output] then {
991 send_log "$exec_output\n"
992 return 1
993 } else {
994 return 0
995 }
996 }
997
998 # List contains test-items with 3 items followed by 2 lists, one item and
999 # one optional item:
1000 # 0:name
1001 # 1:ld/ar leading options, placed before object files
1002 # 2:ld/ar trailing options, placed after object files
1003 # 3:assembler options
1004 # 4:filenames of assembler files
1005 # 5:list of actions, options and expected outputs.
1006 # 6:name of output file
1007 # 7:compiler flags (optional)
1008 #
1009 # Actions: { command command-line-options file-containg-expected-output-regexps }
1010 # Commands:
1011 # objdump: Apply objdump options on result.
1012 # nm: Apply nm options on result.
1013 # readelf: Apply readelf options on result.
1014 # ld: Don't apply anything on result. Compare output during linking with
1015 # the file containing regexps (which is the second arg, not the third).
1016 # Note that this *must* be the first action if it is to be used at all;
1017 # in all other cases, any output from the linker during linking is
1018 # treated as a sign of an error and FAILs the test.
1019 #
1020 proc run_ld_link_tests { ldtests } {
1021 global ld
1022 global as
1023 global nm
1024 global ar
1025 global objdump
1026 global READELF
1027 global srcdir
1028 global subdir
1029 global env
1030 global CC
1031 global CFLAGS
1032 global runtests
1033 global exec_output
1034
1035 foreach testitem $ldtests {
1036 set testname [lindex $testitem 0]
1037
1038 if ![runtest_file_p $runtests $testname] then {
1039 continue
1040 }
1041
1042 set ld_options [lindex $testitem 1]
1043 set ld_after [lindex $testitem 2]
1044 set as_options [lindex $testitem 3]
1045 set src_files [lindex $testitem 4]
1046 set actions [lindex $testitem 5]
1047 set binfile tmpdir/[lindex $testitem 6]
1048 set cflags [lindex $testitem 7]
1049 set objfiles {}
1050 set is_unresolved 0
1051 set failed 0
1052 set maybe_failed 0
1053 set ld_output ""
1054
1055 # verbose -log "Testname is $testname"
1056 # verbose -log "ld_options is $ld_options"
1057 # verbose -log "ld_after is $ld_after"
1058 # verbose -log "as_options is $as_options"
1059 # verbose -log "src_files is $src_files"
1060 # verbose -log "actions is $actions"
1061 # verbose -log "binfile is $binfile"
1062
1063 # Assemble each file in the test.
1064 foreach src_file $src_files {
1065 set fileroot "[file rootname [file tail $src_file]]"
1066 set objfile "tmpdir/$fileroot.o"
1067 lappend objfiles $objfile
1068
1069 if { [file extension $src_file] == ".c" } {
1070 set as_file "tmpdir/$fileroot.s"
1071 if ![ld_compile "$CC -S $CFLAGS $cflags" $srcdir/$subdir/$src_file $as_file] {
1072 set is_unresolved 1
1073 break
1074 }
1075 } else {
1076 set as_file "$srcdir/$subdir/$src_file"
1077 }
1078 if ![ld_assemble $as "$as_options $as_file" $objfile] {
1079 set is_unresolved 1
1080 break
1081 }
1082 }
1083
1084 # Catch assembler errors.
1085 if { $is_unresolved } {
1086 unresolved $testname
1087 continue
1088 }
1089
1090 if { [regexp ".*\\.a$" $binfile] } {
1091 if { ![ar_simple_create $ar $ld_options $binfile "$objfiles $ld_after"] } {
1092 set failed 1
1093 }
1094 } elseif { ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles $ld_after"] } {
1095 set maybe_failed 1
1096 set ld_output "$exec_output"
1097 }
1098
1099 if { !$failed } {
1100 foreach actionlist $actions {
1101 set action [lindex $actionlist 0]
1102 set progopts [lindex $actionlist 1]
1103
1104 # There are actions where we run regexp_diff on the
1105 # output, and there are other actions (presumably).
1106 # Handling of the former look the same.
1107 set dump_prog ""
1108 switch -- $action {
1109 objdump
1110 { set dump_prog $objdump }
1111 nm
1112 { set dump_prog $nm }
1113 readelf
1114 { set dump_prog $READELF }
1115 ld
1116 { set dump_prog "ld" }
1117 default
1118 {
1119 perror "Unrecognized action $action"
1120 set is_unresolved 1
1121 break
1122 }
1123 }
1124
1125 if { $action == "ld" } {
1126 set regexpfile $progopts
1127 verbose "regexpfile is $srcdir/$subdir/$regexpfile"
1128 set_file_contents "tmpdir/ld.messages" "$ld_output"
1129 verbose "ld.messages has '[file_contents tmpdir/ld.messages]'"
1130 if { [regexp_diff "tmpdir/ld.messages" "$srcdir/$subdir/$regexpfile"] } then {
1131 verbose "output is $ld_output" 2
1132 set failed 1
1133 break
1134 }
1135 set maybe_failed 0
1136 } elseif { !$maybe_failed && $dump_prog != "" } {
1137 set dumpfile [lindex $actionlist 2]
1138 set binary $dump_prog
1139
1140 # Ensure consistent sorting of symbols
1141 if {[info exists env(LC_ALL)]} {
1142 set old_lc_all $env(LC_ALL)
1143 }
1144 set env(LC_ALL) "C"
1145 set cmd "$binary $progopts $binfile"
1146 set status [remote_exec host [concat sh -c [list "$cmd >dump.out 2>ld.stderr"]] "" "/dev/null"]
1147 send_log "$cmd\n"
1148 remote_upload host "ld.stderr"
1149 set comp_output [prune_warnings [file_contents "ld.stderr"]]
1150 remote_file host delete "ld.stderr"
1151 remote_file build delete "ld.stderr"
1152
1153 if {[info exists old_lc_all]} {
1154 set env(LC_ALL) $old_lc_all
1155 } else {
1156 unset env(LC_ALL)
1157 }
1158
1159 if ![string match "" $comp_output] then {
1160 send_log "$comp_output\n"
1161 set failed 1
1162 break
1163 }
1164
1165 remote_upload host "dump.out"
1166
1167 if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then {
1168 verbose "output is [file_contents "dump.out"]" 2
1169 set failed 1
1170 remote_file build delete "dump.out"
1171 remote_file host delete "dump.out"
1172 break
1173 }
1174 remote_file build delete "dump.out"
1175 remote_file host delete "dump.out"
1176 }
1177 }
1178 }
1179
1180 if { $is_unresolved } {
1181 unresolved $testname
1182 } elseif { $maybe_failed || $failed } {
1183 fail $testname
1184 } else {
1185 pass $testname
1186 }
1187 }
1188 }
1189
1190 # This definition is taken from an unreleased version of DejaGnu. Once
1191 # that version gets released, and has been out in the world for a few
1192 # months at least, it may be safe to delete this copy.
1193 if ![string length [info proc prune_warnings]] {
1194 #
1195 # prune_warnings -- delete various system verbosities from TEXT
1196 #
1197 # An example is:
1198 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
1199 #
1200 # Sites with particular verbose os's may wish to override this in site.exp.
1201 #
1202 proc prune_warnings { text } {
1203 # This is from sun4's. Do it for all machines for now.
1204 # The "\\1" is to try to preserve a "\n" but only if necessary.
1205 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
1206
1207 # It might be tempting to get carried away and delete blank lines, etc.
1208 # Just delete *exactly* what we're ask to, and that's it.
1209 return $text
1210 }
1211 }
1212
1213 # targets_to_xfail is a list of target triplets to be xfailed.
1214 # ldtests contains test-items with 3 items followed by 1 lists, 2 items
1215 # and 3 optional items:
1216 # 0:name
1217 # 1:ld options
1218 # 2:assembler options
1219 # 3:filenames of source files
1220 # 4:name of output file
1221 # 5:expected output
1222 # 6:compiler flags (optional)
1223 # 7:language (optional)
1224 # 8:linker warning (optional)
1225
1226 proc run_ld_link_exec_tests { targets_to_xfail ldtests } {
1227 global ld
1228 global as
1229 global srcdir
1230 global subdir
1231 global env
1232 global CC
1233 global CXX
1234 global CFLAGS
1235 global CXXFLAGS
1236 global errcnt
1237 global exec_output
1238
1239 foreach testitem $ldtests {
1240 foreach target $targets_to_xfail {
1241 setup_xfail $target
1242 }
1243 set testname [lindex $testitem 0]
1244 set ld_options [lindex $testitem 1]
1245 set as_options [lindex $testitem 2]
1246 set src_files [lindex $testitem 3]
1247 set binfile tmpdir/[lindex $testitem 4]
1248 set expfile [lindex $testitem 5]
1249 set cflags [lindex $testitem 6]
1250 set lang [lindex $testitem 7]
1251 set warning [lindex $testitem 8]
1252 set objfiles {}
1253 set failed 0
1254
1255 # verbose -log "Testname is $testname"
1256 # verbose -log "ld_options is $ld_options"
1257 # verbose -log "as_options is $as_options"
1258 # verbose -log "src_files is $src_files"
1259 # verbose -log "binfile is $binfile"
1260
1261 # Assemble each file in the test.
1262 foreach src_file $src_files {
1263 set fileroot "[file rootname [file tail $src_file]]"
1264 set objfile "tmpdir/$fileroot.o"
1265 lappend objfiles $objfile
1266
1267 # We ignore warnings since some compilers may generate
1268 # incorrect section attributes and the assembler will warn
1269 # them.
1270 if { [ string match "c++" $lang ] } {
1271 ld_compile "$CXX -c $CXXFLAGS $cflags" $srcdir/$subdir/$src_file $objfile
1272 } else {
1273 ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/$src_file $objfile
1274 }
1275 }
1276
1277 # We have to use $CC to build PIE and shared library.
1278 if { [ string match "c" $lang ] } {
1279 set link_proc ld_simple_link
1280 set link_cmd $CC
1281 } elseif { [ string match "c++" $lang ] } {
1282 set link_proc ld_simple_link
1283 set link_cmd $CXX
1284 } elseif { [ string match "-shared" $ld_options ] \
1285 || [ string match "-pie" $ld_options ] } {
1286 set link_proc ld_simple_link
1287 set link_cmd $CC
1288 } else {
1289 set link_proc ld_link
1290 set link_cmd $ld
1291 }
1292
1293 if ![$link_proc $link_cmd $binfile "-L$srcdir/$subdir $ld_options $objfiles"] {
1294 set failed 1
1295 } else {
1296 set failed 0
1297 }
1298
1299 # Check if exec_output is expected.
1300 if { $warning != "" } then {
1301 verbose -log "returned with: <$exec_output>, expected: <$warning>"
1302 if { [regexp $warning $exec_output] } then {
1303 set failed 0
1304 } else {
1305 set failed 1
1306 }
1307 }
1308
1309 if { $failed == 0 } {
1310 send_log "Running: $binfile > $binfile.out\n"
1311 verbose "Running: $binfile > $binfile.out"
1312 catch "exec $binfile > $binfile.out" exec_output
1313
1314 if ![string match "" $exec_output] then {
1315 send_log "$exec_output\n"
1316 verbose "$exec_output" 1
1317 set failed 1
1318 } else {
1319 send_log "diff $binfile.out $srcdir/$subdir/$expfile\n"
1320 verbose "diff $binfile.out $srcdir/$subdir/$expfile"
1321 catch "exec diff $binfile.out $srcdir/$subdir/$expfile" exec_output
1322 set exec_output [prune_warnings $exec_output]
1323
1324 if ![string match "" $exec_output] then {
1325 send_log "$exec_output\n"
1326 verbose "$exec_output" 1
1327 set failed 1
1328 }
1329 }
1330 }
1331
1332 if { $failed != 0 } {
1333 fail $testname
1334 } else {
1335 set errcnt 0
1336 pass $testname
1337 }
1338 }
1339 }
1340
1341 # List contains test-items with 3 items followed by 2 lists, one item and
1342 # one optional item:
1343 # 0:name
1344 # 1:ld or ar options
1345 # 2:compile options
1346 # 3:filenames of source files
1347 # 4:action and options.
1348 # 5:name of output file
1349 # 6:language (optional)
1350 # 7:linker warnings (optional)
1351 #
1352 # Actions:
1353 # objdump: Apply objdump options on result. Compare with regex (last arg).
1354 # nm: Apply nm options on result. Compare with regex (last arg).
1355 # readelf: Apply readelf options on result. Compare with regex (last arg).
1356 #
1357 proc run_cc_link_tests { ldtests } {
1358 global nm
1359 global objdump
1360 global READELF
1361 global srcdir
1362 global subdir
1363 global env
1364 global CC
1365 global CXX
1366 global CFLAGS
1367 global CXXFLAGS
1368 global ar
1369 global exec_output
1370
1371 foreach testitem $ldtests {
1372 set testname [lindex $testitem 0]
1373 set ldflags [lindex $testitem 1]
1374 set cflags [lindex $testitem 2]
1375 set src_files [lindex $testitem 3]
1376 set actions [lindex $testitem 4]
1377 set binfile tmpdir/[lindex $testitem 5]
1378 set lang [lindex $testitem 6]
1379 set warnings [lindex $testitem 7]
1380 set objfiles {}
1381 set is_unresolved 0
1382 set failed 0
1383
1384 # Compile each file in the test.
1385 foreach src_file $src_files {
1386 set fileroot "[file rootname [file tail $src_file]]"
1387 set objfile "tmpdir/$fileroot.o"
1388 lappend objfiles $objfile
1389
1390 # We ignore warnings since some compilers may generate
1391 # incorrect section attributes and the assembler will warn
1392 # them.
1393 if { [ string match "c++" $lang ] } {
1394 ld_compile "$CXX -c $CXXFLAGS $cflags" $srcdir/$subdir/$src_file $objfile
1395 } else {
1396 ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/$src_file $objfile
1397 }
1398 }
1399
1400 # Clear error and warning counts.
1401 reset_vars
1402
1403 if { [ string match "c++" $lang ] } {
1404 set cc_cmd $CXX
1405 } else {
1406 set cc_cmd $CC
1407 }
1408
1409 if { [regexp ".*\\.a$" $binfile] } {
1410 if { ![ar_simple_create $ar $ldflags $binfile "$objfiles"] } {
1411 fail $testname
1412 set failed 1
1413 } else {
1414 set failed 0
1415 }
1416 } else {
1417 if { ![ld_simple_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles"] } {
1418 set failed 1
1419 } else {
1420 set failed 0
1421 }
1422
1423 # Check if exec_output is expected.
1424 if { $warnings != "" } then {
1425 verbose -log "returned with: <$exec_output>, expected: <$warnings>"
1426 if { [regexp $warnings $exec_output] } then {
1427 set failed 2
1428 } else {
1429 set failed 1
1430 }
1431 }
1432
1433 if { $failed == 1 } {
1434 fail $testname
1435 }
1436 }
1437
1438 if { $failed == 0 } {
1439 foreach actionlist $actions {
1440 set action [lindex $actionlist 0]
1441 set progopts [lindex $actionlist 1]
1442
1443 # There are actions where we run regexp_diff on the
1444 # output, and there are other actions (presumably).
1445 # Handling of the former look the same.
1446 set dump_prog ""
1447 switch -- $action {
1448 objdump
1449 { set dump_prog $objdump }
1450 nm
1451 { set dump_prog $nm }
1452 readelf
1453 { set dump_prog $READELF }
1454 default
1455 {
1456 perror "Unrecognized action $action"
1457 set is_unresolved 1
1458 break
1459 }
1460 }
1461
1462 if { $dump_prog != "" } {
1463 set dumpfile [lindex $actionlist 2]
1464 set binary $dump_prog
1465
1466 # Ensure consistent sorting of symbols
1467 if {[info exists env(LC_ALL)]} {
1468 set old_lc_all $env(LC_ALL)
1469 }
1470 set env(LC_ALL) "C"
1471 set cmd "$binary $progopts $binfile > dump.out"
1472 send_log "$cmd\n"
1473 catch "exec $cmd" comp_output
1474 if {[info exists old_lc_all]} {
1475 set env(LC_ALL) $old_lc_all
1476 } else {
1477 unset env(LC_ALL)
1478 }
1479 set comp_output [prune_warnings $comp_output]
1480
1481 if ![string match "" $comp_output] then {
1482 send_log "$comp_output\n"
1483 set failed 1
1484 break
1485 }
1486
1487 if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then {
1488 verbose "output is [file_contents "dump.out"]" 2
1489 set failed 1
1490 break
1491 }
1492 }
1493 }
1494
1495 if { $failed != 0 } {
1496 fail $testname
1497 } else { if { $is_unresolved == 0 } {
1498 pass $testname
1499 } }
1500 }
1501
1502 # Catch action errors.
1503 if { $is_unresolved != 0 } {
1504 unresolved $testname
1505 continue
1506 }
1507 }
1508 }
1509
1510 # Returns true if --gc-sections is supported on the target.
1511
1512 proc check_gc_sections_available { } {
1513 global gc_sections_available_saved
1514 global ld
1515
1516 if {![info exists gc_sections_available_saved]} {
1517 # Some targets don't support gc-sections despite whatever's
1518 # advertised by ld's options.
1519 if { [istarget arc-*-*]
1520 || [istarget d30v-*-*]
1521 || [istarget dlx-*-*]
1522 || [istarget i960-*-*]
1523 || [istarget or32-*-*]
1524 || [istarget pj*-*-*]
1525 || [istarget alpha-*-*]
1526 || [istarget hppa*64-*-*]
1527 || [istarget i370-*-*]
1528 || [istarget i860-*-*]
1529 || [istarget ia64-*-*]
1530 || [istarget mep-*-*]
1531 || [istarget mn10200-*-*]
1532 || [istarget *-*-cygwin]
1533 || [istarget *-*-mingw*] } {
1534 set gc_sections_available_saved 0
1535 return 0
1536 }
1537
1538 # elf2flt uses -q (--emit-relocs), which is incompatible with
1539 # --gc-sections.
1540 if { [board_info target exists ldflags]
1541 && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
1542 set gc_sections_available_saved 0
1543 return 0
1544 }
1545
1546 # Check if the ld used by gcc supports --gc-sections.
1547 # FIXME: this test is useless since ld --help always says
1548 # --gc-sections is available
1549 set ld_output [remote_exec host $ld "--help"]
1550 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
1551 set gc_sections_available_saved 1
1552 } else {
1553 set gc_sections_available_saved 0
1554 }
1555 }
1556 return $gc_sections_available_saved
1557 }
1558
1559 # Returns true if -shared is supported on the target
1560 # Only used and accurate for ELF targets at the moment
1561
1562 proc check_shared_lib_support { } {
1563 if {![istarget aarch64*-*-elf]
1564 && ![istarget arc-*-*]
1565 && ![istarget arm*-*-elf]
1566 && ![istarget avr-*-*]
1567 && ![istarget cr16-*-*]
1568 && ![istarget cris*-*-elf]
1569 && ![istarget crx-*-*]
1570 && ![istarget d10v-*-*]
1571 && ![istarget d30v-*-*]
1572 && ![istarget dlx-*-*]
1573 && ![istarget epiphany-*-*]
1574 && ![istarget fr30-*-*]
1575 && ![istarget frv-*-*]
1576 && ![istarget h8300-*-*]
1577 && ![istarget i860-*-*]
1578 && ![istarget i960-*-*]
1579 && ![istarget ip2k-*-*]
1580 && ![istarget iq2000-*-*]
1581 && ![istarget lm32-*-*]
1582 && ![istarget m32c-*-*]
1583 && ![istarget m32r-*-*]
1584 && ![istarget m6811-*-*]
1585 && ![istarget m6812-*-*]
1586 && ![istarget m68hc1*-*-*]
1587 && ![istarget mcore*-*-*]
1588 && ![istarget mep-*-*]
1589 && ![istarget microblaze-*-*]
1590 && ![istarget mips*-*-elf]
1591 && ![istarget mn10200-*-*]
1592 && ![istarget moxie-*-*]
1593 && ![istarget msp430-*-*]
1594 && ![istarget mt-*-*]
1595 && ![istarget openrisc-*-*]
1596 && ![istarget or32-*-*]
1597 && ![istarget pj-*-*]
1598 && ![istarget rx-*-*]
1599 && ![istarget spu-*-*]
1600 && ![istarget v850*-*-*]
1601 && ![istarget xstormy16-*-*]
1602 && ![istarget *-*-irix*]
1603 && ![istarget *-*-rtems] } {
1604 return 1
1605 }
1606 return 0
1607 }
1608
1609 # Returns true if the target ld supports the plugin API.
1610 proc check_plugin_api_available { } {
1611 global plugin_api_available_saved
1612 global ld
1613 if {![info exists plugin_api_available_saved]} {
1614 # Check if the ld used by gcc supports --plugin.
1615 set ld_output [remote_exec host $ld "--help"]
1616 if { [ string first "-plugin" $ld_output ] >= 0 } {
1617 set plugin_api_available_saved 1
1618 } else {
1619 set plugin_api_available_saved 0
1620 }
1621 }
1622 return $plugin_api_available_saved
1623 }
1624
1625 # Returns true if the target compiler supports LTO
1626 proc check_lto_available { } {
1627 global lto_available_saved
1628 global CC
1629 if {![info exists lto_available_saved]} {
1630 # Check if gcc supports -flto -fuse-linker-plugin
1631 if { [which $CC] == 0 } {
1632 set lto_available_saved 0
1633 return 0
1634 }
1635 set basename "lto"
1636 set src ${basename}[pid].c
1637 set output ${basename}[pid].so
1638 set f [open $src "w"]
1639 puts $f ""
1640 close $f
1641 set status [remote_exec host $CC "-shared -B[pwd]/tmpdir/ld/ -flto -fuse-linker-plugin $src -o $output"]
1642 if { [lindex $status 0] == 0 } {
1643 set lto_available_saved 1
1644 } else {
1645 set lto_available_saved 0
1646 }
1647 file delete $src
1648 file delete $output
1649 }
1650 return $lto_available_saved
1651 }
1652
1653 # Check if the assembler supports CFI statements.
1654
1655 proc check_as_cfi { } {
1656 global check_as_cfi_result
1657 global as
1658 if [info exists check_as_cfi_result] {
1659 return $check_as_cfi_result
1660 }
1661 set as_file "tmpdir/check_as_cfi.s"
1662 set as_fh [open $as_file w 0666]
1663 puts $as_fh "# Generated file. DO NOT EDIT"
1664 puts $as_fh "\t.cfi_startproc"
1665 puts $as_fh "\t.cfi_endproc"
1666 close $as_fh
1667 remote_download host $as_file
1668 verbose -log "Checking CFI support:"
1669 rename "perror" "check_as_cfi_perror"
1670 proc perror { args } { }
1671 set success [ld_assemble $as $as_file "/dev/null"]
1672 rename "perror" ""
1673 rename "check_as_cfi_perror" "perror"
1674 #remote_file host delete $as_file
1675 set check_as_cfi_result $success
1676 return $success
1677 }
1678
1679 # Provide virtual target "cfi" for targets supporting CFI.
1680
1681 rename "istarget" "istarget_ld"
1682 proc istarget { target } {
1683 if {$target == "cfi"} {
1684 return [check_as_cfi]
1685 }
1686 return [istarget_ld $target]
1687 }
This page took 0.067275 seconds and 5 git commands to generate.