OSDN Git Service

PR libfortran/24432
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # gcc-patches@gcc.gnu.org
19
20 # This file defines procs for determining features supported by the target.
21
22 # Try to compile some code and return the messages printed by the compiler.
23 #
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 # The rest is optional:
28 # OPTIONS: additional compiler options to use.
29 proc get_compiler_messages {basename type contents args} {
30     global tool
31
32     if { [llength $args] > 0 } {
33         set options "additional_flags=[lindex $args 0]"
34     } else {
35         set options ""
36     }
37
38     set src ${basename}[pid].c
39     switch $type {
40         assembly { set output ${basename}[pid].s }
41         object { set output ${basename}[pid].o }
42     }
43     set f [open $src "w"]
44     puts $f $contents
45     close $f
46     set lines [${tool}_target_compile $src $output $type "$options"]
47     file delete $src
48     remote_file build delete $output
49
50     return $lines
51 }
52
53 proc current_target_name { } {
54     global target_info
55     if [info exists target_info(target,name)] {
56         set answer $target_info(target,name)
57     } else {
58         set answer ""
59     }
60     return $answer
61 }
62
63 ###############################
64 # proc check_weak_available { }
65 ###############################
66
67 # weak symbols are only supported in some configs/object formats
68 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
69
70 proc check_weak_available { } {
71     global target_triplet
72     global target_cpu
73
74     # All mips targets should support it
75
76     if { [ string first "mips" $target_cpu ] >= 0 } {
77         return 1
78     }
79
80     # All solaris2 targets should support it
81
82     if { [regexp ".*-solaris2.*" $target_triplet] } {
83         return 1
84     }
85
86     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
87
88     if { [regexp "alpha.*osf.*" $target_triplet] } {
89         return 1
90     }
91
92     # Windows targets Cygwin and MingW32 support it
93
94     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
95         return 1
96     }
97
98     # HP-UX 10.X doesn't support it
99
100     if { [regexp "hppa.*hpux10" $target_triplet] } {
101         return 0
102     }
103
104     # ELF and ECOFF support it. a.out does with gas/gld but may also with
105     # other linkers, so we should try it
106
107     set objformat [gcc_target_object_format]
108
109     switch $objformat {
110         elf      { return 1 }
111         ecoff    { return 1 }
112         a.out    { return 1 }
113         mach-o   { return 1 }
114         som      { return 1 }
115         unknown  { return -1 }
116         default  { return 0 }
117     }
118 }
119
120 ###############################
121 # proc check_visibility_available { what_kind }
122 ###############################
123
124 # The visibility attribute is only support in some object formats
125 # This proc returns 1 if it is supported, 0 if not.
126 # The argument is the kind of visibility, default/protected/hidden/internal.
127
128 proc check_visibility_available { what_kind } {
129     global visibility_available_saved
130     global tool
131     global target_triplet
132
133     # On NetWare, support makes no sense.
134     if { [string match "*-*-netware*" $target_triplet] } {
135         return 0
136     }
137
138     if [string match "" $what_kind] { set what_kind "hidden" }
139
140     if { [info exists visibility_available_saved] } {
141         verbose "Saved result is <$visibility_available_saved>" 1
142         if { [ lsearch -exact $visibility_available_saved $what_kind ] != -1 } {
143             return 1
144         } elseif { [ lsearch -exact $visibility_available_saved "!$what_kind" ] != -1 } {
145             return 0
146         }
147     }
148
149     set lines [get_compiler_messages visibility object "
150         void f() __attribute__((visibility(\"$what_kind\")));
151         void f() {}
152     "]
153     if [string match "" $lines] then {
154         set answer 1
155         lappend visibility_available_saved $what_kind
156     } else {
157         set answer 0
158         lappend visibility_available_saved "!$what_kind"
159     }
160     return $answer
161 }
162
163 ###############################
164 # proc check_alias_available { }
165 ###############################
166
167 # Determine if the target toolchain supports the alias attribute.
168
169 # Returns 2 if the target supports aliases.  Returns 1 if the target
170 # only supports weak aliased.  Returns 0 if the target does not
171 # support aliases at all.  Returns -1 if support for aliases could not
172 # be determined.
173
174 proc check_alias_available { } {
175     global alias_available_saved
176     global tool
177
178     if [info exists alias_available_saved] {
179         verbose "check_alias_available  returning saved $alias_available_saved" 2
180     } else {
181         set src alias[pid].c
182         set obj alias[pid].o
183         verbose "check_alias_available  compiling testfile $src" 2
184         set f [open $src "w"]
185         # Compile a small test program.  The definition of "g" is
186         # necessary to keep the Solaris assembler from complaining
187         # about the program.
188         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
189         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
190         close $f
191         set lines [${tool}_target_compile $src $obj object ""]
192         file delete $src
193         remote_file build delete $obj
194
195         if [string match "" $lines] then {
196             # No error messages, everything is OK.
197             set alias_available_saved 2
198         } else {
199             if [regexp "alias definitions not supported" $lines] {
200                 verbose "check_alias_available  target does not support aliases" 2
201
202                 set objformat [gcc_target_object_format]
203
204                 if { $objformat == "elf" } {
205                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
206                     set alias_available_saved -1
207                 } else {
208                     set alias_available_saved 0
209                 }
210             } else {
211                 if [regexp "only weak aliases are supported" $lines] {
212                 verbose "check_alias_available  target supports only weak aliases" 2
213                 set alias_available_saved 1
214                 } else {
215                     set alias_available_saved -1
216                 }
217             }
218         }
219
220         verbose "check_alias_available  returning $alias_available_saved" 2
221     }
222
223     return $alias_available_saved
224 }
225
226 # Returns true if --gc-sections is supported on the target.
227
228 proc check_gc_sections_available { } {
229     global gc_sections_available_saved
230     global tool
231
232     if {![info exists gc_sections_available_saved]} {
233         # Some targets don't support gc-sections despite whatever's
234         # advertised by ld's options.
235         if { [istarget alpha*-*-*]
236              || [istarget ia64-*-*] } {
237             set gc_sections_available_saved 0
238             return 0
239         }
240
241         # Check if the ld used by gcc supports --gc-sections.
242         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
243         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
244         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
245         set ld_output [remote_exec host "$gcc_ld" "--help"]
246         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
247             set gc_sections_available_saved 1
248         } else {
249             set gc_sections_available_saved 0
250         }
251     }
252     return $gc_sections_available_saved
253 }
254
255 # Return true if profiling is supported on the target.
256
257 proc check_profiling_available { test_what } {
258     global profiling_available_saved
259
260     verbose "Profiling argument is <$test_what>" 1
261
262     # These conditions depend on the argument so examine them before
263     # looking at the cache variable.
264
265     # Support for -p on solaris2 relies on mcrt1.o which comes with the
266     # vendor compiler.  We cannot reliably predict the directory where the
267     # vendor compiler (and thus mcrt1.o) is installed so we can't
268     # necessarily find mcrt1.o even if we have it.
269     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
270         return 0
271     }
272
273     # Support for -p on irix relies on libprof1.a which doesn't appear to
274     # exist on any irix6 system currently posting testsuite results.
275     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
276     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
277     if { [istarget mips*-*-irix*]
278     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
279         return 0
280     }
281
282     # Now examine the cache variable.
283     if {![info exists profiling_available_saved]} {
284         # Some targets don't have any implementation of __bb_init_func or are
285         # missing other needed machinery.
286         if { [istarget mmix-*-*]
287              || [istarget arm*-*-eabi*]
288              || [istarget arm*-*-elf]
289              || [istarget arm*-*-symbianelf*]
290              || [istarget powerpc-*-eabi*]
291              || [istarget strongarm*-*-elf]
292              || [istarget xscale*-*-elf]
293              || [istarget cris-*-*]
294              || [istarget h8300-*-*]
295              || [istarget mips*-*-elf]
296              || [istarget xtensa-*-elf]
297              || [istarget *-*-windiss] } {
298             set profiling_available_saved 0
299         } else {
300             set profiling_available_saved 1
301         }
302     }
303
304     return $profiling_available_saved
305 }
306
307 # Return 1 if target has packed layout of structure members by
308 # default, 0 otherwise.  Note that this is slightly different than
309 # whether the target has "natural alignment": both attributes may be
310 # false.
311
312 proc check_effective_target_default_packed { } {
313     global et_default_packed_saved
314     global et_default_packed_target_name
315
316     if { ![info exists et_default_packed_target_name] } {
317         set et_default_packed_target_name ""
318     }
319
320     # If the target has changed since we set the cached value, clear it.
321     set current_target [current_target_name]
322     if { $current_target != $et_default_packed_target_name } {
323         verbose "check_effective_target_default_packed: `$et_default_packed_target_name'" 2
324         set et_default_packed_target_name $current_target
325         if [info exists et_default_packed_saved] {
326             verbose "check_effective_target_default_packed: removing cached result" 2
327             unset et_default_packed_saved
328         }
329     }
330
331     if [info exists et_default_packed_saved] {
332         verbose "check_effective_target_default_packed: using cached result" 2
333     } else {
334         verbose "check_effective_target_default_packed: compiling source" 2
335
336         set et_default_packed_saved \
337             [string match "" [get_compiler_messages default_packed assembly {
338             struct x { char a; long b; } c;
339             int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
340         } ]]
341
342     }
343     verbose "check_effective_target_default_packed: returning $et_default_packed_saved" 2
344     return $et_default_packed_saved
345 }
346
347 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
348 # documentation, where the test also comes from.
349
350 proc check_effective_target_pcc_bitfield_type_matters { } {
351     global et_pcc_bitfield_type_matters_saved
352     global et_pcc_bitfield_type_matters_target_name
353
354     if { ![info exists et_pcc_bitfield_type_matters_target_name] } {
355         set et_pcc_bitfield_type_matters_target_name ""
356     }
357
358     # If the target has changed since we set the cached value, clear it.
359     set current_target [current_target_name]
360     if { $current_target != $et_pcc_bitfield_type_matters_target_name } {
361         verbose "check_effective_target_pcc_bitfield_type_matters: `$et_pcc_bitfield_type_matters_target_name'" 2
362         set et_pcc_bitfield_type_matters_target_name $current_target
363         if [info exists et_pcc_bitfield_type_matters_saved] {
364             verbose "check_effective_target_pcc_bitfield_type_matters: removing cached result" 2
365             unset et_pcc_bitfield_type_matters_saved
366         }
367     }
368
369     if [info exists et_pcc_bitfield_type_matters_saved] {
370         verbose "check_effective_target_pcc_bitfield_type_matters: using cached result" 2
371     } else {
372         verbose "check_effective_target_pcc_bitfield_type_matters: compiling source" 2
373
374         # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
375         # bitfields, but let's stick to the example code from the docs.
376         set et_pcc_bitfield_type_matters_saved \
377             [string match "" [get_compiler_messages pcc_bitfield_type_matters assembly {
378             struct foo1 { char x; char :0; char y; };
379             struct foo2 { char x; int :0; char y; };
380             int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
381         } ]]
382     }
383     verbose "check_effective_target_pcc_bitfield_type_matters: returning $et_pcc_bitfield_type_matters_saved" 2
384     return $et_pcc_bitfield_type_matters_saved
385 }
386
387 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
388 # emitted, 0 otherwise.  Whether a shared library can actually be built is
389 # out of scope for this test.
390 #
391 # When the target name changes, replace the cached result.
392
393 proc check_effective_target_fpic { } {
394     global et_fpic_saved
395     global et_fpic_target_name
396
397     if { ![info exists et_fpic_target_name] } {
398         set et_fpic_target_name ""
399     }
400
401     # If the target has changed since we set the cached value, clear it.
402     set current_target [current_target_name]
403     if { $current_target != $et_fpic_target_name } {
404         verbose "check_effective_target_fpic: `$et_fpic_target_name'" 2
405         set et_fpic_target_name $current_target
406         if [info exists et_fpic_saved] {
407             verbose "check_effective_target_fpic: removing cached result" 2
408             unset et_fpic_saved
409         }
410     }
411
412     if [info exists et_fpic_saved] {
413         verbose "check_effective_target_fpic: using cached result" 2
414     } else {
415         verbose "check_effective_target_fpic: compiling source" 2
416
417         # Note that M68K has a multilib that supports -fpic but not
418         # -fPIC, so we need to check both.  We test with a program that
419         # requires GOT references.
420         set et_fpic_saved [string match "" [get_compiler_messages fpic object {
421             extern int foo (void); extern int bar;
422             int baz (void) { return foo () + bar; }
423         } "-fpic"]]
424
425         if { $et_fpic_saved != 0 } {
426             set et_fpic_saved [string match "" [get_compiler_messages fpic object {
427                 extern int foo (void); extern int bar;
428                 int baz (void) { return foo () + bar; }
429             } "-fPIC"]]
430         }
431     }
432     verbose "check_effective_target_fpic: returning $et_fpic_saved" 2
433     return $et_fpic_saved
434 }
435
436 # Return true if iconv is supported on the target. In particular IBM1047.
437
438 proc check_iconv_available { test_what } {
439     global tool
440     global libiconv
441
442     set result ""
443
444     set src iconv[pid].c
445     set exe iconv[pid].x
446     verbose "check_iconv_available compiling testfile $src" 2
447     set f [open $src "w"]
448     # Compile a small test program.
449     puts $f "#include <iconv.h>\n"
450     puts $f "int main (void)\n {\n iconv_t cd; \n"
451     puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
452     puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
453     puts $f "return 0;\n}"
454     close $f
455
456     # If the tool configuration file has not set libiconv, try "-liconv"
457     if { ![info exists libiconv] } {
458         set libiconv "-liconv"
459     }
460     set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
461     file delete $src
462
463     if [string match "" $lines] then {
464         # No error messages, everything is OK.
465
466         set result [${tool}_load "./$exe" "" ""]
467         set status [lindex $result 0]
468         remote_file build delete $exe
469
470         verbose "check_iconv_available status is <$status>" 2
471
472         if { $status == "pass" } then {
473             return 1
474         }
475     }
476
477     return 0
478 }
479
480 # Return true if named sections are supported on this target.
481 # This proc does not cache results, because the answer may vary
482 # when cycling over subtarget options (e.g. irix o32/n32/n64) in
483 # the same test run.
484 proc check_named_sections_available { } {
485     verbose "check_named_sections_available: compiling source" 2
486     set answer [string match "" [get_compiler_messages named object {
487         int __attribute__ ((section("whatever"))) foo;
488     }]]
489     verbose "check_named_sections_available: returning $answer" 2
490     return $answer
491 }
492
493 # Return 1 if the target supports Fortran real kinds larger than real(8),
494 # 0 otherwise.
495 #
496 # When the target name changes, replace the cached result.
497
498 proc check_effective_target_fortran_large_real { } {
499     global et_fortran_large_real_saved
500     global et_fortran_large_real_target_name
501     global tool
502
503     if { ![info exists et_fortran_large_real_target_name] } {
504         set et_fortran_large_real_target_name ""
505     }
506
507     # If the target has changed since we set the cached value, clear it.
508     set current_target [current_target_name]
509     if { $current_target != $et_fortran_large_real_target_name } {
510         verbose "check_effective_target_fortran_large_real: `$et_fortran_large_real_target_name' `$current_target'" 2
511         set et_fortran_large_real_target_name $current_target
512         if [info exists et_fortran_large_real_saved] {
513             verbose "check_effective_target_fortran_large_real: removing cached result" 2
514             unset et_fortran_large_real_saved
515         }
516     }
517
518     if [info exists et_fortran_large_real_saved] {
519         verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
520     } else {
521         set et_fortran_large_real_saved 0
522
523         # Set up, compile, and execute a test program using large real
524         # kinds.  Include the current process ID in the file names to
525         # prevent conflicts with invocations for multiple testsuites.
526         set src real[pid].f90
527         set exe real[pid].x
528
529         set f [open $src "w"]
530         puts $f "integer,parameter :: k = &"
531         puts $f "  selected_real_kind (precision (0.0_8) + 1)"
532         puts $f "real(kind=k) :: x"
533         puts $f "x = cos (x);"
534         puts $f "end"
535         close $f
536
537         verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
538         set lines [${tool}_target_compile $src $exe executable ""]
539         file delete $src
540
541         if [string match "" $lines] then {
542             # No error message, compilation succeeded.
543             set et_fortran_large_real_saved 1
544         }
545     }
546
547     return $et_fortran_large_real_saved
548 }
549
550 # Return 1 if the target supports Fortran integer kinds larger than
551 # integer(8), 0 otherwise.
552 #
553 # When the target name changes, replace the cached result.
554
555 proc check_effective_target_fortran_large_int { } {
556     global et_fortran_large_int_saved
557     global et_fortran_large_int_target_name
558     global tool
559
560     if { ![info exists et_fortran_large_int_target_name] } {
561         set et_fortran_large_int_target_name ""
562     }
563
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_fortran_large_int_target_name } {
567         verbose "check_effective_target_fortran_large_int: `$et_fortran_large_int_target_name' `$current_target'" 2
568         set et_fortran_large_int_target_name $current_target
569         if [info exists et_fortran_large_int_saved] {
570             verbose "check_effective_target_fortran_large_int: removing cached result" 2
571             unset et_fortran_large_int_saved
572         }
573     }
574
575     if [info exists et_fortran_large_int_saved] {
576         verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
577     } else {
578         set et_fortran_large_int_saved 0
579
580         # Set up, compile, and execute a test program using large integer
581         # kinds.  Include the current process ID in the file names to
582         # prevent conflicts with invocations for multiple testsuites.
583         set src int[pid].f90
584         set exe int[pid].x
585
586         set f [open $src "w"]
587         puts $f "integer,parameter :: k = &"
588         puts $f "  selected_int_kind (range (0_8) + 1)"
589         puts $f "integer(kind=k) :: i"
590         puts $f "end"
591         close $f
592
593         verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
594         set lines [${tool}_target_compile $src $exe executable ""]
595         file delete $src
596
597         if [string match "" $lines] then {
598             # No error message, compilation succeeded.
599             set et_fortran_large_int_saved 1
600         }
601     }
602
603     return $et_fortran_large_int_saved
604 }
605
606 # Return 1 if we can statically link libgfortran, 0 otherwise.
607 #
608 # When the target name changes, replace the cached result.
609
610 proc check_effective_target_static_libgfortran { } {
611     global et_static_libgfortran
612     global et_static_libgfortran_target_name
613     global tool
614
615     if { ![info exists et_static_libgfortran_target_name] } {
616        set et_static_libgfortran_target_name ""
617     }
618
619     # If the target has changed since we set the cached value, clear it.
620     set current_target [current_target_name]
621     if { $current_target != $et_static_libgfortran_target_name } {
622        verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
623        set et_static_libgfortran_target_name $current_target
624        if [info exists et_static_libgfortran_saved] {
625            verbose "check_effective_target_static_libgfortran: removing cached result" 2
626            unset et_static_libgfortran_saved
627        }
628     }
629
630     if [info exists et_static_libgfortran_saved] {
631        verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
632     } else {
633        set et_static_libgfortran_saved 0
634
635        # Set up, compile, and execute a test program using static linking.
636        # Include the current process ID in the file names to prevent
637        # conflicts with invocations for multiple testsuites.
638        set opts "additional_flags=-static"
639        set src static[pid].f
640        set exe static[pid].x
641
642        set f [open $src "w"]
643        puts $f "      print *, 'test'"
644        puts $f "      end"
645        close $f
646
647        verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
648        set lines [${tool}_target_compile $src $exe executable "$opts"]
649        file delete $src
650
651        if [string match "" $lines] then {
652            # No error message, compilation succeeded.
653            set et_static_libgfortran_saved 1
654        }
655     }
656
657     return $et_static_libgfortran_saved
658 }
659
660 # Return 1 if the target supports executing AltiVec instructions, 0
661 # otherwise.  Cache the result.
662
663 proc check_vmx_hw_available { } {
664     global vmx_hw_available_saved
665     global tool
666
667     if [info exists vmx_hw_available_saved] {
668         verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
669     } else {
670         set vmx_hw_available_saved 0
671
672         # Some simulators are known to not support VMX instructions.
673         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
674             verbose "check_hw_available  returning 0" 2
675             return $vmx_hw_available_saved
676         }
677
678         # Set up, compile, and execute a test program containing VMX
679         # instructions.  Include the current process ID in the file
680         # names to prevent conflicts with invocations for multiple
681         # testsuites.
682         set src vmx[pid].c
683         set exe vmx[pid].x
684
685         set f [open $src "w"]
686         puts $f "int main() {"
687         puts $f "#ifdef __MACH__"
688         puts $f "  asm volatile (\"vor v0,v0,v0\");"
689         puts $f "#else"
690         puts $f "  asm volatile (\"vor 0,0,0\");"
691         puts $f "#endif"
692         puts $f "  return 0; }"
693         close $f
694
695         # Most targets don't require special flags for this test case, but
696         # Darwin does.
697         if [istarget *-*-darwin*] {
698           set opts "additional_flags=-maltivec"
699         } else {
700           set opts ""
701         }
702
703         verbose "check_vmx_hw_available  compiling testfile $src" 2
704         set lines [${tool}_target_compile $src $exe executable "$opts"]
705         file delete $src
706
707         if [string match "" $lines] then {
708             # No error message, compilation succeeded.
709             set result [${tool}_load "./$exe" "" ""]
710             set status [lindex $result 0]
711             remote_file build delete $exe
712             verbose "check_vmx_hw_available testfile status is <$status>" 2
713
714             if { $status == "pass" } then {
715                 set vmx_hw_available_saved 1
716             }
717         } else {
718             verbose "check_vmx_hw_availalble testfile compilation failed" 2
719         }
720     }
721
722     return $vmx_hw_available_saved
723 }
724
725 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
726 # complex float arguments.  This affects gfortran tests that call cabsf
727 # in libm built by an earlier compiler.  Return 1 if libm uses the same
728 # argument passing as the compiler under test, 0 otherwise.
729 #
730 # When the target name changes, replace the cached result.
731
732 proc check_effective_target_broken_cplxf_arg { } {
733     global et_broken_cplxf_arg_saved
734     global et_broken_cplxf_arg_target_name
735     global tool
736
737     # Skip the work for targets known not to be affected.
738     if { ![istarget powerpc64-*-linux*] } {
739         return 0
740     } elseif { [is-effective-target ilp32] } {
741         return 0
742     }
743
744     if { ![info exists et_broken_cplxf_arg_target_name] } {
745         set et_broken_cplxf_arg_target_name ""
746     }
747
748     # If the target has changed since we set the cached value, clear it.
749     set current_target [current_target_name]
750     if { $current_target != $et_broken_cplxf_arg_target_name } {
751         verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
752         set et_broken_cplxf_arg_target_name $current_target
753         if [info exists et_broken_cplxf_arg_saved] {
754             verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
755             unset et_broken_cplxf_arg_saved
756         }
757     }
758
759     if [info exists et_broken_cplxf_arg_saved] {
760         verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
761     } else {
762         set et_broken_cplxf_arg_saved 0
763         # This is only known to affect one target.
764         if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
765             set et_broken_cplxf_arg_saved 0
766             verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
767             return $et_broken_cplxf_arg_saved
768         }
769
770         # Set up, compile, and execute a C test program that calls cabsf.
771         set src cabsf[pid].c
772         set exe cabsf[pid].x
773
774         set f [open $src "w"]
775         puts $f "#include <complex.h>"
776         puts $f "extern void abort (void);"
777         puts $f "float fabsf (float);"
778         puts $f "float cabsf (_Complex float);"
779         puts $f "int main ()"
780         puts $f "{"
781         puts $f "  _Complex float cf;"
782         puts $f "  float f;"
783         puts $f "  cf = 3 + 4.0fi;"
784         puts $f "  f = cabsf (cf);"
785         puts $f "  if (fabsf (f - 5.0) > 0.0001) abort ();"
786         puts $f "  return 0;"
787         puts $f "}"
788         close $f
789
790         set lines [${tool}_target_compile $src $exe executable "-lm"]
791         file delete $src
792
793         if [string match "" $lines] {
794             # No error message, compilation succeeded.
795             set result [${tool}_load "./$exe" "" ""]
796             set status [lindex $result 0]
797             remote_file build delete $exe
798
799             verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
800
801             if { $status != "pass" } {
802                 set et_broken_cplxf_arg_saved 1
803             }
804         } else {
805             verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
806         }
807     }
808     return $et_broken_cplxf_arg_saved
809 }
810
811 proc check_alpha_max_hw_available { } {
812     global alpha_max_hw_available_saved
813     global tool
814
815     if [info exists alpha_max_hw_available_saved] {
816         verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
817     } else {
818         set alpha_max_hw_available_saved 0
819
820         # Set up, compile, and execute a test program probing bit 8 of the
821         # architecture mask, which indicates presence of MAX instructions.
822         set src max[pid].c
823         set exe max[pid].x
824
825         set f [open $src "w"]
826         puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
827         close $f
828
829         verbose "check_alpha_max_hw_available compiling testfile $src" 2
830         set lines [${tool}_target_compile $src $exe executable ""]
831         file delete $src
832
833         if [string match "" $lines] then {
834             # No error message, compilation succeeded.
835             set result [${tool}_load "./$exe" "" ""]
836             set status [lindex $result 0]
837             remote_file build delete $exe
838             verbose "check_alpha_max_hw_available testfile status is <$status>" 2
839
840             if { $status == "pass" } then {
841                 set alpha_max_hw_available_saved 1
842             }
843         } else {
844             verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
845         }
846     }
847
848     return $alpha_max_hw_available_saved
849 }
850
851 # Returns true iff the FUNCTION is available on the target system.
852 # (This is essentially a Tcl implementation of Autoconf's
853 # AC_CHECK_FUNC.)
854
855 proc check_function_available { function } {
856     set var "${function}_available_saved"
857     global $var
858     global tool
859
860     if {![info exists $var]} {
861         # Assume it exists.
862         set $var 1
863         # Check to make sure.
864         set src "function[pid].c"
865         set exe "function[pid].exe"
866
867         set f [open $src "w"]
868         puts $f "int main () { $function (); }"
869         close $f
870
871         set lines [${tool}_target_compile $src $exe executable ""]
872         file delete $src
873         file delete $exe
874
875         if {![string match "" $lines]} then {
876             set $var 0
877             verbose -log "$function is not available"
878         } else {
879             verbose -log "$function is available"
880         }
881     }
882
883     eval return \$$var
884 }
885
886 # Returns true iff "fork" is available on the target system.
887
888 proc check_fork_available {} {
889     return [check_function_available "fork"]
890 }
891
892 # Returns true iff "mkfifo" is available on the target system.
893
894 proc check_mkfifo_available {} {
895     if {[istarget *-*-cygwin*]} {
896        # Cygwin has mkfifo, but support is incomplete.
897        return 0
898      }
899
900     return [check_function_available "mkfifo"]
901 }
902
903 # Return 1 if we're generating 32-bit code using default options, 0
904 # otherwise.
905 #
906 # When the target name changes, replace the cached result.
907
908 proc check_effective_target_ilp32 { } {
909     global et_ilp32_saved
910     global et_ilp32_target_name
911
912     if { ![info exists et_ilp32_target_name] } {
913         set et_ilp32_target_name ""
914     }
915
916     # If the target has changed since we set the cached value, clear it.
917     set current_target [current_target_name]
918     if { $current_target != $et_ilp32_target_name } {
919         verbose "check_effective_target_ilp32: `$et_ilp32_target_name' `$current_target'" 2
920         set et_ilp32_target_name $current_target
921         if { [info exists et_ilp32_saved] } {
922             verbose "check_effective_target_ilp32: removing cached result" 2
923             unset et_ilp32_saved
924         }
925     }
926
927     if [info exists et_ilp32_saved] {
928         verbose "check-effective_target_ilp32: using cached result" 2
929     } else {
930         verbose "check_effective_target_ilp32: compiling source" 2
931         set et_ilp32_saved [string match "" [get_compiler_messages ilp32 object {
932             int dummy[(sizeof (int) == 4 && sizeof (void *) == 4 && sizeof (long) == 4 ) ? 1 : -1];
933         }]]
934     }
935     verbose "check_effective_target_ilp32: returning $et_ilp32_saved" 2
936     return $et_ilp32_saved
937 }
938
939 # Return 1 if we're generating 64-bit code using default options, 0
940 # otherwise.
941 #
942 # When the target name changes, replace the cached result.
943
944 proc check_effective_target_lp64 { } {
945     global et_lp64_saved
946     global et_lp64_target_name
947
948     if { ![info exists et_lp64_target_name] } {
949         set et_lp64_target_name ""
950     }
951
952     # If the target has changed since we set the cached value, clear it.
953     set current_target [current_target_name]
954     if { $current_target != $et_lp64_target_name } {
955         verbose "check_effective_target_lp64: `$et_lp64_target_name' `$current_target'" 2
956         set et_lp64_target_name $current_target
957         if [info exists et_lp64_saved] {
958             verbose "check_effective_target_lp64: removing cached result" 2
959             unset et_lp64_saved
960         }
961     }
962
963     if [info exists et_lp64_saved] {
964         verbose "check_effective_target_lp64: using cached result" 2
965     } else {
966         verbose "check_effective_target_lp64: compiling source" 2
967         set et_lp64_saved [string match "" [get_compiler_messages lp64 object {
968             int dummy[(sizeof (int) == 4 && sizeof (void *) == 8 && sizeof (long) == 8 ) ? 1 : -1];
969         }]]
970     }
971     verbose "check_effective_target_lp64: returning $et_lp64_saved" 2
972     return $et_lp64_saved
973 }
974
975 # Return 1 if the target needs a command line argument to enable a SIMD
976 # instruction set.
977 #
978 # This won't change for different subtargets so cache the result.
979
980 proc check_effective_target_vect_cmdline_needed { } {
981     global et_vect_cmdline_needed_saved
982
983     if [info exists et_vect_cmdline_needed_saved] {
984         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
985     } else {
986         set et_vect_cmdline_needed_saved 1
987         if { [istarget ia64-*-*]
988               || [istarget x86_64-*-*] } {
989            set et_vect_cmdline_needed_saved 0
990         }
991     }
992
993     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
994     return $et_vect_cmdline_needed_saved
995 }
996
997 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
998 #
999 # This won't change for different subtargets so cache the result.
1000
1001 proc check_effective_target_vect_int { } {
1002     global et_vect_int_saved
1003
1004     if [info exists et_vect_int_saved] {
1005         verbose "check_effective_target_vect_int: using cached result" 2
1006     } else {
1007         set et_vect_int_saved 0
1008         if { [istarget i?86-*-*]
1009               || [istarget powerpc*-*-*]
1010               || [istarget x86_64-*-*]
1011               || [istarget sparc*-*-*]
1012               || [istarget alpha*-*-*]
1013               || [istarget ia64-*-*] } {
1014            set et_vect_int_saved 1
1015         }
1016     }
1017
1018     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1019     return $et_vect_int_saved
1020 }
1021
1022 # Return 1 is this is an arm target using 32-bit instructions
1023 proc check_effective_target_arm32 { } {
1024     global et_arm32_saved
1025     global et_arm32_target_name
1026     global compiler_flags
1027
1028     if { ![info exists et_arm32_target_name] } {
1029         set et_arm32_target_name ""
1030     }
1031
1032     # If the target has changed since we set the cached value, clear it.
1033     set current_target [current_target_name]
1034     if { $current_target != $et_arm32_target_name } {
1035         verbose "check_effective_target_arm32: `$et_arm32_target_name' `$current_target'" 2
1036         set et_arm32_target_name $current_target
1037         if { [info exists et_arm32_saved] } {
1038             verbose "check_effective_target_arm32: removing cached result" 2
1039             unset et_arm32_saved
1040         }
1041     }
1042
1043     if [info exists et_arm32_saved] {
1044         verbose "check-effective_target_arm32: using cached result" 2
1045     } else {
1046         set et_arm32_saved 0
1047         if { [istarget arm-*-*]
1048               || [istarget strongarm*-*-*]
1049               || [istarget xscale-*-*] } {
1050             if ![string match "*-mthumb *" $compiler_flags] {
1051                 set et_arm32_saved 1
1052             }
1053         }
1054     }
1055     verbose "check_effective_target_arm32: returning $et_arm32_saved" 2
1056     return $et_arm32_saved
1057 }
1058
1059 # Return 1 if the target supports hardware vector shift operation.
1060
1061 proc check_effective_target_vect_shift { } {
1062     global et_vect_shift_saved
1063
1064     if [info exists et_vect_shift_saved] {
1065         verbose "check_effective_target_vect_shift: using cached result" 2
1066     } else {
1067         set et_vect_shift_saved 0
1068         if { [istarget powerpc*-*-*]
1069              || [istarget ia64-*-*]
1070              || [istarget i?86-*-*]
1071              || [istarget x86_64-*-*] } {
1072            set et_vect_shift_saved 1
1073         }
1074     }
1075
1076     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1077     return $et_vect_shift_saved
1078 }
1079
1080 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1081 #
1082 # This can change for different subtargets so do not cache the result.
1083
1084 proc check_effective_target_vect_long { } {
1085     if { [istarget i?86-*-*]
1086          || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
1087          || [istarget x86_64-*-*]
1088          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1089         set answer 1
1090     } else {
1091         set answer 0
1092     }
1093
1094     verbose "check_effective_target_vect_long: returning $answer" 2
1095     return $answer
1096 }
1097
1098 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1099 #
1100 # This won't change for different subtargets so cache the result.
1101
1102 proc check_effective_target_vect_float { } {
1103     global et_vect_float_saved
1104
1105     if [info exists et_vect_float_saved] {
1106         verbose "check_effective_target_vect_float: using cached result" 2
1107     } else {
1108         set et_vect_float_saved 0
1109         if { [istarget i?86-*-*]
1110               || [istarget powerpc*-*-*]
1111               || [istarget mipsisa64*-*-*]
1112               || [istarget x86_64-*-*]
1113               || [istarget ia64-*-*] } {
1114            set et_vect_float_saved 1
1115         }
1116     }
1117
1118     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1119     return $et_vect_float_saved
1120 }
1121
1122 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1123 #
1124 # This won't change for different subtargets so cache the result.
1125
1126 proc check_effective_target_vect_double { } {
1127     global et_vect_double_saved
1128
1129     if [info exists et_vect_double_saved] {
1130         verbose "check_effective_target_vect_double: using cached result" 2
1131     } else {
1132         set et_vect_double_saved 0
1133         if { [istarget i?86-*-*]
1134               || [istarget x86_64-*-*] } {
1135            set et_vect_double_saved 1
1136         }
1137     }
1138
1139     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1140     return $et_vect_double_saved
1141 }
1142
1143 # Return 1 if the target plus current options does not support a vector
1144 # max instruction on "int", 0 otherwise.
1145 #
1146 # This won't change for different subtargets so cache the result.
1147
1148 proc check_effective_target_vect_no_int_max { } {
1149     global et_vect_no_int_max_saved
1150
1151     if [info exists et_vect_no_int_max_saved] {
1152         verbose "check_effective_target_vect_no_int_max: using cached result" 2
1153     } else {
1154         set et_vect_no_int_max_saved 0
1155         if { [istarget sparc*-*-*]
1156              || [istarget alpha*-*-*] } {
1157             set et_vect_no_int_max_saved 1
1158         }
1159     }
1160     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1161     return $et_vect_no_int_max_saved
1162 }
1163
1164 # Return 1 if the target plus current options does not support a vector
1165 # add instruction on "int", 0 otherwise.
1166 #
1167 # This won't change for different subtargets so cache the result.
1168
1169 proc check_effective_target_vect_no_int_add { } {
1170     global et_vect_no_int_add_saved
1171
1172     if [info exists et_vect_no_int_add_saved] {
1173         verbose "check_effective_target_vect_no_int_add: using cached result" 2
1174     } else {
1175         set et_vect_no_int_add_saved 0
1176         # Alpha only supports vector add on V8QI and V4HI.
1177         if { [istarget alpha*-*-*] } {
1178             set et_vect_no_int_add_saved 1
1179         }
1180     }
1181     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1182     return $et_vect_no_int_add_saved
1183 }
1184
1185 # Return 1 if the target plus current options does not support vector
1186 # bitwise instructions, 0 otherwise.
1187 #
1188 # This won't change for different subtargets so cache the result.
1189
1190 proc check_effective_target_vect_no_bitwise { } {
1191     global et_vect_no_bitwise_saved
1192
1193     if [info exists et_vect_no_bitwise_saved] {
1194         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1195     } else {
1196         set et_vect_no_bitwise_saved 0
1197     }
1198     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1199     return $et_vect_no_bitwise_saved
1200 }
1201
1202 # Return 1 if the target plus current options does not support a vector
1203 # alignment mechanism, 0 otherwise.
1204 #
1205 # This won't change for different subtargets so cache the result.
1206
1207 proc check_effective_target_vect_no_align { } {
1208     global et_vect_no_align_saved
1209
1210     if [info exists et_vect_no_align_saved] {
1211         verbose "check_effective_target_vect_no_align: using cached result" 2
1212     } else {
1213         set et_vect_no_align_saved 0
1214         if { [istarget mipsisa64*-*-*]
1215              || [istarget sparc*-*-*]
1216              || [istarget ia64-*-*] } {
1217             set et_vect_no_align_saved 1
1218         }
1219     }
1220     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
1221     return $et_vect_no_align_saved
1222 }
1223
1224 # Return 1 if the target supports vector conditional operations, 0 otherwise.
1225
1226 proc check_effective_target_vect_condition { } {
1227     global et_vect_cond_saved
1228
1229     if [info exists et_vect_cond_saved] {
1230         verbose "check_effective_target_vect_cond: using cached result" 2
1231     } else {
1232         set et_vect_cond_saved 0
1233         if { [istarget powerpc*-*-*]
1234              || [istarget ia64-*-*]
1235              || [istarget i?86-*-*]
1236              || [istarget x86_64-*-*] } {
1237            set et_vect_cond_saved 1
1238         }
1239     }
1240
1241     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
1242     return $et_vect_cond_saved
1243 }
1244
1245 # Return 1 if the target supports vector int multiplication, 0 otherwise.
1246
1247 proc check_effective_target_vect_int_mult { } {
1248     global et_vect_int_mult_saved
1249
1250     if [info exists et_vect_int_mult_saved] {
1251         verbose "check_effective_target_vect_int_mult: using cached result" 2
1252     } else {
1253         set et_vect_int_mult_saved 0
1254         if { [istarget powerpc*-*-*]
1255              || [istarget i?86-*-*]
1256              || [istarget x86_64-*-*] } {
1257            set et_vect_int_mult_saved 1
1258         }
1259     }
1260
1261     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
1262     return $et_vect_int_mult_saved
1263 }
1264
1265 # Return 1 if the target supports atomic operations on "int" and "long".
1266
1267 proc check_effective_target_sync_int_long { } {
1268     global et_sync_int_long_saved
1269
1270     if [info exists et_sync_int_long_saved] {
1271         verbose "check_effective_target_sync_int_long: using cached result" 2
1272     } else {
1273         set et_sync_int_long_saved 0
1274 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1275 # load-reserved/store-conditional instructions.
1276         if { [istarget ia64-*-*]
1277              || [istarget i?86-*-*]
1278              || [istarget x86_64-*-*]
1279              || [istarget alpha*-*-*] 
1280              || [istarget s390*-*-*] 
1281              || [istarget powerpc*-*-*] } {
1282            set et_sync_int_long_saved 1
1283         }
1284     }
1285
1286     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
1287     return $et_sync_int_long_saved
1288 }
1289
1290 # Return 1 if the target supports atomic operations on "char" and "short".
1291
1292 proc check_effective_target_sync_char_short { } {
1293     global et_sync_char_short_saved
1294
1295     if [info exists et_sync_char_short_saved] {
1296         verbose "check_effective_target_sync_char_short: using cached result" 2
1297     } else {
1298         set et_sync_char_short_saved 0
1299 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1300 # load-reserved/store-conditional instructions.
1301         if { [istarget ia64-*-*]
1302              || [istarget i?86-*-*]
1303              || [istarget x86_64-*-*]
1304              || [istarget alpha*-*-*] 
1305              || [istarget powerpc*-*-*] } {
1306            set et_sync_char_short_saved 1
1307         }
1308     }
1309
1310     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
1311     return $et_sync_char_short_saved
1312 }
1313
1314 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
1315 # This can be used with any check_* proc that takes no argument and
1316 # returns only 1 or 0.  It could be used with check_* procs that take
1317 # arguments with keywords that pass particular arguments.
1318
1319 proc is-effective-target { arg } {
1320     set selected 0
1321     if { [info procs check_effective_target_${arg}] != [list] } {
1322         set selected [check_effective_target_${arg}]
1323     } else {
1324         switch $arg {
1325           "vmx_hw"         { set selected [check_vmx_hw_available] }
1326           "named_sections" { set selected [check_named_sections_available] }
1327           "gc_sections"    { set selected [check_gc_sections_available] }
1328           default          { error "unknown effective target keyword `$arg'" }
1329         }
1330     }
1331     verbose "is-effective-target: $arg $selected" 2
1332     return $selected
1333 }
1334
1335 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
1336
1337 proc is-effective-target-keyword { arg } {
1338     if { [info procs check_effective_target_${arg}] != [list] } {
1339         return 1
1340     } else {
1341         # These have different names for their check_* procs.
1342         switch $arg {
1343           "vmx_hw"         { return 1 }
1344           "named_sections" { return 1 }
1345           "gc_sections"    { return 1 }
1346           default          { return 0 }
1347         }
1348     }
1349 }