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 /* Allow #sccs (but don't do anything). */
108 #define SCCS_DIRECTIVE
110 /* We use Dbx symbol format. */
112 #define DBX_DEBUGGING_INFO
114 /* Also enable Dwarf 2 as an option. */
116 #define DWARF2_DEBUGGING_INFO
118 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
120 /* When generating stabs debugging, use N_BINCL entries. */
122 #define DBX_USE_BINCL
124 /* There is no limit to the length of stabs strings. */
126 #define DBX_CONTIN_LENGTH 0
128 /* gdb needs a null N_SO at the end of each file for scattered loading. */
130 #undef DBX_OUTPUT_MAIN_SOURCE_FILE_END
131 #define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \
132 do { text_section (); \
134 "\t.stabs \"%s\",%d,0,0,Letext\nLetext:\n", "" , N_SO); \
137 /* Our profiling scheme doesn't LP labels and counter words. */
139 #define NO_PROFILE_COUNTERS
141 #undef INIT_SECTION_ASM_OP
142 #define INIT_SECTION_ASM_OP
146 #define TARGET_ASM_CONSTRUCTOR machopic_asm_out_constructor
147 #define TARGET_ASM_DESTRUCTOR machopic_asm_out_destructor
150 /* Don't output a .file directive. That is only used by the assembler for
153 #undef ASM_FILE_START
154 #define ASM_FILE_START(FILE)
157 #define ASM_FILE_END(FILE) \
159 machopic_finish (asm_out_file); \
160 if (strcmp (lang_hooks.name, "GNU C++") == 0) \
162 constructor_section (); \
163 destructor_section (); \
164 ASM_OUTPUT_ALIGN (FILE, 1); \
168 #undef ASM_OUTPUT_LABEL
169 #define ASM_OUTPUT_LABEL(FILE,NAME) \
170 do { assemble_name (FILE, NAME); fputs (":\n", FILE); } while (0)
172 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
173 fprintf (FILE, "\t.space %d\n", SIZE)
175 /* Give ObjC methods pretty symbol names. */
177 #undef OBJC_GEN_METHOD_LABEL
178 #define OBJC_GEN_METHOD_LABEL(BUF,IS_INST,CLASS_NAME,CAT_NAME,SEL_NAME,NUM) \
180 sprintf (BUF, "%c[%s(%s) %s]", (IS_INST) ? '-' : '+', \
181 (CLASS_NAME), (CAT_NAME), (SEL_NAME)); \
183 sprintf (BUF, "%c[%s %s]", (IS_INST) ? '-' : '+', \
184 (CLASS_NAME), (SEL_NAME)); \
187 /* The RTTI data (e.g., __ti4name) is common and public (and static),
188 but it does need to be referenced via indirect PIC data pointers.
189 The machopic_define_name calls are telling the machopic subsystem
190 that the name *is* defined in this module, so it doesn't need to
191 make them indirect. */
193 #undef ASM_DECLARE_OBJECT_NAME
194 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
196 const char *xname = NAME; \
197 if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF) \
198 xname = IDENTIFIER_POINTER (DECL_NAME (DECL)); \
199 if ((TREE_STATIC (DECL) \
200 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
201 || DECL_INITIAL (DECL)) \
202 machopic_define_name (xname); \
203 if ((TREE_STATIC (DECL) \
204 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
205 || DECL_INITIAL (DECL)) \
206 (* targetm.encode_section_info) (DECL, false); \
207 ASM_OUTPUT_LABEL (FILE, xname); \
210 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
212 const char *xname = NAME; \
213 if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF) \
214 xname = IDENTIFIER_POINTER (DECL_NAME (DECL)); \
215 if ((TREE_STATIC (DECL) \
216 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
217 || DECL_INITIAL (DECL)) \
218 machopic_define_name (xname); \
219 if ((TREE_STATIC (DECL) \
220 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
221 || DECL_INITIAL (DECL)) \
222 (* targetm.encode_section_info) (DECL, false); \
223 ASM_OUTPUT_LABEL (FILE, xname); \
224 /* Avoid generating stubs for functions we've just defined by \
225 outputting any required stub name label now. */ \
226 machopic_output_possible_stub_label (FILE, xname); \
229 /* Wrap new method names in quotes so the assembler doesn't gag.
230 Make Objective-C internal symbols local. */
232 #undef ASM_OUTPUT_LABELREF
233 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
235 const char *xname = darwin_strip_name_encoding (NAME); \
236 if (xname[0] == '&' || xname[0] == '*') \
238 int len = strlen (xname); \
239 if (len > 6 && !strcmp ("$stub", xname + len - 5)) \
240 machopic_validate_stub_or_non_lazy_ptr (xname, 1); \
241 else if (len > 7 && !strcmp ("$stub\"", xname + len - 6)) \
242 machopic_validate_stub_or_non_lazy_ptr (xname, 1); \
243 else if (len > 14 && !strcmp ("$non_lazy_ptr", xname + len - 13)) \
244 machopic_validate_stub_or_non_lazy_ptr (xname, 0); \
245 fputs (&xname[1], FILE); \
247 else if (xname[0] == '+' || xname[0] == '-') \
248 fprintf (FILE, "\"%s\"", xname); \
249 else if (!strncmp (xname, "_OBJC_", 6)) \
250 fprintf (FILE, "L%s", xname); \
251 else if (!strncmp (xname, ".objc_class_name_", 17)) \
252 fprintf (FILE, "%s", xname); \
254 fprintf (FILE, "_%s", xname); \
257 /* Output before executable code. */
258 #undef TEXT_SECTION_ASM_OP
259 #define TEXT_SECTION_ASM_OP ".text"
261 /* Output before writable data. */
263 #undef DATA_SECTION_ASM_OP
264 #define DATA_SECTION_ASM_OP ".data"
267 #define ALIGN_ASM_OP ".align"
269 #undef ASM_OUTPUT_ALIGN
270 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
272 fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG))
274 /* Ensure correct alignment of bss data. */
276 #undef ASM_OUTPUT_ALIGNED_DECL_LOCAL
277 #define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN) \
279 fputs (".lcomm ", (FILE)); \
280 assemble_name ((FILE), (NAME)); \
281 fprintf ((FILE), ",%u,%u\n", (SIZE), \
282 floor_log2 ((ALIGN) / BITS_PER_UNIT)); \
283 if ((DECL) && ((TREE_STATIC (DECL) \
284 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
285 || DECL_INITIAL (DECL))) \
286 (* targetm.encode_section_info) (DECL, false); \
287 if ((DECL) && ((TREE_STATIC (DECL) \
288 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
289 || DECL_INITIAL (DECL))) \
290 machopic_define_name (NAME); \
293 /* Output nothing for #ident. */
295 #undef ASM_OUTPUT_IDENT
296 #define ASM_OUTPUT_IDENT(FILE, NAME)
298 /* The maximum alignment which the object file format can support.
299 For Mach-O, this is 2^15. */
301 #undef MAX_OFILE_ALIGNMENT
302 #define MAX_OFILE_ALIGNMENT 0x8000
304 /* Create new Mach-O sections. */
306 #undef SECTION_FUNCTION
307 #define SECTION_FUNCTION(FUNCTION, SECTION, DIRECTIVE, OBJC) \
308 extern void FUNCTION PARAMS ((void)); \
312 if (in_section != SECTION) \
315 objc_section_init (); \
318 fprintf (asm_out_file, "%s\n", DIRECTIVE); \
319 in_section = SECTION; \
323 /* Darwin uses many types of special sections. */
325 #undef EXTRA_SECTIONS
326 #define EXTRA_SECTIONS \
327 in_const, in_const_data, in_cstring, in_literal4, in_literal8, \
328 in_constructor, in_destructor, in_mod_init, in_mod_term, \
329 in_objc_class, in_objc_meta_class, in_objc_category, \
330 in_objc_class_vars, in_objc_instance_vars, \
331 in_objc_cls_meth, in_objc_inst_meth, \
332 in_objc_cat_cls_meth, in_objc_cat_inst_meth, \
333 in_objc_selector_refs, \
334 in_objc_selector_fixup, \
335 in_objc_symbols, in_objc_module_info, \
336 in_objc_protocol, in_objc_string_object, \
337 in_objc_constant_string_object, \
338 in_objc_class_names, in_objc_meth_var_names, \
339 in_objc_meth_var_types, in_objc_cls_refs, \
340 in_machopic_nl_symbol_ptr, \
341 in_machopic_lazy_symbol_ptr, \
342 in_machopic_symbol_stub, \
343 in_machopic_picsymbol_stub, \
344 in_darwin_exception, in_darwin_eh_frame, \
347 #undef EXTRA_SECTION_FUNCTIONS
348 #define EXTRA_SECTION_FUNCTIONS \
349 static void objc_section_init PARAMS ((void)); \
350 SECTION_FUNCTION (const_section, \
353 SECTION_FUNCTION (const_data_section, \
356 SECTION_FUNCTION (cstring_section, \
359 SECTION_FUNCTION (literal4_section, \
362 SECTION_FUNCTION (literal8_section, \
365 SECTION_FUNCTION (constructor_section, \
368 SECTION_FUNCTION (mod_init_section, \
370 ".mod_init_func", 0) \
371 SECTION_FUNCTION (mod_term_section, \
373 ".mod_term_func", 0) \
374 SECTION_FUNCTION (destructor_section, \
377 SECTION_FUNCTION (objc_class_section, \
380 SECTION_FUNCTION (objc_meta_class_section, \
381 in_objc_meta_class, \
382 ".objc_meta_class", 1) \
383 SECTION_FUNCTION (objc_category_section, \
385 ".objc_category", 1) \
386 SECTION_FUNCTION (objc_class_vars_section, \
387 in_objc_class_vars, \
388 ".objc_class_vars", 1) \
389 SECTION_FUNCTION (objc_instance_vars_section, \
390 in_objc_instance_vars, \
391 ".objc_instance_vars", 1) \
392 SECTION_FUNCTION (objc_cls_meth_section, \
394 ".objc_cls_meth", 1) \
395 SECTION_FUNCTION (objc_inst_meth_section, \
397 ".objc_inst_meth", 1) \
398 SECTION_FUNCTION (objc_cat_cls_meth_section, \
399 in_objc_cat_cls_meth, \
400 ".objc_cat_cls_meth", 1) \
401 SECTION_FUNCTION (objc_cat_inst_meth_section, \
402 in_objc_cat_inst_meth, \
403 ".objc_cat_inst_meth", 1) \
404 SECTION_FUNCTION (objc_selector_refs_section, \
405 in_objc_selector_refs, \
406 ".objc_message_refs", 1) \
407 SECTION_FUNCTION (objc_selector_fixup_section, \
408 in_objc_selector_fixup, \
409 ".section __OBJC, __sel_fixup", 1) \
410 SECTION_FUNCTION (objc_symbols_section, \
412 ".objc_symbols", 1) \
413 SECTION_FUNCTION (objc_module_info_section, \
414 in_objc_module_info, \
415 ".objc_module_info", 1) \
416 SECTION_FUNCTION (objc_protocol_section, \
418 ".objc_protocol", 1) \
419 SECTION_FUNCTION (objc_string_object_section, \
420 in_objc_string_object, \
421 ".objc_string_object", 1) \
422 SECTION_FUNCTION (objc_constant_string_object_section, \
423 in_objc_constant_string_object, \
424 ".section __OBJC, __cstring_object", 1) \
425 SECTION_FUNCTION (objc_class_names_section, \
426 in_objc_class_names, \
427 ".objc_class_names", 1) \
428 SECTION_FUNCTION (objc_meth_var_names_section, \
429 in_objc_meth_var_names, \
430 ".objc_meth_var_names", 1) \
431 SECTION_FUNCTION (objc_meth_var_types_section, \
432 in_objc_meth_var_types, \
433 ".objc_meth_var_types", 1) \
434 SECTION_FUNCTION (objc_cls_refs_section, \
436 ".objc_cls_refs", 1) \
438 SECTION_FUNCTION (machopic_lazy_symbol_ptr_section, \
439 in_machopic_lazy_symbol_ptr, \
440 ".lazy_symbol_pointer", 0) \
441 SECTION_FUNCTION (machopic_nl_symbol_ptr_section, \
442 in_machopic_nl_symbol_ptr, \
443 ".non_lazy_symbol_pointer", 0) \
444 SECTION_FUNCTION (machopic_symbol_stub_section, \
445 in_machopic_symbol_stub, \
447 SECTION_FUNCTION (machopic_picsymbol_stub_section, \
448 in_machopic_picsymbol_stub, \
449 ".picsymbol_stub", 0) \
450 SECTION_FUNCTION (darwin_exception_section, \
451 in_darwin_exception, \
452 ".section __TEXT,__gcc_except_tab", 0) \
453 SECTION_FUNCTION (darwin_eh_frame_section, \
454 in_darwin_eh_frame, \
455 ".section __TEXT,__eh_frame", 0) \
458 objc_section_init () \
460 static int been_here = 0; \
462 if (been_here == 0) \
465 /* written, cold -> hot */ \
466 objc_cat_cls_meth_section (); \
467 objc_cat_inst_meth_section (); \
468 objc_string_object_section (); \
469 objc_constant_string_object_section (); \
470 objc_selector_refs_section (); \
471 objc_selector_fixup_section (); \
472 objc_cls_refs_section (); \
473 objc_class_section (); \
474 objc_meta_class_section (); \
475 /* shared, hot -> cold */ \
476 objc_cls_meth_section (); \
477 objc_inst_meth_section (); \
478 objc_protocol_section (); \
479 objc_class_names_section (); \
480 objc_meth_var_types_section (); \
481 objc_meth_var_names_section (); \
482 objc_category_section (); \
483 objc_class_vars_section (); \
484 objc_instance_vars_section (); \
485 objc_module_info_section (); \
486 objc_symbols_section (); \
490 #define READONLY_DATA_SECTION const_section
492 #undef TARGET_ASM_SELECT_SECTION
493 #define TARGET_ASM_SELECT_SECTION machopic_select_section
494 #undef TARGET_ASM_SELECT_RTX_SECTION
495 #define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
497 #define ASM_DECLARE_UNRESOLVED_REFERENCE(FILE,NAME) \
501 fprintf (FILE, "\t.lazy_reference "); \
503 fprintf (FILE, "\t.reference "); \
504 assemble_name (FILE, NAME); \
505 fprintf (FILE, "\n"); \
509 #define ASM_DECLARE_CLASS_REFERENCE(FILE,NAME) \
512 fprintf (FILE, "\t"); \
513 assemble_name (FILE, NAME); \
514 fprintf (FILE, "=0\n"); \
515 assemble_global (NAME); \
519 #undef ASM_GLOBALIZE_LABEL
520 #define ASM_GLOBALIZE_LABEL(FILE,NAME) \
521 do { const char *const _x = (NAME); if (!!strncmp (_x, "_OBJC_", 6)) { \
522 (fputs (".globl ", FILE), assemble_name (FILE, _x), fputs ("\n", FILE)); \
525 #undef ASM_GENERATE_INTERNAL_LABEL
526 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
527 sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM))
529 /* This is how to output an internal numbered label where PREFIX is
530 the class of label and NUM is the number within the class. */
532 #undef ASM_OUTPUT_INTERNAL_LABEL
533 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \
534 fprintf (FILE, "%s%d:\n", PREFIX, NUM)
536 /* Since we have a separate readonly data section, define this so that
537 jump tables end up in text rather than data. */
539 #ifndef JUMP_TABLES_IN_TEXT_SECTION
540 #define JUMP_TABLES_IN_TEXT_SECTION 1
543 /* Symbolic names for various things we might know about a symbol. */
545 enum machopic_addr_class {
547 MACHOPIC_DEFINED_DATA,
548 MACHOPIC_UNDEFINED_DATA,
549 MACHOPIC_DEFINED_FUNCTION,
550 MACHOPIC_UNDEFINED_FUNCTION
553 /* Macros defining the various PIC cases. */
555 #define MACHOPIC_INDIRECT (flag_pic)
556 #define MACHOPIC_JUST_INDIRECT (flag_pic == 1)
557 #define MACHOPIC_PURE (flag_pic == 2)
559 #define TARGET_ENCODE_SECTION_INFO darwin_encode_section_info
560 #define TARGET_STRIP_NAME_ENCODING darwin_strip_name_encoding
562 #define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH) \
564 const char *const stub_ = (STUB); \
565 char *buffer_ = (BUF); \
566 strcpy (buffer_, stub_); \
567 if (stub_[0] == '"') \
569 strcpy (buffer_ + (STUB_LENGTH) - 1, "_binder\""); \
573 strcpy (buffer_ + (STUB_LENGTH), "_binder"); \
577 #define GEN_SYMBOL_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH) \
579 const char *const symbol_ = (SYMBOL); \
580 char *buffer_ = (BUF); \
581 if (name_needs_quotes (symbol_) && symbol_[0] != '"') \
583 sprintf (buffer_, "\"%s\"", symbol_); \
587 strcpy (buffer_, symbol_); \
591 /* Given a symbol name string, create the lazy pointer version
592 of the symbol name. */
594 #define GEN_LAZY_PTR_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH) \
596 const char *symbol_ = darwin_strip_name_encoding (SYMBOL); \
597 char *buffer_ = (BUF); \
598 if (symbol_[0] == '"') \
600 strcpy (buffer_, "\"L"); \
601 strcpy (buffer_ + 2, symbol_ + 1); \
602 strcpy (buffer_ + (SYMBOL_LENGTH), "$lazy_ptr\""); \
604 else if (name_needs_quotes (symbol_)) \
606 strcpy (buffer_, "\"L"); \
607 strcpy (buffer_ + 2, symbol_); \
608 strcpy (buffer_ + (SYMBOL_LENGTH) + 2, "$lazy_ptr\""); \
612 strcpy (buffer_, "L"); \
613 strcpy (buffer_ + 1, symbol_); \
614 strcpy (buffer_ + (SYMBOL_LENGTH) + 1, "$lazy_ptr"); \
618 #define TARGET_ASM_EXCEPTION_SECTION darwin_exception_section
620 #define TARGET_ASM_EH_FRAME_SECTION darwin_eh_frame_section
622 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \
623 (((CODE) == 1 || (GLOBAL) == 0) ? DW_EH_PE_pcrel : DW_EH_PE_absptr)
625 #define DARWIN_REGISTER_TARGET_PRAGMAS(PFILE) \
627 cpp_register_pragma (PFILE, 0, "mark", darwin_pragma_ignore); \
628 cpp_register_pragma (PFILE, 0, "options", darwin_pragma_options); \
629 cpp_register_pragma (PFILE, 0, "segment", darwin_pragma_ignore); \
630 cpp_register_pragma (PFILE, 0, "unused", darwin_pragma_unused); \
634 #define ASM_APP_ON ""
636 #define ASM_APP_OFF ""