1 # Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # gcc-patches@gcc.gnu.org
21 # This file defines procs for determining features supported by the target.
23 # Try to compile some code and return the messages printed by the compiler.
25 # BASENAME is a basename to use for temporary files.
26 # TYPE is the type of compilation to perform (see target_compile).
27 # CONTENTS gives the contents of the input file.
28 # The rest is optional:
29 # OPTIONS: additional compiler options to use.
30 proc get_compiler_messages {basename type contents args} {
33 if { [llength $args] > 0 } {
34 set options "additional_flags=[lindex $args 0]"
39 set src ${basename}[pid].c
41 assembly { set output ${basename}[pid].s }
42 object { set output ${basename}[pid].o }
47 set lines [${tool}_target_compile $src $output $type "$options"]
49 remote_file build delete $output
54 proc current_target_name { } {
56 if [info exists target_info(target,name)] {
57 set answer $target_info(target,name)
64 # Implement an effective-target check for property PROP by invoking
65 # the compiler and seeing if it prints any messages. Assume that the
66 # property holds if the compiler doesn't print anything. The other
67 # arguments are as for get_compiler_messages, starting with TYPE.
68 proc check_no_compiler_messages {prop args} {
71 set target [current_target_name]
72 if {![info exists et_cache($prop,target)]
73 || $et_cache($prop,target) != $target} {
74 verbose "check_effective_target $prop: compiling source for $target" 2
75 set et_cache($prop,target) $target
76 set et_cache($prop,value) \
77 [string match "" [eval get_compiler_messages $prop $args]]
79 set value $et_cache($prop,value)
80 verbose "check_effective_target $prop: returning $value for $target" 2
84 ###############################
85 # proc check_weak_available { }
86 ###############################
88 # weak symbols are only supported in some configs/object formats
89 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
91 proc check_weak_available { } {
95 # All mips targets should support it
97 if { [ string first "mips" $target_cpu ] >= 0 } {
101 # All solaris2 targets should support it
103 if { [regexp ".*-solaris2.*" $target_triplet] } {
107 # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
109 if { [regexp "alpha.*osf.*" $target_triplet] } {
113 # Windows targets Cygwin and MingW32 support it
115 if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
119 # HP-UX 10.X doesn't support it
121 if { [regexp "hppa.*hpux10" $target_triplet] } {
125 # ELF and ECOFF support it. a.out does with gas/gld but may also with
126 # other linkers, so we should try it
128 set objformat [gcc_target_object_format]
136 unknown { return -1 }
141 ###############################
142 # proc check_visibility_available { what_kind }
143 ###############################
145 # The visibility attribute is only support in some object formats
146 # This proc returns 1 if it is supported, 0 if not.
147 # The argument is the kind of visibility, default/protected/hidden/internal.
149 proc check_visibility_available { what_kind } {
151 global target_triplet
153 # On NetWare, support makes no sense.
154 if { [istarget *-*-netware*] } {
158 if [string match "" $what_kind] { set what_kind "hidden" }
160 return [check_no_compiler_messages visibility_available_$what_kind object "
161 void f() __attribute__((visibility(\"$what_kind\")));
166 ###############################
167 # proc check_alias_available { }
168 ###############################
170 # Determine if the target toolchain supports the alias attribute.
172 # Returns 2 if the target supports aliases. Returns 1 if the target
173 # only supports weak aliased. Returns 0 if the target does not
174 # support aliases at all. Returns -1 if support for aliases could not
177 proc check_alias_available { } {
178 global alias_available_saved
181 if [info exists alias_available_saved] {
182 verbose "check_alias_available returning saved $alias_available_saved" 2
186 verbose "check_alias_available compiling testfile $src" 2
187 set f [open $src "w"]
188 # Compile a small test program. The definition of "g" is
189 # necessary to keep the Solaris assembler from complaining
191 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
192 puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
194 set lines [${tool}_target_compile $src $obj object ""]
196 remote_file build delete $obj
198 if [string match "" $lines] then {
199 # No error messages, everything is OK.
200 set alias_available_saved 2
202 if [regexp "alias definitions not supported" $lines] {
203 verbose "check_alias_available target does not support aliases" 2
205 set objformat [gcc_target_object_format]
207 if { $objformat == "elf" } {
208 verbose "check_alias_available but target uses ELF format, so it ought to" 2
209 set alias_available_saved -1
211 set alias_available_saved 0
214 if [regexp "only weak aliases are supported" $lines] {
215 verbose "check_alias_available target supports only weak aliases" 2
216 set alias_available_saved 1
218 set alias_available_saved -1
223 verbose "check_alias_available returning $alias_available_saved" 2
226 return $alias_available_saved
229 # Returns true if --gc-sections is supported on the target.
231 proc check_gc_sections_available { } {
232 global gc_sections_available_saved
235 if {![info exists gc_sections_available_saved]} {
236 # Some targets don't support gc-sections despite whatever's
237 # advertised by ld's options.
238 if { [istarget alpha*-*-*]
239 || [istarget ia64-*-*] } {
240 set gc_sections_available_saved 0
244 # Check if the ld used by gcc supports --gc-sections.
245 set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
246 regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
247 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
248 set ld_output [remote_exec host "$gcc_ld" "--help"]
249 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
250 set gc_sections_available_saved 1
252 set gc_sections_available_saved 0
255 return $gc_sections_available_saved
258 # Return true if profiling is supported on the target.
260 proc check_profiling_available { test_what } {
261 global profiling_available_saved
263 verbose "Profiling argument is <$test_what>" 1
265 # These conditions depend on the argument so examine them before
266 # looking at the cache variable.
268 # Support for -p on solaris2 relies on mcrt1.o which comes with the
269 # vendor compiler. We cannot reliably predict the directory where the
270 # vendor compiler (and thus mcrt1.o) is installed so we can't
271 # necessarily find mcrt1.o even if we have it.
272 if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
276 # Support for -p on irix relies on libprof1.a which doesn't appear to
277 # exist on any irix6 system currently posting testsuite results.
278 # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
279 # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
280 if { [istarget mips*-*-irix*]
281 && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
285 # At present, there is no profiling support on NetWare.
286 if { [istarget *-*-netware*] } {
290 # Now examine the cache variable.
291 if {![info exists profiling_available_saved]} {
292 # Some targets don't have any implementation of __bb_init_func or are
293 # missing other needed machinery.
294 if { [istarget mmix-*-*]
295 || [istarget arm*-*-eabi*]
296 || [istarget arm*-*-elf]
297 || [istarget arm*-*-symbianelf*]
298 || [istarget powerpc-*-eabi*]
299 || [istarget strongarm*-*-elf]
300 || [istarget xscale*-*-elf]
301 || [istarget cris-*-*]
302 || [istarget h8300-*-*]
303 || [istarget m68k-*-elf]
304 || [istarget mips*-*-elf]
305 || [istarget xtensa-*-elf]
306 || [istarget *-*-windiss] } {
307 set profiling_available_saved 0
309 set profiling_available_saved 1
313 return $profiling_available_saved
316 # Return 1 if target has packed layout of structure members by
317 # default, 0 otherwise. Note that this is slightly different than
318 # whether the target has "natural alignment": both attributes may be
321 proc check_effective_target_default_packed { } {
322 return [check_no_compiler_messages default_packed assembly {
323 struct x { char a; long b; } c;
324 int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
328 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined. See
329 # documentation, where the test also comes from.
331 proc check_effective_target_pcc_bitfield_type_matters { } {
332 # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
333 # bitfields, but let's stick to the example code from the docs.
334 return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
335 struct foo1 { char x; char :0; char y; };
336 struct foo2 { char x; int :0; char y; };
337 int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
341 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
343 # This won't change for different subtargets so cache the result.
345 proc check_effective_target_tls {} {
348 if [info exists et_tls_saved] {
349 verbose "check_effective_target_tls: using cached result" 2
355 verbose "check_effective_target_tls: compiling testfile $src" 2
356 set f [open $src "w"]
357 # Compile a small test program.
358 puts $f "__thread int i;\n"
361 # Test for thread-local data supported by the platform.
363 [target_compile $src $asm assembly ""]
365 if { [string match "*not supported*" $comp_output] } {
368 remove-build-file $asm
370 verbose "check_effective_target_tls: returning $et_tls_saved" 2
374 # Return 1 if TLS executables can run correctly, 0 otherwise.
376 # This won't change for different subtargets so cache the result.
378 proc check_effective_target_tls_runtime {} {
379 global et_tls_runtime_saved
381 if [info exists et_tls_runtime_saved] {
382 verbose "check_effective_target_tls_runtime: using cached result" 2
384 set et_tls_runtime_saved 0
386 set src tls_runtime[pid].c
387 set exe tls_runtime[pid].x
388 verbose "check_effective_target_tls_runtime: compiling testfile $src" 2
389 set f [open $src "w"]
390 # Compile a small test program.
391 puts $f "__thread int thr = 0;\n"
392 puts $f "int main(void)\n {\n return thr;\n}"
396 [target_compile $src $exe executable ""]
399 if [string match "" $comp_output] then {
400 # No error messages, everything is OK.
402 set result [remote_load target "./$exe" "" ""]
403 set status [lindex $result 0]
404 remote_file build delete $exe
406 verbose "check_effective_target_tls_runtime status is <$status>" 2
408 if { $status == "pass" } {
409 set et_tls_runtime_saved 1
412 verbose "check_effective_target_tls_runtime: returning $et_tls_runtime_saved" 2
416 return $et_tls_runtime_saved
419 # Return 1 if compilation with -fopenmp is error-free for trivial
422 proc check_effective_target_fopenmp {} {
423 return [check_no_compiler_messages fopenmp object {
428 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
429 # for trivial code, 0 otherwise.
431 proc check_effective_target_freorder {} {
432 return [check_no_compiler_messages freorder object {
434 } "-freorder-blocks-and-partition"]
437 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
438 # emitted, 0 otherwise. Whether a shared library can actually be built is
439 # out of scope for this test.
441 proc check_effective_target_fpic { } {
442 # Note that M68K has a multilib that supports -fpic but not
443 # -fPIC, so we need to check both. We test with a program that
444 # requires GOT references.
445 foreach arg {fpic fPIC} {
446 if [check_no_compiler_messages $arg object {
447 extern int foo (void); extern int bar;
448 int baz (void) { return foo () + bar; }
456 # Return true if iconv is supported on the target. In particular IBM1047.
458 proc check_iconv_available { test_what } {
466 verbose "check_iconv_available compiling testfile $src" 2
467 set f [open $src "w"]
468 # Compile a small test program.
469 puts $f "#include <iconv.h>\n"
470 puts $f "int main (void)\n {\n iconv_t cd; \n"
471 puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
472 puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
473 puts $f "return 0;\n}"
476 # If the tool configuration file has not set libiconv, try "-liconv"
477 if { ![info exists libiconv] } {
478 set libiconv "-liconv"
480 set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
483 if [string match "" $lines] then {
484 # No error messages, everything is OK.
486 set result [${tool}_load "./$exe" "" ""]
487 set status [lindex $result 0]
488 remote_file build delete $exe
490 verbose "check_iconv_available status is <$status>" 2
492 if { $status == "pass" } then {
500 # Return true if named sections are supported on this target.
502 proc check_named_sections_available { } {
503 return [check_no_compiler_messages named_sections assembly {
504 int __attribute__ ((section("whatever"))) foo;
508 # Return 1 if the target supports Fortran real kinds larger than real(8),
511 # When the target name changes, replace the cached result.
513 proc check_effective_target_fortran_large_real { } {
514 global et_fortran_large_real_saved
515 global et_fortran_large_real_target_name
518 if { ![info exists et_fortran_large_real_target_name] } {
519 set et_fortran_large_real_target_name ""
522 # If the target has changed since we set the cached value, clear it.
523 set current_target [current_target_name]
524 if { $current_target != $et_fortran_large_real_target_name } {
525 verbose "check_effective_target_fortran_large_real: `$et_fortran_large_real_target_name' `$current_target'" 2
526 set et_fortran_large_real_target_name $current_target
527 if [info exists et_fortran_large_real_saved] {
528 verbose "check_effective_target_fortran_large_real: removing cached result" 2
529 unset et_fortran_large_real_saved
533 if [info exists et_fortran_large_real_saved] {
534 verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
536 set et_fortran_large_real_saved 0
538 # Set up, compile, and execute a test program using large real
539 # kinds. Include the current process ID in the file names to
540 # prevent conflicts with invocations for multiple testsuites.
541 set src real[pid].f90
544 set f [open $src "w"]
545 puts $f "integer,parameter :: k = &"
546 puts $f " selected_real_kind (precision (0.0_8) + 1)"
547 puts $f "real(kind=k) :: x"
548 puts $f "x = cos (x);"
552 verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
553 set lines [${tool}_target_compile $src $exe executable ""]
556 if [string match "" $lines] then {
557 # No error message, compilation succeeded.
558 set et_fortran_large_real_saved 1
562 return $et_fortran_large_real_saved
565 # Return 1 if the target supports Fortran integer kinds larger than
566 # integer(8), 0 otherwise.
568 # When the target name changes, replace the cached result.
570 proc check_effective_target_fortran_large_int { } {
571 global et_fortran_large_int_saved
572 global et_fortran_large_int_target_name
575 if { ![info exists et_fortran_large_int_target_name] } {
576 set et_fortran_large_int_target_name ""
579 # If the target has changed since we set the cached value, clear it.
580 set current_target [current_target_name]
581 if { $current_target != $et_fortran_large_int_target_name } {
582 verbose "check_effective_target_fortran_large_int: `$et_fortran_large_int_target_name' `$current_target'" 2
583 set et_fortran_large_int_target_name $current_target
584 if [info exists et_fortran_large_int_saved] {
585 verbose "check_effective_target_fortran_large_int: removing cached result" 2
586 unset et_fortran_large_int_saved
590 if [info exists et_fortran_large_int_saved] {
591 verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
593 set et_fortran_large_int_saved 0
595 # Set up, compile, and execute a test program using large integer
596 # kinds. Include the current process ID in the file names to
597 # prevent conflicts with invocations for multiple testsuites.
601 set f [open $src "w"]
602 puts $f "integer,parameter :: k = &"
603 puts $f " selected_int_kind (range (0_8) + 1)"
604 puts $f "integer(kind=k) :: i"
608 verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
609 set lines [${tool}_target_compile $src $exe executable ""]
612 if [string match "" $lines] then {
613 # No error message, compilation succeeded.
614 set et_fortran_large_int_saved 1
618 return $et_fortran_large_int_saved
621 # Return 1 if we can statically link libgfortran, 0 otherwise.
623 # When the target name changes, replace the cached result.
625 proc check_effective_target_static_libgfortran { } {
626 global et_static_libgfortran
627 global et_static_libgfortran_target_name
630 if { ![info exists et_static_libgfortran_target_name] } {
631 set et_static_libgfortran_target_name ""
634 # If the target has changed since we set the cached value, clear it.
635 set current_target [current_target_name]
636 if { $current_target != $et_static_libgfortran_target_name } {
637 verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
638 set et_static_libgfortran_target_name $current_target
639 if [info exists et_static_libgfortran_saved] {
640 verbose "check_effective_target_static_libgfortran: removing cached result" 2
641 unset et_static_libgfortran_saved
645 if [info exists et_static_libgfortran_saved] {
646 verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
648 set et_static_libgfortran_saved 0
650 # Set up, compile, and execute a test program using static linking.
651 # Include the current process ID in the file names to prevent
652 # conflicts with invocations for multiple testsuites.
653 set opts "additional_flags=-static"
654 set src static[pid].f
655 set exe static[pid].x
657 set f [open $src "w"]
658 puts $f " print *, 'test'"
662 verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
663 set lines [${tool}_target_compile $src $exe executable "$opts"]
666 if [string match "" $lines] then {
667 # No error message, compilation succeeded.
668 set et_static_libgfortran_saved 1
672 return $et_static_libgfortran_saved
675 # Return 1 if the target supports executing AltiVec instructions, 0
676 # otherwise. Cache the result.
678 proc check_vmx_hw_available { } {
679 global vmx_hw_available_saved
682 if [info exists vmx_hw_available_saved] {
683 verbose "check_hw_available returning saved $vmx_hw_available_saved" 2
685 set vmx_hw_available_saved 0
687 # Some simulators are known to not support VMX instructions.
688 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
689 verbose "check_hw_available returning 0" 2
690 return $vmx_hw_available_saved
693 # Set up, compile, and execute a test program containing VMX
694 # instructions. Include the current process ID in the file
695 # names to prevent conflicts with invocations for multiple
700 set f [open $src "w"]
701 puts $f "int main() {"
702 puts $f "#ifdef __MACH__"
703 puts $f " asm volatile (\"vor v0,v0,v0\");"
705 puts $f " asm volatile (\"vor 0,0,0\");"
707 puts $f " return 0; }"
710 # Most targets don't require special flags for this test case, but
712 if [istarget *-*-darwin*] {
713 set opts "additional_flags=-maltivec"
718 verbose "check_vmx_hw_available compiling testfile $src" 2
719 set lines [${tool}_target_compile $src $exe executable "$opts"]
722 if [string match "" $lines] then {
723 # No error message, compilation succeeded.
724 set result [${tool}_load "./$exe" "" ""]
725 set status [lindex $result 0]
726 remote_file build delete $exe
727 verbose "check_vmx_hw_available testfile status is <$status>" 2
729 if { $status == "pass" } then {
730 set vmx_hw_available_saved 1
733 verbose "check_vmx_hw_availalble testfile compilation failed" 2
737 return $vmx_hw_available_saved
740 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
741 # complex float arguments. This affects gfortran tests that call cabsf
742 # in libm built by an earlier compiler. Return 1 if libm uses the same
743 # argument passing as the compiler under test, 0 otherwise.
745 # When the target name changes, replace the cached result.
747 proc check_effective_target_broken_cplxf_arg { } {
748 global et_broken_cplxf_arg_saved
749 global et_broken_cplxf_arg_target_name
752 # Skip the work for targets known not to be affected.
753 if { ![istarget powerpc64-*-linux*] } {
755 } elseif { [is-effective-target ilp32] } {
759 if { ![info exists et_broken_cplxf_arg_target_name] } {
760 set et_broken_cplxf_arg_target_name ""
763 # If the target has changed since we set the cached value, clear it.
764 set current_target [current_target_name]
765 if { $current_target != $et_broken_cplxf_arg_target_name } {
766 verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
767 set et_broken_cplxf_arg_target_name $current_target
768 if [info exists et_broken_cplxf_arg_saved] {
769 verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
770 unset et_broken_cplxf_arg_saved
774 if [info exists et_broken_cplxf_arg_saved] {
775 verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
777 set et_broken_cplxf_arg_saved 0
778 # This is only known to affect one target.
779 if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
780 set et_broken_cplxf_arg_saved 0
781 verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
782 return $et_broken_cplxf_arg_saved
785 # Set up, compile, and execute a C test program that calls cabsf.
789 set f [open $src "w"]
790 puts $f "#include <complex.h>"
791 puts $f "extern void abort (void);"
792 puts $f "float fabsf (float);"
793 puts $f "float cabsf (_Complex float);"
794 puts $f "int main ()"
796 puts $f " _Complex float cf;"
798 puts $f " cf = 3 + 4.0fi;"
799 puts $f " f = cabsf (cf);"
800 puts $f " if (fabsf (f - 5.0) > 0.0001) abort ();"
805 set lines [${tool}_target_compile $src $exe executable "-lm"]
808 if [string match "" $lines] {
809 # No error message, compilation succeeded.
810 set result [${tool}_load "./$exe" "" ""]
811 set status [lindex $result 0]
812 remote_file build delete $exe
814 verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
816 if { $status != "pass" } {
817 set et_broken_cplxf_arg_saved 1
820 verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
823 return $et_broken_cplxf_arg_saved
826 proc check_alpha_max_hw_available { } {
827 global alpha_max_hw_available_saved
830 if [info exists alpha_max_hw_available_saved] {
831 verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
833 set alpha_max_hw_available_saved 0
835 # Set up, compile, and execute a test program probing bit 8 of the
836 # architecture mask, which indicates presence of MAX instructions.
840 set f [open $src "w"]
841 puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
844 verbose "check_alpha_max_hw_available compiling testfile $src" 2
845 set lines [${tool}_target_compile $src $exe executable ""]
848 if [string match "" $lines] then {
849 # No error message, compilation succeeded.
850 set result [${tool}_load "./$exe" "" ""]
851 set status [lindex $result 0]
852 remote_file build delete $exe
853 verbose "check_alpha_max_hw_available testfile status is <$status>" 2
855 if { $status == "pass" } then {
856 set alpha_max_hw_available_saved 1
859 verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
863 return $alpha_max_hw_available_saved
866 # Returns true iff the FUNCTION is available on the target system.
867 # (This is essentially a Tcl implementation of Autoconf's
870 proc check_function_available { function } {
871 set var "${function}_available_saved"
875 if {![info exists $var]} {
878 # Check to make sure.
879 set src "function[pid].c"
880 set exe "function[pid].exe"
882 set f [open $src "w"]
883 puts $f "int main () { $function (); }"
886 set lines [${tool}_target_compile $src $exe executable ""]
890 if {![string match "" $lines]} then {
892 verbose -log "$function is not available"
894 verbose -log "$function is available"
901 # Returns true iff "fork" is available on the target system.
903 proc check_fork_available {} {
904 return [check_function_available "fork"]
907 # Returns true iff "mkfifo" is available on the target system.
909 proc check_mkfifo_available {} {
910 if {[istarget *-*-cygwin*]} {
911 # Cygwin has mkfifo, but support is incomplete.
915 return [check_function_available "mkfifo"]
918 # Return 1 if we're generating 32-bit code using default options, 0
921 proc check_effective_target_ilp32 { } {
922 return [check_no_compiler_messages ilp32 object {
923 int dummy[sizeof (int) == 4
924 && sizeof (void *) == 4
925 && sizeof (long) == 4 ? 1 : -1];
929 # Return 1 if we're generating 64-bit code using default options, 0
932 proc check_effective_target_lp64 { } {
933 return [check_no_compiler_messages lp64 object {
934 int dummy[sizeof (int) == 4
935 && sizeof (void *) == 8
936 && sizeof (long) == 8 ? 1 : -1];
940 # Return 1 if the target supports compiling decimal floating point,
943 proc check_effective_target_dfp_nocache { } {
944 verbose "check_effective_target_dfp_nocache: compiling source" 2
945 set ret [string match "" [get_compiler_messages dfp object {
946 _Decimal32 x; _Decimal64 y; _Decimal128 z;
948 verbose "check_effective_target_dfp_nocache: returning $ret" 2
952 proc check_effective_target_dfprt_nocache { } {
957 verbose "check_effective_target_dfprt_nocache: compiling source" 2
958 # Set up, compile, and execute a test program containing decimal
963 set f [open $src "w"]
964 puts $f "_Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;"
965 puts $f "int main () { z = x + y; return 0; }"
968 verbose "check_effective_target_dfprt_nocache: compiling testfile $src" 2
969 set lines [${tool}_target_compile $src $exe executable ""]
972 if [string match "" $lines] then {
973 # No error message, compilation succeeded.
974 set result [${tool}_load "./$exe" "" ""]
975 set status [lindex $result 0]
976 remote_file build delete $exe
977 verbose "check_effective_target_dfprt_nocache: testfile status is <$status>" 2
978 if { $status == "pass" } then {
983 verbose "check_effective_target_dfprt_nocache: returning $ret" 2
986 # Return 1 if the target supports compiling Decimal Floating Point,
989 # This won't change for different subtargets so cache the result.
991 proc check_effective_target_dfp { } {
994 if [info exists et_dfp_saved] {
995 verbose "check_effective_target_dfp: using cached result" 2
997 set et_dfp_saved [check_effective_target_dfp_nocache]
999 verbose "check_effective_target_dfp: returning $et_dfp_saved" 2
1000 return $et_dfp_saved
1003 # Return 1 if the target supports linking and executing Decimal Floating
1004 # Point, # 0 otherwise.
1006 # This won't change for different subtargets so cache the result.
1008 proc check_effective_target_dfprt { } {
1009 global et_dfprt_saved
1012 if [info exists et_dfprt_saved] {
1013 verbose "check_effective_target_dfprt: using cached result" 2
1015 set et_dfprt_saved [check_effective_target_dfprt_nocache]
1017 verbose "check_effective_target_dfprt: returning $et_dfprt_saved" 2
1018 return $et_dfprt_saved
1021 # Return 1 if the target needs a command line argument to enable a SIMD
1024 # This won't change for different subtargets so cache the result.
1026 proc check_effective_target_vect_cmdline_needed { } {
1027 global et_vect_cmdline_needed_saved
1029 if [info exists et_vect_cmdline_needed_saved] {
1030 verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1032 set et_vect_cmdline_needed_saved 1
1033 if { [istarget ia64-*-*]
1034 || [istarget x86_64-*-*] } {
1035 set et_vect_cmdline_needed_saved 0
1039 verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1040 return $et_vect_cmdline_needed_saved
1043 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1045 # This won't change for different subtargets so cache the result.
1047 proc check_effective_target_vect_int { } {
1048 global et_vect_int_saved
1050 if [info exists et_vect_int_saved] {
1051 verbose "check_effective_target_vect_int: using cached result" 2
1053 set et_vect_int_saved 0
1054 if { [istarget i?86-*-*]
1055 || [istarget powerpc*-*-*]
1056 || [istarget x86_64-*-*]
1057 || [istarget sparc*-*-*]
1058 || [istarget alpha*-*-*]
1059 || [istarget ia64-*-*] } {
1060 set et_vect_int_saved 1
1064 verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1065 return $et_vect_int_saved
1068 # Return 1 is this is an arm target using 32-bit instructions
1069 proc check_effective_target_arm32 { } {
1070 global et_arm32_saved
1071 global et_arm32_target_name
1072 global compiler_flags
1074 if { ![info exists et_arm32_target_name] } {
1075 set et_arm32_target_name ""
1078 # If the target has changed since we set the cached value, clear it.
1079 set current_target [current_target_name]
1080 if { $current_target != $et_arm32_target_name } {
1081 verbose "check_effective_target_arm32: `$et_arm32_target_name' `$current_target'" 2
1082 set et_arm32_target_name $current_target
1083 if { [info exists et_arm32_saved] } {
1084 verbose "check_effective_target_arm32: removing cached result" 2
1085 unset et_arm32_saved
1089 if [info exists et_arm32_saved] {
1090 verbose "check-effective_target_arm32: using cached result" 2
1092 set et_arm32_saved 0
1093 if { [istarget arm-*-*]
1094 || [istarget strongarm*-*-*]
1095 || [istarget xscale-*-*] } {
1096 if ![string match "*-mthumb *" $compiler_flags] {
1097 set et_arm32_saved 1
1101 verbose "check_effective_target_arm32: returning $et_arm32_saved" 2
1102 return $et_arm32_saved
1105 # Return 1 if the target supports hardware vector shift operation.
1107 proc check_effective_target_vect_shift { } {
1108 global et_vect_shift_saved
1110 if [info exists et_vect_shift_saved] {
1111 verbose "check_effective_target_vect_shift: using cached result" 2
1113 set et_vect_shift_saved 0
1114 if { [istarget powerpc*-*-*]
1115 || [istarget ia64-*-*]
1116 || [istarget i?86-*-*]
1117 || [istarget x86_64-*-*] } {
1118 set et_vect_shift_saved 1
1122 verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1123 return $et_vect_shift_saved
1126 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1128 # This can change for different subtargets so do not cache the result.
1130 proc check_effective_target_vect_long { } {
1131 if { [istarget i?86-*-*]
1132 || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
1133 || [istarget x86_64-*-*]
1134 || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1140 verbose "check_effective_target_vect_long: returning $answer" 2
1144 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1146 # This won't change for different subtargets so cache the result.
1148 proc check_effective_target_vect_float { } {
1149 global et_vect_float_saved
1151 if [info exists et_vect_float_saved] {
1152 verbose "check_effective_target_vect_float: using cached result" 2
1154 set et_vect_float_saved 0
1155 if { [istarget i?86-*-*]
1156 || [istarget powerpc*-*-*]
1157 || [istarget mipsisa64*-*-*]
1158 || [istarget x86_64-*-*]
1159 || [istarget ia64-*-*] } {
1160 set et_vect_float_saved 1
1164 verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1165 return $et_vect_float_saved
1168 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1170 # This won't change for different subtargets so cache the result.
1172 proc check_effective_target_vect_double { } {
1173 global et_vect_double_saved
1175 if [info exists et_vect_double_saved] {
1176 verbose "check_effective_target_vect_double: using cached result" 2
1178 set et_vect_double_saved 0
1179 if { [istarget i?86-*-*]
1180 || [istarget x86_64-*-*] } {
1181 set et_vect_double_saved 1
1185 verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1186 return $et_vect_double_saved
1189 # Return 1 if the target plus current options does not support a vector
1190 # max instruction on "int", 0 otherwise.
1192 # This won't change for different subtargets so cache the result.
1194 proc check_effective_target_vect_no_int_max { } {
1195 global et_vect_no_int_max_saved
1197 if [info exists et_vect_no_int_max_saved] {
1198 verbose "check_effective_target_vect_no_int_max: using cached result" 2
1200 set et_vect_no_int_max_saved 0
1201 if { [istarget sparc*-*-*]
1202 || [istarget alpha*-*-*] } {
1203 set et_vect_no_int_max_saved 1
1206 verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1207 return $et_vect_no_int_max_saved
1210 # Return 1 if the target plus current options does not support a vector
1211 # add instruction on "int", 0 otherwise.
1213 # This won't change for different subtargets so cache the result.
1215 proc check_effective_target_vect_no_int_add { } {
1216 global et_vect_no_int_add_saved
1218 if [info exists et_vect_no_int_add_saved] {
1219 verbose "check_effective_target_vect_no_int_add: using cached result" 2
1221 set et_vect_no_int_add_saved 0
1222 # Alpha only supports vector add on V8QI and V4HI.
1223 if { [istarget alpha*-*-*] } {
1224 set et_vect_no_int_add_saved 1
1227 verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1228 return $et_vect_no_int_add_saved
1231 # Return 1 if the target plus current options does not support vector
1232 # bitwise instructions, 0 otherwise.
1234 # This won't change for different subtargets so cache the result.
1236 proc check_effective_target_vect_no_bitwise { } {
1237 global et_vect_no_bitwise_saved
1239 if [info exists et_vect_no_bitwise_saved] {
1240 verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1242 set et_vect_no_bitwise_saved 0
1244 verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1245 return $et_vect_no_bitwise_saved
1248 # Return 1 if the target plus current options supports a vector
1249 # widening summation of *short* args into *int* result, 0 otherwise.
1251 # This won't change for different subtargets so cache the result.
1253 proc check_effective_target_vect_widen_sum_hi_to_si { } {
1254 global et_vect_widen_sum_hi_to_si
1256 if [info exists et_vect_widen_sum_hi_to_si_saved] {
1257 verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
1259 set et_vect_widen_sum_hi_to_si_saved 0
1260 if { [istarget powerpc*-*-*]
1261 || [istarget ia64-*-*] } {
1262 set et_vect_widen_sum_hi_to_si_saved 1
1265 verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
1266 return $et_vect_widen_sum_hi_to_si_saved
1269 # Return 1 if the target plus current options supports a vector
1270 # widening summation of *char* args into *short* result, 0 otherwise.
1272 # This won't change for different subtargets so cache the result.
1274 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
1275 global et_vect_widen_sum_qi_to_hi
1277 if [info exists et_vect_widen_sum_qi_to_hi_saved] {
1278 verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
1280 set et_vect_widen_sum_qi_to_hi_saved 0
1281 if { [istarget ia64-*-*] } {
1282 set et_vect_widen_sum_qi_to_hi_saved 1
1285 verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
1286 return $et_vect_widen_sum_qi_to_hi_saved
1289 # Return 1 if the target plus current options supports a vector
1290 # widening summation of *char* args into *int* result, 0 otherwise.
1292 # This won't change for different subtargets so cache the result.
1294 proc check_effective_target_vect_widen_sum_qi_to_si { } {
1295 global et_vect_widen_sum_qi_to_si
1297 if [info exists et_vect_widen_sum_qi_to_si_saved] {
1298 verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
1300 set et_vect_widen_sum_qi_to_si_saved 0
1301 if { [istarget powerpc*-*-*] } {
1302 set et_vect_widen_sum_qi_to_si_saved 1
1305 verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
1306 return $et_vect_widen_sum_qi_to_si_saved
1309 # Return 1 if the target plus current options supports a vector
1310 # widening summation, 0 otherwise.
1312 # This won't change for different subtargets so cache the result.
1314 proc check_effective_target_vect_widen_sum { } {
1315 global et_vect_widen_sum
1317 if [info exists et_vect_widen_sum_saved] {
1318 verbose "check_effective_target_vect_widen_sum: using cached result" 2
1320 set et_vect_widen_sum_saved 0
1321 if { [istarget powerpc*-*-*]
1322 || [istarget ia64-*-*] } {
1323 set et_vect_widen_sum_saved 1
1326 verbose "check_effective_target_vect_widen_sum: returning $et_vect_widen_sum_saved" 2
1327 return $et_vect_widen_sum_saved
1330 # Return 1 if the target plus current options supports a vector
1331 # dot-product of signed chars, 0 otherwise.
1333 # This won't change for different subtargets so cache the result.
1335 proc check_effective_target_vect_sdot_qi { } {
1336 global et_vect_sdot_qi
1338 if [info exists et_vect_sdot_qi_saved] {
1339 verbose "check_effective_target_vect_sdot_qi: using cached result" 2
1341 set et_vect_sdot_qi_saved 0
1342 if { [istarget ia64-*-*] } {
1343 set et_vect_sdot_qi_saved 1
1346 verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
1347 return $et_vect_sdot_qi_saved
1350 # Return 1 if the target plus current options supports a vector
1351 # dot-product of unsigned chars, 0 otherwise.
1353 # This won't change for different subtargets so cache the result.
1355 proc check_effective_target_vect_udot_qi { } {
1356 global et_vect_udot_qi
1358 if [info exists et_vect_udot_qi_saved] {
1359 verbose "check_effective_target_vect_udot_qi: using cached result" 2
1361 set et_vect_udot_qi_saved 0
1362 if { [istarget powerpc*-*-*]
1363 || [istarget ia64-*-*] } {
1364 set et_vect_udot_qi_saved 1
1367 verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
1368 return $et_vect_udot_qi_saved
1371 # Return 1 if the target plus current options supports a vector
1372 # dot-product of signed shorts, 0 otherwise.
1374 # This won't change for different subtargets so cache the result.
1376 proc check_effective_target_vect_sdot_hi { } {
1377 global et_vect_sdot_hi
1379 if [info exists et_vect_sdot_hi_saved] {
1380 verbose "check_effective_target_vect_sdot_hi: using cached result" 2
1382 set et_vect_sdot_hi_saved 0
1383 if { [istarget powerpc*-*-*]
1384 || [istarget i?86-*-*]
1385 || [istarget x86_64-*-*]
1386 || [istarget ia64-*-*] } {
1387 set et_vect_sdot_hi_saved 1
1390 verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
1391 return $et_vect_sdot_hi_saved
1394 # Return 1 if the target plus current options supports a vector
1395 # dot-product of unsigned shorts, 0 otherwise.
1397 # This won't change for different subtargets so cache the result.
1399 proc check_effective_target_vect_udot_hi { } {
1400 global et_vect_udot_hi
1402 if [info exists et_vect_udot_hi_saved] {
1403 verbose "check_effective_target_vect_udot_hi: using cached result" 2
1405 set et_vect_udot_hi_saved 0
1406 if { [istarget powerpc*-*-*] } {
1407 set et_vect_udot_hi_saved 1
1410 verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
1411 return $et_vect_udot_hi_saved
1415 # Return 1 if the target plus current options does not support a vector
1416 # alignment mechanism, 0 otherwise.
1418 # This won't change for different subtargets so cache the result.
1420 proc check_effective_target_vect_no_align { } {
1421 global et_vect_no_align_saved
1423 if [info exists et_vect_no_align_saved] {
1424 verbose "check_effective_target_vect_no_align: using cached result" 2
1426 set et_vect_no_align_saved 0
1427 if { [istarget mipsisa64*-*-*]
1428 || [istarget sparc*-*-*]
1429 || [istarget ia64-*-*] } {
1430 set et_vect_no_align_saved 1
1433 verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
1434 return $et_vect_no_align_saved
1437 # Return 1 if the target supports vector conditional operations, 0 otherwise.
1439 proc check_effective_target_vect_condition { } {
1440 global et_vect_cond_saved
1442 if [info exists et_vect_cond_saved] {
1443 verbose "check_effective_target_vect_cond: using cached result" 2
1445 set et_vect_cond_saved 0
1446 if { [istarget powerpc*-*-*]
1447 || [istarget ia64-*-*]
1448 || [istarget i?86-*-*]
1449 || [istarget x86_64-*-*] } {
1450 set et_vect_cond_saved 1
1454 verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
1455 return $et_vect_cond_saved
1458 # Return 1 if the target supports vector char multiplication, 0 otherwise.
1460 proc check_effective_target_vect_char_mult { } {
1461 global et_vect_char_mult_saved
1463 if [info exists et_vect_char_mult_saved] {
1464 verbose "check_effective_target_vect_char_mult: using cached result" 2
1466 set et_vect_char_mult_saved 0
1467 if { [istarget ia64-*-*]
1468 || [istarget i?86-*-*]
1469 || [istarget x86_64-*-*] } {
1470 set et_vect_char_mult_saved 1
1474 verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
1475 return $et_vect_char_mult_saved
1478 # Return 1 if the target supports vector short multiplication, 0 otherwise.
1480 proc check_effective_target_vect_short_mult { } {
1481 global et_vect_short_mult_saved
1483 if [info exists et_vect_short_mult_saved] {
1484 verbose "check_effective_target_vect_short_mult: using cached result" 2
1486 set et_vect_short_mult_saved 0
1487 if { [istarget ia64-*-*]
1488 || [istarget i?86-*-*]
1489 || [istarget x86_64-*-*] } {
1490 set et_vect_short_mult_saved 1
1494 verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
1495 return $et_vect_short_mult_saved
1498 # Return 1 if the target supports vector int multiplication, 0 otherwise.
1500 proc check_effective_target_vect_int_mult { } {
1501 global et_vect_int_mult_saved
1503 if [info exists et_vect_int_mult_saved] {
1504 verbose "check_effective_target_vect_int_mult: using cached result" 2
1506 set et_vect_int_mult_saved 0
1507 if { [istarget powerpc*-*-*]
1508 || [istarget i?86-*-*]
1509 || [istarget x86_64-*-*] } {
1510 set et_vect_int_mult_saved 1
1514 verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
1515 return $et_vect_int_mult_saved
1518 # Return 1 if the target supports atomic operations on "int" and "long".
1520 proc check_effective_target_sync_int_long { } {
1521 global et_sync_int_long_saved
1523 if [info exists et_sync_int_long_saved] {
1524 verbose "check_effective_target_sync_int_long: using cached result" 2
1526 set et_sync_int_long_saved 0
1527 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1528 # load-reserved/store-conditional instructions.
1529 if { [istarget ia64-*-*]
1530 || [istarget i?86-*-*]
1531 || [istarget x86_64-*-*]
1532 || [istarget alpha*-*-*]
1533 || [istarget s390*-*-*]
1534 || [istarget powerpc*-*-*]
1535 || [istarget sparc64-*-*]
1536 || [istarget sparcv9-*-*] } {
1537 set et_sync_int_long_saved 1
1541 verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
1542 return $et_sync_int_long_saved
1545 # Return 1 if the target supports atomic operations on "char" and "short".
1547 proc check_effective_target_sync_char_short { } {
1548 global et_sync_char_short_saved
1550 if [info exists et_sync_char_short_saved] {
1551 verbose "check_effective_target_sync_char_short: using cached result" 2
1553 set et_sync_char_short_saved 0
1554 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1555 # load-reserved/store-conditional instructions.
1556 if { [istarget ia64-*-*]
1557 || [istarget i?86-*-*]
1558 || [istarget x86_64-*-*]
1559 || [istarget alpha*-*-*]
1560 || [istarget s390*-*-*]
1561 || [istarget powerpc*-*-*]
1562 || [istarget sparc64-*-*]
1563 || [istarget sparcv9-*-*] } {
1564 set et_sync_char_short_saved 1
1568 verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
1569 return $et_sync_char_short_saved
1572 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
1573 # This can be used with any check_* proc that takes no argument and
1574 # returns only 1 or 0. It could be used with check_* procs that take
1575 # arguments with keywords that pass particular arguments.
1577 proc is-effective-target { arg } {
1579 if { [info procs check_effective_target_${arg}] != [list] } {
1580 set selected [check_effective_target_${arg}]
1583 "vmx_hw" { set selected [check_vmx_hw_available] }
1584 "named_sections" { set selected [check_named_sections_available] }
1585 "gc_sections" { set selected [check_gc_sections_available] }
1586 default { error "unknown effective target keyword `$arg'" }
1589 verbose "is-effective-target: $arg $selected" 2
1593 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
1595 proc is-effective-target-keyword { arg } {
1596 if { [info procs check_effective_target_${arg}] != [list] } {
1599 # These have different names for their check_* procs.
1601 "vmx_hw" { return 1 }
1602 "named_sections" { return 1 }
1603 "gc_sections" { return 1 }
1604 default { return 0 }
1609 # Return 1 if target default to short enums
1611 proc check_effective_target_short_enums { } {
1612 return [check_no_compiler_messages short_enums assembly {
1614 int s[sizeof (enum foo) == 1 ? 1 : -1];