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"
45 #include "langhooks.h"
49 #include "targhooks.h"
50 #include "tree-mudflap.h"
52 #include "cfglayout.h"
53 #include "basic-block.h"
54 #include "tree-iterator.h"
56 #ifdef XCOFF_DEBUGGING_INFO
57 #include "xcoffout.h" /* Needed for external data
58 declarations for e.g. AIX 4.x. */
61 /* The (assembler) name of the first globally-visible object output. */
62 extern GTY(()) const char *first_global_object_name;
63 extern GTY(()) const char *weak_global_object_name;
65 const char *first_global_object_name;
66 const char *weak_global_object_name;
69 struct constant_descriptor_rtx;
70 struct rtx_constant_pool;
72 #define n_deferred_constants (crtl->varasm.deferred_constants)
74 /* Number for making the label on the next
75 constant that is stored in memory. */
77 static GTY(()) int const_labelno;
79 /* Carry information from ASM_DECLARE_OBJECT_NAME
80 to ASM_FINISH_DECLARE_OBJECT. */
82 int size_directive_output;
84 /* The last decl for which assemble_variable was called,
85 if it did ASM_DECLARE_OBJECT_NAME.
86 If the last call to assemble_variable didn't do that,
89 tree last_assemble_variable_decl;
91 /* The following global variable indicates if the first basic block
92 in a function belongs to the cold partition or not. */
94 bool first_function_block_is_cold;
96 /* We give all constants their own alias set. Perhaps redundant with
97 MEM_READONLY_P, but pre-dates it. */
99 static alias_set_type const_alias_set;
101 static const char *strip_reg_name (const char *);
102 static int contains_pointers_p (tree);
103 #ifdef ASM_OUTPUT_EXTERNAL
104 static bool incorporeal_function_p (tree);
106 static void decode_addr_const (tree, struct addr_const *);
107 static hashval_t const_desc_hash (const void *);
108 static int const_desc_eq (const void *, const void *);
109 static hashval_t const_hash_1 (const tree);
110 static int compare_constant (const tree, const tree);
111 static tree copy_constant (tree);
112 static void output_constant_def_contents (rtx);
113 static void output_addressed_constants (tree);
114 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
115 static unsigned min_align (unsigned, unsigned);
116 static void globalize_decl (tree);
117 #ifdef BSS_SECTION_ASM_OP
118 #ifdef ASM_OUTPUT_BSS
119 static void asm_output_bss (FILE *, tree, const char *,
120 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
122 #ifdef ASM_OUTPUT_ALIGNED_BSS
123 static void asm_output_aligned_bss (FILE *, tree, const char *,
124 unsigned HOST_WIDE_INT, int)
127 #endif /* BSS_SECTION_ASM_OP */
128 static void mark_weak (tree);
129 static void output_constant_pool (const char *, tree);
131 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
132 section *text_section;
133 section *data_section;
134 section *readonly_data_section;
135 section *sdata_section;
136 section *ctors_section;
137 section *dtors_section;
138 section *bss_section;
139 section *sbss_section;
141 /* Various forms of common section. All are guaranteed to be nonnull. */
142 section *tls_comm_section;
143 section *comm_section;
144 section *lcomm_section;
146 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
148 section *bss_noswitch_section;
150 /* The section that holds the main exception table, when known. The section
151 is set either by the target's init_sections hook or by the first call to
152 switch_to_exception_section. */
153 section *exception_section;
155 /* The section that holds the DWARF2 frame unwind information, when known.
156 The section is set either by the target's init_sections hook or by the
157 first call to switch_to_eh_frame_section. */
158 section *eh_frame_section;
160 /* asm_out_file's current section. This is NULL if no section has yet
161 been selected or if we lose track of what the current section is. */
164 /* True if code for the current function is currently being directed
165 at the cold section. */
166 bool in_cold_section_p;
168 /* A linked list of all the unnamed sections. */
169 static GTY(()) section *unnamed_sections;
171 /* Return a nonzero value if DECL has a section attribute. */
172 #define IN_NAMED_SECTION(DECL) \
173 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
174 && DECL_SECTION_NAME (DECL) != NULL_TREE)
176 /* Hash table of named sections. */
177 static GTY((param_is (section))) htab_t section_htab;
179 /* A table of object_blocks, indexed by section. */
180 static GTY((param_is (struct object_block))) htab_t object_block_htab;
182 /* The next number to use for internal anchor labels. */
183 static GTY(()) int anchor_labelno;
185 /* A pool of constants that can be shared between functions. */
186 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
190 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
192 static GTY (()) tree emutls_object_type;
193 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
194 macro can be used on them to distinguish the control variable from
195 the initialization template. */
196 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
198 #if !defined (NO_DOT_IN_LABEL)
199 # define EMUTLS_SEPARATOR "."
200 #elif !defined (NO_DOLLAR_IN_LABEL)
201 # define EMUTLS_SEPARATOR "$"
203 # define EMUTLS_SEPARATOR "_"
206 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
207 IDENTIFIER_NODE NAME's name. */
210 prefix_name (const char *prefix, tree name)
212 unsigned plen = strlen (prefix);
213 unsigned nlen = strlen (IDENTIFIER_POINTER (name));
214 char *toname = (char *) alloca (plen + nlen + 1);
216 memcpy (toname, prefix, plen);
217 memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
219 return get_identifier (toname);
222 /* Create an identifier for the struct __emutls_object, given an identifier
223 of the DECL_ASSEMBLY_NAME of the original object. */
226 get_emutls_object_name (tree name)
228 const char *prefix = (targetm.emutls.var_prefix
229 ? targetm.emutls.var_prefix
230 : "__emutls_v" EMUTLS_SEPARATOR);
231 return prefix_name (prefix, name);
235 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
237 tree word_type_node, field, next_field;
239 field = build_decl (UNKNOWN_LOCATION,
240 FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
241 DECL_CONTEXT (field) = type;
244 field = build_decl (UNKNOWN_LOCATION,
245 FIELD_DECL, get_identifier ("__offset"),
247 DECL_CONTEXT (field) = type;
248 TREE_CHAIN (field) = next_field;
251 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
252 field = build_decl (UNKNOWN_LOCATION,
253 FIELD_DECL, get_identifier ("__align"),
255 DECL_CONTEXT (field) = type;
256 TREE_CHAIN (field) = next_field;
259 field = build_decl (UNKNOWN_LOCATION,
260 FIELD_DECL, get_identifier ("__size"), word_type_node);
261 DECL_CONTEXT (field) = type;
262 TREE_CHAIN (field) = next_field;
267 /* Create the structure for struct __emutls_object. This should match the
268 structure at the top of emutls.c, modulo the union there. */
271 get_emutls_object_type (void)
273 tree type, type_name, field;
275 type = emutls_object_type;
279 emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
281 field = targetm.emutls.var_fields (type, &type_name);
283 type_name = get_identifier ("__emutls_object");
284 type_name = build_decl (UNKNOWN_LOCATION,
285 TYPE_DECL, type_name, type);
286 TYPE_NAME (type) = type_name;
287 TYPE_FIELDS (type) = field;
293 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
294 This will be used for initializing the emulated tls data area. */
297 get_emutls_init_templ_addr (tree decl)
301 if (targetm.emutls.register_common && !DECL_INITIAL (decl)
302 && !DECL_SECTION_NAME (decl))
303 return null_pointer_node;
305 name = DECL_ASSEMBLER_NAME (decl);
306 if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0])
308 const char *prefix = (targetm.emutls.tmpl_prefix
309 ? targetm.emutls.tmpl_prefix
310 : "__emutls_t" EMUTLS_SEPARATOR);
311 name = prefix_name (prefix, name);
314 to = build_decl (DECL_SOURCE_LOCATION (decl),
315 VAR_DECL, name, TREE_TYPE (decl));
316 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
318 DECL_ARTIFICIAL (to) = 1;
319 TREE_USED (to) = TREE_USED (decl);
320 TREE_READONLY (to) = 1;
321 DECL_IGNORED_P (to) = 1;
322 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
323 DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
324 DECL_PRESERVE_P (to) = DECL_PRESERVE_P (decl);
326 DECL_WEAK (to) = DECL_WEAK (decl);
327 if (DECL_ONE_ONLY (decl))
329 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
330 TREE_STATIC (to) = TREE_STATIC (decl);
331 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
332 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
335 TREE_STATIC (to) = 1;
337 DECL_VISIBILITY_SPECIFIED (to) = DECL_VISIBILITY_SPECIFIED (decl);
338 DECL_INITIAL (to) = DECL_INITIAL (decl);
339 DECL_INITIAL (decl) = NULL;
341 varpool_finalize_decl (to);
342 return build_fold_addr_expr (to);
345 /* When emulating tls, we use a control structure for use by the runtime.
346 Create and return this structure. */
349 emutls_decl (tree decl)
352 struct tree_map *h, in;
355 if (targetm.have_tls || decl == NULL || decl == error_mark_node
356 || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
359 /* Look up the object in the hash; return the control structure if
360 it has already been created. */
362 emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
364 name = DECL_ASSEMBLER_NAME (decl);
366 /* Note that we use the hash of the decl's name, rather than a hash
367 of the decl's pointer. In emutls_finish we iterate through the
368 hash table, and we want this traversal to be predictable. */
369 in.hash = IDENTIFIER_HASH_VALUE (name);
371 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
372 h = (struct tree_map *) *loc;
377 to = build_decl (DECL_SOURCE_LOCATION (decl),
378 VAR_DECL, get_emutls_object_name (name),
379 get_emutls_object_type ());
381 h = GGC_NEW (struct tree_map);
385 *(struct tree_map **) loc = h;
387 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
388 DECL_ARTIFICIAL (to) = 1;
389 DECL_IGNORED_P (to) = 1;
390 /* FIXME: work around PR44132. */
391 DECL_PRESERVE_P (to) = 1;
392 TREE_READONLY (to) = 0;
393 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
394 if (DECL_ONE_ONLY (decl))
395 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
396 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
397 if (targetm.emutls.var_align_fixed)
398 /* If we're not allowed to change the proxy object's
399 alignment, pretend it's been set by the user. */
400 DECL_USER_ALIGN (to) = 1;
403 /* Note that these fields may need to be updated from time to time from
404 the original decl. Consider:
405 extern __thread int i;
406 int foo() { return i; }
408 in which I goes from external to locally defined and initialized. */
409 DECL_DLLIMPORT_P (to) = DECL_DLLIMPORT_P (decl);
410 DECL_ATTRIBUTES (to) = targetm.merge_decl_attributes (decl, to);
412 TREE_STATIC (to) = TREE_STATIC (decl);
413 TREE_USED (to) = TREE_USED (decl);
414 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
415 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
416 DECL_COMMON (to) = DECL_COMMON (decl);
417 DECL_WEAK (to) = DECL_WEAK (decl);
418 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
419 DECL_VISIBILITY_SPECIFIED (to) = DECL_VISIBILITY_SPECIFIED (decl);
421 /* Fortran might pass this to us. */
422 DECL_RESTRICTED_P (to) = DECL_RESTRICTED_P (decl);
428 emutls_common_1 (void **loc, void *xstmts)
430 struct tree_map *h = *(struct tree_map **) loc;
431 tree args, x, *pstmts = (tree *) xstmts;
434 if (! DECL_COMMON (h->base.from)
435 || (DECL_INITIAL (h->base.from)
436 && DECL_INITIAL (h->base.from) != error_mark_node))
439 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
441 /* The idea was to call get_emutls_init_templ_addr here, but if we
442 do this and there is an initializer, -fanchor_section loses,
443 because it would be too late to ensure the template is
445 x = null_pointer_node;
446 args = tree_cons (NULL, x, NULL);
447 x = build_int_cst (word_type_node, DECL_ALIGN_UNIT (h->base.from));
448 args = tree_cons (NULL, x, args);
449 x = fold_convert (word_type_node, DECL_SIZE_UNIT (h->base.from));
450 args = tree_cons (NULL, x, args);
451 x = build_fold_addr_expr (h->to);
452 args = tree_cons (NULL, x, args);
454 x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
455 x = build_function_call_expr (UNKNOWN_LOCATION, x, args);
457 append_to_statement_list (x, pstmts);
461 /* Callback to finalize one emutls control variable. */
464 emutls_finalize_control_var (void **loc,
465 void *unused ATTRIBUTE_UNUSED)
467 struct tree_map *h = *(struct tree_map **) loc;
470 struct varpool_node *node = varpool_node (h->to);
471 /* Because varpool_finalize_decl () has side-effects,
472 only apply to un-finalized vars. */
473 if (node && !node->finalized)
474 varpool_finalize_decl (h->to);
479 /* Finalize emutls control vars and add a static constructor if
485 if (emutls_htab == NULL)
487 htab_traverse_noresize (emutls_htab,
488 emutls_finalize_control_var, NULL);
490 if (targetm.emutls.register_common)
492 tree body = NULL_TREE;
494 htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
495 if (body == NULL_TREE)
498 cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
502 /* Helper routines for maintaining section_htab. */
505 section_entry_eq (const void *p1, const void *p2)
507 const section *old = (const section *) p1;
508 const char *new_name = (const char *) p2;
510 return strcmp (old->named.name, new_name) == 0;
514 section_entry_hash (const void *p)
516 const section *old = (const section *) p;
517 return htab_hash_string (old->named.name);
520 /* Return a hash value for section SECT. */
523 hash_section (section *sect)
525 if (sect->common.flags & SECTION_NAMED)
526 return htab_hash_string (sect->named.name);
527 return sect->common.flags;
530 /* Helper routines for maintaining object_block_htab. */
533 object_block_entry_eq (const void *p1, const void *p2)
535 const struct object_block *old = (const struct object_block *) p1;
536 const section *new_section = (const section *) p2;
538 return old->sect == new_section;
542 object_block_entry_hash (const void *p)
544 const struct object_block *old = (const struct object_block *) p;
545 return hash_section (old->sect);
548 /* Return a new unnamed section with the given fields. */
551 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
556 sect = GGC_NEW (section);
557 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
558 sect->unnamed.callback = callback;
559 sect->unnamed.data = data;
560 sect->unnamed.next = unnamed_sections;
562 unnamed_sections = sect;
566 /* Return a SECTION_NOSWITCH section with the given fields. */
569 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
573 sect = GGC_NEW (section);
574 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
575 sect->noswitch.callback = callback;
580 /* Return the named section structure associated with NAME. Create
581 a new section with the given fields if no such structure exists. */
584 get_section (const char *name, unsigned int flags, tree decl)
586 section *sect, **slot;
589 htab_find_slot_with_hash (section_htab, name,
590 htab_hash_string (name), INSERT);
591 flags |= SECTION_NAMED;
594 sect = GGC_NEW (section);
595 sect->named.common.flags = flags;
596 sect->named.name = ggc_strdup (name);
597 sect->named.decl = decl;
603 if ((sect->common.flags & ~SECTION_DECLARED) != flags
604 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
606 /* Sanity check user variables for flag changes. */
608 decl = sect->named.decl;
610 error ("%+D causes a section type conflict", decl);
616 /* Return true if the current compilation mode benefits from having
617 objects grouped into blocks. */
620 use_object_blocks_p (void)
622 return flag_section_anchors;
625 /* Return the object_block structure for section SECT. Create a new
626 structure if we haven't created one already. Return null if SECT
629 static struct object_block *
630 get_block_for_section (section *sect)
632 struct object_block *block;
638 slot = htab_find_slot_with_hash (object_block_htab, sect,
639 hash_section (sect), INSERT);
640 block = (struct object_block *) *slot;
643 block = (struct object_block *)
644 ggc_alloc_cleared (sizeof (struct 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 = (rtx) ggc_alloc_zone (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_LABEL (asm_out_file, fnname);
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 (const char *name)
2467 ASM_OUTPUT_LABEL (asm_out_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_NEW (struct 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 #ifdef ASM_DECLARE_CONSTANT_NAME
3480 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
3482 /* Standard thing is just output label for the constant. */
3483 ASM_OUTPUT_LABEL (asm_out_file, label);
3484 #endif /* ASM_DECLARE_CONSTANT_NAME */
3486 /* Output the value of EXP. */
3487 output_constant (exp, size, align);
3490 /* We must output the constant data referred to by SYMBOL; do so. */
3493 output_constant_def_contents (rtx symbol)
3495 tree decl = SYMBOL_REF_DECL (symbol);
3496 tree exp = DECL_INITIAL (decl);
3499 /* Make sure any other constants whose addresses appear in EXP
3500 are assigned label numbers. */
3501 output_addressed_constants (exp);
3503 /* We are no longer deferring this constant. */
3504 TREE_ASM_WRITTEN (exp) = 1;
3506 /* If the constant is part of an object block, make sure that the
3507 decl has been positioned within its block, but do not write out
3508 its definition yet. output_object_blocks will do that later. */
3509 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3510 place_block_symbol (symbol);
3513 align = DECL_ALIGN (decl);
3514 switch_to_section (get_constant_section (exp, align));
3515 if (align > BITS_PER_UNIT)
3516 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3517 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3520 mudflap_enqueue_constant (exp);
3523 /* Look up EXP in the table of constant descriptors. Return the rtl
3524 if it has been emitted, else null. */
3527 lookup_constant_def (tree exp)
3529 struct constant_descriptor_tree *desc;
3530 struct constant_descriptor_tree key;
3533 key.hash = const_hash_1 (exp);
3534 desc = (struct constant_descriptor_tree *)
3535 htab_find_with_hash (const_desc_htab, &key, key.hash);
3537 return (desc ? desc->rtl : NULL_RTX);
3540 /* Return a tree representing a reference to constant data in memory
3541 for the constant expression EXP.
3543 This is the counterpart of output_constant_def at the Tree level. */
3546 tree_output_constant_def (tree exp)
3548 struct constant_descriptor_tree *desc, key;
3552 /* Look up EXP in the table of constant descriptors. If we didn't find
3553 it, create a new one. */
3555 key.hash = const_hash_1 (exp);
3556 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3558 desc = (struct constant_descriptor_tree *) *loc;
3561 desc = build_constant_desc (exp);
3562 desc->hash = key.hash;
3566 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3567 varpool_finalize_decl (decl);
3571 /* Used in the hash tables to avoid outputting the same constant
3572 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3573 are output once per function, not once per file. */
3574 /* ??? Only a few targets need per-function constant pools. Most
3575 can use one per-file pool. Should add a targetm bit to tell the
3578 struct GTY(()) rtx_constant_pool {
3579 /* Pointers to first and last constant in pool, as ordered by offset. */
3580 struct constant_descriptor_rtx *first;
3581 struct constant_descriptor_rtx *last;
3583 /* Hash facility for making memory-constants from constant rtl-expressions.
3584 It is used on RISC machines where immediate integer arguments and
3585 constant addresses are restricted so that such constants must be stored
3587 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3589 /* Current offset in constant pool (does not include any
3590 machine-specific header). */
3591 HOST_WIDE_INT offset;
3594 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3595 struct constant_descriptor_rtx *next;
3599 HOST_WIDE_INT offset;
3601 enum machine_mode mode;
3607 /* Hash and compare functions for const_rtx_htab. */
3610 const_desc_rtx_hash (const void *ptr)
3612 const struct constant_descriptor_rtx *const desc
3613 = (const struct constant_descriptor_rtx *) ptr;
3618 const_desc_rtx_eq (const void *a, const void *b)
3620 const struct constant_descriptor_rtx *const x
3621 = (const struct constant_descriptor_rtx *) a;
3622 const struct constant_descriptor_rtx *const y
3623 = (const struct constant_descriptor_rtx *) b;
3625 if (x->mode != y->mode)
3627 return rtx_equal_p (x->constant, y->constant);
3630 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3633 const_rtx_hash_1 (rtx *xp, void *data)
3635 unsigned HOST_WIDE_INT hwi;
3636 enum machine_mode mode;
3642 code = GET_CODE (x);
3643 mode = GET_MODE (x);
3644 h = (hashval_t) code * 1048573 + mode;
3652 int shift = sizeof (hashval_t) * CHAR_BIT;
3653 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3656 h ^= (hashval_t) hwi;
3657 for (i = 1; i < n; ++i)
3660 h ^= (hashval_t) hwi;
3666 if (mode == VOIDmode)
3668 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3672 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3676 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3682 for (i = XVECLEN (x, 0); i-- > 0; )
3683 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3688 h ^= htab_hash_string (XSTR (x, 0));
3692 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3696 case UNSPEC_VOLATILE:
3697 h = h * 251 + XINT (x, 1);
3704 hp = (hashval_t *) data;
3705 *hp = *hp * 509 + h;
3709 /* Compute a hash value for X, which should be a constant. */
3712 const_rtx_hash (rtx x)
3715 for_each_rtx (&x, const_rtx_hash_1, &h);
3720 /* Create and return a new rtx constant pool. */
3722 static struct rtx_constant_pool *
3723 create_constant_pool (void)
3725 struct rtx_constant_pool *pool;
3727 pool = GGC_NEW (struct rtx_constant_pool);
3728 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3729 const_desc_rtx_eq, NULL);
3736 /* Initialize constant pool hashing for a new function. */
3739 init_varasm_status (void)
3741 crtl->varasm.pool = create_constant_pool ();
3742 crtl->varasm.deferred_constants = 0;
3745 /* Given a MINUS expression, simplify it if both sides
3746 include the same symbol. */
3749 simplify_subtraction (rtx x)
3751 rtx r = simplify_rtx (x);
3755 /* Given a constant rtx X, make (or find) a memory constant for its value
3756 and return a MEM rtx to refer to it in memory. */
3759 force_const_mem (enum machine_mode mode, rtx x)
3761 struct constant_descriptor_rtx *desc, tmp;
3762 struct rtx_constant_pool *pool;
3769 /* If we're not allowed to drop X into the constant pool, don't. */
3770 if (targetm.cannot_force_const_mem (x))
3773 /* Record that this function has used a constant pool entry. */
3774 crtl->uses_const_pool = 1;
3776 /* Decide which pool to use. */
3777 pool = (targetm.use_blocks_for_constant_p (mode, x)
3778 ? shared_constant_pool
3779 : crtl->varasm.pool);
3781 /* Lookup the value in the hashtable. */
3784 hash = const_rtx_hash (x);
3785 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3786 desc = (struct constant_descriptor_rtx *) *slot;
3788 /* If the constant was already present, return its memory. */
3790 return copy_rtx (desc->mem);
3792 /* Otherwise, create a new descriptor. */
3793 desc = GGC_NEW (struct constant_descriptor_rtx);
3796 /* Align the location counter as required by EXP's data type. */
3797 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3798 #ifdef CONSTANT_ALIGNMENT
3800 tree type = lang_hooks.types.type_for_mode (mode, 0);
3801 if (type != NULL_TREE)
3802 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3806 pool->offset += (align / BITS_PER_UNIT) - 1;
3807 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3810 desc->constant = tmp.constant;
3811 desc->offset = pool->offset;
3814 desc->align = align;
3815 desc->labelno = const_labelno;
3818 pool->offset += GET_MODE_SIZE (mode);
3820 pool->last->next = desc;
3822 pool->first = pool->last = desc;
3825 /* Create a string containing the label name, in LABEL. */
3826 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3829 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3830 the constants pool. */
3831 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3833 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3834 symbol = create_block_symbol (ggc_strdup (label),
3835 get_block_for_section (sect), -1);
3838 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3840 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3841 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3842 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3844 /* Construct the MEM. */
3845 desc->mem = def = gen_const_mem (mode, symbol);
3846 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3847 set_mem_align (def, align);
3849 /* If we're dropping a label to the constant pool, make sure we
3851 if (GET_CODE (x) == LABEL_REF)
3852 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3854 return copy_rtx (def);
3857 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3860 get_pool_constant (rtx addr)
3862 return SYMBOL_REF_CONSTANT (addr)->constant;
3865 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3866 and whether it has been output or not. */
3869 get_pool_constant_mark (rtx addr, bool *pmarked)
3871 struct constant_descriptor_rtx *desc;
3873 desc = SYMBOL_REF_CONSTANT (addr);
3874 *pmarked = (desc->mark != 0);
3875 return desc->constant;
3878 /* Similar, return the mode. */
3881 get_pool_mode (const_rtx addr)
3883 return SYMBOL_REF_CONSTANT (addr)->mode;
3886 /* Return the size of the constant pool. */
3889 get_pool_size (void)
3891 return crtl->varasm.pool->offset;
3894 /* Worker function for output_constant_pool_1. Emit assembly for X
3895 in MODE with known alignment ALIGN. */
3898 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3900 switch (GET_MODE_CLASS (mode))
3903 case MODE_DECIMAL_FLOAT:
3907 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3908 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3909 assemble_real (r, mode, align);
3914 case MODE_PARTIAL_INT:
3919 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3922 case MODE_VECTOR_FLOAT:
3923 case MODE_VECTOR_INT:
3924 case MODE_VECTOR_FRACT:
3925 case MODE_VECTOR_UFRACT:
3926 case MODE_VECTOR_ACCUM:
3927 case MODE_VECTOR_UACCUM:
3930 enum machine_mode submode = GET_MODE_INNER (mode);
3931 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3933 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3934 units = CONST_VECTOR_NUNITS (x);
3936 for (i = 0; i < units; i++)
3938 rtx elt = CONST_VECTOR_ELT (x, i);
3939 output_constant_pool_2 (submode, elt, i ? subalign : align);
3949 /* Worker function for output_constant_pool. Emit constant DESC,
3950 giving it ALIGN bits of alignment. */
3953 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3960 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3961 whose CODE_LABEL has been deleted. This can occur if a jump table
3962 is eliminated by optimization. If so, write a constant of zero
3963 instead. Note that this can also happen by turning the
3964 CODE_LABEL into a NOTE. */
3965 /* ??? This seems completely and utterly wrong. Certainly it's
3966 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3967 functioning even with INSN_DELETED_P and friends. */
3970 switch (GET_CODE (tmp))
3973 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3974 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3976 tmp = XEXP (XEXP (tmp, 0), 0);
3980 tmp = XEXP (tmp, 0);
3981 gcc_assert (!INSN_DELETED_P (tmp));
3982 gcc_assert (!NOTE_P (tmp)
3983 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3990 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3991 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3992 align, desc->labelno, done);
3995 assemble_align (align);
3997 /* Output the label. */
3998 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
4000 /* Output the data. */
4001 output_constant_pool_2 (desc->mode, x, align);
4003 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
4004 sections have proper size. */
4005 if (align > GET_MODE_BITSIZE (desc->mode)
4007 && (in_section->common.flags & SECTION_MERGE))
4008 assemble_align (align);
4010 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4016 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4017 to as used. Emit referenced deferred strings. This function can
4018 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4021 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
4023 rtx x = *current_rtx;
4025 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
4028 if (CONSTANT_POOL_ADDRESS_P (x))
4030 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
4031 if (desc->mark == 0)
4034 for_each_rtx (&desc->constant, mark_constant, NULL);
4037 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
4039 tree decl = SYMBOL_REF_DECL (x);
4040 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
4042 n_deferred_constants--;
4043 output_constant_def_contents (x);
4050 /* Look through appropriate parts of INSN, marking all entries in the
4051 constant pool which are actually being used. Entries that are only
4052 referenced by other constants are also marked as used. Emit
4053 deferred strings that are used. */
4056 mark_constants (rtx insn)
4061 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4062 insns, not any notes that may be attached. We don't want to mark
4063 a constant just because it happens to appear in a REG_EQUIV note. */
4064 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
4066 rtx seq = PATTERN (insn);
4067 int i, n = XVECLEN (seq, 0);
4068 for (i = 0; i < n; ++i)
4070 rtx subinsn = XVECEXP (seq, 0, i);
4071 if (INSN_P (subinsn))
4072 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
4076 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
4079 /* Look through the instructions for this function, and mark all the
4080 entries in POOL which are actually being used. Emit deferred constants
4081 which have indeed been used. */
4084 mark_constant_pool (void)
4088 if (!crtl->uses_const_pool && n_deferred_constants == 0)
4091 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4092 mark_constants (insn);
4094 for (link = crtl->epilogue_delay_list;
4096 link = XEXP (link, 1))
4097 mark_constants (XEXP (link, 0));
4100 /* Write all the constants in POOL. */
4103 output_constant_pool_contents (struct rtx_constant_pool *pool)
4105 struct constant_descriptor_rtx *desc;
4107 for (desc = pool->first; desc ; desc = desc->next)
4110 /* If the constant is part of an object_block, make sure that
4111 the constant has been positioned within its block, but do not
4112 write out its definition yet. output_object_blocks will do
4114 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4115 && SYMBOL_REF_BLOCK (desc->sym))
4116 place_block_symbol (desc->sym);
4119 switch_to_section (targetm.asm_out.select_rtx_section
4120 (desc->mode, desc->constant, desc->align));
4121 output_constant_pool_1 (desc, desc->align);
4126 /* Mark all constants that are used in the current function, then write
4127 out the function's private constant pool. */
4130 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
4131 tree fndecl ATTRIBUTE_UNUSED)
4133 struct rtx_constant_pool *pool = crtl->varasm.pool;
4135 /* It is possible for gcc to call force_const_mem and then to later
4136 discard the instructions which refer to the constant. In such a
4137 case we do not need to output the constant. */
4138 mark_constant_pool ();
4140 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4141 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
4144 output_constant_pool_contents (pool);
4146 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4147 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
4151 /* Write the contents of the shared constant pool. */
4154 output_shared_constant_pool (void)
4156 output_constant_pool_contents (shared_constant_pool);
4159 /* Determine what kind of relocations EXP may need. */
4162 compute_reloc_for_constant (tree exp)
4164 int reloc = 0, reloc2;
4167 switch (TREE_CODE (exp))
4171 /* Go inside any operations that get_inner_reference can handle and see
4172 if what's inside is a constant: no need to do anything here for
4173 addresses of variables or functions. */
4174 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4175 tem = TREE_OPERAND (tem, 0))
4178 if (TREE_PUBLIC (tem))
4185 case POINTER_PLUS_EXPR:
4186 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4187 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4191 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4192 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4193 /* The difference of two local labels is computable at link time. */
4194 if (reloc == 1 && reloc2 == 1)
4201 case VIEW_CONVERT_EXPR:
4202 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4207 unsigned HOST_WIDE_INT idx;
4208 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4210 reloc |= compute_reloc_for_constant (tem);
4220 /* Find all the constants whose addresses are referenced inside of EXP,
4221 and make sure assembler code with a label has been output for each one.
4222 Indicate whether an ADDR_EXPR has been encountered. */
4225 output_addressed_constants (tree exp)
4229 switch (TREE_CODE (exp))
4233 /* Go inside any operations that get_inner_reference can handle and see
4234 if what's inside is a constant: no need to do anything here for
4235 addresses of variables or functions. */
4236 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4237 tem = TREE_OPERAND (tem, 0))
4240 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4241 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4242 tem = DECL_INITIAL (tem);
4244 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4245 output_constant_def (tem, 0);
4249 case POINTER_PLUS_EXPR:
4251 output_addressed_constants (TREE_OPERAND (exp, 1));
4255 case VIEW_CONVERT_EXPR:
4256 output_addressed_constants (TREE_OPERAND (exp, 0));
4261 unsigned HOST_WIDE_INT idx;
4262 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4264 output_addressed_constants (tem);
4273 /* Whether a constructor CTOR is a valid static constant initializer if all
4274 its elements are. This used to be internal to initializer_constant_valid_p
4275 and has been exposed to let other functions like categorize_ctor_elements
4276 evaluate the property while walking a constructor for other purposes. */
4279 constructor_static_from_elts_p (const_tree ctor)
4281 return (TREE_CONSTANT (ctor)
4282 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4283 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4284 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4287 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4290 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4291 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4292 which are valid when ENDTYPE is an integer of any size; in
4293 particular, this does not accept a pointer minus a constant. This
4294 returns null_pointer_node if the VALUE is an absolute constant
4295 which can be used to initialize a static variable. Otherwise it
4299 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4303 if (!INTEGRAL_TYPE_P (endtype))
4306 op0 = TREE_OPERAND (value, 0);
4307 op1 = TREE_OPERAND (value, 1);
4309 /* Like STRIP_NOPS except allow the operand mode to widen. This
4310 works around a feature of fold that simplifies (int)(p1 - p2) to
4311 ((int)p1 - (int)p2) under the theory that the narrower operation
4314 while (CONVERT_EXPR_P (op0)
4315 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4317 tree inner = TREE_OPERAND (op0, 0);
4318 if (inner == error_mark_node
4319 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4320 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4321 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4326 while (CONVERT_EXPR_P (op1)
4327 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4329 tree inner = TREE_OPERAND (op1, 0);
4330 if (inner == error_mark_node
4331 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4332 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4333 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4338 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4342 op1 = initializer_constant_valid_p_1 (op1, endtype,
4343 cache ? cache + 2 : NULL);
4344 /* Both initializers must be known. */
4348 && (op0 == null_pointer_node
4349 || TREE_CODE (value) == MINUS_EXPR))
4350 return null_pointer_node;
4352 /* Support differences between labels. */
4353 if (TREE_CODE (op0) == LABEL_DECL
4354 && TREE_CODE (op1) == LABEL_DECL)
4355 return null_pointer_node;
4357 if (TREE_CODE (op0) == STRING_CST
4358 && TREE_CODE (op1) == STRING_CST
4359 && operand_equal_p (op0, op1, 1))
4360 return null_pointer_node;
4366 /* Helper function of initializer_constant_valid_p.
4367 Return nonzero if VALUE is a valid constant-valued expression
4368 for use in initializing a static variable; one that can be an
4369 element of a "constant" initializer.
4371 Return null_pointer_node if the value is absolute;
4372 if it is relocatable, return the variable that determines the relocation.
4373 We assume that VALUE has been folded as much as possible;
4374 therefore, we do not need to check for such things as
4375 arithmetic-combinations of integers.
4377 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4380 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4384 switch (TREE_CODE (value))
4387 if (constructor_static_from_elts_p (value))
4389 unsigned HOST_WIDE_INT idx;
4391 bool absolute = true;
4393 if (cache && cache[0] == value)
4395 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4398 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4405 cache[1] = NULL_TREE;
4409 if (reloc != null_pointer_node)
4412 /* For a non-absolute relocation, there is no single
4413 variable that can be "the variable that determines the
4418 cache[1] = absolute ? null_pointer_node : error_mark_node;
4420 return absolute ? null_pointer_node : error_mark_node;
4423 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4431 return null_pointer_node;
4436 tree op0 = staticp (TREE_OPERAND (value, 0));
4439 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4440 to be a constant, this is old-skool offsetof-like nonsense. */
4441 if (TREE_CODE (op0) == INDIRECT_REF
4442 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4443 return null_pointer_node;
4444 /* Taking the address of a nested function involves a trampoline,
4445 unless we don't need or want one. */
4446 if (TREE_CODE (op0) == FUNCTION_DECL
4447 && DECL_STATIC_CHAIN (op0)
4448 && !TREE_NO_TRAMPOLINE (value))
4450 /* "&{...}" requires a temporary to hold the constructed
4452 if (TREE_CODE (op0) == CONSTRUCTOR)
4458 case NON_LVALUE_EXPR:
4459 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4462 case VIEW_CONVERT_EXPR:
4464 tree src = TREE_OPERAND (value, 0);
4465 tree src_type = TREE_TYPE (src);
4466 tree dest_type = TREE_TYPE (value);
4468 /* Allow view-conversions from aggregate to non-aggregate type only
4469 if the bit pattern is fully preserved afterwards; otherwise, the
4470 RTL expander won't be able to apply a subsequent transformation
4471 to the underlying constructor. */
4472 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4474 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4475 return initializer_constant_valid_p_1 (src, endtype, cache);
4480 /* Allow all other kinds of view-conversion. */
4481 return initializer_constant_valid_p_1 (src, endtype, cache);
4486 tree src = TREE_OPERAND (value, 0);
4487 tree src_type = TREE_TYPE (src);
4488 tree dest_type = TREE_TYPE (value);
4490 /* Allow conversions between pointer types, floating-point
4491 types, and offset types. */
4492 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4493 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4494 || (TREE_CODE (dest_type) == OFFSET_TYPE
4495 && TREE_CODE (src_type) == OFFSET_TYPE))
4496 return initializer_constant_valid_p_1 (src, endtype, cache);
4498 /* Allow length-preserving conversions between integer types. */
4499 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4500 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4501 return initializer_constant_valid_p_1 (src, endtype, cache);
4503 /* Allow conversions between other integer types only if
4505 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4507 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4508 if (inner == null_pointer_node)
4509 return null_pointer_node;
4513 /* Allow (int) &foo provided int is as wide as a pointer. */
4514 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4515 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4516 return initializer_constant_valid_p_1 (src, endtype, cache);
4518 /* Likewise conversions from int to pointers, but also allow
4519 conversions from 0. */
4520 if ((POINTER_TYPE_P (dest_type)
4521 || TREE_CODE (dest_type) == OFFSET_TYPE)
4522 && INTEGRAL_TYPE_P (src_type))
4524 if (TREE_CODE (src) == INTEGER_CST
4525 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4526 return null_pointer_node;
4527 if (integer_zerop (src))
4528 return null_pointer_node;
4529 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4530 return initializer_constant_valid_p_1 (src, endtype, cache);
4533 /* Allow conversions to struct or union types if the value
4535 if (TREE_CODE (dest_type) == RECORD_TYPE
4536 || TREE_CODE (dest_type) == UNION_TYPE)
4537 return initializer_constant_valid_p_1 (src, endtype, cache);
4541 case POINTER_PLUS_EXPR:
4543 /* Any valid floating-point constants will have been folded by now;
4544 with -frounding-math we hit this with addition of two constants. */
4545 if (TREE_CODE (endtype) == REAL_TYPE)
4547 if (cache && cache[0] == value)
4549 if (! INTEGRAL_TYPE_P (endtype)
4550 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4552 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4554 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4557 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4558 endtype, ncache + 2);
4559 /* If either term is absolute, use the other term's relocation. */
4560 if (valid0 == null_pointer_node)
4562 else if (valid1 == null_pointer_node)
4564 /* Support narrowing pointer differences. */
4566 ret = narrowing_initializer_constant_valid_p (value, endtype,
4570 /* Support narrowing pointer differences. */
4571 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4580 if (TREE_CODE (endtype) == REAL_TYPE)
4582 if (cache && cache[0] == value)
4584 if (! INTEGRAL_TYPE_P (endtype)
4585 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4587 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4589 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4592 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4593 endtype, ncache + 2);
4594 /* Win if second argument is absolute. */
4595 if (valid1 == null_pointer_node)
4597 /* Win if both arguments have the same relocation.
4598 Then the value is absolute. */
4599 else if (valid0 == valid1 && valid0 != 0)
4600 ret = null_pointer_node;
4601 /* Since GCC guarantees that string constants are unique in the
4602 generated code, a subtraction between two copies of the same
4603 constant string is absolute. */
4604 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4605 && valid1 && TREE_CODE (valid1) == STRING_CST
4606 && operand_equal_p (valid0, valid1, 1))
4607 ret = null_pointer_node;
4608 /* Support narrowing differences. */
4610 ret = narrowing_initializer_constant_valid_p (value, endtype,
4614 /* Support narrowing differences. */
4615 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4630 /* Return nonzero if VALUE is a valid constant-valued expression
4631 for use in initializing a static variable; one that can be an
4632 element of a "constant" initializer.
4634 Return null_pointer_node if the value is absolute;
4635 if it is relocatable, return the variable that determines the relocation.
4636 We assume that VALUE has been folded as much as possible;
4637 therefore, we do not need to check for such things as
4638 arithmetic-combinations of integers. */
4640 initializer_constant_valid_p (tree value, tree endtype)
4642 return initializer_constant_valid_p_1 (value, endtype, NULL);
4645 /* Return true if VALUE is a valid constant-valued expression
4646 for use in initializing a static bit-field; one that can be
4647 an element of a "constant" initializer. */
4650 initializer_constant_valid_for_bitfield_p (tree value)
4652 /* For bitfields we support integer constants or possibly nested aggregates
4654 switch (TREE_CODE (value))
4658 unsigned HOST_WIDE_INT idx;
4661 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4662 if (!initializer_constant_valid_for_bitfield_p (elt))
4670 case VIEW_CONVERT_EXPR:
4671 case NON_LVALUE_EXPR:
4673 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4682 /* output_constructor outer state of relevance in recursive calls, typically
4683 for nested aggregate bitfields. */
4686 unsigned int bit_offset; /* current position in ... */
4687 int byte; /* ... the outer byte buffer. */
4690 static unsigned HOST_WIDE_INT
4691 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4694 /* Output assembler code for constant EXP to FILE, with no label.
4695 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4696 Assumes output_addressed_constants has been done on EXP already.
4698 Generate exactly SIZE bytes of assembler data, padding at the end
4699 with zeros if necessary. SIZE must always be specified.
4701 SIZE is important for structure constructors,
4702 since trailing members may have been omitted from the constructor.
4703 It is also important for initialization of arrays from string constants
4704 since the full length of the string constant might not be wanted.
4705 It is also needed for initialization of unions, where the initializer's
4706 type is just one member, and that may not be as long as the union.
4708 There a case in which we would fail to output exactly SIZE bytes:
4709 for a structure constructor that wants to produce more than SIZE bytes.
4710 But such constructors will never be generated for any possible input.
4712 ALIGN is the alignment of the data in bits. */
4715 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4717 enum tree_code code;
4718 unsigned HOST_WIDE_INT thissize;
4720 if (size == 0 || flag_syntax_only)
4723 /* See if we're trying to initialize a pointer in a non-default mode
4724 to the address of some declaration somewhere. If the target says
4725 the mode is valid for pointers, assume the target has a way of
4727 if (TREE_CODE (exp) == NOP_EXPR
4728 && POINTER_TYPE_P (TREE_TYPE (exp))
4729 && targetm.addr_space.valid_pointer_mode
4730 (TYPE_MODE (TREE_TYPE (exp)),
4731 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4733 tree saved_type = TREE_TYPE (exp);
4735 /* Peel off any intermediate conversions-to-pointer for valid
4737 while (TREE_CODE (exp) == NOP_EXPR
4738 && POINTER_TYPE_P (TREE_TYPE (exp))
4739 && targetm.addr_space.valid_pointer_mode
4740 (TYPE_MODE (TREE_TYPE (exp)),
4741 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4742 exp = TREE_OPERAND (exp, 0);
4744 /* If what we're left with is the address of something, we can
4745 convert the address to the final type and output it that
4747 if (TREE_CODE (exp) == ADDR_EXPR)
4748 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4749 /* Likewise for constant ints. */
4750 else if (TREE_CODE (exp) == INTEGER_CST)
4751 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4752 TREE_INT_CST_HIGH (exp));
4756 /* Eliminate any conversions since we'll be outputting the underlying
4758 while (CONVERT_EXPR_P (exp)
4759 || TREE_CODE (exp) == NON_LVALUE_EXPR
4760 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4762 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4763 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4765 /* Make sure eliminating the conversion is really a no-op, except with
4766 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4767 union types to allow for Ada unchecked unions. */
4768 if (type_size > op_size
4769 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4770 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4771 /* Keep the conversion. */
4774 exp = TREE_OPERAND (exp, 0);
4777 code = TREE_CODE (TREE_TYPE (exp));
4778 thissize = int_size_in_bytes (TREE_TYPE (exp));
4780 /* Allow a constructor with no elements for any data type.
4781 This means to fill the space with zeros. */
4782 if (TREE_CODE (exp) == CONSTRUCTOR
4783 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4785 assemble_zeros (size);
4789 if (TREE_CODE (exp) == FDESC_EXPR)
4791 #ifdef ASM_OUTPUT_FDESC
4792 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4793 tree decl = TREE_OPERAND (exp, 0);
4794 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4801 /* Now output the underlying data. If we've handling the padding, return.
4802 Otherwise, break and ensure SIZE is the size written. */
4809 case REFERENCE_TYPE:
4811 case FIXED_POINT_TYPE:
4812 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4813 EXPAND_INITIALIZER),
4814 MIN (size, thissize), align, 0))
4815 error ("initializer for integer/fixed-point value is too complicated");
4819 if (TREE_CODE (exp) != REAL_CST)
4820 error ("initializer for floating value is not a floating constant");
4822 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4826 output_constant (TREE_REALPART (exp), thissize / 2, align);
4827 output_constant (TREE_IMAGPART (exp), thissize / 2,
4828 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4833 switch (TREE_CODE (exp))
4836 output_constructor (exp, size, align, NULL);
4839 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4841 assemble_string (TREE_STRING_POINTER (exp), thissize);
4848 unsigned int nalign;
4849 enum machine_mode inner;
4851 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4852 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4854 elt_size = GET_MODE_SIZE (inner);
4856 link = TREE_VECTOR_CST_ELTS (exp);
4857 output_constant (TREE_VALUE (link), elt_size, align);
4858 thissize = elt_size;
4859 while ((link = TREE_CHAIN (link)) != NULL)
4861 output_constant (TREE_VALUE (link), elt_size, nalign);
4862 thissize += elt_size;
4873 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4874 output_constructor (exp, size, align, NULL);
4884 if (size > thissize)
4885 assemble_zeros (size - thissize);
4889 /* Subroutine of output_constructor, used for computing the size of
4890 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4891 type with an unspecified upper bound. */
4893 static unsigned HOST_WIDE_INT
4894 array_size_for_constructor (tree val)
4897 unsigned HOST_WIDE_INT cnt;
4898 tree index, value, tmp;
4900 /* This code used to attempt to handle string constants that are not
4901 arrays of single-bytes, but nothing else does, so there's no point in
4903 if (TREE_CODE (val) == STRING_CST)
4904 return TREE_STRING_LENGTH (val);
4906 max_index = NULL_TREE;
4907 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4909 if (TREE_CODE (index) == RANGE_EXPR)
4910 index = TREE_OPERAND (index, 1);
4911 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4915 if (max_index == NULL_TREE)
4918 /* Compute the total number of array elements. */
4919 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4920 i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4921 fold_convert (sizetype, tmp));
4922 i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4924 /* Multiply by the array element unit size to find number of bytes. */
4925 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4927 return tree_low_cst (i, 1);
4930 /* Other datastructures + helpers for output_constructor. */
4932 /* output_constructor local state to support interaction with helpers. */
4936 /* Received arguments. */
4937 tree exp; /* Constructor expression. */
4938 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4939 unsigned int align; /* Known initial alignment. */
4941 /* Constructor expression data. */
4942 tree type; /* Expression type. */
4943 tree field; /* Current field decl in a record. */
4944 tree min_index; /* Lower bound if specified for an array. */
4946 /* Output processing state. */
4947 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4948 bool byte_buffer_in_use; /* Whether byte ... */
4949 int byte; /* ... contains part of a bitfield byte yet to
4952 int last_relative_index; /* Implicit or explicit index of the last
4953 array element output within a bitfield. */
4954 /* Current element. */
4955 tree val; /* Current element value. */
4956 tree index; /* Current element index. */
4960 /* Helper for output_constructor. From the current LOCAL state, output a
4961 RANGE_EXPR element. */
4964 output_constructor_array_range (oc_local_state *local)
4966 unsigned HOST_WIDE_INT fieldsize
4967 = int_size_in_bytes (TREE_TYPE (local->type));
4969 HOST_WIDE_INT lo_index
4970 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4971 HOST_WIDE_INT hi_index
4972 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4973 HOST_WIDE_INT index;
4976 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4978 for (index = lo_index; index <= hi_index; index++)
4980 /* Output the element's initial value. */
4981 if (local->val == NULL_TREE)
4982 assemble_zeros (fieldsize);
4984 output_constant (local->val, fieldsize, align2);
4986 /* Count its size. */
4987 local->total_bytes += fieldsize;
4991 /* Helper for output_constructor. From the current LOCAL state, output a
4992 field element that is not true bitfield or part of an outer one. */
4995 output_constructor_regular_field (oc_local_state *local)
4997 /* Field size and position. Since this structure is static, we know the
4998 positions are constant. */
4999 unsigned HOST_WIDE_INT fieldsize;
5000 HOST_WIDE_INT fieldpos;
5002 unsigned int align2;
5004 if (local->index != NULL_TREE)
5005 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
5006 * ((tree_low_cst (local->index, 0)
5007 - tree_low_cst (local->min_index, 0))));
5008 else if (local->field != NULL_TREE)
5009 fieldpos = int_byte_position (local->field);
5013 /* Output any buffered-up bit-fields preceding this element. */
5014 if (local->byte_buffer_in_use)
5016 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5017 local->total_bytes++;
5018 local->byte_buffer_in_use = false;
5021 /* Advance to offset of this element.
5022 Note no alignment needed in an array, since that is guaranteed
5023 if each element has the proper size. */
5024 if ((local->field != NULL_TREE || local->index != NULL_TREE)
5025 && fieldpos != local->total_bytes)
5027 gcc_assert (fieldpos >= local->total_bytes);
5028 assemble_zeros (fieldpos - local->total_bytes);
5029 local->total_bytes = fieldpos;
5032 /* Find the alignment of this element. */
5033 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
5035 /* Determine size this element should occupy. */
5040 /* If this is an array with an unspecified upper bound,
5041 the initializer determines the size. */
5042 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5043 but we cannot do this until the deprecated support for
5044 initializing zero-length array members is removed. */
5045 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
5046 && TYPE_DOMAIN (TREE_TYPE (local->field))
5047 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
5049 fieldsize = array_size_for_constructor (local->val);
5050 /* Given a non-empty initialization, this field had
5052 gcc_assert (!fieldsize || !TREE_CHAIN (local->field));
5054 else if (DECL_SIZE_UNIT (local->field))
5056 /* ??? This can't be right. If the decl size overflows
5057 a host integer we will silently emit no data. */
5058 if (host_integerp (DECL_SIZE_UNIT (local->field), 1))
5059 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
5063 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
5065 /* Output the element's initial value. */
5066 if (local->val == NULL_TREE)
5067 assemble_zeros (fieldsize);
5069 output_constant (local->val, fieldsize, align2);
5071 /* Count its size. */
5072 local->total_bytes += fieldsize;
5075 /* Helper for output_constructor. From the current LOCAL and OUTER states,
5076 output an element that is a true bitfield or part of an outer one. */
5079 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
5081 /* Bit size of this element. */
5082 HOST_WIDE_INT ebitsize
5084 ? tree_low_cst (DECL_SIZE (local->field), 1)
5085 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
5087 /* Relative index of this element if this is an array component. */
5088 HOST_WIDE_INT relative_index
5091 ? (tree_low_cst (local->index, 0)
5092 - tree_low_cst (local->min_index, 0))
5093 : local->last_relative_index + 1)
5096 /* Bit position of this element from the start of the containing
5098 HOST_WIDE_INT constructor_relative_ebitpos
5100 ? int_bit_position (local->field)
5101 : ebitsize * relative_index);
5103 /* Bit position of this element from the start of a possibly ongoing
5104 outer byte buffer. */
5105 HOST_WIDE_INT byte_relative_ebitpos
5106 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
5108 /* From the start of a possibly ongoing outer byte buffer, offsets to
5109 the first bit of this element and to the first bit past the end of
5111 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
5112 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
5114 local->last_relative_index = relative_index;
5116 if (local->val == NULL_TREE)
5117 local->val = integer_zero_node;
5119 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
5120 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
5121 local->val = TREE_OPERAND (local->val, 0);
5123 if (TREE_CODE (local->val) != INTEGER_CST
5124 && TREE_CODE (local->val) != CONSTRUCTOR)
5126 error ("invalid initial value for member %qE", DECL_NAME (local->field));
5130 /* If this field does not start in this (or, next) byte,
5132 if (next_offset / BITS_PER_UNIT != local->total_bytes)
5134 /* Output remnant of any bit field in previous bytes. */
5135 if (local->byte_buffer_in_use)
5137 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5138 local->total_bytes++;
5139 local->byte_buffer_in_use = false;
5142 /* If still not at proper byte, advance to there. */
5143 if (next_offset / BITS_PER_UNIT != local->total_bytes)
5145 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
5146 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
5147 local->total_bytes = next_offset / BITS_PER_UNIT;
5151 /* Set up the buffer if necessary. */
5152 if (!local->byte_buffer_in_use)
5156 local->byte_buffer_in_use = true;
5159 /* If this is nested constructor, recurse passing the bit offset and the
5160 pending data, then retrieve the new pending data afterwards. */
5161 if (TREE_CODE (local->val) == CONSTRUCTOR)
5163 oc_outer_state output_state;
5165 output_state.bit_offset = next_offset % BITS_PER_UNIT;
5166 output_state.byte = local->byte;
5168 += output_constructor (local->val, 0, 0, &output_state);
5169 local->byte = output_state.byte;
5173 /* Otherwise, we must split the element into pieces that fall within
5174 separate bytes, and combine each byte with previous or following
5176 while (next_offset < end_offset)
5180 HOST_WIDE_INT value;
5181 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
5182 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
5184 /* Advance from byte to byte
5185 within this element when necessary. */
5186 while (next_byte != local->total_bytes)
5188 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5189 local->total_bytes++;
5193 /* Number of bits we can process at once
5194 (all part of the same byte). */
5195 this_time = MIN (end_offset - next_offset,
5196 BITS_PER_UNIT - next_bit);
5197 if (BYTES_BIG_ENDIAN)
5199 /* On big-endian machine, take the most significant bits
5200 first (of the bits that are significant)
5201 and put them into bytes from the most significant end. */
5202 shift = end_offset - next_offset - this_time;
5204 /* Don't try to take a bunch of bits that cross
5205 the word boundary in the INTEGER_CST. We can
5206 only select bits from the LOW or HIGH part
5208 if (shift < HOST_BITS_PER_WIDE_INT
5209 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5211 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
5212 shift = HOST_BITS_PER_WIDE_INT;
5215 /* Now get the bits from the appropriate constant word. */
5216 if (shift < HOST_BITS_PER_WIDE_INT)
5217 value = TREE_INT_CST_LOW (local->val);
5220 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5221 value = TREE_INT_CST_HIGH (local->val);
5222 shift -= HOST_BITS_PER_WIDE_INT;
5225 /* Get the result. This works only when:
5226 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5227 local->byte |= (((value >> shift)
5228 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5229 << (BITS_PER_UNIT - this_time - next_bit));
5233 /* On little-endian machines,
5234 take first the least significant bits of the value
5235 and pack them starting at the least significant
5236 bits of the bytes. */
5237 shift = next_offset - byte_relative_ebitpos;
5239 /* Don't try to take a bunch of bits that cross
5240 the word boundary in the INTEGER_CST. We can
5241 only select bits from the LOW or HIGH part
5243 if (shift < HOST_BITS_PER_WIDE_INT
5244 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5245 this_time = (HOST_BITS_PER_WIDE_INT - shift);
5247 /* Now get the bits from the appropriate constant word. */
5248 if (shift < HOST_BITS_PER_WIDE_INT)
5249 value = TREE_INT_CST_LOW (local->val);
5252 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5253 value = TREE_INT_CST_HIGH (local->val);
5254 shift -= HOST_BITS_PER_WIDE_INT;
5257 /* Get the result. This works only when:
5258 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5259 local->byte |= (((value >> shift)
5260 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5264 next_offset += this_time;
5265 local->byte_buffer_in_use = true;
5269 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5270 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5271 caller output state of relevance in recursive invocations. */
5273 static unsigned HOST_WIDE_INT
5274 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
5275 unsigned int align, oc_outer_state * outer)
5277 unsigned HOST_WIDE_INT cnt;
5278 constructor_elt *ce;
5280 oc_local_state local;
5282 /* Setup our local state to communicate with helpers. */
5285 local.align = align;
5287 local.total_bytes = 0;
5288 local.byte_buffer_in_use = outer != NULL;
5289 local.byte = outer ? outer->byte : 0;
5291 local.type = TREE_TYPE (exp);
5293 local.last_relative_index = -1;
5295 local.min_index = NULL_TREE;
5296 if (TREE_CODE (local.type) == ARRAY_TYPE
5297 && TYPE_DOMAIN (local.type) != NULL_TREE)
5298 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5300 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
5302 /* As CE goes through the elements of the constant, FIELD goes through the
5303 structure fields if the constant is a structure. If the constant is a
5304 union, we override this by getting the field from the TREE_LIST element.
5305 But the constant could also be an array. Then FIELD is zero.
5307 There is always a maximum of one element in the chain LINK for unions
5308 (even if the initializer in a source program incorrectly contains
5311 local.field = NULL_TREE;
5312 if (TREE_CODE (local.type) == RECORD_TYPE)
5313 local.field = TYPE_FIELDS (local.type);
5316 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
5317 cnt++, local.field = local.field ? TREE_CHAIN (local.field) : 0)
5319 local.val = ce->value;
5320 local.index = NULL_TREE;
5322 /* The element in a union constructor specifies the proper field
5324 if ((TREE_CODE (local.type) == RECORD_TYPE
5325 || TREE_CODE (local.type) == UNION_TYPE
5326 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
5327 && ce->index != NULL_TREE)
5328 local.field = ce->index;
5330 else if (TREE_CODE (local.type) == ARRAY_TYPE)
5331 local.index = ce->index;
5333 #ifdef ASM_COMMENT_START
5334 if (local.field && flag_verbose_asm)
5335 fprintf (asm_out_file, "%s %s:\n",
5337 DECL_NAME (local.field)
5338 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
5342 /* Eliminate the marker that makes a cast not be an lvalue. */
5343 if (local.val != NULL_TREE)
5344 STRIP_NOPS (local.val);
5346 /* Output the current element, using the appropriate helper ... */
5348 /* For an array slice not part of an outer bitfield. */
5350 && local.index != NULL_TREE
5351 && TREE_CODE (local.index) == RANGE_EXPR)
5352 output_constructor_array_range (&local);
5354 /* For a field that is neither a true bitfield nor part of an outer one,
5355 known to be at least byte aligned and multiple-of-bytes long. */
5357 && (local.field == NULL_TREE
5358 || !CONSTRUCTOR_BITFIELD_P (local.field)))
5359 output_constructor_regular_field (&local);
5361 /* For a true bitfield or part of an outer one. */
5363 output_constructor_bitfield (&local, outer);
5366 /* If we are not at toplevel, save the pending data for our caller.
5367 Otherwise output the pending data and padding zeros as needed. */
5369 outer->byte = local.byte;
5372 if (local.byte_buffer_in_use)
5374 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
5375 local.total_bytes++;
5378 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
5380 assemble_zeros (local.size - local.total_bytes);
5381 local.total_bytes = local.size;
5385 return local.total_bytes;
5388 /* Mark DECL as weak. */
5391 mark_weak (tree decl)
5393 DECL_WEAK (decl) = 1;
5395 if (DECL_RTL_SET_P (decl)
5396 && MEM_P (DECL_RTL (decl))
5397 && XEXP (DECL_RTL (decl), 0)
5398 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5399 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5402 /* Merge weak status between NEWDECL and OLDDECL. */
5405 merge_weak (tree newdecl, tree olddecl)
5407 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5409 if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
5412 /* We put the NEWDECL on the weak_decls list at some point
5413 and OLDDECL as well. Keep just OLDDECL on the list. */
5414 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5415 if (TREE_VALUE (*pwd) == newdecl)
5417 *pwd = TREE_CHAIN (*pwd);
5424 if (DECL_WEAK (newdecl))
5428 /* NEWDECL is weak, but OLDDECL is not. */
5430 /* If we already output the OLDDECL, we're in trouble; we can't
5431 go back and make it weak. This error cannot be caught in
5432 declare_weak because the NEWDECL and OLDDECL was not yet
5433 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5434 if (TREE_ASM_WRITTEN (olddecl))
5435 error ("weak declaration of %q+D must precede definition",
5438 /* If we've already generated rtl referencing OLDDECL, we may
5439 have done so in a way that will not function properly with
5441 else if (TREE_USED (olddecl)
5442 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
5443 warning (0, "weak declaration of %q+D after first use results "
5444 "in unspecified behavior", newdecl);
5448 /* We put the NEWDECL on the weak_decls list at some point.
5449 Replace it with the OLDDECL. */
5450 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5451 if (TREE_VALUE (wd) == newdecl)
5453 TREE_VALUE (wd) = olddecl;
5456 /* We may not find the entry on the list. If NEWDECL is a
5457 weak alias, then we will have already called
5458 globalize_decl to remove the entry; in that case, we do
5459 not need to do anything. */
5462 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5463 mark_weak (olddecl);
5466 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5467 weak. Just update NEWDECL to indicate that it's weak too. */
5468 mark_weak (newdecl);
5471 /* Declare DECL to be a weak symbol. */
5474 declare_weak (tree decl)
5476 if (! TREE_PUBLIC (decl))
5477 error ("weak declaration of %q+D must be public", decl);
5478 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
5479 error ("weak declaration of %q+D must precede definition", decl);
5480 else if (!SUPPORTS_WEAK)
5481 warning (0, "weak declaration of %q+D not supported", decl);
5484 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5485 DECL_ATTRIBUTES (decl)
5486 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5490 weak_finish_1 (tree decl)
5492 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5493 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5496 if (! TREE_USED (decl))
5499 #ifdef ASM_WEAKEN_DECL
5500 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5502 #ifdef ASM_WEAKEN_LABEL
5503 ASM_WEAKEN_LABEL (asm_out_file, name);
5505 #ifdef ASM_OUTPUT_WEAK_ALIAS
5507 static bool warn_once = 0;
5510 warning (0, "only weak aliases are supported in this configuration");
5520 /* This TREE_LIST contains weakref targets. */
5522 static GTY(()) tree weakref_targets;
5524 /* Forward declaration. */
5525 static tree find_decl_and_mark_needed (tree decl, tree target);
5527 /* Emit any pending weak declarations. */
5534 for (t = weakref_targets; t; t = TREE_CHAIN (t))
5536 tree alias_decl = TREE_PURPOSE (t);
5537 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5539 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5540 /* Remove alias_decl from the weak list, but leave entries for
5541 the target alone. */
5543 #ifndef ASM_OUTPUT_WEAKREF
5544 else if (! TREE_SYMBOL_REFERENCED (target))
5546 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5547 defined, otherwise we and weak_finish_1 would use
5548 different macros. */
5549 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5550 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5552 tree decl = find_decl_and_mark_needed (alias_decl, target);
5556 decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5557 TREE_CODE (alias_decl), target,
5558 TREE_TYPE (alias_decl));
5560 DECL_EXTERNAL (decl) = 1;
5561 TREE_PUBLIC (decl) = 1;
5562 DECL_ARTIFICIAL (decl) = 1;
5563 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5564 TREE_USED (decl) = 1;
5567 weak_finish_1 (decl);
5576 /* Remove the alias and the target from the pending weak list
5577 so that we do not emit any .weak directives for the former,
5578 nor multiple .weak directives for the latter. */
5579 for (p = &weak_decls; (t2 = *p) ; )
5581 if (TREE_VALUE (t2) == alias_decl
5582 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5583 *p = TREE_CHAIN (t2);
5585 p = &TREE_CHAIN (t2);
5588 /* Remove other weakrefs to the same target, to speed things up. */
5589 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5591 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5592 *p = TREE_CHAIN (t2);
5594 p = &TREE_CHAIN (t2);
5599 for (t = weak_decls; t; t = TREE_CHAIN (t))
5601 tree decl = TREE_VALUE (t);
5603 weak_finish_1 (decl);
5607 /* Emit the assembly bits to indicate that DECL is globally visible. */
5610 globalize_decl (tree decl)
5613 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5614 if (DECL_WEAK (decl))
5616 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5619 #ifdef ASM_WEAKEN_DECL
5620 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5622 ASM_WEAKEN_LABEL (asm_out_file, name);
5625 /* Remove this function from the pending weak list so that
5626 we do not emit multiple .weak directives for it. */
5627 for (p = &weak_decls; (t = *p) ; )
5629 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5630 *p = TREE_CHAIN (t);
5632 p = &TREE_CHAIN (t);
5635 /* Remove weakrefs to the same target from the pending weakref
5636 list, for the same reason. */
5637 for (p = &weakref_targets; (t = *p) ; )
5639 if (DECL_ASSEMBLER_NAME (decl)
5640 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5641 *p = TREE_CHAIN (t);
5643 p = &TREE_CHAIN (t);
5650 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5653 VEC(alias_pair,gc) *alias_pairs;
5655 /* Given an assembly name, find the decl it is associated with. At the
5656 same time, mark it needed for cgraph. */
5659 find_decl_and_mark_needed (tree decl, tree target)
5661 struct cgraph_node *fnode = NULL;
5662 struct varpool_node *vnode = NULL;
5664 if (TREE_CODE (decl) == FUNCTION_DECL)
5666 fnode = cgraph_node_for_asm (target);
5668 vnode = varpool_node_for_asm (target);
5672 vnode = varpool_node_for_asm (target);
5674 fnode = cgraph_node_for_asm (target);
5679 cgraph_mark_needed_node (fnode);
5684 varpool_mark_needed_node (vnode);
5685 vnode->force_output = 1;
5692 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5693 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5694 tree node is DECL to have the value of the tree node TARGET. */
5697 do_assemble_alias (tree decl, tree target)
5699 if (TREE_ASM_WRITTEN (decl))
5702 /* We must force creation of DECL_RTL for debug info generation, even though
5703 we don't use it here. */
5704 make_decl_rtl (decl);
5706 TREE_ASM_WRITTEN (decl) = 1;
5707 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5709 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5711 ultimate_transparent_alias_target (&target);
5713 if (!targetm.have_tls
5714 && TREE_CODE (decl) == VAR_DECL
5715 && DECL_THREAD_LOCAL_P (decl))
5717 decl = emutls_decl (decl);
5718 target = get_emutls_object_name (target);
5721 if (!TREE_SYMBOL_REFERENCED (target))
5722 weakref_targets = tree_cons (decl, target, weakref_targets);
5724 #ifdef ASM_OUTPUT_WEAKREF
5725 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5726 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5727 IDENTIFIER_POINTER (target));
5731 error_at (DECL_SOURCE_LOCATION (decl),
5732 "weakref is not supported in this configuration");
5739 if (!targetm.have_tls
5740 && TREE_CODE (decl) == VAR_DECL
5741 && DECL_THREAD_LOCAL_P (decl))
5743 decl = emutls_decl (decl);
5744 target = get_emutls_object_name (target);
5747 #ifdef ASM_OUTPUT_DEF
5748 /* Make name accessible from other files, if appropriate. */
5750 if (TREE_PUBLIC (decl))
5752 globalize_decl (decl);
5753 maybe_assemble_visibility (decl);
5756 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5757 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5759 ASM_OUTPUT_DEF (asm_out_file,
5760 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5761 IDENTIFIER_POINTER (target));
5763 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5768 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5769 # ifdef ASM_WEAKEN_DECL
5770 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5772 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5774 /* Remove this function from the pending weak list so that
5775 we do not emit multiple .weak directives for it. */
5776 for (p = &weak_decls; (t = *p) ; )
5777 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5778 *p = TREE_CHAIN (t);
5780 p = &TREE_CHAIN (t);
5782 /* Remove weakrefs to the same target from the pending weakref
5783 list, for the same reason. */
5784 for (p = &weakref_targets; (t = *p) ; )
5786 if (DECL_ASSEMBLER_NAME (decl)
5787 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5788 *p = TREE_CHAIN (t);
5790 p = &TREE_CHAIN (t);
5797 /* Remove the alias pairing for functions that are no longer in the call
5801 remove_unreachable_alias_pairs (void)
5806 if (alias_pairs == NULL)
5809 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5811 if (!DECL_EXTERNAL (p->decl))
5813 struct cgraph_node *fnode = NULL;
5814 struct varpool_node *vnode = NULL;
5815 fnode = cgraph_node_for_asm (p->target);
5816 vnode = (fnode == NULL) ? varpool_node_for_asm (p->target) : NULL;
5817 if (fnode == NULL && vnode == NULL)
5819 VEC_unordered_remove (alias_pair, alias_pairs, i);
5829 /* First pass of completing pending aliases. Make sure that cgraph knows
5830 which symbols will be required. */
5833 finish_aliases_1 (void)
5838 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5842 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5843 if (target_decl == NULL)
5845 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5846 error ("%q+D aliased to undefined symbol %qE",
5847 p->decl, p->target);
5849 else if (DECL_EXTERNAL (target_decl)
5850 /* We use local aliases for C++ thunks to force the tailcall
5851 to bind locally. Of course this is a hack - to keep it
5852 working do the following (which is not strictly correct). */
5853 && (! TREE_CODE (target_decl) == FUNCTION_DECL
5854 || ! DECL_VIRTUAL_P (target_decl))
5855 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5856 error ("%q+D aliased to external symbol %qE",
5857 p->decl, p->target);
5861 /* Second pass of completing pending aliases. Emit the actual assembly.
5862 This happens at the end of compilation and thus it is assured that the
5863 target symbol has been emitted. */
5866 finish_aliases_2 (void)
5871 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5872 do_assemble_alias (p->decl, p->target);
5874 VEC_truncate (alias_pair, alias_pairs, 0);
5877 /* Emit an assembler directive to make the symbol for DECL an alias to
5878 the symbol for TARGET. */
5881 assemble_alias (tree decl, tree target)
5884 bool is_weakref = false;
5886 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5888 tree alias = DECL_ASSEMBLER_NAME (decl);
5892 ultimate_transparent_alias_target (&target);
5894 if (alias == target)
5895 error ("weakref %q+D ultimately targets itself", decl);
5898 #ifndef ASM_OUTPUT_WEAKREF
5899 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5900 TREE_CHAIN (alias) = target;
5903 if (TREE_PUBLIC (decl))
5904 error ("weakref %q+D must have static linkage", decl);
5908 #if !defined (ASM_OUTPUT_DEF)
5909 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5910 error_at (DECL_SOURCE_LOCATION (decl),
5911 "alias definitions not supported in this configuration");
5914 if (!DECL_WEAK (decl))
5916 error_at (DECL_SOURCE_LOCATION (decl),
5917 "only weak aliases are supported in this configuration");
5923 TREE_USED (decl) = 1;
5925 /* A quirk of the initial implementation of aliases required that the user
5926 add "extern" to all of them. Which is silly, but now historical. Do
5927 note that the symbol is in fact locally defined. */
5929 DECL_EXTERNAL (decl) = 0;
5931 /* Allow aliases to aliases. */
5932 if (TREE_CODE (decl) == FUNCTION_DECL)
5933 cgraph_node (decl)->alias = true;
5935 varpool_node (decl)->alias = true;
5937 /* If the target has already been emitted, we don't have to queue the
5938 alias. This saves a tad of memory. */
5939 if (cgraph_global_info_ready)
5940 target_decl = find_decl_and_mark_needed (decl, target);
5943 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5944 do_assemble_alias (decl, target);
5947 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5953 /* Emit an assembler directive to set symbol for DECL visibility to
5954 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5957 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
5958 int vis ATTRIBUTE_UNUSED)
5960 #ifdef HAVE_GAS_HIDDEN
5961 static const char * const visibility_types[] = {
5962 NULL, "protected", "hidden", "internal"
5965 const char *name, *type;
5967 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5968 type = visibility_types[vis];
5970 fprintf (asm_out_file, "\t.%s\t", type);
5971 assemble_name (asm_out_file, name);
5972 fprintf (asm_out_file, "\n");
5974 warning (OPT_Wattributes, "visibility attribute not supported "
5975 "in this configuration; ignored");
5979 /* A helper function to call assemble_visibility when needed for a decl. */
5982 maybe_assemble_visibility (tree decl)
5984 enum symbol_visibility vis = DECL_VISIBILITY (decl);
5986 if (vis != VISIBILITY_DEFAULT)
5988 targetm.asm_out.visibility (decl, vis);
5995 /* Returns 1 if the target configuration supports defining public symbols
5996 so that one of them will be chosen at link time instead of generating a
5997 multiply-defined symbol error, whether through the use of weak symbols or
5998 a target-specific mechanism for having duplicates discarded. */
6001 supports_one_only (void)
6003 if (SUPPORTS_ONE_ONLY)
6005 return SUPPORTS_WEAK;
6008 /* Set up DECL as a public symbol that can be defined in multiple
6009 translation units without generating a linker error. */
6012 make_decl_one_only (tree decl, tree comdat_group)
6014 gcc_assert (TREE_CODE (decl) == VAR_DECL
6015 || TREE_CODE (decl) == FUNCTION_DECL);
6017 TREE_PUBLIC (decl) = 1;
6019 if (SUPPORTS_ONE_ONLY)
6021 #ifdef MAKE_DECL_ONE_ONLY
6022 MAKE_DECL_ONE_ONLY (decl);
6024 DECL_COMDAT_GROUP (decl) = comdat_group;
6026 else if (TREE_CODE (decl) == VAR_DECL
6027 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
6028 DECL_COMMON (decl) = 1;
6031 gcc_assert (SUPPORTS_WEAK);
6032 DECL_WEAK (decl) = 1;
6037 init_varasm_once (void)
6039 section_htab = htab_create_ggc (31, section_entry_hash,
6040 section_entry_eq, NULL);
6041 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
6042 object_block_entry_eq, NULL);
6043 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
6044 const_desc_eq, NULL);
6046 const_alias_set = new_alias_set ();
6047 shared_constant_pool = create_constant_pool ();
6049 #ifdef TEXT_SECTION_ASM_OP
6050 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
6051 TEXT_SECTION_ASM_OP);
6054 #ifdef DATA_SECTION_ASM_OP
6055 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6056 DATA_SECTION_ASM_OP);
6059 #ifdef SDATA_SECTION_ASM_OP
6060 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6061 SDATA_SECTION_ASM_OP);
6064 #ifdef READONLY_DATA_SECTION_ASM_OP
6065 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
6066 READONLY_DATA_SECTION_ASM_OP);
6069 #ifdef CTORS_SECTION_ASM_OP
6070 ctors_section = get_unnamed_section (0, output_section_asm_op,
6071 CTORS_SECTION_ASM_OP);
6074 #ifdef DTORS_SECTION_ASM_OP
6075 dtors_section = get_unnamed_section (0, output_section_asm_op,
6076 DTORS_SECTION_ASM_OP);
6079 #ifdef BSS_SECTION_ASM_OP
6080 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6081 output_section_asm_op,
6082 BSS_SECTION_ASM_OP);
6085 #ifdef SBSS_SECTION_ASM_OP
6086 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6087 output_section_asm_op,
6088 SBSS_SECTION_ASM_OP);
6091 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6092 | SECTION_COMMON, emit_tls_common);
6093 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6094 | SECTION_COMMON, emit_local);
6095 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6096 | SECTION_COMMON, emit_common);
6098 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
6099 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
6103 targetm.asm_out.init_sections ();
6105 if (readonly_data_section == NULL)
6106 readonly_data_section = text_section;
6110 decl_default_tls_model (const_tree decl)
6112 enum tls_model kind;
6115 is_local = targetm.binds_local_p (decl);
6119 kind = TLS_MODEL_LOCAL_EXEC;
6121 kind = TLS_MODEL_INITIAL_EXEC;
6124 /* Local dynamic is inefficient when we're not combining the
6125 parts of the address. */
6126 else if (optimize && is_local)
6127 kind = TLS_MODEL_LOCAL_DYNAMIC;
6129 kind = TLS_MODEL_GLOBAL_DYNAMIC;
6130 if (kind < flag_tls_default)
6131 kind = flag_tls_default;
6136 /* Select a set of attributes for section NAME based on the properties
6137 of DECL and whether or not RELOC indicates that DECL's initializer
6138 might contain runtime relocations.
6140 We make the section read-only and executable for a function decl,
6141 read-only for a const data decl, and writable for a non-const data decl. */
6144 default_section_type_flags (tree decl, const char *name, int reloc)
6148 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
6149 flags = SECTION_CODE;
6150 else if (decl && decl_readonly_section (decl, reloc))
6152 else if (current_function_decl
6154 && crtl->subsections.unlikely_text_section_name
6155 && strcmp (name, crtl->subsections.unlikely_text_section_name) == 0)
6156 flags = SECTION_CODE;
6158 && (!current_function_decl || !cfun)
6159 && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6160 flags = SECTION_CODE;
6162 flags = SECTION_WRITE;
6164 if (decl && DECL_ONE_ONLY (decl))
6165 flags |= SECTION_LINKONCE;
6167 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6168 flags |= SECTION_TLS | SECTION_WRITE;
6170 if (strcmp (name, ".bss") == 0
6171 || strncmp (name, ".bss.", 5) == 0
6172 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
6173 || strcmp (name, ".sbss") == 0
6174 || strncmp (name, ".sbss.", 6) == 0
6175 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
6176 flags |= SECTION_BSS;
6178 if (strcmp (name, ".tdata") == 0
6179 || strncmp (name, ".tdata.", 7) == 0
6180 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
6181 flags |= SECTION_TLS;
6183 if (strcmp (name, ".tbss") == 0
6184 || strncmp (name, ".tbss.", 6) == 0
6185 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
6186 flags |= SECTION_TLS | SECTION_BSS;
6188 /* These three sections have special ELF types. They are neither
6189 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6190 want to print a section type (@progbits or @nobits). If someone
6191 is silly enough to emit code or TLS variables to one of these
6192 sections, then don't handle them specially. */
6193 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
6194 && (strcmp (name, ".init_array") == 0
6195 || strcmp (name, ".fini_array") == 0
6196 || strcmp (name, ".preinit_array") == 0))
6197 flags |= SECTION_NOTYPE;
6202 /* Return true if the target supports some form of global BSS,
6203 either through bss_noswitch_section, or by selecting a BSS
6204 section in TARGET_ASM_SELECT_SECTION. */
6207 have_global_bss_p (void)
6209 return bss_noswitch_section || targetm.have_switchable_bss_sections;
6212 /* Output assembly to switch to section NAME with attribute FLAGS.
6213 Four variants for common object file formats. */
6216 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
6217 unsigned int flags ATTRIBUTE_UNUSED,
6218 tree decl ATTRIBUTE_UNUSED)
6220 /* Some object formats don't support named sections at all. The
6221 front-end should already have flagged this as an error. */
6225 #ifndef TLS_SECTION_ASM_FLAG
6226 #define TLS_SECTION_ASM_FLAG 'T'
6230 default_elf_asm_named_section (const char *name, unsigned int flags,
6231 tree decl ATTRIBUTE_UNUSED)
6233 char flagchars[10], *f = flagchars;
6235 /* If we have already declared this section, we can use an
6236 abbreviated form to switch back to it -- unless this section is
6237 part of a COMDAT groups, in which case GAS requires the full
6238 declaration every time. */
6239 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6240 && (flags & SECTION_DECLARED))
6242 fprintf (asm_out_file, "\t.section\t%s\n", name);
6246 if (!(flags & SECTION_DEBUG))
6248 if (flags & SECTION_WRITE)
6250 if (flags & SECTION_CODE)
6252 if (flags & SECTION_SMALL)
6254 if (flags & SECTION_MERGE)
6256 if (flags & SECTION_STRINGS)
6258 if (flags & SECTION_TLS)
6259 *f++ = TLS_SECTION_ASM_FLAG;
6260 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6264 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
6266 if (!(flags & SECTION_NOTYPE))
6271 if (flags & SECTION_BSS)
6277 #ifdef ASM_COMMENT_START
6278 /* On platforms that use "@" as the assembly comment character,
6280 if (strcmp (ASM_COMMENT_START, "@") == 0)
6283 fprintf (asm_out_file, format, type);
6285 if (flags & SECTION_ENTSIZE)
6286 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
6287 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6289 if (TREE_CODE (decl) == IDENTIFIER_NODE)
6290 fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
6292 fprintf (asm_out_file, ",%s,comdat",
6293 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
6297 putc ('\n', asm_out_file);
6301 default_coff_asm_named_section (const char *name, unsigned int flags,
6302 tree decl ATTRIBUTE_UNUSED)
6304 char flagchars[8], *f = flagchars;
6306 if (flags & SECTION_WRITE)
6308 if (flags & SECTION_CODE)
6312 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
6316 default_pe_asm_named_section (const char *name, unsigned int flags,
6319 default_coff_asm_named_section (name, flags, decl);
6321 if (flags & SECTION_LINKONCE)
6323 /* Functions may have been compiled at various levels of
6324 optimization so we can't use `same_size' here.
6325 Instead, have the linker pick one. */
6326 fprintf (asm_out_file, "\t.linkonce %s\n",
6327 (flags & SECTION_CODE ? "discard" : "same_size"));
6331 /* The lame default section selector. */
6334 default_select_section (tree decl, int reloc,
6335 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6339 if (decl_readonly_section (decl, reloc))
6340 return readonly_data_section;
6342 else if (TREE_CODE (decl) == CONSTRUCTOR)
6344 if (! ((flag_pic && reloc)
6345 || !TREE_READONLY (decl)
6346 || TREE_SIDE_EFFECTS (decl)
6347 || !TREE_CONSTANT (decl)))
6348 return readonly_data_section;
6350 else if (TREE_CODE (decl) == STRING_CST)
6351 return readonly_data_section;
6352 else if (! (flag_pic && reloc))
6353 return readonly_data_section;
6355 return data_section;
6358 enum section_category
6359 categorize_decl_for_section (const_tree decl, int reloc)
6361 enum section_category ret;
6363 if (TREE_CODE (decl) == FUNCTION_DECL)
6365 else if (TREE_CODE (decl) == STRING_CST)
6367 if (flag_mudflap) /* or !flag_merge_constants */
6368 return SECCAT_RODATA;
6370 return SECCAT_RODATA_MERGE_STR;
6372 else if (TREE_CODE (decl) == VAR_DECL)
6374 if (bss_initializer_p (decl))
6376 else if (! TREE_READONLY (decl)
6377 || TREE_SIDE_EFFECTS (decl)
6378 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6380 /* Here the reloc_rw_mask is not testing whether the section should
6381 be read-only or not, but whether the dynamic link will have to
6382 do something. If so, we wish to segregate the data in order to
6383 minimize cache misses inside the dynamic linker. */
6384 if (reloc & targetm.asm_out.reloc_rw_mask ())
6385 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6389 else if (reloc & targetm.asm_out.reloc_rw_mask ())
6390 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6391 else if (reloc || flag_merge_constants < 2)
6392 /* C and C++ don't allow different variables to share the same
6393 location. -fmerge-all-constants allows even that (at the
6394 expense of not conforming). */
6395 ret = SECCAT_RODATA;
6396 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6397 ret = SECCAT_RODATA_MERGE_STR_INIT;
6399 ret = SECCAT_RODATA_MERGE_CONST;
6401 else if (TREE_CODE (decl) == CONSTRUCTOR)
6403 if ((reloc & targetm.asm_out.reloc_rw_mask ())
6404 || TREE_SIDE_EFFECTS (decl)
6405 || ! TREE_CONSTANT (decl))
6408 ret = SECCAT_RODATA;
6411 ret = SECCAT_RODATA;
6413 /* There are no read-only thread-local sections. */
6414 if (TREE_CODE (decl) == VAR_DECL && DECL_TLS_MODEL (decl))
6416 if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED)
6418 if (DECL_EMUTLS_VAR_P (decl))
6420 if (targetm.emutls.var_section)
6421 ret = SECCAT_EMUTLS_VAR;
6425 if (targetm.emutls.tmpl_prefix)
6426 ret = SECCAT_EMUTLS_TMPL;
6429 /* Note that this would be *just* SECCAT_BSS, except that there's
6430 no concept of a read-only thread-local-data section. */
6431 else if (ret == SECCAT_BSS
6432 || (flag_zero_initialized_in_bss
6433 && initializer_zerop (DECL_INITIAL (decl))))
6439 /* If the target uses small data sections, select it. */
6440 else if (targetm.in_small_data_p (decl))
6442 if (ret == SECCAT_BSS)
6444 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6445 ret = SECCAT_SRODATA;
6454 decl_readonly_section (const_tree decl, int reloc)
6456 switch (categorize_decl_for_section (decl, reloc))
6459 case SECCAT_RODATA_MERGE_STR:
6460 case SECCAT_RODATA_MERGE_STR_INIT:
6461 case SECCAT_RODATA_MERGE_CONST:
6462 case SECCAT_SRODATA:
6471 /* Select a section based on the above categorization. */
6474 default_elf_select_section (tree decl, int reloc,
6475 unsigned HOST_WIDE_INT align)
6478 switch (categorize_decl_for_section (decl, reloc))
6481 /* We're not supposed to be called on FUNCTION_DECLs. */
6484 return readonly_data_section;
6485 case SECCAT_RODATA_MERGE_STR:
6486 return mergeable_string_section (decl, align, 0);
6487 case SECCAT_RODATA_MERGE_STR_INIT:
6488 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6489 case SECCAT_RODATA_MERGE_CONST:
6490 return mergeable_constant_section (DECL_MODE (decl), align, 0);
6491 case SECCAT_SRODATA:
6495 return data_section;
6496 case SECCAT_DATA_REL:
6497 sname = ".data.rel";
6499 case SECCAT_DATA_REL_LOCAL:
6500 sname = ".data.rel.local";
6502 case SECCAT_DATA_REL_RO:
6503 sname = ".data.rel.ro";
6505 case SECCAT_DATA_REL_RO_LOCAL:
6506 sname = ".data.rel.ro.local";
6525 case SECCAT_EMUTLS_VAR:
6526 sname = targetm.emutls.var_section;
6528 case SECCAT_EMUTLS_TMPL:
6529 sname = targetm.emutls.tmpl_section;
6537 return get_named_section (decl, sname, reloc);
6540 /* Construct a unique section name based on the decl name and the
6541 categorization performed above. */
6544 default_unique_section (tree decl, int reloc)
6546 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6547 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6548 const char *prefix, *name, *linkonce;
6551 switch (categorize_decl_for_section (decl, reloc))
6554 prefix = one_only ? ".t" : ".text";
6557 case SECCAT_RODATA_MERGE_STR:
6558 case SECCAT_RODATA_MERGE_STR_INIT:
6559 case SECCAT_RODATA_MERGE_CONST:
6560 prefix = one_only ? ".r" : ".rodata";
6562 case SECCAT_SRODATA:
6563 prefix = one_only ? ".s2" : ".sdata2";
6566 prefix = one_only ? ".d" : ".data";
6568 case SECCAT_DATA_REL:
6569 prefix = one_only ? ".d.rel" : ".data.rel";
6571 case SECCAT_DATA_REL_LOCAL:
6572 prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6574 case SECCAT_DATA_REL_RO:
6575 prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6577 case SECCAT_DATA_REL_RO_LOCAL:
6578 prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6581 prefix = one_only ? ".s" : ".sdata";
6584 prefix = one_only ? ".b" : ".bss";
6587 prefix = one_only ? ".sb" : ".sbss";
6590 prefix = one_only ? ".td" : ".tdata";
6593 prefix = one_only ? ".tb" : ".tbss";
6595 case SECCAT_EMUTLS_VAR:
6596 prefix = targetm.emutls.var_section;
6598 case SECCAT_EMUTLS_TMPL:
6599 prefix = targetm.emutls.tmpl_section;
6605 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6606 name = targetm.strip_name_encoding (name);
6608 /* If we're using one_only, then there needs to be a .gnu.linkonce
6609 prefix to the section name. */
6610 linkonce = one_only ? ".gnu.linkonce" : "";
6612 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6614 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6617 /* Like compute_reloc_for_constant, except for an RTX. The return value
6618 is a mask for which bit 1 indicates a global relocation, and bit 0
6619 indicates a local relocation. */
6622 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6624 int *preloc = (int *) data;
6627 switch (GET_CODE (x))
6630 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6643 compute_reloc_for_rtx (rtx x)
6647 switch (GET_CODE (x))
6653 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6662 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6664 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6666 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6667 return data_section;
6669 return readonly_data_section;
6673 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6674 unsigned HOST_WIDE_INT align)
6676 int reloc = compute_reloc_for_rtx (x);
6678 /* ??? Handle small data here somehow. */
6680 if (reloc & targetm.asm_out.reloc_rw_mask ())
6683 return get_named_section (NULL, ".data.rel.ro.local", 1);
6685 return get_named_section (NULL, ".data.rel.ro", 3);
6688 return mergeable_constant_section (mode, align, 0);
6691 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6694 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6699 /* Careful not to prod global register variables. */
6702 symbol = XEXP (rtl, 0);
6703 if (GET_CODE (symbol) != SYMBOL_REF)
6706 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6707 if (TREE_CODE (decl) == FUNCTION_DECL)
6708 flags |= SYMBOL_FLAG_FUNCTION;
6709 if (targetm.binds_local_p (decl))
6710 flags |= SYMBOL_FLAG_LOCAL;
6711 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)
6712 && DECL_TLS_MODEL (decl) != TLS_MODEL_EMULATED)
6713 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6714 else if (targetm.in_small_data_p (decl))
6715 flags |= SYMBOL_FLAG_SMALL;
6716 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6717 being PUBLIC, the thing *must* be defined in this translation unit.
6718 Prevent this buglet from being propagated into rtl code as well. */
6719 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6720 flags |= SYMBOL_FLAG_EXTERNAL;
6722 SYMBOL_REF_FLAGS (symbol) = flags;
6725 /* By default, we do nothing for encode_section_info, so we need not
6726 do anything but discard the '*' marker. */
6729 default_strip_name_encoding (const char *str)
6731 return str + (*str == '*');
6734 #ifdef ASM_OUTPUT_DEF
6735 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6736 anchor relative to ".", the current section position. */
6739 default_asm_output_anchor (rtx symbol)
6743 sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6744 SYMBOL_REF_BLOCK_OFFSET (symbol));
6745 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6749 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6752 default_use_anchors_for_symbol_p (const_rtx symbol)
6757 /* Don't use anchors for mergeable sections. The linker might move
6758 the objects around. */
6759 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6760 if (sect->common.flags & SECTION_MERGE)
6763 /* Don't use anchors for small data sections. The small data register
6764 acts as an anchor for such sections. */
6765 if (sect->common.flags & SECTION_SMALL)
6768 decl = SYMBOL_REF_DECL (symbol);
6769 if (decl && DECL_P (decl))
6771 /* Don't use section anchors for decls that might be defined by
6773 if (!targetm.binds_local_p (decl))
6776 /* Don't use section anchors for decls that will be placed in a
6777 small data section. */
6778 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6779 one above. The problem is that we only use SECTION_SMALL for
6780 sections that should be marked as small in the section directive. */
6781 if (targetm.in_small_data_p (decl))
6787 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6788 wrt cross-module name binding. */
6791 default_binds_local_p (const_tree exp)
6793 return default_binds_local_p_1 (exp, flag_shlib);
6797 default_binds_local_p_1 (const_tree exp, int shlib)
6801 /* A non-decl is an entry in the constant pool. */
6804 /* Weakrefs may not bind locally, even though the weakref itself is
6805 always static and therefore local. */
6806 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6808 /* Static variables are always local. */
6809 else if (! TREE_PUBLIC (exp))
6811 /* A variable is local if the user has said explicitly that it will
6813 else if (DECL_VISIBILITY_SPECIFIED (exp)
6814 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6816 /* Variables defined outside this object might not be local. */
6817 else if (DECL_EXTERNAL (exp))
6819 /* If defined in this object and visibility is not default, must be
6821 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6823 /* Default visibility weak data can be overridden by a strong symbol
6824 in another module and so are not local. */
6825 else if (DECL_WEAK (exp))
6827 /* If PIC, then assume that any global name can be overridden by
6828 symbols resolved from other modules, unless we are compiling with
6829 -fwhole-program, which assumes that names are local. */
6831 local_p = flag_whole_program;
6832 /* Uninitialized COMMON variable may be unified with symbols
6833 resolved from other modules. */
6834 else if (DECL_COMMON (exp)
6835 && (DECL_INITIAL (exp) == NULL
6836 || DECL_INITIAL (exp) == error_mark_node))
6838 /* Otherwise we're left with initialized (or non-common) global data
6839 which is of necessity defined locally. */
6846 /* Default function to output code that will globalize a label. A
6847 target must define GLOBAL_ASM_OP or provide its own function to
6848 globalize a label. */
6849 #ifdef GLOBAL_ASM_OP
6851 default_globalize_label (FILE * stream, const char *name)
6853 fputs (GLOBAL_ASM_OP, stream);
6854 assemble_name (stream, name);
6855 putc ('\n', stream);
6857 #endif /* GLOBAL_ASM_OP */
6859 /* Default function to output code that will globalize a declaration. */
6861 default_globalize_decl_name (FILE * stream, tree decl)
6863 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6864 targetm.asm_out.globalize_label (stream, name);
6867 /* Default function to output a label for unwind information. The
6868 default is to do nothing. A target that needs nonlocal labels for
6869 unwind information must provide its own function to do this. */
6871 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6872 tree decl ATTRIBUTE_UNUSED,
6873 int for_eh ATTRIBUTE_UNUSED,
6874 int empty ATTRIBUTE_UNUSED)
6878 /* Default function to output a label to divide up the exception table.
6879 The default is to do nothing. A target that needs/wants to divide
6880 up the table must provide it's own function to do this. */
6882 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6886 /* This is how to output an internal numbered label where PREFIX is
6887 the class of label and LABELNO is the number within the class. */
6890 default_internal_label (FILE *stream, const char *prefix,
6891 unsigned long labelno)
6893 char *const buf = (char *) alloca (40 + strlen (prefix));
6894 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6895 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6898 /* This is the default behavior at the beginning of a file. It's
6899 controlled by two other target-hook toggles. */
6901 default_file_start (void)
6903 if (targetm.file_start_app_off
6904 && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
6905 fputs (ASM_APP_OFF, asm_out_file);
6907 if (targetm.file_start_file_directive)
6908 output_file_directive (asm_out_file, main_input_filename);
6911 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6912 which emits a special section directive used to indicate whether or
6913 not this object file needs an executable stack. This is primarily
6914 a GNU extension to ELF but could be used on other targets. */
6916 int trampolines_created;
6919 file_end_indicate_exec_stack (void)
6921 unsigned int flags = SECTION_DEBUG;
6922 if (trampolines_created)
6923 flags |= SECTION_CODE;
6925 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
6928 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6929 a get_unnamed_section callback. */
6932 output_section_asm_op (const void *directive)
6934 fprintf (asm_out_file, "%s\n", (const char *) directive);
6937 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6938 the current section is NEW_SECTION. */
6941 switch_to_section (section *new_section)
6943 if (in_section == new_section)
6946 if (new_section->common.flags & SECTION_FORGET)
6949 in_section = new_section;
6951 switch (SECTION_STYLE (new_section))
6955 && !crtl->subsections.unlikely_text_section_name
6956 && strcmp (new_section->named.name,
6957 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6958 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6960 targetm.asm_out.named_section (new_section->named.name,
6961 new_section->named.common.flags,
6962 new_section->named.decl);
6965 case SECTION_UNNAMED:
6966 new_section->unnamed.callback (new_section->unnamed.data);
6969 case SECTION_NOSWITCH:
6974 new_section->common.flags |= SECTION_DECLARED;
6977 /* If block symbol SYMBOL has not yet been assigned an offset, place
6978 it at the end of its block. */
6981 place_block_symbol (rtx symbol)
6983 unsigned HOST_WIDE_INT size, mask, offset;
6984 struct constant_descriptor_rtx *desc;
6985 unsigned int alignment;
6986 struct object_block *block;
6989 gcc_assert (SYMBOL_REF_BLOCK (symbol));
6990 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6993 /* Work out the symbol's size and alignment. */
6994 if (CONSTANT_POOL_ADDRESS_P (symbol))
6996 desc = SYMBOL_REF_CONSTANT (symbol);
6997 alignment = desc->align;
6998 size = GET_MODE_SIZE (desc->mode);
7000 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7002 decl = SYMBOL_REF_DECL (symbol);
7003 alignment = DECL_ALIGN (decl);
7004 size = get_constant_size (DECL_INITIAL (decl));
7008 decl = SYMBOL_REF_DECL (symbol);
7009 alignment = DECL_ALIGN (decl);
7010 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7013 /* Calculate the object's offset from the start of the block. */
7014 block = SYMBOL_REF_BLOCK (symbol);
7015 mask = alignment / BITS_PER_UNIT - 1;
7016 offset = (block->size + mask) & ~mask;
7017 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
7019 /* Record the block's new alignment and size. */
7020 block->alignment = MAX (block->alignment, alignment);
7021 block->size = offset + size;
7023 VEC_safe_push (rtx, gc, block->objects, symbol);
7026 /* Return the anchor that should be used to address byte offset OFFSET
7027 from the first object in BLOCK. MODEL is the TLS model used
7031 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
7032 enum tls_model model)
7035 unsigned int begin, middle, end;
7036 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
7039 /* Work out the anchor's offset. Use an offset of 0 for the first
7040 anchor so that we don't pessimize the case where we take the address
7041 of a variable at the beginning of the block. This is particularly
7042 useful when a block has only one variable assigned to it.
7044 We try to place anchors RANGE bytes apart, so there can then be
7045 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7046 a ptr_mode offset. With some target settings, the lowest such
7047 anchor might be out of range for the lowest ptr_mode offset;
7048 likewise the highest anchor for the highest offset. Use anchors
7049 at the extreme ends of the ptr_mode range in such cases.
7051 All arithmetic uses unsigned integers in order to avoid
7053 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
7054 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
7055 range = max_offset - min_offset + 1;
7060 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
7063 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
7064 delta -= delta % range;
7067 offset = (HOST_WIDE_INT) (-delta);
7071 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
7072 delta -= delta % range;
7073 if (delta > bias - 1)
7075 offset = (HOST_WIDE_INT) delta;
7079 /* Do a binary search to see if there's already an anchor we can use.
7080 Set BEGIN to the new anchor's index if not. */
7082 end = VEC_length (rtx, block->anchors);
7083 while (begin != end)
7085 middle = (end + begin) / 2;
7086 anchor = VEC_index (rtx, block->anchors, middle);
7087 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
7089 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
7091 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
7093 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
7099 /* Create a new anchor with a unique label. */
7100 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
7101 anchor = create_block_symbol (ggc_strdup (label), block, offset);
7102 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
7103 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
7105 /* Insert it at index BEGIN. */
7106 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
7110 /* Output the objects in BLOCK. */
7113 output_object_block (struct object_block *block)
7115 struct constant_descriptor_rtx *desc;
7117 HOST_WIDE_INT offset;
7121 if (block->objects == NULL)
7124 /* Switch to the section and make sure that the first byte is
7125 suitably aligned. */
7126 switch_to_section (block->sect);
7127 assemble_align (block->alignment);
7129 /* Define the values of all anchors relative to the current section
7131 for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
7132 targetm.asm_out.output_anchor (symbol);
7134 /* Output the objects themselves. */
7136 for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
7138 /* Move to the object's offset, padding with zeros if necessary. */
7139 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
7140 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
7141 if (CONSTANT_POOL_ADDRESS_P (symbol))
7143 desc = SYMBOL_REF_CONSTANT (symbol);
7144 output_constant_pool_1 (desc, 1);
7145 offset += GET_MODE_SIZE (desc->mode);
7147 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7149 decl = SYMBOL_REF_DECL (symbol);
7150 assemble_constant_contents (DECL_INITIAL (decl), XSTR (symbol, 0),
7152 offset += get_constant_size (DECL_INITIAL (decl));
7156 decl = SYMBOL_REF_DECL (symbol);
7157 assemble_variable_contents (decl, XSTR (symbol, 0), false);
7158 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7163 /* A htab_traverse callback used to call output_object_block for
7164 each member of object_block_htab. */
7167 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
7169 output_object_block ((struct object_block *) (*slot));
7173 /* Output the definitions of all object_blocks. */
7176 output_object_blocks (void)
7178 htab_traverse (object_block_htab, output_object_block_htab, NULL);
7181 /* This function provides a possible implementation of the
7182 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7183 by -frecord-gcc-switches it creates a new mergeable, string section in the
7184 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7185 contains the switches in ASCII format.
7187 FIXME: This code does not correctly handle double quote characters
7188 that appear inside strings, (it strips them rather than preserving them).
7189 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7190 characters - instead it treats them as sub-string separators. Since
7191 we want to emit NUL strings terminators into the object file we have to use
7195 elf_record_gcc_switches (print_switch_type type, const char * name)
7197 static char buffer[1024];
7199 /* This variable is used as part of a simplistic heuristic to detect
7200 command line switches which take an argument:
7202 "If a command line option does not start with a dash then
7203 it is an argument for the previous command line option."
7205 This fails in the case of the command line option which is the name
7206 of the file to compile, but otherwise it is pretty reasonable. */
7207 static bool previous_name_held_back = FALSE;
7211 case SWITCH_TYPE_PASSED:
7214 if (previous_name_held_back)
7216 unsigned int len = strlen (buffer);
7218 snprintf (buffer + len, sizeof buffer - len, " %s", name);
7219 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7220 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7221 previous_name_held_back = FALSE;
7225 strncpy (buffer, name, sizeof buffer);
7226 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7227 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7232 if (previous_name_held_back)
7234 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7235 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7238 strncpy (buffer, name, sizeof buffer);
7239 previous_name_held_back = TRUE;
7243 case SWITCH_TYPE_DESCRIPTIVE:
7246 /* Distinguish between invocations where name is NULL. */
7247 static bool started = false;
7251 if (previous_name_held_back)
7253 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7254 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7261 sec = get_section (targetm.asm_out.record_gcc_switches_section,
7265 | (SECTION_ENTSIZE & 1),
7267 switch_to_section (sec);
7276 /* The return value is currently ignored by the caller, but must be 0.
7277 For -fverbose-asm the return value would be the number of characters
7278 emitted into the assembler file. */
7282 /* Emit text to declare externally defined symbols. It is needed to
7283 properly support non-default visibility. */
7285 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
7287 const char *name ATTRIBUTE_UNUSED)
7289 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7290 set in order to avoid putting out names that are never really
7292 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
7293 && targetm.binds_local_p (decl))
7294 maybe_assemble_visibility (decl);
7297 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7300 make_debug_expr_from_rtl (const_rtx exp)
7302 tree ddecl = make_node (DEBUG_EXPR_DECL), type;
7303 enum machine_mode mode = GET_MODE (exp);
7306 DECL_ARTIFICIAL (ddecl) = 1;
7307 if (REG_P (exp) && REG_EXPR (exp))
7308 type = TREE_TYPE (REG_EXPR (exp));
7309 else if (MEM_P (exp) && MEM_EXPR (exp))
7310 type = TREE_TYPE (MEM_EXPR (exp));
7313 if (type && TYPE_MODE (type) == mode)
7314 TREE_TYPE (ddecl) = type;
7316 TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
7317 DECL_MODE (ddecl) = mode;
7318 dval = gen_rtx_DEBUG_EXPR (mode);
7319 DEBUG_EXPR_TREE_DECL (dval) = ddecl;
7320 SET_DECL_RTL (ddecl, dval);
7324 #include "gt-varasm.h"