OSDN Git Service

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