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 #ifndef IN_NAMED_SECTION
174 #define IN_NAMED_SECTION(DECL) \
175 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
176 && DECL_SECTION_NAME (DECL) != NULL_TREE)
179 /* Hash table of named sections. */
180 static GTY((param_is (section
))) htab_t section_htab
;
182 /* A table of object_blocks, indexed by section. */
183 static GTY((param_is (struct object_block
))) htab_t object_block_htab
;
185 /* The next number to use for internal anchor labels. */
186 static GTY(()) int anchor_labelno
;
188 /* A pool of constants that can be shared between functions. */
189 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
193 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
195 static GTY (()) tree emutls_object_type
;
196 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
197 macro can be used on them to distinguish the control variable from
198 the initialization template. */
199 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
201 #if !defined (NO_DOT_IN_LABEL)
202 # define EMUTLS_SEPARATOR "."
203 #elif !defined (NO_DOLLAR_IN_LABEL)
204 # define EMUTLS_SEPARATOR "$"
206 # define EMUTLS_SEPARATOR "_"
209 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
210 IDENTIFIER_NODE NAME's name. */
213 prefix_name (const char *prefix
, tree name
)
215 unsigned plen
= strlen (prefix
);
216 unsigned nlen
= strlen (IDENTIFIER_POINTER (name
));
217 char *toname
= (char *) alloca (plen
+ nlen
+ 1);
219 memcpy (toname
, prefix
, plen
);
220 memcpy (toname
+ plen
, IDENTIFIER_POINTER (name
), nlen
+ 1);
222 return get_identifier (toname
);
225 /* Create an identifier for the struct __emutls_object, given an identifier
226 of the DECL_ASSEMBLY_NAME of the original object. */
229 get_emutls_object_name (tree name
)
231 const char *prefix
= (targetm
.emutls
.var_prefix
232 ? targetm
.emutls
.var_prefix
233 : "__emutls_v" EMUTLS_SEPARATOR
);
234 return prefix_name (prefix
, name
);
238 default_emutls_var_fields (tree type
, tree
*name ATTRIBUTE_UNUSED
)
240 tree word_type_node
, field
, next_field
;
242 field
= build_decl (UNKNOWN_LOCATION
,
243 FIELD_DECL
, get_identifier ("__templ"), ptr_type_node
);
244 DECL_CONTEXT (field
) = type
;
247 field
= build_decl (UNKNOWN_LOCATION
,
248 FIELD_DECL
, get_identifier ("__offset"),
250 DECL_CONTEXT (field
) = type
;
251 TREE_CHAIN (field
) = next_field
;
254 word_type_node
= lang_hooks
.types
.type_for_mode (word_mode
, 1);
255 field
= build_decl (UNKNOWN_LOCATION
,
256 FIELD_DECL
, get_identifier ("__align"),
258 DECL_CONTEXT (field
) = type
;
259 TREE_CHAIN (field
) = next_field
;
262 field
= build_decl (UNKNOWN_LOCATION
,
263 FIELD_DECL
, get_identifier ("__size"), word_type_node
);
264 DECL_CONTEXT (field
) = type
;
265 TREE_CHAIN (field
) = next_field
;
270 /* Create the structure for struct __emutls_object. This should match the
271 structure at the top of emutls.c, modulo the union there. */
274 get_emutls_object_type (void)
276 tree type
, type_name
, field
;
278 type
= emutls_object_type
;
282 emutls_object_type
= type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
284 field
= targetm
.emutls
.var_fields (type
, &type_name
);
286 type_name
= get_identifier ("__emutls_object");
287 type_name
= build_decl (UNKNOWN_LOCATION
,
288 TYPE_DECL
, type_name
, type
);
289 TYPE_NAME (type
) = type_name
;
290 TYPE_FIELDS (type
) = field
;
296 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
297 This will be used for initializing the emulated tls data area. */
300 get_emutls_init_templ_addr (tree decl
)
304 if (targetm
.emutls
.register_common
&& !DECL_INITIAL (decl
)
305 && !DECL_SECTION_NAME (decl
))
306 return null_pointer_node
;
308 name
= DECL_ASSEMBLER_NAME (decl
);
309 if (!targetm
.emutls
.tmpl_prefix
|| targetm
.emutls
.tmpl_prefix
[0])
311 const char *prefix
= (targetm
.emutls
.tmpl_prefix
312 ? targetm
.emutls
.tmpl_prefix
313 : "__emutls_t" EMUTLS_SEPARATOR
);
314 name
= prefix_name (prefix
, name
);
317 to
= build_decl (DECL_SOURCE_LOCATION (decl
),
318 VAR_DECL
, name
, TREE_TYPE (decl
));
319 SET_DECL_ASSEMBLER_NAME (to
, DECL_NAME (to
));
320 DECL_TLS_MODEL (to
) = TLS_MODEL_EMULATED
;
321 DECL_ARTIFICIAL (to
) = 1;
322 TREE_USED (to
) = TREE_USED (decl
);
323 TREE_READONLY (to
) = 1;
324 DECL_IGNORED_P (to
) = 1;
325 DECL_CONTEXT (to
) = DECL_CONTEXT (decl
);
326 DECL_SECTION_NAME (to
) = DECL_SECTION_NAME (decl
);
328 DECL_WEAK (to
) = DECL_WEAK (decl
);
329 if (DECL_ONE_ONLY (decl
))
331 make_decl_one_only (to
, DECL_ASSEMBLER_NAME (to
));
332 TREE_STATIC (to
) = TREE_STATIC (decl
);
333 TREE_PUBLIC (to
) = TREE_PUBLIC (decl
);
334 DECL_VISIBILITY (to
) = DECL_VISIBILITY (decl
);
337 TREE_STATIC (to
) = 1;
339 DECL_INITIAL (to
) = DECL_INITIAL (decl
);
340 DECL_INITIAL (decl
) = NULL
;
342 varpool_finalize_decl (to
);
343 return build_fold_addr_expr (to
);
346 /* When emulating tls, we use a control structure for use by the runtime.
347 Create and return this structure. */
350 emutls_decl (tree decl
)
353 struct tree_map
*h
, in
;
356 if (targetm
.have_tls
|| decl
== NULL
|| decl
== error_mark_node
357 || TREE_CODE (decl
) != VAR_DECL
|| ! DECL_THREAD_LOCAL_P (decl
))
360 /* Look up the object in the hash; return the control structure if
361 it has already been created. */
363 emutls_htab
= htab_create_ggc (512, tree_map_hash
, tree_map_eq
, 0);
365 name
= DECL_ASSEMBLER_NAME (decl
);
367 /* Note that we use the hash of the decl's name, rather than a hash
368 of the decl's pointer. In emutls_finish we iterate through the
369 hash table, and we want this traversal to be predictable. */
370 in
.hash
= htab_hash_string (IDENTIFIER_POINTER (name
));
372 loc
= htab_find_slot_with_hash (emutls_htab
, &in
, in
.hash
, INSERT
);
373 h
= (struct tree_map
*) *loc
;
378 to
= build_decl (DECL_SOURCE_LOCATION (decl
),
379 VAR_DECL
, get_emutls_object_name (name
),
380 get_emutls_object_type ());
382 h
= GGC_NEW (struct tree_map
);
386 *(struct tree_map
**) loc
= h
;
388 DECL_TLS_MODEL (to
) = TLS_MODEL_EMULATED
;
389 DECL_ARTIFICIAL (to
) = 1;
390 DECL_IGNORED_P (to
) = 1;
391 TREE_READONLY (to
) = 0;
392 SET_DECL_ASSEMBLER_NAME (to
, DECL_NAME (to
));
393 if (DECL_ONE_ONLY (decl
))
394 make_decl_one_only (to
, DECL_ASSEMBLER_NAME (to
));
395 DECL_CONTEXT (to
) = DECL_CONTEXT (decl
);
396 if (targetm
.emutls
.var_align_fixed
)
397 /* If we're not allowed to change the proxy object's
398 alignment, pretend it's been set by the user. */
399 DECL_USER_ALIGN (to
) = 1;
402 /* Note that these fields may need to be updated from time to time from
403 the original decl. Consider:
404 extern __thread int i;
405 int foo() { return i; }
407 in which I goes from external to locally defined and initialized. */
409 TREE_STATIC (to
) = TREE_STATIC (decl
);
410 TREE_USED (to
) = TREE_USED (decl
);
411 TREE_PUBLIC (to
) = TREE_PUBLIC (decl
);
412 DECL_EXTERNAL (to
) = DECL_EXTERNAL (decl
);
413 DECL_COMMON (to
) = DECL_COMMON (decl
);
414 DECL_WEAK (to
) = DECL_WEAK (decl
);
415 DECL_VISIBILITY (to
) = DECL_VISIBILITY (decl
);
421 emutls_common_1 (void **loc
, void *xstmts
)
423 struct tree_map
*h
= *(struct tree_map
**) loc
;
424 tree args
, x
, *pstmts
= (tree
*) xstmts
;
427 if (! DECL_COMMON (h
->base
.from
)
428 || (DECL_INITIAL (h
->base
.from
)
429 && DECL_INITIAL (h
->base
.from
) != error_mark_node
))
432 word_type_node
= lang_hooks
.types
.type_for_mode (word_mode
, 1);
434 /* The idea was to call get_emutls_init_templ_addr here, but if we
435 do this and there is an initializer, -fanchor_section loses,
436 because it would be too late to ensure the template is
438 x
= null_pointer_node
;
439 args
= tree_cons (NULL
, x
, NULL
);
440 x
= build_int_cst (word_type_node
, DECL_ALIGN_UNIT (h
->base
.from
));
441 args
= tree_cons (NULL
, x
, args
);
442 x
= fold_convert (word_type_node
, DECL_SIZE_UNIT (h
->base
.from
));
443 args
= tree_cons (NULL
, x
, args
);
444 x
= build_fold_addr_expr (h
->to
);
445 args
= tree_cons (NULL
, x
, args
);
447 x
= built_in_decls
[BUILT_IN_EMUTLS_REGISTER_COMMON
];
448 x
= build_function_call_expr (UNKNOWN_LOCATION
, x
, args
);
450 append_to_statement_list (x
, pstmts
);
457 if (targetm
.emutls
.register_common
)
459 tree body
= NULL_TREE
;
461 if (emutls_htab
== NULL
)
464 htab_traverse_noresize (emutls_htab
, emutls_common_1
, &body
);
465 if (body
== NULL_TREE
)
468 cgraph_build_static_cdtor ('I', body
, DEFAULT_INIT_PRIORITY
);
472 /* Helper routines for maintaining section_htab. */
475 section_entry_eq (const void *p1
, const void *p2
)
477 const section
*old
= (const section
*) p1
;
478 const char *new_name
= (const char *) p2
;
480 return strcmp (old
->named
.name
, new_name
) == 0;
484 section_entry_hash (const void *p
)
486 const section
*old
= (const section
*) p
;
487 return htab_hash_string (old
->named
.name
);
490 /* Return a hash value for section SECT. */
493 hash_section (section
*sect
)
495 if (sect
->common
.flags
& SECTION_NAMED
)
496 return htab_hash_string (sect
->named
.name
);
497 return sect
->common
.flags
;
500 /* Helper routines for maintaining object_block_htab. */
503 object_block_entry_eq (const void *p1
, const void *p2
)
505 const struct object_block
*old
= (const struct object_block
*) p1
;
506 const section
*new_section
= (const section
*) p2
;
508 return old
->sect
== new_section
;
512 object_block_entry_hash (const void *p
)
514 const struct object_block
*old
= (const struct object_block
*) p
;
515 return hash_section (old
->sect
);
518 /* Return a new unnamed section with the given fields. */
521 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
526 sect
= GGC_NEW (section
);
527 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
528 sect
->unnamed
.callback
= callback
;
529 sect
->unnamed
.data
= data
;
530 sect
->unnamed
.next
= unnamed_sections
;
532 unnamed_sections
= sect
;
536 /* Return a SECTION_NOSWITCH section with the given fields. */
539 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
543 sect
= GGC_NEW (section
);
544 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
545 sect
->noswitch
.callback
= callback
;
550 /* Return the named section structure associated with NAME. Create
551 a new section with the given fields if no such structure exists. */
554 get_section (const char *name
, unsigned int flags
, tree decl
)
556 section
*sect
, **slot
;
559 htab_find_slot_with_hash (section_htab
, name
,
560 htab_hash_string (name
), INSERT
);
561 flags
|= SECTION_NAMED
;
564 sect
= GGC_NEW (section
);
565 sect
->named
.common
.flags
= flags
;
566 sect
->named
.name
= ggc_strdup (name
);
567 sect
->named
.decl
= decl
;
573 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
574 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
576 /* Sanity check user variables for flag changes. */
578 decl
= sect
->named
.decl
;
580 error ("%+D causes a section type conflict", decl
);
586 /* Return true if the current compilation mode benefits from having
587 objects grouped into blocks. */
590 use_object_blocks_p (void)
592 return flag_section_anchors
;
595 /* Return the object_block structure for section SECT. Create a new
596 structure if we haven't created one already. Return null if SECT
599 static struct object_block
*
600 get_block_for_section (section
*sect
)
602 struct object_block
*block
;
608 slot
= htab_find_slot_with_hash (object_block_htab
, sect
,
609 hash_section (sect
), INSERT
);
610 block
= (struct object_block
*) *slot
;
613 block
= (struct object_block
*)
614 ggc_alloc_cleared (sizeof (struct object_block
));
621 /* Create a symbol with label LABEL and place it at byte offset
622 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
623 is not yet known. LABEL must be a garbage-collected string. */
626 create_block_symbol (const char *label
, struct object_block
*block
,
627 HOST_WIDE_INT offset
)
632 /* Create the extended SYMBOL_REF. */
633 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
634 symbol
= (rtx
) ggc_alloc_zone (size
, &rtl_zone
);
636 /* Initialize the normal SYMBOL_REF fields. */
637 memset (symbol
, 0, size
);
638 PUT_CODE (symbol
, SYMBOL_REF
);
639 PUT_MODE (symbol
, Pmode
);
640 XSTR (symbol
, 0) = label
;
641 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
643 /* Initialize the block_symbol stuff. */
644 SYMBOL_REF_BLOCK (symbol
) = block
;
645 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
651 initialize_cold_section_name (void)
653 const char *stripped_name
;
657 gcc_assert (cfun
&& current_function_decl
);
658 if (crtl
->subsections
.unlikely_text_section_name
)
661 dsn
= DECL_SECTION_NAME (current_function_decl
);
662 if (flag_function_sections
&& dsn
)
664 name
= (char *) alloca (TREE_STRING_LENGTH (dsn
) + 1);
665 memcpy (name
, TREE_STRING_POINTER (dsn
), TREE_STRING_LENGTH (dsn
) + 1);
667 stripped_name
= targetm
.strip_name_encoding (name
);
669 buffer
= ACONCAT ((stripped_name
, "_unlikely", NULL
));
670 crtl
->subsections
.unlikely_text_section_name
= ggc_strdup (buffer
);
673 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
676 /* Tell assembler to switch to unlikely-to-be-executed text section. */
679 unlikely_text_section (void)
683 if (!crtl
->subsections
.unlikely_text_section_name
)
684 initialize_cold_section_name ();
686 return get_named_section (NULL
, crtl
->subsections
.unlikely_text_section_name
, 0);
689 return get_named_section (NULL
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
, 0);
692 /* When called within a function context, return true if the function
693 has been assigned a cold text section and if SECT is that section.
694 When called outside a function context, return true if SECT is the
695 default cold section. */
698 unlikely_text_section_p (section
*sect
)
703 name
= crtl
->subsections
.unlikely_text_section_name
;
705 name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
709 && SECTION_STYLE (sect
) == SECTION_NAMED
710 && strcmp (name
, sect
->named
.name
) == 0);
713 /* Return a section with a particular name and with whatever SECTION_*
714 flags section_type_flags deems appropriate. The name of the section
715 is taken from NAME if nonnull, otherwise it is taken from DECL's
716 DECL_SECTION_NAME. DECL is the decl associated with the section
717 (see the section comment for details) and RELOC is as for
718 section_type_flags. */
721 get_named_section (tree decl
, const char *name
, int reloc
)
725 gcc_assert (!decl
|| DECL_P (decl
));
727 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
729 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
731 return get_section (name
, flags
, decl
);
734 /* If required, set DECL_SECTION_NAME to a unique name. */
737 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
738 int flag_function_or_data_sections
)
740 if (DECL_SECTION_NAME (decl
) == NULL_TREE
741 && targetm
.have_named_sections
742 && (flag_function_or_data_sections
743 || DECL_ONE_ONLY (decl
)))
744 targetm
.asm_out
.unique_section (decl
, reloc
);
747 #ifdef BSS_SECTION_ASM_OP
749 #ifdef ASM_OUTPUT_BSS
751 /* Utility function for ASM_OUTPUT_BSS for targets to use if
752 they don't support alignments in .bss.
753 ??? It is believed that this function will work in most cases so such
754 support is localized here. */
757 asm_output_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
759 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
760 unsigned HOST_WIDE_INT rounded
)
762 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl
), 0), 0), name
) == 0);
763 targetm
.asm_out
.globalize_decl_name (file
, decl
);
764 switch_to_section (bss_section
);
765 #ifdef ASM_DECLARE_OBJECT_NAME
766 last_assemble_variable_decl
= decl
;
767 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
769 /* Standard thing is just output label for the object. */
770 ASM_OUTPUT_LABEL (file
, name
);
771 #endif /* ASM_DECLARE_OBJECT_NAME */
772 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
777 #ifdef ASM_OUTPUT_ALIGNED_BSS
779 /* Utility function for targets to use in implementing
780 ASM_OUTPUT_ALIGNED_BSS.
781 ??? It is believed that this function will work in most cases so such
782 support is localized here. */
785 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
786 const char *name
, unsigned HOST_WIDE_INT size
,
789 switch_to_section (bss_section
);
790 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
791 #ifdef ASM_DECLARE_OBJECT_NAME
792 last_assemble_variable_decl
= decl
;
793 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
795 /* Standard thing is just output label for the object. */
796 ASM_OUTPUT_LABEL (file
, name
);
797 #endif /* ASM_DECLARE_OBJECT_NAME */
798 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
803 #endif /* BSS_SECTION_ASM_OP */
805 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
806 /* Return the hot section for function DECL. Return text_section for
810 hot_function_section (tree decl
)
812 if (decl
!= NULL_TREE
813 && DECL_SECTION_NAME (decl
) != NULL_TREE
814 && targetm
.have_named_sections
)
815 return get_named_section (decl
, NULL
, 0);
821 /* Return the section for function DECL.
823 If DECL is NULL_TREE, return the text section. We can be passed
824 NULL_TREE under some circumstances by dbxout.c at least. */
827 function_section (tree decl
)
831 if (first_function_block_is_cold
)
834 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
835 if (decl
!= NULL_TREE
836 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
837 return reloc
? unlikely_text_section ()
838 : get_named_section (decl
, NULL
, 0);
840 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
842 return reloc
? unlikely_text_section () : hot_function_section (decl
);
847 current_function_section (void)
849 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
850 if (current_function_decl
!= NULL_TREE
851 && DECL_SECTION_NAME (current_function_decl
) != NULL_TREE
)
852 return in_cold_section_p
? unlikely_text_section ()
853 : get_named_section (current_function_decl
,
856 return targetm
.asm_out
.select_section (current_function_decl
,
858 DECL_ALIGN (current_function_decl
));
860 return (in_cold_section_p
861 ? unlikely_text_section ()
862 : hot_function_section (current_function_decl
));
866 /* Return the read-only data section associated with function DECL. */
869 default_function_rodata_section (tree decl
)
871 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
873 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
875 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
881 dot
= strchr (name
+ 1, '.');
884 len
= strlen (dot
) + 8;
885 rname
= (char *) alloca (len
);
887 strcpy (rname
, ".rodata");
889 return get_section (rname
, SECTION_LINKONCE
, decl
);
891 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
892 else if (DECL_ONE_ONLY (decl
)
893 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
895 size_t len
= strlen (name
) + 1;
896 char *rname
= (char *) alloca (len
);
898 memcpy (rname
, name
, len
);
900 return get_section (rname
, SECTION_LINKONCE
, decl
);
902 /* For .text.foo we want to use .rodata.foo. */
903 else if (flag_function_sections
&& flag_data_sections
904 && strncmp (name
, ".text.", 6) == 0)
906 size_t len
= strlen (name
) + 1;
907 char *rname
= (char *) alloca (len
+ 2);
909 memcpy (rname
, ".rodata", 7);
910 memcpy (rname
+ 7, name
+ 5, len
- 5);
911 return get_section (rname
, 0, decl
);
915 return readonly_data_section
;
918 /* Return the read-only data section associated with function DECL
919 for targets where that section should be always the single
920 readonly data section. */
923 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
925 return readonly_data_section
;
928 /* Return the section to use for string merging. */
931 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
932 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
933 unsigned int flags ATTRIBUTE_UNUSED
)
937 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
938 && TREE_CODE (decl
) == STRING_CST
939 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
941 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
942 && TREE_STRING_LENGTH (decl
) >= len
)
944 enum machine_mode mode
;
945 unsigned int modesize
;
951 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
952 modesize
= GET_MODE_BITSIZE (mode
);
953 if (modesize
>= 8 && modesize
<= 256
954 && (modesize
& (modesize
- 1)) == 0)
956 if (align
< modesize
)
959 str
= TREE_STRING_POINTER (decl
);
960 unit
= GET_MODE_SIZE (mode
);
962 /* Check for embedded NUL characters. */
963 for (i
= 0; i
< len
; i
+= unit
)
965 for (j
= 0; j
< unit
; j
++)
966 if (str
[i
+ j
] != '\0')
973 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
975 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
976 return get_section (name
, flags
, NULL
);
981 return readonly_data_section
;
984 /* Return the section to use for constant merging. */
987 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
988 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
989 unsigned int flags ATTRIBUTE_UNUSED
)
991 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
993 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
999 && (align
& (align
- 1)) == 0)
1003 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
1004 flags
|= (align
/ 8) | SECTION_MERGE
;
1005 return get_section (name
, flags
, NULL
);
1007 return readonly_data_section
;
1010 /* Given NAME, a putative register name, discard any customary prefixes. */
1013 strip_reg_name (const char *name
)
1015 #ifdef REGISTER_PREFIX
1016 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
1017 name
+= strlen (REGISTER_PREFIX
);
1019 if (name
[0] == '%' || name
[0] == '#')
1024 /* The user has asked for a DECL to have a particular name. Set (or
1025 change) it in such a way that we don't prefix an underscore to
1028 set_user_assembler_name (tree decl
, const char *name
)
1030 char *starred
= (char *) alloca (strlen (name
) + 2);
1032 strcpy (starred
+ 1, name
);
1033 change_decl_assembler_name (decl
, get_identifier (starred
));
1034 SET_DECL_RTL (decl
, NULL_RTX
);
1037 /* Decode an `asm' spec for a declaration as a register name.
1038 Return the register number, or -1 if nothing specified,
1039 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1040 or -3 if ASMSPEC is `cc' and is not recognized,
1041 or -4 if ASMSPEC is `memory' and is not recognized.
1042 Accept an exact spelling or a decimal number.
1043 Prefixes such as % are optional. */
1046 decode_reg_name (const char *asmspec
)
1052 /* Get rid of confusing prefixes. */
1053 asmspec
= strip_reg_name (asmspec
);
1055 /* Allow a decimal number as a "register name". */
1056 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
1057 if (! ISDIGIT (asmspec
[i
]))
1059 if (asmspec
[0] != 0 && i
< 0)
1062 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
1068 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1070 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
1073 #ifdef ADDITIONAL_REGISTER_NAMES
1075 static const struct { const char *const name
; const int number
; } table
[]
1076 = ADDITIONAL_REGISTER_NAMES
;
1078 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
1079 if (table
[i
].name
[0]
1080 && ! strcmp (asmspec
, table
[i
].name
))
1081 return table
[i
].number
;
1083 #endif /* ADDITIONAL_REGISTER_NAMES */
1085 if (!strcmp (asmspec
, "memory"))
1088 if (!strcmp (asmspec
, "cc"))
1097 /* Return true if DECL's initializer is suitable for a BSS section. */
1100 bss_initializer_p (const_tree decl
)
1102 return (DECL_INITIAL (decl
) == NULL
1103 || DECL_INITIAL (decl
) == error_mark_node
1104 || (flag_zero_initialized_in_bss
1105 /* Leave constant zeroes in .rodata so they
1107 && !TREE_READONLY (decl
)
1108 && initializer_zerop (DECL_INITIAL (decl
))));
1111 /* Compute the alignment of variable specified by DECL.
1112 DONT_OUTPUT_DATA is from assemble_variable. */
1115 align_variable (tree decl
, bool dont_output_data
)
1117 unsigned int align
= DECL_ALIGN (decl
);
1119 /* In the case for initialing an array whose length isn't specified,
1120 where we have not yet been able to do the layout,
1121 figure out the proper alignment now. */
1122 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1123 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1124 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1126 /* Some object file formats have a maximum alignment which they support.
1127 In particular, a.out format supports a maximum alignment of 4. */
1128 if (align
> MAX_OFILE_ALIGNMENT
)
1130 warning (0, "alignment of %q+D is greater than maximum object "
1131 "file alignment. Using %d", decl
,
1132 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1133 align
= MAX_OFILE_ALIGNMENT
;
1136 /* On some machines, it is good to increase alignment sometimes. */
1137 if (! DECL_USER_ALIGN (decl
))
1139 #ifdef DATA_ALIGNMENT
1140 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1141 /* Don't increase alignment too much for TLS variables - TLS space
1143 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1146 #ifdef CONSTANT_ALIGNMENT
1147 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1149 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
1151 /* Don't increase alignment too much for TLS variables - TLS space
1153 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1154 align
= const_align
;
1159 /* Reset the alignment in case we have made it tighter, so we can benefit
1160 from it in get_pointer_alignment. */
1161 DECL_ALIGN (decl
) = align
;
1164 /* Return the section into which the given VAR_DECL or CONST_DECL
1165 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1166 section should be used wherever possible. */
1169 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1171 addr_space_t as
= ADDR_SPACE_GENERIC
;
1174 if (TREE_TYPE (decl
) != error_mark_node
)
1175 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1177 if (DECL_COMMON (decl
))
1179 /* If the decl has been given an explicit section name, or it resides
1180 in a non-generic address space, then it isn't common, and shouldn't
1181 be handled as such. */
1182 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1183 && ADDR_SPACE_GENERIC_P (as
));
1184 if (DECL_THREAD_LOCAL_P (decl
))
1185 return tls_comm_section
;
1186 /* This cannot be common bss for an emulated TLS object without
1187 a register_common hook. */
1188 else if (DECL_TLS_MODEL (decl
) == TLS_MODEL_EMULATED
1189 && !targetm
.emutls
.register_common
)
1191 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1192 return comm_section
;
1195 if (DECL_INITIAL (decl
) == error_mark_node
)
1196 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1197 else if (DECL_INITIAL (decl
))
1198 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1202 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1203 if (IN_NAMED_SECTION (decl
))
1204 return get_named_section (decl
, NULL
, reloc
);
1206 if (ADDR_SPACE_GENERIC_P (as
)
1207 && !DECL_THREAD_LOCAL_P (decl
)
1208 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1209 && bss_initializer_p (decl
))
1211 if (!TREE_PUBLIC (decl
))
1212 return lcomm_section
;
1213 if (bss_noswitch_section
)
1214 return bss_noswitch_section
;
1217 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
1220 /* Return the block into which object_block DECL should be placed. */
1222 static struct object_block
*
1223 get_block_for_decl (tree decl
)
1227 if (TREE_CODE (decl
) == VAR_DECL
)
1229 /* The object must be defined in this translation unit. */
1230 if (DECL_EXTERNAL (decl
))
1233 /* There's no point using object blocks for something that is
1234 isolated by definition. */
1235 if (DECL_ONE_ONLY (decl
))
1239 /* We can only calculate block offsets if the decl has a known
1241 if (DECL_SIZE_UNIT (decl
) == NULL
)
1243 if (!host_integerp (DECL_SIZE_UNIT (decl
), 1))
1246 /* Find out which section should contain DECL. We cannot put it into
1247 an object block if it requires a standalone definition. */
1248 if (TREE_CODE (decl
) == VAR_DECL
)
1249 align_variable (decl
, 0);
1250 sect
= get_variable_section (decl
, true);
1251 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1254 return get_block_for_section (sect
);
1257 /* Make sure block symbol SYMBOL is in block BLOCK. */
1260 change_symbol_block (rtx symbol
, struct object_block
*block
)
1262 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1264 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1265 SYMBOL_REF_BLOCK (symbol
) = block
;
1269 /* Return true if it is possible to put DECL in an object_block. */
1272 use_blocks_for_decl_p (tree decl
)
1274 /* Only data DECLs can be placed into object blocks. */
1275 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
1278 /* Detect decls created by dw2_force_const_mem. Such decls are
1279 special because DECL_INITIAL doesn't specify the decl's true value.
1280 dw2_output_indirect_constants will instead call assemble_variable
1281 with dont_output_data set to 1 and then print the contents itself. */
1282 if (DECL_INITIAL (decl
) == decl
)
1285 /* If this decl is an alias, then we don't want to emit a definition. */
1286 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl
)))
1292 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1293 have static storage duration. In other words, it should not be an
1294 automatic variable, including PARM_DECLs.
1296 There is, however, one exception: this function handles variables
1297 explicitly placed in a particular register by the user.
1299 This is never called for PARM_DECL nodes. */
1302 make_decl_rtl (tree decl
)
1304 const char *name
= 0;
1308 /* Check that we are not being given an automatic variable. */
1309 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1310 && TREE_CODE (decl
) != RESULT_DECL
);
1312 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1313 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1314 || TREE_STATIC (decl
)
1315 || TREE_PUBLIC (decl
)
1316 || DECL_EXTERNAL (decl
)
1317 || DECL_REGISTER (decl
));
1319 /* And that we were not given a type or a label. */
1320 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1321 && TREE_CODE (decl
) != LABEL_DECL
);
1323 /* For a duplicate declaration, we can be called twice on the
1324 same DECL node. Don't discard the RTL already made. */
1325 if (DECL_RTL_SET_P (decl
))
1327 /* If the old RTL had the wrong mode, fix the mode. */
1328 x
= DECL_RTL (decl
);
1329 if (GET_MODE (x
) != DECL_MODE (decl
))
1330 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1332 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1335 /* ??? Another way to do this would be to maintain a hashed
1336 table of such critters. Instead of adding stuff to a DECL
1337 to give certain attributes to it, we could use an external
1338 hash map from DECL to set of attributes. */
1340 /* Let the target reassign the RTL if it wants.
1341 This is necessary, for example, when one machine specific
1342 decl attribute overrides another. */
1343 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1345 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1346 on the new decl information. */
1348 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1349 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1350 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1352 /* Make this function static known to the mudflap runtime. */
1353 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1354 mudflap_enqueue_decl (decl
);
1359 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1361 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1362 && DECL_REGISTER (decl
))
1364 error ("register name not specified for %q+D", decl
);
1366 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1368 const char *asmspec
= name
+1;
1369 reg_number
= decode_reg_name (asmspec
);
1370 /* First detect errors in declaring global registers. */
1371 if (reg_number
== -1)
1372 error ("register name not specified for %q+D", decl
);
1373 else if (reg_number
< 0)
1374 error ("invalid register name for %q+D", decl
);
1375 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
1376 error ("data type of %q+D isn%'t suitable for a register",
1378 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
1379 error ("register specified for %q+D isn%'t suitable for data type",
1381 /* Now handle properly declared static register variables. */
1386 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1388 DECL_INITIAL (decl
) = 0;
1389 error ("global register variable has initial value");
1391 if (TREE_THIS_VOLATILE (decl
))
1392 warning (OPT_Wvolatile_register_var
,
1393 "optimization may eliminate reads and/or "
1394 "writes to register variables");
1396 /* If the user specified one of the eliminables registers here,
1397 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1398 confused with that register and be eliminated. This usage is
1399 somewhat suspect... */
1401 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
1402 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1403 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1405 if (TREE_STATIC (decl
))
1407 /* Make this register global, so not usable for anything
1409 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1410 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1411 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1413 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
1415 globalize_reg (reg_number
+ --nregs
);
1418 /* As a register variable, it has no section. */
1422 /* Now handle ordinary static variables and functions (in memory).
1423 Also handle vars declared register invalidly. */
1424 else if (name
[0] == '*')
1426 #ifdef REGISTER_PREFIX
1427 if (strlen (REGISTER_PREFIX
) != 0)
1429 reg_number
= decode_reg_name (name
);
1430 if (reg_number
>= 0 || reg_number
== -3)
1431 error ("register name given for non-register variable %q+D", decl
);
1436 /* Specifying a section attribute on a variable forces it into a
1437 non-.bss section, and thus it cannot be common. */
1438 gcc_assert (!(TREE_CODE (decl
) == VAR_DECL
1439 && DECL_SECTION_NAME (decl
) != NULL_TREE
1440 && DECL_INITIAL (decl
) == NULL_TREE
1441 && DECL_COMMON (decl
))
1442 || !DECL_COMMON (decl
));
1444 /* Variables can't be both common and weak. */
1445 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1446 || !DECL_WEAK (decl
)
1447 || !DECL_COMMON (decl
));
1449 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1450 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1453 enum machine_mode address_mode
= Pmode
;
1454 if (TREE_TYPE (decl
) != error_mark_node
)
1456 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1457 address_mode
= targetm
.addr_space
.address_mode (as
);
1459 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1461 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1462 SET_SYMBOL_REF_DECL (x
, decl
);
1464 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1465 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1466 set_mem_attributes (x
, decl
, 1);
1467 SET_DECL_RTL (decl
, x
);
1469 /* Optionally set flags or add text to the name to record information
1470 such as that it is a function name.
1471 If the name is changed, the macro ASM_OUTPUT_LABELREF
1472 will have to know how to strip this information. */
1473 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1475 /* Make this function static known to the mudflap runtime. */
1476 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1477 mudflap_enqueue_decl (decl
);
1480 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1481 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1485 make_decl_rtl_for_debug (tree decl
)
1487 unsigned int save_aliasing_flag
, save_mudflap_flag
;
1490 if (DECL_RTL_SET_P (decl
))
1491 return DECL_RTL (decl
);
1493 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1494 call new_alias_set. If running with -fcompare-debug, sometimes
1495 we do not want to create alias sets that will throw the alias
1496 numbers off in the comparison dumps. So... clearing
1497 flag_strict_aliasing will keep new_alias_set() from creating a
1498 new set. It is undesirable to register decl with mudflap
1499 in this case as well. */
1500 save_aliasing_flag
= flag_strict_aliasing
;
1501 flag_strict_aliasing
= 0;
1502 save_mudflap_flag
= flag_mudflap
;
1505 rtl
= DECL_RTL (decl
);
1506 /* Reset DECL_RTL back, as various parts of the compiler expects
1507 DECL_RTL set meaning it is actually going to be output. */
1508 SET_DECL_RTL (decl
, NULL
);
1510 flag_strict_aliasing
= save_aliasing_flag
;
1511 flag_mudflap
= save_mudflap_flag
;
1516 /* Output a string of literal assembler code
1517 for an `asm' keyword used between functions. */
1520 assemble_asm (tree string
)
1524 if (TREE_CODE (string
) == ADDR_EXPR
)
1525 string
= TREE_OPERAND (string
, 0);
1527 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1530 /* Record an element in the table of global destructors. SYMBOL is
1531 a SYMBOL_REF of the function to be called; PRIORITY is a number
1532 between 0 and MAX_INIT_PRIORITY. */
1535 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
1536 int priority ATTRIBUTE_UNUSED
)
1538 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1539 /* Tell GNU LD that this is part of the static destructor set.
1540 This will work for any system that uses stabs, most usefully
1542 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1543 dbxout_stab_value_label (XSTR (symbol
, 0));
1545 sorry ("global destructors not supported on this target");
1549 /* Write the address of the entity given by SYMBOL to SEC. */
1551 assemble_addr_to_section (rtx symbol
, section
*sec
)
1553 switch_to_section (sec
);
1554 assemble_align (POINTER_SIZE
);
1555 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1558 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1559 not) section for PRIORITY. */
1561 get_cdtor_priority_section (int priority
, bool constructor_p
)
1565 /* ??? This only works reliably with the GNU linker. */
1566 sprintf (buf
, "%s.%.5u",
1567 constructor_p
? ".ctors" : ".dtors",
1568 /* Invert the numbering so the linker puts us in the proper
1569 order; constructors are run from right to left, and the
1570 linker sorts in increasing order. */
1571 MAX_INIT_PRIORITY
- priority
);
1572 return get_section (buf
, SECTION_WRITE
, NULL
);
1576 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1580 if (priority
!= DEFAULT_INIT_PRIORITY
)
1581 sec
= get_cdtor_priority_section (priority
,
1582 /*constructor_p=*/false);
1584 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1586 assemble_addr_to_section (symbol
, sec
);
1589 #ifdef DTORS_SECTION_ASM_OP
1591 default_dtor_section_asm_out_destructor (rtx symbol
,
1592 int priority ATTRIBUTE_UNUSED
)
1594 assemble_addr_to_section (symbol
, dtors_section
);
1598 /* Likewise for global constructors. */
1601 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
1602 int priority ATTRIBUTE_UNUSED
)
1604 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1605 /* Tell GNU LD that this is part of the static destructor set.
1606 This will work for any system that uses stabs, most usefully
1608 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1609 dbxout_stab_value_label (XSTR (symbol
, 0));
1611 sorry ("global constructors not supported on this target");
1616 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1620 if (priority
!= DEFAULT_INIT_PRIORITY
)
1621 sec
= get_cdtor_priority_section (priority
,
1622 /*constructor_p=*/true);
1624 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1626 assemble_addr_to_section (symbol
, sec
);
1629 #ifdef CTORS_SECTION_ASM_OP
1631 default_ctor_section_asm_out_constructor (rtx symbol
,
1632 int priority ATTRIBUTE_UNUSED
)
1634 assemble_addr_to_section (symbol
, ctors_section
);
1638 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1639 a nonzero value if the constant pool should be output before the
1640 start of the function, or a zero value if the pool should output
1641 after the end of the function. The default is to put it before the
1644 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1645 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1648 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1649 to be output to assembler.
1650 Set first_global_object_name and weak_global_object_name as appropriate. */
1653 notice_global_symbol (tree decl
)
1655 const char **type
= &first_global_object_name
;
1657 if (first_global_object_name
1658 || !TREE_PUBLIC (decl
)
1659 || DECL_EXTERNAL (decl
)
1660 || !DECL_NAME (decl
)
1661 || (TREE_CODE (decl
) != FUNCTION_DECL
1662 && (TREE_CODE (decl
) != VAR_DECL
1663 || (DECL_COMMON (decl
)
1664 && (DECL_INITIAL (decl
) == 0
1665 || DECL_INITIAL (decl
) == error_mark_node
))))
1666 || !MEM_P (DECL_RTL (decl
)))
1669 /* We win when global object is found, but it is useful to know about weak
1670 symbol as well so we can produce nicer unique names. */
1671 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1672 type
= &weak_global_object_name
;
1678 rtx decl_rtl
= DECL_RTL (decl
);
1680 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1681 name
= ggc_strdup (p
);
1687 /* Output assembler code for the constant pool of a function and associated
1688 with defining the name of the function. DECL describes the function.
1689 NAME is the function's name. For the constant pool, we use the current
1690 constant pool data. */
1693 assemble_start_function (tree decl
, const char *fnname
)
1696 char tmp_label
[100];
1697 bool hot_label_written
= false;
1699 crtl
->subsections
.unlikely_text_section_name
= NULL
;
1701 first_function_block_is_cold
= false;
1702 if (flag_reorder_blocks_and_partition
)
1704 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1705 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1706 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1707 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1708 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1709 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1710 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1711 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1716 crtl
->subsections
.hot_section_label
= NULL
;
1717 crtl
->subsections
.cold_section_label
= NULL
;
1718 crtl
->subsections
.hot_section_end_label
= NULL
;
1719 crtl
->subsections
.cold_section_end_label
= NULL
;
1722 /* The following code does not need preprocessing in the assembler. */
1726 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1727 output_constant_pool (fnname
, decl
);
1729 resolve_unique_section (decl
, 0, flag_function_sections
);
1731 /* Make sure the not and cold text (code) sections are properly
1732 aligned. This is necessary here in the case where the function
1733 has both hot and cold sections, because we don't want to re-set
1734 the alignment when the section switch happens mid-function. */
1736 if (flag_reorder_blocks_and_partition
)
1738 switch_to_section (unlikely_text_section ());
1739 assemble_align (DECL_ALIGN (decl
));
1740 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1742 /* When the function starts with a cold section, we need to explicitly
1743 align the hot section and write out the hot section label.
1744 But if the current function is a thunk, we do not have a CFG. */
1746 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1748 switch_to_section (text_section
);
1749 assemble_align (DECL_ALIGN (decl
));
1750 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1751 hot_label_written
= true;
1752 first_function_block_is_cold
= true;
1755 else if (DECL_SECTION_NAME (decl
))
1757 /* Calls to function_section rely on first_function_block_is_cold
1758 being accurate. The first block may be cold even if we aren't
1759 doing partitioning, if the entire function was decided by
1760 choose_function_section (predict.c) to be cold. */
1762 initialize_cold_section_name ();
1764 if (crtl
->subsections
.unlikely_text_section_name
1765 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
1766 crtl
->subsections
.unlikely_text_section_name
) == 0)
1767 first_function_block_is_cold
= true;
1770 in_cold_section_p
= first_function_block_is_cold
;
1772 /* Switch to the correct text section for the start of the function. */
1774 switch_to_section (function_section (decl
));
1775 if (flag_reorder_blocks_and_partition
1776 && !hot_label_written
)
1777 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1779 /* Tell assembler to move to target machine's alignment for functions. */
1780 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1783 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1786 /* Handle a user-specified function alignment.
1787 Note that we still need to align to DECL_ALIGN, as above,
1788 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1789 if (! DECL_USER_ALIGN (decl
)
1790 && align_functions_log
> align
1791 && optimize_function_for_speed_p (cfun
))
1793 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1794 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1795 align_functions_log
, align_functions
- 1);
1797 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1801 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1802 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1805 if (!DECL_IGNORED_P (decl
))
1806 (*debug_hooks
->begin_function
) (decl
);
1808 /* Make function name accessible from other files, if appropriate. */
1810 if (TREE_PUBLIC (decl
))
1812 notice_global_symbol (decl
);
1814 globalize_decl (decl
);
1816 maybe_assemble_visibility (decl
);
1819 if (DECL_PRESERVE_P (decl
))
1820 targetm
.asm_out
.mark_decl_preserved (fnname
);
1822 /* Do any machine/system dependent processing of the function name. */
1823 #ifdef ASM_DECLARE_FUNCTION_NAME
1824 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1826 /* Standard thing is just output label for the function. */
1827 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1828 #endif /* ASM_DECLARE_FUNCTION_NAME */
1831 /* Output assembler code associated with defining the size of the
1832 function. DECL describes the function. NAME is the function's name. */
1835 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1837 #ifdef ASM_DECLARE_FUNCTION_SIZE
1838 /* We could have switched section in the middle of the function. */
1839 if (flag_reorder_blocks_and_partition
)
1840 switch_to_section (function_section (decl
));
1841 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1843 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1845 output_constant_pool (fnname
, decl
);
1846 switch_to_section (function_section (decl
)); /* need to switch back */
1848 /* Output labels for end of hot/cold text sections (to be used by
1850 if (flag_reorder_blocks_and_partition
)
1852 section
*save_text_section
;
1854 save_text_section
= in_section
;
1855 switch_to_section (unlikely_text_section ());
1856 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1857 if (first_function_block_is_cold
)
1858 switch_to_section (text_section
);
1860 switch_to_section (function_section (decl
));
1861 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1862 switch_to_section (save_text_section
);
1866 /* Assemble code to leave SIZE bytes of zeros. */
1869 assemble_zeros (unsigned HOST_WIDE_INT size
)
1871 /* Do no output if -fsyntax-only. */
1872 if (flag_syntax_only
)
1875 #ifdef ASM_NO_SKIP_IN_TEXT
1876 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1877 so we must output 0s explicitly in the text section. */
1878 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1880 unsigned HOST_WIDE_INT i
;
1881 for (i
= 0; i
< size
; i
++)
1882 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1887 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1890 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1893 assemble_align (int align
)
1895 if (align
> BITS_PER_UNIT
)
1897 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1901 /* Assemble a string constant with the specified C string as contents. */
1904 assemble_string (const char *p
, int size
)
1909 /* If the string is very long, split it up. */
1913 int thissize
= size
- pos
;
1914 if (thissize
> maximum
)
1917 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1925 /* A noswitch_section_callback for lcomm_section. */
1928 emit_local (tree decl ATTRIBUTE_UNUSED
,
1929 const char *name ATTRIBUTE_UNUSED
,
1930 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1931 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1933 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1934 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1935 size
, DECL_ALIGN (decl
));
1937 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1938 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1941 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1946 /* A noswitch_section_callback for bss_noswitch_section. */
1948 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1950 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1951 const char *name ATTRIBUTE_UNUSED
,
1952 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1953 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1955 #if defined ASM_OUTPUT_ALIGNED_BSS
1956 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
, DECL_ALIGN (decl
));
1959 ASM_OUTPUT_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1965 /* A noswitch_section_callback for comm_section. */
1968 emit_common (tree decl ATTRIBUTE_UNUSED
,
1969 const char *name ATTRIBUTE_UNUSED
,
1970 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1971 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1973 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1974 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1975 size
, DECL_ALIGN (decl
));
1977 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1978 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1981 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1986 /* A noswitch_section_callback for tls_comm_section. */
1989 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1990 const char *name ATTRIBUTE_UNUSED
,
1991 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1992 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1994 #ifdef ASM_OUTPUT_TLS_COMMON
1995 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1998 sorry ("thread-local COMMON data not implemented");
2003 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2004 NAME is the name of DECL's SYMBOL_REF. */
2007 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
)
2009 unsigned HOST_WIDE_INT size
, rounded
;
2011 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
2014 /* Don't allocate zero bytes of common,
2015 since that means "undefined external" in the linker. */
2019 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2020 so that each uninitialized object starts on such a boundary. */
2021 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
2022 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2023 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2025 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
2026 && (unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
2027 warning (0, "requested alignment for %q+D is greater than "
2028 "implemented alignment of %wu", decl
, rounded
);
2031 /* A subroutine of assemble_variable. Output the label and contents of
2032 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2033 is as for assemble_variable. */
2036 assemble_variable_contents (tree decl
, const char *name
,
2037 bool dont_output_data
)
2039 /* Do any machine/system dependent processing of the object. */
2040 #ifdef ASM_DECLARE_OBJECT_NAME
2041 last_assemble_variable_decl
= decl
;
2042 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
2044 /* Standard thing is just output label for the object. */
2045 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2046 #endif /* ASM_DECLARE_OBJECT_NAME */
2048 if (!dont_output_data
)
2050 if (DECL_INITIAL (decl
)
2051 && DECL_INITIAL (decl
) != error_mark_node
2052 && !initializer_zerop (DECL_INITIAL (decl
)))
2053 /* Output the actual data. */
2054 output_constant (DECL_INITIAL (decl
),
2055 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
2058 /* Leave space for it. */
2059 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
2063 /* Initialize emulated tls object TO, which refers to TLS variable
2064 DECL and is initialized by PROXY. */
2067 default_emutls_var_init (tree to
, tree decl
, tree proxy
)
2069 VEC(constructor_elt
,gc
) *v
= VEC_alloc (constructor_elt
, gc
, 4);
2070 constructor_elt
*elt
;
2071 tree type
= TREE_TYPE (to
);
2072 tree field
= TYPE_FIELDS (type
);
2074 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2076 elt
->value
= fold_convert (TREE_TYPE (field
), DECL_SIZE_UNIT (decl
));
2078 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2079 field
= TREE_CHAIN (field
);
2081 elt
->value
= build_int_cst (TREE_TYPE (field
),
2082 DECL_ALIGN_UNIT (decl
));
2084 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2085 field
= TREE_CHAIN (field
);
2087 elt
->value
= null_pointer_node
;
2089 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2090 field
= TREE_CHAIN (field
);
2094 return build_constructor (type
, v
);
2097 /* Assemble everything that is needed for a variable or function declaration.
2098 Not used for automatic variables, and not used for function definitions.
2099 Should not be called for variables of incomplete structure type.
2101 TOP_LEVEL is nonzero if this variable has file scope.
2102 AT_END is nonzero if this is the special handling, at end of compilation,
2103 to define things that have had only tentative definitions.
2104 DONT_OUTPUT_DATA if nonzero means don't actually output the
2105 initial value (that will be done by the caller). */
2108 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
2109 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
2112 rtx decl_rtl
, symbol
;
2115 if (! targetm
.have_tls
2116 && TREE_CODE (decl
) == VAR_DECL
2117 && DECL_THREAD_LOCAL_P (decl
))
2119 tree to
= emutls_decl (decl
);
2121 /* If this variable is defined locally, then we need to initialize the
2122 control structure with size and alignment information. We do this
2123 at the last moment because tentative definitions can take a locally
2124 defined but uninitialized variable and initialize it later, which
2125 would result in incorrect contents. */
2126 if (! DECL_EXTERNAL (to
)
2127 && (! DECL_COMMON (to
)
2128 || (DECL_INITIAL (decl
)
2129 && DECL_INITIAL (decl
) != error_mark_node
)))
2131 DECL_INITIAL (to
) = targetm
.emutls
.var_init
2132 (to
, decl
, get_emutls_init_templ_addr (decl
));
2134 /* Make sure the template is marked as needed early enough.
2135 Without this, if the variable is placed in a
2136 section-anchored block, the template will only be marked
2137 when it's too late. */
2138 record_references_in_initializer (to
, false);
2144 last_assemble_variable_decl
= 0;
2146 /* Normally no need to say anything here for external references,
2147 since assemble_external is called by the language-specific code
2148 when a declaration is first seen. */
2150 if (DECL_EXTERNAL (decl
))
2153 /* Output no assembler code for a function declaration.
2154 Only definitions of functions output anything. */
2156 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2159 /* Do nothing for global register variables. */
2160 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2162 TREE_ASM_WRITTEN (decl
) = 1;
2166 /* If type was incomplete when the variable was declared,
2167 see if it is complete now. */
2169 if (DECL_SIZE (decl
) == 0)
2170 layout_decl (decl
, 0);
2172 /* Still incomplete => don't allocate it; treat the tentative defn
2173 (which is what it must have been) as an `extern' reference. */
2175 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2177 error ("storage size of %q+D isn%'t known", decl
);
2178 TREE_ASM_WRITTEN (decl
) = 1;
2182 /* The first declaration of a variable that comes through this function
2183 decides whether it is global (in C, has external linkage)
2184 or local (in C, has internal linkage). So do nothing more
2185 if this function has already run. */
2187 if (TREE_ASM_WRITTEN (decl
))
2190 /* Make sure targetm.encode_section_info is invoked before we set
2192 decl_rtl
= DECL_RTL (decl
);
2194 TREE_ASM_WRITTEN (decl
) = 1;
2196 /* Do no output if -fsyntax-only. */
2197 if (flag_syntax_only
)
2202 if (! dont_output_data
2203 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
2205 error ("size of variable %q+D is too large", decl
);
2209 gcc_assert (MEM_P (decl_rtl
));
2210 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2211 symbol
= XEXP (decl_rtl
, 0);
2212 name
= XSTR (symbol
, 0);
2213 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2214 notice_global_symbol (decl
);
2216 /* Compute the alignment of this data. */
2218 align_variable (decl
, dont_output_data
);
2219 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2221 if (TREE_PUBLIC (decl
))
2222 maybe_assemble_visibility (decl
);
2224 if (DECL_PRESERVE_P (decl
))
2225 targetm
.asm_out
.mark_decl_preserved (name
);
2227 /* First make the assembler name(s) global if appropriate. */
2228 sect
= get_variable_section (decl
, false);
2229 if (TREE_PUBLIC (decl
)
2230 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2231 globalize_decl (decl
);
2233 /* Output any data that we will need to use the address of. */
2234 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2235 output_addressed_constants (DECL_INITIAL (decl
));
2237 /* dbxout.c needs to know this. */
2238 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2239 DECL_IN_TEXT_SECTION (decl
) = 1;
2241 /* If the decl is part of an object_block, make sure that the decl
2242 has been positioned within its block, but do not write out its
2243 definition yet. output_object_blocks will do that later. */
2244 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2246 gcc_assert (!dont_output_data
);
2247 place_block_symbol (symbol
);
2249 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2250 assemble_noswitch_variable (decl
, name
, sect
);
2253 switch_to_section (sect
);
2254 if (DECL_ALIGN (decl
) > BITS_PER_UNIT
)
2255 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
2256 assemble_variable_contents (decl
, name
, dont_output_data
);
2260 /* Return 1 if type TYPE contains any pointers. */
2263 contains_pointers_p (tree type
)
2265 switch (TREE_CODE (type
))
2268 case REFERENCE_TYPE
:
2269 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2270 so I'll play safe and return 1. */
2276 case QUAL_UNION_TYPE
:
2279 /* For a type that has fields, see if the fields have pointers. */
2280 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2281 if (TREE_CODE (fields
) == FIELD_DECL
2282 && contains_pointers_p (TREE_TYPE (fields
)))
2288 /* An array type contains pointers if its element type does. */
2289 return contains_pointers_p (TREE_TYPE (type
));
2296 /* We delay assemble_external processing until
2297 the compilation unit is finalized. This is the best we can do for
2298 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2299 it all the way to final. See PR 17982 for further discussion. */
2300 static GTY(()) tree pending_assemble_externals
;
2302 #ifdef ASM_OUTPUT_EXTERNAL
2303 /* True if DECL is a function decl for which no out-of-line copy exists.
2304 It is assumed that DECL's assembler name has been set. */
2307 incorporeal_function_p (tree decl
)
2309 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2313 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2314 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
2317 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2318 if (is_builtin_name (name
))
2324 /* Actually do the tests to determine if this is necessary, and invoke
2325 ASM_OUTPUT_EXTERNAL. */
2327 assemble_external_real (tree decl
)
2329 rtx rtl
= DECL_RTL (decl
);
2331 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2332 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2333 && !incorporeal_function_p (decl
))
2335 /* Some systems do require some output. */
2336 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2337 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2343 process_pending_assemble_externals (void)
2345 #ifdef ASM_OUTPUT_EXTERNAL
2347 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2348 assemble_external_real (TREE_VALUE (list
));
2350 pending_assemble_externals
= 0;
2354 /* This TREE_LIST contains any weak symbol declarations waiting
2356 static GTY(()) tree weak_decls
;
2358 /* Output something to declare an external symbol to the assembler,
2359 and qualifiers such as weakness. (Most assemblers don't need
2360 extern declaration, so we normally output nothing.) Do nothing if
2361 DECL is not external. */
2364 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2366 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2367 main body of this code is only rarely exercised. To provide some
2368 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2369 open. If it's not, we should not be calling this function. */
2370 gcc_assert (asm_out_file
);
2372 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2375 /* We want to output annotation for weak and external symbols at
2376 very last to check if they are references or not. */
2380 /* TREE_STATIC is a weird and abused creature which is not
2381 generally the right test for whether an entity has been
2382 locally emitted, inlined or otherwise not-really-extern, but
2383 for declarations that can be weak, it happens to be
2385 && !TREE_STATIC (decl
)
2386 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2387 && value_member (decl
, weak_decls
) == NULL_TREE
)
2388 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2390 #ifdef ASM_OUTPUT_EXTERNAL
2391 if (value_member (decl
, pending_assemble_externals
) == NULL_TREE
)
2392 pending_assemble_externals
= tree_cons (NULL
, decl
,
2393 pending_assemble_externals
);
2397 /* Similar, for calling a library function FUN. */
2400 assemble_external_libcall (rtx fun
)
2402 /* Declare library function name external when first used, if nec. */
2403 if (! SYMBOL_REF_USED (fun
))
2405 SYMBOL_REF_USED (fun
) = 1;
2406 targetm
.asm_out
.external_libcall (fun
);
2410 /* Assemble a label named NAME. */
2413 assemble_label (const char *name
)
2415 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2418 /* Set the symbol_referenced flag for ID. */
2420 mark_referenced (tree id
)
2422 TREE_SYMBOL_REFERENCED (id
) = 1;
2425 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2427 mark_decl_referenced (tree decl
)
2429 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2431 /* Extern inline functions don't become needed when referenced.
2432 If we know a method will be emitted in other TU and no new
2433 functions can be marked reachable, just use the external
2435 struct cgraph_node
*node
= cgraph_node (decl
);
2436 if (!DECL_EXTERNAL (decl
)
2437 && (!node
->local
.vtable_method
|| !cgraph_global_info_ready
2438 || !node
->local
.finalized
))
2439 cgraph_mark_needed_node (node
);
2441 else if (TREE_CODE (decl
) == VAR_DECL
)
2443 struct varpool_node
*node
= varpool_node (decl
);
2444 varpool_mark_needed_node (node
);
2445 /* C++ frontend use mark_decl_references to force COMDAT variables
2446 to be output that might appear dead otherwise. */
2447 node
->force_output
= true;
2449 /* else do nothing - we can get various sorts of CST nodes here,
2450 which do not need to be marked. */
2454 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2455 until we find an identifier that is not itself a transparent alias.
2456 Modify the alias passed to it by reference (and all aliases on the
2457 way to the ultimate target), such that they do not have to be
2458 followed again, and return the ultimate target of the alias
2462 ultimate_transparent_alias_target (tree
*alias
)
2464 tree target
= *alias
;
2466 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2468 gcc_assert (TREE_CHAIN (target
));
2469 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2470 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2471 && ! TREE_CHAIN (target
));
2478 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2479 starts with a *, the rest of NAME is output verbatim. Otherwise
2480 NAME is transformed in a target-specific way (usually by the
2481 addition of an underscore). */
2484 assemble_name_raw (FILE *file
, const char *name
)
2487 fputs (&name
[1], file
);
2489 ASM_OUTPUT_LABELREF (file
, name
);
2492 /* Like assemble_name_raw, but should be used when NAME might refer to
2493 an entity that is also represented as a tree (like a function or
2494 variable). If NAME does refer to such an entity, that entity will
2495 be marked as referenced. */
2498 assemble_name (FILE *file
, const char *name
)
2500 const char *real_name
;
2503 real_name
= targetm
.strip_name_encoding (name
);
2505 id
= maybe_get_identifier (real_name
);
2510 mark_referenced (id
);
2511 ultimate_transparent_alias_target (&id
);
2513 name
= IDENTIFIER_POINTER (id
);
2514 gcc_assert (! TREE_CHAIN (id
));
2517 assemble_name_raw (file
, name
);
2520 /* Allocate SIZE bytes writable static space with a gensym name
2521 and return an RTX to refer to its address. */
2524 assemble_static_space (unsigned HOST_WIDE_INT size
)
2527 const char *namestring
;
2530 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2532 namestring
= ggc_strdup (name
);
2534 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2535 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2537 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2538 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2541 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2542 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2545 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2546 so that each uninitialized object starts on such a boundary. */
2547 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2548 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2549 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2550 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2551 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2552 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2559 /* Assemble the static constant template for function entry trampolines.
2560 This is done at most once per compilation.
2561 Returns an RTX for the address of the template. */
2563 static GTY(()) rtx initial_trampoline
;
2566 assemble_trampoline_template (void)
2573 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2575 if (initial_trampoline
)
2576 return initial_trampoline
;
2578 /* By default, put trampoline templates in read-only data section. */
2580 #ifdef TRAMPOLINE_SECTION
2581 switch_to_section (TRAMPOLINE_SECTION
);
2583 switch_to_section (readonly_data_section
);
2586 /* Write the assembler code to define one. */
2587 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2589 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2591 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2592 targetm
.asm_out
.trampoline_template (asm_out_file
);
2594 /* Record the rtl to refer to it. */
2595 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2596 name
= ggc_strdup (label
);
2597 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2598 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2600 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2601 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2602 set_mem_size (initial_trampoline
, GEN_INT (TRAMPOLINE_SIZE
));
2604 return initial_trampoline
;
2607 /* A and B are either alignments or offsets. Return the minimum alignment
2608 that may be assumed after adding the two together. */
2610 static inline unsigned
2611 min_align (unsigned int a
, unsigned int b
)
2613 return (a
| b
) & -(a
| b
);
2616 /* Return the assembler directive for creating a given kind of integer
2617 object. SIZE is the number of bytes in the object and ALIGNED_P
2618 indicates whether it is known to be aligned. Return NULL if the
2619 assembly dialect has no such directive.
2621 The returned string should be printed at the start of a new line and
2622 be followed immediately by the object's initial value. */
2625 integer_asm_op (int size
, int aligned_p
)
2627 struct asm_int_op
*ops
;
2630 ops
= &targetm
.asm_out
.aligned_op
;
2632 ops
= &targetm
.asm_out
.unaligned_op
;
2637 return targetm
.asm_out
.byte_op
;
2651 /* Use directive OP to assemble an integer object X. Print OP at the
2652 start of the line, followed immediately by the value of X. */
2655 assemble_integer_with_op (const char *op
, rtx x
)
2657 fputs (op
, asm_out_file
);
2658 output_addr_const (asm_out_file
, x
);
2659 fputc ('\n', asm_out_file
);
2662 /* The default implementation of the asm_out.integer target hook. */
2665 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2666 unsigned int size ATTRIBUTE_UNUSED
,
2667 int aligned_p ATTRIBUTE_UNUSED
)
2669 const char *op
= integer_asm_op (size
, aligned_p
);
2670 /* Avoid GAS bugs for large values. Specifically negative values whose
2671 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2672 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2674 return op
&& (assemble_integer_with_op (op
, x
), true);
2677 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2678 the alignment of the integer in bits. Return 1 if we were able to output
2679 the constant, otherwise 0. We must be able to output the constant,
2680 if FORCE is nonzero. */
2683 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2687 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2689 /* See if the target hook can handle this kind of object. */
2690 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2693 /* If the object is a multi-byte one, try splitting it up. Split
2694 it into words it if is multi-word, otherwise split it into bytes. */
2697 enum machine_mode omode
, imode
;
2698 unsigned int subalign
;
2699 unsigned int subsize
, i
;
2700 enum mode_class mclass
;
2702 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2703 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2704 if (GET_CODE (x
) == CONST_FIXED
)
2705 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2709 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2710 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2712 for (i
= 0; i
< size
; i
+= subsize
)
2714 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2715 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2721 /* If we've printed some of it, but not all of it, there's no going
2726 gcc_assert (!force
);
2732 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2734 long data
[4] = {0, 0, 0, 0};
2736 int bitsize
, nelts
, nunits
, units_per
;
2738 /* This is hairy. We have a quantity of known size. real_to_target
2739 will put it into an array of *host* longs, 32 bits per element
2740 (even if long is more than 32 bits). We need to determine the
2741 number of array elements that are occupied (nelts) and the number
2742 of *target* min-addressable units that will be occupied in the
2743 object file (nunits). We cannot assume that 32 divides the
2744 mode's bitsize (size * BITS_PER_UNIT) evenly.
2746 size * BITS_PER_UNIT is used here to make sure that padding bits
2747 (which might appear at either end of the value; real_to_target
2748 will include the padding bits in its output array) are included. */
2750 nunits
= GET_MODE_SIZE (mode
);
2751 bitsize
= nunits
* BITS_PER_UNIT
;
2752 nelts
= CEIL (bitsize
, 32);
2753 units_per
= 32 / BITS_PER_UNIT
;
2755 real_to_target (data
, &d
, mode
);
2757 /* Put out the first word with the specified alignment. */
2758 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2759 nunits
-= units_per
;
2761 /* Subsequent words need only 32-bit alignment. */
2762 align
= min_align (align
, 32);
2764 for (i
= 1; i
< nelts
; i
++)
2766 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2767 nunits
-= units_per
;
2771 /* Given an expression EXP with a constant value,
2772 reduce it to the sum of an assembler symbol and an integer.
2773 Store them both in the structure *VALUE.
2774 EXP must be reducible. */
2776 struct GTY(()) addr_const
{
2778 HOST_WIDE_INT offset
;
2782 decode_addr_const (tree exp
, struct addr_const
*value
)
2784 tree target
= TREE_OPERAND (exp
, 0);
2790 if (TREE_CODE (target
) == COMPONENT_REF
2791 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2794 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2795 target
= TREE_OPERAND (target
, 0);
2797 else if (TREE_CODE (target
) == ARRAY_REF
2798 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2800 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2801 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2802 target
= TREE_OPERAND (target
, 0);
2808 switch (TREE_CODE (target
))
2812 x
= DECL_RTL (target
);
2816 x
= gen_rtx_MEM (FUNCTION_MODE
,
2817 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2826 x
= output_constant_def (target
, 1);
2833 gcc_assert (MEM_P (x
));
2837 value
->offset
= offset
;
2841 static GTY((param_is (struct constant_descriptor_tree
)))
2842 htab_t const_desc_htab
;
2844 static struct constant_descriptor_tree
* build_constant_desc (tree
);
2845 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2847 /* Constant pool accessor function. */
2850 constant_pool_htab (void)
2852 return const_desc_htab
;
2855 /* Compute a hash code for a constant expression. */
2858 const_desc_hash (const void *ptr
)
2860 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2864 const_hash_1 (const tree exp
)
2869 enum tree_code code
= TREE_CODE (exp
);
2871 /* Either set P and LEN to the address and len of something to hash and
2872 exit the switch or return a value. */
2877 p
= (char *) &TREE_INT_CST (exp
);
2878 len
= sizeof TREE_INT_CST (exp
);
2882 return real_hash (TREE_REAL_CST_PTR (exp
));
2885 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2888 p
= TREE_STRING_POINTER (exp
);
2889 len
= TREE_STRING_LENGTH (exp
);
2893 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2894 + const_hash_1 (TREE_IMAGPART (exp
)));
2898 unsigned HOST_WIDE_INT idx
;
2901 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2903 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2905 hi
= hi
* 603 + const_hash_1 (value
);
2913 struct addr_const value
;
2915 decode_addr_const (exp
, &value
);
2916 switch (GET_CODE (value
.base
))
2919 /* Don't hash the address of the SYMBOL_REF;
2920 only use the offset and the symbol name. */
2922 p
= XSTR (value
.base
, 0);
2923 for (i
= 0; p
[i
] != 0; i
++)
2924 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2928 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2938 case POINTER_PLUS_EXPR
:
2940 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2941 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2944 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2947 /* A language specific constant. Just hash the code. */
2951 /* Compute hashing function. */
2953 for (i
= 0; i
< len
; i
++)
2954 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2959 /* Wrapper of compare_constant, for the htab interface. */
2961 const_desc_eq (const void *p1
, const void *p2
)
2963 const struct constant_descriptor_tree
*const c1
2964 = (const struct constant_descriptor_tree
*) p1
;
2965 const struct constant_descriptor_tree
*const c2
2966 = (const struct constant_descriptor_tree
*) p2
;
2967 if (c1
->hash
!= c2
->hash
)
2969 return compare_constant (c1
->value
, c2
->value
);
2972 /* Compare t1 and t2, and return 1 only if they are known to result in
2973 the same bit pattern on output. */
2976 compare_constant (const tree t1
, const tree t2
)
2978 enum tree_code typecode
;
2980 if (t1
== NULL_TREE
)
2981 return t2
== NULL_TREE
;
2982 if (t2
== NULL_TREE
)
2985 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2988 switch (TREE_CODE (t1
))
2991 /* Integer constants are the same only if the same width of type. */
2992 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2994 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2996 return tree_int_cst_equal (t1
, t2
);
2999 /* Real constants are the same only if the same width of type. */
3000 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3003 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
3006 /* Fixed constants are the same only if the same width of type. */
3007 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3010 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
3013 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3016 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3017 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3018 TREE_STRING_LENGTH (t1
)));
3021 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
3022 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
3026 VEC(constructor_elt
, gc
) *v1
, *v2
;
3027 unsigned HOST_WIDE_INT idx
;
3029 typecode
= TREE_CODE (TREE_TYPE (t1
));
3030 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3033 if (typecode
== ARRAY_TYPE
)
3035 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3036 /* For arrays, check that the sizes all match. */
3037 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3039 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
3044 /* For record and union constructors, require exact type
3046 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3050 v1
= CONSTRUCTOR_ELTS (t1
);
3051 v2
= CONSTRUCTOR_ELTS (t2
);
3052 if (VEC_length (constructor_elt
, v1
)
3053 != VEC_length (constructor_elt
, v2
))
3056 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
3058 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
3059 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
3061 /* Check that each value is the same... */
3062 if (!compare_constant (c1
->value
, c2
->value
))
3064 /* ... and that they apply to the same fields! */
3065 if (typecode
== ARRAY_TYPE
)
3067 if (!compare_constant (c1
->index
, c2
->index
))
3072 if (c1
->index
!= c2
->index
)
3083 struct addr_const value1
, value2
;
3085 decode_addr_const (t1
, &value1
);
3086 decode_addr_const (t2
, &value2
);
3087 return (value1
.offset
== value2
.offset
3088 && strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3092 case POINTER_PLUS_EXPR
:
3095 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3096 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3099 case VIEW_CONVERT_EXPR
:
3100 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3109 /* Make a copy of the whole tree structure for a constant. This
3110 handles the same types of nodes that compare_constant handles. */
3113 copy_constant (tree exp
)
3115 switch (TREE_CODE (exp
))
3118 /* For ADDR_EXPR, we do not want to copy the decl whose address
3119 is requested. We do want to copy constants though. */
3120 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
3121 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3122 copy_constant (TREE_OPERAND (exp
, 0)));
3124 return copy_node (exp
);
3130 return copy_node (exp
);
3133 return build_complex (TREE_TYPE (exp
),
3134 copy_constant (TREE_REALPART (exp
)),
3135 copy_constant (TREE_IMAGPART (exp
)));
3138 case POINTER_PLUS_EXPR
:
3140 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
3141 copy_constant (TREE_OPERAND (exp
, 0)),
3142 copy_constant (TREE_OPERAND (exp
, 1)));
3145 case VIEW_CONVERT_EXPR
:
3146 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3147 copy_constant (TREE_OPERAND (exp
, 0)));
3151 tree copy
= copy_node (exp
);
3152 VEC(constructor_elt
, gc
) *v
;
3153 unsigned HOST_WIDE_INT idx
;
3154 tree purpose
, value
;
3156 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
3157 CONSTRUCTOR_ELTS (exp
)));
3158 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
3160 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
3161 ce
->index
= purpose
;
3162 ce
->value
= copy_constant (value
);
3164 CONSTRUCTOR_ELTS (copy
) = v
;
3173 /* Return the alignment of constant EXP in bits. */
3176 get_constant_alignment (tree exp
)
3180 align
= TYPE_ALIGN (TREE_TYPE (exp
));
3181 #ifdef CONSTANT_ALIGNMENT
3182 align
= CONSTANT_ALIGNMENT (exp
, align
);
3187 /* Return the section into which constant EXP should be placed. */
3190 get_constant_section (tree exp
)
3192 if (IN_NAMED_SECTION (exp
))
3193 return get_named_section (exp
, NULL
, compute_reloc_for_constant (exp
));
3195 return targetm
.asm_out
.select_section (exp
,
3196 compute_reloc_for_constant (exp
),
3197 get_constant_alignment (exp
));
3200 /* Return the size of constant EXP in bytes. */
3202 static HOST_WIDE_INT
3203 get_constant_size (tree exp
)
3207 size
= int_size_in_bytes (TREE_TYPE (exp
));
3208 if (TREE_CODE (exp
) == STRING_CST
)
3209 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3213 /* Subroutine of output_constant_def:
3214 No constant equal to EXP is known to have been output.
3215 Make a constant descriptor to enter EXP in the hash table.
3216 Assign the label number and construct RTL to refer to the
3217 constant's location in memory.
3218 Caller is responsible for updating the hash table. */
3220 static struct constant_descriptor_tree
*
3221 build_constant_desc (tree exp
)
3227 struct constant_descriptor_tree
*desc
;
3229 desc
= GGC_NEW (struct constant_descriptor_tree
);
3230 desc
->value
= copy_constant (exp
);
3232 /* Propagate marked-ness to copied constant. */
3233 if (flag_mudflap
&& mf_marked_p (exp
))
3234 mf_mark (desc
->value
);
3236 /* Create a string containing the label name, in LABEL. */
3237 labelno
= const_labelno
++;
3238 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3240 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3241 if (use_object_blocks_p ())
3243 section
*sect
= get_constant_section (exp
);
3244 symbol
= create_block_symbol (ggc_strdup (label
),
3245 get_block_for_section (sect
), -1);
3248 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3249 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3250 SET_SYMBOL_REF_DECL (symbol
, desc
->value
);
3251 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3253 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3254 set_mem_attributes (rtl
, exp
, 1);
3255 set_mem_alias_set (rtl
, 0);
3256 set_mem_alias_set (rtl
, const_alias_set
);
3258 /* We cannot share RTX'es in pool entries.
3259 Mark this piece of RTL as required for unsharing. */
3260 RTX_FLAG (rtl
, used
) = 1;
3262 /* Set flags or add text to the name to record information, such as
3263 that it is a local symbol. If the name is changed, the macro
3264 ASM_OUTPUT_LABELREF will have to know how to strip this
3265 information. This call might invalidate our local variable
3266 SYMBOL; we can't use it afterward. */
3268 targetm
.encode_section_info (exp
, rtl
, true);
3275 /* Return an rtx representing a reference to constant data in memory
3276 for the constant expression EXP.
3278 If assembler code for such a constant has already been output,
3279 return an rtx to refer to it.
3280 Otherwise, output such a constant in memory
3281 and generate an rtx for it.
3283 If DEFER is nonzero, this constant can be deferred and output only
3284 if referenced in the function after all optimizations.
3286 `const_desc_table' records which constants already have label strings. */
3289 output_constant_def (tree exp
, int defer
)
3291 struct constant_descriptor_tree
*desc
;
3292 struct constant_descriptor_tree key
;
3295 /* Look up EXP in the table of constant descriptors. If we didn't find
3296 it, create a new one. */
3298 key
.hash
= const_hash_1 (exp
);
3299 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3301 desc
= (struct constant_descriptor_tree
*) *loc
;
3304 desc
= build_constant_desc (exp
);
3305 desc
->hash
= key
.hash
;
3309 maybe_output_constant_def_contents (desc
, defer
);
3313 /* Subroutine of output_constant_def: Decide whether or not we need to
3314 output the constant DESC now, and if so, do it. */
3316 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3319 rtx symbol
= XEXP (desc
->rtl
, 0);
3320 tree exp
= desc
->value
;
3322 if (flag_syntax_only
)
3325 if (TREE_ASM_WRITTEN (exp
))
3326 /* Already output; don't do it again. */
3329 /* We can always defer constants as long as the context allows
3333 /* Increment n_deferred_constants if it exists. It needs to be at
3334 least as large as the number of constants actually referred to
3335 by the function. If it's too small we'll stop looking too early
3336 and fail to emit constants; if it's too large we'll only look
3337 through the entire function when we could have stopped earlier. */
3339 n_deferred_constants
++;
3343 output_constant_def_contents (symbol
);
3346 /* Subroutine of output_constant_def_contents. Output the definition
3347 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3348 constant's alignment in bits. */
3351 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3355 size
= get_constant_size (exp
);
3357 /* Do any machine/system dependent processing of the constant. */
3358 #ifdef ASM_DECLARE_CONSTANT_NAME
3359 ASM_DECLARE_CONSTANT_NAME (asm_out_file
, label
, exp
, size
);
3361 /* Standard thing is just output label for the constant. */
3362 ASM_OUTPUT_LABEL (asm_out_file
, label
);
3363 #endif /* ASM_DECLARE_CONSTANT_NAME */
3365 /* Output the value of EXP. */
3366 output_constant (exp
, size
, align
);
3369 /* We must output the constant data referred to by SYMBOL; do so. */
3372 output_constant_def_contents (rtx symbol
)
3374 tree exp
= SYMBOL_REF_DECL (symbol
);
3377 /* Make sure any other constants whose addresses appear in EXP
3378 are assigned label numbers. */
3379 output_addressed_constants (exp
);
3381 /* We are no longer deferring this constant. */
3382 TREE_ASM_WRITTEN (exp
) = 1;
3384 /* If the constant is part of an object block, make sure that the
3385 decl has been positioned within its block, but do not write out
3386 its definition yet. output_object_blocks will do that later. */
3387 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3388 place_block_symbol (symbol
);
3391 switch_to_section (get_constant_section (exp
));
3392 align
= get_constant_alignment (exp
);
3393 if (align
> BITS_PER_UNIT
)
3394 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3395 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3398 mudflap_enqueue_constant (exp
);
3401 /* Look up EXP in the table of constant descriptors. Return the rtl
3402 if it has been emitted, else null. */
3405 lookup_constant_def (tree exp
)
3407 struct constant_descriptor_tree
*desc
;
3408 struct constant_descriptor_tree key
;
3411 key
.hash
= const_hash_1 (exp
);
3412 desc
= (struct constant_descriptor_tree
*)
3413 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3415 return (desc
? desc
->rtl
: NULL_RTX
);
3418 /* Used in the hash tables to avoid outputting the same constant
3419 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3420 are output once per function, not once per file. */
3421 /* ??? Only a few targets need per-function constant pools. Most
3422 can use one per-file pool. Should add a targetm bit to tell the
3425 struct GTY(()) rtx_constant_pool
{
3426 /* Pointers to first and last constant in pool, as ordered by offset. */
3427 struct constant_descriptor_rtx
*first
;
3428 struct constant_descriptor_rtx
*last
;
3430 /* Hash facility for making memory-constants from constant rtl-expressions.
3431 It is used on RISC machines where immediate integer arguments and
3432 constant addresses are restricted so that such constants must be stored
3434 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3436 /* Current offset in constant pool (does not include any
3437 machine-specific header). */
3438 HOST_WIDE_INT offset
;
3441 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3442 struct constant_descriptor_rtx
*next
;
3446 HOST_WIDE_INT offset
;
3448 enum machine_mode mode
;
3454 /* Hash and compare functions for const_rtx_htab. */
3457 const_desc_rtx_hash (const void *ptr
)
3459 const struct constant_descriptor_rtx
*const desc
3460 = (const struct constant_descriptor_rtx
*) ptr
;
3465 const_desc_rtx_eq (const void *a
, const void *b
)
3467 const struct constant_descriptor_rtx
*const x
3468 = (const struct constant_descriptor_rtx
*) a
;
3469 const struct constant_descriptor_rtx
*const y
3470 = (const struct constant_descriptor_rtx
*) b
;
3472 if (x
->mode
!= y
->mode
)
3474 return rtx_equal_p (x
->constant
, y
->constant
);
3477 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3480 const_rtx_hash_1 (rtx
*xp
, void *data
)
3482 unsigned HOST_WIDE_INT hwi
;
3483 enum machine_mode mode
;
3489 code
= GET_CODE (x
);
3490 mode
= GET_MODE (x
);
3491 h
= (hashval_t
) code
* 1048573 + mode
;
3499 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3500 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3503 h
^= (hashval_t
) hwi
;
3504 for (i
= 1; i
< n
; ++i
)
3507 h
^= (hashval_t
) hwi
;
3513 if (mode
== VOIDmode
)
3515 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3519 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3523 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3529 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3530 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3535 h
^= htab_hash_string (XSTR (x
, 0));
3539 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3543 case UNSPEC_VOLATILE
:
3544 h
= h
* 251 + XINT (x
, 1);
3551 hp
= (hashval_t
*) data
;
3552 *hp
= *hp
* 509 + h
;
3556 /* Compute a hash value for X, which should be a constant. */
3559 const_rtx_hash (rtx x
)
3562 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3567 /* Create and return a new rtx constant pool. */
3569 static struct rtx_constant_pool
*
3570 create_constant_pool (void)
3572 struct rtx_constant_pool
*pool
;
3574 pool
= GGC_NEW (struct rtx_constant_pool
);
3575 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3576 const_desc_rtx_eq
, NULL
);
3583 /* Initialize constant pool hashing for a new function. */
3586 init_varasm_status (void)
3588 crtl
->varasm
.pool
= create_constant_pool ();
3589 crtl
->varasm
.deferred_constants
= 0;
3592 /* Given a MINUS expression, simplify it if both sides
3593 include the same symbol. */
3596 simplify_subtraction (rtx x
)
3598 rtx r
= simplify_rtx (x
);
3602 /* Given a constant rtx X, make (or find) a memory constant for its value
3603 and return a MEM rtx to refer to it in memory. */
3606 force_const_mem (enum machine_mode mode
, rtx x
)
3608 struct constant_descriptor_rtx
*desc
, tmp
;
3609 struct rtx_constant_pool
*pool
;
3616 /* If we're not allowed to drop X into the constant pool, don't. */
3617 if (targetm
.cannot_force_const_mem (x
))
3620 /* Record that this function has used a constant pool entry. */
3621 crtl
->uses_const_pool
= 1;
3623 /* Decide which pool to use. */
3624 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3625 ? shared_constant_pool
3626 : crtl
->varasm
.pool
);
3628 /* Lookup the value in the hashtable. */
3631 hash
= const_rtx_hash (x
);
3632 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3633 desc
= (struct constant_descriptor_rtx
*) *slot
;
3635 /* If the constant was already present, return its memory. */
3637 return copy_rtx (desc
->mem
);
3639 /* Otherwise, create a new descriptor. */
3640 desc
= GGC_NEW (struct constant_descriptor_rtx
);
3643 /* Align the location counter as required by EXP's data type. */
3644 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3645 #ifdef CONSTANT_ALIGNMENT
3647 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3648 if (type
!= NULL_TREE
)
3649 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3653 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3654 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3657 desc
->constant
= tmp
.constant
;
3658 desc
->offset
= pool
->offset
;
3661 desc
->align
= align
;
3662 desc
->labelno
= const_labelno
;
3665 pool
->offset
+= GET_MODE_SIZE (mode
);
3667 pool
->last
->next
= desc
;
3669 pool
->first
= pool
->last
= desc
;
3672 /* Create a string containing the label name, in LABEL. */
3673 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3676 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3677 the constants pool. */
3678 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3680 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3681 symbol
= create_block_symbol (ggc_strdup (label
),
3682 get_block_for_section (sect
), -1);
3685 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3687 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3688 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3689 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3691 /* Construct the MEM. */
3692 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3693 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3694 set_mem_align (def
, align
);
3696 /* If we're dropping a label to the constant pool, make sure we
3698 if (GET_CODE (x
) == LABEL_REF
)
3699 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3701 return copy_rtx (def
);
3704 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3707 get_pool_constant (rtx addr
)
3709 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3712 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3713 and whether it has been output or not. */
3716 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3718 struct constant_descriptor_rtx
*desc
;
3720 desc
= SYMBOL_REF_CONSTANT (addr
);
3721 *pmarked
= (desc
->mark
!= 0);
3722 return desc
->constant
;
3725 /* Similar, return the mode. */
3728 get_pool_mode (const_rtx addr
)
3730 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3733 /* Return the size of the constant pool. */
3736 get_pool_size (void)
3738 return crtl
->varasm
.pool
->offset
;
3741 /* Worker function for output_constant_pool_1. Emit assembly for X
3742 in MODE with known alignment ALIGN. */
3745 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3747 switch (GET_MODE_CLASS (mode
))
3750 case MODE_DECIMAL_FLOAT
:
3754 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3755 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3756 assemble_real (r
, mode
, align
);
3761 case MODE_PARTIAL_INT
:
3766 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3769 case MODE_VECTOR_FLOAT
:
3770 case MODE_VECTOR_INT
:
3771 case MODE_VECTOR_FRACT
:
3772 case MODE_VECTOR_UFRACT
:
3773 case MODE_VECTOR_ACCUM
:
3774 case MODE_VECTOR_UACCUM
:
3777 enum machine_mode submode
= GET_MODE_INNER (mode
);
3778 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3780 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3781 units
= CONST_VECTOR_NUNITS (x
);
3783 for (i
= 0; i
< units
; i
++)
3785 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3786 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3796 /* Worker function for output_constant_pool. Emit constant DESC,
3797 giving it ALIGN bits of alignment. */
3800 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3807 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3808 whose CODE_LABEL has been deleted. This can occur if a jump table
3809 is eliminated by optimization. If so, write a constant of zero
3810 instead. Note that this can also happen by turning the
3811 CODE_LABEL into a NOTE. */
3812 /* ??? This seems completely and utterly wrong. Certainly it's
3813 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3814 functioning even with INSN_DELETED_P and friends. */
3817 switch (GET_CODE (tmp
))
3820 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3821 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3823 tmp
= XEXP (XEXP (tmp
, 0), 0);
3827 tmp
= XEXP (tmp
, 0);
3828 gcc_assert (!INSN_DELETED_P (tmp
));
3829 gcc_assert (!NOTE_P (tmp
)
3830 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3837 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3838 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3839 align
, desc
->labelno
, done
);
3842 assemble_align (align
);
3844 /* Output the label. */
3845 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3847 /* Output the data. */
3848 output_constant_pool_2 (desc
->mode
, x
, align
);
3850 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3851 sections have proper size. */
3852 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3854 && (in_section
->common
.flags
& SECTION_MERGE
))
3855 assemble_align (align
);
3857 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3863 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3864 to as used. Emit referenced deferred strings. This function can
3865 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3868 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
3870 rtx x
= *current_rtx
;
3872 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3875 if (CONSTANT_POOL_ADDRESS_P (x
))
3877 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3878 if (desc
->mark
== 0)
3881 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
3884 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3886 tree exp
= SYMBOL_REF_DECL (x
);
3887 if (!TREE_ASM_WRITTEN (exp
))
3889 n_deferred_constants
--;
3890 output_constant_def_contents (x
);
3897 /* Look through appropriate parts of INSN, marking all entries in the
3898 constant pool which are actually being used. Entries that are only
3899 referenced by other constants are also marked as used. Emit
3900 deferred strings that are used. */
3903 mark_constants (rtx insn
)
3908 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3909 insns, not any notes that may be attached. We don't want to mark
3910 a constant just because it happens to appear in a REG_EQUIV note. */
3911 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3913 rtx seq
= PATTERN (insn
);
3914 int i
, n
= XVECLEN (seq
, 0);
3915 for (i
= 0; i
< n
; ++i
)
3917 rtx subinsn
= XVECEXP (seq
, 0, i
);
3918 if (INSN_P (subinsn
))
3919 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
3923 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
3926 /* Look through the instructions for this function, and mark all the
3927 entries in POOL which are actually being used. Emit deferred constants
3928 which have indeed been used. */
3931 mark_constant_pool (void)
3935 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
3938 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3939 mark_constants (insn
);
3941 for (link
= crtl
->epilogue_delay_list
;
3943 link
= XEXP (link
, 1))
3944 mark_constants (XEXP (link
, 0));
3947 /* Write all the constants in POOL. */
3950 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
3952 struct constant_descriptor_rtx
*desc
;
3954 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3957 /* If the constant is part of an object_block, make sure that
3958 the constant has been positioned within its block, but do not
3959 write out its definition yet. output_object_blocks will do
3961 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
3962 && SYMBOL_REF_BLOCK (desc
->sym
))
3963 place_block_symbol (desc
->sym
);
3966 switch_to_section (targetm
.asm_out
.select_rtx_section
3967 (desc
->mode
, desc
->constant
, desc
->align
));
3968 output_constant_pool_1 (desc
, desc
->align
);
3973 /* Mark all constants that are used in the current function, then write
3974 out the function's private constant pool. */
3977 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3978 tree fndecl ATTRIBUTE_UNUSED
)
3980 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
3982 /* It is possible for gcc to call force_const_mem and then to later
3983 discard the instructions which refer to the constant. In such a
3984 case we do not need to output the constant. */
3985 mark_constant_pool ();
3987 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3988 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3991 output_constant_pool_contents (pool
);
3993 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3994 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3998 /* Write the contents of the shared constant pool. */
4001 output_shared_constant_pool (void)
4003 output_constant_pool_contents (shared_constant_pool
);
4006 /* Determine what kind of relocations EXP may need. */
4009 compute_reloc_for_constant (tree exp
)
4011 int reloc
= 0, reloc2
;
4014 switch (TREE_CODE (exp
))
4018 /* Go inside any operations that get_inner_reference can handle and see
4019 if what's inside is a constant: no need to do anything here for
4020 addresses of variables or functions. */
4021 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4022 tem
= TREE_OPERAND (tem
, 0))
4025 if (TREE_PUBLIC (tem
))
4032 case POINTER_PLUS_EXPR
:
4033 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4034 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4038 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4039 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4040 /* The difference of two local labels is computable at link time. */
4041 if (reloc
== 1 && reloc2
== 1)
4048 case VIEW_CONVERT_EXPR
:
4049 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4054 unsigned HOST_WIDE_INT idx
;
4055 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4057 reloc
|= compute_reloc_for_constant (tem
);
4067 /* Find all the constants whose addresses are referenced inside of EXP,
4068 and make sure assembler code with a label has been output for each one.
4069 Indicate whether an ADDR_EXPR has been encountered. */
4072 output_addressed_constants (tree exp
)
4076 switch (TREE_CODE (exp
))
4080 /* Go inside any operations that get_inner_reference can handle and see
4081 if what's inside is a constant: no need to do anything here for
4082 addresses of variables or functions. */
4083 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4084 tem
= TREE_OPERAND (tem
, 0))
4087 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4088 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4089 tem
= DECL_INITIAL (tem
);
4091 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4092 output_constant_def (tem
, 0);
4096 case POINTER_PLUS_EXPR
:
4098 output_addressed_constants (TREE_OPERAND (exp
, 1));
4102 case VIEW_CONVERT_EXPR
:
4103 output_addressed_constants (TREE_OPERAND (exp
, 0));
4108 unsigned HOST_WIDE_INT idx
;
4109 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4111 output_addressed_constants (tem
);
4120 /* Whether a constructor CTOR is a valid static constant initializer if all
4121 its elements are. This used to be internal to initializer_constant_valid_p
4122 and has been exposed to let other functions like categorize_ctor_elements
4123 evaluate the property while walking a constructor for other purposes. */
4126 constructor_static_from_elts_p (const_tree ctor
)
4128 return (TREE_CONSTANT (ctor
)
4129 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4130 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
)
4131 && !VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (ctor
)));
4134 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4137 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4138 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4139 which are valid when ENDTYPE is an integer of any size; in
4140 particular, this does not accept a pointer minus a constant. This
4141 returns null_pointer_node if the VALUE is an absolute constant
4142 which can be used to initialize a static variable. Otherwise it
4146 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4150 if (!INTEGRAL_TYPE_P (endtype
))
4153 op0
= TREE_OPERAND (value
, 0);
4154 op1
= TREE_OPERAND (value
, 1);
4156 /* Like STRIP_NOPS except allow the operand mode to widen. This
4157 works around a feature of fold that simplifies (int)(p1 - p2) to
4158 ((int)p1 - (int)p2) under the theory that the narrower operation
4161 while (CONVERT_EXPR_P (op0
)
4162 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4164 tree inner
= TREE_OPERAND (op0
, 0);
4165 if (inner
== error_mark_node
4166 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4167 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4168 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4173 while (CONVERT_EXPR_P (op1
)
4174 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4176 tree inner
= TREE_OPERAND (op1
, 0);
4177 if (inner
== error_mark_node
4178 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4179 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4180 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4185 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4189 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4190 cache
? cache
+ 2 : NULL
);
4191 /* Both initializers must be known. */
4195 && (op0
== null_pointer_node
4196 || TREE_CODE (value
) == MINUS_EXPR
))
4197 return null_pointer_node
;
4199 /* Support differences between labels. */
4200 if (TREE_CODE (op0
) == LABEL_DECL
4201 && TREE_CODE (op1
) == LABEL_DECL
)
4202 return null_pointer_node
;
4204 if (TREE_CODE (op0
) == STRING_CST
4205 && TREE_CODE (op1
) == STRING_CST
4206 && operand_equal_p (op0
, op1
, 1))
4207 return null_pointer_node
;
4213 /* Helper function of initializer_constant_valid_p.
4214 Return nonzero if VALUE is a valid constant-valued expression
4215 for use in initializing a static variable; one that can be an
4216 element of a "constant" initializer.
4218 Return null_pointer_node if the value is absolute;
4219 if it is relocatable, return the variable that determines the relocation.
4220 We assume that VALUE has been folded as much as possible;
4221 therefore, we do not need to check for such things as
4222 arithmetic-combinations of integers.
4224 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4227 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4231 switch (TREE_CODE (value
))
4234 if (constructor_static_from_elts_p (value
))
4236 unsigned HOST_WIDE_INT idx
;
4238 bool absolute
= true;
4240 if (cache
&& cache
[0] == value
)
4242 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4245 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4252 cache
[1] = NULL_TREE
;
4256 if (reloc
!= null_pointer_node
)
4259 /* For a non-absolute relocation, there is no single
4260 variable that can be "the variable that determines the
4265 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4267 return absolute
? null_pointer_node
: error_mark_node
;
4270 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4278 return null_pointer_node
;
4283 tree op0
= staticp (TREE_OPERAND (value
, 0));
4286 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4287 to be a constant, this is old-skool offsetof-like nonsense. */
4288 if (TREE_CODE (op0
) == INDIRECT_REF
4289 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4290 return null_pointer_node
;
4291 /* Taking the address of a nested function involves a trampoline,
4292 unless we don't need or want one. */
4293 if (TREE_CODE (op0
) == FUNCTION_DECL
4294 && DECL_STATIC_CHAIN (op0
)
4295 && !TREE_NO_TRAMPOLINE (value
))
4297 /* "&{...}" requires a temporary to hold the constructed
4299 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4305 case NON_LVALUE_EXPR
:
4306 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4309 case VIEW_CONVERT_EXPR
:
4311 tree src
= TREE_OPERAND (value
, 0);
4312 tree src_type
= TREE_TYPE (src
);
4313 tree dest_type
= TREE_TYPE (value
);
4315 /* Allow view-conversions from aggregate to non-aggregate type only
4316 if the bit pattern is fully preserved afterwards; otherwise, the
4317 RTL expander won't be able to apply a subsequent transformation
4318 to the underlying constructor. */
4319 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4321 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4322 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4327 /* Allow all other kinds of view-conversion. */
4328 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4333 tree src
= TREE_OPERAND (value
, 0);
4334 tree src_type
= TREE_TYPE (src
);
4335 tree dest_type
= TREE_TYPE (value
);
4337 /* Allow conversions between pointer types, floating-point
4338 types, and offset types. */
4339 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4340 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4341 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4342 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4343 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4345 /* Allow length-preserving conversions between integer types. */
4346 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4347 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4348 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4350 /* Allow conversions between other integer types only if
4352 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4354 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4355 if (inner
== null_pointer_node
)
4356 return null_pointer_node
;
4360 /* Allow (int) &foo provided int is as wide as a pointer. */
4361 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4362 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4363 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4365 /* Likewise conversions from int to pointers, but also allow
4366 conversions from 0. */
4367 if ((POINTER_TYPE_P (dest_type
)
4368 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4369 && INTEGRAL_TYPE_P (src_type
))
4371 if (TREE_CODE (src
) == INTEGER_CST
4372 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4373 return null_pointer_node
;
4374 if (integer_zerop (src
))
4375 return null_pointer_node
;
4376 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4377 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4380 /* Allow conversions to struct or union types if the value
4382 if (TREE_CODE (dest_type
) == RECORD_TYPE
4383 || TREE_CODE (dest_type
) == UNION_TYPE
)
4384 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4388 case POINTER_PLUS_EXPR
:
4390 /* Any valid floating-point constants will have been folded by now;
4391 with -frounding-math we hit this with addition of two constants. */
4392 if (TREE_CODE (endtype
) == REAL_TYPE
)
4394 if (cache
&& cache
[0] == value
)
4396 if (! INTEGRAL_TYPE_P (endtype
)
4397 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4399 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4401 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4404 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4405 endtype
, ncache
+ 2);
4406 /* If either term is absolute, use the other term's relocation. */
4407 if (valid0
== null_pointer_node
)
4409 else if (valid1
== null_pointer_node
)
4411 /* Support narrowing pointer differences. */
4413 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4417 /* Support narrowing pointer differences. */
4418 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4427 if (TREE_CODE (endtype
) == REAL_TYPE
)
4429 if (cache
&& cache
[0] == value
)
4431 if (! INTEGRAL_TYPE_P (endtype
)
4432 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4434 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4436 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4439 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4440 endtype
, ncache
+ 2);
4441 /* Win if second argument is absolute. */
4442 if (valid1
== null_pointer_node
)
4444 /* Win if both arguments have the same relocation.
4445 Then the value is absolute. */
4446 else if (valid0
== valid1
&& valid0
!= 0)
4447 ret
= null_pointer_node
;
4448 /* Since GCC guarantees that string constants are unique in the
4449 generated code, a subtraction between two copies of the same
4450 constant string is absolute. */
4451 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4452 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4453 && operand_equal_p (valid0
, valid1
, 1))
4454 ret
= null_pointer_node
;
4455 /* Support narrowing differences. */
4457 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4461 /* Support narrowing differences. */
4462 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4477 /* Return nonzero if VALUE is a valid constant-valued expression
4478 for use in initializing a static variable; one that can be an
4479 element of a "constant" initializer.
4481 Return null_pointer_node if the value is absolute;
4482 if it is relocatable, return the variable that determines the relocation.
4483 We assume that VALUE has been folded as much as possible;
4484 therefore, we do not need to check for such things as
4485 arithmetic-combinations of integers. */
4487 initializer_constant_valid_p (tree value
, tree endtype
)
4489 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4492 /* Return true if VALUE is a valid constant-valued expression
4493 for use in initializing a static bit-field; one that can be
4494 an element of a "constant" initializer. */
4497 initializer_constant_valid_for_bitfield_p (tree value
)
4499 /* For bitfields we support integer constants or possibly nested aggregates
4501 switch (TREE_CODE (value
))
4505 unsigned HOST_WIDE_INT idx
;
4508 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4509 if (!initializer_constant_valid_for_bitfield_p (elt
))
4517 case VIEW_CONVERT_EXPR
:
4518 case NON_LVALUE_EXPR
:
4520 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4529 /* output_constructor outer state of relevance in recursive calls, typically
4530 for nested aggregate bitfields. */
4533 unsigned int bit_offset
; /* current position in ... */
4534 int byte
; /* ... the outer byte buffer. */
4537 static unsigned HOST_WIDE_INT
4538 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4541 /* Output assembler code for constant EXP to FILE, with no label.
4542 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4543 Assumes output_addressed_constants has been done on EXP already.
4545 Generate exactly SIZE bytes of assembler data, padding at the end
4546 with zeros if necessary. SIZE must always be specified.
4548 SIZE is important for structure constructors,
4549 since trailing members may have been omitted from the constructor.
4550 It is also important for initialization of arrays from string constants
4551 since the full length of the string constant might not be wanted.
4552 It is also needed for initialization of unions, where the initializer's
4553 type is just one member, and that may not be as long as the union.
4555 There a case in which we would fail to output exactly SIZE bytes:
4556 for a structure constructor that wants to produce more than SIZE bytes.
4557 But such constructors will never be generated for any possible input.
4559 ALIGN is the alignment of the data in bits. */
4562 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4564 enum tree_code code
;
4565 unsigned HOST_WIDE_INT thissize
;
4567 if (size
== 0 || flag_syntax_only
)
4570 /* See if we're trying to initialize a pointer in a non-default mode
4571 to the address of some declaration somewhere. If the target says
4572 the mode is valid for pointers, assume the target has a way of
4574 if (TREE_CODE (exp
) == NOP_EXPR
4575 && POINTER_TYPE_P (TREE_TYPE (exp
))
4576 && targetm
.addr_space
.valid_pointer_mode
4577 (TYPE_MODE (TREE_TYPE (exp
)),
4578 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4580 tree saved_type
= TREE_TYPE (exp
);
4582 /* Peel off any intermediate conversions-to-pointer for valid
4584 while (TREE_CODE (exp
) == NOP_EXPR
4585 && POINTER_TYPE_P (TREE_TYPE (exp
))
4586 && targetm
.addr_space
.valid_pointer_mode
4587 (TYPE_MODE (TREE_TYPE (exp
)),
4588 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4589 exp
= TREE_OPERAND (exp
, 0);
4591 /* If what we're left with is the address of something, we can
4592 convert the address to the final type and output it that
4594 if (TREE_CODE (exp
) == ADDR_EXPR
)
4595 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4596 /* Likewise for constant ints. */
4597 else if (TREE_CODE (exp
) == INTEGER_CST
)
4598 exp
= build_int_cst_wide (saved_type
, TREE_INT_CST_LOW (exp
),
4599 TREE_INT_CST_HIGH (exp
));
4603 /* Eliminate any conversions since we'll be outputting the underlying
4605 while (CONVERT_EXPR_P (exp
)
4606 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4607 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4609 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4610 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4612 /* Make sure eliminating the conversion is really a no-op, except with
4613 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4614 union types to allow for Ada unchecked unions. */
4615 if (type_size
> op_size
4616 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4617 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4618 /* Keep the conversion. */
4621 exp
= TREE_OPERAND (exp
, 0);
4624 code
= TREE_CODE (TREE_TYPE (exp
));
4625 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4627 /* Allow a constructor with no elements for any data type.
4628 This means to fill the space with zeros. */
4629 if (TREE_CODE (exp
) == CONSTRUCTOR
4630 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
4632 assemble_zeros (size
);
4636 if (TREE_CODE (exp
) == FDESC_EXPR
)
4638 #ifdef ASM_OUTPUT_FDESC
4639 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4640 tree decl
= TREE_OPERAND (exp
, 0);
4641 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4648 /* Now output the underlying data. If we've handling the padding, return.
4649 Otherwise, break and ensure SIZE is the size written. */
4656 case REFERENCE_TYPE
:
4658 case FIXED_POINT_TYPE
:
4659 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4660 EXPAND_INITIALIZER
),
4661 MIN (size
, thissize
), align
, 0))
4662 error ("initializer for integer/fixed-point value is too complicated");
4666 if (TREE_CODE (exp
) != REAL_CST
)
4667 error ("initializer for floating value is not a floating constant");
4669 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4673 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4674 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4675 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4680 switch (TREE_CODE (exp
))
4683 output_constructor (exp
, size
, align
, NULL
);
4686 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
4688 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4695 unsigned int nalign
;
4696 enum machine_mode inner
;
4698 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4699 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4701 elt_size
= GET_MODE_SIZE (inner
);
4703 link
= TREE_VECTOR_CST_ELTS (exp
);
4704 output_constant (TREE_VALUE (link
), elt_size
, align
);
4705 thissize
= elt_size
;
4706 while ((link
= TREE_CHAIN (link
)) != NULL
)
4708 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
4709 thissize
+= elt_size
;
4720 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4721 output_constructor (exp
, size
, align
, NULL
);
4731 if (size
> thissize
)
4732 assemble_zeros (size
- thissize
);
4736 /* Subroutine of output_constructor, used for computing the size of
4737 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4738 type with an unspecified upper bound. */
4740 static unsigned HOST_WIDE_INT
4741 array_size_for_constructor (tree val
)
4744 unsigned HOST_WIDE_INT cnt
;
4745 tree index
, value
, tmp
;
4747 /* This code used to attempt to handle string constants that are not
4748 arrays of single-bytes, but nothing else does, so there's no point in
4750 if (TREE_CODE (val
) == STRING_CST
)
4751 return TREE_STRING_LENGTH (val
);
4753 max_index
= NULL_TREE
;
4754 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4756 if (TREE_CODE (index
) == RANGE_EXPR
)
4757 index
= TREE_OPERAND (index
, 1);
4758 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4762 if (max_index
== NULL_TREE
)
4765 /* Compute the total number of array elements. */
4766 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4767 i
= size_binop (MINUS_EXPR
, fold_convert (sizetype
, max_index
),
4768 fold_convert (sizetype
, tmp
));
4769 i
= size_binop (PLUS_EXPR
, i
, build_int_cst (sizetype
, 1));
4771 /* Multiply by the array element unit size to find number of bytes. */
4772 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4774 return tree_low_cst (i
, 1);
4777 /* Other datastructures + helpers for output_constructor. */
4779 /* output_constructor local state to support interaction with helpers. */
4783 /* Received arguments. */
4784 tree exp
; /* Constructor expression. */
4785 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4786 unsigned int align
; /* Known initial alignment. */
4788 /* Constructor expression data. */
4789 tree type
; /* Expression type. */
4790 tree field
; /* Current field decl in a record. */
4791 tree min_index
; /* Lower bound if specified for an array. */
4793 /* Output processing state. */
4794 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4795 bool byte_buffer_in_use
; /* Whether byte ... */
4796 int byte
; /* ... contains part of a bitfield byte yet to
4799 int last_relative_index
; /* Implicit or explicit index of the last
4800 array element output within a bitfield. */
4801 /* Current element. */
4802 tree val
; /* Current element value. */
4803 tree index
; /* Current element index. */
4807 /* Helper for output_constructor. From the current LOCAL state, output a
4808 RANGE_EXPR element. */
4811 output_constructor_array_range (oc_local_state
*local
)
4813 unsigned HOST_WIDE_INT fieldsize
4814 = int_size_in_bytes (TREE_TYPE (local
->type
));
4816 HOST_WIDE_INT lo_index
4817 = tree_low_cst (TREE_OPERAND (local
->index
, 0), 0);
4818 HOST_WIDE_INT hi_index
4819 = tree_low_cst (TREE_OPERAND (local
->index
, 1), 0);
4820 HOST_WIDE_INT index
;
4823 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4825 for (index
= lo_index
; index
<= hi_index
; index
++)
4827 /* Output the element's initial value. */
4828 if (local
->val
== NULL_TREE
)
4829 assemble_zeros (fieldsize
);
4831 output_constant (local
->val
, fieldsize
, align2
);
4833 /* Count its size. */
4834 local
->total_bytes
+= fieldsize
;
4838 /* Helper for output_constructor. From the current LOCAL state, output a
4839 field element that is not true bitfield or part of an outer one. */
4842 output_constructor_regular_field (oc_local_state
*local
)
4844 /* Field size and position. Since this structure is static, we know the
4845 positions are constant. */
4846 unsigned HOST_WIDE_INT fieldsize
;
4847 HOST_WIDE_INT fieldpos
;
4849 unsigned int align2
;
4851 if (local
->index
!= NULL_TREE
)
4852 fieldpos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
)), 1)
4853 * ((tree_low_cst (local
->index
, 0)
4854 - tree_low_cst (local
->min_index
, 0))));
4855 else if (local
->field
!= NULL_TREE
)
4856 fieldpos
= int_byte_position (local
->field
);
4860 /* Output any buffered-up bit-fields preceding this element. */
4861 if (local
->byte_buffer_in_use
)
4863 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4864 local
->total_bytes
++;
4865 local
->byte_buffer_in_use
= false;
4868 /* Advance to offset of this element.
4869 Note no alignment needed in an array, since that is guaranteed
4870 if each element has the proper size. */
4871 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4872 && fieldpos
!= local
->total_bytes
)
4874 gcc_assert (fieldpos
>= local
->total_bytes
);
4875 assemble_zeros (fieldpos
- local
->total_bytes
);
4876 local
->total_bytes
= fieldpos
;
4879 /* Find the alignment of this element. */
4880 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
4882 /* Determine size this element should occupy. */
4887 /* If this is an array with an unspecified upper bound,
4888 the initializer determines the size. */
4889 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4890 but we cannot do this until the deprecated support for
4891 initializing zero-length array members is removed. */
4892 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
4893 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
4894 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
4896 fieldsize
= array_size_for_constructor (local
->val
);
4897 /* Given a non-empty initialization, this field had
4899 gcc_assert (!fieldsize
|| !TREE_CHAIN (local
->field
));
4901 else if (DECL_SIZE_UNIT (local
->field
))
4903 /* ??? This can't be right. If the decl size overflows
4904 a host integer we will silently emit no data. */
4905 if (host_integerp (DECL_SIZE_UNIT (local
->field
), 1))
4906 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (local
->field
), 1);
4910 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
4912 /* Output the element's initial value. */
4913 if (local
->val
== NULL_TREE
)
4914 assemble_zeros (fieldsize
);
4916 output_constant (local
->val
, fieldsize
, align2
);
4918 /* Count its size. */
4919 local
->total_bytes
+= fieldsize
;
4922 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4923 output an element that is a true bitfield or part of an outer one. */
4926 output_constructor_bitfield (oc_local_state
*local
, oc_outer_state
*outer
)
4928 /* Bit size of this element. */
4929 HOST_WIDE_INT ebitsize
4931 ? tree_low_cst (DECL_SIZE (local
->field
), 1)
4932 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local
->type
)), 1));
4934 /* Relative index of this element if this is an array component. */
4935 HOST_WIDE_INT relative_index
4938 ? (tree_low_cst (local
->index
, 0)
4939 - tree_low_cst (local
->min_index
, 0))
4940 : local
->last_relative_index
+ 1)
4943 /* Bit position of this element from the start of the containing
4945 HOST_WIDE_INT constructor_relative_ebitpos
4947 ? int_bit_position (local
->field
)
4948 : ebitsize
* relative_index
);
4950 /* Bit position of this element from the start of a possibly ongoing
4951 outer byte buffer. */
4952 HOST_WIDE_INT byte_relative_ebitpos
4953 = ((outer
? outer
->bit_offset
: 0) + constructor_relative_ebitpos
);
4955 /* From the start of a possibly ongoing outer byte buffer, offsets to
4956 the first bit of this element and to the first bit past the end of
4958 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
4959 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
4961 local
->last_relative_index
= relative_index
;
4963 if (local
->val
== NULL_TREE
)
4964 local
->val
= integer_zero_node
;
4966 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
4967 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
4968 local
->val
= TREE_OPERAND (local
->val
, 0);
4970 if (TREE_CODE (local
->val
) != INTEGER_CST
4971 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
4973 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
4977 /* If this field does not start in this (or, next) byte,
4979 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4981 /* Output remnant of any bit field in previous bytes. */
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 /* If still not at proper byte, advance to there. */
4990 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4992 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
4993 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
4994 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
4998 /* Set up the buffer if necessary. */
4999 if (!local
->byte_buffer_in_use
)
5003 local
->byte_buffer_in_use
= true;
5006 /* If this is nested constructor, recurse passing the bit offset and the
5007 pending data, then retrieve the new pending data afterwards. */
5008 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
5010 oc_outer_state output_state
;
5012 output_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
5013 output_state
.byte
= local
->byte
;
5015 += output_constructor (local
->val
, 0, 0, &output_state
);
5016 local
->byte
= output_state
.byte
;
5020 /* Otherwise, we must split the element into pieces that fall within
5021 separate bytes, and combine each byte with previous or following
5023 while (next_offset
< end_offset
)
5027 HOST_WIDE_INT value
;
5028 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5029 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5031 /* Advance from byte to byte
5032 within this element when necessary. */
5033 while (next_byte
!= local
->total_bytes
)
5035 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5036 local
->total_bytes
++;
5040 /* Number of bits we can process at once
5041 (all part of the same byte). */
5042 this_time
= MIN (end_offset
- next_offset
,
5043 BITS_PER_UNIT
- next_bit
);
5044 if (BYTES_BIG_ENDIAN
)
5046 /* On big-endian machine, take the most significant bits
5047 first (of the bits that are significant)
5048 and put them into bytes from the most significant end. */
5049 shift
= end_offset
- next_offset
- this_time
;
5051 /* Don't try to take a bunch of bits that cross
5052 the word boundary in the INTEGER_CST. We can
5053 only select bits from the LOW or HIGH part
5055 if (shift
< HOST_BITS_PER_WIDE_INT
5056 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
5058 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
5059 shift
= HOST_BITS_PER_WIDE_INT
;
5062 /* Now get the bits from the appropriate constant word. */
5063 if (shift
< HOST_BITS_PER_WIDE_INT
)
5064 value
= TREE_INT_CST_LOW (local
->val
);
5067 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
5068 value
= TREE_INT_CST_HIGH (local
->val
);
5069 shift
-= HOST_BITS_PER_WIDE_INT
;
5072 /* Get the result. This works only when:
5073 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5074 local
->byte
|= (((value
>> shift
)
5075 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5076 << (BITS_PER_UNIT
- this_time
- next_bit
));
5080 /* On little-endian machines,
5081 take first the least significant bits of the value
5082 and pack them starting at the least significant
5083 bits of the bytes. */
5084 shift
= next_offset
- byte_relative_ebitpos
;
5086 /* Don't try to take a bunch of bits that cross
5087 the word boundary in the INTEGER_CST. We can
5088 only select bits from the LOW or HIGH part
5090 if (shift
< HOST_BITS_PER_WIDE_INT
5091 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
5092 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
5094 /* Now get the bits from the appropriate constant word. */
5095 if (shift
< HOST_BITS_PER_WIDE_INT
)
5096 value
= TREE_INT_CST_LOW (local
->val
);
5099 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
5100 value
= TREE_INT_CST_HIGH (local
->val
);
5101 shift
-= HOST_BITS_PER_WIDE_INT
;
5104 /* Get the result. This works only when:
5105 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5106 local
->byte
|= (((value
>> shift
)
5107 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5111 next_offset
+= this_time
;
5112 local
->byte_buffer_in_use
= true;
5116 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5117 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5118 caller output state of relevance in recursive invocations. */
5120 static unsigned HOST_WIDE_INT
5121 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5122 unsigned int align
, oc_outer_state
* outer
)
5124 unsigned HOST_WIDE_INT cnt
;
5125 constructor_elt
*ce
;
5127 oc_local_state local
;
5129 /* Setup our local state to communicate with helpers. */
5132 local
.align
= align
;
5134 local
.total_bytes
= 0;
5135 local
.byte_buffer_in_use
= outer
!= NULL
;
5136 local
.byte
= outer
? outer
->byte
: 0;
5138 local
.type
= TREE_TYPE (exp
);
5140 local
.last_relative_index
= -1;
5142 local
.min_index
= NULL_TREE
;
5143 if (TREE_CODE (local
.type
) == ARRAY_TYPE
5144 && TYPE_DOMAIN (local
.type
) != NULL_TREE
)
5145 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5147 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5149 /* As CE goes through the elements of the constant, FIELD goes through the
5150 structure fields if the constant is a structure. If the constant is a
5151 union, we override this by getting the field from the TREE_LIST element.
5152 But the constant could also be an array. Then FIELD is zero.
5154 There is always a maximum of one element in the chain LINK for unions
5155 (even if the initializer in a source program incorrectly contains
5158 local
.field
= NULL_TREE
;
5159 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5160 local
.field
= TYPE_FIELDS (local
.type
);
5163 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
5164 cnt
++, local
.field
= local
.field
? TREE_CHAIN (local
.field
) : 0)
5166 local
.val
= ce
->value
;
5167 local
.index
= NULL_TREE
;
5169 /* The element in a union constructor specifies the proper field
5171 if ((TREE_CODE (local
.type
) == RECORD_TYPE
5172 || TREE_CODE (local
.type
) == UNION_TYPE
5173 || TREE_CODE (local
.type
) == QUAL_UNION_TYPE
)
5174 && ce
->index
!= NULL_TREE
)
5175 local
.field
= ce
->index
;
5177 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5178 local
.index
= ce
->index
;
5180 #ifdef ASM_COMMENT_START
5181 if (local
.field
&& flag_verbose_asm
)
5182 fprintf (asm_out_file
, "%s %s:\n",
5184 DECL_NAME (local
.field
)
5185 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5189 /* Eliminate the marker that makes a cast not be an lvalue. */
5190 if (local
.val
!= NULL_TREE
)
5191 STRIP_NOPS (local
.val
);
5193 /* Output the current element, using the appropriate helper ... */
5195 /* For an array slice not part of an outer bitfield. */
5197 && local
.index
!= NULL_TREE
5198 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5199 output_constructor_array_range (&local
);
5201 /* For a field that is neither a true bitfield nor part of an outer one,
5202 known to be at least byte aligned and multiple-of-bytes long. */
5204 && (local
.field
== NULL_TREE
5205 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5206 output_constructor_regular_field (&local
);
5208 /* For a true bitfield or part of an outer one. */
5210 output_constructor_bitfield (&local
, outer
);
5213 /* If we are not at toplevel, save the pending data for our caller.
5214 Otherwise output the pending data and padding zeros as needed. */
5216 outer
->byte
= local
.byte
;
5219 if (local
.byte_buffer_in_use
)
5221 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5222 local
.total_bytes
++;
5225 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5227 assemble_zeros (local
.size
- local
.total_bytes
);
5228 local
.total_bytes
= local
.size
;
5232 return local
.total_bytes
;
5235 /* Mark DECL as weak. */
5238 mark_weak (tree decl
)
5240 DECL_WEAK (decl
) = 1;
5242 if (DECL_RTL_SET_P (decl
)
5243 && MEM_P (DECL_RTL (decl
))
5244 && XEXP (DECL_RTL (decl
), 0)
5245 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5246 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5249 /* Merge weak status between NEWDECL and OLDDECL. */
5252 merge_weak (tree newdecl
, tree olddecl
)
5254 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5256 if (DECL_WEAK (newdecl
) && SUPPORTS_WEAK
)
5259 /* We put the NEWDECL on the weak_decls list at some point
5260 and OLDDECL as well. Keep just OLDDECL on the list. */
5261 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5262 if (TREE_VALUE (*pwd
) == newdecl
)
5264 *pwd
= TREE_CHAIN (*pwd
);
5271 if (DECL_WEAK (newdecl
))
5275 /* NEWDECL is weak, but OLDDECL is not. */
5277 /* If we already output the OLDDECL, we're in trouble; we can't
5278 go back and make it weak. This error cannot be caught in
5279 declare_weak because the NEWDECL and OLDDECL was not yet
5280 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5281 if (TREE_ASM_WRITTEN (olddecl
))
5282 error ("weak declaration of %q+D must precede definition",
5285 /* If we've already generated rtl referencing OLDDECL, we may
5286 have done so in a way that will not function properly with
5288 else if (TREE_USED (olddecl
)
5289 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
5290 warning (0, "weak declaration of %q+D after first use results "
5291 "in unspecified behavior", newdecl
);
5295 /* We put the NEWDECL on the weak_decls list at some point.
5296 Replace it with the OLDDECL. */
5297 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5298 if (TREE_VALUE (wd
) == newdecl
)
5300 TREE_VALUE (wd
) = olddecl
;
5303 /* We may not find the entry on the list. If NEWDECL is a
5304 weak alias, then we will have already called
5305 globalize_decl to remove the entry; in that case, we do
5306 not need to do anything. */
5309 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5310 mark_weak (olddecl
);
5313 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5314 weak. Just update NEWDECL to indicate that it's weak too. */
5315 mark_weak (newdecl
);
5318 /* Declare DECL to be a weak symbol. */
5321 declare_weak (tree decl
)
5323 if (! TREE_PUBLIC (decl
))
5324 error ("weak declaration of %q+D must be public", decl
);
5325 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
5326 error ("weak declaration of %q+D must precede definition", decl
);
5327 else if (!SUPPORTS_WEAK
)
5328 warning (0, "weak declaration of %q+D not supported", decl
);
5331 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5332 DECL_ATTRIBUTES (decl
)
5333 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5337 weak_finish_1 (tree decl
)
5339 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5340 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5343 if (! TREE_USED (decl
))
5346 #ifdef ASM_WEAKEN_DECL
5347 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5349 #ifdef ASM_WEAKEN_LABEL
5350 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5352 #ifdef ASM_OUTPUT_WEAK_ALIAS
5354 static bool warn_once
= 0;
5357 warning (0, "only weak aliases are supported in this configuration");
5367 /* This TREE_LIST contains weakref targets. */
5369 static GTY(()) tree weakref_targets
;
5371 /* Forward declaration. */
5372 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
5374 /* Emit any pending weak declarations. */
5381 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5383 tree alias_decl
= TREE_PURPOSE (t
);
5384 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5386 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5387 /* Remove alias_decl from the weak list, but leave entries for
5388 the target alone. */
5390 #ifndef ASM_OUTPUT_WEAKREF
5391 else if (! TREE_SYMBOL_REFERENCED (target
))
5393 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5394 defined, otherwise we and weak_finish_1 would use
5395 different macros. */
5396 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5397 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5399 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
5403 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5404 TREE_CODE (alias_decl
), target
,
5405 TREE_TYPE (alias_decl
));
5407 DECL_EXTERNAL (decl
) = 1;
5408 TREE_PUBLIC (decl
) = 1;
5409 DECL_ARTIFICIAL (decl
) = 1;
5410 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5411 TREE_USED (decl
) = 1;
5414 weak_finish_1 (decl
);
5423 /* Remove the alias and the target from the pending weak list
5424 so that we do not emit any .weak directives for the former,
5425 nor multiple .weak directives for the latter. */
5426 for (p
= &weak_decls
; (t2
= *p
) ; )
5428 if (TREE_VALUE (t2
) == alias_decl
5429 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5430 *p
= TREE_CHAIN (t2
);
5432 p
= &TREE_CHAIN (t2
);
5435 /* Remove other weakrefs to the same target, to speed things up. */
5436 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5438 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5439 *p
= TREE_CHAIN (t2
);
5441 p
= &TREE_CHAIN (t2
);
5446 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5448 tree decl
= TREE_VALUE (t
);
5450 weak_finish_1 (decl
);
5454 /* Emit the assembly bits to indicate that DECL is globally visible. */
5457 globalize_decl (tree decl
)
5460 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5461 if (DECL_WEAK (decl
))
5463 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5466 #ifdef ASM_WEAKEN_DECL
5467 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5469 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5472 /* Remove this function from the pending weak list so that
5473 we do not emit multiple .weak directives for it. */
5474 for (p
= &weak_decls
; (t
= *p
) ; )
5476 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5477 *p
= TREE_CHAIN (t
);
5479 p
= &TREE_CHAIN (t
);
5482 /* Remove weakrefs to the same target from the pending weakref
5483 list, for the same reason. */
5484 for (p
= &weakref_targets
; (t
= *p
) ; )
5486 if (DECL_ASSEMBLER_NAME (decl
)
5487 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5488 *p
= TREE_CHAIN (t
);
5490 p
= &TREE_CHAIN (t
);
5497 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5500 VEC(alias_pair
,gc
) *alias_pairs
;
5502 /* Given an assembly name, find the decl it is associated with. At the
5503 same time, mark it needed for cgraph. */
5506 find_decl_and_mark_needed (tree decl
, tree target
)
5508 struct cgraph_node
*fnode
= NULL
;
5509 struct varpool_node
*vnode
= NULL
;
5511 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5513 fnode
= cgraph_node_for_asm (target
);
5515 vnode
= varpool_node_for_asm (target
);
5519 vnode
= varpool_node_for_asm (target
);
5521 fnode
= cgraph_node_for_asm (target
);
5526 cgraph_mark_needed_node (fnode
);
5531 varpool_mark_needed_node (vnode
);
5538 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5539 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5540 tree node is DECL to have the value of the tree node TARGET. */
5543 do_assemble_alias (tree decl
, tree target
)
5545 if (TREE_ASM_WRITTEN (decl
))
5548 /* We must force creation of DECL_RTL for debug info generation, even though
5549 we don't use it here. */
5550 make_decl_rtl (decl
);
5552 TREE_ASM_WRITTEN (decl
) = 1;
5553 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5555 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5557 ultimate_transparent_alias_target (&target
);
5559 if (!targetm
.have_tls
5560 && TREE_CODE (decl
) == VAR_DECL
5561 && DECL_THREAD_LOCAL_P (decl
))
5563 decl
= emutls_decl (decl
);
5564 target
= get_emutls_object_name (target
);
5567 if (!TREE_SYMBOL_REFERENCED (target
))
5568 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5570 #ifdef ASM_OUTPUT_WEAKREF
5571 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5572 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5573 IDENTIFIER_POINTER (target
));
5577 error_at (DECL_SOURCE_LOCATION (decl
),
5578 "weakref is not supported in this configuration");
5585 if (!targetm
.have_tls
5586 && TREE_CODE (decl
) == VAR_DECL
5587 && DECL_THREAD_LOCAL_P (decl
))
5589 decl
= emutls_decl (decl
);
5590 target
= get_emutls_object_name (target
);
5593 #ifdef ASM_OUTPUT_DEF
5594 /* Make name accessible from other files, if appropriate. */
5596 if (TREE_PUBLIC (decl
))
5598 globalize_decl (decl
);
5599 maybe_assemble_visibility (decl
);
5602 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5603 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5605 ASM_OUTPUT_DEF (asm_out_file
,
5606 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5607 IDENTIFIER_POINTER (target
));
5609 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5614 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5615 # ifdef ASM_WEAKEN_DECL
5616 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5618 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5620 /* Remove this function from the pending weak list so that
5621 we do not emit multiple .weak directives for it. */
5622 for (p
= &weak_decls
; (t
= *p
) ; )
5623 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5624 *p
= TREE_CHAIN (t
);
5626 p
= &TREE_CHAIN (t
);
5628 /* Remove weakrefs to the same target from the pending weakref
5629 list, for the same reason. */
5630 for (p
= &weakref_targets
; (t
= *p
) ; )
5632 if (DECL_ASSEMBLER_NAME (decl
)
5633 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5634 *p
= TREE_CHAIN (t
);
5636 p
= &TREE_CHAIN (t
);
5643 /* Remove the alias pairing for functions that are no longer in the call
5647 remove_unreachable_alias_pairs (void)
5652 if (alias_pairs
== NULL
)
5655 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); )
5657 if (!DECL_EXTERNAL (p
->decl
))
5659 struct cgraph_node
*fnode
= NULL
;
5660 struct varpool_node
*vnode
= NULL
;
5661 fnode
= cgraph_node_for_asm (p
->target
);
5662 vnode
= (fnode
== NULL
) ? varpool_node_for_asm (p
->target
) : NULL
;
5663 if (fnode
== NULL
&& vnode
== NULL
)
5665 VEC_unordered_remove (alias_pair
, alias_pairs
, i
);
5675 /* First pass of completing pending aliases. Make sure that cgraph knows
5676 which symbols will be required. */
5679 finish_aliases_1 (void)
5684 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
5688 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
5689 if (target_decl
== NULL
)
5691 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5692 error ("%q+D aliased to undefined symbol %qE",
5693 p
->decl
, p
->target
);
5695 else if (DECL_EXTERNAL (target_decl
)
5696 /* We use local aliases for C++ thunks to force the tailcall
5697 to bind locally. Of course this is a hack - to keep it
5698 working do the following (which is not strictly correct). */
5699 && (! TREE_CODE (target_decl
) == FUNCTION_DECL
5700 || ! DECL_VIRTUAL_P (target_decl
))
5701 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5702 error ("%q+D aliased to external symbol %qE",
5703 p
->decl
, p
->target
);
5707 /* Second pass of completing pending aliases. Emit the actual assembly.
5708 This happens at the end of compilation and thus it is assured that the
5709 target symbol has been emitted. */
5712 finish_aliases_2 (void)
5717 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
5718 do_assemble_alias (p
->decl
, p
->target
);
5720 VEC_truncate (alias_pair
, alias_pairs
, 0);
5723 /* Emit an assembler directive to make the symbol for DECL an alias to
5724 the symbol for TARGET. */
5727 assemble_alias (tree decl
, tree target
)
5730 bool is_weakref
= false;
5732 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5734 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5738 ultimate_transparent_alias_target (&target
);
5740 if (alias
== target
)
5741 error ("weakref %q+D ultimately targets itself", decl
);
5744 #ifndef ASM_OUTPUT_WEAKREF
5745 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
5746 TREE_CHAIN (alias
) = target
;
5749 if (TREE_PUBLIC (decl
))
5750 error ("weakref %q+D must have static linkage", decl
);
5754 #if !defined (ASM_OUTPUT_DEF)
5755 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5756 error_at (DECL_SOURCE_LOCATION (decl
),
5757 "alias definitions not supported in this configuration");
5760 if (!DECL_WEAK (decl
))
5762 error_at (DECL_SOURCE_LOCATION (decl
),
5763 "only weak aliases are supported in this configuration");
5769 TREE_USED (decl
) = 1;
5771 /* A quirk of the initial implementation of aliases required that the user
5772 add "extern" to all of them. Which is silly, but now historical. Do
5773 note that the symbol is in fact locally defined. */
5775 DECL_EXTERNAL (decl
) = 0;
5777 /* Allow aliases to aliases. */
5778 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5779 cgraph_node (decl
)->alias
= true;
5781 varpool_node (decl
)->alias
= true;
5783 /* If the target has already been emitted, we don't have to queue the
5784 alias. This saves a tad of memory. */
5785 if (cgraph_global_info_ready
)
5786 target_decl
= find_decl_and_mark_needed (decl
, target
);
5789 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5790 do_assemble_alias (decl
, target
);
5793 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
5799 /* Emit an assembler directive to set symbol for DECL visibility to
5800 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5803 default_assemble_visibility (tree decl
, int vis
)
5805 static const char * const visibility_types
[] = {
5806 NULL
, "protected", "hidden", "internal"
5809 const char *name
, *type
;
5811 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5812 type
= visibility_types
[vis
];
5814 #ifdef HAVE_GAS_HIDDEN
5815 fprintf (asm_out_file
, "\t.%s\t", type
);
5816 assemble_name (asm_out_file
, name
);
5817 fprintf (asm_out_file
, "\n");
5819 warning (OPT_Wattributes
, "visibility attribute not supported "
5820 "in this configuration; ignored");
5824 /* A helper function to call assemble_visibility when needed for a decl. */
5827 maybe_assemble_visibility (tree decl
)
5829 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5831 if (vis
!= VISIBILITY_DEFAULT
)
5833 targetm
.asm_out
.visibility (decl
, vis
);
5840 /* Returns 1 if the target configuration supports defining public symbols
5841 so that one of them will be chosen at link time instead of generating a
5842 multiply-defined symbol error, whether through the use of weak symbols or
5843 a target-specific mechanism for having duplicates discarded. */
5846 supports_one_only (void)
5848 if (SUPPORTS_ONE_ONLY
)
5850 return SUPPORTS_WEAK
;
5853 /* Set up DECL as a public symbol that can be defined in multiple
5854 translation units without generating a linker error. */
5857 make_decl_one_only (tree decl
, tree comdat_group
)
5859 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5860 || TREE_CODE (decl
) == FUNCTION_DECL
);
5862 TREE_PUBLIC (decl
) = 1;
5864 if (SUPPORTS_ONE_ONLY
)
5866 #ifdef MAKE_DECL_ONE_ONLY
5867 MAKE_DECL_ONE_ONLY (decl
);
5869 DECL_COMDAT_GROUP (decl
) = comdat_group
;
5871 else if (TREE_CODE (decl
) == VAR_DECL
5872 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5873 DECL_COMMON (decl
) = 1;
5876 gcc_assert (SUPPORTS_WEAK
);
5877 DECL_WEAK (decl
) = 1;
5882 init_varasm_once (void)
5884 section_htab
= htab_create_ggc (31, section_entry_hash
,
5885 section_entry_eq
, NULL
);
5886 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
5887 object_block_entry_eq
, NULL
);
5888 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
5889 const_desc_eq
, NULL
);
5891 const_alias_set
= new_alias_set ();
5892 shared_constant_pool
= create_constant_pool ();
5894 #ifdef TEXT_SECTION_ASM_OP
5895 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
5896 TEXT_SECTION_ASM_OP
);
5899 #ifdef DATA_SECTION_ASM_OP
5900 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5901 DATA_SECTION_ASM_OP
);
5904 #ifdef SDATA_SECTION_ASM_OP
5905 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5906 SDATA_SECTION_ASM_OP
);
5909 #ifdef READONLY_DATA_SECTION_ASM_OP
5910 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
5911 READONLY_DATA_SECTION_ASM_OP
);
5914 #ifdef CTORS_SECTION_ASM_OP
5915 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
5916 CTORS_SECTION_ASM_OP
);
5919 #ifdef DTORS_SECTION_ASM_OP
5920 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
5921 DTORS_SECTION_ASM_OP
);
5924 #ifdef BSS_SECTION_ASM_OP
5925 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5926 output_section_asm_op
,
5927 BSS_SECTION_ASM_OP
);
5930 #ifdef SBSS_SECTION_ASM_OP
5931 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5932 output_section_asm_op
,
5933 SBSS_SECTION_ASM_OP
);
5936 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5937 | SECTION_COMMON
, emit_tls_common
);
5938 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5939 | SECTION_COMMON
, emit_local
);
5940 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5941 | SECTION_COMMON
, emit_common
);
5943 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5944 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
5948 targetm
.asm_out
.init_sections ();
5950 if (readonly_data_section
== NULL
)
5951 readonly_data_section
= text_section
;
5955 decl_default_tls_model (const_tree decl
)
5957 enum tls_model kind
;
5960 is_local
= targetm
.binds_local_p (decl
);
5964 kind
= TLS_MODEL_LOCAL_EXEC
;
5966 kind
= TLS_MODEL_INITIAL_EXEC
;
5969 /* Local dynamic is inefficient when we're not combining the
5970 parts of the address. */
5971 else if (optimize
&& is_local
)
5972 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
5974 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
5975 if (kind
< flag_tls_default
)
5976 kind
= flag_tls_default
;
5981 /* Select a set of attributes for section NAME based on the properties
5982 of DECL and whether or not RELOC indicates that DECL's initializer
5983 might contain runtime relocations.
5985 We make the section read-only and executable for a function decl,
5986 read-only for a const data decl, and writable for a non-const data decl. */
5989 default_section_type_flags (tree decl
, const char *name
, int reloc
)
5993 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
5994 flags
= SECTION_CODE
;
5995 else if (decl
&& decl_readonly_section (decl
, reloc
))
5997 else if (current_function_decl
5999 && crtl
->subsections
.unlikely_text_section_name
6000 && strcmp (name
, crtl
->subsections
.unlikely_text_section_name
) == 0)
6001 flags
= SECTION_CODE
;
6003 && (!current_function_decl
|| !cfun
)
6004 && strcmp (name
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6005 flags
= SECTION_CODE
;
6007 flags
= SECTION_WRITE
;
6009 if (decl
&& DECL_ONE_ONLY (decl
))
6010 flags
|= SECTION_LINKONCE
;
6012 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6013 flags
|= SECTION_TLS
| SECTION_WRITE
;
6015 if (strcmp (name
, ".bss") == 0
6016 || strncmp (name
, ".bss.", 5) == 0
6017 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6018 || strcmp (name
, ".sbss") == 0
6019 || strncmp (name
, ".sbss.", 6) == 0
6020 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6021 flags
|= SECTION_BSS
;
6023 if (strcmp (name
, ".tdata") == 0
6024 || strncmp (name
, ".tdata.", 7) == 0
6025 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6026 flags
|= SECTION_TLS
;
6028 if (strcmp (name
, ".tbss") == 0
6029 || strncmp (name
, ".tbss.", 6) == 0
6030 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6031 flags
|= SECTION_TLS
| SECTION_BSS
;
6033 /* These three sections have special ELF types. They are neither
6034 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6035 want to print a section type (@progbits or @nobits). If someone
6036 is silly enough to emit code or TLS variables to one of these
6037 sections, then don't handle them specially. */
6038 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
6039 && (strcmp (name
, ".init_array") == 0
6040 || strcmp (name
, ".fini_array") == 0
6041 || strcmp (name
, ".preinit_array") == 0))
6042 flags
|= SECTION_NOTYPE
;
6047 /* Return true if the target supports some form of global BSS,
6048 either through bss_noswitch_section, or by selecting a BSS
6049 section in TARGET_ASM_SELECT_SECTION. */
6052 have_global_bss_p (void)
6054 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6057 /* Output assembly to switch to section NAME with attribute FLAGS.
6058 Four variants for common object file formats. */
6061 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6062 unsigned int flags ATTRIBUTE_UNUSED
,
6063 tree decl ATTRIBUTE_UNUSED
)
6065 /* Some object formats don't support named sections at all. The
6066 front-end should already have flagged this as an error. */
6071 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6072 tree decl ATTRIBUTE_UNUSED
)
6074 char flagchars
[10], *f
= flagchars
;
6076 /* If we have already declared this section, we can use an
6077 abbreviated form to switch back to it -- unless this section is
6078 part of a COMDAT groups, in which case GAS requires the full
6079 declaration every time. */
6080 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6081 && (flags
& SECTION_DECLARED
))
6083 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6087 if (!(flags
& SECTION_DEBUG
))
6089 if (flags
& SECTION_WRITE
)
6091 if (flags
& SECTION_CODE
)
6093 if (flags
& SECTION_SMALL
)
6095 if (flags
& SECTION_MERGE
)
6097 if (flags
& SECTION_STRINGS
)
6099 if (flags
& SECTION_TLS
)
6101 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6105 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6107 if (!(flags
& SECTION_NOTYPE
))
6112 if (flags
& SECTION_BSS
)
6118 #ifdef ASM_COMMENT_START
6119 /* On platforms that use "@" as the assembly comment character,
6121 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6124 fprintf (asm_out_file
, format
, type
);
6126 if (flags
& SECTION_ENTSIZE
)
6127 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6128 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6130 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6131 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6133 fprintf (asm_out_file
, ",%s,comdat",
6134 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6138 putc ('\n', asm_out_file
);
6142 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6143 tree decl ATTRIBUTE_UNUSED
)
6145 char flagchars
[8], *f
= flagchars
;
6147 if (flags
& SECTION_WRITE
)
6149 if (flags
& SECTION_CODE
)
6153 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6157 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6160 default_coff_asm_named_section (name
, flags
, decl
);
6162 if (flags
& SECTION_LINKONCE
)
6164 /* Functions may have been compiled at various levels of
6165 optimization so we can't use `same_size' here.
6166 Instead, have the linker pick one. */
6167 fprintf (asm_out_file
, "\t.linkonce %s\n",
6168 (flags
& SECTION_CODE
? "discard" : "same_size"));
6172 /* The lame default section selector. */
6175 default_select_section (tree decl
, int reloc
,
6176 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6180 if (decl_readonly_section (decl
, reloc
))
6181 return readonly_data_section
;
6183 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6185 if (! ((flag_pic
&& reloc
)
6186 || !TREE_READONLY (decl
)
6187 || TREE_SIDE_EFFECTS (decl
)
6188 || !TREE_CONSTANT (decl
)))
6189 return readonly_data_section
;
6191 else if (TREE_CODE (decl
) == STRING_CST
)
6192 return readonly_data_section
;
6193 else if (! (flag_pic
&& reloc
))
6194 return readonly_data_section
;
6196 return data_section
;
6199 enum section_category
6200 categorize_decl_for_section (const_tree decl
, int reloc
)
6202 enum section_category ret
;
6204 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6206 else if (TREE_CODE (decl
) == STRING_CST
)
6208 if (flag_mudflap
) /* or !flag_merge_constants */
6209 return SECCAT_RODATA
;
6211 return SECCAT_RODATA_MERGE_STR
;
6213 else if (TREE_CODE (decl
) == VAR_DECL
)
6215 if (bss_initializer_p (decl
))
6217 else if (! TREE_READONLY (decl
)
6218 || TREE_SIDE_EFFECTS (decl
)
6219 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6221 /* Here the reloc_rw_mask is not testing whether the section should
6222 be read-only or not, but whether the dynamic link will have to
6223 do something. If so, we wish to segregate the data in order to
6224 minimize cache misses inside the dynamic linker. */
6225 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6226 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6230 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6231 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6232 else if (reloc
|| flag_merge_constants
< 2)
6233 /* C and C++ don't allow different variables to share the same
6234 location. -fmerge-all-constants allows even that (at the
6235 expense of not conforming). */
6236 ret
= SECCAT_RODATA
;
6237 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6238 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6240 ret
= SECCAT_RODATA_MERGE_CONST
;
6242 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6244 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6245 || TREE_SIDE_EFFECTS (decl
)
6246 || ! TREE_CONSTANT (decl
))
6249 ret
= SECCAT_RODATA
;
6252 ret
= SECCAT_RODATA
;
6254 /* There are no read-only thread-local sections. */
6255 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_TLS_MODEL (decl
))
6257 if (DECL_TLS_MODEL (decl
) == TLS_MODEL_EMULATED
)
6259 if (DECL_EMUTLS_VAR_P (decl
))
6261 if (targetm
.emutls
.var_section
)
6262 ret
= SECCAT_EMUTLS_VAR
;
6266 if (targetm
.emutls
.tmpl_prefix
)
6267 ret
= SECCAT_EMUTLS_TMPL
;
6270 /* Note that this would be *just* SECCAT_BSS, except that there's
6271 no concept of a read-only thread-local-data section. */
6272 else if (ret
== SECCAT_BSS
6273 || (flag_zero_initialized_in_bss
6274 && initializer_zerop (DECL_INITIAL (decl
))))
6280 /* If the target uses small data sections, select it. */
6281 else if (targetm
.in_small_data_p (decl
))
6283 if (ret
== SECCAT_BSS
)
6285 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6286 ret
= SECCAT_SRODATA
;
6295 decl_readonly_section (const_tree decl
, int reloc
)
6297 switch (categorize_decl_for_section (decl
, reloc
))
6300 case SECCAT_RODATA_MERGE_STR
:
6301 case SECCAT_RODATA_MERGE_STR_INIT
:
6302 case SECCAT_RODATA_MERGE_CONST
:
6303 case SECCAT_SRODATA
:
6312 /* Select a section based on the above categorization. */
6315 default_elf_select_section (tree decl
, int reloc
,
6316 unsigned HOST_WIDE_INT align
)
6319 switch (categorize_decl_for_section (decl
, reloc
))
6322 /* We're not supposed to be called on FUNCTION_DECLs. */
6325 return readonly_data_section
;
6326 case SECCAT_RODATA_MERGE_STR
:
6327 return mergeable_string_section (decl
, align
, 0);
6328 case SECCAT_RODATA_MERGE_STR_INIT
:
6329 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6330 case SECCAT_RODATA_MERGE_CONST
:
6331 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6332 case SECCAT_SRODATA
:
6336 return data_section
;
6337 case SECCAT_DATA_REL
:
6338 sname
= ".data.rel";
6340 case SECCAT_DATA_REL_LOCAL
:
6341 sname
= ".data.rel.local";
6343 case SECCAT_DATA_REL_RO
:
6344 sname
= ".data.rel.ro";
6346 case SECCAT_DATA_REL_RO_LOCAL
:
6347 sname
= ".data.rel.ro.local";
6366 case SECCAT_EMUTLS_VAR
:
6367 sname
= targetm
.emutls
.var_section
;
6369 case SECCAT_EMUTLS_TMPL
:
6370 sname
= targetm
.emutls
.tmpl_section
;
6378 return get_named_section (decl
, sname
, reloc
);
6381 /* Construct a unique section name based on the decl name and the
6382 categorization performed above. */
6385 default_unique_section (tree decl
, int reloc
)
6387 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6388 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6389 const char *prefix
, *name
, *linkonce
;
6392 switch (categorize_decl_for_section (decl
, reloc
))
6395 prefix
= one_only
? ".t" : ".text";
6398 case SECCAT_RODATA_MERGE_STR
:
6399 case SECCAT_RODATA_MERGE_STR_INIT
:
6400 case SECCAT_RODATA_MERGE_CONST
:
6401 prefix
= one_only
? ".r" : ".rodata";
6403 case SECCAT_SRODATA
:
6404 prefix
= one_only
? ".s2" : ".sdata2";
6407 prefix
= one_only
? ".d" : ".data";
6409 case SECCAT_DATA_REL
:
6410 prefix
= one_only
? ".d.rel" : ".data.rel";
6412 case SECCAT_DATA_REL_LOCAL
:
6413 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6415 case SECCAT_DATA_REL_RO
:
6416 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6418 case SECCAT_DATA_REL_RO_LOCAL
:
6419 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6422 prefix
= one_only
? ".s" : ".sdata";
6425 prefix
= one_only
? ".b" : ".bss";
6428 prefix
= one_only
? ".sb" : ".sbss";
6431 prefix
= one_only
? ".td" : ".tdata";
6434 prefix
= one_only
? ".tb" : ".tbss";
6436 case SECCAT_EMUTLS_VAR
:
6437 prefix
= targetm
.emutls
.var_section
;
6439 case SECCAT_EMUTLS_TMPL
:
6440 prefix
= targetm
.emutls
.tmpl_section
;
6446 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6447 name
= targetm
.strip_name_encoding (name
);
6449 /* If we're using one_only, then there needs to be a .gnu.linkonce
6450 prefix to the section name. */
6451 linkonce
= one_only
? ".gnu.linkonce" : "";
6453 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6455 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6458 /* Like compute_reloc_for_constant, except for an RTX. The return value
6459 is a mask for which bit 1 indicates a global relocation, and bit 0
6460 indicates a local relocation. */
6463 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6465 int *preloc
= (int *) data
;
6468 switch (GET_CODE (x
))
6471 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6484 compute_reloc_for_rtx (rtx x
)
6488 switch (GET_CODE (x
))
6494 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6503 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6505 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6507 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6508 return data_section
;
6510 return readonly_data_section
;
6514 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6515 unsigned HOST_WIDE_INT align
)
6517 int reloc
= compute_reloc_for_rtx (x
);
6519 /* ??? Handle small data here somehow. */
6521 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6524 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6526 return get_named_section (NULL
, ".data.rel.ro", 3);
6529 return mergeable_constant_section (mode
, align
, 0);
6532 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6535 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6540 /* Careful not to prod global register variables. */
6543 symbol
= XEXP (rtl
, 0);
6544 if (GET_CODE (symbol
) != SYMBOL_REF
)
6547 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6548 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6549 flags
|= SYMBOL_FLAG_FUNCTION
;
6550 if (targetm
.binds_local_p (decl
))
6551 flags
|= SYMBOL_FLAG_LOCAL
;
6552 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
)
6553 && DECL_TLS_MODEL (decl
) != TLS_MODEL_EMULATED
)
6554 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6555 else if (targetm
.in_small_data_p (decl
))
6556 flags
|= SYMBOL_FLAG_SMALL
;
6557 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6558 being PUBLIC, the thing *must* be defined in this translation unit.
6559 Prevent this buglet from being propagated into rtl code as well. */
6560 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6561 flags
|= SYMBOL_FLAG_EXTERNAL
;
6563 SYMBOL_REF_FLAGS (symbol
) = flags
;
6566 /* By default, we do nothing for encode_section_info, so we need not
6567 do anything but discard the '*' marker. */
6570 default_strip_name_encoding (const char *str
)
6572 return str
+ (*str
== '*');
6575 #ifdef ASM_OUTPUT_DEF
6576 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6577 anchor relative to ".", the current section position. */
6580 default_asm_output_anchor (rtx symbol
)
6584 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6585 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6586 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6590 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6593 default_use_anchors_for_symbol_p (const_rtx symbol
)
6598 /* Don't use anchors for mergeable sections. The linker might move
6599 the objects around. */
6600 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6601 if (sect
->common
.flags
& SECTION_MERGE
)
6604 /* Don't use anchors for small data sections. The small data register
6605 acts as an anchor for such sections. */
6606 if (sect
->common
.flags
& SECTION_SMALL
)
6609 decl
= SYMBOL_REF_DECL (symbol
);
6610 if (decl
&& DECL_P (decl
))
6612 /* Don't use section anchors for decls that might be defined by
6614 if (!targetm
.binds_local_p (decl
))
6617 /* Don't use section anchors for decls that will be placed in a
6618 small data section. */
6619 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6620 one above. The problem is that we only use SECTION_SMALL for
6621 sections that should be marked as small in the section directive. */
6622 if (targetm
.in_small_data_p (decl
))
6628 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6629 wrt cross-module name binding. */
6632 default_binds_local_p (const_tree exp
)
6634 return default_binds_local_p_1 (exp
, flag_shlib
);
6638 default_binds_local_p_1 (const_tree exp
, int shlib
)
6642 /* A non-decl is an entry in the constant pool. */
6645 /* Weakrefs may not bind locally, even though the weakref itself is
6646 always static and therefore local. */
6647 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
6649 /* Static variables are always local. */
6650 else if (! TREE_PUBLIC (exp
))
6652 /* A variable is local if the user has said explicitly that it will
6654 else if (DECL_VISIBILITY_SPECIFIED (exp
)
6655 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6657 /* Variables defined outside this object might not be local. */
6658 else if (DECL_EXTERNAL (exp
))
6660 /* If defined in this object and visibility is not default, must be
6662 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6664 /* Default visibility weak data can be overridden by a strong symbol
6665 in another module and so are not local. */
6666 else if (DECL_WEAK (exp
))
6668 /* If PIC, then assume that any global name can be overridden by
6669 symbols resolved from other modules, unless we are compiling with
6670 -fwhole-program, which assumes that names are local. */
6672 local_p
= flag_whole_program
;
6673 /* Uninitialized COMMON variable may be unified with symbols
6674 resolved from other modules. */
6675 else if (DECL_COMMON (exp
)
6676 && (DECL_INITIAL (exp
) == NULL
6677 || DECL_INITIAL (exp
) == error_mark_node
))
6679 /* Otherwise we're left with initialized (or non-common) global data
6680 which is of necessity defined locally. */
6687 /* Default function to output code that will globalize a label. A
6688 target must define GLOBAL_ASM_OP or provide its own function to
6689 globalize a label. */
6690 #ifdef GLOBAL_ASM_OP
6692 default_globalize_label (FILE * stream
, const char *name
)
6694 fputs (GLOBAL_ASM_OP
, stream
);
6695 assemble_name (stream
, name
);
6696 putc ('\n', stream
);
6698 #endif /* GLOBAL_ASM_OP */
6700 /* Default function to output code that will globalize a declaration. */
6702 default_globalize_decl_name (FILE * stream
, tree decl
)
6704 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6705 targetm
.asm_out
.globalize_label (stream
, name
);
6708 /* Default function to output a label for unwind information. The
6709 default is to do nothing. A target that needs nonlocal labels for
6710 unwind information must provide its own function to do this. */
6712 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6713 tree decl ATTRIBUTE_UNUSED
,
6714 int for_eh ATTRIBUTE_UNUSED
,
6715 int empty ATTRIBUTE_UNUSED
)
6719 /* Default function to output a label to divide up the exception table.
6720 The default is to do nothing. A target that needs/wants to divide
6721 up the table must provide it's own function to do this. */
6723 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6727 /* This is how to output an internal numbered label where PREFIX is
6728 the class of label and LABELNO is the number within the class. */
6731 default_internal_label (FILE *stream
, const char *prefix
,
6732 unsigned long labelno
)
6734 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6735 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6736 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6739 /* This is the default behavior at the beginning of a file. It's
6740 controlled by two other target-hook toggles. */
6742 default_file_start (void)
6744 if (targetm
.file_start_app_off
6745 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6746 fputs (ASM_APP_OFF
, asm_out_file
);
6748 if (targetm
.file_start_file_directive
)
6749 output_file_directive (asm_out_file
, main_input_filename
);
6752 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6753 which emits a special section directive used to indicate whether or
6754 not this object file needs an executable stack. This is primarily
6755 a GNU extension to ELF but could be used on other targets. */
6757 int trampolines_created
;
6760 file_end_indicate_exec_stack (void)
6762 unsigned int flags
= SECTION_DEBUG
;
6763 if (trampolines_created
)
6764 flags
|= SECTION_CODE
;
6766 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6769 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6770 a get_unnamed_section callback. */
6773 output_section_asm_op (const void *directive
)
6775 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
6778 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6779 the current section is NEW_SECTION. */
6782 switch_to_section (section
*new_section
)
6784 if (in_section
== new_section
)
6787 if (new_section
->common
.flags
& SECTION_FORGET
)
6790 in_section
= new_section
;
6792 switch (SECTION_STYLE (new_section
))
6796 && !crtl
->subsections
.unlikely_text_section_name
6797 && strcmp (new_section
->named
.name
,
6798 UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6799 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
6801 targetm
.asm_out
.named_section (new_section
->named
.name
,
6802 new_section
->named
.common
.flags
,
6803 new_section
->named
.decl
);
6806 case SECTION_UNNAMED
:
6807 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
6810 case SECTION_NOSWITCH
:
6815 new_section
->common
.flags
|= SECTION_DECLARED
;
6818 /* If block symbol SYMBOL has not yet been assigned an offset, place
6819 it at the end of its block. */
6822 place_block_symbol (rtx symbol
)
6824 unsigned HOST_WIDE_INT size
, mask
, offset
;
6825 struct constant_descriptor_rtx
*desc
;
6826 unsigned int alignment
;
6827 struct object_block
*block
;
6830 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
6831 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
6834 /* Work out the symbol's size and alignment. */
6835 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6837 desc
= SYMBOL_REF_CONSTANT (symbol
);
6838 alignment
= desc
->align
;
6839 size
= GET_MODE_SIZE (desc
->mode
);
6841 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6843 decl
= SYMBOL_REF_DECL (symbol
);
6844 alignment
= get_constant_alignment (decl
);
6845 size
= get_constant_size (decl
);
6849 decl
= SYMBOL_REF_DECL (symbol
);
6850 alignment
= DECL_ALIGN (decl
);
6851 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
6854 /* Calculate the object's offset from the start of the block. */
6855 block
= SYMBOL_REF_BLOCK (symbol
);
6856 mask
= alignment
/ BITS_PER_UNIT
- 1;
6857 offset
= (block
->size
+ mask
) & ~mask
;
6858 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
6860 /* Record the block's new alignment and size. */
6861 block
->alignment
= MAX (block
->alignment
, alignment
);
6862 block
->size
= offset
+ size
;
6864 VEC_safe_push (rtx
, gc
, block
->objects
, symbol
);
6867 /* Return the anchor that should be used to address byte offset OFFSET
6868 from the first object in BLOCK. MODEL is the TLS model used
6872 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
6873 enum tls_model model
)
6876 unsigned int begin
, middle
, end
;
6877 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
6880 /* Work out the anchor's offset. Use an offset of 0 for the first
6881 anchor so that we don't pessimize the case where we take the address
6882 of a variable at the beginning of the block. This is particularly
6883 useful when a block has only one variable assigned to it.
6885 We try to place anchors RANGE bytes apart, so there can then be
6886 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6887 a ptr_mode offset. With some target settings, the lowest such
6888 anchor might be out of range for the lowest ptr_mode offset;
6889 likewise the highest anchor for the highest offset. Use anchors
6890 at the extreme ends of the ptr_mode range in such cases.
6892 All arithmetic uses unsigned integers in order to avoid
6894 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
6895 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
6896 range
= max_offset
- min_offset
+ 1;
6901 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
6904 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
6905 delta
-= delta
% range
;
6908 offset
= (HOST_WIDE_INT
) (-delta
);
6912 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
6913 delta
-= delta
% range
;
6914 if (delta
> bias
- 1)
6916 offset
= (HOST_WIDE_INT
) delta
;
6920 /* Do a binary search to see if there's already an anchor we can use.
6921 Set BEGIN to the new anchor's index if not. */
6923 end
= VEC_length (rtx
, block
->anchors
);
6924 while (begin
!= end
)
6926 middle
= (end
+ begin
) / 2;
6927 anchor
= VEC_index (rtx
, block
->anchors
, middle
);
6928 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
6930 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
6932 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
6934 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
6940 /* Create a new anchor with a unique label. */
6941 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
6942 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
6943 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
6944 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
6946 /* Insert it at index BEGIN. */
6947 VEC_safe_insert (rtx
, gc
, block
->anchors
, begin
, anchor
);
6951 /* Output the objects in BLOCK. */
6954 output_object_block (struct object_block
*block
)
6956 struct constant_descriptor_rtx
*desc
;
6958 HOST_WIDE_INT offset
;
6962 if (block
->objects
== NULL
)
6965 /* Switch to the section and make sure that the first byte is
6966 suitably aligned. */
6967 switch_to_section (block
->sect
);
6968 assemble_align (block
->alignment
);
6970 /* Define the values of all anchors relative to the current section
6972 for (i
= 0; VEC_iterate (rtx
, block
->anchors
, i
, symbol
); i
++)
6973 targetm
.asm_out
.output_anchor (symbol
);
6975 /* Output the objects themselves. */
6977 for (i
= 0; VEC_iterate (rtx
, block
->objects
, i
, symbol
); i
++)
6979 /* Move to the object's offset, padding with zeros if necessary. */
6980 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
6981 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
6982 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6984 desc
= SYMBOL_REF_CONSTANT (symbol
);
6985 output_constant_pool_1 (desc
, 1);
6986 offset
+= GET_MODE_SIZE (desc
->mode
);
6988 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6990 decl
= SYMBOL_REF_DECL (symbol
);
6991 assemble_constant_contents (decl
, XSTR (symbol
, 0),
6992 get_constant_alignment (decl
));
6993 offset
+= get_constant_size (decl
);
6997 decl
= SYMBOL_REF_DECL (symbol
);
6998 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
6999 offset
+= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
7004 /* A htab_traverse callback used to call output_object_block for
7005 each member of object_block_htab. */
7008 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
7010 output_object_block ((struct object_block
*) (*slot
));
7014 /* Output the definitions of all object_blocks. */
7017 output_object_blocks (void)
7019 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
7022 /* This function provides a possible implementation of the
7023 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7024 by -frecord-gcc-switches it creates a new mergeable, string section in the
7025 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7026 contains the switches in ASCII format.
7028 FIXME: This code does not correctly handle double quote characters
7029 that appear inside strings, (it strips them rather than preserving them).
7030 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7031 characters - instead it treats them as sub-string separators. Since
7032 we want to emit NUL strings terminators into the object file we have to use
7036 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7038 static char buffer
[1024];
7040 /* This variable is used as part of a simplistic heuristic to detect
7041 command line switches which take an argument:
7043 "If a command line option does not start with a dash then
7044 it is an argument for the previous command line option."
7046 This fails in the case of the command line option which is the name
7047 of the file to compile, but otherwise it is pretty reasonable. */
7048 static bool previous_name_held_back
= FALSE
;
7052 case SWITCH_TYPE_PASSED
:
7055 if (previous_name_held_back
)
7057 unsigned int len
= strlen (buffer
);
7059 snprintf (buffer
+ len
, sizeof buffer
- len
, " %s", name
);
7060 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7061 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7062 previous_name_held_back
= FALSE
;
7066 strncpy (buffer
, name
, sizeof buffer
);
7067 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7068 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7073 if (previous_name_held_back
)
7075 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7076 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7079 strncpy (buffer
, name
, sizeof buffer
);
7080 previous_name_held_back
= TRUE
;
7084 case SWITCH_TYPE_DESCRIPTIVE
:
7087 /* Distinguish between invocations where name is NULL. */
7088 static bool started
= false;
7092 if (previous_name_held_back
)
7094 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7095 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7102 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7106 | (SECTION_ENTSIZE
& 1),
7108 switch_to_section (sec
);
7117 /* The return value is currently ignored by the caller, but must be 0.
7118 For -fverbose-asm the return value would be the number of characters
7119 emitted into the assembler file. */
7123 /* Emit text to declare externally defined symbols. It is needed to
7124 properly support non-default visibility. */
7126 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7128 const char *name ATTRIBUTE_UNUSED
)
7130 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7131 set in order to avoid putting out names that are never really
7133 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7134 && targetm
.binds_local_p (decl
))
7135 maybe_assemble_visibility (decl
);
7138 #include "gt-varasm.h"