]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/darwin.c
Don't mark statements modified when we are in ipa mode
[thirdparty/gcc.git] / gcc / config / darwin.c
CommitLineData
80d725d7 1/* Functions for generic Darwin as target machine for GNU C compiler.
2be1b07e 2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 2000, 2001, 2002, 2003, 2004,
a7df40d7 3 2005, 2006, 2007, 2008
80d725d7 4 Free Software Foundation, Inc.
5 Contributed by Apple Computer Inc.
6
187b36cf 7This file is part of GCC.
80d725d7 8
187b36cf 9GCC is free software; you can redistribute it and/or modify
80d725d7 10it under the terms of the GNU General Public License as published by
038d1e19 11the Free Software Foundation; either version 3, or (at your option)
80d725d7 12any later version.
13
187b36cf 14GCC is distributed in the hope that it will be useful,
80d725d7 15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
038d1e19 20along with GCC; see the file COPYING3. If not see
21<http://www.gnu.org/licenses/>. */
80d725d7 22
23#include "config.h"
24#include "system.h"
805e22b2 25#include "coretypes.h"
26#include "tm.h"
80d725d7 27#include "rtl.h"
28#include "regs.h"
29#include "hard-reg-set.h"
30#include "real.h"
31#include "insn-config.h"
32#include "conditions.h"
33#include "insn-flags.h"
34#include "output.h"
35#include "insn-attr.h"
36#include "flags.h"
37#include "tree.h"
38#include "expr.h"
39#include "reload.h"
80d725d7 40#include "function.h"
41#include "ggc.h"
d19bd1f0 42#include "langhooks.h"
6d3abfc0 43#include "target.h"
79e2a0ca 44#include "tm_p.h"
690abe5d 45#include "toplev.h"
ab06d2ff 46#include "hashtab.h"
3072d30e 47#include "df.h"
cf756914 48#include "debug.h"
80d725d7 49
f0ed0e8a 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
cb4213cd 57 translation unit with versions of those functions and methods
f0ed0e8a 58 from the newly compiled translation unit. The new functions access
d188633a 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.
f0ed0e8a 62
8063e558 63 The changes are to insert 5 nops at the beginning of all functions
d188633a 64 and to use indirection to get at static symbols. The 5 nops
f0ed0e8a 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,
84cbcde5 68 including existing function pointers and virtual methods. See
f0ed0e8a 69 rs6000_emit_prologue for the code that handles the nop insertions.
b215c058 70
f0ed0e8a 71 The added indirection allows gdb to redirect accesses to static
d188633a 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. */
f0ed0e8a 79
92e4ba7d 80/* Section names. */
81section * darwin_sections[NUM_DARWIN_SECTIONS];
2f14b1f9 82
f720b7c6 83/* True if we're setting __attribute__ ((ms_struct)). */
84int darwin_ms_struct = false;
85
2f14b1f9 86/* A get_unnamed_section callback used to switch to an ObjC section.
87 DIRECTIVE is as for output_section_asm_op. */
88
89static void
90output_objc_section_asm_op (const void *directive)
91{
92e4ba7d 92 static bool been_here = false;
2f14b1f9 93
92e4ba7d 94 if (! been_here)
2f14b1f9 95 {
b215c058 96 static const enum darwin_section_enum tomark[] =
92e4ba7d 97 {
98 /* written, cold -> hot */
99 objc_cat_cls_meth_section,
100 objc_cat_inst_meth_section,
101 objc_string_object_section,
102 objc_constant_string_object_section,
103 objc_selector_refs_section,
104 objc_selector_fixup_section,
105 objc_cls_refs_section,
106 objc_class_section,
107 objc_meta_class_section,
108 /* shared, hot -> cold */
109 objc_cls_meth_section,
110 objc_inst_meth_section,
111 objc_protocol_section,
112 objc_class_names_section,
113 objc_meth_var_types_section,
114 objc_meth_var_names_section,
115 objc_category_section,
116 objc_class_vars_section,
117 objc_instance_vars_section,
118 objc_module_info_section,
119 objc_symbols_section
120 };
121 size_t i;
b215c058 122
92e4ba7d 123 been_here = true;
124 for (i = 0; i < ARRAY_SIZE (tomark); i++)
125 switch_to_section (darwin_sections[tomark[i]]);
2f14b1f9 126 }
127 output_section_asm_op (directive);
128}
129
130/* Implement TARGET_ASM_INIT_SECTIONS. */
131
132void
133darwin_init_sections (void)
134{
92e4ba7d 135#define DEF_SECTION(NAME, FLAGS, DIRECTIVE, OBJC) \
136 darwin_sections[NAME] = \
137 get_unnamed_section (FLAGS, (OBJC \
138 ? output_objc_section_asm_op \
139 : output_section_asm_op), \
140 "\t" DIRECTIVE);
141#include "config/darwin-sections.def"
2f14b1f9 142#undef DEF_SECTION
143
92e4ba7d 144 readonly_data_section = darwin_sections[const_section];
145 exception_section = darwin_sections[darwin_exception_section];
146 eh_frame_section = darwin_sections[darwin_eh_frame_section];
2f14b1f9 147}
f0ed0e8a 148
80d725d7 149int
b40da9a7 150name_needs_quotes (const char *name)
80d725d7 151{
152 int c;
153 while ((c = *name++) != '\0')
37ec5024 154 if (! ISIDNUM (c) && c != '.' && c != '$')
80d725d7 155 return 1;
156 return 0;
157}
158
866318b4 159/* Return true if SYM_REF can be used without an indirection. */
ab06d2ff 160static int
161machopic_symbol_defined_p (rtx sym_ref)
80d725d7 162{
866318b4 163 if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_DEFINED)
164 return true;
165
166 /* If a symbol references local and is not an extern to this
167 file, then the symbol might be able to declared as defined. */
168 if (SYMBOL_REF_LOCAL_P (sym_ref) && ! SYMBOL_REF_EXTERNAL_P (sym_ref))
169 {
170 /* If the symbol references a variable and the variable is a
171 common symbol, then this symbol is not defined. */
172 if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_VARIABLE)
173 {
174 tree decl = SYMBOL_REF_DECL (sym_ref);
175 if (!decl)
176 return true;
177 if (DECL_COMMON (decl))
178 return false;
179 }
180 return true;
181 }
182 return false;
80d725d7 183}
184
ab06d2ff 185/* This module assumes that (const (symbol_ref "foo")) is a legal pic
186 reference, which will not be changed. */
b40da9a7 187
80d725d7 188enum machopic_addr_class
ab06d2ff 189machopic_classify_symbol (rtx sym_ref)
80d725d7 190{
ab06d2ff 191 int flags;
192 bool function_p;
193
194 flags = SYMBOL_REF_FLAGS (sym_ref);
195 function_p = SYMBOL_REF_FUNCTION_P (sym_ref);
196 if (machopic_symbol_defined_p (sym_ref))
b215c058 197 return (function_p
ab06d2ff 198 ? MACHOPIC_DEFINED_FUNCTION : MACHOPIC_DEFINED_DATA);
199 else
b215c058 200 return (function_p
ab06d2ff 201 ? MACHOPIC_UNDEFINED_FUNCTION : MACHOPIC_UNDEFINED_DATA);
80d725d7 202}
203
f0ed0e8a 204#ifndef TARGET_FIX_AND_CONTINUE
205#define TARGET_FIX_AND_CONTINUE 0
206#endif
207
208/* Indicate when fix-and-continue style code generation is being used
209 and when a reference to data should be indirected so that it can be
0975351b 210 rebound in a new translation unit to reference the original instance
f0ed0e8a 211 of that data. Symbol names that are for code generation local to
212 the translation unit are bound to the new translation unit;
213 currently this means symbols that begin with L or _OBJC_;
214 otherwise, we indicate that an indirect reference should be made to
215 permit the runtime to rebind new instances of the translation unit
216 to the original instance of the data. */
217
218static int
219indirect_data (rtx sym_ref)
220{
221 int lprefix;
222 const char *name;
223
c4f8e01f 224 /* If we aren't generating fix-and-continue code, don't do anything
225 special. */
f0ed0e8a 226 if (TARGET_FIX_AND_CONTINUE == 0)
227 return 0;
228
229 /* Otherwise, all symbol except symbols that begin with L or _OBJC_
230 are indirected. Symbols that begin with L and _OBJC_ are always
231 bound to the current translation unit as they are used for
232 generated local data of the translation unit. */
233
234 name = XSTR (sym_ref, 0);
235
236 lprefix = (((name[0] == '*' || name[0] == '&')
237 && (name[1] == 'L' || (name[1] == '"' && name[2] == 'L')))
78a79402 238 || (strncmp (name, "_OBJC_", 6) == 0));
f0ed0e8a 239
240 return ! lprefix;
241}
242
243
80d725d7 244static int
ab06d2ff 245machopic_data_defined_p (rtx sym_ref)
80d725d7 246{
f0ed0e8a 247 if (indirect_data (sym_ref))
248 return 0;
249
ab06d2ff 250 switch (machopic_classify_symbol (sym_ref))
80d725d7 251 {
252 case MACHOPIC_DEFINED_DATA:
3a7ccce8 253 case MACHOPIC_DEFINED_FUNCTION:
80d725d7 254 return 1;
255 default:
256 return 0;
257 }
258}
259
80d725d7 260void
ab06d2ff 261machopic_define_symbol (rtx mem)
80d725d7 262{
ab06d2ff 263 rtx sym_ref;
b215c058 264
27d2baef 265 gcc_assert (GET_CODE (mem) == MEM);
ab06d2ff 266 sym_ref = XEXP (mem, 0);
267 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_DEFINED;
80d725d7 268}
269
fb80456a 270static GTY(()) const char * function_base;
80d725d7 271
a7260dec 272const char *
b40da9a7 273machopic_function_base_name (void)
80d725d7 274{
8f74ae7b 275 /* if dynamic-no-pic is on, we should not get here */
27d2baef 276 gcc_assert (!MACHO_DYNAMIC_NO_PIC_P);
80d725d7 277
b186bdc9 278 if (function_base == NULL)
fb80456a 279 function_base = ggc_alloc_string ("<pic base>", sizeof ("<pic base>"));
b186bdc9 280
18d50ae6 281 crtl->uses_pic_offset_table = 1;
b186bdc9 282
283 return function_base;
284}
285
ab06d2ff 286/* Return a SYMBOL_REF for the PIC function base. */
287
288rtx
289machopic_function_base_sym (void)
290{
291 rtx sym_ref;
292
293 sym_ref = gen_rtx_SYMBOL_REF (Pmode, machopic_function_base_name ());
b215c058 294 SYMBOL_REF_FLAGS (sym_ref)
ab06d2ff 295 |= (MACHO_SYMBOL_FLAG_VARIABLE | MACHO_SYMBOL_FLAG_DEFINED);
296 return sym_ref;
297}
298
b06a3cc3 299/* Return either ORIG or (const:P (minus:P ORIG PIC_BASE)), depending
300 on whether pic_base is NULL or not. */
301static inline rtx
302gen_pic_offset (rtx orig, rtx pic_base)
303{
304 if (!pic_base)
305 return orig;
306 else
307 return gen_rtx_CONST (Pmode, gen_rtx_MINUS (Pmode, orig, pic_base));
308}
309
b186bdc9 310static GTY(()) const char * function_base_func_name;
311static GTY(()) int current_pic_label_num;
312
313void
314machopic_output_function_base_name (FILE *file)
315{
316 const char *current_name;
317
1d60d981 318 /* If dynamic-no-pic is on, we should not get here. */
27d2baef 319 gcc_assert (!MACHO_DYNAMIC_NO_PIC_P);
b40da9a7 320 current_name =
b186bdc9 321 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
3a32429b 322 if (function_base_func_name != current_name)
80d725d7 323 {
80d725d7 324 ++current_pic_label_num;
3a32429b 325 function_base_func_name = current_name;
80d725d7 326 }
b186bdc9 327 fprintf (file, "\"L%011d$pb\"", current_pic_label_num);
80d725d7 328}
329
ab06d2ff 330/* The suffix attached to non-lazy pointer symbols. */
331#define NON_LAZY_POINTER_SUFFIX "$non_lazy_ptr"
332/* The suffix attached to stub symbols. */
333#define STUB_SUFFIX "$stub"
80d725d7 334
ab06d2ff 335typedef struct machopic_indirection GTY (())
80d725d7 336{
ab06d2ff 337 /* The SYMBOL_REF for the entity referenced. */
338 rtx symbol;
6d3abfc0 339 /* The name of the stub or non-lazy pointer. */
340 const char * ptr_name;
ab06d2ff 341 /* True iff this entry is for a stub (as opposed to a non-lazy
342 pointer). */
343 bool stub_p;
344 /* True iff this stub or pointer pointer has been referenced. */
345 bool used;
346} machopic_indirection;
347
348/* A table mapping stub names and non-lazy pointer names to
349 SYMBOL_REFs for the stubbed-to and pointed-to entities. */
350
b215c058 351static GTY ((param_is (struct machopic_indirection))) htab_t
ab06d2ff 352 machopic_indirections;
353
354/* Return a hash value for a SLOT in the indirections hash table. */
355
356static hashval_t
357machopic_indirection_hash (const void *slot)
358{
359 const machopic_indirection *p = (const machopic_indirection *) slot;
6d3abfc0 360 return htab_hash_string (p->ptr_name);
ab06d2ff 361}
b40da9a7 362
ab06d2ff 363/* Returns true if the KEY is the same as that associated with
364 SLOT. */
365
366static int
367machopic_indirection_eq (const void *slot, const void *key)
368{
6d3abfc0 369 return strcmp (((const machopic_indirection *) slot)->ptr_name, key) == 0;
ab06d2ff 370}
80d725d7 371
ab06d2ff 372/* Return the name of the non-lazy pointer (if STUB_P is false) or
373 stub (if STUB_B is true) corresponding to the given name. */
8dfaa51b 374
ab06d2ff 375const char *
376machopic_indirection_name (rtx sym_ref, bool stub_p)
377{
378 char *buffer;
379 const char *name = XSTR (sym_ref, 0);
6d3abfc0 380 size_t namelen = strlen (name);
ab06d2ff 381 machopic_indirection *p;
6d3abfc0 382 void ** slot;
524eafbc 383 bool saw_star = false;
384 bool needs_quotes;
385 const char *suffix;
386 const char *prefix = user_label_prefix;
387 const char *quote = "";
b359164b 388 tree id;
389
390 id = maybe_get_identifier (name);
391 if (id)
392 {
393 tree id_orig = id;
394
395 while (IDENTIFIER_TRANSPARENT_ALIAS (id))
396 id = TREE_CHAIN (id);
397 if (id != id_orig)
398 {
399 name = IDENTIFIER_POINTER (id);
400 namelen = strlen (name);
401 }
402 }
b215c058 403
524eafbc 404 if (name[0] == '*')
8dfaa51b 405 {
524eafbc 406 saw_star = true;
407 prefix = "";
408 ++name;
409 --namelen;
ab06d2ff 410 }
524eafbc 411
412 needs_quotes = name_needs_quotes (name);
413 if (needs_quotes)
ab06d2ff 414 {
524eafbc 415 quote = "\"";
8dfaa51b 416 }
417
524eafbc 418 if (stub_p)
419 suffix = STUB_SUFFIX;
420 else
421 suffix = NON_LAZY_POINTER_SUFFIX;
422
423 buffer = alloca (strlen ("&L")
424 + strlen (prefix)
425 + namelen
426 + strlen (suffix)
427 + 2 * strlen (quote)
428 + 1 /* '\0' */);
429
430 /* Construct the name of the non-lazy pointer or stub. */
431 sprintf (buffer, "&%sL%s%s%s%s", quote, prefix, name, suffix, quote);
432
6d3abfc0 433 if (!machopic_indirections)
b215c058 434 machopic_indirections = htab_create_ggc (37,
6d3abfc0 435 machopic_indirection_hash,
436 machopic_indirection_eq,
437 /*htab_del=*/NULL);
b215c058 438
6d3abfc0 439 slot = htab_find_slot_with_hash (machopic_indirections, buffer,
440 htab_hash_string (buffer), INSERT);
441 if (*slot)
442 {
443 p = (machopic_indirection *) *slot;
444 }
445 else
ab06d2ff 446 {
ab06d2ff 447 p = (machopic_indirection *) ggc_alloc (sizeof (machopic_indirection));
448 p->symbol = sym_ref;
6d3abfc0 449 p->ptr_name = xstrdup (buffer);
ab06d2ff 450 p->stub_p = stub_p;
6d3abfc0 451 p->used = false;
452 *slot = p;
ab06d2ff 453 }
b215c058 454
6d3abfc0 455 return p->ptr_name;
80d725d7 456}
457
ab06d2ff 458/* Return the name of the stub for the mcount function. */
80d725d7 459
ab06d2ff 460const char*
461machopic_mcount_stub_name (void)
80d725d7 462{
620dd87a 463 rtx symbol = gen_rtx_SYMBOL_REF (Pmode, "*mcount");
464 return machopic_indirection_name (symbol, /*stub_p=*/true);
80d725d7 465}
466
ab06d2ff 467/* If NAME is the name of a stub or a non-lazy pointer , mark the stub
468 or non-lazy pointer as used -- and mark the object to which the
469 pointer/stub refers as used as well, since the pointer/stub will
470 emit a reference to it. */
471
80d725d7 472void
ab06d2ff 473machopic_validate_stub_or_non_lazy_ptr (const char *name)
80d725d7 474{
ab06d2ff 475 machopic_indirection *p;
b215c058 476
477 p = ((machopic_indirection *)
6d3abfc0 478 (htab_find_with_hash (machopic_indirections, name,
479 htab_hash_string (name))));
480 if (p && ! p->used)
ab06d2ff 481 {
6d3abfc0 482 const char *real_name;
483 tree id;
b215c058 484
6d3abfc0 485 p->used = true;
486
09e39ca0 487 /* Do what output_addr_const will do when we actually call it. */
488 if (SYMBOL_REF_DECL (p->symbol))
489 mark_decl_referenced (SYMBOL_REF_DECL (p->symbol));
490
491 real_name = targetm.strip_name_encoding (XSTR (p->symbol, 0));
b215c058 492
6d3abfc0 493 id = maybe_get_identifier (real_name);
494 if (id)
495 mark_referenced (id);
ab06d2ff 496 }
80d725d7 497}
498
499/* Transform ORIG, which may be any data source, to the corresponding
500 source using indirections. */
501
502rtx
b40da9a7 503machopic_indirect_data_reference (rtx orig, rtx reg)
80d725d7 504{
505 rtx ptr_ref = orig;
b40da9a7 506
80d725d7 507 if (! MACHOPIC_INDIRECT)
508 return orig;
509
510 if (GET_CODE (orig) == SYMBOL_REF)
511 {
ab06d2ff 512 int defined = machopic_data_defined_p (orig);
8f74ae7b 513
514 if (defined && MACHO_DYNAMIC_NO_PIC_P)
515 {
516#if defined (TARGET_TOC)
fed0a860 517 /* Create a new register for CSE opportunities. */
e1ba4a27 518 rtx hi_reg = (!can_create_pseudo_p () ? reg : gen_reg_rtx (Pmode));
fed0a860 519 emit_insn (gen_macho_high (hi_reg, orig));
520 emit_insn (gen_macho_low (reg, hi_reg, orig));
8f74ae7b 521#else
522 /* some other cpu -- writeme! */
27d2baef 523 gcc_unreachable ();
8f74ae7b 524#endif
525 return reg;
526 }
527 else if (defined)
80d725d7 528 {
5352873f 529#if defined (TARGET_TOC) || defined (HAVE_lo_sum)
ab06d2ff 530 rtx pic_base = machopic_function_base_sym ();
b06a3cc3 531 rtx offset = gen_pic_offset (orig, pic_base);
5352873f 532#endif
80d725d7 533
534#if defined (TARGET_TOC) /* i.e., PowerPC */
e1ba4a27 535 rtx hi_sum_reg = (!can_create_pseudo_p ()
536 ? reg
537 : gen_reg_rtx (Pmode));
80d725d7 538
27d2baef 539 gcc_assert (reg);
80d725d7 540
37ec5024 541 emit_insn (gen_rtx_SET (Pmode, hi_sum_reg,
542 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
543 gen_rtx_HIGH (Pmode, offset))));
544 emit_insn (gen_rtx_SET (Pmode, reg,
3b4a645f 545 gen_rtx_LO_SUM (Pmode, hi_sum_reg,
546 copy_rtx (offset))));
80d725d7 547
548 orig = reg;
549#else
550#if defined (HAVE_lo_sum)
27d2baef 551 gcc_assert (reg);
80d725d7 552
37ec5024 553 emit_insn (gen_rtx_SET (VOIDmode, reg,
554 gen_rtx_HIGH (Pmode, offset)));
555 emit_insn (gen_rtx_SET (VOIDmode, reg,
3b4a645f 556 gen_rtx_LO_SUM (Pmode, reg,
557 copy_rtx (offset))));
18b42941 558 emit_use (pic_offset_table_rtx);
80d725d7 559
37ec5024 560 orig = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, reg);
80d725d7 561#endif
562#endif
563 return orig;
564 }
565
329f67ae 566 ptr_ref = (gen_rtx_SYMBOL_REF
b215c058 567 (Pmode,
ab06d2ff 568 machopic_indirection_name (orig, /*stub_p=*/false)));
80d725d7 569
7c266bb1 570 SYMBOL_REF_DATA (ptr_ref) = SYMBOL_REF_DATA (orig);
f9226418 571
e265a6da 572 ptr_ref = gen_const_mem (Pmode, ptr_ref);
329f67ae 573 machopic_define_symbol (ptr_ref);
80d725d7 574
575 return ptr_ref;
576 }
577 else if (GET_CODE (orig) == CONST)
578 {
579 rtx base, result;
580
581 /* legitimize both operands of the PLUS */
582 if (GET_CODE (XEXP (orig, 0)) == PLUS)
583 {
584 base = machopic_indirect_data_reference (XEXP (XEXP (orig, 0), 0),
585 reg);
586 orig = machopic_indirect_data_reference (XEXP (XEXP (orig, 0), 1),
587 (base == reg ? 0 : reg));
588 }
b40da9a7 589 else
80d725d7 590 return orig;
591
592 if (MACHOPIC_PURE && GET_CODE (orig) == CONST_INT)
b244d4c7 593 result = plus_constant (base, INTVAL (orig));
80d725d7 594 else
37ec5024 595 result = gen_rtx_PLUS (Pmode, base, orig);
80d725d7 596
80d725d7 597 if (MACHOPIC_JUST_INDIRECT && GET_CODE (base) == MEM)
598 {
599 if (reg)
600 {
601 emit_move_insn (reg, result);
602 result = reg;
603 }
604 else
605 {
606 result = force_reg (GET_MODE (result), result);
607 }
608 }
609
610 return result;
611
612 }
613 else if (GET_CODE (orig) == MEM)
614 XEXP (ptr_ref, 0) = machopic_indirect_data_reference (XEXP (orig, 0), reg);
615 /* When the target is i386, this code prevents crashes due to the
616 compiler's ignorance on how to move the PIC base register to
617 other registers. (The reload phase sometimes introduces such
618 insns.) */
619 else if (GET_CODE (orig) == PLUS
620 && GET_CODE (XEXP (orig, 0)) == REG
621 && REGNO (XEXP (orig, 0)) == PIC_OFFSET_TABLE_REGNUM
622#ifdef I386
623 /* Prevent the same register from being erroneously used
624 as both the base and index registers. */
625 && GET_CODE (XEXP (orig, 1)) == CONST
626#endif
627 && reg)
628 {
629 emit_move_insn (reg, XEXP (orig, 0));
630 XEXP (ptr_ref, 0) = reg;
631 }
632 return ptr_ref;
633}
634
80d725d7 635/* Transform TARGET (a MEM), which is a function call target, to the
636 corresponding symbol_stub if necessary. Return a new MEM. */
637
638rtx
b40da9a7 639machopic_indirect_call_target (rtx target)
80d725d7 640{
641 if (GET_CODE (target) != MEM)
642 return target;
643
b215c058 644 if (MACHOPIC_INDIRECT
ab06d2ff 645 && GET_CODE (XEXP (target, 0)) == SYMBOL_REF
646 && !(SYMBOL_REF_FLAGS (XEXP (target, 0))
647 & MACHO_SYMBOL_FLAG_DEFINED))
b40da9a7 648 {
ab06d2ff 649 rtx sym_ref = XEXP (target, 0);
b215c058 650 const char *stub_name = machopic_indirection_name (sym_ref,
ab06d2ff 651 /*stub_p=*/true);
652 enum machine_mode mode = GET_MODE (sym_ref);
b215c058 653
ab06d2ff 654 XEXP (target, 0) = gen_rtx_SYMBOL_REF (mode, stub_name);
7c266bb1 655 SYMBOL_REF_DATA (XEXP (target, 0)) = SYMBOL_REF_DATA (sym_ref);
b04fab2a 656 MEM_READONLY_P (target) = 1;
e265a6da 657 MEM_NOTRAP_P (target) = 1;
80d725d7 658 }
659
660 return target;
661}
662
663rtx
b40da9a7 664machopic_legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
80d725d7 665{
666 rtx pic_ref = orig;
667
8f74ae7b 668 if (! MACHOPIC_INDIRECT)
80d725d7 669 return orig;
670
671 /* First handle a simple SYMBOL_REF or LABEL_REF */
672 if (GET_CODE (orig) == LABEL_REF
673 || (GET_CODE (orig) == SYMBOL_REF
674 ))
675 {
676 /* addr(foo) = &func+(foo-func) */
677 rtx pic_base;
678
679 orig = machopic_indirect_data_reference (orig, reg);
680
b40da9a7 681 if (GET_CODE (orig) == PLUS
80d725d7 682 && GET_CODE (XEXP (orig, 0)) == REG)
683 {
684 if (reg == 0)
685 return force_reg (mode, orig);
686
687 emit_move_insn (reg, orig);
688 return reg;
b40da9a7 689 }
80d725d7 690
b06a3cc3 691 /* if dynamic-no-pic we don't have a pic base */
8f74ae7b 692 if (MACHO_DYNAMIC_NO_PIC_P)
b06a3cc3 693 pic_base = NULL;
8f74ae7b 694 else
ab06d2ff 695 pic_base = machopic_function_base_sym ();
80d725d7 696
697 if (GET_CODE (orig) == MEM)
698 {
699 if (reg == 0)
700 {
27d2baef 701 gcc_assert (!reload_in_progress);
702 reg = gen_reg_rtx (Pmode);
80d725d7 703 }
b40da9a7 704
80d725d7 705#ifdef HAVE_lo_sum
8f74ae7b 706 if (MACHO_DYNAMIC_NO_PIC_P
707 && (GET_CODE (XEXP (orig, 0)) == SYMBOL_REF
708 || GET_CODE (XEXP (orig, 0)) == LABEL_REF))
709 {
710#if defined (TARGET_TOC) /* ppc */
e1ba4a27 711 rtx temp_reg = (!can_create_pseudo_p ()
712 ? reg :
713 gen_reg_rtx (Pmode));
8f74ae7b 714 rtx asym = XEXP (orig, 0);
715 rtx mem;
716
301a5e52 717 emit_insn (gen_macho_high (temp_reg, asym));
e265a6da 718 mem = gen_const_mem (GET_MODE (orig),
3b4a645f 719 gen_rtx_LO_SUM (Pmode, temp_reg,
720 copy_rtx (asym)));
37ec5024 721 emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
8f74ae7b 722#else
c4f8e01f 723 /* Some other CPU -- WriteMe! but right now there are no other
724 platforms that can use dynamic-no-pic */
27d2baef 725 gcc_unreachable ();
8f74ae7b 726#endif
727 pic_ref = reg;
728 }
729 else
b40da9a7 730 if (GET_CODE (XEXP (orig, 0)) == SYMBOL_REF
80d725d7 731 || GET_CODE (XEXP (orig, 0)) == LABEL_REF)
732 {
b06a3cc3 733 rtx offset = gen_pic_offset (XEXP (orig, 0), pic_base);
80d725d7 734#if defined (TARGET_TOC) /* i.e., PowerPC */
735 /* Generating a new reg may expose opportunities for
736 common subexpression elimination. */
e1ba4a27 737 rtx hi_sum_reg = (!can_create_pseudo_p ()
738 ? reg
739 : gen_reg_rtx (Pmode));
37ec5024 740 rtx mem;
741 rtx insn;
742 rtx sum;
b215c058 743
37ec5024 744 sum = gen_rtx_HIGH (Pmode, offset);
745 if (! MACHO_DYNAMIC_NO_PIC_P)
746 sum = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, sum);
80d725d7 747
37ec5024 748 emit_insn (gen_rtx_SET (Pmode, hi_sum_reg, sum));
749
e265a6da 750 mem = gen_const_mem (GET_MODE (orig),
b215c058 751 gen_rtx_LO_SUM (Pmode,
3b4a645f 752 hi_sum_reg,
753 copy_rtx (offset)));
37ec5024 754 insn = emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
24153880 755 set_unique_reg_note (insn, REG_EQUAL, pic_ref);
37ec5024 756
757 pic_ref = reg;
80d725d7 758#else
18b42941 759 emit_use (gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM));
37ec5024 760
761 emit_insn (gen_rtx_SET (VOIDmode, reg,
762 gen_rtx_HIGH (Pmode,
b215c058 763 gen_rtx_CONST (Pmode,
37ec5024 764 offset))));
765 emit_insn (gen_rtx_SET (VOIDmode, reg,
766 gen_rtx_LO_SUM (Pmode, reg,
3b4a645f 767 gen_rtx_CONST (Pmode,
768 copy_rtx (offset)))));
37ec5024 769 pic_ref = gen_rtx_PLUS (Pmode,
770 pic_offset_table_rtx, reg);
80d725d7 771#endif
772 }
773 else
774#endif /* HAVE_lo_sum */
775 {
776 rtx pic = pic_offset_table_rtx;
777 if (GET_CODE (pic) != REG)
778 {
779 emit_move_insn (reg, pic);
780 pic = reg;
781 }
782#if 0
18b42941 783 emit_use (gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM));
80d725d7 784#endif
785
3e111a71 786 if (reload_in_progress)
3072d30e 787 df_set_regs_ever_live (REGNO (pic), true);
b06a3cc3 788 pic_ref = gen_rtx_PLUS (Pmode, pic,
789 gen_pic_offset (XEXP (orig, 0),
790 pic_base));
80d725d7 791 }
b40da9a7 792
80d725d7 793#if !defined (TARGET_TOC)
80d725d7 794 emit_move_insn (reg, pic_ref);
e265a6da 795 pic_ref = gen_const_mem (GET_MODE (orig), reg);
7ba97778 796#endif
80d725d7 797 }
798 else
799 {
800
801#ifdef HAVE_lo_sum
b40da9a7 802 if (GET_CODE (orig) == SYMBOL_REF
80d725d7 803 || GET_CODE (orig) == LABEL_REF)
804 {
b06a3cc3 805 rtx offset = gen_pic_offset (orig, pic_base);
80d725d7 806#if defined (TARGET_TOC) /* i.e., PowerPC */
807 rtx hi_sum_reg;
808
809 if (reg == 0)
810 {
27d2baef 811 gcc_assert (!reload_in_progress);
812 reg = gen_reg_rtx (Pmode);
80d725d7 813 }
b40da9a7 814
80d725d7 815 hi_sum_reg = reg;
816
37ec5024 817 emit_insn (gen_rtx_SET (Pmode, hi_sum_reg,
818 (MACHO_DYNAMIC_NO_PIC_P)
819 ? gen_rtx_HIGH (Pmode, offset)
820 : gen_rtx_PLUS (Pmode,
821 pic_offset_table_rtx,
b215c058 822 gen_rtx_HIGH (Pmode,
37ec5024 823 offset))));
824 emit_insn (gen_rtx_SET (VOIDmode, reg,
825 gen_rtx_LO_SUM (Pmode,
3b4a645f 826 hi_sum_reg,
827 copy_rtx (offset))));
80d725d7 828 pic_ref = reg;
829#else
37ec5024 830 emit_insn (gen_rtx_SET (VOIDmode, reg,
831 gen_rtx_HIGH (Pmode, offset)));
832 emit_insn (gen_rtx_SET (VOIDmode, reg,
3b4a645f 833 gen_rtx_LO_SUM (Pmode, reg,
834 copy_rtx (offset))));
37ec5024 835 pic_ref = gen_rtx_PLUS (Pmode,
836 pic_offset_table_rtx, reg);
80d725d7 837#endif
838 }
839 else
840#endif /* HAVE_lo_sum */
841 {
7a5893fc 842 if (REG_P (orig)
843 || GET_CODE (orig) == SUBREG)
80d725d7 844 {
845 return orig;
846 }
847 else
848 {
849 rtx pic = pic_offset_table_rtx;
850 if (GET_CODE (pic) != REG)
851 {
852 emit_move_insn (reg, pic);
853 pic = reg;
854 }
855#if 0
18b42941 856 emit_use (pic_offset_table_rtx);
80d725d7 857#endif
3e111a71 858 if (reload_in_progress)
3072d30e 859 df_set_regs_ever_live (REGNO (pic), true);
37ec5024 860 pic_ref = gen_rtx_PLUS (Pmode,
861 pic,
b06a3cc3 862 gen_pic_offset (orig, pic_base));
80d725d7 863 }
864 }
865 }
866
80d725d7 867 if (GET_CODE (pic_ref) != REG)
868 {
869 if (reg != 0)
870 {
871 emit_move_insn (reg, pic_ref);
872 return reg;
873 }
874 else
875 {
876 return force_reg (mode, pic_ref);
877 }
878 }
879 else
880 {
881 return pic_ref;
882 }
883 }
884
885 else if (GET_CODE (orig) == SYMBOL_REF)
886 return orig;
887
888 else if (GET_CODE (orig) == PLUS
889 && (GET_CODE (XEXP (orig, 0)) == MEM
890 || GET_CODE (XEXP (orig, 0)) == SYMBOL_REF
891 || GET_CODE (XEXP (orig, 0)) == LABEL_REF)
892 && XEXP (orig, 0) != pic_offset_table_rtx
893 && GET_CODE (XEXP (orig, 1)) != REG)
b40da9a7 894
80d725d7 895 {
896 rtx base;
897 int is_complex = (GET_CODE (XEXP (orig, 0)) == MEM);
898
899 base = machopic_legitimize_pic_address (XEXP (orig, 0), Pmode, reg);
900 orig = machopic_legitimize_pic_address (XEXP (orig, 1),
901 Pmode, (base == reg ? 0 : reg));
902 if (GET_CODE (orig) == CONST_INT)
903 {
b244d4c7 904 pic_ref = plus_constant (base, INTVAL (orig));
80d725d7 905 is_complex = 1;
906 }
907 else
37ec5024 908 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
80d725d7 909
80d725d7 910 if (reg && is_complex)
911 {
912 emit_move_insn (reg, pic_ref);
913 pic_ref = reg;
914 }
915 /* Likewise, should we set special REG_NOTEs here? */
916 }
917
918 else if (GET_CODE (orig) == CONST)
919 {
920 return machopic_legitimize_pic_address (XEXP (orig, 0), Pmode, reg);
921 }
922
923 else if (GET_CODE (orig) == MEM
924 && GET_CODE (XEXP (orig, 0)) == SYMBOL_REF)
925 {
926 rtx addr = machopic_legitimize_pic_address (XEXP (orig, 0), Pmode, reg);
b04fab2a 927 addr = replace_equiv_address (orig, addr);
80d725d7 928 emit_move_insn (reg, addr);
929 pic_ref = reg;
930 }
931
932 return pic_ref;
933}
934
ab06d2ff 935/* Output the stub or non-lazy pointer in *SLOT, if it has been used.
936 DATA is the FILE* for assembly output. Called from
937 htab_traverse. */
80d725d7 938
ab06d2ff 939static int
940machopic_output_indirection (void **slot, void *data)
80d725d7 941{
ab06d2ff 942 machopic_indirection *p = *((machopic_indirection **) slot);
943 FILE *asm_out_file = (FILE *) data;
944 rtx symbol;
945 const char *sym_name;
946 const char *ptr_name;
b215c058 947
ab06d2ff 948 if (!p->used)
949 return 1;
80d725d7 950
ab06d2ff 951 symbol = p->symbol;
952 sym_name = XSTR (symbol, 0);
6d3abfc0 953 ptr_name = p->ptr_name;
b215c058 954
ab06d2ff 955 if (p->stub_p)
80d725d7 956 {
80d725d7 957 char *sym;
958 char *stub;
b359164b 959 tree id;
960
961 id = maybe_get_identifier (sym_name);
962 if (id)
963 {
964 tree id_orig = id;
965
966 while (IDENTIFIER_TRANSPARENT_ALIAS (id))
967 id = TREE_CHAIN (id);
968 if (id != id_orig)
969 sym_name = IDENTIFIER_POINTER (id);
970 }
80d725d7 971
80d725d7 972 sym = alloca (strlen (sym_name) + 2);
973 if (sym_name[0] == '*' || sym_name[0] == '&')
974 strcpy (sym, sym_name + 1);
975 else if (sym_name[0] == '-' || sym_name[0] == '+')
b40da9a7 976 strcpy (sym, sym_name);
80d725d7 977 else
e9764bbb 978 sprintf (sym, "%s%s", user_label_prefix, sym_name);
80d725d7 979
ab06d2ff 980 stub = alloca (strlen (ptr_name) + 2);
981 if (ptr_name[0] == '*' || ptr_name[0] == '&')
982 strcpy (stub, ptr_name + 1);
80d725d7 983 else
ab06d2ff 984 sprintf (stub, "%s%s", user_label_prefix, ptr_name);
80d725d7 985
09e39ca0 986 machopic_output_stub (asm_out_file, sym, stub);
80d725d7 987 }
f0ed0e8a 988 else if (! indirect_data (symbol)
8d806159 989 && (machopic_symbol_defined_p (symbol)
990 || SYMBOL_REF_LOCAL_P (symbol)))
80d725d7 991 {
2f14b1f9 992 switch_to_section (data_section);
ab06d2ff 993 assemble_align (GET_MODE_ALIGNMENT (Pmode));
994 assemble_label (ptr_name);
995 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, sym_name),
996 GET_MODE_SIZE (Pmode),
997 GET_MODE_ALIGNMENT (Pmode), 1);
80d725d7 998 }
ab06d2ff 999 else
1000 {
f0ed0e8a 1001 rtx init = const0_rtx;
1002
92e4ba7d 1003 switch_to_section (darwin_sections[machopic_nl_symbol_ptr_section]);
ab06d2ff 1004 assemble_name (asm_out_file, ptr_name);
1005 fprintf (asm_out_file, ":\n");
b215c058 1006
ab06d2ff 1007 fprintf (asm_out_file, "\t.indirect_symbol ");
1008 assemble_name (asm_out_file, sym_name);
1009 fprintf (asm_out_file, "\n");
b215c058 1010
f0ed0e8a 1011 /* Variables that are marked with MACHO_SYMBOL_STATIC need to
1012 have their symbol name instead of 0 in the second entry of
1013 the non-lazy symbol pointer data structure when they are
1014 defined. This allows the runtime to rebind newer instances
1015 of the translation unit with the original instance of the
d188633a 1016 symbol. */
f0ed0e8a 1017
1018 if ((SYMBOL_REF_FLAGS (symbol) & MACHO_SYMBOL_STATIC)
1019 && machopic_symbol_defined_p (symbol))
1020 init = gen_rtx_SYMBOL_REF (Pmode, sym_name);
1021
1022 assemble_integer (init, GET_MODE_SIZE (Pmode),
ab06d2ff 1023 GET_MODE_ALIGNMENT (Pmode), 1);
1024 }
b215c058 1025
ab06d2ff 1026 return 1;
1027}
1028
1029void
1030machopic_finish (FILE *asm_out_file)
1031{
1032 if (machopic_indirections)
f0ed0e8a 1033 htab_traverse_noresize (machopic_indirections,
ab06d2ff 1034 machopic_output_indirection,
1035 asm_out_file);
80d725d7 1036}
1037
b40da9a7 1038int
1039machopic_operand_p (rtx op)
80d725d7 1040{
1041 if (MACHOPIC_JUST_INDIRECT)
1042 {
1043 while (GET_CODE (op) == CONST)
1044 op = XEXP (op, 0);
1045
1046 if (GET_CODE (op) == SYMBOL_REF)
ab06d2ff 1047 return machopic_symbol_defined_p (op);
80d725d7 1048 else
1049 return 0;
1050 }
1051
1052 while (GET_CODE (op) == CONST)
1053 op = XEXP (op, 0);
1054
1055 if (GET_CODE (op) == MINUS
1056 && GET_CODE (XEXP (op, 0)) == SYMBOL_REF
1057 && GET_CODE (XEXP (op, 1)) == SYMBOL_REF
ab06d2ff 1058 && machopic_symbol_defined_p (XEXP (op, 0))
1059 && machopic_symbol_defined_p (XEXP (op, 1)))
80d725d7 1060 return 1;
1061
80d725d7 1062 return 0;
1063}
8dfaa51b 1064
1065/* This function records whether a given name corresponds to a defined
1066 or undefined function or variable, for machopic_classify_ident to
1067 use later. */
1068
1069void
b40da9a7 1070darwin_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
8dfaa51b 1071{
5a121a91 1072 rtx sym_ref;
8dfaa51b 1073
9af9a32c 1074 /* Do the standard encoding things first. */
1075 default_encode_section_info (decl, rtl, first);
1076
ab06d2ff 1077 if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
1078 return;
9af9a32c 1079
ab06d2ff 1080 sym_ref = XEXP (rtl, 0);
1081 if (TREE_CODE (decl) == VAR_DECL)
1082 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_VARIABLE;
1083
1084 if (!DECL_EXTERNAL (decl)
1dc74225 1085 && (!TREE_PUBLIC (decl) || !DECL_WEAK (decl))
0a3ecdc1 1086 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))
8dfaa51b 1087 && ((TREE_STATIC (decl)
1088 && (!DECL_COMMON (decl) || !TREE_PUBLIC (decl)))
2f4fae92 1089 || (!DECL_COMMON (decl) && DECL_INITIAL (decl)
fd419242 1090 && DECL_INITIAL (decl) != error_mark_node)))
ab06d2ff 1091 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_DEFINED;
f0ed0e8a 1092
d188633a 1093 if (! TREE_PUBLIC (decl))
f0ed0e8a 1094 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_STATIC;
e479d0de 1095}
01d15dc5 1096
9423c9b7 1097void
1098darwin_mark_decl_preserved (const char *name)
1099{
1100 fprintf (asm_out_file, ".no_dead_strip ");
1101 assemble_name (asm_out_file, name);
1102 fputc ('\n', asm_out_file);
1103}
1104
50e6797e 1105static section *
1106darwin_text_section (int reloc, int weak)
52470889 1107{
50e6797e 1108 if (reloc)
1109 return (weak
1110 ? darwin_sections[text_unlikely_coal_section]
1111 : unlikely_text_section ());
7def0f5c 1112 else
50e6797e 1113 return (weak
1114 ? darwin_sections[text_coal_section]
1115 : text_section);
1116}
1117
1118static section *
1119darwin_rodata_section (int weak)
1120{
1121 return (weak
1122 ? darwin_sections[const_coal_section]
1123 : darwin_sections[const_section]);
1124}
b40da9a7 1125
50e6797e 1126static section *
1127darwin_mergeable_string_section (tree exp,
1128 unsigned HOST_WIDE_INT align)
1129{
1130 if (flag_merge_constants
1131 && TREE_CODE (exp) == STRING_CST
1132 && TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1133 && align <= 256
a7df40d7 1134 && (int_size_in_bytes (TREE_TYPE (exp))
1135 == TREE_STRING_LENGTH (exp))
b40da9a7 1136 && ((size_t) TREE_STRING_LENGTH (exp)
a814bad5 1137 == strlen (TREE_STRING_POINTER (exp)) + 1))
92e4ba7d 1138 return darwin_sections[cstring_section];
50e6797e 1139
1140 return readonly_data_section;
1141}
1142
4be92808 1143#ifndef HAVE_GAS_LITERAL16
1144#define HAVE_GAS_LITERAL16 0
1145#endif
1146
50e6797e 1147static section *
1148darwin_mergeable_constant_section (tree exp,
1149 unsigned HOST_WIDE_INT align)
1150{
1151 enum machine_mode mode = DECL_MODE (exp);
1152 unsigned int modesize = GET_MODE_BITSIZE (mode);
1153
1154 if (flag_merge_constants
1155 && mode != VOIDmode
1156 && mode != BLKmode
1157 && modesize <= align
1158 && align >= 8
1159 && align <= 256
1160 && (align & (align -1)) == 0)
52470889 1161 {
853b103d 1162 tree size = TYPE_SIZE_UNIT (TREE_TYPE (exp));
52470889 1163
50e6797e 1164 if (TREE_CODE (size) == INTEGER_CST
1165 && TREE_INT_CST_LOW (size) == 4
1166 && TREE_INT_CST_HIGH (size) == 0)
1167 return darwin_sections[literal4_section];
1168 else if (TREE_CODE (size) == INTEGER_CST
1169 && TREE_INT_CST_LOW (size) == 8
3ebc7dec 1170 && TREE_INT_CST_HIGH (size) == 0)
50e6797e 1171 return darwin_sections[literal8_section];
4be92808 1172 else if (HAVE_GAS_LITERAL16
1173 && TARGET_64BIT
50e6797e 1174 && TREE_CODE (size) == INTEGER_CST
1175 && TREE_INT_CST_LOW (size) == 16
1176 && TREE_INT_CST_HIGH (size) == 0)
1177 return darwin_sections[literal16_section];
1178 else
1179 return readonly_data_section;
1180 }
1181
1182 return readonly_data_section;
1183}
1184
0b769e4a 1185int
1186machopic_reloc_rw_mask (void)
1187{
1188 return MACHOPIC_INDIRECT ? 3 : 0;
1189}
1190
50e6797e 1191section *
1192machopic_select_section (tree decl,
1193 int reloc,
1194 unsigned HOST_WIDE_INT align)
1195{
1196 bool weak = (DECL_P (decl)
1197 && DECL_WEAK (decl)
1198 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
1199 || ! lookup_attribute ("weak_import",
1200 DECL_ATTRIBUTES (decl))));
50e6797e 1201 section *base_section;
1202
c6134e23 1203 switch (categorize_decl_for_section (decl, reloc))
50e6797e 1204 {
1205 case SECCAT_TEXT:
1206 base_section = darwin_text_section (reloc, weak);
1207 break;
1208
1209 case SECCAT_RODATA:
1210 case SECCAT_SRODATA:
1211 base_section = darwin_rodata_section (weak);
1212 break;
1213
1214 case SECCAT_RODATA_MERGE_STR:
1215 base_section = darwin_mergeable_string_section (decl, align);
1216 break;
1217
1218 case SECCAT_RODATA_MERGE_STR_INIT:
1219 base_section = darwin_mergeable_string_section (DECL_INITIAL (decl), align);
1220 break;
1221
1222 case SECCAT_RODATA_MERGE_CONST:
1223 base_section = darwin_mergeable_constant_section (decl, align);
1224 break;
1225
1226 case SECCAT_DATA:
1227 case SECCAT_DATA_REL:
1228 case SECCAT_DATA_REL_LOCAL:
1229 case SECCAT_DATA_REL_RO:
1230 case SECCAT_DATA_REL_RO_LOCAL:
1231 case SECCAT_SDATA:
1232 case SECCAT_TDATA:
1233 case SECCAT_BSS:
1234 case SECCAT_SBSS:
1235 case SECCAT_TBSS:
1236 if (TREE_READONLY (decl) || TREE_CONSTANT (decl))
1237 base_section = weak ? darwin_sections[const_data_coal_section]
1238 : darwin_sections[const_data_section];
52470889 1239 else
50e6797e 1240 base_section = weak ? darwin_sections[data_coal_section] : data_section;
1241 break;
1242
1243 default:
1244 gcc_unreachable ();
52470889 1245 }
50e6797e 1246
1247 /* Darwin weird special cases. */
1248 if (TREE_CODE (decl) == CONSTRUCTOR
1249 && TREE_TYPE (decl)
1250 && TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
1251 && TYPE_NAME (TREE_TYPE (decl)))
52470889 1252 {
50e6797e 1253 tree name = TYPE_NAME (TREE_TYPE (decl));
52470889 1254 if (TREE_CODE (name) == TYPE_DECL)
50e6797e 1255 name = DECL_NAME (name);
0616a948 1256
1257 if (!strcmp (IDENTIFIER_POINTER (name), "__builtin_ObjCString"))
50e6797e 1258 {
1259 if (flag_next_runtime)
1260 return darwin_sections[objc_constant_string_object_section];
1261 else
1262 return darwin_sections[objc_string_object_section];
1263 }
52470889 1264 else
50e6797e 1265 return base_section;
52470889 1266 }
50e6797e 1267 else if (TREE_CODE (decl) == VAR_DECL
1268 && DECL_NAME (decl)
1269 && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE
1270 && IDENTIFIER_POINTER (DECL_NAME (decl))
1271 && !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "_OBJC_", 6))
52470889 1272 {
50e6797e 1273 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
52470889 1274
1275 if (!strncmp (name, "_OBJC_CLASS_METHODS_", 20))
50e6797e 1276 return darwin_sections[objc_cls_meth_section];
52470889 1277 else if (!strncmp (name, "_OBJC_INSTANCE_METHODS_", 23))
50e6797e 1278 return darwin_sections[objc_inst_meth_section];
52470889 1279 else if (!strncmp (name, "_OBJC_CATEGORY_CLASS_METHODS_", 20))
50e6797e 1280 return darwin_sections[objc_cat_cls_meth_section];
52470889 1281 else if (!strncmp (name, "_OBJC_CATEGORY_INSTANCE_METHODS_", 23))
50e6797e 1282 return darwin_sections[objc_cat_inst_meth_section];
52470889 1283 else if (!strncmp (name, "_OBJC_CLASS_VARIABLES_", 22))
50e6797e 1284 return darwin_sections[objc_class_vars_section];
52470889 1285 else if (!strncmp (name, "_OBJC_INSTANCE_VARIABLES_", 25))
50e6797e 1286 return darwin_sections[objc_instance_vars_section];
52470889 1287 else if (!strncmp (name, "_OBJC_CLASS_PROTOCOLS_", 22))
50e6797e 1288 return darwin_sections[objc_cat_cls_meth_section];
52470889 1289 else if (!strncmp (name, "_OBJC_CLASS_NAME_", 17))
50e6797e 1290 return darwin_sections[objc_class_names_section];
52470889 1291 else if (!strncmp (name, "_OBJC_METH_VAR_NAME_", 20))
50e6797e 1292 return darwin_sections[objc_meth_var_names_section];
52470889 1293 else if (!strncmp (name, "_OBJC_METH_VAR_TYPE_", 20))
50e6797e 1294 return darwin_sections[objc_meth_var_types_section];
52470889 1295 else if (!strncmp (name, "_OBJC_CLASS_REFERENCES", 22))
50e6797e 1296 return darwin_sections[objc_cls_refs_section];
52470889 1297 else if (!strncmp (name, "_OBJC_CLASS_", 12))
50e6797e 1298 return darwin_sections[objc_class_section];
52470889 1299 else if (!strncmp (name, "_OBJC_METACLASS_", 16))
50e6797e 1300 return darwin_sections[objc_meta_class_section];
52470889 1301 else if (!strncmp (name, "_OBJC_CATEGORY_", 15))
50e6797e 1302 return darwin_sections[objc_category_section];
52470889 1303 else if (!strncmp (name, "_OBJC_SELECTOR_REFERENCES", 25))
50e6797e 1304 return darwin_sections[objc_selector_refs_section];
52470889 1305 else if (!strncmp (name, "_OBJC_SELECTOR_FIXUP", 20))
50e6797e 1306 return darwin_sections[objc_selector_fixup_section];
52470889 1307 else if (!strncmp (name, "_OBJC_SYMBOLS", 13))
50e6797e 1308 return darwin_sections[objc_symbols_section];
52470889 1309 else if (!strncmp (name, "_OBJC_MODULES", 13))
50e6797e 1310 return darwin_sections[objc_module_info_section];
c17b85ea 1311 else if (!strncmp (name, "_OBJC_IMAGE_INFO", 16))
50e6797e 1312 return darwin_sections[objc_image_info_section];
52470889 1313 else if (!strncmp (name, "_OBJC_PROTOCOL_INSTANCE_METHODS_", 32))
50e6797e 1314 return darwin_sections[objc_cat_inst_meth_section];
52470889 1315 else if (!strncmp (name, "_OBJC_PROTOCOL_CLASS_METHODS_", 29))
50e6797e 1316 return darwin_sections[objc_cat_cls_meth_section];
52470889 1317 else if (!strncmp (name, "_OBJC_PROTOCOL_REFS_", 20))
50e6797e 1318 return darwin_sections[objc_cat_cls_meth_section];
52470889 1319 else if (!strncmp (name, "_OBJC_PROTOCOL_", 15))
50e6797e 1320 return darwin_sections[objc_protocol_section];
52470889 1321 else
50e6797e 1322 return base_section;
52470889 1323 }
50e6797e 1324
1325 return base_section;
52470889 1326}
1327
bbfbe351 1328/* This can be called with address expressions as "rtx".
9cb8e99f 1329 They must go in "const". */
bbfbe351 1330
2f14b1f9 1331section *
b40da9a7 1332machopic_select_rtx_section (enum machine_mode mode, rtx x,
1333 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
bbfbe351 1334{
f2e8796e 1335 if (GET_MODE_SIZE (mode) == 8
1336 && (GET_CODE (x) == CONST_INT
1337 || GET_CODE (x) == CONST_DOUBLE))
92e4ba7d 1338 return darwin_sections[literal8_section];
bbfbe351 1339 else if (GET_MODE_SIZE (mode) == 4
1340 && (GET_CODE (x) == CONST_INT
1341 || GET_CODE (x) == CONST_DOUBLE))
92e4ba7d 1342 return darwin_sections[literal4_section];
4be92808 1343 else if (HAVE_GAS_LITERAL16
1344 && TARGET_64BIT
7463cbdf 1345 && GET_MODE_SIZE (mode) == 16
3ebc7dec 1346 && (GET_CODE (x) == CONST_INT
2805e80b 1347 || GET_CODE (x) == CONST_DOUBLE
1348 || GET_CODE (x) == CONST_VECTOR))
3ebc7dec 1349 return darwin_sections[literal16_section];
459f8624 1350 else if (MACHOPIC_INDIRECT
76dece62 1351 && (GET_CODE (x) == SYMBOL_REF
1352 || GET_CODE (x) == CONST
1353 || GET_CODE (x) == LABEL_REF))
92e4ba7d 1354 return darwin_sections[const_data_section];
bbfbe351 1355 else
92e4ba7d 1356 return darwin_sections[const_section];
bbfbe351 1357}
1358
01d15dc5 1359void
b40da9a7 1360machopic_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
01d15dc5 1361{
8f74ae7b 1362 if (MACHOPIC_INDIRECT)
92e4ba7d 1363 switch_to_section (darwin_sections[mod_init_section]);
01d15dc5 1364 else
92e4ba7d 1365 switch_to_section (darwin_sections[constructor_section]);
09d688ff 1366 assemble_align (POINTER_SIZE);
1367 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
01d15dc5 1368
8f74ae7b 1369 if (! MACHOPIC_INDIRECT)
01d15dc5 1370 fprintf (asm_out_file, ".reference .constructors_used\n");
1371}
1372
1373void
b40da9a7 1374machopic_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
01d15dc5 1375{
8f74ae7b 1376 if (MACHOPIC_INDIRECT)
92e4ba7d 1377 switch_to_section (darwin_sections[mod_term_section]);
01d15dc5 1378 else
92e4ba7d 1379 switch_to_section (darwin_sections[destructor_section]);
09d688ff 1380 assemble_align (POINTER_SIZE);
1381 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
01d15dc5 1382
8f74ae7b 1383 if (! MACHOPIC_INDIRECT)
01d15dc5 1384 fprintf (asm_out_file, ".reference .destructors_used\n");
1385}
1f3233d1 1386
67c1e638 1387void
b40da9a7 1388darwin_globalize_label (FILE *stream, const char *name)
67c1e638 1389{
1390 if (!!strncmp (name, "_OBJC_", 6))
1391 default_globalize_label (stream, name);
1392}
1393
2f9fc8ef 1394void
b215c058 1395darwin_asm_named_section (const char *name,
537cd941 1396 unsigned int flags ATTRIBUTE_UNUSED,
1397 tree decl ATTRIBUTE_UNUSED)
2f9fc8ef 1398{
1dc74225 1399 fprintf (asm_out_file, "\t.section %s\n", name);
2f9fc8ef 1400}
1401
b215c058 1402void
1dc74225 1403darwin_unique_section (tree decl ATTRIBUTE_UNUSED, int reloc ATTRIBUTE_UNUSED)
2f9fc8ef 1404{
1dc74225 1405 /* Darwin does not use unique sections. */
2f9fc8ef 1406}
1407
5b182752 1408/* Handle __attribute__ ((apple_kext_compatibility)).
1409 This only applies to darwin kexts for 2.95 compatibility -- it shrinks the
1410 vtable for classes with this attribute (and their descendants) by not
1411 outputting the new 3.0 nondeleting destructor. This means that such
1412 objects CANNOT be allocated on the stack or as globals UNLESS they have
1413 a completely empty `operator delete'.
1414 Luckily, this fits in with the Darwin kext model.
1415
1416 This attribute also disables gcc3's potential overlaying of derived
1417 class data members on the padding at the end of the base class. */
1418
1419tree
1420darwin_handle_kext_attribute (tree *node, tree name,
1421 tree args ATTRIBUTE_UNUSED,
1422 int flags ATTRIBUTE_UNUSED,
1423 bool *no_add_attrs)
1424{
1425 /* APPLE KEXT stuff -- only applies with pure static C++ code. */
1426 if (! TARGET_KEXTABI)
1427 {
666137bc 1428 warning (0, "%<%s%> 2.95 vtable-compatibility attribute applies "
5b182752 1429 "only when compiling a kext", IDENTIFIER_POINTER (name));
1430
1431 *no_add_attrs = true;
1432 }
1433 else if (TREE_CODE (*node) != RECORD_TYPE)
1434 {
666137bc 1435 warning (0, "%<%s%> 2.95 vtable-compatibility attribute applies "
5b182752 1436 "only to C++ classes", IDENTIFIER_POINTER (name));
1437
1438 *no_add_attrs = true;
1439 }
1440
1441 return NULL_TREE;
1442}
1443
975d636c 1444/* Handle a "weak_import" attribute; arguments as in
1445 struct attribute_spec.handler. */
1446
1447tree
1448darwin_handle_weak_import_attribute (tree *node, tree name,
1449 tree ARG_UNUSED (args),
1450 int ARG_UNUSED (flags),
1451 bool * no_add_attrs)
1452{
d0ddd548 1453 if (TREE_CODE (*node) != FUNCTION_DECL && TREE_CODE (*node) != VAR_DECL)
975d636c 1454 {
9b2d6d13 1455 warning (OPT_Wattributes, "%qs attribute ignored",
1456 IDENTIFIER_POINTER (name));
975d636c 1457 *no_add_attrs = true;
1458 }
1459 else
1460 declare_weak (*node);
1461
1462 return NULL_TREE;
1463}
a3952a36 1464
b215c058 1465/* Emit a label for an FDE, making it global and/or weak if appropriate.
ef1074f7 1466 The third parameter is nonzero if this is for exception handling.
1467 The fourth parameter is nonzero if this is just a placeholder for an
2f9fc8ef 1468 FDE that we are omitting. */
ef1074f7 1469
b215c058 1470void
ef1074f7 1471darwin_emit_unwind_label (FILE *file, tree decl, int for_eh, int empty)
2f9fc8ef 1472{
3469b0cf 1473 char *lab;
ef1074f7 1474
1475 if (! for_eh)
d08d29c0 1476 return;
2f9fc8ef 1477
e8f535c2 1478 lab = concat (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), ".eh", NULL);
2f9fc8ef 1479
1480 if (TREE_PUBLIC (decl))
e8f535c2 1481 {
1482 targetm.asm_out.globalize_label (file, lab);
1483 if (DECL_VISIBILITY (decl) == VISIBILITY_HIDDEN)
1484 {
1485 fputs ("\t.private_extern ", file);
1486 assemble_name (file, lab);
1487 fputc ('\n', file);
1488 }
1489 }
2f9fc8ef 1490
1dc74225 1491 if (DECL_WEAK (decl))
e8f535c2 1492 {
1493 fputs ("\t.weak_definition ", file);
1494 assemble_name (file, lab);
1495 fputc ('\n', file);
1496 }
2f9fc8ef 1497
e8f535c2 1498 assemble_name (file, lab);
2f9fc8ef 1499 if (empty)
a3952a36 1500 {
e8f535c2 1501 fputs (" = 0\n", file);
a3952a36 1502
1503 /* Mark the absolute .eh and .eh1 style labels as needed to
1504 ensure that we don't dead code strip them and keep such
1505 labels from another instantiation point until we can fix this
1506 properly with group comdat support. */
e8f535c2 1507 darwin_mark_decl_preserved (lab);
a3952a36 1508 }
2f9fc8ef 1509 else
e8f535c2 1510 fputs (":\n", file);
2f9fc8ef 1511
1512 free (lab);
1513}
1514
b215c058 1515static GTY(()) unsigned long except_table_label_num;
1516
1517void
1518darwin_emit_except_table_label (FILE *file)
1519{
1520 char section_start_label[30];
1521
1522 ASM_GENERATE_INTERNAL_LABEL (section_start_label, "GCC_except_table",
1523 except_table_label_num++);
1524 ASM_OUTPUT_LABEL (file, section_start_label);
1525}
1526/* Generate a PC-relative reference to a Mach-O non-lazy-symbol. */
ef1074f7 1527
2f9fc8ef 1528void
1529darwin_non_lazy_pcrel (FILE *file, rtx addr)
1530{
2f9fc8ef 1531 const char *nlp_name;
1532
27d2baef 1533 gcc_assert (GET_CODE (addr) == SYMBOL_REF);
2f9fc8ef 1534
ab06d2ff 1535 nlp_name = machopic_indirection_name (addr, /*stub_p=*/false);
2f9fc8ef 1536 fputs ("\t.long\t", file);
1537 ASM_OUTPUT_LABELREF (file, nlp_name);
1538 fputs ("-.", file);
1539}
1540
2c5b6111 1541/* Emit an assembler directive to set visibility for a symbol. The
1542 only supported visibilities are VISIBILITY_DEFAULT and
1543 VISIBILITY_HIDDEN; the latter corresponds to Darwin's "private
1544 extern". There is no MACH-O equivalent of ELF's
1545 VISIBILITY_INTERNAL or VISIBILITY_PROTECTED. */
1546
b215c058 1547void
2c5b6111 1548darwin_assemble_visibility (tree decl, int vis)
1549{
1550 if (vis == VISIBILITY_DEFAULT)
1551 ;
1552 else if (vis == VISIBILITY_HIDDEN)
1553 {
1554 fputs ("\t.private_extern ", asm_out_file);
1555 assemble_name (asm_out_file,
1556 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
1557 fputs ("\n", asm_out_file);
1558 }
1559 else
9b2d6d13 1560 warning (OPT_Wattributes, "internal and protected visibility attributes "
1561 "not supported in this configuration; ignored");
2c5b6111 1562}
1563
a08b74c8 1564/* Output a difference of two labels that will be an assembly time
1565 constant if the two labels are local. (.long lab1-lab2 will be
1566 very different if lab1 is at the boundary between two sections; it
1567 will be relocated according to the second section, not the first,
1568 so one ends up with a difference between labels in different
1569 sections, which is bad in the dwarf2 eh context for instance.) */
1570
1571static int darwin_dwarf_label_counter;
1572
1573void
85d3e3b5 1574darwin_asm_output_dwarf_delta (FILE *file, int size,
b40da9a7 1575 const char *lab1, const char *lab2)
a08b74c8 1576{
2f9fc8ef 1577 int islocaldiff = (lab1[0] == '*' && lab1[1] == 'L'
1578 && lab2[0] == '*' && lab2[1] == 'L');
dcf3c3f7 1579 const char *directive = (size == 8 ? ".quad" : ".long");
a08b74c8 1580
1581 if (islocaldiff)
1582 fprintf (file, "\t.set L$set$%d,", darwin_dwarf_label_counter);
1583 else
85d3e3b5 1584 fprintf (file, "\t%s\t", directive);
48126f0c 1585 assemble_name_raw (file, lab1);
a08b74c8 1586 fprintf (file, "-");
48126f0c 1587 assemble_name_raw (file, lab2);
a08b74c8 1588 if (islocaldiff)
85d3e3b5 1589 fprintf (file, "\n\t%s L$set$%d", directive, darwin_dwarf_label_counter++);
a08b74c8 1590}
d08d29c0 1591
1592/* Output labels for the start of the DWARF sections if necessary. */
1593void
1594darwin_file_start (void)
1595{
1596 if (write_symbols == DWARF2_DEBUG)
1597 {
f720b7c6 1598 static const char * const debugnames[] =
d08d29c0 1599 {
1600 DEBUG_FRAME_SECTION,
1601 DEBUG_INFO_SECTION,
1602 DEBUG_ABBREV_SECTION,
1603 DEBUG_ARANGES_SECTION,
1604 DEBUG_MACINFO_SECTION,
1605 DEBUG_LINE_SECTION,
1606 DEBUG_LOC_SECTION,
1607 DEBUG_PUBNAMES_SECTION,
af84796a 1608 DEBUG_PUBTYPES_SECTION,
d08d29c0 1609 DEBUG_STR_SECTION,
1610 DEBUG_RANGES_SECTION
1611 };
1612 size_t i;
1613
1614 for (i = 0; i < ARRAY_SIZE (debugnames); i++)
1615 {
1616 int namelen;
1617
1618 switch_to_section (get_section (debugnames[i], SECTION_DEBUG, NULL));
f720b7c6 1619
d08d29c0 1620 gcc_assert (strncmp (debugnames[i], "__DWARF,", 8) == 0);
1621 gcc_assert (strchr (debugnames[i] + 8, ','));
f720b7c6 1622
d08d29c0 1623 namelen = strchr (debugnames[i] + 8, ',') - (debugnames[i] + 8);
1624 fprintf (asm_out_file, "Lsection%.*s:\n", namelen, debugnames[i] + 8);
1625 }
1626 }
1627}
1628
1629/* Output an offset in a DWARF section on Darwin. On Darwin, DWARF section
1630 offsets are not represented using relocs in .o files; either the
1631 section never leaves the .o file, or the linker or other tool is
1632 responsible for parsing the DWARF and updating the offsets. */
1633
1634void
1635darwin_asm_output_dwarf_offset (FILE *file, int size, const char * lab,
1636 section *base)
1637{
1638 char sname[64];
1639 int namelen;
f720b7c6 1640
d08d29c0 1641 gcc_assert (base->common.flags & SECTION_NAMED);
1642 gcc_assert (strncmp (base->named.name, "__DWARF,", 8) == 0);
1643 gcc_assert (strchr (base->named.name + 8, ','));
1644
1645 namelen = strchr (base->named.name + 8, ',') - (base->named.name + 8);
1646 sprintf (sname, "*Lsection%.*s", namelen, base->named.name + 8);
1647 darwin_asm_output_dwarf_delta (file, size, lab, sname);
1648}
a08b74c8 1649
f6940372 1650void
b40da9a7 1651darwin_file_end (void)
f6940372 1652{
1653 machopic_finish (asm_out_file);
1654 if (strcmp (lang_hooks.name, "GNU C++") == 0)
1655 {
92e4ba7d 1656 switch_to_section (darwin_sections[constructor_section]);
1657 switch_to_section (darwin_sections[destructor_section]);
f6940372 1658 ASM_OUTPUT_ALIGN (asm_out_file, 1);
1659 }
9e96724e 1660 fprintf (asm_out_file, "\t.subsections_via_symbols\n");
f6940372 1661}
1662
5b182752 1663/* TODO: Add a language hook for identifying if a decl is a vtable. */
1664#define DARWIN_VTABLE_P(DECL) 0
1665
0765d519 1666/* Cross-module name binding. Darwin does not support overriding
5b182752 1667 functions at dynamic-link time, except for vtables in kexts. */
0765d519 1668
1669bool
a9f1838b 1670darwin_binds_local_p (const_tree decl)
0765d519 1671{
5b182752 1672 return default_binds_local_p_1 (decl,
1673 TARGET_KEXTABI && DARWIN_VTABLE_P (decl));
0765d519 1674}
1675
f13da317 1676#if 0
1677/* See TARGET_ASM_OUTPUT_ANCHOR for why we can't do this yet. */
8c27005f 1678/* The Darwin's implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
1679 anchor relative to ".", the current section position. We cannot use
1680 the default one because ASM_OUTPUT_DEF is wrong for Darwin. */
1681
1682void
1683darwin_asm_output_anchor (rtx symbol)
1684{
1685 fprintf (asm_out_file, "\t.set\t");
1686 assemble_name (asm_out_file, XSTR (symbol, 0));
1687 fprintf (asm_out_file, ", . + " HOST_WIDE_INT_PRINT_DEC "\n",
1688 SYMBOL_REF_BLOCK_OFFSET (symbol));
1689}
f13da317 1690#endif
8c27005f 1691
f720b7c6 1692/* Set the darwin specific attributes on TYPE. */
1693void
1694darwin_set_default_type_attributes (tree type)
1695{
1696 if (darwin_ms_struct
1697 && TREE_CODE (type) == RECORD_TYPE)
1698 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("ms_struct"),
1699 NULL_TREE,
1700 TYPE_ATTRIBUTES (type));
1701}
1702
26ac986e 1703/* True, iff we're generating code for loadable kernel extensions. */
5b182752 1704
1705bool
1706darwin_kextabi_p (void) {
1707 return flag_apple_kext;
1708}
1709
1710void
1711darwin_override_options (void)
1712{
5b182752 1713 if (flag_mkernel || flag_apple_kext)
1714 {
1715 /* -mkernel implies -fapple-kext for C++ */
1716 if (strcmp (lang_hooks.name, "GNU C++") == 0)
1717 flag_apple_kext = 1;
1718
1719 flag_no_common = 1;
1720
1721 /* No EH in kexts. */
1722 flag_exceptions = 0;
1723 /* No -fnon-call-exceptions data in kexts. */
1724 flag_non_call_exceptions = 0;
1725 }
d53bb226 1726 if (flag_var_tracking
fe6e8926 1727 && strverscmp (darwin_macosx_version_min, "10.5") >= 0
ffdfb40f 1728 && debug_info_level >= DINFO_LEVEL_NORMAL
1729 && debug_hooks->var_location != do_nothing_debug_hooks.var_location)
d53bb226 1730 flag_var_tracking_uninit = 1;
5b182752 1731}
1732
6aee6ac8 1733/* Add $LDBL128 suffix to long double builtins. */
1734
1735static void
1736darwin_patch_builtin (int fncode)
1737{
1738 tree fn = built_in_decls[fncode];
1739 tree sym;
1740 char *newname;
1741
1742 if (!fn)
1743 return;
1744
1745 sym = DECL_ASSEMBLER_NAME (fn);
d243d9c9 1746 newname = ACONCAT (("_", IDENTIFIER_POINTER (sym), "$LDBL128", NULL));
1747
6aee6ac8 1748 set_user_assembler_name (fn, newname);
6aee6ac8 1749
1750 fn = implicit_built_in_decls[fncode];
1751 if (fn)
1752 set_user_assembler_name (fn, newname);
6aee6ac8 1753}
1754
1755void
1756darwin_patch_builtins (void)
1757{
1758 if (LONG_DOUBLE_TYPE_SIZE != 128)
1759 return;
1760
1761#define PATCH_BUILTIN(fncode) darwin_patch_builtin (fncode);
d243d9c9 1762#define PATCH_BUILTIN_NO64(fncode) \
1763 if (!TARGET_64BIT) \
6aee6ac8 1764 darwin_patch_builtin (fncode);
d243d9c9 1765#define PATCH_BUILTIN_VARIADIC(fncode) \
1766 if (!TARGET_64BIT \
6aee6ac8 1767 && (strverscmp (darwin_macosx_version_min, "10.3.9") >= 0)) \
1768 darwin_patch_builtin (fncode);
1769#include "darwin-ppc-ldouble-patch.def"
1770#undef PATCH_BUILTIN
1771#undef PATCH_BUILTIN_NO64
1772#undef PATCH_BUILTIN_VARIADIC
1773}
1774
1775
1f3233d1 1776#include "gt-darwin.h"