1 # Copyright (C) 1999, 2001, 2003, 2004, 2005 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 2 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; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # gcc-patches@gcc.gnu.org
20 # This file defines procs for determining features supported by the target.
22 # Try to compile some code and return the messages printed by the compiler.
24 # BASENAME is a basename to use for temporary files.
25 # TYPE is the type of compilation to perform (see target_compile).
26 # CONTENTS gives the contents of the input file.
27 proc get_compiler_messages {basename type contents} {
30 set src ${basename}[pid].c
32 assembly { set output ${basename}[pid].s }
33 object { set output ${basename}[pid].o }
38 set lines [${tool}_target_compile $src $output $type ""]
40 remote_file build delete $output
45 proc current_target_name { } {
47 if [info exists target_info(target,name)] {
48 set answer $target_info(target,name)
55 ###############################
56 # proc check_weak_available { }
57 ###############################
59 # weak symbols are only supported in some configs/object formats
60 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
62 proc check_weak_available { } {
66 # All mips targets should support it
68 if { [ string first "mips" $target_cpu ] >= 0 } {
72 # All solaris2 targets should support it
74 if { [regexp ".*-solaris2.*" $target_triplet] } {
78 # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
80 if { [regexp "alpha.*osf.*" $target_triplet] } {
84 # Windows targets Cygwin and MingW32 support it
86 if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
90 # HP-UX 10.X doesn't support it
92 if { [regexp "hppa.*hpux10" $target_triplet] } {
96 # ELF and ECOFF support it. a.out does with gas/gld but may also with
97 # other linkers, so we should try it
99 set objformat [gcc_target_object_format]
107 unknown { return -1 }
112 ###############################
113 # proc check_visibility_available { }
114 ###############################
116 # The visibility attribute is only support in some object formats
117 # This proc returns 1 if it is supported, 0 if not.
119 proc check_visibility_available { } {
120 global visibility_available_saved
122 global target_triplet
124 # On NetWare, support makes no sense.
125 if { [string match "*-*-netware*" $target_triplet] } {
129 if {![info exists visibility_available_saved] } {
130 set lines [get_compiler_messages visibility object {
131 void f() __attribute__((visibility("hidden")));
134 if [string match "" $lines] then {
135 set visibility_available_saved 1
137 set visibility_available_saved 0
140 return $visibility_available_saved
143 ###############################
144 # proc check_alias_available { }
145 ###############################
147 # Determine if the target toolchain supports the alias attribute.
149 # Returns 2 if the target supports aliases. Returns 1 if the target
150 # only supports weak aliased. Returns 0 if the target does not
151 # support aliases at all. Returns -1 if support for aliases could not
154 proc check_alias_available { } {
155 global alias_available_saved
158 if [info exists alias_available_saved] {
159 verbose "check_alias_available returning saved $alias_available_saved" 2
163 verbose "check_alias_available compiling testfile $src" 2
164 set f [open $src "w"]
165 # Compile a small test program. The definition of "g" is
166 # necessary to keep the Solaris assembler from complaining
168 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
169 puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
171 set lines [${tool}_target_compile $src $obj object ""]
173 remote_file build delete $obj
175 if [string match "" $lines] then {
176 # No error messages, everything is OK.
177 set alias_available_saved 2
179 if [regexp "alias definitions not supported" $lines] {
180 verbose "check_alias_available target does not support aliases" 2
182 set objformat [gcc_target_object_format]
184 if { $objformat == "elf" } {
185 verbose "check_alias_available but target uses ELF format, so it ought to" 2
186 set alias_available_saved -1
188 set alias_available_saved 0
191 if [regexp "only weak aliases are supported" $lines] {
192 verbose "check_alias_available target supports only weak aliases" 2
193 set alias_available_saved 1
195 set alias_available_saved -1
200 verbose "check_alias_available returning $alias_available_saved" 2
203 return $alias_available_saved
206 # Returns true if --gc-sections is supported on the target.
208 proc check_gc_sections_available { } {
209 global gc_sections_available_saved
212 if {![info exists gc_sections_available_saved]} {
213 # Some targets don't support gc-sections despite whatever's
214 # advertised by ld's options.
215 if { [istarget alpha*-*-*]
216 || [istarget ia64-*-*] } {
217 set gc_sections_available_saved 0
221 # Check if the ld used by gcc supports --gc-sections.
222 set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
223 regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
224 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
225 set ld_output [remote_exec host "$gcc_ld" "--help"]
226 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
227 set gc_sections_available_saved 1
229 set gc_sections_available_saved 0
232 return $gc_sections_available_saved
235 # Return true if profiling is supported on the target.
237 proc check_profiling_available { test_what } {
238 global profiling_available_saved
240 verbose "Profiling argument is <$test_what>" 1
242 # These conditions depend on the argument so examine them before
243 # looking at the cache variable.
245 # Support for -p on solaris2 relies on mcrt1.o which comes with the
246 # vendor compiler. We cannot reliably predict the directory where the
247 # vendor compiler (and thus mcrt1.o) is installed so we can't
248 # necessarily find mcrt1.o even if we have it.
249 if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
253 # Support for -p on irix relies on libprof1.a which doesn't appear to
254 # exist on any irix6 system currently posting testsuite results.
255 # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
256 # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
257 if { [istarget mips*-*-irix*]
258 && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
262 # Now examine the cache variable.
263 if {![info exists profiling_available_saved]} {
264 # Some targets don't have any implementation of __bb_init_func or are
265 # missing other needed machinery.
266 if { [istarget mmix-*-*]
267 || [istarget arm*-*-eabi*]
268 || [istarget arm*-*-elf]
269 || [istarget arm*-*-symbianelf*]
270 || [istarget powerpc-*-eabi*]
271 || [istarget strongarm*-*-elf]
272 || [istarget xscale*-*-elf]
273 || [istarget cris-*-*]
274 || [istarget h8300-*-*]
275 || [istarget mips*-*-elf]
276 || [istarget *-*-windiss] } {
277 set profiling_available_saved 0
279 set profiling_available_saved 1
283 return $profiling_available_saved
286 # Return true if iconv is supported on the target. In particular IBM1047.
288 proc check_iconv_available { test_what } {
296 verbose "check_iconv_available compiling testfile $src" 2
297 set f [open $src "w"]
298 # Compile a small test program.
299 puts $f "#include <iconv.h>\n"
300 puts $f "int main (void)\n {\n iconv_t cd; \n"
301 puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
302 puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
303 puts $f "return 0;\n}"
306 set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
309 if [string match "" $lines] then {
310 # No error messages, everything is OK.
312 set result [${tool}_load "./$exe" "" ""]
313 set status [lindex $result 0]
314 remote_file build delete $exe
316 verbose "check_iconv_available status is <$status>" 2
318 if { $status == "pass" } then {
326 # Return true if named sections are supported on this target.
327 # This proc does not cache results, because the answer may vary
328 # when cycling over subtarget options (e.g. irix o32/n32/n64) in
330 proc check_named_sections_available { } {
331 verbose "check_named_sections_available: compiling source" 2
332 set answer [string match "" [get_compiler_messages named object {
333 int __attribute__ ((section("whatever"))) foo;
335 verbose "check_named_sections_available: returning $answer" 2
339 # Return 1 if the target supports executing AltiVec instructions, 0
340 # otherwise. Cache the result.
342 proc check_vmx_hw_available { } {
343 global vmx_hw_available_saved
346 if [info exists vmx_hw_available_saved] {
347 verbose "check_hw_available returning saved $vmx_hw_available_saved" 2
349 set vmx_hw_available_saved 0
351 # Some simulators are known to not support VMX instructions.
352 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
353 verbose "check_hw_available returning 0" 2
354 return $vmx_hw_available_saved
357 # Set up, compile, and execute a test program containing VMX
358 # instructions. Include the current process ID in the file
359 # names to prevent conflicts with invocations for multiple
364 set f [open $src "w"]
365 puts $f "int main() {"
366 puts $f "#ifdef __MACH__"
367 puts $f " asm volatile (\"vor v0,v0,v0\");"
369 puts $f " asm volatile (\"vor 0,0,0\");"
371 puts $f " return 0; }"
374 verbose "check_vmx_hw_available compiling testfile $src" 2
375 set lines [${tool}_target_compile $src $exe executable ""]
378 if [string match "" $lines] then {
379 # No error message, compilation succeeded.
380 set result [${tool}_load "./$exe" "" ""]
381 set status [lindex $result 0]
382 remote_file build delete $exe
383 verbose "check_vmx_hw_available testfile status is <$status>" 2
385 if { $status == "pass" } then {
386 set vmx_hw_available_saved 1
389 verbose "check_vmx_hw_availalble testfile compilation failed" 2
393 return $vmx_hw_available_saved
396 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
397 # complex float arguments. This affects gfortran tests that call cabsf
398 # in libm built by an earlier compiler. Return 1 if libm uses the same
399 # argument passing as the compiler under test, 0 otherwise.
401 # When the target name changes, replace the cached result.
403 proc check_effective_target_broken_cplxf_arg { } {
404 global et_broken_cplxf_arg_saved
405 global et_broken_cplxf_arg_target_name
408 # Skip the work for targets known not to be affected.
409 if { ![istarget powerpc64-*-linux*] } {
411 } elseif { [is-effective-target ilp32] } {
415 if { ![info exists et_broken_cplxf_arg_target_name] } {
416 set et_broken_cplxf_arg_target_name ""
419 # If the target has changed since we set the cached value, clear it.
420 set current_target [current_target_name]
421 if { $current_target != $et_broken_cplxf_arg_target_name } {
422 verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
423 set et_broken_cplxf_arg_target_name $current_target
424 if [info exists et_broken_cplxf_arg_saved] {
425 verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
426 unset et_broken_cplxf_arg_saved
430 if [info exists et_broken_cplxf_arg_saved] {
431 verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
433 set et_broken_cplxf_arg_saved 0
434 # This is only known to affect one target.
435 if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
436 set et_broken_cplxf_arg_saved 0
437 verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
438 return $et_broken_cplxf_arg_saved
441 # Set up, compile, and execute a C test program that calls cabsf.
445 set f [open $src "w"]
446 puts $f "#include <complex.h>"
447 puts $f "extern void abort (void);"
448 puts $f "float fabsf (float);"
449 puts $f "float cabsf (_Complex float);"
450 puts $f "int main ()"
452 puts $f " _Complex float cf;"
454 puts $f " cf = 3 + 4.0fi;"
455 puts $f " f = cabsf (cf);"
456 puts $f " if (fabsf (f - 5.0) > 0.0001) abort ();"
461 set lines [${tool}_target_compile $src $exe executable "-lm"]
464 if [string match "" $lines] {
465 # No error message, compilation succeeded.
466 set result [${tool}_load "./$exe" "" ""]
467 set status [lindex $result 0]
468 remote_file build delete $exe
470 verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
472 if { $status != "pass" } {
473 set et_broken_cplxf_arg_saved 1
476 verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
479 return $et_broken_cplxf_arg_saved
482 proc check_alpha_max_hw_available { } {
483 global alpha_max_hw_available_saved
486 if [info exists alpha_max_hw_available_saved] {
487 verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
489 set alpha_max_hw_available_saved 0
491 # Set up, compile, and execute a test program probing bit 8 of the
492 # architecture mask, which indicates presence of MAX instructions.
496 set f [open $src "w"]
497 puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
500 verbose "check_alpha_max_hw_available compiling testfile $src" 2
501 set lines [${tool}_target_compile $src $exe executable ""]
504 if [string match "" $lines] then {
505 # No error message, compilation succeeded.
506 set result [${tool}_load "./$exe" "" ""]
507 set status [lindex $result 0]
508 remote_file build delete $exe
509 verbose "check_alpha_max_hw_available testfile status is <$status>" 2
511 if { $status == "pass" } then {
512 set alpha_max_hw_available_saved 1
515 verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
519 return $alpha_max_hw_available_saved
522 # Return 1 if we're generating 32-bit code using default options, 0
525 # When the target name changes, replace the cached result.
527 proc check_effective_target_ilp32 { } {
528 global et_ilp32_saved
529 global et_ilp32_target_name
531 if { ![info exists et_ilp32_target_name] } {
532 set et_ilp32_target_name ""
535 # If the target has changed since we set the cached value, clear it.
536 set current_target [current_target_name]
537 if { $current_target != $et_ilp32_target_name } {
538 verbose "check_effective_target_ilp32: `$et_ilp32_target_name' `$current_target'" 2
539 set et_ilp32_target_name $current_target
540 if { [info exists et_ilp32_saved] } {
541 verbose "check_effective_target_ilp32: removing cached result" 2
546 if [info exists et_ilp32_saved] {
547 verbose "check-effective_target_ilp32: using cached result" 2
549 verbose "check_effective_target_ilp32: compiling source" 2
550 set et_ilp32_saved [string match "" [get_compiler_messages ilp32 object {
551 int dummy[(sizeof (int) == 4 && sizeof (void *) == 4 && sizeof (long) == 4 ) ? 1 : -1];
554 verbose "check_effective_target_ilp32: returning $et_ilp32_saved" 2
555 return $et_ilp32_saved
558 # Return 1 if we're generating 64-bit code using default options, 0
561 # When the target name changes, replace the cached result.
563 proc check_effective_target_lp64 { } {
565 global et_lp64_target_name
567 if { ![info exists et_lp64_target_name] } {
568 set et_lp64_target_name ""
571 # If the target has changed since we set the cached value, clear it.
572 set current_target [current_target_name]
573 if { $current_target != $et_lp64_target_name } {
574 verbose "check_effective_target_lp64: `$et_lp64_target_name' `$current_target'" 2
575 set et_lp64_target_name $current_target
576 if [info exists et_lp64_saved] {
577 verbose "check_effective_target_lp64: removing cached result" 2
582 if [info exists et_lp64_saved] {
583 verbose "check_effective_target_lp64: using cached result" 2
585 verbose "check_effective_target_lp64: compiling source" 2
586 set et_lp64_saved [string match "" [get_compiler_messages lp64 object {
587 int dummy[(sizeof (int) == 4 && sizeof (void *) == 8 && sizeof (long) == 8 ) ? 1 : -1];
590 verbose "check_effective_target_lp64: returning $et_lp64_saved" 2
591 return $et_lp64_saved
594 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
596 # This won't change for different subtargets so cache the result.
598 proc check_effective_target_vect_int { } {
599 global et_vect_int_saved
601 if [info exists et_vect_int_saved] {
602 verbose "check_effective_target_vect_int: using cached result" 2
604 set et_vect_int_saved 0
605 if { [istarget i?86-*-*]
606 || [istarget powerpc*-*-*]
607 || [istarget x86_64-*-*]
608 || [istarget sparc*-*-*]
609 || [istarget alpha*-*-*]
610 || [istarget ia64-*-*] } {
611 set et_vect_int_saved 1
615 verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
616 return $et_vect_int_saved
619 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
621 # This can change for different subtargets so do not cache the result.
623 proc check_effective_target_vect_long { } {
624 if { [istarget i?86-*-*]
625 || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
626 || [istarget x86_64-*-*]
627 || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
633 verbose "check_effective_target_vect_long: returning $answer" 2
637 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
639 # This won't change for different subtargets so cache the result.
641 proc check_effective_target_vect_float { } {
642 global et_vect_float_saved
644 if [info exists et_vect_float_saved] {
645 verbose "check_effective_target_vect_float: using cached result" 2
647 set et_vect_float_saved 0
648 if { [istarget i?86-*-*]
649 || [istarget powerpc*-*-*]
650 || [istarget mipsisa64*-*-*]
651 || [istarget x86_64-*-*]
652 || [istarget ia64-*-*] } {
653 set et_vect_float_saved 1
657 verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
658 return $et_vect_float_saved
661 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
663 # This won't change for different subtargets so cache the result.
665 proc check_effective_target_vect_double { } {
666 global et_vect_double_saved
668 if [info exists et_vect_double_saved] {
669 verbose "check_effective_target_vect_double: using cached result" 2
671 set et_vect_double_saved 0
672 if { [istarget i?86-*-*]
673 || [istarget x86_64-*-*] } {
674 set et_vect_double_saved 1
678 verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
679 return $et_vect_double_saved
682 # Return 1 if the target plus current options does not support a vector
683 # max instruction, 0 otherwise.
685 # This won't change for different subtargets so cache the result.
687 proc check_effective_target_vect_no_max { } {
688 global et_vect_no_max_saved
690 if [info exists et_vect_no_max_saved] {
691 verbose "check_effective_target_vect_no_max: using cached result" 2
693 set et_vect_no_max_saved 0
694 if { [istarget i?86-*-*]
695 || [istarget x86_64-*-*]
696 || [istarget sparc*-*-*]
697 || [istarget alpha*-*-*] } {
698 set et_vect_no_max_saved 1
701 verbose "check_effective_target_vect_no_max: returning $et_vect_no_max_saved" 2
702 return $et_vect_no_max_saved
705 # Return 1 if the target plus current options does not support vector
706 # bitwise instructions, 0 otherwise.
708 # This won't change for different subtargets so cache the result.
710 proc check_effective_target_vect_no_bitwise { } {
711 global et_vect_no_bitwise_saved
713 if [info exists et_vect_no_bitwise_saved] {
714 verbose "check_effective_target_vect_no_bitwise: using cached result" 2
716 set et_vect_no_bitwise_saved 0
718 verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
719 return $et_vect_no_bitwise_saved
722 # Return 1 if the target plus current options does not support a vector
723 # alignment mechanism, 0 otherwise.
725 # This won't change for different subtargets so cache the result.
727 proc check_effective_target_vect_no_align { } {
728 global et_vect_no_align_saved
730 if [info exists et_vect_no_align_saved] {
731 verbose "check_effective_target_vect_no_align: using cached result" 2
733 set et_vect_no_align_saved 0
734 if { [istarget mipsisa64*-*-*]
735 || [istarget sparc*-*-*]
736 || [istarget ia64-*-*] } {
737 set et_vect_no_align_saved 1
740 verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
741 return $et_vect_no_align_saved
744 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
745 # This can be used with any check_* proc that takes no argument and
746 # returns only 1 or 0. It could be used with check_* procs that take
747 # arguments with keywords that pass particular arguments.
749 proc is-effective-target { arg } {
751 if { [info procs check_effective_target_${arg}] != [list] } {
752 set selected [check_effective_target_${arg}]
755 "vmx_hw" { set selected [check_vmx_hw_available] }
756 "named_sections" { set selected [check_named_sections_available] }
757 "gc_sections" { set selected [check_gc_sections_available] }
758 default { error "unknown effective target keyword `$arg'" }
761 verbose "is-effective-target: $arg $selected" 2
765 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
767 proc is-effective-target-keyword { arg } {
768 if { [info procs check_effective_target_${arg}] != [list] } {
771 # These have different names for their check_* procs.
773 "vmx_hw" { return 1 }
774 "named_sections" { return 1 }
775 "gc_sections" { return 1 }