OSDN Git Service

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