1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
6 This file is part of GCC.
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
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
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
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.
28 We also output the assembler code for constants stored in memory
29 and are responsible for combining constants with the same value. */
33 #include "coretypes.h"
40 #include "hard-reg-set.h"
48 #include "langhooks.h"
52 #include "tree-mudflap.h"
54 #include "cfglayout.h"
55 #include "basic-block.h"
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h" /* Needed for external data
59 declarations for e.g. AIX 4.x. */
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;
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
70 struct constant_descriptor_rtx;
71 struct rtx_constant_pool;
73 struct varasm_status GTY(())
75 /* If we're using a per-function constant pool, this is it. */
76 struct rtx_constant_pool *pool;
78 /* Number of tree-constants deferred during the expansion of this
80 unsigned int deferred_constants;
83 #define n_deferred_constants (cfun->varasm->deferred_constants)
85 /* Number for making the label on the next
86 constant that is stored in memory. */
88 static GTY(()) int const_labelno;
90 /* Carry information from ASM_DECLARE_OBJECT_NAME
91 to ASM_FINISH_DECLARE_OBJECT. */
93 int size_directive_output;
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,
100 tree last_assemble_variable_decl;
102 /* The following global variable indicates if the first basic block
103 in a function belongs to the cold partition or not. */
105 bool first_function_block_is_cold;
107 /* We give all constants their own alias set. Perhaps redundant with
108 MEM_READONLY_P, but pre-dates it. */
110 static HOST_WIDE_INT const_alias_set;
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);
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 #ifdef BSS_SECTION_ASM_OP
130 #ifdef ASM_OUTPUT_BSS
131 static void asm_output_bss (FILE *, tree, const char *,
132 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
134 #ifdef ASM_OUTPUT_ALIGNED_BSS
135 static void asm_output_aligned_bss (FILE *, tree, const char *,
136 unsigned HOST_WIDE_INT, int)
139 #endif /* BSS_SECTION_ASM_OP */
140 static void mark_weak (tree);
141 static void output_constant_pool (const char *, tree);
143 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
144 section *text_section;
145 section *data_section;
146 section *readonly_data_section;
147 section *sdata_section;
148 section *ctors_section;
149 section *dtors_section;
150 section *bss_section;
151 section *sbss_section;
153 /* Various forms of common section. All are guaranteed to be nonnull. */
154 section *tls_comm_section;
155 section *comm_section;
156 section *lcomm_section;
158 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
160 section *bss_noswitch_section;
162 /* The section that holds the main exception table, when known. The section
163 is set either by the target's init_sections hook or by the first call to
164 switch_to_exception_section. */
165 section *exception_section;
167 /* The section that holds the DWARF2 frame unwind information, when known.
168 The section is set either by the target's init_sections hook or by the
169 first call to switch_to_eh_frame_section. */
170 section *eh_frame_section;
172 /* asm_out_file's current section. This is NULL if no section has yet
173 been selected or if we lose track of what the current section is. */
176 /* True if code for the current function is currently being directed
177 at the cold section. */
178 bool in_cold_section_p;
180 /* A linked list of all the unnamed sections. */
181 static GTY(()) section *unnamed_sections;
183 /* Return a nonzero value if DECL has a section attribute. */
184 #ifndef IN_NAMED_SECTION
185 #define IN_NAMED_SECTION(DECL) \
186 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
187 && DECL_SECTION_NAME (DECL) != NULL_TREE)
190 /* Hash table of named sections. */
191 static GTY((param_is (section))) htab_t section_htab;
193 /* A table of object_blocks, indexed by section. */
194 static GTY((param_is (struct object_block))) htab_t object_block_htab;
196 /* The next number to use for internal anchor labels. */
197 static GTY(()) int anchor_labelno;
199 /* A pool of constants that can be shared between functions. */
200 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
202 /* Helper routines for maintaining section_htab. */
205 section_entry_eq (const void *p1, const void *p2)
207 const section *old = p1;
208 const char *new = p2;
210 return strcmp (old->named.name, new) == 0;
214 section_entry_hash (const void *p)
216 const section *old = p;
217 return htab_hash_string (old->named.name);
220 /* Return a hash value for section SECT. */
223 hash_section (section *sect)
225 if (sect->common.flags & SECTION_NAMED)
226 return htab_hash_string (sect->named.name);
227 return sect->common.flags;
230 /* Helper routines for maintaining object_block_htab. */
233 object_block_entry_eq (const void *p1, const void *p2)
235 const struct object_block *old = p1;
236 const section *new = p2;
238 return old->sect == new;
242 object_block_entry_hash (const void *p)
244 const struct object_block *old = p;
245 return hash_section (old->sect);
248 /* Return a new unnamed section with the given fields. */
251 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
256 sect = ggc_alloc (sizeof (struct unnamed_section));
257 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
258 sect->unnamed.callback = callback;
259 sect->unnamed.data = data;
260 sect->unnamed.next = unnamed_sections;
262 unnamed_sections = sect;
266 /* Return a SECTION_NOSWITCH section with the given fields. */
269 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
273 sect = ggc_alloc (sizeof (struct unnamed_section));
274 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
275 sect->noswitch.callback = callback;
280 /* Return the named section structure associated with NAME. Create
281 a new section with the given fields if no such structure exists. */
284 get_section (const char *name, unsigned int flags, tree decl)
286 section *sect, **slot;
289 htab_find_slot_with_hash (section_htab, name,
290 htab_hash_string (name), INSERT);
291 flags |= SECTION_NAMED;
294 sect = ggc_alloc (sizeof (struct named_section));
295 sect->named.common.flags = flags;
296 sect->named.name = ggc_strdup (name);
297 sect->named.decl = decl;
303 if ((sect->common.flags & ~SECTION_DECLARED) != flags
304 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
306 /* Sanity check user variables for flag changes. */
308 decl = sect->named.decl;
310 error ("%+D causes a section type conflict", decl);
316 /* Return true if the current compilation mode benefits from having
317 objects grouped into blocks. */
320 use_object_blocks_p (void)
322 return flag_section_anchors;
325 /* Return the object_block structure for section SECT. Create a new
326 structure if we haven't created one already. Return null if SECT
329 static struct object_block *
330 get_block_for_section (section *sect)
332 struct object_block *block;
338 slot = htab_find_slot_with_hash (object_block_htab, sect,
339 hash_section (sect), INSERT);
340 block = (struct object_block *) *slot;
343 block = (struct object_block *)
344 ggc_alloc_cleared (sizeof (struct object_block));
351 /* Create a symbol with label LABEL and place it at byte offset
352 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
353 is not yet known. LABEL must be a garbage-collected string. */
356 create_block_symbol (const char *label, struct object_block *block,
357 HOST_WIDE_INT offset)
362 /* Create the extended SYMBOL_REF. */
363 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
364 symbol = ggc_alloc_zone (size, &rtl_zone);
366 /* Initialize the normal SYMBOL_REF fields. */
367 memset (symbol, 0, size);
368 PUT_CODE (symbol, SYMBOL_REF);
369 PUT_MODE (symbol, Pmode);
370 XSTR (symbol, 0) = label;
371 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
373 /* Initialize the block_symbol stuff. */
374 SYMBOL_REF_BLOCK (symbol) = block;
375 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
381 initialize_cold_section_name (void)
383 const char *stripped_name;
387 gcc_assert (cfun && current_function_decl);
388 if (cfun->unlikely_text_section_name)
391 dsn = DECL_SECTION_NAME (current_function_decl);
392 if (flag_function_sections && dsn)
394 name = alloca (TREE_STRING_LENGTH (dsn) + 1);
395 memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
397 stripped_name = targetm.strip_name_encoding (name);
399 buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
400 cfun->unlikely_text_section_name = ggc_strdup (buffer);
403 cfun->unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
406 /* Tell assembler to switch to unlikely-to-be-executed text section. */
409 unlikely_text_section (void)
413 if (!cfun->unlikely_text_section_name)
414 initialize_cold_section_name ();
416 return get_named_section (NULL, cfun->unlikely_text_section_name, 0);
419 return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
422 /* When called within a function context, return true if the function
423 has been assigned a cold text section and if SECT is that section.
424 When called outside a function context, return true if SECT is the
425 default cold section. */
428 unlikely_text_section_p (section *sect)
433 name = cfun->unlikely_text_section_name;
435 name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
439 && SECTION_STYLE (sect) == SECTION_NAMED
440 && strcmp (name, sect->named.name) == 0);
443 /* Return a section with a particular name and with whatever SECTION_*
444 flags section_type_flags deems appropriate. The name of the section
445 is taken from NAME if nonnull, otherwise it is taken from DECL's
446 DECL_SECTION_NAME. DECL is the decl associated with the section
447 (see the section comment for details) and RELOC is as for
448 section_type_flags. */
451 get_named_section (tree decl, const char *name, int reloc)
455 gcc_assert (!decl || DECL_P (decl));
457 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
459 flags = targetm.section_type_flags (decl, name, reloc);
461 return get_section (name, flags, decl);
464 /* If required, set DECL_SECTION_NAME to a unique name. */
467 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
468 int flag_function_or_data_sections)
470 if (DECL_SECTION_NAME (decl) == NULL_TREE
471 && targetm.have_named_sections
472 && (flag_function_or_data_sections
473 || DECL_ONE_ONLY (decl)))
474 targetm.asm_out.unique_section (decl, reloc);
477 #ifdef BSS_SECTION_ASM_OP
479 #ifdef ASM_OUTPUT_BSS
481 /* Utility function for ASM_OUTPUT_BSS for targets to use if
482 they don't support alignments in .bss.
483 ??? It is believed that this function will work in most cases so such
484 support is localized here. */
487 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
489 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
490 unsigned HOST_WIDE_INT rounded)
492 targetm.asm_out.globalize_label (file, name);
493 switch_to_section (bss_section);
494 #ifdef ASM_DECLARE_OBJECT_NAME
495 last_assemble_variable_decl = decl;
496 ASM_DECLARE_OBJECT_NAME (file, name, decl);
498 /* Standard thing is just output label for the object. */
499 ASM_OUTPUT_LABEL (file, name);
500 #endif /* ASM_DECLARE_OBJECT_NAME */
501 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
506 #ifdef ASM_OUTPUT_ALIGNED_BSS
508 /* Utility function for targets to use in implementing
509 ASM_OUTPUT_ALIGNED_BSS.
510 ??? It is believed that this function will work in most cases so such
511 support is localized here. */
514 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
515 const char *name, unsigned HOST_WIDE_INT size,
518 switch_to_section (bss_section);
519 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
520 #ifdef ASM_DECLARE_OBJECT_NAME
521 last_assemble_variable_decl = decl;
522 ASM_DECLARE_OBJECT_NAME (file, name, decl);
524 /* Standard thing is just output label for the object. */
525 ASM_OUTPUT_LABEL (file, name);
526 #endif /* ASM_DECLARE_OBJECT_NAME */
527 ASM_OUTPUT_SKIP (file, size ? size : 1);
532 #endif /* BSS_SECTION_ASM_OP */
534 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
535 /* Return the hot section for function DECL. Return text_section for
539 hot_function_section (tree decl)
541 if (decl != NULL_TREE
542 && DECL_SECTION_NAME (decl) != NULL_TREE
543 && targetm.have_named_sections)
544 return get_named_section (decl, NULL, 0);
550 /* Return the section for function DECL.
552 If DECL is NULL_TREE, return the text section. We can be passed
553 NULL_TREE under some circumstances by dbxout.c at least. */
556 function_section (tree decl)
560 if (first_function_block_is_cold)
563 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
564 if (decl != NULL_TREE
565 && DECL_SECTION_NAME (decl) != NULL_TREE)
566 return reloc ? unlikely_text_section ()
567 : get_named_section (decl, NULL, 0);
569 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
571 return reloc ? unlikely_text_section () : hot_function_section (decl);
576 current_function_section (void)
578 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
579 if (current_function_decl != NULL_TREE
580 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
581 return in_cold_section_p ? unlikely_text_section ()
582 : get_named_section (current_function_decl,
585 return targetm.asm_out.select_section (current_function_decl,
587 DECL_ALIGN (current_function_decl));
589 return (in_cold_section_p
590 ? unlikely_text_section ()
591 : hot_function_section (current_function_decl));
595 /* Return the read-only data section associated with function DECL. */
598 default_function_rodata_section (tree decl)
600 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
602 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
604 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
606 size_t len = strlen (name) + 3;
607 char* rname = alloca (len);
609 strcpy (rname, ".rodata");
610 strcat (rname, name + 5);
611 return get_section (rname, SECTION_LINKONCE, decl);
613 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
614 else if (DECL_ONE_ONLY (decl)
615 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
617 size_t len = strlen (name) + 1;
618 char *rname = alloca (len);
620 memcpy (rname, name, len);
622 return get_section (rname, SECTION_LINKONCE, decl);
624 /* For .text.foo we want to use .rodata.foo. */
625 else if (flag_function_sections && flag_data_sections
626 && strncmp (name, ".text.", 6) == 0)
628 size_t len = strlen (name) + 1;
629 char *rname = alloca (len + 2);
631 memcpy (rname, ".rodata", 7);
632 memcpy (rname + 7, name + 5, len - 5);
633 return get_section (rname, 0, decl);
637 return readonly_data_section;
640 /* Return the read-only data section associated with function DECL
641 for targets where that section should be always the single
642 readonly data section. */
645 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
647 return readonly_data_section;
650 /* Return the section to use for string merging. */
653 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
654 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
655 unsigned int flags ATTRIBUTE_UNUSED)
659 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
660 && TREE_CODE (decl) == STRING_CST
661 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
663 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
664 && TREE_STRING_LENGTH (decl) >= len)
666 enum machine_mode mode;
667 unsigned int modesize;
673 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
674 modesize = GET_MODE_BITSIZE (mode);
675 if (modesize >= 8 && modesize <= 256
676 && (modesize & (modesize - 1)) == 0)
678 if (align < modesize)
681 str = TREE_STRING_POINTER (decl);
682 unit = GET_MODE_SIZE (mode);
684 /* Check for embedded NUL characters. */
685 for (i = 0; i < len; i += unit)
687 for (j = 0; j < unit; j++)
688 if (str[i + j] != '\0')
695 sprintf (name, ".rodata.str%d.%d", modesize / 8,
697 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
698 return get_section (name, flags, NULL);
703 return readonly_data_section;
706 /* Return the section to use for constant merging. */
709 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
710 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
711 unsigned int flags ATTRIBUTE_UNUSED)
713 unsigned int modesize = GET_MODE_BITSIZE (mode);
715 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
721 && (align & (align - 1)) == 0)
725 sprintf (name, ".rodata.cst%d", (int) (align / 8));
726 flags |= (align / 8) | SECTION_MERGE;
727 return get_section (name, flags, NULL);
729 return readonly_data_section;
732 /* Given NAME, a putative register name, discard any customary prefixes. */
735 strip_reg_name (const char *name)
737 #ifdef REGISTER_PREFIX
738 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
739 name += strlen (REGISTER_PREFIX);
741 if (name[0] == '%' || name[0] == '#')
746 /* The user has asked for a DECL to have a particular name. Set (or
747 change) it in such a way that we don't prefix an underscore to
750 set_user_assembler_name (tree decl, const char *name)
752 char *starred = alloca (strlen (name) + 2);
754 strcpy (starred + 1, name);
755 change_decl_assembler_name (decl, get_identifier (starred));
756 SET_DECL_RTL (decl, NULL_RTX);
759 /* Decode an `asm' spec for a declaration as a register name.
760 Return the register number, or -1 if nothing specified,
761 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
762 or -3 if ASMSPEC is `cc' and is not recognized,
763 or -4 if ASMSPEC is `memory' and is not recognized.
764 Accept an exact spelling or a decimal number.
765 Prefixes such as % are optional. */
768 decode_reg_name (const char *asmspec)
774 /* Get rid of confusing prefixes. */
775 asmspec = strip_reg_name (asmspec);
777 /* Allow a decimal number as a "register name". */
778 for (i = strlen (asmspec) - 1; i >= 0; i--)
779 if (! ISDIGIT (asmspec[i]))
781 if (asmspec[0] != 0 && i < 0)
784 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
790 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
792 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
795 #ifdef ADDITIONAL_REGISTER_NAMES
797 static const struct { const char *const name; const int number; } table[]
798 = ADDITIONAL_REGISTER_NAMES;
800 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
802 && ! strcmp (asmspec, table[i].name))
803 return table[i].number;
805 #endif /* ADDITIONAL_REGISTER_NAMES */
807 if (!strcmp (asmspec, "memory"))
810 if (!strcmp (asmspec, "cc"))
819 /* Return true if DECL's initializer is suitable for a BSS section. */
822 bss_initializer_p (tree decl)
824 return (DECL_INITIAL (decl) == NULL
825 || DECL_INITIAL (decl) == error_mark_node
826 || (flag_zero_initialized_in_bss
827 /* Leave constant zeroes in .rodata so they
829 && !TREE_READONLY (decl)
830 && initializer_zerop (DECL_INITIAL (decl))));
833 /* Compute the alignment of variable specified by DECL.
834 DONT_OUTPUT_DATA is from assemble_variable. */
837 align_variable (tree decl, bool dont_output_data)
839 unsigned int align = DECL_ALIGN (decl);
841 /* In the case for initialing an array whose length isn't specified,
842 where we have not yet been able to do the layout,
843 figure out the proper alignment now. */
844 if (dont_output_data && DECL_SIZE (decl) == 0
845 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
846 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
848 /* Some object file formats have a maximum alignment which they support.
849 In particular, a.out format supports a maximum alignment of 4. */
850 if (align > MAX_OFILE_ALIGNMENT)
852 warning (0, "alignment of %q+D is greater than maximum object "
853 "file alignment. Using %d", decl,
854 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
855 align = MAX_OFILE_ALIGNMENT;
858 /* On some machines, it is good to increase alignment sometimes. */
859 if (! DECL_USER_ALIGN (decl))
861 #ifdef DATA_ALIGNMENT
862 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
864 #ifdef CONSTANT_ALIGNMENT
865 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
866 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
870 /* Reset the alignment in case we have made it tighter, so we can benefit
871 from it in get_pointer_alignment. */
872 DECL_ALIGN (decl) = align;
875 /* Return the section into which the given VAR_DECL or CONST_DECL
876 should be placed. PREFER_NOSWITCH_P is true if a noswitch
877 section should be used wherever possible. */
880 get_variable_section (tree decl, bool prefer_noswitch_p)
884 /* If the decl has been given an explicit section name, then it
885 isn't common, and shouldn't be handled as such. */
886 if (DECL_COMMON (decl) && DECL_SECTION_NAME (decl) == NULL)
888 if (DECL_THREAD_LOCAL_P (decl))
889 return tls_comm_section;
890 if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
894 if (DECL_INITIAL (decl) == error_mark_node)
895 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
896 else if (DECL_INITIAL (decl))
897 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
901 resolve_unique_section (decl, reloc, flag_data_sections);
902 if (IN_NAMED_SECTION (decl))
903 return get_named_section (decl, NULL, reloc);
905 if (!DECL_THREAD_LOCAL_P (decl)
906 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
907 && bss_initializer_p (decl))
909 if (!TREE_PUBLIC (decl))
910 return lcomm_section;
911 if (bss_noswitch_section)
912 return bss_noswitch_section;
915 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
918 /* Return the block into which object_block DECL should be placed. */
920 static struct object_block *
921 get_block_for_decl (tree decl)
925 if (TREE_CODE (decl) == VAR_DECL)
927 /* The object must be defined in this translation unit. */
928 if (DECL_EXTERNAL (decl))
931 /* There's no point using object blocks for something that is
932 isolated by definition. */
933 if (DECL_ONE_ONLY (decl))
937 /* We can only calculate block offsets if the decl has a known
939 if (DECL_SIZE_UNIT (decl) == NULL)
941 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
944 /* Find out which section should contain DECL. We cannot put it into
945 an object block if it requires a standalone definition. */
946 if (TREE_CODE (decl) == VAR_DECL)
947 align_variable (decl, 0);
948 sect = get_variable_section (decl, true);
949 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
952 return get_block_for_section (sect);
955 /* Make sure block symbol SYMBOL is in block BLOCK. */
958 change_symbol_block (rtx symbol, struct object_block *block)
960 if (block != SYMBOL_REF_BLOCK (symbol))
962 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
963 SYMBOL_REF_BLOCK (symbol) = block;
967 /* Return true if it is possible to put DECL in an object_block. */
970 use_blocks_for_decl_p (tree decl)
972 /* Only data DECLs can be placed into object blocks. */
973 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
976 /* Detect decls created by dw2_force_const_mem. Such decls are
977 special because DECL_INITIAL doesn't specify the decl's true value.
978 dw2_output_indirect_constants will instead call assemble_variable
979 with dont_output_data set to 1 and then print the contents itself. */
980 if (DECL_INITIAL (decl) == decl)
983 /* If this decl is an alias, then we don't want to emit a definition. */
984 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
990 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
991 have static storage duration. In other words, it should not be an
992 automatic variable, including PARM_DECLs.
994 There is, however, one exception: this function handles variables
995 explicitly placed in a particular register by the user.
997 This is never called for PARM_DECL nodes. */
1000 make_decl_rtl (tree decl)
1002 const char *name = 0;
1006 /* Check that we are not being given an automatic variable. */
1007 gcc_assert (TREE_CODE (decl) != PARM_DECL
1008 && TREE_CODE (decl) != RESULT_DECL);
1010 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1011 gcc_assert (TREE_CODE (decl) != VAR_DECL
1012 || TREE_STATIC (decl)
1013 || TREE_PUBLIC (decl)
1014 || DECL_EXTERNAL (decl)
1015 || DECL_REGISTER (decl));
1017 /* And that we were not given a type or a label. */
1018 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1019 && TREE_CODE (decl) != LABEL_DECL);
1021 /* For a duplicate declaration, we can be called twice on the
1022 same DECL node. Don't discard the RTL already made. */
1023 if (DECL_RTL_SET_P (decl))
1025 /* If the old RTL had the wrong mode, fix the mode. */
1026 x = DECL_RTL (decl);
1027 if (GET_MODE (x) != DECL_MODE (decl))
1028 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1030 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1033 /* ??? Another way to do this would be to maintain a hashed
1034 table of such critters. Instead of adding stuff to a DECL
1035 to give certain attributes to it, we could use an external
1036 hash map from DECL to set of attributes. */
1038 /* Let the target reassign the RTL if it wants.
1039 This is necessary, for example, when one machine specific
1040 decl attribute overrides another. */
1041 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1043 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1044 on the new decl information. */
1046 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1047 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1048 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1050 /* Make this function static known to the mudflap runtime. */
1051 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1052 mudflap_enqueue_decl (decl);
1057 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1059 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1060 && DECL_REGISTER (decl))
1062 error ("register name not specified for %q+D", decl);
1064 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1066 const char *asmspec = name+1;
1067 reg_number = decode_reg_name (asmspec);
1068 /* First detect errors in declaring global registers. */
1069 if (reg_number == -1)
1070 error ("register name not specified for %q+D", decl);
1071 else if (reg_number < 0)
1072 error ("invalid register name for %q+D", decl);
1073 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1074 error ("data type of %q+D isn%'t suitable for a register",
1076 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1077 error ("register specified for %q+D isn%'t suitable for data type",
1079 /* Now handle properly declared static register variables. */
1084 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1086 DECL_INITIAL (decl) = 0;
1087 error ("global register variable has initial value");
1089 if (TREE_THIS_VOLATILE (decl))
1090 warning (OPT_Wvolatile_register_var,
1091 "optimization may eliminate reads and/or "
1092 "writes to register variables");
1094 /* If the user specified one of the eliminables registers here,
1095 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1096 confused with that register and be eliminated. This usage is
1097 somewhat suspect... */
1099 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1100 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1101 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1103 if (TREE_STATIC (decl))
1105 /* Make this register global, so not usable for anything
1107 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1108 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1109 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1111 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1113 globalize_reg (reg_number + --nregs);
1116 /* As a register variable, it has no section. */
1120 /* Now handle ordinary static variables and functions (in memory).
1121 Also handle vars declared register invalidly. */
1122 else if (name[0] == '*')
1124 #ifdef REGISTER_PREFIX
1125 if (strlen (REGISTER_PREFIX) != 0)
1127 reg_number = decode_reg_name (name);
1128 if (reg_number >= 0 || reg_number == -3)
1129 error ("register name given for non-register variable %q+D", decl);
1134 /* Specifying a section attribute on a variable forces it into a
1135 non-.bss section, and thus it cannot be common. */
1136 if (TREE_CODE (decl) == VAR_DECL
1137 && DECL_SECTION_NAME (decl) != NULL_TREE
1138 && DECL_INITIAL (decl) == NULL_TREE
1139 && DECL_COMMON (decl))
1140 DECL_COMMON (decl) = 0;
1142 /* Variables can't be both common and weak. */
1143 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1144 DECL_COMMON (decl) = 0;
1146 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1147 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1149 x = gen_rtx_SYMBOL_REF (Pmode, name);
1150 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1151 SET_SYMBOL_REF_DECL (x, decl);
1153 x = gen_rtx_MEM (DECL_MODE (decl), x);
1154 if (TREE_CODE (decl) != FUNCTION_DECL)
1155 set_mem_attributes (x, decl, 1);
1156 SET_DECL_RTL (decl, x);
1158 /* Optionally set flags or add text to the name to record information
1159 such as that it is a function name.
1160 If the name is changed, the macro ASM_OUTPUT_LABELREF
1161 will have to know how to strip this information. */
1162 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1164 /* Make this function static known to the mudflap runtime. */
1165 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1166 mudflap_enqueue_decl (decl);
1169 /* Output a string of literal assembler code
1170 for an `asm' keyword used between functions. */
1173 assemble_asm (tree string)
1177 if (TREE_CODE (string) == ADDR_EXPR)
1178 string = TREE_OPERAND (string, 0);
1180 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1183 /* Record an element in the table of global destructors. SYMBOL is
1184 a SYMBOL_REF of the function to be called; PRIORITY is a number
1185 between 0 and MAX_INIT_PRIORITY. */
1188 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1189 int priority ATTRIBUTE_UNUSED)
1191 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1192 /* Tell GNU LD that this is part of the static destructor set.
1193 This will work for any system that uses stabs, most usefully
1195 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1196 dbxout_stab_value_label (XSTR (symbol, 0));
1198 sorry ("global destructors not supported on this target");
1203 default_named_section_asm_out_destructor (rtx symbol, int priority)
1205 const char *section = ".dtors";
1208 /* ??? This only works reliably with the GNU linker. */
1209 if (priority != DEFAULT_INIT_PRIORITY)
1211 sprintf (buf, ".dtors.%.5u",
1212 /* Invert the numbering so the linker puts us in the proper
1213 order; constructors are run from right to left, and the
1214 linker sorts in increasing order. */
1215 MAX_INIT_PRIORITY - priority);
1219 switch_to_section (get_section (section, SECTION_WRITE, NULL));
1220 assemble_align (POINTER_SIZE);
1221 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1224 #ifdef DTORS_SECTION_ASM_OP
1226 default_dtor_section_asm_out_destructor (rtx symbol,
1227 int priority ATTRIBUTE_UNUSED)
1229 switch_to_section (dtors_section);
1230 assemble_align (POINTER_SIZE);
1231 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1235 /* Likewise for global constructors. */
1238 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1239 int priority ATTRIBUTE_UNUSED)
1241 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1242 /* Tell GNU LD that this is part of the static destructor set.
1243 This will work for any system that uses stabs, most usefully
1245 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1246 dbxout_stab_value_label (XSTR (symbol, 0));
1248 sorry ("global constructors not supported on this target");
1253 default_named_section_asm_out_constructor (rtx symbol, int priority)
1255 const char *section = ".ctors";
1258 /* ??? This only works reliably with the GNU linker. */
1259 if (priority != DEFAULT_INIT_PRIORITY)
1261 sprintf (buf, ".ctors.%.5u",
1262 /* Invert the numbering so the linker puts us in the proper
1263 order; constructors are run from right to left, and the
1264 linker sorts in increasing order. */
1265 MAX_INIT_PRIORITY - priority);
1269 switch_to_section (get_section (section, SECTION_WRITE, NULL));
1270 assemble_align (POINTER_SIZE);
1271 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1274 #ifdef CTORS_SECTION_ASM_OP
1276 default_ctor_section_asm_out_constructor (rtx symbol,
1277 int priority ATTRIBUTE_UNUSED)
1279 switch_to_section (ctors_section);
1280 assemble_align (POINTER_SIZE);
1281 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1285 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1286 a nonzero value if the constant pool should be output before the
1287 start of the function, or a zero value if the pool should output
1288 after the end of the function. The default is to put it before the
1291 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1292 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1295 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1296 to be output to assembler.
1297 Set first_global_object_name and weak_global_object_name as appropriate. */
1300 notice_global_symbol (tree decl)
1302 const char **type = &first_global_object_name;
1304 if (first_global_object_name
1305 || !TREE_PUBLIC (decl)
1306 || DECL_EXTERNAL (decl)
1307 || !DECL_NAME (decl)
1308 || (TREE_CODE (decl) != FUNCTION_DECL
1309 && (TREE_CODE (decl) != VAR_DECL
1310 || (DECL_COMMON (decl)
1311 && (DECL_INITIAL (decl) == 0
1312 || DECL_INITIAL (decl) == error_mark_node))))
1313 || !MEM_P (DECL_RTL (decl)))
1316 /* We win when global object is found, but it is useful to know about weak
1317 symbol as well so we can produce nicer unique names. */
1318 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl))
1319 type = &weak_global_object_name;
1325 rtx decl_rtl = DECL_RTL (decl);
1327 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1328 name = ggc_strdup (p);
1334 /* Output assembler code for the constant pool of a function and associated
1335 with defining the name of the function. DECL describes the function.
1336 NAME is the function's name. For the constant pool, we use the current
1337 constant pool data. */
1340 assemble_start_function (tree decl, const char *fnname)
1343 char tmp_label[100];
1344 bool hot_label_written = false;
1346 cfun->unlikely_text_section_name = NULL;
1348 first_function_block_is_cold = false;
1349 if (flag_reorder_blocks_and_partition)
1351 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1352 cfun->hot_section_label = ggc_strdup (tmp_label);
1353 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1354 cfun->cold_section_label = ggc_strdup (tmp_label);
1355 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1356 cfun->hot_section_end_label = ggc_strdup (tmp_label);
1357 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1358 cfun->cold_section_end_label = ggc_strdup (tmp_label);
1363 cfun->hot_section_label = NULL;
1364 cfun->cold_section_label = NULL;
1365 cfun->hot_section_end_label = NULL;
1366 cfun->cold_section_end_label = NULL;
1369 /* The following code does not need preprocessing in the assembler. */
1373 if (CONSTANT_POOL_BEFORE_FUNCTION)
1374 output_constant_pool (fnname, decl);
1376 resolve_unique_section (decl, 0, flag_function_sections);
1378 /* Make sure the not and cold text (code) sections are properly
1379 aligned. This is necessary here in the case where the function
1380 has both hot and cold sections, because we don't want to re-set
1381 the alignment when the section switch happens mid-function. */
1383 if (flag_reorder_blocks_and_partition)
1385 switch_to_section (unlikely_text_section ());
1386 assemble_align (DECL_ALIGN (decl));
1387 ASM_OUTPUT_LABEL (asm_out_file, cfun->cold_section_label);
1389 /* When the function starts with a cold section, we need to explicitly
1390 align the hot section and write out the hot section label.
1391 But if the current function is a thunk, we do not have a CFG. */
1392 if (!current_function_is_thunk
1393 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1395 switch_to_section (text_section);
1396 assemble_align (DECL_ALIGN (decl));
1397 ASM_OUTPUT_LABEL (asm_out_file, cfun->hot_section_label);
1398 hot_label_written = true;
1399 first_function_block_is_cold = true;
1402 else if (DECL_SECTION_NAME (decl))
1404 /* Calls to function_section rely on first_function_block_is_cold
1405 being accurate. The first block may be cold even if we aren't
1406 doing partitioning, if the entire function was decided by
1407 choose_function_section (predict.c) to be cold. */
1409 initialize_cold_section_name ();
1411 if (cfun->unlikely_text_section_name
1412 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1413 cfun->unlikely_text_section_name) == 0)
1414 first_function_block_is_cold = true;
1417 in_cold_section_p = first_function_block_is_cold;
1419 /* Switch to the correct text section for the start of the function. */
1421 switch_to_section (function_section (decl));
1422 if (flag_reorder_blocks_and_partition
1423 && !hot_label_written)
1424 ASM_OUTPUT_LABEL (asm_out_file, cfun->hot_section_label);
1426 /* Tell assembler to move to target machine's alignment for functions. */
1427 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1430 ASM_OUTPUT_ALIGN (asm_out_file, align);
1433 /* Handle a user-specified function alignment.
1434 Note that we still need to align to DECL_ALIGN, as above,
1435 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1436 if (! DECL_USER_ALIGN (decl)
1437 && align_functions_log > align
1438 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1440 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1441 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1442 align_functions_log, align_functions - 1);
1444 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1448 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1449 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1452 (*debug_hooks->begin_function) (decl);
1454 /* Make function name accessible from other files, if appropriate. */
1456 if (TREE_PUBLIC (decl))
1458 notice_global_symbol (decl);
1460 globalize_decl (decl);
1462 maybe_assemble_visibility (decl);
1465 if (DECL_PRESERVE_P (decl))
1466 targetm.asm_out.mark_decl_preserved (fnname);
1468 /* Do any machine/system dependent processing of the function name. */
1469 #ifdef ASM_DECLARE_FUNCTION_NAME
1470 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1472 /* Standard thing is just output label for the function. */
1473 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1474 #endif /* ASM_DECLARE_FUNCTION_NAME */
1477 /* Output assembler code associated with defining the size of the
1478 function. DECL describes the function. NAME is the function's name. */
1481 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1483 #ifdef ASM_DECLARE_FUNCTION_SIZE
1484 /* We could have switched section in the middle of the function. */
1485 if (flag_reorder_blocks_and_partition)
1486 switch_to_section (function_section (decl));
1487 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1489 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1491 output_constant_pool (fnname, decl);
1492 switch_to_section (function_section (decl)); /* need to switch back */
1494 /* Output labels for end of hot/cold text sections (to be used by
1496 if (flag_reorder_blocks_and_partition)
1498 section *save_text_section;
1500 save_text_section = in_section;
1501 switch_to_section (unlikely_text_section ());
1502 ASM_OUTPUT_LABEL (asm_out_file, cfun->cold_section_end_label);
1503 if (first_function_block_is_cold)
1504 switch_to_section (text_section);
1506 switch_to_section (function_section (decl));
1507 ASM_OUTPUT_LABEL (asm_out_file, cfun->hot_section_end_label);
1508 switch_to_section (save_text_section);
1512 /* Assemble code to leave SIZE bytes of zeros. */
1515 assemble_zeros (unsigned HOST_WIDE_INT size)
1517 /* Do no output if -fsyntax-only. */
1518 if (flag_syntax_only)
1521 #ifdef ASM_NO_SKIP_IN_TEXT
1522 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1523 so we must output 0s explicitly in the text section. */
1524 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1526 unsigned HOST_WIDE_INT i;
1527 for (i = 0; i < size; i++)
1528 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1533 ASM_OUTPUT_SKIP (asm_out_file, size);
1536 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1539 assemble_align (int align)
1541 if (align > BITS_PER_UNIT)
1543 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1547 /* Assemble a string constant with the specified C string as contents. */
1550 assemble_string (const char *p, int size)
1555 /* If the string is very long, split it up. */
1559 int thissize = size - pos;
1560 if (thissize > maximum)
1563 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1571 /* A noswitch_section_callback for lcomm_section. */
1574 emit_local (tree decl ATTRIBUTE_UNUSED,
1575 const char *name ATTRIBUTE_UNUSED,
1576 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1577 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1579 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1580 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1581 size, DECL_ALIGN (decl));
1583 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1584 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1587 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1592 /* A noswitch_section_callback for bss_noswitch_section. */
1594 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1596 emit_bss (tree decl ATTRIBUTE_UNUSED,
1597 const char *name ATTRIBUTE_UNUSED,
1598 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1599 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1601 #if defined ASM_OUTPUT_ALIGNED_BSS
1602 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1605 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1611 /* A noswitch_section_callback for comm_section. */
1614 emit_common (tree decl ATTRIBUTE_UNUSED,
1615 const char *name ATTRIBUTE_UNUSED,
1616 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1617 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1619 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1620 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1621 size, DECL_ALIGN (decl));
1623 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1624 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1627 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1632 /* A noswitch_section_callback for tls_comm_section. */
1635 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1636 const char *name ATTRIBUTE_UNUSED,
1637 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1638 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1640 #ifdef ASM_OUTPUT_TLS_COMMON
1641 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1644 sorry ("thread-local COMMON data not implemented");
1649 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1650 NAME is the name of DECL's SYMBOL_REF. */
1653 assemble_noswitch_variable (tree decl, const char *name, section *sect)
1655 unsigned HOST_WIDE_INT size, rounded;
1657 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1660 /* Don't allocate zero bytes of common,
1661 since that means "undefined external" in the linker. */
1665 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1666 so that each uninitialized object starts on such a boundary. */
1667 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1668 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1669 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1671 if (!sect->noswitch.callback (decl, name, size, rounded)
1672 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1673 warning (0, "requested alignment for %q+D is greater than "
1674 "implemented alignment of %wu", decl, rounded);
1677 /* A subroutine of assemble_variable. Output the label and contents of
1678 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1679 is as for assemble_variable. */
1682 assemble_variable_contents (tree decl, const char *name,
1683 bool dont_output_data)
1685 /* Do any machine/system dependent processing of the object. */
1686 #ifdef ASM_DECLARE_OBJECT_NAME
1687 last_assemble_variable_decl = decl;
1688 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1690 /* Standard thing is just output label for the object. */
1691 ASM_OUTPUT_LABEL (asm_out_file, name);
1692 #endif /* ASM_DECLARE_OBJECT_NAME */
1694 if (!dont_output_data)
1696 if (DECL_INITIAL (decl)
1697 && DECL_INITIAL (decl) != error_mark_node
1698 && !initializer_zerop (DECL_INITIAL (decl)))
1699 /* Output the actual data. */
1700 output_constant (DECL_INITIAL (decl),
1701 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1704 /* Leave space for it. */
1705 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1709 /* Assemble everything that is needed for a variable or function declaration.
1710 Not used for automatic variables, and not used for function definitions.
1711 Should not be called for variables of incomplete structure type.
1713 TOP_LEVEL is nonzero if this variable has file scope.
1714 AT_END is nonzero if this is the special handling, at end of compilation,
1715 to define things that have had only tentative definitions.
1716 DONT_OUTPUT_DATA if nonzero means don't actually output the
1717 initial value (that will be done by the caller). */
1720 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1721 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1724 rtx decl_rtl, symbol;
1727 if (lang_hooks.decls.prepare_assemble_variable)
1728 lang_hooks.decls.prepare_assemble_variable (decl);
1730 last_assemble_variable_decl = 0;
1732 /* Normally no need to say anything here for external references,
1733 since assemble_external is called by the language-specific code
1734 when a declaration is first seen. */
1736 if (DECL_EXTERNAL (decl))
1739 /* Output no assembler code for a function declaration.
1740 Only definitions of functions output anything. */
1742 if (TREE_CODE (decl) == FUNCTION_DECL)
1745 /* Do nothing for global register variables. */
1746 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1748 TREE_ASM_WRITTEN (decl) = 1;
1752 /* If type was incomplete when the variable was declared,
1753 see if it is complete now. */
1755 if (DECL_SIZE (decl) == 0)
1756 layout_decl (decl, 0);
1758 /* Still incomplete => don't allocate it; treat the tentative defn
1759 (which is what it must have been) as an `extern' reference. */
1761 if (!dont_output_data && DECL_SIZE (decl) == 0)
1763 error ("storage size of %q+D isn%'t known", decl);
1764 TREE_ASM_WRITTEN (decl) = 1;
1768 /* The first declaration of a variable that comes through this function
1769 decides whether it is global (in C, has external linkage)
1770 or local (in C, has internal linkage). So do nothing more
1771 if this function has already run. */
1773 if (TREE_ASM_WRITTEN (decl))
1776 /* Make sure targetm.encode_section_info is invoked before we set
1778 decl_rtl = DECL_RTL (decl);
1780 TREE_ASM_WRITTEN (decl) = 1;
1782 /* Do no output if -fsyntax-only. */
1783 if (flag_syntax_only)
1788 if (! dont_output_data
1789 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1791 error ("size of variable %q+D is too large", decl);
1795 gcc_assert (MEM_P (decl_rtl));
1796 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
1797 symbol = XEXP (decl_rtl, 0);
1798 name = XSTR (symbol, 0);
1799 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1800 notice_global_symbol (decl);
1802 /* Compute the alignment of this data. */
1804 align_variable (decl, dont_output_data);
1805 set_mem_align (decl_rtl, DECL_ALIGN (decl));
1807 if (TREE_PUBLIC (decl))
1808 maybe_assemble_visibility (decl);
1810 if (DECL_PRESERVE_P (decl))
1811 targetm.asm_out.mark_decl_preserved (name);
1813 /* First make the assembler name(s) global if appropriate. */
1814 sect = get_variable_section (decl, false);
1815 if (TREE_PUBLIC (decl)
1817 && (sect->common.flags & SECTION_COMMON) == 0)
1818 globalize_decl (decl);
1820 /* Output any data that we will need to use the address of. */
1821 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
1822 output_addressed_constants (DECL_INITIAL (decl));
1824 /* dbxout.c needs to know this. */
1825 if (sect && (sect->common.flags & SECTION_CODE) != 0)
1826 DECL_IN_TEXT_SECTION (decl) = 1;
1828 /* If the decl is part of an object_block, make sure that the decl
1829 has been positioned within its block, but do not write out its
1830 definition yet. output_object_blocks will do that later. */
1831 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
1833 gcc_assert (!dont_output_data);
1834 place_block_symbol (symbol);
1836 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1837 assemble_noswitch_variable (decl, name, sect);
1840 switch_to_section (sect);
1841 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
1842 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
1843 assemble_variable_contents (decl, name, dont_output_data);
1847 /* Return 1 if type TYPE contains any pointers. */
1850 contains_pointers_p (tree type)
1852 switch (TREE_CODE (type))
1855 case REFERENCE_TYPE:
1856 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1857 so I'll play safe and return 1. */
1863 case QUAL_UNION_TYPE:
1866 /* For a type that has fields, see if the fields have pointers. */
1867 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1868 if (TREE_CODE (fields) == FIELD_DECL
1869 && contains_pointers_p (TREE_TYPE (fields)))
1875 /* An array type contains pointers if its element type does. */
1876 return contains_pointers_p (TREE_TYPE (type));
1883 /* In unit-at-a-time mode, we delay assemble_external processing until
1884 the compilation unit is finalized. This is the best we can do for
1885 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
1886 it all the way to final. See PR 17982 for further discussion. */
1887 static GTY(()) tree pending_assemble_externals;
1889 #ifdef ASM_OUTPUT_EXTERNAL
1890 /* True if DECL is a function decl for which no out-of-line copy exists.
1891 It is assumed that DECL's assembler name has been set. */
1894 incorporeal_function_p (tree decl)
1896 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1900 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
1901 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
1904 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1905 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
1911 /* Actually do the tests to determine if this is necessary, and invoke
1912 ASM_OUTPUT_EXTERNAL. */
1914 assemble_external_real (tree decl)
1916 rtx rtl = DECL_RTL (decl);
1918 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1919 && !SYMBOL_REF_USED (XEXP (rtl, 0))
1920 && !incorporeal_function_p (decl))
1922 /* Some systems do require some output. */
1923 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1924 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1930 process_pending_assemble_externals (void)
1932 #ifdef ASM_OUTPUT_EXTERNAL
1934 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
1935 assemble_external_real (TREE_VALUE (list));
1937 pending_assemble_externals = 0;
1941 /* Output something to declare an external symbol to the assembler.
1942 (Most assemblers don't need this, so we normally output nothing.)
1943 Do nothing if DECL is not external. */
1946 assemble_external (tree decl ATTRIBUTE_UNUSED)
1948 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1949 main body of this code is only rarely exercised. To provide some
1950 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1951 open. If it's not, we should not be calling this function. */
1952 gcc_assert (asm_out_file);
1954 #ifdef ASM_OUTPUT_EXTERNAL
1955 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
1958 /* We want to output external symbols at very last to check if they
1959 are references or not. */
1960 pending_assemble_externals = tree_cons (0, decl,
1961 pending_assemble_externals);
1965 /* Similar, for calling a library function FUN. */
1968 assemble_external_libcall (rtx fun)
1970 /* Declare library function name external when first used, if nec. */
1971 if (! SYMBOL_REF_USED (fun))
1973 SYMBOL_REF_USED (fun) = 1;
1974 targetm.asm_out.external_libcall (fun);
1978 /* Assemble a label named NAME. */
1981 assemble_label (const char *name)
1983 ASM_OUTPUT_LABEL (asm_out_file, name);
1986 /* Set the symbol_referenced flag for ID. */
1988 mark_referenced (tree id)
1990 TREE_SYMBOL_REFERENCED (id) = 1;
1993 /* Set the symbol_referenced flag for DECL and notify callgraph. */
1995 mark_decl_referenced (tree decl)
1997 if (TREE_CODE (decl) == FUNCTION_DECL)
1999 /* Extern inline functions don't become needed when referenced.
2000 If we know a method will be emitted in other TU and no new
2001 functions can be marked reachable, just use the external
2003 struct cgraph_node *node = cgraph_node (decl);
2004 if (!DECL_EXTERNAL (decl)
2005 && (!node->local.vtable_method || !cgraph_global_info_ready
2006 || !node->local.finalized))
2007 cgraph_mark_needed_node (node);
2009 else if (TREE_CODE (decl) == VAR_DECL)
2011 struct cgraph_varpool_node *node = cgraph_varpool_node (decl);
2012 cgraph_varpool_mark_needed_node (node);
2013 /* C++ frontend use mark_decl_references to force COMDAT variables
2014 to be output that might appear dead otherwise. */
2015 node->force_output = true;
2017 /* else do nothing - we can get various sorts of CST nodes here,
2018 which do not need to be marked. */
2022 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2023 until we find an identifier that is not itself a transparent alias.
2024 Modify the alias passed to it by reference (and all aliases on the
2025 way to the ultimate target), such that they do not have to be
2026 followed again, and return the ultimate target of the alias
2030 ultimate_transparent_alias_target (tree *alias)
2032 tree target = *alias;
2034 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2036 gcc_assert (TREE_CHAIN (target));
2037 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2038 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2039 && ! TREE_CHAIN (target));
2046 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2047 starts with a *, the rest of NAME is output verbatim. Otherwise
2048 NAME is transformed in a target-specific way (usually by the
2049 addition of an underscore). */
2052 assemble_name_raw (FILE *file, const char *name)
2055 fputs (&name[1], file);
2057 ASM_OUTPUT_LABELREF (file, name);
2060 /* Like assemble_name_raw, but should be used when NAME might refer to
2061 an entity that is also represented as a tree (like a function or
2062 variable). If NAME does refer to such an entity, that entity will
2063 be marked as referenced. */
2066 assemble_name (FILE *file, const char *name)
2068 const char *real_name;
2071 real_name = targetm.strip_name_encoding (name);
2073 id = maybe_get_identifier (real_name);
2078 mark_referenced (id);
2079 ultimate_transparent_alias_target (&id);
2081 name = IDENTIFIER_POINTER (id);
2082 gcc_assert (! TREE_CHAIN (id));
2085 assemble_name_raw (file, name);
2088 /* Allocate SIZE bytes writable static space with a gensym name
2089 and return an RTX to refer to its address. */
2092 assemble_static_space (unsigned HOST_WIDE_INT size)
2095 const char *namestring;
2098 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2100 namestring = ggc_strdup (name);
2102 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2103 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2105 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2106 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2109 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2110 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2113 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2114 so that each uninitialized object starts on such a boundary. */
2115 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2116 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2117 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2118 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2119 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2120 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2127 /* Assemble the static constant template for function entry trampolines.
2128 This is done at most once per compilation.
2129 Returns an RTX for the address of the template. */
2131 static GTY(()) rtx initial_trampoline;
2133 #ifdef TRAMPOLINE_TEMPLATE
2135 assemble_trampoline_template (void)
2142 if (initial_trampoline)
2143 return initial_trampoline;
2145 /* By default, put trampoline templates in read-only data section. */
2147 #ifdef TRAMPOLINE_SECTION
2148 switch_to_section (TRAMPOLINE_SECTION);
2150 switch_to_section (readonly_data_section);
2153 /* Write the assembler code to define one. */
2154 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2157 ASM_OUTPUT_ALIGN (asm_out_file, align);
2160 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2161 TRAMPOLINE_TEMPLATE (asm_out_file);
2163 /* Record the rtl to refer to it. */
2164 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2165 name = ggc_strdup (label);
2166 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2167 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2169 initial_trampoline = gen_rtx_MEM (BLKmode, symbol);
2170 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2172 return initial_trampoline;
2176 /* A and B are either alignments or offsets. Return the minimum alignment
2177 that may be assumed after adding the two together. */
2179 static inline unsigned
2180 min_align (unsigned int a, unsigned int b)
2182 return (a | b) & -(a | b);
2185 /* Return the assembler directive for creating a given kind of integer
2186 object. SIZE is the number of bytes in the object and ALIGNED_P
2187 indicates whether it is known to be aligned. Return NULL if the
2188 assembly dialect has no such directive.
2190 The returned string should be printed at the start of a new line and
2191 be followed immediately by the object's initial value. */
2194 integer_asm_op (int size, int aligned_p)
2196 struct asm_int_op *ops;
2199 ops = &targetm.asm_out.aligned_op;
2201 ops = &targetm.asm_out.unaligned_op;
2206 return targetm.asm_out.byte_op;
2220 /* Use directive OP to assemble an integer object X. Print OP at the
2221 start of the line, followed immediately by the value of X. */
2224 assemble_integer_with_op (const char *op, rtx x)
2226 fputs (op, asm_out_file);
2227 output_addr_const (asm_out_file, x);
2228 fputc ('\n', asm_out_file);
2231 /* The default implementation of the asm_out.integer target hook. */
2234 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2235 unsigned int size ATTRIBUTE_UNUSED,
2236 int aligned_p ATTRIBUTE_UNUSED)
2238 const char *op = integer_asm_op (size, aligned_p);
2239 /* Avoid GAS bugs for large values. Specifically negative values whose
2240 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2241 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2243 return op && (assemble_integer_with_op (op, x), true);
2246 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2247 the alignment of the integer in bits. Return 1 if we were able to output
2248 the constant, otherwise 0. We must be able to output the constant,
2249 if FORCE is nonzero. */
2252 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2256 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2258 /* See if the target hook can handle this kind of object. */
2259 if (targetm.asm_out.integer (x, size, aligned_p))
2262 /* If the object is a multi-byte one, try splitting it up. Split
2263 it into words it if is multi-word, otherwise split it into bytes. */
2266 enum machine_mode omode, imode;
2267 unsigned int subalign;
2268 unsigned int subsize, i;
2270 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2271 subalign = MIN (align, subsize * BITS_PER_UNIT);
2272 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
2273 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2275 for (i = 0; i < size; i += subsize)
2277 rtx partial = simplify_subreg (omode, x, imode, i);
2278 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2284 /* If we've printed some of it, but not all of it, there's no going
2289 gcc_assert (!force);
2295 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2297 long data[4] = {0, 0, 0, 0};
2299 int bitsize, nelts, nunits, units_per;
2301 /* This is hairy. We have a quantity of known size. real_to_target
2302 will put it into an array of *host* longs, 32 bits per element
2303 (even if long is more than 32 bits). We need to determine the
2304 number of array elements that are occupied (nelts) and the number
2305 of *target* min-addressable units that will be occupied in the
2306 object file (nunits). We cannot assume that 32 divides the
2307 mode's bitsize (size * BITS_PER_UNIT) evenly.
2309 size * BITS_PER_UNIT is used here to make sure that padding bits
2310 (which might appear at either end of the value; real_to_target
2311 will include the padding bits in its output array) are included. */
2313 nunits = GET_MODE_SIZE (mode);
2314 bitsize = nunits * BITS_PER_UNIT;
2315 nelts = CEIL (bitsize, 32);
2316 units_per = 32 / BITS_PER_UNIT;
2318 real_to_target (data, &d, mode);
2320 /* Put out the first word with the specified alignment. */
2321 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2322 nunits -= units_per;
2324 /* Subsequent words need only 32-bit alignment. */
2325 align = min_align (align, 32);
2327 for (i = 1; i < nelts; i++)
2329 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2330 nunits -= units_per;
2334 /* Given an expression EXP with a constant value,
2335 reduce it to the sum of an assembler symbol and an integer.
2336 Store them both in the structure *VALUE.
2337 EXP must be reducible. */
2339 struct addr_const GTY(())
2342 HOST_WIDE_INT offset;
2346 decode_addr_const (tree exp, struct addr_const *value)
2348 tree target = TREE_OPERAND (exp, 0);
2354 if (TREE_CODE (target) == COMPONENT_REF
2355 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2358 offset += int_byte_position (TREE_OPERAND (target, 1));
2359 target = TREE_OPERAND (target, 0);
2361 else if (TREE_CODE (target) == ARRAY_REF
2362 || TREE_CODE (target) == ARRAY_RANGE_REF)
2364 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2365 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2366 target = TREE_OPERAND (target, 0);
2372 switch (TREE_CODE (target))
2376 x = DECL_RTL (target);
2380 x = gen_rtx_MEM (FUNCTION_MODE,
2381 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2389 x = output_constant_def (target, 1);
2396 gcc_assert (MEM_P (x));
2400 value->offset = offset;
2403 /* Uniquize all constants that appear in memory.
2404 Each constant in memory thus far output is recorded
2405 in `const_desc_table'. */
2407 struct constant_descriptor_tree GTY(())
2409 /* A MEM for the constant. */
2412 /* The value of the constant. */
2415 /* Hash of value. Computing the hash from value each time
2416 hashfn is called can't work properly, as that means recursive
2417 use of the hash table during hash table expansion. */
2421 static GTY((param_is (struct constant_descriptor_tree)))
2422 htab_t const_desc_htab;
2424 static struct constant_descriptor_tree * build_constant_desc (tree);
2425 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2427 /* Compute a hash code for a constant expression. */
2430 const_desc_hash (const void *ptr)
2432 return ((struct constant_descriptor_tree *)ptr)->hash;
2436 const_hash_1 (const tree exp)
2441 enum tree_code code = TREE_CODE (exp);
2443 /* Either set P and LEN to the address and len of something to hash and
2444 exit the switch or return a value. */
2449 p = (char *) &TREE_INT_CST (exp);
2450 len = sizeof TREE_INT_CST (exp);
2454 return real_hash (TREE_REAL_CST_PTR (exp));
2457 p = TREE_STRING_POINTER (exp);
2458 len = TREE_STRING_LENGTH (exp);
2462 return (const_hash_1 (TREE_REALPART (exp)) * 5
2463 + const_hash_1 (TREE_IMAGPART (exp)));
2467 unsigned HOST_WIDE_INT idx;
2470 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2472 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2474 hi = hi * 603 + const_hash_1 (value);
2482 struct addr_const value;
2484 decode_addr_const (exp, &value);
2485 switch (GET_CODE (value.base))
2488 /* Don't hash the address of the SYMBOL_REF;
2489 only use the offset and the symbol name. */
2491 p = XSTR (value.base, 0);
2492 for (i = 0; p[i] != 0; i++)
2493 hi = ((hi * 613) + (unsigned) (p[i]));
2497 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2508 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2509 + const_hash_1 (TREE_OPERAND (exp, 1)));
2513 case NON_LVALUE_EXPR:
2514 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2517 /* A language specific constant. Just hash the code. */
2521 /* Compute hashing function. */
2523 for (i = 0; i < len; i++)
2524 hi = ((hi * 613) + (unsigned) (p[i]));
2529 /* Wrapper of compare_constant, for the htab interface. */
2531 const_desc_eq (const void *p1, const void *p2)
2533 const struct constant_descriptor_tree *c1 = p1;
2534 const struct constant_descriptor_tree *c2 = p2;
2535 if (c1->hash != c2->hash)
2537 return compare_constant (c1->value, c2->value);
2540 /* Compare t1 and t2, and return 1 only if they are known to result in
2541 the same bit pattern on output. */
2544 compare_constant (const tree t1, const tree t2)
2546 enum tree_code typecode;
2548 if (t1 == NULL_TREE)
2549 return t2 == NULL_TREE;
2550 if (t2 == NULL_TREE)
2553 if (TREE_CODE (t1) != TREE_CODE (t2))
2556 switch (TREE_CODE (t1))
2559 /* Integer constants are the same only if the same width of type. */
2560 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2562 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2564 return tree_int_cst_equal (t1, t2);
2567 /* Real constants are the same only if the same width of type. */
2568 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2571 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2574 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2577 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2578 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2579 TREE_STRING_LENGTH (t1)));
2582 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2583 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2587 VEC(constructor_elt, gc) *v1, *v2;
2588 unsigned HOST_WIDE_INT idx;
2590 typecode = TREE_CODE (TREE_TYPE (t1));
2591 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2594 if (typecode == ARRAY_TYPE)
2596 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2597 /* For arrays, check that the sizes all match. */
2598 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2600 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2605 /* For record and union constructors, require exact type
2607 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2611 v1 = CONSTRUCTOR_ELTS (t1);
2612 v2 = CONSTRUCTOR_ELTS (t2);
2613 if (VEC_length (constructor_elt, v1)
2614 != VEC_length (constructor_elt, v2))
2617 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
2619 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
2620 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
2622 /* Check that each value is the same... */
2623 if (!compare_constant (c1->value, c2->value))
2625 /* ... and that they apply to the same fields! */
2626 if (typecode == ARRAY_TYPE)
2628 if (!compare_constant (c1->index, c2->index))
2633 if (c1->index != c2->index)
2644 struct addr_const value1, value2;
2646 decode_addr_const (t1, &value1);
2647 decode_addr_const (t2, &value2);
2648 return (value1.offset == value2.offset
2649 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2655 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2656 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2660 case NON_LVALUE_EXPR:
2661 case VIEW_CONVERT_EXPR:
2662 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2667 nt1 = lang_hooks.expand_constant (t1);
2668 nt2 = lang_hooks.expand_constant (t2);
2669 if (nt1 != t1 || nt2 != t2)
2670 return compare_constant (nt1, nt2);
2679 /* Make a copy of the whole tree structure for a constant. This
2680 handles the same types of nodes that compare_constant handles. */
2683 copy_constant (tree exp)
2685 switch (TREE_CODE (exp))
2688 /* For ADDR_EXPR, we do not want to copy the decl whose address
2689 is requested. We do want to copy constants though. */
2690 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
2691 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2692 copy_constant (TREE_OPERAND (exp, 0)));
2694 return copy_node (exp);
2699 return copy_node (exp);
2702 return build_complex (TREE_TYPE (exp),
2703 copy_constant (TREE_REALPART (exp)),
2704 copy_constant (TREE_IMAGPART (exp)));
2708 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
2709 copy_constant (TREE_OPERAND (exp, 0)),
2710 copy_constant (TREE_OPERAND (exp, 1)));
2714 case NON_LVALUE_EXPR:
2715 case VIEW_CONVERT_EXPR:
2716 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2717 copy_constant (TREE_OPERAND (exp, 0)));
2721 tree copy = copy_node (exp);
2722 VEC(constructor_elt, gc) *v;
2723 unsigned HOST_WIDE_INT idx;
2724 tree purpose, value;
2726 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
2727 CONSTRUCTOR_ELTS (exp)));
2728 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
2730 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
2731 ce->index = purpose;
2732 ce->value = copy_constant (value);
2734 CONSTRUCTOR_ELTS (copy) = v;
2740 tree t = lang_hooks.expand_constant (exp);
2742 gcc_assert (t != exp);
2743 return copy_constant (t);
2748 /* Return the alignment of constant EXP in bits. */
2751 get_constant_alignment (tree exp)
2755 align = TYPE_ALIGN (TREE_TYPE (exp));
2756 #ifdef CONSTANT_ALIGNMENT
2757 align = CONSTANT_ALIGNMENT (exp, align);
2762 /* Return the section into which constant EXP should be placed. */
2765 get_constant_section (tree exp)
2767 if (IN_NAMED_SECTION (exp))
2768 return get_named_section (exp, NULL, compute_reloc_for_constant (exp));
2770 return targetm.asm_out.select_section (exp,
2771 compute_reloc_for_constant (exp),
2772 get_constant_alignment (exp));
2775 /* Return the size of constant EXP in bytes. */
2777 static HOST_WIDE_INT
2778 get_constant_size (tree exp)
2782 size = int_size_in_bytes (TREE_TYPE (exp));
2783 if (TREE_CODE (exp) == STRING_CST)
2784 size = MAX (TREE_STRING_LENGTH (exp), size);
2788 /* Subroutine of output_constant_def:
2789 No constant equal to EXP is known to have been output.
2790 Make a constant descriptor to enter EXP in the hash table.
2791 Assign the label number and construct RTL to refer to the
2792 constant's location in memory.
2793 Caller is responsible for updating the hash table. */
2795 static struct constant_descriptor_tree *
2796 build_constant_desc (tree exp)
2802 struct constant_descriptor_tree *desc;
2804 desc = ggc_alloc (sizeof (*desc));
2805 desc->value = copy_constant (exp);
2807 /* Propagate marked-ness to copied constant. */
2808 if (flag_mudflap && mf_marked_p (exp))
2809 mf_mark (desc->value);
2811 /* Create a string containing the label name, in LABEL. */
2812 labelno = const_labelno++;
2813 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2815 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2816 if (use_object_blocks_p ())
2818 section *sect = get_constant_section (exp);
2819 symbol = create_block_symbol (ggc_strdup (label),
2820 get_block_for_section (sect), -1);
2823 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2824 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
2825 SET_SYMBOL_REF_DECL (symbol, desc->value);
2826 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2828 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2829 set_mem_attributes (rtl, exp, 1);
2830 set_mem_alias_set (rtl, 0);
2831 set_mem_alias_set (rtl, const_alias_set);
2833 /* Set flags or add text to the name to record information, such as
2834 that it is a local symbol. If the name is changed, the macro
2835 ASM_OUTPUT_LABELREF will have to know how to strip this
2836 information. This call might invalidate our local variable
2837 SYMBOL; we can't use it afterward. */
2839 targetm.encode_section_info (exp, rtl, true);
2846 /* Return an rtx representing a reference to constant data in memory
2847 for the constant expression EXP.
2849 If assembler code for such a constant has already been output,
2850 return an rtx to refer to it.
2851 Otherwise, output such a constant in memory
2852 and generate an rtx for it.
2854 If DEFER is nonzero, this constant can be deferred and output only
2855 if referenced in the function after all optimizations.
2857 `const_desc_table' records which constants already have label strings. */
2860 output_constant_def (tree exp, int defer)
2862 struct constant_descriptor_tree *desc;
2863 struct constant_descriptor_tree key;
2866 /* Look up EXP in the table of constant descriptors. If we didn't find
2867 it, create a new one. */
2869 key.hash = const_hash_1 (exp);
2870 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
2875 desc = build_constant_desc (exp);
2876 desc->hash = key.hash;
2880 maybe_output_constant_def_contents (desc, defer);
2884 /* Subroutine of output_constant_def: Decide whether or not we need to
2885 output the constant DESC now, and if so, do it. */
2887 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
2890 rtx symbol = XEXP (desc->rtl, 0);
2891 tree exp = desc->value;
2893 if (flag_syntax_only)
2896 if (TREE_ASM_WRITTEN (exp))
2897 /* Already output; don't do it again. */
2900 /* We can always defer constants as long as the context allows
2904 /* Increment n_deferred_constants if it exists. It needs to be at
2905 least as large as the number of constants actually referred to
2906 by the function. If it's too small we'll stop looking too early
2907 and fail to emit constants; if it's too large we'll only look
2908 through the entire function when we could have stopped earlier. */
2910 n_deferred_constants++;
2914 output_constant_def_contents (symbol);
2917 /* Subroutine of output_constant_def_contents. Output the definition
2918 of constant EXP, which is pointed to by label LABEL. ALIGN is the
2919 constant's alignment in bits. */
2922 assemble_constant_contents (tree exp, const char *label, unsigned int align)
2926 size = get_constant_size (exp);
2928 /* Do any machine/system dependent processing of the constant. */
2929 #ifdef ASM_DECLARE_CONSTANT_NAME
2930 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
2932 /* Standard thing is just output label for the constant. */
2933 ASM_OUTPUT_LABEL (asm_out_file, label);
2934 #endif /* ASM_DECLARE_CONSTANT_NAME */
2936 /* Output the value of EXP. */
2937 output_constant (exp, size, align);
2940 /* We must output the constant data referred to by SYMBOL; do so. */
2943 output_constant_def_contents (rtx symbol)
2945 tree exp = SYMBOL_REF_DECL (symbol);
2948 /* Make sure any other constants whose addresses appear in EXP
2949 are assigned label numbers. */
2950 output_addressed_constants (exp);
2952 /* We are no longer deferring this constant. */
2953 TREE_ASM_WRITTEN (exp) = 1;
2955 /* If the constant is part of an object block, make sure that the
2956 decl has been positioned within its block, but do not write out
2957 its definition yet. output_object_blocks will do that later. */
2958 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2959 place_block_symbol (symbol);
2962 switch_to_section (get_constant_section (exp));
2963 align = get_constant_alignment (exp);
2964 if (align > BITS_PER_UNIT)
2965 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2966 assemble_constant_contents (exp, XSTR (symbol, 0), align);
2969 mudflap_enqueue_constant (exp);
2972 /* Look up EXP in the table of constant descriptors. Return the rtl
2973 if it has been emitted, else null. */
2976 lookup_constant_def (tree exp)
2978 struct constant_descriptor_tree *desc;
2979 struct constant_descriptor_tree key;
2982 key.hash = const_hash_1 (exp);
2983 desc = htab_find_with_hash (const_desc_htab, &key, key.hash);
2985 return (desc ? desc->rtl : NULL_RTX);
2988 /* Used in the hash tables to avoid outputting the same constant
2989 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2990 are output once per function, not once per file. */
2991 /* ??? Only a few targets need per-function constant pools. Most
2992 can use one per-file pool. Should add a targetm bit to tell the
2995 struct rtx_constant_pool GTY(())
2997 /* Pointers to first and last constant in pool, as ordered by offset. */
2998 struct constant_descriptor_rtx *first;
2999 struct constant_descriptor_rtx *last;
3001 /* Hash facility for making memory-constants from constant rtl-expressions.
3002 It is used on RISC machines where immediate integer arguments and
3003 constant addresses are restricted so that such constants must be stored
3005 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3007 /* Current offset in constant pool (does not include any
3008 machine-specific header). */
3009 HOST_WIDE_INT offset;
3012 struct constant_descriptor_rtx GTY((chain_next ("%h.next")))
3014 struct constant_descriptor_rtx *next;
3018 HOST_WIDE_INT offset;
3020 enum machine_mode mode;
3026 /* Hash and compare functions for const_rtx_htab. */
3029 const_desc_rtx_hash (const void *ptr)
3031 const struct constant_descriptor_rtx *desc = ptr;
3036 const_desc_rtx_eq (const void *a, const void *b)
3038 const struct constant_descriptor_rtx *x = a;
3039 const struct constant_descriptor_rtx *y = b;
3041 if (x->mode != y->mode)
3043 return rtx_equal_p (x->constant, y->constant);
3046 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3049 const_rtx_hash_1 (rtx *xp, void *data)
3051 unsigned HOST_WIDE_INT hwi;
3052 enum machine_mode mode;
3058 code = GET_CODE (x);
3059 mode = GET_MODE (x);
3060 h = (hashval_t) code * 1048573 + mode;
3068 const int shift = sizeof (hashval_t) * CHAR_BIT;
3069 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3072 h ^= (hashval_t) hwi;
3073 for (i = 1; i < n; ++i)
3076 h ^= (hashval_t) hwi;
3082 if (mode == VOIDmode)
3084 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3088 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3094 for (i = XVECLEN (x, 0); i-- > 0; )
3095 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3100 h ^= htab_hash_string (XSTR (x, 0));
3104 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3108 case UNSPEC_VOLATILE:
3109 h = h * 251 + XINT (x, 1);
3117 *hp = *hp * 509 + h;
3121 /* Compute a hash value for X, which should be a constant. */
3124 const_rtx_hash (rtx x)
3127 for_each_rtx (&x, const_rtx_hash_1, &h);
3132 /* Create and return a new rtx constant pool. */
3134 static struct rtx_constant_pool *
3135 create_constant_pool (void)
3137 struct rtx_constant_pool *pool;
3139 pool = ggc_alloc (sizeof (struct rtx_constant_pool));
3140 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3141 const_desc_rtx_eq, NULL);
3148 /* Initialize constant pool hashing for a new function. */
3151 init_varasm_status (struct function *f)
3153 struct varasm_status *p;
3155 p = ggc_alloc (sizeof (struct varasm_status));
3158 p->pool = create_constant_pool ();
3159 p->deferred_constants = 0;
3162 /* Given a MINUS expression, simplify it if both sides
3163 include the same symbol. */
3166 simplify_subtraction (rtx x)
3168 rtx r = simplify_rtx (x);
3172 /* Given a constant rtx X, make (or find) a memory constant for its value
3173 and return a MEM rtx to refer to it in memory. */
3176 force_const_mem (enum machine_mode mode, rtx x)
3178 struct constant_descriptor_rtx *desc, tmp;
3179 struct rtx_constant_pool *pool;
3186 /* If we're not allowed to drop X into the constant pool, don't. */
3187 if (targetm.cannot_force_const_mem (x))
3190 /* Record that this function has used a constant pool entry. */
3191 current_function_uses_const_pool = 1;
3193 /* Decide which pool to use. */
3194 pool = (targetm.use_blocks_for_constant_p (mode, x)
3195 ? shared_constant_pool
3196 : cfun->varasm->pool);
3198 /* Lookup the value in the hashtable. */
3201 hash = const_rtx_hash (x);
3202 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3205 /* If the constant was already present, return its memory. */
3207 return copy_rtx (desc->mem);
3209 /* Otherwise, create a new descriptor. */
3210 desc = ggc_alloc (sizeof (*desc));
3213 /* Align the location counter as required by EXP's data type. */
3214 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3215 #ifdef CONSTANT_ALIGNMENT
3217 tree type = lang_hooks.types.type_for_mode (mode, 0);
3218 if (type != NULL_TREE)
3219 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3223 pool->offset += (align / BITS_PER_UNIT) - 1;
3224 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3227 desc->constant = tmp.constant;
3228 desc->offset = pool->offset;
3231 desc->align = align;
3232 desc->labelno = const_labelno;
3235 pool->offset += GET_MODE_SIZE (mode);
3237 pool->last->next = desc;
3239 pool->first = pool->last = desc;
3242 /* Create a string containing the label name, in LABEL. */
3243 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3246 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3247 the constants pool. */
3248 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3250 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3251 symbol = create_block_symbol (ggc_strdup (label),
3252 get_block_for_section (sect), -1);
3255 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3257 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3258 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3259 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3261 /* Construct the MEM. */
3262 desc->mem = def = gen_const_mem (mode, symbol);
3263 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3264 set_mem_align (def, align);
3266 /* If we're dropping a label to the constant pool, make sure we
3268 if (GET_CODE (x) == LABEL_REF)
3269 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3271 return copy_rtx (def);
3274 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3277 get_pool_constant (rtx addr)
3279 return SYMBOL_REF_CONSTANT (addr)->constant;
3282 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3283 and whether it has been output or not. */
3286 get_pool_constant_mark (rtx addr, bool *pmarked)
3288 struct constant_descriptor_rtx *desc;
3290 desc = SYMBOL_REF_CONSTANT (addr);
3291 *pmarked = (desc->mark != 0);
3292 return desc->constant;
3295 /* Similar, return the mode. */
3298 get_pool_mode (rtx addr)
3300 return SYMBOL_REF_CONSTANT (addr)->mode;
3303 /* Return the size of the constant pool. */
3306 get_pool_size (void)
3308 return cfun->varasm->pool->offset;
3311 /* Worker function for output_constant_pool_1. Emit assembly for X
3312 in MODE with known alignment ALIGN. */
3315 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3317 switch (GET_MODE_CLASS (mode))
3320 case MODE_DECIMAL_FLOAT:
3324 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3325 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3326 assemble_real (r, mode, align);
3331 case MODE_PARTIAL_INT:
3332 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3335 case MODE_VECTOR_FLOAT:
3336 case MODE_VECTOR_INT:
3339 enum machine_mode submode = GET_MODE_INNER (mode);
3340 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3342 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3343 units = CONST_VECTOR_NUNITS (x);
3345 for (i = 0; i < units; i++)
3347 rtx elt = CONST_VECTOR_ELT (x, i);
3348 output_constant_pool_2 (submode, elt, i ? subalign : align);
3358 /* Worker function for output_constant_pool. Emit constant DESC,
3359 giving it ALIGN bits of alignment. */
3362 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3369 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3370 whose CODE_LABEL has been deleted. This can occur if a jump table
3371 is eliminated by optimization. If so, write a constant of zero
3372 instead. Note that this can also happen by turning the
3373 CODE_LABEL into a NOTE. */
3374 /* ??? This seems completely and utterly wrong. Certainly it's
3375 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3376 functioning even with INSN_DELETED_P and friends. */
3379 switch (GET_CODE (x))
3382 if (GET_CODE (XEXP (x, 0)) != PLUS
3383 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3385 tmp = XEXP (XEXP (x, 0), 0);
3390 gcc_assert (!INSN_DELETED_P (tmp));
3391 gcc_assert (!NOTE_P (tmp)
3392 || NOTE_LINE_NUMBER (tmp) != NOTE_INSN_DELETED);
3399 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3400 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3401 align, desc->labelno, done);
3404 assemble_align (align);
3406 /* Output the label. */
3407 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3409 /* Output the data. */
3410 output_constant_pool_2 (desc->mode, x, align);
3412 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3413 sections have proper size. */
3414 if (align > GET_MODE_BITSIZE (desc->mode)
3416 && (in_section->common.flags & SECTION_MERGE))
3417 assemble_align (align);
3419 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3425 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3426 to as used. Emit referenced deferred strings. This function can
3427 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3430 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3432 rtx x = *current_rtx;
3434 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3437 if (CONSTANT_POOL_ADDRESS_P (x))
3439 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3440 if (desc->mark == 0)
3443 for_each_rtx (&desc->constant, mark_constant, NULL);
3446 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3448 tree exp = SYMBOL_REF_DECL (x);
3449 if (!TREE_ASM_WRITTEN (exp))
3451 n_deferred_constants--;
3452 output_constant_def_contents (x);
3459 /* Look through appropriate parts of INSN, marking all entries in the
3460 constant pool which are actually being used. Entries that are only
3461 referenced by other constants are also marked as used. Emit
3462 deferred strings that are used. */
3465 mark_constants (rtx insn)
3470 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3471 insns, not any notes that may be attached. We don't want to mark
3472 a constant just because it happens to appear in a REG_EQUIV note. */
3473 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3475 rtx seq = PATTERN (insn);
3476 int i, n = XVECLEN (seq, 0);
3477 for (i = 0; i < n; ++i)
3479 rtx subinsn = XVECEXP (seq, 0, i);
3480 if (INSN_P (subinsn))
3481 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
3485 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
3488 /* Look through the instructions for this function, and mark all the
3489 entries in POOL which are actually being used. Emit deferred constants
3490 which have indeed been used. */
3493 mark_constant_pool (void)
3497 if (!current_function_uses_const_pool && n_deferred_constants == 0)
3500 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3501 mark_constants (insn);
3503 for (link = current_function_epilogue_delay_list;
3505 link = XEXP (link, 1))
3506 mark_constants (XEXP (link, 0));
3509 /* Write all the constants in POOL. */
3512 output_constant_pool_contents (struct rtx_constant_pool *pool)
3514 struct constant_descriptor_rtx *desc;
3516 for (desc = pool->first; desc ; desc = desc->next)
3519 /* If the constant is part of an object_block, make sure that
3520 the constant has been positioned within its block, but do not
3521 write out its definition yet. output_object_blocks will do
3523 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
3524 && SYMBOL_REF_BLOCK (desc->sym))
3525 place_block_symbol (desc->sym);
3528 switch_to_section (targetm.asm_out.select_rtx_section
3529 (desc->mode, desc->constant, desc->align));
3530 output_constant_pool_1 (desc, desc->align);
3535 /* Mark all constants that are used in the current function, then write
3536 out the function's private constant pool. */
3539 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3540 tree fndecl ATTRIBUTE_UNUSED)
3542 struct rtx_constant_pool *pool = cfun->varasm->pool;
3544 /* It is possible for gcc to call force_const_mem and then to later
3545 discard the instructions which refer to the constant. In such a
3546 case we do not need to output the constant. */
3547 mark_constant_pool ();
3549 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3550 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3553 output_constant_pool_contents (pool);
3555 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3556 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3560 /* Write the contents of the shared constant pool. */
3563 output_shared_constant_pool (void)
3565 output_constant_pool_contents (shared_constant_pool);
3568 /* Determine what kind of relocations EXP may need. */
3571 compute_reloc_for_constant (tree exp)
3573 int reloc = 0, reloc2;
3576 /* Give the front-end a chance to convert VALUE to something that
3577 looks more like a constant to the back-end. */
3578 exp = lang_hooks.expand_constant (exp);
3580 switch (TREE_CODE (exp))
3584 /* Go inside any operations that get_inner_reference can handle and see
3585 if what's inside is a constant: no need to do anything here for
3586 addresses of variables or functions. */
3587 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3588 tem = TREE_OPERAND (tem, 0))
3591 if (TREE_PUBLIC (tem))
3598 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3599 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3603 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3604 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3605 /* The difference of two local labels is computable at link time. */
3606 if (reloc == 1 && reloc2 == 1)
3614 case NON_LVALUE_EXPR:
3615 case VIEW_CONVERT_EXPR:
3616 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3621 unsigned HOST_WIDE_INT idx;
3622 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
3624 reloc |= compute_reloc_for_constant (tem);
3634 /* Find all the constants whose addresses are referenced inside of EXP,
3635 and make sure assembler code with a label has been output for each one.
3636 Indicate whether an ADDR_EXPR has been encountered. */
3639 output_addressed_constants (tree exp)
3643 /* Give the front-end a chance to convert VALUE to something that
3644 looks more like a constant to the back-end. */
3645 exp = lang_hooks.expand_constant (exp);
3647 switch (TREE_CODE (exp))
3651 /* Go inside any operations that get_inner_reference can handle and see
3652 if what's inside is a constant: no need to do anything here for
3653 addresses of variables or functions. */
3654 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3655 tem = TREE_OPERAND (tem, 0))
3658 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3659 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
3660 tem = DECL_INITIAL (tem);
3662 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
3663 output_constant_def (tem, 0);
3668 output_addressed_constants (TREE_OPERAND (exp, 1));
3673 case NON_LVALUE_EXPR:
3674 case VIEW_CONVERT_EXPR:
3675 output_addressed_constants (TREE_OPERAND (exp, 0));
3680 unsigned HOST_WIDE_INT idx;
3681 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
3683 output_addressed_constants (tem);
3692 /* Whether a constructor CTOR is a valid static constant initializer if all
3693 its elements are. This used to be internal to initializer_constant_valid_p
3694 and has been exposed to let other functions like categorize_ctor_elements
3695 evaluate the property while walking a constructor for other purposes. */
3698 constructor_static_from_elts_p (tree ctor)
3700 return (TREE_CONSTANT (ctor)
3701 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
3702 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
3703 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
3706 /* Return nonzero if VALUE is a valid constant-valued expression
3707 for use in initializing a static variable; one that can be an
3708 element of a "constant" initializer.
3710 Return null_pointer_node if the value is absolute;
3711 if it is relocatable, return the variable that determines the relocation.
3712 We assume that VALUE has been folded as much as possible;
3713 therefore, we do not need to check for such things as
3714 arithmetic-combinations of integers. */
3717 initializer_constant_valid_p (tree value, tree endtype)
3719 /* Give the front-end a chance to convert VALUE to something that
3720 looks more like a constant to the back-end. */
3721 value = lang_hooks.expand_constant (value);
3723 switch (TREE_CODE (value))
3726 if (constructor_static_from_elts_p (value))
3728 unsigned HOST_WIDE_INT idx;
3730 bool absolute = true;
3732 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
3735 reloc = initializer_constant_valid_p (elt, TREE_TYPE (elt));
3738 if (reloc != null_pointer_node)
3741 /* For a non-absolute relocation, there is no single
3742 variable that can be "the variable that determines the
3744 return absolute ? null_pointer_node : error_mark_node;
3747 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
3754 return null_pointer_node;
3758 value = staticp (TREE_OPERAND (value, 0));
3761 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to
3762 be a constant, this is old-skool offsetof-like nonsense. */
3763 if (TREE_CODE (value) == INDIRECT_REF
3764 && TREE_CONSTANT (TREE_OPERAND (value, 0)))
3765 return null_pointer_node;
3766 /* Taking the address of a nested function involves a trampoline. */
3767 if (TREE_CODE (value) == FUNCTION_DECL
3768 && ((decl_function_context (value)
3769 && !DECL_NO_STATIC_CHAIN (value))
3770 || DECL_DLLIMPORT_P (value)))
3772 /* "&{...}" requires a temporary to hold the constructed
3774 if (TREE_CODE (value) == CONSTRUCTOR)
3779 case VIEW_CONVERT_EXPR:
3780 case NON_LVALUE_EXPR:
3781 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3790 src = TREE_OPERAND (value, 0);
3791 src_type = TREE_TYPE (src);
3792 dest_type = TREE_TYPE (value);
3794 /* Allow conversions between pointer types, floating-point
3795 types, and offset types. */
3796 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
3797 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
3798 || (TREE_CODE (dest_type) == OFFSET_TYPE
3799 && TREE_CODE (src_type) == OFFSET_TYPE))
3800 return initializer_constant_valid_p (src, endtype);
3802 /* Allow length-preserving conversions between integer types. */
3803 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
3804 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
3805 return initializer_constant_valid_p (src, endtype);
3807 /* Allow conversions between other integer types only if
3809 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
3811 tree inner = initializer_constant_valid_p (src, endtype);
3812 if (inner == null_pointer_node)
3813 return null_pointer_node;
3817 /* Allow (int) &foo provided int is as wide as a pointer. */
3818 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
3819 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
3820 return initializer_constant_valid_p (src, endtype);
3822 /* Likewise conversions from int to pointers, but also allow
3823 conversions from 0. */
3824 if ((POINTER_TYPE_P (dest_type)
3825 || TREE_CODE (dest_type) == OFFSET_TYPE)
3826 && INTEGRAL_TYPE_P (src_type))
3828 if (TREE_CODE (src) == INTEGER_CST
3829 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
3830 return null_pointer_node;
3831 if (integer_zerop (src))
3832 return null_pointer_node;
3833 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
3834 return initializer_constant_valid_p (src, endtype);
3837 /* Allow conversions to struct or union types if the value
3839 if (TREE_CODE (dest_type) == RECORD_TYPE
3840 || TREE_CODE (dest_type) == UNION_TYPE)
3841 return initializer_constant_valid_p (src, endtype);
3846 if (! INTEGRAL_TYPE_P (endtype)
3847 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3849 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3851 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3853 /* If either term is absolute, use the other terms relocation. */
3854 if (valid0 == null_pointer_node)
3856 if (valid1 == null_pointer_node)
3862 if (! INTEGRAL_TYPE_P (endtype)
3863 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3865 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3867 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3869 /* Win if second argument is absolute. */
3870 if (valid1 == null_pointer_node)
3872 /* Win if both arguments have the same relocation.
3873 Then the value is absolute. */
3874 if (valid0 == valid1 && valid0 != 0)
3875 return null_pointer_node;
3877 /* Since GCC guarantees that string constants are unique in the
3878 generated code, a subtraction between two copies of the same
3879 constant string is absolute. */
3880 if (valid0 && TREE_CODE (valid0) == STRING_CST
3881 && valid1 && TREE_CODE (valid1) == STRING_CST
3882 && operand_equal_p (valid0, valid1, 1))
3883 return null_pointer_node;
3886 /* Support narrowing differences. */
3887 if (INTEGRAL_TYPE_P (endtype))
3891 op0 = TREE_OPERAND (value, 0);
3892 op1 = TREE_OPERAND (value, 1);
3894 /* Like STRIP_NOPS except allow the operand mode to widen.
3895 This works around a feature of fold that simplifies
3896 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3897 that the narrower operation is cheaper. */
3899 while (TREE_CODE (op0) == NOP_EXPR
3900 || TREE_CODE (op0) == CONVERT_EXPR
3901 || TREE_CODE (op0) == NON_LVALUE_EXPR)
3903 tree inner = TREE_OPERAND (op0, 0);
3904 if (inner == error_mark_node
3905 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3906 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3907 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3912 while (TREE_CODE (op1) == NOP_EXPR
3913 || TREE_CODE (op1) == CONVERT_EXPR
3914 || TREE_CODE (op1) == NON_LVALUE_EXPR)
3916 tree inner = TREE_OPERAND (op1, 0);
3917 if (inner == error_mark_node
3918 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3919 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3920 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3925 op0 = initializer_constant_valid_p (op0, endtype);
3926 op1 = initializer_constant_valid_p (op1, endtype);
3928 /* Both initializers must be known. */
3932 return null_pointer_node;
3934 /* Support differences between labels. */
3935 if (TREE_CODE (op0) == LABEL_DECL
3936 && TREE_CODE (op1) == LABEL_DECL)
3937 return null_pointer_node;
3939 if (TREE_CODE (op0) == STRING_CST
3940 && TREE_CODE (op1) == STRING_CST
3941 && operand_equal_p (op0, op1, 1))
3942 return null_pointer_node;
3954 /* Output assembler code for constant EXP to FILE, with no label.
3955 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3956 Assumes output_addressed_constants has been done on EXP already.
3958 Generate exactly SIZE bytes of assembler data, padding at the end
3959 with zeros if necessary. SIZE must always be specified.
3961 SIZE is important for structure constructors,
3962 since trailing members may have been omitted from the constructor.
3963 It is also important for initialization of arrays from string constants
3964 since the full length of the string constant might not be wanted.
3965 It is also needed for initialization of unions, where the initializer's
3966 type is just one member, and that may not be as long as the union.
3968 There a case in which we would fail to output exactly SIZE bytes:
3969 for a structure constructor that wants to produce more than SIZE bytes.
3970 But such constructors will never be generated for any possible input.
3972 ALIGN is the alignment of the data in bits. */
3975 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
3977 enum tree_code code;
3978 unsigned HOST_WIDE_INT thissize;
3980 /* Some front-ends use constants other than the standard language-independent
3981 varieties, but which may still be output directly. Give the front-end a
3982 chance to convert EXP to a language-independent representation. */
3983 exp = lang_hooks.expand_constant (exp);
3985 if (size == 0 || flag_syntax_only)
3988 /* See if we're trying to initialize a pointer in a non-default mode
3989 to the address of some declaration somewhere. If the target says
3990 the mode is valid for pointers, assume the target has a way of
3992 if (TREE_CODE (exp) == NOP_EXPR
3993 && POINTER_TYPE_P (TREE_TYPE (exp))
3994 && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp))))
3996 tree saved_type = TREE_TYPE (exp);
3998 /* Peel off any intermediate conversions-to-pointer for valid
4000 while (TREE_CODE (exp) == NOP_EXPR
4001 && POINTER_TYPE_P (TREE_TYPE (exp))
4002 && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp))))
4003 exp = TREE_OPERAND (exp, 0);
4005 /* If what we're left with is the address of something, we can
4006 convert the address to the final type and output it that
4008 if (TREE_CODE (exp) == ADDR_EXPR)
4009 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4010 /* Likewise for constant ints. */
4011 else if (TREE_CODE (exp) == INTEGER_CST)
4012 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4013 TREE_INT_CST_HIGH (exp));
4017 /* Eliminate any conversions since we'll be outputting the underlying
4019 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4020 || TREE_CODE (exp) == NON_LVALUE_EXPR
4021 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4023 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4024 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4026 /* Make sure eliminating the conversion is really a no-op, except with
4027 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4028 union types to allow for Ada unchecked unions. */
4029 if (type_size > op_size
4030 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4031 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4032 /* Keep the conversion. */
4035 exp = TREE_OPERAND (exp, 0);
4038 code = TREE_CODE (TREE_TYPE (exp));
4039 thissize = int_size_in_bytes (TREE_TYPE (exp));
4041 /* Give the front end another chance to expand constants. */
4042 exp = lang_hooks.expand_constant (exp);
4044 /* Allow a constructor with no elements for any data type.
4045 This means to fill the space with zeros. */
4046 if (TREE_CODE (exp) == CONSTRUCTOR
4047 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4049 assemble_zeros (size);
4053 if (TREE_CODE (exp) == FDESC_EXPR)
4055 #ifdef ASM_OUTPUT_FDESC
4056 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4057 tree decl = TREE_OPERAND (exp, 0);
4058 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4065 /* Now output the underlying data. If we've handling the padding, return.
4066 Otherwise, break and ensure SIZE is the size written. */
4073 case REFERENCE_TYPE:
4075 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4076 EXPAND_INITIALIZER),
4077 MIN (size, thissize), align, 0))
4078 error ("initializer for integer value is too complicated");
4082 if (TREE_CODE (exp) != REAL_CST)
4083 error ("initializer for floating value is not a floating constant");
4085 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4089 output_constant (TREE_REALPART (exp), thissize / 2, align);
4090 output_constant (TREE_IMAGPART (exp), thissize / 2,
4091 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4096 switch (TREE_CODE (exp))
4099 output_constructor (exp, size, align);
4102 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4104 assemble_string (TREE_STRING_POINTER (exp), thissize);
4111 unsigned int nalign;
4112 enum machine_mode inner;
4114 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4115 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4117 elt_size = GET_MODE_SIZE (inner);
4119 link = TREE_VECTOR_CST_ELTS (exp);
4120 output_constant (TREE_VALUE (link), elt_size, align);
4121 thissize = elt_size;
4122 while ((link = TREE_CHAIN (link)) != NULL)
4124 output_constant (TREE_VALUE (link), elt_size, nalign);
4125 thissize += elt_size;
4136 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4137 output_constructor (exp, size, align);
4147 if (size > thissize)
4148 assemble_zeros (size - thissize);
4152 /* Subroutine of output_constructor, used for computing the size of
4153 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4154 type with an unspecified upper bound. */
4156 static unsigned HOST_WIDE_INT
4157 array_size_for_constructor (tree val)
4160 unsigned HOST_WIDE_INT cnt;
4161 tree index, value, tmp;
4163 /* This code used to attempt to handle string constants that are not
4164 arrays of single-bytes, but nothing else does, so there's no point in
4166 if (TREE_CODE (val) == STRING_CST)
4167 return TREE_STRING_LENGTH (val);
4169 max_index = NULL_TREE;
4170 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4172 if (TREE_CODE (index) == RANGE_EXPR)
4173 index = TREE_OPERAND (index, 1);
4174 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4178 if (max_index == NULL_TREE)
4181 /* Compute the total number of array elements. */
4182 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4183 i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4184 fold_convert (sizetype, tmp));
4185 i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4187 /* Multiply by the array element unit size to find number of bytes. */
4188 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4190 return tree_low_cst (i, 1);
4193 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4194 Generate at least SIZE bytes, padding if necessary. */
4197 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
4200 tree type = TREE_TYPE (exp);
4203 /* Number of bytes output or skipped so far.
4204 In other words, current position within the constructor. */
4205 HOST_WIDE_INT total_bytes = 0;
4206 /* Nonzero means BYTE contains part of a byte, to be output. */
4207 int byte_buffer_in_use = 0;
4209 unsigned HOST_WIDE_INT cnt;
4210 constructor_elt *ce;
4212 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
4214 if (TREE_CODE (type) == RECORD_TYPE)
4215 field = TYPE_FIELDS (type);
4217 if (TREE_CODE (type) == ARRAY_TYPE
4218 && TYPE_DOMAIN (type) != 0)
4219 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4221 /* As LINK goes through the elements of the constant,
4222 FIELD goes through the structure fields, if the constant is a structure.
4223 if the constant is a union, then we override this,
4224 by getting the field from the TREE_LIST element.
4225 But the constant could also be an array. Then FIELD is zero.
4227 There is always a maximum of one element in the chain LINK for unions
4228 (even if the initializer in a source program incorrectly contains
4231 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
4232 cnt++, field = field ? TREE_CHAIN (field) : 0)
4234 tree val = ce->value;
4237 /* The element in a union constructor specifies the proper field
4239 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4240 || TREE_CODE (type) == QUAL_UNION_TYPE)
4244 else if (TREE_CODE (type) == ARRAY_TYPE)
4247 #ifdef ASM_COMMENT_START
4248 if (field && flag_verbose_asm)
4249 fprintf (asm_out_file, "%s %s:\n",
4252 ? IDENTIFIER_POINTER (DECL_NAME (field))
4256 /* Eliminate the marker that makes a cast not be an lvalue. */
4260 if (index && TREE_CODE (index) == RANGE_EXPR)
4262 unsigned HOST_WIDE_INT fieldsize
4263 = int_size_in_bytes (TREE_TYPE (type));
4264 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4265 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4266 HOST_WIDE_INT index;
4267 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4269 for (index = lo_index; index <= hi_index; index++)
4271 /* Output the element's initial value. */
4273 assemble_zeros (fieldsize);
4275 output_constant (val, fieldsize, align2);
4277 /* Count its size. */
4278 total_bytes += fieldsize;
4281 else if (field == 0 || !DECL_BIT_FIELD (field))
4283 /* An element that is not a bit-field. */
4285 unsigned HOST_WIDE_INT fieldsize;
4286 /* Since this structure is static,
4287 we know the positions are constant. */
4288 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4289 unsigned int align2;
4292 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4293 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4295 /* Output any buffered-up bit-fields preceding this element. */
4296 if (byte_buffer_in_use)
4298 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4300 byte_buffer_in_use = 0;
4303 /* Advance to offset of this element.
4304 Note no alignment needed in an array, since that is guaranteed
4305 if each element has the proper size. */
4306 if ((field != 0 || index != 0) && pos != total_bytes)
4308 gcc_assert (pos >= total_bytes);
4309 assemble_zeros (pos - total_bytes);
4313 /* Find the alignment of this element. */
4314 align2 = min_align (align, BITS_PER_UNIT * pos);
4316 /* Determine size this element should occupy. */
4321 /* If this is an array with an unspecified upper bound,
4322 the initializer determines the size. */
4323 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4324 but we cannot do this until the deprecated support for
4325 initializing zero-length array members is removed. */
4326 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4327 && TYPE_DOMAIN (TREE_TYPE (field))
4328 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4330 fieldsize = array_size_for_constructor (val);
4331 /* Given a non-empty initialization, this field had
4333 gcc_assert (!fieldsize || !TREE_CHAIN (field));
4335 else if (DECL_SIZE_UNIT (field))
4337 /* ??? This can't be right. If the decl size overflows
4338 a host integer we will silently emit no data. */
4339 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4340 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4344 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4346 /* Output the element's initial value. */
4348 assemble_zeros (fieldsize);
4350 output_constant (val, fieldsize, align2);
4352 /* Count its size. */
4353 total_bytes += fieldsize;
4355 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4356 error ("invalid initial value for member %qs",
4357 IDENTIFIER_POINTER (DECL_NAME (field)));
4360 /* Element that is a bit-field. */
4362 HOST_WIDE_INT next_offset = int_bit_position (field);
4363 HOST_WIDE_INT end_offset
4364 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4367 val = integer_zero_node;
4369 /* If this field does not start in this (or, next) byte,
4371 if (next_offset / BITS_PER_UNIT != total_bytes)
4373 /* Output remnant of any bit field in previous bytes. */
4374 if (byte_buffer_in_use)
4376 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4378 byte_buffer_in_use = 0;
4381 /* If still not at proper byte, advance to there. */
4382 if (next_offset / BITS_PER_UNIT != total_bytes)
4384 gcc_assert (next_offset / BITS_PER_UNIT >= total_bytes);
4385 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4386 total_bytes = next_offset / BITS_PER_UNIT;
4390 if (! byte_buffer_in_use)
4393 /* We must split the element into pieces that fall within
4394 separate bytes, and combine each byte with previous or
4395 following bit-fields. */
4397 /* next_offset is the offset n fbits from the beginning of
4398 the structure to the next bit of this element to be processed.
4399 end_offset is the offset of the first bit past the end of
4401 while (next_offset < end_offset)
4405 HOST_WIDE_INT value;
4406 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4407 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4409 /* Advance from byte to byte
4410 within this element when necessary. */
4411 while (next_byte != total_bytes)
4413 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4418 /* Number of bits we can process at once
4419 (all part of the same byte). */
4420 this_time = MIN (end_offset - next_offset,
4421 BITS_PER_UNIT - next_bit);
4422 if (BYTES_BIG_ENDIAN)
4424 /* On big-endian machine, take the most significant bits
4425 first (of the bits that are significant)
4426 and put them into bytes from the most significant end. */
4427 shift = end_offset - next_offset - this_time;
4429 /* Don't try to take a bunch of bits that cross
4430 the word boundary in the INTEGER_CST. We can
4431 only select bits from the LOW or HIGH part
4433 if (shift < HOST_BITS_PER_WIDE_INT
4434 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4436 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4437 shift = HOST_BITS_PER_WIDE_INT;
4440 /* Now get the bits from the appropriate constant word. */
4441 if (shift < HOST_BITS_PER_WIDE_INT)
4442 value = TREE_INT_CST_LOW (val);
4445 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4446 value = TREE_INT_CST_HIGH (val);
4447 shift -= HOST_BITS_PER_WIDE_INT;
4450 /* Get the result. This works only when:
4451 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4452 byte |= (((value >> shift)
4453 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4454 << (BITS_PER_UNIT - this_time - next_bit));
4458 /* On little-endian machines,
4459 take first the least significant bits of the value
4460 and pack them starting at the least significant
4461 bits of the bytes. */
4462 shift = next_offset - int_bit_position (field);
4464 /* Don't try to take a bunch of bits that cross
4465 the word boundary in the INTEGER_CST. We can
4466 only select bits from the LOW or HIGH part
4468 if (shift < HOST_BITS_PER_WIDE_INT
4469 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4470 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4472 /* Now get the bits from the appropriate constant word. */
4473 if (shift < HOST_BITS_PER_WIDE_INT)
4474 value = TREE_INT_CST_LOW (val);
4477 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4478 value = TREE_INT_CST_HIGH (val);
4479 shift -= HOST_BITS_PER_WIDE_INT;
4482 /* Get the result. This works only when:
4483 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4484 byte |= (((value >> shift)
4485 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4489 next_offset += this_time;
4490 byte_buffer_in_use = 1;
4495 if (byte_buffer_in_use)
4497 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4501 if ((unsigned HOST_WIDE_INT)total_bytes < size)
4502 assemble_zeros (size - total_bytes);
4505 /* This TREE_LIST contains any weak symbol declarations waiting
4507 static GTY(()) tree weak_decls;
4509 /* Mark DECL as weak. */
4512 mark_weak (tree decl)
4514 DECL_WEAK (decl) = 1;
4516 if (DECL_RTL_SET_P (decl)
4517 && MEM_P (DECL_RTL (decl))
4518 && XEXP (DECL_RTL (decl), 0)
4519 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4520 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4523 /* Merge weak status between NEWDECL and OLDDECL. */
4526 merge_weak (tree newdecl, tree olddecl)
4528 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4530 if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
4533 /* We put the NEWDECL on the weak_decls list at some point
4534 and OLDDECL as well. Keep just OLDDECL on the list. */
4535 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
4536 if (TREE_VALUE (*pwd) == newdecl)
4538 *pwd = TREE_CHAIN (*pwd);
4545 if (DECL_WEAK (newdecl))
4549 /* NEWDECL is weak, but OLDDECL is not. */
4551 /* If we already output the OLDDECL, we're in trouble; we can't
4552 go back and make it weak. This error cannot caught in
4553 declare_weak because the NEWDECL and OLDDECL was not yet
4554 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4555 if (TREE_ASM_WRITTEN (olddecl))
4556 error ("weak declaration of %q+D must precede definition",
4559 /* If we've already generated rtl referencing OLDDECL, we may
4560 have done so in a way that will not function properly with
4562 else if (TREE_USED (olddecl)
4563 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4564 warning (0, "weak declaration of %q+D after first use results "
4565 "in unspecified behavior", newdecl);
4569 /* We put the NEWDECL on the weak_decls list at some point.
4570 Replace it with the OLDDECL. */
4571 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4572 if (TREE_VALUE (wd) == newdecl)
4574 TREE_VALUE (wd) = olddecl;
4577 /* We may not find the entry on the list. If NEWDECL is a
4578 weak alias, then we will have already called
4579 globalize_decl to remove the entry; in that case, we do
4580 not need to do anything. */
4583 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4584 mark_weak (olddecl);
4587 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4588 weak. Just update NEWDECL to indicate that it's weak too. */
4589 mark_weak (newdecl);
4592 /* Declare DECL to be a weak symbol. */
4595 declare_weak (tree decl)
4597 if (! TREE_PUBLIC (decl))
4598 error ("weak declaration of %q+D must be public", decl);
4599 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4600 error ("weak declaration of %q+D must precede definition", decl);
4601 else if (SUPPORTS_WEAK)
4603 if (! DECL_WEAK (decl))
4604 weak_decls = tree_cons (NULL, decl, weak_decls);
4607 warning (0, "weak declaration of %q+D not supported", decl);
4613 weak_finish_1 (tree decl)
4615 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4616 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4619 if (! TREE_USED (decl))
4622 #ifdef ASM_WEAKEN_DECL
4623 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4625 #ifdef ASM_WEAKEN_LABEL
4626 ASM_WEAKEN_LABEL (asm_out_file, name);
4628 #ifdef ASM_OUTPUT_WEAK_ALIAS
4630 static bool warn_once = 0;
4633 warning (0, "only weak aliases are supported in this configuration");
4643 /* This TREE_LIST contains weakref targets. */
4645 static GTY(()) tree weakref_targets;
4647 /* Forward declaration. */
4648 static tree find_decl_and_mark_needed (tree decl, tree target);
4650 /* Emit any pending weak declarations. */
4657 for (t = weakref_targets; t; t = TREE_CHAIN (t))
4659 tree alias_decl = TREE_PURPOSE (t);
4660 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
4662 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
4663 /* Remove alias_decl from the weak list, but leave entries for
4664 the target alone. */
4666 #ifndef ASM_OUTPUT_WEAKREF
4667 else if (! TREE_SYMBOL_REFERENCED (target))
4669 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
4670 defined, otherwise we and weak_finish_1 would use a
4671 different macros. */
4672 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
4673 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
4675 tree decl = find_decl_and_mark_needed (alias_decl, target);
4679 decl = build_decl (TREE_CODE (alias_decl), target,
4680 TREE_TYPE (alias_decl));
4682 DECL_EXTERNAL (decl) = 1;
4683 TREE_PUBLIC (decl) = 1;
4684 DECL_ARTIFICIAL (decl) = 1;
4685 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
4686 TREE_USED (decl) = 1;
4689 weak_finish_1 (decl);
4698 /* Remove the alias and the target from the pending weak list
4699 so that we do not emit any .weak directives for the former,
4700 nor multiple .weak directives for the latter. */
4701 for (p = &weak_decls; (t2 = *p) ; )
4703 if (TREE_VALUE (t2) == alias_decl
4704 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
4705 *p = TREE_CHAIN (t2);
4707 p = &TREE_CHAIN (t2);
4710 /* Remove other weakrefs to the same target, to speed things up. */
4711 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
4713 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
4714 *p = TREE_CHAIN (t2);
4716 p = &TREE_CHAIN (t2);
4721 for (t = weak_decls; t; t = TREE_CHAIN (t))
4723 tree decl = TREE_VALUE (t);
4725 weak_finish_1 (decl);
4729 /* Emit the assembly bits to indicate that DECL is globally visible. */
4732 globalize_decl (tree decl)
4734 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4736 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4737 if (DECL_WEAK (decl))
4741 #ifdef ASM_WEAKEN_DECL
4742 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4744 ASM_WEAKEN_LABEL (asm_out_file, name);
4747 /* Remove this function from the pending weak list so that
4748 we do not emit multiple .weak directives for it. */
4749 for (p = &weak_decls; (t = *p) ; )
4751 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4752 *p = TREE_CHAIN (t);
4754 p = &TREE_CHAIN (t);
4757 /* Remove weakrefs to the same target from the pending weakref
4758 list, for the same reason. */
4759 for (p = &weakref_targets; (t = *p) ; )
4761 if (DECL_ASSEMBLER_NAME (decl)
4762 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
4763 *p = TREE_CHAIN (t);
4765 p = &TREE_CHAIN (t);
4770 #elif defined(ASM_MAKE_LABEL_LINKONCE)
4771 if (DECL_ONE_ONLY (decl))
4772 ASM_MAKE_LABEL_LINKONCE (asm_out_file, name);
4775 targetm.asm_out.globalize_label (asm_out_file, name);
4778 /* We have to be able to tell cgraph about the needed-ness of the target
4779 of an alias. This requires that the decl have been defined. Aliases
4780 that precede their definition have to be queued for later processing. */
4782 typedef struct alias_pair GTY(())
4788 /* Define gc'd vector type. */
4789 DEF_VEC_O(alias_pair);
4790 DEF_VEC_ALLOC_O(alias_pair,gc);
4792 static GTY(()) VEC(alias_pair,gc) *alias_pairs;
4794 /* Given an assembly name, find the decl it is associated with. At the
4795 same time, mark it needed for cgraph. */
4798 find_decl_and_mark_needed (tree decl, tree target)
4800 struct cgraph_node *fnode = NULL;
4801 struct cgraph_varpool_node *vnode = NULL;
4803 if (TREE_CODE (decl) == FUNCTION_DECL)
4805 fnode = cgraph_node_for_asm (target);
4807 vnode = cgraph_varpool_node_for_asm (target);
4811 vnode = cgraph_varpool_node_for_asm (target);
4813 fnode = cgraph_node_for_asm (target);
4818 /* We can't mark function nodes as used after cgraph global info
4819 is finished. This wouldn't generally be necessary, but C++
4820 virtual table thunks are introduced late in the game and
4821 might seem like they need marking, although in fact they
4823 if (! cgraph_global_info_ready)
4824 cgraph_mark_needed_node (fnode);
4829 cgraph_varpool_mark_needed_node (vnode);
4836 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
4837 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
4838 tree node is DECL to have the value of the tree node TARGET. */
4841 do_assemble_alias (tree decl, tree target)
4843 if (TREE_ASM_WRITTEN (decl))
4846 TREE_ASM_WRITTEN (decl) = 1;
4847 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4849 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
4851 ultimate_transparent_alias_target (&target);
4853 if (!TREE_SYMBOL_REFERENCED (target))
4854 weakref_targets = tree_cons (decl, target, weakref_targets);
4856 #ifdef ASM_OUTPUT_WEAKREF
4857 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
4858 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
4859 IDENTIFIER_POINTER (target));
4863 error ("%Jweakref is not supported in this configuration", decl);
4870 #ifdef ASM_OUTPUT_DEF
4871 /* Make name accessible from other files, if appropriate. */
4873 if (TREE_PUBLIC (decl))
4875 globalize_decl (decl);
4876 maybe_assemble_visibility (decl);
4879 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
4880 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4882 ASM_OUTPUT_DEF (asm_out_file,
4883 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
4884 IDENTIFIER_POINTER (target));
4886 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4891 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4892 # ifdef ASM_WEAKEN_DECL
4893 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4895 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4897 /* Remove this function from the pending weak list so that
4898 we do not emit multiple .weak directives for it. */
4899 for (p = &weak_decls; (t = *p) ; )
4900 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4901 *p = TREE_CHAIN (t);
4903 p = &TREE_CHAIN (t);
4905 /* Remove weakrefs to the same target from the pending weakref
4906 list, for the same reason. */
4907 for (p = &weakref_targets; (t = *p) ; )
4909 if (DECL_ASSEMBLER_NAME (decl)
4910 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
4911 *p = TREE_CHAIN (t);
4913 p = &TREE_CHAIN (t);
4919 /* First pass of completing pending aliases. Make sure that cgraph knows
4920 which symbols will be required. */
4923 finish_aliases_1 (void)
4928 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
4932 target_decl = find_decl_and_mark_needed (p->decl, p->target);
4933 if (target_decl == NULL)
4935 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
4936 error ("%q+D aliased to undefined symbol %qs",
4937 p->decl, IDENTIFIER_POINTER (p->target));
4939 else if (DECL_EXTERNAL (target_decl)
4940 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
4941 error ("%q+D aliased to external symbol %qs",
4942 p->decl, IDENTIFIER_POINTER (p->target));
4946 /* Second pass of completing pending aliases. Emit the actual assembly.
4947 This happens at the end of compilation and thus it is assured that the
4948 target symbol has been emitted. */
4951 finish_aliases_2 (void)
4956 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
4957 do_assemble_alias (p->decl, p->target);
4959 VEC_truncate (alias_pair, alias_pairs, 0);
4962 /* Emit an assembler directive to make the symbol for DECL an alias to
4963 the symbol for TARGET. */
4966 assemble_alias (tree decl, tree target)
4969 bool is_weakref = false;
4971 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
4973 tree alias = DECL_ASSEMBLER_NAME (decl);
4977 ultimate_transparent_alias_target (&target);
4979 if (alias == target)
4980 error ("weakref %q+D ultimately targets itself", decl);
4983 #ifndef ASM_OUTPUT_WEAKREF
4984 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
4985 TREE_CHAIN (alias) = target;
4988 if (TREE_PUBLIC (decl))
4989 error ("weakref %q+D must have static linkage", decl);
4993 #if !defined (ASM_OUTPUT_DEF)
4994 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
4995 error ("%Jalias definitions not supported in this configuration", decl);
4998 if (!DECL_WEAK (decl))
5000 error ("%Jonly weak aliases are supported in this configuration", decl);
5007 /* We must force creation of DECL_RTL for debug info generation, even though
5008 we don't use it here. */
5009 make_decl_rtl (decl);
5010 TREE_USED (decl) = 1;
5012 /* A quirk of the initial implementation of aliases required that the user
5013 add "extern" to all of them. Which is silly, but now historical. Do
5014 note that the symbol is in fact locally defined. */
5016 DECL_EXTERNAL (decl) = 0;
5018 /* Allow aliases to aliases. */
5019 if (TREE_CODE (decl) == FUNCTION_DECL)
5020 cgraph_node (decl)->alias = true;
5022 cgraph_varpool_node (decl)->alias = true;
5024 /* If the target has already been emitted, we don't have to queue the
5025 alias. This saves a tad o memory. */
5026 target_decl = find_decl_and_mark_needed (decl, target);
5027 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5028 do_assemble_alias (decl, target);
5031 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5037 /* Emit an assembler directive to set symbol for DECL visibility to
5038 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5041 default_assemble_visibility (tree decl, int vis)
5043 static const char * const visibility_types[] = {
5044 NULL, "protected", "hidden", "internal"
5047 const char *name, *type;
5049 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5050 type = visibility_types[vis];
5052 #ifdef HAVE_GAS_HIDDEN
5053 fprintf (asm_out_file, "\t.%s\t", type);
5054 assemble_name (asm_out_file, name);
5055 fprintf (asm_out_file, "\n");
5057 warning (OPT_Wattributes, "visibility attribute not supported "
5058 "in this configuration; ignored");
5062 /* A helper function to call assemble_visibility when needed for a decl. */
5065 maybe_assemble_visibility (tree decl)
5067 enum symbol_visibility vis = DECL_VISIBILITY (decl);
5069 if (vis != VISIBILITY_DEFAULT)
5071 targetm.asm_out.visibility (decl, vis);
5078 /* Returns 1 if the target configuration supports defining public symbols
5079 so that one of them will be chosen at link time instead of generating a
5080 multiply-defined symbol error, whether through the use of weak symbols or
5081 a target-specific mechanism for having duplicates discarded. */
5084 supports_one_only (void)
5086 if (SUPPORTS_ONE_ONLY)
5088 return SUPPORTS_WEAK;
5091 /* Set up DECL as a public symbol that can be defined in multiple
5092 translation units without generating a linker error. */
5095 make_decl_one_only (tree decl)
5097 gcc_assert (TREE_CODE (decl) == VAR_DECL
5098 || TREE_CODE (decl) == FUNCTION_DECL);
5100 TREE_PUBLIC (decl) = 1;
5102 if (SUPPORTS_ONE_ONLY)
5104 #ifdef MAKE_DECL_ONE_ONLY
5105 MAKE_DECL_ONE_ONLY (decl);
5107 DECL_ONE_ONLY (decl) = 1;
5109 else if (TREE_CODE (decl) == VAR_DECL
5110 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5111 DECL_COMMON (decl) = 1;
5114 gcc_assert (SUPPORTS_WEAK);
5115 DECL_WEAK (decl) = 1;
5120 init_varasm_once (void)
5122 section_htab = htab_create_ggc (31, section_entry_hash,
5123 section_entry_eq, NULL);
5124 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
5125 object_block_entry_eq, NULL);
5126 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
5127 const_desc_eq, NULL);
5129 const_alias_set = new_alias_set ();
5130 shared_constant_pool = create_constant_pool ();
5132 #ifdef TEXT_SECTION_ASM_OP
5133 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
5134 TEXT_SECTION_ASM_OP);
5137 #ifdef DATA_SECTION_ASM_OP
5138 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5139 DATA_SECTION_ASM_OP);
5142 #ifdef SDATA_SECTION_ASM_OP
5143 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5144 SDATA_SECTION_ASM_OP);
5147 #ifdef READONLY_DATA_SECTION_ASM_OP
5148 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
5149 READONLY_DATA_SECTION_ASM_OP);
5152 #ifdef CTORS_SECTION_ASM_OP
5153 ctors_section = get_unnamed_section (0, output_section_asm_op,
5154 CTORS_SECTION_ASM_OP);
5157 #ifdef DTORS_SECTION_ASM_OP
5158 dtors_section = get_unnamed_section (0, output_section_asm_op,
5159 DTORS_SECTION_ASM_OP);
5162 #ifdef BSS_SECTION_ASM_OP
5163 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5164 output_section_asm_op,
5165 BSS_SECTION_ASM_OP);
5168 #ifdef SBSS_SECTION_ASM_OP
5169 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5170 output_section_asm_op,
5171 SBSS_SECTION_ASM_OP);
5174 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5175 | SECTION_COMMON, emit_tls_common);
5176 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5177 | SECTION_COMMON, emit_local);
5178 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5179 | SECTION_COMMON, emit_common);
5181 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5182 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
5186 targetm.asm_out.init_sections ();
5188 if (readonly_data_section == NULL)
5189 readonly_data_section = text_section;
5193 decl_default_tls_model (tree decl)
5195 enum tls_model kind;
5198 is_local = targetm.binds_local_p (decl);
5202 kind = TLS_MODEL_LOCAL_EXEC;
5204 kind = TLS_MODEL_INITIAL_EXEC;
5207 /* Local dynamic is inefficient when we're not combining the
5208 parts of the address. */
5209 else if (optimize && is_local)
5210 kind = TLS_MODEL_LOCAL_DYNAMIC;
5212 kind = TLS_MODEL_GLOBAL_DYNAMIC;
5213 if (kind < flag_tls_default)
5214 kind = flag_tls_default;
5219 /* Select a set of attributes for section NAME based on the properties
5220 of DECL and whether or not RELOC indicates that DECL's initializer
5221 might contain runtime relocations.
5223 We make the section read-only and executable for a function decl,
5224 read-only for a const data decl, and writable for a non-const data decl. */
5227 default_section_type_flags (tree decl, const char *name, int reloc)
5231 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5232 flags = SECTION_CODE;
5233 else if (decl && decl_readonly_section (decl, reloc))
5235 else if (current_function_decl
5237 && cfun->unlikely_text_section_name
5238 && strcmp (name, cfun->unlikely_text_section_name) == 0)
5239 flags = SECTION_CODE;
5241 && (!current_function_decl || !cfun)
5242 && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
5243 flags = SECTION_CODE;
5245 flags = SECTION_WRITE;
5247 if (decl && DECL_ONE_ONLY (decl))
5248 flags |= SECTION_LINKONCE;
5250 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
5251 flags |= SECTION_TLS | SECTION_WRITE;
5253 if (strcmp (name, ".bss") == 0
5254 || strncmp (name, ".bss.", 5) == 0
5255 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5256 || strcmp (name, ".sbss") == 0
5257 || strncmp (name, ".sbss.", 6) == 0
5258 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5259 flags |= SECTION_BSS;
5261 if (strcmp (name, ".tdata") == 0
5262 || strncmp (name, ".tdata.", 7) == 0
5263 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
5264 flags |= SECTION_TLS;
5266 if (strcmp (name, ".tbss") == 0
5267 || strncmp (name, ".tbss.", 6) == 0
5268 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
5269 flags |= SECTION_TLS | SECTION_BSS;
5271 /* These three sections have special ELF types. They are neither
5272 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
5273 want to print a section type (@progbits or @nobits). If someone
5274 is silly enough to emit code or TLS variables to one of these
5275 sections, then don't handle them specially. */
5276 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
5277 && (strcmp (name, ".init_array") == 0
5278 || strcmp (name, ".fini_array") == 0
5279 || strcmp (name, ".preinit_array") == 0))
5280 flags |= SECTION_NOTYPE;
5285 /* Return true if the target supports some form of global BSS,
5286 either through bss_noswitch_section, or by selecting a BSS
5287 section in TARGET_ASM_SELECT_SECTION. */
5290 have_global_bss_p (void)
5292 return bss_noswitch_section || targetm.have_switchable_bss_sections;
5295 /* Output assembly to switch to section NAME with attribute FLAGS.
5296 Four variants for common object file formats. */
5299 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
5300 unsigned int flags ATTRIBUTE_UNUSED,
5301 tree decl ATTRIBUTE_UNUSED)
5303 /* Some object formats don't support named sections at all. The
5304 front-end should already have flagged this as an error. */
5309 default_elf_asm_named_section (const char *name, unsigned int flags,
5310 tree decl ATTRIBUTE_UNUSED)
5312 char flagchars[10], *f = flagchars;
5314 /* If we have already declared this section, we can use an
5315 abbreviated form to switch back to it -- unless this section is
5316 part of a COMDAT groups, in which case GAS requires the full
5317 declaration every time. */
5318 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5319 && (flags & SECTION_DECLARED))
5321 fprintf (asm_out_file, "\t.section\t%s\n", name);
5325 if (!(flags & SECTION_DEBUG))
5327 if (flags & SECTION_WRITE)
5329 if (flags & SECTION_CODE)
5331 if (flags & SECTION_SMALL)
5333 if (flags & SECTION_MERGE)
5335 if (flags & SECTION_STRINGS)
5337 if (flags & SECTION_TLS)
5339 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5343 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
5345 if (!(flags & SECTION_NOTYPE))
5350 if (flags & SECTION_BSS)
5356 #ifdef ASM_COMMENT_START
5357 /* On platforms that use "@" as the assembly comment character,
5359 if (strcmp (ASM_COMMENT_START, "@") == 0)
5362 fprintf (asm_out_file, format, type);
5364 if (flags & SECTION_ENTSIZE)
5365 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
5366 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5367 fprintf (asm_out_file, ",%s,comdat",
5368 lang_hooks.decls.comdat_group (decl));
5371 putc ('\n', asm_out_file);
5375 default_coff_asm_named_section (const char *name, unsigned int flags,
5376 tree decl ATTRIBUTE_UNUSED)
5378 char flagchars[8], *f = flagchars;
5380 if (flags & SECTION_WRITE)
5382 if (flags & SECTION_CODE)
5386 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5390 default_pe_asm_named_section (const char *name, unsigned int flags,
5393 default_coff_asm_named_section (name, flags, decl);
5395 if (flags & SECTION_LINKONCE)
5397 /* Functions may have been compiled at various levels of
5398 optimization so we can't use `same_size' here.
5399 Instead, have the linker pick one. */
5400 fprintf (asm_out_file, "\t.linkonce %s\n",
5401 (flags & SECTION_CODE ? "discard" : "same_size"));
5405 /* The lame default section selector. */
5408 default_select_section (tree decl, int reloc,
5409 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5413 if (decl_readonly_section (decl, reloc))
5414 return readonly_data_section;
5416 else if (TREE_CODE (decl) == CONSTRUCTOR)
5418 if (! ((flag_pic && reloc)
5419 || !TREE_READONLY (decl)
5420 || TREE_SIDE_EFFECTS (decl)
5421 || !TREE_CONSTANT (decl)))
5422 return readonly_data_section;
5424 else if (TREE_CODE (decl) == STRING_CST)
5425 return readonly_data_section;
5426 else if (! (flag_pic && reloc))
5427 return readonly_data_section;
5429 return data_section;
5432 enum section_category
5433 categorize_decl_for_section (tree decl, int reloc)
5435 enum section_category ret;
5437 if (TREE_CODE (decl) == FUNCTION_DECL)
5439 else if (TREE_CODE (decl) == STRING_CST)
5441 if (flag_mudflap) /* or !flag_merge_constants */
5442 return SECCAT_RODATA;
5444 return SECCAT_RODATA_MERGE_STR;
5446 else if (TREE_CODE (decl) == VAR_DECL)
5448 if (bss_initializer_p (decl))
5450 else if (! TREE_READONLY (decl)
5451 || TREE_SIDE_EFFECTS (decl)
5452 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
5454 /* Here the reloc_rw_mask is not testing whether the section should
5455 be read-only or not, but whether the dynamic link will have to
5456 do something. If so, we wish to segregate the data in order to
5457 minimize cache misses inside the dynamic linker. */
5458 if (reloc & targetm.asm_out.reloc_rw_mask ())
5459 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
5463 else if (reloc & targetm.asm_out.reloc_rw_mask ())
5464 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
5465 else if (reloc || flag_merge_constants < 2)
5466 /* C and C++ don't allow different variables to share the same
5467 location. -fmerge-all-constants allows even that (at the
5468 expense of not conforming). */
5469 ret = SECCAT_RODATA;
5470 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
5471 ret = SECCAT_RODATA_MERGE_STR_INIT;
5473 ret = SECCAT_RODATA_MERGE_CONST;
5475 else if (TREE_CODE (decl) == CONSTRUCTOR)
5477 if ((reloc & targetm.asm_out.reloc_rw_mask ())
5478 || TREE_SIDE_EFFECTS (decl)
5479 || ! TREE_CONSTANT (decl))
5482 ret = SECCAT_RODATA;
5485 ret = SECCAT_RODATA;
5487 /* There are no read-only thread-local sections. */
5488 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
5490 /* Note that this would be *just* SECCAT_BSS, except that there's
5491 no concept of a read-only thread-local-data section. */
5492 if (ret == SECCAT_BSS
5493 || (flag_zero_initialized_in_bss
5494 && initializer_zerop (DECL_INITIAL (decl))))
5500 /* If the target uses small data sections, select it. */
5501 else if (targetm.in_small_data_p (decl))
5503 if (ret == SECCAT_BSS)
5505 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
5506 ret = SECCAT_SRODATA;
5515 decl_readonly_section (tree decl, int reloc)
5517 switch (categorize_decl_for_section (decl, reloc))
5520 case SECCAT_RODATA_MERGE_STR:
5521 case SECCAT_RODATA_MERGE_STR_INIT:
5522 case SECCAT_RODATA_MERGE_CONST:
5523 case SECCAT_SRODATA:
5532 /* Select a section based on the above categorization. */
5535 default_elf_select_section (tree decl, int reloc,
5536 unsigned HOST_WIDE_INT align)
5539 switch (categorize_decl_for_section (decl, reloc))
5542 /* We're not supposed to be called on FUNCTION_DECLs. */
5545 return readonly_data_section;
5546 case SECCAT_RODATA_MERGE_STR:
5547 return mergeable_string_section (decl, align, 0);
5548 case SECCAT_RODATA_MERGE_STR_INIT:
5549 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
5550 case SECCAT_RODATA_MERGE_CONST:
5551 return mergeable_constant_section (DECL_MODE (decl), align, 0);
5552 case SECCAT_SRODATA:
5556 return data_section;
5557 case SECCAT_DATA_REL:
5558 sname = ".data.rel";
5560 case SECCAT_DATA_REL_LOCAL:
5561 sname = ".data.rel.local";
5563 case SECCAT_DATA_REL_RO:
5564 sname = ".data.rel.ro";
5566 case SECCAT_DATA_REL_RO_LOCAL:
5567 sname = ".data.rel.ro.local";
5592 return get_named_section (decl, sname, reloc);
5595 /* Construct a unique section name based on the decl name and the
5596 categorization performed above. */
5599 default_unique_section (tree decl, int reloc)
5601 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
5602 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
5603 const char *prefix, *name;
5607 switch (categorize_decl_for_section (decl, reloc))
5610 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
5613 case SECCAT_RODATA_MERGE_STR:
5614 case SECCAT_RODATA_MERGE_STR_INIT:
5615 case SECCAT_RODATA_MERGE_CONST:
5616 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
5618 case SECCAT_SRODATA:
5619 prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
5622 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
5624 case SECCAT_DATA_REL:
5625 prefix = one_only ? ".gnu.linkonce.d.rel." : ".data.rel.";
5627 case SECCAT_DATA_REL_LOCAL:
5628 prefix = one_only ? ".gnu.linkonce.d.rel.local." : ".data.rel.local.";
5630 case SECCAT_DATA_REL_RO:
5631 prefix = one_only ? ".gnu.linkonce.d.rel.ro." : ".data.rel.ro.";
5633 case SECCAT_DATA_REL_RO_LOCAL:
5634 prefix = one_only ? ".gnu.linkonce.d.rel.ro.local."
5635 : ".data.rel.ro.local.";
5638 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
5641 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
5644 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
5647 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
5650 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
5655 plen = strlen (prefix);
5657 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5658 name = targetm.strip_name_encoding (name);
5659 nlen = strlen (name);
5661 string = alloca (nlen + plen + 1);
5662 memcpy (string, prefix, plen);
5663 memcpy (string + plen, name, nlen + 1);
5665 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
5668 /* Like compute_reloc_for_constant, except for an RTX. The return value
5669 is a mask for which bit 1 indicates a global relocation, and bit 0
5670 indicates a local relocation. */
5673 compute_reloc_for_rtx_1 (rtx *xp, void *data)
5678 switch (GET_CODE (x))
5681 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
5694 compute_reloc_for_rtx (rtx x)
5698 switch (GET_CODE (x))
5704 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
5713 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
5715 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5717 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
5718 return data_section;
5720 return readonly_data_section;
5724 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
5725 unsigned HOST_WIDE_INT align)
5727 int reloc = compute_reloc_for_rtx (x);
5729 /* ??? Handle small data here somehow. */
5731 if (reloc & targetm.asm_out.reloc_rw_mask ())
5734 return get_named_section (NULL, ".data.rel.ro.local", 1);
5736 return get_named_section (NULL, ".data.rel.ro", 3);
5739 return mergeable_constant_section (mode, align, 0);
5742 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5745 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
5750 /* Careful not to prod global register variables. */
5753 symbol = XEXP (rtl, 0);
5754 if (GET_CODE (symbol) != SYMBOL_REF)
5757 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
5758 if (TREE_CODE (decl) == FUNCTION_DECL)
5759 flags |= SYMBOL_FLAG_FUNCTION;
5760 if (targetm.binds_local_p (decl))
5761 flags |= SYMBOL_FLAG_LOCAL;
5762 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
5763 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
5764 else if (targetm.in_small_data_p (decl))
5765 flags |= SYMBOL_FLAG_SMALL;
5766 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5767 being PUBLIC, the thing *must* be defined in this translation unit.
5768 Prevent this buglet from being propagated into rtl code as well. */
5769 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
5770 flags |= SYMBOL_FLAG_EXTERNAL;
5772 SYMBOL_REF_FLAGS (symbol) = flags;
5775 /* By default, we do nothing for encode_section_info, so we need not
5776 do anything but discard the '*' marker. */
5779 default_strip_name_encoding (const char *str)
5781 return str + (*str == '*');
5784 #ifdef ASM_OUTPUT_DEF
5785 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
5786 anchor relative to ".", the current section position. */
5789 default_asm_output_anchor (rtx symbol)
5793 sprintf (buffer, ". + " HOST_WIDE_INT_PRINT_DEC,
5794 SYMBOL_REF_BLOCK_OFFSET (symbol));
5795 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
5799 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
5802 default_use_anchors_for_symbol_p (rtx symbol)
5807 /* Don't use anchors for mergeable sections. The linker might move
5808 the objects around. */
5809 sect = SYMBOL_REF_BLOCK (symbol)->sect;
5810 if (sect->common.flags & SECTION_MERGE)
5813 /* Don't use anchors for small data sections. The small data register
5814 acts as an anchor for such sections. */
5815 if (sect->common.flags & SECTION_SMALL)
5818 decl = SYMBOL_REF_DECL (symbol);
5819 if (decl && DECL_P (decl))
5821 /* Don't use section anchors for decls that might be defined by
5823 if (!targetm.binds_local_p (decl))
5826 /* Don't use section anchors for decls that will be placed in a
5827 small data section. */
5828 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
5829 one above. The problem is that we only use SECTION_SMALL for
5830 sections that should be marked as small in the section directive. */
5831 if (targetm.in_small_data_p (decl))
5837 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5838 wrt cross-module name binding. */
5841 default_binds_local_p (tree exp)
5843 return default_binds_local_p_1 (exp, flag_shlib);
5847 default_binds_local_p_1 (tree exp, int shlib)
5851 /* A non-decl is an entry in the constant pool. */
5854 /* Weakrefs may not bind locally, even though the weakref itself is
5855 always static and therefore local. */
5856 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
5858 /* Static variables are always local. */
5859 else if (! TREE_PUBLIC (exp))
5861 /* A variable is local if the user has said explicitly that it will
5863 else if (DECL_VISIBILITY_SPECIFIED (exp)
5864 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5866 /* Variables defined outside this object might not be local. */
5867 else if (DECL_EXTERNAL (exp))
5869 /* If defined in this object and visibility is not default, must be
5871 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5873 /* Default visibility weak data can be overridden by a strong symbol
5874 in another module and so are not local. */
5875 else if (DECL_WEAK (exp))
5877 /* If PIC, then assume that any global name can be overridden by
5878 symbols resolved from other modules, unless we are compiling with
5879 -fwhole-program, which assumes that names are local. */
5881 local_p = flag_whole_program;
5882 /* Uninitialized COMMON variable may be unified with symbols
5883 resolved from other modules. */
5884 else if (DECL_COMMON (exp)
5885 && (DECL_INITIAL (exp) == NULL
5886 || DECL_INITIAL (exp) == error_mark_node))
5888 /* Otherwise we're left with initialized (or non-common) global data
5889 which is of necessity defined locally. */
5896 /* Determine whether or not a pointer mode is valid. Assume defaults
5897 of ptr_mode or Pmode - can be overridden. */
5899 default_valid_pointer_mode (enum machine_mode mode)
5901 return (mode == ptr_mode || mode == Pmode);
5904 /* Default function to output code that will globalize a label. A
5905 target must define GLOBAL_ASM_OP or provide its own function to
5906 globalize a label. */
5907 #ifdef GLOBAL_ASM_OP
5909 default_globalize_label (FILE * stream, const char *name)
5911 fputs (GLOBAL_ASM_OP, stream);
5912 assemble_name (stream, name);
5913 putc ('\n', stream);
5915 #endif /* GLOBAL_ASM_OP */
5917 /* Default function to output a label for unwind information. The
5918 default is to do nothing. A target that needs nonlocal labels for
5919 unwind information must provide its own function to do this. */
5921 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
5922 tree decl ATTRIBUTE_UNUSED,
5923 int for_eh ATTRIBUTE_UNUSED,
5924 int empty ATTRIBUTE_UNUSED)
5928 /* Default function to output a label to divide up the exception table.
5929 The default is to do nothing. A target that needs/wants to divide
5930 up the table must provide it's own function to do this. */
5932 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
5936 /* This is how to output an internal numbered label where PREFIX is
5937 the class of label and LABELNO is the number within the class. */
5940 default_internal_label (FILE *stream, const char *prefix,
5941 unsigned long labelno)
5943 char *const buf = alloca (40 + strlen (prefix));
5944 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
5945 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
5948 /* This is the default behavior at the beginning of a file. It's
5949 controlled by two other target-hook toggles. */
5951 default_file_start (void)
5953 if (targetm.file_start_app_off && !flag_verbose_asm)
5954 fputs (ASM_APP_OFF, asm_out_file);
5956 if (targetm.file_start_file_directive)
5957 output_file_directive (asm_out_file, main_input_filename);
5960 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5961 which emits a special section directive used to indicate whether or
5962 not this object file needs an executable stack. This is primarily
5963 a GNU extension to ELF but could be used on other targets. */
5965 int trampolines_created;
5968 file_end_indicate_exec_stack (void)
5970 unsigned int flags = SECTION_DEBUG;
5971 if (trampolines_created)
5972 flags |= SECTION_CODE;
5974 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
5977 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
5978 a get_unnamed_section callback. */
5981 output_section_asm_op (const void *directive)
5983 fprintf (asm_out_file, "%s\n", (const char *) directive);
5986 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
5987 the current section is NEW_SECTION. */
5990 switch_to_section (section *new_section)
5992 if (in_section == new_section)
5995 if (new_section->common.flags & SECTION_FORGET)
5998 in_section = new_section;
6000 switch (SECTION_STYLE (new_section))
6004 && !cfun->unlikely_text_section_name
6005 && strcmp (new_section->named.name,
6006 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6007 cfun->unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6009 targetm.asm_out.named_section (new_section->named.name,
6010 new_section->named.common.flags,
6011 new_section->named.decl);
6014 case SECTION_UNNAMED:
6015 new_section->unnamed.callback (new_section->unnamed.data);
6018 case SECTION_NOSWITCH:
6023 new_section->common.flags |= SECTION_DECLARED;
6026 /* If block symbol SYMBOL has not yet been assigned an offset, place
6027 it at the end of its block. */
6030 place_block_symbol (rtx symbol)
6032 unsigned HOST_WIDE_INT size, mask, offset;
6033 struct constant_descriptor_rtx *desc;
6034 unsigned int alignment;
6035 struct object_block *block;
6038 gcc_assert (SYMBOL_REF_BLOCK (symbol));
6039 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6042 /* Work out the symbol's size and alignment. */
6043 if (CONSTANT_POOL_ADDRESS_P (symbol))
6045 desc = SYMBOL_REF_CONSTANT (symbol);
6046 alignment = desc->align;
6047 size = GET_MODE_SIZE (desc->mode);
6049 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6051 decl = SYMBOL_REF_DECL (symbol);
6052 alignment = get_constant_alignment (decl);
6053 size = get_constant_size (decl);
6057 decl = SYMBOL_REF_DECL (symbol);
6058 alignment = DECL_ALIGN (decl);
6059 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6062 /* Calculate the object's offset from the start of the block. */
6063 block = SYMBOL_REF_BLOCK (symbol);
6064 mask = alignment / BITS_PER_UNIT - 1;
6065 offset = (block->size + mask) & ~mask;
6066 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
6068 /* Record the block's new alignment and size. */
6069 block->alignment = MAX (block->alignment, alignment);
6070 block->size = offset + size;
6072 VEC_safe_push (rtx, gc, block->objects, symbol);
6075 /* Return the anchor that should be used to address byte offset OFFSET
6076 from the first object in BLOCK. MODEL is the TLS model used
6080 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
6081 enum tls_model model)
6084 unsigned int begin, middle, end;
6085 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
6088 /* Work out the anchor's offset. Use an offset of 0 for the first
6089 anchor so that we don't pessimize the case where we take the address
6090 of a variable at the beginning of the block. This is particularly
6091 useful when a block has only one variable assigned to it.
6093 We try to place anchors RANGE bytes apart, so there can then be
6094 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6095 a ptr_mode offset. With some target settings, the lowest such
6096 anchor might be out of range for the lowest ptr_mode offset;
6097 likewise the highest anchor for the highest offset. Use anchors
6098 at the extreme ends of the ptr_mode range in such cases.
6100 All arithmetic uses unsigned integers in order to avoid
6102 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
6103 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
6104 range = max_offset - min_offset + 1;
6109 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
6112 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
6113 delta -= delta % range;
6116 offset = (HOST_WIDE_INT) (-delta);
6120 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
6121 delta -= delta % range;
6122 if (delta > bias - 1)
6124 offset = (HOST_WIDE_INT) delta;
6128 /* Do a binary search to see if there's already an anchor we can use.
6129 Set BEGIN to the new anchor's index if not. */
6131 end = VEC_length (rtx, block->anchors);
6132 while (begin != end)
6134 middle = (end + begin) / 2;
6135 anchor = VEC_index (rtx, block->anchors, middle);
6136 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
6138 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
6140 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
6142 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
6148 /* Create a new anchor with a unique label. */
6149 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
6150 anchor = create_block_symbol (ggc_strdup (label), block, offset);
6151 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
6152 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
6154 /* Insert it at index BEGIN. */
6155 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
6159 /* Output the objects in BLOCK. */
6162 output_object_block (struct object_block *block)
6164 struct constant_descriptor_rtx *desc;
6166 HOST_WIDE_INT offset;
6170 if (block->objects == NULL)
6173 /* Switch to the section and make sure that the first byte is
6174 suitably aligned. */
6175 switch_to_section (block->sect);
6176 assemble_align (block->alignment);
6178 /* Define the values of all anchors relative to the current section
6180 for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
6181 targetm.asm_out.output_anchor (symbol);
6183 /* Output the objects themselves. */
6185 for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
6187 /* Move to the object's offset, padding with zeros if necessary. */
6188 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
6189 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
6190 if (CONSTANT_POOL_ADDRESS_P (symbol))
6192 desc = SYMBOL_REF_CONSTANT (symbol);
6193 output_constant_pool_1 (desc, 1);
6194 offset += GET_MODE_SIZE (desc->mode);
6196 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6198 decl = SYMBOL_REF_DECL (symbol);
6199 assemble_constant_contents (decl, XSTR (symbol, 0),
6200 get_constant_alignment (decl));
6201 offset += get_constant_size (decl);
6205 decl = SYMBOL_REF_DECL (symbol);
6206 assemble_variable_contents (decl, XSTR (symbol, 0), false);
6207 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6212 /* A htab_traverse callback used to call output_object_block for
6213 each member of object_block_htab. */
6216 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
6218 output_object_block ((struct object_block *) (*slot));
6222 /* Output the definitions of all object_blocks. */
6225 output_object_blocks (void)
6227 htab_traverse (object_block_htab, output_object_block_htab, NULL);
6230 /* Emit text to declare externally defined symbols. It is needed to
6231 properly support non-default visibility. */
6233 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
6235 const char *name ATTRIBUTE_UNUSED)
6237 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
6238 set in order to avoid putting out names that are never really
6240 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
6241 && targetm.binds_local_p (decl))
6242 maybe_assemble_visibility (decl);
6245 #include "gt-varasm.h"