1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
42 #include "diagnostic-core.h"
46 #include "langhooks.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h" /* Needed for external data
59 declarations for e.g. AIX 4.x. */
62 /* The (assembler) name of the first globally-visible object output. */
63 extern GTY(()) const char *first_global_object_name;
64 extern GTY(()) const char *weak_global_object_name;
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
70 struct constant_descriptor_rtx;
71 struct rtx_constant_pool;
73 #define n_deferred_constants (crtl->varasm.deferred_constants)
75 /* Number for making the label on the next
76 constant that is stored in memory. */
78 static GTY(()) int const_labelno;
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81 to ASM_FINISH_DECLARE_OBJECT. */
83 int size_directive_output;
85 /* The last decl for which assemble_variable was called,
86 if it did ASM_DECLARE_OBJECT_NAME.
87 If the last call to assemble_variable didn't do that,
90 tree last_assemble_variable_decl;
92 /* The following global variable indicates if the first basic block
93 in a function belongs to the cold partition or not. */
95 bool first_function_block_is_cold;
97 /* We give all constants their own alias set. Perhaps redundant with
98 MEM_READONLY_P, but pre-dates it. */
100 static alias_set_type const_alias_set;
102 static const char *strip_reg_name (const char *);
103 static int contains_pointers_p (tree);
104 #ifdef ASM_OUTPUT_EXTERNAL
105 static bool incorporeal_function_p (tree);
107 static void decode_addr_const (tree, struct addr_const *);
108 static hashval_t const_desc_hash (const void *);
109 static int const_desc_eq (const void *, const void *);
110 static hashval_t const_hash_1 (const tree);
111 static int compare_constant (const tree, const tree);
112 static tree copy_constant (tree);
113 static void output_constant_def_contents (rtx);
114 static void output_addressed_constants (tree);
115 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
116 static unsigned min_align (unsigned, unsigned);
117 static void globalize_decl (tree);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_BSS
120 static void asm_output_bss (FILE *, tree, const char *,
121 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
123 #ifdef ASM_OUTPUT_ALIGNED_BSS
124 static void asm_output_aligned_bss (FILE *, tree, const char *,
125 unsigned HOST_WIDE_INT, int)
128 #endif /* BSS_SECTION_ASM_OP */
129 static void mark_weak (tree);
130 static void output_constant_pool (const char *, tree);
132 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
133 section *text_section;
134 section *data_section;
135 section *readonly_data_section;
136 section *sdata_section;
137 section *ctors_section;
138 section *dtors_section;
139 section *bss_section;
140 section *sbss_section;
142 /* Various forms of common section. All are guaranteed to be nonnull. */
143 section *tls_comm_section;
144 section *comm_section;
145 section *lcomm_section;
147 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
149 section *bss_noswitch_section;
151 /* The section that holds the main exception table, when known. The section
152 is set either by the target's init_sections hook or by the first call to
153 switch_to_exception_section. */
154 section *exception_section;
156 /* The section that holds the DWARF2 frame unwind information, when known.
157 The section is set either by the target's init_sections hook or by the
158 first call to switch_to_eh_frame_section. */
159 section *eh_frame_section;
161 /* asm_out_file's current section. This is NULL if no section has yet
162 been selected or if we lose track of what the current section is. */
165 /* True if code for the current function is currently being directed
166 at the cold section. */
167 bool in_cold_section_p;
169 /* A linked list of all the unnamed sections. */
170 static GTY(()) section *unnamed_sections;
172 /* Return a nonzero value if DECL has a section attribute. */
173 #define IN_NAMED_SECTION(DECL) \
174 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
175 && DECL_SECTION_NAME (DECL) != NULL_TREE)
177 /* Hash table of named sections. */
178 static GTY((param_is (section))) htab_t section_htab;
180 /* A table of object_blocks, indexed by section. */
181 static GTY((param_is (struct object_block))) htab_t object_block_htab;
183 /* The next number to use for internal anchor labels. */
184 static GTY(()) int anchor_labelno;
186 /* A pool of constants that can be shared between functions. */
187 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
193 static GTY (()) tree emutls_object_type;
194 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
195 macro can be used on them to distinguish the control variable from
196 the initialization template. */
197 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
199 #if !defined (NO_DOT_IN_LABEL)
200 # define EMUTLS_SEPARATOR "."
201 #elif !defined (NO_DOLLAR_IN_LABEL)
202 # define EMUTLS_SEPARATOR "$"
204 # define EMUTLS_SEPARATOR "_"
207 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
208 IDENTIFIER_NODE NAME's name. */
211 prefix_name (const char *prefix, tree name)
213 unsigned plen = strlen (prefix);
214 unsigned nlen = strlen (IDENTIFIER_POINTER (name));
215 char *toname = (char *) alloca (plen + nlen + 1);
217 memcpy (toname, prefix, plen);
218 memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
220 return get_identifier (toname);
223 /* Create an identifier for the struct __emutls_object, given an identifier
224 of the DECL_ASSEMBLY_NAME of the original object. */
227 get_emutls_object_name (tree name)
229 const char *prefix = (targetm.emutls.var_prefix
230 ? targetm.emutls.var_prefix
231 : "__emutls_v" EMUTLS_SEPARATOR);
232 return prefix_name (prefix, name);
236 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
238 tree word_type_node, field, next_field;
240 field = build_decl (UNKNOWN_LOCATION,
241 FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
242 DECL_CONTEXT (field) = type;
245 field = build_decl (UNKNOWN_LOCATION,
246 FIELD_DECL, get_identifier ("__offset"),
248 DECL_CONTEXT (field) = type;
249 TREE_CHAIN (field) = next_field;
252 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
253 field = build_decl (UNKNOWN_LOCATION,
254 FIELD_DECL, get_identifier ("__align"),
256 DECL_CONTEXT (field) = type;
257 TREE_CHAIN (field) = next_field;
260 field = build_decl (UNKNOWN_LOCATION,
261 FIELD_DECL, get_identifier ("__size"), word_type_node);
262 DECL_CONTEXT (field) = type;
263 TREE_CHAIN (field) = next_field;
268 /* Create the structure for struct __emutls_object. This should match the
269 structure at the top of emutls.c, modulo the union there. */
272 get_emutls_object_type (void)
274 tree type, type_name, field;
276 type = emutls_object_type;
280 emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
282 field = targetm.emutls.var_fields (type, &type_name);
284 type_name = get_identifier ("__emutls_object");
285 type_name = build_decl (UNKNOWN_LOCATION,
286 TYPE_DECL, type_name, type);
287 TYPE_NAME (type) = type_name;
288 TYPE_FIELDS (type) = field;
294 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
295 This will be used for initializing the emulated tls data area. */
298 get_emutls_init_templ_addr (tree decl)
302 if (targetm.emutls.register_common && !DECL_INITIAL (decl)
303 && !DECL_SECTION_NAME (decl))
304 return null_pointer_node;
306 name = DECL_ASSEMBLER_NAME (decl);
307 if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0])
309 const char *prefix = (targetm.emutls.tmpl_prefix
310 ? targetm.emutls.tmpl_prefix
311 : "__emutls_t" EMUTLS_SEPARATOR);
312 name = prefix_name (prefix, name);
315 to = build_decl (DECL_SOURCE_LOCATION (decl),
316 VAR_DECL, name, TREE_TYPE (decl));
317 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
319 DECL_ARTIFICIAL (to) = 1;
320 TREE_USED (to) = TREE_USED (decl);
321 TREE_READONLY (to) = 1;
322 DECL_IGNORED_P (to) = 1;
323 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
324 DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
325 DECL_PRESERVE_P (to) = DECL_PRESERVE_P (decl);
327 DECL_WEAK (to) = DECL_WEAK (decl);
328 if (DECL_ONE_ONLY (decl))
330 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
331 TREE_STATIC (to) = TREE_STATIC (decl);
332 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
333 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
336 TREE_STATIC (to) = 1;
338 DECL_VISIBILITY_SPECIFIED (to) = DECL_VISIBILITY_SPECIFIED (decl);
339 DECL_INITIAL (to) = DECL_INITIAL (decl);
340 DECL_INITIAL (decl) = NULL;
342 varpool_finalize_decl (to);
343 return build_fold_addr_expr (to);
346 /* When emulating tls, we use a control structure for use by the runtime.
347 Create and return this structure. */
350 emutls_decl (tree decl)
353 struct tree_map *h, in;
356 if (targetm.have_tls || decl == NULL || decl == error_mark_node
357 || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
360 /* Look up the object in the hash; return the control structure if
361 it has already been created. */
363 emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
365 name = DECL_ASSEMBLER_NAME (decl);
367 /* Note that we use the hash of the decl's name, rather than a hash
368 of the decl's pointer. In emutls_finish we iterate through the
369 hash table, and we want this traversal to be predictable. */
370 in.hash = IDENTIFIER_HASH_VALUE (name);
372 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
373 h = (struct tree_map *) *loc;
378 to = build_decl (DECL_SOURCE_LOCATION (decl),
379 VAR_DECL, get_emutls_object_name (name),
380 get_emutls_object_type ());
382 h = ggc_alloc_tree_map ();
386 *(struct tree_map **) loc = h;
388 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
389 DECL_ARTIFICIAL (to) = 1;
390 DECL_IGNORED_P (to) = 1;
391 /* FIXME: work around PR44132. */
392 DECL_PRESERVE_P (to) = 1;
393 TREE_READONLY (to) = 0;
394 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
395 if (DECL_ONE_ONLY (decl))
396 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
397 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
398 if (targetm.emutls.var_align_fixed)
399 /* If we're not allowed to change the proxy object's
400 alignment, pretend it's been set by the user. */
401 DECL_USER_ALIGN (to) = 1;
404 /* Note that these fields may need to be updated from time to time from
405 the original decl. Consider:
406 extern __thread int i;
407 int foo() { return i; }
409 in which I goes from external to locally defined and initialized. */
410 DECL_DLLIMPORT_P (to) = DECL_DLLIMPORT_P (decl);
411 DECL_ATTRIBUTES (to) = targetm.merge_decl_attributes (decl, to);
413 TREE_STATIC (to) = TREE_STATIC (decl);
414 TREE_USED (to) = TREE_USED (decl);
415 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
416 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
417 DECL_COMMON (to) = DECL_COMMON (decl);
418 DECL_WEAK (to) = DECL_WEAK (decl);
419 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
420 DECL_VISIBILITY_SPECIFIED (to) = DECL_VISIBILITY_SPECIFIED (decl);
422 /* Fortran might pass this to us. */
423 DECL_RESTRICTED_P (to) = DECL_RESTRICTED_P (decl);
429 emutls_common_1 (void **loc, void *xstmts)
431 struct tree_map *h = *(struct tree_map **) loc;
432 tree 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 = TREE_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 = TREE_CHAIN (field);
2125 elt->value = null_pointer_node;
2127 elt = VEC_quick_push (constructor_elt, v, NULL);
2128 field = TREE_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 if (! targetm.have_tls
2154 && TREE_CODE (decl) == VAR_DECL
2155 && DECL_THREAD_LOCAL_P (decl))
2157 tree to = emutls_decl (decl);
2159 /* If this variable is defined locally, then we need to initialize the
2160 control structure with size and alignment information. We do this
2161 at the last moment because tentative definitions can take a locally
2162 defined but uninitialized variable and initialize it later, which
2163 would result in incorrect contents. */
2164 if (! DECL_EXTERNAL (to)
2165 && (! DECL_COMMON (to)
2166 || (DECL_INITIAL (decl)
2167 && DECL_INITIAL (decl) != error_mark_node)))
2169 DECL_INITIAL (to) = targetm.emutls.var_init
2170 (to, decl, get_emutls_init_templ_addr (decl));
2172 /* Make sure the template is marked as needed early enough.
2173 Without this, if the variable is placed in a
2174 section-anchored block, the template will only be marked
2175 when it's too late. */
2176 record_references_in_initializer (to, false);
2182 last_assemble_variable_decl = 0;
2184 /* Normally no need to say anything here for external references,
2185 since assemble_external is called by the language-specific code
2186 when a declaration is first seen. */
2188 if (DECL_EXTERNAL (decl))
2191 /* Output no assembler code for a function declaration.
2192 Only definitions of functions output anything. */
2194 if (TREE_CODE (decl) == FUNCTION_DECL)
2197 /* Do nothing for global register variables. */
2198 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2200 TREE_ASM_WRITTEN (decl) = 1;
2204 /* If type was incomplete when the variable was declared,
2205 see if it is complete now. */
2207 if (DECL_SIZE (decl) == 0)
2208 layout_decl (decl, 0);
2210 /* Still incomplete => don't allocate it; treat the tentative defn
2211 (which is what it must have been) as an `extern' reference. */
2213 if (!dont_output_data && DECL_SIZE (decl) == 0)
2215 error ("storage size of %q+D isn%'t known", decl);
2216 TREE_ASM_WRITTEN (decl) = 1;
2220 /* The first declaration of a variable that comes through this function
2221 decides whether it is global (in C, has external linkage)
2222 or local (in C, has internal linkage). So do nothing more
2223 if this function has already run. */
2225 if (TREE_ASM_WRITTEN (decl))
2228 /* Make sure targetm.encode_section_info is invoked before we set
2230 decl_rtl = DECL_RTL (decl);
2232 TREE_ASM_WRITTEN (decl) = 1;
2234 /* Do no output if -fsyntax-only. */
2235 if (flag_syntax_only)
2238 if (! dont_output_data
2239 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2241 error ("size of variable %q+D is too large", decl);
2245 gcc_assert (MEM_P (decl_rtl));
2246 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2247 symbol = XEXP (decl_rtl, 0);
2249 /* If this symbol belongs to the tree constant pool, output the constant
2250 if it hasn't already been written. */
2251 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2253 tree decl = SYMBOL_REF_DECL (symbol);
2254 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2255 output_constant_def_contents (symbol);
2261 name = XSTR (symbol, 0);
2262 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2263 notice_global_symbol (decl);
2265 /* Compute the alignment of this data. */
2267 align_variable (decl, dont_output_data);
2268 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2270 if (TREE_PUBLIC (decl))
2271 maybe_assemble_visibility (decl);
2273 if (DECL_PRESERVE_P (decl))
2274 targetm.asm_out.mark_decl_preserved (name);
2276 /* First make the assembler name(s) global if appropriate. */
2277 sect = get_variable_section (decl, false);
2278 if (TREE_PUBLIC (decl)
2279 && (sect->common.flags & SECTION_COMMON) == 0)
2280 globalize_decl (decl);
2282 /* Output any data that we will need to use the address of. */
2283 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2284 output_addressed_constants (DECL_INITIAL (decl));
2286 /* dbxout.c needs to know this. */
2287 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2288 DECL_IN_TEXT_SECTION (decl) = 1;
2290 /* If the decl is part of an object_block, make sure that the decl
2291 has been positioned within its block, but do not write out its
2292 definition yet. output_object_blocks will do that later. */
2293 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2295 gcc_assert (!dont_output_data);
2296 place_block_symbol (symbol);
2298 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2299 assemble_noswitch_variable (decl, name, sect);
2302 switch_to_section (sect);
2303 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2304 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2305 assemble_variable_contents (decl, name, dont_output_data);
2309 /* Return 1 if type TYPE contains any pointers. */
2312 contains_pointers_p (tree type)
2314 switch (TREE_CODE (type))
2317 case REFERENCE_TYPE:
2318 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2319 so I'll play safe and return 1. */
2325 case QUAL_UNION_TYPE:
2328 /* For a type that has fields, see if the fields have pointers. */
2329 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2330 if (TREE_CODE (fields) == FIELD_DECL
2331 && contains_pointers_p (TREE_TYPE (fields)))
2337 /* An array type contains pointers if its element type does. */
2338 return contains_pointers_p (TREE_TYPE (type));
2345 /* We delay assemble_external processing until
2346 the compilation unit is finalized. This is the best we can do for
2347 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2348 it all the way to final. See PR 17982 for further discussion. */
2349 static GTY(()) tree pending_assemble_externals;
2351 #ifdef ASM_OUTPUT_EXTERNAL
2352 /* True if DECL is a function decl for which no out-of-line copy exists.
2353 It is assumed that DECL's assembler name has been set. */
2356 incorporeal_function_p (tree decl)
2358 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2362 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2363 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2366 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2367 if (is_builtin_name (name))
2373 /* Actually do the tests to determine if this is necessary, and invoke
2374 ASM_OUTPUT_EXTERNAL. */
2376 assemble_external_real (tree decl)
2378 rtx rtl = DECL_RTL (decl);
2380 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2381 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2382 && !incorporeal_function_p (decl))
2384 /* Some systems do require some output. */
2385 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2386 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2392 process_pending_assemble_externals (void)
2394 #ifdef ASM_OUTPUT_EXTERNAL
2396 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2397 assemble_external_real (TREE_VALUE (list));
2399 pending_assemble_externals = 0;
2403 /* This TREE_LIST contains any weak symbol declarations waiting
2405 static GTY(()) tree weak_decls;
2407 /* Output something to declare an external symbol to the assembler,
2408 and qualifiers such as weakness. (Most assemblers don't need
2409 extern declaration, so we normally output nothing.) Do nothing if
2410 DECL is not external. */
2413 assemble_external (tree decl ATTRIBUTE_UNUSED)
2415 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2416 main body of this code is only rarely exercised. To provide some
2417 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2418 open. If it's not, we should not be calling this function. */
2419 gcc_assert (asm_out_file);
2421 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2424 /* We want to output annotation for weak and external symbols at
2425 very last to check if they are references or not. */
2429 /* TREE_STATIC is a weird and abused creature which is not
2430 generally the right test for whether an entity has been
2431 locally emitted, inlined or otherwise not-really-extern, but
2432 for declarations that can be weak, it happens to be
2434 && !TREE_STATIC (decl)
2435 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2436 && value_member (decl, weak_decls) == NULL_TREE)
2437 weak_decls = tree_cons (NULL, decl, weak_decls);
2439 #ifdef ASM_OUTPUT_EXTERNAL
2440 if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2441 pending_assemble_externals = tree_cons (NULL, decl,
2442 pending_assemble_externals);
2446 /* Similar, for calling a library function FUN. */
2449 assemble_external_libcall (rtx fun)
2451 /* Declare library function name external when first used, if nec. */
2452 if (! SYMBOL_REF_USED (fun))
2454 SYMBOL_REF_USED (fun) = 1;
2455 targetm.asm_out.external_libcall (fun);
2459 /* Assemble a label named NAME. */
2462 assemble_label (FILE *file, const char *name)
2464 ASM_OUTPUT_LABEL (file, name);
2467 /* Set the symbol_referenced flag for ID. */
2469 mark_referenced (tree id)
2471 TREE_SYMBOL_REFERENCED (id) = 1;
2474 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2476 mark_decl_referenced (tree decl)
2478 if (TREE_CODE (decl) == FUNCTION_DECL)
2480 /* Extern inline functions don't become needed when referenced.
2481 If we know a method will be emitted in other TU and no new
2482 functions can be marked reachable, just use the external
2484 struct cgraph_node *node = cgraph_node (decl);
2485 if (!DECL_EXTERNAL (decl)
2486 && (!node->local.vtable_method || !cgraph_global_info_ready
2487 || !node->local.finalized))
2488 cgraph_mark_needed_node (node);
2490 else if (TREE_CODE (decl) == VAR_DECL)
2492 struct varpool_node *node = varpool_node (decl);
2493 varpool_mark_needed_node (node);
2494 /* C++ frontend use mark_decl_references to force COMDAT variables
2495 to be output that might appear dead otherwise. */
2496 node->force_output = true;
2498 /* else do nothing - we can get various sorts of CST nodes here,
2499 which do not need to be marked. */
2503 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2504 until we find an identifier that is not itself a transparent alias.
2505 Modify the alias passed to it by reference (and all aliases on the
2506 way to the ultimate target), such that they do not have to be
2507 followed again, and return the ultimate target of the alias
2511 ultimate_transparent_alias_target (tree *alias)
2513 tree target = *alias;
2515 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2517 gcc_assert (TREE_CHAIN (target));
2518 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2519 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2520 && ! TREE_CHAIN (target));
2527 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2528 starts with a *, the rest of NAME is output verbatim. Otherwise
2529 NAME is transformed in a target-specific way (usually by the
2530 addition of an underscore). */
2533 assemble_name_raw (FILE *file, const char *name)
2536 fputs (&name[1], file);
2538 ASM_OUTPUT_LABELREF (file, name);
2541 /* Like assemble_name_raw, but should be used when NAME might refer to
2542 an entity that is also represented as a tree (like a function or
2543 variable). If NAME does refer to such an entity, that entity will
2544 be marked as referenced. */
2547 assemble_name (FILE *file, const char *name)
2549 const char *real_name;
2552 real_name = targetm.strip_name_encoding (name);
2554 id = maybe_get_identifier (real_name);
2559 mark_referenced (id);
2560 ultimate_transparent_alias_target (&id);
2562 name = IDENTIFIER_POINTER (id);
2563 gcc_assert (! TREE_CHAIN (id));
2566 assemble_name_raw (file, name);
2569 /* Allocate SIZE bytes writable static space with a gensym name
2570 and return an RTX to refer to its address. */
2573 assemble_static_space (unsigned HOST_WIDE_INT size)
2576 const char *namestring;
2579 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2581 namestring = ggc_strdup (name);
2583 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2584 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2586 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2587 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2590 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2591 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2594 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2595 so that each uninitialized object starts on such a boundary. */
2596 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2597 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2598 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2599 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2600 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2601 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2608 /* Assemble the static constant template for function entry trampolines.
2609 This is done at most once per compilation.
2610 Returns an RTX for the address of the template. */
2612 static GTY(()) rtx initial_trampoline;
2615 assemble_trampoline_template (void)
2622 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2624 if (initial_trampoline)
2625 return initial_trampoline;
2627 /* By default, put trampoline templates in read-only data section. */
2629 #ifdef TRAMPOLINE_SECTION
2630 switch_to_section (TRAMPOLINE_SECTION);
2632 switch_to_section (readonly_data_section);
2635 /* Write the assembler code to define one. */
2636 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2638 ASM_OUTPUT_ALIGN (asm_out_file, align);
2640 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2641 targetm.asm_out.trampoline_template (asm_out_file);
2643 /* Record the rtl to refer to it. */
2644 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2645 name = ggc_strdup (label);
2646 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2647 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2649 initial_trampoline = gen_const_mem (BLKmode, symbol);
2650 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2651 set_mem_size (initial_trampoline, GEN_INT (TRAMPOLINE_SIZE));
2653 return initial_trampoline;
2656 /* A and B are either alignments or offsets. Return the minimum alignment
2657 that may be assumed after adding the two together. */
2659 static inline unsigned
2660 min_align (unsigned int a, unsigned int b)
2662 return (a | b) & -(a | b);
2665 /* Return the assembler directive for creating a given kind of integer
2666 object. SIZE is the number of bytes in the object and ALIGNED_P
2667 indicates whether it is known to be aligned. Return NULL if the
2668 assembly dialect has no such directive.
2670 The returned string should be printed at the start of a new line and
2671 be followed immediately by the object's initial value. */
2674 integer_asm_op (int size, int aligned_p)
2676 struct asm_int_op *ops;
2679 ops = &targetm.asm_out.aligned_op;
2681 ops = &targetm.asm_out.unaligned_op;
2686 return targetm.asm_out.byte_op;
2700 /* Use directive OP to assemble an integer object X. Print OP at the
2701 start of the line, followed immediately by the value of X. */
2704 assemble_integer_with_op (const char *op, rtx x)
2706 fputs (op, asm_out_file);
2707 output_addr_const (asm_out_file, x);
2708 fputc ('\n', asm_out_file);
2711 /* The default implementation of the asm_out.integer target hook. */
2714 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2715 unsigned int size ATTRIBUTE_UNUSED,
2716 int aligned_p ATTRIBUTE_UNUSED)
2718 const char *op = integer_asm_op (size, aligned_p);
2719 /* Avoid GAS bugs for large values. Specifically negative values whose
2720 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2721 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2723 return op && (assemble_integer_with_op (op, x), true);
2726 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2727 the alignment of the integer in bits. Return 1 if we were able to output
2728 the constant, otherwise 0. We must be able to output the constant,
2729 if FORCE is nonzero. */
2732 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2736 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2738 /* See if the target hook can handle this kind of object. */
2739 if (targetm.asm_out.integer (x, size, aligned_p))
2742 /* If the object is a multi-byte one, try splitting it up. Split
2743 it into words it if is multi-word, otherwise split it into bytes. */
2746 enum machine_mode omode, imode;
2747 unsigned int subalign;
2748 unsigned int subsize, i;
2749 enum mode_class mclass;
2751 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2752 subalign = MIN (align, subsize * BITS_PER_UNIT);
2753 if (GET_CODE (x) == CONST_FIXED)
2754 mclass = GET_MODE_CLASS (GET_MODE (x));
2758 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2759 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2761 for (i = 0; i < size; i += subsize)
2763 rtx partial = simplify_subreg (omode, x, imode, i);
2764 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2770 /* If we've printed some of it, but not all of it, there's no going
2775 gcc_assert (!force);
2781 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2783 long data[4] = {0, 0, 0, 0};
2785 int bitsize, nelts, nunits, units_per;
2787 /* This is hairy. We have a quantity of known size. real_to_target
2788 will put it into an array of *host* longs, 32 bits per element
2789 (even if long is more than 32 bits). We need to determine the
2790 number of array elements that are occupied (nelts) and the number
2791 of *target* min-addressable units that will be occupied in the
2792 object file (nunits). We cannot assume that 32 divides the
2793 mode's bitsize (size * BITS_PER_UNIT) evenly.
2795 size * BITS_PER_UNIT is used here to make sure that padding bits
2796 (which might appear at either end of the value; real_to_target
2797 will include the padding bits in its output array) are included. */
2799 nunits = GET_MODE_SIZE (mode);
2800 bitsize = nunits * BITS_PER_UNIT;
2801 nelts = CEIL (bitsize, 32);
2802 units_per = 32 / BITS_PER_UNIT;
2804 real_to_target (data, &d, mode);
2806 /* Put out the first word with the specified alignment. */
2807 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2808 nunits -= units_per;
2810 /* Subsequent words need only 32-bit alignment. */
2811 align = min_align (align, 32);
2813 for (i = 1; i < nelts; i++)
2815 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2816 nunits -= units_per;
2820 /* Given an expression EXP with a constant value,
2821 reduce it to the sum of an assembler symbol and an integer.
2822 Store them both in the structure *VALUE.
2823 EXP must be reducible. */
2825 struct GTY(()) addr_const {
2827 HOST_WIDE_INT offset;
2831 decode_addr_const (tree exp, struct addr_const *value)
2833 tree target = TREE_OPERAND (exp, 0);
2839 if (TREE_CODE (target) == COMPONENT_REF
2840 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2842 offset += int_byte_position (TREE_OPERAND (target, 1));
2843 target = TREE_OPERAND (target, 0);
2845 else if (TREE_CODE (target) == ARRAY_REF
2846 || TREE_CODE (target) == ARRAY_RANGE_REF)
2848 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2849 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2850 target = TREE_OPERAND (target, 0);
2852 else if (TREE_CODE (target) == INDIRECT_REF
2853 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2854 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2856 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2861 switch (TREE_CODE (target))
2865 x = DECL_RTL (target);
2869 x = gen_rtx_MEM (FUNCTION_MODE,
2870 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2879 x = output_constant_def (target, 1);
2886 gcc_assert (MEM_P (x));
2890 value->offset = offset;
2894 static GTY((param_is (struct constant_descriptor_tree)))
2895 htab_t const_desc_htab;
2897 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2899 /* Constant pool accessor function. */
2902 constant_pool_htab (void)
2904 return const_desc_htab;
2907 /* Compute a hash code for a constant expression. */
2910 const_desc_hash (const void *ptr)
2912 return ((const struct constant_descriptor_tree *)ptr)->hash;
2916 const_hash_1 (const tree exp)
2921 enum tree_code code = TREE_CODE (exp);
2923 /* Either set P and LEN to the address and len of something to hash and
2924 exit the switch or return a value. */
2929 p = (char *) &TREE_INT_CST (exp);
2930 len = sizeof TREE_INT_CST (exp);
2934 return real_hash (TREE_REAL_CST_PTR (exp));
2937 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2940 p = TREE_STRING_POINTER (exp);
2941 len = TREE_STRING_LENGTH (exp);
2945 return (const_hash_1 (TREE_REALPART (exp)) * 5
2946 + const_hash_1 (TREE_IMAGPART (exp)));
2952 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2954 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2955 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2962 unsigned HOST_WIDE_INT idx;
2965 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2967 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2969 hi = hi * 603 + const_hash_1 (value);
2977 struct addr_const value;
2979 decode_addr_const (exp, &value);
2980 switch (GET_CODE (value.base))
2983 /* Don't hash the address of the SYMBOL_REF;
2984 only use the offset and the symbol name. */
2986 p = XSTR (value.base, 0);
2987 for (i = 0; p[i] != 0; i++)
2988 hi = ((hi * 613) + (unsigned) (p[i]));
2992 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
3002 case POINTER_PLUS_EXPR:
3004 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
3005 + const_hash_1 (TREE_OPERAND (exp, 1)));
3008 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
3011 /* A language specific constant. Just hash the code. */
3015 /* Compute hashing function. */
3017 for (i = 0; i < len; i++)
3018 hi = ((hi * 613) + (unsigned) (p[i]));
3023 /* Wrapper of compare_constant, for the htab interface. */
3025 const_desc_eq (const void *p1, const void *p2)
3027 const struct constant_descriptor_tree *const c1
3028 = (const struct constant_descriptor_tree *) p1;
3029 const struct constant_descriptor_tree *const c2
3030 = (const struct constant_descriptor_tree *) p2;
3031 if (c1->hash != c2->hash)
3033 return compare_constant (c1->value, c2->value);
3036 /* Compare t1 and t2, and return 1 only if they are known to result in
3037 the same bit pattern on output. */
3040 compare_constant (const tree t1, const tree t2)
3042 enum tree_code typecode;
3044 if (t1 == NULL_TREE)
3045 return t2 == NULL_TREE;
3046 if (t2 == NULL_TREE)
3049 if (TREE_CODE (t1) != TREE_CODE (t2))
3052 switch (TREE_CODE (t1))
3055 /* Integer constants are the same only if the same width of type. */
3056 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3058 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3060 return tree_int_cst_equal (t1, t2);
3063 /* Real constants are the same only if the same width of type. */
3064 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3067 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3070 /* Fixed constants are the same only if the same width of type. */
3071 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3074 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3077 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3080 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3081 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3082 TREE_STRING_LENGTH (t1)));
3085 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3086 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3092 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
3093 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
3096 link2 = TREE_VECTOR_CST_ELTS (t2);
3097 for (link1 = TREE_VECTOR_CST_ELTS (t1);
3099 link1 = TREE_CHAIN (link1))
3101 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
3103 link2 = TREE_CHAIN (link2);
3111 VEC(constructor_elt, gc) *v1, *v2;
3112 unsigned HOST_WIDE_INT idx;
3114 typecode = TREE_CODE (TREE_TYPE (t1));
3115 if (typecode != TREE_CODE (TREE_TYPE (t2)))
3118 if (typecode == ARRAY_TYPE)
3120 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3121 /* For arrays, check that the sizes all match. */
3122 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3124 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
3129 /* For record and union constructors, require exact type
3131 if (TREE_TYPE (t1) != TREE_TYPE (t2))
3135 v1 = CONSTRUCTOR_ELTS (t1);
3136 v2 = CONSTRUCTOR_ELTS (t2);
3137 if (VEC_length (constructor_elt, v1)
3138 != VEC_length (constructor_elt, v2))
3141 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
3143 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
3144 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
3146 /* Check that each value is the same... */
3147 if (!compare_constant (c1->value, c2->value))
3149 /* ... and that they apply to the same fields! */
3150 if (typecode == ARRAY_TYPE)
3152 if (!compare_constant (c1->index, c2->index))
3157 if (c1->index != c2->index)
3168 struct addr_const value1, value2;
3172 decode_addr_const (t1, &value1);
3173 decode_addr_const (t2, &value2);
3175 if (value1.offset != value2.offset)
3178 code = GET_CODE (value1.base);
3179 if (code != GET_CODE (value2.base))
3185 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3189 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
3190 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
3200 case POINTER_PLUS_EXPR:
3203 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3204 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3207 case VIEW_CONVERT_EXPR:
3208 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3217 /* Make a copy of the whole tree structure for a constant. This
3218 handles the same types of nodes that compare_constant handles. */
3221 copy_constant (tree exp)
3223 switch (TREE_CODE (exp))
3226 /* For ADDR_EXPR, we do not want to copy the decl whose address
3227 is requested. We do want to copy constants though. */
3228 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3229 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3230 copy_constant (TREE_OPERAND (exp, 0)));
3232 return copy_node (exp);
3238 return copy_node (exp);
3241 return build_complex (TREE_TYPE (exp),
3242 copy_constant (TREE_REALPART (exp)),
3243 copy_constant (TREE_IMAGPART (exp)));
3246 case POINTER_PLUS_EXPR:
3248 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3249 copy_constant (TREE_OPERAND (exp, 0)),
3250 copy_constant (TREE_OPERAND (exp, 1)));
3253 case VIEW_CONVERT_EXPR:
3254 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3255 copy_constant (TREE_OPERAND (exp, 0)));
3258 return build_vector (TREE_TYPE (exp),
3259 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3263 tree copy = copy_node (exp);
3264 VEC(constructor_elt, gc) *v;
3265 unsigned HOST_WIDE_INT idx;
3266 tree purpose, value;
3268 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3269 CONSTRUCTOR_ELTS (exp)));
3270 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3272 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3273 ce->index = purpose;
3274 ce->value = copy_constant (value);
3276 CONSTRUCTOR_ELTS (copy) = v;
3285 /* Return the section into which constant EXP should be placed. */
3288 get_constant_section (tree exp, unsigned int align)
3290 return targetm.asm_out.select_section (exp,
3291 compute_reloc_for_constant (exp),
3295 /* Return the size of constant EXP in bytes. */
3297 static HOST_WIDE_INT
3298 get_constant_size (tree exp)
3302 size = int_size_in_bytes (TREE_TYPE (exp));
3303 if (TREE_CODE (exp) == STRING_CST)
3304 size = MAX (TREE_STRING_LENGTH (exp), size);
3308 /* Subroutine of output_constant_def:
3309 No constant equal to EXP is known to have been output.
3310 Make a constant descriptor to enter EXP in the hash table.
3311 Assign the label number and construct RTL to refer to the
3312 constant's location in memory.
3313 Caller is responsible for updating the hash table. */
3315 static struct constant_descriptor_tree *
3316 build_constant_desc (tree exp)
3318 struct constant_descriptor_tree *desc;
3324 desc = ggc_alloc_constant_descriptor_tree ();
3325 desc->value = copy_constant (exp);
3327 /* Propagate marked-ness to copied constant. */
3328 if (flag_mudflap && mf_marked_p (exp))
3329 mf_mark (desc->value);
3331 /* Create a string containing the label name, in LABEL. */
3332 labelno = const_labelno++;
3333 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3335 /* Construct the VAR_DECL associated with the constant. */
3336 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3338 DECL_ARTIFICIAL (decl) = 1;
3339 DECL_IGNORED_P (decl) = 1;
3340 TREE_READONLY (decl) = 1;
3341 TREE_STATIC (decl) = 1;
3342 TREE_ADDRESSABLE (decl) = 1;
3343 /* We don't set the RTL yet as this would cause varpool to assume that the
3344 variable is referenced. Moreover, it would just be dropped in LTO mode.
3345 Instead we set the flag that will be recognized in make_decl_rtl. */
3346 DECL_IN_CONSTANT_POOL (decl) = 1;
3347 DECL_INITIAL (decl) = desc->value;
3348 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3349 architectures so use DATA_ALIGNMENT as well, except for strings. */
3350 if (TREE_CODE (exp) == STRING_CST)
3352 #ifdef CONSTANT_ALIGNMENT
3353 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3357 align_variable (decl, 0);
3359 /* Now construct the SYMBOL_REF and the MEM. */
3360 if (use_object_blocks_p ())
3362 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3363 symbol = create_block_symbol (ggc_strdup (label),
3364 get_block_for_section (sect), -1);
3367 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3368 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3369 SET_SYMBOL_REF_DECL (symbol, decl);
3370 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3372 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3373 set_mem_attributes (rtl, exp, 1);
3374 set_mem_alias_set (rtl, 0);
3375 set_mem_alias_set (rtl, const_alias_set);
3377 /* We cannot share RTX'es in pool entries.
3378 Mark this piece of RTL as required for unsharing. */
3379 RTX_FLAG (rtl, used) = 1;
3381 /* Set flags or add text to the name to record information, such as
3382 that it is a local symbol. If the name is changed, the macro
3383 ASM_OUTPUT_LABELREF will have to know how to strip this
3384 information. This call might invalidate our local variable
3385 SYMBOL; we can't use it afterward. */
3386 targetm.encode_section_info (exp, rtl, true);
3393 /* Return an rtx representing a reference to constant data in memory
3394 for the constant expression EXP.
3396 If assembler code for such a constant has already been output,
3397 return an rtx to refer to it.
3398 Otherwise, output such a constant in memory
3399 and generate an rtx for it.
3401 If DEFER is nonzero, this constant can be deferred and output only
3402 if referenced in the function after all optimizations.
3404 `const_desc_table' records which constants already have label strings. */
3407 output_constant_def (tree exp, int defer)
3409 struct constant_descriptor_tree *desc;
3410 struct constant_descriptor_tree key;
3413 /* Look up EXP in the table of constant descriptors. If we didn't find
3414 it, create a new one. */
3416 key.hash = const_hash_1 (exp);
3417 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3419 desc = (struct constant_descriptor_tree *) *loc;
3422 desc = build_constant_desc (exp);
3423 desc->hash = key.hash;
3427 maybe_output_constant_def_contents (desc, defer);
3431 /* Subroutine of output_constant_def: Decide whether or not we need to
3432 output the constant DESC now, and if so, do it. */
3434 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3437 rtx symbol = XEXP (desc->rtl, 0);
3438 tree exp = desc->value;
3440 if (flag_syntax_only)
3443 if (TREE_ASM_WRITTEN (exp))
3444 /* Already output; don't do it again. */
3447 /* We can always defer constants as long as the context allows
3451 /* Increment n_deferred_constants if it exists. It needs to be at
3452 least as large as the number of constants actually referred to
3453 by the function. If it's too small we'll stop looking too early
3454 and fail to emit constants; if it's too large we'll only look
3455 through the entire function when we could have stopped earlier. */
3457 n_deferred_constants++;
3461 output_constant_def_contents (symbol);
3464 /* Subroutine of output_constant_def_contents. Output the definition
3465 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3466 constant's alignment in bits. */
3469 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3473 size = get_constant_size (exp);
3475 /* Do any machine/system dependent processing of the constant. */
3476 targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3478 /* Output the value of EXP. */
3479 output_constant (exp, size, align);
3482 /* We must output the constant data referred to by SYMBOL; do so. */
3485 output_constant_def_contents (rtx symbol)
3487 tree decl = SYMBOL_REF_DECL (symbol);
3488 tree exp = DECL_INITIAL (decl);
3491 /* Make sure any other constants whose addresses appear in EXP
3492 are assigned label numbers. */
3493 output_addressed_constants (exp);
3495 /* We are no longer deferring this constant. */
3496 TREE_ASM_WRITTEN (exp) = 1;
3498 /* If the constant is part of an object block, make sure that the
3499 decl has been positioned within its block, but do not write out
3500 its definition yet. output_object_blocks will do that later. */
3501 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3502 place_block_symbol (symbol);
3505 align = DECL_ALIGN (decl);
3506 switch_to_section (get_constant_section (exp, align));
3507 if (align > BITS_PER_UNIT)
3508 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3509 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3512 mudflap_enqueue_constant (exp);
3515 /* Look up EXP in the table of constant descriptors. Return the rtl
3516 if it has been emitted, else null. */
3519 lookup_constant_def (tree exp)
3521 struct constant_descriptor_tree *desc;
3522 struct constant_descriptor_tree key;
3525 key.hash = const_hash_1 (exp);
3526 desc = (struct constant_descriptor_tree *)
3527 htab_find_with_hash (const_desc_htab, &key, key.hash);
3529 return (desc ? desc->rtl : NULL_RTX);
3532 /* Return a tree representing a reference to constant data in memory
3533 for the constant expression EXP.
3535 This is the counterpart of output_constant_def at the Tree level. */
3538 tree_output_constant_def (tree exp)
3540 struct constant_descriptor_tree *desc, key;
3544 /* Look up EXP in the table of constant descriptors. If we didn't find
3545 it, create a new one. */
3547 key.hash = const_hash_1 (exp);
3548 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3550 desc = (struct constant_descriptor_tree *) *loc;
3553 desc = build_constant_desc (exp);
3554 desc->hash = key.hash;
3558 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3559 varpool_finalize_decl (decl);
3563 /* Used in the hash tables to avoid outputting the same constant
3564 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3565 are output once per function, not once per file. */
3566 /* ??? Only a few targets need per-function constant pools. Most
3567 can use one per-file pool. Should add a targetm bit to tell the
3570 struct GTY(()) rtx_constant_pool {
3571 /* Pointers to first and last constant in pool, as ordered by offset. */
3572 struct constant_descriptor_rtx *first;
3573 struct constant_descriptor_rtx *last;
3575 /* Hash facility for making memory-constants from constant rtl-expressions.
3576 It is used on RISC machines where immediate integer arguments and
3577 constant addresses are restricted so that such constants must be stored
3579 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3581 /* Current offset in constant pool (does not include any
3582 machine-specific header). */
3583 HOST_WIDE_INT offset;
3586 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3587 struct constant_descriptor_rtx *next;
3591 HOST_WIDE_INT offset;
3593 enum machine_mode mode;
3599 /* Hash and compare functions for const_rtx_htab. */
3602 const_desc_rtx_hash (const void *ptr)
3604 const struct constant_descriptor_rtx *const desc
3605 = (const struct constant_descriptor_rtx *) ptr;
3610 const_desc_rtx_eq (const void *a, const void *b)
3612 const struct constant_descriptor_rtx *const x
3613 = (const struct constant_descriptor_rtx *) a;
3614 const struct constant_descriptor_rtx *const y
3615 = (const struct constant_descriptor_rtx *) b;
3617 if (x->mode != y->mode)
3619 return rtx_equal_p (x->constant, y->constant);
3622 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3625 const_rtx_hash_1 (rtx *xp, void *data)
3627 unsigned HOST_WIDE_INT hwi;
3628 enum machine_mode mode;
3634 code = GET_CODE (x);
3635 mode = GET_MODE (x);
3636 h = (hashval_t) code * 1048573 + mode;
3644 int shift = sizeof (hashval_t) * CHAR_BIT;
3645 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3648 h ^= (hashval_t) hwi;
3649 for (i = 1; i < n; ++i)
3652 h ^= (hashval_t) hwi;
3658 if (mode == VOIDmode)
3660 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3664 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3668 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3674 for (i = XVECLEN (x, 0); i-- > 0; )
3675 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3680 h ^= htab_hash_string (XSTR (x, 0));
3684 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3688 case UNSPEC_VOLATILE:
3689 h = h * 251 + XINT (x, 1);
3696 hp = (hashval_t *) data;
3697 *hp = *hp * 509 + h;
3701 /* Compute a hash value for X, which should be a constant. */
3704 const_rtx_hash (rtx x)
3707 for_each_rtx (&x, const_rtx_hash_1, &h);
3712 /* Create and return a new rtx constant pool. */
3714 static struct rtx_constant_pool *
3715 create_constant_pool (void)
3717 struct rtx_constant_pool *pool;
3719 pool = ggc_alloc_rtx_constant_pool ();
3720 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3721 const_desc_rtx_eq, NULL);
3728 /* Initialize constant pool hashing for a new function. */
3731 init_varasm_status (void)
3733 crtl->varasm.pool = create_constant_pool ();
3734 crtl->varasm.deferred_constants = 0;
3737 /* Given a MINUS expression, simplify it if both sides
3738 include the same symbol. */
3741 simplify_subtraction (rtx x)
3743 rtx r = simplify_rtx (x);
3747 /* Given a constant rtx X, make (or find) a memory constant for its value
3748 and return a MEM rtx to refer to it in memory. */
3751 force_const_mem (enum machine_mode mode, rtx x)
3753 struct constant_descriptor_rtx *desc, tmp;
3754 struct rtx_constant_pool *pool;
3761 /* If we're not allowed to drop X into the constant pool, don't. */
3762 if (targetm.cannot_force_const_mem (x))
3765 /* Record that this function has used a constant pool entry. */
3766 crtl->uses_const_pool = 1;
3768 /* Decide which pool to use. */
3769 pool = (targetm.use_blocks_for_constant_p (mode, x)
3770 ? shared_constant_pool
3771 : crtl->varasm.pool);
3773 /* Lookup the value in the hashtable. */
3776 hash = const_rtx_hash (x);
3777 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3778 desc = (struct constant_descriptor_rtx *) *slot;
3780 /* If the constant was already present, return its memory. */
3782 return copy_rtx (desc->mem);
3784 /* Otherwise, create a new descriptor. */
3785 desc = ggc_alloc_constant_descriptor_rtx ();
3788 /* Align the location counter as required by EXP's data type. */
3789 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3790 #ifdef CONSTANT_ALIGNMENT
3792 tree type = lang_hooks.types.type_for_mode (mode, 0);
3793 if (type != NULL_TREE)
3794 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3798 pool->offset += (align / BITS_PER_UNIT) - 1;
3799 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3802 desc->constant = tmp.constant;
3803 desc->offset = pool->offset;
3806 desc->align = align;
3807 desc->labelno = const_labelno;
3810 pool->offset += GET_MODE_SIZE (mode);
3812 pool->last->next = desc;
3814 pool->first = pool->last = desc;
3817 /* Create a string containing the label name, in LABEL. */
3818 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3821 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3822 the constants pool. */
3823 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3825 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3826 symbol = create_block_symbol (ggc_strdup (label),
3827 get_block_for_section (sect), -1);
3830 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3832 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3833 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3834 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3836 /* Construct the MEM. */
3837 desc->mem = def = gen_const_mem (mode, symbol);
3838 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3839 set_mem_align (def, align);
3841 /* If we're dropping a label to the constant pool, make sure we
3843 if (GET_CODE (x) == LABEL_REF)
3844 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3846 return copy_rtx (def);
3849 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3852 get_pool_constant (rtx addr)
3854 return SYMBOL_REF_CONSTANT (addr)->constant;
3857 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3858 and whether it has been output or not. */
3861 get_pool_constant_mark (rtx addr, bool *pmarked)
3863 struct constant_descriptor_rtx *desc;
3865 desc = SYMBOL_REF_CONSTANT (addr);
3866 *pmarked = (desc->mark != 0);
3867 return desc->constant;
3870 /* Similar, return the mode. */
3873 get_pool_mode (const_rtx addr)
3875 return SYMBOL_REF_CONSTANT (addr)->mode;
3878 /* Return the size of the constant pool. */
3881 get_pool_size (void)
3883 return crtl->varasm.pool->offset;
3886 /* Worker function for output_constant_pool_1. Emit assembly for X
3887 in MODE with known alignment ALIGN. */
3890 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3892 switch (GET_MODE_CLASS (mode))
3895 case MODE_DECIMAL_FLOAT:
3899 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3900 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3901 assemble_real (r, mode, align);
3906 case MODE_PARTIAL_INT:
3911 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3914 case MODE_VECTOR_FLOAT:
3915 case MODE_VECTOR_INT:
3916 case MODE_VECTOR_FRACT:
3917 case MODE_VECTOR_UFRACT:
3918 case MODE_VECTOR_ACCUM:
3919 case MODE_VECTOR_UACCUM:
3922 enum machine_mode submode = GET_MODE_INNER (mode);
3923 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3925 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3926 units = CONST_VECTOR_NUNITS (x);
3928 for (i = 0; i < units; i++)
3930 rtx elt = CONST_VECTOR_ELT (x, i);
3931 output_constant_pool_2 (submode, elt, i ? subalign : align);
3941 /* Worker function for output_constant_pool. Emit constant DESC,
3942 giving it ALIGN bits of alignment. */
3945 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3952 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3953 whose CODE_LABEL has been deleted. This can occur if a jump table
3954 is eliminated by optimization. If so, write a constant of zero
3955 instead. Note that this can also happen by turning the
3956 CODE_LABEL into a NOTE. */
3957 /* ??? This seems completely and utterly wrong. Certainly it's
3958 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3959 functioning even with INSN_DELETED_P and friends. */
3962 switch (GET_CODE (tmp))
3965 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3966 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3968 tmp = XEXP (XEXP (tmp, 0), 0);
3972 tmp = XEXP (tmp, 0);
3973 gcc_assert (!INSN_DELETED_P (tmp));
3974 gcc_assert (!NOTE_P (tmp)
3975 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3982 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3983 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3984 align, desc->labelno, done);
3987 assemble_align (align);
3989 /* Output the label. */
3990 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3992 /* Output the data. */
3993 output_constant_pool_2 (desc->mode, x, align);
3995 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3996 sections have proper size. */
3997 if (align > GET_MODE_BITSIZE (desc->mode)
3999 && (in_section->common.flags & SECTION_MERGE))
4000 assemble_align (align);
4002 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4008 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4009 to as used. Emit referenced deferred strings. This function can
4010 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4013 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
4015 rtx x = *current_rtx;
4017 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
4020 if (CONSTANT_POOL_ADDRESS_P (x))
4022 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
4023 if (desc->mark == 0)
4026 for_each_rtx (&desc->constant, mark_constant, NULL);
4029 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
4031 tree decl = SYMBOL_REF_DECL (x);
4032 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
4034 n_deferred_constants--;
4035 output_constant_def_contents (x);
4042 /* Look through appropriate parts of INSN, marking all entries in the
4043 constant pool which are actually being used. Entries that are only
4044 referenced by other constants are also marked as used. Emit
4045 deferred strings that are used. */
4048 mark_constants (rtx insn)
4053 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4054 insns, not any notes that may be attached. We don't want to mark
4055 a constant just because it happens to appear in a REG_EQUIV note. */
4056 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
4058 rtx seq = PATTERN (insn);
4059 int i, n = XVECLEN (seq, 0);
4060 for (i = 0; i < n; ++i)
4062 rtx subinsn = XVECEXP (seq, 0, i);
4063 if (INSN_P (subinsn))
4064 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
4068 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
4071 /* Look through the instructions for this function, and mark all the
4072 entries in POOL which are actually being used. Emit deferred constants
4073 which have indeed been used. */
4076 mark_constant_pool (void)
4080 if (!crtl->uses_const_pool && n_deferred_constants == 0)
4083 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4084 mark_constants (insn);
4086 for (link = crtl->epilogue_delay_list;
4088 link = XEXP (link, 1))
4089 mark_constants (XEXP (link, 0));
4092 /* Write all the constants in POOL. */
4095 output_constant_pool_contents (struct rtx_constant_pool *pool)
4097 struct constant_descriptor_rtx *desc;
4099 for (desc = pool->first; desc ; desc = desc->next)
4102 /* If the constant is part of an object_block, make sure that
4103 the constant has been positioned within its block, but do not
4104 write out its definition yet. output_object_blocks will do
4106 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4107 && SYMBOL_REF_BLOCK (desc->sym))
4108 place_block_symbol (desc->sym);
4111 switch_to_section (targetm.asm_out.select_rtx_section
4112 (desc->mode, desc->constant, desc->align));
4113 output_constant_pool_1 (desc, desc->align);
4118 /* Mark all constants that are used in the current function, then write
4119 out the function's private constant pool. */
4122 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
4123 tree fndecl ATTRIBUTE_UNUSED)
4125 struct rtx_constant_pool *pool = crtl->varasm.pool;
4127 /* It is possible for gcc to call force_const_mem and then to later
4128 discard the instructions which refer to the constant. In such a
4129 case we do not need to output the constant. */
4130 mark_constant_pool ();
4132 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4133 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
4136 output_constant_pool_contents (pool);
4138 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4139 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
4143 /* Write the contents of the shared constant pool. */
4146 output_shared_constant_pool (void)
4148 output_constant_pool_contents (shared_constant_pool);
4151 /* Determine what kind of relocations EXP may need. */
4154 compute_reloc_for_constant (tree exp)
4156 int reloc = 0, reloc2;
4159 switch (TREE_CODE (exp))
4163 /* Go inside any operations that get_inner_reference can handle and see
4164 if what's inside is a constant: no need to do anything here for
4165 addresses of variables or functions. */
4166 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4167 tem = TREE_OPERAND (tem, 0))
4170 if (TREE_PUBLIC (tem))
4177 case POINTER_PLUS_EXPR:
4178 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4179 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4183 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4184 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4185 /* The difference of two local labels is computable at link time. */
4186 if (reloc == 1 && reloc2 == 1)
4193 case VIEW_CONVERT_EXPR:
4194 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4199 unsigned HOST_WIDE_INT idx;
4200 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4202 reloc |= compute_reloc_for_constant (tem);
4212 /* Find all the constants whose addresses are referenced inside of EXP,
4213 and make sure assembler code with a label has been output for each one.
4214 Indicate whether an ADDR_EXPR has been encountered. */
4217 output_addressed_constants (tree exp)
4221 switch (TREE_CODE (exp))
4225 /* Go inside any operations that get_inner_reference can handle and see
4226 if what's inside is a constant: no need to do anything here for
4227 addresses of variables or functions. */
4228 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4229 tem = TREE_OPERAND (tem, 0))
4232 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4233 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4234 tem = DECL_INITIAL (tem);
4236 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4237 output_constant_def (tem, 0);
4241 case POINTER_PLUS_EXPR:
4243 output_addressed_constants (TREE_OPERAND (exp, 1));
4247 case VIEW_CONVERT_EXPR:
4248 output_addressed_constants (TREE_OPERAND (exp, 0));
4253 unsigned HOST_WIDE_INT idx;
4254 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4256 output_addressed_constants (tem);
4265 /* Whether a constructor CTOR is a valid static constant initializer if all
4266 its elements are. This used to be internal to initializer_constant_valid_p
4267 and has been exposed to let other functions like categorize_ctor_elements
4268 evaluate the property while walking a constructor for other purposes. */
4271 constructor_static_from_elts_p (const_tree ctor)
4273 return (TREE_CONSTANT (ctor)
4274 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4275 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4276 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4279 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4282 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4283 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4284 which are valid when ENDTYPE is an integer of any size; in
4285 particular, this does not accept a pointer minus a constant. This
4286 returns null_pointer_node if the VALUE is an absolute constant
4287 which can be used to initialize a static variable. Otherwise it
4291 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4295 if (!INTEGRAL_TYPE_P (endtype))
4298 op0 = TREE_OPERAND (value, 0);
4299 op1 = TREE_OPERAND (value, 1);
4301 /* Like STRIP_NOPS except allow the operand mode to widen. This
4302 works around a feature of fold that simplifies (int)(p1 - p2) to
4303 ((int)p1 - (int)p2) under the theory that the narrower operation
4306 while (CONVERT_EXPR_P (op0)
4307 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4309 tree inner = TREE_OPERAND (op0, 0);
4310 if (inner == error_mark_node
4311 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4312 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4313 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4318 while (CONVERT_EXPR_P (op1)
4319 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4321 tree inner = TREE_OPERAND (op1, 0);
4322 if (inner == error_mark_node
4323 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4324 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4325 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4330 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4334 op1 = initializer_constant_valid_p_1 (op1, endtype,
4335 cache ? cache + 2 : NULL);
4336 /* Both initializers must be known. */
4340 && (op0 == null_pointer_node
4341 || TREE_CODE (value) == MINUS_EXPR))
4342 return null_pointer_node;
4344 /* Support differences between labels. */
4345 if (TREE_CODE (op0) == LABEL_DECL
4346 && TREE_CODE (op1) == LABEL_DECL)
4347 return null_pointer_node;
4349 if (TREE_CODE (op0) == STRING_CST
4350 && TREE_CODE (op1) == STRING_CST
4351 && operand_equal_p (op0, op1, 1))
4352 return null_pointer_node;
4358 /* Helper function of initializer_constant_valid_p.
4359 Return nonzero if VALUE is a valid constant-valued expression
4360 for use in initializing a static variable; one that can be an
4361 element of a "constant" initializer.
4363 Return null_pointer_node if the value is absolute;
4364 if it is relocatable, return the variable that determines the relocation.
4365 We assume that VALUE has been folded as much as possible;
4366 therefore, we do not need to check for such things as
4367 arithmetic-combinations of integers.
4369 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4372 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4376 switch (TREE_CODE (value))
4379 if (constructor_static_from_elts_p (value))
4381 unsigned HOST_WIDE_INT idx;
4383 bool absolute = true;
4385 if (cache && cache[0] == value)
4387 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4390 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4397 cache[1] = NULL_TREE;
4401 if (reloc != null_pointer_node)
4404 /* For a non-absolute relocation, there is no single
4405 variable that can be "the variable that determines the
4410 cache[1] = absolute ? null_pointer_node : error_mark_node;
4412 return absolute ? null_pointer_node : error_mark_node;
4415 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4423 return null_pointer_node;
4428 tree op0 = staticp (TREE_OPERAND (value, 0));
4431 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4432 to be a constant, this is old-skool offsetof-like nonsense. */
4433 if (TREE_CODE (op0) == INDIRECT_REF
4434 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4435 return null_pointer_node;
4436 /* Taking the address of a nested function involves a trampoline,
4437 unless we don't need or want one. */
4438 if (TREE_CODE (op0) == FUNCTION_DECL
4439 && DECL_STATIC_CHAIN (op0)
4440 && !TREE_NO_TRAMPOLINE (value))
4442 /* "&{...}" requires a temporary to hold the constructed
4444 if (TREE_CODE (op0) == CONSTRUCTOR)
4450 case NON_LVALUE_EXPR:
4451 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4454 case VIEW_CONVERT_EXPR:
4456 tree src = TREE_OPERAND (value, 0);
4457 tree src_type = TREE_TYPE (src);
4458 tree dest_type = TREE_TYPE (value);
4460 /* Allow view-conversions from aggregate to non-aggregate type only
4461 if the bit pattern is fully preserved afterwards; otherwise, the
4462 RTL expander won't be able to apply a subsequent transformation
4463 to the underlying constructor. */
4464 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4466 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4467 return initializer_constant_valid_p_1 (src, endtype, cache);
4472 /* Allow all other kinds of view-conversion. */
4473 return initializer_constant_valid_p_1 (src, endtype, cache);
4478 tree src = TREE_OPERAND (value, 0);
4479 tree src_type = TREE_TYPE (src);
4480 tree dest_type = TREE_TYPE (value);
4482 /* Allow conversions between pointer types, floating-point
4483 types, and offset types. */
4484 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4485 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4486 || (TREE_CODE (dest_type) == OFFSET_TYPE
4487 && TREE_CODE (src_type) == OFFSET_TYPE))
4488 return initializer_constant_valid_p_1 (src, endtype, cache);
4490 /* Allow length-preserving conversions between integer types. */
4491 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4492 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4493 return initializer_constant_valid_p_1 (src, endtype, cache);
4495 /* Allow conversions between other integer types only if
4497 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4499 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4500 if (inner == null_pointer_node)
4501 return null_pointer_node;
4505 /* Allow (int) &foo provided int is as wide as a pointer. */
4506 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4507 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4508 return initializer_constant_valid_p_1 (src, endtype, cache);
4510 /* Likewise conversions from int to pointers, but also allow
4511 conversions from 0. */
4512 if ((POINTER_TYPE_P (dest_type)
4513 || TREE_CODE (dest_type) == OFFSET_TYPE)
4514 && INTEGRAL_TYPE_P (src_type))
4516 if (TREE_CODE (src) == INTEGER_CST
4517 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4518 return null_pointer_node;
4519 if (integer_zerop (src))
4520 return null_pointer_node;
4521 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4522 return initializer_constant_valid_p_1 (src, endtype, cache);
4525 /* Allow conversions to struct or union types if the value
4527 if (TREE_CODE (dest_type) == RECORD_TYPE
4528 || TREE_CODE (dest_type) == UNION_TYPE)
4529 return initializer_constant_valid_p_1 (src, endtype, cache);
4533 case POINTER_PLUS_EXPR:
4535 /* Any valid floating-point constants will have been folded by now;
4536 with -frounding-math we hit this with addition of two constants. */
4537 if (TREE_CODE (endtype) == REAL_TYPE)
4539 if (cache && cache[0] == value)
4541 if (! INTEGRAL_TYPE_P (endtype)
4542 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4544 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4546 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4549 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4550 endtype, ncache + 2);
4551 /* If either term is absolute, use the other term's relocation. */
4552 if (valid0 == null_pointer_node)
4554 else if (valid1 == null_pointer_node)
4556 /* Support narrowing pointer differences. */
4558 ret = narrowing_initializer_constant_valid_p (value, endtype,
4562 /* Support narrowing pointer differences. */
4563 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4572 if (TREE_CODE (endtype) == REAL_TYPE)
4574 if (cache && cache[0] == value)
4576 if (! INTEGRAL_TYPE_P (endtype)
4577 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4579 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4581 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4584 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4585 endtype, ncache + 2);
4586 /* Win if second argument is absolute. */
4587 if (valid1 == null_pointer_node)
4589 /* Win if both arguments have the same relocation.
4590 Then the value is absolute. */
4591 else if (valid0 == valid1 && valid0 != 0)
4592 ret = null_pointer_node;
4593 /* Since GCC guarantees that string constants are unique in the
4594 generated code, a subtraction between two copies of the same
4595 constant string is absolute. */
4596 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4597 && valid1 && TREE_CODE (valid1) == STRING_CST
4598 && operand_equal_p (valid0, valid1, 1))
4599 ret = null_pointer_node;
4600 /* Support narrowing differences. */
4602 ret = narrowing_initializer_constant_valid_p (value, endtype,
4606 /* Support narrowing differences. */
4607 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4622 /* Return nonzero if VALUE is a valid constant-valued expression
4623 for use in initializing a static variable; one that can be an
4624 element of a "constant" initializer.
4626 Return null_pointer_node if the value is absolute;
4627 if it is relocatable, return the variable that determines the relocation.
4628 We assume that VALUE has been folded as much as possible;
4629 therefore, we do not need to check for such things as
4630 arithmetic-combinations of integers. */
4632 initializer_constant_valid_p (tree value, tree endtype)
4634 return initializer_constant_valid_p_1 (value, endtype, NULL);
4637 /* Return true if VALUE is a valid constant-valued expression
4638 for use in initializing a static bit-field; one that can be
4639 an element of a "constant" initializer. */
4642 initializer_constant_valid_for_bitfield_p (tree value)
4644 /* For bitfields we support integer constants or possibly nested aggregates
4646 switch (TREE_CODE (value))
4650 unsigned HOST_WIDE_INT idx;
4653 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4654 if (!initializer_constant_valid_for_bitfield_p (elt))
4662 case VIEW_CONVERT_EXPR:
4663 case NON_LVALUE_EXPR:
4665 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4674 /* output_constructor outer state of relevance in recursive calls, typically
4675 for nested aggregate bitfields. */
4678 unsigned int bit_offset; /* current position in ... */
4679 int byte; /* ... the outer byte buffer. */
4682 static unsigned HOST_WIDE_INT
4683 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4686 /* Output assembler code for constant EXP to FILE, with no label.
4687 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4688 Assumes output_addressed_constants has been done on EXP already.
4690 Generate exactly SIZE bytes of assembler data, padding at the end
4691 with zeros if necessary. SIZE must always be specified.
4693 SIZE is important for structure constructors,
4694 since trailing members may have been omitted from the constructor.
4695 It is also important for initialization of arrays from string constants
4696 since the full length of the string constant might not be wanted.
4697 It is also needed for initialization of unions, where the initializer's
4698 type is just one member, and that may not be as long as the union.
4700 There a case in which we would fail to output exactly SIZE bytes:
4701 for a structure constructor that wants to produce more than SIZE bytes.
4702 But such constructors will never be generated for any possible input.
4704 ALIGN is the alignment of the data in bits. */
4707 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4709 enum tree_code code;
4710 unsigned HOST_WIDE_INT thissize;
4712 if (size == 0 || flag_syntax_only)
4715 /* See if we're trying to initialize a pointer in a non-default mode
4716 to the address of some declaration somewhere. If the target says
4717 the mode is valid for pointers, assume the target has a way of
4719 if (TREE_CODE (exp) == NOP_EXPR
4720 && POINTER_TYPE_P (TREE_TYPE (exp))
4721 && targetm.addr_space.valid_pointer_mode
4722 (TYPE_MODE (TREE_TYPE (exp)),
4723 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4725 tree saved_type = TREE_TYPE (exp);
4727 /* Peel off any intermediate conversions-to-pointer for valid
4729 while (TREE_CODE (exp) == NOP_EXPR
4730 && POINTER_TYPE_P (TREE_TYPE (exp))
4731 && targetm.addr_space.valid_pointer_mode
4732 (TYPE_MODE (TREE_TYPE (exp)),
4733 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4734 exp = TREE_OPERAND (exp, 0);
4736 /* If what we're left with is the address of something, we can
4737 convert the address to the final type and output it that
4739 if (TREE_CODE (exp) == ADDR_EXPR)
4740 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4741 /* Likewise for constant ints. */
4742 else if (TREE_CODE (exp) == INTEGER_CST)
4743 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4744 TREE_INT_CST_HIGH (exp));
4748 /* Eliminate any conversions since we'll be outputting the underlying
4750 while (CONVERT_EXPR_P (exp)
4751 || TREE_CODE (exp) == NON_LVALUE_EXPR
4752 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4754 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4755 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4757 /* Make sure eliminating the conversion is really a no-op, except with
4758 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4759 union types to allow for Ada unchecked unions. */
4760 if (type_size > op_size
4761 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4762 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4763 /* Keep the conversion. */
4766 exp = TREE_OPERAND (exp, 0);
4769 code = TREE_CODE (TREE_TYPE (exp));
4770 thissize = int_size_in_bytes (TREE_TYPE (exp));
4772 /* Allow a constructor with no elements for any data type.
4773 This means to fill the space with zeros. */
4774 if (TREE_CODE (exp) == CONSTRUCTOR
4775 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4777 assemble_zeros (size);
4781 if (TREE_CODE (exp) == FDESC_EXPR)
4783 #ifdef ASM_OUTPUT_FDESC
4784 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4785 tree decl = TREE_OPERAND (exp, 0);
4786 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4793 /* Now output the underlying data. If we've handling the padding, return.
4794 Otherwise, break and ensure SIZE is the size written. */
4801 case REFERENCE_TYPE:
4803 case FIXED_POINT_TYPE:
4804 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4805 EXPAND_INITIALIZER),
4806 MIN (size, thissize), align, 0))
4807 error ("initializer for integer/fixed-point value is too complicated");
4811 if (TREE_CODE (exp) != REAL_CST)
4812 error ("initializer for floating value is not a floating constant");
4814 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4818 output_constant (TREE_REALPART (exp), thissize / 2, align);
4819 output_constant (TREE_IMAGPART (exp), thissize / 2,
4820 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4825 switch (TREE_CODE (exp))
4828 output_constructor (exp, size, align, NULL);
4831 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4833 assemble_string (TREE_STRING_POINTER (exp), thissize);
4840 unsigned int nalign;
4841 enum machine_mode inner;
4843 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4844 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4846 elt_size = GET_MODE_SIZE (inner);
4848 link = TREE_VECTOR_CST_ELTS (exp);
4849 output_constant (TREE_VALUE (link), elt_size, align);
4850 thissize = elt_size;
4851 while ((link = TREE_CHAIN (link)) != NULL)
4853 output_constant (TREE_VALUE (link), elt_size, nalign);
4854 thissize += elt_size;
4865 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4866 output_constructor (exp, size, align, NULL);
4876 if (size > thissize)
4877 assemble_zeros (size - thissize);
4881 /* Subroutine of output_constructor, used for computing the size of
4882 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4883 type with an unspecified upper bound. */
4885 static unsigned HOST_WIDE_INT
4886 array_size_for_constructor (tree val)
4889 unsigned HOST_WIDE_INT cnt;
4890 tree index, value, tmp;
4892 /* This code used to attempt to handle string constants that are not
4893 arrays of single-bytes, but nothing else does, so there's no point in
4895 if (TREE_CODE (val) == STRING_CST)
4896 return TREE_STRING_LENGTH (val);
4898 max_index = NULL_TREE;
4899 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4901 if (TREE_CODE (index) == RANGE_EXPR)
4902 index = TREE_OPERAND (index, 1);
4903 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4907 if (max_index == NULL_TREE)
4910 /* Compute the total number of array elements. */
4911 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4912 i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4913 fold_convert (sizetype, tmp));
4914 i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4916 /* Multiply by the array element unit size to find number of bytes. */
4917 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4919 return tree_low_cst (i, 1);
4922 /* Other datastructures + helpers for output_constructor. */
4924 /* output_constructor local state to support interaction with helpers. */
4928 /* Received arguments. */
4929 tree exp; /* Constructor expression. */
4930 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4931 unsigned int align; /* Known initial alignment. */
4933 /* Constructor expression data. */
4934 tree type; /* Expression type. */
4935 tree field; /* Current field decl in a record. */
4936 tree min_index; /* Lower bound if specified for an array. */
4938 /* Output processing state. */
4939 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4940 bool byte_buffer_in_use; /* Whether byte ... */
4941 int byte; /* ... contains part of a bitfield byte yet to
4944 int last_relative_index; /* Implicit or explicit index of the last
4945 array element output within a bitfield. */
4946 /* Current element. */
4947 tree val; /* Current element value. */
4948 tree index; /* Current element index. */
4952 /* Helper for output_constructor. From the current LOCAL state, output a
4953 RANGE_EXPR element. */
4956 output_constructor_array_range (oc_local_state *local)
4958 unsigned HOST_WIDE_INT fieldsize
4959 = int_size_in_bytes (TREE_TYPE (local->type));
4961 HOST_WIDE_INT lo_index
4962 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4963 HOST_WIDE_INT hi_index
4964 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4965 HOST_WIDE_INT index;
4968 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4970 for (index = lo_index; index <= hi_index; index++)
4972 /* Output the element's initial value. */
4973 if (local->val == NULL_TREE)
4974 assemble_zeros (fieldsize);
4976 output_constant (local->val, fieldsize, align2);
4978 /* Count its size. */
4979 local->total_bytes += fieldsize;
4983 /* Helper for output_constructor. From the current LOCAL state, output a
4984 field element that is not true bitfield or part of an outer one. */
4987 output_constructor_regular_field (oc_local_state *local)
4989 /* Field size and position. Since this structure is static, we know the
4990 positions are constant. */
4991 unsigned HOST_WIDE_INT fieldsize;
4992 HOST_WIDE_INT fieldpos;
4994 unsigned int align2;
4996 if (local->index != NULL_TREE)
4997 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
4998 * ((tree_low_cst (local->index, 0)
4999 - tree_low_cst (local->min_index, 0))));
5000 else if (local->field != NULL_TREE)
5001 fieldpos = int_byte_position (local->field);
5005 /* Output any buffered-up bit-fields preceding this element. */
5006 if (local->byte_buffer_in_use)
5008 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5009 local->total_bytes++;
5010 local->byte_buffer_in_use = false;
5013 /* Advance to offset of this element.
5014 Note no alignment needed in an array, since that is guaranteed
5015 if each element has the proper size. */
5016 if ((local->field != NULL_TREE || local->index != NULL_TREE)
5017 && fieldpos != local->total_bytes)
5019 gcc_assert (fieldpos >= local->total_bytes);
5020 assemble_zeros (fieldpos - local->total_bytes);
5021 local->total_bytes = fieldpos;
5024 /* Find the alignment of this element. */
5025 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
5027 /* Determine size this element should occupy. */
5032 /* If this is an array with an unspecified upper bound,
5033 the initializer determines the size. */
5034 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5035 but we cannot do this until the deprecated support for
5036 initializing zero-length array members is removed. */
5037 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
5038 && TYPE_DOMAIN (TREE_TYPE (local->field))
5039 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
5041 fieldsize = array_size_for_constructor (local->val);
5042 /* Given a non-empty initialization, this field had
5044 gcc_assert (!fieldsize || !TREE_CHAIN (local->field));
5046 else if (DECL_SIZE_UNIT (local->field))
5048 /* ??? This can't be right. If the decl size overflows
5049 a host integer we will silently emit no data. */
5050 if (host_integerp (DECL_SIZE_UNIT (local->field), 1))
5051 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
5055 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
5057 /* Output the element's initial value. */
5058 if (local->val == NULL_TREE)
5059 assemble_zeros (fieldsize);
5061 output_constant (local->val, fieldsize, align2);
5063 /* Count its size. */
5064 local->total_bytes += fieldsize;
5067 /* Helper for output_constructor. From the current LOCAL and OUTER states,
5068 output an element that is a true bitfield or part of an outer one. */
5071 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
5073 /* Bit size of this element. */
5074 HOST_WIDE_INT ebitsize
5076 ? tree_low_cst (DECL_SIZE (local->field), 1)
5077 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
5079 /* Relative index of this element if this is an array component. */
5080 HOST_WIDE_INT relative_index
5083 ? (tree_low_cst (local->index, 0)
5084 - tree_low_cst (local->min_index, 0))
5085 : local->last_relative_index + 1)
5088 /* Bit position of this element from the start of the containing
5090 HOST_WIDE_INT constructor_relative_ebitpos
5092 ? int_bit_position (local->field)
5093 : ebitsize * relative_index);
5095 /* Bit position of this element from the start of a possibly ongoing
5096 outer byte buffer. */
5097 HOST_WIDE_INT byte_relative_ebitpos
5098 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
5100 /* From the start of a possibly ongoing outer byte buffer, offsets to
5101 the first bit of this element and to the first bit past the end of
5103 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
5104 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
5106 local->last_relative_index = relative_index;
5108 if (local->val == NULL_TREE)
5109 local->val = integer_zero_node;
5111 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
5112 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
5113 local->val = TREE_OPERAND (local->val, 0);
5115 if (TREE_CODE (local->val) != INTEGER_CST
5116 && TREE_CODE (local->val) != CONSTRUCTOR)
5118 error ("invalid initial value for member %qE", DECL_NAME (local->field));
5122 /* If this field does not start in this (or, next) byte,
5124 if (next_offset / BITS_PER_UNIT != local->total_bytes)
5126 /* Output remnant of any bit field in previous bytes. */
5127 if (local->byte_buffer_in_use)
5129 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5130 local->total_bytes++;
5131 local->byte_buffer_in_use = false;
5134 /* If still not at proper byte, advance to there. */
5135 if (next_offset / BITS_PER_UNIT != local->total_bytes)
5137 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
5138 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
5139 local->total_bytes = next_offset / BITS_PER_UNIT;
5143 /* Set up the buffer if necessary. */
5144 if (!local->byte_buffer_in_use)
5148 local->byte_buffer_in_use = true;
5151 /* If this is nested constructor, recurse passing the bit offset and the
5152 pending data, then retrieve the new pending data afterwards. */
5153 if (TREE_CODE (local->val) == CONSTRUCTOR)
5155 oc_outer_state output_state;
5157 output_state.bit_offset = next_offset % BITS_PER_UNIT;
5158 output_state.byte = local->byte;
5160 += output_constructor (local->val, 0, 0, &output_state);
5161 local->byte = output_state.byte;
5165 /* Otherwise, we must split the element into pieces that fall within
5166 separate bytes, and combine each byte with previous or following
5168 while (next_offset < end_offset)
5172 HOST_WIDE_INT value;
5173 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
5174 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
5176 /* Advance from byte to byte
5177 within this element when necessary. */
5178 while (next_byte != local->total_bytes)
5180 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5181 local->total_bytes++;
5185 /* Number of bits we can process at once
5186 (all part of the same byte). */
5187 this_time = MIN (end_offset - next_offset,
5188 BITS_PER_UNIT - next_bit);
5189 if (BYTES_BIG_ENDIAN)
5191 /* On big-endian machine, take the most significant bits
5192 first (of the bits that are significant)
5193 and put them into bytes from the most significant end. */
5194 shift = end_offset - next_offset - this_time;
5196 /* Don't try to take a bunch of bits that cross
5197 the word boundary in the INTEGER_CST. We can
5198 only select bits from the LOW or HIGH part
5200 if (shift < HOST_BITS_PER_WIDE_INT
5201 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5203 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
5204 shift = HOST_BITS_PER_WIDE_INT;
5207 /* Now get the bits from the appropriate constant word. */
5208 if (shift < HOST_BITS_PER_WIDE_INT)
5209 value = TREE_INT_CST_LOW (local->val);
5212 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5213 value = TREE_INT_CST_HIGH (local->val);
5214 shift -= HOST_BITS_PER_WIDE_INT;
5217 /* Get the result. This works only when:
5218 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5219 local->byte |= (((value >> shift)
5220 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5221 << (BITS_PER_UNIT - this_time - next_bit));
5225 /* On little-endian machines,
5226 take first the least significant bits of the value
5227 and pack them starting at the least significant
5228 bits of the bytes. */
5229 shift = next_offset - byte_relative_ebitpos;
5231 /* Don't try to take a bunch of bits that cross
5232 the word boundary in the INTEGER_CST. We can
5233 only select bits from the LOW or HIGH part
5235 if (shift < HOST_BITS_PER_WIDE_INT
5236 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5237 this_time = (HOST_BITS_PER_WIDE_INT - shift);
5239 /* Now get the bits from the appropriate constant word. */
5240 if (shift < HOST_BITS_PER_WIDE_INT)
5241 value = TREE_INT_CST_LOW (local->val);
5244 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5245 value = TREE_INT_CST_HIGH (local->val);
5246 shift -= HOST_BITS_PER_WIDE_INT;
5249 /* Get the result. This works only when:
5250 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5251 local->byte |= (((value >> shift)
5252 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5256 next_offset += this_time;
5257 local->byte_buffer_in_use = true;
5261 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5262 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5263 caller output state of relevance in recursive invocations. */
5265 static unsigned HOST_WIDE_INT
5266 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
5267 unsigned int align, oc_outer_state * outer)
5269 unsigned HOST_WIDE_INT cnt;
5270 constructor_elt *ce;
5272 oc_local_state local;
5274 /* Setup our local state to communicate with helpers. */
5277 local.align = align;
5279 local.total_bytes = 0;
5280 local.byte_buffer_in_use = outer != NULL;
5281 local.byte = outer ? outer->byte : 0;
5283 local.type = TREE_TYPE (exp);
5285 local.last_relative_index = -1;
5287 local.min_index = NULL_TREE;
5288 if (TREE_CODE (local.type) == ARRAY_TYPE
5289 && TYPE_DOMAIN (local.type) != NULL_TREE)
5290 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5292 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
5294 /* As CE goes through the elements of the constant, FIELD goes through the
5295 structure fields if the constant is a structure. If the constant is a
5296 union, we override this by getting the field from the TREE_LIST element.
5297 But the constant could also be an array. Then FIELD is zero.
5299 There is always a maximum of one element in the chain LINK for unions
5300 (even if the initializer in a source program incorrectly contains
5303 local.field = NULL_TREE;
5304 if (TREE_CODE (local.type) == RECORD_TYPE)
5305 local.field = TYPE_FIELDS (local.type);
5308 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
5309 cnt++, local.field = local.field ? TREE_CHAIN (local.field) : 0)
5311 local.val = ce->value;
5312 local.index = NULL_TREE;
5314 /* The element in a union constructor specifies the proper field
5316 if ((TREE_CODE (local.type) == RECORD_TYPE
5317 || TREE_CODE (local.type) == UNION_TYPE
5318 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
5319 && ce->index != NULL_TREE)
5320 local.field = ce->index;
5322 else if (TREE_CODE (local.type) == ARRAY_TYPE)
5323 local.index = ce->index;
5325 #ifdef ASM_COMMENT_START
5326 if (local.field && flag_verbose_asm)
5327 fprintf (asm_out_file, "%s %s:\n",
5329 DECL_NAME (local.field)
5330 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
5334 /* Eliminate the marker that makes a cast not be an lvalue. */
5335 if (local.val != NULL_TREE)
5336 STRIP_NOPS (local.val);
5338 /* Output the current element, using the appropriate helper ... */
5340 /* For an array slice not part of an outer bitfield. */
5342 && local.index != NULL_TREE
5343 && TREE_CODE (local.index) == RANGE_EXPR)
5344 output_constructor_array_range (&local);
5346 /* For a field that is neither a true bitfield nor part of an outer one,
5347 known to be at least byte aligned and multiple-of-bytes long. */
5349 && (local.field == NULL_TREE
5350 || !CONSTRUCTOR_BITFIELD_P (local.field)))
5351 output_constructor_regular_field (&local);
5353 /* For a true bitfield or part of an outer one. */
5355 output_constructor_bitfield (&local, outer);
5358 /* If we are not at toplevel, save the pending data for our caller.
5359 Otherwise output the pending data and padding zeros as needed. */
5361 outer->byte = local.byte;
5364 if (local.byte_buffer_in_use)
5366 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
5367 local.total_bytes++;
5370 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
5372 assemble_zeros (local.size - local.total_bytes);
5373 local.total_bytes = local.size;
5377 return local.total_bytes;
5380 /* Mark DECL as weak. */
5383 mark_weak (tree decl)
5385 DECL_WEAK (decl) = 1;
5387 if (DECL_RTL_SET_P (decl)
5388 && MEM_P (DECL_RTL (decl))
5389 && XEXP (DECL_RTL (decl), 0)
5390 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5391 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5394 /* Merge weak status between NEWDECL and OLDDECL. */
5397 merge_weak (tree newdecl, tree olddecl)
5399 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5401 if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
5404 /* We put the NEWDECL on the weak_decls list at some point
5405 and OLDDECL as well. Keep just OLDDECL on the list. */
5406 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5407 if (TREE_VALUE (*pwd) == newdecl)
5409 *pwd = TREE_CHAIN (*pwd);
5416 if (DECL_WEAK (newdecl))
5420 /* NEWDECL is weak, but OLDDECL is not. */
5422 /* If we already output the OLDDECL, we're in trouble; we can't
5423 go back and make it weak. This error cannot be caught in
5424 declare_weak because the NEWDECL and OLDDECL was not yet
5425 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5426 if (TREE_ASM_WRITTEN (olddecl))
5427 error ("weak declaration of %q+D must precede definition",
5430 /* If we've already generated rtl referencing OLDDECL, we may
5431 have done so in a way that will not function properly with
5433 else if (TREE_USED (olddecl)
5434 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
5435 warning (0, "weak declaration of %q+D after first use results "
5436 "in unspecified behavior", newdecl);
5440 /* We put the NEWDECL on the weak_decls list at some point.
5441 Replace it with the OLDDECL. */
5442 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5443 if (TREE_VALUE (wd) == newdecl)
5445 TREE_VALUE (wd) = olddecl;
5448 /* We may not find the entry on the list. If NEWDECL is a
5449 weak alias, then we will have already called
5450 globalize_decl to remove the entry; in that case, we do
5451 not need to do anything. */
5454 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5455 mark_weak (olddecl);
5458 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5459 weak. Just update NEWDECL to indicate that it's weak too. */
5460 mark_weak (newdecl);
5463 /* Declare DECL to be a weak symbol. */
5466 declare_weak (tree decl)
5468 if (! TREE_PUBLIC (decl))
5469 error ("weak declaration of %q+D must be public", decl);
5470 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
5471 error ("weak declaration of %q+D must precede definition", decl);
5472 else if (!SUPPORTS_WEAK)
5473 warning (0, "weak declaration of %q+D not supported", decl);
5476 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5477 DECL_ATTRIBUTES (decl)
5478 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5482 weak_finish_1 (tree decl)
5484 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5485 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5488 if (! TREE_USED (decl))
5491 #ifdef ASM_WEAKEN_DECL
5492 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5494 #ifdef ASM_WEAKEN_LABEL
5495 ASM_WEAKEN_LABEL (asm_out_file, name);
5497 #ifdef ASM_OUTPUT_WEAK_ALIAS
5499 static bool warn_once = 0;
5502 warning (0, "only weak aliases are supported in this configuration");
5512 /* This TREE_LIST contains weakref targets. */
5514 static GTY(()) tree weakref_targets;
5516 /* Forward declaration. */
5517 static tree find_decl_and_mark_needed (tree decl, tree target);
5519 /* Emit any pending weak declarations. */
5526 for (t = weakref_targets; t; t = TREE_CHAIN (t))
5528 tree alias_decl = TREE_PURPOSE (t);
5529 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5531 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5532 /* Remove alias_decl from the weak list, but leave entries for
5533 the target alone. */
5535 #ifndef ASM_OUTPUT_WEAKREF
5536 else if (! TREE_SYMBOL_REFERENCED (target))
5538 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5539 defined, otherwise we and weak_finish_1 would use
5540 different macros. */
5541 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5542 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5544 tree decl = find_decl_and_mark_needed (alias_decl, target);
5548 decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5549 TREE_CODE (alias_decl), target,
5550 TREE_TYPE (alias_decl));
5552 DECL_EXTERNAL (decl) = 1;
5553 TREE_PUBLIC (decl) = 1;
5554 DECL_ARTIFICIAL (decl) = 1;
5555 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5556 TREE_USED (decl) = 1;
5559 weak_finish_1 (decl);
5568 /* Remove the alias and the target from the pending weak list
5569 so that we do not emit any .weak directives for the former,
5570 nor multiple .weak directives for the latter. */
5571 for (p = &weak_decls; (t2 = *p) ; )
5573 if (TREE_VALUE (t2) == alias_decl
5574 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5575 *p = TREE_CHAIN (t2);
5577 p = &TREE_CHAIN (t2);
5580 /* Remove other weakrefs to the same target, to speed things up. */
5581 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5583 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5584 *p = TREE_CHAIN (t2);
5586 p = &TREE_CHAIN (t2);
5591 for (t = weak_decls; t; t = TREE_CHAIN (t))
5593 tree decl = TREE_VALUE (t);
5595 weak_finish_1 (decl);
5599 /* Emit the assembly bits to indicate that DECL is globally visible. */
5602 globalize_decl (tree decl)
5605 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5606 if (DECL_WEAK (decl))
5608 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5611 #ifdef ASM_WEAKEN_DECL
5612 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5614 ASM_WEAKEN_LABEL (asm_out_file, name);
5617 /* Remove this function from the pending weak list so that
5618 we do not emit multiple .weak directives for it. */
5619 for (p = &weak_decls; (t = *p) ; )
5621 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5622 *p = TREE_CHAIN (t);
5624 p = &TREE_CHAIN (t);
5627 /* Remove weakrefs to the same target from the pending weakref
5628 list, for the same reason. */
5629 for (p = &weakref_targets; (t = *p) ; )
5631 if (DECL_ASSEMBLER_NAME (decl)
5632 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5633 *p = TREE_CHAIN (t);
5635 p = &TREE_CHAIN (t);
5642 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5645 VEC(alias_pair,gc) *alias_pairs;
5647 /* Given an assembly name, find the decl it is associated with. At the
5648 same time, mark it needed for cgraph. */
5651 find_decl_and_mark_needed (tree decl, tree target)
5653 struct cgraph_node *fnode = NULL;
5654 struct varpool_node *vnode = NULL;
5656 if (TREE_CODE (decl) == FUNCTION_DECL)
5658 fnode = cgraph_node_for_asm (target);
5660 vnode = varpool_node_for_asm (target);
5664 vnode = varpool_node_for_asm (target);
5666 fnode = cgraph_node_for_asm (target);
5671 cgraph_mark_needed_node (fnode);
5676 varpool_mark_needed_node (vnode);
5677 vnode->force_output = 1;
5684 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5685 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5686 tree node is DECL to have the value of the tree node TARGET. */
5689 do_assemble_alias (tree decl, tree target)
5691 if (TREE_ASM_WRITTEN (decl))
5694 /* We must force creation of DECL_RTL for debug info generation, even though
5695 we don't use it here. */
5696 make_decl_rtl (decl);
5698 TREE_ASM_WRITTEN (decl) = 1;
5699 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5701 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5703 ultimate_transparent_alias_target (&target);
5705 if (!targetm.have_tls
5706 && TREE_CODE (decl) == VAR_DECL
5707 && DECL_THREAD_LOCAL_P (decl))
5709 decl = emutls_decl (decl);
5710 target = get_emutls_object_name (target);
5713 if (!TREE_SYMBOL_REFERENCED (target))
5714 weakref_targets = tree_cons (decl, target, weakref_targets);
5716 #ifdef ASM_OUTPUT_WEAKREF
5717 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5718 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5719 IDENTIFIER_POINTER (target));
5723 error_at (DECL_SOURCE_LOCATION (decl),
5724 "weakref is not supported in this configuration");
5731 if (!targetm.have_tls
5732 && TREE_CODE (decl) == VAR_DECL
5733 && DECL_THREAD_LOCAL_P (decl))
5735 decl = emutls_decl (decl);
5736 target = get_emutls_object_name (target);
5739 #ifdef ASM_OUTPUT_DEF
5740 /* Make name accessible from other files, if appropriate. */
5742 if (TREE_PUBLIC (decl))
5744 globalize_decl (decl);
5745 maybe_assemble_visibility (decl);
5748 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5749 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5751 ASM_OUTPUT_DEF (asm_out_file,
5752 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5753 IDENTIFIER_POINTER (target));
5755 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5760 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5761 # ifdef ASM_WEAKEN_DECL
5762 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5764 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5766 /* Remove this function from the pending weak list so that
5767 we do not emit multiple .weak directives for it. */
5768 for (p = &weak_decls; (t = *p) ; )
5769 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5770 *p = TREE_CHAIN (t);
5772 p = &TREE_CHAIN (t);
5774 /* Remove weakrefs to the same target from the pending weakref
5775 list, for the same reason. */
5776 for (p = &weakref_targets; (t = *p) ; )
5778 if (DECL_ASSEMBLER_NAME (decl)
5779 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5780 *p = TREE_CHAIN (t);
5782 p = &TREE_CHAIN (t);
5789 /* Remove the alias pairing for functions that are no longer in the call
5793 remove_unreachable_alias_pairs (void)
5798 if (alias_pairs == NULL)
5801 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5803 if (!DECL_EXTERNAL (p->decl))
5805 struct cgraph_node *fnode = NULL;
5806 struct varpool_node *vnode = NULL;
5807 fnode = cgraph_node_for_asm (p->target);
5808 vnode = (fnode == NULL) ? varpool_node_for_asm (p->target) : NULL;
5809 if (fnode == NULL && vnode == NULL)
5811 VEC_unordered_remove (alias_pair, alias_pairs, i);
5821 /* First pass of completing pending aliases. Make sure that cgraph knows
5822 which symbols will be required. */
5825 finish_aliases_1 (void)
5830 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5834 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5835 if (target_decl == NULL)
5837 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5838 error ("%q+D aliased to undefined symbol %qE",
5839 p->decl, p->target);
5841 else if (DECL_EXTERNAL (target_decl)
5842 /* We use local aliases for C++ thunks to force the tailcall
5843 to bind locally. Of course this is a hack - to keep it
5844 working do the following (which is not strictly correct). */
5845 && (! TREE_CODE (target_decl) == FUNCTION_DECL
5846 || ! DECL_VIRTUAL_P (target_decl))
5847 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5848 error ("%q+D aliased to external symbol %qE",
5849 p->decl, p->target);
5853 /* Second pass of completing pending aliases. Emit the actual assembly.
5854 This happens at the end of compilation and thus it is assured that the
5855 target symbol has been emitted. */
5858 finish_aliases_2 (void)
5863 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5864 do_assemble_alias (p->decl, p->target);
5866 VEC_truncate (alias_pair, alias_pairs, 0);
5869 /* Emit an assembler directive to make the symbol for DECL an alias to
5870 the symbol for TARGET. */
5873 assemble_alias (tree decl, tree target)
5876 bool is_weakref = false;
5878 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5880 tree alias = DECL_ASSEMBLER_NAME (decl);
5884 ultimate_transparent_alias_target (&target);
5886 if (alias == target)
5887 error ("weakref %q+D ultimately targets itself", decl);
5890 #ifndef ASM_OUTPUT_WEAKREF
5891 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5892 TREE_CHAIN (alias) = target;
5895 if (TREE_PUBLIC (decl))
5896 error ("weakref %q+D must have static linkage", decl);
5900 #if !defined (ASM_OUTPUT_DEF)
5901 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5902 error_at (DECL_SOURCE_LOCATION (decl),
5903 "alias definitions not supported in this configuration");
5906 if (!DECL_WEAK (decl))
5908 error_at (DECL_SOURCE_LOCATION (decl),
5909 "only weak aliases are supported in this configuration");
5915 TREE_USED (decl) = 1;
5917 /* A quirk of the initial implementation of aliases required that the user
5918 add "extern" to all of them. Which is silly, but now historical. Do
5919 note that the symbol is in fact locally defined. */
5921 DECL_EXTERNAL (decl) = 0;
5923 /* Allow aliases to aliases. */
5924 if (TREE_CODE (decl) == FUNCTION_DECL)
5925 cgraph_node (decl)->alias = true;
5927 varpool_node (decl)->alias = true;
5929 /* If the target has already been emitted, we don't have to queue the
5930 alias. This saves a tad of memory. */
5931 if (cgraph_global_info_ready)
5932 target_decl = find_decl_and_mark_needed (decl, target);
5935 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5936 do_assemble_alias (decl, target);
5939 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5945 /* Emit an assembler directive to set symbol for DECL visibility to
5946 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5949 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
5950 int vis ATTRIBUTE_UNUSED)
5952 #ifdef HAVE_GAS_HIDDEN
5953 static const char * const visibility_types[] = {
5954 NULL, "protected", "hidden", "internal"
5957 const char *name, *type;
5959 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5960 type = visibility_types[vis];
5962 fprintf (asm_out_file, "\t.%s\t", type);
5963 assemble_name (asm_out_file, name);
5964 fprintf (asm_out_file, "\n");
5966 warning (OPT_Wattributes, "visibility attribute not supported "
5967 "in this configuration; ignored");
5971 /* A helper function to call assemble_visibility when needed for a decl. */
5974 maybe_assemble_visibility (tree decl)
5976 enum symbol_visibility vis = DECL_VISIBILITY (decl);
5978 if (vis != VISIBILITY_DEFAULT)
5980 targetm.asm_out.assemble_visibility (decl, vis);
5987 /* Returns 1 if the target configuration supports defining public symbols
5988 so that one of them will be chosen at link time instead of generating a
5989 multiply-defined symbol error, whether through the use of weak symbols or
5990 a target-specific mechanism for having duplicates discarded. */
5993 supports_one_only (void)
5995 if (SUPPORTS_ONE_ONLY)
5997 return SUPPORTS_WEAK;
6000 /* Set up DECL as a public symbol that can be defined in multiple
6001 translation units without generating a linker error. */
6004 make_decl_one_only (tree decl, tree comdat_group)
6006 gcc_assert (TREE_CODE (decl) == VAR_DECL
6007 || TREE_CODE (decl) == FUNCTION_DECL);
6009 TREE_PUBLIC (decl) = 1;
6011 if (SUPPORTS_ONE_ONLY)
6013 #ifdef MAKE_DECL_ONE_ONLY
6014 MAKE_DECL_ONE_ONLY (decl);
6016 DECL_COMDAT_GROUP (decl) = comdat_group;
6018 else if (TREE_CODE (decl) == VAR_DECL
6019 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
6020 DECL_COMMON (decl) = 1;
6023 gcc_assert (SUPPORTS_WEAK);
6024 DECL_WEAK (decl) = 1;
6029 init_varasm_once (void)
6031 section_htab = htab_create_ggc (31, section_entry_hash,
6032 section_entry_eq, NULL);
6033 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
6034 object_block_entry_eq, NULL);
6035 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
6036 const_desc_eq, NULL);
6038 const_alias_set = new_alias_set ();
6039 shared_constant_pool = create_constant_pool ();
6041 #ifdef TEXT_SECTION_ASM_OP
6042 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
6043 TEXT_SECTION_ASM_OP);
6046 #ifdef DATA_SECTION_ASM_OP
6047 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6048 DATA_SECTION_ASM_OP);
6051 #ifdef SDATA_SECTION_ASM_OP
6052 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6053 SDATA_SECTION_ASM_OP);
6056 #ifdef READONLY_DATA_SECTION_ASM_OP
6057 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
6058 READONLY_DATA_SECTION_ASM_OP);
6061 #ifdef CTORS_SECTION_ASM_OP
6062 ctors_section = get_unnamed_section (0, output_section_asm_op,
6063 CTORS_SECTION_ASM_OP);
6066 #ifdef DTORS_SECTION_ASM_OP
6067 dtors_section = get_unnamed_section (0, output_section_asm_op,
6068 DTORS_SECTION_ASM_OP);
6071 #ifdef BSS_SECTION_ASM_OP
6072 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6073 output_section_asm_op,
6074 BSS_SECTION_ASM_OP);
6077 #ifdef SBSS_SECTION_ASM_OP
6078 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6079 output_section_asm_op,
6080 SBSS_SECTION_ASM_OP);
6083 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6084 | SECTION_COMMON, emit_tls_common);
6085 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6086 | SECTION_COMMON, emit_local);
6087 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6088 | SECTION_COMMON, emit_common);
6090 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
6091 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
6095 targetm.asm_out.init_sections ();
6097 if (readonly_data_section == NULL)
6098 readonly_data_section = text_section;
6102 decl_default_tls_model (const_tree decl)
6104 enum tls_model kind;
6107 is_local = targetm.binds_local_p (decl);
6111 kind = TLS_MODEL_LOCAL_EXEC;
6113 kind = TLS_MODEL_INITIAL_EXEC;
6116 /* Local dynamic is inefficient when we're not combining the
6117 parts of the address. */
6118 else if (optimize && is_local)
6119 kind = TLS_MODEL_LOCAL_DYNAMIC;
6121 kind = TLS_MODEL_GLOBAL_DYNAMIC;
6122 if (kind < flag_tls_default)
6123 kind = flag_tls_default;
6128 /* Select a set of attributes for section NAME based on the properties
6129 of DECL and whether or not RELOC indicates that DECL's initializer
6130 might contain runtime relocations.
6132 We make the section read-only and executable for a function decl,
6133 read-only for a const data decl, and writable for a non-const data decl. */
6136 default_section_type_flags (tree decl, const char *name, int reloc)
6140 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
6141 flags = SECTION_CODE;
6142 else if (decl && decl_readonly_section (decl, reloc))
6144 else if (current_function_decl
6146 && crtl->subsections.unlikely_text_section_name
6147 && strcmp (name, crtl->subsections.unlikely_text_section_name) == 0)
6148 flags = SECTION_CODE;
6150 && (!current_function_decl || !cfun)
6151 && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6152 flags = SECTION_CODE;
6154 flags = SECTION_WRITE;
6156 if (decl && DECL_ONE_ONLY (decl))
6157 flags |= SECTION_LINKONCE;
6159 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6160 flags |= SECTION_TLS | SECTION_WRITE;
6162 if (strcmp (name, ".bss") == 0
6163 || strncmp (name, ".bss.", 5) == 0
6164 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
6165 || strcmp (name, ".sbss") == 0
6166 || strncmp (name, ".sbss.", 6) == 0
6167 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
6168 flags |= SECTION_BSS;
6170 if (strcmp (name, ".tdata") == 0
6171 || strncmp (name, ".tdata.", 7) == 0
6172 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
6173 flags |= SECTION_TLS;
6175 if (strcmp (name, ".tbss") == 0
6176 || strncmp (name, ".tbss.", 6) == 0
6177 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
6178 flags |= SECTION_TLS | SECTION_BSS;
6180 /* These three sections have special ELF types. They are neither
6181 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6182 want to print a section type (@progbits or @nobits). If someone
6183 is silly enough to emit code or TLS variables to one of these
6184 sections, then don't handle them specially. */
6185 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
6186 && (strcmp (name, ".init_array") == 0
6187 || strcmp (name, ".fini_array") == 0
6188 || strcmp (name, ".preinit_array") == 0))
6189 flags |= SECTION_NOTYPE;
6194 /* Return true if the target supports some form of global BSS,
6195 either through bss_noswitch_section, or by selecting a BSS
6196 section in TARGET_ASM_SELECT_SECTION. */
6199 have_global_bss_p (void)
6201 return bss_noswitch_section || targetm.have_switchable_bss_sections;
6204 /* Output assembly to switch to section NAME with attribute FLAGS.
6205 Four variants for common object file formats. */
6208 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
6209 unsigned int flags ATTRIBUTE_UNUSED,
6210 tree decl ATTRIBUTE_UNUSED)
6212 /* Some object formats don't support named sections at all. The
6213 front-end should already have flagged this as an error. */
6217 #ifndef TLS_SECTION_ASM_FLAG
6218 #define TLS_SECTION_ASM_FLAG 'T'
6222 default_elf_asm_named_section (const char *name, unsigned int flags,
6223 tree decl ATTRIBUTE_UNUSED)
6225 char flagchars[10], *f = flagchars;
6227 /* If we have already declared this section, we can use an
6228 abbreviated form to switch back to it -- unless this section is
6229 part of a COMDAT groups, in which case GAS requires the full
6230 declaration every time. */
6231 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6232 && (flags & SECTION_DECLARED))
6234 fprintf (asm_out_file, "\t.section\t%s\n", name);
6238 if (!(flags & SECTION_DEBUG))
6240 if (flags & SECTION_WRITE)
6242 if (flags & SECTION_CODE)
6244 if (flags & SECTION_SMALL)
6246 if (flags & SECTION_MERGE)
6248 if (flags & SECTION_STRINGS)
6250 if (flags & SECTION_TLS)
6251 *f++ = TLS_SECTION_ASM_FLAG;
6252 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6256 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
6258 if (!(flags & SECTION_NOTYPE))
6263 if (flags & SECTION_BSS)
6269 #ifdef ASM_COMMENT_START
6270 /* On platforms that use "@" as the assembly comment character,
6272 if (strcmp (ASM_COMMENT_START, "@") == 0)
6275 fprintf (asm_out_file, format, type);
6277 if (flags & SECTION_ENTSIZE)
6278 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
6279 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6281 if (TREE_CODE (decl) == IDENTIFIER_NODE)
6282 fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
6284 fprintf (asm_out_file, ",%s,comdat",
6285 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
6289 putc ('\n', asm_out_file);
6293 default_coff_asm_named_section (const char *name, unsigned int flags,
6294 tree decl ATTRIBUTE_UNUSED)
6296 char flagchars[8], *f = flagchars;
6298 if (flags & SECTION_WRITE)
6300 if (flags & SECTION_CODE)
6304 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
6308 default_pe_asm_named_section (const char *name, unsigned int flags,
6311 default_coff_asm_named_section (name, flags, decl);
6313 if (flags & SECTION_LINKONCE)
6315 /* Functions may have been compiled at various levels of
6316 optimization so we can't use `same_size' here.
6317 Instead, have the linker pick one. */
6318 fprintf (asm_out_file, "\t.linkonce %s\n",
6319 (flags & SECTION_CODE ? "discard" : "same_size"));
6323 /* The lame default section selector. */
6326 default_select_section (tree decl, int reloc,
6327 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6331 if (decl_readonly_section (decl, reloc))
6332 return readonly_data_section;
6334 else if (TREE_CODE (decl) == CONSTRUCTOR)
6336 if (! ((flag_pic && reloc)
6337 || !TREE_READONLY (decl)
6338 || TREE_SIDE_EFFECTS (decl)
6339 || !TREE_CONSTANT (decl)))
6340 return readonly_data_section;
6342 else if (TREE_CODE (decl) == STRING_CST)
6343 return readonly_data_section;
6344 else if (! (flag_pic && reloc))
6345 return readonly_data_section;
6347 return data_section;
6350 enum section_category
6351 categorize_decl_for_section (const_tree decl, int reloc)
6353 enum section_category ret;
6355 if (TREE_CODE (decl) == FUNCTION_DECL)
6357 else if (TREE_CODE (decl) == STRING_CST)
6359 if (flag_mudflap) /* or !flag_merge_constants */
6360 return SECCAT_RODATA;
6362 return SECCAT_RODATA_MERGE_STR;
6364 else if (TREE_CODE (decl) == VAR_DECL)
6366 if (bss_initializer_p (decl))
6368 else if (! TREE_READONLY (decl)
6369 || TREE_SIDE_EFFECTS (decl)
6370 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6372 /* Here the reloc_rw_mask is not testing whether the section should
6373 be read-only or not, but whether the dynamic link will have to
6374 do something. If so, we wish to segregate the data in order to
6375 minimize cache misses inside the dynamic linker. */
6376 if (reloc & targetm.asm_out.reloc_rw_mask ())
6377 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6381 else if (reloc & targetm.asm_out.reloc_rw_mask ())
6382 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6383 else if (reloc || flag_merge_constants < 2)
6384 /* C and C++ don't allow different variables to share the same
6385 location. -fmerge-all-constants allows even that (at the
6386 expense of not conforming). */
6387 ret = SECCAT_RODATA;
6388 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6389 ret = SECCAT_RODATA_MERGE_STR_INIT;
6391 ret = SECCAT_RODATA_MERGE_CONST;
6393 else if (TREE_CODE (decl) == CONSTRUCTOR)
6395 if ((reloc & targetm.asm_out.reloc_rw_mask ())
6396 || TREE_SIDE_EFFECTS (decl)
6397 || ! TREE_CONSTANT (decl))
6400 ret = SECCAT_RODATA;
6403 ret = SECCAT_RODATA;
6405 /* There are no read-only thread-local sections. */
6406 if (TREE_CODE (decl) == VAR_DECL && DECL_TLS_MODEL (decl))
6408 if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED)
6410 if (DECL_EMUTLS_VAR_P (decl))
6412 if (targetm.emutls.var_section)
6413 ret = SECCAT_EMUTLS_VAR;
6417 if (targetm.emutls.tmpl_prefix)
6418 ret = SECCAT_EMUTLS_TMPL;
6421 /* Note that this would be *just* SECCAT_BSS, except that there's
6422 no concept of a read-only thread-local-data section. */
6423 else if (ret == SECCAT_BSS
6424 || (flag_zero_initialized_in_bss
6425 && initializer_zerop (DECL_INITIAL (decl))))
6431 /* If the target uses small data sections, select it. */
6432 else if (targetm.in_small_data_p (decl))
6434 if (ret == SECCAT_BSS)
6436 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6437 ret = SECCAT_SRODATA;
6446 decl_readonly_section (const_tree decl, int reloc)
6448 switch (categorize_decl_for_section (decl, reloc))
6451 case SECCAT_RODATA_MERGE_STR:
6452 case SECCAT_RODATA_MERGE_STR_INIT:
6453 case SECCAT_RODATA_MERGE_CONST:
6454 case SECCAT_SRODATA:
6463 /* Select a section based on the above categorization. */
6466 default_elf_select_section (tree decl, int reloc,
6467 unsigned HOST_WIDE_INT align)
6470 switch (categorize_decl_for_section (decl, reloc))
6473 /* We're not supposed to be called on FUNCTION_DECLs. */
6476 return readonly_data_section;
6477 case SECCAT_RODATA_MERGE_STR:
6478 return mergeable_string_section (decl, align, 0);
6479 case SECCAT_RODATA_MERGE_STR_INIT:
6480 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6481 case SECCAT_RODATA_MERGE_CONST:
6482 return mergeable_constant_section (DECL_MODE (decl), align, 0);
6483 case SECCAT_SRODATA:
6487 return data_section;
6488 case SECCAT_DATA_REL:
6489 sname = ".data.rel";
6491 case SECCAT_DATA_REL_LOCAL:
6492 sname = ".data.rel.local";
6494 case SECCAT_DATA_REL_RO:
6495 sname = ".data.rel.ro";
6497 case SECCAT_DATA_REL_RO_LOCAL:
6498 sname = ".data.rel.ro.local";
6517 case SECCAT_EMUTLS_VAR:
6518 sname = targetm.emutls.var_section;
6520 case SECCAT_EMUTLS_TMPL:
6521 sname = targetm.emutls.tmpl_section;
6529 return get_named_section (decl, sname, reloc);
6532 /* Construct a unique section name based on the decl name and the
6533 categorization performed above. */
6536 default_unique_section (tree decl, int reloc)
6538 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6539 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6540 const char *prefix, *name, *linkonce;
6543 switch (categorize_decl_for_section (decl, reloc))
6546 prefix = one_only ? ".t" : ".text";
6549 case SECCAT_RODATA_MERGE_STR:
6550 case SECCAT_RODATA_MERGE_STR_INIT:
6551 case SECCAT_RODATA_MERGE_CONST:
6552 prefix = one_only ? ".r" : ".rodata";
6554 case SECCAT_SRODATA:
6555 prefix = one_only ? ".s2" : ".sdata2";
6558 prefix = one_only ? ".d" : ".data";
6560 case SECCAT_DATA_REL:
6561 prefix = one_only ? ".d.rel" : ".data.rel";
6563 case SECCAT_DATA_REL_LOCAL:
6564 prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6566 case SECCAT_DATA_REL_RO:
6567 prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6569 case SECCAT_DATA_REL_RO_LOCAL:
6570 prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6573 prefix = one_only ? ".s" : ".sdata";
6576 prefix = one_only ? ".b" : ".bss";
6579 prefix = one_only ? ".sb" : ".sbss";
6582 prefix = one_only ? ".td" : ".tdata";
6585 prefix = one_only ? ".tb" : ".tbss";
6587 case SECCAT_EMUTLS_VAR:
6588 prefix = targetm.emutls.var_section;
6590 case SECCAT_EMUTLS_TMPL:
6591 prefix = targetm.emutls.tmpl_section;
6597 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6598 name = targetm.strip_name_encoding (name);
6600 /* If we're using one_only, then there needs to be a .gnu.linkonce
6601 prefix to the section name. */
6602 linkonce = one_only ? ".gnu.linkonce" : "";
6604 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6606 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6609 /* Like compute_reloc_for_constant, except for an RTX. The return value
6610 is a mask for which bit 1 indicates a global relocation, and bit 0
6611 indicates a local relocation. */
6614 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6616 int *preloc = (int *) data;
6619 switch (GET_CODE (x))
6622 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6635 compute_reloc_for_rtx (rtx x)
6639 switch (GET_CODE (x))
6645 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6654 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6656 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6658 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6659 return data_section;
6661 return readonly_data_section;
6665 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6666 unsigned HOST_WIDE_INT align)
6668 int reloc = compute_reloc_for_rtx (x);
6670 /* ??? Handle small data here somehow. */
6672 if (reloc & targetm.asm_out.reloc_rw_mask ())
6675 return get_named_section (NULL, ".data.rel.ro.local", 1);
6677 return get_named_section (NULL, ".data.rel.ro", 3);
6680 return mergeable_constant_section (mode, align, 0);
6683 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6686 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6691 /* Careful not to prod global register variables. */
6694 symbol = XEXP (rtl, 0);
6695 if (GET_CODE (symbol) != SYMBOL_REF)
6698 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6699 if (TREE_CODE (decl) == FUNCTION_DECL)
6700 flags |= SYMBOL_FLAG_FUNCTION;
6701 if (targetm.binds_local_p (decl))
6702 flags |= SYMBOL_FLAG_LOCAL;
6703 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)
6704 && DECL_TLS_MODEL (decl) != TLS_MODEL_EMULATED)
6705 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6706 else if (targetm.in_small_data_p (decl))
6707 flags |= SYMBOL_FLAG_SMALL;
6708 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6709 being PUBLIC, the thing *must* be defined in this translation unit.
6710 Prevent this buglet from being propagated into rtl code as well. */
6711 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6712 flags |= SYMBOL_FLAG_EXTERNAL;
6714 SYMBOL_REF_FLAGS (symbol) = flags;
6717 /* By default, we do nothing for encode_section_info, so we need not
6718 do anything but discard the '*' marker. */
6721 default_strip_name_encoding (const char *str)
6723 return str + (*str == '*');
6726 #ifdef ASM_OUTPUT_DEF
6727 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6728 anchor relative to ".", the current section position. */
6731 default_asm_output_anchor (rtx symbol)
6735 sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6736 SYMBOL_REF_BLOCK_OFFSET (symbol));
6737 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6741 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6744 default_use_anchors_for_symbol_p (const_rtx symbol)
6749 /* Don't use anchors for mergeable sections. The linker might move
6750 the objects around. */
6751 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6752 if (sect->common.flags & SECTION_MERGE)
6755 /* Don't use anchors for small data sections. The small data register
6756 acts as an anchor for such sections. */
6757 if (sect->common.flags & SECTION_SMALL)
6760 decl = SYMBOL_REF_DECL (symbol);
6761 if (decl && DECL_P (decl))
6763 /* Don't use section anchors for decls that might be defined by
6765 if (!targetm.binds_local_p (decl))
6768 /* Don't use section anchors for decls that will be placed in a
6769 small data section. */
6770 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6771 one above. The problem is that we only use SECTION_SMALL for
6772 sections that should be marked as small in the section directive. */
6773 if (targetm.in_small_data_p (decl))
6779 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6780 wrt cross-module name binding. */
6783 default_binds_local_p (const_tree exp)
6785 return default_binds_local_p_1 (exp, flag_shlib);
6789 default_binds_local_p_1 (const_tree exp, int shlib)
6793 /* A non-decl is an entry in the constant pool. */
6796 /* Weakrefs may not bind locally, even though the weakref itself is
6797 always static and therefore local. */
6798 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6800 /* Static variables are always local. */
6801 else if (! TREE_PUBLIC (exp))
6803 /* A variable is local if the user has said explicitly that it will
6805 else if (DECL_VISIBILITY_SPECIFIED (exp)
6806 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6808 /* Variables defined outside this object might not be local. */
6809 else if (DECL_EXTERNAL (exp))
6811 /* If defined in this object and visibility is not default, must be
6813 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6815 /* Default visibility weak data can be overridden by a strong symbol
6816 in another module and so are not local. */
6817 else if (DECL_WEAK (exp))
6819 /* If PIC, then assume that any global name can be overridden by
6820 symbols resolved from other modules, unless we are compiling with
6821 -fwhole-program, which assumes that names are local. */
6823 local_p = flag_whole_program;
6824 /* Uninitialized COMMON variable may be unified with symbols
6825 resolved from other modules. */
6826 else if (DECL_COMMON (exp)
6827 && (DECL_INITIAL (exp) == NULL
6828 || DECL_INITIAL (exp) == error_mark_node))
6830 /* Otherwise we're left with initialized (or non-common) global data
6831 which is of necessity defined locally. */
6838 /* Default function to output code that will globalize a label. A
6839 target must define GLOBAL_ASM_OP or provide its own function to
6840 globalize a label. */
6841 #ifdef GLOBAL_ASM_OP
6843 default_globalize_label (FILE * stream, const char *name)
6845 fputs (GLOBAL_ASM_OP, stream);
6846 assemble_name (stream, name);
6847 putc ('\n', stream);
6849 #endif /* GLOBAL_ASM_OP */
6851 /* Default function to output code that will globalize a declaration. */
6853 default_globalize_decl_name (FILE * stream, tree decl)
6855 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6856 targetm.asm_out.globalize_label (stream, name);
6859 /* Default function to output a label for unwind information. The
6860 default is to do nothing. A target that needs nonlocal labels for
6861 unwind information must provide its own function to do this. */
6863 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6864 tree decl ATTRIBUTE_UNUSED,
6865 int for_eh ATTRIBUTE_UNUSED,
6866 int empty ATTRIBUTE_UNUSED)
6870 /* Default function to output a label to divide up the exception table.
6871 The default is to do nothing. A target that needs/wants to divide
6872 up the table must provide it's own function to do this. */
6874 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6878 /* This is how to output an internal numbered label where PREFIX is
6879 the class of label and LABELNO is the number within the class. */
6882 default_internal_label (FILE *stream, const char *prefix,
6883 unsigned long labelno)
6885 char *const buf = (char *) alloca (40 + strlen (prefix));
6886 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6887 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6891 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6894 default_asm_declare_constant_name (FILE *file, const char *name,
6895 const_tree exp ATTRIBUTE_UNUSED,
6896 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
6898 assemble_label (file, name);
6901 /* This is the default behavior at the beginning of a file. It's
6902 controlled by two other target-hook toggles. */
6904 default_file_start (void)
6906 if (targetm.asm_file_start_app_off
6907 && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
6908 fputs (ASM_APP_OFF, asm_out_file);
6910 if (targetm.asm_file_start_file_directive)
6911 output_file_directive (asm_out_file, main_input_filename);
6914 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6915 which emits a special section directive used to indicate whether or
6916 not this object file needs an executable stack. This is primarily
6917 a GNU extension to ELF but could be used on other targets. */
6919 int trampolines_created;
6922 file_end_indicate_exec_stack (void)
6924 unsigned int flags = SECTION_DEBUG;
6925 if (trampolines_created)
6926 flags |= SECTION_CODE;
6928 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
6931 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6932 a get_unnamed_section callback. */
6935 output_section_asm_op (const void *directive)
6937 fprintf (asm_out_file, "%s\n", (const char *) directive);
6940 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6941 the current section is NEW_SECTION. */
6944 switch_to_section (section *new_section)
6946 if (in_section == new_section)
6949 if (new_section->common.flags & SECTION_FORGET)
6952 in_section = new_section;
6954 switch (SECTION_STYLE (new_section))
6958 && !crtl->subsections.unlikely_text_section_name
6959 && strcmp (new_section->named.name,
6960 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6961 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6963 targetm.asm_out.named_section (new_section->named.name,
6964 new_section->named.common.flags,
6965 new_section->named.decl);
6968 case SECTION_UNNAMED:
6969 new_section->unnamed.callback (new_section->unnamed.data);
6972 case SECTION_NOSWITCH:
6977 new_section->common.flags |= SECTION_DECLARED;
6980 /* If block symbol SYMBOL has not yet been assigned an offset, place
6981 it at the end of its block. */
6984 place_block_symbol (rtx symbol)
6986 unsigned HOST_WIDE_INT size, mask, offset;
6987 struct constant_descriptor_rtx *desc;
6988 unsigned int alignment;
6989 struct object_block *block;
6992 gcc_assert (SYMBOL_REF_BLOCK (symbol));
6993 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6996 /* Work out the symbol's size and alignment. */
6997 if (CONSTANT_POOL_ADDRESS_P (symbol))
6999 desc = SYMBOL_REF_CONSTANT (symbol);
7000 alignment = desc->align;
7001 size = GET_MODE_SIZE (desc->mode);
7003 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7005 decl = SYMBOL_REF_DECL (symbol);
7006 alignment = DECL_ALIGN (decl);
7007 size = get_constant_size (DECL_INITIAL (decl));
7011 decl = SYMBOL_REF_DECL (symbol);
7012 alignment = DECL_ALIGN (decl);
7013 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7016 /* Calculate the object's offset from the start of the block. */
7017 block = SYMBOL_REF_BLOCK (symbol);
7018 mask = alignment / BITS_PER_UNIT - 1;
7019 offset = (block->size + mask) & ~mask;
7020 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
7022 /* Record the block's new alignment and size. */
7023 block->alignment = MAX (block->alignment, alignment);
7024 block->size = offset + size;
7026 VEC_safe_push (rtx, gc, block->objects, symbol);
7029 /* Return the anchor that should be used to address byte offset OFFSET
7030 from the first object in BLOCK. MODEL is the TLS model used
7034 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
7035 enum tls_model model)
7038 unsigned int begin, middle, end;
7039 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
7042 /* Work out the anchor's offset. Use an offset of 0 for the first
7043 anchor so that we don't pessimize the case where we take the address
7044 of a variable at the beginning of the block. This is particularly
7045 useful when a block has only one variable assigned to it.
7047 We try to place anchors RANGE bytes apart, so there can then be
7048 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7049 a ptr_mode offset. With some target settings, the lowest such
7050 anchor might be out of range for the lowest ptr_mode offset;
7051 likewise the highest anchor for the highest offset. Use anchors
7052 at the extreme ends of the ptr_mode range in such cases.
7054 All arithmetic uses unsigned integers in order to avoid
7056 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
7057 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
7058 range = max_offset - min_offset + 1;
7063 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
7066 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
7067 delta -= delta % range;
7070 offset = (HOST_WIDE_INT) (-delta);
7074 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
7075 delta -= delta % range;
7076 if (delta > bias - 1)
7078 offset = (HOST_WIDE_INT) delta;
7082 /* Do a binary search to see if there's already an anchor we can use.
7083 Set BEGIN to the new anchor's index if not. */
7085 end = VEC_length (rtx, block->anchors);
7086 while (begin != end)
7088 middle = (end + begin) / 2;
7089 anchor = VEC_index (rtx, block->anchors, middle);
7090 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
7092 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
7094 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
7096 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
7102 /* Create a new anchor with a unique label. */
7103 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
7104 anchor = create_block_symbol (ggc_strdup (label), block, offset);
7105 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
7106 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
7108 /* Insert it at index BEGIN. */
7109 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
7113 /* Output the objects in BLOCK. */
7116 output_object_block (struct object_block *block)
7118 struct constant_descriptor_rtx *desc;
7120 HOST_WIDE_INT offset;
7124 if (block->objects == NULL)
7127 /* Switch to the section and make sure that the first byte is
7128 suitably aligned. */
7129 switch_to_section (block->sect);
7130 assemble_align (block->alignment);
7132 /* Define the values of all anchors relative to the current section
7134 for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
7135 targetm.asm_out.output_anchor (symbol);
7137 /* Output the objects themselves. */
7139 for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
7141 /* Move to the object's offset, padding with zeros if necessary. */
7142 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
7143 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
7144 if (CONSTANT_POOL_ADDRESS_P (symbol))
7146 desc = SYMBOL_REF_CONSTANT (symbol);
7147 output_constant_pool_1 (desc, 1);
7148 offset += GET_MODE_SIZE (desc->mode);
7150 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7152 decl = SYMBOL_REF_DECL (symbol);
7153 assemble_constant_contents (DECL_INITIAL (decl), XSTR (symbol, 0),
7155 offset += get_constant_size (DECL_INITIAL (decl));
7159 decl = SYMBOL_REF_DECL (symbol);
7160 assemble_variable_contents (decl, XSTR (symbol, 0), false);
7161 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7166 /* A htab_traverse callback used to call output_object_block for
7167 each member of object_block_htab. */
7170 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
7172 output_object_block ((struct object_block *) (*slot));
7176 /* Output the definitions of all object_blocks. */
7179 output_object_blocks (void)
7181 htab_traverse (object_block_htab, output_object_block_htab, NULL);
7184 /* This function provides a possible implementation of the
7185 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7186 by -frecord-gcc-switches it creates a new mergeable, string section in the
7187 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7188 contains the switches in ASCII format.
7190 FIXME: This code does not correctly handle double quote characters
7191 that appear inside strings, (it strips them rather than preserving them).
7192 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7193 characters - instead it treats them as sub-string separators. Since
7194 we want to emit NUL strings terminators into the object file we have to use
7198 elf_record_gcc_switches (print_switch_type type, const char * name)
7202 case SWITCH_TYPE_PASSED:
7203 ASM_OUTPUT_ASCII (asm_out_file, name, strlen (name));
7204 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7207 case SWITCH_TYPE_DESCRIPTIVE:
7210 /* Distinguish between invocations where name is NULL. */
7211 static bool started = false;
7217 sec = get_section (targetm.asm_out.record_gcc_switches_section,
7221 | (SECTION_ENTSIZE & 1),
7223 switch_to_section (sec);
7232 /* The return value is currently ignored by the caller, but must be 0.
7233 For -fverbose-asm the return value would be the number of characters
7234 emitted into the assembler file. */
7238 /* Emit text to declare externally defined symbols. It is needed to
7239 properly support non-default visibility. */
7241 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
7243 const char *name ATTRIBUTE_UNUSED)
7245 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7246 set in order to avoid putting out names that are never really
7248 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
7249 && targetm.binds_local_p (decl))
7250 maybe_assemble_visibility (decl);
7253 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7256 make_debug_expr_from_rtl (const_rtx exp)
7258 tree ddecl = make_node (DEBUG_EXPR_DECL), type;
7259 enum machine_mode mode = GET_MODE (exp);
7262 DECL_ARTIFICIAL (ddecl) = 1;
7263 if (REG_P (exp) && REG_EXPR (exp))
7264 type = TREE_TYPE (REG_EXPR (exp));
7265 else if (MEM_P (exp) && MEM_EXPR (exp))
7266 type = TREE_TYPE (MEM_EXPR (exp));
7269 if (type && TYPE_MODE (type) == mode)
7270 TREE_TYPE (ddecl) = type;
7272 TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
7273 DECL_MODE (ddecl) = mode;
7274 dval = gen_rtx_DEBUG_EXPR (mode);
7275 DEBUG_EXPR_TREE_DECL (dval) = ddecl;
7276 SET_DECL_RTL (ddecl, dval);
7280 #include "gt-varasm.h"