1 # Copyright
(C
) 2009-2018 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 # A subroutine of lto_handle_diagnostics
: check
TEXT for the expected
20 # diagnostics
for one specific source file
, issuing PASS
/FAIL results.
21 #
Return TEXT, stripped of
any diagnostics that were handled.
23 #
NAME is the testcase
name to use when reporting PASS
/FAIL results.
24 # FILENAME is the
name (with full path
) of the file we
're interested in.
25 # MESSAGES_FOR_FILE is a list of expected messages, akin to DejaGnu's
26 #
"dg-messages" variable.
27 #
TEXT is the textual output from the LTO link.
29 proc lto_handle_diagnostics_for_file
{ name filename messages_for_file
text } {
30 global dg
-linenum-format
32 set filename_without_path
[file tail $filename
]
34 # This loop is adapted from the related part of DejaGnu
's dg-test,
35 # with changes as detailed below to cope with the LTO case.
37 foreach i ${messages_for_file} {
38 verbose "Scanning for message: $i" 4
40 # Remove all error messages for the line [lindex $i 0]
41 # in the source file. If we find any, success!
42 set line [lindex $i 0]
43 set pattern [lindex $i 2]
44 set comment [lindex $i 3]
45 verbose "line: $line" 4
46 verbose "pattern: $pattern" 4
47 verbose "comment: $comment" 4
48 #send_user "Before:\n$text\n"
50 # Unlike dg-test, we use $filename_without_path in this pattern.
51 # This is to ensure that we have the correct file/line combination.
52 # This imposes the restriction that the filename can't contain
53 #
any regexp control characters. We have to
strip the path
, since
54 # e.g. the
'+' in
"g++.dg" wouldn't be valid.
55 set pat
"(^|\n)(\[^\n\]+$filename_without_path$line\[^\n\]*($pattern)\[^\n\]*\n?)+"
56 if {[regsub
-all $pat $
text "\n" text]} {
57 set text [string trimleft $
text]
64 #send_user
"After:\n$text\n"
66 # $line will either be a formatted line number or a number all by
67 # itself.
Delete the formatting.
68 scan $line $
{dg
-linenum-format
} line
70 # Unlike dg
-test
, add the filename to the PASS
/FAIL message
(rather
71 # than just the line number
) so that the user can identify the
72 # pertinent directive.
73 set describe_where
"$filename_without_path line $line"
75 # Issue the PASS
/FAIL
, adding
"LTO" to the messages (e.g. "LTO errors")
76 # to distinguish them from the non
-LTO case
(in case we ever need to
78 switch [lindex $i
1] {
80 $ok
"$name $comment (test for LTO errors, $describe_where)"
83 x$ok
"$name $comment (test for LTO errors, $describe_where)"
86 $ok
"$name $comment (test for LTO warnings, $describe_where)"
89 x$ok
"$name $comment (test for LTO warnings, $describe_where)"
92 $uhoh
"$name $comment (test for LTO bogus messages, $describe_where)"
95 x$uhoh
"$name $comment (test for LTO bogus messages, $describe_where)"
98 $uhoh
"$name $comment (test for LTO build failure, $describe_where)"
101 x$uhoh
"$name $comment (test for LTO build failure, $describe_where)"
110 # Support
for checking
for link
-time diagnostics
: check
for
111 # the expected diagnostics within
TEXT, issuing PASS
/FAIL results.
112 #
Return TEXT, stripped of
any diagnostics that were handled.
114 #
TEXT is the textual output from the LTO link.
116 proc lto_handle_diagnostics
{ text } {
119 upvar dg
-messages
-by
-file messages_by_file
121 verbose
"lto_handle_diagnostics: entry: $text" 2
123 if { ![array
exists messages_by_file
] } {
124 error
"lto_handle_diagnostics: messages_by_file not defined"
127 foreach src
[lsort
[array names messages_by_file
]] {
128 set dg
-messages $messages_by_file
($src
)
129 verbose
" messages for $src: ${dg-messages}" 3
130 set text [lto_handle_diagnostics_for_file $testcase $src \
131 $
{dg
-messages
} $
text]
134 verbose
"lto_handle_diagnostics: exit: $text" 2
139 # Prune messages that aren
't useful.
141 proc lto_prune_warns { text } {
143 verbose "lto_prune_warns: entry: $text" 2
145 # Many tests that use visibility will still pass on platforms that don't support it.
146 regsub
-all
"(^|\n)\[^\n\]*: warning: visibility attribute not supported in this configuration; ignored\[^\n\]*" $text "" text
148 # Allow mixed
-language LTO tests to pass with make check
-c
++0x
149 regsub
-all
"(^|\n)\[^\n\]*: warning: command line option '-std=\[^\n\]*" $text "" text
151 # And
any stray location lines.
152 regsub
-all
"(^|\n)\[^\n\]*: In function \[^\n\]*" $text "" text
153 regsub
-all
"(^|\n)In file included from \[^\n\]*" $text "" text
154 regsub
-all
"(^|\n)\[ \t\]*from \[^\n\]*" $text "" text
156 # Sun
ld warns about common symbols with differing sizes. Unlike GNU
ld
157 #
--warn
-common
(off by default
), they cannot be disabled.
158 regsub
-all
"(^|\n)ld: warning: symbol \[`'\]\[^\n\]*' has differing sizes:" $text "" text
159 regsub
-all
"(^|\n)\[ \t\]*\[\(\]file \[^\n\]* value=\[^\n\]*; file \[^\n\]* value=\[^\n\]*\[)\];" $text "" text
160 regsub
-all
"(^|\n)\[ \t\]*\[^\n\]* definition taken" $text "" text
162 # Ignore informational notes.
163 regsub
-all
"(^|\n)\[^\n\]*: note: \[^\n\]*" $text "" text
165 verbose
"lto_prune_warns: exit: $text" 2
170 # lto_init
-- called at the start of each subdir of tests
172 proc lto_init
{ args } {
175 if {[info exists args] && $
args == "no-mathlib"} {
179 set dest
[target_info
name]
180 if [board_info $dest
exists mathlib
] {
181 set saved_mathlib
[board_info $dest mathlib
]
183 set board_info
($dest
,mathlib
) " "
186 # Each test is run with the compiler options from this list.
187 # The default option lists can be overridden by LTO_OPTIONS
="[list
188 #
{opts_1
} {opts_2
}...
{opts_n
}]" where opts_i are lists of options.
189 # You can put this in the environment before site.exp is written or
190 # add it to site.exp directly.
191 if ![info exists LTO_OPTIONS
] {
192 if [check_linker_plugin_available
] {
193 set LTO_OPTIONS
[list \
194 {-O0
-flto
-flto
-partition
=none -fuse
-linker
-plugin
} \
195 {-O2
-flto
-flto
-partition
=none -fuse
-linker
-plugin
-fno
-fat
-lto
-objects
} \
196 {-O0
-flto
-flto
-partition
=1to1
-fno
-use
-linker
-plugin
} \
197 {-O2
-flto
-flto
-partition
=1to1
-fno
-use
-linker
-plugin
} \
198 {-O0
-flto
-fuse
-linker
-plugin
-fno
-fat
-lto
-objects
} \
199 {-O2
-flto
-fuse
-linker
-plugin
} \
202 set LTO_OPTIONS
[list \
203 {-O0
-flto
-flto
-partition
=none } \
204 {-O2
-flto
-flto
-partition
=none } \
205 {-O0
-flto
-flto
-partition
=1to1
} \
206 {-O2
-flto
-flto
-partition
=1to1
} \
215 # lto_finish
-- called at the end of each subdir of tests
if mathlib is
219 proc lto_finish
{ } {
223 set dest
[target_info
name]
224 if [info exists saved_mathlib
] {
225 set board_info
($dest
,mathlib
) $saved_mathlib
226 } elseif
[board_info $dest
exists mathlib
] {
227 unset board_info
($dest
,mathlib
)
231 # Subsets of tests can be selectively disabled by members of this list
:
232 #
- ATTRIBUTE
: disable all tests using the __attribute__ extension
,
233 #
- COMPLEX
: disable all tests using the complex types feature
,
234 #
- COMPLEX_INT
: disable all tests using the complex integral types extension
,
235 #
- VA
: disable all tests using the
variable number of arguments feature
,
236 #
- VLA_IN_STRUCT
: disable all tests using the
variable-length arrays as
237 # structure members extension
,
238 #
- ZERO_ARRAY
: disable all tests using the zero
-sized arrays extension.
239 # The default skip lists can be overriden by
240 # LTO_SKIPS
="[list {skip_1}...{skip_n}]"
241 # where skip_i are skip identifiers. You can put this in the environment
242 # before site.exp is written or add it to site.exp directly.
243 if ![info exists LTO_SKIPS
] {
244 set LTO_SKIPS
[list
{}]
248 set lto_skip_list $LTO_SKIPS
254 # lto
-obj -- compile to an object file
256 # SOURCE is the source file
257 # DEST is the object file
258 # OPTALL is the list of compiler options to use with all tests
259 # OPTFILE is the list of compiler options to use with this file
260 # OPTSTR is the options to print with test messages
261 # XFAILDATA is the xfail data to be passed to the compiler
262 proc lto
-obj { source dest optall optfile optstr xfaildata
} {
265 global compiler_conditional_xfail_data
268 # Add the skip specifiers.
269 foreach skip $lto_skip_list
{
270 if { ![string match $skip
""] } {
271 lappend optall
"-DSKIP_$skip"
275 #
Set up the options
for compiling this file.
277 lappend options
"additional_flags=$optall $optfile"
279 set compiler_conditional_xfail_data $xfaildata
281 # Allow C source files to mix freely with other languages
282 if [ string match
"*.c" $source ] then {
283 set comp_output
[gcc_target_compile
"$source" "$dest" object $options]
285 set comp_output
[$
{tool
}_target_compile
"$source" "$dest" object $options]
287 # Prune unimportant visibility warnings before checking output.
288 set comp_output
[lto_prune_warns $comp_output
]
289 $
{tool
}_check_compile
"$testcase $dest assemble" $optstr $dest $comp_output
292 # lto
-link
-and
-maybe
-run
-- link the object files and run the executable
293 #
if compile_type is
set to
"run"
295 # TESTNAME is the mixture of object files to link
296 #
OBJLIST is the list of object files to link
297 # DEST is the
name of the executable
298 # OPTALL is a list of compiler and linker options to use
for all tests
299 # OPTFILE is a list of compiler and linker options to use
for this test
300 # OPTSTR is the list of options to list in messages
301 proc lto
-link
-and
-maybe
-run
{ testname
objlist dest optall optfile optstr
} {
307 upvar dg
-messages
-by
-file dg
-messages
-by
-file
309 verbose
"lto-link-and-maybe-run" 2
311 # Check that all of the objects were built successfully.
312 foreach
obj [split $
objlist] {
313 if ![file_on_host
exists $
obj] then {
314 unresolved
"$testcase $testname link $optstr"
315 unresolved
"$testcase $testname execute $optstr"
320 #
Set up the options
for linking this test.
322 lappend options
"additional_flags=$optall $optfile"
324 set target_board
[target_info
name]
327 # Some LTO tests
do relocatable linking. Some target boards
set
328 # a linker script which can
't be used for relocatable linking.
329 # Use the default linker script instead.
330 if { [lsearch -exact [split "$optall $optfile"] "-r"] >= 0 } {
334 if { $relocatable } {
335 set saved_ldscript [board_info $target_board ldscript]
336 set board_info($target_board,ldscript) ""
339 # Link the objects into an executable.
340 set comp_output [${tool}_target_compile "$objlist" $dest executable \
343 if { $relocatable } {
344 set board_info($target_board,ldscript) $saved_ldscript
347 # Check for diagnostics specified by directives
348 set comp_output [lto_handle_diagnostics $comp_output]
350 # Prune unimportant visibility warnings before checking output.
351 set comp_output [lto_prune_warns $comp_output]
353 if ![${tool}_check_compile "$testcase $testname link" $optstr \
354 $dest $comp_output] then {
355 if { ![string compare "execute" $compile_type] } {
356 unresolved "$testcase $testname execute $optstr"
361 # Return if we only needed to link.
362 if { ![string compare "link" $compile_type] } {
366 # Run the self-checking executable.
367 if ![string match "*/*" $dest] then {
370 set result [${tool}_load $dest "" ""]
371 set status [lindex $result 0]
372 if { $status == "pass" } then {
373 file_on_host delete $dest
375 $status "$testcase $testname execute $optstr"
378 # Potentially handle the given dg- directive (a list)
379 # Return true is the directive was handled, false otherwise.
381 proc lto-can-handle-directive { op } {
382 set cmd [lindex $op 0]
384 # dg-warning and dg-message append to dg-messages.
385 upvar dg-messages dg-messages
387 # A list of directives to recognize, and a list of directives
389 # For example, "dg-lto-warning" is implemented by calling "dg-warning".
390 set directives { dg-lto-warning dg-lto-message }
391 set remapped_directives { dg-warning dg-message }
393 set idx [lsearch -exact $directives $cmd]
395 verbose "remapping from: $op" 4
397 set remapped_cmd [lindex $remapped_directives $idx]
398 set op [lreplace $op 0 0 $remapped_cmd]
400 verbose "remapped to: $op" 4
402 set status [catch "$op" errmsg]
403 if { $status != 0 } {
404 if { 0 && [info exists errorInfo] } {
405 # This also prints a backtrace which will just confuse
406 # testcase writers, so it's disabled.
407 perror
"$name: $errorInfo\n"
409 perror
"$name: $errmsg for \"$op\"\n"
411 # ??? The
call to unresolved here is necessary to clear `errcnt
'.
412 # What we really need is a proc like perror that doesn't
set errcnt.
413 # It should also
set exit_status to
1.
414 unresolved
"$name: $errmsg for \"$op\""
423 # lto
-get-options
-main
-- get target requirements
for a test and
424 # options
for the primary source file and the test as a whole
426 # SRC is the full pathname of the primary source file.
427 proc lto
-get-options
-main
{ src
} {
429 global dg
-extra
-ld-options
430 global dg
-suppress
-ld-options
432 set dg
-extra
-ld-options
""
433 set dg
-suppress
-ld-options
""
435 # dg
-options sets a
variable called dg
-extra
-tool
-flags.
436 set dg
-extra
-tool
-flags
""
438 # dg
-options sets a
variable called tool_flags.
441 # dg
-require
-* sets dg
-do-what.
442 upvar dg
-do-what dg
-do-what
443 upvar dg
-final
-code dg
-final
-code
446 # dg
-warning and dg
-message append to dg
-messages.
447 upvar dg
-messages
-by
-file dg
-messages
-by
-file
450 set tmp
[dg
-get-options $src
]
451 verbose
"getting options for $src: $tmp"
453 set cmd
[lindex $op
0]
454 verbose
"cmd is $cmd"
455 if { [string match
"dg-skip-if" $cmd] \
456 ||
[string match
"dg-require-*" $cmd] } {
457 set status [catch
"$op" errmsg]
458 if { $
status != 0 } {
459 perror
"src: $errmsg for \"$op\"\n"
460 unresolved
"$src: $errmsg for \"$op\""
463 } elseif
{ [string match
"dg-lto-options" $cmd] } {
464 set op
[lreplace $op
0 0 "dg-options"]
465 set status [catch
"$op" errmsg]
466 if { $
status != 0 } {
467 perror
"src: $errmsg for \"$op\"\n"
468 unresolved
"$src: $errmsg for \"$op\""
471 } elseif
{ ![string compare
"dg-xfail-if" $cmd] \
472 ||
![string compare
"dg-options" $cmd] } {
473 warning
"lto.exp does not support $cmd in primary source file"
474 } elseif
{ ![string compare
"dg-lto-do" $cmd] } {
475 if { [llength $op
] > 3 } {
476 set kw
[lindex
[lindex $op
3] 0]
477 if [string match
"target" $kw] {
478 perror
"$src: dg-lto-do does not support \"target\""
479 } elseif
[string match
"xfail" $kw] {
480 perror
"$src: dg-lto-do does not support \"xfail\""
482 perror
"$src: dg-lto-do takes a single argument"
485 set dgdo
[lindex $op
2]
486 verbose
"dg-lto-do command for \"$op\" is $dgdo"
487 if { ![string compare
"assemble" $dgdo] } {
488 set compile_type
"assemble"
489 } elseif
{ ![string compare
"run" $dgdo] } {
490 set compile_type
"run"
491 } elseif
{ ![string compare
"link" $dgdo] } {
492 set compile_type
"link"
494 warning
"lto.exp does not support dg-lto-do $dgdo"
496 } elseif
{ ![string compare
"dg-extra-ld-options" $cmd] } {
497 if { [llength $op
] > 4 } {
498 error
"[lindex $op 0]: too many arguments"
500 if { [llength $op
] == 3
501 ||
([llength $op
] > 3
502 && [dg
-process
-target
[lindex $op
3]] == "S") } {
503 set dg
-extra
-ld-options
[lindex $op
2]
505 "dg-extra-ld-options for main is ${dg-extra-ld-options}"
508 } elseif
{ ![string compare
"dg-suppress-ld-options" $cmd] } {
509 if { [llength $op
] > 4 } {
510 error
"[lindex $op 0]: too many arguments"
512 if { [llength $op
] == 3
513 ||
([llength $op
] > 3
514 && [dg
-process
-target
[lindex $op
3]] == "S") } {
515 set dg
-suppress
-ld-options
[lindex $op
2]
517 "dg-suppress-ld-options for main is ${dg-suppress-ld-options}"
520 } elseif
{ ![string compare
"dg-final" $cmd] } {
521 if { [llength $op
] > 3 } {
522 error
"[lindex $op 0]: too many arguments"
524 append dg
-final
-code
"[lindex $op 2]\n"
526 } elseif
{ ![lto
-can
-handle
-directive $op
] } {
527 # Ignore unrecognized dg
- commands
, but warn about them.
528 warning
"lto.exp does not support $cmd"
532 verbose
"dg-messages: ${dg-messages}" 3
533 set dg
-messages
-by
-file
($src
) $
{dg
-messages
}
535 #
Return flags to use
for compiling the primary source file and
for
537 verbose
"dg-extra-tool-flags for main is ${dg-extra-tool-flags}"
538 return $
{dg
-extra
-tool
-flags
}
542 # lto
-get-options
-- get special tool flags to use
for a secondary
545 # SRC is the full pathname of the source file.
546 # The result is a list of options to use.
548 # This code is copied from proc dg
-test in dg.exp from DejaGNU.
549 proc lto
-get-options
{ src
} {
550 # dg
-options sets a
variable called dg
-extra
-tool
-flags.
551 set dg
-extra
-tool
-flags
""
553 # dg
-xfail
-if sets compiler_conditional_xfail_data.
554 global compiler_conditional_xfail_data
555 set compiler_conditional_xfail_data
""
557 # dg
-xfail
-if needs access to dg
-do-what.
558 upvar dg
-do-what dg
-do-what
560 # dg
-warning appends to dg
-messages.
561 upvar dg
-messages
-by
-file dg
-messages
-by
-file
564 set tmp
[dg
-get-options $src
]
566 set cmd
[lindex $op
0]
567 if { ![string compare
"dg-options" $cmd] \
568 ||
![string compare
"dg-xfail-if" $cmd] } {
569 set status [catch
"$op" errmsg]
570 if { $
status != 0 } {
571 perror
"src: $errmsg for \"$op\"\n"
572 unresolved
"$src: $errmsg for \"$op\""
575 } elseif
{ [string match
"dg-require-*" $cmd] } {
576 warning
"lto.exp does not support $cmd in secondary source files"
577 } elseif
{ ![lto
-can
-handle
-directive $op
] } {
578 # Ignore unrecognized dg
- commands
, but warn about them.
579 warning
"lto.exp does not support $cmd in secondary source files"
583 verbose
"dg-messages: ${dg-messages}" 3
584 if { [info exists dg
-messages
-by
-file
($src
)] } {
585 append dg
-messages
-by
-file
($src
) $
{dg
-messages
}
587 set dg
-messages
-by
-file
($src
) $
{dg
-messages
}
590 return $
{dg
-extra
-tool
-flags
}
593 # lto
-execute -- compile multi
-file tests
595 # SRC1 is the full pathname of the main file of the testcase.
596 # SID identifies a test suite in the names of temporary files.
597 proc lto
-execute { src1 sid
} {
599 global lto_option_list
604 global compiler_conditional_xfail_data
605 global dg
-do-what
-default
607 global dg
-extra
-ld-options
608 global dg
-suppress
-ld-options
611 global testname_with_flags
613 #
Get extra flags
for this test from the primary source file
, and
614 # process other dg
-* options that this suite supports. Warn about
616 verbose
"lto-execute: $src1" 1
617 set compile_type
"run"
618 set dg
-do-what
[list $
{dg
-do-what
-default
} "" P]
619 array
set dg
-messages
-by
-file
[list
]
620 set extra_flags
(0) [lto
-get-options
-main $src1
]
621 set compile_xfail
(0) ""
623 #
If the main file defines dg
-options
, those flags are used to
624 # overwrite the default lto_option_list taken from LTO_OPTIONS.
625 if { [string length $extra_flags
(0)] > 0 } {
626 set lto_option_list $extra_flags
(0)
627 set extra_flags
(0) ""
629 set lto_option_list $LTO_OPTIONS
632 #
Set up the names of the other source files.
633 set dir [file dirname $src1
]
634 set base
[file rootname $src1
]
635 set base
[string range $base
[string length $
dir] end
]
636 regsub
"_0" $base "" base
637 regsub
"/" $base "" base
642 set names
[glob
-nocomplain
-types f
-- "${dir}/${base}_${i}.*"]
643 if { [llength $
{names
}] > 1 } {
644 warning
"lto-execute: more than one file matched ${dir}/${base}_${i}.*"
646 if { [llength $
{names
}] == 1 } {
647 lappend src_list
[lindex $
{names
} 0]
655 # Use the dg
-options mechanism to specify extra flags
for each
656 # of the secondary files.
657 # The extra flags in each file are used to
compile that file
, and the
658 # extra flags in
*_0.
* are also used
for linking.
659 verbose
"\tsrc_list is: $src_list"
660 for {set i
1} {$i
< $num_srcs
} {incr i
} {
661 set extra_flags
($i
) [lto
-get-options
[lindex $src_list $i
]]
662 set compile_xfail
($i
) $compiler_conditional_xfail_data
665 #
Define the names of the object files.
667 for {set i
0} {$i
< $num_srcs
} {incr i
} {
668 lappend obj_list
"${sid}_${base}_${i}.o"
671 #
Get the base
name of this test
, for use in messages.
672 set testcase
[lindex $
{src_list
} 0]
674 # Remove the $srcdir and $tmpdir prefixes from $src1.
(It would
675 # be possible to use
"regsub" here, if we were careful to escape
676 # all regular expression characters in $srcdir and $tmpdir
, but
677 # that would be more complicated that this approach.
)
678 if {[string first
"$srcdir/" "${testcase}"] == 0} {
679 set testcase
[string range
"${testcase}" [string length "$srcdir/"] end]
681 if {[string first
"$tmpdir/" "$testcase"] == 0} {
682 set testcase
[string range
"$testcase" [string length "$tmpdir/"] end]
683 set testcase
"tmpdir-$testcase"
685 #
If we couldn
't rip $srcdir out of `src1' then just
do the best we can.
686 # The point is to reduce the unnecessary noise in the logs. Don
't strip
687 # out too much because different testcases with the same name can confuse
689 if [string match
"/*" $testcase] then {
690 set testcase
"[file tail [file dirname $src1]]/[file tail $src1]"
693 # Check whether this test is supported
for this target.
694 if { [lindex $
{dg
-do-what
} 1 ] == "N" } {
695 unsupported
"$testcase"
696 verbose
"$testcase not supported on this target, skipping it" 3
699 # Should be safe
for non
-fortran too but be paranoid..
700 if {$sid eq
"f_lto"} {
701 list
-module
-names $src_list
703 regsub
"_0.*" $testcase "" testcase
705 #
Set up the base
name of executable files so they
'll be unique.
706 regsub -all "\[./\]" $testcase "-" execbase
708 # Loop through all of the option lists used for this test.
710 foreach option $lto_option_list {
711 verbose "Testing $testcase, $option"
713 # There's a unique
name for each executable we generate.
714 set execname
"${execbase}-${count}1.exe"
717 file_on_host
delete $execname
719 #
Compile pieces with the compiler under test.
721 foreach src $src_list
obj $obj_list
{
722 lto
-obj $src $
obj $option $extra_flags
($i
) $option \
727 # Link
(using the compiler under test
), run
, and clean up tests.
728 if { ![string compare
"run" $compile_type] \
729 ||
![string compare
"link" $compile_type] } {
731 # Filter out
any link options we were asked to suppress.
733 foreach x
[split $option
] {
734 if {[lsearch $
{dg
-suppress
-ld-options
} $x
] == -1} {
738 set filtered
[join $reduced
" "]
740 lto
-link
-and
-maybe
-run \
741 "[lindex $obj_list 0]-[lindex $obj_list end]" \
742 $obj_list $execname $filtered $
{dg
-extra
-ld-options
} \
747 # Are there
any further tests to perform?
748 # Note that
if the
program has special run
-time requirements
, running
749 # of the
program can be delayed until here. Ditto
for other situations.
750 # It would be a bit cumbersome though.
752 if ![string match $
{dg
-final
-code
} ""] {
753 regsub
-all
"\\\\(\[{}\])" ${dg-final-code} "\\1" dg-final-code
754 # Note that the use of `
args' here makes this a varargs proc.
755 proc dg-final-proc { args } ${dg-final-code}
756 verbose "Running dg-final tests." 3
757 verbose "dg-final-proc:\n[info body dg-final-proc]" 4
758 if [catch "dg-final-proc $src1" errmsg] {
759 perror "$src1: error executing dg-final: $errmsg"
760 # ??? The call to unresolved here is necessary to clear
761 # `errcnt'. What we really need is a proc like perror that
762 # doesn
't set errcnt. It should also set exit_status to 1.
763 unresolved "$src1: error executing dg-final: $errmsg"
767 # Clean up object files.
768 set files [glob -nocomplain ${sid}_*.o]
769 if { $files != "" } {
770 foreach objfile $files {
771 if { ![info exists gluefile] || $objfile != $gluefile } {
772 eval "file_on_host delete $objfile"
777 # Clean up after -save-temps. The LTO tests don't use dg
-test
, so
778 # testname
-for-summary needs to be defined explicitly
for each
779 # file that needs to be removed.
780 set testname_with_flags $execname
782 eval
"cleanup-saved-temps"
784 for {set i
0} {$i
< $num_srcs
} {incr i
} {
785 set testname_with_flags
"${base}_${i}"
786 eval
"cleanup-saved-temps"
787 set testname_with_flags
"${sid}_${base}_${i}"
788 eval
"cleanup-saved-temps"
791 unset testname_with_flags
793 if { ![string compare
"run" $compile_type] \
794 ||
![string compare
"link" $compile_type] } {
795 file_on_host
delete $execname
797 # Should be safe
for non
-fortran too but be paranoid..
798 if {$sid eq
"f_lto"} {
804 # Utility
for scanning a symbol in the final executable
, invoked via dg
-final.
805 #
Call pass
if pattern is present
, otherwise fail.
807 #
Argument 0 is the regexp to match.
808 #
Argument 1 handles expected failures and the like
809 proc scan
-symbol
{ args } {
812 upvar
2 execname execname
814 if { [llength $
args] >= 2 } {
815 switch [dg
-process
-target
[lindex $
args 1]] {
818 "F" { setup_xfail "*-*-*" }
823 # Find nm like we find g
++ in g
++.exp.
824 if ![info exists nm
] {
825 set nm
[findfile $base_dir
/..
/..
/..
/binutils
/nm \
826 $base_dir
/..
/..
/..
/binutils
/nm \
827 [findfile $base_dir
/..
/..
/nm $base_dir
/..
/..
/nm \
828 [findfile $base_dir
/nm $base_dir
/nm \
830 verbose
-log "nm is $nm"
833 set output_file
"[glob -nocomplain $execname]"
834 if { $output_file
== "" } {
835 fail
"scan-symbol $args: dump file does not exist"
839 set fd
[open
"| $nm $output_file" r]
843 if [regexp
-- [lindex $
args 0] $
text] {
844 pass
"scan-symbol $args"
846 fail
"scan-symbol $args"
850 #
Call pass
if object readelf is ok
, otherwise fail.
851 # example
: /* { dg
-final
{ object
-readelf Tag_ABI_enum_size
int} } */
852 proc object
-readelf
{ args } {
855 upvar
2 execname execname
857 if { [llength $
args] < 2 } {
858 error
"object-readelf: too few arguments"
861 if { [llength $
args] > 3 } {
862 error
"object-readelf: too many arguments"
865 if { [llength $
args] >= 3 } {
866 switch [dg
-process
-target
[lindex $
args 2]] {
869 "F" { setup_xfail "*-*-*" }
874 # Find size like we find g
++ in g
++.exp.
875 if ![info exists readelf
] {
876 set readelf
[findfile $base_dir
/..
/..
/..
/binutils
/readelf \
877 $base_dir
/..
/..
/..
/binutils
/readelf \
878 [findfile $base_dir
/..
/..
/readelf $base_dir
/..
/..
/readelf \
879 [findfile $base_dir
/readelf $base_dir
/readelf \
880 [transform readelf
]]]]
881 verbose
-log "readelf is $readelf"
884 set what
[lindex $
args 0]
885 set with
[lindex $
args 1]
887 if ![file_on_host
exists $execname
] {
888 verbose
-log "$execname does not exist"
889 unresolved
"object-readelf $what "
893 set output
[remote_exec host
"$readelf -A" "$execname"]
894 set status [lindex $output
0]
895 if { $
status != 0 } {
896 verbose
-log "object-readelf: $readelf failed"
897 unresolved
"object-readelf $what $execname"
901 set text [lindex $output
1]
902 set lines
[split $
text "\n"]
907 set line_tex
[lindex $lines $i
]
908 if { [llength $
{line_tex
}] > 1} {
910 if [regexp
-- $what $line_tex
] {
911 set match
[regexp
-- $with $line_tex
]
919 verbose
-log "$what size is $with;"
921 pass
"object-readelf $what size is correct."
923 fail
"object-readelf $what size is incorrect."