1 # Copyright
(C
) 2003, 2005, 2008, 2009, 2010, 2011, 2014, 2019 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 this
program; see the file COPYING3.
If not see
15 #
<http
://www.gnu.org
/licenses
/>.
17 proc load_gcc_lib
{ filename
} {
18 global srcdir loaded_libs
19 load_file $srcdir
/..
/..
/gcc
/testsuite
/lib
/$filename
20 set loaded_libs
($filename
) ""
25 load_gcc_lib target
-supports.exp
26 load_gcc_lib target
-supports
-dg.exp
27 load_gcc_lib target
-libpath.exp
28 load_gcc_lib wrapper.exp
30 proc check_effective_target_gccbug
{ } {
35 #
Return 1 if the target matches the effective target
'arg', 0 otherwise.
36 # This can be used with
any check_
* proc that takes no
argument and
37 # returns only
1 or
0. It could be used with check_
* procs that take
38 # arguments with keywords that pass particular arguments.
40 proc is
-effective
-target
{ arg } {
43 if { ![info exists et_index
] } {
44 # Initialize the effective target index that is used in some
45 # check_effective_target_
* procs.
48 if { [info procs check_effective_target_$
{arg}] != [list
] } {
49 set selected
[check_effective_target_$
{arg}]
51 error
"unknown effective target keyword `$arg'"
53 verbose
"is-effective-target: $arg $selected" 2
57 proc is
-effective
-target
-keyword
{ arg } {
58 if { [info procs check_effective_target_$
{arg}] != [list
] } {
65 # Intercept the
call to the DejaGnu version of dg
-process
-target to
66 # support use of an effective
-target keyword in place of a list of
67 # target triplets to xfail or skip a test.
69 # The
argument to dg
-process
-target is the keyword
"target" or "xfail"
70 # followed by a selector
:
71 # target
-triplet
-1 ...
72 # effective
-target
-keyword
75 #
For a target list the result is
"S" if the target is selected, "N" otherwise.
76 #
For an xfail list the result is
"F" if the target is affected, "P" otherwise.
78 # In contexts that allow either
"target" or "xfail" the argument can be
79 # target selector1 xfail selector2
80 # which returns
"N" if selector1 is not selected, otherwise the result of
83 # A selector expression appears within curly braces and uses a single logical
84 # operator
: !, &&, or ||. An operand is another selector expression
, an
85 # effective
-target keyword
, or a list of target triplets within quotes or
88 if { [info procs saved
-dg
-process
-target
] == [list
] } {
89 rename dg
-process
-target saved
-dg
-process
-target
91 # Evaluate an operand within a selector expression.
92 proc selector_opd
{ op
} {
95 set answer
[ expr
{ [dg
-process
-target $selector
] == "S" } ]
96 verbose
"selector_opd: `$op' $answer" 2
100 # Evaluate a target triplet list within a selector expression.
101 # Unlike other operands
, this needs to be expanded from a list to
102 # the same string as
"target".
103 proc selector_list
{ op
} {
104 set selector
"target [join $op]"
105 set answer
[ expr
{ [dg
-process
-target $selector
] == "S" } ]
106 verbose
"selector_list: `$op' $answer" 2
110 # Evaluate a selector expression.
111 proc selector_expression
{ exp
} {
112 if { [llength $exp
] == 2 } {
113 if [string match
"!" [lindex $exp 0]] {
114 set op1
[lindex $exp
1]
115 set answer
[expr
{ ! [selector_opd $op1
] }]
117 # Assume it
's a list of target triplets.
118 set answer [selector_list $exp]
120 } elseif { [llength $exp] == 3 } {
121 set op1 [lindex $exp 0]
122 set opr [lindex $exp 1]
123 set op2 [lindex $exp 2]
124 if [string match "&&" $opr] {
125 set answer [expr { [selector_opd $op1] && [selector_opd $op2] }]
126 } elseif [string match "||" $opr] {
127 set answer [expr { [selector_opd $op1] || [selector_opd $op2] }]
129 # Assume it's a list of target triplets.
130 set answer
[selector_list $exp
]
133 # Assume it
's a list of target triplets.
134 set answer [selector_list $exp]
137 verbose "selector_expression: `$exp' $answer
" 2
141 # Evaluate
"target selector" or "xfail selector".
143 proc dg
-process
-target
-1 { args } {
144 verbose
"dg-process-target-1: `$args'" 2
146 # Extract the
'what' keyword from the
argument list.
147 set selector
[string trim
[lindex $
args 0]]
148 if [regexp
"^xfail " $selector] {
150 } elseif
[regexp
"^target " $selector] {
153 error
"syntax error in target selector \"$selector\""
156 # Extract the rest of the list
, which might be a keyword.
157 regsub
"^${what}" $selector "" rest
158 set rest
[string trim $rest
]
160 if [is
-effective
-target
-keyword $rest
] {
161 # The selector is an effective target keyword.
162 if [is
-effective
-target $rest
] {
163 return [expr
{ $what
== "xfail" ? "F" : "S" }]
165 return [expr
{ $what
== "xfail" ? "P" : "N" }]
169 if [string match
"{*}" $rest] {
170 if [selector_expression
[lindex $rest
0]] {
171 return [expr
{ $what
== "xfail" ? "F" : "S" }]
173 return [expr
{ $what
== "xfail" ? "P" : "N" }]
177 # The selector is not an effective
-target keyword
, so process
178 # the list of target triplets.
179 return [saved
-dg
-process
-target $selector
]
182 # Intercept calls to the DejaGnu function. In addition to
183 # processing
"target selector" or "xfail selector", handle
184 #
"target selector1 xfail selector2".
186 proc dg
-process
-target
{ args } {
187 verbose
"replacement dg-process-target: `$args'" 2
189 set selector
[string trim
[lindex $
args 0]]
191 #
If the
argument list contains both
'target' and
'xfail',
192 # process
'target' and
, if that succeeds
, process
'xfail'.
193 if [regexp
"^target .* xfail .*" $selector] {
194 set xfail_index
[string first
"xfail" $selector]
195 set xfail_selector
[string range $selector $xfail_index end
]
196 set target_selector
[string range $selector
0 [expr $xfail_index
-1]]
197 set target_selector
[string trim $target_selector
]
198 if { [dg
-process
-target
-1 $target_selector
] == "N" } {
201 return [dg
-process
-target
-1 $xfail_selector
]
204 return [dg
-process
-target
-1 $selector
]
208 #
Define libffi callbacks
for dg.exp.
210 proc libffi
-dg
-test
-1 { target_compile prog do_what extra_tool_flags
} {
212 # To
get all
\n in dg
-output test strings to match printf output
213 # in a
system that outputs it as
\015\012 (i.e. not just
\012), we
214 # need to change all
\n into
\r?
\n. As there is no dejagnu flag
215 # or hook to
do that
, we simply change the
text being tested.
216 # Unfortunately
, we have to know that the
variable is called
217 # dg
-output
-text and lives in the caller of libffi
-dg
-test
, which
218 # is two calls up. Overriding proc dg
-output would be longer and
219 # would necessarily have the same assumption.
220 upvar
2 dg
-output
-text output_match
222 if { [llength $output_match
] > 1 } {
223 regsub
-all
"\n" [lindex $output_match 1] "\r?\n" x
224 set output_match
[lreplace $output_match
1 1 $x
]
227 #
Set up the compiler flags
, based
on what we
're going to do.
232 set compile_type "assembly"
233 set output_file "[file rootname [file tail $prog]].s"
236 set compile_type "executable"
237 set output_file "[file rootname [file tail $prog]].exe"
238 # The following line is needed for targets like the i960 where
239 # the default output file is b.out. Sigh.
242 set compile_type "executable"
243 # FIXME: "./" is to cope with "." not being in $PATH.
244 # Should this be handled elsewhere?
246 set output_file "./[file rootname [file tail $prog]].exe"
247 # This is the only place where we care if an executable was
248 # created or not. If it was, dg.exp will try to run it.
249 remote_file build delete $output_file;
252 perror "$do_what: not a valid dg-do keyword"
257 if { $extra_tool_flags != "" } {
258 lappend options "additional_flags=$extra_tool_flags"
261 set comp_output [libffi_target_compile "$prog" "$output_file" "$compile_type" $options];
264 return [list $comp_output $output_file]
268 proc libffi-dg-test { prog do_what extra_tool_flags } {
269 return [libffi-dg-test-1 target_compile $prog $do_what $extra_tool_flags]
272 proc libffi-dg-prune { target_triplet text } {
273 # We get this with some qemu emulated systems (eg. ppc64le-linux-gnu)
274 regsub -all "(^|\n)\[^\n\]*unable to perform all requested operations" $text "" text
278 proc libffi-init { args } {
279 global gluefile wrap_flags;
286 global libffi_include
287 global libffi_link_flags
289 global ld_library_path
290 global compiler_vendor
292 set blddirffi [lookfor_file [get_multilibs] libffi]
293 verbose "libffi $blddirffi"
294 set blddircxx [lookfor_file [get_multilibs] libstdc++-v3]
295 verbose "libstdc++ $blddircxx"
297 set compiler_vendor "gnu"
299 if { [string match $compiler_vendor "gnu"] } {
300 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
302 set gccdir [file dirname $gccdir]
304 verbose "gccdir $gccdir"
306 set ld_library_path "."
307 append ld_library_path ":${gccdir}"
309 set compiler "${gccdir}/xgcc"
310 if { [is_remote host] == 0 && [which $compiler] != 0 } {
311 foreach i "[exec $compiler --print-multi-lib]" {
313 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
314 set mldir [string trimright $mldir "\;@"]
315 if { "$mldir" == "." } {
318 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
319 append ld_library_path ":${gccdir}/${mldir}"
325 # add the library path for libffi.
326 append ld_library_path ":${blddirffi}/.libs"
327 # add the library path for libstdc++ as well.
328 append ld_library_path ":${blddircxx}/src/.libs"
330 verbose "ld_library_path: $ld_library_path"
332 # Point to the Libffi headers in libffi.
333 set libffi_include "${blddirffi}/include"
334 verbose "libffi_include $libffi_include"
336 set libffi_dir "${blddirffi}/.libs"
337 verbose "libffi_dir $libffi_dir"
338 if { $libffi_dir != "" } {
339 set libffi_dir [file dirname ${libffi_dir}]
340 if [istarget *-*-darwin*] {
341 set libffi_link_flags "-B${libffi_dir}/.libs"
342 lappend libffi_link_flags "-B${blddircxx}/src/.libs"
344 set libffi_link_flags "-L${libffi_dir}/.libs"
345 lappend libffi_link_flags "-L${blddircxx}/src/.libs"
349 set_ld_library_path_env_vars
350 libffi_maybe_build_wrapper "${objdir}/testglue.o"
353 proc libffi_exit { } {
356 if [info exists gluefile] {
357 file_on_build delete $gluefile;
362 proc libffi_target_compile { source dest type options } {
363 global gluefile wrap_flags;
367 global libffi_link_flags
368 global libffi_include
369 global target_triplet
370 global compiler_vendor
372 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
373 lappend options "libs=${gluefile}"
374 lappend options "ldflags=$wrap_flags"
377 if { $blddirffi != "" } {
378 # If '--with
-build
-sysroot
=[...
]' was specified, use it for build-tree
380 global SYSROOT_CFLAGS_FOR_TARGET
381 lappend options "additional_flags=${SYSROOT_CFLAGS_FOR_TARGET}"
384 # TOOL_OPTIONS must come first, so that it doesn't override testcase
386 if [info exists TOOL_OPTIONS
] {
387 lappend options
"additional_flags=$TOOL_OPTIONS"
390 # search
for ffi_mips.h in srcdir
, too
391 lappend options
"additional_flags=-I${libffi_include} -I${srcdir}/../include -I${libffi_include}/.."
392 lappend options
"additional_flags=${libffi_link_flags}"
394 # Darwin needs a stack execution allowed flag.
396 if { [istarget
"*-*-darwin9*"] || [istarget "*-*-darwin1*"]
397 ||
[istarget
"x86_64-*-darwin2*"] } {
398 lappend options
"additional_flags=-Wl,-allow_stack_execute"
399 lappend options
"additional_flags=-Wl,-search_paths_first"
402 #
If you
're building the compiler with --prefix set to a place
403 # where it's not yet installed
, then the linker won
't be able to
404 # find the libgcc used by libffi.dylib. We could pass the
405 # -dylib_file option, but that's complicated
, and it
's much easier
406 # to just make the linker find libgcc using -L options.
407 if { [string match "*-*-darwin*" $target_triplet] } {
408 lappend options "libs= -shared-libgcc"
411 if { [string match "*-*-openbsd*" $target_triplet] } {
412 lappend options "libs= -lpthread"
415 lappend options "libs= -lffi"
417 if { [string match "aarch64*-*-linux*" $target_triplet] } {
418 lappend options "libs= -lpthread"
421 if { [string match "*.cc" $source] } {
422 lappend options "ldflags=-shared-libgcc -lstdc++"
425 if { [string match "arc*-*-linux*" $target_triplet] } {
426 lappend options "libs= -lpthread"
429 verbose "options: $options"
430 return [target_compile $source $dest $type $options]
433 # TEST should be a preprocessor condition. Returns true if it holds.
434 proc libffi_feature_test { test } {
435 set src "ffitest[pid].c"
437 set f [open $src "w"]
438 puts $f "#include <ffi.h>"
442 puts $f "# error Failed $test"
446 set lines [libffi_target_compile $src /dev/null assembly ""]
449 return [string match "" $lines]
455 # search_for -- looks for a string match in a file
457 proc search_for { file pattern } {
458 set fd [open $file r]
459 while { [gets $fd cur_line]>=0 } {
460 if [string match "*$pattern*" $cur_line] then {
469 # Modified dg-runtest that can cycle through a list of optimization options
471 proc libffi-dg-runtest { testcases default-extra-flags } {
474 foreach test $testcases {
475 # If we're only testing specific files and this isn
't one of
477 if ![runtest_file_p $runtests $test] {
481 # Look for a loop within the source code - if we don't find one
,
482 # don
't pass -funroll[-all]-loops.
483 global torture_with_loops torture_without_loops
484 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
485 set option_list $torture_with_loops
487 set option_list $torture_without_loops
490 set nshort [file tail [file dirname $test]]/[file tail $test]
492 foreach flags $option_list {
493 verbose "Testing $nshort, $flags" 1
494 dg-test $test $flags ${default-extra-flags}
499 proc run-many-tests { testcases extra_flags } {
500 global compiler_vendor
503 switch $compiler_vendor {
505 set common "-W -Wall"
506 if [info exists env(LIBFFI_TEST_OPTIMIZATION)] {
507 set optimizations [ list $env(LIBFFI_TEST_OPTIMIZATION) ]
509 set optimizations { "-O0" "-O2" }
513 set common "-W -Wall -Wno-psabi"
514 if [info exists env(LIBFFI_TEST_OPTIMIZATION)] {
515 set optimizations [ list $env(LIBFFI_TEST_OPTIMIZATION) ]
517 set optimizations { "-O0" "-O2" }
521 # Assume we are using the vendor compiler.
523 if [info exists env(LIBFFI_TEST_OPTIMIZATION)] {
524 set optimizations [ list $env(LIBFFI_TEST_OPTIMIZATION) ]
526 set optimizations { "" }
531 info exists env(LD_LIBRARY_PATH)
533 set targetabis { "" }
534 if [string match $compiler_vendor "gnu"] {
535 if [libffi_feature_test "#ifdef __i386__"] {
538 "-DABI_NUM=FFI_STDCALL -DABI_ATTR=__STDCALL__"
539 "-DABI_NUM=FFI_THISCALL -DABI_ATTR=__THISCALL__"
540 "-DABI_NUM=FFI_FASTCALL -DABI_ATTR=__FASTCALL__"
542 } elseif { [istarget "x86_64-*-*"] \
543 && [libffi_feature_test "#if !defined __ILP32__ \
544 && !defined __i386__"] } {
547 "-DABI_NUM=FFI_GNUW64 -DABI_ATTR=__MSABI__"
552 set common [ concat $common $extra_flags ]
553 foreach test $testcases {
554 set testname [file tail $test]
555 if [search_for $test "ABI_NUM"] {
560 foreach opt $optimizations {
562 set options [concat $common $opt $abi]
563 set has_gccbug false;
564 if { [string match $compiler_vendor "gnu"] \
565 && [string match "*MSABI*" $abi] \
566 && ( ( [string match "*DGTEST=57 *" $common] \
567 && [string match "*call.c*" $testname] ) \
568 || ( [string match "*DGTEST=54 *" $common] \
569 && [string match "*callback*" $testname] ) \
570 || [string match "*DGTEST=55 *" $common] \
571 || [string match "*DGTEST=56 *" $common] ) } then {
572 if [libffi_feature_test "#if (__GNUC__ < 9) || ((__GNUC__ == 9) && (__GNUC_MINOR__ < 3))"] {
576 verbose "Testing $testname, $options" 1
577 verbose "has_gccbug = $has_gccbug" 1
578 dg-test $test $options ""
584 # Like check_conditional_xfail, but callable from a dg test.
586 proc dg-xfail-if { args } {
587 set args [lreplace $args 0 0]
588 set selector "target [join [lindex $args 1]]"
589 if { [dg-process-target $selector] == "S" } {
590 global compiler_conditional_xfail_data
591 set compiler_conditional_xfail_data $args
595 proc check-flags { args } {
597 # The args are within another list; pull them out.
598 set args [lindex $args 0]
600 # The next two arguments are optional. If they were not specified,
602 if { [llength $args] == 2 } {
603 lappend $args [list "*"]
605 if { [llength $args] == 3 } {
606 lappend $args [list ""]
609 # If the option strings are the defaults, or the same as the
610 # defaults, there is no need to call check_conditional_xfail to
611 # compare them to the actual options.
612 if { [string compare [lindex $args 2] "*"] == 0
613 && [string compare [lindex $args 3] "" ] == 0 } {
616 # The target list might be an effective-target keyword, so replace
617 # the original list with "*-*-*", since we already know it matches.
618 set result [check_conditional_xfail [lreplace $args 1 1 "*-*-*"]]
624 proc dg-skip-if { args } {
625 # Verify the number of arguments. The last two are optional.
626 set args [lreplace $args 0 0]
627 if { [llength $args] < 2 || [llength $args] > 4 } {
628 error "dg-skip-if 2: need 2, 3, or 4 arguments"
631 # Don't bother
if we
're already skipping the test.
632 upvar dg-do-what dg-do-what
633 if { [lindex ${dg-do-what} 1] == "N" } {
637 set selector [list target [lindex $args 1]]
638 if { [dg-process-target $selector] == "S" } {
639 if [check-flags $args] {
640 upvar dg-do-what dg-do-what
641 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
646 # We need to make sure that additional_files and additional_sources
647 # are both cleared out after every test. It is not enough to clear
648 # them out *before* the next test run because gcc-target-compile gets
649 # run directly from some .exp files (outside of any test). (Those
650 # uses should eventually be eliminated.)
652 # Because the DG framework doesn't provide a hook that is run at the
653 # end of a test
, we must replace dg
-test with a wrapper.
655 if { [info procs saved
-dg
-test
] == [list
] } {
656 rename dg
-test saved
-dg
-test
658 proc dg
-test
{ args } {
659 global additional_files
660 global additional_sources
663 if { [ catch
{ eval saved
-dg
-test $
args } errmsg
] } {
664 set saved_info $errorInfo
665 set additional_files
""
666 set additional_sources
""
667 error $errmsg $saved_info
669 set additional_files
""
670 set additional_sources
""