xref: /netbsd-src/external/gpl3/gcc/dist/gcc/config/darwin.h (revision 0a3071956a3a9fdebdbf7f338cf2d439b45fc728)
1 /* Target definitions for Darwin (Mac OS X) systems.
2    Copyright (C) 1989-2022 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 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
20 
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24 <http://www.gnu.org/licenses/>.  */
25 
26 #ifndef CONFIG_DARWIN_H
27 #define CONFIG_DARWIN_H
28 
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 
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 
43 #define DARWIN_X86 0
44 #define DARWIN_PPC 0
45 
46 #define OBJECT_FORMAT_MACHO 1
47 
48 /* Suppress g++ attempt to link in the math library automatically. */
49 #define MATH_LIBRARY ""
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 
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 
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 
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 
114 /* Default to using the NeXT-style runtime, since that's what is
115    pre-installed on Darwin systems.  */
116 
117 #define NEXT_OBJC_RUNTIME 100508
118 
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 
125 /* True if pragma ms_struct is in effect.  */
126 extern GTY(()) int darwin_ms_struct;
127 
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.
137    We keep a couple of cases where a negative option originally appeared after
138    the positive alternate, potentially overriding it.
139    When we report an error with %e, it seems necessary to strip the option
140    before doing so, otherwise it survives to the cc1 command line (%e doesn't
141    appear to abort the program before this).
142    Right now there's no mechanism to split up the "variable portion" (%*) of
143    the matched spec string, so where we have some driver specs that take 2
144    or 3 arguments, these cannot be processed here, but are deferred until the
145    LINK_SPEC, where they are copied verbatim.  */
146 
147 #undef SUBTARGET_DRIVER_SELF_SPECS
148 #define SUBTARGET_DRIVER_SELF_SPECS					\
149   "%{static|fapple-kext|mkernel:%{shared|dynamic|dynamiclib: \
150      %econflicting code generation switches}}",\
151   "%{shared|dynamiclib:-Xlinker -dylib \
152      %{allowable_client*:-Xlinker -allowable_client -Xlinker %*} \
153        %<allowable_client* \
154      %{bundle_loader*: %<bundle_loader* \
155        %e-bundle_loader not allowed with -dynamiclib} \
156      %{client_name*: %<client_name* \
157        %e-client_name not allowed with -dynamiclib} \
158      %{compatibility_version*:\
159        -Xlinker -dylib_compatibility_version -Xlinker %*} \
160        %<compatibility_version* \
161      %{current_version*:-Xlinker -dylib_current_version -Xlinker %*} \
162        %<current_version* \
163      %{install_name*:-Xlinker -dylib_install_name -Xlinker %* } \
164        %<install_name* \
165      %{keep_private_externs: %<keep_private_externs \
166        %e-keep_private_externs not allowed with -dynamiclib} \
167      %{private_bundle: %<private_bundle \
168        %e-private_bundle not allowed with -dynamiclib} \
169     }",							\
170   "%{!dynamiclib:%{!shared: \
171      %{bundle_loader*:-Xlinker -bundle_loader -Xlinker %*} \
172        %<bundle_loader* \
173      %{client_name*:-Xlinker -client_name -Xlinker %*} \
174        %<client_name* \
175      %{compatibility_version*: %<compatibility_version* \
176        %e-compatibility_version only allowed with -dynamiclib} \
177      %{current_version*: %<current_version* \
178        %e-current_version only allowed with -dynamiclib} \
179      %{install_name*: %<install_name* \
180        %e-install_name only allowed with -dynamiclib} \
181      %{keep_private_externs:-Xlinker -keep_private_externs} \
182        %<keep_private_externs \
183      %{private_bundle:-Xlinker -private_bundle} \
184        %<private_bundle \
185     }}",									\
186   "%{all_load:-Xlinker -all_load} %<all_load",				\
187   "%{arch_errors_fatal:-Xlinker -arch_errors_fatal} \
188     %<arch_errors_fatal",						\
189   "%{bind_at_load:-Xlinker -bind_at_load} %<bind_at_load",		\
190   "%{bundle:%{!dynamiclib:%{!shared: -Xlinker -bundle; \
191 			    :%e-bundle not allowed with -shared}; \
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",		\
220   "%{multiply_defined*:-Xlinker -multiply_defined -Xlinker %*} \
221      %<multiply_defined* ",						\
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*",					\
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 "
273 
274 #if LD64_HAS_EXPORT_DYNAMIC
275 #define DARWIN_RDYNAMIC "%{rdynamic:-export_dynamic}"
276 #else
277 #define DARWIN_RDYNAMIC "%{rdynamic:%nrdynamic is not supported}"
278 #endif
279 
280 #if LD64_HAS_PLATFORM_VERSION
281 #define DARWIN_PLATFORM_ID \
282   "%{mmacosx-version-min=*: -platform_version macos %* 0.0} "
283 #else
284 #define DARWIN_PLATFORM_ID \
285   "%{mmacosx-version-min=*:-macosx_version_min %*} "
286 #endif
287 
288 /* Code built with mdynamic-no-pic does not support PIE/PIC, so  we disallow
289    these combinations; we also ensure that the no_pie option is passed to
290    ld64 on system versions that default to PIE when mdynamic-no-pic is given.
291    FIXME: we should check that the linker supports the -pie and -no_pie.
292    options.  */
293 #define DARWIN_PIE_SPEC \
294 "%{pie|fpie|fPIE:\
295    %{mdynamic-no-pic: \
296      %n'-mdynamic-no-pic' overrides '-pie', '-fpie' or '-fPIE'; \
297      :%:version-compare(>= 10.5 mmacosx-version-min= -pie) }; \
298    mdynamic-no-pic:%:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } "
299 
300 #define DARWIN_NOPIE_SPEC \
301 "%{no-pie|fno-pie|fno-PIE: \
302    %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) }"
303 
304 #define DARWIN_CC1_SPEC							\
305   "%<dynamic %<force_cpusubtype_ALL %<multiply_defined* %<dynamiclib"
306 
307 #define SUBSUBTARGET_OVERRIDE_OPTIONS					\
308   do {									\
309     darwin_override_options ();						\
310   } while (0)
311 
312 #define SUBTARGET_C_COMMON_OVERRIDE_OPTIONS do {                        \
313     if (flag_mkernel || flag_apple_kext)				\
314       {									\
315 	if (flag_use_cxa_atexit == 2)					\
316 	  flag_use_cxa_atexit = 0;					\
317 	/* kexts should always be built without the coalesced sections	\
318 	   because the kernel loader doesn't grok such sections.  */	\
319 	flag_weak = 0;							\
320 	/* No RTTI in kexts.  */					\
321 	flag_rtti = 0;							\
322       }									\
323   } while (0)
324 
325 /* Machine dependent cpp options.  Don't add more options here, add
326    them to darwin_cpp_builtins in darwin-c.cc.  */
327 
328 #undef	CPP_SPEC
329 #define CPP_SPEC "%{static:%{!dynamic:-D__STATIC__}}%{!static:-D__DYNAMIC__}" \
330 	" %{pthread:-D_REENTRANT} "
331 
332 /* This is a fix for PR41260 by passing -no_compact_unwind on darwin10 and
333    later until the assembler, linker and libunwind are able to deal with the
334    output from GCC.
335 
336    FIXME: we should check that the linker supports the option.
337 */
338 
339 #define DARWIN_NOCOMPACT_UNWIND \
340 " %:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) "
341 
342 /* In Darwin linker specs we can put -lcrt0.o and ld will search the library
343    path for crt0.o or -lcrtx.a and it will search for libcrtx.a.  As for
344    other ports, we can also put xxx.{o,a}%s and get the appropriate complete
345    startfile absolute directory.  This latter point is important when we want
346    to override ld's rule of .dylib being found ahead of .a and the user wants
347    the convenience library to be linked.  */
348 
349 /* The LINK_COMMAND spec is mostly a clone of the standard LINK_COMMAND_SPEC,
350    plus precomp, libtool, and fat build additions.
351 
352    In general, random Darwin linker flags should go into LINK_SPEC
353    instead of LINK_COMMAND_SPEC.  The command spec is better for
354    specifying the handling of options understood by generic Unix
355    linkers, and for positional arguments like libraries.  */
356 
357 #define LINK_COMMAND_SPEC_A \
358    "%{!c:%{!E:%{!S:%{!M:%{!MM:%{!fsyntax-only:%{!fdump=*: \
359     %(linker)" \
360     LINK_PLUGIN_SPEC \
361     "%{flto*:%<fcompare-debug*} \
362      %{flto} %{fno-lto} %{flto=*} \
363     %l " \
364     DARWIN_PLATFORM_ID \
365     LINK_COMPRESS_DEBUG_SPEC \
366    "%X %{s} %{t} %{Z} %{u*} \
367     %{e*} %{r} \
368     %{o*}%{!o:-o a.out} \
369     %{!r:%{!nostdlib:%{!nostartfiles:%S}}} \
370     %{L*} %(link_libgcc) \
371     %{!r:%{!nostdlib:%{!nodefaultlibs: " DARWIN_WEAK_CRTS "}}} \
372     %o \
373     %{!r:%{!nostdlib:%{!nodefaultlibs:\
374       %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \
375       %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): \
376 	%{static|static-libgcc|static-libstdc++|static-libgfortran: \
377 	  libgomp.a%s; : -lgomp }} \
378       %{fgnu-tm: \
379 	%{static|static-libgcc|static-libstdc++|static-libgfortran: \
380 	  libitm.a%s; : -litm }} \
381       %{%:sanitize(address): -lasan } \
382       %{%:sanitize(undefined): -lubsan } \
383       %(link_ssp) \
384       %:version-compare(>< 10.6 10.7 mmacosx-version-min= -ld10-uwfef) \
385       %(link_gcc_c_sequence) \
386       %{!nodefaultexport: \
387 	%{%:version-compare(>= 10.11 asm_macosx_version_min= -U): \
388 	   ___emutls_get_address -exported_symbol ___emutls_get_address \
389 	  -U ___emutls_register_common \
390 	  -exported_symbol ___emutls_register_common \
391 	  -U ___gcc_nested_func_ptr_created \
392 	  -exported_symbol ___gcc_nested_func_ptr_created \
393 	  -U ___gcc_nested_func_ptr_deleted \
394 	  -exported_symbol ___gcc_nested_func_ptr_deleted \
395       }} \
396     }}}\
397     %{!r:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*} "\
398     DARWIN_PIE_SPEC \
399     DARWIN_NOPIE_SPEC \
400     DARWIN_RDYNAMIC \
401     DARWIN_NOCOMPACT_UNWIND \
402     "}}}}}}} %<pie %<no-pie %<rdynamic %<X %<rpath "
403 
404 /* Spec that controls whether the debug linker is run automatically for
405    a link step.  This needs to be done if there is a source file on the
406    command line which will result in a temporary object (and debug is
407    enabled).  */
408 
409 #define DSYMUTIL_SPEC \
410   "%{!c:%{!E:%{!S:%{!r:%{!M:%{!MM:%{!fsyntax-only:%{!fdump=*:\
411      %{g*:%{!gctf:%{!gbtf:%{!gstabs*:%{%:debug-level-gt(0): -idsym \
412        %{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm|.s|.f|.f90|\
413 	 .f95|.f03|.f77|.for|.F|.F90|.F95|.F03|.d: -dsym }\
414       }}}}}\
415    }}}}}}}}"
416 
417 #define LINK_COMMAND_SPEC LINK_COMMAND_SPEC_A DSYMUTIL_SPEC
418 
419 /* Tell collect2 to run dsymutil for us as necessary.  */
420 #define COLLECT_RUN_DSYMUTIL 1
421 
422 /* We only want one instance of %G, since libSystem (Darwin's -lc) does not
423    depend on libgcc. */
424 #undef  LINK_GCC_C_SEQUENCE_SPEC
425 #define LINK_GCC_C_SEQUENCE_SPEC \
426  "%G %{!nolibc:%L} "
427 
428 /* ld64 supports a sysroot, it just has a different name and there's no easy
429    way to check for it at config time.  */
430 #undef HAVE_LD_SYSROOT
431 #define HAVE_LD_SYSROOT 1
432 /* It seems the only (working) way to get a space after %R is to append a
433    dangling '/'.  */
434 #define SYSROOT_SPEC "%{!isysroot*:-syslibroot %R/ } "
435 
436 /* Do the same as clang, for now, and insert the sysroot for ld when an
437    isysroot is specified.  */
438 #define LINK_SYSROOT_SPEC "%{isysroot*:-syslibroot %*} "
439 
440 /* Suppress the addition of extra prefix paths when a sysroot is in use.  */
441 #define STANDARD_STARTFILE_PREFIX_1 ""
442 #define STANDARD_STARTFILE_PREFIX_2 ""
443 
444 
445 /* Please keep the random linker options in alphabetical order.
446    Note that options taking arguments may appear multiple times on a command
447    line with different arguments each time, so put a * after their names so
448    all of them get passed.  */
449 #define LINK_SPEC  \
450   "%{static}%{!static:%{!dynamic:-dynamic}} \
451    %:remove-outfile(-ldl) \
452    %:remove-outfile(-lm) \
453    %:remove-outfile(-lpthread) \
454    %{fgnu-runtime: %{static|static-libgcc: \
455                      %:replace-outfile(-lobjc libobjc-gnu.a%s); \
456                     :%:replace-outfile(-lobjc -lobjc-gnu )}}\
457    %{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran libgfortran.a%s)}\
458    %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos libgphobos.a%s)}\
459    %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp libgomp.a%s)}\
460    %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}\
461    %{force_cpusubtype_ALL:-arch %(darwin_arch)} \
462    %{!force_cpusubtype_ALL:-arch %(darwin_subarch)} "\
463    LINK_SYSROOT_SPEC \
464    "%{!multiply_defined*:%{shared-libgcc: \
465      %:version-compare(< 10.5 mmacosx-version-min= -multiply_defined) \
466      %:version-compare(< 10.5 mmacosx-version-min= suppress) }} \
467    %{sectalign*} %{sectcreate*} %{sectobjectsymbols*}  %{sectorder*} \
468    %{segaddr*} %{segcreate*} %{segprot*} "
469 
470 /* Machine dependent libraries.  */
471 
472 #define LIB_SPEC "%{!static:-lSystem}"
473 
474 /*
475    Note that by default, -lgcc_eh is not linked against.
476    This is because,in general, we need to unwind through system libraries that
477    are linked with the shared unwinder in libunwind (or libgcc_s for 10.4/5).
478 
479    For -static-libgcc: < 10.6, use the unwinder in libgcc_eh (and find
480    the emultls impl. there too).
481 
482    For -static-libgcc: >= 10.6, the unwinder *still* comes from libSystem and
483    we find the emutls impl from lemutls_w. In either case, the builtins etc.
484    are linked from -lgcc.
485 
486    When we have specified shared-libgcc or any case that might require
487    exceptions, we pull the libgcc content (including emulated tls) from
488    -lgcc_s.1 in GCC and the unwinder from /usr/lib/libgcc_s.1 for < 10.6 and
489    libSystem for >= 10.6 respectively.
490    Otherwise, we just link the emutls/builtins from convenience libs.
491 
492    If we need exceptions, prior to 10.3.9, then we have to link the static
493    eh lib, since there's no shared version on the system.
494 
495    In all cases, libgcc_s.1 will be installed with the compiler, or any app
496    built using it, so we can link the builtins and emutls shared on all.
497 
498    We have to work around that DYLD_XXXX are disabled in macOS 10.11+ which
499    means that any bootstrap trying to use a shared libgcc with a bumped SO-
500    name will fail.  This means that we do not accept shared libgcc for these
501    versions.
502 
503    For -static-libgcc: >= 10.6, the unwinder *still* comes from libSystem and
504    we find the emutls impl from lemutls_w. In either case, the builtins etc.
505    are linked from -lgcc.
506 >
507    Otherwise, we just link the shared version of gcc_s.1.1 and pick up
508    exceptions:
509      * Prior to 10.3.9, then we have to link the static eh lib, since there
510        is no shared version on the system.
511      * from 10.3.9 to 10.5, from /usr/lib/libgcc_s.1.dylib
512      * from 10.6 onwards, from libSystem.dylib
513 
514    In all cases, libgcc_s.1.1 will be installed with the compiler, or any app
515    built using it, so we can link the builtins and emutls shared on all.
516 */
517 #undef REAL_LIBGCC_SPEC
518 #define REAL_LIBGCC_SPEC \
519 "%{static-libgcc|static:						  \
520     %:version-compare(!> 10.6 mmacosx-version-min= -lgcc_eh);		  \
521    shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime:		  \
522     %:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1)	  \
523     %:version-compare(!> 10.3.9 mmacosx-version-min= -lgcc_eh)		  \
524     %:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4)   \
525     %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5)	  \
526   } -lgcc "
527 
528 #define DARWIN_WEAK_CRTS \
529 "%{static-libgcc|static:						  \
530    %:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w) ; \
531    shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \
532      %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) ; \
533    : -lemutls_w \
534   }"
535 
536 /* We specify crt0.o as -lcrt0.o so that ld will search the library path.  */
537 
538 #undef  STARTFILE_SPEC
539 #define STARTFILE_SPEC							    \
540 "%{dynamiclib|shared: %(darwin_dylib1) %{fgnu-tm: -lcrttms.o}}		   \
541  %{!dynamiclib:%{!shared:%{bundle:%(darwin_bundle1)}			    \
542      %{!bundle:%{pg:%{static:-lgcrt0.o}					    \
543                      %{!static:%{object:-lgcrt0.o}			    \
544                                %{!object:%{preload:-lgcrt0.o}		    \
545                                  %{!preload:-lgcrt1.o                       \
546                                  %:version-compare(>= 10.8 mmacosx-version-min= -no_new_main) \
547                                  %(darwin_crt2)}}}}    \
548                 %{!pg:%{static:-lcrt0.o}				    \
549                       %{!static:%{object:-lcrt0.o}			    \
550                                 %{!object:%{preload:-lcrt0.o}		    \
551                                   %{!preload: %(darwin_crt1)		    \
552 					      %(darwin_crt2)}}}}}}}	    \
553  %(darwin_crt3) "
554 
555 /* We want a destructor last in the list.  */
556 #define TM_DESTRUCTOR "%{fgnu-tm: -lcrttme.o}"
557 #define ENDFILE_SPEC TM_DESTRUCTOR
558 
559 #define DARWIN_EXTRA_SPECS						\
560   { "darwin_crt1", DARWIN_CRT1_SPEC },					\
561   { "darwin_crt2", DARWIN_CRT2_SPEC },					\
562   { "darwin_crt3", DARWIN_CRT3_SPEC },					\
563   { "darwin_dylib1", DARWIN_DYLIB1_SPEC },				\
564   { "darwin_bundle1", DARWIN_BUNDLE1_SPEC },
565 
566 #define DARWIN_CRT1_SPEC						\
567   "%:version-compare(!> 10.5 mmacosx-version-min= -lcrt1.o)		\
568    %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lcrt1.10.5.o)	\
569    %:version-compare(>< 10.6 10.8 mmacosx-version-min= -lcrt1.10.6.o)	\
570    %{fgnu-tm: -lcrttms.o}"
571 
572 #define DARWIN_CRT2_SPEC ""
573 
574 /* crt3.o provides __cxa_atexit on systems that don't have it (and a fix
575    up for faulty versions on 10.4).  Since it's only used with C++, which
576    requires passing -shared-libgcc, key off that to avoid unnecessarily
577    adding a destructor to every program built for 10.4 or earlier.  */
578 
579 #define DARWIN_CRT3_SPEC \
580 "%{shared-libgcc:%:version-compare(< 10.5 mmacosx-version-min= crt3.o%s)}"
581 
582 #define DARWIN_DYLIB1_SPEC						\
583   "%:version-compare(!> 10.5 mmacosx-version-min= -ldylib1.o)		\
584    %:version-compare(>< 10.5 10.6 mmacosx-version-min= -ldylib1.10.5.o)"
585 
586 #define DARWIN_BUNDLE1_SPEC \
587 "%{!static:%:version-compare(< 10.6 mmacosx-version-min= -lbundle1.o)	\
588 	   %{fgnu-tm: -lcrttms.o}}"
589 
590 #ifdef HAVE_AS_MMACOSX_VERSION_MIN_OPTION
591 /* Emit macosx version (but only major).  */
592 #define ASM_MMACOSX_VERSION_MIN_SPEC \
593 "%{asm_macosx_version_min=*: -mmacosx-version-min=%* } \
594    %<asm_macosx_version_min=* "
595 #else
596 #define ASM_MMACOSX_VERSION_MIN_SPEC " %<asm_macosx_version_min=* "
597 #endif
598 
599 #if HAVE_GNU_AS
600 /* The options are added in gcc.cc for this case.  */
601 #define ASM_OPTIONS ""
602 #else
603 /* When we detect that we're cctools or llvm as, we need to insert the right
604    additional options.  Actually, currently these are the same as GAS.  */
605 #define ASM_OPTIONS "%{v} %{w:-W} %{I*}"
606 #endif
607 
608 /* Default Darwin ASM_SPEC, very simple. */
609 #define ASM_SPEC \
610 "%{static} -arch %(darwin_arch) " \
611 ASM_OPTIONS ASM_MMACOSX_VERSION_MIN_SPEC
612 
613 #ifdef HAVE_AS_STABS_DIRECTIVE
614 /* We only pass a debug option to the assembler if that supports stabs, since
615    dwarf is not uniformly supported in the assemblers.  */
616 #define ASM_DEBUG_SPEC  "%{g*:%{%:debug-level-gt(0):%{!gdwarf*:--gstabs}}}"
617 #else
618 #define ASM_DEBUG_SPEC  ""
619 #endif
620 
621 #undef  ASM_DEBUG_OPTION_SPEC
622 #define ASM_DEBUG_OPTION_SPEC	""
623 
624 #define ASM_FINAL_SPEC \
625   "%{gsplit-dwarf:%ngsplit-dwarf is not supported on this platform} \
626      %<gsplit-dwarf"
627 
628 /* We now require C++11 to bootstrap and newer tools than those based on
629    stabs, so require DWARF-2, even if stabs is supported by the assembler.  */
630 
631 #define DWARF2_DEBUGGING_INFO 1
632 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
633 
634 #ifdef HAVE_AS_STABS_DIRECTIVE
635 #define DBX_DEBUGGING_INFO 1
636 #endif
637 
638 #define DEBUG_FRAME_SECTION	  "__DWARF,__debug_frame,regular,debug"
639 #define DEBUG_INFO_SECTION	  "__DWARF,__debug_info,regular,debug"
640 #define DEBUG_ABBREV_SECTION	  "__DWARF,__debug_abbrev,regular,debug"
641 #define DEBUG_ARANGES_SECTION	  "__DWARF,__debug_aranges,regular,debug"
642 #define DEBUG_MACINFO_SECTION	  "__DWARF,__debug_macinfo,regular,debug"
643 #define DEBUG_LINE_SECTION	  "__DWARF,__debug_line,regular,debug"
644 #define DEBUG_LOC_SECTION	  "__DWARF,__debug_loc,regular,debug"
645 #define DEBUG_LOCLISTS_SECTION    "__DWARF,__debug_loclists,regular,debug"
646 
647 #define DEBUG_STR_SECTION	  "__DWARF,__debug_str,regular,debug"
648 #define DEBUG_STR_OFFSETS_SECTION "__DWARF,__debug_str_offs,regular,debug"
649 #define DEBUG_RANGES_SECTION	  "__DWARF,__debug_ranges,regular,debug"
650 #define DEBUG_RNGLISTS_SECTION    "__DWARF,__debug_rnglists,regular,debug"
651 #define DEBUG_MACRO_SECTION       "__DWARF,__debug_macro,regular,debug"
652 
653 #define DEBUG_LTO_INFO_SECTION	  "__GNU_DWARF_LTO,__debug_info,regular,debug"
654 #define DEBUG_LTO_ABBREV_SECTION  "__GNU_DWARF_LTO,__debug_abbrev,regular,debug"
655 #define DEBUG_LTO_MACINFO_SECTION "__GNU_DWARF_LTO,__debug_macinfo,regular,debug"
656 #define DEBUG_LTO_LINE_SECTION	  "__GNU_DWARF_LTO,__debug_line,regular,debug"
657 #define DEBUG_LTO_STR_SECTION	  "__GNU_DWARF_LTO,__debug_str,regular,debug"
658 #define DEBUG_LTO_MACRO_SECTION   "__GNU_DWARF_LTO,__debug_macro,regular,debug"
659 
660 #define TARGET_WANT_DEBUG_PUB_SECTIONS true
661 #define DEBUG_PUBNAMES_SECTION   ((debug_generate_pub_sections == 2) \
662                                ? "__DWARF,__debug_gnu_pubn,regular,debug" \
663                                : "__DWARF,__debug_pubnames,regular,debug")
664 
665 #define DEBUG_PUBTYPES_SECTION   ((debug_generate_pub_sections == 2) \
666                                ? "__DWARF,__debug_gnu_pubt,regular,debug" \
667                                : "__DWARF,__debug_pubtypes,regular,debug")
668 
669 /* When generating stabs debugging, use N_BINCL entries.  */
670 
671 #define DBX_USE_BINCL
672 
673 /* There is no limit to the length of stabs strings.  */
674 
675 #define DBX_CONTIN_LENGTH 0
676 
677 /* gdb needs a null N_SO at the end of each file for scattered loading.  */
678 
679 #define DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
680 
681 /* GCC's definition of 'one_only' is the same as its definition of 'weak'.  */
682 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
683 
684 /* Mach-O supports 'weak imports', and 'weak definitions' in coalesced
685    sections.  machopic_select_section ensures that weak variables go in
686    coalesced sections.  Weak aliases (or any other kind of aliases) are
687    not supported.  Weak symbols that aren't visible outside the .s file
688    are not supported.  */
689 #define ASM_WEAKEN_DECL(FILE, DECL, NAME, ALIAS)			\
690   do {									\
691     if (ALIAS)								\
692       {									\
693 	warning (0, "alias definitions not supported in Mach-O; ignored");	\
694 	break;								\
695       }									\
696  									\
697     if (! DECL_EXTERNAL (DECL) && TREE_PUBLIC (DECL))			\
698       targetm.asm_out.globalize_label (FILE, NAME);			\
699     if (DECL_EXTERNAL (DECL))						\
700       fputs ("\t.weak_reference ", FILE);				\
701     else if (lookup_attribute ("weak_import", DECL_ATTRIBUTES (DECL)))	\
702       break;								\
703     else if (TREE_PUBLIC (DECL))					\
704       fputs ("\t.weak_definition ", FILE);				\
705     else								\
706       break;								\
707     assemble_name (FILE, NAME);						\
708     fputc ('\n', FILE);							\
709   } while (0)
710 
711 /* Darwin has the pthread routines in libSystem, which every program
712    links to, so there's no need for weak-ness for that.  */
713 #define GTHREAD_USE_WEAK 0
714 
715 /* On Darwin, we don't (at the time of writing) have linkonce sections
716    with names, so it's safe to make the class data not comdat.  */
717 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT hook_bool_void_false
718 
719 /* For efficiency, on Darwin the RTTI information that is always
720    emitted in the standard C++ library should not be COMDAT.  */
721 #define TARGET_CXX_LIBRARY_RTTI_COMDAT hook_bool_void_false
722 
723 /* We make exception information linkonce. */
724 #undef TARGET_USES_WEAK_UNWIND_INFO
725 #define TARGET_USES_WEAK_UNWIND_INFO 1
726 
727 /* We need to use a nonlocal label for the start of an EH frame: the
728    Darwin linker requires that a coalesced section start with a label.
729    Unfortunately, it also requires that 'debug' sections don't contain
730    labels.  */
731 #undef FRAME_BEGIN_LABEL
732 #define FRAME_BEGIN_LABEL (for_eh ? "EH_frame" : "Lframe")
733 
734 /* Emit a label for the FDE corresponding to DECL.  EMPTY means
735    emit a label for an empty FDE. */
736 #define TARGET_ASM_EMIT_UNWIND_LABEL darwin_emit_unwind_label
737 
738 /* Emit a label to separate the exception table.  */
739 #define TARGET_ASM_EMIT_EXCEPT_TABLE_LABEL darwin_emit_except_table_label
740 
741 /* Make an EH (personality or LDSA) symbol indirect as needed.  */
742 #define TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT darwin_make_eh_symbol_indirect
743 
744 /* Some of Darwin's unwinders need current frame address state to be reset
745    after a DW_CFA_restore_state recovers the register values.  */
746 #undef TARGET_ASM_SHOULD_RESTORE_CFA_STATE
747 #define TARGET_ASM_SHOULD_RESTORE_CFA_STATE darwin_should_restore_cfa_state
748 
749 /* Our profiling scheme doesn't LP labels and counter words.  */
750 
751 #define NO_PROFILE_COUNTERS	1
752 
753 #undef	INIT_SECTION_ASM_OP
754 #define INIT_SECTION_ASM_OP ""
755 
756 #undef	INVOKE__main
757 
758 #define TARGET_ASM_CONSTRUCTOR  machopic_asm_out_constructor
759 #define TARGET_ASM_DESTRUCTOR   machopic_asm_out_destructor
760 
761 /* Always prefix with an underscore.  */
762 
763 #define USER_LABEL_PREFIX "_"
764 
765 /* A dummy symbol that will be replaced with the function base name.  */
766 #define MACHOPIC_FUNCTION_BASE_NAME "<pic base>"
767 
768 /* Don't output a .file directive.  That is only used by the assembler for
769    error reporting.  */
770 #undef	TARGET_ASM_FILE_START_FILE_DIRECTIVE
771 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE false
772 
773 #undef  TARGET_ASM_FILE_END
774 #define TARGET_ASM_FILE_END darwin_file_end
775 
776 /* Because Mach-O relocations have a counter from 1 to 255 for the
777    section number they apply to, it is necessary to output all
778    normal sections before the LTO sections, to make sure that the
779    sections that may have relocations always have a section number
780    smaller than 255.  */
781 #undef  TARGET_ASM_LTO_START
782 #define TARGET_ASM_LTO_START darwin_asm_lto_start
783 #undef  TARGET_ASM_LTO_END
784 #define TARGET_ASM_LTO_END darwin_asm_lto_end
785 
786 #define ASM_OUTPUT_SKIP(FILE,SIZE)  \
787   fprintf (FILE, "\t.space " HOST_WIDE_INT_PRINT_UNSIGNED"\n", SIZE)
788 
789 /* Give ObjC methods pretty symbol names.  */
790 
791 #undef	OBJC_GEN_METHOD_LABEL
792 #define OBJC_GEN_METHOD_LABEL(BUF,IS_INST,CLASS_NAME,CAT_NAME,SEL_NAME,NUM) \
793   do { if (CAT_NAME)							\
794 	 sprintf (BUF, "%c[%s(%s) %s]", (IS_INST) ? '-' : '+',		\
795 		  (CLASS_NAME), (CAT_NAME), (SEL_NAME));		\
796        else								\
797 	 sprintf (BUF, "%c[%s %s]", (IS_INST) ? '-' : '+',		\
798 		  (CLASS_NAME), (SEL_NAME));				\
799      } while (0)
800 
801 #undef ASM_DECLARE_OBJECT_NAME
802 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
803 	darwin_asm_declare_object_name ((FILE), (NAME), (DECL))
804 
805 /* The RTTI data (e.g., __ti4name) is common and public (and static),
806    but it does need to be referenced via indirect PIC data pointers.
807    The machopic_define_symbol calls are telling the machopic subsystem
808    that the name *is* defined in this module, so it doesn't need to
809    make them indirect.  */
810 
811 #undef ASM_DECLARE_FUNCTION_NAME
812 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)			\
813   do {									\
814     const char *xname = NAME;						\
815     if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF)		\
816       xname = IDENTIFIER_POINTER (DECL_NAME (DECL));			\
817     if (! DECL_WEAK (DECL)						\
818         && ((TREE_STATIC (DECL)						\
819 	     && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))		\
820             || DECL_INITIAL (DECL)))					\
821         machopic_define_symbol (DECL_RTL (DECL));			\
822     if ((TREE_STATIC (DECL)						\
823 	 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))		\
824         || DECL_INITIAL (DECL))						\
825       (* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false);	\
826     ASM_OUTPUT_FUNCTION_LABEL (FILE, xname, DECL);			\
827   } while (0)
828 
829 #undef TARGET_ASM_DECLARE_CONSTANT_NAME
830 #define TARGET_ASM_DECLARE_CONSTANT_NAME darwin_asm_declare_constant_name
831 
832 /* Wrap new method names in quotes so the assembler doesn't gag.
833    Make Objective-C internal symbols local and in doing this, we need
834    to accommodate the name mangling done by c++ on file scope locals.  */
835 
836 int darwin_label_is_anonymous_local_objc_name (const char *name);
837 
838 #undef	ASM_OUTPUT_LABELREF
839 #define ASM_OUTPUT_LABELREF(FILE,NAME)					     \
840   do {									     \
841        const char *xname = (NAME);					     \
842        if (! strcmp (xname, MACHOPIC_FUNCTION_BASE_NAME))		     \
843          machopic_output_function_base_name(FILE);                           \
844        else if (xname[0] == '&' || xname[0] == '*')			     \
845          {								     \
846            int len = strlen (xname);					     \
847 	   if (len > 6 && !strcmp ("$stub", xname + len - 5))		     \
848 	     machopic_validate_stub_or_non_lazy_ptr (xname);		     \
849 	   else if (len > 7 && !strcmp ("$stub\"", xname + len - 6))	     \
850 	     machopic_validate_stub_or_non_lazy_ptr (xname);		     \
851 	   else if (len > 14 && !strcmp ("$non_lazy_ptr", xname + len - 13)) \
852 	     machopic_validate_stub_or_non_lazy_ptr (xname);		     \
853 	   else if (len > 15 && !strcmp ("$non_lazy_ptr\"", xname + len - 14)) \
854 	     machopic_validate_stub_or_non_lazy_ptr (xname);		     \
855 	   if (xname[1] != '"' && name_needs_quotes (&xname[1]))	     \
856 	     fprintf (FILE, "\"%s\"", &xname[1]);			     \
857 	   else								     \
858 	     fputs (&xname[1], FILE); 					     \
859 	 }								     \
860        else if (xname[0] == '+' || xname[0] == '-')			     \
861          fprintf (FILE, "\"%s\"", xname);				     \
862        else if (darwin_label_is_anonymous_local_objc_name (xname))	     \
863 	fprintf (FILE, "%c%s", flag_next_runtime ? 'L' : 'l', xname);	     \
864        else if (strncmp (xname, "__anon_cfstring", 15) == 0)		     \
865 	fprintf (FILE, "L%s", xname);					     \
866        else if (xname[0] != '"' && name_needs_quotes (xname))		     \
867 	 asm_fprintf (FILE, "\"%U%s\"", xname);				     \
868        else								     \
869          asm_fprintf (FILE, "%U%s", xname);				     \
870   } while (0)
871 
872 /* Output before executable code.  */
873 #undef TEXT_SECTION_ASM_OP
874 #define TEXT_SECTION_ASM_OP "\t.text"
875 
876 /* Output before writable data.  */
877 
878 #undef DATA_SECTION_ASM_OP
879 #define DATA_SECTION_ASM_OP "\t.data"
880 
881 #undef	ALIGN_ASM_OP
882 #define ALIGN_ASM_OP		".align"
883 
884 #undef	ASM_OUTPUT_ALIGN
885 #define ASM_OUTPUT_ALIGN(FILE,LOG)	\
886   if ((LOG) != 0)			\
887     fprintf (FILE, "\t%s\t%d\n", ALIGN_ASM_OP, (LOG))
888 
889 /* The maximum alignment which the object file format can support in bits
890    which depends on the OS version and whether the object is a common
891    variable.  */
892 
893 #undef	MAX_OFILE_ALIGNMENT
894 #define MAX_OFILE_ALIGNMENT ((1U << L2_MAX_OFILE_ALIGNMENT) * 8U)
895 
896 /*  These are the three variants that emit referenced blank space.  */
897 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN)		\
898 	darwin_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
899 
900 #undef	ASM_OUTPUT_ALIGNED_DECL_LOCAL
901 #define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN)	\
902 	darwin_asm_output_aligned_decl_local				\
903 				  ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
904 
905 #undef  ASM_OUTPUT_ALIGNED_DECL_COMMON
906 #define ASM_OUTPUT_ALIGNED_DECL_COMMON(FILE, DECL, NAME, SIZE, ALIGN)	\
907 	darwin_asm_output_aligned_decl_common				\
908 				   ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
909 
910 /* The generic version, archs should over-ride where required.  */
911 #define MACHOPIC_NL_SYMBOL_PTR_SECTION ".non_lazy_symbol_pointer"
912 
913 /* Declare the section variables.  */
914 #ifndef USED_FOR_TARGET
915 enum darwin_section_enum {
916 #define DEF_SECTION(NAME, FLAGS, DIRECTIVE, OBJC) NAME,
917 #include "darwin-sections.def"
918 #undef DEF_SECTION
919   NUM_DARWIN_SECTIONS
920 };
921 extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
922 #endif
923 
924 #undef	TARGET_ASM_SELECT_SECTION
925 #define TARGET_ASM_SELECT_SECTION machopic_select_section
926 
927 #undef	TARGET_ASM_FUNCTION_SECTION
928 #define TARGET_ASM_FUNCTION_SECTION darwin_function_section
929 
930 #undef	TARGET_ASM_SELECT_RTX_SECTION
931 #define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
932 #undef  TARGET_ASM_UNIQUE_SECTION
933 #define TARGET_ASM_UNIQUE_SECTION darwin_unique_section
934 #undef  TARGET_ASM_FUNCTION_RODATA_SECTION
935 #define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
936 
937 #undef  TARGET_ASM_TM_CLONE_TABLE_SECTION
938 #define TARGET_ASM_TM_CLONE_TABLE_SECTION darwin_tm_clone_table_section
939 
940 #undef  TARGET_ASM_RELOC_RW_MASK
941 #define TARGET_ASM_RELOC_RW_MASK machopic_reloc_rw_mask
942 
943 /* Globalizing directive for a label.  */
944 #define GLOBAL_ASM_OP "\t.globl "
945 #define TARGET_ASM_GLOBALIZE_LABEL darwin_globalize_label
946 
947 /* Emit an assembler directive to set visibility for a symbol.  Used
948    to support visibility attribute and Darwin's private extern
949    feature.  */
950 #undef TARGET_ASM_ASSEMBLE_VISIBILITY
951 #define TARGET_ASM_ASSEMBLE_VISIBILITY darwin_assemble_visibility
952 
953 /* Extra attributes for Darwin.  */
954 #define SUBTARGET_ATTRIBUTE_TABLE					     \
955   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,		     \
956        affects_type_identity, handler, exclude } */			     \
957   { "apple_kext_compatibility", 0, 0, false, true, false, false,	     \
958     darwin_handle_kext_attribute, NULL },				     \
959   { "weak_import", 0, 0, true, false, false, false,			     \
960     darwin_handle_weak_import_attribute, NULL }
961 
962 /* Make local constant labels linker-visible, so that if one follows a
963    weak_global constant, ld64 will be able to separate the atoms.  */
964 #undef ASM_GENERATE_INTERNAL_LABEL
965 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)	\
966   do {							\
967     if (strcmp ("LC", PREFIX) == 0)			\
968       sprintf (LABEL, "*%s%ld", "lC", (long)(NUM));	\
969     else if (strcmp ("Lubsan_data", PREFIX) == 0)	\
970       sprintf (LABEL, "*%s%ld", "lubsan_data", (long)(NUM));\
971     else if (strcmp ("Lubsan_type", PREFIX) == 0)	\
972       sprintf (LABEL, "*%s%ld", "lubsan_type", (long)(NUM));\
973     else if (strcmp ("LASAN", PREFIX) == 0)	\
974       sprintf (LABEL, "*%s%ld", "lASAN", (long)(NUM));\
975     else if (strcmp ("LTRAMP", PREFIX) == 0)	\
976       sprintf (LABEL, "*%s%ld", "lTRAMP", (long)(NUM));\
977     else						\
978       sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM));	\
979   } while (0)
980 
981 #undef TARGET_ASM_MARK_DECL_PRESERVED
982 #define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved
983 
984 /* Any port using this header needs to define the first available
985    subtarget symbol bit: SYMBOL_FLAG_SUBT_DEP.  */
986 
987 /* Is a variable. */
988 #define MACHO_SYMBOL_FLAG_VARIABLE (SYMBOL_FLAG_SUBT_DEP)
989 #define MACHO_SYMBOL_VARIABLE_P(RTX) \
990   ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_VARIABLE) != 0)
991 
992 /* Set on a symbol that must be indirected, even when there is a
993    definition in the TU.  The ABI mandates that common symbols are so
994    indirected, as are weak.  If 'fix-and-continue' is operational then
995    data symbols might also be.  */
996 
997 #define MACHO_SYMBOL_FLAG_MUST_INDIRECT ((SYMBOL_FLAG_SUBT_DEP) << 1)
998 #define MACHO_SYMBOL_MUST_INDIRECT_P(RTX) \
999   ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_MUST_INDIRECT) != 0)
1000 
1001 /* Set on a symbol with SYMBOL_FLAG_FUNCTION or MACHO_SYMBOL_FLAG_VARIABLE
1002    to indicate that the function or variable is considered defined in this
1003    translation unit.  */
1004 
1005 #define MACHO_SYMBOL_FLAG_DEFINED ((SYMBOL_FLAG_SUBT_DEP) << 2)
1006 #define MACHO_SYMBOL_DEFINED_P(RTX) \
1007   ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_DEFINED) != 0)
1008 
1009 /* Set on a symbol that has specified non-default visibility.  */
1010 
1011 #define MACHO_SYMBOL_FLAG_HIDDEN_VIS ((SYMBOL_FLAG_SUBT_DEP) << 3)
1012 #define MACHO_SYMBOL_HIDDEN_VIS_P(RTX) \
1013   ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_HIDDEN_VIS) != 0)
1014 
1015 /* Set on a symbol that should be made visible to the linker (overriding
1016    'L' symbol prefixes).  */
1017 
1018 #define MACHO_SYMBOL_FLAG_LINKER_VIS ((SYMBOL_FLAG_SUBT_DEP) << 4)
1019 #define MACHO_SYMBOL_LINKER_VIS_P(RTX) \
1020   ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_LINKER_VIS) != 0)
1021 
1022 /* Set on a symbol that is a pic stub or symbol indirection (i.e. the
1023    L_xxxxx${stub,non_lazy_ptr,lazy_ptr}.  */
1024 
1025 #define MACHO_SYMBOL_FLAG_INDIRECTION ((SYMBOL_FLAG_SUBT_DEP) << 5)
1026 #define MACHO_SYMBOL_INDIRECTION_P(RTX) \
1027   ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_INDIRECTION) != 0)
1028 
1029 /* Set on a symbol to indicate when fix-and-continue style code
1030    generation is being used and the symbol refers to a static symbol
1031    that should be rebound from new instances of a translation unit to
1032    the original instance of the data.  */
1033 
1034 #define MACHO_SYMBOL_FLAG_STATIC ((SYMBOL_FLAG_SUBT_DEP) << 6)
1035 #define MACHO_SYMBOL_STATIC_P(RTX) \
1036   ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_STATIC) != 0)
1037 
1038 /* Symbolic names for various things we might know about a symbol.  */
1039 
1040 enum machopic_addr_class {
1041   MACHOPIC_UNDEFINED,
1042   MACHOPIC_DEFINED_DATA,
1043   MACHOPIC_UNDEFINED_DATA,
1044   MACHOPIC_DEFINED_FUNCTION,
1045   MACHOPIC_UNDEFINED_FUNCTION
1046 };
1047 
1048 /* Macros defining the various PIC cases.  */
1049 
1050 #undef  MACHO_DYNAMIC_NO_PIC_P
1051 #define MACHO_DYNAMIC_NO_PIC_P	(TARGET_MACHO_DYNAMIC_NO_PIC)
1052 #undef  MACHOPIC_INDIRECT
1053 #define MACHOPIC_INDIRECT	(flag_pic || MACHO_DYNAMIC_NO_PIC_P)
1054 #define MACHOPIC_JUST_INDIRECT	(MACHO_DYNAMIC_NO_PIC_P)
1055 #undef  MACHOPIC_PURE
1056 #define MACHOPIC_PURE		(flag_pic && ! MACHO_DYNAMIC_NO_PIC_P)
1057 
1058 #undef TARGET_ENCODE_SECTION_INFO
1059 #define TARGET_ENCODE_SECTION_INFO  darwin_encode_section_info
1060 #undef TARGET_STRIP_NAME_ENCODING
1061 #define TARGET_STRIP_NAME_ENCODING  default_strip_name_encoding
1062 
1063 #define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH)		\
1064   do {								\
1065     const char *const stub_ = (STUB);				\
1066     char *buffer_ = (BUF);					\
1067     strcpy (buffer_, stub_);					\
1068     if (stub_[0] == '"')					\
1069       {								\
1070 	strcpy (buffer_ + (STUB_LENGTH) - 1, "_binder\"");	\
1071       }								\
1072     else							\
1073       {								\
1074 	strcpy (buffer_ + (STUB_LENGTH), "_binder");		\
1075       }								\
1076   } while (0)
1077 
1078 #define GEN_SYMBOL_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH)	\
1079   do {								\
1080     const char *const symbol_ = (SYMBOL);			\
1081     char *buffer_ = (BUF);					\
1082     if (name_needs_quotes (symbol_) && symbol_[0] != '"')	\
1083       {								\
1084 	  sprintf (buffer_, "\"%s\"", symbol_);			\
1085       }								\
1086     else							\
1087       {								\
1088 	strcpy (buffer_, symbol_);				\
1089       }								\
1090   } while (0)
1091 
1092 /* Given a symbol name string, create the lazy pointer version
1093    of the symbol name.  */
1094 
1095 #define GEN_LAZY_PTR_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH)	\
1096   do {								\
1097     const char *symbol_ = (SYMBOL);                             \
1098     char *buffer_ = (BUF);					\
1099     if (symbol_[0] == '"')					\
1100       {								\
1101         strcpy (buffer_, "\"L");				\
1102         strcpy (buffer_ + 2, symbol_ + 1);			\
1103 	strcpy (buffer_ + (SYMBOL_LENGTH), "$lazy_ptr\"");	\
1104       }								\
1105     else if (name_needs_quotes (symbol_))			\
1106       {								\
1107         strcpy (buffer_, "\"L");				\
1108         strcpy (buffer_ + 2, symbol_);				\
1109 	strcpy (buffer_ + (SYMBOL_LENGTH) + 2, "$lazy_ptr\"");	\
1110       }								\
1111     else							\
1112       {								\
1113         strcpy (buffer_, "L");					\
1114         strcpy (buffer_ + 1, symbol_);				\
1115 	strcpy (buffer_ + (SYMBOL_LENGTH) + 1, "$lazy_ptr");	\
1116       }								\
1117   } while (0)
1118 
1119 #define EH_FRAME_SECTION_NAME   "__TEXT"
1120 #define EH_FRAME_SECTION_ATTR ",coalesced,no_toc+strip_static_syms+live_support"
1121 
1122 #undef ASM_PREFERRED_EH_DATA_FORMAT
1123 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL)  \
1124   (((CODE) == 2 && (GLOBAL) == 1) || ((CODE) == 0 && (GLOBAL) == 1) \
1125    ? (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4) : \
1126      ((CODE) == 1 || (GLOBAL) == 0) ? DW_EH_PE_pcrel : DW_EH_PE_absptr)
1127 
1128 #define ASM_OUTPUT_DWARF_DELTA(FILE,SIZE,LABEL1,LABEL2)  \
1129   darwin_asm_output_dwarf_delta (FILE, SIZE, LABEL1, LABEL2, 0)
1130 
1131 #define ASM_OUTPUT_DWARF_OFFSET(FILE,SIZE,LABEL,OFFSET,BASE)  \
1132   darwin_asm_output_dwarf_offset (FILE, SIZE, LABEL, OFFSET, BASE)
1133 
1134 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(ASM_OUT_FILE, ENCODING, SIZE, ADDR, DONE)	\
1135       if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) {				\
1136 	darwin_non_lazy_pcrel (ASM_OUT_FILE, ADDR);					\
1137 	goto DONE;									\
1138       }
1139 
1140 /* Experimentally, putting jump tables in text is faster on SPEC.
1141    Also this is needed for correctness for coalesced functions.  */
1142 
1143 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1144 #define JUMP_TABLES_IN_TEXT_SECTION 1
1145 #endif
1146 
1147 #define TARGET_TERMINATE_DW2_EH_FRAME_INFO false
1148 
1149 #define TARGET_ASM_INIT_SECTIONS darwin_init_sections
1150 #undef TARGET_ASM_NAMED_SECTION
1151 #define TARGET_ASM_NAMED_SECTION darwin_asm_named_section
1152 
1153 #define DARWIN_REGISTER_TARGET_PRAGMAS()			\
1154   do {								\
1155     if (!flag_preprocess_only)					\
1156       cpp_register_pragma (parse_in, NULL, "mark",		\
1157 			   darwin_pragma_ignore, false);	\
1158     c_register_pragma (0, "options", darwin_pragma_options);	\
1159     c_register_pragma (0, "segment", darwin_pragma_ignore);	\
1160     c_register_pragma (0, "unused", darwin_pragma_unused);	\
1161     c_register_pragma (0, "ms_struct", darwin_pragma_ms_struct); \
1162   } while (0)
1163 
1164 #undef ASM_APP_ON
1165 #define ASM_APP_ON ""
1166 #undef ASM_APP_OFF
1167 #define ASM_APP_OFF ""
1168 
1169 void darwin_register_frameworks (const char *, const char *, int);
1170 void darwin_register_objc_includes (const char *, const char *, int);
1171 #define TARGET_EXTRA_PRE_INCLUDES darwin_register_objc_includes
1172 #define TARGET_EXTRA_INCLUDES darwin_register_frameworks
1173 
1174 void add_framework_path (char *);
1175 #define TARGET_OPTF add_framework_path
1176 
1177 #define TARGET_POSIX_IO
1178 
1179 #define WINT_TYPE "int"
1180 
1181 /* Every program on darwin links against libSystem which contains the pthread
1182    routines, so there's no need to explicitly call out when doing threaded
1183    work.  */
1184 
1185 #undef GOMP_SELF_SPECS
1186 #define GOMP_SELF_SPECS ""
1187 #undef GTM_SELF_SPECS
1188 #define GTM_SELF_SPECS ""
1189 
1190 /* Darwin disables section anchors by default.
1191    They should be enabled per arch where support exists in that arch.  */
1192 #define TARGET_ASM_OUTPUT_ANCHOR NULL
1193 #define DARWIN_SECTION_ANCHORS 0
1194 
1195 #define HAVE_ENABLE_EXECUTE_STACK
1196 
1197 /* For Apple KEXTs, we make the constructors return this to match gcc
1198    2.95.  */
1199 #define TARGET_CXX_CDTOR_RETURNS_THIS (darwin_kextabi_p)
1200 #define TARGET_KEXTABI flag_apple_kext
1201 
1202 /* We have target-specific builtins.  */
1203 #define SUBTARGET_FOLD_BUILTIN darwin_fold_builtin
1204 
1205 #define TARGET_N_FORMAT_TYPES 1
1206 #define TARGET_FORMAT_TYPES darwin_additional_format_types
1207 
1208 #ifndef USED_FOR_TARGET
1209 extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **);
1210 #define GCC_DRIVER_HOST_INITIALIZATION \
1211   darwin_driver_init (&decoded_options_count, &decoded_options)
1212 #endif
1213 
1214 /* The Apple assembler and linker do not support constructor priorities.  */
1215 #undef SUPPORTS_INIT_PRIORITY
1216 #define SUPPORTS_INIT_PRIORITY 0
1217 
1218 #undef STACK_CHECK_STATIC_BUILTIN
1219 #define STACK_CHECK_STATIC_BUILTIN 1
1220 
1221 /* When building cross-compilers (and native crosses) we shall default to
1222    providing an osx-version-min of this unless overridden by the User.
1223    10.5 is the only version that fully supports all our archs so that's the
1224    fall-back default.  */
1225 #ifndef DEF_MIN_OSX_VERSION
1226 #define DEF_MIN_OSX_VERSION "10.5"
1227 #endif
1228 
1229 /* Later versions of ld64 support coalescing weak code/data without requiring
1230    that they be placed in specially identified sections.  This is the earliest
1231    _tested_ version known to support this so far.  */
1232 #define MIN_LD64_NO_COAL_SECTS "236.3"
1233 
1234 /* From at least version 62.1, ld64 can build symbol indirection stubs as
1235    needed, and there is no need for the compiler to emit them.  */
1236 #define MIN_LD64_OMIT_STUBS "62.1"
1237 
1238 /* Emit start labels for init and term sections from this version.  */
1239 #define MIN_LD64_INIT_TERM_START_LABELS "136.0"
1240 
1241 /* If we have no definition for the linker version, pick the minimum version
1242    that will bootstrap the compiler.  */
1243 #ifndef LD64_VERSION
1244 # ifndef  DEF_LD64
1245 #  define LD64_VERSION "85.2.1"
1246 # else
1247 #  define LD64_VERSION DEF_LD64
1248 # endif
1249 #endif
1250 
1251 /* CTF and BTF support.  */
1252 #undef CTF_INFO_SECTION_NAME
1253 #define CTF_INFO_SECTION_NAME "__CTF_BTF,__ctf,regular,debug"
1254 #undef BTF_INFO_SECTION_NAME
1255 #define BTF_INFO_SECTION_NAME "__CTF_BTF,__btf,regular,debug"
1256 
1257 #endif /* CONFIG_DARWIN_H */
1258