1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010 Free Software Foundation, Inc.
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 3, 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 COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
42 #include "diagnostic-core.h"
46 #include "langhooks.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.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 #define n_deferred_constants (crtl->varasm.deferred_constants)
75 /* Number for making the label on the next
76 constant that is stored in memory. */
78 static GTY(()) int const_labelno;
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81 to ASM_FINISH_DECLARE_OBJECT. */
83 int size_directive_output;
85 /* The last decl for which assemble_variable was called,
86 if it did ASM_DECLARE_OBJECT_NAME.
87 If the last call to assemble_variable didn't do that,
90 tree last_assemble_variable_decl;
92 /* The following global variable indicates if the first basic block
93 in a function belongs to the cold partition or not. */
95 bool first_function_block_is_cold;
97 /* We give all constants their own alias set. Perhaps redundant with
98 MEM_READONLY_P, but pre-dates it. */
100 static alias_set_type const_alias_set;
102 static const char *strip_reg_name (const char *);
103 static int contains_pointers_p (tree);
104 #ifdef ASM_OUTPUT_EXTERNAL
105 static bool incorporeal_function_p (tree);
107 static void decode_addr_const (tree, struct addr_const *);
108 static hashval_t const_desc_hash (const void *);
109 static int const_desc_eq (const void *, const void *);
110 static hashval_t const_hash_1 (const tree);
111 static int compare_constant (const tree, const tree);
112 static tree copy_constant (tree);
113 static void output_constant_def_contents (rtx);
114 static void output_addressed_constants (tree);
115 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
116 static unsigned min_align (unsigned, unsigned);
117 static void globalize_decl (tree);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_BSS
120 static void asm_output_bss (FILE *, tree, const char *,
121 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
123 #ifdef ASM_OUTPUT_ALIGNED_BSS
124 static void asm_output_aligned_bss (FILE *, tree, const char *,
125 unsigned HOST_WIDE_INT, int)
128 #endif /* BSS_SECTION_ASM_OP */
129 static void mark_weak (tree);
130 static void output_constant_pool (const char *, tree);
132 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
133 section *text_section;
134 section *data_section;
135 section *readonly_data_section;
136 section *sdata_section;
137 section *ctors_section;
138 section *dtors_section;
139 section *bss_section;
140 section *sbss_section;
142 /* Various forms of common section. All are guaranteed to be nonnull. */
143 section *tls_comm_section;
144 section *comm_section;
145 section *lcomm_section;
147 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
149 section *bss_noswitch_section;
151 /* The section that holds the main exception table, when known. The section
152 is set either by the target's init_sections hook or by the first call to
153 switch_to_exception_section. */
154 section *exception_section;
156 /* The section that holds the DWARF2 frame unwind information, when known.
157 The section is set either by the target's init_sections hook or by the
158 first call to switch_to_eh_frame_section. */
159 section *eh_frame_section;
161 /* asm_out_file's current section. This is NULL if no section has yet
162 been selected or if we lose track of what the current section is. */
165 /* True if code for the current function is currently being directed
166 at the cold section. */
167 bool in_cold_section_p;
169 /* A linked list of all the unnamed sections. */
170 static GTY(()) section *unnamed_sections;
172 /* Return a nonzero value if DECL has a section attribute. */
173 #define IN_NAMED_SECTION(DECL) \
174 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
175 && DECL_SECTION_NAME (DECL) != NULL_TREE)
177 /* Hash table of named sections. */
178 static GTY((param_is (section))) htab_t section_htab;
180 /* A table of object_blocks, indexed by section. */
181 static GTY((param_is (struct object_block))) htab_t object_block_htab;
183 /* The next number to use for internal anchor labels. */
184 static GTY(()) int anchor_labelno;
186 /* A pool of constants that can be shared between functions. */
187 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
189 /* Helper routines for maintaining section_htab. */
192 section_entry_eq (const void *p1, const void *p2)
194 const section *old = (const section *) p1;
195 const char *new_name = (const char *) p2;
197 return strcmp (old->named.name, new_name) == 0;
201 section_entry_hash (const void *p)
203 const section *old = (const section *) p;
204 return htab_hash_string (old->named.name);
207 /* Return a hash value for section SECT. */
210 hash_section (section *sect)
212 if (sect->common.flags & SECTION_NAMED)
213 return htab_hash_string (sect->named.name);
214 return sect->common.flags;
217 /* Helper routines for maintaining object_block_htab. */
220 object_block_entry_eq (const void *p1, const void *p2)
222 const struct object_block *old = (const struct object_block *) p1;
223 const section *new_section = (const section *) p2;
225 return old->sect == new_section;
229 object_block_entry_hash (const void *p)
231 const struct object_block *old = (const struct object_block *) p;
232 return hash_section (old->sect);
235 /* Return a new unnamed section with the given fields. */
238 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
243 sect = ggc_alloc_section ();
244 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
245 sect->unnamed.callback = callback;
246 sect->unnamed.data = data;
247 sect->unnamed.next = unnamed_sections;
249 unnamed_sections = sect;
253 /* Return a SECTION_NOSWITCH section with the given fields. */
256 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
260 sect = ggc_alloc_section ();
261 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
262 sect->noswitch.callback = callback;
267 /* Return the named section structure associated with NAME. Create
268 a new section with the given fields if no such structure exists. */
271 get_section (const char *name, unsigned int flags, tree decl)
273 section *sect, **slot;
276 htab_find_slot_with_hash (section_htab, name,
277 htab_hash_string (name), INSERT);
278 flags |= SECTION_NAMED;
281 sect = ggc_alloc_section ();
282 sect->named.common.flags = flags;
283 sect->named.name = ggc_strdup (name);
284 sect->named.decl = decl;
290 if ((sect->common.flags & ~SECTION_DECLARED) != flags
291 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
293 /* Sanity check user variables for flag changes. */
295 decl = sect->named.decl;
297 error ("%+D causes a section type conflict", decl);
303 /* Return true if the current compilation mode benefits from having
304 objects grouped into blocks. */
307 use_object_blocks_p (void)
309 return flag_section_anchors;
312 /* Return the object_block structure for section SECT. Create a new
313 structure if we haven't created one already. Return null if SECT
316 static struct object_block *
317 get_block_for_section (section *sect)
319 struct object_block *block;
325 slot = htab_find_slot_with_hash (object_block_htab, sect,
326 hash_section (sect), INSERT);
327 block = (struct object_block *) *slot;
330 block = ggc_alloc_cleared_object_block ();
337 /* Create a symbol with label LABEL and place it at byte offset
338 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
339 is not yet known. LABEL must be a garbage-collected string. */
342 create_block_symbol (const char *label, struct object_block *block,
343 HOST_WIDE_INT offset)
348 /* Create the extended SYMBOL_REF. */
349 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
350 symbol = ggc_alloc_zone_rtx_def (size, &rtl_zone);
352 /* Initialize the normal SYMBOL_REF fields. */
353 memset (symbol, 0, size);
354 PUT_CODE (symbol, SYMBOL_REF);
355 PUT_MODE (symbol, Pmode);
356 XSTR (symbol, 0) = label;
357 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
359 /* Initialize the block_symbol stuff. */
360 SYMBOL_REF_BLOCK (symbol) = block;
361 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
367 initialize_cold_section_name (void)
369 const char *stripped_name;
373 gcc_assert (cfun && current_function_decl);
374 if (crtl->subsections.unlikely_text_section_name)
377 dsn = DECL_SECTION_NAME (current_function_decl);
378 if (flag_function_sections && dsn)
380 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
381 memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
383 stripped_name = targetm.strip_name_encoding (name);
385 buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
386 crtl->subsections.unlikely_text_section_name = ggc_strdup (buffer);
389 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
392 /* Tell assembler to switch to unlikely-to-be-executed text section. */
395 unlikely_text_section (void)
399 if (!crtl->subsections.unlikely_text_section_name)
400 initialize_cold_section_name ();
402 return get_named_section (NULL, crtl->subsections.unlikely_text_section_name, 0);
405 return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
408 /* When called within a function context, return true if the function
409 has been assigned a cold text section and if SECT is that section.
410 When called outside a function context, return true if SECT is the
411 default cold section. */
414 unlikely_text_section_p (section *sect)
419 name = crtl->subsections.unlikely_text_section_name;
421 name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
425 && SECTION_STYLE (sect) == SECTION_NAMED
426 && strcmp (name, sect->named.name) == 0);
429 /* Return a section with a particular name and with whatever SECTION_*
430 flags section_type_flags deems appropriate. The name of the section
431 is taken from NAME if nonnull, otherwise it is taken from DECL's
432 DECL_SECTION_NAME. DECL is the decl associated with the section
433 (see the section comment for details) and RELOC is as for
434 section_type_flags. */
437 get_named_section (tree decl, const char *name, int reloc)
441 gcc_assert (!decl || DECL_P (decl));
443 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
445 flags = targetm.section_type_flags (decl, name, reloc);
447 return get_section (name, flags, decl);
450 /* If required, set DECL_SECTION_NAME to a unique name. */
453 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
454 int flag_function_or_data_sections)
456 if (DECL_SECTION_NAME (decl) == NULL_TREE
457 && targetm.have_named_sections
458 && (flag_function_or_data_sections
459 || DECL_ONE_ONLY (decl)))
460 targetm.asm_out.unique_section (decl, reloc);
463 #ifdef BSS_SECTION_ASM_OP
465 #ifdef ASM_OUTPUT_BSS
467 /* Utility function for ASM_OUTPUT_BSS for targets to use if
468 they don't support alignments in .bss.
469 ??? It is believed that this function will work in most cases so such
470 support is localized here. */
473 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
475 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
476 unsigned HOST_WIDE_INT rounded)
478 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl), 0), 0), name) == 0);
479 targetm.asm_out.globalize_decl_name (file, decl);
480 switch_to_section (bss_section);
481 #ifdef ASM_DECLARE_OBJECT_NAME
482 last_assemble_variable_decl = decl;
483 ASM_DECLARE_OBJECT_NAME (file, name, decl);
485 /* Standard thing is just output label for the object. */
486 ASM_OUTPUT_LABEL (file, name);
487 #endif /* ASM_DECLARE_OBJECT_NAME */
488 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
493 #ifdef ASM_OUTPUT_ALIGNED_BSS
495 /* Utility function for targets to use in implementing
496 ASM_OUTPUT_ALIGNED_BSS.
497 ??? It is believed that this function will work in most cases so such
498 support is localized here. */
501 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
502 const char *name, unsigned HOST_WIDE_INT size,
505 switch_to_section (bss_section);
506 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
507 #ifdef ASM_DECLARE_OBJECT_NAME
508 last_assemble_variable_decl = decl;
509 ASM_DECLARE_OBJECT_NAME (file, name, decl);
511 /* Standard thing is just output label for the object. */
512 ASM_OUTPUT_LABEL (file, name);
513 #endif /* ASM_DECLARE_OBJECT_NAME */
514 ASM_OUTPUT_SKIP (file, size ? size : 1);
519 #endif /* BSS_SECTION_ASM_OP */
521 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
522 /* Return the hot section for function DECL. Return text_section for
526 hot_function_section (tree decl)
528 if (decl != NULL_TREE
529 && DECL_SECTION_NAME (decl) != NULL_TREE
530 && targetm.have_named_sections)
531 return get_named_section (decl, NULL, 0);
537 /* Return the section for function DECL.
539 If DECL is NULL_TREE, return the text section. We can be passed
540 NULL_TREE under some circumstances by dbxout.c at least. */
543 function_section (tree decl)
547 if (first_function_block_is_cold)
550 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
551 if (decl != NULL_TREE
552 && DECL_SECTION_NAME (decl) != NULL_TREE)
553 return reloc ? unlikely_text_section ()
554 : get_named_section (decl, NULL, 0);
556 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
558 return reloc ? unlikely_text_section () : hot_function_section (decl);
563 current_function_section (void)
565 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
566 if (current_function_decl != NULL_TREE
567 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
568 return in_cold_section_p ? unlikely_text_section ()
569 : get_named_section (current_function_decl,
572 return targetm.asm_out.select_section (current_function_decl,
574 DECL_ALIGN (current_function_decl));
576 return (in_cold_section_p
577 ? unlikely_text_section ()
578 : hot_function_section (current_function_decl));
582 /* Return the read-only data section associated with function DECL. */
585 default_function_rodata_section (tree decl)
587 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
589 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
591 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
597 dot = strchr (name + 1, '.');
600 len = strlen (dot) + 8;
601 rname = (char *) alloca (len);
603 strcpy (rname, ".rodata");
605 return get_section (rname, SECTION_LINKONCE, decl);
607 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
608 else if (DECL_ONE_ONLY (decl)
609 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
611 size_t len = strlen (name) + 1;
612 char *rname = (char *) alloca (len);
614 memcpy (rname, name, len);
616 return get_section (rname, SECTION_LINKONCE, decl);
618 /* For .text.foo we want to use .rodata.foo. */
619 else if (flag_function_sections && flag_data_sections
620 && strncmp (name, ".text.", 6) == 0)
622 size_t len = strlen (name) + 1;
623 char *rname = (char *) alloca (len + 2);
625 memcpy (rname, ".rodata", 7);
626 memcpy (rname + 7, name + 5, len - 5);
627 return get_section (rname, 0, decl);
631 return readonly_data_section;
634 /* Return the read-only data section associated with function DECL
635 for targets where that section should be always the single
636 readonly data section. */
639 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
641 return readonly_data_section;
644 /* Return the section to use for string merging. */
647 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
648 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
649 unsigned int flags ATTRIBUTE_UNUSED)
653 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
654 && TREE_CODE (decl) == STRING_CST
655 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
657 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
658 && TREE_STRING_LENGTH (decl) >= len)
660 enum machine_mode mode;
661 unsigned int modesize;
667 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
668 modesize = GET_MODE_BITSIZE (mode);
669 if (modesize >= 8 && modesize <= 256
670 && (modesize & (modesize - 1)) == 0)
672 if (align < modesize)
675 str = TREE_STRING_POINTER (decl);
676 unit = GET_MODE_SIZE (mode);
678 /* Check for embedded NUL characters. */
679 for (i = 0; i < len; i += unit)
681 for (j = 0; j < unit; j++)
682 if (str[i + j] != '\0')
689 sprintf (name, ".rodata.str%d.%d", modesize / 8,
691 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
692 return get_section (name, flags, NULL);
697 return readonly_data_section;
700 /* Return the section to use for constant merging. */
703 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
704 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
705 unsigned int flags ATTRIBUTE_UNUSED)
707 unsigned int modesize = GET_MODE_BITSIZE (mode);
709 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
715 && (align & (align - 1)) == 0)
719 sprintf (name, ".rodata.cst%d", (int) (align / 8));
720 flags |= (align / 8) | SECTION_MERGE;
721 return get_section (name, flags, NULL);
723 return readonly_data_section;
726 /* Given NAME, a putative register name, discard any customary prefixes. */
729 strip_reg_name (const char *name)
731 #ifdef REGISTER_PREFIX
732 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
733 name += strlen (REGISTER_PREFIX);
735 if (name[0] == '%' || name[0] == '#')
740 /* The user has asked for a DECL to have a particular name. Set (or
741 change) it in such a way that we don't prefix an underscore to
744 set_user_assembler_name (tree decl, const char *name)
746 char *starred = (char *) alloca (strlen (name) + 2);
748 strcpy (starred + 1, name);
749 change_decl_assembler_name (decl, get_identifier (starred));
750 SET_DECL_RTL (decl, NULL_RTX);
753 /* Decode an `asm' spec for a declaration as a register name.
754 Return the register number, or -1 if nothing specified,
755 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
756 or -3 if ASMSPEC is `cc' and is not recognized,
757 or -4 if ASMSPEC is `memory' and is not recognized.
758 Accept an exact spelling or a decimal number.
759 Prefixes such as % are optional. */
762 decode_reg_name (const char *asmspec)
768 /* Get rid of confusing prefixes. */
769 asmspec = strip_reg_name (asmspec);
771 /* Allow a decimal number as a "register name". */
772 for (i = strlen (asmspec) - 1; i >= 0; i--)
773 if (! ISDIGIT (asmspec[i]))
775 if (asmspec[0] != 0 && i < 0)
778 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
784 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
786 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
789 #ifdef ADDITIONAL_REGISTER_NAMES
791 static const struct { const char *const name; const int number; } table[]
792 = ADDITIONAL_REGISTER_NAMES;
794 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
796 && ! strcmp (asmspec, table[i].name))
797 return table[i].number;
799 #endif /* ADDITIONAL_REGISTER_NAMES */
801 if (!strcmp (asmspec, "memory"))
804 if (!strcmp (asmspec, "cc"))
813 /* Return true if DECL's initializer is suitable for a BSS section. */
816 bss_initializer_p (const_tree decl)
818 return (DECL_INITIAL (decl) == NULL
819 || DECL_INITIAL (decl) == error_mark_node
820 || (flag_zero_initialized_in_bss
821 /* Leave constant zeroes in .rodata so they
823 && !TREE_READONLY (decl)
824 && initializer_zerop (DECL_INITIAL (decl))));
827 /* Compute the alignment of variable specified by DECL.
828 DONT_OUTPUT_DATA is from assemble_variable. */
831 align_variable (tree decl, bool dont_output_data)
833 unsigned int align = DECL_ALIGN (decl);
835 /* In the case for initialing an array whose length isn't specified,
836 where we have not yet been able to do the layout,
837 figure out the proper alignment now. */
838 if (dont_output_data && DECL_SIZE (decl) == 0
839 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
840 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
842 /* Some object file formats have a maximum alignment which they support.
843 In particular, a.out format supports a maximum alignment of 4. */
844 if (align > MAX_OFILE_ALIGNMENT)
846 warning (0, "alignment of %q+D is greater than maximum object "
847 "file alignment. Using %d", decl,
848 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
849 align = MAX_OFILE_ALIGNMENT;
852 /* On some machines, it is good to increase alignment sometimes. */
853 if (! DECL_USER_ALIGN (decl))
855 #ifdef DATA_ALIGNMENT
856 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
857 /* Don't increase alignment too much for TLS variables - TLS space
859 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
862 #ifdef CONSTANT_ALIGNMENT
863 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
865 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
867 /* Don't increase alignment too much for TLS variables - TLS space
869 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
875 /* Reset the alignment in case we have made it tighter, so we can benefit
876 from it in get_pointer_alignment. */
877 DECL_ALIGN (decl) = align;
880 /* Return the section into which the given VAR_DECL or CONST_DECL
881 should be placed. PREFER_NOSWITCH_P is true if a noswitch
882 section should be used wherever possible. */
885 get_variable_section (tree decl, bool prefer_noswitch_p)
887 addr_space_t as = ADDR_SPACE_GENERIC;
890 if (TREE_TYPE (decl) != error_mark_node)
891 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
893 if (DECL_COMMON (decl))
895 /* If the decl has been given an explicit section name, or it resides
896 in a non-generic address space, then it isn't common, and shouldn't
897 be handled as such. */
898 gcc_assert (DECL_SECTION_NAME (decl) == NULL
899 && ADDR_SPACE_GENERIC_P (as));
900 if (DECL_THREAD_LOCAL_P (decl))
901 return tls_comm_section;
902 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
906 if (DECL_INITIAL (decl) == error_mark_node)
907 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
908 else if (DECL_INITIAL (decl))
909 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
913 resolve_unique_section (decl, reloc, flag_data_sections);
914 if (IN_NAMED_SECTION (decl))
915 return get_named_section (decl, NULL, reloc);
917 if (ADDR_SPACE_GENERIC_P (as)
918 && !DECL_THREAD_LOCAL_P (decl)
919 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
920 && bss_initializer_p (decl))
922 if (!TREE_PUBLIC (decl))
923 return lcomm_section;
924 if (bss_noswitch_section)
925 return bss_noswitch_section;
928 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
931 /* Return the block into which object_block DECL should be placed. */
933 static struct object_block *
934 get_block_for_decl (tree decl)
938 if (TREE_CODE (decl) == VAR_DECL)
940 /* The object must be defined in this translation unit. */
941 if (DECL_EXTERNAL (decl))
944 /* There's no point using object blocks for something that is
945 isolated by definition. */
946 if (DECL_ONE_ONLY (decl))
950 /* We can only calculate block offsets if the decl has a known
952 if (DECL_SIZE_UNIT (decl) == NULL)
954 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
957 /* Find out which section should contain DECL. We cannot put it into
958 an object block if it requires a standalone definition. */
959 if (TREE_CODE (decl) == VAR_DECL)
960 align_variable (decl, 0);
961 sect = get_variable_section (decl, true);
962 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
965 return get_block_for_section (sect);
968 /* Make sure block symbol SYMBOL is in block BLOCK. */
971 change_symbol_block (rtx symbol, struct object_block *block)
973 if (block != SYMBOL_REF_BLOCK (symbol))
975 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
976 SYMBOL_REF_BLOCK (symbol) = block;
980 /* Return true if it is possible to put DECL in an object_block. */
983 use_blocks_for_decl_p (tree decl)
985 /* Only data DECLs can be placed into object blocks. */
986 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
989 /* Detect decls created by dw2_force_const_mem. Such decls are
990 special because DECL_INITIAL doesn't specify the decl's true value.
991 dw2_output_indirect_constants will instead call assemble_variable
992 with dont_output_data set to 1 and then print the contents itself. */
993 if (DECL_INITIAL (decl) == decl)
996 /* If this decl is an alias, then we don't want to emit a
998 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1004 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1005 have static storage duration. In other words, it should not be an
1006 automatic variable, including PARM_DECLs.
1008 There is, however, one exception: this function handles variables
1009 explicitly placed in a particular register by the user.
1011 This is never called for PARM_DECL nodes. */
1014 make_decl_rtl (tree decl)
1016 const char *name = 0;
1020 /* Check that we are not being given an automatic variable. */
1021 gcc_assert (TREE_CODE (decl) != PARM_DECL
1022 && TREE_CODE (decl) != RESULT_DECL);
1024 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1025 gcc_assert (TREE_CODE (decl) != VAR_DECL
1026 || TREE_STATIC (decl)
1027 || TREE_PUBLIC (decl)
1028 || DECL_EXTERNAL (decl)
1029 || DECL_REGISTER (decl));
1031 /* And that we were not given a type or a label. */
1032 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1033 && TREE_CODE (decl) != LABEL_DECL);
1035 /* For a duplicate declaration, we can be called twice on the
1036 same DECL node. Don't discard the RTL already made. */
1037 if (DECL_RTL_SET_P (decl))
1039 /* If the old RTL had the wrong mode, fix the mode. */
1040 x = DECL_RTL (decl);
1041 if (GET_MODE (x) != DECL_MODE (decl))
1042 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1044 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1047 /* ??? Another way to do this would be to maintain a hashed
1048 table of such critters. Instead of adding stuff to a DECL
1049 to give certain attributes to it, we could use an external
1050 hash map from DECL to set of attributes. */
1052 /* Let the target reassign the RTL if it wants.
1053 This is necessary, for example, when one machine specific
1054 decl attribute overrides another. */
1055 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1057 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1058 on the new decl information. */
1060 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1061 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1062 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1064 /* Make this function static known to the mudflap runtime. */
1065 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1066 mudflap_enqueue_decl (decl);
1071 /* If this variable belongs to the global constant pool, retrieve the
1072 pre-computed RTL or recompute it in LTO mode. */
1073 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1075 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1079 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1081 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1082 && DECL_REGISTER (decl))
1084 error ("register name not specified for %q+D", decl);
1086 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1088 const char *asmspec = name+1;
1089 reg_number = decode_reg_name (asmspec);
1090 /* First detect errors in declaring global registers. */
1091 if (reg_number == -1)
1092 error ("register name not specified for %q+D", decl);
1093 else if (reg_number < 0)
1094 error ("invalid register name for %q+D", decl);
1095 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1096 error ("data type of %q+D isn%'t suitable for a register",
1098 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1099 error ("register specified for %q+D isn%'t suitable for data type",
1101 /* Now handle properly declared static register variables. */
1106 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1108 DECL_INITIAL (decl) = 0;
1109 error ("global register variable has initial value");
1111 if (TREE_THIS_VOLATILE (decl))
1112 warning (OPT_Wvolatile_register_var,
1113 "optimization may eliminate reads and/or "
1114 "writes to register variables");
1116 /* If the user specified one of the eliminables registers here,
1117 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1118 confused with that register and be eliminated. This usage is
1119 somewhat suspect... */
1121 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1122 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1123 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1125 if (TREE_STATIC (decl))
1127 /* Make this register global, so not usable for anything
1129 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1130 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1131 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1133 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1135 globalize_reg (reg_number + --nregs);
1138 /* As a register variable, it has no section. */
1142 /* Now handle ordinary static variables and functions (in memory).
1143 Also handle vars declared register invalidly. */
1144 else if (name[0] == '*')
1146 #ifdef REGISTER_PREFIX
1147 if (strlen (REGISTER_PREFIX) != 0)
1149 reg_number = decode_reg_name (name);
1150 if (reg_number >= 0 || reg_number == -3)
1151 error ("register name given for non-register variable %q+D", decl);
1156 /* Specifying a section attribute on a variable forces it into a
1157 non-.bss section, and thus it cannot be common. */
1158 /* FIXME: In general this code should not be necessary because
1159 visibility pass is doing the same work. But notice_global_symbol
1160 is called early and it needs to make DECL_RTL to get the name.
1161 we take care of recomputing the DECL_RTL after visibility is changed. */
1162 if (TREE_CODE (decl) == VAR_DECL
1163 && DECL_SECTION_NAME (decl) != NULL_TREE
1164 && DECL_INITIAL (decl) == NULL_TREE
1165 && DECL_COMMON (decl))
1166 DECL_COMMON (decl) = 0;
1168 /* Variables can't be both common and weak. */
1169 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1170 DECL_COMMON (decl) = 0;
1172 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1173 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1176 enum machine_mode address_mode = Pmode;
1177 if (TREE_TYPE (decl) != error_mark_node)
1179 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1180 address_mode = targetm.addr_space.address_mode (as);
1182 x = gen_rtx_SYMBOL_REF (address_mode, name);
1184 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1185 SET_SYMBOL_REF_DECL (x, decl);
1187 x = gen_rtx_MEM (DECL_MODE (decl), x);
1188 if (TREE_CODE (decl) != FUNCTION_DECL)
1189 set_mem_attributes (x, decl, 1);
1190 SET_DECL_RTL (decl, x);
1192 /* Optionally set flags or add text to the name to record information
1193 such as that it is a function name.
1194 If the name is changed, the macro ASM_OUTPUT_LABELREF
1195 will have to know how to strip this information. */
1196 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1198 /* Make this function static known to the mudflap runtime. */
1199 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1200 mudflap_enqueue_decl (decl);
1203 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1204 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1208 make_decl_rtl_for_debug (tree decl)
1210 unsigned int save_aliasing_flag, save_mudflap_flag;
1213 if (DECL_RTL_SET_P (decl))
1214 return DECL_RTL (decl);
1216 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1217 call new_alias_set. If running with -fcompare-debug, sometimes
1218 we do not want to create alias sets that will throw the alias
1219 numbers off in the comparison dumps. So... clearing
1220 flag_strict_aliasing will keep new_alias_set() from creating a
1221 new set. It is undesirable to register decl with mudflap
1222 in this case as well. */
1223 save_aliasing_flag = flag_strict_aliasing;
1224 flag_strict_aliasing = 0;
1225 save_mudflap_flag = flag_mudflap;
1228 rtl = DECL_RTL (decl);
1229 /* Reset DECL_RTL back, as various parts of the compiler expects
1230 DECL_RTL set meaning it is actually going to be output. */
1231 SET_DECL_RTL (decl, NULL);
1233 flag_strict_aliasing = save_aliasing_flag;
1234 flag_mudflap = save_mudflap_flag;
1239 /* Output a string of literal assembler code
1240 for an `asm' keyword used between functions. */
1243 assemble_asm (tree string)
1247 if (TREE_CODE (string) == ADDR_EXPR)
1248 string = TREE_OPERAND (string, 0);
1250 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1253 /* Record an element in the table of global destructors. SYMBOL is
1254 a SYMBOL_REF of the function to be called; PRIORITY is a number
1255 between 0 and MAX_INIT_PRIORITY. */
1258 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1259 int priority ATTRIBUTE_UNUSED)
1261 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1262 /* Tell GNU LD that this is part of the static destructor set.
1263 This will work for any system that uses stabs, most usefully
1265 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1266 dbxout_stab_value_label (XSTR (symbol, 0));
1268 sorry ("global destructors not supported on this target");
1272 /* Write the address of the entity given by SYMBOL to SEC. */
1274 assemble_addr_to_section (rtx symbol, section *sec)
1276 switch_to_section (sec);
1277 assemble_align (POINTER_SIZE);
1278 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1281 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1282 not) section for PRIORITY. */
1284 get_cdtor_priority_section (int priority, bool constructor_p)
1288 /* ??? This only works reliably with the GNU linker. */
1289 sprintf (buf, "%s.%.5u",
1290 constructor_p ? ".ctors" : ".dtors",
1291 /* Invert the numbering so the linker puts us in the proper
1292 order; constructors are run from right to left, and the
1293 linker sorts in increasing order. */
1294 MAX_INIT_PRIORITY - priority);
1295 return get_section (buf, SECTION_WRITE, NULL);
1299 default_named_section_asm_out_destructor (rtx symbol, int priority)
1303 if (priority != DEFAULT_INIT_PRIORITY)
1304 sec = get_cdtor_priority_section (priority,
1305 /*constructor_p=*/false);
1307 sec = get_section (".dtors", SECTION_WRITE, NULL);
1309 assemble_addr_to_section (symbol, sec);
1312 #ifdef DTORS_SECTION_ASM_OP
1314 default_dtor_section_asm_out_destructor (rtx symbol,
1315 int priority ATTRIBUTE_UNUSED)
1317 assemble_addr_to_section (symbol, dtors_section);
1321 /* Likewise for global constructors. */
1324 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1325 int priority ATTRIBUTE_UNUSED)
1327 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1328 /* Tell GNU LD that this is part of the static destructor set.
1329 This will work for any system that uses stabs, most usefully
1331 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1332 dbxout_stab_value_label (XSTR (symbol, 0));
1334 sorry ("global constructors not supported on this target");
1339 default_named_section_asm_out_constructor (rtx symbol, int priority)
1343 if (priority != DEFAULT_INIT_PRIORITY)
1344 sec = get_cdtor_priority_section (priority,
1345 /*constructor_p=*/true);
1347 sec = get_section (".ctors", SECTION_WRITE, NULL);
1349 assemble_addr_to_section (symbol, sec);
1352 #ifdef CTORS_SECTION_ASM_OP
1354 default_ctor_section_asm_out_constructor (rtx symbol,
1355 int priority ATTRIBUTE_UNUSED)
1357 assemble_addr_to_section (symbol, ctors_section);
1361 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1362 a nonzero value if the constant pool should be output before the
1363 start of the function, or a zero value if the pool should output
1364 after the end of the function. The default is to put it before the
1367 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1368 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1371 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1372 to be output to assembler.
1373 Set first_global_object_name and weak_global_object_name as appropriate. */
1376 notice_global_symbol (tree decl)
1378 const char **type = &first_global_object_name;
1380 if (first_global_object_name
1381 || !TREE_PUBLIC (decl)
1382 || DECL_EXTERNAL (decl)
1383 || !DECL_NAME (decl)
1384 || (TREE_CODE (decl) != FUNCTION_DECL
1385 && (TREE_CODE (decl) != VAR_DECL
1386 || (DECL_COMMON (decl)
1387 && (DECL_INITIAL (decl) == 0
1388 || DECL_INITIAL (decl) == error_mark_node))))
1389 || !MEM_P (DECL_RTL (decl)))
1392 /* We win when global object is found, but it is useful to know about weak
1393 symbol as well so we can produce nicer unique names. */
1394 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1395 type = &weak_global_object_name;
1401 rtx decl_rtl = DECL_RTL (decl);
1403 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1404 name = ggc_strdup (p);
1410 /* Output assembler code for the constant pool of a function and associated
1411 with defining the name of the function. DECL describes the function.
1412 NAME is the function's name. For the constant pool, we use the current
1413 constant pool data. */
1416 assemble_start_function (tree decl, const char *fnname)
1419 char tmp_label[100];
1420 bool hot_label_written = false;
1422 crtl->subsections.unlikely_text_section_name = NULL;
1424 first_function_block_is_cold = false;
1425 if (flag_reorder_blocks_and_partition)
1427 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1428 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1429 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1430 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1431 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1432 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1433 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1434 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1439 crtl->subsections.hot_section_label = NULL;
1440 crtl->subsections.cold_section_label = NULL;
1441 crtl->subsections.hot_section_end_label = NULL;
1442 crtl->subsections.cold_section_end_label = NULL;
1445 /* The following code does not need preprocessing in the assembler. */
1449 if (CONSTANT_POOL_BEFORE_FUNCTION)
1450 output_constant_pool (fnname, decl);
1452 resolve_unique_section (decl, 0, flag_function_sections);
1454 /* Make sure the not and cold text (code) sections are properly
1455 aligned. This is necessary here in the case where the function
1456 has both hot and cold sections, because we don't want to re-set
1457 the alignment when the section switch happens mid-function. */
1459 if (flag_reorder_blocks_and_partition)
1461 switch_to_section (unlikely_text_section ());
1462 assemble_align (DECL_ALIGN (decl));
1463 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1465 /* When the function starts with a cold section, we need to explicitly
1466 align the hot section and write out the hot section label.
1467 But if the current function is a thunk, we do not have a CFG. */
1469 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1471 switch_to_section (text_section);
1472 assemble_align (DECL_ALIGN (decl));
1473 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1474 hot_label_written = true;
1475 first_function_block_is_cold = true;
1478 else if (DECL_SECTION_NAME (decl))
1480 /* Calls to function_section rely on first_function_block_is_cold
1481 being accurate. The first block may be cold even if we aren't
1482 doing partitioning, if the entire function was decided by
1483 choose_function_section (predict.c) to be cold. */
1485 initialize_cold_section_name ();
1487 if (crtl->subsections.unlikely_text_section_name
1488 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1489 crtl->subsections.unlikely_text_section_name) == 0)
1490 first_function_block_is_cold = true;
1493 in_cold_section_p = first_function_block_is_cold;
1495 /* Switch to the correct text section for the start of the function. */
1497 switch_to_section (function_section (decl));
1498 if (flag_reorder_blocks_and_partition
1499 && !hot_label_written)
1500 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1502 /* Tell assembler to move to target machine's alignment for functions. */
1503 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1506 ASM_OUTPUT_ALIGN (asm_out_file, align);
1509 /* Handle a user-specified function alignment.
1510 Note that we still need to align to DECL_ALIGN, as above,
1511 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1512 if (! DECL_USER_ALIGN (decl)
1513 && align_functions_log > align
1514 && optimize_function_for_speed_p (cfun))
1516 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1517 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1518 align_functions_log, align_functions - 1);
1520 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1524 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1525 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1528 if (!DECL_IGNORED_P (decl))
1529 (*debug_hooks->begin_function) (decl);
1531 /* Make function name accessible from other files, if appropriate. */
1533 if (TREE_PUBLIC (decl))
1535 notice_global_symbol (decl);
1537 globalize_decl (decl);
1539 maybe_assemble_visibility (decl);
1542 if (DECL_PRESERVE_P (decl))
1543 targetm.asm_out.mark_decl_preserved (fnname);
1545 /* Do any machine/system dependent processing of the function name. */
1546 #ifdef ASM_DECLARE_FUNCTION_NAME
1547 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1549 /* Standard thing is just output label for the function. */
1550 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
1551 #endif /* ASM_DECLARE_FUNCTION_NAME */
1554 /* Output assembler code associated with defining the size of the
1555 function. DECL describes the function. NAME is the function's name. */
1558 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1560 #ifdef ASM_DECLARE_FUNCTION_SIZE
1561 /* We could have switched section in the middle of the function. */
1562 if (flag_reorder_blocks_and_partition)
1563 switch_to_section (function_section (decl));
1564 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1566 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1568 output_constant_pool (fnname, decl);
1569 switch_to_section (function_section (decl)); /* need to switch back */
1571 /* Output labels for end of hot/cold text sections (to be used by
1573 if (flag_reorder_blocks_and_partition)
1575 section *save_text_section;
1577 save_text_section = in_section;
1578 switch_to_section (unlikely_text_section ());
1579 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1580 if (first_function_block_is_cold)
1581 switch_to_section (text_section);
1583 switch_to_section (function_section (decl));
1584 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1585 switch_to_section (save_text_section);
1589 /* Assemble code to leave SIZE bytes of zeros. */
1592 assemble_zeros (unsigned HOST_WIDE_INT size)
1594 /* Do no output if -fsyntax-only. */
1595 if (flag_syntax_only)
1598 #ifdef ASM_NO_SKIP_IN_TEXT
1599 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1600 so we must output 0s explicitly in the text section. */
1601 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1603 unsigned HOST_WIDE_INT i;
1604 for (i = 0; i < size; i++)
1605 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1610 ASM_OUTPUT_SKIP (asm_out_file, size);
1613 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1616 assemble_align (int align)
1618 if (align > BITS_PER_UNIT)
1620 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1624 /* Assemble a string constant with the specified C string as contents. */
1627 assemble_string (const char *p, int size)
1632 /* If the string is very long, split it up. */
1636 int thissize = size - pos;
1637 if (thissize > maximum)
1640 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1648 /* A noswitch_section_callback for lcomm_section. */
1651 emit_local (tree decl ATTRIBUTE_UNUSED,
1652 const char *name ATTRIBUTE_UNUSED,
1653 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1654 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1656 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1657 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1658 size, DECL_ALIGN (decl));
1660 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1661 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1664 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1669 /* A noswitch_section_callback for bss_noswitch_section. */
1671 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1673 emit_bss (tree decl ATTRIBUTE_UNUSED,
1674 const char *name ATTRIBUTE_UNUSED,
1675 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1676 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1678 #if defined ASM_OUTPUT_ALIGNED_BSS
1679 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1682 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1688 /* A noswitch_section_callback for comm_section. */
1691 emit_common (tree decl ATTRIBUTE_UNUSED,
1692 const char *name ATTRIBUTE_UNUSED,
1693 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1694 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1696 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1697 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1698 size, DECL_ALIGN (decl));
1700 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1701 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1704 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1709 /* A noswitch_section_callback for tls_comm_section. */
1712 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1713 const char *name ATTRIBUTE_UNUSED,
1714 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1715 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1717 #ifdef ASM_OUTPUT_TLS_COMMON
1718 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1721 sorry ("thread-local COMMON data not implemented");
1726 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1727 NAME is the name of DECL's SYMBOL_REF. */
1730 assemble_noswitch_variable (tree decl, const char *name, section *sect)
1732 unsigned HOST_WIDE_INT size, rounded;
1734 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1737 /* Don't allocate zero bytes of common,
1738 since that means "undefined external" in the linker. */
1742 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1743 so that each uninitialized object starts on such a boundary. */
1744 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1745 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1746 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1748 if (!sect->noswitch.callback (decl, name, size, rounded)
1749 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1750 warning (0, "requested alignment for %q+D is greater than "
1751 "implemented alignment of %wu", decl, rounded);
1754 /* A subroutine of assemble_variable. Output the label and contents of
1755 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1756 is as for assemble_variable. */
1759 assemble_variable_contents (tree decl, const char *name,
1760 bool dont_output_data)
1762 /* Do any machine/system dependent processing of the object. */
1763 #ifdef ASM_DECLARE_OBJECT_NAME
1764 last_assemble_variable_decl = decl;
1765 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1767 /* Standard thing is just output label for the object. */
1768 ASM_OUTPUT_LABEL (asm_out_file, name);
1769 #endif /* ASM_DECLARE_OBJECT_NAME */
1771 if (!dont_output_data)
1773 if (DECL_INITIAL (decl)
1774 && DECL_INITIAL (decl) != error_mark_node
1775 && !initializer_zerop (DECL_INITIAL (decl)))
1776 /* Output the actual data. */
1777 output_constant (DECL_INITIAL (decl),
1778 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1781 /* Leave space for it. */
1782 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1786 /* Assemble everything that is needed for a variable or function declaration.
1787 Not used for automatic variables, and not used for function definitions.
1788 Should not be called for variables of incomplete structure type.
1790 TOP_LEVEL is nonzero if this variable has file scope.
1791 AT_END is nonzero if this is the special handling, at end of compilation,
1792 to define things that have had only tentative definitions.
1793 DONT_OUTPUT_DATA if nonzero means don't actually output the
1794 initial value (that will be done by the caller). */
1797 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1798 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1801 rtx decl_rtl, symbol;
1804 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1805 gcc_assert (TREE_CODE (decl) == VAR_DECL);
1807 /* Emulated TLS had better not get this far. */
1808 gcc_checking_assert (targetm.have_tls || !DECL_THREAD_LOCAL_P (decl));
1810 last_assemble_variable_decl = 0;
1812 /* Normally no need to say anything here for external references,
1813 since assemble_external is called by the language-specific code
1814 when a declaration is first seen. */
1816 if (DECL_EXTERNAL (decl))
1819 /* Do nothing for global register variables. */
1820 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1822 TREE_ASM_WRITTEN (decl) = 1;
1826 /* If type was incomplete when the variable was declared,
1827 see if it is complete now. */
1829 if (DECL_SIZE (decl) == 0)
1830 layout_decl (decl, 0);
1832 /* Still incomplete => don't allocate it; treat the tentative defn
1833 (which is what it must have been) as an `extern' reference. */
1835 if (!dont_output_data && DECL_SIZE (decl) == 0)
1837 error ("storage size of %q+D isn%'t known", decl);
1838 TREE_ASM_WRITTEN (decl) = 1;
1842 /* The first declaration of a variable that comes through this function
1843 decides whether it is global (in C, has external linkage)
1844 or local (in C, has internal linkage). So do nothing more
1845 if this function has already run. */
1847 if (TREE_ASM_WRITTEN (decl))
1850 /* Make sure targetm.encode_section_info is invoked before we set
1852 decl_rtl = DECL_RTL (decl);
1854 TREE_ASM_WRITTEN (decl) = 1;
1856 /* Do no output if -fsyntax-only. */
1857 if (flag_syntax_only)
1860 if (! dont_output_data
1861 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1863 error ("size of variable %q+D is too large", decl);
1867 gcc_assert (MEM_P (decl_rtl));
1868 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
1869 symbol = XEXP (decl_rtl, 0);
1871 /* If this symbol belongs to the tree constant pool, output the constant
1872 if it hasn't already been written. */
1873 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
1875 tree decl = SYMBOL_REF_DECL (symbol);
1876 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
1877 output_constant_def_contents (symbol);
1883 name = XSTR (symbol, 0);
1884 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1885 notice_global_symbol (decl);
1887 /* Compute the alignment of this data. */
1889 align_variable (decl, dont_output_data);
1890 set_mem_align (decl_rtl, DECL_ALIGN (decl));
1892 if (TREE_PUBLIC (decl))
1893 maybe_assemble_visibility (decl);
1895 if (DECL_PRESERVE_P (decl))
1896 targetm.asm_out.mark_decl_preserved (name);
1898 /* First make the assembler name(s) global if appropriate. */
1899 sect = get_variable_section (decl, false);
1900 if (TREE_PUBLIC (decl)
1901 && (sect->common.flags & SECTION_COMMON) == 0)
1902 globalize_decl (decl);
1904 /* Output any data that we will need to use the address of. */
1905 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
1906 output_addressed_constants (DECL_INITIAL (decl));
1908 /* dbxout.c needs to know this. */
1909 if (sect && (sect->common.flags & SECTION_CODE) != 0)
1910 DECL_IN_TEXT_SECTION (decl) = 1;
1912 /* If the decl is part of an object_block, make sure that the decl
1913 has been positioned within its block, but do not write out its
1914 definition yet. output_object_blocks will do that later. */
1915 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
1917 gcc_assert (!dont_output_data);
1918 place_block_symbol (symbol);
1920 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1921 assemble_noswitch_variable (decl, name, sect);
1924 switch_to_section (sect);
1925 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
1926 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
1927 assemble_variable_contents (decl, name, dont_output_data);
1931 /* Return 1 if type TYPE contains any pointers. */
1934 contains_pointers_p (tree type)
1936 switch (TREE_CODE (type))
1939 case REFERENCE_TYPE:
1940 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1941 so I'll play safe and return 1. */
1947 case QUAL_UNION_TYPE:
1950 /* For a type that has fields, see if the fields have pointers. */
1951 for (fields = TYPE_FIELDS (type); fields; fields = DECL_CHAIN (fields))
1952 if (TREE_CODE (fields) == FIELD_DECL
1953 && contains_pointers_p (TREE_TYPE (fields)))
1959 /* An array type contains pointers if its element type does. */
1960 return contains_pointers_p (TREE_TYPE (type));
1967 /* We delay assemble_external processing until
1968 the compilation unit is finalized. This is the best we can do for
1969 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
1970 it all the way to final. See PR 17982 for further discussion. */
1971 static GTY(()) tree pending_assemble_externals;
1973 #ifdef ASM_OUTPUT_EXTERNAL
1974 /* True if DECL is a function decl for which no out-of-line copy exists.
1975 It is assumed that DECL's assembler name has been set. */
1978 incorporeal_function_p (tree decl)
1980 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1984 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
1985 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
1988 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1989 if (is_builtin_name (name))
1995 /* Actually do the tests to determine if this is necessary, and invoke
1996 ASM_OUTPUT_EXTERNAL. */
1998 assemble_external_real (tree decl)
2000 rtx rtl = DECL_RTL (decl);
2002 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2003 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2004 && !incorporeal_function_p (decl))
2006 /* Some systems do require some output. */
2007 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2008 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2014 process_pending_assemble_externals (void)
2016 #ifdef ASM_OUTPUT_EXTERNAL
2018 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2019 assemble_external_real (TREE_VALUE (list));
2021 pending_assemble_externals = 0;
2025 /* This TREE_LIST contains any weak symbol declarations waiting
2027 static GTY(()) tree weak_decls;
2029 /* Output something to declare an external symbol to the assembler,
2030 and qualifiers such as weakness. (Most assemblers don't need
2031 extern declaration, so we normally output nothing.) Do nothing if
2032 DECL is not external. */
2035 assemble_external (tree decl ATTRIBUTE_UNUSED)
2037 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2038 main body of this code is only rarely exercised. To provide some
2039 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2040 open. If it's not, we should not be calling this function. */
2041 gcc_assert (asm_out_file);
2043 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2046 /* We want to output annotation for weak and external symbols at
2047 very last to check if they are references or not. */
2051 /* TREE_STATIC is a weird and abused creature which is not
2052 generally the right test for whether an entity has been
2053 locally emitted, inlined or otherwise not-really-extern, but
2054 for declarations that can be weak, it happens to be
2056 && !TREE_STATIC (decl)
2057 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2058 && value_member (decl, weak_decls) == NULL_TREE)
2059 weak_decls = tree_cons (NULL, decl, weak_decls);
2061 #ifdef ASM_OUTPUT_EXTERNAL
2062 if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2063 pending_assemble_externals = tree_cons (NULL, decl,
2064 pending_assemble_externals);
2068 /* Similar, for calling a library function FUN. */
2071 assemble_external_libcall (rtx fun)
2073 /* Declare library function name external when first used, if nec. */
2074 if (! SYMBOL_REF_USED (fun))
2076 SYMBOL_REF_USED (fun) = 1;
2077 targetm.asm_out.external_libcall (fun);
2081 /* Assemble a label named NAME. */
2084 assemble_label (FILE *file, const char *name)
2086 ASM_OUTPUT_LABEL (file, name);
2089 /* Set the symbol_referenced flag for ID. */
2091 mark_referenced (tree id)
2093 TREE_SYMBOL_REFERENCED (id) = 1;
2096 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2098 mark_decl_referenced (tree decl)
2100 if (TREE_CODE (decl) == FUNCTION_DECL)
2102 /* Extern inline functions don't become needed when referenced.
2103 If we know a method will be emitted in other TU and no new
2104 functions can be marked reachable, just use the external
2106 struct cgraph_node *node = cgraph_node (decl);
2107 if (!DECL_EXTERNAL (decl)
2108 && (!node->local.vtable_method || !cgraph_global_info_ready
2109 || !node->local.finalized))
2110 cgraph_mark_needed_node (node);
2112 else if (TREE_CODE (decl) == VAR_DECL)
2114 struct varpool_node *node = varpool_node (decl);
2115 varpool_mark_needed_node (node);
2116 /* C++ frontend use mark_decl_references to force COMDAT variables
2117 to be output that might appear dead otherwise. */
2118 node->force_output = true;
2120 /* else do nothing - we can get various sorts of CST nodes here,
2121 which do not need to be marked. */
2125 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2126 until we find an identifier that is not itself a transparent alias.
2127 Modify the alias passed to it by reference (and all aliases on the
2128 way to the ultimate target), such that they do not have to be
2129 followed again, and return the ultimate target of the alias
2133 ultimate_transparent_alias_target (tree *alias)
2135 tree target = *alias;
2137 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2139 gcc_assert (TREE_CHAIN (target));
2140 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2141 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2142 && ! TREE_CHAIN (target));
2149 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2150 starts with a *, the rest of NAME is output verbatim. Otherwise
2151 NAME is transformed in a target-specific way (usually by the
2152 addition of an underscore). */
2155 assemble_name_raw (FILE *file, const char *name)
2158 fputs (&name[1], file);
2160 ASM_OUTPUT_LABELREF (file, name);
2163 /* Like assemble_name_raw, but should be used when NAME might refer to
2164 an entity that is also represented as a tree (like a function or
2165 variable). If NAME does refer to such an entity, that entity will
2166 be marked as referenced. */
2169 assemble_name (FILE *file, const char *name)
2171 const char *real_name;
2174 real_name = targetm.strip_name_encoding (name);
2176 id = maybe_get_identifier (real_name);
2181 mark_referenced (id);
2182 ultimate_transparent_alias_target (&id);
2184 name = IDENTIFIER_POINTER (id);
2185 gcc_assert (! TREE_CHAIN (id));
2188 assemble_name_raw (file, name);
2191 /* Allocate SIZE bytes writable static space with a gensym name
2192 and return an RTX to refer to its address. */
2195 assemble_static_space (unsigned HOST_WIDE_INT size)
2198 const char *namestring;
2201 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2203 namestring = ggc_strdup (name);
2205 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2206 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2208 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2209 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2212 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2213 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2216 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2217 so that each uninitialized object starts on such a boundary. */
2218 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2219 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2220 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2221 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2222 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2223 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2230 /* Assemble the static constant template for function entry trampolines.
2231 This is done at most once per compilation.
2232 Returns an RTX for the address of the template. */
2234 static GTY(()) rtx initial_trampoline;
2237 assemble_trampoline_template (void)
2244 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2246 if (initial_trampoline)
2247 return initial_trampoline;
2249 /* By default, put trampoline templates in read-only data section. */
2251 #ifdef TRAMPOLINE_SECTION
2252 switch_to_section (TRAMPOLINE_SECTION);
2254 switch_to_section (readonly_data_section);
2257 /* Write the assembler code to define one. */
2258 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2260 ASM_OUTPUT_ALIGN (asm_out_file, align);
2262 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2263 targetm.asm_out.trampoline_template (asm_out_file);
2265 /* Record the rtl to refer to it. */
2266 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2267 name = ggc_strdup (label);
2268 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2269 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2271 initial_trampoline = gen_const_mem (BLKmode, symbol);
2272 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2273 set_mem_size (initial_trampoline, GEN_INT (TRAMPOLINE_SIZE));
2275 return initial_trampoline;
2278 /* A and B are either alignments or offsets. Return the minimum alignment
2279 that may be assumed after adding the two together. */
2281 static inline unsigned
2282 min_align (unsigned int a, unsigned int b)
2284 return (a | b) & -(a | b);
2287 /* Return the assembler directive for creating a given kind of integer
2288 object. SIZE is the number of bytes in the object and ALIGNED_P
2289 indicates whether it is known to be aligned. Return NULL if the
2290 assembly dialect has no such directive.
2292 The returned string should be printed at the start of a new line and
2293 be followed immediately by the object's initial value. */
2296 integer_asm_op (int size, int aligned_p)
2298 struct asm_int_op *ops;
2301 ops = &targetm.asm_out.aligned_op;
2303 ops = &targetm.asm_out.unaligned_op;
2308 return targetm.asm_out.byte_op;
2322 /* Use directive OP to assemble an integer object X. Print OP at the
2323 start of the line, followed immediately by the value of X. */
2326 assemble_integer_with_op (const char *op, rtx x)
2328 fputs (op, asm_out_file);
2329 output_addr_const (asm_out_file, x);
2330 fputc ('\n', asm_out_file);
2333 /* The default implementation of the asm_out.integer target hook. */
2336 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2337 unsigned int size ATTRIBUTE_UNUSED,
2338 int aligned_p ATTRIBUTE_UNUSED)
2340 const char *op = integer_asm_op (size, aligned_p);
2341 /* Avoid GAS bugs for large values. Specifically negative values whose
2342 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2343 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2345 return op && (assemble_integer_with_op (op, x), true);
2348 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2349 the alignment of the integer in bits. Return 1 if we were able to output
2350 the constant, otherwise 0. We must be able to output the constant,
2351 if FORCE is nonzero. */
2354 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2358 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2360 /* See if the target hook can handle this kind of object. */
2361 if (targetm.asm_out.integer (x, size, aligned_p))
2364 /* If the object is a multi-byte one, try splitting it up. Split
2365 it into words it if is multi-word, otherwise split it into bytes. */
2368 enum machine_mode omode, imode;
2369 unsigned int subalign;
2370 unsigned int subsize, i;
2371 enum mode_class mclass;
2373 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2374 subalign = MIN (align, subsize * BITS_PER_UNIT);
2375 if (GET_CODE (x) == CONST_FIXED)
2376 mclass = GET_MODE_CLASS (GET_MODE (x));
2380 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2381 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2383 for (i = 0; i < size; i += subsize)
2385 rtx partial = simplify_subreg (omode, x, imode, i);
2386 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2392 /* If we've printed some of it, but not all of it, there's no going
2397 gcc_assert (!force);
2403 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2405 long data[4] = {0, 0, 0, 0};
2407 int bitsize, nelts, nunits, units_per;
2409 /* This is hairy. We have a quantity of known size. real_to_target
2410 will put it into an array of *host* longs, 32 bits per element
2411 (even if long is more than 32 bits). We need to determine the
2412 number of array elements that are occupied (nelts) and the number
2413 of *target* min-addressable units that will be occupied in the
2414 object file (nunits). We cannot assume that 32 divides the
2415 mode's bitsize (size * BITS_PER_UNIT) evenly.
2417 size * BITS_PER_UNIT is used here to make sure that padding bits
2418 (which might appear at either end of the value; real_to_target
2419 will include the padding bits in its output array) are included. */
2421 nunits = GET_MODE_SIZE (mode);
2422 bitsize = nunits * BITS_PER_UNIT;
2423 nelts = CEIL (bitsize, 32);
2424 units_per = 32 / BITS_PER_UNIT;
2426 real_to_target (data, &d, mode);
2428 /* Put out the first word with the specified alignment. */
2429 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2430 nunits -= units_per;
2432 /* Subsequent words need only 32-bit alignment. */
2433 align = min_align (align, 32);
2435 for (i = 1; i < nelts; i++)
2437 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2438 nunits -= units_per;
2442 /* Given an expression EXP with a constant value,
2443 reduce it to the sum of an assembler symbol and an integer.
2444 Store them both in the structure *VALUE.
2445 EXP must be reducible. */
2447 struct GTY(()) addr_const {
2449 HOST_WIDE_INT offset;
2453 decode_addr_const (tree exp, struct addr_const *value)
2455 tree target = TREE_OPERAND (exp, 0);
2461 if (TREE_CODE (target) == COMPONENT_REF
2462 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2464 offset += int_byte_position (TREE_OPERAND (target, 1));
2465 target = TREE_OPERAND (target, 0);
2467 else if (TREE_CODE (target) == ARRAY_REF
2468 || TREE_CODE (target) == ARRAY_RANGE_REF)
2470 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2471 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2472 target = TREE_OPERAND (target, 0);
2474 else if (TREE_CODE (target) == INDIRECT_REF
2475 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2476 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2478 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2483 switch (TREE_CODE (target))
2487 x = DECL_RTL (target);
2491 x = gen_rtx_MEM (FUNCTION_MODE,
2492 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2501 x = output_constant_def (target, 1);
2508 gcc_assert (MEM_P (x));
2512 value->offset = offset;
2516 static GTY((param_is (struct constant_descriptor_tree)))
2517 htab_t const_desc_htab;
2519 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2521 /* Constant pool accessor function. */
2524 constant_pool_htab (void)
2526 return const_desc_htab;
2529 /* Compute a hash code for a constant expression. */
2532 const_desc_hash (const void *ptr)
2534 return ((const struct constant_descriptor_tree *)ptr)->hash;
2538 const_hash_1 (const tree exp)
2543 enum tree_code code = TREE_CODE (exp);
2545 /* Either set P and LEN to the address and len of something to hash and
2546 exit the switch or return a value. */
2551 p = (char *) &TREE_INT_CST (exp);
2552 len = sizeof TREE_INT_CST (exp);
2556 return real_hash (TREE_REAL_CST_PTR (exp));
2559 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2562 p = TREE_STRING_POINTER (exp);
2563 len = TREE_STRING_LENGTH (exp);
2567 return (const_hash_1 (TREE_REALPART (exp)) * 5
2568 + const_hash_1 (TREE_IMAGPART (exp)));
2574 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2576 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2577 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2584 unsigned HOST_WIDE_INT idx;
2587 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2589 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2591 hi = hi * 603 + const_hash_1 (value);
2599 struct addr_const value;
2601 decode_addr_const (exp, &value);
2602 switch (GET_CODE (value.base))
2605 /* Don't hash the address of the SYMBOL_REF;
2606 only use the offset and the symbol name. */
2608 p = XSTR (value.base, 0);
2609 for (i = 0; p[i] != 0; i++)
2610 hi = ((hi * 613) + (unsigned) (p[i]));
2614 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2624 case POINTER_PLUS_EXPR:
2626 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2627 + const_hash_1 (TREE_OPERAND (exp, 1)));
2630 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2633 /* A language specific constant. Just hash the code. */
2637 /* Compute hashing function. */
2639 for (i = 0; i < len; i++)
2640 hi = ((hi * 613) + (unsigned) (p[i]));
2645 /* Wrapper of compare_constant, for the htab interface. */
2647 const_desc_eq (const void *p1, const void *p2)
2649 const struct constant_descriptor_tree *const c1
2650 = (const struct constant_descriptor_tree *) p1;
2651 const struct constant_descriptor_tree *const c2
2652 = (const struct constant_descriptor_tree *) p2;
2653 if (c1->hash != c2->hash)
2655 return compare_constant (c1->value, c2->value);
2658 /* Compare t1 and t2, and return 1 only if they are known to result in
2659 the same bit pattern on output. */
2662 compare_constant (const tree t1, const tree t2)
2664 enum tree_code typecode;
2666 if (t1 == NULL_TREE)
2667 return t2 == NULL_TREE;
2668 if (t2 == NULL_TREE)
2671 if (TREE_CODE (t1) != TREE_CODE (t2))
2674 switch (TREE_CODE (t1))
2677 /* Integer constants are the same only if the same width of type. */
2678 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2680 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2682 return tree_int_cst_equal (t1, t2);
2685 /* Real constants are the same only if the same width of type. */
2686 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2689 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2692 /* Fixed constants are the same only if the same width of type. */
2693 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2696 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
2699 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2702 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2703 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2704 TREE_STRING_LENGTH (t1)));
2707 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2708 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2714 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
2715 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
2718 link2 = TREE_VECTOR_CST_ELTS (t2);
2719 for (link1 = TREE_VECTOR_CST_ELTS (t1);
2721 link1 = TREE_CHAIN (link1))
2723 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
2725 link2 = TREE_CHAIN (link2);
2733 VEC(constructor_elt, gc) *v1, *v2;
2734 unsigned HOST_WIDE_INT idx;
2736 typecode = TREE_CODE (TREE_TYPE (t1));
2737 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2740 if (typecode == ARRAY_TYPE)
2742 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2743 /* For arrays, check that the sizes all match. */
2744 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2746 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2751 /* For record and union constructors, require exact type
2753 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2757 v1 = CONSTRUCTOR_ELTS (t1);
2758 v2 = CONSTRUCTOR_ELTS (t2);
2759 if (VEC_length (constructor_elt, v1)
2760 != VEC_length (constructor_elt, v2))
2763 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
2765 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
2766 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
2768 /* Check that each value is the same... */
2769 if (!compare_constant (c1->value, c2->value))
2771 /* ... and that they apply to the same fields! */
2772 if (typecode == ARRAY_TYPE)
2774 if (!compare_constant (c1->index, c2->index))
2779 if (c1->index != c2->index)
2790 struct addr_const value1, value2;
2794 decode_addr_const (t1, &value1);
2795 decode_addr_const (t2, &value2);
2797 if (value1.offset != value2.offset)
2800 code = GET_CODE (value1.base);
2801 if (code != GET_CODE (value2.base))
2807 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2811 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
2812 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
2822 case POINTER_PLUS_EXPR:
2825 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2826 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2829 case VIEW_CONVERT_EXPR:
2830 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2839 /* Make a copy of the whole tree structure for a constant. This
2840 handles the same types of nodes that compare_constant handles. */
2843 copy_constant (tree exp)
2845 switch (TREE_CODE (exp))
2848 /* For ADDR_EXPR, we do not want to copy the decl whose address
2849 is requested. We do want to copy constants though. */
2850 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
2851 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2852 copy_constant (TREE_OPERAND (exp, 0)));
2854 return copy_node (exp);
2860 return copy_node (exp);
2863 return build_complex (TREE_TYPE (exp),
2864 copy_constant (TREE_REALPART (exp)),
2865 copy_constant (TREE_IMAGPART (exp)));
2868 case POINTER_PLUS_EXPR:
2870 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
2871 copy_constant (TREE_OPERAND (exp, 0)),
2872 copy_constant (TREE_OPERAND (exp, 1)));
2875 case VIEW_CONVERT_EXPR:
2876 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2877 copy_constant (TREE_OPERAND (exp, 0)));
2880 return build_vector (TREE_TYPE (exp),
2881 copy_list (TREE_VECTOR_CST_ELTS (exp)));
2885 tree copy = copy_node (exp);
2886 VEC(constructor_elt, gc) *v;
2887 unsigned HOST_WIDE_INT idx;
2888 tree purpose, value;
2890 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
2891 CONSTRUCTOR_ELTS (exp)));
2892 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
2894 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
2895 ce->index = purpose;
2896 ce->value = copy_constant (value);
2898 CONSTRUCTOR_ELTS (copy) = v;
2907 /* Return the section into which constant EXP should be placed. */
2910 get_constant_section (tree exp, unsigned int align)
2912 return targetm.asm_out.select_section (exp,
2913 compute_reloc_for_constant (exp),
2917 /* Return the size of constant EXP in bytes. */
2919 static HOST_WIDE_INT
2920 get_constant_size (tree exp)
2924 size = int_size_in_bytes (TREE_TYPE (exp));
2925 if (TREE_CODE (exp) == STRING_CST)
2926 size = MAX (TREE_STRING_LENGTH (exp), size);
2930 /* Subroutine of output_constant_def:
2931 No constant equal to EXP is known to have been output.
2932 Make a constant descriptor to enter EXP in the hash table.
2933 Assign the label number and construct RTL to refer to the
2934 constant's location in memory.
2935 Caller is responsible for updating the hash table. */
2937 static struct constant_descriptor_tree *
2938 build_constant_desc (tree exp)
2940 struct constant_descriptor_tree *desc;
2946 desc = ggc_alloc_constant_descriptor_tree ();
2947 desc->value = copy_constant (exp);
2949 /* Propagate marked-ness to copied constant. */
2950 if (flag_mudflap && mf_marked_p (exp))
2951 mf_mark (desc->value);
2953 /* Create a string containing the label name, in LABEL. */
2954 labelno = const_labelno++;
2955 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2957 /* Construct the VAR_DECL associated with the constant. */
2958 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
2960 DECL_ARTIFICIAL (decl) = 1;
2961 DECL_IGNORED_P (decl) = 1;
2962 TREE_READONLY (decl) = 1;
2963 TREE_STATIC (decl) = 1;
2964 TREE_ADDRESSABLE (decl) = 1;
2965 /* We don't set the RTL yet as this would cause varpool to assume that the
2966 variable is referenced. Moreover, it would just be dropped in LTO mode.
2967 Instead we set the flag that will be recognized in make_decl_rtl. */
2968 DECL_IN_CONSTANT_POOL (decl) = 1;
2969 DECL_INITIAL (decl) = desc->value;
2970 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
2971 architectures so use DATA_ALIGNMENT as well, except for strings. */
2972 if (TREE_CODE (exp) == STRING_CST)
2974 #ifdef CONSTANT_ALIGNMENT
2975 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
2979 align_variable (decl, 0);
2981 /* Now construct the SYMBOL_REF and the MEM. */
2982 if (use_object_blocks_p ())
2984 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
2985 symbol = create_block_symbol (ggc_strdup (label),
2986 get_block_for_section (sect), -1);
2989 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2990 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
2991 SET_SYMBOL_REF_DECL (symbol, decl);
2992 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2994 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2995 set_mem_attributes (rtl, exp, 1);
2996 set_mem_alias_set (rtl, 0);
2997 set_mem_alias_set (rtl, const_alias_set);
2999 /* We cannot share RTX'es in pool entries.
3000 Mark this piece of RTL as required for unsharing. */
3001 RTX_FLAG (rtl, used) = 1;
3003 /* Set flags or add text to the name to record information, such as
3004 that it is a local symbol. If the name is changed, the macro
3005 ASM_OUTPUT_LABELREF will have to know how to strip this
3006 information. This call might invalidate our local variable
3007 SYMBOL; we can't use it afterward. */
3008 targetm.encode_section_info (exp, rtl, true);
3015 /* Return an rtx representing a reference to constant data in memory
3016 for the constant expression EXP.
3018 If assembler code for such a constant has already been output,
3019 return an rtx to refer to it.
3020 Otherwise, output such a constant in memory
3021 and generate an rtx for it.
3023 If DEFER is nonzero, this constant can be deferred and output only
3024 if referenced in the function after all optimizations.
3026 `const_desc_table' records which constants already have label strings. */
3029 output_constant_def (tree exp, int defer)
3031 struct constant_descriptor_tree *desc;
3032 struct constant_descriptor_tree key;
3035 /* Look up EXP in the table of constant descriptors. If we didn't find
3036 it, create a new one. */
3038 key.hash = const_hash_1 (exp);
3039 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3041 desc = (struct constant_descriptor_tree *) *loc;
3044 desc = build_constant_desc (exp);
3045 desc->hash = key.hash;
3049 maybe_output_constant_def_contents (desc, defer);
3053 /* Subroutine of output_constant_def: Decide whether or not we need to
3054 output the constant DESC now, and if so, do it. */
3056 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3059 rtx symbol = XEXP (desc->rtl, 0);
3060 tree exp = desc->value;
3062 if (flag_syntax_only)
3065 if (TREE_ASM_WRITTEN (exp))
3066 /* Already output; don't do it again. */
3069 /* We can always defer constants as long as the context allows
3073 /* Increment n_deferred_constants if it exists. It needs to be at
3074 least as large as the number of constants actually referred to
3075 by the function. If it's too small we'll stop looking too early
3076 and fail to emit constants; if it's too large we'll only look
3077 through the entire function when we could have stopped earlier. */
3079 n_deferred_constants++;
3083 output_constant_def_contents (symbol);
3086 /* Subroutine of output_constant_def_contents. Output the definition
3087 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3088 constant's alignment in bits. */
3091 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3095 size = get_constant_size (exp);
3097 /* Do any machine/system dependent processing of the constant. */
3098 targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3100 /* Output the value of EXP. */
3101 output_constant (exp, size, align);
3104 /* We must output the constant data referred to by SYMBOL; do so. */
3107 output_constant_def_contents (rtx symbol)
3109 tree decl = SYMBOL_REF_DECL (symbol);
3110 tree exp = DECL_INITIAL (decl);
3113 /* Make sure any other constants whose addresses appear in EXP
3114 are assigned label numbers. */
3115 output_addressed_constants (exp);
3117 /* We are no longer deferring this constant. */
3118 TREE_ASM_WRITTEN (exp) = 1;
3120 /* If the constant is part of an object block, make sure that the
3121 decl has been positioned within its block, but do not write out
3122 its definition yet. output_object_blocks will do that later. */
3123 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3124 place_block_symbol (symbol);
3127 align = DECL_ALIGN (decl);
3128 switch_to_section (get_constant_section (exp, align));
3129 if (align > BITS_PER_UNIT)
3130 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3131 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3134 mudflap_enqueue_constant (exp);
3137 /* Look up EXP in the table of constant descriptors. Return the rtl
3138 if it has been emitted, else null. */
3141 lookup_constant_def (tree exp)
3143 struct constant_descriptor_tree *desc;
3144 struct constant_descriptor_tree key;
3147 key.hash = const_hash_1 (exp);
3148 desc = (struct constant_descriptor_tree *)
3149 htab_find_with_hash (const_desc_htab, &key, key.hash);
3151 return (desc ? desc->rtl : NULL_RTX);
3154 /* Return a tree representing a reference to constant data in memory
3155 for the constant expression EXP.
3157 This is the counterpart of output_constant_def at the Tree level. */
3160 tree_output_constant_def (tree exp)
3162 struct constant_descriptor_tree *desc, key;
3166 /* Look up EXP in the table of constant descriptors. If we didn't find
3167 it, create a new one. */
3169 key.hash = const_hash_1 (exp);
3170 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3172 desc = (struct constant_descriptor_tree *) *loc;
3175 desc = build_constant_desc (exp);
3176 desc->hash = key.hash;
3180 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3181 varpool_finalize_decl (decl);
3185 /* Used in the hash tables to avoid outputting the same constant
3186 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3187 are output once per function, not once per file. */
3188 /* ??? Only a few targets need per-function constant pools. Most
3189 can use one per-file pool. Should add a targetm bit to tell the
3192 struct GTY(()) rtx_constant_pool {
3193 /* Pointers to first and last constant in pool, as ordered by offset. */
3194 struct constant_descriptor_rtx *first;
3195 struct constant_descriptor_rtx *last;
3197 /* Hash facility for making memory-constants from constant rtl-expressions.
3198 It is used on RISC machines where immediate integer arguments and
3199 constant addresses are restricted so that such constants must be stored
3201 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3203 /* Current offset in constant pool (does not include any
3204 machine-specific header). */
3205 HOST_WIDE_INT offset;
3208 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3209 struct constant_descriptor_rtx *next;
3213 HOST_WIDE_INT offset;
3215 enum machine_mode mode;
3221 /* Hash and compare functions for const_rtx_htab. */
3224 const_desc_rtx_hash (const void *ptr)
3226 const struct constant_descriptor_rtx *const desc
3227 = (const struct constant_descriptor_rtx *) ptr;
3232 const_desc_rtx_eq (const void *a, const void *b)
3234 const struct constant_descriptor_rtx *const x
3235 = (const struct constant_descriptor_rtx *) a;
3236 const struct constant_descriptor_rtx *const y
3237 = (const struct constant_descriptor_rtx *) b;
3239 if (x->mode != y->mode)
3241 return rtx_equal_p (x->constant, y->constant);
3244 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3247 const_rtx_hash_1 (rtx *xp, void *data)
3249 unsigned HOST_WIDE_INT hwi;
3250 enum machine_mode mode;
3256 code = GET_CODE (x);
3257 mode = GET_MODE (x);
3258 h = (hashval_t) code * 1048573 + mode;
3266 int shift = sizeof (hashval_t) * CHAR_BIT;
3267 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3270 h ^= (hashval_t) hwi;
3271 for (i = 1; i < n; ++i)
3274 h ^= (hashval_t) hwi;
3280 if (mode == VOIDmode)
3282 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3286 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3290 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3296 for (i = XVECLEN (x, 0); i-- > 0; )
3297 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3302 h ^= htab_hash_string (XSTR (x, 0));
3306 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3310 case UNSPEC_VOLATILE:
3311 h = h * 251 + XINT (x, 1);
3318 hp = (hashval_t *) data;
3319 *hp = *hp * 509 + h;
3323 /* Compute a hash value for X, which should be a constant. */
3326 const_rtx_hash (rtx x)
3329 for_each_rtx (&x, const_rtx_hash_1, &h);
3334 /* Create and return a new rtx constant pool. */
3336 static struct rtx_constant_pool *
3337 create_constant_pool (void)
3339 struct rtx_constant_pool *pool;
3341 pool = ggc_alloc_rtx_constant_pool ();
3342 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3343 const_desc_rtx_eq, NULL);
3350 /* Initialize constant pool hashing for a new function. */
3353 init_varasm_status (void)
3355 crtl->varasm.pool = create_constant_pool ();
3356 crtl->varasm.deferred_constants = 0;
3359 /* Given a MINUS expression, simplify it if both sides
3360 include the same symbol. */
3363 simplify_subtraction (rtx x)
3365 rtx r = simplify_rtx (x);
3369 /* Given a constant rtx X, make (or find) a memory constant for its value
3370 and return a MEM rtx to refer to it in memory. */
3373 force_const_mem (enum machine_mode mode, rtx x)
3375 struct constant_descriptor_rtx *desc, tmp;
3376 struct rtx_constant_pool *pool;
3383 /* If we're not allowed to drop X into the constant pool, don't. */
3384 if (targetm.cannot_force_const_mem (x))
3387 /* Record that this function has used a constant pool entry. */
3388 crtl->uses_const_pool = 1;
3390 /* Decide which pool to use. */
3391 pool = (targetm.use_blocks_for_constant_p (mode, x)
3392 ? shared_constant_pool
3393 : crtl->varasm.pool);
3395 /* Lookup the value in the hashtable. */
3398 hash = const_rtx_hash (x);
3399 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3400 desc = (struct constant_descriptor_rtx *) *slot;
3402 /* If the constant was already present, return its memory. */
3404 return copy_rtx (desc->mem);
3406 /* Otherwise, create a new descriptor. */
3407 desc = ggc_alloc_constant_descriptor_rtx ();
3410 /* Align the location counter as required by EXP's data type. */
3411 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3412 #ifdef CONSTANT_ALIGNMENT
3414 tree type = lang_hooks.types.type_for_mode (mode, 0);
3415 if (type != NULL_TREE)
3416 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3420 pool->offset += (align / BITS_PER_UNIT) - 1;
3421 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3424 desc->constant = tmp.constant;
3425 desc->offset = pool->offset;
3428 desc->align = align;
3429 desc->labelno = const_labelno;
3432 pool->offset += GET_MODE_SIZE (mode);
3434 pool->last->next = desc;
3436 pool->first = pool->last = desc;
3439 /* Create a string containing the label name, in LABEL. */
3440 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3443 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3444 the constants pool. */
3445 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3447 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3448 symbol = create_block_symbol (ggc_strdup (label),
3449 get_block_for_section (sect), -1);
3452 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3454 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3455 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3456 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3458 /* Construct the MEM. */
3459 desc->mem = def = gen_const_mem (mode, symbol);
3460 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3461 set_mem_align (def, align);
3463 /* If we're dropping a label to the constant pool, make sure we
3465 if (GET_CODE (x) == LABEL_REF)
3466 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3468 return copy_rtx (def);
3471 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3474 get_pool_constant (rtx addr)
3476 return SYMBOL_REF_CONSTANT (addr)->constant;
3479 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3480 and whether it has been output or not. */
3483 get_pool_constant_mark (rtx addr, bool *pmarked)
3485 struct constant_descriptor_rtx *desc;
3487 desc = SYMBOL_REF_CONSTANT (addr);
3488 *pmarked = (desc->mark != 0);
3489 return desc->constant;
3492 /* Similar, return the mode. */
3495 get_pool_mode (const_rtx addr)
3497 return SYMBOL_REF_CONSTANT (addr)->mode;
3500 /* Return the size of the constant pool. */
3503 get_pool_size (void)
3505 return crtl->varasm.pool->offset;
3508 /* Worker function for output_constant_pool_1. Emit assembly for X
3509 in MODE with known alignment ALIGN. */
3512 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3514 switch (GET_MODE_CLASS (mode))
3517 case MODE_DECIMAL_FLOAT:
3521 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3522 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3523 assemble_real (r, mode, align);
3528 case MODE_PARTIAL_INT:
3533 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3536 case MODE_VECTOR_FLOAT:
3537 case MODE_VECTOR_INT:
3538 case MODE_VECTOR_FRACT:
3539 case MODE_VECTOR_UFRACT:
3540 case MODE_VECTOR_ACCUM:
3541 case MODE_VECTOR_UACCUM:
3544 enum machine_mode submode = GET_MODE_INNER (mode);
3545 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3547 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3548 units = CONST_VECTOR_NUNITS (x);
3550 for (i = 0; i < units; i++)
3552 rtx elt = CONST_VECTOR_ELT (x, i);
3553 output_constant_pool_2 (submode, elt, i ? subalign : align);
3563 /* Worker function for output_constant_pool. Emit constant DESC,
3564 giving it ALIGN bits of alignment. */
3567 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3574 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3575 whose CODE_LABEL has been deleted. This can occur if a jump table
3576 is eliminated by optimization. If so, write a constant of zero
3577 instead. Note that this can also happen by turning the
3578 CODE_LABEL into a NOTE. */
3579 /* ??? This seems completely and utterly wrong. Certainly it's
3580 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3581 functioning even with INSN_DELETED_P and friends. */
3584 switch (GET_CODE (tmp))
3587 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3588 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3590 tmp = XEXP (XEXP (tmp, 0), 0);
3594 tmp = XEXP (tmp, 0);
3595 gcc_assert (!INSN_DELETED_P (tmp));
3596 gcc_assert (!NOTE_P (tmp)
3597 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3604 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3605 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3606 align, desc->labelno, done);
3609 assemble_align (align);
3611 /* Output the label. */
3612 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3614 /* Output the data. */
3615 output_constant_pool_2 (desc->mode, x, align);
3617 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3618 sections have proper size. */
3619 if (align > GET_MODE_BITSIZE (desc->mode)
3621 && (in_section->common.flags & SECTION_MERGE))
3622 assemble_align (align);
3624 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3630 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3631 to as used. Emit referenced deferred strings. This function can
3632 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3635 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3637 rtx x = *current_rtx;
3639 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3642 if (CONSTANT_POOL_ADDRESS_P (x))
3644 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3645 if (desc->mark == 0)
3648 for_each_rtx (&desc->constant, mark_constant, NULL);
3651 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3653 tree decl = SYMBOL_REF_DECL (x);
3654 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
3656 n_deferred_constants--;
3657 output_constant_def_contents (x);
3664 /* Look through appropriate parts of INSN, marking all entries in the
3665 constant pool which are actually being used. Entries that are only
3666 referenced by other constants are also marked as used. Emit
3667 deferred strings that are used. */
3670 mark_constants (rtx insn)
3675 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3676 insns, not any notes that may be attached. We don't want to mark
3677 a constant just because it happens to appear in a REG_EQUIV note. */
3678 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3680 rtx seq = PATTERN (insn);
3681 int i, n = XVECLEN (seq, 0);
3682 for (i = 0; i < n; ++i)
3684 rtx subinsn = XVECEXP (seq, 0, i);
3685 if (INSN_P (subinsn))
3686 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
3690 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
3693 /* Look through the instructions for this function, and mark all the
3694 entries in POOL which are actually being used. Emit deferred constants
3695 which have indeed been used. */
3698 mark_constant_pool (void)
3702 if (!crtl->uses_const_pool && n_deferred_constants == 0)
3705 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3706 mark_constants (insn);
3708 for (link = crtl->epilogue_delay_list;
3710 link = XEXP (link, 1))
3711 mark_constants (XEXP (link, 0));
3714 /* Write all the constants in POOL. */
3717 output_constant_pool_contents (struct rtx_constant_pool *pool)
3719 struct constant_descriptor_rtx *desc;
3721 for (desc = pool->first; desc ; desc = desc->next)
3724 /* If the constant is part of an object_block, make sure that
3725 the constant has been positioned within its block, but do not
3726 write out its definition yet. output_object_blocks will do
3728 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
3729 && SYMBOL_REF_BLOCK (desc->sym))
3730 place_block_symbol (desc->sym);
3733 switch_to_section (targetm.asm_out.select_rtx_section
3734 (desc->mode, desc->constant, desc->align));
3735 output_constant_pool_1 (desc, desc->align);
3740 /* Mark all constants that are used in the current function, then write
3741 out the function's private constant pool. */
3744 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3745 tree fndecl ATTRIBUTE_UNUSED)
3747 struct rtx_constant_pool *pool = crtl->varasm.pool;
3749 /* It is possible for gcc to call force_const_mem and then to later
3750 discard the instructions which refer to the constant. In such a
3751 case we do not need to output the constant. */
3752 mark_constant_pool ();
3754 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3755 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3758 output_constant_pool_contents (pool);
3760 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3761 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3765 /* Write the contents of the shared constant pool. */
3768 output_shared_constant_pool (void)
3770 output_constant_pool_contents (shared_constant_pool);
3773 /* Determine what kind of relocations EXP may need. */
3776 compute_reloc_for_constant (tree exp)
3778 int reloc = 0, reloc2;
3781 switch (TREE_CODE (exp))
3785 /* Go inside any operations that get_inner_reference can handle and see
3786 if what's inside is a constant: no need to do anything here for
3787 addresses of variables or functions. */
3788 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3789 tem = TREE_OPERAND (tem, 0))
3792 if (TREE_PUBLIC (tem))
3799 case POINTER_PLUS_EXPR:
3800 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3801 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3805 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3806 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3807 /* The difference of two local labels is computable at link time. */
3808 if (reloc == 1 && reloc2 == 1)
3815 case VIEW_CONVERT_EXPR:
3816 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3821 unsigned HOST_WIDE_INT idx;
3822 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
3824 reloc |= compute_reloc_for_constant (tem);
3834 /* Find all the constants whose addresses are referenced inside of EXP,
3835 and make sure assembler code with a label has been output for each one.
3836 Indicate whether an ADDR_EXPR has been encountered. */
3839 output_addressed_constants (tree exp)
3843 switch (TREE_CODE (exp))
3847 /* Go inside any operations that get_inner_reference can handle and see
3848 if what's inside is a constant: no need to do anything here for
3849 addresses of variables or functions. */
3850 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3851 tem = TREE_OPERAND (tem, 0))
3854 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3855 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
3856 tem = DECL_INITIAL (tem);
3858 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
3859 output_constant_def (tem, 0);
3863 case POINTER_PLUS_EXPR:
3865 output_addressed_constants (TREE_OPERAND (exp, 1));
3869 case VIEW_CONVERT_EXPR:
3870 output_addressed_constants (TREE_OPERAND (exp, 0));
3875 unsigned HOST_WIDE_INT idx;
3876 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
3878 output_addressed_constants (tem);
3887 /* Whether a constructor CTOR is a valid static constant initializer if all
3888 its elements are. This used to be internal to initializer_constant_valid_p
3889 and has been exposed to let other functions like categorize_ctor_elements
3890 evaluate the property while walking a constructor for other purposes. */
3893 constructor_static_from_elts_p (const_tree ctor)
3895 return (TREE_CONSTANT (ctor)
3896 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
3897 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
3898 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
3901 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
3904 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
3905 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
3906 which are valid when ENDTYPE is an integer of any size; in
3907 particular, this does not accept a pointer minus a constant. This
3908 returns null_pointer_node if the VALUE is an absolute constant
3909 which can be used to initialize a static variable. Otherwise it
3913 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
3917 if (!INTEGRAL_TYPE_P (endtype))
3920 op0 = TREE_OPERAND (value, 0);
3921 op1 = TREE_OPERAND (value, 1);
3923 /* Like STRIP_NOPS except allow the operand mode to widen. This
3924 works around a feature of fold that simplifies (int)(p1 - p2) to
3925 ((int)p1 - (int)p2) under the theory that the narrower operation
3928 while (CONVERT_EXPR_P (op0)
3929 || TREE_CODE (op0) == NON_LVALUE_EXPR)
3931 tree inner = TREE_OPERAND (op0, 0);
3932 if (inner == error_mark_node
3933 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3934 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3935 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3940 while (CONVERT_EXPR_P (op1)
3941 || TREE_CODE (op1) == NON_LVALUE_EXPR)
3943 tree inner = TREE_OPERAND (op1, 0);
3944 if (inner == error_mark_node
3945 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3946 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3947 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3952 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
3956 op1 = initializer_constant_valid_p_1 (op1, endtype,
3957 cache ? cache + 2 : NULL);
3958 /* Both initializers must be known. */
3962 && (op0 == null_pointer_node
3963 || TREE_CODE (value) == MINUS_EXPR))
3964 return null_pointer_node;
3966 /* Support differences between labels. */
3967 if (TREE_CODE (op0) == LABEL_DECL
3968 && TREE_CODE (op1) == LABEL_DECL)
3969 return null_pointer_node;
3971 if (TREE_CODE (op0) == STRING_CST
3972 && TREE_CODE (op1) == STRING_CST
3973 && operand_equal_p (op0, op1, 1))
3974 return null_pointer_node;
3980 /* Helper function of initializer_constant_valid_p.
3981 Return nonzero if VALUE is a valid constant-valued expression
3982 for use in initializing a static variable; one that can be an
3983 element of a "constant" initializer.
3985 Return null_pointer_node if the value is absolute;
3986 if it is relocatable, return the variable that determines the relocation.
3987 We assume that VALUE has been folded as much as possible;
3988 therefore, we do not need to check for such things as
3989 arithmetic-combinations of integers.
3991 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
3994 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
3998 switch (TREE_CODE (value))
4001 if (constructor_static_from_elts_p (value))
4003 unsigned HOST_WIDE_INT idx;
4005 bool absolute = true;
4007 if (cache && cache[0] == value)
4009 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4012 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4019 cache[1] = NULL_TREE;
4023 if (reloc != null_pointer_node)
4026 /* For a non-absolute relocation, there is no single
4027 variable that can be "the variable that determines the
4032 cache[1] = absolute ? null_pointer_node : error_mark_node;
4034 return absolute ? null_pointer_node : error_mark_node;
4037 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4045 return null_pointer_node;
4050 tree op0 = staticp (TREE_OPERAND (value, 0));
4053 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4054 to be a constant, this is old-skool offsetof-like nonsense. */
4055 if (TREE_CODE (op0) == INDIRECT_REF
4056 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4057 return null_pointer_node;
4058 /* Taking the address of a nested function involves a trampoline,
4059 unless we don't need or want one. */
4060 if (TREE_CODE (op0) == FUNCTION_DECL
4061 && DECL_STATIC_CHAIN (op0)
4062 && !TREE_NO_TRAMPOLINE (value))
4064 /* "&{...}" requires a temporary to hold the constructed
4066 if (TREE_CODE (op0) == CONSTRUCTOR)
4072 case NON_LVALUE_EXPR:
4073 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4076 case VIEW_CONVERT_EXPR:
4078 tree src = TREE_OPERAND (value, 0);
4079 tree src_type = TREE_TYPE (src);
4080 tree dest_type = TREE_TYPE (value);
4082 /* Allow view-conversions from aggregate to non-aggregate type only
4083 if the bit pattern is fully preserved afterwards; otherwise, the
4084 RTL expander won't be able to apply a subsequent transformation
4085 to the underlying constructor. */
4086 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4088 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4089 return initializer_constant_valid_p_1 (src, endtype, cache);
4094 /* Allow all other kinds of view-conversion. */
4095 return initializer_constant_valid_p_1 (src, endtype, cache);
4100 tree src = TREE_OPERAND (value, 0);
4101 tree src_type = TREE_TYPE (src);
4102 tree dest_type = TREE_TYPE (value);
4104 /* Allow conversions between pointer types, floating-point
4105 types, and offset types. */
4106 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4107 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4108 || (TREE_CODE (dest_type) == OFFSET_TYPE
4109 && TREE_CODE (src_type) == OFFSET_TYPE))
4110 return initializer_constant_valid_p_1 (src, endtype, cache);
4112 /* Allow length-preserving conversions between integer types. */
4113 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4114 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4115 return initializer_constant_valid_p_1 (src, endtype, cache);
4117 /* Allow conversions between other integer types only if
4119 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4121 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4122 if (inner == null_pointer_node)
4123 return null_pointer_node;
4127 /* Allow (int) &foo provided int is as wide as a pointer. */
4128 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4129 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4130 return initializer_constant_valid_p_1 (src, endtype, cache);
4132 /* Likewise conversions from int to pointers, but also allow
4133 conversions from 0. */
4134 if ((POINTER_TYPE_P (dest_type)
4135 || TREE_CODE (dest_type) == OFFSET_TYPE)
4136 && INTEGRAL_TYPE_P (src_type))
4138 if (TREE_CODE (src) == INTEGER_CST
4139 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4140 return null_pointer_node;
4141 if (integer_zerop (src))
4142 return null_pointer_node;
4143 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4144 return initializer_constant_valid_p_1 (src, endtype, cache);
4147 /* Allow conversions to struct or union types if the value
4149 if (TREE_CODE (dest_type) == RECORD_TYPE
4150 || TREE_CODE (dest_type) == UNION_TYPE)
4151 return initializer_constant_valid_p_1 (src, endtype, cache);
4155 case POINTER_PLUS_EXPR:
4157 /* Any valid floating-point constants will have been folded by now;
4158 with -frounding-math we hit this with addition of two constants. */
4159 if (TREE_CODE (endtype) == REAL_TYPE)
4161 if (cache && cache[0] == value)
4163 if (! INTEGRAL_TYPE_P (endtype)
4164 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4166 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4168 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4171 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4172 endtype, ncache + 2);
4173 /* If either term is absolute, use the other term's relocation. */
4174 if (valid0 == null_pointer_node)
4176 else if (valid1 == null_pointer_node)
4178 /* Support narrowing pointer differences. */
4180 ret = narrowing_initializer_constant_valid_p (value, endtype,
4184 /* Support narrowing pointer differences. */
4185 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4194 if (TREE_CODE (endtype) == REAL_TYPE)
4196 if (cache && cache[0] == value)
4198 if (! INTEGRAL_TYPE_P (endtype)
4199 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4201 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4203 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4206 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4207 endtype, ncache + 2);
4208 /* Win if second argument is absolute. */
4209 if (valid1 == null_pointer_node)
4211 /* Win if both arguments have the same relocation.
4212 Then the value is absolute. */
4213 else if (valid0 == valid1 && valid0 != 0)
4214 ret = null_pointer_node;
4215 /* Since GCC guarantees that string constants are unique in the
4216 generated code, a subtraction between two copies of the same
4217 constant string is absolute. */
4218 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4219 && valid1 && TREE_CODE (valid1) == STRING_CST
4220 && operand_equal_p (valid0, valid1, 1))
4221 ret = null_pointer_node;
4222 /* Support narrowing differences. */
4224 ret = narrowing_initializer_constant_valid_p (value, endtype,
4228 /* Support narrowing differences. */
4229 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4244 /* Return nonzero if VALUE is a valid constant-valued expression
4245 for use in initializing a static variable; one that can be an
4246 element of a "constant" initializer.
4248 Return null_pointer_node if the value is absolute;
4249 if it is relocatable, return the variable that determines the relocation.
4250 We assume that VALUE has been folded as much as possible;
4251 therefore, we do not need to check for such things as
4252 arithmetic-combinations of integers. */
4254 initializer_constant_valid_p (tree value, tree endtype)
4256 return initializer_constant_valid_p_1 (value, endtype, NULL);
4259 /* Return true if VALUE is a valid constant-valued expression
4260 for use in initializing a static bit-field; one that can be
4261 an element of a "constant" initializer. */
4264 initializer_constant_valid_for_bitfield_p (tree value)
4266 /* For bitfields we support integer constants or possibly nested aggregates
4268 switch (TREE_CODE (value))
4272 unsigned HOST_WIDE_INT idx;
4275 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4276 if (!initializer_constant_valid_for_bitfield_p (elt))
4284 case VIEW_CONVERT_EXPR:
4285 case NON_LVALUE_EXPR:
4287 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4296 /* output_constructor outer state of relevance in recursive calls, typically
4297 for nested aggregate bitfields. */
4300 unsigned int bit_offset; /* current position in ... */
4301 int byte; /* ... the outer byte buffer. */
4304 static unsigned HOST_WIDE_INT
4305 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4308 /* Output assembler code for constant EXP to FILE, with no label.
4309 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4310 Assumes output_addressed_constants has been done on EXP already.
4312 Generate exactly SIZE bytes of assembler data, padding at the end
4313 with zeros if necessary. SIZE must always be specified.
4315 SIZE is important for structure constructors,
4316 since trailing members may have been omitted from the constructor.
4317 It is also important for initialization of arrays from string constants
4318 since the full length of the string constant might not be wanted.
4319 It is also needed for initialization of unions, where the initializer's
4320 type is just one member, and that may not be as long as the union.
4322 There a case in which we would fail to output exactly SIZE bytes:
4323 for a structure constructor that wants to produce more than SIZE bytes.
4324 But such constructors will never be generated for any possible input.
4326 ALIGN is the alignment of the data in bits. */
4329 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4331 enum tree_code code;
4332 unsigned HOST_WIDE_INT thissize;
4334 if (size == 0 || flag_syntax_only)
4337 /* See if we're trying to initialize a pointer in a non-default mode
4338 to the address of some declaration somewhere. If the target says
4339 the mode is valid for pointers, assume the target has a way of
4341 if (TREE_CODE (exp) == NOP_EXPR
4342 && POINTER_TYPE_P (TREE_TYPE (exp))
4343 && targetm.addr_space.valid_pointer_mode
4344 (TYPE_MODE (TREE_TYPE (exp)),
4345 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4347 tree saved_type = TREE_TYPE (exp);
4349 /* Peel off any intermediate conversions-to-pointer for valid
4351 while (TREE_CODE (exp) == NOP_EXPR
4352 && POINTER_TYPE_P (TREE_TYPE (exp))
4353 && targetm.addr_space.valid_pointer_mode
4354 (TYPE_MODE (TREE_TYPE (exp)),
4355 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4356 exp = TREE_OPERAND (exp, 0);
4358 /* If what we're left with is the address of something, we can
4359 convert the address to the final type and output it that
4361 if (TREE_CODE (exp) == ADDR_EXPR)
4362 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4363 /* Likewise for constant ints. */
4364 else if (TREE_CODE (exp) == INTEGER_CST)
4365 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4366 TREE_INT_CST_HIGH (exp));
4370 /* Eliminate any conversions since we'll be outputting the underlying
4372 while (CONVERT_EXPR_P (exp)
4373 || TREE_CODE (exp) == NON_LVALUE_EXPR
4374 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4376 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4377 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4379 /* Make sure eliminating the conversion is really a no-op, except with
4380 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4381 union types to allow for Ada unchecked unions. */
4382 if (type_size > op_size
4383 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4384 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4385 /* Keep the conversion. */
4388 exp = TREE_OPERAND (exp, 0);
4391 code = TREE_CODE (TREE_TYPE (exp));
4392 thissize = int_size_in_bytes (TREE_TYPE (exp));
4394 /* Allow a constructor with no elements for any data type.
4395 This means to fill the space with zeros. */
4396 if (TREE_CODE (exp) == CONSTRUCTOR
4397 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4399 assemble_zeros (size);
4403 if (TREE_CODE (exp) == FDESC_EXPR)
4405 #ifdef ASM_OUTPUT_FDESC
4406 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4407 tree decl = TREE_OPERAND (exp, 0);
4408 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4415 /* Now output the underlying data. If we've handling the padding, return.
4416 Otherwise, break and ensure SIZE is the size written. */
4423 case REFERENCE_TYPE:
4425 case FIXED_POINT_TYPE:
4426 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4427 EXPAND_INITIALIZER),
4428 MIN (size, thissize), align, 0))
4429 error ("initializer for integer/fixed-point value is too complicated");
4433 if (TREE_CODE (exp) != REAL_CST)
4434 error ("initializer for floating value is not a floating constant");
4436 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4440 output_constant (TREE_REALPART (exp), thissize / 2, align);
4441 output_constant (TREE_IMAGPART (exp), thissize / 2,
4442 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4447 switch (TREE_CODE (exp))
4450 output_constructor (exp, size, align, NULL);
4453 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4455 assemble_string (TREE_STRING_POINTER (exp), thissize);
4462 unsigned int nalign;
4463 enum machine_mode inner;
4465 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4466 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4468 elt_size = GET_MODE_SIZE (inner);
4470 link = TREE_VECTOR_CST_ELTS (exp);
4471 output_constant (TREE_VALUE (link), elt_size, align);
4472 thissize = elt_size;
4473 while ((link = TREE_CHAIN (link)) != NULL)
4475 output_constant (TREE_VALUE (link), elt_size, nalign);
4476 thissize += elt_size;
4487 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4488 output_constructor (exp, size, align, NULL);
4498 if (size > thissize)
4499 assemble_zeros (size - thissize);
4503 /* Subroutine of output_constructor, used for computing the size of
4504 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4505 type with an unspecified upper bound. */
4507 static unsigned HOST_WIDE_INT
4508 array_size_for_constructor (tree val)
4511 unsigned HOST_WIDE_INT cnt;
4512 tree index, value, tmp;
4514 /* This code used to attempt to handle string constants that are not
4515 arrays of single-bytes, but nothing else does, so there's no point in
4517 if (TREE_CODE (val) == STRING_CST)
4518 return TREE_STRING_LENGTH (val);
4520 max_index = NULL_TREE;
4521 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4523 if (TREE_CODE (index) == RANGE_EXPR)
4524 index = TREE_OPERAND (index, 1);
4525 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4529 if (max_index == NULL_TREE)
4532 /* Compute the total number of array elements. */
4533 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4534 i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4535 fold_convert (sizetype, tmp));
4536 i = size_binop (PLUS_EXPR, i, size_one_node);
4538 /* Multiply by the array element unit size to find number of bytes. */
4539 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4541 return tree_low_cst (i, 1);
4544 /* Other datastructures + helpers for output_constructor. */
4546 /* output_constructor local state to support interaction with helpers. */
4550 /* Received arguments. */
4551 tree exp; /* Constructor expression. */
4552 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4553 unsigned int align; /* Known initial alignment. */
4555 /* Constructor expression data. */
4556 tree type; /* Expression type. */
4557 tree field; /* Current field decl in a record. */
4558 tree min_index; /* Lower bound if specified for an array. */
4560 /* Output processing state. */
4561 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4562 bool byte_buffer_in_use; /* Whether byte ... */
4563 int byte; /* ... contains part of a bitfield byte yet to
4566 int last_relative_index; /* Implicit or explicit index of the last
4567 array element output within a bitfield. */
4568 /* Current element. */
4569 tree val; /* Current element value. */
4570 tree index; /* Current element index. */
4574 /* Helper for output_constructor. From the current LOCAL state, output a
4575 RANGE_EXPR element. */
4578 output_constructor_array_range (oc_local_state *local)
4580 unsigned HOST_WIDE_INT fieldsize
4581 = int_size_in_bytes (TREE_TYPE (local->type));
4583 HOST_WIDE_INT lo_index
4584 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4585 HOST_WIDE_INT hi_index
4586 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4587 HOST_WIDE_INT index;
4590 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4592 for (index = lo_index; index <= hi_index; index++)
4594 /* Output the element's initial value. */
4595 if (local->val == NULL_TREE)
4596 assemble_zeros (fieldsize);
4598 output_constant (local->val, fieldsize, align2);
4600 /* Count its size. */
4601 local->total_bytes += fieldsize;
4605 /* Helper for output_constructor. From the current LOCAL state, output a
4606 field element that is not true bitfield or part of an outer one. */
4609 output_constructor_regular_field (oc_local_state *local)
4611 /* Field size and position. Since this structure is static, we know the
4612 positions are constant. */
4613 unsigned HOST_WIDE_INT fieldsize;
4614 HOST_WIDE_INT fieldpos;
4616 unsigned int align2;
4618 if (local->index != NULL_TREE)
4619 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
4620 * ((tree_low_cst (local->index, 0)
4621 - tree_low_cst (local->min_index, 0))));
4622 else if (local->field != NULL_TREE)
4623 fieldpos = int_byte_position (local->field);
4627 /* Output any buffered-up bit-fields preceding this element. */
4628 if (local->byte_buffer_in_use)
4630 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4631 local->total_bytes++;
4632 local->byte_buffer_in_use = false;
4635 /* Advance to offset of this element.
4636 Note no alignment needed in an array, since that is guaranteed
4637 if each element has the proper size. */
4638 if ((local->field != NULL_TREE || local->index != NULL_TREE)
4639 && fieldpos != local->total_bytes)
4641 gcc_assert (fieldpos >= local->total_bytes);
4642 assemble_zeros (fieldpos - local->total_bytes);
4643 local->total_bytes = fieldpos;
4646 /* Find the alignment of this element. */
4647 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
4649 /* Determine size this element should occupy. */
4654 /* If this is an array with an unspecified upper bound,
4655 the initializer determines the size. */
4656 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4657 but we cannot do this until the deprecated support for
4658 initializing zero-length array members is removed. */
4659 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
4660 && TYPE_DOMAIN (TREE_TYPE (local->field))
4661 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
4663 fieldsize = array_size_for_constructor (local->val);
4664 /* Given a non-empty initialization, this field had
4666 gcc_assert (!fieldsize || !DECL_CHAIN (local->field));
4668 else if (DECL_SIZE_UNIT (local->field))
4670 /* ??? This can't be right. If the decl size overflows
4671 a host integer we will silently emit no data. */
4672 if (host_integerp (DECL_SIZE_UNIT (local->field), 1))
4673 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
4677 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
4679 /* Output the element's initial value. */
4680 if (local->val == NULL_TREE)
4681 assemble_zeros (fieldsize);
4683 output_constant (local->val, fieldsize, align2);
4685 /* Count its size. */
4686 local->total_bytes += fieldsize;
4689 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4690 output an element that is a true bitfield or part of an outer one. */
4693 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
4695 /* Bit size of this element. */
4696 HOST_WIDE_INT ebitsize
4698 ? tree_low_cst (DECL_SIZE (local->field), 1)
4699 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
4701 /* Relative index of this element if this is an array component. */
4702 HOST_WIDE_INT relative_index
4705 ? (tree_low_cst (local->index, 0)
4706 - tree_low_cst (local->min_index, 0))
4707 : local->last_relative_index + 1)
4710 /* Bit position of this element from the start of the containing
4712 HOST_WIDE_INT constructor_relative_ebitpos
4714 ? int_bit_position (local->field)
4715 : ebitsize * relative_index);
4717 /* Bit position of this element from the start of a possibly ongoing
4718 outer byte buffer. */
4719 HOST_WIDE_INT byte_relative_ebitpos
4720 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
4722 /* From the start of a possibly ongoing outer byte buffer, offsets to
4723 the first bit of this element and to the first bit past the end of
4725 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
4726 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
4728 local->last_relative_index = relative_index;
4730 if (local->val == NULL_TREE)
4731 local->val = integer_zero_node;
4733 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
4734 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
4735 local->val = TREE_OPERAND (local->val, 0);
4737 if (TREE_CODE (local->val) != INTEGER_CST
4738 && TREE_CODE (local->val) != CONSTRUCTOR)
4740 error ("invalid initial value for member %qE", DECL_NAME (local->field));
4744 /* If this field does not start in this (or, next) byte,
4746 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4748 /* Output remnant of any bit field in previous bytes. */
4749 if (local->byte_buffer_in_use)
4751 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4752 local->total_bytes++;
4753 local->byte_buffer_in_use = false;
4756 /* If still not at proper byte, advance to there. */
4757 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4759 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
4760 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
4761 local->total_bytes = next_offset / BITS_PER_UNIT;
4765 /* Set up the buffer if necessary. */
4766 if (!local->byte_buffer_in_use)
4770 local->byte_buffer_in_use = true;
4773 /* If this is nested constructor, recurse passing the bit offset and the
4774 pending data, then retrieve the new pending data afterwards. */
4775 if (TREE_CODE (local->val) == CONSTRUCTOR)
4777 oc_outer_state output_state;
4779 output_state.bit_offset = next_offset % BITS_PER_UNIT;
4780 output_state.byte = local->byte;
4782 += output_constructor (local->val, 0, 0, &output_state);
4783 local->byte = output_state.byte;
4787 /* Otherwise, we must split the element into pieces that fall within
4788 separate bytes, and combine each byte with previous or following
4790 while (next_offset < end_offset)
4794 HOST_WIDE_INT value;
4795 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4796 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4798 /* Advance from byte to byte
4799 within this element when necessary. */
4800 while (next_byte != local->total_bytes)
4802 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4803 local->total_bytes++;
4807 /* Number of bits we can process at once
4808 (all part of the same byte). */
4809 this_time = MIN (end_offset - next_offset,
4810 BITS_PER_UNIT - next_bit);
4811 if (BYTES_BIG_ENDIAN)
4813 /* On big-endian machine, take the most significant bits
4814 first (of the bits that are significant)
4815 and put them into bytes from the most significant end. */
4816 shift = end_offset - next_offset - this_time;
4818 /* Don't try to take a bunch of bits that cross
4819 the word boundary in the INTEGER_CST. We can
4820 only select bits from the LOW or HIGH part
4822 if (shift < HOST_BITS_PER_WIDE_INT
4823 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4825 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4826 shift = HOST_BITS_PER_WIDE_INT;
4829 /* Now get the bits from the appropriate constant word. */
4830 if (shift < HOST_BITS_PER_WIDE_INT)
4831 value = TREE_INT_CST_LOW (local->val);
4834 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4835 value = TREE_INT_CST_HIGH (local->val);
4836 shift -= HOST_BITS_PER_WIDE_INT;
4839 /* Get the result. This works only when:
4840 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4841 local->byte |= (((value >> shift)
4842 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4843 << (BITS_PER_UNIT - this_time - next_bit));
4847 /* On little-endian machines,
4848 take first the least significant bits of the value
4849 and pack them starting at the least significant
4850 bits of the bytes. */
4851 shift = next_offset - byte_relative_ebitpos;
4853 /* Don't try to take a bunch of bits that cross
4854 the word boundary in the INTEGER_CST. We can
4855 only select bits from the LOW or HIGH part
4857 if (shift < HOST_BITS_PER_WIDE_INT
4858 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4859 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4861 /* Now get the bits from the appropriate constant word. */
4862 if (shift < HOST_BITS_PER_WIDE_INT)
4863 value = TREE_INT_CST_LOW (local->val);
4866 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4867 value = TREE_INT_CST_HIGH (local->val);
4868 shift -= HOST_BITS_PER_WIDE_INT;
4871 /* Get the result. This works only when:
4872 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4873 local->byte |= (((value >> shift)
4874 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4878 next_offset += this_time;
4879 local->byte_buffer_in_use = true;
4883 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4884 Generate at least SIZE bytes, padding if necessary. OUTER designates the
4885 caller output state of relevance in recursive invocations. */
4887 static unsigned HOST_WIDE_INT
4888 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
4889 unsigned int align, oc_outer_state * outer)
4891 unsigned HOST_WIDE_INT cnt;
4892 constructor_elt *ce;
4894 oc_local_state local;
4896 /* Setup our local state to communicate with helpers. */
4899 local.align = align;
4901 local.total_bytes = 0;
4902 local.byte_buffer_in_use = outer != NULL;
4903 local.byte = outer ? outer->byte : 0;
4905 local.type = TREE_TYPE (exp);
4907 local.last_relative_index = -1;
4909 local.min_index = NULL_TREE;
4910 if (TREE_CODE (local.type) == ARRAY_TYPE
4911 && TYPE_DOMAIN (local.type) != NULL_TREE)
4912 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
4914 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
4916 /* As CE goes through the elements of the constant, FIELD goes through the
4917 structure fields if the constant is a structure. If the constant is a
4918 union, we override this by getting the field from the TREE_LIST element.
4919 But the constant could also be an array. Then FIELD is zero.
4921 There is always a maximum of one element in the chain LINK for unions
4922 (even if the initializer in a source program incorrectly contains
4925 local.field = NULL_TREE;
4926 if (TREE_CODE (local.type) == RECORD_TYPE)
4927 local.field = TYPE_FIELDS (local.type);
4930 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
4931 cnt++, local.field = local.field ? DECL_CHAIN (local.field) : 0)
4933 local.val = ce->value;
4934 local.index = NULL_TREE;
4936 /* The element in a union constructor specifies the proper field
4938 if ((TREE_CODE (local.type) == RECORD_TYPE
4939 || TREE_CODE (local.type) == UNION_TYPE
4940 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
4941 && ce->index != NULL_TREE)
4942 local.field = ce->index;
4944 else if (TREE_CODE (local.type) == ARRAY_TYPE)
4945 local.index = ce->index;
4947 #ifdef ASM_COMMENT_START
4948 if (local.field && flag_verbose_asm)
4949 fprintf (asm_out_file, "%s %s:\n",
4951 DECL_NAME (local.field)
4952 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
4956 /* Eliminate the marker that makes a cast not be an lvalue. */
4957 if (local.val != NULL_TREE)
4958 STRIP_NOPS (local.val);
4960 /* Output the current element, using the appropriate helper ... */
4962 /* For an array slice not part of an outer bitfield. */
4964 && local.index != NULL_TREE
4965 && TREE_CODE (local.index) == RANGE_EXPR)
4966 output_constructor_array_range (&local);
4968 /* For a field that is neither a true bitfield nor part of an outer one,
4969 known to be at least byte aligned and multiple-of-bytes long. */
4971 && (local.field == NULL_TREE
4972 || !CONSTRUCTOR_BITFIELD_P (local.field)))
4973 output_constructor_regular_field (&local);
4975 /* For a true bitfield or part of an outer one. */
4977 output_constructor_bitfield (&local, outer);
4980 /* If we are not at toplevel, save the pending data for our caller.
4981 Otherwise output the pending data and padding zeros as needed. */
4983 outer->byte = local.byte;
4986 if (local.byte_buffer_in_use)
4988 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
4989 local.total_bytes++;
4992 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
4994 assemble_zeros (local.size - local.total_bytes);
4995 local.total_bytes = local.size;
4999 return local.total_bytes;
5002 /* Mark DECL as weak. */
5005 mark_weak (tree decl)
5007 DECL_WEAK (decl) = 1;
5009 if (DECL_RTL_SET_P (decl)
5010 && MEM_P (DECL_RTL (decl))
5011 && XEXP (DECL_RTL (decl), 0)
5012 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5013 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5016 /* Merge weak status between NEWDECL and OLDDECL. */
5019 merge_weak (tree newdecl, tree olddecl)
5021 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5023 if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
5026 /* We put the NEWDECL on the weak_decls list at some point
5027 and OLDDECL as well. Keep just OLDDECL on the list. */
5028 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5029 if (TREE_VALUE (*pwd) == newdecl)
5031 *pwd = TREE_CHAIN (*pwd);
5038 if (DECL_WEAK (newdecl))
5042 /* NEWDECL is weak, but OLDDECL is not. */
5044 /* If we already output the OLDDECL, we're in trouble; we can't
5045 go back and make it weak. This error cannot be caught in
5046 declare_weak because the NEWDECL and OLDDECL was not yet
5047 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5048 if (TREE_ASM_WRITTEN (olddecl))
5049 error ("weak declaration of %q+D must precede definition",
5052 /* If we've already generated rtl referencing OLDDECL, we may
5053 have done so in a way that will not function properly with
5055 else if (TREE_USED (olddecl)
5056 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
5057 warning (0, "weak declaration of %q+D after first use results "
5058 "in unspecified behavior", newdecl);
5062 /* We put the NEWDECL on the weak_decls list at some point.
5063 Replace it with the OLDDECL. */
5064 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5065 if (TREE_VALUE (wd) == newdecl)
5067 TREE_VALUE (wd) = olddecl;
5070 /* We may not find the entry on the list. If NEWDECL is a
5071 weak alias, then we will have already called
5072 globalize_decl to remove the entry; in that case, we do
5073 not need to do anything. */
5076 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5077 mark_weak (olddecl);
5080 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5081 weak. Just update NEWDECL to indicate that it's weak too. */
5082 mark_weak (newdecl);
5085 /* Declare DECL to be a weak symbol. */
5088 declare_weak (tree decl)
5090 if (! TREE_PUBLIC (decl))
5091 error ("weak declaration of %q+D must be public", decl);
5092 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
5093 error ("weak declaration of %q+D must precede definition", decl);
5094 else if (!SUPPORTS_WEAK)
5095 warning (0, "weak declaration of %q+D not supported", decl);
5098 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5099 DECL_ATTRIBUTES (decl)
5100 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5104 weak_finish_1 (tree decl)
5106 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5107 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5110 if (! TREE_USED (decl))
5113 #ifdef ASM_WEAKEN_DECL
5114 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5116 #ifdef ASM_WEAKEN_LABEL
5117 ASM_WEAKEN_LABEL (asm_out_file, name);
5119 #ifdef ASM_OUTPUT_WEAK_ALIAS
5121 static bool warn_once = 0;
5124 warning (0, "only weak aliases are supported in this configuration");
5134 /* This TREE_LIST contains weakref targets. */
5136 static GTY(()) tree weakref_targets;
5138 /* Forward declaration. */
5139 static tree find_decl_and_mark_needed (tree decl, tree target);
5141 /* Emit any pending weak declarations. */
5148 for (t = weakref_targets; t; t = TREE_CHAIN (t))
5150 tree alias_decl = TREE_PURPOSE (t);
5151 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5153 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5154 /* Remove alias_decl from the weak list, but leave entries for
5155 the target alone. */
5157 #ifndef ASM_OUTPUT_WEAKREF
5158 else if (! TREE_SYMBOL_REFERENCED (target))
5160 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5161 defined, otherwise we and weak_finish_1 would use
5162 different macros. */
5163 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5164 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5166 tree decl = find_decl_and_mark_needed (alias_decl, target);
5170 decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5171 TREE_CODE (alias_decl), target,
5172 TREE_TYPE (alias_decl));
5174 DECL_EXTERNAL (decl) = 1;
5175 TREE_PUBLIC (decl) = 1;
5176 DECL_ARTIFICIAL (decl) = 1;
5177 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5178 TREE_USED (decl) = 1;
5181 weak_finish_1 (decl);
5190 /* Remove the alias and the target from the pending weak list
5191 so that we do not emit any .weak directives for the former,
5192 nor multiple .weak directives for the latter. */
5193 for (p = &weak_decls; (t2 = *p) ; )
5195 if (TREE_VALUE (t2) == alias_decl
5196 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5197 *p = TREE_CHAIN (t2);
5199 p = &TREE_CHAIN (t2);
5202 /* Remove other weakrefs to the same target, to speed things up. */
5203 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5205 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5206 *p = TREE_CHAIN (t2);
5208 p = &TREE_CHAIN (t2);
5213 for (t = weak_decls; t; t = TREE_CHAIN (t))
5215 tree decl = TREE_VALUE (t);
5217 weak_finish_1 (decl);
5221 /* Emit the assembly bits to indicate that DECL is globally visible. */
5224 globalize_decl (tree decl)
5227 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5228 if (DECL_WEAK (decl))
5230 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5233 #ifdef ASM_WEAKEN_DECL
5234 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5236 ASM_WEAKEN_LABEL (asm_out_file, name);
5239 /* Remove this function from the pending weak list so that
5240 we do not emit multiple .weak directives for it. */
5241 for (p = &weak_decls; (t = *p) ; )
5243 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5244 *p = TREE_CHAIN (t);
5246 p = &TREE_CHAIN (t);
5249 /* Remove weakrefs to the same target from the pending weakref
5250 list, for the same reason. */
5251 for (p = &weakref_targets; (t = *p) ; )
5253 if (DECL_ASSEMBLER_NAME (decl)
5254 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5255 *p = TREE_CHAIN (t);
5257 p = &TREE_CHAIN (t);
5264 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5267 VEC(alias_pair,gc) *alias_pairs;
5269 /* Given an assembly name, find the decl it is associated with. At the
5270 same time, mark it needed for cgraph. */
5273 find_decl_and_mark_needed (tree decl, tree target)
5275 struct cgraph_node *fnode = NULL;
5276 struct varpool_node *vnode = NULL;
5278 if (TREE_CODE (decl) == FUNCTION_DECL)
5280 fnode = cgraph_node_for_asm (target);
5282 vnode = varpool_node_for_asm (target);
5286 vnode = varpool_node_for_asm (target);
5288 fnode = cgraph_node_for_asm (target);
5293 cgraph_mark_needed_node (fnode);
5298 varpool_mark_needed_node (vnode);
5299 vnode->force_output = 1;
5306 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5307 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5308 tree node is DECL to have the value of the tree node TARGET. */
5311 do_assemble_alias (tree decl, tree target)
5313 /* Emulated TLS had better not get this var. */
5314 gcc_assert(!(!targetm.have_tls
5315 && TREE_CODE (decl) == VAR_DECL
5316 && DECL_THREAD_LOCAL_P (decl)));
5318 if (TREE_ASM_WRITTEN (decl))
5321 /* We must force creation of DECL_RTL for debug info generation, even though
5322 we don't use it here. */
5323 make_decl_rtl (decl);
5325 TREE_ASM_WRITTEN (decl) = 1;
5326 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5328 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5330 ultimate_transparent_alias_target (&target);
5332 if (!TREE_SYMBOL_REFERENCED (target))
5333 weakref_targets = tree_cons (decl, target, weakref_targets);
5335 #ifdef ASM_OUTPUT_WEAKREF
5336 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5337 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5338 IDENTIFIER_POINTER (target));
5342 error_at (DECL_SOURCE_LOCATION (decl),
5343 "weakref is not supported in this configuration");
5350 #ifdef ASM_OUTPUT_DEF
5351 /* Make name accessible from other files, if appropriate. */
5353 if (TREE_PUBLIC (decl))
5355 globalize_decl (decl);
5356 maybe_assemble_visibility (decl);
5358 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
5360 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GAS_INDIRECT_FUNCTION
5361 ASM_OUTPUT_TYPE_DIRECTIVE
5362 (asm_out_file, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5365 error_at (DECL_SOURCE_LOCATION (decl),
5366 "ifunc is not supported in this configuration");
5370 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5371 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5373 ASM_OUTPUT_DEF (asm_out_file,
5374 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5375 IDENTIFIER_POINTER (target));
5377 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5382 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5383 # ifdef ASM_WEAKEN_DECL
5384 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5386 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5388 /* Remove this function from the pending weak list so that
5389 we do not emit multiple .weak directives for it. */
5390 for (p = &weak_decls; (t = *p) ; )
5391 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5392 *p = TREE_CHAIN (t);
5394 p = &TREE_CHAIN (t);
5396 /* Remove weakrefs to the same target from the pending weakref
5397 list, for the same reason. */
5398 for (p = &weakref_targets; (t = *p) ; )
5400 if (DECL_ASSEMBLER_NAME (decl)
5401 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5402 *p = TREE_CHAIN (t);
5404 p = &TREE_CHAIN (t);
5411 /* Remove the alias pairing for functions that are no longer in the call
5415 remove_unreachable_alias_pairs (void)
5420 if (alias_pairs == NULL)
5423 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5425 if (!DECL_EXTERNAL (p->decl))
5427 struct cgraph_node *fnode = NULL;
5428 struct varpool_node *vnode = NULL;
5429 fnode = cgraph_node_for_asm (p->target);
5430 vnode = (fnode == NULL) ? varpool_node_for_asm (p->target) : NULL;
5431 if (fnode == NULL && vnode == NULL)
5433 VEC_unordered_remove (alias_pair, alias_pairs, i);
5443 /* First pass of completing pending aliases. Make sure that cgraph knows
5444 which symbols will be required. */
5447 finish_aliases_1 (void)
5452 FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
5456 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5457 if (target_decl == NULL)
5459 if (! (p->emitted_diags & ALIAS_DIAG_TO_UNDEF)
5460 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5462 error ("%q+D aliased to undefined symbol %qE",
5463 p->decl, p->target);
5464 p->emitted_diags |= ALIAS_DIAG_TO_UNDEF;
5467 else if (! (p->emitted_diags & ALIAS_DIAG_TO_EXTERN)
5468 && DECL_EXTERNAL (target_decl)
5469 /* We use local aliases for C++ thunks to force the tailcall
5470 to bind locally. This is a hack - to keep it working do
5471 the following (which is not strictly correct). */
5472 && (! TREE_CODE (target_decl) == FUNCTION_DECL
5473 || ! DECL_VIRTUAL_P (target_decl))
5474 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5476 error ("%q+D aliased to external symbol %qE",
5477 p->decl, p->target);
5478 p->emitted_diags |= ALIAS_DIAG_TO_EXTERN;
5483 /* Second pass of completing pending aliases. Emit the actual assembly.
5484 This happens at the end of compilation and thus it is assured that the
5485 target symbol has been emitted. */
5488 finish_aliases_2 (void)
5493 FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
5494 do_assemble_alias (p->decl, p->target);
5496 VEC_truncate (alias_pair, alias_pairs, 0);
5499 /* Emit an assembler directive to make the symbol for DECL an alias to
5500 the symbol for TARGET. */
5503 assemble_alias (tree decl, tree target)
5506 bool is_weakref = false;
5508 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5510 tree alias = DECL_ASSEMBLER_NAME (decl);
5514 ultimate_transparent_alias_target (&target);
5516 if (alias == target)
5517 error ("weakref %q+D ultimately targets itself", decl);
5520 #ifndef ASM_OUTPUT_WEAKREF
5521 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5522 TREE_CHAIN (alias) = target;
5525 if (TREE_PUBLIC (decl))
5526 error ("weakref %q+D must have static linkage", decl);
5530 #if !defined (ASM_OUTPUT_DEF)
5531 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5532 error_at (DECL_SOURCE_LOCATION (decl),
5533 "alias definitions not supported in this configuration");
5536 if (!DECL_WEAK (decl))
5538 error_at (DECL_SOURCE_LOCATION (decl),
5539 "only weak aliases are supported in this configuration");
5545 TREE_USED (decl) = 1;
5547 /* A quirk of the initial implementation of aliases required that the user
5548 add "extern" to all of them. Which is silly, but now historical. Do
5549 note that the symbol is in fact locally defined. */
5551 DECL_EXTERNAL (decl) = 0;
5553 /* Allow aliases to aliases. */
5554 if (TREE_CODE (decl) == FUNCTION_DECL)
5555 cgraph_node (decl)->alias = true;
5557 varpool_node (decl)->alias = true;
5559 /* If the target has already been emitted, we don't have to queue the
5560 alias. This saves a tad of memory. */
5561 if (cgraph_global_info_ready)
5562 target_decl = find_decl_and_mark_needed (decl, target);
5565 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5566 do_assemble_alias (decl, target);
5569 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5572 p->emitted_diags = ALIAS_DIAG_NONE;
5576 /* Emit an assembler directive to set symbol for DECL visibility to
5577 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5580 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
5581 int vis ATTRIBUTE_UNUSED)
5583 #ifdef HAVE_GAS_HIDDEN
5584 static const char * const visibility_types[] = {
5585 NULL, "protected", "hidden", "internal"
5588 const char *name, *type;
5590 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5591 type = visibility_types[vis];
5593 fprintf (asm_out_file, "\t.%s\t", type);
5594 assemble_name (asm_out_file, name);
5595 fprintf (asm_out_file, "\n");
5597 warning (OPT_Wattributes, "visibility attribute not supported "
5598 "in this configuration; ignored");
5602 /* A helper function to call assemble_visibility when needed for a decl. */
5605 maybe_assemble_visibility (tree decl)
5607 enum symbol_visibility vis = DECL_VISIBILITY (decl);
5609 if (vis != VISIBILITY_DEFAULT)
5611 targetm.asm_out.assemble_visibility (decl, vis);
5618 /* Returns 1 if the target configuration supports defining public symbols
5619 so that one of them will be chosen at link time instead of generating a
5620 multiply-defined symbol error, whether through the use of weak symbols or
5621 a target-specific mechanism for having duplicates discarded. */
5624 supports_one_only (void)
5626 if (SUPPORTS_ONE_ONLY)
5628 return SUPPORTS_WEAK;
5631 /* Set up DECL as a public symbol that can be defined in multiple
5632 translation units without generating a linker error. */
5635 make_decl_one_only (tree decl, tree comdat_group)
5637 gcc_assert (TREE_CODE (decl) == VAR_DECL
5638 || TREE_CODE (decl) == FUNCTION_DECL);
5640 TREE_PUBLIC (decl) = 1;
5642 if (SUPPORTS_ONE_ONLY)
5644 #ifdef MAKE_DECL_ONE_ONLY
5645 MAKE_DECL_ONE_ONLY (decl);
5647 DECL_COMDAT_GROUP (decl) = comdat_group;
5649 else if (TREE_CODE (decl) == VAR_DECL
5650 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5651 DECL_COMMON (decl) = 1;
5654 gcc_assert (SUPPORTS_WEAK);
5655 DECL_WEAK (decl) = 1;
5660 init_varasm_once (void)
5662 section_htab = htab_create_ggc (31, section_entry_hash,
5663 section_entry_eq, NULL);
5664 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
5665 object_block_entry_eq, NULL);
5666 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
5667 const_desc_eq, NULL);
5669 const_alias_set = new_alias_set ();
5670 shared_constant_pool = create_constant_pool ();
5672 #ifdef TEXT_SECTION_ASM_OP
5673 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
5674 TEXT_SECTION_ASM_OP);
5677 #ifdef DATA_SECTION_ASM_OP
5678 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5679 DATA_SECTION_ASM_OP);
5682 #ifdef SDATA_SECTION_ASM_OP
5683 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5684 SDATA_SECTION_ASM_OP);
5687 #ifdef READONLY_DATA_SECTION_ASM_OP
5688 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
5689 READONLY_DATA_SECTION_ASM_OP);
5692 #ifdef CTORS_SECTION_ASM_OP
5693 ctors_section = get_unnamed_section (0, output_section_asm_op,
5694 CTORS_SECTION_ASM_OP);
5697 #ifdef DTORS_SECTION_ASM_OP
5698 dtors_section = get_unnamed_section (0, output_section_asm_op,
5699 DTORS_SECTION_ASM_OP);
5702 #ifdef BSS_SECTION_ASM_OP
5703 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5704 output_section_asm_op,
5705 BSS_SECTION_ASM_OP);
5708 #ifdef SBSS_SECTION_ASM_OP
5709 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5710 output_section_asm_op,
5711 SBSS_SECTION_ASM_OP);
5714 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5715 | SECTION_COMMON, emit_tls_common);
5716 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5717 | SECTION_COMMON, emit_local);
5718 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5719 | SECTION_COMMON, emit_common);
5721 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5722 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
5726 targetm.asm_out.init_sections ();
5728 if (readonly_data_section == NULL)
5729 readonly_data_section = text_section;
5733 decl_default_tls_model (const_tree decl)
5735 enum tls_model kind;
5738 is_local = targetm.binds_local_p (decl);
5742 kind = TLS_MODEL_LOCAL_EXEC;
5744 kind = TLS_MODEL_INITIAL_EXEC;
5747 /* Local dynamic is inefficient when we're not combining the
5748 parts of the address. */
5749 else if (optimize && is_local)
5750 kind = TLS_MODEL_LOCAL_DYNAMIC;
5752 kind = TLS_MODEL_GLOBAL_DYNAMIC;
5753 if (kind < flag_tls_default)
5754 kind = flag_tls_default;
5759 /* Select a set of attributes for section NAME based on the properties
5760 of DECL and whether or not RELOC indicates that DECL's initializer
5761 might contain runtime relocations.
5763 We make the section read-only and executable for a function decl,
5764 read-only for a const data decl, and writable for a non-const data decl. */
5767 default_section_type_flags (tree decl, const char *name, int reloc)
5771 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5772 flags = SECTION_CODE;
5773 else if (decl && decl_readonly_section (decl, reloc))
5775 else if (current_function_decl
5777 && crtl->subsections.unlikely_text_section_name
5778 && strcmp (name, crtl->subsections.unlikely_text_section_name) == 0)
5779 flags = SECTION_CODE;
5781 && (!current_function_decl || !cfun)
5782 && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
5783 flags = SECTION_CODE;
5785 flags = SECTION_WRITE;
5787 if (decl && DECL_ONE_ONLY (decl))
5788 flags |= SECTION_LINKONCE;
5790 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
5791 flags |= SECTION_TLS | SECTION_WRITE;
5793 if (strcmp (name, ".bss") == 0
5794 || strncmp (name, ".bss.", 5) == 0
5795 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5796 || strcmp (name, ".sbss") == 0
5797 || strncmp (name, ".sbss.", 6) == 0
5798 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5799 flags |= SECTION_BSS;
5801 if (strcmp (name, ".tdata") == 0
5802 || strncmp (name, ".tdata.", 7) == 0
5803 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
5804 flags |= SECTION_TLS;
5806 if (strcmp (name, ".tbss") == 0
5807 || strncmp (name, ".tbss.", 6) == 0
5808 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
5809 flags |= SECTION_TLS | SECTION_BSS;
5811 /* These three sections have special ELF types. They are neither
5812 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
5813 want to print a section type (@progbits or @nobits). If someone
5814 is silly enough to emit code or TLS variables to one of these
5815 sections, then don't handle them specially. */
5816 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
5817 && (strcmp (name, ".init_array") == 0
5818 || strcmp (name, ".fini_array") == 0
5819 || strcmp (name, ".preinit_array") == 0))
5820 flags |= SECTION_NOTYPE;
5825 /* Return true if the target supports some form of global BSS,
5826 either through bss_noswitch_section, or by selecting a BSS
5827 section in TARGET_ASM_SELECT_SECTION. */
5830 have_global_bss_p (void)
5832 return bss_noswitch_section || targetm.have_switchable_bss_sections;
5835 /* Output assembly to switch to section NAME with attribute FLAGS.
5836 Four variants for common object file formats. */
5839 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
5840 unsigned int flags ATTRIBUTE_UNUSED,
5841 tree decl ATTRIBUTE_UNUSED)
5843 /* Some object formats don't support named sections at all. The
5844 front-end should already have flagged this as an error. */
5848 #ifndef TLS_SECTION_ASM_FLAG
5849 #define TLS_SECTION_ASM_FLAG 'T'
5853 default_elf_asm_named_section (const char *name, unsigned int flags,
5854 tree decl ATTRIBUTE_UNUSED)
5856 char flagchars[10], *f = flagchars;
5858 /* If we have already declared this section, we can use an
5859 abbreviated form to switch back to it -- unless this section is
5860 part of a COMDAT groups, in which case GAS requires the full
5861 declaration every time. */
5862 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5863 && (flags & SECTION_DECLARED))
5865 fprintf (asm_out_file, "\t.section\t%s\n", name);
5869 if (!(flags & SECTION_DEBUG))
5871 if (flags & SECTION_WRITE)
5873 if (flags & SECTION_CODE)
5875 if (flags & SECTION_SMALL)
5877 if (flags & SECTION_MERGE)
5879 if (flags & SECTION_STRINGS)
5881 if (flags & SECTION_TLS)
5882 *f++ = TLS_SECTION_ASM_FLAG;
5883 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5887 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
5889 if (!(flags & SECTION_NOTYPE))
5894 if (flags & SECTION_BSS)
5900 #ifdef ASM_COMMENT_START
5901 /* On platforms that use "@" as the assembly comment character,
5903 if (strcmp (ASM_COMMENT_START, "@") == 0)
5906 fprintf (asm_out_file, format, type);
5908 if (flags & SECTION_ENTSIZE)
5909 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
5910 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5912 if (TREE_CODE (decl) == IDENTIFIER_NODE)
5913 fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
5915 fprintf (asm_out_file, ",%s,comdat",
5916 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
5920 putc ('\n', asm_out_file);
5924 default_coff_asm_named_section (const char *name, unsigned int flags,
5925 tree decl ATTRIBUTE_UNUSED)
5927 char flagchars[8], *f = flagchars;
5929 if (flags & SECTION_WRITE)
5931 if (flags & SECTION_CODE)
5935 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5939 default_pe_asm_named_section (const char *name, unsigned int flags,
5942 default_coff_asm_named_section (name, flags, decl);
5944 if (flags & SECTION_LINKONCE)
5946 /* Functions may have been compiled at various levels of
5947 optimization so we can't use `same_size' here.
5948 Instead, have the linker pick one. */
5949 fprintf (asm_out_file, "\t.linkonce %s\n",
5950 (flags & SECTION_CODE ? "discard" : "same_size"));
5954 /* The lame default section selector. */
5957 default_select_section (tree decl, int reloc,
5958 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5962 if (decl_readonly_section (decl, reloc))
5963 return readonly_data_section;
5965 else if (TREE_CODE (decl) == CONSTRUCTOR)
5967 if (! ((flag_pic && reloc)
5968 || !TREE_READONLY (decl)
5969 || TREE_SIDE_EFFECTS (decl)
5970 || !TREE_CONSTANT (decl)))
5971 return readonly_data_section;
5973 else if (TREE_CODE (decl) == STRING_CST)
5974 return readonly_data_section;
5975 else if (! (flag_pic && reloc))
5976 return readonly_data_section;
5978 return data_section;
5981 enum section_category
5982 categorize_decl_for_section (const_tree decl, int reloc)
5984 enum section_category ret;
5986 if (TREE_CODE (decl) == FUNCTION_DECL)
5988 else if (TREE_CODE (decl) == STRING_CST)
5990 if (flag_mudflap) /* or !flag_merge_constants */
5991 return SECCAT_RODATA;
5993 return SECCAT_RODATA_MERGE_STR;
5995 else if (TREE_CODE (decl) == VAR_DECL)
5997 if (bss_initializer_p (decl))
5999 else if (! TREE_READONLY (decl)
6000 || TREE_SIDE_EFFECTS (decl)
6001 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6003 /* Here the reloc_rw_mask is not testing whether the section should
6004 be read-only or not, but whether the dynamic link will have to
6005 do something. If so, we wish to segregate the data in order to
6006 minimize cache misses inside the dynamic linker. */
6007 if (reloc & targetm.asm_out.reloc_rw_mask ())
6008 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6012 else if (reloc & targetm.asm_out.reloc_rw_mask ())
6013 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6014 else if (reloc || flag_merge_constants < 2)
6015 /* C and C++ don't allow different variables to share the same
6016 location. -fmerge-all-constants allows even that (at the
6017 expense of not conforming). */
6018 ret = SECCAT_RODATA;
6019 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6020 ret = SECCAT_RODATA_MERGE_STR_INIT;
6022 ret = SECCAT_RODATA_MERGE_CONST;
6024 else if (TREE_CODE (decl) == CONSTRUCTOR)
6026 if ((reloc & targetm.asm_out.reloc_rw_mask ())
6027 || TREE_SIDE_EFFECTS (decl)
6028 || ! TREE_CONSTANT (decl))
6031 ret = SECCAT_RODATA;
6034 ret = SECCAT_RODATA;
6036 /* There are no read-only thread-local sections. */
6037 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6039 /* Note that this would be *just* SECCAT_BSS, except that there's
6040 no concept of a read-only thread-local-data section. */
6041 if (ret == SECCAT_BSS
6042 || (flag_zero_initialized_in_bss
6043 && initializer_zerop (DECL_INITIAL (decl))))
6049 /* If the target uses small data sections, select it. */
6050 else if (targetm.in_small_data_p (decl))
6052 if (ret == SECCAT_BSS)
6054 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6055 ret = SECCAT_SRODATA;
6064 decl_readonly_section (const_tree decl, int reloc)
6066 switch (categorize_decl_for_section (decl, reloc))
6069 case SECCAT_RODATA_MERGE_STR:
6070 case SECCAT_RODATA_MERGE_STR_INIT:
6071 case SECCAT_RODATA_MERGE_CONST:
6072 case SECCAT_SRODATA:
6081 /* Select a section based on the above categorization. */
6084 default_elf_select_section (tree decl, int reloc,
6085 unsigned HOST_WIDE_INT align)
6088 switch (categorize_decl_for_section (decl, reloc))
6091 /* We're not supposed to be called on FUNCTION_DECLs. */
6094 return readonly_data_section;
6095 case SECCAT_RODATA_MERGE_STR:
6096 return mergeable_string_section (decl, align, 0);
6097 case SECCAT_RODATA_MERGE_STR_INIT:
6098 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6099 case SECCAT_RODATA_MERGE_CONST:
6100 return mergeable_constant_section (DECL_MODE (decl), align, 0);
6101 case SECCAT_SRODATA:
6105 return data_section;
6106 case SECCAT_DATA_REL:
6107 sname = ".data.rel";
6109 case SECCAT_DATA_REL_LOCAL:
6110 sname = ".data.rel.local";
6112 case SECCAT_DATA_REL_RO:
6113 sname = ".data.rel.ro";
6115 case SECCAT_DATA_REL_RO_LOCAL:
6116 sname = ".data.rel.ro.local";
6141 return get_named_section (decl, sname, reloc);
6144 /* Construct a unique section name based on the decl name and the
6145 categorization performed above. */
6148 default_unique_section (tree decl, int reloc)
6150 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6151 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6152 const char *prefix, *name, *linkonce;
6155 switch (categorize_decl_for_section (decl, reloc))
6158 prefix = one_only ? ".t" : ".text";
6161 case SECCAT_RODATA_MERGE_STR:
6162 case SECCAT_RODATA_MERGE_STR_INIT:
6163 case SECCAT_RODATA_MERGE_CONST:
6164 prefix = one_only ? ".r" : ".rodata";
6166 case SECCAT_SRODATA:
6167 prefix = one_only ? ".s2" : ".sdata2";
6170 prefix = one_only ? ".d" : ".data";
6172 case SECCAT_DATA_REL:
6173 prefix = one_only ? ".d.rel" : ".data.rel";
6175 case SECCAT_DATA_REL_LOCAL:
6176 prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6178 case SECCAT_DATA_REL_RO:
6179 prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6181 case SECCAT_DATA_REL_RO_LOCAL:
6182 prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6185 prefix = one_only ? ".s" : ".sdata";
6188 prefix = one_only ? ".b" : ".bss";
6191 prefix = one_only ? ".sb" : ".sbss";
6194 prefix = one_only ? ".td" : ".tdata";
6197 prefix = one_only ? ".tb" : ".tbss";
6203 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6204 name = targetm.strip_name_encoding (name);
6206 /* If we're using one_only, then there needs to be a .gnu.linkonce
6207 prefix to the section name. */
6208 linkonce = one_only ? ".gnu.linkonce" : "";
6210 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6212 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6215 /* Like compute_reloc_for_constant, except for an RTX. The return value
6216 is a mask for which bit 1 indicates a global relocation, and bit 0
6217 indicates a local relocation. */
6220 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6222 int *preloc = (int *) data;
6225 switch (GET_CODE (x))
6228 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6241 compute_reloc_for_rtx (rtx x)
6245 switch (GET_CODE (x))
6251 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6260 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6262 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6264 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6265 return data_section;
6267 return readonly_data_section;
6271 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6272 unsigned HOST_WIDE_INT align)
6274 int reloc = compute_reloc_for_rtx (x);
6276 /* ??? Handle small data here somehow. */
6278 if (reloc & targetm.asm_out.reloc_rw_mask ())
6281 return get_named_section (NULL, ".data.rel.ro.local", 1);
6283 return get_named_section (NULL, ".data.rel.ro", 3);
6286 return mergeable_constant_section (mode, align, 0);
6289 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6292 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6297 /* Careful not to prod global register variables. */
6300 symbol = XEXP (rtl, 0);
6301 if (GET_CODE (symbol) != SYMBOL_REF)
6304 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6305 if (TREE_CODE (decl) == FUNCTION_DECL)
6306 flags |= SYMBOL_FLAG_FUNCTION;
6307 if (targetm.binds_local_p (decl))
6308 flags |= SYMBOL_FLAG_LOCAL;
6309 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6310 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6311 else if (targetm.in_small_data_p (decl))
6312 flags |= SYMBOL_FLAG_SMALL;
6313 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6314 being PUBLIC, the thing *must* be defined in this translation unit.
6315 Prevent this buglet from being propagated into rtl code as well. */
6316 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6317 flags |= SYMBOL_FLAG_EXTERNAL;
6319 SYMBOL_REF_FLAGS (symbol) = flags;
6322 /* By default, we do nothing for encode_section_info, so we need not
6323 do anything but discard the '*' marker. */
6326 default_strip_name_encoding (const char *str)
6328 return str + (*str == '*');
6331 #ifdef ASM_OUTPUT_DEF
6332 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6333 anchor relative to ".", the current section position. */
6336 default_asm_output_anchor (rtx symbol)
6340 sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6341 SYMBOL_REF_BLOCK_OFFSET (symbol));
6342 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6346 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6349 default_use_anchors_for_symbol_p (const_rtx symbol)
6354 /* Don't use anchors for mergeable sections. The linker might move
6355 the objects around. */
6356 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6357 if (sect->common.flags & SECTION_MERGE)
6360 /* Don't use anchors for small data sections. The small data register
6361 acts as an anchor for such sections. */
6362 if (sect->common.flags & SECTION_SMALL)
6365 decl = SYMBOL_REF_DECL (symbol);
6366 if (decl && DECL_P (decl))
6368 /* Don't use section anchors for decls that might be defined by
6370 if (!targetm.binds_local_p (decl))
6373 /* Don't use section anchors for decls that will be placed in a
6374 small data section. */
6375 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6376 one above. The problem is that we only use SECTION_SMALL for
6377 sections that should be marked as small in the section directive. */
6378 if (targetm.in_small_data_p (decl))
6384 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6385 wrt cross-module name binding. */
6388 default_binds_local_p (const_tree exp)
6390 return default_binds_local_p_1 (exp, flag_shlib);
6394 default_binds_local_p_1 (const_tree exp, int shlib)
6398 /* A non-decl is an entry in the constant pool. */
6401 /* Weakrefs may not bind locally, even though the weakref itself is
6402 always static and therefore local. */
6403 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6405 /* Static variables are always local. */
6406 else if (! TREE_PUBLIC (exp))
6408 /* A variable is local if the user has said explicitly that it will
6410 else if (DECL_VISIBILITY_SPECIFIED (exp)
6411 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6413 /* Variables defined outside this object might not be local. */
6414 else if (DECL_EXTERNAL (exp))
6416 /* If defined in this object and visibility is not default, must be
6418 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6420 /* Default visibility weak data can be overridden by a strong symbol
6421 in another module and so are not local. */
6422 else if (DECL_WEAK (exp))
6424 /* If PIC, then assume that any global name can be overridden by
6425 symbols resolved from other modules, unless we are compiling with
6426 -fwhole-program, which assumes that names are local. */
6428 local_p = flag_whole_program;
6429 /* Uninitialized COMMON variable may be unified with symbols
6430 resolved from other modules. */
6431 else if (DECL_COMMON (exp)
6432 && (DECL_INITIAL (exp) == NULL
6433 || DECL_INITIAL (exp) == error_mark_node))
6435 /* Otherwise we're left with initialized (or non-common) global data
6436 which is of necessity defined locally. */
6443 /* Default function to output code that will globalize a label. A
6444 target must define GLOBAL_ASM_OP or provide its own function to
6445 globalize a label. */
6446 #ifdef GLOBAL_ASM_OP
6448 default_globalize_label (FILE * stream, const char *name)
6450 fputs (GLOBAL_ASM_OP, stream);
6451 assemble_name (stream, name);
6452 putc ('\n', stream);
6454 #endif /* GLOBAL_ASM_OP */
6456 /* Default function to output code that will globalize a declaration. */
6458 default_globalize_decl_name (FILE * stream, tree decl)
6460 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6461 targetm.asm_out.globalize_label (stream, name);
6464 /* Default function to output a label for unwind information. The
6465 default is to do nothing. A target that needs nonlocal labels for
6466 unwind information must provide its own function to do this. */
6468 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6469 tree decl ATTRIBUTE_UNUSED,
6470 int for_eh ATTRIBUTE_UNUSED,
6471 int empty ATTRIBUTE_UNUSED)
6475 /* Default function to output a label to divide up the exception table.
6476 The default is to do nothing. A target that needs/wants to divide
6477 up the table must provide it's own function to do this. */
6479 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6483 /* This is how to output an internal numbered label where PREFIX is
6484 the class of label and LABELNO is the number within the class. */
6487 default_internal_label (FILE *stream, const char *prefix,
6488 unsigned long labelno)
6490 char *const buf = (char *) alloca (40 + strlen (prefix));
6491 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6492 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6496 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6499 default_asm_declare_constant_name (FILE *file, const char *name,
6500 const_tree exp ATTRIBUTE_UNUSED,
6501 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
6503 assemble_label (file, name);
6506 /* This is the default behavior at the beginning of a file. It's
6507 controlled by two other target-hook toggles. */
6509 default_file_start (void)
6511 if (targetm.asm_file_start_app_off
6512 && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
6513 fputs (ASM_APP_OFF, asm_out_file);
6515 if (targetm.asm_file_start_file_directive)
6516 output_file_directive (asm_out_file, main_input_filename);
6519 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6520 which emits a special section directive used to indicate whether or
6521 not this object file needs an executable stack. This is primarily
6522 a GNU extension to ELF but could be used on other targets. */
6524 int trampolines_created;
6527 file_end_indicate_exec_stack (void)
6529 unsigned int flags = SECTION_DEBUG;
6530 if (trampolines_created)
6531 flags |= SECTION_CODE;
6533 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
6536 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6537 a get_unnamed_section callback. */
6540 output_section_asm_op (const void *directive)
6542 fprintf (asm_out_file, "%s\n", (const char *) directive);
6545 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6546 the current section is NEW_SECTION. */
6549 switch_to_section (section *new_section)
6551 if (in_section == new_section)
6554 if (new_section->common.flags & SECTION_FORGET)
6557 in_section = new_section;
6559 switch (SECTION_STYLE (new_section))
6563 && !crtl->subsections.unlikely_text_section_name
6564 && strcmp (new_section->named.name,
6565 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6566 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6568 targetm.asm_out.named_section (new_section->named.name,
6569 new_section->named.common.flags,
6570 new_section->named.decl);
6573 case SECTION_UNNAMED:
6574 new_section->unnamed.callback (new_section->unnamed.data);
6577 case SECTION_NOSWITCH:
6582 new_section->common.flags |= SECTION_DECLARED;
6585 /* If block symbol SYMBOL has not yet been assigned an offset, place
6586 it at the end of its block. */
6589 place_block_symbol (rtx symbol)
6591 unsigned HOST_WIDE_INT size, mask, offset;
6592 struct constant_descriptor_rtx *desc;
6593 unsigned int alignment;
6594 struct object_block *block;
6597 gcc_assert (SYMBOL_REF_BLOCK (symbol));
6598 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6601 /* Work out the symbol's size and alignment. */
6602 if (CONSTANT_POOL_ADDRESS_P (symbol))
6604 desc = SYMBOL_REF_CONSTANT (symbol);
6605 alignment = desc->align;
6606 size = GET_MODE_SIZE (desc->mode);
6608 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6610 decl = SYMBOL_REF_DECL (symbol);
6611 alignment = DECL_ALIGN (decl);
6612 size = get_constant_size (DECL_INITIAL (decl));
6616 decl = SYMBOL_REF_DECL (symbol);
6617 alignment = DECL_ALIGN (decl);
6618 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6621 /* Calculate the object's offset from the start of the block. */
6622 block = SYMBOL_REF_BLOCK (symbol);
6623 mask = alignment / BITS_PER_UNIT - 1;
6624 offset = (block->size + mask) & ~mask;
6625 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
6627 /* Record the block's new alignment and size. */
6628 block->alignment = MAX (block->alignment, alignment);
6629 block->size = offset + size;
6631 VEC_safe_push (rtx, gc, block->objects, symbol);
6634 /* Return the anchor that should be used to address byte offset OFFSET
6635 from the first object in BLOCK. MODEL is the TLS model used
6639 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
6640 enum tls_model model)
6643 unsigned int begin, middle, end;
6644 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
6647 /* Work out the anchor's offset. Use an offset of 0 for the first
6648 anchor so that we don't pessimize the case where we take the address
6649 of a variable at the beginning of the block. This is particularly
6650 useful when a block has only one variable assigned to it.
6652 We try to place anchors RANGE bytes apart, so there can then be
6653 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6654 a ptr_mode offset. With some target settings, the lowest such
6655 anchor might be out of range for the lowest ptr_mode offset;
6656 likewise the highest anchor for the highest offset. Use anchors
6657 at the extreme ends of the ptr_mode range in such cases.
6659 All arithmetic uses unsigned integers in order to avoid
6661 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
6662 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
6663 range = max_offset - min_offset + 1;
6668 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
6671 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
6672 delta -= delta % range;
6675 offset = (HOST_WIDE_INT) (-delta);
6679 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
6680 delta -= delta % range;
6681 if (delta > bias - 1)
6683 offset = (HOST_WIDE_INT) delta;
6687 /* Do a binary search to see if there's already an anchor we can use.
6688 Set BEGIN to the new anchor's index if not. */
6690 end = VEC_length (rtx, block->anchors);
6691 while (begin != end)
6693 middle = (end + begin) / 2;
6694 anchor = VEC_index (rtx, block->anchors, middle);
6695 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
6697 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
6699 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
6701 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
6707 /* Create a new anchor with a unique label. */
6708 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
6709 anchor = create_block_symbol (ggc_strdup (label), block, offset);
6710 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
6711 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
6713 /* Insert it at index BEGIN. */
6714 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
6718 /* Output the objects in BLOCK. */
6721 output_object_block (struct object_block *block)
6723 struct constant_descriptor_rtx *desc;
6725 HOST_WIDE_INT offset;
6729 if (block->objects == NULL)
6732 /* Switch to the section and make sure that the first byte is
6733 suitably aligned. */
6734 switch_to_section (block->sect);
6735 assemble_align (block->alignment);
6737 /* Define the values of all anchors relative to the current section
6739 FOR_EACH_VEC_ELT (rtx, block->anchors, i, symbol)
6740 targetm.asm_out.output_anchor (symbol);
6742 /* Output the objects themselves. */
6744 FOR_EACH_VEC_ELT (rtx, block->objects, i, symbol)
6746 /* Move to the object's offset, padding with zeros if necessary. */
6747 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
6748 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
6749 if (CONSTANT_POOL_ADDRESS_P (symbol))
6751 desc = SYMBOL_REF_CONSTANT (symbol);
6752 output_constant_pool_1 (desc, 1);
6753 offset += GET_MODE_SIZE (desc->mode);
6755 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6757 decl = SYMBOL_REF_DECL (symbol);
6758 assemble_constant_contents (DECL_INITIAL (decl), XSTR (symbol, 0),
6760 offset += get_constant_size (DECL_INITIAL (decl));
6764 decl = SYMBOL_REF_DECL (symbol);
6765 assemble_variable_contents (decl, XSTR (symbol, 0), false);
6766 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6771 /* A htab_traverse callback used to call output_object_block for
6772 each member of object_block_htab. */
6775 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
6777 output_object_block ((struct object_block *) (*slot));
6781 /* Output the definitions of all object_blocks. */
6784 output_object_blocks (void)
6786 htab_traverse (object_block_htab, output_object_block_htab, NULL);
6789 /* This function provides a possible implementation of the
6790 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
6791 by -frecord-gcc-switches it creates a new mergeable, string section in the
6792 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
6793 contains the switches in ASCII format.
6795 FIXME: This code does not correctly handle double quote characters
6796 that appear inside strings, (it strips them rather than preserving them).
6797 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
6798 characters - instead it treats them as sub-string separators. Since
6799 we want to emit NUL strings terminators into the object file we have to use
6803 elf_record_gcc_switches (print_switch_type type, const char * name)
6807 case SWITCH_TYPE_PASSED:
6808 ASM_OUTPUT_ASCII (asm_out_file, name, strlen (name));
6809 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
6812 case SWITCH_TYPE_DESCRIPTIVE:
6815 /* Distinguish between invocations where name is NULL. */
6816 static bool started = false;
6822 sec = get_section (targetm.asm_out.record_gcc_switches_section,
6826 | (SECTION_ENTSIZE & 1),
6828 switch_to_section (sec);
6837 /* The return value is currently ignored by the caller, but must be 0.
6838 For -fverbose-asm the return value would be the number of characters
6839 emitted into the assembler file. */
6843 /* Emit text to declare externally defined symbols. It is needed to
6844 properly support non-default visibility. */
6846 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
6848 const char *name ATTRIBUTE_UNUSED)
6850 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
6851 set in order to avoid putting out names that are never really
6853 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
6854 && targetm.binds_local_p (decl))
6855 maybe_assemble_visibility (decl);
6858 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
6861 default_asm_output_source_filename (FILE *file, const char *name)
6863 #ifdef ASM_OUTPUT_SOURCE_FILENAME
6864 ASM_OUTPUT_SOURCE_FILENAME (file, name);
6866 fprintf (file, "\t.file\t");
6867 output_quoted_string (file, name);
6872 /* Output a file name in the form wanted by System V. */
6875 output_file_directive (FILE *asm_file, const char *input_name)
6880 if (input_name == NULL)
6881 input_name = "<stdin>";
6883 input_name = remap_debug_filename (input_name);
6885 len = strlen (input_name);
6886 na = input_name + len;
6888 /* NA gets INPUT_NAME sans directory names. */
6889 while (na > input_name)
6891 if (IS_DIR_SEPARATOR (na[-1]))
6896 targetm.asm_out.output_source_filename (asm_file, na);
6899 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
6902 make_debug_expr_from_rtl (const_rtx exp)
6904 tree ddecl = make_node (DEBUG_EXPR_DECL), type;
6905 enum machine_mode mode = GET_MODE (exp);
6908 DECL_ARTIFICIAL (ddecl) = 1;
6909 if (REG_P (exp) && REG_EXPR (exp))
6910 type = TREE_TYPE (REG_EXPR (exp));
6911 else if (MEM_P (exp) && MEM_EXPR (exp))
6912 type = TREE_TYPE (MEM_EXPR (exp));
6915 if (type && TYPE_MODE (type) == mode)
6916 TREE_TYPE (ddecl) = type;
6918 TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
6919 DECL_MODE (ddecl) = mode;
6920 dval = gen_rtx_DEBUG_EXPR (mode);
6921 DEBUG_EXPR_TREE_DECL (dval) = ddecl;
6922 SET_DECL_RTL (ddecl, dval);
6926 #include "gt-varasm.h"