OSDN Git Service

* lib/target-supports.exp
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 proc get_compiler_messages {basename type contents} {
28     global tool
29
30     set src ${basename}[pid].c
31     switch $type {
32         assembly { set output ${basename}[pid].s }
33         object { set output ${basename}[pid].o }
34     }
35     set f [open $src "w"]
36     puts $f $contents
37     close $f
38     set lines [${tool}_target_compile $src $output $type ""]
39     file delete $src
40     remote_file build delete $output
41
42     return $lines
43 }
44
45 ###############################
46 # proc check_weak_available { }
47 ###############################
48
49 # weak symbols are only supported in some configs/object formats
50 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
51
52 proc check_weak_available { } {
53     global target_triplet
54     global target_cpu
55
56     # All mips targets should support it
57
58     if { [ string first "mips" $target_cpu ] >= 0 } {
59         return 1
60     }
61
62     # All solaris2 targets should support it
63
64     if { [regexp ".*-solaris2.*" $target_triplet] } {
65         return 1
66     }
67
68     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
69
70     if { [regexp "alpha.*osf.*" $target_triplet] } {
71         return 1
72     }
73
74     # Windows targets Cygwin and MingW32 support it
75
76     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
77         return 1
78     }
79
80     # ELF and ECOFF support it. a.out does with gas/gld but may also with
81     # other linkers, so we should try it
82
83     set objformat [gcc_target_object_format]
84
85     switch $objformat {
86         elf      { return 1 }
87         ecoff    { return 1 }
88         a.out    { return 1 }
89         mach-o   { return 1 }
90         unknown  { return -1 }
91         default  { return 0 }
92     }
93 }
94
95 ###############################
96 # proc check_visibility_available { }
97 ###############################
98
99 # The visibility attribute is only support in some object formats
100 # This proc returns 1 if it is supported, 0 if not.
101
102 proc check_visibility_available { } {
103     global visibility_available_saved
104     global tool
105     global target_triplet
106
107     # On NetWare, support makes no sense.
108     if { [string match "*-*-netware*" $target_triplet] } {
109         return 0
110     }
111
112     if {![info exists visibility_available_saved] } {
113         set lines [get_compiler_messages visibility object {
114             void f() __attribute__((visibility("hidden")));
115             void f() {}
116         }]
117         if [string match "" $lines] then {
118             set visibility_available_saved 1
119         } else {
120             set visibility_available_saved 0
121         }
122     }
123     return $visibility_available_saved
124 }
125
126 ###############################
127 # proc check_alias_available { }
128 ###############################
129
130 # Determine if the target toolchain supports the alias attribute.
131
132 # Returns 2 if the target supports aliases.  Returns 1 if the target
133 # only supports weak aliased.  Returns 0 if the target does not
134 # support aliases at all.  Returns -1 if support for aliases could not
135 # be determined.
136
137 proc check_alias_available { } {
138     global alias_available_saved
139     global tool
140
141     if [info exists alias_available_saved] {
142         verbose "check_alias_available  returning saved $alias_available_saved" 2
143     } else {
144         set src alias[pid].c
145         set obj alias[pid].o
146         verbose "check_alias_available  compiling testfile $src" 2
147         set f [open $src "w"]
148         # Compile a small test program.  The definition of "g" is
149         # necessary to keep the Solaris assembler from complaining
150         # about the program.
151         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
152         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
153         close $f
154         set lines [${tool}_target_compile $src $obj object ""]
155         file delete $src
156         remote_file build delete $obj
157
158         if [string match "" $lines] then {
159             # No error messages, everything is OK.
160             set alias_available_saved 2
161         } else {
162             if [regexp "alias definitions not supported" $lines] {
163                 verbose "check_alias_available  target does not support aliases" 2
164
165                 set objformat [gcc_target_object_format]
166
167                 if { $objformat == "elf" } {
168                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
169                     set alias_available_saved -1
170                 } else {
171                     set alias_available_saved 0
172                 }
173             } else {
174                 if [regexp "only weak aliases are supported" $lines] {
175                 verbose "check_alias_available  target supports only weak aliases" 2
176                 set alias_available_saved 1
177                 } else {
178                     set alias_available_saved -1
179                 }
180             }
181         }
182
183         verbose "check_alias_available  returning $alias_available_saved" 2
184     }
185
186     return $alias_available_saved
187 }
188
189 # Returns true if --gc-sections is supported on the target.
190
191 proc check_gc_sections_available { } {
192     global gc_sections_available_saved
193     global tool
194
195     if {![info exists gc_sections_available_saved]} {
196         # Some targets don't support gc-sections despite whatever's
197         # advertised by ld's options.
198         if { [istarget alpha*-*-*]
199              || [istarget ia64-*-*] } {
200             set gc_sections_available_saved 0
201             return 0
202         }
203
204         # Check if the ld used by gcc supports --gc-sections.
205         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
206         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
207         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
208         set ld_output [remote_exec host "$gcc_ld" "--help"]
209         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
210             set gc_sections_available_saved 1
211         } else {
212             set gc_sections_available_saved 0
213         }
214     }
215     return $gc_sections_available_saved
216 }
217
218 # Return true if profiling is supported on the target.
219
220 proc check_profiling_available { test_what } {
221     global profiling_available_saved
222
223     verbose "Profiling argument is <$test_what>" 1
224
225     # These conditions depend on the argument so examine them before
226     # looking at the cache variable.
227
228     # Support for -p on solaris2 relies on mcrt1.o which comes with the
229     # vendor compiler.  We cannot reliably predict the directory where the
230     # vendor compiler (and thus mcrt1.o) is installed so we can't
231     # necessarily find mcrt1.o even if we have it.
232     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
233         return 0
234     }
235
236     # Support for -p on irix relies on libprof1.a which doesn't appear to
237     # exist on any irix6 system currently posting testsuite results.
238     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
239     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
240     if { [istarget mips*-*-irix*]
241     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
242         return 0
243     }
244
245     # Now examine the cache variable.
246     if {![info exists profiling_available_saved]} {
247         # Some targets don't have any implementation of __bb_init_func or are
248         # missing other needed machinery.
249         if { [istarget mmix-*-*]
250              || [istarget arm*-*-eabi*]
251              || [istarget arm*-*-elf]
252              || [istarget arm*-*-symbianelf*]
253              || [istarget powerpc-*-eabi*]
254              || [istarget strongarm*-*-elf]
255              || [istarget xscale*-*-elf]
256              || [istarget cris-*-*]
257              || [istarget h8300-*-*]
258              || [istarget mips*-*-elf]
259              || [istarget *-*-windiss] } {
260             set profiling_available_saved 0
261         } else {
262             set profiling_available_saved 1
263         }
264     }
265
266     return $profiling_available_saved
267 }
268
269 # Return true if iconv is supported on the target. In particular IBM-1047.
270
271 proc check_iconv_available { test_what } {
272     global tool
273     global libiconv
274
275     set result ""
276
277     set src iconv[pid].c
278     set exe iconv[pid].x
279     verbose "check_iconv_available compiling testfile $src" 2
280     set f [open $src "w"]
281     # Compile a small test program.
282     puts $f "#include <iconv.h>\n"
283     puts $f "int main (void)\n {\n iconv_t cd; \n"
284     puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
285     puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
286     puts $f "return 0;\n}"
287     close $f
288
289     set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
290     file delete $src
291
292     if [string match "" $lines] then {
293         # No error messages, everything is OK.
294
295         set result [${tool}_load "./$exe" "" ""]
296         set status [lindex $result 0];
297         remote_file build delete $exe
298
299         verbose "check_iconv_available status is <$status>" 2
300
301         if { $status == "pass" } then {
302             return 1
303         }
304     }
305
306     return 0
307 }
308
309 # Return true if named sections are supported on this target.
310 # This proc does not cache results, because the answer may vary
311 # when cycling over subtarget options (e.g. irix o32/n32/n64) in
312 # the same test run.
313 proc check_named_sections_available { } {
314     verbose "check_named_sections_available: compiling source" 2
315     set answer [string match "" [get_compiler_messages named object {
316         int __attribute__ ((section("whatever"))) foo;
317     }]]
318     verbose "check_named_sections_available: returning $answer" 2
319     return $answer
320 }
321
322 # Return 1 if the target supports executing AltiVec instructions, 0
323 # otherwise.  Cache the result.
324
325 proc check_vmx_hw_available { } {
326     global vmx_hw_available_saved
327     global tool
328
329     if [info exists vmx_hw_available_saved] {
330         verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
331     } else {
332         set vmx_hw_available_saved 0
333
334         # Some simulators are known to not support VMX instructions.
335         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
336             verbose "check_hw_available  returning 0" 2
337             return $vmx_hw_available_saved
338         }
339
340         # Set up, compile, and execute a test program containing VMX
341         # instructions.  Include the current process ID in the file
342         # names to prevent conflicts with invocations for multiple
343         # testsuites.
344         set src vmx[pid].c
345         set exe vmx[pid].x
346
347         set f [open $src "w"]
348         puts $f "int main() {"
349         puts $f "#ifdef __MACH__"
350         puts $f "  asm volatile (\"vor v0,v0,v0\");"
351         puts $f "#else"
352         puts $f "  asm volatile (\"vor 0,0,0\");"
353         puts $f "#endif"
354         puts $f "  return 0; }"
355         close $f
356
357         verbose "check_vmx_hw_available  compiling testfile $src" 2
358         set lines [${tool}_target_compile $src $exe executable ""]
359         file delete $src
360
361         if [string match "" $lines] then {
362             # No error message, compilation succeeded.
363             set result [${tool}_load "./$exe" "" ""]
364             set status [lindex $result 0]
365             remote_file build delete $exe
366             verbose "check_vmx_hw_available testfile status is <$status>" 2
367
368             if { $status == "pass" } then {
369                 set vmx_hw_available_saved 1
370             }
371         } else {
372             verbose "check_vmx_hw_availalble testfile compilation failed" 2
373         }
374     }
375
376     return $vmx_hw_available_saved
377 }
378
379 proc check_alpha_max_hw_available { } {
380     global alpha_max_hw_available_saved
381     global tool
382
383     if [info exists alpha_max_hw_available_saved] {
384         verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
385     } else {
386         set alpha_max_hw_available_saved 0
387
388         # Set up, compile, and execute a test program probing bit 8 of the
389         # architecture mask, which indicates presence of MAX instructions.
390         set src max[pid].c
391         set exe max[pid].x
392
393         set f [open $src "w"]
394         puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
395         close $f
396
397         verbose "check_alpha_max_hw_available compiling testfile $src" 2
398         set lines [${tool}_target_compile $src $exe executable ""]
399         file delete $src
400
401         if [string match "" $lines] then {
402             # No error message, compilation succeeded.
403             set result [${tool}_load "./$exe" "" ""]
404             set status [lindex $result 0]
405             remote_file build delete $exe
406             verbose "check_alpha_max_hw_available testfile status is <$status>" 2
407
408             if { $status == "pass" } then {
409                 set alpha_max_hw_available_saved 1
410             }
411         } else {
412             verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
413         }
414     }
415
416     return $alpha_max_hw_available_saved
417 }
418
419 # Return 1 if we're generating 32-bit code using default options, 0
420 # otherwise.
421
422 proc check_effective_target_ilp32 { } {
423     verbose "check_effective_target_ilp32: compiling source" 2
424     set answer [string match "" [get_compiler_messages ilp32 object {
425         int dummy[(sizeof (int) == 4 && sizeof (void *) == 4 && sizeof (long) == 4 ) ? 1 : -1];
426     }]]
427     verbose "check_effective_target_ilp32: returning $answer" 2
428     return $answer
429 }
430
431 # Return 1 if we're generating 64-bit code using default options, 0
432 # otherwise.
433
434 proc check_effective_target_lp64 { } {
435     verbose "check_effective_target_lp64: compiling source" 2
436     set answer [string match "" [get_compiler_messages lp64 object {
437         int dummy[(sizeof (int) == 4 && sizeof (void *) == 8 && sizeof (long) == 8 ) ? 1 : -1];
438     }]]
439     verbose "check_effective_target_lp64: returning $answer" 2
440     return $answer
441 }
442
443 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
444 #
445 # This won't change for different subtargets so cache the result.
446
447 proc check_effective_target_vect_int { } {
448     global et_vect_int_saved
449
450     if [info exists et_vect_int_saved] {
451         verbose "check_effective_target_vect_int: using cached result" 2
452     } else {
453         set et_vect_int_saved 0
454         if { [istarget i?86-*-*]
455               || [istarget powerpc*-*-*]
456               || [istarget x86_64-*-*]
457               || [istarget sparc*-*-*]
458               || [istarget alpha*-*-*] } {
459            set et_vect_int_saved 1
460         }
461     }
462
463     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
464     return $et_vect_int_saved
465 }
466
467 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
468 #
469 # This can change for different subtargets so do not cache the result.
470
471 proc check_effective_target_vect_long { } {
472     if { [istarget i?86-*-*]
473          || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
474          || [istarget x86_64-*-*]
475          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
476         set answer 1
477     } else {
478         set answer 0
479     }
480
481     verbose "check_effective_target_vect_long: returning $answer" 2
482     return $answer
483 }
484
485 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
486 #
487 # This won't change for different subtargets so cache the result.
488
489 proc check_effective_target_vect_float { } {
490     global et_vect_float_saved
491
492     if [info exists et_vect_float_saved] {
493         verbose "check_effective_target_vect_float: using cached result" 2
494     } else {
495         set et_vect_float_saved 0
496         if { [istarget i?86-*-*]
497               || [istarget powerpc*-*-*]
498               || [istarget mipsisa64*-*-*]
499               || [istarget x86_64-*-*] } {
500            set et_vect_float_saved 1
501         }
502     }
503
504     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
505     return $et_vect_float_saved
506 }
507
508 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
509 #
510 # This won't change for different subtargets so cache the result.
511
512 proc check_effective_target_vect_double { } {
513     global et_vect_double_saved
514
515     if [info exists et_vect_double_saved] {
516         verbose "check_effective_target_vect_double: using cached result" 2
517     } else {
518         set et_vect_double_saved 0
519         if { [istarget i?86-*-*]
520               || [istarget x86_64-*-*] } {
521            set et_vect_double_saved 1
522         }
523     }
524
525     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
526     return $et_vect_double_saved
527 }
528
529 # Return 1 if the target plus current options does not support a vector
530 # max instruction, 0 otherwise.
531 #
532 # This won't change for different subtargets so cache the result.
533
534 proc check_effective_target_vect_no_max { } {
535     global et_vect_no_max_saved
536
537     if [info exists et_vect_no_max_saved] {
538         verbose "check_effective_target_vect_no_max: using cached result" 2
539     } else {
540         set et_vect_no_max_saved 0
541         if { [istarget i?86-*-*]
542              || [istarget x86_64-*-*]
543              || [istarget sparc*-*-*]
544              || [istarget alpha*-*-*] } {
545             set et_vect_no_max_saved 1
546         }
547     }
548     verbose "check_effective_target_vect_no_max: returning $et_vect_no_max_saved" 2
549     return $et_vect_no_max_saved
550 }
551
552 # Return 1 if the target plus current options does not support vector
553 # bitwise instructions, 0 otherwise.
554 #
555 # This won't change for different subtargets so cache the result.
556
557 proc check_effective_target_vect_no_bitwise { } {
558     global et_vect_no_bitwise_saved
559
560     if [info exists et_vect_no_bitwise_saved] {
561         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
562     } else {
563         set et_vect_no_bitwise_saved 0
564         if { [istarget i?86-*-*]
565              || [istarget x86_64-*-*]
566              || [istarget alpha-*-*] } {
567             set et_vect_no_bitwise_saved 1
568         }
569     }
570     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
571     return $et_vect_no_bitwise_saved
572 }
573
574 # Return 1 if the target plus current options does not support a vector
575 # alignment mechanism, 0 otherwise.
576 #
577 # This won't change for different subtargets so cache the result.
578
579 proc check_effective_target_vect_no_align { } {
580     global et_vect_no_align_saved
581
582     if [info exists et_vect_no_align_saved] {
583         verbose "check_effective_target_vect_no_align: using cached result" 2
584     } else {
585         set et_vect_no_align_saved 0
586         if { [istarget i?86-*-*]
587              || [istarget x86_64-*-*]
588              || [istarget mipsisa64*-*-*]
589              || [istarget sparc*-*-*] } {
590             set et_vect_no_align_saved 1
591         }
592     }
593     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
594     return $et_vect_no_align_saved
595 }
596
597 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
598 # This can be used with any check_* proc that takes no argument and
599 # returns only 1 or 0.  It could be used with check_* procs that take
600 # arguments with keywords that pass particular arguments.
601
602 proc is-effective-target { arg } {
603     set selected 0
604     if { [info procs check_effective_target_${arg}] != [list] } {
605         set selected [check_effective_target_${arg}]
606     } else {
607         switch $arg {
608           "vmx_hw"         { set selected [check_vmx_hw_available] }
609           "named_sections" { set selected [check_named_sections_available] }
610           "gc_sections"    { set selected [check_gc_sections_available] }
611           default          { error "unknown effective target keyword `$arg'" }
612         }
613     }
614     verbose "is-effective-target: $arg $selected" 2
615     return $selected
616 }
617
618 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
619
620 proc is-effective-target-keyword { arg } {
621     if { [info procs check_effective_target_${arg}] != [list] } {
622         return 1
623     } else {
624         # These have different names for their check_* procs.
625         switch $arg {
626           "vmx_hw"         { return 1 }
627           "named_sections" { return 1 }
628           "gc_sections"    { return 1 }
629           default          { return 0 }
630         }
631     }
632 }