1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
42 #include "diagnostic-core.h"
46 #include "langhooks.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h" /* Needed for external data
59 declarations for e.g. AIX 4.x. */
62 /* The (assembler) name of the first globally-visible object output. */
63 extern GTY(()) const char *first_global_object_name;
64 extern GTY(()) const char *weak_global_object_name;
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
70 struct constant_descriptor_rtx;
71 struct rtx_constant_pool;
73 #define n_deferred_constants (crtl->varasm.deferred_constants)
75 /* Number for making the label on the next
76 constant that is stored in memory. */
78 static GTY(()) int const_labelno;
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81 to ASM_FINISH_DECLARE_OBJECT. */
83 int size_directive_output;
85 /* The last decl for which assemble_variable was called,
86 if it did ASM_DECLARE_OBJECT_NAME.
87 If the last call to assemble_variable didn't do that,
90 tree last_assemble_variable_decl;
92 /* The following global variable indicates if the first basic block
93 in a function belongs to the cold partition or not. */
95 bool first_function_block_is_cold;
97 /* We give all constants their own alias set. Perhaps redundant with
98 MEM_READONLY_P, but pre-dates it. */
100 static alias_set_type const_alias_set;
102 static const char *strip_reg_name (const char *);
103 static int contains_pointers_p (tree);
104 #ifdef ASM_OUTPUT_EXTERNAL
105 static bool incorporeal_function_p (tree);
107 static void decode_addr_const (tree, struct addr_const *);
108 static hashval_t const_desc_hash (const void *);
109 static int const_desc_eq (const void *, const void *);
110 static hashval_t const_hash_1 (const tree);
111 static int compare_constant (const tree, const tree);
112 static tree copy_constant (tree);
113 static void output_constant_def_contents (rtx);
114 static void output_addressed_constants (tree);
115 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
116 static unsigned min_align (unsigned, unsigned);
117 static void globalize_decl (tree);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_BSS
120 static void asm_output_bss (FILE *, tree, const char *,
121 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
123 #ifdef ASM_OUTPUT_ALIGNED_BSS
124 static void asm_output_aligned_bss (FILE *, tree, const char *,
125 unsigned HOST_WIDE_INT, int)
128 #endif /* BSS_SECTION_ASM_OP */
129 static void mark_weak (tree);
130 static void output_constant_pool (const char *, tree);
132 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
133 section *text_section;
134 section *data_section;
135 section *readonly_data_section;
136 section *sdata_section;
137 section *ctors_section;
138 section *dtors_section;
139 section *bss_section;
140 section *sbss_section;
142 /* Various forms of common section. All are guaranteed to be nonnull. */
143 section *tls_comm_section;
144 section *comm_section;
145 section *lcomm_section;
147 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
149 section *bss_noswitch_section;
151 /* The section that holds the main exception table, when known. The section
152 is set either by the target's init_sections hook or by the first call to
153 switch_to_exception_section. */
154 section *exception_section;
156 /* The section that holds the DWARF2 frame unwind information, when known.
157 The section is set either by the target's init_sections hook or by the
158 first call to switch_to_eh_frame_section. */
159 section *eh_frame_section;
161 /* asm_out_file's current section. This is NULL if no section has yet
162 been selected or if we lose track of what the current section is. */
165 /* True if code for the current function is currently being directed
166 at the cold section. */
167 bool in_cold_section_p;
169 /* A linked list of all the unnamed sections. */
170 static GTY(()) section *unnamed_sections;
172 /* Return a nonzero value if DECL has a section attribute. */
173 #define IN_NAMED_SECTION(DECL) \
174 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
175 && DECL_SECTION_NAME (DECL) != NULL_TREE)
177 /* Hash table of named sections. */
178 static GTY((param_is (section))) htab_t section_htab;
180 /* A table of object_blocks, indexed by section. */
181 static GTY((param_is (struct object_block))) htab_t object_block_htab;
183 /* The next number to use for internal anchor labels. */
184 static GTY(()) int anchor_labelno;
186 /* A pool of constants that can be shared between functions. */
187 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
193 static GTY (()) tree emutls_object_type;
194 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
195 macro can be used on them to distinguish the control variable from
196 the initialization template. */
197 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
199 #if !defined (NO_DOT_IN_LABEL)
200 # define EMUTLS_SEPARATOR "."
201 #elif !defined (NO_DOLLAR_IN_LABEL)
202 # define EMUTLS_SEPARATOR "$"
204 # define EMUTLS_SEPARATOR "_"
207 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
208 IDENTIFIER_NODE NAME's name. */
211 prefix_name (const char *prefix, tree name)
213 unsigned plen = strlen (prefix);
214 unsigned nlen = strlen (IDENTIFIER_POINTER (name));
215 char *toname = (char *) alloca (plen + nlen + 1);
217 memcpy (toname, prefix, plen);
218 memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
220 return get_identifier (toname);
223 /* Create an identifier for the struct __emutls_object, given an identifier
224 of the DECL_ASSEMBLY_NAME of the original object. */
227 get_emutls_object_name (tree name)
229 const char *prefix = (targetm.emutls.var_prefix
230 ? targetm.emutls.var_prefix
231 : "__emutls_v" EMUTLS_SEPARATOR);
232 return prefix_name (prefix, name);
236 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
238 tree word_type_node, field, next_field;
240 field = build_decl (UNKNOWN_LOCATION,
241 FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
242 DECL_CONTEXT (field) = type;
245 field = build_decl (UNKNOWN_LOCATION,
246 FIELD_DECL, get_identifier ("__offset"),
248 DECL_CONTEXT (field) = type;
249 DECL_CHAIN (field) = next_field;
252 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
253 field = build_decl (UNKNOWN_LOCATION,
254 FIELD_DECL, get_identifier ("__align"),
256 DECL_CONTEXT (field) = type;
257 DECL_CHAIN (field) = next_field;
260 field = build_decl (UNKNOWN_LOCATION,
261 FIELD_DECL, get_identifier ("__size"), word_type_node);
262 DECL_CONTEXT (field) = type;
263 DECL_CHAIN (field) = next_field;
268 /* Create the structure for struct __emutls_object. This should match the
269 structure at the top of emutls.c, modulo the union there. */
272 get_emutls_object_type (void)
274 tree type, type_name, field;
276 type = emutls_object_type;
280 emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
282 field = targetm.emutls.var_fields (type, &type_name);
284 type_name = get_identifier ("__emutls_object");
285 type_name = build_decl (UNKNOWN_LOCATION,
286 TYPE_DECL, type_name, type);
287 TYPE_NAME (type) = type_name;
288 TYPE_FIELDS (type) = field;
294 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
295 This will be used for initializing the emulated tls data area. */
298 get_emutls_init_templ_addr (tree decl)
302 if (targetm.emutls.register_common && !DECL_INITIAL (decl)
303 && !DECL_SECTION_NAME (decl))
304 return null_pointer_node;
306 name = DECL_ASSEMBLER_NAME (decl);
307 if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0])
309 const char *prefix = (targetm.emutls.tmpl_prefix
310 ? targetm.emutls.tmpl_prefix
311 : "__emutls_t" EMUTLS_SEPARATOR);
312 name = prefix_name (prefix, name);
315 to = build_decl (DECL_SOURCE_LOCATION (decl),
316 VAR_DECL, name, TREE_TYPE (decl));
317 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
319 DECL_ARTIFICIAL (to) = 1;
320 TREE_USED (to) = TREE_USED (decl);
321 TREE_READONLY (to) = 1;
322 DECL_IGNORED_P (to) = 1;
323 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
324 DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
325 DECL_PRESERVE_P (to) = DECL_PRESERVE_P (decl);
327 DECL_WEAK (to) = DECL_WEAK (decl);
328 if (DECL_ONE_ONLY (decl))
330 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
331 TREE_STATIC (to) = TREE_STATIC (decl);
332 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
333 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
336 TREE_STATIC (to) = 1;
338 DECL_VISIBILITY_SPECIFIED (to) = DECL_VISIBILITY_SPECIFIED (decl);
339 DECL_INITIAL (to) = DECL_INITIAL (decl);
340 DECL_INITIAL (decl) = NULL;
342 varpool_finalize_decl (to);
343 return build_fold_addr_expr (to);
346 /* When emulating tls, we use a control structure for use by the runtime.
347 Create and return this structure. */
350 emutls_decl (tree decl)
353 struct tree_map *h, in;
356 if (targetm.have_tls || decl == NULL || decl == error_mark_node
357 || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
360 /* Look up the object in the hash; return the control structure if
361 it has already been created. */
363 emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
365 name = DECL_ASSEMBLER_NAME (decl);
367 /* Note that we use the hash of the decl's name, rather than a hash
368 of the decl's pointer. In emutls_finish we iterate through the
369 hash table, and we want this traversal to be predictable. */
370 in.hash = IDENTIFIER_HASH_VALUE (name);
372 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
373 h = (struct tree_map *) *loc;
378 to = build_decl (DECL_SOURCE_LOCATION (decl),
379 VAR_DECL, get_emutls_object_name (name),
380 get_emutls_object_type ());
382 h = ggc_alloc_tree_map ();
386 *(struct tree_map **) loc = h;
388 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
389 DECL_ARTIFICIAL (to) = 1;
390 DECL_IGNORED_P (to) = 1;
391 /* FIXME: work around PR44132. */
392 DECL_PRESERVE_P (to) = 1;
393 TREE_READONLY (to) = 0;
394 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
395 if (DECL_ONE_ONLY (decl))
396 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
397 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
398 if (targetm.emutls.var_align_fixed)
399 /* If we're not allowed to change the proxy object's
400 alignment, pretend it's been set by the user. */
401 DECL_USER_ALIGN (to) = 1;
404 /* Note that these fields may need to be updated from time to time from
405 the original decl. Consider:
406 extern __thread int i;
407 int foo() { return i; }
409 in which I goes from external to locally defined and initialized. */
410 DECL_DLLIMPORT_P (to) = DECL_DLLIMPORT_P (decl);
411 DECL_ATTRIBUTES (to) = targetm.merge_decl_attributes (decl, to);
413 TREE_STATIC (to) = TREE_STATIC (decl);
414 TREE_USED (to) = TREE_USED (decl);
415 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
416 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
417 DECL_COMMON (to) = DECL_COMMON (decl);
418 DECL_WEAK (to) = DECL_WEAK (decl);
419 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
420 DECL_VISIBILITY_SPECIFIED (to) = DECL_VISIBILITY_SPECIFIED (decl);
422 /* Fortran might pass this to us. */
423 DECL_RESTRICTED_P (to) = DECL_RESTRICTED_P (decl);
429 emutls_common_1 (void **loc, void *xstmts)
431 struct tree_map *h = *(struct tree_map **) loc;
432 tree x, *pstmts = (tree *) xstmts;
435 if (! DECL_COMMON (h->base.from)
436 || (DECL_INITIAL (h->base.from)
437 && DECL_INITIAL (h->base.from) != error_mark_node))
440 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
442 /* The idea was to call get_emutls_init_templ_addr here, but if we
443 do this and there is an initializer, -fanchor_section loses,
444 because it would be too late to ensure the template is
446 x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
447 x = build_call_expr (x, 4,
448 build_fold_addr_expr (h->to),
449 fold_convert (word_type_node,
450 DECL_SIZE_UNIT (h->base.from)),
451 build_int_cst (word_type_node,
452 DECL_ALIGN_UNIT (h->base.from)),
455 append_to_statement_list (x, pstmts);
459 /* Callback to finalize one emutls control variable. */
462 emutls_finalize_control_var (void **loc,
463 void *unused ATTRIBUTE_UNUSED)
465 struct tree_map *h = *(struct tree_map **) loc;
468 struct varpool_node *node = varpool_node (h->to);
469 /* Because varpool_finalize_decl () has side-effects,
470 only apply to un-finalized vars. */
471 if (node && !node->finalized)
472 varpool_finalize_decl (h->to);
477 /* Finalize emutls control vars and add a static constructor if
483 if (emutls_htab == NULL)
485 htab_traverse_noresize (emutls_htab,
486 emutls_finalize_control_var, NULL);
488 if (targetm.emutls.register_common)
490 tree body = NULL_TREE;
492 htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
493 if (body == NULL_TREE)
496 cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
500 /* Helper routines for maintaining section_htab. */
503 section_entry_eq (const void *p1, const void *p2)
505 const section *old = (const section *) p1;
506 const char *new_name = (const char *) p2;
508 return strcmp (old->named.name, new_name) == 0;
512 section_entry_hash (const void *p)
514 const section *old = (const section *) p;
515 return htab_hash_string (old->named.name);
518 /* Return a hash value for section SECT. */
521 hash_section (section *sect)
523 if (sect->common.flags & SECTION_NAMED)
524 return htab_hash_string (sect->named.name);
525 return sect->common.flags;
528 /* Helper routines for maintaining object_block_htab. */
531 object_block_entry_eq (const void *p1, const void *p2)
533 const struct object_block *old = (const struct object_block *) p1;
534 const section *new_section = (const section *) p2;
536 return old->sect == new_section;
540 object_block_entry_hash (const void *p)
542 const struct object_block *old = (const struct object_block *) p;
543 return hash_section (old->sect);
546 /* Return a new unnamed section with the given fields. */
549 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
554 sect = ggc_alloc_section ();
555 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
556 sect->unnamed.callback = callback;
557 sect->unnamed.data = data;
558 sect->unnamed.next = unnamed_sections;
560 unnamed_sections = sect;
564 /* Return a SECTION_NOSWITCH section with the given fields. */
567 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
571 sect = ggc_alloc_section ();
572 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
573 sect->noswitch.callback = callback;
578 /* Return the named section structure associated with NAME. Create
579 a new section with the given fields if no such structure exists. */
582 get_section (const char *name, unsigned int flags, tree decl)
584 section *sect, **slot;
587 htab_find_slot_with_hash (section_htab, name,
588 htab_hash_string (name), INSERT);
589 flags |= SECTION_NAMED;
592 sect = ggc_alloc_section ();
593 sect->named.common.flags = flags;
594 sect->named.name = ggc_strdup (name);
595 sect->named.decl = decl;
601 if ((sect->common.flags & ~SECTION_DECLARED) != flags
602 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
604 /* Sanity check user variables for flag changes. */
606 decl = sect->named.decl;
608 error ("%+D causes a section type conflict", decl);
614 /* Return true if the current compilation mode benefits from having
615 objects grouped into blocks. */
618 use_object_blocks_p (void)
620 return flag_section_anchors;
623 /* Return the object_block structure for section SECT. Create a new
624 structure if we haven't created one already. Return null if SECT
627 static struct object_block *
628 get_block_for_section (section *sect)
630 struct object_block *block;
636 slot = htab_find_slot_with_hash (object_block_htab, sect,
637 hash_section (sect), INSERT);
638 block = (struct object_block *) *slot;
641 block = ggc_alloc_cleared_object_block ();
648 /* Create a symbol with label LABEL and place it at byte offset
649 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
650 is not yet known. LABEL must be a garbage-collected string. */
653 create_block_symbol (const char *label, struct object_block *block,
654 HOST_WIDE_INT offset)
659 /* Create the extended SYMBOL_REF. */
660 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
661 symbol = ggc_alloc_zone_rtx_def (size, &rtl_zone);
663 /* Initialize the normal SYMBOL_REF fields. */
664 memset (symbol, 0, size);
665 PUT_CODE (symbol, SYMBOL_REF);
666 PUT_MODE (symbol, Pmode);
667 XSTR (symbol, 0) = label;
668 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
670 /* Initialize the block_symbol stuff. */
671 SYMBOL_REF_BLOCK (symbol) = block;
672 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
678 initialize_cold_section_name (void)
680 const char *stripped_name;
684 gcc_assert (cfun && current_function_decl);
685 if (crtl->subsections.unlikely_text_section_name)
688 dsn = DECL_SECTION_NAME (current_function_decl);
689 if (flag_function_sections && dsn)
691 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
692 memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
694 stripped_name = targetm.strip_name_encoding (name);
696 buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
697 crtl->subsections.unlikely_text_section_name = ggc_strdup (buffer);
700 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
703 /* Tell assembler to switch to unlikely-to-be-executed text section. */
706 unlikely_text_section (void)
710 if (!crtl->subsections.unlikely_text_section_name)
711 initialize_cold_section_name ();
713 return get_named_section (NULL, crtl->subsections.unlikely_text_section_name, 0);
716 return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
719 /* When called within a function context, return true if the function
720 has been assigned a cold text section and if SECT is that section.
721 When called outside a function context, return true if SECT is the
722 default cold section. */
725 unlikely_text_section_p (section *sect)
730 name = crtl->subsections.unlikely_text_section_name;
732 name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
736 && SECTION_STYLE (sect) == SECTION_NAMED
737 && strcmp (name, sect->named.name) == 0);
740 /* Return a section with a particular name and with whatever SECTION_*
741 flags section_type_flags deems appropriate. The name of the section
742 is taken from NAME if nonnull, otherwise it is taken from DECL's
743 DECL_SECTION_NAME. DECL is the decl associated with the section
744 (see the section comment for details) and RELOC is as for
745 section_type_flags. */
748 get_named_section (tree decl, const char *name, int reloc)
752 gcc_assert (!decl || DECL_P (decl));
754 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
756 flags = targetm.section_type_flags (decl, name, reloc);
758 return get_section (name, flags, decl);
761 /* If required, set DECL_SECTION_NAME to a unique name. */
764 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
765 int flag_function_or_data_sections)
767 if (DECL_SECTION_NAME (decl) == NULL_TREE
768 && targetm.have_named_sections
769 && (flag_function_or_data_sections
770 || DECL_ONE_ONLY (decl)))
771 targetm.asm_out.unique_section (decl, reloc);
774 #ifdef BSS_SECTION_ASM_OP
776 #ifdef ASM_OUTPUT_BSS
778 /* Utility function for ASM_OUTPUT_BSS for targets to use if
779 they don't support alignments in .bss.
780 ??? It is believed that this function will work in most cases so such
781 support is localized here. */
784 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
786 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
787 unsigned HOST_WIDE_INT rounded)
789 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl), 0), 0), name) == 0);
790 targetm.asm_out.globalize_decl_name (file, decl);
791 switch_to_section (bss_section);
792 #ifdef ASM_DECLARE_OBJECT_NAME
793 last_assemble_variable_decl = decl;
794 ASM_DECLARE_OBJECT_NAME (file, name, decl);
796 /* Standard thing is just output label for the object. */
797 ASM_OUTPUT_LABEL (file, name);
798 #endif /* ASM_DECLARE_OBJECT_NAME */
799 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
804 #ifdef ASM_OUTPUT_ALIGNED_BSS
806 /* Utility function for targets to use in implementing
807 ASM_OUTPUT_ALIGNED_BSS.
808 ??? It is believed that this function will work in most cases so such
809 support is localized here. */
812 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
813 const char *name, unsigned HOST_WIDE_INT size,
816 switch_to_section (bss_section);
817 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
818 #ifdef ASM_DECLARE_OBJECT_NAME
819 last_assemble_variable_decl = decl;
820 ASM_DECLARE_OBJECT_NAME (file, name, decl);
822 /* Standard thing is just output label for the object. */
823 ASM_OUTPUT_LABEL (file, name);
824 #endif /* ASM_DECLARE_OBJECT_NAME */
825 ASM_OUTPUT_SKIP (file, size ? size : 1);
830 #endif /* BSS_SECTION_ASM_OP */
832 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
833 /* Return the hot section for function DECL. Return text_section for
837 hot_function_section (tree decl)
839 if (decl != NULL_TREE
840 && DECL_SECTION_NAME (decl) != NULL_TREE
841 && targetm.have_named_sections)
842 return get_named_section (decl, NULL, 0);
848 /* Return the section for function DECL.
850 If DECL is NULL_TREE, return the text section. We can be passed
851 NULL_TREE under some circumstances by dbxout.c at least. */
854 function_section (tree decl)
858 if (first_function_block_is_cold)
861 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
862 if (decl != NULL_TREE
863 && DECL_SECTION_NAME (decl) != NULL_TREE)
864 return reloc ? unlikely_text_section ()
865 : get_named_section (decl, NULL, 0);
867 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
869 return reloc ? unlikely_text_section () : hot_function_section (decl);
874 current_function_section (void)
876 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
877 if (current_function_decl != NULL_TREE
878 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
879 return in_cold_section_p ? unlikely_text_section ()
880 : get_named_section (current_function_decl,
883 return targetm.asm_out.select_section (current_function_decl,
885 DECL_ALIGN (current_function_decl));
887 return (in_cold_section_p
888 ? unlikely_text_section ()
889 : hot_function_section (current_function_decl));
893 /* Return the read-only data section associated with function DECL. */
896 default_function_rodata_section (tree decl)
898 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
900 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
902 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
908 dot = strchr (name + 1, '.');
911 len = strlen (dot) + 8;
912 rname = (char *) alloca (len);
914 strcpy (rname, ".rodata");
916 return get_section (rname, SECTION_LINKONCE, decl);
918 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
919 else if (DECL_ONE_ONLY (decl)
920 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
922 size_t len = strlen (name) + 1;
923 char *rname = (char *) alloca (len);
925 memcpy (rname, name, len);
927 return get_section (rname, SECTION_LINKONCE, decl);
929 /* For .text.foo we want to use .rodata.foo. */
930 else if (flag_function_sections && flag_data_sections
931 && strncmp (name, ".text.", 6) == 0)
933 size_t len = strlen (name) + 1;
934 char *rname = (char *) alloca (len + 2);
936 memcpy (rname, ".rodata", 7);
937 memcpy (rname + 7, name + 5, len - 5);
938 return get_section (rname, 0, decl);
942 return readonly_data_section;
945 /* Return the read-only data section associated with function DECL
946 for targets where that section should be always the single
947 readonly data section. */
950 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
952 return readonly_data_section;
955 /* Return the section to use for string merging. */
958 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
959 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
960 unsigned int flags ATTRIBUTE_UNUSED)
964 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
965 && TREE_CODE (decl) == STRING_CST
966 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
968 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
969 && TREE_STRING_LENGTH (decl) >= len)
971 enum machine_mode mode;
972 unsigned int modesize;
978 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
979 modesize = GET_MODE_BITSIZE (mode);
980 if (modesize >= 8 && modesize <= 256
981 && (modesize & (modesize - 1)) == 0)
983 if (align < modesize)
986 str = TREE_STRING_POINTER (decl);
987 unit = GET_MODE_SIZE (mode);
989 /* Check for embedded NUL characters. */
990 for (i = 0; i < len; i += unit)
992 for (j = 0; j < unit; j++)
993 if (str[i + j] != '\0')
1000 sprintf (name, ".rodata.str%d.%d", modesize / 8,
1002 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
1003 return get_section (name, flags, NULL);
1008 return readonly_data_section;
1011 /* Return the section to use for constant merging. */
1014 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
1015 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
1016 unsigned int flags ATTRIBUTE_UNUSED)
1018 unsigned int modesize = GET_MODE_BITSIZE (mode);
1020 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
1023 && modesize <= align
1026 && (align & (align - 1)) == 0)
1030 sprintf (name, ".rodata.cst%d", (int) (align / 8));
1031 flags |= (align / 8) | SECTION_MERGE;
1032 return get_section (name, flags, NULL);
1034 return readonly_data_section;
1037 /* Given NAME, a putative register name, discard any customary prefixes. */
1040 strip_reg_name (const char *name)
1042 #ifdef REGISTER_PREFIX
1043 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
1044 name += strlen (REGISTER_PREFIX);
1046 if (name[0] == '%' || name[0] == '#')
1051 /* The user has asked for a DECL to have a particular name. Set (or
1052 change) it in such a way that we don't prefix an underscore to
1055 set_user_assembler_name (tree decl, const char *name)
1057 char *starred = (char *) alloca (strlen (name) + 2);
1059 strcpy (starred + 1, name);
1060 change_decl_assembler_name (decl, get_identifier (starred));
1061 SET_DECL_RTL (decl, NULL_RTX);
1064 /* Decode an `asm' spec for a declaration as a register name.
1065 Return the register number, or -1 if nothing specified,
1066 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1067 or -3 if ASMSPEC is `cc' and is not recognized,
1068 or -4 if ASMSPEC is `memory' and is not recognized.
1069 Accept an exact spelling or a decimal number.
1070 Prefixes such as % are optional. */
1073 decode_reg_name (const char *asmspec)
1079 /* Get rid of confusing prefixes. */
1080 asmspec = strip_reg_name (asmspec);
1082 /* Allow a decimal number as a "register name". */
1083 for (i = strlen (asmspec) - 1; i >= 0; i--)
1084 if (! ISDIGIT (asmspec[i]))
1086 if (asmspec[0] != 0 && i < 0)
1089 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
1095 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1097 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1100 #ifdef ADDITIONAL_REGISTER_NAMES
1102 static const struct { const char *const name; const int number; } table[]
1103 = ADDITIONAL_REGISTER_NAMES;
1105 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1106 if (table[i].name[0]
1107 && ! strcmp (asmspec, table[i].name))
1108 return table[i].number;
1110 #endif /* ADDITIONAL_REGISTER_NAMES */
1112 if (!strcmp (asmspec, "memory"))
1115 if (!strcmp (asmspec, "cc"))
1124 /* Return true if DECL's initializer is suitable for a BSS section. */
1127 bss_initializer_p (const_tree decl)
1129 return (DECL_INITIAL (decl) == NULL
1130 || DECL_INITIAL (decl) == error_mark_node
1131 || (flag_zero_initialized_in_bss
1132 /* Leave constant zeroes in .rodata so they
1134 && !TREE_READONLY (decl)
1135 && initializer_zerop (DECL_INITIAL (decl))));
1138 /* Compute the alignment of variable specified by DECL.
1139 DONT_OUTPUT_DATA is from assemble_variable. */
1142 align_variable (tree decl, bool dont_output_data)
1144 unsigned int align = DECL_ALIGN (decl);
1146 /* In the case for initialing an array whose length isn't specified,
1147 where we have not yet been able to do the layout,
1148 figure out the proper alignment now. */
1149 if (dont_output_data && DECL_SIZE (decl) == 0
1150 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1151 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1153 /* Some object file formats have a maximum alignment which they support.
1154 In particular, a.out format supports a maximum alignment of 4. */
1155 if (align > MAX_OFILE_ALIGNMENT)
1157 warning (0, "alignment of %q+D is greater than maximum object "
1158 "file alignment. Using %d", decl,
1159 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1160 align = MAX_OFILE_ALIGNMENT;
1163 /* On some machines, it is good to increase alignment sometimes. */
1164 if (! DECL_USER_ALIGN (decl))
1166 #ifdef DATA_ALIGNMENT
1167 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1168 /* Don't increase alignment too much for TLS variables - TLS space
1170 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1173 #ifdef CONSTANT_ALIGNMENT
1174 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1176 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
1178 /* Don't increase alignment too much for TLS variables - TLS space
1180 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1181 align = const_align;
1186 /* Reset the alignment in case we have made it tighter, so we can benefit
1187 from it in get_pointer_alignment. */
1188 DECL_ALIGN (decl) = align;
1191 /* Return the section into which the given VAR_DECL or CONST_DECL
1192 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1193 section should be used wherever possible. */
1196 get_variable_section (tree decl, bool prefer_noswitch_p)
1198 addr_space_t as = ADDR_SPACE_GENERIC;
1201 if (TREE_TYPE (decl) != error_mark_node)
1202 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1204 if (DECL_COMMON (decl))
1206 /* If the decl has been given an explicit section name, or it resides
1207 in a non-generic address space, then it isn't common, and shouldn't
1208 be handled as such. */
1209 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1210 && ADDR_SPACE_GENERIC_P (as));
1211 if (DECL_THREAD_LOCAL_P (decl))
1212 return tls_comm_section;
1213 /* This cannot be common bss for an emulated TLS object without
1214 a register_common hook. */
1215 else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED
1216 && !targetm.emutls.register_common)
1218 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1219 return comm_section;
1222 if (DECL_INITIAL (decl) == error_mark_node)
1223 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1224 else if (DECL_INITIAL (decl))
1225 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1229 resolve_unique_section (decl, reloc, flag_data_sections);
1230 if (IN_NAMED_SECTION (decl))
1231 return get_named_section (decl, NULL, reloc);
1233 if (ADDR_SPACE_GENERIC_P (as)
1234 && !DECL_THREAD_LOCAL_P (decl)
1235 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1236 && bss_initializer_p (decl))
1238 if (!TREE_PUBLIC (decl))
1239 return lcomm_section;
1240 if (bss_noswitch_section)
1241 return bss_noswitch_section;
1244 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1247 /* Return the block into which object_block DECL should be placed. */
1249 static struct object_block *
1250 get_block_for_decl (tree decl)
1254 if (TREE_CODE (decl) == VAR_DECL)
1256 /* The object must be defined in this translation unit. */
1257 if (DECL_EXTERNAL (decl))
1260 /* There's no point using object blocks for something that is
1261 isolated by definition. */
1262 if (DECL_ONE_ONLY (decl))
1266 /* We can only calculate block offsets if the decl has a known
1268 if (DECL_SIZE_UNIT (decl) == NULL)
1270 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1273 /* Find out which section should contain DECL. We cannot put it into
1274 an object block if it requires a standalone definition. */
1275 if (TREE_CODE (decl) == VAR_DECL)
1276 align_variable (decl, 0);
1277 sect = get_variable_section (decl, true);
1278 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1281 return get_block_for_section (sect);
1284 /* Make sure block symbol SYMBOL is in block BLOCK. */
1287 change_symbol_block (rtx symbol, struct object_block *block)
1289 if (block != SYMBOL_REF_BLOCK (symbol))
1291 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1292 SYMBOL_REF_BLOCK (symbol) = block;
1296 /* Return true if it is possible to put DECL in an object_block. */
1299 use_blocks_for_decl_p (tree decl)
1301 /* Only data DECLs can be placed into object blocks. */
1302 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1305 /* Detect decls created by dw2_force_const_mem. Such decls are
1306 special because DECL_INITIAL doesn't specify the decl's true value.
1307 dw2_output_indirect_constants will instead call assemble_variable
1308 with dont_output_data set to 1 and then print the contents itself. */
1309 if (DECL_INITIAL (decl) == decl)
1312 /* If this decl is an alias, then we don't want to emit a definition. */
1313 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1319 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1320 have static storage duration. In other words, it should not be an
1321 automatic variable, including PARM_DECLs.
1323 There is, however, one exception: this function handles variables
1324 explicitly placed in a particular register by the user.
1326 This is never called for PARM_DECL nodes. */
1329 make_decl_rtl (tree decl)
1331 const char *name = 0;
1335 /* Check that we are not being given an automatic variable. */
1336 gcc_assert (TREE_CODE (decl) != PARM_DECL
1337 && TREE_CODE (decl) != RESULT_DECL);
1339 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1340 gcc_assert (TREE_CODE (decl) != VAR_DECL
1341 || TREE_STATIC (decl)
1342 || TREE_PUBLIC (decl)
1343 || DECL_EXTERNAL (decl)
1344 || DECL_REGISTER (decl));
1346 /* And that we were not given a type or a label. */
1347 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1348 && TREE_CODE (decl) != LABEL_DECL);
1350 /* For a duplicate declaration, we can be called twice on the
1351 same DECL node. Don't discard the RTL already made. */
1352 if (DECL_RTL_SET_P (decl))
1354 /* If the old RTL had the wrong mode, fix the mode. */
1355 x = DECL_RTL (decl);
1356 if (GET_MODE (x) != DECL_MODE (decl))
1357 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1359 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1362 /* ??? Another way to do this would be to maintain a hashed
1363 table of such critters. Instead of adding stuff to a DECL
1364 to give certain attributes to it, we could use an external
1365 hash map from DECL to set of attributes. */
1367 /* Let the target reassign the RTL if it wants.
1368 This is necessary, for example, when one machine specific
1369 decl attribute overrides another. */
1370 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1372 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1373 on the new decl information. */
1375 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1376 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1377 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1379 /* Make this function static known to the mudflap runtime. */
1380 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1381 mudflap_enqueue_decl (decl);
1386 /* If this variable belongs to the global constant pool, retrieve the
1387 pre-computed RTL or recompute it in LTO mode. */
1388 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1390 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1394 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1396 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1397 && DECL_REGISTER (decl))
1399 error ("register name not specified for %q+D", decl);
1401 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1403 const char *asmspec = name+1;
1404 reg_number = decode_reg_name (asmspec);
1405 /* First detect errors in declaring global registers. */
1406 if (reg_number == -1)
1407 error ("register name not specified for %q+D", decl);
1408 else if (reg_number < 0)
1409 error ("invalid register name for %q+D", decl);
1410 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1411 error ("data type of %q+D isn%'t suitable for a register",
1413 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1414 error ("register specified for %q+D isn%'t suitable for data type",
1416 /* Now handle properly declared static register variables. */
1421 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1423 DECL_INITIAL (decl) = 0;
1424 error ("global register variable has initial value");
1426 if (TREE_THIS_VOLATILE (decl))
1427 warning (OPT_Wvolatile_register_var,
1428 "optimization may eliminate reads and/or "
1429 "writes to register variables");
1431 /* If the user specified one of the eliminables registers here,
1432 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1433 confused with that register and be eliminated. This usage is
1434 somewhat suspect... */
1436 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1437 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1438 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1440 if (TREE_STATIC (decl))
1442 /* Make this register global, so not usable for anything
1444 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1445 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1446 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1448 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1450 globalize_reg (reg_number + --nregs);
1453 /* As a register variable, it has no section. */
1457 /* Now handle ordinary static variables and functions (in memory).
1458 Also handle vars declared register invalidly. */
1459 else if (name[0] == '*')
1461 #ifdef REGISTER_PREFIX
1462 if (strlen (REGISTER_PREFIX) != 0)
1464 reg_number = decode_reg_name (name);
1465 if (reg_number >= 0 || reg_number == -3)
1466 error ("register name given for non-register variable %q+D", decl);
1471 /* Specifying a section attribute on a variable forces it into a
1472 non-.bss section, and thus it cannot be common. */
1473 /* FIXME: In general this code should not be necessary because
1474 visibility pass is doing the same work. But notice_global_symbol
1475 is called early and it needs to make DECL_RTL to get the name.
1476 we take care of recomputing the DECL_RTL after visibility is changed. */
1477 if (TREE_CODE (decl) == VAR_DECL
1478 && DECL_SECTION_NAME (decl) != NULL_TREE
1479 && DECL_INITIAL (decl) == NULL_TREE
1480 && DECL_COMMON (decl))
1481 DECL_COMMON (decl) = 0;
1483 /* Variables can't be both common and weak. */
1484 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1485 DECL_COMMON (decl) = 0;
1487 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1488 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1491 enum machine_mode address_mode = Pmode;
1492 if (TREE_TYPE (decl) != error_mark_node)
1494 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1495 address_mode = targetm.addr_space.address_mode (as);
1497 x = gen_rtx_SYMBOL_REF (address_mode, name);
1499 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1500 SET_SYMBOL_REF_DECL (x, decl);
1502 x = gen_rtx_MEM (DECL_MODE (decl), x);
1503 if (TREE_CODE (decl) != FUNCTION_DECL)
1504 set_mem_attributes (x, decl, 1);
1505 SET_DECL_RTL (decl, x);
1507 /* Optionally set flags or add text to the name to record information
1508 such as that it is a function name.
1509 If the name is changed, the macro ASM_OUTPUT_LABELREF
1510 will have to know how to strip this information. */
1511 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1513 /* Make this function static known to the mudflap runtime. */
1514 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1515 mudflap_enqueue_decl (decl);
1518 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1519 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1523 make_decl_rtl_for_debug (tree decl)
1525 unsigned int save_aliasing_flag, save_mudflap_flag;
1528 if (DECL_RTL_SET_P (decl))
1529 return DECL_RTL (decl);
1531 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1532 call new_alias_set. If running with -fcompare-debug, sometimes
1533 we do not want to create alias sets that will throw the alias
1534 numbers off in the comparison dumps. So... clearing
1535 flag_strict_aliasing will keep new_alias_set() from creating a
1536 new set. It is undesirable to register decl with mudflap
1537 in this case as well. */
1538 save_aliasing_flag = flag_strict_aliasing;
1539 flag_strict_aliasing = 0;
1540 save_mudflap_flag = flag_mudflap;
1543 rtl = DECL_RTL (decl);
1544 /* Reset DECL_RTL back, as various parts of the compiler expects
1545 DECL_RTL set meaning it is actually going to be output. */
1546 SET_DECL_RTL (decl, NULL);
1548 flag_strict_aliasing = save_aliasing_flag;
1549 flag_mudflap = save_mudflap_flag;
1554 /* Output a string of literal assembler code
1555 for an `asm' keyword used between functions. */
1558 assemble_asm (tree string)
1562 if (TREE_CODE (string) == ADDR_EXPR)
1563 string = TREE_OPERAND (string, 0);
1565 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1568 /* Record an element in the table of global destructors. SYMBOL is
1569 a SYMBOL_REF of the function to be called; PRIORITY is a number
1570 between 0 and MAX_INIT_PRIORITY. */
1573 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1574 int priority ATTRIBUTE_UNUSED)
1576 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1577 /* Tell GNU LD that this is part of the static destructor set.
1578 This will work for any system that uses stabs, most usefully
1580 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1581 dbxout_stab_value_label (XSTR (symbol, 0));
1583 sorry ("global destructors not supported on this target");
1587 /* Write the address of the entity given by SYMBOL to SEC. */
1589 assemble_addr_to_section (rtx symbol, section *sec)
1591 switch_to_section (sec);
1592 assemble_align (POINTER_SIZE);
1593 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1596 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1597 not) section for PRIORITY. */
1599 get_cdtor_priority_section (int priority, bool constructor_p)
1603 /* ??? This only works reliably with the GNU linker. */
1604 sprintf (buf, "%s.%.5u",
1605 constructor_p ? ".ctors" : ".dtors",
1606 /* Invert the numbering so the linker puts us in the proper
1607 order; constructors are run from right to left, and the
1608 linker sorts in increasing order. */
1609 MAX_INIT_PRIORITY - priority);
1610 return get_section (buf, SECTION_WRITE, NULL);
1614 default_named_section_asm_out_destructor (rtx symbol, int priority)
1618 if (priority != DEFAULT_INIT_PRIORITY)
1619 sec = get_cdtor_priority_section (priority,
1620 /*constructor_p=*/false);
1622 sec = get_section (".dtors", SECTION_WRITE, NULL);
1624 assemble_addr_to_section (symbol, sec);
1627 #ifdef DTORS_SECTION_ASM_OP
1629 default_dtor_section_asm_out_destructor (rtx symbol,
1630 int priority ATTRIBUTE_UNUSED)
1632 assemble_addr_to_section (symbol, dtors_section);
1636 /* Likewise for global constructors. */
1639 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1640 int priority ATTRIBUTE_UNUSED)
1642 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1643 /* Tell GNU LD that this is part of the static destructor set.
1644 This will work for any system that uses stabs, most usefully
1646 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1647 dbxout_stab_value_label (XSTR (symbol, 0));
1649 sorry ("global constructors not supported on this target");
1654 default_named_section_asm_out_constructor (rtx symbol, int priority)
1658 if (priority != DEFAULT_INIT_PRIORITY)
1659 sec = get_cdtor_priority_section (priority,
1660 /*constructor_p=*/true);
1662 sec = get_section (".ctors", SECTION_WRITE, NULL);
1664 assemble_addr_to_section (symbol, sec);
1667 #ifdef CTORS_SECTION_ASM_OP
1669 default_ctor_section_asm_out_constructor (rtx symbol,
1670 int priority ATTRIBUTE_UNUSED)
1672 assemble_addr_to_section (symbol, ctors_section);
1676 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1677 a nonzero value if the constant pool should be output before the
1678 start of the function, or a zero value if the pool should output
1679 after the end of the function. The default is to put it before the
1682 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1683 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1686 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1687 to be output to assembler.
1688 Set first_global_object_name and weak_global_object_name as appropriate. */
1691 notice_global_symbol (tree decl)
1693 const char **type = &first_global_object_name;
1695 if (first_global_object_name
1696 || !TREE_PUBLIC (decl)
1697 || DECL_EXTERNAL (decl)
1698 || !DECL_NAME (decl)
1699 || (TREE_CODE (decl) != FUNCTION_DECL
1700 && (TREE_CODE (decl) != VAR_DECL
1701 || (DECL_COMMON (decl)
1702 && (DECL_INITIAL (decl) == 0
1703 || DECL_INITIAL (decl) == error_mark_node))))
1704 || !MEM_P (DECL_RTL (decl)))
1707 /* We win when global object is found, but it is useful to know about weak
1708 symbol as well so we can produce nicer unique names. */
1709 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1710 type = &weak_global_object_name;
1716 rtx decl_rtl = DECL_RTL (decl);
1718 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1719 name = ggc_strdup (p);
1725 /* Output assembler code for the constant pool of a function and associated
1726 with defining the name of the function. DECL describes the function.
1727 NAME is the function's name. For the constant pool, we use the current
1728 constant pool data. */
1731 assemble_start_function (tree decl, const char *fnname)
1734 char tmp_label[100];
1735 bool hot_label_written = false;
1737 crtl->subsections.unlikely_text_section_name = NULL;
1739 first_function_block_is_cold = false;
1740 if (flag_reorder_blocks_and_partition)
1742 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1743 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1744 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1745 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1746 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1747 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1748 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1749 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1754 crtl->subsections.hot_section_label = NULL;
1755 crtl->subsections.cold_section_label = NULL;
1756 crtl->subsections.hot_section_end_label = NULL;
1757 crtl->subsections.cold_section_end_label = NULL;
1760 /* The following code does not need preprocessing in the assembler. */
1764 if (CONSTANT_POOL_BEFORE_FUNCTION)
1765 output_constant_pool (fnname, decl);
1767 resolve_unique_section (decl, 0, flag_function_sections);
1769 /* Make sure the not and cold text (code) sections are properly
1770 aligned. This is necessary here in the case where the function
1771 has both hot and cold sections, because we don't want to re-set
1772 the alignment when the section switch happens mid-function. */
1774 if (flag_reorder_blocks_and_partition)
1776 switch_to_section (unlikely_text_section ());
1777 assemble_align (DECL_ALIGN (decl));
1778 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1780 /* When the function starts with a cold section, we need to explicitly
1781 align the hot section and write out the hot section label.
1782 But if the current function is a thunk, we do not have a CFG. */
1784 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1786 switch_to_section (text_section);
1787 assemble_align (DECL_ALIGN (decl));
1788 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1789 hot_label_written = true;
1790 first_function_block_is_cold = true;
1793 else if (DECL_SECTION_NAME (decl))
1795 /* Calls to function_section rely on first_function_block_is_cold
1796 being accurate. The first block may be cold even if we aren't
1797 doing partitioning, if the entire function was decided by
1798 choose_function_section (predict.c) to be cold. */
1800 initialize_cold_section_name ();
1802 if (crtl->subsections.unlikely_text_section_name
1803 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1804 crtl->subsections.unlikely_text_section_name) == 0)
1805 first_function_block_is_cold = true;
1808 in_cold_section_p = first_function_block_is_cold;
1810 /* Switch to the correct text section for the start of the function. */
1812 switch_to_section (function_section (decl));
1813 if (flag_reorder_blocks_and_partition
1814 && !hot_label_written)
1815 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1817 /* Tell assembler to move to target machine's alignment for functions. */
1818 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1821 ASM_OUTPUT_ALIGN (asm_out_file, align);
1824 /* Handle a user-specified function alignment.
1825 Note that we still need to align to DECL_ALIGN, as above,
1826 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1827 if (! DECL_USER_ALIGN (decl)
1828 && align_functions_log > align
1829 && optimize_function_for_speed_p (cfun))
1831 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1832 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1833 align_functions_log, align_functions - 1);
1835 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1839 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1840 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1843 if (!DECL_IGNORED_P (decl))
1844 (*debug_hooks->begin_function) (decl);
1846 /* Make function name accessible from other files, if appropriate. */
1848 if (TREE_PUBLIC (decl))
1850 notice_global_symbol (decl);
1852 globalize_decl (decl);
1854 maybe_assemble_visibility (decl);
1857 if (DECL_PRESERVE_P (decl))
1858 targetm.asm_out.mark_decl_preserved (fnname);
1860 /* Do any machine/system dependent processing of the function name. */
1861 #ifdef ASM_DECLARE_FUNCTION_NAME
1862 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1864 /* Standard thing is just output label for the function. */
1865 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
1866 #endif /* ASM_DECLARE_FUNCTION_NAME */
1869 /* Output assembler code associated with defining the size of the
1870 function. DECL describes the function. NAME is the function's name. */
1873 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1875 #ifdef ASM_DECLARE_FUNCTION_SIZE
1876 /* We could have switched section in the middle of the function. */
1877 if (flag_reorder_blocks_and_partition)
1878 switch_to_section (function_section (decl));
1879 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1881 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1883 output_constant_pool (fnname, decl);
1884 switch_to_section (function_section (decl)); /* need to switch back */
1886 /* Output labels for end of hot/cold text sections (to be used by
1888 if (flag_reorder_blocks_and_partition)
1890 section *save_text_section;
1892 save_text_section = in_section;
1893 switch_to_section (unlikely_text_section ());
1894 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1895 if (first_function_block_is_cold)
1896 switch_to_section (text_section);
1898 switch_to_section (function_section (decl));
1899 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1900 switch_to_section (save_text_section);
1904 /* Assemble code to leave SIZE bytes of zeros. */
1907 assemble_zeros (unsigned HOST_WIDE_INT size)
1909 /* Do no output if -fsyntax-only. */
1910 if (flag_syntax_only)
1913 #ifdef ASM_NO_SKIP_IN_TEXT
1914 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1915 so we must output 0s explicitly in the text section. */
1916 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1918 unsigned HOST_WIDE_INT i;
1919 for (i = 0; i < size; i++)
1920 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1925 ASM_OUTPUT_SKIP (asm_out_file, size);
1928 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1931 assemble_align (int align)
1933 if (align > BITS_PER_UNIT)
1935 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1939 /* Assemble a string constant with the specified C string as contents. */
1942 assemble_string (const char *p, int size)
1947 /* If the string is very long, split it up. */
1951 int thissize = size - pos;
1952 if (thissize > maximum)
1955 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1963 /* A noswitch_section_callback for lcomm_section. */
1966 emit_local (tree decl ATTRIBUTE_UNUSED,
1967 const char *name ATTRIBUTE_UNUSED,
1968 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1969 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1971 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1972 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1973 size, DECL_ALIGN (decl));
1975 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1976 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1979 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1984 /* A noswitch_section_callback for bss_noswitch_section. */
1986 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1988 emit_bss (tree decl ATTRIBUTE_UNUSED,
1989 const char *name ATTRIBUTE_UNUSED,
1990 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1991 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1993 #if defined ASM_OUTPUT_ALIGNED_BSS
1994 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1997 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
2003 /* A noswitch_section_callback for comm_section. */
2006 emit_common (tree decl ATTRIBUTE_UNUSED,
2007 const char *name ATTRIBUTE_UNUSED,
2008 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2009 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2011 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
2012 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
2013 size, DECL_ALIGN (decl));
2015 #elif defined ASM_OUTPUT_ALIGNED_COMMON
2016 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
2019 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
2024 /* A noswitch_section_callback for tls_comm_section. */
2027 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
2028 const char *name ATTRIBUTE_UNUSED,
2029 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2030 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2032 #ifdef ASM_OUTPUT_TLS_COMMON
2033 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
2036 sorry ("thread-local COMMON data not implemented");
2041 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2042 NAME is the name of DECL's SYMBOL_REF. */
2045 assemble_noswitch_variable (tree decl, const char *name, section *sect)
2047 unsigned HOST_WIDE_INT size, rounded;
2049 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
2052 /* Don't allocate zero bytes of common,
2053 since that means "undefined external" in the linker. */
2057 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2058 so that each uninitialized object starts on such a boundary. */
2059 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
2060 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2061 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2063 if (!sect->noswitch.callback (decl, name, size, rounded)
2064 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
2065 warning (0, "requested alignment for %q+D is greater than "
2066 "implemented alignment of %wu", decl, rounded);
2069 /* A subroutine of assemble_variable. Output the label and contents of
2070 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2071 is as for assemble_variable. */
2074 assemble_variable_contents (tree decl, const char *name,
2075 bool dont_output_data)
2077 /* Do any machine/system dependent processing of the object. */
2078 #ifdef ASM_DECLARE_OBJECT_NAME
2079 last_assemble_variable_decl = decl;
2080 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
2082 /* Standard thing is just output label for the object. */
2083 ASM_OUTPUT_LABEL (asm_out_file, name);
2084 #endif /* ASM_DECLARE_OBJECT_NAME */
2086 if (!dont_output_data)
2088 if (DECL_INITIAL (decl)
2089 && DECL_INITIAL (decl) != error_mark_node
2090 && !initializer_zerop (DECL_INITIAL (decl)))
2091 /* Output the actual data. */
2092 output_constant (DECL_INITIAL (decl),
2093 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
2096 /* Leave space for it. */
2097 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
2101 /* Initialize emulated tls object TO, which refers to TLS variable
2102 DECL and is initialized by PROXY. */
2105 default_emutls_var_init (tree to, tree decl, tree proxy)
2107 VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4);
2108 constructor_elt *elt;
2109 tree type = TREE_TYPE (to);
2110 tree field = TYPE_FIELDS (type);
2112 elt = VEC_quick_push (constructor_elt, v, NULL);
2114 elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
2116 elt = VEC_quick_push (constructor_elt, v, NULL);
2117 field = DECL_CHAIN (field);
2119 elt->value = build_int_cst (TREE_TYPE (field),
2120 DECL_ALIGN_UNIT (decl));
2122 elt = VEC_quick_push (constructor_elt, v, NULL);
2123 field = DECL_CHAIN (field);
2125 elt->value = null_pointer_node;
2127 elt = VEC_quick_push (constructor_elt, v, NULL);
2128 field = DECL_CHAIN (field);
2132 return build_constructor (type, v);
2135 /* Assemble everything that is needed for a variable or function declaration.
2136 Not used for automatic variables, and not used for function definitions.
2137 Should not be called for variables of incomplete structure type.
2139 TOP_LEVEL is nonzero if this variable has file scope.
2140 AT_END is nonzero if this is the special handling, at end of compilation,
2141 to define things that have had only tentative definitions.
2142 DONT_OUTPUT_DATA if nonzero means don't actually output the
2143 initial value (that will be done by the caller). */
2146 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2147 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2150 rtx decl_rtl, symbol;
2153 /* This function is supposed to handle VARIABLES. Ensure we have one. */
2154 gcc_assert (TREE_CODE (decl) == VAR_DECL);
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 /* Do nothing for global register variables. */
2195 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2197 TREE_ASM_WRITTEN (decl) = 1;
2201 /* If type was incomplete when the variable was declared,
2202 see if it is complete now. */
2204 if (DECL_SIZE (decl) == 0)
2205 layout_decl (decl, 0);
2207 /* Still incomplete => don't allocate it; treat the tentative defn
2208 (which is what it must have been) as an `extern' reference. */
2210 if (!dont_output_data && DECL_SIZE (decl) == 0)
2212 error ("storage size of %q+D isn%'t known", decl);
2213 TREE_ASM_WRITTEN (decl) = 1;
2217 /* The first declaration of a variable that comes through this function
2218 decides whether it is global (in C, has external linkage)
2219 or local (in C, has internal linkage). So do nothing more
2220 if this function has already run. */
2222 if (TREE_ASM_WRITTEN (decl))
2225 /* Make sure targetm.encode_section_info is invoked before we set
2227 decl_rtl = DECL_RTL (decl);
2229 TREE_ASM_WRITTEN (decl) = 1;
2231 /* Do no output if -fsyntax-only. */
2232 if (flag_syntax_only)
2235 if (! dont_output_data
2236 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2238 error ("size of variable %q+D is too large", decl);
2242 gcc_assert (MEM_P (decl_rtl));
2243 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2244 symbol = XEXP (decl_rtl, 0);
2246 /* If this symbol belongs to the tree constant pool, output the constant
2247 if it hasn't already been written. */
2248 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2250 tree decl = SYMBOL_REF_DECL (symbol);
2251 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2252 output_constant_def_contents (symbol);
2258 name = XSTR (symbol, 0);
2259 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2260 notice_global_symbol (decl);
2262 /* Compute the alignment of this data. */
2264 align_variable (decl, dont_output_data);
2265 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2267 if (TREE_PUBLIC (decl))
2268 maybe_assemble_visibility (decl);
2270 if (DECL_PRESERVE_P (decl))
2271 targetm.asm_out.mark_decl_preserved (name);
2273 /* First make the assembler name(s) global if appropriate. */
2274 sect = get_variable_section (decl, false);
2275 if (TREE_PUBLIC (decl)
2276 && (sect->common.flags & SECTION_COMMON) == 0)
2277 globalize_decl (decl);
2279 /* Output any data that we will need to use the address of. */
2280 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2281 output_addressed_constants (DECL_INITIAL (decl));
2283 /* dbxout.c needs to know this. */
2284 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2285 DECL_IN_TEXT_SECTION (decl) = 1;
2287 /* If the decl is part of an object_block, make sure that the decl
2288 has been positioned within its block, but do not write out its
2289 definition yet. output_object_blocks will do that later. */
2290 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2292 gcc_assert (!dont_output_data);
2293 place_block_symbol (symbol);
2295 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2296 assemble_noswitch_variable (decl, name, sect);
2299 switch_to_section (sect);
2300 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2301 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2302 assemble_variable_contents (decl, name, dont_output_data);
2306 /* Return 1 if type TYPE contains any pointers. */
2309 contains_pointers_p (tree type)
2311 switch (TREE_CODE (type))
2314 case REFERENCE_TYPE:
2315 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2316 so I'll play safe and return 1. */
2322 case QUAL_UNION_TYPE:
2325 /* For a type that has fields, see if the fields have pointers. */
2326 for (fields = TYPE_FIELDS (type); fields; fields = DECL_CHAIN (fields))
2327 if (TREE_CODE (fields) == FIELD_DECL
2328 && contains_pointers_p (TREE_TYPE (fields)))
2334 /* An array type contains pointers if its element type does. */
2335 return contains_pointers_p (TREE_TYPE (type));
2342 /* We delay assemble_external processing until
2343 the compilation unit is finalized. This is the best we can do for
2344 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2345 it all the way to final. See PR 17982 for further discussion. */
2346 static GTY(()) tree pending_assemble_externals;
2348 #ifdef ASM_OUTPUT_EXTERNAL
2349 /* True if DECL is a function decl for which no out-of-line copy exists.
2350 It is assumed that DECL's assembler name has been set. */
2353 incorporeal_function_p (tree decl)
2355 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2359 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2360 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2363 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2364 if (is_builtin_name (name))
2370 /* Actually do the tests to determine if this is necessary, and invoke
2371 ASM_OUTPUT_EXTERNAL. */
2373 assemble_external_real (tree decl)
2375 rtx rtl = DECL_RTL (decl);
2377 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2378 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2379 && !incorporeal_function_p (decl))
2381 /* Some systems do require some output. */
2382 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2383 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2389 process_pending_assemble_externals (void)
2391 #ifdef ASM_OUTPUT_EXTERNAL
2393 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2394 assemble_external_real (TREE_VALUE (list));
2396 pending_assemble_externals = 0;
2400 /* This TREE_LIST contains any weak symbol declarations waiting
2402 static GTY(()) tree weak_decls;
2404 /* Output something to declare an external symbol to the assembler,
2405 and qualifiers such as weakness. (Most assemblers don't need
2406 extern declaration, so we normally output nothing.) Do nothing if
2407 DECL is not external. */
2410 assemble_external (tree decl ATTRIBUTE_UNUSED)
2412 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2413 main body of this code is only rarely exercised. To provide some
2414 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2415 open. If it's not, we should not be calling this function. */
2416 gcc_assert (asm_out_file);
2418 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2421 /* We want to output annotation for weak and external symbols at
2422 very last to check if they are references or not. */
2426 /* TREE_STATIC is a weird and abused creature which is not
2427 generally the right test for whether an entity has been
2428 locally emitted, inlined or otherwise not-really-extern, but
2429 for declarations that can be weak, it happens to be
2431 && !TREE_STATIC (decl)
2432 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2433 && value_member (decl, weak_decls) == NULL_TREE)
2434 weak_decls = tree_cons (NULL, decl, weak_decls);
2436 #ifdef ASM_OUTPUT_EXTERNAL
2437 if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2438 pending_assemble_externals = tree_cons (NULL, decl,
2439 pending_assemble_externals);
2443 /* Similar, for calling a library function FUN. */
2446 assemble_external_libcall (rtx fun)
2448 /* Declare library function name external when first used, if nec. */
2449 if (! SYMBOL_REF_USED (fun))
2451 SYMBOL_REF_USED (fun) = 1;
2452 targetm.asm_out.external_libcall (fun);
2456 /* Assemble a label named NAME. */
2459 assemble_label (FILE *file, const char *name)
2461 ASM_OUTPUT_LABEL (file, name);
2464 /* Set the symbol_referenced flag for ID. */
2466 mark_referenced (tree id)
2468 TREE_SYMBOL_REFERENCED (id) = 1;
2471 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2473 mark_decl_referenced (tree decl)
2475 if (TREE_CODE (decl) == FUNCTION_DECL)
2477 /* Extern inline functions don't become needed when referenced.
2478 If we know a method will be emitted in other TU and no new
2479 functions can be marked reachable, just use the external
2481 struct cgraph_node *node = cgraph_node (decl);
2482 if (!DECL_EXTERNAL (decl)
2483 && (!node->local.vtable_method || !cgraph_global_info_ready
2484 || !node->local.finalized))
2485 cgraph_mark_needed_node (node);
2487 else if (TREE_CODE (decl) == VAR_DECL)
2489 struct varpool_node *node = varpool_node (decl);
2490 varpool_mark_needed_node (node);
2491 /* C++ frontend use mark_decl_references to force COMDAT variables
2492 to be output that might appear dead otherwise. */
2493 node->force_output = true;
2495 /* else do nothing - we can get various sorts of CST nodes here,
2496 which do not need to be marked. */
2500 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2501 until we find an identifier that is not itself a transparent alias.
2502 Modify the alias passed to it by reference (and all aliases on the
2503 way to the ultimate target), such that they do not have to be
2504 followed again, and return the ultimate target of the alias
2508 ultimate_transparent_alias_target (tree *alias)
2510 tree target = *alias;
2512 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2514 gcc_assert (TREE_CHAIN (target));
2515 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2516 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2517 && ! TREE_CHAIN (target));
2524 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2525 starts with a *, the rest of NAME is output verbatim. Otherwise
2526 NAME is transformed in a target-specific way (usually by the
2527 addition of an underscore). */
2530 assemble_name_raw (FILE *file, const char *name)
2533 fputs (&name[1], file);
2535 ASM_OUTPUT_LABELREF (file, name);
2538 /* Like assemble_name_raw, but should be used when NAME might refer to
2539 an entity that is also represented as a tree (like a function or
2540 variable). If NAME does refer to such an entity, that entity will
2541 be marked as referenced. */
2544 assemble_name (FILE *file, const char *name)
2546 const char *real_name;
2549 real_name = targetm.strip_name_encoding (name);
2551 id = maybe_get_identifier (real_name);
2556 mark_referenced (id);
2557 ultimate_transparent_alias_target (&id);
2559 name = IDENTIFIER_POINTER (id);
2560 gcc_assert (! TREE_CHAIN (id));
2563 assemble_name_raw (file, name);
2566 /* Allocate SIZE bytes writable static space with a gensym name
2567 and return an RTX to refer to its address. */
2570 assemble_static_space (unsigned HOST_WIDE_INT size)
2573 const char *namestring;
2576 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2578 namestring = ggc_strdup (name);
2580 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2581 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2583 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2584 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2587 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2588 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2591 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2592 so that each uninitialized object starts on such a boundary. */
2593 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2594 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2595 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2596 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2597 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2598 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2605 /* Assemble the static constant template for function entry trampolines.
2606 This is done at most once per compilation.
2607 Returns an RTX for the address of the template. */
2609 static GTY(()) rtx initial_trampoline;
2612 assemble_trampoline_template (void)
2619 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2621 if (initial_trampoline)
2622 return initial_trampoline;
2624 /* By default, put trampoline templates in read-only data section. */
2626 #ifdef TRAMPOLINE_SECTION
2627 switch_to_section (TRAMPOLINE_SECTION);
2629 switch_to_section (readonly_data_section);
2632 /* Write the assembler code to define one. */
2633 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2635 ASM_OUTPUT_ALIGN (asm_out_file, align);
2637 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2638 targetm.asm_out.trampoline_template (asm_out_file);
2640 /* Record the rtl to refer to it. */
2641 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2642 name = ggc_strdup (label);
2643 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2644 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2646 initial_trampoline = gen_const_mem (BLKmode, symbol);
2647 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2648 set_mem_size (initial_trampoline, GEN_INT (TRAMPOLINE_SIZE));
2650 return initial_trampoline;
2653 /* A and B are either alignments or offsets. Return the minimum alignment
2654 that may be assumed after adding the two together. */
2656 static inline unsigned
2657 min_align (unsigned int a, unsigned int b)
2659 return (a | b) & -(a | b);
2662 /* Return the assembler directive for creating a given kind of integer
2663 object. SIZE is the number of bytes in the object and ALIGNED_P
2664 indicates whether it is known to be aligned. Return NULL if the
2665 assembly dialect has no such directive.
2667 The returned string should be printed at the start of a new line and
2668 be followed immediately by the object's initial value. */
2671 integer_asm_op (int size, int aligned_p)
2673 struct asm_int_op *ops;
2676 ops = &targetm.asm_out.aligned_op;
2678 ops = &targetm.asm_out.unaligned_op;
2683 return targetm.asm_out.byte_op;
2697 /* Use directive OP to assemble an integer object X. Print OP at the
2698 start of the line, followed immediately by the value of X. */
2701 assemble_integer_with_op (const char *op, rtx x)
2703 fputs (op, asm_out_file);
2704 output_addr_const (asm_out_file, x);
2705 fputc ('\n', asm_out_file);
2708 /* The default implementation of the asm_out.integer target hook. */
2711 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2712 unsigned int size ATTRIBUTE_UNUSED,
2713 int aligned_p ATTRIBUTE_UNUSED)
2715 const char *op = integer_asm_op (size, aligned_p);
2716 /* Avoid GAS bugs for large values. Specifically negative values whose
2717 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2718 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2720 return op && (assemble_integer_with_op (op, x), true);
2723 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2724 the alignment of the integer in bits. Return 1 if we were able to output
2725 the constant, otherwise 0. We must be able to output the constant,
2726 if FORCE is nonzero. */
2729 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2733 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2735 /* See if the target hook can handle this kind of object. */
2736 if (targetm.asm_out.integer (x, size, aligned_p))
2739 /* If the object is a multi-byte one, try splitting it up. Split
2740 it into words it if is multi-word, otherwise split it into bytes. */
2743 enum machine_mode omode, imode;
2744 unsigned int subalign;
2745 unsigned int subsize, i;
2746 enum mode_class mclass;
2748 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2749 subalign = MIN (align, subsize * BITS_PER_UNIT);
2750 if (GET_CODE (x) == CONST_FIXED)
2751 mclass = GET_MODE_CLASS (GET_MODE (x));
2755 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2756 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2758 for (i = 0; i < size; i += subsize)
2760 rtx partial = simplify_subreg (omode, x, imode, i);
2761 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2767 /* If we've printed some of it, but not all of it, there's no going
2772 gcc_assert (!force);
2778 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2780 long data[4] = {0, 0, 0, 0};
2782 int bitsize, nelts, nunits, units_per;
2784 /* This is hairy. We have a quantity of known size. real_to_target
2785 will put it into an array of *host* longs, 32 bits per element
2786 (even if long is more than 32 bits). We need to determine the
2787 number of array elements that are occupied (nelts) and the number
2788 of *target* min-addressable units that will be occupied in the
2789 object file (nunits). We cannot assume that 32 divides the
2790 mode's bitsize (size * BITS_PER_UNIT) evenly.
2792 size * BITS_PER_UNIT is used here to make sure that padding bits
2793 (which might appear at either end of the value; real_to_target
2794 will include the padding bits in its output array) are included. */
2796 nunits = GET_MODE_SIZE (mode);
2797 bitsize = nunits * BITS_PER_UNIT;
2798 nelts = CEIL (bitsize, 32);
2799 units_per = 32 / BITS_PER_UNIT;
2801 real_to_target (data, &d, mode);
2803 /* Put out the first word with the specified alignment. */
2804 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2805 nunits -= units_per;
2807 /* Subsequent words need only 32-bit alignment. */
2808 align = min_align (align, 32);
2810 for (i = 1; i < nelts; i++)
2812 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2813 nunits -= units_per;
2817 /* Given an expression EXP with a constant value,
2818 reduce it to the sum of an assembler symbol and an integer.
2819 Store them both in the structure *VALUE.
2820 EXP must be reducible. */
2822 struct GTY(()) addr_const {
2824 HOST_WIDE_INT offset;
2828 decode_addr_const (tree exp, struct addr_const *value)
2830 tree target = TREE_OPERAND (exp, 0);
2836 if (TREE_CODE (target) == COMPONENT_REF
2837 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2839 offset += int_byte_position (TREE_OPERAND (target, 1));
2840 target = TREE_OPERAND (target, 0);
2842 else if (TREE_CODE (target) == ARRAY_REF
2843 || TREE_CODE (target) == ARRAY_RANGE_REF)
2845 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2846 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2847 target = TREE_OPERAND (target, 0);
2849 else if (TREE_CODE (target) == INDIRECT_REF
2850 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2851 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2853 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2858 switch (TREE_CODE (target))
2862 x = DECL_RTL (target);
2866 x = gen_rtx_MEM (FUNCTION_MODE,
2867 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2876 x = output_constant_def (target, 1);
2883 gcc_assert (MEM_P (x));
2887 value->offset = offset;
2891 static GTY((param_is (struct constant_descriptor_tree)))
2892 htab_t const_desc_htab;
2894 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2896 /* Constant pool accessor function. */
2899 constant_pool_htab (void)
2901 return const_desc_htab;
2904 /* Compute a hash code for a constant expression. */
2907 const_desc_hash (const void *ptr)
2909 return ((const struct constant_descriptor_tree *)ptr)->hash;
2913 const_hash_1 (const tree exp)
2918 enum tree_code code = TREE_CODE (exp);
2920 /* Either set P and LEN to the address and len of something to hash and
2921 exit the switch or return a value. */
2926 p = (char *) &TREE_INT_CST (exp);
2927 len = sizeof TREE_INT_CST (exp);
2931 return real_hash (TREE_REAL_CST_PTR (exp));
2934 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2937 p = TREE_STRING_POINTER (exp);
2938 len = TREE_STRING_LENGTH (exp);
2942 return (const_hash_1 (TREE_REALPART (exp)) * 5
2943 + const_hash_1 (TREE_IMAGPART (exp)));
2949 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2951 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2952 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2959 unsigned HOST_WIDE_INT idx;
2962 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2964 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2966 hi = hi * 603 + const_hash_1 (value);
2974 struct addr_const value;
2976 decode_addr_const (exp, &value);
2977 switch (GET_CODE (value.base))
2980 /* Don't hash the address of the SYMBOL_REF;
2981 only use the offset and the symbol name. */
2983 p = XSTR (value.base, 0);
2984 for (i = 0; p[i] != 0; i++)
2985 hi = ((hi * 613) + (unsigned) (p[i]));
2989 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2999 case POINTER_PLUS_EXPR:
3001 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
3002 + const_hash_1 (TREE_OPERAND (exp, 1)));
3005 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
3008 /* A language specific constant. Just hash the code. */
3012 /* Compute hashing function. */
3014 for (i = 0; i < len; i++)
3015 hi = ((hi * 613) + (unsigned) (p[i]));
3020 /* Wrapper of compare_constant, for the htab interface. */
3022 const_desc_eq (const void *p1, const void *p2)
3024 const struct constant_descriptor_tree *const c1
3025 = (const struct constant_descriptor_tree *) p1;
3026 const struct constant_descriptor_tree *const c2
3027 = (const struct constant_descriptor_tree *) p2;
3028 if (c1->hash != c2->hash)
3030 return compare_constant (c1->value, c2->value);
3033 /* Compare t1 and t2, and return 1 only if they are known to result in
3034 the same bit pattern on output. */
3037 compare_constant (const tree t1, const tree t2)
3039 enum tree_code typecode;
3041 if (t1 == NULL_TREE)
3042 return t2 == NULL_TREE;
3043 if (t2 == NULL_TREE)
3046 if (TREE_CODE (t1) != TREE_CODE (t2))
3049 switch (TREE_CODE (t1))
3052 /* Integer constants are the same only if the same width of type. */
3053 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3055 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3057 return tree_int_cst_equal (t1, t2);
3060 /* Real constants are the same only if the same width of type. */
3061 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3064 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3067 /* Fixed constants are the same only if the same width of type. */
3068 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3071 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3074 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3077 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3078 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3079 TREE_STRING_LENGTH (t1)));
3082 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3083 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3089 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
3090 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
3093 link2 = TREE_VECTOR_CST_ELTS (t2);
3094 for (link1 = TREE_VECTOR_CST_ELTS (t1);
3096 link1 = TREE_CHAIN (link1))
3098 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
3100 link2 = TREE_CHAIN (link2);
3108 VEC(constructor_elt, gc) *v1, *v2;
3109 unsigned HOST_WIDE_INT idx;
3111 typecode = TREE_CODE (TREE_TYPE (t1));
3112 if (typecode != TREE_CODE (TREE_TYPE (t2)))
3115 if (typecode == ARRAY_TYPE)
3117 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3118 /* For arrays, check that the sizes all match. */
3119 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3121 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
3126 /* For record and union constructors, require exact type
3128 if (TREE_TYPE (t1) != TREE_TYPE (t2))
3132 v1 = CONSTRUCTOR_ELTS (t1);
3133 v2 = CONSTRUCTOR_ELTS (t2);
3134 if (VEC_length (constructor_elt, v1)
3135 != VEC_length (constructor_elt, v2))
3138 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
3140 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
3141 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
3143 /* Check that each value is the same... */
3144 if (!compare_constant (c1->value, c2->value))
3146 /* ... and that they apply to the same fields! */
3147 if (typecode == ARRAY_TYPE)
3149 if (!compare_constant (c1->index, c2->index))
3154 if (c1->index != c2->index)
3165 struct addr_const value1, value2;
3169 decode_addr_const (t1, &value1);
3170 decode_addr_const (t2, &value2);
3172 if (value1.offset != value2.offset)
3175 code = GET_CODE (value1.base);
3176 if (code != GET_CODE (value2.base))
3182 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3186 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
3187 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
3197 case POINTER_PLUS_EXPR:
3200 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3201 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3204 case VIEW_CONVERT_EXPR:
3205 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3214 /* Make a copy of the whole tree structure for a constant. This
3215 handles the same types of nodes that compare_constant handles. */
3218 copy_constant (tree exp)
3220 switch (TREE_CODE (exp))
3223 /* For ADDR_EXPR, we do not want to copy the decl whose address
3224 is requested. We do want to copy constants though. */
3225 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3226 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3227 copy_constant (TREE_OPERAND (exp, 0)));
3229 return copy_node (exp);
3235 return copy_node (exp);
3238 return build_complex (TREE_TYPE (exp),
3239 copy_constant (TREE_REALPART (exp)),
3240 copy_constant (TREE_IMAGPART (exp)));
3243 case POINTER_PLUS_EXPR:
3245 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3246 copy_constant (TREE_OPERAND (exp, 0)),
3247 copy_constant (TREE_OPERAND (exp, 1)));
3250 case VIEW_CONVERT_EXPR:
3251 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3252 copy_constant (TREE_OPERAND (exp, 0)));
3255 return build_vector (TREE_TYPE (exp),
3256 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3260 tree copy = copy_node (exp);
3261 VEC(constructor_elt, gc) *v;
3262 unsigned HOST_WIDE_INT idx;
3263 tree purpose, value;
3265 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3266 CONSTRUCTOR_ELTS (exp)));
3267 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3269 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3270 ce->index = purpose;
3271 ce->value = copy_constant (value);
3273 CONSTRUCTOR_ELTS (copy) = v;
3282 /* Return the section into which constant EXP should be placed. */
3285 get_constant_section (tree exp, unsigned int align)
3287 return targetm.asm_out.select_section (exp,
3288 compute_reloc_for_constant (exp),
3292 /* Return the size of constant EXP in bytes. */
3294 static HOST_WIDE_INT
3295 get_constant_size (tree exp)
3299 size = int_size_in_bytes (TREE_TYPE (exp));
3300 if (TREE_CODE (exp) == STRING_CST)
3301 size = MAX (TREE_STRING_LENGTH (exp), size);
3305 /* Subroutine of output_constant_def:
3306 No constant equal to EXP is known to have been output.
3307 Make a constant descriptor to enter EXP in the hash table.
3308 Assign the label number and construct RTL to refer to the
3309 constant's location in memory.
3310 Caller is responsible for updating the hash table. */
3312 static struct constant_descriptor_tree *
3313 build_constant_desc (tree exp)
3315 struct constant_descriptor_tree *desc;
3321 desc = ggc_alloc_constant_descriptor_tree ();
3322 desc->value = copy_constant (exp);
3324 /* Propagate marked-ness to copied constant. */
3325 if (flag_mudflap && mf_marked_p (exp))
3326 mf_mark (desc->value);
3328 /* Create a string containing the label name, in LABEL. */
3329 labelno = const_labelno++;
3330 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3332 /* Construct the VAR_DECL associated with the constant. */
3333 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3335 DECL_ARTIFICIAL (decl) = 1;
3336 DECL_IGNORED_P (decl) = 1;
3337 TREE_READONLY (decl) = 1;
3338 TREE_STATIC (decl) = 1;
3339 TREE_ADDRESSABLE (decl) = 1;
3340 /* We don't set the RTL yet as this would cause varpool to assume that the
3341 variable is referenced. Moreover, it would just be dropped in LTO mode.
3342 Instead we set the flag that will be recognized in make_decl_rtl. */
3343 DECL_IN_CONSTANT_POOL (decl) = 1;
3344 DECL_INITIAL (decl) = desc->value;
3345 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3346 architectures so use DATA_ALIGNMENT as well, except for strings. */
3347 if (TREE_CODE (exp) == STRING_CST)
3349 #ifdef CONSTANT_ALIGNMENT
3350 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3354 align_variable (decl, 0);
3356 /* Now construct the SYMBOL_REF and the MEM. */
3357 if (use_object_blocks_p ())
3359 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3360 symbol = create_block_symbol (ggc_strdup (label),
3361 get_block_for_section (sect), -1);
3364 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3365 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3366 SET_SYMBOL_REF_DECL (symbol, decl);
3367 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3369 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3370 set_mem_attributes (rtl, exp, 1);
3371 set_mem_alias_set (rtl, 0);
3372 set_mem_alias_set (rtl, const_alias_set);
3374 /* We cannot share RTX'es in pool entries.
3375 Mark this piece of RTL as required for unsharing. */
3376 RTX_FLAG (rtl, used) = 1;
3378 /* Set flags or add text to the name to record information, such as
3379 that it is a local symbol. If the name is changed, the macro
3380 ASM_OUTPUT_LABELREF will have to know how to strip this
3381 information. This call might invalidate our local variable
3382 SYMBOL; we can't use it afterward. */
3383 targetm.encode_section_info (exp, rtl, true);
3390 /* Return an rtx representing a reference to constant data in memory
3391 for the constant expression EXP.
3393 If assembler code for such a constant has already been output,
3394 return an rtx to refer to it.
3395 Otherwise, output such a constant in memory
3396 and generate an rtx for it.
3398 If DEFER is nonzero, this constant can be deferred and output only
3399 if referenced in the function after all optimizations.
3401 `const_desc_table' records which constants already have label strings. */
3404 output_constant_def (tree exp, int defer)
3406 struct constant_descriptor_tree *desc;
3407 struct constant_descriptor_tree key;
3410 /* Look up EXP in the table of constant descriptors. If we didn't find
3411 it, create a new one. */
3413 key.hash = const_hash_1 (exp);
3414 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3416 desc = (struct constant_descriptor_tree *) *loc;
3419 desc = build_constant_desc (exp);
3420 desc->hash = key.hash;
3424 maybe_output_constant_def_contents (desc, defer);
3428 /* Subroutine of output_constant_def: Decide whether or not we need to
3429 output the constant DESC now, and if so, do it. */
3431 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3434 rtx symbol = XEXP (desc->rtl, 0);
3435 tree exp = desc->value;
3437 if (flag_syntax_only)
3440 if (TREE_ASM_WRITTEN (exp))
3441 /* Already output; don't do it again. */
3444 /* We can always defer constants as long as the context allows
3448 /* Increment n_deferred_constants if it exists. It needs to be at
3449 least as large as the number of constants actually referred to
3450 by the function. If it's too small we'll stop looking too early
3451 and fail to emit constants; if it's too large we'll only look
3452 through the entire function when we could have stopped earlier. */
3454 n_deferred_constants++;
3458 output_constant_def_contents (symbol);
3461 /* Subroutine of output_constant_def_contents. Output the definition
3462 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3463 constant's alignment in bits. */
3466 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3470 size = get_constant_size (exp);
3472 /* Do any machine/system dependent processing of the constant. */
3473 targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3475 /* Output the value of EXP. */
3476 output_constant (exp, size, align);
3479 /* We must output the constant data referred to by SYMBOL; do so. */
3482 output_constant_def_contents (rtx symbol)
3484 tree decl = SYMBOL_REF_DECL (symbol);
3485 tree exp = DECL_INITIAL (decl);
3488 /* Make sure any other constants whose addresses appear in EXP
3489 are assigned label numbers. */
3490 output_addressed_constants (exp);
3492 /* We are no longer deferring this constant. */
3493 TREE_ASM_WRITTEN (exp) = 1;
3495 /* If the constant is part of an object block, make sure that the
3496 decl has been positioned within its block, but do not write out
3497 its definition yet. output_object_blocks will do that later. */
3498 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3499 place_block_symbol (symbol);
3502 align = DECL_ALIGN (decl);
3503 switch_to_section (get_constant_section (exp, align));
3504 if (align > BITS_PER_UNIT)
3505 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3506 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3509 mudflap_enqueue_constant (exp);
3512 /* Look up EXP in the table of constant descriptors. Return the rtl
3513 if it has been emitted, else null. */
3516 lookup_constant_def (tree exp)
3518 struct constant_descriptor_tree *desc;
3519 struct constant_descriptor_tree key;
3522 key.hash = const_hash_1 (exp);
3523 desc = (struct constant_descriptor_tree *)
3524 htab_find_with_hash (const_desc_htab, &key, key.hash);
3526 return (desc ? desc->rtl : NULL_RTX);
3529 /* Return a tree representing a reference to constant data in memory
3530 for the constant expression EXP.
3532 This is the counterpart of output_constant_def at the Tree level. */
3535 tree_output_constant_def (tree exp)
3537 struct constant_descriptor_tree *desc, key;
3541 /* Look up EXP in the table of constant descriptors. If we didn't find
3542 it, create a new one. */
3544 key.hash = const_hash_1 (exp);
3545 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3547 desc = (struct constant_descriptor_tree *) *loc;
3550 desc = build_constant_desc (exp);
3551 desc->hash = key.hash;
3555 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3556 varpool_finalize_decl (decl);
3560 /* Used in the hash tables to avoid outputting the same constant
3561 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3562 are output once per function, not once per file. */
3563 /* ??? Only a few targets need per-function constant pools. Most
3564 can use one per-file pool. Should add a targetm bit to tell the
3567 struct GTY(()) rtx_constant_pool {
3568 /* Pointers to first and last constant in pool, as ordered by offset. */
3569 struct constant_descriptor_rtx *first;
3570 struct constant_descriptor_rtx *last;
3572 /* Hash facility for making memory-constants from constant rtl-expressions.
3573 It is used on RISC machines where immediate integer arguments and
3574 constant addresses are restricted so that such constants must be stored
3576 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3578 /* Current offset in constant pool (does not include any
3579 machine-specific header). */
3580 HOST_WIDE_INT offset;
3583 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3584 struct constant_descriptor_rtx *next;
3588 HOST_WIDE_INT offset;
3590 enum machine_mode mode;
3596 /* Hash and compare functions for const_rtx_htab. */
3599 const_desc_rtx_hash (const void *ptr)
3601 const struct constant_descriptor_rtx *const desc
3602 = (const struct constant_descriptor_rtx *) ptr;
3607 const_desc_rtx_eq (const void *a, const void *b)
3609 const struct constant_descriptor_rtx *const x
3610 = (const struct constant_descriptor_rtx *) a;
3611 const struct constant_descriptor_rtx *const y
3612 = (const struct constant_descriptor_rtx *) b;
3614 if (x->mode != y->mode)
3616 return rtx_equal_p (x->constant, y->constant);
3619 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3622 const_rtx_hash_1 (rtx *xp, void *data)
3624 unsigned HOST_WIDE_INT hwi;
3625 enum machine_mode mode;
3631 code = GET_CODE (x);
3632 mode = GET_MODE (x);
3633 h = (hashval_t) code * 1048573 + mode;
3641 int shift = sizeof (hashval_t) * CHAR_BIT;
3642 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3645 h ^= (hashval_t) hwi;
3646 for (i = 1; i < n; ++i)
3649 h ^= (hashval_t) hwi;
3655 if (mode == VOIDmode)
3657 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3661 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3665 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3671 for (i = XVECLEN (x, 0); i-- > 0; )
3672 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3677 h ^= htab_hash_string (XSTR (x, 0));
3681 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3685 case UNSPEC_VOLATILE:
3686 h = h * 251 + XINT (x, 1);
3693 hp = (hashval_t *) data;
3694 *hp = *hp * 509 + h;
3698 /* Compute a hash value for X, which should be a constant. */
3701 const_rtx_hash (rtx x)
3704 for_each_rtx (&x, const_rtx_hash_1, &h);
3709 /* Create and return a new rtx constant pool. */
3711 static struct rtx_constant_pool *
3712 create_constant_pool (void)
3714 struct rtx_constant_pool *pool;
3716 pool = ggc_alloc_rtx_constant_pool ();
3717 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3718 const_desc_rtx_eq, NULL);
3725 /* Initialize constant pool hashing for a new function. */
3728 init_varasm_status (void)
3730 crtl->varasm.pool = create_constant_pool ();
3731 crtl->varasm.deferred_constants = 0;
3734 /* Given a MINUS expression, simplify it if both sides
3735 include the same symbol. */
3738 simplify_subtraction (rtx x)
3740 rtx r = simplify_rtx (x);
3744 /* Given a constant rtx X, make (or find) a memory constant for its value
3745 and return a MEM rtx to refer to it in memory. */
3748 force_const_mem (enum machine_mode mode, rtx x)
3750 struct constant_descriptor_rtx *desc, tmp;
3751 struct rtx_constant_pool *pool;
3758 /* If we're not allowed to drop X into the constant pool, don't. */
3759 if (targetm.cannot_force_const_mem (x))
3762 /* Record that this function has used a constant pool entry. */
3763 crtl->uses_const_pool = 1;
3765 /* Decide which pool to use. */
3766 pool = (targetm.use_blocks_for_constant_p (mode, x)
3767 ? shared_constant_pool
3768 : crtl->varasm.pool);
3770 /* Lookup the value in the hashtable. */
3773 hash = const_rtx_hash (x);
3774 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3775 desc = (struct constant_descriptor_rtx *) *slot;
3777 /* If the constant was already present, return its memory. */
3779 return copy_rtx (desc->mem);
3781 /* Otherwise, create a new descriptor. */
3782 desc = ggc_alloc_constant_descriptor_rtx ();
3785 /* Align the location counter as required by EXP's data type. */
3786 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3787 #ifdef CONSTANT_ALIGNMENT
3789 tree type = lang_hooks.types.type_for_mode (mode, 0);
3790 if (type != NULL_TREE)
3791 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3795 pool->offset += (align / BITS_PER_UNIT) - 1;
3796 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3799 desc->constant = tmp.constant;
3800 desc->offset = pool->offset;
3803 desc->align = align;
3804 desc->labelno = const_labelno;
3807 pool->offset += GET_MODE_SIZE (mode);
3809 pool->last->next = desc;
3811 pool->first = pool->last = desc;
3814 /* Create a string containing the label name, in LABEL. */
3815 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3818 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3819 the constants pool. */
3820 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3822 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3823 symbol = create_block_symbol (ggc_strdup (label),
3824 get_block_for_section (sect), -1);
3827 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3829 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3830 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3831 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3833 /* Construct the MEM. */
3834 desc->mem = def = gen_const_mem (mode, symbol);
3835 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3836 set_mem_align (def, align);
3838 /* If we're dropping a label to the constant pool, make sure we
3840 if (GET_CODE (x) == LABEL_REF)
3841 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3843 return copy_rtx (def);
3846 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3849 get_pool_constant (rtx addr)
3851 return SYMBOL_REF_CONSTANT (addr)->constant;
3854 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3855 and whether it has been output or not. */
3858 get_pool_constant_mark (rtx addr, bool *pmarked)
3860 struct constant_descriptor_rtx *desc;
3862 desc = SYMBOL_REF_CONSTANT (addr);
3863 *pmarked = (desc->mark != 0);
3864 return desc->constant;
3867 /* Similar, return the mode. */
3870 get_pool_mode (const_rtx addr)
3872 return SYMBOL_REF_CONSTANT (addr)->mode;
3875 /* Return the size of the constant pool. */
3878 get_pool_size (void)
3880 return crtl->varasm.pool->offset;
3883 /* Worker function for output_constant_pool_1. Emit assembly for X
3884 in MODE with known alignment ALIGN. */
3887 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3889 switch (GET_MODE_CLASS (mode))
3892 case MODE_DECIMAL_FLOAT:
3896 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3897 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3898 assemble_real (r, mode, align);
3903 case MODE_PARTIAL_INT:
3908 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3911 case MODE_VECTOR_FLOAT:
3912 case MODE_VECTOR_INT:
3913 case MODE_VECTOR_FRACT:
3914 case MODE_VECTOR_UFRACT:
3915 case MODE_VECTOR_ACCUM:
3916 case MODE_VECTOR_UACCUM:
3919 enum machine_mode submode = GET_MODE_INNER (mode);
3920 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3922 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3923 units = CONST_VECTOR_NUNITS (x);
3925 for (i = 0; i < units; i++)
3927 rtx elt = CONST_VECTOR_ELT (x, i);
3928 output_constant_pool_2 (submode, elt, i ? subalign : align);
3938 /* Worker function for output_constant_pool. Emit constant DESC,
3939 giving it ALIGN bits of alignment. */
3942 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3949 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3950 whose CODE_LABEL has been deleted. This can occur if a jump table
3951 is eliminated by optimization. If so, write a constant of zero
3952 instead. Note that this can also happen by turning the
3953 CODE_LABEL into a NOTE. */
3954 /* ??? This seems completely and utterly wrong. Certainly it's
3955 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3956 functioning even with INSN_DELETED_P and friends. */
3959 switch (GET_CODE (tmp))
3962 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3963 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3965 tmp = XEXP (XEXP (tmp, 0), 0);
3969 tmp = XEXP (tmp, 0);
3970 gcc_assert (!INSN_DELETED_P (tmp));
3971 gcc_assert (!NOTE_P (tmp)
3972 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3979 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3980 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3981 align, desc->labelno, done);
3984 assemble_align (align);
3986 /* Output the label. */
3987 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3989 /* Output the data. */
3990 output_constant_pool_2 (desc->mode, x, align);
3992 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3993 sections have proper size. */
3994 if (align > GET_MODE_BITSIZE (desc->mode)
3996 && (in_section->common.flags & SECTION_MERGE))
3997 assemble_align (align);
3999 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4005 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4006 to as used. Emit referenced deferred strings. This function can
4007 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4010 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
4012 rtx x = *current_rtx;
4014 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
4017 if (CONSTANT_POOL_ADDRESS_P (x))
4019 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
4020 if (desc->mark == 0)
4023 for_each_rtx (&desc->constant, mark_constant, NULL);
4026 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
4028 tree decl = SYMBOL_REF_DECL (x);
4029 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
4031 n_deferred_constants--;
4032 output_constant_def_contents (x);
4039 /* Look through appropriate parts of INSN, marking all entries in the
4040 constant pool which are actually being used. Entries that are only
4041 referenced by other constants are also marked as used. Emit
4042 deferred strings that are used. */
4045 mark_constants (rtx insn)
4050 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4051 insns, not any notes that may be attached. We don't want to mark
4052 a constant just because it happens to appear in a REG_EQUIV note. */
4053 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
4055 rtx seq = PATTERN (insn);
4056 int i, n = XVECLEN (seq, 0);
4057 for (i = 0; i < n; ++i)
4059 rtx subinsn = XVECEXP (seq, 0, i);
4060 if (INSN_P (subinsn))
4061 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
4065 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
4068 /* Look through the instructions for this function, and mark all the
4069 entries in POOL which are actually being used. Emit deferred constants
4070 which have indeed been used. */
4073 mark_constant_pool (void)
4077 if (!crtl->uses_const_pool && n_deferred_constants == 0)
4080 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4081 mark_constants (insn);
4083 for (link = crtl->epilogue_delay_list;
4085 link = XEXP (link, 1))
4086 mark_constants (XEXP (link, 0));
4089 /* Write all the constants in POOL. */
4092 output_constant_pool_contents (struct rtx_constant_pool *pool)
4094 struct constant_descriptor_rtx *desc;
4096 for (desc = pool->first; desc ; desc = desc->next)
4099 /* If the constant is part of an object_block, make sure that
4100 the constant has been positioned within its block, but do not
4101 write out its definition yet. output_object_blocks will do
4103 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4104 && SYMBOL_REF_BLOCK (desc->sym))
4105 place_block_symbol (desc->sym);
4108 switch_to_section (targetm.asm_out.select_rtx_section
4109 (desc->mode, desc->constant, desc->align));
4110 output_constant_pool_1 (desc, desc->align);
4115 /* Mark all constants that are used in the current function, then write
4116 out the function's private constant pool. */
4119 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
4120 tree fndecl ATTRIBUTE_UNUSED)
4122 struct rtx_constant_pool *pool = crtl->varasm.pool;
4124 /* It is possible for gcc to call force_const_mem and then to later
4125 discard the instructions which refer to the constant. In such a
4126 case we do not need to output the constant. */
4127 mark_constant_pool ();
4129 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4130 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
4133 output_constant_pool_contents (pool);
4135 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4136 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
4140 /* Write the contents of the shared constant pool. */
4143 output_shared_constant_pool (void)
4145 output_constant_pool_contents (shared_constant_pool);
4148 /* Determine what kind of relocations EXP may need. */
4151 compute_reloc_for_constant (tree exp)
4153 int reloc = 0, reloc2;
4156 switch (TREE_CODE (exp))
4160 /* Go inside any operations that get_inner_reference can handle and see
4161 if what's inside is a constant: no need to do anything here for
4162 addresses of variables or functions. */
4163 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4164 tem = TREE_OPERAND (tem, 0))
4167 if (TREE_PUBLIC (tem))
4174 case POINTER_PLUS_EXPR:
4175 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4176 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4180 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4181 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4182 /* The difference of two local labels is computable at link time. */
4183 if (reloc == 1 && reloc2 == 1)
4190 case VIEW_CONVERT_EXPR:
4191 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4196 unsigned HOST_WIDE_INT idx;
4197 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4199 reloc |= compute_reloc_for_constant (tem);
4209 /* Find all the constants whose addresses are referenced inside of EXP,
4210 and make sure assembler code with a label has been output for each one.
4211 Indicate whether an ADDR_EXPR has been encountered. */
4214 output_addressed_constants (tree exp)
4218 switch (TREE_CODE (exp))
4222 /* Go inside any operations that get_inner_reference can handle and see
4223 if what's inside is a constant: no need to do anything here for
4224 addresses of variables or functions. */
4225 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4226 tem = TREE_OPERAND (tem, 0))
4229 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4230 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4231 tem = DECL_INITIAL (tem);
4233 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4234 output_constant_def (tem, 0);
4238 case POINTER_PLUS_EXPR:
4240 output_addressed_constants (TREE_OPERAND (exp, 1));
4244 case VIEW_CONVERT_EXPR:
4245 output_addressed_constants (TREE_OPERAND (exp, 0));
4250 unsigned HOST_WIDE_INT idx;
4251 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4253 output_addressed_constants (tem);
4262 /* Whether a constructor CTOR is a valid static constant initializer if all
4263 its elements are. This used to be internal to initializer_constant_valid_p
4264 and has been exposed to let other functions like categorize_ctor_elements
4265 evaluate the property while walking a constructor for other purposes. */
4268 constructor_static_from_elts_p (const_tree ctor)
4270 return (TREE_CONSTANT (ctor)
4271 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4272 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4273 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4276 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4279 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4280 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4281 which are valid when ENDTYPE is an integer of any size; in
4282 particular, this does not accept a pointer minus a constant. This
4283 returns null_pointer_node if the VALUE is an absolute constant
4284 which can be used to initialize a static variable. Otherwise it
4288 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4292 if (!INTEGRAL_TYPE_P (endtype))
4295 op0 = TREE_OPERAND (value, 0);
4296 op1 = TREE_OPERAND (value, 1);
4298 /* Like STRIP_NOPS except allow the operand mode to widen. This
4299 works around a feature of fold that simplifies (int)(p1 - p2) to
4300 ((int)p1 - (int)p2) under the theory that the narrower operation
4303 while (CONVERT_EXPR_P (op0)
4304 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4306 tree inner = TREE_OPERAND (op0, 0);
4307 if (inner == error_mark_node
4308 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4309 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4310 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4315 while (CONVERT_EXPR_P (op1)
4316 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4318 tree inner = TREE_OPERAND (op1, 0);
4319 if (inner == error_mark_node
4320 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4321 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4322 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4327 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4331 op1 = initializer_constant_valid_p_1 (op1, endtype,
4332 cache ? cache + 2 : NULL);
4333 /* Both initializers must be known. */
4337 && (op0 == null_pointer_node
4338 || TREE_CODE (value) == MINUS_EXPR))
4339 return null_pointer_node;
4341 /* Support differences between labels. */
4342 if (TREE_CODE (op0) == LABEL_DECL
4343 && TREE_CODE (op1) == LABEL_DECL)
4344 return null_pointer_node;
4346 if (TREE_CODE (op0) == STRING_CST
4347 && TREE_CODE (op1) == STRING_CST
4348 && operand_equal_p (op0, op1, 1))
4349 return null_pointer_node;
4355 /* Helper function of initializer_constant_valid_p.
4356 Return nonzero if VALUE is a valid constant-valued expression
4357 for use in initializing a static variable; one that can be an
4358 element of a "constant" initializer.
4360 Return null_pointer_node if the value is absolute;
4361 if it is relocatable, return the variable that determines the relocation.
4362 We assume that VALUE has been folded as much as possible;
4363 therefore, we do not need to check for such things as
4364 arithmetic-combinations of integers.
4366 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4369 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4373 switch (TREE_CODE (value))
4376 if (constructor_static_from_elts_p (value))
4378 unsigned HOST_WIDE_INT idx;
4380 bool absolute = true;
4382 if (cache && cache[0] == value)
4384 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4387 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4394 cache[1] = NULL_TREE;
4398 if (reloc != null_pointer_node)
4401 /* For a non-absolute relocation, there is no single
4402 variable that can be "the variable that determines the
4407 cache[1] = absolute ? null_pointer_node : error_mark_node;
4409 return absolute ? null_pointer_node : error_mark_node;
4412 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4420 return null_pointer_node;
4425 tree op0 = staticp (TREE_OPERAND (value, 0));
4428 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4429 to be a constant, this is old-skool offsetof-like nonsense. */
4430 if (TREE_CODE (op0) == INDIRECT_REF
4431 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4432 return null_pointer_node;
4433 /* Taking the address of a nested function involves a trampoline,
4434 unless we don't need or want one. */
4435 if (TREE_CODE (op0) == FUNCTION_DECL
4436 && DECL_STATIC_CHAIN (op0)
4437 && !TREE_NO_TRAMPOLINE (value))
4439 /* "&{...}" requires a temporary to hold the constructed
4441 if (TREE_CODE (op0) == CONSTRUCTOR)
4447 case NON_LVALUE_EXPR:
4448 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4451 case VIEW_CONVERT_EXPR:
4453 tree src = TREE_OPERAND (value, 0);
4454 tree src_type = TREE_TYPE (src);
4455 tree dest_type = TREE_TYPE (value);
4457 /* Allow view-conversions from aggregate to non-aggregate type only
4458 if the bit pattern is fully preserved afterwards; otherwise, the
4459 RTL expander won't be able to apply a subsequent transformation
4460 to the underlying constructor. */
4461 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4463 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4464 return initializer_constant_valid_p_1 (src, endtype, cache);
4469 /* Allow all other kinds of view-conversion. */
4470 return initializer_constant_valid_p_1 (src, endtype, cache);
4475 tree src = TREE_OPERAND (value, 0);
4476 tree src_type = TREE_TYPE (src);
4477 tree dest_type = TREE_TYPE (value);
4479 /* Allow conversions between pointer types, floating-point
4480 types, and offset types. */
4481 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4482 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4483 || (TREE_CODE (dest_type) == OFFSET_TYPE
4484 && TREE_CODE (src_type) == OFFSET_TYPE))
4485 return initializer_constant_valid_p_1 (src, endtype, cache);
4487 /* Allow length-preserving conversions between integer types. */
4488 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4489 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4490 return initializer_constant_valid_p_1 (src, endtype, cache);
4492 /* Allow conversions between other integer types only if
4494 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4496 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4497 if (inner == null_pointer_node)
4498 return null_pointer_node;
4502 /* Allow (int) &foo provided int is as wide as a pointer. */
4503 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4504 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4505 return initializer_constant_valid_p_1 (src, endtype, cache);
4507 /* Likewise conversions from int to pointers, but also allow
4508 conversions from 0. */
4509 if ((POINTER_TYPE_P (dest_type)
4510 || TREE_CODE (dest_type) == OFFSET_TYPE)
4511 && INTEGRAL_TYPE_P (src_type))
4513 if (TREE_CODE (src) == INTEGER_CST
4514 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4515 return null_pointer_node;
4516 if (integer_zerop (src))
4517 return null_pointer_node;
4518 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4519 return initializer_constant_valid_p_1 (src, endtype, cache);
4522 /* Allow conversions to struct or union types if the value
4524 if (TREE_CODE (dest_type) == RECORD_TYPE
4525 || TREE_CODE (dest_type) == UNION_TYPE)
4526 return initializer_constant_valid_p_1 (src, endtype, cache);
4530 case POINTER_PLUS_EXPR:
4532 /* Any valid floating-point constants will have been folded by now;
4533 with -frounding-math we hit this with addition of two constants. */
4534 if (TREE_CODE (endtype) == REAL_TYPE)
4536 if (cache && cache[0] == value)
4538 if (! INTEGRAL_TYPE_P (endtype)
4539 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4541 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4543 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4546 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4547 endtype, ncache + 2);
4548 /* If either term is absolute, use the other term's relocation. */
4549 if (valid0 == null_pointer_node)
4551 else if (valid1 == null_pointer_node)
4553 /* Support narrowing pointer differences. */
4555 ret = narrowing_initializer_constant_valid_p (value, endtype,
4559 /* Support narrowing pointer differences. */
4560 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4569 if (TREE_CODE (endtype) == REAL_TYPE)
4571 if (cache && cache[0] == value)
4573 if (! INTEGRAL_TYPE_P (endtype)
4574 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4576 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4578 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4581 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4582 endtype, ncache + 2);
4583 /* Win if second argument is absolute. */
4584 if (valid1 == null_pointer_node)
4586 /* Win if both arguments have the same relocation.
4587 Then the value is absolute. */
4588 else if (valid0 == valid1 && valid0 != 0)
4589 ret = null_pointer_node;
4590 /* Since GCC guarantees that string constants are unique in the
4591 generated code, a subtraction between two copies of the same
4592 constant string is absolute. */
4593 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4594 && valid1 && TREE_CODE (valid1) == STRING_CST
4595 && operand_equal_p (valid0, valid1, 1))
4596 ret = null_pointer_node;
4597 /* Support narrowing differences. */
4599 ret = narrowing_initializer_constant_valid_p (value, endtype,
4603 /* Support narrowing differences. */
4604 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4619 /* Return nonzero if VALUE is a valid constant-valued expression
4620 for use in initializing a static variable; one that can be an
4621 element of a "constant" initializer.
4623 Return null_pointer_node if the value is absolute;
4624 if it is relocatable, return the variable that determines the relocation.
4625 We assume that VALUE has been folded as much as possible;
4626 therefore, we do not need to check for such things as
4627 arithmetic-combinations of integers. */
4629 initializer_constant_valid_p (tree value, tree endtype)
4631 return initializer_constant_valid_p_1 (value, endtype, NULL);
4634 /* Return true if VALUE is a valid constant-valued expression
4635 for use in initializing a static bit-field; one that can be
4636 an element of a "constant" initializer. */
4639 initializer_constant_valid_for_bitfield_p (tree value)
4641 /* For bitfields we support integer constants or possibly nested aggregates
4643 switch (TREE_CODE (value))
4647 unsigned HOST_WIDE_INT idx;
4650 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4651 if (!initializer_constant_valid_for_bitfield_p (elt))
4659 case VIEW_CONVERT_EXPR:
4660 case NON_LVALUE_EXPR:
4662 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4671 /* output_constructor outer state of relevance in recursive calls, typically
4672 for nested aggregate bitfields. */
4675 unsigned int bit_offset; /* current position in ... */
4676 int byte; /* ... the outer byte buffer. */
4679 static unsigned HOST_WIDE_INT
4680 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4683 /* Output assembler code for constant EXP to FILE, with no label.
4684 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4685 Assumes output_addressed_constants has been done on EXP already.
4687 Generate exactly SIZE bytes of assembler data, padding at the end
4688 with zeros if necessary. SIZE must always be specified.
4690 SIZE is important for structure constructors,
4691 since trailing members may have been omitted from the constructor.
4692 It is also important for initialization of arrays from string constants
4693 since the full length of the string constant might not be wanted.
4694 It is also needed for initialization of unions, where the initializer's
4695 type is just one member, and that may not be as long as the union.
4697 There a case in which we would fail to output exactly SIZE bytes:
4698 for a structure constructor that wants to produce more than SIZE bytes.
4699 But such constructors will never be generated for any possible input.
4701 ALIGN is the alignment of the data in bits. */
4704 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4706 enum tree_code code;
4707 unsigned HOST_WIDE_INT thissize;
4709 if (size == 0 || flag_syntax_only)
4712 /* See if we're trying to initialize a pointer in a non-default mode
4713 to the address of some declaration somewhere. If the target says
4714 the mode is valid for pointers, assume the target has a way of
4716 if (TREE_CODE (exp) == NOP_EXPR
4717 && POINTER_TYPE_P (TREE_TYPE (exp))
4718 && targetm.addr_space.valid_pointer_mode
4719 (TYPE_MODE (TREE_TYPE (exp)),
4720 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4722 tree saved_type = TREE_TYPE (exp);
4724 /* Peel off any intermediate conversions-to-pointer for valid
4726 while (TREE_CODE (exp) == NOP_EXPR
4727 && POINTER_TYPE_P (TREE_TYPE (exp))
4728 && targetm.addr_space.valid_pointer_mode
4729 (TYPE_MODE (TREE_TYPE (exp)),
4730 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4731 exp = TREE_OPERAND (exp, 0);
4733 /* If what we're left with is the address of something, we can
4734 convert the address to the final type and output it that
4736 if (TREE_CODE (exp) == ADDR_EXPR)
4737 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4738 /* Likewise for constant ints. */
4739 else if (TREE_CODE (exp) == INTEGER_CST)
4740 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4741 TREE_INT_CST_HIGH (exp));
4745 /* Eliminate any conversions since we'll be outputting the underlying
4747 while (CONVERT_EXPR_P (exp)
4748 || TREE_CODE (exp) == NON_LVALUE_EXPR
4749 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4751 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4752 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4754 /* Make sure eliminating the conversion is really a no-op, except with
4755 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4756 union types to allow for Ada unchecked unions. */
4757 if (type_size > op_size
4758 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4759 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4760 /* Keep the conversion. */
4763 exp = TREE_OPERAND (exp, 0);
4766 code = TREE_CODE (TREE_TYPE (exp));
4767 thissize = int_size_in_bytes (TREE_TYPE (exp));
4769 /* Allow a constructor with no elements for any data type.
4770 This means to fill the space with zeros. */
4771 if (TREE_CODE (exp) == CONSTRUCTOR
4772 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4774 assemble_zeros (size);
4778 if (TREE_CODE (exp) == FDESC_EXPR)
4780 #ifdef ASM_OUTPUT_FDESC
4781 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4782 tree decl = TREE_OPERAND (exp, 0);
4783 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4790 /* Now output the underlying data. If we've handling the padding, return.
4791 Otherwise, break and ensure SIZE is the size written. */
4798 case REFERENCE_TYPE:
4800 case FIXED_POINT_TYPE:
4801 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4802 EXPAND_INITIALIZER),
4803 MIN (size, thissize), align, 0))
4804 error ("initializer for integer/fixed-point value is too complicated");
4808 if (TREE_CODE (exp) != REAL_CST)
4809 error ("initializer for floating value is not a floating constant");
4811 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4815 output_constant (TREE_REALPART (exp), thissize / 2, align);
4816 output_constant (TREE_IMAGPART (exp), thissize / 2,
4817 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4822 switch (TREE_CODE (exp))
4825 output_constructor (exp, size, align, NULL);
4828 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4830 assemble_string (TREE_STRING_POINTER (exp), thissize);
4837 unsigned int nalign;
4838 enum machine_mode inner;
4840 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4841 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4843 elt_size = GET_MODE_SIZE (inner);
4845 link = TREE_VECTOR_CST_ELTS (exp);
4846 output_constant (TREE_VALUE (link), elt_size, align);
4847 thissize = elt_size;
4848 while ((link = TREE_CHAIN (link)) != NULL)
4850 output_constant (TREE_VALUE (link), elt_size, nalign);
4851 thissize += elt_size;
4862 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4863 output_constructor (exp, size, align, NULL);
4873 if (size > thissize)
4874 assemble_zeros (size - thissize);
4878 /* Subroutine of output_constructor, used for computing the size of
4879 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4880 type with an unspecified upper bound. */
4882 static unsigned HOST_WIDE_INT
4883 array_size_for_constructor (tree val)
4886 unsigned HOST_WIDE_INT cnt;
4887 tree index, value, tmp;
4889 /* This code used to attempt to handle string constants that are not
4890 arrays of single-bytes, but nothing else does, so there's no point in
4892 if (TREE_CODE (val) == STRING_CST)
4893 return TREE_STRING_LENGTH (val);
4895 max_index = NULL_TREE;
4896 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4898 if (TREE_CODE (index) == RANGE_EXPR)
4899 index = TREE_OPERAND (index, 1);
4900 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4904 if (max_index == NULL_TREE)
4907 /* Compute the total number of array elements. */
4908 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4909 i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4910 fold_convert (sizetype, tmp));
4911 i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4913 /* Multiply by the array element unit size to find number of bytes. */
4914 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4916 return tree_low_cst (i, 1);
4919 /* Other datastructures + helpers for output_constructor. */
4921 /* output_constructor local state to support interaction with helpers. */
4925 /* Received arguments. */
4926 tree exp; /* Constructor expression. */
4927 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4928 unsigned int align; /* Known initial alignment. */
4930 /* Constructor expression data. */
4931 tree type; /* Expression type. */
4932 tree field; /* Current field decl in a record. */
4933 tree min_index; /* Lower bound if specified for an array. */
4935 /* Output processing state. */
4936 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4937 bool byte_buffer_in_use; /* Whether byte ... */
4938 int byte; /* ... contains part of a bitfield byte yet to
4941 int last_relative_index; /* Implicit or explicit index of the last
4942 array element output within a bitfield. */
4943 /* Current element. */
4944 tree val; /* Current element value. */
4945 tree index; /* Current element index. */
4949 /* Helper for output_constructor. From the current LOCAL state, output a
4950 RANGE_EXPR element. */
4953 output_constructor_array_range (oc_local_state *local)
4955 unsigned HOST_WIDE_INT fieldsize
4956 = int_size_in_bytes (TREE_TYPE (local->type));
4958 HOST_WIDE_INT lo_index
4959 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4960 HOST_WIDE_INT hi_index
4961 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4962 HOST_WIDE_INT index;
4965 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4967 for (index = lo_index; index <= hi_index; index++)
4969 /* Output the element's initial value. */
4970 if (local->val == NULL_TREE)
4971 assemble_zeros (fieldsize);
4973 output_constant (local->val, fieldsize, align2);
4975 /* Count its size. */
4976 local->total_bytes += fieldsize;
4980 /* Helper for output_constructor. From the current LOCAL state, output a
4981 field element that is not true bitfield or part of an outer one. */
4984 output_constructor_regular_field (oc_local_state *local)
4986 /* Field size and position. Since this structure is static, we know the
4987 positions are constant. */
4988 unsigned HOST_WIDE_INT fieldsize;
4989 HOST_WIDE_INT fieldpos;
4991 unsigned int align2;
4993 if (local->index != NULL_TREE)
4994 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
4995 * ((tree_low_cst (local->index, 0)
4996 - tree_low_cst (local->min_index, 0))));
4997 else if (local->field != NULL_TREE)
4998 fieldpos = int_byte_position (local->field);
5002 /* Output any buffered-up bit-fields preceding this element. */
5003 if (local->byte_buffer_in_use)
5005 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5006 local->total_bytes++;
5007 local->byte_buffer_in_use = false;
5010 /* Advance to offset of this element.
5011 Note no alignment needed in an array, since that is guaranteed
5012 if each element has the proper size. */
5013 if ((local->field != NULL_TREE || local->index != NULL_TREE)
5014 && fieldpos != local->total_bytes)
5016 gcc_assert (fieldpos >= local->total_bytes);
5017 assemble_zeros (fieldpos - local->total_bytes);
5018 local->total_bytes = fieldpos;
5021 /* Find the alignment of this element. */
5022 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
5024 /* Determine size this element should occupy. */
5029 /* If this is an array with an unspecified upper bound,
5030 the initializer determines the size. */
5031 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5032 but we cannot do this until the deprecated support for
5033 initializing zero-length array members is removed. */
5034 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
5035 && TYPE_DOMAIN (TREE_TYPE (local->field))
5036 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
5038 fieldsize = array_size_for_constructor (local->val);
5039 /* Given a non-empty initialization, this field had
5041 gcc_assert (!fieldsize || !DECL_CHAIN (local->field));
5043 else if (DECL_SIZE_UNIT (local->field))
5045 /* ??? This can't be right. If the decl size overflows
5046 a host integer we will silently emit no data. */
5047 if (host_integerp (DECL_SIZE_UNIT (local->field), 1))
5048 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
5052 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
5054 /* Output the element's initial value. */
5055 if (local->val == NULL_TREE)
5056 assemble_zeros (fieldsize);
5058 output_constant (local->val, fieldsize, align2);
5060 /* Count its size. */
5061 local->total_bytes += fieldsize;
5064 /* Helper for output_constructor. From the current LOCAL and OUTER states,
5065 output an element that is a true bitfield or part of an outer one. */
5068 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
5070 /* Bit size of this element. */
5071 HOST_WIDE_INT ebitsize
5073 ? tree_low_cst (DECL_SIZE (local->field), 1)
5074 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
5076 /* Relative index of this element if this is an array component. */
5077 HOST_WIDE_INT relative_index
5080 ? (tree_low_cst (local->index, 0)
5081 - tree_low_cst (local->min_index, 0))
5082 : local->last_relative_index + 1)
5085 /* Bit position of this element from the start of the containing
5087 HOST_WIDE_INT constructor_relative_ebitpos
5089 ? int_bit_position (local->field)
5090 : ebitsize * relative_index);
5092 /* Bit position of this element from the start of a possibly ongoing
5093 outer byte buffer. */
5094 HOST_WIDE_INT byte_relative_ebitpos
5095 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
5097 /* From the start of a possibly ongoing outer byte buffer, offsets to
5098 the first bit of this element and to the first bit past the end of
5100 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
5101 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
5103 local->last_relative_index = relative_index;
5105 if (local->val == NULL_TREE)
5106 local->val = integer_zero_node;
5108 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
5109 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
5110 local->val = TREE_OPERAND (local->val, 0);
5112 if (TREE_CODE (local->val) != INTEGER_CST
5113 && TREE_CODE (local->val) != CONSTRUCTOR)
5115 error ("invalid initial value for member %qE", DECL_NAME (local->field));
5119 /* If this field does not start in this (or, next) byte,
5121 if (next_offset / BITS_PER_UNIT != local->total_bytes)
5123 /* Output remnant of any bit field in previous bytes. */
5124 if (local->byte_buffer_in_use)
5126 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5127 local->total_bytes++;
5128 local->byte_buffer_in_use = false;
5131 /* If still not at proper byte, advance to there. */
5132 if (next_offset / BITS_PER_UNIT != local->total_bytes)
5134 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
5135 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
5136 local->total_bytes = next_offset / BITS_PER_UNIT;
5140 /* Set up the buffer if necessary. */
5141 if (!local->byte_buffer_in_use)
5145 local->byte_buffer_in_use = true;
5148 /* If this is nested constructor, recurse passing the bit offset and the
5149 pending data, then retrieve the new pending data afterwards. */
5150 if (TREE_CODE (local->val) == CONSTRUCTOR)
5152 oc_outer_state output_state;
5154 output_state.bit_offset = next_offset % BITS_PER_UNIT;
5155 output_state.byte = local->byte;
5157 += output_constructor (local->val, 0, 0, &output_state);
5158 local->byte = output_state.byte;
5162 /* Otherwise, we must split the element into pieces that fall within
5163 separate bytes, and combine each byte with previous or following
5165 while (next_offset < end_offset)
5169 HOST_WIDE_INT value;
5170 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
5171 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
5173 /* Advance from byte to byte
5174 within this element when necessary. */
5175 while (next_byte != local->total_bytes)
5177 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5178 local->total_bytes++;
5182 /* Number of bits we can process at once
5183 (all part of the same byte). */
5184 this_time = MIN (end_offset - next_offset,
5185 BITS_PER_UNIT - next_bit);
5186 if (BYTES_BIG_ENDIAN)
5188 /* On big-endian machine, take the most significant bits
5189 first (of the bits that are significant)
5190 and put them into bytes from the most significant end. */
5191 shift = end_offset - next_offset - this_time;
5193 /* Don't try to take a bunch of bits that cross
5194 the word boundary in the INTEGER_CST. We can
5195 only select bits from the LOW or HIGH part
5197 if (shift < HOST_BITS_PER_WIDE_INT
5198 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5200 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
5201 shift = HOST_BITS_PER_WIDE_INT;
5204 /* Now get the bits from the appropriate constant word. */
5205 if (shift < HOST_BITS_PER_WIDE_INT)
5206 value = TREE_INT_CST_LOW (local->val);
5209 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5210 value = TREE_INT_CST_HIGH (local->val);
5211 shift -= HOST_BITS_PER_WIDE_INT;
5214 /* Get the result. This works only when:
5215 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5216 local->byte |= (((value >> shift)
5217 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5218 << (BITS_PER_UNIT - this_time - next_bit));
5222 /* On little-endian machines,
5223 take first the least significant bits of the value
5224 and pack them starting at the least significant
5225 bits of the bytes. */
5226 shift = next_offset - byte_relative_ebitpos;
5228 /* Don't try to take a bunch of bits that cross
5229 the word boundary in the INTEGER_CST. We can
5230 only select bits from the LOW or HIGH part
5232 if (shift < HOST_BITS_PER_WIDE_INT
5233 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5234 this_time = (HOST_BITS_PER_WIDE_INT - shift);
5236 /* Now get the bits from the appropriate constant word. */
5237 if (shift < HOST_BITS_PER_WIDE_INT)
5238 value = TREE_INT_CST_LOW (local->val);
5241 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5242 value = TREE_INT_CST_HIGH (local->val);
5243 shift -= HOST_BITS_PER_WIDE_INT;
5246 /* Get the result. This works only when:
5247 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5248 local->byte |= (((value >> shift)
5249 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5253 next_offset += this_time;
5254 local->byte_buffer_in_use = true;
5258 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5259 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5260 caller output state of relevance in recursive invocations. */
5262 static unsigned HOST_WIDE_INT
5263 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
5264 unsigned int align, oc_outer_state * outer)
5266 unsigned HOST_WIDE_INT cnt;
5267 constructor_elt *ce;
5269 oc_local_state local;
5271 /* Setup our local state to communicate with helpers. */
5274 local.align = align;
5276 local.total_bytes = 0;
5277 local.byte_buffer_in_use = outer != NULL;
5278 local.byte = outer ? outer->byte : 0;
5280 local.type = TREE_TYPE (exp);
5282 local.last_relative_index = -1;
5284 local.min_index = NULL_TREE;
5285 if (TREE_CODE (local.type) == ARRAY_TYPE
5286 && TYPE_DOMAIN (local.type) != NULL_TREE)
5287 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5289 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
5291 /* As CE goes through the elements of the constant, FIELD goes through the
5292 structure fields if the constant is a structure. If the constant is a
5293 union, we override this by getting the field from the TREE_LIST element.
5294 But the constant could also be an array. Then FIELD is zero.
5296 There is always a maximum of one element in the chain LINK for unions
5297 (even if the initializer in a source program incorrectly contains
5300 local.field = NULL_TREE;
5301 if (TREE_CODE (local.type) == RECORD_TYPE)
5302 local.field = TYPE_FIELDS (local.type);
5305 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
5306 cnt++, local.field = local.field ? DECL_CHAIN (local.field) : 0)
5308 local.val = ce->value;
5309 local.index = NULL_TREE;
5311 /* The element in a union constructor specifies the proper field
5313 if ((TREE_CODE (local.type) == RECORD_TYPE
5314 || TREE_CODE (local.type) == UNION_TYPE
5315 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
5316 && ce->index != NULL_TREE)
5317 local.field = ce->index;
5319 else if (TREE_CODE (local.type) == ARRAY_TYPE)
5320 local.index = ce->index;
5322 #ifdef ASM_COMMENT_START
5323 if (local.field && flag_verbose_asm)
5324 fprintf (asm_out_file, "%s %s:\n",
5326 DECL_NAME (local.field)
5327 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
5331 /* Eliminate the marker that makes a cast not be an lvalue. */
5332 if (local.val != NULL_TREE)
5333 STRIP_NOPS (local.val);
5335 /* Output the current element, using the appropriate helper ... */
5337 /* For an array slice not part of an outer bitfield. */
5339 && local.index != NULL_TREE
5340 && TREE_CODE (local.index) == RANGE_EXPR)
5341 output_constructor_array_range (&local);
5343 /* For a field that is neither a true bitfield nor part of an outer one,
5344 known to be at least byte aligned and multiple-of-bytes long. */
5346 && (local.field == NULL_TREE
5347 || !CONSTRUCTOR_BITFIELD_P (local.field)))
5348 output_constructor_regular_field (&local);
5350 /* For a true bitfield or part of an outer one. */
5352 output_constructor_bitfield (&local, outer);
5355 /* If we are not at toplevel, save the pending data for our caller.
5356 Otherwise output the pending data and padding zeros as needed. */
5358 outer->byte = local.byte;
5361 if (local.byte_buffer_in_use)
5363 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
5364 local.total_bytes++;
5367 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
5369 assemble_zeros (local.size - local.total_bytes);
5370 local.total_bytes = local.size;
5374 return local.total_bytes;
5377 /* Mark DECL as weak. */
5380 mark_weak (tree decl)
5382 DECL_WEAK (decl) = 1;
5384 if (DECL_RTL_SET_P (decl)
5385 && MEM_P (DECL_RTL (decl))
5386 && XEXP (DECL_RTL (decl), 0)
5387 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5388 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5391 /* Merge weak status between NEWDECL and OLDDECL. */
5394 merge_weak (tree newdecl, tree olddecl)
5396 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5398 if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
5401 /* We put the NEWDECL on the weak_decls list at some point
5402 and OLDDECL as well. Keep just OLDDECL on the list. */
5403 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5404 if (TREE_VALUE (*pwd) == newdecl)
5406 *pwd = TREE_CHAIN (*pwd);
5413 if (DECL_WEAK (newdecl))
5417 /* NEWDECL is weak, but OLDDECL is not. */
5419 /* If we already output the OLDDECL, we're in trouble; we can't
5420 go back and make it weak. This error cannot be caught in
5421 declare_weak because the NEWDECL and OLDDECL was not yet
5422 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5423 if (TREE_ASM_WRITTEN (olddecl))
5424 error ("weak declaration of %q+D must precede definition",
5427 /* If we've already generated rtl referencing OLDDECL, we may
5428 have done so in a way that will not function properly with
5430 else if (TREE_USED (olddecl)
5431 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
5432 warning (0, "weak declaration of %q+D after first use results "
5433 "in unspecified behavior", newdecl);
5437 /* We put the NEWDECL on the weak_decls list at some point.
5438 Replace it with the OLDDECL. */
5439 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5440 if (TREE_VALUE (wd) == newdecl)
5442 TREE_VALUE (wd) = olddecl;
5445 /* We may not find the entry on the list. If NEWDECL is a
5446 weak alias, then we will have already called
5447 globalize_decl to remove the entry; in that case, we do
5448 not need to do anything. */
5451 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5452 mark_weak (olddecl);
5455 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5456 weak. Just update NEWDECL to indicate that it's weak too. */
5457 mark_weak (newdecl);
5460 /* Declare DECL to be a weak symbol. */
5463 declare_weak (tree decl)
5465 if (! TREE_PUBLIC (decl))
5466 error ("weak declaration of %q+D must be public", decl);
5467 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
5468 error ("weak declaration of %q+D must precede definition", decl);
5469 else if (!SUPPORTS_WEAK)
5470 warning (0, "weak declaration of %q+D not supported", decl);
5473 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5474 DECL_ATTRIBUTES (decl)
5475 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5479 weak_finish_1 (tree decl)
5481 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5482 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5485 if (! TREE_USED (decl))
5488 #ifdef ASM_WEAKEN_DECL
5489 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5491 #ifdef ASM_WEAKEN_LABEL
5492 ASM_WEAKEN_LABEL (asm_out_file, name);
5494 #ifdef ASM_OUTPUT_WEAK_ALIAS
5496 static bool warn_once = 0;
5499 warning (0, "only weak aliases are supported in this configuration");
5509 /* This TREE_LIST contains weakref targets. */
5511 static GTY(()) tree weakref_targets;
5513 /* Forward declaration. */
5514 static tree find_decl_and_mark_needed (tree decl, tree target);
5516 /* Emit any pending weak declarations. */
5523 for (t = weakref_targets; t; t = TREE_CHAIN (t))
5525 tree alias_decl = TREE_PURPOSE (t);
5526 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5528 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5529 /* Remove alias_decl from the weak list, but leave entries for
5530 the target alone. */
5532 #ifndef ASM_OUTPUT_WEAKREF
5533 else if (! TREE_SYMBOL_REFERENCED (target))
5535 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5536 defined, otherwise we and weak_finish_1 would use
5537 different macros. */
5538 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5539 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5541 tree decl = find_decl_and_mark_needed (alias_decl, target);
5545 decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5546 TREE_CODE (alias_decl), target,
5547 TREE_TYPE (alias_decl));
5549 DECL_EXTERNAL (decl) = 1;
5550 TREE_PUBLIC (decl) = 1;
5551 DECL_ARTIFICIAL (decl) = 1;
5552 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5553 TREE_USED (decl) = 1;
5556 weak_finish_1 (decl);
5565 /* Remove the alias and the target from the pending weak list
5566 so that we do not emit any .weak directives for the former,
5567 nor multiple .weak directives for the latter. */
5568 for (p = &weak_decls; (t2 = *p) ; )
5570 if (TREE_VALUE (t2) == alias_decl
5571 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5572 *p = TREE_CHAIN (t2);
5574 p = &TREE_CHAIN (t2);
5577 /* Remove other weakrefs to the same target, to speed things up. */
5578 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5580 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5581 *p = TREE_CHAIN (t2);
5583 p = &TREE_CHAIN (t2);
5588 for (t = weak_decls; t; t = TREE_CHAIN (t))
5590 tree decl = TREE_VALUE (t);
5592 weak_finish_1 (decl);
5596 /* Emit the assembly bits to indicate that DECL is globally visible. */
5599 globalize_decl (tree decl)
5602 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5603 if (DECL_WEAK (decl))
5605 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5608 #ifdef ASM_WEAKEN_DECL
5609 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5611 ASM_WEAKEN_LABEL (asm_out_file, name);
5614 /* Remove this function from the pending weak list so that
5615 we do not emit multiple .weak directives for it. */
5616 for (p = &weak_decls; (t = *p) ; )
5618 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5619 *p = TREE_CHAIN (t);
5621 p = &TREE_CHAIN (t);
5624 /* Remove weakrefs to the same target from the pending weakref
5625 list, for the same reason. */
5626 for (p = &weakref_targets; (t = *p) ; )
5628 if (DECL_ASSEMBLER_NAME (decl)
5629 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5630 *p = TREE_CHAIN (t);
5632 p = &TREE_CHAIN (t);
5639 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5642 VEC(alias_pair,gc) *alias_pairs;
5644 /* Given an assembly name, find the decl it is associated with. At the
5645 same time, mark it needed for cgraph. */
5648 find_decl_and_mark_needed (tree decl, tree target)
5650 struct cgraph_node *fnode = NULL;
5651 struct varpool_node *vnode = NULL;
5653 if (TREE_CODE (decl) == FUNCTION_DECL)
5655 fnode = cgraph_node_for_asm (target);
5657 vnode = varpool_node_for_asm (target);
5661 vnode = varpool_node_for_asm (target);
5663 fnode = cgraph_node_for_asm (target);
5668 cgraph_mark_needed_node (fnode);
5673 varpool_mark_needed_node (vnode);
5674 vnode->force_output = 1;
5681 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5682 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5683 tree node is DECL to have the value of the tree node TARGET. */
5686 do_assemble_alias (tree decl, tree target)
5688 if (TREE_ASM_WRITTEN (decl))
5691 /* We must force creation of DECL_RTL for debug info generation, even though
5692 we don't use it here. */
5693 make_decl_rtl (decl);
5695 TREE_ASM_WRITTEN (decl) = 1;
5696 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5698 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5700 ultimate_transparent_alias_target (&target);
5702 if (!targetm.have_tls
5703 && TREE_CODE (decl) == VAR_DECL
5704 && DECL_THREAD_LOCAL_P (decl))
5706 decl = emutls_decl (decl);
5707 target = get_emutls_object_name (target);
5710 if (!TREE_SYMBOL_REFERENCED (target))
5711 weakref_targets = tree_cons (decl, target, weakref_targets);
5713 #ifdef ASM_OUTPUT_WEAKREF
5714 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5715 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5716 IDENTIFIER_POINTER (target));
5720 error_at (DECL_SOURCE_LOCATION (decl),
5721 "weakref is not supported in this configuration");
5728 if (!targetm.have_tls
5729 && TREE_CODE (decl) == VAR_DECL
5730 && DECL_THREAD_LOCAL_P (decl))
5732 decl = emutls_decl (decl);
5733 target = get_emutls_object_name (target);
5736 #ifdef ASM_OUTPUT_DEF
5737 /* Make name accessible from other files, if appropriate. */
5739 if (TREE_PUBLIC (decl))
5741 globalize_decl (decl);
5742 maybe_assemble_visibility (decl);
5745 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5746 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5748 ASM_OUTPUT_DEF (asm_out_file,
5749 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5750 IDENTIFIER_POINTER (target));
5752 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5757 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5758 # ifdef ASM_WEAKEN_DECL
5759 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5761 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5763 /* Remove this function from the pending weak list so that
5764 we do not emit multiple .weak directives for it. */
5765 for (p = &weak_decls; (t = *p) ; )
5766 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5767 *p = TREE_CHAIN (t);
5769 p = &TREE_CHAIN (t);
5771 /* Remove weakrefs to the same target from the pending weakref
5772 list, for the same reason. */
5773 for (p = &weakref_targets; (t = *p) ; )
5775 if (DECL_ASSEMBLER_NAME (decl)
5776 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5777 *p = TREE_CHAIN (t);
5779 p = &TREE_CHAIN (t);
5786 /* Remove the alias pairing for functions that are no longer in the call
5790 remove_unreachable_alias_pairs (void)
5795 if (alias_pairs == NULL)
5798 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5800 if (!DECL_EXTERNAL (p->decl))
5802 struct cgraph_node *fnode = NULL;
5803 struct varpool_node *vnode = NULL;
5804 fnode = cgraph_node_for_asm (p->target);
5805 vnode = (fnode == NULL) ? varpool_node_for_asm (p->target) : NULL;
5806 if (fnode == NULL && vnode == NULL)
5808 VEC_unordered_remove (alias_pair, alias_pairs, i);
5818 /* First pass of completing pending aliases. Make sure that cgraph knows
5819 which symbols will be required. */
5822 finish_aliases_1 (void)
5827 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5831 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5832 if (target_decl == NULL)
5834 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5835 error ("%q+D aliased to undefined symbol %qE",
5836 p->decl, p->target);
5838 else if (DECL_EXTERNAL (target_decl)
5839 /* We use local aliases for C++ thunks to force the tailcall
5840 to bind locally. Of course this is a hack - to keep it
5841 working do the following (which is not strictly correct). */
5842 && (! TREE_CODE (target_decl) == FUNCTION_DECL
5843 || ! DECL_VIRTUAL_P (target_decl))
5844 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5845 error ("%q+D aliased to external symbol %qE",
5846 p->decl, p->target);
5850 /* Second pass of completing pending aliases. Emit the actual assembly.
5851 This happens at the end of compilation and thus it is assured that the
5852 target symbol has been emitted. */
5855 finish_aliases_2 (void)
5860 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5861 do_assemble_alias (p->decl, p->target);
5863 VEC_truncate (alias_pair, alias_pairs, 0);
5866 /* Emit an assembler directive to make the symbol for DECL an alias to
5867 the symbol for TARGET. */
5870 assemble_alias (tree decl, tree target)
5873 bool is_weakref = false;
5875 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5877 tree alias = DECL_ASSEMBLER_NAME (decl);
5881 ultimate_transparent_alias_target (&target);
5883 if (alias == target)
5884 error ("weakref %q+D ultimately targets itself", decl);
5887 #ifndef ASM_OUTPUT_WEAKREF
5888 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5889 TREE_CHAIN (alias) = target;
5892 if (TREE_PUBLIC (decl))
5893 error ("weakref %q+D must have static linkage", decl);
5897 #if !defined (ASM_OUTPUT_DEF)
5898 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5899 error_at (DECL_SOURCE_LOCATION (decl),
5900 "alias definitions not supported in this configuration");
5903 if (!DECL_WEAK (decl))
5905 error_at (DECL_SOURCE_LOCATION (decl),
5906 "only weak aliases are supported in this configuration");
5912 TREE_USED (decl) = 1;
5914 /* A quirk of the initial implementation of aliases required that the user
5915 add "extern" to all of them. Which is silly, but now historical. Do
5916 note that the symbol is in fact locally defined. */
5918 DECL_EXTERNAL (decl) = 0;
5920 /* Allow aliases to aliases. */
5921 if (TREE_CODE (decl) == FUNCTION_DECL)
5922 cgraph_node (decl)->alias = true;
5924 varpool_node (decl)->alias = true;
5926 /* If the target has already been emitted, we don't have to queue the
5927 alias. This saves a tad of memory. */
5928 if (cgraph_global_info_ready)
5929 target_decl = find_decl_and_mark_needed (decl, target);
5932 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5933 do_assemble_alias (decl, target);
5936 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5942 /* Emit an assembler directive to set symbol for DECL visibility to
5943 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5946 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
5947 int vis ATTRIBUTE_UNUSED)
5949 #ifdef HAVE_GAS_HIDDEN
5950 static const char * const visibility_types[] = {
5951 NULL, "protected", "hidden", "internal"
5954 const char *name, *type;
5956 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5957 type = visibility_types[vis];
5959 fprintf (asm_out_file, "\t.%s\t", type);
5960 assemble_name (asm_out_file, name);
5961 fprintf (asm_out_file, "\n");
5963 warning (OPT_Wattributes, "visibility attribute not supported "
5964 "in this configuration; ignored");
5968 /* A helper function to call assemble_visibility when needed for a decl. */
5971 maybe_assemble_visibility (tree decl)
5973 enum symbol_visibility vis = DECL_VISIBILITY (decl);
5975 if (vis != VISIBILITY_DEFAULT)
5977 targetm.asm_out.assemble_visibility (decl, vis);
5984 /* Returns 1 if the target configuration supports defining public symbols
5985 so that one of them will be chosen at link time instead of generating a
5986 multiply-defined symbol error, whether through the use of weak symbols or
5987 a target-specific mechanism for having duplicates discarded. */
5990 supports_one_only (void)
5992 if (SUPPORTS_ONE_ONLY)
5994 return SUPPORTS_WEAK;
5997 /* Set up DECL as a public symbol that can be defined in multiple
5998 translation units without generating a linker error. */
6001 make_decl_one_only (tree decl, tree comdat_group)
6003 gcc_assert (TREE_CODE (decl) == VAR_DECL
6004 || TREE_CODE (decl) == FUNCTION_DECL);
6006 TREE_PUBLIC (decl) = 1;
6008 if (SUPPORTS_ONE_ONLY)
6010 #ifdef MAKE_DECL_ONE_ONLY
6011 MAKE_DECL_ONE_ONLY (decl);
6013 DECL_COMDAT_GROUP (decl) = comdat_group;
6015 else if (TREE_CODE (decl) == VAR_DECL
6016 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
6017 DECL_COMMON (decl) = 1;
6020 gcc_assert (SUPPORTS_WEAK);
6021 DECL_WEAK (decl) = 1;
6026 init_varasm_once (void)
6028 section_htab = htab_create_ggc (31, section_entry_hash,
6029 section_entry_eq, NULL);
6030 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
6031 object_block_entry_eq, NULL);
6032 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
6033 const_desc_eq, NULL);
6035 const_alias_set = new_alias_set ();
6036 shared_constant_pool = create_constant_pool ();
6038 #ifdef TEXT_SECTION_ASM_OP
6039 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
6040 TEXT_SECTION_ASM_OP);
6043 #ifdef DATA_SECTION_ASM_OP
6044 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6045 DATA_SECTION_ASM_OP);
6048 #ifdef SDATA_SECTION_ASM_OP
6049 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6050 SDATA_SECTION_ASM_OP);
6053 #ifdef READONLY_DATA_SECTION_ASM_OP
6054 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
6055 READONLY_DATA_SECTION_ASM_OP);
6058 #ifdef CTORS_SECTION_ASM_OP
6059 ctors_section = get_unnamed_section (0, output_section_asm_op,
6060 CTORS_SECTION_ASM_OP);
6063 #ifdef DTORS_SECTION_ASM_OP
6064 dtors_section = get_unnamed_section (0, output_section_asm_op,
6065 DTORS_SECTION_ASM_OP);
6068 #ifdef BSS_SECTION_ASM_OP
6069 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6070 output_section_asm_op,
6071 BSS_SECTION_ASM_OP);
6074 #ifdef SBSS_SECTION_ASM_OP
6075 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6076 output_section_asm_op,
6077 SBSS_SECTION_ASM_OP);
6080 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6081 | SECTION_COMMON, emit_tls_common);
6082 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6083 | SECTION_COMMON, emit_local);
6084 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6085 | SECTION_COMMON, emit_common);
6087 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
6088 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
6092 targetm.asm_out.init_sections ();
6094 if (readonly_data_section == NULL)
6095 readonly_data_section = text_section;
6099 decl_default_tls_model (const_tree decl)
6101 enum tls_model kind;
6104 is_local = targetm.binds_local_p (decl);
6108 kind = TLS_MODEL_LOCAL_EXEC;
6110 kind = TLS_MODEL_INITIAL_EXEC;
6113 /* Local dynamic is inefficient when we're not combining the
6114 parts of the address. */
6115 else if (optimize && is_local)
6116 kind = TLS_MODEL_LOCAL_DYNAMIC;
6118 kind = TLS_MODEL_GLOBAL_DYNAMIC;
6119 if (kind < flag_tls_default)
6120 kind = flag_tls_default;
6125 /* Select a set of attributes for section NAME based on the properties
6126 of DECL and whether or not RELOC indicates that DECL's initializer
6127 might contain runtime relocations.
6129 We make the section read-only and executable for a function decl,
6130 read-only for a const data decl, and writable for a non-const data decl. */
6133 default_section_type_flags (tree decl, const char *name, int reloc)
6137 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
6138 flags = SECTION_CODE;
6139 else if (decl && decl_readonly_section (decl, reloc))
6141 else if (current_function_decl
6143 && crtl->subsections.unlikely_text_section_name
6144 && strcmp (name, crtl->subsections.unlikely_text_section_name) == 0)
6145 flags = SECTION_CODE;
6147 && (!current_function_decl || !cfun)
6148 && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6149 flags = SECTION_CODE;
6151 flags = SECTION_WRITE;
6153 if (decl && DECL_ONE_ONLY (decl))
6154 flags |= SECTION_LINKONCE;
6156 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6157 flags |= SECTION_TLS | SECTION_WRITE;
6159 if (strcmp (name, ".bss") == 0
6160 || strncmp (name, ".bss.", 5) == 0
6161 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
6162 || strcmp (name, ".sbss") == 0
6163 || strncmp (name, ".sbss.", 6) == 0
6164 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
6165 flags |= SECTION_BSS;
6167 if (strcmp (name, ".tdata") == 0
6168 || strncmp (name, ".tdata.", 7) == 0
6169 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
6170 flags |= SECTION_TLS;
6172 if (strcmp (name, ".tbss") == 0
6173 || strncmp (name, ".tbss.", 6) == 0
6174 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
6175 flags |= SECTION_TLS | SECTION_BSS;
6177 /* These three sections have special ELF types. They are neither
6178 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6179 want to print a section type (@progbits or @nobits). If someone
6180 is silly enough to emit code or TLS variables to one of these
6181 sections, then don't handle them specially. */
6182 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
6183 && (strcmp (name, ".init_array") == 0
6184 || strcmp (name, ".fini_array") == 0
6185 || strcmp (name, ".preinit_array") == 0))
6186 flags |= SECTION_NOTYPE;
6191 /* Return true if the target supports some form of global BSS,
6192 either through bss_noswitch_section, or by selecting a BSS
6193 section in TARGET_ASM_SELECT_SECTION. */
6196 have_global_bss_p (void)
6198 return bss_noswitch_section || targetm.have_switchable_bss_sections;
6201 /* Output assembly to switch to section NAME with attribute FLAGS.
6202 Four variants for common object file formats. */
6205 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
6206 unsigned int flags ATTRIBUTE_UNUSED,
6207 tree decl ATTRIBUTE_UNUSED)
6209 /* Some object formats don't support named sections at all. The
6210 front-end should already have flagged this as an error. */
6214 #ifndef TLS_SECTION_ASM_FLAG
6215 #define TLS_SECTION_ASM_FLAG 'T'
6219 default_elf_asm_named_section (const char *name, unsigned int flags,
6220 tree decl ATTRIBUTE_UNUSED)
6222 char flagchars[10], *f = flagchars;
6224 /* If we have already declared this section, we can use an
6225 abbreviated form to switch back to it -- unless this section is
6226 part of a COMDAT groups, in which case GAS requires the full
6227 declaration every time. */
6228 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6229 && (flags & SECTION_DECLARED))
6231 fprintf (asm_out_file, "\t.section\t%s\n", name);
6235 if (!(flags & SECTION_DEBUG))
6237 if (flags & SECTION_WRITE)
6239 if (flags & SECTION_CODE)
6241 if (flags & SECTION_SMALL)
6243 if (flags & SECTION_MERGE)
6245 if (flags & SECTION_STRINGS)
6247 if (flags & SECTION_TLS)
6248 *f++ = TLS_SECTION_ASM_FLAG;
6249 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6253 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
6255 if (!(flags & SECTION_NOTYPE))
6260 if (flags & SECTION_BSS)
6266 #ifdef ASM_COMMENT_START
6267 /* On platforms that use "@" as the assembly comment character,
6269 if (strcmp (ASM_COMMENT_START, "@") == 0)
6272 fprintf (asm_out_file, format, type);
6274 if (flags & SECTION_ENTSIZE)
6275 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
6276 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6278 if (TREE_CODE (decl) == IDENTIFIER_NODE)
6279 fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
6281 fprintf (asm_out_file, ",%s,comdat",
6282 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
6286 putc ('\n', asm_out_file);
6290 default_coff_asm_named_section (const char *name, unsigned int flags,
6291 tree decl ATTRIBUTE_UNUSED)
6293 char flagchars[8], *f = flagchars;
6295 if (flags & SECTION_WRITE)
6297 if (flags & SECTION_CODE)
6301 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
6305 default_pe_asm_named_section (const char *name, unsigned int flags,
6308 default_coff_asm_named_section (name, flags, decl);
6310 if (flags & SECTION_LINKONCE)
6312 /* Functions may have been compiled at various levels of
6313 optimization so we can't use `same_size' here.
6314 Instead, have the linker pick one. */
6315 fprintf (asm_out_file, "\t.linkonce %s\n",
6316 (flags & SECTION_CODE ? "discard" : "same_size"));
6320 /* The lame default section selector. */
6323 default_select_section (tree decl, int reloc,
6324 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6328 if (decl_readonly_section (decl, reloc))
6329 return readonly_data_section;
6331 else if (TREE_CODE (decl) == CONSTRUCTOR)
6333 if (! ((flag_pic && reloc)
6334 || !TREE_READONLY (decl)
6335 || TREE_SIDE_EFFECTS (decl)
6336 || !TREE_CONSTANT (decl)))
6337 return readonly_data_section;
6339 else if (TREE_CODE (decl) == STRING_CST)
6340 return readonly_data_section;
6341 else if (! (flag_pic && reloc))
6342 return readonly_data_section;
6344 return data_section;
6347 enum section_category
6348 categorize_decl_for_section (const_tree decl, int reloc)
6350 enum section_category ret;
6352 if (TREE_CODE (decl) == FUNCTION_DECL)
6354 else if (TREE_CODE (decl) == STRING_CST)
6356 if (flag_mudflap) /* or !flag_merge_constants */
6357 return SECCAT_RODATA;
6359 return SECCAT_RODATA_MERGE_STR;
6361 else if (TREE_CODE (decl) == VAR_DECL)
6363 if (bss_initializer_p (decl))
6365 else if (! TREE_READONLY (decl)
6366 || TREE_SIDE_EFFECTS (decl)
6367 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6369 /* Here the reloc_rw_mask is not testing whether the section should
6370 be read-only or not, but whether the dynamic link will have to
6371 do something. If so, we wish to segregate the data in order to
6372 minimize cache misses inside the dynamic linker. */
6373 if (reloc & targetm.asm_out.reloc_rw_mask ())
6374 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6378 else if (reloc & targetm.asm_out.reloc_rw_mask ())
6379 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6380 else if (reloc || flag_merge_constants < 2)
6381 /* C and C++ don't allow different variables to share the same
6382 location. -fmerge-all-constants allows even that (at the
6383 expense of not conforming). */
6384 ret = SECCAT_RODATA;
6385 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6386 ret = SECCAT_RODATA_MERGE_STR_INIT;
6388 ret = SECCAT_RODATA_MERGE_CONST;
6390 else if (TREE_CODE (decl) == CONSTRUCTOR)
6392 if ((reloc & targetm.asm_out.reloc_rw_mask ())
6393 || TREE_SIDE_EFFECTS (decl)
6394 || ! TREE_CONSTANT (decl))
6397 ret = SECCAT_RODATA;
6400 ret = SECCAT_RODATA;
6402 /* There are no read-only thread-local sections. */
6403 if (TREE_CODE (decl) == VAR_DECL && DECL_TLS_MODEL (decl))
6405 if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED)
6407 if (DECL_EMUTLS_VAR_P (decl))
6409 if (targetm.emutls.var_section)
6410 ret = SECCAT_EMUTLS_VAR;
6414 if (targetm.emutls.tmpl_prefix)
6415 ret = SECCAT_EMUTLS_TMPL;
6418 /* Note that this would be *just* SECCAT_BSS, except that there's
6419 no concept of a read-only thread-local-data section. */
6420 else if (ret == SECCAT_BSS
6421 || (flag_zero_initialized_in_bss
6422 && initializer_zerop (DECL_INITIAL (decl))))
6428 /* If the target uses small data sections, select it. */
6429 else if (targetm.in_small_data_p (decl))
6431 if (ret == SECCAT_BSS)
6433 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6434 ret = SECCAT_SRODATA;
6443 decl_readonly_section (const_tree decl, int reloc)
6445 switch (categorize_decl_for_section (decl, reloc))
6448 case SECCAT_RODATA_MERGE_STR:
6449 case SECCAT_RODATA_MERGE_STR_INIT:
6450 case SECCAT_RODATA_MERGE_CONST:
6451 case SECCAT_SRODATA:
6460 /* Select a section based on the above categorization. */
6463 default_elf_select_section (tree decl, int reloc,
6464 unsigned HOST_WIDE_INT align)
6467 switch (categorize_decl_for_section (decl, reloc))
6470 /* We're not supposed to be called on FUNCTION_DECLs. */
6473 return readonly_data_section;
6474 case SECCAT_RODATA_MERGE_STR:
6475 return mergeable_string_section (decl, align, 0);
6476 case SECCAT_RODATA_MERGE_STR_INIT:
6477 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6478 case SECCAT_RODATA_MERGE_CONST:
6479 return mergeable_constant_section (DECL_MODE (decl), align, 0);
6480 case SECCAT_SRODATA:
6484 return data_section;
6485 case SECCAT_DATA_REL:
6486 sname = ".data.rel";
6488 case SECCAT_DATA_REL_LOCAL:
6489 sname = ".data.rel.local";
6491 case SECCAT_DATA_REL_RO:
6492 sname = ".data.rel.ro";
6494 case SECCAT_DATA_REL_RO_LOCAL:
6495 sname = ".data.rel.ro.local";
6514 case SECCAT_EMUTLS_VAR:
6515 sname = targetm.emutls.var_section;
6517 case SECCAT_EMUTLS_TMPL:
6518 sname = targetm.emutls.tmpl_section;
6526 return get_named_section (decl, sname, reloc);
6529 /* Construct a unique section name based on the decl name and the
6530 categorization performed above. */
6533 default_unique_section (tree decl, int reloc)
6535 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6536 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6537 const char *prefix, *name, *linkonce;
6540 switch (categorize_decl_for_section (decl, reloc))
6543 prefix = one_only ? ".t" : ".text";
6546 case SECCAT_RODATA_MERGE_STR:
6547 case SECCAT_RODATA_MERGE_STR_INIT:
6548 case SECCAT_RODATA_MERGE_CONST:
6549 prefix = one_only ? ".r" : ".rodata";
6551 case SECCAT_SRODATA:
6552 prefix = one_only ? ".s2" : ".sdata2";
6555 prefix = one_only ? ".d" : ".data";
6557 case SECCAT_DATA_REL:
6558 prefix = one_only ? ".d.rel" : ".data.rel";
6560 case SECCAT_DATA_REL_LOCAL:
6561 prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6563 case SECCAT_DATA_REL_RO:
6564 prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6566 case SECCAT_DATA_REL_RO_LOCAL:
6567 prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6570 prefix = one_only ? ".s" : ".sdata";
6573 prefix = one_only ? ".b" : ".bss";
6576 prefix = one_only ? ".sb" : ".sbss";
6579 prefix = one_only ? ".td" : ".tdata";
6582 prefix = one_only ? ".tb" : ".tbss";
6584 case SECCAT_EMUTLS_VAR:
6585 prefix = targetm.emutls.var_section;
6587 case SECCAT_EMUTLS_TMPL:
6588 prefix = targetm.emutls.tmpl_section;
6594 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6595 name = targetm.strip_name_encoding (name);
6597 /* If we're using one_only, then there needs to be a .gnu.linkonce
6598 prefix to the section name. */
6599 linkonce = one_only ? ".gnu.linkonce" : "";
6601 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6603 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6606 /* Like compute_reloc_for_constant, except for an RTX. The return value
6607 is a mask for which bit 1 indicates a global relocation, and bit 0
6608 indicates a local relocation. */
6611 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6613 int *preloc = (int *) data;
6616 switch (GET_CODE (x))
6619 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6632 compute_reloc_for_rtx (rtx x)
6636 switch (GET_CODE (x))
6642 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6651 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6653 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6655 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6656 return data_section;
6658 return readonly_data_section;
6662 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6663 unsigned HOST_WIDE_INT align)
6665 int reloc = compute_reloc_for_rtx (x);
6667 /* ??? Handle small data here somehow. */
6669 if (reloc & targetm.asm_out.reloc_rw_mask ())
6672 return get_named_section (NULL, ".data.rel.ro.local", 1);
6674 return get_named_section (NULL, ".data.rel.ro", 3);
6677 return mergeable_constant_section (mode, align, 0);
6680 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6683 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6688 /* Careful not to prod global register variables. */
6691 symbol = XEXP (rtl, 0);
6692 if (GET_CODE (symbol) != SYMBOL_REF)
6695 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6696 if (TREE_CODE (decl) == FUNCTION_DECL)
6697 flags |= SYMBOL_FLAG_FUNCTION;
6698 if (targetm.binds_local_p (decl))
6699 flags |= SYMBOL_FLAG_LOCAL;
6700 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)
6701 && DECL_TLS_MODEL (decl) != TLS_MODEL_EMULATED)
6702 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6703 else if (targetm.in_small_data_p (decl))
6704 flags |= SYMBOL_FLAG_SMALL;
6705 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6706 being PUBLIC, the thing *must* be defined in this translation unit.
6707 Prevent this buglet from being propagated into rtl code as well. */
6708 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6709 flags |= SYMBOL_FLAG_EXTERNAL;
6711 SYMBOL_REF_FLAGS (symbol) = flags;
6714 /* By default, we do nothing for encode_section_info, so we need not
6715 do anything but discard the '*' marker. */
6718 default_strip_name_encoding (const char *str)
6720 return str + (*str == '*');
6723 #ifdef ASM_OUTPUT_DEF
6724 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6725 anchor relative to ".", the current section position. */
6728 default_asm_output_anchor (rtx symbol)
6732 sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6733 SYMBOL_REF_BLOCK_OFFSET (symbol));
6734 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6738 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6741 default_use_anchors_for_symbol_p (const_rtx symbol)
6746 /* Don't use anchors for mergeable sections. The linker might move
6747 the objects around. */
6748 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6749 if (sect->common.flags & SECTION_MERGE)
6752 /* Don't use anchors for small data sections. The small data register
6753 acts as an anchor for such sections. */
6754 if (sect->common.flags & SECTION_SMALL)
6757 decl = SYMBOL_REF_DECL (symbol);
6758 if (decl && DECL_P (decl))
6760 /* Don't use section anchors for decls that might be defined by
6762 if (!targetm.binds_local_p (decl))
6765 /* Don't use section anchors for decls that will be placed in a
6766 small data section. */
6767 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6768 one above. The problem is that we only use SECTION_SMALL for
6769 sections that should be marked as small in the section directive. */
6770 if (targetm.in_small_data_p (decl))
6776 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6777 wrt cross-module name binding. */
6780 default_binds_local_p (const_tree exp)
6782 return default_binds_local_p_1 (exp, flag_shlib);
6786 default_binds_local_p_1 (const_tree exp, int shlib)
6790 /* A non-decl is an entry in the constant pool. */
6793 /* Weakrefs may not bind locally, even though the weakref itself is
6794 always static and therefore local. */
6795 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6797 /* Static variables are always local. */
6798 else if (! TREE_PUBLIC (exp))
6800 /* A variable is local if the user has said explicitly that it will
6802 else if (DECL_VISIBILITY_SPECIFIED (exp)
6803 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6805 /* Variables defined outside this object might not be local. */
6806 else if (DECL_EXTERNAL (exp))
6808 /* If defined in this object and visibility is not default, must be
6810 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6812 /* Default visibility weak data can be overridden by a strong symbol
6813 in another module and so are not local. */
6814 else if (DECL_WEAK (exp))
6816 /* If PIC, then assume that any global name can be overridden by
6817 symbols resolved from other modules, unless we are compiling with
6818 -fwhole-program, which assumes that names are local. */
6820 local_p = flag_whole_program;
6821 /* Uninitialized COMMON variable may be unified with symbols
6822 resolved from other modules. */
6823 else if (DECL_COMMON (exp)
6824 && (DECL_INITIAL (exp) == NULL
6825 || DECL_INITIAL (exp) == error_mark_node))
6827 /* Otherwise we're left with initialized (or non-common) global data
6828 which is of necessity defined locally. */
6835 /* Default function to output code that will globalize a label. A
6836 target must define GLOBAL_ASM_OP or provide its own function to
6837 globalize a label. */
6838 #ifdef GLOBAL_ASM_OP
6840 default_globalize_label (FILE * stream, const char *name)
6842 fputs (GLOBAL_ASM_OP, stream);
6843 assemble_name (stream, name);
6844 putc ('\n', stream);
6846 #endif /* GLOBAL_ASM_OP */
6848 /* Default function to output code that will globalize a declaration. */
6850 default_globalize_decl_name (FILE * stream, tree decl)
6852 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6853 targetm.asm_out.globalize_label (stream, name);
6856 /* Default function to output a label for unwind information. The
6857 default is to do nothing. A target that needs nonlocal labels for
6858 unwind information must provide its own function to do this. */
6860 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6861 tree decl ATTRIBUTE_UNUSED,
6862 int for_eh ATTRIBUTE_UNUSED,
6863 int empty ATTRIBUTE_UNUSED)
6867 /* Default function to output a label to divide up the exception table.
6868 The default is to do nothing. A target that needs/wants to divide
6869 up the table must provide it's own function to do this. */
6871 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6875 /* This is how to output an internal numbered label where PREFIX is
6876 the class of label and LABELNO is the number within the class. */
6879 default_internal_label (FILE *stream, const char *prefix,
6880 unsigned long labelno)
6882 char *const buf = (char *) alloca (40 + strlen (prefix));
6883 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6884 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6888 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6891 default_asm_declare_constant_name (FILE *file, const char *name,
6892 const_tree exp ATTRIBUTE_UNUSED,
6893 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
6895 assemble_label (file, name);
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.asm_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.asm_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)
7199 case SWITCH_TYPE_PASSED:
7200 ASM_OUTPUT_ASCII (asm_out_file, name, strlen (name));
7201 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7204 case SWITCH_TYPE_DESCRIPTIVE:
7207 /* Distinguish between invocations where name is NULL. */
7208 static bool started = false;
7214 sec = get_section (targetm.asm_out.record_gcc_switches_section,
7218 | (SECTION_ENTSIZE & 1),
7220 switch_to_section (sec);
7229 /* The return value is currently ignored by the caller, but must be 0.
7230 For -fverbose-asm the return value would be the number of characters
7231 emitted into the assembler file. */
7235 /* Emit text to declare externally defined symbols. It is needed to
7236 properly support non-default visibility. */
7238 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
7240 const char *name ATTRIBUTE_UNUSED)
7242 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7243 set in order to avoid putting out names that are never really
7245 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
7246 && targetm.binds_local_p (decl))
7247 maybe_assemble_visibility (decl);
7250 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7253 make_debug_expr_from_rtl (const_rtx exp)
7255 tree ddecl = make_node (DEBUG_EXPR_DECL), type;
7256 enum machine_mode mode = GET_MODE (exp);
7259 DECL_ARTIFICIAL (ddecl) = 1;
7260 if (REG_P (exp) && REG_EXPR (exp))
7261 type = TREE_TYPE (REG_EXPR (exp));
7262 else if (MEM_P (exp) && MEM_EXPR (exp))
7263 type = TREE_TYPE (MEM_EXPR (exp));
7266 if (type && TYPE_MODE (type) == mode)
7267 TREE_TYPE (ddecl) = type;
7269 TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
7270 DECL_MODE (ddecl) = mode;
7271 dval = gen_rtx_DEBUG_EXPR (mode);
7272 DEBUG_EXPR_TREE_DECL (dval) = ddecl;
7273 SET_DECL_RTL (ddecl, dval);
7277 #include "gt-varasm.h"