OSDN Git Service

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