OSDN Git Service

PR c/29091
[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             thissize = elt_size;
4407             while ((link = TREE_CHAIN (link)) != NULL)
4408               {
4409                 output_constant (TREE_VALUE (link), elt_size, nalign);
4410                 thissize += elt_size;
4411               }
4412             break;
4413           }
4414         default:
4415           gcc_unreachable ();
4416         }
4417       break;
4418
4419     case RECORD_TYPE:
4420     case UNION_TYPE:
4421       gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4422       output_constructor (exp, size, align);
4423       return;
4424
4425     case ERROR_MARK:
4426       return;
4427
4428     default:
4429       gcc_unreachable ();
4430     }
4431
4432   if (size > thissize)
4433     assemble_zeros (size - thissize);
4434 }
4435
4436 \f
4437 /* Subroutine of output_constructor, used for computing the size of
4438    arrays of unspecified length.  VAL must be a CONSTRUCTOR of an array
4439    type with an unspecified upper bound.  */
4440
4441 static unsigned HOST_WIDE_INT
4442 array_size_for_constructor (tree val)
4443 {
4444   tree max_index, i;
4445   unsigned HOST_WIDE_INT cnt;
4446   tree index, value, tmp;
4447
4448   /* This code used to attempt to handle string constants that are not
4449      arrays of single-bytes, but nothing else does, so there's no point in
4450      doing it here.  */
4451   if (TREE_CODE (val) == STRING_CST)
4452     return TREE_STRING_LENGTH (val);
4453
4454   max_index = NULL_TREE;
4455   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4456     {
4457       if (TREE_CODE (index) == RANGE_EXPR)
4458         index = TREE_OPERAND (index, 1);
4459       if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4460         max_index = index;
4461     }
4462
4463   if (max_index == NULL_TREE)
4464     return 0;
4465
4466   /* Compute the total number of array elements.  */
4467   tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4468   i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4469                   fold_convert (sizetype, tmp));
4470   i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4471
4472   /* Multiply by the array element unit size to find number of bytes.  */
4473   i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4474
4475   return tree_low_cst (i, 1);
4476 }
4477
4478 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4479    Generate at least SIZE bytes, padding if necessary.  */
4480
4481 static void
4482 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
4483                     unsigned int align)
4484 {
4485   tree type = TREE_TYPE (exp);
4486   tree field = 0;
4487   tree min_index = 0;
4488   /* Number of bytes output or skipped so far.
4489      In other words, current position within the constructor.  */
4490   HOST_WIDE_INT total_bytes = 0;
4491   /* Nonzero means BYTE contains part of a byte, to be output.  */
4492   int byte_buffer_in_use = 0;
4493   int byte = 0;
4494   unsigned HOST_WIDE_INT cnt;
4495   constructor_elt *ce;
4496
4497   gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
4498
4499   if (TREE_CODE (type) == RECORD_TYPE)
4500     field = TYPE_FIELDS (type);
4501
4502   if (TREE_CODE (type) == ARRAY_TYPE
4503       && TYPE_DOMAIN (type) != 0)
4504     min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4505
4506   /* As LINK goes through the elements of the constant,
4507      FIELD goes through the structure fields, if the constant is a structure.
4508      if the constant is a union, then we override this,
4509      by getting the field from the TREE_LIST element.
4510      But the constant could also be an array.  Then FIELD is zero.
4511
4512      There is always a maximum of one element in the chain LINK for unions
4513      (even if the initializer in a source program incorrectly contains
4514      more one).  */
4515   for (cnt = 0;
4516        VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
4517        cnt++, field = field ? TREE_CHAIN (field) : 0)
4518     {
4519       tree val = ce->value;
4520       tree index = 0;
4521
4522       /* The element in a union constructor specifies the proper field
4523          or index.  */
4524       if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4525            || TREE_CODE (type) == QUAL_UNION_TYPE)
4526           && ce->index != 0)
4527         field = ce->index;
4528
4529       else if (TREE_CODE (type) == ARRAY_TYPE)
4530         index = ce->index;
4531
4532 #ifdef ASM_COMMENT_START
4533       if (field && flag_verbose_asm)
4534         fprintf (asm_out_file, "%s %s:\n",
4535                  ASM_COMMENT_START,
4536                  DECL_NAME (field)
4537                  ? IDENTIFIER_POINTER (DECL_NAME (field))
4538                  : "<anonymous>");
4539 #endif
4540
4541       /* Eliminate the marker that makes a cast not be an lvalue.  */
4542       if (val != 0)
4543         STRIP_NOPS (val);
4544
4545       if (index && TREE_CODE (index) == RANGE_EXPR)
4546         {
4547           unsigned HOST_WIDE_INT fieldsize
4548             = int_size_in_bytes (TREE_TYPE (type));
4549           HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4550           HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4551           HOST_WIDE_INT index;
4552           unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4553
4554           for (index = lo_index; index <= hi_index; index++)
4555             {
4556               /* Output the element's initial value.  */
4557               if (val == 0)
4558                 assemble_zeros (fieldsize);
4559               else
4560                 output_constant (val, fieldsize, align2);
4561
4562               /* Count its size.  */
4563               total_bytes += fieldsize;
4564             }
4565         }
4566       else if (field == 0 || !DECL_BIT_FIELD (field))
4567         {
4568           /* An element that is not a bit-field.  */
4569
4570           unsigned HOST_WIDE_INT fieldsize;
4571           /* Since this structure is static,
4572              we know the positions are constant.  */
4573           HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4574           unsigned int align2;
4575
4576           if (index != 0)
4577             pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4578                    * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4579
4580           /* Output any buffered-up bit-fields preceding this element.  */
4581           if (byte_buffer_in_use)
4582             {
4583               assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4584               total_bytes++;
4585               byte_buffer_in_use = 0;
4586             }
4587
4588           /* Advance to offset of this element.
4589              Note no alignment needed in an array, since that is guaranteed
4590              if each element has the proper size.  */
4591           if ((field != 0 || index != 0) && pos != total_bytes)
4592             {
4593               gcc_assert (pos >= total_bytes);
4594               assemble_zeros (pos - total_bytes);
4595               total_bytes = pos;
4596             }
4597
4598           /* Find the alignment of this element.  */
4599           align2 = min_align (align, BITS_PER_UNIT * pos);
4600
4601           /* Determine size this element should occupy.  */
4602           if (field)
4603             {
4604               fieldsize = 0;
4605
4606               /* If this is an array with an unspecified upper bound,
4607                  the initializer determines the size.  */
4608               /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4609                  but we cannot do this until the deprecated support for
4610                  initializing zero-length array members is removed.  */
4611               if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4612                   && TYPE_DOMAIN (TREE_TYPE (field))
4613                   && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4614                 {
4615                   fieldsize = array_size_for_constructor (val);
4616                   /* Given a non-empty initialization, this field had
4617                      better be last.  */
4618                   gcc_assert (!fieldsize || !TREE_CHAIN (field));
4619                 }
4620               else if (DECL_SIZE_UNIT (field))
4621                 {
4622                   /* ??? This can't be right.  If the decl size overflows
4623                      a host integer we will silently emit no data.  */
4624                   if (host_integerp (DECL_SIZE_UNIT (field), 1))
4625                     fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4626                 }
4627             }
4628           else
4629             fieldsize = int_size_in_bytes (TREE_TYPE (type));
4630
4631           /* Output the element's initial value.  */
4632           if (val == 0)
4633             assemble_zeros (fieldsize);
4634           else
4635             output_constant (val, fieldsize, align2);
4636
4637           /* Count its size.  */
4638           total_bytes += fieldsize;
4639         }
4640       else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4641         error ("invalid initial value for member %qs",
4642                IDENTIFIER_POINTER (DECL_NAME (field)));
4643       else
4644         {
4645           /* Element that is a bit-field.  */
4646
4647           HOST_WIDE_INT next_offset = int_bit_position (field);
4648           HOST_WIDE_INT end_offset
4649             = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4650
4651           if (val == 0)
4652             val = integer_zero_node;
4653
4654           /* If this field does not start in this (or, next) byte,
4655              skip some bytes.  */
4656           if (next_offset / BITS_PER_UNIT != total_bytes)
4657             {
4658               /* Output remnant of any bit field in previous bytes.  */
4659               if (byte_buffer_in_use)
4660                 {
4661                   assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4662                   total_bytes++;
4663                   byte_buffer_in_use = 0;
4664                 }
4665
4666               /* If still not at proper byte, advance to there.  */
4667               if (next_offset / BITS_PER_UNIT != total_bytes)
4668                 {
4669                   gcc_assert (next_offset / BITS_PER_UNIT >= total_bytes);
4670                   assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4671                   total_bytes = next_offset / BITS_PER_UNIT;
4672                 }
4673             }
4674
4675           if (! byte_buffer_in_use)
4676             byte = 0;
4677
4678           /* We must split the element into pieces that fall within
4679              separate bytes, and combine each byte with previous or
4680              following bit-fields.  */
4681
4682           /* next_offset is the offset n fbits from the beginning of
4683              the structure to the next bit of this element to be processed.
4684              end_offset is the offset of the first bit past the end of
4685              this element.  */
4686           while (next_offset < end_offset)
4687             {
4688               int this_time;
4689               int shift;
4690               HOST_WIDE_INT value;
4691               HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4692               HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4693
4694               /* Advance from byte to byte
4695                  within this element when necessary.  */
4696               while (next_byte != total_bytes)
4697                 {
4698                   assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4699                   total_bytes++;
4700                   byte = 0;
4701                 }
4702
4703               /* Number of bits we can process at once
4704                  (all part of the same byte).  */
4705               this_time = MIN (end_offset - next_offset,
4706                                BITS_PER_UNIT - next_bit);
4707               if (BYTES_BIG_ENDIAN)
4708                 {
4709                   /* On big-endian machine, take the most significant bits
4710                      first (of the bits that are significant)
4711                      and put them into bytes from the most significant end.  */
4712                   shift = end_offset - next_offset - this_time;
4713
4714                   /* Don't try to take a bunch of bits that cross
4715                      the word boundary in the INTEGER_CST. We can
4716                      only select bits from the LOW or HIGH part
4717                      not from both.  */
4718                   if (shift < HOST_BITS_PER_WIDE_INT
4719                       && shift + this_time > HOST_BITS_PER_WIDE_INT)
4720                     {
4721                       this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4722                       shift = HOST_BITS_PER_WIDE_INT;
4723                     }
4724
4725                   /* Now get the bits from the appropriate constant word.  */
4726                   if (shift < HOST_BITS_PER_WIDE_INT)
4727                     value = TREE_INT_CST_LOW (val);
4728                   else
4729                     {
4730                       gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4731                       value = TREE_INT_CST_HIGH (val);
4732                       shift -= HOST_BITS_PER_WIDE_INT;
4733                     }
4734
4735                   /* Get the result. This works only when:
4736                      1 <= this_time <= HOST_BITS_PER_WIDE_INT.  */
4737                   byte |= (((value >> shift)
4738                             & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4739                            << (BITS_PER_UNIT - this_time - next_bit));
4740                 }
4741               else
4742                 {
4743                   /* On little-endian machines,
4744                      take first the least significant bits of the value
4745                      and pack them starting at the least significant
4746                      bits of the bytes.  */
4747                   shift = next_offset - int_bit_position (field);
4748
4749                   /* Don't try to take a bunch of bits that cross
4750                      the word boundary in the INTEGER_CST. We can
4751                      only select bits from the LOW or HIGH part
4752                      not from both.  */
4753                   if (shift < HOST_BITS_PER_WIDE_INT
4754                       && shift + this_time > HOST_BITS_PER_WIDE_INT)
4755                     this_time = (HOST_BITS_PER_WIDE_INT - shift);
4756
4757                   /* Now get the bits from the appropriate constant word.  */
4758                   if (shift < HOST_BITS_PER_WIDE_INT)
4759                     value = TREE_INT_CST_LOW (val);
4760                   else
4761                     {
4762                       gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4763                       value = TREE_INT_CST_HIGH (val);
4764                       shift -= HOST_BITS_PER_WIDE_INT;
4765                     }
4766
4767                   /* Get the result. This works only when:
4768                      1 <= this_time <= HOST_BITS_PER_WIDE_INT.  */
4769                   byte |= (((value >> shift)
4770                             & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4771                            << next_bit);
4772                 }
4773
4774               next_offset += this_time;
4775               byte_buffer_in_use = 1;
4776             }
4777         }
4778     }
4779
4780   if (byte_buffer_in_use)
4781     {
4782       assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4783       total_bytes++;
4784     }
4785
4786   if ((unsigned HOST_WIDE_INT)total_bytes < size)
4787     assemble_zeros (size - total_bytes);
4788 }
4789
4790 /* This TREE_LIST contains any weak symbol declarations waiting
4791    to be emitted.  */
4792 static GTY(()) tree weak_decls;
4793
4794 /* Mark DECL as weak.  */
4795
4796 static void
4797 mark_weak (tree decl)
4798 {
4799   DECL_WEAK (decl) = 1;
4800
4801   if (DECL_RTL_SET_P (decl)
4802       && MEM_P (DECL_RTL (decl))
4803       && XEXP (DECL_RTL (decl), 0)
4804       && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4805     SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4806 }
4807
4808 /* Merge weak status between NEWDECL and OLDDECL.  */
4809
4810 void
4811 merge_weak (tree newdecl, tree olddecl)
4812 {
4813   if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4814     {
4815       if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
4816         {
4817           tree *pwd;
4818           /* We put the NEWDECL on the weak_decls list at some point
4819              and OLDDECL as well.  Keep just OLDDECL on the list.  */
4820           for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
4821             if (TREE_VALUE (*pwd) == newdecl)
4822               {
4823                 *pwd = TREE_CHAIN (*pwd);
4824                 break;
4825               }
4826         }
4827       return;
4828     }
4829
4830   if (DECL_WEAK (newdecl))
4831     {
4832       tree wd;
4833
4834       /* NEWDECL is weak, but OLDDECL is not.  */
4835
4836       /* If we already output the OLDDECL, we're in trouble; we can't
4837          go back and make it weak.  This error cannot caught in
4838          declare_weak because the NEWDECL and OLDDECL was not yet
4839          been merged; therefore, TREE_ASM_WRITTEN was not set.  */
4840       if (TREE_ASM_WRITTEN (olddecl))
4841         error ("weak declaration of %q+D must precede definition",
4842                newdecl);
4843
4844       /* If we've already generated rtl referencing OLDDECL, we may
4845          have done so in a way that will not function properly with
4846          a weak symbol.  */
4847       else if (TREE_USED (olddecl)
4848                && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4849         warning (0, "weak declaration of %q+D after first use results "
4850                  "in unspecified behavior", newdecl);
4851
4852       if (SUPPORTS_WEAK)
4853         {
4854           /* We put the NEWDECL on the weak_decls list at some point.
4855              Replace it with the OLDDECL.  */
4856           for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4857             if (TREE_VALUE (wd) == newdecl)
4858               {
4859                 TREE_VALUE (wd) = olddecl;
4860                 break;
4861               }
4862           /* We may not find the entry on the list.  If NEWDECL is a
4863              weak alias, then we will have already called
4864              globalize_decl to remove the entry; in that case, we do
4865              not need to do anything.  */
4866         }
4867
4868       /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping.  */
4869       mark_weak (olddecl);
4870     }
4871   else
4872     /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4873        weak.  Just update NEWDECL to indicate that it's weak too.  */
4874     mark_weak (newdecl);
4875 }
4876
4877 /* Declare DECL to be a weak symbol.  */
4878
4879 void
4880 declare_weak (tree decl)
4881 {
4882   if (! TREE_PUBLIC (decl))
4883     error ("weak declaration of %q+D must be public", decl);
4884   else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4885     error ("weak declaration of %q+D must precede definition", decl);
4886   else if (SUPPORTS_WEAK)
4887     {
4888       if (! DECL_WEAK (decl))
4889         weak_decls = tree_cons (NULL, decl, weak_decls);
4890     }
4891   else
4892     warning (0, "weak declaration of %q+D not supported", decl);
4893
4894   mark_weak (decl);
4895 }
4896
4897 static void
4898 weak_finish_1 (tree decl)
4899 {
4900 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4901   const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4902 #endif
4903
4904   if (! TREE_USED (decl))
4905     return;
4906
4907 #ifdef ASM_WEAKEN_DECL
4908   ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4909 #else
4910 #ifdef ASM_WEAKEN_LABEL
4911   ASM_WEAKEN_LABEL (asm_out_file, name);
4912 #else
4913 #ifdef ASM_OUTPUT_WEAK_ALIAS
4914   {
4915     static bool warn_once = 0;
4916     if (! warn_once)
4917       {
4918         warning (0, "only weak aliases are supported in this configuration");
4919         warn_once = 1;
4920       }
4921     return;
4922   }
4923 #endif
4924 #endif
4925 #endif
4926 }
4927
4928 /* This TREE_LIST contains weakref targets.  */
4929
4930 static GTY(()) tree weakref_targets;
4931
4932 /* Forward declaration.  */
4933 static tree find_decl_and_mark_needed (tree decl, tree target);
4934
4935 /* Emit any pending weak declarations.  */
4936
4937 void
4938 weak_finish (void)
4939 {
4940   tree t;
4941
4942   for (t = weakref_targets; t; t = TREE_CHAIN (t))
4943     {
4944       tree alias_decl = TREE_PURPOSE (t);
4945       tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
4946
4947       if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
4948         /* Remove alias_decl from the weak list, but leave entries for
4949            the target alone.  */
4950         target = NULL_TREE;
4951 #ifndef ASM_OUTPUT_WEAKREF
4952       else if (! TREE_SYMBOL_REFERENCED (target))
4953         {
4954           /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
4955              defined, otherwise we and weak_finish_1 would use a
4956              different macros.  */
4957 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
4958           ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
4959 # else
4960           tree decl = find_decl_and_mark_needed (alias_decl, target);
4961
4962           if (! decl)
4963             {
4964               decl = build_decl (TREE_CODE (alias_decl), target,
4965                                  TREE_TYPE (alias_decl));
4966
4967               DECL_EXTERNAL (decl) = 1;
4968               TREE_PUBLIC (decl) = 1;
4969               DECL_ARTIFICIAL (decl) = 1;
4970               TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
4971               TREE_USED (decl) = 1;
4972             }
4973
4974           weak_finish_1 (decl);
4975 # endif
4976         }
4977 #endif
4978
4979       {
4980         tree *p;
4981         tree t2;
4982
4983         /* Remove the alias and the target from the pending weak list
4984            so that we do not emit any .weak directives for the former,
4985            nor multiple .weak directives for the latter.  */
4986         for (p = &weak_decls; (t2 = *p) ; )
4987           {
4988             if (TREE_VALUE (t2) == alias_decl
4989                 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
4990               *p = TREE_CHAIN (t2);
4991             else
4992               p = &TREE_CHAIN (t2);
4993           }
4994
4995         /* Remove other weakrefs to the same target, to speed things up.  */
4996         for (p = &TREE_CHAIN (t); (t2 = *p) ; )
4997           {
4998             if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
4999               *p = TREE_CHAIN (t2);
5000             else
5001               p = &TREE_CHAIN (t2);
5002           }
5003       }
5004     }
5005
5006   for (t = weak_decls; t; t = TREE_CHAIN (t))
5007     {
5008       tree decl = TREE_VALUE (t);
5009
5010       weak_finish_1 (decl);
5011     }
5012 }
5013
5014 /* Emit the assembly bits to indicate that DECL is globally visible.  */
5015
5016 static void
5017 globalize_decl (tree decl)
5018 {
5019   const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5020
5021 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5022   if (DECL_WEAK (decl))
5023     {
5024       tree *p, t;
5025
5026 #ifdef ASM_WEAKEN_DECL
5027       ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5028 #else
5029       ASM_WEAKEN_LABEL (asm_out_file, name);
5030 #endif
5031
5032       /* Remove this function from the pending weak list so that
5033          we do not emit multiple .weak directives for it.  */
5034       for (p = &weak_decls; (t = *p) ; )
5035         {
5036           if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5037             *p = TREE_CHAIN (t);
5038           else
5039             p = &TREE_CHAIN (t);
5040         }
5041
5042       /* Remove weakrefs to the same target from the pending weakref
5043          list, for the same reason.  */
5044       for (p = &weakref_targets; (t = *p) ; )
5045         {
5046           if (DECL_ASSEMBLER_NAME (decl)
5047               == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5048             *p = TREE_CHAIN (t);
5049           else
5050             p = &TREE_CHAIN (t);
5051         }
5052
5053       return;
5054     }
5055 #elif defined(ASM_MAKE_LABEL_LINKONCE)
5056   if (DECL_ONE_ONLY (decl))
5057     ASM_MAKE_LABEL_LINKONCE (asm_out_file, name);
5058 #endif
5059
5060   targetm.asm_out.globalize_label (asm_out_file, name);
5061 }
5062
5063 /* We have to be able to tell cgraph about the needed-ness of the target
5064    of an alias.  This requires that the decl have been defined.  Aliases
5065    that precede their definition have to be queued for later processing.  */
5066
5067 typedef struct alias_pair GTY(())
5068 {
5069   tree decl;
5070   tree target;
5071 } alias_pair;
5072
5073 /* Define gc'd vector type.  */
5074 DEF_VEC_O(alias_pair);
5075 DEF_VEC_ALLOC_O(alias_pair,gc);
5076
5077 static GTY(()) VEC(alias_pair,gc) *alias_pairs;
5078
5079 /* Given an assembly name, find the decl it is associated with.  At the
5080    same time, mark it needed for cgraph.  */
5081
5082 static tree
5083 find_decl_and_mark_needed (tree decl, tree target)
5084 {
5085   struct cgraph_node *fnode = NULL;
5086   struct cgraph_varpool_node *vnode = NULL;
5087
5088   if (TREE_CODE (decl) == FUNCTION_DECL)
5089     {
5090       fnode = cgraph_node_for_asm (target);
5091       if (fnode == NULL)
5092         vnode = cgraph_varpool_node_for_asm (target);
5093     }
5094   else
5095     {
5096       vnode = cgraph_varpool_node_for_asm (target);
5097       if (vnode == NULL)
5098         fnode = cgraph_node_for_asm (target);
5099     }
5100
5101   if (fnode)
5102     {
5103       /* We can't mark function nodes as used after cgraph global info
5104          is finished.  This wouldn't generally be necessary, but C++
5105          virtual table thunks are introduced late in the game and
5106          might seem like they need marking, although in fact they
5107          don't.  */
5108       if (! cgraph_global_info_ready)
5109         cgraph_mark_needed_node (fnode);
5110       return fnode->decl;
5111     }
5112   else if (vnode)
5113     {
5114       cgraph_varpool_mark_needed_node (vnode);
5115       return vnode->decl;
5116     }
5117   else
5118     return NULL_TREE;
5119 }
5120
5121 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5122    or ASM_OUTPUT_DEF_FROM_DECLS.  The function defines the symbol whose
5123    tree node is DECL to have the value of the tree node TARGET.  */
5124
5125 static void
5126 do_assemble_alias (tree decl, tree target)
5127 {
5128   if (TREE_ASM_WRITTEN (decl))
5129     return;
5130
5131   TREE_ASM_WRITTEN (decl) = 1;
5132   TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5133
5134   if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5135     {
5136       ultimate_transparent_alias_target (&target);
5137
5138       if (!targetm.have_tls
5139           && TREE_CODE (decl) == VAR_DECL
5140           && DECL_THREAD_LOCAL_P (decl))
5141         {
5142           decl = emutls_decl (decl);
5143           target = get_emutls_object_name (target);
5144         }
5145
5146       if (!TREE_SYMBOL_REFERENCED (target))
5147         weakref_targets = tree_cons (decl, target, weakref_targets);
5148
5149 #ifdef ASM_OUTPUT_WEAKREF
5150       ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5151                           IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5152                           IDENTIFIER_POINTER (target));
5153 #else
5154       if (!SUPPORTS_WEAK)
5155         {
5156           error ("%Jweakref is not supported in this configuration", decl);
5157           return;
5158         }
5159 #endif
5160       return;
5161     }
5162
5163   if (!targetm.have_tls
5164       && TREE_CODE (decl) == VAR_DECL
5165       && DECL_THREAD_LOCAL_P (decl))
5166     {
5167       decl = emutls_decl (decl);
5168       target = get_emutls_object_name (target);
5169     }
5170
5171 #ifdef ASM_OUTPUT_DEF
5172   /* Make name accessible from other files, if appropriate.  */
5173
5174   if (TREE_PUBLIC (decl))
5175     {
5176       globalize_decl (decl);
5177       maybe_assemble_visibility (decl);
5178     }
5179
5180 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5181   ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5182 # else
5183   ASM_OUTPUT_DEF (asm_out_file,
5184                   IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5185                   IDENTIFIER_POINTER (target));
5186 # endif
5187 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5188   {
5189     const char *name;
5190     tree *p, t;
5191
5192     name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5193 # ifdef ASM_WEAKEN_DECL
5194     ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5195 # else
5196     ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5197 # endif
5198     /* Remove this function from the pending weak list so that
5199        we do not emit multiple .weak directives for it.  */
5200     for (p = &weak_decls; (t = *p) ; )
5201       if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5202         *p = TREE_CHAIN (t);
5203       else
5204         p = &TREE_CHAIN (t);
5205
5206     /* Remove weakrefs to the same target from the pending weakref
5207        list, for the same reason.  */
5208     for (p = &weakref_targets; (t = *p) ; )
5209       {
5210         if (DECL_ASSEMBLER_NAME (decl)
5211             == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5212           *p = TREE_CHAIN (t);
5213         else
5214           p = &TREE_CHAIN (t);
5215       }
5216   }
5217 #endif
5218 }
5219
5220 /* First pass of completing pending aliases.  Make sure that cgraph knows
5221    which symbols will be required.  */
5222
5223 void
5224 finish_aliases_1 (void)
5225 {
5226   unsigned i;
5227   alias_pair *p;
5228
5229   for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5230     {
5231       tree target_decl;
5232
5233       target_decl = find_decl_and_mark_needed (p->decl, p->target);
5234       if (target_decl == NULL)
5235         {
5236           if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5237             error ("%q+D aliased to undefined symbol %qs",
5238                    p->decl, IDENTIFIER_POINTER (p->target));
5239         }
5240       else if (DECL_EXTERNAL (target_decl)
5241                && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5242         error ("%q+D aliased to external symbol %qs",
5243                p->decl, IDENTIFIER_POINTER (p->target));
5244     }
5245 }
5246
5247 /* Second pass of completing pending aliases.  Emit the actual assembly.
5248    This happens at the end of compilation and thus it is assured that the
5249    target symbol has been emitted.  */
5250
5251 void
5252 finish_aliases_2 (void)
5253 {
5254   unsigned i;
5255   alias_pair *p;
5256
5257   for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5258     do_assemble_alias (p->decl, p->target);
5259
5260   VEC_truncate (alias_pair, alias_pairs, 0);
5261 }
5262
5263 /* Emit an assembler directive to make the symbol for DECL an alias to
5264    the symbol for TARGET.  */
5265
5266 void
5267 assemble_alias (tree decl, tree target)
5268 {
5269   tree target_decl;
5270   bool is_weakref = false;
5271
5272   if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5273     {
5274       tree alias = DECL_ASSEMBLER_NAME (decl);
5275
5276       is_weakref = true;
5277
5278       ultimate_transparent_alias_target (&target);
5279
5280       if (alias == target)
5281         error ("weakref %q+D ultimately targets itself", decl);
5282       else
5283         {
5284 #ifndef ASM_OUTPUT_WEAKREF
5285           IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5286           TREE_CHAIN (alias) = target;
5287 #endif
5288         }
5289       if (TREE_PUBLIC (decl))
5290         error ("weakref %q+D must have static linkage", decl);
5291     }
5292   else
5293     {
5294 #if !defined (ASM_OUTPUT_DEF)
5295 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5296       error ("%Jalias definitions not supported in this configuration", decl);
5297       return;
5298 # else
5299       if (!DECL_WEAK (decl))
5300         {
5301           error ("%Jonly weak aliases are supported in this configuration", decl);
5302           return;
5303         }
5304 # endif
5305 #endif
5306     }
5307
5308   /* We must force creation of DECL_RTL for debug info generation, even though
5309      we don't use it here.  */
5310   make_decl_rtl (decl);
5311   TREE_USED (decl) = 1;
5312
5313   /* A quirk of the initial implementation of aliases required that the user
5314      add "extern" to all of them.  Which is silly, but now historical.  Do
5315      note that the symbol is in fact locally defined.  */
5316   if (! is_weakref)
5317     DECL_EXTERNAL (decl) = 0;
5318
5319   /* Allow aliases to aliases.  */
5320   if (TREE_CODE (decl) == FUNCTION_DECL)
5321     cgraph_node (decl)->alias = true;
5322   else
5323     cgraph_varpool_node (decl)->alias = true;
5324
5325   /* If the target has already been emitted, we don't have to queue the
5326      alias.  This saves a tad o memory.  */
5327   target_decl = find_decl_and_mark_needed (decl, target);
5328   if (target_decl && TREE_ASM_WRITTEN (target_decl))
5329     do_assemble_alias (decl, target);
5330   else
5331     {
5332       alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5333       p->decl = decl;
5334       p->target = target;
5335     }
5336 }
5337
5338 /* Emit an assembler directive to set symbol for DECL visibility to
5339    the visibility type VIS, which must not be VISIBILITY_DEFAULT.  */
5340
5341 void
5342 default_assemble_visibility (tree decl, int vis)
5343 {
5344   static const char * const visibility_types[] = {
5345     NULL, "protected", "hidden", "internal"
5346   };
5347
5348   const char *name, *type;
5349
5350   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5351   type = visibility_types[vis];
5352
5353 #ifdef HAVE_GAS_HIDDEN
5354   fprintf (asm_out_file, "\t.%s\t", type);
5355   assemble_name (asm_out_file, name);
5356   fprintf (asm_out_file, "\n");
5357 #else
5358   warning (OPT_Wattributes, "visibility attribute not supported "
5359            "in this configuration; ignored");
5360 #endif
5361 }
5362
5363 /* A helper function to call assemble_visibility when needed for a decl.  */
5364
5365 static void
5366 maybe_assemble_visibility (tree decl)
5367 {
5368   enum symbol_visibility vis = DECL_VISIBILITY (decl);
5369
5370   if (vis != VISIBILITY_DEFAULT)
5371     targetm.asm_out.visibility (decl, vis);
5372 }
5373
5374 /* Returns 1 if the target configuration supports defining public symbols
5375    so that one of them will be chosen at link time instead of generating a
5376    multiply-defined symbol error, whether through the use of weak symbols or
5377    a target-specific mechanism for having duplicates discarded.  */
5378
5379 int
5380 supports_one_only (void)
5381 {
5382   if (SUPPORTS_ONE_ONLY)
5383     return 1;
5384   return SUPPORTS_WEAK;
5385 }
5386
5387 /* Set up DECL as a public symbol that can be defined in multiple
5388    translation units without generating a linker error.  */
5389
5390 void
5391 make_decl_one_only (tree decl)
5392 {
5393   gcc_assert (TREE_CODE (decl) == VAR_DECL
5394               || TREE_CODE (decl) == FUNCTION_DECL);
5395
5396   TREE_PUBLIC (decl) = 1;
5397
5398   if (SUPPORTS_ONE_ONLY)
5399     {
5400 #ifdef MAKE_DECL_ONE_ONLY
5401       MAKE_DECL_ONE_ONLY (decl);
5402 #endif
5403       DECL_ONE_ONLY (decl) = 1;
5404     }
5405   else if (TREE_CODE (decl) == VAR_DECL
5406       && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5407     DECL_COMMON (decl) = 1;
5408   else
5409     {
5410       gcc_assert (SUPPORTS_WEAK);
5411       DECL_WEAK (decl) = 1;
5412     }
5413 }
5414
5415 void
5416 init_varasm_once (void)
5417 {
5418   section_htab = htab_create_ggc (31, section_entry_hash,
5419                                   section_entry_eq, NULL);
5420   object_block_htab = htab_create_ggc (31, object_block_entry_hash,
5421                                        object_block_entry_eq, NULL);
5422   const_desc_htab = htab_create_ggc (1009, const_desc_hash,
5423                                      const_desc_eq, NULL);
5424
5425   const_alias_set = new_alias_set ();
5426   shared_constant_pool = create_constant_pool ();
5427
5428 #ifdef TEXT_SECTION_ASM_OP
5429   text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
5430                                       TEXT_SECTION_ASM_OP);
5431 #endif
5432
5433 #ifdef DATA_SECTION_ASM_OP
5434   data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5435                                       DATA_SECTION_ASM_OP);
5436 #endif
5437
5438 #ifdef SDATA_SECTION_ASM_OP
5439   sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5440                                        SDATA_SECTION_ASM_OP);
5441 #endif
5442
5443 #ifdef READONLY_DATA_SECTION_ASM_OP
5444   readonly_data_section = get_unnamed_section (0, output_section_asm_op,
5445                                                READONLY_DATA_SECTION_ASM_OP);
5446 #endif
5447
5448 #ifdef CTORS_SECTION_ASM_OP
5449   ctors_section = get_unnamed_section (0, output_section_asm_op,
5450                                        CTORS_SECTION_ASM_OP);
5451 #endif
5452
5453 #ifdef DTORS_SECTION_ASM_OP
5454   dtors_section = get_unnamed_section (0, output_section_asm_op,
5455                                        DTORS_SECTION_ASM_OP);
5456 #endif
5457
5458 #ifdef BSS_SECTION_ASM_OP
5459   bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5460                                      output_section_asm_op,
5461                                      BSS_SECTION_ASM_OP);
5462 #endif
5463
5464 #ifdef SBSS_SECTION_ASM_OP
5465   sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5466                                       output_section_asm_op,
5467                                       SBSS_SECTION_ASM_OP);
5468 #endif
5469
5470   tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5471                                            | SECTION_COMMON, emit_tls_common);
5472   lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5473                                         | SECTION_COMMON, emit_local);
5474   comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5475                                        | SECTION_COMMON, emit_common);
5476
5477 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5478   bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
5479                                                emit_bss);
5480 #endif
5481
5482   targetm.asm_out.init_sections ();
5483
5484   if (readonly_data_section == NULL)
5485     readonly_data_section = text_section;
5486 }
5487
5488 enum tls_model
5489 decl_default_tls_model (tree decl)
5490 {
5491   enum tls_model kind;
5492   bool is_local;
5493
5494   is_local = targetm.binds_local_p (decl);
5495   if (!flag_shlib)
5496     {
5497       if (is_local)
5498         kind = TLS_MODEL_LOCAL_EXEC;
5499       else
5500         kind = TLS_MODEL_INITIAL_EXEC;
5501     }
5502
5503   /* Local dynamic is inefficient when we're not combining the
5504      parts of the address.  */
5505   else if (optimize && is_local)
5506     kind = TLS_MODEL_LOCAL_DYNAMIC;
5507   else
5508     kind = TLS_MODEL_GLOBAL_DYNAMIC;
5509   if (kind < flag_tls_default)
5510     kind = flag_tls_default;
5511
5512   return kind;
5513 }
5514
5515 /* Select a set of attributes for section NAME based on the properties
5516    of DECL and whether or not RELOC indicates that DECL's initializer
5517    might contain runtime relocations.
5518
5519    We make the section read-only and executable for a function decl,
5520    read-only for a const data decl, and writable for a non-const data decl.  */
5521
5522 unsigned int
5523 default_section_type_flags (tree decl, const char *name, int reloc)
5524 {
5525   return default_section_type_flags_1 (decl, name, reloc, flag_pic);
5526 }
5527
5528 unsigned int
5529 default_section_type_flags_1 (tree decl, const char *name, int reloc,
5530                               int shlib)
5531 {
5532   unsigned int flags;
5533
5534   if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5535     flags = SECTION_CODE;
5536   else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
5537     flags = 0;
5538   else if (current_function_decl
5539            && cfun
5540            && cfun->unlikely_text_section_name
5541            && strcmp (name, cfun->unlikely_text_section_name) == 0)
5542     flags = SECTION_CODE;
5543   else if (!decl
5544            && (!current_function_decl || !cfun)
5545            && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
5546     flags = SECTION_CODE;
5547   else
5548     flags = SECTION_WRITE;
5549
5550   if (decl && DECL_ONE_ONLY (decl))
5551     flags |= SECTION_LINKONCE;
5552
5553   if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
5554     flags |= SECTION_TLS | SECTION_WRITE;
5555
5556   if (strcmp (name, ".bss") == 0
5557       || strncmp (name, ".bss.", 5) == 0
5558       || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5559       || strcmp (name, ".sbss") == 0
5560       || strncmp (name, ".sbss.", 6) == 0
5561       || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5562     flags |= SECTION_BSS;
5563
5564   if (strcmp (name, ".tdata") == 0
5565       || strncmp (name, ".tdata.", 7) == 0
5566       || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
5567     flags |= SECTION_TLS;
5568
5569   if (strcmp (name, ".tbss") == 0
5570       || strncmp (name, ".tbss.", 6) == 0
5571       || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
5572     flags |= SECTION_TLS | SECTION_BSS;
5573
5574   /* These three sections have special ELF types.  They are neither
5575      SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
5576      want to print a section type (@progbits or @nobits).  If someone
5577      is silly enough to emit code or TLS variables to one of these
5578      sections, then don't handle them specially.  */
5579   if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
5580       && (strcmp (name, ".init_array") == 0
5581           || strcmp (name, ".fini_array") == 0
5582           || strcmp (name, ".preinit_array") == 0))
5583     flags |= SECTION_NOTYPE;
5584
5585   return flags;
5586 }
5587
5588 /* Return true if the target supports some form of global BSS,
5589    either through bss_noswitch_section, or by selecting a BSS
5590    section in TARGET_ASM_SELECT_SECTION.  */
5591
5592 bool
5593 have_global_bss_p (void)
5594 {
5595   return bss_noswitch_section || targetm.have_switchable_bss_sections;
5596 }
5597
5598 /* Output assembly to switch to section NAME with attribute FLAGS.
5599    Four variants for common object file formats.  */
5600
5601 void
5602 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
5603                           unsigned int flags ATTRIBUTE_UNUSED,
5604                           tree decl ATTRIBUTE_UNUSED)
5605 {
5606   /* Some object formats don't support named sections at all.  The
5607      front-end should already have flagged this as an error.  */
5608   gcc_unreachable ();
5609 }
5610
5611 void
5612 default_elf_asm_named_section (const char *name, unsigned int flags,
5613                                tree decl ATTRIBUTE_UNUSED)
5614 {
5615   char flagchars[10], *f = flagchars;
5616
5617   /* If we have already declared this section, we can use an
5618      abbreviated form to switch back to it -- unless this section is
5619      part of a COMDAT groups, in which case GAS requires the full
5620      declaration every time.  */
5621   if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5622       && (flags & SECTION_DECLARED))
5623     {
5624       fprintf (asm_out_file, "\t.section\t%s\n", name);
5625       return;
5626     }
5627
5628   if (!(flags & SECTION_DEBUG))
5629     *f++ = 'a';
5630   if (flags & SECTION_WRITE)
5631     *f++ = 'w';
5632   if (flags & SECTION_CODE)
5633     *f++ = 'x';
5634   if (flags & SECTION_SMALL)
5635     *f++ = 's';
5636   if (flags & SECTION_MERGE)
5637     *f++ = 'M';
5638   if (flags & SECTION_STRINGS)
5639     *f++ = 'S';
5640   if (flags & SECTION_TLS)
5641     *f++ = 'T';
5642   if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5643     *f++ = 'G';
5644   *f = '\0';
5645
5646   fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
5647
5648   if (!(flags & SECTION_NOTYPE))
5649     {
5650       const char *type;
5651       const char *format;
5652
5653       if (flags & SECTION_BSS)
5654         type = "nobits";
5655       else
5656         type = "progbits";
5657
5658       format = ",@%s";
5659 #ifdef ASM_COMMENT_START
5660       /* On platforms that use "@" as the assembly comment character,
5661          use "%" instead.  */
5662       if (strcmp (ASM_COMMENT_START, "@") == 0)
5663         format = ",%%%s";
5664 #endif
5665       fprintf (asm_out_file, format, type);
5666
5667       if (flags & SECTION_ENTSIZE)
5668         fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
5669       if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5670         fprintf (asm_out_file, ",%s,comdat",
5671                  lang_hooks.decls.comdat_group (decl));
5672     }
5673
5674   putc ('\n', asm_out_file);
5675 }
5676
5677 void
5678 default_coff_asm_named_section (const char *name, unsigned int flags,
5679                                 tree decl ATTRIBUTE_UNUSED)
5680 {
5681   char flagchars[8], *f = flagchars;
5682
5683   if (flags & SECTION_WRITE)
5684     *f++ = 'w';
5685   if (flags & SECTION_CODE)
5686     *f++ = 'x';
5687   *f = '\0';
5688
5689   fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5690 }
5691
5692 void
5693 default_pe_asm_named_section (const char *name, unsigned int flags,
5694                               tree decl)
5695 {
5696   default_coff_asm_named_section (name, flags, decl);
5697
5698   if (flags & SECTION_LINKONCE)
5699     {
5700       /* Functions may have been compiled at various levels of
5701          optimization so we can't use `same_size' here.
5702          Instead, have the linker pick one.  */
5703       fprintf (asm_out_file, "\t.linkonce %s\n",
5704                (flags & SECTION_CODE ? "discard" : "same_size"));
5705     }
5706 }
5707 \f
5708 /* The lame default section selector.  */
5709
5710 section *
5711 default_select_section (tree decl, int reloc,
5712                         unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5713 {
5714   if (DECL_P (decl))
5715     {
5716       if (decl_readonly_section (decl, reloc))
5717         return readonly_data_section;
5718     }
5719   else if (TREE_CODE (decl) == CONSTRUCTOR)
5720     {
5721       if (! ((flag_pic && reloc)
5722              || !TREE_READONLY (decl)
5723              || TREE_SIDE_EFFECTS (decl)
5724              || !TREE_CONSTANT (decl)))
5725         return readonly_data_section;
5726     }
5727   else if (TREE_CODE (decl) == STRING_CST)
5728     return readonly_data_section;
5729   else if (! (flag_pic && reloc))
5730     return readonly_data_section;
5731
5732   return data_section;
5733 }
5734
5735 enum section_category
5736 categorize_decl_for_section (tree decl, int reloc, int shlib)
5737 {
5738   enum section_category ret;
5739
5740   if (TREE_CODE (decl) == FUNCTION_DECL)
5741     return SECCAT_TEXT;
5742   else if (TREE_CODE (decl) == STRING_CST)
5743     {
5744       if (flag_mudflap) /* or !flag_merge_constants */
5745         return SECCAT_RODATA;
5746       else
5747         return SECCAT_RODATA_MERGE_STR;
5748     }
5749   else if (TREE_CODE (decl) == VAR_DECL)
5750     {
5751       if (bss_initializer_p (decl))
5752         ret = SECCAT_BSS;
5753       else if (! TREE_READONLY (decl)
5754                || TREE_SIDE_EFFECTS (decl)
5755                || ! TREE_CONSTANT (DECL_INITIAL (decl)))
5756         {
5757           if (shlib && (reloc & 2))
5758             ret = SECCAT_DATA_REL;
5759           else if (shlib && reloc)
5760             ret = SECCAT_DATA_REL_LOCAL;
5761           else
5762             ret = SECCAT_DATA;
5763         }
5764       else if (shlib && (reloc & 2))
5765         ret = SECCAT_DATA_REL_RO;
5766       else if (shlib && reloc)
5767         ret = SECCAT_DATA_REL_RO_LOCAL;
5768       else if (reloc || flag_merge_constants < 2)
5769         /* C and C++ don't allow different variables to share the same
5770            location.  -fmerge-all-constants allows even that (at the
5771            expense of not conforming).  */
5772         ret = SECCAT_RODATA;
5773       else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
5774         ret = SECCAT_RODATA_MERGE_STR_INIT;
5775       else
5776         ret = SECCAT_RODATA_MERGE_CONST;
5777     }
5778   else if (TREE_CODE (decl) == CONSTRUCTOR)
5779     {
5780       if ((shlib && reloc)
5781           || TREE_SIDE_EFFECTS (decl)
5782           || ! TREE_CONSTANT (decl))
5783         ret = SECCAT_DATA;
5784       else
5785         ret = SECCAT_RODATA;
5786     }
5787   else
5788     ret = SECCAT_RODATA;
5789
5790   /* There are no read-only thread-local sections.  */
5791   if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
5792     {
5793       /* Note that this would be *just* SECCAT_BSS, except that there's
5794          no concept of a read-only thread-local-data section.  */
5795       if (ret == SECCAT_BSS
5796           || (flag_zero_initialized_in_bss
5797               && initializer_zerop (DECL_INITIAL (decl))))
5798         ret = SECCAT_TBSS;
5799       else
5800         ret = SECCAT_TDATA;
5801     }
5802
5803   /* If the target uses small data sections, select it.  */
5804   else if (targetm.in_small_data_p (decl))
5805     {
5806       if (ret == SECCAT_BSS)
5807         ret = SECCAT_SBSS;
5808       else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
5809         ret = SECCAT_SRODATA;
5810       else
5811         ret = SECCAT_SDATA;
5812     }
5813
5814   return ret;
5815 }
5816
5817 bool
5818 decl_readonly_section (tree decl, int reloc)
5819 {
5820   return decl_readonly_section_1 (decl, reloc, flag_pic);
5821 }
5822
5823 bool
5824 decl_readonly_section_1 (tree decl, int reloc, int shlib)
5825 {
5826   switch (categorize_decl_for_section (decl, reloc, shlib))
5827     {
5828     case SECCAT_RODATA:
5829     case SECCAT_RODATA_MERGE_STR:
5830     case SECCAT_RODATA_MERGE_STR_INIT:
5831     case SECCAT_RODATA_MERGE_CONST:
5832     case SECCAT_SRODATA:
5833       return true;
5834       break;
5835     default:
5836       return false;
5837       break;
5838     }
5839 }
5840
5841 /* Select a section based on the above categorization.  */
5842
5843 section *
5844 default_elf_select_section (tree decl, int reloc,
5845                             unsigned HOST_WIDE_INT align)
5846 {
5847   return default_elf_select_section_1 (decl, reloc, align, flag_pic);
5848 }
5849
5850 section *
5851 default_elf_select_section_1 (tree decl, int reloc,
5852                               unsigned HOST_WIDE_INT align, int shlib)
5853 {
5854   const char *sname;
5855   switch (categorize_decl_for_section (decl, reloc, shlib))
5856     {
5857     case SECCAT_TEXT:
5858       /* We're not supposed to be called on FUNCTION_DECLs.  */
5859       gcc_unreachable ();
5860     case SECCAT_RODATA:
5861       return readonly_data_section;
5862     case SECCAT_RODATA_MERGE_STR:
5863       return mergeable_string_section (decl, align, 0);
5864     case SECCAT_RODATA_MERGE_STR_INIT:
5865       return mergeable_string_section (DECL_INITIAL (decl), align, 0);
5866     case SECCAT_RODATA_MERGE_CONST:
5867       return mergeable_constant_section (DECL_MODE (decl), align, 0);
5868     case SECCAT_SRODATA:
5869       sname = ".sdata2";
5870       break;
5871     case SECCAT_DATA:
5872       return data_section;
5873     case SECCAT_DATA_REL:
5874       sname = ".data.rel";
5875       break;
5876     case SECCAT_DATA_REL_LOCAL:
5877       sname = ".data.rel.local";
5878       break;
5879     case SECCAT_DATA_REL_RO:
5880       sname = ".data.rel.ro";
5881       break;
5882     case SECCAT_DATA_REL_RO_LOCAL:
5883       sname = ".data.rel.ro.local";
5884       break;
5885     case SECCAT_SDATA:
5886       sname = ".sdata";
5887       break;
5888     case SECCAT_TDATA:
5889       sname = ".tdata";
5890       break;
5891     case SECCAT_BSS:
5892       if (bss_section)
5893         return bss_section;
5894       sname = ".bss";
5895       break;
5896     case SECCAT_SBSS:
5897       sname = ".sbss";
5898       break;
5899     case SECCAT_TBSS:
5900       sname = ".tbss";
5901       break;
5902     default:
5903       gcc_unreachable ();
5904     }
5905
5906   if (!DECL_P (decl))
5907     decl = NULL_TREE;
5908   return get_named_section (decl, sname, reloc);
5909 }
5910
5911 /* Construct a unique section name based on the decl name and the
5912    categorization performed above.  */
5913
5914 void
5915 default_unique_section (tree decl, int reloc)
5916 {
5917   default_unique_section_1 (decl, reloc, flag_pic);
5918 }
5919
5920 void
5921 default_unique_section_1 (tree decl, int reloc, int shlib)
5922 {
5923   /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
5924   bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
5925   const char *prefix, *name;
5926   size_t nlen, plen;
5927   char *string;
5928
5929   switch (categorize_decl_for_section (decl, reloc, shlib))
5930     {
5931     case SECCAT_TEXT:
5932       prefix = one_only ? ".gnu.linkonce.t." : ".text.";
5933       break;
5934     case SECCAT_RODATA:
5935     case SECCAT_RODATA_MERGE_STR:
5936     case SECCAT_RODATA_MERGE_STR_INIT:
5937     case SECCAT_RODATA_MERGE_CONST:
5938       prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
5939       break;
5940     case SECCAT_SRODATA:
5941       prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
5942       break;
5943     case SECCAT_DATA:
5944       prefix = one_only ? ".gnu.linkonce.d." : ".data.";
5945       break;
5946     case SECCAT_DATA_REL:
5947       prefix = one_only ? ".gnu.linkonce.d.rel." : ".data.rel.";
5948       break;
5949     case SECCAT_DATA_REL_LOCAL:
5950       prefix = one_only ? ".gnu.linkonce.d.rel.local." : ".data.rel.local.";
5951       break;
5952     case SECCAT_DATA_REL_RO:
5953       prefix = one_only ? ".gnu.linkonce.d.rel.ro." : ".data.rel.ro.";
5954       break;
5955     case SECCAT_DATA_REL_RO_LOCAL:
5956       prefix = one_only ? ".gnu.linkonce.d.rel.ro.local."
5957                : ".data.rel.ro.local.";
5958       break;
5959     case SECCAT_SDATA:
5960       prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
5961       break;
5962     case SECCAT_BSS:
5963       prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
5964       break;
5965     case SECCAT_SBSS:
5966       prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
5967       break;
5968     case SECCAT_TDATA:
5969       prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
5970       break;
5971     case SECCAT_TBSS:
5972       prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
5973       break;
5974     default:
5975       gcc_unreachable ();
5976     }
5977   plen = strlen (prefix);
5978
5979   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5980   name = targetm.strip_name_encoding (name);
5981   nlen = strlen (name);
5982
5983   string = alloca (nlen + plen + 1);
5984   memcpy (string, prefix, plen);
5985   memcpy (string + plen, name, nlen + 1);
5986
5987   DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
5988 }
5989
5990 section *
5991 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
5992                             rtx x,
5993                             unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5994 {
5995   if (flag_pic)
5996     switch (GET_CODE (x))
5997       {
5998       case CONST:
5999       case SYMBOL_REF:
6000       case LABEL_REF:
6001         return data_section;
6002
6003       default:
6004         break;
6005       }
6006
6007   return readonly_data_section;
6008 }
6009
6010 section *
6011 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6012                                 unsigned HOST_WIDE_INT align)
6013 {
6014   /* ??? Handle small data here somehow.  */
6015
6016   if (flag_pic)
6017     switch (GET_CODE (x))
6018       {
6019       case CONST:
6020       case SYMBOL_REF:
6021         return get_named_section (NULL, ".data.rel.ro", 3);
6022
6023       case LABEL_REF:
6024         return get_named_section (NULL, ".data.rel.ro.local", 1);
6025
6026       default:
6027         break;
6028       }
6029
6030   return mergeable_constant_section (mode, align, 0);
6031 }
6032
6033 /* Set the generally applicable flags on the SYMBOL_REF for EXP.  */
6034
6035 void
6036 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6037 {
6038   rtx symbol;
6039   int flags;
6040
6041   /* Careful not to prod global register variables.  */
6042   if (!MEM_P (rtl))
6043     return;
6044   symbol = XEXP (rtl, 0);
6045   if (GET_CODE (symbol) != SYMBOL_REF)
6046     return;
6047
6048   flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6049   if (TREE_CODE (decl) == FUNCTION_DECL)
6050     flags |= SYMBOL_FLAG_FUNCTION;
6051   if (targetm.binds_local_p (decl))
6052     flags |= SYMBOL_FLAG_LOCAL;
6053   if (targetm.have_tls && TREE_CODE (decl) == VAR_DECL
6054       && DECL_THREAD_LOCAL_P (decl))
6055     flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6056   else if (targetm.in_small_data_p (decl))
6057     flags |= SYMBOL_FLAG_SMALL;
6058   /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names?  Without
6059      being PUBLIC, the thing *must* be defined in this translation unit.
6060      Prevent this buglet from being propagated into rtl code as well.  */
6061   if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6062     flags |= SYMBOL_FLAG_EXTERNAL;
6063
6064   SYMBOL_REF_FLAGS (symbol) = flags;
6065 }
6066
6067 /* By default, we do nothing for encode_section_info, so we need not
6068    do anything but discard the '*' marker.  */
6069
6070 const char *
6071 default_strip_name_encoding (const char *str)
6072 {
6073   return str + (*str == '*');
6074 }
6075
6076 #ifdef ASM_OUTPUT_DEF
6077 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR.  Define the
6078    anchor relative to ".", the current section position.  */
6079
6080 void
6081 default_asm_output_anchor (rtx symbol)
6082 {
6083   char buffer[100];
6084
6085   sprintf (buffer, ". + " HOST_WIDE_INT_PRINT_DEC,
6086            SYMBOL_REF_BLOCK_OFFSET (symbol));
6087   ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6088 }
6089 #endif
6090
6091 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P.  */
6092
6093 bool
6094 default_use_anchors_for_symbol_p (rtx symbol)
6095 {
6096   section *sect;
6097   tree decl;
6098
6099   /* Don't use anchors for mergeable sections.  The linker might move
6100      the objects around.  */
6101   sect = SYMBOL_REF_BLOCK (symbol)->sect;
6102   if (sect->common.flags & SECTION_MERGE)
6103     return false;
6104
6105   /* Don't use anchors for small data sections.  The small data register
6106      acts as an anchor for such sections.  */
6107   if (sect->common.flags & SECTION_SMALL)
6108     return false;
6109
6110   decl = SYMBOL_REF_DECL (symbol);
6111   if (decl && DECL_P (decl))
6112     {
6113       /* Don't use section anchors for decls that might be defined by
6114          other modules.  */
6115       if (!targetm.binds_local_p (decl))
6116         return false;
6117
6118       /* Don't use section anchors for decls that will be placed in a
6119          small data section.  */
6120       /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6121          one above.  The problem is that we only use SECTION_SMALL for
6122          sections that should be marked as small in the section directive.  */
6123       if (targetm.in_small_data_p (decl))
6124         return false;
6125     }
6126   return true;
6127 }
6128
6129 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6130    wrt cross-module name binding.  */
6131
6132 bool
6133 default_binds_local_p (tree exp)
6134 {
6135   return default_binds_local_p_1 (exp, flag_shlib);
6136 }
6137
6138 bool
6139 default_binds_local_p_1 (tree exp, int shlib)
6140 {
6141   bool local_p;
6142
6143   /* A non-decl is an entry in the constant pool.  */
6144   if (!DECL_P (exp))
6145     local_p = true;
6146   /* Weakrefs may not bind locally, even though the weakref itself is
6147      always static and therefore local.  */
6148   else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6149     local_p = false;
6150   /* Static variables are always local.  */
6151   else if (! TREE_PUBLIC (exp))
6152     local_p = true;
6153   /* A variable is local if the user has said explicitly that it will
6154      be.  */
6155   else if (DECL_VISIBILITY_SPECIFIED (exp)
6156            && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6157     local_p = true;
6158   /* Variables defined outside this object might not be local.  */
6159   else if (DECL_EXTERNAL (exp))
6160     local_p = false;
6161   /* If defined in this object and visibility is not default, must be
6162      local.  */
6163   else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6164     local_p = true;
6165   /* Default visibility weak data can be overridden by a strong symbol
6166      in another module and so are not local.  */
6167   else if (DECL_WEAK (exp))
6168     local_p = false;
6169   /* If PIC, then assume that any global name can be overridden by
6170      symbols resolved from other modules.  */
6171   else if (shlib)
6172     local_p = false;
6173   /* Uninitialized COMMON variable may be unified with symbols
6174      resolved from other modules.  */
6175   else if (DECL_COMMON (exp)
6176            && (DECL_INITIAL (exp) == NULL
6177                || DECL_INITIAL (exp) == error_mark_node))
6178     local_p = false;
6179   /* Otherwise we're left with initialized (or non-common) global data
6180      which is of necessity defined locally.  */
6181   else
6182     local_p = true;
6183
6184   return local_p;
6185 }
6186
6187 /* Determine whether or not a pointer mode is valid. Assume defaults
6188    of ptr_mode or Pmode - can be overridden.  */
6189 bool
6190 default_valid_pointer_mode (enum machine_mode mode)
6191 {
6192   return (mode == ptr_mode || mode == Pmode);
6193 }
6194
6195 /* Default function to output code that will globalize a label.  A
6196    target must define GLOBAL_ASM_OP or provide its own function to
6197    globalize a label.  */
6198 #ifdef GLOBAL_ASM_OP
6199 void
6200 default_globalize_label (FILE * stream, const char *name)
6201 {
6202   fputs (GLOBAL_ASM_OP, stream);
6203   assemble_name (stream, name);
6204   putc ('\n', stream);
6205 }
6206 #endif /* GLOBAL_ASM_OP */
6207
6208 /* Default function to output a label for unwind information.  The
6209    default is to do nothing.  A target that needs nonlocal labels for
6210    unwind information must provide its own function to do this.  */
6211 void
6212 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6213                            tree decl ATTRIBUTE_UNUSED,
6214                            int for_eh ATTRIBUTE_UNUSED,
6215                            int empty ATTRIBUTE_UNUSED)
6216 {
6217 }
6218
6219 /* Default function to output a label to divide up the exception table.
6220    The default is to do nothing.  A target that needs/wants to divide
6221    up the table must provide it's own function to do this.  */
6222 void
6223 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6224 {
6225 }
6226
6227 /* This is how to output an internal numbered label where PREFIX is
6228    the class of label and LABELNO is the number within the class.  */
6229
6230 void
6231 default_internal_label (FILE *stream, const char *prefix,
6232                         unsigned long labelno)
6233 {
6234   char *const buf = alloca (40 + strlen (prefix));
6235   ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6236   ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6237 }
6238
6239 /* This is the default behavior at the beginning of a file.  It's
6240    controlled by two other target-hook toggles.  */
6241 void
6242 default_file_start (void)
6243 {
6244   if (targetm.file_start_app_off && !flag_verbose_asm)
6245     fputs (ASM_APP_OFF, asm_out_file);
6246
6247   if (targetm.file_start_file_directive)
6248     output_file_directive (asm_out_file, main_input_filename);
6249 }
6250
6251 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6252    which emits a special section directive used to indicate whether or
6253    not this object file needs an executable stack.  This is primarily
6254    a GNU extension to ELF but could be used on other targets.  */
6255
6256 int trampolines_created;
6257
6258 void
6259 file_end_indicate_exec_stack (void)
6260 {
6261   unsigned int flags = SECTION_DEBUG;
6262   if (trampolines_created)
6263     flags |= SECTION_CODE;
6264
6265   switch_to_section (get_section (".note.GNU-stack", flags, NULL));
6266 }
6267
6268 /* Output DIRECTIVE (a C string) followed by a newline.  This is used as
6269    a get_unnamed_section callback.  */
6270
6271 void
6272 output_section_asm_op (const void *directive)
6273 {
6274   fprintf (asm_out_file, "%s\n", (const char *) directive);
6275 }
6276
6277 /* Emit assembly code to switch to section NEW_SECTION.  Do nothing if
6278    the current section is NEW_SECTION.  */
6279
6280 void
6281 switch_to_section (section *new_section)
6282 {
6283   if (in_section == new_section)
6284     return;
6285
6286   if (new_section->common.flags & SECTION_FORGET)
6287     in_section = NULL;
6288   else
6289     in_section = new_section;
6290
6291   switch (SECTION_STYLE (new_section))
6292     {
6293     case SECTION_NAMED:
6294       if (cfun
6295           && !cfun->unlikely_text_section_name
6296           && strcmp (new_section->named.name,
6297                      UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6298         cfun->unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6299
6300       targetm.asm_out.named_section (new_section->named.name,
6301                                      new_section->named.common.flags,
6302                                      new_section->named.decl);
6303       break;
6304
6305     case SECTION_UNNAMED:
6306       new_section->unnamed.callback (new_section->unnamed.data);
6307       break;
6308
6309     case SECTION_NOSWITCH:
6310       gcc_unreachable ();
6311       break;
6312     }
6313
6314   new_section->common.flags |= SECTION_DECLARED;
6315 }
6316
6317 /* If block symbol SYMBOL has not yet been assigned an offset, place
6318    it at the end of its block.  */
6319
6320 void
6321 place_block_symbol (rtx symbol)
6322 {
6323   unsigned HOST_WIDE_INT size, mask, offset;
6324   struct constant_descriptor_rtx *desc;
6325   unsigned int alignment;
6326   struct object_block *block;
6327   tree decl;
6328
6329   gcc_assert (SYMBOL_REF_BLOCK (symbol));
6330   if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6331     return;
6332
6333   /* Work out the symbol's size and alignment.  */
6334   if (CONSTANT_POOL_ADDRESS_P (symbol))
6335     {
6336       desc = SYMBOL_REF_CONSTANT (symbol);
6337       alignment = desc->align;
6338       size = GET_MODE_SIZE (desc->mode);
6339     }
6340   else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6341     {
6342       decl = SYMBOL_REF_DECL (symbol);
6343       alignment = get_constant_alignment (decl);
6344       size = get_constant_size (decl);
6345     }
6346   else
6347     {
6348       decl = SYMBOL_REF_DECL (symbol);
6349       alignment = DECL_ALIGN (decl);
6350       size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6351     }
6352
6353   /* Calculate the object's offset from the start of the block.  */
6354   block = SYMBOL_REF_BLOCK (symbol);
6355   mask = alignment / BITS_PER_UNIT - 1;
6356   offset = (block->size + mask) & ~mask;
6357   SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
6358
6359   /* Record the block's new alignment and size.  */
6360   block->alignment = MAX (block->alignment, alignment);
6361   block->size = offset + size;
6362
6363   VEC_safe_push (rtx, gc, block->objects, symbol);
6364 }
6365
6366 /* Return the anchor that should be used to address byte offset OFFSET
6367    from the first object in BLOCK.  MODEL is the TLS model used
6368    to access it.  */
6369
6370 rtx
6371 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
6372                     enum tls_model model)
6373 {
6374   char label[100];
6375   unsigned int begin, middle, end;
6376   unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
6377   rtx anchor;
6378
6379   /* Work out the anchor's offset.  Use an offset of 0 for the first
6380      anchor so that we don't pessimize the case where we take the address
6381      of a variable at the beginning of the block.  This is particularly
6382      useful when a block has only one variable assigned to it.
6383
6384      We try to place anchors RANGE bytes apart, so there can then be
6385      anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6386      a ptr_mode offset.  With some target settings, the lowest such
6387      anchor might be out of range for the lowest ptr_mode offset;
6388      likewise the highest anchor for the highest offset.  Use anchors
6389      at the extreme ends of the ptr_mode range in such cases.
6390
6391      All arithmetic uses unsigned integers in order to avoid
6392      signed overflow.  */
6393   max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
6394   min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
6395   range = max_offset - min_offset + 1;
6396   if (range == 0)
6397     offset = 0;
6398   else
6399     {
6400       bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
6401       if (offset < 0)
6402         {
6403           delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
6404           delta -= delta % range;
6405           if (delta > bias)
6406             delta = bias;
6407           offset = (HOST_WIDE_INT) (-delta);
6408         }
6409       else
6410         {
6411           delta = (unsigned HOST_WIDE_INT) offset - min_offset;
6412           delta -= delta % range;
6413           if (delta > bias - 1)
6414             delta = bias - 1;
6415           offset = (HOST_WIDE_INT) delta;
6416         }
6417     }
6418
6419   /* Do a binary search to see if there's already an anchor we can use.
6420      Set BEGIN to the new anchor's index if not.  */
6421   begin = 0;
6422   end = VEC_length (rtx, block->anchors);
6423   while (begin != end)
6424     {
6425       middle = (end + begin) / 2;
6426       anchor = VEC_index (rtx, block->anchors, middle);
6427       if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
6428         end = middle;
6429       else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
6430         begin = middle + 1;
6431       else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
6432         end = middle;
6433       else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
6434         begin = middle + 1;
6435       else
6436         return anchor;
6437     }
6438
6439   /* Create a new anchor with a unique label.  */
6440   ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
6441   anchor = create_block_symbol (ggc_strdup (label), block, offset);
6442   SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
6443   SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
6444
6445   /* Insert it at index BEGIN.  */
6446   VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
6447   return anchor;
6448 }
6449
6450 /* Output the objects in BLOCK.  */
6451
6452 static void
6453 output_object_block (struct object_block *block)
6454 {
6455   struct constant_descriptor_rtx *desc;
6456   unsigned int i;
6457   HOST_WIDE_INT offset;
6458   tree decl;
6459   rtx symbol;
6460
6461   if (block->objects == NULL)
6462     return;
6463
6464   /* Switch to the section and make sure that the first byte is
6465      suitably aligned.  */
6466   switch_to_section (block->sect);
6467   assemble_align (block->alignment);
6468
6469   /* Define the values of all anchors relative to the current section
6470      position.  */
6471   for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
6472     targetm.asm_out.output_anchor (symbol);
6473
6474   /* Output the objects themselves.  */
6475   offset = 0;
6476   for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
6477     {
6478       /* Move to the object's offset, padding with zeros if necessary.  */
6479       assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
6480       offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
6481       if (CONSTANT_POOL_ADDRESS_P (symbol))
6482         {
6483           desc = SYMBOL_REF_CONSTANT (symbol);
6484           output_constant_pool_1 (desc, 1);
6485           offset += GET_MODE_SIZE (desc->mode);
6486         }
6487       else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6488         {
6489           decl = SYMBOL_REF_DECL (symbol);
6490           assemble_constant_contents (decl, XSTR (symbol, 0),
6491                                       get_constant_alignment (decl));
6492           offset += get_constant_size (decl);
6493         }
6494       else
6495         {
6496           decl = SYMBOL_REF_DECL (symbol);
6497           assemble_variable_contents (decl, XSTR (symbol, 0), false);
6498           offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6499         }
6500     }
6501 }
6502
6503 /* A htab_traverse callback used to call output_object_block for
6504    each member of object_block_htab.  */
6505
6506 static int
6507 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
6508 {
6509   output_object_block ((struct object_block *) (*slot));
6510   return 1;
6511 }
6512
6513 /* Output the definitions of all object_blocks.  */
6514
6515 void
6516 output_object_blocks (void)
6517 {
6518   htab_traverse (object_block_htab, output_object_block_htab, NULL);
6519 }
6520
6521 #include "gt-varasm.h"