xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/config/i386/darwin.h (revision e7ac2a8b5bd66fa2e050809de09a075c36a7014d)
1 /* Target definitions for x86 running Darwin.
2    Copyright (C) 2001-2018 Free Software Foundation, Inc.
3    Contributed by Apple Computer Inc.
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 3, 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 COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20 
21 /* Enable Mach-O bits in generic x86 code.  */
22 #undef TARGET_MACHO
23 #define TARGET_MACHO 1
24 
25 #undef DARWIN_X86
26 #define DARWIN_X86 1
27 
28 #undef  TARGET_64BIT
29 #undef	TARGET_64BIT_P
30 #define TARGET_64BIT TARGET_ISA_64BIT
31 #define	TARGET_64BIT_P(x) TARGET_ISA_64BIT_P(x)
32 
33 #ifdef IN_LIBGCC2
34 #undef TARGET_64BIT
35 #ifdef __x86_64__
36 #define TARGET_64BIT 1
37 #else
38 #define TARGET_64BIT 0
39 #endif
40 #endif
41 
42 /* WORKAROUND pr80556:
43    For x86_64 Darwin10 and later, the unwinder is in libunwind (redirected
44    from libSystem).  This doesn't use the keymgr (see keymgr.c) and therefore
45    the calls that libgcc makes to obtain the KEYMGR_GCC3_DW2_OBJ_LIST are not
46    updated to include new images, and might not even be valid for a single
47    image.
48    Therefore, for 64b exes at least, we must use the libunwind implementation,
49    even when static-libgcc is specified.  We put libSystem first so that
50    unwinder symbols are satisfied from there.
51    We default to 64b for single-arch builds, so apply this unconditionally. */
52 #undef REAL_LIBGCC_SPEC
53 #define REAL_LIBGCC_SPEC						   \
54    "%{static-libgcc|static: 						   \
55        %:version-compare(>= 10.6 mmacosx-version-min= -lSystem)		   \
56        -lgcc_eh -lgcc;							   \
57       shared-libgcc|fexceptions|fgnu-runtime:				   \
58        %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_s.10.4)	   \
59        %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5)   \
60        %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_ext.10.4)	   \
61        %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_ext.10.5)	   \
62        -lgcc ;								   \
63       :%:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \
64        %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5)   \
65        %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_ext.10.4)	   \
66        %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_ext.10.5)	   \
67        -lgcc }"
68 
69 /* Size of the Obj-C jump buffer.  */
70 #define OBJC_JBLEN ((TARGET_64BIT) ? ((9 * 2) + 3 + 16) : (18))
71 
72 #undef TARGET_FPMATH_DEFAULT
73 #define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
74 
75 #define TARGET_OS_CPP_BUILTINS()                \
76   do                                            \
77     {                                           \
78       builtin_define ("__LITTLE_ENDIAN__");     \
79       darwin_cpp_builtins (pfile);		\
80     }                                           \
81   while (0)
82 
83 #undef PTRDIFF_TYPE
84 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
85 
86 #undef WCHAR_TYPE
87 #define WCHAR_TYPE "int"
88 
89 #undef WCHAR_TYPE_SIZE
90 #define WCHAR_TYPE_SIZE 32
91 
92 /* Generate pic symbol indirection stubs if this is true.  */
93 #undef TARGET_MACHO_SYMBOL_STUBS
94 #define TARGET_MACHO_SYMBOL_STUBS (darwin_symbol_stubs)
95 
96 /* For compatibility with OSX system tools, use the new style of pic stub
97    if this is set (default).  */
98 #undef  MACHOPIC_ATT_STUB
99 #define MACHOPIC_ATT_STUB (darwin_macho_att_stub)
100 
101 #undef MAX_BITS_PER_WORD
102 #define MAX_BITS_PER_WORD 64
103 
104 #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
105 #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
106 
107 #undef TARGET_KEEPS_VECTOR_ALIGNED_STACK
108 #define TARGET_KEEPS_VECTOR_ALIGNED_STACK 1
109 
110 /* On Darwin, the stack is 128-bit aligned at the point of every call.
111    Failure to ensure this will lead to a crash in the system libraries
112    or dynamic loader.  */
113 
114 #undef MAIN_STACK_BOUNDARY
115 #define MAIN_STACK_BOUNDARY 128
116 
117 /* Since we'll never want a stack boundary less aligned than 128 bits
118    we need the extra work here otherwise bits of gcc get very grumpy
119    when we ask for lower alignment.  We could just reject values less
120    than 128 bits for Darwin, but it's easier to up the alignment if
121    it's below the minimum.  */
122 #undef PREFERRED_STACK_BOUNDARY
123 #define PREFERRED_STACK_BOUNDARY			\
124   MAX (128, ix86_preferred_stack_boundary)
125 
126 /* We want -fPIC by default, unless we're using -static to compile for
127    the kernel or some such.  */
128 
129 #undef CC1_SPEC
130 #define CC1_SPEC "%(cc1_cpu) \
131   %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
132   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \
133   %{mx32:%eDarwin is not an mx32 platform}" \
134   DARWIN_CC1_SPEC
135 
136 #undef ASM_SPEC
137 #define ASM_SPEC "-arch %(darwin_arch) \
138   " ASM_OPTIONS " -force_cpusubtype_ALL \
139   %{static}" ASM_MMACOSX_VERSION_MIN_SPEC
140 
141 #undef ENDFILE_SPEC
142 #define ENDFILE_SPEC \
143   "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
144    %{mpc32:crtprec32.o%s} \
145    %{mpc64:crtprec64.o%s} \
146    %{mpc80:crtprec80.o%s}" TM_DESTRUCTOR
147 
148 /* We default to x86_64 for single-arch builds, bi-arch overrides.  */
149 #define DARWIN_ARCH_SPEC "x86_64"
150 
151 #undef SUBTARGET_EXTRA_SPECS
152 #define SUBTARGET_EXTRA_SPECS                                   \
153   DARWIN_EXTRA_SPECS                                            \
154   { "darwin_arch", DARWIN_ARCH_SPEC },				\
155   { "darwin_crt2", "" },                                        \
156   { "darwin_subarch", DARWIN_ARCH_SPEC },
157 
158 /* The Darwin assembler mostly follows AT&T syntax.  */
159 #undef ASSEMBLER_DIALECT
160 #define ASSEMBLER_DIALECT ASM_ATT
161 
162 /* Define macro used to output shift-double opcodes when the shift
163    count is in %cl.  Some assemblers require %cl as an argument;
164    some don't.  This macro controls what to do: by default, don't
165    print %cl.  */
166 
167 #define SHIFT_DOUBLE_OMITS_COUNT 0
168 
169 #undef TARGET_ASM_FILE_END
170 #define TARGET_ASM_FILE_END darwin_file_end
171 
172 /* Define the syntax of pseudo-ops, labels and comments.  */
173 
174 /* String containing the assembler's comment-starter.  */
175 
176 #define ASM_COMMENT_START "#"
177 
178 /* By default, target has a 80387, uses IEEE compatible arithmetic,
179    and returns float values in the 387.  */
180 
181 #undef TARGET_SUBTARGET_DEFAULT
182 #define TARGET_SUBTARGET_DEFAULT (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
183 
184 /* For darwin we want to target specific processor features as a minimum,
185    but these unfortunately don't correspond to a specific processor.  */
186 #undef TARGET_SUBTARGET32_ISA_DEFAULT
187 #define TARGET_SUBTARGET32_ISA_DEFAULT (OPTION_MASK_ISA_MMX		\
188 					| OPTION_MASK_ISA_SSE		\
189 					| OPTION_MASK_ISA_SSE2		\
190 					| OPTION_MASK_ISA_SSE3)
191 
192 #undef TARGET_SUBTARGET64_ISA_DEFAULT
193 #define TARGET_SUBTARGET64_ISA_DEFAULT TARGET_SUBTARGET32_ISA_DEFAULT
194 
195 #undef GOT_SYMBOL_NAME
196 #define GOT_SYMBOL_NAME MACHOPIC_FUNCTION_BASE_NAME
197 
198 /* Define the syntax of pseudo-ops, labels and comments.  */
199 
200 #define LPREFIX "L"
201 
202 /* Assembler pseudos to introduce constants of various size.  */
203 
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"
208 
209 #define SUBTARGET_ENCODE_SECTION_INFO  darwin_encode_section_info
210 
211 #undef ASM_OUTPUT_ALIGN
212 #define ASM_OUTPUT_ALIGN(FILE,LOG)	\
213  do { if ((LOG) != 0)			\
214         {				\
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)); \
219         }				\
220     } while (0)
221 
222 #ifdef HAVE_GAS_MAX_SKIP_P2ALIGN
223 #define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE,LOG,MAX_SKIP)                    \
224   do {                                                                  \
225     if ((LOG) != 0) {                                                   \
226       if ((MAX_SKIP) == 0 || (MAX_SKIP) >= (1 << (LOG)) - 1)            \
227         fprintf ((FILE), "\t.p2align %d\n", (LOG));                     \
228       else                                                              \
229         fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP));     \
230     }                                                                   \
231   } while (0)
232 #endif
233 
234 /* Darwin x86 assemblers support the .ident directive.  */
235 
236 #undef TARGET_ASM_OUTPUT_IDENT
237 #define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive
238 
239 /* Darwin profiling -- call mcount.  */
240 #undef FUNCTION_PROFILER
241 #define FUNCTION_PROFILER(FILE, LABELNO)				\
242   do {									\
243     if (TARGET_MACHO_SYMBOL_STUBS 					\
244 	&& MACHOPIC_INDIRECT && !TARGET_64BIT)				\
245       {									\
246 	const char *name = machopic_mcount_stub_name ();		\
247 	fprintf (FILE, "\tcall %s\n", name+1);  /*  skip '&'  */	\
248 	machopic_validate_stub_or_non_lazy_ptr (name);			\
249       }									\
250     else fprintf (FILE, "\tcall mcount\n");				\
251   } while (0)
252 
253 #define C_COMMON_OVERRIDE_OPTIONS					\
254   do {									\
255     SUBTARGET_C_COMMON_OVERRIDE_OPTIONS;				\
256   } while (0)
257 
258 #undef SUBTARGET_OVERRIDE_OPTIONS
259 #define SUBTARGET_OVERRIDE_OPTIONS \
260 do {									\
261   if (TARGET_64BIT && MACHO_DYNAMIC_NO_PIC_P)				\
262     target_flags &= ~MASK_MACHO_DYNAMIC_NO_PIC;				\
263 } while (0)
264 
265 /* Darwin on x86_64 uses dwarf-2 by default.  Pre-darwin9 32-bit
266    compiles default to stabs+.  darwin9+ defaults to dwarf-2.  */
267 #ifndef DARWIN_PREFER_DWARF
268 #undef PREFERRED_DEBUGGING_TYPE
269 #ifdef HAVE_AS_STABS_DIRECTIVE
270 #define PREFERRED_DEBUGGING_TYPE (TARGET_64BIT ? DWARF2_DEBUG : DBX_DEBUG)
271 #else
272 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
273 #endif
274 #endif
275 
276 /* Darwin uses the standard DWARF register numbers but the default
277    register numbers for STABS.  Fortunately for 64-bit code the
278    default and the standard are the same.  */
279 #undef DBX_REGISTER_NUMBER
280 #define DBX_REGISTER_NUMBER(n) 					\
281   (TARGET_64BIT ? dbx64_register_map[n]				\
282    : write_symbols == DWARF2_DEBUG ? svr4_dbx_register_map[n]	\
283    : dbx_register_map[n])
284 
285 /* Unfortunately, the 32-bit EH information also doesn't use the standard
286    DWARF register numbers.  */
287 #define DWARF2_FRAME_REG_OUT(n, for_eh)					\
288   (! (for_eh) || write_symbols != DWARF2_DEBUG || TARGET_64BIT ? (n)	\
289    : (n) == 5 ? 4							\
290    : (n) == 4 ? 5							\
291    : (n) >= 11 && (n) <= 18 ? (n) + 1					\
292    : (n))
293 
294 #undef REGISTER_SUBTARGET_PRAGMAS
295 #define REGISTER_SUBTARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
296 
297 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
298 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
299 
300 /* For 64-bit, we need to add 4 because @GOTPCREL is relative to the
301    end of the instruction, but without the 4 we'd only have the right
302    address for the start of the instruction.  */
303 #undef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
304 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE)	\
305   if (TARGET_64BIT)				                                \
306     {                                                                           \
307       if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel)			\
308         {                                                                       \
309 	   fputs (ASM_LONG, FILE);                                              \
310 	   assemble_name (FILE, XSTR (ADDR, 0));				\
311 	   fputs ("+4@GOTPCREL", FILE);                                         \
312 	   goto DONE;                                                           \
313         }									\
314     }										\
315   else                                                                          \
316     {										\
317       if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1))                      \
318         {                                                                       \
319           darwin_non_lazy_pcrel (FILE, ADDR);                                   \
320           goto DONE;								\
321         }                                                                       \
322     }
323 
324 /* First available SYMBOL flag bit for use by subtargets.  */
325 #define SYMBOL_FLAG_SUBT_DEP (SYMBOL_FLAG_MACH_DEP << 5)
326 
327 #undef MACHOPIC_NL_SYMBOL_PTR_SECTION
328 #define MACHOPIC_NL_SYMBOL_PTR_SECTION \
329 		".section __IMPORT,__pointers,non_lazy_symbol_pointers"
330 
331 #define SUBTARGET32_DEFAULT_CPU "i686"
332 
333 #undef  SUBTARGET_INIT_BUILTINS
334 #define SUBTARGET_INIT_BUILTINS					\
335 do {								\
336   ix86_builtins[(int) IX86_BUILTIN_CFSTRING]			\
337     = darwin_init_cfstring_builtins ((unsigned) (IX86_BUILTIN_CFSTRING));	\
338   darwin_rename_builtins ();					\
339 } while(0)
340