1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
46 #include "langhooks.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h" /* Needed for external data
59 declarations for e.g. AIX 4.x. */
62 /* The (assembler) name of the first globally-visible object output. */
63 extern GTY(()) const char *first_global_object_name;
64 extern GTY(()) const char *weak_global_object_name;
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
70 struct constant_descriptor_rtx;
71 struct rtx_constant_pool;
73 #define n_deferred_constants (crtl->varasm.deferred_constants)
75 /* Number for making the label on the next
76 constant that is stored in memory. */
78 static GTY(()) int const_labelno;
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81 to ASM_FINISH_DECLARE_OBJECT. */
83 int size_directive_output;
85 /* The last decl for which assemble_variable was called,
86 if it did ASM_DECLARE_OBJECT_NAME.
87 If the last call to assemble_variable didn't do that,
90 tree last_assemble_variable_decl;
92 /* The following global variable indicates if the first basic block
93 in a function belongs to the cold partition or not. */
95 bool first_function_block_is_cold;
97 /* We give all constants their own alias set. Perhaps redundant with
98 MEM_READONLY_P, but pre-dates it. */
100 static alias_set_type const_alias_set;
102 static const char *strip_reg_name (const char *);
103 static int contains_pointers_p (tree);
104 #ifdef ASM_OUTPUT_EXTERNAL
105 static bool incorporeal_function_p (tree);
107 static void decode_addr_const (tree, struct addr_const *);
108 static hashval_t const_desc_hash (const void *);
109 static int const_desc_eq (const void *, const void *);
110 static hashval_t const_hash_1 (const tree);
111 static int compare_constant (const tree, const tree);
112 static tree copy_constant (tree);
113 static void output_constant_def_contents (rtx);
114 static void output_addressed_constants (tree);
115 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
116 static unsigned min_align (unsigned, unsigned);
117 static void globalize_decl (tree);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_BSS
120 static void asm_output_bss (FILE *, tree, const char *,
121 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
123 #ifdef ASM_OUTPUT_ALIGNED_BSS
124 static void asm_output_aligned_bss (FILE *, tree, const char *,
125 unsigned HOST_WIDE_INT, int)
128 #endif /* BSS_SECTION_ASM_OP */
129 static void mark_weak (tree);
130 static void output_constant_pool (const char *, tree);
132 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
133 section *text_section;
134 section *data_section;
135 section *readonly_data_section;
136 section *sdata_section;
137 section *ctors_section;
138 section *dtors_section;
139 section *bss_section;
140 section *sbss_section;
142 /* Various forms of common section. All are guaranteed to be nonnull. */
143 section *tls_comm_section;
144 section *comm_section;
145 section *lcomm_section;
147 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
149 section *bss_noswitch_section;
151 /* The section that holds the main exception table, when known. The section
152 is set either by the target's init_sections hook or by the first call to
153 switch_to_exception_section. */
154 section *exception_section;
156 /* The section that holds the DWARF2 frame unwind information, when known.
157 The section is set either by the target's init_sections hook or by the
158 first call to switch_to_eh_frame_section. */
159 section *eh_frame_section;
161 /* asm_out_file's current section. This is NULL if no section has yet
162 been selected or if we lose track of what the current section is. */
165 /* True if code for the current function is currently being directed
166 at the cold section. */
167 bool in_cold_section_p;
169 /* A linked list of all the unnamed sections. */
170 static GTY(()) section *unnamed_sections;
172 /* Return a nonzero value if DECL has a section attribute. */
173 #define IN_NAMED_SECTION(DECL) \
174 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
175 && DECL_SECTION_NAME (DECL) != NULL_TREE)
177 /* Hash table of named sections. */
178 static GTY((param_is (section))) htab_t section_htab;
180 /* A table of object_blocks, indexed by section. */
181 static GTY((param_is (struct object_block))) htab_t object_block_htab;
183 /* The next number to use for internal anchor labels. */
184 static GTY(()) int anchor_labelno;
186 /* A pool of constants that can be shared between functions. */
187 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
193 static GTY (()) tree emutls_object_type;
194 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
195 macro can be used on them to distinguish the control variable from
196 the initialization template. */
197 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
199 #if !defined (NO_DOT_IN_LABEL)
200 # define EMUTLS_SEPARATOR "."
201 #elif !defined (NO_DOLLAR_IN_LABEL)
202 # define EMUTLS_SEPARATOR "$"
204 # define EMUTLS_SEPARATOR "_"
207 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
208 IDENTIFIER_NODE NAME's name. */
211 prefix_name (const char *prefix, tree name)
213 unsigned plen = strlen (prefix);
214 unsigned nlen = strlen (IDENTIFIER_POINTER (name));
215 char *toname = (char *) alloca (plen + nlen + 1);
217 memcpy (toname, prefix, plen);
218 memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
220 return get_identifier (toname);
223 /* Create an identifier for the struct __emutls_object, given an identifier
224 of the DECL_ASSEMBLY_NAME of the original object. */
227 get_emutls_object_name (tree name)
229 const char *prefix = (targetm.emutls.var_prefix
230 ? targetm.emutls.var_prefix
231 : "__emutls_v" EMUTLS_SEPARATOR);
232 return prefix_name (prefix, name);
236 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
238 tree word_type_node, field, next_field;
240 field = build_decl (UNKNOWN_LOCATION,
241 FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
242 DECL_CONTEXT (field) = type;
245 field = build_decl (UNKNOWN_LOCATION,
246 FIELD_DECL, get_identifier ("__offset"),
248 DECL_CONTEXT (field) = type;
249 TREE_CHAIN (field) = next_field;
252 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
253 field = build_decl (UNKNOWN_LOCATION,
254 FIELD_DECL, get_identifier ("__align"),
256 DECL_CONTEXT (field) = type;
257 TREE_CHAIN (field) = next_field;
260 field = build_decl (UNKNOWN_LOCATION,
261 FIELD_DECL, get_identifier ("__size"), word_type_node);
262 DECL_CONTEXT (field) = type;
263 TREE_CHAIN (field) = next_field;
268 /* Create the structure for struct __emutls_object. This should match the
269 structure at the top of emutls.c, modulo the union there. */
272 get_emutls_object_type (void)
274 tree type, type_name, field;
276 type = emutls_object_type;
280 emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
282 field = targetm.emutls.var_fields (type, &type_name);
284 type_name = get_identifier ("__emutls_object");
285 type_name = build_decl (UNKNOWN_LOCATION,
286 TYPE_DECL, type_name, type);
287 TYPE_NAME (type) = type_name;
288 TYPE_FIELDS (type) = field;
294 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
295 This will be used for initializing the emulated tls data area. */
298 get_emutls_init_templ_addr (tree decl)
302 if (targetm.emutls.register_common && !DECL_INITIAL (decl)
303 && !DECL_SECTION_NAME (decl))
304 return null_pointer_node;
306 name = DECL_ASSEMBLER_NAME (decl);
307 if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0])
309 const char *prefix = (targetm.emutls.tmpl_prefix
310 ? targetm.emutls.tmpl_prefix
311 : "__emutls_t" EMUTLS_SEPARATOR);
312 name = prefix_name (prefix, name);
315 to = build_decl (DECL_SOURCE_LOCATION (decl),
316 VAR_DECL, name, TREE_TYPE (decl));
317 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
318 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
319 DECL_ARTIFICIAL (to) = 1;
320 TREE_USED (to) = TREE_USED (decl);
321 TREE_READONLY (to) = 1;
322 DECL_IGNORED_P (to) = 1;
323 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
324 DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
326 DECL_WEAK (to) = DECL_WEAK (decl);
327 if (DECL_ONE_ONLY (decl))
329 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
330 TREE_STATIC (to) = TREE_STATIC (decl);
331 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
332 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
335 TREE_STATIC (to) = 1;
337 DECL_INITIAL (to) = DECL_INITIAL (decl);
338 DECL_INITIAL (decl) = NULL;
340 varpool_finalize_decl (to);
341 return build_fold_addr_expr (to);
344 /* When emulating tls, we use a control structure for use by the runtime.
345 Create and return this structure. */
348 emutls_decl (tree decl)
351 struct tree_map *h, in;
354 if (targetm.have_tls || decl == NULL || decl == error_mark_node
355 || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
358 /* Look up the object in the hash; return the control structure if
359 it has already been created. */
361 emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
363 name = DECL_ASSEMBLER_NAME (decl);
365 /* Note that we use the hash of the decl's name, rather than a hash
366 of the decl's pointer. In emutls_finish we iterate through the
367 hash table, and we want this traversal to be predictable. */
368 in.hash = htab_hash_string (IDENTIFIER_POINTER (name));
370 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
371 h = (struct tree_map *) *loc;
376 to = build_decl (DECL_SOURCE_LOCATION (decl),
377 VAR_DECL, get_emutls_object_name (name),
378 get_emutls_object_type ());
380 h = GGC_NEW (struct tree_map);
384 *(struct tree_map **) loc = h;
386 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
387 DECL_ARTIFICIAL (to) = 1;
388 DECL_IGNORED_P (to) = 1;
389 TREE_READONLY (to) = 0;
390 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
391 if (DECL_ONE_ONLY (decl))
392 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
393 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
394 if (targetm.emutls.var_align_fixed)
395 /* If we're not allowed to change the proxy object's
396 alignment, pretend it's been set by the user. */
397 DECL_USER_ALIGN (to) = 1;
400 /* Note that these fields may need to be updated from time to time from
401 the original decl. Consider:
402 extern __thread int i;
403 int foo() { return i; }
405 in which I goes from external to locally defined and initialized. */
407 TREE_STATIC (to) = TREE_STATIC (decl);
408 TREE_USED (to) = TREE_USED (decl);
409 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
410 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
411 DECL_COMMON (to) = DECL_COMMON (decl);
412 DECL_WEAK (to) = DECL_WEAK (decl);
413 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
419 emutls_common_1 (void **loc, void *xstmts)
421 struct tree_map *h = *(struct tree_map **) loc;
422 tree args, x, *pstmts = (tree *) xstmts;
425 if (! DECL_COMMON (h->base.from)
426 || (DECL_INITIAL (h->base.from)
427 && DECL_INITIAL (h->base.from) != error_mark_node))
430 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
432 /* The idea was to call get_emutls_init_templ_addr here, but if we
433 do this and there is an initializer, -fanchor_section loses,
434 because it would be too late to ensure the template is
436 x = null_pointer_node;
437 args = tree_cons (NULL, x, NULL);
438 x = build_int_cst (word_type_node, DECL_ALIGN_UNIT (h->base.from));
439 args = tree_cons (NULL, x, args);
440 x = fold_convert (word_type_node, DECL_SIZE_UNIT (h->base.from));
441 args = tree_cons (NULL, x, args);
442 x = build_fold_addr_expr (h->to);
443 args = tree_cons (NULL, x, args);
445 x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
446 x = build_function_call_expr (UNKNOWN_LOCATION, x, args);
448 append_to_statement_list (x, pstmts);
455 if (targetm.emutls.register_common)
457 tree body = NULL_TREE;
459 if (emutls_htab == NULL)
462 htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
463 if (body == NULL_TREE)
466 cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
470 /* Helper routines for maintaining section_htab. */
473 section_entry_eq (const void *p1, const void *p2)
475 const section *old = (const section *) p1;
476 const char *new_name = (const char *) p2;
478 return strcmp (old->named.name, new_name) == 0;
482 section_entry_hash (const void *p)
484 const section *old = (const section *) p;
485 return htab_hash_string (old->named.name);
488 /* Return a hash value for section SECT. */
491 hash_section (section *sect)
493 if (sect->common.flags & SECTION_NAMED)
494 return htab_hash_string (sect->named.name);
495 return sect->common.flags;
498 /* Helper routines for maintaining object_block_htab. */
501 object_block_entry_eq (const void *p1, const void *p2)
503 const struct object_block *old = (const struct object_block *) p1;
504 const section *new_section = (const section *) p2;
506 return old->sect == new_section;
510 object_block_entry_hash (const void *p)
512 const struct object_block *old = (const struct object_block *) p;
513 return hash_section (old->sect);
516 /* Return a new unnamed section with the given fields. */
519 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
524 sect = GGC_NEW (section);
525 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
526 sect->unnamed.callback = callback;
527 sect->unnamed.data = data;
528 sect->unnamed.next = unnamed_sections;
530 unnamed_sections = sect;
534 /* Return a SECTION_NOSWITCH section with the given fields. */
537 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
541 sect = GGC_NEW (section);
542 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
543 sect->noswitch.callback = callback;
548 /* Return the named section structure associated with NAME. Create
549 a new section with the given fields if no such structure exists. */
552 get_section (const char *name, unsigned int flags, tree decl)
554 section *sect, **slot;
557 htab_find_slot_with_hash (section_htab, name,
558 htab_hash_string (name), INSERT);
559 flags |= SECTION_NAMED;
562 sect = GGC_NEW (section);
563 sect->named.common.flags = flags;
564 sect->named.name = ggc_strdup (name);
565 sect->named.decl = decl;
571 if ((sect->common.flags & ~SECTION_DECLARED) != flags
572 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
574 /* Sanity check user variables for flag changes. */
576 decl = sect->named.decl;
578 error ("%+D causes a section type conflict", decl);
584 /* Return true if the current compilation mode benefits from having
585 objects grouped into blocks. */
588 use_object_blocks_p (void)
590 return flag_section_anchors;
593 /* Return the object_block structure for section SECT. Create a new
594 structure if we haven't created one already. Return null if SECT
597 static struct object_block *
598 get_block_for_section (section *sect)
600 struct object_block *block;
606 slot = htab_find_slot_with_hash (object_block_htab, sect,
607 hash_section (sect), INSERT);
608 block = (struct object_block *) *slot;
611 block = (struct object_block *)
612 ggc_alloc_cleared (sizeof (struct object_block));
619 /* Create a symbol with label LABEL and place it at byte offset
620 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
621 is not yet known. LABEL must be a garbage-collected string. */
624 create_block_symbol (const char *label, struct object_block *block,
625 HOST_WIDE_INT offset)
630 /* Create the extended SYMBOL_REF. */
631 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
632 symbol = (rtx) ggc_alloc_zone (size, &rtl_zone);
634 /* Initialize the normal SYMBOL_REF fields. */
635 memset (symbol, 0, size);
636 PUT_CODE (symbol, SYMBOL_REF);
637 PUT_MODE (symbol, Pmode);
638 XSTR (symbol, 0) = label;
639 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
641 /* Initialize the block_symbol stuff. */
642 SYMBOL_REF_BLOCK (symbol) = block;
643 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
649 initialize_cold_section_name (void)
651 const char *stripped_name;
655 gcc_assert (cfun && current_function_decl);
656 if (crtl->subsections.unlikely_text_section_name)
659 dsn = DECL_SECTION_NAME (current_function_decl);
660 if (flag_function_sections && dsn)
662 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
663 memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
665 stripped_name = targetm.strip_name_encoding (name);
667 buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
668 crtl->subsections.unlikely_text_section_name = ggc_strdup (buffer);
671 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
674 /* Tell assembler to switch to unlikely-to-be-executed text section. */
677 unlikely_text_section (void)
681 if (!crtl->subsections.unlikely_text_section_name)
682 initialize_cold_section_name ();
684 return get_named_section (NULL, crtl->subsections.unlikely_text_section_name, 0);
687 return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
690 /* When called within a function context, return true if the function
691 has been assigned a cold text section and if SECT is that section.
692 When called outside a function context, return true if SECT is the
693 default cold section. */
696 unlikely_text_section_p (section *sect)
701 name = crtl->subsections.unlikely_text_section_name;
703 name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
707 && SECTION_STYLE (sect) == SECTION_NAMED
708 && strcmp (name, sect->named.name) == 0);
711 /* Return a section with a particular name and with whatever SECTION_*
712 flags section_type_flags deems appropriate. The name of the section
713 is taken from NAME if nonnull, otherwise it is taken from DECL's
714 DECL_SECTION_NAME. DECL is the decl associated with the section
715 (see the section comment for details) and RELOC is as for
716 section_type_flags. */
719 get_named_section (tree decl, const char *name, int reloc)
723 gcc_assert (!decl || DECL_P (decl));
725 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
727 flags = targetm.section_type_flags (decl, name, reloc);
729 return get_section (name, flags, decl);
732 /* If required, set DECL_SECTION_NAME to a unique name. */
735 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
736 int flag_function_or_data_sections)
738 if (DECL_SECTION_NAME (decl) == NULL_TREE
739 && targetm.have_named_sections
740 && (flag_function_or_data_sections
741 || DECL_ONE_ONLY (decl)))
742 targetm.asm_out.unique_section (decl, reloc);
745 #ifdef BSS_SECTION_ASM_OP
747 #ifdef ASM_OUTPUT_BSS
749 /* Utility function for ASM_OUTPUT_BSS for targets to use if
750 they don't support alignments in .bss.
751 ??? It is believed that this function will work in most cases so such
752 support is localized here. */
755 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
757 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
758 unsigned HOST_WIDE_INT rounded)
760 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl), 0), 0), name) == 0);
761 targetm.asm_out.globalize_decl_name (file, decl);
762 switch_to_section (bss_section);
763 #ifdef ASM_DECLARE_OBJECT_NAME
764 last_assemble_variable_decl = decl;
765 ASM_DECLARE_OBJECT_NAME (file, name, decl);
767 /* Standard thing is just output label for the object. */
768 ASM_OUTPUT_LABEL (file, name);
769 #endif /* ASM_DECLARE_OBJECT_NAME */
770 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
775 #ifdef ASM_OUTPUT_ALIGNED_BSS
777 /* Utility function for targets to use in implementing
778 ASM_OUTPUT_ALIGNED_BSS.
779 ??? It is believed that this function will work in most cases so such
780 support is localized here. */
783 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
784 const char *name, unsigned HOST_WIDE_INT size,
787 switch_to_section (bss_section);
788 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
789 #ifdef ASM_DECLARE_OBJECT_NAME
790 last_assemble_variable_decl = decl;
791 ASM_DECLARE_OBJECT_NAME (file, name, decl);
793 /* Standard thing is just output label for the object. */
794 ASM_OUTPUT_LABEL (file, name);
795 #endif /* ASM_DECLARE_OBJECT_NAME */
796 ASM_OUTPUT_SKIP (file, size ? size : 1);
801 #endif /* BSS_SECTION_ASM_OP */
803 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
804 /* Return the hot section for function DECL. Return text_section for
808 hot_function_section (tree decl)
810 if (decl != NULL_TREE
811 && DECL_SECTION_NAME (decl) != NULL_TREE
812 && targetm.have_named_sections)
813 return get_named_section (decl, NULL, 0);
819 /* Return the section for function DECL.
821 If DECL is NULL_TREE, return the text section. We can be passed
822 NULL_TREE under some circumstances by dbxout.c at least. */
825 function_section (tree decl)
829 if (first_function_block_is_cold)
832 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
833 if (decl != NULL_TREE
834 && DECL_SECTION_NAME (decl) != NULL_TREE)
835 return reloc ? unlikely_text_section ()
836 : get_named_section (decl, NULL, 0);
838 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
840 return reloc ? unlikely_text_section () : hot_function_section (decl);
845 current_function_section (void)
847 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
848 if (current_function_decl != NULL_TREE
849 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
850 return in_cold_section_p ? unlikely_text_section ()
851 : get_named_section (current_function_decl,
854 return targetm.asm_out.select_section (current_function_decl,
856 DECL_ALIGN (current_function_decl));
858 return (in_cold_section_p
859 ? unlikely_text_section ()
860 : hot_function_section (current_function_decl));
864 /* Return the read-only data section associated with function DECL. */
867 default_function_rodata_section (tree decl)
869 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
871 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
873 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
879 dot = strchr (name + 1, '.');
882 len = strlen (dot) + 8;
883 rname = (char *) alloca (len);
885 strcpy (rname, ".rodata");
887 return get_section (rname, SECTION_LINKONCE, decl);
889 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
890 else if (DECL_ONE_ONLY (decl)
891 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
893 size_t len = strlen (name) + 1;
894 char *rname = (char *) alloca (len);
896 memcpy (rname, name, len);
898 return get_section (rname, SECTION_LINKONCE, decl);
900 /* For .text.foo we want to use .rodata.foo. */
901 else if (flag_function_sections && flag_data_sections
902 && strncmp (name, ".text.", 6) == 0)
904 size_t len = strlen (name) + 1;
905 char *rname = (char *) alloca (len + 2);
907 memcpy (rname, ".rodata", 7);
908 memcpy (rname + 7, name + 5, len - 5);
909 return get_section (rname, 0, decl);
913 return readonly_data_section;
916 /* Return the read-only data section associated with function DECL
917 for targets where that section should be always the single
918 readonly data section. */
921 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
923 return readonly_data_section;
926 /* Return the section to use for string merging. */
929 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
930 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
931 unsigned int flags ATTRIBUTE_UNUSED)
935 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
936 && TREE_CODE (decl) == STRING_CST
937 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
939 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
940 && TREE_STRING_LENGTH (decl) >= len)
942 enum machine_mode mode;
943 unsigned int modesize;
949 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
950 modesize = GET_MODE_BITSIZE (mode);
951 if (modesize >= 8 && modesize <= 256
952 && (modesize & (modesize - 1)) == 0)
954 if (align < modesize)
957 str = TREE_STRING_POINTER (decl);
958 unit = GET_MODE_SIZE (mode);
960 /* Check for embedded NUL characters. */
961 for (i = 0; i < len; i += unit)
963 for (j = 0; j < unit; j++)
964 if (str[i + j] != '\0')
971 sprintf (name, ".rodata.str%d.%d", modesize / 8,
973 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
974 return get_section (name, flags, NULL);
979 return readonly_data_section;
982 /* Return the section to use for constant merging. */
985 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
986 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
987 unsigned int flags ATTRIBUTE_UNUSED)
989 unsigned int modesize = GET_MODE_BITSIZE (mode);
991 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
997 && (align & (align - 1)) == 0)
1001 sprintf (name, ".rodata.cst%d", (int) (align / 8));
1002 flags |= (align / 8) | SECTION_MERGE;
1003 return get_section (name, flags, NULL);
1005 return readonly_data_section;
1008 /* Given NAME, a putative register name, discard any customary prefixes. */
1011 strip_reg_name (const char *name)
1013 #ifdef REGISTER_PREFIX
1014 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
1015 name += strlen (REGISTER_PREFIX);
1017 if (name[0] == '%' || name[0] == '#')
1022 /* The user has asked for a DECL to have a particular name. Set (or
1023 change) it in such a way that we don't prefix an underscore to
1026 set_user_assembler_name (tree decl, const char *name)
1028 char *starred = (char *) alloca (strlen (name) + 2);
1030 strcpy (starred + 1, name);
1031 change_decl_assembler_name (decl, get_identifier (starred));
1032 SET_DECL_RTL (decl, NULL_RTX);
1035 /* Decode an `asm' spec for a declaration as a register name.
1036 Return the register number, or -1 if nothing specified,
1037 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1038 or -3 if ASMSPEC is `cc' and is not recognized,
1039 or -4 if ASMSPEC is `memory' and is not recognized.
1040 Accept an exact spelling or a decimal number.
1041 Prefixes such as % are optional. */
1044 decode_reg_name (const char *asmspec)
1050 /* Get rid of confusing prefixes. */
1051 asmspec = strip_reg_name (asmspec);
1053 /* Allow a decimal number as a "register name". */
1054 for (i = strlen (asmspec) - 1; i >= 0; i--)
1055 if (! ISDIGIT (asmspec[i]))
1057 if (asmspec[0] != 0 && i < 0)
1060 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
1066 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1068 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1071 #ifdef ADDITIONAL_REGISTER_NAMES
1073 static const struct { const char *const name; const int number; } table[]
1074 = ADDITIONAL_REGISTER_NAMES;
1076 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1077 if (table[i].name[0]
1078 && ! strcmp (asmspec, table[i].name))
1079 return table[i].number;
1081 #endif /* ADDITIONAL_REGISTER_NAMES */
1083 if (!strcmp (asmspec, "memory"))
1086 if (!strcmp (asmspec, "cc"))
1095 /* Return true if DECL's initializer is suitable for a BSS section. */
1098 bss_initializer_p (const_tree decl)
1100 return (DECL_INITIAL (decl) == NULL
1101 || DECL_INITIAL (decl) == error_mark_node
1102 || (flag_zero_initialized_in_bss
1103 /* Leave constant zeroes in .rodata so they
1105 && !TREE_READONLY (decl)
1106 && initializer_zerop (DECL_INITIAL (decl))));
1109 /* Compute the alignment of variable specified by DECL.
1110 DONT_OUTPUT_DATA is from assemble_variable. */
1113 align_variable (tree decl, bool dont_output_data)
1115 unsigned int align = DECL_ALIGN (decl);
1117 /* In the case for initialing an array whose length isn't specified,
1118 where we have not yet been able to do the layout,
1119 figure out the proper alignment now. */
1120 if (dont_output_data && DECL_SIZE (decl) == 0
1121 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1122 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1124 /* Some object file formats have a maximum alignment which they support.
1125 In particular, a.out format supports a maximum alignment of 4. */
1126 if (align > MAX_OFILE_ALIGNMENT)
1128 warning (0, "alignment of %q+D is greater than maximum object "
1129 "file alignment. Using %d", decl,
1130 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1131 align = MAX_OFILE_ALIGNMENT;
1134 /* On some machines, it is good to increase alignment sometimes. */
1135 if (! DECL_USER_ALIGN (decl))
1137 #ifdef DATA_ALIGNMENT
1138 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1139 /* Don't increase alignment too much for TLS variables - TLS space
1141 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1144 #ifdef CONSTANT_ALIGNMENT
1145 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1147 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
1149 /* Don't increase alignment too much for TLS variables - TLS space
1151 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1152 align = const_align;
1157 /* Reset the alignment in case we have made it tighter, so we can benefit
1158 from it in get_pointer_alignment. */
1159 DECL_ALIGN (decl) = align;
1162 /* Return the section into which the given VAR_DECL or CONST_DECL
1163 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1164 section should be used wherever possible. */
1167 get_variable_section (tree decl, bool prefer_noswitch_p)
1169 addr_space_t as = ADDR_SPACE_GENERIC;
1172 if (TREE_TYPE (decl) != error_mark_node)
1173 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1175 if (DECL_COMMON (decl))
1177 /* If the decl has been given an explicit section name, or it resides
1178 in a non-generic address space, then it isn't common, and shouldn't
1179 be handled as such. */
1180 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1181 && ADDR_SPACE_GENERIC_P (as));
1182 if (DECL_THREAD_LOCAL_P (decl))
1183 return tls_comm_section;
1184 /* This cannot be common bss for an emulated TLS object without
1185 a register_common hook. */
1186 else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED
1187 && !targetm.emutls.register_common)
1189 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1190 return comm_section;
1193 if (DECL_INITIAL (decl) == error_mark_node)
1194 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1195 else if (DECL_INITIAL (decl))
1196 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1200 resolve_unique_section (decl, reloc, flag_data_sections);
1201 if (IN_NAMED_SECTION (decl))
1202 return get_named_section (decl, NULL, reloc);
1204 if (ADDR_SPACE_GENERIC_P (as)
1205 && !DECL_THREAD_LOCAL_P (decl)
1206 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1207 && bss_initializer_p (decl))
1209 if (!TREE_PUBLIC (decl))
1210 return lcomm_section;
1211 if (bss_noswitch_section)
1212 return bss_noswitch_section;
1215 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1218 /* Return the block into which object_block DECL should be placed. */
1220 static struct object_block *
1221 get_block_for_decl (tree decl)
1225 if (TREE_CODE (decl) == VAR_DECL)
1227 /* The object must be defined in this translation unit. */
1228 if (DECL_EXTERNAL (decl))
1231 /* There's no point using object blocks for something that is
1232 isolated by definition. */
1233 if (DECL_ONE_ONLY (decl))
1237 /* We can only calculate block offsets if the decl has a known
1239 if (DECL_SIZE_UNIT (decl) == NULL)
1241 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1244 /* Find out which section should contain DECL. We cannot put it into
1245 an object block if it requires a standalone definition. */
1246 if (TREE_CODE (decl) == VAR_DECL)
1247 align_variable (decl, 0);
1248 sect = get_variable_section (decl, true);
1249 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1252 return get_block_for_section (sect);
1255 /* Make sure block symbol SYMBOL is in block BLOCK. */
1258 change_symbol_block (rtx symbol, struct object_block *block)
1260 if (block != SYMBOL_REF_BLOCK (symbol))
1262 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1263 SYMBOL_REF_BLOCK (symbol) = block;
1267 /* Return true if it is possible to put DECL in an object_block. */
1270 use_blocks_for_decl_p (tree decl)
1272 /* Only data DECLs can be placed into object blocks. */
1273 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1276 /* Detect decls created by dw2_force_const_mem. Such decls are
1277 special because DECL_INITIAL doesn't specify the decl's true value.
1278 dw2_output_indirect_constants will instead call assemble_variable
1279 with dont_output_data set to 1 and then print the contents itself. */
1280 if (DECL_INITIAL (decl) == decl)
1283 /* If this decl is an alias, then we don't want to emit a definition. */
1284 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1290 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1291 have static storage duration. In other words, it should not be an
1292 automatic variable, including PARM_DECLs.
1294 There is, however, one exception: this function handles variables
1295 explicitly placed in a particular register by the user.
1297 This is never called for PARM_DECL nodes. */
1300 make_decl_rtl (tree decl)
1302 const char *name = 0;
1306 /* Check that we are not being given an automatic variable. */
1307 gcc_assert (TREE_CODE (decl) != PARM_DECL
1308 && TREE_CODE (decl) != RESULT_DECL);
1310 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1311 gcc_assert (TREE_CODE (decl) != VAR_DECL
1312 || TREE_STATIC (decl)
1313 || TREE_PUBLIC (decl)
1314 || DECL_EXTERNAL (decl)
1315 || DECL_REGISTER (decl));
1317 /* And that we were not given a type or a label. */
1318 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1319 && TREE_CODE (decl) != LABEL_DECL);
1321 /* For a duplicate declaration, we can be called twice on the
1322 same DECL node. Don't discard the RTL already made. */
1323 if (DECL_RTL_SET_P (decl))
1325 /* If the old RTL had the wrong mode, fix the mode. */
1326 x = DECL_RTL (decl);
1327 if (GET_MODE (x) != DECL_MODE (decl))
1328 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1330 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1333 /* ??? Another way to do this would be to maintain a hashed
1334 table of such critters. Instead of adding stuff to a DECL
1335 to give certain attributes to it, we could use an external
1336 hash map from DECL to set of attributes. */
1338 /* Let the target reassign the RTL if it wants.
1339 This is necessary, for example, when one machine specific
1340 decl attribute overrides another. */
1341 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1343 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1344 on the new decl information. */
1346 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1347 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1348 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1350 /* Make this function static known to the mudflap runtime. */
1351 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1352 mudflap_enqueue_decl (decl);
1357 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1359 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1360 && DECL_REGISTER (decl))
1362 error ("register name not specified for %q+D", decl);
1364 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1366 const char *asmspec = name+1;
1367 reg_number = decode_reg_name (asmspec);
1368 /* First detect errors in declaring global registers. */
1369 if (reg_number == -1)
1370 error ("register name not specified for %q+D", decl);
1371 else if (reg_number < 0)
1372 error ("invalid register name for %q+D", decl);
1373 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1374 error ("data type of %q+D isn%'t suitable for a register",
1376 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1377 error ("register specified for %q+D isn%'t suitable for data type",
1379 /* Now handle properly declared static register variables. */
1384 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1386 DECL_INITIAL (decl) = 0;
1387 error ("global register variable has initial value");
1389 if (TREE_THIS_VOLATILE (decl))
1390 warning (OPT_Wvolatile_register_var,
1391 "optimization may eliminate reads and/or "
1392 "writes to register variables");
1394 /* If the user specified one of the eliminables registers here,
1395 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1396 confused with that register and be eliminated. This usage is
1397 somewhat suspect... */
1399 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1400 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1401 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1403 if (TREE_STATIC (decl))
1405 /* Make this register global, so not usable for anything
1407 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1408 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1409 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1411 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1413 globalize_reg (reg_number + --nregs);
1416 /* As a register variable, it has no section. */
1420 /* Now handle ordinary static variables and functions (in memory).
1421 Also handle vars declared register invalidly. */
1422 else if (name[0] == '*')
1424 #ifdef REGISTER_PREFIX
1425 if (strlen (REGISTER_PREFIX) != 0)
1427 reg_number = decode_reg_name (name);
1428 if (reg_number >= 0 || reg_number == -3)
1429 error ("register name given for non-register variable %q+D", decl);
1434 /* Specifying a section attribute on a variable forces it into a
1435 non-.bss section, and thus it cannot be common. */
1436 /* FIXME: In general this code should not be necessary because
1437 visibility pass is doing the same work. But notice_global_symbol
1438 is called early and it needs to make DECL_RTL to get the name.
1439 we take care of recomputing the DECL_RTL after visibility is changed. */
1440 if (TREE_CODE (decl) == VAR_DECL
1441 && DECL_SECTION_NAME (decl) != NULL_TREE
1442 && DECL_INITIAL (decl) == NULL_TREE
1443 && DECL_COMMON (decl))
1444 DECL_COMMON (decl) = 0;
1446 /* Variables can't be both common and weak. */
1447 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1448 DECL_COMMON (decl) = 0;
1450 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1451 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1454 enum machine_mode address_mode = Pmode;
1455 if (TREE_TYPE (decl) != error_mark_node)
1457 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1458 address_mode = targetm.addr_space.address_mode (as);
1460 x = gen_rtx_SYMBOL_REF (address_mode, name);
1462 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1463 SET_SYMBOL_REF_DECL (x, decl);
1465 x = gen_rtx_MEM (DECL_MODE (decl), x);
1466 if (TREE_CODE (decl) != FUNCTION_DECL)
1467 set_mem_attributes (x, decl, 1);
1468 SET_DECL_RTL (decl, x);
1470 /* Optionally set flags or add text to the name to record information
1471 such as that it is a function name.
1472 If the name is changed, the macro ASM_OUTPUT_LABELREF
1473 will have to know how to strip this information. */
1474 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1476 /* Make this function static known to the mudflap runtime. */
1477 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1478 mudflap_enqueue_decl (decl);
1481 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1482 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1486 make_decl_rtl_for_debug (tree decl)
1488 unsigned int save_aliasing_flag, save_mudflap_flag;
1491 if (DECL_RTL_SET_P (decl))
1492 return DECL_RTL (decl);
1494 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1495 call new_alias_set. If running with -fcompare-debug, sometimes
1496 we do not want to create alias sets that will throw the alias
1497 numbers off in the comparison dumps. So... clearing
1498 flag_strict_aliasing will keep new_alias_set() from creating a
1499 new set. It is undesirable to register decl with mudflap
1500 in this case as well. */
1501 save_aliasing_flag = flag_strict_aliasing;
1502 flag_strict_aliasing = 0;
1503 save_mudflap_flag = flag_mudflap;
1506 rtl = DECL_RTL (decl);
1507 /* Reset DECL_RTL back, as various parts of the compiler expects
1508 DECL_RTL set meaning it is actually going to be output. */
1509 SET_DECL_RTL (decl, NULL);
1511 flag_strict_aliasing = save_aliasing_flag;
1512 flag_mudflap = save_mudflap_flag;
1517 /* Output a string of literal assembler code
1518 for an `asm' keyword used between functions. */
1521 assemble_asm (tree string)
1525 if (TREE_CODE (string) == ADDR_EXPR)
1526 string = TREE_OPERAND (string, 0);
1528 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1531 /* Record an element in the table of global destructors. SYMBOL is
1532 a SYMBOL_REF of the function to be called; PRIORITY is a number
1533 between 0 and MAX_INIT_PRIORITY. */
1536 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1537 int priority ATTRIBUTE_UNUSED)
1539 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1540 /* Tell GNU LD that this is part of the static destructor set.
1541 This will work for any system that uses stabs, most usefully
1543 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1544 dbxout_stab_value_label (XSTR (symbol, 0));
1546 sorry ("global destructors not supported on this target");
1550 /* Write the address of the entity given by SYMBOL to SEC. */
1552 assemble_addr_to_section (rtx symbol, section *sec)
1554 switch_to_section (sec);
1555 assemble_align (POINTER_SIZE);
1556 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1559 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1560 not) section for PRIORITY. */
1562 get_cdtor_priority_section (int priority, bool constructor_p)
1566 /* ??? This only works reliably with the GNU linker. */
1567 sprintf (buf, "%s.%.5u",
1568 constructor_p ? ".ctors" : ".dtors",
1569 /* Invert the numbering so the linker puts us in the proper
1570 order; constructors are run from right to left, and the
1571 linker sorts in increasing order. */
1572 MAX_INIT_PRIORITY - priority);
1573 return get_section (buf, SECTION_WRITE, NULL);
1577 default_named_section_asm_out_destructor (rtx symbol, int priority)
1581 if (priority != DEFAULT_INIT_PRIORITY)
1582 sec = get_cdtor_priority_section (priority,
1583 /*constructor_p=*/false);
1585 sec = get_section (".dtors", SECTION_WRITE, NULL);
1587 assemble_addr_to_section (symbol, sec);
1590 #ifdef DTORS_SECTION_ASM_OP
1592 default_dtor_section_asm_out_destructor (rtx symbol,
1593 int priority ATTRIBUTE_UNUSED)
1595 assemble_addr_to_section (symbol, dtors_section);
1599 /* Likewise for global constructors. */
1602 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1603 int priority ATTRIBUTE_UNUSED)
1605 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1606 /* Tell GNU LD that this is part of the static destructor set.
1607 This will work for any system that uses stabs, most usefully
1609 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1610 dbxout_stab_value_label (XSTR (symbol, 0));
1612 sorry ("global constructors not supported on this target");
1617 default_named_section_asm_out_constructor (rtx symbol, int priority)
1621 if (priority != DEFAULT_INIT_PRIORITY)
1622 sec = get_cdtor_priority_section (priority,
1623 /*constructor_p=*/true);
1625 sec = get_section (".ctors", SECTION_WRITE, NULL);
1627 assemble_addr_to_section (symbol, sec);
1630 #ifdef CTORS_SECTION_ASM_OP
1632 default_ctor_section_asm_out_constructor (rtx symbol,
1633 int priority ATTRIBUTE_UNUSED)
1635 assemble_addr_to_section (symbol, ctors_section);
1639 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1640 a nonzero value if the constant pool should be output before the
1641 start of the function, or a zero value if the pool should output
1642 after the end of the function. The default is to put it before the
1645 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1646 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1649 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1650 to be output to assembler.
1651 Set first_global_object_name and weak_global_object_name as appropriate. */
1654 notice_global_symbol (tree decl)
1656 const char **type = &first_global_object_name;
1658 if (first_global_object_name
1659 || !TREE_PUBLIC (decl)
1660 || DECL_EXTERNAL (decl)
1661 || !DECL_NAME (decl)
1662 || (TREE_CODE (decl) != FUNCTION_DECL
1663 && (TREE_CODE (decl) != VAR_DECL
1664 || (DECL_COMMON (decl)
1665 && (DECL_INITIAL (decl) == 0
1666 || DECL_INITIAL (decl) == error_mark_node))))
1667 || !MEM_P (DECL_RTL (decl)))
1670 /* We win when global object is found, but it is useful to know about weak
1671 symbol as well so we can produce nicer unique names. */
1672 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1673 type = &weak_global_object_name;
1679 rtx decl_rtl = DECL_RTL (decl);
1681 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1682 name = ggc_strdup (p);
1688 /* Output assembler code for the constant pool of a function and associated
1689 with defining the name of the function. DECL describes the function.
1690 NAME is the function's name. For the constant pool, we use the current
1691 constant pool data. */
1694 assemble_start_function (tree decl, const char *fnname)
1697 char tmp_label[100];
1698 bool hot_label_written = false;
1700 crtl->subsections.unlikely_text_section_name = NULL;
1702 first_function_block_is_cold = false;
1703 if (flag_reorder_blocks_and_partition)
1705 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1706 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1707 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1708 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1709 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1710 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1711 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1712 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1717 crtl->subsections.hot_section_label = NULL;
1718 crtl->subsections.cold_section_label = NULL;
1719 crtl->subsections.hot_section_end_label = NULL;
1720 crtl->subsections.cold_section_end_label = NULL;
1723 /* The following code does not need preprocessing in the assembler. */
1727 if (CONSTANT_POOL_BEFORE_FUNCTION)
1728 output_constant_pool (fnname, decl);
1730 resolve_unique_section (decl, 0, flag_function_sections);
1732 /* Make sure the not and cold text (code) sections are properly
1733 aligned. This is necessary here in the case where the function
1734 has both hot and cold sections, because we don't want to re-set
1735 the alignment when the section switch happens mid-function. */
1737 if (flag_reorder_blocks_and_partition)
1739 switch_to_section (unlikely_text_section ());
1740 assemble_align (DECL_ALIGN (decl));
1741 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1743 /* When the function starts with a cold section, we need to explicitly
1744 align the hot section and write out the hot section label.
1745 But if the current function is a thunk, we do not have a CFG. */
1747 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1749 switch_to_section (text_section);
1750 assemble_align (DECL_ALIGN (decl));
1751 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1752 hot_label_written = true;
1753 first_function_block_is_cold = true;
1756 else if (DECL_SECTION_NAME (decl))
1758 /* Calls to function_section rely on first_function_block_is_cold
1759 being accurate. The first block may be cold even if we aren't
1760 doing partitioning, if the entire function was decided by
1761 choose_function_section (predict.c) to be cold. */
1763 initialize_cold_section_name ();
1765 if (crtl->subsections.unlikely_text_section_name
1766 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1767 crtl->subsections.unlikely_text_section_name) == 0)
1768 first_function_block_is_cold = true;
1771 in_cold_section_p = first_function_block_is_cold;
1773 /* Switch to the correct text section for the start of the function. */
1775 switch_to_section (function_section (decl));
1776 if (flag_reorder_blocks_and_partition
1777 && !hot_label_written)
1778 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1780 /* Tell assembler to move to target machine's alignment for functions. */
1781 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1784 ASM_OUTPUT_ALIGN (asm_out_file, align);
1787 /* Handle a user-specified function alignment.
1788 Note that we still need to align to DECL_ALIGN, as above,
1789 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1790 if (! DECL_USER_ALIGN (decl)
1791 && align_functions_log > align
1792 && optimize_function_for_speed_p (cfun))
1794 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1795 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1796 align_functions_log, align_functions - 1);
1798 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1802 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1803 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1806 if (!DECL_IGNORED_P (decl))
1807 (*debug_hooks->begin_function) (decl);
1809 /* Make function name accessible from other files, if appropriate. */
1811 if (TREE_PUBLIC (decl))
1813 notice_global_symbol (decl);
1815 globalize_decl (decl);
1817 maybe_assemble_visibility (decl);
1820 if (DECL_PRESERVE_P (decl))
1821 targetm.asm_out.mark_decl_preserved (fnname);
1823 /* Do any machine/system dependent processing of the function name. */
1824 #ifdef ASM_DECLARE_FUNCTION_NAME
1825 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1827 /* Standard thing is just output label for the function. */
1828 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1829 #endif /* ASM_DECLARE_FUNCTION_NAME */
1832 /* Output assembler code associated with defining the size of the
1833 function. DECL describes the function. NAME is the function's name. */
1836 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1838 #ifdef ASM_DECLARE_FUNCTION_SIZE
1839 /* We could have switched section in the middle of the function. */
1840 if (flag_reorder_blocks_and_partition)
1841 switch_to_section (function_section (decl));
1842 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1844 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1846 output_constant_pool (fnname, decl);
1847 switch_to_section (function_section (decl)); /* need to switch back */
1849 /* Output labels for end of hot/cold text sections (to be used by
1851 if (flag_reorder_blocks_and_partition)
1853 section *save_text_section;
1855 save_text_section = in_section;
1856 switch_to_section (unlikely_text_section ());
1857 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1858 if (first_function_block_is_cold)
1859 switch_to_section (text_section);
1861 switch_to_section (function_section (decl));
1862 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1863 switch_to_section (save_text_section);
1867 /* Assemble code to leave SIZE bytes of zeros. */
1870 assemble_zeros (unsigned HOST_WIDE_INT size)
1872 /* Do no output if -fsyntax-only. */
1873 if (flag_syntax_only)
1876 #ifdef ASM_NO_SKIP_IN_TEXT
1877 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1878 so we must output 0s explicitly in the text section. */
1879 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1881 unsigned HOST_WIDE_INT i;
1882 for (i = 0; i < size; i++)
1883 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1888 ASM_OUTPUT_SKIP (asm_out_file, size);
1891 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1894 assemble_align (int align)
1896 if (align > BITS_PER_UNIT)
1898 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1902 /* Assemble a string constant with the specified C string as contents. */
1905 assemble_string (const char *p, int size)
1910 /* If the string is very long, split it up. */
1914 int thissize = size - pos;
1915 if (thissize > maximum)
1918 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1926 /* A noswitch_section_callback for lcomm_section. */
1929 emit_local (tree decl ATTRIBUTE_UNUSED,
1930 const char *name ATTRIBUTE_UNUSED,
1931 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1932 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1934 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1935 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1936 size, DECL_ALIGN (decl));
1938 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1939 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1942 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1947 /* A noswitch_section_callback for bss_noswitch_section. */
1949 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1951 emit_bss (tree decl ATTRIBUTE_UNUSED,
1952 const char *name ATTRIBUTE_UNUSED,
1953 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1954 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1956 #if defined ASM_OUTPUT_ALIGNED_BSS
1957 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1960 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1966 /* A noswitch_section_callback for comm_section. */
1969 emit_common (tree decl ATTRIBUTE_UNUSED,
1970 const char *name ATTRIBUTE_UNUSED,
1971 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1972 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1974 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1975 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1976 size, DECL_ALIGN (decl));
1978 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1979 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1982 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1987 /* A noswitch_section_callback for tls_comm_section. */
1990 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1991 const char *name ATTRIBUTE_UNUSED,
1992 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1993 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1995 #ifdef ASM_OUTPUT_TLS_COMMON
1996 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1999 sorry ("thread-local COMMON data not implemented");
2004 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2005 NAME is the name of DECL's SYMBOL_REF. */
2008 assemble_noswitch_variable (tree decl, const char *name, section *sect)
2010 unsigned HOST_WIDE_INT size, rounded;
2012 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
2015 /* Don't allocate zero bytes of common,
2016 since that means "undefined external" in the linker. */
2020 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2021 so that each uninitialized object starts on such a boundary. */
2022 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
2023 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2024 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2026 if (!sect->noswitch.callback (decl, name, size, rounded)
2027 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
2028 warning (0, "requested alignment for %q+D is greater than "
2029 "implemented alignment of %wu", decl, rounded);
2032 /* A subroutine of assemble_variable. Output the label and contents of
2033 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2034 is as for assemble_variable. */
2037 assemble_variable_contents (tree decl, const char *name,
2038 bool dont_output_data)
2040 /* Do any machine/system dependent processing of the object. */
2041 #ifdef ASM_DECLARE_OBJECT_NAME
2042 last_assemble_variable_decl = decl;
2043 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
2045 /* Standard thing is just output label for the object. */
2046 ASM_OUTPUT_LABEL (asm_out_file, name);
2047 #endif /* ASM_DECLARE_OBJECT_NAME */
2049 if (!dont_output_data)
2051 if (DECL_INITIAL (decl)
2052 && DECL_INITIAL (decl) != error_mark_node
2053 && !initializer_zerop (DECL_INITIAL (decl)))
2054 /* Output the actual data. */
2055 output_constant (DECL_INITIAL (decl),
2056 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
2059 /* Leave space for it. */
2060 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
2064 /* Initialize emulated tls object TO, which refers to TLS variable
2065 DECL and is initialized by PROXY. */
2068 default_emutls_var_init (tree to, tree decl, tree proxy)
2070 VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4);
2071 constructor_elt *elt;
2072 tree type = TREE_TYPE (to);
2073 tree field = TYPE_FIELDS (type);
2075 elt = VEC_quick_push (constructor_elt, v, NULL);
2077 elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
2079 elt = VEC_quick_push (constructor_elt, v, NULL);
2080 field = TREE_CHAIN (field);
2082 elt->value = build_int_cst (TREE_TYPE (field),
2083 DECL_ALIGN_UNIT (decl));
2085 elt = VEC_quick_push (constructor_elt, v, NULL);
2086 field = TREE_CHAIN (field);
2088 elt->value = null_pointer_node;
2090 elt = VEC_quick_push (constructor_elt, v, NULL);
2091 field = TREE_CHAIN (field);
2095 return build_constructor (type, v);
2098 /* Assemble everything that is needed for a variable or function declaration.
2099 Not used for automatic variables, and not used for function definitions.
2100 Should not be called for variables of incomplete structure type.
2102 TOP_LEVEL is nonzero if this variable has file scope.
2103 AT_END is nonzero if this is the special handling, at end of compilation,
2104 to define things that have had only tentative definitions.
2105 DONT_OUTPUT_DATA if nonzero means don't actually output the
2106 initial value (that will be done by the caller). */
2109 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2110 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2113 rtx decl_rtl, symbol;
2116 if (! targetm.have_tls
2117 && TREE_CODE (decl) == VAR_DECL
2118 && DECL_THREAD_LOCAL_P (decl))
2120 tree to = emutls_decl (decl);
2122 /* If this variable is defined locally, then we need to initialize the
2123 control structure with size and alignment information. We do this
2124 at the last moment because tentative definitions can take a locally
2125 defined but uninitialized variable and initialize it later, which
2126 would result in incorrect contents. */
2127 if (! DECL_EXTERNAL (to)
2128 && (! DECL_COMMON (to)
2129 || (DECL_INITIAL (decl)
2130 && DECL_INITIAL (decl) != error_mark_node)))
2132 DECL_INITIAL (to) = targetm.emutls.var_init
2133 (to, decl, get_emutls_init_templ_addr (decl));
2135 /* Make sure the template is marked as needed early enough.
2136 Without this, if the variable is placed in a
2137 section-anchored block, the template will only be marked
2138 when it's too late. */
2139 record_references_in_initializer (to, false);
2145 last_assemble_variable_decl = 0;
2147 /* Normally no need to say anything here for external references,
2148 since assemble_external is called by the language-specific code
2149 when a declaration is first seen. */
2151 if (DECL_EXTERNAL (decl))
2154 /* Output no assembler code for a function declaration.
2155 Only definitions of functions output anything. */
2157 if (TREE_CODE (decl) == FUNCTION_DECL)
2160 /* Do nothing for global register variables. */
2161 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2163 TREE_ASM_WRITTEN (decl) = 1;
2167 /* If type was incomplete when the variable was declared,
2168 see if it is complete now. */
2170 if (DECL_SIZE (decl) == 0)
2171 layout_decl (decl, 0);
2173 /* Still incomplete => don't allocate it; treat the tentative defn
2174 (which is what it must have been) as an `extern' reference. */
2176 if (!dont_output_data && DECL_SIZE (decl) == 0)
2178 error ("storage size of %q+D isn%'t known", decl);
2179 TREE_ASM_WRITTEN (decl) = 1;
2183 /* The first declaration of a variable that comes through this function
2184 decides whether it is global (in C, has external linkage)
2185 or local (in C, has internal linkage). So do nothing more
2186 if this function has already run. */
2188 if (TREE_ASM_WRITTEN (decl))
2191 /* Make sure targetm.encode_section_info is invoked before we set
2193 decl_rtl = DECL_RTL (decl);
2195 TREE_ASM_WRITTEN (decl) = 1;
2197 /* Do no output if -fsyntax-only. */
2198 if (flag_syntax_only)
2203 if (! dont_output_data
2204 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2206 error ("size of variable %q+D is too large", decl);
2210 gcc_assert (MEM_P (decl_rtl));
2211 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2212 symbol = XEXP (decl_rtl, 0);
2213 name = XSTR (symbol, 0);
2214 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2215 notice_global_symbol (decl);
2217 /* Compute the alignment of this data. */
2219 align_variable (decl, dont_output_data);
2220 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2222 if (TREE_PUBLIC (decl))
2223 maybe_assemble_visibility (decl);
2225 if (DECL_PRESERVE_P (decl))
2226 targetm.asm_out.mark_decl_preserved (name);
2228 /* First make the assembler name(s) global if appropriate. */
2229 sect = get_variable_section (decl, false);
2230 if (TREE_PUBLIC (decl)
2231 && (sect->common.flags & SECTION_COMMON) == 0)
2232 globalize_decl (decl);
2234 /* Output any data that we will need to use the address of. */
2235 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2236 output_addressed_constants (DECL_INITIAL (decl));
2238 /* dbxout.c needs to know this. */
2239 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2240 DECL_IN_TEXT_SECTION (decl) = 1;
2242 /* If the decl is part of an object_block, make sure that the decl
2243 has been positioned within its block, but do not write out its
2244 definition yet. output_object_blocks will do that later. */
2245 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2247 gcc_assert (!dont_output_data);
2248 place_block_symbol (symbol);
2250 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2251 assemble_noswitch_variable (decl, name, sect);
2254 switch_to_section (sect);
2255 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2256 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2257 assemble_variable_contents (decl, name, dont_output_data);
2261 /* Return 1 if type TYPE contains any pointers. */
2264 contains_pointers_p (tree type)
2266 switch (TREE_CODE (type))
2269 case REFERENCE_TYPE:
2270 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2271 so I'll play safe and return 1. */
2277 case QUAL_UNION_TYPE:
2280 /* For a type that has fields, see if the fields have pointers. */
2281 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2282 if (TREE_CODE (fields) == FIELD_DECL
2283 && contains_pointers_p (TREE_TYPE (fields)))
2289 /* An array type contains pointers if its element type does. */
2290 return contains_pointers_p (TREE_TYPE (type));
2297 /* We delay assemble_external processing until
2298 the compilation unit is finalized. This is the best we can do for
2299 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2300 it all the way to final. See PR 17982 for further discussion. */
2301 static GTY(()) tree pending_assemble_externals;
2303 #ifdef ASM_OUTPUT_EXTERNAL
2304 /* True if DECL is a function decl for which no out-of-line copy exists.
2305 It is assumed that DECL's assembler name has been set. */
2308 incorporeal_function_p (tree decl)
2310 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2314 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2315 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2318 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2319 if (is_builtin_name (name))
2325 /* Actually do the tests to determine if this is necessary, and invoke
2326 ASM_OUTPUT_EXTERNAL. */
2328 assemble_external_real (tree decl)
2330 rtx rtl = DECL_RTL (decl);
2332 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2333 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2334 && !incorporeal_function_p (decl))
2336 /* Some systems do require some output. */
2337 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2338 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2344 process_pending_assemble_externals (void)
2346 #ifdef ASM_OUTPUT_EXTERNAL
2348 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2349 assemble_external_real (TREE_VALUE (list));
2351 pending_assemble_externals = 0;
2355 /* This TREE_LIST contains any weak symbol declarations waiting
2357 static GTY(()) tree weak_decls;
2359 /* Output something to declare an external symbol to the assembler,
2360 and qualifiers such as weakness. (Most assemblers don't need
2361 extern declaration, so we normally output nothing.) Do nothing if
2362 DECL is not external. */
2365 assemble_external (tree decl ATTRIBUTE_UNUSED)
2367 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2368 main body of this code is only rarely exercised. To provide some
2369 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2370 open. If it's not, we should not be calling this function. */
2371 gcc_assert (asm_out_file);
2373 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2376 /* We want to output annotation for weak and external symbols at
2377 very last to check if they are references or not. */
2381 /* TREE_STATIC is a weird and abused creature which is not
2382 generally the right test for whether an entity has been
2383 locally emitted, inlined or otherwise not-really-extern, but
2384 for declarations that can be weak, it happens to be
2386 && !TREE_STATIC (decl)
2387 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2388 && value_member (decl, weak_decls) == NULL_TREE)
2389 weak_decls = tree_cons (NULL, decl, weak_decls);
2391 #ifdef ASM_OUTPUT_EXTERNAL
2392 if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2393 pending_assemble_externals = tree_cons (NULL, decl,
2394 pending_assemble_externals);
2398 /* Similar, for calling a library function FUN. */
2401 assemble_external_libcall (rtx fun)
2403 /* Declare library function name external when first used, if nec. */
2404 if (! SYMBOL_REF_USED (fun))
2406 SYMBOL_REF_USED (fun) = 1;
2407 targetm.asm_out.external_libcall (fun);
2411 /* Assemble a label named NAME. */
2414 assemble_label (const char *name)
2416 ASM_OUTPUT_LABEL (asm_out_file, name);
2419 /* Set the symbol_referenced flag for ID. */
2421 mark_referenced (tree id)
2423 TREE_SYMBOL_REFERENCED (id) = 1;
2426 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2428 mark_decl_referenced (tree decl)
2430 if (TREE_CODE (decl) == FUNCTION_DECL)
2432 /* Extern inline functions don't become needed when referenced.
2433 If we know a method will be emitted in other TU and no new
2434 functions can be marked reachable, just use the external
2436 struct cgraph_node *node = cgraph_node (decl);
2437 if (!DECL_EXTERNAL (decl)
2438 && (!node->local.vtable_method || !cgraph_global_info_ready
2439 || !node->local.finalized))
2440 cgraph_mark_needed_node (node);
2442 else if (TREE_CODE (decl) == VAR_DECL)
2444 struct varpool_node *node = varpool_node (decl);
2445 varpool_mark_needed_node (node);
2446 /* C++ frontend use mark_decl_references to force COMDAT variables
2447 to be output that might appear dead otherwise. */
2448 node->force_output = true;
2450 /* else do nothing - we can get various sorts of CST nodes here,
2451 which do not need to be marked. */
2455 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2456 until we find an identifier that is not itself a transparent alias.
2457 Modify the alias passed to it by reference (and all aliases on the
2458 way to the ultimate target), such that they do not have to be
2459 followed again, and return the ultimate target of the alias
2463 ultimate_transparent_alias_target (tree *alias)
2465 tree target = *alias;
2467 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2469 gcc_assert (TREE_CHAIN (target));
2470 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2471 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2472 && ! TREE_CHAIN (target));
2479 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2480 starts with a *, the rest of NAME is output verbatim. Otherwise
2481 NAME is transformed in a target-specific way (usually by the
2482 addition of an underscore). */
2485 assemble_name_raw (FILE *file, const char *name)
2488 fputs (&name[1], file);
2490 ASM_OUTPUT_LABELREF (file, name);
2493 /* Like assemble_name_raw, but should be used when NAME might refer to
2494 an entity that is also represented as a tree (like a function or
2495 variable). If NAME does refer to such an entity, that entity will
2496 be marked as referenced. */
2499 assemble_name (FILE *file, const char *name)
2501 const char *real_name;
2504 real_name = targetm.strip_name_encoding (name);
2506 id = maybe_get_identifier (real_name);
2511 mark_referenced (id);
2512 ultimate_transparent_alias_target (&id);
2514 name = IDENTIFIER_POINTER (id);
2515 gcc_assert (! TREE_CHAIN (id));
2518 assemble_name_raw (file, name);
2521 /* Allocate SIZE bytes writable static space with a gensym name
2522 and return an RTX to refer to its address. */
2525 assemble_static_space (unsigned HOST_WIDE_INT size)
2528 const char *namestring;
2531 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2533 namestring = ggc_strdup (name);
2535 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2536 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2538 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2539 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2542 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2543 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2546 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2547 so that each uninitialized object starts on such a boundary. */
2548 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2549 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2550 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2551 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2552 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2553 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2560 /* Assemble the static constant template for function entry trampolines.
2561 This is done at most once per compilation.
2562 Returns an RTX for the address of the template. */
2564 static GTY(()) rtx initial_trampoline;
2567 assemble_trampoline_template (void)
2574 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2576 if (initial_trampoline)
2577 return initial_trampoline;
2579 /* By default, put trampoline templates in read-only data section. */
2581 #ifdef TRAMPOLINE_SECTION
2582 switch_to_section (TRAMPOLINE_SECTION);
2584 switch_to_section (readonly_data_section);
2587 /* Write the assembler code to define one. */
2588 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2590 ASM_OUTPUT_ALIGN (asm_out_file, align);
2592 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2593 targetm.asm_out.trampoline_template (asm_out_file);
2595 /* Record the rtl to refer to it. */
2596 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2597 name = ggc_strdup (label);
2598 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2599 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2601 initial_trampoline = gen_const_mem (BLKmode, symbol);
2602 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2603 set_mem_size (initial_trampoline, GEN_INT (TRAMPOLINE_SIZE));
2605 return initial_trampoline;
2608 /* A and B are either alignments or offsets. Return the minimum alignment
2609 that may be assumed after adding the two together. */
2611 static inline unsigned
2612 min_align (unsigned int a, unsigned int b)
2614 return (a | b) & -(a | b);
2617 /* Return the assembler directive for creating a given kind of integer
2618 object. SIZE is the number of bytes in the object and ALIGNED_P
2619 indicates whether it is known to be aligned. Return NULL if the
2620 assembly dialect has no such directive.
2622 The returned string should be printed at the start of a new line and
2623 be followed immediately by the object's initial value. */
2626 integer_asm_op (int size, int aligned_p)
2628 struct asm_int_op *ops;
2631 ops = &targetm.asm_out.aligned_op;
2633 ops = &targetm.asm_out.unaligned_op;
2638 return targetm.asm_out.byte_op;
2652 /* Use directive OP to assemble an integer object X. Print OP at the
2653 start of the line, followed immediately by the value of X. */
2656 assemble_integer_with_op (const char *op, rtx x)
2658 fputs (op, asm_out_file);
2659 output_addr_const (asm_out_file, x);
2660 fputc ('\n', asm_out_file);
2663 /* The default implementation of the asm_out.integer target hook. */
2666 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2667 unsigned int size ATTRIBUTE_UNUSED,
2668 int aligned_p ATTRIBUTE_UNUSED)
2670 const char *op = integer_asm_op (size, aligned_p);
2671 /* Avoid GAS bugs for large values. Specifically negative values whose
2672 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2673 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2675 return op && (assemble_integer_with_op (op, x), true);
2678 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2679 the alignment of the integer in bits. Return 1 if we were able to output
2680 the constant, otherwise 0. We must be able to output the constant,
2681 if FORCE is nonzero. */
2684 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2688 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2690 /* See if the target hook can handle this kind of object. */
2691 if (targetm.asm_out.integer (x, size, aligned_p))
2694 /* If the object is a multi-byte one, try splitting it up. Split
2695 it into words it if is multi-word, otherwise split it into bytes. */
2698 enum machine_mode omode, imode;
2699 unsigned int subalign;
2700 unsigned int subsize, i;
2701 enum mode_class mclass;
2703 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2704 subalign = MIN (align, subsize * BITS_PER_UNIT);
2705 if (GET_CODE (x) == CONST_FIXED)
2706 mclass = GET_MODE_CLASS (GET_MODE (x));
2710 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2711 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2713 for (i = 0; i < size; i += subsize)
2715 rtx partial = simplify_subreg (omode, x, imode, i);
2716 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2722 /* If we've printed some of it, but not all of it, there's no going
2727 gcc_assert (!force);
2733 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2735 long data[4] = {0, 0, 0, 0};
2737 int bitsize, nelts, nunits, units_per;
2739 /* This is hairy. We have a quantity of known size. real_to_target
2740 will put it into an array of *host* longs, 32 bits per element
2741 (even if long is more than 32 bits). We need to determine the
2742 number of array elements that are occupied (nelts) and the number
2743 of *target* min-addressable units that will be occupied in the
2744 object file (nunits). We cannot assume that 32 divides the
2745 mode's bitsize (size * BITS_PER_UNIT) evenly.
2747 size * BITS_PER_UNIT is used here to make sure that padding bits
2748 (which might appear at either end of the value; real_to_target
2749 will include the padding bits in its output array) are included. */
2751 nunits = GET_MODE_SIZE (mode);
2752 bitsize = nunits * BITS_PER_UNIT;
2753 nelts = CEIL (bitsize, 32);
2754 units_per = 32 / BITS_PER_UNIT;
2756 real_to_target (data, &d, mode);
2758 /* Put out the first word with the specified alignment. */
2759 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2760 nunits -= units_per;
2762 /* Subsequent words need only 32-bit alignment. */
2763 align = min_align (align, 32);
2765 for (i = 1; i < nelts; i++)
2767 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2768 nunits -= units_per;
2772 /* Given an expression EXP with a constant value,
2773 reduce it to the sum of an assembler symbol and an integer.
2774 Store them both in the structure *VALUE.
2775 EXP must be reducible. */
2777 struct GTY(()) addr_const {
2779 HOST_WIDE_INT offset;
2783 decode_addr_const (tree exp, struct addr_const *value)
2785 tree target = TREE_OPERAND (exp, 0);
2791 if (TREE_CODE (target) == COMPONENT_REF
2792 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2795 offset += int_byte_position (TREE_OPERAND (target, 1));
2796 target = TREE_OPERAND (target, 0);
2798 else if (TREE_CODE (target) == ARRAY_REF
2799 || TREE_CODE (target) == ARRAY_RANGE_REF)
2801 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2802 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2803 target = TREE_OPERAND (target, 0);
2805 else if (TREE_CODE (target) == INDIRECT_REF
2806 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2807 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2809 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2814 switch (TREE_CODE (target))
2818 x = DECL_RTL (target);
2822 x = gen_rtx_MEM (FUNCTION_MODE,
2823 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2832 x = output_constant_def (target, 1);
2839 gcc_assert (MEM_P (x));
2843 value->offset = offset;
2847 static GTY((param_is (struct constant_descriptor_tree)))
2848 htab_t const_desc_htab;
2850 static struct constant_descriptor_tree * build_constant_desc (tree);
2851 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2853 /* Constant pool accessor function. */
2856 constant_pool_htab (void)
2858 return const_desc_htab;
2861 /* Compute a hash code for a constant expression. */
2864 const_desc_hash (const void *ptr)
2866 return ((const struct constant_descriptor_tree *)ptr)->hash;
2870 const_hash_1 (const tree exp)
2875 enum tree_code code = TREE_CODE (exp);
2877 /* Either set P and LEN to the address and len of something to hash and
2878 exit the switch or return a value. */
2883 p = (char *) &TREE_INT_CST (exp);
2884 len = sizeof TREE_INT_CST (exp);
2888 return real_hash (TREE_REAL_CST_PTR (exp));
2891 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2894 p = TREE_STRING_POINTER (exp);
2895 len = TREE_STRING_LENGTH (exp);
2899 return (const_hash_1 (TREE_REALPART (exp)) * 5
2900 + const_hash_1 (TREE_IMAGPART (exp)));
2906 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2908 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2909 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2916 unsigned HOST_WIDE_INT idx;
2919 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2921 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2923 hi = hi * 603 + const_hash_1 (value);
2931 struct addr_const value;
2933 decode_addr_const (exp, &value);
2934 switch (GET_CODE (value.base))
2937 /* Don't hash the address of the SYMBOL_REF;
2938 only use the offset and the symbol name. */
2940 p = XSTR (value.base, 0);
2941 for (i = 0; p[i] != 0; i++)
2942 hi = ((hi * 613) + (unsigned) (p[i]));
2946 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2956 case POINTER_PLUS_EXPR:
2958 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2959 + const_hash_1 (TREE_OPERAND (exp, 1)));
2962 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2965 /* A language specific constant. Just hash the code. */
2969 /* Compute hashing function. */
2971 for (i = 0; i < len; i++)
2972 hi = ((hi * 613) + (unsigned) (p[i]));
2977 /* Wrapper of compare_constant, for the htab interface. */
2979 const_desc_eq (const void *p1, const void *p2)
2981 const struct constant_descriptor_tree *const c1
2982 = (const struct constant_descriptor_tree *) p1;
2983 const struct constant_descriptor_tree *const c2
2984 = (const struct constant_descriptor_tree *) p2;
2985 if (c1->hash != c2->hash)
2987 return compare_constant (c1->value, c2->value);
2990 /* Compare t1 and t2, and return 1 only if they are known to result in
2991 the same bit pattern on output. */
2994 compare_constant (const tree t1, const tree t2)
2996 enum tree_code typecode;
2998 if (t1 == NULL_TREE)
2999 return t2 == NULL_TREE;
3000 if (t2 == NULL_TREE)
3003 if (TREE_CODE (t1) != TREE_CODE (t2))
3006 switch (TREE_CODE (t1))
3009 /* Integer constants are the same only if the same width of type. */
3010 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3012 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3014 return tree_int_cst_equal (t1, t2);
3017 /* Real constants are the same only if the same width of type. */
3018 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3021 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3024 /* Fixed constants are the same only if the same width of type. */
3025 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3028 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3031 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3034 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3035 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3036 TREE_STRING_LENGTH (t1)));
3039 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3040 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3046 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
3047 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
3050 link2 = TREE_VECTOR_CST_ELTS (t2);
3051 for (link1 = TREE_VECTOR_CST_ELTS (t1);
3053 link1 = TREE_CHAIN (link1))
3055 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
3057 link2 = TREE_CHAIN (link2);
3065 VEC(constructor_elt, gc) *v1, *v2;
3066 unsigned HOST_WIDE_INT idx;
3068 typecode = TREE_CODE (TREE_TYPE (t1));
3069 if (typecode != TREE_CODE (TREE_TYPE (t2)))
3072 if (typecode == ARRAY_TYPE)
3074 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3075 /* For arrays, check that the sizes all match. */
3076 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3078 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
3083 /* For record and union constructors, require exact type
3085 if (TREE_TYPE (t1) != TREE_TYPE (t2))
3089 v1 = CONSTRUCTOR_ELTS (t1);
3090 v2 = CONSTRUCTOR_ELTS (t2);
3091 if (VEC_length (constructor_elt, v1)
3092 != VEC_length (constructor_elt, v2))
3095 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
3097 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
3098 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
3100 /* Check that each value is the same... */
3101 if (!compare_constant (c1->value, c2->value))
3103 /* ... and that they apply to the same fields! */
3104 if (typecode == ARRAY_TYPE)
3106 if (!compare_constant (c1->index, c2->index))
3111 if (c1->index != c2->index)
3122 struct addr_const value1, value2;
3126 decode_addr_const (t1, &value1);
3127 decode_addr_const (t2, &value2);
3129 if (value1.offset != value2.offset)
3132 code = GET_CODE (value1.base);
3133 if (code != GET_CODE (value2.base))
3139 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3143 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
3144 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
3154 case POINTER_PLUS_EXPR:
3157 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3158 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3161 case VIEW_CONVERT_EXPR:
3162 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3171 /* Make a copy of the whole tree structure for a constant. This
3172 handles the same types of nodes that compare_constant handles. */
3175 copy_constant (tree exp)
3177 switch (TREE_CODE (exp))
3180 /* For ADDR_EXPR, we do not want to copy the decl whose address
3181 is requested. We do want to copy constants though. */
3182 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3183 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3184 copy_constant (TREE_OPERAND (exp, 0)));
3186 return copy_node (exp);
3192 return copy_node (exp);
3195 return build_complex (TREE_TYPE (exp),
3196 copy_constant (TREE_REALPART (exp)),
3197 copy_constant (TREE_IMAGPART (exp)));
3200 case POINTER_PLUS_EXPR:
3202 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3203 copy_constant (TREE_OPERAND (exp, 0)),
3204 copy_constant (TREE_OPERAND (exp, 1)));
3207 case VIEW_CONVERT_EXPR:
3208 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3209 copy_constant (TREE_OPERAND (exp, 0)));
3212 return build_vector (TREE_TYPE (exp),
3213 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3217 tree copy = copy_node (exp);
3218 VEC(constructor_elt, gc) *v;
3219 unsigned HOST_WIDE_INT idx;
3220 tree purpose, value;
3222 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3223 CONSTRUCTOR_ELTS (exp)));
3224 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3226 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3227 ce->index = purpose;
3228 ce->value = copy_constant (value);
3230 CONSTRUCTOR_ELTS (copy) = v;
3239 /* Return the alignment of constant EXP in bits. */
3242 get_constant_alignment (tree exp)
3246 align = TYPE_ALIGN (TREE_TYPE (exp));
3247 #ifdef CONSTANT_ALIGNMENT
3248 align = CONSTANT_ALIGNMENT (exp, align);
3253 /* Return the section into which constant EXP should be placed. */
3256 get_constant_section (tree exp)
3258 if (IN_NAMED_SECTION (exp))
3259 return get_named_section (exp, NULL, compute_reloc_for_constant (exp));
3261 return targetm.asm_out.select_section (exp,
3262 compute_reloc_for_constant (exp),
3263 get_constant_alignment (exp));
3266 /* Return the size of constant EXP in bytes. */
3268 static HOST_WIDE_INT
3269 get_constant_size (tree exp)
3273 size = int_size_in_bytes (TREE_TYPE (exp));
3274 if (TREE_CODE (exp) == STRING_CST)
3275 size = MAX (TREE_STRING_LENGTH (exp), size);
3279 /* Subroutine of output_constant_def:
3280 No constant equal to EXP is known to have been output.
3281 Make a constant descriptor to enter EXP in the hash table.
3282 Assign the label number and construct RTL to refer to the
3283 constant's location in memory.
3284 Caller is responsible for updating the hash table. */
3286 static struct constant_descriptor_tree *
3287 build_constant_desc (tree exp)
3293 struct constant_descriptor_tree *desc;
3295 desc = GGC_NEW (struct constant_descriptor_tree);
3296 desc->value = copy_constant (exp);
3298 /* Propagate marked-ness to copied constant. */
3299 if (flag_mudflap && mf_marked_p (exp))
3300 mf_mark (desc->value);
3302 /* Create a string containing the label name, in LABEL. */
3303 labelno = const_labelno++;
3304 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3306 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3307 if (use_object_blocks_p ())
3309 section *sect = get_constant_section (exp);
3310 symbol = create_block_symbol (ggc_strdup (label),
3311 get_block_for_section (sect), -1);
3314 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3315 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3316 SET_SYMBOL_REF_DECL (symbol, desc->value);
3317 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3319 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3320 set_mem_attributes (rtl, exp, 1);
3321 set_mem_alias_set (rtl, 0);
3322 set_mem_alias_set (rtl, const_alias_set);
3324 /* We cannot share RTX'es in pool entries.
3325 Mark this piece of RTL as required for unsharing. */
3326 RTX_FLAG (rtl, used) = 1;
3328 /* Set flags or add text to the name to record information, such as
3329 that it is a local symbol. If the name is changed, the macro
3330 ASM_OUTPUT_LABELREF will have to know how to strip this
3331 information. This call might invalidate our local variable
3332 SYMBOL; we can't use it afterward. */
3334 targetm.encode_section_info (exp, rtl, true);
3341 /* Return an rtx representing a reference to constant data in memory
3342 for the constant expression EXP.
3344 If assembler code for such a constant has already been output,
3345 return an rtx to refer to it.
3346 Otherwise, output such a constant in memory
3347 and generate an rtx for it.
3349 If DEFER is nonzero, this constant can be deferred and output only
3350 if referenced in the function after all optimizations.
3352 `const_desc_table' records which constants already have label strings. */
3355 output_constant_def (tree exp, int defer)
3357 struct constant_descriptor_tree *desc;
3358 struct constant_descriptor_tree key;
3361 /* Look up EXP in the table of constant descriptors. If we didn't find
3362 it, create a new one. */
3364 key.hash = const_hash_1 (exp);
3365 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3367 desc = (struct constant_descriptor_tree *) *loc;
3370 desc = build_constant_desc (exp);
3371 desc->hash = key.hash;
3375 maybe_output_constant_def_contents (desc, defer);
3379 /* Subroutine of output_constant_def: Decide whether or not we need to
3380 output the constant DESC now, and if so, do it. */
3382 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3385 rtx symbol = XEXP (desc->rtl, 0);
3386 tree exp = desc->value;
3388 if (flag_syntax_only)
3391 if (TREE_ASM_WRITTEN (exp))
3392 /* Already output; don't do it again. */
3395 /* We can always defer constants as long as the context allows
3399 /* Increment n_deferred_constants if it exists. It needs to be at
3400 least as large as the number of constants actually referred to
3401 by the function. If it's too small we'll stop looking too early
3402 and fail to emit constants; if it's too large we'll only look
3403 through the entire function when we could have stopped earlier. */
3405 n_deferred_constants++;
3409 output_constant_def_contents (symbol);
3412 /* Subroutine of output_constant_def_contents. Output the definition
3413 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3414 constant's alignment in bits. */
3417 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3421 size = get_constant_size (exp);
3423 /* Do any machine/system dependent processing of the constant. */
3424 #ifdef ASM_DECLARE_CONSTANT_NAME
3425 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
3427 /* Standard thing is just output label for the constant. */
3428 ASM_OUTPUT_LABEL (asm_out_file, label);
3429 #endif /* ASM_DECLARE_CONSTANT_NAME */
3431 /* Output the value of EXP. */
3432 output_constant (exp, size, align);
3435 /* We must output the constant data referred to by SYMBOL; do so. */
3438 output_constant_def_contents (rtx symbol)
3440 tree exp = SYMBOL_REF_DECL (symbol);
3443 /* Make sure any other constants whose addresses appear in EXP
3444 are assigned label numbers. */
3445 output_addressed_constants (exp);
3447 /* We are no longer deferring this constant. */
3448 TREE_ASM_WRITTEN (exp) = 1;
3450 /* If the constant is part of an object block, make sure that the
3451 decl has been positioned within its block, but do not write out
3452 its definition yet. output_object_blocks will do that later. */
3453 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3454 place_block_symbol (symbol);
3457 switch_to_section (get_constant_section (exp));
3458 align = get_constant_alignment (exp);
3459 if (align > BITS_PER_UNIT)
3460 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3461 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3464 mudflap_enqueue_constant (exp);
3467 /* Look up EXP in the table of constant descriptors. Return the rtl
3468 if it has been emitted, else null. */
3471 lookup_constant_def (tree exp)
3473 struct constant_descriptor_tree *desc;
3474 struct constant_descriptor_tree key;
3477 key.hash = const_hash_1 (exp);
3478 desc = (struct constant_descriptor_tree *)
3479 htab_find_with_hash (const_desc_htab, &key, key.hash);
3481 return (desc ? desc->rtl : NULL_RTX);
3484 /* Used in the hash tables to avoid outputting the same constant
3485 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3486 are output once per function, not once per file. */
3487 /* ??? Only a few targets need per-function constant pools. Most
3488 can use one per-file pool. Should add a targetm bit to tell the
3491 struct GTY(()) rtx_constant_pool {
3492 /* Pointers to first and last constant in pool, as ordered by offset. */
3493 struct constant_descriptor_rtx *first;
3494 struct constant_descriptor_rtx *last;
3496 /* Hash facility for making memory-constants from constant rtl-expressions.
3497 It is used on RISC machines where immediate integer arguments and
3498 constant addresses are restricted so that such constants must be stored
3500 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3502 /* Current offset in constant pool (does not include any
3503 machine-specific header). */
3504 HOST_WIDE_INT offset;
3507 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3508 struct constant_descriptor_rtx *next;
3512 HOST_WIDE_INT offset;
3514 enum machine_mode mode;
3520 /* Hash and compare functions for const_rtx_htab. */
3523 const_desc_rtx_hash (const void *ptr)
3525 const struct constant_descriptor_rtx *const desc
3526 = (const struct constant_descriptor_rtx *) ptr;
3531 const_desc_rtx_eq (const void *a, const void *b)
3533 const struct constant_descriptor_rtx *const x
3534 = (const struct constant_descriptor_rtx *) a;
3535 const struct constant_descriptor_rtx *const y
3536 = (const struct constant_descriptor_rtx *) b;
3538 if (x->mode != y->mode)
3540 return rtx_equal_p (x->constant, y->constant);
3543 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3546 const_rtx_hash_1 (rtx *xp, void *data)
3548 unsigned HOST_WIDE_INT hwi;
3549 enum machine_mode mode;
3555 code = GET_CODE (x);
3556 mode = GET_MODE (x);
3557 h = (hashval_t) code * 1048573 + mode;
3565 int shift = sizeof (hashval_t) * CHAR_BIT;
3566 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3569 h ^= (hashval_t) hwi;
3570 for (i = 1; i < n; ++i)
3573 h ^= (hashval_t) hwi;
3579 if (mode == VOIDmode)
3581 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3585 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3589 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3595 for (i = XVECLEN (x, 0); i-- > 0; )
3596 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3601 h ^= htab_hash_string (XSTR (x, 0));
3605 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3609 case UNSPEC_VOLATILE:
3610 h = h * 251 + XINT (x, 1);
3617 hp = (hashval_t *) data;
3618 *hp = *hp * 509 + h;
3622 /* Compute a hash value for X, which should be a constant. */
3625 const_rtx_hash (rtx x)
3628 for_each_rtx (&x, const_rtx_hash_1, &h);
3633 /* Create and return a new rtx constant pool. */
3635 static struct rtx_constant_pool *
3636 create_constant_pool (void)
3638 struct rtx_constant_pool *pool;
3640 pool = GGC_NEW (struct rtx_constant_pool);
3641 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3642 const_desc_rtx_eq, NULL);
3649 /* Initialize constant pool hashing for a new function. */
3652 init_varasm_status (void)
3654 crtl->varasm.pool = create_constant_pool ();
3655 crtl->varasm.deferred_constants = 0;
3658 /* Given a MINUS expression, simplify it if both sides
3659 include the same symbol. */
3662 simplify_subtraction (rtx x)
3664 rtx r = simplify_rtx (x);
3668 /* Given a constant rtx X, make (or find) a memory constant for its value
3669 and return a MEM rtx to refer to it in memory. */
3672 force_const_mem (enum machine_mode mode, rtx x)
3674 struct constant_descriptor_rtx *desc, tmp;
3675 struct rtx_constant_pool *pool;
3682 /* If we're not allowed to drop X into the constant pool, don't. */
3683 if (targetm.cannot_force_const_mem (x))
3686 /* Record that this function has used a constant pool entry. */
3687 crtl->uses_const_pool = 1;
3689 /* Decide which pool to use. */
3690 pool = (targetm.use_blocks_for_constant_p (mode, x)
3691 ? shared_constant_pool
3692 : crtl->varasm.pool);
3694 /* Lookup the value in the hashtable. */
3697 hash = const_rtx_hash (x);
3698 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3699 desc = (struct constant_descriptor_rtx *) *slot;
3701 /* If the constant was already present, return its memory. */
3703 return copy_rtx (desc->mem);
3705 /* Otherwise, create a new descriptor. */
3706 desc = GGC_NEW (struct constant_descriptor_rtx);
3709 /* Align the location counter as required by EXP's data type. */
3710 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3711 #ifdef CONSTANT_ALIGNMENT
3713 tree type = lang_hooks.types.type_for_mode (mode, 0);
3714 if (type != NULL_TREE)
3715 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3719 pool->offset += (align / BITS_PER_UNIT) - 1;
3720 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3723 desc->constant = tmp.constant;
3724 desc->offset = pool->offset;
3727 desc->align = align;
3728 desc->labelno = const_labelno;
3731 pool->offset += GET_MODE_SIZE (mode);
3733 pool->last->next = desc;
3735 pool->first = pool->last = desc;
3738 /* Create a string containing the label name, in LABEL. */
3739 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3742 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3743 the constants pool. */
3744 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3746 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3747 symbol = create_block_symbol (ggc_strdup (label),
3748 get_block_for_section (sect), -1);
3751 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3753 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3754 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3755 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3757 /* Construct the MEM. */
3758 desc->mem = def = gen_const_mem (mode, symbol);
3759 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3760 set_mem_align (def, align);
3762 /* If we're dropping a label to the constant pool, make sure we
3764 if (GET_CODE (x) == LABEL_REF)
3765 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3767 return copy_rtx (def);
3770 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3773 get_pool_constant (rtx addr)
3775 return SYMBOL_REF_CONSTANT (addr)->constant;
3778 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3779 and whether it has been output or not. */
3782 get_pool_constant_mark (rtx addr, bool *pmarked)
3784 struct constant_descriptor_rtx *desc;
3786 desc = SYMBOL_REF_CONSTANT (addr);
3787 *pmarked = (desc->mark != 0);
3788 return desc->constant;
3791 /* Similar, return the mode. */
3794 get_pool_mode (const_rtx addr)
3796 return SYMBOL_REF_CONSTANT (addr)->mode;
3799 /* Return the size of the constant pool. */
3802 get_pool_size (void)
3804 return crtl->varasm.pool->offset;
3807 /* Worker function for output_constant_pool_1. Emit assembly for X
3808 in MODE with known alignment ALIGN. */
3811 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3813 switch (GET_MODE_CLASS (mode))
3816 case MODE_DECIMAL_FLOAT:
3820 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3821 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3822 assemble_real (r, mode, align);
3827 case MODE_PARTIAL_INT:
3832 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3835 case MODE_VECTOR_FLOAT:
3836 case MODE_VECTOR_INT:
3837 case MODE_VECTOR_FRACT:
3838 case MODE_VECTOR_UFRACT:
3839 case MODE_VECTOR_ACCUM:
3840 case MODE_VECTOR_UACCUM:
3843 enum machine_mode submode = GET_MODE_INNER (mode);
3844 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3846 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3847 units = CONST_VECTOR_NUNITS (x);
3849 for (i = 0; i < units; i++)
3851 rtx elt = CONST_VECTOR_ELT (x, i);
3852 output_constant_pool_2 (submode, elt, i ? subalign : align);
3862 /* Worker function for output_constant_pool. Emit constant DESC,
3863 giving it ALIGN bits of alignment. */
3866 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3873 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3874 whose CODE_LABEL has been deleted. This can occur if a jump table
3875 is eliminated by optimization. If so, write a constant of zero
3876 instead. Note that this can also happen by turning the
3877 CODE_LABEL into a NOTE. */
3878 /* ??? This seems completely and utterly wrong. Certainly it's
3879 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3880 functioning even with INSN_DELETED_P and friends. */
3883 switch (GET_CODE (tmp))
3886 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3887 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3889 tmp = XEXP (XEXP (tmp, 0), 0);
3893 tmp = XEXP (tmp, 0);
3894 gcc_assert (!INSN_DELETED_P (tmp));
3895 gcc_assert (!NOTE_P (tmp)
3896 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3903 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3904 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3905 align, desc->labelno, done);
3908 assemble_align (align);
3910 /* Output the label. */
3911 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3913 /* Output the data. */
3914 output_constant_pool_2 (desc->mode, x, align);
3916 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3917 sections have proper size. */
3918 if (align > GET_MODE_BITSIZE (desc->mode)
3920 && (in_section->common.flags & SECTION_MERGE))
3921 assemble_align (align);
3923 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3929 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3930 to as used. Emit referenced deferred strings. This function can
3931 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3934 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3936 rtx x = *current_rtx;
3938 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3941 if (CONSTANT_POOL_ADDRESS_P (x))
3943 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3944 if (desc->mark == 0)
3947 for_each_rtx (&desc->constant, mark_constant, NULL);
3950 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3952 tree exp = SYMBOL_REF_DECL (x);
3953 if (!TREE_ASM_WRITTEN (exp))
3955 n_deferred_constants--;
3956 output_constant_def_contents (x);
3963 /* Look through appropriate parts of INSN, marking all entries in the
3964 constant pool which are actually being used. Entries that are only
3965 referenced by other constants are also marked as used. Emit
3966 deferred strings that are used. */
3969 mark_constants (rtx insn)
3974 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3975 insns, not any notes that may be attached. We don't want to mark
3976 a constant just because it happens to appear in a REG_EQUIV note. */
3977 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3979 rtx seq = PATTERN (insn);
3980 int i, n = XVECLEN (seq, 0);
3981 for (i = 0; i < n; ++i)
3983 rtx subinsn = XVECEXP (seq, 0, i);
3984 if (INSN_P (subinsn))
3985 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
3989 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
3992 /* Look through the instructions for this function, and mark all the
3993 entries in POOL which are actually being used. Emit deferred constants
3994 which have indeed been used. */
3997 mark_constant_pool (void)
4001 if (!crtl->uses_const_pool && n_deferred_constants == 0)
4004 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4005 mark_constants (insn);
4007 for (link = crtl->epilogue_delay_list;
4009 link = XEXP (link, 1))
4010 mark_constants (XEXP (link, 0));
4013 /* Write all the constants in POOL. */
4016 output_constant_pool_contents (struct rtx_constant_pool *pool)
4018 struct constant_descriptor_rtx *desc;
4020 for (desc = pool->first; desc ; desc = desc->next)
4023 /* If the constant is part of an object_block, make sure that
4024 the constant has been positioned within its block, but do not
4025 write out its definition yet. output_object_blocks will do
4027 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4028 && SYMBOL_REF_BLOCK (desc->sym))
4029 place_block_symbol (desc->sym);
4032 switch_to_section (targetm.asm_out.select_rtx_section
4033 (desc->mode, desc->constant, desc->align));
4034 output_constant_pool_1 (desc, desc->align);
4039 /* Mark all constants that are used in the current function, then write
4040 out the function's private constant pool. */
4043 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
4044 tree fndecl ATTRIBUTE_UNUSED)
4046 struct rtx_constant_pool *pool = crtl->varasm.pool;
4048 /* It is possible for gcc to call force_const_mem and then to later
4049 discard the instructions which refer to the constant. In such a
4050 case we do not need to output the constant. */
4051 mark_constant_pool ();
4053 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4054 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
4057 output_constant_pool_contents (pool);
4059 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4060 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
4064 /* Write the contents of the shared constant pool. */
4067 output_shared_constant_pool (void)
4069 output_constant_pool_contents (shared_constant_pool);
4072 /* Determine what kind of relocations EXP may need. */
4075 compute_reloc_for_constant (tree exp)
4077 int reloc = 0, reloc2;
4080 switch (TREE_CODE (exp))
4084 /* Go inside any operations that get_inner_reference can handle and see
4085 if what's inside is a constant: no need to do anything here for
4086 addresses of variables or functions. */
4087 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4088 tem = TREE_OPERAND (tem, 0))
4091 if (TREE_PUBLIC (tem))
4098 case POINTER_PLUS_EXPR:
4099 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4100 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4104 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4105 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4106 /* The difference of two local labels is computable at link time. */
4107 if (reloc == 1 && reloc2 == 1)
4114 case VIEW_CONVERT_EXPR:
4115 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4120 unsigned HOST_WIDE_INT idx;
4121 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4123 reloc |= compute_reloc_for_constant (tem);
4133 /* Find all the constants whose addresses are referenced inside of EXP,
4134 and make sure assembler code with a label has been output for each one.
4135 Indicate whether an ADDR_EXPR has been encountered. */
4138 output_addressed_constants (tree exp)
4142 switch (TREE_CODE (exp))
4146 /* Go inside any operations that get_inner_reference can handle and see
4147 if what's inside is a constant: no need to do anything here for
4148 addresses of variables or functions. */
4149 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4150 tem = TREE_OPERAND (tem, 0))
4153 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4154 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4155 tem = DECL_INITIAL (tem);
4157 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4158 output_constant_def (tem, 0);
4162 case POINTER_PLUS_EXPR:
4164 output_addressed_constants (TREE_OPERAND (exp, 1));
4168 case VIEW_CONVERT_EXPR:
4169 output_addressed_constants (TREE_OPERAND (exp, 0));
4174 unsigned HOST_WIDE_INT idx;
4175 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4177 output_addressed_constants (tem);
4186 /* Whether a constructor CTOR is a valid static constant initializer if all
4187 its elements are. This used to be internal to initializer_constant_valid_p
4188 and has been exposed to let other functions like categorize_ctor_elements
4189 evaluate the property while walking a constructor for other purposes. */
4192 constructor_static_from_elts_p (const_tree ctor)
4194 return (TREE_CONSTANT (ctor)
4195 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4196 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4197 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4200 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4203 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4204 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4205 which are valid when ENDTYPE is an integer of any size; in
4206 particular, this does not accept a pointer minus a constant. This
4207 returns null_pointer_node if the VALUE is an absolute constant
4208 which can be used to initialize a static variable. Otherwise it
4212 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4216 if (!INTEGRAL_TYPE_P (endtype))
4219 op0 = TREE_OPERAND (value, 0);
4220 op1 = TREE_OPERAND (value, 1);
4222 /* Like STRIP_NOPS except allow the operand mode to widen. This
4223 works around a feature of fold that simplifies (int)(p1 - p2) to
4224 ((int)p1 - (int)p2) under the theory that the narrower operation
4227 while (CONVERT_EXPR_P (op0)
4228 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4230 tree inner = TREE_OPERAND (op0, 0);
4231 if (inner == error_mark_node
4232 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4233 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4234 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4239 while (CONVERT_EXPR_P (op1)
4240 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4242 tree inner = TREE_OPERAND (op1, 0);
4243 if (inner == error_mark_node
4244 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4245 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4246 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4251 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4255 op1 = initializer_constant_valid_p_1 (op1, endtype,
4256 cache ? cache + 2 : NULL);
4257 /* Both initializers must be known. */
4261 && (op0 == null_pointer_node
4262 || TREE_CODE (value) == MINUS_EXPR))
4263 return null_pointer_node;
4265 /* Support differences between labels. */
4266 if (TREE_CODE (op0) == LABEL_DECL
4267 && TREE_CODE (op1) == LABEL_DECL)
4268 return null_pointer_node;
4270 if (TREE_CODE (op0) == STRING_CST
4271 && TREE_CODE (op1) == STRING_CST
4272 && operand_equal_p (op0, op1, 1))
4273 return null_pointer_node;
4279 /* Helper function of initializer_constant_valid_p.
4280 Return nonzero if VALUE is a valid constant-valued expression
4281 for use in initializing a static variable; one that can be an
4282 element of a "constant" initializer.
4284 Return null_pointer_node if the value is absolute;
4285 if it is relocatable, return the variable that determines the relocation.
4286 We assume that VALUE has been folded as much as possible;
4287 therefore, we do not need to check for such things as
4288 arithmetic-combinations of integers.
4290 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4293 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4297 switch (TREE_CODE (value))
4300 if (constructor_static_from_elts_p (value))
4302 unsigned HOST_WIDE_INT idx;
4304 bool absolute = true;
4306 if (cache && cache[0] == value)
4308 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4311 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4318 cache[1] = NULL_TREE;
4322 if (reloc != null_pointer_node)
4325 /* For a non-absolute relocation, there is no single
4326 variable that can be "the variable that determines the
4331 cache[1] = absolute ? null_pointer_node : error_mark_node;
4333 return absolute ? null_pointer_node : error_mark_node;
4336 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4344 return null_pointer_node;
4349 tree op0 = staticp (TREE_OPERAND (value, 0));
4352 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4353 to be a constant, this is old-skool offsetof-like nonsense. */
4354 if (TREE_CODE (op0) == INDIRECT_REF
4355 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4356 return null_pointer_node;
4357 /* Taking the address of a nested function involves a trampoline,
4358 unless we don't need or want one. */
4359 if (TREE_CODE (op0) == FUNCTION_DECL
4360 && DECL_STATIC_CHAIN (op0)
4361 && !TREE_NO_TRAMPOLINE (value))
4363 /* "&{...}" requires a temporary to hold the constructed
4365 if (TREE_CODE (op0) == CONSTRUCTOR)
4371 case NON_LVALUE_EXPR:
4372 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4375 case VIEW_CONVERT_EXPR:
4377 tree src = TREE_OPERAND (value, 0);
4378 tree src_type = TREE_TYPE (src);
4379 tree dest_type = TREE_TYPE (value);
4381 /* Allow view-conversions from aggregate to non-aggregate type only
4382 if the bit pattern is fully preserved afterwards; otherwise, the
4383 RTL expander won't be able to apply a subsequent transformation
4384 to the underlying constructor. */
4385 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4387 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4388 return initializer_constant_valid_p_1 (src, endtype, cache);
4393 /* Allow all other kinds of view-conversion. */
4394 return initializer_constant_valid_p_1 (src, endtype, cache);
4399 tree src = TREE_OPERAND (value, 0);
4400 tree src_type = TREE_TYPE (src);
4401 tree dest_type = TREE_TYPE (value);
4403 /* Allow conversions between pointer types, floating-point
4404 types, and offset types. */
4405 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4406 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4407 || (TREE_CODE (dest_type) == OFFSET_TYPE
4408 && TREE_CODE (src_type) == OFFSET_TYPE))
4409 return initializer_constant_valid_p_1 (src, endtype, cache);
4411 /* Allow length-preserving conversions between integer types. */
4412 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4413 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4414 return initializer_constant_valid_p_1 (src, endtype, cache);
4416 /* Allow conversions between other integer types only if
4418 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4420 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4421 if (inner == null_pointer_node)
4422 return null_pointer_node;
4426 /* Allow (int) &foo provided int is as wide as a pointer. */
4427 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4428 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4429 return initializer_constant_valid_p_1 (src, endtype, cache);
4431 /* Likewise conversions from int to pointers, but also allow
4432 conversions from 0. */
4433 if ((POINTER_TYPE_P (dest_type)
4434 || TREE_CODE (dest_type) == OFFSET_TYPE)
4435 && INTEGRAL_TYPE_P (src_type))
4437 if (TREE_CODE (src) == INTEGER_CST
4438 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4439 return null_pointer_node;
4440 if (integer_zerop (src))
4441 return null_pointer_node;
4442 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4443 return initializer_constant_valid_p_1 (src, endtype, cache);
4446 /* Allow conversions to struct or union types if the value
4448 if (TREE_CODE (dest_type) == RECORD_TYPE
4449 || TREE_CODE (dest_type) == UNION_TYPE)
4450 return initializer_constant_valid_p_1 (src, endtype, cache);
4454 case POINTER_PLUS_EXPR:
4456 /* Any valid floating-point constants will have been folded by now;
4457 with -frounding-math we hit this with addition of two constants. */
4458 if (TREE_CODE (endtype) == REAL_TYPE)
4460 if (cache && cache[0] == value)
4462 if (! INTEGRAL_TYPE_P (endtype)
4463 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4465 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4467 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4470 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4471 endtype, ncache + 2);
4472 /* If either term is absolute, use the other term's relocation. */
4473 if (valid0 == null_pointer_node)
4475 else if (valid1 == null_pointer_node)
4477 /* Support narrowing pointer differences. */
4479 ret = narrowing_initializer_constant_valid_p (value, endtype,
4483 /* Support narrowing pointer differences. */
4484 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4493 if (TREE_CODE (endtype) == REAL_TYPE)
4495 if (cache && cache[0] == value)
4497 if (! INTEGRAL_TYPE_P (endtype)
4498 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4500 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4502 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4505 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4506 endtype, ncache + 2);
4507 /* Win if second argument is absolute. */
4508 if (valid1 == null_pointer_node)
4510 /* Win if both arguments have the same relocation.
4511 Then the value is absolute. */
4512 else if (valid0 == valid1 && valid0 != 0)
4513 ret = null_pointer_node;
4514 /* Since GCC guarantees that string constants are unique in the
4515 generated code, a subtraction between two copies of the same
4516 constant string is absolute. */
4517 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4518 && valid1 && TREE_CODE (valid1) == STRING_CST
4519 && operand_equal_p (valid0, valid1, 1))
4520 ret = null_pointer_node;
4521 /* Support narrowing differences. */
4523 ret = narrowing_initializer_constant_valid_p (value, endtype,
4527 /* Support narrowing differences. */
4528 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4543 /* Return nonzero if VALUE is a valid constant-valued expression
4544 for use in initializing a static variable; one that can be an
4545 element of a "constant" initializer.
4547 Return null_pointer_node if the value is absolute;
4548 if it is relocatable, return the variable that determines the relocation.
4549 We assume that VALUE has been folded as much as possible;
4550 therefore, we do not need to check for such things as
4551 arithmetic-combinations of integers. */
4553 initializer_constant_valid_p (tree value, tree endtype)
4555 return initializer_constant_valid_p_1 (value, endtype, NULL);
4558 /* Return true if VALUE is a valid constant-valued expression
4559 for use in initializing a static bit-field; one that can be
4560 an element of a "constant" initializer. */
4563 initializer_constant_valid_for_bitfield_p (tree value)
4565 /* For bitfields we support integer constants or possibly nested aggregates
4567 switch (TREE_CODE (value))
4571 unsigned HOST_WIDE_INT idx;
4574 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4575 if (!initializer_constant_valid_for_bitfield_p (elt))
4583 case VIEW_CONVERT_EXPR:
4584 case NON_LVALUE_EXPR:
4586 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4595 /* output_constructor outer state of relevance in recursive calls, typically
4596 for nested aggregate bitfields. */
4599 unsigned int bit_offset; /* current position in ... */
4600 int byte; /* ... the outer byte buffer. */
4603 static unsigned HOST_WIDE_INT
4604 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4607 /* Output assembler code for constant EXP to FILE, with no label.
4608 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4609 Assumes output_addressed_constants has been done on EXP already.
4611 Generate exactly SIZE bytes of assembler data, padding at the end
4612 with zeros if necessary. SIZE must always be specified.
4614 SIZE is important for structure constructors,
4615 since trailing members may have been omitted from the constructor.
4616 It is also important for initialization of arrays from string constants
4617 since the full length of the string constant might not be wanted.
4618 It is also needed for initialization of unions, where the initializer's
4619 type is just one member, and that may not be as long as the union.
4621 There a case in which we would fail to output exactly SIZE bytes:
4622 for a structure constructor that wants to produce more than SIZE bytes.
4623 But such constructors will never be generated for any possible input.
4625 ALIGN is the alignment of the data in bits. */
4628 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4630 enum tree_code code;
4631 unsigned HOST_WIDE_INT thissize;
4633 if (size == 0 || flag_syntax_only)
4636 /* See if we're trying to initialize a pointer in a non-default mode
4637 to the address of some declaration somewhere. If the target says
4638 the mode is valid for pointers, assume the target has a way of
4640 if (TREE_CODE (exp) == NOP_EXPR
4641 && POINTER_TYPE_P (TREE_TYPE (exp))
4642 && targetm.addr_space.valid_pointer_mode
4643 (TYPE_MODE (TREE_TYPE (exp)),
4644 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4646 tree saved_type = TREE_TYPE (exp);
4648 /* Peel off any intermediate conversions-to-pointer for valid
4650 while (TREE_CODE (exp) == NOP_EXPR
4651 && POINTER_TYPE_P (TREE_TYPE (exp))
4652 && targetm.addr_space.valid_pointer_mode
4653 (TYPE_MODE (TREE_TYPE (exp)),
4654 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4655 exp = TREE_OPERAND (exp, 0);
4657 /* If what we're left with is the address of something, we can
4658 convert the address to the final type and output it that
4660 if (TREE_CODE (exp) == ADDR_EXPR)
4661 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4662 /* Likewise for constant ints. */
4663 else if (TREE_CODE (exp) == INTEGER_CST)
4664 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4665 TREE_INT_CST_HIGH (exp));
4669 /* Eliminate any conversions since we'll be outputting the underlying
4671 while (CONVERT_EXPR_P (exp)
4672 || TREE_CODE (exp) == NON_LVALUE_EXPR
4673 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4675 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4676 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4678 /* Make sure eliminating the conversion is really a no-op, except with
4679 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4680 union types to allow for Ada unchecked unions. */
4681 if (type_size > op_size
4682 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4683 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4684 /* Keep the conversion. */
4687 exp = TREE_OPERAND (exp, 0);
4690 code = TREE_CODE (TREE_TYPE (exp));
4691 thissize = int_size_in_bytes (TREE_TYPE (exp));
4693 /* Allow a constructor with no elements for any data type.
4694 This means to fill the space with zeros. */
4695 if (TREE_CODE (exp) == CONSTRUCTOR
4696 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4698 assemble_zeros (size);
4702 if (TREE_CODE (exp) == FDESC_EXPR)
4704 #ifdef ASM_OUTPUT_FDESC
4705 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4706 tree decl = TREE_OPERAND (exp, 0);
4707 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4714 /* Now output the underlying data. If we've handling the padding, return.
4715 Otherwise, break and ensure SIZE is the size written. */
4722 case REFERENCE_TYPE:
4724 case FIXED_POINT_TYPE:
4725 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4726 EXPAND_INITIALIZER),
4727 MIN (size, thissize), align, 0))
4728 error ("initializer for integer/fixed-point value is too complicated");
4732 if (TREE_CODE (exp) != REAL_CST)
4733 error ("initializer for floating value is not a floating constant");
4735 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4739 output_constant (TREE_REALPART (exp), thissize / 2, align);
4740 output_constant (TREE_IMAGPART (exp), thissize / 2,
4741 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4746 switch (TREE_CODE (exp))
4749 output_constructor (exp, size, align, NULL);
4752 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4754 assemble_string (TREE_STRING_POINTER (exp), thissize);
4761 unsigned int nalign;
4762 enum machine_mode inner;
4764 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4765 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4767 elt_size = GET_MODE_SIZE (inner);
4769 link = TREE_VECTOR_CST_ELTS (exp);
4770 output_constant (TREE_VALUE (link), elt_size, align);
4771 thissize = elt_size;
4772 while ((link = TREE_CHAIN (link)) != NULL)
4774 output_constant (TREE_VALUE (link), elt_size, nalign);
4775 thissize += elt_size;
4786 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4787 output_constructor (exp, size, align, NULL);
4797 if (size > thissize)
4798 assemble_zeros (size - thissize);
4802 /* Subroutine of output_constructor, used for computing the size of
4803 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4804 type with an unspecified upper bound. */
4806 static unsigned HOST_WIDE_INT
4807 array_size_for_constructor (tree val)
4810 unsigned HOST_WIDE_INT cnt;
4811 tree index, value, tmp;
4813 /* This code used to attempt to handle string constants that are not
4814 arrays of single-bytes, but nothing else does, so there's no point in
4816 if (TREE_CODE (val) == STRING_CST)
4817 return TREE_STRING_LENGTH (val);
4819 max_index = NULL_TREE;
4820 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4822 if (TREE_CODE (index) == RANGE_EXPR)
4823 index = TREE_OPERAND (index, 1);
4824 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4828 if (max_index == NULL_TREE)
4831 /* Compute the total number of array elements. */
4832 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4833 i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4834 fold_convert (sizetype, tmp));
4835 i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4837 /* Multiply by the array element unit size to find number of bytes. */
4838 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4840 return tree_low_cst (i, 1);
4843 /* Other datastructures + helpers for output_constructor. */
4845 /* output_constructor local state to support interaction with helpers. */
4849 /* Received arguments. */
4850 tree exp; /* Constructor expression. */
4851 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4852 unsigned int align; /* Known initial alignment. */
4854 /* Constructor expression data. */
4855 tree type; /* Expression type. */
4856 tree field; /* Current field decl in a record. */
4857 tree min_index; /* Lower bound if specified for an array. */
4859 /* Output processing state. */
4860 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4861 bool byte_buffer_in_use; /* Whether byte ... */
4862 int byte; /* ... contains part of a bitfield byte yet to
4865 int last_relative_index; /* Implicit or explicit index of the last
4866 array element output within a bitfield. */
4867 /* Current element. */
4868 tree val; /* Current element value. */
4869 tree index; /* Current element index. */
4873 /* Helper for output_constructor. From the current LOCAL state, output a
4874 RANGE_EXPR element. */
4877 output_constructor_array_range (oc_local_state *local)
4879 unsigned HOST_WIDE_INT fieldsize
4880 = int_size_in_bytes (TREE_TYPE (local->type));
4882 HOST_WIDE_INT lo_index
4883 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4884 HOST_WIDE_INT hi_index
4885 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4886 HOST_WIDE_INT index;
4889 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4891 for (index = lo_index; index <= hi_index; index++)
4893 /* Output the element's initial value. */
4894 if (local->val == NULL_TREE)
4895 assemble_zeros (fieldsize);
4897 output_constant (local->val, fieldsize, align2);
4899 /* Count its size. */
4900 local->total_bytes += fieldsize;
4904 /* Helper for output_constructor. From the current LOCAL state, output a
4905 field element that is not true bitfield or part of an outer one. */
4908 output_constructor_regular_field (oc_local_state *local)
4910 /* Field size and position. Since this structure is static, we know the
4911 positions are constant. */
4912 unsigned HOST_WIDE_INT fieldsize;
4913 HOST_WIDE_INT fieldpos;
4915 unsigned int align2;
4917 if (local->index != NULL_TREE)
4918 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
4919 * ((tree_low_cst (local->index, 0)
4920 - tree_low_cst (local->min_index, 0))));
4921 else if (local->field != NULL_TREE)
4922 fieldpos = int_byte_position (local->field);
4926 /* Output any buffered-up bit-fields preceding this element. */
4927 if (local->byte_buffer_in_use)
4929 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4930 local->total_bytes++;
4931 local->byte_buffer_in_use = false;
4934 /* Advance to offset of this element.
4935 Note no alignment needed in an array, since that is guaranteed
4936 if each element has the proper size. */
4937 if ((local->field != NULL_TREE || local->index != NULL_TREE)
4938 && fieldpos != local->total_bytes)
4940 gcc_assert (fieldpos >= local->total_bytes);
4941 assemble_zeros (fieldpos - local->total_bytes);
4942 local->total_bytes = fieldpos;
4945 /* Find the alignment of this element. */
4946 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
4948 /* Determine size this element should occupy. */
4953 /* If this is an array with an unspecified upper bound,
4954 the initializer determines the size. */
4955 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4956 but we cannot do this until the deprecated support for
4957 initializing zero-length array members is removed. */
4958 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
4959 && TYPE_DOMAIN (TREE_TYPE (local->field))
4960 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
4962 fieldsize = array_size_for_constructor (local->val);
4963 /* Given a non-empty initialization, this field had
4965 gcc_assert (!fieldsize || !TREE_CHAIN (local->field));
4967 else if (DECL_SIZE_UNIT (local->field))
4969 /* ??? This can't be right. If the decl size overflows
4970 a host integer we will silently emit no data. */
4971 if (host_integerp (DECL_SIZE_UNIT (local->field), 1))
4972 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
4976 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
4978 /* Output the element's initial value. */
4979 if (local->val == NULL_TREE)
4980 assemble_zeros (fieldsize);
4982 output_constant (local->val, fieldsize, align2);
4984 /* Count its size. */
4985 local->total_bytes += fieldsize;
4988 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4989 output an element that is a true bitfield or part of an outer one. */
4992 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
4994 /* Bit size of this element. */
4995 HOST_WIDE_INT ebitsize
4997 ? tree_low_cst (DECL_SIZE (local->field), 1)
4998 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
5000 /* Relative index of this element if this is an array component. */
5001 HOST_WIDE_INT relative_index
5004 ? (tree_low_cst (local->index, 0)
5005 - tree_low_cst (local->min_index, 0))
5006 : local->last_relative_index + 1)
5009 /* Bit position of this element from the start of the containing
5011 HOST_WIDE_INT constructor_relative_ebitpos
5013 ? int_bit_position (local->field)
5014 : ebitsize * relative_index);
5016 /* Bit position of this element from the start of a possibly ongoing
5017 outer byte buffer. */
5018 HOST_WIDE_INT byte_relative_ebitpos
5019 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
5021 /* From the start of a possibly ongoing outer byte buffer, offsets to
5022 the first bit of this element and to the first bit past the end of
5024 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
5025 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
5027 local->last_relative_index = relative_index;
5029 if (local->val == NULL_TREE)
5030 local->val = integer_zero_node;
5032 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
5033 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
5034 local->val = TREE_OPERAND (local->val, 0);
5036 if (TREE_CODE (local->val) != INTEGER_CST
5037 && TREE_CODE (local->val) != CONSTRUCTOR)
5039 error ("invalid initial value for member %qE", DECL_NAME (local->field));
5043 /* If this field does not start in this (or, next) byte,
5045 if (next_offset / BITS_PER_UNIT != local->total_bytes)
5047 /* Output remnant of any bit field in previous bytes. */
5048 if (local->byte_buffer_in_use)
5050 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5051 local->total_bytes++;
5052 local->byte_buffer_in_use = false;
5055 /* If still not at proper byte, advance to there. */
5056 if (next_offset / BITS_PER_UNIT != local->total_bytes)
5058 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
5059 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
5060 local->total_bytes = next_offset / BITS_PER_UNIT;
5064 /* Set up the buffer if necessary. */
5065 if (!local->byte_buffer_in_use)
5069 local->byte_buffer_in_use = true;
5072 /* If this is nested constructor, recurse passing the bit offset and the
5073 pending data, then retrieve the new pending data afterwards. */
5074 if (TREE_CODE (local->val) == CONSTRUCTOR)
5076 oc_outer_state output_state;
5078 output_state.bit_offset = next_offset % BITS_PER_UNIT;
5079 output_state.byte = local->byte;
5081 += output_constructor (local->val, 0, 0, &output_state);
5082 local->byte = output_state.byte;
5086 /* Otherwise, we must split the element into pieces that fall within
5087 separate bytes, and combine each byte with previous or following
5089 while (next_offset < end_offset)
5093 HOST_WIDE_INT value;
5094 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
5095 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
5097 /* Advance from byte to byte
5098 within this element when necessary. */
5099 while (next_byte != local->total_bytes)
5101 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5102 local->total_bytes++;
5106 /* Number of bits we can process at once
5107 (all part of the same byte). */
5108 this_time = MIN (end_offset - next_offset,
5109 BITS_PER_UNIT - next_bit);
5110 if (BYTES_BIG_ENDIAN)
5112 /* On big-endian machine, take the most significant bits
5113 first (of the bits that are significant)
5114 and put them into bytes from the most significant end. */
5115 shift = end_offset - next_offset - this_time;
5117 /* Don't try to take a bunch of bits that cross
5118 the word boundary in the INTEGER_CST. We can
5119 only select bits from the LOW or HIGH part
5121 if (shift < HOST_BITS_PER_WIDE_INT
5122 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5124 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
5125 shift = HOST_BITS_PER_WIDE_INT;
5128 /* Now get the bits from the appropriate constant word. */
5129 if (shift < HOST_BITS_PER_WIDE_INT)
5130 value = TREE_INT_CST_LOW (local->val);
5133 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5134 value = TREE_INT_CST_HIGH (local->val);
5135 shift -= HOST_BITS_PER_WIDE_INT;
5138 /* Get the result. This works only when:
5139 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5140 local->byte |= (((value >> shift)
5141 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5142 << (BITS_PER_UNIT - this_time - next_bit));
5146 /* On little-endian machines,
5147 take first the least significant bits of the value
5148 and pack them starting at the least significant
5149 bits of the bytes. */
5150 shift = next_offset - byte_relative_ebitpos;
5152 /* Don't try to take a bunch of bits that cross
5153 the word boundary in the INTEGER_CST. We can
5154 only select bits from the LOW or HIGH part
5156 if (shift < HOST_BITS_PER_WIDE_INT
5157 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5158 this_time = (HOST_BITS_PER_WIDE_INT - shift);
5160 /* Now get the bits from the appropriate constant word. */
5161 if (shift < HOST_BITS_PER_WIDE_INT)
5162 value = TREE_INT_CST_LOW (local->val);
5165 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5166 value = TREE_INT_CST_HIGH (local->val);
5167 shift -= HOST_BITS_PER_WIDE_INT;
5170 /* Get the result. This works only when:
5171 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5172 local->byte |= (((value >> shift)
5173 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5177 next_offset += this_time;
5178 local->byte_buffer_in_use = true;
5182 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5183 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5184 caller output state of relevance in recursive invocations. */
5186 static unsigned HOST_WIDE_INT
5187 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
5188 unsigned int align, oc_outer_state * outer)
5190 unsigned HOST_WIDE_INT cnt;
5191 constructor_elt *ce;
5193 oc_local_state local;
5195 /* Setup our local state to communicate with helpers. */
5198 local.align = align;
5200 local.total_bytes = 0;
5201 local.byte_buffer_in_use = outer != NULL;
5202 local.byte = outer ? outer->byte : 0;
5204 local.type = TREE_TYPE (exp);
5206 local.last_relative_index = -1;
5208 local.min_index = NULL_TREE;
5209 if (TREE_CODE (local.type) == ARRAY_TYPE
5210 && TYPE_DOMAIN (local.type) != NULL_TREE)
5211 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5213 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
5215 /* As CE goes through the elements of the constant, FIELD goes through the
5216 structure fields if the constant is a structure. If the constant is a
5217 union, we override this by getting the field from the TREE_LIST element.
5218 But the constant could also be an array. Then FIELD is zero.
5220 There is always a maximum of one element in the chain LINK for unions
5221 (even if the initializer in a source program incorrectly contains
5224 local.field = NULL_TREE;
5225 if (TREE_CODE (local.type) == RECORD_TYPE)
5226 local.field = TYPE_FIELDS (local.type);
5229 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
5230 cnt++, local.field = local.field ? TREE_CHAIN (local.field) : 0)
5232 local.val = ce->value;
5233 local.index = NULL_TREE;
5235 /* The element in a union constructor specifies the proper field
5237 if ((TREE_CODE (local.type) == RECORD_TYPE
5238 || TREE_CODE (local.type) == UNION_TYPE
5239 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
5240 && ce->index != NULL_TREE)
5241 local.field = ce->index;
5243 else if (TREE_CODE (local.type) == ARRAY_TYPE)
5244 local.index = ce->index;
5246 #ifdef ASM_COMMENT_START
5247 if (local.field && flag_verbose_asm)
5248 fprintf (asm_out_file, "%s %s:\n",
5250 DECL_NAME (local.field)
5251 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
5255 /* Eliminate the marker that makes a cast not be an lvalue. */
5256 if (local.val != NULL_TREE)
5257 STRIP_NOPS (local.val);
5259 /* Output the current element, using the appropriate helper ... */
5261 /* For an array slice not part of an outer bitfield. */
5263 && local.index != NULL_TREE
5264 && TREE_CODE (local.index) == RANGE_EXPR)
5265 output_constructor_array_range (&local);
5267 /* For a field that is neither a true bitfield nor part of an outer one,
5268 known to be at least byte aligned and multiple-of-bytes long. */
5270 && (local.field == NULL_TREE
5271 || !CONSTRUCTOR_BITFIELD_P (local.field)))
5272 output_constructor_regular_field (&local);
5274 /* For a true bitfield or part of an outer one. */
5276 output_constructor_bitfield (&local, outer);
5279 /* If we are not at toplevel, save the pending data for our caller.
5280 Otherwise output the pending data and padding zeros as needed. */
5282 outer->byte = local.byte;
5285 if (local.byte_buffer_in_use)
5287 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
5288 local.total_bytes++;
5291 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
5293 assemble_zeros (local.size - local.total_bytes);
5294 local.total_bytes = local.size;
5298 return local.total_bytes;
5301 /* Mark DECL as weak. */
5304 mark_weak (tree decl)
5306 DECL_WEAK (decl) = 1;
5308 if (DECL_RTL_SET_P (decl)
5309 && MEM_P (DECL_RTL (decl))
5310 && XEXP (DECL_RTL (decl), 0)
5311 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5312 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5315 /* Merge weak status between NEWDECL and OLDDECL. */
5318 merge_weak (tree newdecl, tree olddecl)
5320 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5322 if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
5325 /* We put the NEWDECL on the weak_decls list at some point
5326 and OLDDECL as well. Keep just OLDDECL on the list. */
5327 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5328 if (TREE_VALUE (*pwd) == newdecl)
5330 *pwd = TREE_CHAIN (*pwd);
5337 if (DECL_WEAK (newdecl))
5341 /* NEWDECL is weak, but OLDDECL is not. */
5343 /* If we already output the OLDDECL, we're in trouble; we can't
5344 go back and make it weak. This error cannot be caught in
5345 declare_weak because the NEWDECL and OLDDECL was not yet
5346 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5347 if (TREE_ASM_WRITTEN (olddecl))
5348 error ("weak declaration of %q+D must precede definition",
5351 /* If we've already generated rtl referencing OLDDECL, we may
5352 have done so in a way that will not function properly with
5354 else if (TREE_USED (olddecl)
5355 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
5356 warning (0, "weak declaration of %q+D after first use results "
5357 "in unspecified behavior", newdecl);
5361 /* We put the NEWDECL on the weak_decls list at some point.
5362 Replace it with the OLDDECL. */
5363 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5364 if (TREE_VALUE (wd) == newdecl)
5366 TREE_VALUE (wd) = olddecl;
5369 /* We may not find the entry on the list. If NEWDECL is a
5370 weak alias, then we will have already called
5371 globalize_decl to remove the entry; in that case, we do
5372 not need to do anything. */
5375 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5376 mark_weak (olddecl);
5379 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5380 weak. Just update NEWDECL to indicate that it's weak too. */
5381 mark_weak (newdecl);
5384 /* Declare DECL to be a weak symbol. */
5387 declare_weak (tree decl)
5389 if (! TREE_PUBLIC (decl))
5390 error ("weak declaration of %q+D must be public", decl);
5391 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
5392 error ("weak declaration of %q+D must precede definition", decl);
5393 else if (!SUPPORTS_WEAK)
5394 warning (0, "weak declaration of %q+D not supported", decl);
5397 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5398 DECL_ATTRIBUTES (decl)
5399 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5403 weak_finish_1 (tree decl)
5405 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5406 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5409 if (! TREE_USED (decl))
5412 #ifdef ASM_WEAKEN_DECL
5413 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5415 #ifdef ASM_WEAKEN_LABEL
5416 ASM_WEAKEN_LABEL (asm_out_file, name);
5418 #ifdef ASM_OUTPUT_WEAK_ALIAS
5420 static bool warn_once = 0;
5423 warning (0, "only weak aliases are supported in this configuration");
5433 /* This TREE_LIST contains weakref targets. */
5435 static GTY(()) tree weakref_targets;
5437 /* Forward declaration. */
5438 static tree find_decl_and_mark_needed (tree decl, tree target);
5440 /* Emit any pending weak declarations. */
5447 for (t = weakref_targets; t; t = TREE_CHAIN (t))
5449 tree alias_decl = TREE_PURPOSE (t);
5450 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5452 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5453 /* Remove alias_decl from the weak list, but leave entries for
5454 the target alone. */
5456 #ifndef ASM_OUTPUT_WEAKREF
5457 else if (! TREE_SYMBOL_REFERENCED (target))
5459 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5460 defined, otherwise we and weak_finish_1 would use
5461 different macros. */
5462 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5463 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5465 tree decl = find_decl_and_mark_needed (alias_decl, target);
5469 decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5470 TREE_CODE (alias_decl), target,
5471 TREE_TYPE (alias_decl));
5473 DECL_EXTERNAL (decl) = 1;
5474 TREE_PUBLIC (decl) = 1;
5475 DECL_ARTIFICIAL (decl) = 1;
5476 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5477 TREE_USED (decl) = 1;
5480 weak_finish_1 (decl);
5489 /* Remove the alias and the target from the pending weak list
5490 so that we do not emit any .weak directives for the former,
5491 nor multiple .weak directives for the latter. */
5492 for (p = &weak_decls; (t2 = *p) ; )
5494 if (TREE_VALUE (t2) == alias_decl
5495 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5496 *p = TREE_CHAIN (t2);
5498 p = &TREE_CHAIN (t2);
5501 /* Remove other weakrefs to the same target, to speed things up. */
5502 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5504 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5505 *p = TREE_CHAIN (t2);
5507 p = &TREE_CHAIN (t2);
5512 for (t = weak_decls; t; t = TREE_CHAIN (t))
5514 tree decl = TREE_VALUE (t);
5516 weak_finish_1 (decl);
5520 /* Emit the assembly bits to indicate that DECL is globally visible. */
5523 globalize_decl (tree decl)
5526 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5527 if (DECL_WEAK (decl))
5529 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5532 #ifdef ASM_WEAKEN_DECL
5533 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5535 ASM_WEAKEN_LABEL (asm_out_file, name);
5538 /* Remove this function from the pending weak list so that
5539 we do not emit multiple .weak directives for it. */
5540 for (p = &weak_decls; (t = *p) ; )
5542 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5543 *p = TREE_CHAIN (t);
5545 p = &TREE_CHAIN (t);
5548 /* Remove weakrefs to the same target from the pending weakref
5549 list, for the same reason. */
5550 for (p = &weakref_targets; (t = *p) ; )
5552 if (DECL_ASSEMBLER_NAME (decl)
5553 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5554 *p = TREE_CHAIN (t);
5556 p = &TREE_CHAIN (t);
5563 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5566 VEC(alias_pair,gc) *alias_pairs;
5568 /* Given an assembly name, find the decl it is associated with. At the
5569 same time, mark it needed for cgraph. */
5572 find_decl_and_mark_needed (tree decl, tree target)
5574 struct cgraph_node *fnode = NULL;
5575 struct varpool_node *vnode = NULL;
5577 if (TREE_CODE (decl) == FUNCTION_DECL)
5579 fnode = cgraph_node_for_asm (target);
5581 vnode = varpool_node_for_asm (target);
5585 vnode = varpool_node_for_asm (target);
5587 fnode = cgraph_node_for_asm (target);
5592 cgraph_mark_needed_node (fnode);
5597 varpool_mark_needed_node (vnode);
5604 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5605 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5606 tree node is DECL to have the value of the tree node TARGET. */
5609 do_assemble_alias (tree decl, tree target)
5611 if (TREE_ASM_WRITTEN (decl))
5614 /* We must force creation of DECL_RTL for debug info generation, even though
5615 we don't use it here. */
5616 make_decl_rtl (decl);
5618 TREE_ASM_WRITTEN (decl) = 1;
5619 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5621 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5623 ultimate_transparent_alias_target (&target);
5625 if (!targetm.have_tls
5626 && TREE_CODE (decl) == VAR_DECL
5627 && DECL_THREAD_LOCAL_P (decl))
5629 decl = emutls_decl (decl);
5630 target = get_emutls_object_name (target);
5633 if (!TREE_SYMBOL_REFERENCED (target))
5634 weakref_targets = tree_cons (decl, target, weakref_targets);
5636 #ifdef ASM_OUTPUT_WEAKREF
5637 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5638 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5639 IDENTIFIER_POINTER (target));
5643 error_at (DECL_SOURCE_LOCATION (decl),
5644 "weakref is not supported in this configuration");
5651 if (!targetm.have_tls
5652 && TREE_CODE (decl) == VAR_DECL
5653 && DECL_THREAD_LOCAL_P (decl))
5655 decl = emutls_decl (decl);
5656 target = get_emutls_object_name (target);
5659 #ifdef ASM_OUTPUT_DEF
5660 /* Make name accessible from other files, if appropriate. */
5662 if (TREE_PUBLIC (decl))
5664 globalize_decl (decl);
5665 maybe_assemble_visibility (decl);
5668 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5669 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5671 ASM_OUTPUT_DEF (asm_out_file,
5672 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5673 IDENTIFIER_POINTER (target));
5675 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5680 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5681 # ifdef ASM_WEAKEN_DECL
5682 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5684 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5686 /* Remove this function from the pending weak list so that
5687 we do not emit multiple .weak directives for it. */
5688 for (p = &weak_decls; (t = *p) ; )
5689 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5690 *p = TREE_CHAIN (t);
5692 p = &TREE_CHAIN (t);
5694 /* Remove weakrefs to the same target from the pending weakref
5695 list, for the same reason. */
5696 for (p = &weakref_targets; (t = *p) ; )
5698 if (DECL_ASSEMBLER_NAME (decl)
5699 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5700 *p = TREE_CHAIN (t);
5702 p = &TREE_CHAIN (t);
5709 /* Remove the alias pairing for functions that are no longer in the call
5713 remove_unreachable_alias_pairs (void)
5718 if (alias_pairs == NULL)
5721 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5723 if (!DECL_EXTERNAL (p->decl))
5725 struct cgraph_node *fnode = NULL;
5726 struct varpool_node *vnode = NULL;
5727 fnode = cgraph_node_for_asm (p->target);
5728 vnode = (fnode == NULL) ? varpool_node_for_asm (p->target) : NULL;
5729 if (fnode == NULL && vnode == NULL)
5731 VEC_unordered_remove (alias_pair, alias_pairs, i);
5741 /* First pass of completing pending aliases. Make sure that cgraph knows
5742 which symbols will be required. */
5745 finish_aliases_1 (void)
5750 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5754 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5755 if (target_decl == NULL)
5757 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5758 error ("%q+D aliased to undefined symbol %qE",
5759 p->decl, p->target);
5761 else if (DECL_EXTERNAL (target_decl)
5762 /* We use local aliases for C++ thunks to force the tailcall
5763 to bind locally. Of course this is a hack - to keep it
5764 working do the following (which is not strictly correct). */
5765 && (! TREE_CODE (target_decl) == FUNCTION_DECL
5766 || ! DECL_VIRTUAL_P (target_decl))
5767 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5768 error ("%q+D aliased to external symbol %qE",
5769 p->decl, p->target);
5773 /* Second pass of completing pending aliases. Emit the actual assembly.
5774 This happens at the end of compilation and thus it is assured that the
5775 target symbol has been emitted. */
5778 finish_aliases_2 (void)
5783 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5784 do_assemble_alias (p->decl, p->target);
5786 VEC_truncate (alias_pair, alias_pairs, 0);
5789 /* Emit an assembler directive to make the symbol for DECL an alias to
5790 the symbol for TARGET. */
5793 assemble_alias (tree decl, tree target)
5796 bool is_weakref = false;
5798 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5800 tree alias = DECL_ASSEMBLER_NAME (decl);
5804 ultimate_transparent_alias_target (&target);
5806 if (alias == target)
5807 error ("weakref %q+D ultimately targets itself", decl);
5810 #ifndef ASM_OUTPUT_WEAKREF
5811 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5812 TREE_CHAIN (alias) = target;
5815 if (TREE_PUBLIC (decl))
5816 error ("weakref %q+D must have static linkage", decl);
5820 #if !defined (ASM_OUTPUT_DEF)
5821 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5822 error_at (DECL_SOURCE_LOCATION (decl),
5823 "alias definitions not supported in this configuration");
5826 if (!DECL_WEAK (decl))
5828 error_at (DECL_SOURCE_LOCATION (decl),
5829 "only weak aliases are supported in this configuration");
5835 TREE_USED (decl) = 1;
5837 /* A quirk of the initial implementation of aliases required that the user
5838 add "extern" to all of them. Which is silly, but now historical. Do
5839 note that the symbol is in fact locally defined. */
5841 DECL_EXTERNAL (decl) = 0;
5843 /* Allow aliases to aliases. */
5844 if (TREE_CODE (decl) == FUNCTION_DECL)
5845 cgraph_node (decl)->alias = true;
5847 varpool_node (decl)->alias = true;
5849 /* If the target has already been emitted, we don't have to queue the
5850 alias. This saves a tad of memory. */
5851 if (cgraph_global_info_ready)
5852 target_decl = find_decl_and_mark_needed (decl, target);
5855 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5856 do_assemble_alias (decl, target);
5859 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5865 /* Emit an assembler directive to set symbol for DECL visibility to
5866 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5869 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
5870 int vis ATTRIBUTE_UNUSED)
5872 #ifdef HAVE_GAS_HIDDEN
5873 static const char * const visibility_types[] = {
5874 NULL, "protected", "hidden", "internal"
5877 const char *name, *type;
5879 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5880 type = visibility_types[vis];
5882 fprintf (asm_out_file, "\t.%s\t", type);
5883 assemble_name (asm_out_file, name);
5884 fprintf (asm_out_file, "\n");
5886 warning (OPT_Wattributes, "visibility attribute not supported "
5887 "in this configuration; ignored");
5891 /* A helper function to call assemble_visibility when needed for a decl. */
5894 maybe_assemble_visibility (tree decl)
5896 enum symbol_visibility vis = DECL_VISIBILITY (decl);
5898 if (vis != VISIBILITY_DEFAULT)
5900 targetm.asm_out.visibility (decl, vis);
5907 /* Returns 1 if the target configuration supports defining public symbols
5908 so that one of them will be chosen at link time instead of generating a
5909 multiply-defined symbol error, whether through the use of weak symbols or
5910 a target-specific mechanism for having duplicates discarded. */
5913 supports_one_only (void)
5915 if (SUPPORTS_ONE_ONLY)
5917 return SUPPORTS_WEAK;
5920 /* Set up DECL as a public symbol that can be defined in multiple
5921 translation units without generating a linker error. */
5924 make_decl_one_only (tree decl, tree comdat_group)
5926 gcc_assert (TREE_CODE (decl) == VAR_DECL
5927 || TREE_CODE (decl) == FUNCTION_DECL);
5929 TREE_PUBLIC (decl) = 1;
5931 if (SUPPORTS_ONE_ONLY)
5933 #ifdef MAKE_DECL_ONE_ONLY
5934 MAKE_DECL_ONE_ONLY (decl);
5936 DECL_COMDAT_GROUP (decl) = comdat_group;
5938 else if (TREE_CODE (decl) == VAR_DECL
5939 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5940 DECL_COMMON (decl) = 1;
5943 gcc_assert (SUPPORTS_WEAK);
5944 DECL_WEAK (decl) = 1;
5949 init_varasm_once (void)
5951 section_htab = htab_create_ggc (31, section_entry_hash,
5952 section_entry_eq, NULL);
5953 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
5954 object_block_entry_eq, NULL);
5955 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
5956 const_desc_eq, NULL);
5958 const_alias_set = new_alias_set ();
5959 shared_constant_pool = create_constant_pool ();
5961 #ifdef TEXT_SECTION_ASM_OP
5962 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
5963 TEXT_SECTION_ASM_OP);
5966 #ifdef DATA_SECTION_ASM_OP
5967 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5968 DATA_SECTION_ASM_OP);
5971 #ifdef SDATA_SECTION_ASM_OP
5972 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5973 SDATA_SECTION_ASM_OP);
5976 #ifdef READONLY_DATA_SECTION_ASM_OP
5977 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
5978 READONLY_DATA_SECTION_ASM_OP);
5981 #ifdef CTORS_SECTION_ASM_OP
5982 ctors_section = get_unnamed_section (0, output_section_asm_op,
5983 CTORS_SECTION_ASM_OP);
5986 #ifdef DTORS_SECTION_ASM_OP
5987 dtors_section = get_unnamed_section (0, output_section_asm_op,
5988 DTORS_SECTION_ASM_OP);
5991 #ifdef BSS_SECTION_ASM_OP
5992 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5993 output_section_asm_op,
5994 BSS_SECTION_ASM_OP);
5997 #ifdef SBSS_SECTION_ASM_OP
5998 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5999 output_section_asm_op,
6000 SBSS_SECTION_ASM_OP);
6003 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6004 | SECTION_COMMON, emit_tls_common);
6005 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6006 | SECTION_COMMON, emit_local);
6007 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6008 | SECTION_COMMON, emit_common);
6010 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
6011 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
6015 targetm.asm_out.init_sections ();
6017 if (readonly_data_section == NULL)
6018 readonly_data_section = text_section;
6022 decl_default_tls_model (const_tree decl)
6024 enum tls_model kind;
6027 is_local = targetm.binds_local_p (decl);
6031 kind = TLS_MODEL_LOCAL_EXEC;
6033 kind = TLS_MODEL_INITIAL_EXEC;
6036 /* Local dynamic is inefficient when we're not combining the
6037 parts of the address. */
6038 else if (optimize && is_local)
6039 kind = TLS_MODEL_LOCAL_DYNAMIC;
6041 kind = TLS_MODEL_GLOBAL_DYNAMIC;
6042 if (kind < flag_tls_default)
6043 kind = flag_tls_default;
6048 /* Select a set of attributes for section NAME based on the properties
6049 of DECL and whether or not RELOC indicates that DECL's initializer
6050 might contain runtime relocations.
6052 We make the section read-only and executable for a function decl,
6053 read-only for a const data decl, and writable for a non-const data decl. */
6056 default_section_type_flags (tree decl, const char *name, int reloc)
6060 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
6061 flags = SECTION_CODE;
6062 else if (decl && decl_readonly_section (decl, reloc))
6064 else if (current_function_decl
6066 && crtl->subsections.unlikely_text_section_name
6067 && strcmp (name, crtl->subsections.unlikely_text_section_name) == 0)
6068 flags = SECTION_CODE;
6070 && (!current_function_decl || !cfun)
6071 && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6072 flags = SECTION_CODE;
6074 flags = SECTION_WRITE;
6076 if (decl && DECL_ONE_ONLY (decl))
6077 flags |= SECTION_LINKONCE;
6079 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6080 flags |= SECTION_TLS | SECTION_WRITE;
6082 if (strcmp (name, ".bss") == 0
6083 || strncmp (name, ".bss.", 5) == 0
6084 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
6085 || strcmp (name, ".sbss") == 0
6086 || strncmp (name, ".sbss.", 6) == 0
6087 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
6088 flags |= SECTION_BSS;
6090 if (strcmp (name, ".tdata") == 0
6091 || strncmp (name, ".tdata.", 7) == 0
6092 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
6093 flags |= SECTION_TLS;
6095 if (strcmp (name, ".tbss") == 0
6096 || strncmp (name, ".tbss.", 6) == 0
6097 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
6098 flags |= SECTION_TLS | SECTION_BSS;
6100 /* These three sections have special ELF types. They are neither
6101 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6102 want to print a section type (@progbits or @nobits). If someone
6103 is silly enough to emit code or TLS variables to one of these
6104 sections, then don't handle them specially. */
6105 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
6106 && (strcmp (name, ".init_array") == 0
6107 || strcmp (name, ".fini_array") == 0
6108 || strcmp (name, ".preinit_array") == 0))
6109 flags |= SECTION_NOTYPE;
6114 /* Return true if the target supports some form of global BSS,
6115 either through bss_noswitch_section, or by selecting a BSS
6116 section in TARGET_ASM_SELECT_SECTION. */
6119 have_global_bss_p (void)
6121 return bss_noswitch_section || targetm.have_switchable_bss_sections;
6124 /* Output assembly to switch to section NAME with attribute FLAGS.
6125 Four variants for common object file formats. */
6128 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
6129 unsigned int flags ATTRIBUTE_UNUSED,
6130 tree decl ATTRIBUTE_UNUSED)
6132 /* Some object formats don't support named sections at all. The
6133 front-end should already have flagged this as an error. */
6137 #ifndef TLS_SECTION_ASM_FLAG
6138 #define TLS_SECTION_ASM_FLAG 'T'
6142 default_elf_asm_named_section (const char *name, unsigned int flags,
6143 tree decl ATTRIBUTE_UNUSED)
6145 char flagchars[10], *f = flagchars;
6147 /* If we have already declared this section, we can use an
6148 abbreviated form to switch back to it -- unless this section is
6149 part of a COMDAT groups, in which case GAS requires the full
6150 declaration every time. */
6151 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6152 && (flags & SECTION_DECLARED))
6154 fprintf (asm_out_file, "\t.section\t%s\n", name);
6158 if (!(flags & SECTION_DEBUG))
6160 if (flags & SECTION_WRITE)
6162 if (flags & SECTION_CODE)
6164 if (flags & SECTION_SMALL)
6166 if (flags & SECTION_MERGE)
6168 if (flags & SECTION_STRINGS)
6170 if (flags & SECTION_TLS)
6171 *f++ = TLS_SECTION_ASM_FLAG;
6172 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6176 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
6178 if (!(flags & SECTION_NOTYPE))
6183 if (flags & SECTION_BSS)
6189 #ifdef ASM_COMMENT_START
6190 /* On platforms that use "@" as the assembly comment character,
6192 if (strcmp (ASM_COMMENT_START, "@") == 0)
6195 fprintf (asm_out_file, format, type);
6197 if (flags & SECTION_ENTSIZE)
6198 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
6199 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6201 if (TREE_CODE (decl) == IDENTIFIER_NODE)
6202 fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
6204 fprintf (asm_out_file, ",%s,comdat",
6205 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
6209 putc ('\n', asm_out_file);
6213 default_coff_asm_named_section (const char *name, unsigned int flags,
6214 tree decl ATTRIBUTE_UNUSED)
6216 char flagchars[8], *f = flagchars;
6218 if (flags & SECTION_WRITE)
6220 if (flags & SECTION_CODE)
6224 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
6228 default_pe_asm_named_section (const char *name, unsigned int flags,
6231 default_coff_asm_named_section (name, flags, decl);
6233 if (flags & SECTION_LINKONCE)
6235 /* Functions may have been compiled at various levels of
6236 optimization so we can't use `same_size' here.
6237 Instead, have the linker pick one. */
6238 fprintf (asm_out_file, "\t.linkonce %s\n",
6239 (flags & SECTION_CODE ? "discard" : "same_size"));
6243 /* The lame default section selector. */
6246 default_select_section (tree decl, int reloc,
6247 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6251 if (decl_readonly_section (decl, reloc))
6252 return readonly_data_section;
6254 else if (TREE_CODE (decl) == CONSTRUCTOR)
6256 if (! ((flag_pic && reloc)
6257 || !TREE_READONLY (decl)
6258 || TREE_SIDE_EFFECTS (decl)
6259 || !TREE_CONSTANT (decl)))
6260 return readonly_data_section;
6262 else if (TREE_CODE (decl) == STRING_CST)
6263 return readonly_data_section;
6264 else if (! (flag_pic && reloc))
6265 return readonly_data_section;
6267 return data_section;
6270 enum section_category
6271 categorize_decl_for_section (const_tree decl, int reloc)
6273 enum section_category ret;
6275 if (TREE_CODE (decl) == FUNCTION_DECL)
6277 else if (TREE_CODE (decl) == STRING_CST)
6279 if (flag_mudflap) /* or !flag_merge_constants */
6280 return SECCAT_RODATA;
6282 return SECCAT_RODATA_MERGE_STR;
6284 else if (TREE_CODE (decl) == VAR_DECL)
6286 if (bss_initializer_p (decl))
6288 else if (! TREE_READONLY (decl)
6289 || TREE_SIDE_EFFECTS (decl)
6290 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6292 /* Here the reloc_rw_mask is not testing whether the section should
6293 be read-only or not, but whether the dynamic link will have to
6294 do something. If so, we wish to segregate the data in order to
6295 minimize cache misses inside the dynamic linker. */
6296 if (reloc & targetm.asm_out.reloc_rw_mask ())
6297 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6301 else if (reloc & targetm.asm_out.reloc_rw_mask ())
6302 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6303 else if (reloc || flag_merge_constants < 2)
6304 /* C and C++ don't allow different variables to share the same
6305 location. -fmerge-all-constants allows even that (at the
6306 expense of not conforming). */
6307 ret = SECCAT_RODATA;
6308 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6309 ret = SECCAT_RODATA_MERGE_STR_INIT;
6311 ret = SECCAT_RODATA_MERGE_CONST;
6313 else if (TREE_CODE (decl) == CONSTRUCTOR)
6315 if ((reloc & targetm.asm_out.reloc_rw_mask ())
6316 || TREE_SIDE_EFFECTS (decl)
6317 || ! TREE_CONSTANT (decl))
6320 ret = SECCAT_RODATA;
6323 ret = SECCAT_RODATA;
6325 /* There are no read-only thread-local sections. */
6326 if (TREE_CODE (decl) == VAR_DECL && DECL_TLS_MODEL (decl))
6328 if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED)
6330 if (DECL_EMUTLS_VAR_P (decl))
6332 if (targetm.emutls.var_section)
6333 ret = SECCAT_EMUTLS_VAR;
6337 if (targetm.emutls.tmpl_prefix)
6338 ret = SECCAT_EMUTLS_TMPL;
6341 /* Note that this would be *just* SECCAT_BSS, except that there's
6342 no concept of a read-only thread-local-data section. */
6343 else if (ret == SECCAT_BSS
6344 || (flag_zero_initialized_in_bss
6345 && initializer_zerop (DECL_INITIAL (decl))))
6351 /* If the target uses small data sections, select it. */
6352 else if (targetm.in_small_data_p (decl))
6354 if (ret == SECCAT_BSS)
6356 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6357 ret = SECCAT_SRODATA;
6366 decl_readonly_section (const_tree decl, int reloc)
6368 switch (categorize_decl_for_section (decl, reloc))
6371 case SECCAT_RODATA_MERGE_STR:
6372 case SECCAT_RODATA_MERGE_STR_INIT:
6373 case SECCAT_RODATA_MERGE_CONST:
6374 case SECCAT_SRODATA:
6383 /* Select a section based on the above categorization. */
6386 default_elf_select_section (tree decl, int reloc,
6387 unsigned HOST_WIDE_INT align)
6390 switch (categorize_decl_for_section (decl, reloc))
6393 /* We're not supposed to be called on FUNCTION_DECLs. */
6396 return readonly_data_section;
6397 case SECCAT_RODATA_MERGE_STR:
6398 return mergeable_string_section (decl, align, 0);
6399 case SECCAT_RODATA_MERGE_STR_INIT:
6400 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6401 case SECCAT_RODATA_MERGE_CONST:
6402 return mergeable_constant_section (DECL_MODE (decl), align, 0);
6403 case SECCAT_SRODATA:
6407 return data_section;
6408 case SECCAT_DATA_REL:
6409 sname = ".data.rel";
6411 case SECCAT_DATA_REL_LOCAL:
6412 sname = ".data.rel.local";
6414 case SECCAT_DATA_REL_RO:
6415 sname = ".data.rel.ro";
6417 case SECCAT_DATA_REL_RO_LOCAL:
6418 sname = ".data.rel.ro.local";
6437 case SECCAT_EMUTLS_VAR:
6438 sname = targetm.emutls.var_section;
6440 case SECCAT_EMUTLS_TMPL:
6441 sname = targetm.emutls.tmpl_section;
6449 return get_named_section (decl, sname, reloc);
6452 /* Construct a unique section name based on the decl name and the
6453 categorization performed above. */
6456 default_unique_section (tree decl, int reloc)
6458 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6459 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6460 const char *prefix, *name, *linkonce;
6463 switch (categorize_decl_for_section (decl, reloc))
6466 prefix = one_only ? ".t" : ".text";
6469 case SECCAT_RODATA_MERGE_STR:
6470 case SECCAT_RODATA_MERGE_STR_INIT:
6471 case SECCAT_RODATA_MERGE_CONST:
6472 prefix = one_only ? ".r" : ".rodata";
6474 case SECCAT_SRODATA:
6475 prefix = one_only ? ".s2" : ".sdata2";
6478 prefix = one_only ? ".d" : ".data";
6480 case SECCAT_DATA_REL:
6481 prefix = one_only ? ".d.rel" : ".data.rel";
6483 case SECCAT_DATA_REL_LOCAL:
6484 prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6486 case SECCAT_DATA_REL_RO:
6487 prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6489 case SECCAT_DATA_REL_RO_LOCAL:
6490 prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6493 prefix = one_only ? ".s" : ".sdata";
6496 prefix = one_only ? ".b" : ".bss";
6499 prefix = one_only ? ".sb" : ".sbss";
6502 prefix = one_only ? ".td" : ".tdata";
6505 prefix = one_only ? ".tb" : ".tbss";
6507 case SECCAT_EMUTLS_VAR:
6508 prefix = targetm.emutls.var_section;
6510 case SECCAT_EMUTLS_TMPL:
6511 prefix = targetm.emutls.tmpl_section;
6517 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6518 name = targetm.strip_name_encoding (name);
6520 /* If we're using one_only, then there needs to be a .gnu.linkonce
6521 prefix to the section name. */
6522 linkonce = one_only ? ".gnu.linkonce" : "";
6524 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6526 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6529 /* Like compute_reloc_for_constant, except for an RTX. The return value
6530 is a mask for which bit 1 indicates a global relocation, and bit 0
6531 indicates a local relocation. */
6534 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6536 int *preloc = (int *) data;
6539 switch (GET_CODE (x))
6542 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6555 compute_reloc_for_rtx (rtx x)
6559 switch (GET_CODE (x))
6565 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6574 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6576 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6578 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6579 return data_section;
6581 return readonly_data_section;
6585 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6586 unsigned HOST_WIDE_INT align)
6588 int reloc = compute_reloc_for_rtx (x);
6590 /* ??? Handle small data here somehow. */
6592 if (reloc & targetm.asm_out.reloc_rw_mask ())
6595 return get_named_section (NULL, ".data.rel.ro.local", 1);
6597 return get_named_section (NULL, ".data.rel.ro", 3);
6600 return mergeable_constant_section (mode, align, 0);
6603 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6606 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6611 /* Careful not to prod global register variables. */
6614 symbol = XEXP (rtl, 0);
6615 if (GET_CODE (symbol) != SYMBOL_REF)
6618 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6619 if (TREE_CODE (decl) == FUNCTION_DECL)
6620 flags |= SYMBOL_FLAG_FUNCTION;
6621 if (targetm.binds_local_p (decl))
6622 flags |= SYMBOL_FLAG_LOCAL;
6623 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)
6624 && DECL_TLS_MODEL (decl) != TLS_MODEL_EMULATED)
6625 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6626 else if (targetm.in_small_data_p (decl))
6627 flags |= SYMBOL_FLAG_SMALL;
6628 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6629 being PUBLIC, the thing *must* be defined in this translation unit.
6630 Prevent this buglet from being propagated into rtl code as well. */
6631 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6632 flags |= SYMBOL_FLAG_EXTERNAL;
6634 SYMBOL_REF_FLAGS (symbol) = flags;
6637 /* By default, we do nothing for encode_section_info, so we need not
6638 do anything but discard the '*' marker. */
6641 default_strip_name_encoding (const char *str)
6643 return str + (*str == '*');
6646 #ifdef ASM_OUTPUT_DEF
6647 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6648 anchor relative to ".", the current section position. */
6651 default_asm_output_anchor (rtx symbol)
6655 sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6656 SYMBOL_REF_BLOCK_OFFSET (symbol));
6657 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6661 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6664 default_use_anchors_for_symbol_p (const_rtx symbol)
6669 /* Don't use anchors for mergeable sections. The linker might move
6670 the objects around. */
6671 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6672 if (sect->common.flags & SECTION_MERGE)
6675 /* Don't use anchors for small data sections. The small data register
6676 acts as an anchor for such sections. */
6677 if (sect->common.flags & SECTION_SMALL)
6680 decl = SYMBOL_REF_DECL (symbol);
6681 if (decl && DECL_P (decl))
6683 /* Don't use section anchors for decls that might be defined by
6685 if (!targetm.binds_local_p (decl))
6688 /* Don't use section anchors for decls that will be placed in a
6689 small data section. */
6690 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6691 one above. The problem is that we only use SECTION_SMALL for
6692 sections that should be marked as small in the section directive. */
6693 if (targetm.in_small_data_p (decl))
6699 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6700 wrt cross-module name binding. */
6703 default_binds_local_p (const_tree exp)
6705 return default_binds_local_p_1 (exp, flag_shlib);
6709 default_binds_local_p_1 (const_tree exp, int shlib)
6713 /* A non-decl is an entry in the constant pool. */
6716 /* Weakrefs may not bind locally, even though the weakref itself is
6717 always static and therefore local. */
6718 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6720 /* Static variables are always local. */
6721 else if (! TREE_PUBLIC (exp))
6723 /* A variable is local if the user has said explicitly that it will
6725 else if (DECL_VISIBILITY_SPECIFIED (exp)
6726 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6728 /* Variables defined outside this object might not be local. */
6729 else if (DECL_EXTERNAL (exp))
6731 /* If defined in this object and visibility is not default, must be
6733 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6735 /* Default visibility weak data can be overridden by a strong symbol
6736 in another module and so are not local. */
6737 else if (DECL_WEAK (exp))
6739 /* If PIC, then assume that any global name can be overridden by
6740 symbols resolved from other modules, unless we are compiling with
6741 -fwhole-program, which assumes that names are local. */
6743 local_p = flag_whole_program;
6744 /* Uninitialized COMMON variable may be unified with symbols
6745 resolved from other modules. */
6746 else if (DECL_COMMON (exp)
6747 && (DECL_INITIAL (exp) == NULL
6748 || DECL_INITIAL (exp) == error_mark_node))
6750 /* Otherwise we're left with initialized (or non-common) global data
6751 which is of necessity defined locally. */
6758 /* Default function to output code that will globalize a label. A
6759 target must define GLOBAL_ASM_OP or provide its own function to
6760 globalize a label. */
6761 #ifdef GLOBAL_ASM_OP
6763 default_globalize_label (FILE * stream, const char *name)
6765 fputs (GLOBAL_ASM_OP, stream);
6766 assemble_name (stream, name);
6767 putc ('\n', stream);
6769 #endif /* GLOBAL_ASM_OP */
6771 /* Default function to output code that will globalize a declaration. */
6773 default_globalize_decl_name (FILE * stream, tree decl)
6775 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6776 targetm.asm_out.globalize_label (stream, name);
6779 /* Default function to output a label for unwind information. The
6780 default is to do nothing. A target that needs nonlocal labels for
6781 unwind information must provide its own function to do this. */
6783 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6784 tree decl ATTRIBUTE_UNUSED,
6785 int for_eh ATTRIBUTE_UNUSED,
6786 int empty ATTRIBUTE_UNUSED)
6790 /* Default function to output a label to divide up the exception table.
6791 The default is to do nothing. A target that needs/wants to divide
6792 up the table must provide it's own function to do this. */
6794 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6798 /* This is how to output an internal numbered label where PREFIX is
6799 the class of label and LABELNO is the number within the class. */
6802 default_internal_label (FILE *stream, const char *prefix,
6803 unsigned long labelno)
6805 char *const buf = (char *) alloca (40 + strlen (prefix));
6806 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6807 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6810 /* This is the default behavior at the beginning of a file. It's
6811 controlled by two other target-hook toggles. */
6813 default_file_start (void)
6815 if (targetm.file_start_app_off
6816 && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
6817 fputs (ASM_APP_OFF, asm_out_file);
6819 if (targetm.file_start_file_directive)
6820 output_file_directive (asm_out_file, main_input_filename);
6823 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6824 which emits a special section directive used to indicate whether or
6825 not this object file needs an executable stack. This is primarily
6826 a GNU extension to ELF but could be used on other targets. */
6828 int trampolines_created;
6831 file_end_indicate_exec_stack (void)
6833 unsigned int flags = SECTION_DEBUG;
6834 if (trampolines_created)
6835 flags |= SECTION_CODE;
6837 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
6840 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6841 a get_unnamed_section callback. */
6844 output_section_asm_op (const void *directive)
6846 fprintf (asm_out_file, "%s\n", (const char *) directive);
6849 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6850 the current section is NEW_SECTION. */
6853 switch_to_section (section *new_section)
6855 if (in_section == new_section)
6858 if (new_section->common.flags & SECTION_FORGET)
6861 in_section = new_section;
6863 switch (SECTION_STYLE (new_section))
6867 && !crtl->subsections.unlikely_text_section_name
6868 && strcmp (new_section->named.name,
6869 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6870 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6872 targetm.asm_out.named_section (new_section->named.name,
6873 new_section->named.common.flags,
6874 new_section->named.decl);
6877 case SECTION_UNNAMED:
6878 new_section->unnamed.callback (new_section->unnamed.data);
6881 case SECTION_NOSWITCH:
6886 new_section->common.flags |= SECTION_DECLARED;
6889 /* If block symbol SYMBOL has not yet been assigned an offset, place
6890 it at the end of its block. */
6893 place_block_symbol (rtx symbol)
6895 unsigned HOST_WIDE_INT size, mask, offset;
6896 struct constant_descriptor_rtx *desc;
6897 unsigned int alignment;
6898 struct object_block *block;
6901 gcc_assert (SYMBOL_REF_BLOCK (symbol));
6902 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6905 /* Work out the symbol's size and alignment. */
6906 if (CONSTANT_POOL_ADDRESS_P (symbol))
6908 desc = SYMBOL_REF_CONSTANT (symbol);
6909 alignment = desc->align;
6910 size = GET_MODE_SIZE (desc->mode);
6912 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6914 decl = SYMBOL_REF_DECL (symbol);
6915 alignment = get_constant_alignment (decl);
6916 size = get_constant_size (decl);
6920 decl = SYMBOL_REF_DECL (symbol);
6921 alignment = DECL_ALIGN (decl);
6922 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6925 /* Calculate the object's offset from the start of the block. */
6926 block = SYMBOL_REF_BLOCK (symbol);
6927 mask = alignment / BITS_PER_UNIT - 1;
6928 offset = (block->size + mask) & ~mask;
6929 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
6931 /* Record the block's new alignment and size. */
6932 block->alignment = MAX (block->alignment, alignment);
6933 block->size = offset + size;
6935 VEC_safe_push (rtx, gc, block->objects, symbol);
6938 /* Return the anchor that should be used to address byte offset OFFSET
6939 from the first object in BLOCK. MODEL is the TLS model used
6943 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
6944 enum tls_model model)
6947 unsigned int begin, middle, end;
6948 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
6951 /* Work out the anchor's offset. Use an offset of 0 for the first
6952 anchor so that we don't pessimize the case where we take the address
6953 of a variable at the beginning of the block. This is particularly
6954 useful when a block has only one variable assigned to it.
6956 We try to place anchors RANGE bytes apart, so there can then be
6957 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6958 a ptr_mode offset. With some target settings, the lowest such
6959 anchor might be out of range for the lowest ptr_mode offset;
6960 likewise the highest anchor for the highest offset. Use anchors
6961 at the extreme ends of the ptr_mode range in such cases.
6963 All arithmetic uses unsigned integers in order to avoid
6965 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
6966 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
6967 range = max_offset - min_offset + 1;
6972 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
6975 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
6976 delta -= delta % range;
6979 offset = (HOST_WIDE_INT) (-delta);
6983 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
6984 delta -= delta % range;
6985 if (delta > bias - 1)
6987 offset = (HOST_WIDE_INT) delta;
6991 /* Do a binary search to see if there's already an anchor we can use.
6992 Set BEGIN to the new anchor's index if not. */
6994 end = VEC_length (rtx, block->anchors);
6995 while (begin != end)
6997 middle = (end + begin) / 2;
6998 anchor = VEC_index (rtx, block->anchors, middle);
6999 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
7001 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
7003 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
7005 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
7011 /* Create a new anchor with a unique label. */
7012 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
7013 anchor = create_block_symbol (ggc_strdup (label), block, offset);
7014 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
7015 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
7017 /* Insert it at index BEGIN. */
7018 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
7022 /* Output the objects in BLOCK. */
7025 output_object_block (struct object_block *block)
7027 struct constant_descriptor_rtx *desc;
7029 HOST_WIDE_INT offset;
7033 if (block->objects == NULL)
7036 /* Switch to the section and make sure that the first byte is
7037 suitably aligned. */
7038 switch_to_section (block->sect);
7039 assemble_align (block->alignment);
7041 /* Define the values of all anchors relative to the current section
7043 for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
7044 targetm.asm_out.output_anchor (symbol);
7046 /* Output the objects themselves. */
7048 for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
7050 /* Move to the object's offset, padding with zeros if necessary. */
7051 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
7052 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
7053 if (CONSTANT_POOL_ADDRESS_P (symbol))
7055 desc = SYMBOL_REF_CONSTANT (symbol);
7056 output_constant_pool_1 (desc, 1);
7057 offset += GET_MODE_SIZE (desc->mode);
7059 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7061 decl = SYMBOL_REF_DECL (symbol);
7062 assemble_constant_contents (decl, XSTR (symbol, 0),
7063 get_constant_alignment (decl));
7064 offset += get_constant_size (decl);
7068 decl = SYMBOL_REF_DECL (symbol);
7069 assemble_variable_contents (decl, XSTR (symbol, 0), false);
7070 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7075 /* A htab_traverse callback used to call output_object_block for
7076 each member of object_block_htab. */
7079 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
7081 output_object_block ((struct object_block *) (*slot));
7085 /* Output the definitions of all object_blocks. */
7088 output_object_blocks (void)
7090 htab_traverse (object_block_htab, output_object_block_htab, NULL);
7093 /* This function provides a possible implementation of the
7094 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7095 by -frecord-gcc-switches it creates a new mergeable, string section in the
7096 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7097 contains the switches in ASCII format.
7099 FIXME: This code does not correctly handle double quote characters
7100 that appear inside strings, (it strips them rather than preserving them).
7101 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7102 characters - instead it treats them as sub-string separators. Since
7103 we want to emit NUL strings terminators into the object file we have to use
7107 elf_record_gcc_switches (print_switch_type type, const char * name)
7109 static char buffer[1024];
7111 /* This variable is used as part of a simplistic heuristic to detect
7112 command line switches which take an argument:
7114 "If a command line option does not start with a dash then
7115 it is an argument for the previous command line option."
7117 This fails in the case of the command line option which is the name
7118 of the file to compile, but otherwise it is pretty reasonable. */
7119 static bool previous_name_held_back = FALSE;
7123 case SWITCH_TYPE_PASSED:
7126 if (previous_name_held_back)
7128 unsigned int len = strlen (buffer);
7130 snprintf (buffer + len, sizeof buffer - len, " %s", name);
7131 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7132 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7133 previous_name_held_back = FALSE;
7137 strncpy (buffer, name, sizeof buffer);
7138 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7139 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7144 if (previous_name_held_back)
7146 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7147 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7150 strncpy (buffer, name, sizeof buffer);
7151 previous_name_held_back = TRUE;
7155 case SWITCH_TYPE_DESCRIPTIVE:
7158 /* Distinguish between invocations where name is NULL. */
7159 static bool started = false;
7163 if (previous_name_held_back)
7165 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7166 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7173 sec = get_section (targetm.asm_out.record_gcc_switches_section,
7177 | (SECTION_ENTSIZE & 1),
7179 switch_to_section (sec);
7188 /* The return value is currently ignored by the caller, but must be 0.
7189 For -fverbose-asm the return value would be the number of characters
7190 emitted into the assembler file. */
7194 /* Emit text to declare externally defined symbols. It is needed to
7195 properly support non-default visibility. */
7197 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
7199 const char *name ATTRIBUTE_UNUSED)
7201 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7202 set in order to avoid putting out names that are never really
7204 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
7205 && targetm.binds_local_p (decl))
7206 maybe_assemble_visibility (decl);
7209 #include "gt-varasm.h"