1 /* Target definitions for Darwin (Mac OS X) systems.
2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Apple Computer Inc.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* The definitions in this file are common to all processor types
24 running Darwin, which is the kernel for Mac OS X. Darwin is
25 basically a BSD user layer laid over a Mach kernel, then evolved
26 for many years (at NeXT) in parallel with other Unix systems. So
27 while the runtime is a somewhat idiosyncratic Mach-based thing,
28 other definitions look like they would for a BSD variant. */
30 /* Although NeXT ran on many different architectures, as of Jan 2001
31 the only supported Darwin targets are PowerPC and x86. */
33 /* Technically, STANDARD_EXEC_PREFIX should be /usr/libexec/, but in
34 practice this makes it hard to install new compilers elsewhere, so
35 leave it undefined and expect system builders to set configure args
38 /* Suppress g++ attempt to link in the math library automatically.
39 (Some Darwin versions have a libm, but they seem to cause problems
40 for C++ executables.) */
42 #define MATH_LIBRARY ""
48 /* Define an empty body for the function do_global_dtors() in libgcc2.c. */
50 #define DO_GLOBAL_DTORS_BODY
52 /* The string value for __SIZE_TYPE__. */
55 #define SIZE_TYPE "long unsigned int"
58 /* Type used for ptrdiff_t, as a string used in a declaration. */
61 #define PTRDIFF_TYPE "int"
66 #define WCHAR_TYPE "int"
67 #undef WCHAR_TYPE_SIZE
68 #define WCHAR_TYPE_SIZE 32
70 /* Default to using the NeXT-style runtime, since that's what is
71 pre-installed on Darwin systems. */
73 #define NEXT_OBJC_RUNTIME
75 /* Don't default to pcc-struct-return, because gcc is the only compiler, and
76 we want to retain compatibility with older gcc versions. */
78 #undef DEFAULT_PCC_STRUCT_RETURN
79 #define DEFAULT_PCC_STRUCT_RETURN 0
81 /* Don't warn about MacOS-style 'APPL' four-char-constants. */
83 #undef WARN_FOUR_CHAR_CONSTANTS
84 #define WARN_FOUR_CHAR_CONSTANTS 0
86 /* Machine dependent cpp options. */
89 #define CPP_SPEC "%{static:-D__STATIC__}%{!static:-D__DYNAMIC__}"
91 /* Machine dependent libraries. */
94 #define LIB_SPEC "%{!static:-lSystem}"
96 /* We specify crt0.o as -lcrt0.o so that ld will search the library path. */
99 #define STARTFILE_SPEC \
100 "%{pg:%{static:-lgcrt0.o}%{!static:-lgcrt1.o}} \
101 %{!pg:%{static:-lcrt0.o}%{!static:-lcrt1.o}}"
103 #undef DOLLARS_IN_IDENTIFIERS
104 #define DOLLARS_IN_IDENTIFIERS 2
106 /* We use Dbx symbol format. */
108 #define DBX_DEBUGGING_INFO 1
110 /* Also enable Dwarf 2 as an option. */
112 #define DWARF2_DEBUGGING_INFO 1
114 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
116 /* When generating stabs debugging, use N_BINCL entries. */
118 #define DBX_USE_BINCL
120 /* There is no limit to the length of stabs strings. */
122 #define DBX_CONTIN_LENGTH 0
124 /* gdb needs a null N_SO at the end of each file for scattered loading. */
126 #undef DBX_OUTPUT_MAIN_SOURCE_FILE_END
127 #define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \
128 do { text_section (); \
130 "\t.stabs \"%s\",%d,0,0,Letext\nLetext:\n", "" , N_SO); \
133 /* Our profiling scheme doesn't LP labels and counter words. */
135 #define NO_PROFILE_COUNTERS
137 #undef INIT_SECTION_ASM_OP
138 #define INIT_SECTION_ASM_OP
142 #define TARGET_ASM_CONSTRUCTOR machopic_asm_out_constructor
143 #define TARGET_ASM_DESTRUCTOR machopic_asm_out_destructor
146 /* Don't output a .file directive. That is only used by the assembler for
149 #undef ASM_FILE_START
150 #define ASM_FILE_START(FILE)
153 #define ASM_FILE_END(FILE) \
155 machopic_finish (asm_out_file); \
156 if (strcmp (lang_hooks.name, "GNU C++") == 0) \
158 constructor_section (); \
159 destructor_section (); \
160 ASM_OUTPUT_ALIGN (FILE, 1); \
164 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
165 fprintf (FILE, "\t.space %d\n", SIZE)
167 /* Give ObjC methods pretty symbol names. */
169 #undef OBJC_GEN_METHOD_LABEL
170 #define OBJC_GEN_METHOD_LABEL(BUF,IS_INST,CLASS_NAME,CAT_NAME,SEL_NAME,NUM) \
172 sprintf (BUF, "%c[%s(%s) %s]", (IS_INST) ? '-' : '+', \
173 (CLASS_NAME), (CAT_NAME), (SEL_NAME)); \
175 sprintf (BUF, "%c[%s %s]", (IS_INST) ? '-' : '+', \
176 (CLASS_NAME), (SEL_NAME)); \
179 /* The RTTI data (e.g., __ti4name) is common and public (and static),
180 but it does need to be referenced via indirect PIC data pointers.
181 The machopic_define_name calls are telling the machopic subsystem
182 that the name *is* defined in this module, so it doesn't need to
183 make them indirect. */
185 #undef ASM_DECLARE_OBJECT_NAME
186 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
188 const char *xname = NAME; \
189 if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF) \
190 xname = IDENTIFIER_POINTER (DECL_NAME (DECL)); \
191 if ((TREE_STATIC (DECL) \
192 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
193 || DECL_INITIAL (DECL)) \
194 machopic_define_name (xname); \
195 if ((TREE_STATIC (DECL) \
196 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
197 || DECL_INITIAL (DECL)) \
198 (* targetm.encode_section_info) (DECL, false); \
199 ASM_OUTPUT_LABEL (FILE, xname); \
202 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
204 const char *xname = NAME; \
205 if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF) \
206 xname = IDENTIFIER_POINTER (DECL_NAME (DECL)); \
207 if ((TREE_STATIC (DECL) \
208 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
209 || DECL_INITIAL (DECL)) \
210 machopic_define_name (xname); \
211 if ((TREE_STATIC (DECL) \
212 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
213 || DECL_INITIAL (DECL)) \
214 (* targetm.encode_section_info) (DECL, false); \
215 ASM_OUTPUT_LABEL (FILE, xname); \
216 /* Avoid generating stubs for functions we've just defined by \
217 outputting any required stub name label now. */ \
218 machopic_output_possible_stub_label (FILE, xname); \
221 /* Wrap new method names in quotes so the assembler doesn't gag.
222 Make Objective-C internal symbols local. */
224 #undef ASM_OUTPUT_LABELREF
225 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
227 const char *xname = darwin_strip_name_encoding (NAME); \
228 if (xname[0] == '&' || xname[0] == '*') \
230 int len = strlen (xname); \
231 if (len > 6 && !strcmp ("$stub", xname + len - 5)) \
232 machopic_validate_stub_or_non_lazy_ptr (xname, 1); \
233 else if (len > 7 && !strcmp ("$stub\"", xname + len - 6)) \
234 machopic_validate_stub_or_non_lazy_ptr (xname, 1); \
235 else if (len > 14 && !strcmp ("$non_lazy_ptr", xname + len - 13)) \
236 machopic_validate_stub_or_non_lazy_ptr (xname, 0); \
237 fputs (&xname[1], FILE); \
239 else if (xname[0] == '+' || xname[0] == '-') \
240 fprintf (FILE, "\"%s\"", xname); \
241 else if (!strncmp (xname, "_OBJC_", 6)) \
242 fprintf (FILE, "L%s", xname); \
243 else if (!strncmp (xname, ".objc_class_name_", 17)) \
244 fprintf (FILE, "%s", xname); \
246 fprintf (FILE, "_%s", xname); \
249 /* Output before executable code. */
250 #undef TEXT_SECTION_ASM_OP
251 #define TEXT_SECTION_ASM_OP ".text"
253 /* Output before writable data. */
255 #undef DATA_SECTION_ASM_OP
256 #define DATA_SECTION_ASM_OP ".data"
259 #define ALIGN_ASM_OP ".align"
261 #undef ASM_OUTPUT_ALIGN
262 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
264 fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG))
266 /* Ensure correct alignment of bss data. */
268 #undef ASM_OUTPUT_ALIGNED_DECL_LOCAL
269 #define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN) \
271 fputs (".lcomm ", (FILE)); \
272 assemble_name ((FILE), (NAME)); \
273 fprintf ((FILE), ",%u,%u\n", (SIZE), \
274 floor_log2 ((ALIGN) / BITS_PER_UNIT)); \
275 if ((DECL) && ((TREE_STATIC (DECL) \
276 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
277 || DECL_INITIAL (DECL))) \
278 (* targetm.encode_section_info) (DECL, false); \
279 if ((DECL) && ((TREE_STATIC (DECL) \
280 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
281 || DECL_INITIAL (DECL))) \
282 machopic_define_name (NAME); \
285 /* Output nothing for #ident. */
287 #undef ASM_OUTPUT_IDENT
288 #define ASM_OUTPUT_IDENT(FILE, NAME)
290 /* The maximum alignment which the object file format can support.
291 For Mach-O, this is 2^15. */
293 #undef MAX_OFILE_ALIGNMENT
294 #define MAX_OFILE_ALIGNMENT 0x8000
296 /* Create new Mach-O sections. */
298 #undef SECTION_FUNCTION
299 #define SECTION_FUNCTION(FUNCTION, SECTION, DIRECTIVE, OBJC) \
300 extern void FUNCTION PARAMS ((void)); \
304 if (in_section != SECTION) \
307 objc_section_init (); \
310 fprintf (asm_out_file, "%s\n", DIRECTIVE); \
311 in_section = SECTION; \
315 /* Darwin uses many types of special sections. */
317 #undef EXTRA_SECTIONS
318 #define EXTRA_SECTIONS \
319 in_const, in_const_data, in_cstring, in_literal4, in_literal8, \
320 in_constructor, in_destructor, in_mod_init, in_mod_term, \
321 in_objc_class, in_objc_meta_class, in_objc_category, \
322 in_objc_class_vars, in_objc_instance_vars, \
323 in_objc_cls_meth, in_objc_inst_meth, \
324 in_objc_cat_cls_meth, in_objc_cat_inst_meth, \
325 in_objc_selector_refs, \
326 in_objc_selector_fixup, \
327 in_objc_symbols, in_objc_module_info, \
328 in_objc_protocol, in_objc_string_object, \
329 in_objc_constant_string_object, \
330 in_objc_class_names, in_objc_meth_var_names, \
331 in_objc_meth_var_types, in_objc_cls_refs, \
332 in_machopic_nl_symbol_ptr, \
333 in_machopic_lazy_symbol_ptr, \
334 in_machopic_symbol_stub, \
335 in_machopic_picsymbol_stub, \
336 in_darwin_exception, in_darwin_eh_frame, \
339 #undef EXTRA_SECTION_FUNCTIONS
340 #define EXTRA_SECTION_FUNCTIONS \
341 static void objc_section_init PARAMS ((void)); \
342 SECTION_FUNCTION (const_section, \
345 SECTION_FUNCTION (const_data_section, \
348 SECTION_FUNCTION (cstring_section, \
351 SECTION_FUNCTION (literal4_section, \
354 SECTION_FUNCTION (literal8_section, \
357 SECTION_FUNCTION (constructor_section, \
360 SECTION_FUNCTION (mod_init_section, \
362 ".mod_init_func", 0) \
363 SECTION_FUNCTION (mod_term_section, \
365 ".mod_term_func", 0) \
366 SECTION_FUNCTION (destructor_section, \
369 SECTION_FUNCTION (objc_class_section, \
372 SECTION_FUNCTION (objc_meta_class_section, \
373 in_objc_meta_class, \
374 ".objc_meta_class", 1) \
375 SECTION_FUNCTION (objc_category_section, \
377 ".objc_category", 1) \
378 SECTION_FUNCTION (objc_class_vars_section, \
379 in_objc_class_vars, \
380 ".objc_class_vars", 1) \
381 SECTION_FUNCTION (objc_instance_vars_section, \
382 in_objc_instance_vars, \
383 ".objc_instance_vars", 1) \
384 SECTION_FUNCTION (objc_cls_meth_section, \
386 ".objc_cls_meth", 1) \
387 SECTION_FUNCTION (objc_inst_meth_section, \
389 ".objc_inst_meth", 1) \
390 SECTION_FUNCTION (objc_cat_cls_meth_section, \
391 in_objc_cat_cls_meth, \
392 ".objc_cat_cls_meth", 1) \
393 SECTION_FUNCTION (objc_cat_inst_meth_section, \
394 in_objc_cat_inst_meth, \
395 ".objc_cat_inst_meth", 1) \
396 SECTION_FUNCTION (objc_selector_refs_section, \
397 in_objc_selector_refs, \
398 ".objc_message_refs", 1) \
399 SECTION_FUNCTION (objc_selector_fixup_section, \
400 in_objc_selector_fixup, \
401 ".section __OBJC, __sel_fixup", 1) \
402 SECTION_FUNCTION (objc_symbols_section, \
404 ".objc_symbols", 1) \
405 SECTION_FUNCTION (objc_module_info_section, \
406 in_objc_module_info, \
407 ".objc_module_info", 1) \
408 SECTION_FUNCTION (objc_protocol_section, \
410 ".objc_protocol", 1) \
411 SECTION_FUNCTION (objc_string_object_section, \
412 in_objc_string_object, \
413 ".objc_string_object", 1) \
414 SECTION_FUNCTION (objc_constant_string_object_section, \
415 in_objc_constant_string_object, \
416 ".section __OBJC, __cstring_object", 1) \
417 SECTION_FUNCTION (objc_class_names_section, \
418 in_objc_class_names, \
419 ".objc_class_names", 1) \
420 SECTION_FUNCTION (objc_meth_var_names_section, \
421 in_objc_meth_var_names, \
422 ".objc_meth_var_names", 1) \
423 SECTION_FUNCTION (objc_meth_var_types_section, \
424 in_objc_meth_var_types, \
425 ".objc_meth_var_types", 1) \
426 SECTION_FUNCTION (objc_cls_refs_section, \
428 ".objc_cls_refs", 1) \
430 SECTION_FUNCTION (machopic_lazy_symbol_ptr_section, \
431 in_machopic_lazy_symbol_ptr, \
432 ".lazy_symbol_pointer", 0) \
433 SECTION_FUNCTION (machopic_nl_symbol_ptr_section, \
434 in_machopic_nl_symbol_ptr, \
435 ".non_lazy_symbol_pointer", 0) \
436 SECTION_FUNCTION (machopic_symbol_stub_section, \
437 in_machopic_symbol_stub, \
439 SECTION_FUNCTION (machopic_picsymbol_stub_section, \
440 in_machopic_picsymbol_stub, \
441 ".picsymbol_stub", 0) \
442 SECTION_FUNCTION (darwin_exception_section, \
443 in_darwin_exception, \
444 ".section __TEXT,__gcc_except_tab", 0) \
445 SECTION_FUNCTION (darwin_eh_frame_section, \
446 in_darwin_eh_frame, \
447 ".section __TEXT,__eh_frame", 0) \
450 objc_section_init () \
452 static int been_here = 0; \
454 if (been_here == 0) \
457 /* written, cold -> hot */ \
458 objc_cat_cls_meth_section (); \
459 objc_cat_inst_meth_section (); \
460 objc_string_object_section (); \
461 objc_constant_string_object_section (); \
462 objc_selector_refs_section (); \
463 objc_selector_fixup_section (); \
464 objc_cls_refs_section (); \
465 objc_class_section (); \
466 objc_meta_class_section (); \
467 /* shared, hot -> cold */ \
468 objc_cls_meth_section (); \
469 objc_inst_meth_section (); \
470 objc_protocol_section (); \
471 objc_class_names_section (); \
472 objc_meth_var_types_section (); \
473 objc_meth_var_names_section (); \
474 objc_category_section (); \
475 objc_class_vars_section (); \
476 objc_instance_vars_section (); \
477 objc_module_info_section (); \
478 objc_symbols_section (); \
482 #define READONLY_DATA_SECTION const_section
484 #undef TARGET_ASM_SELECT_SECTION
485 #define TARGET_ASM_SELECT_SECTION machopic_select_section
486 #undef TARGET_ASM_SELECT_RTX_SECTION
487 #define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
489 #define ASM_DECLARE_UNRESOLVED_REFERENCE(FILE,NAME) \
493 fprintf (FILE, "\t.lazy_reference "); \
495 fprintf (FILE, "\t.reference "); \
496 assemble_name (FILE, NAME); \
497 fprintf (FILE, "\n"); \
501 #define ASM_DECLARE_CLASS_REFERENCE(FILE,NAME) \
504 fprintf (FILE, "\t"); \
505 assemble_name (FILE, NAME); \
506 fprintf (FILE, "=0\n"); \
507 (*targetm.asm_out.globalize_label) (FILE, NAME); \
511 /* Globalizing directive for a label. */
512 #define GLOBAL_ASM_OP ".globl "
513 #define TARGET_ASM_GLOBALIZE_LABEL darwin_globalize_label
515 #undef ASM_GENERATE_INTERNAL_LABEL
516 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
517 sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM))
519 /* This is how to output an internal numbered label where PREFIX is
520 the class of label and NUM is the number within the class. */
522 #undef ASM_OUTPUT_INTERNAL_LABEL
523 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \
524 fprintf (FILE, "%s%d:\n", PREFIX, NUM)
526 /* Since we have a separate readonly data section, define this so that
527 jump tables end up in text rather than data. */
529 #ifndef JUMP_TABLES_IN_TEXT_SECTION
530 #define JUMP_TABLES_IN_TEXT_SECTION 1
533 /* Symbolic names for various things we might know about a symbol. */
535 enum machopic_addr_class {
537 MACHOPIC_DEFINED_DATA,
538 MACHOPIC_UNDEFINED_DATA,
539 MACHOPIC_DEFINED_FUNCTION,
540 MACHOPIC_UNDEFINED_FUNCTION
543 /* Macros defining the various PIC cases. */
545 #define MACHOPIC_INDIRECT (flag_pic)
546 #define MACHOPIC_JUST_INDIRECT (flag_pic == 1)
547 #define MACHOPIC_PURE (flag_pic == 2)
549 #undef TARGET_ENCODE_SECTION_INFO
550 #define TARGET_ENCODE_SECTION_INFO darwin_encode_section_info
551 #undef TARGET_STRIP_NAME_ENCODING
552 #define TARGET_STRIP_NAME_ENCODING darwin_strip_name_encoding
554 #define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH) \
556 const char *const stub_ = (STUB); \
557 char *buffer_ = (BUF); \
558 strcpy (buffer_, stub_); \
559 if (stub_[0] == '"') \
561 strcpy (buffer_ + (STUB_LENGTH) - 1, "_binder\""); \
565 strcpy (buffer_ + (STUB_LENGTH), "_binder"); \
569 #define GEN_SYMBOL_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH) \
571 const char *const symbol_ = (SYMBOL); \
572 char *buffer_ = (BUF); \
573 if (name_needs_quotes (symbol_) && symbol_[0] != '"') \
575 sprintf (buffer_, "\"%s\"", symbol_); \
579 strcpy (buffer_, symbol_); \
583 /* Given a symbol name string, create the lazy pointer version
584 of the symbol name. */
586 #define GEN_LAZY_PTR_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH) \
588 const char *symbol_ = darwin_strip_name_encoding (SYMBOL); \
589 char *buffer_ = (BUF); \
590 if (symbol_[0] == '"') \
592 strcpy (buffer_, "\"L"); \
593 strcpy (buffer_ + 2, symbol_ + 1); \
594 strcpy (buffer_ + (SYMBOL_LENGTH), "$lazy_ptr\""); \
596 else if (name_needs_quotes (symbol_)) \
598 strcpy (buffer_, "\"L"); \
599 strcpy (buffer_ + 2, symbol_); \
600 strcpy (buffer_ + (SYMBOL_LENGTH) + 2, "$lazy_ptr\""); \
604 strcpy (buffer_, "L"); \
605 strcpy (buffer_ + 1, symbol_); \
606 strcpy (buffer_ + (SYMBOL_LENGTH) + 1, "$lazy_ptr"); \
610 #define TARGET_ASM_EXCEPTION_SECTION darwin_exception_section
612 #define TARGET_ASM_EH_FRAME_SECTION darwin_eh_frame_section
614 #undef ASM_PREFERRED_EH_DATA_FORMAT
615 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \
616 (((CODE) == 1 || (GLOBAL) == 0) ? DW_EH_PE_pcrel : DW_EH_PE_absptr)
618 #define DARWIN_REGISTER_TARGET_PRAGMAS(PFILE) \
620 cpp_register_pragma (PFILE, 0, "mark", darwin_pragma_ignore); \
621 cpp_register_pragma (PFILE, 0, "options", darwin_pragma_options); \
622 cpp_register_pragma (PFILE, 0, "segment", darwin_pragma_ignore); \
623 cpp_register_pragma (PFILE, 0, "unused", darwin_pragma_unused); \
627 #define ASM_APP_ON ""
629 #define ASM_APP_OFF ""