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