Bring in all split-stack work done over on gccgo branch.
[official-gcc.git] / gcc / config / i386 / darwin.h
blob416b0238c38a2034deee5190c67c06d71f956c35
1 /* Target definitions for x86 running Darwin.
2 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2010
3 Free Software Foundation, Inc.
4 Contributed by Apple Computer Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* Enable Mach-O bits in generic x86 code. */
23 #undef TARGET_MACHO
24 #define TARGET_MACHO 1
26 #define TARGET_VERSION fprintf (stderr, " (i686 Darwin)");
28 #undef TARGET_64BIT
29 #define TARGET_64BIT OPTION_ISA_64BIT
31 #ifdef IN_LIBGCC2
32 #undef TARGET_64BIT
33 #ifdef __x86_64__
34 #define TARGET_64BIT 1
35 #else
36 #define TARGET_64BIT 0
37 #endif
38 #endif
40 /* Size of the Obj-C jump buffer. */
41 #define OBJC_JBLEN ((TARGET_64BIT) ? ((9 * 2) + 3 + 16) : (18))
43 #undef TARGET_FPMATH_DEFAULT
44 #define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
46 #define TARGET_OS_CPP_BUILTINS() \
47 do \
48 { \
49 builtin_define ("__LITTLE_ENDIAN__"); \
50 darwin_cpp_builtins (pfile); \
51 } \
52 while (0)
54 #undef PTRDIFF_TYPE
55 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
57 #undef WCHAR_TYPE
58 #define WCHAR_TYPE "int"
60 #undef WCHAR_TYPE_SIZE
61 #define WCHAR_TYPE_SIZE 32
63 /* Generate branch islands stubs if this is true. */
64 extern int darwin_emit_branch_islands;
66 #undef TARGET_MACHO_BRANCH_ISLANDS
67 #define TARGET_MACHO_BRANCH_ISLANDS darwin_emit_branch_islands
69 #undef MAX_BITS_PER_WORD
70 #define MAX_BITS_PER_WORD 64
72 #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
73 #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
75 #undef TARGET_KEEPS_VECTOR_ALIGNED_STACK
76 #define TARGET_KEEPS_VECTOR_ALIGNED_STACK 1
78 /* On Darwin, the stack is 128-bit aligned at the point of every call.
79 Failure to ensure this will lead to a crash in the system libraries
80 or dynamic loader. */
81 #undef STACK_BOUNDARY
82 #define STACK_BOUNDARY \
83 ((profile_flag || (TARGET_64BIT && ix86_abi == MS_ABI)) \
84 ? 128 : BITS_PER_WORD)
86 #undef MAIN_STACK_BOUNDARY
87 #define MAIN_STACK_BOUNDARY 128
89 /* Since we'll never want a stack boundary less aligned than 128 bits
90 we need the extra work here otherwise bits of gcc get very grumpy
91 when we ask for lower alignment. We could just reject values less
92 than 128 bits for Darwin, but it's easier to up the alignment if
93 it's below the minimum. */
94 #undef PREFERRED_STACK_BOUNDARY
95 #define PREFERRED_STACK_BOUNDARY \
96 MAX (128, ix86_preferred_stack_boundary)
98 /* We want -fPIC by default, unless we're using -static to compile for
99 the kernel or some such. */
101 #undef CC1_SPEC
102 #define CC1_SPEC "%(cc1_cpu) \
103 %<mdynamic-no-pic " /* For now, we just ignore this flag */ " \
104 %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
105 %{!mmacosx-version-min=*:-mmacosx-version-min=%(darwin_minversion)} \
106 %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }}"
108 #undef ASM_SPEC
109 #define ASM_SPEC "-arch %(darwin_arch) -force_cpusubtype_ALL"
111 #define DARWIN_ARCH_SPEC "%{m64:x86_64;:i386}"
112 #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
114 /* Determine a minimum version based on compiler options. */
115 #define DARWIN_MINVERSION_SPEC \
116 "%{!m64|fgnu-runtime:10.4; \
117 ,objective-c|,objc-cpp-output:10.5; \
118 ,objective-c-header:10.5; \
119 ,objective-c++|,objective-c++-cpp-output:10.5; \
120 ,objective-c++-header|,objc++-cpp-output:10.5; \
121 :10.4}"
123 #undef ENDFILE_SPEC
124 #define ENDFILE_SPEC \
125 "%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
126 %{mpc32:crtprec32.o%s} \
127 %{mpc64:crtprec64.o%s} \
128 %{mpc80:crtprec80.o%s}"
130 #undef SUBTARGET_EXTRA_SPECS
131 #define SUBTARGET_EXTRA_SPECS \
132 DARWIN_EXTRA_SPECS \
133 { "darwin_arch", DARWIN_ARCH_SPEC }, \
134 { "darwin_crt2", "" }, \
135 { "darwin_subarch", DARWIN_SUBARCH_SPEC },
137 /* Use the following macro for any Darwin/x86-specific command-line option
138 translation. */
139 #define SUBTARGET_OPTION_TRANSLATE_TABLE \
140 { "", "" }
142 /* The Darwin assembler mostly follows AT&T syntax. */
143 #undef ASSEMBLER_DIALECT
144 #define ASSEMBLER_DIALECT ASM_ATT
146 /* Define macro used to output shift-double opcodes when the shift
147 count is in %cl. Some assemblers require %cl as an argument;
148 some don't. This macro controls what to do: by default, don't
149 print %cl. */
151 #define SHIFT_DOUBLE_OMITS_COUNT 0
153 /* Put all *tf routines in libgcc. */
154 #undef LIBGCC2_HAS_TF_MODE
155 #define LIBGCC2_HAS_TF_MODE 1
156 #define LIBGCC2_TF_CEXT q
157 #define TF_SIZE 113
159 #undef TARGET_ASM_FILE_END
160 #define TARGET_ASM_FILE_END darwin_file_end
162 /* Define the syntax of pseudo-ops, labels and comments. */
164 /* String containing the assembler's comment-starter. */
166 #define ASM_COMMENT_START "#"
168 /* By default, target has a 80387, uses IEEE compatible arithmetic,
169 and returns float values in the 387. */
171 #undef TARGET_SUBTARGET_DEFAULT
172 #define TARGET_SUBTARGET_DEFAULT (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
174 /* For darwin we want to target specific processor features as a minimum,
175 but these unfortunately don't correspond to a specific processor. */
176 #undef TARGET_SUBTARGET32_ISA_DEFAULT
177 #define TARGET_SUBTARGET32_ISA_DEFAULT (OPTION_MASK_ISA_MMX \
178 | OPTION_MASK_ISA_SSE \
179 | OPTION_MASK_ISA_SSE2 \
180 | OPTION_MASK_ISA_SSE3)
182 #undef TARGET_SUBTARGET64_ISA_DEFAULT
183 #define TARGET_SUBTARGET64_ISA_DEFAULT TARGET_SUBTARGET32_ISA_DEFAULT
185 /* For now, disable dynamic-no-pic. We'll need to go through i386.c
186 with a fine-tooth comb looking for refs to flag_pic! */
187 #define MASK_MACHO_DYNAMIC_NO_PIC 0
188 #define TARGET_DYNAMIC_NO_PIC (target_flags & MASK_MACHO_DYNAMIC_NO_PIC)
190 #undef GOT_SYMBOL_NAME
191 #define GOT_SYMBOL_NAME MACHOPIC_FUNCTION_BASE_NAME
193 /* Define the syntax of pseudo-ops, labels and comments. */
195 #define LPREFIX "L"
197 /* These are used by -fbranch-probabilities */
198 #define HOT_TEXT_SECTION_NAME "__TEXT,__text,regular,pure_instructions"
199 #define UNLIKELY_EXECUTED_TEXT_SECTION_NAME \
200 "__TEXT,__unlikely,regular,pure_instructions"
202 /* Assembler pseudos to introduce constants of various size. */
204 #define ASM_BYTE "\t.byte\t"
205 #define ASM_SHORT "\t.word\t"
206 #define ASM_LONG "\t.long\t"
207 #define ASM_QUAD "\t.quad\t"
209 #define SUBTARGET_ENCODE_SECTION_INFO darwin_encode_section_info
211 #undef ASM_OUTPUT_ALIGN
212 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
213 do { if ((LOG) != 0) \
215 if (in_section == text_section) \
216 fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
217 else \
218 fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
220 } while (0)
222 /* This says how to output an assembler line
223 to define a global common symbol. */
225 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \
226 ( fputs ("\t.comm ", (FILE)), \
227 assemble_name ((FILE), (NAME)), \
228 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (ROUNDED)))
230 /* This says how to output an assembler line
231 to define a local common symbol. */
233 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \
234 ( fputs ("\t.lcomm ", (FILE)), \
235 assemble_name ((FILE), (NAME)), \
236 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (ROUNDED)))
238 /* Darwin profiling -- call mcount. */
239 #undef FUNCTION_PROFILER
240 #define FUNCTION_PROFILER(FILE, LABELNO) \
241 do { \
242 if (TARGET_MACHO_BRANCH_ISLANDS && MACHOPIC_INDIRECT && !TARGET_64BIT) \
244 const char *name = machopic_mcount_stub_name (); \
245 fprintf (FILE, "\tcall %s\n", name+1); /* skip '&' */ \
246 machopic_validate_stub_or_non_lazy_ptr (name); \
248 else fprintf (FILE, "\tcall mcount\n"); \
249 } while (0)
251 #define C_COMMON_OVERRIDE_OPTIONS \
252 do { \
253 SUBTARGET_C_COMMON_OVERRIDE_OPTIONS; \
254 } while (0)
256 /* Darwin on x86_64 uses dwarf-2 by default. Pre-darwin9 32-bit
257 compiles default to stabs+. darwin9+ defaults to dwarf-2. */
258 #ifndef DARWIN_PREFER_DWARF
259 #undef PREFERRED_DEBUGGING_TYPE
260 #define PREFERRED_DEBUGGING_TYPE (TARGET_64BIT ? DWARF2_DEBUG : DBX_DEBUG)
261 #endif
263 /* Darwin uses the standard DWARF register numbers but the default
264 register numbers for STABS. Fortunately for 64-bit code the
265 default and the standard are the same. */
266 #undef DBX_REGISTER_NUMBER
267 #define DBX_REGISTER_NUMBER(n) \
268 (TARGET_64BIT ? dbx64_register_map[n] \
269 : write_symbols == DWARF2_DEBUG ? svr4_dbx_register_map[n] \
270 : dbx_register_map[n])
272 /* Unfortunately, the 32-bit EH information also doesn't use the standard
273 DWARF register numbers. */
274 #define DWARF2_FRAME_REG_OUT(n, for_eh) \
275 (! (for_eh) || write_symbols != DWARF2_DEBUG || TARGET_64BIT ? (n) \
276 : (n) == 5 ? 4 \
277 : (n) == 4 ? 5 \
278 : (n) >= 11 && (n) <= 18 ? (n) + 1 \
279 : (n))
281 #undef REGISTER_SUBTARGET_PRAGMAS
282 #define REGISTER_SUBTARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
284 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
285 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
287 /* For 64-bit, we need to add 4 because @GOTPCREL is relative to the
288 end of the instruction, but without the 4 we'd only have the right
289 address for the start of the instruction. */
290 #undef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
291 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE) \
292 if (TARGET_64BIT) \
294 if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel) \
296 fputs (ASM_LONG, FILE); \
297 assemble_name (FILE, XSTR (ADDR, 0)); \
298 fputs ("+4@GOTPCREL", FILE); \
299 goto DONE; \
302 else \
304 if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) \
306 darwin_non_lazy_pcrel (FILE, ADDR); \
307 goto DONE; \
311 /* This needs to move since i386 uses the first flag and other flags are
312 used in Mach-O. */
313 #undef MACHO_SYMBOL_FLAG_VARIABLE
314 #define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3)
316 #define SUBTARGET32_DEFAULT_CPU "i686"