86afbbefe52fbb8335040931eabeaf5f9ce12dfc
[gcc.git] / gcc / config / sparc / sol2.h
1 /* Definitions of target machine for GCC, for SPARC running Solaris 2
2 Copyright 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005,
3 2006, 2007, 2008, 2010, 2011 Free Software Foundation, Inc.
4 Contributed by Ron Guilmette (rfg@netcom.com).
5 Additional changes by David V. Henkel-Wallace (gumby@cygnus.com).
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
22
23 /* Solaris allows 64-bit out and global registers to be used in 32-bit mode.
24 sparc_override_options will disable V8+ if either not generating V9 code
25 or generating 64-bit code. */
26 #undef TARGET_DEFAULT
27 #ifdef TARGET_64BIT_DEFAULT
28 #define TARGET_DEFAULT \
29 (MASK_V9 + MASK_64BIT + MASK_PTR64 + MASK_STACK_BIAS + \
30 MASK_V8PLUS + MASK_APP_REGS + MASK_FPU + MASK_LONG_DOUBLE_128)
31 #else
32 #define TARGET_DEFAULT \
33 (MASK_V8PLUS + MASK_APP_REGS + MASK_FPU + MASK_LONG_DOUBLE_128)
34 #endif
35
36 /* The default code model used to be CM_MEDANY on Solaris
37 but even Sun eventually found it to be quite wasteful
38 and changed it to CM_MEDMID in the Studio 9 compiler. */
39 #undef SPARC_DEFAULT_CMODEL
40 #define SPARC_DEFAULT_CMODEL CM_MEDMID
41
42 /* Select a format to encode pointers in exception handling data. CODE
43 is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is
44 true if the symbol may be affected by dynamic relocations.
45
46 Some Solaris dynamic linkers don't handle unaligned section relative
47 relocs properly, so force them to be aligned. */
48 #ifndef HAVE_AS_SPARC_UA_PCREL
49 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \
50 ((flag_pic || GLOBAL) ? DW_EH_PE_aligned : DW_EH_PE_absptr)
51 #endif
52
53 \f
54
55 /* Supposedly the same as vanilla sparc svr4, except for the stuff below: */
56
57 /* This is here rather than in sparc.h because it's not known what
58 other assemblers will accept. */
59
60 #ifndef USE_GAS
61 #define AS_SPARC64_FLAG "-xarch=v9"
62 #else
63 #define AS_SPARC64_FLAG "-TSO -64 -Av9"
64 #endif
65
66 #undef ASM_CPU32_DEFAULT_SPEC
67 #define ASM_CPU32_DEFAULT_SPEC ""
68 #undef ASM_CPU64_DEFAULT_SPEC
69 #define ASM_CPU64_DEFAULT_SPEC AS_SPARC64_FLAG
70
71 #if TARGET_CPU_DEFAULT == TARGET_CPU_v9
72 #undef CPP_CPU64_DEFAULT_SPEC
73 #define CPP_CPU64_DEFAULT_SPEC ""
74 #undef ASM_CPU32_DEFAULT_SPEC
75 #define ASM_CPU32_DEFAULT_SPEC "-xarch=v8plus"
76 #undef ASM_CPU_DEFAULT_SPEC
77 #define ASM_CPU_DEFAULT_SPEC ASM_CPU32_DEFAULT_SPEC
78 #endif
79
80 #if TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc
81 #undef CPP_CPU64_DEFAULT_SPEC
82 #define CPP_CPU64_DEFAULT_SPEC ""
83 #undef ASM_CPU32_DEFAULT_SPEC
84 #define ASM_CPU32_DEFAULT_SPEC "-xarch=v8plusa"
85 #undef ASM_CPU64_DEFAULT_SPEC
86 #define ASM_CPU64_DEFAULT_SPEC AS_SPARC64_FLAG "a"
87 #undef ASM_CPU_DEFAULT_SPEC
88 #define ASM_CPU_DEFAULT_SPEC ASM_CPU32_DEFAULT_SPEC
89 #endif
90
91 #if TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc3
92 #undef CPP_CPU64_DEFAULT_SPEC
93 #define CPP_CPU64_DEFAULT_SPEC ""
94 #undef ASM_CPU32_DEFAULT_SPEC
95 #define ASM_CPU32_DEFAULT_SPEC "-xarch=v8plusb"
96 #undef ASM_CPU64_DEFAULT_SPEC
97 #define ASM_CPU64_DEFAULT_SPEC AS_SPARC64_FLAG "b"
98 #undef ASM_CPU_DEFAULT_SPEC
99 #define ASM_CPU_DEFAULT_SPEC ASM_CPU32_DEFAULT_SPEC
100 #endif
101
102 #if TARGET_CPU_DEFAULT == TARGET_CPU_niagara
103 #undef CPP_CPU64_DEFAULT_SPEC
104 #define CPP_CPU64_DEFAULT_SPEC ""
105 #undef ASM_CPU32_DEFAULT_SPEC
106 #define ASM_CPU32_DEFAULT_SPEC "-xarch=v8plusb"
107 #undef ASM_CPU64_DEFAULT_SPEC
108 #define ASM_CPU64_DEFAULT_SPEC AS_SPARC64_FLAG "b"
109 #undef ASM_CPU_DEFAULT_SPEC
110 #define ASM_CPU_DEFAULT_SPEC ASM_CPU32_DEFAULT_SPEC
111 #endif
112
113 #if TARGET_CPU_DEFAULT == TARGET_CPU_niagara2
114 #undef CPP_CPU64_DEFAULT_SPEC
115 #define CPP_CPU64_DEFAULT_SPEC ""
116 #undef ASM_CPU32_DEFAULT_SPEC
117 #define ASM_CPU32_DEFAULT_SPEC "-xarch=v8plusb"
118 #undef ASM_CPU64_DEFAULT_SPEC
119 #define ASM_CPU64_DEFAULT_SPEC AS_SPARC64_FLAG "b"
120 #undef ASM_CPU_DEFAULT_SPEC
121 #define ASM_CPU_DEFAULT_SPEC ASM_CPU32_DEFAULT_SPEC
122 #endif
123
124 /* Both Sun as and GNU as understand -K PIC. */
125 #undef ASM_SPEC
126 #define ASM_SPEC ASM_SPEC_BASE ASM_PIC_SPEC
127
128 #undef CPP_CPU_SPEC
129 #define CPP_CPU_SPEC "\
130 %{mcpu=sparclet|mcpu=tsc701:-D__sparclet__} \
131 %{mcpu=sparclite|mcpu-f930|mcpu=f934:-D__sparclite__} \
132 %{mcpu=v8:" DEF_ARCH32_SPEC("-D__sparcv8") "} \
133 %{mcpu=supersparc:-D__supersparc__ " DEF_ARCH32_SPEC("-D__sparcv8") "} \
134 %{mcpu=v9|mcpu=ultrasparc|mcpu=ultrasparc3|mcpu=niagara|mcpu=niagara2:" DEF_ARCH32_SPEC("-D__sparcv8") "} \
135 %{!mcpu*:%(cpp_cpu_default)} \
136 "
137
138 #undef CPP_CPU_DEFAULT_SPEC
139 #define CPP_CPU_DEFAULT_SPEC \
140 (DEFAULT_ARCH32_P ? "\
141 %{m64:" CPP_CPU64_DEFAULT_SPEC "} \
142 %{!m64:" CPP_CPU32_DEFAULT_SPEC "} \
143 " : "\
144 %{m32:" CPP_CPU32_DEFAULT_SPEC "} \
145 %{!m32:" CPP_CPU64_DEFAULT_SPEC "} \
146 ")
147
148 #undef CPP_ARCH32_SPEC
149 #define CPP_ARCH32_SPEC ""
150 #undef CPP_ARCH64_SPEC
151 #define CPP_ARCH64_SPEC "-D__arch64__ -D__sparcv9"
152
153 #undef CPP_ARCH_SPEC
154 #define CPP_ARCH_SPEC "\
155 %{m32:%(cpp_arch32)} \
156 %{m64:%(cpp_arch64)} \
157 %{!m32:%{!m64:%(cpp_arch_default)}} \
158 "
159
160 /* -mcpu=native handling only makes sense with compiler running on
161 a SPARC chip. */
162 #if defined(__sparc__)
163 extern const char *host_detect_local_cpu (int argc, const char **argv);
164 # define EXTRA_SPEC_FUNCTIONS \
165 { "local_cpu_detect", host_detect_local_cpu },
166
167 # define MCPU_MTUNE_NATIVE_SPECS \
168 " %{mcpu=native:%<mcpu=native %:local_cpu_detect(cpu)}" \
169 " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
170 #else
171 # define MCPU_MTUNE_NATIVE_SPECS ""
172 #endif
173
174 #define DRIVER_SELF_SPECS MCPU_MTUNE_NATIVE_SPECS
175
176 #undef CC1_SPEC
177 #if DEFAULT_ARCH32_P
178 #define CC1_SPEC "\
179 %{m64:%{m32:%emay not use both -m32 and -m64}} \
180 %{m64:-mptr64 -mstack-bias -mno-v8plus \
181 %{!mcpu*:-%{!mv8plus:mcpu=v9}}} \
182 "
183 #else
184 #define CC1_SPEC "\
185 %{m32:%{m64:%emay not use both -m32 and -m64}} \
186 %{m32:-mptr32 -mno-stack-bias \
187 %{!mcpu*:%{!mv8plus:-mcpu=v9}}} \
188 %{mv8plus:-m32 -mptr32 -mno-stack-bias \
189 %{!mcpu*:-mcpu=v9}} \
190 "
191 #endif
192
193 /* Support for a compile-time default CPU, et cetera. The rules are:
194 --with-cpu is ignored if -mcpu is specified.
195 --with-tune is ignored if -mtune is specified.
196 --with-float is ignored if -mhard-float, -msoft-float, -mfpu, or -mno-fpu
197 are specified.
198 In the SPARC_BI_ARCH compiler we cannot pass %{!mcpu=*:-mcpu=%(VALUE)}
199 here, otherwise say -mcpu=v7 would be passed even when -m64.
200 CC1_SPEC above takes care of this instead. */
201 #undef OPTION_DEFAULT_SPECS
202 #if DEFAULT_ARCH32_P
203 #define OPTION_DEFAULT_SPECS \
204 {"cpu", "%{!m64:%{!mcpu=*:-mcpu=%(VALUE)}}" }, \
205 {"tune", "%{!mtune=*:-mtune=%(VALUE)}" }, \
206 {"float", "%{!msoft-float:%{!mhard-float:%{!mfpu:%{!mno-fpu:-m%(VALUE)-float}}}}" }
207 #else
208 #define OPTION_DEFAULT_SPECS \
209 {"cpu", "%{!m32:%{!mcpu=*:-mcpu=%(VALUE)}}" }, \
210 {"tune", "%{!mtune=*:-mtune=%(VALUE)}" }, \
211 {"float", "%{!msoft-float:%{!mhard-float:%{!mfpu:%{!mno-fpu:-m%(VALUE)-float}}}}" }
212 #endif
213
214 #undef ASM_CPU_SPEC
215 #define ASM_CPU_SPEC "\
216 %{mcpu=v9:" DEF_ARCH32_SPEC("-xarch=v8plus") DEF_ARCH64_SPEC(AS_SPARC64_FLAG) "} \
217 %{mcpu=ultrasparc:" DEF_ARCH32_SPEC("-xarch=v8plusa") DEF_ARCH64_SPEC(AS_SPARC64_FLAG "a") "} \
218 %{mcpu=ultrasparc3:" DEF_ARCH32_SPEC("-xarch=v8plusb") DEF_ARCH64_SPEC(AS_SPARC64_FLAG "b") "} \
219 %{mcpu=niagara:" DEF_ARCH32_SPEC("-xarch=v8plusb") DEF_ARCH64_SPEC(AS_SPARC64_FLAG "b") "} \
220 %{mcpu=niagara2:" DEF_ARCH32_SPEC("-xarch=v8plusb") DEF_ARCH64_SPEC(AS_SPARC64_FLAG "b") "} \
221 %{!mcpu=niagara2:%{!mcpu=niagara:%{!mcpu=ultrasparc3:%{!mcpu=ultrasparc:%{!mcpu=v9:%{mcpu*:" DEF_ARCH32_SPEC("-xarch=v8") DEF_ARCH64_SPEC(AS_SPARC64_FLAG) "}}}}}} \
222 %{!mcpu*:%(asm_cpu_default)} \
223 "
224
225 #undef ASM_ARCH32_SPEC
226 #define ASM_ARCH32_SPEC ""
227
228 #undef ASM_ARCH64_SPEC
229 #define ASM_ARCH64_SPEC ""
230
231 #undef ASM_ARCH_DEFAULT_SPEC
232 #define ASM_ARCH_DEFAULT_SPEC ""
233
234 #undef ASM_ARCH_SPEC
235 #define ASM_ARCH_SPEC ""
236
237 #ifdef USE_GLD
238 /* Since binutils 2.21, GNU ld supports new *_sol2 emulations to strictly
239 follow the Solaris 2 ABI. Prefer them if present. */
240 #ifdef HAVE_LD_SOL2_EMULATION
241 #define ARCH32_EMULATION "elf32_sparc_sol2"
242 #define ARCH64_EMULATION "elf64_sparc_sol2"
243 #else
244 #define ARCH32_EMULATION "elf32_sparc"
245 #define ARCH64_EMULATION "elf64_sparc"
246 #endif
247 #endif
248
249 #define ARCH64_SUBDIR "sparcv9"
250
251 #define SUBTARGET_CPU_EXTRA_SPECS
252
253 \f
254
255 /* Register the Solaris-specific #pragma directives. */
256 #define REGISTER_TARGET_PRAGMAS() solaris_register_pragmas ()
257
258 #if defined(USE_GAS) && defined(HAVE_AS_TLS)
259 /* Use GNU extensions to TLS support. */
260 #undef TARGET_SUN_TLS
261 #undef TARGET_GNU_TLS
262 #define TARGET_SUN_TLS 0
263 #define TARGET_GNU_TLS 1
264 #endif
265
266 #undef LOCAL_LABEL_PREFIX
267 #define LOCAL_LABEL_PREFIX "."
268
269 /* The Solaris 2 assembler uses .skip, not .zero, so put this back. */
270 #undef ASM_OUTPUT_SKIP
271 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
272 fprintf (FILE, "\t.skip %u\n", (int)(SIZE))
273
274 /* This is how to store into the string LABEL
275 the symbol_ref name of an internal numbered label where
276 PREFIX is the class of label and NUM is the number within the class.
277 This is suitable for output with `assemble_name'. */
278
279 #undef ASM_GENERATE_INTERNAL_LABEL
280 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
281 sprintf ((LABEL), "*.L%s%lu", (PREFIX), (unsigned long)(NUM))
282
283 /* The native TLS-enabled assembler requires the directive #tls_object
284 to be put on objects in TLS sections (as of v7.1). This is not
285 required by GNU as but supported on SPARC. */
286 #undef ASM_DECLARE_OBJECT_NAME
287 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
288 do \
289 { \
290 HOST_WIDE_INT size; \
291 \
292 if (targetm.have_tls && DECL_THREAD_LOCAL_P (DECL)) \
293 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "tls_object"); \
294 else \
295 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
296 \
297 size_directive_output = 0; \
298 if (!flag_inhibit_size_directive \
299 && (DECL) && DECL_SIZE (DECL)) \
300 { \
301 size_directive_output = 1; \
302 size = int_size_in_bytes (TREE_TYPE (DECL)); \
303 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size); \
304 } \
305 \
306 ASM_OUTPUT_LABEL (FILE, NAME); \
307 } \
308 while (0)
309
310 /* Output a simple call for .init/.fini. */
311 #define ASM_OUTPUT_CALL(FILE, FN) \
312 do \
313 { \
314 fprintf (FILE, "\tcall\t"); \
315 targetm.asm_out.print_operand (FILE, XEXP (DECL_RTL (FN), 0), 0); \
316 fprintf (FILE, "\n\tnop\n"); \
317 } \
318 while (0)
319
320 #ifndef USE_GAS
321 /* This is how to output an assembler line that says to advance
322 the location counter to a multiple of 2**LOG bytes using the
323 NOP instruction as padding. The filler pattern doesn't work
324 with GNU as. */
325 #define ASM_OUTPUT_ALIGN_WITH_NOP(FILE,LOG) \
326 if ((LOG) != 0) \
327 fprintf (FILE, "\t.align %d,0x1000000\n", (1<<(LOG)))
328
329 /* Use Solaris ELF section syntax with Sun as. */
330 #undef TARGET_ASM_NAMED_SECTION
331 #define TARGET_ASM_NAMED_SECTION sparc_solaris_elf_asm_named_section
332
333 /* Sun as requires doublequoted section names on SPARC. While GNU as
334 supports that, too, we prefer the standard variant. */
335 #undef SECTION_NAME_FORMAT
336 #define SECTION_NAME_FORMAT "\"%s\""
337 #endif /* !USE_GAS */
338
339 /* Undefine this so that attribute((init_priority)) works with GNU ld. */
340 #ifdef USE_GLD
341 #undef CTORS_SECTION_ASM_OP
342 #undef DTORS_SECTION_ASM_OP
343 #endif
344
345 \f
346
347 /* Define for support of TFmode long double.
348 SPARC ABI says that long double is 4 words. */
349 #define LONG_DOUBLE_TYPE_SIZE 128
350
351 /* Solaris's _Qp_* library routine implementation clobbers the output
352 memory before the inputs are fully consumed. */
353
354 #undef TARGET_BUGGY_QP_LIB
355 #define TARGET_BUGGY_QP_LIB 1
356
357 #undef SUN_CONVERSION_LIBFUNCS
358 #define SUN_CONVERSION_LIBFUNCS 1
359
360 #undef DITF_CONVERSION_LIBFUNCS
361 #define DITF_CONVERSION_LIBFUNCS 1
362
363 #undef SUN_INTEGER_MULTIPLY_64
364 #define SUN_INTEGER_MULTIPLY_64 1