OSDN Git Service

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