1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
42 #include "diagnostic-core.h"
46 #include "langhooks.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h" /* Needed for external data
59 declarations for e.g. AIX 4.x. */
62 /* The (assembler) name of the first globally-visible object output. */
63 extern GTY(()) const char *first_global_object_name;
64 extern GTY(()) const char *weak_global_object_name;
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
70 struct constant_descriptor_rtx;
71 struct rtx_constant_pool;
73 #define n_deferred_constants (crtl->varasm.deferred_constants)
75 /* Number for making the label on the next
76 constant that is stored in memory. */
78 static GTY(()) int const_labelno;
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81 to ASM_FINISH_DECLARE_OBJECT. */
83 int size_directive_output;
85 /* The last decl for which assemble_variable was called,
86 if it did ASM_DECLARE_OBJECT_NAME.
87 If the last call to assemble_variable didn't do that,
90 tree last_assemble_variable_decl;
92 /* The following global variable indicates if the first basic block
93 in a function belongs to the cold partition or not. */
95 bool first_function_block_is_cold;
97 /* We give all constants their own alias set. Perhaps redundant with
98 MEM_READONLY_P, but pre-dates it. */
100 static alias_set_type const_alias_set;
102 static const char *strip_reg_name (const char *);
103 static int contains_pointers_p (tree);
104 #ifdef ASM_OUTPUT_EXTERNAL
105 static bool incorporeal_function_p (tree);
107 static void decode_addr_const (tree, struct addr_const *);
108 static hashval_t const_desc_hash (const void *);
109 static int const_desc_eq (const void *, const void *);
110 static hashval_t const_hash_1 (const tree);
111 static int compare_constant (const tree, const tree);
112 static tree copy_constant (tree);
113 static void output_constant_def_contents (rtx);
114 static void output_addressed_constants (tree);
115 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
116 static unsigned min_align (unsigned, unsigned);
117 static void globalize_decl (tree);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_BSS
120 static void asm_output_bss (FILE *, tree, const char *,
121 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
123 #ifdef ASM_OUTPUT_ALIGNED_BSS
124 static void asm_output_aligned_bss (FILE *, tree, const char *,
125 unsigned HOST_WIDE_INT, int)
128 #endif /* BSS_SECTION_ASM_OP */
129 static void mark_weak (tree);
130 static void output_constant_pool (const char *, tree);
132 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
133 section *text_section;
134 section *data_section;
135 section *readonly_data_section;
136 section *sdata_section;
137 section *ctors_section;
138 section *dtors_section;
139 section *bss_section;
140 section *sbss_section;
142 /* Various forms of common section. All are guaranteed to be nonnull. */
143 section *tls_comm_section;
144 section *comm_section;
145 section *lcomm_section;
147 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
149 section *bss_noswitch_section;
151 /* The section that holds the main exception table, when known. The section
152 is set either by the target's init_sections hook or by the first call to
153 switch_to_exception_section. */
154 section *exception_section;
156 /* The section that holds the DWARF2 frame unwind information, when known.
157 The section is set either by the target's init_sections hook or by the
158 first call to switch_to_eh_frame_section. */
159 section *eh_frame_section;
161 /* asm_out_file's current section. This is NULL if no section has yet
162 been selected or if we lose track of what the current section is. */
165 /* True if code for the current function is currently being directed
166 at the cold section. */
167 bool in_cold_section_p;
169 /* A linked list of all the unnamed sections. */
170 static GTY(()) section *unnamed_sections;
172 /* Return a nonzero value if DECL has a section attribute. */
173 #define IN_NAMED_SECTION(DECL) \
174 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
175 && DECL_SECTION_NAME (DECL) != NULL_TREE)
177 /* Hash table of named sections. */
178 static GTY((param_is (section))) htab_t section_htab;
180 /* A table of object_blocks, indexed by section. */
181 static GTY((param_is (struct object_block))) htab_t object_block_htab;
183 /* The next number to use for internal anchor labels. */
184 static GTY(()) int anchor_labelno;
186 /* A pool of constants that can be shared between functions. */
187 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
193 static GTY (()) tree emutls_object_type;
194 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
195 macro can be used on them to distinguish the control variable from
196 the initialization template. */
197 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
199 #if !defined (NO_DOT_IN_LABEL)
200 # define EMUTLS_SEPARATOR "."
201 #elif !defined (NO_DOLLAR_IN_LABEL)
202 # define EMUTLS_SEPARATOR "$"
204 # define EMUTLS_SEPARATOR "_"
207 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
208 IDENTIFIER_NODE NAME's name. */
211 prefix_name (const char *prefix, tree name)
213 unsigned plen = strlen (prefix);
214 unsigned nlen = strlen (IDENTIFIER_POINTER (name));
215 char *toname = (char *) alloca (plen + nlen + 1);
217 memcpy (toname, prefix, plen);
218 memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
220 return get_identifier (toname);
223 /* Create an identifier for the struct __emutls_object, given an identifier
224 of the DECL_ASSEMBLY_NAME of the original object. */
227 get_emutls_object_name (tree name)
229 const char *prefix = (targetm.emutls.var_prefix
230 ? targetm.emutls.var_prefix
231 : "__emutls_v" EMUTLS_SEPARATOR);
232 return prefix_name (prefix, name);
236 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
238 tree word_type_node, field, next_field;
240 field = build_decl (UNKNOWN_LOCATION,
241 FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
242 DECL_CONTEXT (field) = type;
245 field = build_decl (UNKNOWN_LOCATION,
246 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 (UNKNOWN_LOCATION,
254 FIELD_DECL, get_identifier ("__align"),
256 DECL_CONTEXT (field) = type;
257 TREE_CHAIN (field) = next_field;
260 field = build_decl (UNKNOWN_LOCATION,
261 FIELD_DECL, get_identifier ("__size"), word_type_node);
262 DECL_CONTEXT (field) = type;
263 TREE_CHAIN (field) = next_field;
268 /* Create the structure for struct __emutls_object. This should match the
269 structure at the top of emutls.c, modulo the union there. */
272 get_emutls_object_type (void)
274 tree type, type_name, field;
276 type = emutls_object_type;
280 emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
282 field = targetm.emutls.var_fields (type, &type_name);
284 type_name = get_identifier ("__emutls_object");
285 type_name = build_decl (UNKNOWN_LOCATION,
286 TYPE_DECL, type_name, type);
287 TYPE_NAME (type) = type_name;
288 TYPE_FIELDS (type) = field;
294 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
295 This will be used for initializing the emulated tls data area. */
298 get_emutls_init_templ_addr (tree decl)
302 if (targetm.emutls.register_common && !DECL_INITIAL (decl)
303 && !DECL_SECTION_NAME (decl))
304 return null_pointer_node;
306 name = DECL_ASSEMBLER_NAME (decl);
307 if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0])
309 const char *prefix = (targetm.emutls.tmpl_prefix
310 ? targetm.emutls.tmpl_prefix
311 : "__emutls_t" EMUTLS_SEPARATOR);
312 name = prefix_name (prefix, name);
315 to = build_decl (DECL_SOURCE_LOCATION (decl),
316 VAR_DECL, name, TREE_TYPE (decl));
317 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
319 DECL_ARTIFICIAL (to) = 1;
320 TREE_USED (to) = TREE_USED (decl);
321 TREE_READONLY (to) = 1;
322 DECL_IGNORED_P (to) = 1;
323 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
324 DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
325 DECL_PRESERVE_P (to) = DECL_PRESERVE_P (decl);
327 DECL_WEAK (to) = DECL_WEAK (decl);
328 if (DECL_ONE_ONLY (decl))
330 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
331 TREE_STATIC (to) = TREE_STATIC (decl);
332 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
333 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
336 TREE_STATIC (to) = 1;
338 DECL_VISIBILITY_SPECIFIED (to) = DECL_VISIBILITY_SPECIFIED (decl);
339 DECL_INITIAL (to) = DECL_INITIAL (decl);
340 DECL_INITIAL (decl) = NULL;
342 varpool_finalize_decl (to);
343 return build_fold_addr_expr (to);
346 /* When emulating tls, we use a control structure for use by the runtime.
347 Create and return this structure. */
350 emutls_decl (tree decl)
353 struct tree_map *h, in;
356 if (targetm.have_tls || decl == NULL || decl == error_mark_node
357 || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
360 /* Look up the object in the hash; return the control structure if
361 it has already been created. */
363 emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
365 name = DECL_ASSEMBLER_NAME (decl);
367 /* Note that we use the hash of the decl's name, rather than a hash
368 of the decl's pointer. In emutls_finish we iterate through the
369 hash table, and we want this traversal to be predictable. */
370 in.hash = IDENTIFIER_HASH_VALUE (name);
372 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
373 h = (struct tree_map *) *loc;
378 to = build_decl (DECL_SOURCE_LOCATION (decl),
379 VAR_DECL, get_emutls_object_name (name),
380 get_emutls_object_type ());
382 h = ggc_alloc_tree_map ();
386 *(struct tree_map **) loc = h;
388 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
389 DECL_ARTIFICIAL (to) = 1;
390 DECL_IGNORED_P (to) = 1;
391 /* FIXME: work around PR44132. */
392 DECL_PRESERVE_P (to) = 1;
393 TREE_READONLY (to) = 0;
394 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
395 if (DECL_ONE_ONLY (decl))
396 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
397 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
398 if (targetm.emutls.var_align_fixed)
399 /* If we're not allowed to change the proxy object's
400 alignment, pretend it's been set by the user. */
401 DECL_USER_ALIGN (to) = 1;
404 /* Note that these fields may need to be updated from time to time from
405 the original decl. Consider:
406 extern __thread int i;
407 int foo() { return i; }
409 in which I goes from external to locally defined and initialized. */
410 DECL_DLLIMPORT_P (to) = DECL_DLLIMPORT_P (decl);
411 DECL_ATTRIBUTES (to) = targetm.merge_decl_attributes (decl, to);
413 TREE_STATIC (to) = TREE_STATIC (decl);
414 TREE_USED (to) = TREE_USED (decl);
415 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
416 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
417 DECL_COMMON (to) = DECL_COMMON (decl);
418 DECL_WEAK (to) = DECL_WEAK (decl);
419 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
420 DECL_VISIBILITY_SPECIFIED (to) = DECL_VISIBILITY_SPECIFIED (decl);
422 /* Fortran might pass this to us. */
423 DECL_RESTRICTED_P (to) = DECL_RESTRICTED_P (decl);
429 emutls_common_1 (void **loc, void *xstmts)
431 struct tree_map *h = *(struct tree_map **) loc;
432 tree args, x, *pstmts = (tree *) xstmts;
435 if (! DECL_COMMON (h->base.from)
436 || (DECL_INITIAL (h->base.from)
437 && DECL_INITIAL (h->base.from) != error_mark_node))
440 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
442 /* The idea was to call get_emutls_init_templ_addr here, but if we
443 do this and there is an initializer, -fanchor_section loses,
444 because it would be too late to ensure the template is
446 x = null_pointer_node;
447 args = tree_cons (NULL, x, NULL);
448 x = build_int_cst (word_type_node, DECL_ALIGN_UNIT (h->base.from));
449 args = tree_cons (NULL, x, args);
450 x = fold_convert (word_type_node, DECL_SIZE_UNIT (h->base.from));
451 args = tree_cons (NULL, x, args);
452 x = build_fold_addr_expr (h->to);
453 args = tree_cons (NULL, x, args);
455 x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
456 x = build_function_call_expr (UNKNOWN_LOCATION, x, args);
458 append_to_statement_list (x, pstmts);
462 /* Callback to finalize one emutls control variable. */
465 emutls_finalize_control_var (void **loc,
466 void *unused ATTRIBUTE_UNUSED)
468 struct tree_map *h = *(struct tree_map **) loc;
471 struct varpool_node *node = varpool_node (h->to);
472 /* Because varpool_finalize_decl () has side-effects,
473 only apply to un-finalized vars. */
474 if (node && !node->finalized)
475 varpool_finalize_decl (h->to);
480 /* Finalize emutls control vars and add a static constructor if
486 if (emutls_htab == NULL)
488 htab_traverse_noresize (emutls_htab,
489 emutls_finalize_control_var, NULL);
491 if (targetm.emutls.register_common)
493 tree body = NULL_TREE;
495 htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
496 if (body == NULL_TREE)
499 cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
503 /* Helper routines for maintaining section_htab. */
506 section_entry_eq (const void *p1, const void *p2)
508 const section *old = (const section *) p1;
509 const char *new_name = (const char *) p2;
511 return strcmp (old->named.name, new_name) == 0;
515 section_entry_hash (const void *p)
517 const section *old = (const section *) p;
518 return htab_hash_string (old->named.name);
521 /* Return a hash value for section SECT. */
524 hash_section (section *sect)
526 if (sect->common.flags & SECTION_NAMED)
527 return htab_hash_string (sect->named.name);
528 return sect->common.flags;
531 /* Helper routines for maintaining object_block_htab. */
534 object_block_entry_eq (const void *p1, const void *p2)
536 const struct object_block *old = (const struct object_block *) p1;
537 const section *new_section = (const section *) p2;
539 return old->sect == new_section;
543 object_block_entry_hash (const void *p)
545 const struct object_block *old = (const struct object_block *) p;
546 return hash_section (old->sect);
549 /* Return a new unnamed section with the given fields. */
552 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
557 sect = ggc_alloc_section ();
558 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
559 sect->unnamed.callback = callback;
560 sect->unnamed.data = data;
561 sect->unnamed.next = unnamed_sections;
563 unnamed_sections = sect;
567 /* Return a SECTION_NOSWITCH section with the given fields. */
570 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
574 sect = ggc_alloc_section ();
575 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
576 sect->noswitch.callback = callback;
581 /* Return the named section structure associated with NAME. Create
582 a new section with the given fields if no such structure exists. */
585 get_section (const char *name, unsigned int flags, tree decl)
587 section *sect, **slot;
590 htab_find_slot_with_hash (section_htab, name,
591 htab_hash_string (name), INSERT);
592 flags |= SECTION_NAMED;
595 sect = ggc_alloc_section ();
596 sect->named.common.flags = flags;
597 sect->named.name = ggc_strdup (name);
598 sect->named.decl = decl;
604 if ((sect->common.flags & ~SECTION_DECLARED) != flags
605 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
607 /* Sanity check user variables for flag changes. */
609 decl = sect->named.decl;
611 error ("%+D causes a section type conflict", decl);
617 /* Return true if the current compilation mode benefits from having
618 objects grouped into blocks. */
621 use_object_blocks_p (void)
623 return flag_section_anchors;
626 /* Return the object_block structure for section SECT. Create a new
627 structure if we haven't created one already. Return null if SECT
630 static struct object_block *
631 get_block_for_section (section *sect)
633 struct object_block *block;
639 slot = htab_find_slot_with_hash (object_block_htab, sect,
640 hash_section (sect), INSERT);
641 block = (struct object_block *) *slot;
644 block = ggc_alloc_cleared_object_block ();
651 /* Create a symbol with label LABEL and place it at byte offset
652 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
653 is not yet known. LABEL must be a garbage-collected string. */
656 create_block_symbol (const char *label, struct object_block *block,
657 HOST_WIDE_INT offset)
662 /* Create the extended SYMBOL_REF. */
663 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
664 symbol = ggc_alloc_zone_rtx_def (size, &rtl_zone);
666 /* Initialize the normal SYMBOL_REF fields. */
667 memset (symbol, 0, size);
668 PUT_CODE (symbol, SYMBOL_REF);
669 PUT_MODE (symbol, Pmode);
670 XSTR (symbol, 0) = label;
671 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
673 /* Initialize the block_symbol stuff. */
674 SYMBOL_REF_BLOCK (symbol) = block;
675 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
681 initialize_cold_section_name (void)
683 const char *stripped_name;
687 gcc_assert (cfun && current_function_decl);
688 if (crtl->subsections.unlikely_text_section_name)
691 dsn = DECL_SECTION_NAME (current_function_decl);
692 if (flag_function_sections && dsn)
694 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
695 memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
697 stripped_name = targetm.strip_name_encoding (name);
699 buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
700 crtl->subsections.unlikely_text_section_name = ggc_strdup (buffer);
703 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
706 /* Tell assembler to switch to unlikely-to-be-executed text section. */
709 unlikely_text_section (void)
713 if (!crtl->subsections.unlikely_text_section_name)
714 initialize_cold_section_name ();
716 return get_named_section (NULL, crtl->subsections.unlikely_text_section_name, 0);
719 return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
722 /* When called within a function context, return true if the function
723 has been assigned a cold text section and if SECT is that section.
724 When called outside a function context, return true if SECT is the
725 default cold section. */
728 unlikely_text_section_p (section *sect)
733 name = crtl->subsections.unlikely_text_section_name;
735 name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
739 && SECTION_STYLE (sect) == SECTION_NAMED
740 && strcmp (name, sect->named.name) == 0);
743 /* Return a section with a particular name and with whatever SECTION_*
744 flags section_type_flags deems appropriate. The name of the section
745 is taken from NAME if nonnull, otherwise it is taken from DECL's
746 DECL_SECTION_NAME. DECL is the decl associated with the section
747 (see the section comment for details) and RELOC is as for
748 section_type_flags. */
751 get_named_section (tree decl, const char *name, int reloc)
755 gcc_assert (!decl || DECL_P (decl));
757 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
759 flags = targetm.section_type_flags (decl, name, reloc);
761 return get_section (name, flags, decl);
764 /* If required, set DECL_SECTION_NAME to a unique name. */
767 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
768 int flag_function_or_data_sections)
770 if (DECL_SECTION_NAME (decl) == NULL_TREE
771 && targetm.have_named_sections
772 && (flag_function_or_data_sections
773 || DECL_ONE_ONLY (decl)))
774 targetm.asm_out.unique_section (decl, reloc);
777 #ifdef BSS_SECTION_ASM_OP
779 #ifdef ASM_OUTPUT_BSS
781 /* Utility function for ASM_OUTPUT_BSS for targets to use if
782 they don't support alignments in .bss.
783 ??? It is believed that this function will work in most cases so such
784 support is localized here. */
787 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
789 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
790 unsigned HOST_WIDE_INT rounded)
792 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl), 0), 0), name) == 0);
793 targetm.asm_out.globalize_decl_name (file, decl);
794 switch_to_section (bss_section);
795 #ifdef ASM_DECLARE_OBJECT_NAME
796 last_assemble_variable_decl = decl;
797 ASM_DECLARE_OBJECT_NAME (file, name, decl);
799 /* Standard thing is just output label for the object. */
800 ASM_OUTPUT_LABEL (file, name);
801 #endif /* ASM_DECLARE_OBJECT_NAME */
802 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
807 #ifdef ASM_OUTPUT_ALIGNED_BSS
809 /* Utility function for targets to use in implementing
810 ASM_OUTPUT_ALIGNED_BSS.
811 ??? It is believed that this function will work in most cases so such
812 support is localized here. */
815 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
816 const char *name, unsigned HOST_WIDE_INT size,
819 switch_to_section (bss_section);
820 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
821 #ifdef ASM_DECLARE_OBJECT_NAME
822 last_assemble_variable_decl = decl;
823 ASM_DECLARE_OBJECT_NAME (file, name, decl);
825 /* Standard thing is just output label for the object. */
826 ASM_OUTPUT_LABEL (file, name);
827 #endif /* ASM_DECLARE_OBJECT_NAME */
828 ASM_OUTPUT_SKIP (file, size ? size : 1);
833 #endif /* BSS_SECTION_ASM_OP */
835 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
836 /* Return the hot section for function DECL. Return text_section for
840 hot_function_section (tree decl)
842 if (decl != NULL_TREE
843 && DECL_SECTION_NAME (decl) != NULL_TREE
844 && targetm.have_named_sections)
845 return get_named_section (decl, NULL, 0);
851 /* Return the section for function DECL.
853 If DECL is NULL_TREE, return the text section. We can be passed
854 NULL_TREE under some circumstances by dbxout.c at least. */
857 function_section (tree decl)
861 if (first_function_block_is_cold)
864 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
865 if (decl != NULL_TREE
866 && DECL_SECTION_NAME (decl) != NULL_TREE)
867 return reloc ? unlikely_text_section ()
868 : get_named_section (decl, NULL, 0);
870 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
872 return reloc ? unlikely_text_section () : hot_function_section (decl);
877 current_function_section (void)
879 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
880 if (current_function_decl != NULL_TREE
881 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
882 return in_cold_section_p ? unlikely_text_section ()
883 : get_named_section (current_function_decl,
886 return targetm.asm_out.select_section (current_function_decl,
888 DECL_ALIGN (current_function_decl));
890 return (in_cold_section_p
891 ? unlikely_text_section ()
892 : hot_function_section (current_function_decl));
896 /* Return the read-only data section associated with function DECL. */
899 default_function_rodata_section (tree decl)
901 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
903 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
905 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
911 dot = strchr (name + 1, '.');
914 len = strlen (dot) + 8;
915 rname = (char *) alloca (len);
917 strcpy (rname, ".rodata");
919 return get_section (rname, SECTION_LINKONCE, decl);
921 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
922 else if (DECL_ONE_ONLY (decl)
923 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
925 size_t len = strlen (name) + 1;
926 char *rname = (char *) alloca (len);
928 memcpy (rname, name, len);
930 return get_section (rname, SECTION_LINKONCE, decl);
932 /* For .text.foo we want to use .rodata.foo. */
933 else if (flag_function_sections && flag_data_sections
934 && strncmp (name, ".text.", 6) == 0)
936 size_t len = strlen (name) + 1;
937 char *rname = (char *) alloca (len + 2);
939 memcpy (rname, ".rodata", 7);
940 memcpy (rname + 7, name + 5, len - 5);
941 return get_section (rname, 0, decl);
945 return readonly_data_section;
948 /* Return the read-only data section associated with function DECL
949 for targets where that section should be always the single
950 readonly data section. */
953 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
955 return readonly_data_section;
958 /* Return the section to use for string merging. */
961 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
962 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
963 unsigned int flags ATTRIBUTE_UNUSED)
967 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
968 && TREE_CODE (decl) == STRING_CST
969 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
971 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
972 && TREE_STRING_LENGTH (decl) >= len)
974 enum machine_mode mode;
975 unsigned int modesize;
981 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
982 modesize = GET_MODE_BITSIZE (mode);
983 if (modesize >= 8 && modesize <= 256
984 && (modesize & (modesize - 1)) == 0)
986 if (align < modesize)
989 str = TREE_STRING_POINTER (decl);
990 unit = GET_MODE_SIZE (mode);
992 /* Check for embedded NUL characters. */
993 for (i = 0; i < len; i += unit)
995 for (j = 0; j < unit; j++)
996 if (str[i + j] != '\0')
1001 if (i == len - unit)
1003 sprintf (name, ".rodata.str%d.%d", modesize / 8,
1005 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
1006 return get_section (name, flags, NULL);
1011 return readonly_data_section;
1014 /* Return the section to use for constant merging. */
1017 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
1018 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
1019 unsigned int flags ATTRIBUTE_UNUSED)
1021 unsigned int modesize = GET_MODE_BITSIZE (mode);
1023 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
1026 && modesize <= align
1029 && (align & (align - 1)) == 0)
1033 sprintf (name, ".rodata.cst%d", (int) (align / 8));
1034 flags |= (align / 8) | SECTION_MERGE;
1035 return get_section (name, flags, NULL);
1037 return readonly_data_section;
1040 /* Given NAME, a putative register name, discard any customary prefixes. */
1043 strip_reg_name (const char *name)
1045 #ifdef REGISTER_PREFIX
1046 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
1047 name += strlen (REGISTER_PREFIX);
1049 if (name[0] == '%' || name[0] == '#')
1054 /* The user has asked for a DECL to have a particular name. Set (or
1055 change) it in such a way that we don't prefix an underscore to
1058 set_user_assembler_name (tree decl, const char *name)
1060 char *starred = (char *) alloca (strlen (name) + 2);
1062 strcpy (starred + 1, name);
1063 change_decl_assembler_name (decl, get_identifier (starred));
1064 SET_DECL_RTL (decl, NULL_RTX);
1067 /* Decode an `asm' spec for a declaration as a register name.
1068 Return the register number, or -1 if nothing specified,
1069 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1070 or -3 if ASMSPEC is `cc' and is not recognized,
1071 or -4 if ASMSPEC is `memory' and is not recognized.
1072 Accept an exact spelling or a decimal number.
1073 Prefixes such as % are optional. */
1076 decode_reg_name (const char *asmspec)
1082 /* Get rid of confusing prefixes. */
1083 asmspec = strip_reg_name (asmspec);
1085 /* Allow a decimal number as a "register name". */
1086 for (i = strlen (asmspec) - 1; i >= 0; i--)
1087 if (! ISDIGIT (asmspec[i]))
1089 if (asmspec[0] != 0 && i < 0)
1092 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
1098 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1100 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1103 #ifdef ADDITIONAL_REGISTER_NAMES
1105 static const struct { const char *const name; const int number; } table[]
1106 = ADDITIONAL_REGISTER_NAMES;
1108 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1109 if (table[i].name[0]
1110 && ! strcmp (asmspec, table[i].name))
1111 return table[i].number;
1113 #endif /* ADDITIONAL_REGISTER_NAMES */
1115 if (!strcmp (asmspec, "memory"))
1118 if (!strcmp (asmspec, "cc"))
1127 /* Return true if DECL's initializer is suitable for a BSS section. */
1130 bss_initializer_p (const_tree decl)
1132 return (DECL_INITIAL (decl) == NULL
1133 || DECL_INITIAL (decl) == error_mark_node
1134 || (flag_zero_initialized_in_bss
1135 /* Leave constant zeroes in .rodata so they
1137 && !TREE_READONLY (decl)
1138 && initializer_zerop (DECL_INITIAL (decl))));
1141 /* Compute the alignment of variable specified by DECL.
1142 DONT_OUTPUT_DATA is from assemble_variable. */
1145 align_variable (tree decl, bool dont_output_data)
1147 unsigned int align = DECL_ALIGN (decl);
1149 /* In the case for initialing an array whose length isn't specified,
1150 where we have not yet been able to do the layout,
1151 figure out the proper alignment now. */
1152 if (dont_output_data && DECL_SIZE (decl) == 0
1153 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1154 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1156 /* Some object file formats have a maximum alignment which they support.
1157 In particular, a.out format supports a maximum alignment of 4. */
1158 if (align > MAX_OFILE_ALIGNMENT)
1160 warning (0, "alignment of %q+D is greater than maximum object "
1161 "file alignment. Using %d", decl,
1162 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1163 align = MAX_OFILE_ALIGNMENT;
1166 /* On some machines, it is good to increase alignment sometimes. */
1167 if (! DECL_USER_ALIGN (decl))
1169 #ifdef DATA_ALIGNMENT
1170 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1171 /* Don't increase alignment too much for TLS variables - TLS space
1173 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1176 #ifdef CONSTANT_ALIGNMENT
1177 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1179 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
1181 /* Don't increase alignment too much for TLS variables - TLS space
1183 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1184 align = const_align;
1189 /* Reset the alignment in case we have made it tighter, so we can benefit
1190 from it in get_pointer_alignment. */
1191 DECL_ALIGN (decl) = align;
1194 /* Return the section into which the given VAR_DECL or CONST_DECL
1195 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1196 section should be used wherever possible. */
1199 get_variable_section (tree decl, bool prefer_noswitch_p)
1201 addr_space_t as = ADDR_SPACE_GENERIC;
1204 if (TREE_TYPE (decl) != error_mark_node)
1205 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1207 if (DECL_COMMON (decl))
1209 /* If the decl has been given an explicit section name, or it resides
1210 in a non-generic address space, then it isn't common, and shouldn't
1211 be handled as such. */
1212 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1213 && ADDR_SPACE_GENERIC_P (as));
1214 if (DECL_THREAD_LOCAL_P (decl))
1215 return tls_comm_section;
1216 /* This cannot be common bss for an emulated TLS object without
1217 a register_common hook. */
1218 else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED
1219 && !targetm.emutls.register_common)
1221 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1222 return comm_section;
1225 if (DECL_INITIAL (decl) == error_mark_node)
1226 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1227 else if (DECL_INITIAL (decl))
1228 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1232 resolve_unique_section (decl, reloc, flag_data_sections);
1233 if (IN_NAMED_SECTION (decl))
1234 return get_named_section (decl, NULL, reloc);
1236 if (ADDR_SPACE_GENERIC_P (as)
1237 && !DECL_THREAD_LOCAL_P (decl)
1238 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1239 && bss_initializer_p (decl))
1241 if (!TREE_PUBLIC (decl))
1242 return lcomm_section;
1243 if (bss_noswitch_section)
1244 return bss_noswitch_section;
1247 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1250 /* Return the block into which object_block DECL should be placed. */
1252 static struct object_block *
1253 get_block_for_decl (tree decl)
1257 if (TREE_CODE (decl) == VAR_DECL)
1259 /* The object must be defined in this translation unit. */
1260 if (DECL_EXTERNAL (decl))
1263 /* There's no point using object blocks for something that is
1264 isolated by definition. */
1265 if (DECL_ONE_ONLY (decl))
1269 /* We can only calculate block offsets if the decl has a known
1271 if (DECL_SIZE_UNIT (decl) == NULL)
1273 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1276 /* Find out which section should contain DECL. We cannot put it into
1277 an object block if it requires a standalone definition. */
1278 if (TREE_CODE (decl) == VAR_DECL)
1279 align_variable (decl, 0);
1280 sect = get_variable_section (decl, true);
1281 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1284 return get_block_for_section (sect);
1287 /* Make sure block symbol SYMBOL is in block BLOCK. */
1290 change_symbol_block (rtx symbol, struct object_block *block)
1292 if (block != SYMBOL_REF_BLOCK (symbol))
1294 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1295 SYMBOL_REF_BLOCK (symbol) = block;
1299 /* Return true if it is possible to put DECL in an object_block. */
1302 use_blocks_for_decl_p (tree decl)
1304 /* Only data DECLs can be placed into object blocks. */
1305 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1308 /* Detect decls created by dw2_force_const_mem. Such decls are
1309 special because DECL_INITIAL doesn't specify the decl's true value.
1310 dw2_output_indirect_constants will instead call assemble_variable
1311 with dont_output_data set to 1 and then print the contents itself. */
1312 if (DECL_INITIAL (decl) == decl)
1315 /* If this decl is an alias, then we don't want to emit a definition. */
1316 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1322 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1323 have static storage duration. In other words, it should not be an
1324 automatic variable, including PARM_DECLs.
1326 There is, however, one exception: this function handles variables
1327 explicitly placed in a particular register by the user.
1329 This is never called for PARM_DECL nodes. */
1332 make_decl_rtl (tree decl)
1334 const char *name = 0;
1338 /* Check that we are not being given an automatic variable. */
1339 gcc_assert (TREE_CODE (decl) != PARM_DECL
1340 && TREE_CODE (decl) != RESULT_DECL);
1342 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1343 gcc_assert (TREE_CODE (decl) != VAR_DECL
1344 || TREE_STATIC (decl)
1345 || TREE_PUBLIC (decl)
1346 || DECL_EXTERNAL (decl)
1347 || DECL_REGISTER (decl));
1349 /* And that we were not given a type or a label. */
1350 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1351 && TREE_CODE (decl) != LABEL_DECL);
1353 /* For a duplicate declaration, we can be called twice on the
1354 same DECL node. Don't discard the RTL already made. */
1355 if (DECL_RTL_SET_P (decl))
1357 /* If the old RTL had the wrong mode, fix the mode. */
1358 x = DECL_RTL (decl);
1359 if (GET_MODE (x) != DECL_MODE (decl))
1360 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1362 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1365 /* ??? Another way to do this would be to maintain a hashed
1366 table of such critters. Instead of adding stuff to a DECL
1367 to give certain attributes to it, we could use an external
1368 hash map from DECL to set of attributes. */
1370 /* Let the target reassign the RTL if it wants.
1371 This is necessary, for example, when one machine specific
1372 decl attribute overrides another. */
1373 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1375 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1376 on the new decl information. */
1378 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1379 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1380 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1382 /* Make this function static known to the mudflap runtime. */
1383 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1384 mudflap_enqueue_decl (decl);
1389 /* If this variable belongs to the global constant pool, retrieve the
1390 pre-computed RTL or recompute it in LTO mode. */
1391 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1393 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1397 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1399 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1400 && DECL_REGISTER (decl))
1402 error ("register name not specified for %q+D", decl);
1404 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1406 const char *asmspec = name+1;
1407 reg_number = decode_reg_name (asmspec);
1408 /* First detect errors in declaring global registers. */
1409 if (reg_number == -1)
1410 error ("register name not specified for %q+D", decl);
1411 else if (reg_number < 0)
1412 error ("invalid register name for %q+D", decl);
1413 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1414 error ("data type of %q+D isn%'t suitable for a register",
1416 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1417 error ("register specified for %q+D isn%'t suitable for data type",
1419 /* Now handle properly declared static register variables. */
1424 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1426 DECL_INITIAL (decl) = 0;
1427 error ("global register variable has initial value");
1429 if (TREE_THIS_VOLATILE (decl))
1430 warning (OPT_Wvolatile_register_var,
1431 "optimization may eliminate reads and/or "
1432 "writes to register variables");
1434 /* If the user specified one of the eliminables registers here,
1435 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1436 confused with that register and be eliminated. This usage is
1437 somewhat suspect... */
1439 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1440 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1441 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1443 if (TREE_STATIC (decl))
1445 /* Make this register global, so not usable for anything
1447 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1448 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1449 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1451 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1453 globalize_reg (reg_number + --nregs);
1456 /* As a register variable, it has no section. */
1460 /* Now handle ordinary static variables and functions (in memory).
1461 Also handle vars declared register invalidly. */
1462 else if (name[0] == '*')
1464 #ifdef REGISTER_PREFIX
1465 if (strlen (REGISTER_PREFIX) != 0)
1467 reg_number = decode_reg_name (name);
1468 if (reg_number >= 0 || reg_number == -3)
1469 error ("register name given for non-register variable %q+D", decl);
1474 /* Specifying a section attribute on a variable forces it into a
1475 non-.bss section, and thus it cannot be common. */
1476 /* FIXME: In general this code should not be necessary because
1477 visibility pass is doing the same work. But notice_global_symbol
1478 is called early and it needs to make DECL_RTL to get the name.
1479 we take care of recomputing the DECL_RTL after visibility is changed. */
1480 if (TREE_CODE (decl) == VAR_DECL
1481 && DECL_SECTION_NAME (decl) != NULL_TREE
1482 && DECL_INITIAL (decl) == NULL_TREE
1483 && DECL_COMMON (decl))
1484 DECL_COMMON (decl) = 0;
1486 /* Variables can't be both common and weak. */
1487 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1488 DECL_COMMON (decl) = 0;
1490 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1491 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1494 enum machine_mode address_mode = Pmode;
1495 if (TREE_TYPE (decl) != error_mark_node)
1497 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1498 address_mode = targetm.addr_space.address_mode (as);
1500 x = gen_rtx_SYMBOL_REF (address_mode, name);
1502 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1503 SET_SYMBOL_REF_DECL (x, decl);
1505 x = gen_rtx_MEM (DECL_MODE (decl), x);
1506 if (TREE_CODE (decl) != FUNCTION_DECL)
1507 set_mem_attributes (x, decl, 1);
1508 SET_DECL_RTL (decl, x);
1510 /* Optionally set flags or add text to the name to record information
1511 such as that it is a function name.
1512 If the name is changed, the macro ASM_OUTPUT_LABELREF
1513 will have to know how to strip this information. */
1514 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1516 /* Make this function static known to the mudflap runtime. */
1517 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1518 mudflap_enqueue_decl (decl);
1521 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1522 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1526 make_decl_rtl_for_debug (tree decl)
1528 unsigned int save_aliasing_flag, save_mudflap_flag;
1531 if (DECL_RTL_SET_P (decl))
1532 return DECL_RTL (decl);
1534 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1535 call new_alias_set. If running with -fcompare-debug, sometimes
1536 we do not want to create alias sets that will throw the alias
1537 numbers off in the comparison dumps. So... clearing
1538 flag_strict_aliasing will keep new_alias_set() from creating a
1539 new set. It is undesirable to register decl with mudflap
1540 in this case as well. */
1541 save_aliasing_flag = flag_strict_aliasing;
1542 flag_strict_aliasing = 0;
1543 save_mudflap_flag = flag_mudflap;
1546 rtl = DECL_RTL (decl);
1547 /* Reset DECL_RTL back, as various parts of the compiler expects
1548 DECL_RTL set meaning it is actually going to be output. */
1549 SET_DECL_RTL (decl, NULL);
1551 flag_strict_aliasing = save_aliasing_flag;
1552 flag_mudflap = save_mudflap_flag;
1557 /* Output a string of literal assembler code
1558 for an `asm' keyword used between functions. */
1561 assemble_asm (tree string)
1565 if (TREE_CODE (string) == ADDR_EXPR)
1566 string = TREE_OPERAND (string, 0);
1568 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1571 /* Record an element in the table of global destructors. SYMBOL is
1572 a SYMBOL_REF of the function to be called; PRIORITY is a number
1573 between 0 and MAX_INIT_PRIORITY. */
1576 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1577 int priority ATTRIBUTE_UNUSED)
1579 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1580 /* Tell GNU LD that this is part of the static destructor set.
1581 This will work for any system that uses stabs, most usefully
1583 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1584 dbxout_stab_value_label (XSTR (symbol, 0));
1586 sorry ("global destructors not supported on this target");
1590 /* Write the address of the entity given by SYMBOL to SEC. */
1592 assemble_addr_to_section (rtx symbol, section *sec)
1594 switch_to_section (sec);
1595 assemble_align (POINTER_SIZE);
1596 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1599 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1600 not) section for PRIORITY. */
1602 get_cdtor_priority_section (int priority, bool constructor_p)
1606 /* ??? This only works reliably with the GNU linker. */
1607 sprintf (buf, "%s.%.5u",
1608 constructor_p ? ".ctors" : ".dtors",
1609 /* Invert the numbering so the linker puts us in the proper
1610 order; constructors are run from right to left, and the
1611 linker sorts in increasing order. */
1612 MAX_INIT_PRIORITY - priority);
1613 return get_section (buf, SECTION_WRITE, NULL);
1617 default_named_section_asm_out_destructor (rtx symbol, int priority)
1621 if (priority != DEFAULT_INIT_PRIORITY)
1622 sec = get_cdtor_priority_section (priority,
1623 /*constructor_p=*/false);
1625 sec = get_section (".dtors", SECTION_WRITE, NULL);
1627 assemble_addr_to_section (symbol, sec);
1630 #ifdef DTORS_SECTION_ASM_OP
1632 default_dtor_section_asm_out_destructor (rtx symbol,
1633 int priority ATTRIBUTE_UNUSED)
1635 assemble_addr_to_section (symbol, dtors_section);
1639 /* Likewise for global constructors. */
1642 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1643 int priority ATTRIBUTE_UNUSED)
1645 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1646 /* Tell GNU LD that this is part of the static destructor set.
1647 This will work for any system that uses stabs, most usefully
1649 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1650 dbxout_stab_value_label (XSTR (symbol, 0));
1652 sorry ("global constructors not supported on this target");
1657 default_named_section_asm_out_constructor (rtx symbol, int priority)
1661 if (priority != DEFAULT_INIT_PRIORITY)
1662 sec = get_cdtor_priority_section (priority,
1663 /*constructor_p=*/true);
1665 sec = get_section (".ctors", SECTION_WRITE, NULL);
1667 assemble_addr_to_section (symbol, sec);
1670 #ifdef CTORS_SECTION_ASM_OP
1672 default_ctor_section_asm_out_constructor (rtx symbol,
1673 int priority ATTRIBUTE_UNUSED)
1675 assemble_addr_to_section (symbol, ctors_section);
1679 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1680 a nonzero value if the constant pool should be output before the
1681 start of the function, or a zero value if the pool should output
1682 after the end of the function. The default is to put it before the
1685 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1686 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1689 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1690 to be output to assembler.
1691 Set first_global_object_name and weak_global_object_name as appropriate. */
1694 notice_global_symbol (tree decl)
1696 const char **type = &first_global_object_name;
1698 if (first_global_object_name
1699 || !TREE_PUBLIC (decl)
1700 || DECL_EXTERNAL (decl)
1701 || !DECL_NAME (decl)
1702 || (TREE_CODE (decl) != FUNCTION_DECL
1703 && (TREE_CODE (decl) != VAR_DECL
1704 || (DECL_COMMON (decl)
1705 && (DECL_INITIAL (decl) == 0
1706 || DECL_INITIAL (decl) == error_mark_node))))
1707 || !MEM_P (DECL_RTL (decl)))
1710 /* We win when global object is found, but it is useful to know about weak
1711 symbol as well so we can produce nicer unique names. */
1712 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1713 type = &weak_global_object_name;
1719 rtx decl_rtl = DECL_RTL (decl);
1721 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1722 name = ggc_strdup (p);
1728 /* Output assembler code for the constant pool of a function and associated
1729 with defining the name of the function. DECL describes the function.
1730 NAME is the function's name. For the constant pool, we use the current
1731 constant pool data. */
1734 assemble_start_function (tree decl, const char *fnname)
1737 char tmp_label[100];
1738 bool hot_label_written = false;
1740 crtl->subsections.unlikely_text_section_name = NULL;
1742 first_function_block_is_cold = false;
1743 if (flag_reorder_blocks_and_partition)
1745 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1746 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1747 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1748 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1749 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1750 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1751 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1752 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1757 crtl->subsections.hot_section_label = NULL;
1758 crtl->subsections.cold_section_label = NULL;
1759 crtl->subsections.hot_section_end_label = NULL;
1760 crtl->subsections.cold_section_end_label = NULL;
1763 /* The following code does not need preprocessing in the assembler. */
1767 if (CONSTANT_POOL_BEFORE_FUNCTION)
1768 output_constant_pool (fnname, decl);
1770 resolve_unique_section (decl, 0, flag_function_sections);
1772 /* Make sure the not and cold text (code) sections are properly
1773 aligned. This is necessary here in the case where the function
1774 has both hot and cold sections, because we don't want to re-set
1775 the alignment when the section switch happens mid-function. */
1777 if (flag_reorder_blocks_and_partition)
1779 switch_to_section (unlikely_text_section ());
1780 assemble_align (DECL_ALIGN (decl));
1781 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1783 /* When the function starts with a cold section, we need to explicitly
1784 align the hot section and write out the hot section label.
1785 But if the current function is a thunk, we do not have a CFG. */
1787 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1789 switch_to_section (text_section);
1790 assemble_align (DECL_ALIGN (decl));
1791 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1792 hot_label_written = true;
1793 first_function_block_is_cold = true;
1796 else if (DECL_SECTION_NAME (decl))
1798 /* Calls to function_section rely on first_function_block_is_cold
1799 being accurate. The first block may be cold even if we aren't
1800 doing partitioning, if the entire function was decided by
1801 choose_function_section (predict.c) to be cold. */
1803 initialize_cold_section_name ();
1805 if (crtl->subsections.unlikely_text_section_name
1806 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1807 crtl->subsections.unlikely_text_section_name) == 0)
1808 first_function_block_is_cold = true;
1811 in_cold_section_p = first_function_block_is_cold;
1813 /* Switch to the correct text section for the start of the function. */
1815 switch_to_section (function_section (decl));
1816 if (flag_reorder_blocks_and_partition
1817 && !hot_label_written)
1818 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1820 /* Tell assembler to move to target machine's alignment for functions. */
1821 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1824 ASM_OUTPUT_ALIGN (asm_out_file, align);
1827 /* Handle a user-specified function alignment.
1828 Note that we still need to align to DECL_ALIGN, as above,
1829 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1830 if (! DECL_USER_ALIGN (decl)
1831 && align_functions_log > align
1832 && optimize_function_for_speed_p (cfun))
1834 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1835 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1836 align_functions_log, align_functions - 1);
1838 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1842 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1843 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1846 if (!DECL_IGNORED_P (decl))
1847 (*debug_hooks->begin_function) (decl);
1849 /* Make function name accessible from other files, if appropriate. */
1851 if (TREE_PUBLIC (decl))
1853 notice_global_symbol (decl);
1855 globalize_decl (decl);
1857 maybe_assemble_visibility (decl);
1860 if (DECL_PRESERVE_P (decl))
1861 targetm.asm_out.mark_decl_preserved (fnname);
1863 /* Do any machine/system dependent processing of the function name. */
1864 #ifdef ASM_DECLARE_FUNCTION_NAME
1865 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1867 /* Standard thing is just output label for the function. */
1868 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
1869 #endif /* ASM_DECLARE_FUNCTION_NAME */
1872 /* Output assembler code associated with defining the size of the
1873 function. DECL describes the function. NAME is the function's name. */
1876 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1878 #ifdef ASM_DECLARE_FUNCTION_SIZE
1879 /* We could have switched section in the middle of the function. */
1880 if (flag_reorder_blocks_and_partition)
1881 switch_to_section (function_section (decl));
1882 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1884 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1886 output_constant_pool (fnname, decl);
1887 switch_to_section (function_section (decl)); /* need to switch back */
1889 /* Output labels for end of hot/cold text sections (to be used by
1891 if (flag_reorder_blocks_and_partition)
1893 section *save_text_section;
1895 save_text_section = in_section;
1896 switch_to_section (unlikely_text_section ());
1897 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1898 if (first_function_block_is_cold)
1899 switch_to_section (text_section);
1901 switch_to_section (function_section (decl));
1902 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1903 switch_to_section (save_text_section);
1907 /* Assemble code to leave SIZE bytes of zeros. */
1910 assemble_zeros (unsigned HOST_WIDE_INT size)
1912 /* Do no output if -fsyntax-only. */
1913 if (flag_syntax_only)
1916 #ifdef ASM_NO_SKIP_IN_TEXT
1917 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1918 so we must output 0s explicitly in the text section. */
1919 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1921 unsigned HOST_WIDE_INT i;
1922 for (i = 0; i < size; i++)
1923 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1928 ASM_OUTPUT_SKIP (asm_out_file, size);
1931 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1934 assemble_align (int align)
1936 if (align > BITS_PER_UNIT)
1938 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1942 /* Assemble a string constant with the specified C string as contents. */
1945 assemble_string (const char *p, int size)
1950 /* If the string is very long, split it up. */
1954 int thissize = size - pos;
1955 if (thissize > maximum)
1958 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1966 /* A noswitch_section_callback for lcomm_section. */
1969 emit_local (tree decl ATTRIBUTE_UNUSED,
1970 const char *name ATTRIBUTE_UNUSED,
1971 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1972 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1974 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1975 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1976 size, DECL_ALIGN (decl));
1978 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1979 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1982 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1987 /* A noswitch_section_callback for bss_noswitch_section. */
1989 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1991 emit_bss (tree decl ATTRIBUTE_UNUSED,
1992 const char *name ATTRIBUTE_UNUSED,
1993 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1994 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1996 #if defined ASM_OUTPUT_ALIGNED_BSS
1997 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
2000 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
2006 /* A noswitch_section_callback for comm_section. */
2009 emit_common (tree decl ATTRIBUTE_UNUSED,
2010 const char *name ATTRIBUTE_UNUSED,
2011 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2012 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2014 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
2015 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
2016 size, DECL_ALIGN (decl));
2018 #elif defined ASM_OUTPUT_ALIGNED_COMMON
2019 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
2022 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
2027 /* A noswitch_section_callback for tls_comm_section. */
2030 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
2031 const char *name ATTRIBUTE_UNUSED,
2032 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2033 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2035 #ifdef ASM_OUTPUT_TLS_COMMON
2036 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
2039 sorry ("thread-local COMMON data not implemented");
2044 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2045 NAME is the name of DECL's SYMBOL_REF. */
2048 assemble_noswitch_variable (tree decl, const char *name, section *sect)
2050 unsigned HOST_WIDE_INT size, rounded;
2052 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
2055 /* Don't allocate zero bytes of common,
2056 since that means "undefined external" in the linker. */
2060 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2061 so that each uninitialized object starts on such a boundary. */
2062 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
2063 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2064 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2066 if (!sect->noswitch.callback (decl, name, size, rounded)
2067 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
2068 warning (0, "requested alignment for %q+D is greater than "
2069 "implemented alignment of %wu", decl, rounded);
2072 /* A subroutine of assemble_variable. Output the label and contents of
2073 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2074 is as for assemble_variable. */
2077 assemble_variable_contents (tree decl, const char *name,
2078 bool dont_output_data)
2080 /* Do any machine/system dependent processing of the object. */
2081 #ifdef ASM_DECLARE_OBJECT_NAME
2082 last_assemble_variable_decl = decl;
2083 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
2085 /* Standard thing is just output label for the object. */
2086 ASM_OUTPUT_LABEL (asm_out_file, name);
2087 #endif /* ASM_DECLARE_OBJECT_NAME */
2089 if (!dont_output_data)
2091 if (DECL_INITIAL (decl)
2092 && DECL_INITIAL (decl) != error_mark_node
2093 && !initializer_zerop (DECL_INITIAL (decl)))
2094 /* Output the actual data. */
2095 output_constant (DECL_INITIAL (decl),
2096 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
2099 /* Leave space for it. */
2100 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
2104 /* Initialize emulated tls object TO, which refers to TLS variable
2105 DECL and is initialized by PROXY. */
2108 default_emutls_var_init (tree to, tree decl, tree proxy)
2110 VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4);
2111 constructor_elt *elt;
2112 tree type = TREE_TYPE (to);
2113 tree field = TYPE_FIELDS (type);
2115 elt = VEC_quick_push (constructor_elt, v, NULL);
2117 elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
2119 elt = VEC_quick_push (constructor_elt, v, NULL);
2120 field = TREE_CHAIN (field);
2122 elt->value = build_int_cst (TREE_TYPE (field),
2123 DECL_ALIGN_UNIT (decl));
2125 elt = VEC_quick_push (constructor_elt, v, NULL);
2126 field = TREE_CHAIN (field);
2128 elt->value = null_pointer_node;
2130 elt = VEC_quick_push (constructor_elt, v, NULL);
2131 field = TREE_CHAIN (field);
2135 return build_constructor (type, v);
2138 /* Assemble everything that is needed for a variable or function declaration.
2139 Not used for automatic variables, and not used for function definitions.
2140 Should not be called for variables of incomplete structure type.
2142 TOP_LEVEL is nonzero if this variable has file scope.
2143 AT_END is nonzero if this is the special handling, at end of compilation,
2144 to define things that have had only tentative definitions.
2145 DONT_OUTPUT_DATA if nonzero means don't actually output the
2146 initial value (that will be done by the caller). */
2149 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2150 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2153 rtx decl_rtl, symbol;
2156 if (! targetm.have_tls
2157 && TREE_CODE (decl) == VAR_DECL
2158 && DECL_THREAD_LOCAL_P (decl))
2160 tree to = emutls_decl (decl);
2162 /* If this variable is defined locally, then we need to initialize the
2163 control structure with size and alignment information. We do this
2164 at the last moment because tentative definitions can take a locally
2165 defined but uninitialized variable and initialize it later, which
2166 would result in incorrect contents. */
2167 if (! DECL_EXTERNAL (to)
2168 && (! DECL_COMMON (to)
2169 || (DECL_INITIAL (decl)
2170 && DECL_INITIAL (decl) != error_mark_node)))
2172 DECL_INITIAL (to) = targetm.emutls.var_init
2173 (to, decl, get_emutls_init_templ_addr (decl));
2175 /* Make sure the template is marked as needed early enough.
2176 Without this, if the variable is placed in a
2177 section-anchored block, the template will only be marked
2178 when it's too late. */
2179 record_references_in_initializer (to, false);
2185 last_assemble_variable_decl = 0;
2187 /* Normally no need to say anything here for external references,
2188 since assemble_external is called by the language-specific code
2189 when a declaration is first seen. */
2191 if (DECL_EXTERNAL (decl))
2194 /* Output no assembler code for a function declaration.
2195 Only definitions of functions output anything. */
2197 if (TREE_CODE (decl) == FUNCTION_DECL)
2200 /* Do nothing for global register variables. */
2201 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2203 TREE_ASM_WRITTEN (decl) = 1;
2207 /* If type was incomplete when the variable was declared,
2208 see if it is complete now. */
2210 if (DECL_SIZE (decl) == 0)
2211 layout_decl (decl, 0);
2213 /* Still incomplete => don't allocate it; treat the tentative defn
2214 (which is what it must have been) as an `extern' reference. */
2216 if (!dont_output_data && DECL_SIZE (decl) == 0)
2218 error ("storage size of %q+D isn%'t known", decl);
2219 TREE_ASM_WRITTEN (decl) = 1;
2223 /* The first declaration of a variable that comes through this function
2224 decides whether it is global (in C, has external linkage)
2225 or local (in C, has internal linkage). So do nothing more
2226 if this function has already run. */
2228 if (TREE_ASM_WRITTEN (decl))
2231 /* Make sure targetm.encode_section_info is invoked before we set
2233 decl_rtl = DECL_RTL (decl);
2235 TREE_ASM_WRITTEN (decl) = 1;
2237 /* Do no output if -fsyntax-only. */
2238 if (flag_syntax_only)
2241 if (! dont_output_data
2242 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2244 error ("size of variable %q+D is too large", decl);
2248 gcc_assert (MEM_P (decl_rtl));
2249 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2250 symbol = XEXP (decl_rtl, 0);
2252 /* If this symbol belongs to the tree constant pool, output the constant
2253 if it hasn't already been written. */
2254 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2256 tree decl = SYMBOL_REF_DECL (symbol);
2257 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2258 output_constant_def_contents (symbol);
2264 name = XSTR (symbol, 0);
2265 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2266 notice_global_symbol (decl);
2268 /* Compute the alignment of this data. */
2270 align_variable (decl, dont_output_data);
2271 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2273 if (TREE_PUBLIC (decl))
2274 maybe_assemble_visibility (decl);
2276 if (DECL_PRESERVE_P (decl))
2277 targetm.asm_out.mark_decl_preserved (name);
2279 /* First make the assembler name(s) global if appropriate. */
2280 sect = get_variable_section (decl, false);
2281 if (TREE_PUBLIC (decl)
2282 && (sect->common.flags & SECTION_COMMON) == 0)
2283 globalize_decl (decl);
2285 /* Output any data that we will need to use the address of. */
2286 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2287 output_addressed_constants (DECL_INITIAL (decl));
2289 /* dbxout.c needs to know this. */
2290 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2291 DECL_IN_TEXT_SECTION (decl) = 1;
2293 /* If the decl is part of an object_block, make sure that the decl
2294 has been positioned within its block, but do not write out its
2295 definition yet. output_object_blocks will do that later. */
2296 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2298 gcc_assert (!dont_output_data);
2299 place_block_symbol (symbol);
2301 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2302 assemble_noswitch_variable (decl, name, sect);
2305 switch_to_section (sect);
2306 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2307 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2308 assemble_variable_contents (decl, name, dont_output_data);
2312 /* Return 1 if type TYPE contains any pointers. */
2315 contains_pointers_p (tree type)
2317 switch (TREE_CODE (type))
2320 case REFERENCE_TYPE:
2321 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2322 so I'll play safe and return 1. */
2328 case QUAL_UNION_TYPE:
2331 /* For a type that has fields, see if the fields have pointers. */
2332 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2333 if (TREE_CODE (fields) == FIELD_DECL
2334 && contains_pointers_p (TREE_TYPE (fields)))
2340 /* An array type contains pointers if its element type does. */
2341 return contains_pointers_p (TREE_TYPE (type));
2348 /* We delay assemble_external processing until
2349 the compilation unit is finalized. This is the best we can do for
2350 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2351 it all the way to final. See PR 17982 for further discussion. */
2352 static GTY(()) tree pending_assemble_externals;
2354 #ifdef ASM_OUTPUT_EXTERNAL
2355 /* True if DECL is a function decl for which no out-of-line copy exists.
2356 It is assumed that DECL's assembler name has been set. */
2359 incorporeal_function_p (tree decl)
2361 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2365 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2366 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2369 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2370 if (is_builtin_name (name))
2376 /* Actually do the tests to determine if this is necessary, and invoke
2377 ASM_OUTPUT_EXTERNAL. */
2379 assemble_external_real (tree decl)
2381 rtx rtl = DECL_RTL (decl);
2383 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2384 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2385 && !incorporeal_function_p (decl))
2387 /* Some systems do require some output. */
2388 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2389 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2395 process_pending_assemble_externals (void)
2397 #ifdef ASM_OUTPUT_EXTERNAL
2399 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2400 assemble_external_real (TREE_VALUE (list));
2402 pending_assemble_externals = 0;
2406 /* This TREE_LIST contains any weak symbol declarations waiting
2408 static GTY(()) tree weak_decls;
2410 /* Output something to declare an external symbol to the assembler,
2411 and qualifiers such as weakness. (Most assemblers don't need
2412 extern declaration, so we normally output nothing.) Do nothing if
2413 DECL is not external. */
2416 assemble_external (tree decl ATTRIBUTE_UNUSED)
2418 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2419 main body of this code is only rarely exercised. To provide some
2420 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2421 open. If it's not, we should not be calling this function. */
2422 gcc_assert (asm_out_file);
2424 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2427 /* We want to output annotation for weak and external symbols at
2428 very last to check if they are references or not. */
2432 /* TREE_STATIC is a weird and abused creature which is not
2433 generally the right test for whether an entity has been
2434 locally emitted, inlined or otherwise not-really-extern, but
2435 for declarations that can be weak, it happens to be
2437 && !TREE_STATIC (decl)
2438 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2439 && value_member (decl, weak_decls) == NULL_TREE)
2440 weak_decls = tree_cons (NULL, decl, weak_decls);
2442 #ifdef ASM_OUTPUT_EXTERNAL
2443 if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2444 pending_assemble_externals = tree_cons (NULL, decl,
2445 pending_assemble_externals);
2449 /* Similar, for calling a library function FUN. */
2452 assemble_external_libcall (rtx fun)
2454 /* Declare library function name external when first used, if nec. */
2455 if (! SYMBOL_REF_USED (fun))
2457 SYMBOL_REF_USED (fun) = 1;
2458 targetm.asm_out.external_libcall (fun);
2462 /* Assemble a label named NAME. */
2465 assemble_label (FILE *file, const char *name)
2467 ASM_OUTPUT_LABEL (file, name);
2470 /* Set the symbol_referenced flag for ID. */
2472 mark_referenced (tree id)
2474 TREE_SYMBOL_REFERENCED (id) = 1;
2477 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2479 mark_decl_referenced (tree decl)
2481 if (TREE_CODE (decl) == FUNCTION_DECL)
2483 /* Extern inline functions don't become needed when referenced.
2484 If we know a method will be emitted in other TU and no new
2485 functions can be marked reachable, just use the external
2487 struct cgraph_node *node = cgraph_node (decl);
2488 if (!DECL_EXTERNAL (decl)
2489 && (!node->local.vtable_method || !cgraph_global_info_ready
2490 || !node->local.finalized))
2491 cgraph_mark_needed_node (node);
2493 else if (TREE_CODE (decl) == VAR_DECL)
2495 struct varpool_node *node = varpool_node (decl);
2496 varpool_mark_needed_node (node);
2497 /* C++ frontend use mark_decl_references to force COMDAT variables
2498 to be output that might appear dead otherwise. */
2499 node->force_output = true;
2501 /* else do nothing - we can get various sorts of CST nodes here,
2502 which do not need to be marked. */
2506 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2507 until we find an identifier that is not itself a transparent alias.
2508 Modify the alias passed to it by reference (and all aliases on the
2509 way to the ultimate target), such that they do not have to be
2510 followed again, and return the ultimate target of the alias
2514 ultimate_transparent_alias_target (tree *alias)
2516 tree target = *alias;
2518 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2520 gcc_assert (TREE_CHAIN (target));
2521 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2522 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2523 && ! TREE_CHAIN (target));
2530 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2531 starts with a *, the rest of NAME is output verbatim. Otherwise
2532 NAME is transformed in a target-specific way (usually by the
2533 addition of an underscore). */
2536 assemble_name_raw (FILE *file, const char *name)
2539 fputs (&name[1], file);
2541 ASM_OUTPUT_LABELREF (file, name);
2544 /* Like assemble_name_raw, but should be used when NAME might refer to
2545 an entity that is also represented as a tree (like a function or
2546 variable). If NAME does refer to such an entity, that entity will
2547 be marked as referenced. */
2550 assemble_name (FILE *file, const char *name)
2552 const char *real_name;
2555 real_name = targetm.strip_name_encoding (name);
2557 id = maybe_get_identifier (real_name);
2562 mark_referenced (id);
2563 ultimate_transparent_alias_target (&id);
2565 name = IDENTIFIER_POINTER (id);
2566 gcc_assert (! TREE_CHAIN (id));
2569 assemble_name_raw (file, name);
2572 /* Allocate SIZE bytes writable static space with a gensym name
2573 and return an RTX to refer to its address. */
2576 assemble_static_space (unsigned HOST_WIDE_INT size)
2579 const char *namestring;
2582 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2584 namestring = ggc_strdup (name);
2586 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2587 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2589 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2590 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2593 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2594 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2597 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2598 so that each uninitialized object starts on such a boundary. */
2599 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2600 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2601 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2602 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2603 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2604 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2611 /* Assemble the static constant template for function entry trampolines.
2612 This is done at most once per compilation.
2613 Returns an RTX for the address of the template. */
2615 static GTY(()) rtx initial_trampoline;
2618 assemble_trampoline_template (void)
2625 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2627 if (initial_trampoline)
2628 return initial_trampoline;
2630 /* By default, put trampoline templates in read-only data section. */
2632 #ifdef TRAMPOLINE_SECTION
2633 switch_to_section (TRAMPOLINE_SECTION);
2635 switch_to_section (readonly_data_section);
2638 /* Write the assembler code to define one. */
2639 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2641 ASM_OUTPUT_ALIGN (asm_out_file, align);
2643 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2644 targetm.asm_out.trampoline_template (asm_out_file);
2646 /* Record the rtl to refer to it. */
2647 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2648 name = ggc_strdup (label);
2649 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2650 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2652 initial_trampoline = gen_const_mem (BLKmode, symbol);
2653 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2654 set_mem_size (initial_trampoline, GEN_INT (TRAMPOLINE_SIZE));
2656 return initial_trampoline;
2659 /* A and B are either alignments or offsets. Return the minimum alignment
2660 that may be assumed after adding the two together. */
2662 static inline unsigned
2663 min_align (unsigned int a, unsigned int b)
2665 return (a | b) & -(a | b);
2668 /* Return the assembler directive for creating a given kind of integer
2669 object. SIZE is the number of bytes in the object and ALIGNED_P
2670 indicates whether it is known to be aligned. Return NULL if the
2671 assembly dialect has no such directive.
2673 The returned string should be printed at the start of a new line and
2674 be followed immediately by the object's initial value. */
2677 integer_asm_op (int size, int aligned_p)
2679 struct asm_int_op *ops;
2682 ops = &targetm.asm_out.aligned_op;
2684 ops = &targetm.asm_out.unaligned_op;
2689 return targetm.asm_out.byte_op;
2703 /* Use directive OP to assemble an integer object X. Print OP at the
2704 start of the line, followed immediately by the value of X. */
2707 assemble_integer_with_op (const char *op, rtx x)
2709 fputs (op, asm_out_file);
2710 output_addr_const (asm_out_file, x);
2711 fputc ('\n', asm_out_file);
2714 /* The default implementation of the asm_out.integer target hook. */
2717 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2718 unsigned int size ATTRIBUTE_UNUSED,
2719 int aligned_p ATTRIBUTE_UNUSED)
2721 const char *op = integer_asm_op (size, aligned_p);
2722 /* Avoid GAS bugs for large values. Specifically negative values whose
2723 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2724 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2726 return op && (assemble_integer_with_op (op, x), true);
2729 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2730 the alignment of the integer in bits. Return 1 if we were able to output
2731 the constant, otherwise 0. We must be able to output the constant,
2732 if FORCE is nonzero. */
2735 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2739 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2741 /* See if the target hook can handle this kind of object. */
2742 if (targetm.asm_out.integer (x, size, aligned_p))
2745 /* If the object is a multi-byte one, try splitting it up. Split
2746 it into words it if is multi-word, otherwise split it into bytes. */
2749 enum machine_mode omode, imode;
2750 unsigned int subalign;
2751 unsigned int subsize, i;
2752 enum mode_class mclass;
2754 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2755 subalign = MIN (align, subsize * BITS_PER_UNIT);
2756 if (GET_CODE (x) == CONST_FIXED)
2757 mclass = GET_MODE_CLASS (GET_MODE (x));
2761 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2762 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2764 for (i = 0; i < size; i += subsize)
2766 rtx partial = simplify_subreg (omode, x, imode, i);
2767 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2773 /* If we've printed some of it, but not all of it, there's no going
2778 gcc_assert (!force);
2784 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2786 long data[4] = {0, 0, 0, 0};
2788 int bitsize, nelts, nunits, units_per;
2790 /* This is hairy. We have a quantity of known size. real_to_target
2791 will put it into an array of *host* longs, 32 bits per element
2792 (even if long is more than 32 bits). We need to determine the
2793 number of array elements that are occupied (nelts) and the number
2794 of *target* min-addressable units that will be occupied in the
2795 object file (nunits). We cannot assume that 32 divides the
2796 mode's bitsize (size * BITS_PER_UNIT) evenly.
2798 size * BITS_PER_UNIT is used here to make sure that padding bits
2799 (which might appear at either end of the value; real_to_target
2800 will include the padding bits in its output array) are included. */
2802 nunits = GET_MODE_SIZE (mode);
2803 bitsize = nunits * BITS_PER_UNIT;
2804 nelts = CEIL (bitsize, 32);
2805 units_per = 32 / BITS_PER_UNIT;
2807 real_to_target (data, &d, mode);
2809 /* Put out the first word with the specified alignment. */
2810 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2811 nunits -= units_per;
2813 /* Subsequent words need only 32-bit alignment. */
2814 align = min_align (align, 32);
2816 for (i = 1; i < nelts; i++)
2818 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2819 nunits -= units_per;
2823 /* Given an expression EXP with a constant value,
2824 reduce it to the sum of an assembler symbol and an integer.
2825 Store them both in the structure *VALUE.
2826 EXP must be reducible. */
2828 struct GTY(()) addr_const {
2830 HOST_WIDE_INT offset;
2834 decode_addr_const (tree exp, struct addr_const *value)
2836 tree target = TREE_OPERAND (exp, 0);
2842 if (TREE_CODE (target) == COMPONENT_REF
2843 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2845 offset += int_byte_position (TREE_OPERAND (target, 1));
2846 target = TREE_OPERAND (target, 0);
2848 else if (TREE_CODE (target) == ARRAY_REF
2849 || TREE_CODE (target) == ARRAY_RANGE_REF)
2851 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2852 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2853 target = TREE_OPERAND (target, 0);
2855 else if (TREE_CODE (target) == INDIRECT_REF
2856 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2857 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2859 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2864 switch (TREE_CODE (target))
2868 x = DECL_RTL (target);
2872 x = gen_rtx_MEM (FUNCTION_MODE,
2873 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2882 x = output_constant_def (target, 1);
2889 gcc_assert (MEM_P (x));
2893 value->offset = offset;
2897 static GTY((param_is (struct constant_descriptor_tree)))
2898 htab_t const_desc_htab;
2900 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2902 /* Constant pool accessor function. */
2905 constant_pool_htab (void)
2907 return const_desc_htab;
2910 /* Compute a hash code for a constant expression. */
2913 const_desc_hash (const void *ptr)
2915 return ((const struct constant_descriptor_tree *)ptr)->hash;
2919 const_hash_1 (const tree exp)
2924 enum tree_code code = TREE_CODE (exp);
2926 /* Either set P and LEN to the address and len of something to hash and
2927 exit the switch or return a value. */
2932 p = (char *) &TREE_INT_CST (exp);
2933 len = sizeof TREE_INT_CST (exp);
2937 return real_hash (TREE_REAL_CST_PTR (exp));
2940 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2943 p = TREE_STRING_POINTER (exp);
2944 len = TREE_STRING_LENGTH (exp);
2948 return (const_hash_1 (TREE_REALPART (exp)) * 5
2949 + const_hash_1 (TREE_IMAGPART (exp)));
2955 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2957 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2958 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2965 unsigned HOST_WIDE_INT idx;
2968 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2970 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2972 hi = hi * 603 + const_hash_1 (value);
2980 struct addr_const value;
2982 decode_addr_const (exp, &value);
2983 switch (GET_CODE (value.base))
2986 /* Don't hash the address of the SYMBOL_REF;
2987 only use the offset and the symbol name. */
2989 p = XSTR (value.base, 0);
2990 for (i = 0; p[i] != 0; i++)
2991 hi = ((hi * 613) + (unsigned) (p[i]));
2995 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
3005 case POINTER_PLUS_EXPR:
3007 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
3008 + const_hash_1 (TREE_OPERAND (exp, 1)));
3011 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
3014 /* A language specific constant. Just hash the code. */
3018 /* Compute hashing function. */
3020 for (i = 0; i < len; i++)
3021 hi = ((hi * 613) + (unsigned) (p[i]));
3026 /* Wrapper of compare_constant, for the htab interface. */
3028 const_desc_eq (const void *p1, const void *p2)
3030 const struct constant_descriptor_tree *const c1
3031 = (const struct constant_descriptor_tree *) p1;
3032 const struct constant_descriptor_tree *const c2
3033 = (const struct constant_descriptor_tree *) p2;
3034 if (c1->hash != c2->hash)
3036 return compare_constant (c1->value, c2->value);
3039 /* Compare t1 and t2, and return 1 only if they are known to result in
3040 the same bit pattern on output. */
3043 compare_constant (const tree t1, const tree t2)
3045 enum tree_code typecode;
3047 if (t1 == NULL_TREE)
3048 return t2 == NULL_TREE;
3049 if (t2 == NULL_TREE)
3052 if (TREE_CODE (t1) != TREE_CODE (t2))
3055 switch (TREE_CODE (t1))
3058 /* Integer constants are the same only if the same width of type. */
3059 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3061 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3063 return tree_int_cst_equal (t1, t2);
3066 /* Real constants are the same only if the same width of type. */
3067 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3070 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3073 /* Fixed constants are the same only if the same width of type. */
3074 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3077 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3080 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3083 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3084 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3085 TREE_STRING_LENGTH (t1)));
3088 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3089 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3095 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
3096 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
3099 link2 = TREE_VECTOR_CST_ELTS (t2);
3100 for (link1 = TREE_VECTOR_CST_ELTS (t1);
3102 link1 = TREE_CHAIN (link1))
3104 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
3106 link2 = TREE_CHAIN (link2);
3114 VEC(constructor_elt, gc) *v1, *v2;
3115 unsigned HOST_WIDE_INT idx;
3117 typecode = TREE_CODE (TREE_TYPE (t1));
3118 if (typecode != TREE_CODE (TREE_TYPE (t2)))
3121 if (typecode == ARRAY_TYPE)
3123 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3124 /* For arrays, check that the sizes all match. */
3125 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3127 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
3132 /* For record and union constructors, require exact type
3134 if (TREE_TYPE (t1) != TREE_TYPE (t2))
3138 v1 = CONSTRUCTOR_ELTS (t1);
3139 v2 = CONSTRUCTOR_ELTS (t2);
3140 if (VEC_length (constructor_elt, v1)
3141 != VEC_length (constructor_elt, v2))
3144 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
3146 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
3147 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
3149 /* Check that each value is the same... */
3150 if (!compare_constant (c1->value, c2->value))
3152 /* ... and that they apply to the same fields! */
3153 if (typecode == ARRAY_TYPE)
3155 if (!compare_constant (c1->index, c2->index))
3160 if (c1->index != c2->index)
3171 struct addr_const value1, value2;
3175 decode_addr_const (t1, &value1);
3176 decode_addr_const (t2, &value2);
3178 if (value1.offset != value2.offset)
3181 code = GET_CODE (value1.base);
3182 if (code != GET_CODE (value2.base))
3188 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3192 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
3193 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
3203 case POINTER_PLUS_EXPR:
3206 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3207 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3210 case VIEW_CONVERT_EXPR:
3211 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3220 /* Make a copy of the whole tree structure for a constant. This
3221 handles the same types of nodes that compare_constant handles. */
3224 copy_constant (tree exp)
3226 switch (TREE_CODE (exp))
3229 /* For ADDR_EXPR, we do not want to copy the decl whose address
3230 is requested. We do want to copy constants though. */
3231 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3232 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3233 copy_constant (TREE_OPERAND (exp, 0)));
3235 return copy_node (exp);
3241 return copy_node (exp);
3244 return build_complex (TREE_TYPE (exp),
3245 copy_constant (TREE_REALPART (exp)),
3246 copy_constant (TREE_IMAGPART (exp)));
3249 case POINTER_PLUS_EXPR:
3251 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3252 copy_constant (TREE_OPERAND (exp, 0)),
3253 copy_constant (TREE_OPERAND (exp, 1)));
3256 case VIEW_CONVERT_EXPR:
3257 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3258 copy_constant (TREE_OPERAND (exp, 0)));
3261 return build_vector (TREE_TYPE (exp),
3262 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3266 tree copy = copy_node (exp);
3267 VEC(constructor_elt, gc) *v;
3268 unsigned HOST_WIDE_INT idx;
3269 tree purpose, value;
3271 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3272 CONSTRUCTOR_ELTS (exp)));
3273 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3275 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3276 ce->index = purpose;
3277 ce->value = copy_constant (value);
3279 CONSTRUCTOR_ELTS (copy) = v;
3288 /* Return the section into which constant EXP should be placed. */
3291 get_constant_section (tree exp, unsigned int align)
3293 return targetm.asm_out.select_section (exp,
3294 compute_reloc_for_constant (exp),
3298 /* Return the size of constant EXP in bytes. */
3300 static HOST_WIDE_INT
3301 get_constant_size (tree exp)
3305 size = int_size_in_bytes (TREE_TYPE (exp));
3306 if (TREE_CODE (exp) == STRING_CST)
3307 size = MAX (TREE_STRING_LENGTH (exp), size);
3311 /* Subroutine of output_constant_def:
3312 No constant equal to EXP is known to have been output.
3313 Make a constant descriptor to enter EXP in the hash table.
3314 Assign the label number and construct RTL to refer to the
3315 constant's location in memory.
3316 Caller is responsible for updating the hash table. */
3318 static struct constant_descriptor_tree *
3319 build_constant_desc (tree exp)
3321 struct constant_descriptor_tree *desc;
3327 desc = ggc_alloc_constant_descriptor_tree ();
3328 desc->value = copy_constant (exp);
3330 /* Propagate marked-ness to copied constant. */
3331 if (flag_mudflap && mf_marked_p (exp))
3332 mf_mark (desc->value);
3334 /* Create a string containing the label name, in LABEL. */
3335 labelno = const_labelno++;
3336 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3338 /* Construct the VAR_DECL associated with the constant. */
3339 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3341 DECL_ARTIFICIAL (decl) = 1;
3342 DECL_IGNORED_P (decl) = 1;
3343 TREE_READONLY (decl) = 1;
3344 TREE_STATIC (decl) = 1;
3345 TREE_ADDRESSABLE (decl) = 1;
3346 /* We don't set the RTL yet as this would cause varpool to assume that the
3347 variable is referenced. Moreover, it would just be dropped in LTO mode.
3348 Instead we set the flag that will be recognized in make_decl_rtl. */
3349 DECL_IN_CONSTANT_POOL (decl) = 1;
3350 DECL_INITIAL (decl) = desc->value;
3351 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3352 architectures so use DATA_ALIGNMENT as well, except for strings. */
3353 if (TREE_CODE (exp) == STRING_CST)
3355 #ifdef CONSTANT_ALIGNMENT
3356 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3360 align_variable (decl, 0);
3362 /* Now construct the SYMBOL_REF and the MEM. */
3363 if (use_object_blocks_p ())
3365 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3366 symbol = create_block_symbol (ggc_strdup (label),
3367 get_block_for_section (sect), -1);
3370 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3371 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3372 SET_SYMBOL_REF_DECL (symbol, decl);
3373 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3375 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3376 set_mem_attributes (rtl, exp, 1);
3377 set_mem_alias_set (rtl, 0);
3378 set_mem_alias_set (rtl, const_alias_set);
3380 /* We cannot share RTX'es in pool entries.
3381 Mark this piece of RTL as required for unsharing. */
3382 RTX_FLAG (rtl, used) = 1;
3384 /* Set flags or add text to the name to record information, such as
3385 that it is a local symbol. If the name is changed, the macro
3386 ASM_OUTPUT_LABELREF will have to know how to strip this
3387 information. This call might invalidate our local variable
3388 SYMBOL; we can't use it afterward. */
3389 targetm.encode_section_info (exp, rtl, true);
3396 /* Return an rtx representing a reference to constant data in memory
3397 for the constant expression EXP.
3399 If assembler code for such a constant has already been output,
3400 return an rtx to refer to it.
3401 Otherwise, output such a constant in memory
3402 and generate an rtx for it.
3404 If DEFER is nonzero, this constant can be deferred and output only
3405 if referenced in the function after all optimizations.
3407 `const_desc_table' records which constants already have label strings. */
3410 output_constant_def (tree exp, int defer)
3412 struct constant_descriptor_tree *desc;
3413 struct constant_descriptor_tree key;
3416 /* Look up EXP in the table of constant descriptors. If we didn't find
3417 it, create a new one. */
3419 key.hash = const_hash_1 (exp);
3420 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3422 desc = (struct constant_descriptor_tree *) *loc;
3425 desc = build_constant_desc (exp);
3426 desc->hash = key.hash;
3430 maybe_output_constant_def_contents (desc, defer);
3434 /* Subroutine of output_constant_def: Decide whether or not we need to
3435 output the constant DESC now, and if so, do it. */
3437 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3440 rtx symbol = XEXP (desc->rtl, 0);
3441 tree exp = desc->value;
3443 if (flag_syntax_only)
3446 if (TREE_ASM_WRITTEN (exp))
3447 /* Already output; don't do it again. */
3450 /* We can always defer constants as long as the context allows
3454 /* Increment n_deferred_constants if it exists. It needs to be at
3455 least as large as the number of constants actually referred to
3456 by the function. If it's too small we'll stop looking too early
3457 and fail to emit constants; if it's too large we'll only look
3458 through the entire function when we could have stopped earlier. */
3460 n_deferred_constants++;
3464 output_constant_def_contents (symbol);
3467 /* Subroutine of output_constant_def_contents. Output the definition
3468 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3469 constant's alignment in bits. */
3472 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3476 size = get_constant_size (exp);
3478 /* Do any machine/system dependent processing of the constant. */
3479 targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3481 /* Output the value of EXP. */
3482 output_constant (exp, size, align);
3485 /* We must output the constant data referred to by SYMBOL; do so. */
3488 output_constant_def_contents (rtx symbol)
3490 tree decl = SYMBOL_REF_DECL (symbol);
3491 tree exp = DECL_INITIAL (decl);
3494 /* Make sure any other constants whose addresses appear in EXP
3495 are assigned label numbers. */
3496 output_addressed_constants (exp);
3498 /* We are no longer deferring this constant. */
3499 TREE_ASM_WRITTEN (exp) = 1;
3501 /* If the constant is part of an object block, make sure that the
3502 decl has been positioned within its block, but do not write out
3503 its definition yet. output_object_blocks will do that later. */
3504 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3505 place_block_symbol (symbol);
3508 align = DECL_ALIGN (decl);
3509 switch_to_section (get_constant_section (exp, align));
3510 if (align > BITS_PER_UNIT)
3511 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3512 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3515 mudflap_enqueue_constant (exp);
3518 /* Look up EXP in the table of constant descriptors. Return the rtl
3519 if it has been emitted, else null. */
3522 lookup_constant_def (tree exp)
3524 struct constant_descriptor_tree *desc;
3525 struct constant_descriptor_tree key;
3528 key.hash = const_hash_1 (exp);
3529 desc = (struct constant_descriptor_tree *)
3530 htab_find_with_hash (const_desc_htab, &key, key.hash);
3532 return (desc ? desc->rtl : NULL_RTX);
3535 /* Return a tree representing a reference to constant data in memory
3536 for the constant expression EXP.
3538 This is the counterpart of output_constant_def at the Tree level. */
3541 tree_output_constant_def (tree exp)
3543 struct constant_descriptor_tree *desc, key;
3547 /* Look up EXP in the table of constant descriptors. If we didn't find
3548 it, create a new one. */
3550 key.hash = const_hash_1 (exp);
3551 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3553 desc = (struct constant_descriptor_tree *) *loc;
3556 desc = build_constant_desc (exp);
3557 desc->hash = key.hash;
3561 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3562 varpool_finalize_decl (decl);
3566 /* Used in the hash tables to avoid outputting the same constant
3567 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3568 are output once per function, not once per file. */
3569 /* ??? Only a few targets need per-function constant pools. Most
3570 can use one per-file pool. Should add a targetm bit to tell the
3573 struct GTY(()) rtx_constant_pool {
3574 /* Pointers to first and last constant in pool, as ordered by offset. */
3575 struct constant_descriptor_rtx *first;
3576 struct constant_descriptor_rtx *last;
3578 /* Hash facility for making memory-constants from constant rtl-expressions.
3579 It is used on RISC machines where immediate integer arguments and
3580 constant addresses are restricted so that such constants must be stored
3582 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3584 /* Current offset in constant pool (does not include any
3585 machine-specific header). */
3586 HOST_WIDE_INT offset;
3589 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3590 struct constant_descriptor_rtx *next;
3594 HOST_WIDE_INT offset;
3596 enum machine_mode mode;
3602 /* Hash and compare functions for const_rtx_htab. */
3605 const_desc_rtx_hash (const void *ptr)
3607 const struct constant_descriptor_rtx *const desc
3608 = (const struct constant_descriptor_rtx *) ptr;
3613 const_desc_rtx_eq (const void *a, const void *b)
3615 const struct constant_descriptor_rtx *const x
3616 = (const struct constant_descriptor_rtx *) a;
3617 const struct constant_descriptor_rtx *const y
3618 = (const struct constant_descriptor_rtx *) b;
3620 if (x->mode != y->mode)
3622 return rtx_equal_p (x->constant, y->constant);
3625 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3628 const_rtx_hash_1 (rtx *xp, void *data)
3630 unsigned HOST_WIDE_INT hwi;
3631 enum machine_mode mode;
3637 code = GET_CODE (x);
3638 mode = GET_MODE (x);
3639 h = (hashval_t) code * 1048573 + mode;
3647 int shift = sizeof (hashval_t) * CHAR_BIT;
3648 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3651 h ^= (hashval_t) hwi;
3652 for (i = 1; i < n; ++i)
3655 h ^= (hashval_t) hwi;
3661 if (mode == VOIDmode)
3663 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3667 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3671 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3677 for (i = XVECLEN (x, 0); i-- > 0; )
3678 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3683 h ^= htab_hash_string (XSTR (x, 0));
3687 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3691 case UNSPEC_VOLATILE:
3692 h = h * 251 + XINT (x, 1);
3699 hp = (hashval_t *) data;
3700 *hp = *hp * 509 + h;
3704 /* Compute a hash value for X, which should be a constant. */
3707 const_rtx_hash (rtx x)
3710 for_each_rtx (&x, const_rtx_hash_1, &h);
3715 /* Create and return a new rtx constant pool. */
3717 static struct rtx_constant_pool *
3718 create_constant_pool (void)
3720 struct rtx_constant_pool *pool;
3722 pool = ggc_alloc_rtx_constant_pool ();
3723 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3724 const_desc_rtx_eq, NULL);
3731 /* Initialize constant pool hashing for a new function. */
3734 init_varasm_status (void)
3736 crtl->varasm.pool = create_constant_pool ();
3737 crtl->varasm.deferred_constants = 0;
3740 /* Given a MINUS expression, simplify it if both sides
3741 include the same symbol. */
3744 simplify_subtraction (rtx x)
3746 rtx r = simplify_rtx (x);
3750 /* Given a constant rtx X, make (or find) a memory constant for its value
3751 and return a MEM rtx to refer to it in memory. */
3754 force_const_mem (enum machine_mode mode, rtx x)
3756 struct constant_descriptor_rtx *desc, tmp;
3757 struct rtx_constant_pool *pool;
3764 /* If we're not allowed to drop X into the constant pool, don't. */
3765 if (targetm.cannot_force_const_mem (x))
3768 /* Record that this function has used a constant pool entry. */
3769 crtl->uses_const_pool = 1;
3771 /* Decide which pool to use. */
3772 pool = (targetm.use_blocks_for_constant_p (mode, x)
3773 ? shared_constant_pool
3774 : crtl->varasm.pool);
3776 /* Lookup the value in the hashtable. */
3779 hash = const_rtx_hash (x);
3780 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3781 desc = (struct constant_descriptor_rtx *) *slot;
3783 /* If the constant was already present, return its memory. */
3785 return copy_rtx (desc->mem);
3787 /* Otherwise, create a new descriptor. */
3788 desc = ggc_alloc_constant_descriptor_rtx ();
3791 /* Align the location counter as required by EXP's data type. */
3792 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3793 #ifdef CONSTANT_ALIGNMENT
3795 tree type = lang_hooks.types.type_for_mode (mode, 0);
3796 if (type != NULL_TREE)
3797 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3801 pool->offset += (align / BITS_PER_UNIT) - 1;
3802 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3805 desc->constant = tmp.constant;
3806 desc->offset = pool->offset;
3809 desc->align = align;
3810 desc->labelno = const_labelno;
3813 pool->offset += GET_MODE_SIZE (mode);
3815 pool->last->next = desc;
3817 pool->first = pool->last = desc;
3820 /* Create a string containing the label name, in LABEL. */
3821 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3824 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3825 the constants pool. */
3826 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3828 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3829 symbol = create_block_symbol (ggc_strdup (label),
3830 get_block_for_section (sect), -1);
3833 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3835 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3836 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3837 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3839 /* Construct the MEM. */
3840 desc->mem = def = gen_const_mem (mode, symbol);
3841 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3842 set_mem_align (def, align);
3844 /* If we're dropping a label to the constant pool, make sure we
3846 if (GET_CODE (x) == LABEL_REF)
3847 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3849 return copy_rtx (def);
3852 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3855 get_pool_constant (rtx addr)
3857 return SYMBOL_REF_CONSTANT (addr)->constant;
3860 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3861 and whether it has been output or not. */
3864 get_pool_constant_mark (rtx addr, bool *pmarked)
3866 struct constant_descriptor_rtx *desc;
3868 desc = SYMBOL_REF_CONSTANT (addr);
3869 *pmarked = (desc->mark != 0);
3870 return desc->constant;
3873 /* Similar, return the mode. */
3876 get_pool_mode (const_rtx addr)
3878 return SYMBOL_REF_CONSTANT (addr)->mode;
3881 /* Return the size of the constant pool. */
3884 get_pool_size (void)
3886 return crtl->varasm.pool->offset;
3889 /* Worker function for output_constant_pool_1. Emit assembly for X
3890 in MODE with known alignment ALIGN. */
3893 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3895 switch (GET_MODE_CLASS (mode))
3898 case MODE_DECIMAL_FLOAT:
3902 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3903 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3904 assemble_real (r, mode, align);
3909 case MODE_PARTIAL_INT:
3914 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3917 case MODE_VECTOR_FLOAT:
3918 case MODE_VECTOR_INT:
3919 case MODE_VECTOR_FRACT:
3920 case MODE_VECTOR_UFRACT:
3921 case MODE_VECTOR_ACCUM:
3922 case MODE_VECTOR_UACCUM:
3925 enum machine_mode submode = GET_MODE_INNER (mode);
3926 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3928 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3929 units = CONST_VECTOR_NUNITS (x);
3931 for (i = 0; i < units; i++)
3933 rtx elt = CONST_VECTOR_ELT (x, i);
3934 output_constant_pool_2 (submode, elt, i ? subalign : align);
3944 /* Worker function for output_constant_pool. Emit constant DESC,
3945 giving it ALIGN bits of alignment. */
3948 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3955 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3956 whose CODE_LABEL has been deleted. This can occur if a jump table
3957 is eliminated by optimization. If so, write a constant of zero
3958 instead. Note that this can also happen by turning the
3959 CODE_LABEL into a NOTE. */
3960 /* ??? This seems completely and utterly wrong. Certainly it's
3961 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3962 functioning even with INSN_DELETED_P and friends. */
3965 switch (GET_CODE (tmp))
3968 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3969 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3971 tmp = XEXP (XEXP (tmp, 0), 0);
3975 tmp = XEXP (tmp, 0);
3976 gcc_assert (!INSN_DELETED_P (tmp));
3977 gcc_assert (!NOTE_P (tmp)
3978 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3985 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3986 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3987 align, desc->labelno, done);
3990 assemble_align (align);
3992 /* Output the label. */
3993 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3995 /* Output the data. */
3996 output_constant_pool_2 (desc->mode, x, align);
3998 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3999 sections have proper size. */
4000 if (align > GET_MODE_BITSIZE (desc->mode)
4002 && (in_section->common.flags & SECTION_MERGE))
4003 assemble_align (align);
4005 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4011 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4012 to as used. Emit referenced deferred strings. This function can
4013 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4016 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
4018 rtx x = *current_rtx;
4020 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
4023 if (CONSTANT_POOL_ADDRESS_P (x))
4025 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
4026 if (desc->mark == 0)
4029 for_each_rtx (&desc->constant, mark_constant, NULL);
4032 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
4034 tree decl = SYMBOL_REF_DECL (x);
4035 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
4037 n_deferred_constants--;
4038 output_constant_def_contents (x);
4045 /* Look through appropriate parts of INSN, marking all entries in the
4046 constant pool which are actually being used. Entries that are only
4047 referenced by other constants are also marked as used. Emit
4048 deferred strings that are used. */
4051 mark_constants (rtx insn)
4056 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4057 insns, not any notes that may be attached. We don't want to mark
4058 a constant just because it happens to appear in a REG_EQUIV note. */
4059 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
4061 rtx seq = PATTERN (insn);
4062 int i, n = XVECLEN (seq, 0);
4063 for (i = 0; i < n; ++i)
4065 rtx subinsn = XVECEXP (seq, 0, i);
4066 if (INSN_P (subinsn))
4067 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
4071 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
4074 /* Look through the instructions for this function, and mark all the
4075 entries in POOL which are actually being used. Emit deferred constants
4076 which have indeed been used. */
4079 mark_constant_pool (void)
4083 if (!crtl->uses_const_pool && n_deferred_constants == 0)
4086 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4087 mark_constants (insn);
4089 for (link = crtl->epilogue_delay_list;
4091 link = XEXP (link, 1))
4092 mark_constants (XEXP (link, 0));
4095 /* Write all the constants in POOL. */
4098 output_constant_pool_contents (struct rtx_constant_pool *pool)
4100 struct constant_descriptor_rtx *desc;
4102 for (desc = pool->first; desc ; desc = desc->next)
4105 /* If the constant is part of an object_block, make sure that
4106 the constant has been positioned within its block, but do not
4107 write out its definition yet. output_object_blocks will do
4109 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4110 && SYMBOL_REF_BLOCK (desc->sym))
4111 place_block_symbol (desc->sym);
4114 switch_to_section (targetm.asm_out.select_rtx_section
4115 (desc->mode, desc->constant, desc->align));
4116 output_constant_pool_1 (desc, desc->align);
4121 /* Mark all constants that are used in the current function, then write
4122 out the function's private constant pool. */
4125 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
4126 tree fndecl ATTRIBUTE_UNUSED)
4128 struct rtx_constant_pool *pool = crtl->varasm.pool;
4130 /* It is possible for gcc to call force_const_mem and then to later
4131 discard the instructions which refer to the constant. In such a
4132 case we do not need to output the constant. */
4133 mark_constant_pool ();
4135 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4136 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
4139 output_constant_pool_contents (pool);
4141 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4142 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
4146 /* Write the contents of the shared constant pool. */
4149 output_shared_constant_pool (void)
4151 output_constant_pool_contents (shared_constant_pool);
4154 /* Determine what kind of relocations EXP may need. */
4157 compute_reloc_for_constant (tree exp)
4159 int reloc = 0, reloc2;
4162 switch (TREE_CODE (exp))
4166 /* Go inside any operations that get_inner_reference can handle and see
4167 if what's inside is a constant: no need to do anything here for
4168 addresses of variables or functions. */
4169 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4170 tem = TREE_OPERAND (tem, 0))
4173 if (TREE_PUBLIC (tem))
4180 case POINTER_PLUS_EXPR:
4181 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4182 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4186 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4187 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4188 /* The difference of two local labels is computable at link time. */
4189 if (reloc == 1 && reloc2 == 1)
4196 case VIEW_CONVERT_EXPR:
4197 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4202 unsigned HOST_WIDE_INT idx;
4203 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4205 reloc |= compute_reloc_for_constant (tem);
4215 /* Find all the constants whose addresses are referenced inside of EXP,
4216 and make sure assembler code with a label has been output for each one.
4217 Indicate whether an ADDR_EXPR has been encountered. */
4220 output_addressed_constants (tree exp)
4224 switch (TREE_CODE (exp))
4228 /* Go inside any operations that get_inner_reference can handle and see
4229 if what's inside is a constant: no need to do anything here for
4230 addresses of variables or functions. */
4231 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4232 tem = TREE_OPERAND (tem, 0))
4235 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4236 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4237 tem = DECL_INITIAL (tem);
4239 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4240 output_constant_def (tem, 0);
4244 case POINTER_PLUS_EXPR:
4246 output_addressed_constants (TREE_OPERAND (exp, 1));
4250 case VIEW_CONVERT_EXPR:
4251 output_addressed_constants (TREE_OPERAND (exp, 0));
4256 unsigned HOST_WIDE_INT idx;
4257 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4259 output_addressed_constants (tem);
4268 /* Whether a constructor CTOR is a valid static constant initializer if all
4269 its elements are. This used to be internal to initializer_constant_valid_p
4270 and has been exposed to let other functions like categorize_ctor_elements
4271 evaluate the property while walking a constructor for other purposes. */
4274 constructor_static_from_elts_p (const_tree ctor)
4276 return (TREE_CONSTANT (ctor)
4277 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4278 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4279 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4282 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4285 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4286 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4287 which are valid when ENDTYPE is an integer of any size; in
4288 particular, this does not accept a pointer minus a constant. This
4289 returns null_pointer_node if the VALUE is an absolute constant
4290 which can be used to initialize a static variable. Otherwise it
4294 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4298 if (!INTEGRAL_TYPE_P (endtype))
4301 op0 = TREE_OPERAND (value, 0);
4302 op1 = TREE_OPERAND (value, 1);
4304 /* Like STRIP_NOPS except allow the operand mode to widen. This
4305 works around a feature of fold that simplifies (int)(p1 - p2) to
4306 ((int)p1 - (int)p2) under the theory that the narrower operation
4309 while (CONVERT_EXPR_P (op0)
4310 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4312 tree inner = TREE_OPERAND (op0, 0);
4313 if (inner == error_mark_node
4314 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4315 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4316 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4321 while (CONVERT_EXPR_P (op1)
4322 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4324 tree inner = TREE_OPERAND (op1, 0);
4325 if (inner == error_mark_node
4326 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4327 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4328 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4333 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4337 op1 = initializer_constant_valid_p_1 (op1, endtype,
4338 cache ? cache + 2 : NULL);
4339 /* Both initializers must be known. */
4343 && (op0 == null_pointer_node
4344 || TREE_CODE (value) == MINUS_EXPR))
4345 return null_pointer_node;
4347 /* Support differences between labels. */
4348 if (TREE_CODE (op0) == LABEL_DECL
4349 && TREE_CODE (op1) == LABEL_DECL)
4350 return null_pointer_node;
4352 if (TREE_CODE (op0) == STRING_CST
4353 && TREE_CODE (op1) == STRING_CST
4354 && operand_equal_p (op0, op1, 1))
4355 return null_pointer_node;
4361 /* Helper function of initializer_constant_valid_p.
4362 Return nonzero if VALUE is a valid constant-valued expression
4363 for use in initializing a static variable; one that can be an
4364 element of a "constant" initializer.
4366 Return null_pointer_node if the value is absolute;
4367 if it is relocatable, return the variable that determines the relocation.
4368 We assume that VALUE has been folded as much as possible;
4369 therefore, we do not need to check for such things as
4370 arithmetic-combinations of integers.
4372 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4375 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4379 switch (TREE_CODE (value))
4382 if (constructor_static_from_elts_p (value))
4384 unsigned HOST_WIDE_INT idx;
4386 bool absolute = true;
4388 if (cache && cache[0] == value)
4390 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4393 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4400 cache[1] = NULL_TREE;
4404 if (reloc != null_pointer_node)
4407 /* For a non-absolute relocation, there is no single
4408 variable that can be "the variable that determines the
4413 cache[1] = absolute ? null_pointer_node : error_mark_node;
4415 return absolute ? null_pointer_node : error_mark_node;
4418 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4426 return null_pointer_node;
4431 tree op0 = staticp (TREE_OPERAND (value, 0));
4434 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4435 to be a constant, this is old-skool offsetof-like nonsense. */
4436 if (TREE_CODE (op0) == INDIRECT_REF
4437 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4438 return null_pointer_node;
4439 /* Taking the address of a nested function involves a trampoline,
4440 unless we don't need or want one. */
4441 if (TREE_CODE (op0) == FUNCTION_DECL
4442 && DECL_STATIC_CHAIN (op0)
4443 && !TREE_NO_TRAMPOLINE (value))
4445 /* "&{...}" requires a temporary to hold the constructed
4447 if (TREE_CODE (op0) == CONSTRUCTOR)
4453 case NON_LVALUE_EXPR:
4454 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4457 case VIEW_CONVERT_EXPR:
4459 tree src = TREE_OPERAND (value, 0);
4460 tree src_type = TREE_TYPE (src);
4461 tree dest_type = TREE_TYPE (value);
4463 /* Allow view-conversions from aggregate to non-aggregate type only
4464 if the bit pattern is fully preserved afterwards; otherwise, the
4465 RTL expander won't be able to apply a subsequent transformation
4466 to the underlying constructor. */
4467 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4469 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4470 return initializer_constant_valid_p_1 (src, endtype, cache);
4475 /* Allow all other kinds of view-conversion. */
4476 return initializer_constant_valid_p_1 (src, endtype, cache);
4481 tree src = TREE_OPERAND (value, 0);
4482 tree src_type = TREE_TYPE (src);
4483 tree dest_type = TREE_TYPE (value);
4485 /* Allow conversions between pointer types, floating-point
4486 types, and offset types. */
4487 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4488 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4489 || (TREE_CODE (dest_type) == OFFSET_TYPE
4490 && TREE_CODE (src_type) == OFFSET_TYPE))
4491 return initializer_constant_valid_p_1 (src, endtype, cache);
4493 /* Allow length-preserving conversions between integer types. */
4494 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4495 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4496 return initializer_constant_valid_p_1 (src, endtype, cache);
4498 /* Allow conversions between other integer types only if
4500 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4502 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4503 if (inner == null_pointer_node)
4504 return null_pointer_node;
4508 /* Allow (int) &foo provided int is as wide as a pointer. */
4509 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4510 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4511 return initializer_constant_valid_p_1 (src, endtype, cache);
4513 /* Likewise conversions from int to pointers, but also allow
4514 conversions from 0. */
4515 if ((POINTER_TYPE_P (dest_type)
4516 || TREE_CODE (dest_type) == OFFSET_TYPE)
4517 && INTEGRAL_TYPE_P (src_type))
4519 if (TREE_CODE (src) == INTEGER_CST
4520 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4521 return null_pointer_node;
4522 if (integer_zerop (src))
4523 return null_pointer_node;
4524 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4525 return initializer_constant_valid_p_1 (src, endtype, cache);
4528 /* Allow conversions to struct or union types if the value
4530 if (TREE_CODE (dest_type) == RECORD_TYPE
4531 || TREE_CODE (dest_type) == UNION_TYPE)
4532 return initializer_constant_valid_p_1 (src, endtype, cache);
4536 case POINTER_PLUS_EXPR:
4538 /* Any valid floating-point constants will have been folded by now;
4539 with -frounding-math we hit this with addition of two constants. */
4540 if (TREE_CODE (endtype) == REAL_TYPE)
4542 if (cache && cache[0] == value)
4544 if (! INTEGRAL_TYPE_P (endtype)
4545 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4547 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4549 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4552 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4553 endtype, ncache + 2);
4554 /* If either term is absolute, use the other term's relocation. */
4555 if (valid0 == null_pointer_node)
4557 else if (valid1 == null_pointer_node)
4559 /* Support narrowing pointer differences. */
4561 ret = narrowing_initializer_constant_valid_p (value, endtype,
4565 /* Support narrowing pointer differences. */
4566 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4575 if (TREE_CODE (endtype) == REAL_TYPE)
4577 if (cache && cache[0] == value)
4579 if (! INTEGRAL_TYPE_P (endtype)
4580 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4582 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4584 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4587 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4588 endtype, ncache + 2);
4589 /* Win if second argument is absolute. */
4590 if (valid1 == null_pointer_node)
4592 /* Win if both arguments have the same relocation.
4593 Then the value is absolute. */
4594 else if (valid0 == valid1 && valid0 != 0)
4595 ret = null_pointer_node;
4596 /* Since GCC guarantees that string constants are unique in the
4597 generated code, a subtraction between two copies of the same
4598 constant string is absolute. */
4599 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4600 && valid1 && TREE_CODE (valid1) == STRING_CST
4601 && operand_equal_p (valid0, valid1, 1))
4602 ret = null_pointer_node;
4603 /* Support narrowing differences. */
4605 ret = narrowing_initializer_constant_valid_p (value, endtype,
4609 /* Support narrowing differences. */
4610 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4625 /* Return nonzero if VALUE is a valid constant-valued expression
4626 for use in initializing a static variable; one that can be an
4627 element of a "constant" initializer.
4629 Return null_pointer_node if the value is absolute;
4630 if it is relocatable, return the variable that determines the relocation.
4631 We assume that VALUE has been folded as much as possible;
4632 therefore, we do not need to check for such things as
4633 arithmetic-combinations of integers. */
4635 initializer_constant_valid_p (tree value, tree endtype)
4637 return initializer_constant_valid_p_1 (value, endtype, NULL);
4640 /* Return true if VALUE is a valid constant-valued expression
4641 for use in initializing a static bit-field; one that can be
4642 an element of a "constant" initializer. */
4645 initializer_constant_valid_for_bitfield_p (tree value)
4647 /* For bitfields we support integer constants or possibly nested aggregates
4649 switch (TREE_CODE (value))
4653 unsigned HOST_WIDE_INT idx;
4656 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4657 if (!initializer_constant_valid_for_bitfield_p (elt))
4665 case VIEW_CONVERT_EXPR:
4666 case NON_LVALUE_EXPR:
4668 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4677 /* output_constructor outer state of relevance in recursive calls, typically
4678 for nested aggregate bitfields. */
4681 unsigned int bit_offset; /* current position in ... */
4682 int byte; /* ... the outer byte buffer. */
4685 static unsigned HOST_WIDE_INT
4686 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4689 /* Output assembler code for constant EXP to FILE, with no label.
4690 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4691 Assumes output_addressed_constants has been done on EXP already.
4693 Generate exactly SIZE bytes of assembler data, padding at the end
4694 with zeros if necessary. SIZE must always be specified.
4696 SIZE is important for structure constructors,
4697 since trailing members may have been omitted from the constructor.
4698 It is also important for initialization of arrays from string constants
4699 since the full length of the string constant might not be wanted.
4700 It is also needed for initialization of unions, where the initializer's
4701 type is just one member, and that may not be as long as the union.
4703 There a case in which we would fail to output exactly SIZE bytes:
4704 for a structure constructor that wants to produce more than SIZE bytes.
4705 But such constructors will never be generated for any possible input.
4707 ALIGN is the alignment of the data in bits. */
4710 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4712 enum tree_code code;
4713 unsigned HOST_WIDE_INT thissize;
4715 if (size == 0 || flag_syntax_only)
4718 /* See if we're trying to initialize a pointer in a non-default mode
4719 to the address of some declaration somewhere. If the target says
4720 the mode is valid for pointers, assume the target has a way of
4722 if (TREE_CODE (exp) == NOP_EXPR
4723 && POINTER_TYPE_P (TREE_TYPE (exp))
4724 && targetm.addr_space.valid_pointer_mode
4725 (TYPE_MODE (TREE_TYPE (exp)),
4726 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4728 tree saved_type = TREE_TYPE (exp);
4730 /* Peel off any intermediate conversions-to-pointer for valid
4732 while (TREE_CODE (exp) == NOP_EXPR
4733 && POINTER_TYPE_P (TREE_TYPE (exp))
4734 && targetm.addr_space.valid_pointer_mode
4735 (TYPE_MODE (TREE_TYPE (exp)),
4736 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4737 exp = TREE_OPERAND (exp, 0);
4739 /* If what we're left with is the address of something, we can
4740 convert the address to the final type and output it that
4742 if (TREE_CODE (exp) == ADDR_EXPR)
4743 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4744 /* Likewise for constant ints. */
4745 else if (TREE_CODE (exp) == INTEGER_CST)
4746 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4747 TREE_INT_CST_HIGH (exp));
4751 /* Eliminate any conversions since we'll be outputting the underlying
4753 while (CONVERT_EXPR_P (exp)
4754 || TREE_CODE (exp) == NON_LVALUE_EXPR
4755 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4757 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4758 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4760 /* Make sure eliminating the conversion is really a no-op, except with
4761 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4762 union types to allow for Ada unchecked unions. */
4763 if (type_size > op_size
4764 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4765 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4766 /* Keep the conversion. */
4769 exp = TREE_OPERAND (exp, 0);
4772 code = TREE_CODE (TREE_TYPE (exp));
4773 thissize = int_size_in_bytes (TREE_TYPE (exp));
4775 /* Allow a constructor with no elements for any data type.
4776 This means to fill the space with zeros. */
4777 if (TREE_CODE (exp) == CONSTRUCTOR
4778 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4780 assemble_zeros (size);
4784 if (TREE_CODE (exp) == FDESC_EXPR)
4786 #ifdef ASM_OUTPUT_FDESC
4787 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4788 tree decl = TREE_OPERAND (exp, 0);
4789 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4796 /* Now output the underlying data. If we've handling the padding, return.
4797 Otherwise, break and ensure SIZE is the size written. */
4804 case REFERENCE_TYPE:
4806 case FIXED_POINT_TYPE:
4807 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4808 EXPAND_INITIALIZER),
4809 MIN (size, thissize), align, 0))
4810 error ("initializer for integer/fixed-point value is too complicated");
4814 if (TREE_CODE (exp) != REAL_CST)
4815 error ("initializer for floating value is not a floating constant");
4817 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4821 output_constant (TREE_REALPART (exp), thissize / 2, align);
4822 output_constant (TREE_IMAGPART (exp), thissize / 2,
4823 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4828 switch (TREE_CODE (exp))
4831 output_constructor (exp, size, align, NULL);
4834 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4836 assemble_string (TREE_STRING_POINTER (exp), thissize);
4843 unsigned int nalign;
4844 enum machine_mode inner;
4846 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4847 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4849 elt_size = GET_MODE_SIZE (inner);
4851 link = TREE_VECTOR_CST_ELTS (exp);
4852 output_constant (TREE_VALUE (link), elt_size, align);
4853 thissize = elt_size;
4854 while ((link = TREE_CHAIN (link)) != NULL)
4856 output_constant (TREE_VALUE (link), elt_size, nalign);
4857 thissize += elt_size;
4868 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4869 output_constructor (exp, size, align, NULL);
4879 if (size > thissize)
4880 assemble_zeros (size - thissize);
4884 /* Subroutine of output_constructor, used for computing the size of
4885 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4886 type with an unspecified upper bound. */
4888 static unsigned HOST_WIDE_INT
4889 array_size_for_constructor (tree val)
4892 unsigned HOST_WIDE_INT cnt;
4893 tree index, value, tmp;
4895 /* This code used to attempt to handle string constants that are not
4896 arrays of single-bytes, but nothing else does, so there's no point in
4898 if (TREE_CODE (val) == STRING_CST)
4899 return TREE_STRING_LENGTH (val);
4901 max_index = NULL_TREE;
4902 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4904 if (TREE_CODE (index) == RANGE_EXPR)
4905 index = TREE_OPERAND (index, 1);
4906 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4910 if (max_index == NULL_TREE)
4913 /* Compute the total number of array elements. */
4914 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4915 i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4916 fold_convert (sizetype, tmp));
4917 i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4919 /* Multiply by the array element unit size to find number of bytes. */
4920 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4922 return tree_low_cst (i, 1);
4925 /* Other datastructures + helpers for output_constructor. */
4927 /* output_constructor local state to support interaction with helpers. */
4931 /* Received arguments. */
4932 tree exp; /* Constructor expression. */
4933 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4934 unsigned int align; /* Known initial alignment. */
4936 /* Constructor expression data. */
4937 tree type; /* Expression type. */
4938 tree field; /* Current field decl in a record. */
4939 tree min_index; /* Lower bound if specified for an array. */
4941 /* Output processing state. */
4942 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4943 bool byte_buffer_in_use; /* Whether byte ... */
4944 int byte; /* ... contains part of a bitfield byte yet to
4947 int last_relative_index; /* Implicit or explicit index of the last
4948 array element output within a bitfield. */
4949 /* Current element. */
4950 tree val; /* Current element value. */
4951 tree index; /* Current element index. */
4955 /* Helper for output_constructor. From the current LOCAL state, output a
4956 RANGE_EXPR element. */
4959 output_constructor_array_range (oc_local_state *local)
4961 unsigned HOST_WIDE_INT fieldsize
4962 = int_size_in_bytes (TREE_TYPE (local->type));
4964 HOST_WIDE_INT lo_index
4965 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4966 HOST_WIDE_INT hi_index
4967 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4968 HOST_WIDE_INT index;
4971 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4973 for (index = lo_index; index <= hi_index; index++)
4975 /* Output the element's initial value. */
4976 if (local->val == NULL_TREE)
4977 assemble_zeros (fieldsize);
4979 output_constant (local->val, fieldsize, align2);
4981 /* Count its size. */
4982 local->total_bytes += fieldsize;
4986 /* Helper for output_constructor. From the current LOCAL state, output a
4987 field element that is not true bitfield or part of an outer one. */
4990 output_constructor_regular_field (oc_local_state *local)
4992 /* Field size and position. Since this structure is static, we know the
4993 positions are constant. */
4994 unsigned HOST_WIDE_INT fieldsize;
4995 HOST_WIDE_INT fieldpos;
4997 unsigned int align2;
4999 if (local->index != NULL_TREE)
5000 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
5001 * ((tree_low_cst (local->index, 0)
5002 - tree_low_cst (local->min_index, 0))));
5003 else if (local->field != NULL_TREE)
5004 fieldpos = int_byte_position (local->field);
5008 /* Output any buffered-up bit-fields preceding this element. */
5009 if (local->byte_buffer_in_use)
5011 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5012 local->total_bytes++;
5013 local->byte_buffer_in_use = false;
5016 /* Advance to offset of this element.
5017 Note no alignment needed in an array, since that is guaranteed
5018 if each element has the proper size. */
5019 if ((local->field != NULL_TREE || local->index != NULL_TREE)
5020 && fieldpos != local->total_bytes)
5022 gcc_assert (fieldpos >= local->total_bytes);
5023 assemble_zeros (fieldpos - local->total_bytes);
5024 local->total_bytes = fieldpos;
5027 /* Find the alignment of this element. */
5028 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
5030 /* Determine size this element should occupy. */
5035 /* If this is an array with an unspecified upper bound,
5036 the initializer determines the size. */
5037 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5038 but we cannot do this until the deprecated support for
5039 initializing zero-length array members is removed. */
5040 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
5041 && TYPE_DOMAIN (TREE_TYPE (local->field))
5042 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
5044 fieldsize = array_size_for_constructor (local->val);
5045 /* Given a non-empty initialization, this field had
5047 gcc_assert (!fieldsize || !TREE_CHAIN (local->field));
5049 else if (DECL_SIZE_UNIT (local->field))
5051 /* ??? This can't be right. If the decl size overflows
5052 a host integer we will silently emit no data. */
5053 if (host_integerp (DECL_SIZE_UNIT (local->field), 1))
5054 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
5058 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
5060 /* Output the element's initial value. */
5061 if (local->val == NULL_TREE)
5062 assemble_zeros (fieldsize);
5064 output_constant (local->val, fieldsize, align2);
5066 /* Count its size. */
5067 local->total_bytes += fieldsize;
5070 /* Helper for output_constructor. From the current LOCAL and OUTER states,
5071 output an element that is a true bitfield or part of an outer one. */
5074 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
5076 /* Bit size of this element. */
5077 HOST_WIDE_INT ebitsize
5079 ? tree_low_cst (DECL_SIZE (local->field), 1)
5080 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
5082 /* Relative index of this element if this is an array component. */
5083 HOST_WIDE_INT relative_index
5086 ? (tree_low_cst (local->index, 0)
5087 - tree_low_cst (local->min_index, 0))
5088 : local->last_relative_index + 1)
5091 /* Bit position of this element from the start of the containing
5093 HOST_WIDE_INT constructor_relative_ebitpos
5095 ? int_bit_position (local->field)
5096 : ebitsize * relative_index);
5098 /* Bit position of this element from the start of a possibly ongoing
5099 outer byte buffer. */
5100 HOST_WIDE_INT byte_relative_ebitpos
5101 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
5103 /* From the start of a possibly ongoing outer byte buffer, offsets to
5104 the first bit of this element and to the first bit past the end of
5106 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
5107 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
5109 local->last_relative_index = relative_index;
5111 if (local->val == NULL_TREE)
5112 local->val = integer_zero_node;
5114 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
5115 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
5116 local->val = TREE_OPERAND (local->val, 0);
5118 if (TREE_CODE (local->val) != INTEGER_CST
5119 && TREE_CODE (local->val) != CONSTRUCTOR)
5121 error ("invalid initial value for member %qE", DECL_NAME (local->field));
5125 /* If this field does not start in this (or, next) byte,
5127 if (next_offset / BITS_PER_UNIT != local->total_bytes)
5129 /* Output remnant of any bit field in previous bytes. */
5130 if (local->byte_buffer_in_use)
5132 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5133 local->total_bytes++;
5134 local->byte_buffer_in_use = false;
5137 /* If still not at proper byte, advance to there. */
5138 if (next_offset / BITS_PER_UNIT != local->total_bytes)
5140 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
5141 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
5142 local->total_bytes = next_offset / BITS_PER_UNIT;
5146 /* Set up the buffer if necessary. */
5147 if (!local->byte_buffer_in_use)
5151 local->byte_buffer_in_use = true;
5154 /* If this is nested constructor, recurse passing the bit offset and the
5155 pending data, then retrieve the new pending data afterwards. */
5156 if (TREE_CODE (local->val) == CONSTRUCTOR)
5158 oc_outer_state output_state;
5160 output_state.bit_offset = next_offset % BITS_PER_UNIT;
5161 output_state.byte = local->byte;
5163 += output_constructor (local->val, 0, 0, &output_state);
5164 local->byte = output_state.byte;
5168 /* Otherwise, we must split the element into pieces that fall within
5169 separate bytes, and combine each byte with previous or following
5171 while (next_offset < end_offset)
5175 HOST_WIDE_INT value;
5176 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
5177 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
5179 /* Advance from byte to byte
5180 within this element when necessary. */
5181 while (next_byte != local->total_bytes)
5183 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5184 local->total_bytes++;
5188 /* Number of bits we can process at once
5189 (all part of the same byte). */
5190 this_time = MIN (end_offset - next_offset,
5191 BITS_PER_UNIT - next_bit);
5192 if (BYTES_BIG_ENDIAN)
5194 /* On big-endian machine, take the most significant bits
5195 first (of the bits that are significant)
5196 and put them into bytes from the most significant end. */
5197 shift = end_offset - next_offset - this_time;
5199 /* Don't try to take a bunch of bits that cross
5200 the word boundary in the INTEGER_CST. We can
5201 only select bits from the LOW or HIGH part
5203 if (shift < HOST_BITS_PER_WIDE_INT
5204 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5206 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
5207 shift = HOST_BITS_PER_WIDE_INT;
5210 /* Now get the bits from the appropriate constant word. */
5211 if (shift < HOST_BITS_PER_WIDE_INT)
5212 value = TREE_INT_CST_LOW (local->val);
5215 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5216 value = TREE_INT_CST_HIGH (local->val);
5217 shift -= HOST_BITS_PER_WIDE_INT;
5220 /* Get the result. This works only when:
5221 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5222 local->byte |= (((value >> shift)
5223 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5224 << (BITS_PER_UNIT - this_time - next_bit));
5228 /* On little-endian machines,
5229 take first the least significant bits of the value
5230 and pack them starting at the least significant
5231 bits of the bytes. */
5232 shift = next_offset - byte_relative_ebitpos;
5234 /* Don't try to take a bunch of bits that cross
5235 the word boundary in the INTEGER_CST. We can
5236 only select bits from the LOW or HIGH part
5238 if (shift < HOST_BITS_PER_WIDE_INT
5239 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5240 this_time = (HOST_BITS_PER_WIDE_INT - shift);
5242 /* Now get the bits from the appropriate constant word. */
5243 if (shift < HOST_BITS_PER_WIDE_INT)
5244 value = TREE_INT_CST_LOW (local->val);
5247 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5248 value = TREE_INT_CST_HIGH (local->val);
5249 shift -= HOST_BITS_PER_WIDE_INT;
5252 /* Get the result. This works only when:
5253 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5254 local->byte |= (((value >> shift)
5255 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5259 next_offset += this_time;
5260 local->byte_buffer_in_use = true;
5264 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5265 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5266 caller output state of relevance in recursive invocations. */
5268 static unsigned HOST_WIDE_INT
5269 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
5270 unsigned int align, oc_outer_state * outer)
5272 unsigned HOST_WIDE_INT cnt;
5273 constructor_elt *ce;
5275 oc_local_state local;
5277 /* Setup our local state to communicate with helpers. */
5280 local.align = align;
5282 local.total_bytes = 0;
5283 local.byte_buffer_in_use = outer != NULL;
5284 local.byte = outer ? outer->byte : 0;
5286 local.type = TREE_TYPE (exp);
5288 local.last_relative_index = -1;
5290 local.min_index = NULL_TREE;
5291 if (TREE_CODE (local.type) == ARRAY_TYPE
5292 && TYPE_DOMAIN (local.type) != NULL_TREE)
5293 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5295 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
5297 /* As CE goes through the elements of the constant, FIELD goes through the
5298 structure fields if the constant is a structure. If the constant is a
5299 union, we override this by getting the field from the TREE_LIST element.
5300 But the constant could also be an array. Then FIELD is zero.
5302 There is always a maximum of one element in the chain LINK for unions
5303 (even if the initializer in a source program incorrectly contains
5306 local.field = NULL_TREE;
5307 if (TREE_CODE (local.type) == RECORD_TYPE)
5308 local.field = TYPE_FIELDS (local.type);
5311 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
5312 cnt++, local.field = local.field ? TREE_CHAIN (local.field) : 0)
5314 local.val = ce->value;
5315 local.index = NULL_TREE;
5317 /* The element in a union constructor specifies the proper field
5319 if ((TREE_CODE (local.type) == RECORD_TYPE
5320 || TREE_CODE (local.type) == UNION_TYPE
5321 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
5322 && ce->index != NULL_TREE)
5323 local.field = ce->index;
5325 else if (TREE_CODE (local.type) == ARRAY_TYPE)
5326 local.index = ce->index;
5328 #ifdef ASM_COMMENT_START
5329 if (local.field && flag_verbose_asm)
5330 fprintf (asm_out_file, "%s %s:\n",
5332 DECL_NAME (local.field)
5333 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
5337 /* Eliminate the marker that makes a cast not be an lvalue. */
5338 if (local.val != NULL_TREE)
5339 STRIP_NOPS (local.val);
5341 /* Output the current element, using the appropriate helper ... */
5343 /* For an array slice not part of an outer bitfield. */
5345 && local.index != NULL_TREE
5346 && TREE_CODE (local.index) == RANGE_EXPR)
5347 output_constructor_array_range (&local);
5349 /* For a field that is neither a true bitfield nor part of an outer one,
5350 known to be at least byte aligned and multiple-of-bytes long. */
5352 && (local.field == NULL_TREE
5353 || !CONSTRUCTOR_BITFIELD_P (local.field)))
5354 output_constructor_regular_field (&local);
5356 /* For a true bitfield or part of an outer one. */
5358 output_constructor_bitfield (&local, outer);
5361 /* If we are not at toplevel, save the pending data for our caller.
5362 Otherwise output the pending data and padding zeros as needed. */
5364 outer->byte = local.byte;
5367 if (local.byte_buffer_in_use)
5369 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
5370 local.total_bytes++;
5373 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
5375 assemble_zeros (local.size - local.total_bytes);
5376 local.total_bytes = local.size;
5380 return local.total_bytes;
5383 /* Mark DECL as weak. */
5386 mark_weak (tree decl)
5388 DECL_WEAK (decl) = 1;
5390 if (DECL_RTL_SET_P (decl)
5391 && MEM_P (DECL_RTL (decl))
5392 && XEXP (DECL_RTL (decl), 0)
5393 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5394 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5397 /* Merge weak status between NEWDECL and OLDDECL. */
5400 merge_weak (tree newdecl, tree olddecl)
5402 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5404 if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
5407 /* We put the NEWDECL on the weak_decls list at some point
5408 and OLDDECL as well. Keep just OLDDECL on the list. */
5409 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5410 if (TREE_VALUE (*pwd) == newdecl)
5412 *pwd = TREE_CHAIN (*pwd);
5419 if (DECL_WEAK (newdecl))
5423 /* NEWDECL is weak, but OLDDECL is not. */
5425 /* If we already output the OLDDECL, we're in trouble; we can't
5426 go back and make it weak. This error cannot be caught in
5427 declare_weak because the NEWDECL and OLDDECL was not yet
5428 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5429 if (TREE_ASM_WRITTEN (olddecl))
5430 error ("weak declaration of %q+D must precede definition",
5433 /* If we've already generated rtl referencing OLDDECL, we may
5434 have done so in a way that will not function properly with
5436 else if (TREE_USED (olddecl)
5437 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
5438 warning (0, "weak declaration of %q+D after first use results "
5439 "in unspecified behavior", newdecl);
5443 /* We put the NEWDECL on the weak_decls list at some point.
5444 Replace it with the OLDDECL. */
5445 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5446 if (TREE_VALUE (wd) == newdecl)
5448 TREE_VALUE (wd) = olddecl;
5451 /* We may not find the entry on the list. If NEWDECL is a
5452 weak alias, then we will have already called
5453 globalize_decl to remove the entry; in that case, we do
5454 not need to do anything. */
5457 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5458 mark_weak (olddecl);
5461 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5462 weak. Just update NEWDECL to indicate that it's weak too. */
5463 mark_weak (newdecl);
5466 /* Declare DECL to be a weak symbol. */
5469 declare_weak (tree decl)
5471 if (! TREE_PUBLIC (decl))
5472 error ("weak declaration of %q+D must be public", decl);
5473 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
5474 error ("weak declaration of %q+D must precede definition", decl);
5475 else if (!SUPPORTS_WEAK)
5476 warning (0, "weak declaration of %q+D not supported", decl);
5479 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5480 DECL_ATTRIBUTES (decl)
5481 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5485 weak_finish_1 (tree decl)
5487 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5488 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5491 if (! TREE_USED (decl))
5494 #ifdef ASM_WEAKEN_DECL
5495 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5497 #ifdef ASM_WEAKEN_LABEL
5498 ASM_WEAKEN_LABEL (asm_out_file, name);
5500 #ifdef ASM_OUTPUT_WEAK_ALIAS
5502 static bool warn_once = 0;
5505 warning (0, "only weak aliases are supported in this configuration");
5515 /* This TREE_LIST contains weakref targets. */
5517 static GTY(()) tree weakref_targets;
5519 /* Forward declaration. */
5520 static tree find_decl_and_mark_needed (tree decl, tree target);
5522 /* Emit any pending weak declarations. */
5529 for (t = weakref_targets; t; t = TREE_CHAIN (t))
5531 tree alias_decl = TREE_PURPOSE (t);
5532 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5534 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5535 /* Remove alias_decl from the weak list, but leave entries for
5536 the target alone. */
5538 #ifndef ASM_OUTPUT_WEAKREF
5539 else if (! TREE_SYMBOL_REFERENCED (target))
5541 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5542 defined, otherwise we and weak_finish_1 would use
5543 different macros. */
5544 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5545 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5547 tree decl = find_decl_and_mark_needed (alias_decl, target);
5551 decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5552 TREE_CODE (alias_decl), target,
5553 TREE_TYPE (alias_decl));
5555 DECL_EXTERNAL (decl) = 1;
5556 TREE_PUBLIC (decl) = 1;
5557 DECL_ARTIFICIAL (decl) = 1;
5558 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5559 TREE_USED (decl) = 1;
5562 weak_finish_1 (decl);
5571 /* Remove the alias and the target from the pending weak list
5572 so that we do not emit any .weak directives for the former,
5573 nor multiple .weak directives for the latter. */
5574 for (p = &weak_decls; (t2 = *p) ; )
5576 if (TREE_VALUE (t2) == alias_decl
5577 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5578 *p = TREE_CHAIN (t2);
5580 p = &TREE_CHAIN (t2);
5583 /* Remove other weakrefs to the same target, to speed things up. */
5584 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5586 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5587 *p = TREE_CHAIN (t2);
5589 p = &TREE_CHAIN (t2);
5594 for (t = weak_decls; t; t = TREE_CHAIN (t))
5596 tree decl = TREE_VALUE (t);
5598 weak_finish_1 (decl);
5602 /* Emit the assembly bits to indicate that DECL is globally visible. */
5605 globalize_decl (tree decl)
5608 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5609 if (DECL_WEAK (decl))
5611 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5614 #ifdef ASM_WEAKEN_DECL
5615 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5617 ASM_WEAKEN_LABEL (asm_out_file, name);
5620 /* Remove this function from the pending weak list so that
5621 we do not emit multiple .weak directives for it. */
5622 for (p = &weak_decls; (t = *p) ; )
5624 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5625 *p = TREE_CHAIN (t);
5627 p = &TREE_CHAIN (t);
5630 /* Remove weakrefs to the same target from the pending weakref
5631 list, for the same reason. */
5632 for (p = &weakref_targets; (t = *p) ; )
5634 if (DECL_ASSEMBLER_NAME (decl)
5635 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5636 *p = TREE_CHAIN (t);
5638 p = &TREE_CHAIN (t);
5645 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5648 VEC(alias_pair,gc) *alias_pairs;
5650 /* Given an assembly name, find the decl it is associated with. At the
5651 same time, mark it needed for cgraph. */
5654 find_decl_and_mark_needed (tree decl, tree target)
5656 struct cgraph_node *fnode = NULL;
5657 struct varpool_node *vnode = NULL;
5659 if (TREE_CODE (decl) == FUNCTION_DECL)
5661 fnode = cgraph_node_for_asm (target);
5663 vnode = varpool_node_for_asm (target);
5667 vnode = varpool_node_for_asm (target);
5669 fnode = cgraph_node_for_asm (target);
5674 cgraph_mark_needed_node (fnode);
5679 varpool_mark_needed_node (vnode);
5680 vnode->force_output = 1;
5687 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5688 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5689 tree node is DECL to have the value of the tree node TARGET. */
5692 do_assemble_alias (tree decl, tree target)
5694 if (TREE_ASM_WRITTEN (decl))
5697 /* We must force creation of DECL_RTL for debug info generation, even though
5698 we don't use it here. */
5699 make_decl_rtl (decl);
5701 TREE_ASM_WRITTEN (decl) = 1;
5702 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5704 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5706 ultimate_transparent_alias_target (&target);
5708 if (!targetm.have_tls
5709 && TREE_CODE (decl) == VAR_DECL
5710 && DECL_THREAD_LOCAL_P (decl))
5712 decl = emutls_decl (decl);
5713 target = get_emutls_object_name (target);
5716 if (!TREE_SYMBOL_REFERENCED (target))
5717 weakref_targets = tree_cons (decl, target, weakref_targets);
5719 #ifdef ASM_OUTPUT_WEAKREF
5720 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5721 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5722 IDENTIFIER_POINTER (target));
5726 error_at (DECL_SOURCE_LOCATION (decl),
5727 "weakref is not supported in this configuration");
5734 if (!targetm.have_tls
5735 && TREE_CODE (decl) == VAR_DECL
5736 && DECL_THREAD_LOCAL_P (decl))
5738 decl = emutls_decl (decl);
5739 target = get_emutls_object_name (target);
5742 #ifdef ASM_OUTPUT_DEF
5743 /* Make name accessible from other files, if appropriate. */
5745 if (TREE_PUBLIC (decl))
5747 globalize_decl (decl);
5748 maybe_assemble_visibility (decl);
5751 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5752 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5754 ASM_OUTPUT_DEF (asm_out_file,
5755 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5756 IDENTIFIER_POINTER (target));
5758 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5763 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5764 # ifdef ASM_WEAKEN_DECL
5765 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5767 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5769 /* Remove this function from the pending weak list so that
5770 we do not emit multiple .weak directives for it. */
5771 for (p = &weak_decls; (t = *p) ; )
5772 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5773 *p = TREE_CHAIN (t);
5775 p = &TREE_CHAIN (t);
5777 /* Remove weakrefs to the same target from the pending weakref
5778 list, for the same reason. */
5779 for (p = &weakref_targets; (t = *p) ; )
5781 if (DECL_ASSEMBLER_NAME (decl)
5782 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5783 *p = TREE_CHAIN (t);
5785 p = &TREE_CHAIN (t);
5792 /* Remove the alias pairing for functions that are no longer in the call
5796 remove_unreachable_alias_pairs (void)
5801 if (alias_pairs == NULL)
5804 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5806 if (!DECL_EXTERNAL (p->decl))
5808 struct cgraph_node *fnode = NULL;
5809 struct varpool_node *vnode = NULL;
5810 fnode = cgraph_node_for_asm (p->target);
5811 vnode = (fnode == NULL) ? varpool_node_for_asm (p->target) : NULL;
5812 if (fnode == NULL && vnode == NULL)
5814 VEC_unordered_remove (alias_pair, alias_pairs, i);
5824 /* First pass of completing pending aliases. Make sure that cgraph knows
5825 which symbols will be required. */
5828 finish_aliases_1 (void)
5833 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5837 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5838 if (target_decl == NULL)
5840 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5841 error ("%q+D aliased to undefined symbol %qE",
5842 p->decl, p->target);
5844 else if (DECL_EXTERNAL (target_decl)
5845 /* We use local aliases for C++ thunks to force the tailcall
5846 to bind locally. Of course this is a hack - to keep it
5847 working do the following (which is not strictly correct). */
5848 && (! TREE_CODE (target_decl) == FUNCTION_DECL
5849 || ! DECL_VIRTUAL_P (target_decl))
5850 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5851 error ("%q+D aliased to external symbol %qE",
5852 p->decl, p->target);
5856 /* Second pass of completing pending aliases. Emit the actual assembly.
5857 This happens at the end of compilation and thus it is assured that the
5858 target symbol has been emitted. */
5861 finish_aliases_2 (void)
5866 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5867 do_assemble_alias (p->decl, p->target);
5869 VEC_truncate (alias_pair, alias_pairs, 0);
5872 /* Emit an assembler directive to make the symbol for DECL an alias to
5873 the symbol for TARGET. */
5876 assemble_alias (tree decl, tree target)
5879 bool is_weakref = false;
5881 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5883 tree alias = DECL_ASSEMBLER_NAME (decl);
5887 ultimate_transparent_alias_target (&target);
5889 if (alias == target)
5890 error ("weakref %q+D ultimately targets itself", decl);
5893 #ifndef ASM_OUTPUT_WEAKREF
5894 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5895 TREE_CHAIN (alias) = target;
5898 if (TREE_PUBLIC (decl))
5899 error ("weakref %q+D must have static linkage", decl);
5903 #if !defined (ASM_OUTPUT_DEF)
5904 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5905 error_at (DECL_SOURCE_LOCATION (decl),
5906 "alias definitions not supported in this configuration");
5909 if (!DECL_WEAK (decl))
5911 error_at (DECL_SOURCE_LOCATION (decl),
5912 "only weak aliases are supported in this configuration");
5918 TREE_USED (decl) = 1;
5920 /* A quirk of the initial implementation of aliases required that the user
5921 add "extern" to all of them. Which is silly, but now historical. Do
5922 note that the symbol is in fact locally defined. */
5924 DECL_EXTERNAL (decl) = 0;
5926 /* Allow aliases to aliases. */
5927 if (TREE_CODE (decl) == FUNCTION_DECL)
5928 cgraph_node (decl)->alias = true;
5930 varpool_node (decl)->alias = true;
5932 /* If the target has already been emitted, we don't have to queue the
5933 alias. This saves a tad of memory. */
5934 if (cgraph_global_info_ready)
5935 target_decl = find_decl_and_mark_needed (decl, target);
5938 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5939 do_assemble_alias (decl, target);
5942 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5948 /* Emit an assembler directive to set symbol for DECL visibility to
5949 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5952 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
5953 int vis ATTRIBUTE_UNUSED)
5955 #ifdef HAVE_GAS_HIDDEN
5956 static const char * const visibility_types[] = {
5957 NULL, "protected", "hidden", "internal"
5960 const char *name, *type;
5962 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5963 type = visibility_types[vis];
5965 fprintf (asm_out_file, "\t.%s\t", type);
5966 assemble_name (asm_out_file, name);
5967 fprintf (asm_out_file, "\n");
5969 warning (OPT_Wattributes, "visibility attribute not supported "
5970 "in this configuration; ignored");
5974 /* A helper function to call assemble_visibility when needed for a decl. */
5977 maybe_assemble_visibility (tree decl)
5979 enum symbol_visibility vis = DECL_VISIBILITY (decl);
5981 if (vis != VISIBILITY_DEFAULT)
5983 targetm.asm_out.assemble_visibility (decl, vis);
5990 /* Returns 1 if the target configuration supports defining public symbols
5991 so that one of them will be chosen at link time instead of generating a
5992 multiply-defined symbol error, whether through the use of weak symbols or
5993 a target-specific mechanism for having duplicates discarded. */
5996 supports_one_only (void)
5998 if (SUPPORTS_ONE_ONLY)
6000 return SUPPORTS_WEAK;
6003 /* Set up DECL as a public symbol that can be defined in multiple
6004 translation units without generating a linker error. */
6007 make_decl_one_only (tree decl, tree comdat_group)
6009 gcc_assert (TREE_CODE (decl) == VAR_DECL
6010 || TREE_CODE (decl) == FUNCTION_DECL);
6012 TREE_PUBLIC (decl) = 1;
6014 if (SUPPORTS_ONE_ONLY)
6016 #ifdef MAKE_DECL_ONE_ONLY
6017 MAKE_DECL_ONE_ONLY (decl);
6019 DECL_COMDAT_GROUP (decl) = comdat_group;
6021 else if (TREE_CODE (decl) == VAR_DECL
6022 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
6023 DECL_COMMON (decl) = 1;
6026 gcc_assert (SUPPORTS_WEAK);
6027 DECL_WEAK (decl) = 1;
6032 init_varasm_once (void)
6034 section_htab = htab_create_ggc (31, section_entry_hash,
6035 section_entry_eq, NULL);
6036 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
6037 object_block_entry_eq, NULL);
6038 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
6039 const_desc_eq, NULL);
6041 const_alias_set = new_alias_set ();
6042 shared_constant_pool = create_constant_pool ();
6044 #ifdef TEXT_SECTION_ASM_OP
6045 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
6046 TEXT_SECTION_ASM_OP);
6049 #ifdef DATA_SECTION_ASM_OP
6050 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6051 DATA_SECTION_ASM_OP);
6054 #ifdef SDATA_SECTION_ASM_OP
6055 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6056 SDATA_SECTION_ASM_OP);
6059 #ifdef READONLY_DATA_SECTION_ASM_OP
6060 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
6061 READONLY_DATA_SECTION_ASM_OP);
6064 #ifdef CTORS_SECTION_ASM_OP
6065 ctors_section = get_unnamed_section (0, output_section_asm_op,
6066 CTORS_SECTION_ASM_OP);
6069 #ifdef DTORS_SECTION_ASM_OP
6070 dtors_section = get_unnamed_section (0, output_section_asm_op,
6071 DTORS_SECTION_ASM_OP);
6074 #ifdef BSS_SECTION_ASM_OP
6075 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6076 output_section_asm_op,
6077 BSS_SECTION_ASM_OP);
6080 #ifdef SBSS_SECTION_ASM_OP
6081 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6082 output_section_asm_op,
6083 SBSS_SECTION_ASM_OP);
6086 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6087 | SECTION_COMMON, emit_tls_common);
6088 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6089 | SECTION_COMMON, emit_local);
6090 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6091 | SECTION_COMMON, emit_common);
6093 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
6094 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
6098 targetm.asm_out.init_sections ();
6100 if (readonly_data_section == NULL)
6101 readonly_data_section = text_section;
6105 decl_default_tls_model (const_tree decl)
6107 enum tls_model kind;
6110 is_local = targetm.binds_local_p (decl);
6114 kind = TLS_MODEL_LOCAL_EXEC;
6116 kind = TLS_MODEL_INITIAL_EXEC;
6119 /* Local dynamic is inefficient when we're not combining the
6120 parts of the address. */
6121 else if (optimize && is_local)
6122 kind = TLS_MODEL_LOCAL_DYNAMIC;
6124 kind = TLS_MODEL_GLOBAL_DYNAMIC;
6125 if (kind < flag_tls_default)
6126 kind = flag_tls_default;
6131 /* Select a set of attributes for section NAME based on the properties
6132 of DECL and whether or not RELOC indicates that DECL's initializer
6133 might contain runtime relocations.
6135 We make the section read-only and executable for a function decl,
6136 read-only for a const data decl, and writable for a non-const data decl. */
6139 default_section_type_flags (tree decl, const char *name, int reloc)
6143 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
6144 flags = SECTION_CODE;
6145 else if (decl && decl_readonly_section (decl, reloc))
6147 else if (current_function_decl
6149 && crtl->subsections.unlikely_text_section_name
6150 && strcmp (name, crtl->subsections.unlikely_text_section_name) == 0)
6151 flags = SECTION_CODE;
6153 && (!current_function_decl || !cfun)
6154 && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6155 flags = SECTION_CODE;
6157 flags = SECTION_WRITE;
6159 if (decl && DECL_ONE_ONLY (decl))
6160 flags |= SECTION_LINKONCE;
6162 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6163 flags |= SECTION_TLS | SECTION_WRITE;
6165 if (strcmp (name, ".bss") == 0
6166 || strncmp (name, ".bss.", 5) == 0
6167 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
6168 || strcmp (name, ".sbss") == 0
6169 || strncmp (name, ".sbss.", 6) == 0
6170 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
6171 flags |= SECTION_BSS;
6173 if (strcmp (name, ".tdata") == 0
6174 || strncmp (name, ".tdata.", 7) == 0
6175 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
6176 flags |= SECTION_TLS;
6178 if (strcmp (name, ".tbss") == 0
6179 || strncmp (name, ".tbss.", 6) == 0
6180 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
6181 flags |= SECTION_TLS | SECTION_BSS;
6183 /* These three sections have special ELF types. They are neither
6184 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6185 want to print a section type (@progbits or @nobits). If someone
6186 is silly enough to emit code or TLS variables to one of these
6187 sections, then don't handle them specially. */
6188 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
6189 && (strcmp (name, ".init_array") == 0
6190 || strcmp (name, ".fini_array") == 0
6191 || strcmp (name, ".preinit_array") == 0))
6192 flags |= SECTION_NOTYPE;
6197 /* Return true if the target supports some form of global BSS,
6198 either through bss_noswitch_section, or by selecting a BSS
6199 section in TARGET_ASM_SELECT_SECTION. */
6202 have_global_bss_p (void)
6204 return bss_noswitch_section || targetm.have_switchable_bss_sections;
6207 /* Output assembly to switch to section NAME with attribute FLAGS.
6208 Four variants for common object file formats. */
6211 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
6212 unsigned int flags ATTRIBUTE_UNUSED,
6213 tree decl ATTRIBUTE_UNUSED)
6215 /* Some object formats don't support named sections at all. The
6216 front-end should already have flagged this as an error. */
6220 #ifndef TLS_SECTION_ASM_FLAG
6221 #define TLS_SECTION_ASM_FLAG 'T'
6225 default_elf_asm_named_section (const char *name, unsigned int flags,
6226 tree decl ATTRIBUTE_UNUSED)
6228 char flagchars[10], *f = flagchars;
6230 /* If we have already declared this section, we can use an
6231 abbreviated form to switch back to it -- unless this section is
6232 part of a COMDAT groups, in which case GAS requires the full
6233 declaration every time. */
6234 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6235 && (flags & SECTION_DECLARED))
6237 fprintf (asm_out_file, "\t.section\t%s\n", name);
6241 if (!(flags & SECTION_DEBUG))
6243 if (flags & SECTION_WRITE)
6245 if (flags & SECTION_CODE)
6247 if (flags & SECTION_SMALL)
6249 if (flags & SECTION_MERGE)
6251 if (flags & SECTION_STRINGS)
6253 if (flags & SECTION_TLS)
6254 *f++ = TLS_SECTION_ASM_FLAG;
6255 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6259 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
6261 if (!(flags & SECTION_NOTYPE))
6266 if (flags & SECTION_BSS)
6272 #ifdef ASM_COMMENT_START
6273 /* On platforms that use "@" as the assembly comment character,
6275 if (strcmp (ASM_COMMENT_START, "@") == 0)
6278 fprintf (asm_out_file, format, type);
6280 if (flags & SECTION_ENTSIZE)
6281 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
6282 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6284 if (TREE_CODE (decl) == IDENTIFIER_NODE)
6285 fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
6287 fprintf (asm_out_file, ",%s,comdat",
6288 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
6292 putc ('\n', asm_out_file);
6296 default_coff_asm_named_section (const char *name, unsigned int flags,
6297 tree decl ATTRIBUTE_UNUSED)
6299 char flagchars[8], *f = flagchars;
6301 if (flags & SECTION_WRITE)
6303 if (flags & SECTION_CODE)
6307 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
6311 default_pe_asm_named_section (const char *name, unsigned int flags,
6314 default_coff_asm_named_section (name, flags, decl);
6316 if (flags & SECTION_LINKONCE)
6318 /* Functions may have been compiled at various levels of
6319 optimization so we can't use `same_size' here.
6320 Instead, have the linker pick one. */
6321 fprintf (asm_out_file, "\t.linkonce %s\n",
6322 (flags & SECTION_CODE ? "discard" : "same_size"));
6326 /* The lame default section selector. */
6329 default_select_section (tree decl, int reloc,
6330 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6334 if (decl_readonly_section (decl, reloc))
6335 return readonly_data_section;
6337 else if (TREE_CODE (decl) == CONSTRUCTOR)
6339 if (! ((flag_pic && reloc)
6340 || !TREE_READONLY (decl)
6341 || TREE_SIDE_EFFECTS (decl)
6342 || !TREE_CONSTANT (decl)))
6343 return readonly_data_section;
6345 else if (TREE_CODE (decl) == STRING_CST)
6346 return readonly_data_section;
6347 else if (! (flag_pic && reloc))
6348 return readonly_data_section;
6350 return data_section;
6353 enum section_category
6354 categorize_decl_for_section (const_tree decl, int reloc)
6356 enum section_category ret;
6358 if (TREE_CODE (decl) == FUNCTION_DECL)
6360 else if (TREE_CODE (decl) == STRING_CST)
6362 if (flag_mudflap) /* or !flag_merge_constants */
6363 return SECCAT_RODATA;
6365 return SECCAT_RODATA_MERGE_STR;
6367 else if (TREE_CODE (decl) == VAR_DECL)
6369 if (bss_initializer_p (decl))
6371 else if (! TREE_READONLY (decl)
6372 || TREE_SIDE_EFFECTS (decl)
6373 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6375 /* Here the reloc_rw_mask is not testing whether the section should
6376 be read-only or not, but whether the dynamic link will have to
6377 do something. If so, we wish to segregate the data in order to
6378 minimize cache misses inside the dynamic linker. */
6379 if (reloc & targetm.asm_out.reloc_rw_mask ())
6380 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6384 else if (reloc & targetm.asm_out.reloc_rw_mask ())
6385 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6386 else if (reloc || flag_merge_constants < 2)
6387 /* C and C++ don't allow different variables to share the same
6388 location. -fmerge-all-constants allows even that (at the
6389 expense of not conforming). */
6390 ret = SECCAT_RODATA;
6391 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6392 ret = SECCAT_RODATA_MERGE_STR_INIT;
6394 ret = SECCAT_RODATA_MERGE_CONST;
6396 else if (TREE_CODE (decl) == CONSTRUCTOR)
6398 if ((reloc & targetm.asm_out.reloc_rw_mask ())
6399 || TREE_SIDE_EFFECTS (decl)
6400 || ! TREE_CONSTANT (decl))
6403 ret = SECCAT_RODATA;
6406 ret = SECCAT_RODATA;
6408 /* There are no read-only thread-local sections. */
6409 if (TREE_CODE (decl) == VAR_DECL && DECL_TLS_MODEL (decl))
6411 if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED)
6413 if (DECL_EMUTLS_VAR_P (decl))
6415 if (targetm.emutls.var_section)
6416 ret = SECCAT_EMUTLS_VAR;
6420 if (targetm.emutls.tmpl_prefix)
6421 ret = SECCAT_EMUTLS_TMPL;
6424 /* Note that this would be *just* SECCAT_BSS, except that there's
6425 no concept of a read-only thread-local-data section. */
6426 else if (ret == SECCAT_BSS
6427 || (flag_zero_initialized_in_bss
6428 && initializer_zerop (DECL_INITIAL (decl))))
6434 /* If the target uses small data sections, select it. */
6435 else if (targetm.in_small_data_p (decl))
6437 if (ret == SECCAT_BSS)
6439 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6440 ret = SECCAT_SRODATA;
6449 decl_readonly_section (const_tree decl, int reloc)
6451 switch (categorize_decl_for_section (decl, reloc))
6454 case SECCAT_RODATA_MERGE_STR:
6455 case SECCAT_RODATA_MERGE_STR_INIT:
6456 case SECCAT_RODATA_MERGE_CONST:
6457 case SECCAT_SRODATA:
6466 /* Select a section based on the above categorization. */
6469 default_elf_select_section (tree decl, int reloc,
6470 unsigned HOST_WIDE_INT align)
6473 switch (categorize_decl_for_section (decl, reloc))
6476 /* We're not supposed to be called on FUNCTION_DECLs. */
6479 return readonly_data_section;
6480 case SECCAT_RODATA_MERGE_STR:
6481 return mergeable_string_section (decl, align, 0);
6482 case SECCAT_RODATA_MERGE_STR_INIT:
6483 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6484 case SECCAT_RODATA_MERGE_CONST:
6485 return mergeable_constant_section (DECL_MODE (decl), align, 0);
6486 case SECCAT_SRODATA:
6490 return data_section;
6491 case SECCAT_DATA_REL:
6492 sname = ".data.rel";
6494 case SECCAT_DATA_REL_LOCAL:
6495 sname = ".data.rel.local";
6497 case SECCAT_DATA_REL_RO:
6498 sname = ".data.rel.ro";
6500 case SECCAT_DATA_REL_RO_LOCAL:
6501 sname = ".data.rel.ro.local";
6520 case SECCAT_EMUTLS_VAR:
6521 sname = targetm.emutls.var_section;
6523 case SECCAT_EMUTLS_TMPL:
6524 sname = targetm.emutls.tmpl_section;
6532 return get_named_section (decl, sname, reloc);
6535 /* Construct a unique section name based on the decl name and the
6536 categorization performed above. */
6539 default_unique_section (tree decl, int reloc)
6541 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6542 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6543 const char *prefix, *name, *linkonce;
6546 switch (categorize_decl_for_section (decl, reloc))
6549 prefix = one_only ? ".t" : ".text";
6552 case SECCAT_RODATA_MERGE_STR:
6553 case SECCAT_RODATA_MERGE_STR_INIT:
6554 case SECCAT_RODATA_MERGE_CONST:
6555 prefix = one_only ? ".r" : ".rodata";
6557 case SECCAT_SRODATA:
6558 prefix = one_only ? ".s2" : ".sdata2";
6561 prefix = one_only ? ".d" : ".data";
6563 case SECCAT_DATA_REL:
6564 prefix = one_only ? ".d.rel" : ".data.rel";
6566 case SECCAT_DATA_REL_LOCAL:
6567 prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6569 case SECCAT_DATA_REL_RO:
6570 prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6572 case SECCAT_DATA_REL_RO_LOCAL:
6573 prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6576 prefix = one_only ? ".s" : ".sdata";
6579 prefix = one_only ? ".b" : ".bss";
6582 prefix = one_only ? ".sb" : ".sbss";
6585 prefix = one_only ? ".td" : ".tdata";
6588 prefix = one_only ? ".tb" : ".tbss";
6590 case SECCAT_EMUTLS_VAR:
6591 prefix = targetm.emutls.var_section;
6593 case SECCAT_EMUTLS_TMPL:
6594 prefix = targetm.emutls.tmpl_section;
6600 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6601 name = targetm.strip_name_encoding (name);
6603 /* If we're using one_only, then there needs to be a .gnu.linkonce
6604 prefix to the section name. */
6605 linkonce = one_only ? ".gnu.linkonce" : "";
6607 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6609 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6612 /* Like compute_reloc_for_constant, except for an RTX. The return value
6613 is a mask for which bit 1 indicates a global relocation, and bit 0
6614 indicates a local relocation. */
6617 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6619 int *preloc = (int *) data;
6622 switch (GET_CODE (x))
6625 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6638 compute_reloc_for_rtx (rtx x)
6642 switch (GET_CODE (x))
6648 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6657 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6659 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6661 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6662 return data_section;
6664 return readonly_data_section;
6668 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6669 unsigned HOST_WIDE_INT align)
6671 int reloc = compute_reloc_for_rtx (x);
6673 /* ??? Handle small data here somehow. */
6675 if (reloc & targetm.asm_out.reloc_rw_mask ())
6678 return get_named_section (NULL, ".data.rel.ro.local", 1);
6680 return get_named_section (NULL, ".data.rel.ro", 3);
6683 return mergeable_constant_section (mode, align, 0);
6686 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6689 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6694 /* Careful not to prod global register variables. */
6697 symbol = XEXP (rtl, 0);
6698 if (GET_CODE (symbol) != SYMBOL_REF)
6701 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6702 if (TREE_CODE (decl) == FUNCTION_DECL)
6703 flags |= SYMBOL_FLAG_FUNCTION;
6704 if (targetm.binds_local_p (decl))
6705 flags |= SYMBOL_FLAG_LOCAL;
6706 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)
6707 && DECL_TLS_MODEL (decl) != TLS_MODEL_EMULATED)
6708 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6709 else if (targetm.in_small_data_p (decl))
6710 flags |= SYMBOL_FLAG_SMALL;
6711 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6712 being PUBLIC, the thing *must* be defined in this translation unit.
6713 Prevent this buglet from being propagated into rtl code as well. */
6714 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6715 flags |= SYMBOL_FLAG_EXTERNAL;
6717 SYMBOL_REF_FLAGS (symbol) = flags;
6720 /* By default, we do nothing for encode_section_info, so we need not
6721 do anything but discard the '*' marker. */
6724 default_strip_name_encoding (const char *str)
6726 return str + (*str == '*');
6729 #ifdef ASM_OUTPUT_DEF
6730 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6731 anchor relative to ".", the current section position. */
6734 default_asm_output_anchor (rtx symbol)
6738 sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6739 SYMBOL_REF_BLOCK_OFFSET (symbol));
6740 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6744 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6747 default_use_anchors_for_symbol_p (const_rtx symbol)
6752 /* Don't use anchors for mergeable sections. The linker might move
6753 the objects around. */
6754 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6755 if (sect->common.flags & SECTION_MERGE)
6758 /* Don't use anchors for small data sections. The small data register
6759 acts as an anchor for such sections. */
6760 if (sect->common.flags & SECTION_SMALL)
6763 decl = SYMBOL_REF_DECL (symbol);
6764 if (decl && DECL_P (decl))
6766 /* Don't use section anchors for decls that might be defined by
6768 if (!targetm.binds_local_p (decl))
6771 /* Don't use section anchors for decls that will be placed in a
6772 small data section. */
6773 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6774 one above. The problem is that we only use SECTION_SMALL for
6775 sections that should be marked as small in the section directive. */
6776 if (targetm.in_small_data_p (decl))
6782 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6783 wrt cross-module name binding. */
6786 default_binds_local_p (const_tree exp)
6788 return default_binds_local_p_1 (exp, flag_shlib);
6792 default_binds_local_p_1 (const_tree exp, int shlib)
6796 /* A non-decl is an entry in the constant pool. */
6799 /* Weakrefs may not bind locally, even though the weakref itself is
6800 always static and therefore local. */
6801 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6803 /* Static variables are always local. */
6804 else if (! TREE_PUBLIC (exp))
6806 /* A variable is local if the user has said explicitly that it will
6808 else if (DECL_VISIBILITY_SPECIFIED (exp)
6809 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6811 /* Variables defined outside this object might not be local. */
6812 else if (DECL_EXTERNAL (exp))
6814 /* If defined in this object and visibility is not default, must be
6816 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6818 /* Default visibility weak data can be overridden by a strong symbol
6819 in another module and so are not local. */
6820 else if (DECL_WEAK (exp))
6822 /* If PIC, then assume that any global name can be overridden by
6823 symbols resolved from other modules, unless we are compiling with
6824 -fwhole-program, which assumes that names are local. */
6826 local_p = flag_whole_program;
6827 /* Uninitialized COMMON variable may be unified with symbols
6828 resolved from other modules. */
6829 else if (DECL_COMMON (exp)
6830 && (DECL_INITIAL (exp) == NULL
6831 || DECL_INITIAL (exp) == error_mark_node))
6833 /* Otherwise we're left with initialized (or non-common) global data
6834 which is of necessity defined locally. */
6841 /* Default function to output code that will globalize a label. A
6842 target must define GLOBAL_ASM_OP or provide its own function to
6843 globalize a label. */
6844 #ifdef GLOBAL_ASM_OP
6846 default_globalize_label (FILE * stream, const char *name)
6848 fputs (GLOBAL_ASM_OP, stream);
6849 assemble_name (stream, name);
6850 putc ('\n', stream);
6852 #endif /* GLOBAL_ASM_OP */
6854 /* Default function to output code that will globalize a declaration. */
6856 default_globalize_decl_name (FILE * stream, tree decl)
6858 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6859 targetm.asm_out.globalize_label (stream, name);
6862 /* Default function to output a label for unwind information. The
6863 default is to do nothing. A target that needs nonlocal labels for
6864 unwind information must provide its own function to do this. */
6866 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6867 tree decl ATTRIBUTE_UNUSED,
6868 int for_eh ATTRIBUTE_UNUSED,
6869 int empty ATTRIBUTE_UNUSED)
6873 /* Default function to output a label to divide up the exception table.
6874 The default is to do nothing. A target that needs/wants to divide
6875 up the table must provide it's own function to do this. */
6877 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6881 /* This is how to output an internal numbered label where PREFIX is
6882 the class of label and LABELNO is the number within the class. */
6885 default_internal_label (FILE *stream, const char *prefix,
6886 unsigned long labelno)
6888 char *const buf = (char *) alloca (40 + strlen (prefix));
6889 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6890 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6894 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6897 default_asm_declare_constant_name (FILE *file, const char *name,
6898 const_tree exp ATTRIBUTE_UNUSED,
6899 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
6901 assemble_label (file, name);
6904 /* This is the default behavior at the beginning of a file. It's
6905 controlled by two other target-hook toggles. */
6907 default_file_start (void)
6909 if (targetm.asm_file_start_app_off
6910 && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
6911 fputs (ASM_APP_OFF, asm_out_file);
6913 if (targetm.asm_file_start_file_directive)
6914 output_file_directive (asm_out_file, main_input_filename);
6917 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6918 which emits a special section directive used to indicate whether or
6919 not this object file needs an executable stack. This is primarily
6920 a GNU extension to ELF but could be used on other targets. */
6922 int trampolines_created;
6925 file_end_indicate_exec_stack (void)
6927 unsigned int flags = SECTION_DEBUG;
6928 if (trampolines_created)
6929 flags |= SECTION_CODE;
6931 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
6934 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6935 a get_unnamed_section callback. */
6938 output_section_asm_op (const void *directive)
6940 fprintf (asm_out_file, "%s\n", (const char *) directive);
6943 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6944 the current section is NEW_SECTION. */
6947 switch_to_section (section *new_section)
6949 if (in_section == new_section)
6952 if (new_section->common.flags & SECTION_FORGET)
6955 in_section = new_section;
6957 switch (SECTION_STYLE (new_section))
6961 && !crtl->subsections.unlikely_text_section_name
6962 && strcmp (new_section->named.name,
6963 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6964 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6966 targetm.asm_out.named_section (new_section->named.name,
6967 new_section->named.common.flags,
6968 new_section->named.decl);
6971 case SECTION_UNNAMED:
6972 new_section->unnamed.callback (new_section->unnamed.data);
6975 case SECTION_NOSWITCH:
6980 new_section->common.flags |= SECTION_DECLARED;
6983 /* If block symbol SYMBOL has not yet been assigned an offset, place
6984 it at the end of its block. */
6987 place_block_symbol (rtx symbol)
6989 unsigned HOST_WIDE_INT size, mask, offset;
6990 struct constant_descriptor_rtx *desc;
6991 unsigned int alignment;
6992 struct object_block *block;
6995 gcc_assert (SYMBOL_REF_BLOCK (symbol));
6996 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6999 /* Work out the symbol's size and alignment. */
7000 if (CONSTANT_POOL_ADDRESS_P (symbol))
7002 desc = SYMBOL_REF_CONSTANT (symbol);
7003 alignment = desc->align;
7004 size = GET_MODE_SIZE (desc->mode);
7006 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7008 decl = SYMBOL_REF_DECL (symbol);
7009 alignment = DECL_ALIGN (decl);
7010 size = get_constant_size (DECL_INITIAL (decl));
7014 decl = SYMBOL_REF_DECL (symbol);
7015 alignment = DECL_ALIGN (decl);
7016 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7019 /* Calculate the object's offset from the start of the block. */
7020 block = SYMBOL_REF_BLOCK (symbol);
7021 mask = alignment / BITS_PER_UNIT - 1;
7022 offset = (block->size + mask) & ~mask;
7023 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
7025 /* Record the block's new alignment and size. */
7026 block->alignment = MAX (block->alignment, alignment);
7027 block->size = offset + size;
7029 VEC_safe_push (rtx, gc, block->objects, symbol);
7032 /* Return the anchor that should be used to address byte offset OFFSET
7033 from the first object in BLOCK. MODEL is the TLS model used
7037 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
7038 enum tls_model model)
7041 unsigned int begin, middle, end;
7042 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
7045 /* Work out the anchor's offset. Use an offset of 0 for the first
7046 anchor so that we don't pessimize the case where we take the address
7047 of a variable at the beginning of the block. This is particularly
7048 useful when a block has only one variable assigned to it.
7050 We try to place anchors RANGE bytes apart, so there can then be
7051 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7052 a ptr_mode offset. With some target settings, the lowest such
7053 anchor might be out of range for the lowest ptr_mode offset;
7054 likewise the highest anchor for the highest offset. Use anchors
7055 at the extreme ends of the ptr_mode range in such cases.
7057 All arithmetic uses unsigned integers in order to avoid
7059 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
7060 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
7061 range = max_offset - min_offset + 1;
7066 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
7069 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
7070 delta -= delta % range;
7073 offset = (HOST_WIDE_INT) (-delta);
7077 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
7078 delta -= delta % range;
7079 if (delta > bias - 1)
7081 offset = (HOST_WIDE_INT) delta;
7085 /* Do a binary search to see if there's already an anchor we can use.
7086 Set BEGIN to the new anchor's index if not. */
7088 end = VEC_length (rtx, block->anchors);
7089 while (begin != end)
7091 middle = (end + begin) / 2;
7092 anchor = VEC_index (rtx, block->anchors, middle);
7093 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
7095 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
7097 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
7099 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
7105 /* Create a new anchor with a unique label. */
7106 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
7107 anchor = create_block_symbol (ggc_strdup (label), block, offset);
7108 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
7109 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
7111 /* Insert it at index BEGIN. */
7112 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
7116 /* Output the objects in BLOCK. */
7119 output_object_block (struct object_block *block)
7121 struct constant_descriptor_rtx *desc;
7123 HOST_WIDE_INT offset;
7127 if (block->objects == NULL)
7130 /* Switch to the section and make sure that the first byte is
7131 suitably aligned. */
7132 switch_to_section (block->sect);
7133 assemble_align (block->alignment);
7135 /* Define the values of all anchors relative to the current section
7137 for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
7138 targetm.asm_out.output_anchor (symbol);
7140 /* Output the objects themselves. */
7142 for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
7144 /* Move to the object's offset, padding with zeros if necessary. */
7145 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
7146 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
7147 if (CONSTANT_POOL_ADDRESS_P (symbol))
7149 desc = SYMBOL_REF_CONSTANT (symbol);
7150 output_constant_pool_1 (desc, 1);
7151 offset += GET_MODE_SIZE (desc->mode);
7153 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7155 decl = SYMBOL_REF_DECL (symbol);
7156 assemble_constant_contents (DECL_INITIAL (decl), XSTR (symbol, 0),
7158 offset += get_constant_size (DECL_INITIAL (decl));
7162 decl = SYMBOL_REF_DECL (symbol);
7163 assemble_variable_contents (decl, XSTR (symbol, 0), false);
7164 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7169 /* A htab_traverse callback used to call output_object_block for
7170 each member of object_block_htab. */
7173 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
7175 output_object_block ((struct object_block *) (*slot));
7179 /* Output the definitions of all object_blocks. */
7182 output_object_blocks (void)
7184 htab_traverse (object_block_htab, output_object_block_htab, NULL);
7187 /* This function provides a possible implementation of the
7188 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7189 by -frecord-gcc-switches it creates a new mergeable, string section in the
7190 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7191 contains the switches in ASCII format.
7193 FIXME: This code does not correctly handle double quote characters
7194 that appear inside strings, (it strips them rather than preserving them).
7195 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7196 characters - instead it treats them as sub-string separators. Since
7197 we want to emit NUL strings terminators into the object file we have to use
7201 elf_record_gcc_switches (print_switch_type type, const char * name)
7205 case SWITCH_TYPE_PASSED:
7206 ASM_OUTPUT_ASCII (asm_out_file, name, strlen (name));
7207 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7210 case SWITCH_TYPE_DESCRIPTIVE:
7213 /* Distinguish between invocations where name is NULL. */
7214 static bool started = false;
7220 sec = get_section (targetm.asm_out.record_gcc_switches_section,
7224 | (SECTION_ENTSIZE & 1),
7226 switch_to_section (sec);
7235 /* The return value is currently ignored by the caller, but must be 0.
7236 For -fverbose-asm the return value would be the number of characters
7237 emitted into the assembler file. */
7241 /* Emit text to declare externally defined symbols. It is needed to
7242 properly support non-default visibility. */
7244 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
7246 const char *name ATTRIBUTE_UNUSED)
7248 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7249 set in order to avoid putting out names that are never really
7251 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
7252 && targetm.binds_local_p (decl))
7253 maybe_assemble_visibility (decl);
7256 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7259 make_debug_expr_from_rtl (const_rtx exp)
7261 tree ddecl = make_node (DEBUG_EXPR_DECL), type;
7262 enum machine_mode mode = GET_MODE (exp);
7265 DECL_ARTIFICIAL (ddecl) = 1;
7266 if (REG_P (exp) && REG_EXPR (exp))
7267 type = TREE_TYPE (REG_EXPR (exp));
7268 else if (MEM_P (exp) && MEM_EXPR (exp))
7269 type = TREE_TYPE (MEM_EXPR (exp));
7272 if (type && TYPE_MODE (type) == mode)
7273 TREE_TYPE (ddecl) = type;
7275 TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
7276 DECL_MODE (ddecl) = mode;
7277 dval = gen_rtx_DEBUG_EXPR (mode);
7278 DEBUG_EXPR_TREE_DECL (dval) = ddecl;
7279 SET_DECL_RTL (ddecl, dval);
7283 #include "gt-varasm.h"