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, 2011 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"
33 #include "pointer-set.h"
40 #include "hard-reg-set.h"
43 #include "diagnostic-core.h"
46 #include "langhooks.h"
50 #include "common/common-target.h"
51 #include "targhooks.h"
52 #include "tree-mudflap.h"
54 #include "cfglayout.h"
55 #include "basic-block.h"
56 #include "tree-iterator.h"
57 #include "pointer-set.h"
59 #ifdef XCOFF_DEBUGGING_INFO
60 #include "xcoffout.h" /* Needed for external data
61 declarations for e.g. AIX 4.x. */
64 /* The (assembler) name of the first globally-visible object output. */
65 extern GTY(()) const char *first_global_object_name;
66 extern GTY(()) const char *weak_global_object_name;
68 const char *first_global_object_name;
69 const char *weak_global_object_name;
72 struct constant_descriptor_rtx;
73 struct rtx_constant_pool;
75 #define n_deferred_constants (crtl->varasm.deferred_constants)
77 /* Number for making the label on the next
78 constant that is stored in memory. */
80 static GTY(()) int const_labelno;
82 /* Carry information from ASM_DECLARE_OBJECT_NAME
83 to ASM_FINISH_DECLARE_OBJECT. */
85 int size_directive_output;
87 /* The last decl for which assemble_variable was called,
88 if it did ASM_DECLARE_OBJECT_NAME.
89 If the last call to assemble_variable didn't do that,
92 tree last_assemble_variable_decl;
94 /* The following global variable indicates if the first basic block
95 in a function belongs to the cold partition or not. */
97 bool first_function_block_is_cold;
99 /* We give all constants their own alias set. Perhaps redundant with
100 MEM_READONLY_P, but pre-dates it. */
102 static alias_set_type const_alias_set;
104 /* Whether we saw any functions with no_split_stack. */
106 static bool saw_no_split_stack;
108 static const char *strip_reg_name (const char *);
109 static int contains_pointers_p (tree);
110 #ifdef ASM_OUTPUT_EXTERNAL
111 static bool incorporeal_function_p (tree);
113 static void decode_addr_const (tree, struct addr_const *);
114 static hashval_t const_desc_hash (const void *);
115 static int const_desc_eq (const void *, const void *);
116 static hashval_t const_hash_1 (const tree);
117 static int compare_constant (const tree, const tree);
118 static tree copy_constant (tree);
119 static void output_constant_def_contents (rtx);
120 static void output_addressed_constants (tree);
121 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
122 static unsigned min_align (unsigned, unsigned);
123 static void globalize_decl (tree);
124 static bool decl_readonly_section_1 (enum section_category);
125 #ifdef BSS_SECTION_ASM_OP
126 #ifdef ASM_OUTPUT_ALIGNED_BSS
127 static void asm_output_aligned_bss (FILE *, tree, const char *,
128 unsigned HOST_WIDE_INT, int)
131 #endif /* BSS_SECTION_ASM_OP */
132 static void mark_weak (tree);
133 static void output_constant_pool (const char *, tree);
135 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
136 section *text_section;
137 section *data_section;
138 section *readonly_data_section;
139 section *sdata_section;
140 section *ctors_section;
141 section *dtors_section;
142 section *bss_section;
143 section *sbss_section;
145 /* Various forms of common section. All are guaranteed to be nonnull. */
146 section *tls_comm_section;
147 section *comm_section;
148 section *lcomm_section;
150 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
152 section *bss_noswitch_section;
154 /* The section that holds the main exception table, when known. The section
155 is set either by the target's init_sections hook or by the first call to
156 switch_to_exception_section. */
157 section *exception_section;
159 /* The section that holds the DWARF2 frame unwind information, when known.
160 The section is set either by the target's init_sections hook or by the
161 first call to switch_to_eh_frame_section. */
162 section *eh_frame_section;
164 /* asm_out_file's current section. This is NULL if no section has yet
165 been selected or if we lose track of what the current section is. */
168 /* True if code for the current function is currently being directed
169 at the cold section. */
170 bool in_cold_section_p;
172 /* A linked list of all the unnamed sections. */
173 static GTY(()) section *unnamed_sections;
175 /* Return a nonzero value if DECL has a section attribute. */
176 #define IN_NAMED_SECTION(DECL) \
177 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
178 && DECL_SECTION_NAME (DECL) != NULL_TREE)
180 /* Hash table of named sections. */
181 static GTY((param_is (section))) htab_t section_htab;
183 /* A table of object_blocks, indexed by section. */
184 static GTY((param_is (struct object_block))) htab_t object_block_htab;
186 /* The next number to use for internal anchor labels. */
187 static GTY(()) int anchor_labelno;
189 /* A pool of constants that can be shared between functions. */
190 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
192 /* Helper routines for maintaining section_htab. */
195 section_entry_eq (const void *p1, const void *p2)
197 const section *old = (const section *) p1;
198 const char *new_name = (const char *) p2;
200 return strcmp (old->named.name, new_name) == 0;
204 section_entry_hash (const void *p)
206 const section *old = (const section *) p;
207 return htab_hash_string (old->named.name);
210 /* Return a hash value for section SECT. */
213 hash_section (section *sect)
215 if (sect->common.flags & SECTION_NAMED)
216 return htab_hash_string (sect->named.name);
217 return sect->common.flags;
220 /* Helper routines for maintaining object_block_htab. */
223 object_block_entry_eq (const void *p1, const void *p2)
225 const struct object_block *old = (const struct object_block *) p1;
226 const section *new_section = (const section *) p2;
228 return old->sect == new_section;
232 object_block_entry_hash (const void *p)
234 const struct object_block *old = (const struct object_block *) p;
235 return hash_section (old->sect);
238 /* Return a new unnamed section with the given fields. */
241 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
246 sect = ggc_alloc_section ();
247 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
248 sect->unnamed.callback = callback;
249 sect->unnamed.data = data;
250 sect->unnamed.next = unnamed_sections;
252 unnamed_sections = sect;
256 /* Return a SECTION_NOSWITCH section with the given fields. */
259 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
263 sect = ggc_alloc_section ();
264 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
265 sect->noswitch.callback = callback;
270 /* Return the named section structure associated with NAME. Create
271 a new section with the given fields if no such structure exists. */
274 get_section (const char *name, unsigned int flags, tree decl)
276 section *sect, **slot;
279 htab_find_slot_with_hash (section_htab, name,
280 htab_hash_string (name), INSERT);
281 flags |= SECTION_NAMED;
284 sect = ggc_alloc_section ();
285 sect->named.common.flags = flags;
286 sect->named.name = ggc_strdup (name);
287 sect->named.decl = decl;
293 if ((sect->common.flags & ~SECTION_DECLARED) != flags
294 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
296 /* It is fine if one of the section flags is
297 SECTION_WRITE | SECTION_RELRO and the other has none of these
298 flags (i.e. read-only) in named sections and either the
299 section hasn't been declared yet or has been declared as writable.
300 In that case just make sure the resulting flags are
301 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
303 if (((sect->common.flags ^ flags) & (SECTION_WRITE | SECTION_RELRO))
304 == (SECTION_WRITE | SECTION_RELRO)
305 && (sect->common.flags
306 & ~(SECTION_DECLARED | SECTION_WRITE | SECTION_RELRO))
307 == (flags & ~(SECTION_WRITE | SECTION_RELRO))
308 && ((sect->common.flags & SECTION_DECLARED) == 0
309 || (sect->common.flags & SECTION_WRITE)))
311 sect->common.flags |= (SECTION_WRITE | SECTION_RELRO);
314 /* Sanity check user variables for flag changes. */
316 decl = sect->named.decl;
318 error ("%+D causes a section type conflict with %D",
319 decl, sect->named.decl);
320 if (decl != sect->named.decl)
321 inform (DECL_SOURCE_LOCATION (sect->named.decl),
322 "%qD was declared here", sect->named.decl);
323 /* Make sure we don't error about one section multiple times. */
324 sect->common.flags |= SECTION_OVERRIDE;
330 /* Return true if the current compilation mode benefits from having
331 objects grouped into blocks. */
334 use_object_blocks_p (void)
336 return flag_section_anchors;
339 /* Return the object_block structure for section SECT. Create a new
340 structure if we haven't created one already. Return null if SECT
343 static struct object_block *
344 get_block_for_section (section *sect)
346 struct object_block *block;
352 slot = htab_find_slot_with_hash (object_block_htab, sect,
353 hash_section (sect), INSERT);
354 block = (struct object_block *) *slot;
357 block = ggc_alloc_cleared_object_block ();
364 /* Create a symbol with label LABEL and place it at byte offset
365 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
366 is not yet known. LABEL must be a garbage-collected string. */
369 create_block_symbol (const char *label, struct object_block *block,
370 HOST_WIDE_INT offset)
375 /* Create the extended SYMBOL_REF. */
376 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
377 symbol = ggc_alloc_zone_rtx_def (size, &rtl_zone);
379 /* Initialize the normal SYMBOL_REF fields. */
380 memset (symbol, 0, size);
381 PUT_CODE (symbol, SYMBOL_REF);
382 PUT_MODE (symbol, Pmode);
383 XSTR (symbol, 0) = label;
384 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
386 /* Initialize the block_symbol stuff. */
387 SYMBOL_REF_BLOCK (symbol) = block;
388 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
393 /* Return a section with a particular name and with whatever SECTION_*
394 flags section_type_flags deems appropriate. The name of the section
395 is taken from NAME if nonnull, otherwise it is taken from DECL's
396 DECL_SECTION_NAME. DECL is the decl associated with the section
397 (see the section comment for details) and RELOC is as for
398 section_type_flags. */
401 get_named_section (tree decl, const char *name, int reloc)
405 gcc_assert (!decl || DECL_P (decl));
407 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
409 flags = targetm.section_type_flags (decl, name, reloc);
411 return get_section (name, flags, decl);
414 /* If required, set DECL_SECTION_NAME to a unique name. */
417 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
418 int flag_function_or_data_sections)
420 if (DECL_SECTION_NAME (decl) == NULL_TREE
421 && targetm_common.have_named_sections
422 && (flag_function_or_data_sections
423 || DECL_ONE_ONLY (decl)))
425 targetm.asm_out.unique_section (decl, reloc);
426 DECL_HAS_IMPLICIT_SECTION_NAME_P (decl) = true;
430 #ifdef BSS_SECTION_ASM_OP
432 #ifdef ASM_OUTPUT_ALIGNED_BSS
434 /* Utility function for targets to use in implementing
435 ASM_OUTPUT_ALIGNED_BSS.
436 ??? It is believed that this function will work in most cases so such
437 support is localized here. */
440 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
441 const char *name, unsigned HOST_WIDE_INT size,
444 switch_to_section (bss_section);
445 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
446 #ifdef ASM_DECLARE_OBJECT_NAME
447 last_assemble_variable_decl = decl;
448 ASM_DECLARE_OBJECT_NAME (file, name, decl);
450 /* Standard thing is just output label for the object. */
451 ASM_OUTPUT_LABEL (file, name);
452 #endif /* ASM_DECLARE_OBJECT_NAME */
453 ASM_OUTPUT_SKIP (file, size ? size : 1);
458 #endif /* BSS_SECTION_ASM_OP */
460 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
461 /* Return the hot section for function DECL. Return text_section for
465 hot_function_section (tree decl)
467 if (decl != NULL_TREE
468 && DECL_SECTION_NAME (decl) != NULL_TREE
469 && targetm_common.have_named_sections)
470 return get_named_section (decl, NULL, 0);
476 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
479 When DECL_SECTION_NAME is non-NULL and it is implicit section and
480 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
481 concatenate the name with NAMED_SECTION_SUFFIX.
482 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
485 get_named_text_section (tree decl,
486 const char *text_section_name,
487 const char *named_section_suffix)
489 if (decl && DECL_SECTION_NAME (decl))
491 if (named_section_suffix)
493 tree dsn = DECL_SECTION_NAME (decl);
494 const char *stripped_name;
497 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
498 memcpy (name, TREE_STRING_POINTER (dsn),
499 TREE_STRING_LENGTH (dsn) + 1);
501 stripped_name = targetm.strip_name_encoding (name);
503 buffer = ACONCAT ((stripped_name, named_section_suffix, NULL));
504 return get_named_section (decl, buffer, 0);
506 else if (DECL_HAS_IMPLICIT_SECTION_NAME_P (decl))
510 /* Do not try to split gnu_linkonce functions. This gets somewhat
512 if (DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP)
514 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
515 name = targetm.strip_name_encoding (name);
516 return get_named_section (decl, ACONCAT ((text_section_name, ".",
522 return get_named_section (decl, text_section_name, 0);
525 /* Choose named function section based on its frequency. */
528 default_function_section (tree decl, enum node_frequency freq,
529 bool startup, bool exit)
531 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
532 /* Old GNU linkers have buggy --gc-section support, which sometimes
533 results in .gcc_except_table* sections being garbage collected. */
535 && DECL_SECTION_NAME (decl)
536 && DECL_HAS_IMPLICIT_SECTION_NAME_P (decl))
540 if (!flag_reorder_functions
541 || !targetm_common.have_named_sections)
543 /* Startup code should go to startup subsection unless it is
544 unlikely executed (this happens especially with function splitting
545 where we can split away unnecesary parts of static constructors. */
546 if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
547 return get_named_text_section (decl, ".text.startup", NULL);
549 /* Similarly for exit. */
550 if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
551 return get_named_text_section (decl, ".text.exit", NULL);
553 /* Group cold functions together, similarly for hot code. */
556 case NODE_FREQUENCY_UNLIKELY_EXECUTED:
557 return get_named_text_section (decl, ".text.unlikely", NULL);
558 case NODE_FREQUENCY_HOT:
559 return get_named_text_section (decl, ".text.hot", NULL);
565 /* Return the section for function DECL.
567 If DECL is NULL_TREE, return the text section. We can be passed
568 NULL_TREE under some circumstances by dbxout.c at least.
570 If FORCE_COLD is true, return cold function section ignoring
571 the frequency info of cgraph_node. */
574 function_section_1 (tree decl, bool force_cold)
576 section *section = NULL;
577 enum node_frequency freq = NODE_FREQUENCY_NORMAL;
578 bool startup = false, exit = false;
582 struct cgraph_node *node = cgraph_get_node (decl);
586 freq = node->frequency;
587 startup = node->only_called_at_startup;
588 exit = node->only_called_at_exit;
592 freq = NODE_FREQUENCY_UNLIKELY_EXECUTED;
594 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
595 if (decl != NULL_TREE
596 && DECL_SECTION_NAME (decl) != NULL_TREE)
598 if (targetm.asm_out.function_section)
599 section = targetm.asm_out.function_section (decl, freq,
603 return get_named_section (decl, NULL, 0);
606 return targetm.asm_out.select_section
607 (decl, freq == NODE_FREQUENCY_UNLIKELY_EXECUTED,
610 if (targetm.asm_out.function_section)
611 section = targetm.asm_out.function_section (decl, freq, startup, exit);
614 return hot_function_section (decl);
618 /* Return the section for function DECL.
620 If DECL is NULL_TREE, return the text section. We can be passed
621 NULL_TREE under some circumstances by dbxout.c at least. */
624 function_section (tree decl)
626 /* Handle cases where function splitting code decides
627 to put function entry point into unlikely executed section
628 despite the fact that the function itself is not cold
629 (i.e. it is called rarely but contains a hot loop that is
630 better to live in hot subsection for the code locality). */
631 return function_section_1 (decl,
632 first_function_block_is_cold);
635 /* Return the section for the current function, take IN_COLD_SECTION_P
639 current_function_section (void)
641 return function_section_1 (current_function_decl, in_cold_section_p);
644 /* Tell assembler to switch to unlikely-to-be-executed text section. */
647 unlikely_text_section (void)
649 return function_section_1 (current_function_decl, true);
652 /* When called within a function context, return true if the function
653 has been assigned a cold text section and if SECT is that section.
654 When called outside a function context, return true if SECT is the
655 default cold section. */
658 unlikely_text_section_p (section *sect)
660 return sect == function_section_1 (current_function_decl, true);
663 /* Return the read-only data section associated with function DECL. */
666 default_function_rodata_section (tree decl)
668 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
670 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
672 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
678 dot = strchr (name + 1, '.');
681 len = strlen (dot) + 8;
682 rname = (char *) alloca (len);
684 strcpy (rname, ".rodata");
686 return get_section (rname, SECTION_LINKONCE, decl);
688 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
689 else if (DECL_ONE_ONLY (decl)
690 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
692 size_t len = strlen (name) + 1;
693 char *rname = (char *) alloca (len);
695 memcpy (rname, name, len);
697 return get_section (rname, SECTION_LINKONCE, decl);
699 /* For .text.foo we want to use .rodata.foo. */
700 else if (flag_function_sections && flag_data_sections
701 && strncmp (name, ".text.", 6) == 0)
703 size_t len = strlen (name) + 1;
704 char *rname = (char *) alloca (len + 2);
706 memcpy (rname, ".rodata", 7);
707 memcpy (rname + 7, name + 5, len - 5);
708 return get_section (rname, 0, decl);
712 return readonly_data_section;
715 /* Return the read-only data section associated with function DECL
716 for targets where that section should be always the single
717 readonly data section. */
720 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
722 return readonly_data_section;
725 /* Return the section to use for string merging. */
728 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
729 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
730 unsigned int flags ATTRIBUTE_UNUSED)
734 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
735 && TREE_CODE (decl) == STRING_CST
736 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
738 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
739 && TREE_STRING_LENGTH (decl) >= len)
741 enum machine_mode mode;
742 unsigned int modesize;
746 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
747 char *name = (char *) alloca (strlen (prefix) + 30);
749 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
750 modesize = GET_MODE_BITSIZE (mode);
751 if (modesize >= 8 && modesize <= 256
752 && (modesize & (modesize - 1)) == 0)
754 if (align < modesize)
757 str = TREE_STRING_POINTER (decl);
758 unit = GET_MODE_SIZE (mode);
760 /* Check for embedded NUL characters. */
761 for (i = 0; i < len; i += unit)
763 for (j = 0; j < unit; j++)
764 if (str[i + j] != '\0')
771 sprintf (name, "%s.str%d.%d", prefix,
772 modesize / 8, (int) (align / 8));
773 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
774 return get_section (name, flags, NULL);
779 return readonly_data_section;
782 /* Return the section to use for constant merging. */
785 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
786 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
787 unsigned int flags ATTRIBUTE_UNUSED)
789 unsigned int modesize = GET_MODE_BITSIZE (mode);
791 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
797 && (align & (align - 1)) == 0)
799 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
800 char *name = (char *) alloca (strlen (prefix) + 30);
802 sprintf (name, "%s.cst%d", prefix, (int) (align / 8));
803 flags |= (align / 8) | SECTION_MERGE;
804 return get_section (name, flags, NULL);
806 return readonly_data_section;
809 /* Given NAME, a putative register name, discard any customary prefixes. */
812 strip_reg_name (const char *name)
814 #ifdef REGISTER_PREFIX
815 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
816 name += strlen (REGISTER_PREFIX);
818 if (name[0] == '%' || name[0] == '#')
823 /* The user has asked for a DECL to have a particular name. Set (or
824 change) it in such a way that we don't prefix an underscore to
827 set_user_assembler_name (tree decl, const char *name)
829 char *starred = (char *) alloca (strlen (name) + 2);
831 strcpy (starred + 1, name);
832 change_decl_assembler_name (decl, get_identifier (starred));
833 SET_DECL_RTL (decl, NULL_RTX);
836 /* Decode an `asm' spec for a declaration as a register name.
837 Return the register number, or -1 if nothing specified,
838 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
839 or -3 if ASMSPEC is `cc' and is not recognized,
840 or -4 if ASMSPEC is `memory' and is not recognized.
841 Accept an exact spelling or a decimal number.
842 Prefixes such as % are optional. */
845 decode_reg_name_and_count (const char *asmspec, int *pnregs)
847 /* Presume just one register is clobbered. */
854 /* Get rid of confusing prefixes. */
855 asmspec = strip_reg_name (asmspec);
857 /* Allow a decimal number as a "register name". */
858 for (i = strlen (asmspec) - 1; i >= 0; i--)
859 if (! ISDIGIT (asmspec[i]))
861 if (asmspec[0] != 0 && i < 0)
864 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
870 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
872 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
875 #ifdef OVERLAPPING_REGISTER_NAMES
879 const char *const name;
882 } table[] = OVERLAPPING_REGISTER_NAMES;
884 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
886 && ! strcmp (asmspec, table[i].name))
888 *pnregs = table[i].nregs;
889 return table[i].number;
892 #endif /* OVERLAPPING_REGISTER_NAMES */
894 #ifdef ADDITIONAL_REGISTER_NAMES
896 static const struct { const char *const name; const int number; } table[]
897 = ADDITIONAL_REGISTER_NAMES;
899 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
901 && ! strcmp (asmspec, table[i].name))
902 return table[i].number;
904 #endif /* ADDITIONAL_REGISTER_NAMES */
906 if (!strcmp (asmspec, "memory"))
909 if (!strcmp (asmspec, "cc"))
919 decode_reg_name (const char *name)
922 return decode_reg_name_and_count (name, &count);
926 /* Return true if DECL's initializer is suitable for a BSS section. */
929 bss_initializer_p (const_tree decl)
931 return (DECL_INITIAL (decl) == NULL
932 || DECL_INITIAL (decl) == error_mark_node
933 || (flag_zero_initialized_in_bss
934 /* Leave constant zeroes in .rodata so they
936 && !TREE_READONLY (decl)
937 && initializer_zerop (DECL_INITIAL (decl))));
940 /* Compute the alignment of variable specified by DECL.
941 DONT_OUTPUT_DATA is from assemble_variable. */
944 align_variable (tree decl, bool dont_output_data)
946 unsigned int align = DECL_ALIGN (decl);
948 /* In the case for initialing an array whose length isn't specified,
949 where we have not yet been able to do the layout,
950 figure out the proper alignment now. */
951 if (dont_output_data && DECL_SIZE (decl) == 0
952 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
953 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
955 /* Some object file formats have a maximum alignment which they support.
956 In particular, a.out format supports a maximum alignment of 4. */
957 if (align > MAX_OFILE_ALIGNMENT)
959 warning (0, "alignment of %q+D is greater than maximum object "
960 "file alignment. Using %d", decl,
961 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
962 align = MAX_OFILE_ALIGNMENT;
965 /* On some machines, it is good to increase alignment sometimes. */
966 if (! DECL_USER_ALIGN (decl))
968 #ifdef DATA_ALIGNMENT
969 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
970 /* Don't increase alignment too much for TLS variables - TLS space
972 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
975 #ifdef CONSTANT_ALIGNMENT
976 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
978 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
980 /* Don't increase alignment too much for TLS variables - TLS space
982 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
988 /* Reset the alignment in case we have made it tighter, so we can benefit
989 from it in get_pointer_alignment. */
990 DECL_ALIGN (decl) = align;
993 /* Return the section into which the given VAR_DECL or CONST_DECL
994 should be placed. PREFER_NOSWITCH_P is true if a noswitch
995 section should be used wherever possible. */
998 get_variable_section (tree decl, bool prefer_noswitch_p)
1000 addr_space_t as = ADDR_SPACE_GENERIC;
1003 if (TREE_TYPE (decl) != error_mark_node)
1004 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1006 if (DECL_COMMON (decl))
1008 /* If the decl has been given an explicit section name, or it resides
1009 in a non-generic address space, then it isn't common, and shouldn't
1010 be handled as such. */
1011 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1012 && ADDR_SPACE_GENERIC_P (as));
1013 if (DECL_THREAD_LOCAL_P (decl))
1014 return tls_comm_section;
1015 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1016 return comm_section;
1019 if (DECL_INITIAL (decl) == error_mark_node)
1020 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1021 else if (DECL_INITIAL (decl))
1022 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1026 resolve_unique_section (decl, reloc, flag_data_sections);
1027 if (IN_NAMED_SECTION (decl))
1028 return get_named_section (decl, NULL, reloc);
1030 if (ADDR_SPACE_GENERIC_P (as)
1031 && !DECL_THREAD_LOCAL_P (decl)
1032 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1033 && bss_initializer_p (decl))
1035 if (!TREE_PUBLIC (decl))
1036 return lcomm_section;
1037 if (bss_noswitch_section)
1038 return bss_noswitch_section;
1041 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1044 /* Return the block into which object_block DECL should be placed. */
1046 static struct object_block *
1047 get_block_for_decl (tree decl)
1051 if (TREE_CODE (decl) == VAR_DECL)
1053 /* The object must be defined in this translation unit. */
1054 if (DECL_EXTERNAL (decl))
1057 /* There's no point using object blocks for something that is
1058 isolated by definition. */
1059 if (DECL_ONE_ONLY (decl))
1063 /* We can only calculate block offsets if the decl has a known
1065 if (DECL_SIZE_UNIT (decl) == NULL)
1067 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1070 /* Find out which section should contain DECL. We cannot put it into
1071 an object block if it requires a standalone definition. */
1072 if (TREE_CODE (decl) == VAR_DECL)
1073 align_variable (decl, 0);
1074 sect = get_variable_section (decl, true);
1075 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1078 return get_block_for_section (sect);
1081 /* Make sure block symbol SYMBOL is in block BLOCK. */
1084 change_symbol_block (rtx symbol, struct object_block *block)
1086 if (block != SYMBOL_REF_BLOCK (symbol))
1088 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1089 SYMBOL_REF_BLOCK (symbol) = block;
1093 /* Return true if it is possible to put DECL in an object_block. */
1096 use_blocks_for_decl_p (tree decl)
1098 /* Only data DECLs can be placed into object blocks. */
1099 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1102 /* Detect decls created by dw2_force_const_mem. Such decls are
1103 special because DECL_INITIAL doesn't specify the decl's true value.
1104 dw2_output_indirect_constants will instead call assemble_variable
1105 with dont_output_data set to 1 and then print the contents itself. */
1106 if (DECL_INITIAL (decl) == decl)
1109 /* If this decl is an alias, then we don't want to emit a
1111 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1117 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1118 have static storage duration. In other words, it should not be an
1119 automatic variable, including PARM_DECLs.
1121 There is, however, one exception: this function handles variables
1122 explicitly placed in a particular register by the user.
1124 This is never called for PARM_DECL nodes. */
1127 make_decl_rtl (tree decl)
1129 const char *name = 0;
1133 /* Check that we are not being given an automatic variable. */
1134 gcc_assert (TREE_CODE (decl) != PARM_DECL
1135 && TREE_CODE (decl) != RESULT_DECL);
1137 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1138 gcc_assert (TREE_CODE (decl) != VAR_DECL
1139 || TREE_STATIC (decl)
1140 || TREE_PUBLIC (decl)
1141 || DECL_EXTERNAL (decl)
1142 || DECL_REGISTER (decl));
1144 /* And that we were not given a type or a label. */
1145 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1146 && TREE_CODE (decl) != LABEL_DECL);
1148 /* For a duplicate declaration, we can be called twice on the
1149 same DECL node. Don't discard the RTL already made. */
1150 if (DECL_RTL_SET_P (decl))
1152 /* If the old RTL had the wrong mode, fix the mode. */
1153 x = DECL_RTL (decl);
1154 if (GET_MODE (x) != DECL_MODE (decl))
1155 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1157 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1160 /* ??? Another way to do this would be to maintain a hashed
1161 table of such critters. Instead of adding stuff to a DECL
1162 to give certain attributes to it, we could use an external
1163 hash map from DECL to set of attributes. */
1165 /* Let the target reassign the RTL if it wants.
1166 This is necessary, for example, when one machine specific
1167 decl attribute overrides another. */
1168 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1170 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1171 on the new decl information. */
1173 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1174 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1175 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1177 /* Make this function static known to the mudflap runtime. */
1178 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1179 mudflap_enqueue_decl (decl);
1184 /* If this variable belongs to the global constant pool, retrieve the
1185 pre-computed RTL or recompute it in LTO mode. */
1186 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1188 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1192 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1194 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1195 && DECL_REGISTER (decl))
1197 error ("register name not specified for %q+D", decl);
1199 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1201 const char *asmspec = name+1;
1202 enum machine_mode mode = DECL_MODE (decl);
1203 reg_number = decode_reg_name (asmspec);
1204 /* First detect errors in declaring global registers. */
1205 if (reg_number == -1)
1206 error ("register name not specified for %q+D", decl);
1207 else if (reg_number < 0)
1208 error ("invalid register name for %q+D", decl);
1209 else if (mode == BLKmode)
1210 error ("data type of %q+D isn%'t suitable for a register",
1212 else if (!in_hard_reg_set_p (accessible_reg_set, mode, reg_number))
1213 error ("the register specified for %q+D cannot be accessed"
1214 " by the current target", decl);
1215 else if (!in_hard_reg_set_p (operand_reg_set, mode, reg_number))
1216 error ("the register specified for %q+D is not general enough"
1217 " to be used as a register variable", decl);
1218 else if (!HARD_REGNO_MODE_OK (reg_number, mode))
1219 error ("register specified for %q+D isn%'t suitable for data type",
1221 /* Now handle properly declared static register variables. */
1226 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1228 DECL_INITIAL (decl) = 0;
1229 error ("global register variable has initial value");
1231 if (TREE_THIS_VOLATILE (decl))
1232 warning (OPT_Wvolatile_register_var,
1233 "optimization may eliminate reads and/or "
1234 "writes to register variables");
1236 /* If the user specified one of the eliminables registers here,
1237 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1238 confused with that register and be eliminated. This usage is
1239 somewhat suspect... */
1241 SET_DECL_RTL (decl, gen_rtx_raw_REG (mode, reg_number));
1242 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1243 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1245 if (TREE_STATIC (decl))
1247 /* Make this register global, so not usable for anything
1249 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1250 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1251 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1253 nregs = hard_regno_nregs[reg_number][mode];
1255 globalize_reg (decl, reg_number + --nregs);
1258 /* As a register variable, it has no section. */
1262 /* Now handle ordinary static variables and functions (in memory).
1263 Also handle vars declared register invalidly. */
1264 else if (name[0] == '*')
1266 #ifdef REGISTER_PREFIX
1267 if (strlen (REGISTER_PREFIX) != 0)
1269 reg_number = decode_reg_name (name);
1270 if (reg_number >= 0 || reg_number == -3)
1271 error ("register name given for non-register variable %q+D", decl);
1276 /* Specifying a section attribute on a variable forces it into a
1277 non-.bss section, and thus it cannot be common. */
1278 /* FIXME: In general this code should not be necessary because
1279 visibility pass is doing the same work. But notice_global_symbol
1280 is called early and it needs to make DECL_RTL to get the name.
1281 we take care of recomputing the DECL_RTL after visibility is changed. */
1282 if (TREE_CODE (decl) == VAR_DECL
1283 && DECL_SECTION_NAME (decl) != NULL_TREE
1284 && DECL_INITIAL (decl) == NULL_TREE
1285 && DECL_COMMON (decl))
1286 DECL_COMMON (decl) = 0;
1288 /* Variables can't be both common and weak. */
1289 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1290 DECL_COMMON (decl) = 0;
1292 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1293 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1296 enum machine_mode address_mode = Pmode;
1297 if (TREE_TYPE (decl) != error_mark_node)
1299 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1300 address_mode = targetm.addr_space.address_mode (as);
1302 x = gen_rtx_SYMBOL_REF (address_mode, name);
1304 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1305 SET_SYMBOL_REF_DECL (x, decl);
1307 x = gen_rtx_MEM (DECL_MODE (decl), x);
1308 if (TREE_CODE (decl) != FUNCTION_DECL)
1309 set_mem_attributes (x, decl, 1);
1310 SET_DECL_RTL (decl, x);
1312 /* Optionally set flags or add text to the name to record information
1313 such as that it is a function name.
1314 If the name is changed, the macro ASM_OUTPUT_LABELREF
1315 will have to know how to strip this information. */
1316 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1318 /* Make this function static known to the mudflap runtime. */
1319 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1320 mudflap_enqueue_decl (decl);
1323 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1324 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1328 make_decl_rtl_for_debug (tree decl)
1330 unsigned int save_aliasing_flag, save_mudflap_flag;
1333 if (DECL_RTL_SET_P (decl))
1334 return DECL_RTL (decl);
1336 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1337 call new_alias_set. If running with -fcompare-debug, sometimes
1338 we do not want to create alias sets that will throw the alias
1339 numbers off in the comparison dumps. So... clearing
1340 flag_strict_aliasing will keep new_alias_set() from creating a
1341 new set. It is undesirable to register decl with mudflap
1342 in this case as well. */
1343 save_aliasing_flag = flag_strict_aliasing;
1344 flag_strict_aliasing = 0;
1345 save_mudflap_flag = flag_mudflap;
1348 rtl = DECL_RTL (decl);
1349 /* Reset DECL_RTL back, as various parts of the compiler expects
1350 DECL_RTL set meaning it is actually going to be output. */
1351 SET_DECL_RTL (decl, NULL);
1353 flag_strict_aliasing = save_aliasing_flag;
1354 flag_mudflap = save_mudflap_flag;
1359 /* Output a string of literal assembler code
1360 for an `asm' keyword used between functions. */
1363 assemble_asm (tree string)
1367 if (TREE_CODE (string) == ADDR_EXPR)
1368 string = TREE_OPERAND (string, 0);
1370 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1373 /* Record an element in the table of global destructors. SYMBOL is
1374 a SYMBOL_REF of the function to be called; PRIORITY is a number
1375 between 0 and MAX_INIT_PRIORITY. */
1378 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1379 int priority ATTRIBUTE_UNUSED)
1381 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1382 /* Tell GNU LD that this is part of the static destructor set.
1383 This will work for any system that uses stabs, most usefully
1385 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1386 dbxout_stab_value_label (XSTR (symbol, 0));
1388 sorry ("global destructors not supported on this target");
1392 /* Write the address of the entity given by SYMBOL to SEC. */
1394 assemble_addr_to_section (rtx symbol, section *sec)
1396 switch_to_section (sec);
1397 assemble_align (POINTER_SIZE);
1398 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1401 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1402 not) section for PRIORITY. */
1404 get_cdtor_priority_section (int priority, bool constructor_p)
1408 /* ??? This only works reliably with the GNU linker. */
1409 sprintf (buf, "%s.%.5u",
1410 constructor_p ? ".ctors" : ".dtors",
1411 /* Invert the numbering so the linker puts us in the proper
1412 order; constructors are run from right to left, and the
1413 linker sorts in increasing order. */
1414 MAX_INIT_PRIORITY - priority);
1415 return get_section (buf, SECTION_WRITE, NULL);
1419 default_named_section_asm_out_destructor (rtx symbol, int priority)
1423 if (priority != DEFAULT_INIT_PRIORITY)
1424 sec = get_cdtor_priority_section (priority,
1425 /*constructor_p=*/false);
1427 sec = get_section (".dtors", SECTION_WRITE, NULL);
1429 assemble_addr_to_section (symbol, sec);
1432 #ifdef DTORS_SECTION_ASM_OP
1434 default_dtor_section_asm_out_destructor (rtx symbol,
1435 int priority ATTRIBUTE_UNUSED)
1437 assemble_addr_to_section (symbol, dtors_section);
1441 /* Likewise for global constructors. */
1444 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1445 int priority ATTRIBUTE_UNUSED)
1447 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1448 /* Tell GNU LD that this is part of the static destructor set.
1449 This will work for any system that uses stabs, most usefully
1451 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1452 dbxout_stab_value_label (XSTR (symbol, 0));
1454 sorry ("global constructors not supported on this target");
1459 default_named_section_asm_out_constructor (rtx symbol, int priority)
1463 if (priority != DEFAULT_INIT_PRIORITY)
1464 sec = get_cdtor_priority_section (priority,
1465 /*constructor_p=*/true);
1467 sec = get_section (".ctors", SECTION_WRITE, NULL);
1469 assemble_addr_to_section (symbol, sec);
1472 #ifdef CTORS_SECTION_ASM_OP
1474 default_ctor_section_asm_out_constructor (rtx symbol,
1475 int priority ATTRIBUTE_UNUSED)
1477 assemble_addr_to_section (symbol, ctors_section);
1481 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1482 a nonzero value if the constant pool should be output before the
1483 start of the function, or a zero value if the pool should output
1484 after the end of the function. The default is to put it before the
1487 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1488 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1491 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1492 to be output to assembler.
1493 Set first_global_object_name and weak_global_object_name as appropriate. */
1496 notice_global_symbol (tree decl)
1498 const char **type = &first_global_object_name;
1500 if (first_global_object_name
1501 || !TREE_PUBLIC (decl)
1502 || DECL_EXTERNAL (decl)
1503 || !DECL_NAME (decl)
1504 || (TREE_CODE (decl) != FUNCTION_DECL
1505 && (TREE_CODE (decl) != VAR_DECL
1506 || (DECL_COMMON (decl)
1507 && (DECL_INITIAL (decl) == 0
1508 || DECL_INITIAL (decl) == error_mark_node))))
1509 || !MEM_P (DECL_RTL (decl)))
1512 /* We win when global object is found, but it is useful to know about weak
1513 symbol as well so we can produce nicer unique names. */
1514 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1515 type = &weak_global_object_name;
1521 rtx decl_rtl = DECL_RTL (decl);
1523 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1524 name = ggc_strdup (p);
1530 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1531 current function goes into the cold section, so that targets can use
1532 current_function_section during RTL expansion. DECL describes the
1536 decide_function_section (tree decl)
1538 first_function_block_is_cold = false;
1540 if (flag_reorder_blocks_and_partition)
1541 /* We will decide in assemble_start_function. */
1544 if (DECL_SECTION_NAME (decl))
1546 struct cgraph_node *node = cgraph_get_node (current_function_decl);
1547 /* Calls to function_section rely on first_function_block_is_cold
1549 first_function_block_is_cold = (node
1551 == NODE_FREQUENCY_UNLIKELY_EXECUTED);
1554 in_cold_section_p = first_function_block_is_cold;
1557 /* Output assembler code for the constant pool of a function and associated
1558 with defining the name of the function. DECL describes the function.
1559 NAME is the function's name. For the constant pool, we use the current
1560 constant pool data. */
1563 assemble_start_function (tree decl, const char *fnname)
1566 char tmp_label[100];
1567 bool hot_label_written = false;
1569 if (flag_reorder_blocks_and_partition)
1571 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1572 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1573 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1574 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1575 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1576 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1577 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1578 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1583 crtl->subsections.hot_section_label = NULL;
1584 crtl->subsections.cold_section_label = NULL;
1585 crtl->subsections.hot_section_end_label = NULL;
1586 crtl->subsections.cold_section_end_label = NULL;
1589 /* The following code does not need preprocessing in the assembler. */
1593 if (CONSTANT_POOL_BEFORE_FUNCTION)
1594 output_constant_pool (fnname, decl);
1596 /* Make sure the not and cold text (code) sections are properly
1597 aligned. This is necessary here in the case where the function
1598 has both hot and cold sections, because we don't want to re-set
1599 the alignment when the section switch happens mid-function. */
1601 if (flag_reorder_blocks_and_partition)
1603 first_function_block_is_cold = false;
1605 switch_to_section (unlikely_text_section ());
1606 assemble_align (DECL_ALIGN (decl));
1607 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1609 /* When the function starts with a cold section, we need to explicitly
1610 align the hot section and write out the hot section label.
1611 But if the current function is a thunk, we do not have a CFG. */
1613 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1615 switch_to_section (text_section);
1616 assemble_align (DECL_ALIGN (decl));
1617 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1618 hot_label_written = true;
1619 first_function_block_is_cold = true;
1621 in_cold_section_p = first_function_block_is_cold;
1625 /* Switch to the correct text section for the start of the function. */
1627 switch_to_section (function_section (decl));
1628 if (flag_reorder_blocks_and_partition
1629 && !hot_label_written)
1630 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1632 /* Tell assembler to move to target machine's alignment for functions. */
1633 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1636 ASM_OUTPUT_ALIGN (asm_out_file, align);
1639 /* Handle a user-specified function alignment.
1640 Note that we still need to align to DECL_ALIGN, as above,
1641 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1642 if (! DECL_USER_ALIGN (decl)
1643 && align_functions_log > align
1644 && optimize_function_for_speed_p (cfun))
1646 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1647 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1648 align_functions_log, align_functions - 1);
1650 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1654 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1655 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1658 if (!DECL_IGNORED_P (decl))
1659 (*debug_hooks->begin_function) (decl);
1661 /* Make function name accessible from other files, if appropriate. */
1663 if (TREE_PUBLIC (decl))
1665 notice_global_symbol (decl);
1667 globalize_decl (decl);
1669 maybe_assemble_visibility (decl);
1672 if (DECL_PRESERVE_P (decl))
1673 targetm.asm_out.mark_decl_preserved (fnname);
1675 /* Do any machine/system dependent processing of the function name. */
1676 #ifdef ASM_DECLARE_FUNCTION_NAME
1677 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1679 /* Standard thing is just output label for the function. */
1680 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
1681 #endif /* ASM_DECLARE_FUNCTION_NAME */
1683 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))
1684 saw_no_split_stack = true;
1687 /* Output assembler code associated with defining the size of the
1688 function. DECL describes the function. NAME is the function's name. */
1691 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1693 #ifdef ASM_DECLARE_FUNCTION_SIZE
1694 /* We could have switched section in the middle of the function. */
1695 if (flag_reorder_blocks_and_partition)
1696 switch_to_section (function_section (decl));
1697 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1699 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1701 output_constant_pool (fnname, decl);
1702 switch_to_section (function_section (decl)); /* need to switch back */
1704 /* Output labels for end of hot/cold text sections (to be used by
1706 if (flag_reorder_blocks_and_partition)
1708 section *save_text_section;
1710 save_text_section = in_section;
1711 switch_to_section (unlikely_text_section ());
1712 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1713 if (first_function_block_is_cold)
1714 switch_to_section (text_section);
1716 switch_to_section (function_section (decl));
1717 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1718 switch_to_section (save_text_section);
1722 /* Assemble code to leave SIZE bytes of zeros. */
1725 assemble_zeros (unsigned HOST_WIDE_INT size)
1727 /* Do no output if -fsyntax-only. */
1728 if (flag_syntax_only)
1731 #ifdef ASM_NO_SKIP_IN_TEXT
1732 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1733 so we must output 0s explicitly in the text section. */
1734 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1736 unsigned HOST_WIDE_INT i;
1737 for (i = 0; i < size; i++)
1738 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1743 ASM_OUTPUT_SKIP (asm_out_file, size);
1746 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1749 assemble_align (int align)
1751 if (align > BITS_PER_UNIT)
1753 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1757 /* Assemble a string constant with the specified C string as contents. */
1760 assemble_string (const char *p, int size)
1765 /* If the string is very long, split it up. */
1769 int thissize = size - pos;
1770 if (thissize > maximum)
1773 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1781 /* A noswitch_section_callback for lcomm_section. */
1784 emit_local (tree decl ATTRIBUTE_UNUSED,
1785 const char *name ATTRIBUTE_UNUSED,
1786 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1787 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1789 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1790 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1791 size, DECL_ALIGN (decl));
1793 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1794 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1797 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1802 /* A noswitch_section_callback for bss_noswitch_section. */
1804 #if defined ASM_OUTPUT_ALIGNED_BSS
1806 emit_bss (tree decl ATTRIBUTE_UNUSED,
1807 const char *name ATTRIBUTE_UNUSED,
1808 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1809 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1811 #if defined ASM_OUTPUT_ALIGNED_BSS
1812 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1818 /* A noswitch_section_callback for comm_section. */
1821 emit_common (tree decl ATTRIBUTE_UNUSED,
1822 const char *name ATTRIBUTE_UNUSED,
1823 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1824 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1826 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1827 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1828 size, DECL_ALIGN (decl));
1830 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1831 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1834 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1839 /* A noswitch_section_callback for tls_comm_section. */
1842 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1843 const char *name ATTRIBUTE_UNUSED,
1844 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1845 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1847 #ifdef ASM_OUTPUT_TLS_COMMON
1848 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1851 sorry ("thread-local COMMON data not implemented");
1856 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1857 NAME is the name of DECL's SYMBOL_REF. */
1860 assemble_noswitch_variable (tree decl, const char *name, section *sect)
1862 unsigned HOST_WIDE_INT size, rounded;
1864 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1867 /* Don't allocate zero bytes of common,
1868 since that means "undefined external" in the linker. */
1872 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1873 so that each uninitialized object starts on such a boundary. */
1874 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1875 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1876 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1878 if (!sect->noswitch.callback (decl, name, size, rounded)
1879 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1880 warning (0, "requested alignment for %q+D is greater than "
1881 "implemented alignment of %wu", decl, rounded);
1884 /* A subroutine of assemble_variable. Output the label and contents of
1885 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1886 is as for assemble_variable. */
1889 assemble_variable_contents (tree decl, const char *name,
1890 bool dont_output_data)
1892 /* Do any machine/system dependent processing of the object. */
1893 #ifdef ASM_DECLARE_OBJECT_NAME
1894 last_assemble_variable_decl = decl;
1895 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1897 /* Standard thing is just output label for the object. */
1898 ASM_OUTPUT_LABEL (asm_out_file, name);
1899 #endif /* ASM_DECLARE_OBJECT_NAME */
1901 if (!dont_output_data)
1903 if (DECL_INITIAL (decl)
1904 && DECL_INITIAL (decl) != error_mark_node
1905 && !initializer_zerop (DECL_INITIAL (decl)))
1906 /* Output the actual data. */
1907 output_constant (DECL_INITIAL (decl),
1908 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1911 /* Leave space for it. */
1912 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1916 /* Assemble everything that is needed for a variable or function declaration.
1917 Not used for automatic variables, and not used for function definitions.
1918 Should not be called for variables of incomplete structure type.
1920 TOP_LEVEL is nonzero if this variable has file scope.
1921 AT_END is nonzero if this is the special handling, at end of compilation,
1922 to define things that have had only tentative definitions.
1923 DONT_OUTPUT_DATA if nonzero means don't actually output the
1924 initial value (that will be done by the caller). */
1927 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1928 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1931 rtx decl_rtl, symbol;
1934 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1935 gcc_assert (TREE_CODE (decl) == VAR_DECL);
1937 /* Emulated TLS had better not get this far. */
1938 gcc_checking_assert (targetm.have_tls || !DECL_THREAD_LOCAL_P (decl));
1940 last_assemble_variable_decl = 0;
1942 /* Normally no need to say anything here for external references,
1943 since assemble_external is called by the language-specific code
1944 when a declaration is first seen. */
1946 if (DECL_EXTERNAL (decl))
1949 /* Do nothing for global register variables. */
1950 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1952 TREE_ASM_WRITTEN (decl) = 1;
1956 /* If type was incomplete when the variable was declared,
1957 see if it is complete now. */
1959 if (DECL_SIZE (decl) == 0)
1960 layout_decl (decl, 0);
1962 /* Still incomplete => don't allocate it; treat the tentative defn
1963 (which is what it must have been) as an `extern' reference. */
1965 if (!dont_output_data && DECL_SIZE (decl) == 0)
1967 error ("storage size of %q+D isn%'t known", decl);
1968 TREE_ASM_WRITTEN (decl) = 1;
1972 /* The first declaration of a variable that comes through this function
1973 decides whether it is global (in C, has external linkage)
1974 or local (in C, has internal linkage). So do nothing more
1975 if this function has already run. */
1977 if (TREE_ASM_WRITTEN (decl))
1980 /* Make sure targetm.encode_section_info is invoked before we set
1982 decl_rtl = DECL_RTL (decl);
1984 TREE_ASM_WRITTEN (decl) = 1;
1986 /* Do no output if -fsyntax-only. */
1987 if (flag_syntax_only)
1990 if (! dont_output_data
1991 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1993 error ("size of variable %q+D is too large", decl);
1997 gcc_assert (MEM_P (decl_rtl));
1998 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
1999 symbol = XEXP (decl_rtl, 0);
2001 /* If this symbol belongs to the tree constant pool, output the constant
2002 if it hasn't already been written. */
2003 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2005 tree decl = SYMBOL_REF_DECL (symbol);
2006 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2007 output_constant_def_contents (symbol);
2013 name = XSTR (symbol, 0);
2014 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2015 notice_global_symbol (decl);
2017 /* Compute the alignment of this data. */
2019 align_variable (decl, dont_output_data);
2020 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2022 if (TREE_PUBLIC (decl))
2023 maybe_assemble_visibility (decl);
2025 if (DECL_PRESERVE_P (decl))
2026 targetm.asm_out.mark_decl_preserved (name);
2028 /* First make the assembler name(s) global if appropriate. */
2029 sect = get_variable_section (decl, false);
2030 if (TREE_PUBLIC (decl)
2031 && (sect->common.flags & SECTION_COMMON) == 0)
2032 globalize_decl (decl);
2034 /* Output any data that we will need to use the address of. */
2035 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2036 output_addressed_constants (DECL_INITIAL (decl));
2038 /* dbxout.c needs to know this. */
2039 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2040 DECL_IN_TEXT_SECTION (decl) = 1;
2042 /* If the decl is part of an object_block, make sure that the decl
2043 has been positioned within its block, but do not write out its
2044 definition yet. output_object_blocks will do that later. */
2045 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2047 gcc_assert (!dont_output_data);
2048 place_block_symbol (symbol);
2050 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2051 assemble_noswitch_variable (decl, name, sect);
2054 switch_to_section (sect);
2055 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2056 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2057 assemble_variable_contents (decl, name, dont_output_data);
2061 /* Return 1 if type TYPE contains any pointers. */
2064 contains_pointers_p (tree type)
2066 switch (TREE_CODE (type))
2069 case REFERENCE_TYPE:
2070 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2071 so I'll play safe and return 1. */
2077 case QUAL_UNION_TYPE:
2080 /* For a type that has fields, see if the fields have pointers. */
2081 for (fields = TYPE_FIELDS (type); fields; fields = DECL_CHAIN (fields))
2082 if (TREE_CODE (fields) == FIELD_DECL
2083 && contains_pointers_p (TREE_TYPE (fields)))
2089 /* An array type contains pointers if its element type does. */
2090 return contains_pointers_p (TREE_TYPE (type));
2097 /* We delay assemble_external processing until
2098 the compilation unit is finalized. This is the best we can do for
2099 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2100 it all the way to final. See PR 17982 for further discussion. */
2101 static GTY(()) tree pending_assemble_externals;
2103 /* FIXME: Trunk is at GCC 4.8 now and the above problem still hasn't been
2104 addressed properly. This caused PR 52640 due to O(external_decls**2)
2105 lookups in the pending_assemble_externals TREE_LIST in assemble_external.
2106 Paper over with this pointer set, which we use to see if we have already
2107 added a decl to pending_assemble_externals without first traversing
2108 the entire pending_assemble_externals list. See assemble_external(). */
2109 static struct pointer_set_t *pending_assemble_externals_set;
2111 #ifdef ASM_OUTPUT_EXTERNAL
2112 /* True if DECL is a function decl for which no out-of-line copy exists.
2113 It is assumed that DECL's assembler name has been set. */
2116 incorporeal_function_p (tree decl)
2118 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2122 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2123 && (DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA
2124 || DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA_WITH_ALIGN))
2127 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2128 /* Atomic or sync builtins which have survived this far will be
2129 resolved externally and therefore are not incorporeal. */
2130 if (strncmp (name, "__builtin_", 10) == 0)
2136 /* Actually do the tests to determine if this is necessary, and invoke
2137 ASM_OUTPUT_EXTERNAL. */
2139 assemble_external_real (tree decl)
2141 rtx rtl = DECL_RTL (decl);
2143 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2144 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2145 && !incorporeal_function_p (decl))
2147 /* Some systems do require some output. */
2148 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2149 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2155 process_pending_assemble_externals (void)
2157 #ifdef ASM_OUTPUT_EXTERNAL
2159 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2160 assemble_external_real (TREE_VALUE (list));
2162 pending_assemble_externals = 0;
2163 pointer_set_destroy (pending_assemble_externals_set);
2167 /* This TREE_LIST contains any weak symbol declarations waiting
2169 static GTY(()) tree weak_decls;
2171 /* Output something to declare an external symbol to the assembler,
2172 and qualifiers such as weakness. (Most assemblers don't need
2173 extern declaration, so we normally output nothing.) Do nothing if
2174 DECL is not external. */
2177 assemble_external (tree decl ATTRIBUTE_UNUSED)
2179 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2180 main body of this code is only rarely exercised. To provide some
2181 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2182 open. If it's not, we should not be calling this function. */
2183 gcc_assert (asm_out_file);
2185 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2188 /* We want to output annotation for weak and external symbols at
2189 very last to check if they are references or not. */
2191 if (TARGET_SUPPORTS_WEAK
2193 /* TREE_STATIC is a weird and abused creature which is not
2194 generally the right test for whether an entity has been
2195 locally emitted, inlined or otherwise not-really-extern, but
2196 for declarations that can be weak, it happens to be
2198 && !TREE_STATIC (decl)
2199 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2200 && value_member (decl, weak_decls) == NULL_TREE)
2201 weak_decls = tree_cons (NULL, decl, weak_decls);
2203 #ifdef ASM_OUTPUT_EXTERNAL
2204 if (! pointer_set_insert (pending_assemble_externals_set, decl))
2205 pending_assemble_externals = tree_cons (NULL, decl,
2206 pending_assemble_externals);
2210 /* Similar, for calling a library function FUN. */
2213 assemble_external_libcall (rtx fun)
2215 /* Declare library function name external when first used, if nec. */
2216 if (! SYMBOL_REF_USED (fun))
2218 SYMBOL_REF_USED (fun) = 1;
2219 targetm.asm_out.external_libcall (fun);
2223 /* Assemble a label named NAME. */
2226 assemble_label (FILE *file, const char *name)
2228 ASM_OUTPUT_LABEL (file, name);
2231 /* Set the symbol_referenced flag for ID. */
2233 mark_referenced (tree id)
2235 TREE_SYMBOL_REFERENCED (id) = 1;
2238 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2240 mark_decl_referenced (tree decl)
2242 if (TREE_CODE (decl) == FUNCTION_DECL)
2244 /* Extern inline functions don't become needed when referenced.
2245 If we know a method will be emitted in other TU and no new
2246 functions can be marked reachable, just use the external
2248 struct cgraph_node *node = cgraph_get_create_node (decl);
2249 if (!DECL_EXTERNAL (decl)
2250 && !node->local.finalized)
2251 cgraph_mark_needed_node (node);
2253 else if (TREE_CODE (decl) == VAR_DECL)
2255 struct varpool_node *node = varpool_node (decl);
2256 varpool_mark_needed_node (node);
2257 /* C++ frontend use mark_decl_references to force COMDAT variables
2258 to be output that might appear dead otherwise. */
2259 node->force_output = true;
2261 /* else do nothing - we can get various sorts of CST nodes here,
2262 which do not need to be marked. */
2266 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2267 until we find an identifier that is not itself a transparent alias.
2268 Modify the alias passed to it by reference (and all aliases on the
2269 way to the ultimate target), such that they do not have to be
2270 followed again, and return the ultimate target of the alias
2274 ultimate_transparent_alias_target (tree *alias)
2276 tree target = *alias;
2278 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2280 gcc_assert (TREE_CHAIN (target));
2281 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2282 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2283 && ! TREE_CHAIN (target));
2290 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2291 starts with a *, the rest of NAME is output verbatim. Otherwise
2292 NAME is transformed in a target-specific way (usually by the
2293 addition of an underscore). */
2296 assemble_name_raw (FILE *file, const char *name)
2299 fputs (&name[1], file);
2301 ASM_OUTPUT_LABELREF (file, name);
2304 /* Like assemble_name_raw, but should be used when NAME might refer to
2305 an entity that is also represented as a tree (like a function or
2306 variable). If NAME does refer to such an entity, that entity will
2307 be marked as referenced. */
2310 assemble_name (FILE *file, const char *name)
2312 const char *real_name;
2315 real_name = targetm.strip_name_encoding (name);
2317 id = maybe_get_identifier (real_name);
2322 mark_referenced (id);
2323 ultimate_transparent_alias_target (&id);
2325 name = IDENTIFIER_POINTER (id);
2326 gcc_assert (! TREE_CHAIN (id));
2329 assemble_name_raw (file, name);
2332 /* Allocate SIZE bytes writable static space with a gensym name
2333 and return an RTX to refer to its address. */
2336 assemble_static_space (unsigned HOST_WIDE_INT size)
2339 const char *namestring;
2342 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2344 namestring = ggc_strdup (name);
2346 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2347 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2349 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2350 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2353 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2354 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2357 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2358 so that each uninitialized object starts on such a boundary. */
2359 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2360 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2361 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2362 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2363 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2364 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2371 /* Assemble the static constant template for function entry trampolines.
2372 This is done at most once per compilation.
2373 Returns an RTX for the address of the template. */
2375 static GTY(()) rtx initial_trampoline;
2378 assemble_trampoline_template (void)
2385 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2387 if (initial_trampoline)
2388 return initial_trampoline;
2390 /* By default, put trampoline templates in read-only data section. */
2392 #ifdef TRAMPOLINE_SECTION
2393 switch_to_section (TRAMPOLINE_SECTION);
2395 switch_to_section (readonly_data_section);
2398 /* Write the assembler code to define one. */
2399 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2401 ASM_OUTPUT_ALIGN (asm_out_file, align);
2403 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2404 targetm.asm_out.trampoline_template (asm_out_file);
2406 /* Record the rtl to refer to it. */
2407 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2408 name = ggc_strdup (label);
2409 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2410 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2412 initial_trampoline = gen_const_mem (BLKmode, symbol);
2413 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2414 set_mem_size (initial_trampoline, TRAMPOLINE_SIZE);
2416 return initial_trampoline;
2419 /* A and B are either alignments or offsets. Return the minimum alignment
2420 that may be assumed after adding the two together. */
2422 static inline unsigned
2423 min_align (unsigned int a, unsigned int b)
2425 return (a | b) & -(a | b);
2428 /* Return the assembler directive for creating a given kind of integer
2429 object. SIZE is the number of bytes in the object and ALIGNED_P
2430 indicates whether it is known to be aligned. Return NULL if the
2431 assembly dialect has no such directive.
2433 The returned string should be printed at the start of a new line and
2434 be followed immediately by the object's initial value. */
2437 integer_asm_op (int size, int aligned_p)
2439 struct asm_int_op *ops;
2442 ops = &targetm.asm_out.aligned_op;
2444 ops = &targetm.asm_out.unaligned_op;
2449 return targetm.asm_out.byte_op;
2463 /* Use directive OP to assemble an integer object X. Print OP at the
2464 start of the line, followed immediately by the value of X. */
2467 assemble_integer_with_op (const char *op, rtx x)
2469 fputs (op, asm_out_file);
2470 output_addr_const (asm_out_file, x);
2471 fputc ('\n', asm_out_file);
2474 /* The default implementation of the asm_out.integer target hook. */
2477 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2478 unsigned int size ATTRIBUTE_UNUSED,
2479 int aligned_p ATTRIBUTE_UNUSED)
2481 const char *op = integer_asm_op (size, aligned_p);
2482 /* Avoid GAS bugs for large values. Specifically negative values whose
2483 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2484 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2486 return op && (assemble_integer_with_op (op, x), true);
2489 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2490 the alignment of the integer in bits. Return 1 if we were able to output
2491 the constant, otherwise 0. We must be able to output the constant,
2492 if FORCE is nonzero. */
2495 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2499 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2501 /* See if the target hook can handle this kind of object. */
2502 if (targetm.asm_out.integer (x, size, aligned_p))
2505 /* If the object is a multi-byte one, try splitting it up. Split
2506 it into words it if is multi-word, otherwise split it into bytes. */
2509 enum machine_mode omode, imode;
2510 unsigned int subalign;
2511 unsigned int subsize, i;
2512 enum mode_class mclass;
2514 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2515 subalign = MIN (align, subsize * BITS_PER_UNIT);
2516 if (GET_CODE (x) == CONST_FIXED)
2517 mclass = GET_MODE_CLASS (GET_MODE (x));
2521 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2522 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2524 for (i = 0; i < size; i += subsize)
2526 rtx partial = simplify_subreg (omode, x, imode, i);
2527 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2533 /* If we've printed some of it, but not all of it, there's no going
2538 gcc_assert (!force);
2544 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2546 long data[4] = {0, 0, 0, 0};
2548 int bitsize, nelts, nunits, units_per;
2550 /* This is hairy. We have a quantity of known size. real_to_target
2551 will put it into an array of *host* longs, 32 bits per element
2552 (even if long is more than 32 bits). We need to determine the
2553 number of array elements that are occupied (nelts) and the number
2554 of *target* min-addressable units that will be occupied in the
2555 object file (nunits). We cannot assume that 32 divides the
2556 mode's bitsize (size * BITS_PER_UNIT) evenly.
2558 size * BITS_PER_UNIT is used here to make sure that padding bits
2559 (which might appear at either end of the value; real_to_target
2560 will include the padding bits in its output array) are included. */
2562 nunits = GET_MODE_SIZE (mode);
2563 bitsize = nunits * BITS_PER_UNIT;
2564 nelts = CEIL (bitsize, 32);
2565 units_per = 32 / BITS_PER_UNIT;
2567 real_to_target (data, &d, mode);
2569 /* Put out the first word with the specified alignment. */
2570 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2571 nunits -= units_per;
2573 /* Subsequent words need only 32-bit alignment. */
2574 align = min_align (align, 32);
2576 for (i = 1; i < nelts; i++)
2578 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2579 nunits -= units_per;
2583 /* Given an expression EXP with a constant value,
2584 reduce it to the sum of an assembler symbol and an integer.
2585 Store them both in the structure *VALUE.
2586 EXP must be reducible. */
2590 HOST_WIDE_INT offset;
2594 decode_addr_const (tree exp, struct addr_const *value)
2596 tree target = TREE_OPERAND (exp, 0);
2602 if (TREE_CODE (target) == COMPONENT_REF
2603 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2605 offset += int_byte_position (TREE_OPERAND (target, 1));
2606 target = TREE_OPERAND (target, 0);
2608 else if (TREE_CODE (target) == ARRAY_REF
2609 || TREE_CODE (target) == ARRAY_RANGE_REF)
2611 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2612 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2613 target = TREE_OPERAND (target, 0);
2615 else if (TREE_CODE (target) == MEM_REF
2616 && TREE_CODE (TREE_OPERAND (target, 0)) == ADDR_EXPR)
2618 offset += mem_ref_offset (target).low;
2619 target = TREE_OPERAND (TREE_OPERAND (target, 0), 0);
2621 else if (TREE_CODE (target) == INDIRECT_REF
2622 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2623 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2625 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2630 switch (TREE_CODE (target))
2634 x = DECL_RTL (target);
2638 x = gen_rtx_MEM (FUNCTION_MODE,
2639 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2648 x = output_constant_def (target, 1);
2655 gcc_assert (MEM_P (x));
2659 value->offset = offset;
2663 static GTY((param_is (struct constant_descriptor_tree)))
2664 htab_t const_desc_htab;
2666 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2668 /* Constant pool accessor function. */
2671 constant_pool_htab (void)
2673 return const_desc_htab;
2676 /* Compute a hash code for a constant expression. */
2679 const_desc_hash (const void *ptr)
2681 return ((const struct constant_descriptor_tree *)ptr)->hash;
2685 const_hash_1 (const tree exp)
2690 enum tree_code code = TREE_CODE (exp);
2692 /* Either set P and LEN to the address and len of something to hash and
2693 exit the switch or return a value. */
2698 p = (char *) &TREE_INT_CST (exp);
2699 len = sizeof TREE_INT_CST (exp);
2703 return real_hash (TREE_REAL_CST_PTR (exp));
2706 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2709 p = TREE_STRING_POINTER (exp);
2710 len = TREE_STRING_LENGTH (exp);
2714 return (const_hash_1 (TREE_REALPART (exp)) * 5
2715 + const_hash_1 (TREE_IMAGPART (exp)));
2721 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2723 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2724 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2731 unsigned HOST_WIDE_INT idx;
2734 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2736 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2738 hi = hi * 603 + const_hash_1 (value);
2746 struct addr_const value;
2748 decode_addr_const (exp, &value);
2749 switch (GET_CODE (value.base))
2752 /* Don't hash the address of the SYMBOL_REF;
2753 only use the offset and the symbol name. */
2755 p = XSTR (value.base, 0);
2756 for (i = 0; p[i] != 0; i++)
2757 hi = ((hi * 613) + (unsigned) (p[i]));
2761 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2771 case POINTER_PLUS_EXPR:
2773 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2774 + const_hash_1 (TREE_OPERAND (exp, 1)));
2777 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2780 /* A language specific constant. Just hash the code. */
2784 /* Compute hashing function. */
2786 for (i = 0; i < len; i++)
2787 hi = ((hi * 613) + (unsigned) (p[i]));
2792 /* Wrapper of compare_constant, for the htab interface. */
2794 const_desc_eq (const void *p1, const void *p2)
2796 const struct constant_descriptor_tree *const c1
2797 = (const struct constant_descriptor_tree *) p1;
2798 const struct constant_descriptor_tree *const c2
2799 = (const struct constant_descriptor_tree *) p2;
2800 if (c1->hash != c2->hash)
2802 return compare_constant (c1->value, c2->value);
2805 /* Compare t1 and t2, and return 1 only if they are known to result in
2806 the same bit pattern on output. */
2809 compare_constant (const tree t1, const tree t2)
2811 enum tree_code typecode;
2813 if (t1 == NULL_TREE)
2814 return t2 == NULL_TREE;
2815 if (t2 == NULL_TREE)
2818 if (TREE_CODE (t1) != TREE_CODE (t2))
2821 switch (TREE_CODE (t1))
2824 /* Integer constants are the same only if the same width of type. */
2825 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2827 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2829 return tree_int_cst_equal (t1, t2);
2832 /* Real constants are the same only if the same width of type. */
2833 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2836 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2839 /* Fixed constants are the same only if the same width of type. */
2840 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2843 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
2846 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2849 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2850 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2851 TREE_STRING_LENGTH (t1)));
2854 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2855 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2861 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
2862 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
2865 link2 = TREE_VECTOR_CST_ELTS (t2);
2866 for (link1 = TREE_VECTOR_CST_ELTS (t1);
2868 link1 = TREE_CHAIN (link1))
2870 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
2872 link2 = TREE_CHAIN (link2);
2880 VEC(constructor_elt, gc) *v1, *v2;
2881 unsigned HOST_WIDE_INT idx;
2883 typecode = TREE_CODE (TREE_TYPE (t1));
2884 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2887 if (typecode == ARRAY_TYPE)
2889 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2890 /* For arrays, check that the sizes all match. */
2891 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2893 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2898 /* For record and union constructors, require exact type
2900 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2904 v1 = CONSTRUCTOR_ELTS (t1);
2905 v2 = CONSTRUCTOR_ELTS (t2);
2906 if (VEC_length (constructor_elt, v1)
2907 != VEC_length (constructor_elt, v2))
2910 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
2912 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
2913 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
2915 /* Check that each value is the same... */
2916 if (!compare_constant (c1->value, c2->value))
2918 /* ... and that they apply to the same fields! */
2919 if (typecode == ARRAY_TYPE)
2921 if (!compare_constant (c1->index, c2->index))
2926 if (c1->index != c2->index)
2937 struct addr_const value1, value2;
2941 decode_addr_const (t1, &value1);
2942 decode_addr_const (t2, &value2);
2944 if (value1.offset != value2.offset)
2947 code = GET_CODE (value1.base);
2948 if (code != GET_CODE (value2.base))
2954 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2958 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
2959 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
2969 case POINTER_PLUS_EXPR:
2972 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2973 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2976 case VIEW_CONVERT_EXPR:
2977 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2986 /* Make a copy of the whole tree structure for a constant. This
2987 handles the same types of nodes that compare_constant handles. */
2990 copy_constant (tree exp)
2992 switch (TREE_CODE (exp))
2995 /* For ADDR_EXPR, we do not want to copy the decl whose address
2996 is requested. We do want to copy constants though. */
2997 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
2998 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2999 copy_constant (TREE_OPERAND (exp, 0)));
3001 return copy_node (exp);
3007 return copy_node (exp);
3010 return build_complex (TREE_TYPE (exp),
3011 copy_constant (TREE_REALPART (exp)),
3012 copy_constant (TREE_IMAGPART (exp)));
3015 case POINTER_PLUS_EXPR:
3017 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3018 copy_constant (TREE_OPERAND (exp, 0)),
3019 copy_constant (TREE_OPERAND (exp, 1)));
3022 case VIEW_CONVERT_EXPR:
3023 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3024 copy_constant (TREE_OPERAND (exp, 0)));
3027 return build_vector (TREE_TYPE (exp),
3028 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3032 tree copy = copy_node (exp);
3033 VEC(constructor_elt, gc) *v;
3034 unsigned HOST_WIDE_INT idx;
3035 tree purpose, value;
3037 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3038 CONSTRUCTOR_ELTS (exp)));
3039 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3041 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3042 ce->index = purpose;
3043 ce->value = copy_constant (value);
3045 CONSTRUCTOR_ELTS (copy) = v;
3054 /* Return the section into which constant EXP should be placed. */
3057 get_constant_section (tree exp, unsigned int align)
3059 return targetm.asm_out.select_section (exp,
3060 compute_reloc_for_constant (exp),
3064 /* Return the size of constant EXP in bytes. */
3066 static HOST_WIDE_INT
3067 get_constant_size (tree exp)
3071 size = int_size_in_bytes (TREE_TYPE (exp));
3072 if (TREE_CODE (exp) == STRING_CST)
3073 size = MAX (TREE_STRING_LENGTH (exp), size);
3077 /* Subroutine of output_constant_def:
3078 No constant equal to EXP is known to have been output.
3079 Make a constant descriptor to enter EXP in the hash table.
3080 Assign the label number and construct RTL to refer to the
3081 constant's location in memory.
3082 Caller is responsible for updating the hash table. */
3084 static struct constant_descriptor_tree *
3085 build_constant_desc (tree exp)
3087 struct constant_descriptor_tree *desc;
3093 desc = ggc_alloc_constant_descriptor_tree ();
3094 desc->value = copy_constant (exp);
3096 /* Propagate marked-ness to copied constant. */
3097 if (flag_mudflap && mf_marked_p (exp))
3098 mf_mark (desc->value);
3100 /* Create a string containing the label name, in LABEL. */
3101 labelno = const_labelno++;
3102 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3104 /* Construct the VAR_DECL associated with the constant. */
3105 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3107 DECL_ARTIFICIAL (decl) = 1;
3108 DECL_IGNORED_P (decl) = 1;
3109 TREE_READONLY (decl) = 1;
3110 TREE_STATIC (decl) = 1;
3111 TREE_ADDRESSABLE (decl) = 1;
3112 /* We don't set the RTL yet as this would cause varpool to assume that the
3113 variable is referenced. Moreover, it would just be dropped in LTO mode.
3114 Instead we set the flag that will be recognized in make_decl_rtl. */
3115 DECL_IN_CONSTANT_POOL (decl) = 1;
3116 DECL_INITIAL (decl) = desc->value;
3117 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3118 architectures so use DATA_ALIGNMENT as well, except for strings. */
3119 if (TREE_CODE (exp) == STRING_CST)
3121 #ifdef CONSTANT_ALIGNMENT
3122 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3126 align_variable (decl, 0);
3128 /* Now construct the SYMBOL_REF and the MEM. */
3129 if (use_object_blocks_p ())
3131 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3132 symbol = create_block_symbol (ggc_strdup (label),
3133 get_block_for_section (sect), -1);
3136 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3137 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3138 SET_SYMBOL_REF_DECL (symbol, decl);
3139 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3141 rtl = gen_const_mem (TYPE_MODE (TREE_TYPE (exp)), symbol);
3142 set_mem_attributes (rtl, exp, 1);
3143 set_mem_alias_set (rtl, 0);
3144 set_mem_alias_set (rtl, const_alias_set);
3146 /* We cannot share RTX'es in pool entries.
3147 Mark this piece of RTL as required for unsharing. */
3148 RTX_FLAG (rtl, used) = 1;
3150 /* Set flags or add text to the name to record information, such as
3151 that it is a local symbol. If the name is changed, the macro
3152 ASM_OUTPUT_LABELREF will have to know how to strip this
3153 information. This call might invalidate our local variable
3154 SYMBOL; we can't use it afterward. */
3155 targetm.encode_section_info (exp, rtl, true);
3162 /* Return an rtx representing a reference to constant data in memory
3163 for the constant expression EXP.
3165 If assembler code for such a constant has already been output,
3166 return an rtx to refer to it.
3167 Otherwise, output such a constant in memory
3168 and generate an rtx for it.
3170 If DEFER is nonzero, this constant can be deferred and output only
3171 if referenced in the function after all optimizations.
3173 `const_desc_table' records which constants already have label strings. */
3176 output_constant_def (tree exp, int defer)
3178 struct constant_descriptor_tree *desc;
3179 struct constant_descriptor_tree key;
3182 /* Look up EXP in the table of constant descriptors. If we didn't find
3183 it, create a new one. */
3185 key.hash = const_hash_1 (exp);
3186 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3188 desc = (struct constant_descriptor_tree *) *loc;
3191 desc = build_constant_desc (exp);
3192 desc->hash = key.hash;
3196 maybe_output_constant_def_contents (desc, defer);
3200 /* Subroutine of output_constant_def: Decide whether or not we need to
3201 output the constant DESC now, and if so, do it. */
3203 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3206 rtx symbol = XEXP (desc->rtl, 0);
3207 tree exp = desc->value;
3209 if (flag_syntax_only)
3212 if (TREE_ASM_WRITTEN (exp))
3213 /* Already output; don't do it again. */
3216 /* We can always defer constants as long as the context allows
3220 /* Increment n_deferred_constants if it exists. It needs to be at
3221 least as large as the number of constants actually referred to
3222 by the function. If it's too small we'll stop looking too early
3223 and fail to emit constants; if it's too large we'll only look
3224 through the entire function when we could have stopped earlier. */
3226 n_deferred_constants++;
3230 output_constant_def_contents (symbol);
3233 /* Subroutine of output_constant_def_contents. Output the definition
3234 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3235 constant's alignment in bits. */
3238 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3242 size = get_constant_size (exp);
3244 /* Do any machine/system dependent processing of the constant. */
3245 targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3247 /* Output the value of EXP. */
3248 output_constant (exp, size, align);
3251 /* We must output the constant data referred to by SYMBOL; do so. */
3254 output_constant_def_contents (rtx symbol)
3256 tree decl = SYMBOL_REF_DECL (symbol);
3257 tree exp = DECL_INITIAL (decl);
3260 /* Make sure any other constants whose addresses appear in EXP
3261 are assigned label numbers. */
3262 output_addressed_constants (exp);
3264 /* We are no longer deferring this constant. */
3265 TREE_ASM_WRITTEN (decl) = TREE_ASM_WRITTEN (exp) = 1;
3267 /* If the constant is part of an object block, make sure that the
3268 decl has been positioned within its block, but do not write out
3269 its definition yet. output_object_blocks will do that later. */
3270 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3271 place_block_symbol (symbol);
3274 align = DECL_ALIGN (decl);
3275 switch_to_section (get_constant_section (exp, align));
3276 if (align > BITS_PER_UNIT)
3277 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3278 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3281 mudflap_enqueue_constant (exp);
3284 /* Look up EXP in the table of constant descriptors. Return the rtl
3285 if it has been emitted, else null. */
3288 lookup_constant_def (tree exp)
3290 struct constant_descriptor_tree *desc;
3291 struct constant_descriptor_tree key;
3294 key.hash = const_hash_1 (exp);
3295 desc = (struct constant_descriptor_tree *)
3296 htab_find_with_hash (const_desc_htab, &key, key.hash);
3298 return (desc ? desc->rtl : NULL_RTX);
3301 /* Return a tree representing a reference to constant data in memory
3302 for the constant expression EXP.
3304 This is the counterpart of output_constant_def at the Tree level. */
3307 tree_output_constant_def (tree exp)
3309 struct constant_descriptor_tree *desc, key;
3313 /* Look up EXP in the table of constant descriptors. If we didn't find
3314 it, create a new one. */
3316 key.hash = const_hash_1 (exp);
3317 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3319 desc = (struct constant_descriptor_tree *) *loc;
3322 desc = build_constant_desc (exp);
3323 desc->hash = key.hash;
3327 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3328 varpool_finalize_decl (decl);
3332 /* Used in the hash tables to avoid outputting the same constant
3333 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3334 are output once per function, not once per file. */
3335 /* ??? Only a few targets need per-function constant pools. Most
3336 can use one per-file pool. Should add a targetm bit to tell the
3339 struct GTY(()) rtx_constant_pool {
3340 /* Pointers to first and last constant in pool, as ordered by offset. */
3341 struct constant_descriptor_rtx *first;
3342 struct constant_descriptor_rtx *last;
3344 /* Hash facility for making memory-constants from constant rtl-expressions.
3345 It is used on RISC machines where immediate integer arguments and
3346 constant addresses are restricted so that such constants must be stored
3348 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3350 /* Current offset in constant pool (does not include any
3351 machine-specific header). */
3352 HOST_WIDE_INT offset;
3355 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3356 struct constant_descriptor_rtx *next;
3360 HOST_WIDE_INT offset;
3362 enum machine_mode mode;
3368 /* Hash and compare functions for const_rtx_htab. */
3371 const_desc_rtx_hash (const void *ptr)
3373 const struct constant_descriptor_rtx *const desc
3374 = (const struct constant_descriptor_rtx *) ptr;
3379 const_desc_rtx_eq (const void *a, const void *b)
3381 const struct constant_descriptor_rtx *const x
3382 = (const struct constant_descriptor_rtx *) a;
3383 const struct constant_descriptor_rtx *const y
3384 = (const struct constant_descriptor_rtx *) b;
3386 if (x->mode != y->mode)
3388 return rtx_equal_p (x->constant, y->constant);
3391 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3394 const_rtx_hash_1 (rtx *xp, void *data)
3396 unsigned HOST_WIDE_INT hwi;
3397 enum machine_mode mode;
3403 code = GET_CODE (x);
3404 mode = GET_MODE (x);
3405 h = (hashval_t) code * 1048573 + mode;
3413 int shift = sizeof (hashval_t) * CHAR_BIT;
3414 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3417 h ^= (hashval_t) hwi;
3418 for (i = 1; i < n; ++i)
3421 h ^= (hashval_t) hwi;
3427 if (mode == VOIDmode)
3429 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3433 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3437 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3443 for (i = XVECLEN (x, 0); i-- > 0; )
3444 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3449 h ^= htab_hash_string (XSTR (x, 0));
3453 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3457 case UNSPEC_VOLATILE:
3458 h = h * 251 + XINT (x, 1);
3465 hp = (hashval_t *) data;
3466 *hp = *hp * 509 + h;
3470 /* Compute a hash value for X, which should be a constant. */
3473 const_rtx_hash (rtx x)
3476 for_each_rtx (&x, const_rtx_hash_1, &h);
3481 /* Create and return a new rtx constant pool. */
3483 static struct rtx_constant_pool *
3484 create_constant_pool (void)
3486 struct rtx_constant_pool *pool;
3488 pool = ggc_alloc_rtx_constant_pool ();
3489 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3490 const_desc_rtx_eq, NULL);
3497 /* Initialize constant pool hashing for a new function. */
3500 init_varasm_status (void)
3502 crtl->varasm.pool = create_constant_pool ();
3503 crtl->varasm.deferred_constants = 0;
3506 /* Given a MINUS expression, simplify it if both sides
3507 include the same symbol. */
3510 simplify_subtraction (rtx x)
3512 rtx r = simplify_rtx (x);
3516 /* Given a constant rtx X, make (or find) a memory constant for its value
3517 and return a MEM rtx to refer to it in memory. */
3520 force_const_mem (enum machine_mode mode, rtx x)
3522 struct constant_descriptor_rtx *desc, tmp;
3523 struct rtx_constant_pool *pool;
3530 /* If we're not allowed to drop X into the constant pool, don't. */
3531 if (targetm.cannot_force_const_mem (mode, x))
3534 /* Record that this function has used a constant pool entry. */
3535 crtl->uses_const_pool = 1;
3537 /* Decide which pool to use. */
3538 pool = (targetm.use_blocks_for_constant_p (mode, x)
3539 ? shared_constant_pool
3540 : crtl->varasm.pool);
3542 /* Lookup the value in the hashtable. */
3545 hash = const_rtx_hash (x);
3546 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3547 desc = (struct constant_descriptor_rtx *) *slot;
3549 /* If the constant was already present, return its memory. */
3551 return copy_rtx (desc->mem);
3553 /* Otherwise, create a new descriptor. */
3554 desc = ggc_alloc_constant_descriptor_rtx ();
3557 /* Align the location counter as required by EXP's data type. */
3558 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3559 #ifdef CONSTANT_ALIGNMENT
3561 tree type = lang_hooks.types.type_for_mode (mode, 0);
3562 if (type != NULL_TREE)
3563 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3567 pool->offset += (align / BITS_PER_UNIT) - 1;
3568 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3571 desc->constant = copy_rtx (tmp.constant);
3572 desc->offset = pool->offset;
3575 desc->align = align;
3576 desc->labelno = const_labelno;
3579 pool->offset += GET_MODE_SIZE (mode);
3581 pool->last->next = desc;
3583 pool->first = pool->last = desc;
3586 /* Create a string containing the label name, in LABEL. */
3587 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3590 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3591 the constants pool. */
3592 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3594 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3595 symbol = create_block_symbol (ggc_strdup (label),
3596 get_block_for_section (sect), -1);
3599 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3601 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3602 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3603 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3605 /* Construct the MEM. */
3606 desc->mem = def = gen_const_mem (mode, symbol);
3607 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3608 set_mem_align (def, align);
3610 /* If we're dropping a label to the constant pool, make sure we
3612 if (GET_CODE (x) == LABEL_REF)
3613 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3615 return copy_rtx (def);
3618 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3621 get_pool_constant (rtx addr)
3623 return SYMBOL_REF_CONSTANT (addr)->constant;
3626 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3627 and whether it has been output or not. */
3630 get_pool_constant_mark (rtx addr, bool *pmarked)
3632 struct constant_descriptor_rtx *desc;
3634 desc = SYMBOL_REF_CONSTANT (addr);
3635 *pmarked = (desc->mark != 0);
3636 return desc->constant;
3639 /* Similar, return the mode. */
3642 get_pool_mode (const_rtx addr)
3644 return SYMBOL_REF_CONSTANT (addr)->mode;
3647 /* Return the size of the constant pool. */
3650 get_pool_size (void)
3652 return crtl->varasm.pool->offset;
3655 /* Worker function for output_constant_pool_1. Emit assembly for X
3656 in MODE with known alignment ALIGN. */
3659 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3661 switch (GET_MODE_CLASS (mode))
3664 case MODE_DECIMAL_FLOAT:
3668 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3669 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3670 assemble_real (r, mode, align);
3675 case MODE_PARTIAL_INT:
3680 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3683 case MODE_VECTOR_FLOAT:
3684 case MODE_VECTOR_INT:
3685 case MODE_VECTOR_FRACT:
3686 case MODE_VECTOR_UFRACT:
3687 case MODE_VECTOR_ACCUM:
3688 case MODE_VECTOR_UACCUM:
3691 enum machine_mode submode = GET_MODE_INNER (mode);
3692 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3694 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3695 units = CONST_VECTOR_NUNITS (x);
3697 for (i = 0; i < units; i++)
3699 rtx elt = CONST_VECTOR_ELT (x, i);
3700 output_constant_pool_2 (submode, elt, i ? subalign : align);
3710 /* Worker function for output_constant_pool. Emit constant DESC,
3711 giving it ALIGN bits of alignment. */
3714 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3721 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3722 whose CODE_LABEL has been deleted. This can occur if a jump table
3723 is eliminated by optimization. If so, write a constant of zero
3724 instead. Note that this can also happen by turning the
3725 CODE_LABEL into a NOTE. */
3726 /* ??? This seems completely and utterly wrong. Certainly it's
3727 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3728 functioning even with INSN_DELETED_P and friends. */
3731 switch (GET_CODE (tmp))
3734 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3735 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3737 tmp = XEXP (XEXP (tmp, 0), 0);
3741 tmp = XEXP (tmp, 0);
3742 gcc_assert (!INSN_DELETED_P (tmp));
3743 gcc_assert (!NOTE_P (tmp)
3744 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3751 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3752 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3753 align, desc->labelno, done);
3756 assemble_align (align);
3758 /* Output the label. */
3759 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3761 /* Output the data. */
3762 output_constant_pool_2 (desc->mode, x, align);
3764 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3765 sections have proper size. */
3766 if (align > GET_MODE_BITSIZE (desc->mode)
3768 && (in_section->common.flags & SECTION_MERGE))
3769 assemble_align (align);
3771 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3777 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3778 to as used. Emit referenced deferred strings. This function can
3779 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3782 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3784 rtx x = *current_rtx;
3786 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3789 if (CONSTANT_POOL_ADDRESS_P (x))
3791 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3792 if (desc->mark == 0)
3795 for_each_rtx (&desc->constant, mark_constant, NULL);
3798 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3800 tree decl = SYMBOL_REF_DECL (x);
3801 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
3803 n_deferred_constants--;
3804 output_constant_def_contents (x);
3811 /* Look through appropriate parts of INSN, marking all entries in the
3812 constant pool which are actually being used. Entries that are only
3813 referenced by other constants are also marked as used. Emit
3814 deferred strings that are used. */
3817 mark_constants (rtx insn)
3822 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3823 insns, not any notes that may be attached. We don't want to mark
3824 a constant just because it happens to appear in a REG_EQUIV note. */
3825 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3827 rtx seq = PATTERN (insn);
3828 int i, n = XVECLEN (seq, 0);
3829 for (i = 0; i < n; ++i)
3831 rtx subinsn = XVECEXP (seq, 0, i);
3832 if (INSN_P (subinsn))
3833 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
3837 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
3840 /* Look through the instructions for this function, and mark all the
3841 entries in POOL which are actually being used. Emit deferred constants
3842 which have indeed been used. */
3845 mark_constant_pool (void)
3849 if (!crtl->uses_const_pool && n_deferred_constants == 0)
3852 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3853 mark_constants (insn);
3855 for (link = crtl->epilogue_delay_list;
3857 link = XEXP (link, 1))
3858 mark_constants (XEXP (link, 0));
3861 /* Write all the constants in POOL. */
3864 output_constant_pool_contents (struct rtx_constant_pool *pool)
3866 struct constant_descriptor_rtx *desc;
3868 for (desc = pool->first; desc ; desc = desc->next)
3871 /* If the constant is part of an object_block, make sure that
3872 the constant has been positioned within its block, but do not
3873 write out its definition yet. output_object_blocks will do
3875 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
3876 && SYMBOL_REF_BLOCK (desc->sym))
3877 place_block_symbol (desc->sym);
3880 switch_to_section (targetm.asm_out.select_rtx_section
3881 (desc->mode, desc->constant, desc->align));
3882 output_constant_pool_1 (desc, desc->align);
3887 /* Mark all constants that are used in the current function, then write
3888 out the function's private constant pool. */
3891 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3892 tree fndecl ATTRIBUTE_UNUSED)
3894 struct rtx_constant_pool *pool = crtl->varasm.pool;
3896 /* It is possible for gcc to call force_const_mem and then to later
3897 discard the instructions which refer to the constant. In such a
3898 case we do not need to output the constant. */
3899 mark_constant_pool ();
3901 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3902 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3905 output_constant_pool_contents (pool);
3907 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3908 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3912 /* Write the contents of the shared constant pool. */
3915 output_shared_constant_pool (void)
3917 output_constant_pool_contents (shared_constant_pool);
3920 /* Determine what kind of relocations EXP may need. */
3923 compute_reloc_for_constant (tree exp)
3925 int reloc = 0, reloc2;
3928 switch (TREE_CODE (exp))
3932 /* Go inside any operations that get_inner_reference can handle and see
3933 if what's inside is a constant: no need to do anything here for
3934 addresses of variables or functions. */
3935 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3936 tem = TREE_OPERAND (tem, 0))
3939 if (TREE_PUBLIC (tem))
3946 case POINTER_PLUS_EXPR:
3947 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3948 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3952 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3953 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3954 /* The difference of two local labels is computable at link time. */
3955 if (reloc == 1 && reloc2 == 1)
3962 case VIEW_CONVERT_EXPR:
3963 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3968 unsigned HOST_WIDE_INT idx;
3969 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
3971 reloc |= compute_reloc_for_constant (tem);
3981 /* Find all the constants whose addresses are referenced inside of EXP,
3982 and make sure assembler code with a label has been output for each one.
3983 Indicate whether an ADDR_EXPR has been encountered. */
3986 output_addressed_constants (tree exp)
3990 switch (TREE_CODE (exp))
3994 /* Go inside any operations that get_inner_reference can handle and see
3995 if what's inside is a constant: no need to do anything here for
3996 addresses of variables or functions. */
3997 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3998 tem = TREE_OPERAND (tem, 0))
4001 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4002 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4003 tem = DECL_INITIAL (tem);
4005 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4006 output_constant_def (tem, 0);
4010 case POINTER_PLUS_EXPR:
4012 output_addressed_constants (TREE_OPERAND (exp, 1));
4016 case VIEW_CONVERT_EXPR:
4017 output_addressed_constants (TREE_OPERAND (exp, 0));
4022 unsigned HOST_WIDE_INT idx;
4023 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4025 output_addressed_constants (tem);
4034 /* Whether a constructor CTOR is a valid static constant initializer if all
4035 its elements are. This used to be internal to initializer_constant_valid_p
4036 and has been exposed to let other functions like categorize_ctor_elements
4037 evaluate the property while walking a constructor for other purposes. */
4040 constructor_static_from_elts_p (const_tree ctor)
4042 return (TREE_CONSTANT (ctor)
4043 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4044 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE
4045 || TREE_CODE (TREE_TYPE (ctor)) == ARRAY_TYPE));
4048 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4051 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4052 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4053 which are valid when ENDTYPE is an integer of any size; in
4054 particular, this does not accept a pointer minus a constant. This
4055 returns null_pointer_node if the VALUE is an absolute constant
4056 which can be used to initialize a static variable. Otherwise it
4060 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4064 if (!INTEGRAL_TYPE_P (endtype))
4067 op0 = TREE_OPERAND (value, 0);
4068 op1 = TREE_OPERAND (value, 1);
4070 /* Like STRIP_NOPS except allow the operand mode to widen. This
4071 works around a feature of fold that simplifies (int)(p1 - p2) to
4072 ((int)p1 - (int)p2) under the theory that the narrower operation
4075 while (CONVERT_EXPR_P (op0)
4076 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4078 tree inner = TREE_OPERAND (op0, 0);
4079 if (inner == error_mark_node
4080 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4081 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4082 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4087 while (CONVERT_EXPR_P (op1)
4088 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4090 tree inner = TREE_OPERAND (op1, 0);
4091 if (inner == error_mark_node
4092 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4093 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4094 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4099 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4103 op1 = initializer_constant_valid_p_1 (op1, endtype,
4104 cache ? cache + 2 : NULL);
4105 /* Both initializers must be known. */
4109 && (op0 == null_pointer_node
4110 || TREE_CODE (value) == MINUS_EXPR))
4111 return null_pointer_node;
4113 /* Support differences between labels. */
4114 if (TREE_CODE (op0) == LABEL_DECL
4115 && TREE_CODE (op1) == LABEL_DECL)
4116 return null_pointer_node;
4118 if (TREE_CODE (op0) == STRING_CST
4119 && TREE_CODE (op1) == STRING_CST
4120 && operand_equal_p (op0, op1, 1))
4121 return null_pointer_node;
4127 /* Helper function of initializer_constant_valid_p.
4128 Return nonzero if VALUE is a valid constant-valued expression
4129 for use in initializing a static variable; one that can be an
4130 element of a "constant" initializer.
4132 Return null_pointer_node if the value is absolute;
4133 if it is relocatable, return the variable that determines the relocation.
4134 We assume that VALUE has been folded as much as possible;
4135 therefore, we do not need to check for such things as
4136 arithmetic-combinations of integers.
4138 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4141 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4145 switch (TREE_CODE (value))
4148 if (constructor_static_from_elts_p (value))
4150 unsigned HOST_WIDE_INT idx;
4152 bool absolute = true;
4154 if (cache && cache[0] == value)
4156 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4159 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4166 cache[1] = NULL_TREE;
4170 if (reloc != null_pointer_node)
4173 /* For a non-absolute relocation, there is no single
4174 variable that can be "the variable that determines the
4179 cache[1] = absolute ? null_pointer_node : error_mark_node;
4181 return absolute ? null_pointer_node : error_mark_node;
4184 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4192 return null_pointer_node;
4197 tree op0 = staticp (TREE_OPERAND (value, 0));
4200 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4201 to be a constant, this is old-skool offsetof-like nonsense. */
4202 if (TREE_CODE (op0) == INDIRECT_REF
4203 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4204 return null_pointer_node;
4205 /* Taking the address of a nested function involves a trampoline,
4206 unless we don't need or want one. */
4207 if (TREE_CODE (op0) == FUNCTION_DECL
4208 && DECL_STATIC_CHAIN (op0)
4209 && !TREE_NO_TRAMPOLINE (value))
4211 /* "&{...}" requires a temporary to hold the constructed
4213 if (TREE_CODE (op0) == CONSTRUCTOR)
4219 case NON_LVALUE_EXPR:
4220 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4223 case VIEW_CONVERT_EXPR:
4225 tree src = TREE_OPERAND (value, 0);
4226 tree src_type = TREE_TYPE (src);
4227 tree dest_type = TREE_TYPE (value);
4229 /* Allow view-conversions from aggregate to non-aggregate type only
4230 if the bit pattern is fully preserved afterwards; otherwise, the
4231 RTL expander won't be able to apply a subsequent transformation
4232 to the underlying constructor. */
4233 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4235 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4236 return initializer_constant_valid_p_1 (src, endtype, cache);
4241 /* Allow all other kinds of view-conversion. */
4242 return initializer_constant_valid_p_1 (src, endtype, cache);
4247 tree src = TREE_OPERAND (value, 0);
4248 tree src_type = TREE_TYPE (src);
4249 tree dest_type = TREE_TYPE (value);
4251 /* Allow conversions between pointer types, floating-point
4252 types, and offset types. */
4253 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4254 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4255 || (TREE_CODE (dest_type) == OFFSET_TYPE
4256 && TREE_CODE (src_type) == OFFSET_TYPE))
4257 return initializer_constant_valid_p_1 (src, endtype, cache);
4259 /* Allow length-preserving conversions between integer types. */
4260 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4261 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4262 return initializer_constant_valid_p_1 (src, endtype, cache);
4264 /* Allow conversions between other integer types only if
4266 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4268 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4269 if (inner == null_pointer_node)
4270 return null_pointer_node;
4274 /* Allow (int) &foo provided int is as wide as a pointer. */
4275 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4276 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4277 return initializer_constant_valid_p_1 (src, endtype, cache);
4279 /* Likewise conversions from int to pointers, but also allow
4280 conversions from 0. */
4281 if ((POINTER_TYPE_P (dest_type)
4282 || TREE_CODE (dest_type) == OFFSET_TYPE)
4283 && INTEGRAL_TYPE_P (src_type))
4285 if (TREE_CODE (src) == INTEGER_CST
4286 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4287 return null_pointer_node;
4288 if (integer_zerop (src))
4289 return null_pointer_node;
4290 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4291 return initializer_constant_valid_p_1 (src, endtype, cache);
4294 /* Allow conversions to struct or union types if the value
4296 if (TREE_CODE (dest_type) == RECORD_TYPE
4297 || TREE_CODE (dest_type) == UNION_TYPE)
4298 return initializer_constant_valid_p_1 (src, endtype, cache);
4302 case POINTER_PLUS_EXPR:
4304 /* Any valid floating-point constants will have been folded by now;
4305 with -frounding-math we hit this with addition of two constants. */
4306 if (TREE_CODE (endtype) == REAL_TYPE)
4308 if (cache && cache[0] == value)
4310 if (! INTEGRAL_TYPE_P (endtype)
4311 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4313 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4315 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4318 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4319 endtype, ncache + 2);
4320 /* If either term is absolute, use the other term's relocation. */
4321 if (valid0 == null_pointer_node)
4323 else if (valid1 == null_pointer_node)
4325 /* Support narrowing pointer differences. */
4327 ret = narrowing_initializer_constant_valid_p (value, endtype,
4331 /* Support narrowing pointer differences. */
4332 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4341 if (TREE_CODE (endtype) == REAL_TYPE)
4343 if (cache && cache[0] == value)
4345 if (! INTEGRAL_TYPE_P (endtype)
4346 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4348 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4350 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4353 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4354 endtype, ncache + 2);
4355 /* Win if second argument is absolute. */
4356 if (valid1 == null_pointer_node)
4358 /* Win if both arguments have the same relocation.
4359 Then the value is absolute. */
4360 else if (valid0 == valid1 && valid0 != 0)
4361 ret = null_pointer_node;
4362 /* Since GCC guarantees that string constants are unique in the
4363 generated code, a subtraction between two copies of the same
4364 constant string is absolute. */
4365 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4366 && valid1 && TREE_CODE (valid1) == STRING_CST
4367 && operand_equal_p (valid0, valid1, 1))
4368 ret = null_pointer_node;
4369 /* Support narrowing differences. */
4371 ret = narrowing_initializer_constant_valid_p (value, endtype,
4375 /* Support narrowing differences. */
4376 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4391 /* Return nonzero if VALUE is a valid constant-valued expression
4392 for use in initializing a static variable; one that can be an
4393 element of a "constant" initializer.
4395 Return null_pointer_node if the value is absolute;
4396 if it is relocatable, return the variable that determines the relocation.
4397 We assume that VALUE has been folded as much as possible;
4398 therefore, we do not need to check for such things as
4399 arithmetic-combinations of integers. */
4401 initializer_constant_valid_p (tree value, tree endtype)
4403 return initializer_constant_valid_p_1 (value, endtype, NULL);
4406 /* Return true if VALUE is a valid constant-valued expression
4407 for use in initializing a static bit-field; one that can be
4408 an element of a "constant" initializer. */
4411 initializer_constant_valid_for_bitfield_p (tree value)
4413 /* For bitfields we support integer constants or possibly nested aggregates
4415 switch (TREE_CODE (value))
4419 unsigned HOST_WIDE_INT idx;
4422 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4423 if (!initializer_constant_valid_for_bitfield_p (elt))
4431 case VIEW_CONVERT_EXPR:
4432 case NON_LVALUE_EXPR:
4434 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4443 /* output_constructor outer state of relevance in recursive calls, typically
4444 for nested aggregate bitfields. */
4447 unsigned int bit_offset; /* current position in ... */
4448 int byte; /* ... the outer byte buffer. */
4451 static unsigned HOST_WIDE_INT
4452 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4455 /* Output assembler code for constant EXP to FILE, with no label.
4456 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4457 Assumes output_addressed_constants has been done on EXP already.
4459 Generate exactly SIZE bytes of assembler data, padding at the end
4460 with zeros if necessary. SIZE must always be specified.
4462 SIZE is important for structure constructors,
4463 since trailing members may have been omitted from the constructor.
4464 It is also important for initialization of arrays from string constants
4465 since the full length of the string constant might not be wanted.
4466 It is also needed for initialization of unions, where the initializer's
4467 type is just one member, and that may not be as long as the union.
4469 There a case in which we would fail to output exactly SIZE bytes:
4470 for a structure constructor that wants to produce more than SIZE bytes.
4471 But such constructors will never be generated for any possible input.
4473 ALIGN is the alignment of the data in bits. */
4476 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4478 enum tree_code code;
4479 unsigned HOST_WIDE_INT thissize;
4481 if (size == 0 || flag_syntax_only)
4484 /* See if we're trying to initialize a pointer in a non-default mode
4485 to the address of some declaration somewhere. If the target says
4486 the mode is valid for pointers, assume the target has a way of
4488 if (TREE_CODE (exp) == NOP_EXPR
4489 && POINTER_TYPE_P (TREE_TYPE (exp))
4490 && targetm.addr_space.valid_pointer_mode
4491 (TYPE_MODE (TREE_TYPE (exp)),
4492 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4494 tree saved_type = TREE_TYPE (exp);
4496 /* Peel off any intermediate conversions-to-pointer for valid
4498 while (TREE_CODE (exp) == NOP_EXPR
4499 && POINTER_TYPE_P (TREE_TYPE (exp))
4500 && targetm.addr_space.valid_pointer_mode
4501 (TYPE_MODE (TREE_TYPE (exp)),
4502 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4503 exp = TREE_OPERAND (exp, 0);
4505 /* If what we're left with is the address of something, we can
4506 convert the address to the final type and output it that
4508 if (TREE_CODE (exp) == ADDR_EXPR)
4509 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4510 /* Likewise for constant ints. */
4511 else if (TREE_CODE (exp) == INTEGER_CST)
4512 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4513 TREE_INT_CST_HIGH (exp));
4517 /* Eliminate any conversions since we'll be outputting the underlying
4519 while (CONVERT_EXPR_P (exp)
4520 || TREE_CODE (exp) == NON_LVALUE_EXPR
4521 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4523 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4524 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4526 /* Make sure eliminating the conversion is really a no-op, except with
4527 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4528 union types to allow for Ada unchecked unions. */
4529 if (type_size > op_size
4530 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4531 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4532 /* Keep the conversion. */
4535 exp = TREE_OPERAND (exp, 0);
4538 code = TREE_CODE (TREE_TYPE (exp));
4539 thissize = int_size_in_bytes (TREE_TYPE (exp));
4541 /* Allow a constructor with no elements for any data type.
4542 This means to fill the space with zeros. */
4543 if (TREE_CODE (exp) == CONSTRUCTOR
4544 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4546 assemble_zeros (size);
4550 if (TREE_CODE (exp) == FDESC_EXPR)
4552 #ifdef ASM_OUTPUT_FDESC
4553 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4554 tree decl = TREE_OPERAND (exp, 0);
4555 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4562 /* Now output the underlying data. If we've handling the padding, return.
4563 Otherwise, break and ensure SIZE is the size written. */
4570 case REFERENCE_TYPE:
4572 case FIXED_POINT_TYPE:
4573 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4574 EXPAND_INITIALIZER),
4575 MIN (size, thissize), align, 0))
4576 error ("initializer for integer/fixed-point value is too complicated");
4580 if (TREE_CODE (exp) != REAL_CST)
4581 error ("initializer for floating value is not a floating constant");
4583 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4587 output_constant (TREE_REALPART (exp), thissize / 2, align);
4588 output_constant (TREE_IMAGPART (exp), thissize / 2,
4589 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4594 switch (TREE_CODE (exp))
4597 output_constructor (exp, size, align, NULL);
4600 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4602 assemble_string (TREE_STRING_POINTER (exp), thissize);
4609 unsigned int nalign;
4610 enum machine_mode inner;
4612 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4613 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4615 elt_size = GET_MODE_SIZE (inner);
4617 link = TREE_VECTOR_CST_ELTS (exp);
4618 output_constant (TREE_VALUE (link), elt_size, align);
4619 thissize = elt_size;
4620 while ((link = TREE_CHAIN (link)) != NULL)
4622 output_constant (TREE_VALUE (link), elt_size, nalign);
4623 thissize += elt_size;
4634 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4635 output_constructor (exp, size, align, NULL);
4645 if (size > thissize)
4646 assemble_zeros (size - thissize);
4650 /* Subroutine of output_constructor, used for computing the size of
4651 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4652 type with an unspecified upper bound. */
4654 static unsigned HOST_WIDE_INT
4655 array_size_for_constructor (tree val)
4658 unsigned HOST_WIDE_INT cnt;
4659 tree index, value, tmp;
4662 /* This code used to attempt to handle string constants that are not
4663 arrays of single-bytes, but nothing else does, so there's no point in
4665 if (TREE_CODE (val) == STRING_CST)
4666 return TREE_STRING_LENGTH (val);
4668 max_index = NULL_TREE;
4669 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4671 if (TREE_CODE (index) == RANGE_EXPR)
4672 index = TREE_OPERAND (index, 1);
4673 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4677 if (max_index == NULL_TREE)
4680 /* Compute the total number of array elements. */
4681 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4682 i = double_int_sub (tree_to_double_int (max_index), tree_to_double_int (tmp));
4683 i = double_int_add (i, double_int_one);
4685 /* Multiply by the array element unit size to find number of bytes. */
4686 i = double_int_mul (i, tree_to_double_int
4687 (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val)))));
4689 gcc_assert (double_int_fits_in_uhwi_p (i));
4693 /* Other datastructures + helpers for output_constructor. */
4695 /* output_constructor local state to support interaction with helpers. */
4699 /* Received arguments. */
4700 tree exp; /* Constructor expression. */
4701 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4702 unsigned int align; /* Known initial alignment. */
4704 /* Constructor expression data. */
4705 tree type; /* Expression type. */
4706 tree field; /* Current field decl in a record. */
4707 tree min_index; /* Lower bound if specified for an array. */
4709 /* Output processing state. */
4710 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4711 bool byte_buffer_in_use; /* Whether byte ... */
4712 int byte; /* ... contains part of a bitfield byte yet to
4715 int last_relative_index; /* Implicit or explicit index of the last
4716 array element output within a bitfield. */
4717 /* Current element. */
4718 tree val; /* Current element value. */
4719 tree index; /* Current element index. */
4723 /* Helper for output_constructor. From the current LOCAL state, output a
4724 RANGE_EXPR element. */
4727 output_constructor_array_range (oc_local_state *local)
4729 unsigned HOST_WIDE_INT fieldsize
4730 = int_size_in_bytes (TREE_TYPE (local->type));
4732 HOST_WIDE_INT lo_index
4733 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4734 HOST_WIDE_INT hi_index
4735 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4736 HOST_WIDE_INT index;
4739 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4741 for (index = lo_index; index <= hi_index; index++)
4743 /* Output the element's initial value. */
4744 if (local->val == NULL_TREE)
4745 assemble_zeros (fieldsize);
4747 output_constant (local->val, fieldsize, align2);
4749 /* Count its size. */
4750 local->total_bytes += fieldsize;
4754 /* Helper for output_constructor. From the current LOCAL state, output a
4755 field element that is not true bitfield or part of an outer one. */
4758 output_constructor_regular_field (oc_local_state *local)
4760 /* Field size and position. Since this structure is static, we know the
4761 positions are constant. */
4762 unsigned HOST_WIDE_INT fieldsize;
4763 HOST_WIDE_INT fieldpos;
4765 unsigned int align2;
4767 if (local->index != NULL_TREE)
4769 double_int idx = double_int_sub (tree_to_double_int (local->index),
4770 tree_to_double_int (local->min_index));
4771 gcc_assert (double_int_fits_in_shwi_p (idx));
4772 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
4775 else if (local->field != NULL_TREE)
4776 fieldpos = int_byte_position (local->field);
4780 /* Output any buffered-up bit-fields preceding this element. */
4781 if (local->byte_buffer_in_use)
4783 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4784 local->total_bytes++;
4785 local->byte_buffer_in_use = false;
4788 /* Advance to offset of this element.
4789 Note no alignment needed in an array, since that is guaranteed
4790 if each element has the proper size. */
4791 if ((local->field != NULL_TREE || local->index != NULL_TREE)
4792 && fieldpos != local->total_bytes)
4794 gcc_assert (fieldpos >= local->total_bytes);
4795 assemble_zeros (fieldpos - local->total_bytes);
4796 local->total_bytes = fieldpos;
4799 /* Find the alignment of this element. */
4800 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
4802 /* Determine size this element should occupy. */
4807 /* If this is an array with an unspecified upper bound,
4808 the initializer determines the size. */
4809 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4810 but we cannot do this until the deprecated support for
4811 initializing zero-length array members is removed. */
4812 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
4813 && TYPE_DOMAIN (TREE_TYPE (local->field))
4814 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
4816 fieldsize = array_size_for_constructor (local->val);
4817 /* Given a non-empty initialization, this field had
4819 gcc_assert (!fieldsize || !DECL_CHAIN (local->field));
4822 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
4825 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
4827 /* Output the element's initial value. */
4828 if (local->val == NULL_TREE)
4829 assemble_zeros (fieldsize);
4831 output_constant (local->val, fieldsize, align2);
4833 /* Count its size. */
4834 local->total_bytes += fieldsize;
4837 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4838 output an element that is a true bitfield or part of an outer one. */
4841 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
4843 /* Bit size of this element. */
4844 HOST_WIDE_INT ebitsize
4846 ? tree_low_cst (DECL_SIZE (local->field), 1)
4847 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
4849 /* Relative index of this element if this is an array component. */
4850 HOST_WIDE_INT relative_index
4853 ? (tree_low_cst (local->index, 0)
4854 - tree_low_cst (local->min_index, 0))
4855 : local->last_relative_index + 1)
4858 /* Bit position of this element from the start of the containing
4860 HOST_WIDE_INT constructor_relative_ebitpos
4862 ? int_bit_position (local->field)
4863 : ebitsize * relative_index);
4865 /* Bit position of this element from the start of a possibly ongoing
4866 outer byte buffer. */
4867 HOST_WIDE_INT byte_relative_ebitpos
4868 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
4870 /* From the start of a possibly ongoing outer byte buffer, offsets to
4871 the first bit of this element and to the first bit past the end of
4873 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
4874 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
4876 local->last_relative_index = relative_index;
4878 if (local->val == NULL_TREE)
4879 local->val = integer_zero_node;
4881 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
4882 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
4883 local->val = TREE_OPERAND (local->val, 0);
4885 if (TREE_CODE (local->val) != INTEGER_CST
4886 && TREE_CODE (local->val) != CONSTRUCTOR)
4888 error ("invalid initial value for member %qE", DECL_NAME (local->field));
4892 /* If this field does not start in this (or, next) byte,
4894 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4896 /* Output remnant of any bit field in previous bytes. */
4897 if (local->byte_buffer_in_use)
4899 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4900 local->total_bytes++;
4901 local->byte_buffer_in_use = false;
4904 /* If still not at proper byte, advance to there. */
4905 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4907 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
4908 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
4909 local->total_bytes = next_offset / BITS_PER_UNIT;
4913 /* Set up the buffer if necessary. */
4914 if (!local->byte_buffer_in_use)
4918 local->byte_buffer_in_use = true;
4921 /* If this is nested constructor, recurse passing the bit offset and the
4922 pending data, then retrieve the new pending data afterwards. */
4923 if (TREE_CODE (local->val) == CONSTRUCTOR)
4925 oc_outer_state output_state;
4927 output_state.bit_offset = next_offset % BITS_PER_UNIT;
4928 output_state.byte = local->byte;
4930 += output_constructor (local->val, 0, 0, &output_state);
4931 local->byte = output_state.byte;
4935 /* Otherwise, we must split the element into pieces that fall within
4936 separate bytes, and combine each byte with previous or following
4938 while (next_offset < end_offset)
4942 HOST_WIDE_INT value;
4943 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4944 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4946 /* Advance from byte to byte
4947 within this element when necessary. */
4948 while (next_byte != local->total_bytes)
4950 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4951 local->total_bytes++;
4955 /* Number of bits we can process at once
4956 (all part of the same byte). */
4957 this_time = MIN (end_offset - next_offset,
4958 BITS_PER_UNIT - next_bit);
4959 if (BYTES_BIG_ENDIAN)
4961 /* On big-endian machine, take the most significant bits
4962 first (of the bits that are significant)
4963 and put them into bytes from the most significant end. */
4964 shift = end_offset - next_offset - this_time;
4966 /* Don't try to take a bunch of bits that cross
4967 the word boundary in the INTEGER_CST. We can
4968 only select bits from the LOW or HIGH part
4970 if (shift < HOST_BITS_PER_WIDE_INT
4971 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4973 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4974 shift = HOST_BITS_PER_WIDE_INT;
4977 /* Now get the bits from the appropriate constant word. */
4978 if (shift < HOST_BITS_PER_WIDE_INT)
4979 value = TREE_INT_CST_LOW (local->val);
4982 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4983 value = TREE_INT_CST_HIGH (local->val);
4984 shift -= HOST_BITS_PER_WIDE_INT;
4987 /* Get the result. This works only when:
4988 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4989 local->byte |= (((value >> shift)
4990 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4991 << (BITS_PER_UNIT - this_time - next_bit));
4995 /* On little-endian machines,
4996 take first the least significant bits of the value
4997 and pack them starting at the least significant
4998 bits of the bytes. */
4999 shift = next_offset - byte_relative_ebitpos;
5001 /* Don't try to take a bunch of bits that cross
5002 the word boundary in the INTEGER_CST. We can
5003 only select bits from the LOW or HIGH part
5005 if (shift < HOST_BITS_PER_WIDE_INT
5006 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5007 this_time = (HOST_BITS_PER_WIDE_INT - shift);
5009 /* Now get the bits from the appropriate constant word. */
5010 if (shift < HOST_BITS_PER_WIDE_INT)
5011 value = TREE_INT_CST_LOW (local->val);
5014 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5015 value = TREE_INT_CST_HIGH (local->val);
5016 shift -= HOST_BITS_PER_WIDE_INT;
5019 /* Get the result. This works only when:
5020 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5021 local->byte |= (((value >> shift)
5022 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5026 next_offset += this_time;
5027 local->byte_buffer_in_use = true;
5031 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5032 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5033 caller output state of relevance in recursive invocations. */
5035 static unsigned HOST_WIDE_INT
5036 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
5037 unsigned int align, oc_outer_state * outer)
5039 unsigned HOST_WIDE_INT cnt;
5040 constructor_elt *ce;
5042 oc_local_state local;
5044 /* Setup our local state to communicate with helpers. */
5047 local.align = align;
5049 local.total_bytes = 0;
5050 local.byte_buffer_in_use = outer != NULL;
5051 local.byte = outer ? outer->byte : 0;
5053 local.type = TREE_TYPE (exp);
5055 local.last_relative_index = -1;
5057 local.min_index = NULL_TREE;
5058 if (TREE_CODE (local.type) == ARRAY_TYPE
5059 && TYPE_DOMAIN (local.type) != NULL_TREE)
5060 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5062 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
5064 /* As CE goes through the elements of the constant, FIELD goes through the
5065 structure fields if the constant is a structure. If the constant is a
5066 union, we override this by getting the field from the TREE_LIST element.
5067 But the constant could also be an array. Then FIELD is zero.
5069 There is always a maximum of one element in the chain LINK for unions
5070 (even if the initializer in a source program incorrectly contains
5073 local.field = NULL_TREE;
5074 if (TREE_CODE (local.type) == RECORD_TYPE)
5075 local.field = TYPE_FIELDS (local.type);
5078 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
5079 cnt++, local.field = local.field ? DECL_CHAIN (local.field) : 0)
5081 local.val = ce->value;
5082 local.index = NULL_TREE;
5084 /* The element in a union constructor specifies the proper field
5086 if ((TREE_CODE (local.type) == RECORD_TYPE
5087 || TREE_CODE (local.type) == UNION_TYPE
5088 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
5089 && ce->index != NULL_TREE)
5090 local.field = ce->index;
5092 else if (TREE_CODE (local.type) == ARRAY_TYPE)
5093 local.index = ce->index;
5095 if (local.field && flag_verbose_asm)
5096 fprintf (asm_out_file, "%s %s:\n",
5098 DECL_NAME (local.field)
5099 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
5102 /* Eliminate the marker that makes a cast not be an lvalue. */
5103 if (local.val != NULL_TREE)
5104 STRIP_NOPS (local.val);
5106 /* Output the current element, using the appropriate helper ... */
5108 /* For an array slice not part of an outer bitfield. */
5110 && local.index != NULL_TREE
5111 && TREE_CODE (local.index) == RANGE_EXPR)
5112 output_constructor_array_range (&local);
5114 /* For a field that is neither a true bitfield nor part of an outer one,
5115 known to be at least byte aligned and multiple-of-bytes long. */
5117 && (local.field == NULL_TREE
5118 || !CONSTRUCTOR_BITFIELD_P (local.field)))
5119 output_constructor_regular_field (&local);
5121 /* For a true bitfield or part of an outer one. */
5123 output_constructor_bitfield (&local, outer);
5126 /* If we are not at toplevel, save the pending data for our caller.
5127 Otherwise output the pending data and padding zeros as needed. */
5129 outer->byte = local.byte;
5132 if (local.byte_buffer_in_use)
5134 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
5135 local.total_bytes++;
5138 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
5140 assemble_zeros (local.size - local.total_bytes);
5141 local.total_bytes = local.size;
5145 return local.total_bytes;
5148 /* Mark DECL as weak. */
5151 mark_weak (tree decl)
5153 DECL_WEAK (decl) = 1;
5155 if (DECL_RTL_SET_P (decl)
5156 && MEM_P (DECL_RTL (decl))
5157 && XEXP (DECL_RTL (decl), 0)
5158 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5159 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5162 /* Merge weak status between NEWDECL and OLDDECL. */
5165 merge_weak (tree newdecl, tree olddecl)
5167 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5169 if (DECL_WEAK (newdecl) && TARGET_SUPPORTS_WEAK)
5172 /* We put the NEWDECL on the weak_decls list at some point
5173 and OLDDECL as well. Keep just OLDDECL on the list. */
5174 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5175 if (TREE_VALUE (*pwd) == newdecl)
5177 *pwd = TREE_CHAIN (*pwd);
5184 if (DECL_WEAK (newdecl))
5188 /* NEWDECL is weak, but OLDDECL is not. */
5190 /* If we already output the OLDDECL, we're in trouble; we can't
5191 go back and make it weak. This should never happen in
5192 unit-at-a-time compilation. */
5193 gcc_assert (!TREE_ASM_WRITTEN (olddecl));
5195 /* If we've already generated rtl referencing OLDDECL, we may
5196 have done so in a way that will not function properly with
5197 a weak symbol. Again in unit-at-a-time this should be
5199 gcc_assert (!TREE_USED (olddecl)
5200 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)));
5202 if (TARGET_SUPPORTS_WEAK)
5204 /* We put the NEWDECL on the weak_decls list at some point.
5205 Replace it with the OLDDECL. */
5206 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5207 if (TREE_VALUE (wd) == newdecl)
5209 TREE_VALUE (wd) = olddecl;
5212 /* We may not find the entry on the list. If NEWDECL is a
5213 weak alias, then we will have already called
5214 globalize_decl to remove the entry; in that case, we do
5215 not need to do anything. */
5218 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5219 mark_weak (olddecl);
5222 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5223 weak. Just update NEWDECL to indicate that it's weak too. */
5224 mark_weak (newdecl);
5227 /* Declare DECL to be a weak symbol. */
5230 declare_weak (tree decl)
5232 gcc_assert (TREE_CODE (decl) != FUNCTION_DECL || !TREE_ASM_WRITTEN (decl));
5233 if (! TREE_PUBLIC (decl))
5234 error ("weak declaration of %q+D must be public", decl);
5235 else if (!TARGET_SUPPORTS_WEAK)
5236 warning (0, "weak declaration of %q+D not supported", decl);
5239 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5240 DECL_ATTRIBUTES (decl)
5241 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5245 weak_finish_1 (tree decl)
5247 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5248 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5251 if (! TREE_USED (decl))
5254 #ifdef ASM_WEAKEN_DECL
5255 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5257 #ifdef ASM_WEAKEN_LABEL
5258 ASM_WEAKEN_LABEL (asm_out_file, name);
5260 #ifdef ASM_OUTPUT_WEAK_ALIAS
5262 static bool warn_once = 0;
5265 warning (0, "only weak aliases are supported in this configuration");
5275 /* This TREE_LIST contains weakref targets. */
5277 static GTY(()) tree weakref_targets;
5279 /* Forward declaration. */
5280 static tree find_decl_and_mark_needed (tree decl, tree target);
5282 /* Emit any pending weak declarations. */
5289 for (t = weakref_targets; t; t = TREE_CHAIN (t))
5291 tree alias_decl = TREE_PURPOSE (t);
5292 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5294 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5295 /* Remove alias_decl from the weak list, but leave entries for
5296 the target alone. */
5298 #ifndef ASM_OUTPUT_WEAKREF
5299 else if (! TREE_SYMBOL_REFERENCED (target))
5301 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5302 defined, otherwise we and weak_finish_1 would use
5303 different macros. */
5304 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5305 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5307 tree decl = find_decl_and_mark_needed (alias_decl, target);
5311 decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5312 TREE_CODE (alias_decl), target,
5313 TREE_TYPE (alias_decl));
5315 DECL_EXTERNAL (decl) = 1;
5316 TREE_PUBLIC (decl) = 1;
5317 DECL_ARTIFICIAL (decl) = 1;
5318 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5319 TREE_USED (decl) = 1;
5322 weak_finish_1 (decl);
5331 /* Remove the alias and the target from the pending weak list
5332 so that we do not emit any .weak directives for the former,
5333 nor multiple .weak directives for the latter. */
5334 for (p = &weak_decls; (t2 = *p) ; )
5336 if (TREE_VALUE (t2) == alias_decl
5337 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5338 *p = TREE_CHAIN (t2);
5340 p = &TREE_CHAIN (t2);
5343 /* Remove other weakrefs to the same target, to speed things up. */
5344 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5346 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5347 *p = TREE_CHAIN (t2);
5349 p = &TREE_CHAIN (t2);
5354 for (t = weak_decls; t; t = TREE_CHAIN (t))
5356 tree decl = TREE_VALUE (t);
5358 weak_finish_1 (decl);
5362 /* Emit the assembly bits to indicate that DECL is globally visible. */
5365 globalize_decl (tree decl)
5368 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5369 if (DECL_WEAK (decl))
5371 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5374 #ifdef ASM_WEAKEN_DECL
5375 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5377 ASM_WEAKEN_LABEL (asm_out_file, name);
5380 /* Remove this function from the pending weak list so that
5381 we do not emit multiple .weak directives for it. */
5382 for (p = &weak_decls; (t = *p) ; )
5384 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5385 *p = TREE_CHAIN (t);
5387 p = &TREE_CHAIN (t);
5390 /* Remove weakrefs to the same target from the pending weakref
5391 list, for the same reason. */
5392 for (p = &weakref_targets; (t = *p) ; )
5394 if (DECL_ASSEMBLER_NAME (decl)
5395 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5396 *p = TREE_CHAIN (t);
5398 p = &TREE_CHAIN (t);
5405 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5408 VEC(alias_pair,gc) *alias_pairs;
5410 /* Given an assembly name, find the decl it is associated with. At the
5411 same time, mark it needed for cgraph. */
5414 find_decl_and_mark_needed (tree decl, tree target)
5416 struct cgraph_node *fnode = NULL;
5417 struct varpool_node *vnode = NULL;
5419 if (TREE_CODE (decl) == FUNCTION_DECL)
5421 fnode = cgraph_node_for_asm (target);
5423 vnode = varpool_node_for_asm (target);
5427 vnode = varpool_node_for_asm (target);
5429 fnode = cgraph_node_for_asm (target);
5434 cgraph_mark_needed_node (fnode);
5439 varpool_mark_needed_node (vnode);
5440 vnode->force_output = 1;
5447 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5448 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5449 tree node is DECL to have the value of the tree node TARGET. */
5452 do_assemble_alias (tree decl, tree target)
5454 /* Emulated TLS had better not get this var. */
5455 gcc_assert(!(!targetm.have_tls
5456 && TREE_CODE (decl) == VAR_DECL
5457 && DECL_THREAD_LOCAL_P (decl)));
5459 if (TREE_ASM_WRITTEN (decl))
5462 /* We must force creation of DECL_RTL for debug info generation, even though
5463 we don't use it here. */
5464 make_decl_rtl (decl);
5466 TREE_ASM_WRITTEN (decl) = 1;
5467 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5469 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5471 ultimate_transparent_alias_target (&target);
5473 if (!TREE_SYMBOL_REFERENCED (target))
5474 weakref_targets = tree_cons (decl, target, weakref_targets);
5476 #ifdef ASM_OUTPUT_WEAKREF
5477 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5478 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5479 IDENTIFIER_POINTER (target));
5481 if (!TARGET_SUPPORTS_WEAK)
5483 error_at (DECL_SOURCE_LOCATION (decl),
5484 "weakref is not supported in this configuration");
5491 #ifdef ASM_OUTPUT_DEF
5492 /* Make name accessible from other files, if appropriate. */
5494 if (TREE_PUBLIC (decl))
5496 globalize_decl (decl);
5497 maybe_assemble_visibility (decl);
5499 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
5501 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
5502 ASM_OUTPUT_TYPE_DIRECTIVE
5503 (asm_out_file, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5506 error_at (DECL_SOURCE_LOCATION (decl),
5507 "ifunc is not supported in this configuration");
5511 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5512 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5514 ASM_OUTPUT_DEF (asm_out_file,
5515 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5516 IDENTIFIER_POINTER (target));
5518 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5523 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5524 # ifdef ASM_WEAKEN_DECL
5525 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5527 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5529 /* Remove this function from the pending weak list so that
5530 we do not emit multiple .weak directives for it. */
5531 for (p = &weak_decls; (t = *p) ; )
5532 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5533 *p = TREE_CHAIN (t);
5535 p = &TREE_CHAIN (t);
5537 /* Remove weakrefs to the same target from the pending weakref
5538 list, for the same reason. */
5539 for (p = &weakref_targets; (t = *p) ; )
5541 if (DECL_ASSEMBLER_NAME (decl)
5542 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5543 *p = TREE_CHAIN (t);
5545 p = &TREE_CHAIN (t);
5552 /* Allocate and construct a symbol alias set. */
5554 static symbol_alias_set_t *
5555 symbol_alias_set_create (void)
5557 return pointer_set_create ();
5560 /* Destruct and free a symbol alias set. */
5563 symbol_alias_set_destroy (symbol_alias_set_t *aset)
5565 pointer_set_destroy (aset);
5568 /* Test if a symbol alias set contains a given name. */
5571 symbol_alias_set_contains (const symbol_alias_set_t *aset, tree t)
5573 /* We accept either a DECL or an IDENTIFIER directly. */
5574 if (TREE_CODE (t) != IDENTIFIER_NODE)
5575 t = DECL_ASSEMBLER_NAME (t);
5576 t = targetm.asm_out.mangle_assembler_name (IDENTIFIER_POINTER (t));
5577 return pointer_set_contains (aset, t);
5580 /* Enter a new name into a symbol alias set. */
5583 symbol_alias_set_insert (symbol_alias_set_t *aset, tree t)
5585 /* We accept either a DECL or an IDENTIFIER directly. */
5586 if (TREE_CODE (t) != IDENTIFIER_NODE)
5587 t = DECL_ASSEMBLER_NAME (t);
5588 t = targetm.asm_out.mangle_assembler_name (IDENTIFIER_POINTER (t));
5589 return pointer_set_insert (aset, t);
5592 /* IN_SET_P is a predicate function assuming to be taken
5593 alias_pair->decl, alias_pair->target and DATA arguments.
5595 Compute set of aliases by including everything where TRIVIALLY_VISIBLE
5596 predeicate is true and propagate across aliases such that when
5597 alias DECL is included, its TARGET is included too. */
5599 static symbol_alias_set_t *
5600 propagate_aliases_forward (bool (*in_set_p)
5601 (tree decl, tree target, void *data),
5604 symbol_alias_set_t *set;
5609 set = symbol_alias_set_create ();
5610 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); ++i)
5611 if (in_set_p (p->decl, p->target, data))
5612 symbol_alias_set_insert (set, p->decl);
5616 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); ++i)
5617 if (symbol_alias_set_contains (set, p->decl)
5618 && !symbol_alias_set_insert (set, p->target))
5626 /* Like propagate_aliases_forward but do backward propagation. */
5628 symbol_alias_set_t *
5629 propagate_aliases_backward (bool (*in_set_p)
5630 (tree decl, tree target, void *data),
5633 symbol_alias_set_t *set;
5638 /* We have to compute the set of set nodes including aliases
5640 set = symbol_alias_set_create ();
5641 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); ++i)
5642 if (in_set_p (p->decl, p->target, data))
5643 symbol_alias_set_insert (set, p->target);
5647 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); ++i)
5648 if (symbol_alias_set_contains (set, p->target)
5649 && !symbol_alias_set_insert (set, p->decl))
5656 /* See if the alias is trivially visible. This means
5657 1) alias is expoerted from the unit or
5658 2) alias is used in the code.
5659 We assume that unused cgraph/varpool nodes has been
5661 Used as callback for propagate_aliases. */
5664 trivially_visible_alias (tree decl, tree target ATTRIBUTE_UNUSED,
5665 void *data ATTRIBUTE_UNUSED)
5667 struct cgraph_node *fnode = NULL;
5668 struct varpool_node *vnode = NULL;
5670 if (!TREE_PUBLIC (decl))
5672 if (TREE_CODE (decl) == FUNCTION_DECL)
5673 fnode = cgraph_get_node (decl);
5675 vnode = varpool_get_node (decl);
5676 return vnode || fnode;
5682 /* See if the target of alias is defined in this unit.
5683 Used as callback for propagate_aliases. */
5686 trivially_defined_alias (tree decl ATTRIBUTE_UNUSED,
5688 void *data ATTRIBUTE_UNUSED)
5690 struct cgraph_node *fnode = NULL;
5691 struct varpool_node *vnode = NULL;
5693 fnode = cgraph_node_for_asm (target);
5694 vnode = (fnode == NULL) ? varpool_node_for_asm (target) : NULL;
5695 return (fnode && fnode->analyzed) || (vnode && vnode->finalized);
5698 /* Remove the alias pairing for functions that are no longer in the call
5702 remove_unreachable_alias_pairs (void)
5704 symbol_alias_set_t *visible;
5708 if (alias_pairs == NULL)
5711 /* We have to compute the set of visible nodes including aliases
5713 visible = propagate_aliases_forward (trivially_visible_alias, NULL);
5715 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5717 if (!DECL_EXTERNAL (p->decl)
5718 && !symbol_alias_set_contains (visible, p->decl))
5720 VEC_unordered_remove (alias_pair, alias_pairs, i);
5727 symbol_alias_set_destroy (visible);
5731 /* First pass of completing pending aliases. Make sure that cgraph knows
5732 which symbols will be required. */
5735 finish_aliases_1 (void)
5737 symbol_alias_set_t *defined;
5741 if (alias_pairs == NULL)
5744 /* We have to compute the set of defined nodes including aliases
5746 defined = propagate_aliases_backward (trivially_defined_alias, NULL);
5748 FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
5752 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5753 if (target_decl == NULL)
5755 if (symbol_alias_set_contains (defined, p->target))
5758 if (! (p->emitted_diags & ALIAS_DIAG_TO_UNDEF)
5759 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5761 error ("%q+D aliased to undefined symbol %qE",
5762 p->decl, p->target);
5763 p->emitted_diags |= ALIAS_DIAG_TO_UNDEF;
5766 else if (! (p->emitted_diags & ALIAS_DIAG_TO_EXTERN)
5767 && DECL_EXTERNAL (target_decl)
5768 /* We use local aliases for C++ thunks to force the tailcall
5769 to bind locally. This is a hack - to keep it working do
5770 the following (which is not strictly correct). */
5771 && (! TREE_CODE (target_decl) == FUNCTION_DECL
5772 || ! DECL_VIRTUAL_P (target_decl))
5773 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5775 error ("%q+D aliased to external symbol %qE",
5776 p->decl, p->target);
5777 p->emitted_diags |= ALIAS_DIAG_TO_EXTERN;
5781 symbol_alias_set_destroy (defined);
5784 /* Second pass of completing pending aliases. Emit the actual assembly.
5785 This happens at the end of compilation and thus it is assured that the
5786 target symbol has been emitted. */
5789 finish_aliases_2 (void)
5794 FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
5795 do_assemble_alias (p->decl, p->target);
5797 VEC_truncate (alias_pair, alias_pairs, 0);
5800 /* Emit an assembler directive to make the symbol for DECL an alias to
5801 the symbol for TARGET. */
5804 assemble_alias (tree decl, tree target)
5808 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5810 tree alias = DECL_ASSEMBLER_NAME (decl);
5812 ultimate_transparent_alias_target (&target);
5814 if (alias == target)
5815 error ("weakref %q+D ultimately targets itself", decl);
5818 #ifndef ASM_OUTPUT_WEAKREF
5819 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5820 TREE_CHAIN (alias) = target;
5823 if (TREE_PUBLIC (decl))
5824 error ("weakref %q+D must have static linkage", decl);
5828 #if !defined (ASM_OUTPUT_DEF)
5829 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5830 error_at (DECL_SOURCE_LOCATION (decl),
5831 "alias definitions not supported in this configuration");
5834 if (!DECL_WEAK (decl))
5836 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
5837 error_at (DECL_SOURCE_LOCATION (decl),
5838 "ifunc is not supported in this configuration");
5840 error_at (DECL_SOURCE_LOCATION (decl),
5841 "only weak aliases are supported in this configuration");
5847 TREE_USED (decl) = 1;
5849 /* Allow aliases to aliases. */
5850 if (TREE_CODE (decl) == FUNCTION_DECL)
5851 cgraph_get_create_node (decl)->alias = true;
5853 varpool_node (decl)->alias = true;
5855 /* If the target has already been emitted, we don't have to queue the
5856 alias. This saves a tad of memory. */
5857 if (cgraph_global_info_ready)
5858 target_decl = find_decl_and_mark_needed (decl, target);
5861 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5862 do_assemble_alias (decl, target);
5865 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5868 p->emitted_diags = ALIAS_DIAG_NONE;
5872 /* Record and output a table of translations from original function
5873 to its transaction aware clone. Note that tm_pure functions are
5874 considered to be their own clone. */
5876 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
5877 htab_t tm_clone_hash;
5880 record_tm_clone_pair (tree o, tree n)
5882 struct tree_map **slot, *h;
5884 if (tm_clone_hash == NULL)
5885 tm_clone_hash = htab_create_ggc (32, tree_map_hash, tree_map_eq, 0);
5887 h = ggc_alloc_tree_map ();
5888 h->hash = htab_hash_pointer (o);
5892 slot = (struct tree_map **)
5893 htab_find_slot_with_hash (tm_clone_hash, h, h->hash, INSERT);
5898 get_tm_clone_pair (tree o)
5902 struct tree_map *h, in;
5905 in.hash = htab_hash_pointer (o);
5906 h = (struct tree_map *) htab_find_with_hash (tm_clone_hash,
5914 typedef struct tm_alias_pair
5921 DEF_VEC_O(tm_alias_pair);
5922 DEF_VEC_ALLOC_O(tm_alias_pair,heap);
5924 /* Helper function for finish_tm_clone_pairs. Dump a hash table entry
5925 into a VEC in INFO. */
5928 dump_tm_clone_to_vec (void **slot, void *info)
5930 struct tree_map *map = (struct tree_map *) *slot;
5931 VEC(tm_alias_pair,heap) **tm_alias_pairs
5932 = (VEC(tm_alias_pair, heap) **) info;
5935 p = VEC_safe_push (tm_alias_pair, heap, *tm_alias_pairs, NULL);
5936 p->from = map->base.from;
5938 p->uid = DECL_UID (p->from);
5942 /* Dump the actual pairs to the .tm_clone_table section. */
5945 dump_tm_clone_pairs (VEC(tm_alias_pair,heap) *tm_alias_pairs)
5949 bool switched = false;
5951 FOR_EACH_VEC_ELT (tm_alias_pair, tm_alias_pairs, i, p)
5955 struct cgraph_node *src_n = cgraph_get_node (src);
5956 struct cgraph_node *dst_n = cgraph_get_node (dst);
5958 /* The function ipa_tm_create_version() marks the clone as needed if
5959 the original function was needed. But we also mark the clone as
5960 needed if we ever called the clone indirectly through
5961 TM_GETTMCLONE. If neither of these are true, we didn't generate
5962 a clone, and we didn't call it indirectly... no sense keeping it
5963 in the clone table. */
5964 if (!dst_n || !dst_n->needed)
5967 /* This covers the case where we have optimized the original
5968 function away, and only access the transactional clone. */
5969 if (!src_n || !src_n->needed)
5974 switch_to_section (targetm.asm_out.tm_clone_table_section ());
5975 assemble_align (POINTER_SIZE);
5979 assemble_integer (XEXP (DECL_RTL (src), 0),
5980 POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
5981 assemble_integer (XEXP (DECL_RTL (dst), 0),
5982 POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
5986 /* Provide a default for the tm_clone_table section. */
5989 default_clone_table_section (void)
5991 return get_named_section (NULL, ".tm_clone_table", 3);
5994 /* Helper comparison function for qsorting by the DECL_UID stored in
5995 alias_pair->emitted_diags. */
5998 tm_alias_pair_cmp (const void *x, const void *y)
6000 const tm_alias_pair *p1 = (const tm_alias_pair *) x;
6001 const tm_alias_pair *p2 = (const tm_alias_pair *) y;
6002 if (p1->uid < p2->uid)
6004 if (p1->uid > p2->uid)
6010 finish_tm_clone_pairs (void)
6012 VEC(tm_alias_pair,heap) *tm_alias_pairs = NULL;
6014 if (tm_clone_hash == NULL)
6017 /* We need a determenistic order for the .tm_clone_table, otherwise
6018 we will get bootstrap comparison failures, so dump the hash table
6019 to a vector, sort it, and dump the vector. */
6021 /* Dump the hashtable to a vector. */
6022 htab_traverse_noresize (tm_clone_hash, dump_tm_clone_to_vec,
6023 (void *) &tm_alias_pairs);
6025 VEC_qsort (tm_alias_pair, tm_alias_pairs, tm_alias_pair_cmp);
6028 dump_tm_clone_pairs (tm_alias_pairs);
6030 htab_delete (tm_clone_hash);
6031 tm_clone_hash = NULL;
6032 VEC_free (tm_alias_pair, heap, tm_alias_pairs);
6036 /* Emit an assembler directive to set symbol for DECL visibility to
6037 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
6040 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
6041 int vis ATTRIBUTE_UNUSED)
6043 #ifdef HAVE_GAS_HIDDEN
6044 static const char * const visibility_types[] = {
6045 NULL, "protected", "hidden", "internal"
6048 const char *name, *type;
6050 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6051 type = visibility_types[vis];
6053 fprintf (asm_out_file, "\t.%s\t", type);
6054 assemble_name (asm_out_file, name);
6055 fprintf (asm_out_file, "\n");
6057 warning (OPT_Wattributes, "visibility attribute not supported "
6058 "in this configuration; ignored");
6062 /* A helper function to call assemble_visibility when needed for a decl. */
6065 maybe_assemble_visibility (tree decl)
6067 enum symbol_visibility vis = DECL_VISIBILITY (decl);
6069 if (vis != VISIBILITY_DEFAULT)
6071 targetm.asm_out.assemble_visibility (decl, vis);
6078 /* Returns 1 if the target configuration supports defining public symbols
6079 so that one of them will be chosen at link time instead of generating a
6080 multiply-defined symbol error, whether through the use of weak symbols or
6081 a target-specific mechanism for having duplicates discarded. */
6084 supports_one_only (void)
6086 if (SUPPORTS_ONE_ONLY)
6088 return TARGET_SUPPORTS_WEAK;
6091 /* Set up DECL as a public symbol that can be defined in multiple
6092 translation units without generating a linker error. */
6095 make_decl_one_only (tree decl, tree comdat_group)
6097 gcc_assert (TREE_CODE (decl) == VAR_DECL
6098 || TREE_CODE (decl) == FUNCTION_DECL);
6100 TREE_PUBLIC (decl) = 1;
6102 if (SUPPORTS_ONE_ONLY)
6104 #ifdef MAKE_DECL_ONE_ONLY
6105 MAKE_DECL_ONE_ONLY (decl);
6107 DECL_COMDAT_GROUP (decl) = comdat_group;
6109 else if (TREE_CODE (decl) == VAR_DECL
6110 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
6111 DECL_COMMON (decl) = 1;
6114 gcc_assert (TARGET_SUPPORTS_WEAK);
6115 DECL_WEAK (decl) = 1;
6120 init_varasm_once (void)
6122 section_htab = htab_create_ggc (31, section_entry_hash,
6123 section_entry_eq, NULL);
6124 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
6125 object_block_entry_eq, NULL);
6126 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
6127 const_desc_eq, NULL);
6129 const_alias_set = new_alias_set ();
6130 shared_constant_pool = create_constant_pool ();
6132 #ifdef TEXT_SECTION_ASM_OP
6133 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
6134 TEXT_SECTION_ASM_OP);
6137 #ifdef DATA_SECTION_ASM_OP
6138 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6139 DATA_SECTION_ASM_OP);
6142 #ifdef SDATA_SECTION_ASM_OP
6143 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6144 SDATA_SECTION_ASM_OP);
6147 #ifdef READONLY_DATA_SECTION_ASM_OP
6148 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
6149 READONLY_DATA_SECTION_ASM_OP);
6152 #ifdef CTORS_SECTION_ASM_OP
6153 ctors_section = get_unnamed_section (0, output_section_asm_op,
6154 CTORS_SECTION_ASM_OP);
6157 #ifdef DTORS_SECTION_ASM_OP
6158 dtors_section = get_unnamed_section (0, output_section_asm_op,
6159 DTORS_SECTION_ASM_OP);
6162 #ifdef BSS_SECTION_ASM_OP
6163 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6164 output_section_asm_op,
6165 BSS_SECTION_ASM_OP);
6168 #ifdef SBSS_SECTION_ASM_OP
6169 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6170 output_section_asm_op,
6171 SBSS_SECTION_ASM_OP);
6174 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6175 | SECTION_COMMON, emit_tls_common);
6176 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6177 | SECTION_COMMON, emit_local);
6178 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6179 | SECTION_COMMON, emit_common);
6181 #if defined ASM_OUTPUT_ALIGNED_BSS
6182 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
6186 targetm.asm_out.init_sections ();
6188 if (readonly_data_section == NULL)
6189 readonly_data_section = text_section;
6191 #ifdef ASM_OUTPUT_EXTERNAL
6192 pending_assemble_externals_set = pointer_set_create ();
6197 decl_default_tls_model (const_tree decl)
6199 enum tls_model kind;
6202 is_local = targetm.binds_local_p (decl);
6206 kind = TLS_MODEL_LOCAL_EXEC;
6208 kind = TLS_MODEL_INITIAL_EXEC;
6211 /* Local dynamic is inefficient when we're not combining the
6212 parts of the address. */
6213 else if (optimize && is_local)
6214 kind = TLS_MODEL_LOCAL_DYNAMIC;
6216 kind = TLS_MODEL_GLOBAL_DYNAMIC;
6217 if (kind < flag_tls_default)
6218 kind = flag_tls_default;
6223 /* Select a set of attributes for section NAME based on the properties
6224 of DECL and whether or not RELOC indicates that DECL's initializer
6225 might contain runtime relocations.
6227 We make the section read-only and executable for a function decl,
6228 read-only for a const data decl, and writable for a non-const data decl. */
6231 default_section_type_flags (tree decl, const char *name, int reloc)
6235 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
6236 flags = SECTION_CODE;
6239 enum section_category category
6240 = categorize_decl_for_section (decl, reloc);
6241 if (decl_readonly_section_1 (category))
6243 else if (category == SECCAT_DATA_REL_RO
6244 || category == SECCAT_DATA_REL_RO_LOCAL)
6245 flags = SECTION_WRITE | SECTION_RELRO;
6247 flags = SECTION_WRITE;
6251 flags = SECTION_WRITE;
6252 if (strcmp (name, ".data.rel.ro") == 0
6253 || strcmp (name, ".data.rel.ro.local") == 0)
6254 flags |= SECTION_RELRO;
6257 if (decl && DECL_ONE_ONLY (decl))
6258 flags |= SECTION_LINKONCE;
6260 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6261 flags |= SECTION_TLS | SECTION_WRITE;
6263 if (strcmp (name, ".bss") == 0
6264 || strncmp (name, ".bss.", 5) == 0
6265 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
6266 || strcmp (name, ".sbss") == 0
6267 || strncmp (name, ".sbss.", 6) == 0
6268 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
6269 flags |= SECTION_BSS;
6271 if (strcmp (name, ".tdata") == 0
6272 || strncmp (name, ".tdata.", 7) == 0
6273 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
6274 flags |= SECTION_TLS;
6276 if (strcmp (name, ".tbss") == 0
6277 || strncmp (name, ".tbss.", 6) == 0
6278 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
6279 flags |= SECTION_TLS | SECTION_BSS;
6281 /* These three sections have special ELF types. They are neither
6282 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6283 want to print a section type (@progbits or @nobits). If someone
6284 is silly enough to emit code or TLS variables to one of these
6285 sections, then don't handle them specially. */
6286 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
6287 && (strcmp (name, ".init_array") == 0
6288 || strcmp (name, ".fini_array") == 0
6289 || strcmp (name, ".preinit_array") == 0))
6290 flags |= SECTION_NOTYPE;
6295 /* Return true if the target supports some form of global BSS,
6296 either through bss_noswitch_section, or by selecting a BSS
6297 section in TARGET_ASM_SELECT_SECTION. */
6300 have_global_bss_p (void)
6302 return bss_noswitch_section || targetm.have_switchable_bss_sections;
6305 /* Output assembly to switch to section NAME with attribute FLAGS.
6306 Four variants for common object file formats. */
6309 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
6310 unsigned int flags ATTRIBUTE_UNUSED,
6311 tree decl ATTRIBUTE_UNUSED)
6313 /* Some object formats don't support named sections at all. The
6314 front-end should already have flagged this as an error. */
6318 #ifndef TLS_SECTION_ASM_FLAG
6319 #define TLS_SECTION_ASM_FLAG 'T'
6323 default_elf_asm_named_section (const char *name, unsigned int flags,
6324 tree decl ATTRIBUTE_UNUSED)
6326 char flagchars[10], *f = flagchars;
6328 /* If we have already declared this section, we can use an
6329 abbreviated form to switch back to it -- unless this section is
6330 part of a COMDAT groups, in which case GAS requires the full
6331 declaration every time. */
6332 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6333 && (flags & SECTION_DECLARED))
6335 fprintf (asm_out_file, "\t.section\t%s\n", name);
6339 if (!(flags & SECTION_DEBUG))
6341 if (flags & SECTION_EXCLUDE)
6343 if (flags & SECTION_WRITE)
6345 if (flags & SECTION_CODE)
6347 if (flags & SECTION_SMALL)
6349 if (flags & SECTION_MERGE)
6351 if (flags & SECTION_STRINGS)
6353 if (flags & SECTION_TLS)
6354 *f++ = TLS_SECTION_ASM_FLAG;
6355 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6359 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
6361 if (!(flags & SECTION_NOTYPE))
6366 if (flags & SECTION_BSS)
6372 /* On platforms that use "@" as the assembly comment character,
6374 if (strcmp (ASM_COMMENT_START, "@") == 0)
6376 fprintf (asm_out_file, format, type);
6378 if (flags & SECTION_ENTSIZE)
6379 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
6380 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6382 if (TREE_CODE (decl) == IDENTIFIER_NODE)
6383 fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
6385 fprintf (asm_out_file, ",%s,comdat",
6386 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
6390 putc ('\n', asm_out_file);
6394 default_coff_asm_named_section (const char *name, unsigned int flags,
6395 tree decl ATTRIBUTE_UNUSED)
6397 char flagchars[8], *f = flagchars;
6399 if (flags & SECTION_WRITE)
6401 if (flags & SECTION_CODE)
6405 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
6409 default_pe_asm_named_section (const char *name, unsigned int flags,
6412 default_coff_asm_named_section (name, flags, decl);
6414 if (flags & SECTION_LINKONCE)
6416 /* Functions may have been compiled at various levels of
6417 optimization so we can't use `same_size' here.
6418 Instead, have the linker pick one. */
6419 fprintf (asm_out_file, "\t.linkonce %s\n",
6420 (flags & SECTION_CODE ? "discard" : "same_size"));
6424 /* The lame default section selector. */
6427 default_select_section (tree decl, int reloc,
6428 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6432 if (decl_readonly_section (decl, reloc))
6433 return readonly_data_section;
6435 else if (TREE_CODE (decl) == CONSTRUCTOR)
6437 if (! ((flag_pic && reloc)
6438 || !TREE_READONLY (decl)
6439 || TREE_SIDE_EFFECTS (decl)
6440 || !TREE_CONSTANT (decl)))
6441 return readonly_data_section;
6443 else if (TREE_CODE (decl) == STRING_CST)
6444 return readonly_data_section;
6445 else if (! (flag_pic && reloc))
6446 return readonly_data_section;
6448 return data_section;
6451 enum section_category
6452 categorize_decl_for_section (const_tree decl, int reloc)
6454 enum section_category ret;
6456 if (TREE_CODE (decl) == FUNCTION_DECL)
6458 else if (TREE_CODE (decl) == STRING_CST)
6460 if (flag_mudflap) /* or !flag_merge_constants */
6461 return SECCAT_RODATA;
6463 return SECCAT_RODATA_MERGE_STR;
6465 else if (TREE_CODE (decl) == VAR_DECL)
6467 if (bss_initializer_p (decl))
6469 else if (! TREE_READONLY (decl)
6470 || TREE_SIDE_EFFECTS (decl)
6471 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6473 /* Here the reloc_rw_mask is not testing whether the section should
6474 be read-only or not, but whether the dynamic link will have to
6475 do something. If so, we wish to segregate the data in order to
6476 minimize cache misses inside the dynamic linker. */
6477 if (reloc & targetm.asm_out.reloc_rw_mask ())
6478 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6482 else if (reloc & targetm.asm_out.reloc_rw_mask ())
6483 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6484 else if (reloc || flag_merge_constants < 2)
6485 /* C and C++ don't allow different variables to share the same
6486 location. -fmerge-all-constants allows even that (at the
6487 expense of not conforming). */
6488 ret = SECCAT_RODATA;
6489 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6490 ret = SECCAT_RODATA_MERGE_STR_INIT;
6492 ret = SECCAT_RODATA_MERGE_CONST;
6494 else if (TREE_CODE (decl) == CONSTRUCTOR)
6496 if ((reloc & targetm.asm_out.reloc_rw_mask ())
6497 || TREE_SIDE_EFFECTS (decl)
6498 || ! TREE_CONSTANT (decl))
6501 ret = SECCAT_RODATA;
6504 ret = SECCAT_RODATA;
6506 /* There are no read-only thread-local sections. */
6507 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6509 /* Note that this would be *just* SECCAT_BSS, except that there's
6510 no concept of a read-only thread-local-data section. */
6511 if (ret == SECCAT_BSS
6512 || (flag_zero_initialized_in_bss
6513 && initializer_zerop (DECL_INITIAL (decl))))
6519 /* If the target uses small data sections, select it. */
6520 else if (targetm.in_small_data_p (decl))
6522 if (ret == SECCAT_BSS)
6524 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6525 ret = SECCAT_SRODATA;
6534 decl_readonly_section_1 (enum section_category category)
6539 case SECCAT_RODATA_MERGE_STR:
6540 case SECCAT_RODATA_MERGE_STR_INIT:
6541 case SECCAT_RODATA_MERGE_CONST:
6542 case SECCAT_SRODATA:
6550 decl_readonly_section (const_tree decl, int reloc)
6552 return decl_readonly_section_1 (categorize_decl_for_section (decl, reloc));
6555 /* Select a section based on the above categorization. */
6558 default_elf_select_section (tree decl, int reloc,
6559 unsigned HOST_WIDE_INT align)
6562 switch (categorize_decl_for_section (decl, reloc))
6565 /* We're not supposed to be called on FUNCTION_DECLs. */
6568 return readonly_data_section;
6569 case SECCAT_RODATA_MERGE_STR:
6570 return mergeable_string_section (decl, align, 0);
6571 case SECCAT_RODATA_MERGE_STR_INIT:
6572 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6573 case SECCAT_RODATA_MERGE_CONST:
6574 return mergeable_constant_section (DECL_MODE (decl), align, 0);
6575 case SECCAT_SRODATA:
6579 return data_section;
6580 case SECCAT_DATA_REL:
6581 sname = ".data.rel";
6583 case SECCAT_DATA_REL_LOCAL:
6584 sname = ".data.rel.local";
6586 case SECCAT_DATA_REL_RO:
6587 sname = ".data.rel.ro";
6589 case SECCAT_DATA_REL_RO_LOCAL:
6590 sname = ".data.rel.ro.local";
6615 return get_named_section (decl, sname, reloc);
6618 /* Construct a unique section name based on the decl name and the
6619 categorization performed above. */
6622 default_unique_section (tree decl, int reloc)
6624 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6625 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6626 const char *prefix, *name, *linkonce;
6629 switch (categorize_decl_for_section (decl, reloc))
6632 prefix = one_only ? ".t" : ".text";
6635 case SECCAT_RODATA_MERGE_STR:
6636 case SECCAT_RODATA_MERGE_STR_INIT:
6637 case SECCAT_RODATA_MERGE_CONST:
6638 prefix = one_only ? ".r" : ".rodata";
6640 case SECCAT_SRODATA:
6641 prefix = one_only ? ".s2" : ".sdata2";
6644 prefix = one_only ? ".d" : ".data";
6646 case SECCAT_DATA_REL:
6647 prefix = one_only ? ".d.rel" : ".data.rel";
6649 case SECCAT_DATA_REL_LOCAL:
6650 prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6652 case SECCAT_DATA_REL_RO:
6653 prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6655 case SECCAT_DATA_REL_RO_LOCAL:
6656 prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6659 prefix = one_only ? ".s" : ".sdata";
6662 prefix = one_only ? ".b" : ".bss";
6665 prefix = one_only ? ".sb" : ".sbss";
6668 prefix = one_only ? ".td" : ".tdata";
6671 prefix = one_only ? ".tb" : ".tbss";
6677 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6678 name = targetm.strip_name_encoding (name);
6680 /* If we're using one_only, then there needs to be a .gnu.linkonce
6681 prefix to the section name. */
6682 linkonce = one_only ? ".gnu.linkonce" : "";
6684 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6686 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6689 /* Like compute_reloc_for_constant, except for an RTX. The return value
6690 is a mask for which bit 1 indicates a global relocation, and bit 0
6691 indicates a local relocation. */
6694 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6696 int *preloc = (int *) data;
6699 switch (GET_CODE (x))
6702 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6715 compute_reloc_for_rtx (rtx x)
6719 switch (GET_CODE (x))
6725 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6734 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6736 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6738 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6739 return data_section;
6741 return readonly_data_section;
6745 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6746 unsigned HOST_WIDE_INT align)
6748 int reloc = compute_reloc_for_rtx (x);
6750 /* ??? Handle small data here somehow. */
6752 if (reloc & targetm.asm_out.reloc_rw_mask ())
6755 return get_named_section (NULL, ".data.rel.ro.local", 1);
6757 return get_named_section (NULL, ".data.rel.ro", 3);
6760 return mergeable_constant_section (mode, align, 0);
6763 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6766 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6771 /* Careful not to prod global register variables. */
6774 symbol = XEXP (rtl, 0);
6775 if (GET_CODE (symbol) != SYMBOL_REF)
6778 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6779 if (TREE_CODE (decl) == FUNCTION_DECL)
6780 flags |= SYMBOL_FLAG_FUNCTION;
6781 if (targetm.binds_local_p (decl))
6782 flags |= SYMBOL_FLAG_LOCAL;
6783 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6784 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6785 else if (targetm.in_small_data_p (decl))
6786 flags |= SYMBOL_FLAG_SMALL;
6787 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6788 being PUBLIC, the thing *must* be defined in this translation unit.
6789 Prevent this buglet from being propagated into rtl code as well. */
6790 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6791 flags |= SYMBOL_FLAG_EXTERNAL;
6793 SYMBOL_REF_FLAGS (symbol) = flags;
6796 /* By default, we do nothing for encode_section_info, so we need not
6797 do anything but discard the '*' marker. */
6800 default_strip_name_encoding (const char *str)
6802 return str + (*str == '*');
6805 #ifdef ASM_OUTPUT_DEF
6806 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6807 anchor relative to ".", the current section position. */
6810 default_asm_output_anchor (rtx symbol)
6814 sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6815 SYMBOL_REF_BLOCK_OFFSET (symbol));
6816 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6820 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6823 default_use_anchors_for_symbol_p (const_rtx symbol)
6828 /* Don't use anchors for mergeable sections. The linker might move
6829 the objects around. */
6830 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6831 if (sect->common.flags & SECTION_MERGE)
6834 /* Don't use anchors for small data sections. The small data register
6835 acts as an anchor for such sections. */
6836 if (sect->common.flags & SECTION_SMALL)
6839 decl = SYMBOL_REF_DECL (symbol);
6840 if (decl && DECL_P (decl))
6842 /* Don't use section anchors for decls that might be defined by
6844 if (!targetm.binds_local_p (decl))
6847 /* Don't use section anchors for decls that will be placed in a
6848 small data section. */
6849 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6850 one above. The problem is that we only use SECTION_SMALL for
6851 sections that should be marked as small in the section directive. */
6852 if (targetm.in_small_data_p (decl))
6858 /* Return true when RESOLUTION indicate that symbol will be bound to the
6859 definition provided by current .o file. */
6862 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution)
6864 return (resolution == LDPR_PREVAILING_DEF
6865 || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
6866 || resolution == LDPR_PREVAILING_DEF_IRONLY);
6869 /* Return true when RESOLUTION indicate that symbol will be bound locally
6870 within current executable or DSO. */
6873 resolution_local_p (enum ld_plugin_symbol_resolution resolution)
6875 return (resolution == LDPR_PREVAILING_DEF
6876 || resolution == LDPR_PREVAILING_DEF_IRONLY
6877 || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
6878 || resolution == LDPR_PREEMPTED_REG
6879 || resolution == LDPR_PREEMPTED_IR
6880 || resolution == LDPR_RESOLVED_IR
6881 || resolution == LDPR_RESOLVED_EXEC);
6884 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6885 wrt cross-module name binding. */
6888 default_binds_local_p (const_tree exp)
6890 return default_binds_local_p_1 (exp, flag_shlib);
6894 default_binds_local_p_1 (const_tree exp, int shlib)
6897 bool resolved_locally = false;
6898 bool resolved_to_local_def = false;
6900 /* With resolution file in hands, take look into resolutions.
6901 We can't just return true for resolved_locally symbols,
6902 because dynamic linking might overwrite symbols
6903 in shared libraries. */
6904 if (TREE_CODE (exp) == VAR_DECL && TREE_PUBLIC (exp)
6905 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
6907 struct varpool_node *vnode = varpool_get_node (exp);
6908 if (vnode && resolution_local_p (vnode->resolution))
6909 resolved_locally = true;
6911 && resolution_to_local_definition_p (vnode->resolution))
6912 resolved_to_local_def = true;
6914 else if (TREE_CODE (exp) == FUNCTION_DECL && TREE_PUBLIC (exp))
6916 struct cgraph_node *node = cgraph_get_node (exp);
6918 && resolution_local_p (node->resolution))
6919 resolved_locally = true;
6921 && resolution_to_local_definition_p (node->resolution))
6922 resolved_to_local_def = true;
6925 /* A non-decl is an entry in the constant pool. */
6928 /* Weakrefs may not bind locally, even though the weakref itself is always
6929 static and therefore local. Similarly, the resolver for ifunc functions
6930 might resolve to a non-local function.
6931 FIXME: We can resolve the weakref case more curefuly by looking at the
6933 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp))
6934 || (TREE_CODE (exp) == FUNCTION_DECL
6935 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (exp))))
6937 /* Static variables are always local. */
6938 else if (! TREE_PUBLIC (exp))
6940 /* A variable is local if the user has said explicitly that it will
6942 else if ((DECL_VISIBILITY_SPECIFIED (exp)
6943 || resolved_to_local_def)
6944 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6946 /* Variables defined outside this object might not be local. */
6947 else if (DECL_EXTERNAL (exp) && !resolved_locally)
6949 /* If defined in this object and visibility is not default, must be
6951 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6953 /* Default visibility weak data can be overridden by a strong symbol
6954 in another module and so are not local. */
6955 else if (DECL_WEAK (exp)
6956 && !resolved_locally)
6958 /* If PIC, then assume that any global name can be overridden by
6959 symbols resolved from other modules. */
6962 /* Uninitialized COMMON variable may be unified with symbols
6963 resolved from other modules. */
6964 else if (DECL_COMMON (exp)
6965 && !resolved_locally
6966 && (DECL_INITIAL (exp) == NULL
6967 || DECL_INITIAL (exp) == error_mark_node))
6969 /* Otherwise we're left with initialized (or non-common) global data
6970 which is of necessity defined locally. */
6977 /* Return true when references to DECL must bind to current definition in
6980 The condition is usually equivalent to whether the function binds to the
6981 current module (shared library or executable), that is to binds_local_p.
6982 We use this fact to avoid need for another target hook and implement
6983 the logic using binds_local_p and just special cases where
6984 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
6985 the weak definitions (that can be overwritten at linktime by other
6986 definition from different object file) and when resolution info is available
6987 we simply use the knowledge passed to us by linker plugin. */
6989 decl_binds_to_current_def_p (tree decl)
6991 gcc_assert (DECL_P (decl));
6992 if (!TREE_PUBLIC (decl))
6994 if (!targetm.binds_local_p (decl))
6996 /* When resolution is available, just use it. */
6997 if (TREE_CODE (decl) == VAR_DECL
6998 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
7000 struct varpool_node *vnode = varpool_get_node (decl);
7002 && vnode->resolution != LDPR_UNKNOWN)
7003 return resolution_to_local_definition_p (vnode->resolution);
7005 else if (TREE_CODE (decl) == FUNCTION_DECL)
7007 struct cgraph_node *node = cgraph_get_node (decl);
7009 && node->resolution != LDPR_UNKNOWN)
7010 return resolution_to_local_definition_p (node->resolution);
7012 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
7013 binds locally but still can be overwritten).
7014 This rely on fact that binds_local_p behave as decl_replaceable_p
7015 for all other declaration types. */
7016 return !DECL_WEAK (decl);
7019 /* A replaceable function or variable is one which may be replaced
7020 at link-time with an entirely different definition, provided that the
7021 replacement has the same type. For example, functions declared
7022 with __attribute__((weak)) on most systems are replaceable.
7024 COMDAT functions are not replaceable, since all definitions of the
7025 function must be equivalent. It is important that COMDAT functions
7026 not be treated as replaceable so that use of C++ template
7027 instantiations is not penalized. */
7030 decl_replaceable_p (tree decl)
7032 gcc_assert (DECL_P (decl));
7033 if (!TREE_PUBLIC (decl) || DECL_COMDAT (decl))
7035 return !decl_binds_to_current_def_p (decl);
7038 /* Default function to output code that will globalize a label. A
7039 target must define GLOBAL_ASM_OP or provide its own function to
7040 globalize a label. */
7041 #ifdef GLOBAL_ASM_OP
7043 default_globalize_label (FILE * stream, const char *name)
7045 fputs (GLOBAL_ASM_OP, stream);
7046 assemble_name (stream, name);
7047 putc ('\n', stream);
7049 #endif /* GLOBAL_ASM_OP */
7051 /* Default function to output code that will globalize a declaration. */
7053 default_globalize_decl_name (FILE * stream, tree decl)
7055 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
7056 targetm.asm_out.globalize_label (stream, name);
7059 /* Default function to output a label for unwind information. The
7060 default is to do nothing. A target that needs nonlocal labels for
7061 unwind information must provide its own function to do this. */
7063 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
7064 tree decl ATTRIBUTE_UNUSED,
7065 int for_eh ATTRIBUTE_UNUSED,
7066 int empty ATTRIBUTE_UNUSED)
7070 /* Default function to output a label to divide up the exception table.
7071 The default is to do nothing. A target that needs/wants to divide
7072 up the table must provide it's own function to do this. */
7074 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
7078 /* This is how to output an internal numbered label where PREFIX is
7079 the class of label and LABELNO is the number within the class. */
7082 default_generate_internal_label (char *buf, const char *prefix,
7083 unsigned long labelno)
7085 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
7088 /* This is how to output an internal numbered label where PREFIX is
7089 the class of label and LABELNO is the number within the class. */
7092 default_internal_label (FILE *stream, const char *prefix,
7093 unsigned long labelno)
7095 char *const buf = (char *) alloca (40 + strlen (prefix));
7096 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
7097 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
7101 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
7104 default_asm_declare_constant_name (FILE *file, const char *name,
7105 const_tree exp ATTRIBUTE_UNUSED,
7106 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
7108 assemble_label (file, name);
7111 /* This is the default behavior at the beginning of a file. It's
7112 controlled by two other target-hook toggles. */
7114 default_file_start (void)
7116 if (targetm.asm_file_start_app_off
7117 && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
7118 fputs (ASM_APP_OFF, asm_out_file);
7120 if (targetm.asm_file_start_file_directive)
7121 output_file_directive (asm_out_file, main_input_filename);
7124 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
7125 which emits a special section directive used to indicate whether or
7126 not this object file needs an executable stack. This is primarily
7127 a GNU extension to ELF but could be used on other targets. */
7129 int trampolines_created;
7132 file_end_indicate_exec_stack (void)
7134 unsigned int flags = SECTION_DEBUG;
7135 if (trampolines_created)
7136 flags |= SECTION_CODE;
7138 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
7141 /* Emit a special section directive to indicate that this object file
7142 was compiled with -fsplit-stack. This is used to let the linker
7143 detect calls between split-stack code and non-split-stack code, so
7144 that it can modify the split-stack code to allocate a sufficiently
7145 large stack. We emit another special section if there are any
7146 functions in this file which have the no_split_stack attribute, to
7147 prevent the linker from warning about being unable to convert the
7148 functions if they call non-split-stack code. */
7151 file_end_indicate_split_stack (void)
7153 if (flag_split_stack)
7155 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG,
7157 if (saw_no_split_stack)
7158 switch_to_section (get_section (".note.GNU-no-split-stack",
7159 SECTION_DEBUG, NULL));
7163 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
7164 a get_unnamed_section callback. */
7167 output_section_asm_op (const void *directive)
7169 fprintf (asm_out_file, "%s\n", (const char *) directive);
7172 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
7173 the current section is NEW_SECTION. */
7176 switch_to_section (section *new_section)
7178 if (in_section == new_section)
7181 if (new_section->common.flags & SECTION_FORGET)
7184 in_section = new_section;
7186 switch (SECTION_STYLE (new_section))
7189 targetm.asm_out.named_section (new_section->named.name,
7190 new_section->named.common.flags,
7191 new_section->named.decl);
7194 case SECTION_UNNAMED:
7195 new_section->unnamed.callback (new_section->unnamed.data);
7198 case SECTION_NOSWITCH:
7203 new_section->common.flags |= SECTION_DECLARED;
7206 /* If block symbol SYMBOL has not yet been assigned an offset, place
7207 it at the end of its block. */
7210 place_block_symbol (rtx symbol)
7212 unsigned HOST_WIDE_INT size, mask, offset;
7213 struct constant_descriptor_rtx *desc;
7214 unsigned int alignment;
7215 struct object_block *block;
7218 gcc_assert (SYMBOL_REF_BLOCK (symbol));
7219 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
7222 /* Work out the symbol's size and alignment. */
7223 if (CONSTANT_POOL_ADDRESS_P (symbol))
7225 desc = SYMBOL_REF_CONSTANT (symbol);
7226 alignment = desc->align;
7227 size = GET_MODE_SIZE (desc->mode);
7229 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7231 decl = SYMBOL_REF_DECL (symbol);
7232 alignment = DECL_ALIGN (decl);
7233 size = get_constant_size (DECL_INITIAL (decl));
7237 decl = SYMBOL_REF_DECL (symbol);
7238 alignment = DECL_ALIGN (decl);
7239 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7242 /* Calculate the object's offset from the start of the block. */
7243 block = SYMBOL_REF_BLOCK (symbol);
7244 mask = alignment / BITS_PER_UNIT - 1;
7245 offset = (block->size + mask) & ~mask;
7246 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
7248 /* Record the block's new alignment and size. */
7249 block->alignment = MAX (block->alignment, alignment);
7250 block->size = offset + size;
7252 VEC_safe_push (rtx, gc, block->objects, symbol);
7255 /* Return the anchor that should be used to address byte offset OFFSET
7256 from the first object in BLOCK. MODEL is the TLS model used
7260 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
7261 enum tls_model model)
7264 unsigned int begin, middle, end;
7265 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
7268 /* Work out the anchor's offset. Use an offset of 0 for the first
7269 anchor so that we don't pessimize the case where we take the address
7270 of a variable at the beginning of the block. This is particularly
7271 useful when a block has only one variable assigned to it.
7273 We try to place anchors RANGE bytes apart, so there can then be
7274 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7275 a ptr_mode offset. With some target settings, the lowest such
7276 anchor might be out of range for the lowest ptr_mode offset;
7277 likewise the highest anchor for the highest offset. Use anchors
7278 at the extreme ends of the ptr_mode range in such cases.
7280 All arithmetic uses unsigned integers in order to avoid
7282 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
7283 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
7284 range = max_offset - min_offset + 1;
7289 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
7292 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
7293 delta -= delta % range;
7296 offset = (HOST_WIDE_INT) (-delta);
7300 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
7301 delta -= delta % range;
7302 if (delta > bias - 1)
7304 offset = (HOST_WIDE_INT) delta;
7308 /* Do a binary search to see if there's already an anchor we can use.
7309 Set BEGIN to the new anchor's index if not. */
7311 end = VEC_length (rtx, block->anchors);
7312 while (begin != end)
7314 middle = (end + begin) / 2;
7315 anchor = VEC_index (rtx, block->anchors, middle);
7316 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
7318 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
7320 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
7322 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
7328 /* Create a new anchor with a unique label. */
7329 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
7330 anchor = create_block_symbol (ggc_strdup (label), block, offset);
7331 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
7332 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
7334 /* Insert it at index BEGIN. */
7335 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
7339 /* Output the objects in BLOCK. */
7342 output_object_block (struct object_block *block)
7344 struct constant_descriptor_rtx *desc;
7346 HOST_WIDE_INT offset;
7350 if (block->objects == NULL)
7353 /* Switch to the section and make sure that the first byte is
7354 suitably aligned. */
7355 switch_to_section (block->sect);
7356 assemble_align (block->alignment);
7358 /* Define the values of all anchors relative to the current section
7360 FOR_EACH_VEC_ELT (rtx, block->anchors, i, symbol)
7361 targetm.asm_out.output_anchor (symbol);
7363 /* Output the objects themselves. */
7365 FOR_EACH_VEC_ELT (rtx, block->objects, i, symbol)
7367 /* Move to the object's offset, padding with zeros if necessary. */
7368 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
7369 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
7370 if (CONSTANT_POOL_ADDRESS_P (symbol))
7372 desc = SYMBOL_REF_CONSTANT (symbol);
7373 output_constant_pool_1 (desc, 1);
7374 offset += GET_MODE_SIZE (desc->mode);
7376 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7378 decl = SYMBOL_REF_DECL (symbol);
7379 assemble_constant_contents (DECL_INITIAL (decl), XSTR (symbol, 0),
7381 offset += get_constant_size (DECL_INITIAL (decl));
7385 decl = SYMBOL_REF_DECL (symbol);
7386 assemble_variable_contents (decl, XSTR (symbol, 0), false);
7387 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7392 /* A htab_traverse callback used to call output_object_block for
7393 each member of object_block_htab. */
7396 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
7398 output_object_block ((struct object_block *) (*slot));
7402 /* Output the definitions of all object_blocks. */
7405 output_object_blocks (void)
7407 htab_traverse (object_block_htab, output_object_block_htab, NULL);
7410 /* This function provides a possible implementation of the
7411 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7412 by -frecord-gcc-switches it creates a new mergeable, string section in the
7413 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7414 contains the switches in ASCII format.
7416 FIXME: This code does not correctly handle double quote characters
7417 that appear inside strings, (it strips them rather than preserving them).
7418 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7419 characters - instead it treats them as sub-string separators. Since
7420 we want to emit NUL strings terminators into the object file we have to use
7424 elf_record_gcc_switches (print_switch_type type, const char * name)
7428 case SWITCH_TYPE_PASSED:
7429 ASM_OUTPUT_ASCII (asm_out_file, name, strlen (name));
7430 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7433 case SWITCH_TYPE_DESCRIPTIVE:
7436 /* Distinguish between invocations where name is NULL. */
7437 static bool started = false;
7443 sec = get_section (targetm.asm_out.record_gcc_switches_section,
7447 | (SECTION_ENTSIZE & 1),
7449 switch_to_section (sec);
7458 /* The return value is currently ignored by the caller, but must be 0.
7459 For -fverbose-asm the return value would be the number of characters
7460 emitted into the assembler file. */
7464 /* Emit text to declare externally defined symbols. It is needed to
7465 properly support non-default visibility. */
7467 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
7469 const char *name ATTRIBUTE_UNUSED)
7471 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7472 set in order to avoid putting out names that are never really
7474 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
7475 && targetm.binds_local_p (decl))
7476 maybe_assemble_visibility (decl);
7479 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7482 default_asm_output_source_filename (FILE *file, const char *name)
7484 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7485 ASM_OUTPUT_SOURCE_FILENAME (file, name);
7487 fprintf (file, "\t.file\t");
7488 output_quoted_string (file, name);
7493 /* Output a file name in the form wanted by System V. */
7496 output_file_directive (FILE *asm_file, const char *input_name)
7501 if (input_name == NULL)
7502 input_name = "<stdin>";
7504 input_name = remap_debug_filename (input_name);
7506 len = strlen (input_name);
7507 na = input_name + len;
7509 /* NA gets INPUT_NAME sans directory names. */
7510 while (na > input_name)
7512 if (IS_DIR_SEPARATOR (na[-1]))
7517 targetm.asm_out.output_source_filename (asm_file, na);
7520 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7523 make_debug_expr_from_rtl (const_rtx exp)
7525 tree ddecl = make_node (DEBUG_EXPR_DECL), type;
7526 enum machine_mode mode = GET_MODE (exp);
7529 DECL_ARTIFICIAL (ddecl) = 1;
7530 if (REG_P (exp) && REG_EXPR (exp))
7531 type = TREE_TYPE (REG_EXPR (exp));
7532 else if (MEM_P (exp) && MEM_EXPR (exp))
7533 type = TREE_TYPE (MEM_EXPR (exp));
7536 if (type && TYPE_MODE (type) == mode)
7537 TREE_TYPE (ddecl) = type;
7539 TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
7540 DECL_MODE (ddecl) = mode;
7541 dval = gen_rtx_DEBUG_EXPR (mode);
7542 DEBUG_EXPR_TREE_DECL (dval) = ddecl;
7543 SET_DECL_RTL (ddecl, dval);
7547 #ifdef ELF_ASCII_ESCAPES
7548 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
7551 default_elf_asm_output_limited_string (FILE *f, const char *s)
7556 fputs (STRING_ASM_OP, f);
7561 escape = ELF_ASCII_ESCAPES[c];
7568 /* TODO: Print in hex with fast function, important for -flto. */
7569 fprintf (f, "\\%03o", c);
7582 /* Default ASM_OUTPUT_ASCII for ELF targets. */
7585 default_elf_asm_output_ascii (FILE *f, const char *s, unsigned int len)
7587 const char *limit = s + len;
7588 const char *last_null = NULL;
7589 unsigned bytes_in_chunk = 0;
7593 for (; s < limit; s++)
7597 if (bytes_in_chunk >= 60)
7606 for (p = s; p < limit && *p != '\0'; p++)
7613 if (p < limit && (p - s) <= (long) ELF_STRING_LIMIT)
7615 if (bytes_in_chunk > 0)
7622 default_elf_asm_output_limited_string (f, s);
7627 if (bytes_in_chunk == 0)
7628 fputs (ASCII_DATA_ASM_OP "\"", f);
7631 escape = ELF_ASCII_ESCAPES[c];
7639 /* TODO: Print in hex with fast function, important for -flto. */
7640 fprintf (f, "\\%03o", c);
7641 bytes_in_chunk += 4;
7646 bytes_in_chunk += 2;
7653 if (bytes_in_chunk > 0)
7661 static GTY(()) section *elf_init_array_section;
7662 static GTY(()) section *elf_fini_array_section;
7665 get_elf_initfini_array_priority_section (int priority,
7669 if (priority != DEFAULT_INIT_PRIORITY)
7672 sprintf (buf, "%s.%.5u",
7673 constructor_p ? ".init_array" : ".fini_array",
7675 sec = get_section (buf, SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
7681 if (elf_init_array_section == NULL)
7682 elf_init_array_section
7683 = get_section (".init_array",
7684 SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
7685 sec = elf_init_array_section;
7689 if (elf_fini_array_section == NULL)
7690 elf_fini_array_section
7691 = get_section (".fini_array",
7692 SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
7693 sec = elf_fini_array_section;
7699 /* Use .init_array section for constructors. */
7702 default_elf_init_array_asm_out_constructor (rtx symbol, int priority)
7704 section *sec = get_elf_initfini_array_priority_section (priority,
7706 assemble_addr_to_section (symbol, sec);
7709 /* Use .fini_array section for destructors. */
7712 default_elf_fini_array_asm_out_destructor (rtx symbol, int priority)
7714 section *sec = get_elf_initfini_array_priority_section (priority,
7716 assemble_addr_to_section (symbol, sec);
7719 #include "gt-varasm.h"