]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/darwin.h
Update copyright years.
[thirdparty/gcc.git] / gcc / config / darwin.h
CommitLineData
ee890fe2 1/* Target definitions for Darwin (Mac OS X) systems.
aeee4812 2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
ee890fe2
SS
3 Contributed by Apple Computer Inc.
4
7ec022b2 5This file is part of GCC.
ee890fe2 6
7ec022b2 7GCC is free software; you can redistribute it and/or modify
ee890fe2 8it under the terms of the GNU General Public License as published by
748086b7 9the Free Software Foundation; either version 3, or (at your option)
ee890fe2
SS
10any later version.
11
7ec022b2 12GCC is distributed in the hope that it will be useful,
ee890fe2
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
748086b7
JJ
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
ee890fe2 25
213c4a8a
GK
26#ifndef CONFIG_DARWIN_H
27#define CONFIG_DARWIN_H
28
ee890fe2
SS
29/* The definitions in this file are common to all processor types
30 running Darwin, which is the kernel for Mac OS X. Darwin is
31 basically a BSD user layer laid over a Mach kernel, then evolved
32 for many years (at NeXT) in parallel with other Unix systems. So
33 while the runtime is a somewhat idiosyncratic Mach-based thing,
34 other definitions look like they would for a BSD variant. */
35
36/* Although NeXT ran on many different architectures, as of Jan 2001
37 the only supported Darwin targets are PowerPC and x86. */
38
7606e68f
SS
39/* One of Darwin's NeXT legacies is the Mach-O format, which is partly
40 like a.out and partly like COFF, with additional features like
41 multi-architecture binary support. */
42
fee3eacd
IS
43#define DARWIN_X86 0
44#define DARWIN_PPC 0
7606e68f 45
9a4a29ea
IS
46#define OBJECT_FORMAT_MACHO 1
47
d42093a1 48/* Suppress g++ attempt to link in the math library automatically. */
abe72dd8 49#define MATH_LIBRARY ""
ee890fe2
SS
50
51/* We have atexit. */
52
53#define HAVE_ATEXIT
54
55/* Define an empty body for the function do_global_dtors() in libgcc2.c. */
56
57#define DO_GLOBAL_DTORS_BODY
58
fabe8cc4
IS
59/* Register static destructors to run from __cxa_atexit instead of putting
60 them into a .mod_term_funcs section. */
61
62#define TARGET_DTORS_FROM_CXA_ATEXIT true
63
ee890fe2
SS
64/* The string value for __SIZE_TYPE__. */
65
66#ifndef SIZE_TYPE
67#define SIZE_TYPE "long unsigned int"
68#endif
69
70/* Type used for ptrdiff_t, as a string used in a declaration. */
71
72#undef PTRDIFF_TYPE
73#define PTRDIFF_TYPE "int"
74
75/* wchar_t is int. */
76
77#undef WCHAR_TYPE
78#define WCHAR_TYPE "int"
79#undef WCHAR_TYPE_SIZE
80#define WCHAR_TYPE_SIZE 32
81
428ddbf0
FXC
82#define INT8_TYPE "signed char"
83#define INT16_TYPE "short int"
84#define INT32_TYPE "int"
85#define INT64_TYPE "long long int"
86#define UINT8_TYPE "unsigned char"
87#define UINT16_TYPE "short unsigned int"
88#define UINT32_TYPE "unsigned int"
89#define UINT64_TYPE "long long unsigned int"
90
91#define INT_LEAST8_TYPE "signed char"
92#define INT_LEAST16_TYPE "short int"
93#define INT_LEAST32_TYPE "int"
94#define INT_LEAST64_TYPE "long long int"
95#define UINT_LEAST8_TYPE "unsigned char"
96#define UINT_LEAST16_TYPE "short unsigned int"
97#define UINT_LEAST32_TYPE "unsigned int"
98#define UINT_LEAST64_TYPE "long long unsigned int"
99
100#define INT_FAST8_TYPE "signed char"
101#define INT_FAST16_TYPE "short int"
102#define INT_FAST32_TYPE "int"
103#define INT_FAST64_TYPE "long long int"
104#define UINT_FAST8_TYPE "unsigned char"
105#define UINT_FAST16_TYPE "short unsigned int"
106#define UINT_FAST32_TYPE "unsigned int"
107#define UINT_FAST64_TYPE "long long unsigned int"
108
109#define INTPTR_TYPE "long int"
110#define UINTPTR_TYPE "long unsigned int"
111
112#define SIG_ATOMIC_TYPE "int"
113
f37f462a
SS
114/* Default to using the NeXT-style runtime, since that's what is
115 pre-installed on Darwin systems. */
116
75d4d7bc 117#define NEXT_OBJC_RUNTIME 100508
f37f462a 118
ee890fe2
SS
119/* Don't default to pcc-struct-return, because gcc is the only compiler, and
120 we want to retain compatibility with older gcc versions. */
121
122#undef DEFAULT_PCC_STRUCT_RETURN
123#define DEFAULT_PCC_STRUCT_RETURN 0
124
4f8bdef9
EC
125/* True if pragma ms_struct is in effect. */
126extern GTY(()) int darwin_ms_struct;
127
353cb291
IS
128/* Darwin has a user convenience feature where some linker options are exposed
129 at the driver level (so one can type "-all_load" instead of "-Wl,-all_load"
130 or "-Xlinker -all_load"). We retain this, but now these options are all
131 marked as 'Driver' and we process them as early as possible so that they
132 get allocated to the right toolchain command. There are a couple of special
133 cases where these driver opts are used multiple times, or to control
134 operations on more than one command (e.g. dynamiclib). These are handled
135 specially and we then add %<xxxx specs for the commands that _don't_ need
136 them. NOTE: the order of 'shared' and 'dynamiclib' is significant, hence
137 they are placed out of alphabetical order at the start. Likewise, we keep
138 a couple of cases where a negative option originally appeared after the
139 positive alternate, potentially overriding it.
140 When we report an error with %e, it seems necessary to strip the option
141 before doing so, otherwise it survives to the cc1 command line (%e doesn't
142 appear to abort the program before this).
143 Right now there's no mechanism to split up the "variable portion" (%*) of
144 the matched spec string, so where we have some driver specs that take 2
145 or 3 arguments, these cannot be processed here, but are deferred until the
79473797 146 LINK_SPEC, where they are copied verbatim. */
db67ea0f 147
98ae96d2
PB
148#undef SUBTARGET_DRIVER_SELF_SPECS
149#define SUBTARGET_DRIVER_SELF_SPECS \
353cb291
IS
150 "%{shared:%{!dynamiclib:-dynamiclib}} %<shared", \
151 "%{static:%{dynamic|dynamiclib:%econflicting code generation switches}}",\
152 "%{dynamiclib:-Xlinker -dylib \
153 %{allowable_client*:-Xlinker -allowable_client -Xlinker %*} \
154 %<allowable_client* \
155 %{bundle_loader*: %<bundle_loader* \
156 %e-bundle_loader not allowed with -dynamiclib} \
157 %{client_name*: %<client_name* \
158 %e-client_name not allowed with -dynamiclib} \
159 %{compatibility_version*:\
160 -Xlinker -dylib_compatibility_version -Xlinker %*} \
161 %<compatibility_version* \
162 %{current_version*:-Xlinker -dylib_current_version -Xlinker %*} \
163 %<current_version* \
164 %{install_name*:-Xlinker -dylib_install_name -Xlinker %* } \
165 %<install_name* \
166 %{keep_private_externs: %<keep_private_externs \
167 %e-keep_private_externs not allowed with -dynamiclib} \
168 %{private_bundle: %<private_bundle \
169 %e-private_bundle not allowed with -dynamiclib} \
170 }", \
171 "%{!dynamiclib: \
172 %{bundle_loader*:-Xlinker -bundle_loader -Xlinker %*} \
173 %<bundle_loader* \
174 %{client_name*:-Xlinker -client_name -Xlinker %*} \
175 %<client_name* \
176 %{compatibility_version*: %<compatibility_version* \
177 %e-compatibility_version only allowed with -dynamiclib} \
178 %{current_version*: %<current_version* \
179 %e-current_version only allowed with -dynamiclib} \
180 %{install_name*: %<install_name* \
181 %e-install_name only allowed with -dynamiclib} \
182 %{keep_private_externs:-Xlinker -keep_private_externs} \
183 %<keep_private_externs \
184 %{private_bundle:-Xlinker -private_bundle} \
185 %<private_bundle \
186 }", \
187 "%{all_load:-Xlinker -all_load} %<all_load", \
188 "%{arch_errors_fatal:-Xlinker -arch_errors_fatal} \
189 %<arch_errors_fatal", \
190 "%{bind_at_load:-Xlinker -bind_at_load} %<bind_at_load", \
191 "%{bundle:%{!dynamiclib:-Xlinker -bundle; \
192 :%e-bundle not allowed with -dynamiclib}}", \
193 "%{dead_strip:-Xlinker -dead_strip} %<dead_strip", \
194 "%{dylib_file*:-Xlinker -dylib_file -Xlinker %*} %<dylib_file*", \
195 "%{dylinker:-Xlinker -dylinker} %<dylinker", \
196 "%{dylinker_install_name*:-Xlinker -dylinker_install_name -Xlinker %*}\
197 %<dylinker_install_name*", \
198 "%{exported_symbols_list*:-Xlinker -exported_symbols_list -Xlinker %*}\
199 %<exported_symbols_list", \
200 "%{findirect-virtual-calls: -fapple-kext} %<findirect-virtual-calls", \
201 "%{fterminated-vtables: -fapple-kext} %<fterminated-vtables", \
202 "%{fapple-kext|mkernel:-static}", \
203 "%{filelist*:-Xlinker -filelist -Xlinker %*} %<filelist*", \
204 "%{flat_namespace:-Xlinker -flat_namespace} %<flat_namespace", \
205 "%{force_cpusubtype_ALL:-Xassembler -force_cpusubtype_ALL} ", \
206 "%{force_flat_namespace: \
207 %{!dynamiclib:-Xlinker -force_flat_namespace; \
208 :%e-force_flat_namespace not allowed with -dynamiclib}} \
209 %<force_flat_namespace", \
210 "%{framework*:-Xlinker -framework -Xlinker %*} %<framework*", \
211 "%{gfull:-g -fno-eliminate-unused-debug-symbols} %<gfull", \
212 "%{gused:-g -feliminate-unused-debug-symbols} %<gused", \
213 "%{gsplit-dwarf:%ngsplit-dwarf is not supported on this platform} \
214 %<gsplit-dwarf", \
215 "%{headerpad_max_install_names:-Xlinker -headerpad_max_install_names}\
216 %<headerpad_max_install_names", \
217 "%{image_base*:-Xlinker -image_base -Xlinker %*} %<image_base*", \
218 "%{init*:-Xlinker -init -Xlinker %*} %<init*", \
219 "%{multi_module:-Xlinker -multi_module} %<multi_module", \
79473797
IS
220 "%{multiply_defined*:-Xlinker -multiply_defined -Xlinker %*} \
221 %<multiply_defined* ", \
353cb291
IS
222 "%{multiplydefinedunused*:\
223 -Xlinker -multiply_defined_unused -Xlinker %*} \
224 %<multiplydefinedunused* ", \
225 "%{no_dead_strip_inits_and_terms:\
226 -Xlinker -no_dead_strip_inits_and_terms} \
227 %<no_dead_strip_inits_and_terms", \
228 "%{nofixprebinding:-Xlinker -nofixprebinding} %<nofixprebinding", \
229 "%{nomultidefs:-Xlinker -nomultidefs} %<nomultidefs", \
230 "%{pagezero_size*:-Xlinker -pagezero_size -Xlinker %*} \
231 %<pagezero_size", \
232 "%{prebind:-Xlinker -prebind} %<prebind", \
233 "%{noprebind:-Xlinker -noprebind} %<noprebind", \
234 "%{prebind_all_twolevel_modules:\
235 -Xlinker -prebind_all_twolevel_modules} \
236 %<prebind_all_twolevel_modules", \
237 "%{preload:-Xlinker -preload} %<preload", \
238 "%{read_only_relocs*:-Xlinker -read_only_relocs -Xlinker %*} \
239 %<read_only_relocs*", \
240 "%{rpath*: -Xlinker -rpath -Xlinker %*}", \
241 "%{seg_addr_table_filename*: \
242 -Xlinker -seg_addr_table_filename -Xlinker %*} \
243 %<seg_addr_table_filename*", \
244 "%{seg_addr_table*:-Xlinker -seg_addr_table -Xlinker %*} \
245 %<seg_addr_table*", \
246 "%{seg1addr*:-Xlinker -image_base -Xlinker %*} %<seg1addr*", \
247 "%{seglinkedit:-Xlinker -seglinkedit} %<seglinkedit", \
248 "%{noseglinkedit:-Xlinker -noseglinkedit} %<noseglinkedit", \
249 "%{segs_read_only_addr*:-Xlinker -segs_read_only_addr -Xlinker %*} \
250 %<segs_read_only_addr*", \
251 "%{segs_read_write_addr*:-Xlinker -segs_read_write_addr -Xlinker %*} \
252 %<segs_read_write_addr*", \
253 "%{single_module:-Xlinker -single_module} %<single_module", \
254 "%{sub_library*:-Xlinker -sub_library -Xlinker %*} %<sub_library*", \
255 "%{sub_umbrella*:-Xlinker -sub_umbrella -Xlinker %*} %<sub_umbrella*",\
256 "%{twolevel_namespace:-Xlinker -twolevel_namespace} \
257 %<twolevel_namespace", \
258 "%{twolevel_namespace_hints:-Xlinker -twolevel_namespace_hints} \
259 %<twolevel_namespace_hints", \
260 "%{umbrella*:-Xlinker -umbrella -Xlinker %*} %<umbrella*", \
261 "%{undefined*:-Xlinker -undefined -Xlinker %*} %<undefined*", \
262 "%{unexported_symbols_list*:\
263 -Xlinker -unexported_symbols_list -Xlinker %*} \
264 %<unexported_symbols_list*", \
353cb291
IS
265 "%{weak_reference_mismatches*:\
266 -Xlinker -weak_reference_mismatches -Xlinker %*} \
267 %<weak_reference_mismatches*", \
268 "%{whyload:-Xlinker -whyload} %<whyload", \
269 "%{whatsloaded:-Xlinker -whatsloaded} %<whatsloaded", \
270 "%{w:-Xlinker -w}", \
271 "%<y*", \
272 "%<Mach "
14fef000
IS
273
274#if LD64_HAS_EXPORT_DYNAMIC
03eddfb3 275#define DARWIN_RDYNAMIC "%{rdynamic:-export_dynamic}"
14fef000 276#else
03eddfb3 277#define DARWIN_RDYNAMIC "%{rdynamic:%nrdynamic is not supported}"
14fef000
IS
278#endif
279
1c1563fb
IS
280/* Code built with mdynamic-no-pic does not support PIE/PIC, so we disallow
281 these combinations; we also ensure that the no_pie option is passed to
282 ld64 on system versions that default to PIE when mdynamic-no-pic is given.
283 FIXME: we should check that the linker supports the -pie and -no_pie.
14fef000
IS
284 options. */
285#define DARWIN_PIE_SPEC \
03eddfb3 286"%{pie|fpie|fPIE:\
14fef000 287 %{mdynamic-no-pic: \
03eddfb3 288 %n'-mdynamic-no-pic' overrides '-pie', '-fpie' or '-fPIE'; \
1c1563fb
IS
289 :%:version-compare(>= 10.5 mmacosx-version-min= -pie) }; \
290 mdynamic-no-pic:%:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } "
14fef000
IS
291
292#define DARWIN_NOPIE_SPEC \
293"%{no-pie|fno-pie|fno-PIE: \
03eddfb3 294 %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) }"
dd2e44f0
IS
295
296#define DARWIN_CC1_SPEC \
353cb291 297 "%<dynamic %<dynamiclib %<force_cpusubtype_ALL "
dd2e44f0
IS
298
299#define SUBSUBTARGET_OVERRIDE_OPTIONS \
300 do { \
301 darwin_override_options (); \
302 } while (0)
303
304#define SUBTARGET_C_COMMON_OVERRIDE_OPTIONS do { \
dd2e44f0
IS
305 if (flag_mkernel || flag_apple_kext) \
306 { \
307 if (flag_use_cxa_atexit == 2) \
308 flag_use_cxa_atexit = 0; \
309 /* kexts should always be built without the coalesced sections \
310 because the kernel loader doesn't grok such sections. */ \
311 flag_weak = 0; \
312 /* No RTTI in kexts. */ \
313 flag_rtti = 0; \
314 } \
315 } while (0)
f475fd3c 316
ed5b9f96 317/* Machine dependent cpp options. Don't add more options here, add
e53b6e56 318 them to darwin_cpp_builtins in darwin-c.cc. */
ee890fe2 319
ee890fe2 320#undef CPP_SPEC
dd2e44f0 321#define CPP_SPEC "%{static:%{!dynamic:-D__STATIC__}}%{!static:-D__DYNAMIC__}" \
353cb291 322 " %{pthread:-D_REENTRANT} "
ee890fe2 323
14fef000
IS
324/* This is a fix for PR41260 by passing -no_compact_unwind on darwin10 and
325 later until the assembler, linker and libunwind are able to deal with the
326 output from GCC.
327
328 FIXME: we should check that the linker supports the option.
329*/
330
331#define DARWIN_NOCOMPACT_UNWIND \
332" %:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) "
333
179c7ef5 334/* In Darwin linker specs we can put -lcrt0.o and ld will search the library
027e3041 335 path for crt0.o or -lcrtx.a and it will search for libcrtx.a. As for
179c7ef5
IS
336 other ports, we can also put xxx.{o,a}%s and get the appropriate complete
337 startfile absolute directory. This latter point is important when we want
338 to override ld's rule of .dylib being found ahead of .a and the user wants
339 the convenience library to be linked. */
340
341/* The LINK_COMMAND spec is mostly a clone of the standard LINK_COMMAND_SPEC,
342 plus precomp, libtool, and fat build additions.
7f814c0b
IS
343
344 In general, random Darwin linker flags should go into LINK_SPEC
48aec0bc
DP
345 instead of LINK_COMMAND_SPEC. The command spec is better for
346 specifying the handling of options understood by generic Unix
347 linkers, and for positional arguments like libraries. */
50eb566f 348
dd2e44f0 349#define LINK_COMMAND_SPEC_A \
4aef14b0 350 "%{!c:%{!E:%{!S:%{!M:%{!MM:%{!fsyntax-only:%{!fdump=*: \
dd350eba
RO
351 %(linker)" \
352 LINK_PLUGIN_SPEC \
353 "%{flto*:%<fcompare-debug*} \
257d10b5 354 %{flto} %{fno-lto} %{flto=*} \
29d7cbd1
RO
355 %l " LINK_COMPRESS_DEBUG_SPEC \
356 "%X %{s} %{t} %{Z} %{u*} \
dd2e44f0
IS
357 %{e*} %{r} \
358 %{o*}%{!o:-o a.out} \
4aef14b0
IS
359 %{!r:%{!nostdlib:%{!nostartfiles:%S}}} \
360 %{L*} %(link_libgcc) %o \
361 %{!r:%{!nostdlib:%{!nodefaultlibs:\
362 %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \
363 %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): \
364 %{static|static-libgcc|static-libstdc++|static-libgfortran: \
365 libgomp.a%s; : -lgomp }} \
366 %{fgnu-tm: \
367 %{static|static-libgcc|static-libstdc++|static-libgfortran: \
368 libitm.a%s; : -litm }} \
0cea211e
IS
369 %{%:sanitize(address): -lasan } \
370 %{%:sanitize(undefined): -lubsan } \
eb89c82f 371 %(link_ssp) \
87385438 372 %:version-compare(>< 10.6 10.7 mmacosx-version-min= -ld10-uwfef) \
eb89c82f 373 %(link_gcc_c_sequence) \
d4943ce9
IS
374 %{!nodefaultexport:%{dylib|dynamiclib|bundle: \
375 %:version-compare(>= 10.11 asm_macosx_version_min= -U) \
376 %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_get_address) \
377 %:version-compare(>= 10.11 asm_macosx_version_min= -exported_symbol) \
378 %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_get_address) \
379 %:version-compare(>= 10.11 asm_macosx_version_min= -U) \
380 %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_register_common) \
381 %:version-compare(>= 10.11 asm_macosx_version_min= -exported_symbol) \
382 %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_register_common) \
383 }} \
0b7fb27b 384 }}}\
4aef14b0 385 %{!r:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*} "\
03eddfb3
IS
386 DARWIN_PIE_SPEC \
387 DARWIN_NOPIE_SPEC \
388 DARWIN_RDYNAMIC \
14fef000 389 DARWIN_NOCOMPACT_UNWIND \
15bdae01 390 "}}}}}}} %<pie %<no-pie %<rdynamic %<X %<rpath "
50eb566f 391
b2cee5e1
IS
392/* Spec that controls whether the debug linker is run automatically for
393 a link step. This needs to be done if there is a source file on the
394 command line which will result in a temporary object (and debug is
395 enabled). */
396
dd2e44f0 397#define DSYMUTIL_SPEC \
4aef14b0 398 "%{!c:%{!E:%{!S:%{!r:%{!M:%{!MM:%{!fsyntax-only:%{!fdump=*:\
7e0db0cd 399 %{g*:%{!gctf:%{!gbtf:%{%:debug-level-gt(0): -idsym \
4aef14b0
IS
400 %{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm|.s|.f|.f90|\
401 .f95|.f03|.f77|.for|.F|.F90|.F95|.F03|.d: -dsym }\
7e0db0cd 402 }}}}\
4aef14b0 403 }}}}}}}}"
50eb566f
IS
404
405#define LINK_COMMAND_SPEC LINK_COMMAND_SPEC_A DSYMUTIL_SPEC
48aec0bc 406
7e82085a 407/* Tell collect2 to run dsymutil for us as necessary. */
11afe8e8
MS
408#define COLLECT_RUN_DSYMUTIL 1
409
d4943ce9
IS
410/* We only want one instance of %G, since libSystem (Darwin's -lc) does not
411 depend on libgcc. */
7f814c0b 412#undef LINK_GCC_C_SEQUENCE_SPEC
89660774 413#define LINK_GCC_C_SEQUENCE_SPEC \
d4943ce9 414 "%G %{!nolibc:%L} "
7f814c0b 415
d42becb9
IS
416/* ld64 supports a sysroot, it just has a different name and there's no easy
417 way to check for it at config time. */
418#undef HAVE_LD_SYSROOT
419#define HAVE_LD_SYSROOT 1
420/* It seems the only (working) way to get a space after %R is to append a
421 dangling '/'. */
353cb291 422#define SYSROOT_SPEC "%{!isysroot*:-syslibroot %R/ } "
d42becb9
IS
423
424/* Do the same as clang, for now, and insert the sysroot for ld when an
425 isysroot is specified. */
353cb291 426#define LINK_SYSROOT_SPEC "%{isysroot*:-syslibroot %*} "
d42becb9
IS
427
428/* Suppress the addition of extra prefix paths when a sysroot is in use. */
429#define STANDARD_STARTFILE_PREFIX_1 ""
430#define STANDARD_STARTFILE_PREFIX_2 ""
9281e73d 431
353cb291
IS
432
433/* Please keep the random linker options in alphabetical order.
434 Note that options taking arguments may appear multiple times on a command
435 line with different arguments each time, so put a * after their names so
436 all of them get passed. */
dd2e44f0 437#define LINK_SPEC \
353cb291 438 "%{static}%{!static:%{!dynamic:-dynamic}} \
dd2e44f0
IS
439 %:remove-outfile(-ldl) \
440 %:remove-outfile(-lm) \
441 %:remove-outfile(-lpthread) \
442 %{fgnu-runtime: %{static|static-libgcc: \
443 %:replace-outfile(-lobjc libobjc-gnu.a%s); \
353cb291 444 :%:replace-outfile(-lobjc -lobjc-gnu )}}\
dd2e44f0 445 %{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran libgfortran.a%s)}\
745be54b 446 %{static|static-libgcc|static-libquadmath:%:replace-outfile(-lquadmath libquadmath.a%s)}\
185b307b 447 %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos libgphobos.a%s)}\
dd2e44f0
IS
448 %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp libgomp.a%s)}\
449 %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}\
dd77b049
IS
450 %{static|static-libgm2:%:replace-outfile(-lm2pim libm2pim.a%s)}\
451 %{static|static-libgm2:%:replace-outfile(-lm2iso libm2iso.a%s)}\
452 %{static|static-libgm2:%:replace-outfile(-lm2min libm2min.a%s)}\
453 %{static|static-libgm2:%:replace-outfile(-lm2log libm2log.a%s)}\
454 %{static|static-libgm2:%:replace-outfile(-lm2cor libm2cor.a%s)}\
455 %{force_cpusubtype_ALL:-arch %(darwin_arch)} \
353cb291
IS
456 %{!force_cpusubtype_ALL:-arch %(darwin_subarch)} "\
457 LINK_SYSROOT_SPEC \
458 "%{mmacosx-version-min=*:-macosx_version_min %*} \
79473797
IS
459 %{!multiply_defined*:%{shared-libgcc: \
460 %:version-compare(< 10.5 mmacosx-version-min= -multiply_defined) \
461 %:version-compare(< 10.5 mmacosx-version-min= suppress) }} \
353cb291
IS
462 %{sectalign*} %{sectcreate*} %{sectobjectsymbols*} %{sectorder*} \
463 %{segaddr*} %{segcreate*} %{segprot*} "
48aec0bc 464
ed5b9f96 465/* Machine dependent libraries. */
ee890fe2 466
5fa5a27c 467#define LIB_SPEC "%{!static:-lSystem}"
ee890fe2 468
65aebf19
IS
469/* Note that by default, -lgcc_eh (which provides a statically-linked unwinder)
470 is not used. This is because, in general, we need to unwind through system
471 libraries that are linked with the shared unwinder in libunwind (or libgcc_s
472 for OSX 10.4/5 [darwin8/9]).
56309261 473
65aebf19
IS
474 When -static-libgcc is forced: < 10.6, use the unwinder in libgcc_eh (and
475 find the emultls impl. there too).
d4943ce9
IS
476
477 For -static-libgcc: >= 10.6, the unwinder *still* comes from libSystem and
478 we find the emutls impl from lemutls_w. In either case, the builtins etc.
65aebf19
IS
479 are linked from -lgcc. The eh library is still available so that it could
480 be specified explicitly if there is some reason to do so.
d4943ce9
IS
481
482 When we have specified shared-libgcc or any case that might require
483 exceptions, we pull the libgcc content (including emulated tls) from
65aebf19 484 -lgcc_s.1.1 in GCC and the unwinder from /usr/lib/libgcc_s.1 for < 10.6 and
d4943ce9
IS
485 libSystem for >= 10.6 respectively.
486 Otherwise, we just link the emutls/builtins from convenience libs.
487
d4943ce9
IS
488 We have to work around that DYLD_XXXX are disabled in macOS 10.11+ which
489 means that any bootstrap trying to use a shared libgcc with a bumped SO-
490 name will fail. This means that we do not accept shared libgcc for these
65aebf19
IS
491 versions (the primary reason for forcing a shared libgcc was that it
492 contained the unwinder on Darwin8 and 9).
d4943ce9 493
65aebf19 494 When using the shared version of gcc_s.1.1 the unwinder is provided by:
d4943ce9 495 * Prior to 10.3.9, then we have to link the static eh lib, since there
65aebf19 496 is no shared unwinder version on the system.
d4943ce9
IS
497 * from 10.3.9 to 10.5, from /usr/lib/libgcc_s.1.dylib
498 * from 10.6 onwards, from libSystem.dylib
d4943ce9 499*/
040b1c5a 500#undef REAL_LIBGCC_SPEC
d4943ce9
IS
501#define REAL_LIBGCC_SPEC \
502"%{static-libgcc|static: \
503 %:version-compare(!> 10.6 mmacosx-version-min= -lgcc_eh) \
504 %:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w); \
505 shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \
506 %:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1) \
507 %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) \
508 %:version-compare(!> 10.3.9 mmacosx-version-min= -lgcc_eh) \
509 %:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \
510 %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5); \
511 : -lemutls_w \
512 } -lgcc "
083cad55 513
179c7ef5 514/* We specify crt0.o as -lcrt0.o so that ld will search the library path. */
ee890fe2 515
48aec0bc 516#undef STARTFILE_SPEC
dd2e44f0 517#define STARTFILE_SPEC \
353cb291
IS
518"%{dynamiclib: %(darwin_dylib1) %{fgnu-tm: -lcrttms.o}} \
519 %{!dynamiclib:%{bundle:%(darwin_bundle1)} \
520 %{!bundle:%{pg:%{static:-lgcrt0.o} \
dd2e44f0
IS
521 %{!static:%{object:-lgcrt0.o} \
522 %{!object:%{preload:-lgcrt0.o} \
3127f133
JH
523 %{!preload:-lgcrt1.o \
524 %:version-compare(>= 10.8 mmacosx-version-min= -no_new_main) \
525 %(darwin_crt2)}}}} \
dd2e44f0
IS
526 %{!pg:%{static:-lcrt0.o} \
527 %{!static:%{object:-lcrt0.o} \
528 %{!object:%{preload:-lcrt0.o} \
529 %{!preload: %(darwin_crt1) \
530 %(darwin_crt2)}}}}}} \
353cb291 531 %(darwin_crt3) %<dynamiclib "
7606e68f 532
e2362f5d 533/* We want a destructor last in the list. */
6c59ffd1
IS
534#define TM_DESTRUCTOR "%{fgnu-tm: -lcrttme.o}"
535#define ENDFILE_SPEC TM_DESTRUCTOR
ee890fe2 536
dd2e44f0
IS
537#define DARWIN_EXTRA_SPECS \
538 { "darwin_crt1", DARWIN_CRT1_SPEC }, \
179c7ef5
IS
539 { "darwin_crt2", DARWIN_CRT2_SPEC }, \
540 { "darwin_crt3", DARWIN_CRT3_SPEC }, \
4e62faf2
IS
541 { "darwin_dylib1", DARWIN_DYLIB1_SPEC }, \
542 { "darwin_bundle1", DARWIN_BUNDLE1_SPEC },
742163c0 543
dd2e44f0
IS
544#define DARWIN_CRT1_SPEC \
545 "%:version-compare(!> 10.5 mmacosx-version-min= -lcrt1.o) \
99b375d0 546 %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lcrt1.10.5.o) \
3127f133 547 %:version-compare(>< 10.6 10.8 mmacosx-version-min= -lcrt1.10.6.o) \
e2362f5d 548 %{fgnu-tm: -lcrttms.o}"
742163c0 549
179c7ef5
IS
550#define DARWIN_CRT2_SPEC ""
551
552/* crt3.o provides __cxa_atexit on systems that don't have it (and a fix
553 up for faulty versions on 10.4). Since it's only used with C++, which
554 requires passing -shared-libgcc, key off that to avoid unnecessarily
555 adding a destructor to every program built for 10.4 or earlier. */
556
557#define DARWIN_CRT3_SPEC \
558"%{shared-libgcc:%:version-compare(< 10.5 mmacosx-version-min= crt3.o%s)}"
559
560#define DARWIN_DYLIB1_SPEC \
561 "%:version-compare(!> 10.5 mmacosx-version-min= -ldylib1.o) \
562 %:version-compare(>< 10.5 10.6 mmacosx-version-min= -ldylib1.10.5.o)"
563
4e62faf2
IS
564#define DARWIN_BUNDLE1_SPEC \
565"%{!static:%:version-compare(< 10.6 mmacosx-version-min= -lbundle1.o) \
566 %{fgnu-tm: -lcrttms.o}}"
567
b410cf1d
IS
568#ifdef HAVE_AS_MMACOSX_VERSION_MIN_OPTION
569/* Emit macosx version (but only major). */
570#define ASM_MMACOSX_VERSION_MIN_SPEC \
353cb291
IS
571"%{asm_macosx_version_min=*: -mmacosx-version-min=%* } \
572 %<asm_macosx_version_min=* "
b410cf1d 573#else
353cb291 574#define ASM_MMACOSX_VERSION_MIN_SPEC " %<asm_macosx_version_min=* "
b410cf1d
IS
575#endif
576
b410cf1d 577#if HAVE_GNU_AS
e53b6e56 578/* The options are added in gcc.cc for this case. */
b410cf1d
IS
579#define ASM_OPTIONS ""
580#else
353cb291
IS
581/* When we detect that we're cctools or llvm as, we need to insert the right
582 additional options. Actually, currently these are the same as GAS. */
b410cf1d
IS
583#define ASM_OPTIONS "%{v} %{w:-W} %{I*}"
584#endif
585
586/* Default Darwin ASM_SPEC, very simple. */
353cb291
IS
587#define ASM_SPEC \
588"%{static} -arch %(darwin_arch) " \
589ASM_OPTIONS ASM_MMACOSX_VERSION_MIN_SPEC
c4e18b1c 590
b2cee5e1 591#define ASM_DEBUG_SPEC ""
b2cee5e1
IS
592#undef ASM_DEBUG_OPTION_SPEC
593#define ASM_DEBUG_OPTION_SPEC ""
594
c7a52e72 595#define ASM_FINAL_SPEC \
353cb291
IS
596 "%{gsplit-dwarf:%ngsplit-dwarf is not supported on this platform} \
597 %<gsplit-dwarf"
40353fb3 598
b2cee5e1
IS
599/* We now require C++11 to bootstrap and newer tools than those based on
600 stabs, so require DWARF-2, even if stabs is supported by the assembler. */
601
b2cee5e1 602#define DWARF2_DEBUGGING_INFO 1
c86de344 603#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
b2cee5e1 604
89bcf3ff
IS
605#define DEBUG_FRAME_SECTION "__DWARF,__debug_frame,regular,debug"
606#define DEBUG_INFO_SECTION "__DWARF,__debug_info,regular,debug"
607#define DEBUG_ABBREV_SECTION "__DWARF,__debug_abbrev,regular,debug"
608#define DEBUG_ARANGES_SECTION "__DWARF,__debug_aranges,regular,debug"
609#define DEBUG_MACINFO_SECTION "__DWARF,__debug_macinfo,regular,debug"
610#define DEBUG_LINE_SECTION "__DWARF,__debug_line,regular,debug"
611#define DEBUG_LOC_SECTION "__DWARF,__debug_loc,regular,debug"
612#define DEBUG_LOCLISTS_SECTION "__DWARF,__debug_loclists,regular,debug"
613
614#define DEBUG_STR_SECTION "__DWARF,__debug_str,regular,debug"
615#define DEBUG_STR_OFFSETS_SECTION "__DWARF,__debug_str_offs,regular,debug"
616#define DEBUG_RANGES_SECTION "__DWARF,__debug_ranges,regular,debug"
617#define DEBUG_RNGLISTS_SECTION "__DWARF,__debug_rnglists,regular,debug"
618#define DEBUG_MACRO_SECTION "__DWARF,__debug_macro,regular,debug"
1ea85365
RB
619
620#define DEBUG_LTO_INFO_SECTION "__GNU_DWARF_LTO,__debug_info,regular,debug"
621#define DEBUG_LTO_ABBREV_SECTION "__GNU_DWARF_LTO,__debug_abbrev,regular,debug"
622#define DEBUG_LTO_MACINFO_SECTION "__GNU_DWARF_LTO,__debug_macinfo,regular,debug"
623#define DEBUG_LTO_LINE_SECTION "__GNU_DWARF_LTO,__debug_line,regular,debug"
624#define DEBUG_LTO_STR_SECTION "__GNU_DWARF_LTO,__debug_str,regular,debug"
625#define DEBUG_LTO_MACRO_SECTION "__GNU_DWARF_LTO,__debug_macro,regular,debug"
eeab4d81 626
9730bc27 627#define TARGET_WANT_DEBUG_PUB_SECTIONS true
89bcf3ff
IS
628#define DEBUG_PUBNAMES_SECTION ((debug_generate_pub_sections == 2) \
629 ? "__DWARF,__debug_gnu_pubn,regular,debug" \
630 : "__DWARF,__debug_pubnames,regular,debug")
631
632#define DEBUG_PUBTYPES_SECTION ((debug_generate_pub_sections == 2) \
633 ? "__DWARF,__debug_gnu_pubt,regular,debug" \
634 : "__DWARF,__debug_pubtypes,regular,debug")
9730bc27 635
f1a66265
GK
636/* GCC's definition of 'one_only' is the same as its definition of 'weak'. */
637#define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
4746cf84 638
f1a66265
GK
639/* Mach-O supports 'weak imports', and 'weak definitions' in coalesced
640 sections. machopic_select_section ensures that weak variables go in
641 coalesced sections. Weak aliases (or any other kind of aliases) are
642 not supported. Weak symbols that aren't visible outside the .s file
643 are not supported. */
dd2e44f0
IS
644#define ASM_WEAKEN_DECL(FILE, DECL, NAME, ALIAS) \
645 do { \
646 if (ALIAS) \
647 { \
648 warning (0, "alias definitions not supported in Mach-O; ignored"); \
649 break; \
650 } \
651 \
652 if (! DECL_EXTERNAL (DECL) && TREE_PUBLIC (DECL)) \
653 targetm.asm_out.globalize_label (FILE, NAME); \
654 if (DECL_EXTERNAL (DECL)) \
655 fputs ("\t.weak_reference ", FILE); \
656 else if (lookup_attribute ("weak_import", DECL_ATTRIBUTES (DECL))) \
657 break; \
658 else if (TREE_PUBLIC (DECL)) \
659 fputs ("\t.weak_definition ", FILE); \
660 else \
661 break; \
662 assemble_name (FILE, NAME); \
663 fputc ('\n', FILE); \
664 } while (0)
4746cf84 665
72747d40
GK
666/* Darwin has the pthread routines in libSystem, which every program
667 links to, so there's no need for weak-ness for that. */
668#define GTHREAD_USE_WEAK 0
669
9e170098
GK
670/* On Darwin, we don't (at the time of writing) have linkonce sections
671 with names, so it's safe to make the class data not comdat. */
672#define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT hook_bool_void_false
673
157600d0
GK
674/* For efficiency, on Darwin the RTTI information that is always
675 emitted in the standard C++ library should not be COMDAT. */
676#define TARGET_CXX_LIBRARY_RTTI_COMDAT hook_bool_void_false
677
4746cf84
MA
678/* We make exception information linkonce. */
679#undef TARGET_USES_WEAK_UNWIND_INFO
680#define TARGET_USES_WEAK_UNWIND_INFO 1
681
682/* We need to use a nonlocal label for the start of an EH frame: the
16d6f994 683 Darwin linker requires that a coalesced section start with a label.
192d0f89
GK
684 Unfortunately, it also requires that 'debug' sections don't contain
685 labels. */
4746cf84 686#undef FRAME_BEGIN_LABEL
192d0f89 687#define FRAME_BEGIN_LABEL (for_eh ? "EH_frame" : "Lframe")
4746cf84 688
7904f95f 689/* Emit a label for the FDE corresponding to DECL. EMPTY means
4746cf84
MA
690 emit a label for an empty FDE. */
691#define TARGET_ASM_EMIT_UNWIND_LABEL darwin_emit_unwind_label
692
083cad55
EC
693/* Emit a label to separate the exception table. */
694#define TARGET_ASM_EMIT_EXCEPT_TABLE_LABEL darwin_emit_except_table_label
695
5d46ec3d
IS
696/* Make an EH (personality or LDSA) symbol indirect as needed. */
697#define TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT darwin_make_eh_symbol_indirect
698
491d5b3c
IS
699/* Some of Darwin's unwinders need current frame address state to be reset
700 after a DW_CFA_restore_state recovers the register values. */
701#undef TARGET_ASM_SHOULD_RESTORE_CFA_STATE
702#define TARGET_ASM_SHOULD_RESTORE_CFA_STATE darwin_should_restore_cfa_state
703
ee890fe2
SS
704/* Our profiling scheme doesn't LP labels and counter words. */
705
9739c90c 706#define NO_PROFILE_COUNTERS 1
ee890fe2 707
ee890fe2 708#undef INIT_SECTION_ASM_OP
4fe24839 709#define INIT_SECTION_ASM_OP ""
ee890fe2
SS
710
711#undef INVOKE__main
712
2cc07db4
RH
713#define TARGET_ASM_CONSTRUCTOR machopic_asm_out_constructor
714#define TARGET_ASM_DESTRUCTOR machopic_asm_out_destructor
ee890fe2 715
6ab9a3f4
SS
716/* Always prefix with an underscore. */
717
718#define USER_LABEL_PREFIX "_"
719
08a6a74b
RS
720/* A dummy symbol that will be replaced with the function base name. */
721#define MACHOPIC_FUNCTION_BASE_NAME "<pic base>"
722
ee890fe2
SS
723/* Don't output a .file directive. That is only used by the assembler for
724 error reporting. */
720b7001
ZW
725#undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
726#define TARGET_ASM_FILE_START_FILE_DIRECTIVE false
ee890fe2 727
a5fe455b
ZW
728#undef TARGET_ASM_FILE_END
729#define TARGET_ASM_FILE_END darwin_file_end
ee890fe2 730
c082f9f3
SB
731/* Because Mach-O relocations have a counter from 1 to 255 for the
732 section number they apply to, it is necessary to output all
733 normal sections before the LTO sections, to make sure that the
734 sections that may have relocations always have a section number
735 smaller than 255. */
736#undef TARGET_ASM_LTO_START
737#define TARGET_ASM_LTO_START darwin_asm_lto_start
738#undef TARGET_ASM_LTO_END
739#define TARGET_ASM_LTO_END darwin_asm_lto_end
740
dd2e44f0 741#define ASM_OUTPUT_SKIP(FILE,SIZE) \
16998094 742 fprintf (FILE, "\t.space " HOST_WIDE_INT_PRINT_UNSIGNED"\n", SIZE)
2aa9948d 743
991b6592 744/* Give ObjC methods pretty symbol names. */
ee890fe2
SS
745
746#undef OBJC_GEN_METHOD_LABEL
dd2e44f0
IS
747#define OBJC_GEN_METHOD_LABEL(BUF,IS_INST,CLASS_NAME,CAT_NAME,SEL_NAME,NUM) \
748 do { if (CAT_NAME) \
749 sprintf (BUF, "%c[%s(%s) %s]", (IS_INST) ? '-' : '+', \
750 (CLASS_NAME), (CAT_NAME), (SEL_NAME)); \
751 else \
752 sprintf (BUF, "%c[%s %s]", (IS_INST) ? '-' : '+', \
753 (CLASS_NAME), (SEL_NAME)); \
754 } while (0)
ee890fe2 755
46a99b06 756#undef ASM_DECLARE_OBJECT_NAME
dd2e44f0
IS
757#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
758 darwin_asm_declare_object_name ((FILE), (NAME), (DECL))
46a99b06 759
ee890fe2
SS
760/* The RTTI data (e.g., __ti4name) is common and public (and static),
761 but it does need to be referenced via indirect PIC data pointers.
11abc112 762 The machopic_define_symbol calls are telling the machopic subsystem
ee890fe2
SS
763 that the name *is* defined in this module, so it doesn't need to
764 make them indirect. */
765
105fe3e0 766#undef ASM_DECLARE_FUNCTION_NAME
dd2e44f0
IS
767#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
768 do { \
769 const char *xname = NAME; \
770 if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF) \
771 xname = IDENTIFIER_POINTER (DECL_NAME (DECL)); \
772 if (! DECL_WEAK (DECL) \
773 && ((TREE_STATIC (DECL) \
774 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
775 || DECL_INITIAL (DECL))) \
776 machopic_define_symbol (DECL_RTL (DECL)); \
777 if ((TREE_STATIC (DECL) \
778 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
779 || DECL_INITIAL (DECL)) \
780 (* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false); \
781 ASM_OUTPUT_FUNCTION_LABEL (FILE, xname, DECL); \
782 } while (0)
ee890fe2 783
e4f7c483
AS
784#undef TARGET_ASM_DECLARE_CONSTANT_NAME
785#define TARGET_ASM_DECLARE_CONSTANT_NAME darwin_asm_declare_constant_name
18f3e349 786
ee890fe2 787/* Wrap new method names in quotes so the assembler doesn't gag.
dd2e44f0 788 Make Objective-C internal symbols local and in doing this, we need
d8299715
DK
789 to accommodate the name mangling done by c++ on file scope locals. */
790
d8299715 791int darwin_label_is_anonymous_local_objc_name (const char *name);
ee890fe2
SS
792
793#undef ASM_OUTPUT_LABELREF
dd2e44f0
IS
794#define ASM_OUTPUT_LABELREF(FILE,NAME) \
795 do { \
796 const char *xname = (NAME); \
797 if (! strcmp (xname, MACHOPIC_FUNCTION_BASE_NAME)) \
798 machopic_output_function_base_name(FILE); \
799 else if (xname[0] == '&' || xname[0] == '*') \
800 { \
801 int len = strlen (xname); \
802 if (len > 6 && !strcmp ("$stub", xname + len - 5)) \
803 machopic_validate_stub_or_non_lazy_ptr (xname); \
804 else if (len > 7 && !strcmp ("$stub\"", xname + len - 6)) \
805 machopic_validate_stub_or_non_lazy_ptr (xname); \
806 else if (len > 14 && !strcmp ("$non_lazy_ptr", xname + len - 13)) \
807 machopic_validate_stub_or_non_lazy_ptr (xname); \
808 else if (len > 15 && !strcmp ("$non_lazy_ptr\"", xname + len - 14)) \
809 machopic_validate_stub_or_non_lazy_ptr (xname); \
810 if (xname[1] != '"' && name_needs_quotes (&xname[1])) \
811 fprintf (FILE, "\"%s\"", &xname[1]); \
812 else \
813 fputs (&xname[1], FILE); \
814 } \
815 else if (xname[0] == '+' || xname[0] == '-') \
816 fprintf (FILE, "\"%s\"", xname); \
d764a8e6 817 else if (darwin_label_is_anonymous_local_objc_name (xname)) \
dd2e44f0 818 fprintf (FILE, "L%s", xname); \
dd2e44f0 819 else if (xname[0] != '"' && name_needs_quotes (xname)) \
cebb4698 820 asm_fprintf (FILE, "\"%U%s\"", xname); \
dd2e44f0
IS
821 else \
822 asm_fprintf (FILE, "%U%s", xname); \
823 } while (0)
ee890fe2 824
2aa9948d
SS
825/* Output before executable code. */
826#undef TEXT_SECTION_ASM_OP
f1a66265 827#define TEXT_SECTION_ASM_OP "\t.text"
2aa9948d
SS
828
829/* Output before writable data. */
830
831#undef DATA_SECTION_ASM_OP
f1a66265 832#define DATA_SECTION_ASM_OP "\t.data"
2aa9948d 833
ee890fe2
SS
834#undef ALIGN_ASM_OP
835#define ALIGN_ASM_OP ".align"
836
837#undef ASM_OUTPUT_ALIGN
dd2e44f0
IS
838#define ASM_OUTPUT_ALIGN(FILE,LOG) \
839 if ((LOG) != 0) \
840 fprintf (FILE, "\t%s\t%d\n", ALIGN_ASM_OP, (LOG))
ee890fe2 841
19bf83a9
IS
842/* The maximum alignment which the object file format can support in bits
843 which depends on the OS version and whether the object is a common
844 variable. */
ee890fe2
SS
845
846#undef MAX_OFILE_ALIGNMENT
19bf83a9 847#define MAX_OFILE_ALIGNMENT ((1U << L2_MAX_OFILE_ALIGNMENT) * 8U)
46a99b06
IS
848
849/* These are the three variants that emit referenced blank space. */
dd2e44f0
IS
850#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
851 darwin_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
46a99b06
IS
852
853#undef ASM_OUTPUT_ALIGNED_DECL_LOCAL
dd2e44f0
IS
854#define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN) \
855 darwin_asm_output_aligned_decl_local \
856 ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
46a99b06
IS
857
858#undef ASM_OUTPUT_ALIGNED_DECL_COMMON
dd2e44f0
IS
859#define ASM_OUTPUT_ALIGNED_DECL_COMMON(FILE, DECL, NAME, SIZE, ALIGN) \
860 darwin_asm_output_aligned_decl_common \
861 ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
46a99b06 862
fee3eacd
IS
863/* The generic version, archs should over-ride where required. */
864#define MACHOPIC_NL_SYMBOL_PTR_SECTION ".non_lazy_symbol_pointer"
865
d6b5193b 866/* Declare the section variables. */
c3e23a08 867#ifndef USED_FOR_TARGET
56c779bc
GK
868enum darwin_section_enum {
869#define DEF_SECTION(NAME, FLAGS, DIRECTIVE, OBJC) NAME,
d6b5193b
RS
870#include "darwin-sections.def"
871#undef DEF_SECTION
56c779bc
GK
872 NUM_DARWIN_SECTIONS
873};
874extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
0e230dfa 875#endif
ee890fe2 876
ae46c4e0
RH
877#undef TARGET_ASM_SELECT_SECTION
878#define TARGET_ASM_SELECT_SECTION machopic_select_section
1f81953b 879
f16d3f39
JH
880#undef TARGET_ASM_FUNCTION_SECTION
881#define TARGET_ASM_FUNCTION_SECTION darwin_function_section
f1a66265 882
b64a1b53
RH
883#undef TARGET_ASM_SELECT_RTX_SECTION
884#define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
4746cf84
MA
885#undef TARGET_ASM_UNIQUE_SECTION
886#define TARGET_ASM_UNIQUE_SECTION darwin_unique_section
ab5c8549
JJ
887#undef TARGET_ASM_FUNCTION_RODATA_SECTION
888#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
50b0b78a
IS
889
890#undef TARGET_ASM_TM_CLONE_TABLE_SECTION
891#define TARGET_ASM_TM_CLONE_TABLE_SECTION darwin_tm_clone_table_section
892
24c78b3a
RH
893#undef TARGET_ASM_RELOC_RW_MASK
894#define TARGET_ASM_RELOC_RW_MASK machopic_reloc_rw_mask
4746cf84 895
5eb99654 896/* Globalizing directive for a label. */
83bf7f5e 897#define GLOBAL_ASM_OP "\t.globl "
5eb99654 898#define TARGET_ASM_GLOBALIZE_LABEL darwin_globalize_label
ee890fe2 899
6ce4806b
MA
900/* Emit an assembler directive to set visibility for a symbol. Used
901 to support visibility attribute and Darwin's private extern
ff482c8d 902 feature. */
6ce4806b
MA
903#undef TARGET_ASM_ASSEMBLE_VISIBILITY
904#define TARGET_ASM_ASSEMBLE_VISIBILITY darwin_assemble_visibility
905
005c1a13 906/* Extra attributes for Darwin. */
dd2e44f0 907#define SUBTARGET_ATTRIBUTE_TABLE \
4849deb1
JJ
908 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, \
909 affects_type_identity, handler, exclude } */ \
910 { "apple_kext_compatibility", 0, 0, false, true, false, false, \
911 darwin_handle_kext_attribute, NULL }, \
912 { "weak_import", 0, 0, true, false, false, false, \
913 darwin_handle_weak_import_attribute, NULL }
6ce4806b 914
7881b63f
IS
915/* Make local constant labels linker-visible, so that if one follows a
916 weak_global constant, ld64 will be able to separate the atoms. */
ee890fe2 917#undef ASM_GENERATE_INTERNAL_LABEL
dd2e44f0 918#define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
7881b63f
IS
919 do { \
920 if (strcmp ("LC", PREFIX) == 0) \
921 sprintf (LABEL, "*%s%ld", "lC", (long)(NUM)); \
804254ed
IS
922 else if (strcmp ("Lubsan_data", PREFIX) == 0) \
923 sprintf (LABEL, "*%s%ld", "lubsan_data", (long)(NUM));\
924 else if (strcmp ("Lubsan_type", PREFIX) == 0) \
925 sprintf (LABEL, "*%s%ld", "lubsan_type", (long)(NUM));\
926 else if (strcmp ("LASAN", PREFIX) == 0) \
927 sprintf (LABEL, "*%s%ld", "lASAN", (long)(NUM));\
f1e2879e
IS
928 else if (strcmp ("LTRAMP", PREFIX) == 0) \
929 sprintf (LABEL, "*%s%ld", "lTRAMP", (long)(NUM));\
7881b63f
IS
930 else \
931 sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM)); \
932 } while (0)
ee890fe2 933
8e3e233b
DP
934#undef TARGET_ASM_MARK_DECL_PRESERVED
935#define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved
936
2161a445
IS
937/* Any port using this header needs to define the first available
938 subtarget symbol bit: SYMBOL_FLAG_SUBT_DEP. */
699c914a 939
2161a445
IS
940/* Is a variable. */
941#define MACHO_SYMBOL_FLAG_VARIABLE (SYMBOL_FLAG_SUBT_DEP)
942#define MACHO_SYMBOL_VARIABLE_P(RTX) \
943 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_VARIABLE) != 0)
944
a3fc4326
IS
945/* Set on a symbol that must be indirected, even when there is a
946 definition in the TU. The ABI mandates that common symbols are so
947 indirected, as are weak. If 'fix-and-continue' is operational then
948 data symbols might also be. */
949
950#define MACHO_SYMBOL_FLAG_MUST_INDIRECT ((SYMBOL_FLAG_SUBT_DEP) << 1)
951#define MACHO_SYMBOL_MUST_INDIRECT_P(RTX) \
952 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_MUST_INDIRECT) != 0)
953
2161a445
IS
954/* Set on a symbol with SYMBOL_FLAG_FUNCTION or MACHO_SYMBOL_FLAG_VARIABLE
955 to indicate that the function or variable is considered defined in this
956 translation unit. */
957
958#define MACHO_SYMBOL_FLAG_DEFINED ((SYMBOL_FLAG_SUBT_DEP) << 2)
959#define MACHO_SYMBOL_DEFINED_P(RTX) \
960 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_DEFINED) != 0)
11abc112 961
b393e5ed
IS
962/* Set on a symbol that has specified non-default visibility. */
963
964#define MACHO_SYMBOL_FLAG_HIDDEN_VIS ((SYMBOL_FLAG_SUBT_DEP) << 3)
965#define MACHO_SYMBOL_HIDDEN_VIS_P(RTX) \
966 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_HIDDEN_VIS) != 0)
967
34548764
IS
968/* Set on a symbol that should be made visible to the linker (overriding
969 'L' symbol prefixes). */
970
971#define MACHO_SYMBOL_FLAG_LINKER_VIS ((SYMBOL_FLAG_SUBT_DEP) << 4)
972#define MACHO_SYMBOL_LINKER_VIS_P(RTX) \
973 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_LINKER_VIS) != 0)
974
a0e887be
IS
975/* Set on a symbol that is a pic stub or symbol indirection (i.e. the
976 L_xxxxx${stub,non_lazy_ptr,lazy_ptr}. */
977
978#define MACHO_SYMBOL_FLAG_INDIRECTION ((SYMBOL_FLAG_SUBT_DEP) << 5)
979#define MACHO_SYMBOL_INDIRECTION_P(RTX) \
980 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_INDIRECTION) != 0)
981
699c914a
MS
982/* Set on a symbol to indicate when fix-and-continue style code
983 generation is being used and the symbol refers to a static symbol
984 that should be rebound from new instances of a translation unit to
985 the original instance of the data. */
986
a0e887be 987#define MACHO_SYMBOL_FLAG_STATIC ((SYMBOL_FLAG_SUBT_DEP) << 6)
2161a445
IS
988#define MACHO_SYMBOL_STATIC_P(RTX) \
989 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_STATIC) != 0)
699c914a 990
ee890fe2
SS
991/* Symbolic names for various things we might know about a symbol. */
992
993enum machopic_addr_class {
994 MACHOPIC_UNDEFINED,
995 MACHOPIC_DEFINED_DATA,
996 MACHOPIC_UNDEFINED_DATA,
997 MACHOPIC_DEFINED_FUNCTION,
998 MACHOPIC_UNDEFINED_FUNCTION
999};
1000
1001/* Macros defining the various PIC cases. */
1002
fee3eacd
IS
1003#undef MACHO_DYNAMIC_NO_PIC_P
1004#define MACHO_DYNAMIC_NO_PIC_P (TARGET_MACHO_DYNAMIC_NO_PIC)
1005#undef MACHOPIC_INDIRECT
ab82a49f 1006#define MACHOPIC_INDIRECT (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
c446d1a7 1007#define MACHOPIC_JUST_INDIRECT (MACHO_DYNAMIC_NO_PIC_P)
fee3eacd 1008#undef MACHOPIC_PURE
c446d1a7 1009#define MACHOPIC_PURE (flag_pic && ! MACHO_DYNAMIC_NO_PIC_P)
ee890fe2 1010
b069de3b 1011#undef TARGET_ENCODE_SECTION_INFO
fb49053f 1012#define TARGET_ENCODE_SECTION_INFO darwin_encode_section_info
b069de3b 1013#undef TARGET_STRIP_NAME_ENCODING
11abc112 1014#define TARGET_STRIP_NAME_ENCODING default_strip_name_encoding
df56a27f 1015
dd2e44f0
IS
1016#define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH) \
1017 do { \
1018 const char *const stub_ = (STUB); \
1019 char *buffer_ = (BUF); \
1020 strcpy (buffer_, stub_); \
1021 if (stub_[0] == '"') \
1022 { \
1023 strcpy (buffer_ + (STUB_LENGTH) - 1, "_binder\""); \
1024 } \
1025 else \
1026 { \
1027 strcpy (buffer_ + (STUB_LENGTH), "_binder"); \
1028 } \
1029 } while (0)
1030
1031#define GEN_SYMBOL_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH) \
1032 do { \
1033 const char *const symbol_ = (SYMBOL); \
1034 char *buffer_ = (BUF); \
1035 if (name_needs_quotes (symbol_) && symbol_[0] != '"') \
1036 { \
1037 sprintf (buffer_, "\"%s\"", symbol_); \
1038 } \
1039 else \
1040 { \
1041 strcpy (buffer_, symbol_); \
1042 } \
1043 } while (0)
ee890fe2
SS
1044
1045/* Given a symbol name string, create the lazy pointer version
1046 of the symbol name. */
1047
dd2e44f0
IS
1048#define GEN_LAZY_PTR_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH) \
1049 do { \
1050 const char *symbol_ = (SYMBOL); \
1051 char *buffer_ = (BUF); \
1052 if (symbol_[0] == '"') \
1053 { \
1054 strcpy (buffer_, "\"L"); \
1055 strcpy (buffer_ + 2, symbol_ + 1); \
1056 strcpy (buffer_ + (SYMBOL_LENGTH), "$lazy_ptr\""); \
1057 } \
1058 else if (name_needs_quotes (symbol_)) \
1059 { \
1060 strcpy (buffer_, "\"L"); \
1061 strcpy (buffer_ + 2, symbol_); \
1062 strcpy (buffer_ + (SYMBOL_LENGTH) + 2, "$lazy_ptr\""); \
1063 } \
1064 else \
1065 { \
1066 strcpy (buffer_, "L"); \
1067 strcpy (buffer_ + 1, symbol_); \
1068 strcpy (buffer_ + (SYMBOL_LENGTH) + 1, "$lazy_ptr"); \
1069 } \
1070 } while (0)
ee890fe2 1071
4746cf84 1072#define EH_FRAME_SECTION_NAME "__TEXT"
92b9a671 1073#define EH_FRAME_SECTION_ATTR ",coalesced,no_toc+strip_static_syms+live_support"
4746cf84 1074
b069de3b 1075#undef ASM_PREFERRED_EH_DATA_FORMAT
dd2e44f0
IS
1076#define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \
1077 (((CODE) == 2 && (GLOBAL) == 1) \
1078 ? (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4) : \
1079 ((CODE) == 1 || (GLOBAL) == 0) ? DW_EH_PE_pcrel : DW_EH_PE_absptr)
7606e68f 1080
dd2e44f0 1081#define ASM_OUTPUT_DWARF_DELTA(FILE,SIZE,LABEL1,LABEL2) \
7180b1a6 1082 darwin_asm_output_dwarf_delta (FILE, SIZE, LABEL1, LABEL2, 0)
7606e68f 1083
7180b1a6
RB
1084#define ASM_OUTPUT_DWARF_OFFSET(FILE,SIZE,LABEL,OFFSET,BASE) \
1085 darwin_asm_output_dwarf_offset (FILE, SIZE, LABEL, OFFSET, BASE)
192d0f89 1086
dd2e44f0
IS
1087#define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(ASM_OUT_FILE, ENCODING, SIZE, ADDR, DONE) \
1088 if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) { \
1089 darwin_non_lazy_pcrel (ASM_OUT_FILE, ADDR); \
1090 goto DONE; \
1091 }
4746cf84 1092
5a25e0c5
DJ
1093/* Experimentally, putting jump tables in text is faster on SPEC.
1094 Also this is needed for correctness for coalesced functions. */
1095
1096#ifndef JUMP_TABLES_IN_TEXT_SECTION
31492595 1097#define JUMP_TABLES_IN_TEXT_SECTION 1
5a25e0c5 1098#endif
4746cf84 1099
7606e68f 1100#define TARGET_TERMINATE_DW2_EH_FRAME_INFO false
abe72dd8 1101
d6b5193b 1102#define TARGET_ASM_INIT_SECTIONS darwin_init_sections
4746cf84
MA
1103#undef TARGET_ASM_NAMED_SECTION
1104#define TARGET_ASM_NAMED_SECTION darwin_asm_named_section
4746cf84 1105
dd2e44f0
IS
1106#define DARWIN_REGISTER_TARGET_PRAGMAS() \
1107 do { \
1108 if (!flag_preprocess_only) \
1109 cpp_register_pragma (parse_in, NULL, "mark", \
1110 darwin_pragma_ignore, false); \
1111 c_register_pragma (0, "options", darwin_pragma_options); \
1112 c_register_pragma (0, "segment", darwin_pragma_ignore); \
1113 c_register_pragma (0, "unused", darwin_pragma_unused); \
1114 c_register_pragma (0, "ms_struct", darwin_pragma_ms_struct); \
1115 } while (0)
2aa9948d
SS
1116
1117#undef ASM_APP_ON
1118#define ASM_APP_ON ""
1119#undef ASM_APP_OFF
1120#define ASM_APP_OFF ""
213c4a8a 1121
3dd53121
AP
1122void darwin_register_frameworks (const char *, const char *, int);
1123void darwin_register_objc_includes (const char *, const char *, int);
1124#define TARGET_EXTRA_PRE_INCLUDES darwin_register_objc_includes
94d1613b
MS
1125#define TARGET_EXTRA_INCLUDES darwin_register_frameworks
1126
1127void add_framework_path (char *);
1128#define TARGET_OPTF add_framework_path
1129
4969c0d8 1130#define TARGET_POSIX_IO
8db4d7a1 1131
2baeaa1b
MS
1132#define WINT_TYPE "int"
1133
953ff289
DN
1134/* Every program on darwin links against libSystem which contains the pthread
1135 routines, so there's no need to explicitly call out when doing threaded
1136 work. */
23f99493 1137
953ff289
DN
1138#undef GOMP_SELF_SPECS
1139#define GOMP_SELF_SPECS ""
255a9a1b
EB
1140#undef GTM_SELF_SPECS
1141#define GTM_SELF_SPECS ""
953ff289 1142
dd2e44f0 1143/* Darwin disables section anchors by default.
46a99b06 1144 They should be enabled per arch where support exists in that arch. */
23f99493 1145#define TARGET_ASM_OUTPUT_ANCHOR NULL
46a99b06 1146#define DARWIN_SECTION_ANCHORS 0
23f99493 1147
10e48e39 1148#define HAVE_ENABLE_EXECUTE_STACK
c6c621d4 1149
f475fd3c
MS
1150/* For Apple KEXTs, we make the constructors return this to match gcc
1151 2.95. */
1152#define TARGET_CXX_CDTOR_RETURNS_THIS (darwin_kextabi_p)
f475fd3c
MS
1153#define TARGET_KEXTABI flag_apple_kext
1154
26705988 1155/* We have target-specific builtins. */
1cd130b0 1156#define SUBTARGET_FOLD_BUILTIN darwin_fold_builtin
26705988 1157
91ebb981
IS
1158#define TARGET_N_FORMAT_TYPES 1
1159#define TARGET_FORMAT_TYPES darwin_additional_format_types
1160
927b679c
IS
1161#ifndef USED_FOR_TARGET
1162extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **);
dd2e44f0
IS
1163#define GCC_DRIVER_HOST_INITIALIZATION \
1164 darwin_driver_init (&decoded_options_count, &decoded_options)
927b679c 1165#endif
e46b55d0 1166
8cd01fe6
JDA
1167/* The Apple assembler and linker do not support constructor priorities. */
1168#undef SUPPORTS_INIT_PRIORITY
1169#define SUPPORTS_INIT_PRIORITY 0
1170
ac6ecec4
IS
1171#undef STACK_CHECK_STATIC_BUILTIN
1172#define STACK_CHECK_STATIC_BUILTIN 1
1173
558c362a 1174/* When building cross-compilers (and native crosses) we shall default to
45c3fea9
IS
1175 providing an osx-version-min of this unless overridden by the User.
1176 10.5 is the only version that fully supports all our archs so that's the
1177 fall-back default. */
105fe3e0 1178#ifndef DEF_MIN_OSX_VERSION
45c3fea9 1179#define DEF_MIN_OSX_VERSION "10.5"
105fe3e0 1180#endif
558c362a 1181
794fa8a6
IS
1182/* Later versions of ld64 support coalescing weak code/data without requiring
1183 that they be placed in specially identified sections. This is the earliest
1184 _tested_ version known to support this so far. */
ef370f93 1185#define MIN_LD64_NO_COAL_SECTS "236.3"
794fa8a6 1186
d308419c 1187/* From at least version 62.1, ld64 can build symbol indirection stubs as
ce3a2015 1188 needed, and there is no need for the compiler to emit them. */
179c7ef5 1189#define MIN_LD64_OMIT_STUBS "62.1"
ce3a2015 1190
66526c6a
IS
1191/* Emit start labels for init and term sections from this version. */
1192#define MIN_LD64_INIT_TERM_START_LABELS "136.0"
1193
ef370f93
IS
1194/* If we have no definition for the linker version, pick the minimum version
1195 that will bootstrap the compiler. */
eb89c82f 1196#ifndef LD64_VERSION
ef370f93
IS
1197# ifndef DEF_LD64
1198# define LD64_VERSION "85.2.1"
1199# else
1200# define LD64_VERSION DEF_LD64
1201# endif
eb89c82f
IS
1202#endif
1203
eb817f27 1204/* CTF and BTF support. */
cc845301 1205#undef CTF_INFO_SECTION_NAME
eb817f27
IS
1206#define CTF_INFO_SECTION_NAME "__CTF_BTF,__ctf,regular,debug"
1207#undef BTF_INFO_SECTION_NAME
1208#define BTF_INFO_SECTION_NAME "__CTF_BTF,__btf,regular,debug"
cc845301 1209
213c4a8a 1210#endif /* CONFIG_DARWIN_H */