1 /* Functions for generic Darwin as target machine for GNU C compiler.
2 Copyright (C) 1989-2013 Free Software Foundation, Inc.
3 Contributed by Apple Computer Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "hard-reg-set.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-flags.h"
32 #include "insn-attr.h"
39 #include "langhooks.h"
42 #include "diagnostic-core.h"
48 #include "lto-streamer.h"
50 /* Darwin supports a feature called fix-and-continue, which is used
51 for rapid turn around debugging. When code is compiled with the
52 -mfix-and-continue flag, two changes are made to the generated code
53 that allow the system to do things that it would normally not be
54 able to do easily. These changes allow gdb to load in
55 recompilation of a translation unit that has been changed into a
56 running program and replace existing functions and methods of that
57 translation unit with versions of those functions and methods
58 from the newly compiled translation unit. The new functions access
59 the existing static symbols from the old translation unit, if the
60 symbol existed in the unit to be replaced, and from the new
61 translation unit, otherwise.
63 The changes are to insert 5 nops at the beginning of all functions
64 and to use indirection to get at static symbols. The 5 nops
65 are required by consumers of the generated code. Currently, gdb
66 uses this to patch in a jump to the overriding function, this
67 allows all uses of the old name to forward to the replacement,
68 including existing function pointers and virtual methods. See
69 rs6000_emit_prologue for the code that handles the nop insertions.
71 The added indirection allows gdb to redirect accesses to static
72 symbols from the newly loaded translation unit to the existing
73 symbol, if any. @code{static} symbols are special and are handled by
74 setting the second word in the .non_lazy_symbol_pointer data
75 structure to symbol. See indirect_data for the code that handles
76 the extra indirection, and machopic_output_indirection and its use
77 of MACHO_SYMBOL_STATIC for the code that handles @code{static}
78 symbol indirection. */
80 /* For darwin >= 9 (OSX 10.5) the linker is capable of making the necessary
81 branch islands and we no longer need to emit darwin stubs.
82 However, if we are generating code for earlier systems (or for use in the
83 kernel) the stubs might still be required, and this will be set true. */
84 int darwin_emit_branch_islands
= false;
86 typedef struct GTY(()) ctor_record
{
88 int priority
; /* constructor priority */
89 int position
; /* original position */
92 static GTY(()) vec
<ctor_record
, va_gc
> *ctors
= NULL
;
94 /* A flag to determine whether we are running c++ or obj-c++. This has to be
95 settable from non-c-family contexts too (i.e. we can't use the c_dialect_
97 int darwin_running_cxx
;
99 /* Some code-gen now depends on OS major version numbers (at least). */
100 int generating_for_darwin_version
;
103 section
* darwin_sections
[NUM_DARWIN_SECTIONS
];
105 /* While we transition to using in-tests instead of ifdef'd code. */
107 #define HAVE_lo_sum 0
108 #define gen_macho_high(a,b) (a)
109 #define gen_macho_low(a,b,c) (a)
112 /* True if we're setting __attribute__ ((ms_struct)). */
113 int darwin_ms_struct
= false;
115 /* Earlier versions of Darwin as do not recognize an alignment field in
116 .comm directives, this should be set for versions that allow it. */
117 int emit_aligned_common
= false;
119 /* A get_unnamed_section callback used to switch to an ObjC section.
120 DIRECTIVE is as for output_section_asm_op. */
123 output_objc_section_asm_op (const void *directive
)
125 static bool been_here
= false;
127 /* The NeXT ObjC Runtime requires these sections to be present and in
128 order in the object. The code below implements this by emitting
129 a section header for each ObjC section the first time that an ObjC
130 section is requested. */
133 section
*saved_in_section
= in_section
;
134 static const enum darwin_section_enum tomark
[] =
136 /* written, cold -> hot */
137 objc_cat_cls_meth_section
,
138 objc_cat_inst_meth_section
,
139 objc_string_object_section
,
140 objc_constant_string_object_section
,
141 objc_selector_refs_section
,
142 objc_selector_fixup_section
,
143 objc_cls_refs_section
,
145 objc_meta_class_section
,
146 /* shared, hot -> cold */
147 objc_cls_meth_section
,
148 objc_inst_meth_section
,
149 objc_protocol_section
,
150 objc_class_names_section
,
151 objc_meth_var_types_section
,
152 objc_meth_var_names_section
,
153 objc_category_section
,
154 objc_class_vars_section
,
155 objc_instance_vars_section
,
156 objc_module_info_section
,
157 objc_symbols_section
,
160 static const enum darwin_section_enum tomarkv1
[] =
162 objc1_protocol_ext_section
,
163 objc1_class_ext_section
,
164 objc1_prop_list_section
167 static const enum darwin_section_enum tomarkv2
[] =
169 objc2_message_refs_section
,
170 objc2_classdefs_section
,
171 objc2_metadata_section
,
172 objc2_classrefs_section
,
173 objc2_classlist_section
,
174 objc2_categorylist_section
,
175 objc2_selector_refs_section
,
176 objc2_nonlazy_class_section
,
177 objc2_nonlazy_category_section
,
178 objc2_protocollist_section
,
179 objc2_protocolrefs_section
,
180 objc2_super_classrefs_section
,
181 objc2_image_info_section
,
182 objc2_constant_string_object_section
187 if (flag_objc_abi
< 2)
189 for (i
= 0; i
< ARRAY_SIZE (tomark
); i
++)
190 switch_to_section (darwin_sections
[tomark
[i
]]);
191 if (flag_objc_abi
== 1)
192 for (i
= 0; i
< ARRAY_SIZE (tomarkv1
); i
++)
193 switch_to_section (darwin_sections
[tomarkv1
[i
]]);
196 for (i
= 0; i
< ARRAY_SIZE (tomarkv2
); i
++)
197 switch_to_section (darwin_sections
[tomarkv2
[i
]]);
198 /* Make sure we don't get varasm.c out of sync with us. */
199 switch_to_section (saved_in_section
);
201 output_section_asm_op (directive
);
205 /* Private flag applied to disable section-anchors in a particular section. */
206 #define SECTION_NO_ANCHOR SECTION_MACH_DEP
209 /* Implement TARGET_ASM_INIT_SECTIONS. */
212 darwin_init_sections (void)
214 #define DEF_SECTION(NAME, FLAGS, DIRECTIVE, OBJC) \
215 darwin_sections[NAME] = \
216 get_unnamed_section (FLAGS, (OBJC \
217 ? output_objc_section_asm_op \
218 : output_section_asm_op), \
220 #include "config/darwin-sections.def"
223 readonly_data_section
= darwin_sections
[const_section
];
224 exception_section
= darwin_sections
[darwin_exception_section
];
225 eh_frame_section
= darwin_sections
[darwin_eh_frame_section
];
229 name_needs_quotes (const char *name
)
232 while ((c
= *name
++) != '\0')
234 && c
!= '.' && c
!= '$' && c
!= '_' )
239 /* Return true if SYM_REF can be used without an indirection. */
241 machopic_symbol_defined_p (rtx sym_ref
)
243 if (SYMBOL_REF_FLAGS (sym_ref
) & MACHO_SYMBOL_FLAG_DEFINED
)
246 /* If a symbol references local and is not an extern to this
247 file, then the symbol might be able to declared as defined. */
248 if (SYMBOL_REF_LOCAL_P (sym_ref
) && ! SYMBOL_REF_EXTERNAL_P (sym_ref
))
250 /* If the symbol references a variable and the variable is a
251 common symbol, then this symbol is not defined. */
252 if (SYMBOL_REF_FLAGS (sym_ref
) & MACHO_SYMBOL_FLAG_VARIABLE
)
254 tree decl
= SYMBOL_REF_DECL (sym_ref
);
257 if (DECL_COMMON (decl
))
265 /* This module assumes that (const (symbol_ref "foo")) is a legal pic
266 reference, which will not be changed. */
268 enum machopic_addr_class
269 machopic_classify_symbol (rtx sym_ref
)
273 function_p
= SYMBOL_REF_FUNCTION_P (sym_ref
);
274 if (machopic_symbol_defined_p (sym_ref
))
276 ? MACHOPIC_DEFINED_FUNCTION
: MACHOPIC_DEFINED_DATA
);
279 ? MACHOPIC_UNDEFINED_FUNCTION
: MACHOPIC_UNDEFINED_DATA
);
282 #ifndef TARGET_FIX_AND_CONTINUE
283 #define TARGET_FIX_AND_CONTINUE 0
286 /* Indicate when fix-and-continue style code generation is being used
287 and when a reference to data should be indirected so that it can be
288 rebound in a new translation unit to reference the original instance
289 of that data. Symbol names that are for code generation local to
290 the translation unit are bound to the new translation unit;
291 currently this means symbols that begin with L or _OBJC_;
292 otherwise, we indicate that an indirect reference should be made to
293 permit the runtime to rebind new instances of the translation unit
294 to the original instance of the data. */
297 indirect_data (rtx sym_ref
)
302 /* If we aren't generating fix-and-continue code, don't do anything
304 if (TARGET_FIX_AND_CONTINUE
== 0)
307 /* Otherwise, all symbol except symbols that begin with L or _OBJC_
308 are indirected. Symbols that begin with L and _OBJC_ are always
309 bound to the current translation unit as they are used for
310 generated local data of the translation unit. */
312 name
= XSTR (sym_ref
, 0);
314 lprefix
= (((name
[0] == '*' || name
[0] == '&')
315 && (name
[1] == 'L' || (name
[1] == '"' && name
[2] == 'L')))
316 || (strncmp (name
, "_OBJC_", 6) == 0));
322 machopic_data_defined_p (rtx sym_ref
)
324 if (indirect_data (sym_ref
))
327 switch (machopic_classify_symbol (sym_ref
))
329 case MACHOPIC_DEFINED_DATA
:
330 case MACHOPIC_DEFINED_FUNCTION
:
338 machopic_define_symbol (rtx mem
)
342 gcc_assert (GET_CODE (mem
) == MEM
);
343 sym_ref
= XEXP (mem
, 0);
344 SYMBOL_REF_FLAGS (sym_ref
) |= MACHO_SYMBOL_FLAG_DEFINED
;
347 /* Return either ORIG or:
349 (const:P (unspec:P [ORIG] UNSPEC_MACHOPIC_OFFSET))
351 depending on MACHO_DYNAMIC_NO_PIC_P. */
353 machopic_gen_offset (rtx orig
)
355 if (MACHO_DYNAMIC_NO_PIC_P
)
359 /* Play games to avoid marking the function as needing pic if we
360 are being called as part of the cost-estimation process. */
361 if (current_ir_type () != IR_GIMPLE
|| currently_expanding_to_rtl
)
362 crtl
->uses_pic_offset_table
= 1;
363 orig
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, orig
),
364 UNSPEC_MACHOPIC_OFFSET
);
365 return gen_rtx_CONST (Pmode
, orig
);
369 static GTY(()) const char * function_base_func_name
;
370 static GTY(()) int current_pic_label_num
;
373 machopic_output_function_base_name (FILE *file
)
375 const char *current_name
;
377 /* If dynamic-no-pic is on, we should not get here. */
378 gcc_assert (!MACHO_DYNAMIC_NO_PIC_P
);
379 /* When we are generating _get_pc thunks within stubs, there is no current
381 if (current_function_decl
)
384 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl
));
385 if (function_base_func_name
!= current_name
)
387 ++current_pic_label_num
;
388 function_base_func_name
= current_name
;
393 ++current_pic_label_num
;
394 function_base_func_name
= "L_machopic_stub_dummy";
396 fprintf (file
, "L%011d$pb", current_pic_label_num
);
399 /* The suffix attached to non-lazy pointer symbols. */
400 #define NON_LAZY_POINTER_SUFFIX "$non_lazy_ptr"
401 /* The suffix attached to stub symbols. */
402 #define STUB_SUFFIX "$stub"
404 typedef struct GTY (()) machopic_indirection
406 /* The SYMBOL_REF for the entity referenced. */
408 /* The name of the stub or non-lazy pointer. */
409 const char * ptr_name
;
410 /* True iff this entry is for a stub (as opposed to a non-lazy
413 /* True iff this stub or pointer pointer has been referenced. */
415 } machopic_indirection
;
417 /* A table mapping stub names and non-lazy pointer names to
418 SYMBOL_REFs for the stubbed-to and pointed-to entities. */
420 static GTY ((param_is (struct machopic_indirection
))) htab_t
421 machopic_indirections
;
423 /* Return a hash value for a SLOT in the indirections hash table. */
426 machopic_indirection_hash (const void *slot
)
428 const machopic_indirection
*p
= (const machopic_indirection
*) slot
;
429 return htab_hash_string (p
->ptr_name
);
432 /* Returns true if the KEY is the same as that associated with
436 machopic_indirection_eq (const void *slot
, const void *key
)
438 return strcmp (((const machopic_indirection
*) slot
)->ptr_name
,
439 (const char *) key
) == 0;
442 /* Return the name of the non-lazy pointer (if STUB_P is false) or
443 stub (if STUB_B is true) corresponding to the given name. */
446 machopic_indirection_name (rtx sym_ref
, bool stub_p
)
449 const char *name
= XSTR (sym_ref
, 0);
450 size_t namelen
= strlen (name
);
451 machopic_indirection
*p
;
455 const char *prefix
= user_label_prefix
;
456 const char *quote
= "";
459 id
= maybe_get_identifier (name
);
464 while (IDENTIFIER_TRANSPARENT_ALIAS (id
))
465 id
= TREE_CHAIN (id
);
468 name
= IDENTIFIER_POINTER (id
);
469 namelen
= strlen (name
);
480 needs_quotes
= name_needs_quotes (name
);
487 suffix
= STUB_SUFFIX
;
489 suffix
= NON_LAZY_POINTER_SUFFIX
;
491 buffer
= XALLOCAVEC (char, strlen ("&L")
498 /* Construct the name of the non-lazy pointer or stub. */
499 sprintf (buffer
, "&%sL%s%s%s%s", quote
, prefix
, name
, suffix
, quote
);
501 if (!machopic_indirections
)
502 machopic_indirections
= htab_create_ggc (37,
503 machopic_indirection_hash
,
504 machopic_indirection_eq
,
507 slot
= htab_find_slot_with_hash (machopic_indirections
, buffer
,
508 htab_hash_string (buffer
), INSERT
);
511 p
= (machopic_indirection
*) *slot
;
515 p
= ggc_alloc_machopic_indirection ();
517 p
->ptr_name
= xstrdup (buffer
);
526 /* Return the name of the stub for the mcount function. */
529 machopic_mcount_stub_name (void)
531 rtx symbol
= gen_rtx_SYMBOL_REF (Pmode
, "*mcount");
532 return machopic_indirection_name (symbol
, /*stub_p=*/true);
535 /* If NAME is the name of a stub or a non-lazy pointer , mark the stub
536 or non-lazy pointer as used -- and mark the object to which the
537 pointer/stub refers as used as well, since the pointer/stub will
538 emit a reference to it. */
541 machopic_validate_stub_or_non_lazy_ptr (const char *name
)
543 machopic_indirection
*p
;
545 p
= ((machopic_indirection
*)
546 (htab_find_with_hash (machopic_indirections
, name
,
547 htab_hash_string (name
))));
550 const char *real_name
;
555 /* Do what output_addr_const will do when we actually call it. */
556 if (SYMBOL_REF_DECL (p
->symbol
))
557 mark_decl_referenced (SYMBOL_REF_DECL (p
->symbol
));
559 real_name
= targetm
.strip_name_encoding (XSTR (p
->symbol
, 0));
561 id
= maybe_get_identifier (real_name
);
563 mark_referenced (id
);
567 /* Transform ORIG, which may be any data source, to the corresponding
568 source using indirections. */
571 machopic_indirect_data_reference (rtx orig
, rtx reg
)
575 if (! MACHOPIC_INDIRECT
)
578 if (GET_CODE (orig
) == SYMBOL_REF
)
580 int defined
= machopic_data_defined_p (orig
);
582 if (defined
&& MACHO_DYNAMIC_NO_PIC_P
)
586 /* Create a new register for CSE opportunities. */
587 rtx hi_reg
= (!can_create_pseudo_p () ? reg
: gen_reg_rtx (Pmode
));
588 emit_insn (gen_macho_high (hi_reg
, orig
));
589 emit_insn (gen_macho_low (reg
, hi_reg
, orig
));
595 /* some other cpu -- writeme! */
601 if (DARWIN_PPC
|| HAVE_lo_sum
)
602 offset
= machopic_gen_offset (orig
);
606 rtx hi_sum_reg
= (!can_create_pseudo_p ()
608 : gen_reg_rtx (Pmode
));
612 emit_insn (gen_rtx_SET (Pmode
, hi_sum_reg
,
613 gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
,
614 gen_rtx_HIGH (Pmode
, offset
))));
615 emit_insn (gen_rtx_SET (Pmode
, reg
,
616 gen_rtx_LO_SUM (Pmode
, hi_sum_reg
,
617 copy_rtx (offset
))));
621 else if (HAVE_lo_sum
)
625 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
626 gen_rtx_HIGH (Pmode
, offset
)));
627 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
628 gen_rtx_LO_SUM (Pmode
, reg
,
629 copy_rtx (offset
))));
630 emit_use (pic_offset_table_rtx
);
632 orig
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, reg
);
637 ptr_ref
= (gen_rtx_SYMBOL_REF
639 machopic_indirection_name (orig
, /*stub_p=*/false)));
641 SYMBOL_REF_DATA (ptr_ref
) = SYMBOL_REF_DATA (orig
);
643 ptr_ref
= gen_const_mem (Pmode
, ptr_ref
);
644 machopic_define_symbol (ptr_ref
);
648 && MACHO_DYNAMIC_NO_PIC_P
)
650 emit_insn (gen_rtx_SET (Pmode
, reg
, ptr_ref
));
656 else if (GET_CODE (orig
) == CONST
)
658 /* If "(const (plus ...", walk the PLUS and return that result.
659 PLUS processing (below) will restore the "(const ..." if
661 if (GET_CODE (XEXP (orig
, 0)) == PLUS
)
662 return machopic_indirect_data_reference (XEXP (orig
, 0), reg
);
666 else if (GET_CODE (orig
) == MEM
)
669 machopic_indirect_data_reference (XEXP (orig
, 0), reg
);
672 else if (GET_CODE (orig
) == PLUS
)
675 /* When the target is i386, this code prevents crashes due to the
676 compiler's ignorance on how to move the PIC base register to
677 other registers. (The reload phase sometimes introduces such
679 if (GET_CODE (XEXP (orig
, 0)) == REG
680 && REGNO (XEXP (orig
, 0)) == PIC_OFFSET_TABLE_REGNUM
681 /* Prevent the same register from being erroneously used
682 as both the base and index registers. */
683 && (DARWIN_X86
&& (GET_CODE (XEXP (orig
, 1)) == CONST
))
686 emit_move_insn (reg
, XEXP (orig
, 0));
687 XEXP (ptr_ref
, 0) = reg
;
691 /* Legitimize both operands of the PLUS. */
692 base
= machopic_indirect_data_reference (XEXP (orig
, 0), reg
);
693 orig
= machopic_indirect_data_reference (XEXP (orig
, 1),
694 (base
== reg
? 0 : reg
));
695 if (MACHOPIC_INDIRECT
&& (GET_CODE (orig
) == CONST_INT
))
696 result
= plus_constant (Pmode
, base
, INTVAL (orig
));
698 result
= gen_rtx_PLUS (Pmode
, base
, orig
);
700 if (MACHOPIC_JUST_INDIRECT
&& GET_CODE (base
) == MEM
)
704 emit_move_insn (reg
, result
);
709 result
= force_reg (GET_MODE (result
), result
);
718 /* Transform TARGET (a MEM), which is a function call target, to the
719 corresponding symbol_stub if necessary. Return a new MEM. */
722 machopic_indirect_call_target (rtx target
)
724 if (! darwin_emit_branch_islands
)
727 if (GET_CODE (target
) != MEM
)
730 if (MACHOPIC_INDIRECT
731 && GET_CODE (XEXP (target
, 0)) == SYMBOL_REF
732 && !(SYMBOL_REF_FLAGS (XEXP (target
, 0))
733 & MACHO_SYMBOL_FLAG_DEFINED
))
735 rtx sym_ref
= XEXP (target
, 0);
736 const char *stub_name
= machopic_indirection_name (sym_ref
,
738 enum machine_mode mode
= GET_MODE (sym_ref
);
740 XEXP (target
, 0) = gen_rtx_SYMBOL_REF (mode
, stub_name
);
741 SYMBOL_REF_DATA (XEXP (target
, 0)) = SYMBOL_REF_DATA (sym_ref
);
742 MEM_READONLY_P (target
) = 1;
743 MEM_NOTRAP_P (target
) = 1;
750 machopic_legitimize_pic_address (rtx orig
, enum machine_mode mode
, rtx reg
)
754 if (! MACHOPIC_INDIRECT
)
757 /* First handle a simple SYMBOL_REF or LABEL_REF */
758 if (GET_CODE (orig
) == LABEL_REF
759 || (GET_CODE (orig
) == SYMBOL_REF
762 /* addr(foo) = &func+(foo-func) */
763 orig
= machopic_indirect_data_reference (orig
, reg
);
765 if (GET_CODE (orig
) == PLUS
766 && GET_CODE (XEXP (orig
, 0)) == REG
)
769 return force_reg (mode
, orig
);
771 emit_move_insn (reg
, orig
);
775 if (GET_CODE (orig
) == MEM
)
779 gcc_assert (!reload_in_progress
);
780 reg
= gen_reg_rtx (Pmode
);
784 if (MACHO_DYNAMIC_NO_PIC_P
785 && (GET_CODE (XEXP (orig
, 0)) == SYMBOL_REF
786 || GET_CODE (XEXP (orig
, 0)) == LABEL_REF
))
788 #if defined (TARGET_TOC) /* ppc */
789 rtx temp_reg
= (!can_create_pseudo_p ()
791 gen_reg_rtx (Pmode
));
792 rtx asym
= XEXP (orig
, 0);
795 emit_insn (gen_macho_high (temp_reg
, asym
));
796 mem
= gen_const_mem (GET_MODE (orig
),
797 gen_rtx_LO_SUM (Pmode
, temp_reg
,
799 emit_insn (gen_rtx_SET (VOIDmode
, reg
, mem
));
801 /* Some other CPU -- WriteMe! but right now there are no other
802 platforms that can use dynamic-no-pic */
808 if (GET_CODE (XEXP (orig
, 0)) == SYMBOL_REF
809 || GET_CODE (XEXP (orig
, 0)) == LABEL_REF
)
811 rtx offset
= machopic_gen_offset (XEXP (orig
, 0));
812 #if defined (TARGET_TOC) /* i.e., PowerPC */
813 /* Generating a new reg may expose opportunities for
814 common subexpression elimination. */
815 rtx hi_sum_reg
= (!can_create_pseudo_p ()
817 : gen_reg_rtx (Pmode
));
822 sum
= gen_rtx_HIGH (Pmode
, offset
);
823 if (! MACHO_DYNAMIC_NO_PIC_P
)
824 sum
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, sum
);
826 emit_insn (gen_rtx_SET (Pmode
, hi_sum_reg
, sum
));
828 mem
= gen_const_mem (GET_MODE (orig
),
829 gen_rtx_LO_SUM (Pmode
,
832 insn
= emit_insn (gen_rtx_SET (VOIDmode
, reg
, mem
));
833 set_unique_reg_note (insn
, REG_EQUAL
, pic_ref
);
837 emit_use (gen_rtx_REG (Pmode
, PIC_OFFSET_TABLE_REGNUM
));
839 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
841 gen_rtx_CONST (Pmode
,
843 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
844 gen_rtx_LO_SUM (Pmode
, reg
,
845 gen_rtx_CONST (Pmode
,
846 copy_rtx (offset
)))));
847 pic_ref
= gen_rtx_PLUS (Pmode
,
848 pic_offset_table_rtx
, reg
);
852 #endif /* HAVE_lo_sum */
854 rtx pic
= pic_offset_table_rtx
;
855 if (GET_CODE (pic
) != REG
)
857 emit_move_insn (reg
, pic
);
861 emit_use (gen_rtx_REG (Pmode
, PIC_OFFSET_TABLE_REGNUM
));
864 if (reload_in_progress
)
865 df_set_regs_ever_live (REGNO (pic
), true);
866 pic_ref
= gen_rtx_PLUS (Pmode
, pic
,
867 machopic_gen_offset (XEXP (orig
, 0)));
870 #if !defined (TARGET_TOC)
871 emit_move_insn (reg
, pic_ref
);
872 pic_ref
= gen_const_mem (GET_MODE (orig
), reg
);
879 if (GET_CODE (orig
) == SYMBOL_REF
880 || GET_CODE (orig
) == LABEL_REF
)
882 rtx offset
= machopic_gen_offset (orig
);
883 #if defined (TARGET_TOC) /* i.e., PowerPC */
888 gcc_assert (!reload_in_progress
);
889 reg
= gen_reg_rtx (Pmode
);
894 emit_insn (gen_rtx_SET (Pmode
, hi_sum_reg
,
895 (MACHO_DYNAMIC_NO_PIC_P
)
896 ? gen_rtx_HIGH (Pmode
, offset
)
897 : gen_rtx_PLUS (Pmode
,
898 pic_offset_table_rtx
,
901 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
902 gen_rtx_LO_SUM (Pmode
,
904 copy_rtx (offset
))));
907 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
908 gen_rtx_HIGH (Pmode
, offset
)));
909 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
910 gen_rtx_LO_SUM (Pmode
, reg
,
911 copy_rtx (offset
))));
912 pic_ref
= gen_rtx_PLUS (Pmode
,
913 pic_offset_table_rtx
, reg
);
917 #endif /* HAVE_lo_sum */
920 || GET_CODE (orig
) == SUBREG
)
926 rtx pic
= pic_offset_table_rtx
;
927 if (GET_CODE (pic
) != REG
)
929 emit_move_insn (reg
, pic
);
933 emit_use (pic_offset_table_rtx
);
935 if (reload_in_progress
)
936 df_set_regs_ever_live (REGNO (pic
), true);
937 pic_ref
= gen_rtx_PLUS (Pmode
,
939 machopic_gen_offset (orig
));
944 if (GET_CODE (pic_ref
) != REG
)
948 emit_move_insn (reg
, pic_ref
);
953 return force_reg (mode
, pic_ref
);
962 else if (GET_CODE (orig
) == SYMBOL_REF
)
965 else if (GET_CODE (orig
) == PLUS
966 && (GET_CODE (XEXP (orig
, 0)) == MEM
967 || GET_CODE (XEXP (orig
, 0)) == SYMBOL_REF
968 || GET_CODE (XEXP (orig
, 0)) == LABEL_REF
)
969 && XEXP (orig
, 0) != pic_offset_table_rtx
970 && GET_CODE (XEXP (orig
, 1)) != REG
)
974 int is_complex
= (GET_CODE (XEXP (orig
, 0)) == MEM
);
976 base
= machopic_legitimize_pic_address (XEXP (orig
, 0), Pmode
, reg
);
977 orig
= machopic_legitimize_pic_address (XEXP (orig
, 1),
978 Pmode
, (base
== reg
? 0 : reg
));
979 if (GET_CODE (orig
) == CONST_INT
)
981 pic_ref
= plus_constant (Pmode
, base
, INTVAL (orig
));
985 pic_ref
= gen_rtx_PLUS (Pmode
, base
, orig
);
987 if (reg
&& is_complex
)
989 emit_move_insn (reg
, pic_ref
);
992 /* Likewise, should we set special REG_NOTEs here? */
995 else if (GET_CODE (orig
) == CONST
)
997 return machopic_legitimize_pic_address (XEXP (orig
, 0), Pmode
, reg
);
1000 else if (GET_CODE (orig
) == MEM
1001 && GET_CODE (XEXP (orig
, 0)) == SYMBOL_REF
)
1003 rtx addr
= machopic_legitimize_pic_address (XEXP (orig
, 0), Pmode
, reg
);
1004 addr
= replace_equiv_address (orig
, addr
);
1005 emit_move_insn (reg
, addr
);
1012 /* Output the stub or non-lazy pointer in *SLOT, if it has been used.
1013 DATA is the FILE* for assembly output. Called from
1017 machopic_output_indirection (void **slot
, void *data
)
1019 machopic_indirection
*p
= *((machopic_indirection
**) slot
);
1020 FILE *asm_out_file
= (FILE *) data
;
1022 const char *sym_name
;
1023 const char *ptr_name
;
1029 sym_name
= XSTR (symbol
, 0);
1030 ptr_name
= p
->ptr_name
;
1038 id
= maybe_get_identifier (sym_name
);
1043 while (IDENTIFIER_TRANSPARENT_ALIAS (id
))
1044 id
= TREE_CHAIN (id
);
1046 sym_name
= IDENTIFIER_POINTER (id
);
1049 sym
= XALLOCAVEC (char, strlen (sym_name
) + 2);
1050 if (sym_name
[0] == '*' || sym_name
[0] == '&')
1051 strcpy (sym
, sym_name
+ 1);
1052 else if (sym_name
[0] == '-' || sym_name
[0] == '+')
1053 strcpy (sym
, sym_name
);
1055 sprintf (sym
, "%s%s", user_label_prefix
, sym_name
);
1057 stub
= XALLOCAVEC (char, strlen (ptr_name
) + 2);
1058 if (ptr_name
[0] == '*' || ptr_name
[0] == '&')
1059 strcpy (stub
, ptr_name
+ 1);
1061 sprintf (stub
, "%s%s", user_label_prefix
, ptr_name
);
1063 machopic_output_stub (asm_out_file
, sym
, stub
);
1065 else if (! indirect_data (symbol
)
1066 && (machopic_symbol_defined_p (symbol
)
1067 || SYMBOL_REF_LOCAL_P (symbol
)))
1069 switch_to_section (data_section
);
1070 assemble_align (GET_MODE_ALIGNMENT (Pmode
));
1071 assemble_label (asm_out_file
, ptr_name
);
1072 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, sym_name
),
1073 GET_MODE_SIZE (Pmode
),
1074 GET_MODE_ALIGNMENT (Pmode
), 1);
1078 rtx init
= const0_rtx
;
1080 switch_to_section (darwin_sections
[machopic_nl_symbol_ptr_section
]);
1082 /* Mach-O symbols are passed around in code through indirect
1083 references and the original symbol_ref hasn't passed through
1084 the generic handling and reference-catching in
1085 output_operand, so we need to manually mark weak references
1087 if (SYMBOL_REF_WEAK (symbol
))
1089 tree decl
= SYMBOL_REF_DECL (symbol
);
1090 gcc_assert (DECL_P (decl
));
1092 if (decl
!= NULL_TREE
1093 && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
)
1094 /* Handle only actual external-only definitions, not
1095 e.g. extern inline code or variables for which
1096 storage has been allocated. */
1097 && !TREE_STATIC (decl
))
1099 fputs ("\t.weak_reference ", asm_out_file
);
1100 assemble_name (asm_out_file
, sym_name
);
1101 fputc ('\n', asm_out_file
);
1105 assemble_name (asm_out_file
, ptr_name
);
1106 fprintf (asm_out_file
, ":\n");
1108 fprintf (asm_out_file
, "\t.indirect_symbol ");
1109 assemble_name (asm_out_file
, sym_name
);
1110 fprintf (asm_out_file
, "\n");
1112 /* Variables that are marked with MACHO_SYMBOL_STATIC need to
1113 have their symbol name instead of 0 in the second entry of
1114 the non-lazy symbol pointer data structure when they are
1115 defined. This allows the runtime to rebind newer instances
1116 of the translation unit with the original instance of the
1119 if ((SYMBOL_REF_FLAGS (symbol
) & MACHO_SYMBOL_STATIC
)
1120 && machopic_symbol_defined_p (symbol
))
1121 init
= gen_rtx_SYMBOL_REF (Pmode
, sym_name
);
1123 assemble_integer (init
, GET_MODE_SIZE (Pmode
),
1124 GET_MODE_ALIGNMENT (Pmode
), 1);
1131 machopic_finish (FILE *asm_out_file
)
1133 if (machopic_indirections
)
1134 htab_traverse_noresize (machopic_indirections
,
1135 machopic_output_indirection
,
1140 machopic_operand_p (rtx op
)
1142 if (MACHOPIC_JUST_INDIRECT
)
1143 return (GET_CODE (op
) == SYMBOL_REF
1144 && machopic_symbol_defined_p (op
));
1146 return (GET_CODE (op
) == CONST
1147 && GET_CODE (XEXP (op
, 0)) == UNSPEC
1148 && XINT (XEXP (op
, 0), 1) == UNSPEC_MACHOPIC_OFFSET
);
1151 /* This function records whether a given name corresponds to a defined
1152 or undefined function or variable, for machopic_classify_ident to
1156 darwin_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
1160 /* Do the standard encoding things first. */
1161 default_encode_section_info (decl
, rtl
, first
);
1163 if (TREE_CODE (decl
) != FUNCTION_DECL
&& TREE_CODE (decl
) != VAR_DECL
)
1166 sym_ref
= XEXP (rtl
, 0);
1167 if (TREE_CODE (decl
) == VAR_DECL
)
1168 SYMBOL_REF_FLAGS (sym_ref
) |= MACHO_SYMBOL_FLAG_VARIABLE
;
1170 if (!DECL_EXTERNAL (decl
)
1171 && (!TREE_PUBLIC (decl
) || !DECL_WEAK (decl
))
1172 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))
1173 && ((TREE_STATIC (decl
)
1174 && (!DECL_COMMON (decl
) || !TREE_PUBLIC (decl
)))
1175 || (!DECL_COMMON (decl
) && DECL_INITIAL (decl
)
1176 && DECL_INITIAL (decl
) != error_mark_node
)))
1177 SYMBOL_REF_FLAGS (sym_ref
) |= MACHO_SYMBOL_FLAG_DEFINED
;
1179 if (! TREE_PUBLIC (decl
))
1180 SYMBOL_REF_FLAGS (sym_ref
) |= MACHO_SYMBOL_STATIC
;
1184 darwin_mark_decl_preserved (const char *name
)
1186 fprintf (asm_out_file
, "\t.no_dead_strip ");
1187 assemble_name (asm_out_file
, name
);
1188 fputc ('\n', asm_out_file
);
1192 darwin_rodata_section (int weak
, bool zsize
)
1195 ? darwin_sections
[const_coal_section
]
1196 : (zsize
? darwin_sections
[zobj_const_section
]
1197 : darwin_sections
[const_section
]));
1201 darwin_mergeable_string_section (tree exp
,
1202 unsigned HOST_WIDE_INT align
)
1204 /* Darwin's ld expects to see non-writable string literals in the .cstring
1205 section. Later versions of ld check and complain when CFStrings are
1206 enabled. Therefore we shall force the strings into .cstring since we
1207 don't support writable ones anyway. */
1208 if ((darwin_constant_cfstrings
|| flag_merge_constants
)
1209 && TREE_CODE (exp
) == STRING_CST
1210 && TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1212 && (int_size_in_bytes (TREE_TYPE (exp
))
1213 == TREE_STRING_LENGTH (exp
))
1214 && ((size_t) TREE_STRING_LENGTH (exp
)
1215 == strlen (TREE_STRING_POINTER (exp
)) + 1))
1216 return darwin_sections
[cstring_section
];
1218 if (DARWIN_SECTION_ANCHORS
&& flag_section_anchors
1219 && TREE_CODE (exp
) == STRING_CST
1220 && TREE_STRING_LENGTH (exp
) == 0)
1221 return darwin_sections
[zobj_const_section
];
1223 return readonly_data_section
;
1226 #ifndef HAVE_GAS_LITERAL16
1227 #define HAVE_GAS_LITERAL16 0
1231 darwin_mergeable_constant_section (tree exp
,
1232 unsigned HOST_WIDE_INT align
,
1235 enum machine_mode mode
= DECL_MODE (exp
);
1236 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
1238 if (DARWIN_SECTION_ANCHORS
1239 && flag_section_anchors
1241 return darwin_sections
[zobj_const_section
];
1243 if (flag_merge_constants
1246 && modesize
<= align
1249 && (align
& (align
-1)) == 0)
1251 tree size
= TYPE_SIZE_UNIT (TREE_TYPE (exp
));
1253 if (TREE_CODE (size
) == INTEGER_CST
1254 && TREE_INT_CST_LOW (size
) == 4
1255 && TREE_INT_CST_HIGH (size
) == 0)
1256 return darwin_sections
[literal4_section
];
1257 else if (TREE_CODE (size
) == INTEGER_CST
1258 && TREE_INT_CST_LOW (size
) == 8
1259 && TREE_INT_CST_HIGH (size
) == 0)
1260 return darwin_sections
[literal8_section
];
1261 else if (HAVE_GAS_LITERAL16
1263 && TREE_CODE (size
) == INTEGER_CST
1264 && TREE_INT_CST_LOW (size
) == 16
1265 && TREE_INT_CST_HIGH (size
) == 0)
1266 return darwin_sections
[literal16_section
];
1268 return readonly_data_section
;
1271 return readonly_data_section
;
1275 darwin_tm_clone_table_section (void)
1277 return get_named_section (NULL
,
1278 "__DATA,__tm_clone_table,regular,no_dead_strip",
1283 machopic_reloc_rw_mask (void)
1285 return MACHOPIC_INDIRECT
? 3 : 0;
1288 /* We have to deal with ObjC/C++ metadata section placement in the common
1289 code, since it will also be called from LTO.
1291 Return metadata attributes, if present (searching for ABI=2 first)
1292 Return NULL_TREE if no such attributes are found. */
1295 is_objc_metadata (tree decl
)
1298 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
1299 && DECL_ATTRIBUTES (decl
))
1301 tree meta
= lookup_attribute ("OBJC2META", DECL_ATTRIBUTES (decl
));
1304 meta
= lookup_attribute ("OBJC1META", DECL_ATTRIBUTES (decl
));
1311 /* Return the section required for Objective C ABI 2 metadata. */
1313 darwin_objc2_section (tree decl ATTRIBUTE_UNUSED
, tree meta
, section
* base
)
1316 tree ident
= TREE_VALUE (meta
);
1317 gcc_assert (TREE_CODE (ident
) == IDENTIFIER_NODE
);
1318 p
= IDENTIFIER_POINTER (ident
);
1320 /* If we are in LTO, then we don't know the state of flag_next_runtime
1321 or flag_objc_abi when the code was generated. We set these from the
1322 meta-data - which is needed to deal with const string constructors. */
1324 flag_next_runtime
= 1;
1327 if (base
== data_section
)
1328 base
= darwin_sections
[objc2_metadata_section
];
1330 /* Most of the OBJC2 META-data end up in the base section, so check it
1332 if (!strncmp (p
, "V2_BASE", 7))
1334 else if (!strncmp (p
, "V2_STRG", 7))
1335 return darwin_sections
[cstring_section
];
1337 else if (!strncmp (p
, "G2_META", 7) || !strncmp (p
, "G2_CLAS", 7))
1338 return darwin_sections
[objc2_classdefs_section
];
1339 else if (!strncmp (p
, "V2_MREF", 7))
1340 return darwin_sections
[objc2_message_refs_section
];
1341 else if (!strncmp (p
, "V2_CLRF", 7))
1342 return darwin_sections
[objc2_classrefs_section
];
1343 else if (!strncmp (p
, "V2_SURF", 7))
1344 return darwin_sections
[objc2_super_classrefs_section
];
1345 else if (!strncmp (p
, "V2_NLCL", 7))
1346 return darwin_sections
[objc2_nonlazy_class_section
];
1347 else if (!strncmp (p
, "V2_CLAB", 7))
1348 return darwin_sections
[objc2_classlist_section
];
1349 else if (!strncmp (p
, "V2_SRFS", 7))
1350 return darwin_sections
[objc2_selector_refs_section
];
1351 else if (!strncmp (p
, "V2_NLCA", 7))
1352 return darwin_sections
[objc2_nonlazy_category_section
];
1353 else if (!strncmp (p
, "V2_CALA", 7))
1354 return darwin_sections
[objc2_categorylist_section
];
1356 else if (!strncmp (p
, "V2_PLST", 7))
1357 return darwin_sections
[objc2_protocollist_section
];
1358 else if (!strncmp (p
, "V2_PRFS", 7))
1359 return darwin_sections
[objc2_protocolrefs_section
];
1361 else if (!strncmp (p
, "V2_INFO", 7))
1362 return darwin_sections
[objc2_image_info_section
];
1364 else if (!strncmp (p
, "V2_EHTY", 7))
1365 return darwin_sections
[data_coal_section
];
1367 else if (!strncmp (p
, "V2_CSTR", 7))
1368 return darwin_sections
[objc2_constant_string_object_section
];
1370 /* Not recognized, default. */
1374 /* Return the section required for Objective C ABI 0/1 metadata. */
1376 darwin_objc1_section (tree decl ATTRIBUTE_UNUSED
, tree meta
, section
* base
)
1379 tree ident
= TREE_VALUE (meta
);
1380 gcc_assert (TREE_CODE (ident
) == IDENTIFIER_NODE
);
1381 p
= IDENTIFIER_POINTER (ident
);
1383 /* If we are in LTO, then we don't know the state of flag_next_runtime
1384 or flag_objc_abi when the code was generated. We set these from the
1385 meta-data - which is needed to deal with const string constructors. */
1386 flag_next_runtime
= 1;
1387 if (!global_options_set
.x_flag_objc_abi
)
1390 /* String sections first, cos there are lots of strings. */
1391 if (!strncmp (p
, "V1_STRG", 7))
1392 return darwin_sections
[cstring_section
];
1393 else if (!strncmp (p
, "V1_CLSN", 7))
1394 return darwin_sections
[objc_class_names_section
];
1395 else if (!strncmp (p
, "V1_METN", 7))
1396 return darwin_sections
[objc_meth_var_names_section
];
1397 else if (!strncmp (p
, "V1_METT", 7))
1398 return darwin_sections
[objc_meth_var_types_section
];
1400 else if (!strncmp (p
, "V1_CLAS", 7))
1401 return darwin_sections
[objc_class_section
];
1402 else if (!strncmp (p
, "V1_META", 7))
1403 return darwin_sections
[objc_meta_class_section
];
1404 else if (!strncmp (p
, "V1_CATG", 7))
1405 return darwin_sections
[objc_category_section
];
1406 else if (!strncmp (p
, "V1_PROT", 7))
1407 return darwin_sections
[objc_protocol_section
];
1409 else if (!strncmp (p
, "V1_CLCV", 7))
1410 return darwin_sections
[objc_class_vars_section
];
1411 else if (!strncmp (p
, "V1_CLIV", 7))
1412 return darwin_sections
[objc_instance_vars_section
];
1414 else if (!strncmp (p
, "V1_CLCM", 7))
1415 return darwin_sections
[objc_cls_meth_section
];
1416 else if (!strncmp (p
, "V1_CLIM", 7))
1417 return darwin_sections
[objc_inst_meth_section
];
1418 else if (!strncmp (p
, "V1_CACM", 7))
1419 return darwin_sections
[objc_cat_cls_meth_section
];
1420 else if (!strncmp (p
, "V1_CAIM", 7))
1421 return darwin_sections
[objc_cat_inst_meth_section
];
1422 else if (!strncmp (p
, "V1_PNSM", 7))
1423 return darwin_sections
[objc_cat_inst_meth_section
];
1424 else if (!strncmp (p
, "V1_PCLM", 7))
1425 return darwin_sections
[objc_cat_cls_meth_section
];
1427 else if (!strncmp (p
, "V1_CLPR", 7))
1428 return darwin_sections
[objc_cat_cls_meth_section
];
1429 else if (!strncmp (p
, "V1_CAPR", 7))
1430 return darwin_sections
[objc_category_section
]; /* ??? CHECK me. */
1432 else if (!strncmp (p
, "V1_PRFS", 7))
1433 return darwin_sections
[objc_cat_cls_meth_section
];
1434 else if (!strncmp (p
, "V1_CLRF", 7))
1435 return darwin_sections
[objc_cls_refs_section
];
1436 else if (!strncmp (p
, "V1_SRFS", 7))
1437 return darwin_sections
[objc_selector_refs_section
];
1439 else if (!strncmp (p
, "V1_MODU", 7))
1440 return darwin_sections
[objc_module_info_section
];
1441 else if (!strncmp (p
, "V1_SYMT", 7))
1442 return darwin_sections
[objc_symbols_section
];
1443 else if (!strncmp (p
, "V1_INFO", 7))
1444 return darwin_sections
[objc_image_info_section
];
1446 else if (!strncmp (p
, "V1_PLST", 7))
1447 return darwin_sections
[objc1_prop_list_section
];
1448 else if (!strncmp (p
, "V1_PEXT", 7))
1449 return darwin_sections
[objc1_protocol_ext_section
];
1450 else if (!strncmp (p
, "V1_CEXT", 7))
1451 return darwin_sections
[objc1_class_ext_section
];
1453 else if (!strncmp (p
, "V2_CSTR", 7))
1454 return darwin_sections
[objc_constant_string_object_section
];
1460 machopic_select_section (tree decl
,
1462 unsigned HOST_WIDE_INT align
)
1464 bool zsize
, one
, weak
, ro
;
1465 section
*base_section
= NULL
;
1467 weak
= (DECL_P (decl
)
1469 && !lookup_attribute ("weak_import", DECL_ATTRIBUTES (decl
)));
1471 zsize
= (DECL_P (decl
)
1472 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
1473 && tree_low_cst (DECL_SIZE_UNIT (decl
), 1) == 0);
1476 && TREE_CODE (decl
) == VAR_DECL
1477 && DECL_ONE_ONLY (decl
);
1479 ro
= TREE_READONLY (decl
) || TREE_CONSTANT (decl
) ;
1481 switch (categorize_decl_for_section (decl
, reloc
))
1488 case SECCAT_SRODATA
:
1489 base_section
= darwin_rodata_section (weak
, zsize
);
1492 case SECCAT_RODATA_MERGE_STR
:
1493 base_section
= darwin_mergeable_string_section (decl
, align
);
1496 case SECCAT_RODATA_MERGE_STR_INIT
:
1497 base_section
= darwin_mergeable_string_section (DECL_INITIAL (decl
), align
);
1500 case SECCAT_RODATA_MERGE_CONST
:
1501 base_section
= darwin_mergeable_constant_section (decl
, align
, zsize
);
1505 case SECCAT_DATA_REL
:
1506 case SECCAT_DATA_REL_LOCAL
:
1507 case SECCAT_DATA_REL_RO
:
1508 case SECCAT_DATA_REL_RO_LOCAL
:
1514 base_section
= darwin_sections
[const_data_coal_section
];
1516 base_section
= darwin_sections
[data_coal_section
];
1518 else if (DARWIN_SECTION_ANCHORS
1519 && flag_section_anchors
1522 /* If we're doing section anchors, then punt zero-sized objects into
1523 their own sections so that they don't interfere with offset
1524 computation for the remaining vars. This does not need to be done
1525 for stuff in mergeable sections, since these are ineligible for
1528 base_section
= darwin_sections
[zobj_const_data_section
];
1530 base_section
= darwin_sections
[zobj_data_section
];
1533 base_section
= darwin_sections
[const_data_section
];
1535 base_section
= data_section
;
1541 base_section
= darwin_sections
[data_coal_section
];
1544 if (!TREE_PUBLIC (decl
))
1545 base_section
= lcomm_section
;
1546 else if (bss_noswitch_section
)
1547 base_section
= bss_noswitch_section
;
1549 base_section
= data_section
;
1557 /* Darwin weird special cases.
1558 a) OBJC Meta-data. */
1560 && (TREE_CODE (decl
) == VAR_DECL
1561 || TREE_CODE (decl
) == CONST_DECL
)
1562 && DECL_ATTRIBUTES (decl
))
1564 tree meta
= lookup_attribute ("OBJC2META", DECL_ATTRIBUTES (decl
));
1566 return darwin_objc2_section (decl
, meta
, base_section
);
1567 meta
= lookup_attribute ("OBJC1META", DECL_ATTRIBUTES (decl
));
1569 return darwin_objc1_section (decl
, meta
, base_section
);
1570 meta
= lookup_attribute ("OBJC1METG", DECL_ATTRIBUTES (decl
));
1572 return base_section
; /* GNU runtime is happy with it all in one pot. */
1575 /* b) Constant string objects. */
1576 if (TREE_CODE (decl
) == CONSTRUCTOR
1578 && TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
1579 && TYPE_NAME (TREE_TYPE (decl
)))
1581 tree name
= TYPE_NAME (TREE_TYPE (decl
));
1582 if (TREE_CODE (name
) == TYPE_DECL
)
1583 name
= DECL_NAME (name
);
1585 /* FIXME: This is unsatisfactory for LTO, since it relies on other
1586 metadata determining the source FE. */
1587 if (!strcmp (IDENTIFIER_POINTER (name
), "__builtin_ObjCString"))
1589 if (flag_next_runtime
)
1591 if (flag_objc_abi
== 2)
1592 return darwin_sections
[objc2_constant_string_object_section
];
1594 return darwin_sections
[objc_constant_string_object_section
];
1597 return darwin_sections
[objc_string_object_section
];
1599 else if (!strcmp (IDENTIFIER_POINTER (name
), "__builtin_CFString"))
1600 return darwin_sections
[cfstring_constant_object_section
];
1602 return base_section
;
1604 /* c) legacy meta-data selection. */
1605 else if (TREE_CODE (decl
) == VAR_DECL
1607 && TREE_CODE (DECL_NAME (decl
)) == IDENTIFIER_NODE
1608 && IDENTIFIER_POINTER (DECL_NAME (decl
))
1609 && flag_next_runtime
1610 && !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl
)), "_OBJC_", 6))
1612 const char *name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1613 static bool warned_objc_46
= false;
1614 /* We shall assert that zero-sized objects are an error in ObjC
1616 gcc_assert (tree_low_cst (DECL_SIZE_UNIT (decl
), 1) != 0);
1618 /* ??? This mechanism for determining the metadata section is
1619 broken when LTO is in use, since the frontend that generated
1620 the data is not identified. We will keep the capability for
1621 the short term - in case any non-Objective-C programs are using
1622 it to place data in specified sections. */
1623 if (!warned_objc_46
)
1625 location_t loc
= DECL_SOURCE_LOCATION (decl
);
1626 warning_at (loc
, 0, "the use of _OBJC_-prefixed variable names"
1627 " to select meta-data sections is deprecated at 4.6"
1628 " and will be removed in 4.7");
1629 warned_objc_46
= true;
1632 if (!strncmp (name
, "_OBJC_CLASS_METHODS_", 20))
1633 return darwin_sections
[objc_cls_meth_section
];
1634 else if (!strncmp (name
, "_OBJC_INSTANCE_METHODS_", 23))
1635 return darwin_sections
[objc_inst_meth_section
];
1636 else if (!strncmp (name
, "_OBJC_CATEGORY_CLASS_METHODS_", 29))
1637 return darwin_sections
[objc_cat_cls_meth_section
];
1638 else if (!strncmp (name
, "_OBJC_CATEGORY_INSTANCE_METHODS_", 32))
1639 return darwin_sections
[objc_cat_inst_meth_section
];
1640 else if (!strncmp (name
, "_OBJC_CLASS_VARIABLES_", 22))
1641 return darwin_sections
[objc_class_vars_section
];
1642 else if (!strncmp (name
, "_OBJC_INSTANCE_VARIABLES_", 25))
1643 return darwin_sections
[objc_instance_vars_section
];
1644 else if (!strncmp (name
, "_OBJC_CLASS_PROTOCOLS_", 22))
1645 return darwin_sections
[objc_cat_cls_meth_section
];
1646 else if (!strncmp (name
, "_OBJC_CLASS_NAME_", 17))
1647 return darwin_sections
[objc_class_names_section
];
1648 else if (!strncmp (name
, "_OBJC_METH_VAR_NAME_", 20))
1649 return darwin_sections
[objc_meth_var_names_section
];
1650 else if (!strncmp (name
, "_OBJC_METH_VAR_TYPE_", 20))
1651 return darwin_sections
[objc_meth_var_types_section
];
1652 else if (!strncmp (name
, "_OBJC_CLASS_REFERENCES", 22))
1653 return darwin_sections
[objc_cls_refs_section
];
1654 else if (!strncmp (name
, "_OBJC_CLASS_", 12))
1655 return darwin_sections
[objc_class_section
];
1656 else if (!strncmp (name
, "_OBJC_METACLASS_", 16))
1657 return darwin_sections
[objc_meta_class_section
];
1658 else if (!strncmp (name
, "_OBJC_CATEGORY_", 15))
1659 return darwin_sections
[objc_category_section
];
1660 else if (!strncmp (name
, "_OBJC_SELECTOR_REFERENCES", 25))
1661 return darwin_sections
[objc_selector_refs_section
];
1662 else if (!strncmp (name
, "_OBJC_SELECTOR_FIXUP", 20))
1663 return darwin_sections
[objc_selector_fixup_section
];
1664 else if (!strncmp (name
, "_OBJC_SYMBOLS", 13))
1665 return darwin_sections
[objc_symbols_section
];
1666 else if (!strncmp (name
, "_OBJC_MODULES", 13))
1667 return darwin_sections
[objc_module_info_section
];
1668 else if (!strncmp (name
, "_OBJC_IMAGE_INFO", 16))
1669 return darwin_sections
[objc_image_info_section
];
1670 else if (!strncmp (name
, "_OBJC_PROTOCOL_INSTANCE_METHODS_", 32))
1671 return darwin_sections
[objc_cat_inst_meth_section
];
1672 else if (!strncmp (name
, "_OBJC_PROTOCOL_CLASS_METHODS_", 29))
1673 return darwin_sections
[objc_cat_cls_meth_section
];
1674 else if (!strncmp (name
, "_OBJC_PROTOCOL_REFS_", 20))
1675 return darwin_sections
[objc_cat_cls_meth_section
];
1676 else if (!strncmp (name
, "_OBJC_PROTOCOL_", 15))
1677 return darwin_sections
[objc_protocol_section
];
1679 return base_section
;
1682 return base_section
;
1685 /* This can be called with address expressions as "rtx".
1686 They must go in "const". */
1689 machopic_select_rtx_section (enum machine_mode mode
, rtx x
,
1690 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
1692 if (GET_MODE_SIZE (mode
) == 8
1693 && (GET_CODE (x
) == CONST_INT
1694 || GET_CODE (x
) == CONST_DOUBLE
))
1695 return darwin_sections
[literal8_section
];
1696 else if (GET_MODE_SIZE (mode
) == 4
1697 && (GET_CODE (x
) == CONST_INT
1698 || GET_CODE (x
) == CONST_DOUBLE
))
1699 return darwin_sections
[literal4_section
];
1700 else if (HAVE_GAS_LITERAL16
1702 && GET_MODE_SIZE (mode
) == 16
1703 && (GET_CODE (x
) == CONST_INT
1704 || GET_CODE (x
) == CONST_DOUBLE
1705 || GET_CODE (x
) == CONST_VECTOR
))
1706 return darwin_sections
[literal16_section
];
1707 else if (MACHOPIC_INDIRECT
1708 && (GET_CODE (x
) == SYMBOL_REF
1709 || GET_CODE (x
) == CONST
1710 || GET_CODE (x
) == LABEL_REF
))
1711 return darwin_sections
[const_data_section
];
1713 return darwin_sections
[const_section
];
1717 machopic_asm_out_constructor (rtx symbol
, int priority ATTRIBUTE_UNUSED
)
1719 ctor_record new_elt
= {symbol
, priority
, vec_safe_length (ctors
)};
1721 vec_safe_push (ctors
, new_elt
);
1723 if (! MACHOPIC_INDIRECT
)
1724 fprintf (asm_out_file
, ".reference .constructors_used\n");
1728 sort_ctor_records (const void * a
, const void * b
)
1730 const ctor_record
*ca
= (const ctor_record
*)a
;
1731 const ctor_record
*cb
= (const ctor_record
*)b
;
1732 if (ca
->priority
> cb
->priority
)
1734 if (ca
->priority
< cb
->priority
)
1736 if (ca
->position
> cb
->position
)
1738 if (ca
->position
< cb
->position
)
1749 if (MACHOPIC_INDIRECT
)
1750 switch_to_section (darwin_sections
[mod_init_section
]);
1752 switch_to_section (darwin_sections
[constructor_section
]);
1754 if (vec_safe_length (ctors
) > 1)
1755 ctors
->qsort (sort_ctor_records
);
1756 FOR_EACH_VEC_SAFE_ELT (ctors
, i
, elt
)
1758 assemble_align (POINTER_SIZE
);
1759 assemble_integer (elt
->symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1764 machopic_asm_out_destructor (rtx symbol
, int priority ATTRIBUTE_UNUSED
)
1766 if (MACHOPIC_INDIRECT
)
1767 switch_to_section (darwin_sections
[mod_term_section
]);
1769 switch_to_section (darwin_sections
[destructor_section
]);
1770 assemble_align (POINTER_SIZE
);
1771 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1773 if (! MACHOPIC_INDIRECT
)
1774 fprintf (asm_out_file
, ".reference .destructors_used\n");
1778 darwin_globalize_label (FILE *stream
, const char *name
)
1780 if (!!strncmp (name
, "_OBJC_", 6))
1781 default_globalize_label (stream
, name
);
1784 /* This routine returns non-zero if 'name' starts with the special objective-c
1785 anonymous file-scope static name. It accommodates c++'s mangling of such
1786 symbols (in this case the symbols will have form _ZL{d}*_OBJC_* d=digit). */
1789 darwin_label_is_anonymous_local_objc_name (const char *name
)
1791 const unsigned char *p
= (const unsigned char *) name
;
1794 if (p
[1] == 'Z' && p
[2] == 'L')
1797 while (*p
>= '0' && *p
<= '9')
1800 return (!strncmp ((const char *)p
, "_OBJC_", 6));
1803 /* LTO support for Mach-O.
1805 This version uses three mach-o sections to encapsulate the (unlimited
1806 number of) lto sections.
1808 __GNU_LTO, __lto_sections contains the concatented GNU LTO section data.
1809 __GNU_LTO, __section_names contains the GNU LTO section names.
1810 __GNU_LTO, __section_index contains an array of values that index these.
1813 <section offset from the start of __GNU_LTO, __lto_sections>,
1815 <name offset from the start of __GNU_LTO, __section_names,
1818 At present, for both m32 and m64 mach-o files each of these fields is
1819 represented by a uint32_t. This is because, AFAICT, a mach-o object
1820 cannot exceed 4Gb because the section_64 offset field (see below) is 32bits.
1823 "offset An integer specifying the offset to this section in the file." */
1825 /* Count lto section numbers. */
1826 static unsigned int lto_section_num
= 0;
1828 /* A vector of information about LTO sections, at present, we only have
1829 the name. TODO: see if we can get the data length somehow. */
1830 typedef struct GTY (()) darwin_lto_section_e
{
1831 const char *sectname
;
1832 } darwin_lto_section_e
;
1834 static GTY (()) vec
<darwin_lto_section_e
, va_gc
> *lto_section_names
;
1836 /* Segment for LTO data. */
1837 #define LTO_SEGMENT_NAME "__GNU_LTO"
1839 /* Section wrapper scheme (used here to wrap the unlimited number of LTO
1840 sections into three Mach-O ones).
1841 NOTE: These names MUST be kept in sync with those in
1842 libiberty/simple-object-mach-o. */
1843 #define LTO_SECTS_SECTION "__wrapper_sects"
1844 #define LTO_NAMES_SECTION "__wrapper_names"
1845 #define LTO_INDEX_SECTION "__wrapper_index"
1847 /* File to temporarily store LTO data. This is appended to asm_out_file
1848 in darwin_end_file. */
1849 static FILE *lto_asm_out_file
, *saved_asm_out_file
;
1850 static char *lto_asm_out_name
;
1852 /* Prepare asm_out_file for LTO output. For darwin, this means hiding
1853 asm_out_file and switching to an alternative output file. */
1855 darwin_asm_lto_start (void)
1857 gcc_assert (! saved_asm_out_file
);
1858 saved_asm_out_file
= asm_out_file
;
1859 if (! lto_asm_out_name
)
1860 lto_asm_out_name
= make_temp_file (".lto.s");
1861 lto_asm_out_file
= fopen (lto_asm_out_name
, "a");
1862 if (lto_asm_out_file
== NULL
)
1863 fatal_error ("failed to open temporary file %s for LTO output",
1865 asm_out_file
= lto_asm_out_file
;
1868 /* Restore asm_out_file. */
1870 darwin_asm_lto_end (void)
1872 gcc_assert (saved_asm_out_file
);
1873 fclose (lto_asm_out_file
);
1874 asm_out_file
= saved_asm_out_file
;
1875 saved_asm_out_file
= NULL
;
1879 darwin_asm_dwarf_section (const char *name
, unsigned int flags
, tree decl
);
1881 /* Called for the TARGET_ASM_NAMED_SECTION hook. */
1884 darwin_asm_named_section (const char *name
,
1886 tree decl ATTRIBUTE_UNUSED
)
1888 /* LTO sections go in a special section that encapsulates the (unlimited)
1889 number of GNU LTO sections within a single mach-o one. */
1890 if (strncmp (name
, LTO_SECTION_NAME_PREFIX
,
1891 strlen (LTO_SECTION_NAME_PREFIX
)) == 0)
1893 darwin_lto_section_e e
;
1894 /* We expect certain flags to be set... */
1895 gcc_assert ((flags
& (SECTION_DEBUG
| SECTION_NAMED
))
1896 == (SECTION_DEBUG
| SECTION_NAMED
));
1898 /* Switch to our combined section. */
1899 fprintf (asm_out_file
, "\t.section %s,%s,regular,debug\n",
1900 LTO_SEGMENT_NAME
, LTO_SECTS_SECTION
);
1901 /* Output a label for the start of this sub-section. */
1902 fprintf (asm_out_file
, "L_GNU_LTO%d:\t;# %s\n",
1903 lto_section_num
, name
);
1904 /* We have to jump through hoops to get the values of the intra-section
1906 fprintf (asm_out_file
, "\t.set L$gnu$lto$offs%d,L_GNU_LTO%d-L_GNU_LTO0\n",
1907 lto_section_num
, lto_section_num
);
1908 fprintf (asm_out_file
,
1909 "\t.set L$gnu$lto$size%d,L_GNU_LTO%d-L_GNU_LTO%d\n",
1910 lto_section_num
, lto_section_num
+1, lto_section_num
);
1912 e
.sectname
= xstrdup (name
);
1913 /* Keep the names, we'll need to make a table later.
1914 TODO: check that we do not revisit sections, that would break
1915 the assumption of how this is done. */
1916 if (lto_section_names
== NULL
)
1917 vec_alloc (lto_section_names
, 16);
1918 vec_safe_push (lto_section_names
, e
);
1920 else if (strncmp (name
, "__DWARF,", 8) == 0)
1921 darwin_asm_dwarf_section (name
, flags
, decl
);
1923 fprintf (asm_out_file
, "\t.section %s\n", name
);
1927 darwin_unique_section (tree decl ATTRIBUTE_UNUSED
, int reloc ATTRIBUTE_UNUSED
)
1929 /* Darwin does not use unique sections. */
1932 /* Handle __attribute__ ((apple_kext_compatibility)).
1933 This only applies to darwin kexts for 2.95 compatibility -- it shrinks the
1934 vtable for classes with this attribute (and their descendants) by not
1935 outputting the new 3.0 nondeleting destructor. This means that such
1936 objects CANNOT be allocated on the stack or as globals UNLESS they have
1937 a completely empty `operator delete'.
1938 Luckily, this fits in with the Darwin kext model.
1940 This attribute also disables gcc3's potential overlaying of derived
1941 class data members on the padding at the end of the base class. */
1944 darwin_handle_kext_attribute (tree
*node
, tree name
,
1945 tree args ATTRIBUTE_UNUSED
,
1946 int flags ATTRIBUTE_UNUSED
,
1949 /* APPLE KEXT stuff -- only applies with pure static C++ code. */
1950 if (! TARGET_KEXTABI
)
1952 warning (0, "%qE 2.95 vtable-compatibility attribute applies "
1953 "only when compiling a kext", name
);
1955 *no_add_attrs
= true;
1957 else if (TREE_CODE (*node
) != RECORD_TYPE
)
1959 warning (0, "%qE 2.95 vtable-compatibility attribute applies "
1960 "only to C++ classes", name
);
1962 *no_add_attrs
= true;
1968 /* Handle a "weak_import" attribute; arguments as in
1969 struct attribute_spec.handler. */
1972 darwin_handle_weak_import_attribute (tree
*node
, tree name
,
1973 tree
ARG_UNUSED (args
),
1974 int ARG_UNUSED (flags
),
1975 bool * no_add_attrs
)
1977 if (TREE_CODE (*node
) != FUNCTION_DECL
&& TREE_CODE (*node
) != VAR_DECL
)
1979 warning (OPT_Wattributes
, "%qE attribute ignored",
1981 *no_add_attrs
= true;
1984 declare_weak (*node
);
1989 /* Emit a label for an FDE, making it global and/or weak if appropriate.
1990 The third parameter is nonzero if this is for exception handling.
1991 The fourth parameter is nonzero if this is just a placeholder for an
1992 FDE that we are omitting. */
1995 darwin_emit_unwind_label (FILE *file
, tree decl
, int for_eh
, int empty
)
1999 static int invok_count
= 0;
2000 static tree last_fun_decl
= NULL_TREE
;
2002 /* We use the linker to emit the .eh labels for Darwin 9 and above. */
2003 if (! for_eh
|| generating_for_darwin_version
>= 9)
2006 /* FIXME: This only works when the eh for all sections of a function is
2007 emitted at the same time. If that changes, we would need to use a lookup
2008 table of some form to determine what to do. Also, we should emit the
2009 unadorned label for the partition containing the public label for a
2010 function. This is of limited use, probably, since we do not currently
2011 enable partitioning. */
2012 strcpy (buf
, ".eh");
2013 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
2015 if (decl
== last_fun_decl
)
2018 snprintf (buf
, 31, "$$part$$%d.eh", invok_count
);
2022 last_fun_decl
= decl
;
2027 lab
= concat (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), buf
, NULL
);
2029 if (TREE_PUBLIC (decl
))
2031 targetm
.asm_out
.globalize_label (file
, lab
);
2032 if (DECL_VISIBILITY (decl
) == VISIBILITY_HIDDEN
)
2034 fputs ("\t.private_extern ", file
);
2035 assemble_name (file
, lab
);
2040 if (DECL_WEAK (decl
))
2042 fputs ("\t.weak_definition ", file
);
2043 assemble_name (file
, lab
);
2047 assemble_name (file
, lab
);
2050 fputs (" = 0\n", file
);
2052 /* Mark the absolute .eh and .eh1 style labels as needed to
2053 ensure that we don't dead code strip them and keep such
2054 labels from another instantiation point until we can fix this
2055 properly with group comdat support. */
2056 darwin_mark_decl_preserved (lab
);
2059 fputs (":\n", file
);
2064 static GTY(()) unsigned long except_table_label_num
;
2067 darwin_emit_except_table_label (FILE *file
)
2069 char section_start_label
[30];
2071 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, "GCC_except_table",
2072 except_table_label_num
++);
2073 ASM_OUTPUT_LABEL (file
, section_start_label
);
2075 /* Generate a PC-relative reference to a Mach-O non-lazy-symbol. */
2078 darwin_non_lazy_pcrel (FILE *file
, rtx addr
)
2080 const char *nlp_name
;
2082 gcc_assert (GET_CODE (addr
) == SYMBOL_REF
);
2084 nlp_name
= machopic_indirection_name (addr
, /*stub_p=*/false);
2085 fputs ("\t.long\t", file
);
2086 ASM_OUTPUT_LABELREF (file
, nlp_name
);
2090 /* If this is uncommented, details of each allocation will be printed
2091 in the asm right before the actual code. WARNING - this will cause some
2092 test-suite fails (since the printout will contain items that some tests
2093 are not expecting) -- so don't leave it on by default (it bloats the
2095 /*#define DEBUG_DARWIN_MEM_ALLOCATORS*/
2097 /* The first two of these routines are ostensibly just intended to put
2098 names into the asm. However, they are both hijacked in order to ensure
2099 that zero-sized items do not make their way into the output. Consequently,
2100 we also need to make these participate in provisions for dealing with
2101 such items in section anchors. */
2103 /* The implementation of ASM_DECLARE_OBJECT_NAME. */
2104 /* The RTTI data (e.g., __ti4name) is common and public (and static),
2105 but it does need to be referenced via indirect PIC data pointers.
2106 The machopic_define_symbol calls are telling the machopic subsystem
2107 that the name *is* defined in this module, so it doesn't need to
2108 make them indirect. */
2110 darwin_asm_declare_object_name (FILE *file
,
2111 const char *nam
, tree decl
)
2113 const char *xname
= nam
;
2114 unsigned HOST_WIDE_INT size
;
2115 bool local_def
, weak
;
2117 weak
= (DECL_P (decl
)
2119 && !lookup_attribute ("weak_import",
2120 DECL_ATTRIBUTES (decl
)));
2122 local_def
= DECL_INITIAL (decl
) || (TREE_STATIC (decl
)
2123 && (!DECL_COMMON (decl
)
2124 || !TREE_PUBLIC (decl
)));
2126 if (GET_CODE (XEXP (DECL_RTL (decl
), 0)) != SYMBOL_REF
)
2127 xname
= IDENTIFIER_POINTER (DECL_NAME (decl
));
2131 (* targetm
.encode_section_info
) (decl
, DECL_RTL (decl
), false);
2133 machopic_define_symbol (DECL_RTL (decl
));
2136 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
2138 #ifdef DEBUG_DARWIN_MEM_ALLOCATORS
2139 fprintf (file
, "# dadon: %s %s (%llu, %u) local %d weak %d"
2140 " stat %d com %d pub %d t-const %d t-ro %d init %lx\n",
2141 xname
, (TREE_CODE (decl
) == VAR_DECL
?"var":"const"),
2142 (unsigned long long)size
, DECL_ALIGN (decl
), local_def
,
2143 DECL_WEAK (decl
), TREE_STATIC (decl
), DECL_COMMON (decl
),
2144 TREE_PUBLIC (decl
), TREE_CONSTANT (decl
), TREE_READONLY (decl
),
2145 (unsigned long)DECL_INITIAL (decl
));
2148 /* Darwin needs help to support local zero-sized objects.
2149 They must be made at least one byte, and the section containing must be
2150 marked as unsuitable for section-anchors (see storage allocators below).
2152 For non-zero objects this output is handled by varasm.c.
2156 unsigned int l2align
= 0;
2158 /* The align must be honored, even for zero-sized. */
2159 if (DECL_ALIGN (decl
))
2161 l2align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
2162 fprintf (file
, "\t.align\t%u\n", l2align
);
2165 ASM_OUTPUT_LABEL (file
, xname
);
2167 fprintf (file
, "\t.space\t"HOST_WIDE_INT_PRINT_UNSIGNED
"\n", size
);
2169 /* Check that we've correctly picked up the zero-sized item and placed it
2171 gcc_assert ((!DARWIN_SECTION_ANCHORS
|| !flag_section_anchors
)
2173 && (in_section
->common
.flags
& SECTION_NO_ANCHOR
)));
2176 ASM_OUTPUT_LABEL (file
, xname
);
2179 /* The implementation of ASM_DECLARE_CONSTANT_NAME. */
2181 darwin_asm_declare_constant_name (FILE *file
, const char *name
,
2182 const_tree exp ATTRIBUTE_UNUSED
,
2185 assemble_label (file
, name
);
2186 /* As for other items, we need at least one byte. */
2189 fputs ("\t.space\t1\n", file
);
2190 /* Check that we've correctly picked up the zero-sized item and placed it
2192 gcc_assert ((!DARWIN_SECTION_ANCHORS
|| !flag_section_anchors
)
2194 && (in_section
->common
.flags
& SECTION_NO_ANCHOR
)));
2198 /* Darwin storage allocators.
2200 Zerofill sections are desirable for large blank data since, otherwise, these
2201 data bloat objects (PR33210).
2203 However, section anchors don't work in .zerofill sections (one cannot switch
2204 to a zerofill section). Ergo, for Darwin targets using section anchors we need
2205 to put (at least some) data into 'normal' switchable sections.
2207 Here we set a relatively arbitrary value for the size of an object to trigger
2208 zerofill when section anchors are enabled (anything bigger than a page for
2209 current Darwin implementations). FIXME: there ought to be some objective way
2210 to make this choice.
2212 When section anchor are off this is ignored anyway. */
2214 #define BYTES_ZFILL 4096
2216 /* Emit a chunk of data for items coalesced by the linker. */
2218 darwin_emit_weak_or_comdat (FILE *fp
, tree decl
, const char *name
,
2219 unsigned HOST_WIDE_INT size
,
2222 /* Since the sections used here are coalesed, they will not be eligible
2223 for section anchors, and therefore we don't need to break that out. */
2224 if (TREE_READONLY (decl
) || TREE_CONSTANT (decl
))
2225 switch_to_section (darwin_sections
[const_data_coal_section
]);
2227 switch_to_section (darwin_sections
[data_coal_section
]);
2229 /* To be consistent, we'll allow darwin_asm_declare_object_name to assemble
2230 the align info for zero-sized items... but do it here otherwise. */
2232 fprintf (fp
, "\t.align\t%d\n", floor_log2 (align
/ BITS_PER_UNIT
));
2234 if (TREE_PUBLIC (decl
))
2235 darwin_globalize_label (fp
, name
);
2237 /* ... and we let it deal with outputting one byte of zero for them too. */
2238 darwin_asm_declare_object_name (fp
, name
, decl
);
2240 assemble_zeros (size
);
2243 /* Emit a chunk of data for ObjC meta-data that got placed in BSS erroneously. */
2245 darwin_emit_objc_zeroed (FILE *fp
, tree decl
, const char *name
,
2246 unsigned HOST_WIDE_INT size
,
2247 unsigned int align
, tree meta
)
2249 section
*ocs
= data_section
;
2251 if (TREE_PURPOSE (meta
) == get_identifier("OBJC2META"))
2252 ocs
= darwin_objc2_section (decl
, meta
, ocs
);
2254 ocs
= darwin_objc1_section (decl
, meta
, ocs
);
2256 switch_to_section (ocs
);
2258 /* We shall declare that zero-sized meta-data are not valid (yet). */
2260 fprintf (fp
, "\t.align\t%d\n", floor_log2 (align
/ BITS_PER_UNIT
));
2262 /* ... and we let it deal with outputting one byte of zero for them too. */
2263 darwin_asm_declare_object_name (fp
, name
, decl
);
2264 assemble_zeros (size
);
2267 /* This routine emits 'local' storage:
2269 When Section Anchors are off this routine emits .zerofill commands in
2270 sections named for their alignment.
2272 When Section Anchors are on, smaller (non-zero-sized) items are placed in
2273 the .static_data section so that the section anchoring system can see them.
2274 Larger items are still placed in .zerofill sections, addressing PR33210.
2275 The routine has no checking - it is all assumed to be done by the caller.
2278 darwin_emit_local_bss (FILE *fp
, tree decl
, const char *name
,
2279 unsigned HOST_WIDE_INT size
,
2280 unsigned int l2align
)
2282 /* FIXME: We have a fudge to make this work with Java even when the target does
2283 not use sections anchors -- Java seems to need at least one small item in a
2284 non-zerofill segment. */
2285 if ((DARWIN_SECTION_ANCHORS
&& flag_section_anchors
&& size
< BYTES_ZFILL
)
2286 || (size
&& size
<= 2))
2288 /* Put smaller objects in _static_data, where the section anchors system
2290 However, if they are zero-sized punt them to yet a different section
2291 (that is not allowed to participate in anchoring). */
2294 fputs ("\t.section\t__DATA,__zobj_bss\n", fp
);
2295 in_section
= darwin_sections
[zobj_bss_section
];
2300 fputs ("\t.static_data\n", fp
);
2301 in_section
= darwin_sections
[static_data_section
];
2305 fprintf (fp
, "\t.align\t%u\n", l2align
);
2307 assemble_name (fp
, name
);
2308 fprintf (fp
, ":\n\t.space\t"HOST_WIDE_INT_PRINT_UNSIGNED
"\n", size
);
2312 /* When we are on a non-section anchor target, we can get zero-sized
2313 items here. However, all we need to do is to bump them to one byte
2314 and the section alignment will take care of the rest. */
2316 unsigned int flags
;
2317 snprintf (secnam
, 64, "__DATA,__%sbss%u", ((size
)?"":"zo_"),
2318 (unsigned) l2align
);
2319 /* We can't anchor (yet, if ever) in zerofill sections, because we can't
2320 switch to them and emit a label. */
2321 flags
= SECTION_BSS
|SECTION_WRITE
|SECTION_NO_ANCHOR
;
2322 in_section
= get_section (secnam
, flags
, NULL
);
2323 fprintf (fp
, "\t.zerofill %s,", secnam
);
2324 assemble_name (fp
, name
);
2329 fprintf (fp
, ","HOST_WIDE_INT_PRINT_UNSIGNED
",%u\n",
2330 size
, (unsigned) l2align
);
2332 fprintf (fp
, ","HOST_WIDE_INT_PRINT_UNSIGNED
"\n", size
);
2335 (*targetm
.encode_section_info
) (decl
, DECL_RTL (decl
), false);
2336 /* This is defined as a file-scope var, so we know to notify machopic. */
2337 machopic_define_symbol (DECL_RTL (decl
));
2340 /* Emit a chunk of common. */
2342 darwin_emit_common (FILE *fp
, const char *name
,
2343 unsigned HOST_WIDE_INT size
, unsigned int align
)
2345 unsigned HOST_WIDE_INT rounded
;
2346 unsigned int l2align
;
2348 /* Earlier systems complain if the alignment exceeds the page size.
2349 The magic number is 4096 * 8 - hard-coded for legacy systems. */
2350 if (!emit_aligned_common
&& (align
> 32768UL))
2351 align
= 4096UL; /* In units. */
2353 align
/= BITS_PER_UNIT
;
2355 /* Make sure we have a meaningful align. */
2359 /* For earlier toolchains, we need to emit the var as a rounded size to
2360 tell ld the alignment. */
2364 rounded
= (size
+ (align
-1)) & ~(align
-1);
2366 l2align
= floor_log2 (align
);
2367 gcc_assert (l2align
<= L2_MAX_OFILE_ALIGNMENT
);
2369 in_section
= comm_section
;
2370 /* We mustn't allow multiple public symbols to share an address when using
2371 the normal OSX toolchain. */
2374 /* Put at least one byte. */
2376 /* This section can no longer participate in section anchoring. */
2377 comm_section
->common
.flags
|= SECTION_NO_ANCHOR
;
2380 fputs ("\t.comm\t", fp
);
2381 assemble_name (fp
, name
);
2382 fprintf (fp
, "," HOST_WIDE_INT_PRINT_UNSIGNED
,
2383 emit_aligned_common
?size
:rounded
);
2384 if (l2align
&& emit_aligned_common
)
2385 fprintf (fp
, ",%u", l2align
);
2389 /* Output a var which is all zero - into aligned BSS sections, common, lcomm
2390 or coalescable data sections (for weak or comdat) as appropriate. */
2393 darwin_output_aligned_bss (FILE *fp
, tree decl
, const char *name
,
2394 unsigned HOST_WIDE_INT size
, unsigned int align
)
2396 unsigned int l2align
;
2397 bool one
, pub
, weak
;
2400 pub
= TREE_PUBLIC (decl
);
2401 one
= DECL_ONE_ONLY (decl
);
2402 weak
= (DECL_P (decl
)
2404 && !lookup_attribute ("weak_import",
2405 DECL_ATTRIBUTES (decl
)));
2407 #ifdef DEBUG_DARWIN_MEM_ALLOCATORS
2408 fprintf (fp
, "# albss: %s (%lld,%d) ro %d cst %d stat %d com %d"
2409 " pub %d weak %d one %d init %lx\n",
2410 name
, (long long)size
, (int)align
, TREE_READONLY (decl
),
2411 TREE_CONSTANT (decl
), TREE_STATIC (decl
), DECL_COMMON (decl
),
2412 pub
, weak
, one
, (unsigned long)DECL_INITIAL (decl
));
2415 /* ObjC metadata can get put in BSS because varasm.c decides it's BSS
2416 before the target has a chance to comment. */
2417 if ((meta
= is_objc_metadata (decl
)))
2419 darwin_emit_objc_zeroed (fp
, decl
, name
, size
, DECL_ALIGN (decl
), meta
);
2423 /* Check that any initializer is valid. */
2424 gcc_assert ((DECL_INITIAL (decl
) == NULL
)
2425 || (DECL_INITIAL (decl
) == error_mark_node
)
2426 || initializer_zerop (DECL_INITIAL (decl
)));
2428 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
);
2429 gcc_assert (!DECL_COMMON (decl
));
2431 /* Pick up the correct alignment. */
2432 if (!size
|| !align
)
2433 align
= DECL_ALIGN (decl
);
2435 l2align
= floor_log2 (align
/ BITS_PER_UNIT
);
2436 gcc_assert (l2align
<= L2_MAX_OFILE_ALIGNMENT
);
2438 last_assemble_variable_decl
= decl
;
2440 /* We would rather not have to check this here - but it seems that we might
2441 be passed a decl that should be in coalesced space. */
2444 /* Weak or COMDAT objects are put in mergeable sections. */
2445 darwin_emit_weak_or_comdat (fp
, decl
, name
, size
,
2450 /* If this is not public, then emit according to local rules. */
2453 darwin_emit_local_bss (fp
, decl
, name
, size
, l2align
);
2457 /* So we have a public symbol (small item fudge for Java, see above). */
2458 if ((DARWIN_SECTION_ANCHORS
&& flag_section_anchors
&& size
< BYTES_ZFILL
)
2459 || (size
&& size
<= 2))
2461 /* Put smaller objects in data, where the section anchors system can get
2462 them. However, if they are zero-sized punt them to yet a different
2463 section (that is not allowed to participate in anchoring). */
2466 fputs ("\t.section\t__DATA,__zobj_data\n", fp
);
2467 in_section
= darwin_sections
[zobj_data_section
];
2472 fputs ("\t.data\n", fp
);
2473 in_section
= data_section
;
2477 fprintf (fp
, "\t.align\t%u\n", l2align
);
2479 assemble_name (fp
, name
);
2480 fprintf (fp
, ":\n\t.space\t"HOST_WIDE_INT_PRINT_UNSIGNED
"\n", size
);
2485 unsigned int flags
;
2486 /* When we are on a non-section anchor target, we can get zero-sized
2487 items here. However, all we need to do is to bump them to one byte
2488 and the section alignment will take care of the rest. */
2489 snprintf (secnam
, 64, "__DATA,__%spu_bss%u", ((size
)?"":"zo_"), l2align
);
2491 /* We can't anchor in zerofill sections, because we can't switch
2492 to them and emit a label. */
2493 flags
= SECTION_BSS
|SECTION_WRITE
|SECTION_NO_ANCHOR
;
2494 in_section
= get_section (secnam
, flags
, NULL
);
2495 fprintf (fp
, "\t.zerofill %s,", secnam
);
2496 assemble_name (fp
, name
);
2501 fprintf (fp
, ","HOST_WIDE_INT_PRINT_UNSIGNED
",%u\n", size
, l2align
);
2503 fprintf (fp
, ","HOST_WIDE_INT_PRINT_UNSIGNED
"\n", size
);
2505 (* targetm
.encode_section_info
) (decl
, DECL_RTL (decl
), false);
2508 /* Output a chunk of common, with alignment specified (where the target
2511 darwin_asm_output_aligned_decl_common (FILE *fp
, tree decl
, const char *name
,
2512 unsigned HOST_WIDE_INT size
,
2515 unsigned int l2align
;
2519 /* No corresponding var. */
2522 #ifdef DEBUG_DARWIN_MEM_ALLOCATORS
2523 fprintf (fp
, "# adcom: %s (%d,%d) decl=0x0\n", name
, (int)size
, (int)align
);
2525 darwin_emit_common (fp
, name
, size
, align
);
2529 one
= DECL_ONE_ONLY (decl
);
2530 weak
= (DECL_P (decl
)
2532 && !lookup_attribute ("weak_import",
2533 DECL_ATTRIBUTES (decl
)));
2535 #ifdef DEBUG_DARWIN_MEM_ALLOCATORS
2536 fprintf (fp
, "# adcom: %s (%lld,%d) ro %d cst %d stat %d com %d pub %d"
2537 " weak %d one %d init %lx\n",
2538 name
, (long long)size
, (int)align
, TREE_READONLY (decl
),
2539 TREE_CONSTANT (decl
), TREE_STATIC (decl
), DECL_COMMON (decl
),
2540 TREE_PUBLIC (decl
), weak
, one
, (unsigned long)DECL_INITIAL (decl
));
2543 /* ObjC metadata can get put in BSS because varasm.c decides it's BSS
2544 before the target has a chance to comment. */
2545 if ((meta
= is_objc_metadata (decl
)))
2547 darwin_emit_objc_zeroed (fp
, decl
, name
, size
, DECL_ALIGN (decl
), meta
);
2551 /* We shouldn't be messing with this if the decl has a section name. */
2552 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
);
2554 /* We would rather not have to check this here - but it seems that we might
2555 be passed a decl that should be in coalesced space. */
2558 /* Weak or COMDAT objects are put in mergable sections. */
2559 darwin_emit_weak_or_comdat (fp
, decl
, name
, size
,
2564 /* We should only get here for DECL_COMMON, with a zero init (and, in
2565 principle, only for public symbols too - although we deal with local
2568 /* Check the initializer is OK. */
2569 gcc_assert (DECL_COMMON (decl
)
2570 && ((DECL_INITIAL (decl
) == NULL
)
2571 || (DECL_INITIAL (decl
) == error_mark_node
)
2572 || initializer_zerop (DECL_INITIAL (decl
))));
2574 last_assemble_variable_decl
= decl
;
2576 if (!size
|| !align
)
2577 align
= DECL_ALIGN (decl
);
2579 l2align
= floor_log2 (align
/ BITS_PER_UNIT
);
2580 /* Check we aren't asking for more aligment than the platform allows. */
2581 gcc_assert (l2align
<= L2_MAX_OFILE_ALIGNMENT
);
2583 if (TREE_PUBLIC (decl
) != 0)
2584 darwin_emit_common (fp
, name
, size
, align
);
2586 darwin_emit_local_bss (fp
, decl
, name
, size
, l2align
);
2589 /* Output a chunk of BSS with alignment specfied. */
2591 darwin_asm_output_aligned_decl_local (FILE *fp
, tree decl
, const char *name
,
2592 unsigned HOST_WIDE_INT size
,
2595 unsigned long l2align
;
2599 one
= DECL_ONE_ONLY (decl
);
2600 weak
= (DECL_P (decl
)
2602 && !lookup_attribute ("weak_import",
2603 DECL_ATTRIBUTES (decl
)));
2605 #ifdef DEBUG_DARWIN_MEM_ALLOCATORS
2606 fprintf (fp
, "# adloc: %s (%lld,%d) ro %d cst %d stat %d one %d pub %d"
2607 " weak %d init %lx\n",
2608 name
, (long long)size
, (int)align
, TREE_READONLY (decl
),
2609 TREE_CONSTANT (decl
), TREE_STATIC (decl
), one
, TREE_PUBLIC (decl
),
2610 weak
, (unsigned long)DECL_INITIAL (decl
));
2613 /* ObjC metadata can get put in BSS because varasm.c decides it's BSS
2614 before the target has a chance to comment. */
2615 if ((meta
= is_objc_metadata (decl
)))
2617 darwin_emit_objc_zeroed (fp
, decl
, name
, size
, DECL_ALIGN (decl
), meta
);
2621 /* We shouldn't be messing with this if the decl has a section name. */
2622 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
);
2624 /* We would rather not have to check this here - but it seems that we might
2625 be passed a decl that should be in coalesced space. */
2628 /* Weak or COMDAT objects are put in mergable sections. */
2629 darwin_emit_weak_or_comdat (fp
, decl
, name
, size
,
2634 /* .. and it should be suitable for placement in local mem. */
2635 gcc_assert(!TREE_PUBLIC (decl
) && !DECL_COMMON (decl
));
2636 /* .. and any initializer must be all-zero. */
2637 gcc_assert ((DECL_INITIAL (decl
) == NULL
)
2638 || (DECL_INITIAL (decl
) == error_mark_node
)
2639 || initializer_zerop (DECL_INITIAL (decl
)));
2641 last_assemble_variable_decl
= decl
;
2643 if (!size
|| !align
)
2644 align
= DECL_ALIGN (decl
);
2646 l2align
= floor_log2 (align
/ BITS_PER_UNIT
);
2647 gcc_assert (l2align
<= L2_MAX_OFILE_ALIGNMENT
);
2649 darwin_emit_local_bss (fp
, decl
, name
, size
, l2align
);
2652 /* Emit an assembler directive to set visibility for a symbol. The
2653 only supported visibilities are VISIBILITY_DEFAULT and
2654 VISIBILITY_HIDDEN; the latter corresponds to Darwin's "private
2655 extern". There is no MACH-O equivalent of ELF's
2656 VISIBILITY_INTERNAL or VISIBILITY_PROTECTED. */
2659 darwin_assemble_visibility (tree decl
, int vis
)
2661 if (vis
== VISIBILITY_DEFAULT
)
2663 else if (vis
== VISIBILITY_HIDDEN
|| vis
== VISIBILITY_INTERNAL
)
2665 fputs ("\t.private_extern ", asm_out_file
);
2666 assemble_name (asm_out_file
,
2667 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
))));
2668 fputs ("\n", asm_out_file
);
2671 warning (OPT_Wattributes
, "protected visibility attribute "
2672 "not supported in this configuration; ignored");
2675 /* vec used by darwin_asm_dwarf_section.
2676 Maybe a hash tab would be better here - but the intention is that this is
2677 a very short list (fewer than 16 items) and each entry should (ideally,
2678 eventually) only be presented once.
2680 A structure to hold a dwarf debug section used entry. */
2682 typedef struct GTY(()) dwarf_sect_used_entry
{
2686 dwarf_sect_used_entry
;
2689 /* A list of used __DWARF sections. */
2690 static GTY (()) vec
<dwarf_sect_used_entry
, va_gc
> *dwarf_sect_names_table
;
2692 /* This is called when we are asked to assemble a named section and the
2693 name begins with __DWARF,. We keep a list of the section names (without
2694 the __DWARF, prefix) and use this to emit our required start label on the
2695 first switch to each section. */
2698 darwin_asm_dwarf_section (const char *name
, unsigned int flags
,
2699 tree
ARG_UNUSED (decl
))
2704 dwarf_sect_used_entry
*ref
;
2706 gcc_assert ((flags
& (SECTION_DEBUG
| SECTION_NAMED
))
2707 == (SECTION_DEBUG
| SECTION_NAMED
));
2708 /* We know that the name starts with __DWARF, */
2710 namelen
= strchr (sname
, ',') - sname
;
2711 gcc_assert (namelen
);
2712 if (dwarf_sect_names_table
== NULL
)
2713 vec_alloc (dwarf_sect_names_table
, 16);
2716 dwarf_sect_names_table
->iterate (i
, &ref
);
2721 if (!strcmp (ref
->name
, sname
))
2729 fprintf (asm_out_file
, "\t.section %s\n", name
);
2732 dwarf_sect_used_entry e
;
2733 fprintf (asm_out_file
, "Lsection%.*s:\n", namelen
, sname
);
2735 e
.name
= xstrdup (sname
);
2736 vec_safe_push (dwarf_sect_names_table
, e
);
2740 /* Output a difference of two labels that will be an assembly time
2741 constant if the two labels are local. (.long lab1-lab2 will be
2742 very different if lab1 is at the boundary between two sections; it
2743 will be relocated according to the second section, not the first,
2744 so one ends up with a difference between labels in different
2745 sections, which is bad in the dwarf2 eh context for instance.) */
2747 static int darwin_dwarf_label_counter
;
2750 darwin_asm_output_dwarf_delta (FILE *file
, int size
,
2751 const char *lab1
, const char *lab2
)
2753 int islocaldiff
= (lab1
[0] == '*' && lab1
[1] == 'L'
2754 && lab2
[0] == '*' && lab2
[1] == 'L');
2755 const char *directive
= (size
== 8 ? ".quad" : ".long");
2758 fprintf (file
, "\t.set L$set$%d,", darwin_dwarf_label_counter
);
2760 fprintf (file
, "\t%s\t", directive
);
2762 assemble_name_raw (file
, lab1
);
2763 fprintf (file
, "-");
2764 assemble_name_raw (file
, lab2
);
2766 fprintf (file
, "\n\t%s L$set$%d", directive
, darwin_dwarf_label_counter
++);
2769 /* Output an offset in a DWARF section on Darwin. On Darwin, DWARF section
2770 offsets are not represented using relocs in .o files; either the
2771 section never leaves the .o file, or the linker or other tool is
2772 responsible for parsing the DWARF and updating the offsets. */
2775 darwin_asm_output_dwarf_offset (FILE *file
, int size
, const char * lab
,
2781 gcc_assert (base
->common
.flags
& SECTION_NAMED
);
2782 gcc_assert (strncmp (base
->named
.name
, "__DWARF,", 8) == 0);
2783 gcc_assert (strchr (base
->named
.name
+ 8, ','));
2785 namelen
= strchr (base
->named
.name
+ 8, ',') - (base
->named
.name
+ 8);
2786 sprintf (sname
, "*Lsection%.*s", namelen
, base
->named
.name
+ 8);
2787 darwin_asm_output_dwarf_delta (file
, size
, lab
, sname
);
2790 /* Called from the within the TARGET_ASM_FILE_START for each target. */
2793 darwin_file_start (void)
2795 /* Nothing to do. */
2798 /* Called for the TARGET_ASM_FILE_END hook.
2799 Emit the mach-o pic indirection data, the lto data and, finally a flag
2800 to tell the linker that it can break the file object into sections and
2801 move those around for efficiency. */
2804 darwin_file_end (void)
2806 if (!vec_safe_is_empty (ctors
))
2808 machopic_finish (asm_out_file
);
2809 if (strcmp (lang_hooks
.name
, "GNU C++") == 0)
2811 switch_to_section (darwin_sections
[constructor_section
]);
2812 switch_to_section (darwin_sections
[destructor_section
]);
2813 ASM_OUTPUT_ALIGN (asm_out_file
, 1);
2816 /* If there was LTO assembler output, append it to asm_out_file. */
2817 if (lto_asm_out_name
)
2820 char *buf
, *lto_asm_txt
;
2822 /* Shouldn't be here if we failed to switch back. */
2823 gcc_assert (! saved_asm_out_file
);
2825 lto_asm_out_file
= fopen (lto_asm_out_name
, "r");
2826 if (lto_asm_out_file
== NULL
)
2827 fatal_error ("failed to open temporary file %s with LTO output",
2829 fseek (lto_asm_out_file
, 0, SEEK_END
);
2830 n
= ftell (lto_asm_out_file
);
2833 fseek (lto_asm_out_file
, 0, SEEK_SET
);
2834 lto_asm_txt
= buf
= (char *) xmalloc (n
+ 1);
2835 while (fgets (lto_asm_txt
, n
, lto_asm_out_file
))
2836 fputs (lto_asm_txt
, asm_out_file
);
2837 /* Put a termination label. */
2838 fprintf (asm_out_file
, "\t.section %s,%s,regular,debug\n",
2839 LTO_SEGMENT_NAME
, LTO_SECTS_SECTION
);
2840 fprintf (asm_out_file
, "L_GNU_LTO%d:\t;# end of lto\n",
2842 /* Make sure our termination label stays in this section. */
2843 fputs ("\t.space\t1\n", asm_out_file
);
2846 /* Remove the temporary file. */
2847 fclose (lto_asm_out_file
);
2848 unlink_if_ordinary (lto_asm_out_name
);
2849 free (lto_asm_out_name
);
2852 /* Output the names and indices. */
2853 if (lto_section_names
&& lto_section_names
->length ())
2856 darwin_lto_section_e
*ref
;
2857 /* For now, we'll make the offsets 4 bytes and unaligned - we'll fix
2858 the latter up ourselves. */
2859 const char *op
= integer_asm_op (4,0);
2861 /* Emit the names. */
2862 fprintf (asm_out_file
, "\t.section %s,%s,regular,debug\n",
2863 LTO_SEGMENT_NAME
, LTO_NAMES_SECTION
);
2864 FOR_EACH_VEC_ELT (*lto_section_names
, count
, ref
)
2866 fprintf (asm_out_file
, "L_GNU_LTO_NAME%d:\n", count
);
2867 /* We have to jump through hoops to get the values of the intra-section
2869 fprintf (asm_out_file
,
2870 "\t.set L$gnu$lto$noff%d,L_GNU_LTO_NAME%d-L_GNU_LTO_NAME0\n",
2872 fprintf (asm_out_file
,
2873 "\t.set L$gnu$lto$nsiz%d,L_GNU_LTO_NAME%d-L_GNU_LTO_NAME%d\n",
2874 count
, count
+1, count
);
2875 fprintf (asm_out_file
, "\t.asciz\t\"%s\"\n", ref
->sectname
);
2877 fprintf (asm_out_file
, "L_GNU_LTO_NAME%d:\t;# end\n", lto_section_num
);
2878 /* make sure our termination label stays in this section. */
2879 fputs ("\t.space\t1\n", asm_out_file
);
2881 /* Emit the Index. */
2882 fprintf (asm_out_file
, "\t.section %s,%s,regular,debug\n",
2883 LTO_SEGMENT_NAME
, LTO_INDEX_SECTION
);
2884 fputs ("\t.align\t2\n", asm_out_file
);
2885 fputs ("# Section offset, Section length, Name offset, Name length\n",
2887 FOR_EACH_VEC_ELT (*lto_section_names
, count
, ref
)
2889 fprintf (asm_out_file
, "%s L$gnu$lto$offs%d\t;# %s\n",
2890 op
, count
, ref
->sectname
);
2891 fprintf (asm_out_file
, "%s L$gnu$lto$size%d\n", op
, count
);
2892 fprintf (asm_out_file
, "%s L$gnu$lto$noff%d\n", op
, count
);
2893 fprintf (asm_out_file
, "%s L$gnu$lto$nsiz%d\n", op
, count
);
2897 /* If we have section anchors, then we must prevent the linker from
2898 re-arranging data. */
2899 if (!DARWIN_SECTION_ANCHORS
|| !flag_section_anchors
)
2900 fprintf (asm_out_file
, "\t.subsections_via_symbols\n");
2903 /* TODO: Add a language hook for identifying if a decl is a vtable. */
2904 #define DARWIN_VTABLE_P(DECL) 0
2906 /* Cross-module name binding. Darwin does not support overriding
2907 functions at dynamic-link time, except for vtables in kexts. */
2910 darwin_binds_local_p (const_tree decl
)
2912 return default_binds_local_p_1 (decl
,
2913 TARGET_KEXTABI
&& DARWIN_VTABLE_P (decl
));
2916 /* The Darwin's implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
2917 anchor relative to ".", the current section position. We cannot use
2918 the default one because ASM_OUTPUT_DEF is wrong for Darwin. */
2920 darwin_asm_output_anchor (rtx symbol
)
2922 fprintf (asm_out_file
, "\t.set\t");
2923 assemble_name (asm_out_file
, XSTR (symbol
, 0));
2924 fprintf (asm_out_file
, ", . + " HOST_WIDE_INT_PRINT_DEC
"\n",
2925 SYMBOL_REF_BLOCK_OFFSET (symbol
));
2928 /* Disable section anchoring on any section containing a zero-sized
2931 darwin_use_anchors_for_symbol_p (const_rtx symbol
)
2933 if (DARWIN_SECTION_ANCHORS
&& flag_section_anchors
)
2936 /* If the section contains a zero-sized object it's ineligible. */
2937 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
2938 /* This should have the effect of disabling anchors for vars that follow
2939 any zero-sized one, in a given section. */
2940 if (sect
->common
.flags
& SECTION_NO_ANCHOR
)
2943 /* Also check the normal reasons for suppressing. */
2944 return default_use_anchors_for_symbol_p (symbol
);
2950 /* Set the darwin specific attributes on TYPE. */
2952 darwin_set_default_type_attributes (tree type
)
2954 if (darwin_ms_struct
2955 && TREE_CODE (type
) == RECORD_TYPE
)
2956 TYPE_ATTRIBUTES (type
) = tree_cons (get_identifier ("ms_struct"),
2958 TYPE_ATTRIBUTES (type
));
2961 /* True, iff we're generating code for loadable kernel extensions. */
2964 darwin_kextabi_p (void) {
2965 return flag_apple_kext
;
2969 darwin_override_options (void)
2971 /* Keep track of which (major) version we're generating code for. */
2972 if (darwin_macosx_version_min
)
2974 if (strverscmp (darwin_macosx_version_min
, "10.6") >= 0)
2975 generating_for_darwin_version
= 10;
2976 else if (strverscmp (darwin_macosx_version_min
, "10.5") >= 0)
2977 generating_for_darwin_version
= 9;
2979 /* Earlier versions are not specifically accounted, until required. */
2982 /* In principle, this should be c-family only. However, we really need to
2983 set sensible defaults for LTO as well, since the section selection stuff
2984 should check for correctness re. the ABI. TODO: check and provide the
2985 flags (runtime & ABI) from the lto wrapper). */
2987 /* Unless set, force ABI=2 for NeXT and m64, 0 otherwise. */
2988 if (!global_options_set
.x_flag_objc_abi
)
2989 global_options
.x_flag_objc_abi
2990 = (!flag_next_runtime
)
2993 : (generating_for_darwin_version
>= 9) ? 1
2996 /* Objective-C family ABI 2 is only valid for next/m64 at present. */
2997 if (global_options_set
.x_flag_objc_abi
&& flag_next_runtime
)
2999 if (TARGET_64BIT
&& global_options
.x_flag_objc_abi
< 2)
3000 error_at (UNKNOWN_LOCATION
, "%<-fobjc-abi-version%> >= 2 must be"
3001 " used for %<-m64%> targets with"
3002 " %<-fnext-runtime%>");
3003 if (!TARGET_64BIT
&& global_options
.x_flag_objc_abi
>= 2)
3004 error_at (UNKNOWN_LOCATION
, "%<-fobjc-abi-version%> >= 2 is not"
3005 " supported on %<-m32%> targets with"
3006 " %<-fnext-runtime%>");
3009 /* Don't emit DWARF3/4 unless specifically selected. This is a
3010 workaround for tool bugs. */
3011 if (!global_options_set
.x_dwarf_strict
)
3013 if (!global_options_set
.x_dwarf_version
)
3016 /* Do not allow unwind tables to be generated by default for m32.
3017 fnon-call-exceptions will override this, regardless of what we do. */
3018 if (generating_for_darwin_version
< 10
3019 && !global_options_set
.x_flag_asynchronous_unwind_tables
3021 global_options
.x_flag_asynchronous_unwind_tables
= 0;
3023 /* Disable -freorder-blocks-and-partition when unwind tables are being
3024 emitted for Darwin < 9 (OSX 10.5).
3025 The strategy is, "Unless the User has specifically set/unset an unwind
3026 flag we will switch off -freorder-blocks-and-partition when unwind tables
3027 will be generated". If the User specifically sets flags... we assume
3028 (s)he knows why... */
3029 if (generating_for_darwin_version
< 9
3030 && global_options_set
.x_flag_reorder_blocks_and_partition
3031 && ((global_options
.x_flag_exceptions
/* User, c++, java */
3032 && !global_options_set
.x_flag_exceptions
) /* User specified... */
3033 || (global_options
.x_flag_unwind_tables
3034 && !global_options_set
.x_flag_unwind_tables
)
3035 || (global_options
.x_flag_non_call_exceptions
3036 && !global_options_set
.x_flag_non_call_exceptions
)
3037 || (global_options
.x_flag_asynchronous_unwind_tables
3038 && !global_options_set
.x_flag_asynchronous_unwind_tables
)))
3040 inform (input_location
,
3041 "-freorder-blocks-and-partition does not work with exceptions "
3042 "on this architecture");
3043 flag_reorder_blocks_and_partition
= 0;
3044 flag_reorder_blocks
= 1;
3047 /* FIXME: flag_objc_sjlj_exceptions is no longer needed since there is only
3048 one valid choice of exception scheme for each runtime. */
3049 if (!global_options_set
.x_flag_objc_sjlj_exceptions
)
3050 global_options
.x_flag_objc_sjlj_exceptions
=
3051 flag_next_runtime
&& !TARGET_64BIT
;
3053 /* FIXME: and this could be eliminated then too. */
3054 if (!global_options_set
.x_flag_exceptions
3055 && flag_objc_exceptions
3057 flag_exceptions
= 1;
3059 if (flag_mkernel
|| flag_apple_kext
)
3061 /* -mkernel implies -fapple-kext for C++ */
3062 if (strcmp (lang_hooks
.name
, "GNU C++") == 0)
3063 flag_apple_kext
= 1;
3067 /* No EH in kexts. */
3068 flag_exceptions
= 0;
3069 /* No -fnon-call-exceptions data in kexts. */
3070 flag_non_call_exceptions
= 0;
3071 /* so no tables either.. */
3072 flag_unwind_tables
= 0;
3073 flag_asynchronous_unwind_tables
= 0;
3074 /* We still need to emit branch islands for kernel context. */
3075 darwin_emit_branch_islands
= true;
3078 if (flag_var_tracking_uninit
== 0
3080 && generating_for_darwin_version
>= 9
3081 && (flag_gtoggle
? (debug_info_level
== DINFO_LEVEL_NONE
)
3082 : (debug_info_level
>= DINFO_LEVEL_NORMAL
))
3083 && write_symbols
== DWARF2_DEBUG
)
3084 flag_var_tracking_uninit
= flag_var_tracking
;
3086 if (MACHO_DYNAMIC_NO_PIC_P
)
3089 warning_at (UNKNOWN_LOCATION
, 0,
3090 "%<-mdynamic-no-pic%> overrides %<-fpic%>, %<-fPIC%>,"
3091 " %<-fpie%> or %<-fPIE%>");
3094 else if (flag_pic
== 1)
3096 /* Darwin's -fpic is -fPIC. */
3100 /* It is assumed that branch island stubs are needed for earlier systems. */
3101 if (generating_for_darwin_version
< 9)
3102 darwin_emit_branch_islands
= true;
3104 emit_aligned_common
= true; /* Later systems can support aligned common. */
3106 /* The c_dialect...() macros are not available to us here. */
3107 darwin_running_cxx
= (strstr (lang_hooks
.name
, "C++") != 0);
3111 /* Add $LDBL128 suffix to long double builtins for ppc darwin. */
3114 darwin_patch_builtin (enum built_in_function fncode
)
3116 tree fn
= builtin_decl_explicit (fncode
);
3123 sym
= DECL_ASSEMBLER_NAME (fn
);
3124 newname
= ACONCAT (("_", IDENTIFIER_POINTER (sym
), "$LDBL128", NULL
));
3126 set_user_assembler_name (fn
, newname
);
3128 fn
= builtin_decl_implicit (fncode
);
3130 set_user_assembler_name (fn
, newname
);
3134 darwin_patch_builtins (void)
3136 if (LONG_DOUBLE_TYPE_SIZE
!= 128)
3139 #define PATCH_BUILTIN(fncode) darwin_patch_builtin (fncode);
3140 #define PATCH_BUILTIN_NO64(fncode) \
3141 if (!TARGET_64BIT) \
3142 darwin_patch_builtin (fncode);
3143 #define PATCH_BUILTIN_VARIADIC(fncode) \
3145 && (strverscmp (darwin_macosx_version_min, "10.3.9") >= 0)) \
3146 darwin_patch_builtin (fncode);
3147 #include "darwin-ppc-ldouble-patch.def"
3148 #undef PATCH_BUILTIN
3149 #undef PATCH_BUILTIN_NO64
3150 #undef PATCH_BUILTIN_VARIADIC
3154 /* CFStrings implementation. */
3155 static GTY(()) tree cfstring_class_reference
= NULL_TREE
;
3156 static GTY(()) tree cfstring_type_node
= NULL_TREE
;
3157 static GTY(()) tree ccfstring_type_node
= NULL_TREE
;
3158 static GTY(()) tree pccfstring_type_node
= NULL_TREE
;
3159 static GTY(()) tree pcint_type_node
= NULL_TREE
;
3160 static GTY(()) tree pcchar_type_node
= NULL_TREE
;
3162 static enum built_in_function darwin_builtin_cfstring
;
3164 /* Store all constructed constant CFStrings in a hash table so that
3165 they get uniqued properly. */
3167 typedef struct GTY (()) cfstring_descriptor
{
3168 /* The string literal. */
3170 /* The resulting constant CFString. */
3172 } cfstring_descriptor
;
3174 static GTY ((param_is (struct cfstring_descriptor
))) htab_t cfstring_htab
;
3176 static hashval_t
cfstring_hash (const void *);
3177 static int cfstring_eq (const void *, const void *);
3180 add_builtin_field_decl (tree type
, const char *name
, tree
**chain
)
3182 tree field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
3183 get_identifier (name
), type
);
3187 *chain
= &DECL_CHAIN (field
);
3193 darwin_init_cfstring_builtins (unsigned builtin_cfstring
)
3195 tree cfsfun
, fields
, pccfstring_ftype_pcchar
;
3198 darwin_builtin_cfstring
=
3199 (enum built_in_function
) builtin_cfstring
;
3201 /* struct __builtin_CFString {
3202 const int *isa; (will point at
3203 int flags; __CFConstantStringClassReference)
3208 pcint_type_node
= build_pointer_type
3209 (build_qualified_type (integer_type_node
, TYPE_QUAL_CONST
));
3211 pcchar_type_node
= build_pointer_type
3212 (build_qualified_type (char_type_node
, TYPE_QUAL_CONST
));
3214 cfstring_type_node
= (*lang_hooks
.types
.make_type
) (RECORD_TYPE
);
3216 /* Have to build backwards for finish struct. */
3217 fields
= add_builtin_field_decl (long_integer_type_node
, "length", &chain
);
3218 add_builtin_field_decl (pcchar_type_node
, "str", &chain
);
3219 add_builtin_field_decl (integer_type_node
, "flags", &chain
);
3220 add_builtin_field_decl (pcint_type_node
, "isa", &chain
);
3221 finish_builtin_struct (cfstring_type_node
, "__builtin_CFString",
3224 /* const struct __builtin_CFstring *
3225 __builtin___CFStringMakeConstantString (const char *); */
3227 ccfstring_type_node
= build_qualified_type
3228 (cfstring_type_node
, TYPE_QUAL_CONST
);
3229 pccfstring_type_node
= build_pointer_type (ccfstring_type_node
);
3230 pccfstring_ftype_pcchar
= build_function_type_list
3231 (pccfstring_type_node
, pcchar_type_node
, NULL_TREE
);
3233 cfsfun
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
3234 get_identifier ("__builtin___CFStringMakeConstantString"),
3235 pccfstring_ftype_pcchar
);
3237 TREE_PUBLIC (cfsfun
) = 1;
3238 DECL_EXTERNAL (cfsfun
) = 1;
3239 DECL_ARTIFICIAL (cfsfun
) = 1;
3240 /* Make a lang-specific section - dup_lang_specific_decl makes a new node
3241 in place of the existing, which may be NULL. */
3242 DECL_LANG_SPECIFIC (cfsfun
) = NULL
;
3243 (*lang_hooks
.dup_lang_specific_decl
) (cfsfun
);
3244 DECL_BUILT_IN_CLASS (cfsfun
) = BUILT_IN_MD
;
3245 DECL_FUNCTION_CODE (cfsfun
) = darwin_builtin_cfstring
;
3246 lang_hooks
.builtin_function (cfsfun
);
3248 /* extern int __CFConstantStringClassReference[]; */
3249 cfstring_class_reference
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
3250 get_identifier ("__CFConstantStringClassReference"),
3251 build_array_type (integer_type_node
, NULL_TREE
));
3253 TREE_PUBLIC (cfstring_class_reference
) = 1;
3254 DECL_ARTIFICIAL (cfstring_class_reference
) = 1;
3255 (*lang_hooks
.decls
.pushdecl
) (cfstring_class_reference
);
3256 DECL_EXTERNAL (cfstring_class_reference
) = 1;
3257 rest_of_decl_compilation (cfstring_class_reference
, 0, 0);
3259 /* Initialize the hash table used to hold the constant CFString objects. */
3260 cfstring_htab
= htab_create_ggc (31, cfstring_hash
, cfstring_eq
, NULL
);
3262 return cfstring_type_node
;
3266 darwin_fold_builtin (tree fndecl
, int n_args
, tree
*argp
,
3267 bool ARG_UNUSED (ignore
))
3269 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
3271 if (fcode
== darwin_builtin_cfstring
)
3273 if (!darwin_constant_cfstrings
)
3275 error ("built-in function %qD requires the"
3276 " %<-mconstant-cfstrings%> flag", fndecl
);
3277 return error_mark_node
;
3282 error ("built-in function %qD takes one argument only", fndecl
);
3283 return error_mark_node
;
3286 return darwin_build_constant_cfstring (*argp
);
3293 darwin_rename_builtins (void)
3295 /* The system ___divdc3 routine in libSystem on darwin10 is not
3296 accurate to 1ulp, ours is, so we avoid ever using the system name
3297 for this routine and instead install a non-conflicting name that
3300 When -ffast-math or -funsafe-math-optimizations is given, we can
3301 use the faster version. */
3302 if (!flag_unsafe_math_optimizations
)
3304 enum built_in_function dcode
3305 = (enum built_in_function
)(BUILT_IN_COMPLEX_DIV_MIN
3306 + DCmode
- MIN_MODE_COMPLEX_FLOAT
);
3307 tree fn
= builtin_decl_explicit (dcode
);
3308 /* Fortran and c call TARGET_INIT_BUILTINS and
3309 TARGET_INIT_LIBFUNCS at different times, so we have to put a
3310 call into each to ensure that at least one of them is called
3311 after build_common_builtin_nodes. A better fix is to add a
3312 new hook to run after build_common_builtin_nodes runs. */
3314 set_user_assembler_name (fn
, "___ieee_divdc3");
3315 fn
= builtin_decl_implicit (dcode
);
3317 set_user_assembler_name (fn
, "___ieee_divdc3");
3322 cfstring_hash (const void *ptr
)
3324 tree str
= ((const struct cfstring_descriptor
*)ptr
)->literal
;
3325 const unsigned char *p
= (const unsigned char *) TREE_STRING_POINTER (str
);
3326 int i
, len
= TREE_STRING_LENGTH (str
);
3329 for (i
= 0; i
< len
; i
++)
3330 h
= ((h
* 613) + p
[i
]);
3336 cfstring_eq (const void *ptr1
, const void *ptr2
)
3338 tree str1
= ((const struct cfstring_descriptor
*)ptr1
)->literal
;
3339 tree str2
= ((const struct cfstring_descriptor
*)ptr2
)->literal
;
3340 int len1
= TREE_STRING_LENGTH (str1
);
3342 return (len1
== TREE_STRING_LENGTH (str2
)
3343 && !memcmp (TREE_STRING_POINTER (str1
), TREE_STRING_POINTER (str2
),
3348 darwin_build_constant_cfstring (tree str
)
3350 struct cfstring_descriptor
*desc
, key
;
3356 error ("CFString literal is missing");
3357 return error_mark_node
;
3362 if (TREE_CODE (str
) == ADDR_EXPR
)
3363 str
= TREE_OPERAND (str
, 0);
3365 if (TREE_CODE (str
) != STRING_CST
)
3367 error ("CFString literal expression is not a string constant");
3368 return error_mark_node
;
3371 /* Perhaps we already constructed a constant CFString just like this one? */
3373 loc
= htab_find_slot (cfstring_htab
, &key
, INSERT
);
3374 desc
= (struct cfstring_descriptor
*) *loc
;
3378 tree var
, constructor
, field
;
3379 vec
<constructor_elt
, va_gc
> *v
= NULL
;
3380 int length
= TREE_STRING_LENGTH (str
) - 1;
3382 if (darwin_warn_nonportable_cfstrings
)
3384 const char *s
= TREE_STRING_POINTER (str
);
3387 for (l
= 0; l
< length
; l
++)
3388 if (!s
[l
] || !isascii (s
[l
]))
3390 warning (darwin_warn_nonportable_cfstrings
, "%s in CFString literal",
3391 s
[l
] ? "non-ASCII character" : "embedded NUL");
3396 *loc
= desc
= ggc_alloc_cleared_cfstring_descriptor ();
3397 desc
->literal
= str
;
3400 field
= TYPE_FIELDS (ccfstring_type_node
);
3401 CONSTRUCTOR_APPEND_ELT(v
, NULL_TREE
,
3402 build1 (ADDR_EXPR
, TREE_TYPE (field
),
3403 cfstring_class_reference
));
3405 field
= DECL_CHAIN (field
);
3406 CONSTRUCTOR_APPEND_ELT(v
, NULL_TREE
,
3407 build_int_cst (TREE_TYPE (field
), 0x000007c8));
3409 field
= DECL_CHAIN (field
);
3410 CONSTRUCTOR_APPEND_ELT(v
, NULL_TREE
,
3411 build1 (ADDR_EXPR
, TREE_TYPE (field
), str
));
3413 field
= DECL_CHAIN (field
);
3414 CONSTRUCTOR_APPEND_ELT(v
, NULL_TREE
,
3415 build_int_cst (TREE_TYPE (field
), length
));
3417 constructor
= build_constructor (ccfstring_type_node
, v
);
3418 TREE_READONLY (constructor
) = 1;
3419 TREE_CONSTANT (constructor
) = 1;
3420 TREE_STATIC (constructor
) = 1;
3422 /* Fromage: The C++ flavor of 'build_unary_op' expects constructor nodes
3423 to have the TREE_HAS_CONSTRUCTOR (...) bit set. However, this file is
3424 being built without any knowledge of C++ tree accessors; hence, we shall
3425 use the generic accessor that TREE_HAS_CONSTRUCTOR actually maps to! */
3426 if (darwin_running_cxx
)
3427 TREE_LANG_FLAG_4 (constructor
) = 1; /* TREE_HAS_CONSTRUCTOR */
3429 /* Create an anonymous global variable for this CFString. */
3430 var
= build_decl (input_location
, CONST_DECL
,
3431 NULL
, TREE_TYPE (constructor
));
3432 DECL_ARTIFICIAL (var
) = 1;
3433 TREE_STATIC (var
) = 1;
3434 DECL_INITIAL (var
) = constructor
;
3435 /* FIXME: This should use a translation_unit_decl to indicate file scope. */
3436 DECL_CONTEXT (var
) = NULL_TREE
;
3437 desc
->constructor
= var
;
3440 addr
= build1 (ADDR_EXPR
, pccfstring_type_node
, desc
->constructor
);
3441 TREE_CONSTANT (addr
) = 1;
3447 darwin_cfstring_p (tree str
)
3449 struct cfstring_descriptor key
;
3457 if (TREE_CODE (str
) == ADDR_EXPR
)
3458 str
= TREE_OPERAND (str
, 0);
3460 if (TREE_CODE (str
) != STRING_CST
)
3464 loc
= htab_find_slot (cfstring_htab
, &key
, NO_INSERT
);
3473 darwin_enter_string_into_cfstring_table (tree str
)
3475 struct cfstring_descriptor key
;
3479 loc
= htab_find_slot (cfstring_htab
, &key
, INSERT
);
3483 *loc
= ggc_alloc_cleared_cfstring_descriptor ();
3484 ((struct cfstring_descriptor
*)*loc
)->literal
= str
;
3488 /* Choose named function section based on its frequency. */
3491 darwin_function_section (tree decl
, enum node_frequency freq
,
3492 bool startup
, bool exit
)
3494 /* Decide if we need to put this in a coalescable section. */
3497 && (!DECL_ATTRIBUTES (decl
)
3498 || !lookup_attribute ("weak_import",
3499 DECL_ATTRIBUTES (decl
))));
3501 /* If there is a specified section name, we should not be trying to
3503 if (decl
&& DECL_SECTION_NAME (decl
) != NULL_TREE
)
3504 return get_named_section (decl
, NULL
, 0);
3506 /* Default when there is no function re-ordering. */
3507 if (!flag_reorder_functions
)
3509 ? darwin_sections
[text_coal_section
]
3512 /* Startup code should go to startup subsection unless it is
3513 unlikely executed (this happens especially with function splitting
3514 where we can split away unnecessary parts of static constructors). */
3515 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
3517 ? darwin_sections
[text_startup_coal_section
]
3518 : darwin_sections
[text_startup_section
];
3520 /* Similarly for exit. */
3521 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
3523 ? darwin_sections
[text_exit_coal_section
]
3524 : darwin_sections
[text_exit_section
];
3526 /* Group cold functions together, similarly for hot code. */
3529 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
3531 ? darwin_sections
[text_cold_coal_section
]
3532 : darwin_sections
[text_cold_section
];
3534 case NODE_FREQUENCY_HOT
:
3536 ? darwin_sections
[text_hot_coal_section
]
3537 : darwin_sections
[text_hot_section
];
3541 ? darwin_sections
[text_coal_section
]
3547 /* When a function is partitioned between sections, we need to insert a label
3548 at the start of each new chunk - so that it may become a valid 'atom' for
3549 eh and debug purposes. Without this the linker will emit warnings if one
3550 tries to add line location information (since the switched fragment will
3554 darwin_function_switched_text_sections (FILE *fp
, tree decl
, bool new_is_cold
)
3557 snprintf (buf
, 128, "%s%s",new_is_cold
?"__cold_sect_of_":"__hot_sect_of_",
3558 IDENTIFIER_POINTER (DECL_NAME (decl
)));
3559 /* Make sure we pick up all the relevant quotes etc. */
3560 assemble_name_raw (fp
, (const char *) buf
);
3564 #include "gt-darwin.h"