1 # Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # Contributed by Diego Novillo <dnovillo@google.com>
19 # Prune messages that aren't useful.
21 proc lto_prune_warns { text } {
23 verbose "lto_prune_warns: entry: $text" 2
25 # Many tests that use visibility will still pass on platforms that don't support it.
26 regsub -all "(^|\n)\[^\n\]*: warning: visibility attribute not supported in this configuration; ignored\[^\n\]*" $text "" text
28 # And any stray location lines.
29 regsub -all "(^|\n)\[^\n\]*: In function \[^\n\]*" $text "" text
30 regsub -all "(^|\n)In file included from :\[^\n\]*" $text "" text
32 # Sun ld warns about common symbols with differing sizes. Unlike GNU ld
33 # --warn-common (off by default), they cannot be disabled.
34 regsub -all "(^|\n)ld: warning: symbol `\[^\n\]*' has differing sizes:" $text "" text
35 regsub -all "(^|\n)\[ \t\]*\[\(\]file \[^\n\]* value=\[^\n\]*; file \[^\n\]* value=\[^\n\]*\[)\];" $text "" text
36 regsub -all "(^|\n)\[ \t\]*\[^\n\]* definition taken" $text "" text
38 verbose "lto_prune_warns: exit: $text" 2
43 # lto_init -- called at the start of each subdir of tests
45 proc lto_init { args } {
48 if {[info exists args] && $args == "no-mathlib"} {
52 set dest [target_info name]
53 if [board_info $dest exists mathlib] {
54 set saved_mathlib [board_info $dest mathlib]
56 set board_info($dest,mathlib) " "
59 # Each test is run with the compiler options from this list.
60 # The default option lists can be overridden by LTO_OPTIONS="[list
61 # {opts_1} {opts_2}... {opts_n}]" where opts_i are lists of options.
62 # You can put this in the environment before site.exp is written or
63 # add it to site.exp directly.
64 if ![info exists LTO_OPTIONS] {
65 set LTO_OPTIONS [list \
75 # lto_finish -- called at the end of each subdir of tests if mathlib is
83 set dest [target_info name]
84 if [info exists saved_mathlib] {
85 set board_info($dest,mathlib) $saved_mathlib
86 } elseif [board_info $dest exists mathlib] {
87 unset board_info($dest,mathlib)
91 # Subsets of tests can be selectively disabled by members of this list:
92 # - ATTRIBUTE: disable all tests using the __attribute__ extension,
93 # - COMPLEX: disable all tests using the complex types feature,
94 # - COMPLEX_INT: disable all tests using the complex integral types extension,
95 # - VA: disable all tests using the variable number of arguments feature,
96 # - VLA_IN_STRUCT: disable all tests using the variable-length arrays as
97 # structure members extension,
98 # - ZERO_ARRAY: disable all tests using the zero-sized arrays extension.
99 # The default skip lists can be overriden by
100 # LTO_SKIPS="[list {skip_1}...{skip_n}]"
101 # where skip_i are skip identifiers. You can put this in the environment
102 # before site.exp is written or add it to site.exp directly.
103 if ![info exists LTO_SKIPS] {
104 set LTO_SKIPS [list {}]
108 set lto_skip_list $LTO_SKIPS
113 # lto-obj -- compile to an object file
115 # SOURCE is the source file
116 # DEST is the object file
117 # OPTALL is the list of compiler options to use with all tests
118 # OPTFILE is the list of compiler options to use with this file
119 # OPTSTR is the options to print with test messages
120 # XFAILDATA is the xfail data to be passed to the compiler
121 proc lto-obj { source dest optall optfile optstr xfaildata } {
124 global compiler_conditional_xfail_data
127 # Add the skip specifiers.
128 foreach skip $lto_skip_list {
129 if { ![string match $skip ""] } {
130 lappend optall "-DSKIP_$skip"
134 # Set up the options for compiling this file.
136 lappend options "additional_flags=$optall $optfile"
138 set compiler_conditional_xfail_data $xfaildata
139 set comp_output [${tool}_target_compile "$source" "$dest" object $options]
140 ${tool}_check_compile "$testcase $dest assemble" $optstr $dest $comp_output
143 # lto-link-and-maybe-run -- link the object files and run the executable
144 # if compile_type is set to "run"
146 # TESTNAME is the mixture of object files to link
147 # OBJLIST is the list of object files to link
148 # DEST is the name of the executable
149 # OPTALL is a list of compiler and linker options to use for all tests
150 # OPTFILE is a list of compiler and linker options to use for this test
151 # OPTSTR is the list of options to list in messages
152 proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
157 # Check that all of the objects were built successfully.
158 foreach obj [split $objlist] {
159 if ![file_on_host exists $obj] then {
160 unresolved "$testcase $testname link $optstr"
161 unresolved "$testcase $testname execute $optstr"
166 # Set up the options for linking this test.
168 lappend options "additional_flags=$optall $optfile"
170 # Link the objects into an executable.
171 set comp_output [${tool}_target_compile "$objlist" $dest executable \
174 # Prune unimportant visibility warnings before checking output.
175 set comp_output [lto_prune_warns $comp_output]
177 if ![${tool}_check_compile "$testcase $testname link" "" \
178 $dest $comp_output] then {
179 unresolved "$testcase $testname execute $optstr"
183 # Return if we only needed to link.
184 if { ![string compare "link" $compile_type] } {
188 # Run the self-checking executable.
189 if ![string match "*/*" $dest] then {
192 set result [${tool}_load $dest "" ""]
193 set status [lindex $result 0]
194 if { $status == "pass" } then {
195 file_on_host delete $dest
197 $status "$testcase $testname execute $optstr"
200 # lto-get-options-main -- get target requirements for a test and
201 # options for the primary source file and the test as a whole
203 # SRC is the full pathname of the primary source file.
204 proc lto-get-options-main { src } {
206 global dg-extra-ld-options
207 global dg-suppress-ld-options
209 set dg-extra-ld-options ""
210 set dg-suppress-ld-options ""
212 # dg-options sets a variable called dg-extra-tool-flags.
213 set dg-extra-tool-flags ""
215 # dg-options sets a variable called tool_flags.
218 # dg-require-* sets dg-do-what.
219 upvar dg-do-what dg-do-what
220 upvar dg-final-code dg-final-code
223 set tmp [dg-get-options $src]
224 verbose "getting options for $src: $tmp"
226 set cmd [lindex $op 0]
227 verbose "cmd is $cmd"
228 if { [string match "dg-skip-if" $cmd] \
229 || [string match "dg-require-*" $cmd] } {
230 set status [catch "$op" errmsg]
231 if { $status != 0 } {
232 perror "src: $errmsg for \"$op\"\n"
233 unresolved "$src: $errmsg for \"$op\""
236 } elseif { [string match "dg-lto-options" $cmd] } {
237 set op [lreplace $op 0 0 "dg-options"]
238 set status [catch "$op" errmsg]
239 if { $status != 0 } {
240 perror "src: $errmsg for \"$op\"\n"
241 unresolved "$src: $errmsg for \"$op\""
244 } elseif { ![string compare "dg-xfail-if" $cmd] \
245 || ![string compare "dg-options" $cmd] } {
246 warning "lto.exp does not support $cmd in primary source file"
247 } elseif { ![string compare "dg-lto-do" $cmd] } {
248 if { [llength $op] > 3 } {
249 set kw [lindex [lindex $op 3] 0]
250 if [string match "target" $kw] {
251 perror "$src: dg-lto-do does not support \"target\""
252 } elseif [string match "xfail" $kw] {
253 perror "$src: dg-lto-do does not support \"xfail\""
255 perror "$src: dg-lto-do takes a single argument"
258 set dgdo [lindex $op 2]
259 verbose "dg-lto-do command for \"$op\" is $dgdo"
260 if { ![string compare "assemble" $dgdo] } {
261 set compile_type "assemble"
262 } elseif { ![string compare "run" $dgdo] } {
263 set compile_type "run"
264 } elseif { ![string compare "link" $dgdo] } {
265 set compile_type "link"
267 warning "lto.exp does not support dg-lto-do $dgdo"
269 } elseif { ![string compare "dg-extra-ld-options" $cmd] } {
270 set dg-extra-ld-options [lindex $op 2]
271 verbose "dg-extra-ld-options for main is ${dg-extra-ld-options}"
272 } elseif { ![string compare "dg-suppress-ld-options" $cmd] } {
273 set dg-suppress-ld-options [lindex $op 2]
275 "dg-suppress-ld-options for main is ${dg-suppress-ld-options}"
276 } elseif { ![string compare "dg-final" $cmd] } {
277 if { [llength $op] > 3 } {
278 error "[lindex $op 0]: too many arguments"
280 append dg-final-code "[lindex $op 2]\n"
283 # Ignore unrecognized dg- commands, but warn about them.
284 warning "lto.exp does not support $cmd"
288 # Return flags to use for compiling the primary source file and for
290 verbose "dg-extra-tool-flags for main is ${dg-extra-tool-flags}"
291 return ${dg-extra-tool-flags}
295 # lto-get-options -- get special tool flags to use for a secondary
298 # SRC is the full pathname of the source file.
299 # The result is a list of options to use.
301 # This code is copied from proc dg-test in dg.exp from DejaGNU.
302 proc lto-get-options { src } {
303 # dg-options sets a variable called dg-extra-tool-flags.
304 set dg-extra-tool-flags ""
306 # dg-xfail-if sets compiler_conditional_xfail_data.
307 global compiler_conditional_xfail_data
308 set compiler_conditional_xfail_data ""
310 # dg-xfail-if needs access to dg-do-what.
311 upvar dg-do-what dg-do-what
313 set tmp [dg-get-options $src]
315 set cmd [lindex $op 0]
316 if { ![string compare "dg-options" $cmd] \
317 || ![string compare "dg-xfail-if" $cmd] } {
318 set status [catch "$op" errmsg]
319 if { $status != 0 } {
320 perror "src: $errmsg for \"$op\"\n"
321 unresolved "$src: $errmsg for \"$op\""
324 } elseif { [string match "dg-require-*" $cmd] } {
325 warning "lto.exp does not support $cmd in secondary source files"
327 # Ignore unrecognized dg- commands, but warn about them.
328 warning "lto.exp does not support $cmd in secondary source files"
332 return ${dg-extra-tool-flags}
335 # lto-execute -- compile multi-file tests
337 # SRC1 is the full pathname of the main file of the testcase.
338 # SID identifies a test suite in the names of temporary files.
339 proc lto-execute { src1 sid } {
341 global lto_option_list
346 global compiler_conditional_xfail_data
347 global dg-do-what-default
349 global dg-extra-ld-options
350 global dg-suppress-ld-options
354 # Get extra flags for this test from the primary source file, and
355 # process other dg-* options that this suite supports. Warn about
357 verbose "lto-execute: $src1" 1
358 set compile_type "run"
359 set dg-do-what [list ${dg-do-what-default} "" P]
360 set extra_flags(0) [lto-get-options-main $src1]
361 set compile_xfail(0) ""
363 # If the main file defines dg-options, those flags are used to
364 # overwrite the default lto_option_list taken from LTO_OPTIONS.
365 if { [string length $extra_flags(0)] > 0 } {
366 set lto_option_list $extra_flags(0)
367 set extra_flags(0) ""
369 set lto_option_list $LTO_OPTIONS
372 # Check whether this test is supported for this target.
373 if { [lindex ${dg-do-what} 1 ] == "N" } {
375 verbose "$src1 not supported on this target, skipping it" 3
379 # Set up the names of the other source files.
380 set dir [file dirname $src1]
381 set base [file rootname $src1]
382 set base [string range $base [string length $dir] end]
383 regsub "_0" $base "" base
384 regsub "/" $base "" base
389 set names [glob -nocomplain -types f -- "${dir}/${base}_${i}.*"]
390 if { [llength ${names}] > 1 } {
391 warning "lto-execute: more than one file matched ${dir}/${base}_${i}.*"
393 if { [llength ${names}] == 1 } {
394 lappend src_list [lindex ${names} 0]
402 # Use the dg-options mechanism to specify extra flags for each
403 # of the secondary files.
404 # The extra flags in each file are used to compile that file, and the
405 # extra flags in *_0.* are also used for linking.
406 verbose "\tsrc_list is: $src_list"
407 for {set i 1} {$i < $num_srcs} {incr i} {
408 set extra_flags($i) [lto-get-options [lindex $src_list $i]]
409 set compile_xfail($i) $compiler_conditional_xfail_data
412 # Define the names of the object files.
414 for {set i 0} {$i < $num_srcs} {incr i} {
415 lappend obj_list "${sid}_${base}_${i}.o"
418 # Get the base name of this test, for use in messages.
419 set testcase [lindex ${src_list} 0]
421 # Remove the $srcdir and $tmpdir prefixes from $src1. (It would
422 # be possible to use "regsub" here, if we were careful to escape
423 # all regular expression characters in $srcdir and $tmpdir, but
424 # that would be more complicated that this approach.)
425 if {[string first "$srcdir/" "${testcase}"] == 0} {
426 set testcase [string range "${testcase}" [string length "$srcdir/"] end]
428 if {[string first "$tmpdir/" "$testcase"] == 0} {
429 set testcase [string range "$testcase" [string length "$tmpdir/"] end]
430 set testcase "tmpdir-$testcase"
432 regsub "_0.*" $testcase "" testcase
434 # Set up the base name of executable files so they'll be unique.
435 regsub -all "\[./\]" $testcase "-" execbase
437 # If we couldn't rip $srcdir out of `src1' then just do the best we can.
438 # The point is to reduce the unnecessary noise in the logs. Don't strip
439 # out too much because different testcases with the same name can confuse
441 if [string match "/*" $testcase] then {
442 set testcase "[file tail [file dirname $src1]]/[file tail $src1]"
445 # Loop through all of the option lists used for this test.
447 foreach option $lto_option_list {
448 verbose "Testing $testcase, $option"
450 # There's a unique name for each executable we generate.
451 set execname "${execbase}-${count}1"
454 file_on_host delete $execname
456 # Compile pieces with the compiler under test.
458 foreach src $src_list obj $obj_list {
459 lto-obj $src $obj $option $extra_flags($i) $option \
464 # Link (using the compiler under test), run, and clean up tests.
465 if { ![string compare "run" $compile_type] \
466 || ![string compare "link" $compile_type] } {
468 # Filter out any link options we were asked to suppress.
470 foreach x [split $option] {
471 if {[lsearch ${dg-suppress-ld-options} $x] == -1} {
475 set filtered [join $reduced " "]
477 lto-link-and-maybe-run \
478 "[lindex $obj_list 0]-[lindex $obj_list end]" \
479 $obj_list $execname $filtered ${dg-extra-ld-options} \
484 # Are there any further tests to perform?
485 # Note that if the program has special run-time requirements, running
486 # of the program can be delayed until here. Ditto for other situations.
487 # It would be a bit cumbersome though.
489 if ![string match ${dg-final-code} ""] {
490 regsub -all "\\\\(\[{}\])" ${dg-final-code} "\\1" dg-final-code
491 # Note that the use of `args' here makes this a varargs proc.
492 proc dg-final-proc { args } ${dg-final-code}
493 verbose "Running dg-final tests." 3
494 verbose "dg-final-proc:\n[info body dg-final-proc]" 4
495 if [catch "dg-final-proc $src1" errmsg] {
496 perror "$name: error executing dg-final: $errmsg"
497 # ??? The call to unresolved here is necessary to clear
498 # `errcnt'. What we really need is a proc like perror that
499 # doesn't set errcnt. It should also set exit_status to 1.
500 unresolved "$name: error executing dg-final: $errmsg"
504 # Clean up object files.
505 set files [glob -nocomplain ${sid}_*.o]
506 if { $files != "" } {
507 foreach objfile $files {
508 if { ![info exists gluefile] || $objfile != $gluefile } {
509 eval "file_on_host delete $objfile"
514 if { ![string compare "run" $compile_type] \
515 || ![string compare "link" $compile_type] } {
516 file_on_host delete $execname
521 # Utility for scanning a symbol in the final executable, invoked via dg-final.
522 # Call pass if pattern is present, otherwise fail.
524 # Argument 0 is the regexp to match.
525 # Argument 1 handles expected failures and the like
526 proc scan-symbol { args } {
529 upvar 2 execname execname
531 if { [llength $args] >= 2 } {
532 switch [dg-process-target [lindex $args 1]] {
535 "F" { setup_xfail "*-*-*" }
540 # Find nm like we find g++ in g++.exp.
541 if ![info exists nm] {
542 set nm [findfile $base_dir/../../../binutils/nm \
543 $base_dir/../../../binutils/nm \
544 [findfile $base_dir/../../nm $base_dir/../../nm \
545 [findfile $base_dir/nm $base_dir/nm \
547 verbose -log "nm is $nm"
550 set output_file "[glob -nocomplain $execname]"
551 if { $output_file == "" } {
552 fail "scan-symbol $args: dump file does not exist"
556 set fd [open "| $nm $output_file" r]
560 if [regexp -- [lindex $args 0] $text] {
561 pass "scan-symbol $args"
563 fail "scan-symbol $args"