xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/config/i386/darwin.h (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
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.
5 
6 This file is part of GCC.
7 
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.
12 
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.
17 
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/>.  */
21 
22 /* Enable Mach-O bits in generic x86 code.  */
23 #undef TARGET_MACHO
24 #define TARGET_MACHO 1
25 
26 #define TARGET_VERSION fprintf (stderr, " (i686 Darwin)");
27 
28 #undef  TARGET_64BIT
29 #define TARGET_64BIT OPTION_ISA_64BIT
30 
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
39 
40 /* Size of the Obj-C jump buffer.  */
41 #define OBJC_JBLEN ((TARGET_64BIT) ? ((9 * 2) + 3 + 16) : (18))
42 
43 #undef TARGET_FPMATH_DEFAULT
44 #define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
45 
46 #define TARGET_OS_CPP_BUILTINS()                \
47   do                                            \
48     {                                           \
49       builtin_define ("__LITTLE_ENDIAN__");     \
50       darwin_cpp_builtins (pfile);		\
51     }                                           \
52   while (0)
53 
54 #undef PTRDIFF_TYPE
55 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
56 
57 #undef WCHAR_TYPE
58 #define WCHAR_TYPE "int"
59 
60 #undef WCHAR_TYPE_SIZE
61 #define WCHAR_TYPE_SIZE 32
62 
63 #undef MAX_BITS_PER_WORD
64 #define MAX_BITS_PER_WORD 64
65 
66 #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
67 #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
68 
69 #undef TARGET_KEEPS_VECTOR_ALIGNED_STACK
70 #define TARGET_KEEPS_VECTOR_ALIGNED_STACK 1
71 
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
74    or dynamic loader.  */
75 #undef STACK_BOUNDARY
76 #define STACK_BOUNDARY \
77  ((profile_flag || (TARGET_64BIT && ix86_abi == MS_ABI)) \
78   ? 128 : BITS_PER_WORD)
79 
80 #undef MAIN_STACK_BOUNDARY
81 #define MAIN_STACK_BOUNDARY 128
82 
83 /* Since we'll never want a stack boundary less aligned than 128 bits
84    we need the extra work here otherwise bits of gcc get very grumpy
85    when we ask for lower alignment.  We could just reject values less
86    than 128 bits for Darwin, but it's easier to up the alignment if
87    it's below the minimum.  */
88 #undef PREFERRED_STACK_BOUNDARY
89 #define PREFERRED_STACK_BOUNDARY			\
90   MAX (128, ix86_preferred_stack_boundary)
91 
92 /* We want -fPIC by default, unless we're using -static to compile for
93    the kernel or some such.  */
94 
95 #undef CC1_SPEC
96 #define CC1_SPEC "%(cc1_cpu) \
97   %<mdynamic-no-pic " /* For now, we just ignore this flag */ " \
98   %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
99   %{!mmacosx-version-min=*:-mmacosx-version-min=%(darwin_minversion)} \
100   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }}"
101 
102 #undef ASM_SPEC
103 #define ASM_SPEC "-arch %(darwin_arch) -force_cpusubtype_ALL"
104 
105 #define DARWIN_ARCH_SPEC "%{m64:x86_64;:i386}"
106 #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
107 
108 /* Determine a minimum version based on compiler options.  */
109 #define DARWIN_MINVERSION_SPEC				\
110  "%{!m64|fgnu-runtime:10.4;				\
111     ,objective-c|,objc-cpp-output:10.5;			\
112     ,objective-c-header:10.5;				\
113     ,objective-c++|,objective-c++-cpp-output:10.5;	\
114     ,objective-c++-header|,objc++-cpp-output:10.5;	\
115     :10.4}"
116 
117 #undef ENDFILE_SPEC
118 #define ENDFILE_SPEC \
119   "%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
120    %{mpc32:crtprec32.o%s} \
121    %{mpc64:crtprec64.o%s} \
122    %{mpc80:crtprec80.o%s}"
123 
124 #undef SUBTARGET_EXTRA_SPECS
125 #define SUBTARGET_EXTRA_SPECS                                   \
126   DARWIN_EXTRA_SPECS                                            \
127   { "darwin_arch", DARWIN_ARCH_SPEC },                          \
128   { "darwin_crt2", "" },                                        \
129   { "darwin_subarch", DARWIN_SUBARCH_SPEC },
130 
131 /* Use the following macro for any Darwin/x86-specific command-line option
132    translation.  */
133 #define SUBTARGET_OPTION_TRANSLATE_TABLE \
134   { "", "" }
135 
136 /* The Darwin assembler mostly follows AT&T syntax.  */
137 #undef ASSEMBLER_DIALECT
138 #define ASSEMBLER_DIALECT ASM_ATT
139 
140 /* Define macro used to output shift-double opcodes when the shift
141    count is in %cl.  Some assemblers require %cl as an argument;
142    some don't.  This macro controls what to do: by default, don't
143    print %cl.  */
144 
145 #define SHIFT_DOUBLE_OMITS_COUNT 0
146 
147 #undef TARGET_ASM_FILE_END
148 #define TARGET_ASM_FILE_END darwin_file_end
149 
150 /* Define the syntax of pseudo-ops, labels and comments.  */
151 
152 /* String containing the assembler's comment-starter.  */
153 
154 #define ASM_COMMENT_START "#"
155 
156 /* By default, target has a 80387, uses IEEE compatible arithmetic,
157    and returns float values in the 387.  */
158 
159 #undef TARGET_SUBTARGET_DEFAULT
160 #define TARGET_SUBTARGET_DEFAULT (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
161 
162 /* For darwin we want to target specific processor features as a minimum,
163    but these unfortunately don't correspond to a specific processor.  */
164 #undef TARGET_SUBTARGET32_ISA_DEFAULT
165 #define TARGET_SUBTARGET32_ISA_DEFAULT (OPTION_MASK_ISA_MMX		\
166 					| OPTION_MASK_ISA_SSE		\
167 					| OPTION_MASK_ISA_SSE2		\
168 					| OPTION_MASK_ISA_SSE3)
169 
170 #undef TARGET_SUBTARGET64_ISA_DEFAULT
171 #define TARGET_SUBTARGET64_ISA_DEFAULT TARGET_SUBTARGET32_ISA_DEFAULT
172 
173 /* For now, disable dynamic-no-pic.  We'll need to go through i386.c
174    with a fine-tooth comb looking for refs to flag_pic!  */
175 #define MASK_MACHO_DYNAMIC_NO_PIC 0
176 #define TARGET_DYNAMIC_NO_PIC	  (target_flags & MASK_MACHO_DYNAMIC_NO_PIC)
177 
178 #undef GOT_SYMBOL_NAME
179 #define GOT_SYMBOL_NAME MACHOPIC_FUNCTION_BASE_NAME
180 
181 /* Define the syntax of pseudo-ops, labels and comments.  */
182 
183 #define LPREFIX "L"
184 
185 /* These are used by -fbranch-probabilities */
186 #define HOT_TEXT_SECTION_NAME "__TEXT,__text,regular,pure_instructions"
187 #define UNLIKELY_EXECUTED_TEXT_SECTION_NAME \
188                               "__TEXT,__unlikely,regular,pure_instructions"
189 
190 /* Assembler pseudos to introduce constants of various size.  */
191 
192 #define ASM_BYTE "\t.byte\t"
193 #define ASM_SHORT "\t.word\t"
194 #define ASM_LONG "\t.long\t"
195 #define ASM_QUAD "\t.quad\t"
196 
197 #define SUBTARGET_ENCODE_SECTION_INFO  darwin_encode_section_info
198 
199 #undef ASM_OUTPUT_ALIGN
200 #define ASM_OUTPUT_ALIGN(FILE,LOG)	\
201  do { if ((LOG) != 0)			\
202         {				\
203           if (in_section == text_section) \
204             fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
205           else				\
206             fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
207         }				\
208     } while (0)
209 
210 /* This says how to output an assembler line
211    to define a global common symbol.  */
212 
213 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED)  \
214 ( fputs (".comm ", (FILE)),			\
215   assemble_name ((FILE), (NAME)),		\
216   fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (ROUNDED)))
217 
218 /* This says how to output an assembler line
219    to define a local common symbol.  */
220 
221 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)  \
222 ( fputs (".lcomm ", (FILE)),			\
223   assemble_name ((FILE), (NAME)),		\
224   fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (ROUNDED)))
225 
226 /* Darwin profiling -- call mcount.  */
227 #undef FUNCTION_PROFILER
228 #define FUNCTION_PROFILER(FILE, LABELNO)				\
229     do {								\
230       if (MACHOPIC_INDIRECT && !TARGET_64BIT)				\
231 	{								\
232 	  const char *name = machopic_mcount_stub_name ();		\
233 	  fprintf (FILE, "\tcall %s\n", name+1);  /*  skip '&'  */	\
234 	  machopic_validate_stub_or_non_lazy_ptr (name);		\
235 	}								\
236       else fprintf (FILE, "\tcall mcount\n");				\
237     } while (0)
238 
239 #define C_COMMON_OVERRIDE_OPTIONS					\
240   do {									\
241     SUBTARGET_C_COMMON_OVERRIDE_OPTIONS;				\
242   } while (0)
243 
244 /* Darwin on x86_64 uses dwarf-2 by default.  Pre-darwin9 32-bit
245    compiles default to stabs+.  darwin9+ defaults to dwarf-2.  */
246 #ifndef DARWIN_PREFER_DWARF
247 #undef PREFERRED_DEBUGGING_TYPE
248 #define PREFERRED_DEBUGGING_TYPE (TARGET_64BIT ? DWARF2_DEBUG : DBX_DEBUG)
249 #endif
250 
251 /* Darwin uses the standard DWARF register numbers but the default
252    register numbers for STABS.  Fortunately for 64-bit code the
253    default and the standard are the same.  */
254 #undef DBX_REGISTER_NUMBER
255 #define DBX_REGISTER_NUMBER(n) 					\
256   (TARGET_64BIT ? dbx64_register_map[n]				\
257    : write_symbols == DWARF2_DEBUG ? svr4_dbx_register_map[n]	\
258    : dbx_register_map[n])
259 
260 /* Unfortunately, the 32-bit EH information also doesn't use the standard
261    DWARF register numbers.  */
262 #define DWARF2_FRAME_REG_OUT(n, for_eh)					\
263   (! (for_eh) || write_symbols != DWARF2_DEBUG || TARGET_64BIT ? (n)	\
264    : (n) == 5 ? 4							\
265    : (n) == 4 ? 5							\
266    : (n) >= 11 && (n) <= 18 ? (n) + 1					\
267    : (n))
268 
269 #undef REGISTER_SUBTARGET_PRAGMAS
270 #define REGISTER_SUBTARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
271 
272 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
273 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
274 
275 /* For 64-bit, we need to add 4 because @GOTPCREL is relative to the
276    end of the instruction, but without the 4 we'd only have the right
277    address for the start of the instruction.  */
278 #undef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
279 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE)	\
280   if (TARGET_64BIT)				                                \
281     {                                                                           \
282       if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel)			\
283         {                                                                       \
284 	   fputs (ASM_LONG, FILE);                                              \
285 	   assemble_name (FILE, XSTR (ADDR, 0));				\
286 	   fputs ("+4@GOTPCREL", FILE);                                         \
287 	   goto DONE;                                                           \
288         }									\
289     }										\
290   else                                                                          \
291     {										\
292       if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1))                      \
293         {                                                                       \
294           darwin_non_lazy_pcrel (FILE, ADDR);                                   \
295           goto DONE;								\
296         }                                                                       \
297     }
298 
299 /* This needs to move since i386 uses the first flag and other flags are
300    used in Mach-O.  */
301 #undef MACHO_SYMBOL_FLAG_VARIABLE
302 #define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3)
303 
304 #define SUBTARGET32_DEFAULT_CPU "i686"
305 
306 #define SUBTARGET_INIT_BUILTINS					\
307 do {								\
308   darwin_rename_builtins ();					\
309 } while(0)
310 
311 /* The system ___divdc3 routine in libSystem on darwin10 is not
312    accurate to 1ulp, ours is, so we avoid ever using the system name
313    for this routine and instead install a non-conflicting name that is
314    accurate.  See darwin_rename_builtins.  */
315 #ifdef L_divdc3
316 #define DECLARE_LIBRARY_RENAMES \
317   asm(".text; ___divdc3: jmp ___ieee_divdc3 ; .globl ___divdc3");
318 #endif
319