1 /* Target definitions for x86 running Darwin.
2 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2008
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)
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. */
24 #define TARGET_MACHO 1
26 #define TARGET_VERSION fprintf (stderr, " (i686 Darwin)");
29 #define TARGET_64BIT OPTION_ISA_64BIT
34 #define TARGET_64BIT 1
36 #define TARGET_64BIT 0
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() \
49 builtin_define ("__LITTLE_ENDIAN__"); \
50 darwin_cpp_builtins (pfile); \
55 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
58 #define WCHAR_TYPE "int"
60 #undef WCHAR_TYPE_SIZE
61 #define WCHAR_TYPE_SIZE 32
63 #undef MAX_BITS_PER_WORD
64 #define MAX_BITS_PER_WORD 64
66 #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
67 #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
69 #undef TARGET_KEEPS_VECTOR_ALIGNED_STACK
70 #define TARGET_KEEPS_VECTOR_ALIGNED_STACK 1
72 /* On Darwin, the stack is 128-bit aligned at the point of every call.
73 Failure to ensure this will lead to a crash in the system libraries
76 #define STACK_BOUNDARY 128
78 #undef MAIN_STACK_BOUNDARY
79 #define MAIN_STACK_BOUNDARY 128
81 /* Since we'll never want a stack boundary less aligned than 128 bits
82 we need the extra work here otherwise bits of gcc get very grumpy
83 when we ask for lower alignment. We could just reject values less
84 than 128 bits for Darwin, but it's easier to up the alignment if
85 it's below the minimum. */
86 #undef PREFERRED_STACK_BOUNDARY
87 #define PREFERRED_STACK_BOUNDARY \
88 MAX (STACK_BOUNDARY, ix86_preferred_stack_boundary)
90 /* We want -fPIC by default, unless we're using -static to compile for
91 the kernel or some such. */
94 #define CC1_SPEC "%(cc1_cpu) \
95 %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
96 %{!mmacosx-version-min=*:-mmacosx-version-min=%(darwin_minversion)} \
97 %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }}"
100 #define ASM_SPEC "-arch %(darwin_arch) -force_cpusubtype_ALL"
102 #define DARWIN_ARCH_SPEC "%{m64:x86_64;:i386}"
103 #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
105 /* Determine a minimum version based on compiler options. */
106 #define DARWIN_MINVERSION_SPEC \
107 "%{!m64|fgnu-runtime:10.4; \
108 ,objective-c|,objc-cpp-output:10.5; \
109 ,objective-c-header:10.5; \
110 ,objective-c++|,objective-c++-cpp-output:10.5; \
111 ,objective-c++-header|,objc++-cpp-output:10.5; \
115 #define ENDFILE_SPEC \
116 "%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
117 %{mpc32:crtprec32.o%s} \
118 %{mpc64:crtprec64.o%s} \
119 %{mpc80:crtprec80.o%s}"
121 #undef SUBTARGET_EXTRA_SPECS
122 #define SUBTARGET_EXTRA_SPECS \
124 { "darwin_arch", DARWIN_ARCH_SPEC }, \
125 { "darwin_crt2", "" }, \
126 { "darwin_subarch", DARWIN_SUBARCH_SPEC },
128 /* Use the following macro for any Darwin/x86-specific command-line option
130 #define SUBTARGET_OPTION_TRANSLATE_TABLE \
133 /* The Darwin assembler mostly follows AT&T syntax. */
134 #undef ASSEMBLER_DIALECT
135 #define ASSEMBLER_DIALECT ASM_ATT
137 /* Define macro used to output shift-double opcodes when the shift
138 count is in %cl. Some assemblers require %cl as an argument;
139 some don't. This macro controls what to do: by default, don't
142 #define SHIFT_DOUBLE_OMITS_COUNT 0
144 extern void darwin_x86_file_end (void);
145 #undef TARGET_ASM_FILE_END
146 #define TARGET_ASM_FILE_END darwin_x86_file_end
148 /* Define the syntax of pseudo-ops, labels and comments. */
150 /* String containing the assembler's comment-starter. */
152 #define ASM_COMMENT_START "#"
154 /* By default, target has a 80387, uses IEEE compatible arithmetic,
155 and returns float values in the 387. */
157 #undef TARGET_SUBTARGET_DEFAULT
158 #define TARGET_SUBTARGET_DEFAULT (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
160 /* For darwin we want to target specific processor features as a minimum,
161 but these unfortunately don't correspond to a specific processor. */
162 #undef TARGET_SUBTARGET32_ISA_DEFAULT
163 #define TARGET_SUBTARGET32_ISA_DEFAULT (OPTION_MASK_ISA_MMX \
164 | OPTION_MASK_ISA_SSE \
165 | OPTION_MASK_ISA_SSE2 \
166 | OPTION_MASK_ISA_SSE3)
168 #undef TARGET_SUBTARGET64_ISA_DEFAULT
169 #define TARGET_SUBTARGET64_ISA_DEFAULT TARGET_SUBTARGET32_ISA_DEFAULT
171 /* For now, disable dynamic-no-pic. We'll need to go through i386.c
172 with a fine-tooth comb looking for refs to flag_pic! */
173 #define MASK_MACHO_DYNAMIC_NO_PIC 0
174 #define TARGET_DYNAMIC_NO_PIC (target_flags & MASK_MACHO_DYNAMIC_NO_PIC)
176 #undef GOT_SYMBOL_NAME
177 #define GOT_SYMBOL_NAME MACHOPIC_FUNCTION_BASE_NAME
179 /* Define the syntax of pseudo-ops, labels and comments. */
183 /* These are used by -fbranch-probabilities */
184 #define HOT_TEXT_SECTION_NAME "__TEXT,__text,regular,pure_instructions"
185 #define UNLIKELY_EXECUTED_TEXT_SECTION_NAME \
186 "__TEXT,__unlikely,regular,pure_instructions"
188 /* Assembler pseudos to introduce constants of various size. */
190 #define ASM_BYTE "\t.byte\t"
191 #define ASM_SHORT "\t.word\t"
192 #define ASM_LONG "\t.long\t"
193 #define ASM_QUAD "\t.quad\t"
195 #define SUBTARGET_ENCODE_SECTION_INFO darwin_encode_section_info
197 #undef ASM_OUTPUT_ALIGN
198 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
199 do { if ((LOG) != 0) \
201 if (in_section == text_section) \
202 fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
204 fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
208 /* This says how to output an assembler line
209 to define a global common symbol. */
211 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \
212 ( fputs (".comm ", (FILE)), \
213 assemble_name ((FILE), (NAME)), \
214 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (ROUNDED)))
216 /* This says how to output an assembler line
217 to define a local common symbol. */
219 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \
220 ( fputs (".lcomm ", (FILE)), \
221 assemble_name ((FILE), (NAME)), \
222 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (ROUNDED)))
224 /* Darwin profiling -- call mcount. */
225 #undef FUNCTION_PROFILER
226 #define FUNCTION_PROFILER(FILE, LABELNO) \
228 if (MACHOPIC_INDIRECT && !TARGET_64BIT) \
230 const char *name = machopic_mcount_stub_name (); \
231 fprintf (FILE, "\tcall %s\n", name+1); /* skip '&' */ \
232 machopic_validate_stub_or_non_lazy_ptr (name); \
234 else fprintf (FILE, "\tcall mcount\n"); \
237 #define C_COMMON_OVERRIDE_OPTIONS \
239 SUBTARGET_C_COMMON_OVERRIDE_OPTIONS; \
242 /* Darwin on x86_64 uses dwarf-2 by default. Pre-darwin9 32-bit
243 compiles default to stabs+. darwin9+ defaults to dwarf-2. */
244 #ifndef DARWIN_PREFER_DWARF
245 #undef PREFERRED_DEBUGGING_TYPE
246 #define PREFERRED_DEBUGGING_TYPE (TARGET_64BIT ? DWARF2_DEBUG : DBX_DEBUG)
249 /* Darwin uses the standard DWARF register numbers but the default
250 register numbers for STABS. Fortunately for 64-bit code the
251 default and the standard are the same. */
252 #undef DBX_REGISTER_NUMBER
253 #define DBX_REGISTER_NUMBER(n) \
254 (TARGET_64BIT ? dbx64_register_map[n] \
255 : write_symbols == DWARF2_DEBUG ? svr4_dbx_register_map[n] \
256 : dbx_register_map[n])
258 /* Unfortunately, the 32-bit EH information also doesn't use the standard
259 DWARF register numbers. */
260 #define DWARF2_FRAME_REG_OUT(n, for_eh) \
261 (! (for_eh) || write_symbols != DWARF2_DEBUG || TARGET_64BIT ? (n) \
264 : (n) >= 11 && (n) <= 18 ? (n) + 1 \
267 #undef REGISTER_SUBTARGET_PRAGMAS
268 #define REGISTER_SUBTARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
270 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
271 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
273 /* For 64-bit, we need to add 4 because @GOTPCREL is relative to the
274 end of the instruction, but without the 4 we'd only have the right
275 address for the start of the instruction. */
276 #undef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
277 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE) \
280 if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel) \
282 fputs (ASM_LONG, FILE); \
283 assemble_name (FILE, XSTR (ADDR, 0)); \
284 fputs ("+4@GOTPCREL", FILE); \
290 if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) \
292 darwin_non_lazy_pcrel (FILE, ADDR); \
297 /* This needs to move since i386 uses the first flag and other flags are
299 #undef MACHO_SYMBOL_FLAG_VARIABLE
300 #define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3)
302 #define SUBTARGET32_DEFAULT_CPU "i686"