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