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