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 /* Machine dependent cpp options. */
84 #define CPP_SPEC "%{static:-D__STATIC__}%{!static:-D__DYNAMIC__}"
86 /* Machine dependent libraries. */
89 #define LIB_SPEC "%{!static:-lSystem}"
91 /* We specify crt0.o as -lcrt0.o so that ld will search the library path. */
94 #define STARTFILE_SPEC \
95 "%{pg:%{static:-lgcrt0.o}%{!static:-lgcrt1.o}} \
96 %{!pg:%{static:-lcrt0.o}%{!static:-lcrt1.o}}"
98 #undef DOLLARS_IN_IDENTIFIERS
99 #define DOLLARS_IN_IDENTIFIERS 2
101 /* We use Dbx symbol format. */
103 #define DBX_DEBUGGING_INFO 1
105 /* When generating stabs debugging, use N_BINCL entries. */
107 #define DBX_USE_BINCL
109 /* There is no limit to the length of stabs strings. */
111 #define DBX_CONTIN_LENGTH 0
113 /* gdb needs a null N_SO at the end of each file for scattered loading. */
115 #undef DBX_OUTPUT_MAIN_SOURCE_FILE_END
116 #define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \
117 do { text_section (); \
119 "\t.stabs \"%s\",%d,0,0,Letext\nLetext:\n", "" , N_SO); \
122 /* Our profiling scheme doesn't LP labels and counter words. */
124 #define NO_PROFILE_COUNTERS
126 #undef INIT_SECTION_ASM_OP
127 #define INIT_SECTION_ASM_OP
131 #define TARGET_ASM_CONSTRUCTOR machopic_asm_out_constructor
132 #define TARGET_ASM_DESTRUCTOR machopic_asm_out_destructor
135 /* Don't output a .file directive. That is only used by the assembler for
138 #undef ASM_FILE_START
139 #define ASM_FILE_START(FILE)
142 #define ASM_FILE_END(FILE) \
144 machopic_finish (asm_out_file); \
145 if (strcmp (lang_hooks.name, "GNU C++") == 0) \
147 constructor_section (); \
148 destructor_section (); \
149 ASM_OUTPUT_ALIGN (FILE, 1); \
153 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
154 fprintf (FILE, "\t.space %d\n", SIZE)
156 /* Give ObjC methods pretty symbol names. */
158 #undef OBJC_GEN_METHOD_LABEL
159 #define OBJC_GEN_METHOD_LABEL(BUF,IS_INST,CLASS_NAME,CAT_NAME,SEL_NAME,NUM) \
161 sprintf (BUF, "%c[%s(%s) %s]", (IS_INST) ? '-' : '+', \
162 (CLASS_NAME), (CAT_NAME), (SEL_NAME)); \
164 sprintf (BUF, "%c[%s %s]", (IS_INST) ? '-' : '+', \
165 (CLASS_NAME), (SEL_NAME)); \
168 /* The RTTI data (e.g., __ti4name) is common and public (and static),
169 but it does need to be referenced via indirect PIC data pointers.
170 The machopic_define_name calls are telling the machopic subsystem
171 that the name *is* defined in this module, so it doesn't need to
172 make them indirect. */
174 #undef ASM_DECLARE_OBJECT_NAME
175 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
177 const char *xname = NAME; \
178 if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF) \
179 xname = IDENTIFIER_POINTER (DECL_NAME (DECL)); \
180 if ((TREE_STATIC (DECL) \
181 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
182 || DECL_INITIAL (DECL)) \
183 machopic_define_name (xname); \
184 if ((TREE_STATIC (DECL) \
185 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
186 || DECL_INITIAL (DECL)) \
187 (* targetm.encode_section_info) (DECL, false); \
188 ASM_OUTPUT_LABEL (FILE, xname); \
191 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
193 const char *xname = NAME; \
194 if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF) \
195 xname = IDENTIFIER_POINTER (DECL_NAME (DECL)); \
196 if ((TREE_STATIC (DECL) \
197 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
198 || DECL_INITIAL (DECL)) \
199 machopic_define_name (xname); \
200 if ((TREE_STATIC (DECL) \
201 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
202 || DECL_INITIAL (DECL)) \
203 (* targetm.encode_section_info) (DECL, false); \
204 ASM_OUTPUT_LABEL (FILE, xname); \
205 /* Avoid generating stubs for functions we've just defined by \
206 outputting any required stub name label now. */ \
207 machopic_output_possible_stub_label (FILE, xname); \
210 /* Wrap new method names in quotes so the assembler doesn't gag.
211 Make Objective-C internal symbols local. */
213 #undef ASM_OUTPUT_LABELREF
214 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
216 const char *xname = darwin_strip_name_encoding (NAME); \
217 if (xname[0] == '&' || xname[0] == '*') \
219 int len = strlen (xname); \
220 if (len > 6 && !strcmp ("$stub", xname + len - 5)) \
221 machopic_validate_stub_or_non_lazy_ptr (xname, 1); \
222 else if (len > 7 && !strcmp ("$stub\"", xname + len - 6)) \
223 machopic_validate_stub_or_non_lazy_ptr (xname, 1); \
224 else if (len > 14 && !strcmp ("$non_lazy_ptr", xname + len - 13)) \
225 machopic_validate_stub_or_non_lazy_ptr (xname, 0); \
226 fputs (&xname[1], FILE); \
228 else if (xname[0] == '+' || xname[0] == '-') \
229 fprintf (FILE, "\"%s\"", xname); \
230 else if (!strncmp (xname, "_OBJC_", 6)) \
231 fprintf (FILE, "L%s", xname); \
232 else if (!strncmp (xname, ".objc_class_name_", 17)) \
233 fprintf (FILE, "%s", xname); \
235 fprintf (FILE, "_%s", xname); \
238 /* Output before executable code. */
239 #undef TEXT_SECTION_ASM_OP
240 #define TEXT_SECTION_ASM_OP ".text"
242 /* Output before writable data. */
244 #undef DATA_SECTION_ASM_OP
245 #define DATA_SECTION_ASM_OP ".data"
248 #define ALIGN_ASM_OP ".align"
250 #undef ASM_OUTPUT_ALIGN
251 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
253 fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG))
255 /* Ensure correct alignment of bss data. */
257 #undef ASM_OUTPUT_ALIGNED_DECL_LOCAL
258 #define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN) \
260 fputs (".lcomm ", (FILE)); \
261 assemble_name ((FILE), (NAME)); \
262 fprintf ((FILE), ",%u,%u\n", (SIZE), \
263 floor_log2 ((ALIGN) / BITS_PER_UNIT)); \
264 if ((DECL) && ((TREE_STATIC (DECL) \
265 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
266 || DECL_INITIAL (DECL))) \
267 (* targetm.encode_section_info) (DECL, false); \
268 if ((DECL) && ((TREE_STATIC (DECL) \
269 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
270 || DECL_INITIAL (DECL))) \
271 machopic_define_name (NAME); \
274 /* The maximum alignment which the object file format can support.
275 For Mach-O, this is 2^15. */
277 #undef MAX_OFILE_ALIGNMENT
278 #define MAX_OFILE_ALIGNMENT 0x8000
280 /* Create new Mach-O sections. */
282 #undef SECTION_FUNCTION
283 #define SECTION_FUNCTION(FUNCTION, SECTION, DIRECTIVE, OBJC) \
284 extern void FUNCTION PARAMS ((void)); \
288 if (in_section != SECTION) \
291 objc_section_init (); \
294 fprintf (asm_out_file, "%s\n", DIRECTIVE); \
295 in_section = SECTION; \
299 /* Darwin uses many types of special sections. */
301 #undef EXTRA_SECTIONS
302 #define EXTRA_SECTIONS \
303 in_const, in_const_data, in_cstring, in_literal4, in_literal8, \
304 in_constructor, in_destructor, in_mod_init, in_mod_term, \
305 in_objc_class, in_objc_meta_class, in_objc_category, \
306 in_objc_class_vars, in_objc_instance_vars, \
307 in_objc_cls_meth, in_objc_inst_meth, \
308 in_objc_cat_cls_meth, in_objc_cat_inst_meth, \
309 in_objc_selector_refs, \
310 in_objc_selector_fixup, \
311 in_objc_symbols, in_objc_module_info, \
312 in_objc_protocol, in_objc_string_object, \
313 in_objc_constant_string_object, \
314 in_objc_class_names, in_objc_meth_var_names, \
315 in_objc_meth_var_types, in_objc_cls_refs, \
316 in_machopic_nl_symbol_ptr, \
317 in_machopic_lazy_symbol_ptr, \
318 in_machopic_symbol_stub, \
319 in_machopic_picsymbol_stub, \
320 in_darwin_exception, in_darwin_eh_frame, \
323 #undef EXTRA_SECTION_FUNCTIONS
324 #define EXTRA_SECTION_FUNCTIONS \
325 static void objc_section_init PARAMS ((void)); \
326 SECTION_FUNCTION (const_section, \
329 SECTION_FUNCTION (const_data_section, \
332 SECTION_FUNCTION (cstring_section, \
335 SECTION_FUNCTION (literal4_section, \
338 SECTION_FUNCTION (literal8_section, \
341 SECTION_FUNCTION (constructor_section, \
344 SECTION_FUNCTION (mod_init_section, \
346 ".mod_init_func", 0) \
347 SECTION_FUNCTION (mod_term_section, \
349 ".mod_term_func", 0) \
350 SECTION_FUNCTION (destructor_section, \
353 SECTION_FUNCTION (objc_class_section, \
356 SECTION_FUNCTION (objc_meta_class_section, \
357 in_objc_meta_class, \
358 ".objc_meta_class", 1) \
359 SECTION_FUNCTION (objc_category_section, \
361 ".objc_category", 1) \
362 SECTION_FUNCTION (objc_class_vars_section, \
363 in_objc_class_vars, \
364 ".objc_class_vars", 1) \
365 SECTION_FUNCTION (objc_instance_vars_section, \
366 in_objc_instance_vars, \
367 ".objc_instance_vars", 1) \
368 SECTION_FUNCTION (objc_cls_meth_section, \
370 ".objc_cls_meth", 1) \
371 SECTION_FUNCTION (objc_inst_meth_section, \
373 ".objc_inst_meth", 1) \
374 SECTION_FUNCTION (objc_cat_cls_meth_section, \
375 in_objc_cat_cls_meth, \
376 ".objc_cat_cls_meth", 1) \
377 SECTION_FUNCTION (objc_cat_inst_meth_section, \
378 in_objc_cat_inst_meth, \
379 ".objc_cat_inst_meth", 1) \
380 SECTION_FUNCTION (objc_selector_refs_section, \
381 in_objc_selector_refs, \
382 ".objc_message_refs", 1) \
383 SECTION_FUNCTION (objc_selector_fixup_section, \
384 in_objc_selector_fixup, \
385 ".section __OBJC, __sel_fixup", 1) \
386 SECTION_FUNCTION (objc_symbols_section, \
388 ".objc_symbols", 1) \
389 SECTION_FUNCTION (objc_module_info_section, \
390 in_objc_module_info, \
391 ".objc_module_info", 1) \
392 SECTION_FUNCTION (objc_protocol_section, \
394 ".objc_protocol", 1) \
395 SECTION_FUNCTION (objc_string_object_section, \
396 in_objc_string_object, \
397 ".objc_string_object", 1) \
398 SECTION_FUNCTION (objc_constant_string_object_section, \
399 in_objc_constant_string_object, \
400 ".section __OBJC, __cstring_object", 1) \
401 SECTION_FUNCTION (objc_class_names_section, \
402 in_objc_class_names, \
403 ".objc_class_names", 1) \
404 SECTION_FUNCTION (objc_meth_var_names_section, \
405 in_objc_meth_var_names, \
406 ".objc_meth_var_names", 1) \
407 SECTION_FUNCTION (objc_meth_var_types_section, \
408 in_objc_meth_var_types, \
409 ".objc_meth_var_types", 1) \
410 SECTION_FUNCTION (objc_cls_refs_section, \
412 ".objc_cls_refs", 1) \
414 SECTION_FUNCTION (machopic_lazy_symbol_ptr_section, \
415 in_machopic_lazy_symbol_ptr, \
416 ".lazy_symbol_pointer", 0) \
417 SECTION_FUNCTION (machopic_nl_symbol_ptr_section, \
418 in_machopic_nl_symbol_ptr, \
419 ".non_lazy_symbol_pointer", 0) \
420 SECTION_FUNCTION (machopic_symbol_stub_section, \
421 in_machopic_symbol_stub, \
423 SECTION_FUNCTION (machopic_picsymbol_stub_section, \
424 in_machopic_picsymbol_stub, \
425 ".picsymbol_stub", 0) \
426 SECTION_FUNCTION (darwin_exception_section, \
427 in_darwin_exception, \
428 ".section __TEXT,__gcc_except_tab", 0) \
429 SECTION_FUNCTION (darwin_eh_frame_section, \
430 in_darwin_eh_frame, \
431 ".section __TEXT,__eh_frame", 0) \
434 objc_section_init () \
436 static int been_here = 0; \
438 if (been_here == 0) \
441 /* written, cold -> hot */ \
442 objc_cat_cls_meth_section (); \
443 objc_cat_inst_meth_section (); \
444 objc_string_object_section (); \
445 objc_constant_string_object_section (); \
446 objc_selector_refs_section (); \
447 objc_selector_fixup_section (); \
448 objc_cls_refs_section (); \
449 objc_class_section (); \
450 objc_meta_class_section (); \
451 /* shared, hot -> cold */ \
452 objc_cls_meth_section (); \
453 objc_inst_meth_section (); \
454 objc_protocol_section (); \
455 objc_class_names_section (); \
456 objc_meth_var_types_section (); \
457 objc_meth_var_names_section (); \
458 objc_category_section (); \
459 objc_class_vars_section (); \
460 objc_instance_vars_section (); \
461 objc_module_info_section (); \
462 objc_symbols_section (); \
466 #define READONLY_DATA_SECTION const_section
468 #undef TARGET_ASM_SELECT_SECTION
469 #define TARGET_ASM_SELECT_SECTION machopic_select_section
470 #undef TARGET_ASM_SELECT_RTX_SECTION
471 #define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
473 #define ASM_DECLARE_UNRESOLVED_REFERENCE(FILE,NAME) \
477 fprintf (FILE, "\t.lazy_reference "); \
479 fprintf (FILE, "\t.reference "); \
480 assemble_name (FILE, NAME); \
481 fprintf (FILE, "\n"); \
485 #define ASM_DECLARE_CLASS_REFERENCE(FILE,NAME) \
488 fprintf (FILE, "\t"); \
489 assemble_name (FILE, NAME); \
490 fprintf (FILE, "=0\n"); \
491 (*targetm.asm_out.globalize_label) (FILE, NAME); \
495 /* Globalizing directive for a label. */
496 #define GLOBAL_ASM_OP ".globl "
497 #define TARGET_ASM_GLOBALIZE_LABEL darwin_globalize_label
499 #undef ASM_GENERATE_INTERNAL_LABEL
500 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
501 sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM))
503 /* This is how to output an internal numbered label where PREFIX is
504 the class of label and NUM is the number within the class. */
506 #undef ASM_OUTPUT_INTERNAL_LABEL
507 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \
508 fprintf (FILE, "%s%d:\n", PREFIX, NUM)
510 /* Since we have a separate readonly data section, define this so that
511 jump tables end up in text rather than data. */
513 #ifndef JUMP_TABLES_IN_TEXT_SECTION
514 #define JUMP_TABLES_IN_TEXT_SECTION 1
517 /* Symbolic names for various things we might know about a symbol. */
519 enum machopic_addr_class {
521 MACHOPIC_DEFINED_DATA,
522 MACHOPIC_UNDEFINED_DATA,
523 MACHOPIC_DEFINED_FUNCTION,
524 MACHOPIC_UNDEFINED_FUNCTION
527 /* Macros defining the various PIC cases. */
529 #define MACHOPIC_INDIRECT (flag_pic)
530 #define MACHOPIC_JUST_INDIRECT (flag_pic == 1)
531 #define MACHOPIC_PURE (flag_pic == 2)
533 #undef TARGET_ENCODE_SECTION_INFO
534 #define TARGET_ENCODE_SECTION_INFO darwin_encode_section_info
535 #undef TARGET_STRIP_NAME_ENCODING
536 #define TARGET_STRIP_NAME_ENCODING darwin_strip_name_encoding
538 #define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH) \
540 const char *const stub_ = (STUB); \
541 char *buffer_ = (BUF); \
542 strcpy (buffer_, stub_); \
543 if (stub_[0] == '"') \
545 strcpy (buffer_ + (STUB_LENGTH) - 1, "_binder\""); \
549 strcpy (buffer_ + (STUB_LENGTH), "_binder"); \
553 #define GEN_SYMBOL_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH) \
555 const char *const symbol_ = (SYMBOL); \
556 char *buffer_ = (BUF); \
557 if (name_needs_quotes (symbol_) && symbol_[0] != '"') \
559 sprintf (buffer_, "\"%s\"", symbol_); \
563 strcpy (buffer_, symbol_); \
567 /* Given a symbol name string, create the lazy pointer version
568 of the symbol name. */
570 #define GEN_LAZY_PTR_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH) \
572 const char *symbol_ = darwin_strip_name_encoding (SYMBOL); \
573 char *buffer_ = (BUF); \
574 if (symbol_[0] == '"') \
576 strcpy (buffer_, "\"L"); \
577 strcpy (buffer_ + 2, symbol_ + 1); \
578 strcpy (buffer_ + (SYMBOL_LENGTH), "$lazy_ptr\""); \
580 else if (name_needs_quotes (symbol_)) \
582 strcpy (buffer_, "\"L"); \
583 strcpy (buffer_ + 2, symbol_); \
584 strcpy (buffer_ + (SYMBOL_LENGTH) + 2, "$lazy_ptr\""); \
588 strcpy (buffer_, "L"); \
589 strcpy (buffer_ + 1, symbol_); \
590 strcpy (buffer_ + (SYMBOL_LENGTH) + 1, "$lazy_ptr"); \
594 #define TARGET_ASM_EXCEPTION_SECTION darwin_exception_section
596 #define TARGET_ASM_EH_FRAME_SECTION darwin_eh_frame_section
598 #undef ASM_PREFERRED_EH_DATA_FORMAT
599 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \
600 (((CODE) == 1 || (GLOBAL) == 0) ? DW_EH_PE_pcrel : DW_EH_PE_absptr)
602 #define DARWIN_REGISTER_TARGET_PRAGMAS(PFILE) \
604 cpp_register_pragma (PFILE, 0, "mark", darwin_pragma_ignore); \
605 cpp_register_pragma (PFILE, 0, "options", darwin_pragma_options); \
606 cpp_register_pragma (PFILE, 0, "segment", darwin_pragma_ignore); \
607 cpp_register_pragma (PFILE, 0, "unused", darwin_pragma_unused); \
611 #define ASM_APP_ON ""
613 #define ASM_APP_OFF ""