Mercurial > hg > CbC > CbC_gcc
comparison gcc/config/darwin.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
65:65488c3d617d | 67:f6334be47118 |
---|---|
1 /* Functions for generic Darwin as target machine for GNU C compiler. | 1 /* Functions for generic Darwin as target machine for GNU C compiler. |
2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 2000, 2001, 2002, 2003, 2004, | 2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 2000, 2001, 2002, 2003, 2004, |
3 2005, 2006, 2007, 2008, 2009, 2010 | 3 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
4 Free Software Foundation, Inc. | 4 Free Software Foundation, Inc. |
5 Contributed by Apple Computer Inc. | 5 Contributed by Apple Computer Inc. |
6 | 6 |
7 This file is part of GCC. | 7 This file is part of GCC. |
8 | 8 |
39 #include "function.h" | 39 #include "function.h" |
40 #include "ggc.h" | 40 #include "ggc.h" |
41 #include "langhooks.h" | 41 #include "langhooks.h" |
42 #include "target.h" | 42 #include "target.h" |
43 #include "tm_p.h" | 43 #include "tm_p.h" |
44 #include "diagnostic-core.h" | |
44 #include "toplev.h" | 45 #include "toplev.h" |
45 #include "hashtab.h" | 46 #include "hashtab.h" |
46 #include "df.h" | 47 #include "df.h" |
47 #include "debug.h" | 48 #include "debug.h" |
48 #include "obstack.h" | 49 #include "obstack.h" |
76 structure to symbol. See indirect_data for the code that handles | 77 structure to symbol. See indirect_data for the code that handles |
77 the extra indirection, and machopic_output_indirection and its use | 78 the extra indirection, and machopic_output_indirection and its use |
78 of MACHO_SYMBOL_STATIC for the code that handles @code{static} | 79 of MACHO_SYMBOL_STATIC for the code that handles @code{static} |
79 symbol indirection. */ | 80 symbol indirection. */ |
80 | 81 |
82 /* For darwin >= 9 (OSX 10.5) the linker is capable of making the necessary | |
83 branch islands and we no longer need to emit darwin stubs. | |
84 However, if we are generating code for earlier systems (or for use in the | |
85 kernel) the stubs might still be required, and this will be set true. */ | |
86 int darwin_emit_branch_islands = false; | |
87 | |
88 /* A flag to determine whether we are running c++ or obj-c++. This has to be | |
89 settable from non-c-family contexts too (i.e. we can't use the c_dialect_ | |
90 functions). */ | |
91 int darwin_running_cxx; | |
92 | |
93 /* Some code-gen now depends on OS major version numbers (at least). */ | |
94 int generating_for_darwin_version ; | |
95 | |
81 /* Section names. */ | 96 /* Section names. */ |
82 section * darwin_sections[NUM_DARWIN_SECTIONS]; | 97 section * darwin_sections[NUM_DARWIN_SECTIONS]; |
83 | 98 |
99 /* While we transition to using in-tests instead of ifdef'd code. */ | |
100 #ifndef HAVE_lo_sum | |
101 #define HAVE_lo_sum 0 | |
102 #define gen_macho_high(a,b) (a) | |
103 #define gen_macho_low(a,b,c) (a) | |
104 #endif | |
105 | |
84 /* True if we're setting __attribute__ ((ms_struct)). */ | 106 /* True if we're setting __attribute__ ((ms_struct)). */ |
85 int darwin_ms_struct = false; | 107 int darwin_ms_struct = false; |
86 | 108 |
109 /* Earlier versions of Darwin as do not recognize an alignment field in | |
110 .comm directives, this should be set for versions that allow it. */ | |
111 int emit_aligned_common = false; | |
112 | |
87 /* A get_unnamed_section callback used to switch to an ObjC section. | 113 /* A get_unnamed_section callback used to switch to an ObjC section. |
88 DIRECTIVE is as for output_section_asm_op. */ | 114 DIRECTIVE is as for output_section_asm_op. */ |
89 | 115 |
90 static void | 116 static void |
91 output_objc_section_asm_op (const void *directive) | 117 output_objc_section_asm_op (const void *directive) |
92 { | 118 { |
93 static bool been_here = false; | 119 static bool been_here = false; |
94 | 120 |
121 /* The NeXT ObjC Runtime requires these sections to be present and in | |
122 order in the object. The code below implements this by emitting | |
123 a section header for each ObjC section the first time that an ObjC | |
124 section is requested. */ | |
95 if (! been_here) | 125 if (! been_here) |
96 { | 126 { |
127 section *saved_in_section = in_section; | |
97 static const enum darwin_section_enum tomark[] = | 128 static const enum darwin_section_enum tomark[] = |
98 { | 129 { |
99 /* written, cold -> hot */ | 130 /* written, cold -> hot */ |
100 objc_cat_cls_meth_section, | 131 objc_cat_cls_meth_section, |
101 objc_cat_inst_meth_section, | 132 objc_cat_inst_meth_section, |
115 objc_meth_var_names_section, | 146 objc_meth_var_names_section, |
116 objc_category_section, | 147 objc_category_section, |
117 objc_class_vars_section, | 148 objc_class_vars_section, |
118 objc_instance_vars_section, | 149 objc_instance_vars_section, |
119 objc_module_info_section, | 150 objc_module_info_section, |
120 objc_symbols_section | 151 objc_symbols_section, |
121 }; | 152 }; |
153 /* ABI=1 */ | |
154 static const enum darwin_section_enum tomarkv1[] = | |
155 { | |
156 objc1_protocol_ext_section, | |
157 objc1_class_ext_section, | |
158 objc1_prop_list_section | |
159 } ; | |
160 /* ABI=2 */ | |
161 static const enum darwin_section_enum tomarkv2[] = | |
162 { | |
163 objc2_message_refs_section, | |
164 objc2_classdefs_section, | |
165 objc2_metadata_section, | |
166 objc2_classrefs_section, | |
167 objc2_classlist_section, | |
168 objc2_categorylist_section, | |
169 objc2_selector_refs_section, | |
170 objc2_nonlazy_class_section, | |
171 objc2_nonlazy_category_section, | |
172 objc2_protocollist_section, | |
173 objc2_protocolrefs_section, | |
174 objc2_super_classrefs_section, | |
175 objc2_image_info_section, | |
176 objc2_constant_string_object_section | |
177 } ; | |
122 size_t i; | 178 size_t i; |
123 | 179 |
124 been_here = true; | 180 been_here = true; |
125 for (i = 0; i < ARRAY_SIZE (tomark); i++) | 181 if (flag_objc_abi < 2) |
126 switch_to_section (darwin_sections[tomark[i]]); | 182 { |
183 for (i = 0; i < ARRAY_SIZE (tomark); i++) | |
184 switch_to_section (darwin_sections[tomark[i]]); | |
185 if (flag_objc_abi == 1) | |
186 for (i = 0; i < ARRAY_SIZE (tomarkv1); i++) | |
187 switch_to_section (darwin_sections[tomarkv1[i]]); | |
188 } | |
189 else | |
190 for (i = 0; i < ARRAY_SIZE (tomarkv2); i++) | |
191 switch_to_section (darwin_sections[tomarkv2[i]]); | |
192 /* Make sure we don't get varasm.c out of sync with us. */ | |
193 switch_to_section (saved_in_section); | |
127 } | 194 } |
128 output_section_asm_op (directive); | 195 output_section_asm_op (directive); |
129 } | 196 } |
197 | |
198 | |
199 /* Private flag applied to disable section-anchors in a particular section. */ | |
200 #define SECTION_NO_ANCHOR SECTION_MACH_DEP | |
201 | |
130 | 202 |
131 /* Implement TARGET_ASM_INIT_SECTIONS. */ | 203 /* Implement TARGET_ASM_INIT_SECTIONS. */ |
132 | 204 |
133 void | 205 void |
134 darwin_init_sections (void) | 206 darwin_init_sections (void) |
150 int | 222 int |
151 name_needs_quotes (const char *name) | 223 name_needs_quotes (const char *name) |
152 { | 224 { |
153 int c; | 225 int c; |
154 while ((c = *name++) != '\0') | 226 while ((c = *name++) != '\0') |
155 if (! ISIDNUM (c) && c != '.' && c != '$') | 227 if (! ISIDNUM (c) |
228 && c != '.' && c != '$' && c != '_' ) | |
156 return 1; | 229 return 1; |
157 return 0; | 230 return 0; |
158 } | 231 } |
159 | 232 |
160 /* Return true if SYM_REF can be used without an indirection. */ | 233 /* Return true if SYM_REF can be used without an indirection. */ |
161 static int | 234 int |
162 machopic_symbol_defined_p (rtx sym_ref) | 235 machopic_symbol_defined_p (rtx sym_ref) |
163 { | 236 { |
164 if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_DEFINED) | 237 if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_DEFINED) |
165 return true; | 238 return true; |
166 | 239 |
237 || (strncmp (name, "_OBJC_", 6) == 0)); | 310 || (strncmp (name, "_OBJC_", 6) == 0)); |
238 | 311 |
239 return ! lprefix; | 312 return ! lprefix; |
240 } | 313 } |
241 | 314 |
242 | |
243 static int | 315 static int |
244 machopic_data_defined_p (rtx sym_ref) | 316 machopic_data_defined_p (rtx sym_ref) |
245 { | 317 { |
246 if (indirect_data (sym_ref)) | 318 if (indirect_data (sym_ref)) |
247 return 0; | 319 return 0; |
296 { | 368 { |
297 const char *current_name; | 369 const char *current_name; |
298 | 370 |
299 /* If dynamic-no-pic is on, we should not get here. */ | 371 /* If dynamic-no-pic is on, we should not get here. */ |
300 gcc_assert (!MACHO_DYNAMIC_NO_PIC_P); | 372 gcc_assert (!MACHO_DYNAMIC_NO_PIC_P); |
301 current_name = | 373 /* When we are generating _get_pc thunks within stubs, there is no current |
302 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)); | 374 function. */ |
303 if (function_base_func_name != current_name) | 375 if (current_function_decl) |
376 { | |
377 current_name = | |
378 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)); | |
379 if (function_base_func_name != current_name) | |
380 { | |
381 ++current_pic_label_num; | |
382 function_base_func_name = current_name; | |
383 } | |
384 } | |
385 else | |
304 { | 386 { |
305 ++current_pic_label_num; | 387 ++current_pic_label_num; |
306 function_base_func_name = current_name; | 388 function_base_func_name = "L_machopic_stub_dummy"; |
307 } | 389 } |
308 fprintf (file, "\"L%011d$pb\"", current_pic_label_num); | 390 fprintf (file, "L%011d$pb", current_pic_label_num); |
309 } | 391 } |
310 | 392 |
311 /* The suffix attached to non-lazy pointer symbols. */ | 393 /* The suffix attached to non-lazy pointer symbols. */ |
312 #define NON_LAZY_POINTER_SUFFIX "$non_lazy_ptr" | 394 #define NON_LAZY_POINTER_SUFFIX "$non_lazy_ptr" |
313 /* The suffix attached to stub symbols. */ | 395 /* The suffix attached to stub symbols. */ |
422 { | 504 { |
423 p = (machopic_indirection *) *slot; | 505 p = (machopic_indirection *) *slot; |
424 } | 506 } |
425 else | 507 else |
426 { | 508 { |
427 p = (machopic_indirection *) ggc_alloc (sizeof (machopic_indirection)); | 509 p = ggc_alloc_machopic_indirection (); |
428 p->symbol = sym_ref; | 510 p->symbol = sym_ref; |
429 p->ptr_name = xstrdup (buffer); | 511 p->ptr_name = xstrdup (buffer); |
430 p->stub_p = stub_p; | 512 p->stub_p = stub_p; |
431 p->used = false; | 513 p->used = false; |
432 *slot = p; | 514 *slot = p; |
491 { | 573 { |
492 int defined = machopic_data_defined_p (orig); | 574 int defined = machopic_data_defined_p (orig); |
493 | 575 |
494 if (defined && MACHO_DYNAMIC_NO_PIC_P) | 576 if (defined && MACHO_DYNAMIC_NO_PIC_P) |
495 { | 577 { |
496 #if defined (TARGET_TOC) | 578 if (DARWIN_PPC) |
579 { | |
497 /* Create a new register for CSE opportunities. */ | 580 /* Create a new register for CSE opportunities. */ |
498 rtx hi_reg = (!can_create_pseudo_p () ? reg : gen_reg_rtx (Pmode)); | 581 rtx hi_reg = (!can_create_pseudo_p () ? reg : gen_reg_rtx (Pmode)); |
499 emit_insn (gen_macho_high (hi_reg, orig)); | 582 emit_insn (gen_macho_high (hi_reg, orig)); |
500 emit_insn (gen_macho_low (reg, hi_reg, orig)); | 583 emit_insn (gen_macho_low (reg, hi_reg, orig)); |
501 #else | 584 return reg; |
585 } | |
586 else if (DARWIN_X86) | |
587 return orig; | |
588 else | |
502 /* some other cpu -- writeme! */ | 589 /* some other cpu -- writeme! */ |
503 gcc_unreachable (); | 590 gcc_unreachable (); |
504 #endif | |
505 return reg; | |
506 } | 591 } |
507 else if (defined) | 592 else if (defined) |
508 { | 593 { |
509 #if defined (TARGET_TOC) || defined (HAVE_lo_sum) | 594 rtx offset = NULL; |
510 rtx offset = machopic_gen_offset (orig); | 595 if (DARWIN_PPC || HAVE_lo_sum) |
511 #endif | 596 offset = machopic_gen_offset (orig); |
512 | 597 |
513 #if defined (TARGET_TOC) /* i.e., PowerPC */ | 598 if (DARWIN_PPC) |
599 { | |
514 rtx hi_sum_reg = (!can_create_pseudo_p () | 600 rtx hi_sum_reg = (!can_create_pseudo_p () |
515 ? reg | 601 ? reg |
516 : gen_reg_rtx (Pmode)); | 602 : gen_reg_rtx (Pmode)); |
517 | 603 |
518 gcc_assert (reg); | 604 gcc_assert (reg); |
523 emit_insn (gen_rtx_SET (Pmode, reg, | 609 emit_insn (gen_rtx_SET (Pmode, reg, |
524 gen_rtx_LO_SUM (Pmode, hi_sum_reg, | 610 gen_rtx_LO_SUM (Pmode, hi_sum_reg, |
525 copy_rtx (offset)))); | 611 copy_rtx (offset)))); |
526 | 612 |
527 orig = reg; | 613 orig = reg; |
528 #else | 614 } |
529 #if defined (HAVE_lo_sum) | 615 else if (HAVE_lo_sum) |
616 { | |
530 gcc_assert (reg); | 617 gcc_assert (reg); |
531 | 618 |
532 emit_insn (gen_rtx_SET (VOIDmode, reg, | 619 emit_insn (gen_rtx_SET (VOIDmode, reg, |
533 gen_rtx_HIGH (Pmode, offset))); | 620 gen_rtx_HIGH (Pmode, offset))); |
534 emit_insn (gen_rtx_SET (VOIDmode, reg, | 621 emit_insn (gen_rtx_SET (VOIDmode, reg, |
535 gen_rtx_LO_SUM (Pmode, reg, | 622 gen_rtx_LO_SUM (Pmode, reg, |
536 copy_rtx (offset)))); | 623 copy_rtx (offset)))); |
537 emit_use (pic_offset_table_rtx); | 624 emit_use (pic_offset_table_rtx); |
538 | 625 |
539 orig = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, reg); | 626 orig = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, reg); |
540 #endif | 627 } |
541 #endif | |
542 return orig; | 628 return orig; |
543 } | 629 } |
544 | 630 |
545 ptr_ref = (gen_rtx_SYMBOL_REF | 631 ptr_ref = (gen_rtx_SYMBOL_REF |
546 (Pmode, | 632 (Pmode, |
549 SYMBOL_REF_DATA (ptr_ref) = SYMBOL_REF_DATA (orig); | 635 SYMBOL_REF_DATA (ptr_ref) = SYMBOL_REF_DATA (orig); |
550 | 636 |
551 ptr_ref = gen_const_mem (Pmode, ptr_ref); | 637 ptr_ref = gen_const_mem (Pmode, ptr_ref); |
552 machopic_define_symbol (ptr_ref); | 638 machopic_define_symbol (ptr_ref); |
553 | 639 |
640 if (DARWIN_X86 | |
641 && reg | |
642 && MACHO_DYNAMIC_NO_PIC_P) | |
643 { | |
644 emit_insn (gen_rtx_SET (Pmode, reg, ptr_ref)); | |
645 ptr_ref = reg; | |
646 } | |
647 | |
554 return ptr_ref; | 648 return ptr_ref; |
555 } | 649 } |
556 else if (GET_CODE (orig) == CONST) | 650 else if (GET_CODE (orig) == CONST) |
557 { | 651 { |
652 /* If "(const (plus ...", walk the PLUS and return that result. | |
653 PLUS processing (below) will restore the "(const ..." if | |
654 appropriate. */ | |
655 if (GET_CODE (XEXP (orig, 0)) == PLUS) | |
656 return machopic_indirect_data_reference (XEXP (orig, 0), reg); | |
657 else | |
658 return orig; | |
659 } | |
660 else if (GET_CODE (orig) == MEM) | |
661 { | |
662 XEXP (ptr_ref, 0) = | |
663 machopic_indirect_data_reference (XEXP (orig, 0), reg); | |
664 return ptr_ref; | |
665 } | |
666 else if (GET_CODE (orig) == PLUS) | |
667 { | |
558 rtx base, result; | 668 rtx base, result; |
559 | 669 /* When the target is i386, this code prevents crashes due to the |
560 /* legitimize both operands of the PLUS */ | 670 compiler's ignorance on how to move the PIC base register to |
561 if (GET_CODE (XEXP (orig, 0)) == PLUS) | 671 other registers. (The reload phase sometimes introduces such |
672 insns.) */ | |
673 if (GET_CODE (XEXP (orig, 0)) == REG | |
674 && REGNO (XEXP (orig, 0)) == PIC_OFFSET_TABLE_REGNUM | |
675 /* Prevent the same register from being erroneously used | |
676 as both the base and index registers. */ | |
677 && (DARWIN_X86 && (GET_CODE (XEXP (orig, 1)) == CONST)) | |
678 && reg) | |
562 { | 679 { |
563 base = machopic_indirect_data_reference (XEXP (XEXP (orig, 0), 0), | 680 emit_move_insn (reg, XEXP (orig, 0)); |
564 reg); | 681 XEXP (ptr_ref, 0) = reg; |
565 orig = machopic_indirect_data_reference (XEXP (XEXP (orig, 0), 1), | 682 return ptr_ref; |
566 (base == reg ? 0 : reg)); | |
567 } | 683 } |
568 else | 684 |
569 return orig; | 685 /* Legitimize both operands of the PLUS. */ |
570 | 686 base = machopic_indirect_data_reference (XEXP (orig, 0), reg); |
571 if (MACHOPIC_PURE && GET_CODE (orig) == CONST_INT) | 687 orig = machopic_indirect_data_reference (XEXP (orig, 1), |
688 (base == reg ? 0 : reg)); | |
689 if (MACHOPIC_INDIRECT && (GET_CODE (orig) == CONST_INT)) | |
572 result = plus_constant (base, INTVAL (orig)); | 690 result = plus_constant (base, INTVAL (orig)); |
573 else | 691 else |
574 result = gen_rtx_PLUS (Pmode, base, orig); | 692 result = gen_rtx_PLUS (Pmode, base, orig); |
575 | 693 |
576 if (MACHOPIC_JUST_INDIRECT && GET_CODE (base) == MEM) | 694 if (MACHOPIC_JUST_INDIRECT && GET_CODE (base) == MEM) |
585 result = force_reg (GET_MODE (result), result); | 703 result = force_reg (GET_MODE (result), result); |
586 } | 704 } |
587 } | 705 } |
588 | 706 |
589 return result; | 707 return result; |
590 | |
591 } | |
592 else if (GET_CODE (orig) == MEM) | |
593 XEXP (ptr_ref, 0) = machopic_indirect_data_reference (XEXP (orig, 0), reg); | |
594 /* When the target is i386, this code prevents crashes due to the | |
595 compiler's ignorance on how to move the PIC base register to | |
596 other registers. (The reload phase sometimes introduces such | |
597 insns.) */ | |
598 else if (GET_CODE (orig) == PLUS | |
599 && GET_CODE (XEXP (orig, 0)) == REG | |
600 && REGNO (XEXP (orig, 0)) == PIC_OFFSET_TABLE_REGNUM | |
601 #ifdef I386 | |
602 /* Prevent the same register from being erroneously used | |
603 as both the base and index registers. */ | |
604 && GET_CODE (XEXP (orig, 1)) == CONST | |
605 #endif | |
606 && reg) | |
607 { | |
608 emit_move_insn (reg, XEXP (orig, 0)); | |
609 XEXP (ptr_ref, 0) = reg; | |
610 } | 708 } |
611 return ptr_ref; | 709 return ptr_ref; |
612 } | 710 } |
613 | 711 |
614 /* Transform TARGET (a MEM), which is a function call target, to the | 712 /* Transform TARGET (a MEM), which is a function call target, to the |
615 corresponding symbol_stub if necessary. Return a new MEM. */ | 713 corresponding symbol_stub if necessary. Return a new MEM. */ |
616 | 714 |
617 rtx | 715 rtx |
618 machopic_indirect_call_target (rtx target) | 716 machopic_indirect_call_target (rtx target) |
619 { | 717 { |
718 if (! darwin_emit_branch_islands) | |
719 return target; | |
720 | |
620 if (GET_CODE (target) != MEM) | 721 if (GET_CODE (target) != MEM) |
621 return target; | 722 return target; |
622 | 723 |
623 if (MACHOPIC_INDIRECT | 724 if (MACHOPIC_INDIRECT |
624 && GET_CODE (XEXP (target, 0)) == SYMBOL_REF | 725 && GET_CODE (XEXP (target, 0)) == SYMBOL_REF |
671 { | 772 { |
672 gcc_assert (!reload_in_progress); | 773 gcc_assert (!reload_in_progress); |
673 reg = gen_reg_rtx (Pmode); | 774 reg = gen_reg_rtx (Pmode); |
674 } | 775 } |
675 | 776 |
676 #ifdef HAVE_lo_sum | 777 #if HAVE_lo_sum |
677 if (MACHO_DYNAMIC_NO_PIC_P | 778 if (MACHO_DYNAMIC_NO_PIC_P |
678 && (GET_CODE (XEXP (orig, 0)) == SYMBOL_REF | 779 && (GET_CODE (XEXP (orig, 0)) == SYMBOL_REF |
679 || GET_CODE (XEXP (orig, 0)) == LABEL_REF)) | 780 || GET_CODE (XEXP (orig, 0)) == LABEL_REF)) |
680 { | 781 { |
681 #if defined (TARGET_TOC) /* ppc */ | 782 #if defined (TARGET_TOC) /* ppc */ |
766 #endif | 867 #endif |
767 } | 868 } |
768 else | 869 else |
769 { | 870 { |
770 | 871 |
771 #ifdef HAVE_lo_sum | 872 #if HAVE_lo_sum |
772 if (GET_CODE (orig) == SYMBOL_REF | 873 if (GET_CODE (orig) == SYMBOL_REF |
773 || GET_CODE (orig) == LABEL_REF) | 874 || GET_CODE (orig) == LABEL_REF) |
774 { | 875 { |
775 rtx offset = machopic_gen_offset (orig); | 876 rtx offset = machopic_gen_offset (orig); |
776 #if defined (TARGET_TOC) /* i.e., PowerPC */ | 877 #if defined (TARGET_TOC) /* i.e., PowerPC */ |
959 && (machopic_symbol_defined_p (symbol) | 1060 && (machopic_symbol_defined_p (symbol) |
960 || SYMBOL_REF_LOCAL_P (symbol))) | 1061 || SYMBOL_REF_LOCAL_P (symbol))) |
961 { | 1062 { |
962 switch_to_section (data_section); | 1063 switch_to_section (data_section); |
963 assemble_align (GET_MODE_ALIGNMENT (Pmode)); | 1064 assemble_align (GET_MODE_ALIGNMENT (Pmode)); |
964 assemble_label (ptr_name); | 1065 assemble_label (asm_out_file, ptr_name); |
965 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, sym_name), | 1066 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, sym_name), |
966 GET_MODE_SIZE (Pmode), | 1067 GET_MODE_SIZE (Pmode), |
967 GET_MODE_ALIGNMENT (Pmode), 1); | 1068 GET_MODE_ALIGNMENT (Pmode), 1); |
968 } | 1069 } |
969 else | 1070 else |
1074 } | 1175 } |
1075 | 1176 |
1076 void | 1177 void |
1077 darwin_mark_decl_preserved (const char *name) | 1178 darwin_mark_decl_preserved (const char *name) |
1078 { | 1179 { |
1079 fprintf (asm_out_file, ".no_dead_strip "); | 1180 fprintf (asm_out_file, "\t.no_dead_strip "); |
1080 assemble_name (asm_out_file, name); | 1181 assemble_name (asm_out_file, name); |
1081 fputc ('\n', asm_out_file); | 1182 fputc ('\n', asm_out_file); |
1082 } | 1183 } |
1083 | 1184 |
1084 static section * | 1185 static section * |
1085 darwin_text_section (int reloc, int weak) | 1186 darwin_rodata_section (int weak, bool zsize) |
1086 { | |
1087 if (reloc) | |
1088 return (weak | |
1089 ? darwin_sections[text_unlikely_coal_section] | |
1090 : unlikely_text_section ()); | |
1091 else | |
1092 return (weak | |
1093 ? darwin_sections[text_coal_section] | |
1094 : text_section); | |
1095 } | |
1096 | |
1097 static section * | |
1098 darwin_rodata_section (int weak) | |
1099 { | 1187 { |
1100 return (weak | 1188 return (weak |
1101 ? darwin_sections[const_coal_section] | 1189 ? darwin_sections[const_coal_section] |
1102 : darwin_sections[const_section]); | 1190 : (zsize ? darwin_sections[zobj_const_section] |
1191 : darwin_sections[const_section])); | |
1103 } | 1192 } |
1104 | 1193 |
1105 static section * | 1194 static section * |
1106 darwin_mergeable_string_section (tree exp, | 1195 darwin_mergeable_string_section (tree exp, |
1107 unsigned HOST_WIDE_INT align) | 1196 unsigned HOST_WIDE_INT align) |
1114 == TREE_STRING_LENGTH (exp)) | 1203 == TREE_STRING_LENGTH (exp)) |
1115 && ((size_t) TREE_STRING_LENGTH (exp) | 1204 && ((size_t) TREE_STRING_LENGTH (exp) |
1116 == strlen (TREE_STRING_POINTER (exp)) + 1)) | 1205 == strlen (TREE_STRING_POINTER (exp)) + 1)) |
1117 return darwin_sections[cstring_section]; | 1206 return darwin_sections[cstring_section]; |
1118 | 1207 |
1208 if (DARWIN_SECTION_ANCHORS && flag_section_anchors | |
1209 && TREE_CODE (exp) == STRING_CST | |
1210 && TREE_STRING_LENGTH (exp) == 0) | |
1211 return darwin_sections[zobj_const_section]; | |
1212 | |
1119 return readonly_data_section; | 1213 return readonly_data_section; |
1120 } | 1214 } |
1121 | 1215 |
1122 #ifndef HAVE_GAS_LITERAL16 | 1216 #ifndef HAVE_GAS_LITERAL16 |
1123 #define HAVE_GAS_LITERAL16 0 | 1217 #define HAVE_GAS_LITERAL16 0 |
1124 #endif | 1218 #endif |
1125 | 1219 |
1126 static section * | 1220 static section * |
1127 darwin_mergeable_constant_section (tree exp, | 1221 darwin_mergeable_constant_section (tree exp, |
1128 unsigned HOST_WIDE_INT align) | 1222 unsigned HOST_WIDE_INT align, |
1223 bool zsize) | |
1129 { | 1224 { |
1130 enum machine_mode mode = DECL_MODE (exp); | 1225 enum machine_mode mode = DECL_MODE (exp); |
1131 unsigned int modesize = GET_MODE_BITSIZE (mode); | 1226 unsigned int modesize = GET_MODE_BITSIZE (mode); |
1227 | |
1228 if (DARWIN_SECTION_ANCHORS | |
1229 && flag_section_anchors | |
1230 && zsize) | |
1231 return darwin_sections[zobj_const_section]; | |
1132 | 1232 |
1133 if (flag_merge_constants | 1233 if (flag_merge_constants |
1134 && mode != VOIDmode | 1234 && mode != VOIDmode |
1135 && mode != BLKmode | 1235 && mode != BLKmode |
1136 && modesize <= align | 1236 && modesize <= align |
1165 machopic_reloc_rw_mask (void) | 1265 machopic_reloc_rw_mask (void) |
1166 { | 1266 { |
1167 return MACHOPIC_INDIRECT ? 3 : 0; | 1267 return MACHOPIC_INDIRECT ? 3 : 0; |
1168 } | 1268 } |
1169 | 1269 |
1270 /* We have to deal with ObjC/C++ metadata section placement in the common | |
1271 code, since it will also be called from LTO. | |
1272 | |
1273 Return metadata attributes, if present (searching for ABI=2 first) | |
1274 Return NULL_TREE if no such attributes are found. */ | |
1275 | |
1276 static tree | |
1277 is_objc_metadata (tree decl) | |
1278 { | |
1279 if (DECL_P (decl) | |
1280 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL) | |
1281 && DECL_ATTRIBUTES (decl)) | |
1282 { | |
1283 tree meta = lookup_attribute ("OBJC2META", DECL_ATTRIBUTES (decl)); | |
1284 if (meta) | |
1285 return meta; | |
1286 meta = lookup_attribute ("OBJC1META", DECL_ATTRIBUTES (decl)); | |
1287 if (meta) | |
1288 return meta; | |
1289 } | |
1290 return NULL_TREE; | |
1291 } | |
1292 | |
1293 /* Return the section required for Objective C ABI 2 metadata. */ | |
1294 static section * | |
1295 darwin_objc2_section (tree decl ATTRIBUTE_UNUSED, tree meta, section * base) | |
1296 { | |
1297 const char *p; | |
1298 tree ident = TREE_VALUE (meta); | |
1299 gcc_assert (TREE_CODE (ident) == IDENTIFIER_NODE); | |
1300 p = IDENTIFIER_POINTER (ident); | |
1301 | |
1302 /* If we are in LTO, then we don't know the state of flag_next_runtime | |
1303 or flag_objc_abi when the code was generated. We set these from the | |
1304 meta-data - which is needed to deal with const string constructors. */ | |
1305 | |
1306 flag_next_runtime = 1; | |
1307 flag_objc_abi = 2; | |
1308 | |
1309 if (base == data_section) | |
1310 base = darwin_sections[objc2_metadata_section]; | |
1311 | |
1312 /* Most of the OBJC2 META-data end up in the base section, so check it | |
1313 first. */ | |
1314 if (!strncmp (p, "V2_BASE", 7)) | |
1315 return base; | |
1316 else if (!strncmp (p, "V2_STRG", 7)) | |
1317 return darwin_sections[cstring_section]; | |
1318 | |
1319 else if (!strncmp (p, "G2_META", 7) || !strncmp (p, "G2_CLAS", 7)) | |
1320 return darwin_sections[objc2_classdefs_section]; | |
1321 else if (!strncmp (p, "V2_MREF", 7)) | |
1322 return darwin_sections[objc2_message_refs_section]; | |
1323 else if (!strncmp (p, "V2_CLRF", 7)) | |
1324 return darwin_sections[objc2_classrefs_section]; | |
1325 else if (!strncmp (p, "V2_SURF", 7)) | |
1326 return darwin_sections[objc2_super_classrefs_section]; | |
1327 else if (!strncmp (p, "V2_NLCL", 7)) | |
1328 return darwin_sections[objc2_nonlazy_class_section]; | |
1329 else if (!strncmp (p, "V2_CLAB", 7)) | |
1330 return darwin_sections[objc2_classlist_section]; | |
1331 else if (!strncmp (p, "V2_SRFS", 7)) | |
1332 return darwin_sections[objc2_selector_refs_section]; | |
1333 else if (!strncmp (p, "V2_NLCA", 7)) | |
1334 return darwin_sections[objc2_nonlazy_category_section]; | |
1335 else if (!strncmp (p, "V2_CALA", 7)) | |
1336 return darwin_sections[objc2_categorylist_section]; | |
1337 | |
1338 else if (!strncmp (p, "V2_PLST", 7)) | |
1339 return darwin_sections[objc2_protocollist_section]; | |
1340 else if (!strncmp (p, "V2_PRFS", 7)) | |
1341 return darwin_sections[objc2_protocolrefs_section]; | |
1342 | |
1343 else if (!strncmp (p, "V2_INFO", 7)) | |
1344 return darwin_sections[objc2_image_info_section]; | |
1345 | |
1346 else if (!strncmp (p, "V2_EHTY", 7)) | |
1347 return darwin_sections[data_coal_section]; | |
1348 | |
1349 else if (!strncmp (p, "V2_CSTR", 7)) | |
1350 return darwin_sections[objc2_constant_string_object_section]; | |
1351 | |
1352 /* Not recognized, default. */ | |
1353 return base; | |
1354 } | |
1355 | |
1356 /* Return the section required for Objective C ABI 0/1 metadata. */ | |
1357 static section * | |
1358 darwin_objc1_section (tree decl ATTRIBUTE_UNUSED, tree meta, section * base) | |
1359 { | |
1360 const char *p; | |
1361 tree ident = TREE_VALUE (meta); | |
1362 gcc_assert (TREE_CODE (ident) == IDENTIFIER_NODE); | |
1363 p = IDENTIFIER_POINTER (ident); | |
1364 | |
1365 /* If we are in LTO, then we don't know the state of flag_next_runtime | |
1366 or flag_objc_abi when the code was generated. We set these from the | |
1367 meta-data - which is needed to deal with const string constructors. */ | |
1368 flag_next_runtime = 1; | |
1369 if (!global_options_set.x_flag_objc_abi) | |
1370 flag_objc_abi = 1; | |
1371 | |
1372 /* String sections first, cos there are lots of strings. */ | |
1373 if (!strncmp (p, "V1_STRG", 7)) | |
1374 return darwin_sections[cstring_section]; | |
1375 else if (!strncmp (p, "V1_CLSN", 7)) | |
1376 return darwin_sections[objc_class_names_section]; | |
1377 else if (!strncmp (p, "V1_METN", 7)) | |
1378 return darwin_sections[objc_meth_var_names_section]; | |
1379 else if (!strncmp (p, "V1_METT", 7)) | |
1380 return darwin_sections[objc_meth_var_types_section]; | |
1381 | |
1382 else if (!strncmp (p, "V1_CLAS", 7)) | |
1383 return darwin_sections[objc_class_section]; | |
1384 else if (!strncmp (p, "V1_META", 7)) | |
1385 return darwin_sections[objc_meta_class_section]; | |
1386 else if (!strncmp (p, "V1_CATG", 7)) | |
1387 return darwin_sections[objc_category_section]; | |
1388 else if (!strncmp (p, "V1_PROT", 7)) | |
1389 return darwin_sections[objc_protocol_section]; | |
1390 | |
1391 else if (!strncmp (p, "V1_CLCV", 7)) | |
1392 return darwin_sections[objc_class_vars_section]; | |
1393 else if (!strncmp (p, "V1_CLIV", 7)) | |
1394 return darwin_sections[objc_instance_vars_section]; | |
1395 | |
1396 else if (!strncmp (p, "V1_CLCM", 7)) | |
1397 return darwin_sections[objc_cls_meth_section]; | |
1398 else if (!strncmp (p, "V1_CLIM", 7)) | |
1399 return darwin_sections[objc_inst_meth_section]; | |
1400 else if (!strncmp (p, "V1_CACM", 7)) | |
1401 return darwin_sections[objc_cat_cls_meth_section]; | |
1402 else if (!strncmp (p, "V1_CAIM", 7)) | |
1403 return darwin_sections[objc_cat_inst_meth_section]; | |
1404 else if (!strncmp (p, "V1_PNSM", 7)) | |
1405 return darwin_sections[objc_cat_inst_meth_section]; | |
1406 else if (!strncmp (p, "V1_PCLM", 7)) | |
1407 return darwin_sections[objc_cat_cls_meth_section]; | |
1408 | |
1409 else if (!strncmp (p, "V1_CLPR", 7)) | |
1410 return darwin_sections[objc_cat_cls_meth_section]; | |
1411 else if (!strncmp (p, "V1_CAPR", 7)) | |
1412 return darwin_sections[objc_category_section]; /* ??? CHECK me. */ | |
1413 | |
1414 else if (!strncmp (p, "V1_PRFS", 7)) | |
1415 return darwin_sections[objc_cat_cls_meth_section]; | |
1416 else if (!strncmp (p, "V1_CLRF", 7)) | |
1417 return darwin_sections[objc_cls_refs_section]; | |
1418 else if (!strncmp (p, "V1_SRFS", 7)) | |
1419 return darwin_sections[objc_selector_refs_section]; | |
1420 | |
1421 else if (!strncmp (p, "V1_MODU", 7)) | |
1422 return darwin_sections[objc_module_info_section]; | |
1423 else if (!strncmp (p, "V1_SYMT", 7)) | |
1424 return darwin_sections[objc_symbols_section]; | |
1425 else if (!strncmp (p, "V1_INFO", 7)) | |
1426 return darwin_sections[objc_image_info_section]; | |
1427 | |
1428 else if (!strncmp (p, "V1_PLST", 7)) | |
1429 return darwin_sections[objc1_prop_list_section]; | |
1430 else if (!strncmp (p, "V1_PEXT", 7)) | |
1431 return darwin_sections[objc1_protocol_ext_section]; | |
1432 else if (!strncmp (p, "V1_CEXT", 7)) | |
1433 return darwin_sections[objc1_class_ext_section]; | |
1434 | |
1435 else if (!strncmp (p, "V2_CSTR", 7)) | |
1436 return darwin_sections[objc_constant_string_object_section]; | |
1437 | |
1438 return base; | |
1439 } | |
1440 | |
1170 section * | 1441 section * |
1171 machopic_select_section (tree decl, | 1442 machopic_select_section (tree decl, |
1172 int reloc, | 1443 int reloc, |
1173 unsigned HOST_WIDE_INT align) | 1444 unsigned HOST_WIDE_INT align) |
1174 { | 1445 { |
1175 bool weak = (DECL_P (decl) | 1446 bool zsize, one, weak, ro; |
1176 && DECL_WEAK (decl) | 1447 section *base_section = NULL; |
1177 && !lookup_attribute ("weak_import", | 1448 |
1178 DECL_ATTRIBUTES (decl))); | 1449 weak = (DECL_P (decl) |
1179 section *base_section; | 1450 && DECL_WEAK (decl) |
1451 && !lookup_attribute ("weak_import", DECL_ATTRIBUTES (decl))); | |
1452 | |
1453 zsize = (DECL_P (decl) | |
1454 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL) | |
1455 && tree_low_cst (DECL_SIZE_UNIT (decl), 1) == 0); | |
1456 | |
1457 one = DECL_P (decl) | |
1458 && TREE_CODE (decl) == VAR_DECL | |
1459 && DECL_ONE_ONLY (decl); | |
1460 | |
1461 ro = TREE_READONLY (decl) || TREE_CONSTANT (decl) ; | |
1180 | 1462 |
1181 switch (categorize_decl_for_section (decl, reloc)) | 1463 switch (categorize_decl_for_section (decl, reloc)) |
1182 { | 1464 { |
1183 case SECCAT_TEXT: | 1465 case SECCAT_TEXT: |
1184 base_section = darwin_text_section (reloc, weak); | 1466 gcc_unreachable (); |
1185 break; | 1467 break; |
1186 | 1468 |
1187 case SECCAT_RODATA: | 1469 case SECCAT_RODATA: |
1188 case SECCAT_SRODATA: | 1470 case SECCAT_SRODATA: |
1189 base_section = darwin_rodata_section (weak); | 1471 base_section = darwin_rodata_section (weak, zsize); |
1190 break; | 1472 break; |
1191 | 1473 |
1192 case SECCAT_RODATA_MERGE_STR: | 1474 case SECCAT_RODATA_MERGE_STR: |
1193 base_section = darwin_mergeable_string_section (decl, align); | 1475 base_section = darwin_mergeable_string_section (decl, align); |
1194 break; | 1476 break; |
1196 case SECCAT_RODATA_MERGE_STR_INIT: | 1478 case SECCAT_RODATA_MERGE_STR_INIT: |
1197 base_section = darwin_mergeable_string_section (DECL_INITIAL (decl), align); | 1479 base_section = darwin_mergeable_string_section (DECL_INITIAL (decl), align); |
1198 break; | 1480 break; |
1199 | 1481 |
1200 case SECCAT_RODATA_MERGE_CONST: | 1482 case SECCAT_RODATA_MERGE_CONST: |
1201 base_section = darwin_mergeable_constant_section (decl, align); | 1483 base_section = darwin_mergeable_constant_section (decl, align, zsize); |
1202 break; | 1484 break; |
1203 | 1485 |
1204 case SECCAT_DATA: | 1486 case SECCAT_DATA: |
1205 case SECCAT_DATA_REL: | 1487 case SECCAT_DATA_REL: |
1206 case SECCAT_DATA_REL_LOCAL: | 1488 case SECCAT_DATA_REL_LOCAL: |
1207 case SECCAT_DATA_REL_RO: | 1489 case SECCAT_DATA_REL_RO: |
1208 case SECCAT_DATA_REL_RO_LOCAL: | 1490 case SECCAT_DATA_REL_RO_LOCAL: |
1209 case SECCAT_SDATA: | 1491 case SECCAT_SDATA: |
1210 case SECCAT_TDATA: | 1492 case SECCAT_TDATA: |
1493 if (weak || one) | |
1494 { | |
1495 if (ro) | |
1496 base_section = darwin_sections[const_data_coal_section]; | |
1497 else | |
1498 base_section = darwin_sections[data_coal_section]; | |
1499 } | |
1500 else if (DARWIN_SECTION_ANCHORS | |
1501 && flag_section_anchors | |
1502 && zsize) | |
1503 { | |
1504 /* If we're doing section anchors, then punt zero-sized objects into | |
1505 their own sections so that they don't interfere with offset | |
1506 computation for the remaining vars. This does not need to be done | |
1507 for stuff in mergeable sections, since these are ineligible for | |
1508 anchors. */ | |
1509 if (ro) | |
1510 base_section = darwin_sections[zobj_const_data_section]; | |
1511 else | |
1512 base_section = darwin_sections[zobj_data_section]; | |
1513 } | |
1514 else if (ro) | |
1515 base_section = darwin_sections[const_data_section]; | |
1516 else | |
1517 base_section = data_section; | |
1518 break; | |
1211 case SECCAT_BSS: | 1519 case SECCAT_BSS: |
1212 case SECCAT_SBSS: | 1520 case SECCAT_SBSS: |
1213 case SECCAT_TBSS: | 1521 case SECCAT_TBSS: |
1214 if (TREE_READONLY (decl) || TREE_CONSTANT (decl)) | 1522 if (weak || one) |
1215 base_section = weak ? darwin_sections[const_data_coal_section] | 1523 base_section = darwin_sections[data_coal_section]; |
1216 : darwin_sections[const_data_section]; | |
1217 else | 1524 else |
1218 base_section = weak ? darwin_sections[data_coal_section] : data_section; | 1525 { |
1526 if (!TREE_PUBLIC (decl)) | |
1527 base_section = lcomm_section; | |
1528 else if (bss_noswitch_section) | |
1529 base_section = bss_noswitch_section; | |
1530 else | |
1531 base_section = data_section; | |
1532 } | |
1219 break; | 1533 break; |
1220 | 1534 |
1221 default: | 1535 default: |
1222 gcc_unreachable (); | 1536 gcc_unreachable (); |
1223 } | 1537 } |
1224 | 1538 |
1225 /* Darwin weird special cases. */ | 1539 /* Darwin weird special cases. |
1540 a) OBJC Meta-data. */ | |
1541 if (DECL_P (decl) | |
1542 && (TREE_CODE (decl) == VAR_DECL | |
1543 || TREE_CODE (decl) == CONST_DECL) | |
1544 && DECL_ATTRIBUTES (decl)) | |
1545 { | |
1546 tree meta = lookup_attribute ("OBJC2META", DECL_ATTRIBUTES (decl)); | |
1547 if (meta) | |
1548 return darwin_objc2_section (decl, meta, base_section); | |
1549 meta = lookup_attribute ("OBJC1META", DECL_ATTRIBUTES (decl)); | |
1550 if (meta) | |
1551 return darwin_objc1_section (decl, meta, base_section); | |
1552 meta = lookup_attribute ("OBJC1METG", DECL_ATTRIBUTES (decl)); | |
1553 if (meta) | |
1554 return base_section; /* GNU runtime is happy with it all in one pot. */ | |
1555 } | |
1556 | |
1557 /* b) Constant string objects. */ | |
1226 if (TREE_CODE (decl) == CONSTRUCTOR | 1558 if (TREE_CODE (decl) == CONSTRUCTOR |
1227 && TREE_TYPE (decl) | 1559 && TREE_TYPE (decl) |
1228 && TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE | 1560 && TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE |
1229 && TYPE_NAME (TREE_TYPE (decl))) | 1561 && TYPE_NAME (TREE_TYPE (decl))) |
1230 { | 1562 { |
1231 tree name = TYPE_NAME (TREE_TYPE (decl)); | 1563 tree name = TYPE_NAME (TREE_TYPE (decl)); |
1232 if (TREE_CODE (name) == TYPE_DECL) | 1564 if (TREE_CODE (name) == TYPE_DECL) |
1233 name = DECL_NAME (name); | 1565 name = DECL_NAME (name); |
1234 | 1566 |
1567 /* FIXME: This is unsatisfactory for LTO, since it relies on other | |
1568 metadata determining the source FE. */ | |
1235 if (!strcmp (IDENTIFIER_POINTER (name), "__builtin_ObjCString")) | 1569 if (!strcmp (IDENTIFIER_POINTER (name), "__builtin_ObjCString")) |
1236 { | 1570 { |
1237 if (flag_next_runtime) | 1571 if (flag_next_runtime) |
1238 return darwin_sections[objc_constant_string_object_section]; | 1572 { |
1239 else | 1573 if (flag_objc_abi == 2) |
1240 return darwin_sections[objc_string_object_section]; | 1574 return darwin_sections[objc2_constant_string_object_section]; |
1241 } | 1575 else |
1576 return darwin_sections[objc_constant_string_object_section]; | |
1577 } | |
1578 else | |
1579 return darwin_sections[objc_string_object_section]; | |
1580 } | |
1581 else if (!strcmp (IDENTIFIER_POINTER (name), "__builtin_CFString")) | |
1582 return darwin_sections[cfstring_constant_object_section]; | |
1242 else | 1583 else |
1243 return base_section; | 1584 return base_section; |
1244 } | 1585 } |
1586 /* c) legacy meta-data selection. */ | |
1245 else if (TREE_CODE (decl) == VAR_DECL | 1587 else if (TREE_CODE (decl) == VAR_DECL |
1246 && DECL_NAME (decl) | 1588 && DECL_NAME (decl) |
1247 && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE | 1589 && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE |
1248 && IDENTIFIER_POINTER (DECL_NAME (decl)) | 1590 && IDENTIFIER_POINTER (DECL_NAME (decl)) |
1591 && flag_next_runtime | |
1249 && !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "_OBJC_", 6)) | 1592 && !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "_OBJC_", 6)) |
1250 { | 1593 { |
1251 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl)); | 1594 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl)); |
1252 | 1595 static bool warned_objc_46 = false; |
1596 /* We shall assert that zero-sized objects are an error in ObjC | |
1597 meta-data. */ | |
1598 gcc_assert (tree_low_cst (DECL_SIZE_UNIT (decl), 1) != 0); | |
1599 | |
1600 /* ??? This mechanism for determining the metadata section is | |
1601 broken when LTO is in use, since the frontend that generated | |
1602 the data is not identified. We will keep the capability for | |
1603 the short term - in case any non-Objective-C programs are using | |
1604 it to place data in specified sections. */ | |
1605 if (!warned_objc_46) | |
1606 { | |
1607 location_t loc = DECL_SOURCE_LOCATION (decl); | |
1608 warning_at (loc, 0, "the use of _OBJC_-prefixed variable names" | |
1609 " to select meta-data sections is deprecated at 4.6" | |
1610 " and will be removed in 4.7"); | |
1611 warned_objc_46 = true; | |
1612 } | |
1613 | |
1253 if (!strncmp (name, "_OBJC_CLASS_METHODS_", 20)) | 1614 if (!strncmp (name, "_OBJC_CLASS_METHODS_", 20)) |
1254 return darwin_sections[objc_cls_meth_section]; | 1615 return darwin_sections[objc_cls_meth_section]; |
1255 else if (!strncmp (name, "_OBJC_INSTANCE_METHODS_", 23)) | 1616 else if (!strncmp (name, "_OBJC_INSTANCE_METHODS_", 23)) |
1256 return darwin_sections[objc_inst_meth_section]; | 1617 return darwin_sections[objc_inst_meth_section]; |
1257 else if (!strncmp (name, "_OBJC_CATEGORY_CLASS_METHODS_", 20)) | 1618 else if (!strncmp (name, "_OBJC_CATEGORY_CLASS_METHODS_", 29)) |
1258 return darwin_sections[objc_cat_cls_meth_section]; | 1619 return darwin_sections[objc_cat_cls_meth_section]; |
1259 else if (!strncmp (name, "_OBJC_CATEGORY_INSTANCE_METHODS_", 23)) | 1620 else if (!strncmp (name, "_OBJC_CATEGORY_INSTANCE_METHODS_", 32)) |
1260 return darwin_sections[objc_cat_inst_meth_section]; | 1621 return darwin_sections[objc_cat_inst_meth_section]; |
1261 else if (!strncmp (name, "_OBJC_CLASS_VARIABLES_", 22)) | 1622 else if (!strncmp (name, "_OBJC_CLASS_VARIABLES_", 22)) |
1262 return darwin_sections[objc_class_vars_section]; | 1623 return darwin_sections[objc_class_vars_section]; |
1263 else if (!strncmp (name, "_OBJC_INSTANCE_VARIABLES_", 25)) | 1624 else if (!strncmp (name, "_OBJC_INSTANCE_VARIABLES_", 25)) |
1264 return darwin_sections[objc_instance_vars_section]; | 1625 return darwin_sections[objc_instance_vars_section]; |
1431 fclose (lto_asm_out_file); | 1792 fclose (lto_asm_out_file); |
1432 asm_out_file = saved_asm_out_file; | 1793 asm_out_file = saved_asm_out_file; |
1433 saved_asm_out_file = NULL; | 1794 saved_asm_out_file = NULL; |
1434 } | 1795 } |
1435 | 1796 |
1797 static void | |
1798 darwin_asm_dwarf_section (const char *name, unsigned int flags, tree decl); | |
1799 | |
1800 /* Called for the TARGET_ASM_NAMED_SECTION hook. */ | |
1801 | |
1436 void | 1802 void |
1437 darwin_asm_named_section (const char *name, | 1803 darwin_asm_named_section (const char *name, |
1438 unsigned int flags, | 1804 unsigned int flags, |
1439 tree decl ATTRIBUTE_UNUSED) | 1805 tree decl ATTRIBUTE_UNUSED) |
1440 { | 1806 { |
1467 within reasonable length. */ | 1833 within reasonable length. */ |
1468 lto_section_names_offset += strlen (name) + 1; | 1834 lto_section_names_offset += strlen (name) + 1; |
1469 gcc_assert (lto_section_names_offset > 0 | 1835 gcc_assert (lto_section_names_offset > 0 |
1470 && lto_section_names_offset < ((unsigned) 1 << 31)); | 1836 && lto_section_names_offset < ((unsigned) 1 << 31)); |
1471 } | 1837 } |
1838 else if (strncmp (name, "__DWARF,", 8) == 0) | |
1839 darwin_asm_dwarf_section (name, flags, decl); | |
1472 else | 1840 else |
1473 fprintf (asm_out_file, "\t.section %s\n", name); | 1841 fprintf (asm_out_file, "\t.section %s\n", name); |
1474 } | 1842 } |
1475 | 1843 |
1476 void | 1844 void |
1542 FDE that we are omitting. */ | 1910 FDE that we are omitting. */ |
1543 | 1911 |
1544 void | 1912 void |
1545 darwin_emit_unwind_label (FILE *file, tree decl, int for_eh, int empty) | 1913 darwin_emit_unwind_label (FILE *file, tree decl, int for_eh, int empty) |
1546 { | 1914 { |
1547 char *lab; | 1915 char *lab ; |
1548 | 1916 char buf[32]; |
1549 if (! for_eh) | 1917 static int invok_count = 0; |
1918 static tree last_fun_decl = NULL_TREE; | |
1919 | |
1920 /* We use the linker to emit the .eh labels for Darwin 9 and above. */ | |
1921 if (! for_eh || generating_for_darwin_version >= 9) | |
1550 return; | 1922 return; |
1551 | 1923 |
1552 lab = concat (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), ".eh", NULL); | 1924 /* FIXME: This only works when the eh for all sections of a function is |
1925 emitted at the same time. If that changes, we would need to use a lookup | |
1926 table of some form to determine what to do. Also, we should emit the | |
1927 unadorned label for the partition containing the public label for a | |
1928 function. This is of limited use, probably, since we do not currently | |
1929 enable partitioning. */ | |
1930 strcpy (buf, ".eh"); | |
1931 if (decl && TREE_CODE (decl) == FUNCTION_DECL) | |
1932 { | |
1933 if (decl == last_fun_decl) | |
1934 { | |
1935 invok_count++; | |
1936 snprintf (buf, 31, "$$part$$%d.eh", invok_count); | |
1937 } | |
1938 else | |
1939 { | |
1940 last_fun_decl = decl; | |
1941 invok_count = 0; | |
1942 } | |
1943 } | |
1944 | |
1945 lab = concat (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), buf, NULL); | |
1553 | 1946 |
1554 if (TREE_PUBLIC (decl)) | 1947 if (TREE_PUBLIC (decl)) |
1555 { | 1948 { |
1556 targetm.asm_out.globalize_label (file, lab); | 1949 targetm.asm_out.globalize_label (file, lab); |
1557 if (DECL_VISIBILITY (decl) == VISIBILITY_HIDDEN) | 1950 if (DECL_VISIBILITY (decl) == VISIBILITY_HIDDEN) |
1610 fputs ("\t.long\t", file); | 2003 fputs ("\t.long\t", file); |
1611 ASM_OUTPUT_LABELREF (file, nlp_name); | 2004 ASM_OUTPUT_LABELREF (file, nlp_name); |
1612 fputs ("-.", file); | 2005 fputs ("-.", file); |
1613 } | 2006 } |
1614 | 2007 |
2008 /* If this is uncommented, details of each allocation will be printed | |
2009 in the asm right before the actual code. WARNING - this will cause some | |
2010 test-suite fails (since the printout will contain items that some tests | |
2011 are not expecting) -- so don't leave it on by default (it bloats the | |
2012 asm too). */ | |
2013 /*#define DEBUG_DARWIN_MEM_ALLOCATORS*/ | |
2014 | |
2015 /* The first two of these routines are ostensibly just intended to put | |
2016 names into the asm. However, they are both hijacked in order to ensure | |
2017 that zero-sized items do not make their way into the output. Consequently, | |
2018 we also need to make these participate in provisions for dealing with | |
2019 such items in section anchors. */ | |
2020 | |
2021 /* The implementation of ASM_DECLARE_OBJECT_NAME. */ | |
2022 /* The RTTI data (e.g., __ti4name) is common and public (and static), | |
2023 but it does need to be referenced via indirect PIC data pointers. | |
2024 The machopic_define_symbol calls are telling the machopic subsystem | |
2025 that the name *is* defined in this module, so it doesn't need to | |
2026 make them indirect. */ | |
2027 void | |
2028 darwin_asm_declare_object_name (FILE *file, | |
2029 const char *nam, tree decl) | |
2030 { | |
2031 const char *xname = nam; | |
2032 unsigned HOST_WIDE_INT size; | |
2033 bool local_def, weak; | |
2034 | |
2035 weak = (DECL_P (decl) | |
2036 && DECL_WEAK (decl) | |
2037 && !lookup_attribute ("weak_import", | |
2038 DECL_ATTRIBUTES (decl))); | |
2039 | |
2040 local_def = DECL_INITIAL (decl) || (TREE_STATIC (decl) | |
2041 && (!DECL_COMMON (decl) | |
2042 || !TREE_PUBLIC (decl))); | |
2043 | |
2044 if (GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF) | |
2045 xname = IDENTIFIER_POINTER (DECL_NAME (decl)); | |
2046 | |
2047 if (local_def) | |
2048 { | |
2049 (* targetm.encode_section_info) (decl, DECL_RTL (decl), false); | |
2050 if (!weak) | |
2051 machopic_define_symbol (DECL_RTL (decl)); | |
2052 } | |
2053 | |
2054 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1); | |
2055 | |
2056 #ifdef DEBUG_DARWIN_MEM_ALLOCATORS | |
2057 fprintf (file, "# dadon: %s %s (%llu, %u) local %d weak %d" | |
2058 " stat %d com %d pub %d t-const %d t-ro %d init %lx\n", | |
2059 xname, (TREE_CODE (decl) == VAR_DECL?"var":"const"), | |
2060 (unsigned long long)size, DECL_ALIGN (decl), local_def, | |
2061 DECL_WEAK (decl), TREE_STATIC (decl), DECL_COMMON (decl), | |
2062 TREE_PUBLIC (decl), TREE_CONSTANT (decl), TREE_READONLY (decl), | |
2063 (unsigned long)DECL_INITIAL (decl)); | |
2064 #endif | |
2065 | |
2066 /* Darwin needs help to support local zero-sized objects. | |
2067 They must be made at least one byte, and the section containing must be | |
2068 marked as unsuitable for section-anchors (see storage allocators below). | |
2069 | |
2070 For non-zero objects this output is handled by varasm.c. | |
2071 */ | |
2072 if (!size) | |
2073 { | |
2074 unsigned int l2align = 0; | |
2075 | |
2076 /* The align must be honored, even for zero-sized. */ | |
2077 if (DECL_ALIGN (decl)) | |
2078 { | |
2079 l2align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT); | |
2080 fprintf (file, "\t.align\t%u\n", l2align); | |
2081 } | |
2082 | |
2083 ASM_OUTPUT_LABEL (file, xname); | |
2084 size = 1; | |
2085 fprintf (file, "\t.space\t"HOST_WIDE_INT_PRINT_UNSIGNED"\n", size); | |
2086 | |
2087 /* Check that we've correctly picked up the zero-sized item and placed it | |
2088 properly. */ | |
2089 gcc_assert ((!DARWIN_SECTION_ANCHORS || !flag_section_anchors) | |
2090 || (in_section | |
2091 && (in_section->common.flags & SECTION_NO_ANCHOR))); | |
2092 } | |
2093 else | |
2094 ASM_OUTPUT_LABEL (file, xname); | |
2095 } | |
2096 | |
2097 /* The implementation of ASM_DECLARE_CONSTANT_NAME. */ | |
2098 void | |
2099 darwin_asm_declare_constant_name (FILE *file, const char *name, | |
2100 const_tree exp ATTRIBUTE_UNUSED, | |
2101 HOST_WIDE_INT size) | |
2102 { | |
2103 assemble_label (file, name); | |
2104 /* As for other items, we need at least one byte. */ | |
2105 if (!size) | |
2106 { | |
2107 fputs ("\t.space\t1\n", file); | |
2108 /* Check that we've correctly picked up the zero-sized item and placed it | |
2109 properly. */ | |
2110 gcc_assert ((!DARWIN_SECTION_ANCHORS || !flag_section_anchors) | |
2111 || (in_section | |
2112 && (in_section->common.flags & SECTION_NO_ANCHOR))); | |
2113 } | |
2114 } | |
2115 | |
2116 /* Darwin storage allocators. | |
2117 | |
2118 Zerofill sections are desirable for large blank data since, otherwise, these | |
2119 data bloat objects (PR33210). | |
2120 | |
2121 However, section anchors don't work in .zerofill sections (one cannot switch | |
2122 to a zerofill section). Ergo, for Darwin targets using section anchors we need | |
2123 to put (at least some) data into 'normal' switchable sections. | |
2124 | |
2125 Here we set a relatively arbitrary value for the size of an object to trigger | |
2126 zerofill when section anchors are enabled (anything bigger than a page for | |
2127 current Darwin implementations). FIXME: there ought to be some objective way | |
2128 to make this choice. | |
2129 | |
2130 When section anchor are off this is ignored anyway. */ | |
2131 | |
2132 #define BYTES_ZFILL 4096 | |
2133 | |
2134 /* Emit a chunk of data for items coalesced by the linker. */ | |
2135 static void | |
2136 darwin_emit_weak_or_comdat (FILE *fp, tree decl, const char *name, | |
2137 unsigned HOST_WIDE_INT size, | |
2138 unsigned int align) | |
2139 { | |
2140 /* Since the sections used here are coalesed, they will not be eligible | |
2141 for section anchors, and therefore we don't need to break that out. */ | |
2142 if (TREE_READONLY (decl) || TREE_CONSTANT (decl)) | |
2143 switch_to_section (darwin_sections[const_data_coal_section]); | |
2144 else | |
2145 switch_to_section (darwin_sections[data_coal_section]); | |
2146 | |
2147 /* To be consistent, we'll allow darwin_asm_declare_object_name to assemble | |
2148 the align info for zero-sized items... but do it here otherwise. */ | |
2149 if (size && align) | |
2150 fprintf (fp, "\t.align\t%d\n", floor_log2 (align / BITS_PER_UNIT)); | |
2151 | |
2152 if (TREE_PUBLIC (decl)) | |
2153 darwin_globalize_label (fp, name); | |
2154 | |
2155 /* ... and we let it deal with outputting one byte of zero for them too. */ | |
2156 darwin_asm_declare_object_name (fp, name, decl); | |
2157 if (size) | |
2158 assemble_zeros (size); | |
2159 } | |
2160 | |
2161 /* Emit a chunk of data for ObjC meta-data that got placed in BSS erroneously. */ | |
2162 static void | |
2163 darwin_emit_objc_zeroed (FILE *fp, tree decl, const char *name, | |
2164 unsigned HOST_WIDE_INT size, | |
2165 unsigned int align, tree meta) | |
2166 { | |
2167 section *ocs = data_section; | |
2168 | |
2169 if (TREE_PURPOSE (meta) == get_identifier("OBJC2META")) | |
2170 ocs = darwin_objc2_section (decl, meta, ocs); | |
2171 else | |
2172 ocs = darwin_objc1_section (decl, meta, ocs); | |
2173 | |
2174 switch_to_section (ocs); | |
2175 | |
2176 /* We shall declare that zero-sized meta-data are not valid (yet). */ | |
2177 gcc_assert (size); | |
2178 fprintf (fp, "\t.align\t%d\n", floor_log2 (align / BITS_PER_UNIT)); | |
2179 | |
2180 /* ... and we let it deal with outputting one byte of zero for them too. */ | |
2181 darwin_asm_declare_object_name (fp, name, decl); | |
2182 assemble_zeros (size); | |
2183 } | |
2184 | |
2185 /* This routine emits 'local' storage: | |
2186 | |
2187 When Section Anchors are off this routine emits .zerofill commands in | |
2188 sections named for their alignment. | |
2189 | |
2190 When Section Anchors are on, smaller (non-zero-sized) items are placed in | |
2191 the .static_data section so that the section anchoring system can see them. | |
2192 Larger items are still placed in .zerofill sections, addressing PR33210. | |
2193 The routine has no checking - it is all assumed to be done by the caller. | |
2194 */ | |
2195 static void | |
2196 darwin_emit_local_bss (FILE *fp, tree decl, const char *name, | |
2197 unsigned HOST_WIDE_INT size, | |
2198 unsigned int l2align) | |
2199 { | |
2200 /* FIXME: We have a fudge to make this work with Java even when the target does | |
2201 not use sections anchors -- Java seems to need at least one small item in a | |
2202 non-zerofill segment. */ | |
2203 if ((DARWIN_SECTION_ANCHORS && flag_section_anchors && size < BYTES_ZFILL) | |
2204 || (size && size <= 2)) | |
2205 { | |
2206 /* Put smaller objects in _static_data, where the section anchors system | |
2207 can get them. | |
2208 However, if they are zero-sized punt them to yet a different section | |
2209 (that is not allowed to participate in anchoring). */ | |
2210 if (!size) | |
2211 { | |
2212 fputs ("\t.section\t__DATA,__zobj_bss\n", fp); | |
2213 in_section = darwin_sections[zobj_bss_section]; | |
2214 size = 1; | |
2215 } | |
2216 else | |
2217 { | |
2218 fputs ("\t.static_data\n", fp); | |
2219 in_section = darwin_sections[static_data_section]; | |
2220 } | |
2221 | |
2222 if (l2align) | |
2223 fprintf (fp, "\t.align\t%u\n", l2align); | |
2224 | |
2225 assemble_name (fp, name); | |
2226 fprintf (fp, ":\n\t.space\t"HOST_WIDE_INT_PRINT_UNSIGNED"\n", size); | |
2227 } | |
2228 else | |
2229 { | |
2230 /* When we are on a non-section anchor target, we can get zero-sized | |
2231 items here. However, all we need to do is to bump them to one byte | |
2232 and the section alignment will take care of the rest. */ | |
2233 char secnam[64]; | |
2234 unsigned int flags ; | |
2235 snprintf (secnam, 64, "__DATA,__%sbss%u", ((size)?"":"zo_"), | |
2236 (unsigned) l2align); | |
2237 /* We can't anchor (yet, if ever) in zerofill sections, because we can't | |
2238 switch to them and emit a label. */ | |
2239 flags = SECTION_BSS|SECTION_WRITE|SECTION_NO_ANCHOR; | |
2240 in_section = get_section (secnam, flags, NULL); | |
2241 fprintf (fp, "\t.zerofill %s,", secnam); | |
2242 assemble_name (fp, name); | |
2243 if (!size) | |
2244 size = 1; | |
2245 | |
2246 if (l2align) | |
2247 fprintf (fp, ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", | |
2248 size, (unsigned) l2align); | |
2249 else | |
2250 fprintf (fp, ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", size); | |
2251 } | |
2252 | |
2253 (*targetm.encode_section_info) (decl, DECL_RTL (decl), false); | |
2254 /* This is defined as a file-scope var, so we know to notify machopic. */ | |
2255 machopic_define_symbol (DECL_RTL (decl)); | |
2256 } | |
2257 | |
2258 /* Emit a chunk of common. */ | |
2259 static void | |
2260 darwin_emit_common (FILE *fp, const char *name, | |
2261 unsigned HOST_WIDE_INT size, unsigned int align) | |
2262 { | |
2263 unsigned HOST_WIDE_INT rounded; | |
2264 unsigned int l2align; | |
2265 | |
2266 /* Earlier systems complain if the alignment exceeds the page size. | |
2267 The magic number is 4096 * 8 - hard-coded for legacy systems. */ | |
2268 if (!emit_aligned_common && (align > 32768UL)) | |
2269 align = 4096UL; /* In units. */ | |
2270 else | |
2271 align /= BITS_PER_UNIT; | |
2272 | |
2273 /* Make sure we have a meaningful align. */ | |
2274 if (!align) | |
2275 align = 1; | |
2276 | |
2277 /* For earlier toolchains, we need to emit the var as a rounded size to | |
2278 tell ld the alignment. */ | |
2279 if (size < align) | |
2280 rounded = align; | |
2281 else | |
2282 rounded = (size + (align-1)) & ~(align-1); | |
2283 | |
2284 l2align = floor_log2 (align); | |
2285 gcc_assert (l2align <= L2_MAX_OFILE_ALIGNMENT); | |
2286 | |
2287 in_section = comm_section; | |
2288 /* We mustn't allow multiple public symbols to share an address when using | |
2289 the normal OSX toolchain. */ | |
2290 if (!size) | |
2291 { | |
2292 /* Put at least one byte. */ | |
2293 size = 1; | |
2294 /* This section can no longer participate in section anchoring. */ | |
2295 comm_section->common.flags |= SECTION_NO_ANCHOR; | |
2296 } | |
2297 | |
2298 fputs ("\t.comm\t", fp); | |
2299 assemble_name (fp, name); | |
2300 fprintf (fp, "," HOST_WIDE_INT_PRINT_UNSIGNED, | |
2301 emit_aligned_common?size:rounded); | |
2302 if (l2align && emit_aligned_common) | |
2303 fprintf (fp, ",%u", l2align); | |
2304 fputs ("\n", fp); | |
2305 } | |
2306 | |
2307 /* Output a var which is all zero - into aligned BSS sections, common, lcomm | |
2308 or coalescable data sections (for weak or comdat) as appropriate. */ | |
2309 | |
2310 void | |
2311 darwin_output_aligned_bss (FILE *fp, tree decl, const char *name, | |
2312 unsigned HOST_WIDE_INT size, unsigned int align) | |
2313 { | |
2314 unsigned int l2align; | |
2315 bool one, pub, weak; | |
2316 tree meta; | |
2317 | |
2318 pub = TREE_PUBLIC (decl); | |
2319 one = DECL_ONE_ONLY (decl); | |
2320 weak = (DECL_P (decl) | |
2321 && DECL_WEAK (decl) | |
2322 && !lookup_attribute ("weak_import", | |
2323 DECL_ATTRIBUTES (decl))); | |
2324 | |
2325 #ifdef DEBUG_DARWIN_MEM_ALLOCATORS | |
2326 fprintf (fp, "# albss: %s (%lld,%d) ro %d cst %d stat %d com %d" | |
2327 " pub %d weak %d one %d init %lx\n", | |
2328 name, (long long)size, (int)align, TREE_READONLY (decl), | |
2329 TREE_CONSTANT (decl), TREE_STATIC (decl), DECL_COMMON (decl), | |
2330 pub, weak, one, (unsigned long)DECL_INITIAL (decl)); | |
2331 #endif | |
2332 | |
2333 /* ObjC metadata can get put in BSS because varasm.c decides it's BSS | |
2334 before the target has a chance to comment. */ | |
2335 if ((meta = is_objc_metadata (decl))) | |
2336 { | |
2337 darwin_emit_objc_zeroed (fp, decl, name, size, DECL_ALIGN (decl), meta); | |
2338 return; | |
2339 } | |
2340 | |
2341 /* Check that any initializer is valid. */ | |
2342 gcc_assert ((DECL_INITIAL (decl) == NULL) | |
2343 || (DECL_INITIAL (decl) == error_mark_node) | |
2344 || initializer_zerop (DECL_INITIAL (decl))); | |
2345 | |
2346 gcc_assert (DECL_SECTION_NAME (decl) == NULL); | |
2347 gcc_assert (!DECL_COMMON (decl)); | |
2348 | |
2349 /* Pick up the correct alignment. */ | |
2350 if (!size || !align) | |
2351 align = DECL_ALIGN (decl); | |
2352 | |
2353 l2align = floor_log2 (align / BITS_PER_UNIT); | |
2354 gcc_assert (l2align <= L2_MAX_OFILE_ALIGNMENT); | |
2355 | |
2356 last_assemble_variable_decl = decl; | |
2357 | |
2358 /* We would rather not have to check this here - but it seems that we might | |
2359 be passed a decl that should be in coalesced space. */ | |
2360 if (one || weak) | |
2361 { | |
2362 /* Weak or COMDAT objects are put in mergeable sections. */ | |
2363 darwin_emit_weak_or_comdat (fp, decl, name, size, | |
2364 DECL_ALIGN (decl)); | |
2365 return; | |
2366 } | |
2367 | |
2368 /* If this is not public, then emit according to local rules. */ | |
2369 if (!pub) | |
2370 { | |
2371 darwin_emit_local_bss (fp, decl, name, size, l2align); | |
2372 return; | |
2373 } | |
2374 | |
2375 /* So we have a public symbol (small item fudge for Java, see above). */ | |
2376 if ((DARWIN_SECTION_ANCHORS && flag_section_anchors && size < BYTES_ZFILL) | |
2377 || (size && size <= 2)) | |
2378 { | |
2379 /* Put smaller objects in data, where the section anchors system can get | |
2380 them. However, if they are zero-sized punt them to yet a different | |
2381 section (that is not allowed to participate in anchoring). */ | |
2382 if (!size) | |
2383 { | |
2384 fputs ("\t.section\t__DATA,__zobj_data\n", fp); | |
2385 in_section = darwin_sections[zobj_data_section]; | |
2386 size = 1; | |
2387 } | |
2388 else | |
2389 { | |
2390 fputs ("\t.data\n", fp); | |
2391 in_section = data_section; | |
2392 } | |
2393 | |
2394 if (l2align) | |
2395 fprintf (fp, "\t.align\t%u\n", l2align); | |
2396 | |
2397 assemble_name (fp, name); | |
2398 fprintf (fp, ":\n\t.space\t"HOST_WIDE_INT_PRINT_UNSIGNED"\n", size); | |
2399 } | |
2400 else | |
2401 { | |
2402 char secnam[64]; | |
2403 unsigned int flags ; | |
2404 /* When we are on a non-section anchor target, we can get zero-sized | |
2405 items here. However, all we need to do is to bump them to one byte | |
2406 and the section alignment will take care of the rest. */ | |
2407 snprintf (secnam, 64, "__DATA,__%spu_bss%u", ((size)?"":"zo_"), l2align); | |
2408 | |
2409 /* We can't anchor in zerofill sections, because we can't switch | |
2410 to them and emit a label. */ | |
2411 flags = SECTION_BSS|SECTION_WRITE|SECTION_NO_ANCHOR; | |
2412 in_section = get_section (secnam, flags, NULL); | |
2413 fprintf (fp, "\t.zerofill %s,", secnam); | |
2414 assemble_name (fp, name); | |
2415 if (!size) | |
2416 size = 1; | |
2417 | |
2418 if (l2align) | |
2419 fprintf (fp, ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", size, l2align); | |
2420 else | |
2421 fprintf (fp, ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", size); | |
2422 } | |
2423 (* targetm.encode_section_info) (decl, DECL_RTL (decl), false); | |
2424 } | |
2425 | |
2426 /* Output a chunk of common, with alignment specified (where the target | |
2427 supports this). */ | |
2428 void | |
2429 darwin_asm_output_aligned_decl_common (FILE *fp, tree decl, const char *name, | |
2430 unsigned HOST_WIDE_INT size, | |
2431 unsigned int align) | |
2432 { | |
2433 unsigned int l2align; | |
2434 bool one, weak; | |
2435 tree meta; | |
2436 | |
2437 /* No corresponding var. */ | |
2438 if (decl==NULL) | |
2439 { | |
2440 #ifdef DEBUG_DARWIN_MEM_ALLOCATORS | |
2441 fprintf (fp, "# adcom: %s (%d,%d) decl=0x0\n", name, (int)size, (int)align); | |
2442 #endif | |
2443 darwin_emit_common (fp, name, size, align); | |
2444 return; | |
2445 } | |
2446 | |
2447 one = DECL_ONE_ONLY (decl); | |
2448 weak = (DECL_P (decl) | |
2449 && DECL_WEAK (decl) | |
2450 && !lookup_attribute ("weak_import", | |
2451 DECL_ATTRIBUTES (decl))); | |
2452 | |
2453 #ifdef DEBUG_DARWIN_MEM_ALLOCATORS | |
2454 fprintf (fp, "# adcom: %s (%lld,%d) ro %d cst %d stat %d com %d pub %d" | |
2455 " weak %d one %d init %lx\n", | |
2456 name, (long long)size, (int)align, TREE_READONLY (decl), | |
2457 TREE_CONSTANT (decl), TREE_STATIC (decl), DECL_COMMON (decl), | |
2458 TREE_PUBLIC (decl), weak, one, (unsigned long)DECL_INITIAL (decl)); | |
2459 #endif | |
2460 | |
2461 /* ObjC metadata can get put in BSS because varasm.c decides it's BSS | |
2462 before the target has a chance to comment. */ | |
2463 if ((meta = is_objc_metadata (decl))) | |
2464 { | |
2465 darwin_emit_objc_zeroed (fp, decl, name, size, DECL_ALIGN (decl), meta); | |
2466 return; | |
2467 } | |
2468 | |
2469 /* We shouldn't be messing with this if the decl has a section name. */ | |
2470 gcc_assert (DECL_SECTION_NAME (decl) == NULL); | |
2471 | |
2472 /* We would rather not have to check this here - but it seems that we might | |
2473 be passed a decl that should be in coalesced space. */ | |
2474 if (one || weak) | |
2475 { | |
2476 /* Weak or COMDAT objects are put in mergable sections. */ | |
2477 darwin_emit_weak_or_comdat (fp, decl, name, size, | |
2478 DECL_ALIGN (decl)); | |
2479 return; | |
2480 } | |
2481 | |
2482 /* We should only get here for DECL_COMMON, with a zero init (and, in | |
2483 principle, only for public symbols too - although we deal with local | |
2484 ones below). */ | |
2485 | |
2486 /* Check the initializer is OK. */ | |
2487 gcc_assert (DECL_COMMON (decl) | |
2488 && ((DECL_INITIAL (decl) == NULL) | |
2489 || (DECL_INITIAL (decl) == error_mark_node) | |
2490 || initializer_zerop (DECL_INITIAL (decl)))); | |
2491 | |
2492 last_assemble_variable_decl = decl; | |
2493 | |
2494 if (!size || !align) | |
2495 align = DECL_ALIGN (decl); | |
2496 | |
2497 l2align = floor_log2 (align / BITS_PER_UNIT); | |
2498 /* Check we aren't asking for more aligment than the platform allows. */ | |
2499 gcc_assert (l2align <= L2_MAX_OFILE_ALIGNMENT); | |
2500 | |
2501 if (TREE_PUBLIC (decl) != 0) | |
2502 darwin_emit_common (fp, name, size, align); | |
2503 else | |
2504 darwin_emit_local_bss (fp, decl, name, size, l2align); | |
2505 } | |
2506 | |
2507 /* Output a chunk of BSS with alignment specfied. */ | |
2508 void | |
2509 darwin_asm_output_aligned_decl_local (FILE *fp, tree decl, const char *name, | |
2510 unsigned HOST_WIDE_INT size, | |
2511 unsigned int align) | |
2512 { | |
2513 unsigned long l2align; | |
2514 bool one, weak; | |
2515 tree meta; | |
2516 | |
2517 one = DECL_ONE_ONLY (decl); | |
2518 weak = (DECL_P (decl) | |
2519 && DECL_WEAK (decl) | |
2520 && !lookup_attribute ("weak_import", | |
2521 DECL_ATTRIBUTES (decl))); | |
2522 | |
2523 #ifdef DEBUG_DARWIN_MEM_ALLOCATORS | |
2524 fprintf (fp, "# adloc: %s (%lld,%d) ro %d cst %d stat %d one %d pub %d" | |
2525 " weak %d init %lx\n", | |
2526 name, (long long)size, (int)align, TREE_READONLY (decl), | |
2527 TREE_CONSTANT (decl), TREE_STATIC (decl), one, TREE_PUBLIC (decl), | |
2528 weak , (unsigned long)DECL_INITIAL (decl)); | |
2529 #endif | |
2530 | |
2531 /* ObjC metadata can get put in BSS because varasm.c decides it's BSS | |
2532 before the target has a chance to comment. */ | |
2533 if ((meta = is_objc_metadata (decl))) | |
2534 { | |
2535 darwin_emit_objc_zeroed (fp, decl, name, size, DECL_ALIGN (decl), meta); | |
2536 return; | |
2537 } | |
2538 | |
2539 /* We shouldn't be messing with this if the decl has a section name. */ | |
2540 gcc_assert (DECL_SECTION_NAME (decl) == NULL); | |
2541 | |
2542 /* We would rather not have to check this here - but it seems that we might | |
2543 be passed a decl that should be in coalesced space. */ | |
2544 if (one || weak) | |
2545 { | |
2546 /* Weak or COMDAT objects are put in mergable sections. */ | |
2547 darwin_emit_weak_or_comdat (fp, decl, name, size, | |
2548 DECL_ALIGN (decl)); | |
2549 return; | |
2550 } | |
2551 | |
2552 /* .. and it should be suitable for placement in local mem. */ | |
2553 gcc_assert(!TREE_PUBLIC (decl) && !DECL_COMMON (decl)); | |
2554 /* .. and any initializer must be all-zero. */ | |
2555 gcc_assert ((DECL_INITIAL (decl) == NULL) | |
2556 || (DECL_INITIAL (decl) == error_mark_node) | |
2557 || initializer_zerop (DECL_INITIAL (decl))); | |
2558 | |
2559 last_assemble_variable_decl = decl; | |
2560 | |
2561 if (!size || !align) | |
2562 align = DECL_ALIGN (decl); | |
2563 | |
2564 l2align = floor_log2 (align / BITS_PER_UNIT); | |
2565 gcc_assert (l2align <= L2_MAX_OFILE_ALIGNMENT); | |
2566 | |
2567 darwin_emit_local_bss (fp, decl, name, size, l2align); | |
2568 } | |
2569 | |
1615 /* Emit an assembler directive to set visibility for a symbol. The | 2570 /* Emit an assembler directive to set visibility for a symbol. The |
1616 only supported visibilities are VISIBILITY_DEFAULT and | 2571 only supported visibilities are VISIBILITY_DEFAULT and |
1617 VISIBILITY_HIDDEN; the latter corresponds to Darwin's "private | 2572 VISIBILITY_HIDDEN; the latter corresponds to Darwin's "private |
1618 extern". There is no MACH-O equivalent of ELF's | 2573 extern". There is no MACH-O equivalent of ELF's |
1619 VISIBILITY_INTERNAL or VISIBILITY_PROTECTED. */ | 2574 VISIBILITY_INTERNAL or VISIBILITY_PROTECTED. */ |
1631 fputs ("\n", asm_out_file); | 2586 fputs ("\n", asm_out_file); |
1632 } | 2587 } |
1633 else | 2588 else |
1634 warning (OPT_Wattributes, "internal and protected visibility attributes " | 2589 warning (OPT_Wattributes, "internal and protected visibility attributes " |
1635 "not supported in this configuration; ignored"); | 2590 "not supported in this configuration; ignored"); |
2591 } | |
2592 | |
2593 /* VEC Used by darwin_asm_dwarf_section. | |
2594 Maybe a hash tab would be better here - but the intention is that this is | |
2595 a very short list (fewer than 16 items) and each entry should (ideally, | |
2596 eventually) only be presented once. | |
2597 | |
2598 A structure to hold a dwarf debug section used entry. */ | |
2599 | |
2600 typedef struct GTY(()) dwarf_sect_used_entry { | |
2601 const char *name; | |
2602 unsigned count; | |
2603 } | |
2604 dwarf_sect_used_entry; | |
2605 | |
2606 DEF_VEC_O(dwarf_sect_used_entry); | |
2607 DEF_VEC_ALLOC_O(dwarf_sect_used_entry, gc); | |
2608 | |
2609 /* A list of used __DWARF sections. */ | |
2610 static GTY (()) VEC (dwarf_sect_used_entry, gc) * dwarf_sect_names_table; | |
2611 | |
2612 /* This is called when we are asked to assemble a named section and the | |
2613 name begins with __DWARF,. We keep a list of the section names (without | |
2614 the __DWARF, prefix) and use this to emit our required start label on the | |
2615 first switch to each section. */ | |
2616 | |
2617 static void | |
2618 darwin_asm_dwarf_section (const char *name, unsigned int flags, | |
2619 tree ARG_UNUSED (decl)) | |
2620 { | |
2621 unsigned i; | |
2622 int namelen; | |
2623 const char * sname; | |
2624 dwarf_sect_used_entry *ref; | |
2625 bool found = false; | |
2626 gcc_assert ((flags & (SECTION_DEBUG | SECTION_NAMED)) | |
2627 == (SECTION_DEBUG | SECTION_NAMED)); | |
2628 /* We know that the name starts with __DWARF, */ | |
2629 sname = name + 8; | |
2630 namelen = strchr (sname, ',') - sname; | |
2631 gcc_assert (namelen); | |
2632 if (dwarf_sect_names_table == NULL) | |
2633 dwarf_sect_names_table = VEC_alloc (dwarf_sect_used_entry, gc, 16); | |
2634 else | |
2635 for (i = 0; | |
2636 VEC_iterate (dwarf_sect_used_entry, dwarf_sect_names_table, i, ref); | |
2637 i++) | |
2638 { | |
2639 if (!ref) | |
2640 break; | |
2641 if (!strcmp (ref->name, sname)) | |
2642 { | |
2643 found = true; | |
2644 ref->count++; | |
2645 break; | |
2646 } | |
2647 } | |
2648 | |
2649 fprintf (asm_out_file, "\t.section %s\n", name); | |
2650 if (!found) | |
2651 { | |
2652 dwarf_sect_used_entry e; | |
2653 fprintf (asm_out_file, "Lsection%.*s:\n", namelen, sname); | |
2654 e.count = 1; | |
2655 e.name = xstrdup (sname); | |
2656 VEC_safe_push (dwarf_sect_used_entry, gc, dwarf_sect_names_table, &e); | |
2657 } | |
1636 } | 2658 } |
1637 | 2659 |
1638 /* Output a difference of two labels that will be an assembly time | 2660 /* Output a difference of two labels that will be an assembly time |
1639 constant if the two labels are local. (.long lab1-lab2 will be | 2661 constant if the two labels are local. (.long lab1-lab2 will be |
1640 very different if lab1 is at the boundary between two sections; it | 2662 very different if lab1 is at the boundary between two sections; it |
1654 | 2676 |
1655 if (islocaldiff) | 2677 if (islocaldiff) |
1656 fprintf (file, "\t.set L$set$%d,", darwin_dwarf_label_counter); | 2678 fprintf (file, "\t.set L$set$%d,", darwin_dwarf_label_counter); |
1657 else | 2679 else |
1658 fprintf (file, "\t%s\t", directive); | 2680 fprintf (file, "\t%s\t", directive); |
2681 | |
1659 assemble_name_raw (file, lab1); | 2682 assemble_name_raw (file, lab1); |
1660 fprintf (file, "-"); | 2683 fprintf (file, "-"); |
1661 assemble_name_raw (file, lab2); | 2684 assemble_name_raw (file, lab2); |
1662 if (islocaldiff) | 2685 if (islocaldiff) |
1663 fprintf (file, "\n\t%s L$set$%d", directive, darwin_dwarf_label_counter++); | 2686 fprintf (file, "\n\t%s L$set$%d", directive, darwin_dwarf_label_counter++); |
1664 } | 2687 } |
1665 | 2688 |
1666 /* Output labels for the start of the DWARF sections if necessary. | 2689 /* Output an offset in a DWARF section on Darwin. On Darwin, DWARF section |
1667 Initialize the stuff we need for LTO long section names support. */ | 2690 offsets are not represented using relocs in .o files; either the |
2691 section never leaves the .o file, or the linker or other tool is | |
2692 responsible for parsing the DWARF and updating the offsets. */ | |
2693 | |
2694 void | |
2695 darwin_asm_output_dwarf_offset (FILE *file, int size, const char * lab, | |
2696 section *base) | |
2697 { | |
2698 char sname[64]; | |
2699 int namelen; | |
2700 | |
2701 gcc_assert (base->common.flags & SECTION_NAMED); | |
2702 gcc_assert (strncmp (base->named.name, "__DWARF,", 8) == 0); | |
2703 gcc_assert (strchr (base->named.name + 8, ',')); | |
2704 | |
2705 namelen = strchr (base->named.name + 8, ',') - (base->named.name + 8); | |
2706 sprintf (sname, "*Lsection%.*s", namelen, base->named.name + 8); | |
2707 darwin_asm_output_dwarf_delta (file, size, lab, sname); | |
2708 } | |
2709 | |
2710 /* Called from the within the TARGET_ASM_FILE_START for each target. | |
2711 Initialize the stuff we need for LTO long section names support. */ | |
2712 | |
1668 void | 2713 void |
1669 darwin_file_start (void) | 2714 darwin_file_start (void) |
1670 { | 2715 { |
1671 if (write_symbols == DWARF2_DEBUG) | |
1672 { | |
1673 static const char * const debugnames[] = | |
1674 { | |
1675 DEBUG_FRAME_SECTION, | |
1676 DEBUG_INFO_SECTION, | |
1677 DEBUG_ABBREV_SECTION, | |
1678 DEBUG_ARANGES_SECTION, | |
1679 DEBUG_MACINFO_SECTION, | |
1680 DEBUG_LINE_SECTION, | |
1681 DEBUG_LOC_SECTION, | |
1682 DEBUG_PUBNAMES_SECTION, | |
1683 DEBUG_PUBTYPES_SECTION, | |
1684 DEBUG_STR_SECTION, | |
1685 DEBUG_RANGES_SECTION | |
1686 }; | |
1687 size_t i; | |
1688 | |
1689 for (i = 0; i < ARRAY_SIZE (debugnames); i++) | |
1690 { | |
1691 int namelen; | |
1692 | |
1693 switch_to_section (get_section (debugnames[i], SECTION_DEBUG, NULL)); | |
1694 | |
1695 gcc_assert (strncmp (debugnames[i], "__DWARF,", 8) == 0); | |
1696 gcc_assert (strchr (debugnames[i] + 8, ',')); | |
1697 | |
1698 namelen = strchr (debugnames[i] + 8, ',') - (debugnames[i] + 8); | |
1699 fprintf (asm_out_file, "Lsection%.*s:\n", namelen, debugnames[i] + 8); | |
1700 } | |
1701 } | |
1702 | |
1703 /* We fill this obstack with the complete section text for the lto section | 2716 /* We fill this obstack with the complete section text for the lto section |
1704 names to write in darwin_file_end. */ | 2717 names to write in darwin_file_end. */ |
1705 obstack_init (<o_section_names_obstack); | 2718 obstack_init (<o_section_names_obstack); |
1706 lto_section_names_offset = 0; | 2719 lto_section_names_offset = 0; |
1707 } | 2720 } |
1708 | 2721 |
1709 /* Output an offset in a DWARF section on Darwin. On Darwin, DWARF section | 2722 /* Called for the TARGET_ASM_FILE_END hook. |
1710 offsets are not represented using relocs in .o files; either the | 2723 Emit the mach-o pic indirection data, the lto data and, finally a flag |
1711 section never leaves the .o file, or the linker or other tool is | 2724 to tell the linker that it can break the file object into sections and |
1712 responsible for parsing the DWARF and updating the offsets. */ | 2725 move those around for efficiency. */ |
1713 | |
1714 void | |
1715 darwin_asm_output_dwarf_offset (FILE *file, int size, const char * lab, | |
1716 section *base) | |
1717 { | |
1718 char sname[64]; | |
1719 int namelen; | |
1720 | |
1721 gcc_assert (base->common.flags & SECTION_NAMED); | |
1722 gcc_assert (strncmp (base->named.name, "__DWARF,", 8) == 0); | |
1723 gcc_assert (strchr (base->named.name + 8, ',')); | |
1724 | |
1725 namelen = strchr (base->named.name + 8, ',') - (base->named.name + 8); | |
1726 sprintf (sname, "*Lsection%.*s", namelen, base->named.name + 8); | |
1727 darwin_asm_output_dwarf_delta (file, size, lab, sname); | |
1728 } | |
1729 | 2726 |
1730 void | 2727 void |
1731 darwin_file_end (void) | 2728 darwin_file_end (void) |
1732 { | 2729 { |
1733 const char *lto_section_names; | 2730 const char *lto_section_names; |
1783 LTO_SEGMENT_NAME); | 2780 LTO_SEGMENT_NAME); |
1784 fprintf (asm_out_file, "%s\n", lto_section_names); | 2781 fprintf (asm_out_file, "%s\n", lto_section_names); |
1785 } | 2782 } |
1786 obstack_free (<o_section_names_obstack, NULL); | 2783 obstack_free (<o_section_names_obstack, NULL); |
1787 | 2784 |
1788 fprintf (asm_out_file, "\t.subsections_via_symbols\n"); | 2785 /* If we have section anchors, then we must prevent the linker from |
2786 re-arranging data. */ | |
2787 if (!DARWIN_SECTION_ANCHORS || !flag_section_anchors) | |
2788 fprintf (asm_out_file, "\t.subsections_via_symbols\n"); | |
1789 } | 2789 } |
1790 | 2790 |
1791 /* TODO: Add a language hook for identifying if a decl is a vtable. */ | 2791 /* TODO: Add a language hook for identifying if a decl is a vtable. */ |
1792 #define DARWIN_VTABLE_P(DECL) 0 | 2792 #define DARWIN_VTABLE_P(DECL) 0 |
1793 | 2793 |
1799 { | 2799 { |
1800 return default_binds_local_p_1 (decl, | 2800 return default_binds_local_p_1 (decl, |
1801 TARGET_KEXTABI && DARWIN_VTABLE_P (decl)); | 2801 TARGET_KEXTABI && DARWIN_VTABLE_P (decl)); |
1802 } | 2802 } |
1803 | 2803 |
1804 #if 0 | |
1805 /* See TARGET_ASM_OUTPUT_ANCHOR for why we can't do this yet. */ | |
1806 /* The Darwin's implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the | 2804 /* The Darwin's implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the |
1807 anchor relative to ".", the current section position. We cannot use | 2805 anchor relative to ".", the current section position. We cannot use |
1808 the default one because ASM_OUTPUT_DEF is wrong for Darwin. */ | 2806 the default one because ASM_OUTPUT_DEF is wrong for Darwin. */ |
1809 | |
1810 void | 2807 void |
1811 darwin_asm_output_anchor (rtx symbol) | 2808 darwin_asm_output_anchor (rtx symbol) |
1812 { | 2809 { |
1813 fprintf (asm_out_file, "\t.set\t"); | 2810 fprintf (asm_out_file, "\t.set\t"); |
1814 assemble_name (asm_out_file, XSTR (symbol, 0)); | 2811 assemble_name (asm_out_file, XSTR (symbol, 0)); |
1815 fprintf (asm_out_file, ", . + " HOST_WIDE_INT_PRINT_DEC "\n", | 2812 fprintf (asm_out_file, ", . + " HOST_WIDE_INT_PRINT_DEC "\n", |
1816 SYMBOL_REF_BLOCK_OFFSET (symbol)); | 2813 SYMBOL_REF_BLOCK_OFFSET (symbol)); |
1817 } | 2814 } |
1818 #endif | 2815 |
2816 /* Disable section anchoring on any section containing a zero-sized | |
2817 object. */ | |
2818 bool | |
2819 darwin_use_anchors_for_symbol_p (const_rtx symbol) | |
2820 { | |
2821 if (DARWIN_SECTION_ANCHORS && flag_section_anchors) | |
2822 { | |
2823 section *sect; | |
2824 /* If the section contains a zero-sized object it's ineligible. */ | |
2825 sect = SYMBOL_REF_BLOCK (symbol)->sect; | |
2826 /* This should have the effect of disabling anchors for vars that follow | |
2827 any zero-sized one, in a given section. */ | |
2828 if (sect->common.flags & SECTION_NO_ANCHOR) | |
2829 return false; | |
2830 | |
2831 /* Also check the normal reasons for suppressing. */ | |
2832 return default_use_anchors_for_symbol_p (symbol); | |
2833 } | |
2834 else | |
2835 return false; | |
2836 } | |
1819 | 2837 |
1820 /* Set the darwin specific attributes on TYPE. */ | 2838 /* Set the darwin specific attributes on TYPE. */ |
1821 void | 2839 void |
1822 darwin_set_default_type_attributes (tree type) | 2840 darwin_set_default_type_attributes (tree type) |
1823 { | 2841 { |
1836 } | 2854 } |
1837 | 2855 |
1838 void | 2856 void |
1839 darwin_override_options (void) | 2857 darwin_override_options (void) |
1840 { | 2858 { |
2859 /* Keep track of which (major) version we're generating code for. */ | |
2860 if (darwin_macosx_version_min) | |
2861 { | |
2862 if (strverscmp (darwin_macosx_version_min, "10.6") >= 0) | |
2863 generating_for_darwin_version = 10; | |
2864 else if (strverscmp (darwin_macosx_version_min, "10.5") >= 0) | |
2865 generating_for_darwin_version = 9; | |
2866 | |
2867 /* Earlier versions are not specifically accounted, until required. */ | |
2868 } | |
2869 | |
1841 /* Don't emit DWARF3/4 unless specifically selected. This is a | 2870 /* Don't emit DWARF3/4 unless specifically selected. This is a |
1842 workaround for tool bugs. */ | 2871 workaround for tool bugs. */ |
1843 if (dwarf_strict < 0) | 2872 if (!global_options_set.x_dwarf_strict) |
1844 dwarf_strict = 1; | 2873 dwarf_strict = 1; |
1845 | 2874 |
1846 /* Disable -freorder-blocks-and-partition for darwin_emit_unwind_label. */ | 2875 /* Do not allow unwind tables to be generated by default for m32. |
1847 if (flag_reorder_blocks_and_partition | 2876 fnon-call-exceptions will override this, regardless of what we do. */ |
1848 && (targetm.asm_out.unwind_label == darwin_emit_unwind_label)) | 2877 if (generating_for_darwin_version < 10 |
2878 && !global_options_set.x_flag_asynchronous_unwind_tables | |
2879 && !TARGET_64BIT) | |
2880 global_options.x_flag_asynchronous_unwind_tables = 0; | |
2881 | |
2882 /* Disable -freorder-blocks-and-partition when unwind tables are being | |
2883 emitted for Darwin < 9 (OSX 10.5). | |
2884 The strategy is, "Unless the User has specifically set/unset an unwind | |
2885 flag we will switch off -freorder-blocks-and-partition when unwind tables | |
2886 will be generated". If the User specifically sets flags... we assume | |
2887 (s)he knows why... */ | |
2888 if (generating_for_darwin_version < 9 | |
2889 && global_options_set.x_flag_reorder_blocks_and_partition | |
2890 && ((global_options.x_flag_exceptions /* User, c++, java */ | |
2891 && !global_options_set.x_flag_exceptions) /* User specified... */ | |
2892 || (global_options.x_flag_unwind_tables | |
2893 && !global_options_set.x_flag_unwind_tables) | |
2894 || (global_options.x_flag_non_call_exceptions | |
2895 && !global_options_set.x_flag_non_call_exceptions) | |
2896 || (global_options.x_flag_asynchronous_unwind_tables | |
2897 && !global_options_set.x_flag_asynchronous_unwind_tables))) | |
1849 { | 2898 { |
1850 inform (input_location, | 2899 inform (input_location, |
1851 "-freorder-blocks-and-partition does not work with exceptions " | 2900 "-freorder-blocks-and-partition does not work with exceptions " |
1852 "on this architecture"); | 2901 "on this architecture"); |
1853 flag_reorder_blocks_and_partition = 0; | 2902 flag_reorder_blocks_and_partition = 0; |
1854 flag_reorder_blocks = 1; | 2903 flag_reorder_blocks = 1; |
1855 } | 2904 } |
1856 | 2905 |
1857 if (flag_mkernel || flag_apple_kext) | 2906 if (flag_mkernel || flag_apple_kext) |
1864 | 2913 |
1865 /* No EH in kexts. */ | 2914 /* No EH in kexts. */ |
1866 flag_exceptions = 0; | 2915 flag_exceptions = 0; |
1867 /* No -fnon-call-exceptions data in kexts. */ | 2916 /* No -fnon-call-exceptions data in kexts. */ |
1868 flag_non_call_exceptions = 0; | 2917 flag_non_call_exceptions = 0; |
1869 } | 2918 /* so no tables either.. */ |
2919 flag_unwind_tables = 0; | |
2920 flag_asynchronous_unwind_tables = 0; | |
2921 /* We still need to emit branch islands for kernel context. */ | |
2922 darwin_emit_branch_islands = true; | |
2923 } | |
2924 | |
1870 if (flag_var_tracking | 2925 if (flag_var_tracking |
1871 && strverscmp (darwin_macosx_version_min, "10.5") >= 0 | 2926 && generating_for_darwin_version >= 9 |
1872 && debug_info_level >= DINFO_LEVEL_NORMAL | 2927 && (flag_gtoggle ? (debug_info_level == DINFO_LEVEL_NONE) |
1873 && debug_hooks->var_location != do_nothing_debug_hooks.var_location) | 2928 : (debug_info_level >= DINFO_LEVEL_NORMAL)) |
2929 && write_symbols == DWARF2_DEBUG) | |
1874 flag_var_tracking_uninit = 1; | 2930 flag_var_tracking_uninit = 1; |
2931 | |
2932 if (MACHO_DYNAMIC_NO_PIC_P) | |
2933 { | |
2934 if (flag_pic) | |
2935 warning (0, "-mdynamic-no-pic overrides -fpic or -fPIC"); | |
2936 flag_pic = 0; | |
2937 } | |
2938 else if (flag_pic == 1) | |
2939 { | |
2940 /* Darwin's -fpic is -fPIC. */ | |
2941 flag_pic = 2; | |
2942 } | |
2943 | |
2944 /* It is assumed that branch island stubs are needed for earlier systems. */ | |
2945 if (generating_for_darwin_version < 9) | |
2946 darwin_emit_branch_islands = true; | |
2947 else | |
2948 emit_aligned_common = true; /* Later systems can support aligned common. */ | |
2949 | |
2950 /* The c_dialect...() macros are not available to us here. */ | |
2951 darwin_running_cxx = (strstr (lang_hooks.name, "C++") != 0); | |
1875 } | 2952 } |
1876 | 2953 |
1877 /* Add $LDBL128 suffix to long double builtins. */ | 2954 /* Add $LDBL128 suffix to long double builtins. */ |
1878 | 2955 |
1879 static void | 2956 static void |
1914 #undef PATCH_BUILTIN | 2991 #undef PATCH_BUILTIN |
1915 #undef PATCH_BUILTIN_NO64 | 2992 #undef PATCH_BUILTIN_NO64 |
1916 #undef PATCH_BUILTIN_VARIADIC | 2993 #undef PATCH_BUILTIN_VARIADIC |
1917 } | 2994 } |
1918 | 2995 |
2996 /* CFStrings implementation. */ | |
2997 static GTY(()) tree cfstring_class_reference = NULL_TREE; | |
2998 static GTY(()) tree cfstring_type_node = NULL_TREE; | |
2999 static GTY(()) tree ccfstring_type_node = NULL_TREE; | |
3000 static GTY(()) tree pccfstring_type_node = NULL_TREE; | |
3001 static GTY(()) tree pcint_type_node = NULL_TREE; | |
3002 static GTY(()) tree pcchar_type_node = NULL_TREE; | |
3003 | |
3004 static enum built_in_function darwin_builtin_cfstring; | |
3005 | |
3006 /* Store all constructed constant CFStrings in a hash table so that | |
3007 they get uniqued properly. */ | |
3008 | |
3009 typedef struct GTY (()) cfstring_descriptor { | |
3010 /* The string literal. */ | |
3011 tree literal; | |
3012 /* The resulting constant CFString. */ | |
3013 tree constructor; | |
3014 } cfstring_descriptor; | |
3015 | |
3016 static GTY ((param_is (struct cfstring_descriptor))) htab_t cfstring_htab; | |
3017 | |
3018 static hashval_t cfstring_hash (const void *); | |
3019 static int cfstring_eq (const void *, const void *); | |
3020 | |
3021 static tree | |
3022 add_builtin_field_decl (tree type, const char *name, tree **chain) | |
3023 { | |
3024 tree field = build_decl (BUILTINS_LOCATION, FIELD_DECL, | |
3025 get_identifier (name), type); | |
3026 | |
3027 if (*chain != NULL) | |
3028 **chain = field; | |
3029 *chain = &DECL_CHAIN (field); | |
3030 | |
3031 return field; | |
3032 } | |
3033 | |
3034 tree | |
3035 darwin_init_cfstring_builtins (unsigned builtin_cfstring) | |
3036 { | |
3037 tree cfsfun, fields, pccfstring_ftype_pcchar; | |
3038 tree *chain = NULL; | |
3039 | |
3040 darwin_builtin_cfstring = | |
3041 (enum built_in_function) builtin_cfstring; | |
3042 | |
3043 /* struct __builtin_CFString { | |
3044 const int *isa; (will point at | |
3045 int flags; __CFConstantStringClassReference) | |
3046 const char *str; | |
3047 long length; | |
3048 }; */ | |
3049 | |
3050 pcint_type_node = build_pointer_type | |
3051 (build_qualified_type (integer_type_node, TYPE_QUAL_CONST)); | |
3052 | |
3053 pcchar_type_node = build_pointer_type | |
3054 (build_qualified_type (char_type_node, TYPE_QUAL_CONST)); | |
3055 | |
3056 cfstring_type_node = (*lang_hooks.types.make_type) (RECORD_TYPE); | |
3057 | |
3058 /* Have to build backwards for finish struct. */ | |
3059 fields = add_builtin_field_decl (long_integer_type_node, "length", &chain); | |
3060 add_builtin_field_decl (pcchar_type_node, "str", &chain); | |
3061 add_builtin_field_decl (integer_type_node, "flags", &chain); | |
3062 add_builtin_field_decl (pcint_type_node, "isa", &chain); | |
3063 finish_builtin_struct (cfstring_type_node, "__builtin_CFString", | |
3064 fields, NULL_TREE); | |
3065 | |
3066 /* const struct __builtin_CFstring * | |
3067 __builtin___CFStringMakeConstantString (const char *); */ | |
3068 | |
3069 ccfstring_type_node = build_qualified_type | |
3070 (cfstring_type_node, TYPE_QUAL_CONST); | |
3071 pccfstring_type_node = build_pointer_type (ccfstring_type_node); | |
3072 pccfstring_ftype_pcchar = build_function_type_list | |
3073 (pccfstring_type_node, pcchar_type_node, NULL_TREE); | |
3074 | |
3075 cfsfun = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, | |
3076 get_identifier ("__builtin___CFStringMakeConstantString"), | |
3077 pccfstring_ftype_pcchar); | |
3078 | |
3079 TREE_PUBLIC (cfsfun) = 1; | |
3080 DECL_EXTERNAL (cfsfun) = 1; | |
3081 DECL_ARTIFICIAL (cfsfun) = 1; | |
3082 /* Make a lang-specific section - dup_lang_specific_decl makes a new node | |
3083 in place of the existing, which may be NULL. */ | |
3084 DECL_LANG_SPECIFIC (cfsfun) = NULL; | |
3085 (*lang_hooks.dup_lang_specific_decl) (cfsfun); | |
3086 DECL_BUILT_IN_CLASS (cfsfun) = BUILT_IN_MD; | |
3087 DECL_FUNCTION_CODE (cfsfun) = darwin_builtin_cfstring; | |
3088 lang_hooks.builtin_function (cfsfun); | |
3089 | |
3090 /* extern int __CFConstantStringClassReference[]; */ | |
3091 cfstring_class_reference = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
3092 get_identifier ("__CFConstantStringClassReference"), | |
3093 build_array_type (integer_type_node, NULL_TREE)); | |
3094 | |
3095 TREE_PUBLIC (cfstring_class_reference) = 1; | |
3096 DECL_ARTIFICIAL (cfstring_class_reference) = 1; | |
3097 (*lang_hooks.decls.pushdecl) (cfstring_class_reference); | |
3098 DECL_EXTERNAL (cfstring_class_reference) = 1; | |
3099 rest_of_decl_compilation (cfstring_class_reference, 0, 0); | |
3100 | |
3101 /* Initialize the hash table used to hold the constant CFString objects. */ | |
3102 cfstring_htab = htab_create_ggc (31, cfstring_hash, cfstring_eq, NULL); | |
3103 | |
3104 return cfstring_type_node; | |
3105 } | |
3106 | |
3107 tree | |
3108 darwin_fold_builtin (tree fndecl, int n_args, tree *argp, | |
3109 bool ARG_UNUSED (ignore)) | |
3110 { | |
3111 unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
3112 | |
3113 if (fcode == darwin_builtin_cfstring) | |
3114 { | |
3115 if (!darwin_constant_cfstrings) | |
3116 { | |
3117 error ("built-in function %qD requires the" | |
3118 " %<-mconstant-cfstrings%> flag", fndecl); | |
3119 return error_mark_node; | |
3120 } | |
3121 | |
3122 if (n_args != 1) | |
3123 { | |
3124 error ("built-in function %qD takes one argument only", fndecl); | |
3125 return error_mark_node; | |
3126 } | |
3127 | |
3128 return darwin_build_constant_cfstring (*argp); | |
3129 } | |
3130 | |
3131 return NULL_TREE; | |
3132 } | |
3133 | |
3134 void | |
3135 darwin_rename_builtins (void) | |
3136 { | |
3137 /* The system ___divdc3 routine in libSystem on darwin10 is not | |
3138 accurate to 1ulp, ours is, so we avoid ever using the system name | |
3139 for this routine and instead install a non-conflicting name that | |
3140 is accurate. | |
3141 | |
3142 When -ffast-math or -funsafe-math-optimizations is given, we can | |
3143 use the faster version. */ | |
3144 if (!flag_unsafe_math_optimizations) | |
3145 { | |
3146 int dcode = (BUILT_IN_COMPLEX_DIV_MIN | |
3147 + DCmode - MIN_MODE_COMPLEX_FLOAT); | |
3148 tree fn = built_in_decls[dcode]; | |
3149 /* Fortran and c call TARGET_INIT_BUILTINS and | |
3150 TARGET_INIT_LIBFUNCS at different times, so we have to put a | |
3151 call into each to ensure that at least one of them is called | |
3152 after build_common_builtin_nodes. A better fix is to add a | |
3153 new hook to run after build_common_builtin_nodes runs. */ | |
3154 if (fn) | |
3155 set_user_assembler_name (fn, "___ieee_divdc3"); | |
3156 fn = implicit_built_in_decls[dcode]; | |
3157 if (fn) | |
3158 set_user_assembler_name (fn, "___ieee_divdc3"); | |
3159 } | |
3160 } | |
3161 | |
3162 static hashval_t | |
3163 cfstring_hash (const void *ptr) | |
3164 { | |
3165 tree str = ((const struct cfstring_descriptor *)ptr)->literal; | |
3166 const unsigned char *p = (const unsigned char *) TREE_STRING_POINTER (str); | |
3167 int i, len = TREE_STRING_LENGTH (str); | |
3168 hashval_t h = len; | |
3169 | |
3170 for (i = 0; i < len; i++) | |
3171 h = ((h * 613) + p[i]); | |
3172 | |
3173 return h; | |
3174 } | |
3175 | |
3176 static int | |
3177 cfstring_eq (const void *ptr1, const void *ptr2) | |
3178 { | |
3179 tree str1 = ((const struct cfstring_descriptor *)ptr1)->literal; | |
3180 tree str2 = ((const struct cfstring_descriptor *)ptr2)->literal; | |
3181 int len1 = TREE_STRING_LENGTH (str1); | |
3182 | |
3183 return (len1 == TREE_STRING_LENGTH (str2) | |
3184 && !memcmp (TREE_STRING_POINTER (str1), TREE_STRING_POINTER (str2), | |
3185 len1)); | |
3186 } | |
3187 | |
3188 tree | |
3189 darwin_build_constant_cfstring (tree str) | |
3190 { | |
3191 struct cfstring_descriptor *desc, key; | |
3192 void **loc; | |
3193 tree addr; | |
3194 | |
3195 if (!str) | |
3196 { | |
3197 error ("CFString literal is missing"); | |
3198 return error_mark_node; | |
3199 } | |
3200 | |
3201 STRIP_NOPS (str); | |
3202 | |
3203 if (TREE_CODE (str) == ADDR_EXPR) | |
3204 str = TREE_OPERAND (str, 0); | |
3205 | |
3206 if (TREE_CODE (str) != STRING_CST) | |
3207 { | |
3208 error ("CFString literal expression is not a string constant"); | |
3209 return error_mark_node; | |
3210 } | |
3211 | |
3212 /* Perhaps we already constructed a constant CFString just like this one? */ | |
3213 key.literal = str; | |
3214 loc = htab_find_slot (cfstring_htab, &key, INSERT); | |
3215 desc = (struct cfstring_descriptor *) *loc; | |
3216 | |
3217 if (!desc) | |
3218 { | |
3219 tree var, constructor, field; | |
3220 VEC(constructor_elt,gc) *v = NULL; | |
3221 int length = TREE_STRING_LENGTH (str) - 1; | |
3222 | |
3223 if (darwin_warn_nonportable_cfstrings) | |
3224 { | |
3225 const char *s = TREE_STRING_POINTER (str); | |
3226 int l = 0; | |
3227 | |
3228 for (l = 0; l < length; l++) | |
3229 if (!s[l] || !isascii (s[l])) | |
3230 { | |
3231 warning (darwin_warn_nonportable_cfstrings, "%s in CFString literal", | |
3232 s[l] ? "non-ASCII character" : "embedded NUL"); | |
3233 break; | |
3234 } | |
3235 } | |
3236 | |
3237 *loc = desc = ggc_alloc_cleared_cfstring_descriptor (); | |
3238 desc->literal = str; | |
3239 | |
3240 /* isa *. */ | |
3241 field = TYPE_FIELDS (ccfstring_type_node); | |
3242 CONSTRUCTOR_APPEND_ELT(v, NULL_TREE, | |
3243 build1 (ADDR_EXPR, TREE_TYPE (field), | |
3244 cfstring_class_reference)); | |
3245 /* flags */ | |
3246 field = DECL_CHAIN (field); | |
3247 CONSTRUCTOR_APPEND_ELT(v, NULL_TREE, | |
3248 build_int_cst (TREE_TYPE (field), 0x000007c8)); | |
3249 /* string *. */ | |
3250 field = DECL_CHAIN (field); | |
3251 CONSTRUCTOR_APPEND_ELT(v, NULL_TREE, | |
3252 build1 (ADDR_EXPR, TREE_TYPE (field), str)); | |
3253 /* length */ | |
3254 field = DECL_CHAIN (field); | |
3255 CONSTRUCTOR_APPEND_ELT(v, NULL_TREE, | |
3256 build_int_cst (TREE_TYPE (field), length)); | |
3257 | |
3258 constructor = build_constructor (ccfstring_type_node, v); | |
3259 TREE_READONLY (constructor) = 1; | |
3260 TREE_CONSTANT (constructor) = 1; | |
3261 TREE_STATIC (constructor) = 1; | |
3262 | |
3263 /* Fromage: The C++ flavor of 'build_unary_op' expects constructor nodes | |
3264 to have the TREE_HAS_CONSTRUCTOR (...) bit set. However, this file is | |
3265 being built without any knowledge of C++ tree accessors; hence, we shall | |
3266 use the generic accessor that TREE_HAS_CONSTRUCTOR actually maps to! */ | |
3267 if (darwin_running_cxx) | |
3268 TREE_LANG_FLAG_4 (constructor) = 1; /* TREE_HAS_CONSTRUCTOR */ | |
3269 | |
3270 /* Create an anonymous global variable for this CFString. */ | |
3271 var = build_decl (input_location, CONST_DECL, | |
3272 NULL, TREE_TYPE (constructor)); | |
3273 DECL_ARTIFICIAL (var) = 1; | |
3274 TREE_STATIC (var) = 1; | |
3275 DECL_INITIAL (var) = constructor; | |
3276 /* FIXME: This should use a translation_unit_decl to indicate file scope. */ | |
3277 DECL_CONTEXT (var) = NULL_TREE; | |
3278 desc->constructor = var; | |
3279 } | |
3280 | |
3281 addr = build1 (ADDR_EXPR, pccfstring_type_node, desc->constructor); | |
3282 TREE_CONSTANT (addr) = 1; | |
3283 | |
3284 return addr; | |
3285 } | |
3286 | |
3287 bool | |
3288 darwin_cfstring_p (tree str) | |
3289 { | |
3290 struct cfstring_descriptor key; | |
3291 void **loc; | |
3292 | |
3293 if (!str) | |
3294 return false; | |
3295 | |
3296 STRIP_NOPS (str); | |
3297 | |
3298 if (TREE_CODE (str) == ADDR_EXPR) | |
3299 str = TREE_OPERAND (str, 0); | |
3300 | |
3301 if (TREE_CODE (str) != STRING_CST) | |
3302 return false; | |
3303 | |
3304 key.literal = str; | |
3305 loc = htab_find_slot (cfstring_htab, &key, NO_INSERT); | |
3306 | |
3307 if (loc) | |
3308 return true; | |
3309 | |
3310 return false; | |
3311 } | |
3312 | |
3313 void | |
3314 darwin_enter_string_into_cfstring_table (tree str) | |
3315 { | |
3316 struct cfstring_descriptor key; | |
3317 void **loc; | |
3318 | |
3319 key.literal = str; | |
3320 loc = htab_find_slot (cfstring_htab, &key, INSERT); | |
3321 | |
3322 if (!*loc) | |
3323 { | |
3324 *loc = ggc_alloc_cleared_cfstring_descriptor (); | |
3325 ((struct cfstring_descriptor *)*loc)->literal = str; | |
3326 } | |
3327 } | |
3328 | |
3329 /* Choose named function section based on its frequency. */ | |
3330 | |
3331 section * | |
3332 darwin_function_section (tree decl, enum node_frequency freq, | |
3333 bool startup, bool exit) | |
3334 { | |
3335 /* Decide if we need to put this in a coalescable section. */ | |
3336 bool weak = (decl | |
3337 && DECL_WEAK (decl) | |
3338 && (!DECL_ATTRIBUTES (decl) | |
3339 || !lookup_attribute ("weak_import", | |
3340 DECL_ATTRIBUTES (decl)))); | |
3341 | |
3342 /* If there is a specified section name, we should not be trying to | |
3343 override. */ | |
3344 if (decl && DECL_SECTION_NAME (decl) != NULL_TREE) | |
3345 return get_named_section (decl, NULL, 0); | |
3346 | |
3347 /* Default when there is no function re-ordering. */ | |
3348 if (!flag_reorder_functions) | |
3349 return (weak) | |
3350 ? darwin_sections[text_coal_section] | |
3351 : text_section; | |
3352 | |
3353 /* Startup code should go to startup subsection unless it is | |
3354 unlikely executed (this happens especially with function splitting | |
3355 where we can split away unnecesary parts of static constructors). */ | |
3356 if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED) | |
3357 return (weak) | |
3358 ? darwin_sections[text_startup_coal_section] | |
3359 : darwin_sections[text_startup_section]; | |
3360 | |
3361 /* Similarly for exit. */ | |
3362 if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED) | |
3363 return (weak) | |
3364 ? darwin_sections[text_exit_coal_section] | |
3365 : darwin_sections[text_exit_section]; | |
3366 | |
3367 /* Group cold functions together, similarly for hot code. */ | |
3368 switch (freq) | |
3369 { | |
3370 case NODE_FREQUENCY_UNLIKELY_EXECUTED: | |
3371 return (weak) | |
3372 ? darwin_sections[text_cold_coal_section] | |
3373 : darwin_sections[text_cold_section]; | |
3374 break; | |
3375 case NODE_FREQUENCY_HOT: | |
3376 return (weak) | |
3377 ? darwin_sections[text_hot_coal_section] | |
3378 : darwin_sections[text_hot_section]; | |
3379 break; | |
3380 default: | |
3381 return (weak) | |
3382 ? darwin_sections[text_coal_section] | |
3383 : text_section; | |
3384 break; | |
3385 } | |
3386 } | |
3387 | |
3388 /* When a function is partitioned between sections, we need to insert a label | |
3389 at the start of each new chunk - so that it may become a valid 'atom' for | |
3390 eh and debug purposes. Without this the linker will emit warnings if one | |
3391 tries to add line location information (since the switched fragment will | |
3392 be anonymous). */ | |
3393 | |
3394 void | |
3395 darwin_function_switched_text_sections (FILE *fp, tree decl, bool new_is_cold) | |
3396 { | |
3397 char buf[128]; | |
3398 snprintf (buf, 128, "%s%s",new_is_cold?"__cold_sect_of_":"__hot_sect_of_", | |
3399 IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3400 /* Make sure we pick up all the relevant quotes etc. */ | |
3401 assemble_name_raw (fp, (const char *) buf); | |
3402 fputs (":\n", fp); | |
3403 } | |
1919 | 3404 |
1920 #include "gt-darwin.h" | 3405 #include "gt-darwin.h" |