1 # Copyright (C) 1999, 2001, 2003, 2004 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 ###############################
46 # proc check_weak_available { }
47 ###############################
49 # weak symbols are only supported in some configs/object formats
50 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
52 proc check_weak_available { } {
56 # All mips targets should support it
58 if { [ string first "mips" $target_cpu ] >= 0 } {
62 # All solaris2 targets should support it
64 if { [regexp ".*-solaris2.*" $target_triplet] } {
68 # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
70 if { [regexp "alpha.*osf.*" $target_triplet] } {
74 # Windows targets Cygwin and MingW32 support it
76 if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
80 # ELF and ECOFF support it. a.out does with gas/gld but may also with
81 # other linkers, so we should try it
83 set objformat [gcc_target_object_format]
95 ###############################
96 # proc check_visibility_available { }
97 ###############################
99 # The visibility attribute is only support in some object formats
100 # This proc returns 1 if it is supported, 0 if not.
102 proc check_visibility_available { } {
103 global visibility_available_saved
105 global target_triplet
107 # On NetWare, support makes no sense.
108 if { [string match "*-*-netware*" $target_triplet] } {
112 if {![info exists visibility_available_saved] } {
113 set lines [get_compiler_messages visibility object {
114 void f() __attribute__((visibility("hidden")));
117 if [string match "" $lines] then {
118 set visibility_available_saved 1
120 set visibility_available_saved 0
123 return $visibility_available_saved
126 ###############################
127 # proc check_alias_available { }
128 ###############################
130 # Determine if the target toolchain supports the alias attribute.
132 # Returns 2 if the target supports aliases. Returns 1 if the target
133 # only supports weak aliased. Returns 0 if the target does not
134 # support aliases at all. Returns -1 if support for aliases could not
137 proc check_alias_available { } {
138 global alias_available_saved
141 if [info exists alias_available_saved] {
142 verbose "check_alias_available returning saved $alias_available_saved" 2
146 verbose "check_alias_available compiling testfile $src" 2
147 set f [open $src "w"]
148 # Compile a small test program. The definition of "g" is
149 # necessary to keep the Solaris assembler from complaining
151 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
152 puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
154 set lines [${tool}_target_compile $src $obj object ""]
156 remote_file build delete $obj
158 if [string match "" $lines] then {
159 # No error messages, everything is OK.
160 set alias_available_saved 2
162 if [regexp "alias definitions not supported" $lines] {
163 verbose "check_alias_available target does not support aliases" 2
165 set objformat [gcc_target_object_format]
167 if { $objformat == "elf" } {
168 verbose "check_alias_available but target uses ELF format, so it ought to" 2
169 set alias_available_saved -1
171 set alias_available_saved 0
174 if [regexp "only weak aliases are supported" $lines] {
175 verbose "check_alias_available target supports only weak aliases" 2
176 set alias_available_saved 1
178 set alias_available_saved -1
183 verbose "check_alias_available returning $alias_available_saved" 2
186 return $alias_available_saved
189 # Returns true if --gc-sections is supported on the target.
191 proc check_gc_sections_available { } {
192 global gc_sections_available_saved
195 if {![info exists gc_sections_available_saved]} {
196 # Some targets don't support gc-sections despite whatever's
197 # advertised by ld's options.
198 if { [istarget alpha*-*-*]
199 || [istarget ia64-*-*] } {
200 set gc_sections_available_saved 0
204 # Check if the ld used by gcc supports --gc-sections.
205 set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
206 regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
207 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
208 set ld_output [remote_exec host "$gcc_ld" "--help"]
209 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
210 set gc_sections_available_saved 1
212 set gc_sections_available_saved 0
215 return $gc_sections_available_saved
218 # Return true if profiling is supported on the target.
220 proc check_profiling_available { test_what } {
221 global profiling_available_saved
223 verbose "Profiling argument is <$test_what>" 1
225 # These conditions depend on the argument so examine them before
226 # looking at the cache variable.
228 # Support for -p on solaris2 relies on mcrt1.o which comes with the
229 # vendor compiler. We cannot reliably predict the directory where the
230 # vendor compiler (and thus mcrt1.o) is installed so we can't
231 # necessarily find mcrt1.o even if we have it.
232 if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
236 # Support for -p on irix relies on libprof1.a which doesn't appear to
237 # exist on any irix6 system currently posting testsuite results.
238 # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
239 # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
240 if { [istarget mips*-*-irix*]
241 && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
245 # Now examine the cache variable.
246 if {![info exists profiling_available_saved]} {
247 # Some targets don't have any implementation of __bb_init_func or are
248 # missing other needed machinery.
249 if { [istarget mmix-*-*]
250 || [istarget arm*-*-eabi*]
251 || [istarget arm*-*-elf]
252 || [istarget arm*-*-symbianelf*]
253 || [istarget powerpc-*-eabi*]
254 || [istarget strongarm*-*-elf]
255 || [istarget xscale*-*-elf]
256 || [istarget cris-*-*]
257 || [istarget h8300-*-*]
258 || [istarget mips*-*-elf]
259 || [istarget *-*-windiss] } {
260 set profiling_available_saved 0
262 set profiling_available_saved 1
266 return $profiling_available_saved
269 # Return true if iconv is supported on the target. In particular IBM-1047.
271 proc check_iconv_available { test_what } {
279 verbose "check_iconv_available compiling testfile $src" 2
280 set f [open $src "w"]
281 # Compile a small test program.
282 puts $f "#include <iconv.h>\n"
283 puts $f "int main (void)\n {\n iconv_t cd; \n"
284 puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
285 puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
286 puts $f "return 0;\n}"
289 set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
292 if [string match "" $lines] then {
293 # No error messages, everything is OK.
295 set result [${tool}_load "./$exe" "" ""]
296 set status [lindex $result 0];
297 remote_file build delete $exe
299 verbose "check_iconv_available status is <$status>" 2
301 if { $status == "pass" } then {
309 # Return true if named sections are supported on this target.
310 # This proc does not cache results, because the answer may vary
311 # when cycling over subtarget options (e.g. irix o32/n32/n64) in
313 proc check_named_sections_available { } {
314 verbose "check_named_sections_available: compiling source" 2
315 set answer [string match "" [get_compiler_messages named object {
316 int __attribute__ ((section("whatever"))) foo;
318 verbose "check_named_sections_available: returning $answer" 2
322 # Return 1 if the target supports executing AltiVec instructions, 0
323 # otherwise. Cache the result.
325 proc check_vmx_hw_available { } {
326 global vmx_hw_available_saved
329 if [info exists vmx_hw_available_saved] {
330 verbose "check_hw_available returning saved $vmx_hw_available_saved" 2
332 set vmx_hw_available_saved 0
334 # Some simulators are known to not support VMX instructions.
335 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
336 verbose "check_hw_available returning 0" 2
337 return $vmx_hw_available_saved
340 # Set up, compile, and execute a test program containing VMX
341 # instructions. Include the current process ID in the file
342 # names to prevent conflicts with invocations for multiple
347 set f [open $src "w"]
348 puts $f "int main() {"
349 puts $f "#ifdef __MACH__"
350 puts $f " asm volatile (\"vor v0,v0,v0\");"
352 puts $f " asm volatile (\"vor 0,0,0\");"
354 puts $f " return 0; }"
357 verbose "check_vmx_hw_available compiling testfile $src" 2
358 set lines [${tool}_target_compile $src $exe executable ""]
361 if [string match "" $lines] then {
362 # No error message, compilation succeeded.
363 set result [${tool}_load "./$exe" "" ""]
364 set status [lindex $result 0]
365 remote_file build delete $exe
366 verbose "check_vmx_hw_available testfile status is <$status>" 2
368 if { $status == "pass" } then {
369 set vmx_hw_available_saved 1
372 verbose "check_vmx_hw_availalble testfile compilation failed" 2
376 return $vmx_hw_available_saved
379 proc check_alpha_max_hw_available { } {
380 global alpha_max_hw_available_saved
383 if [info exists alpha_max_hw_available_saved] {
384 verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
386 set alpha_max_hw_available_saved 0
388 # Set up, compile, and execute a test program probing bit 8 of the
389 # architecture mask, which indicates presence of MAX instructions.
393 set f [open $src "w"]
394 puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
397 verbose "check_alpha_max_hw_available compiling testfile $src" 2
398 set lines [${tool}_target_compile $src $exe executable ""]
401 if [string match "" $lines] then {
402 # No error message, compilation succeeded.
403 set result [${tool}_load "./$exe" "" ""]
404 set status [lindex $result 0]
405 remote_file build delete $exe
406 verbose "check_alpha_max_hw_available testfile status is <$status>" 2
408 if { $status == "pass" } then {
409 set alpha_max_hw_available_saved 1
412 verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
416 return $alpha_max_hw_available_saved
419 # Return 1 if we're generating 32-bit code using default options, 0
422 proc check_effective_target_ilp32 { } {
423 verbose "check_effective_target_ilp32: compiling source" 2
424 set answer [string match "" [get_compiler_messages ilp32 object {
425 int dummy[(sizeof (int) == 4 && sizeof (void *) == 4 && sizeof (long) == 4 ) ? 1 : -1];
427 verbose "check_effective_target_ilp32: returning $answer" 2
431 # Return 1 if we're generating 64-bit code using default options, 0
434 proc check_effective_target_lp64 { } {
435 verbose "check_effective_target_lp64: compiling source" 2
436 set answer [string match "" [get_compiler_messages lp64 object {
437 int dummy[(sizeof (int) == 4 && sizeof (void *) == 8 && sizeof (long) == 8 ) ? 1 : -1];
439 verbose "check_effective_target_lp64: returning $answer" 2
443 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
445 # This won't change for different subtargets so cache the result.
447 proc check_effective_target_vect_int { } {
448 global et_vect_int_saved
450 if [info exists et_vect_int_saved] {
451 verbose "check_effective_target_vect_int: using cached result" 2
453 set et_vect_int_saved 0
454 if { [istarget i?86-*-*]
455 || [istarget powerpc*-*-*]
456 || [istarget x86_64-*-*]
457 || [istarget sparc*-*-*]
458 || [istarget alpha*-*-*]
459 || [istarget ia64-*-*] } {
460 set et_vect_int_saved 1
464 verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
465 return $et_vect_int_saved
468 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
470 # This can change for different subtargets so do not cache the result.
472 proc check_effective_target_vect_long { } {
473 if { [istarget i?86-*-*]
474 || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
475 || [istarget x86_64-*-*]
476 || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
482 verbose "check_effective_target_vect_long: returning $answer" 2
486 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
488 # This won't change for different subtargets so cache the result.
490 proc check_effective_target_vect_float { } {
491 global et_vect_float_saved
493 if [info exists et_vect_float_saved] {
494 verbose "check_effective_target_vect_float: using cached result" 2
496 set et_vect_float_saved 0
497 if { [istarget i?86-*-*]
498 || [istarget powerpc*-*-*]
499 || [istarget mipsisa64*-*-*]
500 || [istarget x86_64-*-*]
501 || [istarget ia64-*-*] } {
502 set et_vect_float_saved 1
506 verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
507 return $et_vect_float_saved
510 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
512 # This won't change for different subtargets so cache the result.
514 proc check_effective_target_vect_double { } {
515 global et_vect_double_saved
517 if [info exists et_vect_double_saved] {
518 verbose "check_effective_target_vect_double: using cached result" 2
520 set et_vect_double_saved 0
521 if { [istarget i?86-*-*]
522 || [istarget x86_64-*-*] } {
523 set et_vect_double_saved 1
527 verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
528 return $et_vect_double_saved
531 # Return 1 if the target plus current options does not support a vector
532 # max instruction, 0 otherwise.
534 # This won't change for different subtargets so cache the result.
536 proc check_effective_target_vect_no_max { } {
537 global et_vect_no_max_saved
539 if [info exists et_vect_no_max_saved] {
540 verbose "check_effective_target_vect_no_max: using cached result" 2
542 set et_vect_no_max_saved 0
543 if { [istarget i?86-*-*]
544 || [istarget x86_64-*-*]
545 || [istarget sparc*-*-*]
546 || [istarget alpha*-*-*] } {
547 set et_vect_no_max_saved 1
550 verbose "check_effective_target_vect_no_max: returning $et_vect_no_max_saved" 2
551 return $et_vect_no_max_saved
554 # Return 1 if the target plus current options does not support vector
555 # bitwise instructions, 0 otherwise.
557 # This won't change for different subtargets so cache the result.
559 proc check_effective_target_vect_no_bitwise { } {
560 global et_vect_no_bitwise_saved
562 if [info exists et_vect_no_bitwise_saved] {
563 verbose "check_effective_target_vect_no_bitwise: using cached result" 2
565 set et_vect_no_bitwise_saved 0
567 verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
568 return $et_vect_no_bitwise_saved
571 # Return 1 if the target plus current options does not support a vector
572 # alignment mechanism, 0 otherwise.
574 # This won't change for different subtargets so cache the result.
576 proc check_effective_target_vect_no_align { } {
577 global et_vect_no_align_saved
579 if [info exists et_vect_no_align_saved] {
580 verbose "check_effective_target_vect_no_align: using cached result" 2
582 set et_vect_no_align_saved 0
583 if { [istarget mipsisa64*-*-*]
584 || [istarget sparc*-*-*]
585 || [istarget ia64-*-*] } {
586 set et_vect_no_align_saved 1
589 verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
590 return $et_vect_no_align_saved
593 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
594 # This can be used with any check_* proc that takes no argument and
595 # returns only 1 or 0. It could be used with check_* procs that take
596 # arguments with keywords that pass particular arguments.
598 proc is-effective-target { arg } {
600 if { [info procs check_effective_target_${arg}] != [list] } {
601 set selected [check_effective_target_${arg}]
604 "vmx_hw" { set selected [check_vmx_hw_available] }
605 "named_sections" { set selected [check_named_sections_available] }
606 "gc_sections" { set selected [check_gc_sections_available] }
607 default { error "unknown effective target keyword `$arg'" }
610 verbose "is-effective-target: $arg $selected" 2
614 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
616 proc is-effective-target-keyword { arg } {
617 if { [info procs check_effective_target_${arg}] != [list] } {
620 # These have different names for their check_* procs.
622 "vmx_hw" { return 1 }
623 "named_sections" { return 1 }
624 "gc_sections" { return 1 }