c3ecfaf1dee26bd92cc46ed65cf93078df08b68f
[gcc.git] / gcc / config / sparc / linux64.h
1 /* Definitions for 64-bit SPARC running Linux-based GNU systems with ELF.
2 Copyright 1996, 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by David S. Miller (davem@caip.rutgers.edu)
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #define TARGET_OS_CPP_BUILTINS() \
23 do \
24 { \
25 builtin_define_std ("unix"); \
26 builtin_define_std ("linux"); \
27 builtin_define ("_LONGLONG"); \
28 builtin_define ("__gnu_linux__"); \
29 builtin_assert ("system=unix"); \
30 builtin_assert ("system=posix"); \
31 } \
32 while (0)
33
34 /* Don't assume anything about the header files. */
35 #define NO_IMPLICIT_EXTERN_C
36
37 #undef MD_EXEC_PREFIX
38 #undef MD_STARTFILE_PREFIX
39
40 #if TARGET_CPU_DEFAULT == TARGET_CPU_v9 || TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc
41 /* A 64 bit v9 compiler with stack-bias,
42 in a Medium/Low code model environment. */
43
44 #undef TARGET_DEFAULT
45 #define TARGET_DEFAULT \
46 (MASK_V9 + MASK_PTR64 + MASK_64BIT /* + MASK_HARD_QUAD */ \
47 + MASK_STACK_BIAS + MASK_APP_REGS + MASK_FPU + MASK_LONG_DOUBLE_128)
48 #endif
49
50 #undef ASM_CPU_DEFAULT_SPEC
51 #define ASM_CPU_DEFAULT_SPEC "-Av9a"
52
53 #ifdef SPARC_BI_ARCH
54
55 #undef CPP_ARCH32_SPEC
56 #define CPP_ARCH32_SPEC "%{mlong-double-128:-D__LONG_DOUBLE_128__}"
57
58 #endif
59
60 /* Provide a STARTFILE_SPEC appropriate for GNU/Linux. Here we add
61 the GNU/Linux magical crtbegin.o file (see crtstuff.c) which
62 provides part of the support for getting C++ file-scope static
63 object constructed before entering `main'. */
64
65 #undef STARTFILE_SPEC
66
67 #ifdef HAVE_LD_PIE
68 #define STARTFILE_SPEC \
69 "%{!shared:%{pg|p:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}}\
70 crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbeginS.o%s}"
71 #else
72 #define STARTFILE_SPEC \
73 "%{!shared:%{pg|p:gcrt1.o%s;:crt1.o%s}}\
74 crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbeginS.o%s}"
75 #endif
76
77 /* Provide a ENDFILE_SPEC appropriate for GNU/Linux. Here we tack on
78 the GNU/Linux magical crtend.o file (see crtstuff.c) which
79 provides part of the support for getting C++ file-scope static
80 object constructed before entering `main', followed by a normal
81 GNU/Linux "finalizer" file, `crtn.o'. */
82
83 #undef ENDFILE_SPEC
84
85 #define ENDFILE_SPEC \
86 "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\
87 %{ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
88
89 /* The GNU C++ standard library requires that these macros be defined. */
90 #undef CPLUSPLUS_CPP_SPEC
91 #define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)"
92
93 #undef TARGET_VERSION
94 #define TARGET_VERSION fprintf (stderr, " (sparc64 GNU/Linux with ELF)");
95
96 /* The default code model. */
97 #undef SPARC_DEFAULT_CMODEL
98 #define SPARC_DEFAULT_CMODEL CM_MEDLOW
99
100 #undef SUBTARGET_SWITCHES
101 #define SUBTARGET_SWITCHES \
102 {"long-double-64", -MASK_LONG_DOUBLE_128, N_("Use 64 bit long doubles") }, \
103 {"long-double-128", MASK_LONG_DOUBLE_128, N_("Use 128 bit long doubles") },
104
105 #undef WCHAR_TYPE
106 #define WCHAR_TYPE "int"
107
108 #undef WCHAR_TYPE_SIZE
109 #define WCHAR_TYPE_SIZE 32
110
111 /* Define for support of TFmode long double.
112 SPARC ABI says that long double is 4 words. */
113 #undef LONG_DOUBLE_TYPE_SIZE
114 #define LONG_DOUBLE_TYPE_SIZE (TARGET_LONG_DOUBLE_128 ? 128 : 64)
115
116 /* Constant which presents upper bound of the above value. */
117 #undef MAX_LONG_DOUBLE_TYPE_SIZE
118 #define MAX_LONG_DOUBLE_TYPE_SIZE 128
119
120 /* Define this to set long double type size to use in libgcc2.c, which can
121 not depend on target_flags. */
122 #if defined(__arch64__) || defined(__LONG_DOUBLE_128__)
123 #define LIBGCC2_LONG_DOUBLE_TYPE_SIZE 128
124 #else
125 #define LIBGCC2_LONG_DOUBLE_TYPE_SIZE 64
126 #endif
127
128 #undef CPP_SUBTARGET_SPEC
129 #define CPP_SUBTARGET_SPEC "\
130 %{fPIC|fpic|fPIE|fpie:-D__PIC__ -D__pic__} \
131 %{posix:-D_POSIX_SOURCE} \
132 %{pthread:-D_REENTRANT} \
133 "
134
135 #undef LIB_SPEC
136 #define LIB_SPEC \
137 "%{pthread:-lpthread} \
138 %{shared:-lc} \
139 %{!shared: %{mieee-fp:-lieee} %{profile:-lc_p}%{!profile:-lc}}"
140
141 /* Provide a LINK_SPEC appropriate for GNU/Linux. Here we provide support
142 for the special GCC options -static and -shared, which allow us to
143 link things in one of these three modes by applying the appropriate
144 combinations of options at link-time. We like to support here for
145 as many of the other GNU linker options as possible. But I don't
146 have the time to search for those flags. I am sure how to add
147 support for -soname shared_object_name. H.J.
148
149 I took out %{v:%{!V:-V}}. It is too much :-(. They can use
150 -Wl,-V.
151
152 When the -shared link option is used a final link is not being
153 done. */
154
155 /* If ELF is the default format, we should not use /lib/elf. */
156
157 #ifdef SPARC_BI_ARCH
158
159 #undef SUBTARGET_EXTRA_SPECS
160 #define SUBTARGET_EXTRA_SPECS \
161 { "link_arch32", LINK_ARCH32_SPEC }, \
162 { "link_arch64", LINK_ARCH64_SPEC }, \
163 { "link_arch_default", LINK_ARCH_DEFAULT_SPEC }, \
164 { "link_arch", LINK_ARCH_SPEC },
165
166 #define LINK_ARCH32_SPEC "-m elf32_sparc -Y P,/usr/lib %{shared:-shared} \
167 %{!shared: \
168 %{!ibcs: \
169 %{!static: \
170 %{rdynamic:-export-dynamic} \
171 %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \
172 %{static:-static}}} \
173 "
174
175 #define LINK_ARCH64_SPEC "-m elf64_sparc -Y P,/usr/lib64 %{shared:-shared} \
176 %{!shared: \
177 %{!ibcs: \
178 %{!static: \
179 %{rdynamic:-export-dynamic} \
180 %{!dynamic-linker:-dynamic-linker /lib64/ld-linux.so.2}} \
181 %{static:-static}}} \
182 "
183
184 #define LINK_ARCH_SPEC "\
185 %{m32:%(link_arch32)} \
186 %{m64:%(link_arch64)} \
187 %{!m32:%{!m64:%(link_arch_default)}} \
188 "
189
190 #define LINK_ARCH_DEFAULT_SPEC \
191 (DEFAULT_ARCH32_P ? LINK_ARCH32_SPEC : LINK_ARCH64_SPEC)
192
193 #undef LINK_SPEC
194 #define LINK_SPEC "\
195 %(link_arch) \
196 %{mlittle-endian:-EL} \
197 %{!mno-relax:%{!r:-relax}} \
198 "
199
200 #undef CC1_SPEC
201 #if DEFAULT_ARCH32_P
202 #define CC1_SPEC "\
203 %{sun4:} %{target:} \
204 %{mcypress:-mcpu=cypress} \
205 %{msparclite:-mcpu=sparclite} %{mf930:-mcpu=f930} %{mf934:-mcpu=f934} \
206 %{mv8:-mcpu=v8} %{msupersparc:-mcpu=supersparc} \
207 %{m32:%{m64:%emay not use both -m32 and -m64}} \
208 %{m64:-mptr64 -mstack-bias -mlong-double-128 \
209 %{!mcpu*:%{!mcypress:%{!msparclite:%{!mf930:%{!mf934:%{!mv8:%{!msupersparc:-mcpu=ultrasparc}}}}}}} \
210 %{!mno-vis:%{!mcpu=v9:-mvis}}} \
211 "
212 #else
213 #define CC1_SPEC "\
214 %{sun4:} %{target:} \
215 %{mcypress:-mcpu=cypress} \
216 %{msparclite:-mcpu=sparclite} %{mf930:-mcpu=f930} %{mf934:-mcpu=f934} \
217 %{mv8:-mcpu=v8} %{msupersparc:-mcpu=supersparc} \
218 %{m32:%{m64:%emay not use both -m32 and -m64}} \
219 %{m32:-mptr32 -mno-stack-bias %{!mlong-double-128:-mlong-double-64} \
220 %{!mcpu*:%{!mcypress:%{!msparclite:%{!mf930:%{!mf934:%{!mv8:%{!msupersparc:-mcpu=cypress}}}}}}}} \
221 %{!m32:%{!mcpu*:-mcpu=ultrasparc}} \
222 %{!mno-vis:%{!m32:%{!mcpu=v9:-mvis}}} \
223 "
224 #endif
225
226 #if DEFAULT_ARCH32_P
227 #define MULTILIB_DEFAULTS { "m32" }
228 #else
229 #define MULTILIB_DEFAULTS { "m64" }
230 #endif
231
232 #else /* !SPARC_BI_ARCH */
233
234 #undef LINK_SPEC
235 #define LINK_SPEC "-m elf64_sparc -Y P,/usr/lib64 %{shared:-shared} \
236 %{!shared: \
237 %{!ibcs: \
238 %{!static: \
239 %{rdynamic:-export-dynamic} \
240 %{!dynamic-linker:-dynamic-linker /lib64/ld-linux.so.2}} \
241 %{static:-static}}} \
242 %{mlittle-endian:-EL} \
243 %{!mno-relax:%{!r:-relax}} \
244 "
245
246 #endif /* !SPARC_BI_ARCH */
247
248 /* The sun bundled assembler doesn't accept -Yd, (and neither does gas).
249 It's safe to pass -s always, even if -g is not used. */
250 #undef ASM_SPEC
251 #define ASM_SPEC "\
252 %{V} \
253 %{v:%{!V:-V}} \
254 %{!Qn:-Qy} \
255 %{n} \
256 %{T} \
257 %{Ym,*} \
258 %{Wa,*:%*} \
259 -s %{fpic|fPIC|fpie|fPIE:-K PIC} \
260 %{mlittle-endian:-EL} \
261 %(asm_cpu) %(asm_arch) %(asm_relax)"
262
263 /* Same as sparc.h */
264 #undef DBX_REGISTER_NUMBER
265 #define DBX_REGISTER_NUMBER(REGNO) (REGNO)
266
267 /* System V Release 4 uses DWARF debugging info. Buf DWARF1 doesn't do
268 64-bit anything, so we use DWARF2. */
269
270 #undef DWARF_DEBUGGING_INFO
271 #define DWARF2_DEBUGGING_INFO 1
272 #define DBX_DEBUGGING_INFO 1
273
274 #undef ASM_OUTPUT_ALIGNED_LOCAL
275 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
276 do { \
277 fputs ("\t.local\t", (FILE)); \
278 assemble_name ((FILE), (NAME)); \
279 putc ('\n', (FILE)); \
280 ASM_OUTPUT_ALIGNED_COMMON (FILE, NAME, SIZE, ALIGN); \
281 } while (0)
282
283 #undef COMMON_ASM_OP
284 #define COMMON_ASM_OP "\t.common\t"
285
286 #undef LOCAL_LABEL_PREFIX
287 #define LOCAL_LABEL_PREFIX "."
288
289 /* This is how to output a reference to an internal numbered label where
290 PREFIX is the class of label and NUM is the number within the class. */
291
292 #undef ASM_OUTPUT_INTERNAL_LABELREF
293 #define ASM_OUTPUT_INTERNAL_LABELREF(FILE,PREFIX,NUM) \
294 fprintf (FILE, ".L%s%d", PREFIX, NUM)
295
296 /* This is how to store into the string LABEL
297 the symbol_ref name of an internal numbered label where
298 PREFIX is the class of label and NUM is the number within the class.
299 This is suitable for output with `assemble_name'. */
300
301 #undef ASM_GENERATE_INTERNAL_LABEL
302 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
303 sprintf (LABEL, "*.L%s%ld", PREFIX, (long)(NUM))
304
305 /* DWARF bits. */
306
307 /* Follow Irix 6 and not the Dwarf2 draft in using 64-bit offsets.
308 Obviously the Dwarf2 folks haven't tried to actually build systems
309 with their spec. On a 64-bit system, only 64-bit relocs become
310 RELATIVE relocations. */
311
312 /* #define DWARF_OFFSET_SIZE PTR_SIZE */
313
314 #if defined(HAVE_LD_EH_FRAME_HDR)
315 #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
316 #endif
317 \f
318 #ifdef HAVE_AS_TLS
319 #undef TARGET_SUN_TLS
320 #undef TARGET_GNU_TLS
321 #define TARGET_SUN_TLS 0
322 #define TARGET_GNU_TLS 1
323 #endif
324 \f
325 /* Don't be different from other Linux platforms in this regard. */
326 #define HANDLE_PRAGMA_PACK_PUSH_POP
327
328 /* We use GNU ld so undefine this so that attribute((init_priority)) works. */
329 #undef CTORS_SECTION_ASM_OP
330 #undef DTORS_SECTION_ASM_OP
331
332 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
333
334 #define LINK_GCC_C_SEQUENCE_SPEC \
335 "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
336
337 /* Do code reading to identify a signal frame, and set the frame
338 state data appropriately. See unwind-dw2.c for the structs. */
339
340 /* Handle multilib correctly. */
341 #if defined(__arch64__)
342 /* 64-bit SPARC version */
343 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS) \
344 do { \
345 unsigned int *pc_ = (CONTEXT)->ra; \
346 long new_cfa_, i_; \
347 long regs_off_, fpu_save_off_; \
348 long this_cfa_, fpu_save_; \
349 \
350 if (pc_[0] != 0x82102065 /* mov NR_rt_sigreturn, %g1 */ \
351 || pc_[1] != 0x91d0206d) /* ta 0x6d */ \
352 break; \
353 regs_off_ = 192 + 128; \
354 fpu_save_off_ = regs_off_ + (16 * 8) + (3 * 8) + (2 * 4); \
355 this_cfa_ = (long) (CONTEXT)->cfa; \
356 new_cfa_ = *(long *)(((CONTEXT)->cfa) + (regs_off_ + (14 * 8))); \
357 new_cfa_ += 2047; /* Stack bias */ \
358 fpu_save_ = *(long *)((this_cfa_) + (fpu_save_off_)); \
359 (FS)->cfa_how = CFA_REG_OFFSET; \
360 (FS)->cfa_reg = 14; \
361 (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa; \
362 for (i_ = 1; i_ < 16; ++i_) \
363 { \
364 (FS)->regs.reg[i_].how = REG_SAVED_OFFSET; \
365 (FS)->regs.reg[i_].loc.offset = \
366 this_cfa_ + (regs_off_ + (i_ * 8)) - new_cfa_; \
367 } \
368 for (i_ = 0; i_ < 16; ++i_) \
369 { \
370 (FS)->regs.reg[i_ + 16].how = REG_SAVED_OFFSET; \
371 (FS)->regs.reg[i_ + 16].loc.offset = \
372 this_cfa_ + (i_ * 8) - new_cfa_; \
373 } \
374 if (fpu_save_) \
375 { \
376 for (i_ = 0; i_ < 64; ++i_) \
377 { \
378 if (i_ > 32 && (i_ & 0x1)) \
379 continue; \
380 (FS)->regs.reg[i_ + 32].how = REG_SAVED_OFFSET; \
381 (FS)->regs.reg[i_ + 32].loc.offset = \
382 (fpu_save_ + (i_ * 4)) - new_cfa_; \
383 } \
384 } \
385 /* Stick return address into %g0, same trick Alpha uses. */ \
386 (FS)->regs.reg[0].how = REG_SAVED_OFFSET; \
387 (FS)->regs.reg[0].loc.offset = \
388 this_cfa_ + (regs_off_ + (16 * 8) + 8) - new_cfa_; \
389 (FS)->retaddr_column = 0; \
390 goto SUCCESS; \
391 } while (0)
392 #else
393 /* 32-bit SPARC version */
394 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS) \
395 do { \
396 unsigned int *pc_ = (CONTEXT)->ra; \
397 int new_cfa_, i_, oldstyle_; \
398 int regs_off_, fpu_save_off_; \
399 int fpu_save_, this_cfa_; \
400 \
401 if (pc_[1] != 0x91d02010) /* ta 0x10 */ \
402 break; \
403 if (pc_[0] == 0x821020d8) /* mov NR_sigreturn, %g1 */ \
404 oldstyle_ = 1; \
405 else if (pc_[0] == 0x82102065) /* mov NR_rt_sigreturn, %g1 */ \
406 oldstyle_ = 0; \
407 else \
408 break; \
409 if (oldstyle_) \
410 { \
411 regs_off_ = 96; \
412 fpu_save_off_ = regs_off_ + (4 * 4) + (16 * 4); \
413 } \
414 else \
415 { \
416 regs_off_ = 96 + 128; \
417 fpu_save_off_ = regs_off_ + (4 * 4) + (16 * 4) + (2 * 4); \
418 } \
419 this_cfa_ = (int) (CONTEXT)->cfa; \
420 new_cfa_ = *(int *)(((CONTEXT)->cfa) + (regs_off_+(4*4)+(14 * 4))); \
421 fpu_save_ = *(int *)((this_cfa_) + (fpu_save_off_)); \
422 (FS)->cfa_how = CFA_REG_OFFSET; \
423 (FS)->cfa_reg = 14; \
424 (FS)->cfa_offset = new_cfa_ - (int) (CONTEXT)->cfa; \
425 for (i_ = 1; i_ < 16; ++i_) \
426 { \
427 if (i_ == 14) \
428 continue; \
429 (FS)->regs.reg[i_].how = REG_SAVED_OFFSET; \
430 (FS)->regs.reg[i_].loc.offset = \
431 this_cfa_ + (regs_off_+(4 * 4)+(i_ * 4)) - new_cfa_; \
432 } \
433 for (i_ = 0; i_ < 16; ++i_) \
434 { \
435 (FS)->regs.reg[i_ + 16].how = REG_SAVED_OFFSET; \
436 (FS)->regs.reg[i_ + 16].loc.offset = \
437 this_cfa_ + (i_ * 4) - new_cfa_; \
438 } \
439 if (fpu_save_) \
440 { \
441 for (i_ = 0; i_ < 32; ++i_) \
442 { \
443 (FS)->regs.reg[i_ + 32].how = REG_SAVED_OFFSET; \
444 (FS)->regs.reg[i_ + 32].loc.offset = \
445 (fpu_save_ + (i_ * 4)) - new_cfa_; \
446 } \
447 } \
448 /* Stick return address into %g0, same trick Alpha uses. */ \
449 (FS)->regs.reg[0].how = REG_SAVED_OFFSET; \
450 (FS)->regs.reg[0].loc.offset = this_cfa_+(regs_off_+4)-new_cfa_; \
451 (FS)->retaddr_column = 0; \
452 goto SUCCESS; \
453 } while (0)
454 #endif