OSDN Git Service

gcc/testsuite/
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007
2 #   Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # gcc-patches@gcc.gnu.org
20
21 # This file defines procs for determining features supported by the target.
22
23 # Try to compile some code and return the messages printed by the compiler,
24 # and optionally the contents for assembly files.  Either a string or
25 # a list of two strings are returned, depending on WANT_OUTPUT.
26 #
27 # BASENAME is a basename to use for temporary files.
28 # WANT_OUTPUT is a flag which is 0 to request returning just the
29 #   compiler messages, or 1 to return the messages and the contents
30 #   of the assembly file.  TYPE should be "assembly" if WANT_OUTPUT
31 #   is set.
32 # TYPE is the type of compilation to perform (see target_compile).
33 # CONTENTS gives the contents of the input file.
34 # The rest is optional:
35 # OPTIONS: additional compiler options to use.
36 proc get_compiler_messages {basename want_output type contents args} {
37     global tool
38
39     if { [llength $args] > 0 } {
40         set options [list "additional_flags=[lindex $args 0]"]
41     } else {
42         set options ""
43     }
44
45     set src ${basename}[pid].c
46     switch $type {
47         assembly { set output ${basename}[pid].s }
48         object { set output ${basename}[pid].o }
49     }
50     set f [open $src "w"]
51     puts $f $contents
52     close $f
53     set lines [${tool}_target_compile $src $output $type "$options"]
54     file delete $src
55
56     if { $want_output } {
57         if { $type != "assembly" } {
58             error "WANT_OUTPUT can only be used with assembly output"
59         } elseif { ![string match "" $lines] } {
60             # An error occurred.
61             set result [list $lines ""]
62         } else {
63             set text ""
64             set chan [open "$output"]
65             while {[gets $chan line] >= 0} {
66                 append text "$line\n"
67             }
68             close $chan
69             set result [list $lines $text]
70         }
71     } else {
72         set result $lines
73     }
74
75     remote_file build delete $output
76     return $result
77 }
78
79 proc current_target_name { } {
80     global target_info
81     if [info exists target_info(target,name)] {
82         set answer $target_info(target,name)
83     } else {
84         set answer ""
85     }
86     return $answer
87 }
88
89 # Implement an effective-target check for property PROP by invoking
90 # the compiler and seeing if it prints any messages.  Assume that the
91 # property holds if the compiler doesn't print anything.  The other
92 # arguments are as for get_compiler_messages, starting with TYPE.
93 proc check_no_compiler_messages {prop args} {
94     global et_cache
95
96     set target [current_target_name]
97     if {![info exists et_cache($prop,target)]
98         || $et_cache($prop,target) != $target} {
99         verbose "check_no_compiler_messages $prop: compiling source for $target" 2
100         set et_cache($prop,target) $target
101         set et_cache($prop,value) \
102             [string match "" [eval get_compiler_messages $prop 0 $args]]
103     }
104     set value $et_cache($prop,value)
105     verbose "check_no_compiler_messages $prop: returning $value for $target" 2
106     return $value
107 }
108
109 # Similar to check_no_compiler_messages, but also verify that the regular
110 # expression PATTERN matches the compiler's output.
111 proc check_no_messages_and_pattern {prop pattern args} {
112     global et_cache
113
114     set target [current_target_name]
115     if {![info exists et_cache($prop,target)]
116         || $et_cache($prop,target) != $target} {
117         verbose "check_no_messages_and_pattern $prop: compiling source for $target" 2
118         set et_cache($prop,target) $target
119         set results [eval get_compiler_messages $prop 1 $args]
120         set et_cache($prop,value) \
121             [expr [string match "" [lindex $results 0]] \
122                  && [regexp $pattern [lindex $results 1]]]
123     }
124     set value $et_cache($prop,value)
125     verbose "check_no_messages_and_pattern $prop: returning $value for $target" 2
126     return $value
127 }
128
129 ###############################
130 # proc check_weak_available { }
131 ###############################
132
133 # weak symbols are only supported in some configs/object formats
134 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
135
136 proc check_weak_available { } {
137     global target_triplet
138     global target_cpu
139
140     # All mips targets should support it
141
142     if { [ string first "mips" $target_cpu ] >= 0 } {
143         return 1
144     }
145
146     # All solaris2 targets should support it
147
148     if { [regexp ".*-solaris2.*" $target_triplet] } {
149         return 1
150     }
151
152     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
153
154     if { [regexp "alpha.*osf.*" $target_triplet] } {
155         return 1
156     }
157
158     # Windows targets Cygwin and MingW32 support it
159
160     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
161         return 1
162     }
163
164     # HP-UX 10.X doesn't support it
165
166     if { [istarget "hppa*-*-hpux10*"] } {
167         return 0
168     }
169
170     # ELF and ECOFF support it. a.out does with gas/gld but may also with
171     # other linkers, so we should try it
172
173     set objformat [gcc_target_object_format]
174
175     switch $objformat {
176         elf      { return 1 }
177         ecoff    { return 1 }
178         a.out    { return 1 }
179         mach-o   { return 1 }
180         som      { return 1 }
181         unknown  { return -1 }
182         default  { return 0 }
183     }
184 }
185
186 ###############################
187 # proc check_visibility_available { what_kind }
188 ###############################
189
190 # The visibility attribute is only support in some object formats
191 # This proc returns 1 if it is supported, 0 if not.
192 # The argument is the kind of visibility, default/protected/hidden/internal.
193
194 proc check_visibility_available { what_kind } {
195     global tool
196     global target_triplet
197
198     # On NetWare, support makes no sense.
199     if { [istarget *-*-netware*] } {
200         return 0
201     }
202
203     if [string match "" $what_kind] { set what_kind "hidden" }
204
205     return [check_no_compiler_messages visibility_available_$what_kind object "
206         void f() __attribute__((visibility(\"$what_kind\")));
207         void f() {}
208     "]
209 }
210
211 ###############################
212 # proc check_alias_available { }
213 ###############################
214
215 # Determine if the target toolchain supports the alias attribute.
216
217 # Returns 2 if the target supports aliases.  Returns 1 if the target
218 # only supports weak aliased.  Returns 0 if the target does not
219 # support aliases at all.  Returns -1 if support for aliases could not
220 # be determined.
221
222 proc check_alias_available { } {
223     global alias_available_saved
224     global tool
225
226     if [info exists alias_available_saved] {
227         verbose "check_alias_available  returning saved $alias_available_saved" 2
228     } else {
229         set src alias[pid].c
230         set obj alias[pid].o
231         verbose "check_alias_available  compiling testfile $src" 2
232         set f [open $src "w"]
233         # Compile a small test program.  The definition of "g" is
234         # necessary to keep the Solaris assembler from complaining
235         # about the program.
236         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
237         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
238         close $f
239         set lines [${tool}_target_compile $src $obj object ""]
240         file delete $src
241         remote_file build delete $obj
242
243         if [string match "" $lines] then {
244             # No error messages, everything is OK.
245             set alias_available_saved 2
246         } else {
247             if [regexp "alias definitions not supported" $lines] {
248                 verbose "check_alias_available  target does not support aliases" 2
249
250                 set objformat [gcc_target_object_format]
251
252                 if { $objformat == "elf" } {
253                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
254                     set alias_available_saved -1
255                 } else {
256                     set alias_available_saved 0
257                 }
258             } else {
259                 if [regexp "only weak aliases are supported" $lines] {
260                 verbose "check_alias_available  target supports only weak aliases" 2
261                 set alias_available_saved 1
262                 } else {
263                     set alias_available_saved -1
264                 }
265             }
266         }
267
268         verbose "check_alias_available  returning $alias_available_saved" 2
269     }
270
271     return $alias_available_saved
272 }
273
274 # Returns true if --gc-sections is supported on the target.
275
276 proc check_gc_sections_available { } {
277     global gc_sections_available_saved
278     global tool
279
280     if {![info exists gc_sections_available_saved]} {
281         # Some targets don't support gc-sections despite whatever's
282         # advertised by ld's options.
283         if { [istarget alpha*-*-*]
284              || [istarget ia64-*-*] } {
285             set gc_sections_available_saved 0
286             return 0
287         }
288
289         # VxWorks kernel modules are relocatable objects linked with -r,
290         # while RTP executables are linked with -q (--emit-relocs).
291         # Both of these options are incompatible with --gc-sections.
292         if { [istarget *-*-vxworks*] } {
293             set gc_sections_available_saved 0
294             return 0
295         }
296
297         # Check if the ld used by gcc supports --gc-sections.
298         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
299         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
300         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
301         set ld_output [remote_exec host "$gcc_ld" "--help"]
302         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
303             set gc_sections_available_saved 1
304         } else {
305             set gc_sections_available_saved 0
306         }
307     }
308     return $gc_sections_available_saved
309 }
310
311 # Return true if profiling is supported on the target.
312
313 proc check_profiling_available { test_what } {
314     global profiling_available_saved
315
316     verbose "Profiling argument is <$test_what>" 1
317
318     # These conditions depend on the argument so examine them before
319     # looking at the cache variable.
320
321     # Support for -p on solaris2 relies on mcrt1.o which comes with the
322     # vendor compiler.  We cannot reliably predict the directory where the
323     # vendor compiler (and thus mcrt1.o) is installed so we can't
324     # necessarily find mcrt1.o even if we have it.
325     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
326         return 0
327     }
328
329     # Support for -p on irix relies on libprof1.a which doesn't appear to
330     # exist on any irix6 system currently posting testsuite results.
331     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
332     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
333     if { [istarget mips*-*-irix*]
334     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
335         return 0
336     }
337
338     # At present, there is no profiling support on NetWare.
339     if { [istarget *-*-netware*] } {
340         return 0
341     }
342
343     # Now examine the cache variable.
344     if {![info exists profiling_available_saved]} {
345         # Some targets don't have any implementation of __bb_init_func or are
346         # missing other needed machinery.
347         if { [istarget mmix-*-*]
348              || [istarget arm*-*-eabi*]
349              || [istarget arm*-*-elf]
350              || [istarget arm*-*-symbianelf*]
351              || [istarget bfin-*-*]
352              || [istarget powerpc-*-eabi*]
353              || [istarget strongarm*-*-elf]
354              || [istarget xscale*-*-elf]
355              || [istarget cris-*-*]
356              || [istarget h8300-*-*]
357              || [istarget m32c-*-elf]
358              || [istarget m68k-*-elf]
359              || [istarget mips*-*-elf]
360              || [istarget xtensa-*-elf]
361              || [istarget *-*-vxworks*]
362              || [istarget *-*-windiss] } {
363             set profiling_available_saved 0
364         } else {
365             set profiling_available_saved 1
366         }
367     }
368
369     return $profiling_available_saved
370 }
371
372 # Return 1 if target has packed layout of structure members by
373 # default, 0 otherwise.  Note that this is slightly different than
374 # whether the target has "natural alignment": both attributes may be
375 # false.
376
377 proc check_effective_target_default_packed { } {
378     return [check_no_compiler_messages default_packed assembly {
379         struct x { char a; long b; } c;
380         int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
381     }]
382 }
383
384 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
385 # documentation, where the test also comes from.
386
387 proc check_effective_target_pcc_bitfield_type_matters { } {
388     # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
389     # bitfields, but let's stick to the example code from the docs.
390     return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
391         struct foo1 { char x; char :0; char y; };
392         struct foo2 { char x; int :0; char y; };
393         int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
394     }]
395 }
396
397 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
398 #
399 # This won't change for different subtargets so cache the result.
400
401 proc check_effective_target_tls {} {
402     global et_tls_saved
403     global tool
404
405     if [info exists et_tls_saved] {
406         verbose "check_effective_target_tls: using cached result" 2
407     } else {
408         set et_tls_saved 1
409
410         set src tls[pid].c
411         set asm tls[pid].S
412         verbose "check_effective_target_tls: compiling testfile $src" 2
413         set f [open $src "w"]
414         # Compile a small test program.
415         puts $f "__thread int i;\n"
416         close $f
417
418         # Test for thread-local data supported by the platform.
419         set comp_output [${tool}_target_compile $src $asm assembly ""]
420         file delete $src
421         if { [string match "*not supported*" $comp_output] } {
422             set et_tls_saved 0
423         } else {
424             set fd [open $asm r]
425             set text [read $fd]
426             close $fd
427             if { [string match "*emutls*" $text]} {
428                 set et_tls_saved 0
429             } else {
430                 set et_tls_saved 1
431             }
432         }
433         remove-build-file $asm
434     }
435     verbose "check_effective_target_tls: returning $et_tls_saved" 2
436     return $et_tls_saved
437 }
438
439 # Return 1 if TLS executables can run correctly, 0 otherwise.
440 #
441 # This won't change for different subtargets so cache the result.
442
443 proc check_effective_target_tls_runtime {} {
444     global et_tls_runtime_saved
445     global tool
446
447     if [info exists et_tls_runtime_saved] {
448         verbose "check_effective_target_tls_runtime: using cached result" 2
449     } else {
450         set et_tls_runtime_saved 0
451
452         set src tls_runtime[pid].c
453         set exe tls_runtime[pid].x
454         verbose "check_effective_target_tls_runtime: compiling testfile $src" 2
455         set f [open $src "w"]
456         # Compile a small test program.
457         puts $f "__thread int thr = 0;\n"
458         puts $f "int main(void)\n {\n return thr;\n}"
459         close $f
460
461         set comp_output \
462             [${tool}_target_compile $src $exe executable ""]
463         file delete $src
464
465         if [string match "" $comp_output] then {
466             # No error messages, everything is OK.
467
468             set result [remote_load target "./$exe" "" ""]
469             set status [lindex $result 0]
470             remote_file build delete $exe
471
472             verbose "check_effective_target_tls_runtime status is <$status>" 2
473
474             if { $status == "pass" } {
475                 set et_tls_runtime_saved 1
476             }
477
478             verbose "check_effective_target_tls_runtime: returning $et_tls_runtime_saved" 2
479         }
480     }
481
482     return $et_tls_runtime_saved
483 }
484
485 # Return 1 if compilation with -fopenmp is error-free for trivial
486 # code, 0 otherwise.
487
488 proc check_effective_target_fopenmp {} {
489     return [check_no_compiler_messages fopenmp object {
490         void foo (void) { }
491     } "-fopenmp"]
492 }
493
494 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
495 # for trivial code, 0 otherwise.
496
497 proc check_effective_target_freorder {} {
498     return [check_no_compiler_messages freorder object {
499         void foo (void) { }
500     } "-freorder-blocks-and-partition"]
501 }
502
503 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
504 # emitted, 0 otherwise.  Whether a shared library can actually be built is
505 # out of scope for this test.
506
507 proc check_effective_target_fpic { } {
508     # Note that M68K has a multilib that supports -fpic but not
509     # -fPIC, so we need to check both.  We test with a program that
510     # requires GOT references.
511     foreach arg {fpic fPIC} {
512         if [check_no_compiler_messages $arg object {
513             extern int foo (void); extern int bar;
514             int baz (void) { return foo () + bar; }
515         } "-$arg"] {
516             return 1
517         }
518     }
519     return 0
520 }
521
522 # Return true if the target supports -mpaired-single (as used on MIPS).
523
524 proc check_effective_target_mpaired_single { } {
525     return [check_no_compiler_messages mpaired_single object {
526         void foo (void) { }
527     } "-mpaired-single"]
528 }
529
530 # Return 1 if the target does not use a status wrapper.
531
532 proc check_effective_target_unwrapped { } {
533     if { [target_info needs_status_wrapper] != "" \
534              && [target_info needs_status_wrapper] != "0" } {
535         return 0
536     }
537     return 1
538 }
539
540 # Return true if iconv is supported on the target. In particular IBM1047.
541
542 proc check_iconv_available { test_what } {
543     global tool
544     global libiconv
545
546     set result ""
547
548     set src iconv[pid].c
549     set exe iconv[pid].x
550     verbose "check_iconv_available compiling testfile $src" 2
551     set f [open $src "w"]
552     # Compile a small test program.
553     puts $f "#include <iconv.h>\n"
554     puts $f "int main (void)\n {\n iconv_t cd; \n"
555     puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
556     puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
557     puts $f "return 0;\n}"
558     close $f
559
560     # If the tool configuration file has not set libiconv, try "-liconv"
561     if { ![info exists libiconv] } {
562         set libiconv "-liconv"
563     }
564     set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
565     file delete $src
566
567     if [string match "" $lines] then {
568         # No error messages, everything is OK.
569
570         set result [${tool}_load "./$exe" "" ""]
571         set status [lindex $result 0]
572         remote_file build delete $exe
573
574         verbose "check_iconv_available status is <$status>" 2
575
576         if { $status == "pass" } then {
577             return 1
578         }
579     }
580
581     return 0
582 }
583
584 # Return true if named sections are supported on this target.
585
586 proc check_named_sections_available { } {
587     return [check_no_compiler_messages named_sections assembly {
588         int __attribute__ ((section("whatever"))) foo;
589     }]
590 }
591
592 # Return 1 if the target supports Fortran real kinds larger than real(8),
593 # 0 otherwise.
594 #
595 # When the target name changes, replace the cached result.
596
597 proc check_effective_target_fortran_large_real { } {
598     global et_fortran_large_real_saved
599     global et_fortran_large_real_target_name
600     global tool
601
602     if { ![info exists et_fortran_large_real_target_name] } {
603         set et_fortran_large_real_target_name ""
604     }
605
606     # If the target has changed since we set the cached value, clear it.
607     set current_target [current_target_name]
608     if { $current_target != $et_fortran_large_real_target_name } {
609         verbose "check_effective_target_fortran_large_real: `$et_fortran_large_real_target_name' `$current_target'" 2
610         set et_fortran_large_real_target_name $current_target
611         if [info exists et_fortran_large_real_saved] {
612             verbose "check_effective_target_fortran_large_real: removing cached result" 2
613             unset et_fortran_large_real_saved
614         }
615     }
616
617     if [info exists et_fortran_large_real_saved] {
618         verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
619     } else {
620         set et_fortran_large_real_saved 0
621
622         # Set up, compile, and execute a test program using large real
623         # kinds.  Include the current process ID in the file names to
624         # prevent conflicts with invocations for multiple testsuites.
625         set src real[pid].f90
626         set exe real[pid].x
627
628         set f [open $src "w"]
629         puts $f "integer,parameter :: k = &"
630         puts $f "  selected_real_kind (precision (0.0_8) + 1)"
631         puts $f "real(kind=k) :: x"
632         puts $f "x = cos (x);"
633         puts $f "end"
634         close $f
635
636         verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
637         set lines [${tool}_target_compile $src $exe executable ""]
638         file delete $src
639
640         if [string match "" $lines] then {
641             # No error message, compilation succeeded.
642             set et_fortran_large_real_saved 1
643         }
644     }
645
646     return $et_fortran_large_real_saved
647 }
648
649 # Return 1 if the target supports Fortran integer kinds larger than
650 # integer(8), 0 otherwise.
651 #
652 # When the target name changes, replace the cached result.
653
654 proc check_effective_target_fortran_large_int { } {
655     global et_fortran_large_int_saved
656     global et_fortran_large_int_target_name
657     global tool
658
659     if { ![info exists et_fortran_large_int_target_name] } {
660         set et_fortran_large_int_target_name ""
661     }
662
663     # If the target has changed since we set the cached value, clear it.
664     set current_target [current_target_name]
665     if { $current_target != $et_fortran_large_int_target_name } {
666         verbose "check_effective_target_fortran_large_int: `$et_fortran_large_int_target_name' `$current_target'" 2
667         set et_fortran_large_int_target_name $current_target
668         if [info exists et_fortran_large_int_saved] {
669             verbose "check_effective_target_fortran_large_int: removing cached result" 2
670             unset et_fortran_large_int_saved
671         }
672     }
673
674     if [info exists et_fortran_large_int_saved] {
675         verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
676     } else {
677         set et_fortran_large_int_saved 0
678
679         # Set up, compile, and execute a test program using large integer
680         # kinds.  Include the current process ID in the file names to
681         # prevent conflicts with invocations for multiple testsuites.
682         set src int[pid].f90
683         set exe int[pid].x
684
685         set f [open $src "w"]
686         puts $f "integer,parameter :: k = &"
687         puts $f "  selected_int_kind (range (0_8) + 1)"
688         puts $f "integer(kind=k) :: i"
689         puts $f "end"
690         close $f
691
692         verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
693         set lines [${tool}_target_compile $src $exe executable ""]
694         file delete $src
695
696         if [string match "" $lines] then {
697             # No error message, compilation succeeded.
698             set et_fortran_large_int_saved 1
699         }
700     }
701
702     return $et_fortran_large_int_saved
703 }
704
705 # Return 1 if we can statically link libgfortran, 0 otherwise.
706 #
707 # When the target name changes, replace the cached result.
708
709 proc check_effective_target_static_libgfortran { } {
710     global et_static_libgfortran
711     global et_static_libgfortran_target_name
712     global tool
713
714     if { ![info exists et_static_libgfortran_target_name] } {
715        set et_static_libgfortran_target_name ""
716     }
717
718     # If the target has changed since we set the cached value, clear it.
719     set current_target [current_target_name]
720     if { $current_target != $et_static_libgfortran_target_name } {
721        verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
722        set et_static_libgfortran_target_name $current_target
723        if [info exists et_static_libgfortran_saved] {
724            verbose "check_effective_target_static_libgfortran: removing cached result" 2
725            unset et_static_libgfortran_saved
726        }
727     }
728
729     if [info exists et_static_libgfortran_saved] {
730        verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
731     } else {
732        set et_static_libgfortran_saved 0
733
734        # Set up, compile, and execute a test program using static linking.
735        # Include the current process ID in the file names to prevent
736        # conflicts with invocations for multiple testsuites.
737        set opts "additional_flags=-static"
738        set src static[pid].f
739        set exe static[pid].x
740
741        set f [open $src "w"]
742        puts $f "      print *, 'test'"
743        puts $f "      end"
744        close $f
745
746        verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
747        set lines [${tool}_target_compile $src $exe executable "$opts"]
748        file delete $src
749
750        if [string match "" $lines] then {
751            # No error message, compilation succeeded.
752            set et_static_libgfortran_saved 1
753        }
754     }
755
756     return $et_static_libgfortran_saved
757 }
758
759 # Return 1 if the target supports executing AltiVec instructions, 0
760 # otherwise.  Cache the result.
761
762 proc check_vmx_hw_available { } {
763     global vmx_hw_available_saved
764     global tool
765
766     if [info exists vmx_hw_available_saved] {
767         verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
768     } else {
769         set vmx_hw_available_saved 0
770
771         # Some simulators are known to not support VMX instructions.
772         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
773             verbose "check_hw_available  returning 0" 2
774             return $vmx_hw_available_saved
775         }
776
777         # Set up, compile, and execute a test program containing VMX
778         # instructions.  Include the current process ID in the file
779         # names to prevent conflicts with invocations for multiple
780         # testsuites.
781         set src vmx[pid].c
782         set exe vmx[pid].x
783
784         set f [open $src "w"]
785         puts $f "int main() {"
786         puts $f "#ifdef __MACH__"
787         puts $f "  asm volatile (\"vor v0,v0,v0\");"
788         puts $f "#else"
789         puts $f "  asm volatile (\"vor 0,0,0\");"
790         puts $f "#endif"
791         puts $f "  return 0; }"
792         close $f
793
794         # Most targets don't require special flags for this test case, but
795         # Darwin does.
796         if [istarget *-*-darwin*] {
797           set opts "additional_flags=-maltivec"
798         } else {
799           set opts ""
800         }
801
802         verbose "check_vmx_hw_available  compiling testfile $src" 2
803         set lines [${tool}_target_compile $src $exe executable "$opts"]
804         file delete $src
805
806         if [string match "" $lines] then {
807             # No error message, compilation succeeded.
808             set result [${tool}_load "./$exe" "" ""]
809             set status [lindex $result 0]
810             remote_file build delete $exe
811             verbose "check_vmx_hw_available testfile status is <$status>" 2
812
813             if { $status == "pass" } then {
814                 set vmx_hw_available_saved 1
815             }
816         } else {
817             verbose "check_vmx_hw_availalble testfile compilation failed" 2
818         }
819     }
820
821     return $vmx_hw_available_saved
822 }
823
824 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
825 # complex float arguments.  This affects gfortran tests that call cabsf
826 # in libm built by an earlier compiler.  Return 1 if libm uses the same
827 # argument passing as the compiler under test, 0 otherwise.
828 #
829 # When the target name changes, replace the cached result.
830
831 proc check_effective_target_broken_cplxf_arg { } {
832     global et_broken_cplxf_arg_saved
833     global et_broken_cplxf_arg_target_name
834     global tool
835
836     # Skip the work for targets known not to be affected.
837     if { ![istarget powerpc64-*-linux*] } {
838         return 0
839     } elseif { [is-effective-target ilp32] } {
840         return 0
841     }
842
843     if { ![info exists et_broken_cplxf_arg_target_name] } {
844         set et_broken_cplxf_arg_target_name ""
845     }
846
847     # If the target has changed since we set the cached value, clear it.
848     set current_target [current_target_name]
849     if { $current_target != $et_broken_cplxf_arg_target_name } {
850         verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
851         set et_broken_cplxf_arg_target_name $current_target
852         if [info exists et_broken_cplxf_arg_saved] {
853             verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
854             unset et_broken_cplxf_arg_saved
855         }
856     }
857
858     if [info exists et_broken_cplxf_arg_saved] {
859         verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
860     } else {
861         set et_broken_cplxf_arg_saved 0
862         # This is only known to affect one target.
863         if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
864             set et_broken_cplxf_arg_saved 0
865             verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
866             return $et_broken_cplxf_arg_saved
867         }
868
869         # Set up, compile, and execute a C test program that calls cabsf.
870         set src cabsf[pid].c
871         set exe cabsf[pid].x
872
873         set f [open $src "w"]
874         puts $f "#include <complex.h>"
875         puts $f "extern void abort (void);"
876         puts $f "float fabsf (float);"
877         puts $f "float cabsf (_Complex float);"
878         puts $f "int main ()"
879         puts $f "{"
880         puts $f "  _Complex float cf;"
881         puts $f "  float f;"
882         puts $f "  cf = 3 + 4.0fi;"
883         puts $f "  f = cabsf (cf);"
884         puts $f "  if (fabsf (f - 5.0) > 0.0001) abort ();"
885         puts $f "  return 0;"
886         puts $f "}"
887         close $f
888
889         set lines [${tool}_target_compile $src $exe executable "-lm"]
890         file delete $src
891
892         if [string match "" $lines] {
893             # No error message, compilation succeeded.
894             set result [${tool}_load "./$exe" "" ""]
895             set status [lindex $result 0]
896             remote_file build delete $exe
897
898             verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
899
900             if { $status != "pass" } {
901                 set et_broken_cplxf_arg_saved 1
902             }
903         } else {
904             verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
905         }
906     }
907     return $et_broken_cplxf_arg_saved
908 }
909
910 proc check_alpha_max_hw_available { } {
911     global alpha_max_hw_available_saved
912     global tool
913
914     if [info exists alpha_max_hw_available_saved] {
915         verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
916     } else {
917         set alpha_max_hw_available_saved 0
918
919         # Set up, compile, and execute a test program probing bit 8 of the
920         # architecture mask, which indicates presence of MAX instructions.
921         set src max[pid].c
922         set exe max[pid].x
923
924         set f [open $src "w"]
925         puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
926         close $f
927
928         verbose "check_alpha_max_hw_available compiling testfile $src" 2
929         set lines [${tool}_target_compile $src $exe executable ""]
930         file delete $src
931
932         if [string match "" $lines] then {
933             # No error message, compilation succeeded.
934             set result [${tool}_load "./$exe" "" ""]
935             set status [lindex $result 0]
936             remote_file build delete $exe
937             verbose "check_alpha_max_hw_available testfile status is <$status>" 2
938
939             if { $status == "pass" } then {
940                 set alpha_max_hw_available_saved 1
941             }
942         } else {
943             verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
944         }
945     }
946
947     return $alpha_max_hw_available_saved
948 }
949
950 # Returns true iff the FUNCTION is available on the target system.
951 # (This is essentially a Tcl implementation of Autoconf's
952 # AC_CHECK_FUNC.)
953
954 proc check_function_available { function } {
955     set var "${function}_available_saved"
956     global $var
957     global tool
958
959     if {![info exists $var]} {
960         # Assume it exists.
961         set $var 1
962         # Check to make sure.
963         set src "function[pid].c"
964         set exe "function[pid].exe"
965
966         set f [open $src "w"]
967         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
968         puts $f "char $function ();\n"
969         puts $f "int main () { $function (); }"
970         close $f
971
972         set lines [${tool}_target_compile $src $exe executable ""]
973         file delete $src
974         file delete $exe
975
976         if {![string match "" $lines]} then {
977             set $var 0
978             verbose -log "$function is not available"
979         } else {
980             verbose -log "$function is available"
981         }
982     }
983
984     eval return \$$var
985 }
986
987 # Returns true iff "fork" is available on the target system.
988
989 proc check_fork_available {} {
990     return [check_function_available "fork"]
991 }
992
993 # Returns true iff "mkfifo" is available on the target system.
994
995 proc check_mkfifo_available {} {
996     if {[istarget *-*-cygwin*]} {
997        # Cygwin has mkfifo, but support is incomplete.
998        return 0
999      }
1000
1001     return [check_function_available "mkfifo"]
1002 }
1003
1004 # Returns true iff "__cxa_atexit" is used on the target system.
1005
1006 proc check_cxa_atexit_available { } {
1007     global et_cxa_atexit
1008     global et_cxa_atexit_target_name
1009     global tool 
1010
1011     if { ![info exists et_cxa_atexit_target_name] } {
1012         set et_cxa_atexit_target_name ""
1013     }
1014
1015     # If the target has changed since we set the cached value, clear it.
1016     set current_target [current_target_name]
1017     if { $current_target != $et_cxa_atexit_target_name } {
1018         verbose "check_cxa_atexit_available: `$et_cxa_atexit_target_name'" 2
1019         set et_cxa_atexit_target_name $current_target
1020         if [info exists et_cxa_atexit] {
1021             verbose "check_cxa_atexit_available: removing cached result" 2
1022             unset et_cxa_atexit
1023         }
1024     }
1025
1026     if [info exists et_cxa_atexit] {
1027         verbose "check_cxa_atexit_available: using cached result" 2
1028     } elseif { [istarget "hppa*-*-hpux10*"] } {
1029         # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
1030         set et_cxa_atexit 0
1031     } else {
1032         set et_cxa_atexit 0
1033
1034         # Set up, compile, and execute a C++ test program that depends
1035         # on correct ordering of static object destructors. This is
1036         # indicative of the presence and use of __cxa_atexit.
1037         set src cxaatexit[pid].cc
1038         set exe cxaatexit[pid].x
1039
1040         set f [open $src "w"]
1041         puts $f "#include <stdlib.h>"
1042         puts $f "static unsigned int count;"
1043         puts $f "struct X"
1044         puts $f "{"
1045         puts $f "  X() { count = 1; }"
1046         puts $f "  ~X()"
1047         puts $f "  {"
1048         puts $f "    if (count != 3)"
1049         puts $f "      exit(1);"
1050         puts $f "    count = 4;"
1051         puts $f "  }"
1052         puts $f "};"
1053         puts $f "void f()"
1054         puts $f "{"
1055         puts $f "  static X x;"
1056         puts $f "}"
1057         puts $f "struct Y"
1058         puts $f "{"
1059         puts $f "  Y() { f(); count = 2; }"
1060         puts $f "  ~Y()"
1061         puts $f "  {"
1062         puts $f "    if (count != 2)"
1063         puts $f "      exit(1);"
1064         puts $f "    count = 3;"
1065         puts $f "  }"
1066         puts $f "};"
1067         puts $f "Y y;"
1068         puts $f "int main()"
1069         puts $f "{ return 0; }"
1070         close $f
1071
1072         set lines [${tool}_target_compile $src $exe executable ""]
1073         file delete $src
1074
1075         if [string match "" $lines] {
1076             # No error message, compilation succeeded.
1077             set result [${tool}_load "./$exe" "" ""]
1078             set status [lindex $result 0]
1079             remote_file build delete $exe
1080
1081             verbose "check_cxa_atexit_available: status is <$status>" 2
1082
1083             if { $status == "pass" } {
1084                 set et_cxa_atexit 1
1085             }
1086         } else {
1087             verbose "check_cxa_atexit_available: compilation failed" 2
1088         }
1089     }
1090     return $et_cxa_atexit
1091 }
1092
1093
1094 # Return 1 if we're generating 32-bit code using default options, 0
1095 # otherwise.
1096
1097 proc check_effective_target_ilp32 { } {
1098     return [check_no_compiler_messages ilp32 object {
1099         int dummy[sizeof (int) == 4
1100                   && sizeof (void *) == 4
1101                   && sizeof (long) == 4 ? 1 : -1];
1102     }]
1103 }
1104
1105 # Return 1 if we're generating 32-bit or larger integers using default
1106 # options, 0 otherwise.
1107
1108 proc check_effective_target_int32plus { } {
1109     return [check_no_compiler_messages int32plus object {
1110         int dummy[sizeof (int) >= 4 ? 1 : -1];
1111     }]
1112 }
1113
1114 # Return 1 if we're generating 32-bit or larger pointers using default
1115 # options, 0 otherwise.
1116
1117 proc check_effective_target_ptr32plus { } {
1118     return [check_no_compiler_messages ptr32plus object {
1119         int dummy[sizeof (void *) >= 4 ? 1 : -1];
1120     }]
1121 }
1122
1123 # Return 1 if we support 32-bit or larger array and structure sizes
1124 # using default options, 0 otherwise.
1125
1126 proc check_effective_target_size32plus { } {
1127     return [check_no_compiler_messages size32plus object {
1128         char dummy[65537];
1129     }]
1130 }
1131
1132 # Returns 1 if we're generating 16-bit or smaller integers with the
1133 # default options, 0 otherwise.
1134
1135 proc check_effective_target_int16 { } {
1136     return [check_no_compiler_messages int16 object {
1137         int dummy[sizeof (int) < 4 ? 1 : -1];
1138     }]
1139 }
1140
1141 # Return 1 if we're generating 64-bit code using default options, 0
1142 # otherwise.
1143
1144 proc check_effective_target_lp64 { } {
1145     return [check_no_compiler_messages lp64 object {
1146         int dummy[sizeof (int) == 4
1147                   && sizeof (void *) == 8
1148                   && sizeof (long) == 8 ? 1 : -1];
1149     }]
1150 }
1151
1152 # Return 1 if the target supports long double larger than double,
1153 # 0 otherwise.
1154
1155 proc check_effective_target_large_long_double { } {
1156     return [check_no_compiler_messages large_long_double object {
1157         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1158     }]
1159 }
1160
1161
1162 # Return 1 if the target supports compiling decimal floating point,
1163 # 0 otherwise.
1164
1165 proc check_effective_target_dfp_nocache { } {
1166     verbose "check_effective_target_dfp_nocache: compiling source" 2
1167     set ret [string match "" [get_compiler_messages dfp 0 object {
1168         _Decimal32 x; _Decimal64 y; _Decimal128 z;
1169     }]]
1170     verbose "check_effective_target_dfp_nocache: returning $ret" 2
1171     return $ret
1172 }
1173
1174 proc check_effective_target_dfprt_nocache { } {
1175     global tool
1176
1177     set ret 0
1178
1179     verbose "check_effective_target_dfprt_nocache: compiling source" 2
1180     # Set up, compile, and execute a test program containing decimal
1181     # float operations.
1182     set src dfprt[pid].c
1183     set exe dfprt[pid].x
1184
1185     set f [open $src "w"]
1186     puts $f "_Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;"
1187     puts $f "int main () { z = x + y; return 0; }"
1188     close $f
1189
1190     verbose "check_effective_target_dfprt_nocache: compiling testfile $src" 2
1191     set lines [${tool}_target_compile $src $exe executable ""]
1192     file delete $src
1193
1194     if [string match "" $lines] then {
1195         # No error message, compilation succeeded.
1196         set result [${tool}_load "./$exe" "" ""]
1197         set status [lindex $result 0]
1198         remote_file build delete $exe
1199         verbose "check_effective_target_dfprt_nocache: testfile status is <$status>" 2
1200         if { $status == "pass" } then {
1201             set ret 1
1202         }
1203     }
1204     return $ret
1205     verbose "check_effective_target_dfprt_nocache: returning $ret" 2
1206 }
1207
1208 # Return 1 if the target supports compiling Decimal Floating Point,
1209 # 0 otherwise.
1210 #
1211 # This won't change for different subtargets so cache the result.
1212
1213 proc check_effective_target_dfp { } {
1214     global et_dfp_saved
1215
1216     if [info exists et_dfp_saved] {
1217         verbose "check_effective_target_dfp: using cached result" 2
1218     } else {
1219         set et_dfp_saved [check_effective_target_dfp_nocache]
1220     }
1221     verbose "check_effective_target_dfp: returning $et_dfp_saved" 2
1222     return $et_dfp_saved
1223 }
1224
1225 # Return 1 if the target supports linking and executing Decimal Floating
1226 # Point, # 0 otherwise.
1227 #
1228 # This won't change for different subtargets so cache the result.
1229
1230 proc check_effective_target_dfprt { } {
1231     global et_dfprt_saved
1232     global tool
1233
1234     if [info exists et_dfprt_saved] {
1235         verbose "check_effective_target_dfprt: using cached result" 2
1236     } else {
1237         set et_dfprt_saved [check_effective_target_dfprt_nocache]
1238     }
1239     verbose "check_effective_target_dfprt: returning $et_dfprt_saved" 2
1240     return $et_dfprt_saved
1241 }
1242
1243 # Return 1 if the target needs a command line argument to enable a SIMD
1244 # instruction set.
1245
1246 proc check_effective_target_vect_cmdline_needed { } {
1247     global et_vect_cmdline_needed_saved
1248     global et_vect_cmdline_needed_target_name
1249
1250     if { ![info exists et_vect_cmdline_needed_target_name] } {
1251         set et_vect_cmdline_needed_target_name ""
1252     }
1253
1254     # If the target has changed since we set the cached value, clear it.
1255     set current_target [current_target_name]
1256     if { $current_target != $et_vect_cmdline_needed_target_name } {
1257         verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
1258         set et_vect_cmdline_needed_target_name $current_target
1259         if { [info exists et_vect_cmdline_needed_saved] } {
1260             verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
1261             unset et_vect_cmdline_needed_saved
1262         }
1263     }
1264
1265     if [info exists et_vect_cmdline_needed_saved] {
1266         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1267     } else {
1268         set et_vect_cmdline_needed_saved 1
1269         if { [istarget ia64-*-*]
1270              || (([istarget x86_64-*-*] || [istarget i?86-*-*])
1271                  && [check_effective_target_lp64])
1272              || ([istarget powerpc*-*-*]
1273                  && ([check_effective_target_powerpc_spe]
1274                      || [check_effective_target_powerpc_altivec]))} {
1275            set et_vect_cmdline_needed_saved 0
1276         }
1277     }
1278
1279     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1280     return $et_vect_cmdline_needed_saved
1281 }
1282
1283 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1284 #
1285 # This won't change for different subtargets so cache the result.
1286
1287 proc check_effective_target_vect_int { } {
1288     global et_vect_int_saved
1289
1290     if [info exists et_vect_int_saved] {
1291         verbose "check_effective_target_vect_int: using cached result" 2
1292     } else {
1293         set et_vect_int_saved 0
1294         if { [istarget i?86-*-*]
1295               || [istarget powerpc*-*-*]
1296               || [istarget spu-*-*]
1297               || [istarget x86_64-*-*]
1298               || [istarget sparc*-*-*]
1299               || [istarget alpha*-*-*]
1300               || [istarget ia64-*-*] } {
1301            set et_vect_int_saved 1
1302         }
1303     }
1304
1305     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1306     return $et_vect_int_saved
1307 }
1308
1309 # Return 1 is this is an arm target using 32-bit instructions
1310 proc check_effective_target_arm32 { } {
1311     global et_arm32_saved
1312     global et_arm32_target_name
1313     global compiler_flags
1314
1315     if { ![info exists et_arm32_target_name] } {
1316         set et_arm32_target_name ""
1317     }
1318
1319     # If the target has changed since we set the cached value, clear it.
1320     set current_target [current_target_name]
1321     if { $current_target != $et_arm32_target_name } {
1322         verbose "check_effective_target_arm32: `$et_arm32_target_name' `$current_target'" 2
1323         set et_arm32_target_name $current_target
1324         if { [info exists et_arm32_saved] } {
1325             verbose "check_effective_target_arm32: removing cached result" 2
1326             unset et_arm32_saved
1327         }
1328     }
1329
1330     if [info exists et_arm32_saved] {
1331         verbose "check-effective_target_arm32: using cached result" 2
1332     } else {
1333         set et_arm32_saved 0
1334         if { [istarget arm-*-*]
1335               || [istarget strongarm*-*-*]
1336               || [istarget xscale-*-*] } {
1337             if ![string match "*-mthumb *" $compiler_flags] {
1338                 set et_arm32_saved 1
1339             }
1340         }
1341     }
1342     verbose "check_effective_target_arm32: returning $et_arm32_saved" 2
1343     return $et_arm32_saved
1344 }
1345
1346 # Return 1 if this is an ARM target supporting -mfpu=vfp
1347 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1348 # options.
1349
1350 proc check_effective_target_arm_vfp_ok { } {
1351     if { [check_effective_target_arm32] } {
1352         return [check_no_compiler_messages arm_vfp_ok object {
1353             int dummy;
1354         } "-mfpu=vfp -mfloat-abi=softfp"]
1355     } else {
1356         return 0
1357     }
1358 }
1359
1360 # Return 1 if this is a PowerPC target with floating-point registers.
1361
1362 proc check_effective_target_powerpc_fprs { } {
1363     if { [istarget powerpc*-*-*]
1364          || [istarget rs6000-*-*] } {
1365         return [check_no_compiler_messages powerpc_fprs object {
1366             #ifdef __NO_FPRS__
1367             #error no FPRs
1368             #else
1369             int dummy;
1370             #endif
1371         }]
1372     } else {
1373         return 0
1374     }
1375 }
1376
1377 # Return 1 if this is a PowerPC target supporting -maltivec.
1378
1379 proc check_effective_target_powerpc_altivec_ok { } {
1380     if { [istarget powerpc*-*-*]
1381          || [istarget rs6000-*-*] } {
1382         # AltiVec is not supported on Aix.
1383         if { [istarget powerpc*-*-aix*] } {
1384             return 0
1385         }
1386         return [check_no_compiler_messages powerpc_altivec_ok object {
1387             int dummy;
1388         } "-maltivec"]
1389     } else {
1390         return 0
1391     }
1392 }
1393
1394 # Return 1 if this is a PowerPC target with SPE enabled.
1395
1396 proc check_effective_target_powerpc_spe { } {
1397     if { [istarget powerpc*-*-*] } {
1398         return [check_no_compiler_messages powerpc_spe object {
1399             #ifndef __SPE__
1400             #error not SPE
1401             #else
1402             int dummy;
1403             #endif
1404         }]
1405     } else {
1406         return 0
1407     }
1408 }
1409
1410 # Return 1 if this is a PowerPC target with Altivec enabled.
1411
1412 proc check_effective_target_powerpc_altivec { } {
1413     if { [istarget powerpc*-*-*] } {
1414         return [check_no_compiler_messages powerpc_altivec object {
1415             #ifndef __ALTIVEC__
1416             #error not Altivec
1417             #else
1418             int dummy;
1419             #endif
1420         }]
1421     } else {
1422         return 0
1423     }
1424 }
1425
1426 # Return 1 if the target supports hardware vector shift operation.
1427
1428 proc check_effective_target_vect_shift { } {
1429     global et_vect_shift_saved
1430
1431     if [info exists et_vect_shift_saved] {
1432         verbose "check_effective_target_vect_shift: using cached result" 2
1433     } else {
1434         set et_vect_shift_saved 0
1435         if { [istarget powerpc*-*-*]
1436              || [istarget ia64-*-*]
1437              || [istarget i?86-*-*]
1438              || [istarget x86_64-*-*] } {
1439            set et_vect_shift_saved 1
1440         }
1441     }
1442
1443     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1444     return $et_vect_shift_saved
1445 }
1446
1447 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1448 #
1449 # This can change for different subtargets so do not cache the result.
1450
1451 proc check_effective_target_vect_long { } {
1452     if { [istarget i?86-*-*]
1453          || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
1454          || [istarget x86_64-*-*]
1455          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1456         set answer 1
1457     } else {
1458         set answer 0
1459     }
1460
1461     verbose "check_effective_target_vect_long: returning $answer" 2
1462     return $answer
1463 }
1464
1465 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1466 #
1467 # This won't change for different subtargets so cache the result.
1468
1469 proc check_effective_target_vect_float { } {
1470     global et_vect_float_saved
1471
1472     if [info exists et_vect_float_saved] {
1473         verbose "check_effective_target_vect_float: using cached result" 2
1474     } else {
1475         set et_vect_float_saved 0
1476         if { [istarget i?86-*-*]
1477               || [istarget powerpc*-*-*]
1478               || [istarget spu-*-*]
1479               || [istarget mipsisa64*-*-*]
1480               || [istarget x86_64-*-*]
1481               || [istarget ia64-*-*] } {
1482            set et_vect_float_saved 1
1483         }
1484     }
1485
1486     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1487     return $et_vect_float_saved
1488 }
1489
1490 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1491 #
1492 # This won't change for different subtargets so cache the result.
1493
1494 proc check_effective_target_vect_double { } {
1495     global et_vect_double_saved
1496
1497     if [info exists et_vect_double_saved] {
1498         verbose "check_effective_target_vect_double: using cached result" 2
1499     } else {
1500         set et_vect_double_saved 0
1501         if { [istarget i?86-*-*]
1502               || [istarget x86_64-*-*] 
1503               || [istarget spu-*-*] } {
1504            set et_vect_double_saved 1
1505         }
1506     }
1507
1508     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1509     return $et_vect_double_saved
1510 }
1511
1512 # Return 0 if the target supports hardware comparison of vectors of double, 0 otherwise.
1513 #
1514 # This won't change for different subtargets so cache the result.
1515
1516 proc check_effective_target_vect_no_compare_double { } {
1517     global et_vect_no_compare_double_saved
1518
1519     if [info exists et_vect_no_compare_double_saved] {
1520         verbose "check_effective_target_vect_no_compare_double: using cached result" 2
1521     } else {
1522         set et_vect_no_compare_double_saved 0
1523         if { [istarget spu-*-*] } {
1524            set et_vect_no_compare_double_saved 1
1525         }
1526     }
1527
1528     verbose "check_effective_target_vect_no_compare_double: returning $et_vect_no_compare_double_saved" 2
1529     return $et_vect_no_compare_double_saved
1530 }
1531
1532 # Return 1 if the target plus current options does not support a vector
1533 # max instruction on "int", 0 otherwise.
1534 #
1535 # This won't change for different subtargets so cache the result.
1536
1537 proc check_effective_target_vect_no_int_max { } {
1538     global et_vect_no_int_max_saved
1539
1540     if [info exists et_vect_no_int_max_saved] {
1541         verbose "check_effective_target_vect_no_int_max: using cached result" 2
1542     } else {
1543         set et_vect_no_int_max_saved 0
1544         if { [istarget sparc*-*-*]
1545              || [istarget spu-*-*]
1546              || [istarget alpha*-*-*] } {
1547             set et_vect_no_int_max_saved 1
1548         }
1549     }
1550     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1551     return $et_vect_no_int_max_saved
1552 }
1553
1554 # Return 1 if the target plus current options does not support a vector
1555 # add instruction on "int", 0 otherwise.
1556 #
1557 # This won't change for different subtargets so cache the result.
1558
1559 proc check_effective_target_vect_no_int_add { } {
1560     global et_vect_no_int_add_saved
1561
1562     if [info exists et_vect_no_int_add_saved] {
1563         verbose "check_effective_target_vect_no_int_add: using cached result" 2
1564     } else {
1565         set et_vect_no_int_add_saved 0
1566         # Alpha only supports vector add on V8QI and V4HI.
1567         if { [istarget alpha*-*-*] } {
1568             set et_vect_no_int_add_saved 1
1569         }
1570     }
1571     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1572     return $et_vect_no_int_add_saved
1573 }
1574
1575 # Return 1 if the target plus current options does not support vector
1576 # bitwise instructions, 0 otherwise.
1577 #
1578 # This won't change for different subtargets so cache the result.
1579
1580 proc check_effective_target_vect_no_bitwise { } {
1581     global et_vect_no_bitwise_saved
1582
1583     if [info exists et_vect_no_bitwise_saved] {
1584         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1585     } else {
1586         set et_vect_no_bitwise_saved 0
1587     }
1588     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1589     return $et_vect_no_bitwise_saved
1590 }
1591
1592 # Return 1 if the target plus current options supports a vector
1593 # widening summation of *short* args into *int* result, 0 otherwise.
1594 # A target can also support this widening summation if it can support
1595 # promotion (unpacking) from shorts to ints.
1596 #
1597 # This won't change for different subtargets so cache the result.
1598                                                                                                 
1599 proc check_effective_target_vect_widen_sum_hi_to_si { } {
1600     global et_vect_widen_sum_hi_to_si
1601
1602     if [info exists et_vect_widen_sum_hi_to_si_saved] {
1603         verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
1604     } else {
1605         set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
1606         if { [istarget powerpc*-*-*] } {
1607             set et_vect_widen_sum_hi_to_si_saved 1
1608         }
1609     }
1610     verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
1611     return $et_vect_widen_sum_hi_to_si_saved
1612 }
1613
1614 # Return 1 if the target plus current options supports a vector
1615 # widening summation of *char* args into *short* result, 0 otherwise.
1616 # A target can also support this widening summation if it can support
1617 # promotion (unpacking) from chars to shorts.
1618 #
1619 # This won't change for different subtargets so cache the result.
1620                                                                                                 
1621 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
1622     global et_vect_widen_sum_qi_to_hi
1623
1624     if [info exists et_vect_widen_sum_qi_to_hi_saved] {
1625         verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
1626     } else {
1627         set et_vect_widen_sum_qi_to_hi_saved 0
1628         if { [check_effective_target_vect_unpack] } {
1629             set et_vect_widen_sum_qi_to_hi_saved 1
1630         }
1631     }
1632     verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
1633     return $et_vect_widen_sum_qi_to_hi_saved
1634 }
1635
1636 # Return 1 if the target plus current options supports a vector
1637 # widening summation of *char* args into *int* result, 0 otherwise.
1638 #
1639 # This won't change for different subtargets so cache the result.
1640                                                                                                 
1641 proc check_effective_target_vect_widen_sum_qi_to_si { } {
1642     global et_vect_widen_sum_qi_to_si
1643
1644     if [info exists et_vect_widen_sum_qi_to_si_saved] {
1645         verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
1646     } else {
1647         set et_vect_widen_sum_qi_to_si_saved 0
1648         if { [istarget powerpc*-*-*] } {
1649             set et_vect_widen_sum_qi_to_si_saved 1
1650         }
1651     }
1652     verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
1653     return $et_vect_widen_sum_qi_to_si_saved
1654 }
1655
1656 # Return 1 if the target plus current options supports a vector
1657 # widening multiplication of *char* args into *short* result, 0 otherwise.
1658 # A target can also support this widening multplication if it can support
1659 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
1660 # multiplication of shorts).
1661 #
1662 # This won't change for different subtargets so cache the result.
1663
1664
1665 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
1666     global et_vect_widen_mult_qi_to_hi
1667
1668     if [info exists et_vect_widen_mult_qi_to_hi_saved] {
1669         verbose "check_effective_target_vect_widen_mult_qi_to_hi: using cached result" 2
1670     } else {
1671         if { [check_effective_target_vect_unpack]
1672              && [check_effective_target_vect_short_mult] } {
1673             set et_vect_widen_mult_qi_to_hi_saved 1
1674         } else {
1675             set et_vect_widen_mult_qi_to_hi_saved 0
1676         }
1677         if { [istarget powerpc*-*-*] } {
1678             set et_vect_widen_mult_qi_to_hi_saved 1
1679         }
1680     }
1681     verbose "check_effective_target_vect_widen_mult_qi_to_hi: returning $et_vect_widen_mult_qi_to_hi_saved" 2
1682     return $et_vect_widen_mult_qi_to_hi_saved
1683 }
1684
1685 # Return 1 if the target plus current options supports a vector
1686 # widening multiplication of *short* args into *int* result, 0 otherwise.
1687 # A target can also support this widening multplication if it can support
1688 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
1689 # multiplication of ints).
1690 #
1691 # This won't change for different subtargets so cache the result.
1692
1693
1694 proc check_effective_target_vect_widen_mult_hi_to_si { } {
1695     global et_vect_widen_mult_hi_to_si
1696
1697     if [info exists et_vect_widen_mult_hi_to_si_saved] {
1698         verbose "check_effective_target_vect_widen_mult_hi_to_si: using cached result" 2
1699     } else {
1700         if { [check_effective_target_vect_unpack]
1701              && [check_effective_target_vect_int_mult] } {
1702           set et_vect_widen_mult_hi_to_si_saved 1
1703         } else {
1704           set et_vect_widen_mult_hi_to_si_saved 0
1705         }
1706         if { [istarget powerpc*-*-*]
1707               || [istarget spu-*-*]
1708               || [istarget i?86-*-*]
1709               || [istarget x86_64-*-*] } {
1710             set et_vect_widen_mult_hi_to_si_saved 1
1711         }
1712     }
1713     verbose "check_effective_target_vect_widen_mult_hi_to_si: returning $et_vect_widen_mult_hi_to_si_saved" 2
1714     return $et_vect_widen_mult_hi_to_si_saved
1715 }
1716
1717 # Return 1 if the target plus current options supports a vector
1718 # dot-product of signed chars, 0 otherwise.
1719 #
1720 # This won't change for different subtargets so cache the result.
1721
1722 proc check_effective_target_vect_sdot_qi { } {
1723     global et_vect_sdot_qi
1724
1725     if [info exists et_vect_sdot_qi_saved] {
1726         verbose "check_effective_target_vect_sdot_qi: using cached result" 2
1727     } else {
1728         set et_vect_sdot_qi_saved 0
1729     }
1730     verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
1731     return $et_vect_sdot_qi_saved
1732 }
1733
1734 # Return 1 if the target plus current options supports a vector
1735 # dot-product of unsigned chars, 0 otherwise.
1736 #
1737 # This won't change for different subtargets so cache the result.
1738
1739 proc check_effective_target_vect_udot_qi { } {
1740     global et_vect_udot_qi
1741
1742     if [info exists et_vect_udot_qi_saved] {
1743         verbose "check_effective_target_vect_udot_qi: using cached result" 2
1744     } else {
1745         set et_vect_udot_qi_saved 0
1746         if { [istarget powerpc*-*-*] } {
1747             set et_vect_udot_qi_saved 1
1748         }
1749     }
1750     verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
1751     return $et_vect_udot_qi_saved
1752 }
1753
1754 # Return 1 if the target plus current options supports a vector
1755 # dot-product of signed shorts, 0 otherwise.
1756 #
1757 # This won't change for different subtargets so cache the result.
1758
1759 proc check_effective_target_vect_sdot_hi { } {
1760     global et_vect_sdot_hi
1761
1762     if [info exists et_vect_sdot_hi_saved] {
1763         verbose "check_effective_target_vect_sdot_hi: using cached result" 2
1764     } else {
1765         set et_vect_sdot_hi_saved 0
1766         if { [istarget powerpc*-*-*] 
1767              || [istarget i?86-*-*]
1768              || [istarget x86_64-*-*] } {
1769             set et_vect_sdot_hi_saved 1
1770         }
1771     }
1772     verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
1773     return $et_vect_sdot_hi_saved
1774 }
1775
1776 # Return 1 if the target plus current options supports a vector
1777 # dot-product of unsigned shorts, 0 otherwise.
1778 #
1779 # This won't change for different subtargets so cache the result.
1780
1781 proc check_effective_target_vect_udot_hi { } {
1782     global et_vect_udot_hi
1783
1784     if [info exists et_vect_udot_hi_saved] {
1785         verbose "check_effective_target_vect_udot_hi: using cached result" 2
1786     } else {
1787         set et_vect_udot_hi_saved 0
1788         if { [istarget powerpc*-*-*] } {
1789             set et_vect_udot_hi_saved 1
1790         }
1791     }
1792     verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
1793     return $et_vect_udot_hi_saved
1794 }
1795
1796
1797 # Return 1 if the target plus current options supports a vector
1798 # demotion (packing) of shorts (to chars) and ints (to shorts) 
1799 # using modulo arithmetic, 0 otherwise.
1800 #
1801 # This won't change for different subtargets so cache the result.
1802                                                                                 
1803 proc check_effective_target_vect_pack_mod { } {
1804     global et_vect_pack_mod
1805                                                                                 
1806     if [info exists et_vect_pack_mod_saved] {
1807         verbose "check_effective_target_vect_pack_mod: using cached result" 2
1808     } else {
1809         set et_vect_pack_mod_saved 0
1810         if { [istarget powerpc*-*-*]
1811              || [istarget i?86-*-*]
1812              || [istarget x86_64-*-*] } {
1813             set et_vect_pack_mod_saved 1
1814         }
1815     }
1816     verbose "check_effective_target_vect_pack_mod: returning $et_vect_pack_mod_saved" 2
1817     return $et_vect_pack_mod_saved
1818 }
1819
1820 # Return 1 if the target plus current options supports a vector
1821 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
1822 #
1823 # This won't change for different subtargets so cache the result.
1824                                    
1825 proc check_effective_target_vect_unpack { } {
1826     global et_vect_unpack
1827                                         
1828     if [info exists et_vect_unpack_saved] {
1829         verbose "check_effective_target_vect_unpack: using cached result" 2
1830     } else {
1831         set et_vect_unpack_saved 0
1832         if { [istarget powerpc*-*-*]
1833              || [istarget i?86-*-*]
1834              || [istarget x86_64-*-*] } {
1835             set et_vect_unpack_saved 1
1836         }
1837     }
1838     verbose "check_effective_target_vect_unpack: returning $et_vect_unpack_saved" 2  
1839     return $et_vect_unpack_saved
1840 }
1841
1842 # Return 1 if the target plus current options does not support a vector
1843 # alignment mechanism, 0 otherwise.
1844 #
1845 # This won't change for different subtargets so cache the result.
1846
1847 proc check_effective_target_vect_no_align { } {
1848     global et_vect_no_align_saved
1849
1850     if [info exists et_vect_no_align_saved] {
1851         verbose "check_effective_target_vect_no_align: using cached result" 2
1852     } else {
1853         set et_vect_no_align_saved 0
1854         if { [istarget mipsisa64*-*-*]
1855              || [istarget sparc*-*-*]
1856              || [istarget ia64-*-*] } {
1857             set et_vect_no_align_saved 1
1858         }
1859     }
1860     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
1861     return $et_vect_no_align_saved
1862 }
1863
1864 # Return 1 if the target supports vector conditional operations, 0 otherwise.
1865
1866 proc check_effective_target_vect_condition { } {
1867     global et_vect_cond_saved
1868
1869     if [info exists et_vect_cond_saved] {
1870         verbose "check_effective_target_vect_cond: using cached result" 2
1871     } else {
1872         set et_vect_cond_saved 0
1873         if { [istarget powerpc*-*-*]
1874              || [istarget ia64-*-*]
1875              || [istarget i?86-*-*]
1876              || [istarget x86_64-*-*] } {
1877            set et_vect_cond_saved 1
1878         }
1879     }
1880
1881     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
1882     return $et_vect_cond_saved
1883 }
1884
1885 # Return 1 if the target supports vector char multiplication, 0 otherwise.
1886
1887 proc check_effective_target_vect_char_mult { } {
1888     global et_vect_char_mult_saved
1889
1890     if [info exists et_vect_char_mult_saved] {
1891         verbose "check_effective_target_vect_char_mult: using cached result" 2
1892     } else {
1893         set et_vect_char_mult_saved 0
1894         if { [istarget ia64-*-*]
1895              || [istarget i?86-*-*]
1896              || [istarget x86_64-*-*] } {
1897            set et_vect_char_mult_saved 1
1898         }
1899     }
1900
1901     verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
1902     return $et_vect_char_mult_saved
1903 }
1904
1905 # Return 1 if the target supports vector short multiplication, 0 otherwise.
1906
1907 proc check_effective_target_vect_short_mult { } {
1908     global et_vect_short_mult_saved
1909
1910     if [info exists et_vect_short_mult_saved] {
1911         verbose "check_effective_target_vect_short_mult: using cached result" 2
1912     } else {
1913         set et_vect_short_mult_saved 0
1914         if { [istarget ia64-*-*]
1915              || [istarget i?86-*-*]
1916              || [istarget x86_64-*-*] } {
1917            set et_vect_short_mult_saved 1
1918         }
1919     }
1920
1921     verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
1922     return $et_vect_short_mult_saved
1923 }
1924
1925 # Return 1 if the target supports vector int multiplication, 0 otherwise.
1926
1927 proc check_effective_target_vect_int_mult { } {
1928     global et_vect_int_mult_saved
1929
1930     if [info exists et_vect_int_mult_saved] {
1931         verbose "check_effective_target_vect_int_mult: using cached result" 2
1932     } else {
1933         set et_vect_int_mult_saved 0
1934         if { [istarget powerpc*-*-*]
1935              || [istarget i?86-*-*]
1936              || [istarget x86_64-*-*] } {
1937            set et_vect_int_mult_saved 1
1938         }
1939     }
1940
1941     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
1942     return $et_vect_int_mult_saved
1943 }
1944
1945 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
1946
1947 proc check_effective_target_vect_extract_even_odd { } {
1948     global et_vect_extract_even_odd_saved
1949     
1950     if [info exists et_vect_extract_even_odd_saved] {
1951         verbose "check_effective_target_vect_extract_even_odd: using cached result" 2
1952     } else {
1953         set et_vect_extract_even_odd_saved 0 
1954         if { [istarget powerpc*-*-*] } {
1955            set et_vect_extract_even_odd_saved 1
1956         }
1957     }
1958
1959     verbose "check_effective_target_vect_extract_even_odd: returning $et_vect_extract_even_odd_saved" 2
1960     return $et_vect_extract_even_odd_saved
1961 }
1962
1963 # Return 1 if the target supports vector interleaving, 0 otherwise.
1964
1965 proc check_effective_target_vect_interleave { } {
1966     global et_vect_interleave_saved
1967     
1968     if [info exists et_vect_interleave_saved] {
1969         verbose "check_effective_target_vect_interleave: using cached result" 2
1970     } else {
1971         set et_vect_interleave_saved 0
1972         if { [istarget powerpc*-*-*]
1973              || [istarget i?86-*-*]
1974              || [istarget x86_64-*-*] } {
1975            set et_vect_interleave_saved 1
1976         }
1977     }
1978
1979     verbose "check_effective_target_vect_interleave: returning $et_vect_interleave_saved" 2
1980     return $et_vect_interleave_saved
1981 }
1982
1983 # Return 1 if the target supports section-anchors
1984
1985 proc check_effective_target_section_anchors { } {
1986     global et_section_anchors_saved
1987
1988     if [info exists et_section_anchors_saved] {
1989         verbose "check_effective_target_section_anchors: using cached result" 2
1990     } else {
1991         set et_section_anchors_saved 0
1992         if { [istarget powerpc*-*-*] } {
1993            set et_section_anchors_saved 1
1994         }
1995     }
1996
1997     verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
1998     return $et_section_anchors_saved
1999 }
2000
2001 # Return 1 if the target supports atomic operations on "int" and "long".
2002
2003 proc check_effective_target_sync_int_long { } {
2004     global et_sync_int_long_saved
2005
2006     if [info exists et_sync_int_long_saved] {
2007         verbose "check_effective_target_sync_int_long: using cached result" 2
2008     } else {
2009         set et_sync_int_long_saved 0
2010 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2011 # load-reserved/store-conditional instructions.
2012         if { [istarget ia64-*-*]
2013              || [istarget i?86-*-*]
2014              || [istarget x86_64-*-*]
2015              || [istarget alpha*-*-*] 
2016              || [istarget s390*-*-*] 
2017              || [istarget powerpc*-*-*]
2018              || [istarget sparc64-*-*]
2019              || [istarget sparcv9-*-*] } {
2020            set et_sync_int_long_saved 1
2021         }
2022     }
2023
2024     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
2025     return $et_sync_int_long_saved
2026 }
2027
2028 # Return 1 if the target supports atomic operations on "char" and "short".
2029
2030 proc check_effective_target_sync_char_short { } {
2031     global et_sync_char_short_saved
2032
2033     if [info exists et_sync_char_short_saved] {
2034         verbose "check_effective_target_sync_char_short: using cached result" 2
2035     } else {
2036         set et_sync_char_short_saved 0
2037 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2038 # load-reserved/store-conditional instructions.
2039         if { [istarget ia64-*-*]
2040              || [istarget i?86-*-*]
2041              || [istarget x86_64-*-*]
2042              || [istarget alpha*-*-*] 
2043              || [istarget s390*-*-*] 
2044              || [istarget powerpc*-*-*]
2045              || [istarget sparc64-*-*]
2046              || [istarget sparcv9-*-*] } {
2047            set et_sync_char_short_saved 1
2048         }
2049     }
2050
2051     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
2052     return $et_sync_char_short_saved
2053 }
2054
2055 # Return 1 if the target uses a ColdFire FPU.
2056
2057 proc check_effective_target_coldfire_fpu { } {
2058     return [check_no_compiler_messages coldfire_fpu assembly {
2059         #ifndef __mcffpu__
2060         #error FOO
2061         #endif
2062     }]
2063 }
2064
2065 # Return true if this is a uClibc target.
2066
2067 proc check_effective_target_uclibc {} {
2068     return [check_no_compiler_messages uclibc object {
2069         #include <features.h>
2070         #if !defined (__UCLIBC__)
2071         #error FOO
2072         #endif
2073     }]
2074 }
2075
2076 # Return true if this is a uclibc target and if the uclibc feature
2077 # described by __$feature__ is not present.
2078
2079 proc check_missing_uclibc_feature {feature} {
2080     return [check_no_compiler_messages $feature object "
2081         #include <features.h>
2082         #if !defined (__UCLIBC) || !defined (__${feature}__)
2083         #error FOO
2084         #endif
2085     "]
2086 }
2087
2088 # Return true if this is a Newlib target.
2089
2090 proc check_effective_target_newlib {} {
2091     return [check_no_compiler_messages newlib object {
2092         #include <newlib.h>
2093     }]
2094 }
2095
2096 # Return 1 if
2097 #   (a) an error of a few ULP is expected in string to floating-point
2098 #       conversion functions; and
2099 #   (b) overflow is not always detected correctly by those functions.
2100
2101 proc check_effective_target_lax_strtofp {} {
2102     # By default, assume that all uClibc targets suffer from this.
2103     return [check_effective_target_uclibc]
2104 }
2105
2106 # Return 1 if this is a target for which wcsftime is a dummy
2107 # function that always returns 0.
2108
2109 proc check_effective_target_dummy_wcsftime {} {
2110     # By default, assume that all uClibc targets suffer from this.
2111     return [check_effective_target_uclibc]
2112 }
2113
2114 # Return 1 if constructors with initialization priority arguments are
2115 # supposed on this target.
2116
2117 proc check_effective_target_init_priority {} {
2118     return [check_no_compiler_messages init_priority assembly "
2119         void f() __attribute__((constructor (1000)));
2120         void f() \{\}
2121     "]
2122 }
2123
2124 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
2125 # This can be used with any check_* proc that takes no argument and
2126 # returns only 1 or 0.  It could be used with check_* procs that take
2127 # arguments with keywords that pass particular arguments.
2128
2129 proc is-effective-target { arg } {
2130     set selected 0
2131     if { [info procs check_effective_target_${arg}] != [list] } {
2132         set selected [check_effective_target_${arg}]
2133     } else {
2134         switch $arg {
2135           "vmx_hw"         { set selected [check_vmx_hw_available] }
2136           "named_sections" { set selected [check_named_sections_available] }
2137           "gc_sections"    { set selected [check_gc_sections_available] }
2138           "cxa_atexit"     { set selected [check_cxa_atexit_available] }
2139           default          { error "unknown effective target keyword `$arg'" }
2140         }
2141     }
2142     verbose "is-effective-target: $arg $selected" 2
2143     return $selected
2144 }
2145
2146 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
2147
2148 proc is-effective-target-keyword { arg } {
2149     if { [info procs check_effective_target_${arg}] != [list] } {
2150         return 1
2151     } else {
2152         # These have different names for their check_* procs.
2153         switch $arg {
2154           "vmx_hw"         { return 1 }
2155           "named_sections" { return 1 }
2156           "gc_sections"    { return 1 }
2157           "cxa_atexit"     { return 1 }
2158           default          { return 0 }
2159         }
2160     }
2161 }
2162
2163 # Return 1 if target default to short enums
2164
2165 proc check_effective_target_short_enums { } {
2166     return [check_no_compiler_messages short_enums assembly {
2167         enum foo { bar };
2168         int s[sizeof (enum foo) == 1 ? 1 : -1];
2169     }]
2170 }
2171
2172 # Return 1 if target supports merging string constants at link time.
2173
2174 proc check_effective_target_string_merging { } {
2175     return [check_no_messages_and_pattern string_merging \
2176                 "rodata\\.str" assembly {
2177                     const char *var = "String";
2178                 } {-O2}]
2179 }
2180
2181 # Return 1 if target has the basic signed and unsigned types in
2182 # <stdint.h>, 0 otherwise.
2183
2184 proc check_effective_target_stdint_types { } {
2185     return [check_no_compiler_messages stdint_types assembly {
2186         #include <stdint.h>
2187         int8_t a; int16_t b; int32_t c; int64_t d;
2188         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
2189     }]
2190 }
2191
2192 # Return 1 if programs are intended to be run on a simulator
2193 # (i.e. slowly) rather than hardware (i.e. fast).
2194
2195 proc check_effective_target_simulator { } {
2196
2197     # All "src/sim" simulators set this one.
2198     if [board_info target exists is_simulator] {
2199         return [board_info target is_simulator]
2200     }
2201
2202     # The "sid" simulators don't set that one, but at least they set
2203     # this one.
2204     if [board_info target exists slow_simulator] {
2205         return [board_info target slow_simulator]
2206     }
2207
2208     return 0
2209 }
2210
2211 # Return 1 if the target is a VxWorks RTP.
2212
2213 proc check_effective_target_vxworks_kernel { } {
2214     return [check_no_compiler_messages vxworks_kernel assembly {
2215         #if !defined __vxworks || defined __RTP__
2216         #error NO
2217         #endif
2218     }]
2219 }
2220
2221 # Return 1 if the target is expected to provide wide character support.
2222
2223 proc check_effective_target_wchar { } {
2224     if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
2225         return 0
2226     }
2227     return [check_no_compiler_messages wchar assembly {
2228         #include <wchar.h>
2229     }]
2230 }