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 # ELF and ECOFF support it. a.out does with gas
/gld but may also with
91 # other linkers
, so we should try it
93 set objformat
[gcc_target_object_format
]
100 unknown
{ return -1 }
105 ###############################
106 # proc check_visibility_available
{ }
107 ###############################
109 # The visibility attribute is only support in some object formats
110 # This proc returns
1 if it is supported
, 0 if not.
112 proc check_visibility_available
{ } {
113 global visibility_available_saved
115 global target_triplet
117 #
On NetWare
, support makes no sense.
118 if { [string match
"*-*-netware*" $target_triplet] } {
122 if {![info exists visibility_available_saved
] } {
123 set lines
[get_compiler_messages visibility object
{
124 void f
() __attribute__
((visibility
("hidden")));
127 if [string match
"" $lines] then {
128 set visibility_available_saved
1
130 set visibility_available_saved
0
133 return $visibility_available_saved
136 ###############################
137 # proc check_alias_available
{ }
138 ###############################
140 # Determine
if the target toolchain supports the alias attribute.
142 # Returns
2 if the target supports aliases. Returns
1 if the target
143 # only supports weak aliased. Returns
0 if the target does not
144 # support aliases at all. Returns
-1 if support
for aliases could not
147 proc check_alias_available
{ } {
148 global alias_available_saved
151 if [info exists alias_available_saved
] {
152 verbose
"check_alias_available returning saved $alias_available_saved" 2
156 verbose
"check_alias_available compiling testfile $src" 2
157 set f
[open $src
"w"]
158 #
Compile a small test
program. The definition of
"g" is
159 # necessary to keep the Solaris assembler from complaining
161 puts $f
"#ifdef __cplusplus\nextern \"C\"\n#endif\n"
162 puts $f
"void g() {} void f() __attribute__((alias(\"g\")));"
164 set lines
[$
{tool
}_target_compile $src $
obj object
""]
166 remote_file build
delete $
obj
168 if [string match
"" $lines] then {
169 # No error messages
, everything is OK.
170 set alias_available_saved
2
172 if [regexp
"alias definitions not supported" $lines] {
173 verbose
"check_alias_available target does not support aliases" 2
175 set objformat
[gcc_target_object_format
]
177 if { $objformat
== "elf" } {
178 verbose
"check_alias_available but target uses ELF format, so it ought to" 2
179 set alias_available_saved
-1
181 set alias_available_saved
0
184 if [regexp
"only weak aliases are supported" $lines] {
185 verbose
"check_alias_available target supports only weak aliases" 2
186 set alias_available_saved
1
188 set alias_available_saved
-1
193 verbose
"check_alias_available returning $alias_available_saved" 2
196 return $alias_available_saved
199 # Returns true
if --gc
-sections is supported
on the target.
201 proc check_gc_sections_available
{ } {
202 global gc_sections_available_saved
205 if {![info exists gc_sections_available_saved
]} {
206 # Some targets don
't support gc-sections despite whatever's
207 # advertised by
ld's options.
208 if { [istarget alpha*-*-*]
209 || [istarget ia64-*-*] } {
210 set gc_sections_available_saved 0
214 # Check if the ld used by gcc supports --gc-sections.
215 set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
216 regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
217 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
218 set ld_output [remote_exec host "$gcc_ld" "--help"]
219 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
220 set gc_sections_available_saved 1
222 set gc_sections_available_saved 0
225 return $gc_sections_available_saved
228 # Return true if profiling is supported on the target.
230 proc check_profiling_available { test_what } {
231 global profiling_available_saved
233 verbose "Profiling argument is <$test_what>" 1
235 # These conditions depend on the argument so examine them before
236 # looking at the cache variable.
238 # Support for -p on solaris2 relies on mcrt1.o which comes with the
239 # vendor compiler. We cannot reliably predict the directory where the
240 # vendor compiler (and thus mcrt1.o) is installed so we can't
241 # necessarily find mcrt1.o even
if we have it.
242 if { [istarget
*-*-solaris2
*] && [lindex $test_what
1] == "-p" } {
246 # Support
for -p
on irix relies
on libprof1.a which doesn
't appear to
247 # exist on any irix6 system currently posting testsuite results.
248 # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
249 # See
: http
://gcc.gnu.org
/ml
/gcc
/2002-10/msg00169.html
250 if { [istarget mips
*-*-irix
*]
251 && ([lindex $test_what
1] == "-p" || [lindex $test_what 1] == "-pg") } {
255 # Now examine the
cache variable.
256 if {![info exists profiling_available_saved
]} {
257 # Some targets don
't have any implementation of __bb_init_func or are
258 # missing other needed machinery.
259 if { [istarget mmix-*-*]
260 || [istarget arm*-*-eabi*]
261 || [istarget arm*-*-elf]
262 || [istarget arm*-*-symbianelf*]
263 || [istarget powerpc-*-eabi*]
264 || [istarget strongarm*-*-elf]
265 || [istarget xscale*-*-elf]
266 || [istarget cris-*-*]
267 || [istarget h8300-*-*]
268 || [istarget mips*-*-elf]
269 || [istarget *-*-windiss] } {
270 set profiling_available_saved 0
272 set profiling_available_saved 1
276 return $profiling_available_saved
279 # Return true if iconv is supported on the target. In particular IBM-1047.
281 proc check_iconv_available { test_what } {
289 verbose "check_iconv_available compiling testfile $src" 2
290 set f [open $src "w"]
291 # Compile a small test program.
292 puts $f "#include <iconv.h>\n"
293 puts $f "int main (void)\n {\n iconv_t cd; \n"
294 puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
295 puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
296 puts $f "return 0;\n}"
299 set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
302 if [string match "" $lines] then {
303 # No error messages, everything is OK.
305 set result [${tool}_load "./$exe" "" ""]
306 set status [lindex $result 0];
307 remote_file build delete $exe
309 verbose "check_iconv_available status is <$status>" 2
311 if { $status == "pass" } then {
319 # Return true if named sections are supported on this target.
320 # This proc does not cache results, because the answer may vary
321 # when cycling over subtarget options (e.g. irix o32/n32/n64) in
323 proc check_named_sections_available { } {
324 verbose "check_named_sections_available: compiling source" 2
325 set answer [string match "" [get_compiler_messages named object {
326 int __attribute__ ((section("whatever"))) foo;
328 verbose "check_named_sections_available: returning $answer" 2
332 # Return 1 if the target supports executing AltiVec instructions, 0
333 # otherwise. Cache the result.
335 proc check_vmx_hw_available { } {
336 global vmx_hw_available_saved
339 if [info exists vmx_hw_available_saved] {
340 verbose "check_hw_available returning saved $vmx_hw_available_saved" 2
342 set vmx_hw_available_saved 0
344 # Some simulators are known to not support VMX instructions.
345 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
346 verbose "check_hw_available returning 0" 2
347 return $vmx_hw_available_saved
350 # Set up, compile, and execute a test program containing VMX
351 # instructions. Include the current process ID in the file
352 # names to prevent conflicts with invocations for multiple
357 set f [open $src "w"]
358 puts $f "int main() {"
359 puts $f "#ifdef __MACH__"
360 puts $f " asm volatile (\"vor v0,v0,v0\");"
362 puts $f " asm volatile (\"vor 0,0,0\");"
364 puts $f " return 0; }"
367 verbose "check_vmx_hw_available compiling testfile $src" 2
368 set lines [${tool}_target_compile $src $exe executable ""]
371 if [string match "" $lines] then {
372 # No error message, compilation succeeded.
373 set result [${tool}_load "./$exe" "" ""]
374 set status [lindex $result 0]
375 remote_file build delete $exe
376 verbose "check_vmx_hw_available testfile status is <$status>" 2
378 if { $status == "pass" } then {
379 set vmx_hw_available_saved 1
382 verbose "check_vmx_hw_availalble testfile compilation failed" 2
386 return $vmx_hw_available_saved
389 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
390 # complex float arguments. This affects gfortran tests that call cabsf
391 # in libm built by an earlier compiler. Return 1 if libm uses the same
392 # argument passing as the compiler under test, 0 otherwise.
394 # When the target name changes, replace the cached result.
396 proc check_effective_target_broken_cplxf_arg { } {
397 global et_broken_cplxf_arg_saved
398 global et_broken_cplxf_arg_target_name
401 # Skip the work for targets known not to be affected.
402 if { ![istarget powerpc64-*-linux*] } {
404 } elseif { [is-effective-target ilp32] } {
408 if { ![info exists et_broken_cplxf_arg_target_name] } {
409 set et_broken_cplxf_arg_target_name ""
412 # If the target has changed since we set the cached value, clear it.
413 set current_target [current_target_name]
414 if { $current_target != $et_broken_cplxf_arg_target_name } {
415 verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
416 set et_broken_cplxf_arg_target_name $current_target
417 if [info exists et_broken_cplxf_arg_saved
] {
418 verbose
"check_effective_target_broken_cplxf_arg: removing cached result" 2
419 unset et_broken_cplxf_arg_saved
423 if [info exists et_broken_cplxf_arg_saved
] {
424 verbose
"check_effective_target_broken_cplxf_arg: using cached result" 2
426 set et_broken_cplxf_arg_saved
0
427 # This is only known to affect one target.
428 if { ![istarget powerpc64
-*-linux
*] ||
![is
-effective
-target lp64
] } {
429 set et_broken_cplxf_arg_saved
0
430 verbose
"check_effective_target_broken_cplxf_arg: caching 0" 2
431 return $et_broken_cplxf_arg_saved
434 #
Set up
, compile, and
execute a C test
program that calls cabsf.
438 set f
[open $src
"w"]
439 puts $f
"#include <complex.h>"
440 puts $f
"extern void abort (void);"
441 puts $f
"float fabsf (float);"
442 puts $f
"float cabsf (_Complex float);"
443 puts $f
"int main ()"
445 puts $f
" _Complex float cf;"
447 puts $f
" cf = 3 + 4.0fi;"
448 puts $f
" f = cabsf (cf);"
449 puts $f
" if (fabsf (f - 5.0) > 0.0001) abort ();"
454 set lines
[$
{tool
}_target_compile $src $exe executable
"-lm"]
457 if [string match
"" $lines] {
458 # No error message
, compilation succeeded.
459 set result
[$
{tool
}_load
"./$exe" "" ""]
460 set status [lindex $result
0]
461 remote_file build
delete $exe
463 verbose
"check_effective_target_broken_cplxf_arg: status is <$status>" 2
465 if { $
status != "pass" } {
466 set et_broken_cplxf_arg_saved
1
469 verbose
"check_effective_target_broken_cplxf_arg: compilation failed" 2
472 return $et_broken_cplxf_arg_saved
475 proc check_alpha_max_hw_available
{ } {
476 global alpha_max_hw_available_saved
479 if [info exists alpha_max_hw_available_saved
] {
480 verbose
"check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
482 set alpha_max_hw_available_saved
0
484 #
Set up
, compile, and
execute a test
program probing bit
8 of the
485 # architecture mask
, which indicates presence of
MAX instructions.
489 set f
[open $src
"w"]
490 puts $f
"int main() { return __builtin_alpha_amask(1<<8) != 0; }"
493 verbose
"check_alpha_max_hw_available compiling testfile $src" 2
494 set lines
[$
{tool
}_target_compile $src $exe executable
""]
497 if [string match
"" $lines] then {
498 # No error message
, compilation succeeded.
499 set result
[$
{tool
}_load
"./$exe" "" ""]
500 set status [lindex $result
0]
501 remote_file build
delete $exe
502 verbose
"check_alpha_max_hw_available testfile status is <$status>" 2
504 if { $
status == "pass" } then {
505 set alpha_max_hw_available_saved
1
508 verbose
"check_alpha_max_hw_availalble testfile compilation failed" 2
512 return $alpha_max_hw_available_saved
515 #
Return 1 if we
're generating 32-bit code using default options, 0
518 # When the target name changes, replace the cached result.
520 proc check_effective_target_ilp32 { } {
521 global et_ilp32_saved
522 global et_ilp32_target_name
524 if { ![info exists et_ilp32_target_name] } {
525 set et_ilp32_target_name ""
528 # If the target has changed since we set the cached value, clear it.
529 set current_target [current_target_name]
530 if { $current_target != $et_ilp32_target_name } {
531 verbose "check_effective_target_ilp32: `$et_ilp32_target_name' `$current_target
'" 2
532 set et_ilp32_target_name $current_target
533 if { [info exists et_ilp32_saved] } {
534 verbose "check_effective_target_ilp32: removing cached result" 2
539 if [info exists et_ilp32_saved] {
540 verbose "check-effective_target_ilp32: using cached result" 2
542 verbose "check_effective_target_ilp32: compiling source" 2
543 set et_ilp32_saved [string match "" [get_compiler_messages ilp32 object {
544 int dummy[(sizeof (int) == 4 && sizeof (void *) == 4 && sizeof (long) == 4 ) ? 1 : -1];
547 verbose "check_effective_target_ilp32: returning $et_ilp32_saved" 2
548 return $et_ilp32_saved
551 # Return 1 if we're generating
64-bit code using default options
, 0
554 # When the target
name changes
, replace the cached result.
556 proc check_effective_target_lp64
{ } {
558 global et_lp64_target_name
560 if { ![info exists et_lp64_target_name
] } {
561 set et_lp64_target_name
""
564 #
If the target has changed since we
set the cached value
, clear it.
565 set current_target
[current_target_name
]
566 if { $current_target
!= $et_lp64_target_name
} {
567 verbose
"check_effective_target_lp64: `$et_lp64_target_name' `$current_target'" 2
568 set et_lp64_target_name $current_target
569 if [info exists et_lp64_saved
] {
570 verbose
"check_effective_target_lp64: removing cached result" 2
575 if [info exists et_lp64_saved
] {
576 verbose
"check_effective_target_lp64: using cached result" 2
578 verbose
"check_effective_target_lp64: compiling source" 2
579 set et_lp64_saved
[string match
"" [get_compiler_messages lp64 object {
580 int dummy
[(sizeof
(int) == 4 && sizeof
(void
*) == 8 && sizeof
(long
) == 8 ) ?
1 : -1];
583 verbose
"check_effective_target_lp64: returning $et_lp64_saved" 2
584 return $et_lp64_saved
587 #
Return 1 if the target supports hardware vectors of
int, 0 otherwise.
589 # This won
't change for different subtargets so cache the result.
591 proc check_effective_target_vect_int { } {
592 global et_vect_int_saved
594 if [info exists et_vect_int_saved] {
595 verbose "check_effective_target_vect_int: using cached result" 2
597 set et_vect_int_saved 0
598 if { [istarget i?86-*-*]
599 || [istarget powerpc*-*-*]
600 || [istarget x86_64-*-*]
601 || [istarget sparc*-*-*]
602 || [istarget alpha*-*-*]
603 || [istarget ia64-*-*] } {
604 set et_vect_int_saved 1
608 verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
609 return $et_vect_int_saved
612 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
614 # This can change for different subtargets so do not cache the result.
616 proc check_effective_target_vect_long { } {
617 if { [istarget i?86-*-*]
618 || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
619 || [istarget x86_64-*-*]
620 || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
626 verbose "check_effective_target_vect_long: returning $answer" 2
630 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
632 # This won't change
for different subtargets so
cache the result.
634 proc check_effective_target_vect_float
{ } {
635 global et_vect_float_saved
637 if [info exists et_vect_float_saved
] {
638 verbose
"check_effective_target_vect_float: using cached result" 2
640 set et_vect_float_saved
0
641 if { [istarget i?
86-*-*]
642 ||
[istarget powerpc
*-*-*]
643 ||
[istarget mipsisa64
*-*-*]
644 ||
[istarget x86_64
-*-*]
645 ||
[istarget ia64
-*-*] } {
646 set et_vect_float_saved
1
650 verbose
"check_effective_target_vect_float: returning $et_vect_float_saved" 2
651 return $et_vect_float_saved
654 #
Return 1 if the target supports hardware vectors of double
, 0 otherwise.
656 # This won
't change for different subtargets so cache the result.
658 proc check_effective_target_vect_double { } {
659 global et_vect_double_saved
661 if [info exists et_vect_double_saved] {
662 verbose "check_effective_target_vect_double: using cached result" 2
664 set et_vect_double_saved 0
665 if { [istarget i?86-*-*]
666 || [istarget x86_64-*-*] } {
667 set et_vect_double_saved 1
671 verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
672 return $et_vect_double_saved
675 # Return 1 if the target plus current options does not support a vector
676 # max instruction, 0 otherwise.
678 # This won't change
for different subtargets so
cache the result.
680 proc check_effective_target_vect_no_max
{ } {
681 global et_vect_no_max_saved
683 if [info exists et_vect_no_max_saved
] {
684 verbose
"check_effective_target_vect_no_max: using cached result" 2
686 set et_vect_no_max_saved
0
687 if { [istarget i?
86-*-*]
688 ||
[istarget x86_64
-*-*]
689 ||
[istarget sparc
*-*-*]
690 ||
[istarget alpha
*-*-*] } {
691 set et_vect_no_max_saved
1
694 verbose
"check_effective_target_vect_no_max: returning $et_vect_no_max_saved" 2
695 return $et_vect_no_max_saved
698 #
Return 1 if the target plus current options does not support vector
699 # bitwise instructions
, 0 otherwise.
701 # This won
't change for different subtargets so cache the result.
703 proc check_effective_target_vect_no_bitwise { } {
704 global et_vect_no_bitwise_saved
706 if [info exists et_vect_no_bitwise_saved] {
707 verbose "check_effective_target_vect_no_bitwise: using cached result" 2
709 set et_vect_no_bitwise_saved 0
711 verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
712 return $et_vect_no_bitwise_saved
715 # Return 1 if the target plus current options does not support a vector
716 # alignment mechanism, 0 otherwise.
718 # This won't change
for different subtargets so
cache the result.
720 proc check_effective_target_vect_no_align
{ } {
721 global et_vect_no_align_saved
723 if [info exists et_vect_no_align_saved
] {
724 verbose
"check_effective_target_vect_no_align: using cached result" 2
726 set et_vect_no_align_saved
0
727 if { [istarget mipsisa64
*-*-*]
728 ||
[istarget sparc
*-*-*]
729 ||
[istarget ia64
-*-*] } {
730 set et_vect_no_align_saved
1
733 verbose
"check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
734 return $et_vect_no_align_saved
737 #
Return 1 if the target matches the effective target
'arg', 0 otherwise.
738 # This can be used with
any check_
* proc that takes no
argument and
739 # returns only
1 or
0. It could be used with check_
* procs that take
740 # arguments with keywords that pass particular arguments.
742 proc is
-effective
-target
{ arg } {
744 if { [info procs check_effective_target_$
{arg}] != [list
] } {
745 set selected
[check_effective_target_$
{arg}]
748 "vmx_hw" { set selected [check_vmx_hw_available] }
749 "named_sections" { set selected [check_named_sections_available] }
750 "gc_sections" { set selected [check_gc_sections_available] }
751 default
{ error
"unknown effective target keyword `$arg'" }
754 verbose
"is-effective-target: $arg $selected" 2
758 #
Return 1 if the
argument is an effective
-target keyword
, 0 otherwise.
760 proc is
-effective
-target
-keyword
{ arg } {
761 if { [info procs check_effective_target_$
{arg}] != [list
] } {
764 # These have different names
for their check_
* procs.
766 "vmx_hw" { return 1 }
767 "named_sections" { return 1 }
768 "gc_sections" { return 1 }