real.h (struct real_format): Split the signbit field into two two fields, signbit_ro...
[gcc.git] / gcc / varasm.c
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 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 the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
22
23
24 /* This file handles generation of all the assembler code
25 *except* the instructions of a function.
26 This includes declarations of variables and their initial values.
27
28 We also output the assembler code for constants stored in memory
29 and are responsible for combining constants with the same value. */
30
31 #include "config.h"
32 #include "system.h"
33 #include "coretypes.h"
34 #include "tm.h"
35 #include "rtl.h"
36 #include "tree.h"
37 #include "flags.h"
38 #include "function.h"
39 #include "expr.h"
40 #include "hard-reg-set.h"
41 #include "regs.h"
42 #include "real.h"
43 #include "output.h"
44 #include "toplev.h"
45 #include "hashtab.h"
46 #include "c-pragma.h"
47 #include "ggc.h"
48 #include "langhooks.h"
49 #include "tm_p.h"
50 #include "debug.h"
51 #include "target.h"
52 #include "tree-mudflap.h"
53 #include "cgraph.h"
54 #include "cfglayout.h"
55
56 #ifdef XCOFF_DEBUGGING_INFO
57 #include "xcoffout.h" /* Needed for external data
58 declarations for e.g. AIX 4.x. */
59 #endif
60
61 /* The (assembler) name of the first globally-visible object output. */
62 const char *first_global_object_name;
63 const char *weak_global_object_name;
64
65 struct addr_const;
66 struct constant_descriptor_rtx;
67 struct rtx_constant_pool;
68
69 struct varasm_status GTY(())
70 {
71 /* If we're using a per-function constant pool, this is it. */
72 struct rtx_constant_pool *pool;
73
74 /* Number of tree-constants deferred during the expansion of this
75 function. */
76 unsigned int deferred_constants;
77 };
78
79 #define n_deferred_constants (cfun->varasm->deferred_constants)
80
81 /* Number for making the label on the next
82 constant that is stored in memory. */
83
84 static GTY(()) int const_labelno;
85
86 /* Carry information from ASM_DECLARE_OBJECT_NAME
87 to ASM_FINISH_DECLARE_OBJECT. */
88
89 int size_directive_output;
90
91 /* The last decl for which assemble_variable was called,
92 if it did ASM_DECLARE_OBJECT_NAME.
93 If the last call to assemble_variable didn't do that,
94 this holds 0. */
95
96 tree last_assemble_variable_decl;
97
98 /* The following global variable indicates if the section label for the
99 "cold" section of code has been output yet to the assembler. The
100 label is useful when running gdb. This is part of the optimization that
101 partitions hot and cold basic blocks into separate sections of the .o
102 file. */
103
104 static bool unlikely_section_label_printed = false;
105
106 /* The following global variable indicates the label name to be put at
107 the start of the first cold section within each function, when
108 partitioning basic blocks into hot and cold sections. */
109
110 static char *unlikely_section_label = NULL;
111
112 /* The following global variable indicates the section name to be used
113 for the current cold section, when partitioning hot and cold basic
114 blocks into separate sections. */
115
116 static char *unlikely_text_section_name = NULL;
117
118 /* We give all constants their own alias set. Perhaps redundant with
119 MEM_READONLY_P, but pre-dates it. */
120
121 static HOST_WIDE_INT const_alias_set;
122
123 static const char *strip_reg_name (const char *);
124 static int contains_pointers_p (tree);
125 #ifdef ASM_OUTPUT_EXTERNAL
126 static bool incorporeal_function_p (tree);
127 #endif
128 static void decode_addr_const (tree, struct addr_const *);
129 static hashval_t const_desc_hash (const void *);
130 static int const_desc_eq (const void *, const void *);
131 static hashval_t const_hash_1 (const tree);
132 static int compare_constant (const tree, const tree);
133 static tree copy_constant (tree);
134 static void output_constant_def_contents (rtx);
135 static void output_addressed_constants (tree);
136 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
137 static unsigned min_align (unsigned, unsigned);
138 static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int);
139 static void globalize_decl (tree);
140 static void maybe_assemble_visibility (tree);
141 static int in_named_entry_eq (const void *, const void *);
142 static hashval_t in_named_entry_hash (const void *);
143 #ifdef BSS_SECTION_ASM_OP
144 #ifdef ASM_OUTPUT_BSS
145 static void asm_output_bss (FILE *, tree, const char *,
146 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
147 #endif
148 #ifdef ASM_OUTPUT_ALIGNED_BSS
149 static void asm_output_aligned_bss (FILE *, tree, const char *,
150 unsigned HOST_WIDE_INT, int)
151 ATTRIBUTE_UNUSED;
152 #endif
153 #endif /* BSS_SECTION_ASM_OP */
154 static bool asm_emit_uninitialised (tree, const char*,
155 unsigned HOST_WIDE_INT,
156 unsigned HOST_WIDE_INT);
157 static void mark_weak (tree);
158 \f
159 enum in_section { no_section, in_text, in_unlikely_executed_text, in_data,
160 in_named
161 #ifdef BSS_SECTION_ASM_OP
162 , in_bss
163 #endif
164 #ifdef CTORS_SECTION_ASM_OP
165 , in_ctors
166 #endif
167 #ifdef DTORS_SECTION_ASM_OP
168 , in_dtors
169 #endif
170 #ifdef READONLY_DATA_SECTION_ASM_OP
171 , in_readonly_data
172 #endif
173 #ifdef EXTRA_SECTIONS
174 , EXTRA_SECTIONS
175 #endif
176 };
177 static GTY(()) enum in_section in_section = no_section;
178
179 /* Return a nonzero value if DECL has a section attribute. */
180 #ifndef IN_NAMED_SECTION
181 #define IN_NAMED_SECTION(DECL) \
182 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
183 && DECL_SECTION_NAME (DECL) != NULL_TREE)
184 #endif
185
186 /* Text of section name when in_section == in_named. */
187 static GTY(()) const char *in_named_name;
188
189 /* Hash table of flags that have been used for a particular named section. */
190
191 struct in_named_entry GTY(())
192 {
193 const char *name;
194 unsigned int flags;
195 bool declared;
196 };
197
198 static GTY((param_is (struct in_named_entry))) htab_t in_named_htab;
199
200 /* Define functions like text_section for any extra sections. */
201 #ifdef EXTRA_SECTION_FUNCTIONS
202 EXTRA_SECTION_FUNCTIONS
203 #endif
204
205 /* Tell assembler to switch to text section. */
206
207 void
208 text_section (void)
209 {
210 if (in_section != in_text)
211 {
212 in_section = in_text;
213 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
214 }
215 }
216
217 /* Tell assembler to switch to unlikely-to-be-executed text section. */
218
219 void
220 unlikely_text_section (void)
221 {
222 const char *name;
223 int len;
224
225 if (! unlikely_text_section_name)
226 {
227 if (DECL_SECTION_NAME (current_function_decl)
228 && (strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME
229 (current_function_decl)),
230 HOT_TEXT_SECTION_NAME) != 0)
231 && (strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME
232 (current_function_decl)),
233 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) != 0))
234 {
235 name = TREE_STRING_POINTER (DECL_SECTION_NAME
236 (current_function_decl));
237 len = strlen (name);
238 unlikely_text_section_name = xmalloc ((len + 10) * sizeof (char));
239 strcpy (unlikely_text_section_name, name);
240 strcat (unlikely_text_section_name, "_unlikely");
241 }
242 else
243 {
244 len = strlen (UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
245 unlikely_text_section_name = xmalloc (len+1 * sizeof (char));
246 strcpy (unlikely_text_section_name,
247 UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
248 }
249 }
250
251 if ((in_section != in_unlikely_executed_text)
252 && (in_section != in_named
253 || strcmp (in_named_name, unlikely_text_section_name) != 0))
254 {
255 named_section (NULL_TREE, unlikely_text_section_name, 0);
256 in_section = in_unlikely_executed_text;
257
258 if (!unlikely_section_label_printed)
259 {
260 ASM_OUTPUT_LABEL (asm_out_file, unlikely_section_label);
261 unlikely_section_label_printed = true;
262 }
263 }
264 }
265
266 /* Tell assembler to switch to data section. */
267
268 void
269 data_section (void)
270 {
271 if (in_section != in_data)
272 {
273 in_section = in_data;
274 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
275 }
276 }
277
278 /* Tell assembler to switch to read-only data section. This is normally
279 the text section. */
280
281 void
282 readonly_data_section (void)
283 {
284 #ifdef READONLY_DATA_SECTION
285 READONLY_DATA_SECTION (); /* Note this can call data_section. */
286 #else
287 #ifdef READONLY_DATA_SECTION_ASM_OP
288 if (in_section != in_readonly_data)
289 {
290 in_section = in_readonly_data;
291 fputs (READONLY_DATA_SECTION_ASM_OP, asm_out_file);
292 fputc ('\n', asm_out_file);
293 }
294 #else
295 text_section ();
296 #endif
297 #endif
298 }
299
300 /* Determine if we're in the text section. */
301
302 int
303 in_text_section (void)
304 {
305 return in_section == in_text;
306 }
307
308 /* Determine if we're in the unlikely-to-be-executed text section. */
309
310 int
311 in_unlikely_text_section (void)
312 {
313 bool ret_val;
314
315 ret_val = ((in_section == in_unlikely_executed_text)
316 || (in_section == in_named
317 && unlikely_text_section_name
318 && strcmp (in_named_name, unlikely_text_section_name) == 0));
319
320 return ret_val;
321 }
322
323 /* Determine if we're in the data section. */
324
325 int
326 in_data_section (void)
327 {
328 return in_section == in_data;
329 }
330
331 /* Helper routines for maintaining in_named_htab. */
332
333 static int
334 in_named_entry_eq (const void *p1, const void *p2)
335 {
336 const struct in_named_entry *old = p1;
337 const char *new = p2;
338
339 return strcmp (old->name, new) == 0;
340 }
341
342 static hashval_t
343 in_named_entry_hash (const void *p)
344 {
345 const struct in_named_entry *old = p;
346 return htab_hash_string (old->name);
347 }
348
349 /* If SECTION has been seen before as a named section, return the flags
350 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
351 set of flags for a section to have, so 0 does not mean that the section
352 has not been seen. */
353
354 static unsigned int
355 get_named_section_flags (const char *section)
356 {
357 struct in_named_entry **slot;
358
359 slot = (struct in_named_entry **)
360 htab_find_slot_with_hash (in_named_htab, section,
361 htab_hash_string (section), NO_INSERT);
362
363 return slot ? (*slot)->flags : 0;
364 }
365
366 /* Returns true if the section has been declared before. Sets internal
367 flag on this section in in_named_hash so subsequent calls on this
368 section will return false. */
369
370 bool
371 named_section_first_declaration (const char *name)
372 {
373 struct in_named_entry **slot;
374
375 slot = (struct in_named_entry **)
376 htab_find_slot_with_hash (in_named_htab, name,
377 htab_hash_string (name), NO_INSERT);
378 if (! (*slot)->declared)
379 {
380 (*slot)->declared = true;
381 return true;
382 }
383 else
384 {
385 return false;
386 }
387 }
388
389
390 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
391 different set of flags, return false. */
392
393 bool
394 set_named_section_flags (const char *section, unsigned int flags)
395 {
396 struct in_named_entry **slot, *entry;
397
398 slot = (struct in_named_entry **)
399 htab_find_slot_with_hash (in_named_htab, section,
400 htab_hash_string (section), INSERT);
401 entry = *slot;
402
403 if (!entry)
404 {
405 entry = ggc_alloc (sizeof (*entry));
406 *slot = entry;
407 entry->name = ggc_strdup (section);
408 entry->flags = flags;
409 entry->declared = false;
410 }
411 else if (entry->flags != flags)
412 return false;
413
414 return true;
415 }
416
417 /* Tell assembler to change to section NAME with attributes FLAGS. If
418 DECL is non-NULL, it is the VAR_DECL or FUNCTION_DECL with which
419 this section is associated. */
420
421 void
422 named_section_real (const char *name, unsigned int flags, tree decl)
423 {
424 if (in_section != in_named || strcmp (name, in_named_name) != 0)
425 {
426 bool unchanged = set_named_section_flags (name, flags);
427
428 gcc_assert (unchanged);
429
430 targetm.asm_out.named_section (name, flags, decl);
431
432 if (flags & SECTION_FORGET)
433 in_section = no_section;
434 else
435 {
436 in_named_name = ggc_strdup (name);
437 in_section = in_named;
438 }
439 }
440 }
441
442 /* Tell assembler to change to section NAME for DECL.
443 If DECL is NULL, just switch to section NAME.
444 If NAME is NULL, get the name from DECL.
445 If RELOC is 1, the initializer for DECL contains relocs. */
446
447 void
448 named_section (tree decl, const char *name, int reloc)
449 {
450 unsigned int flags;
451
452 gcc_assert (!decl || DECL_P (decl));
453 if (name == NULL)
454 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
455
456 if (strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0
457 && !unlikely_text_section_name)
458 unlikely_text_section_name =
459 xstrdup (UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
460
461 flags = targetm.section_type_flags (decl, name, reloc);
462
463 /* Sanity check user variables for flag changes. Non-user
464 section flag changes will abort in named_section_flags.
465 However, don't complain if SECTION_OVERRIDE is set.
466 We trust that the setter knows that it is safe to ignore
467 the default flags for this decl. */
468 if (decl && ! set_named_section_flags (name, flags))
469 {
470 flags = get_named_section_flags (name);
471 if ((flags & SECTION_OVERRIDE) == 0)
472 error ("%J%D causes a section type conflict", decl, decl);
473 }
474
475 named_section_real (name, flags, decl);
476 }
477
478 /* If required, set DECL_SECTION_NAME to a unique name. */
479
480 void
481 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
482 int flag_function_or_data_sections)
483 {
484 if (DECL_SECTION_NAME (decl) == NULL_TREE
485 && targetm.have_named_sections
486 && (flag_function_or_data_sections
487 || DECL_ONE_ONLY (decl)))
488 targetm.asm_out.unique_section (decl, reloc);
489 }
490
491 #ifdef BSS_SECTION_ASM_OP
492
493 /* Tell the assembler to switch to the bss section. */
494
495 void
496 bss_section (void)
497 {
498 if (in_section != in_bss)
499 {
500 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
501 in_section = in_bss;
502 }
503 }
504
505 #ifdef ASM_OUTPUT_BSS
506
507 /* Utility function for ASM_OUTPUT_BSS for targets to use if
508 they don't support alignments in .bss.
509 ??? It is believed that this function will work in most cases so such
510 support is localized here. */
511
512 static void
513 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
514 const char *name,
515 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
516 unsigned HOST_WIDE_INT rounded)
517 {
518 targetm.asm_out.globalize_label (file, name);
519 bss_section ();
520 #ifdef ASM_DECLARE_OBJECT_NAME
521 last_assemble_variable_decl = decl;
522 ASM_DECLARE_OBJECT_NAME (file, name, decl);
523 #else
524 /* Standard thing is just output label for the object. */
525 ASM_OUTPUT_LABEL (file, name);
526 #endif /* ASM_DECLARE_OBJECT_NAME */
527 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
528 }
529
530 #endif
531
532 #ifdef ASM_OUTPUT_ALIGNED_BSS
533
534 /* Utility function for targets to use in implementing
535 ASM_OUTPUT_ALIGNED_BSS.
536 ??? It is believed that this function will work in most cases so such
537 support is localized here. */
538
539 static void
540 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
541 const char *name, unsigned HOST_WIDE_INT size,
542 int align)
543 {
544 bss_section ();
545 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
546 #ifdef ASM_DECLARE_OBJECT_NAME
547 last_assemble_variable_decl = decl;
548 ASM_DECLARE_OBJECT_NAME (file, name, decl);
549 #else
550 /* Standard thing is just output label for the object. */
551 ASM_OUTPUT_LABEL (file, name);
552 #endif /* ASM_DECLARE_OBJECT_NAME */
553 ASM_OUTPUT_SKIP (file, size ? size : 1);
554 }
555
556 #endif
557
558 #endif /* BSS_SECTION_ASM_OP */
559
560 /* Switch to the section for function DECL.
561
562 If DECL is NULL_TREE, switch to the text section. We can be passed
563 NULL_TREE under some circumstances by dbxout.c at least. */
564
565 void
566 function_section (tree decl)
567 {
568 if (decl == NULL_TREE)
569 text_section ();
570 else
571 {
572 /* ??? Typical use of this function maybe shouldn't be looking
573 for unlikely blocks at all - in the event that an entire
574 function is going into the unlikely-execute section, that
575 should be reflected in its DECL_SECTION_NAME. */
576 rtx insns = cfun && cfun->emit ? get_insns () : 0;
577 bool unlikely = insns && scan_ahead_for_unlikely_executed_note (insns);
578
579 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
580 targetm.asm_out.select_section (decl, unlikely, DECL_ALIGN (decl));
581 #else
582 if (unlikely)
583 unlikely_text_section ();
584 else if (DECL_SECTION_NAME (decl))
585 named_section (decl, 0, 0);
586 else
587 text_section ();
588 #endif
589 }
590 }
591
592 /* Switch to read-only data section associated with function DECL. */
593
594 void
595 default_function_rodata_section (tree decl)
596 {
597 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
598 {
599 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
600
601 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
602 if (DECL_ONE_ONLY (decl) && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
603 {
604 size_t len = strlen (name) + 1;
605 char *rname = alloca (len);
606
607 memcpy (rname, name, len);
608 rname[14] = 'r';
609 named_section_real (rname, SECTION_LINKONCE, decl);
610 return;
611 }
612 /* For .text.foo we want to use .rodata.foo. */
613 else if (flag_function_sections && flag_data_sections
614 && strncmp (name, ".text.", 6) == 0)
615 {
616 size_t len = strlen (name) + 1;
617 char *rname = alloca (len + 2);
618
619 memcpy (rname, ".rodata", 7);
620 memcpy (rname + 7, name + 5, len - 5);
621 named_section_flags (rname, 0);
622 return;
623 }
624 }
625
626 readonly_data_section ();
627 }
628
629 /* Switch to read-only data section associated with function DECL
630 for targets where that section should be always the single
631 readonly data section. */
632
633 void
634 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
635 {
636 readonly_data_section ();
637 }
638
639 /* Switch to section for variable DECL. RELOC is the same as the
640 argument to SELECT_SECTION. */
641
642 void
643 variable_section (tree decl, int reloc)
644 {
645 if (IN_NAMED_SECTION (decl))
646 named_section (decl, NULL, reloc);
647 else
648 targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
649 }
650
651 /* Tell assembler to switch to the section for string merging. */
652
653 void
654 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
655 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
656 unsigned int flags ATTRIBUTE_UNUSED)
657 {
658 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
659 && TREE_CODE (decl) == STRING_CST
660 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
661 && align <= 256
662 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
663 {
664 enum machine_mode mode;
665 unsigned int modesize;
666 const char *str;
667 int i, j, len, unit;
668 char name[30];
669
670 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
671 modesize = GET_MODE_BITSIZE (mode);
672 if (modesize >= 8 && modesize <= 256
673 && (modesize & (modesize - 1)) == 0)
674 {
675 if (align < modesize)
676 align = modesize;
677
678 str = TREE_STRING_POINTER (decl);
679 len = TREE_STRING_LENGTH (decl);
680 unit = GET_MODE_SIZE (mode);
681
682 /* Check for embedded NUL characters. */
683 for (i = 0; i < len; i += unit)
684 {
685 for (j = 0; j < unit; j++)
686 if (str[i + j] != '\0')
687 break;
688 if (j == unit)
689 break;
690 }
691 if (i == len - unit)
692 {
693 sprintf (name, ".rodata.str%d.%d", modesize / 8,
694 (int) (align / 8));
695 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
696 if (!i && modesize < align)
697 {
698 /* A "" string with requested alignment greater than
699 character size might cause a problem:
700 if some other string required even bigger
701 alignment than "", then linker might think the
702 "" is just part of padding after some other string
703 and not put it into the hash table initially.
704 But this means "" could have smaller alignment
705 than requested. */
706 #ifdef ASM_OUTPUT_SECTION_START
707 named_section_flags (name, flags);
708 ASM_OUTPUT_SECTION_START (asm_out_file);
709 #else
710 readonly_data_section ();
711 #endif
712 return;
713 }
714
715 named_section_flags (name, flags);
716 return;
717 }
718 }
719 }
720
721 readonly_data_section ();
722 }
723
724 /* Tell assembler to switch to the section for constant merging. */
725
726 void
727 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
728 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
729 unsigned int flags ATTRIBUTE_UNUSED)
730 {
731 unsigned int modesize = GET_MODE_BITSIZE (mode);
732
733 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
734 && mode != VOIDmode
735 && mode != BLKmode
736 && modesize <= align
737 && align >= 8
738 && align <= 256
739 && (align & (align - 1)) == 0)
740 {
741 char name[24];
742
743 sprintf (name, ".rodata.cst%d", (int) (align / 8));
744 flags |= (align / 8) | SECTION_MERGE;
745 named_section_flags (name, flags);
746 return;
747 }
748
749 readonly_data_section ();
750 }
751 \f
752 /* Given NAME, a putative register name, discard any customary prefixes. */
753
754 static const char *
755 strip_reg_name (const char *name)
756 {
757 #ifdef REGISTER_PREFIX
758 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
759 name += strlen (REGISTER_PREFIX);
760 #endif
761 if (name[0] == '%' || name[0] == '#')
762 name++;
763 return name;
764 }
765 \f
766 /* The user has asked for a DECL to have a particular name. Set (or
767 change) it in such a way that we don't prefix an underscore to
768 it. */
769 void
770 set_user_assembler_name (tree decl, const char *name)
771 {
772 char *starred = alloca (strlen (name) + 2);
773 starred[0] = '*';
774 strcpy (starred + 1, name);
775 change_decl_assembler_name (decl, get_identifier (starred));
776 SET_DECL_RTL (decl, NULL_RTX);
777 }
778 \f
779 /* Decode an `asm' spec for a declaration as a register name.
780 Return the register number, or -1 if nothing specified,
781 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
782 or -3 if ASMSPEC is `cc' and is not recognized,
783 or -4 if ASMSPEC is `memory' and is not recognized.
784 Accept an exact spelling or a decimal number.
785 Prefixes such as % are optional. */
786
787 int
788 decode_reg_name (const char *asmspec)
789 {
790 if (asmspec != 0)
791 {
792 int i;
793
794 /* Get rid of confusing prefixes. */
795 asmspec = strip_reg_name (asmspec);
796
797 /* Allow a decimal number as a "register name". */
798 for (i = strlen (asmspec) - 1; i >= 0; i--)
799 if (! ISDIGIT (asmspec[i]))
800 break;
801 if (asmspec[0] != 0 && i < 0)
802 {
803 i = atoi (asmspec);
804 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
805 return i;
806 else
807 return -2;
808 }
809
810 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
811 if (reg_names[i][0]
812 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
813 return i;
814
815 #ifdef ADDITIONAL_REGISTER_NAMES
816 {
817 static const struct { const char *const name; const int number; } table[]
818 = ADDITIONAL_REGISTER_NAMES;
819
820 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
821 if (! strcmp (asmspec, table[i].name))
822 return table[i].number;
823 }
824 #endif /* ADDITIONAL_REGISTER_NAMES */
825
826 if (!strcmp (asmspec, "memory"))
827 return -4;
828
829 if (!strcmp (asmspec, "cc"))
830 return -3;
831
832 return -2;
833 }
834
835 return -1;
836 }
837 \f
838 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
839 have static storage duration. In other words, it should not be an
840 automatic variable, including PARM_DECLs.
841
842 There is, however, one exception: this function handles variables
843 explicitly placed in a particular register by the user.
844
845 This is never called for PARM_DECL nodes. */
846
847 void
848 make_decl_rtl (tree decl)
849 {
850 const char *name = 0;
851 int reg_number;
852 rtx x;
853
854 /* Check that we are not being given an automatic variable. */
855 gcc_assert (TREE_CODE (decl) != PARM_DECL
856 && TREE_CODE (decl) != RESULT_DECL);
857
858 /* A weak alias has TREE_PUBLIC set but not the other bits. */
859 gcc_assert (TREE_CODE (decl) != VAR_DECL
860 || TREE_STATIC (decl)
861 || TREE_PUBLIC (decl)
862 || DECL_EXTERNAL (decl)
863 || DECL_REGISTER (decl));
864
865 /* And that we were not given a type or a label. */
866 gcc_assert (TREE_CODE (decl) != TYPE_DECL
867 && TREE_CODE (decl) != LABEL_DECL);
868
869 /* For a duplicate declaration, we can be called twice on the
870 same DECL node. Don't discard the RTL already made. */
871 if (DECL_RTL_SET_P (decl))
872 {
873 /* If the old RTL had the wrong mode, fix the mode. */
874 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
875 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
876 DECL_MODE (decl), 0));
877
878 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
879 return;
880
881 /* ??? Another way to do this would be to maintain a hashed
882 table of such critters. Instead of adding stuff to a DECL
883 to give certain attributes to it, we could use an external
884 hash map from DECL to set of attributes. */
885
886 /* Let the target reassign the RTL if it wants.
887 This is necessary, for example, when one machine specific
888 decl attribute overrides another. */
889 targetm.encode_section_info (decl, DECL_RTL (decl), false);
890
891 /* Make this function static known to the mudflap runtime. */
892 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
893 mudflap_enqueue_decl (decl);
894
895 return;
896 }
897
898 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
899
900
901 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
902 {
903 reg_number = decode_reg_name (name);
904 /* First detect errors in declaring global registers. */
905 if (reg_number == -1)
906 error ("%Jregister name not specified for %qD", decl, decl);
907 else if (reg_number < 0)
908 error ("%Jinvalid register name for %qD", decl, decl);
909 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
910 error ("%Jdata type of %qD isn%'t suitable for a register",
911 decl, decl);
912 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
913 error ("%Jregister specified for %qD isn%'t suitable for data type",
914 decl, decl);
915 /* Now handle properly declared static register variables. */
916 else
917 {
918 int nregs;
919
920 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
921 {
922 DECL_INITIAL (decl) = 0;
923 error ("global register variable has initial value");
924 }
925 if (TREE_THIS_VOLATILE (decl))
926 warning ("volatile register variables don%'t "
927 "work as you might wish");
928
929 /* If the user specified one of the eliminables registers here,
930 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
931 confused with that register and be eliminated. This usage is
932 somewhat suspect... */
933
934 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
935 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
936 REG_USERVAR_P (DECL_RTL (decl)) = 1;
937
938 if (TREE_STATIC (decl))
939 {
940 /* Make this register global, so not usable for anything
941 else. */
942 #ifdef ASM_DECLARE_REGISTER_GLOBAL
943 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
944 #endif
945 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
946 while (nregs > 0)
947 globalize_reg (reg_number + --nregs);
948 }
949
950 /* As a register variable, it has no section. */
951 return;
952 }
953 }
954 /* Now handle ordinary static variables and functions (in memory).
955 Also handle vars declared register invalidly. */
956 else if (name[0] == '*')
957 {
958 #ifdef REGISTER_PREFIX
959 if (strlen (REGISTER_PREFIX) != 0)
960 {
961 reg_number = decode_reg_name (name);
962 if (reg_number >= 0 || reg_number == -3)
963 error ("%Jregister name given for non-register variable %qD", decl, decl);
964 }
965 #endif
966 }
967
968 /* Specifying a section attribute on a variable forces it into a
969 non-.bss section, and thus it cannot be common. */
970 if (TREE_CODE (decl) == VAR_DECL
971 && DECL_SECTION_NAME (decl) != NULL_TREE
972 && DECL_INITIAL (decl) == NULL_TREE
973 && DECL_COMMON (decl))
974 DECL_COMMON (decl) = 0;
975
976 /* Variables can't be both common and weak. */
977 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
978 DECL_COMMON (decl) = 0;
979
980 x = gen_rtx_SYMBOL_REF (Pmode, name);
981 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
982 SYMBOL_REF_DECL (x) = decl;
983
984 x = gen_rtx_MEM (DECL_MODE (decl), x);
985 if (TREE_CODE (decl) != FUNCTION_DECL)
986 set_mem_attributes (x, decl, 1);
987 SET_DECL_RTL (decl, x);
988
989 /* Optionally set flags or add text to the name to record information
990 such as that it is a function name.
991 If the name is changed, the macro ASM_OUTPUT_LABELREF
992 will have to know how to strip this information. */
993 targetm.encode_section_info (decl, DECL_RTL (decl), true);
994
995 /* Make this function static known to the mudflap runtime. */
996 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
997 mudflap_enqueue_decl (decl);
998 }
999
1000 /* Make the rtl for variable VAR be volatile.
1001 Use this only for static variables. */
1002
1003 void
1004 make_var_volatile (tree var)
1005 {
1006 gcc_assert (MEM_P (DECL_RTL (var)));
1007
1008 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
1009 }
1010 \f
1011 /* Output a string of literal assembler code
1012 for an `asm' keyword used between functions. */
1013
1014 void
1015 assemble_asm (tree string)
1016 {
1017 app_enable ();
1018
1019 if (TREE_CODE (string) == ADDR_EXPR)
1020 string = TREE_OPERAND (string, 0);
1021
1022 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1023 }
1024
1025 /* Record an element in the table of global destructors. SYMBOL is
1026 a SYMBOL_REF of the function to be called; PRIORITY is a number
1027 between 0 and MAX_INIT_PRIORITY. */
1028
1029 void
1030 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1031 int priority ATTRIBUTE_UNUSED)
1032 {
1033 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1034 /* Tell GNU LD that this is part of the static destructor set.
1035 This will work for any system that uses stabs, most usefully
1036 aout systems. */
1037 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1038 dbxout_stab_value_label (XSTR (symbol, 0));
1039 #else
1040 sorry ("global destructors not supported on this target");
1041 #endif
1042 }
1043
1044 void
1045 default_named_section_asm_out_destructor (rtx symbol, int priority)
1046 {
1047 const char *section = ".dtors";
1048 char buf[16];
1049
1050 /* ??? This only works reliably with the GNU linker. */
1051 if (priority != DEFAULT_INIT_PRIORITY)
1052 {
1053 sprintf (buf, ".dtors.%.5u",
1054 /* Invert the numbering so the linker puts us in the proper
1055 order; constructors are run from right to left, and the
1056 linker sorts in increasing order. */
1057 MAX_INIT_PRIORITY - priority);
1058 section = buf;
1059 }
1060
1061 named_section_flags (section, SECTION_WRITE);
1062 assemble_align (POINTER_SIZE);
1063 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1064 }
1065
1066 #ifdef DTORS_SECTION_ASM_OP
1067 void
1068 dtors_section (void)
1069 {
1070 if (in_section != in_dtors)
1071 {
1072 in_section = in_dtors;
1073 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1074 fputc ('\n', asm_out_file);
1075 }
1076 }
1077
1078 void
1079 default_dtor_section_asm_out_destructor (rtx symbol,
1080 int priority ATTRIBUTE_UNUSED)
1081 {
1082 dtors_section ();
1083 assemble_align (POINTER_SIZE);
1084 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1085 }
1086 #endif
1087
1088 /* Likewise for global constructors. */
1089
1090 void
1091 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1092 int priority ATTRIBUTE_UNUSED)
1093 {
1094 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1095 /* Tell GNU LD that this is part of the static destructor set.
1096 This will work for any system that uses stabs, most usefully
1097 aout systems. */
1098 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1099 dbxout_stab_value_label (XSTR (symbol, 0));
1100 #else
1101 sorry ("global constructors not supported on this target");
1102 #endif
1103 }
1104
1105 void
1106 default_named_section_asm_out_constructor (rtx symbol, int priority)
1107 {
1108 const char *section = ".ctors";
1109 char buf[16];
1110
1111 /* ??? This only works reliably with the GNU linker. */
1112 if (priority != DEFAULT_INIT_PRIORITY)
1113 {
1114 sprintf (buf, ".ctors.%.5u",
1115 /* Invert the numbering so the linker puts us in the proper
1116 order; constructors are run from right to left, and the
1117 linker sorts in increasing order. */
1118 MAX_INIT_PRIORITY - priority);
1119 section = buf;
1120 }
1121
1122 named_section_flags (section, SECTION_WRITE);
1123 assemble_align (POINTER_SIZE);
1124 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1125 }
1126
1127 #ifdef CTORS_SECTION_ASM_OP
1128 void
1129 ctors_section (void)
1130 {
1131 if (in_section != in_ctors)
1132 {
1133 in_section = in_ctors;
1134 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1135 fputc ('\n', asm_out_file);
1136 }
1137 }
1138
1139 void
1140 default_ctor_section_asm_out_constructor (rtx symbol,
1141 int priority ATTRIBUTE_UNUSED)
1142 {
1143 ctors_section ();
1144 assemble_align (POINTER_SIZE);
1145 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1146 }
1147 #endif
1148 \f
1149 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1150 a nonzero value if the constant pool should be output before the
1151 start of the function, or a zero value if the pool should output
1152 after the end of the function. The default is to put it before the
1153 start. */
1154
1155 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1156 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1157 #endif
1158
1159 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1160 to be output to assembler.
1161 Set first_global_object_name and weak_global_object_name as appropriate. */
1162
1163 void
1164 notice_global_symbol (tree decl)
1165 {
1166 const char **type = &first_global_object_name;
1167
1168 if (first_global_object_name
1169 || !TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
1170 || !DECL_NAME (decl)
1171 || (TREE_CODE (decl) != FUNCTION_DECL
1172 && (TREE_CODE (decl) != VAR_DECL
1173 || (DECL_COMMON (decl)
1174 && (DECL_INITIAL (decl) == 0
1175 || DECL_INITIAL (decl) == error_mark_node))))
1176 || !MEM_P (DECL_RTL (decl)))
1177 return;
1178
1179 /* We win when global object is found, but it is useful to know about weak
1180 symbol as well so we can produce nicer unique names. */
1181 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl))
1182 type = &weak_global_object_name;
1183
1184 if (!*type)
1185 {
1186 const char *p;
1187 char *name;
1188 rtx decl_rtl = DECL_RTL (decl);
1189
1190 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1191 name = xstrdup (p);
1192
1193 *type = name;
1194 }
1195 }
1196
1197 /* Output assembler code for the constant pool of a function and associated
1198 with defining the name of the function. DECL describes the function.
1199 NAME is the function's name. For the constant pool, we use the current
1200 constant pool data. */
1201
1202 void
1203 assemble_start_function (tree decl, const char *fnname)
1204 {
1205 int align;
1206
1207 if (unlikely_text_section_name)
1208 free (unlikely_text_section_name);
1209
1210 unlikely_section_label_printed = false;
1211 unlikely_text_section_name = NULL;
1212
1213 unlikely_section_label = reconcat (unlikely_section_label,
1214 fnname, ".unlikely_section", NULL);
1215
1216 /* The following code does not need preprocessing in the assembler. */
1217
1218 app_disable ();
1219
1220 if (CONSTANT_POOL_BEFORE_FUNCTION)
1221 output_constant_pool (fnname, decl);
1222
1223 /* Make sure the cold text (code) section is properly aligned. This
1224 is necessary here in the case where the function has both hot and
1225 cold sections, because we don't want to re-set the alignment when the
1226 section switch happens mid-function. We don't need to set the hot
1227 section alignment here, because code further down in this function
1228 sets the alignment for whichever section comes first, and if there
1229 is a hot section it is guaranteed to be first. */
1230
1231 if (flag_reorder_blocks_and_partition)
1232 {
1233 unlikely_text_section ();
1234 assemble_align (FUNCTION_BOUNDARY);
1235 }
1236
1237 resolve_unique_section (decl, 0, flag_function_sections);
1238 function_section (decl);
1239
1240 /* Tell assembler to move to target machine's alignment for functions. */
1241 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1242 if (align < force_align_functions_log)
1243 align = force_align_functions_log;
1244 if (align > 0)
1245 {
1246 ASM_OUTPUT_ALIGN (asm_out_file, align);
1247 }
1248
1249 /* Handle a user-specified function alignment.
1250 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1251 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1252 if (align_functions_log > align
1253 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1254 {
1255 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1256 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1257 align_functions_log, align_functions - 1);
1258 #else
1259 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1260 #endif
1261 }
1262
1263 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1264 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1265 #endif
1266
1267 (*debug_hooks->begin_function) (decl);
1268
1269 /* Make function name accessible from other files, if appropriate. */
1270
1271 if (TREE_PUBLIC (decl))
1272 {
1273 notice_global_symbol (decl);
1274
1275 globalize_decl (decl);
1276
1277 maybe_assemble_visibility (decl);
1278 }
1279
1280 if (DECL_PRESERVE_P (decl))
1281 targetm.asm_out.mark_decl_preserved (fnname);
1282
1283 /* Do any machine/system dependent processing of the function name. */
1284 #ifdef ASM_DECLARE_FUNCTION_NAME
1285 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1286 #else
1287 /* Standard thing is just output label for the function. */
1288 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1289 #endif /* ASM_DECLARE_FUNCTION_NAME */
1290
1291 if (in_unlikely_text_section ()
1292 && !unlikely_section_label_printed)
1293 {
1294 ASM_OUTPUT_LABEL (asm_out_file, unlikely_section_label);
1295 unlikely_section_label_printed = true;
1296 }
1297 }
1298
1299 /* Output assembler code associated with defining the size of the
1300 function. DECL describes the function. NAME is the function's name. */
1301
1302 void
1303 assemble_end_function (tree decl, const char *fnname)
1304 {
1305 #ifdef ASM_DECLARE_FUNCTION_SIZE
1306 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1307 #endif
1308 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1309 {
1310 output_constant_pool (fnname, decl);
1311 function_section (decl); /* need to switch back */
1312 }
1313 }
1314 \f
1315 /* Assemble code to leave SIZE bytes of zeros. */
1316
1317 void
1318 assemble_zeros (unsigned HOST_WIDE_INT size)
1319 {
1320 /* Do no output if -fsyntax-only. */
1321 if (flag_syntax_only)
1322 return;
1323
1324 #ifdef ASM_NO_SKIP_IN_TEXT
1325 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1326 so we must output 0s explicitly in the text section. */
1327 if ((ASM_NO_SKIP_IN_TEXT && in_text_section ())
1328 || (ASM_NO_SKIP_IN_TEXT && in_unlikely_text_section ()))
1329 {
1330 unsigned HOST_WIDE_INT i;
1331 for (i = 0; i < size; i++)
1332 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1333 }
1334 else
1335 #endif
1336 if (size > 0)
1337 ASM_OUTPUT_SKIP (asm_out_file, size);
1338 }
1339
1340 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1341
1342 void
1343 assemble_align (int align)
1344 {
1345 if (align > BITS_PER_UNIT)
1346 {
1347 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1348 }
1349 }
1350
1351 /* Assemble a string constant with the specified C string as contents. */
1352
1353 void
1354 assemble_string (const char *p, int size)
1355 {
1356 int pos = 0;
1357 int maximum = 2000;
1358
1359 /* If the string is very long, split it up. */
1360
1361 while (pos < size)
1362 {
1363 int thissize = size - pos;
1364 if (thissize > maximum)
1365 thissize = maximum;
1366
1367 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1368
1369 pos += thissize;
1370 p += thissize;
1371 }
1372 }
1373
1374 \f
1375 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1376 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1377 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1378 #else
1379 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1380 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1381 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1382 #else
1383 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1384 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1385 #endif
1386 #endif
1387
1388 #if defined ASM_OUTPUT_ALIGNED_BSS
1389 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1390 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1391 #else
1392 #if defined ASM_OUTPUT_BSS
1393 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1394 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1395 #else
1396 #undef ASM_EMIT_BSS
1397 #endif
1398 #endif
1399
1400 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1401 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1402 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1403 #else
1404 #if defined ASM_OUTPUT_ALIGNED_COMMON
1405 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1406 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1407 #else
1408 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1409 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1410 #endif
1411 #endif
1412
1413 static bool
1414 asm_emit_uninitialised (tree decl, const char *name,
1415 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1416 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1417 {
1418 enum
1419 {
1420 asm_dest_common,
1421 asm_dest_bss,
1422 asm_dest_local
1423 }
1424 destination = asm_dest_local;
1425
1426 /* ??? We should handle .bss via select_section mechanisms rather than
1427 via special target hooks. That would eliminate this special case. */
1428 if (TREE_PUBLIC (decl))
1429 {
1430 if (!DECL_COMMON (decl))
1431 #ifdef ASM_EMIT_BSS
1432 destination = asm_dest_bss;
1433 #else
1434 return false;
1435 #endif
1436 else
1437 destination = asm_dest_common;
1438 }
1439
1440 if (destination != asm_dest_common)
1441 {
1442 resolve_unique_section (decl, 0, flag_data_sections);
1443 /* Custom sections don't belong here. */
1444 if (DECL_SECTION_NAME (decl))
1445 return false;
1446 }
1447
1448 if (destination == asm_dest_bss)
1449 globalize_decl (decl);
1450
1451 if (flag_shared_data)
1452 {
1453 switch (destination)
1454 {
1455 #ifdef ASM_OUTPUT_SHARED_BSS
1456 case asm_dest_bss:
1457 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1458 return;
1459 #endif
1460 #ifdef ASM_OUTPUT_SHARED_COMMON
1461 case asm_dest_common:
1462 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1463 return;
1464 #endif
1465 #ifdef ASM_OUTPUT_SHARED_LOCAL
1466 case asm_dest_local:
1467 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1468 return;
1469 #endif
1470 default:
1471 break;
1472 }
1473 }
1474
1475 switch (destination)
1476 {
1477 #ifdef ASM_EMIT_BSS
1478 case asm_dest_bss:
1479 ASM_EMIT_BSS (decl, name, size, rounded);
1480 break;
1481 #endif
1482 case asm_dest_common:
1483 ASM_EMIT_COMMON (decl, name, size, rounded);
1484 break;
1485 case asm_dest_local:
1486 ASM_EMIT_LOCAL (decl, name, size, rounded);
1487 break;
1488 default:
1489 gcc_unreachable ();
1490 }
1491
1492 return true;
1493 }
1494
1495 /* Assemble everything that is needed for a variable or function declaration.
1496 Not used for automatic variables, and not used for function definitions.
1497 Should not be called for variables of incomplete structure type.
1498
1499 TOP_LEVEL is nonzero if this variable has file scope.
1500 AT_END is nonzero if this is the special handling, at end of compilation,
1501 to define things that have had only tentative definitions.
1502 DONT_OUTPUT_DATA if nonzero means don't actually output the
1503 initial value (that will be done by the caller). */
1504
1505 void
1506 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1507 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1508 {
1509 const char *name;
1510 unsigned int align;
1511 int reloc = 0;
1512 rtx decl_rtl;
1513
1514 if (lang_hooks.decls.prepare_assemble_variable)
1515 lang_hooks.decls.prepare_assemble_variable (decl);
1516
1517 last_assemble_variable_decl = 0;
1518
1519 /* Normally no need to say anything here for external references,
1520 since assemble_external is called by the language-specific code
1521 when a declaration is first seen. */
1522
1523 if (DECL_EXTERNAL (decl))
1524 return;
1525
1526 /* Output no assembler code for a function declaration.
1527 Only definitions of functions output anything. */
1528
1529 if (TREE_CODE (decl) == FUNCTION_DECL)
1530 return;
1531
1532 /* Do nothing for global register variables. */
1533 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1534 {
1535 TREE_ASM_WRITTEN (decl) = 1;
1536 return;
1537 }
1538
1539 /* If type was incomplete when the variable was declared,
1540 see if it is complete now. */
1541
1542 if (DECL_SIZE (decl) == 0)
1543 layout_decl (decl, 0);
1544
1545 /* Still incomplete => don't allocate it; treat the tentative defn
1546 (which is what it must have been) as an `extern' reference. */
1547
1548 if (!dont_output_data && DECL_SIZE (decl) == 0)
1549 {
1550 error ("%Jstorage size of %qD isn%'t known", decl, decl);
1551 TREE_ASM_WRITTEN (decl) = 1;
1552 return;
1553 }
1554
1555 /* The first declaration of a variable that comes through this function
1556 decides whether it is global (in C, has external linkage)
1557 or local (in C, has internal linkage). So do nothing more
1558 if this function has already run. */
1559
1560 if (TREE_ASM_WRITTEN (decl))
1561 return;
1562
1563 /* Make sure targetm.encode_section_info is invoked before we set
1564 ASM_WRITTEN. */
1565 decl_rtl = DECL_RTL (decl);
1566
1567 TREE_ASM_WRITTEN (decl) = 1;
1568
1569 /* Do no output if -fsyntax-only. */
1570 if (flag_syntax_only)
1571 return;
1572
1573 app_disable ();
1574
1575 if (! dont_output_data
1576 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1577 {
1578 error ("%Jsize of variable %qD is too large", decl, decl);
1579 return;
1580 }
1581
1582 name = XSTR (XEXP (decl_rtl, 0), 0);
1583 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1584 notice_global_symbol (decl);
1585
1586 /* Compute the alignment of this data. */
1587
1588 align = DECL_ALIGN (decl);
1589
1590 /* In the case for initialing an array whose length isn't specified,
1591 where we have not yet been able to do the layout,
1592 figure out the proper alignment now. */
1593 if (dont_output_data && DECL_SIZE (decl) == 0
1594 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1595 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1596
1597 /* Some object file formats have a maximum alignment which they support.
1598 In particular, a.out format supports a maximum alignment of 4. */
1599 if (align > MAX_OFILE_ALIGNMENT)
1600 {
1601 warning ("%Jalignment of %qD is greater than maximum object "
1602 "file alignment. Using %d", decl, decl,
1603 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1604 align = MAX_OFILE_ALIGNMENT;
1605 }
1606
1607 /* On some machines, it is good to increase alignment sometimes. */
1608 if (! DECL_USER_ALIGN (decl))
1609 {
1610 #ifdef DATA_ALIGNMENT
1611 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1612 #endif
1613 #ifdef CONSTANT_ALIGNMENT
1614 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1615 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1616 #endif
1617 }
1618
1619 /* Reset the alignment in case we have made it tighter, so we can benefit
1620 from it in get_pointer_alignment. */
1621 DECL_ALIGN (decl) = align;
1622 set_mem_align (decl_rtl, align);
1623
1624 if (TREE_PUBLIC (decl))
1625 maybe_assemble_visibility (decl);
1626
1627 if (DECL_PRESERVE_P (decl))
1628 targetm.asm_out.mark_decl_preserved (name);
1629
1630 /* Handle uninitialized definitions. */
1631
1632 /* If the decl has been given an explicit section name, then it
1633 isn't common, and shouldn't be handled as such. */
1634 if (DECL_SECTION_NAME (decl) || dont_output_data)
1635 ;
1636 /* We don't implement common thread-local data at present. */
1637 else if (DECL_THREAD_LOCAL (decl))
1638 {
1639 if (DECL_COMMON (decl))
1640 sorry ("thread-local COMMON data not implemented");
1641 }
1642 else if (DECL_INITIAL (decl) == 0
1643 || DECL_INITIAL (decl) == error_mark_node
1644 || (flag_zero_initialized_in_bss
1645 /* Leave constant zeroes in .rodata so they can be shared. */
1646 && !TREE_READONLY (decl)
1647 && initializer_zerop (DECL_INITIAL (decl))))
1648 {
1649 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1650 unsigned HOST_WIDE_INT rounded = size;
1651
1652 /* Don't allocate zero bytes of common,
1653 since that means "undefined external" in the linker. */
1654 if (size == 0)
1655 rounded = 1;
1656
1657 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1658 so that each uninitialized object starts on such a boundary. */
1659 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1660 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1661 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1662
1663 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1664 if ((unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1665 warning ("%Jrequested alignment for %qD is greater than "
1666 "implemented alignment of %d", decl, decl, rounded);
1667 #endif
1668
1669 /* If the target cannot output uninitialized but not common global data
1670 in .bss, then we have to use .data, so fall through. */
1671 if (asm_emit_uninitialised (decl, name, size, rounded))
1672 return;
1673 }
1674
1675 /* Handle initialized definitions.
1676 Also handle uninitialized global definitions if -fno-common and the
1677 target doesn't support ASM_OUTPUT_BSS. */
1678
1679 /* First make the assembler name(s) global if appropriate. */
1680 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1681 globalize_decl (decl);
1682
1683 /* Output any data that we will need to use the address of. */
1684 if (DECL_INITIAL (decl) == error_mark_node)
1685 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1686 else if (DECL_INITIAL (decl))
1687 {
1688 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1689 output_addressed_constants (DECL_INITIAL (decl));
1690 }
1691
1692 /* Switch to the appropriate section. */
1693 resolve_unique_section (decl, reloc, flag_data_sections);
1694 variable_section (decl, reloc);
1695
1696 /* dbxout.c needs to know this. */
1697 if (in_text_section () || in_unlikely_text_section ())
1698 DECL_IN_TEXT_SECTION (decl) = 1;
1699
1700 /* Output the alignment of this data. */
1701 if (align > BITS_PER_UNIT)
1702 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
1703
1704 /* Do any machine/system dependent processing of the object. */
1705 #ifdef ASM_DECLARE_OBJECT_NAME
1706 last_assemble_variable_decl = decl;
1707 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1708 #else
1709 /* Standard thing is just output label for the object. */
1710 ASM_OUTPUT_LABEL (asm_out_file, name);
1711 #endif /* ASM_DECLARE_OBJECT_NAME */
1712
1713 if (!dont_output_data)
1714 {
1715 if (DECL_INITIAL (decl)
1716 && DECL_INITIAL (decl) != error_mark_node
1717 && !initializer_zerop (DECL_INITIAL (decl)))
1718 /* Output the actual data. */
1719 output_constant (DECL_INITIAL (decl),
1720 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1721 align);
1722 else
1723 /* Leave space for it. */
1724 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1725 }
1726 }
1727
1728 /* Return 1 if type TYPE contains any pointers. */
1729
1730 static int
1731 contains_pointers_p (tree type)
1732 {
1733 switch (TREE_CODE (type))
1734 {
1735 case POINTER_TYPE:
1736 case REFERENCE_TYPE:
1737 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1738 so I'll play safe and return 1. */
1739 case OFFSET_TYPE:
1740 return 1;
1741
1742 case RECORD_TYPE:
1743 case UNION_TYPE:
1744 case QUAL_UNION_TYPE:
1745 {
1746 tree fields;
1747 /* For a type that has fields, see if the fields have pointers. */
1748 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1749 if (TREE_CODE (fields) == FIELD_DECL
1750 && contains_pointers_p (TREE_TYPE (fields)))
1751 return 1;
1752 return 0;
1753 }
1754
1755 case ARRAY_TYPE:
1756 /* An array type contains pointers if its element type does. */
1757 return contains_pointers_p (TREE_TYPE (type));
1758
1759 default:
1760 return 0;
1761 }
1762 }
1763
1764 /* In unit-at-a-time mode, we delay assemble_external processing until
1765 the compilation unit is finalized. This is the best we can do for
1766 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
1767 it all the way to final. See PR 17982 for further discussion. */
1768 static GTY(()) tree pending_assemble_externals;
1769
1770 #ifdef ASM_OUTPUT_EXTERNAL
1771 /* True if DECL is a function decl for which no out-of-line copy exists.
1772 It is assumed that DECL's assembler name has been set. */
1773
1774 static bool
1775 incorporeal_function_p (tree decl)
1776 {
1777 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1778 {
1779 const char *name;
1780
1781 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
1782 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
1783 return true;
1784
1785 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1786 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
1787 return true;
1788 }
1789 return false;
1790 }
1791
1792 /* Actually do the tests to determine if this is necessary, and invoke
1793 ASM_OUTPUT_EXTERNAL. */
1794 static void
1795 assemble_external_real (tree decl)
1796 {
1797 rtx rtl = DECL_RTL (decl);
1798
1799 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1800 && !SYMBOL_REF_USED (XEXP (rtl, 0))
1801 && !incorporeal_function_p (decl))
1802 {
1803 /* Some systems do require some output. */
1804 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1805 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1806 }
1807 }
1808 #endif
1809
1810 void
1811 process_pending_assemble_externals (void)
1812 {
1813 #ifdef ASM_OUTPUT_EXTERNAL
1814 tree list;
1815 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
1816 assemble_external_real (TREE_VALUE (list));
1817
1818 pending_assemble_externals = 0;
1819 #endif
1820 }
1821
1822 /* Output something to declare an external symbol to the assembler.
1823 (Most assemblers don't need this, so we normally output nothing.)
1824 Do nothing if DECL is not external. */
1825
1826 void
1827 assemble_external (tree decl ATTRIBUTE_UNUSED)
1828 {
1829 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1830 main body of this code is only rarely exercised. To provide some
1831 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1832 open. If it's not, we should not be calling this function. */
1833 gcc_assert (asm_out_file);
1834
1835 #ifdef ASM_OUTPUT_EXTERNAL
1836 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
1837 return;
1838
1839 if (flag_unit_at_a_time)
1840 pending_assemble_externals = tree_cons (0, decl,
1841 pending_assemble_externals);
1842 else
1843 assemble_external_real (decl);
1844 #endif
1845 }
1846
1847 /* Similar, for calling a library function FUN. */
1848
1849 void
1850 assemble_external_libcall (rtx fun)
1851 {
1852 /* Declare library function name external when first used, if nec. */
1853 if (! SYMBOL_REF_USED (fun))
1854 {
1855 SYMBOL_REF_USED (fun) = 1;
1856 targetm.asm_out.external_libcall (fun);
1857 }
1858 }
1859
1860 /* Assemble a label named NAME. */
1861
1862 void
1863 assemble_label (const char *name)
1864 {
1865 ASM_OUTPUT_LABEL (asm_out_file, name);
1866 }
1867
1868 /* Set the symbol_referenced flag for ID. */
1869 void
1870 mark_referenced (tree id)
1871 {
1872 TREE_SYMBOL_REFERENCED (id) = 1;
1873 }
1874
1875 /* Set the symbol_referenced flag for DECL and notify callgraph. */
1876 void
1877 mark_decl_referenced (tree decl)
1878 {
1879 if (TREE_CODE (decl) == FUNCTION_DECL)
1880 cgraph_mark_needed_node (cgraph_node (decl));
1881 else if (TREE_CODE (decl) == VAR_DECL)
1882 cgraph_varpool_mark_needed_node (cgraph_varpool_node (decl));
1883 /* else do nothing - we can get various sorts of CST nodes here,
1884 which do not need to be marked. */
1885 }
1886
1887 /* Output to FILE (an assembly file) a reference to NAME. If NAME
1888 starts with a *, the rest of NAME is output verbatim. Otherwise
1889 NAME is transformed in a target-specific way (usually by the
1890 addition of an underscore). */
1891
1892 void
1893 assemble_name_raw (FILE *file, const char *name)
1894 {
1895 if (name[0] == '*')
1896 fputs (&name[1], file);
1897 else
1898 ASM_OUTPUT_LABELREF (file, name);
1899 }
1900
1901 /* Like assemble_name_raw, but should be used when NAME might refer to
1902 an entity that is also represented as a tree (like a function or
1903 variable). If NAME does refer to such an entity, that entity will
1904 be marked as referenced. */
1905
1906 void
1907 assemble_name (FILE *file, const char *name)
1908 {
1909 const char *real_name;
1910 tree id;
1911
1912 real_name = targetm.strip_name_encoding (name);
1913
1914 id = maybe_get_identifier (real_name);
1915 if (id)
1916 mark_referenced (id);
1917
1918 assemble_name_raw (file, name);
1919 }
1920
1921 /* Allocate SIZE bytes writable static space with a gensym name
1922 and return an RTX to refer to its address. */
1923
1924 rtx
1925 assemble_static_space (unsigned HOST_WIDE_INT size)
1926 {
1927 char name[12];
1928 const char *namestring;
1929 rtx x;
1930
1931 #if 0
1932 if (flag_shared_data)
1933 data_section ();
1934 #endif
1935
1936 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1937 ++const_labelno;
1938 namestring = ggc_strdup (name);
1939
1940 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1941 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
1942
1943 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1944 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1945 BIGGEST_ALIGNMENT);
1946 #else
1947 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1948 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1949 #else
1950 {
1951 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1952 so that each uninitialized object starts on such a boundary. */
1953 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1954 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1955 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1956 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1957 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1958 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1959 }
1960 #endif
1961 #endif
1962 return x;
1963 }
1964
1965 /* Assemble the static constant template for function entry trampolines.
1966 This is done at most once per compilation.
1967 Returns an RTX for the address of the template. */
1968
1969 static GTY(()) rtx initial_trampoline;
1970
1971 #ifdef TRAMPOLINE_TEMPLATE
1972 rtx
1973 assemble_trampoline_template (void)
1974 {
1975 char label[256];
1976 const char *name;
1977 int align;
1978 rtx symbol;
1979
1980 if (initial_trampoline)
1981 return initial_trampoline;
1982
1983 /* By default, put trampoline templates in read-only data section. */
1984
1985 #ifdef TRAMPOLINE_SECTION
1986 TRAMPOLINE_SECTION ();
1987 #else
1988 readonly_data_section ();
1989 #endif
1990
1991 /* Write the assembler code to define one. */
1992 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1993 if (align > 0)
1994 {
1995 ASM_OUTPUT_ALIGN (asm_out_file, align);
1996 }
1997
1998 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
1999 TRAMPOLINE_TEMPLATE (asm_out_file);
2000
2001 /* Record the rtl to refer to it. */
2002 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2003 name = ggc_strdup (label);
2004 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2005 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2006
2007 initial_trampoline = gen_rtx_MEM (BLKmode, symbol);
2008 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2009
2010 return initial_trampoline;
2011 }
2012 #endif
2013 \f
2014 /* A and B are either alignments or offsets. Return the minimum alignment
2015 that may be assumed after adding the two together. */
2016
2017 static inline unsigned
2018 min_align (unsigned int a, unsigned int b)
2019 {
2020 return (a | b) & -(a | b);
2021 }
2022
2023 /* Return the assembler directive for creating a given kind of integer
2024 object. SIZE is the number of bytes in the object and ALIGNED_P
2025 indicates whether it is known to be aligned. Return NULL if the
2026 assembly dialect has no such directive.
2027
2028 The returned string should be printed at the start of a new line and
2029 be followed immediately by the object's initial value. */
2030
2031 const char *
2032 integer_asm_op (int size, int aligned_p)
2033 {
2034 struct asm_int_op *ops;
2035
2036 if (aligned_p)
2037 ops = &targetm.asm_out.aligned_op;
2038 else
2039 ops = &targetm.asm_out.unaligned_op;
2040
2041 switch (size)
2042 {
2043 case 1:
2044 return targetm.asm_out.byte_op;
2045 case 2:
2046 return ops->hi;
2047 case 4:
2048 return ops->si;
2049 case 8:
2050 return ops->di;
2051 case 16:
2052 return ops->ti;
2053 default:
2054 return NULL;
2055 }
2056 }
2057
2058 /* Use directive OP to assemble an integer object X. Print OP at the
2059 start of the line, followed immediately by the value of X. */
2060
2061 void
2062 assemble_integer_with_op (const char *op, rtx x)
2063 {
2064 fputs (op, asm_out_file);
2065 output_addr_const (asm_out_file, x);
2066 fputc ('\n', asm_out_file);
2067 }
2068
2069 /* The default implementation of the asm_out.integer target hook. */
2070
2071 bool
2072 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2073 unsigned int size ATTRIBUTE_UNUSED,
2074 int aligned_p ATTRIBUTE_UNUSED)
2075 {
2076 const char *op = integer_asm_op (size, aligned_p);
2077 /* Avoid GAS bugs for large values. Specifically negative values whose
2078 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2079 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2080 return false;
2081 return op && (assemble_integer_with_op (op, x), true);
2082 }
2083
2084 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2085 the alignment of the integer in bits. Return 1 if we were able to output
2086 the constant, otherwise 0. If FORCE is nonzero, abort if we can't output
2087 the constant. */
2088
2089 bool
2090 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2091 {
2092 int aligned_p;
2093
2094 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2095
2096 /* See if the target hook can handle this kind of object. */
2097 if (targetm.asm_out.integer (x, size, aligned_p))
2098 return true;
2099
2100 /* If the object is a multi-byte one, try splitting it up. Split
2101 it into words it if is multi-word, otherwise split it into bytes. */
2102 if (size > 1)
2103 {
2104 enum machine_mode omode, imode;
2105 unsigned int subalign;
2106 unsigned int subsize, i;
2107
2108 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2109 subalign = MIN (align, subsize * BITS_PER_UNIT);
2110 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
2111 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2112
2113 for (i = 0; i < size; i += subsize)
2114 {
2115 rtx partial = simplify_subreg (omode, x, imode, i);
2116 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2117 break;
2118 }
2119 if (i == size)
2120 return true;
2121
2122 /* If we've printed some of it, but not all of it, there's no going
2123 back now. */
2124 gcc_assert (!i);
2125 }
2126
2127 gcc_assert (!force);
2128
2129 return false;
2130 }
2131 \f
2132 void
2133 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2134 {
2135 long data[4];
2136 int i;
2137 int bitsize, nelts, nunits, units_per;
2138
2139 /* This is hairy. We have a quantity of known size. real_to_target
2140 will put it into an array of *host* longs, 32 bits per element
2141 (even if long is more than 32 bits). We need to determine the
2142 number of array elements that are occupied (nelts) and the number
2143 of *target* min-addressable units that will be occupied in the
2144 object file (nunits). We cannot assume that 32 divides the
2145 mode's bitsize (size * BITS_PER_UNIT) evenly.
2146
2147 size * BITS_PER_UNIT is used here to make sure that padding bits
2148 (which might appear at either end of the value; real_to_target
2149 will include the padding bits in its output array) are included. */
2150
2151 nunits = GET_MODE_SIZE (mode);
2152 bitsize = nunits * BITS_PER_UNIT;
2153 nelts = CEIL (bitsize, 32);
2154 units_per = 32 / BITS_PER_UNIT;
2155
2156 real_to_target (data, &d, mode);
2157
2158 /* Put out the first word with the specified alignment. */
2159 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2160 nunits -= units_per;
2161
2162 /* Subsequent words need only 32-bit alignment. */
2163 align = min_align (align, 32);
2164
2165 for (i = 1; i < nelts; i++)
2166 {
2167 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2168 nunits -= units_per;
2169 }
2170 }
2171 \f
2172 /* Given an expression EXP with a constant value,
2173 reduce it to the sum of an assembler symbol and an integer.
2174 Store them both in the structure *VALUE.
2175 Abort if EXP does not reduce. */
2176
2177 struct addr_const GTY(())
2178 {
2179 rtx base;
2180 HOST_WIDE_INT offset;
2181 };
2182
2183 static void
2184 decode_addr_const (tree exp, struct addr_const *value)
2185 {
2186 tree target = TREE_OPERAND (exp, 0);
2187 int offset = 0;
2188 rtx x;
2189
2190 while (1)
2191 {
2192 if (TREE_CODE (target) == COMPONENT_REF
2193 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2194
2195 {
2196 offset += int_byte_position (TREE_OPERAND (target, 1));
2197 target = TREE_OPERAND (target, 0);
2198 }
2199 else if (TREE_CODE (target) == ARRAY_REF
2200 || TREE_CODE (target) == ARRAY_RANGE_REF)
2201 {
2202 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2203 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2204 target = TREE_OPERAND (target, 0);
2205 }
2206 else
2207 break;
2208 }
2209
2210 switch (TREE_CODE (target))
2211 {
2212 case VAR_DECL:
2213 case FUNCTION_DECL:
2214 x = DECL_RTL (target);
2215 break;
2216
2217 case LABEL_DECL:
2218 x = gen_rtx_MEM (FUNCTION_MODE,
2219 gen_rtx_LABEL_REF (VOIDmode, force_label_rtx (target)));
2220 break;
2221
2222 case REAL_CST:
2223 case STRING_CST:
2224 case COMPLEX_CST:
2225 case CONSTRUCTOR:
2226 case INTEGER_CST:
2227 x = output_constant_def (target, 1);
2228 break;
2229
2230 default:
2231 gcc_unreachable ();
2232 }
2233
2234 gcc_assert (MEM_P (x));
2235 x = XEXP (x, 0);
2236
2237 value->base = x;
2238 value->offset = offset;
2239 }
2240 \f
2241 /* Uniquize all constants that appear in memory.
2242 Each constant in memory thus far output is recorded
2243 in `const_desc_table'. */
2244
2245 struct constant_descriptor_tree GTY(())
2246 {
2247 /* A MEM for the constant. */
2248 rtx rtl;
2249
2250 /* The value of the constant. */
2251 tree value;
2252 };
2253
2254 static GTY((param_is (struct constant_descriptor_tree)))
2255 htab_t const_desc_htab;
2256
2257 static struct constant_descriptor_tree * build_constant_desc (tree);
2258 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2259
2260 /* Compute a hash code for a constant expression. */
2261
2262 static hashval_t
2263 const_desc_hash (const void *ptr)
2264 {
2265 return const_hash_1 (((struct constant_descriptor_tree *)ptr)->value);
2266 }
2267
2268 static hashval_t
2269 const_hash_1 (const tree exp)
2270 {
2271 const char *p;
2272 hashval_t hi;
2273 int len, i;
2274 enum tree_code code = TREE_CODE (exp);
2275
2276 /* Either set P and LEN to the address and len of something to hash and
2277 exit the switch or return a value. */
2278
2279 switch (code)
2280 {
2281 case INTEGER_CST:
2282 p = (char *) &TREE_INT_CST (exp);
2283 len = sizeof TREE_INT_CST (exp);
2284 break;
2285
2286 case REAL_CST:
2287 return real_hash (TREE_REAL_CST_PTR (exp));
2288
2289 case STRING_CST:
2290 p = TREE_STRING_POINTER (exp);
2291 len = TREE_STRING_LENGTH (exp);
2292 break;
2293
2294 case COMPLEX_CST:
2295 return (const_hash_1 (TREE_REALPART (exp)) * 5
2296 + const_hash_1 (TREE_IMAGPART (exp)));
2297
2298 case CONSTRUCTOR:
2299 {
2300 tree link;
2301
2302 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2303
2304 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2305 if (TREE_VALUE (link))
2306 hi = hi * 603 + const_hash_1 (TREE_VALUE (link));
2307
2308 return hi;
2309 }
2310
2311 case ADDR_EXPR:
2312 case FDESC_EXPR:
2313 {
2314 struct addr_const value;
2315
2316 decode_addr_const (exp, &value);
2317 switch (GET_CODE (value.base))
2318 {
2319 case SYMBOL_REF:
2320 /* Don't hash the address of the SYMBOL_REF;
2321 only use the offset and the symbol name. */
2322 hi = value.offset;
2323 p = XSTR (value.base, 0);
2324 for (i = 0; p[i] != 0; i++)
2325 hi = ((hi * 613) + (unsigned) (p[i]));
2326 break;
2327
2328 case LABEL_REF:
2329 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2330 break;
2331
2332 default:
2333 gcc_unreachable ();
2334 }
2335 }
2336 return hi;
2337
2338 case PLUS_EXPR:
2339 case MINUS_EXPR:
2340 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2341 + const_hash_1 (TREE_OPERAND (exp, 1)));
2342
2343 case NOP_EXPR:
2344 case CONVERT_EXPR:
2345 case NON_LVALUE_EXPR:
2346 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2347
2348 default:
2349 /* A language specific constant. Just hash the code. */
2350 return code;
2351 }
2352
2353 /* Compute hashing function. */
2354 hi = len;
2355 for (i = 0; i < len; i++)
2356 hi = ((hi * 613) + (unsigned) (p[i]));
2357
2358 return hi;
2359 }
2360
2361 /* Wrapper of compare_constant, for the htab interface. */
2362 static int
2363 const_desc_eq (const void *p1, const void *p2)
2364 {
2365 return compare_constant (((struct constant_descriptor_tree *)p1)->value,
2366 ((struct constant_descriptor_tree *)p2)->value);
2367 }
2368
2369 /* Compare t1 and t2, and return 1 only if they are known to result in
2370 the same bit pattern on output. */
2371
2372 static int
2373 compare_constant (const tree t1, const tree t2)
2374 {
2375 enum tree_code typecode;
2376
2377 if (t1 == NULL_TREE)
2378 return t2 == NULL_TREE;
2379 if (t2 == NULL_TREE)
2380 return 0;
2381
2382 if (TREE_CODE (t1) != TREE_CODE (t2))
2383 return 0;
2384
2385 switch (TREE_CODE (t1))
2386 {
2387 case INTEGER_CST:
2388 /* Integer constants are the same only if the same width of type. */
2389 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2390 return 0;
2391 return tree_int_cst_equal (t1, t2);
2392
2393 case REAL_CST:
2394 /* Real constants are the same only if the same width of type. */
2395 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2396 return 0;
2397
2398 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2399
2400 case STRING_CST:
2401 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2402 return 0;
2403
2404 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2405 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2406 TREE_STRING_LENGTH (t1)));
2407
2408 case COMPLEX_CST:
2409 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2410 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2411
2412 case CONSTRUCTOR:
2413 {
2414 tree l1, l2;
2415
2416 typecode = TREE_CODE (TREE_TYPE (t1));
2417 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2418 return 0;
2419
2420 if (typecode == ARRAY_TYPE)
2421 {
2422 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2423 /* For arrays, check that the sizes all match. */
2424 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2425 || size_1 == -1
2426 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2427 return 0;
2428 }
2429 else
2430 {
2431 /* For record and union constructors, require exact type
2432 equality. */
2433 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2434 return 0;
2435 }
2436
2437 for (l1 = CONSTRUCTOR_ELTS (t1), l2 = CONSTRUCTOR_ELTS (t2);
2438 l1 && l2;
2439 l1 = TREE_CHAIN (l1), l2 = TREE_CHAIN (l2))
2440 {
2441 /* Check that each value is the same... */
2442 if (! compare_constant (TREE_VALUE (l1), TREE_VALUE (l2)))
2443 return 0;
2444 /* ... and that they apply to the same fields! */
2445 if (typecode == ARRAY_TYPE)
2446 {
2447 if (! compare_constant (TREE_PURPOSE (l1),
2448 TREE_PURPOSE (l2)))
2449 return 0;
2450 }
2451 else
2452 {
2453 if (TREE_PURPOSE (l1) != TREE_PURPOSE (l2))
2454 return 0;
2455 }
2456 }
2457
2458 return l1 == NULL_TREE && l2 == NULL_TREE;
2459 }
2460
2461 case ADDR_EXPR:
2462 case FDESC_EXPR:
2463 {
2464 struct addr_const value1, value2;
2465
2466 decode_addr_const (t1, &value1);
2467 decode_addr_const (t2, &value2);
2468 return (value1.offset == value2.offset
2469 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2470 }
2471
2472 case PLUS_EXPR:
2473 case MINUS_EXPR:
2474 case RANGE_EXPR:
2475 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2476 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2477
2478 case NOP_EXPR:
2479 case CONVERT_EXPR:
2480 case NON_LVALUE_EXPR:
2481 case VIEW_CONVERT_EXPR:
2482 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2483
2484 default:
2485 {
2486 tree nt1, nt2;
2487 nt1 = lang_hooks.expand_constant (t1);
2488 nt2 = lang_hooks.expand_constant (t2);
2489 if (nt1 != t1 || nt2 != t2)
2490 return compare_constant (nt1, nt2);
2491 else
2492 return 0;
2493 }
2494 }
2495
2496 gcc_unreachable ();
2497 }
2498 \f
2499 /* Make a copy of the whole tree structure for a constant. This
2500 handles the same types of nodes that compare_constant handles. */
2501
2502 static tree
2503 copy_constant (tree exp)
2504 {
2505 switch (TREE_CODE (exp))
2506 {
2507 case ADDR_EXPR:
2508 /* For ADDR_EXPR, we do not want to copy the decl whose address
2509 is requested. We do want to copy constants though. */
2510 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
2511 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2512 copy_constant (TREE_OPERAND (exp, 0)));
2513 else
2514 return copy_node (exp);
2515
2516 case INTEGER_CST:
2517 case REAL_CST:
2518 case STRING_CST:
2519 return copy_node (exp);
2520
2521 case COMPLEX_CST:
2522 return build_complex (TREE_TYPE (exp),
2523 copy_constant (TREE_REALPART (exp)),
2524 copy_constant (TREE_IMAGPART (exp)));
2525
2526 case PLUS_EXPR:
2527 case MINUS_EXPR:
2528 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
2529 copy_constant (TREE_OPERAND (exp, 0)),
2530 copy_constant (TREE_OPERAND (exp, 1)));
2531
2532 case NOP_EXPR:
2533 case CONVERT_EXPR:
2534 case NON_LVALUE_EXPR:
2535 case VIEW_CONVERT_EXPR:
2536 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2537 copy_constant (TREE_OPERAND (exp, 0)));
2538
2539 case CONSTRUCTOR:
2540 {
2541 tree copy = copy_node (exp);
2542 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2543 tree tail;
2544
2545 CONSTRUCTOR_ELTS (copy) = list;
2546 for (tail = list; tail; tail = TREE_CHAIN (tail))
2547 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2548
2549 return copy;
2550 }
2551
2552 default:
2553 {
2554 tree t = lang_hooks.expand_constant (exp);
2555
2556 gcc_assert (t == exp);
2557 return copy_constant (t);
2558 }
2559 }
2560 }
2561 \f
2562 /* Subroutine of output_constant_def:
2563 No constant equal to EXP is known to have been output.
2564 Make a constant descriptor to enter EXP in the hash table.
2565 Assign the label number and construct RTL to refer to the
2566 constant's location in memory.
2567 Caller is responsible for updating the hash table. */
2568
2569 static struct constant_descriptor_tree *
2570 build_constant_desc (tree exp)
2571 {
2572 rtx symbol;
2573 rtx rtl;
2574 char label[256];
2575 int labelno;
2576 struct constant_descriptor_tree *desc;
2577
2578 desc = ggc_alloc (sizeof (*desc));
2579 desc->value = copy_constant (exp);
2580
2581 /* Propagate marked-ness to copied constant. */
2582 if (flag_mudflap && mf_marked_p (exp))
2583 mf_mark (desc->value);
2584
2585 /* Create a string containing the label name, in LABEL. */
2586 labelno = const_labelno++;
2587 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2588
2589 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2590 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2591 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2592 SYMBOL_REF_DECL (symbol) = desc->value;
2593 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2594
2595 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2596 set_mem_attributes (rtl, exp, 1);
2597 set_mem_alias_set (rtl, 0);
2598 set_mem_alias_set (rtl, const_alias_set);
2599
2600 /* Set flags or add text to the name to record information, such as
2601 that it is a local symbol. If the name is changed, the macro
2602 ASM_OUTPUT_LABELREF will have to know how to strip this
2603 information. This call might invalidate our local variable
2604 SYMBOL; we can't use it afterward. */
2605
2606 targetm.encode_section_info (exp, rtl, true);
2607
2608 desc->rtl = rtl;
2609
2610 return desc;
2611 }
2612
2613 /* Return an rtx representing a reference to constant data in memory
2614 for the constant expression EXP.
2615
2616 If assembler code for such a constant has already been output,
2617 return an rtx to refer to it.
2618 Otherwise, output such a constant in memory
2619 and generate an rtx for it.
2620
2621 If DEFER is nonzero, this constant can be deferred and output only
2622 if referenced in the function after all optimizations.
2623
2624 `const_desc_table' records which constants already have label strings. */
2625
2626 rtx
2627 output_constant_def (tree exp, int defer)
2628 {
2629 struct constant_descriptor_tree *desc;
2630 struct constant_descriptor_tree key;
2631 void **loc;
2632
2633 /* Look up EXP in the table of constant descriptors. If we didn't find
2634 it, create a new one. */
2635 key.value = exp;
2636 loc = htab_find_slot (const_desc_htab, &key, INSERT);
2637
2638 desc = *loc;
2639 if (desc == 0)
2640 {
2641 desc = build_constant_desc (exp);
2642 *loc = desc;
2643 }
2644
2645 maybe_output_constant_def_contents (desc, defer);
2646 return desc->rtl;
2647 }
2648
2649 /* Subroutine of output_constant_def: Decide whether or not we need to
2650 output the constant DESC now, and if so, do it. */
2651 static void
2652 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
2653 int defer)
2654 {
2655 rtx symbol = XEXP (desc->rtl, 0);
2656 tree exp = desc->value;
2657
2658 if (flag_syntax_only)
2659 return;
2660
2661 if (TREE_ASM_WRITTEN (exp))
2662 /* Already output; don't do it again. */
2663 return;
2664
2665 /* We can always defer constants as long as the context allows
2666 doing so. */
2667 if (defer)
2668 {
2669 /* Increment n_deferred_constants if it exists. It needs to be at
2670 least as large as the number of constants actually referred to
2671 by the function. If it's too small we'll stop looking too early
2672 and fail to emit constants; if it's too large we'll only look
2673 through the entire function when we could have stopped earlier. */
2674 if (cfun)
2675 n_deferred_constants++;
2676 return;
2677 }
2678
2679 output_constant_def_contents (symbol);
2680 }
2681
2682 /* We must output the constant data referred to by SYMBOL; do so. */
2683
2684 static void
2685 output_constant_def_contents (rtx symbol)
2686 {
2687 tree exp = SYMBOL_REF_DECL (symbol);
2688 const char *label = XSTR (symbol, 0);
2689 HOST_WIDE_INT size;
2690
2691 /* Make sure any other constants whose addresses appear in EXP
2692 are assigned label numbers. */
2693 int reloc = compute_reloc_for_constant (exp);
2694
2695 /* Align the location counter as required by EXP's data type. */
2696 unsigned int align = TYPE_ALIGN (TREE_TYPE (exp));
2697 #ifdef CONSTANT_ALIGNMENT
2698 align = CONSTANT_ALIGNMENT (exp, align);
2699 #endif
2700
2701 output_addressed_constants (exp);
2702
2703 /* We are no longer deferring this constant. */
2704 TREE_ASM_WRITTEN (exp) = 1;
2705
2706 if (IN_NAMED_SECTION (exp))
2707 named_section (exp, NULL, reloc);
2708 else
2709 targetm.asm_out.select_section (exp, reloc, align);
2710
2711 if (align > BITS_PER_UNIT)
2712 {
2713 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2714 }
2715
2716 size = int_size_in_bytes (TREE_TYPE (exp));
2717 if (TREE_CODE (exp) == STRING_CST)
2718 size = MAX (TREE_STRING_LENGTH (exp), size);
2719
2720 /* Do any machine/system dependent processing of the constant. */
2721 #ifdef ASM_DECLARE_CONSTANT_NAME
2722 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
2723 #else
2724 /* Standard thing is just output label for the constant. */
2725 ASM_OUTPUT_LABEL (asm_out_file, label);
2726 #endif /* ASM_DECLARE_CONSTANT_NAME */
2727
2728 /* Output the value of EXP. */
2729 output_constant (exp, size, align);
2730 if (flag_mudflap)
2731 mudflap_enqueue_constant (exp);
2732 }
2733
2734 /* Look up EXP in the table of constant descriptors. Return the rtl
2735 if it has been emitted, else null. */
2736
2737 rtx
2738 lookup_constant_def (tree exp)
2739 {
2740 struct constant_descriptor_tree *desc;
2741 struct constant_descriptor_tree key;
2742
2743 key.value = exp;
2744 desc = htab_find (const_desc_htab, &key);
2745
2746 return (desc ? desc->rtl : NULL_RTX);
2747 }
2748 \f
2749 /* Used in the hash tables to avoid outputting the same constant
2750 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2751 are output once per function, not once per file. */
2752 /* ??? Only a few targets need per-function constant pools. Most
2753 can use one per-file pool. Should add a targetm bit to tell the
2754 difference. */
2755
2756 struct rtx_constant_pool GTY(())
2757 {
2758 /* Pointers to first and last constant in pool, as ordered by offset. */
2759 struct constant_descriptor_rtx *first;
2760 struct constant_descriptor_rtx *last;
2761
2762 /* Hash facility for making memory-constants from constant rtl-expressions.
2763 It is used on RISC machines where immediate integer arguments and
2764 constant addresses are restricted so that such constants must be stored
2765 in memory. */
2766 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
2767 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_sym_htab;
2768
2769 /* Current offset in constant pool (does not include any
2770 machine-specific header). */
2771 HOST_WIDE_INT offset;
2772 };
2773
2774 struct constant_descriptor_rtx GTY((chain_next ("%h.next")))
2775 {
2776 struct constant_descriptor_rtx *next;
2777 rtx mem;
2778 rtx sym;
2779 rtx constant;
2780 HOST_WIDE_INT offset;
2781 hashval_t hash;
2782 enum machine_mode mode;
2783 unsigned int align;
2784 int labelno;
2785 int mark;
2786 };
2787
2788 /* Hash and compare functions for const_rtx_htab. */
2789
2790 static hashval_t
2791 const_desc_rtx_hash (const void *ptr)
2792 {
2793 const struct constant_descriptor_rtx *desc = ptr;
2794 return desc->hash;
2795 }
2796
2797 static int
2798 const_desc_rtx_eq (const void *a, const void *b)
2799 {
2800 const struct constant_descriptor_rtx *x = a;
2801 const struct constant_descriptor_rtx *y = b;
2802
2803 if (x->mode != y->mode)
2804 return 0;
2805 return rtx_equal_p (x->constant, y->constant);
2806 }
2807
2808 /* Hash and compare functions for const_rtx_sym_htab. */
2809
2810 static hashval_t
2811 const_desc_rtx_sym_hash (const void *ptr)
2812 {
2813 const struct constant_descriptor_rtx *desc = ptr;
2814 return htab_hash_string (XSTR (desc->sym, 0));
2815 }
2816
2817 static int
2818 const_desc_rtx_sym_eq (const void *a, const void *b)
2819 {
2820 const struct constant_descriptor_rtx *x = a;
2821 const struct constant_descriptor_rtx *y = b;
2822 return XSTR (x->sym, 0) == XSTR (y->sym, 0);
2823 }
2824
2825 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
2826
2827 static int
2828 const_rtx_hash_1 (rtx *xp, void *data)
2829 {
2830 unsigned HOST_WIDE_INT hwi;
2831 enum machine_mode mode;
2832 enum rtx_code code;
2833 hashval_t h, *hp;
2834 rtx x;
2835
2836 x = *xp;
2837 code = GET_CODE (x);
2838 mode = GET_MODE (x);
2839 h = (hashval_t) code * 1048573 + mode;
2840
2841 switch (code)
2842 {
2843 case CONST_INT:
2844 hwi = INTVAL (x);
2845 fold_hwi:
2846 {
2847 const int shift = sizeof (hashval_t) * CHAR_BIT;
2848 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
2849 int i;
2850
2851 h ^= (hashval_t) hwi;
2852 for (i = 1; i < n; ++i)
2853 {
2854 hwi >>= shift;
2855 h ^= (hashval_t) hwi;
2856 }
2857 }
2858 break;
2859
2860 case CONST_DOUBLE:
2861 if (mode == VOIDmode)
2862 {
2863 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
2864 goto fold_hwi;
2865 }
2866 else
2867 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
2868 break;
2869
2870 case CONST_VECTOR:
2871 {
2872 int i;
2873 for (i = XVECLEN (x, 0); i-- > 0; )
2874 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
2875 }
2876 break;
2877
2878 case SYMBOL_REF:
2879 h ^= htab_hash_string (XSTR (x, 0));
2880 break;
2881
2882 case LABEL_REF:
2883 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
2884 break;
2885
2886 case UNSPEC:
2887 case UNSPEC_VOLATILE:
2888 h = h * 251 + XINT (x, 1);
2889 break;
2890
2891 default:
2892 break;
2893 }
2894
2895 hp = data;
2896 *hp = *hp * 509 + h;
2897 return 0;
2898 }
2899
2900 /* Compute a hash value for X, which should be a constant. */
2901
2902 static hashval_t
2903 const_rtx_hash (rtx x)
2904 {
2905 hashval_t h = 0;
2906 for_each_rtx (&x, const_rtx_hash_1, &h);
2907 return h;
2908 }
2909
2910 \f
2911 /* Initialize constant pool hashing for a new function. */
2912
2913 void
2914 init_varasm_status (struct function *f)
2915 {
2916 struct varasm_status *p;
2917 struct rtx_constant_pool *pool;
2918
2919 p = ggc_alloc (sizeof (struct varasm_status));
2920 f->varasm = p;
2921
2922 pool = ggc_alloc (sizeof (struct rtx_constant_pool));
2923 p->pool = pool;
2924 p->deferred_constants = 0;
2925
2926 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
2927 const_desc_rtx_eq, NULL);
2928 pool->const_rtx_sym_htab = htab_create_ggc (31, const_desc_rtx_sym_hash,
2929 const_desc_rtx_sym_eq, NULL);
2930 pool->first = pool->last = NULL;
2931 pool->offset = 0;
2932 }
2933 \f
2934 /* Given a MINUS expression, simplify it if both sides
2935 include the same symbol. */
2936
2937 rtx
2938 simplify_subtraction (rtx x)
2939 {
2940 rtx r = simplify_rtx (x);
2941 return r ? r : x;
2942 }
2943 \f
2944 /* Given a constant rtx X, make (or find) a memory constant for its value
2945 and return a MEM rtx to refer to it in memory. */
2946
2947 rtx
2948 force_const_mem (enum machine_mode mode, rtx x)
2949 {
2950 struct constant_descriptor_rtx *desc, tmp;
2951 struct rtx_constant_pool *pool = cfun->varasm->pool;
2952 char label[256];
2953 rtx def, symbol;
2954 hashval_t hash;
2955 unsigned int align;
2956 void **slot;
2957
2958 /* If we're not allowed to drop X into the constant pool, don't. */
2959 if (targetm.cannot_force_const_mem (x))
2960 return NULL_RTX;
2961
2962 /* Lookup the value in the hashtable. */
2963 tmp.constant = x;
2964 tmp.mode = mode;
2965 hash = const_rtx_hash (x);
2966 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
2967 desc = *slot;
2968
2969 /* If the constant was already present, return its memory. */
2970 if (desc)
2971 return copy_rtx (desc->mem);
2972
2973 /* Otherwise, create a new descriptor. */
2974 desc = ggc_alloc (sizeof (*desc));
2975 *slot = desc;
2976
2977 /* Align the location counter as required by EXP's data type. */
2978 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
2979 #ifdef CONSTANT_ALIGNMENT
2980 {
2981 tree type = lang_hooks.types.type_for_mode (mode, 0);
2982 if (type != NULL_TREE)
2983 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
2984 }
2985 #endif
2986
2987 pool->offset += (align / BITS_PER_UNIT) - 1;
2988 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
2989
2990 desc->next = NULL;
2991 desc->constant = tmp.constant;
2992 desc->offset = pool->offset;
2993 desc->hash = hash;
2994 desc->mode = mode;
2995 desc->align = align;
2996 desc->labelno = const_labelno;
2997 desc->mark = 0;
2998
2999 pool->offset += GET_MODE_SIZE (mode);
3000 if (pool->last)
3001 pool->last->next = desc;
3002 else
3003 pool->first = pool->last = desc;
3004 pool->last = desc;
3005
3006 /* Create a string containing the label name, in LABEL. */
3007 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3008 ++const_labelno;
3009
3010 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3011 the constants pool. */
3012 desc->sym = symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3013 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
3014 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3015 current_function_uses_const_pool = 1;
3016
3017 /* Insert the descriptor into the symbol cross-reference table too. */
3018 slot = htab_find_slot (pool->const_rtx_sym_htab, desc, INSERT);
3019 gcc_assert (!*slot);
3020 *slot = desc;
3021
3022 /* Construct the MEM. */
3023 desc->mem = def = gen_const_mem (mode, symbol);
3024 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3025 set_mem_align (def, align);
3026
3027 /* If we're dropping a label to the constant pool, make sure we
3028 don't delete it. */
3029 if (GET_CODE (x) == LABEL_REF)
3030 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3031
3032 return copy_rtx (def);
3033 }
3034 \f
3035 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3036 the corresponding constant_descriptor_rtx structure. */
3037
3038 static struct constant_descriptor_rtx *
3039 find_pool_constant (struct rtx_constant_pool *pool, rtx sym)
3040 {
3041 struct constant_descriptor_rtx tmp;
3042 tmp.sym = sym;
3043 return htab_find (pool->const_rtx_sym_htab, &tmp);
3044 }
3045
3046 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3047
3048 rtx
3049 get_pool_constant (rtx addr)
3050 {
3051 return find_pool_constant (cfun->varasm->pool, addr)->constant;
3052 }
3053
3054 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3055 and whether it has been output or not. */
3056
3057 rtx
3058 get_pool_constant_mark (rtx addr, bool *pmarked)
3059 {
3060 struct constant_descriptor_rtx *desc;
3061
3062 desc = find_pool_constant (cfun->varasm->pool, addr);
3063 *pmarked = (desc->mark != 0);
3064 return desc->constant;
3065 }
3066
3067 /* Likewise, but for the constant pool of a specific function. */
3068
3069 rtx
3070 get_pool_constant_for_function (struct function *f, rtx addr)
3071 {
3072 return find_pool_constant (f->varasm->pool, addr)->constant;
3073 }
3074
3075 /* Similar, return the mode. */
3076
3077 enum machine_mode
3078 get_pool_mode (rtx addr)
3079 {
3080 return find_pool_constant (cfun->varasm->pool, addr)->mode;
3081 }
3082
3083 /* Return the size of the constant pool. */
3084
3085 int
3086 get_pool_size (void)
3087 {
3088 return cfun->varasm->pool->offset;
3089 }
3090 \f
3091 /* Worker function for output_constant_pool_1. Emit assembly for X
3092 in MODE with known alignment ALIGN. */
3093
3094 static void
3095 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3096 {
3097 switch (GET_MODE_CLASS (mode))
3098 {
3099 case MODE_FLOAT:
3100 {
3101 REAL_VALUE_TYPE r;
3102
3103 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3104 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3105 assemble_real (r, mode, align);
3106 break;
3107 }
3108
3109 case MODE_INT:
3110 case MODE_PARTIAL_INT:
3111 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3112 break;
3113
3114 case MODE_VECTOR_FLOAT:
3115 case MODE_VECTOR_INT:
3116 {
3117 int i, units;
3118 enum machine_mode submode = GET_MODE_INNER (mode);
3119 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3120
3121 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3122 units = CONST_VECTOR_NUNITS (x);
3123
3124 for (i = 0; i < units; i++)
3125 {
3126 rtx elt = CONST_VECTOR_ELT (x, i);
3127 output_constant_pool_2 (submode, elt, i ? subalign : align);
3128 }
3129 }
3130 break;
3131
3132 default:
3133 gcc_unreachable ();
3134 }
3135 }
3136
3137 /* Worker function for output_constant_pool. Emit POOL. */
3138
3139 static void
3140 output_constant_pool_1 (struct constant_descriptor_rtx *desc)
3141 {
3142 rtx x, tmp;
3143
3144 if (!desc->mark)
3145 return;
3146 x = desc->constant;
3147
3148 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3149 whose CODE_LABEL has been deleted. This can occur if a jump table
3150 is eliminated by optimization. If so, write a constant of zero
3151 instead. Note that this can also happen by turning the
3152 CODE_LABEL into a NOTE. */
3153 /* ??? This seems completely and utterly wrong. Certainly it's
3154 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3155 functioning even with INSN_DELETED_P and friends. */
3156
3157 tmp = x;
3158 switch (GET_CODE (x))
3159 {
3160 case CONST:
3161 if (GET_CODE (XEXP (x, 0)) != PLUS
3162 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3163 break;
3164 tmp = XEXP (XEXP (x, 0), 0);
3165 /* FALLTHRU */
3166
3167 case LABEL_REF:
3168 tmp = XEXP (x, 0);
3169 gcc_assert (!INSN_DELETED_P (tmp));
3170 gcc_assert (!NOTE_P (tmp)
3171 || NOTE_LINE_NUMBER (tmp) != NOTE_INSN_DELETED);
3172 break;
3173
3174 default:
3175 break;
3176 }
3177
3178 /* First switch to correct section. */
3179 targetm.asm_out.select_rtx_section (desc->mode, x, desc->align);
3180
3181 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3182 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3183 desc->align, desc->labelno, done);
3184 #endif
3185
3186 assemble_align (desc->align);
3187
3188 /* Output the label. */
3189 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3190
3191 /* Output the data. */
3192 output_constant_pool_2 (desc->mode, x, desc->align);
3193
3194 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3195 sections have proper size. */
3196 if (desc->align > GET_MODE_BITSIZE (desc->mode)
3197 && in_section == in_named
3198 && get_named_section_flags (in_named_name) & SECTION_MERGE)
3199 assemble_align (desc->align);
3200
3201 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3202 done:
3203 #endif
3204 return;
3205 }
3206
3207 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3208 to as used. Emit referenced deferred strings. This function can
3209 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3210
3211 static int
3212 mark_constant (rtx *current_rtx, void *data)
3213 {
3214 struct rtx_constant_pool *pool = data;
3215 rtx x = *current_rtx;
3216
3217 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3218 return 0;
3219
3220 if (CONSTANT_POOL_ADDRESS_P (x))
3221 {
3222 struct constant_descriptor_rtx *desc = find_pool_constant (pool, x);
3223 if (desc->mark == 0)
3224 {
3225 desc->mark = 1;
3226 for_each_rtx (&desc->constant, mark_constant, pool);
3227 }
3228 }
3229 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3230 {
3231 tree exp = SYMBOL_REF_DECL (x);
3232 if (!TREE_ASM_WRITTEN (exp))
3233 {
3234 n_deferred_constants--;
3235 output_constant_def_contents (x);
3236 }
3237 }
3238
3239 return -1;
3240 }
3241
3242 /* Look through appropriate parts of INSN, marking all entries in the
3243 constant pool which are actually being used. Entries that are only
3244 referenced by other constants are also marked as used. Emit
3245 deferred strings that are used. */
3246
3247 static void
3248 mark_constants (struct rtx_constant_pool *pool, rtx insn)
3249 {
3250 if (!INSN_P (insn))
3251 return;
3252
3253 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3254 insns, not any notes that may be attached. We don't want to mark
3255 a constant just because it happens to appear in a REG_EQUIV note. */
3256 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3257 {
3258 rtx seq = PATTERN (insn);
3259 int i, n = XVECLEN (seq, 0);
3260 for (i = 0; i < n; ++i)
3261 {
3262 rtx subinsn = XVECEXP (seq, 0, i);
3263 if (INSN_P (subinsn))
3264 for_each_rtx (&PATTERN (subinsn), mark_constant, pool);
3265 }
3266 }
3267 else
3268 for_each_rtx (&PATTERN (insn), mark_constant, pool);
3269 }
3270
3271 /* Look through the instructions for this function, and mark all the
3272 entries in POOL which are actually being used. Emit deferred constants
3273 which have indeed been used. */
3274
3275 static void
3276 mark_constant_pool (struct rtx_constant_pool *pool)
3277 {
3278 rtx insn, link;
3279
3280 if (pool->first == 0 && n_deferred_constants == 0)
3281 return;
3282
3283 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3284 mark_constants (pool, insn);
3285
3286 for (link = current_function_epilogue_delay_list;
3287 link;
3288 link = XEXP (link, 1))
3289 mark_constants (pool, XEXP (link, 0));
3290 }
3291
3292 /* Write all the constants in the constant pool. */
3293
3294 void
3295 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3296 tree fndecl ATTRIBUTE_UNUSED)
3297 {
3298 struct rtx_constant_pool *pool = cfun->varasm->pool;
3299 struct constant_descriptor_rtx *desc;
3300
3301 /* It is possible for gcc to call force_const_mem and then to later
3302 discard the instructions which refer to the constant. In such a
3303 case we do not need to output the constant. */
3304 mark_constant_pool (pool);
3305
3306 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3307 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3308 #endif
3309
3310 for (desc = pool->first; desc ; desc = desc->next)
3311 output_constant_pool_1 (desc);
3312
3313 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3314 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3315 #endif
3316 }
3317 \f
3318 /* Determine what kind of relocations EXP may need. */
3319
3320 int
3321 compute_reloc_for_constant (tree exp)
3322 {
3323 int reloc = 0, reloc2;
3324 tree tem;
3325
3326 /* Give the front-end a chance to convert VALUE to something that
3327 looks more like a constant to the back-end. */
3328 exp = lang_hooks.expand_constant (exp);
3329
3330 switch (TREE_CODE (exp))
3331 {
3332 case ADDR_EXPR:
3333 case FDESC_EXPR:
3334 /* Go inside any operations that get_inner_reference can handle and see
3335 if what's inside is a constant: no need to do anything here for
3336 addresses of variables or functions. */
3337 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3338 tem = TREE_OPERAND (tem, 0))
3339 ;
3340
3341 if (TREE_PUBLIC (tem))
3342 reloc |= 2;
3343 else
3344 reloc |= 1;
3345 break;
3346
3347 case PLUS_EXPR:
3348 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3349 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3350 break;
3351
3352 case MINUS_EXPR:
3353 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3354 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3355 /* The difference of two local labels is computable at link time. */
3356 if (reloc == 1 && reloc2 == 1)
3357 reloc = 0;
3358 else
3359 reloc |= reloc2;
3360 break;
3361
3362 case NOP_EXPR:
3363 case CONVERT_EXPR:
3364 case NON_LVALUE_EXPR:
3365 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3366 break;
3367
3368 case CONSTRUCTOR:
3369 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3370 if (TREE_VALUE (tem) != 0)
3371 reloc |= compute_reloc_for_constant (TREE_VALUE (tem));
3372
3373 break;
3374
3375 default:
3376 break;
3377 }
3378 return reloc;
3379 }
3380
3381 /* Find all the constants whose addresses are referenced inside of EXP,
3382 and make sure assembler code with a label has been output for each one.
3383 Indicate whether an ADDR_EXPR has been encountered. */
3384
3385 static void
3386 output_addressed_constants (tree exp)
3387 {
3388 tree tem;
3389
3390 /* Give the front-end a chance to convert VALUE to something that
3391 looks more like a constant to the back-end. */
3392 exp = lang_hooks.expand_constant (exp);
3393
3394 switch (TREE_CODE (exp))
3395 {
3396 case ADDR_EXPR:
3397 case FDESC_EXPR:
3398 /* Go inside any operations that get_inner_reference can handle and see
3399 if what's inside is a constant: no need to do anything here for
3400 addresses of variables or functions. */
3401 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3402 tem = TREE_OPERAND (tem, 0))
3403 ;
3404
3405 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3406 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
3407 tem = DECL_INITIAL (tem);
3408
3409 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
3410 output_constant_def (tem, 0);
3411 break;
3412
3413 case PLUS_EXPR:
3414 case MINUS_EXPR:
3415 output_addressed_constants (TREE_OPERAND (exp, 1));
3416 /* Fall through. */
3417
3418 case NOP_EXPR:
3419 case CONVERT_EXPR:
3420 case NON_LVALUE_EXPR:
3421 output_addressed_constants (TREE_OPERAND (exp, 0));
3422 break;
3423
3424 case CONSTRUCTOR:
3425 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3426 if (TREE_VALUE (tem) != 0)
3427 output_addressed_constants (TREE_VALUE (tem));
3428
3429 break;
3430
3431 default:
3432 break;
3433 }
3434 }
3435 \f
3436 /* Return nonzero if VALUE is a valid constant-valued expression
3437 for use in initializing a static variable; one that can be an
3438 element of a "constant" initializer.
3439
3440 Return null_pointer_node if the value is absolute;
3441 if it is relocatable, return the variable that determines the relocation.
3442 We assume that VALUE has been folded as much as possible;
3443 therefore, we do not need to check for such things as
3444 arithmetic-combinations of integers. */
3445
3446 tree
3447 initializer_constant_valid_p (tree value, tree endtype)
3448 {
3449 /* Give the front-end a chance to convert VALUE to something that
3450 looks more like a constant to the back-end. */
3451 value = lang_hooks.expand_constant (value);
3452
3453 switch (TREE_CODE (value))
3454 {
3455 case CONSTRUCTOR:
3456 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
3457 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
3458 && TREE_CONSTANT (value)
3459 && CONSTRUCTOR_ELTS (value))
3460 {
3461 tree elt;
3462 bool absolute = true;
3463
3464 for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt))
3465 {
3466 tree reloc;
3467 value = TREE_VALUE (elt);
3468 reloc = initializer_constant_valid_p (value, TREE_TYPE (value));
3469 if (!reloc)
3470 return NULL_TREE;
3471 if (reloc != null_pointer_node)
3472 absolute = false;
3473 }
3474 /* For a non-absolute relocation, there is no single
3475 variable that can be "the variable that determines the
3476 relocation." */
3477 return absolute ? null_pointer_node : error_mark_node;
3478 }
3479
3480 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
3481
3482 case INTEGER_CST:
3483 case VECTOR_CST:
3484 case REAL_CST:
3485 case STRING_CST:
3486 case COMPLEX_CST:
3487 return null_pointer_node;
3488
3489 case ADDR_EXPR:
3490 case FDESC_EXPR:
3491 value = staticp (TREE_OPERAND (value, 0));
3492 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to
3493 be a constant, this is old-skool offsetof-like nonsense. */
3494 if (value
3495 && TREE_CODE (value) == INDIRECT_REF
3496 && TREE_CONSTANT (TREE_OPERAND (value, 0)))
3497 return null_pointer_node;
3498 /* Taking the address of a nested function involves a trampoline. */
3499 if (value
3500 && TREE_CODE (value) == FUNCTION_DECL
3501 && ((decl_function_context (value) && !DECL_NO_STATIC_CHAIN (value))
3502 || DECL_NON_ADDR_CONST_P (value)))
3503 return NULL_TREE;
3504 return value;
3505
3506 case VIEW_CONVERT_EXPR:
3507 case NON_LVALUE_EXPR:
3508 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3509
3510 case CONVERT_EXPR:
3511 case NOP_EXPR:
3512 {
3513 tree src;
3514 tree src_type;
3515 tree dest_type;
3516
3517 src = TREE_OPERAND (value, 0);
3518 src_type = TREE_TYPE (src);
3519 dest_type = TREE_TYPE (value);
3520
3521 /* Allow conversions between pointer types, floating-point
3522 types, and offset types. */
3523 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
3524 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
3525 || (TREE_CODE (dest_type) == OFFSET_TYPE
3526 && TREE_CODE (src_type) == OFFSET_TYPE))
3527 return initializer_constant_valid_p (src, endtype);
3528
3529 /* Allow length-preserving conversions between integer types. */
3530 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
3531 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
3532 return initializer_constant_valid_p (src, endtype);
3533
3534 /* Allow conversions between other integer types only if
3535 explicit value. */
3536 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
3537 {
3538 tree inner = initializer_constant_valid_p (src, endtype);
3539 if (inner == null_pointer_node)
3540 return null_pointer_node;
3541 break;
3542 }
3543
3544 /* Allow (int) &foo provided int is as wide as a pointer. */
3545 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
3546 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
3547 return initializer_constant_valid_p (src, endtype);
3548
3549 /* Likewise conversions from int to pointers, but also allow
3550 conversions from 0. */
3551 if ((POINTER_TYPE_P (dest_type)
3552 || TREE_CODE (dest_type) == OFFSET_TYPE)
3553 && INTEGRAL_TYPE_P (src_type))
3554 {
3555 if (integer_zerop (src))
3556 return null_pointer_node;
3557 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
3558 return initializer_constant_valid_p (src, endtype);
3559 }
3560
3561 /* Allow conversions to struct or union types if the value
3562 inside is okay. */
3563 if (TREE_CODE (dest_type) == RECORD_TYPE
3564 || TREE_CODE (dest_type) == UNION_TYPE)
3565 return initializer_constant_valid_p (src, endtype);
3566 }
3567 break;
3568
3569 case PLUS_EXPR:
3570 if (! INTEGRAL_TYPE_P (endtype)
3571 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3572 {
3573 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3574 endtype);
3575 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3576 endtype);
3577 /* If either term is absolute, use the other terms relocation. */
3578 if (valid0 == null_pointer_node)
3579 return valid1;
3580 if (valid1 == null_pointer_node)
3581 return valid0;
3582 }
3583 break;
3584
3585 case MINUS_EXPR:
3586 if (! INTEGRAL_TYPE_P (endtype)
3587 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3588 {
3589 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3590 endtype);
3591 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3592 endtype);
3593 /* Win if second argument is absolute. */
3594 if (valid1 == null_pointer_node)
3595 return valid0;
3596 /* Win if both arguments have the same relocation.
3597 Then the value is absolute. */
3598 if (valid0 == valid1 && valid0 != 0)
3599 return null_pointer_node;
3600
3601 /* Since GCC guarantees that string constants are unique in the
3602 generated code, a subtraction between two copies of the same
3603 constant string is absolute. */
3604 if (valid0 && TREE_CODE (valid0) == STRING_CST
3605 && valid1 && TREE_CODE (valid1) == STRING_CST
3606 && operand_equal_p (valid0, valid1, 1))
3607 return null_pointer_node;
3608 }
3609
3610 /* Support narrowing differences. */
3611 if (INTEGRAL_TYPE_P (endtype))
3612 {
3613 tree op0, op1;
3614
3615 op0 = TREE_OPERAND (value, 0);
3616 op1 = TREE_OPERAND (value, 1);
3617
3618 /* Like STRIP_NOPS except allow the operand mode to widen.
3619 This works around a feature of fold that simplifies
3620 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3621 that the narrower operation is cheaper. */
3622
3623 while (TREE_CODE (op0) == NOP_EXPR
3624 || TREE_CODE (op0) == CONVERT_EXPR
3625 || TREE_CODE (op0) == NON_LVALUE_EXPR)
3626 {
3627 tree inner = TREE_OPERAND (op0, 0);
3628 if (inner == error_mark_node
3629 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3630 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3631 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3632 break;
3633 op0 = inner;
3634 }
3635
3636 while (TREE_CODE (op1) == NOP_EXPR
3637 || TREE_CODE (op1) == CONVERT_EXPR
3638 || TREE_CODE (op1) == NON_LVALUE_EXPR)
3639 {
3640 tree inner = TREE_OPERAND (op1, 0);
3641 if (inner == error_mark_node
3642 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3643 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3644 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3645 break;
3646 op1 = inner;
3647 }
3648
3649 op0 = initializer_constant_valid_p (op0, endtype);
3650 op1 = initializer_constant_valid_p (op1, endtype);
3651
3652 /* Both initializers must be known. */
3653 if (op0 && op1)
3654 {
3655 if (op0 == op1)
3656 return null_pointer_node;
3657
3658 /* Support differences between labels. */
3659 if (TREE_CODE (op0) == LABEL_DECL
3660 && TREE_CODE (op1) == LABEL_DECL)
3661 return null_pointer_node;
3662
3663 if (TREE_CODE (op0) == STRING_CST
3664 && TREE_CODE (op1) == STRING_CST
3665 && operand_equal_p (op0, op1, 1))
3666 return null_pointer_node;
3667 }
3668 }
3669 break;
3670
3671 default:
3672 break;
3673 }
3674
3675 return 0;
3676 }
3677 \f
3678 /* Output assembler code for constant EXP to FILE, with no label.
3679 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3680 Assumes output_addressed_constants has been done on EXP already.
3681
3682 Generate exactly SIZE bytes of assembler data, padding at the end
3683 with zeros if necessary. SIZE must always be specified.
3684
3685 SIZE is important for structure constructors,
3686 since trailing members may have been omitted from the constructor.
3687 It is also important for initialization of arrays from string constants
3688 since the full length of the string constant might not be wanted.
3689 It is also needed for initialization of unions, where the initializer's
3690 type is just one member, and that may not be as long as the union.
3691
3692 There a case in which we would fail to output exactly SIZE bytes:
3693 for a structure constructor that wants to produce more than SIZE bytes.
3694 But such constructors will never be generated for any possible input.
3695
3696 ALIGN is the alignment of the data in bits. */
3697
3698 void
3699 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
3700 {
3701 enum tree_code code;
3702 unsigned HOST_WIDE_INT thissize;
3703
3704 /* Some front-ends use constants other than the standard language-independent
3705 varieties, but which may still be output directly. Give the front-end a
3706 chance to convert EXP to a language-independent representation. */
3707 exp = lang_hooks.expand_constant (exp);
3708
3709 if (size == 0 || flag_syntax_only)
3710 return;
3711
3712 /* Eliminate any conversions since we'll be outputting the underlying
3713 constant. */
3714 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3715 || TREE_CODE (exp) == NON_LVALUE_EXPR
3716 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
3717 exp = TREE_OPERAND (exp, 0);
3718
3719 code = TREE_CODE (TREE_TYPE (exp));
3720 thissize = int_size_in_bytes (TREE_TYPE (exp));
3721
3722 /* Allow a constructor with no elements for any data type.
3723 This means to fill the space with zeros. */
3724 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3725 {
3726 assemble_zeros (size);
3727 return;
3728 }
3729
3730 if (TREE_CODE (exp) == FDESC_EXPR)
3731 {
3732 #ifdef ASM_OUTPUT_FDESC
3733 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
3734 tree decl = TREE_OPERAND (exp, 0);
3735 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
3736 #else
3737 gcc_unreachable ();
3738 #endif
3739 return;
3740 }
3741
3742 /* Now output the underlying data. If we've handling the padding, return.
3743 Otherwise, break and ensure SIZE is the size written. */
3744 switch (code)
3745 {
3746 case CHAR_TYPE:
3747 case BOOLEAN_TYPE:
3748 case INTEGER_TYPE:
3749 case ENUMERAL_TYPE:
3750 case POINTER_TYPE:
3751 case REFERENCE_TYPE:
3752 case OFFSET_TYPE:
3753 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3754 EXPAND_INITIALIZER),
3755 MIN (size, thissize), align, 0))
3756 error ("initializer for integer value is too complicated");
3757 break;
3758
3759 case REAL_TYPE:
3760 if (TREE_CODE (exp) != REAL_CST)
3761 error ("initializer for floating value is not a floating constant");
3762
3763 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
3764 break;
3765
3766 case COMPLEX_TYPE:
3767 output_constant (TREE_REALPART (exp), thissize / 2, align);
3768 output_constant (TREE_IMAGPART (exp), thissize / 2,
3769 min_align (align, BITS_PER_UNIT * (thissize / 2)));
3770 break;
3771
3772 case ARRAY_TYPE:
3773 case VECTOR_TYPE:
3774 switch (TREE_CODE (exp))
3775 {
3776 case CONSTRUCTOR:
3777 output_constructor (exp, size, align);
3778 return;
3779 case STRING_CST:
3780 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
3781 size);
3782 assemble_string (TREE_STRING_POINTER (exp), thissize);
3783 break;
3784
3785 case VECTOR_CST:
3786 {
3787 int elt_size;
3788 tree link;
3789 unsigned int nalign;
3790 enum machine_mode inner;
3791
3792 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
3793 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
3794
3795 elt_size = GET_MODE_SIZE (inner);
3796
3797 link = TREE_VECTOR_CST_ELTS (exp);
3798 output_constant (TREE_VALUE (link), elt_size, align);
3799 while ((link = TREE_CHAIN (link)) != NULL)
3800 output_constant (TREE_VALUE (link), elt_size, nalign);
3801 break;
3802 }
3803 default:
3804 gcc_unreachable ();
3805 }
3806 break;
3807
3808 case RECORD_TYPE:
3809 case UNION_TYPE:
3810 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
3811 output_constructor (exp, size, align);
3812 return;
3813
3814 case ERROR_MARK:
3815 return;
3816
3817 default:
3818 gcc_unreachable ();
3819 }
3820
3821 if (size > thissize)
3822 assemble_zeros (size - thissize);
3823 }
3824
3825 \f
3826 /* Subroutine of output_constructor, used for computing the size of
3827 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3828 type with an unspecified upper bound. */
3829
3830 static unsigned HOST_WIDE_INT
3831 array_size_for_constructor (tree val)
3832 {
3833 tree max_index, i;
3834
3835 /* This code used to attempt to handle string constants that are not
3836 arrays of single-bytes, but nothing else does, so there's no point in
3837 doing it here. */
3838 if (TREE_CODE (val) == STRING_CST)
3839 return TREE_STRING_LENGTH (val);
3840
3841 max_index = NULL_TREE;
3842 for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i))
3843 {
3844 tree index = TREE_PURPOSE (i);
3845
3846 if (TREE_CODE (index) == RANGE_EXPR)
3847 index = TREE_OPERAND (index, 1);
3848 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
3849 max_index = index;
3850 }
3851
3852 if (max_index == NULL_TREE)
3853 return 0;
3854
3855 /* Compute the total number of array elements. */
3856 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
3857 convert (sizetype,
3858 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
3859 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
3860
3861 /* Multiply by the array element unit size to find number of bytes. */
3862 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
3863
3864 return tree_low_cst (i, 1);
3865 }
3866
3867 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3868 Generate at least SIZE bytes, padding if necessary. */
3869
3870 static void
3871 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
3872 unsigned int align)
3873 {
3874 tree type = TREE_TYPE (exp);
3875 tree link, field = 0;
3876 tree min_index = 0;
3877 /* Number of bytes output or skipped so far.
3878 In other words, current position within the constructor. */
3879 HOST_WIDE_INT total_bytes = 0;
3880 /* Nonzero means BYTE contains part of a byte, to be output. */
3881 int byte_buffer_in_use = 0;
3882 int byte = 0;
3883
3884 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
3885
3886 if (TREE_CODE (type) == RECORD_TYPE)
3887 field = TYPE_FIELDS (type);
3888
3889 if (TREE_CODE (type) == ARRAY_TYPE
3890 && TYPE_DOMAIN (type) != 0)
3891 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
3892
3893 /* As LINK goes through the elements of the constant,
3894 FIELD goes through the structure fields, if the constant is a structure.
3895 if the constant is a union, then we override this,
3896 by getting the field from the TREE_LIST element.
3897 But the constant could also be an array. Then FIELD is zero.
3898
3899 There is always a maximum of one element in the chain LINK for unions
3900 (even if the initializer in a source program incorrectly contains
3901 more one). */
3902 for (link = CONSTRUCTOR_ELTS (exp);
3903 link;
3904 link = TREE_CHAIN (link),
3905 field = field ? TREE_CHAIN (field) : 0)
3906 {
3907 tree val = TREE_VALUE (link);
3908 tree index = 0;
3909
3910 /* The element in a union constructor specifies the proper field
3911 or index. */
3912 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
3913 || TREE_CODE (type) == QUAL_UNION_TYPE)
3914 && TREE_PURPOSE (link) != 0)
3915 field = TREE_PURPOSE (link);
3916
3917 else if (TREE_CODE (type) == ARRAY_TYPE)
3918 index = TREE_PURPOSE (link);
3919
3920 #ifdef ASM_COMMENT_START
3921 if (field && flag_verbose_asm)
3922 fprintf (asm_out_file, "%s %s:\n",
3923 ASM_COMMENT_START,
3924 DECL_NAME (field)
3925 ? IDENTIFIER_POINTER (DECL_NAME (field))
3926 : "<anonymous>");
3927 #endif
3928
3929 /* Eliminate the marker that makes a cast not be an lvalue. */
3930 if (val != 0)
3931 STRIP_NOPS (val);
3932
3933 if (index && TREE_CODE (index) == RANGE_EXPR)
3934 {
3935 unsigned HOST_WIDE_INT fieldsize
3936 = int_size_in_bytes (TREE_TYPE (type));
3937 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
3938 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
3939 HOST_WIDE_INT index;
3940 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
3941
3942 for (index = lo_index; index <= hi_index; index++)
3943 {
3944 /* Output the element's initial value. */
3945 if (val == 0)
3946 assemble_zeros (fieldsize);
3947 else
3948 output_constant (val, fieldsize, align2);
3949
3950 /* Count its size. */
3951 total_bytes += fieldsize;
3952 }
3953 }
3954 else if (field == 0 || !DECL_BIT_FIELD (field))
3955 {
3956 /* An element that is not a bit-field. */
3957
3958 unsigned HOST_WIDE_INT fieldsize;
3959 /* Since this structure is static,
3960 we know the positions are constant. */
3961 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
3962 unsigned int align2;
3963
3964 if (index != 0)
3965 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
3966 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
3967
3968 /* Output any buffered-up bit-fields preceding this element. */
3969 if (byte_buffer_in_use)
3970 {
3971 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3972 total_bytes++;
3973 byte_buffer_in_use = 0;
3974 }
3975
3976 /* Advance to offset of this element.
3977 Note no alignment needed in an array, since that is guaranteed
3978 if each element has the proper size. */
3979 if ((field != 0 || index != 0) && pos != total_bytes)
3980 {
3981 assemble_zeros (pos - total_bytes);
3982 total_bytes = pos;
3983 }
3984
3985 /* Find the alignment of this element. */
3986 align2 = min_align (align, BITS_PER_UNIT * pos);
3987
3988 /* Determine size this element should occupy. */
3989 if (field)
3990 {
3991 fieldsize = 0;
3992
3993 /* If this is an array with an unspecified upper bound,
3994 the initializer determines the size. */
3995 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
3996 but we cannot do this until the deprecated support for
3997 initializing zero-length array members is removed. */
3998 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
3999 && TYPE_DOMAIN (TREE_TYPE (field))
4000 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4001 {
4002 fieldsize = array_size_for_constructor (val);
4003 /* Given a non-empty initialization, this field had
4004 better be last. */
4005 gcc_assert (!fieldsize || !TREE_CHAIN (field));
4006 }
4007 else if (DECL_SIZE_UNIT (field))
4008 {
4009 /* ??? This can't be right. If the decl size overflows
4010 a host integer we will silently emit no data. */
4011 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4012 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4013 }
4014 }
4015 else
4016 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4017
4018 /* Output the element's initial value. */
4019 if (val == 0)
4020 assemble_zeros (fieldsize);
4021 else
4022 output_constant (val, fieldsize, align2);
4023
4024 /* Count its size. */
4025 total_bytes += fieldsize;
4026 }
4027 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4028 error ("invalid initial value for member %qs",
4029 IDENTIFIER_POINTER (DECL_NAME (field)));
4030 else
4031 {
4032 /* Element that is a bit-field. */
4033
4034 HOST_WIDE_INT next_offset = int_bit_position (field);
4035 HOST_WIDE_INT end_offset
4036 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4037
4038 if (val == 0)
4039 val = integer_zero_node;
4040
4041 /* If this field does not start in this (or, next) byte,
4042 skip some bytes. */
4043 if (next_offset / BITS_PER_UNIT != total_bytes)
4044 {
4045 /* Output remnant of any bit field in previous bytes. */
4046 if (byte_buffer_in_use)
4047 {
4048 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4049 total_bytes++;
4050 byte_buffer_in_use = 0;
4051 }
4052
4053 /* If still not at proper byte, advance to there. */
4054 if (next_offset / BITS_PER_UNIT != total_bytes)
4055 {
4056 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4057 total_bytes = next_offset / BITS_PER_UNIT;
4058 }
4059 }
4060
4061 if (! byte_buffer_in_use)
4062 byte = 0;
4063
4064 /* We must split the element into pieces that fall within
4065 separate bytes, and combine each byte with previous or
4066 following bit-fields. */
4067
4068 /* next_offset is the offset n fbits from the beginning of
4069 the structure to the next bit of this element to be processed.
4070 end_offset is the offset of the first bit past the end of
4071 this element. */
4072 while (next_offset < end_offset)
4073 {
4074 int this_time;
4075 int shift;
4076 HOST_WIDE_INT value;
4077 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4078 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4079
4080 /* Advance from byte to byte
4081 within this element when necessary. */
4082 while (next_byte != total_bytes)
4083 {
4084 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4085 total_bytes++;
4086 byte = 0;
4087 }
4088
4089 /* Number of bits we can process at once
4090 (all part of the same byte). */
4091 this_time = MIN (end_offset - next_offset,
4092 BITS_PER_UNIT - next_bit);
4093 if (BYTES_BIG_ENDIAN)
4094 {
4095 /* On big-endian machine, take the most significant bits
4096 first (of the bits that are significant)
4097 and put them into bytes from the most significant end. */
4098 shift = end_offset - next_offset - this_time;
4099
4100 /* Don't try to take a bunch of bits that cross
4101 the word boundary in the INTEGER_CST. We can
4102 only select bits from the LOW or HIGH part
4103 not from both. */
4104 if (shift < HOST_BITS_PER_WIDE_INT
4105 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4106 {
4107 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4108 shift = HOST_BITS_PER_WIDE_INT;
4109 }
4110
4111 /* Now get the bits from the appropriate constant word. */
4112 if (shift < HOST_BITS_PER_WIDE_INT)
4113 value = TREE_INT_CST_LOW (val);
4114 else
4115 {
4116 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4117 value = TREE_INT_CST_HIGH (val);
4118 shift -= HOST_BITS_PER_WIDE_INT;
4119 }
4120
4121 /* Get the result. This works only when:
4122 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4123 byte |= (((value >> shift)
4124 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4125 << (BITS_PER_UNIT - this_time - next_bit));
4126 }
4127 else
4128 {
4129 /* On little-endian machines,
4130 take first the least significant bits of the value
4131 and pack them starting at the least significant
4132 bits of the bytes. */
4133 shift = next_offset - int_bit_position (field);
4134
4135 /* Don't try to take a bunch of bits that cross
4136 the word boundary in the INTEGER_CST. We can
4137 only select bits from the LOW or HIGH part
4138 not from both. */
4139 if (shift < HOST_BITS_PER_WIDE_INT
4140 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4141 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4142
4143 /* Now get the bits from the appropriate constant word. */
4144 if (shift < HOST_BITS_PER_WIDE_INT)
4145 value = TREE_INT_CST_LOW (val);
4146 else
4147 {
4148 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4149 value = TREE_INT_CST_HIGH (val);
4150 shift -= HOST_BITS_PER_WIDE_INT;
4151 }
4152
4153 /* Get the result. This works only when:
4154 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4155 byte |= (((value >> shift)
4156 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4157 << next_bit);
4158 }
4159
4160 next_offset += this_time;
4161 byte_buffer_in_use = 1;
4162 }
4163 }
4164 }
4165
4166 if (byte_buffer_in_use)
4167 {
4168 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4169 total_bytes++;
4170 }
4171
4172 if ((unsigned HOST_WIDE_INT)total_bytes < size)
4173 assemble_zeros (size - total_bytes);
4174 }
4175
4176 /* This TREE_LIST contains any weak symbol declarations waiting
4177 to be emitted. */
4178 static GTY(()) tree weak_decls;
4179
4180 /* Mark DECL as weak. */
4181
4182 static void
4183 mark_weak (tree decl)
4184 {
4185 DECL_WEAK (decl) = 1;
4186
4187 if (DECL_RTL_SET_P (decl)
4188 && MEM_P (DECL_RTL (decl))
4189 && XEXP (DECL_RTL (decl), 0)
4190 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4191 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4192 }
4193
4194 /* Merge weak status between NEWDECL and OLDDECL. */
4195
4196 void
4197 merge_weak (tree newdecl, tree olddecl)
4198 {
4199 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4200 return;
4201
4202 if (DECL_WEAK (newdecl))
4203 {
4204 tree wd;
4205
4206 /* NEWDECL is weak, but OLDDECL is not. */
4207
4208 /* If we already output the OLDDECL, we're in trouble; we can't
4209 go back and make it weak. This error cannot caught in
4210 declare_weak because the NEWDECL and OLDDECL was not yet
4211 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4212 if (TREE_ASM_WRITTEN (olddecl))
4213 error ("%Jweak declaration of %qD must precede definition",
4214 newdecl, newdecl);
4215
4216 /* If we've already generated rtl referencing OLDDECL, we may
4217 have done so in a way that will not function properly with
4218 a weak symbol. */
4219 else if (TREE_USED (olddecl)
4220 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4221 warning ("%Jweak declaration of %qD after first use results "
4222 "in unspecified behavior", newdecl, newdecl);
4223
4224 if (SUPPORTS_WEAK)
4225 {
4226 /* We put the NEWDECL on the weak_decls list at some point.
4227 Replace it with the OLDDECL. */
4228 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4229 if (TREE_VALUE (wd) == newdecl)
4230 {
4231 TREE_VALUE (wd) = olddecl;
4232 break;
4233 }
4234 /* We may not find the entry on the list. If NEWDECL is a
4235 weak alias, then we will have already called
4236 globalize_decl to remove the entry; in that case, we do
4237 not need to do anything. */
4238 }
4239
4240 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4241 mark_weak (olddecl);
4242 }
4243 else
4244 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4245 weak. Just update NEWDECL to indicate that it's weak too. */
4246 mark_weak (newdecl);
4247 }
4248
4249 /* Declare DECL to be a weak symbol. */
4250
4251 void
4252 declare_weak (tree decl)
4253 {
4254 if (! TREE_PUBLIC (decl))
4255 error ("%Jweak declaration of %qD must be public", decl, decl);
4256 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4257 error ("%Jweak declaration of %qD must precede definition", decl, decl);
4258 else if (SUPPORTS_WEAK)
4259 {
4260 if (! DECL_WEAK (decl))
4261 weak_decls = tree_cons (NULL, decl, weak_decls);
4262 }
4263 else
4264 warning ("%Jweak declaration of %qD not supported", decl, decl);
4265
4266 mark_weak (decl);
4267 }
4268
4269 /* Emit any pending weak declarations. */
4270
4271 void
4272 weak_finish (void)
4273 {
4274 tree t;
4275
4276 for (t = weak_decls; t; t = TREE_CHAIN (t))
4277 {
4278 tree decl = TREE_VALUE (t);
4279 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4280 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4281 #endif
4282
4283 if (! TREE_USED (decl))
4284 continue;
4285
4286 #ifdef ASM_WEAKEN_DECL
4287 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4288 #else
4289 #ifdef ASM_WEAKEN_LABEL
4290 ASM_WEAKEN_LABEL (asm_out_file, name);
4291 #else
4292 #ifdef ASM_OUTPUT_WEAK_ALIAS
4293 warning ("only weak aliases are supported in this configuration");
4294 return;
4295 #endif
4296 #endif
4297 #endif
4298 }
4299 }
4300
4301 /* Emit the assembly bits to indicate that DECL is globally visible. */
4302
4303 static void
4304 globalize_decl (tree decl)
4305 {
4306 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4307
4308 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4309 if (DECL_WEAK (decl))
4310 {
4311 tree *p, t;
4312
4313 #ifdef ASM_WEAKEN_DECL
4314 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4315 #else
4316 ASM_WEAKEN_LABEL (asm_out_file, name);
4317 #endif
4318
4319 /* Remove this function from the pending weak list so that
4320 we do not emit multiple .weak directives for it. */
4321 for (p = &weak_decls; (t = *p) ; )
4322 {
4323 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4324 *p = TREE_CHAIN (t);
4325 else
4326 p = &TREE_CHAIN (t);
4327 }
4328 return;
4329 }
4330 #elif defined(ASM_MAKE_LABEL_LINKONCE)
4331 if (DECL_ONE_ONLY (decl))
4332 ASM_MAKE_LABEL_LINKONCE (asm_out_file, name);
4333 #endif
4334
4335 targetm.asm_out.globalize_label (asm_out_file, name);
4336 }
4337
4338 /* Some targets do not allow a forward or undefined reference in a
4339 ASM_OUTPUT_DEF. Thus, a mechanism is needed to defer the output of
4340 this assembler code. The following struct holds the declaration
4341 and target for a deferred output define. */
4342 struct output_def_pair GTY(())
4343 {
4344 tree decl;
4345 tree target;
4346 };
4347 typedef struct output_def_pair *output_def_pair;
4348
4349 /* Define gc'd vector type. */
4350 DEF_VEC_GC_P(output_def_pair);
4351
4352 /* Vector of output_def_pair pointers. */
4353 static GTY(()) VEC(output_def_pair) *output_defs;
4354
4355 #ifdef ASM_OUTPUT_DEF
4356 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
4357 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
4358 tree node is DECL to have the value of the tree node TARGET. */
4359
4360 static void
4361 assemble_output_def (tree decl ATTRIBUTE_UNUSED, tree target ATTRIBUTE_UNUSED)
4362 {
4363 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4364 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4365 #else
4366 ASM_OUTPUT_DEF (asm_out_file,
4367 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
4368 IDENTIFIER_POINTER (target));
4369 #endif
4370 }
4371 #endif
4372
4373 /* Process the vector of pending assembler defines. */
4374
4375 void
4376 process_pending_assemble_output_defs (void)
4377 {
4378 #ifdef ASM_OUTPUT_DEF
4379 unsigned i;
4380 output_def_pair p;
4381
4382 for (i = 0; VEC_iterate (output_def_pair, output_defs, i, p); i++)
4383 assemble_output_def (p->decl, p->target);
4384
4385 output_defs = NULL;
4386 #endif
4387 }
4388
4389 /* Emit an assembler directive to make the symbol for DECL an alias to
4390 the symbol for TARGET. */
4391
4392 void
4393 assemble_alias (tree decl, tree target)
4394 {
4395 /* We must force creation of DECL_RTL for debug info generation, even though
4396 we don't use it here. */
4397 make_decl_rtl (decl);
4398
4399 #ifdef ASM_OUTPUT_DEF
4400 /* Make name accessible from other files, if appropriate. */
4401
4402 if (TREE_PUBLIC (decl))
4403 {
4404 globalize_decl (decl);
4405 maybe_assemble_visibility (decl);
4406 }
4407
4408 if (TARGET_DEFERRED_OUTPUT_DEFS (decl, target))
4409 {
4410 output_def_pair p;
4411
4412 p = ggc_alloc (sizeof (struct output_def_pair));
4413 p->decl = decl;
4414 p->target = target;
4415 VEC_safe_push (output_def_pair, output_defs, p);
4416 }
4417 else
4418 assemble_output_def (decl, target);
4419 #else /* !ASM_OUTPUT_DEF */
4420 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4421 if (DECL_WEAK (decl))
4422 {
4423 const char *name;
4424 tree *p, t;
4425
4426 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4427 #ifdef ASM_WEAKEN_DECL
4428 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4429 #else
4430 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4431 #endif
4432 /* Remove this function from the pending weak list so that
4433 we do not emit multiple .weak directives for it. */
4434 for (p = &weak_decls; (t = *p) ; )
4435 if (DECL_ASSEMBLER_NAME (decl)
4436 == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4437 *p = TREE_CHAIN (t);
4438 else
4439 p = &TREE_CHAIN (t);
4440 }
4441 else
4442 warning ("only weak aliases are supported in this configuration");
4443
4444 #else
4445 warning ("alias definitions not supported in this configuration; ignored");
4446 #endif
4447 #endif
4448
4449 /* Tell cgraph that the aliased symbol is needed. We *could* be more
4450 specific and tell cgraph about the relationship between the two
4451 symbols, but given that aliases virtually always exist for a reason,
4452 it doesn't seem worthwhile. */
4453 if (flag_unit_at_a_time)
4454 {
4455 struct cgraph_node *fnode = NULL;
4456 struct cgraph_varpool_node *vnode = NULL;
4457
4458 if (TREE_CODE (decl) == FUNCTION_DECL)
4459 {
4460 fnode = cgraph_node_for_asm (target);
4461 if (fnode != NULL)
4462 cgraph_mark_needed_node (fnode);
4463 else
4464 {
4465 vnode = cgraph_varpool_node_for_asm (target);
4466 if (vnode != NULL)
4467 cgraph_varpool_mark_needed_node (vnode);
4468 }
4469 }
4470 else
4471 {
4472 vnode = cgraph_varpool_node_for_asm (target);
4473 if (vnode != NULL)
4474 cgraph_varpool_mark_needed_node (vnode);
4475 else
4476 {
4477 fnode = cgraph_node_for_asm (target);
4478 if (fnode != NULL)
4479 cgraph_mark_needed_node (fnode);
4480 }
4481 }
4482
4483 if (fnode == NULL && vnode == NULL)
4484 warning ("%qD aliased to undefined symbol %qE", decl, target);
4485 }
4486
4487 TREE_USED (decl) = 1;
4488 TREE_ASM_WRITTEN (decl) = 1;
4489 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4490 }
4491
4492 /* Emit an assembler directive to set symbol for DECL visibility to
4493 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4494
4495 void
4496 default_assemble_visibility (tree decl, int vis)
4497 {
4498 static const char * const visibility_types[] = {
4499 NULL, "internal", "hidden", "protected"
4500 };
4501
4502 const char *name, *type;
4503
4504 name = (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4505 type = visibility_types[vis];
4506
4507 #ifdef HAVE_GAS_HIDDEN
4508 fprintf (asm_out_file, "\t.%s\t", type);
4509 assemble_name (asm_out_file, name);
4510 fprintf (asm_out_file, "\n");
4511 #else
4512 warning ("visibility attribute not supported in this configuration; ignored");
4513 #endif
4514 }
4515
4516 /* A helper function to call assemble_visibility when needed for a decl. */
4517
4518 static void
4519 maybe_assemble_visibility (tree decl)
4520 {
4521 enum symbol_visibility vis = DECL_VISIBILITY (decl);
4522
4523 if (vis != VISIBILITY_DEFAULT)
4524 targetm.asm_out.visibility (decl, vis);
4525 }
4526
4527 /* Returns 1 if the target configuration supports defining public symbols
4528 so that one of them will be chosen at link time instead of generating a
4529 multiply-defined symbol error, whether through the use of weak symbols or
4530 a target-specific mechanism for having duplicates discarded. */
4531
4532 int
4533 supports_one_only (void)
4534 {
4535 if (SUPPORTS_ONE_ONLY)
4536 return 1;
4537 return SUPPORTS_WEAK;
4538 }
4539
4540 /* Set up DECL as a public symbol that can be defined in multiple
4541 translation units without generating a linker error. */
4542
4543 void
4544 make_decl_one_only (tree decl)
4545 {
4546 gcc_assert (TREE_CODE (decl) == VAR_DECL
4547 || TREE_CODE (decl) == FUNCTION_DECL);
4548
4549 TREE_PUBLIC (decl) = 1;
4550
4551 if (SUPPORTS_ONE_ONLY)
4552 {
4553 #ifdef MAKE_DECL_ONE_ONLY
4554 MAKE_DECL_ONE_ONLY (decl);
4555 #endif
4556 DECL_ONE_ONLY (decl) = 1;
4557 }
4558 else if (TREE_CODE (decl) == VAR_DECL
4559 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4560 DECL_COMMON (decl) = 1;
4561 else
4562 {
4563 gcc_assert (SUPPORTS_WEAK);
4564 DECL_WEAK (decl) = 1;
4565 }
4566 }
4567
4568 void
4569 init_varasm_once (void)
4570 {
4571 in_named_htab = htab_create_ggc (31, in_named_entry_hash,
4572 in_named_entry_eq, NULL);
4573 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
4574 const_desc_eq, NULL);
4575
4576 const_alias_set = new_alias_set ();
4577 }
4578
4579 static enum tls_model
4580 decl_tls_model (tree decl)
4581 {
4582 enum tls_model kind;
4583 tree attr = lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl));
4584 bool is_local;
4585
4586 if (attr)
4587 {
4588 attr = TREE_VALUE (TREE_VALUE (attr));
4589 gcc_assert (TREE_CODE (attr) == STRING_CST);
4590
4591 if (!strcmp (TREE_STRING_POINTER (attr), "local-exec"))
4592 kind = TLS_MODEL_LOCAL_EXEC;
4593 else if (!strcmp (TREE_STRING_POINTER (attr), "initial-exec"))
4594 kind = TLS_MODEL_INITIAL_EXEC;
4595 else if (!strcmp (TREE_STRING_POINTER (attr), "local-dynamic"))
4596 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
4597 else if (!strcmp (TREE_STRING_POINTER (attr), "global-dynamic"))
4598 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4599 else
4600 gcc_unreachable ();
4601 return kind;
4602 }
4603
4604 is_local = targetm.binds_local_p (decl);
4605 if (!flag_shlib)
4606 {
4607 if (is_local)
4608 kind = TLS_MODEL_LOCAL_EXEC;
4609 else
4610 kind = TLS_MODEL_INITIAL_EXEC;
4611 }
4612 /* Local dynamic is inefficient when we're not combining the
4613 parts of the address. */
4614 else if (optimize && is_local)
4615 kind = TLS_MODEL_LOCAL_DYNAMIC;
4616 else
4617 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4618 if (kind < flag_tls_default)
4619 kind = flag_tls_default;
4620
4621 return kind;
4622 }
4623
4624 /* Select a set of attributes for section NAME based on the properties
4625 of DECL and whether or not RELOC indicates that DECL's initializer
4626 might contain runtime relocations.
4627
4628 We make the section read-only and executable for a function decl,
4629 read-only for a const data decl, and writable for a non-const data decl. */
4630
4631 unsigned int
4632 default_section_type_flags (tree decl, const char *name, int reloc)
4633 {
4634 return default_section_type_flags_1 (decl, name, reloc, flag_pic);
4635 }
4636
4637 unsigned int
4638 default_section_type_flags_1 (tree decl, const char *name, int reloc,
4639 int shlib)
4640 {
4641 unsigned int flags;
4642
4643 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4644 flags = SECTION_CODE;
4645 else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
4646 flags = 0;
4647 else if (unlikely_text_section_name
4648 && strcmp (name, unlikely_text_section_name) == 0)
4649 flags = SECTION_CODE;
4650 else
4651 flags = SECTION_WRITE;
4652
4653 if (decl && DECL_ONE_ONLY (decl))
4654 flags |= SECTION_LINKONCE;
4655
4656 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4657 flags |= SECTION_TLS | SECTION_WRITE;
4658
4659 if (strcmp (name, ".bss") == 0
4660 || strncmp (name, ".bss.", 5) == 0
4661 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
4662 || strcmp (name, ".sbss") == 0
4663 || strncmp (name, ".sbss.", 6) == 0
4664 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
4665 flags |= SECTION_BSS;
4666
4667 if (strcmp (name, ".tdata") == 0
4668 || strncmp (name, ".tdata.", 7) == 0
4669 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
4670 flags |= SECTION_TLS;
4671
4672 if (strcmp (name, ".tbss") == 0
4673 || strncmp (name, ".tbss.", 6) == 0
4674 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4675 flags |= SECTION_TLS | SECTION_BSS;
4676
4677 /* These three sections have special ELF types. They are neither
4678 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4679 want to print a section type (@progbits or @nobits). If someone
4680 is silly enough to emit code or TLS variables to one of these
4681 sections, then don't handle them specially. */
4682 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
4683 && (strcmp (name, ".init_array") == 0
4684 || strcmp (name, ".fini_array") == 0
4685 || strcmp (name, ".preinit_array") == 0))
4686 flags |= SECTION_NOTYPE;
4687
4688 return flags;
4689 }
4690
4691 /* Output assembly to switch to section NAME with attribute FLAGS.
4692 Four variants for common object file formats. */
4693
4694 void
4695 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
4696 unsigned int flags ATTRIBUTE_UNUSED,
4697 tree decl ATTRIBUTE_UNUSED)
4698 {
4699 /* Some object formats don't support named sections at all. The
4700 front-end should already have flagged this as an error. */
4701 gcc_unreachable ();
4702 }
4703
4704 void
4705 default_elf_asm_named_section (const char *name, unsigned int flags,
4706 tree decl ATTRIBUTE_UNUSED)
4707 {
4708 char flagchars[10], *f = flagchars;
4709
4710 /* If we have already declared this section, we can use an
4711 abbreviated form to switch back to it -- unless this section is
4712 part of a COMDAT groups, in which case GAS requires the full
4713 declaration every time. */
4714 if (!(HAVE_GAS_COMDAT_GROUP && (flags & SECTION_LINKONCE))
4715 && ! named_section_first_declaration (name))
4716 {
4717 fprintf (asm_out_file, "\t.section\t%s\n", name);
4718 return;
4719 }
4720
4721 if (!(flags & SECTION_DEBUG))
4722 *f++ = 'a';
4723 if (flags & SECTION_WRITE)
4724 *f++ = 'w';
4725 if (flags & SECTION_CODE)
4726 *f++ = 'x';
4727 if (flags & SECTION_SMALL)
4728 *f++ = 's';
4729 if (flags & SECTION_MERGE)
4730 *f++ = 'M';
4731 if (flags & SECTION_STRINGS)
4732 *f++ = 'S';
4733 if (flags & SECTION_TLS)
4734 *f++ = 'T';
4735 if (HAVE_GAS_COMDAT_GROUP && (flags & SECTION_LINKONCE))
4736 *f++ = 'G';
4737 *f = '\0';
4738
4739 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
4740
4741 if (!(flags & SECTION_NOTYPE))
4742 {
4743 const char *type;
4744 const char *format;
4745
4746 if (flags & SECTION_BSS)
4747 type = "nobits";
4748 else
4749 type = "progbits";
4750
4751 format = ",@%s";
4752 #ifdef ASM_COMMENT_START
4753 /* On platforms that use "@" as the assembly comment character,
4754 use "%" instead. */
4755 if (strcmp (ASM_COMMENT_START, "@") == 0)
4756 format = ",%%%s";
4757 #endif
4758 fprintf (asm_out_file, format, type);
4759
4760 if (flags & SECTION_ENTSIZE)
4761 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
4762 if (HAVE_GAS_COMDAT_GROUP && (flags & SECTION_LINKONCE))
4763 fprintf (asm_out_file, ",%s,comdat",
4764 lang_hooks.decls.comdat_group (decl));
4765 }
4766
4767 putc ('\n', asm_out_file);
4768 }
4769
4770 void
4771 default_coff_asm_named_section (const char *name, unsigned int flags,
4772 tree decl ATTRIBUTE_UNUSED)
4773 {
4774 char flagchars[8], *f = flagchars;
4775
4776 if (flags & SECTION_WRITE)
4777 *f++ = 'w';
4778 if (flags & SECTION_CODE)
4779 *f++ = 'x';
4780 *f = '\0';
4781
4782 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
4783 }
4784
4785 void
4786 default_pe_asm_named_section (const char *name, unsigned int flags,
4787 tree decl)
4788 {
4789 default_coff_asm_named_section (name, flags, decl);
4790
4791 if (flags & SECTION_LINKONCE)
4792 {
4793 /* Functions may have been compiled at various levels of
4794 optimization so we can't use `same_size' here.
4795 Instead, have the linker pick one. */
4796 fprintf (asm_out_file, "\t.linkonce %s\n",
4797 (flags & SECTION_CODE ? "discard" : "same_size"));
4798 }
4799 }
4800 \f
4801 /* The lame default section selector. */
4802
4803 void
4804 default_select_section (tree decl, int reloc,
4805 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4806 {
4807 bool readonly = false;
4808
4809 if (DECL_P (decl))
4810 {
4811 if (decl_readonly_section (decl, reloc))
4812 readonly = true;
4813 }
4814 else if (TREE_CODE (decl) == CONSTRUCTOR)
4815 {
4816 if (! ((flag_pic && reloc)
4817 || !TREE_READONLY (decl)
4818 || TREE_SIDE_EFFECTS (decl)
4819 || !TREE_CONSTANT (decl)))
4820 readonly = true;
4821 }
4822 else if (TREE_CODE (decl) == STRING_CST)
4823 readonly = true;
4824 else if (! (flag_pic && reloc))
4825 readonly = true;
4826
4827 if (readonly)
4828 readonly_data_section ();
4829 else
4830 data_section ();
4831 }
4832
4833 /* A helper function for default_elf_select_section and
4834 default_elf_unique_section. Categorizes the DECL. */
4835
4836 enum section_category
4837 {
4838 SECCAT_TEXT,
4839
4840 SECCAT_RODATA,
4841 SECCAT_RODATA_MERGE_STR,
4842 SECCAT_RODATA_MERGE_STR_INIT,
4843 SECCAT_RODATA_MERGE_CONST,
4844 SECCAT_SRODATA,
4845
4846 SECCAT_DATA,
4847
4848 /* To optimize loading of shared programs, define following subsections
4849 of data section:
4850 _REL Contains data that has relocations, so they get grouped
4851 together and dynamic linker will visit fewer pages in memory.
4852 _RO Contains data that is otherwise read-only. This is useful
4853 with prelinking as most relocations won't be dynamically
4854 linked and thus stay read only.
4855 _LOCAL Marks data containing relocations only to local objects.
4856 These relocations will get fully resolved by prelinking. */
4857 SECCAT_DATA_REL,
4858 SECCAT_DATA_REL_LOCAL,
4859 SECCAT_DATA_REL_RO,
4860 SECCAT_DATA_REL_RO_LOCAL,
4861
4862 SECCAT_SDATA,
4863 SECCAT_TDATA,
4864
4865 SECCAT_BSS,
4866 SECCAT_SBSS,
4867 SECCAT_TBSS
4868 };
4869
4870 static enum section_category
4871 categorize_decl_for_section (tree, int, int);
4872
4873 static enum section_category
4874 categorize_decl_for_section (tree decl, int reloc, int shlib)
4875 {
4876 enum section_category ret;
4877
4878 if (TREE_CODE (decl) == FUNCTION_DECL)
4879 return SECCAT_TEXT;
4880 else if (TREE_CODE (decl) == STRING_CST)
4881 {
4882 if (flag_mudflap) /* or !flag_merge_constants */
4883 return SECCAT_RODATA;
4884 else
4885 return SECCAT_RODATA_MERGE_STR;
4886 }
4887 else if (TREE_CODE (decl) == VAR_DECL)
4888 {
4889 if (DECL_INITIAL (decl) == NULL
4890 || DECL_INITIAL (decl) == error_mark_node
4891 || (flag_zero_initialized_in_bss
4892 /* Leave constant zeroes in .rodata so they can be shared. */
4893 && !TREE_READONLY (decl)
4894 && initializer_zerop (DECL_INITIAL (decl))))
4895 ret = SECCAT_BSS;
4896 else if (! TREE_READONLY (decl)
4897 || TREE_SIDE_EFFECTS (decl)
4898 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
4899 {
4900 if (shlib && (reloc & 2))
4901 ret = SECCAT_DATA_REL;
4902 else if (shlib && reloc)
4903 ret = SECCAT_DATA_REL_LOCAL;
4904 else
4905 ret = SECCAT_DATA;
4906 }
4907 else if (shlib && (reloc & 2))
4908 ret = SECCAT_DATA_REL_RO;
4909 else if (shlib && reloc)
4910 ret = SECCAT_DATA_REL_RO_LOCAL;
4911 else if (reloc || flag_merge_constants < 2)
4912 /* C and C++ don't allow different variables to share the same
4913 location. -fmerge-all-constants allows even that (at the
4914 expense of not conforming). */
4915 ret = SECCAT_RODATA;
4916 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
4917 ret = SECCAT_RODATA_MERGE_STR_INIT;
4918 else
4919 ret = SECCAT_RODATA_MERGE_CONST;
4920 }
4921 else if (TREE_CODE (decl) == CONSTRUCTOR)
4922 {
4923 if ((shlib && reloc)
4924 || TREE_SIDE_EFFECTS (decl)
4925 || ! TREE_CONSTANT (decl))
4926 ret = SECCAT_DATA;
4927 else
4928 ret = SECCAT_RODATA;
4929 }
4930 else
4931 ret = SECCAT_RODATA;
4932
4933 /* There are no read-only thread-local sections. */
4934 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4935 {
4936 /* Note that this would be *just* SECCAT_BSS, except that there's
4937 no concept of a read-only thread-local-data section. */
4938 if (ret == SECCAT_BSS
4939 || (flag_zero_initialized_in_bss
4940 && initializer_zerop (DECL_INITIAL (decl))))
4941 ret = SECCAT_TBSS;
4942 else
4943 ret = SECCAT_TDATA;
4944 }
4945
4946 /* If the target uses small data sections, select it. */
4947 else if (targetm.in_small_data_p (decl))
4948 {
4949 if (ret == SECCAT_BSS)
4950 ret = SECCAT_SBSS;
4951 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
4952 ret = SECCAT_SRODATA;
4953 else
4954 ret = SECCAT_SDATA;
4955 }
4956
4957 return ret;
4958 }
4959
4960 bool
4961 decl_readonly_section (tree decl, int reloc)
4962 {
4963 return decl_readonly_section_1 (decl, reloc, flag_pic);
4964 }
4965
4966 bool
4967 decl_readonly_section_1 (tree decl, int reloc, int shlib)
4968 {
4969 switch (categorize_decl_for_section (decl, reloc, shlib))
4970 {
4971 case SECCAT_RODATA:
4972 case SECCAT_RODATA_MERGE_STR:
4973 case SECCAT_RODATA_MERGE_STR_INIT:
4974 case SECCAT_RODATA_MERGE_CONST:
4975 case SECCAT_SRODATA:
4976 return true;
4977 break;
4978 default:
4979 return false;
4980 break;
4981 }
4982 }
4983
4984 /* Select a section based on the above categorization. */
4985
4986 void
4987 default_elf_select_section (tree decl, int reloc,
4988 unsigned HOST_WIDE_INT align)
4989 {
4990 default_elf_select_section_1 (decl, reloc, align, flag_pic);
4991 }
4992
4993 void
4994 default_elf_select_section_1 (tree decl, int reloc,
4995 unsigned HOST_WIDE_INT align, int shlib)
4996 {
4997 const char *sname;
4998 switch (categorize_decl_for_section (decl, reloc, shlib))
4999 {
5000 case SECCAT_TEXT:
5001 /* We're not supposed to be called on FUNCTION_DECLs. */
5002 gcc_unreachable ();
5003 case SECCAT_RODATA:
5004 readonly_data_section ();
5005 return;
5006 case SECCAT_RODATA_MERGE_STR:
5007 mergeable_string_section (decl, align, 0);
5008 return;
5009 case SECCAT_RODATA_MERGE_STR_INIT:
5010 mergeable_string_section (DECL_INITIAL (decl), align, 0);
5011 return;
5012 case SECCAT_RODATA_MERGE_CONST:
5013 mergeable_constant_section (DECL_MODE (decl), align, 0);
5014 return;
5015 case SECCAT_SRODATA:
5016 sname = ".sdata2";
5017 break;
5018 case SECCAT_DATA:
5019 data_section ();
5020 return;
5021 case SECCAT_DATA_REL:
5022 sname = ".data.rel";
5023 break;
5024 case SECCAT_DATA_REL_LOCAL:
5025 sname = ".data.rel.local";
5026 break;
5027 case SECCAT_DATA_REL_RO:
5028 sname = ".data.rel.ro";
5029 break;
5030 case SECCAT_DATA_REL_RO_LOCAL:
5031 sname = ".data.rel.ro.local";
5032 break;
5033 case SECCAT_SDATA:
5034 sname = ".sdata";
5035 break;
5036 case SECCAT_TDATA:
5037 sname = ".tdata";
5038 break;
5039 case SECCAT_BSS:
5040 #ifdef BSS_SECTION_ASM_OP
5041 bss_section ();
5042 return;
5043 #else
5044 sname = ".bss";
5045 break;
5046 #endif
5047 case SECCAT_SBSS:
5048 sname = ".sbss";
5049 break;
5050 case SECCAT_TBSS:
5051 sname = ".tbss";
5052 break;
5053 default:
5054 gcc_unreachable ();
5055 }
5056
5057 if (!DECL_P (decl))
5058 decl = NULL_TREE;
5059 named_section (decl, sname, reloc);
5060 }
5061
5062 /* Construct a unique section name based on the decl name and the
5063 categorization performed above. */
5064
5065 void
5066 default_unique_section (tree decl, int reloc)
5067 {
5068 default_unique_section_1 (decl, reloc, flag_pic);
5069 }
5070
5071 void
5072 default_unique_section_1 (tree decl, int reloc, int shlib)
5073 {
5074 bool one_only = DECL_ONE_ONLY (decl);
5075 const char *prefix, *name;
5076 size_t nlen, plen;
5077 char *string;
5078
5079 switch (categorize_decl_for_section (decl, reloc, shlib))
5080 {
5081 case SECCAT_TEXT:
5082 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
5083 break;
5084 case SECCAT_RODATA:
5085 case SECCAT_RODATA_MERGE_STR:
5086 case SECCAT_RODATA_MERGE_STR_INIT:
5087 case SECCAT_RODATA_MERGE_CONST:
5088 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
5089 break;
5090 case SECCAT_SRODATA:
5091 prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
5092 break;
5093 case SECCAT_DATA:
5094 case SECCAT_DATA_REL:
5095 case SECCAT_DATA_REL_LOCAL:
5096 case SECCAT_DATA_REL_RO:
5097 case SECCAT_DATA_REL_RO_LOCAL:
5098 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
5099 break;
5100 case SECCAT_SDATA:
5101 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
5102 break;
5103 case SECCAT_BSS:
5104 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
5105 break;
5106 case SECCAT_SBSS:
5107 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
5108 break;
5109 case SECCAT_TDATA:
5110 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
5111 break;
5112 case SECCAT_TBSS:
5113 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
5114 break;
5115 default:
5116 gcc_unreachable ();
5117 }
5118 plen = strlen (prefix);
5119
5120 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5121 name = targetm.strip_name_encoding (name);
5122 nlen = strlen (name);
5123
5124 string = alloca (nlen + plen + 1);
5125 memcpy (string, prefix, plen);
5126 memcpy (string + plen, name, nlen + 1);
5127
5128 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
5129 }
5130
5131 void
5132 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
5133 rtx x,
5134 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5135 {
5136 if (flag_pic)
5137 switch (GET_CODE (x))
5138 {
5139 case CONST:
5140 case SYMBOL_REF:
5141 case LABEL_REF:
5142 data_section ();
5143 return;
5144
5145 default:
5146 break;
5147 }
5148
5149 readonly_data_section ();
5150 }
5151
5152 void
5153 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
5154 unsigned HOST_WIDE_INT align)
5155 {
5156 /* ??? Handle small data here somehow. */
5157
5158 if (flag_pic)
5159 switch (GET_CODE (x))
5160 {
5161 case CONST:
5162 case SYMBOL_REF:
5163 named_section (NULL_TREE, ".data.rel.ro", 3);
5164 return;
5165
5166 case LABEL_REF:
5167 named_section (NULL_TREE, ".data.rel.ro.local", 1);
5168 return;
5169
5170 default:
5171 break;
5172 }
5173
5174 mergeable_constant_section (mode, align, 0);
5175 }
5176
5177 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5178
5179 void
5180 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
5181 {
5182 rtx symbol;
5183 int flags;
5184
5185 /* Careful not to prod global register variables. */
5186 if (!MEM_P (rtl))
5187 return;
5188 symbol = XEXP (rtl, 0);
5189 if (GET_CODE (symbol) != SYMBOL_REF)
5190 return;
5191
5192 flags = 0;
5193 if (TREE_CODE (decl) == FUNCTION_DECL)
5194 flags |= SYMBOL_FLAG_FUNCTION;
5195 if (targetm.binds_local_p (decl))
5196 flags |= SYMBOL_FLAG_LOCAL;
5197 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
5198 flags |= decl_tls_model (decl) << SYMBOL_FLAG_TLS_SHIFT;
5199 else if (targetm.in_small_data_p (decl))
5200 flags |= SYMBOL_FLAG_SMALL;
5201 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5202 being PUBLIC, the thing *must* be defined in this translation unit.
5203 Prevent this buglet from being propagated into rtl code as well. */
5204 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
5205 flags |= SYMBOL_FLAG_EXTERNAL;
5206
5207 SYMBOL_REF_FLAGS (symbol) = flags;
5208 }
5209
5210 /* By default, we do nothing for encode_section_info, so we need not
5211 do anything but discard the '*' marker. */
5212
5213 const char *
5214 default_strip_name_encoding (const char *str)
5215 {
5216 return str + (*str == '*');
5217 }
5218
5219 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5220 wrt cross-module name binding. */
5221
5222 bool
5223 default_binds_local_p (tree exp)
5224 {
5225 return default_binds_local_p_1 (exp, flag_shlib);
5226 }
5227
5228 bool
5229 default_binds_local_p_1 (tree exp, int shlib)
5230 {
5231 bool local_p;
5232
5233 /* A non-decl is an entry in the constant pool. */
5234 if (!DECL_P (exp))
5235 local_p = true;
5236 /* Static variables are always local. */
5237 else if (! TREE_PUBLIC (exp))
5238 local_p = true;
5239 /* A variable is local if the user explicitly tells us so. */
5240 else if (DECL_VISIBILITY_SPECIFIED (exp) && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5241 local_p = true;
5242 /* Otherwise, variables defined outside this object may not be local. */
5243 else if (DECL_EXTERNAL (exp))
5244 local_p = false;
5245 /* Linkonce and weak data are never local. */
5246 else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
5247 local_p = false;
5248 /* If none of the above and visibility is not default, make local. */
5249 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5250 local_p = true;
5251 /* If PIC, then assume that any global name can be overridden by
5252 symbols resolved from other modules. */
5253 else if (shlib)
5254 local_p = false;
5255 /* Uninitialized COMMON variable may be unified with symbols
5256 resolved from other modules. */
5257 else if (DECL_COMMON (exp)
5258 && (DECL_INITIAL (exp) == NULL
5259 || DECL_INITIAL (exp) == error_mark_node))
5260 local_p = false;
5261 /* Otherwise we're left with initialized (or non-common) global data
5262 which is of necessity defined locally. */
5263 else
5264 local_p = true;
5265
5266 return local_p;
5267 }
5268
5269 /* Determine whether or not a pointer mode is valid. Assume defaults
5270 of ptr_mode or Pmode - can be overridden. */
5271 bool
5272 default_valid_pointer_mode (enum machine_mode mode)
5273 {
5274 return (mode == ptr_mode || mode == Pmode);
5275 }
5276
5277 /* Default function to output code that will globalize a label. A
5278 target must define GLOBAL_ASM_OP or provide it's own function to
5279 globalize a label. */
5280 #ifdef GLOBAL_ASM_OP
5281 void
5282 default_globalize_label (FILE * stream, const char *name)
5283 {
5284 fputs (GLOBAL_ASM_OP, stream);
5285 assemble_name (stream, name);
5286 putc ('\n', stream);
5287 }
5288 #endif /* GLOBAL_ASM_OP */
5289
5290 /* Default function to output a label for unwind information. The
5291 default is to do nothing. A target that needs nonlocal labels for
5292 unwind information must provide its own function to do this. */
5293 void
5294 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
5295 tree decl ATTRIBUTE_UNUSED,
5296 int for_eh ATTRIBUTE_UNUSED,
5297 int empty ATTRIBUTE_UNUSED)
5298 {
5299 }
5300
5301 /* This is how to output an internal numbered label where PREFIX is
5302 the class of label and LABELNO is the number within the class. */
5303
5304 void
5305 default_internal_label (FILE *stream, const char *prefix,
5306 unsigned long labelno)
5307 {
5308 char *const buf = alloca (40 + strlen (prefix));
5309 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
5310 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
5311 }
5312
5313 /* This is the default behavior at the beginning of a file. It's
5314 controlled by two other target-hook toggles. */
5315 void
5316 default_file_start (void)
5317 {
5318 if (targetm.file_start_app_off && !flag_verbose_asm)
5319 fputs (ASM_APP_OFF, asm_out_file);
5320
5321 if (targetm.file_start_file_directive)
5322 output_file_directive (asm_out_file, main_input_filename);
5323 }
5324
5325 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5326 which emits a special section directive used to indicate whether or
5327 not this object file needs an executable stack. This is primarily
5328 a GNU extension to ELF but could be used on other targets. */
5329
5330 int trampolines_created;
5331
5332 void
5333 file_end_indicate_exec_stack (void)
5334 {
5335 unsigned int flags = SECTION_DEBUG;
5336 if (trampolines_created)
5337 flags |= SECTION_CODE;
5338
5339 named_section_flags (".note.GNU-stack", flags);
5340 }
5341
5342 #include "gt-varasm.h"