1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987-2023 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 /* This file handles generation of all the assembler code
22 *except* the instructions of a function.
23 This includes declarations of variables and their initial values.
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
30 #include "coretypes.h"
38 #include "stringpool.h"
42 #include "diagnostic-core.h"
43 #include "fold-const.h"
44 #include "stor-layout.h"
53 #include "langhooks.h"
55 #include "common/common-target.h"
56 #include "stringpool.h"
60 #include "file-prefix-map.h" /* remap_debug_filename() */
61 #include "alloc-pool.h"
65 /* The (assembler) name of the first globally-visible object output. */
66 extern GTY(()) const char *first_global_object_name
;
67 extern GTY(()) const char *weak_global_object_name
;
69 const char *first_global_object_name
;
70 const char *weak_global_object_name
;
73 class constant_descriptor_rtx
;
74 struct rtx_constant_pool
;
76 #define n_deferred_constants (crtl->varasm.deferred_constants)
78 /* Number for making the label on the next
79 constant that is stored in memory. */
81 static GTY(()) int const_labelno
;
83 /* Carry information from ASM_DECLARE_OBJECT_NAME
84 to ASM_FINISH_DECLARE_OBJECT. */
86 int size_directive_output
;
88 /* The last decl for which assemble_variable was called,
89 if it did ASM_DECLARE_OBJECT_NAME.
90 If the last call to assemble_variable didn't do that,
93 tree last_assemble_variable_decl
;
95 /* The following global variable indicates if the first basic block
96 in a function belongs to the cold partition or not. */
98 bool first_function_block_is_cold
;
100 /* Whether we saw any functions with no_split_stack. */
102 static bool saw_no_split_stack
;
104 static const char *strip_reg_name (const char *);
105 static bool contains_pointers_p (tree
);
106 #ifdef ASM_OUTPUT_EXTERNAL
107 static bool incorporeal_function_p (tree
);
109 static void decode_addr_const (tree
, class addr_const
*);
110 static hashval_t
const_hash_1 (const tree
);
111 static bool compare_constant (const tree
, const tree
);
112 static void output_constant_def_contents (rtx
);
113 static void output_addressed_constants (tree
, int);
114 static unsigned HOST_WIDE_INT
output_constant (tree
, unsigned HOST_WIDE_INT
,
115 unsigned int, bool, bool);
116 static void globalize_decl (tree
);
117 static bool decl_readonly_section_1 (enum section_category
);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_ALIGNED_BSS
120 static void asm_output_aligned_bss (FILE *, tree
, const char *,
121 unsigned HOST_WIDE_INT
, int)
124 #endif /* BSS_SECTION_ASM_OP */
125 static void mark_weak (tree
);
126 static void output_constant_pool (const char *, tree
);
127 static void handle_vtv_comdat_section (section
*, const_tree
);
129 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
130 section
*text_section
;
131 section
*data_section
;
132 section
*readonly_data_section
;
133 section
*sdata_section
;
134 section
*ctors_section
;
135 section
*dtors_section
;
136 section
*bss_section
;
137 section
*sbss_section
;
139 /* Various forms of common section. All are guaranteed to be nonnull. */
140 section
*tls_comm_section
;
141 section
*comm_section
;
142 section
*lcomm_section
;
144 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
146 section
*bss_noswitch_section
;
148 /* The section that holds the main exception table, when known. The section
149 is set either by the target's init_sections hook or by the first call to
150 switch_to_exception_section. */
151 section
*exception_section
;
153 /* The section that holds the DWARF2 frame unwind information, when known.
154 The section is set either by the target's init_sections hook or by the
155 first call to switch_to_eh_frame_section. */
156 section
*eh_frame_section
;
158 /* asm_out_file's current section. This is NULL if no section has yet
159 been selected or if we lose track of what the current section is. */
162 /* True if code for the current function is currently being directed
163 at the cold section. */
164 bool in_cold_section_p
;
166 /* The following global holds the "function name" for the code in the
167 cold section of a function, if hot/cold function splitting is enabled
168 and there was actually code that went into the cold section. A
169 pseudo function name is needed for the cold section of code for some
170 debugging tools that perform symbolization. */
171 tree cold_function_name
= NULL_TREE
;
173 /* A linked list of all the unnamed sections. */
174 static GTY(()) section
*unnamed_sections
;
176 /* Return a nonzero value if DECL has a section attribute. */
177 #define IN_NAMED_SECTION(DECL) \
178 (VAR_OR_FUNCTION_DECL_P (DECL) && DECL_SECTION_NAME (DECL) != NULL)
180 struct section_hasher
: ggc_ptr_hash
<section
>
182 typedef const char *compare_type
;
184 static hashval_t
hash (section
*);
185 static bool equal (section
*, const char *);
188 /* Hash table of named sections. */
189 static GTY(()) hash_table
<section_hasher
> *section_htab
;
191 struct object_block_hasher
: ggc_ptr_hash
<object_block
>
193 typedef const section
*compare_type
;
195 static hashval_t
hash (object_block
*);
196 static bool equal (object_block
*, const section
*);
199 /* A table of object_blocks, indexed by section. */
200 static GTY(()) hash_table
<object_block_hasher
> *object_block_htab
;
202 /* The next number to use for internal anchor labels. */
203 static GTY(()) int anchor_labelno
;
205 /* A pool of constants that can be shared between functions. */
206 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
208 /* Helper routines for maintaining section_htab. */
211 section_hasher::equal (section
*old
, const char *new_name
)
213 return strcmp (old
->named
.name
, new_name
) == 0;
217 section_hasher::hash (section
*old
)
219 return htab_hash_string (old
->named
.name
);
222 /* Return a hash value for section SECT. */
225 hash_section (section
*sect
)
227 if (sect
->common
.flags
& SECTION_NAMED
)
228 return htab_hash_string (sect
->named
.name
);
229 return sect
->common
.flags
& ~SECTION_DECLARED
;
232 /* Helper routines for maintaining object_block_htab. */
235 object_block_hasher::equal (object_block
*old
, const section
*new_section
)
237 return old
->sect
== new_section
;
241 object_block_hasher::hash (object_block
*old
)
243 return hash_section (old
->sect
);
246 /* Return a new unnamed section with the given fields. */
249 get_unnamed_section (unsigned int flags
, void (*callback
) (const char *),
254 sect
= ggc_alloc
<section
> ();
255 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
256 sect
->unnamed
.callback
= callback
;
257 sect
->unnamed
.data
= data
;
258 sect
->unnamed
.next
= unnamed_sections
;
260 unnamed_sections
= sect
;
264 /* Return a SECTION_NOSWITCH section with the given fields. */
267 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
271 sect
= ggc_alloc
<section
> ();
272 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
273 sect
->noswitch
.callback
= callback
;
278 /* Return the named section structure associated with NAME. Create
279 a new section with the given fields if no such structure exists.
280 When NOT_EXISTING, then fail if the section already exists. Return
281 the existing section if the SECTION_RETAIN bit doesn't match. Set
282 the SECTION_WRITE | SECTION_RELRO bits on the existing section
283 if one of the section flags is SECTION_WRITE | SECTION_RELRO and the
284 other has none of these flags in named sections and either the section
285 hasn't been declared yet or has been declared as writable. */
288 get_section (const char *name
, unsigned int flags
, tree decl
,
291 section
*sect
, **slot
;
293 slot
= section_htab
->find_slot_with_hash (name
, htab_hash_string (name
),
295 flags
|= SECTION_NAMED
;
298 && lookup_attribute ("retain", DECL_ATTRIBUTES (decl
)))
299 flags
|= SECTION_RETAIN
;
302 sect
= ggc_alloc
<section
> ();
303 sect
->named
.common
.flags
= flags
;
304 sect
->named
.name
= ggc_strdup (name
);
305 sect
->named
.decl
= decl
;
311 internal_error ("section already exists: %qs", name
);
314 /* It is fine if one of the sections has SECTION_NOTYPE as long as
315 the other has none of the contrary flags (see the logic at the end
316 of default_section_type_flags, below). */
317 if (((sect
->common
.flags
^ flags
) & SECTION_NOTYPE
)
318 && !((sect
->common
.flags
| flags
)
319 & (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
| SECTION_ENTSIZE
320 | (HAVE_COMDAT_GROUP
? SECTION_LINKONCE
: 0))))
322 sect
->common
.flags
|= SECTION_NOTYPE
;
323 flags
|= SECTION_NOTYPE
;
325 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
326 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
328 /* It is fine if one of the section flags is
329 SECTION_WRITE | SECTION_RELRO and the other has none of these
330 flags (i.e. read-only) in named sections and either the
331 section hasn't been declared yet or has been declared as writable.
332 In that case just make sure the resulting flags are
333 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
335 if (((sect
->common
.flags
^ flags
) & (SECTION_WRITE
| SECTION_RELRO
))
336 == (SECTION_WRITE
| SECTION_RELRO
)
337 && (sect
->common
.flags
338 & ~(SECTION_DECLARED
| SECTION_WRITE
| SECTION_RELRO
))
339 == (flags
& ~(SECTION_WRITE
| SECTION_RELRO
))
340 && ((sect
->common
.flags
& SECTION_DECLARED
) == 0
341 || (sect
->common
.flags
& SECTION_WRITE
)))
343 sect
->common
.flags
|= (SECTION_WRITE
| SECTION_RELRO
);
346 /* If the SECTION_RETAIN bit doesn't match, return and switch
347 to a new section later. */
348 if ((sect
->common
.flags
& SECTION_RETAIN
)
349 != (flags
& SECTION_RETAIN
))
351 /* Sanity check user variables for flag changes. */
352 if (sect
->named
.decl
!= NULL
353 && DECL_P (sect
->named
.decl
)
354 && decl
!= sect
->named
.decl
)
356 if (decl
!= NULL
&& DECL_P (decl
))
357 error ("%+qD causes a section type conflict with %qD",
358 decl
, sect
->named
.decl
);
360 error ("section type conflict with %qD", sect
->named
.decl
);
361 inform (DECL_SOURCE_LOCATION (sect
->named
.decl
),
362 "%qD was declared here", sect
->named
.decl
);
364 else if (decl
!= NULL
&& DECL_P (decl
))
365 error ("%+qD causes a section type conflict", decl
);
367 error ("section type conflict");
368 /* Make sure we don't error about one section multiple times. */
369 sect
->common
.flags
|= SECTION_OVERRIDE
;
375 /* Return true if the current compilation mode benefits from having
376 objects grouped into blocks. */
379 use_object_blocks_p (void)
381 return flag_section_anchors
;
384 /* Return the object_block structure for section SECT. Create a new
385 structure if we haven't created one already. Return null if SECT
386 itself is null. Return also null for mergeable sections since
387 section anchors can't be used in mergeable sections anyway,
388 because the linker might move objects around, and using the
389 object blocks infrastructure in that case is both a waste and a
390 maintenance burden. */
392 static struct object_block
*
393 get_block_for_section (section
*sect
)
395 struct object_block
*block
;
400 if (sect
->common
.flags
& SECTION_MERGE
)
404 = object_block_htab
->find_slot_with_hash (sect
, hash_section (sect
),
409 block
= ggc_cleared_alloc
<object_block
> ();
416 /* Create a symbol with label LABEL and place it at byte offset
417 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
418 is not yet known. LABEL must be a garbage-collected string. */
421 create_block_symbol (const char *label
, struct object_block
*block
,
422 HOST_WIDE_INT offset
)
427 /* Create the extended SYMBOL_REF. */
428 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
429 symbol
= (rtx
) ggc_internal_alloc (size
);
431 /* Initialize the normal SYMBOL_REF fields. */
432 memset (symbol
, 0, size
);
433 PUT_CODE (symbol
, SYMBOL_REF
);
434 PUT_MODE (symbol
, Pmode
);
435 XSTR (symbol
, 0) = label
;
436 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
438 /* Initialize the block_symbol stuff. */
439 SYMBOL_REF_BLOCK (symbol
) = block
;
440 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
445 /* Return a section with a particular name and with whatever SECTION_*
446 flags section_type_flags deems appropriate. The name of the section
447 is taken from NAME if nonnull, otherwise it is taken from DECL's
448 DECL_SECTION_NAME. DECL is the decl associated with the section
449 (see the section comment for details) and RELOC is as for
450 section_type_flags. */
453 get_named_section (tree decl
, const char *name
, int reloc
)
459 gcc_assert (decl
&& DECL_P (decl
) && DECL_SECTION_NAME (decl
));
460 name
= DECL_SECTION_NAME (decl
);
463 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
464 return get_section (name
, flags
, decl
);
467 /* Worker for resolve_unique_section. */
470 set_implicit_section (struct symtab_node
*n
, void *data ATTRIBUTE_UNUSED
)
472 n
->implicit_section
= true;
476 /* If required, set DECL_SECTION_NAME to a unique name. */
479 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
480 int flag_function_or_data_sections
)
482 if (DECL_SECTION_NAME (decl
) == NULL
483 && targetm_common
.have_named_sections
484 && (flag_function_or_data_sections
485 || lookup_attribute ("retain", DECL_ATTRIBUTES (decl
))
486 || DECL_COMDAT_GROUP (decl
)))
488 targetm
.asm_out
.unique_section (decl
, reloc
);
489 if (DECL_SECTION_NAME (decl
))
490 symtab_node::get (decl
)->call_for_symbol_and_aliases
491 (set_implicit_section
, NULL
, true);
495 #ifdef BSS_SECTION_ASM_OP
497 #ifdef ASM_OUTPUT_ALIGNED_BSS
499 /* Utility function for targets to use in implementing
500 ASM_OUTPUT_ALIGNED_BSS.
501 ??? It is believed that this function will work in most cases so such
502 support is localized here. */
505 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
506 const char *name
, unsigned HOST_WIDE_INT size
,
509 switch_to_section (bss_section
);
510 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
511 #ifdef ASM_DECLARE_OBJECT_NAME
512 last_assemble_variable_decl
= decl
;
513 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
515 /* Standard thing is just output label for the object. */
516 ASM_OUTPUT_LABEL (file
, name
);
517 #endif /* ASM_DECLARE_OBJECT_NAME */
518 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
523 #endif /* BSS_SECTION_ASM_OP */
525 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
526 /* Return the hot section for function DECL. Return text_section for
530 hot_function_section (tree decl
)
532 if (decl
!= NULL_TREE
533 && DECL_SECTION_NAME (decl
) != NULL
534 && targetm_common
.have_named_sections
)
535 return get_named_section (decl
, NULL
, 0);
541 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
544 When DECL_SECTION_NAME is non-NULL and it is implicit section and
545 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
546 concatenate the name with NAMED_SECTION_SUFFIX.
547 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
550 get_named_text_section (tree decl
,
551 const char *text_section_name
,
552 const char *named_section_suffix
)
554 if (decl
&& DECL_SECTION_NAME (decl
))
556 if (named_section_suffix
)
558 const char *dsn
= DECL_SECTION_NAME (decl
);
559 const char *stripped_name
;
562 name
= (char *) alloca (strlen (dsn
) + 1);
566 stripped_name
= targetm
.strip_name_encoding (name
);
568 buffer
= ACONCAT ((stripped_name
, named_section_suffix
, NULL
));
569 return get_named_section (decl
, buffer
, 0);
571 else if (symtab_node::get (decl
)->implicit_section
)
575 /* Do not try to split gnu_linkonce functions. This gets somewhat
577 if (DECL_COMDAT_GROUP (decl
) && !HAVE_COMDAT_GROUP
)
579 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
580 name
= targetm
.strip_name_encoding (name
);
581 return get_named_section (decl
, ACONCAT ((text_section_name
, ".",
587 return get_named_section (decl
, text_section_name
, 0);
590 /* Choose named function section based on its frequency. */
593 default_function_section (tree decl
, enum node_frequency freq
,
594 bool startup
, bool exit
)
596 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
597 /* Old GNU linkers have buggy --gc-section support, which sometimes
598 results in .gcc_except_table* sections being garbage collected. */
600 && symtab_node::get (decl
)->implicit_section
)
604 if (!flag_reorder_functions
605 || !targetm_common
.have_named_sections
)
607 /* Startup code should go to startup subsection unless it is
608 unlikely executed (this happens especially with function splitting
609 where we can split away unnecessary parts of static constructors. */
610 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
612 /* During LTO the tp_first_run profiling will naturally place all
613 initialization code first. Using separate section is counter-productive
614 because startup only code may call functions which are no longer
617 || !cgraph_node::get (decl
)->tp_first_run
618 || !opt_for_fn (decl
, flag_profile_reorder_functions
))
619 return get_named_text_section (decl
, ".text.startup", NULL
);
624 /* Similarly for exit. */
625 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
626 return get_named_text_section (decl
, ".text.exit", NULL
);
628 /* Group cold functions together, similarly for hot code. */
631 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
632 return get_named_text_section (decl
, ".text.unlikely", NULL
);
633 case NODE_FREQUENCY_HOT
:
634 return get_named_text_section (decl
, ".text.hot", NULL
);
641 /* Return the section for function DECL.
643 If DECL is NULL_TREE, return the text section. We can be passed
644 NULL_TREE under some circumstances by dbxout.cc at least.
646 If FORCE_COLD is true, return cold function section ignoring
647 the frequency info of cgraph_node. */
650 function_section_1 (tree decl
, bool force_cold
)
652 section
*section
= NULL
;
653 enum node_frequency freq
= NODE_FREQUENCY_NORMAL
;
654 bool startup
= false, exit
= false;
658 struct cgraph_node
*node
= cgraph_node::get (decl
);
662 freq
= node
->frequency
;
663 startup
= node
->only_called_at_startup
;
664 exit
= node
->only_called_at_exit
;
668 freq
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
670 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
671 if (decl
!= NULL_TREE
672 && DECL_SECTION_NAME (decl
) != NULL
)
674 if (targetm
.asm_out
.function_section
)
675 section
= targetm
.asm_out
.function_section (decl
, freq
,
679 return get_named_section (decl
, NULL
, 0);
682 return targetm
.asm_out
.select_section
683 (decl
, freq
== NODE_FREQUENCY_UNLIKELY_EXECUTED
,
684 symtab_node::get (decl
)->definition_alignment ());
686 if (targetm
.asm_out
.function_section
)
687 section
= targetm
.asm_out
.function_section (decl
, freq
, startup
, exit
);
690 return hot_function_section (decl
);
694 /* Return the section for function DECL.
696 If DECL is NULL_TREE, return the text section. We can be passed
697 NULL_TREE under some circumstances by dbxout.cc at least. */
700 function_section (tree decl
)
702 /* Handle cases where function splitting code decides
703 to put function entry point into unlikely executed section
704 despite the fact that the function itself is not cold
705 (i.e. it is called rarely but contains a hot loop that is
706 better to live in hot subsection for the code locality). */
707 return function_section_1 (decl
,
708 first_function_block_is_cold
);
711 /* Return the section for the current function, take IN_COLD_SECTION_P
715 current_function_section (void)
717 return function_section_1 (current_function_decl
, in_cold_section_p
);
720 /* Tell assembler to switch to unlikely-to-be-executed text section. */
723 unlikely_text_section (void)
725 return function_section_1 (current_function_decl
, true);
728 /* When called within a function context, return true if the function
729 has been assigned a cold text section and if SECT is that section.
730 When called outside a function context, return true if SECT is the
731 default cold section. */
734 unlikely_text_section_p (section
*sect
)
736 return sect
== function_section_1 (current_function_decl
, true);
739 /* Switch to the other function partition (if inside of hot section
740 into cold section, otherwise into the hot section). */
743 switch_to_other_text_partition (void)
745 in_cold_section_p
= !in_cold_section_p
;
746 switch_to_section (current_function_section ());
749 /* Return the read-only or relocated read-only data section
750 associated with function DECL. */
753 default_function_rodata_section (tree decl
, bool relocatable
)
762 sname
= ".data.rel.ro.local";
763 flags
= (SECTION_WRITE
| SECTION_RELRO
);
768 if (decl
&& DECL_SECTION_NAME (decl
))
770 const char *name
= DECL_SECTION_NAME (decl
);
772 if (DECL_COMDAT_GROUP (decl
) && HAVE_COMDAT_GROUP
)
778 dot
= strchr (name
+ 1, '.');
781 len
= strlen (dot
) + strlen (sname
) + 1;
782 rname
= (char *) alloca (len
);
784 strcpy (rname
, sname
);
786 return get_section (rname
, (SECTION_LINKONCE
| flags
), decl
);
788 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo or
789 .gnu.linkonce.d.rel.ro.local.foo if the jump table is relocatable. */
790 else if (DECL_COMDAT_GROUP (decl
)
791 && startswith (name
, ".gnu.linkonce.t."))
798 len
= strlen (name
) + strlen (".rel.ro.local") + 1;
799 rname
= (char *) alloca (len
);
801 strcpy (rname
, ".gnu.linkonce.d.rel.ro.local");
802 strcat (rname
, name
+ 15);
806 len
= strlen (name
) + 1;
807 rname
= (char *) alloca (len
);
809 memcpy (rname
, name
, len
);
812 return get_section (rname
, (SECTION_LINKONCE
| flags
), decl
);
814 /* For .text.foo we want to use .rodata.foo. */
815 else if (flag_function_sections
&& flag_data_sections
816 && startswith (name
, ".text."))
818 size_t len
= strlen (name
) + 1;
819 char *rname
= (char *) alloca (len
+ strlen (sname
) - 5);
821 memcpy (rname
, sname
, strlen (sname
));
822 memcpy (rname
+ strlen (sname
), name
+ 5, len
- 5);
823 return get_section (rname
, flags
, decl
);
828 return get_section (sname
, flags
, decl
);
830 return readonly_data_section
;
833 /* Return the read-only data section associated with function DECL
834 for targets where that section should be always the single
835 readonly data section. */
838 default_no_function_rodata_section (tree
, bool)
840 return readonly_data_section
;
843 /* A subroutine of mergeable_string_section and mergeable_constant_section. */
846 function_mergeable_rodata_prefix (void)
848 section
*s
= targetm
.asm_out
.function_rodata_section (current_function_decl
,
850 if (SECTION_STYLE (s
) == SECTION_NAMED
)
851 return s
->named
.name
;
853 return targetm
.asm_out
.mergeable_rodata_prefix
;
856 /* Return the section to use for string merging. */
859 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
860 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
861 unsigned int flags ATTRIBUTE_UNUSED
)
865 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
866 && TREE_CODE (decl
) == STRING_CST
867 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
869 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
870 && TREE_STRING_LENGTH (decl
) == len
)
872 scalar_int_mode mode
;
873 unsigned int modesize
;
877 const char *prefix
= function_mergeable_rodata_prefix ();
878 char *name
= (char *) alloca (strlen (prefix
) + 30);
880 mode
= SCALAR_INT_TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
881 modesize
= GET_MODE_BITSIZE (mode
);
882 if (modesize
>= 8 && modesize
<= 256
883 && (modesize
& (modesize
- 1)) == 0)
885 if (align
< modesize
)
888 if (!HAVE_LD_ALIGNED_SHF_MERGE
&& align
> 8)
889 return readonly_data_section
;
891 str
= TREE_STRING_POINTER (decl
);
892 unit
= GET_MODE_SIZE (mode
);
894 /* Check for embedded NUL characters. */
895 for (i
= 0; i
< len
; i
+= unit
)
897 for (j
= 0; j
< unit
; j
++)
898 if (str
[i
+ j
] != '\0')
903 if (i
== len
- unit
|| (unit
== 1 && i
== len
))
905 sprintf (name
, "%s.str%d.%d", prefix
,
906 modesize
/ 8, (int) (align
/ 8));
907 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
908 return get_section (name
, flags
, NULL
);
913 return readonly_data_section
;
916 /* Return the section to use for constant merging. */
919 mergeable_constant_section (machine_mode mode ATTRIBUTE_UNUSED
,
920 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
921 unsigned int flags ATTRIBUTE_UNUSED
)
923 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
926 && known_le (GET_MODE_BITSIZE (mode
), align
)
929 && (align
& (align
- 1)) == 0
930 && (HAVE_LD_ALIGNED_SHF_MERGE
? 1 : align
== 8))
932 const char *prefix
= function_mergeable_rodata_prefix ();
933 char *name
= (char *) alloca (strlen (prefix
) + 30);
935 sprintf (name
, "%s.cst%d", prefix
, (int) (align
/ 8));
936 flags
|= (align
/ 8) | SECTION_MERGE
;
937 return get_section (name
, flags
, NULL
);
939 return readonly_data_section
;
942 /* Given NAME, a putative register name, discard any customary prefixes. */
945 strip_reg_name (const char *name
)
947 #ifdef REGISTER_PREFIX
948 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
949 name
+= strlen (REGISTER_PREFIX
);
951 if (name
[0] == '%' || name
[0] == '#')
956 /* The user has asked for a DECL to have a particular name. Set (or
957 change) it in such a way that we don't prefix an underscore to
960 set_user_assembler_name (tree decl
, const char *name
)
962 char *starred
= (char *) alloca (strlen (name
) + 2);
964 strcpy (starred
+ 1, name
);
965 symtab
->change_decl_assembler_name (decl
, get_identifier (starred
));
966 SET_DECL_RTL (decl
, NULL_RTX
);
969 /* Decode an `asm' spec for a declaration as a register name.
970 Return the register number, or -1 if nothing specified,
971 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
972 or -3 if ASMSPEC is `cc' and is not recognized,
973 or -4 if ASMSPEC is `memory' and is not recognized.
974 Accept an exact spelling or a decimal number.
975 Prefixes such as % are optional. */
978 decode_reg_name_and_count (const char *asmspec
, int *pnregs
)
980 /* Presume just one register is clobbered. */
987 /* Get rid of confusing prefixes. */
988 asmspec
= strip_reg_name (asmspec
);
990 /* Allow a decimal number as a "register name". */
991 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
992 if (! ISDIGIT (asmspec
[i
]))
994 if (asmspec
[0] != 0 && i
< 0)
997 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0 && reg_names
[i
][0])
1003 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1005 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
1008 #ifdef OVERLAPPING_REGISTER_NAMES
1012 const char *const name
;
1015 } table
[] = OVERLAPPING_REGISTER_NAMES
;
1017 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
1018 if (table
[i
].name
[0]
1019 && ! strcmp (asmspec
, table
[i
].name
))
1021 *pnregs
= table
[i
].nregs
;
1022 return table
[i
].number
;
1025 #endif /* OVERLAPPING_REGISTER_NAMES */
1027 #ifdef ADDITIONAL_REGISTER_NAMES
1029 static const struct { const char *const name
; const int number
; } table
[]
1030 = ADDITIONAL_REGISTER_NAMES
;
1032 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
1033 if (table
[i
].name
[0]
1034 && ! strcmp (asmspec
, table
[i
].name
)
1035 && reg_names
[table
[i
].number
][0])
1036 return table
[i
].number
;
1038 #endif /* ADDITIONAL_REGISTER_NAMES */
1040 if (!strcmp (asmspec
, "memory"))
1043 if (!strcmp (asmspec
, "cc"))
1053 decode_reg_name (const char *name
)
1056 return decode_reg_name_and_count (name
, &count
);
1060 /* Return true if DECL's initializer is suitable for a BSS section. */
1063 bss_initializer_p (const_tree decl
, bool named
)
1065 /* Do not put non-common constants into the .bss section, they belong in
1066 a readonly section, except when NAMED is true. */
1067 return ((!TREE_READONLY (decl
) || DECL_COMMON (decl
) || named
)
1068 && (DECL_INITIAL (decl
) == NULL
1069 /* In LTO we have no errors in program; error_mark_node is used
1070 to mark offlined constructors. */
1071 || (DECL_INITIAL (decl
) == error_mark_node
1073 || (flag_zero_initialized_in_bss
1074 && initializer_zerop (DECL_INITIAL (decl
))
1075 /* A decl with the "persistent" attribute applied and
1076 explicitly initialized to 0 should not be treated as a BSS
1078 && !DECL_PERSISTENT_P (decl
))));
1081 /* Compute the alignment of variable specified by DECL.
1082 DONT_OUTPUT_DATA is from assemble_variable. */
1085 align_variable (tree decl
, bool dont_output_data
)
1087 unsigned int align
= DECL_ALIGN (decl
);
1089 /* In the case for initialing an array whose length isn't specified,
1090 where we have not yet been able to do the layout,
1091 figure out the proper alignment now. */
1092 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1093 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1094 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1096 /* Some object file formats have a maximum alignment which they support.
1097 In particular, a.out format supports a maximum alignment of 4. */
1098 if (align
> MAX_OFILE_ALIGNMENT
)
1100 error ("alignment of %q+D is greater than maximum object "
1101 "file alignment %d", decl
,
1102 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1103 align
= MAX_OFILE_ALIGNMENT
;
1106 if (! DECL_USER_ALIGN (decl
))
1108 #ifdef DATA_ABI_ALIGNMENT
1109 unsigned int data_abi_align
1110 = DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1111 /* For backwards compatibility, don't assume the ABI alignment for
1113 if (! DECL_THREAD_LOCAL_P (decl
) || data_abi_align
<= BITS_PER_WORD
)
1114 align
= data_abi_align
;
1117 /* On some machines, it is good to increase alignment sometimes.
1118 But as DECL_ALIGN is used both for actually emitting the variable
1119 and for code accessing the variable as guaranteed alignment, we
1120 can only increase the alignment if it is a performance optimization
1121 if the references to it must bind to the current definition. */
1122 if (decl_binds_to_current_def_p (decl
)
1123 && !DECL_VIRTUAL_P (decl
))
1125 #ifdef DATA_ALIGNMENT
1126 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1127 /* Don't increase alignment too much for TLS variables - TLS space
1129 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1132 if (DECL_INITIAL (decl
) != 0
1133 /* In LTO we have no errors in program; error_mark_node is used
1134 to mark offlined constructors. */
1135 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1137 unsigned int const_align
1138 = targetm
.constant_alignment (DECL_INITIAL (decl
), align
);
1139 /* Don't increase alignment too much for TLS variables - TLS
1140 space is too precious. */
1141 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1142 align
= const_align
;
1147 /* Reset the alignment in case we have made it tighter, so we can benefit
1148 from it in get_pointer_alignment. */
1149 SET_DECL_ALIGN (decl
, align
);
1152 /* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1153 beyond what align_variable returned. */
1156 get_variable_align (tree decl
)
1158 unsigned int align
= DECL_ALIGN (decl
);
1160 /* For user aligned vars or static vars align_variable already did
1162 if (DECL_USER_ALIGN (decl
) || !TREE_PUBLIC (decl
))
1165 #ifdef DATA_ABI_ALIGNMENT
1166 if (DECL_THREAD_LOCAL_P (decl
))
1167 align
= DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1170 /* For decls that bind to the current definition, align_variable
1171 did also everything, except for not assuming ABI required alignment
1172 of TLS variables. For other vars, increase the alignment here
1173 as an optimization. */
1174 if (!decl_binds_to_current_def_p (decl
))
1176 /* On some machines, it is good to increase alignment sometimes. */
1177 #ifdef DATA_ALIGNMENT
1178 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1179 /* Don't increase alignment too much for TLS variables - TLS space
1181 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1184 if (DECL_INITIAL (decl
) != 0
1185 /* In LTO we have no errors in program; error_mark_node is used
1186 to mark offlined constructors. */
1187 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1189 unsigned int const_align
1190 = targetm
.constant_alignment (DECL_INITIAL (decl
), align
);
1191 /* Don't increase alignment too much for TLS variables - TLS space
1193 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1194 align
= const_align
;
1201 /* Compute reloc for get_variable_section. The return value
1202 is a mask for which bit 1 indicates a global relocation, and bit 0
1203 indicates a local relocation. */
1206 compute_reloc_for_var (tree decl
)
1210 if (DECL_INITIAL (decl
) == error_mark_node
)
1211 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1212 else if (DECL_INITIAL (decl
))
1213 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1220 /* Return the section into which the given VAR_DECL or CONST_DECL
1221 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1222 section should be used wherever possible. */
1225 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1227 addr_space_t as
= ADDR_SPACE_GENERIC
;
1229 varpool_node
*vnode
= varpool_node::get (decl
);
1232 vnode
= vnode
->ultimate_alias_target ();
1236 if (TREE_TYPE (decl
) != error_mark_node
)
1237 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1239 /* We need the constructor to figure out reloc flag. */
1241 vnode
->get_constructor ();
1243 if (DECL_COMMON (decl
)
1244 && !lookup_attribute ("retain", DECL_ATTRIBUTES (decl
)))
1246 /* If the decl has been given an explicit section name, or it resides
1247 in a non-generic address space, then it isn't common, and shouldn't
1248 be handled as such. */
1249 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1250 && ADDR_SPACE_GENERIC_P (as
));
1251 if (DECL_THREAD_LOCAL_P (decl
))
1252 return tls_comm_section
;
1253 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1254 return comm_section
;
1257 reloc
= compute_reloc_for_var (decl
);
1259 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1260 if (IN_NAMED_SECTION (decl
))
1262 section
*sect
= get_named_section (decl
, NULL
, reloc
);
1264 if ((sect
->common
.flags
& SECTION_BSS
)
1265 && !bss_initializer_p (decl
, true))
1267 error_at (DECL_SOURCE_LOCATION (decl
),
1268 "only zero initializers are allowed in section %qs",
1270 DECL_INITIAL (decl
) = error_mark_node
;
1275 if (ADDR_SPACE_GENERIC_P (as
)
1276 && !DECL_THREAD_LOCAL_P (decl
)
1277 && !DECL_NOINIT_P (decl
)
1278 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1279 && bss_initializer_p (decl
))
1281 if (!TREE_PUBLIC (decl
)
1282 && !((flag_sanitize
& SANITIZE_ADDRESS
)
1283 && asan_protect_global (decl
)))
1284 return lcomm_section
;
1285 if (bss_noswitch_section
)
1286 return bss_noswitch_section
;
1289 return targetm
.asm_out
.select_section (decl
, reloc
,
1290 get_variable_align (decl
));
1293 /* Return the block into which object_block DECL should be placed. */
1295 static struct object_block
*
1296 get_block_for_decl (tree decl
)
1302 /* The object must be defined in this translation unit. */
1303 if (DECL_EXTERNAL (decl
))
1306 /* There's no point using object blocks for something that is
1307 isolated by definition. */
1308 if (DECL_COMDAT_GROUP (decl
))
1312 /* We can only calculate block offsets if the decl has a known
1314 if (DECL_SIZE_UNIT (decl
) == NULL
)
1316 if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl
)))
1319 /* Find out which section should contain DECL. We cannot put it into
1320 an object block if it requires a standalone definition. */
1322 align_variable (decl
, 0);
1323 sect
= get_variable_section (decl
, true);
1324 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1327 if (bool (lookup_attribute ("retain", DECL_ATTRIBUTES (decl
)))
1328 != bool (sect
->common
.flags
& SECTION_RETAIN
))
1331 return get_block_for_section (sect
);
1334 /* Make sure block symbol SYMBOL is in block BLOCK. */
1337 change_symbol_block (rtx symbol
, struct object_block
*block
)
1339 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1341 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1342 SYMBOL_REF_BLOCK (symbol
) = block
;
1346 /* Return true if it is possible to put DECL in an object_block. */
1349 use_blocks_for_decl_p (tree decl
)
1351 struct symtab_node
*snode
;
1353 /* Don't create object blocks if each DECL is placed into a separate
1354 section because that will uselessly create a section anchor for
1356 if (flag_data_sections
)
1359 /* Only data DECLs can be placed into object blocks. */
1360 if (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
1363 /* DECL_INITIAL (decl) set to decl is a hack used for some decls that
1364 are never used from code directly and we never want object block handling
1366 if (DECL_INITIAL (decl
) == decl
)
1369 /* If this decl is an alias, then we don't want to emit a
1372 && (snode
= symtab_node::get (decl
)) != NULL
1376 return targetm
.use_blocks_for_decl_p (decl
);
1379 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1380 until we find an identifier that is not itself a transparent alias.
1381 Modify the alias passed to it by reference (and all aliases on the
1382 way to the ultimate target), such that they do not have to be
1383 followed again, and return the ultimate target of the alias
1387 ultimate_transparent_alias_target (tree
*alias
)
1389 tree target
= *alias
;
1391 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
1393 gcc_assert (TREE_CHAIN (target
));
1394 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
1395 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
1396 && ! TREE_CHAIN (target
));
1403 /* Return true if REGNUM is mentioned in ELIMINABLE_REGS as a from
1407 eliminable_regno_p (int regnum
)
1413 } eliminables
[] = ELIMINABLE_REGS
;
1414 for (size_t i
= 0; i
< ARRAY_SIZE (eliminables
); i
++)
1415 if (regnum
== eliminables
[i
].from
)
1420 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1421 have static storage duration. In other words, it should not be an
1422 automatic variable, including PARM_DECLs.
1424 There is, however, one exception: this function handles variables
1425 explicitly placed in a particular register by the user.
1427 This is never called for PARM_DECL nodes. */
1430 make_decl_rtl (tree decl
)
1432 const char *name
= 0;
1437 /* Check that we are not being given an automatic variable. */
1438 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1439 && TREE_CODE (decl
) != RESULT_DECL
);
1441 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1442 gcc_assert (!VAR_P (decl
)
1443 || TREE_STATIC (decl
)
1444 || TREE_PUBLIC (decl
)
1445 || DECL_EXTERNAL (decl
)
1446 || DECL_REGISTER (decl
));
1448 /* And that we were not given a type or a label. */
1449 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1450 && TREE_CODE (decl
) != LABEL_DECL
);
1452 /* For a duplicate declaration, we can be called twice on the
1453 same DECL node. Don't discard the RTL already made. */
1454 if (DECL_RTL_SET_P (decl
))
1456 /* If the old RTL had the wrong mode, fix the mode. */
1457 x
= DECL_RTL (decl
);
1458 if (GET_MODE (x
) != DECL_MODE (decl
))
1459 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1461 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1464 /* ??? Another way to do this would be to maintain a hashed
1465 table of such critters. Instead of adding stuff to a DECL
1466 to give certain attributes to it, we could use an external
1467 hash map from DECL to set of attributes. */
1469 /* Let the target reassign the RTL if it wants.
1470 This is necessary, for example, when one machine specific
1471 decl attribute overrides another. */
1472 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1474 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1475 on the new decl information. */
1477 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1478 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1479 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1484 /* If this variable belongs to the global constant pool, retrieve the
1485 pre-computed RTL or recompute it in LTO mode. */
1486 if (VAR_P (decl
) && DECL_IN_CONSTANT_POOL (decl
))
1488 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1492 id
= DECL_ASSEMBLER_NAME (decl
);
1493 name
= IDENTIFIER_POINTER (id
);
1495 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1496 && DECL_REGISTER (decl
))
1498 error ("register name not specified for %q+D", decl
);
1500 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1502 const char *asmspec
= name
+1;
1503 machine_mode mode
= DECL_MODE (decl
);
1504 reg_number
= decode_reg_name (asmspec
);
1505 /* First detect errors in declaring global registers. */
1506 if (reg_number
== -1)
1507 error ("register name not specified for %q+D", decl
);
1508 else if (reg_number
< 0)
1509 error ("invalid register name for %q+D", decl
);
1510 else if (mode
== BLKmode
)
1511 error ("data type of %q+D isn%'t suitable for a register",
1513 else if (!in_hard_reg_set_p (accessible_reg_set
, mode
, reg_number
))
1514 error ("the register specified for %q+D cannot be accessed"
1515 " by the current target", decl
);
1516 else if (!in_hard_reg_set_p (operand_reg_set
, mode
, reg_number
))
1517 error ("the register specified for %q+D is not general enough"
1518 " to be used as a register variable", decl
);
1519 else if (!targetm
.hard_regno_mode_ok (reg_number
, mode
))
1520 error ("register specified for %q+D isn%'t suitable for data type",
1522 else if (reg_number
!= HARD_FRAME_POINTER_REGNUM
1523 && (reg_number
== FRAME_POINTER_REGNUM
1524 #ifdef RETURN_ADDRESS_POINTER_REGNUM
1525 || reg_number
== RETURN_ADDRESS_POINTER_REGNUM
1527 || reg_number
== ARG_POINTER_REGNUM
)
1528 && eliminable_regno_p (reg_number
))
1529 error ("register specified for %q+D is an internal GCC "
1530 "implementation detail", decl
);
1531 /* Now handle properly declared static register variables. */
1536 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1538 DECL_INITIAL (decl
) = 0;
1539 error ("global register variable has initial value");
1541 if (TREE_THIS_VOLATILE (decl
))
1542 warning (OPT_Wvolatile_register_var
,
1543 "optimization may eliminate reads and/or "
1544 "writes to register variables");
1546 /* If the user specified one of the eliminables registers here,
1547 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1548 confused with that register and be eliminated. This usage is
1549 somewhat suspect... */
1551 SET_DECL_RTL (decl
, gen_raw_REG (mode
, reg_number
));
1552 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1553 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1555 if (TREE_STATIC (decl
))
1557 /* Make this register global, so not usable for anything
1559 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1560 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1561 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1563 nregs
= hard_regno_nregs (reg_number
, mode
);
1565 globalize_reg (decl
, reg_number
+ --nregs
);
1568 /* As a register variable, it has no section. */
1571 /* Avoid internal errors from invalid register
1573 SET_DECL_ASSEMBLER_NAME (decl
, NULL_TREE
);
1574 DECL_HARD_REGISTER (decl
) = 0;
1575 /* Also avoid SSA inconsistencies by pretending this is an external
1577 DECL_EXTERNAL (decl
) = 1;
1580 /* Now handle ordinary static variables and functions (in memory).
1581 Also handle vars declared register invalidly. */
1582 else if (name
[0] == '*')
1584 #ifdef REGISTER_PREFIX
1585 if (strlen (REGISTER_PREFIX
) != 0)
1587 reg_number
= decode_reg_name (name
);
1588 if (reg_number
>= 0 || reg_number
== -3)
1589 error ("register name given for non-register variable %q+D", decl
);
1594 /* Specifying a section attribute on a variable forces it into a
1595 non-.bss section, and thus it cannot be common. */
1596 /* FIXME: In general this code should not be necessary because
1597 visibility pass is doing the same work. But notice_global_symbol
1598 is called early and it needs to make DECL_RTL to get the name.
1599 we take care of recomputing the DECL_RTL after visibility is changed. */
1601 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
1602 && DECL_SECTION_NAME (decl
) != NULL
1603 && DECL_INITIAL (decl
) == NULL_TREE
1604 && DECL_COMMON (decl
))
1605 DECL_COMMON (decl
) = 0;
1607 /* Variables can't be both common and weak. */
1608 if (VAR_P (decl
) && DECL_WEAK (decl
))
1609 DECL_COMMON (decl
) = 0;
1611 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1612 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1615 machine_mode address_mode
= Pmode
;
1616 if (TREE_TYPE (decl
) != error_mark_node
)
1618 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1619 address_mode
= targetm
.addr_space
.address_mode (as
);
1621 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1623 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1624 SET_SYMBOL_REF_DECL (x
, decl
);
1626 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1627 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1628 set_mem_attributes (x
, decl
, 1);
1629 SET_DECL_RTL (decl
, x
);
1631 /* Optionally set flags or add text to the name to record information
1632 such as that it is a function name.
1633 If the name is changed, the macro ASM_OUTPUT_LABELREF
1634 will have to know how to strip this information. */
1635 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1638 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1639 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1643 make_decl_rtl_for_debug (tree decl
)
1645 unsigned int save_aliasing_flag
;
1648 if (DECL_RTL_SET_P (decl
))
1649 return DECL_RTL (decl
);
1651 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1652 call new_alias_set. If running with -fcompare-debug, sometimes
1653 we do not want to create alias sets that will throw the alias
1654 numbers off in the comparison dumps. So... clearing
1655 flag_strict_aliasing will keep new_alias_set() from creating a
1657 save_aliasing_flag
= flag_strict_aliasing
;
1658 flag_strict_aliasing
= 0;
1660 rtl
= DECL_RTL (decl
);
1661 /* Reset DECL_RTL back, as various parts of the compiler expects
1662 DECL_RTL set meaning it is actually going to be output. */
1663 SET_DECL_RTL (decl
, NULL
);
1665 flag_strict_aliasing
= save_aliasing_flag
;
1669 /* Output a string of literal assembler code
1670 for an `asm' keyword used between functions. */
1673 assemble_asm (tree string
)
1678 if (TREE_CODE (string
) == ADDR_EXPR
)
1679 string
= TREE_OPERAND (string
, 0);
1681 p
= TREE_STRING_POINTER (string
);
1682 fprintf (asm_out_file
, "%s%s\n", p
[0] == '\t' ? "" : "\t", p
);
1685 /* Write the address of the entity given by SYMBOL to SEC. */
1687 assemble_addr_to_section (rtx symbol
, section
*sec
)
1689 switch_to_section (sec
);
1690 assemble_align (POINTER_SIZE
);
1691 assemble_integer (symbol
, POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
1694 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1695 not) section for PRIORITY. */
1697 get_cdtor_priority_section (int priority
, bool constructor_p
)
1699 /* Buffer conservatively large enough for the full range of a 32-bit
1700 int plus the text below. */
1703 /* ??? This only works reliably with the GNU linker. */
1704 sprintf (buf
, "%s.%.5u",
1705 constructor_p
? ".ctors" : ".dtors",
1706 /* Invert the numbering so the linker puts us in the proper
1707 order; constructors are run from right to left, and the
1708 linker sorts in increasing order. */
1709 MAX_INIT_PRIORITY
- priority
);
1710 return get_section (buf
, SECTION_WRITE
, NULL
);
1714 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1718 if (priority
!= DEFAULT_INIT_PRIORITY
)
1719 sec
= get_cdtor_priority_section (priority
,
1720 /*constructor_p=*/false);
1722 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1724 assemble_addr_to_section (symbol
, sec
);
1727 #ifdef DTORS_SECTION_ASM_OP
1729 default_dtor_section_asm_out_destructor (rtx symbol
,
1730 int priority ATTRIBUTE_UNUSED
)
1732 assemble_addr_to_section (symbol
, dtors_section
);
1737 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1741 if (priority
!= DEFAULT_INIT_PRIORITY
)
1742 sec
= get_cdtor_priority_section (priority
,
1743 /*constructor_p=*/true);
1745 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1747 assemble_addr_to_section (symbol
, sec
);
1750 #ifdef CTORS_SECTION_ASM_OP
1752 default_ctor_section_asm_out_constructor (rtx symbol
,
1753 int priority ATTRIBUTE_UNUSED
)
1755 assemble_addr_to_section (symbol
, ctors_section
);
1759 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1760 a nonzero value if the constant pool should be output before the
1761 start of the function, or a zero value if the pool should output
1762 after the end of the function. The default is to put it before the
1765 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1766 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1769 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1770 to be output to assembler.
1771 Set first_global_object_name and weak_global_object_name as appropriate. */
1774 notice_global_symbol (tree decl
)
1776 const char **t
= &first_global_object_name
;
1778 if (first_global_object_name
1779 || !TREE_PUBLIC (decl
)
1780 || DECL_EXTERNAL (decl
)
1781 || !DECL_NAME (decl
)
1782 || (VAR_P (decl
) && DECL_HARD_REGISTER (decl
))
1783 || (TREE_CODE (decl
) != FUNCTION_DECL
1785 || (DECL_COMMON (decl
)
1786 && (DECL_INITIAL (decl
) == 0
1787 || DECL_INITIAL (decl
) == error_mark_node
)))))
1790 /* We win when global object is found, but it is useful to know about weak
1791 symbol as well so we can produce nicer unique names. */
1792 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1793 t
= &weak_global_object_name
;
1797 tree id
= DECL_ASSEMBLER_NAME (decl
);
1798 ultimate_transparent_alias_target (&id
);
1799 *t
= ggc_strdup (targetm
.strip_name_encoding (IDENTIFIER_POINTER (id
)));
1803 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1804 current function goes into the cold section, so that targets can use
1805 current_function_section during RTL expansion. DECL describes the
1809 decide_function_section (tree decl
)
1811 first_function_block_is_cold
= false;
1813 if (DECL_SECTION_NAME (decl
))
1815 struct cgraph_node
*node
= cgraph_node::get (current_function_decl
);
1816 /* Calls to function_section rely on first_function_block_is_cold
1818 first_function_block_is_cold
= (node
1820 == NODE_FREQUENCY_UNLIKELY_EXECUTED
);
1823 in_cold_section_p
= first_function_block_is_cold
;
1826 /* Get the function's name, as described by its RTL. This may be
1827 different from the DECL_NAME name used in the source file. */
1829 get_fnname_from_decl (tree decl
)
1831 rtx x
= DECL_RTL (decl
);
1832 gcc_assert (MEM_P (x
));
1834 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
1838 /* Output assembler code for the constant pool of a function and associated
1839 with defining the name of the function. DECL describes the function.
1840 NAME is the function's name. For the constant pool, we use the current
1841 constant pool data. */
1844 assemble_start_function (tree decl
, const char *fnname
)
1847 char tmp_label
[100];
1848 bool hot_label_written
= false;
1850 if (crtl
->has_bb_partition
)
1852 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1853 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1854 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1855 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1856 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1857 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1858 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1859 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1861 cold_function_name
= NULL_TREE
;
1865 crtl
->subsections
.hot_section_label
= NULL
;
1866 crtl
->subsections
.cold_section_label
= NULL
;
1867 crtl
->subsections
.hot_section_end_label
= NULL
;
1868 crtl
->subsections
.cold_section_end_label
= NULL
;
1871 /* The following code does not need preprocessing in the assembler. */
1875 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1876 output_constant_pool (fnname
, decl
);
1878 align
= symtab_node::get (decl
)->definition_alignment ();
1880 /* Make sure the not and cold text (code) sections are properly
1881 aligned. This is necessary here in the case where the function
1882 has both hot and cold sections, because we don't want to re-set
1883 the alignment when the section switch happens mid-function. */
1885 if (crtl
->has_bb_partition
)
1887 first_function_block_is_cold
= false;
1889 switch_to_section (unlikely_text_section ());
1890 assemble_align (align
);
1891 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1893 /* When the function starts with a cold section, we need to explicitly
1894 align the hot section and write out the hot section label.
1895 But if the current function is a thunk, we do not have a CFG. */
1897 && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun
)->next_bb
) == BB_COLD_PARTITION
)
1899 switch_to_section (text_section
);
1900 assemble_align (align
);
1901 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1902 hot_label_written
= true;
1903 first_function_block_is_cold
= true;
1905 in_cold_section_p
= first_function_block_is_cold
;
1909 /* Switch to the correct text section for the start of the function. */
1911 switch_to_section (function_section (decl
), decl
);
1912 if (crtl
->has_bb_partition
&& !hot_label_written
)
1913 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1915 /* Tell assembler to move to target machine's alignment for functions. */
1916 align
= floor_log2 (align
/ BITS_PER_UNIT
);
1919 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1922 /* Handle a user-specified function alignment.
1923 Note that we still need to align to DECL_ALIGN, as above,
1924 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1925 if (! DECL_USER_ALIGN (decl
)
1926 && align_functions
.levels
[0].log
> align
1927 && optimize_function_for_speed_p (cfun
))
1929 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1930 int align_log
= align_functions
.levels
[0].log
;
1932 int max_skip
= align_functions
.levels
[0].maxskip
;
1933 if (flag_limit_function_alignment
&& crtl
->max_insn_address
> 0
1934 && max_skip
>= crtl
->max_insn_address
)
1935 max_skip
= crtl
->max_insn_address
- 1;
1937 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1938 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
, align_log
, max_skip
);
1939 if (max_skip
== align_functions
.levels
[0].maxskip
)
1940 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1941 align_functions
.levels
[1].log
,
1942 align_functions
.levels
[1].maxskip
);
1944 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions
.levels
[0].log
);
1948 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1949 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1952 if (!DECL_IGNORED_P (decl
))
1953 (*debug_hooks
->begin_function
) (decl
);
1955 /* Make function name accessible from other files, if appropriate. */
1957 if (TREE_PUBLIC (decl
))
1959 notice_global_symbol (decl
);
1961 globalize_decl (decl
);
1963 maybe_assemble_visibility (decl
);
1966 if (DECL_PRESERVE_P (decl
))
1967 targetm
.asm_out
.mark_decl_preserved (fnname
);
1969 unsigned short patch_area_size
= crtl
->patch_area_size
;
1970 unsigned short patch_area_entry
= crtl
->patch_area_entry
;
1972 /* Emit the patching area before the entry label, if any. */
1973 if (patch_area_entry
> 0)
1974 targetm
.asm_out
.print_patchable_function_entry (asm_out_file
,
1975 patch_area_entry
, true);
1977 /* Do any machine/system dependent processing of the function name. */
1978 #ifdef ASM_DECLARE_FUNCTION_NAME
1979 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1981 /* Standard thing is just output label for the function. */
1982 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1983 #endif /* ASM_DECLARE_FUNCTION_NAME */
1985 /* And the area after the label. Record it if we haven't done so yet. */
1986 if (patch_area_size
> patch_area_entry
)
1987 targetm
.asm_out
.print_patchable_function_entry (asm_out_file
,
1990 patch_area_entry
== 0);
1992 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1993 saw_no_split_stack
= true;
1996 /* Output assembler code associated with defining the size of the
1997 function. DECL describes the function. NAME is the function's name. */
2000 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
2002 #ifdef ASM_DECLARE_FUNCTION_SIZE
2003 /* We could have switched section in the middle of the function. */
2004 if (crtl
->has_bb_partition
)
2005 switch_to_section (function_section (decl
));
2006 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
2008 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
2010 output_constant_pool (fnname
, decl
);
2011 switch_to_section (function_section (decl
)); /* need to switch back */
2013 /* Output labels for end of hot/cold text sections (to be used by
2015 if (crtl
->has_bb_partition
)
2017 section
*save_text_section
;
2019 save_text_section
= in_section
;
2020 switch_to_section (unlikely_text_section ());
2021 #ifdef ASM_DECLARE_COLD_FUNCTION_SIZE
2022 if (cold_function_name
!= NULL_TREE
)
2023 ASM_DECLARE_COLD_FUNCTION_SIZE (asm_out_file
,
2024 IDENTIFIER_POINTER (cold_function_name
),
2027 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
2028 if (first_function_block_is_cold
)
2029 switch_to_section (text_section
);
2031 switch_to_section (function_section (decl
));
2032 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
2033 switch_to_section (save_text_section
);
2037 /* Assemble code to leave SIZE bytes of zeros. */
2040 assemble_zeros (unsigned HOST_WIDE_INT size
)
2042 /* Do no output if -fsyntax-only. */
2043 if (flag_syntax_only
)
2046 #ifdef ASM_NO_SKIP_IN_TEXT
2047 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
2048 so we must output 0s explicitly in the text section. */
2049 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
2051 unsigned HOST_WIDE_INT i
;
2052 for (i
= 0; i
< size
; i
++)
2053 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
2058 ASM_OUTPUT_SKIP (asm_out_file
, size
);
2061 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
2064 assemble_align (unsigned int align
)
2066 if (align
> BITS_PER_UNIT
)
2068 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2072 /* Assemble a string constant with the specified C string as contents. */
2075 assemble_string (const char *p
, int size
)
2080 /* If the string is very long, split it up. */
2084 int thissize
= size
- pos
;
2085 if (thissize
> maximum
)
2088 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
2096 /* A noswitch_section_callback for lcomm_section. */
2099 emit_local (tree decl ATTRIBUTE_UNUSED
,
2100 const char *name ATTRIBUTE_UNUSED
,
2101 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2102 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2104 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
2105 unsigned int align
= symtab_node::get (decl
)->definition_alignment ();
2106 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
2109 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
2110 unsigned int align
= symtab_node::get (decl
)->definition_alignment ();
2111 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, align
);
2114 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2119 /* A noswitch_section_callback for bss_noswitch_section. */
2121 #if defined ASM_OUTPUT_ALIGNED_BSS
2123 emit_bss (tree decl ATTRIBUTE_UNUSED
,
2124 const char *name ATTRIBUTE_UNUSED
,
2125 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2126 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2128 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
,
2129 get_variable_align (decl
));
2134 /* A noswitch_section_callback for comm_section. */
2137 emit_common (tree decl ATTRIBUTE_UNUSED
,
2138 const char *name ATTRIBUTE_UNUSED
,
2139 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2140 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2142 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
2143 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
2144 size
, get_variable_align (decl
));
2146 #elif defined ASM_OUTPUT_ALIGNED_COMMON
2147 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
2148 get_variable_align (decl
));
2151 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
2156 /* A noswitch_section_callback for tls_comm_section. */
2159 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
2160 const char *name ATTRIBUTE_UNUSED
,
2161 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2162 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2164 #ifdef ASM_OUTPUT_TLS_COMMON
2165 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
2168 sorry ("thread-local COMMON data not implemented");
2173 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2174 NAME is the name of DECL's SYMBOL_REF. */
2177 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
,
2180 unsigned HOST_WIDE_INT size
, rounded
;
2182 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2185 if ((flag_sanitize
& SANITIZE_ADDRESS
) && asan_protect_global (decl
))
2186 size
+= asan_red_zone_size (size
);
2188 /* Don't allocate zero bytes of common,
2189 since that means "undefined external" in the linker. */
2193 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2194 so that each uninitialized object starts on such a boundary. */
2195 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
2196 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2197 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2199 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
2200 && (unsigned HOST_WIDE_INT
) (align
/ BITS_PER_UNIT
) > rounded
)
2201 error ("requested alignment for %q+D is greater than "
2202 "implemented alignment of %wu", decl
, rounded
);
2205 /* A subroutine of assemble_variable. Output the label and contents of
2206 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2207 is as for assemble_variable. */
2210 assemble_variable_contents (tree decl
, const char *name
,
2211 bool dont_output_data
, bool merge_strings
)
2213 /* Do any machine/system dependent processing of the object. */
2214 #ifdef ASM_DECLARE_OBJECT_NAME
2215 last_assemble_variable_decl
= decl
;
2216 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
2218 /* Standard thing is just output label for the object. */
2219 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2220 #endif /* ASM_DECLARE_OBJECT_NAME */
2222 if (!dont_output_data
)
2224 /* Caller is supposed to use varpool_get_constructor when it wants
2225 to output the body. */
2226 gcc_assert (!in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
);
2227 if (DECL_INITIAL (decl
)
2228 && DECL_INITIAL (decl
) != error_mark_node
2229 && !initializer_zerop (DECL_INITIAL (decl
)))
2230 /* Output the actual data. */
2231 output_constant (DECL_INITIAL (decl
),
2232 tree_to_uhwi (DECL_SIZE_UNIT (decl
)),
2233 get_variable_align (decl
),
2234 false, merge_strings
);
2236 /* Leave space for it. */
2237 assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl
)));
2238 targetm
.asm_out
.decl_end ();
2242 /* Write out assembly for the variable DECL, which is not defined in
2243 the current translation unit. */
2245 assemble_undefined_decl (tree decl
)
2247 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
2248 targetm
.asm_out
.assemble_undefined_decl (asm_out_file
, name
, decl
);
2251 /* Assemble everything that is needed for a variable or function declaration.
2252 Not used for automatic variables, and not used for function definitions.
2253 Should not be called for variables of incomplete structure type.
2255 TOP_LEVEL is nonzero if this variable has file scope.
2256 AT_END is nonzero if this is the special handling, at end of compilation,
2257 to define things that have had only tentative definitions.
2258 DONT_OUTPUT_DATA if nonzero means don't actually output the
2259 initial value (that will be done by the caller). */
2262 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
2263 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
2266 rtx decl_rtl
, symbol
;
2269 bool asan_protected
= false;
2271 /* This function is supposed to handle VARIABLES. Ensure we have one. */
2272 gcc_assert (VAR_P (decl
));
2274 /* Emulated TLS had better not get this far. */
2275 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
2277 last_assemble_variable_decl
= 0;
2279 /* Normally no need to say anything here for external references,
2280 since assemble_external is called by the language-specific code
2281 when a declaration is first seen. */
2283 if (DECL_EXTERNAL (decl
))
2286 /* Do nothing for global register variables. */
2287 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2289 TREE_ASM_WRITTEN (decl
) = 1;
2293 /* If type was incomplete when the variable was declared,
2294 see if it is complete now. */
2296 if (DECL_SIZE (decl
) == 0)
2297 layout_decl (decl
, 0);
2299 /* Still incomplete => don't allocate it; treat the tentative defn
2300 (which is what it must have been) as an `extern' reference. */
2302 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2304 error ("storage size of %q+D isn%'t known", decl
);
2305 TREE_ASM_WRITTEN (decl
) = 1;
2309 /* The first declaration of a variable that comes through this function
2310 decides whether it is global (in C, has external linkage)
2311 or local (in C, has internal linkage). So do nothing more
2312 if this function has already run. */
2314 if (TREE_ASM_WRITTEN (decl
))
2317 /* Make sure targetm.encode_section_info is invoked before we set
2319 decl_rtl
= DECL_RTL (decl
);
2321 TREE_ASM_WRITTEN (decl
) = 1;
2323 /* Do no output if -fsyntax-only. */
2324 if (flag_syntax_only
)
2327 if (! dont_output_data
2328 && ! valid_constant_size_p (DECL_SIZE_UNIT (decl
)))
2330 error ("size of variable %q+D is too large", decl
);
2334 gcc_assert (MEM_P (decl_rtl
));
2335 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2336 symbol
= XEXP (decl_rtl
, 0);
2338 /* If this symbol belongs to the tree constant pool, output the constant
2339 if it hasn't already been written. */
2340 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
2342 tree decl
= SYMBOL_REF_DECL (symbol
);
2343 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2344 output_constant_def_contents (symbol
);
2350 name
= XSTR (symbol
, 0);
2351 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2352 notice_global_symbol (decl
);
2354 /* Compute the alignment of this data. */
2356 align_variable (decl
, dont_output_data
);
2358 if ((flag_sanitize
& SANITIZE_ADDRESS
)
2359 && asan_protect_global (decl
))
2361 asan_protected
= true;
2362 SET_DECL_ALIGN (decl
, MAX (DECL_ALIGN (decl
),
2363 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
));
2366 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2368 align
= get_variable_align (decl
);
2370 if (TREE_PUBLIC (decl
))
2371 maybe_assemble_visibility (decl
);
2373 if (DECL_PRESERVE_P (decl
))
2374 targetm
.asm_out
.mark_decl_preserved (name
);
2376 /* First make the assembler name(s) global if appropriate. */
2377 sect
= get_variable_section (decl
, false);
2378 if (TREE_PUBLIC (decl
)
2379 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2380 globalize_decl (decl
);
2382 /* Output any data that we will need to use the address of. */
2383 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2384 output_addressed_constants (DECL_INITIAL (decl
), 0);
2386 /* dbxout.cc needs to know this. */
2387 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2388 DECL_IN_TEXT_SECTION (decl
) = 1;
2390 /* If the decl is part of an object_block, make sure that the decl
2391 has been positioned within its block, but do not write out its
2392 definition yet. output_object_blocks will do that later. */
2393 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2395 gcc_assert (!dont_output_data
);
2396 place_block_symbol (symbol
);
2398 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2399 assemble_noswitch_variable (decl
, name
, sect
, align
);
2402 /* Special-case handling of vtv comdat sections. */
2403 if (SECTION_STYLE (sect
) == SECTION_NAMED
2404 && (strcmp (sect
->named
.name
, ".vtable_map_vars") == 0))
2405 handle_vtv_comdat_section (sect
, decl
);
2407 switch_to_section (sect
, decl
);
2408 if (align
> BITS_PER_UNIT
)
2409 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2410 assemble_variable_contents (decl
, name
, dont_output_data
,
2411 (sect
->common
.flags
& SECTION_MERGE
)
2412 && (sect
->common
.flags
& SECTION_STRINGS
));
2415 unsigned HOST_WIDE_INT
int size
2416 = tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2417 assemble_zeros (asan_red_zone_size (size
));
2422 /* Return true if type TYPE contains any pointers. */
2425 contains_pointers_p (tree type
)
2427 switch (TREE_CODE (type
))
2430 case REFERENCE_TYPE
:
2431 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2432 so I'll play safe and return 1. */
2438 case QUAL_UNION_TYPE
:
2441 /* For a type that has fields, see if the fields have pointers. */
2442 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
2443 if (TREE_CODE (fields
) == FIELD_DECL
2444 && contains_pointers_p (TREE_TYPE (fields
)))
2450 /* An array type contains pointers if its element type does. */
2451 return contains_pointers_p (TREE_TYPE (type
));
2458 /* We delay assemble_external processing until
2459 the compilation unit is finalized. This is the best we can do for
2460 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2461 it all the way to final. See PR 17982 for further discussion. */
2462 static GTY(()) tree pending_assemble_externals
;
2464 /* A similar list of pending libcall symbols. We only want to declare
2465 symbols that are actually used in the final assembly. */
2466 static GTY(()) rtx pending_libcall_symbols
;
2468 #ifdef ASM_OUTPUT_EXTERNAL
2469 /* Some targets delay some output to final using TARGET_ASM_FILE_END.
2470 As a result, assemble_external can be called after the list of externals
2471 is processed and the pointer set destroyed. */
2472 static bool pending_assemble_externals_processed
;
2474 /* Avoid O(external_decls**2) lookups in the pending_assemble_externals
2475 TREE_LIST in assemble_external. */
2476 static hash_set
<tree
> *pending_assemble_externals_set
;
2478 /* True if DECL is a function decl for which no out-of-line copy exists.
2479 It is assumed that DECL's assembler name has been set. */
2482 incorporeal_function_p (tree decl
)
2484 if (TREE_CODE (decl
) == FUNCTION_DECL
&& fndecl_built_in_p (decl
))
2488 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2489 && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl
)))
2492 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2493 /* Atomic or sync builtins which have survived this far will be
2494 resolved externally and therefore are not incorporeal. */
2495 if (startswith (name
, "__builtin_"))
2501 /* Actually do the tests to determine if this is necessary, and invoke
2502 ASM_OUTPUT_EXTERNAL. */
2504 assemble_external_real (tree decl
)
2506 rtx rtl
= DECL_RTL (decl
);
2508 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2509 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2510 && !incorporeal_function_p (decl
))
2512 /* Some systems do require some output. */
2513 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2514 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2520 process_pending_assemble_externals (void)
2522 #ifdef ASM_OUTPUT_EXTERNAL
2524 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2525 assemble_external_real (TREE_VALUE (list
));
2527 for (rtx list
= pending_libcall_symbols
; list
; list
= XEXP (list
, 1))
2529 rtx symbol
= XEXP (list
, 0);
2530 tree id
= get_identifier (XSTR (symbol
, 0));
2531 if (TREE_SYMBOL_REFERENCED (id
))
2532 targetm
.asm_out
.external_libcall (symbol
);
2535 pending_assemble_externals
= 0;
2536 pending_assemble_externals_processed
= true;
2537 pending_libcall_symbols
= NULL_RTX
;
2538 delete pending_assemble_externals_set
;
2542 /* This TREE_LIST contains any weak symbol declarations waiting
2544 static GTY(()) tree weak_decls
;
2546 /* Output something to declare an external symbol to the assembler,
2547 and qualifiers such as weakness. (Most assemblers don't need
2548 extern declaration, so we normally output nothing.) Do nothing if
2549 DECL is not external. */
2552 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2554 /* Make sure that the ASM_OUT_FILE is open.
2555 If it's not, we should not be calling this function. */
2556 gcc_assert (asm_out_file
);
2558 /* In a perfect world, the following condition would be true.
2559 Sadly, the Go front end emit assembly *from the front end*,
2560 bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2562 /* This function should only be called if we are expanding, or have
2564 Ideally, only final.cc would be calling this function, but it is
2565 not clear whether that would break things somehow. See PR 17982
2566 for further discussion. */
2567 gcc_assert (state
== EXPANSION
2568 || state
== FINISHED
);
2571 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2574 /* We want to output annotation for weak and external symbols at
2575 very last to check if they are references or not. */
2577 if (TARGET_SUPPORTS_WEAK
2579 /* TREE_STATIC is a weird and abused creature which is not
2580 generally the right test for whether an entity has been
2581 locally emitted, inlined or otherwise not-really-extern, but
2582 for declarations that can be weak, it happens to be
2584 && !TREE_STATIC (decl
)
2585 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2586 && value_member (decl
, weak_decls
) == NULL_TREE
)
2587 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2589 #ifdef ASM_OUTPUT_EXTERNAL
2590 if (pending_assemble_externals_processed
)
2592 assemble_external_real (decl
);
2596 if (! pending_assemble_externals_set
->add (decl
))
2597 pending_assemble_externals
= tree_cons (NULL
, decl
,
2598 pending_assemble_externals
);
2602 /* Similar, for calling a library function FUN. */
2605 assemble_external_libcall (rtx fun
)
2607 /* Declare library function name external when first used, if nec. */
2608 if (! SYMBOL_REF_USED (fun
))
2610 #ifdef ASM_OUTPUT_EXTERNAL
2611 gcc_assert (!pending_assemble_externals_processed
);
2613 SYMBOL_REF_USED (fun
) = 1;
2614 /* Make sure the libcall symbol is in the symtab so any
2615 reference to it will mark its tree node as referenced, via
2616 assemble_name_resolve. These are eventually emitted, if
2617 used, in process_pending_assemble_externals. */
2618 get_identifier (XSTR (fun
, 0));
2619 pending_libcall_symbols
= gen_rtx_EXPR_LIST (VOIDmode
, fun
,
2620 pending_libcall_symbols
);
2624 /* Assemble a label named NAME. */
2627 assemble_label (FILE *file
, const char *name
)
2629 ASM_OUTPUT_LABEL (file
, name
);
2632 /* Set the symbol_referenced flag for ID. */
2634 mark_referenced (tree id
)
2636 TREE_SYMBOL_REFERENCED (id
) = 1;
2639 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2641 mark_decl_referenced (tree decl
)
2643 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2645 /* Extern inline functions don't become needed when referenced.
2646 If we know a method will be emitted in other TU and no new
2647 functions can be marked reachable, just use the external
2649 struct cgraph_node
*node
= cgraph_node::get_create (decl
);
2650 if (!DECL_EXTERNAL (decl
)
2651 && !node
->definition
)
2652 node
->mark_force_output ();
2654 else if (VAR_P (decl
))
2656 varpool_node
*node
= varpool_node::get_create (decl
);
2657 /* C++ frontend use mark_decl_references to force COMDAT variables
2658 to be output that might appear dead otherwise. */
2659 node
->force_output
= true;
2661 /* else do nothing - we can get various sorts of CST nodes here,
2662 which do not need to be marked. */
2666 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2667 starts with a *, the rest of NAME is output verbatim. Otherwise
2668 NAME is transformed in a target-specific way (usually by the
2669 addition of an underscore). */
2672 assemble_name_raw (FILE *file
, const char *name
)
2675 fputs (&name
[1], file
);
2677 ASM_OUTPUT_LABELREF (file
, name
);
2680 /* Return NAME that should actually be emitted, looking through
2681 transparent aliases. If NAME refers to an entity that is also
2682 represented as a tree (like a function or variable), mark the entity
2685 assemble_name_resolve (const char *name
)
2687 const char *real_name
= targetm
.strip_name_encoding (name
);
2688 tree id
= maybe_get_identifier (real_name
);
2694 mark_referenced (id
);
2695 ultimate_transparent_alias_target (&id
);
2697 name
= IDENTIFIER_POINTER (id
);
2698 gcc_assert (! TREE_CHAIN (id
));
2704 /* Like assemble_name_raw, but should be used when NAME might refer to
2705 an entity that is also represented as a tree (like a function or
2706 variable). If NAME does refer to such an entity, that entity will
2707 be marked as referenced. */
2710 assemble_name (FILE *file
, const char *name
)
2712 assemble_name_raw (file
, assemble_name_resolve (name
));
2715 /* Allocate SIZE bytes writable static space with a gensym name
2716 and return an RTX to refer to its address. */
2719 assemble_static_space (unsigned HOST_WIDE_INT size
)
2722 const char *namestring
;
2725 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2727 namestring
= ggc_strdup (name
);
2729 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2730 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2732 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2733 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2736 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2737 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2740 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2741 so that each uninitialized object starts on such a boundary. */
2742 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2743 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2744 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2745 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2746 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2747 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2754 /* Assemble the static constant template for function entry trampolines.
2755 This is done at most once per compilation.
2756 Returns an RTX for the address of the template. */
2758 static GTY(()) rtx initial_trampoline
;
2761 assemble_trampoline_template (void)
2768 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2770 if (initial_trampoline
)
2771 return initial_trampoline
;
2773 /* By default, put trampoline templates in read-only data section. */
2775 #ifdef TRAMPOLINE_SECTION
2776 switch_to_section (TRAMPOLINE_SECTION
);
2778 switch_to_section (readonly_data_section
);
2781 /* Write the assembler code to define one. */
2782 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2784 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2786 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2787 targetm
.asm_out
.trampoline_template (asm_out_file
);
2789 /* Record the rtl to refer to it. */
2790 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2791 name
= ggc_strdup (label
);
2792 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2793 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2795 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2796 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2797 set_mem_size (initial_trampoline
, TRAMPOLINE_SIZE
);
2799 return initial_trampoline
;
2802 /* A and B are either alignments or offsets. Return the minimum alignment
2803 that may be assumed after adding the two together. */
2805 static inline unsigned
2806 min_align (unsigned int a
, unsigned int b
)
2808 return least_bit_hwi (a
| b
);
2811 /* Return the assembler directive for creating a given kind of integer
2812 object. SIZE is the number of bytes in the object and ALIGNED_P
2813 indicates whether it is known to be aligned. Return NULL if the
2814 assembly dialect has no such directive.
2816 The returned string should be printed at the start of a new line and
2817 be followed immediately by the object's initial value. */
2820 integer_asm_op (int size
, int aligned_p
)
2822 struct asm_int_op
*ops
;
2825 ops
= &targetm
.asm_out
.aligned_op
;
2827 ops
= &targetm
.asm_out
.unaligned_op
;
2832 return targetm
.asm_out
.byte_op
;
2860 /* Use directive OP to assemble an integer object X. Print OP at the
2861 start of the line, followed immediately by the value of X. */
2864 assemble_integer_with_op (const char *op
, rtx x
)
2866 fputs (op
, asm_out_file
);
2867 output_addr_const (asm_out_file
, x
);
2868 fputc ('\n', asm_out_file
);
2871 /* The default implementation of the asm_out.integer target hook. */
2874 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2875 unsigned int size ATTRIBUTE_UNUSED
,
2876 int aligned_p ATTRIBUTE_UNUSED
)
2878 const char *op
= integer_asm_op (size
, aligned_p
);
2879 /* Avoid GAS bugs for large values. Specifically negative values whose
2880 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2881 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE_UNITS
)
2883 return op
&& (assemble_integer_with_op (op
, x
), true);
2886 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2887 the alignment of the integer in bits. Return 1 if we were able to output
2888 the constant, otherwise 0. We must be able to output the constant,
2889 if FORCE is nonzero. */
2892 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2896 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2898 /* See if the target hook can handle this kind of object. */
2899 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2902 /* If the object is a multi-byte one, try splitting it up. Split
2903 it into words it if is multi-word, otherwise split it into bytes. */
2906 machine_mode omode
, imode
;
2907 unsigned int subalign
;
2908 unsigned int subsize
, i
;
2909 enum mode_class mclass
;
2911 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2912 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2913 if (GET_CODE (x
) == CONST_FIXED
)
2914 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2918 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0).require ();
2919 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0).require ();
2921 for (i
= 0; i
< size
; i
+= subsize
)
2923 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2924 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2930 /* If we've printed some of it, but not all of it, there's no going
2935 gcc_assert (!force
);
2940 /* Assemble the floating-point constant D into an object of size MODE. ALIGN
2941 is the alignment of the constant in bits. If REVERSE is true, D is output
2942 in reverse storage order. */
2945 assemble_real (REAL_VALUE_TYPE d
, scalar_float_mode mode
, unsigned int align
,
2948 long data
[4] = {0, 0, 0, 0};
2949 int bitsize
, nelts
, nunits
, units_per
;
2952 /* This is hairy. We have a quantity of known size. real_to_target
2953 will put it into an array of *host* longs, 32 bits per element
2954 (even if long is more than 32 bits). We need to determine the
2955 number of array elements that are occupied (nelts) and the number
2956 of *target* min-addressable units that will be occupied in the
2957 object file (nunits). We cannot assume that 32 divides the
2958 mode's bitsize (size * BITS_PER_UNIT) evenly.
2960 size * BITS_PER_UNIT is used here to make sure that padding bits
2961 (which might appear at either end of the value; real_to_target
2962 will include the padding bits in its output array) are included. */
2964 nunits
= GET_MODE_SIZE (mode
);
2965 bitsize
= nunits
* BITS_PER_UNIT
;
2966 nelts
= CEIL (bitsize
, 32);
2967 units_per
= 32 / BITS_PER_UNIT
;
2969 real_to_target (data
, &d
, mode
);
2971 /* Put out the first word with the specified alignment. */
2972 unsigned int chunk_nunits
= MIN (nunits
, units_per
);
2974 elt
= flip_storage_order (SImode
, gen_int_mode (data
[nelts
- 1], SImode
));
2976 elt
= GEN_INT (sext_hwi (data
[0], chunk_nunits
* BITS_PER_UNIT
));
2977 assemble_integer (elt
, chunk_nunits
, align
, 1);
2978 nunits
-= chunk_nunits
;
2980 /* Subsequent words need only 32-bit alignment. */
2981 align
= min_align (align
, 32);
2983 for (int i
= 1; i
< nelts
; i
++)
2985 chunk_nunits
= MIN (nunits
, units_per
);
2987 elt
= flip_storage_order (SImode
,
2988 gen_int_mode (data
[nelts
- 1 - i
], SImode
));
2990 elt
= GEN_INT (sext_hwi (data
[i
], chunk_nunits
* BITS_PER_UNIT
));
2991 assemble_integer (elt
, chunk_nunits
, align
, 1);
2992 nunits
-= chunk_nunits
;
2996 /* Given an expression EXP with a constant value,
2997 reduce it to the sum of an assembler symbol and an integer.
2998 Store them both in the structure *VALUE.
2999 EXP must be reducible. */
3008 decode_addr_const (tree exp
, class addr_const
*value
)
3010 tree target
= TREE_OPERAND (exp
, 0);
3011 poly_int64 offset
= 0;
3017 if (TREE_CODE (target
) == COMPONENT_REF
3018 && poly_int_tree_p (byte_position (TREE_OPERAND (target
, 1)),
3022 target
= TREE_OPERAND (target
, 0);
3024 else if (TREE_CODE (target
) == ARRAY_REF
3025 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
3027 /* Truncate big offset. */
3029 += (TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (target
)))
3030 * wi::to_poly_widest (TREE_OPERAND (target
, 1)).force_shwi ());
3031 target
= TREE_OPERAND (target
, 0);
3033 else if (TREE_CODE (target
) == MEM_REF
3034 && TREE_CODE (TREE_OPERAND (target
, 0)) == ADDR_EXPR
)
3036 offset
+= mem_ref_offset (target
).force_shwi ();
3037 target
= TREE_OPERAND (TREE_OPERAND (target
, 0), 0);
3039 else if (INDIRECT_REF_P (target
)
3040 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
3041 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
3043 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
3048 switch (TREE_CODE (target
))
3052 x
= DECL_RTL (target
);
3056 x
= gen_rtx_MEM (FUNCTION_MODE
,
3057 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
3066 x
= lookup_constant_def (target
);
3067 /* Should have been added by output_addressed_constants. */
3072 /* This deals with absolute addresses. */
3073 offset
+= tree_to_shwi (TREE_OPERAND (target
, 0));
3074 x
= gen_rtx_MEM (QImode
,
3075 gen_rtx_SYMBOL_REF (Pmode
, "origin of addresses"));
3078 case COMPOUND_LITERAL_EXPR
:
3079 gcc_assert (COMPOUND_LITERAL_EXPR_DECL (target
));
3080 x
= DECL_RTL (COMPOUND_LITERAL_EXPR_DECL (target
));
3087 gcc_assert (MEM_P (x
));
3091 value
->offset
= offset
;
3094 static GTY(()) hash_table
<tree_descriptor_hasher
> *const_desc_htab
;
3096 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
3098 /* Constant pool accessor function. */
3100 hash_table
<tree_descriptor_hasher
> *
3101 constant_pool_htab (void)
3103 return const_desc_htab
;
3106 /* Compute a hash code for a constant expression. */
3109 tree_descriptor_hasher::hash (constant_descriptor_tree
*ptr
)
3115 const_hash_1 (const tree exp
)
3120 enum tree_code code
= TREE_CODE (exp
);
3122 /* Either set P and LEN to the address and len of something to hash and
3123 exit the switch or return a value. */
3128 p
= (char *) &TREE_INT_CST_ELT (exp
, 0);
3129 len
= TREE_INT_CST_NUNITS (exp
) * sizeof (HOST_WIDE_INT
);
3133 return real_hash (TREE_REAL_CST_PTR (exp
));
3136 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
3139 p
= TREE_STRING_POINTER (exp
);
3140 len
= TREE_STRING_LENGTH (exp
);
3144 return (const_hash_1 (TREE_REALPART (exp
)) * 5
3145 + const_hash_1 (TREE_IMAGPART (exp
)));
3149 hi
= 7 + VECTOR_CST_NPATTERNS (exp
);
3150 hi
= hi
* 563 + VECTOR_CST_NELTS_PER_PATTERN (exp
);
3151 unsigned int count
= vector_cst_encoded_nelts (exp
);
3152 for (unsigned int i
= 0; i
< count
; ++i
)
3153 hi
= hi
* 563 + const_hash_1 (VECTOR_CST_ENCODED_ELT (exp
, i
));
3159 unsigned HOST_WIDE_INT idx
;
3162 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
3164 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
3166 hi
= hi
* 603 + const_hash_1 (value
);
3172 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
3173 return const_hash_1 (TREE_OPERAND (exp
, 0));
3178 class addr_const value
;
3180 decode_addr_const (exp
, &value
);
3181 switch (GET_CODE (value
.base
))
3184 /* Don't hash the address of the SYMBOL_REF;
3185 only use the offset and the symbol name. */
3186 hi
= value
.offset
.coeffs
[0];
3187 p
= XSTR (value
.base
, 0);
3188 for (i
= 0; p
[i
] != 0; i
++)
3189 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
3193 hi
= (value
.offset
.coeffs
[0]
3194 + CODE_LABEL_NUMBER (label_ref_label (value
.base
)) * 13);
3204 case POINTER_PLUS_EXPR
:
3206 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
3207 + const_hash_1 (TREE_OPERAND (exp
, 1)));
3210 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
3213 /* A language specific constant. Just hash the code. */
3217 /* Compute hashing function. */
3219 for (i
= 0; i
< len
; i
++)
3220 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
3225 /* Wrapper of compare_constant, for the htab interface. */
3227 tree_descriptor_hasher::equal (constant_descriptor_tree
*c1
,
3228 constant_descriptor_tree
*c2
)
3230 if (c1
->hash
!= c2
->hash
)
3232 return compare_constant (c1
->value
, c2
->value
);
3235 /* Compare t1 and t2, and return true only if they are known to result in
3236 the same bit pattern on output. */
3239 compare_constant (const tree t1
, const tree t2
)
3241 enum tree_code typecode
;
3243 if (t1
== NULL_TREE
)
3244 return t2
== NULL_TREE
;
3245 if (t2
== NULL_TREE
)
3248 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3251 switch (TREE_CODE (t1
))
3254 /* Integer constants are the same only if the same width of type. */
3255 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3257 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3259 return tree_int_cst_equal (t1
, t2
);
3262 /* Real constants are the same only if the same width of type. In
3263 addition to the same width, we need to check whether the modes are the
3264 same. There might be two floating point modes that are the same size
3265 but have different representations, such as the PowerPC that has 2
3266 different 128-bit floating point types (IBM extended double and IEEE
3267 128-bit floating point). */
3268 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3270 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3272 return real_identical (&TREE_REAL_CST (t1
), &TREE_REAL_CST (t2
));
3275 /* Fixed constants are the same only if the same width of type. */
3276 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3279 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
3282 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3283 || int_size_in_bytes (TREE_TYPE (t1
))
3284 != int_size_in_bytes (TREE_TYPE (t2
)))
3287 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3288 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3289 TREE_STRING_LENGTH (t1
)));
3292 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
3293 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
3297 if (VECTOR_CST_NPATTERNS (t1
)
3298 != VECTOR_CST_NPATTERNS (t2
))
3301 if (VECTOR_CST_NELTS_PER_PATTERN (t1
)
3302 != VECTOR_CST_NELTS_PER_PATTERN (t2
))
3305 unsigned int count
= vector_cst_encoded_nelts (t1
);
3306 for (unsigned int i
= 0; i
< count
; ++i
)
3307 if (!compare_constant (VECTOR_CST_ENCODED_ELT (t1
, i
),
3308 VECTOR_CST_ENCODED_ELT (t2
, i
)))
3316 vec
<constructor_elt
, va_gc
> *v1
, *v2
;
3317 unsigned HOST_WIDE_INT idx
;
3319 typecode
= TREE_CODE (TREE_TYPE (t1
));
3320 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3323 if (typecode
== ARRAY_TYPE
)
3325 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3326 /* For arrays, check that mode, size and storage order match. */
3327 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3329 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
))
3330 || TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t1
))
3331 != TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t2
)))
3336 /* For record and union constructors, require exact type
3338 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3342 v1
= CONSTRUCTOR_ELTS (t1
);
3343 v2
= CONSTRUCTOR_ELTS (t2
);
3344 if (vec_safe_length (v1
) != vec_safe_length (v2
))
3347 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
3349 constructor_elt
*c1
= &(*v1
)[idx
];
3350 constructor_elt
*c2
= &(*v2
)[idx
];
3352 /* Check that each value is the same... */
3353 if (!compare_constant (c1
->value
, c2
->value
))
3355 /* ... and that they apply to the same fields! */
3356 if (typecode
== ARRAY_TYPE
)
3358 if (!compare_constant (c1
->index
, c2
->index
))
3363 if (c1
->index
!= c2
->index
)
3374 class addr_const value1
, value2
;
3378 decode_addr_const (t1
, &value1
);
3379 decode_addr_const (t2
, &value2
);
3381 if (maybe_ne (value1
.offset
, value2
.offset
))
3384 code
= GET_CODE (value1
.base
);
3385 if (code
!= GET_CODE (value2
.base
))
3391 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3395 ret
= (CODE_LABEL_NUMBER (label_ref_label (value1
.base
))
3396 == CODE_LABEL_NUMBER (label_ref_label (value2
.base
)));
3406 case POINTER_PLUS_EXPR
:
3409 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3410 && compare_constant (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3413 case VIEW_CONVERT_EXPR
:
3414 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3421 /* Return the section into which constant EXP should be placed. */
3424 get_constant_section (tree exp
, unsigned int align
)
3426 return targetm
.asm_out
.select_section (exp
,
3427 compute_reloc_for_constant (exp
),
3431 /* Return the size of constant EXP in bytes. */
3433 static HOST_WIDE_INT
3434 get_constant_size (tree exp
)
3438 size
= int_size_in_bytes (TREE_TYPE (exp
));
3439 gcc_checking_assert (size
>= 0);
3440 gcc_checking_assert (TREE_CODE (exp
) != STRING_CST
3441 || size
>= TREE_STRING_LENGTH (exp
));
3445 /* Subroutine of output_constant_def:
3446 No constant equal to EXP is known to have been output.
3447 Make a constant descriptor to enter EXP in the hash table.
3448 Assign the label number and construct RTL to refer to the
3449 constant's location in memory.
3450 Caller is responsible for updating the hash table. */
3452 static struct constant_descriptor_tree
*
3453 build_constant_desc (tree exp
)
3455 struct constant_descriptor_tree
*desc
;
3461 desc
= ggc_alloc
<constant_descriptor_tree
> ();
3464 /* Create a string containing the label name, in LABEL. */
3465 labelno
= const_labelno
++;
3466 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3468 /* Construct the VAR_DECL associated with the constant. */
3469 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3471 DECL_ARTIFICIAL (decl
) = 1;
3472 DECL_IGNORED_P (decl
) = 1;
3473 TREE_READONLY (decl
) = 1;
3474 TREE_STATIC (decl
) = 1;
3475 TREE_ADDRESSABLE (decl
) = 1;
3476 /* We don't set the RTL yet as this would cause varpool to assume that the
3477 variable is referenced. Moreover, it would just be dropped in LTO mode.
3478 Instead we set the flag that will be recognized in make_decl_rtl. */
3479 DECL_IN_CONSTANT_POOL (decl
) = 1;
3480 DECL_INITIAL (decl
) = desc
->value
;
3481 /* ??? targetm.constant_alignment hasn't been updated for vector types on
3482 most architectures so use DATA_ALIGNMENT as well, except for strings. */
3483 if (TREE_CODE (exp
) == STRING_CST
)
3484 SET_DECL_ALIGN (decl
, targetm
.constant_alignment (exp
, DECL_ALIGN (decl
)));
3487 align_variable (decl
, 0);
3488 if (DECL_ALIGN (decl
) < GET_MODE_ALIGNMENT (DECL_MODE (decl
))
3489 && ((optab_handler (movmisalign_optab
, DECL_MODE (decl
))
3490 != CODE_FOR_nothing
)
3491 || targetm
.slow_unaligned_access (DECL_MODE (decl
),
3492 DECL_ALIGN (decl
))))
3493 SET_DECL_ALIGN (decl
, GET_MODE_ALIGNMENT (DECL_MODE (decl
)));
3496 /* Now construct the SYMBOL_REF and the MEM. */
3497 if (use_object_blocks_p ())
3499 int align
= (TREE_CODE (decl
) == CONST_DECL
3500 || (VAR_P (decl
) && DECL_IN_CONSTANT_POOL (decl
))
3502 : symtab_node::get (decl
)->definition_alignment ());
3503 section
*sect
= get_constant_section (exp
, align
);
3504 symbol
= create_block_symbol (ggc_strdup (label
),
3505 get_block_for_section (sect
), -1);
3508 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3509 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3510 SET_SYMBOL_REF_DECL (symbol
, decl
);
3511 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3513 rtl
= gen_const_mem (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3514 set_mem_alias_set (rtl
, 0);
3516 /* Putting EXP into the literal pool might have imposed a different
3517 alignment which should be visible in the RTX as well. */
3518 set_mem_align (rtl
, DECL_ALIGN (decl
));
3520 /* We cannot share RTX'es in pool entries.
3521 Mark this piece of RTL as required for unsharing. */
3522 RTX_FLAG (rtl
, used
) = 1;
3524 /* Set flags or add text to the name to record information, such as
3525 that it is a local symbol. If the name is changed, the macro
3526 ASM_OUTPUT_LABELREF will have to know how to strip this
3527 information. This call might invalidate our local variable
3528 SYMBOL; we can't use it afterward. */
3529 targetm
.encode_section_info (exp
, rtl
, true);
3536 /* Subroutine of output_constant_def and tree_output_constant_def:
3537 Add a constant to the hash table that tracks which constants
3538 already have labels. */
3540 static constant_descriptor_tree
*
3541 add_constant_to_table (tree exp
, int defer
)
3543 /* The hash table methods may call output_constant_def for addressed
3544 constants, so handle them first. */
3545 output_addressed_constants (exp
, defer
);
3547 /* Sanity check to catch recursive insertion. */
3548 static bool inserting
;
3549 gcc_assert (!inserting
);
3552 /* Look up EXP in the table of constant descriptors. If we didn't
3553 find it, create a new one. */
3554 struct constant_descriptor_tree key
;
3556 key
.hash
= const_hash_1 (exp
);
3557 constant_descriptor_tree
**loc
3558 = const_desc_htab
->find_slot_with_hash (&key
, key
.hash
, INSERT
);
3562 struct constant_descriptor_tree
*desc
= *loc
;
3565 desc
= build_constant_desc (exp
);
3566 desc
->hash
= key
.hash
;
3573 /* Return an rtx representing a reference to constant data in memory
3574 for the constant expression EXP.
3576 If assembler code for such a constant has already been output,
3577 return an rtx to refer to it.
3578 Otherwise, output such a constant in memory
3579 and generate an rtx for it.
3581 If DEFER is nonzero, this constant can be deferred and output only
3582 if referenced in the function after all optimizations.
3584 `const_desc_table' records which constants already have label strings. */
3587 output_constant_def (tree exp
, int defer
)
3589 struct constant_descriptor_tree
*desc
= add_constant_to_table (exp
, defer
);
3590 maybe_output_constant_def_contents (desc
, defer
);
3594 /* Subroutine of output_constant_def: Decide whether or not we need to
3595 output the constant DESC now, and if so, do it. */
3597 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3600 rtx symbol
= XEXP (desc
->rtl
, 0);
3601 tree exp
= desc
->value
;
3603 if (flag_syntax_only
)
3606 if (TREE_ASM_WRITTEN (exp
))
3607 /* Already output; don't do it again. */
3610 /* We can always defer constants as long as the context allows
3614 /* Increment n_deferred_constants if it exists. It needs to be at
3615 least as large as the number of constants actually referred to
3616 by the function. If it's too small we'll stop looking too early
3617 and fail to emit constants; if it's too large we'll only look
3618 through the entire function when we could have stopped earlier. */
3620 n_deferred_constants
++;
3624 output_constant_def_contents (symbol
);
3627 /* Subroutine of output_constant_def_contents. Output the definition
3628 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3629 constant's alignment in bits. */
3632 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
,
3637 size
= get_constant_size (exp
);
3639 /* Do any machine/system dependent processing of the constant. */
3640 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3642 /* Output the value of EXP. */
3643 output_constant (exp
, size
, align
, false, merge_strings
);
3645 targetm
.asm_out
.decl_end ();
3648 /* We must output the constant data referred to by SYMBOL; do so. */
3651 output_constant_def_contents (rtx symbol
)
3653 tree decl
= SYMBOL_REF_DECL (symbol
);
3654 tree exp
= DECL_INITIAL (decl
);
3655 bool asan_protected
= false;
3657 /* Make sure any other constants whose addresses appear in EXP
3658 are assigned label numbers. */
3659 output_addressed_constants (exp
, 0);
3661 /* We are no longer deferring this constant. */
3662 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3664 if ((flag_sanitize
& SANITIZE_ADDRESS
)
3665 && TREE_CODE (exp
) == STRING_CST
3666 && asan_protect_global (exp
))
3668 asan_protected
= true;
3669 SET_DECL_ALIGN (decl
, MAX (DECL_ALIGN (decl
),
3670 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
));
3673 /* If the constant is part of an object block, make sure that the
3674 decl has been positioned within its block, but do not write out
3675 its definition yet. output_object_blocks will do that later. */
3676 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3677 place_block_symbol (symbol
);
3680 int align
= (TREE_CODE (decl
) == CONST_DECL
3681 || (VAR_P (decl
) && DECL_IN_CONSTANT_POOL (decl
))
3683 : symtab_node::get (decl
)->definition_alignment ());
3684 section
*sect
= get_constant_section (exp
, align
);
3685 switch_to_section (sect
);
3686 if (align
> BITS_PER_UNIT
)
3687 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3688 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
,
3689 (sect
->common
.flags
& SECTION_MERGE
)
3690 && (sect
->common
.flags
& SECTION_STRINGS
));
3693 HOST_WIDE_INT size
= get_constant_size (exp
);
3694 assemble_zeros (asan_red_zone_size (size
));
3699 /* Look up EXP in the table of constant descriptors. Return the rtl
3700 if it has been emitted, else null. */
3703 lookup_constant_def (tree exp
)
3705 struct constant_descriptor_tree key
;
3708 key
.hash
= const_hash_1 (exp
);
3709 constant_descriptor_tree
*desc
3710 = const_desc_htab
->find_with_hash (&key
, key
.hash
);
3712 return (desc
? desc
->rtl
: NULL_RTX
);
3715 /* Return a tree representing a reference to constant data in memory
3716 for the constant expression EXP.
3718 This is the counterpart of output_constant_def at the Tree level. */
3721 tree_output_constant_def (tree exp
)
3723 struct constant_descriptor_tree
*desc
= add_constant_to_table (exp
, 1);
3724 tree decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3725 varpool_node::finalize_decl (decl
);
3729 class GTY((chain_next ("%h.next"), for_user
)) constant_descriptor_rtx
{
3731 class constant_descriptor_rtx
*next
;
3735 HOST_WIDE_INT offset
;
3737 fixed_size_mode mode
;
3743 struct const_rtx_desc_hasher
: ggc_ptr_hash
<constant_descriptor_rtx
>
3745 static hashval_t
hash (constant_descriptor_rtx
*);
3746 static bool equal (constant_descriptor_rtx
*, constant_descriptor_rtx
*);
3749 /* Used in the hash tables to avoid outputting the same constant
3750 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3751 are output once per function, not once per file. */
3752 /* ??? Only a few targets need per-function constant pools. Most
3753 can use one per-file pool. Should add a targetm bit to tell the
3756 struct GTY(()) rtx_constant_pool
{
3757 /* Pointers to first and last constant in pool, as ordered by offset. */
3758 class constant_descriptor_rtx
*first
;
3759 class constant_descriptor_rtx
*last
;
3761 /* Hash facility for making memory-constants from constant rtl-expressions.
3762 It is used on RISC machines where immediate integer arguments and
3763 constant addresses are restricted so that such constants must be stored
3765 hash_table
<const_rtx_desc_hasher
> *const_rtx_htab
;
3767 /* Current offset in constant pool (does not include any
3768 machine-specific header). */
3769 HOST_WIDE_INT offset
;
3772 /* Hash and compare functions for const_rtx_htab. */
3775 const_rtx_desc_hasher::hash (constant_descriptor_rtx
*desc
)
3781 const_rtx_desc_hasher::equal (constant_descriptor_rtx
*x
,
3782 constant_descriptor_rtx
*y
)
3784 if (x
->mode
!= y
->mode
)
3786 return rtx_equal_p (x
->constant
, y
->constant
);
3789 /* Hash one component of a constant. */
3792 const_rtx_hash_1 (const_rtx x
)
3794 unsigned HOST_WIDE_INT hwi
;
3800 code
= GET_CODE (x
);
3801 mode
= GET_MODE (x
);
3802 h
= (hashval_t
) code
* 1048573 + mode
;
3811 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3812 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3814 h
^= (hashval_t
) hwi
;
3815 for (i
= 1; i
< n
; ++i
)
3818 h
^= (hashval_t
) hwi
;
3823 case CONST_WIDE_INT
:
3826 for (i
= 0; i
< CONST_WIDE_INT_NUNITS (x
); i
++)
3827 hwi
^= CONST_WIDE_INT_ELT (x
, i
);
3832 if (TARGET_SUPPORTS_WIDE_INT
== 0 && mode
== VOIDmode
)
3834 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3838 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3842 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3846 h
^= htab_hash_string (XSTR (x
, 0));
3850 h
= h
* 251 + CODE_LABEL_NUMBER (label_ref_label (x
));
3854 case UNSPEC_VOLATILE
:
3855 h
= h
* 251 + XINT (x
, 1);
3865 /* Compute a hash value for X, which should be a constant. */
3868 const_rtx_hash (rtx x
)
3871 subrtx_iterator::array_type array
;
3872 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
3873 h
= h
* 509 + const_rtx_hash_1 (*iter
);
3878 /* Create and return a new rtx constant pool. */
3880 static struct rtx_constant_pool
*
3881 create_constant_pool (void)
3883 struct rtx_constant_pool
*pool
;
3885 pool
= ggc_alloc
<rtx_constant_pool
> ();
3886 pool
->const_rtx_htab
= hash_table
<const_rtx_desc_hasher
>::create_ggc (31);
3893 /* Initialize constant pool hashing for a new function. */
3896 init_varasm_status (void)
3898 crtl
->varasm
.pool
= create_constant_pool ();
3899 crtl
->varasm
.deferred_constants
= 0;
3902 /* Given a MINUS expression, simplify it if both sides
3903 include the same symbol. */
3906 simplify_subtraction (rtx x
)
3908 rtx r
= simplify_rtx (x
);
3912 /* Given a constant rtx X, make (or find) a memory constant for its value
3913 and return a MEM rtx to refer to it in memory. IN_MODE is the mode
3917 force_const_mem (machine_mode in_mode
, rtx x
)
3919 class constant_descriptor_rtx
*desc
, tmp
;
3920 struct rtx_constant_pool
*pool
;
3925 constant_descriptor_rtx
**slot
;
3926 fixed_size_mode mode
;
3928 /* We can't force variable-sized objects to memory. */
3929 if (!is_a
<fixed_size_mode
> (in_mode
, &mode
))
3932 /* If we're not allowed to drop X into the constant pool, don't. */
3933 if (targetm
.cannot_force_const_mem (mode
, x
))
3936 /* Record that this function has used a constant pool entry. */
3937 crtl
->uses_const_pool
= 1;
3939 /* Decide which pool to use. */
3940 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3941 ? shared_constant_pool
3942 : crtl
->varasm
.pool
);
3944 /* Lookup the value in the hashtable. */
3947 hash
= const_rtx_hash (x
);
3948 slot
= pool
->const_rtx_htab
->find_slot_with_hash (&tmp
, hash
, INSERT
);
3951 /* If the constant was already present, return its memory. */
3953 return copy_rtx (desc
->mem
);
3955 /* Otherwise, create a new descriptor. */
3956 desc
= ggc_alloc
<constant_descriptor_rtx
> ();
3959 /* Align the location counter as required by EXP's data type. */
3960 machine_mode align_mode
= (mode
== VOIDmode
? word_mode
: mode
);
3961 align
= targetm
.static_rtx_alignment (align_mode
);
3963 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3964 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3967 desc
->constant
= copy_rtx (tmp
.constant
);
3968 desc
->offset
= pool
->offset
;
3971 desc
->align
= align
;
3972 desc
->labelno
= const_labelno
;
3975 pool
->offset
+= GET_MODE_SIZE (mode
);
3977 pool
->last
->next
= desc
;
3979 pool
->first
= pool
->last
= desc
;
3982 /* Create a string containing the label name, in LABEL. */
3983 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3986 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3987 the constants pool. */
3988 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3990 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3991 symbol
= create_block_symbol (ggc_strdup (label
),
3992 get_block_for_section (sect
), -1);
3995 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3997 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3998 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3999 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
4001 /* Construct the MEM. */
4002 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
4003 set_mem_align (def
, align
);
4005 /* If we're dropping a label to the constant pool, make sure we
4007 if (GET_CODE (x
) == LABEL_REF
)
4008 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
4010 return copy_rtx (def
);
4013 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
4016 get_pool_constant (const_rtx addr
)
4018 return SYMBOL_REF_CONSTANT (addr
)->constant
;
4021 /* Given a constant pool SYMBOL_REF, return the corresponding constant
4022 and whether it has been output or not. */
4025 get_pool_constant_mark (rtx addr
, bool *pmarked
)
4027 class constant_descriptor_rtx
*desc
;
4029 desc
= SYMBOL_REF_CONSTANT (addr
);
4030 *pmarked
= (desc
->mark
!= 0);
4031 return desc
->constant
;
4034 /* Similar, return the mode. */
4037 get_pool_mode (const_rtx addr
)
4039 return SYMBOL_REF_CONSTANT (addr
)->mode
;
4042 /* Return TRUE if and only if the constant pool has no entries. Note
4043 that even entries we might end up choosing not to emit are counted
4044 here, so there is the potential for missed optimizations. */
4047 constant_pool_empty_p (void)
4049 return crtl
->varasm
.pool
->first
== NULL
;
4052 /* Worker function for output_constant_pool_1. Emit assembly for X
4053 in MODE with known alignment ALIGN. */
4056 output_constant_pool_2 (fixed_size_mode mode
, rtx x
, unsigned int align
)
4058 switch (GET_MODE_CLASS (mode
))
4061 case MODE_DECIMAL_FLOAT
:
4063 gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x
));
4064 assemble_real (*CONST_DOUBLE_REAL_VALUE (x
),
4065 as_a
<scalar_float_mode
> (mode
), align
, false);
4070 case MODE_PARTIAL_INT
:
4075 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
4078 case MODE_VECTOR_BOOL
:
4080 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
4082 /* Pick the smallest integer mode that contains at least one
4083 whole element. Often this is byte_mode and contains more
4084 than one element. */
4085 unsigned int nelts
= GET_MODE_NUNITS (mode
);
4086 unsigned int elt_bits
= GET_MODE_PRECISION (mode
) / nelts
;
4087 unsigned int int_bits
= MAX (elt_bits
, BITS_PER_UNIT
);
4088 scalar_int_mode int_mode
= int_mode_for_size (int_bits
, 0).require ();
4089 unsigned int mask
= GET_MODE_MASK (GET_MODE_INNER (mode
));
4091 /* We allow GET_MODE_PRECISION (mode) <= GET_MODE_BITSIZE (mode) but
4092 only properly handle cases where the difference is less than a
4094 gcc_assert (GET_MODE_BITSIZE (mode
) - GET_MODE_PRECISION (mode
) <
4097 /* Build the constant up one integer at a time. */
4098 unsigned int elts_per_int
= int_bits
/ elt_bits
;
4099 for (unsigned int i
= 0; i
< nelts
; i
+= elts_per_int
)
4101 unsigned HOST_WIDE_INT value
= 0;
4102 unsigned int limit
= MIN (nelts
- i
, elts_per_int
);
4103 for (unsigned int j
= 0; j
< limit
; ++j
)
4105 auto elt
= INTVAL (CONST_VECTOR_ELT (x
, i
+ j
));
4106 value
|= (elt
& mask
) << (j
* elt_bits
);
4108 output_constant_pool_2 (int_mode
, gen_int_mode (value
, int_mode
),
4109 i
!= 0 ? MIN (align
, int_bits
) : align
);
4113 case MODE_VECTOR_FLOAT
:
4114 case MODE_VECTOR_INT
:
4115 case MODE_VECTOR_FRACT
:
4116 case MODE_VECTOR_UFRACT
:
4117 case MODE_VECTOR_ACCUM
:
4118 case MODE_VECTOR_UACCUM
:
4121 scalar_mode submode
= GET_MODE_INNER (mode
);
4122 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
4124 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
4125 units
= GET_MODE_NUNITS (mode
);
4127 for (i
= 0; i
< units
; i
++)
4129 rtx elt
= CONST_VECTOR_ELT (x
, i
);
4130 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
4140 /* Worker function for output_constant_pool. Emit constant DESC,
4141 giving it ALIGN bits of alignment. */
4144 output_constant_pool_1 (class constant_descriptor_rtx
*desc
,
4151 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
4152 whose CODE_LABEL has been deleted. This can occur if a jump table
4153 is eliminated by optimization. If so, write a constant of zero
4154 instead. Note that this can also happen by turning the
4155 CODE_LABEL into a NOTE. */
4156 /* ??? This seems completely and utterly wrong. Certainly it's
4157 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
4158 functioning even with rtx_insn::deleted and friends. */
4161 switch (GET_CODE (tmp
))
4164 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
4165 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
4167 tmp
= XEXP (XEXP (tmp
, 0), 0);
4172 rtx_insn
*insn
= label_ref_label (tmp
);
4173 gcc_assert (!insn
->deleted ());
4174 gcc_assert (!NOTE_P (insn
)
4175 || NOTE_KIND (insn
) != NOTE_INSN_DELETED
);
4183 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4184 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
4185 align
, desc
->labelno
, done
);
4188 assemble_align (align
);
4190 /* Output the label. */
4191 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
4194 Pass actual alignment value while emitting string constant to asm code
4195 as function 'output_constant_pool_1' explicitly passes the alignment as 1
4196 assuming that the data is already aligned which prevents the generation
4197 of fix-up table entries. */
4198 output_constant_pool_2 (desc
->mode
, x
, desc
->align
);
4200 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
4201 sections have proper size. */
4202 if (align
> GET_MODE_BITSIZE (desc
->mode
)
4204 && (in_section
->common
.flags
& SECTION_MERGE
))
4205 assemble_align (align
);
4207 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4213 /* Recompute the offsets of entries in POOL, and the overall size of
4214 POOL. Do this after calling mark_constant_pool to ensure that we
4215 are computing the offset values for the pool which we will actually
4219 recompute_pool_offsets (struct rtx_constant_pool
*pool
)
4221 class constant_descriptor_rtx
*desc
;
4224 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
4227 /* Recalculate offset. */
4228 unsigned int align
= desc
->align
;
4229 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
4230 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
4231 desc
->offset
= pool
->offset
;
4232 pool
->offset
+= GET_MODE_SIZE (desc
->mode
);
4236 /* Mark all constants that are referenced by SYMBOL_REFs in X.
4237 Emit referenced deferred strings. */
4240 mark_constants_in_pattern (rtx insn
)
4242 subrtx_iterator::array_type array
;
4243 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), ALL
)
4245 const_rtx x
= *iter
;
4246 if (GET_CODE (x
) == SYMBOL_REF
)
4248 if (CONSTANT_POOL_ADDRESS_P (x
))
4250 class constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
4251 if (desc
->mark
== 0)
4254 iter
.substitute (desc
->constant
);
4257 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
4259 tree decl
= SYMBOL_REF_DECL (x
);
4260 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
4262 n_deferred_constants
--;
4263 output_constant_def_contents (CONST_CAST_RTX (x
));
4270 /* Look through appropriate parts of INSN, marking all entries in the
4271 constant pool which are actually being used. Entries that are only
4272 referenced by other constants are also marked as used. Emit
4273 deferred strings that are used. */
4276 mark_constants (rtx_insn
*insn
)
4281 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4282 insns, not any notes that may be attached. We don't want to mark
4283 a constant just because it happens to appear in a REG_EQUIV note. */
4284 if (rtx_sequence
*seq
= dyn_cast
<rtx_sequence
*> (PATTERN (insn
)))
4286 int i
, n
= seq
->len ();
4287 for (i
= 0; i
< n
; ++i
)
4289 rtx subinsn
= seq
->element (i
);
4290 if (INSN_P (subinsn
))
4291 mark_constants_in_pattern (subinsn
);
4295 mark_constants_in_pattern (insn
);
4298 /* Look through the instructions for this function, and mark all the
4299 entries in POOL which are actually being used. Emit deferred constants
4300 which have indeed been used. */
4303 mark_constant_pool (void)
4307 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
4310 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4311 mark_constants (insn
);
4314 /* Write all the constants in POOL. */
4317 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
4319 class constant_descriptor_rtx
*desc
;
4321 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
4324 #ifdef ASM_OUTPUT_DEF
4325 gcc_checking_assert (TARGET_SUPPORTS_ALIASES
);
4327 const char *name
= XSTR (desc
->sym
, 0);
4329 char buffer
[256 + 32];
4332 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", ~desc
->mark
);
4336 sprintf (buffer
, "%s+%ld", p
, (long) (desc
->offset
));
4339 ASM_OUTPUT_DEF (asm_out_file
, name
, p
);
4344 else if (desc
->mark
)
4346 /* If the constant is part of an object_block, make sure that
4347 the constant has been positioned within its block, but do not
4348 write out its definition yet. output_object_blocks will do
4350 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
4351 && SYMBOL_REF_BLOCK (desc
->sym
))
4352 place_block_symbol (desc
->sym
);
4355 switch_to_section (targetm
.asm_out
.select_rtx_section
4356 (desc
->mode
, desc
->constant
, desc
->align
));
4357 output_constant_pool_1 (desc
, desc
->align
);
4362 struct constant_descriptor_rtx_data
{
4363 constant_descriptor_rtx
*desc
;
4365 unsigned short size
;
4366 unsigned short offset
;
4370 /* qsort callback to sort constant_descriptor_rtx_data * vector by
4374 constant_descriptor_rtx_data_cmp (const void *p1
, const void *p2
)
4376 constant_descriptor_rtx_data
*const data1
4377 = *(constant_descriptor_rtx_data
* const *) p1
;
4378 constant_descriptor_rtx_data
*const data2
4379 = *(constant_descriptor_rtx_data
* const *) p2
;
4380 if (data1
->size
> data2
->size
)
4382 if (data1
->size
< data2
->size
)
4384 if (data1
->hash
< data2
->hash
)
4386 gcc_assert (data1
->hash
> data2
->hash
);
4390 struct const_rtx_data_hasher
: nofree_ptr_hash
<constant_descriptor_rtx_data
>
4392 static hashval_t
hash (constant_descriptor_rtx_data
*);
4393 static bool equal (constant_descriptor_rtx_data
*,
4394 constant_descriptor_rtx_data
*);
4397 /* Hash and compare functions for const_rtx_data_htab. */
4400 const_rtx_data_hasher::hash (constant_descriptor_rtx_data
*data
)
4406 const_rtx_data_hasher::equal (constant_descriptor_rtx_data
*x
,
4407 constant_descriptor_rtx_data
*y
)
4409 if (x
->hash
!= y
->hash
|| x
->size
!= y
->size
)
4411 unsigned int align1
= x
->desc
->align
;
4412 unsigned int align2
= y
->desc
->align
;
4413 unsigned int offset1
= (x
->offset
* BITS_PER_UNIT
) & (align1
- 1);
4414 unsigned int offset2
= (y
->offset
* BITS_PER_UNIT
) & (align2
- 1);
4416 align1
= least_bit_hwi (offset1
);
4418 align2
= least_bit_hwi (offset2
);
4419 if (align2
> align1
)
4421 if (memcmp (x
->bytes
, y
->bytes
, x
->size
* sizeof (target_unit
)) != 0)
4426 /* Attempt to optimize constant pool POOL. If it contains both CONST_VECTOR
4427 constants and scalar constants with the values of CONST_VECTOR elements,
4428 try to alias the scalar constants with the CONST_VECTOR elements. */
4431 optimize_constant_pool (struct rtx_constant_pool
*pool
)
4433 auto_vec
<target_unit
, 128> buffer
;
4434 auto_vec
<constant_descriptor_rtx_data
*, 128> vec
;
4435 object_allocator
<constant_descriptor_rtx_data
>
4436 data_pool ("constant_descriptor_rtx_data_pool");
4439 for (constant_descriptor_rtx
*desc
= pool
->first
; desc
; desc
= desc
->next
)
4441 && ! (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
4442 && SYMBOL_REF_BLOCK (desc
->sym
)))
4444 buffer
.truncate (0);
4445 buffer
.reserve (GET_MODE_SIZE (desc
->mode
));
4446 if (native_encode_rtx (desc
->mode
, desc
->constant
, buffer
, 0,
4447 GET_MODE_SIZE (desc
->mode
)))
4449 constant_descriptor_rtx_data
*data
= data_pool
.allocate ();
4452 data
->size
= GET_MODE_SIZE (desc
->mode
);
4456 vec
.safe_push (data
);
4461 vec
.qsort (constant_descriptor_rtx_data_cmp
);
4462 unsigned min_size
= vec
.last ()->size
;
4463 target_unit
*bytes
= XNEWVEC (target_unit
, size
);
4465 constant_descriptor_rtx_data
*data
;
4466 hash_table
<const_rtx_data_hasher
> * htab
4467 = new hash_table
<const_rtx_data_hasher
> (31);
4469 FOR_EACH_VEC_ELT (vec
, i
, data
)
4471 buffer
.truncate (0);
4472 native_encode_rtx (data
->desc
->mode
, data
->desc
->constant
,
4473 buffer
, 0, data
->size
);
4474 memcpy (bytes
+ size
, buffer
.address (), data
->size
);
4475 data
->bytes
= bytes
+ size
;
4476 data
->hash
= iterative_hash (data
->bytes
,
4477 data
->size
* sizeof (target_unit
), 0);
4479 constant_descriptor_rtx_data
**slot
4480 = htab
->find_slot_with_hash (data
, data
->hash
, INSERT
);
4483 data
->desc
->mark
= ~(*slot
)->desc
->labelno
;
4484 data
->desc
->offset
= (*slot
)->offset
;
4488 unsigned int sz
= 1 << floor_log2 (data
->size
);
4491 for (sz
>>= 1; sz
>= min_size
; sz
>>= 1)
4492 for (unsigned off
= 0; off
+ sz
<= data
->size
; off
+= sz
)
4494 constant_descriptor_rtx_data tmp
;
4495 tmp
.desc
= data
->desc
;
4496 tmp
.bytes
= data
->bytes
+ off
;
4499 tmp
.hash
= iterative_hash (tmp
.bytes
,
4500 sz
* sizeof (target_unit
), 0);
4501 slot
= htab
->find_slot_with_hash (&tmp
, tmp
.hash
, INSERT
);
4504 *slot
= data_pool
.allocate ();
4513 data_pool
.release ();
4516 /* Mark all constants that are used in the current function, then write
4517 out the function's private constant pool. */
4520 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
4521 tree fndecl ATTRIBUTE_UNUSED
)
4523 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
4525 /* It is possible for gcc to call force_const_mem and then to later
4526 discard the instructions which refer to the constant. In such a
4527 case we do not need to output the constant. */
4528 mark_constant_pool ();
4530 /* Having marked the constant pool entries we'll actually emit, we
4531 now need to rebuild the offset information, which may have become
4533 recompute_pool_offsets (pool
);
4535 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4536 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4539 output_constant_pool_contents (pool
);
4541 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4542 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4546 /* Write the contents of the shared constant pool. */
4549 output_shared_constant_pool (void)
4552 && TARGET_SUPPORTS_ALIASES
)
4553 optimize_constant_pool (shared_constant_pool
);
4555 output_constant_pool_contents (shared_constant_pool
);
4558 /* Determine what kind of relocations EXP may need. */
4561 compute_reloc_for_constant (tree exp
)
4563 int reloc
= 0, reloc2
;
4566 switch (TREE_CODE (exp
))
4570 /* Go inside any operations that get_inner_reference can handle and see
4571 if what's inside is a constant: no need to do anything here for
4572 addresses of variables or functions. */
4573 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4574 tem
= TREE_OPERAND (tem
, 0))
4577 if (TREE_CODE (tem
) == MEM_REF
4578 && TREE_CODE (TREE_OPERAND (tem
, 0)) == ADDR_EXPR
)
4580 reloc
= compute_reloc_for_constant (TREE_OPERAND (tem
, 0));
4584 if (!targetm
.binds_local_p (tem
))
4591 case POINTER_PLUS_EXPR
:
4592 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4593 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4597 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4598 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4599 /* The difference of two local labels is computable at link time. */
4600 if (reloc
== 1 && reloc2
== 1)
4607 case VIEW_CONVERT_EXPR
:
4608 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4613 unsigned HOST_WIDE_INT idx
;
4614 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4616 reloc
|= compute_reloc_for_constant (tem
);
4626 /* Find all the constants whose addresses are referenced inside of EXP,
4627 and make sure assembler code with a label has been output for each one.
4628 Indicate whether an ADDR_EXPR has been encountered. */
4631 output_addressed_constants (tree exp
, int defer
)
4635 switch (TREE_CODE (exp
))
4639 /* Go inside any operations that get_inner_reference can handle and see
4640 if what's inside is a constant: no need to do anything here for
4641 addresses of variables or functions. */
4642 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4643 tem
= TREE_OPERAND (tem
, 0))
4646 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4647 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4648 tem
= DECL_INITIAL (tem
);
4650 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4651 output_constant_def (tem
, defer
);
4653 if (TREE_CODE (tem
) == MEM_REF
)
4654 output_addressed_constants (TREE_OPERAND (tem
, 0), defer
);
4658 case POINTER_PLUS_EXPR
:
4660 output_addressed_constants (TREE_OPERAND (exp
, 1), defer
);
4664 case VIEW_CONVERT_EXPR
:
4665 output_addressed_constants (TREE_OPERAND (exp
, 0), defer
);
4670 unsigned HOST_WIDE_INT idx
;
4671 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4673 output_addressed_constants (tem
, defer
);
4682 /* Whether a constructor CTOR is a valid static constant initializer if all
4683 its elements are. This used to be internal to initializer_constant_valid_p
4684 and has been exposed to let other functions like categorize_ctor_elements
4685 evaluate the property while walking a constructor for other purposes. */
4688 constructor_static_from_elts_p (const_tree ctor
)
4690 return (TREE_CONSTANT (ctor
)
4691 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4692 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
4693 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
4696 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4699 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4700 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4701 which are valid when ENDTYPE is an integer of any size; in
4702 particular, this does not accept a pointer minus a constant. This
4703 returns null_pointer_node if the VALUE is an absolute constant
4704 which can be used to initialize a static variable. Otherwise it
4708 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4712 if (!INTEGRAL_TYPE_P (endtype
))
4715 op0
= TREE_OPERAND (value
, 0);
4716 op1
= TREE_OPERAND (value
, 1);
4718 /* Like STRIP_NOPS except allow the operand mode to widen. This
4719 works around a feature of fold that simplifies (int)(p1 - p2) to
4720 ((int)p1 - (int)p2) under the theory that the narrower operation
4723 while (CONVERT_EXPR_P (op0
)
4724 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4726 tree inner
= TREE_OPERAND (op0
, 0);
4727 if (inner
== error_mark_node
4728 || ! INTEGRAL_TYPE_P (TREE_TYPE (op0
))
4729 || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op0
)))
4730 || ! INTEGRAL_TYPE_P (TREE_TYPE (inner
))
4731 || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4732 || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op0
)))
4733 > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner
)))))
4738 while (CONVERT_EXPR_P (op1
)
4739 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4741 tree inner
= TREE_OPERAND (op1
, 0);
4742 if (inner
== error_mark_node
4743 || ! INTEGRAL_TYPE_P (TREE_TYPE (op1
))
4744 || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op1
)))
4745 || ! INTEGRAL_TYPE_P (TREE_TYPE (inner
))
4746 || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4747 || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op1
)))
4748 > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner
)))))
4753 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4757 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4758 cache
? cache
+ 2 : NULL
);
4759 /* Both initializers must be known. */
4763 && (op0
== null_pointer_node
4764 || TREE_CODE (value
) == MINUS_EXPR
))
4765 return null_pointer_node
;
4767 /* Support differences between labels. */
4768 if (TREE_CODE (op0
) == LABEL_DECL
4769 && TREE_CODE (op1
) == LABEL_DECL
)
4770 return null_pointer_node
;
4772 if (TREE_CODE (op0
) == STRING_CST
4773 && TREE_CODE (op1
) == STRING_CST
4774 && operand_equal_p (op0
, op1
, 1))
4775 return null_pointer_node
;
4781 /* Helper function of initializer_constant_valid_p.
4782 Return nonzero if VALUE is a valid constant-valued expression
4783 for use in initializing a static variable; one that can be an
4784 element of a "constant" initializer.
4786 Return null_pointer_node if the value is absolute;
4787 if it is relocatable, return the variable that determines the relocation.
4788 We assume that VALUE has been folded as much as possible;
4789 therefore, we do not need to check for such things as
4790 arithmetic-combinations of integers.
4792 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4795 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4799 switch (TREE_CODE (value
))
4802 if (constructor_static_from_elts_p (value
))
4804 unsigned HOST_WIDE_INT idx
;
4806 bool absolute
= true;
4808 if (cache
&& cache
[0] == value
)
4810 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4813 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4816 /* An absolute value is required with reverse SSO. */
4817 || (reloc
!= null_pointer_node
4818 && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (value
))
4819 && !AGGREGATE_TYPE_P (TREE_TYPE (elt
))))
4824 cache
[1] = NULL_TREE
;
4828 if (reloc
!= null_pointer_node
)
4831 /* For a non-absolute relocation, there is no single
4832 variable that can be "the variable that determines the
4837 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4839 return absolute
? null_pointer_node
: error_mark_node
;
4842 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4850 return null_pointer_node
;
4855 tree op0
= staticp (TREE_OPERAND (value
, 0));
4858 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4859 to be a constant, this is old-skool offsetof-like nonsense. */
4860 if (TREE_CODE (op0
) == INDIRECT_REF
4861 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4862 return null_pointer_node
;
4863 /* Taking the address of a nested function involves a trampoline,
4864 unless we don't need or want one. */
4865 if (TREE_CODE (op0
) == FUNCTION_DECL
4866 && DECL_STATIC_CHAIN (op0
)
4867 && !TREE_NO_TRAMPOLINE (value
))
4869 /* "&{...}" requires a temporary to hold the constructed
4871 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4877 case NON_LVALUE_EXPR
:
4878 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4881 case VIEW_CONVERT_EXPR
:
4883 tree src
= TREE_OPERAND (value
, 0);
4884 tree src_type
= TREE_TYPE (src
);
4885 tree dest_type
= TREE_TYPE (value
);
4887 /* Allow view-conversions from aggregate to non-aggregate type only
4888 if the bit pattern is fully preserved afterwards; otherwise, the
4889 RTL expander won't be able to apply a subsequent transformation
4890 to the underlying constructor. */
4891 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4893 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4894 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4899 /* Allow all other kinds of view-conversion. */
4900 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4905 tree src
= TREE_OPERAND (value
, 0);
4906 tree src_type
= TREE_TYPE (src
);
4907 tree dest_type
= TREE_TYPE (value
);
4909 /* Allow conversions between pointer types and offset types. */
4910 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4911 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4912 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4913 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4915 /* Allow length-preserving conversions between integer types and
4916 floating-point types. */
4917 if (((INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4918 || (SCALAR_FLOAT_TYPE_P (dest_type
)
4919 && SCALAR_FLOAT_TYPE_P (src_type
)))
4920 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4921 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4923 /* Allow conversions between other integer types only if
4924 explicit value. Don't allow sign-extension to a type larger
4925 than word and pointer, there aren't relocations that would
4926 allow to sign extend it to a wider type. */
4927 if (INTEGRAL_TYPE_P (dest_type
)
4928 && INTEGRAL_TYPE_P (src_type
)
4929 && (TYPE_UNSIGNED (src_type
)
4930 || TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
)
4931 || TYPE_PRECISION (dest_type
) <= BITS_PER_WORD
4932 || TYPE_PRECISION (dest_type
) <= POINTER_SIZE
))
4934 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4935 if (inner
== null_pointer_node
)
4936 return null_pointer_node
;
4940 /* Allow (int) &foo provided int is as wide as a pointer. */
4941 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4942 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4943 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4945 /* Likewise conversions from int to pointers, but also allow
4946 conversions from 0. */
4947 if ((POINTER_TYPE_P (dest_type
)
4948 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4949 && INTEGRAL_TYPE_P (src_type
))
4951 if (TREE_CODE (src
) == INTEGER_CST
4952 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4953 return null_pointer_node
;
4954 if (integer_zerop (src
))
4955 return null_pointer_node
;
4956 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4957 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4960 /* Allow conversions to struct or union types if the value
4962 if (TREE_CODE (dest_type
) == RECORD_TYPE
4963 || TREE_CODE (dest_type
) == UNION_TYPE
)
4964 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4968 case POINTER_PLUS_EXPR
:
4970 /* Any valid floating-point constants will have been folded by now;
4971 with -frounding-math we hit this with addition of two constants. */
4972 if (TREE_CODE (endtype
) == REAL_TYPE
)
4974 if (cache
&& cache
[0] == value
)
4976 if (! INTEGRAL_TYPE_P (endtype
)
4977 || ! INTEGRAL_TYPE_P (TREE_TYPE (value
))
4978 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4980 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4982 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4985 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4986 endtype
, ncache
+ 2);
4987 /* If either term is absolute, use the other term's relocation. */
4988 if (valid0
== null_pointer_node
)
4990 else if (valid1
== null_pointer_node
)
4992 /* Support narrowing pointer differences. */
4994 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4998 /* Support narrowing pointer differences. */
4999 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
5007 case POINTER_DIFF_EXPR
:
5009 if (TREE_CODE (endtype
) == REAL_TYPE
)
5011 if (cache
&& cache
[0] == value
)
5013 if (! INTEGRAL_TYPE_P (endtype
)
5014 || ! INTEGRAL_TYPE_P (TREE_TYPE (value
))
5015 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
5017 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
5019 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
5022 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
5023 endtype
, ncache
+ 2);
5024 /* Win if second argument is absolute. */
5025 if (valid1
== null_pointer_node
)
5027 /* Win if both arguments have the same relocation.
5028 Then the value is absolute. */
5029 else if (valid0
== valid1
&& valid0
!= 0)
5030 ret
= null_pointer_node
;
5031 /* Since GCC guarantees that string constants are unique in the
5032 generated code, a subtraction between two copies of the same
5033 constant string is absolute. */
5034 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
5035 && valid1
&& TREE_CODE (valid1
) == STRING_CST
5036 && operand_equal_p (valid0
, valid1
, 1))
5037 ret
= null_pointer_node
;
5038 /* Support narrowing differences. */
5040 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
5044 /* Support narrowing differences. */
5045 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
5060 /* Return nonzero if VALUE is a valid constant-valued expression
5061 for use in initializing a static variable; one that can be an
5062 element of a "constant" initializer.
5064 Return null_pointer_node if the value is absolute;
5065 if it is relocatable, return the variable that determines the relocation.
5066 We assume that VALUE has been folded as much as possible;
5067 therefore, we do not need to check for such things as
5068 arithmetic-combinations of integers. */
5070 initializer_constant_valid_p (tree value
, tree endtype
, bool reverse
)
5072 tree reloc
= initializer_constant_valid_p_1 (value
, endtype
, NULL
);
5074 /* An absolute value is required with reverse storage order. */
5076 && reloc
!= null_pointer_node
5078 && !AGGREGATE_TYPE_P (endtype
)
5079 && !VECTOR_TYPE_P (endtype
))
5085 /* Return true if VALUE is a valid constant-valued expression
5086 for use in initializing a static bit-field; one that can be
5087 an element of a "constant" initializer. */
5090 initializer_constant_valid_for_bitfield_p (const_tree value
)
5092 /* For bitfields we support integer constants or possibly nested aggregates
5094 switch (TREE_CODE (value
))
5098 unsigned HOST_WIDE_INT idx
;
5101 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
5102 if (!initializer_constant_valid_for_bitfield_p (elt
))
5111 case VIEW_CONVERT_EXPR
:
5112 case NON_LVALUE_EXPR
:
5114 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
5123 /* Check if a STRING_CST fits into the field.
5124 Tolerate only the case when the NUL termination
5125 does not fit into the field. */
5128 check_string_literal (tree string
, unsigned HOST_WIDE_INT size
)
5130 tree type
= TREE_TYPE (string
);
5131 tree eltype
= TREE_TYPE (type
);
5132 unsigned HOST_WIDE_INT elts
= tree_to_uhwi (TYPE_SIZE_UNIT (eltype
));
5133 unsigned HOST_WIDE_INT mem_size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
5134 int len
= TREE_STRING_LENGTH (string
);
5136 if (elts
!= 1 && elts
!= 2 && elts
!= 4)
5138 if (len
< 0 || len
% elts
!= 0)
5140 if (size
< (unsigned)len
)
5142 if (mem_size
!= size
)
5147 /* output_constructor outer state of relevance in recursive calls, typically
5148 for nested aggregate bitfields. */
5150 struct oc_outer_state
{
5151 unsigned int bit_offset
; /* current position in ... */
5152 int byte
; /* ... the outer byte buffer. */
5155 static unsigned HOST_WIDE_INT
5156 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int, bool,
5159 /* Output assembler code for constant EXP, with no label.
5160 This includes the pseudo-op such as ".int" or ".byte", and a newline.
5161 Assumes output_addressed_constants has been done on EXP already.
5163 Generate at least SIZE bytes of assembler data, padding at the end
5164 with zeros if necessary. SIZE must always be specified. The returned
5165 value is the actual number of bytes of assembler data generated, which
5166 may be bigger than SIZE if the object contains a variable length field.
5168 SIZE is important for structure constructors,
5169 since trailing members may have been omitted from the constructor.
5170 It is also important for initialization of arrays from string constants
5171 since the full length of the string constant might not be wanted.
5172 It is also needed for initialization of unions, where the initializer's
5173 type is just one member, and that may not be as long as the union.
5175 There a case in which we would fail to output exactly SIZE bytes:
5176 for a structure constructor that wants to produce more than SIZE bytes.
5177 But such constructors will never be generated for any possible input.
5179 ALIGN is the alignment of the data in bits.
5181 If REVERSE is true, EXP is output in reverse storage order. */
5183 static unsigned HOST_WIDE_INT
5184 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
,
5185 bool reverse
, bool merge_strings
)
5187 enum tree_code code
;
5188 unsigned HOST_WIDE_INT thissize
;
5191 if (size
== 0 || flag_syntax_only
)
5194 /* See if we're trying to initialize a pointer in a non-default mode
5195 to the address of some declaration somewhere. If the target says
5196 the mode is valid for pointers, assume the target has a way of
5198 if (TREE_CODE (exp
) == NOP_EXPR
5199 && POINTER_TYPE_P (TREE_TYPE (exp
))
5200 && targetm
.addr_space
.valid_pointer_mode
5201 (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp
)),
5202 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
5204 tree saved_type
= TREE_TYPE (exp
);
5206 /* Peel off any intermediate conversions-to-pointer for valid
5208 while (TREE_CODE (exp
) == NOP_EXPR
5209 && POINTER_TYPE_P (TREE_TYPE (exp
))
5210 && targetm
.addr_space
.valid_pointer_mode
5211 (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp
)),
5212 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
5213 exp
= TREE_OPERAND (exp
, 0);
5215 /* If what we're left with is the address of something, we can
5216 convert the address to the final type and output it that
5218 if (TREE_CODE (exp
) == ADDR_EXPR
)
5219 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
5220 /* Likewise for constant ints. */
5221 else if (TREE_CODE (exp
) == INTEGER_CST
)
5222 exp
= fold_convert (saved_type
, exp
);
5226 /* Eliminate any conversions since we'll be outputting the underlying
5228 while (CONVERT_EXPR_P (exp
)
5229 || TREE_CODE (exp
) == NON_LVALUE_EXPR
5230 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
5232 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
5233 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
5235 /* Make sure eliminating the conversion is really a no-op, except with
5236 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
5237 union types to allow for Ada unchecked unions. */
5238 if (type_size
> op_size
5239 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
5240 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
5241 /* Keep the conversion. */
5244 exp
= TREE_OPERAND (exp
, 0);
5247 code
= TREE_CODE (TREE_TYPE (exp
));
5248 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
5250 /* Allow a constructor with no elements for any data type.
5251 This means to fill the space with zeros. */
5252 if (TREE_CODE (exp
) == CONSTRUCTOR
5253 && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp
)))
5255 assemble_zeros (size
);
5259 if (TREE_CODE (exp
) == FDESC_EXPR
)
5261 #ifdef ASM_OUTPUT_FDESC
5262 HOST_WIDE_INT part
= tree_to_shwi (TREE_OPERAND (exp
, 1));
5263 tree decl
= TREE_OPERAND (exp
, 0);
5264 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
5271 /* Now output the underlying data. If we've handling the padding, return.
5272 Otherwise, break and ensure SIZE is the size written. */
5279 case REFERENCE_TYPE
:
5281 case FIXED_POINT_TYPE
:
5283 cst
= expand_expr (exp
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
5285 cst
= flip_storage_order (TYPE_MODE (TREE_TYPE (exp
)), cst
);
5286 if (!assemble_integer (cst
, MIN (size
, thissize
), align
, 0))
5287 error ("initializer for integer/fixed-point value is too complicated");
5291 gcc_assert (size
== thissize
);
5292 if (TREE_CODE (exp
) != REAL_CST
)
5293 error ("initializer for floating value is not a floating constant");
5295 assemble_real (TREE_REAL_CST (exp
),
5296 SCALAR_FLOAT_TYPE_MODE (TREE_TYPE (exp
)),
5301 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
,
5303 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
5304 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)),
5309 if (TREE_CODE (exp
) != INTEGER_CST
)
5310 error ("initializer for %<_BitInt(%d)%> value is not an integer "
5311 "constant", TYPE_PRECISION (TREE_TYPE (exp
)));
5314 struct bitint_info info
;
5315 tree type
= TREE_TYPE (exp
);
5316 bool ok
= targetm
.c
.bitint_type_info (TYPE_PRECISION (type
), &info
);
5318 scalar_int_mode limb_mode
5319 = as_a
<scalar_int_mode
> (info
.abi_limb_mode
);
5320 if (TYPE_PRECISION (type
) <= GET_MODE_PRECISION (limb_mode
))
5322 cst
= expand_expr (exp
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
5324 cst
= flip_storage_order (TYPE_MODE (TREE_TYPE (exp
)), cst
);
5325 if (!assemble_integer (cst
, MIN (size
, thissize
), align
, 0))
5326 error ("initializer for integer/fixed-point value is too "
5330 int prec
= GET_MODE_PRECISION (limb_mode
);
5331 int cnt
= CEIL (TYPE_PRECISION (type
), prec
);
5332 tree limb_type
= build_nonstandard_integer_type (prec
, 1);
5333 int elt_size
= GET_MODE_SIZE (limb_mode
);
5334 unsigned int nalign
= MIN (align
, GET_MODE_ALIGNMENT (limb_mode
));
5336 if (prec
== HOST_BITS_PER_WIDE_INT
)
5337 for (int i
= 0; i
< cnt
; i
++)
5339 int idx
= (info
.big_endian
^ reverse
) ? cnt
- 1 - i
: i
;
5341 if (idx
>= TREE_INT_CST_EXT_NUNITS (exp
))
5342 c
= build_int_cst (limb_type
,
5343 tree_int_cst_sgn (exp
) < 0 ? -1 : 0);
5345 c
= build_int_cst (limb_type
,
5346 TREE_INT_CST_ELT (exp
, idx
));
5347 output_constant (c
, elt_size
, nalign
, reverse
, false);
5348 thissize
+= elt_size
;
5351 for (int i
= 0; i
< cnt
; i
++)
5353 int idx
= (info
.big_endian
^ reverse
) ? cnt
- 1 - i
: i
;
5354 wide_int w
= wi::rshift (wi::to_wide (exp
), idx
* prec
,
5355 TYPE_SIGN (TREE_TYPE (exp
)));
5356 tree c
= wide_int_to_tree (limb_type
,
5357 wide_int::from (w
, prec
, UNSIGNED
));
5358 output_constant (c
, elt_size
, nalign
, reverse
, false);
5359 thissize
+= elt_size
;
5366 switch (TREE_CODE (exp
))
5369 return output_constructor (exp
, size
, align
, reverse
, NULL
);
5371 thissize
= (unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
);
5374 || TREE_STRING_POINTER (exp
) [thissize
- 1] != '\0'))
5376 gcc_checking_assert (check_string_literal (exp
, size
));
5377 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
5381 scalar_mode inner
= SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
5382 unsigned int nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
5383 int elt_size
= GET_MODE_SIZE (inner
);
5384 output_constant (VECTOR_CST_ELT (exp
, 0), elt_size
, align
,
5386 thissize
= elt_size
;
5387 /* Static constants must have a fixed size. */
5388 unsigned int nunits
= VECTOR_CST_NELTS (exp
).to_constant ();
5389 for (unsigned int i
= 1; i
< nunits
; i
++)
5391 output_constant (VECTOR_CST_ELT (exp
, i
), elt_size
, nalign
,
5393 thissize
+= elt_size
;
5404 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
5405 return output_constructor (exp
, size
, align
, reverse
, NULL
);
5414 if (size
> thissize
)
5415 assemble_zeros (size
- thissize
);
5420 /* Subroutine of output_constructor, used for computing the size of
5421 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
5422 type with an unspecified upper bound. */
5424 static unsigned HOST_WIDE_INT
5425 array_size_for_constructor (tree val
)
5428 unsigned HOST_WIDE_INT cnt
;
5429 tree index
, value
, tmp
;
5432 /* This code used to attempt to handle string constants that are not
5433 arrays of single-bytes, but nothing else does, so there's no point in
5435 if (TREE_CODE (val
) == STRING_CST
)
5436 return TREE_STRING_LENGTH (val
);
5438 max_index
= NULL_TREE
;
5439 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
5441 if (TREE_CODE (index
) == RANGE_EXPR
)
5442 index
= TREE_OPERAND (index
, 1);
5443 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
5447 if (max_index
== NULL_TREE
)
5450 /* Compute the total number of array elements. */
5451 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
5452 i
= wi::to_offset (max_index
) - wi::to_offset (tmp
) + 1;
5454 /* Multiply by the array element unit size to find number of bytes. */
5455 i
*= wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
5457 gcc_assert (wi::fits_uhwi_p (i
));
5458 return i
.to_uhwi ();
5461 /* Other datastructures + helpers for output_constructor. */
5463 /* output_constructor local state to support interaction with helpers. */
5465 struct oc_local_state
{
5467 /* Received arguments. */
5468 tree exp
; /* Constructor expression. */
5469 tree type
; /* Type of constructor expression. */
5470 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
5471 unsigned int align
; /* Known initial alignment. */
5472 tree min_index
; /* Lower bound if specified for an array. */
5474 /* Output processing state. */
5475 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
5476 int byte
; /* Part of a bitfield byte yet to be output. */
5477 int last_relative_index
; /* Implicit or explicit index of the last
5478 array element output within a bitfield. */
5479 bool byte_buffer_in_use
; /* Whether BYTE is in use. */
5480 bool reverse
; /* Whether reverse storage order is in use. */
5482 /* Current element. */
5483 tree field
; /* Current field decl in a record. */
5484 tree val
; /* Current element value. */
5485 tree index
; /* Current element index. */
5489 /* Helper for output_constructor. From the current LOCAL state, output a
5490 RANGE_EXPR element. */
5493 output_constructor_array_range (oc_local_state
*local
)
5495 /* Perform the index calculation in modulo arithmetic but
5496 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5497 but we are using an unsigned sizetype. */
5498 unsigned prec
= TYPE_PRECISION (sizetype
);
5499 offset_int idx
= wi::sext (wi::to_offset (TREE_OPERAND (local
->index
, 0))
5500 - wi::to_offset (local
->min_index
), prec
);
5501 tree valtype
= TREE_TYPE (local
->val
);
5502 HOST_WIDE_INT fieldpos
5503 = (idx
* wi::to_offset (TYPE_SIZE_UNIT (valtype
))).to_short_addr ();
5505 /* Advance to offset of this element. */
5506 if (fieldpos
> local
->total_bytes
)
5508 assemble_zeros (fieldpos
- local
->total_bytes
);
5509 local
->total_bytes
= fieldpos
;
5512 /* Must not go backwards. */
5513 gcc_assert (fieldpos
== local
->total_bytes
);
5515 unsigned HOST_WIDE_INT fieldsize
5516 = int_size_in_bytes (TREE_TYPE (local
->type
));
5518 HOST_WIDE_INT lo_index
5519 = tree_to_shwi (TREE_OPERAND (local
->index
, 0));
5520 HOST_WIDE_INT hi_index
5521 = tree_to_shwi (TREE_OPERAND (local
->index
, 1));
5522 HOST_WIDE_INT index
;
5525 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
5527 for (index
= lo_index
; index
<= hi_index
; index
++)
5529 /* Output the element's initial value. */
5530 if (local
->val
== NULL_TREE
)
5531 assemble_zeros (fieldsize
);
5533 fieldsize
= output_constant (local
->val
, fieldsize
, align2
,
5534 local
->reverse
, false);
5536 /* Count its size. */
5537 local
->total_bytes
+= fieldsize
;
5541 /* Helper for output_constructor. From the current LOCAL state, output a
5542 field element that is not true bitfield or part of an outer one. */
5545 output_constructor_regular_field (oc_local_state
*local
)
5547 /* Field size and position. Since this structure is static, we know the
5548 positions are constant. */
5549 unsigned HOST_WIDE_INT fieldsize
;
5550 HOST_WIDE_INT fieldpos
;
5552 unsigned int align2
;
5554 /* Output any buffered-up bit-fields preceding this element. */
5555 if (local
->byte_buffer_in_use
)
5557 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5558 local
->total_bytes
++;
5559 local
->byte_buffer_in_use
= false;
5562 if (local
->index
!= NULL_TREE
)
5564 /* Perform the index calculation in modulo arithmetic but
5565 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5566 but we are using an unsigned sizetype. */
5567 unsigned prec
= TYPE_PRECISION (sizetype
);
5568 offset_int idx
= wi::sext (wi::to_offset (local
->index
)
5569 - wi::to_offset (local
->min_index
), prec
);
5570 fieldpos
= (idx
* wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
))))
5573 else if (local
->field
!= NULL_TREE
)
5574 fieldpos
= int_byte_position (local
->field
);
5578 /* Advance to offset of this element.
5579 Note no alignment needed in an array, since that is guaranteed
5580 if each element has the proper size. */
5581 if (local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
5583 if (fieldpos
> local
->total_bytes
)
5585 assemble_zeros (fieldpos
- local
->total_bytes
);
5586 local
->total_bytes
= fieldpos
;
5589 /* Must not go backwards. */
5590 gcc_assert (fieldpos
== local
->total_bytes
);
5593 /* Find the alignment of this element. */
5594 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
5596 /* Determine size this element should occupy. */
5601 /* If this is an array with an unspecified upper bound,
5602 the initializer determines the size. */
5603 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5604 but we cannot do this until the deprecated support for
5605 initializing zero-length array members is removed. */
5606 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
5607 && (!TYPE_DOMAIN (TREE_TYPE (local
->field
))
5608 || !TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
)))))
5610 unsigned HOST_WIDE_INT fldsize
5611 = array_size_for_constructor (local
->val
);
5612 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->val
));
5613 /* In most cases fieldsize == fldsize as the size of the initializer
5614 determines how many elements the flexible array member has. For
5615 C++ fldsize can be smaller though, if the last or several last or
5616 all initializers of the flexible array member have side-effects
5617 and the FE splits them into dynamic initialization. */
5618 gcc_checking_assert (fieldsize
>= fldsize
);
5619 /* Given a non-empty initialization, this field had better
5620 be last. Given a flexible array member, the next field
5621 on the chain is a TYPE_DECL of the enclosing struct. */
5622 const_tree next
= DECL_CHAIN (local
->field
);
5623 gcc_assert (!fieldsize
|| !next
|| TREE_CODE (next
) != FIELD_DECL
);
5626 fieldsize
= tree_to_uhwi (DECL_SIZE_UNIT (local
->field
));
5629 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
5631 /* Output the element's initial value. */
5632 if (local
->val
== NULL_TREE
)
5633 assemble_zeros (fieldsize
);
5635 fieldsize
= output_constant (local
->val
, fieldsize
, align2
,
5636 local
->reverse
, false);
5638 /* Count its size. */
5639 local
->total_bytes
+= fieldsize
;
5642 /* Helper for output_constructor. From the LOCAL state, output an element
5643 that is a true bitfield or part of an outer one. BIT_OFFSET is the offset
5644 from the start of a possibly ongoing outer byte buffer. */
5647 output_constructor_bitfield (oc_local_state
*local
, unsigned int bit_offset
)
5649 /* Bit size of this element. */
5650 HOST_WIDE_INT ebitsize
5652 ? tree_to_uhwi (DECL_SIZE (local
->field
))
5653 : tree_to_uhwi (TYPE_SIZE (TREE_TYPE (local
->type
))));
5655 /* Relative index of this element if this is an array component. */
5656 HOST_WIDE_INT relative_index
5660 ? tree_to_uhwi (local
->index
) - tree_to_uhwi (local
->min_index
)
5661 : local
->last_relative_index
+ 1));
5663 /* Bit position of this element from the start of the containing
5665 HOST_WIDE_INT constructor_relative_ebitpos
5667 ? int_bit_position (local
->field
)
5668 : ebitsize
* relative_index
);
5670 /* Bit position of this element from the start of a possibly ongoing
5671 outer byte buffer. */
5672 HOST_WIDE_INT byte_relative_ebitpos
5673 = bit_offset
+ constructor_relative_ebitpos
;
5675 /* From the start of a possibly ongoing outer byte buffer, offsets to
5676 the first bit of this element and to the first bit past the end of
5678 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
5679 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
5681 local
->last_relative_index
= relative_index
;
5683 if (local
->val
== NULL_TREE
)
5684 local
->val
= integer_zero_node
;
5686 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
5687 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
5688 local
->val
= TREE_OPERAND (local
->val
, 0);
5690 if (TREE_CODE (local
->val
) != INTEGER_CST
5691 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
5693 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
5697 /* If this field does not start in this (or next) byte, skip some bytes. */
5698 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5700 /* Output remnant of any bit field in previous bytes. */
5701 if (local
->byte_buffer_in_use
)
5703 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5704 local
->total_bytes
++;
5705 local
->byte_buffer_in_use
= false;
5708 /* If still not at proper byte, advance to there. */
5709 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5711 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
5712 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
5713 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
5717 /* Set up the buffer if necessary. */
5718 if (!local
->byte_buffer_in_use
)
5722 local
->byte_buffer_in_use
= true;
5725 /* If this is nested constructor, recurse passing the bit offset and the
5726 pending data, then retrieve the new pending data afterwards. */
5727 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
5729 oc_outer_state temp_state
;
5730 temp_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
5731 temp_state
.byte
= local
->byte
;
5733 += output_constructor (local
->val
, 0, 0, local
->reverse
, &temp_state
);
5734 local
->byte
= temp_state
.byte
;
5738 /* Otherwise, we must split the element into pieces that fall within
5739 separate bytes, and combine each byte with previous or following
5741 while (next_offset
< end_offset
)
5745 unsigned HOST_WIDE_INT value
;
5746 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5747 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5749 /* Advance from byte to byte within this element when necessary. */
5750 while (next_byte
!= local
->total_bytes
)
5752 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5753 local
->total_bytes
++;
5757 /* Number of bits we can process at once (all part of the same byte). */
5758 this_time
= MIN (end_offset
- next_offset
, BITS_PER_UNIT
- next_bit
);
5759 if (local
->reverse
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
)
5761 /* For big-endian data, take the most significant bits (of the
5762 bits that are significant) first and put them into bytes from
5763 the most significant end. */
5764 shift
= end_offset
- next_offset
- this_time
;
5766 /* Don't try to take a bunch of bits that cross
5767 the word boundary in the INTEGER_CST. We can
5768 only select bits from one element. */
5769 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5770 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5772 const int end
= shift
+ this_time
- 1;
5773 shift
= end
& -HOST_BITS_PER_WIDE_INT
;
5774 this_time
= end
- shift
+ 1;
5777 /* Now get the bits we want to insert. */
5778 value
= wi::extract_uhwi (wi::to_widest (local
->val
),
5781 /* Get the result. This works only when:
5782 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5783 local
->byte
|= value
<< (BITS_PER_UNIT
- this_time
- next_bit
);
5787 /* On little-endian machines, take the least significant bits of
5788 the value first and pack them starting at the least significant
5789 bits of the bytes. */
5790 shift
= next_offset
- byte_relative_ebitpos
;
5792 /* Don't try to take a bunch of bits that cross
5793 the word boundary in the INTEGER_CST. We can
5794 only select bits from one element. */
5795 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5796 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5798 = HOST_BITS_PER_WIDE_INT
- (shift
& (HOST_BITS_PER_WIDE_INT
- 1));
5800 /* Now get the bits we want to insert. */
5801 value
= wi::extract_uhwi (wi::to_widest (local
->val
),
5804 /* Get the result. This works only when:
5805 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5806 local
->byte
|= value
<< next_bit
;
5809 next_offset
+= this_time
;
5810 local
->byte_buffer_in_use
= true;
5814 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5815 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5816 caller output state of relevance in recursive invocations. */
5818 static unsigned HOST_WIDE_INT
5819 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
,
5820 bool reverse
, oc_outer_state
*outer
)
5822 unsigned HOST_WIDE_INT cnt
;
5823 constructor_elt
*ce
;
5824 oc_local_state local
;
5826 /* Setup our local state to communicate with helpers. */
5828 local
.type
= TREE_TYPE (exp
);
5830 local
.align
= align
;
5831 if (TREE_CODE (local
.type
) == ARRAY_TYPE
&& TYPE_DOMAIN (local
.type
))
5832 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5834 local
.min_index
= integer_zero_node
;
5836 local
.total_bytes
= 0;
5837 local
.byte_buffer_in_use
= outer
!= NULL
;
5838 local
.byte
= outer
? outer
->byte
: 0;
5839 local
.last_relative_index
= -1;
5840 /* The storage order is specified for every aggregate type. */
5841 if (AGGREGATE_TYPE_P (local
.type
))
5842 local
.reverse
= TYPE_REVERSE_STORAGE_ORDER (local
.type
);
5844 local
.reverse
= reverse
;
5846 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5848 /* As CE goes through the elements of the constant, FIELD goes through the
5849 structure fields if the constant is a structure. If the constant is a
5850 union, we override this by getting the field from the TREE_LIST element.
5851 But the constant could also be an array. Then FIELD is zero.
5853 There is always a maximum of one element in the chain LINK for unions
5854 (even if the initializer in a source program incorrectly contains
5857 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5858 local
.field
= TYPE_FIELDS (local
.type
);
5860 local
.field
= NULL_TREE
;
5863 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), cnt
, &ce
);
5864 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
5866 local
.val
= ce
->value
;
5867 local
.index
= NULL_TREE
;
5869 /* The element in a union constructor specifies the proper field
5871 if (RECORD_OR_UNION_TYPE_P (local
.type
) && ce
->index
!= NULL_TREE
)
5872 local
.field
= ce
->index
;
5874 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5875 local
.index
= ce
->index
;
5877 if (local
.field
&& flag_verbose_asm
)
5878 fprintf (asm_out_file
, "%s %s:\n",
5880 DECL_NAME (local
.field
)
5881 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5884 /* Eliminate the marker that makes a cast not be an lvalue. */
5885 if (local
.val
!= NULL_TREE
)
5886 STRIP_NOPS (local
.val
);
5888 /* Output the current element, using the appropriate helper ... */
5890 /* For an array slice not part of an outer bitfield. */
5892 && local
.index
!= NULL_TREE
5893 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5894 output_constructor_array_range (&local
);
5896 /* For a field that is neither a true bitfield nor part of an outer one,
5897 known to be at least byte aligned and multiple-of-bytes long. */
5899 && (local
.field
== NULL_TREE
5900 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5901 output_constructor_regular_field (&local
);
5903 /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
5904 supported for scalar fields, so we may need to convert first. */
5907 if (TREE_CODE (local
.val
) == REAL_CST
)
5909 = fold_unary (VIEW_CONVERT_EXPR
,
5910 build_nonstandard_integer_type
5911 (TYPE_PRECISION (TREE_TYPE (local
.val
)), 0),
5913 output_constructor_bitfield (&local
, outer
? outer
->bit_offset
: 0);
5917 /* If we are not at toplevel, save the pending data for our caller.
5918 Otherwise output the pending data and padding zeros as needed. */
5920 outer
->byte
= local
.byte
;
5923 if (local
.byte_buffer_in_use
)
5925 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5926 local
.total_bytes
++;
5929 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5931 assemble_zeros (local
.size
- local
.total_bytes
);
5932 local
.total_bytes
= local
.size
;
5936 return local
.total_bytes
;
5939 /* Mark DECL as weak. */
5942 mark_weak (tree decl
)
5944 if (DECL_WEAK (decl
))
5947 struct symtab_node
*n
= symtab_node::get (decl
);
5948 if (n
&& n
->refuse_visibility_changes
)
5949 error ("%qD declared weak after being used", decl
);
5950 DECL_WEAK (decl
) = 1;
5952 if (DECL_RTL_SET_P (decl
)
5953 && MEM_P (DECL_RTL (decl
))
5954 && XEXP (DECL_RTL (decl
), 0)
5955 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5956 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5959 /* Merge weak status between NEWDECL and OLDDECL. */
5962 merge_weak (tree newdecl
, tree olddecl
)
5964 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5966 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5969 /* We put the NEWDECL on the weak_decls list at some point
5970 and OLDDECL as well. Keep just OLDDECL on the list. */
5971 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5972 if (TREE_VALUE (*pwd
) == newdecl
)
5974 *pwd
= TREE_CHAIN (*pwd
);
5981 if (DECL_WEAK (newdecl
))
5985 /* NEWDECL is weak, but OLDDECL is not. */
5987 /* If we already output the OLDDECL, we're in trouble; we can't
5988 go back and make it weak. This should never happen in
5989 unit-at-a-time compilation. */
5990 gcc_assert (!TREE_ASM_WRITTEN (olddecl
));
5992 /* If we've already generated rtl referencing OLDDECL, we may
5993 have done so in a way that will not function properly with
5994 a weak symbol. Again in unit-at-a-time this should be
5996 gcc_assert (!TREE_USED (olddecl
)
5997 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)));
5999 /* PR 49899: You cannot convert a static function into a weak, public function. */
6000 if (! TREE_PUBLIC (olddecl
) && TREE_PUBLIC (newdecl
))
6001 error ("weak declaration of %q+D being applied to a already "
6002 "existing, static definition", newdecl
);
6004 if (TARGET_SUPPORTS_WEAK
)
6006 /* We put the NEWDECL on the weak_decls list at some point.
6007 Replace it with the OLDDECL. */
6008 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
6009 if (TREE_VALUE (wd
) == newdecl
)
6011 TREE_VALUE (wd
) = olddecl
;
6014 /* We may not find the entry on the list. If NEWDECL is a
6015 weak alias, then we will have already called
6016 globalize_decl to remove the entry; in that case, we do
6017 not need to do anything. */
6020 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
6021 mark_weak (olddecl
);
6024 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
6025 weak. Just update NEWDECL to indicate that it's weak too. */
6026 mark_weak (newdecl
);
6029 /* Declare DECL to be a weak symbol. */
6032 declare_weak (tree decl
)
6034 /* With -fsyntax-only, TREE_ASM_WRITTEN might be set on certain function
6035 decls earlier than normally, but as with -fsyntax-only nothing is really
6036 emitted, there is no harm in marking it weak later. */
6037 gcc_assert (TREE_CODE (decl
) != FUNCTION_DECL
6038 || !TREE_ASM_WRITTEN (decl
)
6039 || flag_syntax_only
);
6040 if (! TREE_PUBLIC (decl
))
6042 error ("weak declaration of %q+D must be public", decl
);
6045 else if (!TARGET_SUPPORTS_WEAK
)
6046 warning (0, "weak declaration of %q+D not supported", decl
);
6049 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
6050 DECL_ATTRIBUTES (decl
)
6051 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
6055 weak_finish_1 (tree decl
)
6057 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
6058 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6061 if (! TREE_USED (decl
))
6064 #ifdef ASM_WEAKEN_DECL
6065 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
6067 #ifdef ASM_WEAKEN_LABEL
6068 ASM_WEAKEN_LABEL (asm_out_file
, name
);
6070 #ifdef ASM_OUTPUT_WEAK_ALIAS
6072 static bool warn_once
= 0;
6075 warning (0, "only weak aliases are supported in this configuration");
6085 /* Fiven an assembly name, find the decl it is associated with. */
6087 find_decl (tree target
)
6089 symtab_node
*node
= symtab_node::get_for_asmname (target
);
6095 /* This TREE_LIST contains weakref targets. */
6097 static GTY(()) tree weakref_targets
;
6099 /* Emit any pending weak declarations. */
6106 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
6108 tree alias_decl
= TREE_PURPOSE (t
);
6109 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
6111 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
))
6112 || TREE_SYMBOL_REFERENCED (target
))
6113 /* Remove alias_decl from the weak list, but leave entries for
6114 the target alone. */
6116 #ifndef ASM_OUTPUT_WEAKREF
6117 else if (! TREE_SYMBOL_REFERENCED (target
))
6119 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
6120 defined, otherwise we and weak_finish_1 would use
6121 different macros. */
6122 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
6123 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
6125 tree decl
= find_decl (target
);
6129 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
6130 TREE_CODE (alias_decl
), target
,
6131 TREE_TYPE (alias_decl
));
6133 DECL_EXTERNAL (decl
) = 1;
6134 TREE_PUBLIC (decl
) = 1;
6135 DECL_ARTIFICIAL (decl
) = 1;
6136 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
6137 TREE_USED (decl
) = 1;
6140 weak_finish_1 (decl
);
6149 /* Remove the alias and the target from the pending weak list
6150 so that we do not emit any .weak directives for the former,
6151 nor multiple .weak directives for the latter. */
6152 for (p
= &weak_decls
; (t2
= *p
) ; )
6154 if (TREE_VALUE (t2
) == alias_decl
6155 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
6156 *p
= TREE_CHAIN (t2
);
6158 p
= &TREE_CHAIN (t2
);
6161 /* Remove other weakrefs to the same target, to speed things up. */
6162 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
6164 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
6165 *p
= TREE_CHAIN (t2
);
6167 p
= &TREE_CHAIN (t2
);
6172 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
6174 tree decl
= TREE_VALUE (t
);
6176 weak_finish_1 (decl
);
6180 /* Emit the assembly bits to indicate that DECL is globally visible. */
6183 globalize_decl (tree decl
)
6186 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
6187 if (DECL_WEAK (decl
))
6189 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6192 #ifdef ASM_WEAKEN_DECL
6193 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
6195 ASM_WEAKEN_LABEL (asm_out_file
, name
);
6198 /* Remove this function from the pending weak list so that
6199 we do not emit multiple .weak directives for it. */
6200 for (p
= &weak_decls
; (t
= *p
) ; )
6202 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
6203 *p
= TREE_CHAIN (t
);
6205 p
= &TREE_CHAIN (t
);
6208 /* Remove weakrefs to the same target from the pending weakref
6209 list, for the same reason. */
6210 for (p
= &weakref_targets
; (t
= *p
) ; )
6212 if (DECL_ASSEMBLER_NAME (decl
)
6213 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
6214 *p
= TREE_CHAIN (t
);
6216 p
= &TREE_CHAIN (t
);
6223 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
6226 vec
<alias_pair
, va_gc
> *alias_pairs
;
6228 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
6229 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
6230 tree node is DECL to have the value of the tree node TARGET. */
6233 do_assemble_alias (tree decl
, tree target
)
6237 /* Emulated TLS had better not get this var. */
6238 gcc_assert (!(!targetm
.have_tls
6240 && DECL_THREAD_LOCAL_P (decl
)));
6242 if (TREE_ASM_WRITTEN (decl
))
6245 id
= DECL_ASSEMBLER_NAME (decl
);
6246 ultimate_transparent_alias_target (&id
);
6247 ultimate_transparent_alias_target (&target
);
6249 /* We must force creation of DECL_RTL for debug info generation, even though
6250 we don't use it here. */
6251 make_decl_rtl (decl
);
6253 TREE_ASM_WRITTEN (decl
) = 1;
6254 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
6255 TREE_ASM_WRITTEN (id
) = 1;
6257 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
6259 if (!TREE_SYMBOL_REFERENCED (target
))
6260 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
6262 #ifdef ASM_OUTPUT_WEAKREF
6263 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
6264 IDENTIFIER_POINTER (id
),
6265 IDENTIFIER_POINTER (target
));
6267 if (!TARGET_SUPPORTS_WEAK
)
6269 error_at (DECL_SOURCE_LOCATION (decl
),
6270 "%qs is not supported in this configuration", "weakref ");
6277 #ifdef ASM_OUTPUT_DEF
6278 tree orig_decl
= decl
;
6280 /* Make name accessible from other files, if appropriate. */
6282 if (TREE_PUBLIC (decl
) || TREE_PUBLIC (orig_decl
))
6284 globalize_decl (decl
);
6285 maybe_assemble_visibility (decl
);
6287 if (TREE_CODE (decl
) == FUNCTION_DECL
6288 && cgraph_node::get (decl
)->ifunc_resolver
)
6290 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
6291 if (targetm
.has_ifunc_p ())
6292 ASM_OUTPUT_TYPE_DIRECTIVE
6293 (asm_out_file
, IDENTIFIER_POINTER (id
),
6297 error_at (DECL_SOURCE_LOCATION (decl
),
6298 "%qs is not supported on this target", "ifunc");
6301 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
6302 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
6304 ASM_OUTPUT_DEF (asm_out_file
,
6305 IDENTIFIER_POINTER (id
),
6306 IDENTIFIER_POINTER (target
));
6308 /* If symbol aliases aren't actually supported... */
6309 if (!TARGET_SUPPORTS_ALIASES
)
6310 /* ..., 'ASM_OUTPUT_DEF{,_FROM_DECLS}' better have raised an error. */
6311 gcc_checking_assert (seen_error ());
6312 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
6317 name
= IDENTIFIER_POINTER (id
);
6318 # ifdef ASM_WEAKEN_DECL
6319 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
6321 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
6323 /* Remove this function from the pending weak list so that
6324 we do not emit multiple .weak directives for it. */
6325 for (p
= &weak_decls
; (t
= *p
) ; )
6326 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
))
6327 || id
== DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
6328 *p
= TREE_CHAIN (t
);
6330 p
= &TREE_CHAIN (t
);
6332 /* Remove weakrefs to the same target from the pending weakref
6333 list, for the same reason. */
6334 for (p
= &weakref_targets
; (t
= *p
) ; )
6336 if (id
== ultimate_transparent_alias_target (&TREE_VALUE (t
)))
6337 *p
= TREE_CHAIN (t
);
6339 p
= &TREE_CHAIN (t
);
6345 /* Output .symver directive. */
6348 do_assemble_symver (tree decl
, tree target
)
6350 tree id
= DECL_ASSEMBLER_NAME (decl
);
6351 ultimate_transparent_alias_target (&id
);
6352 ultimate_transparent_alias_target (&target
);
6353 #ifdef ASM_OUTPUT_SYMVER_DIRECTIVE
6354 ASM_OUTPUT_SYMVER_DIRECTIVE (asm_out_file
,
6355 IDENTIFIER_POINTER (target
),
6356 IDENTIFIER_POINTER (id
));
6358 error ("symver is only supported on ELF platforms");
6362 /* Emit an assembler directive to make the symbol for DECL an alias to
6363 the symbol for TARGET. */
6366 assemble_alias (tree decl
, tree target
)
6370 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
6372 tree alias
= DECL_ASSEMBLER_NAME (decl
);
6374 ultimate_transparent_alias_target (&target
);
6376 if (alias
== target
)
6377 error ("%qs symbol %q+D ultimately targets itself", "weakref", decl
);
6378 if (TREE_PUBLIC (decl
))
6379 error ("%qs symbol %q+D must have static linkage", "weakref", decl
);
6381 else if (!TARGET_SUPPORTS_ALIASES
)
6383 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
6384 error_at (DECL_SOURCE_LOCATION (decl
),
6385 "alias definitions not supported in this configuration");
6386 TREE_ASM_WRITTEN (decl
) = 1;
6389 if (!DECL_WEAK (decl
))
6391 /* NB: ifunc_resolver isn't set when an error is detected. */
6392 if (TREE_CODE (decl
) == FUNCTION_DECL
6393 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
6394 error_at (DECL_SOURCE_LOCATION (decl
),
6395 "%qs is not supported in this configuration", "ifunc");
6397 error_at (DECL_SOURCE_LOCATION (decl
),
6398 "only weak aliases are supported in this configuration");
6399 TREE_ASM_WRITTEN (decl
) = 1;
6405 TREE_USED (decl
) = 1;
6407 /* Allow aliases to aliases. */
6408 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6409 cgraph_node::get_create (decl
)->alias
= true;
6411 varpool_node::get_create (decl
)->alias
= true;
6413 /* If the target has already been emitted, we don't have to queue the
6414 alias. This saves a tad of memory. */
6415 if (symtab
->global_info_ready
)
6416 target_decl
= find_decl (target
);
6419 if ((target_decl
&& TREE_ASM_WRITTEN (target_decl
))
6420 || symtab
->state
>= EXPANSION
)
6421 do_assemble_alias (decl
, target
);
6424 alias_pair p
= {decl
, target
};
6425 vec_safe_push (alias_pairs
, p
);
6429 /* Record and output a table of translations from original function
6430 to its transaction aware clone. Note that tm_pure functions are
6431 considered to be their own clone. */
6433 struct tm_clone_hasher
: ggc_cache_ptr_hash
<tree_map
>
6435 static hashval_t
hash (tree_map
*m
) { return tree_map_hash (m
); }
6436 static bool equal (tree_map
*a
, tree_map
*b
) { return tree_map_eq (a
, b
); }
6439 keep_cache_entry (tree_map
*&e
)
6441 return ggc_marked_p (e
->base
.from
);
6445 static GTY((cache
)) hash_table
<tm_clone_hasher
> *tm_clone_hash
;
6448 record_tm_clone_pair (tree o
, tree n
)
6450 struct tree_map
**slot
, *h
;
6452 if (tm_clone_hash
== NULL
)
6453 tm_clone_hash
= hash_table
<tm_clone_hasher
>::create_ggc (32);
6455 h
= ggc_alloc
<tree_map
> ();
6456 h
->hash
= htab_hash_pointer (o
);
6460 slot
= tm_clone_hash
->find_slot_with_hash (h
, h
->hash
, INSERT
);
6465 get_tm_clone_pair (tree o
)
6469 struct tree_map
*h
, in
;
6472 in
.hash
= htab_hash_pointer (o
);
6473 h
= tm_clone_hash
->find_with_hash (&in
, in
.hash
);
6480 struct tm_alias_pair
6488 /* Dump the actual pairs to the .tm_clone_table section. */
6491 dump_tm_clone_pairs (vec
<tm_alias_pair
> tm_alias_pairs
)
6495 bool switched
= false;
6497 FOR_EACH_VEC_ELT (tm_alias_pairs
, i
, p
)
6501 struct cgraph_node
*src_n
= cgraph_node::get (src
);
6502 struct cgraph_node
*dst_n
= cgraph_node::get (dst
);
6504 /* The function ipa_tm_create_version() marks the clone as needed if
6505 the original function was needed. But we also mark the clone as
6506 needed if we ever called the clone indirectly through
6507 TM_GETTMCLONE. If neither of these are true, we didn't generate
6508 a clone, and we didn't call it indirectly... no sense keeping it
6509 in the clone table. */
6510 if (!dst_n
|| !dst_n
->definition
)
6513 /* This covers the case where we have optimized the original
6514 function away, and only access the transactional clone. */
6515 if (!src_n
|| !src_n
->definition
)
6520 switch_to_section (targetm
.asm_out
.tm_clone_table_section ());
6521 assemble_align (POINTER_SIZE
);
6525 assemble_integer (XEXP (DECL_RTL (src
), 0),
6526 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
6527 assemble_integer (XEXP (DECL_RTL (dst
), 0),
6528 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
6532 /* Provide a default for the tm_clone_table section. */
6535 default_clone_table_section (void)
6537 return get_named_section (NULL
, ".tm_clone_table", 3);
6540 /* Helper comparison function for qsorting by the DECL_UID stored in
6541 alias_pair->emitted_diags. */
6544 tm_alias_pair_cmp (const void *x
, const void *y
)
6546 const tm_alias_pair
*p1
= (const tm_alias_pair
*) x
;
6547 const tm_alias_pair
*p2
= (const tm_alias_pair
*) y
;
6548 if (p1
->uid
< p2
->uid
)
6550 if (p1
->uid
> p2
->uid
)
6556 finish_tm_clone_pairs (void)
6558 vec
<tm_alias_pair
> tm_alias_pairs
= vNULL
;
6560 if (tm_clone_hash
== NULL
)
6563 /* We need a determenistic order for the .tm_clone_table, otherwise
6564 we will get bootstrap comparison failures, so dump the hash table
6565 to a vector, sort it, and dump the vector. */
6567 /* Dump the hashtable to a vector. */
6569 hash_table
<tm_clone_hasher
>::iterator iter
;
6570 FOR_EACH_HASH_TABLE_ELEMENT (*tm_clone_hash
, map
, tree_map
*, iter
)
6572 tm_alias_pair p
= {DECL_UID (map
->base
.from
), map
->base
.from
, map
->to
};
6573 tm_alias_pairs
.safe_push (p
);
6576 tm_alias_pairs
.qsort (tm_alias_pair_cmp
);
6579 dump_tm_clone_pairs (tm_alias_pairs
);
6581 tm_clone_hash
->empty ();
6582 tm_clone_hash
= NULL
;
6583 tm_alias_pairs
.release ();
6587 /* Emit an assembler directive to set symbol for DECL visibility to
6588 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
6591 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
6592 int vis ATTRIBUTE_UNUSED
)
6594 #ifdef HAVE_GAS_HIDDEN
6595 static const char * const visibility_types
[] = {
6596 NULL
, "protected", "hidden", "internal"
6599 const char *name
, *type
;
6602 id
= DECL_ASSEMBLER_NAME (decl
);
6603 ultimate_transparent_alias_target (&id
);
6604 name
= IDENTIFIER_POINTER (id
);
6606 type
= visibility_types
[vis
];
6608 fprintf (asm_out_file
, "\t.%s\t", type
);
6609 assemble_name (asm_out_file
, name
);
6610 fprintf (asm_out_file
, "\n");
6612 if (!DECL_ARTIFICIAL (decl
))
6613 warning (OPT_Wattributes
, "visibility attribute not supported "
6614 "in this configuration; ignored");
6618 /* A helper function to call assemble_visibility when needed for a decl. */
6621 maybe_assemble_visibility (tree decl
)
6623 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
6624 if (vis
!= VISIBILITY_DEFAULT
)
6626 targetm
.asm_out
.assemble_visibility (decl
, vis
);
6633 /* Returns true if the target configuration supports defining public symbols
6634 so that one of them will be chosen at link time instead of generating a
6635 multiply-defined symbol error, whether through the use of weak symbols or
6636 a target-specific mechanism for having duplicates discarded. */
6639 supports_one_only (void)
6641 if (SUPPORTS_ONE_ONLY
)
6643 if (TARGET_SUPPORTS_WEAK
)
6648 /* Set up DECL as a public symbol that can be defined in multiple
6649 translation units without generating a linker error. */
6652 make_decl_one_only (tree decl
, tree comdat_group
)
6654 struct symtab_node
*symbol
;
6655 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
6657 TREE_PUBLIC (decl
) = 1;
6660 symbol
= varpool_node::get_create (decl
);
6662 symbol
= cgraph_node::get_create (decl
);
6664 if (SUPPORTS_ONE_ONLY
)
6666 #ifdef MAKE_DECL_ONE_ONLY
6667 MAKE_DECL_ONE_ONLY (decl
);
6669 symbol
->set_comdat_group (comdat_group
);
6671 else if (VAR_P (decl
)
6672 && (DECL_INITIAL (decl
) == 0
6673 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
6674 DECL_COMMON (decl
) = 1;
6677 gcc_assert (TARGET_SUPPORTS_WEAK
);
6678 DECL_WEAK (decl
) = 1;
6683 init_varasm_once (void)
6685 section_htab
= hash_table
<section_hasher
>::create_ggc (31);
6686 object_block_htab
= hash_table
<object_block_hasher
>::create_ggc (31);
6687 const_desc_htab
= hash_table
<tree_descriptor_hasher
>::create_ggc (1009);
6689 shared_constant_pool
= create_constant_pool ();
6691 #ifdef TEXT_SECTION_ASM_OP
6692 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
6693 TEXT_SECTION_ASM_OP
);
6696 #ifdef DATA_SECTION_ASM_OP
6697 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6698 DATA_SECTION_ASM_OP
);
6701 #ifdef SDATA_SECTION_ASM_OP
6702 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6703 SDATA_SECTION_ASM_OP
);
6706 #ifdef READONLY_DATA_SECTION_ASM_OP
6707 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
6708 READONLY_DATA_SECTION_ASM_OP
);
6711 #ifdef CTORS_SECTION_ASM_OP
6712 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
6713 CTORS_SECTION_ASM_OP
);
6716 #ifdef DTORS_SECTION_ASM_OP
6717 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
6718 DTORS_SECTION_ASM_OP
);
6721 #ifdef BSS_SECTION_ASM_OP
6722 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6723 output_section_asm_op
,
6724 BSS_SECTION_ASM_OP
);
6727 #ifdef SBSS_SECTION_ASM_OP
6728 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6729 output_section_asm_op
,
6730 SBSS_SECTION_ASM_OP
);
6733 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6734 | SECTION_COMMON
, emit_tls_common
);
6735 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6736 | SECTION_COMMON
, emit_local
);
6737 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6738 | SECTION_COMMON
, emit_common
);
6740 #if defined ASM_OUTPUT_ALIGNED_BSS
6741 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
6745 targetm
.asm_out
.init_sections ();
6747 if (readonly_data_section
== NULL
)
6748 readonly_data_section
= text_section
;
6750 #ifdef ASM_OUTPUT_EXTERNAL
6751 pending_assemble_externals_set
= new hash_set
<tree
>;
6755 /* Determine whether SYMBOL is used in any optimized function. */
6758 have_optimized_refs (struct symtab_node
*symbol
)
6760 struct ipa_ref
*ref
;
6762 for (int i
= 0; symbol
->iterate_referring (i
, ref
); i
++)
6764 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (ref
->referring
);
6766 if (cnode
&& opt_for_fn (cnode
->decl
, optimize
))
6773 /* Check if promoting general-dynamic TLS access model to local-dynamic is
6774 desirable for DECL. */
6777 optimize_dyn_tls_for_decl_p (const_tree decl
)
6781 return symtab
->state
>= IPA
&& have_optimized_refs (symtab_node::get (decl
));
6786 decl_default_tls_model (const_tree decl
)
6788 enum tls_model kind
;
6791 is_local
= targetm
.binds_local_p (decl
);
6795 kind
= TLS_MODEL_LOCAL_EXEC
;
6797 kind
= TLS_MODEL_INITIAL_EXEC
;
6800 /* Local dynamic is inefficient when we're not combining the
6801 parts of the address. */
6802 else if (is_local
&& optimize_dyn_tls_for_decl_p (decl
))
6803 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6805 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6806 if (kind
< flag_tls_default
)
6807 kind
= flag_tls_default
;
6812 /* Select a set of attributes for section NAME based on the properties
6813 of DECL and whether or not RELOC indicates that DECL's initializer
6814 might contain runtime relocations.
6816 We make the section read-only and executable for a function decl,
6817 read-only for a const data decl, and writable for a non-const data decl. */
6820 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6824 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6825 flags
= SECTION_CODE
;
6828 enum section_category category
6829 = categorize_decl_for_section (decl
, reloc
);
6830 if (decl_readonly_section_1 (category
))
6832 else if (category
== SECCAT_DATA_REL_RO
6833 || category
== SECCAT_DATA_REL_RO_LOCAL
)
6834 flags
= SECTION_WRITE
| SECTION_RELRO
;
6836 flags
= SECTION_WRITE
;
6840 flags
= SECTION_WRITE
;
6841 if (strcmp (name
, ".data.rel.ro") == 0
6842 || strcmp (name
, ".data.rel.ro.local") == 0)
6843 flags
|= SECTION_RELRO
;
6846 if (decl
&& DECL_P (decl
) && DECL_COMDAT_GROUP (decl
))
6847 flags
|= SECTION_LINKONCE
;
6849 if (strcmp (name
, ".vtable_map_vars") == 0)
6850 flags
|= SECTION_LINKONCE
;
6852 if (decl
&& VAR_P (decl
) && DECL_THREAD_LOCAL_P (decl
))
6853 flags
|= SECTION_TLS
| SECTION_WRITE
;
6855 if (strcmp (name
, ".bss") == 0
6856 || startswith (name
, ".bss.")
6857 || startswith (name
, ".gnu.linkonce.b.")
6858 || strcmp (name
, ".persistent.bss") == 0
6859 || strcmp (name
, ".sbss") == 0
6860 || startswith (name
, ".sbss.")
6861 || startswith (name
, ".gnu.linkonce.sb."))
6862 flags
|= SECTION_BSS
;
6864 if (strcmp (name
, ".tdata") == 0
6865 || startswith (name
, ".tdata.")
6866 || startswith (name
, ".gnu.linkonce.td."))
6867 flags
|= SECTION_TLS
;
6869 if (strcmp (name
, ".tbss") == 0
6870 || startswith (name
, ".tbss.")
6871 || startswith (name
, ".gnu.linkonce.tb."))
6872 flags
|= SECTION_TLS
| SECTION_BSS
;
6874 if (strcmp (name
, ".noinit") == 0)
6875 flags
|= SECTION_WRITE
| SECTION_BSS
| SECTION_NOTYPE
;
6877 if (strcmp (name
, ".persistent") == 0)
6878 flags
|= SECTION_WRITE
| SECTION_NOTYPE
;
6880 /* Various sections have special ELF types that the assembler will
6881 assign by default based on the name. They are neither SHT_PROGBITS
6882 nor SHT_NOBITS, so when changing sections we don't want to print a
6883 section type (@progbits or @nobits). Rather than duplicating the
6884 assembler's knowledge of what those special name patterns are, just
6885 let the assembler choose the type if we don't know a specific
6886 reason to set it to something other than the default. SHT_PROGBITS
6887 is the default for sections whose name is not specially known to
6888 the assembler, so it does no harm to leave the choice to the
6889 assembler when @progbits is the best thing we know to use. If
6890 someone is silly enough to emit code or TLS variables to one of
6891 these sections, then don't handle them specially.
6893 default_elf_asm_named_section (below) handles the BSS, TLS, ENTSIZE, and
6894 LINKONCE cases when NOTYPE is not set, so leave those to its logic. */
6895 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
| SECTION_ENTSIZE
))
6896 && !(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
)))
6897 flags
|= SECTION_NOTYPE
;
6902 /* Return true if the target supports some form of global BSS,
6903 either through bss_noswitch_section, or by selecting a BSS
6904 section in TARGET_ASM_SELECT_SECTION. */
6907 have_global_bss_p (void)
6909 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6912 /* Output assembly to switch to section NAME with attribute FLAGS.
6913 Four variants for common object file formats. */
6916 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6917 unsigned int flags ATTRIBUTE_UNUSED
,
6918 tree decl ATTRIBUTE_UNUSED
)
6920 /* Some object formats don't support named sections at all. The
6921 front-end should already have flagged this as an error. */
6925 #ifndef TLS_SECTION_ASM_FLAG
6926 #define TLS_SECTION_ASM_FLAG 'T'
6930 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6933 char flagchars
[11], *f
= flagchars
;
6934 unsigned int numeric_value
= 0;
6936 /* If we have already declared this section, we can use an
6937 abbreviated form to switch back to it -- unless this section is
6938 part of a COMDAT groups or with SHF_GNU_RETAIN or with SHF_LINK_ORDER,
6939 in which case GAS requires the full declaration every time. */
6940 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6941 && !(flags
& (SECTION_RETAIN
| SECTION_LINK_ORDER
))
6942 && (flags
& SECTION_DECLARED
))
6944 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6948 /* If we have a machine specific flag, then use the numeric value to pass
6950 if (targetm
.asm_out
.elf_flags_numeric (flags
, &numeric_value
))
6951 snprintf (f
, sizeof (flagchars
), "0x%08x", numeric_value
);
6954 if (!(flags
& SECTION_DEBUG
))
6956 #if HAVE_GAS_SECTION_EXCLUDE
6957 if (flags
& SECTION_EXCLUDE
)
6960 if (flags
& SECTION_WRITE
)
6962 if (flags
& SECTION_CODE
)
6964 if (flags
& SECTION_SMALL
)
6966 if (flags
& SECTION_MERGE
)
6968 if (flags
& SECTION_STRINGS
)
6970 if (flags
& SECTION_TLS
)
6971 *f
++ = TLS_SECTION_ASM_FLAG
;
6972 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6974 if (flags
& SECTION_RETAIN
)
6976 if (flags
& SECTION_LINK_ORDER
)
6978 #ifdef MACH_DEP_SECTION_ASM_FLAG
6979 if (flags
& SECTION_MACH_DEP
)
6980 *f
++ = MACH_DEP_SECTION_ASM_FLAG
;
6985 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6987 /* default_section_type_flags (above) knows which flags need special
6988 handling here, and sets NOTYPE when none of these apply so that the
6989 assembler's logic for default types can apply to user-chosen
6991 if (!(flags
& SECTION_NOTYPE
))
6996 if (flags
& SECTION_BSS
)
7002 /* On platforms that use "@" as the assembly comment character,
7004 if (strcmp (ASM_COMMENT_START
, "@") == 0)
7006 fprintf (asm_out_file
, format
, type
);
7008 if (flags
& SECTION_ENTSIZE
)
7009 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
7010 if (flags
& SECTION_LINK_ORDER
)
7012 /* For now, only section "__patchable_function_entries"
7013 adopts flag SECTION_LINK_ORDER, internal label LPFE*
7014 was emitted in default_print_patchable_function_entry,
7015 just place it here for linked_to section. */
7016 gcc_assert (!strcmp (name
, "__patchable_function_entries"));
7017 fprintf (asm_out_file
, ",");
7019 ASM_GENERATE_INTERNAL_LABEL (buf
, "LPFE",
7020 current_function_funcdef_no
);
7021 assemble_name_raw (asm_out_file
, buf
);
7023 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
7025 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
7026 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
7028 fprintf (asm_out_file
, ",%s,comdat",
7029 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
7033 putc ('\n', asm_out_file
);
7037 default_coff_asm_named_section (const char *name
, unsigned int flags
,
7038 tree decl ATTRIBUTE_UNUSED
)
7040 char flagchars
[8], *f
= flagchars
;
7042 if (flags
& SECTION_WRITE
)
7044 if (flags
& SECTION_CODE
)
7048 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
7052 default_pe_asm_named_section (const char *name
, unsigned int flags
,
7055 default_coff_asm_named_section (name
, flags
, decl
);
7057 if (flags
& SECTION_LINKONCE
)
7059 /* Functions may have been compiled at various levels of
7060 optimization so we can't use `same_size' here.
7061 Instead, have the linker pick one. */
7062 fprintf (asm_out_file
, "\t.linkonce %s\n",
7063 (flags
& SECTION_CODE
? "discard" : "same_size"));
7067 /* The lame default section selector. */
7070 default_select_section (tree decl
, int reloc
,
7071 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
7075 if (decl_readonly_section (decl
, reloc
))
7076 return readonly_data_section
;
7078 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
7080 if (! ((flag_pic
&& reloc
)
7081 || !TREE_READONLY (decl
)
7082 || !TREE_CONSTANT (decl
)))
7083 return readonly_data_section
;
7085 else if (TREE_CODE (decl
) == STRING_CST
)
7086 return readonly_data_section
;
7087 else if (! (flag_pic
&& reloc
))
7088 return readonly_data_section
;
7090 return data_section
;
7093 enum section_category
7094 categorize_decl_for_section (const_tree decl
, int reloc
)
7096 enum section_category ret
;
7098 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7100 else if (TREE_CODE (decl
) == STRING_CST
)
7102 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7103 && asan_protect_global (CONST_CAST_TREE (decl
)))
7104 /* or !flag_merge_constants */
7105 return SECCAT_RODATA
;
7107 return SECCAT_RODATA_MERGE_STR
;
7109 else if (VAR_P (decl
))
7111 tree d
= CONST_CAST_TREE (decl
);
7112 if (bss_initializer_p (decl
))
7114 else if (! TREE_READONLY (decl
)
7115 || (DECL_INITIAL (decl
)
7116 && ! TREE_CONSTANT (DECL_INITIAL (decl
))))
7118 /* Here the reloc_rw_mask is not testing whether the section should
7119 be read-only or not, but whether the dynamic link will have to
7120 do something. If so, we wish to segregate the data in order to
7121 minimize cache misses inside the dynamic linker. */
7122 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
7123 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
7127 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
7128 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
7129 else if (reloc
|| (flag_merge_constants
< 2 && !DECL_MERGEABLE (decl
))
7130 || ((flag_sanitize
& SANITIZE_ADDRESS
)
7131 /* PR 81697: for architectures that use section anchors we
7132 need to ignore DECL_RTL_SET_P (decl) for string constants
7133 inside this asan_protect_global call because otherwise
7134 we'll wrongly put them into SECCAT_RODATA_MERGE_CONST
7135 section, set DECL_RTL (decl) later on and add DECL to
7136 protected globals via successive asan_protect_global
7137 calls. In this scenario we'll end up with wrong
7138 alignment of these strings at runtime and possible ASan
7140 && asan_protect_global (d
, use_object_blocks_p ()
7141 && use_blocks_for_decl_p (d
))))
7142 /* C and C++ don't allow different variables to share the same
7143 location. -fmerge-all-constants allows even that (at the
7144 expense of not conforming). */
7145 ret
= SECCAT_RODATA
;
7146 else if (DECL_INITIAL (decl
)
7147 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
7148 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
7150 ret
= SECCAT_RODATA_MERGE_CONST
;
7152 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
7154 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
7155 || ! TREE_CONSTANT (decl
))
7158 ret
= SECCAT_RODATA
;
7161 ret
= SECCAT_RODATA
;
7163 /* There are no read-only thread-local sections. */
7164 if (VAR_P (decl
) && DECL_THREAD_LOCAL_P (decl
))
7166 /* Note that this would be *just* SECCAT_BSS, except that there's
7167 no concept of a read-only thread-local-data section. */
7168 if (ret
== SECCAT_BSS
7169 || DECL_INITIAL (decl
) == NULL
7170 || (flag_zero_initialized_in_bss
7171 && initializer_zerop (DECL_INITIAL (decl
))))
7177 /* If the target uses small data sections, select it. */
7178 else if (targetm
.in_small_data_p (decl
))
7180 if (ret
== SECCAT_BSS
)
7182 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
7183 ret
= SECCAT_SRODATA
;
7192 decl_readonly_section_1 (enum section_category category
)
7197 case SECCAT_RODATA_MERGE_STR
:
7198 case SECCAT_RODATA_MERGE_STR_INIT
:
7199 case SECCAT_RODATA_MERGE_CONST
:
7200 case SECCAT_SRODATA
:
7208 decl_readonly_section (const_tree decl
, int reloc
)
7210 return decl_readonly_section_1 (categorize_decl_for_section (decl
, reloc
));
7213 /* Select a section based on the above categorization. */
7216 default_elf_select_section (tree decl
, int reloc
,
7217 unsigned HOST_WIDE_INT align
)
7221 switch (categorize_decl_for_section (decl
, reloc
))
7224 /* We're not supposed to be called on FUNCTION_DECLs. */
7227 return readonly_data_section
;
7228 case SECCAT_RODATA_MERGE_STR
:
7229 return mergeable_string_section (decl
, align
, 0);
7230 case SECCAT_RODATA_MERGE_STR_INIT
:
7231 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
7232 case SECCAT_RODATA_MERGE_CONST
:
7233 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
7234 case SECCAT_SRODATA
:
7238 if (DECL_P (decl
) && DECL_PERSISTENT_P (decl
))
7240 sname
= ".persistent";
7243 return data_section
;
7244 case SECCAT_DATA_REL
:
7245 sname
= ".data.rel";
7247 case SECCAT_DATA_REL_LOCAL
:
7248 sname
= ".data.rel.local";
7250 case SECCAT_DATA_REL_RO
:
7251 sname
= ".data.rel.ro";
7253 case SECCAT_DATA_REL_RO_LOCAL
:
7254 sname
= ".data.rel.ro.local";
7263 if (DECL_P (decl
) && DECL_NOINIT_P (decl
))
7282 return get_named_section (decl
, sname
, reloc
);
7285 /* Construct a unique section name based on the decl name and the
7286 categorization performed above. */
7289 default_unique_section (tree decl
, int reloc
)
7291 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
7292 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
7293 const char *prefix
, *name
, *linkonce
;
7297 switch (categorize_decl_for_section (decl
, reloc
))
7300 prefix
= one_only
? ".t" : ".text";
7303 case SECCAT_RODATA_MERGE_STR
:
7304 case SECCAT_RODATA_MERGE_STR_INIT
:
7305 case SECCAT_RODATA_MERGE_CONST
:
7306 prefix
= one_only
? ".r" : ".rodata";
7308 case SECCAT_SRODATA
:
7309 prefix
= one_only
? ".s2" : ".sdata2";
7312 prefix
= one_only
? ".d" : ".data";
7313 if (DECL_P (decl
) && DECL_PERSISTENT_P (decl
))
7315 prefix
= one_only
? ".p" : ".persistent";
7319 case SECCAT_DATA_REL
:
7320 prefix
= one_only
? ".d.rel" : ".data.rel";
7322 case SECCAT_DATA_REL_LOCAL
:
7323 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
7325 case SECCAT_DATA_REL_RO
:
7326 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
7328 case SECCAT_DATA_REL_RO_LOCAL
:
7329 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
7332 prefix
= one_only
? ".s" : ".sdata";
7335 if (DECL_P (decl
) && DECL_NOINIT_P (decl
))
7337 prefix
= one_only
? ".n" : ".noinit";
7340 prefix
= one_only
? ".b" : ".bss";
7343 prefix
= one_only
? ".sb" : ".sbss";
7346 prefix
= one_only
? ".td" : ".tdata";
7349 prefix
= one_only
? ".tb" : ".tbss";
7355 id
= DECL_ASSEMBLER_NAME (decl
);
7356 ultimate_transparent_alias_target (&id
);
7357 name
= IDENTIFIER_POINTER (id
);
7358 name
= targetm
.strip_name_encoding (name
);
7360 /* If we're using one_only, then there needs to be a .gnu.linkonce
7361 prefix to the section name. */
7362 linkonce
= one_only
? ".gnu.linkonce" : "";
7364 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
7366 set_decl_section_name (decl
, string
);
7369 /* Subroutine of compute_reloc_for_rtx for leaf rtxes. */
7372 compute_reloc_for_rtx_1 (const_rtx x
)
7374 switch (GET_CODE (x
))
7377 return SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
7385 /* Like compute_reloc_for_constant, except for an RTX. The return value
7386 is a mask for which bit 1 indicates a global relocation, and bit 0
7387 indicates a local relocation. Used by default_select_rtx_section
7388 and default_elf_select_rtx_section. */
7391 compute_reloc_for_rtx (const_rtx x
)
7393 switch (GET_CODE (x
))
7397 return compute_reloc_for_rtx_1 (x
);
7402 subrtx_iterator::array_type array
;
7403 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
7404 reloc
|= compute_reloc_for_rtx_1 (*iter
);
7414 default_select_rtx_section (machine_mode mode ATTRIBUTE_UNUSED
,
7416 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
7418 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
7419 return data_section
;
7421 return readonly_data_section
;
7425 default_elf_select_rtx_section (machine_mode mode
, rtx x
,
7426 unsigned HOST_WIDE_INT align
)
7428 int reloc
= compute_reloc_for_rtx (x
);
7430 /* ??? Handle small data here somehow. */
7432 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
7435 return get_named_section (NULL
, ".data.rel.ro.local", 1);
7437 return get_named_section (NULL
, ".data.rel.ro", 3);
7440 return mergeable_constant_section (mode
, align
, 0);
7443 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
7446 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
7451 /* Careful not to prod global register variables. */
7454 symbol
= XEXP (rtl
, 0);
7455 if (GET_CODE (symbol
) != SYMBOL_REF
)
7458 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
7459 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7460 flags
|= SYMBOL_FLAG_FUNCTION
;
7461 if (targetm
.binds_local_p (decl
))
7462 flags
|= SYMBOL_FLAG_LOCAL
;
7463 if (VAR_P (decl
) && DECL_THREAD_LOCAL_P (decl
))
7464 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
7465 else if (targetm
.in_small_data_p (decl
))
7466 flags
|= SYMBOL_FLAG_SMALL
;
7467 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
7468 being PUBLIC, the thing *must* be defined in this translation unit.
7469 Prevent this buglet from being propagated into rtl code as well. */
7470 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
7471 flags
|= SYMBOL_FLAG_EXTERNAL
;
7473 SYMBOL_REF_FLAGS (symbol
) = flags
;
7476 /* By default, we do nothing for encode_section_info, so we need not
7477 do anything but discard the '*' marker. */
7480 default_strip_name_encoding (const char *str
)
7482 return str
+ (*str
== '*');
7485 #ifdef ASM_OUTPUT_DEF
7486 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
7487 anchor relative to ".", the current section position. */
7490 default_asm_output_anchor (rtx symbol
)
7492 gcc_checking_assert (TARGET_SUPPORTS_ALIASES
);
7496 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
7497 SYMBOL_REF_BLOCK_OFFSET (symbol
));
7498 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
7502 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
7505 default_use_anchors_for_symbol_p (const_rtx symbol
)
7508 section
*sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
7510 /* This function should only be called with non-zero SYMBOL_REF_BLOCK,
7511 furthermore get_block_for_section should not create object blocks
7512 for mergeable sections. */
7513 gcc_checking_assert (sect
&& !(sect
->common
.flags
& SECTION_MERGE
));
7515 /* Don't use anchors for small data sections. The small data register
7516 acts as an anchor for such sections. */
7517 if (sect
->common
.flags
& SECTION_SMALL
)
7520 decl
= SYMBOL_REF_DECL (symbol
);
7521 if (decl
&& DECL_P (decl
))
7523 /* Don't use section anchors for decls that might be defined or
7524 usurped by other modules. */
7525 if (TREE_PUBLIC (decl
) && !decl_binds_to_current_def_p (decl
))
7528 /* Don't use section anchors for decls that will be placed in a
7529 small data section. */
7530 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
7531 one above. The problem is that we only use SECTION_SMALL for
7532 sections that should be marked as small in the section directive. */
7533 if (targetm
.in_small_data_p (decl
))
7536 /* Don't use section anchors for decls that won't fit inside a single
7537 anchor range to reduce the amount of instructions required to refer
7538 to the entire declaration. */
7539 if (DECL_SIZE_UNIT (decl
) == NULL_TREE
7540 || !tree_fits_uhwi_p (DECL_SIZE_UNIT (decl
))
7541 || (tree_to_uhwi (DECL_SIZE_UNIT (decl
))
7542 >= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
))
7549 /* Return true when RESOLUTION indicate that symbol will be bound to the
7550 definition provided by current .o file. */
7553 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
7555 return (resolution
== LDPR_PREVAILING_DEF
7556 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
7557 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
7560 /* Return true when RESOLUTION indicate that symbol will be bound locally
7561 within current executable or DSO. */
7564 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
7566 return (resolution
== LDPR_PREVAILING_DEF
7567 || resolution
== LDPR_PREVAILING_DEF_IRONLY
7568 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
7569 || resolution
== LDPR_PREEMPTED_REG
7570 || resolution
== LDPR_PREEMPTED_IR
7571 || resolution
== LDPR_RESOLVED_IR
7572 || resolution
== LDPR_RESOLVED_EXEC
);
7575 /* COMMON_LOCAL_P is true means that the linker can guarantee that an
7576 uninitialized common symbol in the executable will still be defined
7577 (through COPY relocation) in the executable. */
7580 default_binds_local_p_3 (const_tree exp
, bool shlib
, bool weak_dominate
,
7581 bool extern_protected_data
, bool common_local_p
)
7583 /* A non-decl is an entry in the constant pool. */
7587 /* Weakrefs may not bind locally, even though the weakref itself is always
7588 static and therefore local. Similarly, the resolver for ifunc functions
7589 might resolve to a non-local function.
7590 FIXME: We can resolve the weakref case more curefuly by looking at the
7592 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
))
7593 || (!targetm
.ifunc_ref_local_ok ()
7594 && TREE_CODE (exp
) == FUNCTION_DECL
7595 && cgraph_node::get (exp
)
7596 && cgraph_node::get (exp
)->ifunc_resolver
))
7599 /* Static variables are always local. */
7600 if (! TREE_PUBLIC (exp
))
7603 /* With resolution file in hand, take look into resolutions.
7604 We can't just return true for resolved_locally symbols,
7605 because dynamic linking might overwrite symbols
7606 in shared libraries. */
7607 bool resolved_locally
= false;
7609 bool uninited_common
= (DECL_COMMON (exp
)
7610 && (DECL_INITIAL (exp
) == NULL
7612 && DECL_INITIAL (exp
) == error_mark_node
)));
7614 /* A non-external variable is defined locally only if it isn't
7615 uninitialized COMMON variable or common_local_p is true. */
7616 bool defined_locally
= (!DECL_EXTERNAL (exp
)
7617 && (!uninited_common
|| common_local_p
));
7618 if (symtab_node
*node
= symtab_node::get (exp
))
7620 if (node
->in_other_partition
)
7621 defined_locally
= true;
7622 if (node
->can_be_discarded_p ())
7624 else if (resolution_to_local_definition_p (node
->resolution
))
7625 defined_locally
= resolved_locally
= true;
7626 else if (resolution_local_p (node
->resolution
))
7627 resolved_locally
= true;
7629 if (defined_locally
&& weak_dominate
&& !shlib
)
7630 resolved_locally
= true;
7632 /* Undefined weak symbols are never defined locally. */
7633 if (DECL_WEAK (exp
) && !defined_locally
)
7636 /* A symbol is local if the user has said explicitly that it will be,
7637 or if we have a definition for the symbol. We cannot infer visibility
7638 for undefined symbols. */
7639 if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
7640 && (TREE_CODE (exp
) == FUNCTION_DECL
7641 || !extern_protected_data
7642 || DECL_VISIBILITY (exp
) != VISIBILITY_PROTECTED
)
7643 && (DECL_VISIBILITY_SPECIFIED (exp
) || defined_locally
))
7646 /* If PIC, then assume that any global name can be overridden by
7647 symbols resolved from other modules. */
7651 /* Variables defined outside this object might not be local. */
7652 if (DECL_EXTERNAL (exp
) && !resolved_locally
)
7655 /* Non-dominant weak symbols are not defined locally. */
7656 if (DECL_WEAK (exp
) && !resolved_locally
)
7659 /* Uninitialized COMMON variable may be unified with symbols
7660 resolved from other modules. */
7661 if (uninited_common
&& !resolved_locally
)
7664 /* Otherwise we're left with initialized (or non-common) global data
7665 which is of necessity defined locally. */
7669 /* Assume ELF-ish defaults, since that's pretty much the most liberal
7670 wrt cross-module name binding. */
7673 default_binds_local_p (const_tree exp
)
7675 return default_binds_local_p_3 (exp
, flag_shlib
!= 0, true, false, false);
7678 /* Similar to default_binds_local_p, but common symbol may be local and
7679 extern protected data is non-local. */
7682 default_binds_local_p_2 (const_tree exp
)
7684 return default_binds_local_p_3 (exp
, flag_shlib
!= 0, true, true,
7689 default_binds_local_p_1 (const_tree exp
, int shlib
)
7691 return default_binds_local_p_3 (exp
, shlib
!= 0, false, false, false);
7694 /* Return true when references to DECL must bind to current definition in
7697 The condition is usually equivalent to whether the function binds to the
7698 current module (shared library or executable), that is to binds_local_p.
7699 We use this fact to avoid need for another target hook and implement
7700 the logic using binds_local_p and just special cases where
7701 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
7702 the weak definitions (that can be overwritten at linktime by other
7703 definition from different object file) and when resolution info is available
7704 we simply use the knowledge passed to us by linker plugin. */
7706 decl_binds_to_current_def_p (const_tree decl
)
7708 gcc_assert (DECL_P (decl
));
7709 if (!targetm
.binds_local_p (decl
))
7711 if (!TREE_PUBLIC (decl
))
7714 /* When resolution is available, just use it. */
7715 if (symtab_node
*node
= symtab_node::get (decl
))
7717 if (node
->resolution
!= LDPR_UNKNOWN
7718 && !node
->can_be_discarded_p ())
7719 return resolution_to_local_definition_p (node
->resolution
);
7722 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
7723 binds locally but still can be overwritten), DECL_COMMON (can be merged
7724 with a non-common definition somewhere in the same module) or
7726 This rely on fact that binds_local_p behave as decl_replaceable_p
7727 for all other declaration types. */
7728 if (DECL_WEAK (decl
))
7730 if (DECL_COMMON (decl
)
7731 && (DECL_INITIAL (decl
) == NULL
7732 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
7734 if (DECL_EXTERNAL (decl
))
7739 /* A replaceable function or variable is one which may be replaced
7740 at link-time with an entirely different definition, provided that the
7741 replacement has the same type. For example, functions declared
7742 with __attribute__((weak)) on most systems are replaceable.
7743 If SEMANTIC_INTERPOSITION_P is false allow interposition only on
7744 symbols explicitly declared weak.
7746 COMDAT functions are not replaceable, since all definitions of the
7747 function must be equivalent. It is important that COMDAT functions
7748 not be treated as replaceable so that use of C++ template
7749 instantiations is not penalized. */
7752 decl_replaceable_p (tree decl
, bool semantic_interposition_p
)
7754 gcc_assert (DECL_P (decl
));
7755 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
7757 if (!semantic_interposition_p
7758 && !DECL_WEAK (decl
))
7760 return !decl_binds_to_current_def_p (decl
);
7763 /* Default function to output code that will globalize a label. A
7764 target must define GLOBAL_ASM_OP or provide its own function to
7765 globalize a label. */
7766 #ifdef GLOBAL_ASM_OP
7768 default_globalize_label (FILE * stream
, const char *name
)
7770 fputs (GLOBAL_ASM_OP
, stream
);
7771 assemble_name (stream
, name
);
7772 putc ('\n', stream
);
7774 #endif /* GLOBAL_ASM_OP */
7776 /* Default function to output code that will globalize a declaration. */
7778 default_globalize_decl_name (FILE * stream
, tree decl
)
7780 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
7781 targetm
.asm_out
.globalize_label (stream
, name
);
7784 /* Default function to output a label for unwind information. The
7785 default is to do nothing. A target that needs nonlocal labels for
7786 unwind information must provide its own function to do this. */
7788 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
7789 tree decl ATTRIBUTE_UNUSED
,
7790 int for_eh ATTRIBUTE_UNUSED
,
7791 int empty ATTRIBUTE_UNUSED
)
7795 /* Default function to output a label to divide up the exception table.
7796 The default is to do nothing. A target that needs/wants to divide
7797 up the table must provide it's own function to do this. */
7799 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
7803 /* This is how to output an internal numbered label where PREFIX is
7804 the class of label and LABELNO is the number within the class. */
7807 default_generate_internal_label (char *buf
, const char *prefix
,
7808 unsigned long labelno
)
7810 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
7813 /* This is how to output an internal numbered label where PREFIX is
7814 the class of label and LABELNO is the number within the class. */
7817 default_internal_label (FILE *stream
, const char *prefix
,
7818 unsigned long labelno
)
7820 char *const buf
= (char *) alloca (40 + strlen (prefix
));
7821 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
7822 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
7826 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
7829 default_asm_declare_constant_name (FILE *file
, const char *name
,
7830 const_tree exp ATTRIBUTE_UNUSED
,
7831 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
7833 assemble_label (file
, name
);
7836 /* This is the default behavior at the beginning of a file. It's
7837 controlled by two other target-hook toggles. */
7839 default_file_start (void)
7841 if (targetm
.asm_file_start_app_off
7842 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
7843 fputs (ASM_APP_OFF
, asm_out_file
);
7845 if (targetm
.asm_file_start_file_directive
)
7847 /* LTO produced units have no meaningful main_input_filename. */
7849 output_file_directive (asm_out_file
, "<artificial>");
7851 output_file_directive (asm_out_file
, main_input_filename
);
7855 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
7856 which emits a special section directive used to indicate whether or
7857 not this object file needs an executable stack. This is primarily
7858 a GNU extension to ELF but could be used on other targets. */
7860 int trampolines_created
;
7863 file_end_indicate_exec_stack (void)
7865 unsigned int flags
= SECTION_DEBUG
;
7866 if (trampolines_created
)
7867 flags
|= SECTION_CODE
;
7869 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
7872 /* Emit a special section directive to indicate that this object file
7873 was compiled with -fsplit-stack. This is used to let the linker
7874 detect calls between split-stack code and non-split-stack code, so
7875 that it can modify the split-stack code to allocate a sufficiently
7876 large stack. We emit another special section if there are any
7877 functions in this file which have the no_split_stack attribute, to
7878 prevent the linker from warning about being unable to convert the
7879 functions if they call non-split-stack code. */
7882 file_end_indicate_split_stack (void)
7884 if (flag_split_stack
)
7886 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
7888 if (saw_no_split_stack
)
7889 switch_to_section (get_section (".note.GNU-no-split-stack",
7890 SECTION_DEBUG
, NULL
));
7894 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
7895 a get_unnamed_section callback. */
7898 output_section_asm_op (const char *directive
)
7900 fprintf (asm_out_file
, "%s\n", directive
);
7903 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
7904 the current section is NEW_SECTION. */
7907 switch_to_section (section
*new_section
, tree decl
)
7910 if ((new_section
->common
.flags
& SECTION_NAMED
)
7913 && ((retain_p
= !!lookup_attribute ("retain",
7914 DECL_ATTRIBUTES (decl
)))
7915 != !!(new_section
->common
.flags
& SECTION_RETAIN
)))
7917 /* If the SECTION_RETAIN bit doesn't match, switch to a new
7919 tree used_decl
, no_used_decl
;
7923 new_section
->common
.flags
|= SECTION_RETAIN
;
7925 no_used_decl
= new_section
->named
.decl
;
7929 new_section
->common
.flags
&= ~(SECTION_RETAIN
7930 | SECTION_DECLARED
);
7931 used_decl
= new_section
->named
.decl
;
7932 no_used_decl
= decl
;
7934 if (no_used_decl
!= used_decl
)
7936 warning (OPT_Wattributes
,
7937 "%+qD without %<retain%> attribute and %qD with "
7938 "%<retain%> attribute are placed in a section with "
7939 "the same name", no_used_decl
, used_decl
);
7940 inform (DECL_SOURCE_LOCATION (used_decl
),
7941 "%qD was declared here", used_decl
);
7944 else if (in_section
== new_section
)
7947 in_section
= new_section
;
7949 switch (SECTION_STYLE (new_section
))
7952 targetm
.asm_out
.named_section (new_section
->named
.name
,
7953 new_section
->named
.common
.flags
,
7954 new_section
->named
.decl
);
7957 case SECTION_UNNAMED
:
7958 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
7961 case SECTION_NOSWITCH
:
7966 new_section
->common
.flags
|= SECTION_DECLARED
;
7969 /* If block symbol SYMBOL has not yet been assigned an offset, place
7970 it at the end of its block. */
7973 place_block_symbol (rtx symbol
)
7975 unsigned HOST_WIDE_INT size
, mask
, offset
;
7976 class constant_descriptor_rtx
*desc
;
7977 unsigned int alignment
;
7978 struct object_block
*block
;
7981 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
7982 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
7985 /* Work out the symbol's size and alignment. */
7986 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7988 desc
= SYMBOL_REF_CONSTANT (symbol
);
7989 alignment
= desc
->align
;
7990 size
= GET_MODE_SIZE (desc
->mode
);
7992 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7994 decl
= SYMBOL_REF_DECL (symbol
);
7995 gcc_checking_assert (DECL_IN_CONSTANT_POOL (decl
));
7996 alignment
= DECL_ALIGN (decl
);
7997 size
= get_constant_size (DECL_INITIAL (decl
));
7998 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7999 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
8000 && asan_protect_global (DECL_INITIAL (decl
)))
8002 size
+= asan_red_zone_size (size
);
8003 alignment
= MAX (alignment
,
8004 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
8009 struct symtab_node
*snode
;
8010 decl
= SYMBOL_REF_DECL (symbol
);
8012 snode
= symtab_node::get (decl
);
8015 rtx target
= DECL_RTL (snode
->ultimate_alias_target ()->decl
);
8017 gcc_assert (MEM_P (target
)
8018 && GET_CODE (XEXP (target
, 0)) == SYMBOL_REF
8019 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (target
, 0)));
8020 target
= XEXP (target
, 0);
8021 place_block_symbol (target
);
8022 SYMBOL_REF_BLOCK_OFFSET (symbol
) = SYMBOL_REF_BLOCK_OFFSET (target
);
8025 alignment
= get_variable_align (decl
);
8026 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
8027 if ((flag_sanitize
& SANITIZE_ADDRESS
)
8028 && asan_protect_global (decl
))
8030 size
+= asan_red_zone_size (size
);
8031 alignment
= MAX (alignment
,
8032 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
8036 /* Calculate the object's offset from the start of the block. */
8037 block
= SYMBOL_REF_BLOCK (symbol
);
8038 mask
= alignment
/ BITS_PER_UNIT
- 1;
8039 offset
= (block
->size
+ mask
) & ~mask
;
8040 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
8042 /* Record the block's new alignment and size. */
8043 block
->alignment
= MAX (block
->alignment
, alignment
);
8044 block
->size
= offset
+ size
;
8046 vec_safe_push (block
->objects
, symbol
);
8049 /* Return the anchor that should be used to address byte offset OFFSET
8050 from the first object in BLOCK. MODEL is the TLS model used
8054 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
8055 enum tls_model model
)
8058 unsigned int begin
, middle
, end
;
8059 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
8062 /* Work out the anchor's offset. Use an offset of 0 for the first
8063 anchor so that we don't pessimize the case where we take the address
8064 of a variable at the beginning of the block. This is particularly
8065 useful when a block has only one variable assigned to it.
8067 We try to place anchors RANGE bytes apart, so there can then be
8068 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
8069 a ptr_mode offset. With some target settings, the lowest such
8070 anchor might be out of range for the lowest ptr_mode offset;
8071 likewise the highest anchor for the highest offset. Use anchors
8072 at the extreme ends of the ptr_mode range in such cases.
8074 All arithmetic uses unsigned integers in order to avoid
8076 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
8077 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
8078 range
= max_offset
- min_offset
+ 1;
8083 bias
= HOST_WIDE_INT_1U
<< (GET_MODE_BITSIZE (ptr_mode
) - 1);
8086 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
8087 delta
-= delta
% range
;
8090 offset
= (HOST_WIDE_INT
) (-delta
);
8094 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
8095 delta
-= delta
% range
;
8096 if (delta
> bias
- 1)
8098 offset
= (HOST_WIDE_INT
) delta
;
8102 /* Do a binary search to see if there's already an anchor we can use.
8103 Set BEGIN to the new anchor's index if not. */
8105 end
= vec_safe_length (block
->anchors
);
8106 while (begin
!= end
)
8108 middle
= (end
+ begin
) / 2;
8109 anchor
= (*block
->anchors
)[middle
];
8110 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
8112 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
8114 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
8116 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
8122 /* Create a new anchor with a unique label. */
8123 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
8124 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
8125 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
8126 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
8128 /* Insert it at index BEGIN. */
8129 vec_safe_insert (block
->anchors
, begin
, anchor
);
8133 /* Output the objects in BLOCK. */
8136 output_object_block (struct object_block
*block
)
8138 class constant_descriptor_rtx
*desc
;
8140 HOST_WIDE_INT offset
;
8144 if (!block
->objects
)
8147 /* Switch to the section and make sure that the first byte is
8148 suitably aligned. */
8149 /* Special case VTV comdat sections similar to assemble_variable. */
8150 if (SECTION_STYLE (block
->sect
) == SECTION_NAMED
8151 && block
->sect
->named
.name
8152 && (strcmp (block
->sect
->named
.name
, ".vtable_map_vars") == 0))
8153 handle_vtv_comdat_section (block
->sect
, block
->sect
->named
.decl
);
8155 switch_to_section (block
->sect
, SYMBOL_REF_DECL ((*block
->objects
)[0]));
8157 gcc_checking_assert (!(block
->sect
->common
.flags
& SECTION_MERGE
));
8158 assemble_align (block
->alignment
);
8160 /* Define the values of all anchors relative to the current section
8162 FOR_EACH_VEC_SAFE_ELT (block
->anchors
, i
, symbol
)
8163 targetm
.asm_out
.output_anchor (symbol
);
8165 /* Output the objects themselves. */
8167 FOR_EACH_VEC_ELT (*block
->objects
, i
, symbol
)
8169 /* Move to the object's offset, padding with zeros if necessary. */
8170 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
8171 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
8172 if (CONSTANT_POOL_ADDRESS_P (symbol
))
8174 desc
= SYMBOL_REF_CONSTANT (symbol
);
8175 /* Pass 1 for align as we have already laid out everything in the block.
8176 So aligning shouldn't be necessary. */
8177 output_constant_pool_1 (desc
, 1);
8178 offset
+= GET_MODE_SIZE (desc
->mode
);
8180 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
8183 decl
= SYMBOL_REF_DECL (symbol
);
8184 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
8185 DECL_ALIGN (decl
), false);
8187 size
= get_constant_size (DECL_INITIAL (decl
));
8189 if ((flag_sanitize
& SANITIZE_ADDRESS
)
8190 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
8191 && asan_protect_global (DECL_INITIAL (decl
)))
8193 size
= asan_red_zone_size (size
);
8194 assemble_zeros (size
);
8201 decl
= SYMBOL_REF_DECL (symbol
);
8202 assemble_variable_contents (decl
, XSTR (symbol
, 0), false, false);
8203 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
8205 if ((flag_sanitize
& SANITIZE_ADDRESS
)
8206 && asan_protect_global (decl
))
8208 size
= asan_red_zone_size (size
);
8209 assemble_zeros (size
);
8216 /* A callback for qsort to compare object_blocks. */
8219 output_object_block_compare (const void *x
, const void *y
)
8221 object_block
*p1
= *(object_block
* const*)x
;
8222 object_block
*p2
= *(object_block
* const*)y
;
8224 if (p1
->sect
->common
.flags
& SECTION_NAMED
8225 && !(p2
->sect
->common
.flags
& SECTION_NAMED
))
8228 if (!(p1
->sect
->common
.flags
& SECTION_NAMED
)
8229 && p2
->sect
->common
.flags
& SECTION_NAMED
)
8232 if (p1
->sect
->common
.flags
& SECTION_NAMED
8233 && p2
->sect
->common
.flags
& SECTION_NAMED
)
8234 return strcmp (p1
->sect
->named
.name
, p2
->sect
->named
.name
);
8236 unsigned f1
= p1
->sect
->common
.flags
;
8237 unsigned f2
= p2
->sect
->common
.flags
;
8240 return f1
< f2
? -1 : 1;
8243 /* Output the definitions of all object_blocks. */
8246 output_object_blocks (void)
8248 vec
<object_block
*, va_heap
> v
;
8249 v
.create (object_block_htab
->elements ());
8251 hash_table
<object_block_hasher
>::iterator hi
;
8253 FOR_EACH_HASH_TABLE_ELEMENT (*object_block_htab
, obj
, object_block
*, hi
)
8256 /* Sort them in order to output them in a deterministic manner,
8257 otherwise we may get .rodata sections in different orders with
8259 v
.qsort (output_object_block_compare
);
8261 FOR_EACH_VEC_ELT (v
, i
, obj
)
8262 output_object_block (obj
);
8267 /* This function provides a possible implementation of the
8268 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
8269 by -frecord-gcc-switches it creates a new mergeable, string section in the
8270 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
8271 contains the switches in ASCII format.
8273 FIXME: This code does not correctly handle double quote characters
8274 that appear inside strings, (it strips them rather than preserving them).
8275 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
8276 characters - instead it treats them as sub-string separators. Since
8277 we want to emit NUL strings terminators into the object file we have to use
8281 elf_record_gcc_switches (const char *options
)
8283 section
*sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
8284 SECTION_DEBUG
| SECTION_MERGE
8285 | SECTION_STRINGS
| (SECTION_ENTSIZE
& 1), NULL
);
8286 switch_to_section (sec
);
8287 ASM_OUTPUT_ASCII (asm_out_file
, options
, strlen (options
) + 1);
8290 /* Emit text to declare externally defined symbols. It is needed to
8291 properly support non-default visibility. */
8293 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
8295 const char *name ATTRIBUTE_UNUSED
)
8297 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
8298 set in order to avoid putting out names that are never really
8299 used. Always output visibility specified in the source. */
8300 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
8301 && (DECL_VISIBILITY_SPECIFIED (decl
)
8302 || targetm
.binds_local_p (decl
)))
8303 maybe_assemble_visibility (decl
);
8306 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
8309 default_asm_output_source_filename (FILE *file
, const char *name
)
8311 #ifdef ASM_OUTPUT_SOURCE_FILENAME
8312 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
8314 fprintf (file
, "\t.file\t");
8315 output_quoted_string (file
, name
);
8320 /* Output a file name in the form wanted by System V. */
8323 output_file_directive (FILE *asm_file
, const char *input_name
)
8328 if (input_name
== NULL
)
8329 input_name
= "<stdin>";
8331 input_name
= remap_debug_filename (input_name
);
8333 len
= strlen (input_name
);
8334 na
= input_name
+ len
;
8336 /* NA gets INPUT_NAME sans directory names. */
8337 while (na
> input_name
)
8339 if (IS_DIR_SEPARATOR (na
[-1]))
8344 targetm
.asm_out
.output_source_filename (asm_file
, na
);
8347 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
8350 make_debug_expr_from_rtl (const_rtx exp
)
8352 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
8353 machine_mode mode
= GET_MODE (exp
);
8356 DECL_ARTIFICIAL (ddecl
) = 1;
8357 if (REG_P (exp
) && REG_EXPR (exp
))
8358 type
= TREE_TYPE (REG_EXPR (exp
));
8359 else if (MEM_P (exp
) && MEM_EXPR (exp
))
8360 type
= TREE_TYPE (MEM_EXPR (exp
));
8363 if (type
&& TYPE_MODE (type
) == mode
)
8364 TREE_TYPE (ddecl
) = type
;
8366 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
8367 SET_DECL_MODE (ddecl
, mode
);
8368 dval
= gen_rtx_DEBUG_EXPR (mode
);
8369 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
8370 SET_DECL_RTL (ddecl
, dval
);
8374 #ifdef ELF_ASCII_ESCAPES
8375 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
8378 default_elf_asm_output_limited_string (FILE *f
, const char *s
)
8383 fputs (STRING_ASM_OP
, f
);
8388 escape
= ELF_ASCII_ESCAPES
[c
];
8396 putc ('0'+((c
>>6)&7), f
);
8397 putc ('0'+((c
>>3)&7), f
);
8398 putc ('0'+(c
&7), f
);
8411 /* Default ASM_OUTPUT_ASCII for ELF targets. */
8414 default_elf_asm_output_ascii (FILE *f
, const char *s
, unsigned int len
)
8416 const char *limit
= s
+ len
;
8417 const char *last_null
= NULL
;
8418 unsigned bytes_in_chunk
= 0;
8422 for (; s
< limit
; s
++)
8426 if (bytes_in_chunk
>= 60)
8435 for (p
= s
; p
< limit
&& *p
!= '\0'; p
++)
8442 if (p
< limit
&& (p
- s
) <= (long) ELF_STRING_LIMIT
)
8444 if (bytes_in_chunk
> 0)
8451 default_elf_asm_output_limited_string (f
, s
);
8456 if (bytes_in_chunk
== 0)
8457 fputs (ASCII_DATA_ASM_OP
"\"", f
);
8460 escape
= ELF_ASCII_ESCAPES
[c
];
8469 putc ('0'+((c
>>6)&7), f
);
8470 putc ('0'+((c
>>3)&7), f
);
8471 putc ('0'+(c
&7), f
);
8472 bytes_in_chunk
+= 4;
8477 bytes_in_chunk
+= 2;
8484 if (bytes_in_chunk
> 0)
8492 static GTY(()) section
*elf_init_array_section
;
8493 static GTY(()) section
*elf_fini_array_section
;
8496 get_elf_initfini_array_priority_section (int priority
,
8500 if (priority
!= DEFAULT_INIT_PRIORITY
)
8503 sprintf (buf
, "%s.%.5u",
8504 constructor_p
? ".init_array" : ".fini_array",
8506 sec
= get_section (buf
, SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
8512 if (elf_init_array_section
== NULL
)
8513 elf_init_array_section
8514 = get_section (".init_array",
8515 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
8516 sec
= elf_init_array_section
;
8520 if (elf_fini_array_section
== NULL
)
8521 elf_fini_array_section
8522 = get_section (".fini_array",
8523 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
8524 sec
= elf_fini_array_section
;
8530 /* Use .init_array section for constructors. */
8533 default_elf_init_array_asm_out_constructor (rtx symbol
, int priority
)
8535 section
*sec
= get_elf_initfini_array_priority_section (priority
,
8537 assemble_addr_to_section (symbol
, sec
);
8540 /* Use .fini_array section for destructors. */
8543 default_elf_fini_array_asm_out_destructor (rtx symbol
, int priority
)
8545 section
*sec
= get_elf_initfini_array_priority_section (priority
,
8547 assemble_addr_to_section (symbol
, sec
);
8550 /* Default TARGET_ASM_OUTPUT_IDENT hook.
8552 This is a bit of a cheat. The real default is a no-op, but this
8553 hook is the default for all targets with a .ident directive. */
8556 default_asm_output_ident_directive (const char *ident_str
)
8558 const char *ident_asm_op
= "\t.ident\t";
8560 /* If we are still in the front end, do not write out the string
8561 to asm_out_file. Instead, add a fake top-level asm statement.
8562 This allows the front ends to use this hook without actually
8563 writing to asm_out_file, to handle #ident or Pragma Ident. */
8564 if (symtab
->state
== PARSING
)
8566 char *buf
= ACONCAT ((ident_asm_op
, "\"", ident_str
, "\"\n", NULL
));
8567 symtab
->finalize_toplevel_asm (build_string (strlen (buf
), buf
));
8570 fprintf (asm_out_file
, "%s\"%s\"\n", ident_asm_op
, ident_str
);
8573 /* Switch to a COMDAT section with COMDAT name of decl.
8575 FIXME: resolve_unique_section needs to deal better with
8576 decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
8577 that is fixed, this if-else statement can be replaced with
8578 a single call to "switch_to_section (sect)". */
8581 switch_to_comdat_section (section
*sect
, tree decl
)
8583 #if defined (OBJECT_FORMAT_ELF)
8584 targetm
.asm_out
.named_section (sect
->named
.name
,
8585 sect
->named
.common
.flags
8590 /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
8591 Therefore the following check is used.
8592 In case a the target is PE or COFF a comdat group section
8593 is created, e.g. .vtable_map_vars$foo. The linker places
8594 everything in .vtable_map_vars at the end.
8596 A fix could be made in
8597 gcc/config/i386/winnt.cc: i386_pe_unique_section. */
8602 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
8603 name
= ACONCAT ((sect
->named
.name
, "$",
8604 IDENTIFIER_POINTER (decl
), NULL
));
8606 name
= ACONCAT ((sect
->named
.name
, "$",
8607 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)),
8610 targetm
.asm_out
.named_section (name
,
8611 sect
->named
.common
.flags
8617 switch_to_section (sect
);
8621 /* This function ensures that vtable_map variables are not only
8622 in the comdat section, but that each variable has its own unique
8623 comdat name. Without this the variables end up in the same section
8624 with a single comdat name. */
8627 handle_vtv_comdat_section (section
*sect
, const_tree decl ATTRIBUTE_UNUSED
)
8629 switch_to_comdat_section(sect
, DECL_NAME (decl
));
8632 #include "gt-varasm.h"