190075Sobrien/* Target definitions for Darwin (Mac OS X) systems.
2169689Skan   Copyright (C) 1989, 1990, 1991, 1992, 1993, 2000, 2001, 2002, 2003, 2004,
3169689Skan   2005
490075Sobrien   Free Software Foundation, Inc.
590075Sobrien   Contributed by Apple Computer Inc.
690075Sobrien
7132718SkanThis file is part of GCC.
890075Sobrien
9132718SkanGCC is free software; you can redistribute it and/or modify
1090075Sobrienit under the terms of the GNU General Public License as published by
1190075Sobrienthe Free Software Foundation; either version 2, or (at your option)
1290075Sobrienany later version.
1390075Sobrien
14132718SkanGCC is distributed in the hope that it will be useful,
1590075Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of
1690075SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1790075SobrienGNU General Public License for more details.
1890075Sobrien
1990075SobrienYou should have received a copy of the GNU General Public License
20132718Skanalong with GCC; see the file COPYING.  If not, write to
21169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
22169689SkanBoston, MA 02110-1301, USA.  */
2390075Sobrien
24169689Skan#ifndef CONFIG_DARWIN_H
25169689Skan#define CONFIG_DARWIN_H
26169689Skan
2790075Sobrien/* The definitions in this file are common to all processor types
2890075Sobrien   running Darwin, which is the kernel for Mac OS X.  Darwin is
2990075Sobrien   basically a BSD user layer laid over a Mach kernel, then evolved
3090075Sobrien   for many years (at NeXT) in parallel with other Unix systems.  So
3190075Sobrien   while the runtime is a somewhat idiosyncratic Mach-based thing,
3290075Sobrien   other definitions look like they would for a BSD variant.  */
3390075Sobrien
3490075Sobrien/* Although NeXT ran on many different architectures, as of Jan 2001
3590075Sobrien   the only supported Darwin targets are PowerPC and x86.  */
3690075Sobrien
37117395Skan/* One of Darwin's NeXT legacies is the Mach-O format, which is partly
38117395Skan   like a.out and partly like COFF, with additional features like
39117395Skan   multi-architecture binary support.  */
40117395Skan
41117395Skan#define OBJECT_FORMAT_MACHO
42117395Skan
43169689Skan/* Suppress g++ attempt to link in the math library automatically. */
4490075Sobrien#define MATH_LIBRARY ""
4590075Sobrien
4690075Sobrien/* We have atexit.  */
4790075Sobrien
4890075Sobrien#define HAVE_ATEXIT
4990075Sobrien
5090075Sobrien/* Define an empty body for the function do_global_dtors() in libgcc2.c.  */
5190075Sobrien
5290075Sobrien#define DO_GLOBAL_DTORS_BODY
5390075Sobrien
5490075Sobrien/* The string value for __SIZE_TYPE__.  */
5590075Sobrien
5690075Sobrien#ifndef SIZE_TYPE
5790075Sobrien#define SIZE_TYPE "long unsigned int"
5890075Sobrien#endif
5990075Sobrien
6090075Sobrien/* Type used for ptrdiff_t, as a string used in a declaration.  */
6190075Sobrien
6290075Sobrien#undef  PTRDIFF_TYPE
6390075Sobrien#define PTRDIFF_TYPE "int"
6490075Sobrien
6590075Sobrien/* wchar_t is int.  */
6690075Sobrien
6790075Sobrien#undef	WCHAR_TYPE
6890075Sobrien#define WCHAR_TYPE "int"
6990075Sobrien#undef	WCHAR_TYPE_SIZE
7090075Sobrien#define WCHAR_TYPE_SIZE 32
7190075Sobrien
7290075Sobrien/* Default to using the NeXT-style runtime, since that's what is
7390075Sobrien   pre-installed on Darwin systems.  */
7490075Sobrien
7590075Sobrien#define NEXT_OBJC_RUNTIME
7690075Sobrien
7790075Sobrien/* Don't default to pcc-struct-return, because gcc is the only compiler, and
7890075Sobrien   we want to retain compatibility with older gcc versions.  */
7990075Sobrien
8090075Sobrien#undef	DEFAULT_PCC_STRUCT_RETURN
8190075Sobrien#define DEFAULT_PCC_STRUCT_RETURN 0
8290075Sobrien
83169689Skan/* True if pragma ms_struct is in effect.  */
84169689Skanextern GTY(()) int darwin_ms_struct;
85169689Skan
86117395Skan/* This table intercepts weirdo options whose names would interfere
87117395Skan   with normal driver conventions, and either translates them into
88117395Skan   standardly-named options, or adds a 'Z' so that they can get to
89117395Skan   specs processing without interference.
9090075Sobrien
91117395Skan   Do not expand a linker option to "-Xlinker -<option>", since that
92117395Skan   forfeits the ability to control via spec strings later.  However,
93117395Skan   as a special exception, do this translation with -filelist, because
94117395Skan   otherwise the driver will think there are no input files and quit.
95117395Skan   (The alternative would be to hack the driver to recognize -filelist
96117395Skan   specially, but it's simpler to use the translation table.)
9790075Sobrien
98117395Skan   Note that an option name with a prefix that matches another option
99117395Skan   name, that also takes an argument, needs to be modified so the
100117395Skan   prefix is different, otherwise a '*' after the shorter option will
101146895Skan   match with the longer one.
102146895Skan
103146895Skan   The SUBTARGET_OPTION_TRANSLATE_TABLE macro, which _must_ be defined
104146895Skan   in gcc/config/{i386,rs6000}/darwin.h, should contain any additional
105146895Skan   command-line option translations specific to the particular target
106146895Skan   architecture.  */
107146895Skan
108117395Skan#define TARGET_OPTION_TRANSLATE_TABLE \
109117395Skan  { "-all_load", "-Zall_load" },  \
110117395Skan  { "-allowable_client", "-Zallowable_client" },  \
111117395Skan  { "-arch_errors_fatal", "-Zarch_errors_fatal" },  \
112117395Skan  { "-bind_at_load", "-Zbind_at_load" },  \
113117395Skan  { "-bundle", "-Zbundle" },  \
114117395Skan  { "-bundle_loader", "-Zbundle_loader" },  \
115117395Skan  { "-weak_reference_mismatches", "-Zweak_reference_mismatches" },  \
116169689Skan  { "-dead_strip", "-Zdead_strip" }, \
117169689Skan  { "-no_dead_strip_inits_and_terms", "-Zno_dead_strip_inits_and_terms" }, \
118117395Skan  { "-dependency-file", "-MF" }, \
119117395Skan  { "-dylib_file", "-Zdylib_file" }, \
120117395Skan  { "-dynamic", "-Zdynamic" },  \
121117395Skan  { "-dynamiclib", "-Zdynamiclib" },  \
122117395Skan  { "-exported_symbols_list", "-Zexported_symbols_list" },  \
123169689Skan  { "-gfull", "-g -fno-eliminate-unused-debug-symbols" }, \
124169689Skan  { "-gused", "-g -feliminate-unused-debug-symbols" }, \
125169689Skan  { "-segaddr", "-Zsegaddr" }, \
126169689Skan  { "-segs_read_only_addr", "-Zsegs_read_only_addr" }, \
127169689Skan  { "-segs_read_write_addr", "-Zsegs_read_write_addr" }, \
128169689Skan  { "-seg_addr_table", "-Zseg_addr_table" }, \
129169689Skan  { "-seg_addr_table_filename", "-Zfn_seg_addr_table_filename" }, \
130169689Skan  { "-fapple-kext", "-fapple-kext -static -Wa,-static" }, \
131117395Skan  { "-filelist", "-Xlinker -filelist -Xlinker" },  \
132169689Skan  { "-findirect-virtual-calls", "-fapple-kext" }, \
133117395Skan  { "-flat_namespace", "-Zflat_namespace" },  \
134117395Skan  { "-force_cpusubtype_ALL", "-Zforce_cpusubtype_ALL" },  \
135117395Skan  { "-force_flat_namespace", "-Zforce_flat_namespace" },  \
136169689Skan  { "-framework", "-Xlinker -framework -Xlinker" },  \
137169689Skan  { "-fterminated-vtables", "-fapple-kext" }, \
138117395Skan  { "-image_base", "-Zimage_base" },  \
139117395Skan  { "-init", "-Zinit" },  \
140117395Skan  { "-install_name", "-Zinstall_name" },  \
141169689Skan  { "-mkernel", "-mkernel -static -Wa,-static" }, \
142117395Skan  { "-multiply_defined_unused", "-Zmultiplydefinedunused" },  \
143117395Skan  { "-multiply_defined", "-Zmultiply_defined" },  \
144117395Skan  { "-multi_module", "-Zmulti_module" },  \
145117395Skan  { "-static", "-static -Wa,-static" },  \
146117395Skan  { "-single_module", "-Zsingle_module" },  \
147169689Skan  { "-unexported_symbols_list", "-Zunexported_symbols_list" }, \
148146895Skan  SUBTARGET_OPTION_TRANSLATE_TABLE
14990075Sobrien
150169689Skan#define SUBSUBTARGET_OVERRIDE_OPTIONS					\
151169689Skan  do {									\
152169689Skan    darwin_override_options ();						\
153169689Skan  } while (0)
154169689Skan
155117395Skan/* These compiler options take n arguments.  */
15690075Sobrien
157117395Skan#undef  WORD_SWITCH_TAKES_ARG
158117395Skan#define WORD_SWITCH_TAKES_ARG(STR)              \
159117395Skan  (DEFAULT_WORD_SWITCH_TAKES_ARG (STR) ? 1 :    \
160117395Skan   !strcmp (STR, "Zallowable_client") ? 1 :     \
161117395Skan   !strcmp (STR, "arch") ? 1 :                  \
162117395Skan   !strcmp (STR, "arch_only") ? 1 :             \
163117395Skan   !strcmp (STR, "Zbundle_loader") ? 1 :        \
164117395Skan   !strcmp (STR, "client_name") ? 1 :           \
165117395Skan   !strcmp (STR, "compatibility_version") ? 1 : \
166117395Skan   !strcmp (STR, "current_version") ? 1 :       \
167117395Skan   !strcmp (STR, "Zdylib_file") ? 1 :           \
168117395Skan   !strcmp (STR, "Zexported_symbols_list") ? 1 : \
169117395Skan   !strcmp (STR, "Zimage_base") ? 1 :           \
170117395Skan   !strcmp (STR, "Zinit") ? 1 :                 \
171117395Skan   !strcmp (STR, "Zinstall_name") ? 1 :         \
172117395Skan   !strcmp (STR, "Zmultiplydefinedunused") ? 1 : \
173117395Skan   !strcmp (STR, "Zmultiply_defined") ? 1 :     \
174117395Skan   !strcmp (STR, "precomp-trustfile") ? 1 :     \
175117395Skan   !strcmp (STR, "read_only_relocs") ? 1 :      \
176117395Skan   !strcmp (STR, "sectcreate") ? 3 :            \
177117395Skan   !strcmp (STR, "sectorder") ? 3 :             \
178169689Skan   !strcmp (STR, "Zsegaddr") ? 2 :              \
179169689Skan   !strcmp (STR, "Zsegs_read_only_addr") ? 1 :  \
180169689Skan   !strcmp (STR, "Zsegs_read_write_addr") ? 1 : \
181169689Skan   !strcmp (STR, "Zseg_addr_table") ? 1 :       \
182169689Skan   !strcmp (STR, "Zfn_seg_addr_table_filename") ? 1 :\
183117395Skan   !strcmp (STR, "seg1addr") ? 1 :              \
184117395Skan   !strcmp (STR, "segprot") ? 3 :               \
185117395Skan   !strcmp (STR, "sub_library") ? 1 :           \
186117395Skan   !strcmp (STR, "sub_umbrella") ? 1 :          \
187117395Skan   !strcmp (STR, "umbrella") ? 1 :              \
188117395Skan   !strcmp (STR, "undefined") ? 1 :             \
189117395Skan   !strcmp (STR, "Zunexported_symbols_list") ? 1 : \
190117395Skan   !strcmp (STR, "Zweak_reference_mismatches") ? 1 : \
191117395Skan   !strcmp (STR, "pagezero_size") ? 1 :         \
192117395Skan   !strcmp (STR, "segs_read_only_addr") ? 1 :   \
193117395Skan   !strcmp (STR, "segs_read_write_addr") ? 1 :  \
194117395Skan   !strcmp (STR, "sectalign") ? 3 :             \
195117395Skan   !strcmp (STR, "sectobjectsymbols") ? 2 :     \
196117395Skan   !strcmp (STR, "segcreate") ? 3 :             \
197117395Skan   !strcmp (STR, "dylinker_install_name") ? 1 : \
198117395Skan   0)
19990075Sobrien
200169689Skan#define SUBTARGET_C_COMMON_OVERRIDE_OPTIONS do {                        \
201169689Skan    if (flag_mkernel || flag_apple_kext)				\
202169689Skan      {									\
203169689Skan	if (flag_use_cxa_atexit == 2)					\
204169689Skan	  flag_use_cxa_atexit = 0;					\
205169689Skan	/* kexts should always be built without the coalesced sections	\
206169689Skan	   because the kernel loader doesn't grok such sections.  */	\
207169689Skan	flag_weak = 0;							\
208169689Skan	/* No RTTI in kexts.  */					\
209169689Skan	flag_rtti = 0;							\
210169689Skan      }									\
211169689Skan  } while (0)
21290075Sobrien
213169689Skan/* Machine dependent cpp options.  Don't add more options here, add
214169689Skan   them to darwin_cpp_builtins in darwin-c.c.  */
215169689Skan
21690075Sobrien#undef	CPP_SPEC
217169689Skan#define CPP_SPEC "%{static:%{!dynamic:-D__STATIC__}}%{!static:-D__DYNAMIC__}" \
218169689Skan	" %{pthread:-D_REENTRANT}"
21990075Sobrien
220117395Skan/* This is mostly a clone of the standard LINK_COMMAND_SPEC, plus
221117395Skan   precomp, libtool, and fat build additions.  Also we
222117395Skan   don't specify a second %G after %L because libSystem is
223117395Skan   self-contained and doesn't need to link against libgcc.a.  */
224117395Skan/* In general, random Darwin linker flags should go into LINK_SPEC
225117395Skan   instead of LINK_COMMAND_SPEC.  The command spec is better for
226117395Skan   specifying the handling of options understood by generic Unix
227117395Skan   linkers, and for positional arguments like libraries.  */
228117395Skan#define LINK_COMMAND_SPEC "\
229117395Skan%{!fdump=*:%{!fsyntax-only:%{!precomp:%{!c:%{!M:%{!MM:%{!E:%{!S:\
230117395Skan    %{!Zdynamiclib:%(linker)}%{Zdynamiclib:/usr/bin/libtool} \
231117395Skan    %l %X %{d} %{s} %{t} %{Z} \
232117395Skan    %{!Zdynamiclib:%{A} %{e*} %{m} %{N} %{n} %{r} %{u*} %{x} %{z}} \
233117395Skan    %{@:-o %f%u.out}%{!@:%{o*}%{!o:-o a.out}} \
234169689Skan    %{!A:%{!nostdlib:%{!nostartfiles:%S}}} \
235169689Skan    %{L*} %{fopenmp:%:include(libgomp.spec)%(link_gomp)}   \
236169689Skan    %(link_libgcc) %o %{fprofile-arcs|fprofile-generate|coverage:-lgcov} \
237169689Skan    %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %G %L}} \
238169689Skan    %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*} }}}}}}}}"
239117395Skan
240169689Skan#ifdef TARGET_SYSTEM_ROOT
241169689Skan#define LINK_SYSROOT_SPEC \
242169689Skan  "%{isysroot*:-syslibroot %*;:-syslibroot " TARGET_SYSTEM_ROOT "}"
243169689Skan#else
244169689Skan#define LINK_SYSROOT_SPEC "%{isysroot*:-syslibroot %*}"
245169689Skan#endif
246169689Skan
247117395Skan/* Please keep the random linker options in alphabetical order (modulo
248117395Skan   'Z' and 'no' prefixes).  Options that can only go to one of libtool
249117395Skan   or ld must be listed twice, under both !Zdynamiclib and
250117395Skan   Zdynamiclib, with one of the cases reporting an error.  */
251117395Skan/* Note that options taking arguments may appear multiple times on a
252117395Skan   command line with different arguments each time, so put a * after
253117395Skan   their names so all of them get passed.  */
254117395Skan#define LINK_SPEC  \
255117395Skan  "%{static}%{!static:-dynamic} \
256169689Skan   %{fgnu-runtime:%:replace-outfile(-lobjc -lobjc-gnu)}\
257117395Skan   %{!Zdynamiclib: \
258169689Skan     %{Zforce_cpusubtype_ALL:-arch %(darwin_arch) -force_cpusubtype_ALL} \
259169689Skan     %{!Zforce_cpusubtype_ALL:-arch %(darwin_subarch)} \
260117395Skan     %{Zbundle:-bundle} \
261117395Skan     %{Zbundle_loader*:-bundle_loader %*} \
262117395Skan     %{client_name*} \
263117395Skan     %{compatibility_version*:%e-compatibility_version only allowed with -dynamiclib\
264117395Skan} \
265117395Skan     %{current_version*:%e-current_version only allowed with -dynamiclib} \
266117395Skan     %{Zforce_flat_namespace:-force_flat_namespace} \
267117395Skan     %{Zinstall_name*:%e-install_name only allowed with -dynamiclib} \
268117395Skan     %{keep_private_externs} \
269117395Skan     %{private_bundle} \
270117395Skan    } \
271117395Skan   %{Zdynamiclib: \
272117395Skan     %{Zbundle:%e-bundle not allowed with -dynamiclib} \
273117395Skan     %{Zbundle_loader*:%e-bundle_loader not allowed with -dynamiclib} \
274117395Skan     %{client_name*:%e-client_name not allowed with -dynamiclib} \
275117395Skan     %{compatibility_version*} \
276117395Skan     %{current_version*} \
277169689Skan     %{Zforce_cpusubtype_ALL:-arch_only %(darwin_arch)} \
278169689Skan     %{!Zforce_cpusubtype_ALL: -arch_only %(darwin_subarch)} \
279117395Skan     %{Zforce_flat_namespace:%e-force_flat_namespace not allowed with -dynamiclib} \
280117395Skan     %{Zinstall_name*:-install_name %*} \
281117395Skan     %{keep_private_externs:%e-keep_private_externs not allowed with -dynamiclib} \
282117395Skan     %{private_bundle:%e-private_bundle not allowed with -dynamiclib} \
283117395Skan    } \
284117395Skan   %{Zall_load:-all_load}%{Zdynamiclib:%{!Zall_load:-noall_load}} \
285117395Skan   %{Zallowable_client*:-allowable_client %*} \
286117395Skan   %{Zbind_at_load:-bind_at_load} \
287117395Skan   %{Zarch_errors_fatal:-arch_errors_fatal} \
288169689Skan   %{Zdead_strip:-dead_strip} \
289169689Skan   %{Zno_dead_strip_inits_and_terms:-no_dead_strip_inits_and_terms} \
290117395Skan   %{Zdylib_file*:-dylib_file %*} \
291117395Skan   %{Zdynamic:-dynamic}\
292117395Skan   %{Zexported_symbols_list*:-exported_symbols_list %*} \
293117395Skan   %{Zflat_namespace:-flat_namespace} \
294117395Skan   %{headerpad_max_install_names*} \
295117395Skan   %{Zimage_base*:-image_base %*} \
296117395Skan   %{Zinit*:-init %*} \
297169689Skan   %{mmacosx-version-min=*:-macosx_version_min %*} \
298169689Skan   %{!mmacosx-version-min=*:%{shared-libgcc:-macosx_version_min 10.3}} \
299117395Skan   %{nomultidefs} \
300117395Skan   %{Zmulti_module:-multi_module} %{Zsingle_module:-single_module} \
301117395Skan   %{Zmultiply_defined*:-multiply_defined %*} \
302169689Skan   %{!Zmultiply_defined*:%{shared-libgcc: \
303169689Skan     %:version-compare(< 10.5 mmacosx-version-min= -multiply_defined) \
304169689Skan     %:version-compare(< 10.5 mmacosx-version-min= suppress)}} \
305117395Skan   %{Zmultiplydefinedunused*:-multiply_defined_unused %*} \
306132718Skan   %{prebind} %{noprebind} %{nofixprebinding} %{prebind_all_twolevel_modules} \
307117395Skan   %{read_only_relocs} \
308169689Skan   %{sectcreate*} %{sectorder*} %{seg1addr*} %{segprot*} \
309169689Skan   %{Zsegaddr*:-segaddr %*} \
310169689Skan   %{Zsegs_read_only_addr*:-segs_read_only_addr %*} \
311169689Skan   %{Zsegs_read_write_addr*:-segs_read_write_addr %*} \
312169689Skan   %{Zseg_addr_table*: -seg_addr_table %*} \
313169689Skan   %{Zfn_seg_addr_table_filename*:-seg_addr_table_filename %*} \
314117395Skan   %{sub_library*} %{sub_umbrella*} \
315169689Skan   " LINK_SYSROOT_SPEC " \
316117395Skan   %{twolevel_namespace} %{twolevel_namespace_hints} \
317117395Skan   %{umbrella*} \
318117395Skan   %{undefined*} \
319117395Skan   %{Zunexported_symbols_list*:-unexported_symbols_list %*} \
320117395Skan   %{Zweak_reference_mismatches*:-weak_reference_mismatches %*} \
321169689Skan   %{!Zweak_reference_mismatches*:-weak_reference_mismatches non-weak} \
322117395Skan   %{X} \
323117395Skan   %{y*} \
324117395Skan   %{w} \
325117395Skan   %{pagezero_size*} %{segs_read_*} %{seglinkedit} %{noseglinkedit}  \
326117395Skan   %{sectalign*} %{sectobjectsymbols*} %{segcreate*} %{whyload} \
327117395Skan   %{whatsloaded} %{dylinker_install_name*} \
328117395Skan   %{dylinker} %{Mach} "
329117395Skan
330117395Skan
33190075Sobrien/* Machine dependent libraries.  */
33290075Sobrien
33390075Sobrien#define LIB_SPEC "%{!static:-lSystem}"
33490075Sobrien
335169689Skan/* Support -mmacosx-version-min by supplying different (stub) libgcc_s.dylib
336169689Skan   libraries to link against, and by not linking against libgcc_s on
337169689Skan   earlier-than-10.3.9.
33890075Sobrien
339169689Skan   Note that by default, -lgcc_eh is not linked against!  This is
340169689Skan   because in a future version of Darwin the EH frame information may
341169689Skan   be in a new format, or the fallback routine might be changed; if
342169689Skan   you want to explicitly link against the static version of those
343169689Skan   routines, because you know you don't need to unwind through system
344169689Skan   libraries, you need to explicitly say -static-libgcc.
345169689Skan
346169689Skan   If it is linked against, it has to be before -lgcc, because it may
347169689Skan   need symbols from -lgcc.  */
348169689Skan#undef REAL_LIBGCC_SPEC
349169689Skan#define REAL_LIBGCC_SPEC						   \
350169689Skan   "%{static-libgcc|static: -lgcc_eh -lgcc;				   \
351169689Skan      shared-libgcc|fexceptions|fgnu-runtime:				   \
352169689Skan       %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_s.10.4)	   \
353169689Skan       %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_s.10.5)	   \
354169689Skan       -lgcc;								   \
355169689Skan      :%:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \
356169689Skan       %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_s.10.5)	   \
357169689Skan       -lgcc}"
358169689Skan
359169689Skan/* We specify crt0.o as -lcrt0.o so that ld will search the library path.
360169689Skan
361169689Skan   crt3.o provides __cxa_atexit on systems that don't have it.  Since
362169689Skan   it's only used with C++, which requires passing -shared-libgcc, key
363169689Skan   off that to avoid unnecessarily adding a destructor to every
364169689Skan   powerpc program built.  */
365169689Skan
366117395Skan#undef  STARTFILE_SPEC
367169689Skan#define STARTFILE_SPEC							    \
368169689Skan  "%{!Zdynamiclib:%{Zbundle:%{!static:-lbundle1.o}}			    \
369169689Skan     %{!Zbundle:%{pg:%{static:-lgcrt0.o}				    \
370169689Skan                     %{!static:%{object:-lgcrt0.o}			    \
371169689Skan                               %{!object:%{preload:-lgcrt0.o}		    \
372169689Skan                                 %{!preload:-lgcrt1.o %(darwin_crt2)}}}}    \
373169689Skan                %{!pg:%{static:-lcrt0.o}				    \
374169689Skan                      %{!static:%{object:-lcrt0.o}			    \
375169689Skan                                %{!object:%{preload:-lcrt0.o}		    \
376169689Skan                                  %{!preload:-lcrt1.o %(darwin_crt2)}}}}}}  \
377169689Skan  %{shared-libgcc:%:version-compare(< 10.5 mmacosx-version-min= crt3.o%s)}"
37890075Sobrien
379117395Skan/* The native Darwin linker doesn't necessarily place files in the order
380117395Skan   that they're specified on the link line.  Thus, it is pointless
381117395Skan   to put anything in ENDFILE_SPEC.  */
382117395Skan/* #define ENDFILE_SPEC "" */
383117395Skan
384169689Skan/* Default Darwin ASM_SPEC, very simple.  */
385169689Skan#define ASM_SPEC "-arch %(darwin_arch) \
386169689Skan  %{Zforce_cpusubtype_ALL:-force_cpusubtype_ALL}"
387169689Skan
38890075Sobrien/* We use Dbx symbol format.  */
38990075Sobrien
390117395Skan#define DBX_DEBUGGING_INFO 1
39190075Sobrien
392169689Skan/* Also enable Dwarf 2 as an option.  */
393169689Skan#define DWARF2_DEBUGGING_INFO
394169689Skan#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
395169689Skan
396169689Skan#define DEBUG_FRAME_SECTION	"__DWARF,__debug_frame,regular,debug"
397169689Skan#define DEBUG_INFO_SECTION	"__DWARF,__debug_info,regular,debug"
398169689Skan#define DEBUG_ABBREV_SECTION	"__DWARF,__debug_abbrev,regular,debug"
399169689Skan#define DEBUG_ARANGES_SECTION	"__DWARF,__debug_aranges,regular,debug"
400169689Skan#define DEBUG_MACINFO_SECTION	"__DWARF,__debug_macinfo,regular,debug"
401169689Skan#define DEBUG_LINE_SECTION	"__DWARF,__debug_line,regular,debug"
402169689Skan#define DEBUG_LOC_SECTION	"__DWARF,__debug_loc,regular,debug"
403169689Skan#define DEBUG_PUBNAMES_SECTION	"__DWARF,__debug_pubnames,regular,debug"
404260395Spfg#define DEBUG_PUBTYPES_SECTION	"__DWARF,__debug_pubtypes,regular,debug"
405169689Skan#define DEBUG_STR_SECTION	"__DWARF,__debug_str,regular,debug"
406169689Skan#define DEBUG_RANGES_SECTION	"__DWARF,__debug_ranges,regular,debug"
407169689Skan
40890075Sobrien/* When generating stabs debugging, use N_BINCL entries.  */
40990075Sobrien
41090075Sobrien#define DBX_USE_BINCL
41190075Sobrien
41290075Sobrien/* There is no limit to the length of stabs strings.  */
41390075Sobrien
41490075Sobrien#define DBX_CONTIN_LENGTH 0
41590075Sobrien
416117395Skan/* gdb needs a null N_SO at the end of each file for scattered loading.  */
41790075Sobrien
418169689Skan#define DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
41990075Sobrien
420169689Skan/* GCC's definition of 'one_only' is the same as its definition of 'weak'.  */
421169689Skan#define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
422169689Skan
423169689Skan/* Mach-O supports 'weak imports', and 'weak definitions' in coalesced
424169689Skan   sections.  machopic_select_section ensures that weak variables go in
425169689Skan   coalesced sections.  Weak aliases (or any other kind of aliases) are
426169689Skan   not supported.  Weak symbols that aren't visible outside the .s file
427169689Skan   are not supported.  */
428169689Skan#define ASM_WEAKEN_DECL(FILE, DECL, NAME, ALIAS)			\
429169689Skan  do {									\
430169689Skan    if (ALIAS)								\
431169689Skan      {									\
432169689Skan	warning (0, "alias definitions not supported in Mach-O; ignored");	\
433169689Skan	break;								\
434169689Skan      }									\
435169689Skan 									\
436169689Skan    if (! DECL_EXTERNAL (DECL) && TREE_PUBLIC (DECL))			\
437169689Skan      targetm.asm_out.globalize_label (FILE, NAME);			\
438169689Skan    if (DECL_EXTERNAL (DECL))						\
439169689Skan      fputs ("\t.weak_reference ", FILE);				\
440169689Skan    else if (! lookup_attribute ("weak", DECL_ATTRIBUTES (DECL))	\
441169689Skan	&& lookup_attribute ("weak_import", DECL_ATTRIBUTES (DECL)))	\
442169689Skan      break;								\
443169689Skan    else if (TREE_PUBLIC (DECL))					\
444169689Skan      fputs ("\t.weak_definition ", FILE);				\
445169689Skan    else								\
446169689Skan      break;								\
447169689Skan    assemble_name (FILE, NAME);						\
448169689Skan    fputc ('\n', FILE);							\
449169689Skan  } while (0)
450169689Skan
451169689Skan/* Darwin has the pthread routines in libSystem, which every program
452169689Skan   links to, so there's no need for weak-ness for that.  */
453169689Skan#define GTHREAD_USE_WEAK 0
454169689Skan
455169689Skan/* The Darwin linker imposes two limitations on common symbols: they
456169689Skan   can't have hidden visibility, and they can't appear in dylibs.  As
457169689Skan   a consequence, we should never use common symbols to represent
458169689Skan   vague linkage. */
459169689Skan#undef USE_COMMON_FOR_ONE_ONLY
460169689Skan#define USE_COMMON_FOR_ONE_ONLY 0
461169689Skan
462169689Skan/* The Darwin linker doesn't want coalesced symbols to appear in
463169689Skan   a static archive's table of contents. */
464169689Skan#undef TARGET_WEAK_NOT_IN_ARCHIVE_TOC
465169689Skan#define TARGET_WEAK_NOT_IN_ARCHIVE_TOC 1
466169689Skan
467169689Skan/* On Darwin, we don't (at the time of writing) have linkonce sections
468169689Skan   with names, so it's safe to make the class data not comdat.  */
469169689Skan#define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT hook_bool_void_false
470169689Skan
471259947Spfg/* For efficiency, on Darwin the RTTI information that is always
472259947Spfg   emitted in the standard C++ library should not be COMDAT.  */
473259947Spfg#define TARGET_CXX_LIBRARY_RTTI_COMDAT hook_bool_void_false
474259947Spfg
475169689Skan/* We make exception information linkonce. */
476169689Skan#undef TARGET_USES_WEAK_UNWIND_INFO
477169689Skan#define TARGET_USES_WEAK_UNWIND_INFO 1
478169689Skan
479169689Skan/* We need to use a nonlocal label for the start of an EH frame: the
480169689Skan   Darwin linker requires that a coalesced section start with a label.
481169689Skan   Unfortunately, it also requires that 'debug' sections don't contain
482169689Skan   labels.  */
483169689Skan#undef FRAME_BEGIN_LABEL
484169689Skan#define FRAME_BEGIN_LABEL (for_eh ? "EH_frame" : "Lframe")
485169689Skan
486169689Skan/* Emit a label for the FDE corresponding to DECL.  EMPTY means
487169689Skan   emit a label for an empty FDE. */
488169689Skan#define TARGET_ASM_EMIT_UNWIND_LABEL darwin_emit_unwind_label
489169689Skan
490169689Skan/* Emit a label to separate the exception table.  */
491169689Skan#define TARGET_ASM_EMIT_EXCEPT_TABLE_LABEL darwin_emit_except_table_label
492169689Skan
49390075Sobrien/* Our profiling scheme doesn't LP labels and counter words.  */
49490075Sobrien
495132718Skan#define NO_PROFILE_COUNTERS	1
49690075Sobrien
49790075Sobrien#undef	INIT_SECTION_ASM_OP
49890075Sobrien#define INIT_SECTION_ASM_OP
49990075Sobrien
50090075Sobrien#undef	INVOKE__main
50190075Sobrien
50290075Sobrien#define TARGET_ASM_CONSTRUCTOR  machopic_asm_out_constructor
50390075Sobrien#define TARGET_ASM_DESTRUCTOR   machopic_asm_out_destructor
50490075Sobrien
505117395Skan/* Always prefix with an underscore.  */
50690075Sobrien
507117395Skan#define USER_LABEL_PREFIX "_"
508117395Skan
50990075Sobrien/* Don't output a .file directive.  That is only used by the assembler for
51090075Sobrien   error reporting.  */
511132718Skan#undef	TARGET_ASM_FILE_START_FILE_DIRECTIVE
512132718Skan#define TARGET_ASM_FILE_START_FILE_DIRECTIVE false
51390075Sobrien
514132718Skan#undef  TARGET_ASM_FILE_END
515132718Skan#define TARGET_ASM_FILE_END darwin_file_end
51690075Sobrien
517117395Skan#define ASM_OUTPUT_SKIP(FILE,SIZE)  \
518132718Skan  fprintf (FILE, "\t.space "HOST_WIDE_INT_PRINT_UNSIGNED"\n", SIZE)
51990075Sobrien
520117395Skan/* Give ObjC methods pretty symbol names.  */
521117395Skan
52290075Sobrien#undef	OBJC_GEN_METHOD_LABEL
52390075Sobrien#define OBJC_GEN_METHOD_LABEL(BUF,IS_INST,CLASS_NAME,CAT_NAME,SEL_NAME,NUM) \
52490075Sobrien  do { if (CAT_NAME)							\
52590075Sobrien	 sprintf (BUF, "%c[%s(%s) %s]", (IS_INST) ? '-' : '+',		\
52690075Sobrien		  (CLASS_NAME), (CAT_NAME), (SEL_NAME));		\
52790075Sobrien       else								\
52890075Sobrien	 sprintf (BUF, "%c[%s %s]", (IS_INST) ? '-' : '+',		\
52990075Sobrien		  (CLASS_NAME), (SEL_NAME));				\
53090075Sobrien     } while (0)
53190075Sobrien
53290075Sobrien/* The RTTI data (e.g., __ti4name) is common and public (and static),
53390075Sobrien   but it does need to be referenced via indirect PIC data pointers.
534169689Skan   The machopic_define_symbol calls are telling the machopic subsystem
53590075Sobrien   that the name *is* defined in this module, so it doesn't need to
53690075Sobrien   make them indirect.  */
53790075Sobrien
53890075Sobrien#undef ASM_DECLARE_OBJECT_NAME
53990075Sobrien#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)			\
54090075Sobrien  do {									\
541132718Skan    const char *xname = NAME;						\
542132718Skan    if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF)		\
543132718Skan      xname = IDENTIFIER_POINTER (DECL_NAME (DECL));			\
544169689Skan    if (! DECL_WEAK (DECL)						\
545169689Skan        && ((TREE_STATIC (DECL)						\
546169689Skan	     && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))		\
547169689Skan            || DECL_INITIAL (DECL)))					\
548169689Skan        machopic_define_symbol (DECL_RTL (DECL));			\
549132718Skan    if ((TREE_STATIC (DECL)						\
550132718Skan	 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))		\
551132718Skan        || DECL_INITIAL (DECL))						\
552132718Skan      (* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false);	\
553132718Skan    ASM_OUTPUT_LABEL (FILE, xname);					\
554169689Skan    /* Darwin doesn't support zero-size objects, so give them a		\
555122180Skan       byte.  */							\
556122180Skan    if (tree_low_cst (DECL_SIZE_UNIT (DECL), 1) == 0)			\
557122180Skan      assemble_zeros (1);						\
55890075Sobrien  } while (0)
55990075Sobrien
560169689Skan#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)			\
56190075Sobrien  do {									\
562169689Skan    const char *xname = NAME;						\
563169689Skan    if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF)		\
564169689Skan      xname = IDENTIFIER_POINTER (DECL_NAME (DECL));			\
565169689Skan    if (! DECL_WEAK (DECL)						\
566169689Skan        && ((TREE_STATIC (DECL)						\
567169689Skan	     && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))		\
568169689Skan            || DECL_INITIAL (DECL)))					\
569169689Skan        machopic_define_symbol (DECL_RTL (DECL));			\
570169689Skan    if ((TREE_STATIC (DECL)						\
571169689Skan	 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))		\
572169689Skan        || DECL_INITIAL (DECL))						\
573132718Skan      (* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false);	\
574169689Skan    ASM_OUTPUT_LABEL (FILE, xname);					\
57590075Sobrien  } while (0)
57690075Sobrien
577122180Skan#define ASM_DECLARE_CONSTANT_NAME(FILE, NAME, EXP, SIZE)	\
578122180Skan  do {								\
579122180Skan    ASM_OUTPUT_LABEL (FILE, NAME);				\
580122180Skan    /* Darwin doesn't support zero-size objects, so give them a	\
581122180Skan       byte.  */						\
582122180Skan    if ((SIZE) == 0)						\
583122180Skan      assemble_zeros (1);					\
584122180Skan  } while (0)
585122180Skan
58690075Sobrien/* Wrap new method names in quotes so the assembler doesn't gag.
58790075Sobrien   Make Objective-C internal symbols local.  */
58890075Sobrien
58990075Sobrien#undef	ASM_OUTPUT_LABELREF
590117395Skan#define ASM_OUTPUT_LABELREF(FILE,NAME)					     \
591117395Skan  do {									     \
592169689Skan       const char *xname = (NAME);					     \
593132718Skan       if (! strcmp (xname, "<pic base>"))				     \
594132718Skan         machopic_output_function_base_name(FILE);                           \
595132718Skan       else if (xname[0] == '&' || xname[0] == '*')			     \
596117395Skan         {								     \
597117395Skan           int len = strlen (xname);					     \
598117395Skan	   if (len > 6 && !strcmp ("$stub", xname + len - 5))		     \
599169689Skan	     machopic_validate_stub_or_non_lazy_ptr (xname);		     \
600117395Skan	   else if (len > 7 && !strcmp ("$stub\"", xname + len - 6))	     \
601169689Skan	     machopic_validate_stub_or_non_lazy_ptr (xname);		     \
602117395Skan	   else if (len > 14 && !strcmp ("$non_lazy_ptr", xname + len - 13)) \
603169689Skan	     machopic_validate_stub_or_non_lazy_ptr (xname);		     \
604169689Skan	   else if (len > 15 && !strcmp ("$non_lazy_ptr\"", xname + len - 14)) \
605169689Skan	     machopic_validate_stub_or_non_lazy_ptr (xname);		     \
606169689Skan	   if (xname[1] != '"' && name_needs_quotes (&xname[1]))	     \
607169689Skan	     fprintf (FILE, "\"%s\"", &xname[1]);			     \
608169689Skan	   else								     \
609169689Skan	     fputs (&xname[1], FILE); 					     \
610117395Skan	 }								     \
611117395Skan       else if (xname[0] == '+' || xname[0] == '-')			     \
612117395Skan         fprintf (FILE, "\"%s\"", xname);				     \
613117395Skan       else if (!strncmp (xname, "_OBJC_", 6))				     \
614117395Skan         fprintf (FILE, "L%s", xname);					     \
615117395Skan       else if (!strncmp (xname, ".objc_class_name_", 17))		     \
616117395Skan	 fprintf (FILE, "%s", xname);					     \
617169689Skan       else if (xname[0] != '"' && name_needs_quotes (xname))		     \
618169689Skan	 fprintf (FILE, "\"%s\"", xname);				     \
619117395Skan       else								     \
620169689Skan         asm_fprintf (FILE, "%U%s", xname);				     \
62190075Sobrien  } while (0)
62290075Sobrien
623117395Skan/* Output before executable code.  */
624117395Skan#undef TEXT_SECTION_ASM_OP
625169689Skan#define TEXT_SECTION_ASM_OP "\t.text"
626117395Skan
627117395Skan/* Output before writable data.  */
628117395Skan
629117395Skan#undef DATA_SECTION_ASM_OP
630169689Skan#define DATA_SECTION_ASM_OP "\t.data"
631117395Skan
63290075Sobrien#undef	ALIGN_ASM_OP
63390075Sobrien#define ALIGN_ASM_OP		".align"
63490075Sobrien
63590075Sobrien#undef	ASM_OUTPUT_ALIGN
63690075Sobrien#define ASM_OUTPUT_ALIGN(FILE,LOG)	\
63790075Sobrien  if ((LOG) != 0)			\
63890075Sobrien    fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG))
63990075Sobrien
64090075Sobrien/* Ensure correct alignment of bss data.  */
64190075Sobrien
64290075Sobrien#undef	ASM_OUTPUT_ALIGNED_DECL_LOCAL
643117395Skan#define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN)	\
644117395Skan  do {									\
645169689Skan    unsigned HOST_WIDE_INT _new_size = SIZE;				\
646117395Skan    fputs (".lcomm ", (FILE));						\
647117395Skan    assemble_name ((FILE), (NAME));					\
648169689Skan    if (_new_size == 0) _new_size = 1;					\
649169689Skan    fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", _new_size,	\
650117395Skan	     floor_log2 ((ALIGN) / BITS_PER_UNIT));			\
651117395Skan    if ((DECL) && ((TREE_STATIC (DECL)					\
652117395Skan	 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))		\
653117395Skan        || DECL_INITIAL (DECL)))					\
654169689Skan      {									\
655169689Skan	(* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false);	\
656169689Skan	machopic_define_symbol (DECL_RTL (DECL));			\
657169689Skan      }									\
65890075Sobrien  } while (0)
65990075Sobrien
660169689Skan/* The maximum alignment which the object file format can support in
661169689Skan   bits.  For Mach-O, this is 2^15 bytes.  */
66290075Sobrien
66390075Sobrien#undef	MAX_OFILE_ALIGNMENT
664169689Skan#define MAX_OFILE_ALIGNMENT (0x8000 * 8)
66590075Sobrien
666169689Skan/* Declare the section variables.  */
667169689Skan#ifndef USED_FOR_TARGET
668169689Skanenum darwin_section_enum {
669169689Skan#define DEF_SECTION(NAME, FLAGS, DIRECTIVE, OBJC) NAME,
670169689Skan#include "darwin-sections.def"
671169689Skan#undef DEF_SECTION
672169689Skan  NUM_DARWIN_SECTIONS
673169689Skan};
674169689Skanextern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
675169689Skan#endif
67690075Sobrien
677117395Skan#undef	TARGET_ASM_SELECT_SECTION
678117395Skan#define TARGET_ASM_SELECT_SECTION machopic_select_section
679169689Skan#define USE_SELECT_SECTION_FOR_FUNCTIONS
680169689Skan
681117395Skan#undef	TARGET_ASM_SELECT_RTX_SECTION
682117395Skan#define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
683169689Skan#undef  TARGET_ASM_UNIQUE_SECTION
684169689Skan#define TARGET_ASM_UNIQUE_SECTION darwin_unique_section
685169689Skan#undef  TARGET_ASM_FUNCTION_RODATA_SECTION
686169689Skan#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
687169689Skan#undef  TARGET_ASM_RELOC_RW_MASK
688169689Skan#define TARGET_ASM_RELOC_RW_MASK machopic_reloc_rw_mask
68990075Sobrien
690169689Skan
69190075Sobrien#define ASM_DECLARE_UNRESOLVED_REFERENCE(FILE,NAME)			\
692132718Skan    do {								\
69390075Sobrien	 if (FILE) {							\
694132718Skan	   if (MACHOPIC_INDIRECT)					\
69590075Sobrien	     fprintf (FILE, "\t.lazy_reference ");			\
69690075Sobrien	   else								\
69790075Sobrien	     fprintf (FILE, "\t.reference ");				\
69890075Sobrien	   assemble_name (FILE, NAME);					\
69990075Sobrien	   fprintf (FILE, "\n");					\
70090075Sobrien	 }                                                              \
70190075Sobrien       } while (0)
70290075Sobrien
70390075Sobrien#define ASM_DECLARE_CLASS_REFERENCE(FILE,NAME)				\
70490075Sobrien    do {								\
70590075Sobrien	 if (FILE) {							\
70690075Sobrien	   fprintf (FILE, "\t");					\
707132718Skan	   assemble_name (FILE, NAME);					\
70890075Sobrien	   fprintf (FILE, "=0\n");					\
709117395Skan	   (*targetm.asm_out.globalize_label) (FILE, NAME);		\
71090075Sobrien	 }								\
71190075Sobrien       } while (0)
71290075Sobrien
713117395Skan/* Globalizing directive for a label.  */
714117395Skan#define GLOBAL_ASM_OP ".globl "
715117395Skan#define TARGET_ASM_GLOBALIZE_LABEL darwin_globalize_label
71690075Sobrien
717132718Skan/* Emit an assembler directive to set visibility for a symbol.  Used
718132718Skan   to support visibility attribute and Darwin's private extern
719169689Skan   feature.  */
720132718Skan#undef TARGET_ASM_ASSEMBLE_VISIBILITY
721132718Skan#define TARGET_ASM_ASSEMBLE_VISIBILITY darwin_assemble_visibility
722132718Skan
723169689Skan/* Extra attributes for Darwin.  */
724169689Skan#define SUBTARGET_ATTRIBUTE_TABLE					     \
725169689Skan  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ \
726169689Skan  { "apple_kext_compatibility", 0, 0, false, true, false,		     \
727169689Skan    darwin_handle_kext_attribute },					     \
728169689Skan  { "weak_import", 0, 0, true, false, false,				     \
729169689Skan    darwin_handle_weak_import_attribute }
730132718Skan
73190075Sobrien#undef ASM_GENERATE_INTERNAL_LABEL
73290075Sobrien#define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)	\
73390075Sobrien  sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM))
73490075Sobrien
735169689Skan#undef TARGET_ASM_MARK_DECL_PRESERVED
736169689Skan#define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved
73790075Sobrien
738169689Skan/* Set on a symbol with SYMBOL_FLAG_FUNCTION or
739169689Skan   MACHO_SYMBOL_FLAG_VARIABLE to indicate that the function or
740169689Skan   variable has been defined in this translation unit.
741169689Skan   When porting Mach-O to new architectures you need to make
742169689Skan   sure these aren't clobbered by the backend.  */
74390075Sobrien
744169689Skan#define MACHO_SYMBOL_FLAG_VARIABLE (SYMBOL_FLAG_MACH_DEP)
745169689Skan#define MACHO_SYMBOL_FLAG_DEFINED ((SYMBOL_FLAG_MACH_DEP) << 1)
746169689Skan
747169689Skan/* Set on a symbol to indicate when fix-and-continue style code
748169689Skan   generation is being used and the symbol refers to a static symbol
749169689Skan   that should be rebound from new instances of a translation unit to
750169689Skan   the original instance of the data.  */
751169689Skan
752169689Skan#define MACHO_SYMBOL_STATIC ((SYMBOL_FLAG_MACH_DEP) << 2)
753169689Skan
75490075Sobrien/* Symbolic names for various things we might know about a symbol.  */
75590075Sobrien
75690075Sobrienenum machopic_addr_class {
75790075Sobrien  MACHOPIC_UNDEFINED,
75890075Sobrien  MACHOPIC_DEFINED_DATA,
75990075Sobrien  MACHOPIC_UNDEFINED_DATA,
76090075Sobrien  MACHOPIC_DEFINED_FUNCTION,
76190075Sobrien  MACHOPIC_UNDEFINED_FUNCTION
76290075Sobrien};
76390075Sobrien
76490075Sobrien/* Macros defining the various PIC cases.  */
76590075Sobrien
766132718Skan#define MACHO_DYNAMIC_NO_PIC_P	(TARGET_DYNAMIC_NO_PIC)
767132718Skan#define MACHOPIC_INDIRECT	(flag_pic || MACHO_DYNAMIC_NO_PIC_P)
768169689Skan#define MACHOPIC_JUST_INDIRECT	(MACHO_DYNAMIC_NO_PIC_P)
769169689Skan#define MACHOPIC_PURE		(flag_pic && ! MACHO_DYNAMIC_NO_PIC_P)
77090075Sobrien
771117395Skan#undef TARGET_ENCODE_SECTION_INFO
772117395Skan#define TARGET_ENCODE_SECTION_INFO  darwin_encode_section_info
773117395Skan#undef TARGET_STRIP_NAME_ENCODING
774169689Skan#define TARGET_STRIP_NAME_ENCODING  default_strip_name_encoding
77590075Sobrien
77690075Sobrien#define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH)		\
77790075Sobrien  do {								\
77890075Sobrien    const char *const stub_ = (STUB);				\
77990075Sobrien    char *buffer_ = (BUF);					\
78090075Sobrien    strcpy (buffer_, stub_);					\
78190075Sobrien    if (stub_[0] == '"')					\
78290075Sobrien      {								\
78390075Sobrien	strcpy (buffer_ + (STUB_LENGTH) - 1, "_binder\"");	\
78490075Sobrien      }								\
78590075Sobrien    else							\
78690075Sobrien      {								\
78790075Sobrien	strcpy (buffer_ + (STUB_LENGTH), "_binder");		\
78890075Sobrien      }								\
78990075Sobrien  } while (0)
79090075Sobrien
79190075Sobrien#define GEN_SYMBOL_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH)	\
79290075Sobrien  do {								\
79390075Sobrien    const char *const symbol_ = (SYMBOL);			\
79490075Sobrien    char *buffer_ = (BUF);					\
79590075Sobrien    if (name_needs_quotes (symbol_) && symbol_[0] != '"')	\
79690075Sobrien      {								\
79790075Sobrien	  sprintf (buffer_, "\"%s\"", symbol_);			\
79890075Sobrien      }								\
79990075Sobrien    else							\
80090075Sobrien      {								\
80190075Sobrien	strcpy (buffer_, symbol_);				\
80290075Sobrien      }								\
80390075Sobrien  } while (0)
80490075Sobrien
80590075Sobrien/* Given a symbol name string, create the lazy pointer version
80690075Sobrien   of the symbol name.  */
80790075Sobrien
80890075Sobrien#define GEN_LAZY_PTR_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH)	\
80990075Sobrien  do {								\
810169689Skan    const char *symbol_ = (SYMBOL);                             \
81190075Sobrien    char *buffer_ = (BUF);					\
81290075Sobrien    if (symbol_[0] == '"')					\
81390075Sobrien      {								\
814117395Skan        strcpy (buffer_, "\"L");				\
81590075Sobrien        strcpy (buffer_ + 2, symbol_ + 1);			\
81690075Sobrien	strcpy (buffer_ + (SYMBOL_LENGTH), "$lazy_ptr\"");	\
81790075Sobrien      }								\
81890075Sobrien    else if (name_needs_quotes (symbol_))			\
81990075Sobrien      {								\
82090075Sobrien        strcpy (buffer_, "\"L");				\
82190075Sobrien        strcpy (buffer_ + 2, symbol_);				\
82290075Sobrien	strcpy (buffer_ + (SYMBOL_LENGTH) + 2, "$lazy_ptr\"");	\
82390075Sobrien      }								\
82490075Sobrien    else							\
82590075Sobrien      {								\
82690075Sobrien        strcpy (buffer_, "L");					\
82790075Sobrien        strcpy (buffer_ + 1, symbol_);				\
82890075Sobrien	strcpy (buffer_ + (SYMBOL_LENGTH) + 1, "$lazy_ptr");	\
82990075Sobrien      }								\
83090075Sobrien  } while (0)
83190075Sobrien
832169689Skan#define EH_FRAME_SECTION_NAME   "__TEXT"
833169689Skan#define EH_FRAME_SECTION_ATTR ",coalesced,no_toc+strip_static_syms+live_support"
83490075Sobrien
835169689Skan/* Java runtime class list.  */
836169689Skan#define JCR_SECTION_NAME "__DATA,jcr,regular,no_dead_strip"
837132718Skan
838117395Skan#undef ASM_PREFERRED_EH_DATA_FORMAT
83990075Sobrien#define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL)  \
840117395Skan  (((CODE) == 2 && (GLOBAL) == 1) \
841169689Skan   ? (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4) : \
842117395Skan     ((CODE) == 1 || (GLOBAL) == 0) ? DW_EH_PE_pcrel : DW_EH_PE_absptr)
84390075Sobrien
844117395Skan#define ASM_OUTPUT_DWARF_DELTA(FILE,SIZE,LABEL1,LABEL2)  \
845117395Skan  darwin_asm_output_dwarf_delta (FILE, SIZE, LABEL1, LABEL2)
846117395Skan
847169689Skan#define ASM_OUTPUT_DWARF_OFFSET(FILE,SIZE,LABEL,BASE)  \
848169689Skan  darwin_asm_output_dwarf_offset (FILE, SIZE, LABEL, BASE)
849169689Skan
850169689Skan#define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(ASM_OUT_FILE, ENCODING, SIZE, ADDR, DONE)	\
851169689Skan      if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) {				\
852169689Skan	darwin_non_lazy_pcrel (ASM_OUT_FILE, ADDR);					\
853169689Skan	goto DONE;									\
854169689Skan      }
855169689Skan
856169689Skan/* Experimentally, putting jump tables in text is faster on SPEC.
857169689Skan   Also this is needed for correctness for coalesced functions.  */
858169689Skan
859169689Skan#ifndef JUMP_TABLES_IN_TEXT_SECTION
860169689Skan#define JUMP_TABLES_IN_TEXT_SECTION 1
861169689Skan#endif
862169689Skan
863117395Skan#define TARGET_TERMINATE_DW2_EH_FRAME_INFO false
864117395Skan
865169689Skan#define TARGET_ASM_INIT_SECTIONS darwin_init_sections
866169689Skan#undef TARGET_ASM_NAMED_SECTION
867169689Skan#define TARGET_ASM_NAMED_SECTION darwin_asm_named_section
868169689Skan
869169689Skan/* Handle pragma weak and pragma pack.  */
870169689Skan#define HANDLE_SYSV_PRAGMA 1
871169689Skan
872169689Skan#define HANDLE_PRAGMA_PACK_PUSH_POP 1
873169689Skan
874132718Skan#define DARWIN_REGISTER_TARGET_PRAGMAS()			\
875132718Skan  do {								\
876260573Spfg    /* APPLE LOCAL begin pragma mark 5614511 */			\
877260573Spfg    /* Removed mark.  */					\
878260573Spfg    /* APPLE LOCAL end pragma mark 5614511 */			\
879132718Skan    c_register_pragma (0, "options", darwin_pragma_options);	\
880132718Skan    c_register_pragma (0, "segment", darwin_pragma_ignore);	\
881132718Skan    c_register_pragma (0, "unused", darwin_pragma_unused);	\
882169689Skan    c_register_pragma (0, "ms_struct", darwin_pragma_ms_struct); \
88390075Sobrien  } while (0)
884117395Skan
885117395Skan#undef ASM_APP_ON
886117395Skan#define ASM_APP_ON ""
887117395Skan#undef ASM_APP_OFF
888117395Skan#define ASM_APP_OFF ""
889169689Skan
890169689Skanvoid darwin_register_frameworks (const char *, const char *, int);
891169689Skanvoid darwin_register_objc_includes (const char *, const char *, int);
892169689Skan#define TARGET_EXTRA_PRE_INCLUDES darwin_register_objc_includes
893169689Skan#define TARGET_EXTRA_INCLUDES darwin_register_frameworks
894169689Skan
895169689Skanvoid add_framework_path (char *);
896169689Skan#define TARGET_OPTF add_framework_path
897169689Skan
898169689Skan#define TARGET_POSIX_IO
899169689Skan
900169689Skan/* All new versions of Darwin have C99 functions.  */
901169689Skan
902169689Skan#define TARGET_C99_FUNCTIONS 1
903169689Skan
904169689Skan#define WINT_TYPE "int"
905169689Skan
906169689Skan/* Every program on darwin links against libSystem which contains the pthread
907169689Skan   routines, so there's no need to explicitly call out when doing threaded
908169689Skan   work.  */
909169689Skan
910169689Skan#undef GOMP_SELF_SPECS
911169689Skan#define GOMP_SELF_SPECS ""
912169689Skan
913169689Skan/* Darwin can't support anchors until we can cope with the adjustments
914169689Skan   to size that ASM_DECLARE_OBJECT_NAME and ASM_DECLARE_CONSTANT_NAME
915169689Skan   when outputting members of an anchor block and the linker can be
916169689Skan   taught to keep them together or we find some other suitable
917169689Skan   code-gen technique.  */
918169689Skan
919169689Skan#if 0
920169689Skan#define TARGET_ASM_OUTPUT_ANCHOR darwin_asm_output_anchor
921169689Skan#else
922169689Skan#define TARGET_ASM_OUTPUT_ANCHOR NULL
923169689Skan#endif
924169689Skan
925169689Skan/* Attempt to turn on execute permission for the stack.  This may be
926169689Skan    used by INITIALIZE_TRAMPOLINE of the target needs it (that is,
927169689Skan    if the target machine can change execute permissions on a page).
928169689Skan
929169689Skan    There is no way to query the execute permission of the stack, so
930169689Skan    we always issue the mprotect() call.
931169689Skan
932169689Skan    Unfortunately it is not possible to make this namespace-clean.
933169689Skan
934169689Skan    Also note that no errors should be emitted by this code; it is
935169689Skan    considered dangerous for library calls to send messages to
936169689Skan    stdout/stderr.  */
937169689Skan
938169689Skan#define ENABLE_EXECUTE_STACK                                            \
939169689Skanextern void __enable_execute_stack (void *);                            \
940169689Skanvoid                                                                    \
941169689Skan__enable_execute_stack (void *addr)                                     \
942169689Skan{                                                                       \
943169689Skan   extern int mprotect (void *, size_t, int);                           \
944169689Skan   extern int getpagesize (void);					\
945169689Skan   static int size;                                                     \
946169689Skan   static long mask;                                                    \
947169689Skan                                                                        \
948169689Skan   char *page, *end;                                                    \
949169689Skan                                                                        \
950169689Skan   if (size == 0)                                                       \
951169689Skan     {                                                                  \
952169689Skan       size = getpagesize();						\
953169689Skan       mask = ~((long) size - 1);                                       \
954169689Skan     }                                                                  \
955169689Skan                                                                        \
956169689Skan   page = (char *) (((long) addr) & mask);                              \
957169689Skan   end  = (char *) ((((long) (addr + (TARGET_64BIT ? 48 : 40))) & mask) + size); \
958169689Skan                                                                        \
959169689Skan   /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */                        \
960169689Skan   (void) mprotect (page, end - page, 7);                               \
961169689Skan}
962169689Skan
963169689Skan/* For Apple KEXTs, we make the constructors return this to match gcc
964169689Skan   2.95.  */
965169689Skan#define TARGET_CXX_CDTOR_RETURNS_THIS (darwin_kextabi_p)
966169689Skanextern int flag_mkernel;
967169689Skanextern int flag_apple_kext;
968169689Skan#define TARGET_KEXTABI flag_apple_kext
969169689Skan
970169689Skan#endif /* CONFIG_DARWIN_H */
971