OSDN Git Service

* lib/file-format.exp (gcc_target_object_format): Use
[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         unknown  { return -1 }
61         default  { return 0 }
62     }
63 }
64
65 ###############################
66 # proc check_visibility_available { }
67 ###############################
68
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.
71
72 proc check_visibility_available { } {
73     global target_triplet
74     global target_cpu
75
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.
79
80     set objformat [gcc_target_object_format]
81
82     switch $objformat {
83         elf      { return 1 }
84         unknown  { return -1 }
85         default  { return 0 }
86     }
87 }
88
89 ###############################
90 # proc check_alias_available { }
91 ###############################
92
93 # Determine if the target toolchain supports the alias attribute.
94
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
98 # be determined.
99
100 proc check_alias_available { } {
101     global alias_available_saved
102     global tool
103
104     if [info exists alias_available_saved] {
105         verbose "check_alias_available  returning saved $alias_available_saved" 2
106     } else {
107         verbose "check_alias_available  compiling testfile" 2
108         set f [open "tmp.c" "w"]
109         # Compile a small test program.  The definition of "g" is
110         # necessary to keep the Solaris assembler from complaining
111         # about the program.
112         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
113         close $f
114         set lines [${tool}_target_compile "tmp.c" "tmp.o" object ""]
115         file delete "tmp.c"
116
117         if [string match "" $lines] then {
118             # No error messages, everything is OK.
119             set alias_available_saved 2
120         } else {
121             if [regexp "alias definitions not supported" $lines] {
122                 verbose "check_alias_available  target does not support aliases" 2
123
124                 set objformat [gcc_target_object_format]
125
126                 if { $objformat == "elf" } {
127                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
128                     set alias_available_saved -1
129                 } else {
130                     set alias_available_saved 0
131                 }
132             } else {
133                 if [regexp "only weak aliases are supported" $lines] {
134                 verbose "check_alias_available  target supports only weak aliases" 2
135                 set alias_available_saved 1
136                 } else {
137                     set alias_available_saved -1
138                 }
139             }
140         }
141         
142         verbose "check_alias_available  returning $alias_available_saved" 2
143     }
144
145     return $alias_available_saved
146 }
147
148 # Returns true if --gc-sections is supported on the target.
149
150 proc check_gc_sections_available { } {
151     global gc_sections_available_saved
152     global tool
153
154     if {![info exists gc_sections_available_saved]} {
155         # Check if the ld used by gcc supports --gc-sections.
156         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=ld" "" "none" ""] 0]
157         set ld_output [remote_exec host "$gcc_ld" "--help"]
158         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
159             set gc_sections_available_saved 1
160         } else {
161             set gc_sections_available_saved 0
162         }
163     }
164     return $gc_sections_available_saved
165 }
166
167 # Return true if profiling is supported on the target.
168
169 proc check_profiling_available { } {
170     global profiling_available_saved
171
172     if {![info exists profiling_available_saved]} {
173         # Some targets don't have any implementation of __bb_init_func or are
174         # missing other needed machinery.
175         if { [istarget mmix-*-*]
176              || [istarget arm*-*-elf]
177              || [istarget strongarm*-*-elf]
178              || [istarget xscale*-*-elf]
179              || [istarget cris-*-*]
180              || [istarget h8300-*-*] 
181              || [istarget *-*-windiss] } {
182             set profiling_available_saved 0
183         } else {
184             set profiling_available_saved 1
185         }
186     }
187     
188     return $profiling_available_saved
189 }