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 # MESSAGES_BY_FILE is a dict
; the keys are source files
(with paths
)
115 # the
values are lists of expected messages
, akin to DejaGnu
's "dg-messages"
117 # TEXT is the textual output from the LTO link.
119 proc lto_handle_diagnostics { messages_by_file text } {
122 verbose "lto_handle_diagnostics: entry: $text" 2
123 verbose " messages_by_file $messages_by_file" 3
125 dict for {src dg-messages} $messages_by_file {
126 set text [lto_handle_diagnostics_for_file $testcase $src \
127 ${dg-messages} $text]
130 verbose "lto_handle_diagnostics: exit: $text" 2
135 # Prune messages that aren't useful.
137 proc lto_prune_warns
{ text } {
139 verbose
"lto_prune_warns: entry: $text" 2
141 # Many tests that use visibility will still pass
on platforms that don
't support it.
142 regsub -all "(^|\n)\[^\n\]*: warning: visibility attribute not supported in this configuration; ignored\[^\n\]*" $text "" text
144 # Allow mixed-language LTO tests to pass with make check-c++0x
145 regsub -all "(^|\n)\[^\n\]*: warning: command line option '-std
=\
[^
\n\
]*" $text "" text
147 # And
any stray location lines.
148 regsub
-all
"(^|\n)\[^\n\]*: In function \[^\n\]*" $text "" text
149 regsub
-all
"(^|\n)In file included from \[^\n\]*" $text "" text
150 regsub
-all
"(^|\n)\[ \t\]*from \[^\n\]*" $text "" text
152 # Sun
ld warns about common symbols with differing sizes. Unlike GNU
ld
153 #
--warn
-common
(off by default
), they cannot be disabled.
154 regsub
-all
"(^|\n)ld: warning: symbol \[`'\]\[^\n\]*' has differing sizes:" $text "" text
155 regsub
-all
"(^|\n)\[ \t\]*\[\(\]file \[^\n\]* value=\[^\n\]*; file \[^\n\]* value=\[^\n\]*\[)\];" $text "" text
156 regsub
-all
"(^|\n)\[ \t\]*\[^\n\]* definition taken" $text "" text
158 # Ignore informational notes.
159 regsub
-all
"(^|\n)\[^\n\]*: note: \[^\n\]*" $text "" text
161 verbose
"lto_prune_warns: exit: $text" 2
166 # lto_init
-- called at the start of each subdir of tests
168 proc lto_init
{ args } {
171 if {[info exists args] && $
args == "no-mathlib"} {
175 set dest
[target_info
name]
176 if [board_info $dest
exists mathlib
] {
177 set saved_mathlib
[board_info $dest mathlib
]
179 set board_info
($dest
,mathlib
) " "
182 # Each test is run with the compiler options from this list.
183 # The default option lists can be overridden by LTO_OPTIONS
="[list
184 #
{opts_1
} {opts_2
}...
{opts_n
}]" where opts_i are lists of options.
185 # You can put this in the environment before site.exp is written or
186 # add it to site.exp directly.
187 if ![info exists LTO_OPTIONS
] {
188 if [check_linker_plugin_available
] {
189 set LTO_OPTIONS
[list \
190 {-O0
-flto
-flto
-partition
=none -fuse
-linker
-plugin
} \
191 {-O2
-flto
-flto
-partition
=none -fuse
-linker
-plugin
-fno
-fat
-lto
-objects
} \
192 {-O0
-flto
-flto
-partition
=1to1
-fno
-use
-linker
-plugin
} \
193 {-O2
-flto
-flto
-partition
=1to1
-fno
-use
-linker
-plugin
} \
194 {-O0
-flto
-fuse
-linker
-plugin
-fno
-fat
-lto
-objects
} \
195 {-O2
-flto
-fuse
-linker
-plugin
} \
198 set LTO_OPTIONS
[list \
199 {-O0
-flto
-flto
-partition
=none } \
200 {-O2
-flto
-flto
-partition
=none } \
201 {-O0
-flto
-flto
-partition
=1to1
} \
202 {-O2
-flto
-flto
-partition
=1to1
} \
211 # lto_finish
-- called at the end of each subdir of tests
if mathlib is
215 proc lto_finish
{ } {
219 set dest
[target_info
name]
220 if [info exists saved_mathlib
] {
221 set board_info
($dest
,mathlib
) $saved_mathlib
222 } elseif
[board_info $dest
exists mathlib
] {
223 unset board_info
($dest
,mathlib
)
227 # Subsets of tests can be selectively disabled by members of this list
:
228 #
- ATTRIBUTE
: disable all tests using the __attribute__ extension
,
229 #
- COMPLEX
: disable all tests using the complex types feature
,
230 #
- COMPLEX_INT
: disable all tests using the complex integral types extension
,
231 #
- VA
: disable all tests using the
variable number of arguments feature
,
232 #
- VLA_IN_STRUCT
: disable all tests using the
variable-length arrays as
233 # structure members extension
,
234 #
- ZERO_ARRAY
: disable all tests using the zero
-sized arrays extension.
235 # The default skip lists can be overriden by
236 # LTO_SKIPS
="[list {skip_1}...{skip_n}]"
237 # where skip_i are skip identifiers. You can put this in the environment
238 # before site.exp is written or add it to site.exp directly.
239 if ![info exists LTO_SKIPS
] {
240 set LTO_SKIPS
[list
{}]
244 set lto_skip_list $LTO_SKIPS
250 # lto
-obj -- compile to an object file
252 # SOURCE is the source file
253 # DEST is the object file
254 # OPTALL is the list of compiler options to use with all tests
255 # OPTFILE is the list of compiler options to use with this file
256 # OPTSTR is the options to print with test messages
257 # XFAILDATA is the xfail data to be passed to the compiler
258 proc lto
-obj { source dest optall optfile optstr xfaildata
} {
261 global compiler_conditional_xfail_data
264 # Add the skip specifiers.
265 foreach skip $lto_skip_list
{
266 if { ![string match $skip
""] } {
267 lappend optall
"-DSKIP_$skip"
271 #
Set up the options
for compiling this file.
273 lappend options
"additional_flags=$optall $optfile"
275 set compiler_conditional_xfail_data $xfaildata
277 # Allow C source files to mix freely with other languages
278 if [ string match
"*.c" $source ] then {
279 set comp_output
[gcc_target_compile
"$source" "$dest" object $options]
281 set comp_output
[$
{tool
}_target_compile
"$source" "$dest" object $options]
283 # Prune unimportant visibility warnings before checking output.
284 set comp_output
[lto_prune_warns $comp_output
]
285 $
{tool
}_check_compile
"$testcase $dest assemble" $optstr $dest $comp_output
288 # lto
-link
-and
-maybe
-run
-- link the object files and run the executable
289 #
if compile_type is
set to
"run"
291 # TESTNAME is the mixture of object files to link
292 #
OBJLIST is the list of object files to link
293 # DEST is the
name of the executable
294 # OPTALL is a list of compiler and linker options to use
for all tests
295 # OPTFILE is a list of compiler and linker options to use
for this test
296 # OPTSTR is the list of options to list in messages
297 # MESSAGES_BY_FILE is a dict of
(src
, dg
-messages
)
298 proc lto
-link
-and
-maybe
-run
{ testname
objlist dest optall optfile optstr \
305 verbose
"lto-link-and-maybe-run" 2
306 verbose
" messages_by_file $messages_by_file" 3
308 # Check that all of the objects were built successfully.
309 foreach
obj [split $
objlist] {
310 if ![file_on_host
exists $
obj] then {
311 unresolved
"$testcase $testname link $optstr"
312 unresolved
"$testcase $testname execute $optstr"
317 #
Set up the options
for linking this test.
319 lappend options
"additional_flags=$optall $optfile"
321 set target_board
[target_info
name]
324 # Some LTO tests
do relocatable linking. Some target boards
set
325 # a linker script which can
't be used for relocatable linking.
326 # Use the default linker script instead.
327 if { [lsearch -exact [split "$optall $optfile"] "-r"] >= 0 } {
331 if { $relocatable } {
332 set saved_ldscript [board_info $target_board ldscript]
333 set board_info($target_board,ldscript) ""
336 # Link the objects into an executable.
337 set comp_output [${tool}_target_compile "$objlist" $dest executable \
340 if { $relocatable } {
341 set board_info($target_board,ldscript) $saved_ldscript
344 # Check for diagnostics specified by directives
345 set comp_output [lto_handle_diagnostics $messages_by_file $comp_output]
347 # Prune unimportant visibility warnings before checking output.
348 set comp_output [lto_prune_warns $comp_output]
350 if ![${tool}_check_compile "$testcase $testname link" $optstr \
351 $dest $comp_output] then {
352 if { ![string compare "execute" $compile_type] } {
353 unresolved "$testcase $testname execute $optstr"
358 # Return if we only needed to link.
359 if { ![string compare "link" $compile_type] } {
363 # Run the self-checking executable.
364 if ![string match "*/*" $dest] then {
367 set result [${tool}_load $dest "" ""]
368 set status [lindex $result 0]
369 if { $status == "pass" } then {
370 file_on_host delete $dest
372 $status "$testcase $testname execute $optstr"
375 # Potentially handle the given dg- directive (a list)
376 # Return true is the directive was handled, false otherwise.
378 proc lto-can-handle-directive { op } {
379 set cmd [lindex $op 0]
381 # dg-warning and dg-message append to dg-messages.
382 upvar dg-messages dg-messages
384 # A list of directives to recognize, and a list of directives
386 # For example, "dg-lto-warning" is implemented by calling "dg-warning".
387 set directives { dg-lto-warning dg-lto-message }
388 set remapped_directives { dg-warning dg-message }
390 set idx [lsearch -exact $directives $cmd]
392 verbose "remapping from: $op" 4
394 set remapped_cmd [lindex $remapped_directives $idx]
395 set op [lreplace $op 0 0 $remapped_cmd]
397 verbose "remapped to: $op" 4
399 set status [catch "$op" errmsg]
400 if { $status != 0 } {
401 if { 0 && [info exists errorInfo] } {
402 # This also prints a backtrace which will just confuse
403 # testcase writers, so it's disabled.
404 perror
"$name: $errorInfo\n"
406 perror
"$name: $errmsg for \"$op\"\n"
408 # ??? The
call to unresolved here is necessary to clear `errcnt
'.
409 # What we really need is a proc like perror that doesn't
set errcnt.
410 # It should also
set exit_status to
1.
411 unresolved
"$name: $errmsg for \"$op\""
420 # lto
-get-options
-main
-- get target requirements
for a test and
421 # options
for the primary source file and the test as a whole
423 # SRC is the full pathname of the primary source file.
424 proc lto
-get-options
-main
{ src
} {
426 global dg
-extra
-ld-options
427 global dg
-suppress
-ld-options
429 set dg
-extra
-ld-options
""
430 set dg
-suppress
-ld-options
""
432 # dg
-options sets a
variable called dg
-extra
-tool
-flags.
433 set dg
-extra
-tool
-flags
""
435 # dg
-options sets a
variable called tool_flags.
438 # dg
-require
-* sets dg
-do-what.
439 upvar dg
-do-what dg
-do-what
440 upvar dg
-final
-code dg
-final
-code
443 # dg
-warning and dg
-message append to dg
-messages.
444 upvar dg
-messages
-by
-file dg
-messages
-by
-file
447 set tmp
[dg
-get-options $src
]
448 verbose
"getting options for $src: $tmp"
450 set cmd
[lindex $op
0]
451 verbose
"cmd is $cmd"
452 if { [string match
"dg-skip-if" $cmd] \
453 ||
[string match
"dg-require-*" $cmd] } {
454 set status [catch
"$op" errmsg]
455 if { $
status != 0 } {
456 perror
"src: $errmsg for \"$op\"\n"
457 unresolved
"$src: $errmsg for \"$op\""
460 } elseif
{ [string match
"dg-lto-options" $cmd] } {
461 set op
[lreplace $op
0 0 "dg-options"]
462 set status [catch
"$op" errmsg]
463 if { $
status != 0 } {
464 perror
"src: $errmsg for \"$op\"\n"
465 unresolved
"$src: $errmsg for \"$op\""
468 } elseif
{ ![string compare
"dg-xfail-if" $cmd] \
469 ||
![string compare
"dg-options" $cmd] } {
470 warning
"lto.exp does not support $cmd in primary source file"
471 } elseif
{ ![string compare
"dg-lto-do" $cmd] } {
472 if { [llength $op
] > 3 } {
473 set kw
[lindex
[lindex $op
3] 0]
474 if [string match
"target" $kw] {
475 perror
"$src: dg-lto-do does not support \"target\""
476 } elseif
[string match
"xfail" $kw] {
477 perror
"$src: dg-lto-do does not support \"xfail\""
479 perror
"$src: dg-lto-do takes a single argument"
482 set dgdo
[lindex $op
2]
483 verbose
"dg-lto-do command for \"$op\" is $dgdo"
484 if { ![string compare
"assemble" $dgdo] } {
485 set compile_type
"assemble"
486 } elseif
{ ![string compare
"run" $dgdo] } {
487 set compile_type
"run"
488 } elseif
{ ![string compare
"link" $dgdo] } {
489 set compile_type
"link"
491 warning
"lto.exp does not support dg-lto-do $dgdo"
493 } elseif
{ ![string compare
"dg-extra-ld-options" $cmd] } {
494 if { [llength $op
] > 4 } {
495 error
"[lindex $op 0]: too many arguments"
497 if { [llength $op
] == 3
498 ||
([llength $op
] > 3
499 && [dg
-process
-target
[lindex $op
3]] == "S") } {
500 set dg
-extra
-ld-options
[lindex $op
2]
502 "dg-extra-ld-options for main is ${dg-extra-ld-options}"
505 } elseif
{ ![string compare
"dg-suppress-ld-options" $cmd] } {
506 if { [llength $op
] > 4 } {
507 error
"[lindex $op 0]: too many arguments"
509 if { [llength $op
] == 3
510 ||
([llength $op
] > 3
511 && [dg
-process
-target
[lindex $op
3]] == "S") } {
512 set dg
-suppress
-ld-options
[lindex $op
2]
514 "dg-suppress-ld-options for main is ${dg-suppress-ld-options}"
517 } elseif
{ ![string compare
"dg-final" $cmd] } {
518 if { [llength $op
] > 3 } {
519 error
"[lindex $op 0]: too many arguments"
521 append dg
-final
-code
"[lindex $op 2]\n"
523 } elseif
{ ![lto
-can
-handle
-directive $op
] } {
524 # Ignore unrecognized dg
- commands
, but warn about them.
525 warning
"lto.exp does not support $cmd"
529 verbose
"dg-messages: ${dg-messages}" 3
530 dict append dg
-messages
-by
-file $src $
{dg
-messages
}
532 #
Return flags to use
for compiling the primary source file and
for
534 verbose
"dg-extra-tool-flags for main is ${dg-extra-tool-flags}"
535 return $
{dg
-extra
-tool
-flags
}
539 # lto
-get-options
-- get special tool flags to use
for a secondary
542 # SRC is the full pathname of the source file.
543 # The result is a list of options to use.
545 # This code is copied from proc dg
-test in dg.exp from DejaGNU.
546 proc lto
-get-options
{ src
} {
547 # dg
-options sets a
variable called dg
-extra
-tool
-flags.
548 set dg
-extra
-tool
-flags
""
550 # dg
-xfail
-if sets compiler_conditional_xfail_data.
551 global compiler_conditional_xfail_data
552 set compiler_conditional_xfail_data
""
554 # dg
-xfail
-if needs access to dg
-do-what.
555 upvar dg
-do-what dg
-do-what
557 # dg
-warning appends to dg
-messages.
558 upvar dg
-messages
-by
-file dg
-messages
-by
-file
561 set tmp
[dg
-get-options $src
]
563 set cmd
[lindex $op
0]
564 if { ![string compare
"dg-options" $cmd] \
565 ||
![string compare
"dg-xfail-if" $cmd] } {
566 set status [catch
"$op" errmsg]
567 if { $
status != 0 } {
568 perror
"src: $errmsg for \"$op\"\n"
569 unresolved
"$src: $errmsg for \"$op\""
572 } elseif
{ [string match
"dg-require-*" $cmd] } {
573 warning
"lto.exp does not support $cmd in secondary source files"
574 } elseif
{ ![lto
-can
-handle
-directive $op
] } {
575 # Ignore unrecognized dg
- commands
, but warn about them.
576 warning
"lto.exp does not support $cmd in secondary source files"
580 verbose
"dg-messages: ${dg-messages}" 3
581 dict append dg
-messages
-by
-file $src $
{dg
-messages
}
583 return $
{dg
-extra
-tool
-flags
}
586 # lto
-execute -- compile multi
-file tests
588 # SRC1 is the full pathname of the main file of the testcase.
589 # SID identifies a test suite in the names of temporary files.
590 proc lto
-execute { src1 sid
} {
592 global lto_option_list
597 global compiler_conditional_xfail_data
598 global dg
-do-what
-default
600 global dg
-extra
-ld-options
601 global dg
-suppress
-ld-options
604 global testname_with_flags
606 #
Get extra flags
for this test from the primary source file
, and
607 # process other dg
-* options that this suite supports. Warn about
609 verbose
"lto-execute: $src1" 1
610 set compile_type
"run"
611 set dg
-do-what
[list $
{dg
-do-what
-default
} "" P]
612 set dg
-messages
-by
-file
[dict create
]
613 set extra_flags
(0) [lto
-get-options
-main $src1
]
614 set compile_xfail
(0) ""
616 #
If the main file defines dg
-options
, those flags are used to
617 # overwrite the default lto_option_list taken from LTO_OPTIONS.
618 if { [string length $extra_flags
(0)] > 0 } {
619 set lto_option_list $extra_flags
(0)
620 set extra_flags
(0) ""
622 set lto_option_list $LTO_OPTIONS
625 #
Set up the names of the other source files.
626 set dir [file dirname $src1
]
627 set base
[file rootname $src1
]
628 set base
[string range $base
[string length $
dir] end
]
629 regsub
"_0" $base "" base
630 regsub
"/" $base "" base
635 set names
[glob
-nocomplain
-types f
-- "${dir}/${base}_${i}.*"]
636 if { [llength $
{names
}] > 1 } {
637 warning
"lto-execute: more than one file matched ${dir}/${base}_${i}.*"
639 if { [llength $
{names
}] == 1 } {
640 lappend src_list
[lindex $
{names
} 0]
648 # Use the dg
-options mechanism to specify extra flags
for each
649 # of the secondary files.
650 # The extra flags in each file are used to
compile that file
, and the
651 # extra flags in
*_0.
* are also used
for linking.
652 verbose
"\tsrc_list is: $src_list"
653 for {set i
1} {$i
< $num_srcs
} {incr i
} {
654 set extra_flags
($i
) [lto
-get-options
[lindex $src_list $i
]]
655 set compile_xfail
($i
) $compiler_conditional_xfail_data
658 #
Define the names of the object files.
660 for {set i
0} {$i
< $num_srcs
} {incr i
} {
661 lappend obj_list
"${sid}_${base}_${i}.o"
664 #
Get the base
name of this test
, for use in messages.
665 set testcase
[lindex $
{src_list
} 0]
667 # Remove the $srcdir and $tmpdir prefixes from $src1.
(It would
668 # be possible to use
"regsub" here, if we were careful to escape
669 # all regular expression characters in $srcdir and $tmpdir
, but
670 # that would be more complicated that this approach.
)
671 if {[string first
"$srcdir/" "${testcase}"] == 0} {
672 set testcase
[string range
"${testcase}" [string length "$srcdir/"] end]
674 if {[string first
"$tmpdir/" "$testcase"] == 0} {
675 set testcase
[string range
"$testcase" [string length "$tmpdir/"] end]
676 set testcase
"tmpdir-$testcase"
678 #
If we couldn
't rip $srcdir out of `src1' then just
do the best we can.
679 # The point is to reduce the unnecessary noise in the logs. Don
't strip
680 # out too much because different testcases with the same name can confuse
682 if [string match
"/*" $testcase] then {
683 set testcase
"[file tail [file dirname $src1]]/[file tail $src1]"
686 # Check whether this test is supported
for this target.
687 if { [lindex $
{dg
-do-what
} 1 ] == "N" } {
688 unsupported
"$testcase"
689 verbose
"$testcase not supported on this target, skipping it" 3
692 # Should be safe
for non
-fortran too but be paranoid..
693 if {$sid eq
"f_lto"} {
694 list
-module
-names $src_list
696 regsub
"_0.*" $testcase "" testcase
698 #
Set up the base
name of executable files so they
'll be unique.
699 regsub -all "\[./\]" $testcase "-" execbase
701 # Loop through all of the option lists used for this test.
703 foreach option $lto_option_list {
704 verbose "Testing $testcase, $option"
706 # There's a unique
name for each executable we generate.
707 set execname
"${execbase}-${count}1.exe"
710 file_on_host
delete $execname
712 #
Compile pieces with the compiler under test.
714 foreach src $src_list
obj $obj_list
{
715 lto
-obj $src $
obj $option $extra_flags
($i
) $option \
720 # Link
(using the compiler under test
), run
, and clean up tests.
721 if { ![string compare
"run" $compile_type] \
722 ||
![string compare
"link" $compile_type] } {
724 # Filter out
any link options we were asked to suppress.
726 foreach x
[split $option
] {
727 if {[lsearch $
{dg
-suppress
-ld-options
} $x
] == -1} {
731 set filtered
[join $reduced
" "]
733 lto
-link
-and
-maybe
-run \
734 "[lindex $obj_list 0]-[lindex $obj_list end]" \
735 $obj_list $execname $filtered $
{dg
-extra
-ld-options
} \
736 $filtered $
{dg
-messages
-by
-file
}
740 # Are there
any further tests to perform?
741 # Note that
if the
program has special run
-time requirements
, running
742 # of the
program can be delayed until here. Ditto
for other situations.
743 # It would be a bit cumbersome though.
745 if ![string match $
{dg
-final
-code
} ""] {
746 regsub
-all
"\\\\(\[{}\])" ${dg-final-code} "\\1" dg-final-code
747 # Note that the use of `
args' here makes this a varargs proc.
748 proc dg-final-proc { args } ${dg-final-code}
749 verbose "Running dg-final tests." 3
750 verbose "dg-final-proc:\n[info body dg-final-proc]" 4
751 if [catch "dg-final-proc $src1" errmsg] {
752 perror "$src1: error executing dg-final: $errmsg"
753 # ??? The call to unresolved here is necessary to clear
754 # `errcnt'. What we really need is a proc like perror that
755 # doesn
't set errcnt. It should also set exit_status to 1.
756 unresolved "$src1: error executing dg-final: $errmsg"
760 # Clean up object files.
761 set files [glob -nocomplain ${sid}_*.o]
762 if { $files != "" } {
763 foreach objfile $files {
764 if { ![info exists gluefile] || $objfile != $gluefile } {
765 eval "file_on_host delete $objfile"
770 # Clean up after -save-temps. The LTO tests don't use dg
-test
, so
771 # testname
-for-summary needs to be defined explicitly
for each
772 # file that needs to be removed.
773 set testname_with_flags $execname
775 eval
"cleanup-saved-temps"
777 for {set i
0} {$i
< $num_srcs
} {incr i
} {
778 set testname_with_flags
"${base}_${i}"
779 eval
"cleanup-saved-temps"
780 set testname_with_flags
"${sid}_${base}_${i}"
781 eval
"cleanup-saved-temps"
784 unset testname_with_flags
786 if { ![string compare
"run" $compile_type] \
787 ||
![string compare
"link" $compile_type] } {
788 file_on_host
delete $execname
790 # Should be safe
for non
-fortran too but be paranoid..
791 if {$sid eq
"f_lto"} {
797 # Utility
for scanning a symbol in the final executable
, invoked via dg
-final.
798 #
Call pass
if pattern is present
, otherwise fail.
800 #
Argument 0 is the regexp to match.
801 #
Argument 1 handles expected failures and the like
802 proc scan
-symbol
{ args } {
805 upvar
2 execname execname
807 if { [llength $
args] >= 2 } {
808 switch [dg
-process
-target
[lindex $
args 1]] {
811 "F" { setup_xfail "*-*-*" }
816 # Find nm like we find g
++ in g
++.exp.
817 if ![info exists nm
] {
818 set nm
[findfile $base_dir
/..
/..
/..
/binutils
/nm \
819 $base_dir
/..
/..
/..
/binutils
/nm \
820 [findfile $base_dir
/..
/..
/nm $base_dir
/..
/..
/nm \
821 [findfile $base_dir
/nm $base_dir
/nm \
823 verbose
-log "nm is $nm"
826 set output_file
"[glob -nocomplain $execname]"
827 if { $output_file
== "" } {
828 fail
"scan-symbol $args: dump file does not exist"
832 set fd
[open
"| $nm $output_file" r]
836 if [regexp
-- [lindex $
args 0] $
text] {
837 pass
"scan-symbol $args"
839 fail
"scan-symbol $args"
843 #
Call pass
if object readelf is ok
, otherwise fail.
844 # example
: /* { dg
-final
{ object
-readelf Tag_ABI_enum_size
int} } */
845 proc object
-readelf
{ args } {
848 upvar
2 execname execname
850 if { [llength $
args] < 2 } {
851 error
"object-readelf: too few arguments"
854 if { [llength $
args] > 3 } {
855 error
"object-readelf: too many arguments"
858 if { [llength $
args] >= 3 } {
859 switch [dg
-process
-target
[lindex $
args 2]] {
862 "F" { setup_xfail "*-*-*" }
867 # Find size like we find g
++ in g
++.exp.
868 if ![info exists readelf
] {
869 set readelf
[findfile $base_dir
/..
/..
/..
/binutils
/readelf \
870 $base_dir
/..
/..
/..
/binutils
/readelf \
871 [findfile $base_dir
/..
/..
/readelf $base_dir
/..
/..
/readelf \
872 [findfile $base_dir
/readelf $base_dir
/readelf \
873 [transform readelf
]]]]
874 verbose
-log "readelf is $readelf"
877 set what
[lindex $
args 0]
878 set with
[lindex $
args 1]
880 if ![file_on_host
exists $execname
] {
881 verbose
-log "$execname does not exist"
882 unresolved
"object-readelf $what "
886 set output
[remote_exec host
"$readelf -A" "$execname"]
887 set status [lindex $output
0]
888 if { $
status != 0 } {
889 verbose
-log "object-readelf: $readelf failed"
890 unresolved
"object-readelf $what $execname"
894 set text [lindex $output
1]
895 set lines
[split $
text "\n"]
900 set line_tex
[lindex $lines $i
]
901 if { [llength $
{line_tex
}] > 1} {
903 if [regexp
-- $what $line_tex
] {
904 set match
[regexp
-- $with $line_tex
]
912 verbose
-log "$what size is $with;"
914 pass
"object-readelf $what size is correct."
916 fail
"object-readelf $what size is incorrect."