OSDN Git Service

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