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);
2809 switch (TREE_CODE (target))
2813 x = DECL_RTL (target);
2817 x = gen_rtx_MEM (FUNCTION_MODE,
2818 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2827 x = output_constant_def (target, 1);
2834 gcc_assert (MEM_P (x));
2838 value->offset = offset;
2842 static GTY((param_is (struct constant_descriptor_tree)))
2843 htab_t const_desc_htab;
2845 static struct constant_descriptor_tree * build_constant_desc (tree);
2846 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2848 /* Constant pool accessor function. */
2851 constant_pool_htab (void)
2853 return const_desc_htab;
2856 /* Compute a hash code for a constant expression. */
2859 const_desc_hash (const void *ptr)
2861 return ((const struct constant_descriptor_tree *)ptr)->hash;
2865 const_hash_1 (const tree exp)
2870 enum tree_code code = TREE_CODE (exp);
2872 /* Either set P and LEN to the address and len of something to hash and
2873 exit the switch or return a value. */
2878 p = (char *) &TREE_INT_CST (exp);
2879 len = sizeof TREE_INT_CST (exp);
2883 return real_hash (TREE_REAL_CST_PTR (exp));
2886 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2889 p = TREE_STRING_POINTER (exp);
2890 len = TREE_STRING_LENGTH (exp);
2894 return (const_hash_1 (TREE_REALPART (exp)) * 5
2895 + const_hash_1 (TREE_IMAGPART (exp)));
2899 unsigned HOST_WIDE_INT idx;
2902 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2904 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2906 hi = hi * 603 + const_hash_1 (value);
2914 struct addr_const value;
2916 decode_addr_const (exp, &value);
2917 switch (GET_CODE (value.base))
2920 /* Don't hash the address of the SYMBOL_REF;
2921 only use the offset and the symbol name. */
2923 p = XSTR (value.base, 0);
2924 for (i = 0; p[i] != 0; i++)
2925 hi = ((hi * 613) + (unsigned) (p[i]));
2929 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2939 case POINTER_PLUS_EXPR:
2941 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2942 + const_hash_1 (TREE_OPERAND (exp, 1)));
2945 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2948 /* A language specific constant. Just hash the code. */
2952 /* Compute hashing function. */
2954 for (i = 0; i < len; i++)
2955 hi = ((hi * 613) + (unsigned) (p[i]));
2960 /* Wrapper of compare_constant, for the htab interface. */
2962 const_desc_eq (const void *p1, const void *p2)
2964 const struct constant_descriptor_tree *const c1
2965 = (const struct constant_descriptor_tree *) p1;
2966 const struct constant_descriptor_tree *const c2
2967 = (const struct constant_descriptor_tree *) p2;
2968 if (c1->hash != c2->hash)
2970 return compare_constant (c1->value, c2->value);
2973 /* Compare t1 and t2, and return 1 only if they are known to result in
2974 the same bit pattern on output. */
2977 compare_constant (const tree t1, const tree t2)
2979 enum tree_code typecode;
2981 if (t1 == NULL_TREE)
2982 return t2 == NULL_TREE;
2983 if (t2 == NULL_TREE)
2986 if (TREE_CODE (t1) != TREE_CODE (t2))
2989 switch (TREE_CODE (t1))
2992 /* Integer constants are the same only if the same width of type. */
2993 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2995 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2997 return tree_int_cst_equal (t1, t2);
3000 /* Real constants are the same only if the same width of type. */
3001 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3004 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3007 /* Fixed constants are the same only if the same width of type. */
3008 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3011 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3014 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3017 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3018 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3019 TREE_STRING_LENGTH (t1)));
3022 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3023 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3027 VEC(constructor_elt, gc) *v1, *v2;
3028 unsigned HOST_WIDE_INT idx;
3030 typecode = TREE_CODE (TREE_TYPE (t1));
3031 if (typecode != TREE_CODE (TREE_TYPE (t2)))
3034 if (typecode == ARRAY_TYPE)
3036 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3037 /* For arrays, check that the sizes all match. */
3038 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3040 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
3045 /* For record and union constructors, require exact type
3047 if (TREE_TYPE (t1) != TREE_TYPE (t2))
3051 v1 = CONSTRUCTOR_ELTS (t1);
3052 v2 = CONSTRUCTOR_ELTS (t2);
3053 if (VEC_length (constructor_elt, v1)
3054 != VEC_length (constructor_elt, v2))
3057 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
3059 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
3060 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
3062 /* Check that each value is the same... */
3063 if (!compare_constant (c1->value, c2->value))
3065 /* ... and that they apply to the same fields! */
3066 if (typecode == ARRAY_TYPE)
3068 if (!compare_constant (c1->index, c2->index))
3073 if (c1->index != c2->index)
3084 struct addr_const value1, value2;
3086 decode_addr_const (t1, &value1);
3087 decode_addr_const (t2, &value2);
3088 return (value1.offset == value2.offset
3089 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3093 case POINTER_PLUS_EXPR:
3096 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3097 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3100 case VIEW_CONVERT_EXPR:
3101 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3110 /* Make a copy of the whole tree structure for a constant. This
3111 handles the same types of nodes that compare_constant handles. */
3114 copy_constant (tree exp)
3116 switch (TREE_CODE (exp))
3119 /* For ADDR_EXPR, we do not want to copy the decl whose address
3120 is requested. We do want to copy constants though. */
3121 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3122 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3123 copy_constant (TREE_OPERAND (exp, 0)));
3125 return copy_node (exp);
3131 return copy_node (exp);
3134 return build_complex (TREE_TYPE (exp),
3135 copy_constant (TREE_REALPART (exp)),
3136 copy_constant (TREE_IMAGPART (exp)));
3139 case POINTER_PLUS_EXPR:
3141 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3142 copy_constant (TREE_OPERAND (exp, 0)),
3143 copy_constant (TREE_OPERAND (exp, 1)));
3146 case VIEW_CONVERT_EXPR:
3147 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3148 copy_constant (TREE_OPERAND (exp, 0)));
3152 tree copy = copy_node (exp);
3153 VEC(constructor_elt, gc) *v;
3154 unsigned HOST_WIDE_INT idx;
3155 tree purpose, value;
3157 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3158 CONSTRUCTOR_ELTS (exp)));
3159 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3161 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3162 ce->index = purpose;
3163 ce->value = copy_constant (value);
3165 CONSTRUCTOR_ELTS (copy) = v;
3174 /* Return the alignment of constant EXP in bits. */
3177 get_constant_alignment (tree exp)
3181 align = TYPE_ALIGN (TREE_TYPE (exp));
3182 #ifdef CONSTANT_ALIGNMENT
3183 align = CONSTANT_ALIGNMENT (exp, align);
3188 /* Return the section into which constant EXP should be placed. */
3191 get_constant_section (tree exp)
3193 if (IN_NAMED_SECTION (exp))
3194 return get_named_section (exp, NULL, compute_reloc_for_constant (exp));
3196 return targetm.asm_out.select_section (exp,
3197 compute_reloc_for_constant (exp),
3198 get_constant_alignment (exp));
3201 /* Return the size of constant EXP in bytes. */
3203 static HOST_WIDE_INT
3204 get_constant_size (tree exp)
3208 size = int_size_in_bytes (TREE_TYPE (exp));
3209 if (TREE_CODE (exp) == STRING_CST)
3210 size = MAX (TREE_STRING_LENGTH (exp), size);
3214 /* Subroutine of output_constant_def:
3215 No constant equal to EXP is known to have been output.
3216 Make a constant descriptor to enter EXP in the hash table.
3217 Assign the label number and construct RTL to refer to the
3218 constant's location in memory.
3219 Caller is responsible for updating the hash table. */
3221 static struct constant_descriptor_tree *
3222 build_constant_desc (tree exp)
3228 struct constant_descriptor_tree *desc;
3230 desc = GGC_NEW (struct constant_descriptor_tree);
3231 desc->value = copy_constant (exp);
3233 /* Propagate marked-ness to copied constant. */
3234 if (flag_mudflap && mf_marked_p (exp))
3235 mf_mark (desc->value);
3237 /* Create a string containing the label name, in LABEL. */
3238 labelno = const_labelno++;
3239 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3241 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3242 if (use_object_blocks_p ())
3244 section *sect = get_constant_section (exp);
3245 symbol = create_block_symbol (ggc_strdup (label),
3246 get_block_for_section (sect), -1);
3249 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3250 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3251 SET_SYMBOL_REF_DECL (symbol, desc->value);
3252 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3254 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3255 set_mem_attributes (rtl, exp, 1);
3256 set_mem_alias_set (rtl, 0);
3257 set_mem_alias_set (rtl, const_alias_set);
3259 /* We cannot share RTX'es in pool entries.
3260 Mark this piece of RTL as required for unsharing. */
3261 RTX_FLAG (rtl, used) = 1;
3263 /* Set flags or add text to the name to record information, such as
3264 that it is a local symbol. If the name is changed, the macro
3265 ASM_OUTPUT_LABELREF will have to know how to strip this
3266 information. This call might invalidate our local variable
3267 SYMBOL; we can't use it afterward. */
3269 targetm.encode_section_info (exp, rtl, true);
3276 /* Return an rtx representing a reference to constant data in memory
3277 for the constant expression EXP.
3279 If assembler code for such a constant has already been output,
3280 return an rtx to refer to it.
3281 Otherwise, output such a constant in memory
3282 and generate an rtx for it.
3284 If DEFER is nonzero, this constant can be deferred and output only
3285 if referenced in the function after all optimizations.
3287 `const_desc_table' records which constants already have label strings. */
3290 output_constant_def (tree exp, int defer)
3292 struct constant_descriptor_tree *desc;
3293 struct constant_descriptor_tree key;
3296 /* Look up EXP in the table of constant descriptors. If we didn't find
3297 it, create a new one. */
3299 key.hash = const_hash_1 (exp);
3300 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3302 desc = (struct constant_descriptor_tree *) *loc;
3305 desc = build_constant_desc (exp);
3306 desc->hash = key.hash;
3310 maybe_output_constant_def_contents (desc, defer);
3314 /* Subroutine of output_constant_def: Decide whether or not we need to
3315 output the constant DESC now, and if so, do it. */
3317 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3320 rtx symbol = XEXP (desc->rtl, 0);
3321 tree exp = desc->value;
3323 if (flag_syntax_only)
3326 if (TREE_ASM_WRITTEN (exp))
3327 /* Already output; don't do it again. */
3330 /* We can always defer constants as long as the context allows
3334 /* Increment n_deferred_constants if it exists. It needs to be at
3335 least as large as the number of constants actually referred to
3336 by the function. If it's too small we'll stop looking too early
3337 and fail to emit constants; if it's too large we'll only look
3338 through the entire function when we could have stopped earlier. */
3340 n_deferred_constants++;
3344 output_constant_def_contents (symbol);
3347 /* Subroutine of output_constant_def_contents. Output the definition
3348 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3349 constant's alignment in bits. */
3352 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3356 size = get_constant_size (exp);
3358 /* Do any machine/system dependent processing of the constant. */
3359 #ifdef ASM_DECLARE_CONSTANT_NAME
3360 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
3362 /* Standard thing is just output label for the constant. */
3363 ASM_OUTPUT_LABEL (asm_out_file, label);
3364 #endif /* ASM_DECLARE_CONSTANT_NAME */
3366 /* Output the value of EXP. */
3367 output_constant (exp, size, align);
3370 /* We must output the constant data referred to by SYMBOL; do so. */
3373 output_constant_def_contents (rtx symbol)
3375 tree exp = SYMBOL_REF_DECL (symbol);
3378 /* Make sure any other constants whose addresses appear in EXP
3379 are assigned label numbers. */
3380 output_addressed_constants (exp);
3382 /* We are no longer deferring this constant. */
3383 TREE_ASM_WRITTEN (exp) = 1;
3385 /* If the constant is part of an object block, make sure that the
3386 decl has been positioned within its block, but do not write out
3387 its definition yet. output_object_blocks will do that later. */
3388 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3389 place_block_symbol (symbol);
3392 switch_to_section (get_constant_section (exp));
3393 align = get_constant_alignment (exp);
3394 if (align > BITS_PER_UNIT)
3395 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3396 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3399 mudflap_enqueue_constant (exp);
3402 /* Look up EXP in the table of constant descriptors. Return the rtl
3403 if it has been emitted, else null. */
3406 lookup_constant_def (tree exp)
3408 struct constant_descriptor_tree *desc;
3409 struct constant_descriptor_tree key;
3412 key.hash = const_hash_1 (exp);
3413 desc = (struct constant_descriptor_tree *)
3414 htab_find_with_hash (const_desc_htab, &key, key.hash);
3416 return (desc ? desc->rtl : NULL_RTX);
3419 /* Used in the hash tables to avoid outputting the same constant
3420 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3421 are output once per function, not once per file. */
3422 /* ??? Only a few targets need per-function constant pools. Most
3423 can use one per-file pool. Should add a targetm bit to tell the
3426 struct GTY(()) rtx_constant_pool {
3427 /* Pointers to first and last constant in pool, as ordered by offset. */
3428 struct constant_descriptor_rtx *first;
3429 struct constant_descriptor_rtx *last;
3431 /* Hash facility for making memory-constants from constant rtl-expressions.
3432 It is used on RISC machines where immediate integer arguments and
3433 constant addresses are restricted so that such constants must be stored
3435 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3437 /* Current offset in constant pool (does not include any
3438 machine-specific header). */
3439 HOST_WIDE_INT offset;
3442 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3443 struct constant_descriptor_rtx *next;
3447 HOST_WIDE_INT offset;
3449 enum machine_mode mode;
3455 /* Hash and compare functions for const_rtx_htab. */
3458 const_desc_rtx_hash (const void *ptr)
3460 const struct constant_descriptor_rtx *const desc
3461 = (const struct constant_descriptor_rtx *) ptr;
3466 const_desc_rtx_eq (const void *a, const void *b)
3468 const struct constant_descriptor_rtx *const x
3469 = (const struct constant_descriptor_rtx *) a;
3470 const struct constant_descriptor_rtx *const y
3471 = (const struct constant_descriptor_rtx *) b;
3473 if (x->mode != y->mode)
3475 return rtx_equal_p (x->constant, y->constant);
3478 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3481 const_rtx_hash_1 (rtx *xp, void *data)
3483 unsigned HOST_WIDE_INT hwi;
3484 enum machine_mode mode;
3490 code = GET_CODE (x);
3491 mode = GET_MODE (x);
3492 h = (hashval_t) code * 1048573 + mode;
3500 int shift = sizeof (hashval_t) * CHAR_BIT;
3501 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3504 h ^= (hashval_t) hwi;
3505 for (i = 1; i < n; ++i)
3508 h ^= (hashval_t) hwi;
3514 if (mode == VOIDmode)
3516 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3520 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3524 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3530 for (i = XVECLEN (x, 0); i-- > 0; )
3531 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3536 h ^= htab_hash_string (XSTR (x, 0));
3540 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3544 case UNSPEC_VOLATILE:
3545 h = h * 251 + XINT (x, 1);
3552 hp = (hashval_t *) data;
3553 *hp = *hp * 509 + h;
3557 /* Compute a hash value for X, which should be a constant. */
3560 const_rtx_hash (rtx x)
3563 for_each_rtx (&x, const_rtx_hash_1, &h);
3568 /* Create and return a new rtx constant pool. */
3570 static struct rtx_constant_pool *
3571 create_constant_pool (void)
3573 struct rtx_constant_pool *pool;
3575 pool = GGC_NEW (struct rtx_constant_pool);
3576 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3577 const_desc_rtx_eq, NULL);
3584 /* Initialize constant pool hashing for a new function. */
3587 init_varasm_status (void)
3589 crtl->varasm.pool = create_constant_pool ();
3590 crtl->varasm.deferred_constants = 0;
3593 /* Given a MINUS expression, simplify it if both sides
3594 include the same symbol. */
3597 simplify_subtraction (rtx x)
3599 rtx r = simplify_rtx (x);
3603 /* Given a constant rtx X, make (or find) a memory constant for its value
3604 and return a MEM rtx to refer to it in memory. */
3607 force_const_mem (enum machine_mode mode, rtx x)
3609 struct constant_descriptor_rtx *desc, tmp;
3610 struct rtx_constant_pool *pool;
3617 /* If we're not allowed to drop X into the constant pool, don't. */
3618 if (targetm.cannot_force_const_mem (x))
3621 /* Record that this function has used a constant pool entry. */
3622 crtl->uses_const_pool = 1;
3624 /* Decide which pool to use. */
3625 pool = (targetm.use_blocks_for_constant_p (mode, x)
3626 ? shared_constant_pool
3627 : crtl->varasm.pool);
3629 /* Lookup the value in the hashtable. */
3632 hash = const_rtx_hash (x);
3633 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3634 desc = (struct constant_descriptor_rtx *) *slot;
3636 /* If the constant was already present, return its memory. */
3638 return copy_rtx (desc->mem);
3640 /* Otherwise, create a new descriptor. */
3641 desc = GGC_NEW (struct constant_descriptor_rtx);
3644 /* Align the location counter as required by EXP's data type. */
3645 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3646 #ifdef CONSTANT_ALIGNMENT
3648 tree type = lang_hooks.types.type_for_mode (mode, 0);
3649 if (type != NULL_TREE)
3650 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3654 pool->offset += (align / BITS_PER_UNIT) - 1;
3655 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3658 desc->constant = tmp.constant;
3659 desc->offset = pool->offset;
3662 desc->align = align;
3663 desc->labelno = const_labelno;
3666 pool->offset += GET_MODE_SIZE (mode);
3668 pool->last->next = desc;
3670 pool->first = pool->last = desc;
3673 /* Create a string containing the label name, in LABEL. */
3674 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3677 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3678 the constants pool. */
3679 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3681 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3682 symbol = create_block_symbol (ggc_strdup (label),
3683 get_block_for_section (sect), -1);
3686 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3688 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3689 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3690 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3692 /* Construct the MEM. */
3693 desc->mem = def = gen_const_mem (mode, symbol);
3694 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3695 set_mem_align (def, align);
3697 /* If we're dropping a label to the constant pool, make sure we
3699 if (GET_CODE (x) == LABEL_REF)
3700 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3702 return copy_rtx (def);
3705 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3708 get_pool_constant (rtx addr)
3710 return SYMBOL_REF_CONSTANT (addr)->constant;
3713 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3714 and whether it has been output or not. */
3717 get_pool_constant_mark (rtx addr, bool *pmarked)
3719 struct constant_descriptor_rtx *desc;
3721 desc = SYMBOL_REF_CONSTANT (addr);
3722 *pmarked = (desc->mark != 0);
3723 return desc->constant;
3726 /* Similar, return the mode. */
3729 get_pool_mode (const_rtx addr)
3731 return SYMBOL_REF_CONSTANT (addr)->mode;
3734 /* Return the size of the constant pool. */
3737 get_pool_size (void)
3739 return crtl->varasm.pool->offset;
3742 /* Worker function for output_constant_pool_1. Emit assembly for X
3743 in MODE with known alignment ALIGN. */
3746 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3748 switch (GET_MODE_CLASS (mode))
3751 case MODE_DECIMAL_FLOAT:
3755 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3756 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3757 assemble_real (r, mode, align);
3762 case MODE_PARTIAL_INT:
3767 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3770 case MODE_VECTOR_FLOAT:
3771 case MODE_VECTOR_INT:
3772 case MODE_VECTOR_FRACT:
3773 case MODE_VECTOR_UFRACT:
3774 case MODE_VECTOR_ACCUM:
3775 case MODE_VECTOR_UACCUM:
3778 enum machine_mode submode = GET_MODE_INNER (mode);
3779 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3781 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3782 units = CONST_VECTOR_NUNITS (x);
3784 for (i = 0; i < units; i++)
3786 rtx elt = CONST_VECTOR_ELT (x, i);
3787 output_constant_pool_2 (submode, elt, i ? subalign : align);
3797 /* Worker function for output_constant_pool. Emit constant DESC,
3798 giving it ALIGN bits of alignment. */
3801 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3808 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3809 whose CODE_LABEL has been deleted. This can occur if a jump table
3810 is eliminated by optimization. If so, write a constant of zero
3811 instead. Note that this can also happen by turning the
3812 CODE_LABEL into a NOTE. */
3813 /* ??? This seems completely and utterly wrong. Certainly it's
3814 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3815 functioning even with INSN_DELETED_P and friends. */
3818 switch (GET_CODE (tmp))
3821 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3822 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3824 tmp = XEXP (XEXP (tmp, 0), 0);
3828 tmp = XEXP (tmp, 0);
3829 gcc_assert (!INSN_DELETED_P (tmp));
3830 gcc_assert (!NOTE_P (tmp)
3831 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3838 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3839 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3840 align, desc->labelno, done);
3843 assemble_align (align);
3845 /* Output the label. */
3846 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3848 /* Output the data. */
3849 output_constant_pool_2 (desc->mode, x, align);
3851 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3852 sections have proper size. */
3853 if (align > GET_MODE_BITSIZE (desc->mode)
3855 && (in_section->common.flags & SECTION_MERGE))
3856 assemble_align (align);
3858 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3864 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3865 to as used. Emit referenced deferred strings. This function can
3866 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3869 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3871 rtx x = *current_rtx;
3873 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3876 if (CONSTANT_POOL_ADDRESS_P (x))
3878 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3879 if (desc->mark == 0)
3882 for_each_rtx (&desc->constant, mark_constant, NULL);
3885 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3887 tree exp = SYMBOL_REF_DECL (x);
3888 if (!TREE_ASM_WRITTEN (exp))
3890 n_deferred_constants--;
3891 output_constant_def_contents (x);
3898 /* Look through appropriate parts of INSN, marking all entries in the
3899 constant pool which are actually being used. Entries that are only
3900 referenced by other constants are also marked as used. Emit
3901 deferred strings that are used. */
3904 mark_constants (rtx insn)
3909 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3910 insns, not any notes that may be attached. We don't want to mark
3911 a constant just because it happens to appear in a REG_EQUIV note. */
3912 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3914 rtx seq = PATTERN (insn);
3915 int i, n = XVECLEN (seq, 0);
3916 for (i = 0; i < n; ++i)
3918 rtx subinsn = XVECEXP (seq, 0, i);
3919 if (INSN_P (subinsn))
3920 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
3924 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
3927 /* Look through the instructions for this function, and mark all the
3928 entries in POOL which are actually being used. Emit deferred constants
3929 which have indeed been used. */
3932 mark_constant_pool (void)
3936 if (!crtl->uses_const_pool && n_deferred_constants == 0)
3939 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3940 mark_constants (insn);
3942 for (link = crtl->epilogue_delay_list;
3944 link = XEXP (link, 1))
3945 mark_constants (XEXP (link, 0));
3948 /* Write all the constants in POOL. */
3951 output_constant_pool_contents (struct rtx_constant_pool *pool)
3953 struct constant_descriptor_rtx *desc;
3955 for (desc = pool->first; desc ; desc = desc->next)
3958 /* If the constant is part of an object_block, make sure that
3959 the constant has been positioned within its block, but do not
3960 write out its definition yet. output_object_blocks will do
3962 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
3963 && SYMBOL_REF_BLOCK (desc->sym))
3964 place_block_symbol (desc->sym);
3967 switch_to_section (targetm.asm_out.select_rtx_section
3968 (desc->mode, desc->constant, desc->align));
3969 output_constant_pool_1 (desc, desc->align);
3974 /* Mark all constants that are used in the current function, then write
3975 out the function's private constant pool. */
3978 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3979 tree fndecl ATTRIBUTE_UNUSED)
3981 struct rtx_constant_pool *pool = crtl->varasm.pool;
3983 /* It is possible for gcc to call force_const_mem and then to later
3984 discard the instructions which refer to the constant. In such a
3985 case we do not need to output the constant. */
3986 mark_constant_pool ();
3988 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3989 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3992 output_constant_pool_contents (pool);
3994 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3995 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3999 /* Write the contents of the shared constant pool. */
4002 output_shared_constant_pool (void)
4004 output_constant_pool_contents (shared_constant_pool);
4007 /* Determine what kind of relocations EXP may need. */
4010 compute_reloc_for_constant (tree exp)
4012 int reloc = 0, reloc2;
4015 switch (TREE_CODE (exp))
4019 /* Go inside any operations that get_inner_reference can handle and see
4020 if what's inside is a constant: no need to do anything here for
4021 addresses of variables or functions. */
4022 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4023 tem = TREE_OPERAND (tem, 0))
4026 if (TREE_PUBLIC (tem))
4033 case POINTER_PLUS_EXPR:
4034 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4035 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4039 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4040 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4041 /* The difference of two local labels is computable at link time. */
4042 if (reloc == 1 && reloc2 == 1)
4049 case VIEW_CONVERT_EXPR:
4050 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4055 unsigned HOST_WIDE_INT idx;
4056 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4058 reloc |= compute_reloc_for_constant (tem);
4068 /* Find all the constants whose addresses are referenced inside of EXP,
4069 and make sure assembler code with a label has been output for each one.
4070 Indicate whether an ADDR_EXPR has been encountered. */
4073 output_addressed_constants (tree exp)
4077 switch (TREE_CODE (exp))
4081 /* Go inside any operations that get_inner_reference can handle and see
4082 if what's inside is a constant: no need to do anything here for
4083 addresses of variables or functions. */
4084 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4085 tem = TREE_OPERAND (tem, 0))
4088 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4089 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4090 tem = DECL_INITIAL (tem);
4092 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4093 output_constant_def (tem, 0);
4097 case POINTER_PLUS_EXPR:
4099 output_addressed_constants (TREE_OPERAND (exp, 1));
4103 case VIEW_CONVERT_EXPR:
4104 output_addressed_constants (TREE_OPERAND (exp, 0));
4109 unsigned HOST_WIDE_INT idx;
4110 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4112 output_addressed_constants (tem);
4121 /* Whether a constructor CTOR is a valid static constant initializer if all
4122 its elements are. This used to be internal to initializer_constant_valid_p
4123 and has been exposed to let other functions like categorize_ctor_elements
4124 evaluate the property while walking a constructor for other purposes. */
4127 constructor_static_from_elts_p (const_tree ctor)
4129 return (TREE_CONSTANT (ctor)
4130 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4131 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4132 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4135 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4138 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4139 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4140 which are valid when ENDTYPE is an integer of any size; in
4141 particular, this does not accept a pointer minus a constant. This
4142 returns null_pointer_node if the VALUE is an absolute constant
4143 which can be used to initialize a static variable. Otherwise it
4147 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4151 if (!INTEGRAL_TYPE_P (endtype))
4154 op0 = TREE_OPERAND (value, 0);
4155 op1 = TREE_OPERAND (value, 1);
4157 /* Like STRIP_NOPS except allow the operand mode to widen. This
4158 works around a feature of fold that simplifies (int)(p1 - p2) to
4159 ((int)p1 - (int)p2) under the theory that the narrower operation
4162 while (CONVERT_EXPR_P (op0)
4163 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4165 tree inner = TREE_OPERAND (op0, 0);
4166 if (inner == error_mark_node
4167 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4168 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4169 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4174 while (CONVERT_EXPR_P (op1)
4175 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4177 tree inner = TREE_OPERAND (op1, 0);
4178 if (inner == error_mark_node
4179 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4180 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4181 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4186 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4190 op1 = initializer_constant_valid_p_1 (op1, endtype,
4191 cache ? cache + 2 : NULL);
4192 /* Both initializers must be known. */
4196 && (op0 == null_pointer_node
4197 || TREE_CODE (value) == MINUS_EXPR))
4198 return null_pointer_node;
4200 /* Support differences between labels. */
4201 if (TREE_CODE (op0) == LABEL_DECL
4202 && TREE_CODE (op1) == LABEL_DECL)
4203 return null_pointer_node;
4205 if (TREE_CODE (op0) == STRING_CST
4206 && TREE_CODE (op1) == STRING_CST
4207 && operand_equal_p (op0, op1, 1))
4208 return null_pointer_node;
4214 /* Helper function of initializer_constant_valid_p.
4215 Return nonzero if VALUE is a valid constant-valued expression
4216 for use in initializing a static variable; one that can be an
4217 element of a "constant" initializer.
4219 Return null_pointer_node if the value is absolute;
4220 if it is relocatable, return the variable that determines the relocation.
4221 We assume that VALUE has been folded as much as possible;
4222 therefore, we do not need to check for such things as
4223 arithmetic-combinations of integers.
4225 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4228 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4232 switch (TREE_CODE (value))
4235 if (constructor_static_from_elts_p (value))
4237 unsigned HOST_WIDE_INT idx;
4239 bool absolute = true;
4241 if (cache && cache[0] == value)
4243 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4246 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4253 cache[1] = NULL_TREE;
4257 if (reloc != null_pointer_node)
4260 /* For a non-absolute relocation, there is no single
4261 variable that can be "the variable that determines the
4266 cache[1] = absolute ? null_pointer_node : error_mark_node;
4268 return absolute ? null_pointer_node : error_mark_node;
4271 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4279 return null_pointer_node;
4284 tree op0 = staticp (TREE_OPERAND (value, 0));
4287 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4288 to be a constant, this is old-skool offsetof-like nonsense. */
4289 if (TREE_CODE (op0) == INDIRECT_REF
4290 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4291 return null_pointer_node;
4292 /* Taking the address of a nested function involves a trampoline,
4293 unless we don't need or want one. */
4294 if (TREE_CODE (op0) == FUNCTION_DECL
4295 && DECL_STATIC_CHAIN (op0)
4296 && !TREE_NO_TRAMPOLINE (value))
4298 /* "&{...}" requires a temporary to hold the constructed
4300 if (TREE_CODE (op0) == CONSTRUCTOR)
4306 case NON_LVALUE_EXPR:
4307 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4310 case VIEW_CONVERT_EXPR:
4312 tree src = TREE_OPERAND (value, 0);
4313 tree src_type = TREE_TYPE (src);
4314 tree dest_type = TREE_TYPE (value);
4316 /* Allow view-conversions from aggregate to non-aggregate type only
4317 if the bit pattern is fully preserved afterwards; otherwise, the
4318 RTL expander won't be able to apply a subsequent transformation
4319 to the underlying constructor. */
4320 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4322 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4323 return initializer_constant_valid_p_1 (src, endtype, cache);
4328 /* Allow all other kinds of view-conversion. */
4329 return initializer_constant_valid_p_1 (src, endtype, cache);
4334 tree src = TREE_OPERAND (value, 0);
4335 tree src_type = TREE_TYPE (src);
4336 tree dest_type = TREE_TYPE (value);
4338 /* Allow conversions between pointer types, floating-point
4339 types, and offset types. */
4340 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4341 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4342 || (TREE_CODE (dest_type) == OFFSET_TYPE
4343 && TREE_CODE (src_type) == OFFSET_TYPE))
4344 return initializer_constant_valid_p_1 (src, endtype, cache);
4346 /* Allow length-preserving conversions between integer types. */
4347 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4348 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4349 return initializer_constant_valid_p_1 (src, endtype, cache);
4351 /* Allow conversions between other integer types only if
4353 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4355 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4356 if (inner == null_pointer_node)
4357 return null_pointer_node;
4361 /* Allow (int) &foo provided int is as wide as a pointer. */
4362 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4363 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4364 return initializer_constant_valid_p_1 (src, endtype, cache);
4366 /* Likewise conversions from int to pointers, but also allow
4367 conversions from 0. */
4368 if ((POINTER_TYPE_P (dest_type)
4369 || TREE_CODE (dest_type) == OFFSET_TYPE)
4370 && INTEGRAL_TYPE_P (src_type))
4372 if (TREE_CODE (src) == INTEGER_CST
4373 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4374 return null_pointer_node;
4375 if (integer_zerop (src))
4376 return null_pointer_node;
4377 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4378 return initializer_constant_valid_p_1 (src, endtype, cache);
4381 /* Allow conversions to struct or union types if the value
4383 if (TREE_CODE (dest_type) == RECORD_TYPE
4384 || TREE_CODE (dest_type) == UNION_TYPE)
4385 return initializer_constant_valid_p_1 (src, endtype, cache);
4389 case POINTER_PLUS_EXPR:
4391 /* Any valid floating-point constants will have been folded by now;
4392 with -frounding-math we hit this with addition of two constants. */
4393 if (TREE_CODE (endtype) == REAL_TYPE)
4395 if (cache && cache[0] == value)
4397 if (! INTEGRAL_TYPE_P (endtype)
4398 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4400 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4402 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4405 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4406 endtype, ncache + 2);
4407 /* If either term is absolute, use the other term's relocation. */
4408 if (valid0 == null_pointer_node)
4410 else if (valid1 == null_pointer_node)
4412 /* Support narrowing pointer differences. */
4414 ret = narrowing_initializer_constant_valid_p (value, endtype,
4418 /* Support narrowing pointer differences. */
4419 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4428 if (TREE_CODE (endtype) == REAL_TYPE)
4430 if (cache && cache[0] == value)
4432 if (! INTEGRAL_TYPE_P (endtype)
4433 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4435 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4437 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4440 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4441 endtype, ncache + 2);
4442 /* Win if second argument is absolute. */
4443 if (valid1 == null_pointer_node)
4445 /* Win if both arguments have the same relocation.
4446 Then the value is absolute. */
4447 else if (valid0 == valid1 && valid0 != 0)
4448 ret = null_pointer_node;
4449 /* Since GCC guarantees that string constants are unique in the
4450 generated code, a subtraction between two copies of the same
4451 constant string is absolute. */
4452 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4453 && valid1 && TREE_CODE (valid1) == STRING_CST
4454 && operand_equal_p (valid0, valid1, 1))
4455 ret = null_pointer_node;
4456 /* Support narrowing differences. */
4458 ret = narrowing_initializer_constant_valid_p (value, endtype,
4462 /* Support narrowing differences. */
4463 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4478 /* Return nonzero if VALUE is a valid constant-valued expression
4479 for use in initializing a static variable; one that can be an
4480 element of a "constant" initializer.
4482 Return null_pointer_node if the value is absolute;
4483 if it is relocatable, return the variable that determines the relocation.
4484 We assume that VALUE has been folded as much as possible;
4485 therefore, we do not need to check for such things as
4486 arithmetic-combinations of integers. */
4488 initializer_constant_valid_p (tree value, tree endtype)
4490 return initializer_constant_valid_p_1 (value, endtype, NULL);
4493 /* Return true if VALUE is a valid constant-valued expression
4494 for use in initializing a static bit-field; one that can be
4495 an element of a "constant" initializer. */
4498 initializer_constant_valid_for_bitfield_p (tree value)
4500 /* For bitfields we support integer constants or possibly nested aggregates
4502 switch (TREE_CODE (value))
4506 unsigned HOST_WIDE_INT idx;
4509 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4510 if (!initializer_constant_valid_for_bitfield_p (elt))
4518 case VIEW_CONVERT_EXPR:
4519 case NON_LVALUE_EXPR:
4521 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4530 /* output_constructor outer state of relevance in recursive calls, typically
4531 for nested aggregate bitfields. */
4534 unsigned int bit_offset; /* current position in ... */
4535 int byte; /* ... the outer byte buffer. */
4538 static unsigned HOST_WIDE_INT
4539 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4542 /* Output assembler code for constant EXP to FILE, with no label.
4543 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4544 Assumes output_addressed_constants has been done on EXP already.
4546 Generate exactly SIZE bytes of assembler data, padding at the end
4547 with zeros if necessary. SIZE must always be specified.
4549 SIZE is important for structure constructors,
4550 since trailing members may have been omitted from the constructor.
4551 It is also important for initialization of arrays from string constants
4552 since the full length of the string constant might not be wanted.
4553 It is also needed for initialization of unions, where the initializer's
4554 type is just one member, and that may not be as long as the union.
4556 There a case in which we would fail to output exactly SIZE bytes:
4557 for a structure constructor that wants to produce more than SIZE bytes.
4558 But such constructors will never be generated for any possible input.
4560 ALIGN is the alignment of the data in bits. */
4563 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4565 enum tree_code code;
4566 unsigned HOST_WIDE_INT thissize;
4568 if (size == 0 || flag_syntax_only)
4571 /* See if we're trying to initialize a pointer in a non-default mode
4572 to the address of some declaration somewhere. If the target says
4573 the mode is valid for pointers, assume the target has a way of
4575 if (TREE_CODE (exp) == NOP_EXPR
4576 && POINTER_TYPE_P (TREE_TYPE (exp))
4577 && targetm.addr_space.valid_pointer_mode
4578 (TYPE_MODE (TREE_TYPE (exp)),
4579 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4581 tree saved_type = TREE_TYPE (exp);
4583 /* Peel off any intermediate conversions-to-pointer for valid
4585 while (TREE_CODE (exp) == NOP_EXPR
4586 && POINTER_TYPE_P (TREE_TYPE (exp))
4587 && targetm.addr_space.valid_pointer_mode
4588 (TYPE_MODE (TREE_TYPE (exp)),
4589 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4590 exp = TREE_OPERAND (exp, 0);
4592 /* If what we're left with is the address of something, we can
4593 convert the address to the final type and output it that
4595 if (TREE_CODE (exp) == ADDR_EXPR)
4596 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4597 /* Likewise for constant ints. */
4598 else if (TREE_CODE (exp) == INTEGER_CST)
4599 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4600 TREE_INT_CST_HIGH (exp));
4604 /* Eliminate any conversions since we'll be outputting the underlying
4606 while (CONVERT_EXPR_P (exp)
4607 || TREE_CODE (exp) == NON_LVALUE_EXPR
4608 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4610 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4611 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4613 /* Make sure eliminating the conversion is really a no-op, except with
4614 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4615 union types to allow for Ada unchecked unions. */
4616 if (type_size > op_size
4617 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4618 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4619 /* Keep the conversion. */
4622 exp = TREE_OPERAND (exp, 0);
4625 code = TREE_CODE (TREE_TYPE (exp));
4626 thissize = int_size_in_bytes (TREE_TYPE (exp));
4628 /* Allow a constructor with no elements for any data type.
4629 This means to fill the space with zeros. */
4630 if (TREE_CODE (exp) == CONSTRUCTOR
4631 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4633 assemble_zeros (size);
4637 if (TREE_CODE (exp) == FDESC_EXPR)
4639 #ifdef ASM_OUTPUT_FDESC
4640 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4641 tree decl = TREE_OPERAND (exp, 0);
4642 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4649 /* Now output the underlying data. If we've handling the padding, return.
4650 Otherwise, break and ensure SIZE is the size written. */
4657 case REFERENCE_TYPE:
4659 case FIXED_POINT_TYPE:
4660 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4661 EXPAND_INITIALIZER),
4662 MIN (size, thissize), align, 0))
4663 error ("initializer for integer/fixed-point value is too complicated");
4667 if (TREE_CODE (exp) != REAL_CST)
4668 error ("initializer for floating value is not a floating constant");
4670 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4674 output_constant (TREE_REALPART (exp), thissize / 2, align);
4675 output_constant (TREE_IMAGPART (exp), thissize / 2,
4676 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4681 switch (TREE_CODE (exp))
4684 output_constructor (exp, size, align, NULL);
4687 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4689 assemble_string (TREE_STRING_POINTER (exp), thissize);
4696 unsigned int nalign;
4697 enum machine_mode inner;
4699 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4700 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4702 elt_size = GET_MODE_SIZE (inner);
4704 link = TREE_VECTOR_CST_ELTS (exp);
4705 output_constant (TREE_VALUE (link), elt_size, align);
4706 thissize = elt_size;
4707 while ((link = TREE_CHAIN (link)) != NULL)
4709 output_constant (TREE_VALUE (link), elt_size, nalign);
4710 thissize += elt_size;
4721 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4722 output_constructor (exp, size, align, NULL);
4732 if (size > thissize)
4733 assemble_zeros (size - thissize);
4737 /* Subroutine of output_constructor, used for computing the size of
4738 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4739 type with an unspecified upper bound. */
4741 static unsigned HOST_WIDE_INT
4742 array_size_for_constructor (tree val)
4745 unsigned HOST_WIDE_INT cnt;
4746 tree index, value, tmp;
4748 /* This code used to attempt to handle string constants that are not
4749 arrays of single-bytes, but nothing else does, so there's no point in
4751 if (TREE_CODE (val) == STRING_CST)
4752 return TREE_STRING_LENGTH (val);
4754 max_index = NULL_TREE;
4755 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4757 if (TREE_CODE (index) == RANGE_EXPR)
4758 index = TREE_OPERAND (index, 1);
4759 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4763 if (max_index == NULL_TREE)
4766 /* Compute the total number of array elements. */
4767 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4768 i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
4769 fold_convert (sizetype, tmp));
4770 i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
4772 /* Multiply by the array element unit size to find number of bytes. */
4773 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4775 return tree_low_cst (i, 1);
4778 /* Other datastructures + helpers for output_constructor. */
4780 /* output_constructor local state to support interaction with helpers. */
4784 /* Received arguments. */
4785 tree exp; /* Constructor expression. */
4786 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4787 unsigned int align; /* Known initial alignment. */
4789 /* Constructor expression data. */
4790 tree type; /* Expression type. */
4791 tree field; /* Current field decl in a record. */
4792 tree min_index; /* Lower bound if specified for an array. */
4794 /* Output processing state. */
4795 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4796 bool byte_buffer_in_use; /* Whether byte ... */
4797 int byte; /* ... contains part of a bitfield byte yet to
4800 int last_relative_index; /* Implicit or explicit index of the last
4801 array element output within a bitfield. */
4802 /* Current element. */
4803 tree val; /* Current element value. */
4804 tree index; /* Current element index. */
4808 /* Helper for output_constructor. From the current LOCAL state, output a
4809 RANGE_EXPR element. */
4812 output_constructor_array_range (oc_local_state *local)
4814 unsigned HOST_WIDE_INT fieldsize
4815 = int_size_in_bytes (TREE_TYPE (local->type));
4817 HOST_WIDE_INT lo_index
4818 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4819 HOST_WIDE_INT hi_index
4820 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4821 HOST_WIDE_INT index;
4824 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4826 for (index = lo_index; index <= hi_index; index++)
4828 /* Output the element's initial value. */
4829 if (local->val == NULL_TREE)
4830 assemble_zeros (fieldsize);
4832 output_constant (local->val, fieldsize, align2);
4834 /* Count its size. */
4835 local->total_bytes += fieldsize;
4839 /* Helper for output_constructor. From the current LOCAL state, output a
4840 field element that is not true bitfield or part of an outer one. */
4843 output_constructor_regular_field (oc_local_state *local)
4845 /* Field size and position. Since this structure is static, we know the
4846 positions are constant. */
4847 unsigned HOST_WIDE_INT fieldsize;
4848 HOST_WIDE_INT fieldpos;
4850 unsigned int align2;
4852 if (local->index != NULL_TREE)
4853 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
4854 * ((tree_low_cst (local->index, 0)
4855 - tree_low_cst (local->min_index, 0))));
4856 else if (local->field != NULL_TREE)
4857 fieldpos = int_byte_position (local->field);
4861 /* Output any buffered-up bit-fields preceding this element. */
4862 if (local->byte_buffer_in_use)
4864 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4865 local->total_bytes++;
4866 local->byte_buffer_in_use = false;
4869 /* Advance to offset of this element.
4870 Note no alignment needed in an array, since that is guaranteed
4871 if each element has the proper size. */
4872 if ((local->field != NULL_TREE || local->index != NULL_TREE)
4873 && fieldpos != local->total_bytes)
4875 gcc_assert (fieldpos >= local->total_bytes);
4876 assemble_zeros (fieldpos - local->total_bytes);
4877 local->total_bytes = fieldpos;
4880 /* Find the alignment of this element. */
4881 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
4883 /* Determine size this element should occupy. */
4888 /* If this is an array with an unspecified upper bound,
4889 the initializer determines the size. */
4890 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4891 but we cannot do this until the deprecated support for
4892 initializing zero-length array members is removed. */
4893 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
4894 && TYPE_DOMAIN (TREE_TYPE (local->field))
4895 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
4897 fieldsize = array_size_for_constructor (local->val);
4898 /* Given a non-empty initialization, this field had
4900 gcc_assert (!fieldsize || !TREE_CHAIN (local->field));
4902 else if (DECL_SIZE_UNIT (local->field))
4904 /* ??? This can't be right. If the decl size overflows
4905 a host integer we will silently emit no data. */
4906 if (host_integerp (DECL_SIZE_UNIT (local->field), 1))
4907 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
4911 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
4913 /* Output the element's initial value. */
4914 if (local->val == NULL_TREE)
4915 assemble_zeros (fieldsize);
4917 output_constant (local->val, fieldsize, align2);
4919 /* Count its size. */
4920 local->total_bytes += fieldsize;
4923 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4924 output an element that is a true bitfield or part of an outer one. */
4927 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
4929 /* Bit size of this element. */
4930 HOST_WIDE_INT ebitsize
4932 ? tree_low_cst (DECL_SIZE (local->field), 1)
4933 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
4935 /* Relative index of this element if this is an array component. */
4936 HOST_WIDE_INT relative_index
4939 ? (tree_low_cst (local->index, 0)
4940 - tree_low_cst (local->min_index, 0))
4941 : local->last_relative_index + 1)
4944 /* Bit position of this element from the start of the containing
4946 HOST_WIDE_INT constructor_relative_ebitpos
4948 ? int_bit_position (local->field)
4949 : ebitsize * relative_index);
4951 /* Bit position of this element from the start of a possibly ongoing
4952 outer byte buffer. */
4953 HOST_WIDE_INT byte_relative_ebitpos
4954 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
4956 /* From the start of a possibly ongoing outer byte buffer, offsets to
4957 the first bit of this element and to the first bit past the end of
4959 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
4960 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
4962 local->last_relative_index = relative_index;
4964 if (local->val == NULL_TREE)
4965 local->val = integer_zero_node;
4967 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
4968 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
4969 local->val = TREE_OPERAND (local->val, 0);
4971 if (TREE_CODE (local->val) != INTEGER_CST
4972 && TREE_CODE (local->val) != CONSTRUCTOR)
4974 error ("invalid initial value for member %qE", DECL_NAME (local->field));
4978 /* If this field does not start in this (or, next) byte,
4980 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4982 /* Output remnant of any bit field in previous bytes. */
4983 if (local->byte_buffer_in_use)
4985 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4986 local->total_bytes++;
4987 local->byte_buffer_in_use = false;
4990 /* If still not at proper byte, advance to there. */
4991 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4993 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
4994 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
4995 local->total_bytes = next_offset / BITS_PER_UNIT;
4999 /* Set up the buffer if necessary. */
5000 if (!local->byte_buffer_in_use)
5004 local->byte_buffer_in_use = true;
5007 /* If this is nested constructor, recurse passing the bit offset and the
5008 pending data, then retrieve the new pending data afterwards. */
5009 if (TREE_CODE (local->val) == CONSTRUCTOR)
5011 oc_outer_state output_state;
5013 output_state.bit_offset = next_offset % BITS_PER_UNIT;
5014 output_state.byte = local->byte;
5016 += output_constructor (local->val, 0, 0, &output_state);
5017 local->byte = output_state.byte;
5021 /* Otherwise, we must split the element into pieces that fall within
5022 separate bytes, and combine each byte with previous or following
5024 while (next_offset < end_offset)
5028 HOST_WIDE_INT value;
5029 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
5030 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
5032 /* Advance from byte to byte
5033 within this element when necessary. */
5034 while (next_byte != local->total_bytes)
5036 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5037 local->total_bytes++;
5041 /* Number of bits we can process at once
5042 (all part of the same byte). */
5043 this_time = MIN (end_offset - next_offset,
5044 BITS_PER_UNIT - next_bit);
5045 if (BYTES_BIG_ENDIAN)
5047 /* On big-endian machine, take the most significant bits
5048 first (of the bits that are significant)
5049 and put them into bytes from the most significant end. */
5050 shift = end_offset - next_offset - this_time;
5052 /* Don't try to take a bunch of bits that cross
5053 the word boundary in the INTEGER_CST. We can
5054 only select bits from the LOW or HIGH part
5056 if (shift < HOST_BITS_PER_WIDE_INT
5057 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5059 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
5060 shift = HOST_BITS_PER_WIDE_INT;
5063 /* Now get the bits from the appropriate constant word. */
5064 if (shift < HOST_BITS_PER_WIDE_INT)
5065 value = TREE_INT_CST_LOW (local->val);
5068 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5069 value = TREE_INT_CST_HIGH (local->val);
5070 shift -= HOST_BITS_PER_WIDE_INT;
5073 /* Get the result. This works only when:
5074 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5075 local->byte |= (((value >> shift)
5076 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5077 << (BITS_PER_UNIT - this_time - next_bit));
5081 /* On little-endian machines,
5082 take first the least significant bits of the value
5083 and pack them starting at the least significant
5084 bits of the bytes. */
5085 shift = next_offset - byte_relative_ebitpos;
5087 /* Don't try to take a bunch of bits that cross
5088 the word boundary in the INTEGER_CST. We can
5089 only select bits from the LOW or HIGH part
5091 if (shift < HOST_BITS_PER_WIDE_INT
5092 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5093 this_time = (HOST_BITS_PER_WIDE_INT - shift);
5095 /* Now get the bits from the appropriate constant word. */
5096 if (shift < HOST_BITS_PER_WIDE_INT)
5097 value = TREE_INT_CST_LOW (local->val);
5100 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5101 value = TREE_INT_CST_HIGH (local->val);
5102 shift -= HOST_BITS_PER_WIDE_INT;
5105 /* Get the result. This works only when:
5106 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5107 local->byte |= (((value >> shift)
5108 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5112 next_offset += this_time;
5113 local->byte_buffer_in_use = true;
5117 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5118 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5119 caller output state of relevance in recursive invocations. */
5121 static unsigned HOST_WIDE_INT
5122 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
5123 unsigned int align, oc_outer_state * outer)
5125 unsigned HOST_WIDE_INT cnt;
5126 constructor_elt *ce;
5128 oc_local_state local;
5130 /* Setup our local state to communicate with helpers. */
5133 local.align = align;
5135 local.total_bytes = 0;
5136 local.byte_buffer_in_use = outer != NULL;
5137 local.byte = outer ? outer->byte : 0;
5139 local.type = TREE_TYPE (exp);
5141 local.last_relative_index = -1;
5143 local.min_index = NULL_TREE;
5144 if (TREE_CODE (local.type) == ARRAY_TYPE
5145 && TYPE_DOMAIN (local.type) != NULL_TREE)
5146 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5148 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
5150 /* As CE goes through the elements of the constant, FIELD goes through the
5151 structure fields if the constant is a structure. If the constant is a
5152 union, we override this by getting the field from the TREE_LIST element.
5153 But the constant could also be an array. Then FIELD is zero.
5155 There is always a maximum of one element in the chain LINK for unions
5156 (even if the initializer in a source program incorrectly contains
5159 local.field = NULL_TREE;
5160 if (TREE_CODE (local.type) == RECORD_TYPE)
5161 local.field = TYPE_FIELDS (local.type);
5164 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
5165 cnt++, local.field = local.field ? TREE_CHAIN (local.field) : 0)
5167 local.val = ce->value;
5168 local.index = NULL_TREE;
5170 /* The element in a union constructor specifies the proper field
5172 if ((TREE_CODE (local.type) == RECORD_TYPE
5173 || TREE_CODE (local.type) == UNION_TYPE
5174 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
5175 && ce->index != NULL_TREE)
5176 local.field = ce->index;
5178 else if (TREE_CODE (local.type) == ARRAY_TYPE)
5179 local.index = ce->index;
5181 #ifdef ASM_COMMENT_START
5182 if (local.field && flag_verbose_asm)
5183 fprintf (asm_out_file, "%s %s:\n",
5185 DECL_NAME (local.field)
5186 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
5190 /* Eliminate the marker that makes a cast not be an lvalue. */
5191 if (local.val != NULL_TREE)
5192 STRIP_NOPS (local.val);
5194 /* Output the current element, using the appropriate helper ... */
5196 /* For an array slice not part of an outer bitfield. */
5198 && local.index != NULL_TREE
5199 && TREE_CODE (local.index) == RANGE_EXPR)
5200 output_constructor_array_range (&local);
5202 /* For a field that is neither a true bitfield nor part of an outer one,
5203 known to be at least byte aligned and multiple-of-bytes long. */
5205 && (local.field == NULL_TREE
5206 || !CONSTRUCTOR_BITFIELD_P (local.field)))
5207 output_constructor_regular_field (&local);
5209 /* For a true bitfield or part of an outer one. */
5211 output_constructor_bitfield (&local, outer);
5214 /* If we are not at toplevel, save the pending data for our caller.
5215 Otherwise output the pending data and padding zeros as needed. */
5217 outer->byte = local.byte;
5220 if (local.byte_buffer_in_use)
5222 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
5223 local.total_bytes++;
5226 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
5228 assemble_zeros (local.size - local.total_bytes);
5229 local.total_bytes = local.size;
5233 return local.total_bytes;
5236 /* Mark DECL as weak. */
5239 mark_weak (tree decl)
5241 DECL_WEAK (decl) = 1;
5243 if (DECL_RTL_SET_P (decl)
5244 && MEM_P (DECL_RTL (decl))
5245 && XEXP (DECL_RTL (decl), 0)
5246 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5247 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5250 /* Merge weak status between NEWDECL and OLDDECL. */
5253 merge_weak (tree newdecl, tree olddecl)
5255 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5257 if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
5260 /* We put the NEWDECL on the weak_decls list at some point
5261 and OLDDECL as well. Keep just OLDDECL on the list. */
5262 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5263 if (TREE_VALUE (*pwd) == newdecl)
5265 *pwd = TREE_CHAIN (*pwd);
5272 if (DECL_WEAK (newdecl))
5276 /* NEWDECL is weak, but OLDDECL is not. */
5278 /* If we already output the OLDDECL, we're in trouble; we can't
5279 go back and make it weak. This error cannot be caught in
5280 declare_weak because the NEWDECL and OLDDECL was not yet
5281 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5282 if (TREE_ASM_WRITTEN (olddecl))
5283 error ("weak declaration of %q+D must precede definition",
5286 /* If we've already generated rtl referencing OLDDECL, we may
5287 have done so in a way that will not function properly with
5289 else if (TREE_USED (olddecl)
5290 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
5291 warning (0, "weak declaration of %q+D after first use results "
5292 "in unspecified behavior", newdecl);
5296 /* We put the NEWDECL on the weak_decls list at some point.
5297 Replace it with the OLDDECL. */
5298 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5299 if (TREE_VALUE (wd) == newdecl)
5301 TREE_VALUE (wd) = olddecl;
5304 /* We may not find the entry on the list. If NEWDECL is a
5305 weak alias, then we will have already called
5306 globalize_decl to remove the entry; in that case, we do
5307 not need to do anything. */
5310 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5311 mark_weak (olddecl);
5314 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5315 weak. Just update NEWDECL to indicate that it's weak too. */
5316 mark_weak (newdecl);
5319 /* Declare DECL to be a weak symbol. */
5322 declare_weak (tree decl)
5324 if (! TREE_PUBLIC (decl))
5325 error ("weak declaration of %q+D must be public", decl);
5326 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
5327 error ("weak declaration of %q+D must precede definition", decl);
5328 else if (!SUPPORTS_WEAK)
5329 warning (0, "weak declaration of %q+D not supported", decl);
5332 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5333 DECL_ATTRIBUTES (decl)
5334 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5338 weak_finish_1 (tree decl)
5340 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5341 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5344 if (! TREE_USED (decl))
5347 #ifdef ASM_WEAKEN_DECL
5348 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5350 #ifdef ASM_WEAKEN_LABEL
5351 ASM_WEAKEN_LABEL (asm_out_file, name);
5353 #ifdef ASM_OUTPUT_WEAK_ALIAS
5355 static bool warn_once = 0;
5358 warning (0, "only weak aliases are supported in this configuration");
5368 /* This TREE_LIST contains weakref targets. */
5370 static GTY(()) tree weakref_targets;
5372 /* Forward declaration. */
5373 static tree find_decl_and_mark_needed (tree decl, tree target);
5375 /* Emit any pending weak declarations. */
5382 for (t = weakref_targets; t; t = TREE_CHAIN (t))
5384 tree alias_decl = TREE_PURPOSE (t);
5385 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5387 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5388 /* Remove alias_decl from the weak list, but leave entries for
5389 the target alone. */
5391 #ifndef ASM_OUTPUT_WEAKREF
5392 else if (! TREE_SYMBOL_REFERENCED (target))
5394 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5395 defined, otherwise we and weak_finish_1 would use
5396 different macros. */
5397 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5398 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5400 tree decl = find_decl_and_mark_needed (alias_decl, target);
5404 decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5405 TREE_CODE (alias_decl), target,
5406 TREE_TYPE (alias_decl));
5408 DECL_EXTERNAL (decl) = 1;
5409 TREE_PUBLIC (decl) = 1;
5410 DECL_ARTIFICIAL (decl) = 1;
5411 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5412 TREE_USED (decl) = 1;
5415 weak_finish_1 (decl);
5424 /* Remove the alias and the target from the pending weak list
5425 so that we do not emit any .weak directives for the former,
5426 nor multiple .weak directives for the latter. */
5427 for (p = &weak_decls; (t2 = *p) ; )
5429 if (TREE_VALUE (t2) == alias_decl
5430 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5431 *p = TREE_CHAIN (t2);
5433 p = &TREE_CHAIN (t2);
5436 /* Remove other weakrefs to the same target, to speed things up. */
5437 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5439 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5440 *p = TREE_CHAIN (t2);
5442 p = &TREE_CHAIN (t2);
5447 for (t = weak_decls; t; t = TREE_CHAIN (t))
5449 tree decl = TREE_VALUE (t);
5451 weak_finish_1 (decl);
5455 /* Emit the assembly bits to indicate that DECL is globally visible. */
5458 globalize_decl (tree decl)
5461 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5462 if (DECL_WEAK (decl))
5464 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5467 #ifdef ASM_WEAKEN_DECL
5468 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5470 ASM_WEAKEN_LABEL (asm_out_file, name);
5473 /* Remove this function from the pending weak list so that
5474 we do not emit multiple .weak directives for it. */
5475 for (p = &weak_decls; (t = *p) ; )
5477 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5478 *p = TREE_CHAIN (t);
5480 p = &TREE_CHAIN (t);
5483 /* Remove weakrefs to the same target from the pending weakref
5484 list, for the same reason. */
5485 for (p = &weakref_targets; (t = *p) ; )
5487 if (DECL_ASSEMBLER_NAME (decl)
5488 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5489 *p = TREE_CHAIN (t);
5491 p = &TREE_CHAIN (t);
5498 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5501 VEC(alias_pair,gc) *alias_pairs;
5503 /* Given an assembly name, find the decl it is associated with. At the
5504 same time, mark it needed for cgraph. */
5507 find_decl_and_mark_needed (tree decl, tree target)
5509 struct cgraph_node *fnode = NULL;
5510 struct varpool_node *vnode = NULL;
5512 if (TREE_CODE (decl) == FUNCTION_DECL)
5514 fnode = cgraph_node_for_asm (target);
5516 vnode = varpool_node_for_asm (target);
5520 vnode = varpool_node_for_asm (target);
5522 fnode = cgraph_node_for_asm (target);
5527 cgraph_mark_needed_node (fnode);
5532 varpool_mark_needed_node (vnode);
5539 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5540 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5541 tree node is DECL to have the value of the tree node TARGET. */
5544 do_assemble_alias (tree decl, tree target)
5546 if (TREE_ASM_WRITTEN (decl))
5549 /* We must force creation of DECL_RTL for debug info generation, even though
5550 we don't use it here. */
5551 make_decl_rtl (decl);
5553 TREE_ASM_WRITTEN (decl) = 1;
5554 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5556 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5558 ultimate_transparent_alias_target (&target);
5560 if (!targetm.have_tls
5561 && TREE_CODE (decl) == VAR_DECL
5562 && DECL_THREAD_LOCAL_P (decl))
5564 decl = emutls_decl (decl);
5565 target = get_emutls_object_name (target);
5568 if (!TREE_SYMBOL_REFERENCED (target))
5569 weakref_targets = tree_cons (decl, target, weakref_targets);
5571 #ifdef ASM_OUTPUT_WEAKREF
5572 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5573 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5574 IDENTIFIER_POINTER (target));
5578 error_at (DECL_SOURCE_LOCATION (decl),
5579 "weakref is not supported in this configuration");
5586 if (!targetm.have_tls
5587 && TREE_CODE (decl) == VAR_DECL
5588 && DECL_THREAD_LOCAL_P (decl))
5590 decl = emutls_decl (decl);
5591 target = get_emutls_object_name (target);
5594 #ifdef ASM_OUTPUT_DEF
5595 /* Make name accessible from other files, if appropriate. */
5597 if (TREE_PUBLIC (decl))
5599 globalize_decl (decl);
5600 maybe_assemble_visibility (decl);
5603 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5604 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5606 ASM_OUTPUT_DEF (asm_out_file,
5607 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5608 IDENTIFIER_POINTER (target));
5610 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5615 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5616 # ifdef ASM_WEAKEN_DECL
5617 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5619 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5621 /* Remove this function from the pending weak list so that
5622 we do not emit multiple .weak directives for it. */
5623 for (p = &weak_decls; (t = *p) ; )
5624 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5625 *p = TREE_CHAIN (t);
5627 p = &TREE_CHAIN (t);
5629 /* Remove weakrefs to the same target from the pending weakref
5630 list, for the same reason. */
5631 for (p = &weakref_targets; (t = *p) ; )
5633 if (DECL_ASSEMBLER_NAME (decl)
5634 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5635 *p = TREE_CHAIN (t);
5637 p = &TREE_CHAIN (t);
5644 /* Remove the alias pairing for functions that are no longer in the call
5648 remove_unreachable_alias_pairs (void)
5653 if (alias_pairs == NULL)
5656 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5658 if (!DECL_EXTERNAL (p->decl))
5660 struct cgraph_node *fnode = NULL;
5661 struct varpool_node *vnode = NULL;
5662 fnode = cgraph_node_for_asm (p->target);
5663 vnode = (fnode == NULL) ? varpool_node_for_asm (p->target) : NULL;
5664 if (fnode == NULL && vnode == NULL)
5666 VEC_unordered_remove (alias_pair, alias_pairs, i);
5676 /* First pass of completing pending aliases. Make sure that cgraph knows
5677 which symbols will be required. */
5680 finish_aliases_1 (void)
5685 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5689 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5690 if (target_decl == NULL)
5692 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5693 error ("%q+D aliased to undefined symbol %qE",
5694 p->decl, p->target);
5696 else if (DECL_EXTERNAL (target_decl)
5697 /* We use local aliases for C++ thunks to force the tailcall
5698 to bind locally. Of course this is a hack - to keep it
5699 working do the following (which is not strictly correct). */
5700 && (! TREE_CODE (target_decl) == FUNCTION_DECL
5701 || ! DECL_VIRTUAL_P (target_decl))
5702 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5703 error ("%q+D aliased to external symbol %qE",
5704 p->decl, p->target);
5708 /* Second pass of completing pending aliases. Emit the actual assembly.
5709 This happens at the end of compilation and thus it is assured that the
5710 target symbol has been emitted. */
5713 finish_aliases_2 (void)
5718 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
5719 do_assemble_alias (p->decl, p->target);
5721 VEC_truncate (alias_pair, alias_pairs, 0);
5724 /* Emit an assembler directive to make the symbol for DECL an alias to
5725 the symbol for TARGET. */
5728 assemble_alias (tree decl, tree target)
5731 bool is_weakref = false;
5733 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5735 tree alias = DECL_ASSEMBLER_NAME (decl);
5739 ultimate_transparent_alias_target (&target);
5741 if (alias == target)
5742 error ("weakref %q+D ultimately targets itself", decl);
5745 #ifndef ASM_OUTPUT_WEAKREF
5746 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5747 TREE_CHAIN (alias) = target;
5750 if (TREE_PUBLIC (decl))
5751 error ("weakref %q+D must have static linkage", decl);
5755 #if !defined (ASM_OUTPUT_DEF)
5756 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5757 error_at (DECL_SOURCE_LOCATION (decl),
5758 "alias definitions not supported in this configuration");
5761 if (!DECL_WEAK (decl))
5763 error_at (DECL_SOURCE_LOCATION (decl),
5764 "only weak aliases are supported in this configuration");
5770 TREE_USED (decl) = 1;
5772 /* A quirk of the initial implementation of aliases required that the user
5773 add "extern" to all of them. Which is silly, but now historical. Do
5774 note that the symbol is in fact locally defined. */
5776 DECL_EXTERNAL (decl) = 0;
5778 /* Allow aliases to aliases. */
5779 if (TREE_CODE (decl) == FUNCTION_DECL)
5780 cgraph_node (decl)->alias = true;
5782 varpool_node (decl)->alias = true;
5784 /* If the target has already been emitted, we don't have to queue the
5785 alias. This saves a tad of memory. */
5786 if (cgraph_global_info_ready)
5787 target_decl = find_decl_and_mark_needed (decl, target);
5790 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5791 do_assemble_alias (decl, target);
5794 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5800 /* Emit an assembler directive to set symbol for DECL visibility to
5801 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5804 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
5805 int vis ATTRIBUTE_UNUSED)
5807 #ifdef HAVE_GAS_HIDDEN
5808 static const char * const visibility_types[] = {
5809 NULL, "protected", "hidden", "internal"
5812 const char *name, *type;
5814 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5815 type = visibility_types[vis];
5817 fprintf (asm_out_file, "\t.%s\t", type);
5818 assemble_name (asm_out_file, name);
5819 fprintf (asm_out_file, "\n");
5821 warning (OPT_Wattributes, "visibility attribute not supported "
5822 "in this configuration; ignored");
5826 /* A helper function to call assemble_visibility when needed for a decl. */
5829 maybe_assemble_visibility (tree decl)
5831 enum symbol_visibility vis = DECL_VISIBILITY (decl);
5833 if (vis != VISIBILITY_DEFAULT)
5835 targetm.asm_out.visibility (decl, vis);
5842 /* Returns 1 if the target configuration supports defining public symbols
5843 so that one of them will be chosen at link time instead of generating a
5844 multiply-defined symbol error, whether through the use of weak symbols or
5845 a target-specific mechanism for having duplicates discarded. */
5848 supports_one_only (void)
5850 if (SUPPORTS_ONE_ONLY)
5852 return SUPPORTS_WEAK;
5855 /* Set up DECL as a public symbol that can be defined in multiple
5856 translation units without generating a linker error. */
5859 make_decl_one_only (tree decl, tree comdat_group)
5861 gcc_assert (TREE_CODE (decl) == VAR_DECL
5862 || TREE_CODE (decl) == FUNCTION_DECL);
5864 TREE_PUBLIC (decl) = 1;
5866 if (SUPPORTS_ONE_ONLY)
5868 #ifdef MAKE_DECL_ONE_ONLY
5869 MAKE_DECL_ONE_ONLY (decl);
5871 DECL_COMDAT_GROUP (decl) = comdat_group;
5873 else if (TREE_CODE (decl) == VAR_DECL
5874 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5875 DECL_COMMON (decl) = 1;
5878 gcc_assert (SUPPORTS_WEAK);
5879 DECL_WEAK (decl) = 1;
5884 init_varasm_once (void)
5886 section_htab = htab_create_ggc (31, section_entry_hash,
5887 section_entry_eq, NULL);
5888 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
5889 object_block_entry_eq, NULL);
5890 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
5891 const_desc_eq, NULL);
5893 const_alias_set = new_alias_set ();
5894 shared_constant_pool = create_constant_pool ();
5896 #ifdef TEXT_SECTION_ASM_OP
5897 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
5898 TEXT_SECTION_ASM_OP);
5901 #ifdef DATA_SECTION_ASM_OP
5902 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5903 DATA_SECTION_ASM_OP);
5906 #ifdef SDATA_SECTION_ASM_OP
5907 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
5908 SDATA_SECTION_ASM_OP);
5911 #ifdef READONLY_DATA_SECTION_ASM_OP
5912 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
5913 READONLY_DATA_SECTION_ASM_OP);
5916 #ifdef CTORS_SECTION_ASM_OP
5917 ctors_section = get_unnamed_section (0, output_section_asm_op,
5918 CTORS_SECTION_ASM_OP);
5921 #ifdef DTORS_SECTION_ASM_OP
5922 dtors_section = get_unnamed_section (0, output_section_asm_op,
5923 DTORS_SECTION_ASM_OP);
5926 #ifdef BSS_SECTION_ASM_OP
5927 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5928 output_section_asm_op,
5929 BSS_SECTION_ASM_OP);
5932 #ifdef SBSS_SECTION_ASM_OP
5933 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
5934 output_section_asm_op,
5935 SBSS_SECTION_ASM_OP);
5938 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5939 | SECTION_COMMON, emit_tls_common);
5940 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5941 | SECTION_COMMON, emit_local);
5942 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
5943 | SECTION_COMMON, emit_common);
5945 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5946 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
5950 targetm.asm_out.init_sections ();
5952 if (readonly_data_section == NULL)
5953 readonly_data_section = text_section;
5957 decl_default_tls_model (const_tree decl)
5959 enum tls_model kind;
5962 is_local = targetm.binds_local_p (decl);
5966 kind = TLS_MODEL_LOCAL_EXEC;
5968 kind = TLS_MODEL_INITIAL_EXEC;
5971 /* Local dynamic is inefficient when we're not combining the
5972 parts of the address. */
5973 else if (optimize && is_local)
5974 kind = TLS_MODEL_LOCAL_DYNAMIC;
5976 kind = TLS_MODEL_GLOBAL_DYNAMIC;
5977 if (kind < flag_tls_default)
5978 kind = flag_tls_default;
5983 /* Select a set of attributes for section NAME based on the properties
5984 of DECL and whether or not RELOC indicates that DECL's initializer
5985 might contain runtime relocations.
5987 We make the section read-only and executable for a function decl,
5988 read-only for a const data decl, and writable for a non-const data decl. */
5991 default_section_type_flags (tree decl, const char *name, int reloc)
5995 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5996 flags = SECTION_CODE;
5997 else if (decl && decl_readonly_section (decl, reloc))
5999 else if (current_function_decl
6001 && crtl->subsections.unlikely_text_section_name
6002 && strcmp (name, crtl->subsections.unlikely_text_section_name) == 0)
6003 flags = SECTION_CODE;
6005 && (!current_function_decl || !cfun)
6006 && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6007 flags = SECTION_CODE;
6009 flags = SECTION_WRITE;
6011 if (decl && DECL_ONE_ONLY (decl))
6012 flags |= SECTION_LINKONCE;
6014 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6015 flags |= SECTION_TLS | SECTION_WRITE;
6017 if (strcmp (name, ".bss") == 0
6018 || strncmp (name, ".bss.", 5) == 0
6019 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
6020 || strcmp (name, ".sbss") == 0
6021 || strncmp (name, ".sbss.", 6) == 0
6022 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
6023 flags |= SECTION_BSS;
6025 if (strcmp (name, ".tdata") == 0
6026 || strncmp (name, ".tdata.", 7) == 0
6027 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
6028 flags |= SECTION_TLS;
6030 if (strcmp (name, ".tbss") == 0
6031 || strncmp (name, ".tbss.", 6) == 0
6032 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
6033 flags |= SECTION_TLS | SECTION_BSS;
6035 /* These three sections have special ELF types. They are neither
6036 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6037 want to print a section type (@progbits or @nobits). If someone
6038 is silly enough to emit code or TLS variables to one of these
6039 sections, then don't handle them specially. */
6040 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
6041 && (strcmp (name, ".init_array") == 0
6042 || strcmp (name, ".fini_array") == 0
6043 || strcmp (name, ".preinit_array") == 0))
6044 flags |= SECTION_NOTYPE;
6049 /* Return true if the target supports some form of global BSS,
6050 either through bss_noswitch_section, or by selecting a BSS
6051 section in TARGET_ASM_SELECT_SECTION. */
6054 have_global_bss_p (void)
6056 return bss_noswitch_section || targetm.have_switchable_bss_sections;
6059 /* Output assembly to switch to section NAME with attribute FLAGS.
6060 Four variants for common object file formats. */
6063 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
6064 unsigned int flags ATTRIBUTE_UNUSED,
6065 tree decl ATTRIBUTE_UNUSED)
6067 /* Some object formats don't support named sections at all. The
6068 front-end should already have flagged this as an error. */
6072 #ifndef TLS_SECTION_ASM_FLAG
6073 #define TLS_SECTION_ASM_FLAG 'T'
6077 default_elf_asm_named_section (const char *name, unsigned int flags,
6078 tree decl ATTRIBUTE_UNUSED)
6080 char flagchars[10], *f = flagchars;
6082 /* If we have already declared this section, we can use an
6083 abbreviated form to switch back to it -- unless this section is
6084 part of a COMDAT groups, in which case GAS requires the full
6085 declaration every time. */
6086 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6087 && (flags & SECTION_DECLARED))
6089 fprintf (asm_out_file, "\t.section\t%s\n", name);
6093 if (!(flags & SECTION_DEBUG))
6095 if (flags & SECTION_WRITE)
6097 if (flags & SECTION_CODE)
6099 if (flags & SECTION_SMALL)
6101 if (flags & SECTION_MERGE)
6103 if (flags & SECTION_STRINGS)
6105 if (flags & SECTION_TLS)
6106 *f++ = TLS_SECTION_ASM_FLAG;
6107 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6111 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
6113 if (!(flags & SECTION_NOTYPE))
6118 if (flags & SECTION_BSS)
6124 #ifdef ASM_COMMENT_START
6125 /* On platforms that use "@" as the assembly comment character,
6127 if (strcmp (ASM_COMMENT_START, "@") == 0)
6130 fprintf (asm_out_file, format, type);
6132 if (flags & SECTION_ENTSIZE)
6133 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
6134 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6136 if (TREE_CODE (decl) == IDENTIFIER_NODE)
6137 fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
6139 fprintf (asm_out_file, ",%s,comdat",
6140 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
6144 putc ('\n', asm_out_file);
6148 default_coff_asm_named_section (const char *name, unsigned int flags,
6149 tree decl ATTRIBUTE_UNUSED)
6151 char flagchars[8], *f = flagchars;
6153 if (flags & SECTION_WRITE)
6155 if (flags & SECTION_CODE)
6159 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
6163 default_pe_asm_named_section (const char *name, unsigned int flags,
6166 default_coff_asm_named_section (name, flags, decl);
6168 if (flags & SECTION_LINKONCE)
6170 /* Functions may have been compiled at various levels of
6171 optimization so we can't use `same_size' here.
6172 Instead, have the linker pick one. */
6173 fprintf (asm_out_file, "\t.linkonce %s\n",
6174 (flags & SECTION_CODE ? "discard" : "same_size"));
6178 /* The lame default section selector. */
6181 default_select_section (tree decl, int reloc,
6182 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6186 if (decl_readonly_section (decl, reloc))
6187 return readonly_data_section;
6189 else if (TREE_CODE (decl) == CONSTRUCTOR)
6191 if (! ((flag_pic && reloc)
6192 || !TREE_READONLY (decl)
6193 || TREE_SIDE_EFFECTS (decl)
6194 || !TREE_CONSTANT (decl)))
6195 return readonly_data_section;
6197 else if (TREE_CODE (decl) == STRING_CST)
6198 return readonly_data_section;
6199 else if (! (flag_pic && reloc))
6200 return readonly_data_section;
6202 return data_section;
6205 enum section_category
6206 categorize_decl_for_section (const_tree decl, int reloc)
6208 enum section_category ret;
6210 if (TREE_CODE (decl) == FUNCTION_DECL)
6212 else if (TREE_CODE (decl) == STRING_CST)
6214 if (flag_mudflap) /* or !flag_merge_constants */
6215 return SECCAT_RODATA;
6217 return SECCAT_RODATA_MERGE_STR;
6219 else if (TREE_CODE (decl) == VAR_DECL)
6221 if (bss_initializer_p (decl))
6223 else if (! TREE_READONLY (decl)
6224 || TREE_SIDE_EFFECTS (decl)
6225 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6227 /* Here the reloc_rw_mask is not testing whether the section should
6228 be read-only or not, but whether the dynamic link will have to
6229 do something. If so, we wish to segregate the data in order to
6230 minimize cache misses inside the dynamic linker. */
6231 if (reloc & targetm.asm_out.reloc_rw_mask ())
6232 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6236 else if (reloc & targetm.asm_out.reloc_rw_mask ())
6237 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6238 else if (reloc || flag_merge_constants < 2)
6239 /* C and C++ don't allow different variables to share the same
6240 location. -fmerge-all-constants allows even that (at the
6241 expense of not conforming). */
6242 ret = SECCAT_RODATA;
6243 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6244 ret = SECCAT_RODATA_MERGE_STR_INIT;
6246 ret = SECCAT_RODATA_MERGE_CONST;
6248 else if (TREE_CODE (decl) == CONSTRUCTOR)
6250 if ((reloc & targetm.asm_out.reloc_rw_mask ())
6251 || TREE_SIDE_EFFECTS (decl)
6252 || ! TREE_CONSTANT (decl))
6255 ret = SECCAT_RODATA;
6258 ret = SECCAT_RODATA;
6260 /* There are no read-only thread-local sections. */
6261 if (TREE_CODE (decl) == VAR_DECL && DECL_TLS_MODEL (decl))
6263 if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED)
6265 if (DECL_EMUTLS_VAR_P (decl))
6267 if (targetm.emutls.var_section)
6268 ret = SECCAT_EMUTLS_VAR;
6272 if (targetm.emutls.tmpl_prefix)
6273 ret = SECCAT_EMUTLS_TMPL;
6276 /* Note that this would be *just* SECCAT_BSS, except that there's
6277 no concept of a read-only thread-local-data section. */
6278 else if (ret == SECCAT_BSS
6279 || (flag_zero_initialized_in_bss
6280 && initializer_zerop (DECL_INITIAL (decl))))
6286 /* If the target uses small data sections, select it. */
6287 else if (targetm.in_small_data_p (decl))
6289 if (ret == SECCAT_BSS)
6291 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6292 ret = SECCAT_SRODATA;
6301 decl_readonly_section (const_tree decl, int reloc)
6303 switch (categorize_decl_for_section (decl, reloc))
6306 case SECCAT_RODATA_MERGE_STR:
6307 case SECCAT_RODATA_MERGE_STR_INIT:
6308 case SECCAT_RODATA_MERGE_CONST:
6309 case SECCAT_SRODATA:
6318 /* Select a section based on the above categorization. */
6321 default_elf_select_section (tree decl, int reloc,
6322 unsigned HOST_WIDE_INT align)
6325 switch (categorize_decl_for_section (decl, reloc))
6328 /* We're not supposed to be called on FUNCTION_DECLs. */
6331 return readonly_data_section;
6332 case SECCAT_RODATA_MERGE_STR:
6333 return mergeable_string_section (decl, align, 0);
6334 case SECCAT_RODATA_MERGE_STR_INIT:
6335 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6336 case SECCAT_RODATA_MERGE_CONST:
6337 return mergeable_constant_section (DECL_MODE (decl), align, 0);
6338 case SECCAT_SRODATA:
6342 return data_section;
6343 case SECCAT_DATA_REL:
6344 sname = ".data.rel";
6346 case SECCAT_DATA_REL_LOCAL:
6347 sname = ".data.rel.local";
6349 case SECCAT_DATA_REL_RO:
6350 sname = ".data.rel.ro";
6352 case SECCAT_DATA_REL_RO_LOCAL:
6353 sname = ".data.rel.ro.local";
6372 case SECCAT_EMUTLS_VAR:
6373 sname = targetm.emutls.var_section;
6375 case SECCAT_EMUTLS_TMPL:
6376 sname = targetm.emutls.tmpl_section;
6384 return get_named_section (decl, sname, reloc);
6387 /* Construct a unique section name based on the decl name and the
6388 categorization performed above. */
6391 default_unique_section (tree decl, int reloc)
6393 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6394 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6395 const char *prefix, *name, *linkonce;
6398 switch (categorize_decl_for_section (decl, reloc))
6401 prefix = one_only ? ".t" : ".text";
6404 case SECCAT_RODATA_MERGE_STR:
6405 case SECCAT_RODATA_MERGE_STR_INIT:
6406 case SECCAT_RODATA_MERGE_CONST:
6407 prefix = one_only ? ".r" : ".rodata";
6409 case SECCAT_SRODATA:
6410 prefix = one_only ? ".s2" : ".sdata2";
6413 prefix = one_only ? ".d" : ".data";
6415 case SECCAT_DATA_REL:
6416 prefix = one_only ? ".d.rel" : ".data.rel";
6418 case SECCAT_DATA_REL_LOCAL:
6419 prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6421 case SECCAT_DATA_REL_RO:
6422 prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6424 case SECCAT_DATA_REL_RO_LOCAL:
6425 prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6428 prefix = one_only ? ".s" : ".sdata";
6431 prefix = one_only ? ".b" : ".bss";
6434 prefix = one_only ? ".sb" : ".sbss";
6437 prefix = one_only ? ".td" : ".tdata";
6440 prefix = one_only ? ".tb" : ".tbss";
6442 case SECCAT_EMUTLS_VAR:
6443 prefix = targetm.emutls.var_section;
6445 case SECCAT_EMUTLS_TMPL:
6446 prefix = targetm.emutls.tmpl_section;
6452 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6453 name = targetm.strip_name_encoding (name);
6455 /* If we're using one_only, then there needs to be a .gnu.linkonce
6456 prefix to the section name. */
6457 linkonce = one_only ? ".gnu.linkonce" : "";
6459 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6461 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6464 /* Like compute_reloc_for_constant, except for an RTX. The return value
6465 is a mask for which bit 1 indicates a global relocation, and bit 0
6466 indicates a local relocation. */
6469 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6471 int *preloc = (int *) data;
6474 switch (GET_CODE (x))
6477 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6490 compute_reloc_for_rtx (rtx x)
6494 switch (GET_CODE (x))
6500 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6509 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6511 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6513 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6514 return data_section;
6516 return readonly_data_section;
6520 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6521 unsigned HOST_WIDE_INT align)
6523 int reloc = compute_reloc_for_rtx (x);
6525 /* ??? Handle small data here somehow. */
6527 if (reloc & targetm.asm_out.reloc_rw_mask ())
6530 return get_named_section (NULL, ".data.rel.ro.local", 1);
6532 return get_named_section (NULL, ".data.rel.ro", 3);
6535 return mergeable_constant_section (mode, align, 0);
6538 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6541 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6546 /* Careful not to prod global register variables. */
6549 symbol = XEXP (rtl, 0);
6550 if (GET_CODE (symbol) != SYMBOL_REF)
6553 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6554 if (TREE_CODE (decl) == FUNCTION_DECL)
6555 flags |= SYMBOL_FLAG_FUNCTION;
6556 if (targetm.binds_local_p (decl))
6557 flags |= SYMBOL_FLAG_LOCAL;
6558 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)
6559 && DECL_TLS_MODEL (decl) != TLS_MODEL_EMULATED)
6560 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6561 else if (targetm.in_small_data_p (decl))
6562 flags |= SYMBOL_FLAG_SMALL;
6563 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6564 being PUBLIC, the thing *must* be defined in this translation unit.
6565 Prevent this buglet from being propagated into rtl code as well. */
6566 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6567 flags |= SYMBOL_FLAG_EXTERNAL;
6569 SYMBOL_REF_FLAGS (symbol) = flags;
6572 /* By default, we do nothing for encode_section_info, so we need not
6573 do anything but discard the '*' marker. */
6576 default_strip_name_encoding (const char *str)
6578 return str + (*str == '*');
6581 #ifdef ASM_OUTPUT_DEF
6582 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6583 anchor relative to ".", the current section position. */
6586 default_asm_output_anchor (rtx symbol)
6590 sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6591 SYMBOL_REF_BLOCK_OFFSET (symbol));
6592 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6596 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6599 default_use_anchors_for_symbol_p (const_rtx symbol)
6604 /* Don't use anchors for mergeable sections. The linker might move
6605 the objects around. */
6606 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6607 if (sect->common.flags & SECTION_MERGE)
6610 /* Don't use anchors for small data sections. The small data register
6611 acts as an anchor for such sections. */
6612 if (sect->common.flags & SECTION_SMALL)
6615 decl = SYMBOL_REF_DECL (symbol);
6616 if (decl && DECL_P (decl))
6618 /* Don't use section anchors for decls that might be defined by
6620 if (!targetm.binds_local_p (decl))
6623 /* Don't use section anchors for decls that will be placed in a
6624 small data section. */
6625 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6626 one above. The problem is that we only use SECTION_SMALL for
6627 sections that should be marked as small in the section directive. */
6628 if (targetm.in_small_data_p (decl))
6634 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6635 wrt cross-module name binding. */
6638 default_binds_local_p (const_tree exp)
6640 return default_binds_local_p_1 (exp, flag_shlib);
6644 default_binds_local_p_1 (const_tree exp, int shlib)
6648 /* A non-decl is an entry in the constant pool. */
6651 /* Weakrefs may not bind locally, even though the weakref itself is
6652 always static and therefore local. */
6653 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
6655 /* Static variables are always local. */
6656 else if (! TREE_PUBLIC (exp))
6658 /* A variable is local if the user has said explicitly that it will
6660 else if (DECL_VISIBILITY_SPECIFIED (exp)
6661 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6663 /* Variables defined outside this object might not be local. */
6664 else if (DECL_EXTERNAL (exp))
6666 /* If defined in this object and visibility is not default, must be
6668 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6670 /* Default visibility weak data can be overridden by a strong symbol
6671 in another module and so are not local. */
6672 else if (DECL_WEAK (exp))
6674 /* If PIC, then assume that any global name can be overridden by
6675 symbols resolved from other modules, unless we are compiling with
6676 -fwhole-program, which assumes that names are local. */
6678 local_p = flag_whole_program;
6679 /* Uninitialized COMMON variable may be unified with symbols
6680 resolved from other modules. */
6681 else if (DECL_COMMON (exp)
6682 && (DECL_INITIAL (exp) == NULL
6683 || DECL_INITIAL (exp) == error_mark_node))
6685 /* Otherwise we're left with initialized (or non-common) global data
6686 which is of necessity defined locally. */
6693 /* Default function to output code that will globalize a label. A
6694 target must define GLOBAL_ASM_OP or provide its own function to
6695 globalize a label. */
6696 #ifdef GLOBAL_ASM_OP
6698 default_globalize_label (FILE * stream, const char *name)
6700 fputs (GLOBAL_ASM_OP, stream);
6701 assemble_name (stream, name);
6702 putc ('\n', stream);
6704 #endif /* GLOBAL_ASM_OP */
6706 /* Default function to output code that will globalize a declaration. */
6708 default_globalize_decl_name (FILE * stream, tree decl)
6710 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6711 targetm.asm_out.globalize_label (stream, name);
6714 /* Default function to output a label for unwind information. The
6715 default is to do nothing. A target that needs nonlocal labels for
6716 unwind information must provide its own function to do this. */
6718 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
6719 tree decl ATTRIBUTE_UNUSED,
6720 int for_eh ATTRIBUTE_UNUSED,
6721 int empty ATTRIBUTE_UNUSED)
6725 /* Default function to output a label to divide up the exception table.
6726 The default is to do nothing. A target that needs/wants to divide
6727 up the table must provide it's own function to do this. */
6729 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
6733 /* This is how to output an internal numbered label where PREFIX is
6734 the class of label and LABELNO is the number within the class. */
6737 default_internal_label (FILE *stream, const char *prefix,
6738 unsigned long labelno)
6740 char *const buf = (char *) alloca (40 + strlen (prefix));
6741 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
6742 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
6745 /* This is the default behavior at the beginning of a file. It's
6746 controlled by two other target-hook toggles. */
6748 default_file_start (void)
6750 if (targetm.file_start_app_off
6751 && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
6752 fputs (ASM_APP_OFF, asm_out_file);
6754 if (targetm.file_start_file_directive)
6755 output_file_directive (asm_out_file, main_input_filename);
6758 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6759 which emits a special section directive used to indicate whether or
6760 not this object file needs an executable stack. This is primarily
6761 a GNU extension to ELF but could be used on other targets. */
6763 int trampolines_created;
6766 file_end_indicate_exec_stack (void)
6768 unsigned int flags = SECTION_DEBUG;
6769 if (trampolines_created)
6770 flags |= SECTION_CODE;
6772 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
6775 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6776 a get_unnamed_section callback. */
6779 output_section_asm_op (const void *directive)
6781 fprintf (asm_out_file, "%s\n", (const char *) directive);
6784 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6785 the current section is NEW_SECTION. */
6788 switch_to_section (section *new_section)
6790 if (in_section == new_section)
6793 if (new_section->common.flags & SECTION_FORGET)
6796 in_section = new_section;
6798 switch (SECTION_STYLE (new_section))
6802 && !crtl->subsections.unlikely_text_section_name
6803 && strcmp (new_section->named.name,
6804 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
6805 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
6807 targetm.asm_out.named_section (new_section->named.name,
6808 new_section->named.common.flags,
6809 new_section->named.decl);
6812 case SECTION_UNNAMED:
6813 new_section->unnamed.callback (new_section->unnamed.data);
6816 case SECTION_NOSWITCH:
6821 new_section->common.flags |= SECTION_DECLARED;
6824 /* If block symbol SYMBOL has not yet been assigned an offset, place
6825 it at the end of its block. */
6828 place_block_symbol (rtx symbol)
6830 unsigned HOST_WIDE_INT size, mask, offset;
6831 struct constant_descriptor_rtx *desc;
6832 unsigned int alignment;
6833 struct object_block *block;
6836 gcc_assert (SYMBOL_REF_BLOCK (symbol));
6837 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
6840 /* Work out the symbol's size and alignment. */
6841 if (CONSTANT_POOL_ADDRESS_P (symbol))
6843 desc = SYMBOL_REF_CONSTANT (symbol);
6844 alignment = desc->align;
6845 size = GET_MODE_SIZE (desc->mode);
6847 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6849 decl = SYMBOL_REF_DECL (symbol);
6850 alignment = get_constant_alignment (decl);
6851 size = get_constant_size (decl);
6855 decl = SYMBOL_REF_DECL (symbol);
6856 alignment = DECL_ALIGN (decl);
6857 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
6860 /* Calculate the object's offset from the start of the block. */
6861 block = SYMBOL_REF_BLOCK (symbol);
6862 mask = alignment / BITS_PER_UNIT - 1;
6863 offset = (block->size + mask) & ~mask;
6864 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
6866 /* Record the block's new alignment and size. */
6867 block->alignment = MAX (block->alignment, alignment);
6868 block->size = offset + size;
6870 VEC_safe_push (rtx, gc, block->objects, symbol);
6873 /* Return the anchor that should be used to address byte offset OFFSET
6874 from the first object in BLOCK. MODEL is the TLS model used
6878 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
6879 enum tls_model model)
6882 unsigned int begin, middle, end;
6883 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
6886 /* Work out the anchor's offset. Use an offset of 0 for the first
6887 anchor so that we don't pessimize the case where we take the address
6888 of a variable at the beginning of the block. This is particularly
6889 useful when a block has only one variable assigned to it.
6891 We try to place anchors RANGE bytes apart, so there can then be
6892 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6893 a ptr_mode offset. With some target settings, the lowest such
6894 anchor might be out of range for the lowest ptr_mode offset;
6895 likewise the highest anchor for the highest offset. Use anchors
6896 at the extreme ends of the ptr_mode range in such cases.
6898 All arithmetic uses unsigned integers in order to avoid
6900 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
6901 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
6902 range = max_offset - min_offset + 1;
6907 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
6910 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
6911 delta -= delta % range;
6914 offset = (HOST_WIDE_INT) (-delta);
6918 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
6919 delta -= delta % range;
6920 if (delta > bias - 1)
6922 offset = (HOST_WIDE_INT) delta;
6926 /* Do a binary search to see if there's already an anchor we can use.
6927 Set BEGIN to the new anchor's index if not. */
6929 end = VEC_length (rtx, block->anchors);
6930 while (begin != end)
6932 middle = (end + begin) / 2;
6933 anchor = VEC_index (rtx, block->anchors, middle);
6934 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
6936 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
6938 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
6940 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
6946 /* Create a new anchor with a unique label. */
6947 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
6948 anchor = create_block_symbol (ggc_strdup (label), block, offset);
6949 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
6950 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
6952 /* Insert it at index BEGIN. */
6953 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
6957 /* Output the objects in BLOCK. */
6960 output_object_block (struct object_block *block)
6962 struct constant_descriptor_rtx *desc;
6964 HOST_WIDE_INT offset;
6968 if (block->objects == NULL)
6971 /* Switch to the section and make sure that the first byte is
6972 suitably aligned. */
6973 switch_to_section (block->sect);
6974 assemble_align (block->alignment);
6976 /* Define the values of all anchors relative to the current section
6978 for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
6979 targetm.asm_out.output_anchor (symbol);
6981 /* Output the objects themselves. */
6983 for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
6985 /* Move to the object's offset, padding with zeros if necessary. */
6986 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
6987 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
6988 if (CONSTANT_POOL_ADDRESS_P (symbol))
6990 desc = SYMBOL_REF_CONSTANT (symbol);
6991 output_constant_pool_1 (desc, 1);
6992 offset += GET_MODE_SIZE (desc->mode);
6994 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6996 decl = SYMBOL_REF_DECL (symbol);
6997 assemble_constant_contents (decl, XSTR (symbol, 0),
6998 get_constant_alignment (decl));
6999 offset += get_constant_size (decl);
7003 decl = SYMBOL_REF_DECL (symbol);
7004 assemble_variable_contents (decl, XSTR (symbol, 0), false);
7005 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7010 /* A htab_traverse callback used to call output_object_block for
7011 each member of object_block_htab. */
7014 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
7016 output_object_block ((struct object_block *) (*slot));
7020 /* Output the definitions of all object_blocks. */
7023 output_object_blocks (void)
7025 htab_traverse (object_block_htab, output_object_block_htab, NULL);
7028 /* This function provides a possible implementation of the
7029 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7030 by -frecord-gcc-switches it creates a new mergeable, string section in the
7031 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7032 contains the switches in ASCII format.
7034 FIXME: This code does not correctly handle double quote characters
7035 that appear inside strings, (it strips them rather than preserving them).
7036 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7037 characters - instead it treats them as sub-string separators. Since
7038 we want to emit NUL strings terminators into the object file we have to use
7042 elf_record_gcc_switches (print_switch_type type, const char * name)
7044 static char buffer[1024];
7046 /* This variable is used as part of a simplistic heuristic to detect
7047 command line switches which take an argument:
7049 "If a command line option does not start with a dash then
7050 it is an argument for the previous command line option."
7052 This fails in the case of the command line option which is the name
7053 of the file to compile, but otherwise it is pretty reasonable. */
7054 static bool previous_name_held_back = FALSE;
7058 case SWITCH_TYPE_PASSED:
7061 if (previous_name_held_back)
7063 unsigned int len = strlen (buffer);
7065 snprintf (buffer + len, sizeof buffer - len, " %s", name);
7066 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7067 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7068 previous_name_held_back = FALSE;
7072 strncpy (buffer, name, sizeof buffer);
7073 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7074 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7079 if (previous_name_held_back)
7081 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7082 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7085 strncpy (buffer, name, sizeof buffer);
7086 previous_name_held_back = TRUE;
7090 case SWITCH_TYPE_DESCRIPTIVE:
7093 /* Distinguish between invocations where name is NULL. */
7094 static bool started = false;
7098 if (previous_name_held_back)
7100 ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
7101 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7108 sec = get_section (targetm.asm_out.record_gcc_switches_section,
7112 | (SECTION_ENTSIZE & 1),
7114 switch_to_section (sec);
7123 /* The return value is currently ignored by the caller, but must be 0.
7124 For -fverbose-asm the return value would be the number of characters
7125 emitted into the assembler file. */
7129 /* Emit text to declare externally defined symbols. It is needed to
7130 properly support non-default visibility. */
7132 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
7134 const char *name ATTRIBUTE_UNUSED)
7136 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7137 set in order to avoid putting out names that are never really
7139 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
7140 && targetm.binds_local_p (decl))
7141 maybe_assemble_visibility (decl);
7144 #include "gt-varasm.h"