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 /* If this variable belongs to the global constant pool, retrieve the
1358 pre-computed RTL or recompute it in LTO mode. */
1359 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1361 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1365 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1367 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1368 && DECL_REGISTER (decl
))
1370 error ("register name not specified for %q+D", decl
);
1372 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1374 const char *asmspec
= name
+1;
1375 reg_number
= decode_reg_name (asmspec
);
1376 /* First detect errors in declaring global registers. */
1377 if (reg_number
== -1)
1378 error ("register name not specified for %q+D", decl
);
1379 else if (reg_number
< 0)
1380 error ("invalid register name for %q+D", decl
);
1381 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
1382 error ("data type of %q+D isn%'t suitable for a register",
1384 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
1385 error ("register specified for %q+D isn%'t suitable for data type",
1387 /* Now handle properly declared static register variables. */
1392 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1394 DECL_INITIAL (decl
) = 0;
1395 error ("global register variable has initial value");
1397 if (TREE_THIS_VOLATILE (decl
))
1398 warning (OPT_Wvolatile_register_var
,
1399 "optimization may eliminate reads and/or "
1400 "writes to register variables");
1402 /* If the user specified one of the eliminables registers here,
1403 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1404 confused with that register and be eliminated. This usage is
1405 somewhat suspect... */
1407 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
1408 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1409 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1411 if (TREE_STATIC (decl
))
1413 /* Make this register global, so not usable for anything
1415 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1416 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1417 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1419 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
1421 globalize_reg (reg_number
+ --nregs
);
1424 /* As a register variable, it has no section. */
1428 /* Now handle ordinary static variables and functions (in memory).
1429 Also handle vars declared register invalidly. */
1430 else if (name
[0] == '*')
1432 #ifdef REGISTER_PREFIX
1433 if (strlen (REGISTER_PREFIX
) != 0)
1435 reg_number
= decode_reg_name (name
);
1436 if (reg_number
>= 0 || reg_number
== -3)
1437 error ("register name given for non-register variable %q+D", decl
);
1442 /* Specifying a section attribute on a variable forces it into a
1443 non-.bss section, and thus it cannot be common. */
1444 /* FIXME: In general this code should not be necessary because
1445 visibility pass is doing the same work. But notice_global_symbol
1446 is called early and it needs to make DECL_RTL to get the name.
1447 we take care of recomputing the DECL_RTL after visibility is changed. */
1448 if (TREE_CODE (decl
) == VAR_DECL
1449 && DECL_SECTION_NAME (decl
) != NULL_TREE
1450 && DECL_INITIAL (decl
) == NULL_TREE
1451 && DECL_COMMON (decl
))
1452 DECL_COMMON (decl
) = 0;
1454 /* Variables can't be both common and weak. */
1455 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1456 DECL_COMMON (decl
) = 0;
1458 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1459 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1462 enum machine_mode address_mode
= Pmode
;
1463 if (TREE_TYPE (decl
) != error_mark_node
)
1465 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1466 address_mode
= targetm
.addr_space
.address_mode (as
);
1468 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1470 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1471 SET_SYMBOL_REF_DECL (x
, decl
);
1473 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1474 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1475 set_mem_attributes (x
, decl
, 1);
1476 SET_DECL_RTL (decl
, x
);
1478 /* Optionally set flags or add text to the name to record information
1479 such as that it is a function name.
1480 If the name is changed, the macro ASM_OUTPUT_LABELREF
1481 will have to know how to strip this information. */
1482 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1484 /* Make this function static known to the mudflap runtime. */
1485 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1486 mudflap_enqueue_decl (decl
);
1489 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1490 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1494 make_decl_rtl_for_debug (tree decl
)
1496 unsigned int save_aliasing_flag
, save_mudflap_flag
;
1499 if (DECL_RTL_SET_P (decl
))
1500 return DECL_RTL (decl
);
1502 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1503 call new_alias_set. If running with -fcompare-debug, sometimes
1504 we do not want to create alias sets that will throw the alias
1505 numbers off in the comparison dumps. So... clearing
1506 flag_strict_aliasing will keep new_alias_set() from creating a
1507 new set. It is undesirable to register decl with mudflap
1508 in this case as well. */
1509 save_aliasing_flag
= flag_strict_aliasing
;
1510 flag_strict_aliasing
= 0;
1511 save_mudflap_flag
= flag_mudflap
;
1514 rtl
= DECL_RTL (decl
);
1515 /* Reset DECL_RTL back, as various parts of the compiler expects
1516 DECL_RTL set meaning it is actually going to be output. */
1517 SET_DECL_RTL (decl
, NULL
);
1519 flag_strict_aliasing
= save_aliasing_flag
;
1520 flag_mudflap
= save_mudflap_flag
;
1525 /* Output a string of literal assembler code
1526 for an `asm' keyword used between functions. */
1529 assemble_asm (tree string
)
1533 if (TREE_CODE (string
) == ADDR_EXPR
)
1534 string
= TREE_OPERAND (string
, 0);
1536 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1539 /* Record an element in the table of global destructors. SYMBOL is
1540 a SYMBOL_REF of the function to be called; PRIORITY is a number
1541 between 0 and MAX_INIT_PRIORITY. */
1544 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
1545 int priority ATTRIBUTE_UNUSED
)
1547 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1548 /* Tell GNU LD that this is part of the static destructor set.
1549 This will work for any system that uses stabs, most usefully
1551 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1552 dbxout_stab_value_label (XSTR (symbol
, 0));
1554 sorry ("global destructors not supported on this target");
1558 /* Write the address of the entity given by SYMBOL to SEC. */
1560 assemble_addr_to_section (rtx symbol
, section
*sec
)
1562 switch_to_section (sec
);
1563 assemble_align (POINTER_SIZE
);
1564 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1567 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1568 not) section for PRIORITY. */
1570 get_cdtor_priority_section (int priority
, bool constructor_p
)
1574 /* ??? This only works reliably with the GNU linker. */
1575 sprintf (buf
, "%s.%.5u",
1576 constructor_p
? ".ctors" : ".dtors",
1577 /* Invert the numbering so the linker puts us in the proper
1578 order; constructors are run from right to left, and the
1579 linker sorts in increasing order. */
1580 MAX_INIT_PRIORITY
- priority
);
1581 return get_section (buf
, SECTION_WRITE
, NULL
);
1585 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1589 if (priority
!= DEFAULT_INIT_PRIORITY
)
1590 sec
= get_cdtor_priority_section (priority
,
1591 /*constructor_p=*/false);
1593 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1595 assemble_addr_to_section (symbol
, sec
);
1598 #ifdef DTORS_SECTION_ASM_OP
1600 default_dtor_section_asm_out_destructor (rtx symbol
,
1601 int priority ATTRIBUTE_UNUSED
)
1603 assemble_addr_to_section (symbol
, dtors_section
);
1607 /* Likewise for global constructors. */
1610 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
1611 int priority ATTRIBUTE_UNUSED
)
1613 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1614 /* Tell GNU LD that this is part of the static destructor set.
1615 This will work for any system that uses stabs, most usefully
1617 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1618 dbxout_stab_value_label (XSTR (symbol
, 0));
1620 sorry ("global constructors not supported on this target");
1625 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1629 if (priority
!= DEFAULT_INIT_PRIORITY
)
1630 sec
= get_cdtor_priority_section (priority
,
1631 /*constructor_p=*/true);
1633 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1635 assemble_addr_to_section (symbol
, sec
);
1638 #ifdef CTORS_SECTION_ASM_OP
1640 default_ctor_section_asm_out_constructor (rtx symbol
,
1641 int priority ATTRIBUTE_UNUSED
)
1643 assemble_addr_to_section (symbol
, ctors_section
);
1647 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1648 a nonzero value if the constant pool should be output before the
1649 start of the function, or a zero value if the pool should output
1650 after the end of the function. The default is to put it before the
1653 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1654 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1657 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1658 to be output to assembler.
1659 Set first_global_object_name and weak_global_object_name as appropriate. */
1662 notice_global_symbol (tree decl
)
1664 const char **type
= &first_global_object_name
;
1666 if (first_global_object_name
1667 || !TREE_PUBLIC (decl
)
1668 || DECL_EXTERNAL (decl
)
1669 || !DECL_NAME (decl
)
1670 || (TREE_CODE (decl
) != FUNCTION_DECL
1671 && (TREE_CODE (decl
) != VAR_DECL
1672 || (DECL_COMMON (decl
)
1673 && (DECL_INITIAL (decl
) == 0
1674 || DECL_INITIAL (decl
) == error_mark_node
))))
1675 || !MEM_P (DECL_RTL (decl
)))
1678 /* We win when global object is found, but it is useful to know about weak
1679 symbol as well so we can produce nicer unique names. */
1680 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1681 type
= &weak_global_object_name
;
1687 rtx decl_rtl
= DECL_RTL (decl
);
1689 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1690 name
= ggc_strdup (p
);
1696 /* Output assembler code for the constant pool of a function and associated
1697 with defining the name of the function. DECL describes the function.
1698 NAME is the function's name. For the constant pool, we use the current
1699 constant pool data. */
1702 assemble_start_function (tree decl
, const char *fnname
)
1705 char tmp_label
[100];
1706 bool hot_label_written
= false;
1708 crtl
->subsections
.unlikely_text_section_name
= NULL
;
1710 first_function_block_is_cold
= false;
1711 if (flag_reorder_blocks_and_partition
)
1713 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1714 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1715 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1716 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1717 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1718 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1719 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1720 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1725 crtl
->subsections
.hot_section_label
= NULL
;
1726 crtl
->subsections
.cold_section_label
= NULL
;
1727 crtl
->subsections
.hot_section_end_label
= NULL
;
1728 crtl
->subsections
.cold_section_end_label
= NULL
;
1731 /* The following code does not need preprocessing in the assembler. */
1735 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1736 output_constant_pool (fnname
, decl
);
1738 resolve_unique_section (decl
, 0, flag_function_sections
);
1740 /* Make sure the not and cold text (code) sections are properly
1741 aligned. This is necessary here in the case where the function
1742 has both hot and cold sections, because we don't want to re-set
1743 the alignment when the section switch happens mid-function. */
1745 if (flag_reorder_blocks_and_partition
)
1747 switch_to_section (unlikely_text_section ());
1748 assemble_align (DECL_ALIGN (decl
));
1749 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1751 /* When the function starts with a cold section, we need to explicitly
1752 align the hot section and write out the hot section label.
1753 But if the current function is a thunk, we do not have a CFG. */
1755 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1757 switch_to_section (text_section
);
1758 assemble_align (DECL_ALIGN (decl
));
1759 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1760 hot_label_written
= true;
1761 first_function_block_is_cold
= true;
1764 else if (DECL_SECTION_NAME (decl
))
1766 /* Calls to function_section rely on first_function_block_is_cold
1767 being accurate. The first block may be cold even if we aren't
1768 doing partitioning, if the entire function was decided by
1769 choose_function_section (predict.c) to be cold. */
1771 initialize_cold_section_name ();
1773 if (crtl
->subsections
.unlikely_text_section_name
1774 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
1775 crtl
->subsections
.unlikely_text_section_name
) == 0)
1776 first_function_block_is_cold
= true;
1779 in_cold_section_p
= first_function_block_is_cold
;
1781 /* Switch to the correct text section for the start of the function. */
1783 switch_to_section (function_section (decl
));
1784 if (flag_reorder_blocks_and_partition
1785 && !hot_label_written
)
1786 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1788 /* Tell assembler to move to target machine's alignment for functions. */
1789 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1792 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1795 /* Handle a user-specified function alignment.
1796 Note that we still need to align to DECL_ALIGN, as above,
1797 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1798 if (! DECL_USER_ALIGN (decl
)
1799 && align_functions_log
> align
1800 && optimize_function_for_speed_p (cfun
))
1802 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1803 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1804 align_functions_log
, align_functions
- 1);
1806 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1810 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1811 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1814 if (!DECL_IGNORED_P (decl
))
1815 (*debug_hooks
->begin_function
) (decl
);
1817 /* Make function name accessible from other files, if appropriate. */
1819 if (TREE_PUBLIC (decl
))
1821 notice_global_symbol (decl
);
1823 globalize_decl (decl
);
1825 maybe_assemble_visibility (decl
);
1828 if (DECL_PRESERVE_P (decl
))
1829 targetm
.asm_out
.mark_decl_preserved (fnname
);
1831 /* Do any machine/system dependent processing of the function name. */
1832 #ifdef ASM_DECLARE_FUNCTION_NAME
1833 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1835 /* Standard thing is just output label for the function. */
1836 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1837 #endif /* ASM_DECLARE_FUNCTION_NAME */
1840 /* Output assembler code associated with defining the size of the
1841 function. DECL describes the function. NAME is the function's name. */
1844 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1846 #ifdef ASM_DECLARE_FUNCTION_SIZE
1847 /* We could have switched section in the middle of the function. */
1848 if (flag_reorder_blocks_and_partition
)
1849 switch_to_section (function_section (decl
));
1850 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1852 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1854 output_constant_pool (fnname
, decl
);
1855 switch_to_section (function_section (decl
)); /* need to switch back */
1857 /* Output labels for end of hot/cold text sections (to be used by
1859 if (flag_reorder_blocks_and_partition
)
1861 section
*save_text_section
;
1863 save_text_section
= in_section
;
1864 switch_to_section (unlikely_text_section ());
1865 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1866 if (first_function_block_is_cold
)
1867 switch_to_section (text_section
);
1869 switch_to_section (function_section (decl
));
1870 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1871 switch_to_section (save_text_section
);
1875 /* Assemble code to leave SIZE bytes of zeros. */
1878 assemble_zeros (unsigned HOST_WIDE_INT size
)
1880 /* Do no output if -fsyntax-only. */
1881 if (flag_syntax_only
)
1884 #ifdef ASM_NO_SKIP_IN_TEXT
1885 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1886 so we must output 0s explicitly in the text section. */
1887 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1889 unsigned HOST_WIDE_INT i
;
1890 for (i
= 0; i
< size
; i
++)
1891 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1896 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1899 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1902 assemble_align (int align
)
1904 if (align
> BITS_PER_UNIT
)
1906 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1910 /* Assemble a string constant with the specified C string as contents. */
1913 assemble_string (const char *p
, int size
)
1918 /* If the string is very long, split it up. */
1922 int thissize
= size
- pos
;
1923 if (thissize
> maximum
)
1926 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1934 /* A noswitch_section_callback for lcomm_section. */
1937 emit_local (tree decl ATTRIBUTE_UNUSED
,
1938 const char *name ATTRIBUTE_UNUSED
,
1939 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1940 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1942 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1943 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1944 size
, DECL_ALIGN (decl
));
1946 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1947 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1950 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1955 /* A noswitch_section_callback for bss_noswitch_section. */
1957 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1959 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1960 const char *name ATTRIBUTE_UNUSED
,
1961 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1962 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1964 #if defined ASM_OUTPUT_ALIGNED_BSS
1965 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
, DECL_ALIGN (decl
));
1968 ASM_OUTPUT_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1974 /* A noswitch_section_callback for comm_section. */
1977 emit_common (tree decl ATTRIBUTE_UNUSED
,
1978 const char *name ATTRIBUTE_UNUSED
,
1979 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1980 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1982 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1983 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1984 size
, DECL_ALIGN (decl
));
1986 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1987 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1990 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1995 /* A noswitch_section_callback for tls_comm_section. */
1998 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1999 const char *name ATTRIBUTE_UNUSED
,
2000 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2001 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2003 #ifdef ASM_OUTPUT_TLS_COMMON
2004 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
2007 sorry ("thread-local COMMON data not implemented");
2012 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2013 NAME is the name of DECL's SYMBOL_REF. */
2016 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
)
2018 unsigned HOST_WIDE_INT size
, rounded
;
2020 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
2023 /* Don't allocate zero bytes of common,
2024 since that means "undefined external" in the linker. */
2028 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2029 so that each uninitialized object starts on such a boundary. */
2030 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
2031 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2032 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2034 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
2035 && (unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
2036 warning (0, "requested alignment for %q+D is greater than "
2037 "implemented alignment of %wu", decl
, rounded
);
2040 /* A subroutine of assemble_variable. Output the label and contents of
2041 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2042 is as for assemble_variable. */
2045 assemble_variable_contents (tree decl
, const char *name
,
2046 bool dont_output_data
)
2048 /* Do any machine/system dependent processing of the object. */
2049 #ifdef ASM_DECLARE_OBJECT_NAME
2050 last_assemble_variable_decl
= decl
;
2051 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
2053 /* Standard thing is just output label for the object. */
2054 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2055 #endif /* ASM_DECLARE_OBJECT_NAME */
2057 if (!dont_output_data
)
2059 if (DECL_INITIAL (decl
)
2060 && DECL_INITIAL (decl
) != error_mark_node
2061 && !initializer_zerop (DECL_INITIAL (decl
)))
2062 /* Output the actual data. */
2063 output_constant (DECL_INITIAL (decl
),
2064 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
2067 /* Leave space for it. */
2068 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
2072 /* Initialize emulated tls object TO, which refers to TLS variable
2073 DECL and is initialized by PROXY. */
2076 default_emutls_var_init (tree to
, tree decl
, tree proxy
)
2078 VEC(constructor_elt
,gc
) *v
= VEC_alloc (constructor_elt
, gc
, 4);
2079 constructor_elt
*elt
;
2080 tree type
= TREE_TYPE (to
);
2081 tree field
= TYPE_FIELDS (type
);
2083 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2085 elt
->value
= fold_convert (TREE_TYPE (field
), DECL_SIZE_UNIT (decl
));
2087 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2088 field
= TREE_CHAIN (field
);
2090 elt
->value
= build_int_cst (TREE_TYPE (field
),
2091 DECL_ALIGN_UNIT (decl
));
2093 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2094 field
= TREE_CHAIN (field
);
2096 elt
->value
= null_pointer_node
;
2098 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2099 field
= TREE_CHAIN (field
);
2103 return build_constructor (type
, v
);
2106 /* Assemble everything that is needed for a variable or function declaration.
2107 Not used for automatic variables, and not used for function definitions.
2108 Should not be called for variables of incomplete structure type.
2110 TOP_LEVEL is nonzero if this variable has file scope.
2111 AT_END is nonzero if this is the special handling, at end of compilation,
2112 to define things that have had only tentative definitions.
2113 DONT_OUTPUT_DATA if nonzero means don't actually output the
2114 initial value (that will be done by the caller). */
2117 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
2118 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
2121 rtx decl_rtl
, symbol
;
2124 if (! targetm
.have_tls
2125 && TREE_CODE (decl
) == VAR_DECL
2126 && DECL_THREAD_LOCAL_P (decl
))
2128 tree to
= emutls_decl (decl
);
2130 /* If this variable is defined locally, then we need to initialize the
2131 control structure with size and alignment information. We do this
2132 at the last moment because tentative definitions can take a locally
2133 defined but uninitialized variable and initialize it later, which
2134 would result in incorrect contents. */
2135 if (! DECL_EXTERNAL (to
)
2136 && (! DECL_COMMON (to
)
2137 || (DECL_INITIAL (decl
)
2138 && DECL_INITIAL (decl
) != error_mark_node
)))
2140 DECL_INITIAL (to
) = targetm
.emutls
.var_init
2141 (to
, decl
, get_emutls_init_templ_addr (decl
));
2143 /* Make sure the template is marked as needed early enough.
2144 Without this, if the variable is placed in a
2145 section-anchored block, the template will only be marked
2146 when it's too late. */
2147 record_references_in_initializer (to
, false);
2153 last_assemble_variable_decl
= 0;
2155 /* Normally no need to say anything here for external references,
2156 since assemble_external is called by the language-specific code
2157 when a declaration is first seen. */
2159 if (DECL_EXTERNAL (decl
))
2162 /* Output no assembler code for a function declaration.
2163 Only definitions of functions output anything. */
2165 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2168 /* Do nothing for global register variables. */
2169 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2171 TREE_ASM_WRITTEN (decl
) = 1;
2175 /* If type was incomplete when the variable was declared,
2176 see if it is complete now. */
2178 if (DECL_SIZE (decl
) == 0)
2179 layout_decl (decl
, 0);
2181 /* Still incomplete => don't allocate it; treat the tentative defn
2182 (which is what it must have been) as an `extern' reference. */
2184 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2186 error ("storage size of %q+D isn%'t known", decl
);
2187 TREE_ASM_WRITTEN (decl
) = 1;
2191 /* The first declaration of a variable that comes through this function
2192 decides whether it is global (in C, has external linkage)
2193 or local (in C, has internal linkage). So do nothing more
2194 if this function has already run. */
2196 if (TREE_ASM_WRITTEN (decl
))
2199 /* Make sure targetm.encode_section_info is invoked before we set
2201 decl_rtl
= DECL_RTL (decl
);
2203 TREE_ASM_WRITTEN (decl
) = 1;
2205 /* Do no output if -fsyntax-only. */
2206 if (flag_syntax_only
)
2209 if (! dont_output_data
2210 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
2212 error ("size of variable %q+D is too large", decl
);
2216 gcc_assert (MEM_P (decl_rtl
));
2217 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2218 symbol
= XEXP (decl_rtl
, 0);
2220 /* If this symbol belongs to the tree constant pool, output the constant
2221 if it hasn't already been written. */
2222 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
2224 tree decl
= SYMBOL_REF_DECL (symbol
);
2225 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2226 output_constant_def_contents (symbol
);
2232 name
= XSTR (symbol
, 0);
2233 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2234 notice_global_symbol (decl
);
2236 /* Compute the alignment of this data. */
2238 align_variable (decl
, dont_output_data
);
2239 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2241 if (TREE_PUBLIC (decl
))
2242 maybe_assemble_visibility (decl
);
2244 if (DECL_PRESERVE_P (decl
))
2245 targetm
.asm_out
.mark_decl_preserved (name
);
2247 /* First make the assembler name(s) global if appropriate. */
2248 sect
= get_variable_section (decl
, false);
2249 if (TREE_PUBLIC (decl
)
2250 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2251 globalize_decl (decl
);
2253 /* Output any data that we will need to use the address of. */
2254 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2255 output_addressed_constants (DECL_INITIAL (decl
));
2257 /* dbxout.c needs to know this. */
2258 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2259 DECL_IN_TEXT_SECTION (decl
) = 1;
2261 /* If the decl is part of an object_block, make sure that the decl
2262 has been positioned within its block, but do not write out its
2263 definition yet. output_object_blocks will do that later. */
2264 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2266 gcc_assert (!dont_output_data
);
2267 place_block_symbol (symbol
);
2269 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2270 assemble_noswitch_variable (decl
, name
, sect
);
2273 switch_to_section (sect
);
2274 if (DECL_ALIGN (decl
) > BITS_PER_UNIT
)
2275 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
2276 assemble_variable_contents (decl
, name
, dont_output_data
);
2280 /* Return 1 if type TYPE contains any pointers. */
2283 contains_pointers_p (tree type
)
2285 switch (TREE_CODE (type
))
2288 case REFERENCE_TYPE
:
2289 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2290 so I'll play safe and return 1. */
2296 case QUAL_UNION_TYPE
:
2299 /* For a type that has fields, see if the fields have pointers. */
2300 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2301 if (TREE_CODE (fields
) == FIELD_DECL
2302 && contains_pointers_p (TREE_TYPE (fields
)))
2308 /* An array type contains pointers if its element type does. */
2309 return contains_pointers_p (TREE_TYPE (type
));
2316 /* We delay assemble_external processing until
2317 the compilation unit is finalized. This is the best we can do for
2318 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2319 it all the way to final. See PR 17982 for further discussion. */
2320 static GTY(()) tree pending_assemble_externals
;
2322 #ifdef ASM_OUTPUT_EXTERNAL
2323 /* True if DECL is a function decl for which no out-of-line copy exists.
2324 It is assumed that DECL's assembler name has been set. */
2327 incorporeal_function_p (tree decl
)
2329 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2333 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2334 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
2337 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2338 if (is_builtin_name (name
))
2344 /* Actually do the tests to determine if this is necessary, and invoke
2345 ASM_OUTPUT_EXTERNAL. */
2347 assemble_external_real (tree decl
)
2349 rtx rtl
= DECL_RTL (decl
);
2351 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2352 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2353 && !incorporeal_function_p (decl
))
2355 /* Some systems do require some output. */
2356 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2357 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2363 process_pending_assemble_externals (void)
2365 #ifdef ASM_OUTPUT_EXTERNAL
2367 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2368 assemble_external_real (TREE_VALUE (list
));
2370 pending_assemble_externals
= 0;
2374 /* This TREE_LIST contains any weak symbol declarations waiting
2376 static GTY(()) tree weak_decls
;
2378 /* Output something to declare an external symbol to the assembler,
2379 and qualifiers such as weakness. (Most assemblers don't need
2380 extern declaration, so we normally output nothing.) Do nothing if
2381 DECL is not external. */
2384 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2386 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2387 main body of this code is only rarely exercised. To provide some
2388 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2389 open. If it's not, we should not be calling this function. */
2390 gcc_assert (asm_out_file
);
2392 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2395 /* We want to output annotation for weak and external symbols at
2396 very last to check if they are references or not. */
2400 /* TREE_STATIC is a weird and abused creature which is not
2401 generally the right test for whether an entity has been
2402 locally emitted, inlined or otherwise not-really-extern, but
2403 for declarations that can be weak, it happens to be
2405 && !TREE_STATIC (decl
)
2406 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2407 && value_member (decl
, weak_decls
) == NULL_TREE
)
2408 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2410 #ifdef ASM_OUTPUT_EXTERNAL
2411 if (value_member (decl
, pending_assemble_externals
) == NULL_TREE
)
2412 pending_assemble_externals
= tree_cons (NULL
, decl
,
2413 pending_assemble_externals
);
2417 /* Similar, for calling a library function FUN. */
2420 assemble_external_libcall (rtx fun
)
2422 /* Declare library function name external when first used, if nec. */
2423 if (! SYMBOL_REF_USED (fun
))
2425 SYMBOL_REF_USED (fun
) = 1;
2426 targetm
.asm_out
.external_libcall (fun
);
2430 /* Assemble a label named NAME. */
2433 assemble_label (const char *name
)
2435 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2438 /* Set the symbol_referenced flag for ID. */
2440 mark_referenced (tree id
)
2442 TREE_SYMBOL_REFERENCED (id
) = 1;
2445 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2447 mark_decl_referenced (tree decl
)
2449 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2451 /* Extern inline functions don't become needed when referenced.
2452 If we know a method will be emitted in other TU and no new
2453 functions can be marked reachable, just use the external
2455 struct cgraph_node
*node
= cgraph_node (decl
);
2456 if (!DECL_EXTERNAL (decl
)
2457 && (!node
->local
.vtable_method
|| !cgraph_global_info_ready
2458 || !node
->local
.finalized
))
2459 cgraph_mark_needed_node (node
);
2461 else if (TREE_CODE (decl
) == VAR_DECL
)
2463 struct varpool_node
*node
= varpool_node (decl
);
2464 varpool_mark_needed_node (node
);
2465 /* C++ frontend use mark_decl_references to force COMDAT variables
2466 to be output that might appear dead otherwise. */
2467 node
->force_output
= true;
2469 /* else do nothing - we can get various sorts of CST nodes here,
2470 which do not need to be marked. */
2474 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2475 until we find an identifier that is not itself a transparent alias.
2476 Modify the alias passed to it by reference (and all aliases on the
2477 way to the ultimate target), such that they do not have to be
2478 followed again, and return the ultimate target of the alias
2482 ultimate_transparent_alias_target (tree
*alias
)
2484 tree target
= *alias
;
2486 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2488 gcc_assert (TREE_CHAIN (target
));
2489 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2490 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2491 && ! TREE_CHAIN (target
));
2498 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2499 starts with a *, the rest of NAME is output verbatim. Otherwise
2500 NAME is transformed in a target-specific way (usually by the
2501 addition of an underscore). */
2504 assemble_name_raw (FILE *file
, const char *name
)
2507 fputs (&name
[1], file
);
2509 ASM_OUTPUT_LABELREF (file
, name
);
2512 /* Like assemble_name_raw, but should be used when NAME might refer to
2513 an entity that is also represented as a tree (like a function or
2514 variable). If NAME does refer to such an entity, that entity will
2515 be marked as referenced. */
2518 assemble_name (FILE *file
, const char *name
)
2520 const char *real_name
;
2523 real_name
= targetm
.strip_name_encoding (name
);
2525 id
= maybe_get_identifier (real_name
);
2530 mark_referenced (id
);
2531 ultimate_transparent_alias_target (&id
);
2533 name
= IDENTIFIER_POINTER (id
);
2534 gcc_assert (! TREE_CHAIN (id
));
2537 assemble_name_raw (file
, name
);
2540 /* Allocate SIZE bytes writable static space with a gensym name
2541 and return an RTX to refer to its address. */
2544 assemble_static_space (unsigned HOST_WIDE_INT size
)
2547 const char *namestring
;
2550 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2552 namestring
= ggc_strdup (name
);
2554 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2555 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2557 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2558 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2561 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2562 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2565 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2566 so that each uninitialized object starts on such a boundary. */
2567 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2568 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2569 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2570 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2571 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2572 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2579 /* Assemble the static constant template for function entry trampolines.
2580 This is done at most once per compilation.
2581 Returns an RTX for the address of the template. */
2583 static GTY(()) rtx initial_trampoline
;
2586 assemble_trampoline_template (void)
2593 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2595 if (initial_trampoline
)
2596 return initial_trampoline
;
2598 /* By default, put trampoline templates in read-only data section. */
2600 #ifdef TRAMPOLINE_SECTION
2601 switch_to_section (TRAMPOLINE_SECTION
);
2603 switch_to_section (readonly_data_section
);
2606 /* Write the assembler code to define one. */
2607 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2609 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2611 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2612 targetm
.asm_out
.trampoline_template (asm_out_file
);
2614 /* Record the rtl to refer to it. */
2615 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2616 name
= ggc_strdup (label
);
2617 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2618 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2620 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2621 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2622 set_mem_size (initial_trampoline
, GEN_INT (TRAMPOLINE_SIZE
));
2624 return initial_trampoline
;
2627 /* A and B are either alignments or offsets. Return the minimum alignment
2628 that may be assumed after adding the two together. */
2630 static inline unsigned
2631 min_align (unsigned int a
, unsigned int b
)
2633 return (a
| b
) & -(a
| b
);
2636 /* Return the assembler directive for creating a given kind of integer
2637 object. SIZE is the number of bytes in the object and ALIGNED_P
2638 indicates whether it is known to be aligned. Return NULL if the
2639 assembly dialect has no such directive.
2641 The returned string should be printed at the start of a new line and
2642 be followed immediately by the object's initial value. */
2645 integer_asm_op (int size
, int aligned_p
)
2647 struct asm_int_op
*ops
;
2650 ops
= &targetm
.asm_out
.aligned_op
;
2652 ops
= &targetm
.asm_out
.unaligned_op
;
2657 return targetm
.asm_out
.byte_op
;
2671 /* Use directive OP to assemble an integer object X. Print OP at the
2672 start of the line, followed immediately by the value of X. */
2675 assemble_integer_with_op (const char *op
, rtx x
)
2677 fputs (op
, asm_out_file
);
2678 output_addr_const (asm_out_file
, x
);
2679 fputc ('\n', asm_out_file
);
2682 /* The default implementation of the asm_out.integer target hook. */
2685 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2686 unsigned int size ATTRIBUTE_UNUSED
,
2687 int aligned_p ATTRIBUTE_UNUSED
)
2689 const char *op
= integer_asm_op (size
, aligned_p
);
2690 /* Avoid GAS bugs for large values. Specifically negative values whose
2691 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2692 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2694 return op
&& (assemble_integer_with_op (op
, x
), true);
2697 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2698 the alignment of the integer in bits. Return 1 if we were able to output
2699 the constant, otherwise 0. We must be able to output the constant,
2700 if FORCE is nonzero. */
2703 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2707 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2709 /* See if the target hook can handle this kind of object. */
2710 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2713 /* If the object is a multi-byte one, try splitting it up. Split
2714 it into words it if is multi-word, otherwise split it into bytes. */
2717 enum machine_mode omode
, imode
;
2718 unsigned int subalign
;
2719 unsigned int subsize
, i
;
2720 enum mode_class mclass
;
2722 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2723 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2724 if (GET_CODE (x
) == CONST_FIXED
)
2725 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2729 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2730 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2732 for (i
= 0; i
< size
; i
+= subsize
)
2734 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2735 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2741 /* If we've printed some of it, but not all of it, there's no going
2746 gcc_assert (!force
);
2752 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2754 long data
[4] = {0, 0, 0, 0};
2756 int bitsize
, nelts
, nunits
, units_per
;
2758 /* This is hairy. We have a quantity of known size. real_to_target
2759 will put it into an array of *host* longs, 32 bits per element
2760 (even if long is more than 32 bits). We need to determine the
2761 number of array elements that are occupied (nelts) and the number
2762 of *target* min-addressable units that will be occupied in the
2763 object file (nunits). We cannot assume that 32 divides the
2764 mode's bitsize (size * BITS_PER_UNIT) evenly.
2766 size * BITS_PER_UNIT is used here to make sure that padding bits
2767 (which might appear at either end of the value; real_to_target
2768 will include the padding bits in its output array) are included. */
2770 nunits
= GET_MODE_SIZE (mode
);
2771 bitsize
= nunits
* BITS_PER_UNIT
;
2772 nelts
= CEIL (bitsize
, 32);
2773 units_per
= 32 / BITS_PER_UNIT
;
2775 real_to_target (data
, &d
, mode
);
2777 /* Put out the first word with the specified alignment. */
2778 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2779 nunits
-= units_per
;
2781 /* Subsequent words need only 32-bit alignment. */
2782 align
= min_align (align
, 32);
2784 for (i
= 1; i
< nelts
; i
++)
2786 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2787 nunits
-= units_per
;
2791 /* Given an expression EXP with a constant value,
2792 reduce it to the sum of an assembler symbol and an integer.
2793 Store them both in the structure *VALUE.
2794 EXP must be reducible. */
2796 struct GTY(()) addr_const
{
2798 HOST_WIDE_INT offset
;
2802 decode_addr_const (tree exp
, struct addr_const
*value
)
2804 tree target
= TREE_OPERAND (exp
, 0);
2810 if (TREE_CODE (target
) == COMPONENT_REF
2811 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2813 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2814 target
= TREE_OPERAND (target
, 0);
2816 else if (TREE_CODE (target
) == ARRAY_REF
2817 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2819 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2820 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2821 target
= TREE_OPERAND (target
, 0);
2823 else if (TREE_CODE (target
) == INDIRECT_REF
2824 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2825 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2827 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2832 switch (TREE_CODE (target
))
2836 x
= DECL_RTL (target
);
2840 x
= gen_rtx_MEM (FUNCTION_MODE
,
2841 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2850 x
= output_constant_def (target
, 1);
2857 gcc_assert (MEM_P (x
));
2861 value
->offset
= offset
;
2865 static GTY((param_is (struct constant_descriptor_tree
)))
2866 htab_t const_desc_htab
;
2868 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2870 /* Constant pool accessor function. */
2873 constant_pool_htab (void)
2875 return const_desc_htab
;
2878 /* Compute a hash code for a constant expression. */
2881 const_desc_hash (const void *ptr
)
2883 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2887 const_hash_1 (const tree exp
)
2892 enum tree_code code
= TREE_CODE (exp
);
2894 /* Either set P and LEN to the address and len of something to hash and
2895 exit the switch or return a value. */
2900 p
= (char *) &TREE_INT_CST (exp
);
2901 len
= sizeof TREE_INT_CST (exp
);
2905 return real_hash (TREE_REAL_CST_PTR (exp
));
2908 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2911 p
= TREE_STRING_POINTER (exp
);
2912 len
= TREE_STRING_LENGTH (exp
);
2916 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2917 + const_hash_1 (TREE_IMAGPART (exp
)));
2923 hi
= 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
));
2925 for (link
= TREE_VECTOR_CST_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2926 hi
= hi
* 563 + const_hash_1 (TREE_VALUE (link
));
2933 unsigned HOST_WIDE_INT idx
;
2936 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2938 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2940 hi
= hi
* 603 + const_hash_1 (value
);
2948 struct addr_const value
;
2950 decode_addr_const (exp
, &value
);
2951 switch (GET_CODE (value
.base
))
2954 /* Don't hash the address of the SYMBOL_REF;
2955 only use the offset and the symbol name. */
2957 p
= XSTR (value
.base
, 0);
2958 for (i
= 0; p
[i
] != 0; i
++)
2959 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2963 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2973 case POINTER_PLUS_EXPR
:
2975 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2976 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2979 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2982 /* A language specific constant. Just hash the code. */
2986 /* Compute hashing function. */
2988 for (i
= 0; i
< len
; i
++)
2989 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2994 /* Wrapper of compare_constant, for the htab interface. */
2996 const_desc_eq (const void *p1
, const void *p2
)
2998 const struct constant_descriptor_tree
*const c1
2999 = (const struct constant_descriptor_tree
*) p1
;
3000 const struct constant_descriptor_tree
*const c2
3001 = (const struct constant_descriptor_tree
*) p2
;
3002 if (c1
->hash
!= c2
->hash
)
3004 return compare_constant (c1
->value
, c2
->value
);
3007 /* Compare t1 and t2, and return 1 only if they are known to result in
3008 the same bit pattern on output. */
3011 compare_constant (const tree t1
, const tree t2
)
3013 enum tree_code typecode
;
3015 if (t1
== NULL_TREE
)
3016 return t2
== NULL_TREE
;
3017 if (t2
== NULL_TREE
)
3020 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3023 switch (TREE_CODE (t1
))
3026 /* Integer constants are the same only if the same width of type. */
3027 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3029 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3031 return tree_int_cst_equal (t1
, t2
);
3034 /* Real constants are the same only if the same width of type. */
3035 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3038 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
3041 /* Fixed constants are the same only if the same width of type. */
3042 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3045 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
3048 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3051 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3052 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3053 TREE_STRING_LENGTH (t1
)));
3056 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
3057 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
3063 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1
))
3064 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2
)))
3067 link2
= TREE_VECTOR_CST_ELTS (t2
);
3068 for (link1
= TREE_VECTOR_CST_ELTS (t1
);
3070 link1
= TREE_CHAIN (link1
))
3072 if (!compare_constant (TREE_VALUE (link1
), TREE_VALUE (link2
)))
3074 link2
= TREE_CHAIN (link2
);
3082 VEC(constructor_elt
, gc
) *v1
, *v2
;
3083 unsigned HOST_WIDE_INT idx
;
3085 typecode
= TREE_CODE (TREE_TYPE (t1
));
3086 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3089 if (typecode
== ARRAY_TYPE
)
3091 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3092 /* For arrays, check that the sizes all match. */
3093 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3095 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
3100 /* For record and union constructors, require exact type
3102 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3106 v1
= CONSTRUCTOR_ELTS (t1
);
3107 v2
= CONSTRUCTOR_ELTS (t2
);
3108 if (VEC_length (constructor_elt
, v1
)
3109 != VEC_length (constructor_elt
, v2
))
3112 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
3114 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
3115 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
3117 /* Check that each value is the same... */
3118 if (!compare_constant (c1
->value
, c2
->value
))
3120 /* ... and that they apply to the same fields! */
3121 if (typecode
== ARRAY_TYPE
)
3123 if (!compare_constant (c1
->index
, c2
->index
))
3128 if (c1
->index
!= c2
->index
)
3139 struct addr_const value1
, value2
;
3143 decode_addr_const (t1
, &value1
);
3144 decode_addr_const (t2
, &value2
);
3146 if (value1
.offset
!= value2
.offset
)
3149 code
= GET_CODE (value1
.base
);
3150 if (code
!= GET_CODE (value2
.base
))
3156 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3160 ret
= (CODE_LABEL_NUMBER (XEXP (value1
.base
, 0))
3161 == CODE_LABEL_NUMBER (XEXP (value2
.base
, 0)));
3171 case POINTER_PLUS_EXPR
:
3174 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3175 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3178 case VIEW_CONVERT_EXPR
:
3179 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3188 /* Make a copy of the whole tree structure for a constant. This
3189 handles the same types of nodes that compare_constant handles. */
3192 copy_constant (tree exp
)
3194 switch (TREE_CODE (exp
))
3197 /* For ADDR_EXPR, we do not want to copy the decl whose address
3198 is requested. We do want to copy constants though. */
3199 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
3200 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3201 copy_constant (TREE_OPERAND (exp
, 0)));
3203 return copy_node (exp
);
3209 return copy_node (exp
);
3212 return build_complex (TREE_TYPE (exp
),
3213 copy_constant (TREE_REALPART (exp
)),
3214 copy_constant (TREE_IMAGPART (exp
)));
3217 case POINTER_PLUS_EXPR
:
3219 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
3220 copy_constant (TREE_OPERAND (exp
, 0)),
3221 copy_constant (TREE_OPERAND (exp
, 1)));
3224 case VIEW_CONVERT_EXPR
:
3225 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3226 copy_constant (TREE_OPERAND (exp
, 0)));
3229 return build_vector (TREE_TYPE (exp
),
3230 copy_list (TREE_VECTOR_CST_ELTS (exp
)));
3234 tree copy
= copy_node (exp
);
3235 VEC(constructor_elt
, gc
) *v
;
3236 unsigned HOST_WIDE_INT idx
;
3237 tree purpose
, value
;
3239 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
3240 CONSTRUCTOR_ELTS (exp
)));
3241 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
3243 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
3244 ce
->index
= purpose
;
3245 ce
->value
= copy_constant (value
);
3247 CONSTRUCTOR_ELTS (copy
) = v
;
3256 /* Return the section into which constant EXP should be placed. */
3259 get_constant_section (tree exp
, unsigned int align
)
3261 return targetm
.asm_out
.select_section (exp
,
3262 compute_reloc_for_constant (exp
),
3266 /* Return the size of constant EXP in bytes. */
3268 static HOST_WIDE_INT
3269 get_constant_size (tree exp
)
3273 size
= int_size_in_bytes (TREE_TYPE (exp
));
3274 if (TREE_CODE (exp
) == STRING_CST
)
3275 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3279 /* Subroutine of output_constant_def:
3280 No constant equal to EXP is known to have been output.
3281 Make a constant descriptor to enter EXP in the hash table.
3282 Assign the label number and construct RTL to refer to the
3283 constant's location in memory.
3284 Caller is responsible for updating the hash table. */
3286 static struct constant_descriptor_tree
*
3287 build_constant_desc (tree exp
)
3289 struct constant_descriptor_tree
*desc
;
3295 desc
= GGC_NEW (struct constant_descriptor_tree
);
3296 desc
->value
= copy_constant (exp
);
3298 /* Propagate marked-ness to copied constant. */
3299 if (flag_mudflap
&& mf_marked_p (exp
))
3300 mf_mark (desc
->value
);
3302 /* Create a string containing the label name, in LABEL. */
3303 labelno
= const_labelno
++;
3304 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3306 /* Construct the VAR_DECL associated with the constant. */
3307 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3309 DECL_ARTIFICIAL (decl
) = 1;
3310 DECL_IGNORED_P (decl
) = 1;
3311 TREE_READONLY (decl
) = 1;
3312 TREE_STATIC (decl
) = 1;
3313 TREE_ADDRESSABLE (decl
) = 1;
3314 /* We don't set the RTL yet as this would cause varpool to assume that the
3315 variable is referenced. Moreover, it would just be dropped in LTO mode.
3316 Instead we set the flag that will be recognized in make_decl_rtl. */
3317 DECL_IN_CONSTANT_POOL (decl
) = 1;
3318 DECL_INITIAL (decl
) = desc
->value
;
3319 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3320 architectures so use DATA_ALIGNMENT as well, except for strings. */
3321 if (TREE_CODE (exp
) == STRING_CST
)
3323 #ifdef CONSTANT_ALIGNMENT
3324 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
3328 align_variable (decl
, 0);
3330 /* Now construct the SYMBOL_REF and the MEM. */
3331 if (use_object_blocks_p ())
3333 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
3334 symbol
= create_block_symbol (ggc_strdup (label
),
3335 get_block_for_section (sect
), -1);
3338 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3339 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3340 SET_SYMBOL_REF_DECL (symbol
, decl
);
3341 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3343 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3344 set_mem_attributes (rtl
, exp
, 1);
3345 set_mem_alias_set (rtl
, 0);
3346 set_mem_alias_set (rtl
, const_alias_set
);
3348 /* We cannot share RTX'es in pool entries.
3349 Mark this piece of RTL as required for unsharing. */
3350 RTX_FLAG (rtl
, used
) = 1;
3352 /* Set flags or add text to the name to record information, such as
3353 that it is a local symbol. If the name is changed, the macro
3354 ASM_OUTPUT_LABELREF will have to know how to strip this
3355 information. This call might invalidate our local variable
3356 SYMBOL; we can't use it afterward. */
3357 targetm
.encode_section_info (exp
, rtl
, true);
3364 /* Return an rtx representing a reference to constant data in memory
3365 for the constant expression EXP.
3367 If assembler code for such a constant has already been output,
3368 return an rtx to refer to it.
3369 Otherwise, output such a constant in memory
3370 and generate an rtx for it.
3372 If DEFER is nonzero, this constant can be deferred and output only
3373 if referenced in the function after all optimizations.
3375 `const_desc_table' records which constants already have label strings. */
3378 output_constant_def (tree exp
, int defer
)
3380 struct constant_descriptor_tree
*desc
;
3381 struct constant_descriptor_tree key
;
3384 /* Look up EXP in the table of constant descriptors. If we didn't find
3385 it, create a new one. */
3387 key
.hash
= const_hash_1 (exp
);
3388 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3390 desc
= (struct constant_descriptor_tree
*) *loc
;
3393 desc
= build_constant_desc (exp
);
3394 desc
->hash
= key
.hash
;
3398 maybe_output_constant_def_contents (desc
, defer
);
3402 /* Subroutine of output_constant_def: Decide whether or not we need to
3403 output the constant DESC now, and if so, do it. */
3405 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3408 rtx symbol
= XEXP (desc
->rtl
, 0);
3409 tree exp
= desc
->value
;
3411 if (flag_syntax_only
)
3414 if (TREE_ASM_WRITTEN (exp
))
3415 /* Already output; don't do it again. */
3418 /* We can always defer constants as long as the context allows
3422 /* Increment n_deferred_constants if it exists. It needs to be at
3423 least as large as the number of constants actually referred to
3424 by the function. If it's too small we'll stop looking too early
3425 and fail to emit constants; if it's too large we'll only look
3426 through the entire function when we could have stopped earlier. */
3428 n_deferred_constants
++;
3432 output_constant_def_contents (symbol
);
3435 /* Subroutine of output_constant_def_contents. Output the definition
3436 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3437 constant's alignment in bits. */
3440 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3444 size
= get_constant_size (exp
);
3446 /* Do any machine/system dependent processing of the constant. */
3447 #ifdef ASM_DECLARE_CONSTANT_NAME
3448 ASM_DECLARE_CONSTANT_NAME (asm_out_file
, label
, exp
, size
);
3450 /* Standard thing is just output label for the constant. */
3451 ASM_OUTPUT_LABEL (asm_out_file
, label
);
3452 #endif /* ASM_DECLARE_CONSTANT_NAME */
3454 /* Output the value of EXP. */
3455 output_constant (exp
, size
, align
);
3458 /* We must output the constant data referred to by SYMBOL; do so. */
3461 output_constant_def_contents (rtx symbol
)
3463 tree decl
= SYMBOL_REF_DECL (symbol
);
3464 tree exp
= DECL_INITIAL (decl
);
3467 /* Make sure any other constants whose addresses appear in EXP
3468 are assigned label numbers. */
3469 output_addressed_constants (exp
);
3471 /* We are no longer deferring this constant. */
3472 TREE_ASM_WRITTEN (exp
) = 1;
3474 /* If the constant is part of an object block, make sure that the
3475 decl has been positioned within its block, but do not write out
3476 its definition yet. output_object_blocks will do that later. */
3477 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3478 place_block_symbol (symbol
);
3481 align
= DECL_ALIGN (decl
);
3482 switch_to_section (get_constant_section (exp
, align
));
3483 if (align
> BITS_PER_UNIT
)
3484 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3485 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3488 mudflap_enqueue_constant (exp
);
3491 /* Look up EXP in the table of constant descriptors. Return the rtl
3492 if it has been emitted, else null. */
3495 lookup_constant_def (tree exp
)
3497 struct constant_descriptor_tree
*desc
;
3498 struct constant_descriptor_tree key
;
3501 key
.hash
= const_hash_1 (exp
);
3502 desc
= (struct constant_descriptor_tree
*)
3503 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3505 return (desc
? desc
->rtl
: NULL_RTX
);
3508 /* Return a tree representing a reference to constant data in memory
3509 for the constant expression EXP.
3511 This is the counterpart of output_constant_def at the Tree level. */
3514 tree_output_constant_def (tree exp
)
3516 struct constant_descriptor_tree
*desc
, key
;
3520 /* Look up EXP in the table of constant descriptors. If we didn't find
3521 it, create a new one. */
3523 key
.hash
= const_hash_1 (exp
);
3524 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3526 desc
= (struct constant_descriptor_tree
*) *loc
;
3529 desc
= build_constant_desc (exp
);
3530 desc
->hash
= key
.hash
;
3534 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3535 varpool_finalize_decl (decl
);
3539 /* Used in the hash tables to avoid outputting the same constant
3540 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3541 are output once per function, not once per file. */
3542 /* ??? Only a few targets need per-function constant pools. Most
3543 can use one per-file pool. Should add a targetm bit to tell the
3546 struct GTY(()) rtx_constant_pool
{
3547 /* Pointers to first and last constant in pool, as ordered by offset. */
3548 struct constant_descriptor_rtx
*first
;
3549 struct constant_descriptor_rtx
*last
;
3551 /* Hash facility for making memory-constants from constant rtl-expressions.
3552 It is used on RISC machines where immediate integer arguments and
3553 constant addresses are restricted so that such constants must be stored
3555 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3557 /* Current offset in constant pool (does not include any
3558 machine-specific header). */
3559 HOST_WIDE_INT offset
;
3562 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3563 struct constant_descriptor_rtx
*next
;
3567 HOST_WIDE_INT offset
;
3569 enum machine_mode mode
;
3575 /* Hash and compare functions for const_rtx_htab. */
3578 const_desc_rtx_hash (const void *ptr
)
3580 const struct constant_descriptor_rtx
*const desc
3581 = (const struct constant_descriptor_rtx
*) ptr
;
3586 const_desc_rtx_eq (const void *a
, const void *b
)
3588 const struct constant_descriptor_rtx
*const x
3589 = (const struct constant_descriptor_rtx
*) a
;
3590 const struct constant_descriptor_rtx
*const y
3591 = (const struct constant_descriptor_rtx
*) b
;
3593 if (x
->mode
!= y
->mode
)
3595 return rtx_equal_p (x
->constant
, y
->constant
);
3598 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3601 const_rtx_hash_1 (rtx
*xp
, void *data
)
3603 unsigned HOST_WIDE_INT hwi
;
3604 enum machine_mode mode
;
3610 code
= GET_CODE (x
);
3611 mode
= GET_MODE (x
);
3612 h
= (hashval_t
) code
* 1048573 + mode
;
3620 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3621 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3624 h
^= (hashval_t
) hwi
;
3625 for (i
= 1; i
< n
; ++i
)
3628 h
^= (hashval_t
) hwi
;
3634 if (mode
== VOIDmode
)
3636 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3640 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3644 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3650 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3651 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3656 h
^= htab_hash_string (XSTR (x
, 0));
3660 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3664 case UNSPEC_VOLATILE
:
3665 h
= h
* 251 + XINT (x
, 1);
3672 hp
= (hashval_t
*) data
;
3673 *hp
= *hp
* 509 + h
;
3677 /* Compute a hash value for X, which should be a constant. */
3680 const_rtx_hash (rtx x
)
3683 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3688 /* Create and return a new rtx constant pool. */
3690 static struct rtx_constant_pool
*
3691 create_constant_pool (void)
3693 struct rtx_constant_pool
*pool
;
3695 pool
= GGC_NEW (struct rtx_constant_pool
);
3696 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3697 const_desc_rtx_eq
, NULL
);
3704 /* Initialize constant pool hashing for a new function. */
3707 init_varasm_status (void)
3709 crtl
->varasm
.pool
= create_constant_pool ();
3710 crtl
->varasm
.deferred_constants
= 0;
3713 /* Given a MINUS expression, simplify it if both sides
3714 include the same symbol. */
3717 simplify_subtraction (rtx x
)
3719 rtx r
= simplify_rtx (x
);
3723 /* Given a constant rtx X, make (or find) a memory constant for its value
3724 and return a MEM rtx to refer to it in memory. */
3727 force_const_mem (enum machine_mode mode
, rtx x
)
3729 struct constant_descriptor_rtx
*desc
, tmp
;
3730 struct rtx_constant_pool
*pool
;
3737 /* If we're not allowed to drop X into the constant pool, don't. */
3738 if (targetm
.cannot_force_const_mem (x
))
3741 /* Record that this function has used a constant pool entry. */
3742 crtl
->uses_const_pool
= 1;
3744 /* Decide which pool to use. */
3745 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3746 ? shared_constant_pool
3747 : crtl
->varasm
.pool
);
3749 /* Lookup the value in the hashtable. */
3752 hash
= const_rtx_hash (x
);
3753 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3754 desc
= (struct constant_descriptor_rtx
*) *slot
;
3756 /* If the constant was already present, return its memory. */
3758 return copy_rtx (desc
->mem
);
3760 /* Otherwise, create a new descriptor. */
3761 desc
= GGC_NEW (struct constant_descriptor_rtx
);
3764 /* Align the location counter as required by EXP's data type. */
3765 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3766 #ifdef CONSTANT_ALIGNMENT
3768 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3769 if (type
!= NULL_TREE
)
3770 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3774 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3775 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3778 desc
->constant
= tmp
.constant
;
3779 desc
->offset
= pool
->offset
;
3782 desc
->align
= align
;
3783 desc
->labelno
= const_labelno
;
3786 pool
->offset
+= GET_MODE_SIZE (mode
);
3788 pool
->last
->next
= desc
;
3790 pool
->first
= pool
->last
= desc
;
3793 /* Create a string containing the label name, in LABEL. */
3794 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3797 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3798 the constants pool. */
3799 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3801 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3802 symbol
= create_block_symbol (ggc_strdup (label
),
3803 get_block_for_section (sect
), -1);
3806 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3808 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3809 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3810 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3812 /* Construct the MEM. */
3813 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3814 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3815 set_mem_align (def
, align
);
3817 /* If we're dropping a label to the constant pool, make sure we
3819 if (GET_CODE (x
) == LABEL_REF
)
3820 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3822 return copy_rtx (def
);
3825 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3828 get_pool_constant (rtx addr
)
3830 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3833 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3834 and whether it has been output or not. */
3837 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3839 struct constant_descriptor_rtx
*desc
;
3841 desc
= SYMBOL_REF_CONSTANT (addr
);
3842 *pmarked
= (desc
->mark
!= 0);
3843 return desc
->constant
;
3846 /* Similar, return the mode. */
3849 get_pool_mode (const_rtx addr
)
3851 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3854 /* Return the size of the constant pool. */
3857 get_pool_size (void)
3859 return crtl
->varasm
.pool
->offset
;
3862 /* Worker function for output_constant_pool_1. Emit assembly for X
3863 in MODE with known alignment ALIGN. */
3866 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3868 switch (GET_MODE_CLASS (mode
))
3871 case MODE_DECIMAL_FLOAT
:
3875 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3876 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3877 assemble_real (r
, mode
, align
);
3882 case MODE_PARTIAL_INT
:
3887 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3890 case MODE_VECTOR_FLOAT
:
3891 case MODE_VECTOR_INT
:
3892 case MODE_VECTOR_FRACT
:
3893 case MODE_VECTOR_UFRACT
:
3894 case MODE_VECTOR_ACCUM
:
3895 case MODE_VECTOR_UACCUM
:
3898 enum machine_mode submode
= GET_MODE_INNER (mode
);
3899 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3901 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3902 units
= CONST_VECTOR_NUNITS (x
);
3904 for (i
= 0; i
< units
; i
++)
3906 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3907 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3917 /* Worker function for output_constant_pool. Emit constant DESC,
3918 giving it ALIGN bits of alignment. */
3921 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3928 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3929 whose CODE_LABEL has been deleted. This can occur if a jump table
3930 is eliminated by optimization. If so, write a constant of zero
3931 instead. Note that this can also happen by turning the
3932 CODE_LABEL into a NOTE. */
3933 /* ??? This seems completely and utterly wrong. Certainly it's
3934 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3935 functioning even with INSN_DELETED_P and friends. */
3938 switch (GET_CODE (tmp
))
3941 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3942 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3944 tmp
= XEXP (XEXP (tmp
, 0), 0);
3948 tmp
= XEXP (tmp
, 0);
3949 gcc_assert (!INSN_DELETED_P (tmp
));
3950 gcc_assert (!NOTE_P (tmp
)
3951 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3958 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3959 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3960 align
, desc
->labelno
, done
);
3963 assemble_align (align
);
3965 /* Output the label. */
3966 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3968 /* Output the data. */
3969 output_constant_pool_2 (desc
->mode
, x
, align
);
3971 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3972 sections have proper size. */
3973 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3975 && (in_section
->common
.flags
& SECTION_MERGE
))
3976 assemble_align (align
);
3978 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3984 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3985 to as used. Emit referenced deferred strings. This function can
3986 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3989 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
3991 rtx x
= *current_rtx
;
3993 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3996 if (CONSTANT_POOL_ADDRESS_P (x
))
3998 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3999 if (desc
->mark
== 0)
4002 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
4005 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
4007 tree decl
= SYMBOL_REF_DECL (x
);
4008 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
4010 n_deferred_constants
--;
4011 output_constant_def_contents (x
);
4018 /* Look through appropriate parts of INSN, marking all entries in the
4019 constant pool which are actually being used. Entries that are only
4020 referenced by other constants are also marked as used. Emit
4021 deferred strings that are used. */
4024 mark_constants (rtx insn
)
4029 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4030 insns, not any notes that may be attached. We don't want to mark
4031 a constant just because it happens to appear in a REG_EQUIV note. */
4032 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
4034 rtx seq
= PATTERN (insn
);
4035 int i
, n
= XVECLEN (seq
, 0);
4036 for (i
= 0; i
< n
; ++i
)
4038 rtx subinsn
= XVECEXP (seq
, 0, i
);
4039 if (INSN_P (subinsn
))
4040 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
4044 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
4047 /* Look through the instructions for this function, and mark all the
4048 entries in POOL which are actually being used. Emit deferred constants
4049 which have indeed been used. */
4052 mark_constant_pool (void)
4056 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
4059 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4060 mark_constants (insn
);
4062 for (link
= crtl
->epilogue_delay_list
;
4064 link
= XEXP (link
, 1))
4065 mark_constants (XEXP (link
, 0));
4068 /* Write all the constants in POOL. */
4071 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
4073 struct constant_descriptor_rtx
*desc
;
4075 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
4078 /* If the constant is part of an object_block, make sure that
4079 the constant has been positioned within its block, but do not
4080 write out its definition yet. output_object_blocks will do
4082 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
4083 && SYMBOL_REF_BLOCK (desc
->sym
))
4084 place_block_symbol (desc
->sym
);
4087 switch_to_section (targetm
.asm_out
.select_rtx_section
4088 (desc
->mode
, desc
->constant
, desc
->align
));
4089 output_constant_pool_1 (desc
, desc
->align
);
4094 /* Mark all constants that are used in the current function, then write
4095 out the function's private constant pool. */
4098 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
4099 tree fndecl ATTRIBUTE_UNUSED
)
4101 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
4103 /* It is possible for gcc to call force_const_mem and then to later
4104 discard the instructions which refer to the constant. In such a
4105 case we do not need to output the constant. */
4106 mark_constant_pool ();
4108 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4109 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4112 output_constant_pool_contents (pool
);
4114 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4115 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4119 /* Write the contents of the shared constant pool. */
4122 output_shared_constant_pool (void)
4124 output_constant_pool_contents (shared_constant_pool
);
4127 /* Determine what kind of relocations EXP may need. */
4130 compute_reloc_for_constant (tree exp
)
4132 int reloc
= 0, reloc2
;
4135 switch (TREE_CODE (exp
))
4139 /* Go inside any operations that get_inner_reference can handle and see
4140 if what's inside is a constant: no need to do anything here for
4141 addresses of variables or functions. */
4142 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4143 tem
= TREE_OPERAND (tem
, 0))
4146 if (TREE_PUBLIC (tem
))
4153 case POINTER_PLUS_EXPR
:
4154 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4155 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4159 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4160 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4161 /* The difference of two local labels is computable at link time. */
4162 if (reloc
== 1 && reloc2
== 1)
4169 case VIEW_CONVERT_EXPR
:
4170 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4175 unsigned HOST_WIDE_INT idx
;
4176 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4178 reloc
|= compute_reloc_for_constant (tem
);
4188 /* Find all the constants whose addresses are referenced inside of EXP,
4189 and make sure assembler code with a label has been output for each one.
4190 Indicate whether an ADDR_EXPR has been encountered. */
4193 output_addressed_constants (tree exp
)
4197 switch (TREE_CODE (exp
))
4201 /* Go inside any operations that get_inner_reference can handle and see
4202 if what's inside is a constant: no need to do anything here for
4203 addresses of variables or functions. */
4204 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4205 tem
= TREE_OPERAND (tem
, 0))
4208 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4209 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4210 tem
= DECL_INITIAL (tem
);
4212 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4213 output_constant_def (tem
, 0);
4217 case POINTER_PLUS_EXPR
:
4219 output_addressed_constants (TREE_OPERAND (exp
, 1));
4223 case VIEW_CONVERT_EXPR
:
4224 output_addressed_constants (TREE_OPERAND (exp
, 0));
4229 unsigned HOST_WIDE_INT idx
;
4230 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4232 output_addressed_constants (tem
);
4241 /* Whether a constructor CTOR is a valid static constant initializer if all
4242 its elements are. This used to be internal to initializer_constant_valid_p
4243 and has been exposed to let other functions like categorize_ctor_elements
4244 evaluate the property while walking a constructor for other purposes. */
4247 constructor_static_from_elts_p (const_tree ctor
)
4249 return (TREE_CONSTANT (ctor
)
4250 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4251 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
)
4252 && !VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (ctor
)));
4255 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4258 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4259 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4260 which are valid when ENDTYPE is an integer of any size; in
4261 particular, this does not accept a pointer minus a constant. This
4262 returns null_pointer_node if the VALUE is an absolute constant
4263 which can be used to initialize a static variable. Otherwise it
4267 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4271 if (!INTEGRAL_TYPE_P (endtype
))
4274 op0
= TREE_OPERAND (value
, 0);
4275 op1
= TREE_OPERAND (value
, 1);
4277 /* Like STRIP_NOPS except allow the operand mode to widen. This
4278 works around a feature of fold that simplifies (int)(p1 - p2) to
4279 ((int)p1 - (int)p2) under the theory that the narrower operation
4282 while (CONVERT_EXPR_P (op0
)
4283 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4285 tree inner
= TREE_OPERAND (op0
, 0);
4286 if (inner
== error_mark_node
4287 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4288 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4289 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4294 while (CONVERT_EXPR_P (op1
)
4295 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4297 tree inner
= TREE_OPERAND (op1
, 0);
4298 if (inner
== error_mark_node
4299 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4300 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4301 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4306 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4310 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4311 cache
? cache
+ 2 : NULL
);
4312 /* Both initializers must be known. */
4316 && (op0
== null_pointer_node
4317 || TREE_CODE (value
) == MINUS_EXPR
))
4318 return null_pointer_node
;
4320 /* Support differences between labels. */
4321 if (TREE_CODE (op0
) == LABEL_DECL
4322 && TREE_CODE (op1
) == LABEL_DECL
)
4323 return null_pointer_node
;
4325 if (TREE_CODE (op0
) == STRING_CST
4326 && TREE_CODE (op1
) == STRING_CST
4327 && operand_equal_p (op0
, op1
, 1))
4328 return null_pointer_node
;
4334 /* Helper function of initializer_constant_valid_p.
4335 Return nonzero if VALUE is a valid constant-valued expression
4336 for use in initializing a static variable; one that can be an
4337 element of a "constant" initializer.
4339 Return null_pointer_node if the value is absolute;
4340 if it is relocatable, return the variable that determines the relocation.
4341 We assume that VALUE has been folded as much as possible;
4342 therefore, we do not need to check for such things as
4343 arithmetic-combinations of integers.
4345 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4348 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4352 switch (TREE_CODE (value
))
4355 if (constructor_static_from_elts_p (value
))
4357 unsigned HOST_WIDE_INT idx
;
4359 bool absolute
= true;
4361 if (cache
&& cache
[0] == value
)
4363 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4366 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4373 cache
[1] = NULL_TREE
;
4377 if (reloc
!= null_pointer_node
)
4380 /* For a non-absolute relocation, there is no single
4381 variable that can be "the variable that determines the
4386 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4388 return absolute
? null_pointer_node
: error_mark_node
;
4391 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4399 return null_pointer_node
;
4404 tree op0
= staticp (TREE_OPERAND (value
, 0));
4407 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4408 to be a constant, this is old-skool offsetof-like nonsense. */
4409 if (TREE_CODE (op0
) == INDIRECT_REF
4410 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4411 return null_pointer_node
;
4412 /* Taking the address of a nested function involves a trampoline,
4413 unless we don't need or want one. */
4414 if (TREE_CODE (op0
) == FUNCTION_DECL
4415 && DECL_STATIC_CHAIN (op0
)
4416 && !TREE_NO_TRAMPOLINE (value
))
4418 /* "&{...}" requires a temporary to hold the constructed
4420 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4426 case NON_LVALUE_EXPR
:
4427 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4430 case VIEW_CONVERT_EXPR
:
4432 tree src
= TREE_OPERAND (value
, 0);
4433 tree src_type
= TREE_TYPE (src
);
4434 tree dest_type
= TREE_TYPE (value
);
4436 /* Allow view-conversions from aggregate to non-aggregate type only
4437 if the bit pattern is fully preserved afterwards; otherwise, the
4438 RTL expander won't be able to apply a subsequent transformation
4439 to the underlying constructor. */
4440 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4442 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4443 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4448 /* Allow all other kinds of view-conversion. */
4449 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4454 tree src
= TREE_OPERAND (value
, 0);
4455 tree src_type
= TREE_TYPE (src
);
4456 tree dest_type
= TREE_TYPE (value
);
4458 /* Allow conversions between pointer types, floating-point
4459 types, and offset types. */
4460 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4461 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4462 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4463 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4464 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4466 /* Allow length-preserving conversions between integer types. */
4467 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4468 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4469 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4471 /* Allow conversions between other integer types only if
4473 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4475 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4476 if (inner
== null_pointer_node
)
4477 return null_pointer_node
;
4481 /* Allow (int) &foo provided int is as wide as a pointer. */
4482 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4483 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4484 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4486 /* Likewise conversions from int to pointers, but also allow
4487 conversions from 0. */
4488 if ((POINTER_TYPE_P (dest_type
)
4489 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4490 && INTEGRAL_TYPE_P (src_type
))
4492 if (TREE_CODE (src
) == INTEGER_CST
4493 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4494 return null_pointer_node
;
4495 if (integer_zerop (src
))
4496 return null_pointer_node
;
4497 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4498 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4501 /* Allow conversions to struct or union types if the value
4503 if (TREE_CODE (dest_type
) == RECORD_TYPE
4504 || TREE_CODE (dest_type
) == UNION_TYPE
)
4505 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4509 case POINTER_PLUS_EXPR
:
4511 /* Any valid floating-point constants will have been folded by now;
4512 with -frounding-math we hit this with addition of two constants. */
4513 if (TREE_CODE (endtype
) == REAL_TYPE
)
4515 if (cache
&& cache
[0] == value
)
4517 if (! INTEGRAL_TYPE_P (endtype
)
4518 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4520 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4522 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4525 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4526 endtype
, ncache
+ 2);
4527 /* If either term is absolute, use the other term's relocation. */
4528 if (valid0
== null_pointer_node
)
4530 else if (valid1
== null_pointer_node
)
4532 /* Support narrowing pointer differences. */
4534 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4538 /* Support narrowing pointer differences. */
4539 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4548 if (TREE_CODE (endtype
) == REAL_TYPE
)
4550 if (cache
&& cache
[0] == value
)
4552 if (! INTEGRAL_TYPE_P (endtype
)
4553 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4555 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4557 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4560 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4561 endtype
, ncache
+ 2);
4562 /* Win if second argument is absolute. */
4563 if (valid1
== null_pointer_node
)
4565 /* Win if both arguments have the same relocation.
4566 Then the value is absolute. */
4567 else if (valid0
== valid1
&& valid0
!= 0)
4568 ret
= null_pointer_node
;
4569 /* Since GCC guarantees that string constants are unique in the
4570 generated code, a subtraction between two copies of the same
4571 constant string is absolute. */
4572 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4573 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4574 && operand_equal_p (valid0
, valid1
, 1))
4575 ret
= null_pointer_node
;
4576 /* Support narrowing differences. */
4578 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4582 /* Support narrowing differences. */
4583 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4598 /* Return nonzero if VALUE is a valid constant-valued expression
4599 for use in initializing a static variable; one that can be an
4600 element of a "constant" initializer.
4602 Return null_pointer_node if the value is absolute;
4603 if it is relocatable, return the variable that determines the relocation.
4604 We assume that VALUE has been folded as much as possible;
4605 therefore, we do not need to check for such things as
4606 arithmetic-combinations of integers. */
4608 initializer_constant_valid_p (tree value
, tree endtype
)
4610 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4613 /* Return true if VALUE is a valid constant-valued expression
4614 for use in initializing a static bit-field; one that can be
4615 an element of a "constant" initializer. */
4618 initializer_constant_valid_for_bitfield_p (tree value
)
4620 /* For bitfields we support integer constants or possibly nested aggregates
4622 switch (TREE_CODE (value
))
4626 unsigned HOST_WIDE_INT idx
;
4629 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4630 if (!initializer_constant_valid_for_bitfield_p (elt
))
4638 case VIEW_CONVERT_EXPR
:
4639 case NON_LVALUE_EXPR
:
4641 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4650 /* output_constructor outer state of relevance in recursive calls, typically
4651 for nested aggregate bitfields. */
4654 unsigned int bit_offset
; /* current position in ... */
4655 int byte
; /* ... the outer byte buffer. */
4658 static unsigned HOST_WIDE_INT
4659 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4662 /* Output assembler code for constant EXP to FILE, with no label.
4663 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4664 Assumes output_addressed_constants has been done on EXP already.
4666 Generate exactly SIZE bytes of assembler data, padding at the end
4667 with zeros if necessary. SIZE must always be specified.
4669 SIZE is important for structure constructors,
4670 since trailing members may have been omitted from the constructor.
4671 It is also important for initialization of arrays from string constants
4672 since the full length of the string constant might not be wanted.
4673 It is also needed for initialization of unions, where the initializer's
4674 type is just one member, and that may not be as long as the union.
4676 There a case in which we would fail to output exactly SIZE bytes:
4677 for a structure constructor that wants to produce more than SIZE bytes.
4678 But such constructors will never be generated for any possible input.
4680 ALIGN is the alignment of the data in bits. */
4683 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4685 enum tree_code code
;
4686 unsigned HOST_WIDE_INT thissize
;
4688 if (size
== 0 || flag_syntax_only
)
4691 /* See if we're trying to initialize a pointer in a non-default mode
4692 to the address of some declaration somewhere. If the target says
4693 the mode is valid for pointers, assume the target has a way of
4695 if (TREE_CODE (exp
) == NOP_EXPR
4696 && POINTER_TYPE_P (TREE_TYPE (exp
))
4697 && targetm
.addr_space
.valid_pointer_mode
4698 (TYPE_MODE (TREE_TYPE (exp
)),
4699 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4701 tree saved_type
= TREE_TYPE (exp
);
4703 /* Peel off any intermediate conversions-to-pointer for valid
4705 while (TREE_CODE (exp
) == NOP_EXPR
4706 && POINTER_TYPE_P (TREE_TYPE (exp
))
4707 && targetm
.addr_space
.valid_pointer_mode
4708 (TYPE_MODE (TREE_TYPE (exp
)),
4709 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4710 exp
= TREE_OPERAND (exp
, 0);
4712 /* If what we're left with is the address of something, we can
4713 convert the address to the final type and output it that
4715 if (TREE_CODE (exp
) == ADDR_EXPR
)
4716 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4717 /* Likewise for constant ints. */
4718 else if (TREE_CODE (exp
) == INTEGER_CST
)
4719 exp
= build_int_cst_wide (saved_type
, TREE_INT_CST_LOW (exp
),
4720 TREE_INT_CST_HIGH (exp
));
4724 /* Eliminate any conversions since we'll be outputting the underlying
4726 while (CONVERT_EXPR_P (exp
)
4727 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4728 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4730 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4731 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4733 /* Make sure eliminating the conversion is really a no-op, except with
4734 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4735 union types to allow for Ada unchecked unions. */
4736 if (type_size
> op_size
4737 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4738 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4739 /* Keep the conversion. */
4742 exp
= TREE_OPERAND (exp
, 0);
4745 code
= TREE_CODE (TREE_TYPE (exp
));
4746 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4748 /* Allow a constructor with no elements for any data type.
4749 This means to fill the space with zeros. */
4750 if (TREE_CODE (exp
) == CONSTRUCTOR
4751 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
4753 assemble_zeros (size
);
4757 if (TREE_CODE (exp
) == FDESC_EXPR
)
4759 #ifdef ASM_OUTPUT_FDESC
4760 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4761 tree decl
= TREE_OPERAND (exp
, 0);
4762 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4769 /* Now output the underlying data. If we've handling the padding, return.
4770 Otherwise, break and ensure SIZE is the size written. */
4777 case REFERENCE_TYPE
:
4779 case FIXED_POINT_TYPE
:
4780 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4781 EXPAND_INITIALIZER
),
4782 MIN (size
, thissize
), align
, 0))
4783 error ("initializer for integer/fixed-point value is too complicated");
4787 if (TREE_CODE (exp
) != REAL_CST
)
4788 error ("initializer for floating value is not a floating constant");
4790 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4794 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4795 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4796 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4801 switch (TREE_CODE (exp
))
4804 output_constructor (exp
, size
, align
, NULL
);
4807 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
4809 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4816 unsigned int nalign
;
4817 enum machine_mode inner
;
4819 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4820 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4822 elt_size
= GET_MODE_SIZE (inner
);
4824 link
= TREE_VECTOR_CST_ELTS (exp
);
4825 output_constant (TREE_VALUE (link
), elt_size
, align
);
4826 thissize
= elt_size
;
4827 while ((link
= TREE_CHAIN (link
)) != NULL
)
4829 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
4830 thissize
+= elt_size
;
4841 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4842 output_constructor (exp
, size
, align
, NULL
);
4852 if (size
> thissize
)
4853 assemble_zeros (size
- thissize
);
4857 /* Subroutine of output_constructor, used for computing the size of
4858 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4859 type with an unspecified upper bound. */
4861 static unsigned HOST_WIDE_INT
4862 array_size_for_constructor (tree val
)
4865 unsigned HOST_WIDE_INT cnt
;
4866 tree index
, value
, tmp
;
4868 /* This code used to attempt to handle string constants that are not
4869 arrays of single-bytes, but nothing else does, so there's no point in
4871 if (TREE_CODE (val
) == STRING_CST
)
4872 return TREE_STRING_LENGTH (val
);
4874 max_index
= NULL_TREE
;
4875 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4877 if (TREE_CODE (index
) == RANGE_EXPR
)
4878 index
= TREE_OPERAND (index
, 1);
4879 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4883 if (max_index
== NULL_TREE
)
4886 /* Compute the total number of array elements. */
4887 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4888 i
= size_binop (MINUS_EXPR
, fold_convert (sizetype
, max_index
),
4889 fold_convert (sizetype
, tmp
));
4890 i
= size_binop (PLUS_EXPR
, i
, build_int_cst (sizetype
, 1));
4892 /* Multiply by the array element unit size to find number of bytes. */
4893 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4895 return tree_low_cst (i
, 1);
4898 /* Other datastructures + helpers for output_constructor. */
4900 /* output_constructor local state to support interaction with helpers. */
4904 /* Received arguments. */
4905 tree exp
; /* Constructor expression. */
4906 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4907 unsigned int align
; /* Known initial alignment. */
4909 /* Constructor expression data. */
4910 tree type
; /* Expression type. */
4911 tree field
; /* Current field decl in a record. */
4912 tree min_index
; /* Lower bound if specified for an array. */
4914 /* Output processing state. */
4915 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4916 bool byte_buffer_in_use
; /* Whether byte ... */
4917 int byte
; /* ... contains part of a bitfield byte yet to
4920 int last_relative_index
; /* Implicit or explicit index of the last
4921 array element output within a bitfield. */
4922 /* Current element. */
4923 tree val
; /* Current element value. */
4924 tree index
; /* Current element index. */
4928 /* Helper for output_constructor. From the current LOCAL state, output a
4929 RANGE_EXPR element. */
4932 output_constructor_array_range (oc_local_state
*local
)
4934 unsigned HOST_WIDE_INT fieldsize
4935 = int_size_in_bytes (TREE_TYPE (local
->type
));
4937 HOST_WIDE_INT lo_index
4938 = tree_low_cst (TREE_OPERAND (local
->index
, 0), 0);
4939 HOST_WIDE_INT hi_index
4940 = tree_low_cst (TREE_OPERAND (local
->index
, 1), 0);
4941 HOST_WIDE_INT index
;
4944 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4946 for (index
= lo_index
; index
<= hi_index
; index
++)
4948 /* Output the element's initial value. */
4949 if (local
->val
== NULL_TREE
)
4950 assemble_zeros (fieldsize
);
4952 output_constant (local
->val
, fieldsize
, align2
);
4954 /* Count its size. */
4955 local
->total_bytes
+= fieldsize
;
4959 /* Helper for output_constructor. From the current LOCAL state, output a
4960 field element that is not true bitfield or part of an outer one. */
4963 output_constructor_regular_field (oc_local_state
*local
)
4965 /* Field size and position. Since this structure is static, we know the
4966 positions are constant. */
4967 unsigned HOST_WIDE_INT fieldsize
;
4968 HOST_WIDE_INT fieldpos
;
4970 unsigned int align2
;
4972 if (local
->index
!= NULL_TREE
)
4973 fieldpos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
)), 1)
4974 * ((tree_low_cst (local
->index
, 0)
4975 - tree_low_cst (local
->min_index
, 0))));
4976 else if (local
->field
!= NULL_TREE
)
4977 fieldpos
= int_byte_position (local
->field
);
4981 /* Output any buffered-up bit-fields preceding this element. */
4982 if (local
->byte_buffer_in_use
)
4984 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4985 local
->total_bytes
++;
4986 local
->byte_buffer_in_use
= false;
4989 /* Advance to offset of this element.
4990 Note no alignment needed in an array, since that is guaranteed
4991 if each element has the proper size. */
4992 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4993 && fieldpos
!= local
->total_bytes
)
4995 gcc_assert (fieldpos
>= local
->total_bytes
);
4996 assemble_zeros (fieldpos
- local
->total_bytes
);
4997 local
->total_bytes
= fieldpos
;
5000 /* Find the alignment of this element. */
5001 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
5003 /* Determine size this element should occupy. */
5008 /* If this is an array with an unspecified upper bound,
5009 the initializer determines the size. */
5010 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5011 but we cannot do this until the deprecated support for
5012 initializing zero-length array members is removed. */
5013 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
5014 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
5015 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
5017 fieldsize
= array_size_for_constructor (local
->val
);
5018 /* Given a non-empty initialization, this field had
5020 gcc_assert (!fieldsize
|| !TREE_CHAIN (local
->field
));
5022 else if (DECL_SIZE_UNIT (local
->field
))
5024 /* ??? This can't be right. If the decl size overflows
5025 a host integer we will silently emit no data. */
5026 if (host_integerp (DECL_SIZE_UNIT (local
->field
), 1))
5027 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (local
->field
), 1);
5031 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
5033 /* Output the element's initial value. */
5034 if (local
->val
== NULL_TREE
)
5035 assemble_zeros (fieldsize
);
5037 output_constant (local
->val
, fieldsize
, align2
);
5039 /* Count its size. */
5040 local
->total_bytes
+= fieldsize
;
5043 /* Helper for output_constructor. From the current LOCAL and OUTER states,
5044 output an element that is a true bitfield or part of an outer one. */
5047 output_constructor_bitfield (oc_local_state
*local
, oc_outer_state
*outer
)
5049 /* Bit size of this element. */
5050 HOST_WIDE_INT ebitsize
5052 ? tree_low_cst (DECL_SIZE (local
->field
), 1)
5053 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local
->type
)), 1));
5055 /* Relative index of this element if this is an array component. */
5056 HOST_WIDE_INT relative_index
5059 ? (tree_low_cst (local
->index
, 0)
5060 - tree_low_cst (local
->min_index
, 0))
5061 : local
->last_relative_index
+ 1)
5064 /* Bit position of this element from the start of the containing
5066 HOST_WIDE_INT constructor_relative_ebitpos
5068 ? int_bit_position (local
->field
)
5069 : ebitsize
* relative_index
);
5071 /* Bit position of this element from the start of a possibly ongoing
5072 outer byte buffer. */
5073 HOST_WIDE_INT byte_relative_ebitpos
5074 = ((outer
? outer
->bit_offset
: 0) + constructor_relative_ebitpos
);
5076 /* From the start of a possibly ongoing outer byte buffer, offsets to
5077 the first bit of this element and to the first bit past the end of
5079 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
5080 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
5082 local
->last_relative_index
= relative_index
;
5084 if (local
->val
== NULL_TREE
)
5085 local
->val
= integer_zero_node
;
5087 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
5088 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
5089 local
->val
= TREE_OPERAND (local
->val
, 0);
5091 if (TREE_CODE (local
->val
) != INTEGER_CST
5092 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
5094 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
5098 /* If this field does not start in this (or, next) byte,
5100 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5102 /* Output remnant of any bit field in previous bytes. */
5103 if (local
->byte_buffer_in_use
)
5105 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5106 local
->total_bytes
++;
5107 local
->byte_buffer_in_use
= false;
5110 /* If still not at proper byte, advance to there. */
5111 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5113 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
5114 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
5115 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
5119 /* Set up the buffer if necessary. */
5120 if (!local
->byte_buffer_in_use
)
5124 local
->byte_buffer_in_use
= true;
5127 /* If this is nested constructor, recurse passing the bit offset and the
5128 pending data, then retrieve the new pending data afterwards. */
5129 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
5131 oc_outer_state output_state
;
5133 output_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
5134 output_state
.byte
= local
->byte
;
5136 += output_constructor (local
->val
, 0, 0, &output_state
);
5137 local
->byte
= output_state
.byte
;
5141 /* Otherwise, we must split the element into pieces that fall within
5142 separate bytes, and combine each byte with previous or following
5144 while (next_offset
< end_offset
)
5148 HOST_WIDE_INT value
;
5149 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5150 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5152 /* Advance from byte to byte
5153 within this element when necessary. */
5154 while (next_byte
!= local
->total_bytes
)
5156 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5157 local
->total_bytes
++;
5161 /* Number of bits we can process at once
5162 (all part of the same byte). */
5163 this_time
= MIN (end_offset
- next_offset
,
5164 BITS_PER_UNIT
- next_bit
);
5165 if (BYTES_BIG_ENDIAN
)
5167 /* On big-endian machine, take the most significant bits
5168 first (of the bits that are significant)
5169 and put them into bytes from the most significant end. */
5170 shift
= end_offset
- next_offset
- this_time
;
5172 /* Don't try to take a bunch of bits that cross
5173 the word boundary in the INTEGER_CST. We can
5174 only select bits from the LOW or HIGH part
5176 if (shift
< HOST_BITS_PER_WIDE_INT
5177 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
5179 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
5180 shift
= HOST_BITS_PER_WIDE_INT
;
5183 /* Now get the bits from the appropriate constant word. */
5184 if (shift
< HOST_BITS_PER_WIDE_INT
)
5185 value
= TREE_INT_CST_LOW (local
->val
);
5188 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
5189 value
= TREE_INT_CST_HIGH (local
->val
);
5190 shift
-= HOST_BITS_PER_WIDE_INT
;
5193 /* Get the result. This works only when:
5194 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5195 local
->byte
|= (((value
>> shift
)
5196 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5197 << (BITS_PER_UNIT
- this_time
- next_bit
));
5201 /* On little-endian machines,
5202 take first the least significant bits of the value
5203 and pack them starting at the least significant
5204 bits of the bytes. */
5205 shift
= next_offset
- byte_relative_ebitpos
;
5207 /* Don't try to take a bunch of bits that cross
5208 the word boundary in the INTEGER_CST. We can
5209 only select bits from the LOW or HIGH part
5211 if (shift
< HOST_BITS_PER_WIDE_INT
5212 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
5213 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
5215 /* Now get the bits from the appropriate constant word. */
5216 if (shift
< HOST_BITS_PER_WIDE_INT
)
5217 value
= TREE_INT_CST_LOW (local
->val
);
5220 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
5221 value
= TREE_INT_CST_HIGH (local
->val
);
5222 shift
-= HOST_BITS_PER_WIDE_INT
;
5225 /* Get the result. This works only when:
5226 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5227 local
->byte
|= (((value
>> shift
)
5228 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5232 next_offset
+= this_time
;
5233 local
->byte_buffer_in_use
= true;
5237 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5238 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5239 caller output state of relevance in recursive invocations. */
5241 static unsigned HOST_WIDE_INT
5242 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5243 unsigned int align
, oc_outer_state
* outer
)
5245 unsigned HOST_WIDE_INT cnt
;
5246 constructor_elt
*ce
;
5248 oc_local_state local
;
5250 /* Setup our local state to communicate with helpers. */
5253 local
.align
= align
;
5255 local
.total_bytes
= 0;
5256 local
.byte_buffer_in_use
= outer
!= NULL
;
5257 local
.byte
= outer
? outer
->byte
: 0;
5259 local
.type
= TREE_TYPE (exp
);
5261 local
.last_relative_index
= -1;
5263 local
.min_index
= NULL_TREE
;
5264 if (TREE_CODE (local
.type
) == ARRAY_TYPE
5265 && TYPE_DOMAIN (local
.type
) != NULL_TREE
)
5266 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5268 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5270 /* As CE goes through the elements of the constant, FIELD goes through the
5271 structure fields if the constant is a structure. If the constant is a
5272 union, we override this by getting the field from the TREE_LIST element.
5273 But the constant could also be an array. Then FIELD is zero.
5275 There is always a maximum of one element in the chain LINK for unions
5276 (even if the initializer in a source program incorrectly contains
5279 local
.field
= NULL_TREE
;
5280 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5281 local
.field
= TYPE_FIELDS (local
.type
);
5284 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
5285 cnt
++, local
.field
= local
.field
? TREE_CHAIN (local
.field
) : 0)
5287 local
.val
= ce
->value
;
5288 local
.index
= NULL_TREE
;
5290 /* The element in a union constructor specifies the proper field
5292 if ((TREE_CODE (local
.type
) == RECORD_TYPE
5293 || TREE_CODE (local
.type
) == UNION_TYPE
5294 || TREE_CODE (local
.type
) == QUAL_UNION_TYPE
)
5295 && ce
->index
!= NULL_TREE
)
5296 local
.field
= ce
->index
;
5298 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5299 local
.index
= ce
->index
;
5301 #ifdef ASM_COMMENT_START
5302 if (local
.field
&& flag_verbose_asm
)
5303 fprintf (asm_out_file
, "%s %s:\n",
5305 DECL_NAME (local
.field
)
5306 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5310 /* Eliminate the marker that makes a cast not be an lvalue. */
5311 if (local
.val
!= NULL_TREE
)
5312 STRIP_NOPS (local
.val
);
5314 /* Output the current element, using the appropriate helper ... */
5316 /* For an array slice not part of an outer bitfield. */
5318 && local
.index
!= NULL_TREE
5319 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5320 output_constructor_array_range (&local
);
5322 /* For a field that is neither a true bitfield nor part of an outer one,
5323 known to be at least byte aligned and multiple-of-bytes long. */
5325 && (local
.field
== NULL_TREE
5326 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5327 output_constructor_regular_field (&local
);
5329 /* For a true bitfield or part of an outer one. */
5331 output_constructor_bitfield (&local
, outer
);
5334 /* If we are not at toplevel, save the pending data for our caller.
5335 Otherwise output the pending data and padding zeros as needed. */
5337 outer
->byte
= local
.byte
;
5340 if (local
.byte_buffer_in_use
)
5342 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5343 local
.total_bytes
++;
5346 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5348 assemble_zeros (local
.size
- local
.total_bytes
);
5349 local
.total_bytes
= local
.size
;
5353 return local
.total_bytes
;
5356 /* Mark DECL as weak. */
5359 mark_weak (tree decl
)
5361 DECL_WEAK (decl
) = 1;
5363 if (DECL_RTL_SET_P (decl
)
5364 && MEM_P (DECL_RTL (decl
))
5365 && XEXP (DECL_RTL (decl
), 0)
5366 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5367 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5370 /* Merge weak status between NEWDECL and OLDDECL. */
5373 merge_weak (tree newdecl
, tree olddecl
)
5375 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5377 if (DECL_WEAK (newdecl
) && SUPPORTS_WEAK
)
5380 /* We put the NEWDECL on the weak_decls list at some point
5381 and OLDDECL as well. Keep just OLDDECL on the list. */
5382 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5383 if (TREE_VALUE (*pwd
) == newdecl
)
5385 *pwd
= TREE_CHAIN (*pwd
);
5392 if (DECL_WEAK (newdecl
))
5396 /* NEWDECL is weak, but OLDDECL is not. */
5398 /* If we already output the OLDDECL, we're in trouble; we can't
5399 go back and make it weak. This error cannot be caught in
5400 declare_weak because the NEWDECL and OLDDECL was not yet
5401 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5402 if (TREE_ASM_WRITTEN (olddecl
))
5403 error ("weak declaration of %q+D must precede definition",
5406 /* If we've already generated rtl referencing OLDDECL, we may
5407 have done so in a way that will not function properly with
5409 else if (TREE_USED (olddecl
)
5410 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
5411 warning (0, "weak declaration of %q+D after first use results "
5412 "in unspecified behavior", newdecl
);
5416 /* We put the NEWDECL on the weak_decls list at some point.
5417 Replace it with the OLDDECL. */
5418 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5419 if (TREE_VALUE (wd
) == newdecl
)
5421 TREE_VALUE (wd
) = olddecl
;
5424 /* We may not find the entry on the list. If NEWDECL is a
5425 weak alias, then we will have already called
5426 globalize_decl to remove the entry; in that case, we do
5427 not need to do anything. */
5430 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5431 mark_weak (olddecl
);
5434 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5435 weak. Just update NEWDECL to indicate that it's weak too. */
5436 mark_weak (newdecl
);
5439 /* Declare DECL to be a weak symbol. */
5442 declare_weak (tree decl
)
5444 if (! TREE_PUBLIC (decl
))
5445 error ("weak declaration of %q+D must be public", decl
);
5446 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
5447 error ("weak declaration of %q+D must precede definition", decl
);
5448 else if (!SUPPORTS_WEAK
)
5449 warning (0, "weak declaration of %q+D not supported", decl
);
5452 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5453 DECL_ATTRIBUTES (decl
)
5454 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5458 weak_finish_1 (tree decl
)
5460 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5461 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5464 if (! TREE_USED (decl
))
5467 #ifdef ASM_WEAKEN_DECL
5468 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5470 #ifdef ASM_WEAKEN_LABEL
5471 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5473 #ifdef ASM_OUTPUT_WEAK_ALIAS
5475 static bool warn_once
= 0;
5478 warning (0, "only weak aliases are supported in this configuration");
5488 /* This TREE_LIST contains weakref targets. */
5490 static GTY(()) tree weakref_targets
;
5492 /* Forward declaration. */
5493 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
5495 /* Emit any pending weak declarations. */
5502 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5504 tree alias_decl
= TREE_PURPOSE (t
);
5505 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5507 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5508 /* Remove alias_decl from the weak list, but leave entries for
5509 the target alone. */
5511 #ifndef ASM_OUTPUT_WEAKREF
5512 else if (! TREE_SYMBOL_REFERENCED (target
))
5514 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5515 defined, otherwise we and weak_finish_1 would use
5516 different macros. */
5517 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5518 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5520 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
5524 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5525 TREE_CODE (alias_decl
), target
,
5526 TREE_TYPE (alias_decl
));
5528 DECL_EXTERNAL (decl
) = 1;
5529 TREE_PUBLIC (decl
) = 1;
5530 DECL_ARTIFICIAL (decl
) = 1;
5531 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5532 TREE_USED (decl
) = 1;
5535 weak_finish_1 (decl
);
5544 /* Remove the alias and the target from the pending weak list
5545 so that we do not emit any .weak directives for the former,
5546 nor multiple .weak directives for the latter. */
5547 for (p
= &weak_decls
; (t2
= *p
) ; )
5549 if (TREE_VALUE (t2
) == alias_decl
5550 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5551 *p
= TREE_CHAIN (t2
);
5553 p
= &TREE_CHAIN (t2
);
5556 /* Remove other weakrefs to the same target, to speed things up. */
5557 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5559 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5560 *p
= TREE_CHAIN (t2
);
5562 p
= &TREE_CHAIN (t2
);
5567 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5569 tree decl
= TREE_VALUE (t
);
5571 weak_finish_1 (decl
);
5575 /* Emit the assembly bits to indicate that DECL is globally visible. */
5578 globalize_decl (tree decl
)
5581 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5582 if (DECL_WEAK (decl
))
5584 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5587 #ifdef ASM_WEAKEN_DECL
5588 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5590 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5593 /* Remove this function from the pending weak list so that
5594 we do not emit multiple .weak directives for it. */
5595 for (p
= &weak_decls
; (t
= *p
) ; )
5597 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5598 *p
= TREE_CHAIN (t
);
5600 p
= &TREE_CHAIN (t
);
5603 /* Remove weakrefs to the same target from the pending weakref
5604 list, for the same reason. */
5605 for (p
= &weakref_targets
; (t
= *p
) ; )
5607 if (DECL_ASSEMBLER_NAME (decl
)
5608 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5609 *p
= TREE_CHAIN (t
);
5611 p
= &TREE_CHAIN (t
);
5618 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5621 VEC(alias_pair
,gc
) *alias_pairs
;
5623 /* Given an assembly name, find the decl it is associated with. At the
5624 same time, mark it needed for cgraph. */
5627 find_decl_and_mark_needed (tree decl
, tree target
)
5629 struct cgraph_node
*fnode
= NULL
;
5630 struct varpool_node
*vnode
= NULL
;
5632 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5634 fnode
= cgraph_node_for_asm (target
);
5636 vnode
= varpool_node_for_asm (target
);
5640 vnode
= varpool_node_for_asm (target
);
5642 fnode
= cgraph_node_for_asm (target
);
5647 cgraph_mark_needed_node (fnode
);
5652 varpool_mark_needed_node (vnode
);
5653 vnode
->force_output
= 1;
5660 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5661 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5662 tree node is DECL to have the value of the tree node TARGET. */
5665 do_assemble_alias (tree decl
, tree target
)
5667 if (TREE_ASM_WRITTEN (decl
))
5670 /* We must force creation of DECL_RTL for debug info generation, even though
5671 we don't use it here. */
5672 make_decl_rtl (decl
);
5674 TREE_ASM_WRITTEN (decl
) = 1;
5675 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5677 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5679 ultimate_transparent_alias_target (&target
);
5681 if (!targetm
.have_tls
5682 && TREE_CODE (decl
) == VAR_DECL
5683 && DECL_THREAD_LOCAL_P (decl
))
5685 decl
= emutls_decl (decl
);
5686 target
= get_emutls_object_name (target
);
5689 if (!TREE_SYMBOL_REFERENCED (target
))
5690 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5692 #ifdef ASM_OUTPUT_WEAKREF
5693 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5694 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5695 IDENTIFIER_POINTER (target
));
5699 error_at (DECL_SOURCE_LOCATION (decl
),
5700 "weakref is not supported in this configuration");
5707 if (!targetm
.have_tls
5708 && TREE_CODE (decl
) == VAR_DECL
5709 && DECL_THREAD_LOCAL_P (decl
))
5711 decl
= emutls_decl (decl
);
5712 target
= get_emutls_object_name (target
);
5715 #ifdef ASM_OUTPUT_DEF
5716 /* Make name accessible from other files, if appropriate. */
5718 if (TREE_PUBLIC (decl
))
5720 globalize_decl (decl
);
5721 maybe_assemble_visibility (decl
);
5724 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5725 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5727 ASM_OUTPUT_DEF (asm_out_file
,
5728 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5729 IDENTIFIER_POINTER (target
));
5731 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5736 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5737 # ifdef ASM_WEAKEN_DECL
5738 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5740 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5742 /* Remove this function from the pending weak list so that
5743 we do not emit multiple .weak directives for it. */
5744 for (p
= &weak_decls
; (t
= *p
) ; )
5745 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5746 *p
= TREE_CHAIN (t
);
5748 p
= &TREE_CHAIN (t
);
5750 /* Remove weakrefs to the same target from the pending weakref
5751 list, for the same reason. */
5752 for (p
= &weakref_targets
; (t
= *p
) ; )
5754 if (DECL_ASSEMBLER_NAME (decl
)
5755 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5756 *p
= TREE_CHAIN (t
);
5758 p
= &TREE_CHAIN (t
);
5765 /* Remove the alias pairing for functions that are no longer in the call
5769 remove_unreachable_alias_pairs (void)
5774 if (alias_pairs
== NULL
)
5777 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); )
5779 if (!DECL_EXTERNAL (p
->decl
))
5781 struct cgraph_node
*fnode
= NULL
;
5782 struct varpool_node
*vnode
= NULL
;
5783 fnode
= cgraph_node_for_asm (p
->target
);
5784 vnode
= (fnode
== NULL
) ? varpool_node_for_asm (p
->target
) : NULL
;
5785 if (fnode
== NULL
&& vnode
== NULL
)
5787 VEC_unordered_remove (alias_pair
, alias_pairs
, i
);
5797 /* First pass of completing pending aliases. Make sure that cgraph knows
5798 which symbols will be required. */
5801 finish_aliases_1 (void)
5806 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
5810 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
5811 if (target_decl
== NULL
)
5813 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5814 error ("%q+D aliased to undefined symbol %qE",
5815 p
->decl
, p
->target
);
5817 else if (DECL_EXTERNAL (target_decl
)
5818 /* We use local aliases for C++ thunks to force the tailcall
5819 to bind locally. Of course this is a hack - to keep it
5820 working do the following (which is not strictly correct). */
5821 && (! TREE_CODE (target_decl
) == FUNCTION_DECL
5822 || ! DECL_VIRTUAL_P (target_decl
))
5823 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5824 error ("%q+D aliased to external symbol %qE",
5825 p
->decl
, p
->target
);
5829 /* Second pass of completing pending aliases. Emit the actual assembly.
5830 This happens at the end of compilation and thus it is assured that the
5831 target symbol has been emitted. */
5834 finish_aliases_2 (void)
5839 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
5840 do_assemble_alias (p
->decl
, p
->target
);
5842 VEC_truncate (alias_pair
, alias_pairs
, 0);
5845 /* Emit an assembler directive to make the symbol for DECL an alias to
5846 the symbol for TARGET. */
5849 assemble_alias (tree decl
, tree target
)
5852 bool is_weakref
= false;
5854 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5856 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5860 ultimate_transparent_alias_target (&target
);
5862 if (alias
== target
)
5863 error ("weakref %q+D ultimately targets itself", decl
);
5866 #ifndef ASM_OUTPUT_WEAKREF
5867 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
5868 TREE_CHAIN (alias
) = target
;
5871 if (TREE_PUBLIC (decl
))
5872 error ("weakref %q+D must have static linkage", decl
);
5876 #if !defined (ASM_OUTPUT_DEF)
5877 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5878 error_at (DECL_SOURCE_LOCATION (decl
),
5879 "alias definitions not supported in this configuration");
5882 if (!DECL_WEAK (decl
))
5884 error_at (DECL_SOURCE_LOCATION (decl
),
5885 "only weak aliases are supported in this configuration");
5891 TREE_USED (decl
) = 1;
5893 /* A quirk of the initial implementation of aliases required that the user
5894 add "extern" to all of them. Which is silly, but now historical. Do
5895 note that the symbol is in fact locally defined. */
5897 DECL_EXTERNAL (decl
) = 0;
5899 /* Allow aliases to aliases. */
5900 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5901 cgraph_node (decl
)->alias
= true;
5903 varpool_node (decl
)->alias
= true;
5905 /* If the target has already been emitted, we don't have to queue the
5906 alias. This saves a tad of memory. */
5907 if (cgraph_global_info_ready
)
5908 target_decl
= find_decl_and_mark_needed (decl
, target
);
5911 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5912 do_assemble_alias (decl
, target
);
5915 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
5921 /* Emit an assembler directive to set symbol for DECL visibility to
5922 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5925 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5926 int vis ATTRIBUTE_UNUSED
)
5928 #ifdef HAVE_GAS_HIDDEN
5929 static const char * const visibility_types
[] = {
5930 NULL
, "protected", "hidden", "internal"
5933 const char *name
, *type
;
5935 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5936 type
= visibility_types
[vis
];
5938 fprintf (asm_out_file
, "\t.%s\t", type
);
5939 assemble_name (asm_out_file
, name
);
5940 fprintf (asm_out_file
, "\n");
5942 warning (OPT_Wattributes
, "visibility attribute not supported "
5943 "in this configuration; ignored");
5947 /* A helper function to call assemble_visibility when needed for a decl. */
5950 maybe_assemble_visibility (tree decl
)
5952 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5954 if (vis
!= VISIBILITY_DEFAULT
)
5956 targetm
.asm_out
.visibility (decl
, vis
);
5963 /* Returns 1 if the target configuration supports defining public symbols
5964 so that one of them will be chosen at link time instead of generating a
5965 multiply-defined symbol error, whether through the use of weak symbols or
5966 a target-specific mechanism for having duplicates discarded. */
5969 supports_one_only (void)
5971 if (SUPPORTS_ONE_ONLY
)
5973 return SUPPORTS_WEAK
;
5976 /* Set up DECL as a public symbol that can be defined in multiple
5977 translation units without generating a linker error. */
5980 make_decl_one_only (tree decl
, tree comdat_group
)
5982 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5983 || TREE_CODE (decl
) == FUNCTION_DECL
);
5985 TREE_PUBLIC (decl
) = 1;
5987 if (SUPPORTS_ONE_ONLY
)
5989 #ifdef MAKE_DECL_ONE_ONLY
5990 MAKE_DECL_ONE_ONLY (decl
);
5992 DECL_COMDAT_GROUP (decl
) = comdat_group
;
5994 else if (TREE_CODE (decl
) == VAR_DECL
5995 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5996 DECL_COMMON (decl
) = 1;
5999 gcc_assert (SUPPORTS_WEAK
);
6000 DECL_WEAK (decl
) = 1;
6005 init_varasm_once (void)
6007 section_htab
= htab_create_ggc (31, section_entry_hash
,
6008 section_entry_eq
, NULL
);
6009 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
6010 object_block_entry_eq
, NULL
);
6011 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
6012 const_desc_eq
, NULL
);
6014 const_alias_set
= new_alias_set ();
6015 shared_constant_pool
= create_constant_pool ();
6017 #ifdef TEXT_SECTION_ASM_OP
6018 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
6019 TEXT_SECTION_ASM_OP
);
6022 #ifdef DATA_SECTION_ASM_OP
6023 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6024 DATA_SECTION_ASM_OP
);
6027 #ifdef SDATA_SECTION_ASM_OP
6028 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6029 SDATA_SECTION_ASM_OP
);
6032 #ifdef READONLY_DATA_SECTION_ASM_OP
6033 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
6034 READONLY_DATA_SECTION_ASM_OP
);
6037 #ifdef CTORS_SECTION_ASM_OP
6038 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
6039 CTORS_SECTION_ASM_OP
);
6042 #ifdef DTORS_SECTION_ASM_OP
6043 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
6044 DTORS_SECTION_ASM_OP
);
6047 #ifdef BSS_SECTION_ASM_OP
6048 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6049 output_section_asm_op
,
6050 BSS_SECTION_ASM_OP
);
6053 #ifdef SBSS_SECTION_ASM_OP
6054 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6055 output_section_asm_op
,
6056 SBSS_SECTION_ASM_OP
);
6059 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6060 | SECTION_COMMON
, emit_tls_common
);
6061 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6062 | SECTION_COMMON
, emit_local
);
6063 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6064 | SECTION_COMMON
, emit_common
);
6066 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
6067 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
6071 targetm
.asm_out
.init_sections ();
6073 if (readonly_data_section
== NULL
)
6074 readonly_data_section
= text_section
;
6078 decl_default_tls_model (const_tree decl
)
6080 enum tls_model kind
;
6083 is_local
= targetm
.binds_local_p (decl
);
6087 kind
= TLS_MODEL_LOCAL_EXEC
;
6089 kind
= TLS_MODEL_INITIAL_EXEC
;
6092 /* Local dynamic is inefficient when we're not combining the
6093 parts of the address. */
6094 else if (optimize
&& is_local
)
6095 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6097 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6098 if (kind
< flag_tls_default
)
6099 kind
= flag_tls_default
;
6104 /* Select a set of attributes for section NAME based on the properties
6105 of DECL and whether or not RELOC indicates that DECL's initializer
6106 might contain runtime relocations.
6108 We make the section read-only and executable for a function decl,
6109 read-only for a const data decl, and writable for a non-const data decl. */
6112 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6116 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6117 flags
= SECTION_CODE
;
6118 else if (decl
&& decl_readonly_section (decl
, reloc
))
6120 else if (current_function_decl
6122 && crtl
->subsections
.unlikely_text_section_name
6123 && strcmp (name
, crtl
->subsections
.unlikely_text_section_name
) == 0)
6124 flags
= SECTION_CODE
;
6126 && (!current_function_decl
|| !cfun
)
6127 && strcmp (name
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6128 flags
= SECTION_CODE
;
6130 flags
= SECTION_WRITE
;
6132 if (decl
&& DECL_ONE_ONLY (decl
))
6133 flags
|= SECTION_LINKONCE
;
6135 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6136 flags
|= SECTION_TLS
| SECTION_WRITE
;
6138 if (strcmp (name
, ".bss") == 0
6139 || strncmp (name
, ".bss.", 5) == 0
6140 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6141 || strcmp (name
, ".sbss") == 0
6142 || strncmp (name
, ".sbss.", 6) == 0
6143 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6144 flags
|= SECTION_BSS
;
6146 if (strcmp (name
, ".tdata") == 0
6147 || strncmp (name
, ".tdata.", 7) == 0
6148 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6149 flags
|= SECTION_TLS
;
6151 if (strcmp (name
, ".tbss") == 0
6152 || strncmp (name
, ".tbss.", 6) == 0
6153 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6154 flags
|= SECTION_TLS
| SECTION_BSS
;
6156 /* These three sections have special ELF types. They are neither
6157 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6158 want to print a section type (@progbits or @nobits). If someone
6159 is silly enough to emit code or TLS variables to one of these
6160 sections, then don't handle them specially. */
6161 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
6162 && (strcmp (name
, ".init_array") == 0
6163 || strcmp (name
, ".fini_array") == 0
6164 || strcmp (name
, ".preinit_array") == 0))
6165 flags
|= SECTION_NOTYPE
;
6170 /* Return true if the target supports some form of global BSS,
6171 either through bss_noswitch_section, or by selecting a BSS
6172 section in TARGET_ASM_SELECT_SECTION. */
6175 have_global_bss_p (void)
6177 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6180 /* Output assembly to switch to section NAME with attribute FLAGS.
6181 Four variants for common object file formats. */
6184 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6185 unsigned int flags ATTRIBUTE_UNUSED
,
6186 tree decl ATTRIBUTE_UNUSED
)
6188 /* Some object formats don't support named sections at all. The
6189 front-end should already have flagged this as an error. */
6193 #ifndef TLS_SECTION_ASM_FLAG
6194 #define TLS_SECTION_ASM_FLAG 'T'
6198 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6199 tree decl ATTRIBUTE_UNUSED
)
6201 char flagchars
[10], *f
= flagchars
;
6203 /* If we have already declared this section, we can use an
6204 abbreviated form to switch back to it -- unless this section is
6205 part of a COMDAT groups, in which case GAS requires the full
6206 declaration every time. */
6207 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6208 && (flags
& SECTION_DECLARED
))
6210 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6214 if (!(flags
& SECTION_DEBUG
))
6216 if (flags
& SECTION_WRITE
)
6218 if (flags
& SECTION_CODE
)
6220 if (flags
& SECTION_SMALL
)
6222 if (flags
& SECTION_MERGE
)
6224 if (flags
& SECTION_STRINGS
)
6226 if (flags
& SECTION_TLS
)
6227 *f
++ = TLS_SECTION_ASM_FLAG
;
6228 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6232 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6234 if (!(flags
& SECTION_NOTYPE
))
6239 if (flags
& SECTION_BSS
)
6245 #ifdef ASM_COMMENT_START
6246 /* On platforms that use "@" as the assembly comment character,
6248 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6251 fprintf (asm_out_file
, format
, type
);
6253 if (flags
& SECTION_ENTSIZE
)
6254 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6255 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6257 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6258 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6260 fprintf (asm_out_file
, ",%s,comdat",
6261 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6265 putc ('\n', asm_out_file
);
6269 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6270 tree decl ATTRIBUTE_UNUSED
)
6272 char flagchars
[8], *f
= flagchars
;
6274 if (flags
& SECTION_WRITE
)
6276 if (flags
& SECTION_CODE
)
6280 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6284 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6287 default_coff_asm_named_section (name
, flags
, decl
);
6289 if (flags
& SECTION_LINKONCE
)
6291 /* Functions may have been compiled at various levels of
6292 optimization so we can't use `same_size' here.
6293 Instead, have the linker pick one. */
6294 fprintf (asm_out_file
, "\t.linkonce %s\n",
6295 (flags
& SECTION_CODE
? "discard" : "same_size"));
6299 /* The lame default section selector. */
6302 default_select_section (tree decl
, int reloc
,
6303 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6307 if (decl_readonly_section (decl
, reloc
))
6308 return readonly_data_section
;
6310 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6312 if (! ((flag_pic
&& reloc
)
6313 || !TREE_READONLY (decl
)
6314 || TREE_SIDE_EFFECTS (decl
)
6315 || !TREE_CONSTANT (decl
)))
6316 return readonly_data_section
;
6318 else if (TREE_CODE (decl
) == STRING_CST
)
6319 return readonly_data_section
;
6320 else if (! (flag_pic
&& reloc
))
6321 return readonly_data_section
;
6323 return data_section
;
6326 enum section_category
6327 categorize_decl_for_section (const_tree decl
, int reloc
)
6329 enum section_category ret
;
6331 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6333 else if (TREE_CODE (decl
) == STRING_CST
)
6335 if (flag_mudflap
) /* or !flag_merge_constants */
6336 return SECCAT_RODATA
;
6338 return SECCAT_RODATA_MERGE_STR
;
6340 else if (TREE_CODE (decl
) == VAR_DECL
)
6342 if (bss_initializer_p (decl
))
6344 else if (! TREE_READONLY (decl
)
6345 || TREE_SIDE_EFFECTS (decl
)
6346 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6348 /* Here the reloc_rw_mask is not testing whether the section should
6349 be read-only or not, but whether the dynamic link will have to
6350 do something. If so, we wish to segregate the data in order to
6351 minimize cache misses inside the dynamic linker. */
6352 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6353 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6357 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6358 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6359 else if (reloc
|| flag_merge_constants
< 2)
6360 /* C and C++ don't allow different variables to share the same
6361 location. -fmerge-all-constants allows even that (at the
6362 expense of not conforming). */
6363 ret
= SECCAT_RODATA
;
6364 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6365 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6367 ret
= SECCAT_RODATA_MERGE_CONST
;
6369 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6371 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6372 || TREE_SIDE_EFFECTS (decl
)
6373 || ! TREE_CONSTANT (decl
))
6376 ret
= SECCAT_RODATA
;
6379 ret
= SECCAT_RODATA
;
6381 /* There are no read-only thread-local sections. */
6382 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_TLS_MODEL (decl
))
6384 if (DECL_TLS_MODEL (decl
) == TLS_MODEL_EMULATED
)
6386 if (DECL_EMUTLS_VAR_P (decl
))
6388 if (targetm
.emutls
.var_section
)
6389 ret
= SECCAT_EMUTLS_VAR
;
6393 if (targetm
.emutls
.tmpl_prefix
)
6394 ret
= SECCAT_EMUTLS_TMPL
;
6397 /* Note that this would be *just* SECCAT_BSS, except that there's
6398 no concept of a read-only thread-local-data section. */
6399 else if (ret
== SECCAT_BSS
6400 || (flag_zero_initialized_in_bss
6401 && initializer_zerop (DECL_INITIAL (decl
))))
6407 /* If the target uses small data sections, select it. */
6408 else if (targetm
.in_small_data_p (decl
))
6410 if (ret
== SECCAT_BSS
)
6412 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6413 ret
= SECCAT_SRODATA
;
6422 decl_readonly_section (const_tree decl
, int reloc
)
6424 switch (categorize_decl_for_section (decl
, reloc
))
6427 case SECCAT_RODATA_MERGE_STR
:
6428 case SECCAT_RODATA_MERGE_STR_INIT
:
6429 case SECCAT_RODATA_MERGE_CONST
:
6430 case SECCAT_SRODATA
:
6439 /* Select a section based on the above categorization. */
6442 default_elf_select_section (tree decl
, int reloc
,
6443 unsigned HOST_WIDE_INT align
)
6446 switch (categorize_decl_for_section (decl
, reloc
))
6449 /* We're not supposed to be called on FUNCTION_DECLs. */
6452 return readonly_data_section
;
6453 case SECCAT_RODATA_MERGE_STR
:
6454 return mergeable_string_section (decl
, align
, 0);
6455 case SECCAT_RODATA_MERGE_STR_INIT
:
6456 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6457 case SECCAT_RODATA_MERGE_CONST
:
6458 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6459 case SECCAT_SRODATA
:
6463 return data_section
;
6464 case SECCAT_DATA_REL
:
6465 sname
= ".data.rel";
6467 case SECCAT_DATA_REL_LOCAL
:
6468 sname
= ".data.rel.local";
6470 case SECCAT_DATA_REL_RO
:
6471 sname
= ".data.rel.ro";
6473 case SECCAT_DATA_REL_RO_LOCAL
:
6474 sname
= ".data.rel.ro.local";
6493 case SECCAT_EMUTLS_VAR
:
6494 sname
= targetm
.emutls
.var_section
;
6496 case SECCAT_EMUTLS_TMPL
:
6497 sname
= targetm
.emutls
.tmpl_section
;
6505 return get_named_section (decl
, sname
, reloc
);
6508 /* Construct a unique section name based on the decl name and the
6509 categorization performed above. */
6512 default_unique_section (tree decl
, int reloc
)
6514 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6515 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6516 const char *prefix
, *name
, *linkonce
;
6519 switch (categorize_decl_for_section (decl
, reloc
))
6522 prefix
= one_only
? ".t" : ".text";
6525 case SECCAT_RODATA_MERGE_STR
:
6526 case SECCAT_RODATA_MERGE_STR_INIT
:
6527 case SECCAT_RODATA_MERGE_CONST
:
6528 prefix
= one_only
? ".r" : ".rodata";
6530 case SECCAT_SRODATA
:
6531 prefix
= one_only
? ".s2" : ".sdata2";
6534 prefix
= one_only
? ".d" : ".data";
6536 case SECCAT_DATA_REL
:
6537 prefix
= one_only
? ".d.rel" : ".data.rel";
6539 case SECCAT_DATA_REL_LOCAL
:
6540 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6542 case SECCAT_DATA_REL_RO
:
6543 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6545 case SECCAT_DATA_REL_RO_LOCAL
:
6546 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6549 prefix
= one_only
? ".s" : ".sdata";
6552 prefix
= one_only
? ".b" : ".bss";
6555 prefix
= one_only
? ".sb" : ".sbss";
6558 prefix
= one_only
? ".td" : ".tdata";
6561 prefix
= one_only
? ".tb" : ".tbss";
6563 case SECCAT_EMUTLS_VAR
:
6564 prefix
= targetm
.emutls
.var_section
;
6566 case SECCAT_EMUTLS_TMPL
:
6567 prefix
= targetm
.emutls
.tmpl_section
;
6573 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6574 name
= targetm
.strip_name_encoding (name
);
6576 /* If we're using one_only, then there needs to be a .gnu.linkonce
6577 prefix to the section name. */
6578 linkonce
= one_only
? ".gnu.linkonce" : "";
6580 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6582 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6585 /* Like compute_reloc_for_constant, except for an RTX. The return value
6586 is a mask for which bit 1 indicates a global relocation, and bit 0
6587 indicates a local relocation. */
6590 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6592 int *preloc
= (int *) data
;
6595 switch (GET_CODE (x
))
6598 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6611 compute_reloc_for_rtx (rtx x
)
6615 switch (GET_CODE (x
))
6621 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6630 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6632 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6634 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6635 return data_section
;
6637 return readonly_data_section
;
6641 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6642 unsigned HOST_WIDE_INT align
)
6644 int reloc
= compute_reloc_for_rtx (x
);
6646 /* ??? Handle small data here somehow. */
6648 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6651 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6653 return get_named_section (NULL
, ".data.rel.ro", 3);
6656 return mergeable_constant_section (mode
, align
, 0);
6659 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6662 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6667 /* Careful not to prod global register variables. */
6670 symbol
= XEXP (rtl
, 0);
6671 if (GET_CODE (symbol
) != SYMBOL_REF
)
6674 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6675 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6676 flags
|= SYMBOL_FLAG_FUNCTION
;
6677 if (targetm
.binds_local_p (decl
))
6678 flags
|= SYMBOL_FLAG_LOCAL
;
6679 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
)
6680 && DECL_TLS_MODEL (decl
) != TLS_MODEL_EMULATED
)
6681 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6682 else if (targetm
.in_small_data_p (decl
))
6683 flags
|= SYMBOL_FLAG_SMALL
;
6684 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6685 being PUBLIC, the thing *must* be defined in this translation unit.
6686 Prevent this buglet from being propagated into rtl code as well. */
6687 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6688 flags
|= SYMBOL_FLAG_EXTERNAL
;
6690 SYMBOL_REF_FLAGS (symbol
) = flags
;
6693 /* By default, we do nothing for encode_section_info, so we need not
6694 do anything but discard the '*' marker. */
6697 default_strip_name_encoding (const char *str
)
6699 return str
+ (*str
== '*');
6702 #ifdef ASM_OUTPUT_DEF
6703 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6704 anchor relative to ".", the current section position. */
6707 default_asm_output_anchor (rtx symbol
)
6711 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6712 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6713 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6717 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6720 default_use_anchors_for_symbol_p (const_rtx symbol
)
6725 /* Don't use anchors for mergeable sections. The linker might move
6726 the objects around. */
6727 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6728 if (sect
->common
.flags
& SECTION_MERGE
)
6731 /* Don't use anchors for small data sections. The small data register
6732 acts as an anchor for such sections. */
6733 if (sect
->common
.flags
& SECTION_SMALL
)
6736 decl
= SYMBOL_REF_DECL (symbol
);
6737 if (decl
&& DECL_P (decl
))
6739 /* Don't use section anchors for decls that might be defined by
6741 if (!targetm
.binds_local_p (decl
))
6744 /* Don't use section anchors for decls that will be placed in a
6745 small data section. */
6746 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6747 one above. The problem is that we only use SECTION_SMALL for
6748 sections that should be marked as small in the section directive. */
6749 if (targetm
.in_small_data_p (decl
))
6755 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6756 wrt cross-module name binding. */
6759 default_binds_local_p (const_tree exp
)
6761 return default_binds_local_p_1 (exp
, flag_shlib
);
6765 default_binds_local_p_1 (const_tree exp
, int shlib
)
6769 /* A non-decl is an entry in the constant pool. */
6772 /* Weakrefs may not bind locally, even though the weakref itself is
6773 always static and therefore local. */
6774 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
6776 /* Static variables are always local. */
6777 else if (! TREE_PUBLIC (exp
))
6779 /* A variable is local if the user has said explicitly that it will
6781 else if (DECL_VISIBILITY_SPECIFIED (exp
)
6782 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6784 /* Variables defined outside this object might not be local. */
6785 else if (DECL_EXTERNAL (exp
))
6787 /* If defined in this object and visibility is not default, must be
6789 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6791 /* Default visibility weak data can be overridden by a strong symbol
6792 in another module and so are not local. */
6793 else if (DECL_WEAK (exp
))
6795 /* If PIC, then assume that any global name can be overridden by
6796 symbols resolved from other modules, unless we are compiling with
6797 -fwhole-program, which assumes that names are local. */
6799 local_p
= flag_whole_program
;
6800 /* Uninitialized COMMON variable may be unified with symbols
6801 resolved from other modules. */
6802 else if (DECL_COMMON (exp
)
6803 && (DECL_INITIAL (exp
) == NULL
6804 || DECL_INITIAL (exp
) == error_mark_node
))
6806 /* Otherwise we're left with initialized (or non-common) global data
6807 which is of necessity defined locally. */
6814 /* Default function to output code that will globalize a label. A
6815 target must define GLOBAL_ASM_OP or provide its own function to
6816 globalize a label. */
6817 #ifdef GLOBAL_ASM_OP
6819 default_globalize_label (FILE * stream
, const char *name
)
6821 fputs (GLOBAL_ASM_OP
, stream
);
6822 assemble_name (stream
, name
);
6823 putc ('\n', stream
);
6825 #endif /* GLOBAL_ASM_OP */
6827 /* Default function to output code that will globalize a declaration. */
6829 default_globalize_decl_name (FILE * stream
, tree decl
)
6831 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6832 targetm
.asm_out
.globalize_label (stream
, name
);
6835 /* Default function to output a label for unwind information. The
6836 default is to do nothing. A target that needs nonlocal labels for
6837 unwind information must provide its own function to do this. */
6839 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6840 tree decl ATTRIBUTE_UNUSED
,
6841 int for_eh ATTRIBUTE_UNUSED
,
6842 int empty ATTRIBUTE_UNUSED
)
6846 /* Default function to output a label to divide up the exception table.
6847 The default is to do nothing. A target that needs/wants to divide
6848 up the table must provide it's own function to do this. */
6850 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6854 /* This is how to output an internal numbered label where PREFIX is
6855 the class of label and LABELNO is the number within the class. */
6858 default_internal_label (FILE *stream
, const char *prefix
,
6859 unsigned long labelno
)
6861 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6862 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6863 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6866 /* This is the default behavior at the beginning of a file. It's
6867 controlled by two other target-hook toggles. */
6869 default_file_start (void)
6871 if (targetm
.file_start_app_off
6872 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6873 fputs (ASM_APP_OFF
, asm_out_file
);
6875 if (targetm
.file_start_file_directive
)
6876 output_file_directive (asm_out_file
, main_input_filename
);
6879 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6880 which emits a special section directive used to indicate whether or
6881 not this object file needs an executable stack. This is primarily
6882 a GNU extension to ELF but could be used on other targets. */
6884 int trampolines_created
;
6887 file_end_indicate_exec_stack (void)
6889 unsigned int flags
= SECTION_DEBUG
;
6890 if (trampolines_created
)
6891 flags
|= SECTION_CODE
;
6893 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6896 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6897 a get_unnamed_section callback. */
6900 output_section_asm_op (const void *directive
)
6902 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
6905 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6906 the current section is NEW_SECTION. */
6909 switch_to_section (section
*new_section
)
6911 if (in_section
== new_section
)
6914 if (new_section
->common
.flags
& SECTION_FORGET
)
6917 in_section
= new_section
;
6919 switch (SECTION_STYLE (new_section
))
6923 && !crtl
->subsections
.unlikely_text_section_name
6924 && strcmp (new_section
->named
.name
,
6925 UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6926 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
6928 targetm
.asm_out
.named_section (new_section
->named
.name
,
6929 new_section
->named
.common
.flags
,
6930 new_section
->named
.decl
);
6933 case SECTION_UNNAMED
:
6934 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
6937 case SECTION_NOSWITCH
:
6942 new_section
->common
.flags
|= SECTION_DECLARED
;
6945 /* If block symbol SYMBOL has not yet been assigned an offset, place
6946 it at the end of its block. */
6949 place_block_symbol (rtx symbol
)
6951 unsigned HOST_WIDE_INT size
, mask
, offset
;
6952 struct constant_descriptor_rtx
*desc
;
6953 unsigned int alignment
;
6954 struct object_block
*block
;
6957 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
6958 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
6961 /* Work out the symbol's size and alignment. */
6962 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6964 desc
= SYMBOL_REF_CONSTANT (symbol
);
6965 alignment
= desc
->align
;
6966 size
= GET_MODE_SIZE (desc
->mode
);
6968 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6970 decl
= SYMBOL_REF_DECL (symbol
);
6971 alignment
= DECL_ALIGN (decl
);
6972 size
= get_constant_size (DECL_INITIAL (decl
));
6976 decl
= SYMBOL_REF_DECL (symbol
);
6977 alignment
= DECL_ALIGN (decl
);
6978 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
6981 /* Calculate the object's offset from the start of the block. */
6982 block
= SYMBOL_REF_BLOCK (symbol
);
6983 mask
= alignment
/ BITS_PER_UNIT
- 1;
6984 offset
= (block
->size
+ mask
) & ~mask
;
6985 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
6987 /* Record the block's new alignment and size. */
6988 block
->alignment
= MAX (block
->alignment
, alignment
);
6989 block
->size
= offset
+ size
;
6991 VEC_safe_push (rtx
, gc
, block
->objects
, symbol
);
6994 /* Return the anchor that should be used to address byte offset OFFSET
6995 from the first object in BLOCK. MODEL is the TLS model used
6999 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7000 enum tls_model model
)
7003 unsigned int begin
, middle
, end
;
7004 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7007 /* Work out the anchor's offset. Use an offset of 0 for the first
7008 anchor so that we don't pessimize the case where we take the address
7009 of a variable at the beginning of the block. This is particularly
7010 useful when a block has only one variable assigned to it.
7012 We try to place anchors RANGE bytes apart, so there can then be
7013 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7014 a ptr_mode offset. With some target settings, the lowest such
7015 anchor might be out of range for the lowest ptr_mode offset;
7016 likewise the highest anchor for the highest offset. Use anchors
7017 at the extreme ends of the ptr_mode range in such cases.
7019 All arithmetic uses unsigned integers in order to avoid
7021 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7022 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7023 range
= max_offset
- min_offset
+ 1;
7028 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
7031 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7032 delta
-= delta
% range
;
7035 offset
= (HOST_WIDE_INT
) (-delta
);
7039 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7040 delta
-= delta
% range
;
7041 if (delta
> bias
- 1)
7043 offset
= (HOST_WIDE_INT
) delta
;
7047 /* Do a binary search to see if there's already an anchor we can use.
7048 Set BEGIN to the new anchor's index if not. */
7050 end
= VEC_length (rtx
, block
->anchors
);
7051 while (begin
!= end
)
7053 middle
= (end
+ begin
) / 2;
7054 anchor
= VEC_index (rtx
, block
->anchors
, middle
);
7055 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7057 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7059 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7061 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7067 /* Create a new anchor with a unique label. */
7068 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7069 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7070 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7071 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7073 /* Insert it at index BEGIN. */
7074 VEC_safe_insert (rtx
, gc
, block
->anchors
, begin
, anchor
);
7078 /* Output the objects in BLOCK. */
7081 output_object_block (struct object_block
*block
)
7083 struct constant_descriptor_rtx
*desc
;
7085 HOST_WIDE_INT offset
;
7089 if (block
->objects
== NULL
)
7092 /* Switch to the section and make sure that the first byte is
7093 suitably aligned. */
7094 switch_to_section (block
->sect
);
7095 assemble_align (block
->alignment
);
7097 /* Define the values of all anchors relative to the current section
7099 for (i
= 0; VEC_iterate (rtx
, block
->anchors
, i
, symbol
); i
++)
7100 targetm
.asm_out
.output_anchor (symbol
);
7102 /* Output the objects themselves. */
7104 for (i
= 0; VEC_iterate (rtx
, block
->objects
, i
, symbol
); i
++)
7106 /* Move to the object's offset, padding with zeros if necessary. */
7107 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7108 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7109 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7111 desc
= SYMBOL_REF_CONSTANT (symbol
);
7112 output_constant_pool_1 (desc
, 1);
7113 offset
+= GET_MODE_SIZE (desc
->mode
);
7115 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7117 decl
= SYMBOL_REF_DECL (symbol
);
7118 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
7120 offset
+= get_constant_size (DECL_INITIAL (decl
));
7124 decl
= SYMBOL_REF_DECL (symbol
);
7125 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
7126 offset
+= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
7131 /* A htab_traverse callback used to call output_object_block for
7132 each member of object_block_htab. */
7135 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
7137 output_object_block ((struct object_block
*) (*slot
));
7141 /* Output the definitions of all object_blocks. */
7144 output_object_blocks (void)
7146 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
7149 /* This function provides a possible implementation of the
7150 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7151 by -frecord-gcc-switches it creates a new mergeable, string section in the
7152 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7153 contains the switches in ASCII format.
7155 FIXME: This code does not correctly handle double quote characters
7156 that appear inside strings, (it strips them rather than preserving them).
7157 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7158 characters - instead it treats them as sub-string separators. Since
7159 we want to emit NUL strings terminators into the object file we have to use
7163 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7165 static char buffer
[1024];
7167 /* This variable is used as part of a simplistic heuristic to detect
7168 command line switches which take an argument:
7170 "If a command line option does not start with a dash then
7171 it is an argument for the previous command line option."
7173 This fails in the case of the command line option which is the name
7174 of the file to compile, but otherwise it is pretty reasonable. */
7175 static bool previous_name_held_back
= FALSE
;
7179 case SWITCH_TYPE_PASSED
:
7182 if (previous_name_held_back
)
7184 unsigned int len
= strlen (buffer
);
7186 snprintf (buffer
+ len
, sizeof buffer
- len
, " %s", name
);
7187 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7188 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7189 previous_name_held_back
= FALSE
;
7193 strncpy (buffer
, name
, sizeof buffer
);
7194 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7195 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7200 if (previous_name_held_back
)
7202 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7203 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7206 strncpy (buffer
, name
, sizeof buffer
);
7207 previous_name_held_back
= TRUE
;
7211 case SWITCH_TYPE_DESCRIPTIVE
:
7214 /* Distinguish between invocations where name is NULL. */
7215 static bool started
= false;
7219 if (previous_name_held_back
)
7221 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7222 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7229 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7233 | (SECTION_ENTSIZE
& 1),
7235 switch_to_section (sec
);
7244 /* The return value is currently ignored by the caller, but must be 0.
7245 For -fverbose-asm the return value would be the number of characters
7246 emitted into the assembler file. */
7250 /* Emit text to declare externally defined symbols. It is needed to
7251 properly support non-default visibility. */
7253 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7255 const char *name ATTRIBUTE_UNUSED
)
7257 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7258 set in order to avoid putting out names that are never really
7260 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7261 && targetm
.binds_local_p (decl
))
7262 maybe_assemble_visibility (decl
);
7265 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7268 make_debug_expr_from_rtl (const_rtx exp
)
7270 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7271 enum machine_mode mode
= GET_MODE (exp
);
7274 DECL_ARTIFICIAL (ddecl
) = 1;
7275 if (REG_P (exp
) && REG_EXPR (exp
))
7276 type
= TREE_TYPE (REG_EXPR (exp
));
7277 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7278 type
= TREE_TYPE (MEM_EXPR (exp
));
7281 if (type
&& TYPE_MODE (type
) == mode
)
7282 TREE_TYPE (ddecl
) = type
;
7284 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7285 DECL_MODE (ddecl
) = mode
;
7286 dval
= gen_rtx_DEBUG_EXPR (mode
);
7287 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7288 SET_DECL_RTL (ddecl
, dval
);
7292 #include "gt-varasm.h"