]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/i386/darwin.h
Update copyright years.
[thirdparty/gcc.git] / gcc / config / i386 / darwin.h
CommitLineData
b069de3b 1/* Target definitions for x86 running Darwin.
83ffe9cd 2 Copyright (C) 2001-2023 Free Software Foundation, Inc.
b069de3b
SS
3 Contributed by Apple Computer Inc.
4
7ec022b2 5This file is part of GCC.
b069de3b 6
7ec022b2 7GCC is free software; you can redistribute it and/or modify
b069de3b 8it under the terms of the GNU General Public License as published by
2f83c7d6 9the Free Software Foundation; either version 3, or (at your option)
b069de3b
SS
10any later version.
11
7ec022b2 12GCC is distributed in the hope that it will be useful,
b069de3b
SS
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
2f83c7d6
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
b069de3b
SS
20
21/* Enable Mach-O bits in generic x86 code. */
22#undef TARGET_MACHO
23#define TARGET_MACHO 1
24
fee3eacd
IS
25#undef DARWIN_X86
26#define DARWIN_X86 1
27
64ee9490
EC
28/* Size of the Obj-C jump buffer. */
29#define OBJC_JBLEN ((TARGET_64BIT) ? ((9 * 2) + 3 + 16) : (18))
30
004d3859
GK
31#undef TARGET_FPMATH_DEFAULT
32#define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
d6cfb47f
UB
33#undef TARGET_FPMATH_DEFAULT_P
34#define TARGET_FPMATH_DEFAULT_P(x) \
35 (TARGET_SSE_P(x) ? FPMATH_SSE : FPMATH_387)
004d3859 36
b069de3b 37#define TARGET_OS_CPP_BUILTINS() \
d6cfb47f
UB
38 do { \
39 builtin_define ("__LITTLE_ENDIAN__"); \
40 darwin_cpp_builtins (pfile); \
41 } while (0)
b069de3b 42
f7288899
EC
43#undef PTRDIFF_TYPE
44#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
45
46#undef WCHAR_TYPE
47#define WCHAR_TYPE "int"
48
49#undef WCHAR_TYPE_SIZE
50#define WCHAR_TYPE_SIZE 32
51
ce3a2015 52/* Generate pic symbol indirection stubs if this is true. */
d308419c
IS
53#undef TARGET_MACHO_SYMBOL_STUBS
54#define TARGET_MACHO_SYMBOL_STUBS (darwin_symbol_stubs)
9005471b 55
fee3eacd 56/* For compatibility with OSX system tools, use the new style of pic stub
ce3a2015 57 if this is set (default). */
fee3eacd
IS
58#undef MACHOPIC_ATT_STUB
59#define MACHOPIC_ATT_STUB (darwin_macho_att_stub)
60
f7288899
EC
61#undef MAX_BITS_PER_WORD
62#define MAX_BITS_PER_WORD 64
63
7d072037
SH
64#undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
65#define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
66
ebff937c
SH
67#undef TARGET_KEEPS_VECTOR_ALIGNED_STACK
68#define TARGET_KEEPS_VECTOR_ALIGNED_STACK 1
69
2734e1c3
GK
70/* On Darwin, the stack is 128-bit aligned at the point of every call.
71 Failure to ensure this will lead to a crash in the system libraries
72 or dynamic loader. */
2734e1c3 73
24f9c418
L
74#undef MAIN_STACK_BOUNDARY
75#define MAIN_STACK_BOUNDARY 128
76
ab47d43e
EC
77/* Since we'll never want a stack boundary less aligned than 128 bits
78 we need the extra work here otherwise bits of gcc get very grumpy
79 when we ask for lower alignment. We could just reject values less
80 than 128 bits for Darwin, but it's easier to up the alignment if
81 it's below the minimum. */
82#undef PREFERRED_STACK_BOUNDARY
d6cfb47f 83#define PREFERRED_STACK_BOUNDARY \
a0766cdb 84 MAX (128, ix86_preferred_stack_boundary)
ab47d43e 85
b069de3b
SS
86/* We want -fPIC by default, unless we're using -static to compile for
87 the kernel or some such. */
88
89#undef CC1_SPEC
0e7f6131
AP
90#define CC1_SPEC "%(cc1_cpu) \
91 %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
c76ea1b8 92 %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \
aa992ce7
IS
93 %{mx32:%eDarwin is not an mx32 platform} \
94 %{mfentry*:%eDarwin does not support -mfentry or associated options}" \
2be55a25 95 DARWIN_CC1_SPEC
b069de3b 96
743b8dd6
IS
97/* This is a workaround for a tool bug: see PR100340. */
98
99#ifdef HAVE_AS_MLLVM_X86_PAD_FOR_ALIGN
353cb291 100#define EXTRA_ASM_OPTS " -mllvm -x86-pad-for-align=false "
743b8dd6
IS
101#else
102#define EXTRA_ASM_OPTS ""
103#endif
104
a56cd1a9 105#undef ASM_SPEC
353cb291
IS
106#define ASM_SPEC \
107"%{static} -arch %(darwin_arch) " \
108 ASM_OPTIONS ASM_MMACOSX_VERSION_MIN_SPEC EXTRA_ASM_OPTS \
109"%{!force_cpusubtype_ALL:-force_cpusubtype_ALL} "
f7288899 110
1d2b1d91
EC
111#undef ENDFILE_SPEC
112#define ENDFILE_SPEC \
0691dde9 113 "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
1d2b1d91
EC
114 %{mpc32:crtprec32.o%s} \
115 %{mpc64:crtprec64.o%s} \
6c59ffd1 116 %{mpc80:crtprec80.o%s}" TM_DESTRUCTOR
1d2b1d91 117
d07092a6 118#ifndef DARWIN_ARCH_SPEC
e3461674 119/* We default to x86_64 for single-arch builds, bi-arch overrides. */
000a0020 120#define DARWIN_ARCH_SPEC "x86_64"
d07092a6
IS
121#define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
122#endif
000a0020 123
3a7e8b87 124#undef SUBTARGET_EXTRA_SPECS
f7288899 125#define SUBTARGET_EXTRA_SPECS \
742163c0 126 DARWIN_EXTRA_SPECS \
000a0020 127 { "darwin_arch", DARWIN_ARCH_SPEC }, \
f7288899 128 { "darwin_crt2", "" }, \
000a0020 129 { "darwin_subarch", DARWIN_ARCH_SPEC },
3a7e8b87 130
b069de3b
SS
131/* The Darwin assembler mostly follows AT&T syntax. */
132#undef ASSEMBLER_DIALECT
133#define ASSEMBLER_DIALECT ASM_ATT
134
135/* Define macro used to output shift-double opcodes when the shift
136 count is in %cl. Some assemblers require %cl as an argument;
137 some don't. This macro controls what to do: by default, don't
138 print %cl. */
139
140#define SHIFT_DOUBLE_OMITS_COUNT 0
141
7d072037 142#undef TARGET_ASM_FILE_END
6d217c32 143#define TARGET_ASM_FILE_END darwin_file_end
7d072037 144
b069de3b
SS
145/* Define the syntax of pseudo-ops, labels and comments. */
146
147/* String containing the assembler's comment-starter. */
148
149#define ASM_COMMENT_START "#"
150
151/* By default, target has a 80387, uses IEEE compatible arithmetic,
152 and returns float values in the 387. */
153
b42f4d62 154#undef TARGET_SUBTARGET_DEFAULT
d6cfb47f
UB
155#define TARGET_SUBTARGET_DEFAULT \
156 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
b069de3b 157
7a1eca83
EC
158/* For darwin we want to target specific processor features as a minimum,
159 but these unfortunately don't correspond to a specific processor. */
160#undef TARGET_SUBTARGET32_ISA_DEFAULT
d6cfb47f
UB
161#define TARGET_SUBTARGET32_ISA_DEFAULT \
162 (OPTION_MASK_ISA_MMX | OPTION_MASK_ISA_SSE \
163 | OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE3)
7a1eca83 164
746ecbcd
L
165#undef TARGET_SUBTARGET64_ISA_DEFAULT
166#define TARGET_SUBTARGET64_ISA_DEFAULT TARGET_SUBTARGET32_ISA_DEFAULT
167
7d072037 168#undef GOT_SYMBOL_NAME
08a6a74b 169#define GOT_SYMBOL_NAME MACHOPIC_FUNCTION_BASE_NAME
7d072037 170
b069de3b
SS
171/* Define the syntax of pseudo-ops, labels and comments. */
172
173#define LPREFIX "L"
174
b069de3b
SS
175/* Assembler pseudos to introduce constants of various size. */
176
e61c6562 177#define ASM_BYTE "\t.byte\t"
b069de3b
SS
178#define ASM_SHORT "\t.word\t"
179#define ASM_LONG "\t.long\t"
f7288899 180#define ASM_QUAD "\t.quad\t"
b069de3b 181
5a2d4de0
AP
182#define SUBTARGET_ENCODE_SECTION_INFO darwin_encode_section_info
183
b069de3b 184#undef ASM_OUTPUT_ALIGN
d6cfb47f
UB
185#define ASM_OUTPUT_ALIGN(FILE,LOG) \
186 do { \
187 if ((LOG) != 0) \
188 { \
189 if (in_section == text_section) \
190 fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
191 else \
192 fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
193 } \
194 } while (0)
b069de3b 195
d590d99a
IS
196/* Darwin x86 assemblers support the .ident directive. */
197
198#undef TARGET_ASM_OUTPUT_IDENT
199#define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive
200
85e10e4f
IS
201/* We always want jump tables in the text section:
202 * for PIC code, we need the subtracted symbol to be defined at
203 assembly-time.
204 * for mdynamic-no-pic, we cannot support jump tables in the .const
205 section for weak functions, this looks to ld64 like direct access
206 to the weak symbol from an anonymous atom. */
207
208#undef JUMP_TABLES_IN_TEXT_SECTION
209#define JUMP_TABLES_IN_TEXT_SECTION 1
210
95cc59f1
IS
211/* Darwin profiling -- call mcount.
212 If we need a stub, then we unconditionally mark it as used. */
b069de3b
SS
213#undef FUNCTION_PROFILER
214#define FUNCTION_PROFILER(FILE, LABELNO) \
d6cfb47f 215 do { \
d308419c 216 if (TARGET_MACHO_SYMBOL_STUBS \
d6cfb47f
UB
217 && MACHOPIC_INDIRECT && !TARGET_64BIT) \
218 { \
219 const char *name = machopic_mcount_stub_name (); \
220 fprintf (FILE, "\tcall %s\n", name+1); /* skip '&' */ \
d6cfb47f
UB
221 } \
222 else fprintf (FILE, "\tcall mcount\n"); \
223 } while (0)
7405f03c 224
f475fd3c
MS
225#define C_COMMON_OVERRIDE_OPTIONS \
226 do { \
227 SUBTARGET_C_COMMON_OVERRIDE_OPTIONS; \
228 } while (0)
229
fee3eacd 230#undef SUBTARGET_OVERRIDE_OPTIONS
d6cfb47f
UB
231#define SUBTARGET_OVERRIDE_OPTIONS \
232 do { \
233 if (TARGET_64BIT && MACHO_DYNAMIC_NO_PIC_P) \
234 target_flags &= ~MASK_MACHO_DYNAMIC_NO_PIC; \
235 } while (0)
fee3eacd 236
7405f03c
GK
237/* Darwin uses the standard DWARF register numbers but the default
238 register numbers for STABS. Fortunately for 64-bit code the
239 default and the standard are the same. */
ca60bd93
ML
240#undef DEBUGGER_REGNO
241#define DEBUGGER_REGNO(n) \
242 (TARGET_64BIT ? debugger64_register_map[n] \
243 : dwarf_debuginfo_p () ? svr4_debugger_register_map[n] \
244 : debugger_register_map[n])
6070e8e5
GK
245
246/* Unfortunately, the 32-bit EH information also doesn't use the standard
247 DWARF register numbers. */
248#define DWARF2_FRAME_REG_OUT(n, for_eh) \
66168f96 249 (! (for_eh) || !dwarf_debuginfo_p () || TARGET_64BIT ? (n) \
6070e8e5
GK
250 : (n) == 5 ? 4 \
251 : (n) == 4 ? 5 \
252 : (n) >= 11 && (n) <= 18 ? (n) + 1 \
253 : (n))
31abac07 254
ab442df7
MM
255#undef REGISTER_SUBTARGET_PRAGMAS
256#define REGISTER_SUBTARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
16d6f994
EC
257
258#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
259#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
2e71a7a3 260
f7288899
EC
261/* For 64-bit, we need to add 4 because @GOTPCREL is relative to the
262 end of the instruction, but without the 4 we'd only have the right
263 address for the start of the instruction. */
264#undef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
d6cfb47f
UB
265#define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE) \
266 if (TARGET_64BIT) \
267 { \
268 if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel) \
269 { \
270 fputs (ASM_LONG, FILE); \
271 assemble_name (FILE, XSTR (ADDR, 0)); \
272 fputs ("+4@GOTPCREL", FILE); \
273 goto DONE; \
274 } \
275 } \
276 else \
277 { \
278 if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) \
279 { \
280 darwin_non_lazy_pcrel (FILE, ADDR); \
281 goto DONE; \
282 } \
f7288899
EC
283 }
284
2161a445
IS
285/* First available SYMBOL flag bit for use by subtargets. */
286#define SYMBOL_FLAG_SUBT_DEP (SYMBOL_FLAG_MACH_DEP << 5)
4dd9ee92 287
fee3eacd
IS
288#undef MACHOPIC_NL_SYMBOL_PTR_SECTION
289#define MACHOPIC_NL_SYMBOL_PTR_SECTION \
290 ".section __IMPORT,__pointers,non_lazy_symbol_pointers"
291
4dd9ee92 292#define SUBTARGET32_DEFAULT_CPU "i686"
26705988
IS
293
294#undef SUBTARGET_INIT_BUILTINS
d6cfb47f
UB
295#define SUBTARGET_INIT_BUILTINS \
296 do { \
297 ix86_builtins[(int) IX86_BUILTIN_CFSTRING] \
13ec6724
IS
298 = darwin_init_cfstring_builtins ((unsigned) (IX86_BUILTIN_CFSTRING)); \
299 darwin_rename_builtins (); \
300 } while(0)
d730fd95
AT
301
302/* Define the shadow offset for asan. */
303#undef SUBTARGET_SHADOW_OFFSET
304#define SUBTARGET_SHADOW_OFFSET \
305 (TARGET_LP64 ? HOST_WIDE_INT_1 << 44 : HOST_WIDE_INT_1 << 29)
fc3e9f58
IS
306
307#undef CLEAR_INSN_CACHE
308#define CLEAR_INSN_CACHE(beg, end) \
309 extern void sys_icache_invalidate(void *start, size_t len); \
310 sys_icache_invalidate ((beg), (size_t)((end)-(beg)))