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