OSDN Git Service

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