1 /* Functions for generic Darwin as target machine for GNU C compiler.
2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Apple Computer Inc.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-flags.h"
34 #include "insn-attr.h"
41 #include "langhooks.h"
46 #include "diagnostic-core.h"
52 #include "lto-streamer.h"
54 /* Darwin supports a feature called fix-and-continue, which is used
55 for rapid turn around debugging. When code is compiled with the
56 -mfix-and-continue flag, two changes are made to the generated code
57 that allow the system to do things that it would normally not be
58 able to do easily. These changes allow gdb to load in
59 recompilation of a translation unit that has been changed into a
60 running program and replace existing functions and methods of that
61 translation unit with versions of those functions and methods
62 from the newly compiled translation unit. The new functions access
63 the existing static symbols from the old translation unit, if the
64 symbol existed in the unit to be replaced, and from the new
65 translation unit, otherwise.
67 The changes are to insert 5 nops at the beginning of all functions
68 and to use indirection to get at static symbols. The 5 nops
69 are required by consumers of the generated code. Currently, gdb
70 uses this to patch in a jump to the overriding function, this
71 allows all uses of the old name to forward to the replacement,
72 including existing function pointers and virtual methods. See
73 rs6000_emit_prologue for the code that handles the nop insertions.
75 The added indirection allows gdb to redirect accesses to static
76 symbols from the newly loaded translation unit to the existing
77 symbol, if any. @code{static} symbols are special and are handled by
78 setting the second word in the .non_lazy_symbol_pointer data
79 structure to symbol. See indirect_data for the code that handles
80 the extra indirection, and machopic_output_indirection and its use
81 of MACHO_SYMBOL_STATIC for the code that handles @code{static}
82 symbol indirection. */
84 /* For darwin >= 9 (OSX 10.5) the linker is capable of making the necessary
85 branch islands and we no longer need to emit darwin stubs.
86 However, if we are generating code for earlier systems (or for use in the
87 kernel) the stubs might still be required, and this will be set true. */
88 int darwin_emit_branch_islands = false;
90 /* A flag to determine whether we are running c++ or obj-c++. This has to be
91 settable from non-c-family contexts too (i.e. we can't use the c_dialect_
93 int darwin_running_cxx;
96 section * darwin_sections[NUM_DARWIN_SECTIONS];
98 /* While we transition to using in-tests instead of ifdef'd code. */
100 #define HAVE_lo_sum 0
101 #define gen_macho_high(a,b) (a)
102 #define gen_macho_low(a,b,c) (a)
105 /* True if we're setting __attribute__ ((ms_struct)). */
106 int darwin_ms_struct = false;
108 /* A get_unnamed_section callback used to switch to an ObjC section.
109 DIRECTIVE is as for output_section_asm_op. */
112 output_objc_section_asm_op (const void *directive)
114 static bool been_here = false;
116 /* The NeXT ObjC Runtime requires these sections to be present and in
117 order in the object. The code below implements this by emitting
118 a section header for each ObjC section the first time that an ObjC
119 section is requested. */
122 section *saved_in_section = in_section;
123 static const enum darwin_section_enum tomark[] =
125 /* written, cold -> hot */
126 objc_cat_cls_meth_section,
127 objc_cat_inst_meth_section,
128 objc_string_object_section,
129 objc_constant_string_object_section,
130 objc_selector_refs_section,
131 objc_selector_fixup_section,
132 objc_cls_refs_section,
134 objc_meta_class_section,
135 /* shared, hot -> cold */
136 objc_cls_meth_section,
137 objc_inst_meth_section,
138 objc_protocol_section,
139 objc_class_names_section,
140 objc_meth_var_types_section,
141 objc_meth_var_names_section,
142 objc_category_section,
143 objc_class_vars_section,
144 objc_instance_vars_section,
145 objc_module_info_section,
151 for (i = 0; i < ARRAY_SIZE (tomark); i++)
152 switch_to_section (darwin_sections[tomark[i]]);
153 switch_to_section (saved_in_section);
155 output_section_asm_op (directive);
158 /* Implement TARGET_ASM_INIT_SECTIONS. */
161 darwin_init_sections (void)
163 #define DEF_SECTION(NAME, FLAGS, DIRECTIVE, OBJC) \
164 darwin_sections[NAME] = \
165 get_unnamed_section (FLAGS, (OBJC \
166 ? output_objc_section_asm_op \
167 : output_section_asm_op), \
169 #include "config/darwin-sections.def"
172 readonly_data_section = darwin_sections[const_section];
173 exception_section = darwin_sections[darwin_exception_section];
174 eh_frame_section = darwin_sections[darwin_eh_frame_section];
178 name_needs_quotes (const char *name)
181 while ((c = *name++) != '\0')
183 && c != '.' && c != '$' && c != '_' )
188 /* Return true if SYM_REF can be used without an indirection. */
190 machopic_symbol_defined_p (rtx sym_ref)
192 if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_DEFINED)
195 /* If a symbol references local and is not an extern to this
196 file, then the symbol might be able to declared as defined. */
197 if (SYMBOL_REF_LOCAL_P (sym_ref) && ! SYMBOL_REF_EXTERNAL_P (sym_ref))
199 /* If the symbol references a variable and the variable is a
200 common symbol, then this symbol is not defined. */
201 if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_VARIABLE)
203 tree decl = SYMBOL_REF_DECL (sym_ref);
206 if (DECL_COMMON (decl))
214 /* This module assumes that (const (symbol_ref "foo")) is a legal pic
215 reference, which will not be changed. */
217 enum machopic_addr_class
218 machopic_classify_symbol (rtx sym_ref)
222 function_p = SYMBOL_REF_FUNCTION_P (sym_ref);
223 if (machopic_symbol_defined_p (sym_ref))
225 ? MACHOPIC_DEFINED_FUNCTION : MACHOPIC_DEFINED_DATA);
228 ? MACHOPIC_UNDEFINED_FUNCTION : MACHOPIC_UNDEFINED_DATA);
231 #ifndef TARGET_FIX_AND_CONTINUE
232 #define TARGET_FIX_AND_CONTINUE 0
235 /* Indicate when fix-and-continue style code generation is being used
236 and when a reference to data should be indirected so that it can be
237 rebound in a new translation unit to reference the original instance
238 of that data. Symbol names that are for code generation local to
239 the translation unit are bound to the new translation unit;
240 currently this means symbols that begin with L or _OBJC_;
241 otherwise, we indicate that an indirect reference should be made to
242 permit the runtime to rebind new instances of the translation unit
243 to the original instance of the data. */
246 indirect_data (rtx sym_ref)
251 /* If we aren't generating fix-and-continue code, don't do anything
253 if (TARGET_FIX_AND_CONTINUE == 0)
256 /* Otherwise, all symbol except symbols that begin with L or _OBJC_
257 are indirected. Symbols that begin with L and _OBJC_ are always
258 bound to the current translation unit as they are used for
259 generated local data of the translation unit. */
261 name = XSTR (sym_ref, 0);
263 lprefix = (((name[0] == '*' || name[0] == '&')
264 && (name[1] == 'L' || (name[1] == '"' && name[2] == 'L')))
265 || (strncmp (name, "_OBJC_", 6) == 0));
272 machopic_data_defined_p (rtx sym_ref)
274 if (indirect_data (sym_ref))
277 switch (machopic_classify_symbol (sym_ref))
279 case MACHOPIC_DEFINED_DATA:
280 case MACHOPIC_DEFINED_FUNCTION:
288 machopic_define_symbol (rtx mem)
292 gcc_assert (GET_CODE (mem) == MEM);
293 sym_ref = XEXP (mem, 0);
294 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_DEFINED;
297 /* Return either ORIG or:
299 (const:P (unspec:P [ORIG] UNSPEC_MACHOPIC_OFFSET))
301 depending on MACHO_DYNAMIC_NO_PIC_P. */
303 machopic_gen_offset (rtx orig)
305 if (MACHO_DYNAMIC_NO_PIC_P)
309 /* Play games to avoid marking the function as needing pic if we
310 are being called as part of the cost-estimation process. */
311 if (current_ir_type () != IR_GIMPLE || currently_expanding_to_rtl)
312 crtl->uses_pic_offset_table = 1;
313 orig = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, orig),
314 UNSPEC_MACHOPIC_OFFSET);
315 return gen_rtx_CONST (Pmode, orig);
319 static GTY(()) const char * function_base_func_name;
320 static GTY(()) int current_pic_label_num;
323 machopic_output_function_base_name (FILE *file)
325 const char *current_name;
327 /* If dynamic-no-pic is on, we should not get here. */
328 gcc_assert (!MACHO_DYNAMIC_NO_PIC_P);
329 /* When we are generating _get_pc thunks within stubs, there is no current
331 if (current_function_decl)
334 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
335 if (function_base_func_name != current_name)
337 ++current_pic_label_num;
338 function_base_func_name = current_name;
343 ++current_pic_label_num;
344 function_base_func_name = "L_machopic_stub_dummy";
346 fprintf (file, "L%011d$pb", current_pic_label_num);
349 /* The suffix attached to non-lazy pointer symbols. */
350 #define NON_LAZY_POINTER_SUFFIX "$non_lazy_ptr"
351 /* The suffix attached to stub symbols. */
352 #define STUB_SUFFIX "$stub"
354 typedef struct GTY (()) machopic_indirection
356 /* The SYMBOL_REF for the entity referenced. */
358 /* The name of the stub or non-lazy pointer. */
359 const char * ptr_name;
360 /* True iff this entry is for a stub (as opposed to a non-lazy
363 /* True iff this stub or pointer pointer has been referenced. */
365 } machopic_indirection;
367 /* A table mapping stub names and non-lazy pointer names to
368 SYMBOL_REFs for the stubbed-to and pointed-to entities. */
370 static GTY ((param_is (struct machopic_indirection))) htab_t
371 machopic_indirections;
373 /* Return a hash value for a SLOT in the indirections hash table. */
376 machopic_indirection_hash (const void *slot)
378 const machopic_indirection *p = (const machopic_indirection *) slot;
379 return htab_hash_string (p->ptr_name);
382 /* Returns true if the KEY is the same as that associated with
386 machopic_indirection_eq (const void *slot, const void *key)
388 return strcmp (((const machopic_indirection *) slot)->ptr_name,
389 (const char *) key) == 0;
392 /* Return the name of the non-lazy pointer (if STUB_P is false) or
393 stub (if STUB_B is true) corresponding to the given name. */
396 machopic_indirection_name (rtx sym_ref, bool stub_p)
399 const char *name = XSTR (sym_ref, 0);
400 size_t namelen = strlen (name);
401 machopic_indirection *p;
405 const char *prefix = user_label_prefix;
406 const char *quote = "";
409 id = maybe_get_identifier (name);
414 while (IDENTIFIER_TRANSPARENT_ALIAS (id))
415 id = TREE_CHAIN (id);
418 name = IDENTIFIER_POINTER (id);
419 namelen = strlen (name);
430 needs_quotes = name_needs_quotes (name);
437 suffix = STUB_SUFFIX;
439 suffix = NON_LAZY_POINTER_SUFFIX;
441 buffer = XALLOCAVEC (char, strlen ("&L")
448 /* Construct the name of the non-lazy pointer or stub. */
449 sprintf (buffer, "&%sL%s%s%s%s", quote, prefix, name, suffix, quote);
451 if (!machopic_indirections)
452 machopic_indirections = htab_create_ggc (37,
453 machopic_indirection_hash,
454 machopic_indirection_eq,
457 slot = htab_find_slot_with_hash (machopic_indirections, buffer,
458 htab_hash_string (buffer), INSERT);
461 p = (machopic_indirection *) *slot;
465 p = ggc_alloc_machopic_indirection ();
467 p->ptr_name = xstrdup (buffer);
476 /* Return the name of the stub for the mcount function. */
479 machopic_mcount_stub_name (void)
481 rtx symbol = gen_rtx_SYMBOL_REF (Pmode, "*mcount");
482 return machopic_indirection_name (symbol, /*stub_p=*/true);
485 /* If NAME is the name of a stub or a non-lazy pointer , mark the stub
486 or non-lazy pointer as used -- and mark the object to which the
487 pointer/stub refers as used as well, since the pointer/stub will
488 emit a reference to it. */
491 machopic_validate_stub_or_non_lazy_ptr (const char *name)
493 machopic_indirection *p;
495 p = ((machopic_indirection *)
496 (htab_find_with_hash (machopic_indirections, name,
497 htab_hash_string (name))));
500 const char *real_name;
505 /* Do what output_addr_const will do when we actually call it. */
506 if (SYMBOL_REF_DECL (p->symbol))
507 mark_decl_referenced (SYMBOL_REF_DECL (p->symbol));
509 real_name = targetm.strip_name_encoding (XSTR (p->symbol, 0));
511 id = maybe_get_identifier (real_name);
513 mark_referenced (id);
517 /* Transform ORIG, which may be any data source, to the corresponding
518 source using indirections. */
521 machopic_indirect_data_reference (rtx orig, rtx reg)
525 if (! MACHOPIC_INDIRECT)
528 if (GET_CODE (orig) == SYMBOL_REF)
530 int defined = machopic_data_defined_p (orig);
532 if (defined && MACHO_DYNAMIC_NO_PIC_P)
536 /* Create a new register for CSE opportunities. */
537 rtx hi_reg = (!can_create_pseudo_p () ? reg : gen_reg_rtx (Pmode));
538 emit_insn (gen_macho_high (hi_reg, orig));
539 emit_insn (gen_macho_low (reg, hi_reg, orig));
545 /* some other cpu -- writeme! */
551 if (DARWIN_PPC || HAVE_lo_sum)
552 offset = machopic_gen_offset (orig);
556 rtx hi_sum_reg = (!can_create_pseudo_p ()
558 : gen_reg_rtx (Pmode));
562 emit_insn (gen_rtx_SET (Pmode, hi_sum_reg,
563 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
564 gen_rtx_HIGH (Pmode, offset))));
565 emit_insn (gen_rtx_SET (Pmode, reg,
566 gen_rtx_LO_SUM (Pmode, hi_sum_reg,
567 copy_rtx (offset))));
571 else if (HAVE_lo_sum)
575 emit_insn (gen_rtx_SET (VOIDmode, reg,
576 gen_rtx_HIGH (Pmode, offset)));
577 emit_insn (gen_rtx_SET (VOIDmode, reg,
578 gen_rtx_LO_SUM (Pmode, reg,
579 copy_rtx (offset))));
580 emit_use (pic_offset_table_rtx);
582 orig = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, reg);
587 ptr_ref = (gen_rtx_SYMBOL_REF
589 machopic_indirection_name (orig, /*stub_p=*/false)));
591 SYMBOL_REF_DATA (ptr_ref) = SYMBOL_REF_DATA (orig);
593 ptr_ref = gen_const_mem (Pmode, ptr_ref);
594 machopic_define_symbol (ptr_ref);
598 && MACHO_DYNAMIC_NO_PIC_P)
600 emit_insn (gen_rtx_SET (Pmode, reg, ptr_ref));
606 else if (GET_CODE (orig) == CONST)
608 /* If "(const (plus ...", walk the PLUS and return that result.
609 PLUS processing (below) will restore the "(const ..." if
611 if (GET_CODE (XEXP (orig, 0)) == PLUS)
612 return machopic_indirect_data_reference (XEXP (orig, 0), reg);
616 else if (GET_CODE (orig) == MEM)
619 machopic_indirect_data_reference (XEXP (orig, 0), reg);
622 else if (GET_CODE (orig) == PLUS)
625 /* When the target is i386, this code prevents crashes due to the
626 compiler's ignorance on how to move the PIC base register to
627 other registers. (The reload phase sometimes introduces such
629 if (GET_CODE (XEXP (orig, 0)) == REG
630 && REGNO (XEXP (orig, 0)) == PIC_OFFSET_TABLE_REGNUM
631 /* Prevent the same register from being erroneously used
632 as both the base and index registers. */
633 && (DARWIN_X86 && (GET_CODE (XEXP (orig, 1)) == CONST))
636 emit_move_insn (reg, XEXP (orig, 0));
637 XEXP (ptr_ref, 0) = reg;
641 /* Legitimize both operands of the PLUS. */
642 base = machopic_indirect_data_reference (XEXP (orig, 0), reg);
643 orig = machopic_indirect_data_reference (XEXP (orig, 1),
644 (base == reg ? 0 : reg));
645 if (MACHOPIC_INDIRECT && (GET_CODE (orig) == CONST_INT))
646 result = plus_constant (base, INTVAL (orig));
648 result = gen_rtx_PLUS (Pmode, base, orig);
650 if (MACHOPIC_JUST_INDIRECT && GET_CODE (base) == MEM)
654 emit_move_insn (reg, result);
659 result = force_reg (GET_MODE (result), result);
668 /* Transform TARGET (a MEM), which is a function call target, to the
669 corresponding symbol_stub if necessary. Return a new MEM. */
672 machopic_indirect_call_target (rtx target)
674 if (! darwin_emit_branch_islands)
677 if (GET_CODE (target) != MEM)
680 if (MACHOPIC_INDIRECT
681 && GET_CODE (XEXP (target, 0)) == SYMBOL_REF
682 && !(SYMBOL_REF_FLAGS (XEXP (target, 0))
683 & MACHO_SYMBOL_FLAG_DEFINED))
685 rtx sym_ref = XEXP (target, 0);
686 const char *stub_name = machopic_indirection_name (sym_ref,
688 enum machine_mode mode = GET_MODE (sym_ref);
690 XEXP (target, 0) = gen_rtx_SYMBOL_REF (mode, stub_name);
691 SYMBOL_REF_DATA (XEXP (target, 0)) = SYMBOL_REF_DATA (sym_ref);
692 MEM_READONLY_P (target) = 1;
693 MEM_NOTRAP_P (target) = 1;
700 machopic_legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
704 if (! MACHOPIC_INDIRECT)
707 /* First handle a simple SYMBOL_REF or LABEL_REF */
708 if (GET_CODE (orig) == LABEL_REF
709 || (GET_CODE (orig) == SYMBOL_REF
712 /* addr(foo) = &func+(foo-func) */
713 orig = machopic_indirect_data_reference (orig, reg);
715 if (GET_CODE (orig) == PLUS
716 && GET_CODE (XEXP (orig, 0)) == REG)
719 return force_reg (mode, orig);
721 emit_move_insn (reg, orig);
725 if (GET_CODE (orig) == MEM)
729 gcc_assert (!reload_in_progress);
730 reg = gen_reg_rtx (Pmode);
734 if (MACHO_DYNAMIC_NO_PIC_P
735 && (GET_CODE (XEXP (orig, 0)) == SYMBOL_REF
736 || GET_CODE (XEXP (orig, 0)) == LABEL_REF))
738 #if defined (TARGET_TOC) /* ppc */
739 rtx temp_reg = (!can_create_pseudo_p ()
741 gen_reg_rtx (Pmode));
742 rtx asym = XEXP (orig, 0);
745 emit_insn (gen_macho_high (temp_reg, asym));
746 mem = gen_const_mem (GET_MODE (orig),
747 gen_rtx_LO_SUM (Pmode, temp_reg,
749 emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
751 /* Some other CPU -- WriteMe! but right now there are no other
752 platforms that can use dynamic-no-pic */
758 if (GET_CODE (XEXP (orig, 0)) == SYMBOL_REF
759 || GET_CODE (XEXP (orig, 0)) == LABEL_REF)
761 rtx offset = machopic_gen_offset (XEXP (orig, 0));
762 #if defined (TARGET_TOC) /* i.e., PowerPC */
763 /* Generating a new reg may expose opportunities for
764 common subexpression elimination. */
765 rtx hi_sum_reg = (!can_create_pseudo_p ()
767 : gen_reg_rtx (Pmode));
772 sum = gen_rtx_HIGH (Pmode, offset);
773 if (! MACHO_DYNAMIC_NO_PIC_P)
774 sum = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, sum);
776 emit_insn (gen_rtx_SET (Pmode, hi_sum_reg, sum));
778 mem = gen_const_mem (GET_MODE (orig),
779 gen_rtx_LO_SUM (Pmode,
782 insn = emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
783 set_unique_reg_note (insn, REG_EQUAL, pic_ref);
787 emit_use (gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM));
789 emit_insn (gen_rtx_SET (VOIDmode, reg,
791 gen_rtx_CONST (Pmode,
793 emit_insn (gen_rtx_SET (VOIDmode, reg,
794 gen_rtx_LO_SUM (Pmode, reg,
795 gen_rtx_CONST (Pmode,
796 copy_rtx (offset)))));
797 pic_ref = gen_rtx_PLUS (Pmode,
798 pic_offset_table_rtx, reg);
802 #endif /* HAVE_lo_sum */
804 rtx pic = pic_offset_table_rtx;
805 if (GET_CODE (pic) != REG)
807 emit_move_insn (reg, pic);
811 emit_use (gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM));
814 if (reload_in_progress)
815 df_set_regs_ever_live (REGNO (pic), true);
816 pic_ref = gen_rtx_PLUS (Pmode, pic,
817 machopic_gen_offset (XEXP (orig, 0)));
820 #if !defined (TARGET_TOC)
821 emit_move_insn (reg, pic_ref);
822 pic_ref = gen_const_mem (GET_MODE (orig), reg);
829 if (GET_CODE (orig) == SYMBOL_REF
830 || GET_CODE (orig) == LABEL_REF)
832 rtx offset = machopic_gen_offset (orig);
833 #if defined (TARGET_TOC) /* i.e., PowerPC */
838 gcc_assert (!reload_in_progress);
839 reg = gen_reg_rtx (Pmode);
844 emit_insn (gen_rtx_SET (Pmode, hi_sum_reg,
845 (MACHO_DYNAMIC_NO_PIC_P)
846 ? gen_rtx_HIGH (Pmode, offset)
847 : gen_rtx_PLUS (Pmode,
848 pic_offset_table_rtx,
851 emit_insn (gen_rtx_SET (VOIDmode, reg,
852 gen_rtx_LO_SUM (Pmode,
854 copy_rtx (offset))));
857 emit_insn (gen_rtx_SET (VOIDmode, reg,
858 gen_rtx_HIGH (Pmode, offset)));
859 emit_insn (gen_rtx_SET (VOIDmode, reg,
860 gen_rtx_LO_SUM (Pmode, reg,
861 copy_rtx (offset))));
862 pic_ref = gen_rtx_PLUS (Pmode,
863 pic_offset_table_rtx, reg);
867 #endif /* HAVE_lo_sum */
870 || GET_CODE (orig) == SUBREG)
876 rtx pic = pic_offset_table_rtx;
877 if (GET_CODE (pic) != REG)
879 emit_move_insn (reg, pic);
883 emit_use (pic_offset_table_rtx);
885 if (reload_in_progress)
886 df_set_regs_ever_live (REGNO (pic), true);
887 pic_ref = gen_rtx_PLUS (Pmode,
889 machopic_gen_offset (orig));
894 if (GET_CODE (pic_ref) != REG)
898 emit_move_insn (reg, pic_ref);
903 return force_reg (mode, pic_ref);
912 else if (GET_CODE (orig) == SYMBOL_REF)
915 else if (GET_CODE (orig) == PLUS
916 && (GET_CODE (XEXP (orig, 0)) == MEM
917 || GET_CODE (XEXP (orig, 0)) == SYMBOL_REF
918 || GET_CODE (XEXP (orig, 0)) == LABEL_REF)
919 && XEXP (orig, 0) != pic_offset_table_rtx
920 && GET_CODE (XEXP (orig, 1)) != REG)
924 int is_complex = (GET_CODE (XEXP (orig, 0)) == MEM);
926 base = machopic_legitimize_pic_address (XEXP (orig, 0), Pmode, reg);
927 orig = machopic_legitimize_pic_address (XEXP (orig, 1),
928 Pmode, (base == reg ? 0 : reg));
929 if (GET_CODE (orig) == CONST_INT)
931 pic_ref = plus_constant (base, INTVAL (orig));
935 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
937 if (reg && is_complex)
939 emit_move_insn (reg, pic_ref);
942 /* Likewise, should we set special REG_NOTEs here? */
945 else if (GET_CODE (orig) == CONST)
947 return machopic_legitimize_pic_address (XEXP (orig, 0), Pmode, reg);
950 else if (GET_CODE (orig) == MEM
951 && GET_CODE (XEXP (orig, 0)) == SYMBOL_REF)
953 rtx addr = machopic_legitimize_pic_address (XEXP (orig, 0), Pmode, reg);
954 addr = replace_equiv_address (orig, addr);
955 emit_move_insn (reg, addr);
962 /* Output the stub or non-lazy pointer in *SLOT, if it has been used.
963 DATA is the FILE* for assembly output. Called from
967 machopic_output_indirection (void **slot, void *data)
969 machopic_indirection *p = *((machopic_indirection **) slot);
970 FILE *asm_out_file = (FILE *) data;
972 const char *sym_name;
973 const char *ptr_name;
979 sym_name = XSTR (symbol, 0);
980 ptr_name = p->ptr_name;
988 id = maybe_get_identifier (sym_name);
993 while (IDENTIFIER_TRANSPARENT_ALIAS (id))
994 id = TREE_CHAIN (id);
996 sym_name = IDENTIFIER_POINTER (id);
999 sym = XALLOCAVEC (char, strlen (sym_name) + 2);
1000 if (sym_name[0] == '*' || sym_name[0] == '&')
1001 strcpy (sym, sym_name + 1);
1002 else if (sym_name[0] == '-' || sym_name[0] == '+')
1003 strcpy (sym, sym_name);
1005 sprintf (sym, "%s%s", user_label_prefix, sym_name);
1007 stub = XALLOCAVEC (char, strlen (ptr_name) + 2);
1008 if (ptr_name[0] == '*' || ptr_name[0] == '&')
1009 strcpy (stub, ptr_name + 1);
1011 sprintf (stub, "%s%s", user_label_prefix, ptr_name);
1013 machopic_output_stub (asm_out_file, sym, stub);
1015 else if (! indirect_data (symbol)
1016 && (machopic_symbol_defined_p (symbol)
1017 || SYMBOL_REF_LOCAL_P (symbol)))
1019 switch_to_section (data_section);
1020 assemble_align (GET_MODE_ALIGNMENT (Pmode));
1021 assemble_label (asm_out_file, ptr_name);
1022 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, sym_name),
1023 GET_MODE_SIZE (Pmode),
1024 GET_MODE_ALIGNMENT (Pmode), 1);
1028 rtx init = const0_rtx;
1030 switch_to_section (darwin_sections[machopic_nl_symbol_ptr_section]);
1032 /* Mach-O symbols are passed around in code through indirect
1033 references and the original symbol_ref hasn't passed through
1034 the generic handling and reference-catching in
1035 output_operand, so we need to manually mark weak references
1037 if (SYMBOL_REF_WEAK (symbol))
1039 tree decl = SYMBOL_REF_DECL (symbol);
1040 gcc_assert (DECL_P (decl));
1042 if (decl != NULL_TREE
1043 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl)
1044 /* Handle only actual external-only definitions, not
1045 e.g. extern inline code or variables for which
1046 storage has been allocated. */
1047 && !TREE_STATIC (decl))
1049 fputs ("\t.weak_reference ", asm_out_file);
1050 assemble_name (asm_out_file, sym_name);
1051 fputc ('\n', asm_out_file);
1055 assemble_name (asm_out_file, ptr_name);
1056 fprintf (asm_out_file, ":\n");
1058 fprintf (asm_out_file, "\t.indirect_symbol ");
1059 assemble_name (asm_out_file, sym_name);
1060 fprintf (asm_out_file, "\n");
1062 /* Variables that are marked with MACHO_SYMBOL_STATIC need to
1063 have their symbol name instead of 0 in the second entry of
1064 the non-lazy symbol pointer data structure when they are
1065 defined. This allows the runtime to rebind newer instances
1066 of the translation unit with the original instance of the
1069 if ((SYMBOL_REF_FLAGS (symbol) & MACHO_SYMBOL_STATIC)
1070 && machopic_symbol_defined_p (symbol))
1071 init = gen_rtx_SYMBOL_REF (Pmode, sym_name);
1073 assemble_integer (init, GET_MODE_SIZE (Pmode),
1074 GET_MODE_ALIGNMENT (Pmode), 1);
1081 machopic_finish (FILE *asm_out_file)
1083 if (machopic_indirections)
1084 htab_traverse_noresize (machopic_indirections,
1085 machopic_output_indirection,
1090 machopic_operand_p (rtx op)
1092 if (MACHOPIC_JUST_INDIRECT)
1093 return (GET_CODE (op) == SYMBOL_REF
1094 && machopic_symbol_defined_p (op));
1096 return (GET_CODE (op) == CONST
1097 && GET_CODE (XEXP (op, 0)) == UNSPEC
1098 && XINT (XEXP (op, 0), 1) == UNSPEC_MACHOPIC_OFFSET);
1101 /* This function records whether a given name corresponds to a defined
1102 or undefined function or variable, for machopic_classify_ident to
1106 darwin_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
1110 /* Do the standard encoding things first. */
1111 default_encode_section_info (decl, rtl, first);
1113 if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
1116 sym_ref = XEXP (rtl, 0);
1117 if (TREE_CODE (decl) == VAR_DECL)
1118 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_VARIABLE;
1120 if (!DECL_EXTERNAL (decl)
1121 && (!TREE_PUBLIC (decl) || !DECL_WEAK (decl))
1122 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))
1123 && ((TREE_STATIC (decl)
1124 && (!DECL_COMMON (decl) || !TREE_PUBLIC (decl)))
1125 || (!DECL_COMMON (decl) && DECL_INITIAL (decl)
1126 && DECL_INITIAL (decl) != error_mark_node)))
1127 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_DEFINED;
1129 if (! TREE_PUBLIC (decl))
1130 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_STATIC;
1134 darwin_mark_decl_preserved (const char *name)
1136 fprintf (asm_out_file, "\t.no_dead_strip ");
1137 assemble_name (asm_out_file, name);
1138 fputc ('\n', asm_out_file);
1142 darwin_text_section (int reloc, int weak)
1146 ? darwin_sections[text_unlikely_coal_section]
1147 : unlikely_text_section ());
1150 ? darwin_sections[text_coal_section]
1155 darwin_rodata_section (int weak)
1158 ? darwin_sections[const_coal_section]
1159 : darwin_sections[const_section]);
1163 darwin_mergeable_string_section (tree exp,
1164 unsigned HOST_WIDE_INT align)
1166 if (flag_merge_constants
1167 && TREE_CODE (exp) == STRING_CST
1168 && TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1170 && (int_size_in_bytes (TREE_TYPE (exp))
1171 == TREE_STRING_LENGTH (exp))
1172 && ((size_t) TREE_STRING_LENGTH (exp)
1173 == strlen (TREE_STRING_POINTER (exp)) + 1))
1174 return darwin_sections[cstring_section];
1176 return readonly_data_section;
1179 #ifndef HAVE_GAS_LITERAL16
1180 #define HAVE_GAS_LITERAL16 0
1184 darwin_mergeable_constant_section (tree exp,
1185 unsigned HOST_WIDE_INT align)
1187 enum machine_mode mode = DECL_MODE (exp);
1188 unsigned int modesize = GET_MODE_BITSIZE (mode);
1190 if (flag_merge_constants
1193 && modesize <= align
1196 && (align & (align -1)) == 0)
1198 tree size = TYPE_SIZE_UNIT (TREE_TYPE (exp));
1200 if (TREE_CODE (size) == INTEGER_CST
1201 && TREE_INT_CST_LOW (size) == 4
1202 && TREE_INT_CST_HIGH (size) == 0)
1203 return darwin_sections[literal4_section];
1204 else if (TREE_CODE (size) == INTEGER_CST
1205 && TREE_INT_CST_LOW (size) == 8
1206 && TREE_INT_CST_HIGH (size) == 0)
1207 return darwin_sections[literal8_section];
1208 else if (HAVE_GAS_LITERAL16
1210 && TREE_CODE (size) == INTEGER_CST
1211 && TREE_INT_CST_LOW (size) == 16
1212 && TREE_INT_CST_HIGH (size) == 0)
1213 return darwin_sections[literal16_section];
1215 return readonly_data_section;
1218 return readonly_data_section;
1222 machopic_reloc_rw_mask (void)
1224 return MACHOPIC_INDIRECT ? 3 : 0;
1228 machopic_select_section (tree decl,
1230 unsigned HOST_WIDE_INT align)
1232 bool weak = (DECL_P (decl)
1234 && !lookup_attribute ("weak_import",
1235 DECL_ATTRIBUTES (decl)));
1236 section *base_section = NULL;
1238 switch (categorize_decl_for_section (decl, reloc))
1242 struct cgraph_node *node;
1243 if (decl && TREE_CODE (decl) == FUNCTION_DECL
1244 && (node = cgraph_get_node (decl)) != NULL)
1245 base_section = darwin_function_section (decl,
1247 node->only_called_at_startup,
1248 node->only_called_at_exit);
1250 base_section = darwin_text_section (reloc, weak);
1255 case SECCAT_SRODATA:
1256 base_section = darwin_rodata_section (weak);
1259 case SECCAT_RODATA_MERGE_STR:
1260 base_section = darwin_mergeable_string_section (decl, align);
1263 case SECCAT_RODATA_MERGE_STR_INIT:
1264 base_section = darwin_mergeable_string_section (DECL_INITIAL (decl), align);
1267 case SECCAT_RODATA_MERGE_CONST:
1268 base_section = darwin_mergeable_constant_section (decl, align);
1272 case SECCAT_DATA_REL:
1273 case SECCAT_DATA_REL_LOCAL:
1274 case SECCAT_DATA_REL_RO:
1275 case SECCAT_DATA_REL_RO_LOCAL:
1281 if (TREE_READONLY (decl) || TREE_CONSTANT (decl))
1282 base_section = weak ? darwin_sections[const_data_coal_section]
1283 : darwin_sections[const_data_section];
1285 base_section = weak ? darwin_sections[data_coal_section] : data_section;
1292 /* Darwin weird special cases. */
1293 if (TREE_CODE (decl) == CONSTRUCTOR
1295 && TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
1296 && TYPE_NAME (TREE_TYPE (decl)))
1298 tree name = TYPE_NAME (TREE_TYPE (decl));
1299 if (TREE_CODE (name) == TYPE_DECL)
1300 name = DECL_NAME (name);
1302 if (!strcmp (IDENTIFIER_POINTER (name), "__builtin_ObjCString"))
1304 if (flag_next_runtime)
1305 return darwin_sections[objc_constant_string_object_section];
1307 return darwin_sections[objc_string_object_section];
1309 else if (!strcmp (IDENTIFIER_POINTER (name), "__builtin_CFString"))
1310 return darwin_sections[cfstring_constant_object_section];
1312 return base_section;
1314 else if (TREE_CODE (decl) == VAR_DECL
1316 && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE
1317 && IDENTIFIER_POINTER (DECL_NAME (decl))
1318 && !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "_OBJC_", 6))
1320 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1322 if (!strncmp (name, "_OBJC_CLASS_METHODS_", 20))
1323 return darwin_sections[objc_cls_meth_section];
1324 else if (!strncmp (name, "_OBJC_INSTANCE_METHODS_", 23))
1325 return darwin_sections[objc_inst_meth_section];
1326 else if (!strncmp (name, "_OBJC_CATEGORY_CLASS_METHODS_", 20))
1327 return darwin_sections[objc_cat_cls_meth_section];
1328 else if (!strncmp (name, "_OBJC_CATEGORY_INSTANCE_METHODS_", 23))
1329 return darwin_sections[objc_cat_inst_meth_section];
1330 else if (!strncmp (name, "_OBJC_CLASS_VARIABLES_", 22))
1331 return darwin_sections[objc_class_vars_section];
1332 else if (!strncmp (name, "_OBJC_INSTANCE_VARIABLES_", 25))
1333 return darwin_sections[objc_instance_vars_section];
1334 else if (!strncmp (name, "_OBJC_CLASS_PROTOCOLS_", 22))
1335 return darwin_sections[objc_cat_cls_meth_section];
1336 else if (!strncmp (name, "_OBJC_CLASS_NAME_", 17))
1337 return darwin_sections[objc_class_names_section];
1338 else if (!strncmp (name, "_OBJC_METH_VAR_NAME_", 20))
1339 return darwin_sections[objc_meth_var_names_section];
1340 else if (!strncmp (name, "_OBJC_METH_VAR_TYPE_", 20))
1341 return darwin_sections[objc_meth_var_types_section];
1342 else if (!strncmp (name, "_OBJC_CLASS_REFERENCES", 22))
1343 return darwin_sections[objc_cls_refs_section];
1344 else if (!strncmp (name, "_OBJC_CLASS_", 12))
1345 return darwin_sections[objc_class_section];
1346 else if (!strncmp (name, "_OBJC_METACLASS_", 16))
1347 return darwin_sections[objc_meta_class_section];
1348 else if (!strncmp (name, "_OBJC_CATEGORY_", 15))
1349 return darwin_sections[objc_category_section];
1350 else if (!strncmp (name, "_OBJC_SELECTOR_REFERENCES", 25))
1351 return darwin_sections[objc_selector_refs_section];
1352 else if (!strncmp (name, "_OBJC_SELECTOR_FIXUP", 20))
1353 return darwin_sections[objc_selector_fixup_section];
1354 else if (!strncmp (name, "_OBJC_SYMBOLS", 13))
1355 return darwin_sections[objc_symbols_section];
1356 else if (!strncmp (name, "_OBJC_MODULES", 13))
1357 return darwin_sections[objc_module_info_section];
1358 else if (!strncmp (name, "_OBJC_IMAGE_INFO", 16))
1359 return darwin_sections[objc_image_info_section];
1360 else if (!strncmp (name, "_OBJC_PROTOCOL_INSTANCE_METHODS_", 32))
1361 return darwin_sections[objc_cat_inst_meth_section];
1362 else if (!strncmp (name, "_OBJC_PROTOCOL_CLASS_METHODS_", 29))
1363 return darwin_sections[objc_cat_cls_meth_section];
1364 else if (!strncmp (name, "_OBJC_PROTOCOL_REFS_", 20))
1365 return darwin_sections[objc_cat_cls_meth_section];
1366 else if (!strncmp (name, "_OBJC_PROTOCOL_", 15))
1367 return darwin_sections[objc_protocol_section];
1369 return base_section;
1372 return base_section;
1375 /* This can be called with address expressions as "rtx".
1376 They must go in "const". */
1379 machopic_select_rtx_section (enum machine_mode mode, rtx x,
1380 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
1382 if (GET_MODE_SIZE (mode) == 8
1383 && (GET_CODE (x) == CONST_INT
1384 || GET_CODE (x) == CONST_DOUBLE))
1385 return darwin_sections[literal8_section];
1386 else if (GET_MODE_SIZE (mode) == 4
1387 && (GET_CODE (x) == CONST_INT
1388 || GET_CODE (x) == CONST_DOUBLE))
1389 return darwin_sections[literal4_section];
1390 else if (HAVE_GAS_LITERAL16
1392 && GET_MODE_SIZE (mode) == 16
1393 && (GET_CODE (x) == CONST_INT
1394 || GET_CODE (x) == CONST_DOUBLE
1395 || GET_CODE (x) == CONST_VECTOR))
1396 return darwin_sections[literal16_section];
1397 else if (MACHOPIC_INDIRECT
1398 && (GET_CODE (x) == SYMBOL_REF
1399 || GET_CODE (x) == CONST
1400 || GET_CODE (x) == LABEL_REF))
1401 return darwin_sections[const_data_section];
1403 return darwin_sections[const_section];
1407 machopic_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
1409 if (MACHOPIC_INDIRECT)
1410 switch_to_section (darwin_sections[mod_init_section]);
1412 switch_to_section (darwin_sections[constructor_section]);
1413 assemble_align (POINTER_SIZE);
1414 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1416 if (! MACHOPIC_INDIRECT)
1417 fprintf (asm_out_file, ".reference .constructors_used\n");
1421 machopic_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
1423 if (MACHOPIC_INDIRECT)
1424 switch_to_section (darwin_sections[mod_term_section]);
1426 switch_to_section (darwin_sections[destructor_section]);
1427 assemble_align (POINTER_SIZE);
1428 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1430 if (! MACHOPIC_INDIRECT)
1431 fprintf (asm_out_file, ".reference .destructors_used\n");
1435 darwin_globalize_label (FILE *stream, const char *name)
1437 if (!!strncmp (name, "_OBJC_", 6))
1438 default_globalize_label (stream, name);
1441 /* This routine returns non-zero if 'name' starts with the special objective-c
1442 anonymous file-scope static name. It accommodates c++'s mangling of such
1443 symbols (in this case the symbols will have form _ZL{d}*_OBJC_* d=digit). */
1446 darwin_label_is_anonymous_local_objc_name (const char *name)
1448 const unsigned char *p = (const unsigned char *) name;
1451 if (p[1] == 'Z' && p[2] == 'L')
1454 while (*p >= '0' && *p <= '9')
1457 return (!strncmp ((const char *)p, "_OBJC_", 6));
1460 /* LTO support for Mach-O. */
1462 /* Section names for LTO sections. */
1463 static unsigned int lto_section_names_offset = 0;
1465 /* This is the obstack which we use to allocate the many strings. */
1466 static struct obstack lto_section_names_obstack;
1468 /* Segment name for LTO sections. */
1469 #define LTO_SEGMENT_NAME "__GNU_LTO"
1471 /* Section name for LTO section names section. */
1472 #define LTO_NAMES_SECTION "__section_names"
1474 /* File to temporarily store LTO data. This is appended to asm_out_file
1475 in darwin_end_file. */
1476 static FILE *lto_asm_out_file, *saved_asm_out_file;
1477 static char *lto_asm_out_name;
1479 /* Prepare asm_out_file for LTO output. For darwin, this means hiding
1480 asm_out_file and switching to an alternative output file. */
1482 darwin_asm_lto_start (void)
1484 gcc_assert (! saved_asm_out_file);
1485 saved_asm_out_file = asm_out_file;
1486 if (! lto_asm_out_name)
1487 lto_asm_out_name = make_temp_file (".lto.s");
1488 lto_asm_out_file = fopen (lto_asm_out_name, "a");
1489 if (lto_asm_out_file == NULL)
1490 fatal_error ("failed to open temporary file %s for LTO output",
1492 asm_out_file = lto_asm_out_file;
1495 /* Restore asm_out_file. */
1497 darwin_asm_lto_end (void)
1499 gcc_assert (saved_asm_out_file);
1500 fclose (lto_asm_out_file);
1501 asm_out_file = saved_asm_out_file;
1502 saved_asm_out_file = NULL;
1506 darwin_asm_dwarf_section (const char *name, unsigned int flags, tree decl);
1508 /* Called for the TARGET_ASM_NAMED_SECTION hook. */
1511 darwin_asm_named_section (const char *name,
1513 tree decl ATTRIBUTE_UNUSED)
1515 /* LTO sections go in a special segment __GNU_LTO. We want to replace the
1516 section name with something we can use to represent arbitrary-length
1517 names (section names in Mach-O are at most 16 characters long). */
1518 if (strncmp (name, LTO_SECTION_NAME_PREFIX,
1519 strlen (LTO_SECTION_NAME_PREFIX)) == 0)
1521 /* We expect certain flags to be set... */
1522 gcc_assert ((flags & (SECTION_DEBUG | SECTION_NAMED))
1523 == (SECTION_DEBUG | SECTION_NAMED));
1525 /* Add the section name to the things to output when we end the
1526 current assembler output file.
1527 This is all not very efficient, but that doesn't matter -- this
1528 shouldn't be a hot path in the compiler... */
1529 obstack_1grow (<o_section_names_obstack, '\t');
1530 obstack_grow (<o_section_names_obstack, ".ascii ", 7);
1531 obstack_1grow (<o_section_names_obstack, '"');
1532 obstack_grow (<o_section_names_obstack, name, strlen (name));
1533 obstack_grow (<o_section_names_obstack, "\\0\"\n", 4);
1535 /* Output the dummy section name. */
1536 fprintf (asm_out_file, "\t# %s\n", name);
1537 fprintf (asm_out_file, "\t.section %s,__%08X,regular,debug\n",
1538 LTO_SEGMENT_NAME, lto_section_names_offset);
1540 /* Update the offset for the next section name. Make sure we stay
1541 within reasonable length. */
1542 lto_section_names_offset += strlen (name) + 1;
1543 gcc_assert (lto_section_names_offset > 0
1544 && lto_section_names_offset < ((unsigned) 1 << 31));
1546 else if (strncmp (name, "__DWARF,", 8) == 0)
1547 darwin_asm_dwarf_section (name, flags, decl);
1549 fprintf (asm_out_file, "\t.section %s\n", name);
1553 darwin_unique_section (tree decl ATTRIBUTE_UNUSED, int reloc ATTRIBUTE_UNUSED)
1555 /* Darwin does not use unique sections. */
1558 /* Handle __attribute__ ((apple_kext_compatibility)).
1559 This only applies to darwin kexts for 2.95 compatibility -- it shrinks the
1560 vtable for classes with this attribute (and their descendants) by not
1561 outputting the new 3.0 nondeleting destructor. This means that such
1562 objects CANNOT be allocated on the stack or as globals UNLESS they have
1563 a completely empty `operator delete'.
1564 Luckily, this fits in with the Darwin kext model.
1566 This attribute also disables gcc3's potential overlaying of derived
1567 class data members on the padding at the end of the base class. */
1570 darwin_handle_kext_attribute (tree *node, tree name,
1571 tree args ATTRIBUTE_UNUSED,
1572 int flags ATTRIBUTE_UNUSED,
1575 /* APPLE KEXT stuff -- only applies with pure static C++ code. */
1576 if (! TARGET_KEXTABI)
1578 warning (0, "%qE 2.95 vtable-compatibility attribute applies "
1579 "only when compiling a kext", name);
1581 *no_add_attrs = true;
1583 else if (TREE_CODE (*node) != RECORD_TYPE)
1585 warning (0, "%qE 2.95 vtable-compatibility attribute applies "
1586 "only to C++ classes", name);
1588 *no_add_attrs = true;
1594 /* Handle a "weak_import" attribute; arguments as in
1595 struct attribute_spec.handler. */
1598 darwin_handle_weak_import_attribute (tree *node, tree name,
1599 tree ARG_UNUSED (args),
1600 int ARG_UNUSED (flags),
1601 bool * no_add_attrs)
1603 if (TREE_CODE (*node) != FUNCTION_DECL && TREE_CODE (*node) != VAR_DECL)
1605 warning (OPT_Wattributes, "%qE attribute ignored",
1607 *no_add_attrs = true;
1610 declare_weak (*node);
1615 /* Emit a label for an FDE, making it global and/or weak if appropriate.
1616 The third parameter is nonzero if this is for exception handling.
1617 The fourth parameter is nonzero if this is just a placeholder for an
1618 FDE that we are omitting. */
1621 darwin_emit_unwind_label (FILE *file, tree decl, int for_eh, int empty)
1628 lab = concat (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), ".eh", NULL);
1630 if (TREE_PUBLIC (decl))
1632 targetm.asm_out.globalize_label (file, lab);
1633 if (DECL_VISIBILITY (decl) == VISIBILITY_HIDDEN)
1635 fputs ("\t.private_extern ", file);
1636 assemble_name (file, lab);
1641 if (DECL_WEAK (decl))
1643 fputs ("\t.weak_definition ", file);
1644 assemble_name (file, lab);
1648 assemble_name (file, lab);
1651 fputs (" = 0\n", file);
1653 /* Mark the absolute .eh and .eh1 style labels as needed to
1654 ensure that we don't dead code strip them and keep such
1655 labels from another instantiation point until we can fix this
1656 properly with group comdat support. */
1657 darwin_mark_decl_preserved (lab);
1660 fputs (":\n", file);
1665 static GTY(()) unsigned long except_table_label_num;
1668 darwin_emit_except_table_label (FILE *file)
1670 char section_start_label[30];
1672 ASM_GENERATE_INTERNAL_LABEL (section_start_label, "GCC_except_table",
1673 except_table_label_num++);
1674 ASM_OUTPUT_LABEL (file, section_start_label);
1676 /* Generate a PC-relative reference to a Mach-O non-lazy-symbol. */
1679 darwin_non_lazy_pcrel (FILE *file, rtx addr)
1681 const char *nlp_name;
1683 gcc_assert (GET_CODE (addr) == SYMBOL_REF);
1685 nlp_name = machopic_indirection_name (addr, /*stub_p=*/false);
1686 fputs ("\t.long\t", file);
1687 ASM_OUTPUT_LABELREF (file, nlp_name);
1691 /* The implementation of ASM_DECLARE_CONSTANT_NAME. */
1694 darwin_asm_declare_constant_name (FILE *file, const char *name,
1695 const_tree exp ATTRIBUTE_UNUSED,
1698 assemble_label (file, name);
1700 /* Darwin doesn't support zero-size objects, so give them a byte. */
1705 /* Emit an assembler directive to set visibility for a symbol. The
1706 only supported visibilities are VISIBILITY_DEFAULT and
1707 VISIBILITY_HIDDEN; the latter corresponds to Darwin's "private
1708 extern". There is no MACH-O equivalent of ELF's
1709 VISIBILITY_INTERNAL or VISIBILITY_PROTECTED. */
1712 darwin_assemble_visibility (tree decl, int vis)
1714 if (vis == VISIBILITY_DEFAULT)
1716 else if (vis == VISIBILITY_HIDDEN)
1718 fputs ("\t.private_extern ", asm_out_file);
1719 assemble_name (asm_out_file,
1720 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
1721 fputs ("\n", asm_out_file);
1724 warning (OPT_Wattributes, "internal and protected visibility attributes "
1725 "not supported in this configuration; ignored");
1728 /* VEC Used by darwin_asm_dwarf_section.
1729 Maybe a hash tab would be better here - but the intention is that this is
1730 a very short list (fewer than 16 items) and each entry should (ideally,
1731 eventually) only be presented once.
1733 A structure to hold a dwarf debug section used entry. */
1735 typedef struct GTY(()) dwarf_sect_used_entry {
1739 dwarf_sect_used_entry;
1741 DEF_VEC_O(dwarf_sect_used_entry);
1742 DEF_VEC_ALLOC_O(dwarf_sect_used_entry, gc);
1744 /* A list of used __DWARF sections. */
1745 static GTY (()) VEC (dwarf_sect_used_entry, gc) * dwarf_sect_names_table;
1747 /* This is called when we are asked to assemble a named section and the
1748 name begins with __DWARF,. We keep a list of the section names (without
1749 the __DWARF, prefix) and use this to emit our required start label on the
1750 first switch to each section. */
1753 darwin_asm_dwarf_section (const char *name, unsigned int flags,
1754 tree ARG_UNUSED (decl))
1759 dwarf_sect_used_entry *ref;
1761 gcc_assert ((flags & (SECTION_DEBUG | SECTION_NAMED))
1762 == (SECTION_DEBUG | SECTION_NAMED));
1763 /* We know that the name starts with __DWARF, */
1765 namelen = strchr (sname, ',') - sname;
1766 gcc_assert (namelen);
1767 if (dwarf_sect_names_table == NULL)
1768 dwarf_sect_names_table = VEC_alloc (dwarf_sect_used_entry, gc, 16);
1771 VEC_iterate (dwarf_sect_used_entry, dwarf_sect_names_table, i, ref);
1776 if (!strcmp (ref->name, sname))
1784 fprintf (asm_out_file, "\t.section %s\n", name);
1787 dwarf_sect_used_entry e;
1788 fprintf (asm_out_file, "Lsection%.*s:\n", namelen, sname);
1790 e.name = xstrdup (sname);
1791 VEC_safe_push (dwarf_sect_used_entry, gc, dwarf_sect_names_table, &e);
1795 /* Output a difference of two labels that will be an assembly time
1796 constant if the two labels are local. (.long lab1-lab2 will be
1797 very different if lab1 is at the boundary between two sections; it
1798 will be relocated according to the second section, not the first,
1799 so one ends up with a difference between labels in different
1800 sections, which is bad in the dwarf2 eh context for instance.) */
1802 static int darwin_dwarf_label_counter;
1805 darwin_asm_output_dwarf_delta (FILE *file, int size,
1806 const char *lab1, const char *lab2)
1808 int islocaldiff = (lab1[0] == '*' && lab1[1] == 'L'
1809 && lab2[0] == '*' && lab2[1] == 'L');
1810 const char *directive = (size == 8 ? ".quad" : ".long");
1813 fprintf (file, "\t.set L$set$%d,", darwin_dwarf_label_counter);
1815 fprintf (file, "\t%s\t", directive);
1816 assemble_name_raw (file, lab1);
1817 fprintf (file, "-");
1818 assemble_name_raw (file, lab2);
1820 fprintf (file, "\n\t%s L$set$%d", directive, darwin_dwarf_label_counter++);
1823 /* Output an offset in a DWARF section on Darwin. On Darwin, DWARF section
1824 offsets are not represented using relocs in .o files; either the
1825 section never leaves the .o file, or the linker or other tool is
1826 responsible for parsing the DWARF and updating the offsets. */
1829 darwin_asm_output_dwarf_offset (FILE *file, int size, const char * lab,
1835 gcc_assert (base->common.flags & SECTION_NAMED);
1836 gcc_assert (strncmp (base->named.name, "__DWARF,", 8) == 0);
1837 gcc_assert (strchr (base->named.name + 8, ','));
1839 namelen = strchr (base->named.name + 8, ',') - (base->named.name + 8);
1840 sprintf (sname, "*Lsection%.*s", namelen, base->named.name + 8);
1841 darwin_asm_output_dwarf_delta (file, size, lab, sname);
1844 /* Called from the within the TARGET_ASM_FILE_START for each target.
1845 Initialize the stuff we need for LTO long section names support. */
1848 darwin_file_start (void)
1850 /* We fill this obstack with the complete section text for the lto section
1851 names to write in darwin_file_end. */
1852 obstack_init (<o_section_names_obstack);
1853 lto_section_names_offset = 0;
1856 /* Called for the TARGET_ASM_FILE_END hook.
1857 Emit the mach-o pic indirection data, the lto data and, finally a flag
1858 to tell the linker that it can break the file object into sections and
1859 move those around for efficiency. */
1862 darwin_file_end (void)
1864 const char *lto_section_names;
1866 machopic_finish (asm_out_file);
1867 if (strcmp (lang_hooks.name, "GNU C++") == 0)
1869 switch_to_section (darwin_sections[constructor_section]);
1870 switch_to_section (darwin_sections[destructor_section]);
1871 ASM_OUTPUT_ALIGN (asm_out_file, 1);
1874 /* If there was LTO assembler output, append it to asm_out_file. */
1875 if (lto_asm_out_name)
1878 char *buf, *lto_asm_txt;
1880 /* Shouldn't be here if we failed to switch back. */
1881 gcc_assert (! saved_asm_out_file);
1883 lto_asm_out_file = fopen (lto_asm_out_name, "r");
1884 if (lto_asm_out_file == NULL)
1885 fatal_error ("failed to open temporary file %s with LTO output",
1887 fseek (lto_asm_out_file, 0, SEEK_END);
1888 n = ftell (lto_asm_out_file);
1891 fseek (lto_asm_out_file, 0, SEEK_SET);
1892 lto_asm_txt = buf = (char *) xmalloc (n + 1);
1893 while (fgets (lto_asm_txt, n, lto_asm_out_file))
1894 fputs (lto_asm_txt, asm_out_file);
1897 /* Remove the temporary file. */
1898 fclose (lto_asm_out_file);
1899 unlink_if_ordinary (lto_asm_out_name);
1900 free (lto_asm_out_name);
1903 /* Finish the LTO section names obstack. Don't output anything if
1904 there are no recorded section names. */
1905 obstack_1grow (<o_section_names_obstack, '\0');
1906 lto_section_names = XOBFINISH (<o_section_names_obstack, const char *);
1907 if (strlen (lto_section_names) > 0)
1909 fprintf (asm_out_file,
1910 "\t.section %s,%s,regular,debug\n",
1911 LTO_SEGMENT_NAME, LTO_NAMES_SECTION);
1912 fprintf (asm_out_file,
1913 "\t# Section names in %s are offsets into this table\n",
1915 fprintf (asm_out_file, "%s\n", lto_section_names);
1917 obstack_free (<o_section_names_obstack, NULL);
1919 fprintf (asm_out_file, "\t.subsections_via_symbols\n");
1922 /* TODO: Add a language hook for identifying if a decl is a vtable. */
1923 #define DARWIN_VTABLE_P(DECL) 0
1925 /* Cross-module name binding. Darwin does not support overriding
1926 functions at dynamic-link time, except for vtables in kexts. */
1929 darwin_binds_local_p (const_tree decl)
1931 return default_binds_local_p_1 (decl,
1932 TARGET_KEXTABI && DARWIN_VTABLE_P (decl));
1936 /* See TARGET_ASM_OUTPUT_ANCHOR for why we can't do this yet. */
1937 /* The Darwin's implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
1938 anchor relative to ".", the current section position. We cannot use
1939 the default one because ASM_OUTPUT_DEF is wrong for Darwin. */
1942 darwin_asm_output_anchor (rtx symbol)
1944 fprintf (asm_out_file, "\t.set\t");
1945 assemble_name (asm_out_file, XSTR (symbol, 0));
1946 fprintf (asm_out_file, ", . + " HOST_WIDE_INT_PRINT_DEC "\n",
1947 SYMBOL_REF_BLOCK_OFFSET (symbol));
1951 /* Set the darwin specific attributes on TYPE. */
1953 darwin_set_default_type_attributes (tree type)
1955 if (darwin_ms_struct
1956 && TREE_CODE (type) == RECORD_TYPE)
1957 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("ms_struct"),
1959 TYPE_ATTRIBUTES (type));
1962 /* True, iff we're generating code for loadable kernel extensions. */
1965 darwin_kextabi_p (void) {
1966 return flag_apple_kext;
1970 darwin_override_options (void)
1972 /* Don't emit DWARF3/4 unless specifically selected. This is a
1973 workaround for tool bugs. */
1974 if (dwarf_strict < 0)
1977 /* Disable -freorder-blocks-and-partition for darwin_emit_unwind_label. */
1978 if (flag_reorder_blocks_and_partition
1979 && (targetm.asm_out.emit_unwind_label == darwin_emit_unwind_label))
1981 inform (input_location,
1982 "-freorder-blocks-and-partition does not work with exceptions "
1983 "on this architecture");
1984 flag_reorder_blocks_and_partition = 0;
1985 flag_reorder_blocks = 1;
1988 if (flag_mkernel || flag_apple_kext)
1990 /* -mkernel implies -fapple-kext for C++ */
1991 if (strcmp (lang_hooks.name, "GNU C++") == 0)
1992 flag_apple_kext = 1;
1996 /* No EH in kexts. */
1997 flag_exceptions = 0;
1998 /* No -fnon-call-exceptions data in kexts. */
1999 flag_non_call_exceptions = 0;
2000 /* We still need to emit branch islands for kernel context. */
2001 darwin_emit_branch_islands = true;
2003 if (flag_var_tracking
2004 && strverscmp (darwin_macosx_version_min, "10.5") >= 0
2005 && debug_info_level >= DINFO_LEVEL_NORMAL
2006 && debug_hooks->var_location != do_nothing_debug_hooks.var_location)
2007 flag_var_tracking_uninit = 1;
2009 if (MACHO_DYNAMIC_NO_PIC_P)
2012 warning (0, "-mdynamic-no-pic overrides -fpic or -fPIC");
2015 else if (flag_pic == 1)
2017 /* Darwin's -fpic is -fPIC. */
2021 /* It is assumed that branch island stubs are needed for earlier systems. */
2022 if (darwin_macosx_version_min
2023 && strverscmp (darwin_macosx_version_min, "10.5") < 0)
2024 darwin_emit_branch_islands = true;
2026 /* The c_dialect...() macros are not available to us here. */
2027 darwin_running_cxx = (strstr (lang_hooks.name, "C++") != 0);
2030 /* Add $LDBL128 suffix to long double builtins. */
2033 darwin_patch_builtin (int fncode)
2035 tree fn = built_in_decls[fncode];
2042 sym = DECL_ASSEMBLER_NAME (fn);
2043 newname = ACONCAT (("_", IDENTIFIER_POINTER (sym), "$LDBL128", NULL));
2045 set_user_assembler_name (fn, newname);
2047 fn = implicit_built_in_decls[fncode];
2049 set_user_assembler_name (fn, newname);
2053 darwin_patch_builtins (void)
2055 if (LONG_DOUBLE_TYPE_SIZE != 128)
2058 #define PATCH_BUILTIN(fncode) darwin_patch_builtin (fncode);
2059 #define PATCH_BUILTIN_NO64(fncode) \
2060 if (!TARGET_64BIT) \
2061 darwin_patch_builtin (fncode);
2062 #define PATCH_BUILTIN_VARIADIC(fncode) \
2064 && (strverscmp (darwin_macosx_version_min, "10.3.9") >= 0)) \
2065 darwin_patch_builtin (fncode);
2066 #include "darwin-ppc-ldouble-patch.def"
2067 #undef PATCH_BUILTIN
2068 #undef PATCH_BUILTIN_NO64
2069 #undef PATCH_BUILTIN_VARIADIC
2072 /* CFStrings implementation. */
2073 static GTY(()) tree cfstring_class_reference = NULL_TREE;
2074 static GTY(()) tree cfstring_type_node = NULL_TREE;
2075 static GTY(()) tree ccfstring_type_node = NULL_TREE;
2076 static GTY(()) tree pccfstring_type_node = NULL_TREE;
2077 static GTY(()) tree pcint_type_node = NULL_TREE;
2078 static GTY(()) tree pcchar_type_node = NULL_TREE;
2080 static enum built_in_function DARWIN_BUILTIN_CFSTRINGMAKECONSTANTSTRING;
2082 /* Store all constructed constant CFStrings in a hash table so that
2083 they get uniqued properly. */
2085 typedef struct GTY (()) cfstring_descriptor {
2086 /* The string literal. */
2088 /* The resulting constant CFString. */
2090 } cfstring_descriptor;
2092 static GTY ((param_is (struct cfstring_descriptor))) htab_t cfstring_htab;
2094 static hashval_t cfstring_hash (const void *);
2095 static int cfstring_eq (const void *, const void *);
2098 add_builtin_field_decl (tree type, const char *name, tree **chain)
2100 tree field = build_decl (BUILTINS_LOCATION, FIELD_DECL,
2101 get_identifier (name), type);
2105 *chain = &DECL_CHAIN (field);
2111 darwin_init_cfstring_builtins (unsigned first_avail)
2113 tree cfsfun, fields, pccfstring_ftype_pcchar;
2116 DARWIN_BUILTIN_CFSTRINGMAKECONSTANTSTRING =
2117 (enum built_in_function) first_avail;
2119 /* struct __builtin_CFString {
2120 const int *isa; (will point at
2121 int flags; __CFConstantStringClassReference)
2126 pcint_type_node = build_pointer_type
2127 (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
2129 pcchar_type_node = build_pointer_type
2130 (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
2132 cfstring_type_node = (*lang_hooks.types.make_type) (RECORD_TYPE);
2134 /* Have to build backwards for finish struct. */
2135 fields = add_builtin_field_decl (long_integer_type_node, "length", &chain);
2136 add_builtin_field_decl (pcchar_type_node, "str", &chain);
2137 add_builtin_field_decl (integer_type_node, "flags", &chain);
2138 add_builtin_field_decl (pcint_type_node, "isa", &chain);
2139 finish_builtin_struct (cfstring_type_node, "__builtin_CFString",
2142 /* const struct __builtin_CFstring *
2143 __builtin___CFStringMakeConstantString (const char *); */
2145 ccfstring_type_node = build_qualified_type
2146 (cfstring_type_node, TYPE_QUAL_CONST);
2147 pccfstring_type_node = build_pointer_type (ccfstring_type_node);
2148 pccfstring_ftype_pcchar = build_function_type_list
2149 (pccfstring_type_node, pcchar_type_node, NULL_TREE);
2151 cfsfun = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
2152 get_identifier ("__builtin___CFStringMakeConstantString"),
2153 pccfstring_ftype_pcchar);
2155 TREE_PUBLIC (cfsfun) = 1;
2156 DECL_EXTERNAL (cfsfun) = 1;
2157 DECL_ARTIFICIAL (cfsfun) = 1;
2158 /* Make a lang-specific section - dup_lang_specific_decl makes a new node
2159 in place of the existing, which may be NULL. */
2160 DECL_LANG_SPECIFIC (cfsfun) = NULL;
2161 (*lang_hooks.dup_lang_specific_decl) (cfsfun);
2162 DECL_BUILT_IN_CLASS (cfsfun) = BUILT_IN_MD;
2163 DECL_FUNCTION_CODE (cfsfun) = DARWIN_BUILTIN_CFSTRINGMAKECONSTANTSTRING;
2164 lang_hooks.builtin_function (cfsfun);
2166 /* extern int __CFConstantStringClassReference[]; */
2167 cfstring_class_reference = build_decl (BUILTINS_LOCATION, VAR_DECL,
2168 get_identifier ("__CFConstantStringClassReference"),
2169 build_array_type (integer_type_node, NULL_TREE));
2171 TREE_PUBLIC (cfstring_class_reference) = 1;
2172 DECL_ARTIFICIAL (cfstring_class_reference) = 1;
2173 (*lang_hooks.decls.pushdecl) (cfstring_class_reference);
2174 DECL_EXTERNAL (cfstring_class_reference) = 1;
2175 rest_of_decl_compilation (cfstring_class_reference, 0, 0);
2177 /* Initialize the hash table used to hold the constant CFString objects. */
2178 cfstring_htab = htab_create_ggc (31, cfstring_hash, cfstring_eq, NULL);
2182 darwin_fold_builtin (tree fndecl, int n_args, tree *argp,
2183 bool ARG_UNUSED (ignore))
2185 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
2187 if (fcode == DARWIN_BUILTIN_CFSTRINGMAKECONSTANTSTRING)
2189 if (!darwin_constant_cfstrings)
2191 error ("built-in function %qD requires the"
2192 " %<-mconstant-cfstrings%> flag", fndecl);
2193 return error_mark_node;
2198 error ("built-in function %qD takes one argument only", fndecl);
2199 return error_mark_node;
2202 return darwin_build_constant_cfstring (*argp);
2209 cfstring_hash (const void *ptr)
2211 tree str = ((const struct cfstring_descriptor *)ptr)->literal;
2212 const unsigned char *p = (const unsigned char *) TREE_STRING_POINTER (str);
2213 int i, len = TREE_STRING_LENGTH (str);
2216 for (i = 0; i < len; i++)
2217 h = ((h * 613) + p[i]);
2223 cfstring_eq (const void *ptr1, const void *ptr2)
2225 tree str1 = ((const struct cfstring_descriptor *)ptr1)->literal;
2226 tree str2 = ((const struct cfstring_descriptor *)ptr2)->literal;
2227 int len1 = TREE_STRING_LENGTH (str1);
2229 return (len1 == TREE_STRING_LENGTH (str2)
2230 && !memcmp (TREE_STRING_POINTER (str1), TREE_STRING_POINTER (str2),
2235 darwin_build_constant_cfstring (tree str)
2237 struct cfstring_descriptor *desc, key;
2243 error ("CFString literal is missing");
2244 return error_mark_node;
2249 if (TREE_CODE (str) == ADDR_EXPR)
2250 str = TREE_OPERAND (str, 0);
2252 if (TREE_CODE (str) != STRING_CST)
2254 error ("CFString literal expression is not a string constant");
2255 return error_mark_node;
2258 /* Perhaps we already constructed a constant CFString just like this one? */
2260 loc = htab_find_slot (cfstring_htab, &key, INSERT);
2261 desc = (struct cfstring_descriptor *) *loc;
2265 tree var, constructor, field;
2266 VEC(constructor_elt,gc) *v = NULL;
2267 int length = TREE_STRING_LENGTH (str) - 1;
2269 if (darwin_warn_nonportable_cfstrings)
2271 const char *s = TREE_STRING_POINTER (str);
2274 for (l = 0; l < length; l++)
2275 if (!s[l] || !isascii (s[l]))
2277 warning (darwin_warn_nonportable_cfstrings, "%s in CFString literal",
2278 s[l] ? "non-ASCII character" : "embedded NUL");
2283 *loc = desc = ggc_alloc_cleared_cfstring_descriptor ();
2284 desc->literal = str;
2287 field = TYPE_FIELDS (ccfstring_type_node);
2288 CONSTRUCTOR_APPEND_ELT(v, NULL_TREE,
2289 build1 (ADDR_EXPR, TREE_TYPE (field),
2290 cfstring_class_reference));
2292 field = DECL_CHAIN (field);
2293 CONSTRUCTOR_APPEND_ELT(v, NULL_TREE,
2294 build_int_cst (TREE_TYPE (field), 0x000007c8));
2296 field = DECL_CHAIN (field);
2297 CONSTRUCTOR_APPEND_ELT(v, NULL_TREE,
2298 build1 (ADDR_EXPR, TREE_TYPE (field), str));
2300 field = DECL_CHAIN (field);
2301 CONSTRUCTOR_APPEND_ELT(v, NULL_TREE,
2302 build_int_cst (TREE_TYPE (field), length));
2304 constructor = build_constructor (ccfstring_type_node, v);
2305 TREE_READONLY (constructor) = 1;
2306 TREE_CONSTANT (constructor) = 1;
2307 TREE_STATIC (constructor) = 1;
2309 /* Fromage: The C++ flavor of 'build_unary_op' expects constructor nodes
2310 to have the TREE_HAS_CONSTRUCTOR (...) bit set. However, this file is
2311 being built without any knowledge of C++ tree accessors; hence, we shall
2312 use the generic accessor that TREE_HAS_CONSTRUCTOR actually maps to! */
2313 if (darwin_running_cxx)
2314 TREE_LANG_FLAG_4 (constructor) = 1; /* TREE_HAS_CONSTRUCTOR */
2316 /* Create an anonymous global variable for this CFString. */
2317 var = build_decl (input_location, CONST_DECL,
2318 NULL, TREE_TYPE (constructor));
2319 DECL_ARTIFICIAL (var) = 1;
2320 TREE_STATIC (var) = 1;
2321 DECL_INITIAL (var) = constructor;
2322 /* FIXME: This should use a translation_unit_decl to indicate file scope. */
2323 DECL_CONTEXT (var) = NULL_TREE;
2324 desc->constructor = var;
2327 addr = build1 (ADDR_EXPR, pccfstring_type_node, desc->constructor);
2328 TREE_CONSTANT (addr) = 1;
2334 darwin_cfstring_p (tree str)
2336 struct cfstring_descriptor key;
2344 if (TREE_CODE (str) == ADDR_EXPR)
2345 str = TREE_OPERAND (str, 0);
2347 if (TREE_CODE (str) != STRING_CST)
2351 loc = htab_find_slot (cfstring_htab, &key, NO_INSERT);
2360 darwin_enter_string_into_cfstring_table (tree str)
2362 struct cfstring_descriptor key;
2366 loc = htab_find_slot (cfstring_htab, &key, INSERT);
2370 *loc = ggc_alloc_cleared_cfstring_descriptor ();
2371 ((struct cfstring_descriptor *)*loc)->literal = str;
2375 /* Choose named function section based on its frequency. */
2378 darwin_function_section (tree decl, enum node_frequency freq,
2379 bool startup, bool exit)
2381 /* Startup code should go to startup subsection unless it is
2382 unlikely executed (this happens especially with function splitting
2383 where we can split away unnecesary parts of static constructors. */
2384 if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
2385 return get_named_text_section
2386 (decl, "__TEXT,__startup,regular,pure_instructions", "_startup");
2388 /* Similarly for exit. */
2389 if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
2390 return get_named_text_section (decl,
2391 "__TEXT,__exit,regular,pure_instructions",
2394 /* Group cold functions together, similarly for hot code. */
2397 case NODE_FREQUENCY_UNLIKELY_EXECUTED:
2398 return get_named_text_section
2400 "__TEXT,__unlikely,regular,pure_instructions", "_unlikely");
2401 case NODE_FREQUENCY_HOT:
2402 return get_named_text_section
2403 (decl, "__TEXT,__hot,regular,pure_instructions", "_hot");
2409 #include "gt-darwin.h"