OSDN Git Service

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