OSDN Git Service

* varasm.c (IN_NAMED_SECTION): Remove guard.
[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, 2006, 2007, 2008, 2009,
4    2010  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 3, 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 COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22
23 /* This file handles generation of all the assembler code
24    *except* the instructions of a function.
25    This includes declarations of variables and their initial values.
26
27    We also output the assembler code for constants stored in memory
28    and are responsible for combining constants with the same value.  */
29
30 #include "config.h"
31 #include "system.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #include "rtl.h"
35 #include "tree.h"
36 #include "flags.h"
37 #include "function.h"
38 #include "expr.h"
39 #include "hard-reg-set.h"
40 #include "regs.h"
41 #include "real.h"
42 #include "output.h"
43 #include "toplev.h"
44 #include "hashtab.h"
45 #include "ggc.h"
46 #include "langhooks.h"
47 #include "tm_p.h"
48 #include "debug.h"
49 #include "target.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
52 #include "cgraph.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.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 #define n_deferred_constants (crtl->varasm.deferred_constants)
74
75 /* Number for making the label on the next
76    constant that is stored in memory.  */
77
78 static GTY(()) int const_labelno;
79
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81    to ASM_FINISH_DECLARE_OBJECT.  */
82
83 int size_directive_output;
84
85 /* The last decl for which assemble_variable was called,
86    if it did ASM_DECLARE_OBJECT_NAME.
87    If the last call to assemble_variable didn't do that,
88    this holds 0.  */
89
90 tree last_assemble_variable_decl;
91
92 /* The following global variable indicates if the first basic block
93    in a function belongs to the cold partition or not.  */
94
95 bool first_function_block_is_cold;
96
97 /* We give all constants their own alias set.  Perhaps redundant with
98    MEM_READONLY_P, but pre-dates it.  */
99
100 static alias_set_type const_alias_set;
101
102 static const char *strip_reg_name (const char *);
103 static int contains_pointers_p (tree);
104 #ifdef ASM_OUTPUT_EXTERNAL
105 static bool incorporeal_function_p (tree);
106 #endif
107 static void decode_addr_const (tree, struct addr_const *);
108 static hashval_t const_desc_hash (const void *);
109 static int const_desc_eq (const void *, const void *);
110 static hashval_t const_hash_1 (const tree);
111 static int compare_constant (const tree, const tree);
112 static tree copy_constant (tree);
113 static void output_constant_def_contents (rtx);
114 static void output_addressed_constants (tree);
115 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
116 static unsigned min_align (unsigned, unsigned);
117 static void globalize_decl (tree);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_BSS
120 static void asm_output_bss (FILE *, tree, const char *,
121                             unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
122 #endif
123 #ifdef ASM_OUTPUT_ALIGNED_BSS
124 static void asm_output_aligned_bss (FILE *, tree, const char *,
125                                     unsigned HOST_WIDE_INT, int)
126      ATTRIBUTE_UNUSED;
127 #endif
128 #endif /* BSS_SECTION_ASM_OP */
129 static void mark_weak (tree);
130 static void output_constant_pool (const char *, tree);
131 \f
132 /* Well-known sections, each one associated with some sort of *_ASM_OP.  */
133 section *text_section;
134 section *data_section;
135 section *readonly_data_section;
136 section *sdata_section;
137 section *ctors_section;
138 section *dtors_section;
139 section *bss_section;
140 section *sbss_section;
141
142 /* Various forms of common section.  All are guaranteed to be nonnull.  */
143 section *tls_comm_section;
144 section *comm_section;
145 section *lcomm_section;
146
147 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
148    May be null.  */
149 section *bss_noswitch_section;
150
151 /* The section that holds the main exception table, when known.  The section
152    is set either by the target's init_sections hook or by the first call to
153    switch_to_exception_section.  */
154 section *exception_section;
155
156 /* The section that holds the DWARF2 frame unwind information, when known.
157    The section is set either by the target's init_sections hook or by the
158    first call to switch_to_eh_frame_section.  */
159 section *eh_frame_section;
160
161 /* asm_out_file's current section.  This is NULL if no section has yet
162    been selected or if we lose track of what the current section is.  */
163 section *in_section;
164
165 /* True if code for the current function is currently being directed
166    at the cold section.  */
167 bool in_cold_section_p;
168
169 /* A linked list of all the unnamed sections.  */
170 static GTY(()) section *unnamed_sections;
171
172 /* Return a nonzero value if DECL has a section attribute.  */
173 #define IN_NAMED_SECTION(DECL) \
174   ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
175    && DECL_SECTION_NAME (DECL) != NULL_TREE)
176
177 /* Hash table of named sections.  */
178 static GTY((param_is (section))) htab_t section_htab;
179
180 /* A table of object_blocks, indexed by section.  */
181 static GTY((param_is (struct object_block))) htab_t object_block_htab;
182
183 /* The next number to use for internal anchor labels.  */
184 static GTY(()) int anchor_labelno;
185
186 /* A pool of constants that can be shared between functions.  */
187 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
188
189 /* TLS emulation.  */
190
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
192      htab_t emutls_htab;
193 static GTY (()) tree emutls_object_type;
194 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED.  This
195    macro can be used on them to distinguish the control variable from
196    the initialization template.  */
197 #define DECL_EMUTLS_VAR_P(D)  (TREE_TYPE (D) == emutls_object_type)
198
199 #if !defined (NO_DOT_IN_LABEL)
200 # define EMUTLS_SEPARATOR       "."
201 #elif !defined (NO_DOLLAR_IN_LABEL)
202 # define EMUTLS_SEPARATOR       "$"
203 #else
204 # define EMUTLS_SEPARATOR       "_"
205 #endif
206
207 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
208    IDENTIFIER_NODE NAME's name.  */
209
210 static tree
211 prefix_name (const char *prefix, tree name)
212 {
213   unsigned plen = strlen (prefix);
214   unsigned nlen = strlen (IDENTIFIER_POINTER (name));
215   char *toname = (char *) alloca (plen + nlen + 1);
216
217   memcpy (toname, prefix, plen);
218   memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
219
220   return get_identifier (toname);
221 }
222
223 /* Create an identifier for the struct __emutls_object, given an identifier
224    of the DECL_ASSEMBLY_NAME of the original object.  */
225
226 static tree
227 get_emutls_object_name (tree name)
228 {
229   const char *prefix = (targetm.emutls.var_prefix
230                         ? targetm.emutls.var_prefix
231                         : "__emutls_v" EMUTLS_SEPARATOR);
232   return prefix_name (prefix, name);
233 }
234
235 tree
236 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
237 {
238   tree word_type_node, field, next_field;
239
240   field = build_decl (UNKNOWN_LOCATION,
241                       FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
242   DECL_CONTEXT (field) = type;
243   next_field = field;
244
245   field = build_decl (UNKNOWN_LOCATION,
246                       FIELD_DECL, get_identifier ("__offset"),
247                       ptr_type_node);
248   DECL_CONTEXT (field) = type;
249   TREE_CHAIN (field) = next_field;
250   next_field = field;
251
252   word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
253   field = build_decl (UNKNOWN_LOCATION,
254                       FIELD_DECL, get_identifier ("__align"),
255                       word_type_node);
256   DECL_CONTEXT (field) = type;
257   TREE_CHAIN (field) = next_field;
258   next_field = field;
259
260   field = build_decl (UNKNOWN_LOCATION,
261                       FIELD_DECL, get_identifier ("__size"), word_type_node);
262   DECL_CONTEXT (field) = type;
263   TREE_CHAIN (field) = next_field;
264
265   return field;
266 }
267
268 /* Create the structure for struct __emutls_object.  This should match the
269    structure at the top of emutls.c, modulo the union there.  */
270
271 static tree
272 get_emutls_object_type (void)
273 {
274   tree type, type_name, field;
275
276   type = emutls_object_type;
277   if (type)
278     return type;
279
280   emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
281   type_name = NULL;
282   field = targetm.emutls.var_fields (type, &type_name);
283   if (!type_name)
284     type_name = get_identifier ("__emutls_object");
285   type_name = build_decl (UNKNOWN_LOCATION,
286                           TYPE_DECL, type_name, type);
287   TYPE_NAME (type) = type_name;
288   TYPE_FIELDS (type) = field;
289   layout_type (type);
290
291   return type;
292 }
293
294 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
295    This will be used for initializing the emulated tls data area.  */
296
297 static tree
298 get_emutls_init_templ_addr (tree decl)
299 {
300   tree name, to;
301
302   if (targetm.emutls.register_common && !DECL_INITIAL (decl)
303       && !DECL_SECTION_NAME (decl))
304     return null_pointer_node;
305
306   name = DECL_ASSEMBLER_NAME (decl);
307   if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0])
308     {
309       const char *prefix = (targetm.emutls.tmpl_prefix
310                             ? targetm.emutls.tmpl_prefix
311                             : "__emutls_t" EMUTLS_SEPARATOR);
312       name = prefix_name (prefix, name);
313     }
314
315   to = build_decl (DECL_SOURCE_LOCATION (decl),
316                    VAR_DECL, name, TREE_TYPE (decl));
317   SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
318   DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
319   DECL_ARTIFICIAL (to) = 1;
320   TREE_USED (to) = TREE_USED (decl);
321   TREE_READONLY (to) = 1;
322   DECL_IGNORED_P (to) = 1;
323   DECL_CONTEXT (to) = DECL_CONTEXT (decl);
324   DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
325
326   DECL_WEAK (to) = DECL_WEAK (decl);
327   if (DECL_ONE_ONLY (decl))
328     {
329       make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
330       TREE_STATIC (to) = TREE_STATIC (decl);
331       TREE_PUBLIC (to) = TREE_PUBLIC (decl);
332       DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
333     }
334   else
335     TREE_STATIC (to) = 1;
336
337   DECL_INITIAL (to) = DECL_INITIAL (decl);
338   DECL_INITIAL (decl) = NULL;
339
340   varpool_finalize_decl (to);
341   return build_fold_addr_expr (to);
342 }
343
344 /* When emulating tls, we use a control structure for use by the runtime.
345    Create and return this structure.  */
346
347 tree
348 emutls_decl (tree decl)
349 {
350   tree name, to;
351   struct tree_map *h, in;
352   void **loc;
353
354   if (targetm.have_tls || decl == NULL || decl == error_mark_node
355       || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
356     return decl;
357
358   /* Look up the object in the hash; return the control structure if
359      it has already been created.  */
360   if (! emutls_htab)
361     emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
362
363   name = DECL_ASSEMBLER_NAME (decl);
364
365   /* Note that we use the hash of the decl's name, rather than a hash
366      of the decl's pointer.  In emutls_finish we iterate through the
367      hash table, and we want this traversal to be predictable.  */
368   in.hash = htab_hash_string (IDENTIFIER_POINTER (name));
369   in.base.from = decl;
370   loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
371   h = (struct tree_map *) *loc;
372   if (h != NULL)
373     to = h->to;
374   else
375     {
376       to = build_decl (DECL_SOURCE_LOCATION (decl),
377                        VAR_DECL, get_emutls_object_name (name),
378                        get_emutls_object_type ());
379
380       h = GGC_NEW (struct tree_map);
381       h->hash = in.hash;
382       h->base.from = decl;
383       h->to = to;
384       *(struct tree_map **) loc = h;
385
386       DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
387       DECL_ARTIFICIAL (to) = 1;
388       DECL_IGNORED_P (to) = 1;
389       TREE_READONLY (to) = 0;
390       SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
391       if (DECL_ONE_ONLY (decl))
392         make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
393       DECL_CONTEXT (to) = DECL_CONTEXT (decl);
394       if (targetm.emutls.var_align_fixed)
395         /* If we're not allowed to change the proxy object's
396            alignment, pretend it's been set by the user.  */
397         DECL_USER_ALIGN (to) = 1;
398     }
399
400   /* Note that these fields may need to be updated from time to time from
401      the original decl.  Consider:
402         extern __thread int i;
403         int foo() { return i; }
404         __thread int i = 1;
405      in which I goes from external to locally defined and initialized.  */
406
407   TREE_STATIC (to) = TREE_STATIC (decl);
408   TREE_USED (to) = TREE_USED (decl);
409   TREE_PUBLIC (to) = TREE_PUBLIC (decl);
410   DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
411   DECL_COMMON (to) = DECL_COMMON (decl);
412   DECL_WEAK (to) = DECL_WEAK (decl);
413   DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
414
415   return to;
416 }
417
418 static int
419 emutls_common_1 (void **loc, void *xstmts)
420 {
421   struct tree_map *h = *(struct tree_map **) loc;
422   tree args, x, *pstmts = (tree *) xstmts;
423   tree word_type_node;
424
425   if (! DECL_COMMON (h->base.from)
426       || (DECL_INITIAL (h->base.from)
427           && DECL_INITIAL (h->base.from) != error_mark_node))
428     return 1;
429
430   word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
431
432   /* The idea was to call get_emutls_init_templ_addr here, but if we
433      do this and there is an initializer, -fanchor_section loses,
434      because it would be too late to ensure the template is
435      output.  */
436   x = null_pointer_node;
437   args = tree_cons (NULL, x, NULL);
438   x = build_int_cst (word_type_node, DECL_ALIGN_UNIT (h->base.from));
439   args = tree_cons (NULL, x, args);
440   x = fold_convert (word_type_node, DECL_SIZE_UNIT (h->base.from));
441   args = tree_cons (NULL, x, args);
442   x = build_fold_addr_expr (h->to);
443   args = tree_cons (NULL, x, args);
444
445   x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
446   x = build_function_call_expr (UNKNOWN_LOCATION, x, args);
447
448   append_to_statement_list (x, pstmts);
449   return 1;
450 }
451
452 void
453 emutls_finish (void)
454 {
455   if (targetm.emutls.register_common)
456     {
457       tree body = NULL_TREE;
458
459       if (emutls_htab == NULL)
460         return;
461
462       htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
463       if (body == NULL_TREE)
464         return;
465
466       cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
467     }
468 }
469
470 /* Helper routines for maintaining section_htab.  */
471
472 static int
473 section_entry_eq (const void *p1, const void *p2)
474 {
475   const section *old = (const section *) p1;
476   const char *new_name = (const char *) p2;
477
478   return strcmp (old->named.name, new_name) == 0;
479 }
480
481 static hashval_t
482 section_entry_hash (const void *p)
483 {
484   const section *old = (const section *) p;
485   return htab_hash_string (old->named.name);
486 }
487
488 /* Return a hash value for section SECT.  */
489
490 static hashval_t
491 hash_section (section *sect)
492 {
493   if (sect->common.flags & SECTION_NAMED)
494     return htab_hash_string (sect->named.name);
495   return sect->common.flags;
496 }
497
498 /* Helper routines for maintaining object_block_htab.  */
499
500 static int
501 object_block_entry_eq (const void *p1, const void *p2)
502 {
503   const struct object_block *old = (const struct object_block *) p1;
504   const section *new_section = (const section *) p2;
505
506   return old->sect == new_section;
507 }
508
509 static hashval_t
510 object_block_entry_hash (const void *p)
511 {
512   const struct object_block *old = (const struct object_block *) p;
513   return hash_section (old->sect);
514 }
515
516 /* Return a new unnamed section with the given fields.  */
517
518 section *
519 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
520                      const void *data)
521 {
522   section *sect;
523
524   sect = GGC_NEW (section);
525   sect->unnamed.common.flags = flags | SECTION_UNNAMED;
526   sect->unnamed.callback = callback;
527   sect->unnamed.data = data;
528   sect->unnamed.next = unnamed_sections;
529
530   unnamed_sections = sect;
531   return sect;
532 }
533
534 /* Return a SECTION_NOSWITCH section with the given fields.  */
535
536 static section *
537 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
538 {
539   section *sect;
540
541   sect = GGC_NEW (section);
542   sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
543   sect->noswitch.callback = callback;
544
545   return sect;
546 }
547
548 /* Return the named section structure associated with NAME.  Create
549    a new section with the given fields if no such structure exists.  */
550
551 section *
552 get_section (const char *name, unsigned int flags, tree decl)
553 {
554   section *sect, **slot;
555
556   slot = (section **)
557     htab_find_slot_with_hash (section_htab, name,
558                               htab_hash_string (name), INSERT);
559   flags |= SECTION_NAMED;
560   if (*slot == NULL)
561     {
562       sect = GGC_NEW (section);
563       sect->named.common.flags = flags;
564       sect->named.name = ggc_strdup (name);
565       sect->named.decl = decl;
566       *slot = sect;
567     }
568   else
569     {
570       sect = *slot;
571       if ((sect->common.flags & ~SECTION_DECLARED) != flags
572           && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
573         {
574           /* Sanity check user variables for flag changes.  */
575           if (decl == 0)
576             decl = sect->named.decl;
577           gcc_assert (decl);
578           error ("%+D causes a section type conflict", decl);
579         }
580     }
581   return sect;
582 }
583
584 /* Return true if the current compilation mode benefits from having
585    objects grouped into blocks.  */
586
587 static bool
588 use_object_blocks_p (void)
589 {
590   return flag_section_anchors;
591 }
592
593 /* Return the object_block structure for section SECT.  Create a new
594    structure if we haven't created one already.  Return null if SECT
595    itself is null.  */
596
597 static struct object_block *
598 get_block_for_section (section *sect)
599 {
600   struct object_block *block;
601   void **slot;
602
603   if (sect == NULL)
604     return NULL;
605
606   slot = htab_find_slot_with_hash (object_block_htab, sect,
607                                    hash_section (sect), INSERT);
608   block = (struct object_block *) *slot;
609   if (block == NULL)
610     {
611       block = (struct object_block *)
612         ggc_alloc_cleared (sizeof (struct object_block));
613       block->sect = sect;
614       *slot = block;
615     }
616   return block;
617 }
618
619 /* Create a symbol with label LABEL and place it at byte offset
620    OFFSET in BLOCK.  OFFSET can be negative if the symbol's offset
621    is not yet known.  LABEL must be a garbage-collected string.  */
622
623 static rtx
624 create_block_symbol (const char *label, struct object_block *block,
625                      HOST_WIDE_INT offset)
626 {
627   rtx symbol;
628   unsigned int size;
629
630   /* Create the extended SYMBOL_REF.  */
631   size = RTX_HDR_SIZE + sizeof (struct block_symbol);
632   symbol = (rtx) ggc_alloc_zone (size, &rtl_zone);
633
634   /* Initialize the normal SYMBOL_REF fields.  */
635   memset (symbol, 0, size);
636   PUT_CODE (symbol, SYMBOL_REF);
637   PUT_MODE (symbol, Pmode);
638   XSTR (symbol, 0) = label;
639   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
640
641   /* Initialize the block_symbol stuff.  */
642   SYMBOL_REF_BLOCK (symbol) = block;
643   SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
644
645   return symbol;
646 }
647
648 static void
649 initialize_cold_section_name (void)
650 {
651   const char *stripped_name;
652   char *name, *buffer;
653   tree dsn;
654
655   gcc_assert (cfun && current_function_decl);
656   if (crtl->subsections.unlikely_text_section_name)
657     return;
658
659   dsn = DECL_SECTION_NAME (current_function_decl);
660   if (flag_function_sections && dsn)
661     {
662       name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
663       memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
664
665       stripped_name = targetm.strip_name_encoding (name);
666
667       buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
668       crtl->subsections.unlikely_text_section_name = ggc_strdup (buffer);
669     }
670   else
671     crtl->subsections.unlikely_text_section_name =  UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
672 }
673
674 /* Tell assembler to switch to unlikely-to-be-executed text section.  */
675
676 section *
677 unlikely_text_section (void)
678 {
679   if (cfun)
680     {
681       if (!crtl->subsections.unlikely_text_section_name)
682         initialize_cold_section_name ();
683
684       return get_named_section (NULL, crtl->subsections.unlikely_text_section_name, 0);
685     }
686   else
687     return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
688 }
689
690 /* When called within a function context, return true if the function
691    has been assigned a cold text section and if SECT is that section.
692    When called outside a function context, return true if SECT is the
693    default cold section.  */
694
695 bool
696 unlikely_text_section_p (section *sect)
697 {
698   const char *name;
699
700   if (cfun)
701     name = crtl->subsections.unlikely_text_section_name;
702   else
703     name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
704
705   return (name
706           && sect
707           && SECTION_STYLE (sect) == SECTION_NAMED
708           && strcmp (name, sect->named.name) == 0);
709 }
710
711 /* Return a section with a particular name and with whatever SECTION_*
712    flags section_type_flags deems appropriate.  The name of the section
713    is taken from NAME if nonnull, otherwise it is taken from DECL's
714    DECL_SECTION_NAME.  DECL is the decl associated with the section
715    (see the section comment for details) and RELOC is as for
716    section_type_flags.  */
717
718 section *
719 get_named_section (tree decl, const char *name, int reloc)
720 {
721   unsigned int flags;
722
723   gcc_assert (!decl || DECL_P (decl));
724   if (name == NULL)
725     name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
726
727   flags = targetm.section_type_flags (decl, name, reloc);
728
729   return get_section (name, flags, decl);
730 }
731
732 /* If required, set DECL_SECTION_NAME to a unique name.  */
733
734 void
735 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
736                         int flag_function_or_data_sections)
737 {
738   if (DECL_SECTION_NAME (decl) == NULL_TREE
739       && targetm.have_named_sections
740       && (flag_function_or_data_sections
741           || DECL_ONE_ONLY (decl)))
742     targetm.asm_out.unique_section (decl, reloc);
743 }
744
745 #ifdef BSS_SECTION_ASM_OP
746
747 #ifdef ASM_OUTPUT_BSS
748
749 /* Utility function for ASM_OUTPUT_BSS for targets to use if
750    they don't support alignments in .bss.
751    ??? It is believed that this function will work in most cases so such
752    support is localized here.  */
753
754 static void
755 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
756                 const char *name,
757                 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
758                 unsigned HOST_WIDE_INT rounded)
759 {
760   gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl), 0), 0), name) == 0);
761   targetm.asm_out.globalize_decl_name (file, decl);
762   switch_to_section (bss_section);
763 #ifdef ASM_DECLARE_OBJECT_NAME
764   last_assemble_variable_decl = decl;
765   ASM_DECLARE_OBJECT_NAME (file, name, decl);
766 #else
767   /* Standard thing is just output label for the object.  */
768   ASM_OUTPUT_LABEL (file, name);
769 #endif /* ASM_DECLARE_OBJECT_NAME */
770   ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
771 }
772
773 #endif
774
775 #ifdef ASM_OUTPUT_ALIGNED_BSS
776
777 /* Utility function for targets to use in implementing
778    ASM_OUTPUT_ALIGNED_BSS.
779    ??? It is believed that this function will work in most cases so such
780    support is localized here.  */
781
782 static void
783 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
784                         const char *name, unsigned HOST_WIDE_INT size,
785                         int align)
786 {
787   switch_to_section (bss_section);
788   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
789 #ifdef ASM_DECLARE_OBJECT_NAME
790   last_assemble_variable_decl = decl;
791   ASM_DECLARE_OBJECT_NAME (file, name, decl);
792 #else
793   /* Standard thing is just output label for the object.  */
794   ASM_OUTPUT_LABEL (file, name);
795 #endif /* ASM_DECLARE_OBJECT_NAME */
796   ASM_OUTPUT_SKIP (file, size ? size : 1);
797 }
798
799 #endif
800
801 #endif /* BSS_SECTION_ASM_OP */
802
803 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
804 /* Return the hot section for function DECL.  Return text_section for
805    null DECLs.  */
806
807 static section *
808 hot_function_section (tree decl)
809 {
810   if (decl != NULL_TREE
811       && DECL_SECTION_NAME (decl) != NULL_TREE
812       && targetm.have_named_sections)
813     return get_named_section (decl, NULL, 0);
814   else
815     return text_section;
816 }
817 #endif
818
819 /* Return the section for function DECL.
820
821    If DECL is NULL_TREE, return the text section.  We can be passed
822    NULL_TREE under some circumstances by dbxout.c at least.  */
823
824 section *
825 function_section (tree decl)
826 {
827   int reloc = 0;
828
829   if (first_function_block_is_cold)
830     reloc = 1;
831
832 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
833   if (decl != NULL_TREE
834       && DECL_SECTION_NAME (decl) != NULL_TREE)
835     return reloc ? unlikely_text_section ()
836                  : get_named_section (decl, NULL, 0);
837   else
838     return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
839 #else
840   return reloc ? unlikely_text_section () : hot_function_section (decl);
841 #endif
842 }
843
844 section *
845 current_function_section (void)
846 {
847 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
848   if (current_function_decl != NULL_TREE
849       && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
850     return in_cold_section_p ? unlikely_text_section ()
851                              : get_named_section (current_function_decl,
852                                                   NULL, 0);
853   else
854     return targetm.asm_out.select_section (current_function_decl,
855                                            in_cold_section_p,
856                                            DECL_ALIGN (current_function_decl));
857 #else
858   return (in_cold_section_p
859           ? unlikely_text_section ()
860           : hot_function_section (current_function_decl));
861 #endif
862 }
863
864 /* Return the read-only data section associated with function DECL.  */
865
866 section *
867 default_function_rodata_section (tree decl)
868 {
869   if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
870     {
871       const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
872
873       if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
874         {
875           const char *dot;
876           size_t len;
877           char* rname;
878
879           dot = strchr (name + 1, '.');
880           if (!dot)
881             dot = name;
882           len = strlen (dot) + 8;
883           rname = (char *) alloca (len);
884
885           strcpy (rname, ".rodata");
886           strcat (rname, dot);
887           return get_section (rname, SECTION_LINKONCE, decl);
888         }
889       /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo.  */
890       else if (DECL_ONE_ONLY (decl)
891                && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
892         {
893           size_t len = strlen (name) + 1;
894           char *rname = (char *) alloca (len);
895
896           memcpy (rname, name, len);
897           rname[14] = 'r';
898           return get_section (rname, SECTION_LINKONCE, decl);
899         }
900       /* For .text.foo we want to use .rodata.foo.  */
901       else if (flag_function_sections && flag_data_sections
902                && strncmp (name, ".text.", 6) == 0)
903         {
904           size_t len = strlen (name) + 1;
905           char *rname = (char *) alloca (len + 2);
906
907           memcpy (rname, ".rodata", 7);
908           memcpy (rname + 7, name + 5, len - 5);
909           return get_section (rname, 0, decl);
910         }
911     }
912
913   return readonly_data_section;
914 }
915
916 /* Return the read-only data section associated with function DECL
917    for targets where that section should be always the single
918    readonly data section.  */
919
920 section *
921 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
922 {
923   return readonly_data_section;
924 }
925
926 /* Return the section to use for string merging.  */
927
928 static section *
929 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
930                           unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
931                           unsigned int flags ATTRIBUTE_UNUSED)
932 {
933   HOST_WIDE_INT len;
934
935   if (HAVE_GAS_SHF_MERGE && flag_merge_constants
936       && TREE_CODE (decl) == STRING_CST
937       && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
938       && align <= 256
939       && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
940       && TREE_STRING_LENGTH (decl) >= len)
941     {
942       enum machine_mode mode;
943       unsigned int modesize;
944       const char *str;
945       HOST_WIDE_INT i;
946       int j, unit;
947       char name[30];
948
949       mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
950       modesize = GET_MODE_BITSIZE (mode);
951       if (modesize >= 8 && modesize <= 256
952           && (modesize & (modesize - 1)) == 0)
953         {
954           if (align < modesize)
955             align = modesize;
956
957           str = TREE_STRING_POINTER (decl);
958           unit = GET_MODE_SIZE (mode);
959
960           /* Check for embedded NUL characters.  */
961           for (i = 0; i < len; i += unit)
962             {
963               for (j = 0; j < unit; j++)
964                 if (str[i + j] != '\0')
965                   break;
966               if (j == unit)
967                 break;
968             }
969           if (i == len - unit)
970             {
971               sprintf (name, ".rodata.str%d.%d", modesize / 8,
972                        (int) (align / 8));
973               flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
974               return get_section (name, flags, NULL);
975             }
976         }
977     }
978
979   return readonly_data_section;
980 }
981
982 /* Return the section to use for constant merging.  */
983
984 section *
985 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
986                             unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
987                             unsigned int flags ATTRIBUTE_UNUSED)
988 {
989   unsigned int modesize = GET_MODE_BITSIZE (mode);
990
991   if (HAVE_GAS_SHF_MERGE && flag_merge_constants
992       && mode != VOIDmode
993       && mode != BLKmode
994       && modesize <= align
995       && align >= 8
996       && align <= 256
997       && (align & (align - 1)) == 0)
998     {
999       char name[24];
1000
1001       sprintf (name, ".rodata.cst%d", (int) (align / 8));
1002       flags |= (align / 8) | SECTION_MERGE;
1003       return get_section (name, flags, NULL);
1004     }
1005   return readonly_data_section;
1006 }
1007 \f
1008 /* Given NAME, a putative register name, discard any customary prefixes.  */
1009
1010 static const char *
1011 strip_reg_name (const char *name)
1012 {
1013 #ifdef REGISTER_PREFIX
1014   if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
1015     name += strlen (REGISTER_PREFIX);
1016 #endif
1017   if (name[0] == '%' || name[0] == '#')
1018     name++;
1019   return name;
1020 }
1021 \f
1022 /* The user has asked for a DECL to have a particular name.  Set (or
1023    change) it in such a way that we don't prefix an underscore to
1024    it.  */
1025 void
1026 set_user_assembler_name (tree decl, const char *name)
1027 {
1028   char *starred = (char *) alloca (strlen (name) + 2);
1029   starred[0] = '*';
1030   strcpy (starred + 1, name);
1031   change_decl_assembler_name (decl, get_identifier (starred));
1032   SET_DECL_RTL (decl, NULL_RTX);
1033 }
1034 \f
1035 /* Decode an `asm' spec for a declaration as a register name.
1036    Return the register number, or -1 if nothing specified,
1037    or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1038    or -3 if ASMSPEC is `cc' and is not recognized,
1039    or -4 if ASMSPEC is `memory' and is not recognized.
1040    Accept an exact spelling or a decimal number.
1041    Prefixes such as % are optional.  */
1042
1043 int
1044 decode_reg_name (const char *asmspec)
1045 {
1046   if (asmspec != 0)
1047     {
1048       int i;
1049
1050       /* Get rid of confusing prefixes.  */
1051       asmspec = strip_reg_name (asmspec);
1052
1053       /* Allow a decimal number as a "register name".  */
1054       for (i = strlen (asmspec) - 1; i >= 0; i--)
1055         if (! ISDIGIT (asmspec[i]))
1056           break;
1057       if (asmspec[0] != 0 && i < 0)
1058         {
1059           i = atoi (asmspec);
1060           if (i < FIRST_PSEUDO_REGISTER && i >= 0)
1061             return i;
1062           else
1063             return -2;
1064         }
1065
1066       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1067         if (reg_names[i][0]
1068             && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1069           return i;
1070
1071 #ifdef ADDITIONAL_REGISTER_NAMES
1072       {
1073         static const struct { const char *const name; const int number; } table[]
1074           = ADDITIONAL_REGISTER_NAMES;
1075
1076         for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1077           if (table[i].name[0]
1078               && ! strcmp (asmspec, table[i].name))
1079             return table[i].number;
1080       }
1081 #endif /* ADDITIONAL_REGISTER_NAMES */
1082
1083       if (!strcmp (asmspec, "memory"))
1084         return -4;
1085
1086       if (!strcmp (asmspec, "cc"))
1087         return -3;
1088
1089       return -2;
1090     }
1091
1092   return -1;
1093 }
1094 \f
1095 /* Return true if DECL's initializer is suitable for a BSS section.  */
1096
1097 static bool
1098 bss_initializer_p (const_tree decl)
1099 {
1100   return (DECL_INITIAL (decl) == NULL
1101           || DECL_INITIAL (decl) == error_mark_node
1102           || (flag_zero_initialized_in_bss
1103               /* Leave constant zeroes in .rodata so they
1104                  can be shared.  */
1105               && !TREE_READONLY (decl)
1106               && initializer_zerop (DECL_INITIAL (decl))));
1107 }
1108
1109 /* Compute the alignment of variable specified by DECL.
1110    DONT_OUTPUT_DATA is from assemble_variable.  */
1111
1112 void
1113 align_variable (tree decl, bool dont_output_data)
1114 {
1115   unsigned int align = DECL_ALIGN (decl);
1116
1117   /* In the case for initialing an array whose length isn't specified,
1118      where we have not yet been able to do the layout,
1119      figure out the proper alignment now.  */
1120   if (dont_output_data && DECL_SIZE (decl) == 0
1121       && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1122     align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1123
1124   /* Some object file formats have a maximum alignment which they support.
1125      In particular, a.out format supports a maximum alignment of 4.  */
1126   if (align > MAX_OFILE_ALIGNMENT)
1127     {
1128       warning (0, "alignment of %q+D is greater than maximum object "
1129                "file alignment.  Using %d", decl,
1130                MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1131       align = MAX_OFILE_ALIGNMENT;
1132     }
1133
1134   /* On some machines, it is good to increase alignment sometimes.  */
1135   if (! DECL_USER_ALIGN (decl))
1136     {
1137 #ifdef DATA_ALIGNMENT
1138       unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1139       /* Don't increase alignment too much for TLS variables - TLS space
1140          is too precious.  */
1141       if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1142         align = data_align;
1143 #endif
1144 #ifdef CONSTANT_ALIGNMENT
1145       if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1146         {
1147           unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
1148                                                          align);
1149           /* Don't increase alignment too much for TLS variables - TLS space
1150              is too precious.  */
1151           if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1152             align = const_align;
1153         }
1154 #endif
1155     }
1156
1157   /* Reset the alignment in case we have made it tighter, so we can benefit
1158      from it in get_pointer_alignment.  */
1159   DECL_ALIGN (decl) = align;
1160 }
1161
1162 /* Return the section into which the given VAR_DECL or CONST_DECL
1163    should be placed.  PREFER_NOSWITCH_P is true if a noswitch
1164    section should be used wherever possible.  */
1165
1166 static section *
1167 get_variable_section (tree decl, bool prefer_noswitch_p)
1168 {
1169   addr_space_t as = ADDR_SPACE_GENERIC;
1170   int reloc;
1171
1172   if (TREE_TYPE (decl) != error_mark_node)
1173     as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1174
1175   if (DECL_COMMON (decl))
1176     {
1177       /* If the decl has been given an explicit section name, or it resides
1178          in a non-generic address space, then it isn't common, and shouldn't
1179          be handled as such.  */
1180       gcc_assert (DECL_SECTION_NAME (decl) == NULL
1181                   && ADDR_SPACE_GENERIC_P (as));
1182       if (DECL_THREAD_LOCAL_P (decl))
1183         return tls_comm_section;
1184       /* This cannot be common bss for an emulated TLS object without
1185          a register_common hook.  */
1186       else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED
1187                && !targetm.emutls.register_common)
1188         ;
1189       else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1190         return comm_section;
1191     }
1192
1193   if (DECL_INITIAL (decl) == error_mark_node)
1194     reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1195   else if (DECL_INITIAL (decl))
1196     reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1197   else
1198     reloc = 0;
1199
1200   resolve_unique_section (decl, reloc, flag_data_sections);
1201   if (IN_NAMED_SECTION (decl))
1202     return get_named_section (decl, NULL, reloc);
1203
1204   if (ADDR_SPACE_GENERIC_P (as)
1205       && !DECL_THREAD_LOCAL_P (decl)
1206       && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1207       && bss_initializer_p (decl))
1208     {
1209       if (!TREE_PUBLIC (decl))
1210         return lcomm_section;
1211       if (bss_noswitch_section)
1212         return bss_noswitch_section;
1213     }
1214
1215   return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1216 }
1217
1218 /* Return the block into which object_block DECL should be placed.  */
1219
1220 static struct object_block *
1221 get_block_for_decl (tree decl)
1222 {
1223   section *sect;
1224
1225   if (TREE_CODE (decl) == VAR_DECL)
1226     {
1227       /* The object must be defined in this translation unit.  */
1228       if (DECL_EXTERNAL (decl))
1229         return NULL;
1230
1231       /* There's no point using object blocks for something that is
1232          isolated by definition.  */
1233       if (DECL_ONE_ONLY (decl))
1234         return NULL;
1235     }
1236
1237   /* We can only calculate block offsets if the decl has a known
1238      constant size.  */
1239   if (DECL_SIZE_UNIT (decl) == NULL)
1240     return NULL;
1241   if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1242     return NULL;
1243
1244   /* Find out which section should contain DECL.  We cannot put it into
1245      an object block if it requires a standalone definition.  */
1246   if (TREE_CODE (decl) == VAR_DECL)
1247       align_variable (decl, 0);
1248   sect = get_variable_section (decl, true);
1249   if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1250     return NULL;
1251
1252   return get_block_for_section (sect);
1253 }
1254
1255 /* Make sure block symbol SYMBOL is in block BLOCK.  */
1256
1257 static void
1258 change_symbol_block (rtx symbol, struct object_block *block)
1259 {
1260   if (block != SYMBOL_REF_BLOCK (symbol))
1261     {
1262       gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1263       SYMBOL_REF_BLOCK (symbol) = block;
1264     }
1265 }
1266
1267 /* Return true if it is possible to put DECL in an object_block.  */
1268
1269 static bool
1270 use_blocks_for_decl_p (tree decl)
1271 {
1272   /* Only data DECLs can be placed into object blocks.  */
1273   if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1274     return false;
1275
1276   /* Detect decls created by dw2_force_const_mem.  Such decls are
1277      special because DECL_INITIAL doesn't specify the decl's true value.
1278      dw2_output_indirect_constants will instead call assemble_variable
1279      with dont_output_data set to 1 and then print the contents itself.  */
1280   if (DECL_INITIAL (decl) == decl)
1281     return false;
1282
1283   /* If this decl is an alias, then we don't want to emit a definition.  */
1284   if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1285     return false;
1286
1287   return true;
1288 }
1289
1290 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL.  DECL should
1291    have static storage duration.  In other words, it should not be an
1292    automatic variable, including PARM_DECLs.
1293
1294    There is, however, one exception: this function handles variables
1295    explicitly placed in a particular register by the user.
1296
1297    This is never called for PARM_DECL nodes.  */
1298
1299 void
1300 make_decl_rtl (tree decl)
1301 {
1302   const char *name = 0;
1303   int reg_number;
1304   rtx x;
1305
1306   /* Check that we are not being given an automatic variable.  */
1307   gcc_assert (TREE_CODE (decl) != PARM_DECL
1308               && TREE_CODE (decl) != RESULT_DECL);
1309
1310   /* A weak alias has TREE_PUBLIC set but not the other bits.  */
1311   gcc_assert (TREE_CODE (decl) != VAR_DECL
1312               || TREE_STATIC (decl)
1313               || TREE_PUBLIC (decl)
1314               || DECL_EXTERNAL (decl)
1315               || DECL_REGISTER (decl));
1316
1317   /* And that we were not given a type or a label.  */
1318   gcc_assert (TREE_CODE (decl) != TYPE_DECL
1319               && TREE_CODE (decl) != LABEL_DECL);
1320
1321   /* For a duplicate declaration, we can be called twice on the
1322      same DECL node.  Don't discard the RTL already made.  */
1323   if (DECL_RTL_SET_P (decl))
1324     {
1325       /* If the old RTL had the wrong mode, fix the mode.  */
1326       x = DECL_RTL (decl);
1327       if (GET_MODE (x) != DECL_MODE (decl))
1328         SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1329
1330       if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1331         return;
1332
1333       /* ??? Another way to do this would be to maintain a hashed
1334          table of such critters.  Instead of adding stuff to a DECL
1335          to give certain attributes to it, we could use an external
1336          hash map from DECL to set of attributes.  */
1337
1338       /* Let the target reassign the RTL if it wants.
1339          This is necessary, for example, when one machine specific
1340          decl attribute overrides another.  */
1341       targetm.encode_section_info (decl, DECL_RTL (decl), false);
1342
1343       /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1344          on the new decl information.  */
1345       if (MEM_P (x)
1346           && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1347           && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1348         change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1349
1350       /* Make this function static known to the mudflap runtime.  */
1351       if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1352         mudflap_enqueue_decl (decl);
1353
1354       return;
1355     }
1356
1357   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1358
1359   if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1360       && DECL_REGISTER (decl))
1361     {
1362       error ("register name not specified for %q+D", decl);
1363     }
1364   else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1365     {
1366       const char *asmspec = name+1;
1367       reg_number = decode_reg_name (asmspec);
1368       /* First detect errors in declaring global registers.  */
1369       if (reg_number == -1)
1370         error ("register name not specified for %q+D", decl);
1371       else if (reg_number < 0)
1372         error ("invalid register name for %q+D", decl);
1373       else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1374         error ("data type of %q+D isn%'t suitable for a register",
1375                decl);
1376       else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1377         error ("register specified for %q+D isn%'t suitable for data type",
1378                decl);
1379       /* Now handle properly declared static register variables.  */
1380       else
1381         {
1382           int nregs;
1383
1384           if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1385             {
1386               DECL_INITIAL (decl) = 0;
1387               error ("global register variable has initial value");
1388             }
1389           if (TREE_THIS_VOLATILE (decl))
1390             warning (OPT_Wvolatile_register_var,
1391                      "optimization may eliminate reads and/or "
1392                      "writes to register variables");
1393
1394           /* If the user specified one of the eliminables registers here,
1395              e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1396              confused with that register and be eliminated.  This usage is
1397              somewhat suspect...  */
1398
1399           SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1400           ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1401           REG_USERVAR_P (DECL_RTL (decl)) = 1;
1402
1403           if (TREE_STATIC (decl))
1404             {
1405               /* Make this register global, so not usable for anything
1406                  else.  */
1407 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1408               name = IDENTIFIER_POINTER (DECL_NAME (decl));
1409               ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1410 #endif
1411               nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1412               while (nregs > 0)
1413                 globalize_reg (reg_number + --nregs);
1414             }
1415
1416           /* As a register variable, it has no section.  */
1417           return;
1418         }
1419     }
1420   /* Now handle ordinary static variables and functions (in memory).
1421      Also handle vars declared register invalidly.  */
1422   else if (name[0] == '*')
1423   {
1424 #ifdef REGISTER_PREFIX
1425     if (strlen (REGISTER_PREFIX) != 0)
1426       {
1427         reg_number = decode_reg_name (name);
1428         if (reg_number >= 0 || reg_number == -3)
1429           error ("register name given for non-register variable %q+D", decl);
1430       }
1431 #endif
1432   }
1433
1434   /* Specifying a section attribute on a variable forces it into a
1435      non-.bss section, and thus it cannot be common.  */
1436   /* FIXME: In general this code should not be necessary because
1437      visibility pass is doing the same work.  But notice_global_symbol
1438      is called early and it needs to make DECL_RTL to get the name.
1439      we take care of recomputing the DECL_RTL after visibility is changed.  */
1440   if (TREE_CODE (decl) == VAR_DECL
1441       && DECL_SECTION_NAME (decl) != NULL_TREE
1442       && DECL_INITIAL (decl) == NULL_TREE
1443       && DECL_COMMON (decl))
1444     DECL_COMMON (decl) = 0;
1445
1446   /* Variables can't be both common and weak.  */
1447   if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1448     DECL_COMMON (decl) = 0;
1449
1450   if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1451     x = create_block_symbol (name, get_block_for_decl (decl), -1);
1452   else
1453     {
1454       enum machine_mode address_mode = Pmode;
1455       if (TREE_TYPE (decl) != error_mark_node)
1456         {
1457           addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1458           address_mode = targetm.addr_space.address_mode (as);
1459         }
1460       x = gen_rtx_SYMBOL_REF (address_mode, name);
1461     }
1462   SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1463   SET_SYMBOL_REF_DECL (x, decl);
1464
1465   x = gen_rtx_MEM (DECL_MODE (decl), x);
1466   if (TREE_CODE (decl) != FUNCTION_DECL)
1467     set_mem_attributes (x, decl, 1);
1468   SET_DECL_RTL (decl, x);
1469
1470   /* Optionally set flags or add text to the name to record information
1471      such as that it is a function name.
1472      If the name is changed, the macro ASM_OUTPUT_LABELREF
1473      will have to know how to strip this information.  */
1474   targetm.encode_section_info (decl, DECL_RTL (decl), true);
1475
1476   /* Make this function static known to the mudflap runtime.  */
1477   if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1478     mudflap_enqueue_decl (decl);
1479 }
1480
1481 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1482    calling make_decl_rtl.  Also, reset DECL_RTL before returning the
1483    rtl.  */
1484
1485 rtx
1486 make_decl_rtl_for_debug (tree decl)
1487 {
1488   unsigned int save_aliasing_flag, save_mudflap_flag;
1489   rtx rtl;
1490
1491   if (DECL_RTL_SET_P (decl))
1492     return DECL_RTL (decl);
1493
1494   /* Kludge alert!  Somewhere down the call chain, make_decl_rtl will
1495      call new_alias_set.  If running with -fcompare-debug, sometimes
1496      we do not want to create alias sets that will throw the alias
1497      numbers off in the comparison dumps.  So... clearing
1498      flag_strict_aliasing will keep new_alias_set() from creating a
1499      new set.  It is undesirable to register decl with mudflap
1500      in this case as well.  */
1501   save_aliasing_flag = flag_strict_aliasing;
1502   flag_strict_aliasing = 0;
1503   save_mudflap_flag = flag_mudflap;
1504   flag_mudflap = 0;
1505
1506   rtl = DECL_RTL (decl);
1507   /* Reset DECL_RTL back, as various parts of the compiler expects
1508      DECL_RTL set meaning it is actually going to be output.  */
1509   SET_DECL_RTL (decl, NULL);
1510
1511   flag_strict_aliasing = save_aliasing_flag;
1512   flag_mudflap = save_mudflap_flag;
1513
1514   return rtl;
1515 }
1516 \f
1517 /* Output a string of literal assembler code
1518    for an `asm' keyword used between functions.  */
1519
1520 void
1521 assemble_asm (tree string)
1522 {
1523   app_enable ();
1524
1525   if (TREE_CODE (string) == ADDR_EXPR)
1526     string = TREE_OPERAND (string, 0);
1527
1528   fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1529 }
1530
1531 /* Record an element in the table of global destructors.  SYMBOL is
1532    a SYMBOL_REF of the function to be called; PRIORITY is a number
1533    between 0 and MAX_INIT_PRIORITY.  */
1534
1535 void
1536 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1537                                   int priority ATTRIBUTE_UNUSED)
1538 {
1539 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1540   /* Tell GNU LD that this is part of the static destructor set.
1541      This will work for any system that uses stabs, most usefully
1542      aout systems.  */
1543   dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1544   dbxout_stab_value_label (XSTR (symbol, 0));
1545 #else
1546   sorry ("global destructors not supported on this target");
1547 #endif
1548 }
1549
1550 /* Write the address of the entity given by SYMBOL to SEC.  */
1551 void
1552 assemble_addr_to_section (rtx symbol, section *sec)
1553 {
1554   switch_to_section (sec);
1555   assemble_align (POINTER_SIZE);
1556   assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1557 }
1558
1559 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1560    not) section for PRIORITY.  */
1561 section *
1562 get_cdtor_priority_section (int priority, bool constructor_p)
1563 {
1564   char buf[16];
1565
1566   /* ??? This only works reliably with the GNU linker.  */
1567   sprintf (buf, "%s.%.5u",
1568            constructor_p ? ".ctors" : ".dtors",
1569            /* Invert the numbering so the linker puts us in the proper
1570               order; constructors are run from right to left, and the
1571               linker sorts in increasing order.  */
1572            MAX_INIT_PRIORITY - priority);
1573   return get_section (buf, SECTION_WRITE, NULL);
1574 }
1575
1576 void
1577 default_named_section_asm_out_destructor (rtx symbol, int priority)
1578 {
1579   section *sec;
1580
1581   if (priority != DEFAULT_INIT_PRIORITY)
1582     sec = get_cdtor_priority_section (priority,
1583                                       /*constructor_p=*/false);
1584   else
1585     sec = get_section (".dtors", SECTION_WRITE, NULL);
1586
1587   assemble_addr_to_section (symbol, sec);
1588 }
1589
1590 #ifdef DTORS_SECTION_ASM_OP
1591 void
1592 default_dtor_section_asm_out_destructor (rtx symbol,
1593                                          int priority ATTRIBUTE_UNUSED)
1594 {
1595   assemble_addr_to_section (symbol, dtors_section);
1596 }
1597 #endif
1598
1599 /* Likewise for global constructors.  */
1600
1601 void
1602 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1603                                    int priority ATTRIBUTE_UNUSED)
1604 {
1605 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1606   /* Tell GNU LD that this is part of the static destructor set.
1607      This will work for any system that uses stabs, most usefully
1608      aout systems.  */
1609   dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1610   dbxout_stab_value_label (XSTR (symbol, 0));
1611 #else
1612   sorry ("global constructors not supported on this target");
1613 #endif
1614 }
1615
1616 void
1617 default_named_section_asm_out_constructor (rtx symbol, int priority)
1618 {
1619   section *sec;
1620
1621   if (priority != DEFAULT_INIT_PRIORITY)
1622     sec = get_cdtor_priority_section (priority,
1623                                       /*constructor_p=*/true);
1624   else
1625     sec = get_section (".ctors", SECTION_WRITE, NULL);
1626
1627   assemble_addr_to_section (symbol, sec);
1628 }
1629
1630 #ifdef CTORS_SECTION_ASM_OP
1631 void
1632 default_ctor_section_asm_out_constructor (rtx symbol,
1633                                           int priority ATTRIBUTE_UNUSED)
1634 {
1635   assemble_addr_to_section (symbol, ctors_section);
1636 }
1637 #endif
1638 \f
1639 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1640    a nonzero value if the constant pool should be output before the
1641    start of the function, or a zero value if the pool should output
1642    after the end of the function.  The default is to put it before the
1643    start.  */
1644
1645 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1646 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1647 #endif
1648
1649 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1650    to be output to assembler.
1651    Set first_global_object_name and weak_global_object_name as appropriate.  */
1652
1653 void
1654 notice_global_symbol (tree decl)
1655 {
1656   const char **type = &first_global_object_name;
1657
1658   if (first_global_object_name
1659       || !TREE_PUBLIC (decl)
1660       || DECL_EXTERNAL (decl)
1661       || !DECL_NAME (decl)
1662       || (TREE_CODE (decl) != FUNCTION_DECL
1663           && (TREE_CODE (decl) != VAR_DECL
1664               || (DECL_COMMON (decl)
1665                   && (DECL_INITIAL (decl) == 0
1666                       || DECL_INITIAL (decl) == error_mark_node))))
1667       || !MEM_P (DECL_RTL (decl)))
1668     return;
1669
1670   /* We win when global object is found, but it is useful to know about weak
1671      symbol as well so we can produce nicer unique names.  */
1672   if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1673     type = &weak_global_object_name;
1674
1675   if (!*type)
1676     {
1677       const char *p;
1678       const char *name;
1679       rtx decl_rtl = DECL_RTL (decl);
1680
1681       p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1682       name = ggc_strdup (p);
1683
1684       *type = name;
1685     }
1686 }
1687
1688 /* Output assembler code for the constant pool of a function and associated
1689    with defining the name of the function.  DECL describes the function.
1690    NAME is the function's name.  For the constant pool, we use the current
1691    constant pool data.  */
1692
1693 void
1694 assemble_start_function (tree decl, const char *fnname)
1695 {
1696   int align;
1697   char tmp_label[100];
1698   bool hot_label_written = false;
1699
1700   crtl->subsections.unlikely_text_section_name = NULL;
1701
1702   first_function_block_is_cold = false;
1703   if (flag_reorder_blocks_and_partition)
1704     {
1705       ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1706       crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1707       ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1708       crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1709       ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1710       crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1711       ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1712       crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1713       const_labelno++;
1714     }
1715   else
1716     {
1717       crtl->subsections.hot_section_label = NULL;
1718       crtl->subsections.cold_section_label = NULL;
1719       crtl->subsections.hot_section_end_label = NULL;
1720       crtl->subsections.cold_section_end_label = NULL;
1721     }
1722
1723   /* The following code does not need preprocessing in the assembler.  */
1724
1725   app_disable ();
1726
1727   if (CONSTANT_POOL_BEFORE_FUNCTION)
1728     output_constant_pool (fnname, decl);
1729
1730   resolve_unique_section (decl, 0, flag_function_sections);
1731
1732   /* Make sure the not and cold text (code) sections are properly
1733      aligned.  This is necessary here in the case where the function
1734      has both hot and cold sections, because we don't want to re-set
1735      the alignment when the section switch happens mid-function.  */
1736
1737   if (flag_reorder_blocks_and_partition)
1738     {
1739       switch_to_section (unlikely_text_section ());
1740       assemble_align (DECL_ALIGN (decl));
1741       ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1742
1743       /* When the function starts with a cold section, we need to explicitly
1744          align the hot section and write out the hot section label.
1745          But if the current function is a thunk, we do not have a CFG.  */
1746       if (!cfun->is_thunk
1747           && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1748         {
1749           switch_to_section (text_section);
1750           assemble_align (DECL_ALIGN (decl));
1751           ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1752           hot_label_written = true;
1753           first_function_block_is_cold = true;
1754         }
1755     }
1756   else if (DECL_SECTION_NAME (decl))
1757     {
1758       /* Calls to function_section rely on first_function_block_is_cold
1759          being accurate.  The first block may be cold even if we aren't
1760          doing partitioning, if the entire function was decided by
1761          choose_function_section (predict.c) to be cold.  */
1762
1763       initialize_cold_section_name ();
1764
1765       if (crtl->subsections.unlikely_text_section_name
1766           && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1767                      crtl->subsections.unlikely_text_section_name) == 0)
1768         first_function_block_is_cold = true;
1769     }
1770
1771   in_cold_section_p = first_function_block_is_cold;
1772
1773   /* Switch to the correct text section for the start of the function.  */
1774
1775   switch_to_section (function_section (decl));
1776   if (flag_reorder_blocks_and_partition
1777       && !hot_label_written)
1778     ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1779
1780   /* Tell assembler to move to target machine's alignment for functions.  */
1781   align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1782   if (align > 0)
1783     {
1784       ASM_OUTPUT_ALIGN (asm_out_file, align);
1785     }
1786
1787   /* Handle a user-specified function alignment.
1788      Note that we still need to align to DECL_ALIGN, as above,
1789      because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all.  */
1790   if (! DECL_USER_ALIGN (decl)
1791       && align_functions_log > align
1792       && optimize_function_for_speed_p (cfun))
1793     {
1794 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1795       ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1796                                  align_functions_log, align_functions - 1);
1797 #else
1798       ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1799 #endif
1800     }
1801
1802 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1803   ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1804 #endif
1805
1806   if (!DECL_IGNORED_P (decl))
1807     (*debug_hooks->begin_function) (decl);
1808
1809   /* Make function name accessible from other files, if appropriate.  */
1810
1811   if (TREE_PUBLIC (decl))
1812     {
1813       notice_global_symbol (decl);
1814
1815       globalize_decl (decl);
1816
1817       maybe_assemble_visibility (decl);
1818     }
1819
1820   if (DECL_PRESERVE_P (decl))
1821     targetm.asm_out.mark_decl_preserved (fnname);
1822
1823   /* Do any machine/system dependent processing of the function name.  */
1824 #ifdef ASM_DECLARE_FUNCTION_NAME
1825   ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1826 #else
1827   /* Standard thing is just output label for the function.  */
1828   ASM_OUTPUT_LABEL (asm_out_file, fnname);
1829 #endif /* ASM_DECLARE_FUNCTION_NAME */
1830 }
1831
1832 /* Output assembler code associated with defining the size of the
1833    function.  DECL describes the function.  NAME is the function's name.  */
1834
1835 void
1836 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1837 {
1838 #ifdef ASM_DECLARE_FUNCTION_SIZE
1839   /* We could have switched section in the middle of the function.  */
1840   if (flag_reorder_blocks_and_partition)
1841     switch_to_section (function_section (decl));
1842   ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1843 #endif
1844   if (! CONSTANT_POOL_BEFORE_FUNCTION)
1845     {
1846       output_constant_pool (fnname, decl);
1847       switch_to_section (function_section (decl)); /* need to switch back */
1848     }
1849   /* Output labels for end of hot/cold text sections (to be used by
1850      debug info.)  */
1851   if (flag_reorder_blocks_and_partition)
1852     {
1853       section *save_text_section;
1854
1855       save_text_section = in_section;
1856       switch_to_section (unlikely_text_section ());
1857       ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1858       if (first_function_block_is_cold)
1859         switch_to_section (text_section);
1860       else
1861         switch_to_section (function_section (decl));
1862       ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1863       switch_to_section (save_text_section);
1864     }
1865 }
1866 \f
1867 /* Assemble code to leave SIZE bytes of zeros.  */
1868
1869 void
1870 assemble_zeros (unsigned HOST_WIDE_INT size)
1871 {
1872   /* Do no output if -fsyntax-only.  */
1873   if (flag_syntax_only)
1874     return;
1875
1876 #ifdef ASM_NO_SKIP_IN_TEXT
1877   /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1878      so we must output 0s explicitly in the text section.  */
1879   if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1880     {
1881       unsigned HOST_WIDE_INT i;
1882       for (i = 0; i < size; i++)
1883         assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1884     }
1885   else
1886 #endif
1887     if (size > 0)
1888       ASM_OUTPUT_SKIP (asm_out_file, size);
1889 }
1890
1891 /* Assemble an alignment pseudo op for an ALIGN-bit boundary.  */
1892
1893 void
1894 assemble_align (int align)
1895 {
1896   if (align > BITS_PER_UNIT)
1897     {
1898       ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1899     }
1900 }
1901
1902 /* Assemble a string constant with the specified C string as contents.  */
1903
1904 void
1905 assemble_string (const char *p, int size)
1906 {
1907   int pos = 0;
1908   int maximum = 2000;
1909
1910   /* If the string is very long, split it up.  */
1911
1912   while (pos < size)
1913     {
1914       int thissize = size - pos;
1915       if (thissize > maximum)
1916         thissize = maximum;
1917
1918       ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1919
1920       pos += thissize;
1921       p += thissize;
1922     }
1923 }
1924
1925 \f
1926 /* A noswitch_section_callback for lcomm_section.  */
1927
1928 static bool
1929 emit_local (tree decl ATTRIBUTE_UNUSED,
1930             const char *name ATTRIBUTE_UNUSED,
1931             unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1932             unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1933 {
1934 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1935   ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1936                                  size, DECL_ALIGN (decl));
1937   return true;
1938 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1939   ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1940   return true;
1941 #else
1942   ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1943   return false;
1944 #endif
1945 }
1946
1947 /* A noswitch_section_callback for bss_noswitch_section.  */
1948
1949 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1950 static bool
1951 emit_bss (tree decl ATTRIBUTE_UNUSED,
1952           const char *name ATTRIBUTE_UNUSED,
1953           unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1954           unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1955 {
1956 #if defined ASM_OUTPUT_ALIGNED_BSS
1957   ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1958   return true;
1959 #else
1960   ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1961   return false;
1962 #endif
1963 }
1964 #endif
1965
1966 /* A noswitch_section_callback for comm_section.  */
1967
1968 static bool
1969 emit_common (tree decl ATTRIBUTE_UNUSED,
1970              const char *name ATTRIBUTE_UNUSED,
1971              unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1972              unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1973 {
1974 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1975   ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1976                                   size, DECL_ALIGN (decl));
1977   return true;
1978 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1979   ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1980   return true;
1981 #else
1982   ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1983   return false;
1984 #endif
1985 }
1986
1987 /* A noswitch_section_callback for tls_comm_section.  */
1988
1989 static bool
1990 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1991                  const char *name ATTRIBUTE_UNUSED,
1992                  unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1993                  unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1994 {
1995 #ifdef ASM_OUTPUT_TLS_COMMON
1996   ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1997   return true;
1998 #else
1999   sorry ("thread-local COMMON data not implemented");
2000   return true;
2001 #endif
2002 }
2003
2004 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2005    NAME is the name of DECL's SYMBOL_REF.  */
2006
2007 static void
2008 assemble_noswitch_variable (tree decl, const char *name, section *sect)
2009 {
2010   unsigned HOST_WIDE_INT size, rounded;
2011
2012   size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
2013   rounded = size;
2014
2015   /* Don't allocate zero bytes of common,
2016      since that means "undefined external" in the linker.  */
2017   if (size == 0)
2018     rounded = 1;
2019
2020   /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2021      so that each uninitialized object starts on such a boundary.  */
2022   rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
2023   rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2024              * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2025
2026   if (!sect->noswitch.callback (decl, name, size, rounded)
2027       && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
2028     warning (0, "requested alignment for %q+D is greater than "
2029              "implemented alignment of %wu", decl, rounded);
2030 }
2031
2032 /* A subroutine of assemble_variable.  Output the label and contents of
2033    DECL, whose address is a SYMBOL_REF with name NAME.  DONT_OUTPUT_DATA
2034    is as for assemble_variable.  */
2035
2036 static void
2037 assemble_variable_contents (tree decl, const char *name,
2038                             bool dont_output_data)
2039 {
2040   /* Do any machine/system dependent processing of the object.  */
2041 #ifdef ASM_DECLARE_OBJECT_NAME
2042   last_assemble_variable_decl = decl;
2043   ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
2044 #else
2045   /* Standard thing is just output label for the object.  */
2046   ASM_OUTPUT_LABEL (asm_out_file, name);
2047 #endif /* ASM_DECLARE_OBJECT_NAME */
2048
2049   if (!dont_output_data)
2050     {
2051       if (DECL_INITIAL (decl)
2052           && DECL_INITIAL (decl) != error_mark_node
2053           && !initializer_zerop (DECL_INITIAL (decl)))
2054         /* Output the actual data.  */
2055         output_constant (DECL_INITIAL (decl),
2056                          tree_low_cst (DECL_SIZE_UNIT (decl), 1),
2057                          DECL_ALIGN (decl));
2058       else
2059         /* Leave space for it.  */
2060         assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
2061     }
2062 }
2063
2064 /* Initialize emulated tls object TO, which refers to TLS variable
2065    DECL and is initialized by PROXY.  */
2066
2067 tree
2068 default_emutls_var_init (tree to, tree decl, tree proxy)
2069 {
2070   VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4);
2071   constructor_elt *elt;
2072   tree type = TREE_TYPE (to);
2073   tree field = TYPE_FIELDS (type);
2074
2075   elt = VEC_quick_push (constructor_elt, v, NULL);
2076   elt->index = field;
2077   elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
2078
2079   elt = VEC_quick_push (constructor_elt, v, NULL);
2080   field = TREE_CHAIN (field);
2081   elt->index = field;
2082   elt->value = build_int_cst (TREE_TYPE (field),
2083                               DECL_ALIGN_UNIT (decl));
2084
2085   elt = VEC_quick_push (constructor_elt, v, NULL);
2086   field = TREE_CHAIN (field);
2087   elt->index = field;
2088   elt->value = null_pointer_node;
2089
2090   elt = VEC_quick_push (constructor_elt, v, NULL);
2091   field = TREE_CHAIN (field);
2092   elt->index = field;
2093   elt->value = proxy;
2094
2095   return build_constructor (type, v);
2096 }
2097
2098 /* Assemble everything that is needed for a variable or function declaration.
2099    Not used for automatic variables, and not used for function definitions.
2100    Should not be called for variables of incomplete structure type.
2101
2102    TOP_LEVEL is nonzero if this variable has file scope.
2103    AT_END is nonzero if this is the special handling, at end of compilation,
2104    to define things that have had only tentative definitions.
2105    DONT_OUTPUT_DATA if nonzero means don't actually output the
2106    initial value (that will be done by the caller).  */
2107
2108 void
2109 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2110                    int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2111 {
2112   const char *name;
2113   rtx decl_rtl, symbol;
2114   section *sect;
2115
2116   if (! targetm.have_tls
2117       && TREE_CODE (decl) == VAR_DECL
2118       && DECL_THREAD_LOCAL_P (decl))
2119     {
2120       tree to = emutls_decl (decl);
2121
2122       /* If this variable is defined locally, then we need to initialize the
2123          control structure with size and alignment information.  We do this
2124          at the last moment because tentative definitions can take a locally
2125          defined but uninitialized variable and initialize it later, which
2126          would result in incorrect contents.  */
2127       if (! DECL_EXTERNAL (to)
2128           && (! DECL_COMMON (to)
2129               || (DECL_INITIAL (decl)
2130                   && DECL_INITIAL (decl) != error_mark_node)))
2131         {
2132           DECL_INITIAL (to) = targetm.emutls.var_init
2133             (to, decl, get_emutls_init_templ_addr (decl));
2134
2135           /* Make sure the template is marked as needed early enough.
2136              Without this, if the variable is placed in a
2137              section-anchored block, the template will only be marked
2138              when it's too late.  */
2139           record_references_in_initializer (to, false);
2140         }
2141
2142       decl = to;
2143     }
2144
2145   last_assemble_variable_decl = 0;
2146
2147   /* Normally no need to say anything here for external references,
2148      since assemble_external is called by the language-specific code
2149      when a declaration is first seen.  */
2150
2151   if (DECL_EXTERNAL (decl))
2152     return;
2153
2154   /* Output no assembler code for a function declaration.
2155      Only definitions of functions output anything.  */
2156
2157   if (TREE_CODE (decl) == FUNCTION_DECL)
2158     return;
2159
2160   /* Do nothing for global register variables.  */
2161   if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2162     {
2163       TREE_ASM_WRITTEN (decl) = 1;
2164       return;
2165     }
2166
2167   /* If type was incomplete when the variable was declared,
2168      see if it is complete now.  */
2169
2170   if (DECL_SIZE (decl) == 0)
2171     layout_decl (decl, 0);
2172
2173   /* Still incomplete => don't allocate it; treat the tentative defn
2174      (which is what it must have been) as an `extern' reference.  */
2175
2176   if (!dont_output_data && DECL_SIZE (decl) == 0)
2177     {
2178       error ("storage size of %q+D isn%'t known", decl);
2179       TREE_ASM_WRITTEN (decl) = 1;
2180       return;
2181     }
2182
2183   /* The first declaration of a variable that comes through this function
2184      decides whether it is global (in C, has external linkage)
2185      or local (in C, has internal linkage).  So do nothing more
2186      if this function has already run.  */
2187
2188   if (TREE_ASM_WRITTEN (decl))
2189     return;
2190
2191   /* Make sure targetm.encode_section_info is invoked before we set
2192      ASM_WRITTEN.  */
2193   decl_rtl = DECL_RTL (decl);
2194
2195   TREE_ASM_WRITTEN (decl) = 1;
2196
2197   /* Do no output if -fsyntax-only.  */
2198   if (flag_syntax_only)
2199     return;
2200
2201   app_disable ();
2202
2203   if (! dont_output_data
2204       && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2205     {
2206       error ("size of variable %q+D is too large", decl);
2207       return;
2208     }
2209
2210   gcc_assert (MEM_P (decl_rtl));
2211   gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2212   symbol = XEXP (decl_rtl, 0);
2213   name = XSTR (symbol, 0);
2214   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2215     notice_global_symbol (decl);
2216
2217   /* Compute the alignment of this data.  */
2218
2219   align_variable (decl, dont_output_data);
2220   set_mem_align (decl_rtl, DECL_ALIGN (decl));
2221
2222   if (TREE_PUBLIC (decl))
2223     maybe_assemble_visibility (decl);
2224
2225   if (DECL_PRESERVE_P (decl))
2226     targetm.asm_out.mark_decl_preserved (name);
2227
2228   /* First make the assembler name(s) global if appropriate.  */
2229   sect = get_variable_section (decl, false);
2230   if (TREE_PUBLIC (decl)
2231       && (sect->common.flags & SECTION_COMMON) == 0)
2232     globalize_decl (decl);
2233
2234   /* Output any data that we will need to use the address of.  */
2235   if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2236     output_addressed_constants (DECL_INITIAL (decl));
2237
2238   /* dbxout.c needs to know this.  */
2239   if (sect && (sect->common.flags & SECTION_CODE) != 0)
2240     DECL_IN_TEXT_SECTION (decl) = 1;
2241
2242   /* If the decl is part of an object_block, make sure that the decl
2243      has been positioned within its block, but do not write out its
2244      definition yet.  output_object_blocks will do that later.  */
2245   if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2246     {
2247       gcc_assert (!dont_output_data);
2248       place_block_symbol (symbol);
2249     }
2250   else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2251     assemble_noswitch_variable (decl, name, sect);
2252   else
2253     {
2254       switch_to_section (sect);
2255       if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2256         ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2257       assemble_variable_contents (decl, name, dont_output_data);
2258     }
2259 }
2260
2261 /* Return 1 if type TYPE contains any pointers.  */
2262
2263 static int
2264 contains_pointers_p (tree type)
2265 {
2266   switch (TREE_CODE (type))
2267     {
2268     case POINTER_TYPE:
2269     case REFERENCE_TYPE:
2270       /* I'm not sure whether OFFSET_TYPE needs this treatment,
2271          so I'll play safe and return 1.  */
2272     case OFFSET_TYPE:
2273       return 1;
2274
2275     case RECORD_TYPE:
2276     case UNION_TYPE:
2277     case QUAL_UNION_TYPE:
2278       {
2279         tree fields;
2280         /* For a type that has fields, see if the fields have pointers.  */
2281         for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2282           if (TREE_CODE (fields) == FIELD_DECL
2283               && contains_pointers_p (TREE_TYPE (fields)))
2284             return 1;
2285         return 0;
2286       }
2287
2288     case ARRAY_TYPE:
2289       /* An array type contains pointers if its element type does.  */
2290       return contains_pointers_p (TREE_TYPE (type));
2291
2292     default:
2293       return 0;
2294     }
2295 }
2296
2297 /* We delay assemble_external processing until
2298    the compilation unit is finalized.  This is the best we can do for
2299    right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2300    it all the way to final.  See PR 17982 for further discussion.  */
2301 static GTY(()) tree pending_assemble_externals;
2302
2303 #ifdef ASM_OUTPUT_EXTERNAL
2304 /* True if DECL is a function decl for which no out-of-line copy exists.
2305    It is assumed that DECL's assembler name has been set.  */
2306
2307 static bool
2308 incorporeal_function_p (tree decl)
2309 {
2310   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2311     {
2312       const char *name;
2313
2314       if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2315           && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2316         return true;
2317
2318       name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2319       if (is_builtin_name (name))
2320         return true;
2321     }
2322   return false;
2323 }
2324
2325 /* Actually do the tests to determine if this is necessary, and invoke
2326    ASM_OUTPUT_EXTERNAL.  */
2327 static void
2328 assemble_external_real (tree decl)
2329 {
2330   rtx rtl = DECL_RTL (decl);
2331
2332   if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2333       && !SYMBOL_REF_USED (XEXP (rtl, 0))
2334       && !incorporeal_function_p (decl))
2335     {
2336       /* Some systems do require some output.  */
2337       SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2338       ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2339     }
2340 }
2341 #endif
2342
2343 void
2344 process_pending_assemble_externals (void)
2345 {
2346 #ifdef ASM_OUTPUT_EXTERNAL
2347   tree list;
2348   for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2349     assemble_external_real (TREE_VALUE (list));
2350
2351   pending_assemble_externals = 0;
2352 #endif
2353 }
2354
2355 /* This TREE_LIST contains any weak symbol declarations waiting
2356    to be emitted.  */
2357 static GTY(()) tree weak_decls;
2358
2359 /* Output something to declare an external symbol to the assembler,
2360    and qualifiers such as weakness.  (Most assemblers don't need
2361    extern declaration, so we normally output nothing.)  Do nothing if
2362    DECL is not external.  */
2363
2364 void
2365 assemble_external (tree decl ATTRIBUTE_UNUSED)
2366 {
2367   /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2368      main body of this code is only rarely exercised.  To provide some
2369      testing, on all platforms, we make sure that the ASM_OUT_FILE is
2370      open.  If it's not, we should not be calling this function.  */
2371   gcc_assert (asm_out_file);
2372
2373   if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2374     return;
2375
2376   /* We want to output annotation for weak and external symbols at
2377      very last to check if they are references or not.  */
2378
2379   if (SUPPORTS_WEAK
2380       && DECL_WEAK (decl)
2381       /* TREE_STATIC is a weird and abused creature which is not
2382          generally the right test for whether an entity has been
2383          locally emitted, inlined or otherwise not-really-extern, but
2384          for declarations that can be weak, it happens to be
2385          match.  */
2386       && !TREE_STATIC (decl)
2387       && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2388       && value_member (decl, weak_decls) == NULL_TREE)
2389     weak_decls = tree_cons (NULL, decl, weak_decls);
2390
2391 #ifdef ASM_OUTPUT_EXTERNAL
2392   if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2393     pending_assemble_externals = tree_cons (NULL, decl,
2394                                             pending_assemble_externals);
2395 #endif
2396 }
2397
2398 /* Similar, for calling a library function FUN.  */
2399
2400 void
2401 assemble_external_libcall (rtx fun)
2402 {
2403   /* Declare library function name external when first used, if nec.  */
2404   if (! SYMBOL_REF_USED (fun))
2405     {
2406       SYMBOL_REF_USED (fun) = 1;
2407       targetm.asm_out.external_libcall (fun);
2408     }
2409 }
2410
2411 /* Assemble a label named NAME.  */
2412
2413 void
2414 assemble_label (const char *name)
2415 {
2416   ASM_OUTPUT_LABEL (asm_out_file, name);
2417 }
2418
2419 /* Set the symbol_referenced flag for ID.  */
2420 void
2421 mark_referenced (tree id)
2422 {
2423   TREE_SYMBOL_REFERENCED (id) = 1;
2424 }
2425
2426 /* Set the symbol_referenced flag for DECL and notify callgraph.  */
2427 void
2428 mark_decl_referenced (tree decl)
2429 {
2430   if (TREE_CODE (decl) == FUNCTION_DECL)
2431     {
2432       /* Extern inline functions don't become needed when referenced.
2433          If we know a method will be emitted in other TU and no new
2434          functions can be marked reachable, just use the external
2435          definition.  */
2436       struct cgraph_node *node = cgraph_node (decl);
2437       if (!DECL_EXTERNAL (decl)
2438           && (!node->local.vtable_method || !cgraph_global_info_ready
2439               || !node->local.finalized))
2440         cgraph_mark_needed_node (node);
2441     }
2442   else if (TREE_CODE (decl) == VAR_DECL)
2443     {
2444       struct varpool_node *node = varpool_node (decl);
2445       varpool_mark_needed_node (node);
2446       /* C++ frontend use mark_decl_references to force COMDAT variables
2447          to be output that might appear dead otherwise.  */
2448       node->force_output = true;
2449     }
2450   /* else do nothing - we can get various sorts of CST nodes here,
2451      which do not need to be marked.  */
2452 }
2453
2454
2455 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2456    until we find an identifier that is not itself a transparent alias.
2457    Modify the alias passed to it by reference (and all aliases on the
2458    way to the ultimate target), such that they do not have to be
2459    followed again, and return the ultimate target of the alias
2460    chain.  */
2461
2462 static inline tree
2463 ultimate_transparent_alias_target (tree *alias)
2464 {
2465   tree target = *alias;
2466
2467   if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2468     {
2469       gcc_assert (TREE_CHAIN (target));
2470       target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2471       gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2472                   && ! TREE_CHAIN (target));
2473       *alias = target;
2474     }
2475
2476   return target;
2477 }
2478
2479 /* Output to FILE (an assembly file) a reference to NAME.  If NAME
2480    starts with a *, the rest of NAME is output verbatim.  Otherwise
2481    NAME is transformed in a target-specific way (usually by the
2482    addition of an underscore).  */
2483
2484 void
2485 assemble_name_raw (FILE *file, const char *name)
2486 {
2487   if (name[0] == '*')
2488     fputs (&name[1], file);
2489   else
2490     ASM_OUTPUT_LABELREF (file, name);
2491 }
2492
2493 /* Like assemble_name_raw, but should be used when NAME might refer to
2494    an entity that is also represented as a tree (like a function or
2495    variable).  If NAME does refer to such an entity, that entity will
2496    be marked as referenced.  */
2497
2498 void
2499 assemble_name (FILE *file, const char *name)
2500 {
2501   const char *real_name;
2502   tree id;
2503
2504   real_name = targetm.strip_name_encoding (name);
2505
2506   id = maybe_get_identifier (real_name);
2507   if (id)
2508     {
2509       tree id_orig = id;
2510
2511       mark_referenced (id);
2512       ultimate_transparent_alias_target (&id);
2513       if (id != id_orig)
2514         name = IDENTIFIER_POINTER (id);
2515       gcc_assert (! TREE_CHAIN (id));
2516     }
2517
2518   assemble_name_raw (file, name);
2519 }
2520
2521 /* Allocate SIZE bytes writable static space with a gensym name
2522    and return an RTX to refer to its address.  */
2523
2524 rtx
2525 assemble_static_space (unsigned HOST_WIDE_INT size)
2526 {
2527   char name[12];
2528   const char *namestring;
2529   rtx x;
2530
2531   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2532   ++const_labelno;
2533   namestring = ggc_strdup (name);
2534
2535   x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2536   SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2537
2538 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2539   ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2540                                  BIGGEST_ALIGNMENT);
2541 #else
2542 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2543   ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2544 #else
2545   {
2546     /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2547        so that each uninitialized object starts on such a boundary.  */
2548     /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL.  */
2549     unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2550       = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2551          / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2552          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2553     ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2554   }
2555 #endif
2556 #endif
2557   return x;
2558 }
2559
2560 /* Assemble the static constant template for function entry trampolines.
2561    This is done at most once per compilation.
2562    Returns an RTX for the address of the template.  */
2563
2564 static GTY(()) rtx initial_trampoline;
2565
2566 rtx
2567 assemble_trampoline_template (void)
2568 {
2569   char label[256];
2570   const char *name;
2571   int align;
2572   rtx symbol;
2573
2574   gcc_assert (targetm.asm_out.trampoline_template != NULL);
2575
2576   if (initial_trampoline)
2577     return initial_trampoline;
2578
2579   /* By default, put trampoline templates in read-only data section.  */
2580
2581 #ifdef TRAMPOLINE_SECTION
2582   switch_to_section (TRAMPOLINE_SECTION);
2583 #else
2584   switch_to_section (readonly_data_section);
2585 #endif
2586
2587   /* Write the assembler code to define one.  */
2588   align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2589   if (align > 0)
2590     ASM_OUTPUT_ALIGN (asm_out_file, align);
2591
2592   targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2593   targetm.asm_out.trampoline_template (asm_out_file);
2594
2595   /* Record the rtl to refer to it.  */
2596   ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2597   name = ggc_strdup (label);
2598   symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2599   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2600
2601   initial_trampoline = gen_const_mem (BLKmode, symbol);
2602   set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2603   set_mem_size (initial_trampoline, GEN_INT (TRAMPOLINE_SIZE));
2604
2605   return initial_trampoline;
2606 }
2607 \f
2608 /* A and B are either alignments or offsets.  Return the minimum alignment
2609    that may be assumed after adding the two together.  */
2610
2611 static inline unsigned
2612 min_align (unsigned int a, unsigned int b)
2613 {
2614   return (a | b) & -(a | b);
2615 }
2616
2617 /* Return the assembler directive for creating a given kind of integer
2618    object.  SIZE is the number of bytes in the object and ALIGNED_P
2619    indicates whether it is known to be aligned.  Return NULL if the
2620    assembly dialect has no such directive.
2621
2622    The returned string should be printed at the start of a new line and
2623    be followed immediately by the object's initial value.  */
2624
2625 const char *
2626 integer_asm_op (int size, int aligned_p)
2627 {
2628   struct asm_int_op *ops;
2629
2630   if (aligned_p)
2631     ops = &targetm.asm_out.aligned_op;
2632   else
2633     ops = &targetm.asm_out.unaligned_op;
2634
2635   switch (size)
2636     {
2637     case 1:
2638       return targetm.asm_out.byte_op;
2639     case 2:
2640       return ops->hi;
2641     case 4:
2642       return ops->si;
2643     case 8:
2644       return ops->di;
2645     case 16:
2646       return ops->ti;
2647     default:
2648       return NULL;
2649     }
2650 }
2651
2652 /* Use directive OP to assemble an integer object X.  Print OP at the
2653    start of the line, followed immediately by the value of X.  */
2654
2655 void
2656 assemble_integer_with_op (const char *op, rtx x)
2657 {
2658   fputs (op, asm_out_file);
2659   output_addr_const (asm_out_file, x);
2660   fputc ('\n', asm_out_file);
2661 }
2662
2663 /* The default implementation of the asm_out.integer target hook.  */
2664
2665 bool
2666 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2667                           unsigned int size ATTRIBUTE_UNUSED,
2668                           int aligned_p ATTRIBUTE_UNUSED)
2669 {
2670   const char *op = integer_asm_op (size, aligned_p);
2671   /* Avoid GAS bugs for large values.  Specifically negative values whose
2672      absolute value fits in a bfd_vma, but not in a bfd_signed_vma.  */
2673   if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2674     return false;
2675   return op && (assemble_integer_with_op (op, x), true);
2676 }
2677
2678 /* Assemble the integer constant X into an object of SIZE bytes.  ALIGN is
2679    the alignment of the integer in bits.  Return 1 if we were able to output
2680    the constant, otherwise 0.  We must be able to output the constant,
2681    if FORCE is nonzero.  */
2682
2683 bool
2684 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2685 {
2686   int aligned_p;
2687
2688   aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2689
2690   /* See if the target hook can handle this kind of object.  */
2691   if (targetm.asm_out.integer (x, size, aligned_p))
2692     return true;
2693
2694   /* If the object is a multi-byte one, try splitting it up.  Split
2695      it into words it if is multi-word, otherwise split it into bytes.  */
2696   if (size > 1)
2697     {
2698       enum machine_mode omode, imode;
2699       unsigned int subalign;
2700       unsigned int subsize, i;
2701       enum mode_class mclass;
2702
2703       subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2704       subalign = MIN (align, subsize * BITS_PER_UNIT);
2705       if (GET_CODE (x) == CONST_FIXED)
2706         mclass = GET_MODE_CLASS (GET_MODE (x));
2707       else
2708         mclass = MODE_INT;
2709
2710       omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2711       imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2712
2713       for (i = 0; i < size; i += subsize)
2714         {
2715           rtx partial = simplify_subreg (omode, x, imode, i);
2716           if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2717             break;
2718         }
2719       if (i == size)
2720         return true;
2721
2722       /* If we've printed some of it, but not all of it, there's no going
2723          back now.  */
2724       gcc_assert (!i);
2725     }
2726
2727   gcc_assert (!force);
2728
2729   return false;
2730 }
2731 \f
2732 void
2733 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2734 {
2735   long data[4] = {0, 0, 0, 0};
2736   int i;
2737   int bitsize, nelts, nunits, units_per;
2738
2739   /* This is hairy.  We have a quantity of known size.  real_to_target
2740      will put it into an array of *host* longs, 32 bits per element
2741      (even if long is more than 32 bits).  We need to determine the
2742      number of array elements that are occupied (nelts) and the number
2743      of *target* min-addressable units that will be occupied in the
2744      object file (nunits).  We cannot assume that 32 divides the
2745      mode's bitsize (size * BITS_PER_UNIT) evenly.
2746
2747      size * BITS_PER_UNIT is used here to make sure that padding bits
2748      (which might appear at either end of the value; real_to_target
2749      will include the padding bits in its output array) are included.  */
2750
2751   nunits = GET_MODE_SIZE (mode);
2752   bitsize = nunits * BITS_PER_UNIT;
2753   nelts = CEIL (bitsize, 32);
2754   units_per = 32 / BITS_PER_UNIT;
2755
2756   real_to_target (data, &d, mode);
2757
2758   /* Put out the first word with the specified alignment.  */
2759   assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2760   nunits -= units_per;
2761
2762   /* Subsequent words need only 32-bit alignment.  */
2763   align = min_align (align, 32);
2764
2765   for (i = 1; i < nelts; i++)
2766     {
2767       assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2768       nunits -= units_per;
2769     }
2770 }
2771 \f
2772 /* Given an expression EXP with a constant value,
2773    reduce it to the sum of an assembler symbol and an integer.
2774    Store them both in the structure *VALUE.
2775    EXP must be reducible.  */
2776
2777 struct GTY(()) addr_const {
2778   rtx base;
2779   HOST_WIDE_INT offset;
2780 };
2781
2782 static void
2783 decode_addr_const (tree exp, struct addr_const *value)
2784 {
2785   tree target = TREE_OPERAND (exp, 0);
2786   int offset = 0;
2787   rtx x;
2788
2789   while (1)
2790     {
2791       if (TREE_CODE (target) == COMPONENT_REF
2792           && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2793
2794         {
2795           offset += int_byte_position (TREE_OPERAND (target, 1));
2796           target = TREE_OPERAND (target, 0);
2797         }
2798       else if (TREE_CODE (target) == ARRAY_REF
2799                || TREE_CODE (target) == ARRAY_RANGE_REF)
2800         {
2801           offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2802                      * tree_low_cst (TREE_OPERAND (target, 1), 0));
2803           target = TREE_OPERAND (target, 0);
2804         }
2805       else
2806         break;
2807     }
2808
2809   switch (TREE_CODE (target))
2810     {
2811     case VAR_DECL:
2812     case FUNCTION_DECL:
2813       x = DECL_RTL (target);
2814       break;
2815
2816     case LABEL_DECL:
2817       x = gen_rtx_MEM (FUNCTION_MODE,
2818                        gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2819       break;
2820
2821     case REAL_CST:
2822     case FIXED_CST:
2823     case STRING_CST:
2824     case COMPLEX_CST:
2825     case CONSTRUCTOR:
2826     case INTEGER_CST:
2827       x = output_constant_def (target, 1);
2828       break;
2829
2830     default:
2831       gcc_unreachable ();
2832     }
2833
2834   gcc_assert (MEM_P (x));
2835   x = XEXP (x, 0);
2836
2837   value->base = x;
2838   value->offset = offset;
2839 }
2840 \f
2841
2842 static GTY((param_is (struct constant_descriptor_tree)))
2843      htab_t const_desc_htab;
2844
2845 static struct constant_descriptor_tree * build_constant_desc (tree);
2846 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2847
2848 /* Constant pool accessor function.  */
2849
2850 htab_t
2851 constant_pool_htab (void)
2852 {
2853   return const_desc_htab;
2854 }
2855
2856 /* Compute a hash code for a constant expression.  */
2857
2858 static hashval_t
2859 const_desc_hash (const void *ptr)
2860 {
2861   return ((const struct constant_descriptor_tree *)ptr)->hash;
2862 }
2863
2864 static hashval_t
2865 const_hash_1 (const tree exp)
2866 {
2867   const char *p;
2868   hashval_t hi;
2869   int len, i;
2870   enum tree_code code = TREE_CODE (exp);
2871
2872   /* Either set P and LEN to the address and len of something to hash and
2873      exit the switch or return a value.  */
2874
2875   switch (code)
2876     {
2877     case INTEGER_CST:
2878       p = (char *) &TREE_INT_CST (exp);
2879       len = sizeof TREE_INT_CST (exp);
2880       break;
2881
2882     case REAL_CST:
2883       return real_hash (TREE_REAL_CST_PTR (exp));
2884
2885     case FIXED_CST:
2886       return fixed_hash (TREE_FIXED_CST_PTR (exp));
2887
2888     case STRING_CST:
2889       p = TREE_STRING_POINTER (exp);
2890       len = TREE_STRING_LENGTH (exp);
2891       break;
2892
2893     case COMPLEX_CST:
2894       return (const_hash_1 (TREE_REALPART (exp)) * 5
2895               + const_hash_1 (TREE_IMAGPART (exp)));
2896
2897     case CONSTRUCTOR:
2898       {
2899         unsigned HOST_WIDE_INT idx;
2900         tree value;
2901
2902         hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2903
2904         FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2905           if (value)
2906             hi = hi * 603 + const_hash_1 (value);
2907
2908         return hi;
2909       }
2910
2911     case ADDR_EXPR:
2912     case FDESC_EXPR:
2913       {
2914         struct addr_const value;
2915
2916         decode_addr_const (exp, &value);
2917         switch (GET_CODE (value.base))
2918           {
2919           case SYMBOL_REF:
2920             /* Don't hash the address of the SYMBOL_REF;
2921                only use the offset and the symbol name.  */
2922             hi = value.offset;
2923             p = XSTR (value.base, 0);
2924             for (i = 0; p[i] != 0; i++)
2925               hi = ((hi * 613) + (unsigned) (p[i]));
2926             break;
2927
2928           case LABEL_REF:
2929             hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2930             break;
2931
2932           default:
2933             gcc_unreachable ();
2934           }
2935       }
2936       return hi;
2937
2938     case PLUS_EXPR:
2939     case POINTER_PLUS_EXPR:
2940     case MINUS_EXPR:
2941       return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2942               + const_hash_1 (TREE_OPERAND (exp, 1)));
2943
2944     CASE_CONVERT:
2945       return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2946
2947     default:
2948       /* A language specific constant. Just hash the code.  */
2949       return code;
2950     }
2951
2952   /* Compute hashing function.  */
2953   hi = len;
2954   for (i = 0; i < len; i++)
2955     hi = ((hi * 613) + (unsigned) (p[i]));
2956
2957   return hi;
2958 }
2959
2960 /* Wrapper of compare_constant, for the htab interface.  */
2961 static int
2962 const_desc_eq (const void *p1, const void *p2)
2963 {
2964   const struct constant_descriptor_tree *const c1
2965     = (const struct constant_descriptor_tree *) p1;
2966   const struct constant_descriptor_tree *const c2
2967     = (const struct constant_descriptor_tree *) p2;
2968   if (c1->hash != c2->hash)
2969     return 0;
2970   return compare_constant (c1->value, c2->value);
2971 }
2972
2973 /* Compare t1 and t2, and return 1 only if they are known to result in
2974    the same bit pattern on output.  */
2975
2976 static int
2977 compare_constant (const tree t1, const tree t2)
2978 {
2979   enum tree_code typecode;
2980
2981   if (t1 == NULL_TREE)
2982     return t2 == NULL_TREE;
2983   if (t2 == NULL_TREE)
2984     return 0;
2985
2986   if (TREE_CODE (t1) != TREE_CODE (t2))
2987     return 0;
2988
2989   switch (TREE_CODE (t1))
2990     {
2991     case INTEGER_CST:
2992       /* Integer constants are the same only if the same width of type.  */
2993       if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2994         return 0;
2995       if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2996         return 0;
2997       return tree_int_cst_equal (t1, t2);
2998
2999     case REAL_CST:
3000       /* Real constants are the same only if the same width of type.  */
3001       if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3002         return 0;
3003
3004       return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3005
3006     case FIXED_CST:
3007       /* Fixed constants are the same only if the same width of type.  */
3008       if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3009         return 0;
3010
3011       return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3012
3013     case STRING_CST:
3014       if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3015         return 0;
3016
3017       return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3018               && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3019                          TREE_STRING_LENGTH (t1)));
3020
3021     case COMPLEX_CST:
3022       return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3023               && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3024
3025     case CONSTRUCTOR:
3026       {
3027         VEC(constructor_elt, gc) *v1, *v2;
3028         unsigned HOST_WIDE_INT idx;
3029
3030         typecode = TREE_CODE (TREE_TYPE (t1));
3031         if (typecode != TREE_CODE (TREE_TYPE (t2)))
3032           return 0;
3033
3034         if (typecode == ARRAY_TYPE)
3035           {
3036             HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3037             /* For arrays, check that the sizes all match.  */
3038             if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3039                 || size_1 == -1
3040                 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
3041               return 0;
3042           }
3043         else
3044           {
3045             /* For record and union constructors, require exact type
3046                equality.  */
3047             if (TREE_TYPE (t1) != TREE_TYPE (t2))
3048               return 0;
3049           }
3050
3051         v1 = CONSTRUCTOR_ELTS (t1);
3052         v2 = CONSTRUCTOR_ELTS (t2);
3053         if (VEC_length (constructor_elt, v1)
3054             != VEC_length (constructor_elt, v2))
3055             return 0;
3056
3057         for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
3058           {
3059             constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
3060             constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
3061
3062             /* Check that each value is the same...  */
3063             if (!compare_constant (c1->value, c2->value))
3064               return 0;
3065             /* ... and that they apply to the same fields!  */
3066             if (typecode == ARRAY_TYPE)
3067               {
3068                 if (!compare_constant (c1->index, c2->index))
3069                   return 0;
3070               }
3071             else
3072               {
3073                 if (c1->index != c2->index)
3074                   return 0;
3075               }
3076           }
3077
3078         return 1;
3079       }
3080
3081     case ADDR_EXPR:
3082     case FDESC_EXPR:
3083       {
3084         struct addr_const value1, value2;
3085
3086         decode_addr_const (t1, &value1);
3087         decode_addr_const (t2, &value2);
3088         return (value1.offset == value2.offset
3089                 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3090       }
3091
3092     case PLUS_EXPR:
3093     case POINTER_PLUS_EXPR:
3094     case MINUS_EXPR:
3095     case RANGE_EXPR:
3096       return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3097               && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3098
3099     CASE_CONVERT:
3100     case VIEW_CONVERT_EXPR:
3101       return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3102
3103     default:
3104       return 0;
3105     }
3106
3107   gcc_unreachable ();
3108 }
3109 \f
3110 /* Make a copy of the whole tree structure for a constant.  This
3111    handles the same types of nodes that compare_constant handles.  */
3112
3113 static tree
3114 copy_constant (tree exp)
3115 {
3116   switch (TREE_CODE (exp))
3117     {
3118     case ADDR_EXPR:
3119       /* For ADDR_EXPR, we do not want to copy the decl whose address
3120          is requested.  We do want to copy constants though.  */
3121       if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3122         return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3123                        copy_constant (TREE_OPERAND (exp, 0)));
3124       else
3125         return copy_node (exp);
3126
3127     case INTEGER_CST:
3128     case REAL_CST:
3129     case FIXED_CST:
3130     case STRING_CST:
3131       return copy_node (exp);
3132
3133     case COMPLEX_CST:
3134       return build_complex (TREE_TYPE (exp),
3135                             copy_constant (TREE_REALPART (exp)),
3136                             copy_constant (TREE_IMAGPART (exp)));
3137
3138     case PLUS_EXPR:
3139     case POINTER_PLUS_EXPR:
3140     case MINUS_EXPR:
3141       return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3142                      copy_constant (TREE_OPERAND (exp, 0)),
3143                      copy_constant (TREE_OPERAND (exp, 1)));
3144
3145     CASE_CONVERT:
3146     case VIEW_CONVERT_EXPR:
3147       return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3148                      copy_constant (TREE_OPERAND (exp, 0)));
3149
3150     case CONSTRUCTOR:
3151       {
3152         tree copy = copy_node (exp);
3153         VEC(constructor_elt, gc) *v;
3154         unsigned HOST_WIDE_INT idx;
3155         tree purpose, value;
3156
3157         v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3158                                                       CONSTRUCTOR_ELTS (exp)));
3159         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3160           {
3161             constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3162             ce->index = purpose;
3163             ce->value = copy_constant (value);
3164           }
3165         CONSTRUCTOR_ELTS (copy) = v;
3166         return copy;
3167       }
3168
3169     default:
3170       gcc_unreachable ();
3171     }
3172 }
3173 \f
3174 /* Return the alignment of constant EXP in bits.  */
3175
3176 static unsigned int
3177 get_constant_alignment (tree exp)
3178 {
3179   unsigned int align;
3180
3181   align = TYPE_ALIGN (TREE_TYPE (exp));
3182 #ifdef CONSTANT_ALIGNMENT
3183   align = CONSTANT_ALIGNMENT (exp, align);
3184 #endif
3185   return align;
3186 }
3187
3188 /* Return the section into which constant EXP should be placed.  */
3189
3190 static section *
3191 get_constant_section (tree exp)
3192 {
3193   if (IN_NAMED_SECTION (exp))
3194     return get_named_section (exp, NULL, compute_reloc_for_constant (exp));
3195   else
3196     return targetm.asm_out.select_section (exp,
3197                                            compute_reloc_for_constant (exp),
3198                                            get_constant_alignment (exp));
3199 }
3200
3201 /* Return the size of constant EXP in bytes.  */
3202
3203 static HOST_WIDE_INT
3204 get_constant_size (tree exp)
3205 {
3206   HOST_WIDE_INT size;
3207
3208   size = int_size_in_bytes (TREE_TYPE (exp));
3209   if (TREE_CODE (exp) == STRING_CST)
3210     size = MAX (TREE_STRING_LENGTH (exp), size);
3211   return size;
3212 }
3213
3214 /* Subroutine of output_constant_def:
3215    No constant equal to EXP is known to have been output.
3216    Make a constant descriptor to enter EXP in the hash table.
3217    Assign the label number and construct RTL to refer to the
3218    constant's location in memory.
3219    Caller is responsible for updating the hash table.  */
3220
3221 static struct constant_descriptor_tree *
3222 build_constant_desc (tree exp)
3223 {
3224   rtx symbol;
3225   rtx rtl;
3226   char label[256];
3227   int labelno;
3228   struct constant_descriptor_tree *desc;
3229
3230   desc = GGC_NEW (struct constant_descriptor_tree);
3231   desc->value = copy_constant (exp);
3232
3233   /* Propagate marked-ness to copied constant.  */
3234   if (flag_mudflap && mf_marked_p (exp))
3235     mf_mark (desc->value);
3236
3237   /* Create a string containing the label name, in LABEL.  */
3238   labelno = const_labelno++;
3239   ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3240
3241   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
3242   if (use_object_blocks_p ())
3243     {
3244       section *sect = get_constant_section (exp);
3245       symbol = create_block_symbol (ggc_strdup (label),
3246                                     get_block_for_section (sect), -1);
3247     }
3248   else
3249     symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3250   SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3251   SET_SYMBOL_REF_DECL (symbol, desc->value);
3252   TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3253
3254   rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3255   set_mem_attributes (rtl, exp, 1);
3256   set_mem_alias_set (rtl, 0);
3257   set_mem_alias_set (rtl, const_alias_set);
3258
3259   /* We cannot share RTX'es in pool entries.
3260      Mark this piece of RTL as required for unsharing.  */
3261   RTX_FLAG (rtl, used) = 1;
3262
3263   /* Set flags or add text to the name to record information, such as
3264      that it is a local symbol.  If the name is changed, the macro
3265      ASM_OUTPUT_LABELREF will have to know how to strip this
3266      information.  This call might invalidate our local variable
3267      SYMBOL; we can't use it afterward.  */
3268
3269   targetm.encode_section_info (exp, rtl, true);
3270
3271   desc->rtl = rtl;
3272
3273   return desc;
3274 }
3275
3276 /* Return an rtx representing a reference to constant data in memory
3277    for the constant expression EXP.
3278
3279    If assembler code for such a constant has already been output,
3280    return an rtx to refer to it.
3281    Otherwise, output such a constant in memory
3282    and generate an rtx for it.
3283
3284    If DEFER is nonzero, this constant can be deferred and output only
3285    if referenced in the function after all optimizations.
3286
3287    `const_desc_table' records which constants already have label strings.  */
3288
3289 rtx
3290 output_constant_def (tree exp, int defer)
3291 {
3292   struct constant_descriptor_tree *desc;
3293   struct constant_descriptor_tree key;
3294   void **loc;
3295
3296   /* Look up EXP in the table of constant descriptors.  If we didn't find
3297      it, create a new one.  */
3298   key.value = exp;
3299   key.hash = const_hash_1 (exp);
3300   loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3301
3302   desc = (struct constant_descriptor_tree *) *loc;
3303   if (desc == 0)
3304     {
3305       desc = build_constant_desc (exp);
3306       desc->hash = key.hash;
3307       *loc = desc;
3308     }
3309
3310   maybe_output_constant_def_contents (desc, defer);
3311   return desc->rtl;
3312 }
3313
3314 /* Subroutine of output_constant_def: Decide whether or not we need to
3315    output the constant DESC now, and if so, do it.  */
3316 static void
3317 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3318                                     int defer)
3319 {
3320   rtx symbol = XEXP (desc->rtl, 0);
3321   tree exp = desc->value;
3322
3323   if (flag_syntax_only)
3324     return;
3325
3326   if (TREE_ASM_WRITTEN (exp))
3327     /* Already output; don't do it again.  */
3328     return;
3329
3330   /* We can always defer constants as long as the context allows
3331      doing so.  */
3332   if (defer)
3333     {
3334       /* Increment n_deferred_constants if it exists.  It needs to be at
3335          least as large as the number of constants actually referred to
3336          by the function.  If it's too small we'll stop looking too early
3337          and fail to emit constants; if it's too large we'll only look
3338          through the entire function when we could have stopped earlier.  */
3339       if (cfun)
3340         n_deferred_constants++;
3341       return;
3342     }
3343
3344   output_constant_def_contents (symbol);
3345 }
3346
3347 /* Subroutine of output_constant_def_contents.  Output the definition
3348    of constant EXP, which is pointed to by label LABEL.  ALIGN is the
3349    constant's alignment in bits.  */
3350
3351 static void
3352 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3353 {
3354   HOST_WIDE_INT size;
3355
3356   size = get_constant_size (exp);
3357
3358   /* Do any machine/system dependent processing of the constant.  */
3359 #ifdef ASM_DECLARE_CONSTANT_NAME
3360   ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
3361 #else
3362   /* Standard thing is just output label for the constant.  */
3363   ASM_OUTPUT_LABEL (asm_out_file, label);
3364 #endif /* ASM_DECLARE_CONSTANT_NAME */
3365
3366   /* Output the value of EXP.  */
3367   output_constant (exp, size, align);
3368 }
3369
3370 /* We must output the constant data referred to by SYMBOL; do so.  */
3371
3372 static void
3373 output_constant_def_contents (rtx symbol)
3374 {
3375   tree exp = SYMBOL_REF_DECL (symbol);
3376   unsigned int align;
3377
3378   /* Make sure any other constants whose addresses appear in EXP
3379      are assigned label numbers.  */
3380   output_addressed_constants (exp);
3381
3382   /* We are no longer deferring this constant.  */
3383   TREE_ASM_WRITTEN (exp) = 1;
3384
3385   /* If the constant is part of an object block, make sure that the
3386      decl has been positioned within its block, but do not write out
3387      its definition yet.  output_object_blocks will do that later.  */
3388   if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3389     place_block_symbol (symbol);
3390   else
3391     {
3392       switch_to_section (get_constant_section (exp));
3393       align = get_constant_alignment (exp);
3394       if (align > BITS_PER_UNIT)
3395         ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3396       assemble_constant_contents (exp, XSTR (symbol, 0), align);
3397     }
3398   if (flag_mudflap)
3399     mudflap_enqueue_constant (exp);
3400 }
3401
3402 /* Look up EXP in the table of constant descriptors.  Return the rtl
3403    if it has been emitted, else null.  */
3404
3405 rtx
3406 lookup_constant_def (tree exp)
3407 {
3408   struct constant_descriptor_tree *desc;
3409   struct constant_descriptor_tree key;
3410
3411   key.value = exp;
3412   key.hash = const_hash_1 (exp);
3413   desc = (struct constant_descriptor_tree *)
3414     htab_find_with_hash (const_desc_htab, &key, key.hash);
3415
3416   return (desc ? desc->rtl : NULL_RTX);
3417 }
3418 \f
3419 /* Used in the hash tables to avoid outputting the same constant
3420    twice.  Unlike 'struct constant_descriptor_tree', RTX constants
3421    are output once per function, not once per file.  */
3422 /* ??? Only a few targets need per-function constant pools.  Most
3423    can use one per-file pool.  Should add a targetm bit to tell the
3424    difference.  */
3425
3426 struct GTY(()) rtx_constant_pool {
3427   /* Pointers to first and last constant in pool, as ordered by offset.  */
3428   struct constant_descriptor_rtx *first;
3429   struct constant_descriptor_rtx *last;
3430
3431   /* Hash facility for making memory-constants from constant rtl-expressions.
3432      It is used on RISC machines where immediate integer arguments and
3433      constant addresses are restricted so that such constants must be stored
3434      in memory.  */
3435   htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3436
3437   /* Current offset in constant pool (does not include any
3438      machine-specific header).  */
3439   HOST_WIDE_INT offset;
3440 };
3441
3442 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3443   struct constant_descriptor_rtx *next;
3444   rtx mem;
3445   rtx sym;
3446   rtx constant;
3447   HOST_WIDE_INT offset;
3448   hashval_t hash;
3449   enum machine_mode mode;
3450   unsigned int align;
3451   int labelno;
3452   int mark;
3453 };
3454
3455 /* Hash and compare functions for const_rtx_htab.  */
3456
3457 static hashval_t
3458 const_desc_rtx_hash (const void *ptr)
3459 {
3460   const struct constant_descriptor_rtx *const desc
3461     = (const struct constant_descriptor_rtx *) ptr;
3462   return desc->hash;
3463 }
3464
3465 static int
3466 const_desc_rtx_eq (const void *a, const void *b)
3467 {
3468   const struct constant_descriptor_rtx *const x
3469     = (const struct constant_descriptor_rtx *) a;
3470   const struct constant_descriptor_rtx *const y
3471     = (const struct constant_descriptor_rtx *) b;
3472
3473   if (x->mode != y->mode)
3474     return 0;
3475   return rtx_equal_p (x->constant, y->constant);
3476 }
3477
3478 /* This is the worker function for const_rtx_hash, called via for_each_rtx.  */
3479
3480 static int
3481 const_rtx_hash_1 (rtx *xp, void *data)
3482 {
3483   unsigned HOST_WIDE_INT hwi;
3484   enum machine_mode mode;
3485   enum rtx_code code;
3486   hashval_t h, *hp;
3487   rtx x;
3488
3489   x = *xp;
3490   code = GET_CODE (x);
3491   mode = GET_MODE (x);
3492   h = (hashval_t) code * 1048573 + mode;
3493
3494   switch (code)
3495     {
3496     case CONST_INT:
3497       hwi = INTVAL (x);
3498     fold_hwi:
3499       {
3500         int shift = sizeof (hashval_t) * CHAR_BIT;
3501         const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3502         int i;
3503
3504         h ^= (hashval_t) hwi;
3505         for (i = 1; i < n; ++i)
3506           {
3507             hwi >>= shift;
3508             h ^= (hashval_t) hwi;
3509           }
3510       }
3511       break;
3512
3513     case CONST_DOUBLE:
3514       if (mode == VOIDmode)
3515         {
3516           hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3517           goto fold_hwi;
3518         }
3519       else
3520         h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3521       break;
3522
3523     case CONST_FIXED:
3524       h ^= fixed_hash (CONST_FIXED_VALUE (x));
3525       break;
3526
3527     case CONST_VECTOR:
3528       {
3529         int i;
3530         for (i = XVECLEN (x, 0); i-- > 0; )
3531           h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3532       }
3533       break;
3534
3535     case SYMBOL_REF:
3536       h ^= htab_hash_string (XSTR (x, 0));
3537       break;
3538
3539     case LABEL_REF:
3540       h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3541       break;
3542
3543     case UNSPEC:
3544     case UNSPEC_VOLATILE:
3545       h = h * 251 + XINT (x, 1);
3546       break;
3547
3548     default:
3549       break;
3550     }
3551
3552   hp = (hashval_t *) data;
3553   *hp = *hp * 509 + h;
3554   return 0;
3555 }
3556
3557 /* Compute a hash value for X, which should be a constant.  */
3558
3559 static hashval_t
3560 const_rtx_hash (rtx x)
3561 {
3562   hashval_t h = 0;
3563   for_each_rtx (&x, const_rtx_hash_1, &h);
3564   return h;
3565 }
3566
3567 \f
3568 /* Create and return a new rtx constant pool.  */
3569
3570 static struct rtx_constant_pool *
3571 create_constant_pool (void)
3572 {
3573   struct rtx_constant_pool *pool;
3574
3575   pool = GGC_NEW (struct rtx_constant_pool);
3576   pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3577                                           const_desc_rtx_eq, NULL);
3578   pool->first = NULL;
3579   pool->last = NULL;
3580   pool->offset = 0;
3581   return pool;
3582 }
3583
3584 /* Initialize constant pool hashing for a new function.  */
3585
3586 void
3587 init_varasm_status (void)
3588 {
3589   crtl->varasm.pool = create_constant_pool ();
3590   crtl->varasm.deferred_constants = 0;
3591 }
3592 \f
3593 /* Given a MINUS expression, simplify it if both sides
3594    include the same symbol.  */
3595
3596 rtx
3597 simplify_subtraction (rtx x)
3598 {
3599   rtx r = simplify_rtx (x);
3600   return r ? r : x;
3601 }
3602 \f
3603 /* Given a constant rtx X, make (or find) a memory constant for its value
3604    and return a MEM rtx to refer to it in memory.  */
3605
3606 rtx
3607 force_const_mem (enum machine_mode mode, rtx x)
3608 {
3609   struct constant_descriptor_rtx *desc, tmp;
3610   struct rtx_constant_pool *pool;
3611   char label[256];
3612   rtx def, symbol;
3613   hashval_t hash;
3614   unsigned int align;
3615   void **slot;
3616
3617   /* If we're not allowed to drop X into the constant pool, don't.  */
3618   if (targetm.cannot_force_const_mem (x))
3619     return NULL_RTX;
3620
3621   /* Record that this function has used a constant pool entry.  */
3622   crtl->uses_const_pool = 1;
3623
3624   /* Decide which pool to use.  */
3625   pool = (targetm.use_blocks_for_constant_p (mode, x)
3626           ? shared_constant_pool
3627           : crtl->varasm.pool);
3628
3629   /* Lookup the value in the hashtable.  */
3630   tmp.constant = x;
3631   tmp.mode = mode;
3632   hash = const_rtx_hash (x);
3633   slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3634   desc = (struct constant_descriptor_rtx *) *slot;
3635
3636   /* If the constant was already present, return its memory.  */
3637   if (desc)
3638     return copy_rtx (desc->mem);
3639
3640   /* Otherwise, create a new descriptor.  */
3641   desc = GGC_NEW (struct constant_descriptor_rtx);
3642   *slot = desc;
3643
3644   /* Align the location counter as required by EXP's data type.  */
3645   align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3646 #ifdef CONSTANT_ALIGNMENT
3647   {
3648     tree type = lang_hooks.types.type_for_mode (mode, 0);
3649     if (type != NULL_TREE)
3650       align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3651   }
3652 #endif
3653
3654   pool->offset += (align / BITS_PER_UNIT) - 1;
3655   pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3656
3657   desc->next = NULL;
3658   desc->constant = tmp.constant;
3659   desc->offset = pool->offset;
3660   desc->hash = hash;
3661   desc->mode = mode;
3662   desc->align = align;
3663   desc->labelno = const_labelno;
3664   desc->mark = 0;
3665
3666   pool->offset += GET_MODE_SIZE (mode);
3667   if (pool->last)
3668     pool->last->next = desc;
3669   else
3670     pool->first = pool->last = desc;
3671   pool->last = desc;
3672
3673   /* Create a string containing the label name, in LABEL.  */
3674   ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3675   ++const_labelno;
3676
3677   /* Construct the SYMBOL_REF.  Make sure to mark it as belonging to
3678      the constants pool.  */
3679   if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3680     {
3681       section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3682       symbol = create_block_symbol (ggc_strdup (label),
3683                                     get_block_for_section (sect), -1);
3684     }
3685   else
3686     symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3687   desc->sym = symbol;
3688   SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3689   CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3690   SET_SYMBOL_REF_CONSTANT (symbol, desc);
3691
3692   /* Construct the MEM.  */
3693   desc->mem = def = gen_const_mem (mode, symbol);
3694   set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3695   set_mem_align (def, align);
3696
3697   /* If we're dropping a label to the constant pool, make sure we
3698      don't delete it.  */
3699   if (GET_CODE (x) == LABEL_REF)
3700     LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3701
3702   return copy_rtx (def);
3703 }
3704 \f
3705 /* Given a constant pool SYMBOL_REF, return the corresponding constant.  */
3706
3707 rtx
3708 get_pool_constant (rtx addr)
3709 {
3710   return SYMBOL_REF_CONSTANT (addr)->constant;
3711 }
3712
3713 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3714    and whether it has been output or not.  */
3715
3716 rtx
3717 get_pool_constant_mark (rtx addr, bool *pmarked)
3718 {
3719   struct constant_descriptor_rtx *desc;
3720
3721   desc = SYMBOL_REF_CONSTANT (addr);
3722   *pmarked = (desc->mark != 0);
3723   return desc->constant;
3724 }
3725
3726 /* Similar, return the mode.  */
3727
3728 enum machine_mode
3729 get_pool_mode (const_rtx addr)
3730 {
3731   return SYMBOL_REF_CONSTANT (addr)->mode;
3732 }
3733
3734 /* Return the size of the constant pool.  */
3735
3736 int
3737 get_pool_size (void)
3738 {
3739   return crtl->varasm.pool->offset;
3740 }
3741 \f
3742 /* Worker function for output_constant_pool_1.  Emit assembly for X
3743    in MODE with known alignment ALIGN.  */
3744
3745 static void
3746 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3747 {
3748   switch (GET_MODE_CLASS (mode))
3749     {
3750     case MODE_FLOAT:
3751     case MODE_DECIMAL_FLOAT:
3752       {
3753         REAL_VALUE_TYPE r;
3754
3755         gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3756         REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3757         assemble_real (r, mode, align);
3758         break;
3759       }
3760
3761     case MODE_INT:
3762     case MODE_PARTIAL_INT:
3763     case MODE_FRACT:
3764     case MODE_UFRACT:
3765     case MODE_ACCUM:
3766     case MODE_UACCUM:
3767       assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3768       break;
3769
3770     case MODE_VECTOR_FLOAT:
3771     case MODE_VECTOR_INT:
3772     case MODE_VECTOR_FRACT:
3773     case MODE_VECTOR_UFRACT:
3774     case MODE_VECTOR_ACCUM:
3775     case MODE_VECTOR_UACCUM:
3776       {
3777         int i, units;
3778         enum machine_mode submode = GET_MODE_INNER (mode);
3779         unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3780
3781         gcc_assert (GET_CODE (x) == CONST_VECTOR);
3782         units = CONST_VECTOR_NUNITS (x);
3783
3784         for (i = 0; i < units; i++)
3785           {
3786             rtx elt = CONST_VECTOR_ELT (x, i);
3787             output_constant_pool_2 (submode, elt, i ? subalign : align);
3788           }
3789       }
3790       break;
3791
3792     default:
3793       gcc_unreachable ();
3794     }
3795 }
3796
3797 /* Worker function for output_constant_pool.  Emit constant DESC,
3798    giving it ALIGN bits of alignment.  */
3799
3800 static void
3801 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3802                         unsigned int align)
3803 {
3804   rtx x, tmp;
3805
3806   x = desc->constant;
3807
3808   /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3809      whose CODE_LABEL has been deleted.  This can occur if a jump table
3810      is eliminated by optimization.  If so, write a constant of zero
3811      instead.  Note that this can also happen by turning the
3812      CODE_LABEL into a NOTE.  */
3813   /* ??? This seems completely and utterly wrong.  Certainly it's
3814      not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3815      functioning even with INSN_DELETED_P and friends.  */
3816
3817   tmp = x;
3818   switch (GET_CODE (tmp))
3819     {
3820     case CONST:
3821       if (GET_CODE (XEXP (tmp, 0)) != PLUS
3822           || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3823         break;
3824       tmp = XEXP (XEXP (tmp, 0), 0);
3825       /* FALLTHRU  */
3826
3827     case LABEL_REF:
3828       tmp = XEXP (tmp, 0);
3829       gcc_assert (!INSN_DELETED_P (tmp));
3830       gcc_assert (!NOTE_P (tmp)
3831                   || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3832       break;
3833
3834     default:
3835       break;
3836     }
3837
3838 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3839   ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3840                                  align, desc->labelno, done);
3841 #endif
3842
3843   assemble_align (align);
3844
3845   /* Output the label.  */
3846   targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3847
3848   /* Output the data.  */
3849   output_constant_pool_2 (desc->mode, x, align);
3850
3851   /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3852      sections have proper size.  */
3853   if (align > GET_MODE_BITSIZE (desc->mode)
3854       && in_section
3855       && (in_section->common.flags & SECTION_MERGE))
3856     assemble_align (align);
3857
3858 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3859  done:
3860 #endif
3861   return;
3862 }
3863
3864 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3865    to as used.  Emit referenced deferred strings.  This function can
3866    be used with for_each_rtx to mark all SYMBOL_REFs in an rtx.  */
3867
3868 static int
3869 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3870 {
3871   rtx x = *current_rtx;
3872
3873   if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3874     return 0;
3875
3876   if (CONSTANT_POOL_ADDRESS_P (x))
3877     {
3878       struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3879       if (desc->mark == 0)
3880         {
3881           desc->mark = 1;
3882           for_each_rtx (&desc->constant, mark_constant, NULL);
3883         }
3884     }
3885   else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3886     {
3887       tree exp = SYMBOL_REF_DECL (x);
3888       if (!TREE_ASM_WRITTEN (exp))
3889         {
3890           n_deferred_constants--;
3891           output_constant_def_contents (x);
3892         }
3893     }
3894
3895   return -1;
3896 }
3897
3898 /* Look through appropriate parts of INSN, marking all entries in the
3899    constant pool which are actually being used.  Entries that are only
3900    referenced by other constants are also marked as used.  Emit
3901    deferred strings that are used.  */
3902
3903 static void
3904 mark_constants (rtx insn)
3905 {
3906   if (!INSN_P (insn))
3907     return;
3908
3909   /* Insns may appear inside a SEQUENCE.  Only check the patterns of
3910      insns, not any notes that may be attached.  We don't want to mark
3911      a constant just because it happens to appear in a REG_EQUIV note.  */
3912   if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3913     {
3914       rtx seq = PATTERN (insn);
3915       int i, n = XVECLEN (seq, 0);
3916       for (i = 0; i < n; ++i)
3917         {
3918           rtx subinsn = XVECEXP (seq, 0, i);
3919           if (INSN_P (subinsn))
3920             for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
3921         }
3922     }
3923   else
3924     for_each_rtx (&PATTERN (insn), mark_constant, NULL);
3925 }
3926
3927 /* Look through the instructions for this function, and mark all the
3928    entries in POOL which are actually being used.  Emit deferred constants
3929    which have indeed been used.  */
3930
3931 static void
3932 mark_constant_pool (void)
3933 {
3934   rtx insn, link;
3935
3936   if (!crtl->uses_const_pool && n_deferred_constants == 0)
3937     return;
3938
3939   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3940     mark_constants (insn);
3941
3942   for (link = crtl->epilogue_delay_list;
3943        link;
3944        link = XEXP (link, 1))
3945     mark_constants (XEXP (link, 0));
3946 }
3947
3948 /* Write all the constants in POOL.  */
3949
3950 static void
3951 output_constant_pool_contents (struct rtx_constant_pool *pool)
3952 {
3953   struct constant_descriptor_rtx *desc;
3954
3955   for (desc = pool->first; desc ; desc = desc->next)
3956     if (desc->mark)
3957       {
3958         /* If the constant is part of an object_block, make sure that
3959            the constant has been positioned within its block, but do not
3960            write out its definition yet.  output_object_blocks will do
3961            that later.  */
3962         if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
3963             && SYMBOL_REF_BLOCK (desc->sym))
3964           place_block_symbol (desc->sym);
3965         else
3966           {
3967             switch_to_section (targetm.asm_out.select_rtx_section
3968                                (desc->mode, desc->constant, desc->align));
3969             output_constant_pool_1 (desc, desc->align);
3970           }
3971       }
3972 }
3973
3974 /* Mark all constants that are used in the current function, then write
3975    out the function's private constant pool.  */
3976
3977 static void
3978 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3979                       tree fndecl ATTRIBUTE_UNUSED)
3980 {
3981   struct rtx_constant_pool *pool = crtl->varasm.pool;
3982
3983   /* It is possible for gcc to call force_const_mem and then to later
3984      discard the instructions which refer to the constant.  In such a
3985      case we do not need to output the constant.  */
3986   mark_constant_pool ();
3987
3988 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3989   ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3990 #endif
3991
3992   output_constant_pool_contents (pool);
3993
3994 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3995   ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3996 #endif
3997 }
3998 \f
3999 /* Write the contents of the shared constant pool.  */
4000
4001 void
4002 output_shared_constant_pool (void)
4003 {
4004   output_constant_pool_contents (shared_constant_pool);
4005 }
4006 \f
4007 /* Determine what kind of relocations EXP may need.  */
4008
4009 int
4010 compute_reloc_for_constant (tree exp)
4011 {
4012   int reloc = 0, reloc2;
4013   tree tem;
4014
4015   switch (TREE_CODE (exp))
4016     {
4017     case ADDR_EXPR:
4018     case FDESC_EXPR:
4019       /* Go inside any operations that get_inner_reference can handle and see
4020          if what's inside is a constant: no need to do anything here for
4021          addresses of variables or functions.  */
4022       for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4023            tem = TREE_OPERAND (tem, 0))
4024         ;
4025
4026       if (TREE_PUBLIC (tem))
4027         reloc |= 2;
4028       else
4029         reloc |= 1;
4030       break;
4031
4032     case PLUS_EXPR:
4033     case POINTER_PLUS_EXPR:
4034       reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4035       reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4036       break;
4037
4038     case MINUS_EXPR:
4039       reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4040       reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4041       /* The difference of two local labels is computable at link time.  */
4042       if (reloc == 1 && reloc2 == 1)
4043         reloc = 0;
4044       else
4045         reloc |= reloc2;
4046       break;
4047
4048     CASE_CONVERT:
4049     case VIEW_CONVERT_EXPR:
4050       reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4051       break;
4052
4053     case CONSTRUCTOR:
4054       {
4055         unsigned HOST_WIDE_INT idx;
4056         FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4057           if (tem != 0)
4058             reloc |= compute_reloc_for_constant (tem);
4059       }
4060       break;
4061
4062     default:
4063       break;
4064     }
4065   return reloc;
4066 }
4067
4068 /* Find all the constants whose addresses are referenced inside of EXP,
4069    and make sure assembler code with a label has been output for each one.
4070    Indicate whether an ADDR_EXPR has been encountered.  */
4071
4072 static void
4073 output_addressed_constants (tree exp)
4074 {
4075   tree tem;
4076
4077   switch (TREE_CODE (exp))
4078     {
4079     case ADDR_EXPR:
4080     case FDESC_EXPR:
4081       /* Go inside any operations that get_inner_reference can handle and see
4082          if what's inside is a constant: no need to do anything here for
4083          addresses of variables or functions.  */
4084       for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4085            tem = TREE_OPERAND (tem, 0))
4086         ;
4087
4088       /* If we have an initialized CONST_DECL, retrieve the initializer.  */
4089       if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4090         tem = DECL_INITIAL (tem);
4091
4092       if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4093         output_constant_def (tem, 0);
4094       break;
4095
4096     case PLUS_EXPR:
4097     case POINTER_PLUS_EXPR:
4098     case MINUS_EXPR:
4099       output_addressed_constants (TREE_OPERAND (exp, 1));
4100       /* Fall through.  */
4101
4102     CASE_CONVERT:
4103     case VIEW_CONVERT_EXPR:
4104       output_addressed_constants (TREE_OPERAND (exp, 0));
4105       break;
4106
4107     case CONSTRUCTOR:
4108       {
4109         unsigned HOST_WIDE_INT idx;
4110         FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4111           if (tem != 0)
4112             output_addressed_constants (tem);
4113       }
4114       break;
4115
4116     default:
4117       break;
4118     }
4119 }
4120 \f
4121 /* Whether a constructor CTOR is a valid static constant initializer if all
4122    its elements are.  This used to be internal to initializer_constant_valid_p
4123    and has been exposed to let other functions like categorize_ctor_elements
4124    evaluate the property while walking a constructor for other purposes.  */
4125
4126 bool
4127 constructor_static_from_elts_p (const_tree ctor)
4128 {
4129   return (TREE_CONSTANT (ctor)
4130           && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4131               || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4132           && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4133 }
4134
4135 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4136                                             tree *cache);
4137
4138 /* A subroutine of initializer_constant_valid_p.  VALUE is a MINUS_EXPR,
4139    PLUS_EXPR or POINTER_PLUS_EXPR.  This looks for cases of VALUE
4140    which are valid when ENDTYPE is an integer of any size; in
4141    particular, this does not accept a pointer minus a constant.  This
4142    returns null_pointer_node if the VALUE is an absolute constant
4143    which can be used to initialize a static variable.  Otherwise it
4144    returns NULL.  */
4145
4146 static tree
4147 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4148 {
4149   tree op0, op1;
4150
4151   if (!INTEGRAL_TYPE_P (endtype))
4152     return NULL_TREE;
4153
4154   op0 = TREE_OPERAND (value, 0);
4155   op1 = TREE_OPERAND (value, 1);
4156
4157   /* Like STRIP_NOPS except allow the operand mode to widen.  This
4158      works around a feature of fold that simplifies (int)(p1 - p2) to
4159      ((int)p1 - (int)p2) under the theory that the narrower operation
4160      is cheaper.  */
4161
4162   while (CONVERT_EXPR_P (op0)
4163          || TREE_CODE (op0) == NON_LVALUE_EXPR)
4164     {
4165       tree inner = TREE_OPERAND (op0, 0);
4166       if (inner == error_mark_node
4167           || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4168           || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4169               > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4170         break;
4171       op0 = inner;
4172     }
4173
4174   while (CONVERT_EXPR_P (op1)
4175          || TREE_CODE (op1) == NON_LVALUE_EXPR)
4176     {
4177       tree inner = TREE_OPERAND (op1, 0);
4178       if (inner == error_mark_node
4179           || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4180           || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4181               > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4182         break;
4183       op1 = inner;
4184     }
4185
4186   op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4187   if (!op0)
4188     return NULL_TREE;
4189
4190   op1 = initializer_constant_valid_p_1 (op1, endtype,
4191                                         cache ? cache + 2 : NULL);
4192   /* Both initializers must be known.  */
4193   if (op1)
4194     {
4195       if (op0 == op1
4196           && (op0 == null_pointer_node
4197               || TREE_CODE (value) == MINUS_EXPR))
4198         return null_pointer_node;
4199
4200       /* Support differences between labels.  */
4201       if (TREE_CODE (op0) == LABEL_DECL
4202           && TREE_CODE (op1) == LABEL_DECL)
4203         return null_pointer_node;
4204
4205       if (TREE_CODE (op0) == STRING_CST
4206           && TREE_CODE (op1) == STRING_CST
4207           && operand_equal_p (op0, op1, 1))
4208         return null_pointer_node;
4209     }
4210
4211   return NULL_TREE;
4212 }
4213
4214 /* Helper function of initializer_constant_valid_p.
4215    Return nonzero if VALUE is a valid constant-valued expression
4216    for use in initializing a static variable; one that can be an
4217    element of a "constant" initializer.
4218
4219    Return null_pointer_node if the value is absolute;
4220    if it is relocatable, return the variable that determines the relocation.
4221    We assume that VALUE has been folded as much as possible;
4222    therefore, we do not need to check for such things as
4223    arithmetic-combinations of integers.
4224
4225    Use CACHE (pointer to 2 tree values) for caching if non-NULL.  */
4226
4227 static tree
4228 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4229 {
4230   tree ret;
4231
4232   switch (TREE_CODE (value))
4233     {
4234     case CONSTRUCTOR:
4235       if (constructor_static_from_elts_p (value))
4236         {
4237           unsigned HOST_WIDE_INT idx;
4238           tree elt;
4239           bool absolute = true;
4240
4241           if (cache && cache[0] == value)
4242             return cache[1];
4243           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4244             {
4245               tree reloc;
4246               reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4247                                                       NULL);
4248               if (!reloc)
4249                 {
4250                   if (cache)
4251                     {
4252                       cache[0] = value;
4253                       cache[1] = NULL_TREE;
4254                     }
4255                   return NULL_TREE;
4256                 }
4257               if (reloc != null_pointer_node)
4258                 absolute = false;
4259             }
4260           /* For a non-absolute relocation, there is no single
4261              variable that can be "the variable that determines the
4262              relocation."  */
4263           if (cache)
4264             {
4265               cache[0] = value;
4266               cache[1] = absolute ? null_pointer_node : error_mark_node;
4267             }
4268           return absolute ? null_pointer_node : error_mark_node;
4269         }
4270
4271       return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4272
4273     case INTEGER_CST:
4274     case VECTOR_CST:
4275     case REAL_CST:
4276     case FIXED_CST:
4277     case STRING_CST:
4278     case COMPLEX_CST:
4279       return null_pointer_node;
4280
4281     case ADDR_EXPR:
4282     case FDESC_EXPR:
4283       {
4284         tree op0 = staticp (TREE_OPERAND (value, 0));
4285         if (op0)
4286           {
4287             /* "&(*a).f" is like unto pointer arithmetic.  If "a" turns out
4288                to be a constant, this is old-skool offsetof-like nonsense.  */
4289             if (TREE_CODE (op0) == INDIRECT_REF
4290                 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4291               return null_pointer_node;
4292             /* Taking the address of a nested function involves a trampoline,
4293                unless we don't need or want one.  */
4294             if (TREE_CODE (op0) == FUNCTION_DECL
4295                 && DECL_STATIC_CHAIN (op0)
4296                 && !TREE_NO_TRAMPOLINE (value))
4297               return NULL_TREE;
4298             /* "&{...}" requires a temporary to hold the constructed
4299                object.  */
4300             if (TREE_CODE (op0) == CONSTRUCTOR)
4301               return NULL_TREE;
4302           }
4303         return op0;
4304       }
4305
4306     case NON_LVALUE_EXPR:
4307       return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4308                                              endtype, cache);
4309
4310     case VIEW_CONVERT_EXPR:
4311       {
4312         tree src = TREE_OPERAND (value, 0);
4313         tree src_type = TREE_TYPE (src);
4314         tree dest_type = TREE_TYPE (value);
4315
4316         /* Allow view-conversions from aggregate to non-aggregate type only
4317            if the bit pattern is fully preserved afterwards; otherwise, the
4318            RTL expander won't be able to apply a subsequent transformation
4319            to the underlying constructor.  */
4320         if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4321           {
4322             if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4323               return initializer_constant_valid_p_1 (src, endtype, cache);
4324             else
4325               return NULL_TREE;
4326           }
4327
4328         /* Allow all other kinds of view-conversion.  */
4329         return initializer_constant_valid_p_1 (src, endtype, cache);
4330       }
4331
4332     CASE_CONVERT:
4333       {
4334         tree src = TREE_OPERAND (value, 0);
4335         tree src_type = TREE_TYPE (src);
4336         tree dest_type = TREE_TYPE (value);
4337
4338         /* Allow conversions between pointer types, floating-point
4339            types, and offset types.  */
4340         if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4341             || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4342             || (TREE_CODE (dest_type) == OFFSET_TYPE
4343                 && TREE_CODE (src_type) == OFFSET_TYPE))
4344           return initializer_constant_valid_p_1 (src, endtype, cache);
4345
4346         /* Allow length-preserving conversions between integer types.  */
4347         if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4348             && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4349           return initializer_constant_valid_p_1 (src, endtype, cache);
4350
4351         /* Allow conversions between other integer types only if
4352            explicit value.  */
4353         if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4354           {
4355             tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4356             if (inner == null_pointer_node)
4357               return null_pointer_node;
4358             break;
4359           }
4360
4361         /* Allow (int) &foo provided int is as wide as a pointer.  */
4362         if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4363             && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4364           return initializer_constant_valid_p_1 (src, endtype, cache);
4365
4366         /* Likewise conversions from int to pointers, but also allow
4367            conversions from 0.  */
4368         if ((POINTER_TYPE_P (dest_type)
4369              || TREE_CODE (dest_type) == OFFSET_TYPE)
4370             && INTEGRAL_TYPE_P (src_type))
4371           {
4372             if (TREE_CODE (src) == INTEGER_CST
4373                 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4374               return null_pointer_node;
4375             if (integer_zerop (src))
4376               return null_pointer_node;
4377             else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4378               return initializer_constant_valid_p_1 (src, endtype, cache);
4379           }
4380
4381         /* Allow conversions to struct or union types if the value
4382            inside is okay.  */
4383         if (TREE_CODE (dest_type) == RECORD_TYPE
4384             || TREE_CODE (dest_type) == UNION_TYPE)
4385           return initializer_constant_valid_p_1 (src, endtype, cache);
4386       }
4387       break;
4388
4389     case POINTER_PLUS_EXPR:
4390     case PLUS_EXPR:
4391       /* Any valid floating-point constants will have been folded by now;
4392          with -frounding-math we hit this with addition of two constants.  */
4393       if (TREE_CODE (endtype) == REAL_TYPE)
4394         return NULL_TREE;
4395       if (cache && cache[0] == value)
4396         return cache[1];
4397       if (! INTEGRAL_TYPE_P (endtype)
4398           || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4399         {
4400           tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4401           tree valid0
4402             = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4403                                               endtype, ncache);
4404           tree valid1
4405             = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4406                                               endtype, ncache + 2);
4407           /* If either term is absolute, use the other term's relocation.  */
4408           if (valid0 == null_pointer_node)
4409             ret = valid1;
4410           else if (valid1 == null_pointer_node)
4411             ret = valid0;
4412           /* Support narrowing pointer differences.  */
4413           else
4414             ret = narrowing_initializer_constant_valid_p (value, endtype,
4415                                                           ncache);
4416         }
4417       else
4418       /* Support narrowing pointer differences.  */
4419         ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4420       if (cache)
4421         {
4422           cache[0] = value;
4423           cache[1] = ret;
4424         }
4425       return ret;
4426
4427     case MINUS_EXPR:
4428       if (TREE_CODE (endtype) == REAL_TYPE)
4429         return NULL_TREE;
4430       if (cache && cache[0] == value)
4431         return cache[1];
4432       if (! INTEGRAL_TYPE_P (endtype)
4433           || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4434         {
4435           tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4436           tree valid0
4437             = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4438                                               endtype, ncache);
4439           tree valid1
4440             = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4441                                               endtype, ncache + 2);
4442           /* Win if second argument is absolute.  */
4443           if (valid1 == null_pointer_node)
4444             ret = valid0;
4445           /* Win if both arguments have the same relocation.
4446              Then the value is absolute.  */
4447           else if (valid0 == valid1 && valid0 != 0)
4448             ret = null_pointer_node;
4449           /* Since GCC guarantees that string constants are unique in the
4450              generated code, a subtraction between two copies of the same
4451              constant string is absolute.  */
4452           else if (valid0 && TREE_CODE (valid0) == STRING_CST
4453                    && valid1 && TREE_CODE (valid1) == STRING_CST
4454                    && operand_equal_p (valid0, valid1, 1))
4455             ret = null_pointer_node;
4456           /* Support narrowing differences.  */
4457           else
4458             ret = narrowing_initializer_constant_valid_p (value, endtype,
4459                                                           ncache);
4460         }
4461       else
4462         /* Support narrowing differences.  */
4463         ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4464       if (cache)
4465         {
4466           cache[0] = value;
4467           cache[1] = ret;
4468         }
4469       return ret;
4470
4471     default:
4472       break;
4473     }
4474
4475   return NULL_TREE;
4476 }
4477
4478 /* Return nonzero if VALUE is a valid constant-valued expression
4479    for use in initializing a static variable; one that can be an
4480    element of a "constant" initializer.
4481
4482    Return null_pointer_node if the value is absolute;
4483    if it is relocatable, return the variable that determines the relocation.
4484    We assume that VALUE has been folded as much as possible;
4485    therefore, we do not need to check for such things as
4486    arithmetic-combinations of integers.  */
4487 tree
4488 initializer_constant_valid_p (tree value, tree endtype)
4489 {
4490   return initializer_constant_valid_p_1 (value, endtype, NULL);
4491 }
4492 \f
4493 /* Return true if VALUE is a valid constant-valued expression
4494    for use in initializing a static bit-field; one that can be
4495    an element of a "constant" initializer.  */
4496
4497 bool
4498 initializer_constant_valid_for_bitfield_p (tree value)
4499 {
4500   /* For bitfields we support integer constants or possibly nested aggregates
4501      of such.  */
4502   switch (TREE_CODE (value))
4503     {
4504     case CONSTRUCTOR:
4505       {
4506         unsigned HOST_WIDE_INT idx;
4507         tree elt;
4508
4509         FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4510           if (!initializer_constant_valid_for_bitfield_p (elt))
4511             return false;
4512         return true;
4513       }
4514
4515     case INTEGER_CST:
4516       return true;
4517
4518     case VIEW_CONVERT_EXPR:
4519     case NON_LVALUE_EXPR:
4520       return
4521         initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4522
4523     default:
4524       break;
4525     }
4526
4527   return false;
4528 }
4529
4530 /* output_constructor outer state of relevance in recursive calls, typically
4531    for nested aggregate bitfields.  */
4532
4533 typedef struct {
4534   unsigned int bit_offset;  /* current position in ...  */
4535   int byte;                 /* ... the outer byte buffer.  */
4536 } oc_outer_state;
4537
4538 static unsigned HOST_WIDE_INT
4539   output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4540                       oc_outer_state *);
4541
4542 /* Output assembler code for constant EXP to FILE, with no label.
4543    This includes the pseudo-op such as ".int" or ".byte", and a newline.
4544    Assumes output_addressed_constants has been done on EXP already.
4545
4546    Generate exactly SIZE bytes of assembler data, padding at the end
4547    with zeros if necessary.  SIZE must always be specified.
4548
4549    SIZE is important for structure constructors,
4550    since trailing members may have been omitted from the constructor.
4551    It is also important for initialization of arrays from string constants
4552    since the full length of the string constant might not be wanted.
4553    It is also needed for initialization of unions, where the initializer's
4554    type is just one member, and that may not be as long as the union.
4555
4556    There a case in which we would fail to output exactly SIZE bytes:
4557    for a structure constructor that wants to produce more than SIZE bytes.
4558    But such constructors will never be generated for any possible input.
4559
4560    ALIGN is the alignment of the data in bits.  */
4561
4562 void
4563 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4564 {
4565   enum tree_code code;
4566   unsigned HOST_WIDE_INT thissize;
4567
4568   if (size == 0 || flag_syntax_only)
4569     return;
4570
4571   /* See if we're trying to initialize a pointer in a non-default mode
4572      to the address of some declaration somewhere.  If the target says
4573      the mode is valid for pointers, assume the target has a way of
4574      resolving it.  */
4575   if (TREE_CODE (exp) == NOP_EXPR
4576       && POINTER_TYPE_P (TREE_TYPE (exp))
4577       && targetm.addr_space.valid_pointer_mode
4578            (TYPE_MODE (TREE_TYPE (exp)),
4579             TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4580     {
4581       tree saved_type = TREE_TYPE (exp);
4582
4583       /* Peel off any intermediate conversions-to-pointer for valid
4584          pointer modes.  */
4585       while (TREE_CODE (exp) == NOP_EXPR
4586              && POINTER_TYPE_P (TREE_TYPE (exp))
4587              && targetm.addr_space.valid_pointer_mode
4588                   (TYPE_MODE (TREE_TYPE (exp)),
4589                    TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4590         exp = TREE_OPERAND (exp, 0);
4591
4592       /* If what we're left with is the address of something, we can
4593          convert the address to the final type and output it that
4594          way.  */
4595       if (TREE_CODE (exp) == ADDR_EXPR)
4596         exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4597       /* Likewise for constant ints.  */
4598       else if (TREE_CODE (exp) == INTEGER_CST)
4599         exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4600                                   TREE_INT_CST_HIGH (exp));
4601
4602     }
4603
4604   /* Eliminate any conversions since we'll be outputting the underlying
4605      constant.  */
4606   while (CONVERT_EXPR_P (exp)
4607          || TREE_CODE (exp) == NON_LVALUE_EXPR
4608          || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4609     {
4610       HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4611       HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4612
4613       /* Make sure eliminating the conversion is really a no-op, except with
4614          VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4615          union types to allow for Ada unchecked unions.  */
4616       if (type_size > op_size
4617           && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4618           && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4619         /* Keep the conversion. */
4620         break;
4621       else
4622         exp = TREE_OPERAND (exp, 0);
4623     }
4624
4625   code = TREE_CODE (TREE_TYPE (exp));
4626   thissize = int_size_in_bytes (TREE_TYPE (exp));
4627
4628   /* Allow a constructor with no elements for any data type.
4629      This means to fill the space with zeros.  */
4630   if (TREE_CODE (exp) == CONSTRUCTOR
4631       && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4632     {
4633       assemble_zeros (size);
4634       return;
4635     }
4636
4637   if (TREE_CODE (exp) == FDESC_EXPR)
4638     {
4639 #ifdef ASM_OUTPUT_FDESC
4640       HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4641       tree decl = TREE_OPERAND (exp, 0);
4642       ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4643 #else
4644       gcc_unreachable ();
4645 #endif
4646       return;
4647     }
4648
4649   /* Now output the underlying data.  If we've handling the padding, return.
4650      Otherwise, break and ensure SIZE is the size written.  */
4651   switch (code)
4652     {
4653     case BOOLEAN_TYPE:
4654     case INTEGER_TYPE:
4655     case ENUMERAL_TYPE:
4656     case POINTER_TYPE:
4657     case REFERENCE_TYPE:
4658     case OFFSET_TYPE:
4659     case FIXED_POINT_TYPE:
4660       if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4661                                            EXPAND_INITIALIZER),
4662                               MIN (size, thissize), align, 0))
4663         error ("initializer for integer/fixed-point value is too complicated");
4664       break;
4665
4666     case REAL_TYPE:
4667       if (TREE_CODE (exp) != REAL_CST)
4668         error ("initializer for floating value is not a floating constant");
4669       else
4670         assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4671       break;
4672
4673     case COMPLEX_TYPE:
4674       output_constant (TREE_REALPART (exp), thissize / 2, align);
4675       output_constant (TREE_IMAGPART (exp), thissize / 2,
4676                        min_align (align, BITS_PER_UNIT * (thissize / 2)));
4677       break;
4678
4679     case ARRAY_TYPE:
4680     case VECTOR_TYPE:
4681       switch (TREE_CODE (exp))
4682         {
4683         case CONSTRUCTOR:
4684             output_constructor (exp, size, align, NULL);
4685           return;
4686         case STRING_CST:
4687           thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4688                           size);
4689           assemble_string (TREE_STRING_POINTER (exp), thissize);
4690           break;
4691
4692         case VECTOR_CST:
4693           {
4694             int elt_size;
4695             tree link;
4696             unsigned int nalign;
4697             enum machine_mode inner;
4698
4699             inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4700             nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4701
4702             elt_size = GET_MODE_SIZE (inner);
4703
4704             link = TREE_VECTOR_CST_ELTS (exp);
4705             output_constant (TREE_VALUE (link), elt_size, align);
4706             thissize = elt_size;
4707             while ((link = TREE_CHAIN (link)) != NULL)
4708               {
4709                 output_constant (TREE_VALUE (link), elt_size, nalign);
4710                 thissize += elt_size;
4711               }
4712             break;
4713           }
4714         default:
4715           gcc_unreachable ();
4716         }
4717       break;
4718
4719     case RECORD_TYPE:
4720     case UNION_TYPE:
4721       gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4722       output_constructor (exp, size, align, NULL);
4723       return;
4724
4725     case ERROR_MARK:
4726       return;
4727
4728     default:
4729       gcc_unreachable ();
4730     }
4731
4732   if (size > thissize)
4733     assemble_zeros (size - thissize);
4734 }
4735
4736 \f
4737 /* Subroutine of output_constructor, used for computing the size of
4738    arrays of unspecified length.  VAL must be a CONSTRUCTOR of an array
4739    type with an unspecified upper bound.  */
4740
4741 static unsigned HOST_WIDE_INT
4742 array_size_for_constructor (tree val)
4743 {
4744   tree max_index, i;
4745   unsigned HOST_WIDE_INT cnt;
4746   tree index, value, tmp;
4747
4748   /* This code used to attempt to handle string constants that are not
4749      arrays of single-bytes, but nothing else does, so there's no point in
4750      doing it here.  */
4751   if (TREE_CODE (val) == STRING_CST)
4752     return TREE_STRING_LENGTH (val);
4753
4754   max_index = NULL_TREE;
4755   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4756     {
4757       if (TREE_CODE (index) == RANGE_EXPR)
4758         index = TREE_OPERAND (index, 1);
4759       if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4760         max_index = index;
4761     }
4762
4763   if (max_index == NULL_TREE)
4764     return 0;
4765
4766   /* Compute the total number of array elements.  */
4767   tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4768   i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4769                   fold_convert (sizetype, tmp));
4770   i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4771
4772   /* Multiply by the array element unit size to find number of bytes.  */
4773   i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4774
4775   return tree_low_cst (i, 1);
4776 }
4777
4778 /* Other datastructures + helpers for output_constructor.  */
4779
4780 /* output_constructor local state to support interaction with helpers.  */
4781
4782 typedef struct {
4783
4784   /* Received arguments.  */
4785   tree exp;                     /* Constructor expression.  */
4786   unsigned HOST_WIDE_INT size;  /* # bytes to output - pad if necessary.  */
4787   unsigned int align;           /* Known initial alignment.  */
4788
4789   /* Constructor expression data.  */
4790   tree type;       /* Expression type.  */
4791   tree field;      /* Current field decl in a record.  */
4792   tree min_index;  /* Lower bound if specified for an array.  */
4793
4794   /* Output processing state.  */
4795   HOST_WIDE_INT total_bytes;  /* # bytes output so far / current position.  */
4796   bool byte_buffer_in_use;    /* Whether byte ...  */
4797   int byte;                   /* ... contains part of a bitfield byte yet to
4798                                  be output.  */
4799
4800   int last_relative_index;    /* Implicit or explicit index of the last
4801                                  array element output within a bitfield.  */
4802   /* Current element.  */
4803   tree val;    /* Current element value.  */
4804   tree index;  /* Current element index.  */
4805
4806 } oc_local_state;
4807
4808 /* Helper for output_constructor.  From the current LOCAL state, output a
4809    RANGE_EXPR element.  */
4810
4811 static void
4812 output_constructor_array_range (oc_local_state *local)
4813 {
4814   unsigned HOST_WIDE_INT fieldsize
4815     = int_size_in_bytes (TREE_TYPE (local->type));
4816
4817   HOST_WIDE_INT lo_index
4818     = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4819   HOST_WIDE_INT hi_index
4820     = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4821   HOST_WIDE_INT index;
4822
4823   unsigned int align2
4824     = min_align (local->align, fieldsize * BITS_PER_UNIT);
4825
4826   for (index = lo_index; index <= hi_index; index++)
4827     {
4828       /* Output the element's initial value.  */
4829       if (local->val == NULL_TREE)
4830         assemble_zeros (fieldsize);
4831       else
4832         output_constant (local->val, fieldsize, align2);
4833
4834       /* Count its size.  */
4835       local->total_bytes += fieldsize;
4836     }
4837 }
4838
4839 /* Helper for output_constructor.  From the current LOCAL state, output a
4840    field element that is not true bitfield or part of an outer one.  */
4841
4842 static void
4843 output_constructor_regular_field (oc_local_state *local)
4844 {
4845   /* Field size and position.  Since this structure is static, we know the
4846      positions are constant.  */
4847   unsigned HOST_WIDE_INT fieldsize;
4848   HOST_WIDE_INT fieldpos;
4849
4850   unsigned int align2;
4851
4852   if (local->index != NULL_TREE)
4853     fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
4854                 * ((tree_low_cst (local->index, 0)
4855                     - tree_low_cst (local->min_index, 0))));
4856   else if (local->field != NULL_TREE)
4857     fieldpos = int_byte_position (local->field);
4858   else
4859     fieldpos = 0;
4860
4861   /* Output any buffered-up bit-fields preceding this element.  */
4862   if (local->byte_buffer_in_use)
4863     {
4864       assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4865       local->total_bytes++;
4866       local->byte_buffer_in_use = false;
4867     }
4868
4869   /* Advance to offset of this element.
4870      Note no alignment needed in an array, since that is guaranteed
4871      if each element has the proper size.  */
4872   if ((local->field != NULL_TREE || local->index != NULL_TREE)
4873       && fieldpos != local->total_bytes)
4874     {
4875       gcc_assert (fieldpos >= local->total_bytes);
4876       assemble_zeros (fieldpos - local->total_bytes);
4877       local->total_bytes = fieldpos;
4878     }
4879
4880   /* Find the alignment of this element.  */
4881   align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
4882
4883   /* Determine size this element should occupy.  */
4884   if (local->field)
4885     {
4886       fieldsize = 0;
4887
4888       /* If this is an array with an unspecified upper bound,
4889          the initializer determines the size.  */
4890       /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4891          but we cannot do this until the deprecated support for
4892          initializing zero-length array members is removed.  */
4893       if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
4894           && TYPE_DOMAIN (TREE_TYPE (local->field))
4895           && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
4896         {
4897           fieldsize = array_size_for_constructor (local->val);
4898           /* Given a non-empty initialization, this field had
4899              better be last.  */
4900           gcc_assert (!fieldsize || !TREE_CHAIN (local->field));
4901         }
4902       else if (DECL_SIZE_UNIT (local->field))
4903         {
4904           /* ??? This can't be right.  If the decl size overflows
4905              a host integer we will silently emit no data.  */
4906           if (host_integerp (DECL_SIZE_UNIT (local->field), 1))
4907             fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
4908         }
4909     }
4910   else
4911     fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
4912
4913   /* Output the element's initial value.  */
4914   if (local->val == NULL_TREE)
4915     assemble_zeros (fieldsize);
4916   else
4917     output_constant (local->val, fieldsize, align2);
4918
4919   /* Count its size.  */
4920   local->total_bytes += fieldsize;
4921 }
4922
4923 /* Helper for output_constructor.  From the current LOCAL and OUTER states,
4924    output an element that is a true bitfield or part of an outer one.  */
4925
4926 static void
4927 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
4928 {
4929   /* Bit size of this element.  */
4930   HOST_WIDE_INT ebitsize
4931     = (local->field
4932        ? tree_low_cst (DECL_SIZE (local->field), 1)
4933        : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
4934
4935   /* Relative index of this element if this is an array component.  */
4936   HOST_WIDE_INT relative_index
4937     = (!local->field
4938        ? (local->index
4939           ? (tree_low_cst (local->index, 0)
4940              - tree_low_cst (local->min_index, 0))
4941           : local->last_relative_index + 1)
4942        : 0);
4943
4944   /* Bit position of this element from the start of the containing
4945      constructor.  */
4946   HOST_WIDE_INT constructor_relative_ebitpos
4947       = (local->field
4948          ? int_bit_position (local->field)
4949          : ebitsize * relative_index);
4950
4951   /* Bit position of this element from the start of a possibly ongoing
4952      outer byte buffer.  */
4953   HOST_WIDE_INT byte_relative_ebitpos
4954       = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
4955
4956   /* From the start of a possibly ongoing outer byte buffer, offsets to
4957      the first bit of this element and to the first bit past the end of
4958      this element.  */
4959   HOST_WIDE_INT next_offset = byte_relative_ebitpos;
4960   HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
4961
4962   local->last_relative_index = relative_index;
4963
4964   if (local->val == NULL_TREE)
4965     local->val = integer_zero_node;
4966
4967   while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
4968          || TREE_CODE (local->val) == NON_LVALUE_EXPR)
4969     local->val = TREE_OPERAND (local->val, 0);
4970
4971   if (TREE_CODE (local->val) != INTEGER_CST
4972       && TREE_CODE (local->val) != CONSTRUCTOR)
4973     {
4974       error ("invalid initial value for member %qE", DECL_NAME (local->field));
4975       return;
4976     }
4977
4978   /* If this field does not start in this (or, next) byte,
4979      skip some bytes.  */
4980   if (next_offset / BITS_PER_UNIT != local->total_bytes)
4981     {
4982       /* Output remnant of any bit field in previous bytes.  */
4983       if (local->byte_buffer_in_use)
4984         {
4985           assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4986           local->total_bytes++;
4987           local->byte_buffer_in_use = false;
4988         }
4989
4990       /* If still not at proper byte, advance to there.  */
4991       if (next_offset / BITS_PER_UNIT != local->total_bytes)
4992         {
4993           gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
4994           assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
4995           local->total_bytes = next_offset / BITS_PER_UNIT;
4996         }
4997     }
4998
4999   /* Set up the buffer if necessary.  */
5000   if (!local->byte_buffer_in_use)
5001     {
5002       local->byte = 0;
5003       if (ebitsize > 0)
5004         local->byte_buffer_in_use = true;
5005     }
5006
5007   /* If this is nested constructor, recurse passing the bit offset and the
5008      pending data, then retrieve the new pending data afterwards.  */
5009   if (TREE_CODE (local->val) == CONSTRUCTOR)
5010     {
5011       oc_outer_state output_state;
5012
5013       output_state.bit_offset = next_offset % BITS_PER_UNIT;
5014       output_state.byte = local->byte;
5015       local->total_bytes
5016           += output_constructor (local->val, 0, 0, &output_state);
5017       local->byte = output_state.byte;
5018       return;
5019     }
5020
5021   /* Otherwise, we must split the element into pieces that fall within
5022      separate bytes, and combine each byte with previous or following
5023      bit-fields.  */
5024   while (next_offset < end_offset)
5025     {
5026       int this_time;
5027       int shift;
5028       HOST_WIDE_INT value;
5029       HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
5030       HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
5031
5032       /* Advance from byte to byte
5033          within this element when necessary.  */
5034       while (next_byte != local->total_bytes)
5035         {
5036           assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5037           local->total_bytes++;
5038           local->byte = 0;
5039         }
5040
5041       /* Number of bits we can process at once
5042          (all part of the same byte).  */
5043       this_time = MIN (end_offset - next_offset,
5044                        BITS_PER_UNIT - next_bit);
5045       if (BYTES_BIG_ENDIAN)
5046         {
5047           /* On big-endian machine, take the most significant bits
5048              first (of the bits that are significant)
5049              and put them into bytes from the most significant end.  */
5050           shift = end_offset - next_offset - this_time;
5051
5052           /* Don't try to take a bunch of bits that cross
5053              the word boundary in the INTEGER_CST. We can
5054              only select bits from the LOW or HIGH part
5055              not from both.  */
5056           if (shift < HOST_BITS_PER_WIDE_INT
5057               && shift + this_time > HOST_BITS_PER_WIDE_INT)
5058             {
5059               this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
5060               shift = HOST_BITS_PER_WIDE_INT;
5061             }
5062
5063           /* Now get the bits from the appropriate constant word.  */
5064           if (shift < HOST_BITS_PER_WIDE_INT)
5065             value = TREE_INT_CST_LOW (local->val);
5066           else
5067             {
5068               gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5069               value = TREE_INT_CST_HIGH (local->val);
5070               shift -= HOST_BITS_PER_WIDE_INT;
5071             }
5072
5073           /* Get the result. This works only when:
5074              1 <= this_time <= HOST_BITS_PER_WIDE_INT.  */
5075           local->byte |= (((value >> shift)
5076                            & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5077                           << (BITS_PER_UNIT - this_time - next_bit));
5078         }
5079       else
5080         {
5081           /* On little-endian machines,
5082              take first the least significant bits of the value
5083              and pack them starting at the least significant
5084              bits of the bytes.  */
5085           shift = next_offset - byte_relative_ebitpos;
5086
5087           /* Don't try to take a bunch of bits that cross
5088              the word boundary in the INTEGER_CST. We can
5089              only select bits from the LOW or HIGH part
5090              not from both.  */
5091           if (shift < HOST_BITS_PER_WIDE_INT
5092               && shift + this_time > HOST_BITS_PER_WIDE_INT)
5093             this_time = (HOST_BITS_PER_WIDE_INT - shift);
5094
5095           /* Now get the bits from the appropriate constant word.  */
5096           if (shift < HOST_BITS_PER_WIDE_INT)
5097             value = TREE_INT_CST_LOW (local->val);
5098           else
5099             {
5100               gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5101               value = TREE_INT_CST_HIGH (local->val);
5102               shift -= HOST_BITS_PER_WIDE_INT;
5103             }
5104
5105           /* Get the result. This works only when:
5106              1 <= this_time <= HOST_BITS_PER_WIDE_INT.  */
5107           local->byte |= (((value >> shift)
5108                            & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5109                           << next_bit);
5110         }
5111
5112       next_offset += this_time;
5113       local->byte_buffer_in_use = true;
5114     }
5115 }
5116
5117 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5118    Generate at least SIZE bytes, padding if necessary.  OUTER designates the
5119    caller output state of relevance in recursive invocations.  */
5120
5121 static unsigned HOST_WIDE_INT
5122 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
5123                     unsigned int align, oc_outer_state * outer)
5124 {
5125   unsigned HOST_WIDE_INT cnt;
5126   constructor_elt *ce;
5127
5128   oc_local_state local;
5129
5130   /* Setup our local state to communicate with helpers.  */
5131   local.exp = exp;
5132   local.size = size;
5133   local.align = align;
5134
5135   local.total_bytes = 0;
5136   local.byte_buffer_in_use = outer != NULL;
5137   local.byte = outer ? outer->byte : 0;
5138
5139   local.type = TREE_TYPE (exp);
5140
5141   local.last_relative_index = -1;
5142
5143   local.min_index = NULL_TREE;
5144   if (TREE_CODE (local.type) == ARRAY_TYPE
5145       && TYPE_DOMAIN (local.type) != NULL_TREE)
5146     local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5147
5148   gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
5149
5150   /* As CE goes through the elements of the constant, FIELD goes through the
5151      structure fields if the constant is a structure.  If the constant is a
5152      union, we override this by getting the field from the TREE_LIST element.
5153      But the constant could also be an array.  Then FIELD is zero.
5154
5155      There is always a maximum of one element in the chain LINK for unions
5156      (even if the initializer in a source program incorrectly contains
5157      more one).  */
5158
5159   local.field = NULL_TREE;
5160   if (TREE_CODE (local.type) == RECORD_TYPE)
5161     local.field = TYPE_FIELDS (local.type);
5162
5163   for (cnt = 0;
5164        VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
5165        cnt++, local.field = local.field ? TREE_CHAIN (local.field) : 0)
5166     {
5167       local.val = ce->value;
5168       local.index = NULL_TREE;
5169
5170       /* The element in a union constructor specifies the proper field
5171          or index.  */
5172       if ((TREE_CODE (local.type) == RECORD_TYPE
5173            || TREE_CODE (local.type) == UNION_TYPE
5174            || TREE_CODE (local.type) == QUAL_UNION_TYPE)
5175           && ce->index != NULL_TREE)
5176         local.field = ce->index;
5177
5178       else if (TREE_CODE (local.type) == ARRAY_TYPE)
5179         local.index = ce->index;
5180
5181 #ifdef ASM_COMMENT_START
5182       if (local.field && flag_verbose_asm)
5183         fprintf (asm_out_file, "%s %s:\n",
5184                  ASM_COMMENT_START,
5185                  DECL_NAME (local.field)
5186                  ? IDENTIFIER_POINTER (DECL_NAME (local.field))
5187                  : "<anonymous>");
5188 #endif
5189
5190       /* Eliminate the marker that makes a cast not be an lvalue.  */
5191       if (local.val != NULL_TREE)
5192         STRIP_NOPS (local.val);
5193
5194       /* Output the current element, using the appropriate helper ...  */
5195
5196       /* For an array slice not part of an outer bitfield.  */
5197       if (!outer
5198           && local.index != NULL_TREE
5199           && TREE_CODE (local.index) == RANGE_EXPR)
5200         output_constructor_array_range (&local);
5201
5202       /* For a field that is neither a true bitfield nor part of an outer one,
5203          known to be at least byte aligned and multiple-of-bytes long.  */
5204       else if (!outer
5205                && (local.field == NULL_TREE
5206                    || !CONSTRUCTOR_BITFIELD_P (local.field)))
5207         output_constructor_regular_field (&local);
5208
5209       /* For a true bitfield or part of an outer one.  */
5210       else
5211         output_constructor_bitfield (&local, outer);
5212     }
5213
5214   /* If we are not at toplevel, save the pending data for our caller.
5215      Otherwise output the pending data and padding zeros as needed. */
5216   if (outer)
5217     outer->byte = local.byte;
5218   else
5219     {
5220       if (local.byte_buffer_in_use)
5221         {
5222           assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
5223           local.total_bytes++;
5224         }
5225
5226       if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
5227         {
5228           assemble_zeros (local.size - local.total_bytes);
5229           local.total_bytes = local.size;
5230         }
5231     }
5232
5233   return local.total_bytes;
5234 }
5235
5236 /* Mark DECL as weak.  */
5237
5238 static void
5239 mark_weak (tree decl)
5240 {
5241   DECL_WEAK (decl) = 1;
5242
5243   if (DECL_RTL_SET_P (decl)
5244       && MEM_P (DECL_RTL (decl))
5245       && XEXP (DECL_RTL (decl), 0)
5246       && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5247     SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5248 }
5249
5250 /* Merge weak status between NEWDECL and OLDDECL.  */
5251
5252 void
5253 merge_weak (tree newdecl, tree olddecl)
5254 {
5255   if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5256     {
5257       if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
5258         {
5259           tree *pwd;
5260           /* We put the NEWDECL on the weak_decls list at some point
5261              and OLDDECL as well.  Keep just OLDDECL on the list.  */
5262           for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5263             if (TREE_VALUE (*pwd) == newdecl)
5264               {
5265                 *pwd = TREE_CHAIN (*pwd);
5266                 break;
5267               }
5268         }
5269       return;
5270     }
5271
5272   if (DECL_WEAK (newdecl))
5273     {
5274       tree wd;
5275
5276       /* NEWDECL is weak, but OLDDECL is not.  */
5277
5278       /* If we already output the OLDDECL, we're in trouble; we can't
5279          go back and make it weak.  This error cannot be caught in
5280          declare_weak because the NEWDECL and OLDDECL was not yet
5281          been merged; therefore, TREE_ASM_WRITTEN was not set.  */
5282       if (TREE_ASM_WRITTEN (olddecl))
5283         error ("weak declaration of %q+D must precede definition",
5284                newdecl);
5285
5286       /* If we've already generated rtl referencing OLDDECL, we may
5287          have done so in a way that will not function properly with
5288          a weak symbol.  */
5289       else if (TREE_USED (olddecl)
5290                && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
5291         warning (0, "weak declaration of %q+D after first use results "
5292                  "in unspecified behavior", newdecl);
5293
5294       if (SUPPORTS_WEAK)
5295         {
5296           /* We put the NEWDECL on the weak_decls list at some point.
5297              Replace it with the OLDDECL.  */
5298           for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5299             if (TREE_VALUE (wd) == newdecl)
5300               {
5301                 TREE_VALUE (wd) = olddecl;
5302                 break;
5303               }
5304           /* We may not find the entry on the list.  If NEWDECL is a
5305              weak alias, then we will have already called
5306              globalize_decl to remove the entry; in that case, we do
5307              not need to do anything.  */
5308         }
5309
5310       /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping.  */
5311       mark_weak (olddecl);
5312     }
5313   else
5314     /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5315        weak.  Just update NEWDECL to indicate that it's weak too.  */
5316     mark_weak (newdecl);
5317 }
5318
5319 /* Declare DECL to be a weak symbol.  */
5320
5321 void
5322 declare_weak (tree decl)
5323 {
5324   if (! TREE_PUBLIC (decl))
5325     error ("weak declaration of %q+D must be public", decl);
5326   else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
5327     error ("weak declaration of %q+D must precede definition", decl);
5328   else if (!SUPPORTS_WEAK)
5329     warning (0, "weak declaration of %q+D not supported", decl);
5330
5331   mark_weak (decl);
5332   if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5333     DECL_ATTRIBUTES (decl)
5334       = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5335 }
5336
5337 static void
5338 weak_finish_1 (tree decl)
5339 {
5340 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5341   const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5342 #endif
5343
5344   if (! TREE_USED (decl))
5345     return;
5346
5347 #ifdef ASM_WEAKEN_DECL
5348   ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5349 #else
5350 #ifdef ASM_WEAKEN_LABEL
5351   ASM_WEAKEN_LABEL (asm_out_file, name);
5352 #else
5353 #ifdef ASM_OUTPUT_WEAK_ALIAS
5354   {
5355     static bool warn_once = 0;
5356     if (! warn_once)
5357       {
5358         warning (0, "only weak aliases are supported in this configuration");
5359         warn_once = 1;
5360       }
5361     return;
5362   }
5363 #endif
5364 #endif
5365 #endif
5366 }
5367
5368 /* This TREE_LIST contains weakref targets.  */
5369
5370 static GTY(()) tree weakref_targets;
5371
5372 /* Forward declaration.  */
5373 static tree find_decl_and_mark_needed (tree decl, tree target);
5374
5375 /* Emit any pending weak declarations.  */
5376
5377 void
5378 weak_finish (void)
5379 {
5380   tree t;
5381
5382   for (t = weakref_targets; t; t = TREE_CHAIN (t))
5383     {
5384       tree alias_decl = TREE_PURPOSE (t);
5385       tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5386
5387       if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5388         /* Remove alias_decl from the weak list, but leave entries for
5389            the target alone.  */
5390         target = NULL_TREE;
5391 #ifndef ASM_OUTPUT_WEAKREF
5392       else if (! TREE_SYMBOL_REFERENCED (target))
5393         {
5394           /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5395              defined, otherwise we and weak_finish_1 would use
5396              different macros.  */
5397 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5398           ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5399 # else
5400           tree decl = find_decl_and_mark_needed (alias_decl, target);
5401
5402           if (! decl)
5403             {
5404               decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5405                                  TREE_CODE (alias_decl), target,
5406                                  TREE_TYPE (alias_decl));
5407
5408               DECL_EXTERNAL (decl) = 1;
5409               TREE_PUBLIC (decl) = 1;
5410               DECL_ARTIFICIAL (decl) = 1;
5411               TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5412               TREE_USED (decl) = 1;
5413             }
5414
5415           weak_finish_1 (decl);
5416 # endif
5417         }
5418 #endif
5419
5420       {
5421         tree *p;
5422         tree t2;
5423
5424         /* Remove the alias and the target from the pending weak list
5425            so that we do not emit any .weak directives for the former,
5426            nor multiple .weak directives for the latter.  */
5427         for (p = &weak_decls; (t2 = *p) ; )
5428           {
5429             if (TREE_VALUE (t2) == alias_decl
5430                 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5431               *p = TREE_CHAIN (t2);
5432             else
5433               p = &TREE_CHAIN (t2);
5434           }
5435
5436         /* Remove other weakrefs to the same target, to speed things up.  */
5437         for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5438           {
5439             if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5440               *p = TREE_CHAIN (t2);
5441             else
5442               p = &TREE_CHAIN (t2);
5443           }
5444       }
5445     }
5446
5447   for (t = weak_decls; t; t = TREE_CHAIN (t))
5448     {
5449       tree decl = TREE_VALUE (t);
5450
5451       weak_finish_1 (decl);
5452     }
5453 }
5454
5455 /* Emit the assembly bits to indicate that DECL is globally visible.  */
5456
5457 static void
5458 globalize_decl (tree decl)
5459 {
5460
5461 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5462   if (DECL_WEAK (decl))
5463     {
5464       const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5465       tree *p, t;
5466
5467 #ifdef ASM_WEAKEN_DECL
5468       ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5469 #else
5470       ASM_WEAKEN_LABEL (asm_out_file, name);
5471 #endif
5472
5473       /* Remove this function from the pending weak list so that
5474          we do not emit multiple .weak directives for it.  */
5475       for (p = &weak_decls; (t = *p) ; )
5476         {
5477           if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5478             *p = TREE_CHAIN (t);
5479           else
5480             p = &TREE_CHAIN (t);
5481         }
5482
5483       /* Remove weakrefs to the same target from the pending weakref
5484          list, for the same reason.  */
5485       for (p = &weakref_targets; (t = *p) ; )
5486         {
5487           if (DECL_ASSEMBLER_NAME (decl)
5488               == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5489             *p = TREE_CHAIN (t);
5490           else
5491             p = &TREE_CHAIN (t);
5492         }
5493
5494       return;
5495     }
5496 #endif
5497
5498   targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5499 }
5500
5501 VEC(alias_pair,gc) *alias_pairs;
5502
5503 /* Given an assembly name, find the decl it is associated with.  At the
5504    same time, mark it needed for cgraph.  */
5505
5506 static tree
5507 find_decl_and_mark_needed (tree decl, tree target)
5508 {
5509   struct cgraph_node *fnode = NULL;
5510   struct varpool_node *vnode = NULL;
5511
5512   if (TREE_CODE (decl) == FUNCTION_DECL)
5513     {
5514       fnode = cgraph_node_for_asm (target);
5515       if (fnode == NULL)
5516         vnode = varpool_node_for_asm (target);
5517     }
5518   else
5519     {
5520       vnode = varpool_node_for_asm (target);
5521       if (vnode == NULL)
5522         fnode = cgraph_node_for_asm (target);
5523     }
5524
5525   if (fnode)
5526     {
5527       cgraph_mark_needed_node (fnode);
5528       return fnode->decl;
5529     }
5530   else if (vnode)
5531     {
5532       varpool_mark_needed_node (vnode);
5533       return vnode->decl;
5534     }
5535   else
5536     return NULL_TREE;
5537 }
5538
5539 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5540    or ASM_OUTPUT_DEF_FROM_DECLS.  The function defines the symbol whose
5541    tree node is DECL to have the value of the tree node TARGET.  */
5542
5543 static void
5544 do_assemble_alias (tree decl, tree target)
5545 {
5546   if (TREE_ASM_WRITTEN (decl))
5547     return;
5548
5549   /* We must force creation of DECL_RTL for debug info generation, even though
5550      we don't use it here.  */
5551   make_decl_rtl (decl);
5552
5553   TREE_ASM_WRITTEN (decl) = 1;
5554   TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5555
5556   if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5557     {
5558       ultimate_transparent_alias_target (&target);
5559
5560       if (!targetm.have_tls
5561           && TREE_CODE (decl) == VAR_DECL
5562           && DECL_THREAD_LOCAL_P (decl))
5563         {
5564           decl = emutls_decl (decl);
5565           target = get_emutls_object_name (target);
5566         }
5567
5568       if (!TREE_SYMBOL_REFERENCED (target))
5569         weakref_targets = tree_cons (decl, target, weakref_targets);
5570
5571 #ifdef ASM_OUTPUT_WEAKREF
5572       ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5573                           IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5574                           IDENTIFIER_POINTER (target));
5575 #else
5576       if (!SUPPORTS_WEAK)
5577         {
5578           error_at (DECL_SOURCE_LOCATION (decl),
5579                     "weakref is not supported in this configuration");
5580           return;
5581         }
5582 #endif
5583       return;
5584     }
5585
5586   if (!targetm.have_tls
5587       && TREE_CODE (decl) == VAR_DECL
5588       && DECL_THREAD_LOCAL_P (decl))
5589     {
5590       decl = emutls_decl (decl);
5591       target = get_emutls_object_name (target);
5592     }
5593
5594 #ifdef ASM_OUTPUT_DEF
5595   /* Make name accessible from other files, if appropriate.  */
5596
5597   if (TREE_PUBLIC (decl))
5598     {
5599       globalize_decl (decl);
5600       maybe_assemble_visibility (decl);
5601     }
5602
5603 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5604   ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5605 # else
5606   ASM_OUTPUT_DEF (asm_out_file,
5607                   IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5608                   IDENTIFIER_POINTER (target));
5609 # endif
5610 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5611   {
5612     const char *name;
5613     tree *p, t;
5614
5615     name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5616 # ifdef ASM_WEAKEN_DECL
5617     ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5618 # else
5619     ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5620 # endif
5621     /* Remove this function from the pending weak list so that
5622        we do not emit multiple .weak directives for it.  */
5623     for (p = &weak_decls; (t = *p) ; )
5624       if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5625         *p = TREE_CHAIN (t);
5626       else
5627         p = &TREE_CHAIN (t);
5628
5629     /* Remove weakrefs to the same target from the pending weakref
5630        list, for the same reason.  */
5631     for (p = &weakref_targets; (t = *p) ; )
5632       {
5633         if (DECL_ASSEMBLER_NAME (decl)
5634             == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5635           *p = TREE_CHAIN (t);
5636         else
5637           p = &TREE_CHAIN (t);
5638       }
5639   }
5640 #endif
5641 }
5642
5643
5644 /* Remove the alias pairing for functions that are no longer in the call
5645    graph.  */
5646
5647 void
5648 remove_unreachable_alias_pairs (void)
5649 {
5650   unsigned i;
5651   alias_pair *p;
5652
5653   if (alias_pairs == NULL)
5654     return;
5655
5656   for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5657     {
5658       if (!DECL_EXTERNAL (p->decl))
5659         {
5660           struct cgraph_node *fnode = NULL;
5661           struct varpool_node *vnode = NULL;
5662           fnode = cgraph_node_for_asm (p->target);
5663           vnode = (fnode == NULL) ? varpool_node_for_asm (p->target) : NULL;
5664           if (fnode == NULL && vnode == NULL)
5665             {
5666               VEC_unordered_remove (alias_pair, alias_pairs, i);
5667               continue;
5668             }
5669         }
5670
5671       i++;
5672     }
5673 }
5674
5675
5676 /* First pass of completing pending aliases.  Make sure that cgraph knows
5677    which symbols will be required.  */
5678
5679 void
5680 finish_aliases_1 (void)
5681 {
5682   unsigned i;
5683   alias_pair *p;
5684
5685   for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5686     {
5687       tree target_decl;
5688
5689       target_decl = find_decl_and_mark_needed (p->decl, p->target);
5690       if (target_decl == NULL)
5691         {
5692           if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5693             error ("%q+D aliased to undefined symbol %qE",
5694                    p->decl, p->target);
5695         }
5696       else if (DECL_EXTERNAL (target_decl)
5697                /* We use local aliases for C++ thunks to force the tailcall
5698                   to bind locally.  Of course this is a hack - to keep it
5699                   working do the following (which is not strictly correct).  */
5700                && (! TREE_CODE (target_decl) == FUNCTION_DECL
5701                    || ! DECL_VIRTUAL_P (target_decl))
5702                && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5703         error ("%q+D aliased to external symbol %qE",
5704                p->decl, p->target);
5705     }
5706 }
5707
5708 /* Second pass of completing pending aliases.  Emit the actual assembly.
5709    This happens at the end of compilation and thus it is assured that the
5710    target symbol has been emitted.  */
5711
5712 void
5713 finish_aliases_2 (void)
5714 {
5715   unsigned i;
5716   alias_pair *p;
5717
5718   for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5719     do_assemble_alias (p->decl, p->target);
5720
5721   VEC_truncate (alias_pair, alias_pairs, 0);
5722 }
5723
5724 /* Emit an assembler directive to make the symbol for DECL an alias to
5725    the symbol for TARGET.  */
5726
5727 void
5728 assemble_alias (tree decl, tree target)
5729 {
5730   tree target_decl;
5731   bool is_weakref = false;
5732
5733   if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5734     {
5735       tree alias = DECL_ASSEMBLER_NAME (decl);
5736
5737       is_weakref = true;
5738
5739       ultimate_transparent_alias_target (&target);
5740
5741       if (alias == target)
5742         error ("weakref %q+D ultimately targets itself", decl);
5743       else
5744         {
5745 #ifndef ASM_OUTPUT_WEAKREF
5746           IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5747           TREE_CHAIN (alias) = target;
5748 #endif
5749         }
5750       if (TREE_PUBLIC (decl))
5751         error ("weakref %q+D must have static linkage", decl);
5752     }
5753   else
5754     {
5755 #if !defined (ASM_OUTPUT_DEF)
5756 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5757       error_at (DECL_SOURCE_LOCATION (decl),
5758                 "alias definitions not supported in this configuration");
5759       return;
5760 # else
5761       if (!DECL_WEAK (decl))
5762         {
5763           error_at (DECL_SOURCE_LOCATION (decl),
5764                     "only weak aliases are supported in this configuration");
5765           return;
5766         }
5767 # endif
5768 #endif
5769     }
5770   TREE_USED (decl) = 1;
5771
5772   /* A quirk of the initial implementation of aliases required that the user
5773      add "extern" to all of them.  Which is silly, but now historical.  Do
5774      note that the symbol is in fact locally defined.  */
5775   if (! is_weakref)
5776     DECL_EXTERNAL (decl) = 0;
5777
5778   /* Allow aliases to aliases.  */
5779   if (TREE_CODE (decl) == FUNCTION_DECL)
5780     cgraph_node (decl)->alias = true;
5781   else
5782     varpool_node (decl)->alias = true;
5783
5784   /* If the target has already been emitted, we don't have to queue the
5785      alias.  This saves a tad of memory.  */
5786   if (cgraph_global_info_ready)
5787     target_decl = find_decl_and_mark_needed (decl, target);
5788   else
5789     target_decl= NULL;
5790   if (target_decl && TREE_ASM_WRITTEN (target_decl))
5791     do_assemble_alias (decl, target);
5792   else
5793     {
5794       alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5795       p->decl = decl;
5796       p->target = target;
5797     }
5798 }
5799
5800 /* Emit an assembler directive to set symbol for DECL visibility to
5801    the visibility type VIS, which must not be VISIBILITY_DEFAULT.  */
5802
5803 void
5804 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED, 
5805                              int vis ATTRIBUTE_UNUSED)
5806 {
5807 #ifdef HAVE_GAS_HIDDEN
5808   static const char * const visibility_types[] = {
5809     NULL, "protected", "hidden", "internal"
5810   };
5811
5812   const char *name, *type;
5813
5814   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5815   type = visibility_types[vis];
5816
5817   fprintf (asm_out_file, "\t.%s\t", type);
5818   assemble_name (asm_out_file, name);
5819   fprintf (asm_out_file, "\n");
5820 #else
5821   warning (OPT_Wattributes, "visibility attribute not supported "
5822            "in this configuration; ignored");
5823 #endif
5824 }
5825
5826 /* A helper function to call assemble_visibility when needed for a decl.  */
5827
5828 int
5829 maybe_assemble_visibility (tree decl)
5830 {
5831   enum symbol_visibility vis = DECL_VISIBILITY (decl);
5832
5833   if (vis != VISIBILITY_DEFAULT)
5834     {
5835       targetm.asm_out.visibility (decl, vis);
5836       return 1;
5837     }
5838   else
5839     return 0;
5840 }
5841
5842 /* Returns 1 if the target configuration supports defining public symbols
5843    so that one of them will be chosen at link time instead of generating a
5844    multiply-defined symbol error, whether through the use of weak symbols or
5845    a target-specific mechanism for having duplicates discarded.  */
5846
5847 int
5848 supports_one_only (void)
5849 {
5850   if (SUPPORTS_ONE_ONLY)
5851     return 1;
5852   return SUPPORTS_WEAK;
5853 }
5854
5855 /* Set up DECL as a public symbol that can be defined in multiple
5856    translation units without generating a linker error.  */
5857
5858 void
5859 make_decl_one_only (tree decl, tree comdat_group)
5860 {
5861   gcc_assert (TREE_CODE (decl) == VAR_DECL
5862               || TREE_CODE (decl) == FUNCTION_DECL);
5863
5864   TREE_PUBLIC (decl) = 1;
5865
5866   if (SUPPORTS_ONE_ONLY)
5867     {
5868 #ifdef MAKE_DECL_ONE_ONLY
5869       MAKE_DECL_ONE_ONLY (decl);
5870 #endif
5871       DECL_COMDAT_GROUP (decl) = comdat_group;
5872     }
5873   else if (TREE_CODE (decl) == VAR_DECL
5874       && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5875     DECL_COMMON (decl) = 1;
5876   else
5877     {
5878       gcc_assert (SUPPORTS_WEAK);
5879       DECL_WEAK (decl) = 1;
5880     }
5881 }
5882
5883 void
5884 init_varasm_once (void)
5885 {
5886   section_htab = htab_create_ggc (31, section_entry_hash,
5887                                   section_entry_eq, NULL);
5888   object_block_htab = htab_create_ggc (31, object_block_entry_hash,
5889                                        object_block_entry_eq, NULL);
5890   const_desc_htab = htab_create_ggc (1009, const_desc_hash,
5891                                      const_desc_eq, NULL);
5892
5893   const_alias_set = new_alias_set ();
5894   shared_constant_pool = create_constant_pool ();
5895
5896 #ifdef TEXT_SECTION_ASM_OP
5897   text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
5898                                       TEXT_SECTION_ASM_OP);
5899 #endif
5900
5901 #ifdef DATA_SECTION_ASM_OP
5902   data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5903                                       DATA_SECTION_ASM_OP);
5904 #endif
5905
5906 #ifdef SDATA_SECTION_ASM_OP
5907   sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5908                                        SDATA_SECTION_ASM_OP);
5909 #endif
5910
5911 #ifdef READONLY_DATA_SECTION_ASM_OP
5912   readonly_data_section = get_unnamed_section (0, output_section_asm_op,
5913                                                READONLY_DATA_SECTION_ASM_OP);
5914 #endif
5915
5916 #ifdef CTORS_SECTION_ASM_OP
5917   ctors_section = get_unnamed_section (0, output_section_asm_op,
5918                                        CTORS_SECTION_ASM_OP);
5919 #endif
5920
5921 #ifdef DTORS_SECTION_ASM_OP
5922   dtors_section = get_unnamed_section (0, output_section_asm_op,
5923                                        DTORS_SECTION_ASM_OP);
5924 #endif
5925
5926 #ifdef BSS_SECTION_ASM_OP
5927   bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5928                                      output_section_asm_op,
5929                                      BSS_SECTION_ASM_OP);
5930 #endif
5931
5932 #ifdef SBSS_SECTION_ASM_OP
5933   sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5934                                       output_section_asm_op,
5935                                       SBSS_SECTION_ASM_OP);
5936 #endif
5937
5938   tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5939                                            | SECTION_COMMON, emit_tls_common);
5940   lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5941                                         | SECTION_COMMON, emit_local);
5942   comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5943                                        | SECTION_COMMON, emit_common);
5944
5945 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5946   bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
5947                                                emit_bss);
5948 #endif
5949
5950   targetm.asm_out.init_sections ();
5951
5952   if (readonly_data_section == NULL)
5953     readonly_data_section = text_section;
5954 }
5955
5956 enum tls_model
5957 decl_default_tls_model (const_tree decl)
5958 {
5959   enum tls_model kind;
5960   bool is_local;
5961
5962   is_local = targetm.binds_local_p (decl);
5963   if (!flag_shlib)
5964     {
5965       if (is_local)
5966         kind = TLS_MODEL_LOCAL_EXEC;
5967       else
5968         kind = TLS_MODEL_INITIAL_EXEC;
5969     }
5970
5971   /* Local dynamic is inefficient when we're not combining the
5972      parts of the address.  */
5973   else if (optimize && is_local)
5974     kind = TLS_MODEL_LOCAL_DYNAMIC;
5975   else
5976     kind = TLS_MODEL_GLOBAL_DYNAMIC;
5977   if (kind < flag_tls_default)
5978     kind = flag_tls_default;
5979
5980   return kind;
5981 }
5982
5983 /* Select a set of attributes for section NAME based on the properties
5984    of DECL and whether or not RELOC indicates that DECL's initializer
5985    might contain runtime relocations.
5986
5987    We make the section read-only and executable for a function decl,
5988    read-only for a const data decl, and writable for a non-const data decl.  */
5989
5990 unsigned int
5991 default_section_type_flags (tree decl, const char *name, int reloc)
5992 {
5993   unsigned int flags;
5994
5995   if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5996     flags = SECTION_CODE;
5997   else if (decl && decl_readonly_section (decl, reloc))
5998     flags = 0;
5999   else if (current_function_decl
6000            && cfun
6001            && crtl->subsections.unlikely_text_section_name
6002            && strcmp (name, crtl->subsections.unlikely_text_section_name) == 0)
6003     flags = SECTION_CODE;
6004   else if (!decl
6005            && (!current_function_decl || !cfun)
6006            && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6007     flags = SECTION_CODE;
6008   else
6009     flags = SECTION_WRITE;
6010
6011   if (decl && DECL_ONE_ONLY (decl))
6012     flags |= SECTION_LINKONCE;
6013
6014   if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6015     flags |= SECTION_TLS | SECTION_WRITE;
6016
6017   if (strcmp (name, ".bss") == 0
6018       || strncmp (name, ".bss.", 5) == 0
6019       || strncmp (name, ".gnu.linkonce.b.", 16) == 0
6020       || strcmp (name, ".sbss") == 0
6021       || strncmp (name, ".sbss.", 6) == 0
6022       || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
6023     flags |= SECTION_BSS;
6024
6025   if (strcmp (name, ".tdata") == 0
6026       || strncmp (name, ".tdata.", 7) == 0
6027       || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
6028     flags |= SECTION_TLS;
6029
6030   if (strcmp (name, ".tbss") == 0
6031       || strncmp (name, ".tbss.", 6) == 0
6032       || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
6033     flags |= SECTION_TLS | SECTION_BSS;
6034
6035   /* These three sections have special ELF types.  They are neither
6036      SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6037      want to print a section type (@progbits or @nobits).  If someone
6038      is silly enough to emit code or TLS variables to one of these
6039      sections, then don't handle them specially.  */
6040   if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
6041       && (strcmp (name, ".init_array") == 0
6042           || strcmp (name, ".fini_array") == 0
6043           || strcmp (name, ".preinit_array") == 0))
6044     flags |= SECTION_NOTYPE;
6045
6046   return flags;
6047 }
6048
6049 /* Return true if the target supports some form of global BSS,
6050    either through bss_noswitch_section, or by selecting a BSS
6051    section in TARGET_ASM_SELECT_SECTION.  */
6052
6053 bool
6054 have_global_bss_p (void)
6055 {
6056   return bss_noswitch_section || targetm.have_switchable_bss_sections;
6057 }
6058
6059 /* Output assembly to switch to section NAME with attribute FLAGS.
6060    Four variants for common object file formats.  */
6061
6062 void
6063 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
6064                           unsigned int flags ATTRIBUTE_UNUSED,
6065                           tree decl ATTRIBUTE_UNUSED)
6066 {
6067   /* Some object formats don't support named sections at all.  The
6068      front-end should already have flagged this as an error.  */
6069   gcc_unreachable ();
6070 }
6071
6072 #ifndef TLS_SECTION_ASM_FLAG
6073 #define TLS_SECTION_ASM_FLAG 'T'
6074 #endif
6075
6076 void
6077 default_elf_asm_named_section (const char *name, unsigned int flags,
6078                                tree decl ATTRIBUTE_UNUSED)
6079 {
6080   char flagchars[10], *f = flagchars;
6081
6082   /* If we have already declared this section, we can use an
6083      abbreviated form to switch back to it -- unless this section is
6084      part of a COMDAT groups, in which case GAS requires the full
6085      declaration every time.  */
6086   if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6087       && (flags & SECTION_DECLARED))
6088     {
6089       fprintf (asm_out_file, "\t.section\t%s\n", name);
6090       return;
6091     }
6092
6093   if (!(flags & SECTION_DEBUG))
6094     *f++ = 'a';
6095   if (flags & SECTION_WRITE)
6096     *f++ = 'w';
6097   if (flags & SECTION_CODE)
6098     *f++ = 'x';
6099   if (flags & SECTION_SMALL)
6100     *f++ = 's';
6101   if (flags & SECTION_MERGE)
6102     *f++ = 'M';
6103   if (flags & SECTION_STRINGS)
6104     *f++ = 'S';
6105   if (flags & SECTION_TLS)
6106     *f++ = TLS_SECTION_ASM_FLAG;
6107   if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6108     *f++ = 'G';
6109   *f = '\0';
6110
6111   fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
6112
6113   if (!(flags & SECTION_NOTYPE))
6114     {
6115       const char *type;
6116       const char *format;
6117
6118       if (flags & SECTION_BSS)
6119         type = "nobits";
6120       else
6121         type = "progbits";
6122
6123       format = ",@%s";
6124 #ifdef ASM_COMMENT_START
6125       /* On platforms that use "@" as the assembly comment character,
6126          use "%" instead.  */
6127       if (strcmp (ASM_COMMENT_START, "@") == 0)
6128         format = ",%%%s";
6129 #endif
6130       fprintf (asm_out_file, format, type);
6131
6132       if (flags & SECTION_ENTSIZE)
6133         fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
6134       if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6135         {
6136           if (TREE_CODE (decl) == IDENTIFIER_NODE)
6137             fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
6138           else
6139             fprintf (asm_out_file, ",%s,comdat",
6140                      IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
6141         }
6142     }
6143
6144   putc ('\n', asm_out_file);
6145 }
6146
6147 void
6148 default_coff_asm_named_section (const char *name, unsigned int flags,
6149                                 tree decl ATTRIBUTE_UNUSED)
6150 {
6151   char flagchars[8], *f = flagchars;
6152
6153   if (flags & SECTION_WRITE)
6154     *f++ = 'w';
6155   if (flags & SECTION_CODE)
6156     *f++ = 'x';
6157   *f = '\0';
6158
6159   fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
6160 }
6161
6162 void
6163 default_pe_asm_named_section (const char *name, unsigned int flags,
6164                               tree decl)
6165 {
6166   default_coff_asm_named_section (name, flags, decl);
6167
6168   if (flags & SECTION_LINKONCE)
6169     {
6170       /* Functions may have been compiled at various levels of
6171          optimization so we can't use `same_size' here.
6172          Instead, have the linker pick one.  */
6173       fprintf (asm_out_file, "\t.linkonce %s\n",
6174                (flags & SECTION_CODE ? "discard" : "same_size"));
6175     }
6176 }
6177 \f
6178 /* The lame default section selector.  */
6179
6180 section *
6181 default_select_section (tree decl, int reloc,
6182                         unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6183 {
6184   if (DECL_P (decl))
6185     {
6186       if (decl_readonly_section (decl, reloc))
6187         return readonly_data_section;
6188     }
6189   else if (TREE_CODE (decl) == CONSTRUCTOR)
6190     {
6191       if (! ((flag_pic && reloc)
6192              || !TREE_READONLY (decl)
6193              || TREE_SIDE_EFFECTS (decl)
6194              || !TREE_CONSTANT (decl)))
6195         return readonly_data_section;
6196     }
6197   else if (TREE_CODE (decl) == STRING_CST)
6198     return readonly_data_section;
6199   else if (! (flag_pic && reloc))
6200     return readonly_data_section;
6201
6202   return data_section;
6203 }
6204
6205 enum section_category
6206 categorize_decl_for_section (const_tree decl, int reloc)
6207 {
6208   enum section_category ret;
6209
6210   if (TREE_CODE (decl) == FUNCTION_DECL)
6211     return SECCAT_TEXT;
6212   else if (TREE_CODE (decl) == STRING_CST)
6213     {
6214       if (flag_mudflap) /* or !flag_merge_constants */
6215         return SECCAT_RODATA;
6216       else
6217         return SECCAT_RODATA_MERGE_STR;
6218     }
6219   else if (TREE_CODE (decl) == VAR_DECL)
6220     {
6221       if (bss_initializer_p (decl))
6222         ret = SECCAT_BSS;
6223       else if (! TREE_READONLY (decl)
6224                || TREE_SIDE_EFFECTS (decl)
6225                || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6226         {
6227           /* Here the reloc_rw_mask is not testing whether the section should
6228              be read-only or not, but whether the dynamic link will have to
6229              do something.  If so, we wish to segregate the data in order to
6230              minimize cache misses inside the dynamic linker.  */
6231           if (reloc & targetm.asm_out.reloc_rw_mask ())
6232             ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6233           else
6234             ret = SECCAT_DATA;
6235         }
6236       else if (reloc & targetm.asm_out.reloc_rw_mask ())
6237         ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6238       else if (reloc || flag_merge_constants < 2)
6239         /* C and C++ don't allow different variables to share the same
6240            location.  -fmerge-all-constants allows even that (at the
6241            expense of not conforming).  */
6242         ret = SECCAT_RODATA;
6243       else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6244         ret = SECCAT_RODATA_MERGE_STR_INIT;
6245       else
6246         ret = SECCAT_RODATA_MERGE_CONST;
6247     }
6248   else if (TREE_CODE (decl) == CONSTRUCTOR)
6249     {
6250       if ((reloc & targetm.asm_out.reloc_rw_mask ())
6251           || TREE_SIDE_EFFECTS (decl)
6252           || ! TREE_CONSTANT (decl))
6253         ret = SECCAT_DATA;
6254       else
6255         ret = SECCAT_RODATA;
6256     }
6257   else
6258     ret = SECCAT_RODATA;
6259
6260   /* There are no read-only thread-local sections.  */
6261   if (TREE_CODE (decl) == VAR_DECL && DECL_TLS_MODEL (decl))
6262     {
6263       if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED)
6264         {
6265           if (DECL_EMUTLS_VAR_P (decl))
6266             {
6267               if (targetm.emutls.var_section)
6268                 ret = SECCAT_EMUTLS_VAR;
6269             }
6270           else
6271             {
6272               if (targetm.emutls.tmpl_prefix)
6273                 ret = SECCAT_EMUTLS_TMPL;
6274             }
6275         }
6276       /* Note that this would be *just* SECCAT_BSS, except that there's
6277          no concept of a read-only thread-local-data section.  */
6278       else if (ret == SECCAT_BSS
6279                || (flag_zero_initialized_in_bss
6280                    && initializer_zerop (DECL_INITIAL (decl))))
6281         ret = SECCAT_TBSS;
6282       else
6283         ret = SECCAT_TDATA;
6284     }
6285
6286   /* If the target uses small data sections, select it.  */
6287   else if (targetm.in_small_data_p (decl))
6288     {
6289       if (ret == SECCAT_BSS)
6290         ret = SECCAT_SBSS;
6291       else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6292         ret = SECCAT_SRODATA;
6293       else
6294         ret = SECCAT_SDATA;
6295     }
6296
6297   return ret;
6298 }
6299
6300 bool
6301 decl_readonly_section (const_tree decl, int reloc)
6302 {
6303   switch (categorize_decl_for_section (decl, reloc))
6304     {
6305     case SECCAT_RODATA:
6306     case SECCAT_RODATA_MERGE_STR:
6307     case SECCAT_RODATA_MERGE_STR_INIT:
6308     case SECCAT_RODATA_MERGE_CONST:
6309     case SECCAT_SRODATA:
6310       return true;
6311       break;
6312     default:
6313       return false;
6314       break;
6315     }
6316 }
6317
6318 /* Select a section based on the above categorization.  */
6319
6320 section *
6321 default_elf_select_section (tree decl, int reloc,
6322                             unsigned HOST_WIDE_INT align)
6323 {
6324   const char *sname;
6325   switch (categorize_decl_for_section (decl, reloc))
6326     {
6327     case SECCAT_TEXT:
6328       /* We're not supposed to be called on FUNCTION_DECLs.  */
6329       gcc_unreachable ();
6330     case SECCAT_RODATA:
6331       return readonly_data_section;
6332     case SECCAT_RODATA_MERGE_STR:
6333       return mergeable_string_section (decl, align, 0);
6334     case SECCAT_RODATA_MERGE_STR_INIT:
6335       return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6336     case SECCAT_RODATA_MERGE_CONST:
6337       return mergeable_constant_section (DECL_MODE (decl), align, 0);
6338     case SECCAT_SRODATA:
6339       sname = ".sdata2";
6340       break;
6341     case SECCAT_DATA:
6342       return data_section;
6343     case SECCAT_DATA_REL:
6344       sname = ".data.rel";
6345       break;
6346     case SECCAT_DATA_REL_LOCAL:
6347       sname = ".data.rel.local";
6348       break;
6349     case SECCAT_DATA_REL_RO:
6350       sname = ".data.rel.ro";
6351       break;
6352     case SECCAT_DATA_REL_RO_LOCAL:
6353       sname = ".data.rel.ro.local";
6354       break;
6355     case SECCAT_SDATA:
6356       sname = ".sdata";
6357       break;
6358     case SECCAT_TDATA:
6359       sname = ".tdata";
6360       break;
6361     case SECCAT_BSS:
6362       if (bss_section)
6363         return bss_section;
6364       sname = ".bss";
6365       break;
6366     case SECCAT_SBSS:
6367       sname = ".sbss";
6368       break;
6369     case SECCAT_TBSS:
6370       sname = ".tbss";
6371       break;
6372     case SECCAT_EMUTLS_VAR:
6373       sname = targetm.emutls.var_section;
6374       break;
6375     case SECCAT_EMUTLS_TMPL:
6376       sname = targetm.emutls.tmpl_section;
6377       break;
6378     default:
6379       gcc_unreachable ();
6380     }
6381
6382   if (!DECL_P (decl))
6383     decl = NULL_TREE;
6384   return get_named_section (decl, sname, reloc);
6385 }
6386
6387 /* Construct a unique section name based on the decl name and the
6388    categorization performed above.  */
6389
6390 void
6391 default_unique_section (tree decl, int reloc)
6392 {
6393   /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
6394   bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6395   const char *prefix, *name, *linkonce;
6396   char *string;
6397
6398   switch (categorize_decl_for_section (decl, reloc))
6399     {
6400     case SECCAT_TEXT:
6401       prefix = one_only ? ".t" : ".text";
6402       break;
6403     case SECCAT_RODATA:
6404     case SECCAT_RODATA_MERGE_STR:
6405     case SECCAT_RODATA_MERGE_STR_INIT:
6406     case SECCAT_RODATA_MERGE_CONST:
6407       prefix = one_only ? ".r" : ".rodata";
6408       break;
6409     case SECCAT_SRODATA:
6410       prefix = one_only ? ".s2" : ".sdata2";
6411       break;
6412     case SECCAT_DATA:
6413       prefix = one_only ? ".d" : ".data";
6414       break;
6415     case SECCAT_DATA_REL:
6416       prefix = one_only ? ".d.rel" : ".data.rel";
6417       break;
6418     case SECCAT_DATA_REL_LOCAL:
6419       prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6420       break;
6421     case SECCAT_DATA_REL_RO:
6422       prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6423       break;
6424     case SECCAT_DATA_REL_RO_LOCAL:
6425       prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6426       break;
6427     case SECCAT_SDATA:
6428       prefix = one_only ? ".s" : ".sdata";
6429       break;
6430     case SECCAT_BSS:
6431       prefix = one_only ? ".b" : ".bss";
6432       break;
6433     case SECCAT_SBSS:
6434       prefix = one_only ? ".sb" : ".sbss";
6435       break;
6436     case SECCAT_TDATA:
6437       prefix = one_only ? ".td" : ".tdata";
6438       break;
6439     case SECCAT_TBSS:
6440       prefix = one_only ? ".tb" : ".tbss";
6441       break;
6442     case SECCAT_EMUTLS_VAR:
6443       prefix = targetm.emutls.var_section;
6444       break;
6445     case SECCAT_EMUTLS_TMPL:
6446       prefix = targetm.emutls.tmpl_section;
6447       break;
6448     default:
6449       gcc_unreachable ();
6450     }
6451
6452   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6453   name = targetm.strip_name_encoding (name);
6454
6455   /* If we're using one_only, then there needs to be a .gnu.linkonce
6456      prefix to the section name.  */
6457   linkonce = one_only ? ".gnu.linkonce" : "";
6458
6459   string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6460
6461   DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6462 }
6463
6464 /* Like compute_reloc_for_constant, except for an RTX.  The return value
6465    is a mask for which bit 1 indicates a global relocation, and bit 0
6466    indicates a local relocation.  */
6467
6468 static int
6469 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6470 {
6471   int *preloc = (int *) data;
6472   rtx x = *xp;
6473
6474   switch (GET_CODE (x))
6475     {
6476     case SYMBOL_REF:
6477       *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6478       break;
6479     case LABEL_REF:
6480       *preloc |= 1;
6481       break;
6482     default:
6483       break;
6484     }
6485
6486   return 0;
6487 }
6488
6489 static int
6490 compute_reloc_for_rtx (rtx x)
6491 {
6492   int reloc;
6493
6494   switch (GET_CODE (x))
6495     {
6496     case CONST:
6497     case SYMBOL_REF:
6498     case LABEL_REF:
6499       reloc = 0;
6500       for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6501       return reloc;
6502
6503     default:
6504       return 0;
6505     }
6506 }
6507
6508 section *
6509 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6510                             rtx x,
6511                             unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6512 {
6513   if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6514     return data_section;
6515   else
6516     return readonly_data_section;
6517 }
6518
6519 section *
6520 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6521                                 unsigned HOST_WIDE_INT align)
6522 {
6523   int reloc = compute_reloc_for_rtx (x);
6524
6525   /* ??? Handle small data here somehow.  */
6526
6527   if (reloc & targetm.asm_out.reloc_rw_mask ())
6528     {
6529       if (reloc == 1)
6530         return get_named_section (NULL, ".data.rel.ro.local", 1);
6531       else
6532         return get_named_section (NULL, ".data.rel.ro", 3);
6533     }
6534
6535   return mergeable_constant_section (mode, align, 0);
6536 }
6537
6538 /* Set the generally applicable flags on the SYMBOL_REF for EXP.  */
6539
6540 void
6541 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6542 {
6543   rtx symbol;
6544   int flags;
6545
6546   /* Careful not to prod global register variables.  */
6547   if (!MEM_P (rtl))
6548     return;
6549   symbol = XEXP (rtl, 0);
6550   if (GET_CODE (symbol) != SYMBOL_REF)
6551     return;
6552
6553   flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6554   if (TREE_CODE (decl) == FUNCTION_DECL)
6555     flags |= SYMBOL_FLAG_FUNCTION;
6556   if (targetm.binds_local_p (decl))
6557     flags |= SYMBOL_FLAG_LOCAL;
6558   if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)
6559       && DECL_TLS_MODEL (decl) != TLS_MODEL_EMULATED)
6560     flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6561   else if (targetm.in_small_data_p (decl))
6562     flags |= SYMBOL_FLAG_SMALL;
6563   /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names?  Without
6564      being PUBLIC, the thing *must* be defined in this translation unit.
6565      Prevent this buglet from being propagated into rtl code as well.  */
6566   if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6567     flags |= SYMBOL_FLAG_EXTERNAL;
6568
6569   SYMBOL_REF_FLAGS (symbol) = flags;
6570 }
6571
6572 /* By default, we do nothing for encode_section_info, so we need not
6573    do anything but discard the '*' marker.  */
6574
6575 const char *
6576 default_strip_name_encoding (const char *str)
6577 {
6578   return str + (*str == '*');
6579 }
6580
6581 #ifdef ASM_OUTPUT_DEF
6582 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR.  Define the
6583    anchor relative to ".", the current section position.  */
6584
6585 void
6586 default_asm_output_anchor (rtx symbol)
6587 {
6588   char buffer[100];
6589
6590   sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6591            SYMBOL_REF_BLOCK_OFFSET (symbol));
6592   ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6593 }
6594 #endif
6595
6596 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P.  */
6597
6598 bool
6599 default_use_anchors_for_symbol_p (const_rtx symbol)
6600 {
6601   section *sect;
6602   tree decl;
6603
6604   /* Don't use anchors for mergeable sections.  The linker might move
6605      the objects around.  */
6606   sect = SYMBOL_REF_BLOCK (symbol)->sect;
6607   if (sect->common.flags & SECTION_MERGE)
6608     return false;
6609
6610   /* Don't use anchors for small data sections.  The small data register
6611      acts as an anchor for such sections.  */
6612   if (sect->common.flags & SECTION_SMALL)
6613     return false;
6614
6615   decl = SYMBOL_REF_DECL (symbol);
6616   if (decl && DECL_P (decl))
6617     {
6618       /* Don't use section anchors for decls that might be defined by
6619          other modules.  */
6620       if (!targetm.binds_local_p (decl))
6621         return false;
6622
6623       /* Don't use section anchors for decls that will be placed in a
6624          small data section.  */
6625       /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6626          one above.  The problem is that we only use SECTION_SMALL for
6627          sections that should be marked as small in the section directive.  */
6628       if (targetm.in_small_data_p (decl))
6629         return false;
6630     }
6631   return true;
6632 }
6633
6634 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6635    wrt cross-module name binding.  */
6636
6637 bool
6638 default_binds_local_p (const_tree exp)
6639 {
6640   return default_binds_local_p_1 (exp, flag_shlib);
6641 }
6642
6643 bool
6644 default_binds_local_p_1 (const_tree exp, int shlib)
6645 {
6646   bool local_p;
6647
6648   /* A non-decl is an entry in the constant pool.  */
6649   if (!DECL_P (exp))
6650     local_p = true;
6651   /* Weakrefs may not bind locally, even though the weakref itself is
6652      always static and therefore local.  */
6653   else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6654     local_p = false;
6655   /* Static variables are always local.  */
6656   else if (! TREE_PUBLIC (exp))
6657     local_p = true;
6658   /* A variable is local if the user has said explicitly that it will
6659      be.  */
6660   else if (DECL_VISIBILITY_SPECIFIED (exp)
6661            && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6662     local_p = true;
6663   /* Variables defined outside this object might not be local.  */
6664   else if (DECL_EXTERNAL (exp))
6665     local_p = false;
6666   /* If defined in this object and visibility is not default, must be
6667      local.  */
6668   else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6669     local_p = true;
6670   /* Default visibility weak data can be overridden by a strong symbol
6671      in another module and so are not local.  */
6672   else if (DECL_WEAK (exp))
6673     local_p = false;
6674   /* If PIC, then assume that any global name can be overridden by
6675      symbols resolved from other modules, unless we are compiling with
6676      -fwhole-program, which assumes that names are local.  */
6677   else if (shlib)
6678     local_p = flag_whole_program;
6679   /* Uninitialized COMMON variable may be unified with symbols
6680      resolved from other modules.  */
6681   else if (DECL_COMMON (exp)
6682            && (DECL_INITIAL (exp) == NULL
6683                || DECL_INITIAL (exp) == error_mark_node))
6684     local_p = false;
6685   /* Otherwise we're left with initialized (or non-common) global data
6686      which is of necessity defined locally.  */
6687   else
6688     local_p = true;
6689
6690   return local_p;
6691 }
6692
6693 /* Default function to output code that will globalize a label.  A
6694    target must define GLOBAL_ASM_OP or provide its own function to
6695    globalize a label.  */
6696 #ifdef GLOBAL_ASM_OP
6697 void
6698 default_globalize_label (FILE * stream, const char *name)
6699 {
6700   fputs (GLOBAL_ASM_OP, stream);
6701   assemble_name (stream, name);
6702   putc ('\n', stream);
6703 }
6704 #endif /* GLOBAL_ASM_OP */
6705
6706 /* Default function to output code that will globalize a declaration.  */
6707 void
6708 default_globalize_decl_name (FILE * stream, tree decl)
6709 {
6710   const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6711   targetm.asm_out.globalize_label (stream, name);
6712 }
6713
6714 /* Default function to output a label for unwind information.  The
6715    default is to do nothing.  A target that needs nonlocal labels for
6716    unwind information must provide its own function to do this.  */
6717 void
6718 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6719                            tree decl ATTRIBUTE_UNUSED,
6720                            int for_eh ATTRIBUTE_UNUSED,
6721                            int empty ATTRIBUTE_UNUSED)
6722 {
6723 }
6724
6725 /* Default function to output a label to divide up the exception table.
6726    The default is to do nothing.  A target that needs/wants to divide
6727    up the table must provide it's own function to do this.  */
6728 void
6729 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6730 {
6731 }
6732
6733 /* This is how to output an internal numbered label where PREFIX is
6734    the class of label and LABELNO is the number within the class.  */
6735
6736 void
6737 default_internal_label (FILE *stream, const char *prefix,
6738                         unsigned long labelno)
6739 {
6740   char *const buf = (char *) alloca (40 + strlen (prefix));
6741   ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6742   ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6743 }
6744
6745 /* This is the default behavior at the beginning of a file.  It's
6746    controlled by two other target-hook toggles.  */
6747 void
6748 default_file_start (void)
6749 {
6750   if (targetm.file_start_app_off
6751       && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
6752     fputs (ASM_APP_OFF, asm_out_file);
6753
6754   if (targetm.file_start_file_directive)
6755     output_file_directive (asm_out_file, main_input_filename);
6756 }
6757
6758 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6759    which emits a special section directive used to indicate whether or
6760    not this object file needs an executable stack.  This is primarily
6761    a GNU extension to ELF but could be used on other targets.  */
6762
6763 int trampolines_created;
6764
6765 void
6766 file_end_indicate_exec_stack (void)
6767 {
6768   unsigned int flags = SECTION_DEBUG;
6769   if (trampolines_created)
6770     flags |= SECTION_CODE;
6771
6772   switch_to_section (get_section (".note.GNU-stack", flags, NULL));
6773 }
6774
6775 /* Output DIRECTIVE (a C string) followed by a newline.  This is used as
6776    a get_unnamed_section callback.  */
6777
6778 void
6779 output_section_asm_op (const void *directive)
6780 {
6781   fprintf (asm_out_file, "%s\n", (const char *) directive);
6782 }
6783
6784 /* Emit assembly code to switch to section NEW_SECTION.  Do nothing if
6785    the current section is NEW_SECTION.  */
6786
6787 void
6788 switch_to_section (section *new_section)
6789 {
6790   if (in_section == new_section)
6791     return;
6792
6793   if (new_section->common.flags & SECTION_FORGET)
6794     in_section = NULL;
6795   else
6796     in_section = new_section;
6797
6798   switch (SECTION_STYLE (new_section))
6799     {
6800     case SECTION_NAMED:
6801       if (cfun
6802           && !crtl->subsections.unlikely_text_section_name
6803           && strcmp (new_section->named.name,
6804                      UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6805         crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6806
6807       targetm.asm_out.named_section (new_section->named.name,
6808                                      new_section->named.common.flags,
6809                                      new_section->named.decl);
6810       break;
6811
6812     case SECTION_UNNAMED:
6813       new_section->unnamed.callback (new_section->unnamed.data);
6814       break;
6815
6816     case SECTION_NOSWITCH:
6817       gcc_unreachable ();
6818       break;
6819     }
6820
6821   new_section->common.flags |= SECTION_DECLARED;
6822 }
6823
6824 /* If block symbol SYMBOL has not yet been assigned an offset, place
6825    it at the end of its block.  */
6826
6827 void
6828 place_block_symbol (rtx symbol)
6829 {
6830   unsigned HOST_WIDE_INT size, mask, offset;
6831   struct constant_descriptor_rtx *desc;
6832   unsigned int alignment;
6833   struct object_block *block;
6834   tree decl;
6835
6836   gcc_assert (SYMBOL_REF_BLOCK (symbol));
6837   if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6838     return;
6839
6840   /* Work out the symbol's size and alignment.  */
6841   if (CONSTANT_POOL_ADDRESS_P (symbol))
6842     {
6843       desc = SYMBOL_REF_CONSTANT (symbol);
6844       alignment = desc->align;
6845       size = GET_MODE_SIZE (desc->mode);
6846     }
6847   else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6848     {
6849       decl = SYMBOL_REF_DECL (symbol);
6850       alignment = get_constant_alignment (decl);
6851       size = get_constant_size (decl);
6852     }
6853   else
6854     {
6855       decl = SYMBOL_REF_DECL (symbol);
6856       alignment = DECL_ALIGN (decl);
6857       size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6858     }
6859
6860   /* Calculate the object's offset from the start of the block.  */
6861   block = SYMBOL_REF_BLOCK (symbol);
6862   mask = alignment / BITS_PER_UNIT - 1;
6863   offset = (block->size + mask) & ~mask;
6864   SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
6865
6866   /* Record the block's new alignment and size.  */
6867   block->alignment = MAX (block->alignment, alignment);
6868   block->size = offset + size;
6869
6870   VEC_safe_push (rtx, gc, block->objects, symbol);
6871 }
6872
6873 /* Return the anchor that should be used to address byte offset OFFSET
6874    from the first object in BLOCK.  MODEL is the TLS model used
6875    to access it.  */
6876
6877 rtx
6878 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
6879                     enum tls_model model)
6880 {
6881   char label[100];
6882   unsigned int begin, middle, end;
6883   unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
6884   rtx anchor;
6885
6886   /* Work out the anchor's offset.  Use an offset of 0 for the first
6887      anchor so that we don't pessimize the case where we take the address
6888      of a variable at the beginning of the block.  This is particularly
6889      useful when a block has only one variable assigned to it.
6890
6891      We try to place anchors RANGE bytes apart, so there can then be
6892      anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6893      a ptr_mode offset.  With some target settings, the lowest such
6894      anchor might be out of range for the lowest ptr_mode offset;
6895      likewise the highest anchor for the highest offset.  Use anchors
6896      at the extreme ends of the ptr_mode range in such cases.
6897
6898      All arithmetic uses unsigned integers in order to avoid
6899      signed overflow.  */
6900   max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
6901   min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
6902   range = max_offset - min_offset + 1;
6903   if (range == 0)
6904     offset = 0;
6905   else
6906     {
6907       bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
6908       if (offset < 0)
6909         {
6910           delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
6911           delta -= delta % range;
6912           if (delta > bias)
6913             delta = bias;
6914           offset = (HOST_WIDE_INT) (-delta);
6915         }
6916       else
6917         {
6918           delta = (unsigned HOST_WIDE_INT) offset - min_offset;
6919           delta -= delta % range;
6920           if (delta > bias - 1)
6921             delta = bias - 1;
6922           offset = (HOST_WIDE_INT) delta;
6923         }
6924     }
6925
6926   /* Do a binary search to see if there's already an anchor we can use.
6927      Set BEGIN to the new anchor's index if not.  */
6928   begin = 0;
6929   end = VEC_length (rtx, block->anchors);
6930   while (begin != end)
6931     {
6932       middle = (end + begin) / 2;
6933       anchor = VEC_index (rtx, block->anchors, middle);
6934       if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
6935         end = middle;
6936       else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
6937         begin = middle + 1;
6938       else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
6939         end = middle;
6940       else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
6941         begin = middle + 1;
6942       else
6943         return anchor;
6944     }
6945
6946   /* Create a new anchor with a unique label.  */
6947   ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
6948   anchor = create_block_symbol (ggc_strdup (label), block, offset);
6949   SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
6950   SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
6951
6952   /* Insert it at index BEGIN.  */
6953   VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
6954   return anchor;
6955 }
6956
6957 /* Output the objects in BLOCK.  */
6958
6959 static void
6960 output_object_block (struct object_block *block)
6961 {
6962   struct constant_descriptor_rtx *desc;
6963   unsigned int i;
6964   HOST_WIDE_INT offset;
6965   tree decl;
6966   rtx symbol;
6967
6968   if (block->objects == NULL)
6969     return;
6970
6971   /* Switch to the section and make sure that the first byte is
6972      suitably aligned.  */
6973   switch_to_section (block->sect);
6974   assemble_align (block->alignment);
6975
6976   /* Define the values of all anchors relative to the current section
6977      position.  */
6978   for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
6979     targetm.asm_out.output_anchor (symbol);
6980
6981   /* Output the objects themselves.  */
6982   offset = 0;
6983   for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
6984     {
6985       /* Move to the object's offset, padding with zeros if necessary.  */
6986       assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
6987       offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
6988       if (CONSTANT_POOL_ADDRESS_P (symbol))
6989         {
6990           desc = SYMBOL_REF_CONSTANT (symbol);
6991           output_constant_pool_1 (desc, 1);
6992           offset += GET_MODE_SIZE (desc->mode);
6993         }
6994       else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6995         {
6996           decl = SYMBOL_REF_DECL (symbol);
6997           assemble_constant_contents (decl, XSTR (symbol, 0),
6998                                       get_constant_alignment (decl));
6999           offset += get_constant_size (decl);
7000         }
7001       else
7002         {
7003           decl = SYMBOL_REF_DECL (symbol);
7004           assemble_variable_contents (decl, XSTR (symbol, 0), false);
7005           offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7006         }
7007     }
7008 }
7009
7010 /* A htab_traverse callback used to call output_object_block for
7011    each member of object_block_htab.  */
7012
7013 static int
7014 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
7015 {
7016   output_object_block ((struct object_block *) (*slot));
7017   return 1;
7018 }
7019
7020 /* Output the definitions of all object_blocks.  */
7021
7022 void
7023 output_object_blocks (void)
7024 {
7025   htab_traverse (object_block_htab, output_object_block_htab, NULL);
7026 }
7027
7028 /* This function provides a possible implementation of the
7029    TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets.  When triggered
7030    by -frecord-gcc-switches it creates a new mergeable, string section in the
7031    assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7032    contains the switches in ASCII format.
7033
7034    FIXME: This code does not correctly handle double quote characters
7035    that appear inside strings, (it strips them rather than preserving them).
7036    FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7037    characters - instead it treats them as sub-string separators.  Since
7038    we want to emit NUL strings terminators into the object file we have to use
7039    ASM_OUTPUT_SKIP.  */
7040
7041 int
7042 elf_record_gcc_switches (print_switch_type type, const char * name)
7043 {
7044   static char buffer[1024];
7045
7046   /* This variable is used as part of a simplistic heuristic to detect
7047      command line switches which take an argument:
7048
7049        "If a command line option does not start with a dash then
7050         it is an argument for the previous command line option."
7051
7052      This fails in the case of the command line option which is the name
7053      of the file to compile, but otherwise it is pretty reasonable.  */
7054   static bool previous_name_held_back = FALSE;
7055
7056   switch (type)
7057     {
7058     case SWITCH_TYPE_PASSED:
7059       if (* name != '-')
7060         {
7061           if (previous_name_held_back)
7062             {
7063               unsigned int len = strlen (buffer);
7064
7065               snprintf (buffer + len, sizeof buffer - len, " %s", name);
7066               ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7067               ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7068               previous_name_held_back = FALSE;
7069             }
7070           else
7071             {
7072               strncpy (buffer, name, sizeof buffer);
7073               ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7074               ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7075             }
7076         }
7077       else
7078         {
7079           if (previous_name_held_back)
7080             {
7081               ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7082               ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7083             }
7084
7085           strncpy (buffer, name, sizeof buffer);
7086           previous_name_held_back = TRUE;
7087         }
7088       break;
7089
7090     case SWITCH_TYPE_DESCRIPTIVE:
7091       if (name == NULL)
7092         {
7093           /* Distinguish between invocations where name is NULL.  */
7094           static bool started = false;
7095
7096           if (started)
7097             {
7098               if (previous_name_held_back)
7099                 {
7100                   ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7101                   ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7102                 }
7103             }
7104           else
7105             {
7106               section * sec;
7107
7108               sec = get_section (targetm.asm_out.record_gcc_switches_section,
7109                                  SECTION_DEBUG
7110                                  | SECTION_MERGE
7111                                  | SECTION_STRINGS
7112                                  | (SECTION_ENTSIZE & 1),
7113                                  NULL);
7114               switch_to_section (sec);
7115               started = true;
7116             }
7117         }
7118
7119     default:
7120       break;
7121     }
7122
7123   /* The return value is currently ignored by the caller, but must be 0.
7124      For -fverbose-asm the return value would be the number of characters
7125      emitted into the assembler file.  */
7126   return 0;
7127 }
7128
7129 /* Emit text to declare externally defined symbols. It is needed to
7130    properly support non-default visibility.  */
7131 void
7132 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
7133                                  tree decl,
7134                                  const char *name ATTRIBUTE_UNUSED)
7135 {
7136   /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7137      set in order to avoid putting out names that are never really
7138      used. */
7139   if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
7140       && targetm.binds_local_p (decl))
7141     maybe_assemble_visibility (decl);
7142 }
7143
7144 #include "gt-varasm.h"