1 # Copyright
(C
) 2009-2013 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 # Allow mixed
-language LTO tests to pass with make check
-c
++0x
29 regsub
-all
"(^|\n)\[^\n\]*: warning: command line option '-std=\[^\n\]*" $text "" text
31 # And
any stray location lines.
32 regsub
-all
"(^|\n)\[^\n\]*: In function \[^\n\]*" $text "" text
33 regsub
-all
"(^|\n)In file included from \[^\n\]*" $text "" text
34 regsub
-all
"(^|\n)\[ \t\]*from \[^\n\]*" $text "" text
36 # Sun
ld warns about common symbols with differing sizes. Unlike GNU
ld
37 #
--warn
-common
(off by default
), they cannot be disabled.
38 regsub
-all
"(^|\n)ld: warning: symbol \[`'\]\[^\n\]*' has differing sizes:" $text "" text
39 regsub
-all
"(^|\n)\[ \t\]*\[\(\]file \[^\n\]* value=\[^\n\]*; file \[^\n\]* value=\[^\n\]*\[)\];" $text "" text
40 regsub
-all
"(^|\n)\[ \t\]*\[^\n\]* definition taken" $text "" text
42 verbose
"lto_prune_warns: exit: $text" 2
47 # lto_init
-- called at the start of each subdir of tests
49 proc lto_init
{ args } {
52 if {[info exists args] && $
args == "no-mathlib"} {
56 set dest
[target_info
name]
57 if [board_info $dest
exists mathlib
] {
58 set saved_mathlib
[board_info $dest mathlib
]
60 set board_info
($dest
,mathlib
) " "
63 # Each test is run with the compiler options from this list.
64 # The default option lists can be overridden by LTO_OPTIONS
="[list
65 #
{opts_1
} {opts_2
}...
{opts_n
}]" where opts_i are lists of options.
66 # You can put this in the environment before site.exp is written or
67 # add it to site.exp directly.
68 if ![info exists LTO_OPTIONS
] {
69 if [check_linker_plugin_available
] {
70 set LTO_OPTIONS
[list \
71 {-O0
-flto
-flto
-partition
=none -fuse
-linker
-plugin
} \
72 {-O2
-flto
-flto
-partition
=none -fuse
-linker
-plugin
-fno
-fat
-lto
-objects
} \
73 {-O0
-flto
-flto
-partition
=1to1
-fno
-use
-linker
-plugin
} \
74 {-O2
-flto
-flto
-partition
=1to1
-fno
-use
-linker
-plugin
} \
75 {-O0
-flto
-fuse
-linker
-plugin
-fno
-fat
-lto
-objects
} \
76 {-O2
-flto
-fuse
-linker
-plugin
} \
79 set LTO_OPTIONS
[list \
80 {-O0
-flto
-flto
-partition
=none } \
81 {-O2
-flto
-flto
-partition
=none } \
82 {-O0
-flto
-flto
-partition
=1to1
} \
83 {-O2
-flto
-flto
-partition
=1to1
} \
92 # lto_finish
-- called at the end of each subdir of tests
if mathlib is
100 set dest
[target_info
name]
101 if [info exists saved_mathlib
] {
102 set board_info
($dest
,mathlib
) $saved_mathlib
103 } elseif
[board_info $dest
exists mathlib
] {
104 unset board_info
($dest
,mathlib
)
108 # Subsets of tests can be selectively disabled by members of this list
:
109 #
- ATTRIBUTE
: disable all tests using the __attribute__ extension
,
110 #
- COMPLEX
: disable all tests using the complex types feature
,
111 #
- COMPLEX_INT
: disable all tests using the complex integral types extension
,
112 #
- VA
: disable all tests using the
variable number of arguments feature
,
113 #
- VLA_IN_STRUCT
: disable all tests using the
variable-length arrays as
114 # structure members extension
,
115 #
- ZERO_ARRAY
: disable all tests using the zero
-sized arrays extension.
116 # The default skip lists can be overriden by
117 # LTO_SKIPS
="[list {skip_1}...{skip_n}]"
118 # where skip_i are skip identifiers. You can put this in the environment
119 # before site.exp is written or add it to site.exp directly.
120 if ![info exists LTO_SKIPS
] {
121 set LTO_SKIPS
[list
{}]
125 set lto_skip_list $LTO_SKIPS
131 # lto
-obj -- compile to an object file
133 # SOURCE is the source file
134 # DEST is the object file
135 # OPTALL is the list of compiler options to use with all tests
136 # OPTFILE is the list of compiler options to use with this file
137 # OPTSTR is the options to print with test messages
138 # XFAILDATA is the xfail data to be passed to the compiler
139 proc lto
-obj { source dest optall optfile optstr xfaildata
} {
142 global compiler_conditional_xfail_data
145 # Add the skip specifiers.
146 foreach skip $lto_skip_list
{
147 if { ![string match $skip
""] } {
148 lappend optall
"-DSKIP_$skip"
152 #
Set up the options
for compiling this file.
154 lappend options
"additional_flags=$optall $optfile"
156 set compiler_conditional_xfail_data $xfaildata
158 # Allow C source files to mix freely with other languages
159 if [ string match
"*.c" $source ] then {
160 set comp_output
[gcc_target_compile
"$source" "$dest" object $options]
162 set comp_output
[$
{tool
}_target_compile
"$source" "$dest" object $options]
164 # Prune unimportant visibility warnings before checking output.
165 set comp_output
[lto_prune_warns $comp_output
]
166 $
{tool
}_check_compile
"$testcase $dest assemble" $optstr $dest $comp_output
169 # lto
-link
-and
-maybe
-run
-- link the object files and run the executable
170 #
if compile_type is
set to
"run"
172 # TESTNAME is the mixture of object files to link
173 #
OBJLIST is the list of object files to link
174 # DEST is the
name of the executable
175 # OPTALL is a list of compiler and linker options to use
for all tests
176 # OPTFILE is a list of compiler and linker options to use
for this test
177 # OPTSTR is the list of options to list in messages
178 proc lto
-link
-and
-maybe
-run
{ testname
objlist dest optall optfile optstr
} {
184 # Check that all of the objects were built successfully.
185 foreach
obj [split $
objlist] {
186 if ![file_on_host
exists $
obj] then {
187 unresolved
"$testcase $testname link $optstr"
188 unresolved
"$testcase $testname execute $optstr"
193 #
Set up the options
for linking this test.
195 lappend options
"additional_flags=$optall $optfile"
197 set target_board
[target_info
name]
200 # Some LTO tests
do relocatable linking. Some target boards
set
201 # a linker script which can
't be used for relocatable linking.
202 # Use the default linker script instead.
203 if { [lsearch -exact [split "$optall $optfile"] "-r"] >= 0 } {
207 if { $relocatable } {
208 set saved_ldscript [board_info $target_board ldscript]
209 set board_info($target_board,ldscript) ""
212 # Link the objects into an executable.
213 set comp_output [${tool}_target_compile "$objlist" $dest executable \
216 if { $relocatable } {
217 set board_info($target_board,ldscript) $saved_ldscript
220 # Prune unimportant visibility warnings before checking output.
221 set comp_output [lto_prune_warns $comp_output]
223 if ![${tool}_check_compile "$testcase $testname link" $optstr \
224 $dest $comp_output] then {
225 unresolved "$testcase $testname execute $optstr"
229 # Return if we only needed to link.
230 if { ![string compare "link" $compile_type] } {
234 # Run the self-checking executable.
235 if ![string match "*/*" $dest] then {
238 set result [${tool}_load $dest "" ""]
239 set status [lindex $result 0]
240 if { $status == "pass" } then {
241 file_on_host delete $dest
243 $status "$testcase $testname execute $optstr"
246 # lto-get-options-main -- get target requirements for a test and
247 # options for the primary source file and the test as a whole
249 # SRC is the full pathname of the primary source file.
250 proc lto-get-options-main { src } {
252 global dg-extra-ld-options
253 global dg-suppress-ld-options
255 set dg-extra-ld-options ""
256 set dg-suppress-ld-options ""
258 # dg-options sets a variable called dg-extra-tool-flags.
259 set dg-extra-tool-flags ""
261 # dg-options sets a variable called tool_flags.
264 # dg-require-* sets dg-do-what.
265 upvar dg-do-what dg-do-what
266 upvar dg-final-code dg-final-code
269 set tmp [dg-get-options $src]
270 verbose "getting options for $src: $tmp"
272 set cmd [lindex $op 0]
273 verbose "cmd is $cmd"
274 if { [string match "dg-skip-if" $cmd] \
275 || [string match "dg-require-*" $cmd] } {
276 set status [catch "$op" errmsg]
277 if { $status != 0 } {
278 perror "src: $errmsg for \"$op\"\n"
279 unresolved "$src: $errmsg for \"$op\""
282 } elseif { [string match "dg-lto-options" $cmd] } {
283 set op [lreplace $op 0 0 "dg-options"]
284 set status [catch "$op" errmsg]
285 if { $status != 0 } {
286 perror "src: $errmsg for \"$op\"\n"
287 unresolved "$src: $errmsg for \"$op\""
290 } elseif { ![string compare "dg-xfail-if" $cmd] \
291 || ![string compare "dg-options" $cmd] } {
292 warning "lto.exp does not support $cmd in primary source file"
293 } elseif { ![string compare "dg-lto-do" $cmd] } {
294 if { [llength $op] > 3 } {
295 set kw [lindex [lindex $op 3] 0]
296 if [string match "target" $kw] {
297 perror "$src: dg-lto-do does not support \"target\""
298 } elseif [string match "xfail" $kw] {
299 perror "$src: dg-lto-do does not support \"xfail\""
301 perror "$src: dg-lto-do takes a single argument"
304 set dgdo [lindex $op 2]
305 verbose "dg-lto-do command for \"$op\" is $dgdo"
306 if { ![string compare "assemble" $dgdo] } {
307 set compile_type "assemble"
308 } elseif { ![string compare "run" $dgdo] } {
309 set compile_type "run"
310 } elseif { ![string compare "link" $dgdo] } {
311 set compile_type "link"
313 warning "lto.exp does not support dg-lto-do $dgdo"
315 } elseif { ![string compare "dg-extra-ld-options" $cmd] } {
316 if { [llength $op] > 4 } {
317 error "[lindex $op 0]: too many arguments"
319 if { [llength $op] == 3
320 || ([llength $op] > 3
321 && [dg-process-target [lindex $op 3]] == "S") } {
322 set dg-extra-ld-options [lindex $op 2]
324 "dg-extra-ld-options for main is ${dg-extra-ld-options}"
327 } elseif { ![string compare "dg-suppress-ld-options" $cmd] } {
328 if { [llength $op] > 4 } {
329 error "[lindex $op 0]: too many arguments"
331 if { [llength $op] == 3
332 || ([llength $op] > 3
333 && [dg-process-target [lindex $op 3]] == "S") } {
334 set dg-suppress-ld-options [lindex $op 2]
336 "dg-suppress-ld-options for main is ${dg-suppress-ld-options}"
339 } elseif { ![string compare "dg-final" $cmd] } {
340 if { [llength $op] > 3 } {
341 error "[lindex $op 0]: too many arguments"
343 append dg-final-code "[lindex $op 2]\n"
346 # Ignore unrecognized dg- commands, but warn about them.
347 warning "lto.exp does not support $cmd"
351 # Return flags to use for compiling the primary source file and for
353 verbose "dg-extra-tool-flags for main is ${dg-extra-tool-flags}"
354 return ${dg-extra-tool-flags}
358 # lto-get-options -- get special tool flags to use for a secondary
361 # SRC is the full pathname of the source file.
362 # The result is a list of options to use.
364 # This code is copied from proc dg-test in dg.exp from DejaGNU.
365 proc lto-get-options { src } {
366 # dg-options sets a variable called dg-extra-tool-flags.
367 set dg-extra-tool-flags ""
369 # dg-xfail-if sets compiler_conditional_xfail_data.
370 global compiler_conditional_xfail_data
371 set compiler_conditional_xfail_data ""
373 # dg-xfail-if needs access to dg-do-what.
374 upvar dg-do-what dg-do-what
376 set tmp [dg-get-options $src]
378 set cmd [lindex $op 0]
379 if { ![string compare "dg-options" $cmd] \
380 || ![string compare "dg-xfail-if" $cmd] } {
381 set status [catch "$op" errmsg]
382 if { $status != 0 } {
383 perror "src: $errmsg for \"$op\"\n"
384 unresolved "$src: $errmsg for \"$op\""
387 } elseif { [string match "dg-require-*" $cmd] } {
388 warning "lto.exp does not support $cmd in secondary source files"
390 # Ignore unrecognized dg- commands, but warn about them.
391 warning "lto.exp does not support $cmd in secondary source files"
395 return ${dg-extra-tool-flags}
398 # lto-execute -- compile multi-file tests
400 # SRC1 is the full pathname of the main file of the testcase.
401 # SID identifies a test suite in the names of temporary files.
402 proc lto-execute { src1 sid } {
404 global lto_option_list
409 global compiler_conditional_xfail_data
410 global dg-do-what-default
412 global dg-extra-ld-options
413 global dg-suppress-ld-options
417 # Get extra flags for this test from the primary source file, and
418 # process other dg-* options that this suite supports. Warn about
420 verbose "lto-execute: $src1" 1
421 set compile_type "run"
422 set dg-do-what [list ${dg-do-what-default} "" P]
423 set extra_flags(0) [lto-get-options-main $src1]
424 set compile_xfail(0) ""
426 # If the main file defines dg-options, those flags are used to
427 # overwrite the default lto_option_list taken from LTO_OPTIONS.
428 if { [string length $extra_flags(0)] > 0 } {
429 set lto_option_list $extra_flags(0)
430 set extra_flags(0) ""
432 set lto_option_list $LTO_OPTIONS
435 # Set up the names of the other source files.
436 set dir [file dirname $src1]
437 set base [file rootname $src1]
438 set base [string range $base [string length $dir] end]
439 regsub "_0" $base "" base
440 regsub "/" $base "" base
445 set names [glob -nocomplain -types f -- "${dir}/${base}_${i}.*"]
446 if { [llength ${names}] > 1 } {
447 warning "lto-execute: more than one file matched ${dir}/${base}_${i}.*"
449 if { [llength ${names}] == 1 } {
450 lappend src_list [lindex ${names} 0]
458 # Use the dg-options mechanism to specify extra flags for each
459 # of the secondary files.
460 # The extra flags in each file are used to compile that file, and the
461 # extra flags in *_0.* are also used for linking.
462 verbose "\tsrc_list is: $src_list"
463 for {set i 1} {$i < $num_srcs} {incr i} {
464 set extra_flags($i) [lto-get-options [lindex $src_list $i]]
465 set compile_xfail($i) $compiler_conditional_xfail_data
468 # Define the names of the object files.
470 for {set i 0} {$i < $num_srcs} {incr i} {
471 lappend obj_list "${sid}_${base}_${i}.o"
474 # Get the base name of this test, for use in messages.
475 set testcase [lindex ${src_list} 0]
477 # Remove the $srcdir and $tmpdir prefixes from $src1. (It would
478 # be possible to use "regsub" here, if we were careful to escape
479 # all regular expression characters in $srcdir and $tmpdir, but
480 # that would be more complicated that this approach.)
481 if {[string first "$srcdir/" "${testcase}"] == 0} {
482 set testcase [string range "${testcase}" [string length "$srcdir/"] end]
484 if {[string first "$tmpdir/" "$testcase"] == 0} {
485 set testcase [string range "$testcase" [string length "$tmpdir/"] end]
486 set testcase "tmpdir-$testcase"
488 # If we couldn't rip $srcdir out of `src1
' then just do the best we can.
489 # The point is to reduce the unnecessary noise in the logs. Don't
strip
490 # out too much because different testcases with the same
name can confuse
492 if [string match "/*" $testcase] then {
493 set testcase "[file tail [file dirname $src1]]/[file tail $src1]"
496 # Check whether this test is supported for this target.
497 if { [lindex ${dg-do-what} 1 ] == "N" } {
498 unsupported "$testcase"
499 verbose "$testcase not supported on this target, skipping it" 3
502 # Should be safe for non-fortran too but be paranoid..
503 if {$sid eq "f_lto"} {
504 list-module-names $src_list
506 regsub "_0.*" $testcase "" testcase
508 # Set up the base name of executable files so they'll be unique.
509 regsub
-all
"\[./\]" $testcase "-" execbase
511 # Loop through all of the option lists used
for this test.
513 foreach option $lto_option_list
{
514 verbose
"Testing $testcase, $option"
516 # There
's a unique name for each executable we generate.
517 set execname "${execbase}-${count}1.exe"
520 file_on_host delete $execname
522 # Compile pieces with the compiler under test.
524 foreach src $src_list obj $obj_list {
525 lto-obj $src $obj $option $extra_flags($i) $option \
530 # Link (using the compiler under test), run, and clean up tests.
531 if { ![string compare "run" $compile_type] \
532 || ![string compare "link" $compile_type] } {
534 # Filter out any link options we were asked to suppress.
536 foreach x [split $option] {
537 if {[lsearch ${dg-suppress-ld-options} $x] == -1} {
541 set filtered [join $reduced " "]
543 lto-link-and-maybe-run \
544 "[lindex $obj_list 0]-[lindex $obj_list end]" \
545 $obj_list $execname $filtered ${dg-extra-ld-options} \
550 # Are there any further tests to perform?
551 # Note that if the program has special run-time requirements, running
552 # of the program can be delayed until here. Ditto for other situations.
553 # It would be a bit cumbersome though.
555 if ![string match ${dg-final-code} ""] {
556 regsub -all "\\\\(\[{}\])" ${dg-final-code} "\\1" dg-final-code
557 # Note that the use of `args' here makes this a varargs proc.
558 proc dg
-final
-proc
{ args } $
{dg
-final
-code
}
559 verbose
"Running dg-final tests." 3
560 verbose
"dg-final-proc:\n[info body dg-final-proc]" 4
561 if [catch
"dg-final-proc $src1" errmsg] {
562 perror
"$name: error executing dg-final: $errmsg"
563 # ??? The
call to unresolved here is necessary to clear
564 # `errcnt
'. What we really need is a proc like perror that
565 # doesn't
set errcnt. It should also
set exit_status to
1.
566 unresolved
"$name: error executing dg-final: $errmsg"
570 # Clean up object files.
571 set files
[glob
-nocomplain $
{sid
}_
*.o
]
572 if { $files
!= "" } {
573 foreach objfile $files
{
574 if { ![info exists gluefile
] || $objfile
!= $gluefile
} {
575 eval
"file_on_host delete $objfile"
580 if { ![string compare
"run" $compile_type] \
581 ||
![string compare
"link" $compile_type] } {
582 file_on_host
delete $execname
584 # Should be safe
for non
-fortran too but be paranoid..
585 if {$sid eq
"f_lto"} {
591 # Utility
for scanning a symbol in the final executable
, invoked via dg
-final.
592 #
Call pass
if pattern is present
, otherwise fail.
594 #
Argument 0 is the regexp to match.
595 #
Argument 1 handles expected failures and the like
596 proc scan
-symbol
{ args } {
599 upvar
2 execname execname
601 if { [llength $
args] >= 2 } {
602 switch [dg
-process
-target
[lindex $
args 1]] {
605 "F" { setup_xfail "*-*-*" }
610 # Find nm like we find g
++ in g
++.exp.
611 if ![info exists nm
] {
612 set nm
[findfile $base_dir
/..
/..
/..
/binutils
/nm \
613 $base_dir
/..
/..
/..
/binutils
/nm \
614 [findfile $base_dir
/..
/..
/nm $base_dir
/..
/..
/nm \
615 [findfile $base_dir
/nm $base_dir
/nm \
617 verbose
-log "nm is $nm"
620 set output_file
"[glob -nocomplain $execname]"
621 if { $output_file
== "" } {
622 fail
"scan-symbol $args: dump file does not exist"
626 set fd
[open
"| $nm $output_file" r]
630 if [regexp
-- [lindex $
args 0] $
text] {
631 pass
"scan-symbol $args"
633 fail
"scan-symbol $args"