OSDN Git Service

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