xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/config/i386/darwin.h (revision e6c7e151de239c49d2e38720a061ed9d1fa99309)
1 /* Target definitions for x86 running Darwin.
2    Copyright (C) 2001-2017 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 /* Size of the Obj-C jump buffer.  */
43 #define OBJC_JBLEN ((TARGET_64BIT) ? ((9 * 2) + 3 + 16) : (18))
44 
45 #undef TARGET_FPMATH_DEFAULT
46 #define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
47 
48 #define TARGET_OS_CPP_BUILTINS()                \
49   do                                            \
50     {                                           \
51       builtin_define ("__LITTLE_ENDIAN__");     \
52       darwin_cpp_builtins (pfile);		\
53     }                                           \
54   while (0)
55 
56 #undef PTRDIFF_TYPE
57 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
58 
59 #undef WCHAR_TYPE
60 #define WCHAR_TYPE "int"
61 
62 #undef WCHAR_TYPE_SIZE
63 #define WCHAR_TYPE_SIZE 32
64 
65 /* Generate branch islands stubs if this is true.  */
66 extern int darwin_emit_branch_islands;
67 
68 #undef TARGET_MACHO_BRANCH_ISLANDS
69 #define TARGET_MACHO_BRANCH_ISLANDS darwin_emit_branch_islands
70 
71 /* For compatibility with OSX system tools, use the new style of pic stub
72    if this is set.  */
73 #undef  MACHOPIC_ATT_STUB
74 #define MACHOPIC_ATT_STUB (darwin_macho_att_stub)
75 
76 #undef MAX_BITS_PER_WORD
77 #define MAX_BITS_PER_WORD 64
78 
79 #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
80 #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
81 
82 #undef TARGET_KEEPS_VECTOR_ALIGNED_STACK
83 #define TARGET_KEEPS_VECTOR_ALIGNED_STACK 1
84 
85 /* On Darwin, the stack is 128-bit aligned at the point of every call.
86    Failure to ensure this will lead to a crash in the system libraries
87    or dynamic loader.  */
88 #undef STACK_BOUNDARY
89 #define STACK_BOUNDARY \
90   ((profile_flag || TARGET_64BIT_MS_ABI) ? 128 : BITS_PER_WORD)
91 
92 #undef MAIN_STACK_BOUNDARY
93 #define MAIN_STACK_BOUNDARY 128
94 
95 /* Since we'll never want a stack boundary less aligned than 128 bits
96    we need the extra work here otherwise bits of gcc get very grumpy
97    when we ask for lower alignment.  We could just reject values less
98    than 128 bits for Darwin, but it's easier to up the alignment if
99    it's below the minimum.  */
100 #undef PREFERRED_STACK_BOUNDARY
101 #define PREFERRED_STACK_BOUNDARY			\
102   MAX (128, ix86_preferred_stack_boundary)
103 
104 /* We want -fPIC by default, unless we're using -static to compile for
105    the kernel or some such.  */
106 
107 #undef CC1_SPEC
108 #define CC1_SPEC "%(cc1_cpu) \
109   %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
110   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} " \
111   DARWIN_CC1_SPEC
112 
113 #undef ASM_SPEC
114 #define ASM_SPEC "-arch %(darwin_arch) \
115   " ASM_OPTIONS " -force_cpusubtype_ALL \
116   %{static}" ASM_MMACOSX_VERSION_MIN_SPEC
117 
118 #define DARWIN_ARCH_SPEC "%{m64:x86_64;:i386}"
119 #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
120 
121 #undef ENDFILE_SPEC
122 #define ENDFILE_SPEC \
123   "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
124    %{mpc32:crtprec32.o%s} \
125    %{mpc64:crtprec64.o%s} \
126    %{mpc80:crtprec80.o%s}" TM_DESTRUCTOR
127 
128 #undef SUBTARGET_EXTRA_SPECS
129 #define SUBTARGET_EXTRA_SPECS                                   \
130   DARWIN_EXTRA_SPECS                                            \
131   { "darwin_arch", DARWIN_ARCH_SPEC },                          \
132   { "darwin_crt2", "" },                                        \
133   { "darwin_subarch", DARWIN_SUBARCH_SPEC },
134 
135 /* The Darwin assembler mostly follows AT&T syntax.  */
136 #undef ASSEMBLER_DIALECT
137 #define ASSEMBLER_DIALECT ASM_ATT
138 
139 /* Define macro used to output shift-double opcodes when the shift
140    count is in %cl.  Some assemblers require %cl as an argument;
141    some don't.  This macro controls what to do: by default, don't
142    print %cl.  */
143 
144 #define SHIFT_DOUBLE_OMITS_COUNT 0
145 
146 #undef TARGET_ASM_FILE_END
147 #define TARGET_ASM_FILE_END darwin_file_end
148 
149 /* Define the syntax of pseudo-ops, labels and comments.  */
150 
151 /* String containing the assembler's comment-starter.  */
152 
153 #define ASM_COMMENT_START "#"
154 
155 /* By default, target has a 80387, uses IEEE compatible arithmetic,
156    and returns float values in the 387.  */
157 
158 #undef TARGET_SUBTARGET_DEFAULT
159 #define TARGET_SUBTARGET_DEFAULT (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
160 
161 /* For darwin we want to target specific processor features as a minimum,
162    but these unfortunately don't correspond to a specific processor.  */
163 #undef TARGET_SUBTARGET32_ISA_DEFAULT
164 #define TARGET_SUBTARGET32_ISA_DEFAULT (OPTION_MASK_ISA_MMX		\
165 					| OPTION_MASK_ISA_SSE		\
166 					| OPTION_MASK_ISA_SSE2		\
167 					| OPTION_MASK_ISA_SSE3)
168 
169 #undef TARGET_SUBTARGET64_ISA_DEFAULT
170 #define TARGET_SUBTARGET64_ISA_DEFAULT TARGET_SUBTARGET32_ISA_DEFAULT
171 
172 #undef GOT_SYMBOL_NAME
173 #define GOT_SYMBOL_NAME MACHOPIC_FUNCTION_BASE_NAME
174 
175 /* Define the syntax of pseudo-ops, labels and comments.  */
176 
177 #define LPREFIX "L"
178 
179 /* Assembler pseudos to introduce constants of various size.  */
180 
181 #define ASM_BYTE "\t.byte\t"
182 #define ASM_SHORT "\t.word\t"
183 #define ASM_LONG "\t.long\t"
184 #define ASM_QUAD "\t.quad\t"
185 
186 #define SUBTARGET_ENCODE_SECTION_INFO  darwin_encode_section_info
187 
188 #undef ASM_OUTPUT_ALIGN
189 #define ASM_OUTPUT_ALIGN(FILE,LOG)	\
190  do { if ((LOG) != 0)			\
191         {				\
192           if (in_section == text_section) \
193             fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
194           else				\
195             fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
196         }				\
197     } while (0)
198 
199 /* Darwin profiling -- call mcount.  */
200 #undef FUNCTION_PROFILER
201 #define FUNCTION_PROFILER(FILE, LABELNO)				\
202     do {								\
203       if (TARGET_MACHO_BRANCH_ISLANDS 					\
204 	   && MACHOPIC_INDIRECT && !TARGET_64BIT)			\
205 	{								\
206 	  const char *name = machopic_mcount_stub_name ();		\
207 	  fprintf (FILE, "\tcall %s\n", name+1);  /*  skip '&'  */	\
208 	  machopic_validate_stub_or_non_lazy_ptr (name);		\
209 	}								\
210       else fprintf (FILE, "\tcall mcount\n");				\
211     } while (0)
212 
213 #define C_COMMON_OVERRIDE_OPTIONS					\
214   do {									\
215     SUBTARGET_C_COMMON_OVERRIDE_OPTIONS;				\
216   } while (0)
217 
218 #undef SUBTARGET_OVERRIDE_OPTIONS
219 #define SUBTARGET_OVERRIDE_OPTIONS \
220 do {									\
221   if (TARGET_64BIT && MACHO_DYNAMIC_NO_PIC_P)				\
222     target_flags &= ~MASK_MACHO_DYNAMIC_NO_PIC;				\
223 } while (0)
224 
225 /* Darwin on x86_64 uses dwarf-2 by default.  Pre-darwin9 32-bit
226    compiles default to stabs+.  darwin9+ defaults to dwarf-2.  */
227 #ifndef DARWIN_PREFER_DWARF
228 #undef PREFERRED_DEBUGGING_TYPE
229 #ifdef HAVE_AS_STABS_DIRECTIVE
230 #define PREFERRED_DEBUGGING_TYPE (TARGET_64BIT ? DWARF2_DEBUG : DBX_DEBUG)
231 #else
232 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
233 #endif
234 #endif
235 
236 /* Darwin uses the standard DWARF register numbers but the default
237    register numbers for STABS.  Fortunately for 64-bit code the
238    default and the standard are the same.  */
239 #undef DBX_REGISTER_NUMBER
240 #define DBX_REGISTER_NUMBER(n) 					\
241   (TARGET_64BIT ? dbx64_register_map[n]				\
242    : write_symbols == DWARF2_DEBUG ? svr4_dbx_register_map[n]	\
243    : dbx_register_map[n])
244 
245 /* Unfortunately, the 32-bit EH information also doesn't use the standard
246    DWARF register numbers.  */
247 #define DWARF2_FRAME_REG_OUT(n, for_eh)					\
248   (! (for_eh) || write_symbols != DWARF2_DEBUG || TARGET_64BIT ? (n)	\
249    : (n) == 5 ? 4							\
250    : (n) == 4 ? 5							\
251    : (n) >= 11 && (n) <= 18 ? (n) + 1					\
252    : (n))
253 
254 #undef REGISTER_SUBTARGET_PRAGMAS
255 #define REGISTER_SUBTARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
256 
257 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
258 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
259 
260 /* For 64-bit, we need to add 4 because @GOTPCREL is relative to the
261    end of the instruction, but without the 4 we'd only have the right
262    address for the start of the instruction.  */
263 #undef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
264 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE)	\
265   if (TARGET_64BIT)				                                \
266     {                                                                           \
267       if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel)			\
268         {                                                                       \
269 	   fputs (ASM_LONG, FILE);                                              \
270 	   assemble_name (FILE, XSTR (ADDR, 0));				\
271 	   fputs ("+4@GOTPCREL", FILE);                                         \
272 	   goto DONE;                                                           \
273         }									\
274     }										\
275   else                                                                          \
276     {										\
277       if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1))                      \
278         {                                                                       \
279           darwin_non_lazy_pcrel (FILE, ADDR);                                   \
280           goto DONE;								\
281         }                                                                       \
282     }
283 
284 /* This needs to move since i386 uses the first flag and other flags are
285    used in Mach-O.  */
286 #undef MACHO_SYMBOL_FLAG_VARIABLE
287 #define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3)
288 
289 #undef MACHOPIC_NL_SYMBOL_PTR_SECTION
290 #define MACHOPIC_NL_SYMBOL_PTR_SECTION \
291 		".section __IMPORT,__pointers,non_lazy_symbol_pointers"
292 
293 #define SUBTARGET32_DEFAULT_CPU "i686"
294 
295 #undef  SUBTARGET_INIT_BUILTINS
296 #define SUBTARGET_INIT_BUILTINS					\
297 do {								\
298   ix86_builtins[(int) IX86_BUILTIN_CFSTRING]			\
299     = darwin_init_cfstring_builtins ((unsigned) (IX86_BUILTIN_CFSTRING));	\
300   darwin_rename_builtins ();					\
301 } while(0)
302