OSDN Git Service

PR target/18106
[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 ###############################
23 # proc check_weak_available { }
24 ###############################
25
26 # weak symbols are only supported in some configs/object formats
27 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
28
29 proc check_weak_available { } {
30     global target_triplet
31     global target_cpu
32
33     # All mips targets should support it
34
35     if { [ string first "mips" $target_cpu ] >= 0 } {
36         return 1
37     }
38
39     # All solaris2 targets should support it
40
41     if { [regexp ".*-solaris2.*" $target_triplet] } {
42         return 1
43     }
44
45     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
46
47     if { [regexp "alpha.*osf.*" $target_triplet] } {
48         return 1
49     }
50
51     # Windows targets Cygwin and MingW32 support it
52
53     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
54         return 1
55     }
56
57     # ELF and ECOFF support it. a.out does with gas/gld but may also with
58     # other linkers, so we should try it
59
60     set objformat [gcc_target_object_format]
61
62     switch $objformat {
63         elf      { return 1 }
64         ecoff    { return 1 }
65         a.out    { return 1 }
66         mach-o   { return 1 }
67         unknown  { return -1 }
68         default  { return 0 }
69     }
70 }
71
72 ###############################
73 # proc check_visibility_available { }
74 ###############################
75
76 # The visibility attribute is only support in some object formats
77 # This proc returns 1 if it is supported, 0 if not, -1 if unsure.
78
79 proc check_visibility_available { } {
80     global target_triplet
81     global target_cpu
82
83     # On NetWare, support makes no sense.
84     
85     if { [string match "*-*-netware*" $target_triplet] } {
86         return 0
87     }
88
89     # ELF supports it if the system has recent GNU ld and gas.
90     # As a start we return 1 for all ELF systems; we'll let people
91     # add exceptions as necessary.
92
93     set objformat [gcc_target_object_format]
94
95     switch $objformat {
96         elf      { return 1 }
97         mach-o   { return 1 }
98         unknown  { return -1 }
99         default  { return 0 }
100     }
101 }
102
103 ###############################
104 # proc check_alias_available { }
105 ###############################
106
107 # Determine if the target toolchain supports the alias attribute.
108
109 # Returns 2 if the target supports aliases.  Returns 1 if the target
110 # only supports weak aliased.  Returns 0 if the target does not
111 # support aliases at all.  Returns -1 if support for aliases could not
112 # be determined.
113
114 proc check_alias_available { } {
115     global alias_available_saved
116     global tool
117
118     if [info exists alias_available_saved] {
119         verbose "check_alias_available  returning saved $alias_available_saved" 2
120     } else {
121         set src alias[pid].c
122         set obj alias[pid].o
123         verbose "check_alias_available  compiling testfile $src" 2
124         set f [open $src "w"]
125         # Compile a small test program.  The definition of "g" is
126         # necessary to keep the Solaris assembler from complaining
127         # about the program.
128         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
129         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
130         close $f
131         set lines [${tool}_target_compile $src $obj object ""]
132         file delete $src
133         remote_file build delete $obj
134
135         if [string match "" $lines] then {
136             # No error messages, everything is OK.
137             set alias_available_saved 2
138         } else {
139             if [regexp "alias definitions not supported" $lines] {
140                 verbose "check_alias_available  target does not support aliases" 2
141
142                 set objformat [gcc_target_object_format]
143
144                 if { $objformat == "elf" } {
145                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
146                     set alias_available_saved -1
147                 } else {
148                     set alias_available_saved 0
149                 }
150             } else {
151                 if [regexp "only weak aliases are supported" $lines] {
152                 verbose "check_alias_available  target supports only weak aliases" 2
153                 set alias_available_saved 1
154                 } else {
155                     set alias_available_saved -1
156                 }
157             }
158         }
159
160         verbose "check_alias_available  returning $alias_available_saved" 2
161     }
162
163     return $alias_available_saved
164 }
165
166 # Returns true if --gc-sections is supported on the target.
167
168 proc check_gc_sections_available { } {
169     global gc_sections_available_saved
170     global tool
171
172     if {![info exists gc_sections_available_saved]} {
173         # Check if the ld used by gcc supports --gc-sections.
174         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
175         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
176         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
177         set ld_output [remote_exec host "$gcc_ld" "--help"]
178         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
179             set gc_sections_available_saved 1
180         } else {
181             set gc_sections_available_saved 0
182         }
183     }
184     return $gc_sections_available_saved
185 }
186
187 # Return true if profiling is supported on the target.
188
189 proc check_profiling_available { test_what } {
190     global profiling_available_saved
191
192     verbose "Profiling argument is <$test_what>" 1
193
194     # These conditions depend on the argument so examine them before
195     # looking at the cache variable.
196
197     # Support for -p on solaris2 relies on mcrt1.o which comes with the
198     # vendor compiler.  We cannot reliably predict the directory where the
199     # vendor compiler (and thus mcrt1.o) is installed so we can't
200     # necessarily find mcrt1.o even if we have it.
201     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
202         return 0
203     }
204
205     # Support for -p on irix relies on libprof1.a which doesn't appear to
206     # exist on any irix6 system currently posting testsuite results.
207     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
208     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
209     if { [istarget mips*-*-irix*]
210     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
211         return 0
212     }
213
214     # Now examine the cache variable.
215     if {![info exists profiling_available_saved]} {
216         # Some targets don't have any implementation of __bb_init_func or are
217         # missing other needed machinery.
218         if { [istarget mmix-*-*]
219              || [istarget arm*-*-eabi*]
220              || [istarget arm*-*-elf]
221              || [istarget arm*-*-symbianelf*]
222              || [istarget powerpc-*-eabi*]
223              || [istarget strongarm*-*-elf]
224              || [istarget xscale*-*-elf]
225              || [istarget cris-*-*]
226              || [istarget h8300-*-*]
227              || [istarget mips*-*-elf]
228              || [istarget *-*-windiss] } {
229             set profiling_available_saved 0
230         } else {
231             set profiling_available_saved 1
232         }
233     }
234
235     return $profiling_available_saved
236 }
237
238 # Return true if iconv is supported on the target. In particular IBM-1047.
239
240 proc check_iconv_available { test_what } {
241     global tool
242     global libiconv
243
244     set result ""
245
246     set src iconv[pid].c
247     set exe iconv[pid].x
248     verbose "check_iconv_available compiling testfile $src" 2
249     set f [open $src "w"]
250     # Compile a small test program.
251     puts $f "#include <iconv.h>\n"
252     puts $f "int main (void)\n {\n iconv_t cd; \n"
253     puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
254     puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
255     puts $f "return 0;\n}"
256     close $f
257
258     set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
259     file delete $src
260
261     if [string match "" $lines] then {
262         # No error messages, everything is OK.
263
264         set result [${tool}_load "./$exe" "" ""]
265         set status [lindex $result 0];
266         remote_file build delete $exe
267
268         verbose "check_iconv_available status is <$status>" 2
269
270         if { $status == "pass" } then {
271             return 1
272         }
273     }
274
275     return 0
276 }
277
278 # Return true if named sections are supported on this target.
279 # This proc does not cache results, because the answer may vary
280 # when cycling over subtarget options (e.g. irix o32/n32/n64) in
281 # the same test run.
282 proc check_named_sections_available { } {
283     global tool
284
285     set src named[pid].c
286     set obj named[pid].o
287     verbose "check_named_sections_available compiling testfile $src" 2
288     set f [open $src "w"]
289     # Compile a small test program.
290     puts $f "int __attribute__ ((section(\"whatever\"))) foo;"
291     close $f
292     set lines [${tool}_target_compile $src $obj object ""]
293     file delete $src
294     remote_file build delete $obj
295
296     # If we got no error messages, everything is OK.
297     set answer [string match "" $lines]
298     verbose "check_named_sections_available  returning $answer" 2
299     return $answer
300 }
301
302 # Return 1 if the target supports executing AltiVec instructions, 0
303 # otherwise.  Cache the result.
304
305 proc check_vmx_hw_available { } {
306     global vmx_hw_available_saved
307     global tool
308
309     if [info exists vmx_hw_available_saved] {
310         verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
311     } else {
312         set vmx_hw_available_saved 0
313
314         # Some simulators are known to not support VMX instructions.
315         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
316             verbose "check_hw_available  returning 0" 2
317             return $vmx_hw_available_saved
318         }
319
320         # Set up, compile, and execute a test program containing VMX
321         # instructions.  Include the current process ID in the file
322         # names to prevent conflicts with invocations for multiple
323         # testsuites.
324         set src vmx[pid].c
325         set exe vmx[pid].x
326
327         set f [open $src "w"]
328         puts $f "int main() {"
329         puts $f "#ifdef __MACH__"
330         puts $f "  asm volatile (\"vor v0,v0,v0\");"
331         puts $f "#else"
332         puts $f "  asm volatile (\"vor 0,0,0\");"
333         puts $f "#endif"
334         puts $f "  return 0; }"
335         close $f
336
337         verbose "check_vmx_hw_available  compiling testfile $src" 2
338         set lines [${tool}_target_compile $src $exe executable ""]
339         file delete $src
340
341         if [string match "" $lines] then {
342             # No error message, compilation succeeded.
343             set result [${tool}_load "./$exe" "" ""]
344             set status [lindex $result 0]
345             remote_file build delete $exe
346             verbose "check_vmx_hw_available testfile status is <$status>" 2
347
348             if { $status == "pass" } then {
349                 set vmx_hw_available_saved 1
350             }
351         } else {
352             verbose "check_vmx_hw_availalble testfile compilation failed" 2
353         }
354     }
355
356     return $vmx_hw_available_saved
357 }