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