OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / config / darwin.h
1 /* Target definitions for Darwin (Mac OS X) systems.
2    Copyright (C) 1989, 1990, 1991, 1992, 1993, 2000, 2001, 2002, 2003, 2004,
3    2005
4    Free Software Foundation, Inc.
5    Contributed by Apple Computer Inc.
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING.  If not, write to
21 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.  */
23
24 #ifndef CONFIG_DARWIN_H
25 #define CONFIG_DARWIN_H
26
27 /* The definitions in this file are common to all processor types
28    running Darwin, which is the kernel for Mac OS X.  Darwin is
29    basically a BSD user layer laid over a Mach kernel, then evolved
30    for many years (at NeXT) in parallel with other Unix systems.  So
31    while the runtime is a somewhat idiosyncratic Mach-based thing,
32    other definitions look like they would for a BSD variant.  */
33
34 /* Although NeXT ran on many different architectures, as of Jan 2001
35    the only supported Darwin targets are PowerPC and x86.  */
36
37 /* One of Darwin's NeXT legacies is the Mach-O format, which is partly
38    like a.out and partly like COFF, with additional features like
39    multi-architecture binary support.  */
40
41 #define OBJECT_FORMAT_MACHO
42
43 /* Suppress g++ attempt to link in the math library automatically. */
44 #define MATH_LIBRARY ""
45
46 /* We have atexit.  */
47
48 #define HAVE_ATEXIT
49
50 /* Define an empty body for the function do_global_dtors() in libgcc2.c.  */
51
52 #define DO_GLOBAL_DTORS_BODY
53
54 /* The string value for __SIZE_TYPE__.  */
55
56 #ifndef SIZE_TYPE
57 #define SIZE_TYPE "long unsigned int"
58 #endif
59
60 /* Type used for ptrdiff_t, as a string used in a declaration.  */
61
62 #undef  PTRDIFF_TYPE
63 #define PTRDIFF_TYPE "int"
64
65 /* wchar_t is int.  */
66
67 #undef  WCHAR_TYPE
68 #define WCHAR_TYPE "int"
69 #undef  WCHAR_TYPE_SIZE
70 #define WCHAR_TYPE_SIZE 32
71
72 /* Default to using the NeXT-style runtime, since that's what is
73    pre-installed on Darwin systems.  */
74
75 #define NEXT_OBJC_RUNTIME
76
77 /* Don't default to pcc-struct-return, because gcc is the only compiler, and
78    we want to retain compatibility with older gcc versions.  */
79
80 #undef  DEFAULT_PCC_STRUCT_RETURN
81 #define DEFAULT_PCC_STRUCT_RETURN 0
82
83 /* True if pragma ms_struct is in effect.  */
84 extern GTY(()) int darwin_ms_struct;
85
86 /* This table intercepts weirdo options whose names would interfere
87    with normal driver conventions, and either translates them into
88    standardly-named options, or adds a 'Z' so that they can get to
89    specs processing without interference.
90
91    Do not expand a linker option to "-Xlinker -<option>", since that
92    forfeits the ability to control via spec strings later.  However,
93    as a special exception, do this translation with -filelist, because
94    otherwise the driver will think there are no input files and quit.
95    (The alternative would be to hack the driver to recognize -filelist
96    specially, but it's simpler to use the translation table.)
97
98    Note that an option name with a prefix that matches another option
99    name, that also takes an argument, needs to be modified so the
100    prefix is different, otherwise a '*' after the shorter option will
101    match with the longer one.
102
103    The SUBTARGET_OPTION_TRANSLATE_TABLE macro, which _must_ be defined
104    in gcc/config/{i386,rs6000}/darwin.h, should contain any additional
105    command-line option translations specific to the particular target
106    architecture.  */
107
108 #define TARGET_OPTION_TRANSLATE_TABLE \
109   { "-all_load", "-Zall_load" },  \
110   { "-allowable_client", "-Zallowable_client" },  \
111   { "-arch_errors_fatal", "-Zarch_errors_fatal" },  \
112   { "-bind_at_load", "-Zbind_at_load" },  \
113   { "-bundle", "-Zbundle" },  \
114   { "-bundle_loader", "-Zbundle_loader" },  \
115   { "-weak_reference_mismatches", "-Zweak_reference_mismatches" },  \
116   { "-dead_strip", "-Zdead_strip" }, \
117   { "-no_dead_strip_inits_and_terms", "-Zno_dead_strip_inits_and_terms" }, \
118   { "-dependency-file", "-MF" }, \
119   { "-dylib_file", "-Zdylib_file" }, \
120   { "-dynamic", "-Zdynamic" },  \
121   { "-dynamiclib", "-Zdynamiclib" },  \
122   { "-exported_symbols_list", "-Zexported_symbols_list" },  \
123   { "-gfull", "-g -fno-eliminate-unused-debug-symbols" }, \
124   { "-gused", "-g -feliminate-unused-debug-symbols" }, \
125   { "-segaddr", "-Zsegaddr" }, \
126   { "-segs_read_only_addr", "-Zsegs_read_only_addr" }, \
127   { "-segs_read_write_addr", "-Zsegs_read_write_addr" }, \
128   { "-seg_addr_table", "-Zseg_addr_table" }, \
129   { "-seg_addr_table_filename", "-Zfn_seg_addr_table_filename" }, \
130   { "-filelist", "-Xlinker -filelist -Xlinker" },  \
131   { "-framework", "-Xlinker -framework -Xlinker" },  \
132   { "-flat_namespace", "-Zflat_namespace" },  \
133   { "-force_cpusubtype_ALL", "-Zforce_cpusubtype_ALL" },  \
134   { "-force_flat_namespace", "-Zforce_flat_namespace" },  \
135   { "-image_base", "-Zimage_base" },  \
136   { "-init", "-Zinit" },  \
137   { "-install_name", "-Zinstall_name" },  \
138   { "-multiply_defined_unused", "-Zmultiplydefinedunused" },  \
139   { "-multiply_defined", "-Zmultiply_defined" },  \
140   { "-multi_module", "-Zmulti_module" },  \
141   { "-static", "-static -Wa,-static" },  \
142   { "-single_module", "-Zsingle_module" },  \
143   { "-unexported_symbols_list", "-Zunexported_symbols_list" }, \
144   SUBTARGET_OPTION_TRANSLATE_TABLE
145
146 /* These compiler options take n arguments.  */
147
148 #undef  WORD_SWITCH_TAKES_ARG
149 #define WORD_SWITCH_TAKES_ARG(STR)              \
150   (DEFAULT_WORD_SWITCH_TAKES_ARG (STR) ? 1 :    \
151    !strcmp (STR, "Zallowable_client") ? 1 :     \
152    !strcmp (STR, "arch") ? 1 :                  \
153    !strcmp (STR, "arch_only") ? 1 :             \
154    !strcmp (STR, "Zbundle_loader") ? 1 :        \
155    !strcmp (STR, "client_name") ? 1 :           \
156    !strcmp (STR, "compatibility_version") ? 1 : \
157    !strcmp (STR, "current_version") ? 1 :       \
158    !strcmp (STR, "Zdylib_file") ? 1 :           \
159    !strcmp (STR, "Zexported_symbols_list") ? 1 : \
160    !strcmp (STR, "Zimage_base") ? 1 :           \
161    !strcmp (STR, "Zinit") ? 1 :                 \
162    !strcmp (STR, "Zinstall_name") ? 1 :         \
163    !strcmp (STR, "Zmultiplydefinedunused") ? 1 : \
164    !strcmp (STR, "Zmultiply_defined") ? 1 :     \
165    !strcmp (STR, "precomp-trustfile") ? 1 :     \
166    !strcmp (STR, "read_only_relocs") ? 1 :      \
167    !strcmp (STR, "sectcreate") ? 3 :            \
168    !strcmp (STR, "sectorder") ? 3 :             \
169    !strcmp (STR, "Zsegaddr") ? 2 :              \
170    !strcmp (STR, "Zsegs_read_only_addr") ? 1 :  \
171    !strcmp (STR, "Zsegs_read_write_addr") ? 1 : \
172    !strcmp (STR, "Zseg_addr_table") ? 1 :       \
173    !strcmp (STR, "Zfn_seg_addr_table_filename") ? 1 :\
174    !strcmp (STR, "seg1addr") ? 1 :              \
175    !strcmp (STR, "segprot") ? 3 :               \
176    !strcmp (STR, "sub_library") ? 1 :           \
177    !strcmp (STR, "sub_umbrella") ? 1 :          \
178    !strcmp (STR, "umbrella") ? 1 :              \
179    !strcmp (STR, "undefined") ? 1 :             \
180    !strcmp (STR, "Zunexported_symbols_list") ? 1 : \
181    !strcmp (STR, "Zweak_reference_mismatches") ? 1 : \
182    !strcmp (STR, "pagezero_size") ? 1 :         \
183    !strcmp (STR, "segs_read_only_addr") ? 1 :   \
184    !strcmp (STR, "segs_read_write_addr") ? 1 :  \
185    !strcmp (STR, "sectalign") ? 3 :             \
186    !strcmp (STR, "sectobjectsymbols") ? 2 :     \
187    !strcmp (STR, "segcreate") ? 3 :             \
188    !strcmp (STR, "dylinker_install_name") ? 1 : \
189    0)
190
191 /* Machine dependent cpp options.  Don't add more options here, add
192    them to darwin_cpp_builtins in darwin-c.c.  */
193
194 #undef  CPP_SPEC
195 #define CPP_SPEC "%{static:%{!dynamic:-D__STATIC__}}%{!static:-D__DYNAMIC__}"
196
197 /* This is mostly a clone of the standard LINK_COMMAND_SPEC, plus
198    precomp, libtool, and fat build additions.  Also we
199    don't specify a second %G after %L because libSystem is
200    self-contained and doesn't need to link against libgcc.a.  */
201 /* In general, random Darwin linker flags should go into LINK_SPEC
202    instead of LINK_COMMAND_SPEC.  The command spec is better for
203    specifying the handling of options understood by generic Unix
204    linkers, and for positional arguments like libraries.  */
205 #define LINK_COMMAND_SPEC "\
206 %{!fdump=*:%{!fsyntax-only:%{!precomp:%{!c:%{!M:%{!MM:%{!E:%{!S:\
207     %{!Zdynamiclib:%(linker)}%{Zdynamiclib:/usr/bin/libtool} \
208     %l %X %{d} %{s} %{t} %{Z} \
209     %{!Zdynamiclib:%{A} %{e*} %{m} %{N} %{n} %{r} %{u*} %{x} %{z}} \
210     %{@:-o %f%u.out}%{!@:%{o*}%{!o:-o a.out}} \
211     %{!A:%{!nostdlib:%{!nostartfiles:%S}}} \
212     %{L*} %{fopenmp:%:include(libgomp.spec)%(link_gomp)}   \
213     %(link_libgcc) %o %{fprofile-arcs|fprofile-generate|coverage:-lgcov} \
214     %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %G %L}} \
215     %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*} }}}}}}}}"
216
217 /* Please keep the random linker options in alphabetical order (modulo
218    'Z' and 'no' prefixes).  Options that can only go to one of libtool
219    or ld must be listed twice, under both !Zdynamiclib and
220    Zdynamiclib, with one of the cases reporting an error.  */
221 /* Note that options taking arguments may appear multiple times on a
222    command line with different arguments each time, so put a * after
223    their names so all of them get passed.  */
224 #define LINK_SPEC  \
225   "%{static}%{!static:-dynamic} \
226    %{fgnu-runtime:%:replace-outfile(-lobjc -lobjc-gnu)}\
227    %{!Zdynamiclib: \
228      %{Zforce_cpusubtype_ALL:-arch %(darwin_arch) -force_cpusubtype_ALL} \
229      %{!Zforce_cpusubtype_ALL:-arch %(darwin_subarch)} \
230      %{Zbundle:-bundle} \
231      %{Zbundle_loader*:-bundle_loader %*} \
232      %{client_name*} \
233      %{compatibility_version*:%e-compatibility_version only allowed with -dynamiclib\
234 } \
235      %{current_version*:%e-current_version only allowed with -dynamiclib} \
236      %{Zforce_flat_namespace:-force_flat_namespace} \
237      %{Zinstall_name*:%e-install_name only allowed with -dynamiclib} \
238      %{keep_private_externs} \
239      %{private_bundle} \
240     } \
241    %{Zdynamiclib: \
242      %{Zbundle:%e-bundle not allowed with -dynamiclib} \
243      %{Zbundle_loader*:%e-bundle_loader not allowed with -dynamiclib} \
244      %{client_name*:%e-client_name not allowed with -dynamiclib} \
245      %{compatibility_version*} \
246      %{current_version*} \
247      %{Zforce_cpusubtype_ALL:-arch_only %(darwin_arch)} \
248      %{!Zforce_cpusubtype_ALL: -arch_only %(darwin_subarch)} \
249      %{Zforce_flat_namespace:%e-force_flat_namespace not allowed with -dynamiclib} \
250      %{Zinstall_name*:-install_name %*} \
251      %{keep_private_externs:%e-keep_private_externs not allowed with -dynamiclib} \
252      %{private_bundle:%e-private_bundle not allowed with -dynamiclib} \
253     } \
254    %{Zall_load:-all_load}%{Zdynamiclib:%{!Zall_load:-noall_load}} \
255    %{Zallowable_client*:-allowable_client %*} \
256    %{Zbind_at_load:-bind_at_load} \
257    %{Zarch_errors_fatal:-arch_errors_fatal} \
258    %{Zdead_strip:-dead_strip} \
259    %{Zno_dead_strip_inits_and_terms:-no_dead_strip_inits_and_terms} \
260    %{Zdylib_file*:-dylib_file %*} \
261    %{Zdynamic:-dynamic}\
262    %{Zexported_symbols_list*:-exported_symbols_list %*} \
263    %{Zflat_namespace:-flat_namespace} \
264    %{headerpad_max_install_names*} \
265    %{Zimage_base*:-image_base %*} \
266    %{Zinit*:-init %*} \
267    %{mmacosx-version-min=*:-macosx_version_min %*} \
268    %{!mmacosx-version-min=*:%{shared-libgcc:-macosx_version_min 10.3}} \
269    %{nomultidefs} \
270    %{Zmulti_module:-multi_module} %{Zsingle_module:-single_module} \
271    %{Zmultiply_defined*:-multiply_defined %*} \
272    %{!Zmultiply_defined*:%{shared-libgcc: \
273      %:version-compare(< 10.5 mmacosx-version-min= -multiply_defined) \
274      %:version-compare(< 10.5 mmacosx-version-min= suppress)}} \
275    %{Zmultiplydefinedunused*:-multiply_defined_unused %*} \
276    %{prebind} %{noprebind} %{nofixprebinding} %{prebind_all_twolevel_modules} \
277    %{read_only_relocs} \
278    %{sectcreate*} %{sectorder*} %{seg1addr*} %{segprot*} \
279    %{Zsegaddr*:-segaddr %*} \
280    %{Zsegs_read_only_addr*:-segs_read_only_addr %*} \
281    %{Zsegs_read_write_addr*:-segs_read_write_addr %*} \
282    %{Zseg_addr_table*: -seg_addr_table %*} \
283    %{Zfn_seg_addr_table_filename*:-seg_addr_table_filename %*} \
284    %{sub_library*} %{sub_umbrella*} \
285    %{isysroot*:-syslibroot %*} \
286    %{twolevel_namespace} %{twolevel_namespace_hints} \
287    %{umbrella*} \
288    %{undefined*} \
289    %{Zunexported_symbols_list*:-unexported_symbols_list %*} \
290    %{Zweak_reference_mismatches*:-weak_reference_mismatches %*} \
291    %{!Zweak_reference_mismatches*:-weak_reference_mismatches non-weak} \
292    %{X} \
293    %{y*} \
294    %{w} \
295    %{pagezero_size*} %{segs_read_*} %{seglinkedit} %{noseglinkedit}  \
296    %{sectalign*} %{sectobjectsymbols*} %{segcreate*} %{whyload} \
297    %{whatsloaded} %{dylinker_install_name*} \
298    %{dylinker} %{Mach} "
299
300
301 /* Machine dependent libraries.  */
302
303 #define LIB_SPEC "%{!static:-lSystem}"
304
305 /* Support -mmacosx-version-min by supplying different (stub) libgcc_s.dylib
306    libraries to link against, and by not linking against libgcc_s on
307    earlier-than-10.3.9.
308
309    Note that by default, -lgcc_eh is not linked against!  This is
310    because in a future version of Darwin the EH frame information may
311    be in a new format, or the fallback routine might be changed; if
312    you want to explicitly link against the static version of those
313    routines, because you know you don't need to unwind through system
314    libraries, you need to explicitly say -static-libgcc.
315
316    If it is linked against, it has to be before -lgcc, because it may
317    need symbols from -lgcc.  */
318 #undef REAL_LIBGCC_SPEC
319 #define REAL_LIBGCC_SPEC                                                   \
320    "%{static-libgcc|static: -lgcc_eh -lgcc;                                \
321       shared-libgcc|fexceptions:                                           \
322        %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_s.10.4)        \
323        %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_s.10.5)        \
324        -lgcc;                                                              \
325       :%:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \
326        %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_s.10.5)        \
327        -lgcc}"
328
329 /* We specify crt0.o as -lcrt0.o so that ld will search the library path.
330
331    crt3.o provides __cxa_atexit on systems that don't have it.  Since
332    it's only used with C++, which requires passing -shared-libgcc, key
333    off that to avoid unnecessarily adding a destructor to every
334    powerpc program built.  */
335
336 #undef  STARTFILE_SPEC
337 #define STARTFILE_SPEC                                                      \
338   "%{!Zdynamiclib:%{Zbundle:%{!static:-lbundle1.o}}                         \
339      %{!Zbundle:%{pg:%{static:-lgcrt0.o}                                    \
340                      %{!static:%{object:-lgcrt0.o}                          \
341                                %{!object:%{preload:-lgcrt0.o}               \
342                                  %{!preload:-lgcrt1.o %(darwin_crt2)}}}}    \
343                 %{!pg:%{static:-lcrt0.o}                                    \
344                       %{!static:%{object:-lcrt0.o}                          \
345                                 %{!object:%{preload:-lcrt0.o}               \
346                                   %{!preload:-lcrt1.o %(darwin_crt2)}}}}}}  \
347   %{shared-libgcc:%:version-compare(< 10.5 mmacosx-version-min= crt3.o%s)}"
348
349 /* The native Darwin linker doesn't necessarily place files in the order
350    that they're specified on the link line.  Thus, it is pointless
351    to put anything in ENDFILE_SPEC.  */
352 /* #define ENDFILE_SPEC "" */
353
354 /* Default Darwin ASM_SPEC, very simple.  */
355 #define ASM_SPEC "-arch %(darwin_arch) \
356   %{Zforce_cpusubtype_ALL:-force_cpusubtype_ALL}"
357
358 /* We use Dbx symbol format.  */
359
360 #define DBX_DEBUGGING_INFO 1
361
362 /* Also enable Dwarf 2 as an option.  */
363 #define DWARF2_DEBUGGING_INFO
364 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
365
366 #define DEBUG_FRAME_SECTION     "__DWARF,__debug_frame,regular,debug"
367 #define DEBUG_INFO_SECTION      "__DWARF,__debug_info,regular,debug"
368 #define DEBUG_ABBREV_SECTION    "__DWARF,__debug_abbrev,regular,debug"
369 #define DEBUG_ARANGES_SECTION   "__DWARF,__debug_aranges,regular,debug"
370 #define DEBUG_MACINFO_SECTION   "__DWARF,__debug_macinfo,regular,debug"
371 #define DEBUG_LINE_SECTION      "__DWARF,__debug_line,regular,debug"
372 #define DEBUG_LOC_SECTION       "__DWARF,__debug_loc,regular,debug"
373 #define DEBUG_PUBNAMES_SECTION  "__DWARF,__debug_pubnames,regular,debug"
374 #define DEBUG_STR_SECTION       "__DWARF,__debug_str,regular,debug"
375 #define DEBUG_RANGES_SECTION    "__DWARF,__debug_ranges,regular,debug"
376
377 /* When generating stabs debugging, use N_BINCL entries.  */
378
379 #define DBX_USE_BINCL
380
381 /* There is no limit to the length of stabs strings.  */
382
383 #define DBX_CONTIN_LENGTH 0
384
385 /* gdb needs a null N_SO at the end of each file for scattered loading.  */
386
387 #define DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
388
389 /* GCC's definition of 'one_only' is the same as its definition of 'weak'.  */
390 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
391
392 /* Mach-O supports 'weak imports', and 'weak definitions' in coalesced
393    sections.  machopic_select_section ensures that weak variables go in
394    coalesced sections.  Weak aliases (or any other kind of aliases) are
395    not supported.  Weak symbols that aren't visible outside the .s file
396    are not supported.  */
397 #define ASM_WEAKEN_DECL(FILE, DECL, NAME, ALIAS)                        \
398   do {                                                                  \
399     if (ALIAS)                                                          \
400       {                                                                 \
401         warning (0, "alias definitions not supported in Mach-O; ignored");      \
402         break;                                                          \
403       }                                                                 \
404                                                                         \
405     if (! DECL_EXTERNAL (DECL) && TREE_PUBLIC (DECL))                   \
406       targetm.asm_out.globalize_label (FILE, NAME);                     \
407     if (DECL_EXTERNAL (DECL))                                           \
408       fputs ("\t.weak_reference ", FILE);                               \
409     else if (! lookup_attribute ("weak", DECL_ATTRIBUTES (DECL))        \
410         && lookup_attribute ("weak_import", DECL_ATTRIBUTES (DECL)))    \
411       break;                                                            \
412     else if (TREE_PUBLIC (DECL))                                        \
413       fputs ("\t.weak_definition ", FILE);                              \
414     else                                                                \
415       break;                                                            \
416     assemble_name (FILE, NAME);                                         \
417     fputc ('\n', FILE);                                                 \
418   } while (0)
419
420 /* Darwin has the pthread routines in libSystem, which every program
421    links to, so there's no need for weak-ness for that.  */
422 #define GTHREAD_USE_WEAK 0
423
424 /* The Darwin linker imposes two limitations on common symbols: they
425    can't have hidden visibility, and they can't appear in dylibs.  As
426    a consequence, we should never use common symbols to represent
427    vague linkage. */
428 #undef USE_COMMON_FOR_ONE_ONLY
429 #define USE_COMMON_FOR_ONE_ONLY 0
430
431 /* The Darwin linker doesn't want coalesced symbols to appear in
432    a static archive's table of contents. */
433 #undef TARGET_WEAK_NOT_IN_ARCHIVE_TOC
434 #define TARGET_WEAK_NOT_IN_ARCHIVE_TOC 1
435
436 /* On Darwin, we don't (at the time of writing) have linkonce sections
437    with names, so it's safe to make the class data not comdat.  */
438 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT hook_bool_void_false
439
440 /* We make exception information linkonce. */
441 #undef TARGET_USES_WEAK_UNWIND_INFO
442 #define TARGET_USES_WEAK_UNWIND_INFO 1
443
444 /* We need to use a nonlocal label for the start of an EH frame: the
445    Darwin linker requires that a coalesced section start with a label.
446    Unfortunately, it also requires that 'debug' sections don't contain
447    labels.  */
448 #undef FRAME_BEGIN_LABEL
449 #define FRAME_BEGIN_LABEL (for_eh ? "EH_frame" : "Lframe")
450
451 /* Emit a label for the FDE corresponding to DECL.  EMPTY means
452    emit a label for an empty FDE. */
453 #define TARGET_ASM_EMIT_UNWIND_LABEL darwin_emit_unwind_label
454
455 /* Emit a label to separate the exception table.  */
456 #define TARGET_ASM_EMIT_EXCEPT_TABLE_LABEL darwin_emit_except_table_label
457
458 /* Our profiling scheme doesn't LP labels and counter words.  */
459
460 #define NO_PROFILE_COUNTERS     1
461
462 #undef  INIT_SECTION_ASM_OP
463 #define INIT_SECTION_ASM_OP
464
465 #undef  INVOKE__main
466
467 #define TARGET_ASM_CONSTRUCTOR  machopic_asm_out_constructor
468 #define TARGET_ASM_DESTRUCTOR   machopic_asm_out_destructor
469
470 /* Always prefix with an underscore.  */
471
472 #define USER_LABEL_PREFIX "_"
473
474 /* Don't output a .file directive.  That is only used by the assembler for
475    error reporting.  */
476 #undef  TARGET_ASM_FILE_START_FILE_DIRECTIVE
477 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE false
478
479 #undef  TARGET_ASM_FILE_END
480 #define TARGET_ASM_FILE_END darwin_file_end
481
482 #define ASM_OUTPUT_SKIP(FILE,SIZE)  \
483   fprintf (FILE, "\t.space "HOST_WIDE_INT_PRINT_UNSIGNED"\n", SIZE)
484
485 /* Give ObjC methods pretty symbol names.  */
486
487 #undef  OBJC_GEN_METHOD_LABEL
488 #define OBJC_GEN_METHOD_LABEL(BUF,IS_INST,CLASS_NAME,CAT_NAME,SEL_NAME,NUM) \
489   do { if (CAT_NAME)                                                    \
490          sprintf (BUF, "%c[%s(%s) %s]", (IS_INST) ? '-' : '+',          \
491                   (CLASS_NAME), (CAT_NAME), (SEL_NAME));                \
492        else                                                             \
493          sprintf (BUF, "%c[%s %s]", (IS_INST) ? '-' : '+',              \
494                   (CLASS_NAME), (SEL_NAME));                            \
495      } while (0)
496
497 /* The RTTI data (e.g., __ti4name) is common and public (and static),
498    but it does need to be referenced via indirect PIC data pointers.
499    The machopic_define_symbol calls are telling the machopic subsystem
500    that the name *is* defined in this module, so it doesn't need to
501    make them indirect.  */
502
503 #undef ASM_DECLARE_OBJECT_NAME
504 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)                       \
505   do {                                                                  \
506     const char *xname = NAME;                                           \
507     if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF)             \
508       xname = IDENTIFIER_POINTER (DECL_NAME (DECL));                    \
509     if (! DECL_WEAK (DECL)                                              \
510         && ((TREE_STATIC (DECL)                                         \
511              && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))           \
512             || DECL_INITIAL (DECL)))                                    \
513         machopic_define_symbol (DECL_RTL (DECL));                       \
514     if ((TREE_STATIC (DECL)                                             \
515          && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))               \
516         || DECL_INITIAL (DECL))                                         \
517       (* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false);   \
518     ASM_OUTPUT_LABEL (FILE, xname);                                     \
519     /* Darwin doesn't support zero-size objects, so give them a         \
520        byte.  */                                                        \
521     if (tree_low_cst (DECL_SIZE_UNIT (DECL), 1) == 0)                   \
522       assemble_zeros (1);                                               \
523   } while (0)
524
525 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)                     \
526   do {                                                                  \
527     const char *xname = NAME;                                           \
528     if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF)             \
529       xname = IDENTIFIER_POINTER (DECL_NAME (DECL));                    \
530     if (! DECL_WEAK (DECL)                                              \
531         && ((TREE_STATIC (DECL)                                         \
532              && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))           \
533             || DECL_INITIAL (DECL)))                                    \
534         machopic_define_symbol (DECL_RTL (DECL));                       \
535     if ((TREE_STATIC (DECL)                                             \
536          && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))               \
537         || DECL_INITIAL (DECL))                                         \
538       (* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false);   \
539     ASM_OUTPUT_LABEL (FILE, xname);                                     \
540   } while (0)
541
542 #define ASM_DECLARE_CONSTANT_NAME(FILE, NAME, EXP, SIZE)        \
543   do {                                                          \
544     ASM_OUTPUT_LABEL (FILE, NAME);                              \
545     /* Darwin doesn't support zero-size objects, so give them a \
546        byte.  */                                                \
547     if ((SIZE) == 0)                                            \
548       assemble_zeros (1);                                       \
549   } while (0)
550
551 /* Wrap new method names in quotes so the assembler doesn't gag.
552    Make Objective-C internal symbols local.  */
553
554 #undef  ASM_OUTPUT_LABELREF
555 #define ASM_OUTPUT_LABELREF(FILE,NAME)                                       \
556   do {                                                                       \
557        const char *xname = (NAME);                                           \
558        if (! strcmp (xname, "<pic base>"))                                   \
559          machopic_output_function_base_name(FILE);                           \
560        else if (xname[0] == '&' || xname[0] == '*')                          \
561          {                                                                   \
562            int len = strlen (xname);                                         \
563            if (len > 6 && !strcmp ("$stub", xname + len - 5))                \
564              machopic_validate_stub_or_non_lazy_ptr (xname);                 \
565            else if (len > 7 && !strcmp ("$stub\"", xname + len - 6))         \
566              machopic_validate_stub_or_non_lazy_ptr (xname);                 \
567            else if (len > 14 && !strcmp ("$non_lazy_ptr", xname + len - 13)) \
568              machopic_validate_stub_or_non_lazy_ptr (xname);                 \
569            else if (len > 15 && !strcmp ("$non_lazy_ptr\"", xname + len - 14)) \
570              machopic_validate_stub_or_non_lazy_ptr (xname);                 \
571            if (xname[1] != '"' && name_needs_quotes (&xname[1]))             \
572              fprintf (FILE, "\"%s\"", &xname[1]);                            \
573            else                                                              \
574              fputs (&xname[1], FILE);                                        \
575          }                                                                   \
576        else if (xname[0] == '+' || xname[0] == '-')                          \
577          fprintf (FILE, "\"%s\"", xname);                                    \
578        else if (!strncmp (xname, "_OBJC_", 6))                               \
579          fprintf (FILE, "L%s", xname);                                       \
580        else if (!strncmp (xname, ".objc_class_name_", 17))                   \
581          fprintf (FILE, "%s", xname);                                        \
582        else if (xname[0] != '"' && name_needs_quotes (xname))                \
583          fprintf (FILE, "\"%s\"", xname);                                    \
584        else                                                                  \
585          asm_fprintf (FILE, "%U%s", xname);                                  \
586   } while (0)
587
588 /* Output before executable code.  */
589 #undef TEXT_SECTION_ASM_OP
590 #define TEXT_SECTION_ASM_OP "\t.text"
591
592 /* Output before writable data.  */
593
594 #undef DATA_SECTION_ASM_OP
595 #define DATA_SECTION_ASM_OP "\t.data"
596
597 #undef  ALIGN_ASM_OP
598 #define ALIGN_ASM_OP            ".align"
599
600 #undef  ASM_OUTPUT_ALIGN
601 #define ASM_OUTPUT_ALIGN(FILE,LOG)      \
602   if ((LOG) != 0)                       \
603     fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG))
604
605 /* Ensure correct alignment of bss data.  */
606
607 #undef  ASM_OUTPUT_ALIGNED_DECL_LOCAL
608 #define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN)    \
609   do {                                                                  \
610     unsigned HOST_WIDE_INT _new_size = SIZE;                            \
611     fputs (".lcomm ", (FILE));                                          \
612     assemble_name ((FILE), (NAME));                                     \
613     if (_new_size == 0) _new_size = 1;                                  \
614     fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", _new_size, \
615              floor_log2 ((ALIGN) / BITS_PER_UNIT));                     \
616     if ((DECL) && ((TREE_STATIC (DECL)                                  \
617          && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))               \
618         || DECL_INITIAL (DECL)))                                        \
619       {                                                                 \
620         (* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false); \
621         machopic_define_symbol (DECL_RTL (DECL));                       \
622       }                                                                 \
623   } while (0)
624
625 /* The maximum alignment which the object file format can support.
626    For Mach-O, this is 2^15.  */
627
628 #undef  MAX_OFILE_ALIGNMENT
629 #define MAX_OFILE_ALIGNMENT 0x8000
630
631 /* Declare the section variables.  */
632 #ifndef USED_FOR_TARGET
633 enum darwin_section_enum {
634 #define DEF_SECTION(NAME, FLAGS, DIRECTIVE, OBJC) NAME,
635 #include "darwin-sections.def"
636 #undef DEF_SECTION
637   NUM_DARWIN_SECTIONS
638 };
639 extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
640 #endif
641
642 #undef  TARGET_ASM_SELECT_SECTION
643 #define TARGET_ASM_SELECT_SECTION machopic_select_section
644 #define USE_SELECT_SECTION_FOR_FUNCTIONS
645
646 #undef  TARGET_ASM_SELECT_RTX_SECTION
647 #define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
648 #undef  TARGET_ASM_UNIQUE_SECTION
649 #define TARGET_ASM_UNIQUE_SECTION darwin_unique_section
650 #undef  TARGET_ASM_FUNCTION_RODATA_SECTION
651 #define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
652
653
654 #define ASM_DECLARE_UNRESOLVED_REFERENCE(FILE,NAME)                     \
655     do {                                                                \
656          if (FILE) {                                                    \
657            if (MACHOPIC_INDIRECT)                                       \
658              fprintf (FILE, "\t.lazy_reference ");                      \
659            else                                                         \
660              fprintf (FILE, "\t.reference ");                           \
661            assemble_name (FILE, NAME);                                  \
662            fprintf (FILE, "\n");                                        \
663          }                                                              \
664        } while (0)
665
666 #define ASM_DECLARE_CLASS_REFERENCE(FILE,NAME)                          \
667     do {                                                                \
668          if (FILE) {                                                    \
669            fprintf (FILE, "\t");                                        \
670            assemble_name (FILE, NAME);                                  \
671            fprintf (FILE, "=0\n");                                      \
672            (*targetm.asm_out.globalize_label) (FILE, NAME);             \
673          }                                                              \
674        } while (0)
675
676 /* Globalizing directive for a label.  */
677 #define GLOBAL_ASM_OP ".globl "
678 #define TARGET_ASM_GLOBALIZE_LABEL darwin_globalize_label
679
680 /* Emit an assembler directive to set visibility for a symbol.  Used
681    to support visibility attribute and Darwin's private extern
682    feature.  */
683 #undef TARGET_ASM_ASSEMBLE_VISIBILITY
684 #define TARGET_ASM_ASSEMBLE_VISIBILITY darwin_assemble_visibility
685
686 /* Extra attributes for Darwin.  */
687 #define SUBTARGET_ATTRIBUTE_TABLE                                            \
688   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ \
689   { "weak_import", 0, 0, true, false, false,                                 \
690     darwin_handle_weak_import_attribute }
691
692 #undef ASM_GENERATE_INTERNAL_LABEL
693 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)   \
694   sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM))
695
696 #undef TARGET_ASM_MARK_DECL_PRESERVED
697 #define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved
698
699 /* Set on a symbol with SYMBOL_FLAG_FUNCTION or
700    MACHO_SYMBOL_FLAG_VARIABLE to indicate that the function or
701    variable has been defined in this translation unit.  */
702
703 #define MACHO_SYMBOL_FLAG_VARIABLE (SYMBOL_FLAG_MACH_DEP)
704 #define MACHO_SYMBOL_FLAG_DEFINED ((SYMBOL_FLAG_MACH_DEP) << 1)
705
706 /* Set on a symbol to indicate when fix-and-continue style code
707    generation is being used and the symbol refers to a static symbol
708    that should be rebound from new instances of a translation unit to
709    the original instance of the data.  */
710
711 #define MACHO_SYMBOL_STATIC ((SYMBOL_FLAG_MACH_DEP) << 2)
712
713 /* Symbolic names for various things we might know about a symbol.  */
714
715 enum machopic_addr_class {
716   MACHOPIC_UNDEFINED,
717   MACHOPIC_DEFINED_DATA,
718   MACHOPIC_UNDEFINED_DATA,
719   MACHOPIC_DEFINED_FUNCTION,
720   MACHOPIC_UNDEFINED_FUNCTION
721 };
722
723 /* Macros defining the various PIC cases.  */
724
725 #define MACHO_DYNAMIC_NO_PIC_P  (TARGET_DYNAMIC_NO_PIC)
726 #define MACHOPIC_INDIRECT       (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
727 #define MACHOPIC_JUST_INDIRECT  (MACHO_DYNAMIC_NO_PIC_P)
728 #define MACHOPIC_PURE           (flag_pic && ! MACHO_DYNAMIC_NO_PIC_P)
729
730 #undef TARGET_ENCODE_SECTION_INFO
731 #define TARGET_ENCODE_SECTION_INFO  darwin_encode_section_info
732 #undef TARGET_STRIP_NAME_ENCODING
733 #define TARGET_STRIP_NAME_ENCODING  default_strip_name_encoding
734
735 #define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH)          \
736   do {                                                          \
737     const char *const stub_ = (STUB);                           \
738     char *buffer_ = (BUF);                                      \
739     strcpy (buffer_, stub_);                                    \
740     if (stub_[0] == '"')                                        \
741       {                                                         \
742         strcpy (buffer_ + (STUB_LENGTH) - 1, "_binder\"");      \
743       }                                                         \
744     else                                                        \
745       {                                                         \
746         strcpy (buffer_ + (STUB_LENGTH), "_binder");            \
747       }                                                         \
748   } while (0)
749
750 #define GEN_SYMBOL_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH)    \
751   do {                                                          \
752     const char *const symbol_ = (SYMBOL);                       \
753     char *buffer_ = (BUF);                                      \
754     if (name_needs_quotes (symbol_) && symbol_[0] != '"')       \
755       {                                                         \
756           sprintf (buffer_, "\"%s\"", symbol_);                 \
757       }                                                         \
758     else                                                        \
759       {                                                         \
760         strcpy (buffer_, symbol_);                              \
761       }                                                         \
762   } while (0)
763
764 /* Given a symbol name string, create the lazy pointer version
765    of the symbol name.  */
766
767 #define GEN_LAZY_PTR_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH)  \
768   do {                                                          \
769     const char *symbol_ = (SYMBOL);                             \
770     char *buffer_ = (BUF);                                      \
771     if (symbol_[0] == '"')                                      \
772       {                                                         \
773         strcpy (buffer_, "\"L");                                \
774         strcpy (buffer_ + 2, symbol_ + 1);                      \
775         strcpy (buffer_ + (SYMBOL_LENGTH), "$lazy_ptr\"");      \
776       }                                                         \
777     else if (name_needs_quotes (symbol_))                       \
778       {                                                         \
779         strcpy (buffer_, "\"L");                                \
780         strcpy (buffer_ + 2, symbol_);                          \
781         strcpy (buffer_ + (SYMBOL_LENGTH) + 2, "$lazy_ptr\"");  \
782       }                                                         \
783     else                                                        \
784       {                                                         \
785         strcpy (buffer_, "L");                                  \
786         strcpy (buffer_ + 1, symbol_);                          \
787         strcpy (buffer_ + (SYMBOL_LENGTH) + 1, "$lazy_ptr");    \
788       }                                                         \
789   } while (0)
790
791 #define EH_FRAME_SECTION_NAME   "__TEXT"
792 #define EH_FRAME_SECTION_ATTR ",coalesced,no_toc+strip_static_syms+live_support"
793
794 /* Java runtime class list.  */
795 #define JCR_SECTION_NAME "__DATA,jcr,regular,no_dead_strip"
796
797 #undef ASM_PREFERRED_EH_DATA_FORMAT
798 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL)  \
799   (((CODE) == 2 && (GLOBAL) == 1) \
800    ? (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4) : \
801      ((CODE) == 1 || (GLOBAL) == 0) ? DW_EH_PE_pcrel : DW_EH_PE_absptr)
802
803 #define ASM_OUTPUT_DWARF_DELTA(FILE,SIZE,LABEL1,LABEL2)  \
804   darwin_asm_output_dwarf_delta (FILE, SIZE, LABEL1, LABEL2)
805
806 #define ASM_OUTPUT_DWARF_OFFSET(FILE,SIZE,LABEL,BASE)  \
807   darwin_asm_output_dwarf_offset (FILE, SIZE, LABEL, BASE)
808
809 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(ASM_OUT_FILE, ENCODING, SIZE, ADDR, DONE)     \
810       if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) {                            \
811         darwin_non_lazy_pcrel (ASM_OUT_FILE, ADDR);                                     \
812         goto DONE;                                                                      \
813       }
814
815 #define TARGET_ASM_OUTPUT_ANCHOR darwin_asm_output_anchor
816
817 /* Experimentally, putting jump tables in text is faster on SPEC.
818    Also this is needed for correctness for coalesced functions.  */
819
820 #ifndef JUMP_TABLES_IN_TEXT_SECTION
821 #define JUMP_TABLES_IN_TEXT_SECTION 1
822 #endif
823
824 #define TARGET_TERMINATE_DW2_EH_FRAME_INFO false
825
826 #define TARGET_ASM_INIT_SECTIONS darwin_init_sections
827 #undef TARGET_ASM_NAMED_SECTION
828 #define TARGET_ASM_NAMED_SECTION darwin_asm_named_section
829
830 #define DARWIN_REGISTER_TARGET_PRAGMAS()                        \
831   do {                                                          \
832     c_register_pragma (0, "mark", darwin_pragma_ignore);        \
833     c_register_pragma (0, "options", darwin_pragma_options);    \
834     c_register_pragma (0, "segment", darwin_pragma_ignore);     \
835     c_register_pragma (0, "unused", darwin_pragma_unused);      \
836     c_register_pragma (0, "ms_struct", darwin_pragma_ms_struct); \
837   } while (0)
838
839 #undef ASM_APP_ON
840 #define ASM_APP_ON ""
841 #undef ASM_APP_OFF
842 #define ASM_APP_OFF ""
843
844 void darwin_register_frameworks (const char *, const char *, int);
845 void darwin_register_objc_includes (const char *, const char *, int);
846 #define TARGET_EXTRA_PRE_INCLUDES darwin_register_objc_includes
847 #define TARGET_EXTRA_INCLUDES darwin_register_frameworks
848
849 void add_framework_path (char *);
850 #define TARGET_OPTF add_framework_path
851
852 #define TARGET_POSIX_IO
853
854 /* All new versions of Darwin have C99 functions.  */
855 #define TARGET_C99_FUNCTIONS 1
856
857 #define WINT_TYPE "int"
858
859 /* Every program on darwin links against libSystem which contains the pthread
860    routines, so there's no need to explicitly call out when doing threaded
861    work.  */
862 #undef GOMP_SELF_SPECS
863 #define GOMP_SELF_SPECS ""
864
865 #endif /* CONFIG_DARWIN_H */