OSDN Git Service

2005-03-31 Jan Hubicka <jh@suse.cz>
[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     {
1887       struct cgraph_varpool_node *node = cgraph_varpool_node (decl);
1888       cgraph_varpool_mark_needed_node (node);
1889       /* C++ frontend use mark_decl_references to force COMDAT variables
1890          to be output that might appear dead otherwise.  */
1891       node->force_output = true;
1892     }
1893   /* else do nothing - we can get various sorts of CST nodes here,
1894      which do not need to be marked.  */
1895 }
1896
1897 /* Output to FILE (an assembly file) a reference to NAME.  If NAME
1898    starts with a *, the rest of NAME is output verbatim.  Otherwise
1899    NAME is transformed in a target-specific way (usually by the
1900    addition of an underscore).  */
1901
1902 void
1903 assemble_name_raw (FILE *file, const char *name)
1904 {
1905   if (name[0] == '*')
1906     fputs (&name[1], file);
1907   else
1908     ASM_OUTPUT_LABELREF (file, name);
1909 }
1910
1911 /* Like assemble_name_raw, but should be used when NAME might refer to
1912    an entity that is also represented as a tree (like a function or
1913    variable).  If NAME does refer to such an entity, that entity will
1914    be marked as referenced.  */
1915
1916 void
1917 assemble_name (FILE *file, const char *name)
1918 {
1919   const char *real_name;
1920   tree id;
1921
1922   real_name = targetm.strip_name_encoding (name);
1923
1924   id = maybe_get_identifier (real_name);
1925   if (id)
1926     mark_referenced (id);
1927
1928   assemble_name_raw (file, name);
1929 }
1930
1931 /* Allocate SIZE bytes writable static space with a gensym name
1932    and return an RTX to refer to its address.  */
1933
1934 rtx
1935 assemble_static_space (unsigned HOST_WIDE_INT size)
1936 {
1937   char name[12];
1938   const char *namestring;
1939   rtx x;
1940
1941 #if 0
1942   if (flag_shared_data)
1943     data_section ();
1944 #endif
1945
1946   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1947   ++const_labelno;
1948   namestring = ggc_strdup (name);
1949
1950   x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1951   SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
1952
1953 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1954   ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1955                                  BIGGEST_ALIGNMENT);
1956 #else
1957 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1958   ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1959 #else
1960   {
1961     /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1962        so that each uninitialized object starts on such a boundary.  */
1963     /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL.  */
1964     unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1965       = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1966          / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1967          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1968     ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1969   }
1970 #endif
1971 #endif
1972   return x;
1973 }
1974
1975 /* Assemble the static constant template for function entry trampolines.
1976    This is done at most once per compilation.
1977    Returns an RTX for the address of the template.  */
1978
1979 static GTY(()) rtx initial_trampoline;
1980
1981 #ifdef TRAMPOLINE_TEMPLATE
1982 rtx
1983 assemble_trampoline_template (void)
1984 {
1985   char label[256];
1986   const char *name;
1987   int align;
1988   rtx symbol;
1989
1990   if (initial_trampoline)
1991     return initial_trampoline;
1992
1993   /* By default, put trampoline templates in read-only data section.  */
1994
1995 #ifdef TRAMPOLINE_SECTION
1996   TRAMPOLINE_SECTION ();
1997 #else
1998   readonly_data_section ();
1999 #endif
2000
2001   /* Write the assembler code to define one.  */
2002   align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2003   if (align > 0)
2004     {
2005       ASM_OUTPUT_ALIGN (asm_out_file, align);
2006     }
2007
2008   targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2009   TRAMPOLINE_TEMPLATE (asm_out_file);
2010
2011   /* Record the rtl to refer to it.  */
2012   ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2013   name = ggc_strdup (label);
2014   symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2015   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2016
2017   initial_trampoline = gen_rtx_MEM (BLKmode, symbol);
2018   set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2019
2020   return initial_trampoline;
2021 }
2022 #endif
2023 \f
2024 /* A and B are either alignments or offsets.  Return the minimum alignment
2025    that may be assumed after adding the two together.  */
2026
2027 static inline unsigned
2028 min_align (unsigned int a, unsigned int b)
2029 {
2030   return (a | b) & -(a | b);
2031 }
2032
2033 /* Return the assembler directive for creating a given kind of integer
2034    object.  SIZE is the number of bytes in the object and ALIGNED_P
2035    indicates whether it is known to be aligned.  Return NULL if the
2036    assembly dialect has no such directive.
2037
2038    The returned string should be printed at the start of a new line and
2039    be followed immediately by the object's initial value.  */
2040
2041 const char *
2042 integer_asm_op (int size, int aligned_p)
2043 {
2044   struct asm_int_op *ops;
2045
2046   if (aligned_p)
2047     ops = &targetm.asm_out.aligned_op;
2048   else
2049     ops = &targetm.asm_out.unaligned_op;
2050
2051   switch (size)
2052     {
2053     case 1:
2054       return targetm.asm_out.byte_op;
2055     case 2:
2056       return ops->hi;
2057     case 4:
2058       return ops->si;
2059     case 8:
2060       return ops->di;
2061     case 16:
2062       return ops->ti;
2063     default:
2064       return NULL;
2065     }
2066 }
2067
2068 /* Use directive OP to assemble an integer object X.  Print OP at the
2069    start of the line, followed immediately by the value of X.  */
2070
2071 void
2072 assemble_integer_with_op (const char *op, rtx x)
2073 {
2074   fputs (op, asm_out_file);
2075   output_addr_const (asm_out_file, x);
2076   fputc ('\n', asm_out_file);
2077 }
2078
2079 /* The default implementation of the asm_out.integer target hook.  */
2080
2081 bool
2082 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2083                           unsigned int size ATTRIBUTE_UNUSED,
2084                           int aligned_p ATTRIBUTE_UNUSED)
2085 {
2086   const char *op = integer_asm_op (size, aligned_p);
2087   /* Avoid GAS bugs for large values.  Specifically negative values whose
2088      absolute value fits in a bfd_vma, but not in a bfd_signed_vma.  */
2089   if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2090     return false;
2091   return op && (assemble_integer_with_op (op, x), true);
2092 }
2093
2094 /* Assemble the integer constant X into an object of SIZE bytes.  ALIGN is
2095    the alignment of the integer in bits.  Return 1 if we were able to output
2096    the constant, otherwise 0.  If FORCE is nonzero, abort if we can't output
2097    the constant.  */
2098
2099 bool
2100 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2101 {
2102   int aligned_p;
2103
2104   aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2105
2106   /* See if the target hook can handle this kind of object.  */
2107   if (targetm.asm_out.integer (x, size, aligned_p))
2108     return true;
2109
2110   /* If the object is a multi-byte one, try splitting it up.  Split
2111      it into words it if is multi-word, otherwise split it into bytes.  */
2112   if (size > 1)
2113     {
2114       enum machine_mode omode, imode;
2115       unsigned int subalign;
2116       unsigned int subsize, i;
2117
2118       subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2119       subalign = MIN (align, subsize * BITS_PER_UNIT);
2120       omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
2121       imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2122
2123       for (i = 0; i < size; i += subsize)
2124         {
2125           rtx partial = simplify_subreg (omode, x, imode, i);
2126           if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2127             break;
2128         }
2129       if (i == size)
2130         return true;
2131
2132       /* If we've printed some of it, but not all of it, there's no going
2133          back now.  */
2134       gcc_assert (!i);
2135     }
2136
2137   gcc_assert (!force);
2138   
2139   return false;
2140 }
2141 \f
2142 void
2143 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2144 {
2145   long data[4];
2146   int i;
2147   int bitsize, nelts, nunits, units_per;
2148
2149   /* This is hairy.  We have a quantity of known size.  real_to_target
2150      will put it into an array of *host* longs, 32 bits per element
2151      (even if long is more than 32 bits).  We need to determine the
2152      number of array elements that are occupied (nelts) and the number
2153      of *target* min-addressable units that will be occupied in the
2154      object file (nunits).  We cannot assume that 32 divides the
2155      mode's bitsize (size * BITS_PER_UNIT) evenly.
2156
2157      size * BITS_PER_UNIT is used here to make sure that padding bits
2158      (which might appear at either end of the value; real_to_target
2159      will include the padding bits in its output array) are included.  */
2160
2161   nunits = GET_MODE_SIZE (mode);
2162   bitsize = nunits * BITS_PER_UNIT;
2163   nelts = CEIL (bitsize, 32);
2164   units_per = 32 / BITS_PER_UNIT;
2165
2166   real_to_target (data, &d, mode);
2167
2168   /* Put out the first word with the specified alignment.  */
2169   assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2170   nunits -= units_per;
2171
2172   /* Subsequent words need only 32-bit alignment.  */
2173   align = min_align (align, 32);
2174
2175   for (i = 1; i < nelts; i++)
2176     {
2177       assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2178       nunits -= units_per;
2179     }
2180 }
2181 \f
2182 /* Given an expression EXP with a constant value,
2183    reduce it to the sum of an assembler symbol and an integer.
2184    Store them both in the structure *VALUE.
2185    Abort if EXP does not reduce.  */
2186
2187 struct addr_const GTY(())
2188 {
2189   rtx base;
2190   HOST_WIDE_INT offset;
2191 };
2192
2193 static void
2194 decode_addr_const (tree exp, struct addr_const *value)
2195 {
2196   tree target = TREE_OPERAND (exp, 0);
2197   int offset = 0;
2198   rtx x;
2199
2200   while (1)
2201     {
2202       if (TREE_CODE (target) == COMPONENT_REF
2203           && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2204
2205         {
2206           offset += int_byte_position (TREE_OPERAND (target, 1));
2207           target = TREE_OPERAND (target, 0);
2208         }
2209       else if (TREE_CODE (target) == ARRAY_REF
2210                || TREE_CODE (target) == ARRAY_RANGE_REF)
2211         {
2212           offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2213                      * tree_low_cst (TREE_OPERAND (target, 1), 0));
2214           target = TREE_OPERAND (target, 0);
2215         }
2216       else
2217         break;
2218     }
2219
2220   switch (TREE_CODE (target))
2221     {
2222     case VAR_DECL:
2223     case FUNCTION_DECL:
2224       x = DECL_RTL (target);
2225       break;
2226
2227     case LABEL_DECL:
2228       x = gen_rtx_MEM (FUNCTION_MODE,
2229                        gen_rtx_LABEL_REF (VOIDmode, force_label_rtx (target)));
2230       break;
2231
2232     case REAL_CST:
2233     case STRING_CST:
2234     case COMPLEX_CST:
2235     case CONSTRUCTOR:
2236     case INTEGER_CST:
2237       x = output_constant_def (target, 1);
2238       break;
2239
2240     default:
2241       gcc_unreachable ();
2242     }
2243
2244   gcc_assert (MEM_P (x));
2245   x = XEXP (x, 0);
2246
2247   value->base = x;
2248   value->offset = offset;
2249 }
2250 \f
2251 /* Uniquize all constants that appear in memory.
2252    Each constant in memory thus far output is recorded
2253    in `const_desc_table'.  */
2254
2255 struct constant_descriptor_tree GTY(())
2256 {
2257   /* A MEM for the constant.  */
2258   rtx rtl;
2259
2260   /* The value of the constant.  */
2261   tree value;
2262 };
2263
2264 static GTY((param_is (struct constant_descriptor_tree)))
2265      htab_t const_desc_htab;
2266
2267 static struct constant_descriptor_tree * build_constant_desc (tree);
2268 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2269
2270 /* Compute a hash code for a constant expression.  */
2271
2272 static hashval_t
2273 const_desc_hash (const void *ptr)
2274 {
2275   return const_hash_1 (((struct constant_descriptor_tree *)ptr)->value);
2276 }
2277
2278 static hashval_t
2279 const_hash_1 (const tree exp)
2280 {
2281   const char *p;
2282   hashval_t hi;
2283   int len, i;
2284   enum tree_code code = TREE_CODE (exp);
2285
2286   /* Either set P and LEN to the address and len of something to hash and
2287      exit the switch or return a value.  */
2288
2289   switch (code)
2290     {
2291     case INTEGER_CST:
2292       p = (char *) &TREE_INT_CST (exp);
2293       len = sizeof TREE_INT_CST (exp);
2294       break;
2295
2296     case REAL_CST:
2297       return real_hash (TREE_REAL_CST_PTR (exp));
2298
2299     case STRING_CST:
2300       p = TREE_STRING_POINTER (exp);
2301       len = TREE_STRING_LENGTH (exp);
2302       break;
2303
2304     case COMPLEX_CST:
2305       return (const_hash_1 (TREE_REALPART (exp)) * 5
2306               + const_hash_1 (TREE_IMAGPART (exp)));
2307
2308     case CONSTRUCTOR:
2309       {
2310         tree link;
2311         
2312         hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2313         
2314         for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2315           if (TREE_VALUE (link))
2316             hi = hi * 603 + const_hash_1 (TREE_VALUE (link));
2317         
2318         return hi;
2319       }
2320
2321     case ADDR_EXPR:
2322     case FDESC_EXPR:
2323       {
2324         struct addr_const value;
2325
2326         decode_addr_const (exp, &value);
2327         switch (GET_CODE (value.base))
2328           {
2329           case SYMBOL_REF:
2330             /* Don't hash the address of the SYMBOL_REF;
2331                only use the offset and the symbol name.  */
2332             hi = value.offset;
2333             p = XSTR (value.base, 0);
2334             for (i = 0; p[i] != 0; i++)
2335               hi = ((hi * 613) + (unsigned) (p[i]));
2336             break;
2337
2338           case LABEL_REF:
2339             hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2340             break;
2341
2342           default:
2343             gcc_unreachable ();
2344           }
2345       }
2346       return hi;
2347
2348     case PLUS_EXPR:
2349     case MINUS_EXPR:
2350       return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2351               + const_hash_1 (TREE_OPERAND (exp, 1)));
2352
2353     case NOP_EXPR:
2354     case CONVERT_EXPR:
2355     case NON_LVALUE_EXPR:
2356       return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2357
2358     default:
2359       /* A language specific constant. Just hash the code.  */
2360       return code;
2361     }
2362
2363   /* Compute hashing function.  */
2364   hi = len;
2365   for (i = 0; i < len; i++)
2366     hi = ((hi * 613) + (unsigned) (p[i]));
2367
2368   return hi;
2369 }
2370
2371 /* Wrapper of compare_constant, for the htab interface.  */
2372 static int
2373 const_desc_eq (const void *p1, const void *p2)
2374 {
2375   return compare_constant (((struct constant_descriptor_tree *)p1)->value,
2376                            ((struct constant_descriptor_tree *)p2)->value);
2377 }
2378
2379 /* Compare t1 and t2, and return 1 only if they are known to result in
2380    the same bit pattern on output.  */
2381
2382 static int
2383 compare_constant (const tree t1, const tree t2)
2384 {
2385   enum tree_code typecode;
2386
2387   if (t1 == NULL_TREE)
2388     return t2 == NULL_TREE;
2389   if (t2 == NULL_TREE)
2390     return 0;
2391
2392   if (TREE_CODE (t1) != TREE_CODE (t2))
2393     return 0;
2394
2395   switch (TREE_CODE (t1))
2396     {
2397     case INTEGER_CST:
2398       /* Integer 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       return tree_int_cst_equal (t1, t2);
2402
2403     case REAL_CST:
2404       /* Real constants are the same only if the same width of type.  */
2405       if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2406         return 0;
2407
2408       return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2409
2410     case STRING_CST:
2411       if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2412         return 0;
2413
2414       return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2415               && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2416                          TREE_STRING_LENGTH (t1)));
2417
2418     case COMPLEX_CST:
2419       return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2420               && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2421
2422     case CONSTRUCTOR:
2423       {
2424         tree l1, l2;
2425         
2426         typecode = TREE_CODE (TREE_TYPE (t1));
2427         if (typecode != TREE_CODE (TREE_TYPE (t2)))
2428           return 0;
2429
2430         if (typecode == ARRAY_TYPE)
2431           {
2432             HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2433             /* For arrays, check that the sizes all match.  */
2434             if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2435                 || size_1 == -1
2436                 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2437               return 0;
2438           }
2439         else
2440           {
2441             /* For record and union constructors, require exact type
2442                equality.  */
2443             if (TREE_TYPE (t1) != TREE_TYPE (t2))
2444               return 0;
2445           }
2446
2447         for (l1 = CONSTRUCTOR_ELTS (t1), l2 = CONSTRUCTOR_ELTS (t2);
2448              l1 && l2;
2449              l1 = TREE_CHAIN (l1), l2 = TREE_CHAIN (l2))
2450           {
2451             /* Check that each value is the same...  */
2452             if (! compare_constant (TREE_VALUE (l1), TREE_VALUE (l2)))
2453               return 0;
2454             /* ... and that they apply to the same fields!  */
2455             if (typecode == ARRAY_TYPE)
2456               {
2457                 if (! compare_constant (TREE_PURPOSE (l1),
2458                                         TREE_PURPOSE (l2)))
2459                   return 0;
2460               }
2461             else
2462               {
2463                 if (TREE_PURPOSE (l1) != TREE_PURPOSE (l2))
2464                   return 0;
2465               }
2466           }
2467         
2468         return l1 == NULL_TREE && l2 == NULL_TREE;
2469       }
2470
2471     case ADDR_EXPR:
2472     case FDESC_EXPR:
2473       {
2474         struct addr_const value1, value2;
2475
2476         decode_addr_const (t1, &value1);
2477         decode_addr_const (t2, &value2);
2478         return (value1.offset == value2.offset
2479                 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2480       }
2481
2482     case PLUS_EXPR:
2483     case MINUS_EXPR:
2484     case RANGE_EXPR:
2485       return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2486               && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2487
2488     case NOP_EXPR:
2489     case CONVERT_EXPR:
2490     case NON_LVALUE_EXPR:
2491     case VIEW_CONVERT_EXPR:
2492       return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2493
2494     default:
2495       {
2496         tree nt1, nt2;
2497         nt1 = lang_hooks.expand_constant (t1);
2498         nt2 = lang_hooks.expand_constant (t2);
2499         if (nt1 != t1 || nt2 != t2)
2500           return compare_constant (nt1, nt2);
2501         else
2502           return 0;
2503       }
2504     }
2505
2506   gcc_unreachable ();
2507 }
2508 \f
2509 /* Make a copy of the whole tree structure for a constant.  This
2510    handles the same types of nodes that compare_constant handles.  */
2511
2512 static tree
2513 copy_constant (tree exp)
2514 {
2515   switch (TREE_CODE (exp))
2516     {
2517     case ADDR_EXPR:
2518       /* For ADDR_EXPR, we do not want to copy the decl whose address
2519          is requested.  We do want to copy constants though.  */
2520       if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
2521         return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2522                        copy_constant (TREE_OPERAND (exp, 0)));
2523       else
2524         return copy_node (exp);
2525
2526     case INTEGER_CST:
2527     case REAL_CST:
2528     case STRING_CST:
2529       return copy_node (exp);
2530
2531     case COMPLEX_CST:
2532       return build_complex (TREE_TYPE (exp),
2533                             copy_constant (TREE_REALPART (exp)),
2534                             copy_constant (TREE_IMAGPART (exp)));
2535
2536     case PLUS_EXPR:
2537     case MINUS_EXPR:
2538       return build2 (TREE_CODE (exp), TREE_TYPE (exp),
2539                      copy_constant (TREE_OPERAND (exp, 0)),
2540                      copy_constant (TREE_OPERAND (exp, 1)));
2541
2542     case NOP_EXPR:
2543     case CONVERT_EXPR:
2544     case NON_LVALUE_EXPR:
2545     case VIEW_CONVERT_EXPR:
2546       return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2547                      copy_constant (TREE_OPERAND (exp, 0)));
2548
2549     case CONSTRUCTOR:
2550       {
2551         tree copy = copy_node (exp);
2552         tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2553         tree tail;
2554
2555         CONSTRUCTOR_ELTS (copy) = list;
2556         for (tail = list; tail; tail = TREE_CHAIN (tail))
2557           TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2558
2559         return copy;
2560       }
2561
2562     default:
2563       {
2564         tree t = lang_hooks.expand_constant (exp);
2565         
2566         gcc_assert (t == exp);
2567         return copy_constant (t);
2568       }
2569     }
2570 }
2571 \f
2572 /* Subroutine of output_constant_def:
2573    No constant equal to EXP is known to have been output.
2574    Make a constant descriptor to enter EXP in the hash table.
2575    Assign the label number and construct RTL to refer to the
2576    constant's location in memory.
2577    Caller is responsible for updating the hash table.  */
2578
2579 static struct constant_descriptor_tree *
2580 build_constant_desc (tree exp)
2581 {
2582   rtx symbol;
2583   rtx rtl;
2584   char label[256];
2585   int labelno;
2586   struct constant_descriptor_tree *desc;
2587
2588   desc = ggc_alloc (sizeof (*desc));
2589   desc->value = copy_constant (exp);
2590
2591   /* Propagate marked-ness to copied constant.  */
2592   if (flag_mudflap && mf_marked_p (exp))
2593     mf_mark (desc->value);
2594
2595   /* Create a string containing the label name, in LABEL.  */
2596   labelno = const_labelno++;
2597   ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2598
2599   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
2600   symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2601   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2602   SYMBOL_REF_DECL (symbol) = desc->value;
2603   TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2604
2605   rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2606   set_mem_attributes (rtl, exp, 1);
2607   set_mem_alias_set (rtl, 0);
2608   set_mem_alias_set (rtl, const_alias_set);
2609
2610   /* Set flags or add text to the name to record information, such as
2611      that it is a local symbol.  If the name is changed, the macro
2612      ASM_OUTPUT_LABELREF will have to know how to strip this
2613      information.  This call might invalidate our local variable
2614      SYMBOL; we can't use it afterward.  */
2615
2616   targetm.encode_section_info (exp, rtl, true);
2617
2618   desc->rtl = rtl;
2619
2620   return desc;
2621 }
2622
2623 /* Return an rtx representing a reference to constant data in memory
2624    for the constant expression EXP.
2625
2626    If assembler code for such a constant has already been output,
2627    return an rtx to refer to it.
2628    Otherwise, output such a constant in memory
2629    and generate an rtx for it.
2630
2631    If DEFER is nonzero, this constant can be deferred and output only
2632    if referenced in the function after all optimizations.
2633
2634    `const_desc_table' records which constants already have label strings.  */
2635
2636 rtx
2637 output_constant_def (tree exp, int defer)
2638 {
2639   struct constant_descriptor_tree *desc;
2640   struct constant_descriptor_tree key;
2641   void **loc;
2642
2643   /* Look up EXP in the table of constant descriptors.  If we didn't find
2644      it, create a new one.  */
2645   key.value = exp;
2646   loc = htab_find_slot (const_desc_htab, &key, INSERT);
2647
2648   desc = *loc;
2649   if (desc == 0)
2650     {
2651       desc = build_constant_desc (exp);
2652       *loc = desc;
2653     }
2654
2655   maybe_output_constant_def_contents (desc, defer);
2656   return desc->rtl;
2657 }
2658
2659 /* Subroutine of output_constant_def: Decide whether or not we need to
2660    output the constant DESC now, and if so, do it.  */
2661 static void
2662 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
2663                                     int defer)
2664 {
2665   rtx symbol = XEXP (desc->rtl, 0);
2666   tree exp = desc->value;
2667
2668   if (flag_syntax_only)
2669     return;
2670
2671   if (TREE_ASM_WRITTEN (exp))
2672     /* Already output; don't do it again.  */
2673     return;
2674
2675   /* We can always defer constants as long as the context allows
2676      doing so.  */
2677   if (defer)
2678     {
2679       /* Increment n_deferred_constants if it exists.  It needs to be at
2680          least as large as the number of constants actually referred to
2681          by the function.  If it's too small we'll stop looking too early
2682          and fail to emit constants; if it's too large we'll only look
2683          through the entire function when we could have stopped earlier.  */
2684       if (cfun)
2685         n_deferred_constants++;
2686       return;
2687     }
2688
2689   output_constant_def_contents (symbol);
2690 }
2691
2692 /* We must output the constant data referred to by SYMBOL; do so.  */
2693
2694 static void
2695 output_constant_def_contents (rtx symbol)
2696 {
2697   tree exp = SYMBOL_REF_DECL (symbol);
2698   const char *label = XSTR (symbol, 0);
2699   HOST_WIDE_INT size;
2700
2701   /* Make sure any other constants whose addresses appear in EXP
2702      are assigned label numbers.  */
2703   int reloc = compute_reloc_for_constant (exp);
2704
2705   /* Align the location counter as required by EXP's data type.  */
2706   unsigned int align = TYPE_ALIGN (TREE_TYPE (exp));
2707 #ifdef CONSTANT_ALIGNMENT
2708   align = CONSTANT_ALIGNMENT (exp, align);
2709 #endif
2710
2711   output_addressed_constants (exp);
2712
2713   /* We are no longer deferring this constant.  */
2714   TREE_ASM_WRITTEN (exp) = 1;
2715
2716   if (IN_NAMED_SECTION (exp))
2717     named_section (exp, NULL, reloc);
2718   else
2719     targetm.asm_out.select_section (exp, reloc, align);
2720
2721   if (align > BITS_PER_UNIT)
2722     {
2723       ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2724     }
2725
2726   size = int_size_in_bytes (TREE_TYPE (exp));
2727   if (TREE_CODE (exp) == STRING_CST)
2728     size = MAX (TREE_STRING_LENGTH (exp), size);
2729
2730   /* Do any machine/system dependent processing of the constant.  */
2731 #ifdef ASM_DECLARE_CONSTANT_NAME
2732   ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
2733 #else
2734   /* Standard thing is just output label for the constant.  */
2735   ASM_OUTPUT_LABEL (asm_out_file, label);
2736 #endif /* ASM_DECLARE_CONSTANT_NAME */
2737
2738   /* Output the value of EXP.  */
2739   output_constant (exp, size, align);
2740   if (flag_mudflap)
2741     mudflap_enqueue_constant (exp);
2742 }
2743
2744 /* Look up EXP in the table of constant descriptors.  Return the rtl
2745    if it has been emitted, else null.  */
2746
2747 rtx
2748 lookup_constant_def (tree exp)
2749 {
2750   struct constant_descriptor_tree *desc;
2751   struct constant_descriptor_tree key;
2752
2753   key.value = exp;
2754   desc = htab_find (const_desc_htab, &key);
2755
2756   return (desc ? desc->rtl : NULL_RTX);
2757 }
2758 \f
2759 /* Used in the hash tables to avoid outputting the same constant
2760    twice.  Unlike 'struct constant_descriptor_tree', RTX constants
2761    are output once per function, not once per file.  */
2762 /* ??? Only a few targets need per-function constant pools.  Most
2763    can use one per-file pool.  Should add a targetm bit to tell the
2764    difference.  */
2765
2766 struct rtx_constant_pool GTY(())
2767 {
2768   /* Pointers to first and last constant in pool, as ordered by offset.  */
2769   struct constant_descriptor_rtx *first;
2770   struct constant_descriptor_rtx *last;
2771
2772   /* Hash facility for making memory-constants from constant rtl-expressions.
2773      It is used on RISC machines where immediate integer arguments and
2774      constant addresses are restricted so that such constants must be stored
2775      in memory.  */
2776   htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
2777   htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_sym_htab;
2778
2779   /* Current offset in constant pool (does not include any
2780      machine-specific header).  */
2781   HOST_WIDE_INT offset;
2782 };
2783
2784 struct constant_descriptor_rtx GTY((chain_next ("%h.next")))
2785 {
2786   struct constant_descriptor_rtx *next;
2787   rtx mem;
2788   rtx sym;
2789   rtx constant;
2790   HOST_WIDE_INT offset;
2791   hashval_t hash;
2792   enum machine_mode mode;
2793   unsigned int align;
2794   int labelno;
2795   int mark;
2796 };
2797
2798 /* Hash and compare functions for const_rtx_htab.  */
2799
2800 static hashval_t
2801 const_desc_rtx_hash (const void *ptr)
2802 {
2803   const struct constant_descriptor_rtx *desc = ptr;
2804   return desc->hash;
2805 }
2806
2807 static int
2808 const_desc_rtx_eq (const void *a, const void *b)
2809 {
2810   const struct constant_descriptor_rtx *x = a;
2811   const struct constant_descriptor_rtx *y = b;
2812
2813   if (x->mode != y->mode)
2814     return 0;
2815   return rtx_equal_p (x->constant, y->constant);
2816 }
2817
2818 /* Hash and compare functions for const_rtx_sym_htab.  */
2819
2820 static hashval_t
2821 const_desc_rtx_sym_hash (const void *ptr)
2822 {
2823   const struct constant_descriptor_rtx *desc = ptr;
2824   return htab_hash_string (XSTR (desc->sym, 0));
2825 }
2826
2827 static int
2828 const_desc_rtx_sym_eq (const void *a, const void *b)
2829 {
2830   const struct constant_descriptor_rtx *x = a;
2831   const struct constant_descriptor_rtx *y = b;
2832   return XSTR (x->sym, 0) == XSTR (y->sym, 0);
2833 }
2834
2835 /* This is the worker function for const_rtx_hash, called via for_each_rtx.  */
2836
2837 static int
2838 const_rtx_hash_1 (rtx *xp, void *data)
2839 {
2840   unsigned HOST_WIDE_INT hwi;
2841   enum machine_mode mode;
2842   enum rtx_code code;
2843   hashval_t h, *hp;
2844   rtx x;
2845
2846   x = *xp;
2847   code = GET_CODE (x);
2848   mode = GET_MODE (x);
2849   h = (hashval_t) code * 1048573 + mode;
2850
2851   switch (code)
2852     {
2853     case CONST_INT:
2854       hwi = INTVAL (x);
2855     fold_hwi:
2856       {
2857         const int shift = sizeof (hashval_t) * CHAR_BIT;
2858         const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
2859         int i;
2860
2861         h ^= (hashval_t) hwi;
2862         for (i = 1; i < n; ++i)
2863           {
2864             hwi >>= shift;
2865             h ^= (hashval_t) hwi;
2866           }
2867       }
2868       break;
2869
2870     case CONST_DOUBLE:
2871       if (mode == VOIDmode)
2872         {
2873           hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
2874           goto fold_hwi;
2875         }
2876       else
2877         h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
2878       break;
2879
2880     case CONST_VECTOR:
2881       {
2882         int i;
2883         for (i = XVECLEN (x, 0); i-- > 0; )
2884           h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
2885       }
2886       break;
2887
2888     case SYMBOL_REF:
2889       h ^= htab_hash_string (XSTR (x, 0));
2890       break;
2891
2892     case LABEL_REF:
2893       h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
2894       break;
2895
2896     case UNSPEC:
2897     case UNSPEC_VOLATILE:
2898       h = h * 251 + XINT (x, 1);
2899       break;
2900
2901     default:
2902       break;
2903     }
2904
2905   hp = data;
2906   *hp = *hp * 509 + h;
2907   return 0;
2908 }
2909
2910 /* Compute a hash value for X, which should be a constant.  */
2911
2912 static hashval_t
2913 const_rtx_hash (rtx x)
2914 {
2915   hashval_t h = 0;
2916   for_each_rtx (&x, const_rtx_hash_1, &h);
2917   return h;
2918 }
2919
2920 \f
2921 /* Initialize constant pool hashing for a new function.  */
2922
2923 void
2924 init_varasm_status (struct function *f)
2925 {
2926   struct varasm_status *p;
2927   struct rtx_constant_pool *pool;
2928
2929   p = ggc_alloc (sizeof (struct varasm_status));
2930   f->varasm = p;
2931
2932   pool = ggc_alloc (sizeof (struct rtx_constant_pool));
2933   p->pool = pool;
2934   p->deferred_constants = 0;
2935
2936   pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
2937                                           const_desc_rtx_eq, NULL);
2938   pool->const_rtx_sym_htab = htab_create_ggc (31, const_desc_rtx_sym_hash,
2939                                               const_desc_rtx_sym_eq, NULL);
2940   pool->first = pool->last = NULL;
2941   pool->offset = 0;
2942 }
2943 \f
2944 /* Given a MINUS expression, simplify it if both sides
2945    include the same symbol.  */
2946
2947 rtx
2948 simplify_subtraction (rtx x)
2949 {
2950   rtx r = simplify_rtx (x);
2951   return r ? r : x;
2952 }
2953 \f
2954 /* Given a constant rtx X, make (or find) a memory constant for its value
2955    and return a MEM rtx to refer to it in memory.  */
2956
2957 rtx
2958 force_const_mem (enum machine_mode mode, rtx x)
2959 {
2960   struct constant_descriptor_rtx *desc, tmp;
2961   struct rtx_constant_pool *pool = cfun->varasm->pool;
2962   char label[256];
2963   rtx def, symbol;
2964   hashval_t hash;
2965   unsigned int align;
2966   void **slot;
2967
2968   /* If we're not allowed to drop X into the constant pool, don't.  */
2969   if (targetm.cannot_force_const_mem (x))
2970     return NULL_RTX;
2971
2972   /* Lookup the value in the hashtable.  */
2973   tmp.constant = x;
2974   tmp.mode = mode;
2975   hash = const_rtx_hash (x);
2976   slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
2977   desc = *slot;
2978   
2979   /* If the constant was already present, return its memory.  */
2980   if (desc)
2981     return copy_rtx (desc->mem);
2982
2983   /* Otherwise, create a new descriptor.  */
2984   desc = ggc_alloc (sizeof (*desc));
2985   *slot = desc;
2986
2987   /* Align the location counter as required by EXP's data type.  */
2988   align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
2989 #ifdef CONSTANT_ALIGNMENT
2990   {
2991     tree type = lang_hooks.types.type_for_mode (mode, 0);
2992     if (type != NULL_TREE)
2993       align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
2994   }
2995 #endif
2996
2997   pool->offset += (align / BITS_PER_UNIT) - 1;
2998   pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
2999
3000   desc->next = NULL;
3001   desc->constant = tmp.constant;
3002   desc->offset = pool->offset;
3003   desc->hash = hash;
3004   desc->mode = mode;
3005   desc->align = align;
3006   desc->labelno = const_labelno;
3007   desc->mark = 0;
3008
3009   pool->offset += GET_MODE_SIZE (mode);
3010   if (pool->last)
3011     pool->last->next = desc;
3012   else
3013     pool->first = pool->last = desc;
3014   pool->last = desc;
3015
3016   /* Create a string containing the label name, in LABEL.  */
3017   ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3018   ++const_labelno;
3019
3020   /* Construct the SYMBOL_REF.  Make sure to mark it as belonging to
3021      the constants pool.  */
3022   desc->sym = symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3023   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
3024   CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3025   current_function_uses_const_pool = 1;
3026
3027   /* Insert the descriptor into the symbol cross-reference table too.  */
3028   slot = htab_find_slot (pool->const_rtx_sym_htab, desc, INSERT);
3029   gcc_assert (!*slot);
3030   *slot = desc;
3031
3032   /* Construct the MEM.  */
3033   desc->mem = def = gen_const_mem (mode, symbol);
3034   set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3035   set_mem_align (def, align);
3036
3037   /* If we're dropping a label to the constant pool, make sure we
3038      don't delete it.  */
3039   if (GET_CODE (x) == LABEL_REF)
3040     LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3041
3042   return copy_rtx (def);
3043 }
3044 \f
3045 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3046    the corresponding constant_descriptor_rtx structure.  */
3047
3048 static struct constant_descriptor_rtx *
3049 find_pool_constant (struct rtx_constant_pool *pool, rtx sym)
3050 {
3051   struct constant_descriptor_rtx tmp;
3052   tmp.sym = sym;
3053   return htab_find (pool->const_rtx_sym_htab, &tmp);
3054 }
3055
3056 /* Given a constant pool SYMBOL_REF, return the corresponding constant.  */
3057
3058 rtx
3059 get_pool_constant (rtx addr)
3060 {
3061   return find_pool_constant (cfun->varasm->pool, addr)->constant;
3062 }
3063
3064 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3065    and whether it has been output or not.  */
3066
3067 rtx
3068 get_pool_constant_mark (rtx addr, bool *pmarked)
3069 {
3070   struct constant_descriptor_rtx *desc;
3071
3072   desc = find_pool_constant (cfun->varasm->pool, addr);
3073   *pmarked = (desc->mark != 0);
3074   return desc->constant;
3075 }
3076
3077 /* Likewise, but for the constant pool of a specific function.  */
3078
3079 rtx
3080 get_pool_constant_for_function (struct function *f, rtx addr)
3081 {
3082   return find_pool_constant (f->varasm->pool, addr)->constant;
3083 }
3084
3085 /* Similar, return the mode.  */
3086
3087 enum machine_mode
3088 get_pool_mode (rtx addr)
3089 {
3090   return find_pool_constant (cfun->varasm->pool, addr)->mode;
3091 }
3092
3093 /* Return the size of the constant pool.  */
3094
3095 int
3096 get_pool_size (void)
3097 {
3098   return cfun->varasm->pool->offset;
3099 }
3100 \f
3101 /* Worker function for output_constant_pool_1.  Emit assembly for X
3102    in MODE with known alignment ALIGN.  */
3103
3104 static void
3105 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3106 {
3107   switch (GET_MODE_CLASS (mode))
3108     {
3109     case MODE_FLOAT:
3110       {
3111         REAL_VALUE_TYPE r;
3112         
3113         gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3114         REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3115         assemble_real (r, mode, align);
3116         break;
3117       }
3118       
3119     case MODE_INT:
3120     case MODE_PARTIAL_INT:
3121       assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3122       break;
3123
3124     case MODE_VECTOR_FLOAT:
3125     case MODE_VECTOR_INT:
3126       {
3127         int i, units;
3128         enum machine_mode submode = GET_MODE_INNER (mode);
3129         unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3130
3131         gcc_assert (GET_CODE (x) == CONST_VECTOR);
3132         units = CONST_VECTOR_NUNITS (x);
3133
3134         for (i = 0; i < units; i++)
3135           {
3136             rtx elt = CONST_VECTOR_ELT (x, i);
3137             output_constant_pool_2 (submode, elt, i ? subalign : align);
3138           }
3139       }
3140       break;
3141
3142     default:
3143       gcc_unreachable ();
3144     }
3145 }
3146
3147 /* Worker function for output_constant_pool.  Emit POOL.  */
3148
3149 static void
3150 output_constant_pool_1 (struct constant_descriptor_rtx *desc)
3151 {
3152   rtx x, tmp;
3153
3154   if (!desc->mark)
3155     return;
3156   x = desc->constant;
3157
3158   /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3159      whose CODE_LABEL has been deleted.  This can occur if a jump table
3160      is eliminated by optimization.  If so, write a constant of zero
3161      instead.  Note that this can also happen by turning the
3162      CODE_LABEL into a NOTE.  */
3163   /* ??? This seems completely and utterly wrong.  Certainly it's
3164      not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3165      functioning even with INSN_DELETED_P and friends.  */
3166
3167   tmp = x;
3168   switch (GET_CODE (x))
3169     {
3170     case CONST:
3171       if (GET_CODE (XEXP (x, 0)) != PLUS
3172           || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3173         break;
3174       tmp = XEXP (XEXP (x, 0), 0);
3175       /* FALLTHRU  */
3176
3177     case LABEL_REF:
3178       tmp = XEXP (x, 0);
3179       gcc_assert (!INSN_DELETED_P (tmp));
3180       gcc_assert (!NOTE_P (tmp)
3181                   || NOTE_LINE_NUMBER (tmp) != NOTE_INSN_DELETED);
3182       break;
3183
3184     default:
3185       break;
3186     }
3187
3188   /* First switch to correct section.  */
3189   targetm.asm_out.select_rtx_section (desc->mode, x, desc->align);
3190
3191 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3192   ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3193                                  desc->align, desc->labelno, done);
3194 #endif
3195
3196   assemble_align (desc->align);
3197
3198   /* Output the label.  */
3199   targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3200
3201   /* Output the data.  */
3202   output_constant_pool_2 (desc->mode, x, desc->align);
3203
3204   /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3205      sections have proper size.  */
3206   if (desc->align > GET_MODE_BITSIZE (desc->mode)
3207       && in_section == in_named
3208       && get_named_section_flags (in_named_name) & SECTION_MERGE)
3209     assemble_align (desc->align);
3210
3211 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3212  done:
3213 #endif
3214   return;
3215 }
3216
3217 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3218    to as used.  Emit referenced deferred strings.  This function can
3219    be used with for_each_rtx to mark all SYMBOL_REFs in an rtx.  */
3220
3221 static int
3222 mark_constant (rtx *current_rtx, void *data)
3223 {
3224   struct rtx_constant_pool *pool = data;
3225   rtx x = *current_rtx;
3226
3227   if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3228     return 0;
3229
3230   if (CONSTANT_POOL_ADDRESS_P (x))
3231     {
3232       struct constant_descriptor_rtx *desc = find_pool_constant (pool, x);
3233       if (desc->mark == 0)
3234         {
3235           desc->mark = 1;
3236           for_each_rtx (&desc->constant, mark_constant, pool);
3237         }
3238     }
3239   else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3240     {
3241       tree exp = SYMBOL_REF_DECL (x);
3242       if (!TREE_ASM_WRITTEN (exp))
3243         {
3244           n_deferred_constants--;
3245           output_constant_def_contents (x);
3246         }
3247     }
3248
3249   return -1;
3250
3251
3252 /* Look through appropriate parts of INSN, marking all entries in the
3253    constant pool which are actually being used.  Entries that are only
3254    referenced by other constants are also marked as used.  Emit
3255    deferred strings that are used.  */
3256
3257 static void
3258 mark_constants (struct rtx_constant_pool *pool, rtx insn)
3259 {
3260   if (!INSN_P (insn))
3261     return;
3262
3263   /* Insns may appear inside a SEQUENCE.  Only check the patterns of
3264      insns, not any notes that may be attached.  We don't want to mark
3265      a constant just because it happens to appear in a REG_EQUIV note.  */
3266   if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3267     {
3268       rtx seq = PATTERN (insn);
3269       int i, n = XVECLEN (seq, 0);
3270       for (i = 0; i < n; ++i)
3271         {
3272           rtx subinsn = XVECEXP (seq, 0, i);
3273           if (INSN_P (subinsn))
3274             for_each_rtx (&PATTERN (subinsn), mark_constant, pool);
3275         }
3276     }
3277   else
3278     for_each_rtx (&PATTERN (insn), mark_constant, pool);
3279 }
3280
3281 /* Look through the instructions for this function, and mark all the
3282    entries in POOL which are actually being used.  Emit deferred constants
3283    which have indeed been used.  */
3284
3285 static void
3286 mark_constant_pool (struct rtx_constant_pool *pool)
3287 {
3288   rtx insn, link;
3289
3290   if (pool->first == 0 && n_deferred_constants == 0)
3291     return;
3292
3293   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3294     mark_constants (pool, insn);
3295
3296   for (link = current_function_epilogue_delay_list;
3297        link;
3298        link = XEXP (link, 1))
3299     mark_constants (pool, XEXP (link, 0));
3300 }
3301
3302 /* Write all the constants in the constant pool.  */
3303
3304 void
3305 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3306                       tree fndecl ATTRIBUTE_UNUSED)
3307 {
3308   struct rtx_constant_pool *pool = cfun->varasm->pool;
3309   struct constant_descriptor_rtx *desc;
3310
3311   /* It is possible for gcc to call force_const_mem and then to later
3312      discard the instructions which refer to the constant.  In such a
3313      case we do not need to output the constant.  */
3314   mark_constant_pool (pool);
3315
3316 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3317   ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3318 #endif
3319
3320   for (desc = pool->first; desc ; desc = desc->next)
3321     output_constant_pool_1 (desc);
3322
3323 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3324   ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3325 #endif
3326 }
3327 \f
3328 /* Determine what kind of relocations EXP may need.  */
3329
3330 int
3331 compute_reloc_for_constant (tree exp)
3332 {
3333   int reloc = 0, reloc2;
3334   tree tem;
3335
3336   /* Give the front-end a chance to convert VALUE to something that
3337      looks more like a constant to the back-end.  */
3338   exp = lang_hooks.expand_constant (exp);
3339
3340   switch (TREE_CODE (exp))
3341     {
3342     case ADDR_EXPR:
3343     case FDESC_EXPR:
3344       /* Go inside any operations that get_inner_reference can handle and see
3345          if what's inside is a constant: no need to do anything here for
3346          addresses of variables or functions.  */
3347       for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3348            tem = TREE_OPERAND (tem, 0))
3349         ;
3350
3351       if (TREE_PUBLIC (tem))
3352         reloc |= 2;
3353       else
3354         reloc |= 1;
3355       break;
3356
3357     case PLUS_EXPR:
3358       reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3359       reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3360       break;
3361
3362     case MINUS_EXPR:
3363       reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3364       reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3365       /* The difference of two local labels is computable at link time.  */
3366       if (reloc == 1 && reloc2 == 1)
3367         reloc = 0;
3368       else
3369         reloc |= reloc2;
3370       break;
3371
3372     case NOP_EXPR:
3373     case CONVERT_EXPR:
3374     case NON_LVALUE_EXPR:
3375       reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3376       break;
3377
3378     case CONSTRUCTOR:
3379       for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3380         if (TREE_VALUE (tem) != 0)
3381           reloc |= compute_reloc_for_constant (TREE_VALUE (tem));
3382
3383       break;
3384
3385     default:
3386       break;
3387     }
3388   return reloc;
3389 }
3390
3391 /* Find all the constants whose addresses are referenced inside of EXP,
3392    and make sure assembler code with a label has been output for each one.
3393    Indicate whether an ADDR_EXPR has been encountered.  */
3394
3395 static void
3396 output_addressed_constants (tree exp)
3397 {
3398   tree tem;
3399
3400   /* Give the front-end a chance to convert VALUE to something that
3401      looks more like a constant to the back-end.  */
3402   exp = lang_hooks.expand_constant (exp);
3403
3404   switch (TREE_CODE (exp))
3405     {
3406     case ADDR_EXPR:
3407     case FDESC_EXPR:
3408       /* Go inside any operations that get_inner_reference can handle and see
3409          if what's inside is a constant: no need to do anything here for
3410          addresses of variables or functions.  */
3411       for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3412            tem = TREE_OPERAND (tem, 0))
3413         ;
3414
3415       /* If we have an initialized CONST_DECL, retrieve the initializer.  */
3416       if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
3417         tem = DECL_INITIAL (tem);
3418
3419       if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
3420         output_constant_def (tem, 0);
3421       break;
3422
3423     case PLUS_EXPR:
3424     case MINUS_EXPR:
3425       output_addressed_constants (TREE_OPERAND (exp, 1));
3426       /* Fall through.  */
3427
3428     case NOP_EXPR:
3429     case CONVERT_EXPR:
3430     case NON_LVALUE_EXPR:
3431       output_addressed_constants (TREE_OPERAND (exp, 0));
3432       break;
3433
3434     case CONSTRUCTOR:
3435       for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3436         if (TREE_VALUE (tem) != 0)
3437           output_addressed_constants (TREE_VALUE (tem));
3438
3439       break;
3440
3441     default:
3442       break;
3443     }
3444 }
3445 \f
3446 /* Return nonzero if VALUE is a valid constant-valued expression
3447    for use in initializing a static variable; one that can be an
3448    element of a "constant" initializer.
3449
3450    Return null_pointer_node if the value is absolute;
3451    if it is relocatable, return the variable that determines the relocation.
3452    We assume that VALUE has been folded as much as possible;
3453    therefore, we do not need to check for such things as
3454    arithmetic-combinations of integers.  */
3455
3456 tree
3457 initializer_constant_valid_p (tree value, tree endtype)
3458 {
3459   /* Give the front-end a chance to convert VALUE to something that
3460      looks more like a constant to the back-end.  */
3461   value = lang_hooks.expand_constant (value);
3462
3463   switch (TREE_CODE (value))
3464     {
3465     case CONSTRUCTOR:
3466       if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
3467            || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
3468           && TREE_CONSTANT (value)
3469           && CONSTRUCTOR_ELTS (value))
3470         {
3471           tree elt;
3472           bool absolute = true;
3473
3474           for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt))
3475             {
3476               tree reloc;
3477               value = TREE_VALUE (elt);
3478               reloc = initializer_constant_valid_p (value, TREE_TYPE (value));
3479               if (!reloc)
3480                 return NULL_TREE;
3481               if (reloc != null_pointer_node)
3482                 absolute = false;
3483             }
3484           /* For a non-absolute relocation, there is no single
3485              variable that can be "the variable that determines the
3486              relocation."  */
3487           return absolute ? null_pointer_node : error_mark_node;
3488         }
3489
3490       return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
3491
3492     case INTEGER_CST:
3493     case VECTOR_CST:
3494     case REAL_CST:
3495     case STRING_CST:
3496     case COMPLEX_CST:
3497       return null_pointer_node;
3498
3499     case ADDR_EXPR:
3500     case FDESC_EXPR:
3501       value = staticp (TREE_OPERAND (value, 0));
3502       /* "&(*a).f" is like unto pointer arithmetic.  If "a" turns out to
3503          be a constant, this is old-skool offsetof-like nonsense.  */
3504       if (value
3505           && TREE_CODE (value) == INDIRECT_REF
3506           && TREE_CONSTANT (TREE_OPERAND (value, 0)))
3507         return null_pointer_node;
3508       /* Taking the address of a nested function involves a trampoline.  */
3509       if (value
3510           && TREE_CODE (value) == FUNCTION_DECL
3511           && ((decl_function_context (value) && !DECL_NO_STATIC_CHAIN (value))
3512               || DECL_NON_ADDR_CONST_P (value)))
3513         return NULL_TREE;
3514       return value;
3515
3516     case VIEW_CONVERT_EXPR:
3517     case NON_LVALUE_EXPR:
3518       return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3519
3520     case CONVERT_EXPR:
3521     case NOP_EXPR:
3522       {
3523         tree src;
3524         tree src_type;
3525         tree dest_type;
3526
3527         src = TREE_OPERAND (value, 0);
3528         src_type = TREE_TYPE (src);
3529         dest_type = TREE_TYPE (value);
3530
3531         /* Allow conversions between pointer types, floating-point
3532            types, and offset types.  */
3533         if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
3534             || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
3535             || (TREE_CODE (dest_type) == OFFSET_TYPE
3536                 && TREE_CODE (src_type) == OFFSET_TYPE))
3537           return initializer_constant_valid_p (src, endtype);
3538
3539         /* Allow length-preserving conversions between integer types.  */
3540         if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
3541             && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
3542           return initializer_constant_valid_p (src, endtype);
3543
3544         /* Allow conversions between other integer types only if
3545            explicit value.  */
3546         if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
3547           {
3548             tree inner = initializer_constant_valid_p (src, endtype);
3549             if (inner == null_pointer_node)
3550               return null_pointer_node;
3551             break;
3552           }
3553
3554         /* Allow (int) &foo provided int is as wide as a pointer.  */
3555         if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
3556             && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
3557           return initializer_constant_valid_p (src, endtype);
3558
3559         /* Likewise conversions from int to pointers, but also allow
3560            conversions from 0.  */
3561         if ((POINTER_TYPE_P (dest_type)
3562              || TREE_CODE (dest_type) == OFFSET_TYPE)
3563             && INTEGRAL_TYPE_P (src_type))
3564           {
3565             if (integer_zerop (src))
3566               return null_pointer_node;
3567             else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
3568               return initializer_constant_valid_p (src, endtype);
3569           }
3570
3571         /* Allow conversions to struct or union types if the value
3572            inside is okay.  */
3573         if (TREE_CODE (dest_type) == RECORD_TYPE
3574             || TREE_CODE (dest_type) == UNION_TYPE)
3575           return initializer_constant_valid_p (src, endtype);
3576       }
3577       break;
3578
3579     case PLUS_EXPR:
3580       if (! INTEGRAL_TYPE_P (endtype)
3581           || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3582         {
3583           tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3584                                                       endtype);
3585           tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3586                                                       endtype);
3587           /* If either term is absolute, use the other terms relocation.  */
3588           if (valid0 == null_pointer_node)
3589             return valid1;
3590           if (valid1 == null_pointer_node)
3591             return valid0;
3592         }
3593       break;
3594
3595     case MINUS_EXPR:
3596       if (! INTEGRAL_TYPE_P (endtype)
3597           || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3598         {
3599           tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3600                                                       endtype);
3601           tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3602                                                       endtype);
3603           /* Win if second argument is absolute.  */
3604           if (valid1 == null_pointer_node)
3605             return valid0;
3606           /* Win if both arguments have the same relocation.
3607              Then the value is absolute.  */
3608           if (valid0 == valid1 && valid0 != 0)
3609             return null_pointer_node;
3610
3611           /* Since GCC guarantees that string constants are unique in the
3612              generated code, a subtraction between two copies of the same
3613              constant string is absolute.  */
3614           if (valid0 && TREE_CODE (valid0) == STRING_CST
3615               && valid1 && TREE_CODE (valid1) == STRING_CST
3616               && operand_equal_p (valid0, valid1, 1))
3617             return null_pointer_node;
3618         }
3619
3620       /* Support narrowing differences.  */
3621       if (INTEGRAL_TYPE_P (endtype))
3622         {
3623           tree op0, op1;
3624
3625           op0 = TREE_OPERAND (value, 0);
3626           op1 = TREE_OPERAND (value, 1);
3627
3628           /* Like STRIP_NOPS except allow the operand mode to widen.
3629              This works around a feature of fold that simplifies
3630              (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3631              that the narrower operation is cheaper.  */
3632
3633           while (TREE_CODE (op0) == NOP_EXPR
3634                  || TREE_CODE (op0) == CONVERT_EXPR
3635                  || TREE_CODE (op0) == NON_LVALUE_EXPR)
3636             {
3637               tree inner = TREE_OPERAND (op0, 0);
3638               if (inner == error_mark_node
3639                   || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3640                   || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3641                       > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3642                 break;
3643               op0 = inner;
3644             }
3645
3646           while (TREE_CODE (op1) == NOP_EXPR
3647                  || TREE_CODE (op1) == CONVERT_EXPR
3648                  || TREE_CODE (op1) == NON_LVALUE_EXPR)
3649             {
3650               tree inner = TREE_OPERAND (op1, 0);
3651               if (inner == error_mark_node
3652                   || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3653                   || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3654                       > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3655                 break;
3656               op1 = inner;
3657             }
3658
3659           op0 = initializer_constant_valid_p (op0, endtype);
3660           op1 = initializer_constant_valid_p (op1, endtype);
3661
3662           /* Both initializers must be known.  */
3663           if (op0 && op1)
3664             {
3665               if (op0 == op1)
3666                 return null_pointer_node;
3667
3668               /* Support differences between labels.  */
3669               if (TREE_CODE (op0) == LABEL_DECL
3670                   && TREE_CODE (op1) == LABEL_DECL)
3671                 return null_pointer_node;
3672
3673               if (TREE_CODE (op0) == STRING_CST
3674                   && TREE_CODE (op1) == STRING_CST
3675                   && operand_equal_p (op0, op1, 1))
3676                 return null_pointer_node;
3677             }
3678         }
3679       break;
3680
3681     default:
3682       break;
3683     }
3684
3685   return 0;
3686 }
3687 \f
3688 /* Output assembler code for constant EXP to FILE, with no label.
3689    This includes the pseudo-op such as ".int" or ".byte", and a newline.
3690    Assumes output_addressed_constants has been done on EXP already.
3691
3692    Generate exactly SIZE bytes of assembler data, padding at the end
3693    with zeros if necessary.  SIZE must always be specified.
3694
3695    SIZE is important for structure constructors,
3696    since trailing members may have been omitted from the constructor.
3697    It is also important for initialization of arrays from string constants
3698    since the full length of the string constant might not be wanted.
3699    It is also needed for initialization of unions, where the initializer's
3700    type is just one member, and that may not be as long as the union.
3701
3702    There a case in which we would fail to output exactly SIZE bytes:
3703    for a structure constructor that wants to produce more than SIZE bytes.
3704    But such constructors will never be generated for any possible input.
3705
3706    ALIGN is the alignment of the data in bits.  */
3707
3708 void
3709 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
3710 {
3711   enum tree_code code;
3712   unsigned HOST_WIDE_INT thissize;
3713
3714   /* Some front-ends use constants other than the standard language-independent
3715      varieties, but which may still be output directly.  Give the front-end a
3716      chance to convert EXP to a language-independent representation.  */
3717   exp = lang_hooks.expand_constant (exp);
3718
3719   if (size == 0 || flag_syntax_only)
3720     return;
3721
3722   /* Eliminate any conversions since we'll be outputting the underlying
3723      constant.  */
3724   while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3725          || TREE_CODE (exp) == NON_LVALUE_EXPR
3726          || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
3727     exp = TREE_OPERAND (exp, 0);
3728
3729   code = TREE_CODE (TREE_TYPE (exp));
3730   thissize = int_size_in_bytes (TREE_TYPE (exp));
3731
3732   /* Allow a constructor with no elements for any data type.
3733      This means to fill the space with zeros.  */
3734   if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3735     {
3736       assemble_zeros (size);
3737       return;
3738     }
3739
3740   if (TREE_CODE (exp) == FDESC_EXPR)
3741     {
3742 #ifdef ASM_OUTPUT_FDESC
3743       HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
3744       tree decl = TREE_OPERAND (exp, 0);
3745       ASM_OUTPUT_FDESC (asm_out_file, decl, part);
3746 #else
3747       gcc_unreachable ();
3748 #endif
3749       return;
3750     }
3751
3752   /* Now output the underlying data.  If we've handling the padding, return.
3753      Otherwise, break and ensure SIZE is the size written.  */
3754   switch (code)
3755     {
3756     case CHAR_TYPE:
3757     case BOOLEAN_TYPE:
3758     case INTEGER_TYPE:
3759     case ENUMERAL_TYPE:
3760     case POINTER_TYPE:
3761     case REFERENCE_TYPE:
3762     case OFFSET_TYPE:
3763       if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3764                                            EXPAND_INITIALIZER),
3765                               MIN (size, thissize), align, 0))
3766         error ("initializer for integer value is too complicated");
3767       break;
3768
3769     case REAL_TYPE:
3770       if (TREE_CODE (exp) != REAL_CST)
3771         error ("initializer for floating value is not a floating constant");
3772
3773       assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
3774       break;
3775
3776     case COMPLEX_TYPE:
3777       output_constant (TREE_REALPART (exp), thissize / 2, align);
3778       output_constant (TREE_IMAGPART (exp), thissize / 2,
3779                        min_align (align, BITS_PER_UNIT * (thissize / 2)));
3780       break;
3781
3782     case ARRAY_TYPE:
3783     case VECTOR_TYPE:
3784       switch (TREE_CODE (exp))
3785         {
3786         case CONSTRUCTOR:
3787           output_constructor (exp, size, align);
3788           return;
3789         case STRING_CST:
3790           thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
3791                           size);
3792           assemble_string (TREE_STRING_POINTER (exp), thissize);
3793           break;
3794
3795         case VECTOR_CST:
3796           {
3797             int elt_size;
3798             tree link;
3799             unsigned int nalign;
3800             enum machine_mode inner;
3801             
3802             inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
3803             nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
3804             
3805             elt_size = GET_MODE_SIZE (inner);
3806             
3807             link = TREE_VECTOR_CST_ELTS (exp);
3808             output_constant (TREE_VALUE (link), elt_size, align);
3809             while ((link = TREE_CHAIN (link)) != NULL)
3810               output_constant (TREE_VALUE (link), elt_size, nalign);
3811             break;
3812           }
3813         default:
3814           gcc_unreachable ();
3815         }
3816       break;
3817
3818     case RECORD_TYPE:
3819     case UNION_TYPE:
3820       gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
3821       output_constructor (exp, size, align);
3822       return;
3823
3824     case ERROR_MARK:
3825       return;
3826
3827     default:
3828       gcc_unreachable ();
3829     }
3830
3831   if (size > thissize)
3832     assemble_zeros (size - thissize);
3833 }
3834
3835 \f
3836 /* Subroutine of output_constructor, used for computing the size of
3837    arrays of unspecified length.  VAL must be a CONSTRUCTOR of an array
3838    type with an unspecified upper bound.  */
3839
3840 static unsigned HOST_WIDE_INT
3841 array_size_for_constructor (tree val)
3842 {
3843   tree max_index, i;
3844
3845   /* This code used to attempt to handle string constants that are not
3846      arrays of single-bytes, but nothing else does, so there's no point in
3847      doing it here.  */
3848   if (TREE_CODE (val) == STRING_CST)
3849     return TREE_STRING_LENGTH (val);
3850
3851   max_index = NULL_TREE;
3852   for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i))
3853     {
3854       tree index = TREE_PURPOSE (i);
3855
3856       if (TREE_CODE (index) == RANGE_EXPR)
3857         index = TREE_OPERAND (index, 1);
3858       if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
3859         max_index = index;
3860     }
3861
3862   if (max_index == NULL_TREE)
3863     return 0;
3864
3865   /* Compute the total number of array elements.  */
3866   i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
3867                   convert (sizetype,
3868                            TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
3869   i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
3870
3871   /* Multiply by the array element unit size to find number of bytes.  */
3872   i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
3873
3874   return tree_low_cst (i, 1);
3875 }
3876
3877 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3878    Generate at least SIZE bytes, padding if necessary.  */
3879
3880 static void
3881 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
3882                     unsigned int align)
3883 {
3884   tree type = TREE_TYPE (exp);
3885   tree link, field = 0;
3886   tree min_index = 0;
3887   /* Number of bytes output or skipped so far.
3888      In other words, current position within the constructor.  */
3889   HOST_WIDE_INT total_bytes = 0;
3890   /* Nonzero means BYTE contains part of a byte, to be output.  */
3891   int byte_buffer_in_use = 0;
3892   int byte = 0;
3893
3894   gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
3895
3896   if (TREE_CODE (type) == RECORD_TYPE)
3897     field = TYPE_FIELDS (type);
3898
3899   if (TREE_CODE (type) == ARRAY_TYPE
3900       && TYPE_DOMAIN (type) != 0)
3901     min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
3902
3903   /* As LINK goes through the elements of the constant,
3904      FIELD goes through the structure fields, if the constant is a structure.
3905      if the constant is a union, then we override this,
3906      by getting the field from the TREE_LIST element.
3907      But the constant could also be an array.  Then FIELD is zero.
3908
3909      There is always a maximum of one element in the chain LINK for unions
3910      (even if the initializer in a source program incorrectly contains
3911      more one).  */
3912   for (link = CONSTRUCTOR_ELTS (exp);
3913        link;
3914        link = TREE_CHAIN (link),
3915        field = field ? TREE_CHAIN (field) : 0)
3916     {
3917       tree val = TREE_VALUE (link);
3918       tree index = 0;
3919
3920       /* The element in a union constructor specifies the proper field
3921          or index.  */
3922       if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
3923            || TREE_CODE (type) == QUAL_UNION_TYPE)
3924           && TREE_PURPOSE (link) != 0)
3925         field = TREE_PURPOSE (link);
3926
3927       else if (TREE_CODE (type) == ARRAY_TYPE)
3928         index = TREE_PURPOSE (link);
3929
3930 #ifdef ASM_COMMENT_START
3931       if (field && flag_verbose_asm)
3932         fprintf (asm_out_file, "%s %s:\n",
3933                  ASM_COMMENT_START, 
3934                  DECL_NAME (field) 
3935                  ? IDENTIFIER_POINTER (DECL_NAME (field))
3936                  : "<anonymous>");
3937 #endif
3938
3939       /* Eliminate the marker that makes a cast not be an lvalue.  */
3940       if (val != 0)
3941         STRIP_NOPS (val);
3942
3943       if (index && TREE_CODE (index) == RANGE_EXPR)
3944         {
3945           unsigned HOST_WIDE_INT fieldsize
3946             = int_size_in_bytes (TREE_TYPE (type));
3947           HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
3948           HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
3949           HOST_WIDE_INT index;
3950           unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
3951
3952           for (index = lo_index; index <= hi_index; index++)
3953             {
3954               /* Output the element's initial value.  */
3955               if (val == 0)
3956                 assemble_zeros (fieldsize);
3957               else
3958                 output_constant (val, fieldsize, align2);
3959
3960               /* Count its size.  */
3961               total_bytes += fieldsize;
3962             }
3963         }
3964       else if (field == 0 || !DECL_BIT_FIELD (field))
3965         {
3966           /* An element that is not a bit-field.  */
3967
3968           unsigned HOST_WIDE_INT fieldsize;
3969           /* Since this structure is static,
3970              we know the positions are constant.  */
3971           HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
3972           unsigned int align2;
3973
3974           if (index != 0)
3975             pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
3976                    * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
3977
3978           /* Output any buffered-up bit-fields preceding this element.  */
3979           if (byte_buffer_in_use)
3980             {
3981               assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3982               total_bytes++;
3983               byte_buffer_in_use = 0;
3984             }
3985
3986           /* Advance to offset of this element.
3987              Note no alignment needed in an array, since that is guaranteed
3988              if each element has the proper size.  */
3989           if ((field != 0 || index != 0) && pos != total_bytes)
3990             {
3991               assemble_zeros (pos - total_bytes);
3992               total_bytes = pos;
3993             }
3994
3995           /* Find the alignment of this element.  */
3996           align2 = min_align (align, BITS_PER_UNIT * pos);
3997
3998           /* Determine size this element should occupy.  */
3999           if (field)
4000             {
4001               fieldsize = 0;
4002
4003               /* If this is an array with an unspecified upper bound,
4004                  the initializer determines the size.  */
4005               /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4006                  but we cannot do this until the deprecated support for
4007                  initializing zero-length array members is removed.  */
4008               if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4009                   && TYPE_DOMAIN (TREE_TYPE (field))
4010                   && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4011                 {
4012                   fieldsize = array_size_for_constructor (val);
4013                   /* Given a non-empty initialization, this field had
4014                      better be last.  */
4015                   gcc_assert (!fieldsize || !TREE_CHAIN (field));
4016                 }
4017               else if (DECL_SIZE_UNIT (field))
4018                 {
4019                   /* ??? This can't be right.  If the decl size overflows
4020                      a host integer we will silently emit no data.  */
4021                   if (host_integerp (DECL_SIZE_UNIT (field), 1))
4022                     fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4023                 }
4024             }
4025           else
4026             fieldsize = int_size_in_bytes (TREE_TYPE (type));
4027
4028           /* Output the element's initial value.  */
4029           if (val == 0)
4030             assemble_zeros (fieldsize);
4031           else
4032             output_constant (val, fieldsize, align2);
4033
4034           /* Count its size.  */
4035           total_bytes += fieldsize;
4036         }
4037       else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4038         error ("invalid initial value for member %qs",
4039                IDENTIFIER_POINTER (DECL_NAME (field)));
4040       else
4041         {
4042           /* Element that is a bit-field.  */
4043
4044           HOST_WIDE_INT next_offset = int_bit_position (field);
4045           HOST_WIDE_INT end_offset
4046             = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4047
4048           if (val == 0)
4049             val = integer_zero_node;
4050
4051           /* If this field does not start in this (or, next) byte,
4052              skip some bytes.  */
4053           if (next_offset / BITS_PER_UNIT != total_bytes)
4054             {
4055               /* Output remnant of any bit field in previous bytes.  */
4056               if (byte_buffer_in_use)
4057                 {
4058                   assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4059                   total_bytes++;
4060                   byte_buffer_in_use = 0;
4061                 }
4062
4063               /* If still not at proper byte, advance to there.  */
4064               if (next_offset / BITS_PER_UNIT != total_bytes)
4065                 {
4066                   assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4067                   total_bytes = next_offset / BITS_PER_UNIT;
4068                 }
4069             }
4070
4071           if (! byte_buffer_in_use)
4072             byte = 0;
4073
4074           /* We must split the element into pieces that fall within
4075              separate bytes, and combine each byte with previous or
4076              following bit-fields.  */
4077
4078           /* next_offset is the offset n fbits from the beginning of
4079              the structure to the next bit of this element to be processed.
4080              end_offset is the offset of the first bit past the end of
4081              this element.  */
4082           while (next_offset < end_offset)
4083             {
4084               int this_time;
4085               int shift;
4086               HOST_WIDE_INT value;
4087               HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4088               HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4089
4090               /* Advance from byte to byte
4091                  within this element when necessary.  */
4092               while (next_byte != total_bytes)
4093                 {
4094                   assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4095                   total_bytes++;
4096                   byte = 0;
4097                 }
4098
4099               /* Number of bits we can process at once
4100                  (all part of the same byte).  */
4101               this_time = MIN (end_offset - next_offset,
4102                                BITS_PER_UNIT - next_bit);
4103               if (BYTES_BIG_ENDIAN)
4104                 {
4105                   /* On big-endian machine, take the most significant bits
4106                      first (of the bits that are significant)
4107                      and put them into bytes from the most significant end.  */
4108                   shift = end_offset - next_offset - this_time;
4109
4110                   /* Don't try to take a bunch of bits that cross
4111                      the word boundary in the INTEGER_CST. We can
4112                      only select bits from the LOW or HIGH part
4113                      not from both.  */
4114                   if (shift < HOST_BITS_PER_WIDE_INT
4115                       && shift + this_time > HOST_BITS_PER_WIDE_INT)
4116                     {
4117                       this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4118                       shift = HOST_BITS_PER_WIDE_INT;
4119                     }
4120
4121                   /* Now get the bits from the appropriate constant word.  */
4122                   if (shift < HOST_BITS_PER_WIDE_INT)
4123                     value = TREE_INT_CST_LOW (val);
4124                   else
4125                     {
4126                       gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4127                       value = TREE_INT_CST_HIGH (val);
4128                       shift -= HOST_BITS_PER_WIDE_INT;
4129                     }
4130
4131                   /* Get the result. This works only when:
4132                      1 <= this_time <= HOST_BITS_PER_WIDE_INT.  */
4133                   byte |= (((value >> shift)
4134                             & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4135                            << (BITS_PER_UNIT - this_time - next_bit));
4136                 }
4137               else
4138                 {
4139                   /* On little-endian machines,
4140                      take first the least significant bits of the value
4141                      and pack them starting at the least significant
4142                      bits of the bytes.  */
4143                   shift = next_offset - int_bit_position (field);
4144
4145                   /* Don't try to take a bunch of bits that cross
4146                      the word boundary in the INTEGER_CST. We can
4147                      only select bits from the LOW or HIGH part
4148                      not from both.  */
4149                   if (shift < HOST_BITS_PER_WIDE_INT
4150                       && shift + this_time > HOST_BITS_PER_WIDE_INT)
4151                     this_time = (HOST_BITS_PER_WIDE_INT - shift);
4152
4153                   /* Now get the bits from the appropriate constant word.  */
4154                   if (shift < HOST_BITS_PER_WIDE_INT)
4155                     value = TREE_INT_CST_LOW (val);
4156                   else
4157                     {
4158                       gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4159                       value = TREE_INT_CST_HIGH (val);
4160                       shift -= HOST_BITS_PER_WIDE_INT;
4161                     }
4162
4163                   /* Get the result. This works only when:
4164                      1 <= this_time <= HOST_BITS_PER_WIDE_INT.  */
4165                   byte |= (((value >> shift)
4166                             & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4167                            << next_bit);
4168                 }
4169
4170               next_offset += this_time;
4171               byte_buffer_in_use = 1;
4172             }
4173         }
4174     }
4175
4176   if (byte_buffer_in_use)
4177     {
4178       assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4179       total_bytes++;
4180     }
4181
4182   if ((unsigned HOST_WIDE_INT)total_bytes < size)
4183     assemble_zeros (size - total_bytes);
4184 }
4185
4186 /* This TREE_LIST contains any weak symbol declarations waiting
4187    to be emitted.  */
4188 static GTY(()) tree weak_decls;
4189
4190 /* Mark DECL as weak.  */
4191
4192 static void
4193 mark_weak (tree decl)
4194 {
4195   DECL_WEAK (decl) = 1;
4196
4197   if (DECL_RTL_SET_P (decl)
4198       && MEM_P (DECL_RTL (decl))
4199       && XEXP (DECL_RTL (decl), 0)
4200       && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4201     SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4202 }
4203
4204 /* Merge weak status between NEWDECL and OLDDECL.  */
4205
4206 void
4207 merge_weak (tree newdecl, tree olddecl)
4208 {
4209   if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4210     return;
4211
4212   if (DECL_WEAK (newdecl))
4213     {
4214       tree wd;
4215
4216       /* NEWDECL is weak, but OLDDECL is not.  */
4217
4218       /* If we already output the OLDDECL, we're in trouble; we can't
4219          go back and make it weak.  This error cannot caught in
4220          declare_weak because the NEWDECL and OLDDECL was not yet
4221          been merged; therefore, TREE_ASM_WRITTEN was not set.  */
4222       if (TREE_ASM_WRITTEN (olddecl))
4223         error ("%Jweak declaration of %qD must precede definition",
4224                newdecl, newdecl);
4225
4226       /* If we've already generated rtl referencing OLDDECL, we may
4227          have done so in a way that will not function properly with
4228          a weak symbol.  */
4229       else if (TREE_USED (olddecl)
4230                && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4231         warning ("%Jweak declaration of %qD after first use results "
4232                  "in unspecified behavior", newdecl, newdecl);
4233
4234       if (SUPPORTS_WEAK)
4235         {
4236           /* We put the NEWDECL on the weak_decls list at some point.
4237              Replace it with the OLDDECL.  */
4238           for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4239             if (TREE_VALUE (wd) == newdecl)
4240               {
4241                 TREE_VALUE (wd) = olddecl;
4242                 break;
4243               }
4244           /* We may not find the entry on the list.  If NEWDECL is a
4245              weak alias, then we will have already called
4246              globalize_decl to remove the entry; in that case, we do
4247              not need to do anything.  */
4248         }
4249
4250       /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping.  */
4251       mark_weak (olddecl);
4252     }
4253   else
4254     /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4255        weak.  Just update NEWDECL to indicate that it's weak too.  */
4256     mark_weak (newdecl);
4257 }
4258
4259 /* Declare DECL to be a weak symbol.  */
4260
4261 void
4262 declare_weak (tree decl)
4263 {
4264   if (! TREE_PUBLIC (decl))
4265     error ("%Jweak declaration of %qD must be public", decl, decl);
4266   else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4267     error ("%Jweak declaration of %qD must precede definition", decl, decl);
4268   else if (SUPPORTS_WEAK)
4269     {
4270       if (! DECL_WEAK (decl))
4271         weak_decls = tree_cons (NULL, decl, weak_decls);
4272     }
4273   else
4274     warning ("%Jweak declaration of %qD not supported", decl, decl);
4275
4276   mark_weak (decl);
4277 }
4278
4279 /* Emit any pending weak declarations.  */
4280
4281 void
4282 weak_finish (void)
4283 {
4284   tree t;
4285
4286   for (t = weak_decls; t; t = TREE_CHAIN (t))
4287     {
4288       tree decl = TREE_VALUE (t);
4289 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4290       const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4291 #endif
4292
4293       if (! TREE_USED (decl))
4294         continue;
4295
4296 #ifdef ASM_WEAKEN_DECL
4297       ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4298 #else
4299 #ifdef ASM_WEAKEN_LABEL
4300       ASM_WEAKEN_LABEL (asm_out_file, name);
4301 #else
4302 #ifdef ASM_OUTPUT_WEAK_ALIAS
4303       warning ("only weak aliases are supported in this configuration");
4304       return;
4305 #endif
4306 #endif
4307 #endif
4308     }
4309 }
4310
4311 /* Emit the assembly bits to indicate that DECL is globally visible.  */
4312
4313 static void
4314 globalize_decl (tree decl)
4315 {
4316   const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4317
4318 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4319   if (DECL_WEAK (decl))
4320     {
4321       tree *p, t;
4322
4323 #ifdef ASM_WEAKEN_DECL
4324       ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4325 #else
4326       ASM_WEAKEN_LABEL (asm_out_file, name);
4327 #endif
4328
4329       /* Remove this function from the pending weak list so that
4330          we do not emit multiple .weak directives for it.  */
4331       for (p = &weak_decls; (t = *p) ; )
4332         {
4333           if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4334             *p = TREE_CHAIN (t);
4335           else
4336             p = &TREE_CHAIN (t);
4337         }
4338       return;
4339     }
4340 #elif defined(ASM_MAKE_LABEL_LINKONCE)
4341   if (DECL_ONE_ONLY (decl))
4342     ASM_MAKE_LABEL_LINKONCE (asm_out_file, name);
4343 #endif
4344
4345   targetm.asm_out.globalize_label (asm_out_file, name);
4346 }
4347
4348 /* We have to be able to tell cgraph about the needed-ness of the target
4349    of an alias.  This requires that the decl have been defined.  Aliases
4350    that preceed their definition have to be queued for later processing.  */
4351
4352 struct alias_pair GTY(())
4353 {
4354   tree decl;
4355   tree target;
4356 };
4357 typedef struct alias_pair *alias_pair;
4358
4359 /* Define gc'd vector type.  */
4360 DEF_VEC_GC_P(alias_pair);
4361
4362 static GTY(()) VEC(alias_pair) *alias_pairs;
4363
4364 /* Given an assembly name, find the decl it is associated with.  At the
4365    same time, mark it needed for cgraph.  */
4366
4367 static tree
4368 find_decl_and_mark_needed (tree decl, tree target)
4369 {
4370   struct cgraph_node *fnode = NULL;
4371   struct cgraph_varpool_node *vnode = NULL;
4372
4373   /* C++ thunk emitting code produces aliases late in the game.
4374      Avoid confusing cgraph code in that case.  */
4375   if (!cgraph_global_info_ready)
4376     {
4377       if (TREE_CODE (decl) == FUNCTION_DECL)
4378         {
4379           fnode = cgraph_node_for_asm (target);
4380           if (fnode == NULL)
4381             vnode = cgraph_varpool_node_for_asm (target);
4382         }
4383       else
4384         {
4385           vnode = cgraph_varpool_node_for_asm (target);
4386           if (vnode == NULL)
4387             fnode = cgraph_node_for_asm (target);
4388         }
4389     }
4390
4391   if (fnode)
4392     {
4393       cgraph_mark_needed_node (fnode);
4394       return fnode->decl;
4395     }
4396   else if (vnode)
4397     {
4398       cgraph_varpool_mark_needed_node (vnode);
4399       return vnode->decl;
4400     }
4401   else 
4402     return NULL_TREE;
4403 }
4404
4405 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
4406    or ASM_OUTPUT_DEF_FROM_DECLS.  The function defines the symbol whose
4407    tree node is DECL to have the value of the tree node TARGET.  */
4408
4409 static void
4410 do_assemble_alias (tree decl, tree target ATTRIBUTE_UNUSED)
4411 {
4412   TREE_ASM_WRITTEN (decl) = 1;
4413   TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4414
4415 #ifdef ASM_OUTPUT_DEF
4416   /* Make name accessible from other files, if appropriate.  */
4417
4418   if (TREE_PUBLIC (decl))
4419     {
4420       globalize_decl (decl);
4421       maybe_assemble_visibility (decl);
4422     }
4423
4424 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
4425   ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4426 # else
4427   ASM_OUTPUT_DEF (asm_out_file,
4428                   IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
4429                   IDENTIFIER_POINTER (target));
4430 # endif
4431 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4432   {
4433     const char *name;
4434     tree *p, t;
4435
4436     name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4437 # ifdef ASM_WEAKEN_DECL
4438     ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4439 # else
4440     ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4441 # endif
4442     /* Remove this function from the pending weak list so that
4443        we do not emit multiple .weak directives for it.  */
4444     for (p = &weak_decls; (t = *p) ; )
4445       if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4446         *p = TREE_CHAIN (t);
4447       else
4448         p = &TREE_CHAIN (t);
4449   }
4450 #endif
4451 }
4452
4453 /* First pass of completing pending aliases.  Make sure that cgraph knows
4454    which symbols will be required.  */
4455
4456 void
4457 finish_aliases_1 (void)
4458 {
4459   unsigned i;
4460   alias_pair p;
4461
4462   for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
4463     {
4464       tree target_decl;
4465
4466       target_decl = find_decl_and_mark_needed (p->decl, p->target);
4467       if (target_decl == NULL)
4468         error ("%J%qD aliased to undefined symbol %qE",
4469                p->decl, p->decl, p->target);
4470       else if (DECL_EXTERNAL (target_decl))
4471         error ("%J%qD aliased to external symbol %qE",
4472                p->decl, p->decl, p->target);
4473     }
4474 }
4475
4476 /* Second pass of completing pending aliases.  Emit the actual assembly.
4477    This happens at the end of compilation and thus it is assured that the
4478    target symbol has been emitted.  */
4479
4480 void
4481 finish_aliases_2 (void)
4482 {
4483   unsigned i;
4484   alias_pair p;
4485
4486   for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
4487     do_assemble_alias (p->decl, p->target);
4488
4489   alias_pairs = NULL;
4490 }
4491
4492 /* Emit an assembler directive to make the symbol for DECL an alias to
4493    the symbol for TARGET.  */
4494
4495 void
4496 assemble_alias (tree decl, tree target)
4497 {
4498   tree target_decl;
4499
4500 #if !defined (ASM_OUTPUT_DEF)
4501 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
4502   error ("%Jalias definitions not supported in this configuration", decl);
4503   return;
4504 # else
4505   if (!DECL_WEAK (decl))
4506     {
4507       error ("%Jonly weak aliases are supported in this configuration", decl);
4508       return;
4509     }
4510 # endif
4511 #endif
4512
4513   /* We must force creation of DECL_RTL for debug info generation, even though
4514      we don't use it here.  */
4515   make_decl_rtl (decl);
4516   TREE_USED (decl) = 1;
4517
4518   /* A quirk of the initial implementation of aliases required that the user
4519      add "extern" to all of them.  Which is silly, but now historical.  Do
4520      note that the symbol is in fact locally defined.  */
4521   DECL_EXTERNAL (decl) = 0;
4522
4523   /* Allow aliases to aliases.  */
4524   if (TREE_CODE (decl) == FUNCTION_DECL)
4525     cgraph_node (decl)->alias = true;
4526   else
4527     cgraph_varpool_node (decl)->alias = true;
4528
4529   /* If the target has already been emitted, we don't have to queue the
4530      alias.  This saves a tad o memory.  */
4531   target_decl = find_decl_and_mark_needed (decl, target);
4532   if (target_decl && TREE_ASM_WRITTEN (target_decl))
4533     do_assemble_alias (decl, target);
4534   else
4535     {
4536       alias_pair p;
4537
4538       p = ggc_alloc (sizeof (struct alias_pair));
4539       p->decl = decl;
4540       p->target = target;
4541       VEC_safe_push (alias_pair, alias_pairs, p);
4542     }
4543 }
4544
4545 /* Emit an assembler directive to set symbol for DECL visibility to
4546    the visibility type VIS, which must not be VISIBILITY_DEFAULT.  */
4547
4548 void
4549 default_assemble_visibility (tree decl, int vis)
4550 {
4551   static const char * const visibility_types[] = {
4552     NULL, "internal", "hidden", "protected"
4553   };
4554
4555   const char *name, *type;
4556
4557   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4558   type = visibility_types[vis];
4559
4560 #ifdef HAVE_GAS_HIDDEN
4561   fprintf (asm_out_file, "\t.%s\t", type);
4562   assemble_name (asm_out_file, name);
4563   fprintf (asm_out_file, "\n");
4564 #else
4565   warning ("visibility attribute not supported in this configuration; ignored");
4566 #endif
4567 }
4568
4569 /* A helper function to call assemble_visibility when needed for a decl.  */
4570
4571 static void
4572 maybe_assemble_visibility (tree decl)
4573 {
4574   enum symbol_visibility vis = DECL_VISIBILITY (decl);
4575
4576   if (vis != VISIBILITY_DEFAULT)
4577     targetm.asm_out.visibility (decl, vis);
4578 }
4579
4580 /* Returns 1 if the target configuration supports defining public symbols
4581    so that one of them will be chosen at link time instead of generating a
4582    multiply-defined symbol error, whether through the use of weak symbols or
4583    a target-specific mechanism for having duplicates discarded.  */
4584
4585 int
4586 supports_one_only (void)
4587 {
4588   if (SUPPORTS_ONE_ONLY)
4589     return 1;
4590   return SUPPORTS_WEAK;
4591 }
4592
4593 /* Set up DECL as a public symbol that can be defined in multiple
4594    translation units without generating a linker error.  */
4595
4596 void
4597 make_decl_one_only (tree decl)
4598 {
4599   gcc_assert (TREE_CODE (decl) == VAR_DECL
4600               || TREE_CODE (decl) == FUNCTION_DECL);
4601
4602   TREE_PUBLIC (decl) = 1;
4603
4604   if (SUPPORTS_ONE_ONLY)
4605     {
4606 #ifdef MAKE_DECL_ONE_ONLY
4607       MAKE_DECL_ONE_ONLY (decl);
4608 #endif
4609       DECL_ONE_ONLY (decl) = 1;
4610     }
4611   else if (TREE_CODE (decl) == VAR_DECL
4612       && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4613     DECL_COMMON (decl) = 1;
4614   else
4615     {
4616       gcc_assert (SUPPORTS_WEAK);
4617       DECL_WEAK (decl) = 1;
4618     }
4619 }
4620
4621 void
4622 init_varasm_once (void)
4623 {
4624   in_named_htab = htab_create_ggc (31, in_named_entry_hash,
4625                                    in_named_entry_eq, NULL);
4626   const_desc_htab = htab_create_ggc (1009, const_desc_hash,
4627                                      const_desc_eq, NULL);
4628
4629   const_alias_set = new_alias_set ();
4630 }
4631
4632 static enum tls_model
4633 decl_tls_model (tree decl)
4634 {
4635   enum tls_model kind;
4636   tree attr = lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl));
4637   bool is_local;
4638
4639   if (attr)
4640     {
4641       attr = TREE_VALUE (TREE_VALUE (attr));
4642       gcc_assert (TREE_CODE (attr) == STRING_CST);
4643       
4644       if (!strcmp (TREE_STRING_POINTER (attr), "local-exec"))
4645         kind = TLS_MODEL_LOCAL_EXEC;
4646       else if (!strcmp (TREE_STRING_POINTER (attr), "initial-exec"))
4647         kind = TLS_MODEL_INITIAL_EXEC;
4648       else if (!strcmp (TREE_STRING_POINTER (attr), "local-dynamic"))
4649         kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
4650       else if (!strcmp (TREE_STRING_POINTER (attr), "global-dynamic"))
4651         kind = TLS_MODEL_GLOBAL_DYNAMIC;
4652       else
4653         gcc_unreachable ();
4654       return kind;
4655     }
4656
4657   is_local = targetm.binds_local_p (decl);
4658   if (!flag_shlib)
4659     {
4660       if (is_local)
4661         kind = TLS_MODEL_LOCAL_EXEC;
4662       else
4663         kind = TLS_MODEL_INITIAL_EXEC;
4664     }
4665   /* Local dynamic is inefficient when we're not combining the
4666      parts of the address.  */
4667   else if (optimize && is_local)
4668     kind = TLS_MODEL_LOCAL_DYNAMIC;
4669   else
4670     kind = TLS_MODEL_GLOBAL_DYNAMIC;
4671   if (kind < flag_tls_default)
4672     kind = flag_tls_default;
4673
4674   return kind;
4675 }
4676
4677 /* Select a set of attributes for section NAME based on the properties
4678    of DECL and whether or not RELOC indicates that DECL's initializer
4679    might contain runtime relocations.
4680
4681    We make the section read-only and executable for a function decl,
4682    read-only for a const data decl, and writable for a non-const data decl.  */
4683
4684 unsigned int
4685 default_section_type_flags (tree decl, const char *name, int reloc)
4686 {
4687   return default_section_type_flags_1 (decl, name, reloc, flag_pic);
4688 }
4689
4690 unsigned int
4691 default_section_type_flags_1 (tree decl, const char *name, int reloc,
4692                               int shlib)
4693 {
4694   unsigned int flags;
4695
4696   if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4697     flags = SECTION_CODE;
4698   else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
4699     flags = 0;
4700   else if (unlikely_text_section_name
4701            && strcmp (name, unlikely_text_section_name) == 0)
4702     flags = SECTION_CODE;
4703   else
4704     flags = SECTION_WRITE;
4705
4706   if (decl && DECL_ONE_ONLY (decl))
4707     flags |= SECTION_LINKONCE;
4708
4709   if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4710     flags |= SECTION_TLS | SECTION_WRITE;
4711
4712   if (strcmp (name, ".bss") == 0
4713       || strncmp (name, ".bss.", 5) == 0
4714       || strncmp (name, ".gnu.linkonce.b.", 16) == 0
4715       || strcmp (name, ".sbss") == 0
4716       || strncmp (name, ".sbss.", 6) == 0
4717       || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
4718     flags |= SECTION_BSS;
4719
4720   if (strcmp (name, ".tdata") == 0
4721       || strncmp (name, ".tdata.", 7) == 0
4722       || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
4723     flags |= SECTION_TLS;
4724
4725   if (strcmp (name, ".tbss") == 0
4726       || strncmp (name, ".tbss.", 6) == 0
4727       || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4728     flags |= SECTION_TLS | SECTION_BSS;
4729
4730   /* These three sections have special ELF types.  They are neither
4731      SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4732      want to print a section type (@progbits or @nobits).  If someone
4733      is silly enough to emit code or TLS variables to one of these
4734      sections, then don't handle them specially.  */
4735   if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
4736       && (strcmp (name, ".init_array") == 0
4737           || strcmp (name, ".fini_array") == 0
4738           || strcmp (name, ".preinit_array") == 0))
4739     flags |= SECTION_NOTYPE;
4740
4741   return flags;
4742 }
4743
4744 /* Output assembly to switch to section NAME with attribute FLAGS.
4745    Four variants for common object file formats.  */
4746
4747 void
4748 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
4749                           unsigned int flags ATTRIBUTE_UNUSED,
4750                           tree decl ATTRIBUTE_UNUSED)
4751 {
4752   /* Some object formats don't support named sections at all.  The
4753      front-end should already have flagged this as an error.  */
4754   gcc_unreachable ();
4755 }
4756
4757 void
4758 default_elf_asm_named_section (const char *name, unsigned int flags,
4759                                tree decl ATTRIBUTE_UNUSED)
4760 {
4761   char flagchars[10], *f = flagchars;
4762
4763   /* If we have already declared this section, we can use an
4764      abbreviated form to switch back to it -- unless this section is
4765      part of a COMDAT groups, in which case GAS requires the full
4766      declaration every time.  */
4767   if (!(HAVE_GAS_COMDAT_GROUP && (flags & SECTION_LINKONCE))
4768       && ! named_section_first_declaration (name))
4769     {
4770       fprintf (asm_out_file, "\t.section\t%s\n", name);
4771       return;
4772     }
4773
4774   if (!(flags & SECTION_DEBUG))
4775     *f++ = 'a';
4776   if (flags & SECTION_WRITE)
4777     *f++ = 'w';
4778   if (flags & SECTION_CODE)
4779     *f++ = 'x';
4780   if (flags & SECTION_SMALL)
4781     *f++ = 's';
4782   if (flags & SECTION_MERGE)
4783     *f++ = 'M';
4784   if (flags & SECTION_STRINGS)
4785     *f++ = 'S';
4786   if (flags & SECTION_TLS)
4787     *f++ = 'T';
4788   if (HAVE_GAS_COMDAT_GROUP && (flags & SECTION_LINKONCE))
4789     *f++ = 'G';
4790   *f = '\0';
4791
4792   fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
4793
4794   if (!(flags & SECTION_NOTYPE))
4795     {
4796       const char *type;
4797       const char *format;
4798
4799       if (flags & SECTION_BSS)
4800         type = "nobits";
4801       else
4802         type = "progbits";
4803
4804       format = ",@%s";
4805 #ifdef ASM_COMMENT_START
4806       /* On platforms that use "@" as the assembly comment character,
4807          use "%" instead.  */
4808       if (strcmp (ASM_COMMENT_START, "@") == 0)
4809         format = ",%%%s";
4810 #endif
4811       fprintf (asm_out_file, format, type);
4812
4813       if (flags & SECTION_ENTSIZE)
4814         fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
4815       if (HAVE_GAS_COMDAT_GROUP && (flags & SECTION_LINKONCE))
4816         fprintf (asm_out_file, ",%s,comdat", 
4817                  lang_hooks.decls.comdat_group (decl));
4818     }
4819
4820   putc ('\n', asm_out_file);
4821 }
4822
4823 void
4824 default_coff_asm_named_section (const char *name, unsigned int flags, 
4825                                 tree decl ATTRIBUTE_UNUSED)
4826 {
4827   char flagchars[8], *f = flagchars;
4828
4829   if (flags & SECTION_WRITE)
4830     *f++ = 'w';
4831   if (flags & SECTION_CODE)
4832     *f++ = 'x';
4833   *f = '\0';
4834
4835   fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
4836 }
4837
4838 void
4839 default_pe_asm_named_section (const char *name, unsigned int flags,
4840                               tree decl)
4841 {
4842   default_coff_asm_named_section (name, flags, decl);
4843
4844   if (flags & SECTION_LINKONCE)
4845     {
4846       /* Functions may have been compiled at various levels of
4847          optimization so we can't use `same_size' here.
4848          Instead, have the linker pick one.  */
4849       fprintf (asm_out_file, "\t.linkonce %s\n",
4850                (flags & SECTION_CODE ? "discard" : "same_size"));
4851     }
4852 }
4853 \f
4854 /* The lame default section selector.  */
4855
4856 void
4857 default_select_section (tree decl, int reloc,
4858                         unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4859 {
4860   bool readonly = false;
4861
4862   if (DECL_P (decl))
4863     {
4864       if (decl_readonly_section (decl, reloc))
4865         readonly = true;
4866     }
4867   else if (TREE_CODE (decl) == CONSTRUCTOR)
4868     {
4869       if (! ((flag_pic && reloc)
4870              || !TREE_READONLY (decl)
4871              || TREE_SIDE_EFFECTS (decl)
4872              || !TREE_CONSTANT (decl)))
4873         readonly = true;
4874     }
4875   else if (TREE_CODE (decl) == STRING_CST)
4876     readonly = true;
4877   else if (! (flag_pic && reloc))
4878     readonly = true;
4879
4880   if (readonly)
4881     readonly_data_section ();
4882   else
4883     data_section ();
4884 }
4885
4886 /* A helper function for default_elf_select_section and
4887    default_elf_unique_section.  Categorizes the DECL.  */
4888
4889 enum section_category
4890 {
4891   SECCAT_TEXT,
4892
4893   SECCAT_RODATA,
4894   SECCAT_RODATA_MERGE_STR,
4895   SECCAT_RODATA_MERGE_STR_INIT,
4896   SECCAT_RODATA_MERGE_CONST,
4897   SECCAT_SRODATA,
4898
4899   SECCAT_DATA,
4900
4901   /* To optimize loading of shared programs, define following subsections
4902      of data section:
4903         _REL    Contains data that has relocations, so they get grouped
4904                 together and dynamic linker will visit fewer pages in memory.
4905         _RO     Contains data that is otherwise read-only.  This is useful
4906                 with prelinking as most relocations won't be dynamically
4907                 linked and thus stay read only.
4908         _LOCAL  Marks data containing relocations only to local objects.
4909                 These relocations will get fully resolved by prelinking.  */
4910   SECCAT_DATA_REL,
4911   SECCAT_DATA_REL_LOCAL,
4912   SECCAT_DATA_REL_RO,
4913   SECCAT_DATA_REL_RO_LOCAL,
4914
4915   SECCAT_SDATA,
4916   SECCAT_TDATA,
4917
4918   SECCAT_BSS,
4919   SECCAT_SBSS,
4920   SECCAT_TBSS
4921 };
4922
4923 static enum section_category
4924 categorize_decl_for_section (tree, int, int);
4925
4926 static enum section_category
4927 categorize_decl_for_section (tree decl, int reloc, int shlib)
4928 {
4929   enum section_category ret;
4930
4931   if (TREE_CODE (decl) == FUNCTION_DECL)
4932     return SECCAT_TEXT;
4933   else if (TREE_CODE (decl) == STRING_CST)
4934     {
4935       if (flag_mudflap) /* or !flag_merge_constants */
4936         return SECCAT_RODATA;
4937       else
4938         return SECCAT_RODATA_MERGE_STR;
4939     }
4940   else if (TREE_CODE (decl) == VAR_DECL)
4941     {
4942       if (DECL_INITIAL (decl) == NULL
4943           || DECL_INITIAL (decl) == error_mark_node
4944           || (flag_zero_initialized_in_bss
4945               /* Leave constant zeroes in .rodata so they can be shared.  */
4946               && !TREE_READONLY (decl)
4947               && initializer_zerop (DECL_INITIAL (decl))))
4948         ret = SECCAT_BSS;
4949       else if (! TREE_READONLY (decl)
4950                || TREE_SIDE_EFFECTS (decl)
4951                || ! TREE_CONSTANT (DECL_INITIAL (decl)))
4952         {
4953           if (shlib && (reloc & 2))
4954             ret = SECCAT_DATA_REL;
4955           else if (shlib && reloc)
4956             ret = SECCAT_DATA_REL_LOCAL;
4957           else
4958             ret = SECCAT_DATA;
4959         }
4960       else if (shlib && (reloc & 2))
4961         ret = SECCAT_DATA_REL_RO;
4962       else if (shlib && reloc)
4963         ret = SECCAT_DATA_REL_RO_LOCAL;
4964       else if (reloc || flag_merge_constants < 2)
4965         /* C and C++ don't allow different variables to share the same
4966            location.  -fmerge-all-constants allows even that (at the
4967            expense of not conforming).  */
4968         ret = SECCAT_RODATA;
4969       else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
4970         ret = SECCAT_RODATA_MERGE_STR_INIT;
4971       else
4972         ret = SECCAT_RODATA_MERGE_CONST;
4973     }
4974   else if (TREE_CODE (decl) == CONSTRUCTOR)
4975     {
4976       if ((shlib && reloc)
4977           || TREE_SIDE_EFFECTS (decl)
4978           || ! TREE_CONSTANT (decl))
4979         ret = SECCAT_DATA;
4980       else
4981         ret = SECCAT_RODATA;
4982     }
4983   else
4984     ret = SECCAT_RODATA;
4985
4986   /* There are no read-only thread-local sections.  */
4987   if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4988     {
4989       /* Note that this would be *just* SECCAT_BSS, except that there's
4990          no concept of a read-only thread-local-data section.  */
4991       if (ret == SECCAT_BSS
4992           || (flag_zero_initialized_in_bss
4993               && initializer_zerop (DECL_INITIAL (decl))))
4994         ret = SECCAT_TBSS;
4995       else
4996         ret = SECCAT_TDATA;
4997     }
4998
4999   /* If the target uses small data sections, select it.  */
5000   else if (targetm.in_small_data_p (decl))
5001     {
5002       if (ret == SECCAT_BSS)
5003         ret = SECCAT_SBSS;
5004       else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
5005         ret = SECCAT_SRODATA;
5006       else
5007         ret = SECCAT_SDATA;
5008     }
5009
5010   return ret;
5011 }
5012
5013 bool
5014 decl_readonly_section (tree decl, int reloc)
5015 {
5016   return decl_readonly_section_1 (decl, reloc, flag_pic);
5017 }
5018
5019 bool
5020 decl_readonly_section_1 (tree decl, int reloc, int shlib)
5021 {
5022   switch (categorize_decl_for_section (decl, reloc, shlib))
5023     {
5024     case SECCAT_RODATA:
5025     case SECCAT_RODATA_MERGE_STR:
5026     case SECCAT_RODATA_MERGE_STR_INIT:
5027     case SECCAT_RODATA_MERGE_CONST:
5028     case SECCAT_SRODATA:
5029       return true;
5030       break;
5031     default:
5032       return false;
5033       break;
5034     }
5035 }
5036
5037 /* Select a section based on the above categorization.  */
5038
5039 void
5040 default_elf_select_section (tree decl, int reloc,
5041                             unsigned HOST_WIDE_INT align)
5042 {
5043   default_elf_select_section_1 (decl, reloc, align, flag_pic);
5044 }
5045
5046 void
5047 default_elf_select_section_1 (tree decl, int reloc,
5048                               unsigned HOST_WIDE_INT align, int shlib)
5049 {
5050   const char *sname;
5051   switch (categorize_decl_for_section (decl, reloc, shlib))
5052     {
5053     case SECCAT_TEXT:
5054       /* We're not supposed to be called on FUNCTION_DECLs.  */
5055       gcc_unreachable ();
5056     case SECCAT_RODATA:
5057       readonly_data_section ();
5058       return;
5059     case SECCAT_RODATA_MERGE_STR:
5060       mergeable_string_section (decl, align, 0);
5061       return;
5062     case SECCAT_RODATA_MERGE_STR_INIT:
5063       mergeable_string_section (DECL_INITIAL (decl), align, 0);
5064       return;
5065     case SECCAT_RODATA_MERGE_CONST:
5066       mergeable_constant_section (DECL_MODE (decl), align, 0);
5067       return;
5068     case SECCAT_SRODATA:
5069       sname = ".sdata2";
5070       break;
5071     case SECCAT_DATA:
5072       data_section ();
5073       return;
5074     case SECCAT_DATA_REL:
5075       sname = ".data.rel";
5076       break;
5077     case SECCAT_DATA_REL_LOCAL:
5078       sname = ".data.rel.local";
5079       break;
5080     case SECCAT_DATA_REL_RO:
5081       sname = ".data.rel.ro";
5082       break;
5083     case SECCAT_DATA_REL_RO_LOCAL:
5084       sname = ".data.rel.ro.local";
5085       break;
5086     case SECCAT_SDATA:
5087       sname = ".sdata";
5088       break;
5089     case SECCAT_TDATA:
5090       sname = ".tdata";
5091       break;
5092     case SECCAT_BSS:
5093 #ifdef BSS_SECTION_ASM_OP
5094       bss_section ();
5095       return;
5096 #else
5097       sname = ".bss";
5098       break;
5099 #endif
5100     case SECCAT_SBSS:
5101       sname = ".sbss";
5102       break;
5103     case SECCAT_TBSS:
5104       sname = ".tbss";
5105       break;
5106     default:
5107       gcc_unreachable ();
5108     }
5109
5110   if (!DECL_P (decl))
5111     decl = NULL_TREE;
5112   named_section (decl, sname, reloc);
5113 }
5114
5115 /* Construct a unique section name based on the decl name and the
5116    categorization performed above.  */
5117
5118 void
5119 default_unique_section (tree decl, int reloc)
5120 {
5121   default_unique_section_1 (decl, reloc, flag_pic);
5122 }
5123
5124 void
5125 default_unique_section_1 (tree decl, int reloc, int shlib)
5126 {
5127   bool one_only = DECL_ONE_ONLY (decl);
5128   const char *prefix, *name;
5129   size_t nlen, plen;
5130   char *string;
5131
5132   switch (categorize_decl_for_section (decl, reloc, shlib))
5133     {
5134     case SECCAT_TEXT:
5135       prefix = one_only ? ".gnu.linkonce.t." : ".text.";
5136       break;
5137     case SECCAT_RODATA:
5138     case SECCAT_RODATA_MERGE_STR:
5139     case SECCAT_RODATA_MERGE_STR_INIT:
5140     case SECCAT_RODATA_MERGE_CONST:
5141       prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
5142       break;
5143     case SECCAT_SRODATA:
5144       prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
5145       break;
5146     case SECCAT_DATA:
5147     case SECCAT_DATA_REL:
5148     case SECCAT_DATA_REL_LOCAL:
5149     case SECCAT_DATA_REL_RO:
5150     case SECCAT_DATA_REL_RO_LOCAL:
5151       prefix = one_only ? ".gnu.linkonce.d." : ".data.";
5152       break;
5153     case SECCAT_SDATA:
5154       prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
5155       break;
5156     case SECCAT_BSS:
5157       prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
5158       break;
5159     case SECCAT_SBSS:
5160       prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
5161       break;
5162     case SECCAT_TDATA:
5163       prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
5164       break;
5165     case SECCAT_TBSS:
5166       prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
5167       break;
5168     default:
5169       gcc_unreachable ();
5170     }
5171   plen = strlen (prefix);
5172
5173   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5174   name = targetm.strip_name_encoding (name);
5175   nlen = strlen (name);
5176
5177   string = alloca (nlen + plen + 1);
5178   memcpy (string, prefix, plen);
5179   memcpy (string + plen, name, nlen + 1);
5180
5181   DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
5182 }
5183
5184 void
5185 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
5186                             rtx x,
5187                             unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5188 {
5189   if (flag_pic)
5190     switch (GET_CODE (x))
5191       {
5192       case CONST:
5193       case SYMBOL_REF:
5194       case LABEL_REF:
5195         data_section ();
5196         return;
5197
5198       default:
5199         break;
5200       }
5201
5202   readonly_data_section ();
5203 }
5204
5205 void
5206 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
5207                                 unsigned HOST_WIDE_INT align)
5208 {
5209   /* ??? Handle small data here somehow.  */
5210
5211   if (flag_pic)
5212     switch (GET_CODE (x))
5213       {
5214       case CONST:
5215       case SYMBOL_REF:
5216         named_section (NULL_TREE, ".data.rel.ro", 3);
5217         return;
5218
5219       case LABEL_REF:
5220         named_section (NULL_TREE, ".data.rel.ro.local", 1);
5221         return;
5222
5223       default:
5224         break;
5225       }
5226
5227   mergeable_constant_section (mode, align, 0);
5228 }
5229
5230 /* Set the generally applicable flags on the SYMBOL_REF for EXP.  */
5231
5232 void
5233 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
5234 {
5235   rtx symbol;
5236   int flags;
5237
5238   /* Careful not to prod global register variables.  */
5239   if (!MEM_P (rtl))
5240     return;
5241   symbol = XEXP (rtl, 0);
5242   if (GET_CODE (symbol) != SYMBOL_REF)
5243     return;
5244
5245   flags = 0;
5246   if (TREE_CODE (decl) == FUNCTION_DECL)
5247     flags |= SYMBOL_FLAG_FUNCTION;
5248   if (targetm.binds_local_p (decl))
5249     flags |= SYMBOL_FLAG_LOCAL;
5250   if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
5251     flags |= decl_tls_model (decl) << SYMBOL_FLAG_TLS_SHIFT;
5252   else if (targetm.in_small_data_p (decl))
5253     flags |= SYMBOL_FLAG_SMALL;
5254   /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names?  Without
5255      being PUBLIC, the thing *must* be defined in this translation unit.
5256      Prevent this buglet from being propagated into rtl code as well.  */
5257   if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
5258     flags |= SYMBOL_FLAG_EXTERNAL;
5259
5260   SYMBOL_REF_FLAGS (symbol) = flags;
5261 }
5262
5263 /* By default, we do nothing for encode_section_info, so we need not
5264    do anything but discard the '*' marker.  */
5265
5266 const char *
5267 default_strip_name_encoding (const char *str)
5268 {
5269   return str + (*str == '*');
5270 }
5271
5272 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5273    wrt cross-module name binding.  */
5274
5275 bool
5276 default_binds_local_p (tree exp)
5277 {
5278   return default_binds_local_p_1 (exp, flag_shlib);
5279 }
5280
5281 bool
5282 default_binds_local_p_1 (tree exp, int shlib)
5283 {
5284   bool local_p;
5285
5286   /* A non-decl is an entry in the constant pool.  */
5287   if (!DECL_P (exp))
5288     local_p = true;
5289   /* Static variables are always local.  */
5290   else if (! TREE_PUBLIC (exp))
5291     local_p = true;
5292   /* A variable is local if the user explicitly tells us so.  */
5293   else if (DECL_VISIBILITY_SPECIFIED (exp) && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5294     local_p = true;
5295   /* Otherwise, variables defined outside this object may not be local.  */
5296   else if (DECL_EXTERNAL (exp))
5297     local_p = false;
5298   /* Linkonce and weak data are never local.  */
5299   else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
5300     local_p = false;
5301   /* If none of the above and visibility is not default, make local.  */
5302   else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5303     local_p = true;
5304   /* If PIC, then assume that any global name can be overridden by
5305      symbols resolved from other modules.  */
5306   else if (shlib)
5307     local_p = false;
5308   /* Uninitialized COMMON variable may be unified with symbols
5309      resolved from other modules.  */
5310   else if (DECL_COMMON (exp)
5311            && (DECL_INITIAL (exp) == NULL
5312                || DECL_INITIAL (exp) == error_mark_node))
5313     local_p = false;
5314   /* Otherwise we're left with initialized (or non-common) global data
5315      which is of necessity defined locally.  */
5316   else
5317     local_p = true;
5318
5319   return local_p;
5320 }
5321
5322 /* Determine whether or not a pointer mode is valid. Assume defaults
5323    of ptr_mode or Pmode - can be overridden.  */
5324 bool
5325 default_valid_pointer_mode (enum machine_mode mode)
5326 {
5327   return (mode == ptr_mode || mode == Pmode);
5328 }
5329
5330 /* Default function to output code that will globalize a label.  A
5331    target must define GLOBAL_ASM_OP or provide it's own function to
5332    globalize a label.  */
5333 #ifdef GLOBAL_ASM_OP
5334 void
5335 default_globalize_label (FILE * stream, const char *name)
5336 {
5337   fputs (GLOBAL_ASM_OP, stream);
5338   assemble_name (stream, name);
5339   putc ('\n', stream);
5340 }
5341 #endif /* GLOBAL_ASM_OP */
5342
5343 /* Default function to output a label for unwind information.  The
5344    default is to do nothing.  A target that needs nonlocal labels for
5345    unwind information must provide its own function to do this.  */
5346 void
5347 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
5348                            tree decl ATTRIBUTE_UNUSED,
5349                            int for_eh ATTRIBUTE_UNUSED,
5350                            int empty ATTRIBUTE_UNUSED)
5351
5352 }
5353
5354 /* This is how to output an internal numbered label where PREFIX is
5355    the class of label and LABELNO is the number within the class.  */
5356
5357 void
5358 default_internal_label (FILE *stream, const char *prefix,
5359                         unsigned long labelno)
5360 {
5361   char *const buf = alloca (40 + strlen (prefix));
5362   ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
5363   ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
5364 }
5365
5366 /* This is the default behavior at the beginning of a file.  It's
5367    controlled by two other target-hook toggles.  */
5368 void
5369 default_file_start (void)
5370 {
5371   if (targetm.file_start_app_off && !flag_verbose_asm)
5372     fputs (ASM_APP_OFF, asm_out_file);
5373
5374   if (targetm.file_start_file_directive)
5375     output_file_directive (asm_out_file, main_input_filename);
5376 }
5377
5378 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5379    which emits a special section directive used to indicate whether or
5380    not this object file needs an executable stack.  This is primarily
5381    a GNU extension to ELF but could be used on other targets.  */
5382
5383 int trampolines_created;
5384
5385 void
5386 file_end_indicate_exec_stack (void)
5387 {
5388   unsigned int flags = SECTION_DEBUG;
5389   if (trampolines_created)
5390     flags |= SECTION_CODE;
5391
5392   named_section_flags (".note.GNU-stack", flags);
5393 }
5394
5395 #include "gt-varasm.h"