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
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 /* This file handles generation of all the assembler code
25 *except* the instructions of a function.
26 This includes declarations of variables and their initial values.
28 We also output the assembler code for constants stored in memory
29 and are responsible for combining constants with the same value. */
33 #include "coretypes.h"
40 #include "hard-reg-set.h"
48 #include "langhooks.h"
52 #include "tree-mudflap.h"
54 #include "cfglayout.h"
55 #include "basic-block.h"
56 #include "tree-iterator.h"
58 #ifdef XCOFF_DEBUGGING_INFO
59 #include "xcoffout.h" /* Needed for external data
60 declarations for e.g. AIX 4.x. */
63 /* The (assembler) name of the first globally-visible object output. */
64 extern GTY(()) const char *first_global_object_name;
65 extern GTY(()) const char *weak_global_object_name;
67 const char *first_global_object_name;
68 const char *weak_global_object_name;
71 struct constant_descriptor_rtx;
72 struct rtx_constant_pool;
74 struct varasm_status GTY(())
76 /* If we're using a per-function constant pool, this is it. */
77 struct rtx_constant_pool *pool;
79 /* Number of tree-constants deferred during the expansion of this
81 unsigned int deferred_constants;
84 #define n_deferred_constants (cfun->varasm->deferred_constants)
86 /* Number for making the label on the next
87 constant that is stored in memory. */
89 static GTY(()) int const_labelno;
91 /* Carry information from ASM_DECLARE_OBJECT_NAME
92 to ASM_FINISH_DECLARE_OBJECT. */
94 int size_directive_output;
96 /* The last decl for which assemble_variable was called,
97 if it did ASM_DECLARE_OBJECT_NAME.
98 If the last call to assemble_variable didn't do that,
101 tree last_assemble_variable_decl;
103 /* The following global variable indicates if the first basic block
104 in a function belongs to the cold partition or not. */
106 bool first_function_block_is_cold;
108 /* We give all constants their own alias set. Perhaps redundant with
109 MEM_READONLY_P, but pre-dates it. */
111 static HOST_WIDE_INT const_alias_set;
113 static const char *strip_reg_name (const char *);
114 static int contains_pointers_p (tree);
115 #ifdef ASM_OUTPUT_EXTERNAL
116 static bool incorporeal_function_p (tree);
118 static void decode_addr_const (tree, struct addr_const *);
119 static hashval_t const_desc_hash (const void *);
120 static int const_desc_eq (const void *, const void *);
121 static hashval_t const_hash_1 (const tree);
122 static int compare_constant (const tree, const tree);
123 static tree copy_constant (tree);
124 static void output_constant_def_contents (rtx);
125 static void output_addressed_constants (tree);
126 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
127 static unsigned min_align (unsigned, unsigned);
128 static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int);
129 static void globalize_decl (tree);
130 static void maybe_assemble_visibility (tree);
131 #ifdef BSS_SECTION_ASM_OP
132 #ifdef ASM_OUTPUT_BSS
133 static void asm_output_bss (FILE *, tree, const char *,
134 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
136 #ifdef ASM_OUTPUT_ALIGNED_BSS
137 static void asm_output_aligned_bss (FILE *, tree, const char *,
138 unsigned HOST_WIDE_INT, int)
141 #endif /* BSS_SECTION_ASM_OP */
142 static void mark_weak (tree);
143 static void output_constant_pool (const char *, tree);
145 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
146 section *text_section;
147 section *data_section;
148 section *readonly_data_section;
149 section *sdata_section;
150 section *ctors_section;
151 section *dtors_section;
152 section *bss_section;
153 section *sbss_section;
155 /* Various forms of common section. All are guaranteed to be nonnull. */
156 section *tls_comm_section;
157 section *comm_section;
158 section *lcomm_section;
160 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
162 section *bss_noswitch_section;
164 /* The section that holds the main exception table, when known. The section
165 is set either by the target's init_sections hook or by the first call to
166 switch_to_exception_section. */
167 section *exception_section;
169 /* The section that holds the DWARF2 frame unwind information, when known.
170 The section is set either by the target's init_sections hook or by the
171 first call to switch_to_eh_frame_section. */
172 section *eh_frame_section;
174 /* asm_out_file's current section. This is NULL if no section has yet
175 been selected or if we lose track of what the current section is. */
178 /* True if code for the current function is currently being directed
179 at the cold section. */
180 bool in_cold_section_p;
182 /* A linked list of all the unnamed sections. */
183 static GTY(()) section *unnamed_sections;
185 /* Return a nonzero value if DECL has a section attribute. */
186 #ifndef IN_NAMED_SECTION
187 #define IN_NAMED_SECTION(DECL) \
188 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
189 && DECL_SECTION_NAME (DECL) != NULL_TREE)
192 /* Hash table of named sections. */
193 static GTY((param_is (section))) htab_t section_htab;
195 /* A table of object_blocks, indexed by section. */
196 static GTY((param_is (struct object_block))) htab_t object_block_htab;
198 /* The next number to use for internal anchor labels. */
199 static GTY(()) int anchor_labelno;
201 /* A pool of constants that can be shared between functions. */
202 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
206 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
208 static GTY (()) tree emutls_object_type;
210 #ifndef NO_DOT_IN_LABEL
211 # define EMUTLS_VAR_PREFIX "__emutls_v."
212 # define EMUTLS_TMPL_PREFIX "__emutls_t."
213 #elif !defined NO_DOLLAR_IN_LABEL
214 # define EMUTLS_VAR_PREFIX "__emutls_v$"
215 # define EMUTLS_TMPL_PREFIX "__emutls_t$"
217 # define EMUTLS_VAR_PREFIX "__emutls_v_"
218 # define EMUTLS_TMPL_PREFIX "__emutls_t_"
221 /* Create an identifier for the struct __emutls_object, given an identifier
222 of the DECL_ASSEMBLY_NAME of the original object. */
225 get_emutls_object_name (tree name)
227 char *toname = alloca (strlen (IDENTIFIER_POINTER (name))
228 + sizeof (EMUTLS_VAR_PREFIX));
229 strcpy (toname, EMUTLS_VAR_PREFIX);
230 strcpy (toname + sizeof (EMUTLS_VAR_PREFIX) - 1, IDENTIFIER_POINTER (name));
232 return get_identifier (toname);
235 /* Create the structure for struct __emutls_object. This should match the
236 structure at the top of emutls.c, modulo the union there. */
239 get_emutls_object_type (void)
241 tree type, type_name, field, next_field, word_type_node;
243 type = emutls_object_type;
247 emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
248 type_name = get_identifier ("__emutls_object");
249 type_name = build_decl (TYPE_DECL, type_name, type);
250 TYPE_NAME (type) = type_name;
252 field = build_decl (FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
253 DECL_CONTEXT (field) = type;
256 field = build_decl (FIELD_DECL, get_identifier ("__offset"), ptr_type_node);
257 DECL_CONTEXT (field) = type;
258 TREE_CHAIN (field) = next_field;
261 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
262 field = build_decl (FIELD_DECL, get_identifier ("__align"), word_type_node);
263 DECL_CONTEXT (field) = type;
264 TREE_CHAIN (field) = next_field;
267 field = build_decl (FIELD_DECL, get_identifier ("__size"), word_type_node);
268 DECL_CONTEXT (field) = type;
269 TREE_CHAIN (field) = next_field;
271 TYPE_FIELDS (type) = field;
277 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
278 This will be used for initializing the emulated tls data area. */
281 get_emutls_init_templ_addr (tree decl)
286 if (!DECL_INITIAL (decl))
287 return null_pointer_node;
289 name = DECL_ASSEMBLER_NAME (decl);
290 toname = alloca (strlen (IDENTIFIER_POINTER (name))
291 + sizeof (EMUTLS_TMPL_PREFIX));
292 strcpy (toname, EMUTLS_TMPL_PREFIX);
293 strcpy (toname + sizeof (EMUTLS_TMPL_PREFIX) - 1, IDENTIFIER_POINTER (name));
294 name = get_identifier (toname);
296 to = build_decl (VAR_DECL, name, TREE_TYPE (decl));
297 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
299 DECL_ARTIFICIAL (to) = 1;
300 TREE_USED (to) = TREE_USED (decl);
301 TREE_READONLY (to) = 1;
302 DECL_IGNORED_P (to) = 1;
303 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
304 DECL_WEAK (to) = DECL_WEAK (decl);
305 if (DECL_ONE_ONLY (decl))
307 make_decl_one_only (to);
308 TREE_STATIC (to) = TREE_STATIC (decl);
309 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
310 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
313 TREE_STATIC (to) = 1;
315 DECL_INITIAL (to) = DECL_INITIAL (decl);
316 DECL_INITIAL (decl) = NULL;
318 cgraph_varpool_finalize_decl (to);
319 return build_fold_addr_expr (to);
322 /* When emulating tls, we use a control structure for use by the runtime.
323 Create and return this structure. */
326 emutls_decl (tree decl)
329 struct tree_map *h, in;
332 if (targetm.have_tls || decl == NULL || decl == error_mark_node
333 || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
336 /* Look up the object in the hash; return the control structure if
337 it has already been created. */
339 emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
341 name = DECL_ASSEMBLER_NAME (decl);
343 /* Note that we use the hash of the decl's name, rather than a hash
344 of the decl's pointer. In emutls_finish we iterate through the
345 hash table, and we want this traversal to be predictable. */
346 in.hash = htab_hash_string (IDENTIFIER_POINTER (name));
348 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
354 to = build_decl (VAR_DECL, get_emutls_object_name (name),
355 get_emutls_object_type ());
357 h = ggc_alloc (sizeof (struct tree_map));
361 *(struct tree_map **) loc = h;
363 DECL_ARTIFICIAL (to) = 1;
364 DECL_IGNORED_P (to) = 1;
365 TREE_READONLY (to) = 0;
367 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
368 if (DECL_ONE_ONLY (decl))
369 make_decl_one_only (to);
370 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
373 /* Note that these fields may need to be updated from time to time from
374 the original decl. Consider:
375 extern __thread int i;
376 int foo() { return i; }
378 in which I goes from external to locally defined and initialized. */
380 TREE_STATIC (to) = TREE_STATIC (decl);
381 TREE_USED (to) = TREE_USED (decl);
382 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
383 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
384 DECL_COMMON (to) = DECL_COMMON (decl);
385 DECL_WEAK (to) = DECL_WEAK (decl);
386 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
392 emutls_common_1 (void **loc, void *xstmts)
394 struct tree_map *h = *(struct tree_map **) loc;
395 tree args, x, *pstmts = (tree *) xstmts;
398 if (!DECL_COMMON (h->from))
401 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
403 x = get_emutls_init_templ_addr (h->from);
404 args = tree_cons (NULL, x, NULL);
405 x = build_int_cst (word_type_node, DECL_ALIGN_UNIT (h->from));
406 args = tree_cons (NULL, x, args);
407 x = fold_convert (word_type_node, DECL_SIZE_UNIT (h->from));
408 args = tree_cons (NULL, x, args);
409 x = build_fold_addr_expr (h->to);
410 args = tree_cons (NULL, x, args);
412 x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
413 x = build_function_call_expr (x, args);
415 append_to_statement_list (x, pstmts);
422 tree body = NULL_TREE;
424 if (emutls_htab == NULL)
427 htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
428 if (body == NULL_TREE)
431 cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
434 /* Helper routines for maintaining section_htab. */
437 section_entry_eq (const void *p1, const void *p2)
439 const section *old = p1;
440 const char *new = p2;
442 return strcmp (old->named.name, new) == 0;
446 section_entry_hash (const void *p)
448 const section *old = p;
449 return htab_hash_string (old->named.name);
452 /* Return a hash value for section SECT. */
455 hash_section (section *sect)
457 if (sect->common.flags & SECTION_NAMED)
458 return htab_hash_string (sect->named.name);
459 return sect->common.flags;
462 /* Helper routines for maintaining object_block_htab. */
465 object_block_entry_eq (const void *p1, const void *p2)
467 const struct object_block *old = p1;
468 const section *new = p2;
470 return old->sect == new;
474 object_block_entry_hash (const void *p)
476 const struct object_block *old = p;
477 return hash_section (old->sect);
480 /* Return a new unnamed section with the given fields. */
483 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
488 sect = ggc_alloc (sizeof (struct unnamed_section));
489 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
490 sect->unnamed.callback = callback;
491 sect->unnamed.data = data;
492 sect->unnamed.next = unnamed_sections;
494 unnamed_sections = sect;
498 /* Return a SECTION_NOSWITCH section with the given fields. */
501 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
505 sect = ggc_alloc (sizeof (struct unnamed_section));
506 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
507 sect->noswitch.callback = callback;
512 /* Return the named section structure associated with NAME. Create
513 a new section with the given fields if no such structure exists. */
516 get_section (const char *name, unsigned int flags, tree decl)
518 section *sect, **slot;
521 htab_find_slot_with_hash (section_htab, name,
522 htab_hash_string (name), INSERT);
523 flags |= SECTION_NAMED;
526 sect = ggc_alloc (sizeof (struct named_section));
527 sect->named.common.flags = flags;
528 sect->named.name = ggc_strdup (name);
529 sect->named.decl = decl;
535 if ((sect->common.flags & ~SECTION_DECLARED) != flags
536 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
538 /* Sanity check user variables for flag changes. */
540 decl = sect->named.decl;
542 error ("%+D causes a section type conflict", decl);
548 /* Return true if the current compilation mode benefits from having
549 objects grouped into blocks. */
552 use_object_blocks_p (void)
554 return flag_section_anchors;
557 /* Return the object_block structure for section SECT. Create a new
558 structure if we haven't created one already. Return null if SECT
561 static struct object_block *
562 get_block_for_section (section *sect)
564 struct object_block *block;
570 slot = htab_find_slot_with_hash (object_block_htab, sect,
571 hash_section (sect), INSERT);
572 block = (struct object_block *) *slot;
575 block = (struct object_block *)
576 ggc_alloc_cleared (sizeof (struct object_block));
583 /* Create a symbol with label LABEL and place it at byte offset
584 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
585 is not yet known. LABEL must be a garbage-collected string. */
588 create_block_symbol (const char *label, struct object_block *block,
589 HOST_WIDE_INT offset)
594 /* Create the extended SYMBOL_REF. */
595 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
596 symbol = ggc_alloc_zone (size, &rtl_zone);
598 /* Initialize the normal SYMBOL_REF fields. */
599 memset (symbol, 0, size);
600 PUT_CODE (symbol, SYMBOL_REF);
601 PUT_MODE (symbol, Pmode);
602 XSTR (symbol, 0) = label;
603 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
605 /* Initialize the block_symbol stuff. */
606 SYMBOL_REF_BLOCK (symbol) = block;
607 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
613 initialize_cold_section_name (void)
615 const char *stripped_name;
619 gcc_assert (cfun && current_function_decl);
620 if (cfun->unlikely_text_section_name)
623 dsn = DECL_SECTION_NAME (current_function_decl);
624 if (flag_function_sections && dsn)
626 name = alloca (TREE_STRING_LENGTH (dsn) + 1);
627 memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
629 stripped_name = targetm.strip_name_encoding (name);
631 buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
632 cfun->unlikely_text_section_name = ggc_strdup (buffer);
635 cfun->unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
638 /* Tell assembler to switch to unlikely-to-be-executed text section. */
641 unlikely_text_section (void)
645 if (!cfun->unlikely_text_section_name)
646 initialize_cold_section_name ();
648 return get_named_section (NULL, cfun->unlikely_text_section_name, 0);
651 return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
654 /* When called within a function context, return true if the function
655 has been assigned a cold text section and if SECT is that section.
656 When called outside a function context, return true if SECT is the
657 default cold section. */
660 unlikely_text_section_p (section *sect)
665 name = cfun->unlikely_text_section_name;
667 name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
671 && SECTION_STYLE (sect) == SECTION_NAMED
672 && strcmp (name, sect->named.name) == 0);
675 /* Return a section with a particular name and with whatever SECTION_*
676 flags section_type_flags deems appropriate. The name of the section
677 is taken from NAME if nonnull, otherwise it is taken from DECL's
678 DECL_SECTION_NAME. DECL is the decl associated with the section
679 (see the section comment for details) and RELOC is as for
680 section_type_flags. */
683 get_named_section (tree decl, const char *name, int reloc)
687 gcc_assert (!decl || DECL_P (decl));
689 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
691 flags = targetm.section_type_flags (decl, name, reloc);
693 return get_section (name, flags, decl);
696 /* If required, set DECL_SECTION_NAME to a unique name. */
699 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
700 int flag_function_or_data_sections)
702 if (DECL_SECTION_NAME (decl) == NULL_TREE
703 && targetm.have_named_sections
704 && (flag_function_or_data_sections
705 || DECL_ONE_ONLY (decl)))
706 targetm.asm_out.unique_section (decl, reloc);
709 #ifdef BSS_SECTION_ASM_OP
711 #ifdef ASM_OUTPUT_BSS
713 /* Utility function for ASM_OUTPUT_BSS for targets to use if
714 they don't support alignments in .bss.
715 ??? It is believed that this function will work in most cases so such
716 support is localized here. */
719 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
721 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
722 unsigned HOST_WIDE_INT rounded)
724 targetm.asm_out.globalize_label (file, name);
725 switch_to_section (bss_section);
726 #ifdef ASM_DECLARE_OBJECT_NAME
727 last_assemble_variable_decl = decl;
728 ASM_DECLARE_OBJECT_NAME (file, name, decl);
730 /* Standard thing is just output label for the object. */
731 ASM_OUTPUT_LABEL (file, name);
732 #endif /* ASM_DECLARE_OBJECT_NAME */
733 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
738 #ifdef ASM_OUTPUT_ALIGNED_BSS
740 /* Utility function for targets to use in implementing
741 ASM_OUTPUT_ALIGNED_BSS.
742 ??? It is believed that this function will work in most cases so such
743 support is localized here. */
746 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
747 const char *name, unsigned HOST_WIDE_INT size,
750 switch_to_section (bss_section);
751 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
752 #ifdef ASM_DECLARE_OBJECT_NAME
753 last_assemble_variable_decl = decl;
754 ASM_DECLARE_OBJECT_NAME (file, name, decl);
756 /* Standard thing is just output label for the object. */
757 ASM_OUTPUT_LABEL (file, name);
758 #endif /* ASM_DECLARE_OBJECT_NAME */
759 ASM_OUTPUT_SKIP (file, size ? size : 1);
764 #endif /* BSS_SECTION_ASM_OP */
766 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
767 /* Return the hot section for function DECL. Return text_section for
771 hot_function_section (tree decl)
773 if (decl != NULL_TREE
774 && DECL_SECTION_NAME (decl) != NULL_TREE
775 && targetm.have_named_sections)
776 return get_named_section (decl, NULL, 0);
782 /* Return the section for function DECL.
784 If DECL is NULL_TREE, return the text section. We can be passed
785 NULL_TREE under some circumstances by dbxout.c at least. */
788 function_section (tree decl)
792 if (first_function_block_is_cold)
795 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
796 if (decl != NULL_TREE
797 && DECL_SECTION_NAME (decl) != NULL_TREE)
798 return reloc ? unlikely_text_section ()
799 : get_named_section (decl, NULL, 0);
801 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
803 return reloc ? unlikely_text_section () : hot_function_section (decl);
808 current_function_section (void)
810 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
811 if (current_function_decl != NULL_TREE
812 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
813 return in_cold_section_p ? unlikely_text_section ()
814 : get_named_section (current_function_decl,
817 return targetm.asm_out.select_section (current_function_decl,
819 DECL_ALIGN (current_function_decl));
821 return (in_cold_section_p
822 ? unlikely_text_section ()
823 : hot_function_section (current_function_decl));
827 /* Return the read-only data section associated with function DECL. */
830 default_function_rodata_section (tree decl)
832 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
834 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
836 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
838 size_t len = strlen (name) + 3;
839 char* rname = alloca (len);
841 strcpy (rname, ".rodata");
842 strcat (rname, name + 5);
843 return get_section (rname, SECTION_LINKONCE, decl);
845 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
846 else if (DECL_ONE_ONLY (decl)
847 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
849 size_t len = strlen (name) + 1;
850 char *rname = alloca (len);
852 memcpy (rname, name, len);
854 return get_section (rname, SECTION_LINKONCE, decl);
856 /* For .text.foo we want to use .rodata.foo. */
857 else if (flag_function_sections && flag_data_sections
858 && strncmp (name, ".text.", 6) == 0)
860 size_t len = strlen (name) + 1;
861 char *rname = alloca (len + 2);
863 memcpy (rname, ".rodata", 7);
864 memcpy (rname + 7, name + 5, len - 5);
865 return get_section (rname, 0, decl);
869 return readonly_data_section;
872 /* Return the read-only data section associated with function DECL
873 for targets where that section should be always the single
874 readonly data section. */
877 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
879 return readonly_data_section;
882 /* Return the section to use for string merging. */
885 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
886 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
887 unsigned int flags ATTRIBUTE_UNUSED)
891 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
892 && TREE_CODE (decl) == STRING_CST
893 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
895 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
896 && TREE_STRING_LENGTH (decl) >= len)
898 enum machine_mode mode;
899 unsigned int modesize;
905 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
906 modesize = GET_MODE_BITSIZE (mode);
907 if (modesize >= 8 && modesize <= 256
908 && (modesize & (modesize - 1)) == 0)
910 if (align < modesize)
913 str = TREE_STRING_POINTER (decl);
914 unit = GET_MODE_SIZE (mode);
916 /* Check for embedded NUL characters. */
917 for (i = 0; i < len; i += unit)
919 for (j = 0; j < unit; j++)
920 if (str[i + j] != '\0')
927 sprintf (name, ".rodata.str%d.%d", modesize / 8,
929 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
930 return get_section (name, flags, NULL);
935 return readonly_data_section;
938 /* Return the section to use for constant merging. */
941 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
942 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
943 unsigned int flags ATTRIBUTE_UNUSED)
945 unsigned int modesize = GET_MODE_BITSIZE (mode);
947 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
953 && (align & (align - 1)) == 0)
957 sprintf (name, ".rodata.cst%d", (int) (align / 8));
958 flags |= (align / 8) | SECTION_MERGE;
959 return get_section (name, flags, NULL);
961 return readonly_data_section;
964 /* Given NAME, a putative register name, discard any customary prefixes. */
967 strip_reg_name (const char *name)
969 #ifdef REGISTER_PREFIX
970 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
971 name += strlen (REGISTER_PREFIX);
973 if (name[0] == '%' || name[0] == '#')
978 /* The user has asked for a DECL to have a particular name. Set (or
979 change) it in such a way that we don't prefix an underscore to
982 set_user_assembler_name (tree decl, const char *name)
984 char *starred = alloca (strlen (name) + 2);
986 strcpy (starred + 1, name);
987 change_decl_assembler_name (decl, get_identifier (starred));
988 SET_DECL_RTL (decl, NULL_RTX);
991 /* Decode an `asm' spec for a declaration as a register name.
992 Return the register number, or -1 if nothing specified,
993 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
994 or -3 if ASMSPEC is `cc' and is not recognized,
995 or -4 if ASMSPEC is `memory' and is not recognized.
996 Accept an exact spelling or a decimal number.
997 Prefixes such as % are optional. */
1000 decode_reg_name (const char *asmspec)
1006 /* Get rid of confusing prefixes. */
1007 asmspec = strip_reg_name (asmspec);
1009 /* Allow a decimal number as a "register name". */
1010 for (i = strlen (asmspec) - 1; i >= 0; i--)
1011 if (! ISDIGIT (asmspec[i]))
1013 if (asmspec[0] != 0 && i < 0)
1016 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
1022 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1024 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1027 #ifdef ADDITIONAL_REGISTER_NAMES
1029 static const struct { const char *const name; const int number; } table[]
1030 = ADDITIONAL_REGISTER_NAMES;
1032 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1033 if (table[i].name[0]
1034 && ! strcmp (asmspec, table[i].name))
1035 return table[i].number;
1037 #endif /* ADDITIONAL_REGISTER_NAMES */
1039 if (!strcmp (asmspec, "memory"))
1042 if (!strcmp (asmspec, "cc"))
1051 /* Return true if DECL's initializer is suitable for a BSS section. */
1054 bss_initializer_p (tree decl)
1056 return (DECL_INITIAL (decl) == NULL
1057 || DECL_INITIAL (decl) == error_mark_node
1058 || (flag_zero_initialized_in_bss
1059 /* Leave constant zeroes in .rodata so they
1061 && !TREE_READONLY (decl)
1062 && initializer_zerop (DECL_INITIAL (decl))));
1065 /* Compute the alignment of variable specified by DECL.
1066 DONT_OUTPUT_DATA is from assemble_variable. */
1069 align_variable (tree decl, bool dont_output_data)
1071 unsigned int align = DECL_ALIGN (decl);
1073 /* In the case for initialing an array whose length isn't specified,
1074 where we have not yet been able to do the layout,
1075 figure out the proper alignment now. */
1076 if (dont_output_data && DECL_SIZE (decl) == 0
1077 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1078 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1080 /* Some object file formats have a maximum alignment which they support.
1081 In particular, a.out format supports a maximum alignment of 4. */
1082 if (align > MAX_OFILE_ALIGNMENT)
1084 warning (0, "alignment of %q+D is greater than maximum object "
1085 "file alignment. Using %d", decl,
1086 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1087 align = MAX_OFILE_ALIGNMENT;
1090 /* On some machines, it is good to increase alignment sometimes. */
1091 if (! DECL_USER_ALIGN (decl))
1093 #ifdef DATA_ALIGNMENT
1094 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1096 #ifdef CONSTANT_ALIGNMENT
1097 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1098 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1102 /* Reset the alignment in case we have made it tighter, so we can benefit
1103 from it in get_pointer_alignment. */
1104 DECL_ALIGN (decl) = align;
1107 /* Return the section into which the given VAR_DECL or CONST_DECL
1108 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1109 section should be used wherever possible. */
1112 get_variable_section (tree decl, bool prefer_noswitch_p)
1116 /* If the decl has been given an explicit section name, then it
1117 isn't common, and shouldn't be handled as such. */
1118 if (DECL_COMMON (decl) && DECL_SECTION_NAME (decl) == NULL)
1120 if (DECL_THREAD_LOCAL_P (decl))
1121 return tls_comm_section;
1122 if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1123 return comm_section;
1126 if (DECL_INITIAL (decl) == error_mark_node)
1127 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1128 else if (DECL_INITIAL (decl))
1129 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1133 resolve_unique_section (decl, reloc, flag_data_sections);
1134 if (IN_NAMED_SECTION (decl))
1135 return get_named_section (decl, NULL, reloc);
1137 if (!DECL_THREAD_LOCAL_P (decl)
1138 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1139 && bss_initializer_p (decl))
1141 if (!TREE_PUBLIC (decl))
1142 return lcomm_section;
1143 if (bss_noswitch_section)
1144 return bss_noswitch_section;
1147 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1150 /* Return the block into which object_block DECL should be placed. */
1152 static struct object_block *
1153 get_block_for_decl (tree decl)
1157 if (TREE_CODE (decl) == VAR_DECL)
1159 /* The object must be defined in this translation unit. */
1160 if (DECL_EXTERNAL (decl))
1163 /* There's no point using object blocks for something that is
1164 isolated by definition. */
1165 if (DECL_ONE_ONLY (decl))
1169 /* We can only calculate block offsets if the decl has a known
1171 if (DECL_SIZE_UNIT (decl) == NULL)
1173 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1176 /* Find out which section should contain DECL. We cannot put it into
1177 an object block if it requires a standalone definition. */
1178 if (TREE_CODE (decl) == VAR_DECL)
1179 align_variable (decl, 0);
1180 sect = get_variable_section (decl, true);
1181 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1184 return get_block_for_section (sect);
1187 /* Make sure block symbol SYMBOL is in block BLOCK. */
1190 change_symbol_block (rtx symbol, struct object_block *block)
1192 if (block != SYMBOL_REF_BLOCK (symbol))
1194 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1195 SYMBOL_REF_BLOCK (symbol) = block;
1199 /* Return true if it is possible to put DECL in an object_block. */
1202 use_blocks_for_decl_p (tree decl)
1204 /* Only data DECLs can be placed into object blocks. */
1205 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1208 /* Detect decls created by dw2_force_const_mem. Such decls are
1209 special because DECL_INITIAL doesn't specify the decl's true value.
1210 dw2_output_indirect_constants will instead call assemble_variable
1211 with dont_output_data set to 1 and then print the contents itself. */
1212 if (DECL_INITIAL (decl) == decl)
1218 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1219 have static storage duration. In other words, it should not be an
1220 automatic variable, including PARM_DECLs.
1222 There is, however, one exception: this function handles variables
1223 explicitly placed in a particular register by the user.
1225 This is never called for PARM_DECL nodes. */
1228 make_decl_rtl (tree decl)
1230 const char *name = 0;
1234 /* Check that we are not being given an automatic variable. */
1235 gcc_assert (TREE_CODE (decl) != PARM_DECL
1236 && TREE_CODE (decl) != RESULT_DECL);
1238 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1239 gcc_assert (TREE_CODE (decl) != VAR_DECL
1240 || TREE_STATIC (decl)
1241 || TREE_PUBLIC (decl)
1242 || DECL_EXTERNAL (decl)
1243 || DECL_REGISTER (decl));
1245 /* And that we were not given a type or a label. */
1246 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1247 && TREE_CODE (decl) != LABEL_DECL);
1249 /* For a duplicate declaration, we can be called twice on the
1250 same DECL node. Don't discard the RTL already made. */
1251 if (DECL_RTL_SET_P (decl))
1253 /* If the old RTL had the wrong mode, fix the mode. */
1254 x = DECL_RTL (decl);
1255 if (GET_MODE (x) != DECL_MODE (decl))
1256 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1258 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1261 /* ??? Another way to do this would be to maintain a hashed
1262 table of such critters. Instead of adding stuff to a DECL
1263 to give certain attributes to it, we could use an external
1264 hash map from DECL to set of attributes. */
1266 /* Let the target reassign the RTL if it wants.
1267 This is necessary, for example, when one machine specific
1268 decl attribute overrides another. */
1269 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1271 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1272 on the new decl information. */
1274 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1275 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1276 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1278 /* Make this function static known to the mudflap runtime. */
1279 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1280 mudflap_enqueue_decl (decl);
1285 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1287 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1288 && DECL_REGISTER (decl))
1290 error ("register name not specified for %q+D", decl);
1292 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1294 const char *asmspec = name+1;
1295 reg_number = decode_reg_name (asmspec);
1296 /* First detect errors in declaring global registers. */
1297 if (reg_number == -1)
1298 error ("register name not specified for %q+D", decl);
1299 else if (reg_number < 0)
1300 error ("invalid register name for %q+D", decl);
1301 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1302 error ("data type of %q+D isn%'t suitable for a register",
1304 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1305 error ("register specified for %q+D isn%'t suitable for data type",
1307 /* Now handle properly declared static register variables. */
1312 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1314 DECL_INITIAL (decl) = 0;
1315 error ("global register variable has initial value");
1317 if (TREE_THIS_VOLATILE (decl))
1318 warning (OPT_Wvolatile_register_var,
1319 "optimization may eliminate reads and/or "
1320 "writes to register variables");
1322 /* If the user specified one of the eliminables registers here,
1323 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1324 confused with that register and be eliminated. This usage is
1325 somewhat suspect... */
1327 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1328 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1329 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1331 if (TREE_STATIC (decl))
1333 /* Make this register global, so not usable for anything
1335 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1336 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1337 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1339 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1341 globalize_reg (reg_number + --nregs);
1344 /* As a register variable, it has no section. */
1348 /* Now handle ordinary static variables and functions (in memory).
1349 Also handle vars declared register invalidly. */
1350 else if (name[0] == '*')
1352 #ifdef REGISTER_PREFIX
1353 if (strlen (REGISTER_PREFIX) != 0)
1355 reg_number = decode_reg_name (name);
1356 if (reg_number >= 0 || reg_number == -3)
1357 error ("register name given for non-register variable %q+D", decl);
1362 /* Specifying a section attribute on a variable forces it into a
1363 non-.bss section, and thus it cannot be common. */
1364 if (TREE_CODE (decl) == VAR_DECL
1365 && DECL_SECTION_NAME (decl) != NULL_TREE
1366 && DECL_INITIAL (decl) == NULL_TREE
1367 && DECL_COMMON (decl))
1368 DECL_COMMON (decl) = 0;
1370 /* Variables can't be both common and weak. */
1371 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1372 DECL_COMMON (decl) = 0;
1374 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1375 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1377 x = gen_rtx_SYMBOL_REF (Pmode, name);
1378 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1379 SET_SYMBOL_REF_DECL (x, decl);
1381 x = gen_rtx_MEM (DECL_MODE (decl), x);
1382 if (TREE_CODE (decl) != FUNCTION_DECL)
1383 set_mem_attributes (x, decl, 1);
1384 SET_DECL_RTL (decl, x);
1386 /* Optionally set flags or add text to the name to record information
1387 such as that it is a function name.
1388 If the name is changed, the macro ASM_OUTPUT_LABELREF
1389 will have to know how to strip this information. */
1390 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1392 /* Make this function static known to the mudflap runtime. */
1393 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1394 mudflap_enqueue_decl (decl);
1397 /* Make the rtl for variable VAR be volatile.
1398 Use this only for static variables. */
1401 make_var_volatile (tree var)
1403 gcc_assert (MEM_P (DECL_RTL (var)));
1405 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
1408 /* Output a string of literal assembler code
1409 for an `asm' keyword used between functions. */
1412 assemble_asm (tree string)
1416 if (TREE_CODE (string) == ADDR_EXPR)
1417 string = TREE_OPERAND (string, 0);
1419 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1422 /* Record an element in the table of global destructors. SYMBOL is
1423 a SYMBOL_REF of the function to be called; PRIORITY is a number
1424 between 0 and MAX_INIT_PRIORITY. */
1427 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1428 int priority ATTRIBUTE_UNUSED)
1430 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1431 /* Tell GNU LD that this is part of the static destructor set.
1432 This will work for any system that uses stabs, most usefully
1434 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1435 dbxout_stab_value_label (XSTR (symbol, 0));
1437 sorry ("global destructors not supported on this target");
1442 default_named_section_asm_out_destructor (rtx symbol, int priority)
1444 const char *section = ".dtors";
1447 /* ??? This only works reliably with the GNU linker. */
1448 if (priority != DEFAULT_INIT_PRIORITY)
1450 sprintf (buf, ".dtors.%.5u",
1451 /* Invert the numbering so the linker puts us in the proper
1452 order; constructors are run from right to left, and the
1453 linker sorts in increasing order. */
1454 MAX_INIT_PRIORITY - priority);
1458 switch_to_section (get_section (section, SECTION_WRITE, NULL));
1459 assemble_align (POINTER_SIZE);
1460 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1463 #ifdef DTORS_SECTION_ASM_OP
1465 default_dtor_section_asm_out_destructor (rtx symbol,
1466 int priority ATTRIBUTE_UNUSED)
1468 switch_to_section (dtors_section);
1469 assemble_align (POINTER_SIZE);
1470 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1474 /* Likewise for global constructors. */
1477 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1478 int priority ATTRIBUTE_UNUSED)
1480 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1481 /* Tell GNU LD that this is part of the static destructor set.
1482 This will work for any system that uses stabs, most usefully
1484 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1485 dbxout_stab_value_label (XSTR (symbol, 0));
1487 sorry ("global constructors not supported on this target");
1492 default_named_section_asm_out_constructor (rtx symbol, int priority)
1494 const char *section = ".ctors";
1497 /* ??? This only works reliably with the GNU linker. */
1498 if (priority != DEFAULT_INIT_PRIORITY)
1500 sprintf (buf, ".ctors.%.5u",
1501 /* Invert the numbering so the linker puts us in the proper
1502 order; constructors are run from right to left, and the
1503 linker sorts in increasing order. */
1504 MAX_INIT_PRIORITY - priority);
1508 switch_to_section (get_section (section, SECTION_WRITE, NULL));
1509 assemble_align (POINTER_SIZE);
1510 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1513 #ifdef CTORS_SECTION_ASM_OP
1515 default_ctor_section_asm_out_constructor (rtx symbol,
1516 int priority ATTRIBUTE_UNUSED)
1518 switch_to_section (ctors_section);
1519 assemble_align (POINTER_SIZE);
1520 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1524 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1525 a nonzero value if the constant pool should be output before the
1526 start of the function, or a zero value if the pool should output
1527 after the end of the function. The default is to put it before the
1530 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1531 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1534 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1535 to be output to assembler.
1536 Set first_global_object_name and weak_global_object_name as appropriate. */
1539 notice_global_symbol (tree decl)
1541 const char **type = &first_global_object_name;
1543 if (first_global_object_name
1544 || !TREE_PUBLIC (decl)
1545 || DECL_EXTERNAL (decl)
1546 || !DECL_NAME (decl)
1547 || (TREE_CODE (decl) != FUNCTION_DECL
1548 && (TREE_CODE (decl) != VAR_DECL
1549 || (DECL_COMMON (decl)
1550 && (DECL_INITIAL (decl) == 0
1551 || DECL_INITIAL (decl) == error_mark_node))))
1552 || !MEM_P (DECL_RTL (decl)))
1555 /* We win when global object is found, but it is useful to know about weak
1556 symbol as well so we can produce nicer unique names. */
1557 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl))
1558 type = &weak_global_object_name;
1564 rtx decl_rtl = DECL_RTL (decl);
1566 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1567 name = ggc_strdup (p);
1573 /* Output assembler code for the constant pool of a function and associated
1574 with defining the name of the function. DECL describes the function.
1575 NAME is the function's name. For the constant pool, we use the current
1576 constant pool data. */
1579 assemble_start_function (tree decl, const char *fnname)
1582 char tmp_label[100];
1583 bool hot_label_written = false;
1585 cfun->unlikely_text_section_name = NULL;
1587 first_function_block_is_cold = false;
1588 if (flag_reorder_blocks_and_partition)
1590 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1591 cfun->hot_section_label = ggc_strdup (tmp_label);
1592 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1593 cfun->cold_section_label = ggc_strdup (tmp_label);
1594 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1595 cfun->hot_section_end_label = ggc_strdup (tmp_label);
1596 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1597 cfun->cold_section_end_label = ggc_strdup (tmp_label);
1602 cfun->hot_section_label = NULL;
1603 cfun->cold_section_label = NULL;
1604 cfun->hot_section_end_label = NULL;
1605 cfun->cold_section_end_label = NULL;
1608 /* The following code does not need preprocessing in the assembler. */
1612 if (CONSTANT_POOL_BEFORE_FUNCTION)
1613 output_constant_pool (fnname, decl);
1615 resolve_unique_section (decl, 0, flag_function_sections);
1617 /* Make sure the not and cold text (code) sections are properly
1618 aligned. This is necessary here in the case where the function
1619 has both hot and cold sections, because we don't want to re-set
1620 the alignment when the section switch happens mid-function. */
1622 if (flag_reorder_blocks_and_partition)
1624 switch_to_section (unlikely_text_section ());
1625 assemble_align (FUNCTION_BOUNDARY);
1626 ASM_OUTPUT_LABEL (asm_out_file, cfun->cold_section_label);
1628 /* When the function starts with a cold section, we need to explicitly
1629 align the hot section and write out the hot section label.
1630 But if the current function is a thunk, we do not have a CFG. */
1631 if (!current_function_is_thunk
1632 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1634 switch_to_section (text_section);
1635 assemble_align (FUNCTION_BOUNDARY);
1636 ASM_OUTPUT_LABEL (asm_out_file, cfun->hot_section_label);
1637 hot_label_written = true;
1638 first_function_block_is_cold = true;
1641 else if (DECL_SECTION_NAME (decl))
1643 /* Calls to function_section rely on first_function_block_is_cold
1644 being accurate. The first block may be cold even if we aren't
1645 doing partitioning, if the entire function was decided by
1646 choose_function_section (predict.c) to be cold. */
1648 initialize_cold_section_name ();
1650 if (cfun->unlikely_text_section_name
1651 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1652 cfun->unlikely_text_section_name) == 0)
1653 first_function_block_is_cold = true;
1656 in_cold_section_p = first_function_block_is_cold;
1658 /* Switch to the correct text section for the start of the function. */
1660 switch_to_section (function_section (decl));
1661 if (flag_reorder_blocks_and_partition
1662 && !hot_label_written)
1663 ASM_OUTPUT_LABEL (asm_out_file, cfun->hot_section_label);
1665 /* Tell assembler to move to target machine's alignment for functions. */
1666 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1667 if (align < force_align_functions_log)
1668 align = force_align_functions_log;
1671 ASM_OUTPUT_ALIGN (asm_out_file, align);
1674 /* Handle a user-specified function alignment.
1675 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1676 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1677 if (align_functions_log > align
1678 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1680 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1681 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1682 align_functions_log, align_functions - 1);
1684 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1688 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1689 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1692 (*debug_hooks->begin_function) (decl);
1694 /* Make function name accessible from other files, if appropriate. */
1696 if (TREE_PUBLIC (decl))
1698 notice_global_symbol (decl);
1700 globalize_decl (decl);
1702 maybe_assemble_visibility (decl);
1705 if (DECL_PRESERVE_P (decl))
1706 targetm.asm_out.mark_decl_preserved (fnname);
1708 /* Do any machine/system dependent processing of the function name. */
1709 #ifdef ASM_DECLARE_FUNCTION_NAME
1710 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1712 /* Standard thing is just output label for the function. */
1713 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1714 #endif /* ASM_DECLARE_FUNCTION_NAME */
1717 /* Output assembler code associated with defining the size of the
1718 function. DECL describes the function. NAME is the function's name. */
1721 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1723 #ifdef ASM_DECLARE_FUNCTION_SIZE
1724 /* We could have switched section in the middle of the function. */
1725 if (flag_reorder_blocks_and_partition)
1726 switch_to_section (function_section (decl));
1727 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1729 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1731 output_constant_pool (fnname, decl);
1732 switch_to_section (function_section (decl)); /* need to switch back */
1734 /* Output labels for end of hot/cold text sections (to be used by
1736 if (flag_reorder_blocks_and_partition)
1738 section *save_text_section;
1740 save_text_section = in_section;
1741 switch_to_section (unlikely_text_section ());
1742 ASM_OUTPUT_LABEL (asm_out_file, cfun->cold_section_end_label);
1743 if (first_function_block_is_cold)
1744 switch_to_section (text_section);
1746 switch_to_section (function_section (decl));
1747 ASM_OUTPUT_LABEL (asm_out_file, cfun->hot_section_end_label);
1748 switch_to_section (save_text_section);
1752 /* Assemble code to leave SIZE bytes of zeros. */
1755 assemble_zeros (unsigned HOST_WIDE_INT size)
1757 /* Do no output if -fsyntax-only. */
1758 if (flag_syntax_only)
1761 #ifdef ASM_NO_SKIP_IN_TEXT
1762 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1763 so we must output 0s explicitly in the text section. */
1764 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1766 unsigned HOST_WIDE_INT i;
1767 for (i = 0; i < size; i++)
1768 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1773 ASM_OUTPUT_SKIP (asm_out_file, size);
1776 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1779 assemble_align (int align)
1781 if (align > BITS_PER_UNIT)
1783 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1787 /* Assemble a string constant with the specified C string as contents. */
1790 assemble_string (const char *p, int size)
1795 /* If the string is very long, split it up. */
1799 int thissize = size - pos;
1800 if (thissize > maximum)
1803 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1811 /* A noswitch_section_callback for lcomm_section. */
1814 emit_local (tree decl ATTRIBUTE_UNUSED,
1815 const char *name ATTRIBUTE_UNUSED,
1816 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1817 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1819 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1820 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1821 size, DECL_ALIGN (decl));
1823 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1824 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1827 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1832 /* A noswitch_section_callback for bss_noswitch_section. */
1834 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1836 emit_bss (tree decl ATTRIBUTE_UNUSED,
1837 const char *name ATTRIBUTE_UNUSED,
1838 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1839 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1841 #if defined ASM_OUTPUT_ALIGNED_BSS
1842 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1845 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1851 /* A noswitch_section_callback for comm_section. */
1854 emit_common (tree decl ATTRIBUTE_UNUSED,
1855 const char *name ATTRIBUTE_UNUSED,
1856 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1857 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1859 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1860 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1861 size, DECL_ALIGN (decl));
1863 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1864 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1867 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1872 /* A noswitch_section_callback for tls_comm_section. */
1875 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1876 const char *name ATTRIBUTE_UNUSED,
1877 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1878 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1880 #ifdef ASM_OUTPUT_TLS_COMMON
1881 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1884 sorry ("thread-local COMMON data not implemented");
1889 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1890 NAME is the name of DECL's SYMBOL_REF. */
1893 assemble_noswitch_variable (tree decl, const char *name, section *sect)
1895 unsigned HOST_WIDE_INT size, rounded;
1897 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1900 /* Don't allocate zero bytes of common,
1901 since that means "undefined external" in the linker. */
1905 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1906 so that each uninitialized object starts on such a boundary. */
1907 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1908 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1909 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1911 if (!sect->noswitch.callback (decl, name, size, rounded)
1912 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1913 warning (0, "requested alignment for %q+D is greater than "
1914 "implemented alignment of %wu", decl, rounded);
1917 /* A subroutine of assemble_variable. Output the label and contents of
1918 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1919 is as for assemble_variable. */
1922 assemble_variable_contents (tree decl, const char *name,
1923 bool dont_output_data)
1925 /* Do any machine/system dependent processing of the object. */
1926 #ifdef ASM_DECLARE_OBJECT_NAME
1927 last_assemble_variable_decl = decl;
1928 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1930 /* Standard thing is just output label for the object. */
1931 ASM_OUTPUT_LABEL (asm_out_file, name);
1932 #endif /* ASM_DECLARE_OBJECT_NAME */
1934 if (!dont_output_data)
1936 if (DECL_INITIAL (decl)
1937 && DECL_INITIAL (decl) != error_mark_node
1938 && !initializer_zerop (DECL_INITIAL (decl)))
1939 /* Output the actual data. */
1940 output_constant (DECL_INITIAL (decl),
1941 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1944 /* Leave space for it. */
1945 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1949 /* Assemble everything that is needed for a variable or function declaration.
1950 Not used for automatic variables, and not used for function definitions.
1951 Should not be called for variables of incomplete structure type.
1953 TOP_LEVEL is nonzero if this variable has file scope.
1954 AT_END is nonzero if this is the special handling, at end of compilation,
1955 to define things that have had only tentative definitions.
1956 DONT_OUTPUT_DATA if nonzero means don't actually output the
1957 initial value (that will be done by the caller). */
1960 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1961 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1964 rtx decl_rtl, symbol;
1967 if (! targetm.have_tls
1968 && TREE_CODE (decl) == VAR_DECL
1969 && DECL_THREAD_LOCAL_P (decl))
1971 tree to = emutls_decl (decl);
1973 /* If this variable is defined locally, then we need to initialize the
1974 control structure with size and alignment information. We do this
1975 at the last moment because tentative definitions can take a locally
1976 defined but uninitialized variable and initialize it later, which
1977 would result in incorrect contents. */
1978 if (! DECL_EXTERNAL (to) && ! DECL_COMMON (to))
1980 VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4);
1981 constructor_elt *elt;
1982 tree type = TREE_TYPE (to);
1983 tree field = TYPE_FIELDS (type);
1985 elt = VEC_quick_push (constructor_elt, v, NULL);
1987 elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
1989 elt = VEC_quick_push (constructor_elt, v, NULL);
1990 field = TREE_CHAIN (field);
1992 elt->value = build_int_cst (TREE_TYPE (field),
1993 DECL_ALIGN_UNIT (decl));
1995 elt = VEC_quick_push (constructor_elt, v, NULL);
1996 field = TREE_CHAIN (field);
1998 elt->value = null_pointer_node;
2000 elt = VEC_quick_push (constructor_elt, v, NULL);
2001 field = TREE_CHAIN (field);
2003 elt->value = get_emutls_init_templ_addr (decl);
2005 DECL_INITIAL (to) = build_constructor (type, v);
2011 if (lang_hooks.decls.prepare_assemble_variable)
2012 lang_hooks.decls.prepare_assemble_variable (decl);
2014 last_assemble_variable_decl = 0;
2016 /* Normally no need to say anything here for external references,
2017 since assemble_external is called by the language-specific code
2018 when a declaration is first seen. */
2020 if (DECL_EXTERNAL (decl))
2023 /* Output no assembler code for a function declaration.
2024 Only definitions of functions output anything. */
2026 if (TREE_CODE (decl) == FUNCTION_DECL)
2029 /* Do nothing for global register variables. */
2030 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2032 TREE_ASM_WRITTEN (decl) = 1;
2036 /* If type was incomplete when the variable was declared,
2037 see if it is complete now. */
2039 if (DECL_SIZE (decl) == 0)
2040 layout_decl (decl, 0);
2042 /* Still incomplete => don't allocate it; treat the tentative defn
2043 (which is what it must have been) as an `extern' reference. */
2045 if (!dont_output_data && DECL_SIZE (decl) == 0)
2047 error ("storage size of %q+D isn%'t known", decl);
2048 TREE_ASM_WRITTEN (decl) = 1;
2052 /* The first declaration of a variable that comes through this function
2053 decides whether it is global (in C, has external linkage)
2054 or local (in C, has internal linkage). So do nothing more
2055 if this function has already run. */
2057 if (TREE_ASM_WRITTEN (decl))
2060 /* Make sure targetm.encode_section_info is invoked before we set
2062 decl_rtl = DECL_RTL (decl);
2064 TREE_ASM_WRITTEN (decl) = 1;
2066 /* Do no output if -fsyntax-only. */
2067 if (flag_syntax_only)
2072 if (! dont_output_data
2073 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2075 error ("size of variable %q+D is too large", decl);
2079 gcc_assert (MEM_P (decl_rtl));
2080 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2081 symbol = XEXP (decl_rtl, 0);
2082 name = XSTR (symbol, 0);
2083 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2084 notice_global_symbol (decl);
2086 /* Compute the alignment of this data. */
2088 align_variable (decl, dont_output_data);
2089 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2091 if (TREE_PUBLIC (decl))
2092 maybe_assemble_visibility (decl);
2094 if (DECL_PRESERVE_P (decl))
2095 targetm.asm_out.mark_decl_preserved (name);
2097 /* First make the assembler name(s) global if appropriate. */
2098 sect = get_variable_section (decl, false);
2099 if (TREE_PUBLIC (decl)
2101 && (sect->common.flags & SECTION_COMMON) == 0)
2102 globalize_decl (decl);
2104 /* Output any data that we will need to use the address of. */
2105 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2106 output_addressed_constants (DECL_INITIAL (decl));
2108 /* dbxout.c needs to know this. */
2109 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2110 DECL_IN_TEXT_SECTION (decl) = 1;
2112 /* If the decl is part of an object_block, make sure that the decl
2113 has been positioned within its block, but do not write out its
2114 definition yet. output_object_blocks will do that later. */
2115 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2117 gcc_assert (!dont_output_data);
2118 place_block_symbol (symbol);
2120 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2121 assemble_noswitch_variable (decl, name, sect);
2124 switch_to_section (sect);
2125 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2126 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2127 assemble_variable_contents (decl, name, dont_output_data);
2131 /* Return 1 if type TYPE contains any pointers. */
2134 contains_pointers_p (tree type)
2136 switch (TREE_CODE (type))
2139 case REFERENCE_TYPE:
2140 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2141 so I'll play safe and return 1. */
2147 case QUAL_UNION_TYPE:
2150 /* For a type that has fields, see if the fields have pointers. */
2151 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2152 if (TREE_CODE (fields) == FIELD_DECL
2153 && contains_pointers_p (TREE_TYPE (fields)))
2159 /* An array type contains pointers if its element type does. */
2160 return contains_pointers_p (TREE_TYPE (type));
2167 /* In unit-at-a-time mode, we delay assemble_external processing until
2168 the compilation unit is finalized. This is the best we can do for
2169 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2170 it all the way to final. See PR 17982 for further discussion. */
2171 static GTY(()) tree pending_assemble_externals;
2173 #ifdef ASM_OUTPUT_EXTERNAL
2174 /* True if DECL is a function decl for which no out-of-line copy exists.
2175 It is assumed that DECL's assembler name has been set. */
2178 incorporeal_function_p (tree decl)
2180 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2184 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2185 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2188 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2189 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
2195 /* Actually do the tests to determine if this is necessary, and invoke
2196 ASM_OUTPUT_EXTERNAL. */
2198 assemble_external_real (tree decl)
2200 rtx rtl = DECL_RTL (decl);
2202 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2203 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2204 && !incorporeal_function_p (decl))
2206 /* Some systems do require some output. */
2207 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2208 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2214 process_pending_assemble_externals (void)
2216 #ifdef ASM_OUTPUT_EXTERNAL
2218 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2219 assemble_external_real (TREE_VALUE (list));
2221 pending_assemble_externals = 0;
2225 /* Output something to declare an external symbol to the assembler.
2226 (Most assemblers don't need this, so we normally output nothing.)
2227 Do nothing if DECL is not external. */
2230 assemble_external (tree decl ATTRIBUTE_UNUSED)
2232 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2233 main body of this code is only rarely exercised. To provide some
2234 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2235 open. If it's not, we should not be calling this function. */
2236 gcc_assert (asm_out_file);
2238 #ifdef ASM_OUTPUT_EXTERNAL
2239 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2242 if (flag_unit_at_a_time)
2243 pending_assemble_externals = tree_cons (0, decl,
2244 pending_assemble_externals);
2246 assemble_external_real (decl);
2250 /* Similar, for calling a library function FUN. */
2253 assemble_external_libcall (rtx fun)
2255 /* Declare library function name external when first used, if nec. */
2256 if (! SYMBOL_REF_USED (fun))
2258 SYMBOL_REF_USED (fun) = 1;
2259 targetm.asm_out.external_libcall (fun);
2263 /* Assemble a label named NAME. */
2266 assemble_label (const char *name)
2268 ASM_OUTPUT_LABEL (asm_out_file, name);
2271 /* Set the symbol_referenced flag for ID. */
2273 mark_referenced (tree id)
2275 TREE_SYMBOL_REFERENCED (id) = 1;
2278 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2280 mark_decl_referenced (tree decl)
2282 if (TREE_CODE (decl) == FUNCTION_DECL)
2284 /* Extern inline functions don't become needed when referenced.
2285 If we know a method will be emitted in other TU and no new
2286 functions can be marked reachable, just use the external
2288 struct cgraph_node *node = cgraph_node (decl);
2289 if (!DECL_EXTERNAL (decl)
2290 && (!node->local.vtable_method || !cgraph_global_info_ready
2291 || !node->local.finalized))
2292 cgraph_mark_needed_node (node);
2294 else if (TREE_CODE (decl) == VAR_DECL)
2296 struct cgraph_varpool_node *node = cgraph_varpool_node (decl);
2297 cgraph_varpool_mark_needed_node (node);
2298 /* C++ frontend use mark_decl_references to force COMDAT variables
2299 to be output that might appear dead otherwise. */
2300 node->force_output = true;
2302 /* else do nothing - we can get various sorts of CST nodes here,
2303 which do not need to be marked. */
2307 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2308 until we find an identifier that is not itself a transparent alias.
2309 Modify the alias passed to it by reference (and all aliases on the
2310 way to the ultimate target), such that they do not have to be
2311 followed again, and return the ultimate target of the alias
2315 ultimate_transparent_alias_target (tree *alias)
2317 tree target = *alias;
2319 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2321 gcc_assert (TREE_CHAIN (target));
2322 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2323 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2324 && ! TREE_CHAIN (target));
2331 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2332 starts with a *, the rest of NAME is output verbatim. Otherwise
2333 NAME is transformed in a target-specific way (usually by the
2334 addition of an underscore). */
2337 assemble_name_raw (FILE *file, const char *name)
2340 fputs (&name[1], file);
2342 ASM_OUTPUT_LABELREF (file, name);
2345 /* Like assemble_name_raw, but should be used when NAME might refer to
2346 an entity that is also represented as a tree (like a function or
2347 variable). If NAME does refer to such an entity, that entity will
2348 be marked as referenced. */
2351 assemble_name (FILE *file, const char *name)
2353 const char *real_name;
2356 real_name = targetm.strip_name_encoding (name);
2358 id = maybe_get_identifier (real_name);
2363 mark_referenced (id);
2364 ultimate_transparent_alias_target (&id);
2366 name = IDENTIFIER_POINTER (id);
2367 gcc_assert (! TREE_CHAIN (id));
2370 assemble_name_raw (file, name);
2373 /* Allocate SIZE bytes writable static space with a gensym name
2374 and return an RTX to refer to its address. */
2377 assemble_static_space (unsigned HOST_WIDE_INT size)
2380 const char *namestring;
2383 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2385 namestring = ggc_strdup (name);
2387 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2388 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2390 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2391 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2394 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2395 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2398 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2399 so that each uninitialized object starts on such a boundary. */
2400 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2401 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2402 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2403 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2404 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2405 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2412 /* Assemble the static constant template for function entry trampolines.
2413 This is done at most once per compilation.
2414 Returns an RTX for the address of the template. */
2416 static GTY(()) rtx initial_trampoline;
2418 #ifdef TRAMPOLINE_TEMPLATE
2420 assemble_trampoline_template (void)
2427 if (initial_trampoline)
2428 return initial_trampoline;
2430 /* By default, put trampoline templates in read-only data section. */
2432 #ifdef TRAMPOLINE_SECTION
2433 switch_to_section (TRAMPOLINE_SECTION);
2435 switch_to_section (readonly_data_section);
2438 /* Write the assembler code to define one. */
2439 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2442 ASM_OUTPUT_ALIGN (asm_out_file, align);
2445 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2446 TRAMPOLINE_TEMPLATE (asm_out_file);
2448 /* Record the rtl to refer to it. */
2449 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2450 name = ggc_strdup (label);
2451 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2452 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2454 initial_trampoline = gen_rtx_MEM (BLKmode, symbol);
2455 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2457 return initial_trampoline;
2461 /* A and B are either alignments or offsets. Return the minimum alignment
2462 that may be assumed after adding the two together. */
2464 static inline unsigned
2465 min_align (unsigned int a, unsigned int b)
2467 return (a | b) & -(a | b);
2470 /* Return the assembler directive for creating a given kind of integer
2471 object. SIZE is the number of bytes in the object and ALIGNED_P
2472 indicates whether it is known to be aligned. Return NULL if the
2473 assembly dialect has no such directive.
2475 The returned string should be printed at the start of a new line and
2476 be followed immediately by the object's initial value. */
2479 integer_asm_op (int size, int aligned_p)
2481 struct asm_int_op *ops;
2484 ops = &targetm.asm_out.aligned_op;
2486 ops = &targetm.asm_out.unaligned_op;
2491 return targetm.asm_out.byte_op;
2505 /* Use directive OP to assemble an integer object X. Print OP at the
2506 start of the line, followed immediately by the value of X. */
2509 assemble_integer_with_op (const char *op, rtx x)
2511 fputs (op, asm_out_file);
2512 output_addr_const (asm_out_file, x);
2513 fputc ('\n', asm_out_file);
2516 /* The default implementation of the asm_out.integer target hook. */
2519 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2520 unsigned int size ATTRIBUTE_UNUSED,
2521 int aligned_p ATTRIBUTE_UNUSED)
2523 const char *op = integer_asm_op (size, aligned_p);
2524 /* Avoid GAS bugs for large values. Specifically negative values whose
2525 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2526 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2528 return op && (assemble_integer_with_op (op, x), true);
2531 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2532 the alignment of the integer in bits. Return 1 if we were able to output
2533 the constant, otherwise 0. We must be able to output the constant,
2534 if FORCE is nonzero. */
2537 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2541 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2543 /* See if the target hook can handle this kind of object. */
2544 if (targetm.asm_out.integer (x, size, aligned_p))
2547 /* If the object is a multi-byte one, try splitting it up. Split
2548 it into words it if is multi-word, otherwise split it into bytes. */
2551 enum machine_mode omode, imode;
2552 unsigned int subalign;
2553 unsigned int subsize, i;
2555 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2556 subalign = MIN (align, subsize * BITS_PER_UNIT);
2557 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
2558 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2560 for (i = 0; i < size; i += subsize)
2562 rtx partial = simplify_subreg (omode, x, imode, i);
2563 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2569 /* If we've printed some of it, but not all of it, there's no going
2574 gcc_assert (!force);
2580 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2582 long data[4] = {0, 0, 0, 0};
2584 int bitsize, nelts, nunits, units_per;
2586 /* This is hairy. We have a quantity of known size. real_to_target
2587 will put it into an array of *host* longs, 32 bits per element
2588 (even if long is more than 32 bits). We need to determine the
2589 number of array elements that are occupied (nelts) and the number
2590 of *target* min-addressable units that will be occupied in the
2591 object file (nunits). We cannot assume that 32 divides the
2592 mode's bitsize (size * BITS_PER_UNIT) evenly.
2594 size * BITS_PER_UNIT is used here to make sure that padding bits
2595 (which might appear at either end of the value; real_to_target
2596 will include the padding bits in its output array) are included. */
2598 nunits = GET_MODE_SIZE (mode);
2599 bitsize = nunits * BITS_PER_UNIT;
2600 nelts = CEIL (bitsize, 32);
2601 units_per = 32 / BITS_PER_UNIT;
2603 real_to_target (data, &d, mode);
2605 /* Put out the first word with the specified alignment. */
2606 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2607 nunits -= units_per;
2609 /* Subsequent words need only 32-bit alignment. */
2610 align = min_align (align, 32);
2612 for (i = 1; i < nelts; i++)
2614 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2615 nunits -= units_per;
2619 /* Given an expression EXP with a constant value,
2620 reduce it to the sum of an assembler symbol and an integer.
2621 Store them both in the structure *VALUE.
2622 EXP must be reducible. */
2624 struct addr_const GTY(())
2627 HOST_WIDE_INT offset;
2631 decode_addr_const (tree exp, struct addr_const *value)
2633 tree target = TREE_OPERAND (exp, 0);
2639 if (TREE_CODE (target) == COMPONENT_REF
2640 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2643 offset += int_byte_position (TREE_OPERAND (target, 1));
2644 target = TREE_OPERAND (target, 0);
2646 else if (TREE_CODE (target) == ARRAY_REF
2647 || TREE_CODE (target) == ARRAY_RANGE_REF)
2649 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2650 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2651 target = TREE_OPERAND (target, 0);
2657 switch (TREE_CODE (target))
2661 x = DECL_RTL (target);
2665 x = gen_rtx_MEM (FUNCTION_MODE,
2666 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2674 x = output_constant_def (target, 1);
2681 gcc_assert (MEM_P (x));
2685 value->offset = offset;
2688 /* Uniquize all constants that appear in memory.
2689 Each constant in memory thus far output is recorded
2690 in `const_desc_table'. */
2692 struct constant_descriptor_tree GTY(())
2694 /* A MEM for the constant. */
2697 /* The value of the constant. */
2700 /* Hash of value. Computing the hash from value each time
2701 hashfn is called can't work properly, as that means recursive
2702 use of the hash table during hash table expansion. */
2706 static GTY((param_is (struct constant_descriptor_tree)))
2707 htab_t const_desc_htab;
2709 static struct constant_descriptor_tree * build_constant_desc (tree);
2710 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2712 /* Compute a hash code for a constant expression. */
2715 const_desc_hash (const void *ptr)
2717 return ((struct constant_descriptor_tree *)ptr)->hash;
2721 const_hash_1 (const tree exp)
2726 enum tree_code code = TREE_CODE (exp);
2728 /* Either set P and LEN to the address and len of something to hash and
2729 exit the switch or return a value. */
2734 p = (char *) &TREE_INT_CST (exp);
2735 len = sizeof TREE_INT_CST (exp);
2739 return real_hash (TREE_REAL_CST_PTR (exp));
2742 p = TREE_STRING_POINTER (exp);
2743 len = TREE_STRING_LENGTH (exp);
2747 return (const_hash_1 (TREE_REALPART (exp)) * 5
2748 + const_hash_1 (TREE_IMAGPART (exp)));
2752 unsigned HOST_WIDE_INT idx;
2755 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2757 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2759 hi = hi * 603 + const_hash_1 (value);
2767 struct addr_const value;
2769 decode_addr_const (exp, &value);
2770 switch (GET_CODE (value.base))
2773 /* Don't hash the address of the SYMBOL_REF;
2774 only use the offset and the symbol name. */
2776 p = XSTR (value.base, 0);
2777 for (i = 0; p[i] != 0; i++)
2778 hi = ((hi * 613) + (unsigned) (p[i]));
2782 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2793 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2794 + const_hash_1 (TREE_OPERAND (exp, 1)));
2798 case NON_LVALUE_EXPR:
2799 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2802 /* A language specific constant. Just hash the code. */
2806 /* Compute hashing function. */
2808 for (i = 0; i < len; i++)
2809 hi = ((hi * 613) + (unsigned) (p[i]));
2814 /* Wrapper of compare_constant, for the htab interface. */
2816 const_desc_eq (const void *p1, const void *p2)
2818 const struct constant_descriptor_tree *c1 = p1;
2819 const struct constant_descriptor_tree *c2 = p2;
2820 if (c1->hash != c2->hash)
2822 return compare_constant (c1->value, c2->value);
2825 /* Compare t1 and t2, and return 1 only if they are known to result in
2826 the same bit pattern on output. */
2829 compare_constant (const tree t1, const tree t2)
2831 enum tree_code typecode;
2833 if (t1 == NULL_TREE)
2834 return t2 == NULL_TREE;
2835 if (t2 == NULL_TREE)
2838 if (TREE_CODE (t1) != TREE_CODE (t2))
2841 switch (TREE_CODE (t1))
2844 /* Integer constants are the same only if the same width of type. */
2845 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2847 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2849 return tree_int_cst_equal (t1, t2);
2852 /* Real constants are the same only if the same width of type. */
2853 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2856 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2859 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2862 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2863 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2864 TREE_STRING_LENGTH (t1)));
2867 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2868 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2872 VEC(constructor_elt, gc) *v1, *v2;
2873 unsigned HOST_WIDE_INT idx;
2875 typecode = TREE_CODE (TREE_TYPE (t1));
2876 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2879 if (typecode == ARRAY_TYPE)
2881 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2882 /* For arrays, check that the sizes all match. */
2883 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2885 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2890 /* For record and union constructors, require exact type
2892 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2896 v1 = CONSTRUCTOR_ELTS (t1);
2897 v2 = CONSTRUCTOR_ELTS (t2);
2898 if (VEC_length (constructor_elt, v1)
2899 != VEC_length (constructor_elt, v2))
2902 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
2904 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
2905 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
2907 /* Check that each value is the same... */
2908 if (!compare_constant (c1->value, c2->value))
2910 /* ... and that they apply to the same fields! */
2911 if (typecode == ARRAY_TYPE)
2913 if (!compare_constant (c1->index, c2->index))
2918 if (c1->index != c2->index)
2929 struct addr_const value1, value2;
2931 decode_addr_const (t1, &value1);
2932 decode_addr_const (t2, &value2);
2933 return (value1.offset == value2.offset
2934 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2940 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2941 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2945 case NON_LVALUE_EXPR:
2946 case VIEW_CONVERT_EXPR:
2947 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2952 nt1 = lang_hooks.expand_constant (t1);
2953 nt2 = lang_hooks.expand_constant (t2);
2954 if (nt1 != t1 || nt2 != t2)
2955 return compare_constant (nt1, nt2);
2964 /* Make a copy of the whole tree structure for a constant. This
2965 handles the same types of nodes that compare_constant handles. */
2968 copy_constant (tree exp)
2970 switch (TREE_CODE (exp))
2973 /* For ADDR_EXPR, we do not want to copy the decl whose address
2974 is requested. We do want to copy constants though. */
2975 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
2976 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2977 copy_constant (TREE_OPERAND (exp, 0)));
2979 return copy_node (exp);
2984 return copy_node (exp);
2987 return build_complex (TREE_TYPE (exp),
2988 copy_constant (TREE_REALPART (exp)),
2989 copy_constant (TREE_IMAGPART (exp)));
2993 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
2994 copy_constant (TREE_OPERAND (exp, 0)),
2995 copy_constant (TREE_OPERAND (exp, 1)));
2999 case NON_LVALUE_EXPR:
3000 case VIEW_CONVERT_EXPR:
3001 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3002 copy_constant (TREE_OPERAND (exp, 0)));
3006 tree copy = copy_node (exp);
3007 VEC(constructor_elt, gc) *v;
3008 unsigned HOST_WIDE_INT idx;
3009 tree purpose, value;
3011 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3012 CONSTRUCTOR_ELTS (exp)));
3013 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3015 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3016 ce->index = purpose;
3017 ce->value = copy_constant (value);
3019 CONSTRUCTOR_ELTS (copy) = v;
3025 tree t = lang_hooks.expand_constant (exp);
3027 gcc_assert (t != exp);
3028 return copy_constant (t);
3033 /* Return the alignment of constant EXP in bits. */
3036 get_constant_alignment (tree exp)
3040 align = TYPE_ALIGN (TREE_TYPE (exp));
3041 #ifdef CONSTANT_ALIGNMENT
3042 align = CONSTANT_ALIGNMENT (exp, align);
3047 /* Return the section into which constant EXP should be placed. */
3050 get_constant_section (tree exp)
3052 if (IN_NAMED_SECTION (exp))
3053 return get_named_section (exp, NULL, compute_reloc_for_constant (exp));
3055 return targetm.asm_out.select_section (exp,
3056 compute_reloc_for_constant (exp),
3057 get_constant_alignment (exp));
3060 /* Return the size of constant EXP in bytes. */
3062 static HOST_WIDE_INT
3063 get_constant_size (tree exp)
3067 size = int_size_in_bytes (TREE_TYPE (exp));
3068 if (TREE_CODE (exp) == STRING_CST)
3069 size = MAX (TREE_STRING_LENGTH (exp), size);
3073 /* Subroutine of output_constant_def:
3074 No constant equal to EXP is known to have been output.
3075 Make a constant descriptor to enter EXP in the hash table.
3076 Assign the label number and construct RTL to refer to the
3077 constant's location in memory.
3078 Caller is responsible for updating the hash table. */
3080 static struct constant_descriptor_tree *
3081 build_constant_desc (tree exp)
3087 struct constant_descriptor_tree *desc;
3089 desc = ggc_alloc (sizeof (*desc));
3090 desc->value = copy_constant (exp);
3092 /* Propagate marked-ness to copied constant. */
3093 if (flag_mudflap && mf_marked_p (exp))
3094 mf_mark (desc->value);
3096 /* Create a string containing the label name, in LABEL. */
3097 labelno = const_labelno++;
3098 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3100 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3101 if (use_object_blocks_p ())
3103 section *sect = get_constant_section (exp);
3104 symbol = create_block_symbol (ggc_strdup (label),
3105 get_block_for_section (sect), -1);
3108 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3109 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3110 SET_SYMBOL_REF_DECL (symbol, desc->value);
3111 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3113 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3114 set_mem_attributes (rtl, exp, 1);
3115 set_mem_alias_set (rtl, 0);
3116 set_mem_alias_set (rtl, const_alias_set);
3118 /* Set flags or add text to the name to record information, such as
3119 that it is a local symbol. If the name is changed, the macro
3120 ASM_OUTPUT_LABELREF will have to know how to strip this
3121 information. This call might invalidate our local variable
3122 SYMBOL; we can't use it afterward. */
3124 targetm.encode_section_info (exp, rtl, true);
3131 /* Return an rtx representing a reference to constant data in memory
3132 for the constant expression EXP.
3134 If assembler code for such a constant has already been output,
3135 return an rtx to refer to it.
3136 Otherwise, output such a constant in memory
3137 and generate an rtx for it.
3139 If DEFER is nonzero, this constant can be deferred and output only
3140 if referenced in the function after all optimizations.
3142 `const_desc_table' records which constants already have label strings. */
3145 output_constant_def (tree exp, int defer)
3147 struct constant_descriptor_tree *desc;
3148 struct constant_descriptor_tree key;
3151 /* Look up EXP in the table of constant descriptors. If we didn't find
3152 it, create a new one. */
3154 key.hash = const_hash_1 (exp);
3155 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3160 desc = build_constant_desc (exp);
3161 desc->hash = key.hash;
3165 maybe_output_constant_def_contents (desc, defer);
3169 /* Subroutine of output_constant_def: Decide whether or not we need to
3170 output the constant DESC now, and if so, do it. */
3172 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3175 rtx symbol = XEXP (desc->rtl, 0);
3176 tree exp = desc->value;
3178 if (flag_syntax_only)
3181 if (TREE_ASM_WRITTEN (exp))
3182 /* Already output; don't do it again. */
3185 /* We can always defer constants as long as the context allows
3189 /* Increment n_deferred_constants if it exists. It needs to be at
3190 least as large as the number of constants actually referred to
3191 by the function. If it's too small we'll stop looking too early
3192 and fail to emit constants; if it's too large we'll only look
3193 through the entire function when we could have stopped earlier. */
3195 n_deferred_constants++;
3199 output_constant_def_contents (symbol);
3202 /* Subroutine of output_constant_def_contents. Output the definition
3203 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3204 constant's alignment in bits. */
3207 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3211 size = get_constant_size (exp);
3213 /* Do any machine/system dependent processing of the constant. */
3214 #ifdef ASM_DECLARE_CONSTANT_NAME
3215 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
3217 /* Standard thing is just output label for the constant. */
3218 ASM_OUTPUT_LABEL (asm_out_file, label);
3219 #endif /* ASM_DECLARE_CONSTANT_NAME */
3221 /* Output the value of EXP. */
3222 output_constant (exp, size, align);
3225 /* We must output the constant data referred to by SYMBOL; do so. */
3228 output_constant_def_contents (rtx symbol)
3230 tree exp = SYMBOL_REF_DECL (symbol);
3233 /* Make sure any other constants whose addresses appear in EXP
3234 are assigned label numbers. */
3235 output_addressed_constants (exp);
3237 /* We are no longer deferring this constant. */
3238 TREE_ASM_WRITTEN (exp) = 1;
3240 /* If the constant is part of an object block, make sure that the
3241 decl has been positioned within its block, but do not write out
3242 its definition yet. output_object_blocks will do that later. */
3243 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3244 place_block_symbol (symbol);
3247 switch_to_section (get_constant_section (exp));
3248 align = get_constant_alignment (exp);
3249 if (align > BITS_PER_UNIT)
3250 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3251 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3254 mudflap_enqueue_constant (exp);
3257 /* Look up EXP in the table of constant descriptors. Return the rtl
3258 if it has been emitted, else null. */
3261 lookup_constant_def (tree exp)
3263 struct constant_descriptor_tree *desc;
3264 struct constant_descriptor_tree key;
3267 key.hash = const_hash_1 (exp);
3268 desc = htab_find_with_hash (const_desc_htab, &key, key.hash);
3270 return (desc ? desc->rtl : NULL_RTX);
3273 /* Used in the hash tables to avoid outputting the same constant
3274 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3275 are output once per function, not once per file. */
3276 /* ??? Only a few targets need per-function constant pools. Most
3277 can use one per-file pool. Should add a targetm bit to tell the
3280 struct rtx_constant_pool GTY(())
3282 /* Pointers to first and last constant in pool, as ordered by offset. */
3283 struct constant_descriptor_rtx *first;
3284 struct constant_descriptor_rtx *last;
3286 /* Hash facility for making memory-constants from constant rtl-expressions.
3287 It is used on RISC machines where immediate integer arguments and
3288 constant addresses are restricted so that such constants must be stored
3290 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3292 /* Current offset in constant pool (does not include any
3293 machine-specific header). */
3294 HOST_WIDE_INT offset;
3297 struct constant_descriptor_rtx GTY((chain_next ("%h.next")))
3299 struct constant_descriptor_rtx *next;
3303 HOST_WIDE_INT offset;
3305 enum machine_mode mode;
3311 /* Hash and compare functions for const_rtx_htab. */
3314 const_desc_rtx_hash (const void *ptr)
3316 const struct constant_descriptor_rtx *desc = ptr;
3321 const_desc_rtx_eq (const void *a, const void *b)
3323 const struct constant_descriptor_rtx *x = a;
3324 const struct constant_descriptor_rtx *y = b;
3326 if (x->mode != y->mode)
3328 return rtx_equal_p (x->constant, y->constant);
3331 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3334 const_rtx_hash_1 (rtx *xp, void *data)
3336 unsigned HOST_WIDE_INT hwi;
3337 enum machine_mode mode;
3343 code = GET_CODE (x);
3344 mode = GET_MODE (x);
3345 h = (hashval_t) code * 1048573 + mode;
3353 const int shift = sizeof (hashval_t) * CHAR_BIT;
3354 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3357 h ^= (hashval_t) hwi;
3358 for (i = 1; i < n; ++i)
3361 h ^= (hashval_t) hwi;
3367 if (mode == VOIDmode)
3369 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3373 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3379 for (i = XVECLEN (x, 0); i-- > 0; )
3380 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3385 h ^= htab_hash_string (XSTR (x, 0));
3389 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3393 case UNSPEC_VOLATILE:
3394 h = h * 251 + XINT (x, 1);
3402 *hp = *hp * 509 + h;
3406 /* Compute a hash value for X, which should be a constant. */
3409 const_rtx_hash (rtx x)
3412 for_each_rtx (&x, const_rtx_hash_1, &h);
3417 /* Create and return a new rtx constant pool. */
3419 static struct rtx_constant_pool *
3420 create_constant_pool (void)
3422 struct rtx_constant_pool *pool;
3424 pool = ggc_alloc (sizeof (struct rtx_constant_pool));
3425 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3426 const_desc_rtx_eq, NULL);
3433 /* Initialize constant pool hashing for a new function. */
3436 init_varasm_status (struct function *f)
3438 struct varasm_status *p;
3440 p = ggc_alloc (sizeof (struct varasm_status));
3443 p->pool = create_constant_pool ();
3444 p->deferred_constants = 0;
3447 /* Given a MINUS expression, simplify it if both sides
3448 include the same symbol. */
3451 simplify_subtraction (rtx x)
3453 rtx r = simplify_rtx (x);
3457 /* Given a constant rtx X, make (or find) a memory constant for its value
3458 and return a MEM rtx to refer to it in memory. */
3461 force_const_mem (enum machine_mode mode, rtx x)
3463 struct constant_descriptor_rtx *desc, tmp;
3464 struct rtx_constant_pool *pool;
3471 /* If we're not allowed to drop X into the constant pool, don't. */
3472 if (targetm.cannot_force_const_mem (x))
3475 /* Record that this function has used a constant pool entry. */
3476 current_function_uses_const_pool = 1;
3478 /* Decide which pool to use. */
3479 pool = (targetm.use_blocks_for_constant_p (mode, x)
3480 ? shared_constant_pool
3481 : cfun->varasm->pool);
3483 /* Lookup the value in the hashtable. */
3486 hash = const_rtx_hash (x);
3487 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3490 /* If the constant was already present, return its memory. */
3492 return copy_rtx (desc->mem);
3494 /* Otherwise, create a new descriptor. */
3495 desc = ggc_alloc (sizeof (*desc));
3498 /* Align the location counter as required by EXP's data type. */
3499 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3500 #ifdef CONSTANT_ALIGNMENT
3502 tree type = lang_hooks.types.type_for_mode (mode, 0);
3503 if (type != NULL_TREE)
3504 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3508 pool->offset += (align / BITS_PER_UNIT) - 1;
3509 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3512 desc->constant = tmp.constant;
3513 desc->offset = pool->offset;
3516 desc->align = align;
3517 desc->labelno = const_labelno;
3520 pool->offset += GET_MODE_SIZE (mode);
3522 pool->last->next = desc;
3524 pool->first = pool->last = desc;
3527 /* Create a string containing the label name, in LABEL. */
3528 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3531 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3532 the constants pool. */
3533 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3535 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3536 symbol = create_block_symbol (ggc_strdup (label),
3537 get_block_for_section (sect), -1);
3540 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3542 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3543 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3544 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3546 /* Construct the MEM. */
3547 desc->mem = def = gen_const_mem (mode, symbol);
3548 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3549 set_mem_align (def, align);
3551 /* If we're dropping a label to the constant pool, make sure we
3553 if (GET_CODE (x) == LABEL_REF)
3554 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3556 return copy_rtx (def);
3559 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3562 get_pool_constant (rtx addr)
3564 return SYMBOL_REF_CONSTANT (addr)->constant;
3567 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3568 and whether it has been output or not. */
3571 get_pool_constant_mark (rtx addr, bool *pmarked)
3573 struct constant_descriptor_rtx *desc;
3575 desc = SYMBOL_REF_CONSTANT (addr);
3576 *pmarked = (desc->mark != 0);
3577 return desc->constant;
3580 /* Similar, return the mode. */
3583 get_pool_mode (rtx addr)
3585 return SYMBOL_REF_CONSTANT (addr)->mode;
3588 /* Return the size of the constant pool. */
3591 get_pool_size (void)
3593 return cfun->varasm->pool->offset;
3596 /* Worker function for output_constant_pool_1. Emit assembly for X
3597 in MODE with known alignment ALIGN. */
3600 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3602 switch (GET_MODE_CLASS (mode))
3605 case MODE_DECIMAL_FLOAT:
3609 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3610 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3611 assemble_real (r, mode, align);
3616 case MODE_PARTIAL_INT:
3617 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3620 case MODE_VECTOR_FLOAT:
3621 case MODE_VECTOR_INT:
3624 enum machine_mode submode = GET_MODE_INNER (mode);
3625 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3627 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3628 units = CONST_VECTOR_NUNITS (x);
3630 for (i = 0; i < units; i++)
3632 rtx elt = CONST_VECTOR_ELT (x, i);
3633 output_constant_pool_2 (submode, elt, i ? subalign : align);
3643 /* Worker function for output_constant_pool. Emit constant DESC,
3644 giving it ALIGN bits of alignment. */
3647 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3654 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3655 whose CODE_LABEL has been deleted. This can occur if a jump table
3656 is eliminated by optimization. If so, write a constant of zero
3657 instead. Note that this can also happen by turning the
3658 CODE_LABEL into a NOTE. */
3659 /* ??? This seems completely and utterly wrong. Certainly it's
3660 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3661 functioning even with INSN_DELETED_P and friends. */
3664 switch (GET_CODE (x))
3667 if (GET_CODE (XEXP (x, 0)) != PLUS
3668 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3670 tmp = XEXP (XEXP (x, 0), 0);
3675 gcc_assert (!INSN_DELETED_P (tmp));
3676 gcc_assert (!NOTE_P (tmp)
3677 || NOTE_LINE_NUMBER (tmp) != NOTE_INSN_DELETED);
3684 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3685 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3686 align, desc->labelno, done);
3689 assemble_align (align);
3691 /* Output the label. */
3692 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3694 /* Output the data. */
3695 output_constant_pool_2 (desc->mode, x, align);
3697 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3698 sections have proper size. */
3699 if (align > GET_MODE_BITSIZE (desc->mode)
3701 && (in_section->common.flags & SECTION_MERGE))
3702 assemble_align (align);
3704 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3710 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3711 to as used. Emit referenced deferred strings. This function can
3712 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3715 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3717 rtx x = *current_rtx;
3719 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3722 if (CONSTANT_POOL_ADDRESS_P (x))
3724 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3725 if (desc->mark == 0)
3728 for_each_rtx (&desc->constant, mark_constant, NULL);
3731 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3733 tree exp = SYMBOL_REF_DECL (x);
3734 if (!TREE_ASM_WRITTEN (exp))
3736 n_deferred_constants--;
3737 output_constant_def_contents (x);
3744 /* Look through appropriate parts of INSN, marking all entries in the
3745 constant pool which are actually being used. Entries that are only
3746 referenced by other constants are also marked as used. Emit
3747 deferred strings that are used. */
3750 mark_constants (rtx insn)
3755 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3756 insns, not any notes that may be attached. We don't want to mark
3757 a constant just because it happens to appear in a REG_EQUIV note. */
3758 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3760 rtx seq = PATTERN (insn);
3761 int i, n = XVECLEN (seq, 0);
3762 for (i = 0; i < n; ++i)
3764 rtx subinsn = XVECEXP (seq, 0, i);
3765 if (INSN_P (subinsn))
3766 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
3770 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
3773 /* Look through the instructions for this function, and mark all the
3774 entries in POOL which are actually being used. Emit deferred constants
3775 which have indeed been used. */
3778 mark_constant_pool (void)
3782 if (!current_function_uses_const_pool && n_deferred_constants == 0)
3785 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3786 mark_constants (insn);
3788 for (link = current_function_epilogue_delay_list;
3790 link = XEXP (link, 1))
3791 mark_constants (XEXP (link, 0));
3794 /* Write all the constants in POOL. */
3797 output_constant_pool_contents (struct rtx_constant_pool *pool)
3799 struct constant_descriptor_rtx *desc;
3801 for (desc = pool->first; desc ; desc = desc->next)
3804 /* If the constant is part of an object_block, make sure that
3805 the constant has been positioned within its block, but do not
3806 write out its definition yet. output_object_blocks will do
3808 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
3809 && SYMBOL_REF_BLOCK (desc->sym))
3810 place_block_symbol (desc->sym);
3813 switch_to_section (targetm.asm_out.select_rtx_section
3814 (desc->mode, desc->constant, desc->align));
3815 output_constant_pool_1 (desc, desc->align);
3820 /* Mark all constants that are used in the current function, then write
3821 out the function's private constant pool. */
3824 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3825 tree fndecl ATTRIBUTE_UNUSED)
3827 struct rtx_constant_pool *pool = cfun->varasm->pool;
3829 /* It is possible for gcc to call force_const_mem and then to later
3830 discard the instructions which refer to the constant. In such a
3831 case we do not need to output the constant. */
3832 mark_constant_pool ();
3834 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3835 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3838 output_constant_pool_contents (pool);
3840 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3841 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3845 /* Write the contents of the shared constant pool. */
3848 output_shared_constant_pool (void)
3850 output_constant_pool_contents (shared_constant_pool);
3853 /* Determine what kind of relocations EXP may need. */
3856 compute_reloc_for_constant (tree exp)
3858 int reloc = 0, reloc2;
3861 /* Give the front-end a chance to convert VALUE to something that
3862 looks more like a constant to the back-end. */
3863 exp = lang_hooks.expand_constant (exp);
3865 switch (TREE_CODE (exp))
3869 /* Go inside any operations that get_inner_reference can handle and see
3870 if what's inside is a constant: no need to do anything here for
3871 addresses of variables or functions. */
3872 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3873 tem = TREE_OPERAND (tem, 0))
3876 if (TREE_PUBLIC (tem))
3883 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3884 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3888 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3889 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3890 /* The difference of two local labels is computable at link time. */
3891 if (reloc == 1 && reloc2 == 1)
3899 case NON_LVALUE_EXPR:
3900 case VIEW_CONVERT_EXPR:
3901 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3906 unsigned HOST_WIDE_INT idx;
3907 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
3909 reloc |= compute_reloc_for_constant (tem);
3919 /* Find all the constants whose addresses are referenced inside of EXP,
3920 and make sure assembler code with a label has been output for each one.
3921 Indicate whether an ADDR_EXPR has been encountered. */
3924 output_addressed_constants (tree exp)
3928 /* Give the front-end a chance to convert VALUE to something that
3929 looks more like a constant to the back-end. */
3930 exp = lang_hooks.expand_constant (exp);
3932 switch (TREE_CODE (exp))
3936 /* Go inside any operations that get_inner_reference can handle and see
3937 if what's inside is a constant: no need to do anything here for
3938 addresses of variables or functions. */
3939 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3940 tem = TREE_OPERAND (tem, 0))
3943 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3944 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
3945 tem = DECL_INITIAL (tem);
3947 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
3948 output_constant_def (tem, 0);
3953 output_addressed_constants (TREE_OPERAND (exp, 1));
3958 case NON_LVALUE_EXPR:
3959 case VIEW_CONVERT_EXPR:
3960 output_addressed_constants (TREE_OPERAND (exp, 0));
3965 unsigned HOST_WIDE_INT idx;
3966 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
3968 output_addressed_constants (tem);
3977 /* Whether a constructor CTOR is a valid static constant initializer if all
3978 its elements are. This used to be internal to initializer_constant_valid_p
3979 and has been exposed to let other functions like categorize_ctor_elements
3980 evaluate the property while walking a constructor for other purposes. */
3983 constructor_static_from_elts_p (tree ctor)
3985 return (TREE_CONSTANT (ctor)
3986 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
3987 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
3988 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
3991 /* Return nonzero if VALUE is a valid constant-valued expression
3992 for use in initializing a static variable; one that can be an
3993 element of a "constant" initializer.
3995 Return null_pointer_node if the value is absolute;
3996 if it is relocatable, return the variable that determines the relocation.
3997 We assume that VALUE has been folded as much as possible;
3998 therefore, we do not need to check for such things as
3999 arithmetic-combinations of integers. */
4002 initializer_constant_valid_p (tree value, tree endtype)
4004 /* Give the front-end a chance to convert VALUE to something that
4005 looks more like a constant to the back-end. */
4006 value = lang_hooks.expand_constant (value);
4008 switch (TREE_CODE (value))
4011 if (constructor_static_from_elts_p (value))
4013 unsigned HOST_WIDE_INT idx;
4015 bool absolute = true;
4017 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4020 reloc = initializer_constant_valid_p (elt, TREE_TYPE (elt));
4023 if (reloc != null_pointer_node)
4026 /* For a non-absolute relocation, there is no single
4027 variable that can be "the variable that determines the
4029 return absolute ? null_pointer_node : error_mark_node;
4032 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4039 return null_pointer_node;
4043 value = staticp (TREE_OPERAND (value, 0));
4046 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to
4047 be a constant, this is old-skool offsetof-like nonsense. */
4048 if (TREE_CODE (value) == INDIRECT_REF
4049 && TREE_CONSTANT (TREE_OPERAND (value, 0)))
4050 return null_pointer_node;
4051 /* Taking the address of a nested function involves a trampoline. */
4052 if (TREE_CODE (value) == FUNCTION_DECL
4053 && ((decl_function_context (value)
4054 && !DECL_NO_STATIC_CHAIN (value))
4055 || DECL_DLLIMPORT_P (value)))
4057 /* "&{...}" requires a temporary to hold the constructed
4059 if (TREE_CODE (value) == CONSTRUCTOR)
4064 case VIEW_CONVERT_EXPR:
4065 case NON_LVALUE_EXPR:
4066 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4075 src = TREE_OPERAND (value, 0);
4076 src_type = TREE_TYPE (src);
4077 dest_type = TREE_TYPE (value);
4079 /* Allow conversions between pointer types, floating-point
4080 types, and offset types. */
4081 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4082 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4083 || (TREE_CODE (dest_type) == OFFSET_TYPE
4084 && TREE_CODE (src_type) == OFFSET_TYPE))
4085 return initializer_constant_valid_p (src, endtype);
4087 /* Allow length-preserving conversions between integer types. */
4088 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4089 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4090 return initializer_constant_valid_p (src, endtype);
4092 /* Allow conversions between other integer types only if
4094 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4096 tree inner = initializer_constant_valid_p (src, endtype);
4097 if (inner == null_pointer_node)
4098 return null_pointer_node;
4102 /* Allow (int) &foo provided int is as wide as a pointer. */
4103 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4104 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4105 return initializer_constant_valid_p (src, endtype);
4107 /* Likewise conversions from int to pointers, but also allow
4108 conversions from 0. */
4109 if ((POINTER_TYPE_P (dest_type)
4110 || TREE_CODE (dest_type) == OFFSET_TYPE)
4111 && INTEGRAL_TYPE_P (src_type))
4113 if (TREE_CODE (src) == INTEGER_CST
4114 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4115 return null_pointer_node;
4116 if (integer_zerop (src))
4117 return null_pointer_node;
4118 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4119 return initializer_constant_valid_p (src, endtype);
4122 /* Allow conversions to struct or union types if the value
4124 if (TREE_CODE (dest_type) == RECORD_TYPE
4125 || TREE_CODE (dest_type) == UNION_TYPE)
4126 return initializer_constant_valid_p (src, endtype);
4131 if (! INTEGRAL_TYPE_P (endtype)
4132 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4134 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4136 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4138 /* If either term is absolute, use the other terms relocation. */
4139 if (valid0 == null_pointer_node)
4141 if (valid1 == null_pointer_node)
4147 if (! INTEGRAL_TYPE_P (endtype)
4148 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4150 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4152 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4154 /* Win if second argument is absolute. */
4155 if (valid1 == null_pointer_node)
4157 /* Win if both arguments have the same relocation.
4158 Then the value is absolute. */
4159 if (valid0 == valid1 && valid0 != 0)
4160 return null_pointer_node;
4162 /* Since GCC guarantees that string constants are unique in the
4163 generated code, a subtraction between two copies of the same
4164 constant string is absolute. */
4165 if (valid0 && TREE_CODE (valid0) == STRING_CST
4166 && valid1 && TREE_CODE (valid1) == STRING_CST
4167 && operand_equal_p (valid0, valid1, 1))
4168 return null_pointer_node;
4171 /* Support narrowing differences. */
4172 if (INTEGRAL_TYPE_P (endtype))
4176 op0 = TREE_OPERAND (value, 0);
4177 op1 = TREE_OPERAND (value, 1);
4179 /* Like STRIP_NOPS except allow the operand mode to widen.
4180 This works around a feature of fold that simplifies
4181 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
4182 that the narrower operation is cheaper. */
4184 while (TREE_CODE (op0) == NOP_EXPR
4185 || TREE_CODE (op0) == CONVERT_EXPR
4186 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4188 tree inner = TREE_OPERAND (op0, 0);
4189 if (inner == error_mark_node
4190 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4191 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4192 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4197 while (TREE_CODE (op1) == NOP_EXPR
4198 || TREE_CODE (op1) == CONVERT_EXPR
4199 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4201 tree inner = TREE_OPERAND (op1, 0);
4202 if (inner == error_mark_node
4203 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4204 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4205 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4210 op0 = initializer_constant_valid_p (op0, endtype);
4211 op1 = initializer_constant_valid_p (op1, endtype);
4213 /* Both initializers must be known. */
4217 return null_pointer_node;
4219 /* Support differences between labels. */
4220 if (TREE_CODE (op0) == LABEL_DECL
4221 && TREE_CODE (op1) == LABEL_DECL)
4222 return null_pointer_node;
4224 if (TREE_CODE (op0) == STRING_CST
4225 && TREE_CODE (op1) == STRING_CST
4226 && operand_equal_p (op0, op1, 1))
4227 return null_pointer_node;
4239 /* Output assembler code for constant EXP to FILE, with no label.
4240 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4241 Assumes output_addressed_constants has been done on EXP already.
4243 Generate exactly SIZE bytes of assembler data, padding at the end
4244 with zeros if necessary. SIZE must always be specified.
4246 SIZE is important for structure constructors,
4247 since trailing members may have been omitted from the constructor.
4248 It is also important for initialization of arrays from string constants
4249 since the full length of the string constant might not be wanted.
4250 It is also needed for initialization of unions, where the initializer's
4251 type is just one member, and that may not be as long as the union.
4253 There a case in which we would fail to output exactly SIZE bytes:
4254 for a structure constructor that wants to produce more than SIZE bytes.
4255 But such constructors will never be generated for any possible input.
4257 ALIGN is the alignment of the data in bits. */
4260 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4262 enum tree_code code;
4263 unsigned HOST_WIDE_INT thissize;
4265 /* Some front-ends use constants other than the standard language-independent
4266 varieties, but which may still be output directly. Give the front-end a
4267 chance to convert EXP to a language-independent representation. */
4268 exp = lang_hooks.expand_constant (exp);
4270 if (size == 0 || flag_syntax_only)
4273 /* See if we're trying to initialize a pointer in a non-default mode
4274 to the address of some declaration somewhere. If the target says
4275 the mode is valid for pointers, assume the target has a way of
4277 if (TREE_CODE (exp) == NOP_EXPR
4278 && POINTER_TYPE_P (TREE_TYPE (exp))
4279 && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp))))
4281 tree saved_type = TREE_TYPE (exp);
4283 /* Peel off any intermediate conversions-to-pointer for valid
4285 while (TREE_CODE (exp) == NOP_EXPR
4286 && POINTER_TYPE_P (TREE_TYPE (exp))
4287 && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp))))
4288 exp = TREE_OPERAND (exp, 0);
4290 /* If what we're left with is the address of something, we can
4291 convert the address to the final type and output it that
4293 if (TREE_CODE (exp) == ADDR_EXPR)
4294 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4295 /* Likewise for constant ints. */
4296 else if (TREE_CODE (exp) == INTEGER_CST)
4297 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4298 TREE_INT_CST_HIGH (exp));
4302 /* Eliminate any conversions since we'll be outputting the underlying
4304 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4305 || TREE_CODE (exp) == NON_LVALUE_EXPR
4306 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4308 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4309 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4311 /* Make sure eliminating the conversion is really a no-op, except with
4312 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4313 union types to allow for Ada unchecked unions. */
4314 if (type_size > op_size
4315 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4316 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4317 /* Keep the conversion. */
4320 exp = TREE_OPERAND (exp, 0);
4323 code = TREE_CODE (TREE_TYPE (exp));
4324 thissize = int_size_in_bytes (TREE_TYPE (exp));
4326 /* Give the front end another chance to expand constants. */
4327 exp = lang_hooks.expand_constant (exp);
4329 /* Allow a constructor with no elements for any data type.
4330 This means to fill the space with zeros. */
4331 if (TREE_CODE (exp) == CONSTRUCTOR
4332 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4334 assemble_zeros (size);
4338 if (TREE_CODE (exp) == FDESC_EXPR)
4340 #ifdef ASM_OUTPUT_FDESC
4341 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4342 tree decl = TREE_OPERAND (exp, 0);
4343 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4350 /* Now output the underlying data. If we've handling the padding, return.
4351 Otherwise, break and ensure SIZE is the size written. */
4358 case REFERENCE_TYPE:
4360 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4361 EXPAND_INITIALIZER),
4362 MIN (size, thissize), align, 0))
4363 error ("initializer for integer value is too complicated");
4367 if (TREE_CODE (exp) != REAL_CST)
4368 error ("initializer for floating value is not a floating constant");
4370 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4374 output_constant (TREE_REALPART (exp), thissize / 2, align);
4375 output_constant (TREE_IMAGPART (exp), thissize / 2,
4376 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4381 switch (TREE_CODE (exp))
4384 output_constructor (exp, size, align);
4387 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4389 assemble_string (TREE_STRING_POINTER (exp), thissize);
4396 unsigned int nalign;
4397 enum machine_mode inner;
4399 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4400 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4402 elt_size = GET_MODE_SIZE (inner);
4404 link = TREE_VECTOR_CST_ELTS (exp);
4405 output_constant (TREE_VALUE (link), elt_size, align);
4406 while ((link = TREE_CHAIN (link)) != NULL)
4407 output_constant (TREE_VALUE (link), elt_size, nalign);
4417 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4418 output_constructor (exp, size, align);
4428 if (size > thissize)
4429 assemble_zeros (size - thissize);
4433 /* Subroutine of output_constructor, used for computing the size of
4434 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4435 type with an unspecified upper bound. */
4437 static unsigned HOST_WIDE_INT
4438 array_size_for_constructor (tree val)
4441 unsigned HOST_WIDE_INT cnt;
4442 tree index, value, tmp;
4444 /* This code used to attempt to handle string constants that are not
4445 arrays of single-bytes, but nothing else does, so there's no point in
4447 if (TREE_CODE (val) == STRING_CST)
4448 return TREE_STRING_LENGTH (val);
4450 max_index = NULL_TREE;
4451 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4453 if (TREE_CODE (index) == RANGE_EXPR)
4454 index = TREE_OPERAND (index, 1);
4455 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4459 if (max_index == NULL_TREE)
4462 /* Compute the total number of array elements. */
4463 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4464 i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4465 fold_convert (sizetype, tmp));
4466 i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4468 /* Multiply by the array element unit size to find number of bytes. */
4469 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4471 return tree_low_cst (i, 1);
4474 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4475 Generate at least SIZE bytes, padding if necessary. */
4478 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
4481 tree type = TREE_TYPE (exp);
4484 /* Number of bytes output or skipped so far.
4485 In other words, current position within the constructor. */
4486 HOST_WIDE_INT total_bytes = 0;
4487 /* Nonzero means BYTE contains part of a byte, to be output. */
4488 int byte_buffer_in_use = 0;
4490 unsigned HOST_WIDE_INT cnt;
4491 constructor_elt *ce;
4493 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
4495 if (TREE_CODE (type) == RECORD_TYPE)
4496 field = TYPE_FIELDS (type);
4498 if (TREE_CODE (type) == ARRAY_TYPE
4499 && TYPE_DOMAIN (type) != 0)
4500 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4502 /* As LINK goes through the elements of the constant,
4503 FIELD goes through the structure fields, if the constant is a structure.
4504 if the constant is a union, then we override this,
4505 by getting the field from the TREE_LIST element.
4506 But the constant could also be an array. Then FIELD is zero.
4508 There is always a maximum of one element in the chain LINK for unions
4509 (even if the initializer in a source program incorrectly contains
4512 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
4513 cnt++, field = field ? TREE_CHAIN (field) : 0)
4515 tree val = ce->value;
4518 /* The element in a union constructor specifies the proper field
4520 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4521 || TREE_CODE (type) == QUAL_UNION_TYPE)
4525 else if (TREE_CODE (type) == ARRAY_TYPE)
4528 #ifdef ASM_COMMENT_START
4529 if (field && flag_verbose_asm)
4530 fprintf (asm_out_file, "%s %s:\n",
4533 ? IDENTIFIER_POINTER (DECL_NAME (field))
4537 /* Eliminate the marker that makes a cast not be an lvalue. */
4541 if (index && TREE_CODE (index) == RANGE_EXPR)
4543 unsigned HOST_WIDE_INT fieldsize
4544 = int_size_in_bytes (TREE_TYPE (type));
4545 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4546 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4547 HOST_WIDE_INT index;
4548 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4550 for (index = lo_index; index <= hi_index; index++)
4552 /* Output the element's initial value. */
4554 assemble_zeros (fieldsize);
4556 output_constant (val, fieldsize, align2);
4558 /* Count its size. */
4559 total_bytes += fieldsize;
4562 else if (field == 0 || !DECL_BIT_FIELD (field))
4564 /* An element that is not a bit-field. */
4566 unsigned HOST_WIDE_INT fieldsize;
4567 /* Since this structure is static,
4568 we know the positions are constant. */
4569 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4570 unsigned int align2;
4573 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4574 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4576 /* Output any buffered-up bit-fields preceding this element. */
4577 if (byte_buffer_in_use)
4579 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4581 byte_buffer_in_use = 0;
4584 /* Advance to offset of this element.
4585 Note no alignment needed in an array, since that is guaranteed
4586 if each element has the proper size. */
4587 if ((field != 0 || index != 0) && pos != total_bytes)
4589 gcc_assert (pos >= total_bytes);
4590 assemble_zeros (pos - total_bytes);
4594 /* Find the alignment of this element. */
4595 align2 = min_align (align, BITS_PER_UNIT * pos);
4597 /* Determine size this element should occupy. */
4602 /* If this is an array with an unspecified upper bound,
4603 the initializer determines the size. */
4604 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4605 but we cannot do this until the deprecated support for
4606 initializing zero-length array members is removed. */
4607 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4608 && TYPE_DOMAIN (TREE_TYPE (field))
4609 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4611 fieldsize = array_size_for_constructor (val);
4612 /* Given a non-empty initialization, this field had
4614 gcc_assert (!fieldsize || !TREE_CHAIN (field));
4616 else if (DECL_SIZE_UNIT (field))
4618 /* ??? This can't be right. If the decl size overflows
4619 a host integer we will silently emit no data. */
4620 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4621 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4625 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4627 /* Output the element's initial value. */
4629 assemble_zeros (fieldsize);
4631 output_constant (val, fieldsize, align2);
4633 /* Count its size. */
4634 total_bytes += fieldsize;
4636 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4637 error ("invalid initial value for member %qs",
4638 IDENTIFIER_POINTER (DECL_NAME (field)));
4641 /* Element that is a bit-field. */
4643 HOST_WIDE_INT next_offset = int_bit_position (field);
4644 HOST_WIDE_INT end_offset
4645 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4648 val = integer_zero_node;
4650 /* If this field does not start in this (or, next) byte,
4652 if (next_offset / BITS_PER_UNIT != total_bytes)
4654 /* Output remnant of any bit field in previous bytes. */
4655 if (byte_buffer_in_use)
4657 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4659 byte_buffer_in_use = 0;
4662 /* If still not at proper byte, advance to there. */
4663 if (next_offset / BITS_PER_UNIT != total_bytes)
4665 gcc_assert (next_offset / BITS_PER_UNIT >= total_bytes);
4666 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4667 total_bytes = next_offset / BITS_PER_UNIT;
4671 if (! byte_buffer_in_use)
4674 /* We must split the element into pieces that fall within
4675 separate bytes, and combine each byte with previous or
4676 following bit-fields. */
4678 /* next_offset is the offset n fbits from the beginning of
4679 the structure to the next bit of this element to be processed.
4680 end_offset is the offset of the first bit past the end of
4682 while (next_offset < end_offset)
4686 HOST_WIDE_INT value;
4687 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4688 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4690 /* Advance from byte to byte
4691 within this element when necessary. */
4692 while (next_byte != total_bytes)
4694 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4699 /* Number of bits we can process at once
4700 (all part of the same byte). */
4701 this_time = MIN (end_offset - next_offset,
4702 BITS_PER_UNIT - next_bit);
4703 if (BYTES_BIG_ENDIAN)
4705 /* On big-endian machine, take the most significant bits
4706 first (of the bits that are significant)
4707 and put them into bytes from the most significant end. */
4708 shift = end_offset - next_offset - this_time;
4710 /* Don't try to take a bunch of bits that cross
4711 the word boundary in the INTEGER_CST. We can
4712 only select bits from the LOW or HIGH part
4714 if (shift < HOST_BITS_PER_WIDE_INT
4715 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4717 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4718 shift = HOST_BITS_PER_WIDE_INT;
4721 /* Now get the bits from the appropriate constant word. */
4722 if (shift < HOST_BITS_PER_WIDE_INT)
4723 value = TREE_INT_CST_LOW (val);
4726 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4727 value = TREE_INT_CST_HIGH (val);
4728 shift -= HOST_BITS_PER_WIDE_INT;
4731 /* Get the result. This works only when:
4732 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4733 byte |= (((value >> shift)
4734 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4735 << (BITS_PER_UNIT - this_time - next_bit));
4739 /* On little-endian machines,
4740 take first the least significant bits of the value
4741 and pack them starting at the least significant
4742 bits of the bytes. */
4743 shift = next_offset - int_bit_position (field);
4745 /* Don't try to take a bunch of bits that cross
4746 the word boundary in the INTEGER_CST. We can
4747 only select bits from the LOW or HIGH part
4749 if (shift < HOST_BITS_PER_WIDE_INT
4750 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4751 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4753 /* Now get the bits from the appropriate constant word. */
4754 if (shift < HOST_BITS_PER_WIDE_INT)
4755 value = TREE_INT_CST_LOW (val);
4758 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4759 value = TREE_INT_CST_HIGH (val);
4760 shift -= HOST_BITS_PER_WIDE_INT;
4763 /* Get the result. This works only when:
4764 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4765 byte |= (((value >> shift)
4766 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4770 next_offset += this_time;
4771 byte_buffer_in_use = 1;
4776 if (byte_buffer_in_use)
4778 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4782 if ((unsigned HOST_WIDE_INT)total_bytes < size)
4783 assemble_zeros (size - total_bytes);
4786 /* This TREE_LIST contains any weak symbol declarations waiting
4788 static GTY(()) tree weak_decls;
4790 /* Mark DECL as weak. */
4793 mark_weak (tree decl)
4795 DECL_WEAK (decl) = 1;
4797 if (DECL_RTL_SET_P (decl)
4798 && MEM_P (DECL_RTL (decl))
4799 && XEXP (DECL_RTL (decl), 0)
4800 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4801 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4804 /* Merge weak status between NEWDECL and OLDDECL. */
4807 merge_weak (tree newdecl, tree olddecl)
4809 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4811 if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
4814 /* We put the NEWDECL on the weak_decls list at some point
4815 and OLDDECL as well. Keep just OLDDECL on the list. */
4816 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
4817 if (TREE_VALUE (*pwd) == newdecl)
4819 *pwd = TREE_CHAIN (*pwd);
4826 if (DECL_WEAK (newdecl))
4830 /* NEWDECL is weak, but OLDDECL is not. */
4832 /* If we already output the OLDDECL, we're in trouble; we can't
4833 go back and make it weak. This error cannot caught in
4834 declare_weak because the NEWDECL and OLDDECL was not yet
4835 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4836 if (TREE_ASM_WRITTEN (olddecl))
4837 error ("weak declaration of %q+D must precede definition",
4840 /* If we've already generated rtl referencing OLDDECL, we may
4841 have done so in a way that will not function properly with
4843 else if (TREE_USED (olddecl)
4844 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4845 warning (0, "weak declaration of %q+D after first use results "
4846 "in unspecified behavior", newdecl);
4850 /* We put the NEWDECL on the weak_decls list at some point.
4851 Replace it with the OLDDECL. */
4852 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4853 if (TREE_VALUE (wd) == newdecl)
4855 TREE_VALUE (wd) = olddecl;
4858 /* We may not find the entry on the list. If NEWDECL is a
4859 weak alias, then we will have already called
4860 globalize_decl to remove the entry; in that case, we do
4861 not need to do anything. */
4864 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4865 mark_weak (olddecl);
4868 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4869 weak. Just update NEWDECL to indicate that it's weak too. */
4870 mark_weak (newdecl);
4873 /* Declare DECL to be a weak symbol. */
4876 declare_weak (tree decl)
4878 if (! TREE_PUBLIC (decl))
4879 error ("weak declaration of %q+D must be public", decl);
4880 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4881 error ("weak declaration of %q+D must precede definition", decl);
4882 else if (SUPPORTS_WEAK)
4884 if (! DECL_WEAK (decl))
4885 weak_decls = tree_cons (NULL, decl, weak_decls);
4888 warning (0, "weak declaration of %q+D not supported", decl);
4894 weak_finish_1 (tree decl)
4896 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4897 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4900 if (! TREE_USED (decl))
4903 #ifdef ASM_WEAKEN_DECL
4904 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4906 #ifdef ASM_WEAKEN_LABEL
4907 ASM_WEAKEN_LABEL (asm_out_file, name);
4909 #ifdef ASM_OUTPUT_WEAK_ALIAS
4911 static bool warn_once = 0;
4914 warning (0, "only weak aliases are supported in this configuration");
4924 /* This TREE_LIST contains weakref targets. */
4926 static GTY(()) tree weakref_targets;
4928 /* Forward declaration. */
4929 static tree find_decl_and_mark_needed (tree decl, tree target);
4931 /* Emit any pending weak declarations. */
4938 for (t = weakref_targets; t; t = TREE_CHAIN (t))
4940 tree alias_decl = TREE_PURPOSE (t);
4941 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
4943 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
4944 /* Remove alias_decl from the weak list, but leave entries for
4945 the target alone. */
4947 #ifndef ASM_OUTPUT_WEAKREF
4948 else if (! TREE_SYMBOL_REFERENCED (target))
4950 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
4951 defined, otherwise we and weak_finish_1 would use a
4952 different macros. */
4953 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
4954 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
4956 tree decl = find_decl_and_mark_needed (alias_decl, target);
4960 decl = build_decl (TREE_CODE (alias_decl), target,
4961 TREE_TYPE (alias_decl));
4963 DECL_EXTERNAL (decl) = 1;
4964 TREE_PUBLIC (decl) = 1;
4965 DECL_ARTIFICIAL (decl) = 1;
4966 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
4967 TREE_USED (decl) = 1;
4970 weak_finish_1 (decl);
4979 /* Remove the alias and the target from the pending weak list
4980 so that we do not emit any .weak directives for the former,
4981 nor multiple .weak directives for the latter. */
4982 for (p = &weak_decls; (t2 = *p) ; )
4984 if (TREE_VALUE (t2) == alias_decl
4985 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
4986 *p = TREE_CHAIN (t2);
4988 p = &TREE_CHAIN (t2);
4991 /* Remove other weakrefs to the same target, to speed things up. */
4992 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
4994 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
4995 *p = TREE_CHAIN (t2);
4997 p = &TREE_CHAIN (t2);
5002 for (t = weak_decls; t; t = TREE_CHAIN (t))
5004 tree decl = TREE_VALUE (t);
5006 weak_finish_1 (decl);
5010 /* Emit the assembly bits to indicate that DECL is globally visible. */
5013 globalize_decl (tree decl)
5015 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5017 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5018 if (DECL_WEAK (decl))
5022 #ifdef ASM_WEAKEN_DECL
5023 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5025 ASM_WEAKEN_LABEL (asm_out_file, name);
5028 /* Remove this function from the pending weak list so that
5029 we do not emit multiple .weak directives for it. */
5030 for (p = &weak_decls; (t = *p) ; )
5032 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5033 *p = TREE_CHAIN (t);
5035 p = &TREE_CHAIN (t);
5038 /* Remove weakrefs to the same target from the pending weakref
5039 list, for the same reason. */
5040 for (p = &weakref_targets; (t = *p) ; )
5042 if (DECL_ASSEMBLER_NAME (decl)
5043 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5044 *p = TREE_CHAIN (t);
5046 p = &TREE_CHAIN (t);
5051 #elif defined(ASM_MAKE_LABEL_LINKONCE)
5052 if (DECL_ONE_ONLY (decl))
5053 ASM_MAKE_LABEL_LINKONCE (asm_out_file, name);
5056 targetm.asm_out.globalize_label (asm_out_file, name);
5059 /* We have to be able to tell cgraph about the needed-ness of the target
5060 of an alias. This requires that the decl have been defined. Aliases
5061 that precede their definition have to be queued for later processing. */
5063 typedef struct alias_pair GTY(())
5069 /* Define gc'd vector type. */
5070 DEF_VEC_O(alias_pair);
5071 DEF_VEC_ALLOC_O(alias_pair,gc);
5073 static GTY(()) VEC(alias_pair,gc) *alias_pairs;
5075 /* Given an assembly name, find the decl it is associated with. At the
5076 same time, mark it needed for cgraph. */
5079 find_decl_and_mark_needed (tree decl, tree target)
5081 struct cgraph_node *fnode = NULL;
5082 struct cgraph_varpool_node *vnode = NULL;
5084 if (TREE_CODE (decl) == FUNCTION_DECL)
5086 fnode = cgraph_node_for_asm (target);
5088 vnode = cgraph_varpool_node_for_asm (target);
5092 vnode = cgraph_varpool_node_for_asm (target);
5094 fnode = cgraph_node_for_asm (target);
5099 /* We can't mark function nodes as used after cgraph global info
5100 is finished. This wouldn't generally be necessary, but C++
5101 virtual table thunks are introduced late in the game and
5102 might seem like they need marking, although in fact they
5104 if (! cgraph_global_info_ready)
5105 cgraph_mark_needed_node (fnode);
5110 cgraph_varpool_mark_needed_node (vnode);
5117 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5118 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5119 tree node is DECL to have the value of the tree node TARGET. */
5122 do_assemble_alias (tree decl, tree target)
5124 if (TREE_ASM_WRITTEN (decl))
5127 TREE_ASM_WRITTEN (decl) = 1;
5128 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5130 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5132 ultimate_transparent_alias_target (&target);
5134 if (!targetm.have_tls
5135 && TREE_CODE (decl) == VAR_DECL
5136 && DECL_THREAD_LOCAL_P (decl))
5138 decl = emutls_decl (decl);
5139 target = get_emutls_object_name (target);
5142 if (!TREE_SYMBOL_REFERENCED (target))
5143 weakref_targets = tree_cons (decl, target, weakref_targets);
5145 #ifdef ASM_OUTPUT_WEAKREF
5146 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5147 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5148 IDENTIFIER_POINTER (target));
5152 error ("%Jweakref is not supported in this configuration", decl);
5159 if (!targetm.have_tls
5160 && TREE_CODE (decl) == VAR_DECL
5161 && DECL_THREAD_LOCAL_P (decl))
5163 decl = emutls_decl (decl);
5164 target = get_emutls_object_name (target);
5167 #ifdef ASM_OUTPUT_DEF
5168 /* Make name accessible from other files, if appropriate. */
5170 if (TREE_PUBLIC (decl))
5172 globalize_decl (decl);
5173 maybe_assemble_visibility (decl);
5176 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5177 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5179 ASM_OUTPUT_DEF (asm_out_file,
5180 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5181 IDENTIFIER_POINTER (target));
5183 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5188 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5189 # ifdef ASM_WEAKEN_DECL
5190 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5192 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5194 /* Remove this function from the pending weak list so that
5195 we do not emit multiple .weak directives for it. */
5196 for (p = &weak_decls; (t = *p) ; )
5197 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5198 *p = TREE_CHAIN (t);
5200 p = &TREE_CHAIN (t);
5202 /* Remove weakrefs to the same target from the pending weakref
5203 list, for the same reason. */
5204 for (p = &weakref_targets; (t = *p) ; )
5206 if (DECL_ASSEMBLER_NAME (decl)
5207 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5208 *p = TREE_CHAIN (t);
5210 p = &TREE_CHAIN (t);
5216 /* First pass of completing pending aliases. Make sure that cgraph knows
5217 which symbols will be required. */
5220 finish_aliases_1 (void)
5225 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5229 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5230 if (target_decl == NULL)
5232 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5233 error ("%q+D aliased to undefined symbol %qs",
5234 p->decl, IDENTIFIER_POINTER (p->target));
5236 else if (DECL_EXTERNAL (target_decl)
5237 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5238 error ("%q+D aliased to external symbol %qs",
5239 p->decl, IDENTIFIER_POINTER (p->target));
5243 /* Second pass of completing pending aliases. Emit the actual assembly.
5244 This happens at the end of compilation and thus it is assured that the
5245 target symbol has been emitted. */
5248 finish_aliases_2 (void)
5253 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5254 do_assemble_alias (p->decl, p->target);
5256 VEC_truncate (alias_pair, alias_pairs, 0);
5259 /* Emit an assembler directive to make the symbol for DECL an alias to
5260 the symbol for TARGET. */
5263 assemble_alias (tree decl, tree target)
5266 bool is_weakref = false;
5268 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5270 tree alias = DECL_ASSEMBLER_NAME (decl);
5274 ultimate_transparent_alias_target (&target);
5276 if (alias == target)
5277 error ("weakref %q+D ultimately targets itself", decl);
5280 #ifndef ASM_OUTPUT_WEAKREF
5281 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5282 TREE_CHAIN (alias) = target;
5285 if (TREE_PUBLIC (decl))
5286 error ("weakref %q+D must have static linkage", decl);
5290 #if !defined (ASM_OUTPUT_DEF)
5291 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5292 error ("%Jalias definitions not supported in this configuration", decl);
5295 if (!DECL_WEAK (decl))
5297 error ("%Jonly weak aliases are supported in this configuration", decl);
5304 /* We must force creation of DECL_RTL for debug info generation, even though
5305 we don't use it here. */
5306 make_decl_rtl (decl);
5307 TREE_USED (decl) = 1;
5309 /* A quirk of the initial implementation of aliases required that the user
5310 add "extern" to all of them. Which is silly, but now historical. Do
5311 note that the symbol is in fact locally defined. */
5313 DECL_EXTERNAL (decl) = 0;
5315 /* Allow aliases to aliases. */
5316 if (TREE_CODE (decl) == FUNCTION_DECL)
5317 cgraph_node (decl)->alias = true;
5319 cgraph_varpool_node (decl)->alias = true;
5321 /* If the target has already been emitted, we don't have to queue the
5322 alias. This saves a tad o memory. */
5323 target_decl = find_decl_and_mark_needed (decl, target);
5324 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5325 do_assemble_alias (decl, target);
5328 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5334 /* Emit an assembler directive to set symbol for DECL visibility to
5335 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5338 default_assemble_visibility (tree decl, int vis)
5340 static const char * const visibility_types[] = {
5341 NULL, "protected", "hidden", "internal"
5344 const char *name, *type;
5346 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5347 type = visibility_types[vis];
5349 #ifdef HAVE_GAS_HIDDEN
5350 fprintf (asm_out_file, "\t.%s\t", type);
5351 assemble_name (asm_out_file, name);
5352 fprintf (asm_out_file, "\n");
5354 warning (OPT_Wattributes, "visibility attribute not supported "
5355 "in this configuration; ignored");
5359 /* A helper function to call assemble_visibility when needed for a decl. */
5362 maybe_assemble_visibility (tree decl)
5364 enum symbol_visibility vis = DECL_VISIBILITY (decl);
5366 if (vis != VISIBILITY_DEFAULT)
5367 targetm.asm_out.visibility (decl, vis);
5370 /* Returns 1 if the target configuration supports defining public symbols
5371 so that one of them will be chosen at link time instead of generating a
5372 multiply-defined symbol error, whether through the use of weak symbols or
5373 a target-specific mechanism for having duplicates discarded. */
5376 supports_one_only (void)
5378 if (SUPPORTS_ONE_ONLY)
5380 return SUPPORTS_WEAK;
5383 /* Set up DECL as a public symbol that can be defined in multiple
5384 translation units without generating a linker error. */
5387 make_decl_one_only (tree decl)
5389 gcc_assert (TREE_CODE (decl) == VAR_DECL
5390 || TREE_CODE (decl) == FUNCTION_DECL);
5392 TREE_PUBLIC (decl) = 1;
5394 if (SUPPORTS_ONE_ONLY)
5396 #ifdef MAKE_DECL_ONE_ONLY
5397 MAKE_DECL_ONE_ONLY (decl);
5399 DECL_ONE_ONLY (decl) = 1;
5401 else if (TREE_CODE (decl) == VAR_DECL
5402 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5403 DECL_COMMON (decl) = 1;
5406 gcc_assert (SUPPORTS_WEAK);
5407 DECL_WEAK (decl) = 1;
5412 init_varasm_once (void)
5414 section_htab = htab_create_ggc (31, section_entry_hash,
5415 section_entry_eq, NULL);
5416 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
5417 object_block_entry_eq, NULL);
5418 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
5419 const_desc_eq, NULL);
5421 const_alias_set = new_alias_set ();
5422 shared_constant_pool = create_constant_pool ();
5424 #ifdef TEXT_SECTION_ASM_OP
5425 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
5426 TEXT_SECTION_ASM_OP);
5429 #ifdef DATA_SECTION_ASM_OP
5430 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5431 DATA_SECTION_ASM_OP);
5434 #ifdef SDATA_SECTION_ASM_OP
5435 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5436 SDATA_SECTION_ASM_OP);
5439 #ifdef READONLY_DATA_SECTION_ASM_OP
5440 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
5441 READONLY_DATA_SECTION_ASM_OP);
5444 #ifdef CTORS_SECTION_ASM_OP
5445 ctors_section = get_unnamed_section (0, output_section_asm_op,
5446 CTORS_SECTION_ASM_OP);
5449 #ifdef DTORS_SECTION_ASM_OP
5450 dtors_section = get_unnamed_section (0, output_section_asm_op,
5451 DTORS_SECTION_ASM_OP);
5454 #ifdef BSS_SECTION_ASM_OP
5455 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5456 output_section_asm_op,
5457 BSS_SECTION_ASM_OP);
5460 #ifdef SBSS_SECTION_ASM_OP
5461 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5462 output_section_asm_op,
5463 SBSS_SECTION_ASM_OP);
5466 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5467 | SECTION_COMMON, emit_tls_common);
5468 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5469 | SECTION_COMMON, emit_local);
5470 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5471 | SECTION_COMMON, emit_common);
5473 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5474 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
5478 targetm.asm_out.init_sections ();
5480 if (readonly_data_section == NULL)
5481 readonly_data_section = text_section;
5485 decl_default_tls_model (tree decl)
5487 enum tls_model kind;
5490 is_local = targetm.binds_local_p (decl);
5494 kind = TLS_MODEL_LOCAL_EXEC;
5496 kind = TLS_MODEL_INITIAL_EXEC;
5499 /* Local dynamic is inefficient when we're not combining the
5500 parts of the address. */
5501 else if (optimize && is_local)
5502 kind = TLS_MODEL_LOCAL_DYNAMIC;
5504 kind = TLS_MODEL_GLOBAL_DYNAMIC;
5505 if (kind < flag_tls_default)
5506 kind = flag_tls_default;
5511 /* Select a set of attributes for section NAME based on the properties
5512 of DECL and whether or not RELOC indicates that DECL's initializer
5513 might contain runtime relocations.
5515 We make the section read-only and executable for a function decl,
5516 read-only for a const data decl, and writable for a non-const data decl. */
5519 default_section_type_flags (tree decl, const char *name, int reloc)
5521 return default_section_type_flags_1 (decl, name, reloc, flag_pic);
5525 default_section_type_flags_1 (tree decl, const char *name, int reloc,
5530 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5531 flags = SECTION_CODE;
5532 else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
5534 else if (current_function_decl
5536 && cfun->unlikely_text_section_name
5537 && strcmp (name, cfun->unlikely_text_section_name) == 0)
5538 flags = SECTION_CODE;
5540 && (!current_function_decl || !cfun)
5541 && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
5542 flags = SECTION_CODE;
5544 flags = SECTION_WRITE;
5546 if (decl && DECL_ONE_ONLY (decl))
5547 flags |= SECTION_LINKONCE;
5549 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
5550 flags |= SECTION_TLS | SECTION_WRITE;
5552 if (strcmp (name, ".bss") == 0
5553 || strncmp (name, ".bss.", 5) == 0
5554 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5555 || strcmp (name, ".sbss") == 0
5556 || strncmp (name, ".sbss.", 6) == 0
5557 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5558 flags |= SECTION_BSS;
5560 if (strcmp (name, ".tdata") == 0
5561 || strncmp (name, ".tdata.", 7) == 0
5562 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
5563 flags |= SECTION_TLS;
5565 if (strcmp (name, ".tbss") == 0
5566 || strncmp (name, ".tbss.", 6) == 0
5567 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
5568 flags |= SECTION_TLS | SECTION_BSS;
5570 /* These three sections have special ELF types. They are neither
5571 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
5572 want to print a section type (@progbits or @nobits). If someone
5573 is silly enough to emit code or TLS variables to one of these
5574 sections, then don't handle them specially. */
5575 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
5576 && (strcmp (name, ".init_array") == 0
5577 || strcmp (name, ".fini_array") == 0
5578 || strcmp (name, ".preinit_array") == 0))
5579 flags |= SECTION_NOTYPE;
5584 /* Return true if the target supports some form of global BSS,
5585 either through bss_noswitch_section, or by selecting a BSS
5586 section in TARGET_ASM_SELECT_SECTION. */
5589 have_global_bss_p (void)
5591 return bss_noswitch_section || targetm.have_switchable_bss_sections;
5594 /* Output assembly to switch to section NAME with attribute FLAGS.
5595 Four variants for common object file formats. */
5598 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
5599 unsigned int flags ATTRIBUTE_UNUSED,
5600 tree decl ATTRIBUTE_UNUSED)
5602 /* Some object formats don't support named sections at all. The
5603 front-end should already have flagged this as an error. */
5608 default_elf_asm_named_section (const char *name, unsigned int flags,
5609 tree decl ATTRIBUTE_UNUSED)
5611 char flagchars[10], *f = flagchars;
5613 /* If we have already declared this section, we can use an
5614 abbreviated form to switch back to it -- unless this section is
5615 part of a COMDAT groups, in which case GAS requires the full
5616 declaration every time. */
5617 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5618 && (flags & SECTION_DECLARED))
5620 fprintf (asm_out_file, "\t.section\t%s\n", name);
5624 if (!(flags & SECTION_DEBUG))
5626 if (flags & SECTION_WRITE)
5628 if (flags & SECTION_CODE)
5630 if (flags & SECTION_SMALL)
5632 if (flags & SECTION_MERGE)
5634 if (flags & SECTION_STRINGS)
5636 if (flags & SECTION_TLS)
5638 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5642 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
5644 if (!(flags & SECTION_NOTYPE))
5649 if (flags & SECTION_BSS)
5655 #ifdef ASM_COMMENT_START
5656 /* On platforms that use "@" as the assembly comment character,
5658 if (strcmp (ASM_COMMENT_START, "@") == 0)
5661 fprintf (asm_out_file, format, type);
5663 if (flags & SECTION_ENTSIZE)
5664 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
5665 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5666 fprintf (asm_out_file, ",%s,comdat",
5667 lang_hooks.decls.comdat_group (decl));
5670 putc ('\n', asm_out_file);
5674 default_coff_asm_named_section (const char *name, unsigned int flags,
5675 tree decl ATTRIBUTE_UNUSED)
5677 char flagchars[8], *f = flagchars;
5679 if (flags & SECTION_WRITE)
5681 if (flags & SECTION_CODE)
5685 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5689 default_pe_asm_named_section (const char *name, unsigned int flags,
5692 default_coff_asm_named_section (name, flags, decl);
5694 if (flags & SECTION_LINKONCE)
5696 /* Functions may have been compiled at various levels of
5697 optimization so we can't use `same_size' here.
5698 Instead, have the linker pick one. */
5699 fprintf (asm_out_file, "\t.linkonce %s\n",
5700 (flags & SECTION_CODE ? "discard" : "same_size"));
5704 /* The lame default section selector. */
5707 default_select_section (tree decl, int reloc,
5708 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5712 if (decl_readonly_section (decl, reloc))
5713 return readonly_data_section;
5715 else if (TREE_CODE (decl) == CONSTRUCTOR)
5717 if (! ((flag_pic && reloc)
5718 || !TREE_READONLY (decl)
5719 || TREE_SIDE_EFFECTS (decl)
5720 || !TREE_CONSTANT (decl)))
5721 return readonly_data_section;
5723 else if (TREE_CODE (decl) == STRING_CST)
5724 return readonly_data_section;
5725 else if (! (flag_pic && reloc))
5726 return readonly_data_section;
5728 return data_section;
5731 enum section_category
5732 categorize_decl_for_section (tree decl, int reloc, int shlib)
5734 enum section_category ret;
5736 if (TREE_CODE (decl) == FUNCTION_DECL)
5738 else if (TREE_CODE (decl) == STRING_CST)
5740 if (flag_mudflap) /* or !flag_merge_constants */
5741 return SECCAT_RODATA;
5743 return SECCAT_RODATA_MERGE_STR;
5745 else if (TREE_CODE (decl) == VAR_DECL)
5747 if (bss_initializer_p (decl))
5749 else if (! TREE_READONLY (decl)
5750 || TREE_SIDE_EFFECTS (decl)
5751 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
5753 if (shlib && (reloc & 2))
5754 ret = SECCAT_DATA_REL;
5755 else if (shlib && reloc)
5756 ret = SECCAT_DATA_REL_LOCAL;
5760 else if (shlib && (reloc & 2))
5761 ret = SECCAT_DATA_REL_RO;
5762 else if (shlib && reloc)
5763 ret = SECCAT_DATA_REL_RO_LOCAL;
5764 else if (reloc || flag_merge_constants < 2)
5765 /* C and C++ don't allow different variables to share the same
5766 location. -fmerge-all-constants allows even that (at the
5767 expense of not conforming). */
5768 ret = SECCAT_RODATA;
5769 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
5770 ret = SECCAT_RODATA_MERGE_STR_INIT;
5772 ret = SECCAT_RODATA_MERGE_CONST;
5774 else if (TREE_CODE (decl) == CONSTRUCTOR)
5776 if ((shlib && reloc)
5777 || TREE_SIDE_EFFECTS (decl)
5778 || ! TREE_CONSTANT (decl))
5781 ret = SECCAT_RODATA;
5784 ret = SECCAT_RODATA;
5786 /* There are no read-only thread-local sections. */
5787 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
5789 /* Note that this would be *just* SECCAT_BSS, except that there's
5790 no concept of a read-only thread-local-data section. */
5791 if (ret == SECCAT_BSS
5792 || (flag_zero_initialized_in_bss
5793 && initializer_zerop (DECL_INITIAL (decl))))
5799 /* If the target uses small data sections, select it. */
5800 else if (targetm.in_small_data_p (decl))
5802 if (ret == SECCAT_BSS)
5804 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
5805 ret = SECCAT_SRODATA;
5814 decl_readonly_section (tree decl, int reloc)
5816 return decl_readonly_section_1 (decl, reloc, flag_pic);
5820 decl_readonly_section_1 (tree decl, int reloc, int shlib)
5822 switch (categorize_decl_for_section (decl, reloc, shlib))
5825 case SECCAT_RODATA_MERGE_STR:
5826 case SECCAT_RODATA_MERGE_STR_INIT:
5827 case SECCAT_RODATA_MERGE_CONST:
5828 case SECCAT_SRODATA:
5837 /* Select a section based on the above categorization. */
5840 default_elf_select_section (tree decl, int reloc,
5841 unsigned HOST_WIDE_INT align)
5843 return default_elf_select_section_1 (decl, reloc, align, flag_pic);
5847 default_elf_select_section_1 (tree decl, int reloc,
5848 unsigned HOST_WIDE_INT align, int shlib)
5851 switch (categorize_decl_for_section (decl, reloc, shlib))
5854 /* We're not supposed to be called on FUNCTION_DECLs. */
5857 return readonly_data_section;
5858 case SECCAT_RODATA_MERGE_STR:
5859 return mergeable_string_section (decl, align, 0);
5860 case SECCAT_RODATA_MERGE_STR_INIT:
5861 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
5862 case SECCAT_RODATA_MERGE_CONST:
5863 return mergeable_constant_section (DECL_MODE (decl), align, 0);
5864 case SECCAT_SRODATA:
5868 return data_section;
5869 case SECCAT_DATA_REL:
5870 sname = ".data.rel";
5872 case SECCAT_DATA_REL_LOCAL:
5873 sname = ".data.rel.local";
5875 case SECCAT_DATA_REL_RO:
5876 sname = ".data.rel.ro";
5878 case SECCAT_DATA_REL_RO_LOCAL:
5879 sname = ".data.rel.ro.local";
5904 return get_named_section (decl, sname, reloc);
5907 /* Construct a unique section name based on the decl name and the
5908 categorization performed above. */
5911 default_unique_section (tree decl, int reloc)
5913 default_unique_section_1 (decl, reloc, flag_pic);
5917 default_unique_section_1 (tree decl, int reloc, int shlib)
5919 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
5920 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
5921 const char *prefix, *name;
5925 switch (categorize_decl_for_section (decl, reloc, shlib))
5928 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
5931 case SECCAT_RODATA_MERGE_STR:
5932 case SECCAT_RODATA_MERGE_STR_INIT:
5933 case SECCAT_RODATA_MERGE_CONST:
5934 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
5936 case SECCAT_SRODATA:
5937 prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
5940 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
5942 case SECCAT_DATA_REL:
5943 prefix = one_only ? ".gnu.linkonce.d.rel." : ".data.rel.";
5945 case SECCAT_DATA_REL_LOCAL:
5946 prefix = one_only ? ".gnu.linkonce.d.rel.local." : ".data.rel.local.";
5948 case SECCAT_DATA_REL_RO:
5949 prefix = one_only ? ".gnu.linkonce.d.rel.ro." : ".data.rel.ro.";
5951 case SECCAT_DATA_REL_RO_LOCAL:
5952 prefix = one_only ? ".gnu.linkonce.d.rel.ro.local."
5953 : ".data.rel.ro.local.";
5956 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
5959 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
5962 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
5965 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
5968 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
5973 plen = strlen (prefix);
5975 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5976 name = targetm.strip_name_encoding (name);
5977 nlen = strlen (name);
5979 string = alloca (nlen + plen + 1);
5980 memcpy (string, prefix, plen);
5981 memcpy (string + plen, name, nlen + 1);
5983 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
5987 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
5989 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5992 switch (GET_CODE (x))
5997 return data_section;
6003 return readonly_data_section;
6007 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6008 unsigned HOST_WIDE_INT align)
6010 /* ??? Handle small data here somehow. */
6013 switch (GET_CODE (x))
6017 return get_named_section (NULL, ".data.rel.ro", 3);
6020 return get_named_section (NULL, ".data.rel.ro.local", 1);
6026 return mergeable_constant_section (mode, align, 0);
6029 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6032 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6037 /* Careful not to prod global register variables. */
6040 symbol = XEXP (rtl, 0);
6041 if (GET_CODE (symbol) != SYMBOL_REF)
6044 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6045 if (TREE_CODE (decl) == FUNCTION_DECL)
6046 flags |= SYMBOL_FLAG_FUNCTION;
6047 if (targetm.binds_local_p (decl))
6048 flags |= SYMBOL_FLAG_LOCAL;
6049 if (targetm.have_tls && TREE_CODE (decl) == VAR_DECL
6050 && DECL_THREAD_LOCAL_P (decl))
6051 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6052 else if (targetm.in_small_data_p (decl))
6053 flags |= SYMBOL_FLAG_SMALL;
6054 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6055 being PUBLIC, the thing *must* be defined in this translation unit.
6056 Prevent this buglet from being propagated into rtl code as well. */
6057 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6058 flags |= SYMBOL_FLAG_EXTERNAL;
6060 SYMBOL_REF_FLAGS (symbol) = flags;
6063 /* By default, we do nothing for encode_section_info, so we need not
6064 do anything but discard the '*' marker. */
6067 default_strip_name_encoding (const char *str)
6069 return str + (*str == '*');
6072 #ifdef ASM_OUTPUT_DEF
6073 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6074 anchor relative to ".", the current section position. */
6077 default_asm_output_anchor (rtx symbol)
6081 sprintf (buffer, ". + " HOST_WIDE_INT_PRINT_DEC,
6082 SYMBOL_REF_BLOCK_OFFSET (symbol));
6083 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6087 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6090 default_use_anchors_for_symbol_p (rtx symbol)
6095 /* Don't use anchors for mergeable sections. The linker might move
6096 the objects around. */
6097 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6098 if (sect->common.flags & SECTION_MERGE)
6101 /* Don't use anchors for small data sections. The small data register
6102 acts as an anchor for such sections. */
6103 if (sect->common.flags & SECTION_SMALL)
6106 decl = SYMBOL_REF_DECL (symbol);
6107 if (decl && DECL_P (decl))
6109 /* Don't use section anchors for decls that might be defined by
6111 if (!targetm.binds_local_p (decl))
6114 /* Don't use section anchors for decls that will be placed in a
6115 small data section. */
6116 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6117 one above. The problem is that we only use SECTION_SMALL for
6118 sections that should be marked as small in the section directive. */
6119 if (targetm.in_small_data_p (decl))
6125 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6126 wrt cross-module name binding. */
6129 default_binds_local_p (tree exp)
6131 return default_binds_local_p_1 (exp, flag_shlib);
6135 default_binds_local_p_1 (tree exp, int shlib)
6139 /* A non-decl is an entry in the constant pool. */
6142 /* Weakrefs may not bind locally, even though the weakref itself is
6143 always static and therefore local. */
6144 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6146 /* Static variables are always local. */
6147 else if (! TREE_PUBLIC (exp))
6149 /* A variable is local if the user has said explicitly that it will
6151 else if (DECL_VISIBILITY_SPECIFIED (exp)
6152 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6154 /* Variables defined outside this object might not be local. */
6155 else if (DECL_EXTERNAL (exp))
6157 /* If defined in this object and visibility is not default, must be
6159 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6161 /* Default visibility weak data can be overridden by a strong symbol
6162 in another module and so are not local. */
6163 else if (DECL_WEAK (exp))
6165 /* If PIC, then assume that any global name can be overridden by
6166 symbols resolved from other modules. */
6169 /* Uninitialized COMMON variable may be unified with symbols
6170 resolved from other modules. */
6171 else if (DECL_COMMON (exp)
6172 && (DECL_INITIAL (exp) == NULL
6173 || DECL_INITIAL (exp) == error_mark_node))
6175 /* Otherwise we're left with initialized (or non-common) global data
6176 which is of necessity defined locally. */
6183 /* Determine whether or not a pointer mode is valid. Assume defaults
6184 of ptr_mode or Pmode - can be overridden. */
6186 default_valid_pointer_mode (enum machine_mode mode)
6188 return (mode == ptr_mode || mode == Pmode);
6191 /* Default function to output code that will globalize a label. A
6192 target must define GLOBAL_ASM_OP or provide its own function to
6193 globalize a label. */
6194 #ifdef GLOBAL_ASM_OP
6196 default_globalize_label (FILE * stream, const char *name)
6198 fputs (GLOBAL_ASM_OP, stream);
6199 assemble_name (stream, name);
6200 putc ('\n', stream);
6202 #endif /* GLOBAL_ASM_OP */
6204 /* Default function to output a label for unwind information. The
6205 default is to do nothing. A target that needs nonlocal labels for
6206 unwind information must provide its own function to do this. */
6208 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6209 tree decl ATTRIBUTE_UNUSED,
6210 int for_eh ATTRIBUTE_UNUSED,
6211 int empty ATTRIBUTE_UNUSED)
6215 /* Default function to output a label to divide up the exception table.
6216 The default is to do nothing. A target that needs/wants to divide
6217 up the table must provide it's own function to do this. */
6219 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6223 /* This is how to output an internal numbered label where PREFIX is
6224 the class of label and LABELNO is the number within the class. */
6227 default_internal_label (FILE *stream, const char *prefix,
6228 unsigned long labelno)
6230 char *const buf = alloca (40 + strlen (prefix));
6231 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6232 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6235 /* This is the default behavior at the beginning of a file. It's
6236 controlled by two other target-hook toggles. */
6238 default_file_start (void)
6240 if (targetm.file_start_app_off && !flag_verbose_asm)
6241 fputs (ASM_APP_OFF, asm_out_file);
6243 if (targetm.file_start_file_directive)
6244 output_file_directive (asm_out_file, main_input_filename);
6247 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6248 which emits a special section directive used to indicate whether or
6249 not this object file needs an executable stack. This is primarily
6250 a GNU extension to ELF but could be used on other targets. */
6252 int trampolines_created;
6255 file_end_indicate_exec_stack (void)
6257 unsigned int flags = SECTION_DEBUG;
6258 if (trampolines_created)
6259 flags |= SECTION_CODE;
6261 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
6264 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6265 a get_unnamed_section callback. */
6268 output_section_asm_op (const void *directive)
6270 fprintf (asm_out_file, "%s\n", (const char *) directive);
6273 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6274 the current section is NEW_SECTION. */
6277 switch_to_section (section *new_section)
6279 if (in_section == new_section)
6282 if (new_section->common.flags & SECTION_FORGET)
6285 in_section = new_section;
6287 switch (SECTION_STYLE (new_section))
6291 && !cfun->unlikely_text_section_name
6292 && strcmp (new_section->named.name,
6293 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6294 cfun->unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6296 targetm.asm_out.named_section (new_section->named.name,
6297 new_section->named.common.flags,
6298 new_section->named.decl);
6301 case SECTION_UNNAMED:
6302 new_section->unnamed.callback (new_section->unnamed.data);
6305 case SECTION_NOSWITCH:
6310 new_section->common.flags |= SECTION_DECLARED;
6313 /* If block symbol SYMBOL has not yet been assigned an offset, place
6314 it at the end of its block. */
6317 place_block_symbol (rtx symbol)
6319 unsigned HOST_WIDE_INT size, mask, offset;
6320 struct constant_descriptor_rtx *desc;
6321 unsigned int alignment;
6322 struct object_block *block;
6325 gcc_assert (SYMBOL_REF_BLOCK (symbol));
6326 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6329 /* Work out the symbol's size and alignment. */
6330 if (CONSTANT_POOL_ADDRESS_P (symbol))
6332 desc = SYMBOL_REF_CONSTANT (symbol);
6333 alignment = desc->align;
6334 size = GET_MODE_SIZE (desc->mode);
6336 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6338 decl = SYMBOL_REF_DECL (symbol);
6339 alignment = get_constant_alignment (decl);
6340 size = get_constant_size (decl);
6344 decl = SYMBOL_REF_DECL (symbol);
6345 alignment = DECL_ALIGN (decl);
6346 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6349 /* Calculate the object's offset from the start of the block. */
6350 block = SYMBOL_REF_BLOCK (symbol);
6351 mask = alignment / BITS_PER_UNIT - 1;
6352 offset = (block->size + mask) & ~mask;
6353 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
6355 /* Record the block's new alignment and size. */
6356 block->alignment = MAX (block->alignment, alignment);
6357 block->size = offset + size;
6359 VEC_safe_push (rtx, gc, block->objects, symbol);
6362 /* Return the anchor that should be used to address byte offset OFFSET
6363 from the first object in BLOCK. MODEL is the TLS model used
6367 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
6368 enum tls_model model)
6371 unsigned int begin, middle, end;
6372 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
6375 /* Work out the anchor's offset. Use an offset of 0 for the first
6376 anchor so that we don't pessimize the case where we take the address
6377 of a variable at the beginning of the block. This is particularly
6378 useful when a block has only one variable assigned to it.
6380 We try to place anchors RANGE bytes apart, so there can then be
6381 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6382 a ptr_mode offset. With some target settings, the lowest such
6383 anchor might be out of range for the lowest ptr_mode offset;
6384 likewise the highest anchor for the highest offset. Use anchors
6385 at the extreme ends of the ptr_mode range in such cases.
6387 All arithmetic uses unsigned integers in order to avoid
6389 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
6390 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
6391 range = max_offset - min_offset + 1;
6396 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
6399 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
6400 delta -= delta % range;
6403 offset = (HOST_WIDE_INT) (-delta);
6407 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
6408 delta -= delta % range;
6409 if (delta > bias - 1)
6411 offset = (HOST_WIDE_INT) delta;
6415 /* Do a binary search to see if there's already an anchor we can use.
6416 Set BEGIN to the new anchor's index if not. */
6418 end = VEC_length (rtx, block->anchors);
6419 while (begin != end)
6421 middle = (end + begin) / 2;
6422 anchor = VEC_index (rtx, block->anchors, middle);
6423 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
6425 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
6427 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
6429 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
6435 /* Create a new anchor with a unique label. */
6436 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
6437 anchor = create_block_symbol (ggc_strdup (label), block, offset);
6438 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
6439 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
6441 /* Insert it at index BEGIN. */
6442 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
6446 /* Output the objects in BLOCK. */
6449 output_object_block (struct object_block *block)
6451 struct constant_descriptor_rtx *desc;
6453 HOST_WIDE_INT offset;
6457 if (block->objects == NULL)
6460 /* Switch to the section and make sure that the first byte is
6461 suitably aligned. */
6462 switch_to_section (block->sect);
6463 assemble_align (block->alignment);
6465 /* Define the values of all anchors relative to the current section
6467 for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
6468 targetm.asm_out.output_anchor (symbol);
6470 /* Output the objects themselves. */
6472 for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
6474 /* Move to the object's offset, padding with zeros if necessary. */
6475 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
6476 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
6477 if (CONSTANT_POOL_ADDRESS_P (symbol))
6479 desc = SYMBOL_REF_CONSTANT (symbol);
6480 output_constant_pool_1 (desc, 1);
6481 offset += GET_MODE_SIZE (desc->mode);
6483 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6485 decl = SYMBOL_REF_DECL (symbol);
6486 assemble_constant_contents (decl, XSTR (symbol, 0),
6487 get_constant_alignment (decl));
6488 offset += get_constant_size (decl);
6492 decl = SYMBOL_REF_DECL (symbol);
6493 assemble_variable_contents (decl, XSTR (symbol, 0), false);
6494 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6499 /* A htab_traverse callback used to call output_object_block for
6500 each member of object_block_htab. */
6503 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
6505 output_object_block ((struct object_block *) (*slot));
6509 /* Output the definitions of all object_blocks. */
6512 output_object_blocks (void)
6514 htab_traverse (object_block_htab, output_object_block_htab, NULL);
6517 #include "gt-varasm.h"