OSDN Git Service

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