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 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
46 #include "langhooks.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h" /* Needed for external data
59 declarations for e.g. AIX 4.x. */
62 /* The (assembler) name of the first globally-visible object output. */
63 extern GTY(()) const char *first_global_object_name;
64 extern GTY(()) const char *weak_global_object_name;
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
70 struct constant_descriptor_rtx;
71 struct rtx_constant_pool;
73 #define n_deferred_constants (crtl->varasm.deferred_constants)
75 /* Number for making the label on the next
76 constant that is stored in memory. */
78 static GTY(()) int const_labelno;
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81 to ASM_FINISH_DECLARE_OBJECT. */
83 int size_directive_output;
85 /* The last decl for which assemble_variable was called,
86 if it did ASM_DECLARE_OBJECT_NAME.
87 If the last call to assemble_variable didn't do that,
90 tree last_assemble_variable_decl;
92 /* The following global variable indicates if the first basic block
93 in a function belongs to the cold partition or not. */
95 bool first_function_block_is_cold;
97 /* We give all constants their own alias set. Perhaps redundant with
98 MEM_READONLY_P, but pre-dates it. */
100 static alias_set_type const_alias_set;
102 static const char *strip_reg_name (const char *);
103 static int contains_pointers_p (tree);
104 #ifdef ASM_OUTPUT_EXTERNAL
105 static bool incorporeal_function_p (tree);
107 static void decode_addr_const (tree, struct addr_const *);
108 static hashval_t const_desc_hash (const void *);
109 static int const_desc_eq (const void *, const void *);
110 static hashval_t const_hash_1 (const tree);
111 static int compare_constant (const tree, const tree);
112 static tree copy_constant (tree);
113 static void output_constant_def_contents (rtx);
114 static void output_addressed_constants (tree);
115 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
116 static unsigned min_align (unsigned, unsigned);
117 static void globalize_decl (tree);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_BSS
120 static void asm_output_bss (FILE *, tree, const char *,
121 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
123 #ifdef ASM_OUTPUT_ALIGNED_BSS
124 static void asm_output_aligned_bss (FILE *, tree, const char *,
125 unsigned HOST_WIDE_INT, int)
128 #endif /* BSS_SECTION_ASM_OP */
129 static void mark_weak (tree);
130 static void output_constant_pool (const char *, tree);
132 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
133 section *text_section;
134 section *data_section;
135 section *readonly_data_section;
136 section *sdata_section;
137 section *ctors_section;
138 section *dtors_section;
139 section *bss_section;
140 section *sbss_section;
142 /* Various forms of common section. All are guaranteed to be nonnull. */
143 section *tls_comm_section;
144 section *comm_section;
145 section *lcomm_section;
147 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
149 section *bss_noswitch_section;
151 /* The section that holds the main exception table, when known. The section
152 is set either by the target's init_sections hook or by the first call to
153 switch_to_exception_section. */
154 section *exception_section;
156 /* The section that holds the DWARF2 frame unwind information, when known.
157 The section is set either by the target's init_sections hook or by the
158 first call to switch_to_eh_frame_section. */
159 section *eh_frame_section;
161 /* asm_out_file's current section. This is NULL if no section has yet
162 been selected or if we lose track of what the current section is. */
165 /* True if code for the current function is currently being directed
166 at the cold section. */
167 bool in_cold_section_p;
169 /* A linked list of all the unnamed sections. */
170 static GTY(()) section *unnamed_sections;
172 /* Return a nonzero value if DECL has a section attribute. */
173 #ifndef IN_NAMED_SECTION
174 #define IN_NAMED_SECTION(DECL) \
175 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
176 && DECL_SECTION_NAME (DECL) != NULL_TREE)
179 /* Hash table of named sections. */
180 static GTY((param_is (section))) htab_t section_htab;
182 /* A table of object_blocks, indexed by section. */
183 static GTY((param_is (struct object_block))) htab_t object_block_htab;
185 /* The next number to use for internal anchor labels. */
186 static GTY(()) int anchor_labelno;
188 /* A pool of constants that can be shared between functions. */
189 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
193 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
195 static GTY (()) tree emutls_object_type;
196 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
197 macro can be used on them to distinguish the control variable from
198 the initialization template. */
199 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
201 #if !defined (NO_DOT_IN_LABEL)
202 # define EMUTLS_SEPARATOR "."
203 #elif !defined (NO_DOLLAR_IN_LABEL)
204 # define EMUTLS_SEPARATOR "$"
206 # define EMUTLS_SEPARATOR "_"
209 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
210 IDENTIFIER_NODE NAME's name. */
213 prefix_name (const char *prefix, tree name)
215 unsigned plen = strlen (prefix);
216 unsigned nlen = strlen (IDENTIFIER_POINTER (name));
217 char *toname = (char *) alloca (plen + nlen + 1);
219 memcpy (toname, prefix, plen);
220 memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
222 return get_identifier (toname);
225 /* Create an identifier for the struct __emutls_object, given an identifier
226 of the DECL_ASSEMBLY_NAME of the original object. */
229 get_emutls_object_name (tree name)
231 const char *prefix = (targetm.emutls.var_prefix
232 ? targetm.emutls.var_prefix
233 : "__emutls_v" EMUTLS_SEPARATOR);
234 return prefix_name (prefix, name);
238 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
240 tree word_type_node, field, next_field;
242 field = build_decl (FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
243 DECL_CONTEXT (field) = type;
246 field = build_decl (FIELD_DECL, get_identifier ("__offset"),
248 DECL_CONTEXT (field) = type;
249 TREE_CHAIN (field) = next_field;
252 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
253 field = build_decl (FIELD_DECL, get_identifier ("__align"),
255 DECL_CONTEXT (field) = type;
256 TREE_CHAIN (field) = next_field;
259 field = build_decl (FIELD_DECL, get_identifier ("__size"), word_type_node);
260 DECL_CONTEXT (field) = type;
261 TREE_CHAIN (field) = next_field;
266 /* Create the structure for struct __emutls_object. This should match the
267 structure at the top of emutls.c, modulo the union there. */
270 get_emutls_object_type (void)
272 tree type, type_name, field;
274 type = emutls_object_type;
278 emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
280 field = targetm.emutls.var_fields (type, &type_name);
282 type_name = get_identifier ("__emutls_object");
283 type_name = build_decl (TYPE_DECL, type_name, type);
284 TYPE_NAME (type) = type_name;
285 TYPE_FIELDS (type) = field;
291 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
292 This will be used for initializing the emulated tls data area. */
295 get_emutls_init_templ_addr (tree decl)
299 if (targetm.emutls.register_common && !DECL_INITIAL (decl)
300 && !DECL_SECTION_NAME (decl))
301 return null_pointer_node;
303 name = DECL_ASSEMBLER_NAME (decl);
304 if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0])
306 const char *prefix = (targetm.emutls.tmpl_prefix
307 ? targetm.emutls.tmpl_prefix
308 : "__emutls_t" EMUTLS_SEPARATOR);
309 name = prefix_name (prefix, name);
312 to = build_decl (VAR_DECL, name, TREE_TYPE (decl));
313 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
314 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
315 DECL_ARTIFICIAL (to) = 1;
316 TREE_USED (to) = TREE_USED (decl);
317 TREE_READONLY (to) = 1;
318 DECL_IGNORED_P (to) = 1;
319 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
320 DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
322 DECL_WEAK (to) = DECL_WEAK (decl);
323 if (DECL_ONE_ONLY (decl))
325 make_decl_one_only (to);
326 TREE_STATIC (to) = TREE_STATIC (decl);
327 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
328 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
331 TREE_STATIC (to) = 1;
333 DECL_INITIAL (to) = DECL_INITIAL (decl);
334 DECL_INITIAL (decl) = NULL;
336 varpool_finalize_decl (to);
337 return build_fold_addr_expr (to);
340 /* When emulating tls, we use a control structure for use by the runtime.
341 Create and return this structure. */
344 emutls_decl (tree decl)
347 struct tree_map *h, in;
350 if (targetm.have_tls || decl == NULL || decl == error_mark_node
351 || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
354 /* Look up the object in the hash; return the control structure if
355 it has already been created. */
357 emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
359 name = DECL_ASSEMBLER_NAME (decl);
361 /* Note that we use the hash of the decl's name, rather than a hash
362 of the decl's pointer. In emutls_finish we iterate through the
363 hash table, and we want this traversal to be predictable. */
364 in.hash = htab_hash_string (IDENTIFIER_POINTER (name));
366 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
367 h = (struct tree_map *) *loc;
372 to = build_decl (VAR_DECL, get_emutls_object_name (name),
373 get_emutls_object_type ());
375 h = GGC_NEW (struct tree_map);
379 *(struct tree_map **) loc = h;
381 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
382 DECL_ARTIFICIAL (to) = 1;
383 DECL_IGNORED_P (to) = 1;
384 TREE_READONLY (to) = 0;
385 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
386 if (DECL_ONE_ONLY (decl))
387 make_decl_one_only (to);
388 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
389 if (targetm.emutls.var_align_fixed)
390 /* If we're not allowed to change the proxy object's
391 alignment, pretend it's been set by the user. */
392 DECL_USER_ALIGN (to) = 1;
395 /* Note that these fields may need to be updated from time to time from
396 the original decl. Consider:
397 extern __thread int i;
398 int foo() { return i; }
400 in which I goes from external to locally defined and initialized. */
402 TREE_STATIC (to) = TREE_STATIC (decl);
403 TREE_USED (to) = TREE_USED (decl);
404 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
405 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
406 DECL_COMMON (to) = DECL_COMMON (decl);
407 DECL_WEAK (to) = DECL_WEAK (decl);
408 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
414 emutls_common_1 (void **loc, void *xstmts)
416 struct tree_map *h = *(struct tree_map **) loc;
417 tree args, x, *pstmts = (tree *) xstmts;
420 if (! DECL_COMMON (h->base.from)
421 || (DECL_INITIAL (h->base.from)
422 && DECL_INITIAL (h->base.from) != error_mark_node))
425 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
427 /* The idea was to call get_emutls_init_templ_addr here, but if we
428 do this and there is an initializer, -fanchor_section loses,
429 because it would be too late to ensure the template is
431 x = null_pointer_node;
432 args = tree_cons (NULL, x, NULL);
433 x = build_int_cst (word_type_node, DECL_ALIGN_UNIT (h->base.from));
434 args = tree_cons (NULL, x, args);
435 x = fold_convert (word_type_node, DECL_SIZE_UNIT (h->base.from));
436 args = tree_cons (NULL, x, args);
437 x = build_fold_addr_expr (h->to);
438 args = tree_cons (NULL, x, args);
440 x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
441 x = build_function_call_expr (x, args);
443 append_to_statement_list (x, pstmts);
450 if (targetm.emutls.register_common)
452 tree body = NULL_TREE;
454 if (emutls_htab == NULL)
457 htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
458 if (body == NULL_TREE)
461 cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
465 /* Helper routines for maintaining section_htab. */
468 section_entry_eq (const void *p1, const void *p2)
470 const section *old = (const section *) p1;
471 const char *new_name = (const char *) p2;
473 return strcmp (old->named.name, new_name) == 0;
477 section_entry_hash (const void *p)
479 const section *old = (const section *) p;
480 return htab_hash_string (old->named.name);
483 /* Return a hash value for section SECT. */
486 hash_section (section *sect)
488 if (sect->common.flags & SECTION_NAMED)
489 return htab_hash_string (sect->named.name);
490 return sect->common.flags;
493 /* Helper routines for maintaining object_block_htab. */
496 object_block_entry_eq (const void *p1, const void *p2)
498 const struct object_block *old = (const struct object_block *) p1;
499 const section *new_section = (const section *) p2;
501 return old->sect == new_section;
505 object_block_entry_hash (const void *p)
507 const struct object_block *old = (const struct object_block *) p;
508 return hash_section (old->sect);
511 /* Return a new unnamed section with the given fields. */
514 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
519 sect = GGC_NEW (section);
520 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
521 sect->unnamed.callback = callback;
522 sect->unnamed.data = data;
523 sect->unnamed.next = unnamed_sections;
525 unnamed_sections = sect;
529 /* Return a SECTION_NOSWITCH section with the given fields. */
532 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
536 sect = GGC_NEW (section);
537 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
538 sect->noswitch.callback = callback;
543 /* Return the named section structure associated with NAME. Create
544 a new section with the given fields if no such structure exists. */
547 get_section (const char *name, unsigned int flags, tree decl)
549 section *sect, **slot;
552 htab_find_slot_with_hash (section_htab, name,
553 htab_hash_string (name), INSERT);
554 flags |= SECTION_NAMED;
557 sect = GGC_NEW (section);
558 sect->named.common.flags = flags;
559 sect->named.name = ggc_strdup (name);
560 sect->named.decl = decl;
566 if ((sect->common.flags & ~SECTION_DECLARED) != flags
567 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
569 /* Sanity check user variables for flag changes. */
571 decl = sect->named.decl;
573 error ("%+D causes a section type conflict", decl);
579 /* Return true if the current compilation mode benefits from having
580 objects grouped into blocks. */
583 use_object_blocks_p (void)
585 return flag_section_anchors;
588 /* Return the object_block structure for section SECT. Create a new
589 structure if we haven't created one already. Return null if SECT
592 static struct object_block *
593 get_block_for_section (section *sect)
595 struct object_block *block;
601 slot = htab_find_slot_with_hash (object_block_htab, sect,
602 hash_section (sect), INSERT);
603 block = (struct object_block *) *slot;
606 block = (struct object_block *)
607 ggc_alloc_cleared (sizeof (struct object_block));
614 /* Create a symbol with label LABEL and place it at byte offset
615 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
616 is not yet known. LABEL must be a garbage-collected string. */
619 create_block_symbol (const char *label, struct object_block *block,
620 HOST_WIDE_INT offset)
625 /* Create the extended SYMBOL_REF. */
626 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
627 symbol = (rtx) ggc_alloc_zone (size, &rtl_zone);
629 /* Initialize the normal SYMBOL_REF fields. */
630 memset (symbol, 0, size);
631 PUT_CODE (symbol, SYMBOL_REF);
632 PUT_MODE (symbol, Pmode);
633 XSTR (symbol, 0) = label;
634 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
636 /* Initialize the block_symbol stuff. */
637 SYMBOL_REF_BLOCK (symbol) = block;
638 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
644 initialize_cold_section_name (void)
646 const char *stripped_name;
650 gcc_assert (cfun && current_function_decl);
651 if (crtl->subsections.unlikely_text_section_name)
654 dsn = DECL_SECTION_NAME (current_function_decl);
655 if (flag_function_sections && dsn)
657 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
658 memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
660 stripped_name = targetm.strip_name_encoding (name);
662 buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
663 crtl->subsections.unlikely_text_section_name = ggc_strdup (buffer);
666 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
669 /* Tell assembler to switch to unlikely-to-be-executed text section. */
672 unlikely_text_section (void)
676 if (!crtl->subsections.unlikely_text_section_name)
677 initialize_cold_section_name ();
679 return get_named_section (NULL, crtl->subsections.unlikely_text_section_name, 0);
682 return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
685 /* When called within a function context, return true if the function
686 has been assigned a cold text section and if SECT is that section.
687 When called outside a function context, return true if SECT is the
688 default cold section. */
691 unlikely_text_section_p (section *sect)
696 name = crtl->subsections.unlikely_text_section_name;
698 name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
702 && SECTION_STYLE (sect) == SECTION_NAMED
703 && strcmp (name, sect->named.name) == 0);
706 /* Return a section with a particular name and with whatever SECTION_*
707 flags section_type_flags deems appropriate. The name of the section
708 is taken from NAME if nonnull, otherwise it is taken from DECL's
709 DECL_SECTION_NAME. DECL is the decl associated with the section
710 (see the section comment for details) and RELOC is as for
711 section_type_flags. */
714 get_named_section (tree decl, const char *name, int reloc)
718 gcc_assert (!decl || DECL_P (decl));
720 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
722 flags = targetm.section_type_flags (decl, name, reloc);
724 return get_section (name, flags, decl);
727 /* If required, set DECL_SECTION_NAME to a unique name. */
730 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
731 int flag_function_or_data_sections)
733 if (DECL_SECTION_NAME (decl) == NULL_TREE
734 && targetm.have_named_sections
735 && (flag_function_or_data_sections
736 || DECL_ONE_ONLY (decl)))
737 targetm.asm_out.unique_section (decl, reloc);
740 #ifdef BSS_SECTION_ASM_OP
742 #ifdef ASM_OUTPUT_BSS
744 /* Utility function for ASM_OUTPUT_BSS for targets to use if
745 they don't support alignments in .bss.
746 ??? It is believed that this function will work in most cases so such
747 support is localized here. */
750 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
752 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
753 unsigned HOST_WIDE_INT rounded)
755 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl), 0), 0), name) == 0);
756 targetm.asm_out.globalize_decl_name (file, decl);
757 switch_to_section (bss_section);
758 #ifdef ASM_DECLARE_OBJECT_NAME
759 last_assemble_variable_decl = decl;
760 ASM_DECLARE_OBJECT_NAME (file, name, decl);
762 /* Standard thing is just output label for the object. */
763 ASM_OUTPUT_LABEL (file, name);
764 #endif /* ASM_DECLARE_OBJECT_NAME */
765 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
770 #ifdef ASM_OUTPUT_ALIGNED_BSS
772 /* Utility function for targets to use in implementing
773 ASM_OUTPUT_ALIGNED_BSS.
774 ??? It is believed that this function will work in most cases so such
775 support is localized here. */
778 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
779 const char *name, unsigned HOST_WIDE_INT size,
782 switch_to_section (bss_section);
783 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
784 #ifdef ASM_DECLARE_OBJECT_NAME
785 last_assemble_variable_decl = decl;
786 ASM_DECLARE_OBJECT_NAME (file, name, decl);
788 /* Standard thing is just output label for the object. */
789 ASM_OUTPUT_LABEL (file, name);
790 #endif /* ASM_DECLARE_OBJECT_NAME */
791 ASM_OUTPUT_SKIP (file, size ? size : 1);
796 #endif /* BSS_SECTION_ASM_OP */
798 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
799 /* Return the hot section for function DECL. Return text_section for
803 hot_function_section (tree decl)
805 if (decl != NULL_TREE
806 && DECL_SECTION_NAME (decl) != NULL_TREE
807 && targetm.have_named_sections)
808 return get_named_section (decl, NULL, 0);
814 /* Return the section for function DECL.
816 If DECL is NULL_TREE, return the text section. We can be passed
817 NULL_TREE under some circumstances by dbxout.c at least. */
820 function_section (tree decl)
824 if (first_function_block_is_cold)
827 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
828 if (decl != NULL_TREE
829 && DECL_SECTION_NAME (decl) != NULL_TREE)
830 return reloc ? unlikely_text_section ()
831 : get_named_section (decl, NULL, 0);
833 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
835 return reloc ? unlikely_text_section () : hot_function_section (decl);
840 current_function_section (void)
842 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
843 if (current_function_decl != NULL_TREE
844 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
845 return in_cold_section_p ? unlikely_text_section ()
846 : get_named_section (current_function_decl,
849 return targetm.asm_out.select_section (current_function_decl,
851 DECL_ALIGN (current_function_decl));
853 return (in_cold_section_p
854 ? unlikely_text_section ()
855 : hot_function_section (current_function_decl));
859 /* Return the read-only data section associated with function DECL. */
862 default_function_rodata_section (tree decl)
864 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
866 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
868 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
874 dot = strchr (name + 1, '.');
877 len = strlen (dot) + 8;
878 rname = (char *) alloca (len);
880 strcpy (rname, ".rodata");
882 return get_section (rname, SECTION_LINKONCE, decl);
884 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
885 else if (DECL_ONE_ONLY (decl)
886 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
888 size_t len = strlen (name) + 1;
889 char *rname = (char *) alloca (len);
891 memcpy (rname, name, len);
893 return get_section (rname, SECTION_LINKONCE, decl);
895 /* For .text.foo we want to use .rodata.foo. */
896 else if (flag_function_sections && flag_data_sections
897 && strncmp (name, ".text.", 6) == 0)
899 size_t len = strlen (name) + 1;
900 char *rname = (char *) alloca (len + 2);
902 memcpy (rname, ".rodata", 7);
903 memcpy (rname + 7, name + 5, len - 5);
904 return get_section (rname, 0, decl);
908 return readonly_data_section;
911 /* Return the read-only data section associated with function DECL
912 for targets where that section should be always the single
913 readonly data section. */
916 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
918 return readonly_data_section;
921 /* Return the section to use for string merging. */
924 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
925 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
926 unsigned int flags ATTRIBUTE_UNUSED)
930 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
931 && TREE_CODE (decl) == STRING_CST
932 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
934 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
935 && TREE_STRING_LENGTH (decl) >= len)
937 enum machine_mode mode;
938 unsigned int modesize;
944 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
945 modesize = GET_MODE_BITSIZE (mode);
946 if (modesize >= 8 && modesize <= 256
947 && (modesize & (modesize - 1)) == 0)
949 if (align < modesize)
952 str = TREE_STRING_POINTER (decl);
953 unit = GET_MODE_SIZE (mode);
955 /* Check for embedded NUL characters. */
956 for (i = 0; i < len; i += unit)
958 for (j = 0; j < unit; j++)
959 if (str[i + j] != '\0')
966 sprintf (name, ".rodata.str%d.%d", modesize / 8,
968 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
969 return get_section (name, flags, NULL);
974 return readonly_data_section;
977 /* Return the section to use for constant merging. */
980 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
981 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
982 unsigned int flags ATTRIBUTE_UNUSED)
984 unsigned int modesize = GET_MODE_BITSIZE (mode);
986 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
992 && (align & (align - 1)) == 0)
996 sprintf (name, ".rodata.cst%d", (int) (align / 8));
997 flags |= (align / 8) | SECTION_MERGE;
998 return get_section (name, flags, NULL);
1000 return readonly_data_section;
1003 /* Given NAME, a putative register name, discard any customary prefixes. */
1006 strip_reg_name (const char *name)
1008 #ifdef REGISTER_PREFIX
1009 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
1010 name += strlen (REGISTER_PREFIX);
1012 if (name[0] == '%' || name[0] == '#')
1017 /* The user has asked for a DECL to have a particular name. Set (or
1018 change) it in such a way that we don't prefix an underscore to
1021 set_user_assembler_name (tree decl, const char *name)
1023 char *starred = (char *) alloca (strlen (name) + 2);
1025 strcpy (starred + 1, name);
1026 change_decl_assembler_name (decl, get_identifier (starred));
1027 SET_DECL_RTL (decl, NULL_RTX);
1030 /* Decode an `asm' spec for a declaration as a register name.
1031 Return the register number, or -1 if nothing specified,
1032 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1033 or -3 if ASMSPEC is `cc' and is not recognized,
1034 or -4 if ASMSPEC is `memory' and is not recognized.
1035 Accept an exact spelling or a decimal number.
1036 Prefixes such as % are optional. */
1039 decode_reg_name (const char *asmspec)
1045 /* Get rid of confusing prefixes. */
1046 asmspec = strip_reg_name (asmspec);
1048 /* Allow a decimal number as a "register name". */
1049 for (i = strlen (asmspec) - 1; i >= 0; i--)
1050 if (! ISDIGIT (asmspec[i]))
1052 if (asmspec[0] != 0 && i < 0)
1055 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
1061 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1063 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1066 #ifdef ADDITIONAL_REGISTER_NAMES
1068 static const struct { const char *const name; const int number; } table[]
1069 = ADDITIONAL_REGISTER_NAMES;
1071 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1072 if (table[i].name[0]
1073 && ! strcmp (asmspec, table[i].name))
1074 return table[i].number;
1076 #endif /* ADDITIONAL_REGISTER_NAMES */
1078 if (!strcmp (asmspec, "memory"))
1081 if (!strcmp (asmspec, "cc"))
1090 /* Return true if DECL's initializer is suitable for a BSS section. */
1093 bss_initializer_p (const_tree decl)
1095 return (DECL_INITIAL (decl) == NULL
1096 || DECL_INITIAL (decl) == error_mark_node
1097 || (flag_zero_initialized_in_bss
1098 /* Leave constant zeroes in .rodata so they
1100 && !TREE_READONLY (decl)
1101 && initializer_zerop (DECL_INITIAL (decl))));
1104 /* Compute the alignment of variable specified by DECL.
1105 DONT_OUTPUT_DATA is from assemble_variable. */
1108 align_variable (tree decl, bool dont_output_data)
1110 unsigned int align = DECL_ALIGN (decl);
1112 /* In the case for initialing an array whose length isn't specified,
1113 where we have not yet been able to do the layout,
1114 figure out the proper alignment now. */
1115 if (dont_output_data && DECL_SIZE (decl) == 0
1116 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1117 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1119 /* Some object file formats have a maximum alignment which they support.
1120 In particular, a.out format supports a maximum alignment of 4. */
1121 if (align > MAX_OFILE_ALIGNMENT)
1123 warning (0, "alignment of %q+D is greater than maximum object "
1124 "file alignment. Using %d", decl,
1125 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1126 align = MAX_OFILE_ALIGNMENT;
1129 /* On some machines, it is good to increase alignment sometimes. */
1130 if (! DECL_USER_ALIGN (decl))
1132 #ifdef DATA_ALIGNMENT
1133 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1134 /* Don't increase alignment too much for TLS variables - TLS space
1136 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1139 #ifdef CONSTANT_ALIGNMENT
1140 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1142 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
1144 /* Don't increase alignment too much for TLS variables - TLS space
1146 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1147 align = const_align;
1152 /* Reset the alignment in case we have made it tighter, so we can benefit
1153 from it in get_pointer_alignment. */
1154 DECL_ALIGN (decl) = align;
1157 /* Return the section into which the given VAR_DECL or CONST_DECL
1158 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1159 section should be used wherever possible. */
1162 get_variable_section (tree decl, bool prefer_noswitch_p)
1166 /* If the decl has been given an explicit section name, then it
1167 isn't common, and shouldn't be handled as such. */
1168 if (DECL_COMMON (decl) && DECL_SECTION_NAME (decl) == NULL)
1170 if (DECL_THREAD_LOCAL_P (decl))
1171 return tls_comm_section;
1172 /* This cannot be common bss for an emulated TLS object without
1173 a register_common hook. */
1174 else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED
1175 && !targetm.emutls.register_common)
1177 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1178 return comm_section;
1181 if (DECL_INITIAL (decl) == error_mark_node)
1182 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1183 else if (DECL_INITIAL (decl))
1184 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1188 resolve_unique_section (decl, reloc, flag_data_sections);
1189 if (IN_NAMED_SECTION (decl))
1190 return get_named_section (decl, NULL, reloc);
1192 if (!DECL_THREAD_LOCAL_P (decl)
1193 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1194 && bss_initializer_p (decl))
1196 if (!TREE_PUBLIC (decl))
1197 return lcomm_section;
1198 if (bss_noswitch_section)
1199 return bss_noswitch_section;
1202 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1205 /* Return the block into which object_block DECL should be placed. */
1207 static struct object_block *
1208 get_block_for_decl (tree decl)
1212 if (TREE_CODE (decl) == VAR_DECL)
1214 /* The object must be defined in this translation unit. */
1215 if (DECL_EXTERNAL (decl))
1218 /* There's no point using object blocks for something that is
1219 isolated by definition. */
1220 if (DECL_ONE_ONLY (decl))
1224 /* We can only calculate block offsets if the decl has a known
1226 if (DECL_SIZE_UNIT (decl) == NULL)
1228 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1231 /* Find out which section should contain DECL. We cannot put it into
1232 an object block if it requires a standalone definition. */
1233 if (TREE_CODE (decl) == VAR_DECL)
1234 align_variable (decl, 0);
1235 sect = get_variable_section (decl, true);
1236 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1239 return get_block_for_section (sect);
1242 /* Make sure block symbol SYMBOL is in block BLOCK. */
1245 change_symbol_block (rtx symbol, struct object_block *block)
1247 if (block != SYMBOL_REF_BLOCK (symbol))
1249 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1250 SYMBOL_REF_BLOCK (symbol) = block;
1254 /* Return true if it is possible to put DECL in an object_block. */
1257 use_blocks_for_decl_p (tree decl)
1259 /* Only data DECLs can be placed into object blocks. */
1260 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1263 /* Detect decls created by dw2_force_const_mem. Such decls are
1264 special because DECL_INITIAL doesn't specify the decl's true value.
1265 dw2_output_indirect_constants will instead call assemble_variable
1266 with dont_output_data set to 1 and then print the contents itself. */
1267 if (DECL_INITIAL (decl) == decl)
1270 /* If this decl is an alias, then we don't want to emit a definition. */
1271 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1277 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1278 have static storage duration. In other words, it should not be an
1279 automatic variable, including PARM_DECLs.
1281 There is, however, one exception: this function handles variables
1282 explicitly placed in a particular register by the user.
1284 This is never called for PARM_DECL nodes. */
1287 make_decl_rtl (tree decl)
1289 const char *name = 0;
1293 /* Check that we are not being given an automatic variable. */
1294 gcc_assert (TREE_CODE (decl) != PARM_DECL
1295 && TREE_CODE (decl) != RESULT_DECL);
1297 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1298 gcc_assert (TREE_CODE (decl) != VAR_DECL
1299 || TREE_STATIC (decl)
1300 || TREE_PUBLIC (decl)
1301 || DECL_EXTERNAL (decl)
1302 || DECL_REGISTER (decl));
1304 /* And that we were not given a type or a label. */
1305 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1306 && TREE_CODE (decl) != LABEL_DECL);
1308 /* For a duplicate declaration, we can be called twice on the
1309 same DECL node. Don't discard the RTL already made. */
1310 if (DECL_RTL_SET_P (decl))
1312 /* If the old RTL had the wrong mode, fix the mode. */
1313 x = DECL_RTL (decl);
1314 if (GET_MODE (x) != DECL_MODE (decl))
1315 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1317 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1320 /* ??? Another way to do this would be to maintain a hashed
1321 table of such critters. Instead of adding stuff to a DECL
1322 to give certain attributes to it, we could use an external
1323 hash map from DECL to set of attributes. */
1325 /* Let the target reassign the RTL if it wants.
1326 This is necessary, for example, when one machine specific
1327 decl attribute overrides another. */
1328 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1330 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1331 on the new decl information. */
1333 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1334 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1335 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1337 /* Make this function static known to the mudflap runtime. */
1338 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1339 mudflap_enqueue_decl (decl);
1344 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1346 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1347 && DECL_REGISTER (decl))
1349 error ("register name not specified for %q+D", decl);
1351 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1353 const char *asmspec = name+1;
1354 reg_number = decode_reg_name (asmspec);
1355 /* First detect errors in declaring global registers. */
1356 if (reg_number == -1)
1357 error ("register name not specified for %q+D", decl);
1358 else if (reg_number < 0)
1359 error ("invalid register name for %q+D", decl);
1360 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1361 error ("data type of %q+D isn%'t suitable for a register",
1363 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1364 error ("register specified for %q+D isn%'t suitable for data type",
1366 /* Now handle properly declared static register variables. */
1371 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1373 DECL_INITIAL (decl) = 0;
1374 error ("global register variable has initial value");
1376 if (TREE_THIS_VOLATILE (decl))
1377 warning (OPT_Wvolatile_register_var,
1378 "optimization may eliminate reads and/or "
1379 "writes to register variables");
1381 /* If the user specified one of the eliminables registers here,
1382 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1383 confused with that register and be eliminated. This usage is
1384 somewhat suspect... */
1386 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1387 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1388 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1390 if (TREE_STATIC (decl))
1392 /* Make this register global, so not usable for anything
1394 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1395 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1396 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1398 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1400 globalize_reg (reg_number + --nregs);
1403 /* As a register variable, it has no section. */
1407 /* Now handle ordinary static variables and functions (in memory).
1408 Also handle vars declared register invalidly. */
1409 else if (name[0] == '*')
1411 #ifdef REGISTER_PREFIX
1412 if (strlen (REGISTER_PREFIX) != 0)
1414 reg_number = decode_reg_name (name);
1415 if (reg_number >= 0 || reg_number == -3)
1416 error ("register name given for non-register variable %q+D", decl);
1421 /* Specifying a section attribute on a variable forces it into a
1422 non-.bss section, and thus it cannot be common. */
1423 if (TREE_CODE (decl) == VAR_DECL
1424 && DECL_SECTION_NAME (decl) != NULL_TREE
1425 && DECL_INITIAL (decl) == NULL_TREE
1426 && DECL_COMMON (decl))
1427 DECL_COMMON (decl) = 0;
1429 /* Variables can't be both common and weak. */
1430 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1431 DECL_COMMON (decl) = 0;
1433 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1434 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1436 x = gen_rtx_SYMBOL_REF (Pmode, name);
1437 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1438 SET_SYMBOL_REF_DECL (x, decl);
1440 x = gen_rtx_MEM (DECL_MODE (decl), x);
1441 if (TREE_CODE (decl) != FUNCTION_DECL)
1442 set_mem_attributes (x, decl, 1);
1443 SET_DECL_RTL (decl, x);
1445 /* Optionally set flags or add text to the name to record information
1446 such as that it is a function name.
1447 If the name is changed, the macro ASM_OUTPUT_LABELREF
1448 will have to know how to strip this information. */
1449 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1451 /* Make this function static known to the mudflap runtime. */
1452 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1453 mudflap_enqueue_decl (decl);
1456 /* Output a string of literal assembler code
1457 for an `asm' keyword used between functions. */
1460 assemble_asm (tree string)
1464 if (TREE_CODE (string) == ADDR_EXPR)
1465 string = TREE_OPERAND (string, 0);
1467 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1470 /* Record an element in the table of global destructors. SYMBOL is
1471 a SYMBOL_REF of the function to be called; PRIORITY is a number
1472 between 0 and MAX_INIT_PRIORITY. */
1475 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1476 int priority ATTRIBUTE_UNUSED)
1478 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1479 /* Tell GNU LD that this is part of the static destructor set.
1480 This will work for any system that uses stabs, most usefully
1482 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1483 dbxout_stab_value_label (XSTR (symbol, 0));
1485 sorry ("global destructors not supported on this target");
1489 /* Write the address of the entity given by SYMBOL to SEC. */
1491 assemble_addr_to_section (rtx symbol, section *sec)
1493 switch_to_section (sec);
1494 assemble_align (POINTER_SIZE);
1495 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1498 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1499 not) section for PRIORITY. */
1501 get_cdtor_priority_section (int priority, bool constructor_p)
1505 /* ??? This only works reliably with the GNU linker. */
1506 sprintf (buf, "%s.%.5u",
1507 constructor_p ? ".ctors" : ".dtors",
1508 /* Invert the numbering so the linker puts us in the proper
1509 order; constructors are run from right to left, and the
1510 linker sorts in increasing order. */
1511 MAX_INIT_PRIORITY - priority);
1512 return get_section (buf, SECTION_WRITE, NULL);
1516 default_named_section_asm_out_destructor (rtx symbol, int priority)
1520 if (priority != DEFAULT_INIT_PRIORITY)
1521 sec = get_cdtor_priority_section (priority,
1522 /*constructor_p=*/false);
1524 sec = get_section (".dtors", SECTION_WRITE, NULL);
1526 assemble_addr_to_section (symbol, sec);
1529 #ifdef DTORS_SECTION_ASM_OP
1531 default_dtor_section_asm_out_destructor (rtx symbol,
1532 int priority ATTRIBUTE_UNUSED)
1534 assemble_addr_to_section (symbol, dtors_section);
1538 /* Likewise for global constructors. */
1541 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1542 int priority ATTRIBUTE_UNUSED)
1544 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1545 /* Tell GNU LD that this is part of the static destructor set.
1546 This will work for any system that uses stabs, most usefully
1548 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1549 dbxout_stab_value_label (XSTR (symbol, 0));
1551 sorry ("global constructors not supported on this target");
1556 default_named_section_asm_out_constructor (rtx symbol, int priority)
1560 if (priority != DEFAULT_INIT_PRIORITY)
1561 sec = get_cdtor_priority_section (priority,
1562 /*constructor_p=*/true);
1564 sec = get_section (".ctors", SECTION_WRITE, NULL);
1566 assemble_addr_to_section (symbol, sec);
1569 #ifdef CTORS_SECTION_ASM_OP
1571 default_ctor_section_asm_out_constructor (rtx symbol,
1572 int priority ATTRIBUTE_UNUSED)
1574 assemble_addr_to_section (symbol, ctors_section);
1578 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1579 a nonzero value if the constant pool should be output before the
1580 start of the function, or a zero value if the pool should output
1581 after the end of the function. The default is to put it before the
1584 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1585 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1588 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1589 to be output to assembler.
1590 Set first_global_object_name and weak_global_object_name as appropriate. */
1593 notice_global_symbol (tree decl)
1595 const char **type = &first_global_object_name;
1597 if (first_global_object_name
1598 || !TREE_PUBLIC (decl)
1599 || DECL_EXTERNAL (decl)
1600 || !DECL_NAME (decl)
1601 || (TREE_CODE (decl) != FUNCTION_DECL
1602 && (TREE_CODE (decl) != VAR_DECL
1603 || (DECL_COMMON (decl)
1604 && (DECL_INITIAL (decl) == 0
1605 || DECL_INITIAL (decl) == error_mark_node))))
1606 || !MEM_P (DECL_RTL (decl)))
1609 /* We win when global object is found, but it is useful to know about weak
1610 symbol as well so we can produce nicer unique names. */
1611 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1612 type = &weak_global_object_name;
1618 rtx decl_rtl = DECL_RTL (decl);
1620 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1621 name = ggc_strdup (p);
1627 /* Output assembler code for the constant pool of a function and associated
1628 with defining the name of the function. DECL describes the function.
1629 NAME is the function's name. For the constant pool, we use the current
1630 constant pool data. */
1633 assemble_start_function (tree decl, const char *fnname)
1636 char tmp_label[100];
1637 bool hot_label_written = false;
1639 crtl->subsections.unlikely_text_section_name = NULL;
1641 first_function_block_is_cold = false;
1642 if (flag_reorder_blocks_and_partition)
1644 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1645 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1646 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1647 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1648 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1649 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1650 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1651 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1656 crtl->subsections.hot_section_label = NULL;
1657 crtl->subsections.cold_section_label = NULL;
1658 crtl->subsections.hot_section_end_label = NULL;
1659 crtl->subsections.cold_section_end_label = NULL;
1662 /* The following code does not need preprocessing in the assembler. */
1666 if (CONSTANT_POOL_BEFORE_FUNCTION)
1667 output_constant_pool (fnname, decl);
1669 resolve_unique_section (decl, 0, flag_function_sections);
1671 /* Make sure the not and cold text (code) sections are properly
1672 aligned. This is necessary here in the case where the function
1673 has both hot and cold sections, because we don't want to re-set
1674 the alignment when the section switch happens mid-function. */
1676 if (flag_reorder_blocks_and_partition)
1678 switch_to_section (unlikely_text_section ());
1679 assemble_align (DECL_ALIGN (decl));
1680 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1682 /* When the function starts with a cold section, we need to explicitly
1683 align the hot section and write out the hot section label.
1684 But if the current function is a thunk, we do not have a CFG. */
1686 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1688 switch_to_section (text_section);
1689 assemble_align (DECL_ALIGN (decl));
1690 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1691 hot_label_written = true;
1692 first_function_block_is_cold = true;
1695 else if (DECL_SECTION_NAME (decl))
1697 /* Calls to function_section rely on first_function_block_is_cold
1698 being accurate. The first block may be cold even if we aren't
1699 doing partitioning, if the entire function was decided by
1700 choose_function_section (predict.c) to be cold. */
1702 initialize_cold_section_name ();
1704 if (crtl->subsections.unlikely_text_section_name
1705 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1706 crtl->subsections.unlikely_text_section_name) == 0)
1707 first_function_block_is_cold = true;
1710 in_cold_section_p = first_function_block_is_cold;
1712 /* Switch to the correct text section for the start of the function. */
1714 switch_to_section (function_section (decl));
1715 if (flag_reorder_blocks_and_partition
1716 && !hot_label_written)
1717 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1719 /* Tell assembler to move to target machine's alignment for functions. */
1720 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1723 ASM_OUTPUT_ALIGN (asm_out_file, align);
1726 /* Handle a user-specified function alignment.
1727 Note that we still need to align to DECL_ALIGN, as above,
1728 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1729 if (! DECL_USER_ALIGN (decl)
1730 && align_functions_log > align
1731 && optimize_function_for_speed_p (cfun))
1733 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1734 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1735 align_functions_log, align_functions - 1);
1737 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1741 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1742 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1745 (*debug_hooks->begin_function) (decl);
1747 /* Make function name accessible from other files, if appropriate. */
1749 if (TREE_PUBLIC (decl))
1751 notice_global_symbol (decl);
1753 globalize_decl (decl);
1755 maybe_assemble_visibility (decl);
1758 if (DECL_PRESERVE_P (decl))
1759 targetm.asm_out.mark_decl_preserved (fnname);
1761 /* Do any machine/system dependent processing of the function name. */
1762 #ifdef ASM_DECLARE_FUNCTION_NAME
1763 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1765 /* Standard thing is just output label for the function. */
1766 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1767 #endif /* ASM_DECLARE_FUNCTION_NAME */
1770 /* Output assembler code associated with defining the size of the
1771 function. DECL describes the function. NAME is the function's name. */
1774 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1776 #ifdef ASM_DECLARE_FUNCTION_SIZE
1777 /* We could have switched section in the middle of the function. */
1778 if (flag_reorder_blocks_and_partition)
1779 switch_to_section (function_section (decl));
1780 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1782 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1784 output_constant_pool (fnname, decl);
1785 switch_to_section (function_section (decl)); /* need to switch back */
1787 /* Output labels for end of hot/cold text sections (to be used by
1789 if (flag_reorder_blocks_and_partition)
1791 section *save_text_section;
1793 save_text_section = in_section;
1794 switch_to_section (unlikely_text_section ());
1795 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1796 if (first_function_block_is_cold)
1797 switch_to_section (text_section);
1799 switch_to_section (function_section (decl));
1800 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1801 switch_to_section (save_text_section);
1805 /* Assemble code to leave SIZE bytes of zeros. */
1808 assemble_zeros (unsigned HOST_WIDE_INT size)
1810 /* Do no output if -fsyntax-only. */
1811 if (flag_syntax_only)
1814 #ifdef ASM_NO_SKIP_IN_TEXT
1815 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1816 so we must output 0s explicitly in the text section. */
1817 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1819 unsigned HOST_WIDE_INT i;
1820 for (i = 0; i < size; i++)
1821 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1826 ASM_OUTPUT_SKIP (asm_out_file, size);
1829 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1832 assemble_align (int align)
1834 if (align > BITS_PER_UNIT)
1836 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1840 /* Assemble a string constant with the specified C string as contents. */
1843 assemble_string (const char *p, int size)
1848 /* If the string is very long, split it up. */
1852 int thissize = size - pos;
1853 if (thissize > maximum)
1856 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1864 /* A noswitch_section_callback for lcomm_section. */
1867 emit_local (tree decl ATTRIBUTE_UNUSED,
1868 const char *name ATTRIBUTE_UNUSED,
1869 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1870 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1872 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1873 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1874 size, DECL_ALIGN (decl));
1876 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1877 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1880 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1885 /* A noswitch_section_callback for bss_noswitch_section. */
1887 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1889 emit_bss (tree decl ATTRIBUTE_UNUSED,
1890 const char *name ATTRIBUTE_UNUSED,
1891 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1892 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1894 #if defined ASM_OUTPUT_ALIGNED_BSS
1895 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1898 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1904 /* A noswitch_section_callback for comm_section. */
1907 emit_common (tree decl ATTRIBUTE_UNUSED,
1908 const char *name ATTRIBUTE_UNUSED,
1909 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1910 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1912 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1913 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1914 size, DECL_ALIGN (decl));
1916 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1917 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1920 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1925 /* A noswitch_section_callback for tls_comm_section. */
1928 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1929 const char *name ATTRIBUTE_UNUSED,
1930 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1931 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1933 #ifdef ASM_OUTPUT_TLS_COMMON
1934 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1937 sorry ("thread-local COMMON data not implemented");
1942 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1943 NAME is the name of DECL's SYMBOL_REF. */
1946 assemble_noswitch_variable (tree decl, const char *name, section *sect)
1948 unsigned HOST_WIDE_INT size, rounded;
1950 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1953 /* Don't allocate zero bytes of common,
1954 since that means "undefined external" in the linker. */
1958 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1959 so that each uninitialized object starts on such a boundary. */
1960 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1961 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1962 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1964 if (!sect->noswitch.callback (decl, name, size, rounded)
1965 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1966 warning (0, "requested alignment for %q+D is greater than "
1967 "implemented alignment of %wu", decl, rounded);
1970 /* A subroutine of assemble_variable. Output the label and contents of
1971 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1972 is as for assemble_variable. */
1975 assemble_variable_contents (tree decl, const char *name,
1976 bool dont_output_data)
1978 /* Do any machine/system dependent processing of the object. */
1979 #ifdef ASM_DECLARE_OBJECT_NAME
1980 last_assemble_variable_decl = decl;
1981 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1983 /* Standard thing is just output label for the object. */
1984 ASM_OUTPUT_LABEL (asm_out_file, name);
1985 #endif /* ASM_DECLARE_OBJECT_NAME */
1987 if (!dont_output_data)
1989 if (DECL_INITIAL (decl)
1990 && DECL_INITIAL (decl) != error_mark_node
1991 && !initializer_zerop (DECL_INITIAL (decl)))
1992 /* Output the actual data. */
1993 output_constant (DECL_INITIAL (decl),
1994 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1997 /* Leave space for it. */
1998 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
2002 /* Initialize emulated tls object TO, which refers to TLS variable
2003 DECL and is initialized by PROXY. */
2006 default_emutls_var_init (tree to, tree decl, tree proxy)
2008 VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4);
2009 constructor_elt *elt;
2010 tree type = TREE_TYPE (to);
2011 tree field = TYPE_FIELDS (type);
2013 elt = VEC_quick_push (constructor_elt, v, NULL);
2015 elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
2017 elt = VEC_quick_push (constructor_elt, v, NULL);
2018 field = TREE_CHAIN (field);
2020 elt->value = build_int_cst (TREE_TYPE (field),
2021 DECL_ALIGN_UNIT (decl));
2023 elt = VEC_quick_push (constructor_elt, v, NULL);
2024 field = TREE_CHAIN (field);
2026 elt->value = null_pointer_node;
2028 elt = VEC_quick_push (constructor_elt, v, NULL);
2029 field = TREE_CHAIN (field);
2033 return build_constructor (type, v);
2036 /* Assemble everything that is needed for a variable or function declaration.
2037 Not used for automatic variables, and not used for function definitions.
2038 Should not be called for variables of incomplete structure type.
2040 TOP_LEVEL is nonzero if this variable has file scope.
2041 AT_END is nonzero if this is the special handling, at end of compilation,
2042 to define things that have had only tentative definitions.
2043 DONT_OUTPUT_DATA if nonzero means don't actually output the
2044 initial value (that will be done by the caller). */
2047 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2048 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2051 rtx decl_rtl, symbol;
2054 if (! targetm.have_tls
2055 && TREE_CODE (decl) == VAR_DECL
2056 && DECL_THREAD_LOCAL_P (decl))
2058 tree to = emutls_decl (decl);
2060 /* If this variable is defined locally, then we need to initialize the
2061 control structure with size and alignment information. We do this
2062 at the last moment because tentative definitions can take a locally
2063 defined but uninitialized variable and initialize it later, which
2064 would result in incorrect contents. */
2065 if (! DECL_EXTERNAL (to)
2066 && (! DECL_COMMON (to)
2067 || (DECL_INITIAL (decl)
2068 && DECL_INITIAL (decl) != error_mark_node)))
2070 DECL_INITIAL (to) = targetm.emutls.var_init
2071 (to, decl, get_emutls_init_templ_addr (decl));
2073 /* Make sure the template is marked as needed early enough.
2074 Without this, if the variable is placed in a
2075 section-anchored block, the template will only be marked
2076 when it's too late. */
2077 record_references_in_initializer (to);
2083 last_assemble_variable_decl = 0;
2085 /* Normally no need to say anything here for external references,
2086 since assemble_external is called by the language-specific code
2087 when a declaration is first seen. */
2089 if (DECL_EXTERNAL (decl))
2092 /* Output no assembler code for a function declaration.
2093 Only definitions of functions output anything. */
2095 if (TREE_CODE (decl) == FUNCTION_DECL)
2098 /* Do nothing for global register variables. */
2099 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2101 TREE_ASM_WRITTEN (decl) = 1;
2105 /* If type was incomplete when the variable was declared,
2106 see if it is complete now. */
2108 if (DECL_SIZE (decl) == 0)
2109 layout_decl (decl, 0);
2111 /* Still incomplete => don't allocate it; treat the tentative defn
2112 (which is what it must have been) as an `extern' reference. */
2114 if (!dont_output_data && DECL_SIZE (decl) == 0)
2116 error ("storage size of %q+D isn%'t known", decl);
2117 TREE_ASM_WRITTEN (decl) = 1;
2121 /* The first declaration of a variable that comes through this function
2122 decides whether it is global (in C, has external linkage)
2123 or local (in C, has internal linkage). So do nothing more
2124 if this function has already run. */
2126 if (TREE_ASM_WRITTEN (decl))
2129 /* Make sure targetm.encode_section_info is invoked before we set
2131 decl_rtl = DECL_RTL (decl);
2133 TREE_ASM_WRITTEN (decl) = 1;
2135 /* Do no output if -fsyntax-only. */
2136 if (flag_syntax_only)
2141 if (! dont_output_data
2142 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2144 error ("size of variable %q+D is too large", decl);
2148 gcc_assert (MEM_P (decl_rtl));
2149 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2150 symbol = XEXP (decl_rtl, 0);
2151 name = XSTR (symbol, 0);
2152 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2153 notice_global_symbol (decl);
2155 /* Compute the alignment of this data. */
2157 align_variable (decl, dont_output_data);
2158 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2160 if (TREE_PUBLIC (decl))
2161 maybe_assemble_visibility (decl);
2163 if (DECL_PRESERVE_P (decl))
2164 targetm.asm_out.mark_decl_preserved (name);
2166 /* First make the assembler name(s) global if appropriate. */
2167 sect = get_variable_section (decl, false);
2168 if (TREE_PUBLIC (decl)
2169 && (sect->common.flags & SECTION_COMMON) == 0)
2170 globalize_decl (decl);
2172 /* Output any data that we will need to use the address of. */
2173 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2174 output_addressed_constants (DECL_INITIAL (decl));
2176 /* dbxout.c needs to know this. */
2177 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2178 DECL_IN_TEXT_SECTION (decl) = 1;
2180 /* If the decl is part of an object_block, make sure that the decl
2181 has been positioned within its block, but do not write out its
2182 definition yet. output_object_blocks will do that later. */
2183 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2185 gcc_assert (!dont_output_data);
2186 place_block_symbol (symbol);
2188 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2189 assemble_noswitch_variable (decl, name, sect);
2192 switch_to_section (sect);
2193 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2194 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2195 assemble_variable_contents (decl, name, dont_output_data);
2199 /* Return 1 if type TYPE contains any pointers. */
2202 contains_pointers_p (tree type)
2204 switch (TREE_CODE (type))
2207 case REFERENCE_TYPE:
2208 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2209 so I'll play safe and return 1. */
2215 case QUAL_UNION_TYPE:
2218 /* For a type that has fields, see if the fields have pointers. */
2219 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2220 if (TREE_CODE (fields) == FIELD_DECL
2221 && contains_pointers_p (TREE_TYPE (fields)))
2227 /* An array type contains pointers if its element type does. */
2228 return contains_pointers_p (TREE_TYPE (type));
2235 /* We delay assemble_external processing until
2236 the compilation unit is finalized. This is the best we can do for
2237 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2238 it all the way to final. See PR 17982 for further discussion. */
2239 static GTY(()) tree pending_assemble_externals;
2241 #ifdef ASM_OUTPUT_EXTERNAL
2242 /* True if DECL is a function decl for which no out-of-line copy exists.
2243 It is assumed that DECL's assembler name has been set. */
2246 incorporeal_function_p (tree decl)
2248 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2252 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2253 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2256 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2257 if (is_builtin_name (name))
2263 /* Actually do the tests to determine if this is necessary, and invoke
2264 ASM_OUTPUT_EXTERNAL. */
2266 assemble_external_real (tree decl)
2268 rtx rtl = DECL_RTL (decl);
2270 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2271 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2272 && !incorporeal_function_p (decl))
2274 /* Some systems do require some output. */
2275 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2276 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2282 process_pending_assemble_externals (void)
2284 #ifdef ASM_OUTPUT_EXTERNAL
2286 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2287 assemble_external_real (TREE_VALUE (list));
2289 pending_assemble_externals = 0;
2293 /* This TREE_LIST contains any weak symbol declarations waiting
2295 static GTY(()) tree weak_decls;
2297 /* Output something to declare an external symbol to the assembler,
2298 and qualifiers such as weakness. (Most assemblers don't need
2299 extern declaration, so we normally output nothing.) Do nothing if
2300 DECL is not external. */
2303 assemble_external (tree decl ATTRIBUTE_UNUSED)
2305 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2306 main body of this code is only rarely exercised. To provide some
2307 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2308 open. If it's not, we should not be calling this function. */
2309 gcc_assert (asm_out_file);
2311 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2314 /* We want to output annotation for weak and external symbols at
2315 very last to check if they are references or not. */
2317 if (SUPPORTS_WEAK && DECL_WEAK (decl)
2318 /* TREE_STATIC is a weird and abused creature which is not
2319 generally the right test for whether an entity has been
2320 locally emitted, inlined or otherwise not-really-extern, but
2321 for declarations that can be weak, it happens to be
2323 && !TREE_STATIC (decl)
2324 && tree_find_value (weak_decls, decl) == NULL_TREE)
2325 weak_decls = tree_cons (NULL, decl, weak_decls);
2327 #ifdef ASM_OUTPUT_EXTERNAL
2328 if (tree_find_value (pending_assemble_externals, decl) == NULL_TREE)
2329 pending_assemble_externals = tree_cons (NULL, decl,
2330 pending_assemble_externals);
2334 /* Similar, for calling a library function FUN. */
2337 assemble_external_libcall (rtx fun)
2339 /* Declare library function name external when first used, if nec. */
2340 if (! SYMBOL_REF_USED (fun))
2342 SYMBOL_REF_USED (fun) = 1;
2343 targetm.asm_out.external_libcall (fun);
2347 /* Assemble a label named NAME. */
2350 assemble_label (const char *name)
2352 ASM_OUTPUT_LABEL (asm_out_file, name);
2355 /* Set the symbol_referenced flag for ID. */
2357 mark_referenced (tree id)
2359 TREE_SYMBOL_REFERENCED (id) = 1;
2362 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2364 mark_decl_referenced (tree decl)
2366 if (TREE_CODE (decl) == FUNCTION_DECL)
2368 /* Extern inline functions don't become needed when referenced.
2369 If we know a method will be emitted in other TU and no new
2370 functions can be marked reachable, just use the external
2372 struct cgraph_node *node = cgraph_node (decl);
2373 if (!DECL_EXTERNAL (decl)
2374 && (!node->local.vtable_method || !cgraph_global_info_ready
2375 || !node->local.finalized))
2376 cgraph_mark_needed_node (node);
2378 else if (TREE_CODE (decl) == VAR_DECL)
2380 struct varpool_node *node = varpool_node (decl);
2381 varpool_mark_needed_node (node);
2382 /* C++ frontend use mark_decl_references to force COMDAT variables
2383 to be output that might appear dead otherwise. */
2384 node->force_output = true;
2386 /* else do nothing - we can get various sorts of CST nodes here,
2387 which do not need to be marked. */
2391 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2392 until we find an identifier that is not itself a transparent alias.
2393 Modify the alias passed to it by reference (and all aliases on the
2394 way to the ultimate target), such that they do not have to be
2395 followed again, and return the ultimate target of the alias
2399 ultimate_transparent_alias_target (tree *alias)
2401 tree target = *alias;
2403 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2405 gcc_assert (TREE_CHAIN (target));
2406 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2407 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2408 && ! TREE_CHAIN (target));
2415 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2416 starts with a *, the rest of NAME is output verbatim. Otherwise
2417 NAME is transformed in a target-specific way (usually by the
2418 addition of an underscore). */
2421 assemble_name_raw (FILE *file, const char *name)
2424 fputs (&name[1], file);
2426 ASM_OUTPUT_LABELREF (file, name);
2429 /* Like assemble_name_raw, but should be used when NAME might refer to
2430 an entity that is also represented as a tree (like a function or
2431 variable). If NAME does refer to such an entity, that entity will
2432 be marked as referenced. */
2435 assemble_name (FILE *file, const char *name)
2437 const char *real_name;
2440 real_name = targetm.strip_name_encoding (name);
2442 id = maybe_get_identifier (real_name);
2447 mark_referenced (id);
2448 ultimate_transparent_alias_target (&id);
2450 name = IDENTIFIER_POINTER (id);
2451 gcc_assert (! TREE_CHAIN (id));
2454 assemble_name_raw (file, name);
2457 /* Allocate SIZE bytes writable static space with a gensym name
2458 and return an RTX to refer to its address. */
2461 assemble_static_space (unsigned HOST_WIDE_INT size)
2464 const char *namestring;
2467 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2469 namestring = ggc_strdup (name);
2471 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2472 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2474 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2475 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2478 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2479 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2482 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2483 so that each uninitialized object starts on such a boundary. */
2484 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2485 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2486 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2487 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2488 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2489 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2496 /* Assemble the static constant template for function entry trampolines.
2497 This is done at most once per compilation.
2498 Returns an RTX for the address of the template. */
2500 static GTY(()) rtx initial_trampoline;
2502 #ifdef TRAMPOLINE_TEMPLATE
2504 assemble_trampoline_template (void)
2511 if (initial_trampoline)
2512 return initial_trampoline;
2514 /* By default, put trampoline templates in read-only data section. */
2516 #ifdef TRAMPOLINE_SECTION
2517 switch_to_section (TRAMPOLINE_SECTION);
2519 switch_to_section (readonly_data_section);
2522 /* Write the assembler code to define one. */
2523 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2526 ASM_OUTPUT_ALIGN (asm_out_file, align);
2529 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2530 TRAMPOLINE_TEMPLATE (asm_out_file);
2532 /* Record the rtl to refer to it. */
2533 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2534 name = ggc_strdup (label);
2535 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2536 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2538 initial_trampoline = gen_rtx_MEM (BLKmode, symbol);
2539 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2541 return initial_trampoline;
2545 /* A and B are either alignments or offsets. Return the minimum alignment
2546 that may be assumed after adding the two together. */
2548 static inline unsigned
2549 min_align (unsigned int a, unsigned int b)
2551 return (a | b) & -(a | b);
2554 /* Return the assembler directive for creating a given kind of integer
2555 object. SIZE is the number of bytes in the object and ALIGNED_P
2556 indicates whether it is known to be aligned. Return NULL if the
2557 assembly dialect has no such directive.
2559 The returned string should be printed at the start of a new line and
2560 be followed immediately by the object's initial value. */
2563 integer_asm_op (int size, int aligned_p)
2565 struct asm_int_op *ops;
2568 ops = &targetm.asm_out.aligned_op;
2570 ops = &targetm.asm_out.unaligned_op;
2575 return targetm.asm_out.byte_op;
2589 /* Use directive OP to assemble an integer object X. Print OP at the
2590 start of the line, followed immediately by the value of X. */
2593 assemble_integer_with_op (const char *op, rtx x)
2595 fputs (op, asm_out_file);
2596 output_addr_const (asm_out_file, x);
2597 fputc ('\n', asm_out_file);
2600 /* The default implementation of the asm_out.integer target hook. */
2603 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2604 unsigned int size ATTRIBUTE_UNUSED,
2605 int aligned_p ATTRIBUTE_UNUSED)
2607 const char *op = integer_asm_op (size, aligned_p);
2608 /* Avoid GAS bugs for large values. Specifically negative values whose
2609 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2610 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2612 return op && (assemble_integer_with_op (op, x), true);
2615 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2616 the alignment of the integer in bits. Return 1 if we were able to output
2617 the constant, otherwise 0. We must be able to output the constant,
2618 if FORCE is nonzero. */
2621 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2625 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2627 /* See if the target hook can handle this kind of object. */
2628 if (targetm.asm_out.integer (x, size, aligned_p))
2631 /* If the object is a multi-byte one, try splitting it up. Split
2632 it into words it if is multi-word, otherwise split it into bytes. */
2635 enum machine_mode omode, imode;
2636 unsigned int subalign;
2637 unsigned int subsize, i;
2638 enum mode_class mclass;
2640 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2641 subalign = MIN (align, subsize * BITS_PER_UNIT);
2642 if (GET_CODE (x) == CONST_FIXED)
2643 mclass = GET_MODE_CLASS (GET_MODE (x));
2647 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2648 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2650 for (i = 0; i < size; i += subsize)
2652 rtx partial = simplify_subreg (omode, x, imode, i);
2653 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2659 /* If we've printed some of it, but not all of it, there's no going
2664 gcc_assert (!force);
2670 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2672 long data[4] = {0, 0, 0, 0};
2674 int bitsize, nelts, nunits, units_per;
2676 /* This is hairy. We have a quantity of known size. real_to_target
2677 will put it into an array of *host* longs, 32 bits per element
2678 (even if long is more than 32 bits). We need to determine the
2679 number of array elements that are occupied (nelts) and the number
2680 of *target* min-addressable units that will be occupied in the
2681 object file (nunits). We cannot assume that 32 divides the
2682 mode's bitsize (size * BITS_PER_UNIT) evenly.
2684 size * BITS_PER_UNIT is used here to make sure that padding bits
2685 (which might appear at either end of the value; real_to_target
2686 will include the padding bits in its output array) are included. */
2688 nunits = GET_MODE_SIZE (mode);
2689 bitsize = nunits * BITS_PER_UNIT;
2690 nelts = CEIL (bitsize, 32);
2691 units_per = 32 / BITS_PER_UNIT;
2693 real_to_target (data, &d, mode);
2695 /* Put out the first word with the specified alignment. */
2696 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2697 nunits -= units_per;
2699 /* Subsequent words need only 32-bit alignment. */
2700 align = min_align (align, 32);
2702 for (i = 1; i < nelts; i++)
2704 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2705 nunits -= units_per;
2709 /* Given an expression EXP with a constant value,
2710 reduce it to the sum of an assembler symbol and an integer.
2711 Store them both in the structure *VALUE.
2712 EXP must be reducible. */
2714 struct GTY(()) addr_const {
2716 HOST_WIDE_INT offset;
2720 decode_addr_const (tree exp, struct addr_const *value)
2722 tree target = TREE_OPERAND (exp, 0);
2728 if (TREE_CODE (target) == COMPONENT_REF
2729 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2732 offset += int_byte_position (TREE_OPERAND (target, 1));
2733 target = TREE_OPERAND (target, 0);
2735 else if (TREE_CODE (target) == ARRAY_REF
2736 || TREE_CODE (target) == ARRAY_RANGE_REF)
2738 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2739 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2740 target = TREE_OPERAND (target, 0);
2746 switch (TREE_CODE (target))
2750 x = DECL_RTL (target);
2754 x = gen_rtx_MEM (FUNCTION_MODE,
2755 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2764 x = output_constant_def (target, 1);
2771 gcc_assert (MEM_P (x));
2775 value->offset = offset;
2778 /* Uniquize all constants that appear in memory.
2779 Each constant in memory thus far output is recorded
2780 in `const_desc_table'. */
2782 struct GTY(()) constant_descriptor_tree {
2783 /* A MEM for the constant. */
2786 /* The value of the constant. */
2789 /* Hash of value. Computing the hash from value each time
2790 hashfn is called can't work properly, as that means recursive
2791 use of the hash table during hash table expansion. */
2795 static GTY((param_is (struct constant_descriptor_tree)))
2796 htab_t const_desc_htab;
2798 static struct constant_descriptor_tree * build_constant_desc (tree);
2799 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2801 /* Compute a hash code for a constant expression. */
2804 const_desc_hash (const void *ptr)
2806 return ((const struct constant_descriptor_tree *)ptr)->hash;
2810 const_hash_1 (const tree exp)
2815 enum tree_code code = TREE_CODE (exp);
2817 /* Either set P and LEN to the address and len of something to hash and
2818 exit the switch or return a value. */
2823 p = (char *) &TREE_INT_CST (exp);
2824 len = sizeof TREE_INT_CST (exp);
2828 return real_hash (TREE_REAL_CST_PTR (exp));
2831 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2834 p = TREE_STRING_POINTER (exp);
2835 len = TREE_STRING_LENGTH (exp);
2839 return (const_hash_1 (TREE_REALPART (exp)) * 5
2840 + const_hash_1 (TREE_IMAGPART (exp)));
2844 unsigned HOST_WIDE_INT idx;
2847 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2849 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2851 hi = hi * 603 + const_hash_1 (value);
2859 struct addr_const value;
2861 decode_addr_const (exp, &value);
2862 switch (GET_CODE (value.base))
2865 /* Don't hash the address of the SYMBOL_REF;
2866 only use the offset and the symbol name. */
2868 p = XSTR (value.base, 0);
2869 for (i = 0; p[i] != 0; i++)
2870 hi = ((hi * 613) + (unsigned) (p[i]));
2874 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2884 case POINTER_PLUS_EXPR:
2886 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2887 + const_hash_1 (TREE_OPERAND (exp, 1)));
2890 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2893 /* A language specific constant. Just hash the code. */
2897 /* Compute hashing function. */
2899 for (i = 0; i < len; i++)
2900 hi = ((hi * 613) + (unsigned) (p[i]));
2905 /* Wrapper of compare_constant, for the htab interface. */
2907 const_desc_eq (const void *p1, const void *p2)
2909 const struct constant_descriptor_tree *const c1
2910 = (const struct constant_descriptor_tree *) p1;
2911 const struct constant_descriptor_tree *const c2
2912 = (const struct constant_descriptor_tree *) p2;
2913 if (c1->hash != c2->hash)
2915 return compare_constant (c1->value, c2->value);
2918 /* Compare t1 and t2, and return 1 only if they are known to result in
2919 the same bit pattern on output. */
2922 compare_constant (const tree t1, const tree t2)
2924 enum tree_code typecode;
2926 if (t1 == NULL_TREE)
2927 return t2 == NULL_TREE;
2928 if (t2 == NULL_TREE)
2931 if (TREE_CODE (t1) != TREE_CODE (t2))
2934 switch (TREE_CODE (t1))
2937 /* Integer constants are the same only if the same width of type. */
2938 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2940 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2942 return tree_int_cst_equal (t1, t2);
2945 /* Real constants are the same only if the same width of type. */
2946 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2949 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2952 /* Fixed constants are the same only if the same width of type. */
2953 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2956 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
2959 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2962 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2963 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2964 TREE_STRING_LENGTH (t1)));
2967 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2968 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2972 VEC(constructor_elt, gc) *v1, *v2;
2973 unsigned HOST_WIDE_INT idx;
2975 typecode = TREE_CODE (TREE_TYPE (t1));
2976 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2979 if (typecode == ARRAY_TYPE)
2981 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2982 /* For arrays, check that the sizes all match. */
2983 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2985 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2990 /* For record and union constructors, require exact type
2992 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2996 v1 = CONSTRUCTOR_ELTS (t1);
2997 v2 = CONSTRUCTOR_ELTS (t2);
2998 if (VEC_length (constructor_elt, v1)
2999 != VEC_length (constructor_elt, v2))
3002 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
3004 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
3005 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
3007 /* Check that each value is the same... */
3008 if (!compare_constant (c1->value, c2->value))
3010 /* ... and that they apply to the same fields! */
3011 if (typecode == ARRAY_TYPE)
3013 if (!compare_constant (c1->index, c2->index))
3018 if (c1->index != c2->index)
3029 struct addr_const value1, value2;
3031 decode_addr_const (t1, &value1);
3032 decode_addr_const (t2, &value2);
3033 return (value1.offset == value2.offset
3034 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3038 case POINTER_PLUS_EXPR:
3041 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3042 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3045 case VIEW_CONVERT_EXPR:
3046 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3055 /* Make a copy of the whole tree structure for a constant. This
3056 handles the same types of nodes that compare_constant handles. */
3059 copy_constant (tree exp)
3061 switch (TREE_CODE (exp))
3064 /* For ADDR_EXPR, we do not want to copy the decl whose address
3065 is requested. We do want to copy constants though. */
3066 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3067 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3068 copy_constant (TREE_OPERAND (exp, 0)));
3070 return copy_node (exp);
3076 return copy_node (exp);
3079 return build_complex (TREE_TYPE (exp),
3080 copy_constant (TREE_REALPART (exp)),
3081 copy_constant (TREE_IMAGPART (exp)));
3084 case POINTER_PLUS_EXPR:
3086 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3087 copy_constant (TREE_OPERAND (exp, 0)),
3088 copy_constant (TREE_OPERAND (exp, 1)));
3091 case VIEW_CONVERT_EXPR:
3092 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3093 copy_constant (TREE_OPERAND (exp, 0)));
3097 tree copy = copy_node (exp);
3098 VEC(constructor_elt, gc) *v;
3099 unsigned HOST_WIDE_INT idx;
3100 tree purpose, value;
3102 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3103 CONSTRUCTOR_ELTS (exp)));
3104 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3106 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3107 ce->index = purpose;
3108 ce->value = copy_constant (value);
3110 CONSTRUCTOR_ELTS (copy) = v;
3119 /* Return the alignment of constant EXP in bits. */
3122 get_constant_alignment (tree exp)
3126 align = TYPE_ALIGN (TREE_TYPE (exp));
3127 #ifdef CONSTANT_ALIGNMENT
3128 align = CONSTANT_ALIGNMENT (exp, align);
3133 /* Return the section into which constant EXP should be placed. */
3136 get_constant_section (tree exp)
3138 if (IN_NAMED_SECTION (exp))
3139 return get_named_section (exp, NULL, compute_reloc_for_constant (exp));
3141 return targetm.asm_out.select_section (exp,
3142 compute_reloc_for_constant (exp),
3143 get_constant_alignment (exp));
3146 /* Return the size of constant EXP in bytes. */
3148 static HOST_WIDE_INT
3149 get_constant_size (tree exp)
3153 size = int_size_in_bytes (TREE_TYPE (exp));
3154 if (TREE_CODE (exp) == STRING_CST)
3155 size = MAX (TREE_STRING_LENGTH (exp), size);
3159 /* Subroutine of output_constant_def:
3160 No constant equal to EXP is known to have been output.
3161 Make a constant descriptor to enter EXP in the hash table.
3162 Assign the label number and construct RTL to refer to the
3163 constant's location in memory.
3164 Caller is responsible for updating the hash table. */
3166 static struct constant_descriptor_tree *
3167 build_constant_desc (tree exp)
3173 struct constant_descriptor_tree *desc;
3175 desc = GGC_NEW (struct constant_descriptor_tree);
3176 desc->value = copy_constant (exp);
3178 /* Propagate marked-ness to copied constant. */
3179 if (flag_mudflap && mf_marked_p (exp))
3180 mf_mark (desc->value);
3182 /* Create a string containing the label name, in LABEL. */
3183 labelno = const_labelno++;
3184 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3186 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3187 if (use_object_blocks_p ())
3189 section *sect = get_constant_section (exp);
3190 symbol = create_block_symbol (ggc_strdup (label),
3191 get_block_for_section (sect), -1);
3194 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3195 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3196 SET_SYMBOL_REF_DECL (symbol, desc->value);
3197 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3199 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3200 set_mem_attributes (rtl, exp, 1);
3201 set_mem_alias_set (rtl, 0);
3202 set_mem_alias_set (rtl, const_alias_set);
3204 /* Set flags or add text to the name to record information, such as
3205 that it is a local symbol. If the name is changed, the macro
3206 ASM_OUTPUT_LABELREF will have to know how to strip this
3207 information. This call might invalidate our local variable
3208 SYMBOL; we can't use it afterward. */
3210 targetm.encode_section_info (exp, rtl, true);
3217 /* Return an rtx representing a reference to constant data in memory
3218 for the constant expression EXP.
3220 If assembler code for such a constant has already been output,
3221 return an rtx to refer to it.
3222 Otherwise, output such a constant in memory
3223 and generate an rtx for it.
3225 If DEFER is nonzero, this constant can be deferred and output only
3226 if referenced in the function after all optimizations.
3228 `const_desc_table' records which constants already have label strings. */
3231 output_constant_def (tree exp, int defer)
3233 struct constant_descriptor_tree *desc;
3234 struct constant_descriptor_tree key;
3237 /* Look up EXP in the table of constant descriptors. If we didn't find
3238 it, create a new one. */
3240 key.hash = const_hash_1 (exp);
3241 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3243 desc = (struct constant_descriptor_tree *) *loc;
3246 desc = build_constant_desc (exp);
3247 desc->hash = key.hash;
3251 maybe_output_constant_def_contents (desc, defer);
3255 /* Subroutine of output_constant_def: Decide whether or not we need to
3256 output the constant DESC now, and if so, do it. */
3258 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3261 rtx symbol = XEXP (desc->rtl, 0);
3262 tree exp = desc->value;
3264 if (flag_syntax_only)
3267 if (TREE_ASM_WRITTEN (exp))
3268 /* Already output; don't do it again. */
3271 /* We can always defer constants as long as the context allows
3275 /* Increment n_deferred_constants if it exists. It needs to be at
3276 least as large as the number of constants actually referred to
3277 by the function. If it's too small we'll stop looking too early
3278 and fail to emit constants; if it's too large we'll only look
3279 through the entire function when we could have stopped earlier. */
3281 n_deferred_constants++;
3285 output_constant_def_contents (symbol);
3288 /* Subroutine of output_constant_def_contents. Output the definition
3289 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3290 constant's alignment in bits. */
3293 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3297 size = get_constant_size (exp);
3299 /* Do any machine/system dependent processing of the constant. */
3300 #ifdef ASM_DECLARE_CONSTANT_NAME
3301 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
3303 /* Standard thing is just output label for the constant. */
3304 ASM_OUTPUT_LABEL (asm_out_file, label);
3305 #endif /* ASM_DECLARE_CONSTANT_NAME */
3307 /* Output the value of EXP. */
3308 output_constant (exp, size, align);
3311 /* We must output the constant data referred to by SYMBOL; do so. */
3314 output_constant_def_contents (rtx symbol)
3316 tree exp = SYMBOL_REF_DECL (symbol);
3319 /* Make sure any other constants whose addresses appear in EXP
3320 are assigned label numbers. */
3321 output_addressed_constants (exp);
3323 /* We are no longer deferring this constant. */
3324 TREE_ASM_WRITTEN (exp) = 1;
3326 /* If the constant is part of an object block, make sure that the
3327 decl has been positioned within its block, but do not write out
3328 its definition yet. output_object_blocks will do that later. */
3329 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3330 place_block_symbol (symbol);
3333 switch_to_section (get_constant_section (exp));
3334 align = get_constant_alignment (exp);
3335 if (align > BITS_PER_UNIT)
3336 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3337 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3340 mudflap_enqueue_constant (exp);
3343 /* Look up EXP in the table of constant descriptors. Return the rtl
3344 if it has been emitted, else null. */
3347 lookup_constant_def (tree exp)
3349 struct constant_descriptor_tree *desc;
3350 struct constant_descriptor_tree key;
3353 key.hash = const_hash_1 (exp);
3354 desc = (struct constant_descriptor_tree *)
3355 htab_find_with_hash (const_desc_htab, &key, key.hash);
3357 return (desc ? desc->rtl : NULL_RTX);
3360 /* Used in the hash tables to avoid outputting the same constant
3361 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3362 are output once per function, not once per file. */
3363 /* ??? Only a few targets need per-function constant pools. Most
3364 can use one per-file pool. Should add a targetm bit to tell the
3367 struct GTY(()) rtx_constant_pool {
3368 /* Pointers to first and last constant in pool, as ordered by offset. */
3369 struct constant_descriptor_rtx *first;
3370 struct constant_descriptor_rtx *last;
3372 /* Hash facility for making memory-constants from constant rtl-expressions.
3373 It is used on RISC machines where immediate integer arguments and
3374 constant addresses are restricted so that such constants must be stored
3376 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3378 /* Current offset in constant pool (does not include any
3379 machine-specific header). */
3380 HOST_WIDE_INT offset;
3383 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3384 struct constant_descriptor_rtx *next;
3388 HOST_WIDE_INT offset;
3390 enum machine_mode mode;
3396 /* Hash and compare functions for const_rtx_htab. */
3399 const_desc_rtx_hash (const void *ptr)
3401 const struct constant_descriptor_rtx *const desc
3402 = (const struct constant_descriptor_rtx *) ptr;
3407 const_desc_rtx_eq (const void *a, const void *b)
3409 const struct constant_descriptor_rtx *const x
3410 = (const struct constant_descriptor_rtx *) a;
3411 const struct constant_descriptor_rtx *const y
3412 = (const struct constant_descriptor_rtx *) b;
3414 if (x->mode != y->mode)
3416 return rtx_equal_p (x->constant, y->constant);
3419 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3422 const_rtx_hash_1 (rtx *xp, void *data)
3424 unsigned HOST_WIDE_INT hwi;
3425 enum machine_mode mode;
3431 code = GET_CODE (x);
3432 mode = GET_MODE (x);
3433 h = (hashval_t) code * 1048573 + mode;
3441 const int shift = sizeof (hashval_t) * CHAR_BIT;
3442 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3445 h ^= (hashval_t) hwi;
3446 for (i = 1; i < n; ++i)
3449 h ^= (hashval_t) hwi;
3455 if (mode == VOIDmode)
3457 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3461 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3465 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3471 for (i = XVECLEN (x, 0); i-- > 0; )
3472 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3477 h ^= htab_hash_string (XSTR (x, 0));
3481 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3485 case UNSPEC_VOLATILE:
3486 h = h * 251 + XINT (x, 1);
3493 hp = (hashval_t *) data;
3494 *hp = *hp * 509 + h;
3498 /* Compute a hash value for X, which should be a constant. */
3501 const_rtx_hash (rtx x)
3504 for_each_rtx (&x, const_rtx_hash_1, &h);
3509 /* Create and return a new rtx constant pool. */
3511 static struct rtx_constant_pool *
3512 create_constant_pool (void)
3514 struct rtx_constant_pool *pool;
3516 pool = GGC_NEW (struct rtx_constant_pool);
3517 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3518 const_desc_rtx_eq, NULL);
3525 /* Initialize constant pool hashing for a new function. */
3528 init_varasm_status (void)
3530 crtl->varasm.pool = create_constant_pool ();
3531 crtl->varasm.deferred_constants = 0;
3534 /* Given a MINUS expression, simplify it if both sides
3535 include the same symbol. */
3538 simplify_subtraction (rtx x)
3540 rtx r = simplify_rtx (x);
3544 /* Given a constant rtx X, make (or find) a memory constant for its value
3545 and return a MEM rtx to refer to it in memory. */
3548 force_const_mem (enum machine_mode mode, rtx x)
3550 struct constant_descriptor_rtx *desc, tmp;
3551 struct rtx_constant_pool *pool;
3558 /* If we're not allowed to drop X into the constant pool, don't. */
3559 if (targetm.cannot_force_const_mem (x))
3562 /* Record that this function has used a constant pool entry. */
3563 crtl->uses_const_pool = 1;
3565 /* Decide which pool to use. */
3566 pool = (targetm.use_blocks_for_constant_p (mode, x)
3567 ? shared_constant_pool
3568 : crtl->varasm.pool);
3570 /* Lookup the value in the hashtable. */
3573 hash = const_rtx_hash (x);
3574 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3575 desc = (struct constant_descriptor_rtx *) *slot;
3577 /* If the constant was already present, return its memory. */
3579 return copy_rtx (desc->mem);
3581 /* Otherwise, create a new descriptor. */
3582 desc = GGC_NEW (struct constant_descriptor_rtx);
3585 /* Align the location counter as required by EXP's data type. */
3586 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3587 #ifdef CONSTANT_ALIGNMENT
3589 tree type = lang_hooks.types.type_for_mode (mode, 0);
3590 if (type != NULL_TREE)
3591 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3595 pool->offset += (align / BITS_PER_UNIT) - 1;
3596 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3599 desc->constant = tmp.constant;
3600 desc->offset = pool->offset;
3603 desc->align = align;
3604 desc->labelno = const_labelno;
3607 pool->offset += GET_MODE_SIZE (mode);
3609 pool->last->next = desc;
3611 pool->first = pool->last = desc;
3614 /* Create a string containing the label name, in LABEL. */
3615 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3618 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3619 the constants pool. */
3620 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3622 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3623 symbol = create_block_symbol (ggc_strdup (label),
3624 get_block_for_section (sect), -1);
3627 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3629 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3630 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3631 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3633 /* Construct the MEM. */
3634 desc->mem = def = gen_const_mem (mode, symbol);
3635 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3636 set_mem_align (def, align);
3638 /* If we're dropping a label to the constant pool, make sure we
3640 if (GET_CODE (x) == LABEL_REF)
3641 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3643 return copy_rtx (def);
3646 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3649 get_pool_constant (rtx addr)
3651 return SYMBOL_REF_CONSTANT (addr)->constant;
3654 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3655 and whether it has been output or not. */
3658 get_pool_constant_mark (rtx addr, bool *pmarked)
3660 struct constant_descriptor_rtx *desc;
3662 desc = SYMBOL_REF_CONSTANT (addr);
3663 *pmarked = (desc->mark != 0);
3664 return desc->constant;
3667 /* Similar, return the mode. */
3670 get_pool_mode (const_rtx addr)
3672 return SYMBOL_REF_CONSTANT (addr)->mode;
3675 /* Return the size of the constant pool. */
3678 get_pool_size (void)
3680 return crtl->varasm.pool->offset;
3683 /* Worker function for output_constant_pool_1. Emit assembly for X
3684 in MODE with known alignment ALIGN. */
3687 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3689 switch (GET_MODE_CLASS (mode))
3692 case MODE_DECIMAL_FLOAT:
3696 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3697 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3698 assemble_real (r, mode, align);
3703 case MODE_PARTIAL_INT:
3708 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3711 case MODE_VECTOR_FLOAT:
3712 case MODE_VECTOR_INT:
3713 case MODE_VECTOR_FRACT:
3714 case MODE_VECTOR_UFRACT:
3715 case MODE_VECTOR_ACCUM:
3716 case MODE_VECTOR_UACCUM:
3719 enum machine_mode submode = GET_MODE_INNER (mode);
3720 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3722 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3723 units = CONST_VECTOR_NUNITS (x);
3725 for (i = 0; i < units; i++)
3727 rtx elt = CONST_VECTOR_ELT (x, i);
3728 output_constant_pool_2 (submode, elt, i ? subalign : align);
3738 /* Worker function for output_constant_pool. Emit constant DESC,
3739 giving it ALIGN bits of alignment. */
3742 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3749 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3750 whose CODE_LABEL has been deleted. This can occur if a jump table
3751 is eliminated by optimization. If so, write a constant of zero
3752 instead. Note that this can also happen by turning the
3753 CODE_LABEL into a NOTE. */
3754 /* ??? This seems completely and utterly wrong. Certainly it's
3755 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3756 functioning even with INSN_DELETED_P and friends. */
3759 switch (GET_CODE (tmp))
3762 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3763 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3765 tmp = XEXP (XEXP (tmp, 0), 0);
3769 tmp = XEXP (tmp, 0);
3770 gcc_assert (!INSN_DELETED_P (tmp));
3771 gcc_assert (!NOTE_P (tmp)
3772 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3779 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3780 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3781 align, desc->labelno, done);
3784 assemble_align (align);
3786 /* Output the label. */
3787 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3789 /* Output the data. */
3790 output_constant_pool_2 (desc->mode, x, align);
3792 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3793 sections have proper size. */
3794 if (align > GET_MODE_BITSIZE (desc->mode)
3796 && (in_section->common.flags & SECTION_MERGE))
3797 assemble_align (align);
3799 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3805 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3806 to as used. Emit referenced deferred strings. This function can
3807 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3810 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3812 rtx x = *current_rtx;
3814 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3817 if (CONSTANT_POOL_ADDRESS_P (x))
3819 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3820 if (desc->mark == 0)
3823 for_each_rtx (&desc->constant, mark_constant, NULL);
3826 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3828 tree exp = SYMBOL_REF_DECL (x);
3829 if (!TREE_ASM_WRITTEN (exp))
3831 n_deferred_constants--;
3832 output_constant_def_contents (x);
3839 /* Look through appropriate parts of INSN, marking all entries in the
3840 constant pool which are actually being used. Entries that are only
3841 referenced by other constants are also marked as used. Emit
3842 deferred strings that are used. */
3845 mark_constants (rtx insn)
3850 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3851 insns, not any notes that may be attached. We don't want to mark
3852 a constant just because it happens to appear in a REG_EQUIV note. */
3853 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3855 rtx seq = PATTERN (insn);
3856 int i, n = XVECLEN (seq, 0);
3857 for (i = 0; i < n; ++i)
3859 rtx subinsn = XVECEXP (seq, 0, i);
3860 if (INSN_P (subinsn))
3861 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
3865 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
3868 /* Look through the instructions for this function, and mark all the
3869 entries in POOL which are actually being used. Emit deferred constants
3870 which have indeed been used. */
3873 mark_constant_pool (void)
3877 if (!crtl->uses_const_pool && n_deferred_constants == 0)
3880 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3881 mark_constants (insn);
3883 for (link = crtl->epilogue_delay_list;
3885 link = XEXP (link, 1))
3886 mark_constants (XEXP (link, 0));
3889 /* Write all the constants in POOL. */
3892 output_constant_pool_contents (struct rtx_constant_pool *pool)
3894 struct constant_descriptor_rtx *desc;
3896 for (desc = pool->first; desc ; desc = desc->next)
3899 /* If the constant is part of an object_block, make sure that
3900 the constant has been positioned within its block, but do not
3901 write out its definition yet. output_object_blocks will do
3903 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
3904 && SYMBOL_REF_BLOCK (desc->sym))
3905 place_block_symbol (desc->sym);
3908 switch_to_section (targetm.asm_out.select_rtx_section
3909 (desc->mode, desc->constant, desc->align));
3910 output_constant_pool_1 (desc, desc->align);
3915 /* Mark all constants that are used in the current function, then write
3916 out the function's private constant pool. */
3919 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3920 tree fndecl ATTRIBUTE_UNUSED)
3922 struct rtx_constant_pool *pool = crtl->varasm.pool;
3924 /* It is possible for gcc to call force_const_mem and then to later
3925 discard the instructions which refer to the constant. In such a
3926 case we do not need to output the constant. */
3927 mark_constant_pool ();
3929 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3930 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3933 output_constant_pool_contents (pool);
3935 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3936 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3940 /* Write the contents of the shared constant pool. */
3943 output_shared_constant_pool (void)
3945 output_constant_pool_contents (shared_constant_pool);
3948 /* Determine what kind of relocations EXP may need. */
3951 compute_reloc_for_constant (tree exp)
3953 int reloc = 0, reloc2;
3956 switch (TREE_CODE (exp))
3960 /* Go inside any operations that get_inner_reference can handle and see
3961 if what's inside is a constant: no need to do anything here for
3962 addresses of variables or functions. */
3963 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3964 tem = TREE_OPERAND (tem, 0))
3967 if (TREE_PUBLIC (tem))
3974 case POINTER_PLUS_EXPR:
3975 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3976 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3980 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3981 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3982 /* The difference of two local labels is computable at link time. */
3983 if (reloc == 1 && reloc2 == 1)
3990 case VIEW_CONVERT_EXPR:
3991 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3996 unsigned HOST_WIDE_INT idx;
3997 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
3999 reloc |= compute_reloc_for_constant (tem);
4009 /* Find all the constants whose addresses are referenced inside of EXP,
4010 and make sure assembler code with a label has been output for each one.
4011 Indicate whether an ADDR_EXPR has been encountered. */
4014 output_addressed_constants (tree exp)
4018 switch (TREE_CODE (exp))
4022 /* Go inside any operations that get_inner_reference can handle and see
4023 if what's inside is a constant: no need to do anything here for
4024 addresses of variables or functions. */
4025 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4026 tem = TREE_OPERAND (tem, 0))
4029 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4030 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4031 tem = DECL_INITIAL (tem);
4033 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4034 output_constant_def (tem, 0);
4038 case POINTER_PLUS_EXPR:
4040 output_addressed_constants (TREE_OPERAND (exp, 1));
4044 case VIEW_CONVERT_EXPR:
4045 output_addressed_constants (TREE_OPERAND (exp, 0));
4050 unsigned HOST_WIDE_INT idx;
4051 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4053 output_addressed_constants (tem);
4062 /* Whether a constructor CTOR is a valid static constant initializer if all
4063 its elements are. This used to be internal to initializer_constant_valid_p
4064 and has been exposed to let other functions like categorize_ctor_elements
4065 evaluate the property while walking a constructor for other purposes. */
4068 constructor_static_from_elts_p (const_tree ctor)
4070 return (TREE_CONSTANT (ctor)
4071 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4072 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4073 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4076 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4077 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4078 which are valid when ENDTYPE is an integer of any size; in
4079 particular, this does not accept a pointer minus a constant. This
4080 returns null_pointer_node if the VALUE is an absolute constant
4081 which can be used to initialize a static variable. Otherwise it
4085 narrowing_initializer_constant_valid_p (tree value, tree endtype)
4089 if (!INTEGRAL_TYPE_P (endtype))
4092 op0 = TREE_OPERAND (value, 0);
4093 op1 = TREE_OPERAND (value, 1);
4095 /* Like STRIP_NOPS except allow the operand mode to widen. This
4096 works around a feature of fold that simplifies (int)(p1 - p2) to
4097 ((int)p1 - (int)p2) under the theory that the narrower operation
4100 while (CONVERT_EXPR_P (op0)
4101 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4103 tree inner = TREE_OPERAND (op0, 0);
4104 if (inner == error_mark_node
4105 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4106 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4107 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4112 while (CONVERT_EXPR_P (op1)
4113 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4115 tree inner = TREE_OPERAND (op1, 0);
4116 if (inner == error_mark_node
4117 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4118 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4119 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4124 op0 = initializer_constant_valid_p (op0, endtype);
4125 op1 = initializer_constant_valid_p (op1, endtype);
4127 /* Both initializers must be known. */
4131 && (op0 == null_pointer_node
4132 || TREE_CODE (value) == MINUS_EXPR))
4133 return null_pointer_node;
4135 /* Support differences between labels. */
4136 if (TREE_CODE (op0) == LABEL_DECL
4137 && TREE_CODE (op1) == LABEL_DECL)
4138 return null_pointer_node;
4140 if (TREE_CODE (op0) == STRING_CST
4141 && TREE_CODE (op1) == STRING_CST
4142 && operand_equal_p (op0, op1, 1))
4143 return null_pointer_node;
4149 /* Return nonzero if VALUE is a valid constant-valued expression
4150 for use in initializing a static variable; one that can be an
4151 element of a "constant" initializer.
4153 Return null_pointer_node if the value is absolute;
4154 if it is relocatable, return the variable that determines the relocation.
4155 We assume that VALUE has been folded as much as possible;
4156 therefore, we do not need to check for such things as
4157 arithmetic-combinations of integers. */
4160 initializer_constant_valid_p (tree value, tree endtype)
4164 switch (TREE_CODE (value))
4167 if (constructor_static_from_elts_p (value))
4169 unsigned HOST_WIDE_INT idx;
4171 bool absolute = true;
4173 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4176 reloc = initializer_constant_valid_p (elt, TREE_TYPE (elt));
4179 if (reloc != null_pointer_node)
4182 /* For a non-absolute relocation, there is no single
4183 variable that can be "the variable that determines the
4185 return absolute ? null_pointer_node : error_mark_node;
4188 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4196 return null_pointer_node;
4201 tree op0 = staticp (TREE_OPERAND (value, 0));
4204 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4205 to be a constant, this is old-skool offsetof-like nonsense. */
4206 if (TREE_CODE (op0) == INDIRECT_REF
4207 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4208 return null_pointer_node;
4209 /* Taking the address of a nested function involves a trampoline,
4210 unless we don't need or want one. */
4211 if (TREE_CODE (op0) == FUNCTION_DECL
4212 && decl_function_context (op0)
4213 && !DECL_NO_STATIC_CHAIN (op0)
4214 && !TREE_NO_TRAMPOLINE (value))
4216 /* "&{...}" requires a temporary to hold the constructed
4218 if (TREE_CODE (op0) == CONSTRUCTOR)
4224 case NON_LVALUE_EXPR:
4225 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4227 case VIEW_CONVERT_EXPR:
4229 tree src = TREE_OPERAND (value, 0);
4230 tree src_type = TREE_TYPE (src);
4231 tree dest_type = TREE_TYPE (value);
4233 /* Allow view-conversions from aggregate to non-aggregate type only
4234 if the bit pattern is fully preserved afterwards; otherwise, the
4235 RTL expander won't be able to apply a subsequent transformation
4236 to the underlying constructor. */
4237 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4239 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4240 return initializer_constant_valid_p (src, endtype);
4245 /* Allow all other kinds of view-conversion. */
4246 return initializer_constant_valid_p (src, endtype);
4251 tree src = TREE_OPERAND (value, 0);
4252 tree src_type = TREE_TYPE (src);
4253 tree dest_type = TREE_TYPE (value);
4255 /* Allow conversions between pointer types, floating-point
4256 types, and offset types. */
4257 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4258 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4259 || (TREE_CODE (dest_type) == OFFSET_TYPE
4260 && TREE_CODE (src_type) == OFFSET_TYPE))
4261 return initializer_constant_valid_p (src, endtype);
4263 /* Allow length-preserving conversions between integer types. */
4264 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4265 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4266 return initializer_constant_valid_p (src, endtype);
4268 /* Allow conversions between other integer types only if
4270 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4272 tree inner = initializer_constant_valid_p (src, endtype);
4273 if (inner == null_pointer_node)
4274 return null_pointer_node;
4278 /* Allow (int) &foo provided int is as wide as a pointer. */
4279 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4280 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4281 return initializer_constant_valid_p (src, endtype);
4283 /* Likewise conversions from int to pointers, but also allow
4284 conversions from 0. */
4285 if ((POINTER_TYPE_P (dest_type)
4286 || TREE_CODE (dest_type) == OFFSET_TYPE)
4287 && INTEGRAL_TYPE_P (src_type))
4289 if (TREE_CODE (src) == INTEGER_CST
4290 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4291 return null_pointer_node;
4292 if (integer_zerop (src))
4293 return null_pointer_node;
4294 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4295 return initializer_constant_valid_p (src, endtype);
4298 /* Allow conversions to struct or union types if the value
4300 if (TREE_CODE (dest_type) == RECORD_TYPE
4301 || TREE_CODE (dest_type) == UNION_TYPE)
4302 return initializer_constant_valid_p (src, endtype);
4306 case POINTER_PLUS_EXPR:
4308 if (! INTEGRAL_TYPE_P (endtype)
4309 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4311 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4313 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4315 /* If either term is absolute, use the other term's relocation. */
4316 if (valid0 == null_pointer_node)
4318 if (valid1 == null_pointer_node)
4322 /* Support narrowing pointer differences. */
4323 ret = narrowing_initializer_constant_valid_p (value, endtype);
4324 if (ret != NULL_TREE)
4330 if (! INTEGRAL_TYPE_P (endtype)
4331 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4333 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4335 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4337 /* Win if second argument is absolute. */
4338 if (valid1 == null_pointer_node)
4340 /* Win if both arguments have the same relocation.
4341 Then the value is absolute. */
4342 if (valid0 == valid1 && valid0 != 0)
4343 return null_pointer_node;
4345 /* Since GCC guarantees that string constants are unique in the
4346 generated code, a subtraction between two copies of the same
4347 constant string is absolute. */
4348 if (valid0 && TREE_CODE (valid0) == STRING_CST
4349 && valid1 && TREE_CODE (valid1) == STRING_CST
4350 && operand_equal_p (valid0, valid1, 1))
4351 return null_pointer_node;
4354 /* Support narrowing differences. */
4355 ret = narrowing_initializer_constant_valid_p (value, endtype);
4356 if (ret != NULL_TREE)
4368 /* Return true if VALUE is a valid constant-valued expression
4369 for use in initializing a static bit-field; one that can be
4370 an element of a "constant" initializer. */
4373 initializer_constant_valid_for_bitfield_p (tree value)
4375 /* For bitfields we support integer constants or possibly nested aggregates
4377 switch (TREE_CODE (value))
4381 unsigned HOST_WIDE_INT idx;
4384 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4385 if (!initializer_constant_valid_for_bitfield_p (elt))
4393 case VIEW_CONVERT_EXPR:
4394 case NON_LVALUE_EXPR:
4396 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4405 /* output_constructor outer state of relevance in recursive calls, typically
4406 for nested aggregate bitfields. */
4409 unsigned int bit_offset; /* current position in ... */
4410 int byte; /* ... the outer byte buffer. */
4413 static unsigned HOST_WIDE_INT
4414 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4417 /* Output assembler code for constant EXP to FILE, with no label.
4418 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4419 Assumes output_addressed_constants has been done on EXP already.
4421 Generate exactly SIZE bytes of assembler data, padding at the end
4422 with zeros if necessary. SIZE must always be specified.
4424 SIZE is important for structure constructors,
4425 since trailing members may have been omitted from the constructor.
4426 It is also important for initialization of arrays from string constants
4427 since the full length of the string constant might not be wanted.
4428 It is also needed for initialization of unions, where the initializer's
4429 type is just one member, and that may not be as long as the union.
4431 There a case in which we would fail to output exactly SIZE bytes:
4432 for a structure constructor that wants to produce more than SIZE bytes.
4433 But such constructors will never be generated for any possible input.
4435 ALIGN is the alignment of the data in bits. */
4438 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4440 enum tree_code code;
4441 unsigned HOST_WIDE_INT thissize;
4443 if (size == 0 || flag_syntax_only)
4446 /* See if we're trying to initialize a pointer in a non-default mode
4447 to the address of some declaration somewhere. If the target says
4448 the mode is valid for pointers, assume the target has a way of
4450 if (TREE_CODE (exp) == NOP_EXPR
4451 && POINTER_TYPE_P (TREE_TYPE (exp))
4452 && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp))))
4454 tree saved_type = TREE_TYPE (exp);
4456 /* Peel off any intermediate conversions-to-pointer for valid
4458 while (TREE_CODE (exp) == NOP_EXPR
4459 && POINTER_TYPE_P (TREE_TYPE (exp))
4460 && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp))))
4461 exp = TREE_OPERAND (exp, 0);
4463 /* If what we're left with is the address of something, we can
4464 convert the address to the final type and output it that
4466 if (TREE_CODE (exp) == ADDR_EXPR)
4467 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4468 /* Likewise for constant ints. */
4469 else if (TREE_CODE (exp) == INTEGER_CST)
4470 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4471 TREE_INT_CST_HIGH (exp));
4475 /* Eliminate any conversions since we'll be outputting the underlying
4477 while (CONVERT_EXPR_P (exp)
4478 || TREE_CODE (exp) == NON_LVALUE_EXPR
4479 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4481 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4482 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4484 /* Make sure eliminating the conversion is really a no-op, except with
4485 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4486 union types to allow for Ada unchecked unions. */
4487 if (type_size > op_size
4488 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4489 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4490 /* Keep the conversion. */
4493 exp = TREE_OPERAND (exp, 0);
4496 code = TREE_CODE (TREE_TYPE (exp));
4497 thissize = int_size_in_bytes (TREE_TYPE (exp));
4499 /* Allow a constructor with no elements for any data type.
4500 This means to fill the space with zeros. */
4501 if (TREE_CODE (exp) == CONSTRUCTOR
4502 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4504 assemble_zeros (size);
4508 if (TREE_CODE (exp) == FDESC_EXPR)
4510 #ifdef ASM_OUTPUT_FDESC
4511 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4512 tree decl = TREE_OPERAND (exp, 0);
4513 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4520 /* Now output the underlying data. If we've handling the padding, return.
4521 Otherwise, break and ensure SIZE is the size written. */
4528 case REFERENCE_TYPE:
4530 case FIXED_POINT_TYPE:
4531 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4532 EXPAND_INITIALIZER),
4533 MIN (size, thissize), align, 0))
4534 error ("initializer for integer/fixed-point value is too complicated");
4538 if (TREE_CODE (exp) != REAL_CST)
4539 error ("initializer for floating value is not a floating constant");
4541 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4545 output_constant (TREE_REALPART (exp), thissize / 2, align);
4546 output_constant (TREE_IMAGPART (exp), thissize / 2,
4547 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4552 switch (TREE_CODE (exp))
4555 output_constructor (exp, size, align, NULL);
4558 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4560 assemble_string (TREE_STRING_POINTER (exp), thissize);
4567 unsigned int nalign;
4568 enum machine_mode inner;
4570 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4571 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4573 elt_size = GET_MODE_SIZE (inner);
4575 link = TREE_VECTOR_CST_ELTS (exp);
4576 output_constant (TREE_VALUE (link), elt_size, align);
4577 thissize = elt_size;
4578 while ((link = TREE_CHAIN (link)) != NULL)
4580 output_constant (TREE_VALUE (link), elt_size, nalign);
4581 thissize += elt_size;
4592 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4593 output_constructor (exp, size, align, NULL);
4603 if (size > thissize)
4604 assemble_zeros (size - thissize);
4608 /* Subroutine of output_constructor, used for computing the size of
4609 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4610 type with an unspecified upper bound. */
4612 static unsigned HOST_WIDE_INT
4613 array_size_for_constructor (tree val)
4616 unsigned HOST_WIDE_INT cnt;
4617 tree index, value, tmp;
4619 /* This code used to attempt to handle string constants that are not
4620 arrays of single-bytes, but nothing else does, so there's no point in
4622 if (TREE_CODE (val) == STRING_CST)
4623 return TREE_STRING_LENGTH (val);
4625 max_index = NULL_TREE;
4626 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4628 if (TREE_CODE (index) == RANGE_EXPR)
4629 index = TREE_OPERAND (index, 1);
4630 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4634 if (max_index == NULL_TREE)
4637 /* Compute the total number of array elements. */
4638 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4639 i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4640 fold_convert (sizetype, tmp));
4641 i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4643 /* Multiply by the array element unit size to find number of bytes. */
4644 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4646 return tree_low_cst (i, 1);
4649 /* Other datastructures + helpers for output_constructor. */
4651 /* output_constructor local state to support interaction with helpers. */
4655 /* Received arguments. */
4656 tree exp; /* Constructor expression. */
4657 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4658 unsigned int align; /* Known initial alignment. */
4660 /* Constructor expression data. */
4661 tree type; /* Expression type. */
4662 tree field; /* Current field decl in a record. */
4663 tree min_index; /* Lower bound if specified for an array. */
4665 /* Output processing state. */
4666 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4667 bool byte_buffer_in_use; /* Whether byte ... */
4668 int byte; /* ... contains part of a bitfield byte yet to
4671 int last_relative_index; /* Implicit or explicit index of the last
4672 array element output within a bitfield. */
4673 /* Current element. */
4674 tree val; /* Current element value. */
4675 tree index; /* Current element index. */
4679 /* Helper for output_constructor. From the current LOCAL state, output a
4680 RANGE_EXPR element. */
4683 output_constructor_array_range (oc_local_state *local)
4685 unsigned HOST_WIDE_INT fieldsize
4686 = int_size_in_bytes (TREE_TYPE (local->type));
4688 HOST_WIDE_INT lo_index
4689 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4690 HOST_WIDE_INT hi_index
4691 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4692 HOST_WIDE_INT index;
4695 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4697 for (index = lo_index; index <= hi_index; index++)
4699 /* Output the element's initial value. */
4700 if (local->val == NULL_TREE)
4701 assemble_zeros (fieldsize);
4703 output_constant (local->val, fieldsize, align2);
4705 /* Count its size. */
4706 local->total_bytes += fieldsize;
4710 /* Helper for output_constructor. From the current LOCAL state, output a
4711 field element that is not true bitfield or part of an outer one. */
4714 output_constructor_regular_field (oc_local_state *local)
4716 /* Field size and position. Since this structure is static, we know the
4717 positions are constant. */
4718 unsigned HOST_WIDE_INT fieldsize;
4719 HOST_WIDE_INT fieldpos;
4721 unsigned int align2;
4723 if (local->index != NULL_TREE)
4724 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
4725 * ((tree_low_cst (local->index, 0)
4726 - tree_low_cst (local->min_index, 0))));
4727 else if (local->field != NULL_TREE)
4728 fieldpos = int_byte_position (local->field);
4732 /* Output any buffered-up bit-fields preceding this element. */
4733 if (local->byte_buffer_in_use)
4735 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4736 local->total_bytes++;
4737 local->byte_buffer_in_use = false;
4740 /* Advance to offset of this element.
4741 Note no alignment needed in an array, since that is guaranteed
4742 if each element has the proper size. */
4743 if ((local->field != NULL_TREE || local->index != NULL_TREE)
4744 && fieldpos != local->total_bytes)
4746 gcc_assert (fieldpos >= local->total_bytes);
4747 assemble_zeros (fieldpos - local->total_bytes);
4748 local->total_bytes = fieldpos;
4751 /* Find the alignment of this element. */
4752 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
4754 /* Determine size this element should occupy. */
4759 /* If this is an array with an unspecified upper bound,
4760 the initializer determines the size. */
4761 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4762 but we cannot do this until the deprecated support for
4763 initializing zero-length array members is removed. */
4764 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
4765 && TYPE_DOMAIN (TREE_TYPE (local->field))
4766 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
4768 fieldsize = array_size_for_constructor (local->val);
4769 /* Given a non-empty initialization, this field had
4771 gcc_assert (!fieldsize || !TREE_CHAIN (local->field));
4773 else if (DECL_SIZE_UNIT (local->field))
4775 /* ??? This can't be right. If the decl size overflows
4776 a host integer we will silently emit no data. */
4777 if (host_integerp (DECL_SIZE_UNIT (local->field), 1))
4778 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
4782 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
4784 /* Output the element's initial value. */
4785 if (local->val == NULL_TREE)
4786 assemble_zeros (fieldsize);
4788 output_constant (local->val, fieldsize, align2);
4790 /* Count its size. */
4791 local->total_bytes += fieldsize;
4794 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4795 output an element that is a true bitfield or part of an outer one. */
4798 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
4800 /* Bit size of this element. */
4801 HOST_WIDE_INT ebitsize
4803 ? tree_low_cst (DECL_SIZE (local->field), 1)
4804 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
4806 /* Relative index of this element if this is an array component. */
4807 HOST_WIDE_INT relative_index
4810 ? (tree_low_cst (local->index, 0)
4811 - tree_low_cst (local->min_index, 0))
4812 : local->last_relative_index + 1)
4815 /* Bit position of this element from the start of the containing
4817 HOST_WIDE_INT constructor_relative_ebitpos
4819 ? int_bit_position (local->field)
4820 : ebitsize * relative_index);
4822 /* Bit position of this element from the start of a possibly ongoing
4823 outer byte buffer. */
4824 HOST_WIDE_INT byte_relative_ebitpos
4825 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
4827 /* From the start of a possibly ongoing outer byte buffer, offsets to
4828 the first bit of this element and to the first bit past the end of
4830 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
4831 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
4833 local->last_relative_index = relative_index;
4835 if (local->val == NULL_TREE)
4836 local->val = integer_zero_node;
4838 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
4839 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
4840 local->val = TREE_OPERAND (local->val, 0);
4842 if (TREE_CODE (local->val) != INTEGER_CST
4843 && TREE_CODE (local->val) != CONSTRUCTOR)
4845 error ("invalid initial value for member %qE", DECL_NAME (local->field));
4849 /* If this field does not start in this (or, next) byte,
4851 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4853 /* Output remnant of any bit field in previous bytes. */
4854 if (local->byte_buffer_in_use)
4856 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4857 local->total_bytes++;
4858 local->byte_buffer_in_use = false;
4861 /* If still not at proper byte, advance to there. */
4862 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4864 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
4865 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
4866 local->total_bytes = next_offset / BITS_PER_UNIT;
4870 /* Set up the buffer if necessary. */
4871 if (!local->byte_buffer_in_use)
4875 local->byte_buffer_in_use = true;
4878 /* If this is nested constructor, recurse passing the bit offset and the
4879 pending data, then retrieve the new pending data afterwards. */
4880 if (TREE_CODE (local->val) == CONSTRUCTOR)
4882 oc_outer_state output_state;
4884 output_state.bit_offset = next_offset % BITS_PER_UNIT;
4885 output_state.byte = local->byte;
4887 += output_constructor (local->val, 0, 0, &output_state);
4888 local->byte = output_state.byte;
4892 /* Otherwise, we must split the element into pieces that fall within
4893 separate bytes, and combine each byte with previous or following
4895 while (next_offset < end_offset)
4899 HOST_WIDE_INT value;
4900 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4901 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4903 /* Advance from byte to byte
4904 within this element when necessary. */
4905 while (next_byte != local->total_bytes)
4907 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4908 local->total_bytes++;
4912 /* Number of bits we can process at once
4913 (all part of the same byte). */
4914 this_time = MIN (end_offset - next_offset,
4915 BITS_PER_UNIT - next_bit);
4916 if (BYTES_BIG_ENDIAN)
4918 /* On big-endian machine, take the most significant bits
4919 first (of the bits that are significant)
4920 and put them into bytes from the most significant end. */
4921 shift = end_offset - next_offset - this_time;
4923 /* Don't try to take a bunch of bits that cross
4924 the word boundary in the INTEGER_CST. We can
4925 only select bits from the LOW or HIGH part
4927 if (shift < HOST_BITS_PER_WIDE_INT
4928 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4930 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4931 shift = HOST_BITS_PER_WIDE_INT;
4934 /* Now get the bits from the appropriate constant word. */
4935 if (shift < HOST_BITS_PER_WIDE_INT)
4936 value = TREE_INT_CST_LOW (local->val);
4939 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4940 value = TREE_INT_CST_HIGH (local->val);
4941 shift -= HOST_BITS_PER_WIDE_INT;
4944 /* Get the result. This works only when:
4945 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4946 local->byte |= (((value >> shift)
4947 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4948 << (BITS_PER_UNIT - this_time - next_bit));
4952 /* On little-endian machines,
4953 take first the least significant bits of the value
4954 and pack them starting at the least significant
4955 bits of the bytes. */
4956 shift = next_offset - byte_relative_ebitpos;
4958 /* Don't try to take a bunch of bits that cross
4959 the word boundary in the INTEGER_CST. We can
4960 only select bits from the LOW or HIGH part
4962 if (shift < HOST_BITS_PER_WIDE_INT
4963 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4964 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4966 /* Now get the bits from the appropriate constant word. */
4967 if (shift < HOST_BITS_PER_WIDE_INT)
4968 value = TREE_INT_CST_LOW (local->val);
4971 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4972 value = TREE_INT_CST_HIGH (local->val);
4973 shift -= HOST_BITS_PER_WIDE_INT;
4976 /* Get the result. This works only when:
4977 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4978 local->byte |= (((value >> shift)
4979 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4983 next_offset += this_time;
4984 local->byte_buffer_in_use = true;
4988 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4989 Generate at least SIZE bytes, padding if necessary. OUTER designates the
4990 caller output state of relevance in recursive invocations. */
4992 static unsigned HOST_WIDE_INT
4993 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
4994 unsigned int align, oc_outer_state * outer)
4996 unsigned HOST_WIDE_INT cnt;
4997 constructor_elt *ce;
4999 oc_local_state local;
5001 /* Setup our local state to communicate with helpers. */
5004 local.align = align;
5006 local.total_bytes = 0;
5007 local.byte_buffer_in_use = outer != NULL;
5008 local.byte = outer ? outer->byte : 0;
5010 local.type = TREE_TYPE (exp);
5012 local.last_relative_index = -1;
5014 local.min_index = NULL_TREE;
5015 if (TREE_CODE (local.type) == ARRAY_TYPE
5016 && TYPE_DOMAIN (local.type) != NULL_TREE)
5017 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5019 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
5021 /* As CE goes through the elements of the constant, FIELD goes through the
5022 structure fields if the constant is a structure. If the constant is a
5023 union, we override this by getting the field from the TREE_LIST element.
5024 But the constant could also be an array. Then FIELD is zero.
5026 There is always a maximum of one element in the chain LINK for unions
5027 (even if the initializer in a source program incorrectly contains
5030 local.field = NULL_TREE;
5031 if (TREE_CODE (local.type) == RECORD_TYPE)
5032 local.field = TYPE_FIELDS (local.type);
5035 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
5036 cnt++, local.field = local.field ? TREE_CHAIN (local.field) : 0)
5038 local.val = ce->value;
5039 local.index = NULL_TREE;
5041 /* The element in a union constructor specifies the proper field
5043 if ((TREE_CODE (local.type) == RECORD_TYPE
5044 || TREE_CODE (local.type) == UNION_TYPE
5045 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
5046 && ce->index != NULL_TREE)
5047 local.field = ce->index;
5049 else if (TREE_CODE (local.type) == ARRAY_TYPE)
5050 local.index = ce->index;
5052 #ifdef ASM_COMMENT_START
5053 if (local.field && flag_verbose_asm)
5054 fprintf (asm_out_file, "%s %s:\n",
5056 DECL_NAME (local.field)
5057 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
5061 /* Eliminate the marker that makes a cast not be an lvalue. */
5062 if (local.val != NULL_TREE)
5063 STRIP_NOPS (local.val);
5065 /* Output the current element, using the appropriate helper ... */
5067 /* For an array slice not part of an outer bitfield. */
5069 && local.index != NULL_TREE
5070 && TREE_CODE (local.index) == RANGE_EXPR)
5071 output_constructor_array_range (&local);
5073 /* For a field that is neither a true bitfield nor part of an outer one,
5074 known to be at least byte aligned and multiple-of-bytes long. */
5076 && (local.field == NULL_TREE
5077 || !CONSTRUCTOR_BITFIELD_P (local.field)))
5078 output_constructor_regular_field (&local);
5080 /* For a true bitfield or part of an outer one. */
5082 output_constructor_bitfield (&local, outer);
5085 /* If we are not at toplevel, save the pending data for our caller.
5086 Otherwise output the pending data and padding zeros as needed. */
5088 outer->byte = local.byte;
5091 if (local.byte_buffer_in_use)
5093 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
5094 local.total_bytes++;
5097 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
5099 assemble_zeros (local.size - local.total_bytes);
5100 local.total_bytes = local.size;
5104 return local.total_bytes;
5107 /* Mark DECL as weak. */
5110 mark_weak (tree decl)
5112 DECL_WEAK (decl) = 1;
5114 if (DECL_RTL_SET_P (decl)
5115 && MEM_P (DECL_RTL (decl))
5116 && XEXP (DECL_RTL (decl), 0)
5117 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5118 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5121 /* Merge weak status between NEWDECL and OLDDECL. */
5124 merge_weak (tree newdecl, tree olddecl)
5126 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5128 if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
5131 /* We put the NEWDECL on the weak_decls list at some point
5132 and OLDDECL as well. Keep just OLDDECL on the list. */
5133 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5134 if (TREE_VALUE (*pwd) == newdecl)
5136 *pwd = TREE_CHAIN (*pwd);
5143 if (DECL_WEAK (newdecl))
5147 /* NEWDECL is weak, but OLDDECL is not. */
5149 /* If we already output the OLDDECL, we're in trouble; we can't
5150 go back and make it weak. This error cannot be caught in
5151 declare_weak because the NEWDECL and OLDDECL was not yet
5152 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5153 if (TREE_ASM_WRITTEN (olddecl))
5154 error ("weak declaration of %q+D must precede definition",
5157 /* If we've already generated rtl referencing OLDDECL, we may
5158 have done so in a way that will not function properly with
5160 else if (TREE_USED (olddecl)
5161 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
5162 warning (0, "weak declaration of %q+D after first use results "
5163 "in unspecified behavior", newdecl);
5167 /* We put the NEWDECL on the weak_decls list at some point.
5168 Replace it with the OLDDECL. */
5169 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5170 if (TREE_VALUE (wd) == newdecl)
5172 TREE_VALUE (wd) = olddecl;
5175 /* We may not find the entry on the list. If NEWDECL is a
5176 weak alias, then we will have already called
5177 globalize_decl to remove the entry; in that case, we do
5178 not need to do anything. */
5181 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5182 mark_weak (olddecl);
5185 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5186 weak. Just update NEWDECL to indicate that it's weak too. */
5187 mark_weak (newdecl);
5190 /* Declare DECL to be a weak symbol. */
5193 declare_weak (tree decl)
5195 if (! TREE_PUBLIC (decl))
5196 error ("weak declaration of %q+D must be public", decl);
5197 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
5198 error ("weak declaration of %q+D must precede definition", decl);
5199 else if (!SUPPORTS_WEAK)
5200 warning (0, "weak declaration of %q+D not supported", decl);
5206 weak_finish_1 (tree decl)
5208 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5209 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5212 if (! TREE_USED (decl))
5215 #ifdef ASM_WEAKEN_DECL
5216 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5218 #ifdef ASM_WEAKEN_LABEL
5219 ASM_WEAKEN_LABEL (asm_out_file, name);
5221 #ifdef ASM_OUTPUT_WEAK_ALIAS
5223 static bool warn_once = 0;
5226 warning (0, "only weak aliases are supported in this configuration");
5236 /* This TREE_LIST contains weakref targets. */
5238 static GTY(()) tree weakref_targets;
5240 /* Forward declaration. */
5241 static tree find_decl_and_mark_needed (tree decl, tree target);
5243 /* Emit any pending weak declarations. */
5250 for (t = weakref_targets; t; t = TREE_CHAIN (t))
5252 tree alias_decl = TREE_PURPOSE (t);
5253 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5255 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5256 /* Remove alias_decl from the weak list, but leave entries for
5257 the target alone. */
5259 #ifndef ASM_OUTPUT_WEAKREF
5260 else if (! TREE_SYMBOL_REFERENCED (target))
5262 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5263 defined, otherwise we and weak_finish_1 would use
5264 different macros. */
5265 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5266 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5268 tree decl = find_decl_and_mark_needed (alias_decl, target);
5272 decl = build_decl (TREE_CODE (alias_decl), target,
5273 TREE_TYPE (alias_decl));
5275 DECL_EXTERNAL (decl) = 1;
5276 TREE_PUBLIC (decl) = 1;
5277 DECL_ARTIFICIAL (decl) = 1;
5278 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5279 TREE_USED (decl) = 1;
5282 weak_finish_1 (decl);
5291 /* Remove the alias and the target from the pending weak list
5292 so that we do not emit any .weak directives for the former,
5293 nor multiple .weak directives for the latter. */
5294 for (p = &weak_decls; (t2 = *p) ; )
5296 if (TREE_VALUE (t2) == alias_decl
5297 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5298 *p = TREE_CHAIN (t2);
5300 p = &TREE_CHAIN (t2);
5303 /* Remove other weakrefs to the same target, to speed things up. */
5304 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5306 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5307 *p = TREE_CHAIN (t2);
5309 p = &TREE_CHAIN (t2);
5314 for (t = weak_decls; t; t = TREE_CHAIN (t))
5316 tree decl = TREE_VALUE (t);
5318 weak_finish_1 (decl);
5322 /* Emit the assembly bits to indicate that DECL is globally visible. */
5325 globalize_decl (tree decl)
5328 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5329 if (DECL_WEAK (decl))
5331 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5334 #ifdef ASM_WEAKEN_DECL
5335 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5337 ASM_WEAKEN_LABEL (asm_out_file, name);
5340 /* Remove this function from the pending weak list so that
5341 we do not emit multiple .weak directives for it. */
5342 for (p = &weak_decls; (t = *p) ; )
5344 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5345 *p = TREE_CHAIN (t);
5347 p = &TREE_CHAIN (t);
5350 /* Remove weakrefs to the same target from the pending weakref
5351 list, for the same reason. */
5352 for (p = &weakref_targets; (t = *p) ; )
5354 if (DECL_ASSEMBLER_NAME (decl)
5355 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5356 *p = TREE_CHAIN (t);
5358 p = &TREE_CHAIN (t);
5365 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5368 /* We have to be able to tell cgraph about the needed-ness of the target
5369 of an alias. This requires that the decl have been defined. Aliases
5370 that precede their definition have to be queued for later processing. */
5372 typedef struct GTY(()) alias_pair {
5377 /* Define gc'd vector type. */
5378 DEF_VEC_O(alias_pair);
5379 DEF_VEC_ALLOC_O(alias_pair,gc);
5381 static GTY(()) VEC(alias_pair,gc) *alias_pairs;
5383 /* Given an assembly name, find the decl it is associated with. At the
5384 same time, mark it needed for cgraph. */
5387 find_decl_and_mark_needed (tree decl, tree target)
5389 struct cgraph_node *fnode = NULL;
5390 struct varpool_node *vnode = NULL;
5392 if (TREE_CODE (decl) == FUNCTION_DECL)
5394 fnode = cgraph_node_for_asm (target);
5396 vnode = varpool_node_for_asm (target);
5400 vnode = varpool_node_for_asm (target);
5402 fnode = cgraph_node_for_asm (target);
5407 /* We can't mark function nodes as used after cgraph global info
5408 is finished. This wouldn't generally be necessary, but C++
5409 virtual table thunks are introduced late in the game and
5410 might seem like they need marking, although in fact they
5412 if (! cgraph_global_info_ready)
5413 cgraph_mark_needed_node (fnode);
5418 varpool_mark_needed_node (vnode);
5425 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5426 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5427 tree node is DECL to have the value of the tree node TARGET. */
5430 do_assemble_alias (tree decl, tree target)
5432 if (TREE_ASM_WRITTEN (decl))
5435 TREE_ASM_WRITTEN (decl) = 1;
5436 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5438 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5440 ultimate_transparent_alias_target (&target);
5442 if (!targetm.have_tls
5443 && TREE_CODE (decl) == VAR_DECL
5444 && DECL_THREAD_LOCAL_P (decl))
5446 decl = emutls_decl (decl);
5447 target = get_emutls_object_name (target);
5450 if (!TREE_SYMBOL_REFERENCED (target))
5451 weakref_targets = tree_cons (decl, target, weakref_targets);
5453 #ifdef ASM_OUTPUT_WEAKREF
5454 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5455 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5456 IDENTIFIER_POINTER (target));
5460 error ("%Jweakref is not supported in this configuration", decl);
5467 if (!targetm.have_tls
5468 && TREE_CODE (decl) == VAR_DECL
5469 && DECL_THREAD_LOCAL_P (decl))
5471 decl = emutls_decl (decl);
5472 target = get_emutls_object_name (target);
5475 #ifdef ASM_OUTPUT_DEF
5476 /* Make name accessible from other files, if appropriate. */
5478 if (TREE_PUBLIC (decl))
5480 globalize_decl (decl);
5481 maybe_assemble_visibility (decl);
5484 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5485 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5487 ASM_OUTPUT_DEF (asm_out_file,
5488 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5489 IDENTIFIER_POINTER (target));
5491 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5496 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5497 # ifdef ASM_WEAKEN_DECL
5498 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5500 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5502 /* Remove this function from the pending weak list so that
5503 we do not emit multiple .weak directives for it. */
5504 for (p = &weak_decls; (t = *p) ; )
5505 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5506 *p = TREE_CHAIN (t);
5508 p = &TREE_CHAIN (t);
5510 /* Remove weakrefs to the same target from the pending weakref
5511 list, for the same reason. */
5512 for (p = &weakref_targets; (t = *p) ; )
5514 if (DECL_ASSEMBLER_NAME (decl)
5515 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5516 *p = TREE_CHAIN (t);
5518 p = &TREE_CHAIN (t);
5524 /* First pass of completing pending aliases. Make sure that cgraph knows
5525 which symbols will be required. */
5528 finish_aliases_1 (void)
5533 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5537 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5538 if (target_decl == NULL)
5540 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5541 error ("%q+D aliased to undefined symbol %qE",
5542 p->decl, p->target);
5544 else if (DECL_EXTERNAL (target_decl)
5545 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5546 error ("%q+D aliased to external symbol %qE",
5547 p->decl, p->target);
5551 /* Second pass of completing pending aliases. Emit the actual assembly.
5552 This happens at the end of compilation and thus it is assured that the
5553 target symbol has been emitted. */
5556 finish_aliases_2 (void)
5561 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5562 do_assemble_alias (p->decl, p->target);
5564 VEC_truncate (alias_pair, alias_pairs, 0);
5567 /* Emit an assembler directive to make the symbol for DECL an alias to
5568 the symbol for TARGET. */
5571 assemble_alias (tree decl, tree target)
5574 bool is_weakref = false;
5576 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5578 tree alias = DECL_ASSEMBLER_NAME (decl);
5582 ultimate_transparent_alias_target (&target);
5584 if (alias == target)
5585 error ("weakref %q+D ultimately targets itself", decl);
5588 #ifndef ASM_OUTPUT_WEAKREF
5589 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5590 TREE_CHAIN (alias) = target;
5593 if (TREE_PUBLIC (decl))
5594 error ("weakref %q+D must have static linkage", decl);
5598 #if !defined (ASM_OUTPUT_DEF)
5599 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5600 error ("%Jalias definitions not supported in this configuration", decl);
5603 if (!DECL_WEAK (decl))
5605 error ("%Jonly weak aliases are supported in this configuration", decl);
5612 /* We must force creation of DECL_RTL for debug info generation, even though
5613 we don't use it here. */
5614 make_decl_rtl (decl);
5615 TREE_USED (decl) = 1;
5617 /* A quirk of the initial implementation of aliases required that the user
5618 add "extern" to all of them. Which is silly, but now historical. Do
5619 note that the symbol is in fact locally defined. */
5621 DECL_EXTERNAL (decl) = 0;
5623 /* Allow aliases to aliases. */
5624 if (TREE_CODE (decl) == FUNCTION_DECL)
5625 cgraph_node (decl)->alias = true;
5627 varpool_node (decl)->alias = true;
5629 /* If the target has already been emitted, we don't have to queue the
5630 alias. This saves a tad of memory. */
5631 if (cgraph_global_info_ready)
5632 target_decl = find_decl_and_mark_needed (decl, target);
5635 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5636 do_assemble_alias (decl, target);
5639 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5645 /* Emit an assembler directive to set symbol for DECL visibility to
5646 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5649 default_assemble_visibility (tree decl, int vis)
5651 static const char * const visibility_types[] = {
5652 NULL, "protected", "hidden", "internal"
5655 const char *name, *type;
5657 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5658 type = visibility_types[vis];
5660 #ifdef HAVE_GAS_HIDDEN
5661 fprintf (asm_out_file, "\t.%s\t", type);
5662 assemble_name (asm_out_file, name);
5663 fprintf (asm_out_file, "\n");
5665 warning (OPT_Wattributes, "visibility attribute not supported "
5666 "in this configuration; ignored");
5670 /* A helper function to call assemble_visibility when needed for a decl. */
5673 maybe_assemble_visibility (tree decl)
5675 enum symbol_visibility vis = DECL_VISIBILITY (decl);
5677 if (vis != VISIBILITY_DEFAULT)
5679 targetm.asm_out.visibility (decl, vis);
5686 /* Returns 1 if the target configuration supports defining public symbols
5687 so that one of them will be chosen at link time instead of generating a
5688 multiply-defined symbol error, whether through the use of weak symbols or
5689 a target-specific mechanism for having duplicates discarded. */
5692 supports_one_only (void)
5694 if (SUPPORTS_ONE_ONLY)
5696 return SUPPORTS_WEAK;
5699 /* Set up DECL as a public symbol that can be defined in multiple
5700 translation units without generating a linker error. */
5703 make_decl_one_only (tree decl)
5705 gcc_assert (TREE_CODE (decl) == VAR_DECL
5706 || TREE_CODE (decl) == FUNCTION_DECL);
5708 TREE_PUBLIC (decl) = 1;
5710 if (SUPPORTS_ONE_ONLY)
5712 #ifdef MAKE_DECL_ONE_ONLY
5713 MAKE_DECL_ONE_ONLY (decl);
5715 DECL_ONE_ONLY (decl) = 1;
5717 else if (TREE_CODE (decl) == VAR_DECL
5718 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5719 DECL_COMMON (decl) = 1;
5722 gcc_assert (SUPPORTS_WEAK);
5723 DECL_WEAK (decl) = 1;
5728 init_varasm_once (void)
5730 section_htab = htab_create_ggc (31, section_entry_hash,
5731 section_entry_eq, NULL);
5732 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
5733 object_block_entry_eq, NULL);
5734 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
5735 const_desc_eq, NULL);
5737 const_alias_set = new_alias_set ();
5738 shared_constant_pool = create_constant_pool ();
5740 #ifdef TEXT_SECTION_ASM_OP
5741 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
5742 TEXT_SECTION_ASM_OP);
5745 #ifdef DATA_SECTION_ASM_OP
5746 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5747 DATA_SECTION_ASM_OP);
5750 #ifdef SDATA_SECTION_ASM_OP
5751 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5752 SDATA_SECTION_ASM_OP);
5755 #ifdef READONLY_DATA_SECTION_ASM_OP
5756 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
5757 READONLY_DATA_SECTION_ASM_OP);
5760 #ifdef CTORS_SECTION_ASM_OP
5761 ctors_section = get_unnamed_section (0, output_section_asm_op,
5762 CTORS_SECTION_ASM_OP);
5765 #ifdef DTORS_SECTION_ASM_OP
5766 dtors_section = get_unnamed_section (0, output_section_asm_op,
5767 DTORS_SECTION_ASM_OP);
5770 #ifdef BSS_SECTION_ASM_OP
5771 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5772 output_section_asm_op,
5773 BSS_SECTION_ASM_OP);
5776 #ifdef SBSS_SECTION_ASM_OP
5777 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5778 output_section_asm_op,
5779 SBSS_SECTION_ASM_OP);
5782 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5783 | SECTION_COMMON, emit_tls_common);
5784 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5785 | SECTION_COMMON, emit_local);
5786 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5787 | SECTION_COMMON, emit_common);
5789 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5790 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
5794 targetm.asm_out.init_sections ();
5796 if (readonly_data_section == NULL)
5797 readonly_data_section = text_section;
5801 decl_default_tls_model (const_tree decl)
5803 enum tls_model kind;
5806 is_local = targetm.binds_local_p (decl);
5810 kind = TLS_MODEL_LOCAL_EXEC;
5812 kind = TLS_MODEL_INITIAL_EXEC;
5815 /* Local dynamic is inefficient when we're not combining the
5816 parts of the address. */
5817 else if (optimize && is_local)
5818 kind = TLS_MODEL_LOCAL_DYNAMIC;
5820 kind = TLS_MODEL_GLOBAL_DYNAMIC;
5821 if (kind < flag_tls_default)
5822 kind = flag_tls_default;
5827 /* Select a set of attributes for section NAME based on the properties
5828 of DECL and whether or not RELOC indicates that DECL's initializer
5829 might contain runtime relocations.
5831 We make the section read-only and executable for a function decl,
5832 read-only for a const data decl, and writable for a non-const data decl. */
5835 default_section_type_flags (tree decl, const char *name, int reloc)
5839 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5840 flags = SECTION_CODE;
5841 else if (decl && decl_readonly_section (decl, reloc))
5843 else if (current_function_decl
5845 && crtl->subsections.unlikely_text_section_name
5846 && strcmp (name, crtl->subsections.unlikely_text_section_name) == 0)
5847 flags = SECTION_CODE;
5849 && (!current_function_decl || !cfun)
5850 && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
5851 flags = SECTION_CODE;
5853 flags = SECTION_WRITE;
5855 if (decl && DECL_ONE_ONLY (decl))
5856 flags |= SECTION_LINKONCE;
5858 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
5859 flags |= SECTION_TLS | SECTION_WRITE;
5861 if (strcmp (name, ".bss") == 0
5862 || strncmp (name, ".bss.", 5) == 0
5863 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5864 || strcmp (name, ".sbss") == 0
5865 || strncmp (name, ".sbss.", 6) == 0
5866 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5867 flags |= SECTION_BSS;
5869 if (strcmp (name, ".tdata") == 0
5870 || strncmp (name, ".tdata.", 7) == 0
5871 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
5872 flags |= SECTION_TLS;
5874 if (strcmp (name, ".tbss") == 0
5875 || strncmp (name, ".tbss.", 6) == 0
5876 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
5877 flags |= SECTION_TLS | SECTION_BSS;
5879 /* These three sections have special ELF types. They are neither
5880 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
5881 want to print a section type (@progbits or @nobits). If someone
5882 is silly enough to emit code or TLS variables to one of these
5883 sections, then don't handle them specially. */
5884 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
5885 && (strcmp (name, ".init_array") == 0
5886 || strcmp (name, ".fini_array") == 0
5887 || strcmp (name, ".preinit_array") == 0))
5888 flags |= SECTION_NOTYPE;
5893 /* Return true if the target supports some form of global BSS,
5894 either through bss_noswitch_section, or by selecting a BSS
5895 section in TARGET_ASM_SELECT_SECTION. */
5898 have_global_bss_p (void)
5900 return bss_noswitch_section || targetm.have_switchable_bss_sections;
5903 /* Output assembly to switch to section NAME with attribute FLAGS.
5904 Four variants for common object file formats. */
5907 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
5908 unsigned int flags ATTRIBUTE_UNUSED,
5909 tree decl ATTRIBUTE_UNUSED)
5911 /* Some object formats don't support named sections at all. The
5912 front-end should already have flagged this as an error. */
5917 default_elf_asm_named_section (const char *name, unsigned int flags,
5918 tree decl ATTRIBUTE_UNUSED)
5920 char flagchars[10], *f = flagchars;
5922 /* If we have already declared this section, we can use an
5923 abbreviated form to switch back to it -- unless this section is
5924 part of a COMDAT groups, in which case GAS requires the full
5925 declaration every time. */
5926 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5927 && (flags & SECTION_DECLARED))
5929 fprintf (asm_out_file, "\t.section\t%s\n", name);
5933 if (!(flags & SECTION_DEBUG))
5935 if (flags & SECTION_WRITE)
5937 if (flags & SECTION_CODE)
5939 if (flags & SECTION_SMALL)
5941 if (flags & SECTION_MERGE)
5943 if (flags & SECTION_STRINGS)
5945 if (flags & SECTION_TLS)
5947 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5951 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
5953 if (!(flags & SECTION_NOTYPE))
5958 if (flags & SECTION_BSS)
5964 #ifdef ASM_COMMENT_START
5965 /* On platforms that use "@" as the assembly comment character,
5967 if (strcmp (ASM_COMMENT_START, "@") == 0)
5970 fprintf (asm_out_file, format, type);
5972 if (flags & SECTION_ENTSIZE)
5973 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
5974 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5975 fprintf (asm_out_file, ",%s,comdat",
5976 lang_hooks.decls.comdat_group (decl));
5979 putc ('\n', asm_out_file);
5983 default_coff_asm_named_section (const char *name, unsigned int flags,
5984 tree decl ATTRIBUTE_UNUSED)
5986 char flagchars[8], *f = flagchars;
5988 if (flags & SECTION_WRITE)
5990 if (flags & SECTION_CODE)
5994 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5998 default_pe_asm_named_section (const char *name, unsigned int flags,
6001 default_coff_asm_named_section (name, flags, decl);
6003 if (flags & SECTION_LINKONCE)
6005 /* Functions may have been compiled at various levels of
6006 optimization so we can't use `same_size' here.
6007 Instead, have the linker pick one. */
6008 fprintf (asm_out_file, "\t.linkonce %s\n",
6009 (flags & SECTION_CODE ? "discard" : "same_size"));
6013 /* The lame default section selector. */
6016 default_select_section (tree decl, int reloc,
6017 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6021 if (decl_readonly_section (decl, reloc))
6022 return readonly_data_section;
6024 else if (TREE_CODE (decl) == CONSTRUCTOR)
6026 if (! ((flag_pic && reloc)
6027 || !TREE_READONLY (decl)
6028 || TREE_SIDE_EFFECTS (decl)
6029 || !TREE_CONSTANT (decl)))
6030 return readonly_data_section;
6032 else if (TREE_CODE (decl) == STRING_CST)
6033 return readonly_data_section;
6034 else if (! (flag_pic && reloc))
6035 return readonly_data_section;
6037 return data_section;
6040 enum section_category
6041 categorize_decl_for_section (const_tree decl, int reloc)
6043 enum section_category ret;
6045 if (TREE_CODE (decl) == FUNCTION_DECL)
6047 else if (TREE_CODE (decl) == STRING_CST)
6049 if (flag_mudflap) /* or !flag_merge_constants */
6050 return SECCAT_RODATA;
6052 return SECCAT_RODATA_MERGE_STR;
6054 else if (TREE_CODE (decl) == VAR_DECL)
6056 if (bss_initializer_p (decl))
6058 else if (! TREE_READONLY (decl)
6059 || TREE_SIDE_EFFECTS (decl)
6060 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6062 /* Here the reloc_rw_mask is not testing whether the section should
6063 be read-only or not, but whether the dynamic link will have to
6064 do something. If so, we wish to segregate the data in order to
6065 minimize cache misses inside the dynamic linker. */
6066 if (reloc & targetm.asm_out.reloc_rw_mask ())
6067 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6071 else if (reloc & targetm.asm_out.reloc_rw_mask ())
6072 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6073 else if (reloc || flag_merge_constants < 2)
6074 /* C and C++ don't allow different variables to share the same
6075 location. -fmerge-all-constants allows even that (at the
6076 expense of not conforming). */
6077 ret = SECCAT_RODATA;
6078 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6079 ret = SECCAT_RODATA_MERGE_STR_INIT;
6081 ret = SECCAT_RODATA_MERGE_CONST;
6083 else if (TREE_CODE (decl) == CONSTRUCTOR)
6085 if ((reloc & targetm.asm_out.reloc_rw_mask ())
6086 || TREE_SIDE_EFFECTS (decl)
6087 || ! TREE_CONSTANT (decl))
6090 ret = SECCAT_RODATA;
6093 ret = SECCAT_RODATA;
6095 /* There are no read-only thread-local sections. */
6096 if (TREE_CODE (decl) == VAR_DECL && DECL_TLS_MODEL (decl))
6098 if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED)
6100 if (DECL_EMUTLS_VAR_P (decl))
6102 if (targetm.emutls.var_section)
6103 ret = SECCAT_EMUTLS_VAR;
6107 if (targetm.emutls.tmpl_prefix)
6108 ret = SECCAT_EMUTLS_TMPL;
6111 /* Note that this would be *just* SECCAT_BSS, except that there's
6112 no concept of a read-only thread-local-data section. */
6113 else if (ret == SECCAT_BSS
6114 || (flag_zero_initialized_in_bss
6115 && initializer_zerop (DECL_INITIAL (decl))))
6121 /* If the target uses small data sections, select it. */
6122 else if (targetm.in_small_data_p (decl))
6124 if (ret == SECCAT_BSS)
6126 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6127 ret = SECCAT_SRODATA;
6136 decl_readonly_section (const_tree decl, int reloc)
6138 switch (categorize_decl_for_section (decl, reloc))
6141 case SECCAT_RODATA_MERGE_STR:
6142 case SECCAT_RODATA_MERGE_STR_INIT:
6143 case SECCAT_RODATA_MERGE_CONST:
6144 case SECCAT_SRODATA:
6153 /* Select a section based on the above categorization. */
6156 default_elf_select_section (tree decl, int reloc,
6157 unsigned HOST_WIDE_INT align)
6160 switch (categorize_decl_for_section (decl, reloc))
6163 /* We're not supposed to be called on FUNCTION_DECLs. */
6166 return readonly_data_section;
6167 case SECCAT_RODATA_MERGE_STR:
6168 return mergeable_string_section (decl, align, 0);
6169 case SECCAT_RODATA_MERGE_STR_INIT:
6170 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6171 case SECCAT_RODATA_MERGE_CONST:
6172 return mergeable_constant_section (DECL_MODE (decl), align, 0);
6173 case SECCAT_SRODATA:
6177 return data_section;
6178 case SECCAT_DATA_REL:
6179 sname = ".data.rel";
6181 case SECCAT_DATA_REL_LOCAL:
6182 sname = ".data.rel.local";
6184 case SECCAT_DATA_REL_RO:
6185 sname = ".data.rel.ro";
6187 case SECCAT_DATA_REL_RO_LOCAL:
6188 sname = ".data.rel.ro.local";
6207 case SECCAT_EMUTLS_VAR:
6208 sname = targetm.emutls.var_section;
6210 case SECCAT_EMUTLS_TMPL:
6211 sname = targetm.emutls.tmpl_section;
6219 return get_named_section (decl, sname, reloc);
6222 /* Construct a unique section name based on the decl name and the
6223 categorization performed above. */
6226 default_unique_section (tree decl, int reloc)
6228 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6229 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6230 const char *prefix, *name, *linkonce;
6233 switch (categorize_decl_for_section (decl, reloc))
6236 prefix = one_only ? ".t" : ".text";
6239 case SECCAT_RODATA_MERGE_STR:
6240 case SECCAT_RODATA_MERGE_STR_INIT:
6241 case SECCAT_RODATA_MERGE_CONST:
6242 prefix = one_only ? ".r" : ".rodata";
6244 case SECCAT_SRODATA:
6245 prefix = one_only ? ".s2" : ".sdata2";
6248 prefix = one_only ? ".d" : ".data";
6250 case SECCAT_DATA_REL:
6251 prefix = one_only ? ".d.rel" : ".data.rel";
6253 case SECCAT_DATA_REL_LOCAL:
6254 prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6256 case SECCAT_DATA_REL_RO:
6257 prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6259 case SECCAT_DATA_REL_RO_LOCAL:
6260 prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6263 prefix = one_only ? ".s" : ".sdata";
6266 prefix = one_only ? ".b" : ".bss";
6269 prefix = one_only ? ".sb" : ".sbss";
6272 prefix = one_only ? ".td" : ".tdata";
6275 prefix = one_only ? ".tb" : ".tbss";
6277 case SECCAT_EMUTLS_VAR:
6278 prefix = targetm.emutls.var_section;
6280 case SECCAT_EMUTLS_TMPL:
6281 prefix = targetm.emutls.tmpl_section;
6287 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6288 name = targetm.strip_name_encoding (name);
6290 /* If we're using one_only, then there needs to be a .gnu.linkonce
6291 prefix to the section name. */
6292 linkonce = one_only ? ".gnu.linkonce" : "";
6294 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6296 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6299 /* Like compute_reloc_for_constant, except for an RTX. The return value
6300 is a mask for which bit 1 indicates a global relocation, and bit 0
6301 indicates a local relocation. */
6304 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6306 int *preloc = (int *) data;
6309 switch (GET_CODE (x))
6312 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6325 compute_reloc_for_rtx (rtx x)
6329 switch (GET_CODE (x))
6335 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6344 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6346 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6348 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6349 return data_section;
6351 return readonly_data_section;
6355 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6356 unsigned HOST_WIDE_INT align)
6358 int reloc = compute_reloc_for_rtx (x);
6360 /* ??? Handle small data here somehow. */
6362 if (reloc & targetm.asm_out.reloc_rw_mask ())
6365 return get_named_section (NULL, ".data.rel.ro.local", 1);
6367 return get_named_section (NULL, ".data.rel.ro", 3);
6370 return mergeable_constant_section (mode, align, 0);
6373 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6376 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6381 /* Careful not to prod global register variables. */
6384 symbol = XEXP (rtl, 0);
6385 if (GET_CODE (symbol) != SYMBOL_REF)
6388 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6389 if (TREE_CODE (decl) == FUNCTION_DECL)
6390 flags |= SYMBOL_FLAG_FUNCTION;
6391 if (targetm.binds_local_p (decl))
6392 flags |= SYMBOL_FLAG_LOCAL;
6393 if (targetm.have_tls && TREE_CODE (decl) == VAR_DECL
6394 && DECL_THREAD_LOCAL_P (decl))
6395 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6396 else if (targetm.in_small_data_p (decl))
6397 flags |= SYMBOL_FLAG_SMALL;
6398 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6399 being PUBLIC, the thing *must* be defined in this translation unit.
6400 Prevent this buglet from being propagated into rtl code as well. */
6401 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6402 flags |= SYMBOL_FLAG_EXTERNAL;
6404 SYMBOL_REF_FLAGS (symbol) = flags;
6407 /* By default, we do nothing for encode_section_info, so we need not
6408 do anything but discard the '*' marker. */
6411 default_strip_name_encoding (const char *str)
6413 return str + (*str == '*');
6416 #ifdef ASM_OUTPUT_DEF
6417 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6418 anchor relative to ".", the current section position. */
6421 default_asm_output_anchor (rtx symbol)
6425 sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6426 SYMBOL_REF_BLOCK_OFFSET (symbol));
6427 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6431 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6434 default_use_anchors_for_symbol_p (const_rtx symbol)
6439 /* Don't use anchors for mergeable sections. The linker might move
6440 the objects around. */
6441 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6442 if (sect->common.flags & SECTION_MERGE)
6445 /* Don't use anchors for small data sections. The small data register
6446 acts as an anchor for such sections. */
6447 if (sect->common.flags & SECTION_SMALL)
6450 decl = SYMBOL_REF_DECL (symbol);
6451 if (decl && DECL_P (decl))
6453 /* Don't use section anchors for decls that might be defined by
6455 if (!targetm.binds_local_p (decl))
6458 /* Don't use section anchors for decls that will be placed in a
6459 small data section. */
6460 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6461 one above. The problem is that we only use SECTION_SMALL for
6462 sections that should be marked as small in the section directive. */
6463 if (targetm.in_small_data_p (decl))
6469 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6470 wrt cross-module name binding. */
6473 default_binds_local_p (const_tree exp)
6475 return default_binds_local_p_1 (exp, flag_shlib);
6479 default_binds_local_p_1 (const_tree exp, int shlib)
6483 /* A non-decl is an entry in the constant pool. */
6486 /* Weakrefs may not bind locally, even though the weakref itself is
6487 always static and therefore local. */
6488 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6490 /* Static variables are always local. */
6491 else if (! TREE_PUBLIC (exp))
6493 /* A variable is local if the user has said explicitly that it will
6495 else if (DECL_VISIBILITY_SPECIFIED (exp)
6496 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6498 /* Variables defined outside this object might not be local. */
6499 else if (DECL_EXTERNAL (exp))
6501 /* If defined in this object and visibility is not default, must be
6503 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6505 /* Default visibility weak data can be overridden by a strong symbol
6506 in another module and so are not local. */
6507 else if (DECL_WEAK (exp))
6509 /* If PIC, then assume that any global name can be overridden by
6510 symbols resolved from other modules, unless we are compiling with
6511 -fwhole-program, which assumes that names are local. */
6513 local_p = flag_whole_program;
6514 /* Uninitialized COMMON variable may be unified with symbols
6515 resolved from other modules. */
6516 else if (DECL_COMMON (exp)
6517 && (DECL_INITIAL (exp) == NULL
6518 || DECL_INITIAL (exp) == error_mark_node))
6520 /* Otherwise we're left with initialized (or non-common) global data
6521 which is of necessity defined locally. */
6528 /* Determine whether or not a pointer mode is valid. Assume defaults
6529 of ptr_mode or Pmode - can be overridden. */
6531 default_valid_pointer_mode (enum machine_mode mode)
6533 return (mode == ptr_mode || mode == Pmode);
6536 /* Default function to output code that will globalize a label. A
6537 target must define GLOBAL_ASM_OP or provide its own function to
6538 globalize a label. */
6539 #ifdef GLOBAL_ASM_OP
6541 default_globalize_label (FILE * stream, const char *name)
6543 fputs (GLOBAL_ASM_OP, stream);
6544 assemble_name (stream, name);
6545 putc ('\n', stream);
6547 #endif /* GLOBAL_ASM_OP */
6549 /* Default function to output code that will globalize a declaration. */
6551 default_globalize_decl_name (FILE * stream, tree decl)
6553 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6554 targetm.asm_out.globalize_label (stream, name);
6557 /* Default function to output a label for unwind information. The
6558 default is to do nothing. A target that needs nonlocal labels for
6559 unwind information must provide its own function to do this. */
6561 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6562 tree decl ATTRIBUTE_UNUSED,
6563 int for_eh ATTRIBUTE_UNUSED,
6564 int empty ATTRIBUTE_UNUSED)
6568 /* Default function to output a label to divide up the exception table.
6569 The default is to do nothing. A target that needs/wants to divide
6570 up the table must provide it's own function to do this. */
6572 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6576 /* This is how to output an internal numbered label where PREFIX is
6577 the class of label and LABELNO is the number within the class. */
6580 default_internal_label (FILE *stream, const char *prefix,
6581 unsigned long labelno)
6583 char *const buf = (char *) alloca (40 + strlen (prefix));
6584 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6585 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6588 /* This is the default behavior at the beginning of a file. It's
6589 controlled by two other target-hook toggles. */
6591 default_file_start (void)
6593 if (targetm.file_start_app_off
6594 && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
6595 fputs (ASM_APP_OFF, asm_out_file);
6597 if (targetm.file_start_file_directive)
6598 output_file_directive (asm_out_file, main_input_filename);
6601 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6602 which emits a special section directive used to indicate whether or
6603 not this object file needs an executable stack. This is primarily
6604 a GNU extension to ELF but could be used on other targets. */
6606 int trampolines_created;
6609 file_end_indicate_exec_stack (void)
6611 unsigned int flags = SECTION_DEBUG;
6612 if (trampolines_created)
6613 flags |= SECTION_CODE;
6615 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
6618 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6619 a get_unnamed_section callback. */
6622 output_section_asm_op (const void *directive)
6624 fprintf (asm_out_file, "%s\n", (const char *) directive);
6627 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6628 the current section is NEW_SECTION. */
6631 switch_to_section (section *new_section)
6633 if (in_section == new_section)
6636 if (new_section->common.flags & SECTION_FORGET)
6639 in_section = new_section;
6641 switch (SECTION_STYLE (new_section))
6645 && !crtl->subsections.unlikely_text_section_name
6646 && strcmp (new_section->named.name,
6647 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6648 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6650 targetm.asm_out.named_section (new_section->named.name,
6651 new_section->named.common.flags,
6652 new_section->named.decl);
6655 case SECTION_UNNAMED:
6656 new_section->unnamed.callback (new_section->unnamed.data);
6659 case SECTION_NOSWITCH:
6664 new_section->common.flags |= SECTION_DECLARED;
6667 /* If block symbol SYMBOL has not yet been assigned an offset, place
6668 it at the end of its block. */
6671 place_block_symbol (rtx symbol)
6673 unsigned HOST_WIDE_INT size, mask, offset;
6674 struct constant_descriptor_rtx *desc;
6675 unsigned int alignment;
6676 struct object_block *block;
6679 gcc_assert (SYMBOL_REF_BLOCK (symbol));
6680 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6683 /* Work out the symbol's size and alignment. */
6684 if (CONSTANT_POOL_ADDRESS_P (symbol))
6686 desc = SYMBOL_REF_CONSTANT (symbol);
6687 alignment = desc->align;
6688 size = GET_MODE_SIZE (desc->mode);
6690 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6692 decl = SYMBOL_REF_DECL (symbol);
6693 alignment = get_constant_alignment (decl);
6694 size = get_constant_size (decl);
6698 decl = SYMBOL_REF_DECL (symbol);
6699 alignment = DECL_ALIGN (decl);
6700 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6703 /* Calculate the object's offset from the start of the block. */
6704 block = SYMBOL_REF_BLOCK (symbol);
6705 mask = alignment / BITS_PER_UNIT - 1;
6706 offset = (block->size + mask) & ~mask;
6707 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
6709 /* Record the block's new alignment and size. */
6710 block->alignment = MAX (block->alignment, alignment);
6711 block->size = offset + size;
6713 VEC_safe_push (rtx, gc, block->objects, symbol);
6716 /* Return the anchor that should be used to address byte offset OFFSET
6717 from the first object in BLOCK. MODEL is the TLS model used
6721 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
6722 enum tls_model model)
6725 unsigned int begin, middle, end;
6726 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
6729 /* Work out the anchor's offset. Use an offset of 0 for the first
6730 anchor so that we don't pessimize the case where we take the address
6731 of a variable at the beginning of the block. This is particularly
6732 useful when a block has only one variable assigned to it.
6734 We try to place anchors RANGE bytes apart, so there can then be
6735 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6736 a ptr_mode offset. With some target settings, the lowest such
6737 anchor might be out of range for the lowest ptr_mode offset;
6738 likewise the highest anchor for the highest offset. Use anchors
6739 at the extreme ends of the ptr_mode range in such cases.
6741 All arithmetic uses unsigned integers in order to avoid
6743 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
6744 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
6745 range = max_offset - min_offset + 1;
6750 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
6753 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
6754 delta -= delta % range;
6757 offset = (HOST_WIDE_INT) (-delta);
6761 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
6762 delta -= delta % range;
6763 if (delta > bias - 1)
6765 offset = (HOST_WIDE_INT) delta;
6769 /* Do a binary search to see if there's already an anchor we can use.
6770 Set BEGIN to the new anchor's index if not. */
6772 end = VEC_length (rtx, block->anchors);
6773 while (begin != end)
6775 middle = (end + begin) / 2;
6776 anchor = VEC_index (rtx, block->anchors, middle);
6777 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
6779 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
6781 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
6783 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
6789 /* Create a new anchor with a unique label. */
6790 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
6791 anchor = create_block_symbol (ggc_strdup (label), block, offset);
6792 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
6793 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
6795 /* Insert it at index BEGIN. */
6796 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
6800 /* Output the objects in BLOCK. */
6803 output_object_block (struct object_block *block)
6805 struct constant_descriptor_rtx *desc;
6807 HOST_WIDE_INT offset;
6811 if (block->objects == NULL)
6814 /* Switch to the section and make sure that the first byte is
6815 suitably aligned. */
6816 switch_to_section (block->sect);
6817 assemble_align (block->alignment);
6819 /* Define the values of all anchors relative to the current section
6821 for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
6822 targetm.asm_out.output_anchor (symbol);
6824 /* Output the objects themselves. */
6826 for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
6828 /* Move to the object's offset, padding with zeros if necessary. */
6829 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
6830 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
6831 if (CONSTANT_POOL_ADDRESS_P (symbol))
6833 desc = SYMBOL_REF_CONSTANT (symbol);
6834 output_constant_pool_1 (desc, 1);
6835 offset += GET_MODE_SIZE (desc->mode);
6837 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6839 decl = SYMBOL_REF_DECL (symbol);
6840 assemble_constant_contents (decl, XSTR (symbol, 0),
6841 get_constant_alignment (decl));
6842 offset += get_constant_size (decl);
6846 decl = SYMBOL_REF_DECL (symbol);
6847 assemble_variable_contents (decl, XSTR (symbol, 0), false);
6848 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6853 /* A htab_traverse callback used to call output_object_block for
6854 each member of object_block_htab. */
6857 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
6859 output_object_block ((struct object_block *) (*slot));
6863 /* Output the definitions of all object_blocks. */
6866 output_object_blocks (void)
6868 htab_traverse (object_block_htab, output_object_block_htab, NULL);
6871 /* This function provides a possible implementation of the
6872 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
6873 by -frecord-gcc-switches it creates a new mergeable, string section in the
6874 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
6875 contains the switches in ASCII format.
6877 FIXME: This code does not correctly handle double quote characters
6878 that appear inside strings, (it strips them rather than preserving them).
6879 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
6880 characters - instead it treats them as sub-string separators. Since
6881 we want to emit NUL strings terminators into the object file we have to use
6885 elf_record_gcc_switches (print_switch_type type, const char * name)
6887 static char buffer[1024];
6889 /* This variable is used as part of a simplistic heuristic to detect
6890 command line switches which take an argument:
6892 "If a command line option does not start with a dash then
6893 it is an argument for the previous command line option."
6895 This fails in the case of the command line option which is the name
6896 of the file to compile, but otherwise it is pretty reasonable. */
6897 static bool previous_name_held_back = FALSE;
6901 case SWITCH_TYPE_PASSED:
6904 if (previous_name_held_back)
6906 unsigned int len = strlen (buffer);
6908 snprintf (buffer + len, sizeof buffer - len, " %s", name);
6909 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
6910 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
6911 previous_name_held_back = FALSE;
6915 strncpy (buffer, name, sizeof buffer);
6916 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
6917 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
6922 if (previous_name_held_back)
6924 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
6925 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
6928 strncpy (buffer, name, sizeof buffer);
6929 previous_name_held_back = TRUE;
6933 case SWITCH_TYPE_DESCRIPTIVE:
6936 /* Distinguish between invocations where name is NULL. */
6937 static bool started = false;
6941 if (previous_name_held_back)
6943 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
6944 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
6951 sec = get_section (targetm.asm_out.record_gcc_switches_section,
6955 | (SECTION_ENTSIZE & 1),
6957 switch_to_section (sec);
6966 /* The return value is currently ignored by the caller, but must be 0.
6967 For -fverbose-asm the return value would be the number of characters
6968 emitted into the assembler file. */
6972 /* Emit text to declare externally defined symbols. It is needed to
6973 properly support non-default visibility. */
6975 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
6977 const char *name ATTRIBUTE_UNUSED)
6979 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
6980 set in order to avoid putting out names that are never really
6982 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
6983 && targetm.binds_local_p (decl))
6984 maybe_assemble_visibility (decl);
6987 #include "gt-varasm.h"