1 # Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # gcc-patches@gcc.gnu.org
20 # This file defines procs for determining features supported by the target.
22 ###############################
23 # proc check_weak_available { }
24 ###############################
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
29 proc check_weak_available { } {
33 # All mips targets should support it
35 if { [ string first "mips" $target_cpu ] >= 0 } {
39 # All solaris2 targets should support it
41 if { [regexp ".*-solaris2.*" $target_triplet] } {
45 # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
47 if { [regexp "alpha.*osf.*" $target_triplet] } {
51 # ELF and ECOFF support it. a.out does with gas/gld but may also with
52 # other linkers, so we should try it
54 set objformat [gcc_target_object_format]
65 ###############################
66 # proc check_visibility_available { }
67 ###############################
69 # The visibility attribute is only support in some object formats
70 # This proc returns 1 if it is supported, 0 if not, -1 if unsure.
72 proc check_visibility_available { } {
76 # ELF supports it if the system has recent GNU ld and gas.
77 # As a start we return 1 for all ELF systems; we'll let people
78 # add exceptions as necessary.
80 set objformat [gcc_target_object_format]
89 ###############################
90 # proc check_alias_available { }
91 ###############################
93 # Determine if the target toolchain supports the alias attribute.
95 # Returns 2 if the target supports aliases. Returns 1 if the target
96 # only supports weak aliased. Returns 0 if the target does not
97 # support aliases at all. Returns -1 if support for aliases could not
100 proc check_alias_available { } {
101 global alias_available_saved
104 if [info exists alias_available_saved] {
105 verbose "check_alias_available returning saved $alias_available_saved" 2
109 verbose "check_alias_available compiling testfile $src" 2
110 set f [open $src "w"]
111 # Compile a small test program. The definition of "g" is
112 # necessary to keep the Solaris assembler from complaining
114 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
115 puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
117 set lines [${tool}_target_compile $src $obj object ""]
119 remote_file build delete $obj
121 if [string match "" $lines] then {
122 # No error messages, everything is OK.
123 set alias_available_saved 2
125 if [regexp "alias definitions not supported" $lines] {
126 verbose "check_alias_available target does not support aliases" 2
128 set objformat [gcc_target_object_format]
130 if { $objformat == "elf" } {
131 verbose "check_alias_available but target uses ELF format, so it ought to" 2
132 set alias_available_saved -1
134 set alias_available_saved 0
137 if [regexp "only weak aliases are supported" $lines] {
138 verbose "check_alias_available target supports only weak aliases" 2
139 set alias_available_saved 1
141 set alias_available_saved -1
146 verbose "check_alias_available returning $alias_available_saved" 2
149 return $alias_available_saved
152 # Returns true if --gc-sections is supported on the target.
154 proc check_gc_sections_available { } {
155 global gc_sections_available_saved
158 if {![info exists gc_sections_available_saved]} {
159 # Check if the ld used by gcc supports --gc-sections.
160 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=ld" "" "none" ""] 0]
161 set ld_output [remote_exec host "$gcc_ld" "--help"]
162 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
163 set gc_sections_available_saved 1
165 set gc_sections_available_saved 0
168 return $gc_sections_available_saved
171 # Return true if profiling is supported on the target.
173 proc check_profiling_available { test_what } {
174 global profiling_available_saved
176 verbose "Profiling argument is <$test_what>" 1
178 # These conditions depend on the argument so examine them before
179 # looking at the cache variable.
181 # Support for -p on solaris2 relies on mcrt1.o which comes with the
182 # vendor compiler. We cannot reliably predict the directory where the
183 # vendor compiler (and thus mcrt1.o) is installed so we can't
184 # necessarily find mcrt1.o even if we have it.
185 if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
189 # Support for -p on irix relies on libprof1.a which doesn't appear to
190 # exist on any irix6 system currently posting testsuite results.
191 # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
192 # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
193 if { [istarget mips*-*-irix*]
194 && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
198 # Now examine the cache variable.
199 if {![info exists profiling_available_saved]} {
200 # Some targets don't have any implementation of __bb_init_func or are
201 # missing other needed machinery.
202 if { [istarget mmix-*-*]
203 || [istarget arm*-*-eabi*]
204 || [istarget arm*-*-elf]
205 || [istarget arm*-*-symbianelf*]
206 || [istarget powerpc-*-eabi*]
207 || [istarget strongarm*-*-elf]
208 || [istarget xscale*-*-elf]
209 || [istarget cris-*-*]
210 || [istarget h8300-*-*]
211 || [istarget mips*-*-elf]
212 || [istarget *-*-windiss] } {
213 set profiling_available_saved 0
215 set profiling_available_saved 1
219 return $profiling_available_saved
222 # Return true if iconv is supported on the target. In particular IBM-1047.
224 proc check_iconv_available { test_what } {
232 verbose "check_iconv_available compiling testfile $src" 2
233 set f [open $src "w"]
234 # Compile a small test program.
235 puts $f "#include <iconv.h>\n"
236 puts $f "int main (void)\n {\n iconv_t cd; \n"
237 puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
238 puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
239 puts $f "return 0;\n}"
242 set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
245 if [string match "" $lines] then {
246 # No error messages, everything is OK.
248 set result [${tool}_load "./$exe" "" ""]
249 set status [lindex $result 0];
250 remote_file build delete $exe
252 verbose "check_iconv_available status is <$status>" 2
254 if { $status == "pass" } then {
262 # Return true if named sections are supported on this target.
263 # This proc does not cache results, because the answer may vary
264 # when cycling over subtarget options (e.g. irix o32/n32/n64) in
266 proc check_named_sections_available { } {
271 verbose "check_named_sections_available compiling testfile $src" 2
272 set f [open $src "w"]
273 # Compile a small test program.
274 puts $f "int __attribute__ ((section(\"whatever\"))) foo;"
276 set lines [${tool}_target_compile $src $obj object ""]
278 remote_file build delete $obj
280 # If we got no error messages, everything is OK.
281 set answer [string match "" $lines]
282 verbose "check_named_sections_available returning $answer" 2
286 # Return 1 if the target supports executing AltiVec instructions, 0
287 # otherwise. Cache the result.
289 proc check_vmx_hw_available { } {
290 global vmx_hw_available_saved
293 if [info exists vmx_hw_available_saved] {
294 verbose "check_hw_available returning saved $vmx_hw_available_saved" 2
296 set vmx_hw_available_saved 0
298 # Some simulators are known to not support VMX instructions.
299 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
300 verbose "check_hw_available returning 0" 2
301 return $vmx_hw_available_saved
304 # Set up, compile, and execute a test program containing VMX
305 # instructions. Include the current process ID in the file
306 # names to prevent conflicts with invocations for multiple
311 set f [open $src "w"]
312 puts $f "int main() {"
313 puts $f "#ifdef __MACH__"
314 puts $f " asm volatile (\"vor v0,v0,v0\");"
316 puts $f " asm volatile (\"vor 0,0,0\");"
318 puts $f " return 0; }"
321 verbose "check_vmx_hw_available compiling testfile $src" 2
322 set lines [${tool}_target_compile $src $exe executable ""]
325 if [string match "" $lines] then {
326 # No error message, compilation succeeded.
327 set result [${tool}_load "./$exe" "" ""]
328 set status [lindex $result 0]
329 remote_file build delete $exe
330 verbose "check_vmx_hw_available testfile status is <$status>" 2
332 if { $status == "pass" } then {
333 set vmx_hw_available_saved 1
336 verbose "check_vmx_hw_availalble testfile compilation failed" 2
340 return $vmx_hw_available_saved