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