OSDN Git Service

* lib/gcc-dg.exp (dg-process-target): Wrapper for dg function to
[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         # Check if the ld used by gcc supports --gc-sections.
197         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
198         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
199         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
200         set ld_output [remote_exec host "$gcc_ld" "--help"]
201         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
202             set gc_sections_available_saved 1
203         } else {
204             set gc_sections_available_saved 0
205         }
206     }
207     return $gc_sections_available_saved
208 }
209
210 # Return true if profiling is supported on the target.
211
212 proc check_profiling_available { test_what } {
213     global profiling_available_saved
214
215     verbose "Profiling argument is <$test_what>" 1
216
217     # These conditions depend on the argument so examine them before
218     # looking at the cache variable.
219
220     # Support for -p on solaris2 relies on mcrt1.o which comes with the
221     # vendor compiler.  We cannot reliably predict the directory where the
222     # vendor compiler (and thus mcrt1.o) is installed so we can't
223     # necessarily find mcrt1.o even if we have it.
224     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
225         return 0
226     }
227
228     # Support for -p on irix relies on libprof1.a which doesn't appear to
229     # exist on any irix6 system currently posting testsuite results.
230     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
231     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
232     if { [istarget mips*-*-irix*]
233     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
234         return 0
235     }
236
237     # Now examine the cache variable.
238     if {![info exists profiling_available_saved]} {
239         # Some targets don't have any implementation of __bb_init_func or are
240         # missing other needed machinery.
241         if { [istarget mmix-*-*]
242              || [istarget arm*-*-eabi*]
243              || [istarget arm*-*-elf]
244              || [istarget arm*-*-symbianelf*]
245              || [istarget powerpc-*-eabi*]
246              || [istarget strongarm*-*-elf]
247              || [istarget xscale*-*-elf]
248              || [istarget cris-*-*]
249              || [istarget h8300-*-*]
250              || [istarget mips*-*-elf]
251              || [istarget *-*-windiss] } {
252             set profiling_available_saved 0
253         } else {
254             set profiling_available_saved 1
255         }
256     }
257
258     return $profiling_available_saved
259 }
260
261 # Return true if iconv is supported on the target. In particular IBM-1047.
262
263 proc check_iconv_available { test_what } {
264     global tool
265     global libiconv
266
267     set result ""
268
269     set src iconv[pid].c
270     set exe iconv[pid].x
271     verbose "check_iconv_available compiling testfile $src" 2
272     set f [open $src "w"]
273     # Compile a small test program.
274     puts $f "#include <iconv.h>\n"
275     puts $f "int main (void)\n {\n iconv_t cd; \n"
276     puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
277     puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
278     puts $f "return 0;\n}"
279     close $f
280
281     set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
282     file delete $src
283
284     if [string match "" $lines] then {
285         # No error messages, everything is OK.
286
287         set result [${tool}_load "./$exe" "" ""]
288         set status [lindex $result 0];
289         remote_file build delete $exe
290
291         verbose "check_iconv_available status is <$status>" 2
292
293         if { $status == "pass" } then {
294             return 1
295         }
296     }
297
298     return 0
299 }
300
301 # Return true if named sections are supported on this target.
302 # This proc does not cache results, because the answer may vary
303 # when cycling over subtarget options (e.g. irix o32/n32/n64) in
304 # the same test run.
305 proc check_named_sections_available { } {
306     verbose "check_named_sections_available: compiling source" 2
307     set answer [string match "" [get_compiler_messages named object {
308         int __attribute__ ((section("whatever"))) foo;
309     }]]
310     verbose "check_named_sections_available: returning $answer" 2
311     return $answer
312 }
313
314 # Return 1 if the target supports executing AltiVec instructions, 0
315 # otherwise.  Cache the result.
316
317 proc check_vmx_hw_available { } {
318     global vmx_hw_available_saved
319     global tool
320
321     if [info exists vmx_hw_available_saved] {
322         verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
323     } else {
324         set vmx_hw_available_saved 0
325
326         # Some simulators are known to not support VMX instructions.
327         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
328             verbose "check_hw_available  returning 0" 2
329             return $vmx_hw_available_saved
330         }
331
332         # Set up, compile, and execute a test program containing VMX
333         # instructions.  Include the current process ID in the file
334         # names to prevent conflicts with invocations for multiple
335         # testsuites.
336         set src vmx[pid].c
337         set exe vmx[pid].x
338
339         set f [open $src "w"]
340         puts $f "int main() {"
341         puts $f "#ifdef __MACH__"
342         puts $f "  asm volatile (\"vor v0,v0,v0\");"
343         puts $f "#else"
344         puts $f "  asm volatile (\"vor 0,0,0\");"
345         puts $f "#endif"
346         puts $f "  return 0; }"
347         close $f
348
349         verbose "check_vmx_hw_available  compiling testfile $src" 2
350         set lines [${tool}_target_compile $src $exe executable ""]
351         file delete $src
352
353         if [string match "" $lines] then {
354             # No error message, compilation succeeded.
355             set result [${tool}_load "./$exe" "" ""]
356             set status [lindex $result 0]
357             remote_file build delete $exe
358             verbose "check_vmx_hw_available testfile status is <$status>" 2
359
360             if { $status == "pass" } then {
361                 set vmx_hw_available_saved 1
362             }
363         } else {
364             verbose "check_vmx_hw_availalble testfile compilation failed" 2
365         }
366     }
367
368     return $vmx_hw_available_saved
369 }
370
371 proc check_alpha_max_hw_available { } {
372     global alpha_max_hw_available_saved
373     global tool
374
375     if [info exists alpha_max_hw_available_saved] {
376         verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
377     } else {
378         set alpha_max_hw_available_saved 0
379
380         # Set up, compile, and execute a test program probing bit 8 of the
381         # architecture mask, which indicates presence of MAX instructions.
382         set src max[pid].c
383         set exe max[pid].x
384
385         set f [open $src "w"]
386         puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
387         close $f
388
389         verbose "check_alpha_max_hw_available compiling testfile $src" 2
390         set lines [${tool}_target_compile $src $exe executable ""]
391         file delete $src
392
393         if [string match "" $lines] then {
394             # No error message, compilation succeeded.
395             set result [${tool}_load "./$exe" "" ""]
396             set status [lindex $result 0]
397             remote_file build delete $exe
398             verbose "check_alpha_max_hw_available testfile status is <$status>" 2
399
400             if { $status == "pass" } then {
401                 set alpha_max_hw_available_saved 1
402             }
403         } else {
404             verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
405         }
406     }
407
408     return $alpha_max_hw_available_saved
409 }
410
411 # Return 1 if we're generating 32-bit code using default options, 0
412 # otherwise.
413
414 proc check_effective_target_ilp32 { } {
415     verbose "check_effective_target_ilp32: compiling source" 2
416     set answer [string match "" [get_compiler_messages ilp32 object {
417         int dummy[(sizeof (int) == 4 && sizeof (void *) == 4 && sizeof (long) == 4 ) ? 1 : -1];
418     }]]
419     verbose "check_effective_target_ilp32: returning $answer" 2
420     return $answer
421 }
422
423 # Return 1 if we're generating 64-bit code using default options, 0
424 # otherwise.
425
426 proc check_effective_target_lp64 { } {
427     verbose "check_effective_target_lp64: compiling source" 2
428     set answer [string match "" [get_compiler_messages lp64 object {
429         int dummy[(sizeof (int) == 4 && sizeof (void *) == 8 && sizeof (long) == 8 ) ? 1 : -1];
430     }]]
431     verbose "check_effective_target_lp64: returning $answer" 2
432     return $answer
433 }
434
435 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
436 #
437 # This won't change for different subtargets so cache the result.
438
439 proc check_effective_target_vect_int { } {
440     global et_vect_int_saved
441
442     if [info exists et_vect_int_saved] {
443         verbose "check_effective_target_vect_int: using cached result" 2
444     } else {
445         set et_vect_int_saved 0
446         if { [istarget i?86-*-*]
447               || [istarget powerpc*-*-*]
448               || [istarget x86_64-*-*]
449               || [istarget sparc*-*-*]
450               || [istarget alpha*-*-*] } {
451            set et_vect_int_saved 1
452         }
453     }
454
455     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
456     return $et_vect_int_saved
457 }
458
459 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
460 #
461 # This can change for different subtargets so do not cache the result.
462
463 proc check_effective_target_vect_long { } {
464     if { [istarget i?86-*-*]
465          || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
466          || [istarget x86_64-*-*]
467          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
468         set answer 1
469     } else {
470         set answer 0
471     }
472
473     verbose "check_effective_target_vect_long: returning $answer" 2
474     return $answer
475 }
476
477 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
478 #
479 # This won't change for different subtargets so cache the result.
480
481 proc check_effective_target_vect_float { } {
482     global et_vect_float_saved
483
484     if [info exists et_vect_float_saved] {
485         verbose "check_effective_target_vect_float: using cached result" 2
486     } else {
487         set et_vect_float_saved 0
488         if { [istarget i?86-*-*]
489               || [istarget powerpc*-*-*]
490               || [istarget mipsisa64*-*-*]
491               || [istarget x86_64-*-*] } {
492            set et_vect_float_saved 1
493         }
494     }
495
496     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
497     return $et_vect_float_saved
498 }
499
500 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
501 #
502 # This won't change for different subtargets so cache the result.
503
504 proc check_effective_target_vect_double { } {
505     global et_vect_double_saved
506
507     if [info exists et_vect_double_saved] {
508         verbose "check_effective_target_vect_double: using cached result" 2
509     } else {
510         set et_vect_double_saved 0
511         if { [istarget i?86-*-*]
512               || [istarget x86_64-*-*] } {
513            set et_vect_double_saved 1
514         }
515     }
516
517     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
518     return $et_vect_double_saved
519 }
520
521 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
522 # This can be used with any check_* proc that takes no argument and
523 # returns only 1 or 0.  It could be used with check_* procs that take
524 # arguments with keywords that pass particular arguments.
525
526 proc is-effective-target { arg } {
527     set selected 0
528     if { [info procs check_effective_target_${arg}] != [list] } {
529         set selected [check_effective_target_${arg}]
530     } else {
531         switch $arg {
532           "vmx_hw"         { set selected [check_vmx_hw_available] }
533           "named_sections" { set selected [check_named_sections_available] }
534           "gc_sections"    { set selected [check_gc_sections_available] }
535           default          { error "unknown effective target keyword `$arg'" }
536         }
537     }
538     verbose "is-effective-target: $arg $selected" 2
539     return $selected
540 }
541
542 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
543
544 proc is-effective-target-keyword { arg } {
545     if { [info procs check_effective_target_${arg}] != [list] } {
546         return 1
547     } else {
548         # These have different names for their check_* procs.
549         switch $arg {
550           "vmx_hw"         { return 1 }
551           "named_sections" { return 1 }
552           "gc_sections"    { return 1 }
553           default          { return 0 }
554         }
555     }
556 }