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