Index: fixincludes/ChangeLog
[gcc.git] / gcc / config / darwin.c
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 Free Software Foundation, Inc.
4 Contributed by Apple Computer Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
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"
40 #include "function.h"
41 #include "ggc.h"
42 #include "langhooks.h"
43 #include "target.h"
44 #include "tm_p.h"
45 #include "errors.h"
46 #include "hashtab.h"
47
48 /* Darwin supports a feature called fix-and-continue, which is used
49 for rapid turn around debugging. When code is compiled with the
50 -mfix-and-continue flag, two changes are made to the generated code
51 that allow the system to do things that it would normally not be
52 able to do easily. These changes allow gdb to load in
53 recompilation of a translation unit that has been changed into a
54 running program and replace existing functions and methods of that
55 translation unit with with versions of those functions and methods
56 from the newly compiled translation unit. The new functions access
57 the existing static data from the old translation unit, if the data
58 existed in the unit to be replaced, and from the new translation
59 unit, for new data.
60
61 The changes are to insert 4 nops at the beginning of all functions
62 and to use indirection to get at static duration data. The 4 nops
63 are required by consumers of the generated code. Currently, gdb
64 uses this to patch in a jump to the overriding function, this
65 allows all uses of the old name to forward to the replacement,
66 including existing function pointers and virtual methods. See
67 rs6000_emit_prologue for the code that handles the nop insertions.
68
69 The added indirection allows gdb to redirect accesses to static
70 duration data from the newly loaded translation unit to the
71 existing data, if any. @code{static} data is special and is
72 handled by setting the second word in the .non_lazy_symbol_pointer
73 data structure to the address of the data. See indirect_data for
74 the code that handles the extra indirection, and
75 machopic_output_indirection and its use of MACHO_SYMBOL_STATIC for
76 the code that handles @code{static} data indirection. */
77
78
79 /* Nonzero if the user passes the -mone-byte-bool switch, which forces
80 sizeof(bool) to be 1. */
81 const char *darwin_one_byte_bool = 0;
82
83 int
84 name_needs_quotes (const char *name)
85 {
86 int c;
87 while ((c = *name++) != '\0')
88 if (! ISIDNUM (c) && c != '.' && c != '$')
89 return 1;
90 return 0;
91 }
92
93 /*
94 * flag_pic = 1 ... generate only indirections
95 * flag_pic = 2 ... generate indirections and pure code
96 */
97
98 static int
99 machopic_symbol_defined_p (rtx sym_ref)
100 {
101 return (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_DEFINED)
102 || (SYMBOL_REF_LOCAL_P (sym_ref) && ! SYMBOL_REF_EXTERNAL_P (sym_ref));
103 }
104
105 /* This module assumes that (const (symbol_ref "foo")) is a legal pic
106 reference, which will not be changed. */
107
108 enum machopic_addr_class
109 machopic_classify_symbol (rtx sym_ref)
110 {
111 int flags;
112 bool function_p;
113
114 flags = SYMBOL_REF_FLAGS (sym_ref);
115 function_p = SYMBOL_REF_FUNCTION_P (sym_ref);
116 if (machopic_symbol_defined_p (sym_ref))
117 return (function_p
118 ? MACHOPIC_DEFINED_FUNCTION : MACHOPIC_DEFINED_DATA);
119 else
120 return (function_p
121 ? MACHOPIC_UNDEFINED_FUNCTION : MACHOPIC_UNDEFINED_DATA);
122 }
123
124 #ifndef TARGET_FIX_AND_CONTINUE
125 #define TARGET_FIX_AND_CONTINUE 0
126 #endif
127
128 /* Indicate when fix-and-continue style code generation is being used
129 and when a reference to data should be indirected so that it can be
130 rebound in a new translation unit to refernce the original instance
131 of that data. Symbol names that are for code generation local to
132 the translation unit are bound to the new translation unit;
133 currently this means symbols that begin with L or _OBJC_;
134 otherwise, we indicate that an indirect reference should be made to
135 permit the runtime to rebind new instances of the translation unit
136 to the original instance of the data. */
137
138 static int
139 indirect_data (rtx sym_ref)
140 {
141 int lprefix;
142 const char *name;
143
144 /* If we aren't generating fix-and-continue code, don't do anything special. */
145 if (TARGET_FIX_AND_CONTINUE == 0)
146 return 0;
147
148 /* Otherwise, all symbol except symbols that begin with L or _OBJC_
149 are indirected. Symbols that begin with L and _OBJC_ are always
150 bound to the current translation unit as they are used for
151 generated local data of the translation unit. */
152
153 name = XSTR (sym_ref, 0);
154
155 lprefix = (((name[0] == '*' || name[0] == '&')
156 && (name[1] == 'L' || (name[1] == '"' && name[2] == 'L')))
157 || (strncmp (name, "_OBJC_", 6)));
158
159 return ! lprefix;
160 }
161
162
163 static int
164 machopic_data_defined_p (rtx sym_ref)
165 {
166 if (indirect_data (sym_ref))
167 return 0;
168
169 switch (machopic_classify_symbol (sym_ref))
170 {
171 case MACHOPIC_DEFINED_DATA:
172 return 1;
173 default:
174 return 0;
175 }
176 }
177
178 void
179 machopic_define_symbol (rtx mem)
180 {
181 rtx sym_ref;
182 if (GET_CODE (mem) != MEM)
183 abort ();
184 sym_ref = XEXP (mem, 0);
185 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_DEFINED;
186 }
187
188 static GTY(()) char * function_base;
189
190 const char *
191 machopic_function_base_name (void)
192 {
193 /* if dynamic-no-pic is on, we should not get here */
194 if (MACHO_DYNAMIC_NO_PIC_P)
195 abort ();
196
197 if (function_base == NULL)
198 function_base =
199 (char *) ggc_alloc_string ("<pic base>", sizeof ("<pic base>"));
200
201 current_function_uses_pic_offset_table = 1;
202
203 return function_base;
204 }
205
206 /* Return a SYMBOL_REF for the PIC function base. */
207
208 rtx
209 machopic_function_base_sym (void)
210 {
211 rtx sym_ref;
212
213 sym_ref = gen_rtx_SYMBOL_REF (Pmode, machopic_function_base_name ());
214 SYMBOL_REF_FLAGS (sym_ref)
215 |= (MACHO_SYMBOL_FLAG_VARIABLE | MACHO_SYMBOL_FLAG_DEFINED);
216 return sym_ref;
217 }
218
219 static GTY(()) const char * function_base_func_name;
220 static GTY(()) int current_pic_label_num;
221
222 void
223 machopic_output_function_base_name (FILE *file)
224 {
225 const char *current_name;
226
227 /* If dynamic-no-pic is on, we should not get here. */
228 if (MACHO_DYNAMIC_NO_PIC_P)
229 abort ();
230 current_name =
231 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
232 if (function_base_func_name != current_name)
233 {
234 ++current_pic_label_num;
235 function_base_func_name = current_name;
236 }
237 fprintf (file, "\"L%011d$pb\"", current_pic_label_num);
238 }
239
240 /* The suffix attached to non-lazy pointer symbols. */
241 #define NON_LAZY_POINTER_SUFFIX "$non_lazy_ptr"
242 /* The suffix attached to stub symbols. */
243 #define STUB_SUFFIX "$stub"
244
245 typedef struct machopic_indirection GTY (())
246 {
247 /* The SYMBOL_REF for the entity referenced. */
248 rtx symbol;
249 /* The name of the stub or non-lazy pointer. */
250 const char * ptr_name;
251 /* True iff this entry is for a stub (as opposed to a non-lazy
252 pointer). */
253 bool stub_p;
254 /* True iff this stub or pointer pointer has been referenced. */
255 bool used;
256 } machopic_indirection;
257
258 /* A table mapping stub names and non-lazy pointer names to
259 SYMBOL_REFs for the stubbed-to and pointed-to entities. */
260
261 static GTY ((param_is (struct machopic_indirection))) htab_t
262 machopic_indirections;
263
264 /* Return a hash value for a SLOT in the indirections hash table. */
265
266 static hashval_t
267 machopic_indirection_hash (const void *slot)
268 {
269 const machopic_indirection *p = (const machopic_indirection *) slot;
270 return htab_hash_string (p->ptr_name);
271 }
272
273 /* Returns true if the KEY is the same as that associated with
274 SLOT. */
275
276 static int
277 machopic_indirection_eq (const void *slot, const void *key)
278 {
279 return strcmp (((const machopic_indirection *) slot)->ptr_name, key) == 0;
280 }
281
282 /* Return the name of the non-lazy pointer (if STUB_P is false) or
283 stub (if STUB_B is true) corresponding to the given name. */
284
285 const char *
286 machopic_indirection_name (rtx sym_ref, bool stub_p)
287 {
288 char *buffer;
289 const char *name = XSTR (sym_ref, 0);
290 size_t namelen = strlen (name);
291 machopic_indirection *p;
292 void ** slot;
293
294 /* Construct the name of the non-lazy pointer or stub. */
295 if (stub_p)
296 {
297 int needs_quotes = name_needs_quotes (name);
298 buffer = alloca (strlen ("&L")
299 + namelen
300 + strlen (STUB_SUFFIX)
301 + 2 /* possible quotes */
302 + 1 /* '\0' */);
303
304 if (needs_quotes)
305 {
306 if (name[0] == '*')
307 sprintf (buffer, "&\"L%s" STUB_SUFFIX "\"", name + 1);
308 else
309 sprintf (buffer, "&\"L%s%s" STUB_SUFFIX "\"", user_label_prefix,
310 name);
311 }
312 else if (name[0] == '*')
313 sprintf (buffer, "&L%s" STUB_SUFFIX, name + 1);
314 else
315 sprintf (buffer, "&L%s%s" STUB_SUFFIX, user_label_prefix, name);
316 }
317 else
318 {
319 buffer = alloca (strlen ("&L")
320 + strlen (user_label_prefix)
321 + namelen
322 + strlen (NON_LAZY_POINTER_SUFFIX)
323 + 1 /* '\0' */);
324 if (name[0] == '*')
325 sprintf (buffer, "&L%s" NON_LAZY_POINTER_SUFFIX, name + 1);
326 else
327 sprintf (buffer, "&L%s%s" NON_LAZY_POINTER_SUFFIX,
328 user_label_prefix, name);
329 }
330
331 if (!machopic_indirections)
332 machopic_indirections = htab_create_ggc (37,
333 machopic_indirection_hash,
334 machopic_indirection_eq,
335 /*htab_del=*/NULL);
336
337 slot = htab_find_slot_with_hash (machopic_indirections, buffer,
338 htab_hash_string (buffer), INSERT);
339 if (*slot)
340 {
341 p = (machopic_indirection *) *slot;
342 }
343 else
344 {
345 p = (machopic_indirection *) ggc_alloc (sizeof (machopic_indirection));
346 p->symbol = sym_ref;
347 p->ptr_name = xstrdup (buffer);
348 p->stub_p = stub_p;
349 p->used = false;
350 *slot = p;
351 }
352
353 return p->ptr_name;
354 }
355
356 /* Return the name of the stub for the mcount function. */
357
358 const char*
359 machopic_mcount_stub_name (void)
360 {
361 rtx symbol = gen_rtx_SYMBOL_REF (Pmode, "*mcount");
362 return machopic_indirection_name (symbol, /*stub_p=*/true);
363 }
364
365 /* If NAME is the name of a stub or a non-lazy pointer , mark the stub
366 or non-lazy pointer as used -- and mark the object to which the
367 pointer/stub refers as used as well, since the pointer/stub will
368 emit a reference to it. */
369
370 void
371 machopic_validate_stub_or_non_lazy_ptr (const char *name)
372 {
373 machopic_indirection *p;
374
375 p = ((machopic_indirection *)
376 (htab_find_with_hash (machopic_indirections, name,
377 htab_hash_string (name))));
378 if (p && ! p->used)
379 {
380 const char *real_name;
381 tree id;
382
383 p->used = true;
384
385 /* Do what output_addr_const will do when we actually call it. */
386 if (SYMBOL_REF_DECL (p->symbol))
387 mark_decl_referenced (SYMBOL_REF_DECL (p->symbol));
388
389 real_name = targetm.strip_name_encoding (XSTR (p->symbol, 0));
390
391 id = maybe_get_identifier (real_name);
392 if (id)
393 mark_referenced (id);
394 }
395 }
396
397 /* Transform ORIG, which may be any data source, to the corresponding
398 source using indirections. */
399
400 rtx
401 machopic_indirect_data_reference (rtx orig, rtx reg)
402 {
403 rtx ptr_ref = orig;
404
405 if (! MACHOPIC_INDIRECT)
406 return orig;
407
408 if (GET_CODE (orig) == SYMBOL_REF)
409 {
410 int defined = machopic_data_defined_p (orig);
411
412 if (defined && MACHO_DYNAMIC_NO_PIC_P)
413 {
414 #if defined (TARGET_TOC)
415 emit_insn (GET_MODE (orig) == DImode
416 ? gen_macho_high_di (reg, orig)
417 : gen_macho_high (reg, orig));
418 emit_insn (GET_MODE (orig) == DImode
419 ? gen_macho_low_di (reg, reg, orig)
420 : gen_macho_low (reg, reg, orig));
421 #else
422 /* some other cpu -- writeme! */
423 abort ();
424 #endif
425 return reg;
426 }
427 else if (defined)
428 {
429 #if defined (TARGET_TOC) || defined (HAVE_lo_sum)
430 rtx pic_base = machopic_function_base_sym ();
431 rtx offset = gen_rtx_CONST (Pmode,
432 gen_rtx_MINUS (Pmode, orig, pic_base));
433 #endif
434
435 #if defined (TARGET_TOC) /* i.e., PowerPC */
436 rtx hi_sum_reg = (no_new_pseudos ? reg : gen_reg_rtx (Pmode));
437
438 if (reg == NULL)
439 abort ();
440
441 emit_insn (gen_rtx_SET (Pmode, hi_sum_reg,
442 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
443 gen_rtx_HIGH (Pmode, offset))));
444 emit_insn (gen_rtx_SET (Pmode, reg,
445 gen_rtx_LO_SUM (Pmode, hi_sum_reg, offset)));
446
447 orig = reg;
448 #else
449 #if defined (HAVE_lo_sum)
450 if (reg == 0) abort ();
451
452 emit_insn (gen_rtx_SET (VOIDmode, reg,
453 gen_rtx_HIGH (Pmode, offset)));
454 emit_insn (gen_rtx_SET (VOIDmode, reg,
455 gen_rtx_LO_SUM (Pmode, reg, offset)));
456 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
457
458 orig = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, reg);
459 #endif
460 #endif
461 return orig;
462 }
463
464 ptr_ref = (gen_rtx_SYMBOL_REF
465 (Pmode,
466 machopic_indirection_name (orig, /*stub_p=*/false)));
467
468 SYMBOL_REF_DECL (ptr_ref) = SYMBOL_REF_DECL (orig);
469
470 ptr_ref = gen_const_mem (Pmode, ptr_ref);
471 machopic_define_symbol (ptr_ref);
472
473 return ptr_ref;
474 }
475 else if (GET_CODE (orig) == CONST)
476 {
477 rtx base, result;
478
479 /* legitimize both operands of the PLUS */
480 if (GET_CODE (XEXP (orig, 0)) == PLUS)
481 {
482 base = machopic_indirect_data_reference (XEXP (XEXP (orig, 0), 0),
483 reg);
484 orig = machopic_indirect_data_reference (XEXP (XEXP (orig, 0), 1),
485 (base == reg ? 0 : reg));
486 }
487 else
488 return orig;
489
490 if (MACHOPIC_PURE && GET_CODE (orig) == CONST_INT)
491 result = plus_constant (base, INTVAL (orig));
492 else
493 result = gen_rtx_PLUS (Pmode, base, orig);
494
495 if (MACHOPIC_JUST_INDIRECT && GET_CODE (base) == MEM)
496 {
497 if (reg)
498 {
499 emit_move_insn (reg, result);
500 result = reg;
501 }
502 else
503 {
504 result = force_reg (GET_MODE (result), result);
505 }
506 }
507
508 return result;
509
510 }
511 else if (GET_CODE (orig) == MEM)
512 XEXP (ptr_ref, 0) = machopic_indirect_data_reference (XEXP (orig, 0), reg);
513 /* When the target is i386, this code prevents crashes due to the
514 compiler's ignorance on how to move the PIC base register to
515 other registers. (The reload phase sometimes introduces such
516 insns.) */
517 else if (GET_CODE (orig) == PLUS
518 && GET_CODE (XEXP (orig, 0)) == REG
519 && REGNO (XEXP (orig, 0)) == PIC_OFFSET_TABLE_REGNUM
520 #ifdef I386
521 /* Prevent the same register from being erroneously used
522 as both the base and index registers. */
523 && GET_CODE (XEXP (orig, 1)) == CONST
524 #endif
525 && reg)
526 {
527 emit_move_insn (reg, XEXP (orig, 0));
528 XEXP (ptr_ref, 0) = reg;
529 }
530 return ptr_ref;
531 }
532
533 /* Transform TARGET (a MEM), which is a function call target, to the
534 corresponding symbol_stub if necessary. Return a new MEM. */
535
536 rtx
537 machopic_indirect_call_target (rtx target)
538 {
539 if (GET_CODE (target) != MEM)
540 return target;
541
542 if (MACHOPIC_INDIRECT
543 && GET_CODE (XEXP (target, 0)) == SYMBOL_REF
544 && !(SYMBOL_REF_FLAGS (XEXP (target, 0))
545 & MACHO_SYMBOL_FLAG_DEFINED))
546 {
547 rtx sym_ref = XEXP (target, 0);
548 const char *stub_name = machopic_indirection_name (sym_ref,
549 /*stub_p=*/true);
550 enum machine_mode mode = GET_MODE (sym_ref);
551 tree decl = SYMBOL_REF_DECL (sym_ref);
552
553 XEXP (target, 0) = gen_rtx_SYMBOL_REF (mode, stub_name);
554 SYMBOL_REF_DECL (XEXP (target, 0)) = decl;
555 MEM_READONLY_P (target) = 1;
556 MEM_NOTRAP_P (target) = 1;
557 }
558
559 return target;
560 }
561
562 rtx
563 machopic_legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
564 {
565 rtx pic_ref = orig;
566
567 if (! MACHOPIC_INDIRECT)
568 return orig;
569
570 /* First handle a simple SYMBOL_REF or LABEL_REF */
571 if (GET_CODE (orig) == LABEL_REF
572 || (GET_CODE (orig) == SYMBOL_REF
573 ))
574 {
575 /* addr(foo) = &func+(foo-func) */
576 rtx pic_base;
577
578 orig = machopic_indirect_data_reference (orig, reg);
579
580 if (GET_CODE (orig) == PLUS
581 && GET_CODE (XEXP (orig, 0)) == REG)
582 {
583 if (reg == 0)
584 return force_reg (mode, orig);
585
586 emit_move_insn (reg, orig);
587 return reg;
588 }
589
590 /* if dynamic-no-pic then use 0 as the pic base */
591 if (MACHO_DYNAMIC_NO_PIC_P)
592 pic_base = CONST0_RTX (Pmode);
593 else
594 pic_base = machopic_function_base_sym ();
595
596 if (GET_CODE (orig) == MEM)
597 {
598 if (reg == 0)
599 {
600 if (reload_in_progress)
601 abort ();
602 else
603 reg = gen_reg_rtx (Pmode);
604 }
605
606 #ifdef HAVE_lo_sum
607 if (MACHO_DYNAMIC_NO_PIC_P
608 && (GET_CODE (XEXP (orig, 0)) == SYMBOL_REF
609 || GET_CODE (XEXP (orig, 0)) == LABEL_REF))
610 {
611 #if defined (TARGET_TOC) /* ppc */
612 rtx temp_reg = (no_new_pseudos) ? reg : gen_reg_rtx (Pmode);
613 rtx asym = XEXP (orig, 0);
614 rtx mem;
615
616 emit_insn (mode == DImode
617 ? gen_macho_high_di (temp_reg, asym)
618 : gen_macho_high (temp_reg, asym));
619 mem = gen_const_mem (GET_MODE (orig),
620 gen_rtx_LO_SUM (Pmode, temp_reg, asym));
621 emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
622 #else
623 /* Some other CPU -- WriteMe! but right now there are no other platform that can use dynamic-no-pic */
624 abort ();
625 #endif
626 pic_ref = reg;
627 }
628 else
629 if (GET_CODE (XEXP (orig, 0)) == SYMBOL_REF
630 || GET_CODE (XEXP (orig, 0)) == LABEL_REF)
631 {
632 rtx offset = gen_rtx_CONST (Pmode,
633 gen_rtx_MINUS (Pmode,
634 XEXP (orig, 0),
635 pic_base));
636 #if defined (TARGET_TOC) /* i.e., PowerPC */
637 /* Generating a new reg may expose opportunities for
638 common subexpression elimination. */
639 rtx hi_sum_reg = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
640 rtx mem;
641 rtx insn;
642 rtx sum;
643
644 sum = gen_rtx_HIGH (Pmode, offset);
645 if (! MACHO_DYNAMIC_NO_PIC_P)
646 sum = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, sum);
647
648 emit_insn (gen_rtx_SET (Pmode, hi_sum_reg, sum));
649
650 mem = gen_const_mem (GET_MODE (orig),
651 gen_rtx_LO_SUM (Pmode,
652 hi_sum_reg, offset));
653 insn = emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
654 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, pic_ref,
655 REG_NOTES (insn));
656
657 pic_ref = reg;
658 #else
659 emit_insn (gen_rtx_USE (VOIDmode,
660 gen_rtx_REG (Pmode,
661 PIC_OFFSET_TABLE_REGNUM)));
662
663 emit_insn (gen_rtx_SET (VOIDmode, reg,
664 gen_rtx_HIGH (Pmode,
665 gen_rtx_CONST (Pmode,
666 offset))));
667 emit_insn (gen_rtx_SET (VOIDmode, reg,
668 gen_rtx_LO_SUM (Pmode, reg,
669 gen_rtx_CONST (Pmode, offset))));
670 pic_ref = gen_rtx_PLUS (Pmode,
671 pic_offset_table_rtx, reg);
672 #endif
673 }
674 else
675 #endif /* HAVE_lo_sum */
676 {
677 rtx pic = pic_offset_table_rtx;
678 if (GET_CODE (pic) != REG)
679 {
680 emit_move_insn (reg, pic);
681 pic = reg;
682 }
683 #if 0
684 emit_insn (gen_rtx_USE (VOIDmode,
685 gen_rtx_REG (Pmode,
686 PIC_OFFSET_TABLE_REGNUM)));
687 #endif
688
689 pic_ref = gen_rtx_PLUS (Pmode,
690 pic,
691 gen_rtx_CONST (Pmode,
692 gen_rtx_MINUS (Pmode,
693 XEXP (orig, 0),
694 pic_base)));
695 }
696
697 #if !defined (TARGET_TOC)
698 emit_move_insn (reg, pic_ref);
699 pic_ref = gen_const_mem (GET_MODE (orig), reg);
700 #endif
701 }
702 else
703 {
704
705 #ifdef HAVE_lo_sum
706 if (GET_CODE (orig) == SYMBOL_REF
707 || GET_CODE (orig) == LABEL_REF)
708 {
709 rtx offset = gen_rtx_CONST (Pmode,
710 gen_rtx_MINUS (Pmode,
711 orig, pic_base));
712 #if defined (TARGET_TOC) /* i.e., PowerPC */
713 rtx hi_sum_reg;
714
715 if (reg == 0)
716 {
717 if (reload_in_progress)
718 abort ();
719 else
720 reg = gen_reg_rtx (Pmode);
721 }
722
723 hi_sum_reg = reg;
724
725 emit_insn (gen_rtx_SET (Pmode, hi_sum_reg,
726 (MACHO_DYNAMIC_NO_PIC_P)
727 ? gen_rtx_HIGH (Pmode, offset)
728 : gen_rtx_PLUS (Pmode,
729 pic_offset_table_rtx,
730 gen_rtx_HIGH (Pmode,
731 offset))));
732 emit_insn (gen_rtx_SET (VOIDmode, reg,
733 gen_rtx_LO_SUM (Pmode,
734 hi_sum_reg, offset)));
735 pic_ref = reg;
736 #else
737 emit_insn (gen_rtx_SET (VOIDmode, reg,
738 gen_rtx_HIGH (Pmode, offset)));
739 emit_insn (gen_rtx_SET (VOIDmode, reg,
740 gen_rtx_LO_SUM (Pmode, reg, offset)));
741 pic_ref = gen_rtx_PLUS (Pmode,
742 pic_offset_table_rtx, reg);
743 #endif
744 }
745 else
746 #endif /* HAVE_lo_sum */
747 {
748 if (GET_CODE (orig) == REG)
749 {
750 return orig;
751 }
752 else
753 {
754 rtx pic = pic_offset_table_rtx;
755 if (GET_CODE (pic) != REG)
756 {
757 emit_move_insn (reg, pic);
758 pic = reg;
759 }
760 #if 0
761 emit_insn (gen_rtx_USE (VOIDmode,
762 pic_offset_table_rtx));
763 #endif
764 pic_ref = gen_rtx_PLUS (Pmode,
765 pic,
766 gen_rtx_CONST (Pmode,
767 gen_rtx_MINUS (Pmode,
768 orig, pic_base)));
769 }
770 }
771 }
772
773 if (GET_CODE (pic_ref) != REG)
774 {
775 if (reg != 0)
776 {
777 emit_move_insn (reg, pic_ref);
778 return reg;
779 }
780 else
781 {
782 return force_reg (mode, pic_ref);
783 }
784 }
785 else
786 {
787 return pic_ref;
788 }
789 }
790
791 else if (GET_CODE (orig) == SYMBOL_REF)
792 return orig;
793
794 else if (GET_CODE (orig) == PLUS
795 && (GET_CODE (XEXP (orig, 0)) == MEM
796 || GET_CODE (XEXP (orig, 0)) == SYMBOL_REF
797 || GET_CODE (XEXP (orig, 0)) == LABEL_REF)
798 && XEXP (orig, 0) != pic_offset_table_rtx
799 && GET_CODE (XEXP (orig, 1)) != REG)
800
801 {
802 rtx base;
803 int is_complex = (GET_CODE (XEXP (orig, 0)) == MEM);
804
805 base = machopic_legitimize_pic_address (XEXP (orig, 0), Pmode, reg);
806 orig = machopic_legitimize_pic_address (XEXP (orig, 1),
807 Pmode, (base == reg ? 0 : reg));
808 if (GET_CODE (orig) == CONST_INT)
809 {
810 pic_ref = plus_constant (base, INTVAL (orig));
811 is_complex = 1;
812 }
813 else
814 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
815
816 if (reg && is_complex)
817 {
818 emit_move_insn (reg, pic_ref);
819 pic_ref = reg;
820 }
821 /* Likewise, should we set special REG_NOTEs here? */
822 }
823
824 else if (GET_CODE (orig) == CONST)
825 {
826 return machopic_legitimize_pic_address (XEXP (orig, 0), Pmode, reg);
827 }
828
829 else if (GET_CODE (orig) == MEM
830 && GET_CODE (XEXP (orig, 0)) == SYMBOL_REF)
831 {
832 rtx addr = machopic_legitimize_pic_address (XEXP (orig, 0), Pmode, reg);
833 addr = replace_equiv_address (orig, addr);
834 emit_move_insn (reg, addr);
835 pic_ref = reg;
836 }
837
838 return pic_ref;
839 }
840
841 /* Output the stub or non-lazy pointer in *SLOT, if it has been used.
842 DATA is the FILE* for assembly output. Called from
843 htab_traverse. */
844
845 static int
846 machopic_output_indirection (void **slot, void *data)
847 {
848 machopic_indirection *p = *((machopic_indirection **) slot);
849 FILE *asm_out_file = (FILE *) data;
850 rtx symbol;
851 const char *sym_name;
852 const char *ptr_name;
853
854 if (!p->used)
855 return 1;
856
857 symbol = p->symbol;
858 sym_name = XSTR (symbol, 0);
859 ptr_name = p->ptr_name;
860
861 if (p->stub_p)
862 {
863 char *sym;
864 char *stub;
865
866 sym = alloca (strlen (sym_name) + 2);
867 if (sym_name[0] == '*' || sym_name[0] == '&')
868 strcpy (sym, sym_name + 1);
869 else if (sym_name[0] == '-' || sym_name[0] == '+')
870 strcpy (sym, sym_name);
871 else
872 sprintf (sym, "%s%s", user_label_prefix, sym_name);
873
874 stub = alloca (strlen (ptr_name) + 2);
875 if (ptr_name[0] == '*' || ptr_name[0] == '&')
876 strcpy (stub, ptr_name + 1);
877 else
878 sprintf (stub, "%s%s", user_label_prefix, ptr_name);
879
880 machopic_output_stub (asm_out_file, sym, stub);
881 }
882 else if (! indirect_data (symbol)
883 && (machopic_symbol_defined_p (symbol)
884 || SYMBOL_REF_LOCAL_P (symbol)))
885 {
886 data_section ();
887 assemble_align (GET_MODE_ALIGNMENT (Pmode));
888 assemble_label (ptr_name);
889 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, sym_name),
890 GET_MODE_SIZE (Pmode),
891 GET_MODE_ALIGNMENT (Pmode), 1);
892 }
893 else
894 {
895 rtx init = const0_rtx;
896
897 machopic_nl_symbol_ptr_section ();
898 assemble_name (asm_out_file, ptr_name);
899 fprintf (asm_out_file, ":\n");
900
901 fprintf (asm_out_file, "\t.indirect_symbol ");
902 assemble_name (asm_out_file, sym_name);
903 fprintf (asm_out_file, "\n");
904
905 /* Variables that are marked with MACHO_SYMBOL_STATIC need to
906 have their symbol name instead of 0 in the second entry of
907 the non-lazy symbol pointer data structure when they are
908 defined. This allows the runtime to rebind newer instances
909 of the translation unit with the original instance of the
910 data. */
911
912 if ((SYMBOL_REF_FLAGS (symbol) & MACHO_SYMBOL_STATIC)
913 && machopic_symbol_defined_p (symbol))
914 init = gen_rtx_SYMBOL_REF (Pmode, sym_name);
915
916 assemble_integer (init, GET_MODE_SIZE (Pmode),
917 GET_MODE_ALIGNMENT (Pmode), 1);
918 }
919
920 return 1;
921 }
922
923 void
924 machopic_finish (FILE *asm_out_file)
925 {
926 if (machopic_indirections)
927 htab_traverse_noresize (machopic_indirections,
928 machopic_output_indirection,
929 asm_out_file);
930 }
931
932 int
933 machopic_operand_p (rtx op)
934 {
935 if (MACHOPIC_JUST_INDIRECT)
936 {
937 while (GET_CODE (op) == CONST)
938 op = XEXP (op, 0);
939
940 if (GET_CODE (op) == SYMBOL_REF)
941 return machopic_symbol_defined_p (op);
942 else
943 return 0;
944 }
945
946 while (GET_CODE (op) == CONST)
947 op = XEXP (op, 0);
948
949 if (GET_CODE (op) == MINUS
950 && GET_CODE (XEXP (op, 0)) == SYMBOL_REF
951 && GET_CODE (XEXP (op, 1)) == SYMBOL_REF
952 && machopic_symbol_defined_p (XEXP (op, 0))
953 && machopic_symbol_defined_p (XEXP (op, 1)))
954 return 1;
955
956 return 0;
957 }
958
959 /* This function records whether a given name corresponds to a defined
960 or undefined function or variable, for machopic_classify_ident to
961 use later. */
962
963 void
964 darwin_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
965 {
966 rtx sym_ref;
967
968 /* Do the standard encoding things first. */
969 default_encode_section_info (decl, rtl, first);
970
971 if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
972 return;
973
974 sym_ref = XEXP (rtl, 0);
975 if (TREE_CODE (decl) == VAR_DECL)
976 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_VARIABLE;
977
978 if (!DECL_EXTERNAL (decl)
979 && (!TREE_PUBLIC (decl) || !DECL_WEAK (decl))
980 && ((TREE_STATIC (decl)
981 && (!DECL_COMMON (decl) || !TREE_PUBLIC (decl)))
982 || (!DECL_COMMON (decl) && DECL_INITIAL (decl)
983 && DECL_INITIAL (decl) != error_mark_node)))
984 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_DEFINED;
985
986 if (TREE_CODE (decl) == VAR_DECL
987 && indirect_data (sym_ref)
988 && ! TREE_PUBLIC (decl))
989 SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_STATIC;
990 }
991
992 void
993 darwin_mark_decl_preserved (const char *name)
994 {
995 fprintf (asm_out_file, ".no_dead_strip ");
996 assemble_name (asm_out_file, name);
997 fputc ('\n', asm_out_file);
998 }
999
1000 void
1001 machopic_select_section (tree exp, int reloc,
1002 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
1003 {
1004 void (*base_function)(void);
1005 bool weak_p = DECL_P (exp) && DECL_WEAK (exp);
1006 static void (* const base_funs[][2])(void) = {
1007 { text_section, text_coal_section },
1008 { text_unlikely_section, text_unlikely_coal_section },
1009 { readonly_data_section, const_coal_section },
1010 { const_data_section, const_data_coal_section },
1011 { data_section, data_coal_section }
1012 };
1013
1014 if (TREE_CODE (exp) == FUNCTION_DECL)
1015 base_function = base_funs[reloc][weak_p];
1016 else if (decl_readonly_section_1 (exp, reloc, MACHOPIC_INDIRECT))
1017 base_function = base_funs[2][weak_p];
1018 else if (TREE_READONLY (exp) || TREE_CONSTANT (exp))
1019 base_function = base_funs[3][weak_p];
1020 else
1021 base_function = base_funs[4][weak_p];
1022
1023 if (TREE_CODE (exp) == STRING_CST
1024 && ((size_t) TREE_STRING_LENGTH (exp)
1025 == strlen (TREE_STRING_POINTER (exp)) + 1))
1026 cstring_section ();
1027 else if ((TREE_CODE (exp) == INTEGER_CST || TREE_CODE (exp) == REAL_CST)
1028 && flag_merge_constants)
1029 {
1030 tree size = TYPE_SIZE (TREE_TYPE (exp));
1031
1032 if (TREE_CODE (size) == INTEGER_CST &&
1033 TREE_INT_CST_LOW (size) == 4 &&
1034 TREE_INT_CST_HIGH (size) == 0)
1035 literal4_section ();
1036 else if (TREE_CODE (size) == INTEGER_CST &&
1037 TREE_INT_CST_LOW (size) == 8 &&
1038 TREE_INT_CST_HIGH (size) == 0)
1039 literal8_section ();
1040 else
1041 base_function ();
1042 }
1043 else if (TREE_CODE (exp) == CONSTRUCTOR
1044 && TREE_TYPE (exp)
1045 && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1046 && TYPE_NAME (TREE_TYPE (exp)))
1047 {
1048 tree name = TYPE_NAME (TREE_TYPE (exp));
1049 if (TREE_CODE (name) == TYPE_DECL)
1050 name = DECL_NAME (name);
1051 if (!strcmp (IDENTIFIER_POINTER (name), "NSConstantString"))
1052 objc_constant_string_object_section ();
1053 else if (!strcmp (IDENTIFIER_POINTER (name), "NXConstantString"))
1054 objc_string_object_section ();
1055 else
1056 base_function ();
1057 }
1058 else if (TREE_CODE (exp) == VAR_DECL &&
1059 DECL_NAME (exp) &&
1060 TREE_CODE (DECL_NAME (exp)) == IDENTIFIER_NODE &&
1061 IDENTIFIER_POINTER (DECL_NAME (exp)) &&
1062 !strncmp (IDENTIFIER_POINTER (DECL_NAME (exp)), "_OBJC_", 6))
1063 {
1064 const char *name = IDENTIFIER_POINTER (DECL_NAME (exp));
1065
1066 if (!strncmp (name, "_OBJC_CLASS_METHODS_", 20))
1067 objc_cls_meth_section ();
1068 else if (!strncmp (name, "_OBJC_INSTANCE_METHODS_", 23))
1069 objc_inst_meth_section ();
1070 else if (!strncmp (name, "_OBJC_CATEGORY_CLASS_METHODS_", 20))
1071 objc_cat_cls_meth_section ();
1072 else if (!strncmp (name, "_OBJC_CATEGORY_INSTANCE_METHODS_", 23))
1073 objc_cat_inst_meth_section ();
1074 else if (!strncmp (name, "_OBJC_CLASS_VARIABLES_", 22))
1075 objc_class_vars_section ();
1076 else if (!strncmp (name, "_OBJC_INSTANCE_VARIABLES_", 25))
1077 objc_instance_vars_section ();
1078 else if (!strncmp (name, "_OBJC_CLASS_PROTOCOLS_", 22))
1079 objc_cat_cls_meth_section ();
1080 else if (!strncmp (name, "_OBJC_CLASS_NAME_", 17))
1081 objc_class_names_section ();
1082 else if (!strncmp (name, "_OBJC_METH_VAR_NAME_", 20))
1083 objc_meth_var_names_section ();
1084 else if (!strncmp (name, "_OBJC_METH_VAR_TYPE_", 20))
1085 objc_meth_var_types_section ();
1086 else if (!strncmp (name, "_OBJC_CLASS_REFERENCES", 22))
1087 objc_cls_refs_section ();
1088 else if (!strncmp (name, "_OBJC_CLASS_", 12))
1089 objc_class_section ();
1090 else if (!strncmp (name, "_OBJC_METACLASS_", 16))
1091 objc_meta_class_section ();
1092 else if (!strncmp (name, "_OBJC_CATEGORY_", 15))
1093 objc_category_section ();
1094 else if (!strncmp (name, "_OBJC_SELECTOR_REFERENCES", 25))
1095 objc_selector_refs_section ();
1096 else if (!strncmp (name, "_OBJC_SELECTOR_FIXUP", 20))
1097 objc_selector_fixup_section ();
1098 else if (!strncmp (name, "_OBJC_SYMBOLS", 13))
1099 objc_symbols_section ();
1100 else if (!strncmp (name, "_OBJC_MODULES", 13))
1101 objc_module_info_section ();
1102 else if (!strncmp (name, "_OBJC_IMAGE_INFO", 16))
1103 objc_image_info_section ();
1104 else if (!strncmp (name, "_OBJC_PROTOCOL_INSTANCE_METHODS_", 32))
1105 objc_cat_inst_meth_section ();
1106 else if (!strncmp (name, "_OBJC_PROTOCOL_CLASS_METHODS_", 29))
1107 objc_cat_cls_meth_section ();
1108 else if (!strncmp (name, "_OBJC_PROTOCOL_REFS_", 20))
1109 objc_cat_cls_meth_section ();
1110 else if (!strncmp (name, "_OBJC_PROTOCOL_", 15))
1111 objc_protocol_section ();
1112 else
1113 base_function ();
1114 }
1115 /* ::operator new and ::operator delete must be coalesced, even
1116 if not weak. There are 8 variants that we look for. */
1117 else if (TREE_CODE (exp) == FUNCTION_DECL
1118 && ! DECL_ONE_ONLY (exp))
1119 {
1120 const char * name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (exp));
1121 if (name[0] == '_' && name[1] == 'Z'
1122 && ((name[2] == 'n' && (name[3] == 'a' || name[3] == 'w')
1123 && name[4] == 'm')
1124 || (name[2] == 'd' && (name[3] == 'a' || name[3] == 'l')
1125 && name[4] == 'P' && name[5] == 'v')))
1126 {
1127 bool delete_p = name[2] == 'd';
1128 if (name[5 + delete_p] == 0
1129 || strcmp (name + 5 + delete_p, "KSt9nothrow_t") == 0)
1130 base_funs[reloc][1] ();
1131 else
1132 base_function ();
1133 }
1134 else
1135 base_function ();
1136 }
1137 else
1138 base_function ();
1139 }
1140
1141 /* This can be called with address expressions as "rtx".
1142 They must go in "const". */
1143
1144 void
1145 machopic_select_rtx_section (enum machine_mode mode, rtx x,
1146 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
1147 {
1148 if (GET_MODE_SIZE (mode) == 8)
1149 literal8_section ();
1150 else if (GET_MODE_SIZE (mode) == 4
1151 && (GET_CODE (x) == CONST_INT
1152 || GET_CODE (x) == CONST_DOUBLE))
1153 literal4_section ();
1154 else if (MACHOPIC_INDIRECT
1155 && (GET_CODE (x) == SYMBOL_REF
1156 || GET_CODE (x) == CONST
1157 || GET_CODE (x) == LABEL_REF))
1158 const_data_section ();
1159 else
1160 const_section ();
1161 }
1162
1163 void
1164 machopic_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
1165 {
1166 if (MACHOPIC_INDIRECT)
1167 mod_init_section ();
1168 else
1169 constructor_section ();
1170 assemble_align (POINTER_SIZE);
1171 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1172
1173 if (! MACHOPIC_INDIRECT)
1174 fprintf (asm_out_file, ".reference .constructors_used\n");
1175 }
1176
1177 void
1178 machopic_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
1179 {
1180 if (MACHOPIC_INDIRECT)
1181 mod_term_section ();
1182 else
1183 destructor_section ();
1184 assemble_align (POINTER_SIZE);
1185 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1186
1187 if (! MACHOPIC_INDIRECT)
1188 fprintf (asm_out_file, ".reference .destructors_used\n");
1189 }
1190
1191 void
1192 darwin_globalize_label (FILE *stream, const char *name)
1193 {
1194 if (!!strncmp (name, "_OBJC_", 6))
1195 default_globalize_label (stream, name);
1196 }
1197
1198 void
1199 darwin_asm_named_section (const char *name,
1200 unsigned int flags ATTRIBUTE_UNUSED,
1201 tree decl ATTRIBUTE_UNUSED)
1202 {
1203 fprintf (asm_out_file, "\t.section %s\n", name);
1204 }
1205
1206 void
1207 darwin_unique_section (tree decl ATTRIBUTE_UNUSED, int reloc ATTRIBUTE_UNUSED)
1208 {
1209 /* Darwin does not use unique sections. */
1210 }
1211
1212 /* Handle a "weak_import" attribute; arguments as in
1213 struct attribute_spec.handler. */
1214
1215 tree
1216 darwin_handle_weak_import_attribute (tree *node, tree name,
1217 tree ARG_UNUSED (args),
1218 int ARG_UNUSED (flags),
1219 bool * no_add_attrs)
1220 {
1221 if (TREE_CODE (*node) != FUNCTION_DECL)
1222 {
1223 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1224 *no_add_attrs = true;
1225 }
1226 else
1227 declare_weak (*node);
1228
1229 return NULL_TREE;
1230 }
1231
1232 static void
1233 no_dead_strip (FILE *file, const char *lab)
1234 {
1235 fprintf (file, ".no_dead_strip %s\n", lab);
1236 }
1237
1238 /* Emit a label for an FDE, making it global and/or weak if appropriate.
1239 The third parameter is nonzero if this is for exception handling.
1240 The fourth parameter is nonzero if this is just a placeholder for an
1241 FDE that we are omitting. */
1242
1243 void
1244 darwin_emit_unwind_label (FILE *file, tree decl, int for_eh, int empty)
1245 {
1246 tree id = DECL_ASSEMBLER_NAME (decl)
1247 ? DECL_ASSEMBLER_NAME (decl)
1248 : DECL_NAME (decl);
1249
1250 const char *prefix = "_";
1251 const int prefix_len = 1;
1252
1253 const char *base = IDENTIFIER_POINTER (id);
1254 unsigned int base_len = IDENTIFIER_LENGTH (id);
1255
1256 const char *suffix = ".eh";
1257
1258 int need_quotes = name_needs_quotes (base);
1259 int quotes_len = need_quotes ? 2 : 0;
1260 char *lab;
1261
1262 if (! for_eh)
1263 suffix = ".eh1";
1264
1265 lab = xmalloc (prefix_len + base_len + strlen (suffix) + quotes_len + 1);
1266 lab[0] = '\0';
1267
1268 if (need_quotes)
1269 strcat(lab, "\"");
1270 strcat(lab, prefix);
1271 strcat(lab, base);
1272 strcat(lab, suffix);
1273 if (need_quotes)
1274 strcat(lab, "\"");
1275
1276 if (TREE_PUBLIC (decl))
1277 fprintf (file, "\t%s %s\n",
1278 (DECL_VISIBILITY (decl) != VISIBILITY_HIDDEN
1279 ? ".globl"
1280 : ".private_extern"),
1281 lab);
1282
1283 if (DECL_WEAK (decl))
1284 fprintf (file, "\t.weak_definition %s\n", lab);
1285
1286 if (empty)
1287 {
1288 fprintf (file, "%s = 0\n", lab);
1289
1290 /* Mark the absolute .eh and .eh1 style labels as needed to
1291 ensure that we don't dead code strip them and keep such
1292 labels from another instantiation point until we can fix this
1293 properly with group comdat support. */
1294 no_dead_strip (file, lab);
1295 }
1296 else
1297 fprintf (file, "%s:\n", lab);
1298
1299 free (lab);
1300 }
1301
1302 /* Generate a PC-relative reference to a Mach-O non-lazy-symbol. */
1303
1304 void
1305 darwin_non_lazy_pcrel (FILE *file, rtx addr)
1306 {
1307 const char *nlp_name;
1308
1309 if (GET_CODE (addr) != SYMBOL_REF)
1310 abort ();
1311
1312 nlp_name = machopic_indirection_name (addr, /*stub_p=*/false);
1313 fputs ("\t.long\t", file);
1314 ASM_OUTPUT_LABELREF (file, nlp_name);
1315 fputs ("-.", file);
1316 }
1317
1318 /* Emit an assembler directive to set visibility for a symbol. The
1319 only supported visibilities are VISIBILITY_DEFAULT and
1320 VISIBILITY_HIDDEN; the latter corresponds to Darwin's "private
1321 extern". There is no MACH-O equivalent of ELF's
1322 VISIBILITY_INTERNAL or VISIBILITY_PROTECTED. */
1323
1324 void
1325 darwin_assemble_visibility (tree decl, int vis)
1326 {
1327 if (vis == VISIBILITY_DEFAULT)
1328 ;
1329 else if (vis == VISIBILITY_HIDDEN)
1330 {
1331 fputs ("\t.private_extern ", asm_out_file);
1332 assemble_name (asm_out_file,
1333 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
1334 fputs ("\n", asm_out_file);
1335 }
1336 else
1337 warning ("internal and protected visibility attributes not supported"
1338 "in this configuration; ignored");
1339 }
1340
1341 /* Output a difference of two labels that will be an assembly time
1342 constant if the two labels are local. (.long lab1-lab2 will be
1343 very different if lab1 is at the boundary between two sections; it
1344 will be relocated according to the second section, not the first,
1345 so one ends up with a difference between labels in different
1346 sections, which is bad in the dwarf2 eh context for instance.) */
1347
1348 static int darwin_dwarf_label_counter;
1349
1350 void
1351 darwin_asm_output_dwarf_delta (FILE *file, int size ATTRIBUTE_UNUSED,
1352 const char *lab1, const char *lab2)
1353 {
1354 int islocaldiff = (lab1[0] == '*' && lab1[1] == 'L'
1355 && lab2[0] == '*' && lab2[1] == 'L');
1356
1357 if (islocaldiff)
1358 fprintf (file, "\t.set L$set$%d,", darwin_dwarf_label_counter);
1359 else
1360 fprintf (file, "\t%s\t", ".long");
1361 assemble_name (file, lab1);
1362 fprintf (file, "-");
1363 assemble_name (file, lab2);
1364 if (islocaldiff)
1365 fprintf (file, "\n\t.long L$set$%d", darwin_dwarf_label_counter++);
1366 }
1367
1368 void
1369 darwin_file_end (void)
1370 {
1371 machopic_finish (asm_out_file);
1372 if (strcmp (lang_hooks.name, "GNU C++") == 0)
1373 {
1374 constructor_section ();
1375 destructor_section ();
1376 ASM_OUTPUT_ALIGN (asm_out_file, 1);
1377 }
1378 fprintf (asm_out_file, "\t.subsections_via_symbols\n");
1379 }
1380
1381 /* True, iff we're generating fast turn around debugging code. When
1382 true, we arrange for function prologues to start with 4 nops so
1383 that gdb may insert code to redirect them, and for data to accessed
1384 indirectly. The runtime uses this indirection to forward
1385 references for data to the original instance of that data. */
1386
1387 int darwin_fix_and_continue;
1388 const char *darwin_fix_and_continue_switch;
1389
1390 #include "gt-darwin.h"