1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987-2020 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"
52 #include "langhooks.h"
54 #include "common/common-target.h"
55 #include "stringpool.h"
59 #include "file-prefix-map.h" /* remap_debug_filename() */
60 #include "alloc-pool.h"
62 #ifdef XCOFF_DEBUGGING_INFO
63 #include "xcoffout.h" /* Needed for external data declarations. */
66 /* The (assembler) name of the first globally-visible object output. */
67 extern GTY(()) const char *first_global_object_name
;
68 extern GTY(()) const char *weak_global_object_name
;
70 const char *first_global_object_name
;
71 const char *weak_global_object_name
;
74 class constant_descriptor_rtx
;
75 struct rtx_constant_pool
;
77 #define n_deferred_constants (crtl->varasm.deferred_constants)
79 /* Number for making the label on the next
80 constant that is stored in memory. */
82 static GTY(()) int const_labelno
;
84 /* Carry information from ASM_DECLARE_OBJECT_NAME
85 to ASM_FINISH_DECLARE_OBJECT. */
87 int size_directive_output
;
89 /* The last decl for which assemble_variable was called,
90 if it did ASM_DECLARE_OBJECT_NAME.
91 If the last call to assemble_variable didn't do that,
94 tree last_assemble_variable_decl
;
96 /* The following global variable indicates if the first basic block
97 in a function belongs to the cold partition or not. */
99 bool first_function_block_is_cold
;
101 /* Whether we saw any functions with no_split_stack. */
103 static bool saw_no_split_stack
;
105 static const char *strip_reg_name (const char *);
106 static int contains_pointers_p (tree
);
107 #ifdef ASM_OUTPUT_EXTERNAL
108 static bool incorporeal_function_p (tree
);
110 static void decode_addr_const (tree
, class addr_const
*);
111 static hashval_t
const_hash_1 (const tree
);
112 static int compare_constant (const tree
, const tree
);
113 static void output_constant_def_contents (rtx
);
114 static void output_addressed_constants (tree
, int);
115 static unsigned HOST_WIDE_INT
output_constant (tree
, unsigned HOST_WIDE_INT
,
116 unsigned int, bool, bool);
117 static void globalize_decl (tree
);
118 static bool decl_readonly_section_1 (enum section_category
);
119 #ifdef BSS_SECTION_ASM_OP
120 #ifdef ASM_OUTPUT_ALIGNED_BSS
121 static void asm_output_aligned_bss (FILE *, tree
, const char *,
122 unsigned HOST_WIDE_INT
, int)
125 #endif /* BSS_SECTION_ASM_OP */
126 static void mark_weak (tree
);
127 static void output_constant_pool (const char *, tree
);
128 static void handle_vtv_comdat_section (section
*, const_tree
);
130 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
131 section
*text_section
;
132 section
*data_section
;
133 section
*readonly_data_section
;
134 section
*sdata_section
;
135 section
*ctors_section
;
136 section
*dtors_section
;
137 section
*bss_section
;
138 section
*sbss_section
;
140 /* Various forms of common section. All are guaranteed to be nonnull. */
141 section
*tls_comm_section
;
142 section
*comm_section
;
143 section
*lcomm_section
;
145 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
147 section
*bss_noswitch_section
;
149 /* The section that holds the main exception table, when known. The section
150 is set either by the target's init_sections hook or by the first call to
151 switch_to_exception_section. */
152 section
*exception_section
;
154 /* The section that holds the DWARF2 frame unwind information, when known.
155 The section is set either by the target's init_sections hook or by the
156 first call to switch_to_eh_frame_section. */
157 section
*eh_frame_section
;
159 /* asm_out_file's current section. This is NULL if no section has yet
160 been selected or if we lose track of what the current section is. */
163 /* True if code for the current function is currently being directed
164 at the cold section. */
165 bool in_cold_section_p
;
167 /* The following global holds the "function name" for the code in the
168 cold section of a function, if hot/cold function splitting is enabled
169 and there was actually code that went into the cold section. A
170 pseudo function name is needed for the cold section of code for some
171 debugging tools that perform symbolization. */
172 tree cold_function_name
= NULL_TREE
;
174 /* A linked list of all the unnamed sections. */
175 static GTY(()) section
*unnamed_sections
;
177 /* Return a nonzero value if DECL has a section attribute. */
178 #define IN_NAMED_SECTION(DECL) \
179 (VAR_OR_FUNCTION_DECL_P (DECL) && DECL_SECTION_NAME (DECL) != NULL)
181 struct section_hasher
: ggc_ptr_hash
<section
>
183 typedef const char *compare_type
;
185 static hashval_t
hash (section
*);
186 static bool equal (section
*, const char *);
189 /* Hash table of named sections. */
190 static GTY(()) hash_table
<section_hasher
> *section_htab
;
192 struct object_block_hasher
: ggc_ptr_hash
<object_block
>
194 typedef const section
*compare_type
;
196 static hashval_t
hash (object_block
*);
197 static bool equal (object_block
*, const section
*);
200 /* A table of object_blocks, indexed by section. */
201 static GTY(()) hash_table
<object_block_hasher
> *object_block_htab
;
203 /* The next number to use for internal anchor labels. */
204 static GTY(()) int anchor_labelno
;
206 /* A pool of constants that can be shared between functions. */
207 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
209 /* Helper routines for maintaining section_htab. */
212 section_hasher::equal (section
*old
, const char *new_name
)
214 return strcmp (old
->named
.name
, new_name
) == 0;
218 section_hasher::hash (section
*old
)
220 return htab_hash_string (old
->named
.name
);
223 /* Return a hash value for section SECT. */
226 hash_section (section
*sect
)
228 if (sect
->common
.flags
& SECTION_NAMED
)
229 return htab_hash_string (sect
->named
.name
);
230 return sect
->common
.flags
& ~SECTION_DECLARED
;
233 /* Helper routines for maintaining object_block_htab. */
236 object_block_hasher::equal (object_block
*old
, const section
*new_section
)
238 return old
->sect
== new_section
;
242 object_block_hasher::hash (object_block
*old
)
244 return hash_section (old
->sect
);
247 /* Return a new unnamed section with the given fields. */
250 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
255 sect
= ggc_alloc
<section
> ();
256 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
257 sect
->unnamed
.callback
= callback
;
258 sect
->unnamed
.data
= data
;
259 sect
->unnamed
.next
= unnamed_sections
;
261 unnamed_sections
= sect
;
265 /* Return a SECTION_NOSWITCH section with the given fields. */
268 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
272 sect
= ggc_alloc
<section
> ();
273 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
274 sect
->noswitch
.callback
= callback
;
279 /* Return the named section structure associated with NAME. Create
280 a new section with the given fields if no such structure exists. */
283 get_section (const char *name
, unsigned int flags
, tree decl
)
285 section
*sect
, **slot
;
287 slot
= section_htab
->find_slot_with_hash (name
, htab_hash_string (name
),
289 flags
|= SECTION_NAMED
;
292 sect
= ggc_alloc
<section
> ();
293 sect
->named
.common
.flags
= flags
;
294 sect
->named
.name
= ggc_strdup (name
);
295 sect
->named
.decl
= decl
;
301 /* It is fine if one of the sections has SECTION_NOTYPE as long as
302 the other has none of the contrary flags (see the logic at the end
303 of default_section_type_flags, below). */
304 if (((sect
->common
.flags
^ flags
) & SECTION_NOTYPE
)
305 && !((sect
->common
.flags
| flags
)
306 & (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
| SECTION_ENTSIZE
307 | (HAVE_COMDAT_GROUP
? SECTION_LINKONCE
: 0))))
309 sect
->common
.flags
|= SECTION_NOTYPE
;
310 flags
|= SECTION_NOTYPE
;
312 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
313 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
315 /* It is fine if one of the section flags is
316 SECTION_WRITE | SECTION_RELRO and the other has none of these
317 flags (i.e. read-only) in named sections and either the
318 section hasn't been declared yet or has been declared as writable.
319 In that case just make sure the resulting flags are
320 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
322 if (((sect
->common
.flags
^ flags
) & (SECTION_WRITE
| SECTION_RELRO
))
323 == (SECTION_WRITE
| SECTION_RELRO
)
324 && (sect
->common
.flags
325 & ~(SECTION_DECLARED
| SECTION_WRITE
| SECTION_RELRO
))
326 == (flags
& ~(SECTION_WRITE
| SECTION_RELRO
))
327 && ((sect
->common
.flags
& SECTION_DECLARED
) == 0
328 || (sect
->common
.flags
& SECTION_WRITE
)))
330 sect
->common
.flags
|= (SECTION_WRITE
| SECTION_RELRO
);
333 /* Sanity check user variables for flag changes. */
334 if (sect
->named
.decl
!= NULL
335 && DECL_P (sect
->named
.decl
)
336 && decl
!= sect
->named
.decl
)
338 if (decl
!= NULL
&& DECL_P (decl
))
339 error ("%+qD causes a section type conflict with %qD",
340 decl
, sect
->named
.decl
);
342 error ("section type conflict with %qD", sect
->named
.decl
);
343 inform (DECL_SOURCE_LOCATION (sect
->named
.decl
),
344 "%qD was declared here", sect
->named
.decl
);
346 else if (decl
!= NULL
&& DECL_P (decl
))
347 error ("%+qD causes a section type conflict", decl
);
349 error ("section type conflict");
350 /* Make sure we don't error about one section multiple times. */
351 sect
->common
.flags
|= SECTION_OVERRIDE
;
357 /* Return true if the current compilation mode benefits from having
358 objects grouped into blocks. */
361 use_object_blocks_p (void)
363 return flag_section_anchors
;
366 /* Return the object_block structure for section SECT. Create a new
367 structure if we haven't created one already. Return null if SECT
368 itself is null. Return also null for mergeable sections since
369 section anchors can't be used in mergeable sections anyway,
370 because the linker might move objects around, and using the
371 object blocks infrastructure in that case is both a waste and a
372 maintenance burden. */
374 static struct object_block
*
375 get_block_for_section (section
*sect
)
377 struct object_block
*block
;
382 if (sect
->common
.flags
& SECTION_MERGE
)
386 = object_block_htab
->find_slot_with_hash (sect
, hash_section (sect
),
391 block
= ggc_cleared_alloc
<object_block
> ();
398 /* Create a symbol with label LABEL and place it at byte offset
399 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
400 is not yet known. LABEL must be a garbage-collected string. */
403 create_block_symbol (const char *label
, struct object_block
*block
,
404 HOST_WIDE_INT offset
)
409 /* Create the extended SYMBOL_REF. */
410 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
411 symbol
= (rtx
) ggc_internal_alloc (size
);
413 /* Initialize the normal SYMBOL_REF fields. */
414 memset (symbol
, 0, size
);
415 PUT_CODE (symbol
, SYMBOL_REF
);
416 PUT_MODE (symbol
, Pmode
);
417 XSTR (symbol
, 0) = label
;
418 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
420 /* Initialize the block_symbol stuff. */
421 SYMBOL_REF_BLOCK (symbol
) = block
;
422 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
427 /* Return a section with a particular name and with whatever SECTION_*
428 flags section_type_flags deems appropriate. The name of the section
429 is taken from NAME if nonnull, otherwise it is taken from DECL's
430 DECL_SECTION_NAME. DECL is the decl associated with the section
431 (see the section comment for details) and RELOC is as for
432 section_type_flags. */
435 get_named_section (tree decl
, const char *name
, int reloc
)
441 gcc_assert (decl
&& DECL_P (decl
) && DECL_SECTION_NAME (decl
));
442 name
= DECL_SECTION_NAME (decl
);
445 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
446 return get_section (name
, flags
, decl
);
449 /* Worker for resolve_unique_section. */
452 set_implicit_section (struct symtab_node
*n
, void *data ATTRIBUTE_UNUSED
)
454 n
->implicit_section
= true;
458 /* If required, set DECL_SECTION_NAME to a unique name. */
461 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
462 int flag_function_or_data_sections
)
464 if (DECL_SECTION_NAME (decl
) == NULL
465 && targetm_common
.have_named_sections
466 && (flag_function_or_data_sections
467 || DECL_COMDAT_GROUP (decl
)))
469 targetm
.asm_out
.unique_section (decl
, reloc
);
470 if (DECL_SECTION_NAME (decl
))
471 symtab_node::get (decl
)->call_for_symbol_and_aliases
472 (set_implicit_section
, NULL
, true);
476 #ifdef BSS_SECTION_ASM_OP
478 #ifdef ASM_OUTPUT_ALIGNED_BSS
480 /* Utility function for targets to use in implementing
481 ASM_OUTPUT_ALIGNED_BSS.
482 ??? It is believed that this function will work in most cases so such
483 support is localized here. */
486 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
487 const char *name
, unsigned HOST_WIDE_INT size
,
490 switch_to_section (bss_section
);
491 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
492 #ifdef ASM_DECLARE_OBJECT_NAME
493 last_assemble_variable_decl
= decl
;
494 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
496 /* Standard thing is just output label for the object. */
497 ASM_OUTPUT_LABEL (file
, name
);
498 #endif /* ASM_DECLARE_OBJECT_NAME */
499 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
504 #endif /* BSS_SECTION_ASM_OP */
506 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
507 /* Return the hot section for function DECL. Return text_section for
511 hot_function_section (tree decl
)
513 if (decl
!= NULL_TREE
514 && DECL_SECTION_NAME (decl
) != NULL
515 && targetm_common
.have_named_sections
)
516 return get_named_section (decl
, NULL
, 0);
522 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
525 When DECL_SECTION_NAME is non-NULL and it is implicit section and
526 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
527 concatenate the name with NAMED_SECTION_SUFFIX.
528 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
531 get_named_text_section (tree decl
,
532 const char *text_section_name
,
533 const char *named_section_suffix
)
535 if (decl
&& DECL_SECTION_NAME (decl
))
537 if (named_section_suffix
)
539 const char *dsn
= DECL_SECTION_NAME (decl
);
540 const char *stripped_name
;
543 name
= (char *) alloca (strlen (dsn
) + 1);
547 stripped_name
= targetm
.strip_name_encoding (name
);
549 buffer
= ACONCAT ((stripped_name
, named_section_suffix
, NULL
));
550 return get_named_section (decl
, buffer
, 0);
552 else if (symtab_node::get (decl
)->implicit_section
)
556 /* Do not try to split gnu_linkonce functions. This gets somewhat
558 if (DECL_COMDAT_GROUP (decl
) && !HAVE_COMDAT_GROUP
)
560 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
561 name
= targetm
.strip_name_encoding (name
);
562 return get_named_section (decl
, ACONCAT ((text_section_name
, ".",
568 return get_named_section (decl
, text_section_name
, 0);
571 /* Choose named function section based on its frequency. */
574 default_function_section (tree decl
, enum node_frequency freq
,
575 bool startup
, bool exit
)
577 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
578 /* Old GNU linkers have buggy --gc-section support, which sometimes
579 results in .gcc_except_table* sections being garbage collected. */
581 && symtab_node::get (decl
)->implicit_section
)
585 if (!flag_reorder_functions
586 || !targetm_common
.have_named_sections
)
588 /* Startup code should go to startup subsection unless it is
589 unlikely executed (this happens especially with function splitting
590 where we can split away unnecessary parts of static constructors. */
591 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
593 /* During LTO the tp_first_run profiling will naturally place all
594 initialization code first. Using separate section is counter-productive
595 because startup only code may call functions which are no longer
598 || !cgraph_node::get (decl
)->tp_first_run
599 || !opt_for_fn (decl
, flag_profile_reorder_functions
))
600 return get_named_text_section (decl
, ".text.startup", NULL
);
605 /* Similarly for exit. */
606 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
607 return get_named_text_section (decl
, ".text.exit", NULL
);
609 /* Group cold functions together, similarly for hot code. */
612 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
613 return get_named_text_section (decl
, ".text.unlikely", NULL
);
614 case NODE_FREQUENCY_HOT
:
615 return get_named_text_section (decl
, ".text.hot", NULL
);
622 /* Return the section for function DECL.
624 If DECL is NULL_TREE, return the text section. We can be passed
625 NULL_TREE under some circumstances by dbxout.c at least.
627 If FORCE_COLD is true, return cold function section ignoring
628 the frequency info of cgraph_node. */
631 function_section_1 (tree decl
, bool force_cold
)
633 section
*section
= NULL
;
634 enum node_frequency freq
= NODE_FREQUENCY_NORMAL
;
635 bool startup
= false, exit
= false;
639 struct cgraph_node
*node
= cgraph_node::get (decl
);
643 freq
= node
->frequency
;
644 startup
= node
->only_called_at_startup
;
645 exit
= node
->only_called_at_exit
;
649 freq
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
651 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
652 if (decl
!= NULL_TREE
653 && DECL_SECTION_NAME (decl
) != NULL
)
655 if (targetm
.asm_out
.function_section
)
656 section
= targetm
.asm_out
.function_section (decl
, freq
,
660 return get_named_section (decl
, NULL
, 0);
663 return targetm
.asm_out
.select_section
664 (decl
, freq
== NODE_FREQUENCY_UNLIKELY_EXECUTED
,
665 symtab_node::get (decl
)->definition_alignment ());
667 if (targetm
.asm_out
.function_section
)
668 section
= targetm
.asm_out
.function_section (decl
, freq
, startup
, exit
);
671 return hot_function_section (decl
);
675 /* Return the section for function DECL.
677 If DECL is NULL_TREE, return the text section. We can be passed
678 NULL_TREE under some circumstances by dbxout.c at least. */
681 function_section (tree decl
)
683 /* Handle cases where function splitting code decides
684 to put function entry point into unlikely executed section
685 despite the fact that the function itself is not cold
686 (i.e. it is called rarely but contains a hot loop that is
687 better to live in hot subsection for the code locality). */
688 return function_section_1 (decl
,
689 first_function_block_is_cold
);
692 /* Return the section for the current function, take IN_COLD_SECTION_P
696 current_function_section (void)
698 return function_section_1 (current_function_decl
, in_cold_section_p
);
701 /* Tell assembler to switch to unlikely-to-be-executed text section. */
704 unlikely_text_section (void)
706 return function_section_1 (current_function_decl
, true);
709 /* When called within a function context, return true if the function
710 has been assigned a cold text section and if SECT is that section.
711 When called outside a function context, return true if SECT is the
712 default cold section. */
715 unlikely_text_section_p (section
*sect
)
717 return sect
== function_section_1 (current_function_decl
, true);
720 /* Switch to the other function partition (if inside of hot section
721 into cold section, otherwise into the hot section). */
724 switch_to_other_text_partition (void)
726 in_cold_section_p
= !in_cold_section_p
;
727 switch_to_section (current_function_section ());
730 /* Return the read-only data section associated with function DECL. */
733 default_function_rodata_section (tree decl
)
735 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
737 const char *name
= DECL_SECTION_NAME (decl
);
739 if (DECL_COMDAT_GROUP (decl
) && HAVE_COMDAT_GROUP
)
745 dot
= strchr (name
+ 1, '.');
748 len
= strlen (dot
) + 8;
749 rname
= (char *) alloca (len
);
751 strcpy (rname
, ".rodata");
753 return get_section (rname
, SECTION_LINKONCE
, decl
);
755 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
756 else if (DECL_COMDAT_GROUP (decl
)
757 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
759 size_t len
= strlen (name
) + 1;
760 char *rname
= (char *) alloca (len
);
762 memcpy (rname
, name
, len
);
764 return get_section (rname
, SECTION_LINKONCE
, decl
);
766 /* For .text.foo we want to use .rodata.foo. */
767 else if (flag_function_sections
&& flag_data_sections
768 && strncmp (name
, ".text.", 6) == 0)
770 size_t len
= strlen (name
) + 1;
771 char *rname
= (char *) alloca (len
+ 2);
773 memcpy (rname
, ".rodata", 7);
774 memcpy (rname
+ 7, name
+ 5, len
- 5);
775 return get_section (rname
, 0, decl
);
779 return readonly_data_section
;
782 /* Return the read-only data section associated with function DECL
783 for targets where that section should be always the single
784 readonly data section. */
787 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
789 return readonly_data_section
;
792 /* A subroutine of mergeable_string_section and mergeable_constant_section. */
795 function_mergeable_rodata_prefix (void)
797 section
*s
= targetm
.asm_out
.function_rodata_section (current_function_decl
);
798 if (SECTION_STYLE (s
) == SECTION_NAMED
)
799 return s
->named
.name
;
801 return targetm
.asm_out
.mergeable_rodata_prefix
;
804 /* Return the section to use for string merging. */
807 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
808 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
809 unsigned int flags ATTRIBUTE_UNUSED
)
813 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
814 && TREE_CODE (decl
) == STRING_CST
815 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
817 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
818 && TREE_STRING_LENGTH (decl
) == len
)
820 scalar_int_mode mode
;
821 unsigned int modesize
;
825 const char *prefix
= function_mergeable_rodata_prefix ();
826 char *name
= (char *) alloca (strlen (prefix
) + 30);
828 mode
= SCALAR_INT_TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
829 modesize
= GET_MODE_BITSIZE (mode
);
830 if (modesize
>= 8 && modesize
<= 256
831 && (modesize
& (modesize
- 1)) == 0)
833 if (align
< modesize
)
836 if (!HAVE_LD_ALIGNED_SHF_MERGE
&& align
> 8)
837 return readonly_data_section
;
839 str
= TREE_STRING_POINTER (decl
);
840 unit
= GET_MODE_SIZE (mode
);
842 /* Check for embedded NUL characters. */
843 for (i
= 0; i
< len
; i
+= unit
)
845 for (j
= 0; j
< unit
; j
++)
846 if (str
[i
+ j
] != '\0')
851 if (i
== len
- unit
|| (unit
== 1 && i
== len
))
853 sprintf (name
, "%s.str%d.%d", prefix
,
854 modesize
/ 8, (int) (align
/ 8));
855 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
856 return get_section (name
, flags
, NULL
);
861 return readonly_data_section
;
864 /* Return the section to use for constant merging. */
867 mergeable_constant_section (machine_mode mode ATTRIBUTE_UNUSED
,
868 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
869 unsigned int flags ATTRIBUTE_UNUSED
)
871 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
874 && known_le (GET_MODE_BITSIZE (mode
), align
)
877 && (align
& (align
- 1)) == 0
878 && (HAVE_LD_ALIGNED_SHF_MERGE
? 1 : align
== 8))
880 const char *prefix
= function_mergeable_rodata_prefix ();
881 char *name
= (char *) alloca (strlen (prefix
) + 30);
883 sprintf (name
, "%s.cst%d", prefix
, (int) (align
/ 8));
884 flags
|= (align
/ 8) | SECTION_MERGE
;
885 return get_section (name
, flags
, NULL
);
887 return readonly_data_section
;
890 /* Given NAME, a putative register name, discard any customary prefixes. */
893 strip_reg_name (const char *name
)
895 #ifdef REGISTER_PREFIX
896 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
897 name
+= strlen (REGISTER_PREFIX
);
899 if (name
[0] == '%' || name
[0] == '#')
904 /* The user has asked for a DECL to have a particular name. Set (or
905 change) it in such a way that we don't prefix an underscore to
908 set_user_assembler_name (tree decl
, const char *name
)
910 char *starred
= (char *) alloca (strlen (name
) + 2);
912 strcpy (starred
+ 1, name
);
913 symtab
->change_decl_assembler_name (decl
, get_identifier (starred
));
914 SET_DECL_RTL (decl
, NULL_RTX
);
917 /* Decode an `asm' spec for a declaration as a register name.
918 Return the register number, or -1 if nothing specified,
919 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
920 or -3 if ASMSPEC is `cc' and is not recognized,
921 or -4 if ASMSPEC is `memory' and is not recognized.
922 Accept an exact spelling or a decimal number.
923 Prefixes such as % are optional. */
926 decode_reg_name_and_count (const char *asmspec
, int *pnregs
)
928 /* Presume just one register is clobbered. */
935 /* Get rid of confusing prefixes. */
936 asmspec
= strip_reg_name (asmspec
);
938 /* Allow a decimal number as a "register name". */
939 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
940 if (! ISDIGIT (asmspec
[i
]))
942 if (asmspec
[0] != 0 && i
< 0)
945 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0 && reg_names
[i
][0])
951 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
953 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
956 #ifdef OVERLAPPING_REGISTER_NAMES
960 const char *const name
;
963 } table
[] = OVERLAPPING_REGISTER_NAMES
;
965 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
967 && ! strcmp (asmspec
, table
[i
].name
))
969 *pnregs
= table
[i
].nregs
;
970 return table
[i
].number
;
973 #endif /* OVERLAPPING_REGISTER_NAMES */
975 #ifdef ADDITIONAL_REGISTER_NAMES
977 static const struct { const char *const name
; const int number
; } table
[]
978 = ADDITIONAL_REGISTER_NAMES
;
980 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
982 && ! strcmp (asmspec
, table
[i
].name
)
983 && reg_names
[table
[i
].number
][0])
984 return table
[i
].number
;
986 #endif /* ADDITIONAL_REGISTER_NAMES */
988 if (!strcmp (asmspec
, "memory"))
991 if (!strcmp (asmspec
, "cc"))
1001 decode_reg_name (const char *name
)
1004 return decode_reg_name_and_count (name
, &count
);
1008 /* Return true if DECL's initializer is suitable for a BSS section. */
1011 bss_initializer_p (const_tree decl
, bool named
)
1013 /* Do not put non-common constants into the .bss section, they belong in
1014 a readonly section, except when NAMED is true. */
1015 return ((!TREE_READONLY (decl
) || DECL_COMMON (decl
) || named
)
1016 && (DECL_INITIAL (decl
) == NULL
1017 /* In LTO we have no errors in program; error_mark_node is used
1018 to mark offlined constructors. */
1019 || (DECL_INITIAL (decl
) == error_mark_node
1021 || (flag_zero_initialized_in_bss
1022 && initializer_zerop (DECL_INITIAL (decl
)))));
1025 /* Compute the alignment of variable specified by DECL.
1026 DONT_OUTPUT_DATA is from assemble_variable. */
1029 align_variable (tree decl
, bool dont_output_data
)
1031 unsigned int align
= DECL_ALIGN (decl
);
1033 /* In the case for initialing an array whose length isn't specified,
1034 where we have not yet been able to do the layout,
1035 figure out the proper alignment now. */
1036 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1037 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1038 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1040 /* Some object file formats have a maximum alignment which they support.
1041 In particular, a.out format supports a maximum alignment of 4. */
1042 if (align
> MAX_OFILE_ALIGNMENT
)
1044 error ("alignment of %q+D is greater than maximum object "
1045 "file alignment %d", decl
,
1046 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1047 align
= MAX_OFILE_ALIGNMENT
;
1050 if (! DECL_USER_ALIGN (decl
))
1052 #ifdef DATA_ABI_ALIGNMENT
1053 unsigned int data_abi_align
1054 = DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1055 /* For backwards compatibility, don't assume the ABI alignment for
1057 if (! DECL_THREAD_LOCAL_P (decl
) || data_abi_align
<= BITS_PER_WORD
)
1058 align
= data_abi_align
;
1061 /* On some machines, it is good to increase alignment sometimes.
1062 But as DECL_ALIGN is used both for actually emitting the variable
1063 and for code accessing the variable as guaranteed alignment, we
1064 can only increase the alignment if it is a performance optimization
1065 if the references to it must bind to the current definition. */
1066 if (decl_binds_to_current_def_p (decl
)
1067 && !DECL_VIRTUAL_P (decl
))
1069 #ifdef DATA_ALIGNMENT
1070 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1071 /* Don't increase alignment too much for TLS variables - TLS space
1073 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1076 if (DECL_INITIAL (decl
) != 0
1077 /* In LTO we have no errors in program; error_mark_node is used
1078 to mark offlined constructors. */
1079 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1081 unsigned int const_align
1082 = targetm
.constant_alignment (DECL_INITIAL (decl
), align
);
1083 /* Don't increase alignment too much for TLS variables - TLS
1084 space is too precious. */
1085 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1086 align
= const_align
;
1091 /* Reset the alignment in case we have made it tighter, so we can benefit
1092 from it in get_pointer_alignment. */
1093 SET_DECL_ALIGN (decl
, align
);
1096 /* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1097 beyond what align_variable returned. */
1100 get_variable_align (tree decl
)
1102 unsigned int align
= DECL_ALIGN (decl
);
1104 /* For user aligned vars or static vars align_variable already did
1106 if (DECL_USER_ALIGN (decl
) || !TREE_PUBLIC (decl
))
1109 #ifdef DATA_ABI_ALIGNMENT
1110 if (DECL_THREAD_LOCAL_P (decl
))
1111 align
= DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1114 /* For decls that bind to the current definition, align_variable
1115 did also everything, except for not assuming ABI required alignment
1116 of TLS variables. For other vars, increase the alignment here
1117 as an optimization. */
1118 if (!decl_binds_to_current_def_p (decl
))
1120 /* On some machines, it is good to increase alignment sometimes. */
1121 #ifdef DATA_ALIGNMENT
1122 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1123 /* Don't increase alignment too much for TLS variables - TLS space
1125 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1128 if (DECL_INITIAL (decl
) != 0
1129 /* In LTO we have no errors in program; error_mark_node is used
1130 to mark offlined constructors. */
1131 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1133 unsigned int const_align
1134 = targetm
.constant_alignment (DECL_INITIAL (decl
), align
);
1135 /* Don't increase alignment too much for TLS variables - TLS space
1137 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1138 align
= const_align
;
1145 /* Return the section into which the given VAR_DECL or CONST_DECL
1146 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1147 section should be used wherever possible. */
1150 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1152 addr_space_t as
= ADDR_SPACE_GENERIC
;
1154 varpool_node
*vnode
= varpool_node::get (decl
);
1157 vnode
= vnode
->ultimate_alias_target ();
1161 if (TREE_TYPE (decl
) != error_mark_node
)
1162 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1164 /* We need the constructor to figure out reloc flag. */
1166 vnode
->get_constructor ();
1168 if (DECL_COMMON (decl
))
1170 /* If the decl has been given an explicit section name, or it resides
1171 in a non-generic address space, then it isn't common, and shouldn't
1172 be handled as such. */
1173 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1174 && ADDR_SPACE_GENERIC_P (as
));
1175 if (DECL_THREAD_LOCAL_P (decl
))
1176 return tls_comm_section
;
1177 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1178 return comm_section
;
1181 if (DECL_INITIAL (decl
) == error_mark_node
)
1182 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1183 else if (DECL_INITIAL (decl
))
1184 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1188 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1189 if (IN_NAMED_SECTION (decl
))
1191 section
*sect
= get_named_section (decl
, NULL
, reloc
);
1193 if ((sect
->common
.flags
& SECTION_BSS
)
1194 && !bss_initializer_p (decl
, true))
1196 error_at (DECL_SOURCE_LOCATION (decl
),
1197 "only zero initializers are allowed in section %qs",
1199 DECL_INITIAL (decl
) = error_mark_node
;
1204 if (ADDR_SPACE_GENERIC_P (as
)
1205 && !DECL_THREAD_LOCAL_P (decl
)
1206 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1207 && bss_initializer_p (decl
))
1209 if (!TREE_PUBLIC (decl
)
1210 && !((flag_sanitize
& SANITIZE_ADDRESS
)
1211 && asan_protect_global (decl
)))
1212 return lcomm_section
;
1213 if (bss_noswitch_section
)
1214 return bss_noswitch_section
;
1217 return targetm
.asm_out
.select_section (decl
, reloc
,
1218 get_variable_align (decl
));
1221 /* Return the block into which object_block DECL should be placed. */
1223 static struct object_block
*
1224 get_block_for_decl (tree decl
)
1230 /* The object must be defined in this translation unit. */
1231 if (DECL_EXTERNAL (decl
))
1234 /* There's no point using object blocks for something that is
1235 isolated by definition. */
1236 if (DECL_COMDAT_GROUP (decl
))
1240 /* We can only calculate block offsets if the decl has a known
1242 if (DECL_SIZE_UNIT (decl
) == NULL
)
1244 if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl
)))
1247 /* Find out which section should contain DECL. We cannot put it into
1248 an object block if it requires a standalone definition. */
1250 align_variable (decl
, 0);
1251 sect
= get_variable_section (decl
, true);
1252 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1255 return get_block_for_section (sect
);
1258 /* Make sure block symbol SYMBOL is in block BLOCK. */
1261 change_symbol_block (rtx symbol
, struct object_block
*block
)
1263 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1265 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1266 SYMBOL_REF_BLOCK (symbol
) = block
;
1270 /* Return true if it is possible to put DECL in an object_block. */
1273 use_blocks_for_decl_p (tree decl
)
1275 struct symtab_node
*snode
;
1277 /* Only data DECLs can be placed into object blocks. */
1278 if (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
1281 /* DECL_INITIAL (decl) set to decl is a hack used for some decls that
1282 are never used from code directly and we never want object block handling
1284 if (DECL_INITIAL (decl
) == decl
)
1287 /* If this decl is an alias, then we don't want to emit a
1290 && (snode
= symtab_node::get (decl
)) != NULL
1294 return targetm
.use_blocks_for_decl_p (decl
);
1297 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1298 until we find an identifier that is not itself a transparent alias.
1299 Modify the alias passed to it by reference (and all aliases on the
1300 way to the ultimate target), such that they do not have to be
1301 followed again, and return the ultimate target of the alias
1305 ultimate_transparent_alias_target (tree
*alias
)
1307 tree target
= *alias
;
1309 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
1311 gcc_assert (TREE_CHAIN (target
));
1312 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
1313 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
1314 && ! TREE_CHAIN (target
));
1321 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1322 have static storage duration. In other words, it should not be an
1323 automatic variable, including PARM_DECLs.
1325 There is, however, one exception: this function handles variables
1326 explicitly placed in a particular register by the user.
1328 This is never called for PARM_DECL nodes. */
1331 make_decl_rtl (tree decl
)
1333 const char *name
= 0;
1338 /* Check that we are not being given an automatic variable. */
1339 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1340 && TREE_CODE (decl
) != RESULT_DECL
);
1342 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1343 gcc_assert (!VAR_P (decl
)
1344 || TREE_STATIC (decl
)
1345 || TREE_PUBLIC (decl
)
1346 || DECL_EXTERNAL (decl
)
1347 || DECL_REGISTER (decl
));
1349 /* And that we were not given a type or a label. */
1350 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1351 && TREE_CODE (decl
) != LABEL_DECL
);
1353 /* For a duplicate declaration, we can be called twice on the
1354 same DECL node. Don't discard the RTL already made. */
1355 if (DECL_RTL_SET_P (decl
))
1357 /* If the old RTL had the wrong mode, fix the mode. */
1358 x
= DECL_RTL (decl
);
1359 if (GET_MODE (x
) != DECL_MODE (decl
))
1360 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1362 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1365 /* ??? Another way to do this would be to maintain a hashed
1366 table of such critters. Instead of adding stuff to a DECL
1367 to give certain attributes to it, we could use an external
1368 hash map from DECL to set of attributes. */
1370 /* Let the target reassign the RTL if it wants.
1371 This is necessary, for example, when one machine specific
1372 decl attribute overrides another. */
1373 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1375 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1376 on the new decl information. */
1378 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1379 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1380 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1385 /* If this variable belongs to the global constant pool, retrieve the
1386 pre-computed RTL or recompute it in LTO mode. */
1387 if (VAR_P (decl
) && DECL_IN_CONSTANT_POOL (decl
))
1389 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1393 id
= DECL_ASSEMBLER_NAME (decl
);
1394 name
= IDENTIFIER_POINTER (id
);
1396 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1397 && DECL_REGISTER (decl
))
1399 error ("register name not specified for %q+D", decl
);
1401 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1403 const char *asmspec
= name
+1;
1404 machine_mode mode
= DECL_MODE (decl
);
1405 reg_number
= decode_reg_name (asmspec
);
1406 /* First detect errors in declaring global registers. */
1407 if (reg_number
== -1)
1408 error ("register name not specified for %q+D", decl
);
1409 else if (reg_number
< 0)
1410 error ("invalid register name for %q+D", decl
);
1411 else if (mode
== BLKmode
)
1412 error ("data type of %q+D isn%'t suitable for a register",
1414 else if (!in_hard_reg_set_p (accessible_reg_set
, mode
, reg_number
))
1415 error ("the register specified for %q+D cannot be accessed"
1416 " by the current target", decl
);
1417 else if (!in_hard_reg_set_p (operand_reg_set
, mode
, reg_number
))
1418 error ("the register specified for %q+D is not general enough"
1419 " to be used as a register variable", decl
);
1420 else if (!targetm
.hard_regno_mode_ok (reg_number
, mode
))
1421 error ("register specified for %q+D isn%'t suitable for data type",
1423 /* Now handle properly declared static register variables. */
1428 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1430 DECL_INITIAL (decl
) = 0;
1431 error ("global register variable has initial value");
1433 if (TREE_THIS_VOLATILE (decl
))
1434 warning (OPT_Wvolatile_register_var
,
1435 "optimization may eliminate reads and/or "
1436 "writes to register variables");
1438 /* If the user specified one of the eliminables registers here,
1439 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1440 confused with that register and be eliminated. This usage is
1441 somewhat suspect... */
1443 SET_DECL_RTL (decl
, gen_raw_REG (mode
, reg_number
));
1444 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1445 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1447 if (TREE_STATIC (decl
))
1449 /* Make this register global, so not usable for anything
1451 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1452 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1453 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1455 nregs
= hard_regno_nregs (reg_number
, mode
);
1457 globalize_reg (decl
, reg_number
+ --nregs
);
1460 /* As a register variable, it has no section. */
1463 /* Avoid internal errors from invalid register
1465 SET_DECL_ASSEMBLER_NAME (decl
, NULL_TREE
);
1466 DECL_HARD_REGISTER (decl
) = 0;
1467 /* Also avoid SSA inconsistencies by pretending this is an external
1469 DECL_EXTERNAL (decl
) = 1;
1472 /* Now handle ordinary static variables and functions (in memory).
1473 Also handle vars declared register invalidly. */
1474 else if (name
[0] == '*')
1476 #ifdef REGISTER_PREFIX
1477 if (strlen (REGISTER_PREFIX
) != 0)
1479 reg_number
= decode_reg_name (name
);
1480 if (reg_number
>= 0 || reg_number
== -3)
1481 error ("register name given for non-register variable %q+D", decl
);
1486 /* Specifying a section attribute on a variable forces it into a
1487 non-.bss section, and thus it cannot be common. */
1488 /* FIXME: In general this code should not be necessary because
1489 visibility pass is doing the same work. But notice_global_symbol
1490 is called early and it needs to make DECL_RTL to get the name.
1491 we take care of recomputing the DECL_RTL after visibility is changed. */
1493 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
1494 && DECL_SECTION_NAME (decl
) != NULL
1495 && DECL_INITIAL (decl
) == NULL_TREE
1496 && DECL_COMMON (decl
))
1497 DECL_COMMON (decl
) = 0;
1499 /* Variables can't be both common and weak. */
1500 if (VAR_P (decl
) && DECL_WEAK (decl
))
1501 DECL_COMMON (decl
) = 0;
1503 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1504 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1507 machine_mode address_mode
= Pmode
;
1508 if (TREE_TYPE (decl
) != error_mark_node
)
1510 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1511 address_mode
= targetm
.addr_space
.address_mode (as
);
1513 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1515 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1516 SET_SYMBOL_REF_DECL (x
, decl
);
1518 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1519 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1520 set_mem_attributes (x
, decl
, 1);
1521 SET_DECL_RTL (decl
, x
);
1523 /* Optionally set flags or add text to the name to record information
1524 such as that it is a function name.
1525 If the name is changed, the macro ASM_OUTPUT_LABELREF
1526 will have to know how to strip this information. */
1527 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1530 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1531 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1535 make_decl_rtl_for_debug (tree decl
)
1537 unsigned int save_aliasing_flag
;
1540 if (DECL_RTL_SET_P (decl
))
1541 return DECL_RTL (decl
);
1543 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1544 call new_alias_set. If running with -fcompare-debug, sometimes
1545 we do not want to create alias sets that will throw the alias
1546 numbers off in the comparison dumps. So... clearing
1547 flag_strict_aliasing will keep new_alias_set() from creating a
1549 save_aliasing_flag
= flag_strict_aliasing
;
1550 flag_strict_aliasing
= 0;
1552 rtl
= DECL_RTL (decl
);
1553 /* Reset DECL_RTL back, as various parts of the compiler expects
1554 DECL_RTL set meaning it is actually going to be output. */
1555 SET_DECL_RTL (decl
, NULL
);
1557 flag_strict_aliasing
= save_aliasing_flag
;
1561 /* Output a string of literal assembler code
1562 for an `asm' keyword used between functions. */
1565 assemble_asm (tree string
)
1570 if (TREE_CODE (string
) == ADDR_EXPR
)
1571 string
= TREE_OPERAND (string
, 0);
1573 p
= TREE_STRING_POINTER (string
);
1574 fprintf (asm_out_file
, "%s%s\n", p
[0] == '\t' ? "" : "\t", p
);
1577 /* Write the address of the entity given by SYMBOL to SEC. */
1579 assemble_addr_to_section (rtx symbol
, section
*sec
)
1581 switch_to_section (sec
);
1582 assemble_align (POINTER_SIZE
);
1583 assemble_integer (symbol
, POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
1586 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1587 not) section for PRIORITY. */
1589 get_cdtor_priority_section (int priority
, bool constructor_p
)
1591 /* Buffer conservatively large enough for the full range of a 32-bit
1592 int plus the text below. */
1595 /* ??? This only works reliably with the GNU linker. */
1596 sprintf (buf
, "%s.%.5u",
1597 constructor_p
? ".ctors" : ".dtors",
1598 /* Invert the numbering so the linker puts us in the proper
1599 order; constructors are run from right to left, and the
1600 linker sorts in increasing order. */
1601 MAX_INIT_PRIORITY
- priority
);
1602 return get_section (buf
, SECTION_WRITE
, NULL
);
1606 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1610 if (priority
!= DEFAULT_INIT_PRIORITY
)
1611 sec
= get_cdtor_priority_section (priority
,
1612 /*constructor_p=*/false);
1614 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1616 assemble_addr_to_section (symbol
, sec
);
1619 #ifdef DTORS_SECTION_ASM_OP
1621 default_dtor_section_asm_out_destructor (rtx symbol
,
1622 int priority ATTRIBUTE_UNUSED
)
1624 assemble_addr_to_section (symbol
, dtors_section
);
1629 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1633 if (priority
!= DEFAULT_INIT_PRIORITY
)
1634 sec
= get_cdtor_priority_section (priority
,
1635 /*constructor_p=*/true);
1637 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1639 assemble_addr_to_section (symbol
, sec
);
1642 #ifdef CTORS_SECTION_ASM_OP
1644 default_ctor_section_asm_out_constructor (rtx symbol
,
1645 int priority ATTRIBUTE_UNUSED
)
1647 assemble_addr_to_section (symbol
, ctors_section
);
1651 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1652 a nonzero value if the constant pool should be output before the
1653 start of the function, or a zero value if the pool should output
1654 after the end of the function. The default is to put it before the
1657 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1658 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1661 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1662 to be output to assembler.
1663 Set first_global_object_name and weak_global_object_name as appropriate. */
1666 notice_global_symbol (tree decl
)
1668 const char **t
= &first_global_object_name
;
1670 if (first_global_object_name
1671 || !TREE_PUBLIC (decl
)
1672 || DECL_EXTERNAL (decl
)
1673 || !DECL_NAME (decl
)
1674 || (VAR_P (decl
) && DECL_HARD_REGISTER (decl
))
1675 || (TREE_CODE (decl
) != FUNCTION_DECL
1677 || (DECL_COMMON (decl
)
1678 && (DECL_INITIAL (decl
) == 0
1679 || DECL_INITIAL (decl
) == error_mark_node
)))))
1682 /* We win when global object is found, but it is useful to know about weak
1683 symbol as well so we can produce nicer unique names. */
1684 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1685 t
= &weak_global_object_name
;
1689 tree id
= DECL_ASSEMBLER_NAME (decl
);
1690 ultimate_transparent_alias_target (&id
);
1691 *t
= ggc_strdup (targetm
.strip_name_encoding (IDENTIFIER_POINTER (id
)));
1695 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1696 current function goes into the cold section, so that targets can use
1697 current_function_section during RTL expansion. DECL describes the
1701 decide_function_section (tree decl
)
1703 first_function_block_is_cold
= false;
1705 if (DECL_SECTION_NAME (decl
))
1707 struct cgraph_node
*node
= cgraph_node::get (current_function_decl
);
1708 /* Calls to function_section rely on first_function_block_is_cold
1710 first_function_block_is_cold
= (node
1712 == NODE_FREQUENCY_UNLIKELY_EXECUTED
);
1715 in_cold_section_p
= first_function_block_is_cold
;
1718 /* Get the function's name, as described by its RTL. This may be
1719 different from the DECL_NAME name used in the source file. */
1721 get_fnname_from_decl (tree decl
)
1723 rtx x
= DECL_RTL (decl
);
1724 gcc_assert (MEM_P (x
));
1726 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
1730 /* Output assembler code for the constant pool of a function and associated
1731 with defining the name of the function. DECL describes the function.
1732 NAME is the function's name. For the constant pool, we use the current
1733 constant pool data. */
1736 assemble_start_function (tree decl
, const char *fnname
)
1739 char tmp_label
[100];
1740 bool hot_label_written
= false;
1742 if (crtl
->has_bb_partition
)
1744 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1745 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1746 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1747 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1748 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1749 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1750 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1751 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1753 cold_function_name
= NULL_TREE
;
1757 crtl
->subsections
.hot_section_label
= NULL
;
1758 crtl
->subsections
.cold_section_label
= NULL
;
1759 crtl
->subsections
.hot_section_end_label
= NULL
;
1760 crtl
->subsections
.cold_section_end_label
= NULL
;
1763 /* The following code does not need preprocessing in the assembler. */
1767 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1768 output_constant_pool (fnname
, decl
);
1770 align
= symtab_node::get (decl
)->definition_alignment ();
1772 /* Make sure the not and cold text (code) sections are properly
1773 aligned. This is necessary here in the case where the function
1774 has both hot and cold sections, because we don't want to re-set
1775 the alignment when the section switch happens mid-function. */
1777 if (crtl
->has_bb_partition
)
1779 first_function_block_is_cold
= false;
1781 switch_to_section (unlikely_text_section ());
1782 assemble_align (align
);
1783 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1785 /* When the function starts with a cold section, we need to explicitly
1786 align the hot section and write out the hot section label.
1787 But if the current function is a thunk, we do not have a CFG. */
1789 && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun
)->next_bb
) == BB_COLD_PARTITION
)
1791 switch_to_section (text_section
);
1792 assemble_align (align
);
1793 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1794 hot_label_written
= true;
1795 first_function_block_is_cold
= true;
1797 in_cold_section_p
= first_function_block_is_cold
;
1801 /* Switch to the correct text section for the start of the function. */
1803 switch_to_section (function_section (decl
));
1804 if (crtl
->has_bb_partition
&& !hot_label_written
)
1805 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1807 /* Tell assembler to move to target machine's alignment for functions. */
1808 align
= floor_log2 (align
/ BITS_PER_UNIT
);
1811 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1814 /* Handle a user-specified function alignment.
1815 Note that we still need to align to DECL_ALIGN, as above,
1816 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1817 if (! DECL_USER_ALIGN (decl
)
1818 && align_functions
.levels
[0].log
> align
1819 && optimize_function_for_speed_p (cfun
))
1821 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1822 int align_log
= align_functions
.levels
[0].log
;
1824 int max_skip
= align_functions
.levels
[0].maxskip
;
1825 if (flag_limit_function_alignment
&& crtl
->max_insn_address
> 0
1826 && max_skip
>= crtl
->max_insn_address
)
1827 max_skip
= crtl
->max_insn_address
- 1;
1829 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1830 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
, align_log
, max_skip
);
1831 if (max_skip
== align_functions
.levels
[0].maxskip
)
1832 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1833 align_functions
.levels
[1].log
,
1834 align_functions
.levels
[1].maxskip
);
1836 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions
.levels
[0].log
);
1840 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1841 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1844 if (!DECL_IGNORED_P (decl
))
1845 (*debug_hooks
->begin_function
) (decl
);
1847 /* Make function name accessible from other files, if appropriate. */
1849 if (TREE_PUBLIC (decl
))
1851 notice_global_symbol (decl
);
1853 globalize_decl (decl
);
1855 maybe_assemble_visibility (decl
);
1858 if (DECL_PRESERVE_P (decl
))
1859 targetm
.asm_out
.mark_decl_preserved (fnname
);
1861 unsigned short patch_area_size
= crtl
->patch_area_size
;
1862 unsigned short patch_area_entry
= crtl
->patch_area_entry
;
1864 /* Emit the patching area before the entry label, if any. */
1865 if (patch_area_entry
> 0)
1866 targetm
.asm_out
.print_patchable_function_entry (asm_out_file
,
1867 patch_area_entry
, true);
1869 /* Do any machine/system dependent processing of the function name. */
1870 #ifdef ASM_DECLARE_FUNCTION_NAME
1871 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1873 /* Standard thing is just output label for the function. */
1874 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1875 #endif /* ASM_DECLARE_FUNCTION_NAME */
1877 /* And the area after the label. Record it if we haven't done so yet. */
1878 if (patch_area_size
> patch_area_entry
)
1879 targetm
.asm_out
.print_patchable_function_entry (asm_out_file
,
1882 patch_area_entry
== 0);
1884 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1885 saw_no_split_stack
= true;
1888 /* Output assembler code associated with defining the size of the
1889 function. DECL describes the function. NAME is the function's name. */
1892 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1894 #ifdef ASM_DECLARE_FUNCTION_SIZE
1895 /* We could have switched section in the middle of the function. */
1896 if (crtl
->has_bb_partition
)
1897 switch_to_section (function_section (decl
));
1898 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1900 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1902 output_constant_pool (fnname
, decl
);
1903 switch_to_section (function_section (decl
)); /* need to switch back */
1905 /* Output labels for end of hot/cold text sections (to be used by
1907 if (crtl
->has_bb_partition
)
1909 section
*save_text_section
;
1911 save_text_section
= in_section
;
1912 switch_to_section (unlikely_text_section ());
1913 #ifdef ASM_DECLARE_COLD_FUNCTION_SIZE
1914 if (cold_function_name
!= NULL_TREE
)
1915 ASM_DECLARE_COLD_FUNCTION_SIZE (asm_out_file
,
1916 IDENTIFIER_POINTER (cold_function_name
),
1919 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1920 if (first_function_block_is_cold
)
1921 switch_to_section (text_section
);
1923 switch_to_section (function_section (decl
));
1924 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1925 switch_to_section (save_text_section
);
1929 /* Assemble code to leave SIZE bytes of zeros. */
1932 assemble_zeros (unsigned HOST_WIDE_INT size
)
1934 /* Do no output if -fsyntax-only. */
1935 if (flag_syntax_only
)
1938 #ifdef ASM_NO_SKIP_IN_TEXT
1939 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1940 so we must output 0s explicitly in the text section. */
1941 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1943 unsigned HOST_WIDE_INT i
;
1944 for (i
= 0; i
< size
; i
++)
1945 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1950 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1953 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1956 assemble_align (unsigned int align
)
1958 if (align
> BITS_PER_UNIT
)
1960 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1964 /* Assemble a string constant with the specified C string as contents. */
1967 assemble_string (const char *p
, int size
)
1972 /* If the string is very long, split it up. */
1976 int thissize
= size
- pos
;
1977 if (thissize
> maximum
)
1980 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1988 /* A noswitch_section_callback for lcomm_section. */
1991 emit_local (tree decl ATTRIBUTE_UNUSED
,
1992 const char *name ATTRIBUTE_UNUSED
,
1993 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1994 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1996 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1997 unsigned int align
= symtab_node::get (decl
)->definition_alignment ();
1998 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
2001 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
2002 unsigned int align
= symtab_node::get (decl
)->definition_alignment ();
2003 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, align
);
2006 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2011 /* A noswitch_section_callback for bss_noswitch_section. */
2013 #if defined ASM_OUTPUT_ALIGNED_BSS
2015 emit_bss (tree decl ATTRIBUTE_UNUSED
,
2016 const char *name ATTRIBUTE_UNUSED
,
2017 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2018 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2020 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
,
2021 get_variable_align (decl
));
2026 /* A noswitch_section_callback for comm_section. */
2029 emit_common (tree decl ATTRIBUTE_UNUSED
,
2030 const char *name ATTRIBUTE_UNUSED
,
2031 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2032 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2034 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
2035 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
2036 size
, get_variable_align (decl
));
2038 #elif defined ASM_OUTPUT_ALIGNED_COMMON
2039 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
2040 get_variable_align (decl
));
2043 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
2048 /* A noswitch_section_callback for tls_comm_section. */
2051 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
2052 const char *name ATTRIBUTE_UNUSED
,
2053 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2054 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2056 #ifdef ASM_OUTPUT_TLS_COMMON
2057 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
2060 sorry ("thread-local COMMON data not implemented");
2065 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2066 NAME is the name of DECL's SYMBOL_REF. */
2069 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
,
2072 unsigned HOST_WIDE_INT size
, rounded
;
2074 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2077 if ((flag_sanitize
& SANITIZE_ADDRESS
) && asan_protect_global (decl
))
2078 size
+= asan_red_zone_size (size
);
2080 /* Don't allocate zero bytes of common,
2081 since that means "undefined external" in the linker. */
2085 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2086 so that each uninitialized object starts on such a boundary. */
2087 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
2088 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2089 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2091 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
2092 && (unsigned HOST_WIDE_INT
) (align
/ BITS_PER_UNIT
) > rounded
)
2093 error ("requested alignment for %q+D is greater than "
2094 "implemented alignment of %wu", decl
, rounded
);
2097 /* A subroutine of assemble_variable. Output the label and contents of
2098 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2099 is as for assemble_variable. */
2102 assemble_variable_contents (tree decl
, const char *name
,
2103 bool dont_output_data
, bool merge_strings
)
2105 /* Do any machine/system dependent processing of the object. */
2106 #ifdef ASM_DECLARE_OBJECT_NAME
2107 last_assemble_variable_decl
= decl
;
2108 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
2110 /* Standard thing is just output label for the object. */
2111 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2112 #endif /* ASM_DECLARE_OBJECT_NAME */
2114 if (!dont_output_data
)
2116 /* Caller is supposed to use varpool_get_constructor when it wants
2117 to output the body. */
2118 gcc_assert (!in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
);
2119 if (DECL_INITIAL (decl
)
2120 && DECL_INITIAL (decl
) != error_mark_node
2121 && !initializer_zerop (DECL_INITIAL (decl
)))
2122 /* Output the actual data. */
2123 output_constant (DECL_INITIAL (decl
),
2124 tree_to_uhwi (DECL_SIZE_UNIT (decl
)),
2125 get_variable_align (decl
),
2126 false, merge_strings
);
2128 /* Leave space for it. */
2129 assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl
)));
2130 targetm
.asm_out
.decl_end ();
2134 /* Write out assembly for the variable DECL, which is not defined in
2135 the current translation unit. */
2137 assemble_undefined_decl (tree decl
)
2139 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
2140 targetm
.asm_out
.assemble_undefined_decl (asm_out_file
, name
, decl
);
2143 /* Assemble everything that is needed for a variable or function declaration.
2144 Not used for automatic variables, and not used for function definitions.
2145 Should not be called for variables of incomplete structure type.
2147 TOP_LEVEL is nonzero if this variable has file scope.
2148 AT_END is nonzero if this is the special handling, at end of compilation,
2149 to define things that have had only tentative definitions.
2150 DONT_OUTPUT_DATA if nonzero means don't actually output the
2151 initial value (that will be done by the caller). */
2154 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
2155 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
2158 rtx decl_rtl
, symbol
;
2161 bool asan_protected
= false;
2163 /* This function is supposed to handle VARIABLES. Ensure we have one. */
2164 gcc_assert (VAR_P (decl
));
2166 /* Emulated TLS had better not get this far. */
2167 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
2169 last_assemble_variable_decl
= 0;
2171 /* Normally no need to say anything here for external references,
2172 since assemble_external is called by the language-specific code
2173 when a declaration is first seen. */
2175 if (DECL_EXTERNAL (decl
))
2178 /* Do nothing for global register variables. */
2179 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2181 TREE_ASM_WRITTEN (decl
) = 1;
2185 /* If type was incomplete when the variable was declared,
2186 see if it is complete now. */
2188 if (DECL_SIZE (decl
) == 0)
2189 layout_decl (decl
, 0);
2191 /* Still incomplete => don't allocate it; treat the tentative defn
2192 (which is what it must have been) as an `extern' reference. */
2194 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2196 error ("storage size of %q+D isn%'t known", decl
);
2197 TREE_ASM_WRITTEN (decl
) = 1;
2201 /* The first declaration of a variable that comes through this function
2202 decides whether it is global (in C, has external linkage)
2203 or local (in C, has internal linkage). So do nothing more
2204 if this function has already run. */
2206 if (TREE_ASM_WRITTEN (decl
))
2209 /* Make sure targetm.encode_section_info is invoked before we set
2211 decl_rtl
= DECL_RTL (decl
);
2213 TREE_ASM_WRITTEN (decl
) = 1;
2215 /* Do no output if -fsyntax-only. */
2216 if (flag_syntax_only
)
2219 if (! dont_output_data
2220 && ! valid_constant_size_p (DECL_SIZE_UNIT (decl
)))
2222 error ("size of variable %q+D is too large", decl
);
2226 gcc_assert (MEM_P (decl_rtl
));
2227 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2228 symbol
= XEXP (decl_rtl
, 0);
2230 /* If this symbol belongs to the tree constant pool, output the constant
2231 if it hasn't already been written. */
2232 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
2234 tree decl
= SYMBOL_REF_DECL (symbol
);
2235 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2236 output_constant_def_contents (symbol
);
2242 name
= XSTR (symbol
, 0);
2243 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2244 notice_global_symbol (decl
);
2246 /* Compute the alignment of this data. */
2248 align_variable (decl
, dont_output_data
);
2250 if ((flag_sanitize
& SANITIZE_ADDRESS
)
2251 && asan_protect_global (decl
))
2253 asan_protected
= true;
2254 SET_DECL_ALIGN (decl
, MAX (DECL_ALIGN (decl
),
2255 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
));
2258 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2260 align
= get_variable_align (decl
);
2262 if (TREE_PUBLIC (decl
))
2263 maybe_assemble_visibility (decl
);
2265 if (DECL_PRESERVE_P (decl
))
2266 targetm
.asm_out
.mark_decl_preserved (name
);
2268 /* First make the assembler name(s) global if appropriate. */
2269 sect
= get_variable_section (decl
, false);
2270 if (TREE_PUBLIC (decl
)
2271 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2272 globalize_decl (decl
);
2274 /* Output any data that we will need to use the address of. */
2275 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2276 output_addressed_constants (DECL_INITIAL (decl
), 0);
2278 /* dbxout.c needs to know this. */
2279 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2280 DECL_IN_TEXT_SECTION (decl
) = 1;
2282 /* If the decl is part of an object_block, make sure that the decl
2283 has been positioned within its block, but do not write out its
2284 definition yet. output_object_blocks will do that later. */
2285 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2287 gcc_assert (!dont_output_data
);
2288 place_block_symbol (symbol
);
2290 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2291 assemble_noswitch_variable (decl
, name
, sect
, align
);
2294 /* Special-case handling of vtv comdat sections. */
2295 if (sect
->named
.name
2296 && (strcmp (sect
->named
.name
, ".vtable_map_vars") == 0))
2297 handle_vtv_comdat_section (sect
, decl
);
2299 switch_to_section (sect
);
2300 if (align
> BITS_PER_UNIT
)
2301 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2302 assemble_variable_contents (decl
, name
, dont_output_data
,
2303 (sect
->common
.flags
& SECTION_MERGE
)
2304 && (sect
->common
.flags
& SECTION_STRINGS
));
2307 unsigned HOST_WIDE_INT
int size
2308 = tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2309 assemble_zeros (asan_red_zone_size (size
));
2315 /* Given a function declaration (FN_DECL), this function assembles the
2316 function into the .preinit_array section. */
2319 assemble_vtv_preinit_initializer (tree fn_decl
)
2322 unsigned flags
= SECTION_WRITE
;
2323 rtx symbol
= XEXP (DECL_RTL (fn_decl
), 0);
2325 flags
|= SECTION_NOTYPE
;
2326 sect
= get_section (".preinit_array", flags
, fn_decl
);
2327 switch_to_section (sect
);
2328 assemble_addr_to_section (symbol
, sect
);
2331 /* Return 1 if type TYPE contains any pointers. */
2334 contains_pointers_p (tree type
)
2336 switch (TREE_CODE (type
))
2339 case REFERENCE_TYPE
:
2340 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2341 so I'll play safe and return 1. */
2347 case QUAL_UNION_TYPE
:
2350 /* For a type that has fields, see if the fields have pointers. */
2351 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
2352 if (TREE_CODE (fields
) == FIELD_DECL
2353 && contains_pointers_p (TREE_TYPE (fields
)))
2359 /* An array type contains pointers if its element type does. */
2360 return contains_pointers_p (TREE_TYPE (type
));
2367 /* We delay assemble_external processing until
2368 the compilation unit is finalized. This is the best we can do for
2369 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2370 it all the way to final. See PR 17982 for further discussion. */
2371 static GTY(()) tree pending_assemble_externals
;
2373 #ifdef ASM_OUTPUT_EXTERNAL
2374 /* Some targets delay some output to final using TARGET_ASM_FILE_END.
2375 As a result, assemble_external can be called after the list of externals
2376 is processed and the pointer set destroyed. */
2377 static bool pending_assemble_externals_processed
;
2379 /* Avoid O(external_decls**2) lookups in the pending_assemble_externals
2380 TREE_LIST in assemble_external. */
2381 static hash_set
<tree
> *pending_assemble_externals_set
;
2383 /* True if DECL is a function decl for which no out-of-line copy exists.
2384 It is assumed that DECL's assembler name has been set. */
2387 incorporeal_function_p (tree decl
)
2389 if (TREE_CODE (decl
) == FUNCTION_DECL
&& fndecl_built_in_p (decl
))
2393 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2394 && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl
)))
2397 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2398 /* Atomic or sync builtins which have survived this far will be
2399 resolved externally and therefore are not incorporeal. */
2400 if (strncmp (name
, "__builtin_", 10) == 0)
2406 /* Actually do the tests to determine if this is necessary, and invoke
2407 ASM_OUTPUT_EXTERNAL. */
2409 assemble_external_real (tree decl
)
2411 rtx rtl
= DECL_RTL (decl
);
2413 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2414 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2415 && !incorporeal_function_p (decl
))
2417 /* Some systems do require some output. */
2418 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2419 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2425 process_pending_assemble_externals (void)
2427 #ifdef ASM_OUTPUT_EXTERNAL
2429 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2430 assemble_external_real (TREE_VALUE (list
));
2432 pending_assemble_externals
= 0;
2433 pending_assemble_externals_processed
= true;
2434 delete pending_assemble_externals_set
;
2438 /* This TREE_LIST contains any weak symbol declarations waiting
2440 static GTY(()) tree weak_decls
;
2442 /* Output something to declare an external symbol to the assembler,
2443 and qualifiers such as weakness. (Most assemblers don't need
2444 extern declaration, so we normally output nothing.) Do nothing if
2445 DECL is not external. */
2448 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2450 /* Make sure that the ASM_OUT_FILE is open.
2451 If it's not, we should not be calling this function. */
2452 gcc_assert (asm_out_file
);
2454 /* In a perfect world, the following condition would be true.
2455 Sadly, the Go front end emit assembly *from the front end*,
2456 bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2458 /* This function should only be called if we are expanding, or have
2460 Ideally, only final.c would be calling this function, but it is
2461 not clear whether that would break things somehow. See PR 17982
2462 for further discussion. */
2463 gcc_assert (state
== EXPANSION
2464 || state
== FINISHED
);
2467 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2470 /* We want to output annotation for weak and external symbols at
2471 very last to check if they are references or not. */
2473 if (TARGET_SUPPORTS_WEAK
2475 /* TREE_STATIC is a weird and abused creature which is not
2476 generally the right test for whether an entity has been
2477 locally emitted, inlined or otherwise not-really-extern, but
2478 for declarations that can be weak, it happens to be
2480 && !TREE_STATIC (decl
)
2481 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2482 && value_member (decl
, weak_decls
) == NULL_TREE
)
2483 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2485 #ifdef ASM_OUTPUT_EXTERNAL
2486 if (pending_assemble_externals_processed
)
2488 assemble_external_real (decl
);
2492 if (! pending_assemble_externals_set
->add (decl
))
2493 pending_assemble_externals
= tree_cons (NULL
, decl
,
2494 pending_assemble_externals
);
2498 /* Similar, for calling a library function FUN. */
2501 assemble_external_libcall (rtx fun
)
2503 /* Declare library function name external when first used, if nec. */
2504 if (! SYMBOL_REF_USED (fun
))
2506 SYMBOL_REF_USED (fun
) = 1;
2507 targetm
.asm_out
.external_libcall (fun
);
2511 /* Assemble a label named NAME. */
2514 assemble_label (FILE *file
, const char *name
)
2516 ASM_OUTPUT_LABEL (file
, name
);
2519 /* Set the symbol_referenced flag for ID. */
2521 mark_referenced (tree id
)
2523 TREE_SYMBOL_REFERENCED (id
) = 1;
2526 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2528 mark_decl_referenced (tree decl
)
2530 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2532 /* Extern inline functions don't become needed when referenced.
2533 If we know a method will be emitted in other TU and no new
2534 functions can be marked reachable, just use the external
2536 struct cgraph_node
*node
= cgraph_node::get_create (decl
);
2537 if (!DECL_EXTERNAL (decl
)
2538 && !node
->definition
)
2539 node
->mark_force_output ();
2541 else if (VAR_P (decl
))
2543 varpool_node
*node
= varpool_node::get_create (decl
);
2544 /* C++ frontend use mark_decl_references to force COMDAT variables
2545 to be output that might appear dead otherwise. */
2546 node
->force_output
= true;
2548 /* else do nothing - we can get various sorts of CST nodes here,
2549 which do not need to be marked. */
2553 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2554 starts with a *, the rest of NAME is output verbatim. Otherwise
2555 NAME is transformed in a target-specific way (usually by the
2556 addition of an underscore). */
2559 assemble_name_raw (FILE *file
, const char *name
)
2562 fputs (&name
[1], file
);
2564 ASM_OUTPUT_LABELREF (file
, name
);
2567 /* Return NAME that should actually be emitted, looking through
2568 transparent aliases. If NAME refers to an entity that is also
2569 represented as a tree (like a function or variable), mark the entity
2572 assemble_name_resolve (const char *name
)
2574 const char *real_name
= targetm
.strip_name_encoding (name
);
2575 tree id
= maybe_get_identifier (real_name
);
2581 mark_referenced (id
);
2582 ultimate_transparent_alias_target (&id
);
2584 name
= IDENTIFIER_POINTER (id
);
2585 gcc_assert (! TREE_CHAIN (id
));
2591 /* Like assemble_name_raw, but should be used when NAME might refer to
2592 an entity that is also represented as a tree (like a function or
2593 variable). If NAME does refer to such an entity, that entity will
2594 be marked as referenced. */
2597 assemble_name (FILE *file
, const char *name
)
2599 assemble_name_raw (file
, assemble_name_resolve (name
));
2602 /* Allocate SIZE bytes writable static space with a gensym name
2603 and return an RTX to refer to its address. */
2606 assemble_static_space (unsigned HOST_WIDE_INT size
)
2609 const char *namestring
;
2612 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2614 namestring
= ggc_strdup (name
);
2616 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2617 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2619 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2620 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2623 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2624 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2627 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2628 so that each uninitialized object starts on such a boundary. */
2629 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2630 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2631 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2632 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2633 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2634 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2641 /* Assemble the static constant template for function entry trampolines.
2642 This is done at most once per compilation.
2643 Returns an RTX for the address of the template. */
2645 static GTY(()) rtx initial_trampoline
;
2648 assemble_trampoline_template (void)
2655 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2657 if (initial_trampoline
)
2658 return initial_trampoline
;
2660 /* By default, put trampoline templates in read-only data section. */
2662 #ifdef TRAMPOLINE_SECTION
2663 switch_to_section (TRAMPOLINE_SECTION
);
2665 switch_to_section (readonly_data_section
);
2668 /* Write the assembler code to define one. */
2669 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2671 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2673 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2674 targetm
.asm_out
.trampoline_template (asm_out_file
);
2676 /* Record the rtl to refer to it. */
2677 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2678 name
= ggc_strdup (label
);
2679 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2680 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2682 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2683 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2684 set_mem_size (initial_trampoline
, TRAMPOLINE_SIZE
);
2686 return initial_trampoline
;
2689 /* A and B are either alignments or offsets. Return the minimum alignment
2690 that may be assumed after adding the two together. */
2692 static inline unsigned
2693 min_align (unsigned int a
, unsigned int b
)
2695 return least_bit_hwi (a
| b
);
2698 /* Return the assembler directive for creating a given kind of integer
2699 object. SIZE is the number of bytes in the object and ALIGNED_P
2700 indicates whether it is known to be aligned. Return NULL if the
2701 assembly dialect has no such directive.
2703 The returned string should be printed at the start of a new line and
2704 be followed immediately by the object's initial value. */
2707 integer_asm_op (int size
, int aligned_p
)
2709 struct asm_int_op
*ops
;
2712 ops
= &targetm
.asm_out
.aligned_op
;
2714 ops
= &targetm
.asm_out
.unaligned_op
;
2719 return targetm
.asm_out
.byte_op
;
2747 /* Use directive OP to assemble an integer object X. Print OP at the
2748 start of the line, followed immediately by the value of X. */
2751 assemble_integer_with_op (const char *op
, rtx x
)
2753 fputs (op
, asm_out_file
);
2754 output_addr_const (asm_out_file
, x
);
2755 fputc ('\n', asm_out_file
);
2758 /* The default implementation of the asm_out.integer target hook. */
2761 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2762 unsigned int size ATTRIBUTE_UNUSED
,
2763 int aligned_p ATTRIBUTE_UNUSED
)
2765 const char *op
= integer_asm_op (size
, aligned_p
);
2766 /* Avoid GAS bugs for large values. Specifically negative values whose
2767 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2768 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE_UNITS
)
2770 return op
&& (assemble_integer_with_op (op
, x
), true);
2773 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2774 the alignment of the integer in bits. Return 1 if we were able to output
2775 the constant, otherwise 0. We must be able to output the constant,
2776 if FORCE is nonzero. */
2779 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2783 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2785 /* See if the target hook can handle this kind of object. */
2786 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2789 /* If the object is a multi-byte one, try splitting it up. Split
2790 it into words it if is multi-word, otherwise split it into bytes. */
2793 machine_mode omode
, imode
;
2794 unsigned int subalign
;
2795 unsigned int subsize
, i
;
2796 enum mode_class mclass
;
2798 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2799 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2800 if (GET_CODE (x
) == CONST_FIXED
)
2801 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2805 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0).require ();
2806 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0).require ();
2808 for (i
= 0; i
< size
; i
+= subsize
)
2810 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2811 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2817 /* If we've printed some of it, but not all of it, there's no going
2822 gcc_assert (!force
);
2827 /* Assemble the floating-point constant D into an object of size MODE. ALIGN
2828 is the alignment of the constant in bits. If REVERSE is true, D is output
2829 in reverse storage order. */
2832 assemble_real (REAL_VALUE_TYPE d
, scalar_float_mode mode
, unsigned int align
,
2835 long data
[4] = {0, 0, 0, 0};
2836 int bitsize
, nelts
, nunits
, units_per
;
2839 /* This is hairy. We have a quantity of known size. real_to_target
2840 will put it into an array of *host* longs, 32 bits per element
2841 (even if long is more than 32 bits). We need to determine the
2842 number of array elements that are occupied (nelts) and the number
2843 of *target* min-addressable units that will be occupied in the
2844 object file (nunits). We cannot assume that 32 divides the
2845 mode's bitsize (size * BITS_PER_UNIT) evenly.
2847 size * BITS_PER_UNIT is used here to make sure that padding bits
2848 (which might appear at either end of the value; real_to_target
2849 will include the padding bits in its output array) are included. */
2851 nunits
= GET_MODE_SIZE (mode
);
2852 bitsize
= nunits
* BITS_PER_UNIT
;
2853 nelts
= CEIL (bitsize
, 32);
2854 units_per
= 32 / BITS_PER_UNIT
;
2856 real_to_target (data
, &d
, mode
);
2858 /* Put out the first word with the specified alignment. */
2859 unsigned int chunk_nunits
= MIN (nunits
, units_per
);
2861 elt
= flip_storage_order (SImode
, gen_int_mode (data
[nelts
- 1], SImode
));
2863 elt
= GEN_INT (sext_hwi (data
[0], chunk_nunits
* BITS_PER_UNIT
));
2864 assemble_integer (elt
, chunk_nunits
, align
, 1);
2865 nunits
-= chunk_nunits
;
2867 /* Subsequent words need only 32-bit alignment. */
2868 align
= min_align (align
, 32);
2870 for (int i
= 1; i
< nelts
; i
++)
2872 chunk_nunits
= MIN (nunits
, units_per
);
2874 elt
= flip_storage_order (SImode
,
2875 gen_int_mode (data
[nelts
- 1 - i
], SImode
));
2877 elt
= GEN_INT (sext_hwi (data
[i
], chunk_nunits
* BITS_PER_UNIT
));
2878 assemble_integer (elt
, chunk_nunits
, align
, 1);
2879 nunits
-= chunk_nunits
;
2883 /* Given an expression EXP with a constant value,
2884 reduce it to the sum of an assembler symbol and an integer.
2885 Store them both in the structure *VALUE.
2886 EXP must be reducible. */
2895 decode_addr_const (tree exp
, class addr_const
*value
)
2897 tree target
= TREE_OPERAND (exp
, 0);
2898 poly_int64 offset
= 0;
2904 if (TREE_CODE (target
) == COMPONENT_REF
2905 && poly_int_tree_p (byte_position (TREE_OPERAND (target
, 1)),
2909 target
= TREE_OPERAND (target
, 0);
2911 else if (TREE_CODE (target
) == ARRAY_REF
2912 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2914 /* Truncate big offset. */
2916 += (TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (target
)))
2917 * wi::to_poly_widest (TREE_OPERAND (target
, 1)).force_shwi ());
2918 target
= TREE_OPERAND (target
, 0);
2920 else if (TREE_CODE (target
) == MEM_REF
2921 && TREE_CODE (TREE_OPERAND (target
, 0)) == ADDR_EXPR
)
2923 offset
+= mem_ref_offset (target
).force_shwi ();
2924 target
= TREE_OPERAND (TREE_OPERAND (target
, 0), 0);
2926 else if (TREE_CODE (target
) == INDIRECT_REF
2927 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2928 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2930 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2935 switch (TREE_CODE (target
))
2939 x
= DECL_RTL (target
);
2943 x
= gen_rtx_MEM (FUNCTION_MODE
,
2944 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2953 x
= lookup_constant_def (target
);
2954 /* Should have been added by output_addressed_constants. */
2959 /* This deals with absolute addresses. */
2960 offset
+= tree_to_shwi (TREE_OPERAND (target
, 0));
2961 x
= gen_rtx_MEM (QImode
,
2962 gen_rtx_SYMBOL_REF (Pmode
, "origin of addresses"));
2965 case COMPOUND_LITERAL_EXPR
:
2966 gcc_assert (COMPOUND_LITERAL_EXPR_DECL (target
));
2967 x
= DECL_RTL (COMPOUND_LITERAL_EXPR_DECL (target
));
2974 gcc_assert (MEM_P (x
));
2978 value
->offset
= offset
;
2981 static GTY(()) hash_table
<tree_descriptor_hasher
> *const_desc_htab
;
2983 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2985 /* Constant pool accessor function. */
2987 hash_table
<tree_descriptor_hasher
> *
2988 constant_pool_htab (void)
2990 return const_desc_htab
;
2993 /* Compute a hash code for a constant expression. */
2996 tree_descriptor_hasher::hash (constant_descriptor_tree
*ptr
)
3002 const_hash_1 (const tree exp
)
3007 enum tree_code code
= TREE_CODE (exp
);
3009 /* Either set P and LEN to the address and len of something to hash and
3010 exit the switch or return a value. */
3015 p
= (char *) &TREE_INT_CST_ELT (exp
, 0);
3016 len
= TREE_INT_CST_NUNITS (exp
) * sizeof (HOST_WIDE_INT
);
3020 return real_hash (TREE_REAL_CST_PTR (exp
));
3023 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
3026 p
= TREE_STRING_POINTER (exp
);
3027 len
= TREE_STRING_LENGTH (exp
);
3031 return (const_hash_1 (TREE_REALPART (exp
)) * 5
3032 + const_hash_1 (TREE_IMAGPART (exp
)));
3036 hi
= 7 + VECTOR_CST_NPATTERNS (exp
);
3037 hi
= hi
* 563 + VECTOR_CST_NELTS_PER_PATTERN (exp
);
3038 unsigned int count
= vector_cst_encoded_nelts (exp
);
3039 for (unsigned int i
= 0; i
< count
; ++i
)
3040 hi
= hi
* 563 + const_hash_1 (VECTOR_CST_ENCODED_ELT (exp
, i
));
3046 unsigned HOST_WIDE_INT idx
;
3049 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
3051 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
3053 hi
= hi
* 603 + const_hash_1 (value
);
3059 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
3060 return const_hash_1 (TREE_OPERAND (exp
, 0));
3065 class addr_const value
;
3067 decode_addr_const (exp
, &value
);
3068 switch (GET_CODE (value
.base
))
3071 /* Don't hash the address of the SYMBOL_REF;
3072 only use the offset and the symbol name. */
3073 hi
= value
.offset
.coeffs
[0];
3074 p
= XSTR (value
.base
, 0);
3075 for (i
= 0; p
[i
] != 0; i
++)
3076 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
3080 hi
= (value
.offset
.coeffs
[0]
3081 + CODE_LABEL_NUMBER (label_ref_label (value
.base
)) * 13);
3091 case POINTER_PLUS_EXPR
:
3093 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
3094 + const_hash_1 (TREE_OPERAND (exp
, 1)));
3097 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
3100 /* A language specific constant. Just hash the code. */
3104 /* Compute hashing function. */
3106 for (i
= 0; i
< len
; i
++)
3107 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
3112 /* Wrapper of compare_constant, for the htab interface. */
3114 tree_descriptor_hasher::equal (constant_descriptor_tree
*c1
,
3115 constant_descriptor_tree
*c2
)
3117 if (c1
->hash
!= c2
->hash
)
3119 return compare_constant (c1
->value
, c2
->value
);
3122 /* Compare t1 and t2, and return 1 only if they are known to result in
3123 the same bit pattern on output. */
3126 compare_constant (const tree t1
, const tree t2
)
3128 enum tree_code typecode
;
3130 if (t1
== NULL_TREE
)
3131 return t2
== NULL_TREE
;
3132 if (t2
== NULL_TREE
)
3135 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3138 switch (TREE_CODE (t1
))
3141 /* Integer constants are the same only if the same width of type. */
3142 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3144 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3146 return tree_int_cst_equal (t1
, t2
);
3149 /* Real constants are the same only if the same width of type. In
3150 addition to the same width, we need to check whether the modes are the
3151 same. There might be two floating point modes that are the same size
3152 but have different representations, such as the PowerPC that has 2
3153 different 128-bit floating point types (IBM extended double and IEEE
3154 128-bit floating point). */
3155 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3157 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3159 return real_identical (&TREE_REAL_CST (t1
), &TREE_REAL_CST (t2
));
3162 /* Fixed constants are the same only if the same width of type. */
3163 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3166 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
3169 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3170 || int_size_in_bytes (TREE_TYPE (t1
))
3171 != int_size_in_bytes (TREE_TYPE (t2
)))
3174 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3175 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3176 TREE_STRING_LENGTH (t1
)));
3179 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
3180 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
3184 if (VECTOR_CST_NPATTERNS (t1
)
3185 != VECTOR_CST_NPATTERNS (t2
))
3188 if (VECTOR_CST_NELTS_PER_PATTERN (t1
)
3189 != VECTOR_CST_NELTS_PER_PATTERN (t2
))
3192 unsigned int count
= vector_cst_encoded_nelts (t1
);
3193 for (unsigned int i
= 0; i
< count
; ++i
)
3194 if (!compare_constant (VECTOR_CST_ENCODED_ELT (t1
, i
),
3195 VECTOR_CST_ENCODED_ELT (t2
, i
)))
3203 vec
<constructor_elt
, va_gc
> *v1
, *v2
;
3204 unsigned HOST_WIDE_INT idx
;
3206 typecode
= TREE_CODE (TREE_TYPE (t1
));
3207 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3210 if (typecode
== ARRAY_TYPE
)
3212 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3213 /* For arrays, check that mode, size and storage order match. */
3214 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3216 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
))
3217 || TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t1
))
3218 != TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t2
)))
3223 /* For record and union constructors, require exact type
3225 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3229 v1
= CONSTRUCTOR_ELTS (t1
);
3230 v2
= CONSTRUCTOR_ELTS (t2
);
3231 if (vec_safe_length (v1
) != vec_safe_length (v2
))
3234 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
3236 constructor_elt
*c1
= &(*v1
)[idx
];
3237 constructor_elt
*c2
= &(*v2
)[idx
];
3239 /* Check that each value is the same... */
3240 if (!compare_constant (c1
->value
, c2
->value
))
3242 /* ... and that they apply to the same fields! */
3243 if (typecode
== ARRAY_TYPE
)
3245 if (!compare_constant (c1
->index
, c2
->index
))
3250 if (c1
->index
!= c2
->index
)
3261 class addr_const value1
, value2
;
3265 decode_addr_const (t1
, &value1
);
3266 decode_addr_const (t2
, &value2
);
3268 if (maybe_ne (value1
.offset
, value2
.offset
))
3271 code
= GET_CODE (value1
.base
);
3272 if (code
!= GET_CODE (value2
.base
))
3278 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3282 ret
= (CODE_LABEL_NUMBER (label_ref_label (value1
.base
))
3283 == CODE_LABEL_NUMBER (label_ref_label (value2
.base
)));
3293 case POINTER_PLUS_EXPR
:
3296 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3297 && compare_constant (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3300 case VIEW_CONVERT_EXPR
:
3301 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3310 /* Return the section into which constant EXP should be placed. */
3313 get_constant_section (tree exp
, unsigned int align
)
3315 return targetm
.asm_out
.select_section (exp
,
3316 compute_reloc_for_constant (exp
),
3320 /* Return the size of constant EXP in bytes. */
3322 static HOST_WIDE_INT
3323 get_constant_size (tree exp
)
3327 size
= int_size_in_bytes (TREE_TYPE (exp
));
3328 gcc_checking_assert (size
>= 0);
3329 gcc_checking_assert (TREE_CODE (exp
) != STRING_CST
3330 || size
>= TREE_STRING_LENGTH (exp
));
3334 /* Subroutine of output_constant_def:
3335 No constant equal to EXP is known to have been output.
3336 Make a constant descriptor to enter EXP in the hash table.
3337 Assign the label number and construct RTL to refer to the
3338 constant's location in memory.
3339 Caller is responsible for updating the hash table. */
3341 static struct constant_descriptor_tree
*
3342 build_constant_desc (tree exp
)
3344 struct constant_descriptor_tree
*desc
;
3350 desc
= ggc_alloc
<constant_descriptor_tree
> ();
3353 /* Create a string containing the label name, in LABEL. */
3354 labelno
= const_labelno
++;
3355 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3357 /* Construct the VAR_DECL associated with the constant. */
3358 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3360 DECL_ARTIFICIAL (decl
) = 1;
3361 DECL_IGNORED_P (decl
) = 1;
3362 TREE_READONLY (decl
) = 1;
3363 TREE_STATIC (decl
) = 1;
3364 TREE_ADDRESSABLE (decl
) = 1;
3365 /* We don't set the RTL yet as this would cause varpool to assume that the
3366 variable is referenced. Moreover, it would just be dropped in LTO mode.
3367 Instead we set the flag that will be recognized in make_decl_rtl. */
3368 DECL_IN_CONSTANT_POOL (decl
) = 1;
3369 DECL_INITIAL (decl
) = desc
->value
;
3370 /* ??? targetm.constant_alignment hasn't been updated for vector types on
3371 most architectures so use DATA_ALIGNMENT as well, except for strings. */
3372 if (TREE_CODE (exp
) == STRING_CST
)
3373 SET_DECL_ALIGN (decl
, targetm
.constant_alignment (exp
, DECL_ALIGN (decl
)));
3376 align_variable (decl
, 0);
3377 if (DECL_ALIGN (decl
) < GET_MODE_ALIGNMENT (DECL_MODE (decl
))
3378 && ((optab_handler (movmisalign_optab
, DECL_MODE (decl
))
3379 != CODE_FOR_nothing
)
3380 || targetm
.slow_unaligned_access (DECL_MODE (decl
),
3381 DECL_ALIGN (decl
))))
3382 SET_DECL_ALIGN (decl
, GET_MODE_ALIGNMENT (DECL_MODE (decl
)));
3385 /* Now construct the SYMBOL_REF and the MEM. */
3386 if (use_object_blocks_p ())
3388 int align
= (TREE_CODE (decl
) == CONST_DECL
3389 || (VAR_P (decl
) && DECL_IN_CONSTANT_POOL (decl
))
3391 : symtab_node::get (decl
)->definition_alignment ());
3392 section
*sect
= get_constant_section (exp
, align
);
3393 symbol
= create_block_symbol (ggc_strdup (label
),
3394 get_block_for_section (sect
), -1);
3397 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3398 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3399 SET_SYMBOL_REF_DECL (symbol
, decl
);
3400 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3402 rtl
= gen_const_mem (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3403 set_mem_alias_set (rtl
, 0);
3405 /* Putting EXP into the literal pool might have imposed a different
3406 alignment which should be visible in the RTX as well. */
3407 set_mem_align (rtl
, DECL_ALIGN (decl
));
3409 /* We cannot share RTX'es in pool entries.
3410 Mark this piece of RTL as required for unsharing. */
3411 RTX_FLAG (rtl
, used
) = 1;
3413 /* Set flags or add text to the name to record information, such as
3414 that it is a local symbol. If the name is changed, the macro
3415 ASM_OUTPUT_LABELREF will have to know how to strip this
3416 information. This call might invalidate our local variable
3417 SYMBOL; we can't use it afterward. */
3418 targetm
.encode_section_info (exp
, rtl
, true);
3425 /* Subroutine of output_constant_def and tree_output_constant_def:
3426 Add a constant to the hash table that tracks which constants
3427 already have labels. */
3429 static constant_descriptor_tree
*
3430 add_constant_to_table (tree exp
, int defer
)
3432 /* The hash table methods may call output_constant_def for addressed
3433 constants, so handle them first. */
3434 output_addressed_constants (exp
, defer
);
3436 /* Sanity check to catch recursive insertion. */
3437 static bool inserting
;
3438 gcc_assert (!inserting
);
3441 /* Look up EXP in the table of constant descriptors. If we didn't
3442 find it, create a new one. */
3443 struct constant_descriptor_tree key
;
3445 key
.hash
= const_hash_1 (exp
);
3446 constant_descriptor_tree
**loc
3447 = const_desc_htab
->find_slot_with_hash (&key
, key
.hash
, INSERT
);
3451 struct constant_descriptor_tree
*desc
= *loc
;
3454 desc
= build_constant_desc (exp
);
3455 desc
->hash
= key
.hash
;
3462 /* Return an rtx representing a reference to constant data in memory
3463 for the constant expression EXP.
3465 If assembler code for such a constant has already been output,
3466 return an rtx to refer to it.
3467 Otherwise, output such a constant in memory
3468 and generate an rtx for it.
3470 If DEFER is nonzero, this constant can be deferred and output only
3471 if referenced in the function after all optimizations.
3473 `const_desc_table' records which constants already have label strings. */
3476 output_constant_def (tree exp
, int defer
)
3478 struct constant_descriptor_tree
*desc
= add_constant_to_table (exp
, defer
);
3479 maybe_output_constant_def_contents (desc
, defer
);
3483 /* Subroutine of output_constant_def: Decide whether or not we need to
3484 output the constant DESC now, and if so, do it. */
3486 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3489 rtx symbol
= XEXP (desc
->rtl
, 0);
3490 tree exp
= desc
->value
;
3492 if (flag_syntax_only
)
3495 if (TREE_ASM_WRITTEN (exp
))
3496 /* Already output; don't do it again. */
3499 /* We can always defer constants as long as the context allows
3503 /* Increment n_deferred_constants if it exists. It needs to be at
3504 least as large as the number of constants actually referred to
3505 by the function. If it's too small we'll stop looking too early
3506 and fail to emit constants; if it's too large we'll only look
3507 through the entire function when we could have stopped earlier. */
3509 n_deferred_constants
++;
3513 output_constant_def_contents (symbol
);
3516 /* Subroutine of output_constant_def_contents. Output the definition
3517 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3518 constant's alignment in bits. */
3521 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
,
3526 size
= get_constant_size (exp
);
3528 /* Do any machine/system dependent processing of the constant. */
3529 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3531 /* Output the value of EXP. */
3532 output_constant (exp
, size
, align
, false, merge_strings
);
3534 targetm
.asm_out
.decl_end ();
3537 /* We must output the constant data referred to by SYMBOL; do so. */
3540 output_constant_def_contents (rtx symbol
)
3542 tree decl
= SYMBOL_REF_DECL (symbol
);
3543 tree exp
= DECL_INITIAL (decl
);
3544 bool asan_protected
= false;
3546 /* Make sure any other constants whose addresses appear in EXP
3547 are assigned label numbers. */
3548 output_addressed_constants (exp
, 0);
3550 /* We are no longer deferring this constant. */
3551 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3553 if ((flag_sanitize
& SANITIZE_ADDRESS
)
3554 && TREE_CODE (exp
) == STRING_CST
3555 && asan_protect_global (exp
))
3557 asan_protected
= true;
3558 SET_DECL_ALIGN (decl
, MAX (DECL_ALIGN (decl
),
3559 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
));
3562 /* If the constant is part of an object block, make sure that the
3563 decl has been positioned within its block, but do not write out
3564 its definition yet. output_object_blocks will do that later. */
3565 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3566 place_block_symbol (symbol
);
3569 int align
= (TREE_CODE (decl
) == CONST_DECL
3570 || (VAR_P (decl
) && DECL_IN_CONSTANT_POOL (decl
))
3572 : symtab_node::get (decl
)->definition_alignment ());
3573 section
*sect
= get_constant_section (exp
, align
);
3574 switch_to_section (sect
);
3575 if (align
> BITS_PER_UNIT
)
3576 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3577 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
,
3578 (sect
->common
.flags
& SECTION_MERGE
)
3579 && (sect
->common
.flags
& SECTION_STRINGS
));
3582 HOST_WIDE_INT size
= get_constant_size (exp
);
3583 assemble_zeros (asan_red_zone_size (size
));
3588 /* Look up EXP in the table of constant descriptors. Return the rtl
3589 if it has been emitted, else null. */
3592 lookup_constant_def (tree exp
)
3594 struct constant_descriptor_tree key
;
3597 key
.hash
= const_hash_1 (exp
);
3598 constant_descriptor_tree
*desc
3599 = const_desc_htab
->find_with_hash (&key
, key
.hash
);
3601 return (desc
? desc
->rtl
: NULL_RTX
);
3604 /* Return a tree representing a reference to constant data in memory
3605 for the constant expression EXP.
3607 This is the counterpart of output_constant_def at the Tree level. */
3610 tree_output_constant_def (tree exp
)
3612 struct constant_descriptor_tree
*desc
= add_constant_to_table (exp
, 1);
3613 tree decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3614 varpool_node::finalize_decl (decl
);
3618 class GTY((chain_next ("%h.next"), for_user
)) constant_descriptor_rtx
{
3620 class constant_descriptor_rtx
*next
;
3624 HOST_WIDE_INT offset
;
3626 fixed_size_mode mode
;
3632 struct const_rtx_desc_hasher
: ggc_ptr_hash
<constant_descriptor_rtx
>
3634 static hashval_t
hash (constant_descriptor_rtx
*);
3635 static bool equal (constant_descriptor_rtx
*, constant_descriptor_rtx
*);
3638 /* Used in the hash tables to avoid outputting the same constant
3639 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3640 are output once per function, not once per file. */
3641 /* ??? Only a few targets need per-function constant pools. Most
3642 can use one per-file pool. Should add a targetm bit to tell the
3645 struct GTY(()) rtx_constant_pool
{
3646 /* Pointers to first and last constant in pool, as ordered by offset. */
3647 class constant_descriptor_rtx
*first
;
3648 class constant_descriptor_rtx
*last
;
3650 /* Hash facility for making memory-constants from constant rtl-expressions.
3651 It is used on RISC machines where immediate integer arguments and
3652 constant addresses are restricted so that such constants must be stored
3654 hash_table
<const_rtx_desc_hasher
> *const_rtx_htab
;
3656 /* Current offset in constant pool (does not include any
3657 machine-specific header). */
3658 HOST_WIDE_INT offset
;
3661 /* Hash and compare functions for const_rtx_htab. */
3664 const_rtx_desc_hasher::hash (constant_descriptor_rtx
*desc
)
3670 const_rtx_desc_hasher::equal (constant_descriptor_rtx
*x
,
3671 constant_descriptor_rtx
*y
)
3673 if (x
->mode
!= y
->mode
)
3675 return rtx_equal_p (x
->constant
, y
->constant
);
3678 /* Hash one component of a constant. */
3681 const_rtx_hash_1 (const_rtx x
)
3683 unsigned HOST_WIDE_INT hwi
;
3689 code
= GET_CODE (x
);
3690 mode
= GET_MODE (x
);
3691 h
= (hashval_t
) code
* 1048573 + mode
;
3700 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3701 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3703 h
^= (hashval_t
) hwi
;
3704 for (i
= 1; i
< n
; ++i
)
3707 h
^= (hashval_t
) hwi
;
3712 case CONST_WIDE_INT
:
3715 for (i
= 0; i
< CONST_WIDE_INT_NUNITS (x
); i
++)
3716 hwi
^= CONST_WIDE_INT_ELT (x
, i
);
3721 if (TARGET_SUPPORTS_WIDE_INT
== 0 && mode
== VOIDmode
)
3723 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3727 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3731 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3735 h
^= htab_hash_string (XSTR (x
, 0));
3739 h
= h
* 251 + CODE_LABEL_NUMBER (label_ref_label (x
));
3743 case UNSPEC_VOLATILE
:
3744 h
= h
* 251 + XINT (x
, 1);
3754 /* Compute a hash value for X, which should be a constant. */
3757 const_rtx_hash (rtx x
)
3760 subrtx_iterator::array_type array
;
3761 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
3762 h
= h
* 509 + const_rtx_hash_1 (*iter
);
3767 /* Create and return a new rtx constant pool. */
3769 static struct rtx_constant_pool
*
3770 create_constant_pool (void)
3772 struct rtx_constant_pool
*pool
;
3774 pool
= ggc_alloc
<rtx_constant_pool
> ();
3775 pool
->const_rtx_htab
= hash_table
<const_rtx_desc_hasher
>::create_ggc (31);
3782 /* Initialize constant pool hashing for a new function. */
3785 init_varasm_status (void)
3787 crtl
->varasm
.pool
= create_constant_pool ();
3788 crtl
->varasm
.deferred_constants
= 0;
3791 /* Given a MINUS expression, simplify it if both sides
3792 include the same symbol. */
3795 simplify_subtraction (rtx x
)
3797 rtx r
= simplify_rtx (x
);
3801 /* Given a constant rtx X, make (or find) a memory constant for its value
3802 and return a MEM rtx to refer to it in memory. IN_MODE is the mode
3806 force_const_mem (machine_mode in_mode
, rtx x
)
3808 class constant_descriptor_rtx
*desc
, tmp
;
3809 struct rtx_constant_pool
*pool
;
3814 constant_descriptor_rtx
**slot
;
3815 fixed_size_mode mode
;
3817 /* We can't force variable-sized objects to memory. */
3818 if (!is_a
<fixed_size_mode
> (in_mode
, &mode
))
3821 /* If we're not allowed to drop X into the constant pool, don't. */
3822 if (targetm
.cannot_force_const_mem (mode
, x
))
3825 /* Record that this function has used a constant pool entry. */
3826 crtl
->uses_const_pool
= 1;
3828 /* Decide which pool to use. */
3829 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3830 ? shared_constant_pool
3831 : crtl
->varasm
.pool
);
3833 /* Lookup the value in the hashtable. */
3836 hash
= const_rtx_hash (x
);
3837 slot
= pool
->const_rtx_htab
->find_slot_with_hash (&tmp
, hash
, INSERT
);
3840 /* If the constant was already present, return its memory. */
3842 return copy_rtx (desc
->mem
);
3844 /* Otherwise, create a new descriptor. */
3845 desc
= ggc_alloc
<constant_descriptor_rtx
> ();
3848 /* Align the location counter as required by EXP's data type. */
3849 machine_mode align_mode
= (mode
== VOIDmode
? word_mode
: mode
);
3850 align
= targetm
.static_rtx_alignment (align_mode
);
3852 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3853 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3856 desc
->constant
= copy_rtx (tmp
.constant
);
3857 desc
->offset
= pool
->offset
;
3860 desc
->align
= align
;
3861 desc
->labelno
= const_labelno
;
3864 pool
->offset
+= GET_MODE_SIZE (mode
);
3866 pool
->last
->next
= desc
;
3868 pool
->first
= pool
->last
= desc
;
3871 /* Create a string containing the label name, in LABEL. */
3872 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3875 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3876 the constants pool. */
3877 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3879 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3880 symbol
= create_block_symbol (ggc_strdup (label
),
3881 get_block_for_section (sect
), -1);
3884 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3886 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3887 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3888 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3890 /* Construct the MEM. */
3891 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3892 set_mem_align (def
, align
);
3894 /* If we're dropping a label to the constant pool, make sure we
3896 if (GET_CODE (x
) == LABEL_REF
)
3897 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3899 return copy_rtx (def
);
3902 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3905 get_pool_constant (const_rtx addr
)
3907 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3910 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3911 and whether it has been output or not. */
3914 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3916 class constant_descriptor_rtx
*desc
;
3918 desc
= SYMBOL_REF_CONSTANT (addr
);
3919 *pmarked
= (desc
->mark
!= 0);
3920 return desc
->constant
;
3923 /* Similar, return the mode. */
3926 get_pool_mode (const_rtx addr
)
3928 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3931 /* Return TRUE if and only if the constant pool has no entries. Note
3932 that even entries we might end up choosing not to emit are counted
3933 here, so there is the potential for missed optimizations. */
3936 constant_pool_empty_p (void)
3938 return crtl
->varasm
.pool
->first
== NULL
;
3941 /* Worker function for output_constant_pool_1. Emit assembly for X
3942 in MODE with known alignment ALIGN. */
3945 output_constant_pool_2 (fixed_size_mode mode
, rtx x
, unsigned int align
)
3947 switch (GET_MODE_CLASS (mode
))
3950 case MODE_DECIMAL_FLOAT
:
3952 gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x
));
3953 assemble_real (*CONST_DOUBLE_REAL_VALUE (x
),
3954 as_a
<scalar_float_mode
> (mode
), align
, false);
3959 case MODE_PARTIAL_INT
:
3964 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3967 case MODE_VECTOR_BOOL
:
3969 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3971 /* Pick the smallest integer mode that contains at least one
3972 whole element. Often this is byte_mode and contains more
3973 than one element. */
3974 unsigned int nelts
= GET_MODE_NUNITS (mode
);
3975 unsigned int elt_bits
= GET_MODE_BITSIZE (mode
) / nelts
;
3976 unsigned int int_bits
= MAX (elt_bits
, BITS_PER_UNIT
);
3977 scalar_int_mode int_mode
= int_mode_for_size (int_bits
, 0).require ();
3979 /* Build the constant up one integer at a time. */
3980 unsigned int elts_per_int
= int_bits
/ elt_bits
;
3981 for (unsigned int i
= 0; i
< nelts
; i
+= elts_per_int
)
3983 unsigned HOST_WIDE_INT value
= 0;
3984 unsigned int limit
= MIN (nelts
- i
, elts_per_int
);
3985 for (unsigned int j
= 0; j
< limit
; ++j
)
3986 if (INTVAL (CONST_VECTOR_ELT (x
, i
+ j
)) != 0)
3987 value
|= 1 << (j
* elt_bits
);
3988 output_constant_pool_2 (int_mode
, gen_int_mode (value
, int_mode
),
3989 i
!= 0 ? MIN (align
, int_bits
) : align
);
3993 case MODE_VECTOR_FLOAT
:
3994 case MODE_VECTOR_INT
:
3995 case MODE_VECTOR_FRACT
:
3996 case MODE_VECTOR_UFRACT
:
3997 case MODE_VECTOR_ACCUM
:
3998 case MODE_VECTOR_UACCUM
:
4001 scalar_mode submode
= GET_MODE_INNER (mode
);
4002 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
4004 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
4005 units
= GET_MODE_NUNITS (mode
);
4007 for (i
= 0; i
< units
; i
++)
4009 rtx elt
= CONST_VECTOR_ELT (x
, i
);
4010 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
4020 /* Worker function for output_constant_pool. Emit constant DESC,
4021 giving it ALIGN bits of alignment. */
4024 output_constant_pool_1 (class constant_descriptor_rtx
*desc
,
4031 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
4032 whose CODE_LABEL has been deleted. This can occur if a jump table
4033 is eliminated by optimization. If so, write a constant of zero
4034 instead. Note that this can also happen by turning the
4035 CODE_LABEL into a NOTE. */
4036 /* ??? This seems completely and utterly wrong. Certainly it's
4037 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
4038 functioning even with rtx_insn::deleted and friends. */
4041 switch (GET_CODE (tmp
))
4044 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
4045 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
4047 tmp
= XEXP (XEXP (tmp
, 0), 0);
4052 rtx_insn
*insn
= label_ref_label (tmp
);
4053 gcc_assert (!insn
->deleted ());
4054 gcc_assert (!NOTE_P (insn
)
4055 || NOTE_KIND (insn
) != NOTE_INSN_DELETED
);
4063 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4064 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
4065 align
, desc
->labelno
, done
);
4068 assemble_align (align
);
4070 /* Output the label. */
4071 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
4074 Pass actual alignment value while emitting string constant to asm code
4075 as function 'output_constant_pool_1' explicitly passes the alignment as 1
4076 assuming that the data is already aligned which prevents the generation
4077 of fix-up table entries. */
4078 output_constant_pool_2 (desc
->mode
, x
, desc
->align
);
4080 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
4081 sections have proper size. */
4082 if (align
> GET_MODE_BITSIZE (desc
->mode
)
4084 && (in_section
->common
.flags
& SECTION_MERGE
))
4085 assemble_align (align
);
4087 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4093 /* Recompute the offsets of entries in POOL, and the overall size of
4094 POOL. Do this after calling mark_constant_pool to ensure that we
4095 are computing the offset values for the pool which we will actually
4099 recompute_pool_offsets (struct rtx_constant_pool
*pool
)
4101 class constant_descriptor_rtx
*desc
;
4104 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
4107 /* Recalculate offset. */
4108 unsigned int align
= desc
->align
;
4109 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
4110 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
4111 desc
->offset
= pool
->offset
;
4112 pool
->offset
+= GET_MODE_SIZE (desc
->mode
);
4116 /* Mark all constants that are referenced by SYMBOL_REFs in X.
4117 Emit referenced deferred strings. */
4120 mark_constants_in_pattern (rtx insn
)
4122 subrtx_iterator::array_type array
;
4123 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), ALL
)
4125 const_rtx x
= *iter
;
4126 if (GET_CODE (x
) == SYMBOL_REF
)
4128 if (CONSTANT_POOL_ADDRESS_P (x
))
4130 class constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
4131 if (desc
->mark
== 0)
4134 iter
.substitute (desc
->constant
);
4137 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
4139 tree decl
= SYMBOL_REF_DECL (x
);
4140 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
4142 n_deferred_constants
--;
4143 output_constant_def_contents (CONST_CAST_RTX (x
));
4150 /* Look through appropriate parts of INSN, marking all entries in the
4151 constant pool which are actually being used. Entries that are only
4152 referenced by other constants are also marked as used. Emit
4153 deferred strings that are used. */
4156 mark_constants (rtx_insn
*insn
)
4161 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4162 insns, not any notes that may be attached. We don't want to mark
4163 a constant just because it happens to appear in a REG_EQUIV note. */
4164 if (rtx_sequence
*seq
= dyn_cast
<rtx_sequence
*> (PATTERN (insn
)))
4166 int i
, n
= seq
->len ();
4167 for (i
= 0; i
< n
; ++i
)
4169 rtx subinsn
= seq
->element (i
);
4170 if (INSN_P (subinsn
))
4171 mark_constants_in_pattern (subinsn
);
4175 mark_constants_in_pattern (insn
);
4178 /* Look through the instructions for this function, and mark all the
4179 entries in POOL which are actually being used. Emit deferred constants
4180 which have indeed been used. */
4183 mark_constant_pool (void)
4187 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
4190 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4191 mark_constants (insn
);
4194 /* Write all the constants in POOL. */
4197 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
4199 class constant_descriptor_rtx
*desc
;
4201 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
4204 #ifdef ASM_OUTPUT_DEF
4205 const char *name
= targetm
.strip_name_encoding (XSTR (desc
->sym
, 0));
4207 char buffer
[256 + 32];
4210 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", ~desc
->mark
);
4211 p
= targetm
.strip_name_encoding (label
);
4214 sprintf (buffer
, "%s+%ld", p
, (long) (desc
->offset
));
4217 ASM_OUTPUT_DEF (asm_out_file
, name
, p
);
4222 else if (desc
->mark
)
4224 /* If the constant is part of an object_block, make sure that
4225 the constant has been positioned within its block, but do not
4226 write out its definition yet. output_object_blocks will do
4228 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
4229 && SYMBOL_REF_BLOCK (desc
->sym
))
4230 place_block_symbol (desc
->sym
);
4233 switch_to_section (targetm
.asm_out
.select_rtx_section
4234 (desc
->mode
, desc
->constant
, desc
->align
));
4235 output_constant_pool_1 (desc
, desc
->align
);
4240 struct constant_descriptor_rtx_data
{
4241 constant_descriptor_rtx
*desc
;
4243 unsigned short size
;
4244 unsigned short offset
;
4248 /* qsort callback to sort constant_descriptor_rtx_data * vector by
4252 constant_descriptor_rtx_data_cmp (const void *p1
, const void *p2
)
4254 constant_descriptor_rtx_data
*const data1
4255 = *(constant_descriptor_rtx_data
* const *) p1
;
4256 constant_descriptor_rtx_data
*const data2
4257 = *(constant_descriptor_rtx_data
* const *) p2
;
4258 if (data1
->size
> data2
->size
)
4260 if (data1
->size
< data2
->size
)
4262 if (data1
->hash
< data2
->hash
)
4264 gcc_assert (data1
->hash
> data2
->hash
);
4268 struct const_rtx_data_hasher
: nofree_ptr_hash
<constant_descriptor_rtx_data
>
4270 static hashval_t
hash (constant_descriptor_rtx_data
*);
4271 static bool equal (constant_descriptor_rtx_data
*,
4272 constant_descriptor_rtx_data
*);
4275 /* Hash and compare functions for const_rtx_data_htab. */
4278 const_rtx_data_hasher::hash (constant_descriptor_rtx_data
*data
)
4284 const_rtx_data_hasher::equal (constant_descriptor_rtx_data
*x
,
4285 constant_descriptor_rtx_data
*y
)
4287 if (x
->hash
!= y
->hash
|| x
->size
!= y
->size
)
4289 unsigned int align1
= x
->desc
->align
;
4290 unsigned int align2
= y
->desc
->align
;
4291 unsigned int offset1
= (x
->offset
* BITS_PER_UNIT
) & (align1
- 1);
4292 unsigned int offset2
= (y
->offset
* BITS_PER_UNIT
) & (align2
- 1);
4294 align1
= least_bit_hwi (offset1
);
4296 align2
= least_bit_hwi (offset2
);
4297 if (align2
> align1
)
4299 if (memcmp (x
->bytes
, y
->bytes
, x
->size
* sizeof (target_unit
)) != 0)
4304 /* Attempt to optimize constant pool POOL. If it contains both CONST_VECTOR
4305 constants and scalar constants with the values of CONST_VECTOR elements,
4306 try to alias the scalar constants with the CONST_VECTOR elements. */
4309 optimize_constant_pool (struct rtx_constant_pool
*pool
)
4311 auto_vec
<target_unit
, 128> buffer
;
4312 auto_vec
<constant_descriptor_rtx_data
*, 128> vec
;
4313 object_allocator
<constant_descriptor_rtx_data
>
4314 data_pool ("constant_descriptor_rtx_data_pool");
4317 for (constant_descriptor_rtx
*desc
= pool
->first
; desc
; desc
= desc
->next
)
4319 && ! (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
4320 && SYMBOL_REF_BLOCK (desc
->sym
)))
4322 buffer
.truncate (0);
4323 buffer
.reserve (GET_MODE_SIZE (desc
->mode
));
4324 if (native_encode_rtx (desc
->mode
, desc
->constant
, buffer
, 0,
4325 GET_MODE_SIZE (desc
->mode
)))
4327 constant_descriptor_rtx_data
*data
= data_pool
.allocate ();
4330 data
->size
= GET_MODE_SIZE (desc
->mode
);
4334 vec
.safe_push (data
);
4339 vec
.qsort (constant_descriptor_rtx_data_cmp
);
4340 unsigned min_size
= vec
.last ()->size
;
4341 target_unit
*bytes
= XNEWVEC (target_unit
, size
);
4343 constant_descriptor_rtx_data
*data
;
4344 hash_table
<const_rtx_data_hasher
> * htab
4345 = new hash_table
<const_rtx_data_hasher
> (31);
4347 FOR_EACH_VEC_ELT (vec
, i
, data
)
4349 buffer
.truncate (0);
4350 native_encode_rtx (data
->desc
->mode
, data
->desc
->constant
,
4351 buffer
, 0, data
->size
);
4352 memcpy (bytes
+ size
, buffer
.address (), data
->size
);
4353 data
->bytes
= bytes
+ size
;
4354 data
->hash
= iterative_hash (data
->bytes
,
4355 data
->size
* sizeof (target_unit
), 0);
4357 constant_descriptor_rtx_data
**slot
4358 = htab
->find_slot_with_hash (data
, data
->hash
, INSERT
);
4361 data
->desc
->mark
= ~(*slot
)->desc
->labelno
;
4362 data
->desc
->offset
= (*slot
)->offset
;
4366 unsigned int sz
= 1 << floor_log2 (data
->size
);
4369 for (sz
>>= 1; sz
>= min_size
; sz
>>= 1)
4370 for (unsigned off
= 0; off
+ sz
<= data
->size
; off
+= sz
)
4372 constant_descriptor_rtx_data tmp
;
4373 tmp
.desc
= data
->desc
;
4374 tmp
.bytes
= data
->bytes
+ off
;
4377 tmp
.hash
= iterative_hash (tmp
.bytes
,
4378 sz
* sizeof (target_unit
), 0);
4379 slot
= htab
->find_slot_with_hash (&tmp
, tmp
.hash
, INSERT
);
4382 *slot
= data_pool
.allocate ();
4391 data_pool
.release ();
4394 /* Mark all constants that are used in the current function, then write
4395 out the function's private constant pool. */
4398 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
4399 tree fndecl ATTRIBUTE_UNUSED
)
4401 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
4403 /* It is possible for gcc to call force_const_mem and then to later
4404 discard the instructions which refer to the constant. In such a
4405 case we do not need to output the constant. */
4406 mark_constant_pool ();
4408 /* Having marked the constant pool entries we'll actually emit, we
4409 now need to rebuild the offset information, which may have become
4411 recompute_pool_offsets (pool
);
4413 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4414 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4417 output_constant_pool_contents (pool
);
4419 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4420 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4424 /* Write the contents of the shared constant pool. */
4427 output_shared_constant_pool (void)
4430 && TARGET_SUPPORTS_ALIASES
)
4431 optimize_constant_pool (shared_constant_pool
);
4433 output_constant_pool_contents (shared_constant_pool
);
4436 /* Determine what kind of relocations EXP may need. */
4439 compute_reloc_for_constant (tree exp
)
4441 int reloc
= 0, reloc2
;
4444 switch (TREE_CODE (exp
))
4448 /* Go inside any operations that get_inner_reference can handle and see
4449 if what's inside is a constant: no need to do anything here for
4450 addresses of variables or functions. */
4451 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4452 tem
= TREE_OPERAND (tem
, 0))
4455 if (TREE_CODE (tem
) == MEM_REF
4456 && TREE_CODE (TREE_OPERAND (tem
, 0)) == ADDR_EXPR
)
4458 reloc
= compute_reloc_for_constant (TREE_OPERAND (tem
, 0));
4462 if (!targetm
.binds_local_p (tem
))
4469 case POINTER_PLUS_EXPR
:
4470 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4471 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4475 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4476 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4477 /* The difference of two local labels is computable at link time. */
4478 if (reloc
== 1 && reloc2
== 1)
4485 case VIEW_CONVERT_EXPR
:
4486 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4491 unsigned HOST_WIDE_INT idx
;
4492 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4494 reloc
|= compute_reloc_for_constant (tem
);
4504 /* Find all the constants whose addresses are referenced inside of EXP,
4505 and make sure assembler code with a label has been output for each one.
4506 Indicate whether an ADDR_EXPR has been encountered. */
4509 output_addressed_constants (tree exp
, int defer
)
4513 switch (TREE_CODE (exp
))
4517 /* Go inside any operations that get_inner_reference can handle and see
4518 if what's inside is a constant: no need to do anything here for
4519 addresses of variables or functions. */
4520 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4521 tem
= TREE_OPERAND (tem
, 0))
4524 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4525 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4526 tem
= DECL_INITIAL (tem
);
4528 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4529 output_constant_def (tem
, defer
);
4531 if (TREE_CODE (tem
) == MEM_REF
)
4532 output_addressed_constants (TREE_OPERAND (tem
, 0), defer
);
4536 case POINTER_PLUS_EXPR
:
4538 output_addressed_constants (TREE_OPERAND (exp
, 1), defer
);
4542 case VIEW_CONVERT_EXPR
:
4543 output_addressed_constants (TREE_OPERAND (exp
, 0), defer
);
4548 unsigned HOST_WIDE_INT idx
;
4549 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4551 output_addressed_constants (tem
, defer
);
4560 /* Whether a constructor CTOR is a valid static constant initializer if all
4561 its elements are. This used to be internal to initializer_constant_valid_p
4562 and has been exposed to let other functions like categorize_ctor_elements
4563 evaluate the property while walking a constructor for other purposes. */
4566 constructor_static_from_elts_p (const_tree ctor
)
4568 return (TREE_CONSTANT (ctor
)
4569 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4570 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
4571 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
4574 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4577 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4578 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4579 which are valid when ENDTYPE is an integer of any size; in
4580 particular, this does not accept a pointer minus a constant. This
4581 returns null_pointer_node if the VALUE is an absolute constant
4582 which can be used to initialize a static variable. Otherwise it
4586 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4590 if (!INTEGRAL_TYPE_P (endtype
))
4593 op0
= TREE_OPERAND (value
, 0);
4594 op1
= TREE_OPERAND (value
, 1);
4596 /* Like STRIP_NOPS except allow the operand mode to widen. This
4597 works around a feature of fold that simplifies (int)(p1 - p2) to
4598 ((int)p1 - (int)p2) under the theory that the narrower operation
4601 while (CONVERT_EXPR_P (op0
)
4602 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4604 tree inner
= TREE_OPERAND (op0
, 0);
4605 if (inner
== error_mark_node
4606 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4607 || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op0
)))
4608 > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner
)))))
4613 while (CONVERT_EXPR_P (op1
)
4614 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4616 tree inner
= TREE_OPERAND (op1
, 0);
4617 if (inner
== error_mark_node
4618 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4619 || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op1
)))
4620 > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner
)))))
4625 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4629 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4630 cache
? cache
+ 2 : NULL
);
4631 /* Both initializers must be known. */
4635 && (op0
== null_pointer_node
4636 || TREE_CODE (value
) == MINUS_EXPR
))
4637 return null_pointer_node
;
4639 /* Support differences between labels. */
4640 if (TREE_CODE (op0
) == LABEL_DECL
4641 && TREE_CODE (op1
) == LABEL_DECL
)
4642 return null_pointer_node
;
4644 if (TREE_CODE (op0
) == STRING_CST
4645 && TREE_CODE (op1
) == STRING_CST
4646 && operand_equal_p (op0
, op1
, 1))
4647 return null_pointer_node
;
4653 /* Helper function of initializer_constant_valid_p.
4654 Return nonzero if VALUE is a valid constant-valued expression
4655 for use in initializing a static variable; one that can be an
4656 element of a "constant" initializer.
4658 Return null_pointer_node if the value is absolute;
4659 if it is relocatable, return the variable that determines the relocation.
4660 We assume that VALUE has been folded as much as possible;
4661 therefore, we do not need to check for such things as
4662 arithmetic-combinations of integers.
4664 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4667 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4671 switch (TREE_CODE (value
))
4674 if (constructor_static_from_elts_p (value
))
4676 unsigned HOST_WIDE_INT idx
;
4678 bool absolute
= true;
4680 if (cache
&& cache
[0] == value
)
4682 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4685 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4688 /* An absolute value is required with reverse SSO. */
4689 || (reloc
!= null_pointer_node
4690 && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (value
))
4691 && !AGGREGATE_TYPE_P (TREE_TYPE (elt
))))
4696 cache
[1] = NULL_TREE
;
4700 if (reloc
!= null_pointer_node
)
4703 /* For a non-absolute relocation, there is no single
4704 variable that can be "the variable that determines the
4709 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4711 return absolute
? null_pointer_node
: error_mark_node
;
4714 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4722 return null_pointer_node
;
4727 tree op0
= staticp (TREE_OPERAND (value
, 0));
4730 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4731 to be a constant, this is old-skool offsetof-like nonsense. */
4732 if (TREE_CODE (op0
) == INDIRECT_REF
4733 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4734 return null_pointer_node
;
4735 /* Taking the address of a nested function involves a trampoline,
4736 unless we don't need or want one. */
4737 if (TREE_CODE (op0
) == FUNCTION_DECL
4738 && DECL_STATIC_CHAIN (op0
)
4739 && !TREE_NO_TRAMPOLINE (value
))
4741 /* "&{...}" requires a temporary to hold the constructed
4743 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4749 case NON_LVALUE_EXPR
:
4750 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4753 case VIEW_CONVERT_EXPR
:
4755 tree src
= TREE_OPERAND (value
, 0);
4756 tree src_type
= TREE_TYPE (src
);
4757 tree dest_type
= TREE_TYPE (value
);
4759 /* Allow view-conversions from aggregate to non-aggregate type only
4760 if the bit pattern is fully preserved afterwards; otherwise, the
4761 RTL expander won't be able to apply a subsequent transformation
4762 to the underlying constructor. */
4763 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4765 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4766 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4771 /* Allow all other kinds of view-conversion. */
4772 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4777 tree src
= TREE_OPERAND (value
, 0);
4778 tree src_type
= TREE_TYPE (src
);
4779 tree dest_type
= TREE_TYPE (value
);
4781 /* Allow conversions between pointer types, floating-point
4782 types, and offset types. */
4783 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4784 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4785 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4786 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4787 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4789 /* Allow length-preserving conversions between integer types. */
4790 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4791 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4792 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4794 /* Allow conversions between other integer types only if
4795 explicit value. Don't allow sign-extension to a type larger
4796 than word and pointer, there aren't relocations that would
4797 allow to sign extend it to a wider type. */
4798 if (INTEGRAL_TYPE_P (dest_type
)
4799 && INTEGRAL_TYPE_P (src_type
)
4800 && (TYPE_UNSIGNED (src_type
)
4801 || TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
)
4802 || TYPE_PRECISION (dest_type
) <= BITS_PER_WORD
4803 || TYPE_PRECISION (dest_type
) <= POINTER_SIZE
))
4805 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4806 if (inner
== null_pointer_node
)
4807 return null_pointer_node
;
4811 /* Allow (int) &foo provided int is as wide as a pointer. */
4812 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4813 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4814 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4816 /* Likewise conversions from int to pointers, but also allow
4817 conversions from 0. */
4818 if ((POINTER_TYPE_P (dest_type
)
4819 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4820 && INTEGRAL_TYPE_P (src_type
))
4822 if (TREE_CODE (src
) == INTEGER_CST
4823 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4824 return null_pointer_node
;
4825 if (integer_zerop (src
))
4826 return null_pointer_node
;
4827 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4828 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4831 /* Allow conversions to struct or union types if the value
4833 if (TREE_CODE (dest_type
) == RECORD_TYPE
4834 || TREE_CODE (dest_type
) == UNION_TYPE
)
4835 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4839 case POINTER_PLUS_EXPR
:
4841 /* Any valid floating-point constants will have been folded by now;
4842 with -frounding-math we hit this with addition of two constants. */
4843 if (TREE_CODE (endtype
) == REAL_TYPE
)
4845 if (cache
&& cache
[0] == value
)
4847 if (! INTEGRAL_TYPE_P (endtype
)
4848 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4850 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4852 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4855 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4856 endtype
, ncache
+ 2);
4857 /* If either term is absolute, use the other term's relocation. */
4858 if (valid0
== null_pointer_node
)
4860 else if (valid1
== null_pointer_node
)
4862 /* Support narrowing pointer differences. */
4864 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4868 /* Support narrowing pointer differences. */
4869 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4877 case POINTER_DIFF_EXPR
:
4879 if (TREE_CODE (endtype
) == REAL_TYPE
)
4881 if (cache
&& cache
[0] == value
)
4883 if (! INTEGRAL_TYPE_P (endtype
)
4884 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4886 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4888 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4891 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4892 endtype
, ncache
+ 2);
4893 /* Win if second argument is absolute. */
4894 if (valid1
== null_pointer_node
)
4896 /* Win if both arguments have the same relocation.
4897 Then the value is absolute. */
4898 else if (valid0
== valid1
&& valid0
!= 0)
4899 ret
= null_pointer_node
;
4900 /* Since GCC guarantees that string constants are unique in the
4901 generated code, a subtraction between two copies of the same
4902 constant string is absolute. */
4903 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4904 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4905 && operand_equal_p (valid0
, valid1
, 1))
4906 ret
= null_pointer_node
;
4907 /* Support narrowing differences. */
4909 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4913 /* Support narrowing differences. */
4914 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4929 /* Return nonzero if VALUE is a valid constant-valued expression
4930 for use in initializing a static variable; one that can be an
4931 element of a "constant" initializer.
4933 Return null_pointer_node if the value is absolute;
4934 if it is relocatable, return the variable that determines the relocation.
4935 We assume that VALUE has been folded as much as possible;
4936 therefore, we do not need to check for such things as
4937 arithmetic-combinations of integers. */
4939 initializer_constant_valid_p (tree value
, tree endtype
, bool reverse
)
4941 tree reloc
= initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4943 /* An absolute value is required with reverse storage order. */
4945 && reloc
!= null_pointer_node
4947 && !AGGREGATE_TYPE_P (endtype
)
4948 && !VECTOR_TYPE_P (endtype
))
4954 /* Return true if VALUE is a valid constant-valued expression
4955 for use in initializing a static bit-field; one that can be
4956 an element of a "constant" initializer. */
4959 initializer_constant_valid_for_bitfield_p (tree value
)
4961 /* For bitfields we support integer constants or possibly nested aggregates
4963 switch (TREE_CODE (value
))
4967 unsigned HOST_WIDE_INT idx
;
4970 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4971 if (!initializer_constant_valid_for_bitfield_p (elt
))
4980 case VIEW_CONVERT_EXPR
:
4981 case NON_LVALUE_EXPR
:
4983 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4992 /* Check if a STRING_CST fits into the field.
4993 Tolerate only the case when the NUL termination
4994 does not fit into the field. */
4997 check_string_literal (tree string
, unsigned HOST_WIDE_INT size
)
4999 tree type
= TREE_TYPE (string
);
5000 tree eltype
= TREE_TYPE (type
);
5001 unsigned HOST_WIDE_INT elts
= tree_to_uhwi (TYPE_SIZE_UNIT (eltype
));
5002 unsigned HOST_WIDE_INT mem_size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
5003 int len
= TREE_STRING_LENGTH (string
);
5005 if (elts
!= 1 && elts
!= 2 && elts
!= 4)
5007 if (len
< 0 || len
% elts
!= 0)
5009 if (size
< (unsigned)len
)
5011 if (mem_size
!= size
)
5016 /* output_constructor outer state of relevance in recursive calls, typically
5017 for nested aggregate bitfields. */
5019 struct oc_outer_state
{
5020 unsigned int bit_offset
; /* current position in ... */
5021 int byte
; /* ... the outer byte buffer. */
5024 static unsigned HOST_WIDE_INT
5025 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int, bool,
5028 /* Output assembler code for constant EXP, with no label.
5029 This includes the pseudo-op such as ".int" or ".byte", and a newline.
5030 Assumes output_addressed_constants has been done on EXP already.
5032 Generate at least SIZE bytes of assembler data, padding at the end
5033 with zeros if necessary. SIZE must always be specified. The returned
5034 value is the actual number of bytes of assembler data generated, which
5035 may be bigger than SIZE if the object contains a variable length field.
5037 SIZE is important for structure constructors,
5038 since trailing members may have been omitted from the constructor.
5039 It is also important for initialization of arrays from string constants
5040 since the full length of the string constant might not be wanted.
5041 It is also needed for initialization of unions, where the initializer's
5042 type is just one member, and that may not be as long as the union.
5044 There a case in which we would fail to output exactly SIZE bytes:
5045 for a structure constructor that wants to produce more than SIZE bytes.
5046 But such constructors will never be generated for any possible input.
5048 ALIGN is the alignment of the data in bits.
5050 If REVERSE is true, EXP is output in reverse storage order. */
5052 static unsigned HOST_WIDE_INT
5053 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
,
5054 bool reverse
, bool merge_strings
)
5056 enum tree_code code
;
5057 unsigned HOST_WIDE_INT thissize
;
5060 if (size
== 0 || flag_syntax_only
)
5063 /* See if we're trying to initialize a pointer in a non-default mode
5064 to the address of some declaration somewhere. If the target says
5065 the mode is valid for pointers, assume the target has a way of
5067 if (TREE_CODE (exp
) == NOP_EXPR
5068 && POINTER_TYPE_P (TREE_TYPE (exp
))
5069 && targetm
.addr_space
.valid_pointer_mode
5070 (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp
)),
5071 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
5073 tree saved_type
= TREE_TYPE (exp
);
5075 /* Peel off any intermediate conversions-to-pointer for valid
5077 while (TREE_CODE (exp
) == NOP_EXPR
5078 && POINTER_TYPE_P (TREE_TYPE (exp
))
5079 && targetm
.addr_space
.valid_pointer_mode
5080 (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp
)),
5081 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
5082 exp
= TREE_OPERAND (exp
, 0);
5084 /* If what we're left with is the address of something, we can
5085 convert the address to the final type and output it that
5087 if (TREE_CODE (exp
) == ADDR_EXPR
)
5088 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
5089 /* Likewise for constant ints. */
5090 else if (TREE_CODE (exp
) == INTEGER_CST
)
5091 exp
= fold_convert (saved_type
, exp
);
5095 /* Eliminate any conversions since we'll be outputting the underlying
5097 while (CONVERT_EXPR_P (exp
)
5098 || TREE_CODE (exp
) == NON_LVALUE_EXPR
5099 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
5101 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
5102 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
5104 /* Make sure eliminating the conversion is really a no-op, except with
5105 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
5106 union types to allow for Ada unchecked unions. */
5107 if (type_size
> op_size
5108 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
5109 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
5110 /* Keep the conversion. */
5113 exp
= TREE_OPERAND (exp
, 0);
5116 code
= TREE_CODE (TREE_TYPE (exp
));
5117 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
5119 /* Allow a constructor with no elements for any data type.
5120 This means to fill the space with zeros. */
5121 if (TREE_CODE (exp
) == CONSTRUCTOR
5122 && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp
)))
5124 assemble_zeros (size
);
5128 if (TREE_CODE (exp
) == FDESC_EXPR
)
5130 #ifdef ASM_OUTPUT_FDESC
5131 HOST_WIDE_INT part
= tree_to_shwi (TREE_OPERAND (exp
, 1));
5132 tree decl
= TREE_OPERAND (exp
, 0);
5133 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
5140 /* Now output the underlying data. If we've handling the padding, return.
5141 Otherwise, break and ensure SIZE is the size written. */
5148 case REFERENCE_TYPE
:
5150 case FIXED_POINT_TYPE
:
5152 cst
= expand_expr (exp
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
5154 cst
= flip_storage_order (TYPE_MODE (TREE_TYPE (exp
)), cst
);
5155 if (!assemble_integer (cst
, MIN (size
, thissize
), align
, 0))
5156 error ("initializer for integer/fixed-point value is too complicated");
5160 if (TREE_CODE (exp
) != REAL_CST
)
5161 error ("initializer for floating value is not a floating constant");
5163 assemble_real (TREE_REAL_CST (exp
),
5164 SCALAR_FLOAT_TYPE_MODE (TREE_TYPE (exp
)),
5169 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
,
5171 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
5172 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)),
5178 switch (TREE_CODE (exp
))
5181 return output_constructor (exp
, size
, align
, reverse
, NULL
);
5183 thissize
= (unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
);
5186 || TREE_STRING_POINTER (exp
) [thissize
- 1] != '\0'))
5188 gcc_checking_assert (check_string_literal (exp
, size
));
5189 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
5193 scalar_mode inner
= SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
5194 unsigned int nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
5195 int elt_size
= GET_MODE_SIZE (inner
);
5196 output_constant (VECTOR_CST_ELT (exp
, 0), elt_size
, align
,
5198 thissize
= elt_size
;
5199 /* Static constants must have a fixed size. */
5200 unsigned int nunits
= VECTOR_CST_NELTS (exp
).to_constant ();
5201 for (unsigned int i
= 1; i
< nunits
; i
++)
5203 output_constant (VECTOR_CST_ELT (exp
, i
), elt_size
, nalign
,
5205 thissize
+= elt_size
;
5216 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
5217 return output_constructor (exp
, size
, align
, reverse
, NULL
);
5226 if (size
> thissize
)
5227 assemble_zeros (size
- thissize
);
5232 /* Subroutine of output_constructor, used for computing the size of
5233 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
5234 type with an unspecified upper bound. */
5236 static unsigned HOST_WIDE_INT
5237 array_size_for_constructor (tree val
)
5240 unsigned HOST_WIDE_INT cnt
;
5241 tree index
, value
, tmp
;
5244 /* This code used to attempt to handle string constants that are not
5245 arrays of single-bytes, but nothing else does, so there's no point in
5247 if (TREE_CODE (val
) == STRING_CST
)
5248 return TREE_STRING_LENGTH (val
);
5250 max_index
= NULL_TREE
;
5251 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
5253 if (TREE_CODE (index
) == RANGE_EXPR
)
5254 index
= TREE_OPERAND (index
, 1);
5255 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
5259 if (max_index
== NULL_TREE
)
5262 /* Compute the total number of array elements. */
5263 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
5264 i
= wi::to_offset (max_index
) - wi::to_offset (tmp
) + 1;
5266 /* Multiply by the array element unit size to find number of bytes. */
5267 i
*= wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
5269 gcc_assert (wi::fits_uhwi_p (i
));
5270 return i
.to_uhwi ();
5273 /* Other datastructures + helpers for output_constructor. */
5275 /* output_constructor local state to support interaction with helpers. */
5277 struct oc_local_state
{
5279 /* Received arguments. */
5280 tree exp
; /* Constructor expression. */
5281 tree type
; /* Type of constructor expression. */
5282 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
5283 unsigned int align
; /* Known initial alignment. */
5284 tree min_index
; /* Lower bound if specified for an array. */
5286 /* Output processing state. */
5287 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
5288 int byte
; /* Part of a bitfield byte yet to be output. */
5289 int last_relative_index
; /* Implicit or explicit index of the last
5290 array element output within a bitfield. */
5291 bool byte_buffer_in_use
; /* Whether BYTE is in use. */
5292 bool reverse
; /* Whether reverse storage order is in use. */
5294 /* Current element. */
5295 tree field
; /* Current field decl in a record. */
5296 tree val
; /* Current element value. */
5297 tree index
; /* Current element index. */
5301 /* Helper for output_constructor. From the current LOCAL state, output a
5302 RANGE_EXPR element. */
5305 output_constructor_array_range (oc_local_state
*local
)
5307 /* Perform the index calculation in modulo arithmetic but
5308 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5309 but we are using an unsigned sizetype. */
5310 unsigned prec
= TYPE_PRECISION (sizetype
);
5311 offset_int idx
= wi::sext (wi::to_offset (TREE_OPERAND (local
->index
, 0))
5312 - wi::to_offset (local
->min_index
), prec
);
5313 tree valtype
= TREE_TYPE (local
->val
);
5314 HOST_WIDE_INT fieldpos
5315 = (idx
* wi::to_offset (TYPE_SIZE_UNIT (valtype
))).to_short_addr ();
5317 /* Advance to offset of this element. */
5318 if (fieldpos
> local
->total_bytes
)
5320 assemble_zeros (fieldpos
- local
->total_bytes
);
5321 local
->total_bytes
= fieldpos
;
5324 /* Must not go backwards. */
5325 gcc_assert (fieldpos
== local
->total_bytes
);
5327 unsigned HOST_WIDE_INT fieldsize
5328 = int_size_in_bytes (TREE_TYPE (local
->type
));
5330 HOST_WIDE_INT lo_index
5331 = tree_to_shwi (TREE_OPERAND (local
->index
, 0));
5332 HOST_WIDE_INT hi_index
5333 = tree_to_shwi (TREE_OPERAND (local
->index
, 1));
5334 HOST_WIDE_INT index
;
5337 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
5339 for (index
= lo_index
; index
<= hi_index
; index
++)
5341 /* Output the element's initial value. */
5342 if (local
->val
== NULL_TREE
)
5343 assemble_zeros (fieldsize
);
5345 fieldsize
= output_constant (local
->val
, fieldsize
, align2
,
5346 local
->reverse
, false);
5348 /* Count its size. */
5349 local
->total_bytes
+= fieldsize
;
5353 /* Helper for output_constructor. From the current LOCAL state, output a
5354 field element that is not true bitfield or part of an outer one. */
5357 output_constructor_regular_field (oc_local_state
*local
)
5359 /* Field size and position. Since this structure is static, we know the
5360 positions are constant. */
5361 unsigned HOST_WIDE_INT fieldsize
;
5362 HOST_WIDE_INT fieldpos
;
5364 unsigned int align2
;
5366 /* Output any buffered-up bit-fields preceding this element. */
5367 if (local
->byte_buffer_in_use
)
5369 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5370 local
->total_bytes
++;
5371 local
->byte_buffer_in_use
= false;
5374 if (local
->index
!= NULL_TREE
)
5376 /* Perform the index calculation in modulo arithmetic but
5377 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5378 but we are using an unsigned sizetype. */
5379 unsigned prec
= TYPE_PRECISION (sizetype
);
5380 offset_int idx
= wi::sext (wi::to_offset (local
->index
)
5381 - wi::to_offset (local
->min_index
), prec
);
5382 fieldpos
= (idx
* wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
))))
5385 else if (local
->field
!= NULL_TREE
)
5386 fieldpos
= int_byte_position (local
->field
);
5390 /* Advance to offset of this element.
5391 Note no alignment needed in an array, since that is guaranteed
5392 if each element has the proper size. */
5393 if (local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
5395 if (fieldpos
> local
->total_bytes
)
5397 assemble_zeros (fieldpos
- local
->total_bytes
);
5398 local
->total_bytes
= fieldpos
;
5401 /* Must not go backwards. */
5402 gcc_assert (fieldpos
== local
->total_bytes
);
5405 /* Find the alignment of this element. */
5406 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
5408 /* Determine size this element should occupy. */
5413 /* If this is an array with an unspecified upper bound,
5414 the initializer determines the size. */
5415 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5416 but we cannot do this until the deprecated support for
5417 initializing zero-length array members is removed. */
5418 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
5419 && (!TYPE_DOMAIN (TREE_TYPE (local
->field
))
5420 || !TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
)))))
5422 fieldsize
= array_size_for_constructor (local
->val
);
5423 /* Given a non-empty initialization, this field had better
5424 be last. Given a flexible array member, the next field
5425 on the chain is a TYPE_DECL of the enclosing struct. */
5426 const_tree next
= DECL_CHAIN (local
->field
);
5427 gcc_assert (!fieldsize
|| !next
|| TREE_CODE (next
) != FIELD_DECL
);
5428 tree size
= TYPE_SIZE_UNIT (TREE_TYPE (local
->val
));
5429 gcc_checking_assert (compare_tree_int (size
, fieldsize
) == 0);
5432 fieldsize
= tree_to_uhwi (DECL_SIZE_UNIT (local
->field
));
5435 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
5437 /* Output the element's initial value. */
5438 if (local
->val
== NULL_TREE
)
5439 assemble_zeros (fieldsize
);
5441 fieldsize
= output_constant (local
->val
, fieldsize
, align2
,
5442 local
->reverse
, false);
5444 /* Count its size. */
5445 local
->total_bytes
+= fieldsize
;
5448 /* Helper for output_constructor. From the LOCAL state, output an element
5449 that is a true bitfield or part of an outer one. BIT_OFFSET is the offset
5450 from the start of a possibly ongoing outer byte buffer. */
5453 output_constructor_bitfield (oc_local_state
*local
, unsigned int bit_offset
)
5455 /* Bit size of this element. */
5456 HOST_WIDE_INT ebitsize
5458 ? tree_to_uhwi (DECL_SIZE (local
->field
))
5459 : tree_to_uhwi (TYPE_SIZE (TREE_TYPE (local
->type
))));
5461 /* Relative index of this element if this is an array component. */
5462 HOST_WIDE_INT relative_index
5465 ? (tree_to_shwi (local
->index
)
5466 - tree_to_shwi (local
->min_index
))
5467 : local
->last_relative_index
+ 1)
5470 /* Bit position of this element from the start of the containing
5472 HOST_WIDE_INT constructor_relative_ebitpos
5474 ? int_bit_position (local
->field
)
5475 : ebitsize
* relative_index
);
5477 /* Bit position of this element from the start of a possibly ongoing
5478 outer byte buffer. */
5479 HOST_WIDE_INT byte_relative_ebitpos
5480 = bit_offset
+ constructor_relative_ebitpos
;
5482 /* From the start of a possibly ongoing outer byte buffer, offsets to
5483 the first bit of this element and to the first bit past the end of
5485 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
5486 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
5488 local
->last_relative_index
= relative_index
;
5490 if (local
->val
== NULL_TREE
)
5491 local
->val
= integer_zero_node
;
5493 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
5494 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
5495 local
->val
= TREE_OPERAND (local
->val
, 0);
5497 if (TREE_CODE (local
->val
) != INTEGER_CST
5498 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
5500 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
5504 /* If this field does not start in this (or next) byte, skip some bytes. */
5505 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5507 /* Output remnant of any bit field in previous bytes. */
5508 if (local
->byte_buffer_in_use
)
5510 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5511 local
->total_bytes
++;
5512 local
->byte_buffer_in_use
= false;
5515 /* If still not at proper byte, advance to there. */
5516 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5518 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
5519 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
5520 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
5524 /* Set up the buffer if necessary. */
5525 if (!local
->byte_buffer_in_use
)
5529 local
->byte_buffer_in_use
= true;
5532 /* If this is nested constructor, recurse passing the bit offset and the
5533 pending data, then retrieve the new pending data afterwards. */
5534 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
5536 oc_outer_state temp_state
;
5537 temp_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
5538 temp_state
.byte
= local
->byte
;
5540 += output_constructor (local
->val
, 0, 0, local
->reverse
, &temp_state
);
5541 local
->byte
= temp_state
.byte
;
5545 /* Otherwise, we must split the element into pieces that fall within
5546 separate bytes, and combine each byte with previous or following
5548 while (next_offset
< end_offset
)
5552 unsigned HOST_WIDE_INT value
;
5553 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5554 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5556 /* Advance from byte to byte within this element when necessary. */
5557 while (next_byte
!= local
->total_bytes
)
5559 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5560 local
->total_bytes
++;
5564 /* Number of bits we can process at once (all part of the same byte). */
5565 this_time
= MIN (end_offset
- next_offset
, BITS_PER_UNIT
- next_bit
);
5566 if (local
->reverse
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
)
5568 /* For big-endian data, take the most significant bits (of the
5569 bits that are significant) first and put them into bytes from
5570 the most significant end. */
5571 shift
= end_offset
- next_offset
- this_time
;
5573 /* Don't try to take a bunch of bits that cross
5574 the word boundary in the INTEGER_CST. We can
5575 only select bits from one element. */
5576 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5577 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5579 const int end
= shift
+ this_time
- 1;
5580 shift
= end
& -HOST_BITS_PER_WIDE_INT
;
5581 this_time
= end
- shift
+ 1;
5584 /* Now get the bits we want to insert. */
5585 value
= wi::extract_uhwi (wi::to_widest (local
->val
),
5588 /* Get the result. This works only when:
5589 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5590 local
->byte
|= value
<< (BITS_PER_UNIT
- this_time
- next_bit
);
5594 /* On little-endian machines, take the least significant bits of
5595 the value first and pack them starting at the least significant
5596 bits of the bytes. */
5597 shift
= next_offset
- byte_relative_ebitpos
;
5599 /* Don't try to take a bunch of bits that cross
5600 the word boundary in the INTEGER_CST. We can
5601 only select bits from one element. */
5602 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5603 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5605 = HOST_BITS_PER_WIDE_INT
- (shift
& (HOST_BITS_PER_WIDE_INT
- 1));
5607 /* Now get the bits we want to insert. */
5608 value
= wi::extract_uhwi (wi::to_widest (local
->val
),
5611 /* Get the result. This works only when:
5612 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5613 local
->byte
|= value
<< next_bit
;
5616 next_offset
+= this_time
;
5617 local
->byte_buffer_in_use
= true;
5621 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5622 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5623 caller output state of relevance in recursive invocations. */
5625 static unsigned HOST_WIDE_INT
5626 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
,
5627 bool reverse
, oc_outer_state
*outer
)
5629 unsigned HOST_WIDE_INT cnt
;
5630 constructor_elt
*ce
;
5631 oc_local_state local
;
5633 /* Setup our local state to communicate with helpers. */
5635 local
.type
= TREE_TYPE (exp
);
5637 local
.align
= align
;
5638 if (TREE_CODE (local
.type
) == ARRAY_TYPE
&& TYPE_DOMAIN (local
.type
))
5639 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5641 local
.min_index
= integer_zero_node
;
5643 local
.total_bytes
= 0;
5644 local
.byte_buffer_in_use
= outer
!= NULL
;
5645 local
.byte
= outer
? outer
->byte
: 0;
5646 local
.last_relative_index
= -1;
5647 /* The storage order is specified for every aggregate type. */
5648 if (AGGREGATE_TYPE_P (local
.type
))
5649 local
.reverse
= TYPE_REVERSE_STORAGE_ORDER (local
.type
);
5651 local
.reverse
= reverse
;
5653 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5655 /* As CE goes through the elements of the constant, FIELD goes through the
5656 structure fields if the constant is a structure. If the constant is a
5657 union, we override this by getting the field from the TREE_LIST element.
5658 But the constant could also be an array. Then FIELD is zero.
5660 There is always a maximum of one element in the chain LINK for unions
5661 (even if the initializer in a source program incorrectly contains
5664 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5665 local
.field
= TYPE_FIELDS (local
.type
);
5667 local
.field
= NULL_TREE
;
5670 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), cnt
, &ce
);
5671 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
5673 local
.val
= ce
->value
;
5674 local
.index
= NULL_TREE
;
5676 /* The element in a union constructor specifies the proper field
5678 if (RECORD_OR_UNION_TYPE_P (local
.type
) && ce
->index
!= NULL_TREE
)
5679 local
.field
= ce
->index
;
5681 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5682 local
.index
= ce
->index
;
5684 if (local
.field
&& flag_verbose_asm
)
5685 fprintf (asm_out_file
, "%s %s:\n",
5687 DECL_NAME (local
.field
)
5688 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5691 /* Eliminate the marker that makes a cast not be an lvalue. */
5692 if (local
.val
!= NULL_TREE
)
5693 STRIP_NOPS (local
.val
);
5695 /* Output the current element, using the appropriate helper ... */
5697 /* For an array slice not part of an outer bitfield. */
5699 && local
.index
!= NULL_TREE
5700 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5701 output_constructor_array_range (&local
);
5703 /* For a field that is neither a true bitfield nor part of an outer one,
5704 known to be at least byte aligned and multiple-of-bytes long. */
5706 && (local
.field
== NULL_TREE
5707 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5708 output_constructor_regular_field (&local
);
5710 /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
5711 supported for scalar fields, so we may need to convert first. */
5714 if (TREE_CODE (local
.val
) == REAL_CST
)
5716 = fold_unary (VIEW_CONVERT_EXPR
,
5717 build_nonstandard_integer_type
5718 (TYPE_PRECISION (TREE_TYPE (local
.val
)), 0),
5720 output_constructor_bitfield (&local
, outer
? outer
->bit_offset
: 0);
5724 /* If we are not at toplevel, save the pending data for our caller.
5725 Otherwise output the pending data and padding zeros as needed. */
5727 outer
->byte
= local
.byte
;
5730 if (local
.byte_buffer_in_use
)
5732 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5733 local
.total_bytes
++;
5736 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5738 assemble_zeros (local
.size
- local
.total_bytes
);
5739 local
.total_bytes
= local
.size
;
5743 return local
.total_bytes
;
5746 /* Mark DECL as weak. */
5749 mark_weak (tree decl
)
5751 if (DECL_WEAK (decl
))
5754 struct symtab_node
*n
= symtab_node::get (decl
);
5755 if (n
&& n
->refuse_visibility_changes
)
5756 error ("%+qD declared weak after being used", decl
);
5757 DECL_WEAK (decl
) = 1;
5759 if (DECL_RTL_SET_P (decl
)
5760 && MEM_P (DECL_RTL (decl
))
5761 && XEXP (DECL_RTL (decl
), 0)
5762 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5763 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5766 /* Merge weak status between NEWDECL and OLDDECL. */
5769 merge_weak (tree newdecl
, tree olddecl
)
5771 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5773 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5776 /* We put the NEWDECL on the weak_decls list at some point
5777 and OLDDECL as well. Keep just OLDDECL on the list. */
5778 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5779 if (TREE_VALUE (*pwd
) == newdecl
)
5781 *pwd
= TREE_CHAIN (*pwd
);
5788 if (DECL_WEAK (newdecl
))
5792 /* NEWDECL is weak, but OLDDECL is not. */
5794 /* If we already output the OLDDECL, we're in trouble; we can't
5795 go back and make it weak. This should never happen in
5796 unit-at-a-time compilation. */
5797 gcc_assert (!TREE_ASM_WRITTEN (olddecl
));
5799 /* If we've already generated rtl referencing OLDDECL, we may
5800 have done so in a way that will not function properly with
5801 a weak symbol. Again in unit-at-a-time this should be
5803 gcc_assert (!TREE_USED (olddecl
)
5804 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)));
5806 /* PR 49899: You cannot convert a static function into a weak, public function. */
5807 if (! TREE_PUBLIC (olddecl
) && TREE_PUBLIC (newdecl
))
5808 error ("weak declaration of %q+D being applied to a already "
5809 "existing, static definition", newdecl
);
5811 if (TARGET_SUPPORTS_WEAK
)
5813 /* We put the NEWDECL on the weak_decls list at some point.
5814 Replace it with the OLDDECL. */
5815 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5816 if (TREE_VALUE (wd
) == newdecl
)
5818 TREE_VALUE (wd
) = olddecl
;
5821 /* We may not find the entry on the list. If NEWDECL is a
5822 weak alias, then we will have already called
5823 globalize_decl to remove the entry; in that case, we do
5824 not need to do anything. */
5827 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5828 mark_weak (olddecl
);
5831 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5832 weak. Just update NEWDECL to indicate that it's weak too. */
5833 mark_weak (newdecl
);
5836 /* Declare DECL to be a weak symbol. */
5839 declare_weak (tree decl
)
5841 gcc_assert (TREE_CODE (decl
) != FUNCTION_DECL
|| !TREE_ASM_WRITTEN (decl
));
5842 if (! TREE_PUBLIC (decl
))
5844 error ("weak declaration of %q+D must be public", decl
);
5847 else if (!TARGET_SUPPORTS_WEAK
)
5848 warning (0, "weak declaration of %q+D not supported", decl
);
5851 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5852 DECL_ATTRIBUTES (decl
)
5853 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5857 weak_finish_1 (tree decl
)
5859 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5860 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5863 if (! TREE_USED (decl
))
5866 #ifdef ASM_WEAKEN_DECL
5867 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5869 #ifdef ASM_WEAKEN_LABEL
5870 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5872 #ifdef ASM_OUTPUT_WEAK_ALIAS
5874 static bool warn_once
= 0;
5877 warning (0, "only weak aliases are supported in this configuration");
5887 /* Fiven an assembly name, find the decl it is associated with. */
5889 find_decl (tree target
)
5891 symtab_node
*node
= symtab_node::get_for_asmname (target
);
5897 /* This TREE_LIST contains weakref targets. */
5899 static GTY(()) tree weakref_targets
;
5901 /* Emit any pending weak declarations. */
5908 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5910 tree alias_decl
= TREE_PURPOSE (t
);
5911 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5913 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
))
5914 || TREE_SYMBOL_REFERENCED (target
))
5915 /* Remove alias_decl from the weak list, but leave entries for
5916 the target alone. */
5918 #ifndef ASM_OUTPUT_WEAKREF
5919 else if (! TREE_SYMBOL_REFERENCED (target
))
5921 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5922 defined, otherwise we and weak_finish_1 would use
5923 different macros. */
5924 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5925 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5927 tree decl
= find_decl (target
);
5931 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5932 TREE_CODE (alias_decl
), target
,
5933 TREE_TYPE (alias_decl
));
5935 DECL_EXTERNAL (decl
) = 1;
5936 TREE_PUBLIC (decl
) = 1;
5937 DECL_ARTIFICIAL (decl
) = 1;
5938 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5939 TREE_USED (decl
) = 1;
5942 weak_finish_1 (decl
);
5951 /* Remove the alias and the target from the pending weak list
5952 so that we do not emit any .weak directives for the former,
5953 nor multiple .weak directives for the latter. */
5954 for (p
= &weak_decls
; (t2
= *p
) ; )
5956 if (TREE_VALUE (t2
) == alias_decl
5957 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5958 *p
= TREE_CHAIN (t2
);
5960 p
= &TREE_CHAIN (t2
);
5963 /* Remove other weakrefs to the same target, to speed things up. */
5964 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5966 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5967 *p
= TREE_CHAIN (t2
);
5969 p
= &TREE_CHAIN (t2
);
5974 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5976 tree decl
= TREE_VALUE (t
);
5978 weak_finish_1 (decl
);
5982 /* Emit the assembly bits to indicate that DECL is globally visible. */
5985 globalize_decl (tree decl
)
5988 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5989 if (DECL_WEAK (decl
))
5991 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5994 #ifdef ASM_WEAKEN_DECL
5995 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5997 ASM_WEAKEN_LABEL (asm_out_file
, name
);
6000 /* Remove this function from the pending weak list so that
6001 we do not emit multiple .weak directives for it. */
6002 for (p
= &weak_decls
; (t
= *p
) ; )
6004 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
6005 *p
= TREE_CHAIN (t
);
6007 p
= &TREE_CHAIN (t
);
6010 /* Remove weakrefs to the same target from the pending weakref
6011 list, for the same reason. */
6012 for (p
= &weakref_targets
; (t
= *p
) ; )
6014 if (DECL_ASSEMBLER_NAME (decl
)
6015 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
6016 *p
= TREE_CHAIN (t
);
6018 p
= &TREE_CHAIN (t
);
6025 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
6028 vec
<alias_pair
, va_gc
> *alias_pairs
;
6030 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
6031 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
6032 tree node is DECL to have the value of the tree node TARGET. */
6035 do_assemble_alias (tree decl
, tree target
)
6039 /* Emulated TLS had better not get this var. */
6040 gcc_assert (!(!targetm
.have_tls
6042 && DECL_THREAD_LOCAL_P (decl
)));
6044 if (TREE_ASM_WRITTEN (decl
))
6047 id
= DECL_ASSEMBLER_NAME (decl
);
6048 ultimate_transparent_alias_target (&id
);
6049 ultimate_transparent_alias_target (&target
);
6051 /* We must force creation of DECL_RTL for debug info generation, even though
6052 we don't use it here. */
6053 make_decl_rtl (decl
);
6055 TREE_ASM_WRITTEN (decl
) = 1;
6056 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
6057 TREE_ASM_WRITTEN (id
) = 1;
6059 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
6061 if (!TREE_SYMBOL_REFERENCED (target
))
6062 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
6064 #ifdef ASM_OUTPUT_WEAKREF
6065 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
6066 IDENTIFIER_POINTER (id
),
6067 IDENTIFIER_POINTER (target
));
6069 if (!TARGET_SUPPORTS_WEAK
)
6071 error_at (DECL_SOURCE_LOCATION (decl
),
6072 "weakref is not supported in this configuration");
6079 #ifdef ASM_OUTPUT_DEF
6080 tree orig_decl
= decl
;
6082 /* Make name accessible from other files, if appropriate. */
6084 if (TREE_PUBLIC (decl
) || TREE_PUBLIC (orig_decl
))
6086 globalize_decl (decl
);
6087 maybe_assemble_visibility (decl
);
6089 if (TREE_CODE (decl
) == FUNCTION_DECL
6090 && cgraph_node::get (decl
)->ifunc_resolver
)
6092 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
6093 if (targetm
.has_ifunc_p ())
6094 ASM_OUTPUT_TYPE_DIRECTIVE
6095 (asm_out_file
, IDENTIFIER_POINTER (id
),
6099 error_at (DECL_SOURCE_LOCATION (decl
),
6100 "%qs is not supported on this target", "ifunc");
6103 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
6104 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
6106 ASM_OUTPUT_DEF (asm_out_file
,
6107 IDENTIFIER_POINTER (id
),
6108 IDENTIFIER_POINTER (target
));
6110 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
6115 name
= IDENTIFIER_POINTER (id
);
6116 # ifdef ASM_WEAKEN_DECL
6117 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
6119 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
6121 /* Remove this function from the pending weak list so that
6122 we do not emit multiple .weak directives for it. */
6123 for (p
= &weak_decls
; (t
= *p
) ; )
6124 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
))
6125 || id
== DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
6126 *p
= TREE_CHAIN (t
);
6128 p
= &TREE_CHAIN (t
);
6130 /* Remove weakrefs to the same target from the pending weakref
6131 list, for the same reason. */
6132 for (p
= &weakref_targets
; (t
= *p
) ; )
6134 if (id
== ultimate_transparent_alias_target (&TREE_VALUE (t
)))
6135 *p
= TREE_CHAIN (t
);
6137 p
= &TREE_CHAIN (t
);
6143 /* Output .symver directive. */
6146 do_assemble_symver (tree decl
, tree target
)
6148 tree id
= DECL_ASSEMBLER_NAME (decl
);
6149 ultimate_transparent_alias_target (&id
);
6150 ultimate_transparent_alias_target (&target
);
6151 #ifdef ASM_OUTPUT_SYMVER_DIRECTIVE
6152 ASM_OUTPUT_SYMVER_DIRECTIVE (asm_out_file
,
6153 IDENTIFIER_POINTER (target
),
6154 IDENTIFIER_POINTER (id
));
6156 error ("symver is only supported on ELF platforms");
6160 /* Emit an assembler directive to make the symbol for DECL an alias to
6161 the symbol for TARGET. */
6164 assemble_alias (tree decl
, tree target
)
6168 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
6170 tree alias
= DECL_ASSEMBLER_NAME (decl
);
6172 ultimate_transparent_alias_target (&target
);
6174 if (alias
== target
)
6175 error ("%qs symbol %q+D ultimately targets itself", "weakref", decl
);
6176 if (TREE_PUBLIC (decl
))
6177 error ("%qs symbol %q+D must have static linkage", "weakref", decl
);
6181 #if !defined (ASM_OUTPUT_DEF)
6182 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
6183 error_at (DECL_SOURCE_LOCATION (decl
),
6184 "alias definitions not supported in this configuration");
6185 TREE_ASM_WRITTEN (decl
) = 1;
6188 if (!DECL_WEAK (decl
))
6190 /* NB: ifunc_resolver isn't set when an error is detected. */
6191 if (TREE_CODE (decl
) == FUNCTION_DECL
6192 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
6193 error_at (DECL_SOURCE_LOCATION (decl
),
6194 "%qs is not supported in this configuration", "ifunc");
6196 error_at (DECL_SOURCE_LOCATION (decl
),
6197 "only weak aliases are supported in this configuration");
6198 TREE_ASM_WRITTEN (decl
) = 1;
6204 TREE_USED (decl
) = 1;
6206 /* Allow aliases to aliases. */
6207 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6208 cgraph_node::get_create (decl
)->alias
= true;
6210 varpool_node::get_create (decl
)->alias
= true;
6212 /* If the target has already been emitted, we don't have to queue the
6213 alias. This saves a tad of memory. */
6214 if (symtab
->global_info_ready
)
6215 target_decl
= find_decl (target
);
6218 if ((target_decl
&& TREE_ASM_WRITTEN (target_decl
))
6219 || symtab
->state
>= EXPANSION
)
6220 do_assemble_alias (decl
, target
);
6223 alias_pair p
= {decl
, target
};
6224 vec_safe_push (alias_pairs
, p
);
6228 /* Record and output a table of translations from original function
6229 to its transaction aware clone. Note that tm_pure functions are
6230 considered to be their own clone. */
6232 struct tm_clone_hasher
: ggc_cache_ptr_hash
<tree_map
>
6234 static hashval_t
hash (tree_map
*m
) { return tree_map_hash (m
); }
6235 static bool equal (tree_map
*a
, tree_map
*b
) { return tree_map_eq (a
, b
); }
6238 keep_cache_entry (tree_map
*&e
)
6240 return ggc_marked_p (e
->base
.from
);
6244 static GTY((cache
)) hash_table
<tm_clone_hasher
> *tm_clone_hash
;
6247 record_tm_clone_pair (tree o
, tree n
)
6249 struct tree_map
**slot
, *h
;
6251 if (tm_clone_hash
== NULL
)
6252 tm_clone_hash
= hash_table
<tm_clone_hasher
>::create_ggc (32);
6254 h
= ggc_alloc
<tree_map
> ();
6255 h
->hash
= htab_hash_pointer (o
);
6259 slot
= tm_clone_hash
->find_slot_with_hash (h
, h
->hash
, INSERT
);
6264 get_tm_clone_pair (tree o
)
6268 struct tree_map
*h
, in
;
6271 in
.hash
= htab_hash_pointer (o
);
6272 h
= tm_clone_hash
->find_with_hash (&in
, in
.hash
);
6279 struct tm_alias_pair
6287 /* Dump the actual pairs to the .tm_clone_table section. */
6290 dump_tm_clone_pairs (vec
<tm_alias_pair
> tm_alias_pairs
)
6294 bool switched
= false;
6296 FOR_EACH_VEC_ELT (tm_alias_pairs
, i
, p
)
6300 struct cgraph_node
*src_n
= cgraph_node::get (src
);
6301 struct cgraph_node
*dst_n
= cgraph_node::get (dst
);
6303 /* The function ipa_tm_create_version() marks the clone as needed if
6304 the original function was needed. But we also mark the clone as
6305 needed if we ever called the clone indirectly through
6306 TM_GETTMCLONE. If neither of these are true, we didn't generate
6307 a clone, and we didn't call it indirectly... no sense keeping it
6308 in the clone table. */
6309 if (!dst_n
|| !dst_n
->definition
)
6312 /* This covers the case where we have optimized the original
6313 function away, and only access the transactional clone. */
6314 if (!src_n
|| !src_n
->definition
)
6319 switch_to_section (targetm
.asm_out
.tm_clone_table_section ());
6320 assemble_align (POINTER_SIZE
);
6324 assemble_integer (XEXP (DECL_RTL (src
), 0),
6325 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
6326 assemble_integer (XEXP (DECL_RTL (dst
), 0),
6327 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
6331 /* Provide a default for the tm_clone_table section. */
6334 default_clone_table_section (void)
6336 return get_named_section (NULL
, ".tm_clone_table", 3);
6339 /* Helper comparison function for qsorting by the DECL_UID stored in
6340 alias_pair->emitted_diags. */
6343 tm_alias_pair_cmp (const void *x
, const void *y
)
6345 const tm_alias_pair
*p1
= (const tm_alias_pair
*) x
;
6346 const tm_alias_pair
*p2
= (const tm_alias_pair
*) y
;
6347 if (p1
->uid
< p2
->uid
)
6349 if (p1
->uid
> p2
->uid
)
6355 finish_tm_clone_pairs (void)
6357 vec
<tm_alias_pair
> tm_alias_pairs
= vNULL
;
6359 if (tm_clone_hash
== NULL
)
6362 /* We need a determenistic order for the .tm_clone_table, otherwise
6363 we will get bootstrap comparison failures, so dump the hash table
6364 to a vector, sort it, and dump the vector. */
6366 /* Dump the hashtable to a vector. */
6368 hash_table
<tm_clone_hasher
>::iterator iter
;
6369 FOR_EACH_HASH_TABLE_ELEMENT (*tm_clone_hash
, map
, tree_map
*, iter
)
6371 tm_alias_pair p
= {DECL_UID (map
->base
.from
), map
->base
.from
, map
->to
};
6372 tm_alias_pairs
.safe_push (p
);
6375 tm_alias_pairs
.qsort (tm_alias_pair_cmp
);
6378 dump_tm_clone_pairs (tm_alias_pairs
);
6380 tm_clone_hash
->empty ();
6381 tm_clone_hash
= NULL
;
6382 tm_alias_pairs
.release ();
6386 /* Emit an assembler directive to set symbol for DECL visibility to
6387 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
6390 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
6391 int vis ATTRIBUTE_UNUSED
)
6393 #ifdef HAVE_GAS_HIDDEN
6394 static const char * const visibility_types
[] = {
6395 NULL
, "protected", "hidden", "internal"
6398 const char *name
, *type
;
6401 id
= DECL_ASSEMBLER_NAME (decl
);
6402 ultimate_transparent_alias_target (&id
);
6403 name
= IDENTIFIER_POINTER (id
);
6405 type
= visibility_types
[vis
];
6407 fprintf (asm_out_file
, "\t.%s\t", type
);
6408 assemble_name (asm_out_file
, name
);
6409 fprintf (asm_out_file
, "\n");
6411 if (!DECL_ARTIFICIAL (decl
))
6412 warning (OPT_Wattributes
, "visibility attribute not supported "
6413 "in this configuration; ignored");
6417 /* A helper function to call assemble_visibility when needed for a decl. */
6420 maybe_assemble_visibility (tree decl
)
6422 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
6423 if (vis
!= VISIBILITY_DEFAULT
)
6425 targetm
.asm_out
.assemble_visibility (decl
, vis
);
6432 /* Returns 1 if the target configuration supports defining public symbols
6433 so that one of them will be chosen at link time instead of generating a
6434 multiply-defined symbol error, whether through the use of weak symbols or
6435 a target-specific mechanism for having duplicates discarded. */
6438 supports_one_only (void)
6440 if (SUPPORTS_ONE_ONLY
)
6442 return TARGET_SUPPORTS_WEAK
;
6445 /* Set up DECL as a public symbol that can be defined in multiple
6446 translation units without generating a linker error. */
6449 make_decl_one_only (tree decl
, tree comdat_group
)
6451 struct symtab_node
*symbol
;
6452 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
6454 TREE_PUBLIC (decl
) = 1;
6457 symbol
= varpool_node::get_create (decl
);
6459 symbol
= cgraph_node::get_create (decl
);
6461 if (SUPPORTS_ONE_ONLY
)
6463 #ifdef MAKE_DECL_ONE_ONLY
6464 MAKE_DECL_ONE_ONLY (decl
);
6466 symbol
->set_comdat_group (comdat_group
);
6468 else if (VAR_P (decl
)
6469 && (DECL_INITIAL (decl
) == 0
6470 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
6471 DECL_COMMON (decl
) = 1;
6474 gcc_assert (TARGET_SUPPORTS_WEAK
);
6475 DECL_WEAK (decl
) = 1;
6480 init_varasm_once (void)
6482 section_htab
= hash_table
<section_hasher
>::create_ggc (31);
6483 object_block_htab
= hash_table
<object_block_hasher
>::create_ggc (31);
6484 const_desc_htab
= hash_table
<tree_descriptor_hasher
>::create_ggc (1009);
6486 shared_constant_pool
= create_constant_pool ();
6488 #ifdef TEXT_SECTION_ASM_OP
6489 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
6490 TEXT_SECTION_ASM_OP
);
6493 #ifdef DATA_SECTION_ASM_OP
6494 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6495 DATA_SECTION_ASM_OP
);
6498 #ifdef SDATA_SECTION_ASM_OP
6499 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6500 SDATA_SECTION_ASM_OP
);
6503 #ifdef READONLY_DATA_SECTION_ASM_OP
6504 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
6505 READONLY_DATA_SECTION_ASM_OP
);
6508 #ifdef CTORS_SECTION_ASM_OP
6509 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
6510 CTORS_SECTION_ASM_OP
);
6513 #ifdef DTORS_SECTION_ASM_OP
6514 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
6515 DTORS_SECTION_ASM_OP
);
6518 #ifdef BSS_SECTION_ASM_OP
6519 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6520 output_section_asm_op
,
6521 BSS_SECTION_ASM_OP
);
6524 #ifdef SBSS_SECTION_ASM_OP
6525 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6526 output_section_asm_op
,
6527 SBSS_SECTION_ASM_OP
);
6530 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6531 | SECTION_COMMON
, emit_tls_common
);
6532 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6533 | SECTION_COMMON
, emit_local
);
6534 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6535 | SECTION_COMMON
, emit_common
);
6537 #if defined ASM_OUTPUT_ALIGNED_BSS
6538 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
6542 targetm
.asm_out
.init_sections ();
6544 if (readonly_data_section
== NULL
)
6545 readonly_data_section
= text_section
;
6547 #ifdef ASM_OUTPUT_EXTERNAL
6548 pending_assemble_externals_set
= new hash_set
<tree
>;
6553 decl_default_tls_model (const_tree decl
)
6555 enum tls_model kind
;
6558 is_local
= targetm
.binds_local_p (decl
);
6562 kind
= TLS_MODEL_LOCAL_EXEC
;
6564 kind
= TLS_MODEL_INITIAL_EXEC
;
6567 /* Local dynamic is inefficient when we're not combining the
6568 parts of the address. */
6569 else if (optimize
&& is_local
)
6570 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6572 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6573 if (kind
< flag_tls_default
)
6574 kind
= flag_tls_default
;
6579 /* Select a set of attributes for section NAME based on the properties
6580 of DECL and whether or not RELOC indicates that DECL's initializer
6581 might contain runtime relocations.
6583 We make the section read-only and executable for a function decl,
6584 read-only for a const data decl, and writable for a non-const data decl. */
6587 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6591 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6592 flags
= SECTION_CODE
;
6595 enum section_category category
6596 = categorize_decl_for_section (decl
, reloc
);
6597 if (decl_readonly_section_1 (category
))
6599 else if (category
== SECCAT_DATA_REL_RO
6600 || category
== SECCAT_DATA_REL_RO_LOCAL
)
6601 flags
= SECTION_WRITE
| SECTION_RELRO
;
6603 flags
= SECTION_WRITE
;
6607 flags
= SECTION_WRITE
;
6608 if (strcmp (name
, ".data.rel.ro") == 0
6609 || strcmp (name
, ".data.rel.ro.local") == 0)
6610 flags
|= SECTION_RELRO
;
6613 if (decl
&& DECL_P (decl
) && DECL_COMDAT_GROUP (decl
))
6614 flags
|= SECTION_LINKONCE
;
6616 if (strcmp (name
, ".vtable_map_vars") == 0)
6617 flags
|= SECTION_LINKONCE
;
6619 if (decl
&& VAR_P (decl
) && DECL_THREAD_LOCAL_P (decl
))
6620 flags
|= SECTION_TLS
| SECTION_WRITE
;
6622 if (strcmp (name
, ".bss") == 0
6623 || strncmp (name
, ".bss.", 5) == 0
6624 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6625 || strcmp (name
, ".persistent.bss") == 0
6626 || strcmp (name
, ".sbss") == 0
6627 || strncmp (name
, ".sbss.", 6) == 0
6628 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6629 flags
|= SECTION_BSS
;
6631 if (strcmp (name
, ".tdata") == 0
6632 || strncmp (name
, ".tdata.", 7) == 0
6633 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6634 flags
|= SECTION_TLS
;
6636 if (strcmp (name
, ".tbss") == 0
6637 || strncmp (name
, ".tbss.", 6) == 0
6638 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6639 flags
|= SECTION_TLS
| SECTION_BSS
;
6641 if (strcmp (name
, ".noinit") == 0)
6642 flags
|= SECTION_WRITE
| SECTION_BSS
| SECTION_NOTYPE
;
6644 /* Various sections have special ELF types that the assembler will
6645 assign by default based on the name. They are neither SHT_PROGBITS
6646 nor SHT_NOBITS, so when changing sections we don't want to print a
6647 section type (@progbits or @nobits). Rather than duplicating the
6648 assembler's knowledge of what those special name patterns are, just
6649 let the assembler choose the type if we don't know a specific
6650 reason to set it to something other than the default. SHT_PROGBITS
6651 is the default for sections whose name is not specially known to
6652 the assembler, so it does no harm to leave the choice to the
6653 assembler when @progbits is the best thing we know to use. If
6654 someone is silly enough to emit code or TLS variables to one of
6655 these sections, then don't handle them specially.
6657 default_elf_asm_named_section (below) handles the BSS, TLS, ENTSIZE, and
6658 LINKONCE cases when NOTYPE is not set, so leave those to its logic. */
6659 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
| SECTION_ENTSIZE
))
6660 && !(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
)))
6661 flags
|= SECTION_NOTYPE
;
6666 /* Return true if the target supports some form of global BSS,
6667 either through bss_noswitch_section, or by selecting a BSS
6668 section in TARGET_ASM_SELECT_SECTION. */
6671 have_global_bss_p (void)
6673 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6676 /* Output assembly to switch to section NAME with attribute FLAGS.
6677 Four variants for common object file formats. */
6680 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6681 unsigned int flags ATTRIBUTE_UNUSED
,
6682 tree decl ATTRIBUTE_UNUSED
)
6684 /* Some object formats don't support named sections at all. The
6685 front-end should already have flagged this as an error. */
6689 #ifndef TLS_SECTION_ASM_FLAG
6690 #define TLS_SECTION_ASM_FLAG 'T'
6694 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6697 char flagchars
[11], *f
= flagchars
;
6698 unsigned int numeric_value
= 0;
6700 /* If we have already declared this section, we can use an
6701 abbreviated form to switch back to it -- unless this section is
6702 part of a COMDAT groups, in which case GAS requires the full
6703 declaration every time. */
6704 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6705 && (flags
& SECTION_DECLARED
))
6707 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6711 /* If we have a machine specific flag, then use the numeric value to pass
6713 if (targetm
.asm_out
.elf_flags_numeric (flags
, &numeric_value
))
6714 snprintf (f
, sizeof (flagchars
), "0x%08x", numeric_value
);
6717 if (!(flags
& SECTION_DEBUG
))
6719 #if HAVE_GAS_SECTION_EXCLUDE
6720 if (flags
& SECTION_EXCLUDE
)
6723 if (flags
& SECTION_WRITE
)
6725 if (flags
& SECTION_CODE
)
6727 if (flags
& SECTION_SMALL
)
6729 if (flags
& SECTION_MERGE
)
6731 if (flags
& SECTION_STRINGS
)
6733 if (flags
& SECTION_TLS
)
6734 *f
++ = TLS_SECTION_ASM_FLAG
;
6735 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6737 #ifdef MACH_DEP_SECTION_ASM_FLAG
6738 if (flags
& SECTION_MACH_DEP
)
6739 *f
++ = MACH_DEP_SECTION_ASM_FLAG
;
6744 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6746 /* default_section_type_flags (above) knows which flags need special
6747 handling here, and sets NOTYPE when none of these apply so that the
6748 assembler's logic for default types can apply to user-chosen
6750 if (!(flags
& SECTION_NOTYPE
))
6755 if (flags
& SECTION_BSS
)
6761 /* On platforms that use "@" as the assembly comment character,
6763 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6765 fprintf (asm_out_file
, format
, type
);
6767 if (flags
& SECTION_ENTSIZE
)
6768 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6769 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6771 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6772 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6774 fprintf (asm_out_file
, ",%s,comdat",
6775 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6779 putc ('\n', asm_out_file
);
6783 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6784 tree decl ATTRIBUTE_UNUSED
)
6786 char flagchars
[8], *f
= flagchars
;
6788 if (flags
& SECTION_WRITE
)
6790 if (flags
& SECTION_CODE
)
6794 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6798 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6801 default_coff_asm_named_section (name
, flags
, decl
);
6803 if (flags
& SECTION_LINKONCE
)
6805 /* Functions may have been compiled at various levels of
6806 optimization so we can't use `same_size' here.
6807 Instead, have the linker pick one. */
6808 fprintf (asm_out_file
, "\t.linkonce %s\n",
6809 (flags
& SECTION_CODE
? "discard" : "same_size"));
6813 /* The lame default section selector. */
6816 default_select_section (tree decl
, int reloc
,
6817 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6821 if (decl_readonly_section (decl
, reloc
))
6822 return readonly_data_section
;
6824 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6826 if (! ((flag_pic
&& reloc
)
6827 || !TREE_READONLY (decl
)
6828 || TREE_SIDE_EFFECTS (decl
)
6829 || !TREE_CONSTANT (decl
)))
6830 return readonly_data_section
;
6832 else if (TREE_CODE (decl
) == STRING_CST
)
6833 return readonly_data_section
;
6834 else if (! (flag_pic
&& reloc
))
6835 return readonly_data_section
;
6837 return data_section
;
6840 enum section_category
6841 categorize_decl_for_section (const_tree decl
, int reloc
)
6843 enum section_category ret
;
6845 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6847 else if (TREE_CODE (decl
) == STRING_CST
)
6849 if ((flag_sanitize
& SANITIZE_ADDRESS
)
6850 && asan_protect_global (CONST_CAST_TREE (decl
)))
6851 /* or !flag_merge_constants */
6852 return SECCAT_RODATA
;
6854 return SECCAT_RODATA_MERGE_STR
;
6856 else if (VAR_P (decl
))
6858 tree d
= CONST_CAST_TREE (decl
);
6859 if (bss_initializer_p (decl
))
6861 else if (! TREE_READONLY (decl
)
6862 || TREE_SIDE_EFFECTS (decl
)
6863 || (DECL_INITIAL (decl
)
6864 && ! TREE_CONSTANT (DECL_INITIAL (decl
))))
6866 /* Here the reloc_rw_mask is not testing whether the section should
6867 be read-only or not, but whether the dynamic link will have to
6868 do something. If so, we wish to segregate the data in order to
6869 minimize cache misses inside the dynamic linker. */
6870 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6871 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6875 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6876 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6877 else if (reloc
|| flag_merge_constants
< 2
6878 || ((flag_sanitize
& SANITIZE_ADDRESS
)
6879 /* PR 81697: for architectures that use section anchors we
6880 need to ignore DECL_RTL_SET_P (decl) for string constants
6881 inside this asan_protect_global call because otherwise
6882 we'll wrongly put them into SECCAT_RODATA_MERGE_CONST
6883 section, set DECL_RTL (decl) later on and add DECL to
6884 protected globals via successive asan_protect_global
6885 calls. In this scenario we'll end up with wrong
6886 alignment of these strings at runtime and possible ASan
6888 && asan_protect_global (d
, use_object_blocks_p ()
6889 && use_blocks_for_decl_p (d
))))
6890 /* C and C++ don't allow different variables to share the same
6891 location. -fmerge-all-constants allows even that (at the
6892 expense of not conforming). */
6893 ret
= SECCAT_RODATA
;
6894 else if (DECL_INITIAL (decl
)
6895 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6896 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6898 ret
= SECCAT_RODATA_MERGE_CONST
;
6900 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6902 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6903 || TREE_SIDE_EFFECTS (decl
)
6904 || ! TREE_CONSTANT (decl
))
6907 ret
= SECCAT_RODATA
;
6910 ret
= SECCAT_RODATA
;
6912 /* There are no read-only thread-local sections. */
6913 if (VAR_P (decl
) && DECL_THREAD_LOCAL_P (decl
))
6915 /* Note that this would be *just* SECCAT_BSS, except that there's
6916 no concept of a read-only thread-local-data section. */
6917 if (ret
== SECCAT_BSS
6918 || DECL_INITIAL (decl
) == NULL
6919 || (flag_zero_initialized_in_bss
6920 && initializer_zerop (DECL_INITIAL (decl
))))
6926 /* If the target uses small data sections, select it. */
6927 else if (targetm
.in_small_data_p (decl
))
6929 if (ret
== SECCAT_BSS
)
6931 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6932 ret
= SECCAT_SRODATA
;
6941 decl_readonly_section_1 (enum section_category category
)
6946 case SECCAT_RODATA_MERGE_STR
:
6947 case SECCAT_RODATA_MERGE_STR_INIT
:
6948 case SECCAT_RODATA_MERGE_CONST
:
6949 case SECCAT_SRODATA
:
6957 decl_readonly_section (const_tree decl
, int reloc
)
6959 return decl_readonly_section_1 (categorize_decl_for_section (decl
, reloc
));
6962 /* Select a section based on the above categorization. */
6965 default_elf_select_section (tree decl
, int reloc
,
6966 unsigned HOST_WIDE_INT align
)
6970 switch (categorize_decl_for_section (decl
, reloc
))
6973 /* We're not supposed to be called on FUNCTION_DECLs. */
6976 return readonly_data_section
;
6977 case SECCAT_RODATA_MERGE_STR
:
6978 return mergeable_string_section (decl
, align
, 0);
6979 case SECCAT_RODATA_MERGE_STR_INIT
:
6980 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6981 case SECCAT_RODATA_MERGE_CONST
:
6982 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6983 case SECCAT_SRODATA
:
6987 return data_section
;
6988 case SECCAT_DATA_REL
:
6989 sname
= ".data.rel";
6991 case SECCAT_DATA_REL_LOCAL
:
6992 sname
= ".data.rel.local";
6994 case SECCAT_DATA_REL_RO
:
6995 sname
= ".data.rel.ro";
6997 case SECCAT_DATA_REL_RO_LOCAL
:
6998 sname
= ".data.rel.ro.local";
7008 && lookup_attribute ("noinit", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
7028 return get_named_section (decl
, sname
, reloc
);
7031 /* Construct a unique section name based on the decl name and the
7032 categorization performed above. */
7035 default_unique_section (tree decl
, int reloc
)
7037 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
7038 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
7039 const char *prefix
, *name
, *linkonce
;
7043 switch (categorize_decl_for_section (decl
, reloc
))
7046 prefix
= one_only
? ".t" : ".text";
7049 case SECCAT_RODATA_MERGE_STR
:
7050 case SECCAT_RODATA_MERGE_STR_INIT
:
7051 case SECCAT_RODATA_MERGE_CONST
:
7052 prefix
= one_only
? ".r" : ".rodata";
7054 case SECCAT_SRODATA
:
7055 prefix
= one_only
? ".s2" : ".sdata2";
7058 prefix
= one_only
? ".d" : ".data";
7060 case SECCAT_DATA_REL
:
7061 prefix
= one_only
? ".d.rel" : ".data.rel";
7063 case SECCAT_DATA_REL_LOCAL
:
7064 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
7066 case SECCAT_DATA_REL_RO
:
7067 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
7069 case SECCAT_DATA_REL_RO_LOCAL
:
7070 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
7073 prefix
= one_only
? ".s" : ".sdata";
7076 prefix
= one_only
? ".b" : ".bss";
7079 prefix
= one_only
? ".sb" : ".sbss";
7082 prefix
= one_only
? ".td" : ".tdata";
7085 prefix
= one_only
? ".tb" : ".tbss";
7091 id
= DECL_ASSEMBLER_NAME (decl
);
7092 ultimate_transparent_alias_target (&id
);
7093 name
= IDENTIFIER_POINTER (id
);
7094 name
= targetm
.strip_name_encoding (name
);
7096 /* If we're using one_only, then there needs to be a .gnu.linkonce
7097 prefix to the section name. */
7098 linkonce
= one_only
? ".gnu.linkonce" : "";
7100 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
7102 set_decl_section_name (decl
, string
);
7105 /* Subroutine of compute_reloc_for_rtx for leaf rtxes. */
7108 compute_reloc_for_rtx_1 (const_rtx x
)
7110 switch (GET_CODE (x
))
7113 return SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
7121 /* Like compute_reloc_for_constant, except for an RTX. The return value
7122 is a mask for which bit 1 indicates a global relocation, and bit 0
7123 indicates a local relocation. */
7126 compute_reloc_for_rtx (const_rtx x
)
7128 switch (GET_CODE (x
))
7132 return compute_reloc_for_rtx_1 (x
);
7137 subrtx_iterator::array_type array
;
7138 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
7139 reloc
|= compute_reloc_for_rtx_1 (*iter
);
7149 default_select_rtx_section (machine_mode mode ATTRIBUTE_UNUSED
,
7151 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
7153 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
7154 return data_section
;
7156 return readonly_data_section
;
7160 default_elf_select_rtx_section (machine_mode mode
, rtx x
,
7161 unsigned HOST_WIDE_INT align
)
7163 int reloc
= compute_reloc_for_rtx (x
);
7165 /* ??? Handle small data here somehow. */
7167 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
7170 return get_named_section (NULL
, ".data.rel.ro.local", 1);
7172 return get_named_section (NULL
, ".data.rel.ro", 3);
7175 return mergeable_constant_section (mode
, align
, 0);
7178 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
7181 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
7186 /* Careful not to prod global register variables. */
7189 symbol
= XEXP (rtl
, 0);
7190 if (GET_CODE (symbol
) != SYMBOL_REF
)
7193 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
7194 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7195 flags
|= SYMBOL_FLAG_FUNCTION
;
7196 if (targetm
.binds_local_p (decl
))
7197 flags
|= SYMBOL_FLAG_LOCAL
;
7198 if (VAR_P (decl
) && DECL_THREAD_LOCAL_P (decl
))
7199 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
7200 else if (targetm
.in_small_data_p (decl
))
7201 flags
|= SYMBOL_FLAG_SMALL
;
7202 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
7203 being PUBLIC, the thing *must* be defined in this translation unit.
7204 Prevent this buglet from being propagated into rtl code as well. */
7205 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
7206 flags
|= SYMBOL_FLAG_EXTERNAL
;
7208 SYMBOL_REF_FLAGS (symbol
) = flags
;
7211 /* By default, we do nothing for encode_section_info, so we need not
7212 do anything but discard the '*' marker. */
7215 default_strip_name_encoding (const char *str
)
7217 return str
+ (*str
== '*');
7220 #ifdef ASM_OUTPUT_DEF
7221 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
7222 anchor relative to ".", the current section position. */
7225 default_asm_output_anchor (rtx symbol
)
7229 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
7230 SYMBOL_REF_BLOCK_OFFSET (symbol
));
7231 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
7235 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
7238 default_use_anchors_for_symbol_p (const_rtx symbol
)
7241 section
*sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
7243 /* This function should only be called with non-zero SYMBOL_REF_BLOCK,
7244 furthermore get_block_for_section should not create object blocks
7245 for mergeable sections. */
7246 gcc_checking_assert (sect
&& !(sect
->common
.flags
& SECTION_MERGE
));
7248 /* Don't use anchors for small data sections. The small data register
7249 acts as an anchor for such sections. */
7250 if (sect
->common
.flags
& SECTION_SMALL
)
7253 decl
= SYMBOL_REF_DECL (symbol
);
7254 if (decl
&& DECL_P (decl
))
7256 /* Don't use section anchors for decls that might be defined or
7257 usurped by other modules. */
7258 if (TREE_PUBLIC (decl
) && !decl_binds_to_current_def_p (decl
))
7261 /* Don't use section anchors for decls that will be placed in a
7262 small data section. */
7263 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
7264 one above. The problem is that we only use SECTION_SMALL for
7265 sections that should be marked as small in the section directive. */
7266 if (targetm
.in_small_data_p (decl
))
7269 /* Don't use section anchors for decls that won't fit inside a single
7270 anchor range to reduce the amount of instructions required to refer
7271 to the entire declaration. */
7272 if (DECL_SIZE_UNIT (decl
) == NULL_TREE
7273 || !tree_fits_uhwi_p (DECL_SIZE_UNIT (decl
))
7274 || (tree_to_uhwi (DECL_SIZE_UNIT (decl
))
7275 >= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
))
7282 /* Return true when RESOLUTION indicate that symbol will be bound to the
7283 definition provided by current .o file. */
7286 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
7288 return (resolution
== LDPR_PREVAILING_DEF
7289 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
7290 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
7293 /* Return true when RESOLUTION indicate that symbol will be bound locally
7294 within current executable or DSO. */
7297 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
7299 return (resolution
== LDPR_PREVAILING_DEF
7300 || resolution
== LDPR_PREVAILING_DEF_IRONLY
7301 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
7302 || resolution
== LDPR_PREEMPTED_REG
7303 || resolution
== LDPR_PREEMPTED_IR
7304 || resolution
== LDPR_RESOLVED_IR
7305 || resolution
== LDPR_RESOLVED_EXEC
);
7308 /* COMMON_LOCAL_P is true means that the linker can guarantee that an
7309 uninitialized common symbol in the executable will still be defined
7310 (through COPY relocation) in the executable. */
7313 default_binds_local_p_3 (const_tree exp
, bool shlib
, bool weak_dominate
,
7314 bool extern_protected_data
, bool common_local_p
)
7316 /* A non-decl is an entry in the constant pool. */
7320 /* Weakrefs may not bind locally, even though the weakref itself is always
7321 static and therefore local. Similarly, the resolver for ifunc functions
7322 might resolve to a non-local function.
7323 FIXME: We can resolve the weakref case more curefuly by looking at the
7325 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
))
7326 || (TREE_CODE (exp
) == FUNCTION_DECL
7327 && cgraph_node::get (exp
)
7328 && cgraph_node::get (exp
)->ifunc_resolver
))
7331 /* Static variables are always local. */
7332 if (! TREE_PUBLIC (exp
))
7335 /* With resolution file in hand, take look into resolutions.
7336 We can't just return true for resolved_locally symbols,
7337 because dynamic linking might overwrite symbols
7338 in shared libraries. */
7339 bool resolved_locally
= false;
7341 bool uninited_common
= (DECL_COMMON (exp
)
7342 && (DECL_INITIAL (exp
) == NULL
7344 && DECL_INITIAL (exp
) == error_mark_node
)));
7346 /* A non-external variable is defined locally only if it isn't
7347 uninitialized COMMON variable or common_local_p is true. */
7348 bool defined_locally
= (!DECL_EXTERNAL (exp
)
7349 && (!uninited_common
|| common_local_p
));
7350 if (symtab_node
*node
= symtab_node::get (exp
))
7352 if (node
->in_other_partition
)
7353 defined_locally
= true;
7354 if (node
->can_be_discarded_p ())
7356 else if (resolution_to_local_definition_p (node
->resolution
))
7357 defined_locally
= resolved_locally
= true;
7358 else if (resolution_local_p (node
->resolution
))
7359 resolved_locally
= true;
7361 if (defined_locally
&& weak_dominate
&& !shlib
)
7362 resolved_locally
= true;
7364 /* Undefined weak symbols are never defined locally. */
7365 if (DECL_WEAK (exp
) && !defined_locally
)
7368 /* A symbol is local if the user has said explicitly that it will be,
7369 or if we have a definition for the symbol. We cannot infer visibility
7370 for undefined symbols. */
7371 if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
7372 && (TREE_CODE (exp
) == FUNCTION_DECL
7373 || !extern_protected_data
7374 || DECL_VISIBILITY (exp
) != VISIBILITY_PROTECTED
)
7375 && (DECL_VISIBILITY_SPECIFIED (exp
) || defined_locally
))
7378 /* If PIC, then assume that any global name can be overridden by
7379 symbols resolved from other modules. */
7383 /* Variables defined outside this object might not be local. */
7384 if (DECL_EXTERNAL (exp
) && !resolved_locally
)
7387 /* Non-dominant weak symbols are not defined locally. */
7388 if (DECL_WEAK (exp
) && !resolved_locally
)
7391 /* Uninitialized COMMON variable may be unified with symbols
7392 resolved from other modules. */
7393 if (uninited_common
&& !resolved_locally
)
7396 /* Otherwise we're left with initialized (or non-common) global data
7397 which is of necessity defined locally. */
7401 /* Assume ELF-ish defaults, since that's pretty much the most liberal
7402 wrt cross-module name binding. */
7405 default_binds_local_p (const_tree exp
)
7407 return default_binds_local_p_3 (exp
, flag_shlib
!= 0, true, false, false);
7410 /* Similar to default_binds_local_p, but common symbol may be local and
7411 extern protected data is non-local. */
7414 default_binds_local_p_2 (const_tree exp
)
7416 return default_binds_local_p_3 (exp
, flag_shlib
!= 0, true, true,
7421 default_binds_local_p_1 (const_tree exp
, int shlib
)
7423 return default_binds_local_p_3 (exp
, shlib
!= 0, false, false, false);
7426 /* Return true when references to DECL must bind to current definition in
7429 The condition is usually equivalent to whether the function binds to the
7430 current module (shared library or executable), that is to binds_local_p.
7431 We use this fact to avoid need for another target hook and implement
7432 the logic using binds_local_p and just special cases where
7433 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
7434 the weak definitions (that can be overwritten at linktime by other
7435 definition from different object file) and when resolution info is available
7436 we simply use the knowledge passed to us by linker plugin. */
7438 decl_binds_to_current_def_p (const_tree decl
)
7440 gcc_assert (DECL_P (decl
));
7441 if (!targetm
.binds_local_p (decl
))
7443 if (!TREE_PUBLIC (decl
))
7446 /* When resolution is available, just use it. */
7447 if (symtab_node
*node
= symtab_node::get (decl
))
7449 if (node
->resolution
!= LDPR_UNKNOWN
7450 && !node
->can_be_discarded_p ())
7451 return resolution_to_local_definition_p (node
->resolution
);
7454 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
7455 binds locally but still can be overwritten), DECL_COMMON (can be merged
7456 with a non-common definition somewhere in the same module) or
7458 This rely on fact that binds_local_p behave as decl_replaceable_p
7459 for all other declaration types. */
7460 if (DECL_WEAK (decl
))
7462 if (DECL_COMMON (decl
)
7463 && (DECL_INITIAL (decl
) == NULL
7464 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
7466 if (DECL_EXTERNAL (decl
))
7471 /* A replaceable function or variable is one which may be replaced
7472 at link-time with an entirely different definition, provided that the
7473 replacement has the same type. For example, functions declared
7474 with __attribute__((weak)) on most systems are replaceable.
7476 COMDAT functions are not replaceable, since all definitions of the
7477 function must be equivalent. It is important that COMDAT functions
7478 not be treated as replaceable so that use of C++ template
7479 instantiations is not penalized. */
7482 decl_replaceable_p (tree decl
)
7484 gcc_assert (DECL_P (decl
));
7485 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
7487 if (!flag_semantic_interposition
7488 && !DECL_WEAK (decl
))
7490 return !decl_binds_to_current_def_p (decl
);
7493 /* Default function to output code that will globalize a label. A
7494 target must define GLOBAL_ASM_OP or provide its own function to
7495 globalize a label. */
7496 #ifdef GLOBAL_ASM_OP
7498 default_globalize_label (FILE * stream
, const char *name
)
7500 fputs (GLOBAL_ASM_OP
, stream
);
7501 assemble_name (stream
, name
);
7502 putc ('\n', stream
);
7504 #endif /* GLOBAL_ASM_OP */
7506 /* Default function to output code that will globalize a declaration. */
7508 default_globalize_decl_name (FILE * stream
, tree decl
)
7510 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
7511 targetm
.asm_out
.globalize_label (stream
, name
);
7514 /* Default function to output a label for unwind information. The
7515 default is to do nothing. A target that needs nonlocal labels for
7516 unwind information must provide its own function to do this. */
7518 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
7519 tree decl ATTRIBUTE_UNUSED
,
7520 int for_eh ATTRIBUTE_UNUSED
,
7521 int empty ATTRIBUTE_UNUSED
)
7525 /* Default function to output a label to divide up the exception table.
7526 The default is to do nothing. A target that needs/wants to divide
7527 up the table must provide it's own function to do this. */
7529 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
7533 /* This is how to output an internal numbered label where PREFIX is
7534 the class of label and LABELNO is the number within the class. */
7537 default_generate_internal_label (char *buf
, const char *prefix
,
7538 unsigned long labelno
)
7540 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
7543 /* This is how to output an internal numbered label where PREFIX is
7544 the class of label and LABELNO is the number within the class. */
7547 default_internal_label (FILE *stream
, const char *prefix
,
7548 unsigned long labelno
)
7550 char *const buf
= (char *) alloca (40 + strlen (prefix
));
7551 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
7552 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
7556 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
7559 default_asm_declare_constant_name (FILE *file
, const char *name
,
7560 const_tree exp ATTRIBUTE_UNUSED
,
7561 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
7563 assemble_label (file
, name
);
7566 /* This is the default behavior at the beginning of a file. It's
7567 controlled by two other target-hook toggles. */
7569 default_file_start (void)
7571 if (targetm
.asm_file_start_app_off
7572 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
7573 fputs (ASM_APP_OFF
, asm_out_file
);
7575 if (targetm
.asm_file_start_file_directive
)
7577 /* LTO produced units have no meaningful main_input_filename. */
7579 output_file_directive (asm_out_file
, "<artificial>");
7581 output_file_directive (asm_out_file
, main_input_filename
);
7585 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
7586 which emits a special section directive used to indicate whether or
7587 not this object file needs an executable stack. This is primarily
7588 a GNU extension to ELF but could be used on other targets. */
7590 int trampolines_created
;
7593 file_end_indicate_exec_stack (void)
7595 unsigned int flags
= SECTION_DEBUG
;
7596 if (trampolines_created
)
7597 flags
|= SECTION_CODE
;
7599 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
7602 /* Emit a special section directive to indicate that this object file
7603 was compiled with -fsplit-stack. This is used to let the linker
7604 detect calls between split-stack code and non-split-stack code, so
7605 that it can modify the split-stack code to allocate a sufficiently
7606 large stack. We emit another special section if there are any
7607 functions in this file which have the no_split_stack attribute, to
7608 prevent the linker from warning about being unable to convert the
7609 functions if they call non-split-stack code. */
7612 file_end_indicate_split_stack (void)
7614 if (flag_split_stack
)
7616 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
7618 if (saw_no_split_stack
)
7619 switch_to_section (get_section (".note.GNU-no-split-stack",
7620 SECTION_DEBUG
, NULL
));
7624 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
7625 a get_unnamed_section callback. */
7628 output_section_asm_op (const void *directive
)
7630 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
7633 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
7634 the current section is NEW_SECTION. */
7637 switch_to_section (section
*new_section
)
7639 if (in_section
== new_section
)
7642 if (new_section
->common
.flags
& SECTION_FORGET
)
7645 in_section
= new_section
;
7647 switch (SECTION_STYLE (new_section
))
7650 targetm
.asm_out
.named_section (new_section
->named
.name
,
7651 new_section
->named
.common
.flags
,
7652 new_section
->named
.decl
);
7655 case SECTION_UNNAMED
:
7656 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
7659 case SECTION_NOSWITCH
:
7664 new_section
->common
.flags
|= SECTION_DECLARED
;
7667 /* If block symbol SYMBOL has not yet been assigned an offset, place
7668 it at the end of its block. */
7671 place_block_symbol (rtx symbol
)
7673 unsigned HOST_WIDE_INT size
, mask
, offset
;
7674 class constant_descriptor_rtx
*desc
;
7675 unsigned int alignment
;
7676 struct object_block
*block
;
7679 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
7680 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
7683 /* Work out the symbol's size and alignment. */
7684 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7686 desc
= SYMBOL_REF_CONSTANT (symbol
);
7687 alignment
= desc
->align
;
7688 size
= GET_MODE_SIZE (desc
->mode
);
7690 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7692 decl
= SYMBOL_REF_DECL (symbol
);
7693 gcc_checking_assert (DECL_IN_CONSTANT_POOL (decl
));
7694 alignment
= DECL_ALIGN (decl
);
7695 size
= get_constant_size (DECL_INITIAL (decl
));
7696 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7697 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7698 && asan_protect_global (DECL_INITIAL (decl
)))
7700 size
+= asan_red_zone_size (size
);
7701 alignment
= MAX (alignment
,
7702 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
7707 struct symtab_node
*snode
;
7708 decl
= SYMBOL_REF_DECL (symbol
);
7710 snode
= symtab_node::get (decl
);
7713 rtx target
= DECL_RTL (snode
->ultimate_alias_target ()->decl
);
7715 gcc_assert (MEM_P (target
)
7716 && GET_CODE (XEXP (target
, 0)) == SYMBOL_REF
7717 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (target
, 0)));
7718 target
= XEXP (target
, 0);
7719 place_block_symbol (target
);
7720 SYMBOL_REF_BLOCK_OFFSET (symbol
) = SYMBOL_REF_BLOCK_OFFSET (target
);
7723 alignment
= get_variable_align (decl
);
7724 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7725 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7726 && asan_protect_global (decl
))
7728 size
+= asan_red_zone_size (size
);
7729 alignment
= MAX (alignment
,
7730 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
7734 /* Calculate the object's offset from the start of the block. */
7735 block
= SYMBOL_REF_BLOCK (symbol
);
7736 mask
= alignment
/ BITS_PER_UNIT
- 1;
7737 offset
= (block
->size
+ mask
) & ~mask
;
7738 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
7740 /* Record the block's new alignment and size. */
7741 block
->alignment
= MAX (block
->alignment
, alignment
);
7742 block
->size
= offset
+ size
;
7744 vec_safe_push (block
->objects
, symbol
);
7747 /* Return the anchor that should be used to address byte offset OFFSET
7748 from the first object in BLOCK. MODEL is the TLS model used
7752 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7753 enum tls_model model
)
7756 unsigned int begin
, middle
, end
;
7757 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7760 /* Work out the anchor's offset. Use an offset of 0 for the first
7761 anchor so that we don't pessimize the case where we take the address
7762 of a variable at the beginning of the block. This is particularly
7763 useful when a block has only one variable assigned to it.
7765 We try to place anchors RANGE bytes apart, so there can then be
7766 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7767 a ptr_mode offset. With some target settings, the lowest such
7768 anchor might be out of range for the lowest ptr_mode offset;
7769 likewise the highest anchor for the highest offset. Use anchors
7770 at the extreme ends of the ptr_mode range in such cases.
7772 All arithmetic uses unsigned integers in order to avoid
7774 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7775 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7776 range
= max_offset
- min_offset
+ 1;
7781 bias
= HOST_WIDE_INT_1U
<< (GET_MODE_BITSIZE (ptr_mode
) - 1);
7784 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7785 delta
-= delta
% range
;
7788 offset
= (HOST_WIDE_INT
) (-delta
);
7792 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7793 delta
-= delta
% range
;
7794 if (delta
> bias
- 1)
7796 offset
= (HOST_WIDE_INT
) delta
;
7800 /* Do a binary search to see if there's already an anchor we can use.
7801 Set BEGIN to the new anchor's index if not. */
7803 end
= vec_safe_length (block
->anchors
);
7804 while (begin
!= end
)
7806 middle
= (end
+ begin
) / 2;
7807 anchor
= (*block
->anchors
)[middle
];
7808 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7810 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7812 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7814 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7820 /* Create a new anchor with a unique label. */
7821 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7822 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7823 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7824 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7826 /* Insert it at index BEGIN. */
7827 vec_safe_insert (block
->anchors
, begin
, anchor
);
7831 /* Output the objects in BLOCK. */
7834 output_object_block (struct object_block
*block
)
7836 class constant_descriptor_rtx
*desc
;
7838 HOST_WIDE_INT offset
;
7842 if (!block
->objects
)
7845 /* Switch to the section and make sure that the first byte is
7846 suitably aligned. */
7847 /* Special case VTV comdat sections similar to assemble_variable. */
7848 if (SECTION_STYLE (block
->sect
) == SECTION_NAMED
7849 && block
->sect
->named
.name
7850 && (strcmp (block
->sect
->named
.name
, ".vtable_map_vars") == 0))
7851 handle_vtv_comdat_section (block
->sect
, block
->sect
->named
.decl
);
7853 switch_to_section (block
->sect
);
7855 gcc_checking_assert (!(block
->sect
->common
.flags
& SECTION_MERGE
));
7856 assemble_align (block
->alignment
);
7858 /* Define the values of all anchors relative to the current section
7860 FOR_EACH_VEC_SAFE_ELT (block
->anchors
, i
, symbol
)
7861 targetm
.asm_out
.output_anchor (symbol
);
7863 /* Output the objects themselves. */
7865 FOR_EACH_VEC_ELT (*block
->objects
, i
, symbol
)
7867 /* Move to the object's offset, padding with zeros if necessary. */
7868 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7869 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7870 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7872 desc
= SYMBOL_REF_CONSTANT (symbol
);
7873 /* Pass 1 for align as we have already laid out everything in the block.
7874 So aligning shouldn't be necessary. */
7875 output_constant_pool_1 (desc
, 1);
7876 offset
+= GET_MODE_SIZE (desc
->mode
);
7878 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7881 decl
= SYMBOL_REF_DECL (symbol
);
7882 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
7883 DECL_ALIGN (decl
), false);
7885 size
= get_constant_size (DECL_INITIAL (decl
));
7887 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7888 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7889 && asan_protect_global (DECL_INITIAL (decl
)))
7891 size
= asan_red_zone_size (size
);
7892 assemble_zeros (size
);
7899 decl
= SYMBOL_REF_DECL (symbol
);
7900 assemble_variable_contents (decl
, XSTR (symbol
, 0), false, false);
7901 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7903 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7904 && asan_protect_global (decl
))
7906 size
= asan_red_zone_size (size
);
7907 assemble_zeros (size
);
7914 /* A callback for qsort to compare object_blocks. */
7917 output_object_block_compare (const void *x
, const void *y
)
7919 object_block
*p1
= *(object_block
* const*)x
;
7920 object_block
*p2
= *(object_block
* const*)y
;
7922 if (p1
->sect
->common
.flags
& SECTION_NAMED
7923 && !(p2
->sect
->common
.flags
& SECTION_NAMED
))
7926 if (!(p1
->sect
->common
.flags
& SECTION_NAMED
)
7927 && p2
->sect
->common
.flags
& SECTION_NAMED
)
7930 if (p1
->sect
->common
.flags
& SECTION_NAMED
7931 && p2
->sect
->common
.flags
& SECTION_NAMED
)
7932 return strcmp (p1
->sect
->named
.name
, p2
->sect
->named
.name
);
7934 unsigned f1
= p1
->sect
->common
.flags
;
7935 unsigned f2
= p2
->sect
->common
.flags
;
7938 return f1
< f2
? -1 : 1;
7941 /* Output the definitions of all object_blocks. */
7944 output_object_blocks (void)
7946 vec
<object_block
*, va_heap
> v
;
7947 v
.create (object_block_htab
->elements ());
7949 hash_table
<object_block_hasher
>::iterator hi
;
7951 FOR_EACH_HASH_TABLE_ELEMENT (*object_block_htab
, obj
, object_block
*, hi
)
7954 /* Sort them in order to output them in a deterministic manner,
7955 otherwise we may get .rodata sections in different orders with
7957 v
.qsort (output_object_block_compare
);
7959 FOR_EACH_VEC_ELT (v
, i
, obj
)
7960 output_object_block (obj
);
7965 /* This function provides a possible implementation of the
7966 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7967 by -frecord-gcc-switches it creates a new mergeable, string section in the
7968 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7969 contains the switches in ASCII format.
7971 FIXME: This code does not correctly handle double quote characters
7972 that appear inside strings, (it strips them rather than preserving them).
7973 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7974 characters - instead it treats them as sub-string separators. Since
7975 we want to emit NUL strings terminators into the object file we have to use
7979 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7983 case SWITCH_TYPE_PASSED
:
7984 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
7985 ASM_OUTPUT_SKIP (asm_out_file
, HOST_WIDE_INT_1U
);
7988 case SWITCH_TYPE_DESCRIPTIVE
:
7991 /* Distinguish between invocations where name is NULL. */
7992 static bool started
= false;
7998 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
8002 | (SECTION_ENTSIZE
& 1),
8004 switch_to_section (sec
);
8013 /* The return value is currently ignored by the caller, but must be 0.
8014 For -fverbose-asm the return value would be the number of characters
8015 emitted into the assembler file. */
8019 /* Emit text to declare externally defined symbols. It is needed to
8020 properly support non-default visibility. */
8022 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
8024 const char *name ATTRIBUTE_UNUSED
)
8026 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
8027 set in order to avoid putting out names that are never really
8028 used. Always output visibility specified in the source. */
8029 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
8030 && (DECL_VISIBILITY_SPECIFIED (decl
)
8031 || targetm
.binds_local_p (decl
)))
8032 maybe_assemble_visibility (decl
);
8035 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
8038 default_asm_output_source_filename (FILE *file
, const char *name
)
8040 #ifdef ASM_OUTPUT_SOURCE_FILENAME
8041 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
8043 fprintf (file
, "\t.file\t");
8044 output_quoted_string (file
, name
);
8049 /* Output a file name in the form wanted by System V. */
8052 output_file_directive (FILE *asm_file
, const char *input_name
)
8057 if (input_name
== NULL
)
8058 input_name
= "<stdin>";
8060 input_name
= remap_debug_filename (input_name
);
8062 len
= strlen (input_name
);
8063 na
= input_name
+ len
;
8065 /* NA gets INPUT_NAME sans directory names. */
8066 while (na
> input_name
)
8068 if (IS_DIR_SEPARATOR (na
[-1]))
8073 targetm
.asm_out
.output_source_filename (asm_file
, na
);
8076 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
8079 make_debug_expr_from_rtl (const_rtx exp
)
8081 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
8082 machine_mode mode
= GET_MODE (exp
);
8085 DECL_ARTIFICIAL (ddecl
) = 1;
8086 if (REG_P (exp
) && REG_EXPR (exp
))
8087 type
= TREE_TYPE (REG_EXPR (exp
));
8088 else if (MEM_P (exp
) && MEM_EXPR (exp
))
8089 type
= TREE_TYPE (MEM_EXPR (exp
));
8092 if (type
&& TYPE_MODE (type
) == mode
)
8093 TREE_TYPE (ddecl
) = type
;
8095 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
8096 SET_DECL_MODE (ddecl
, mode
);
8097 dval
= gen_rtx_DEBUG_EXPR (mode
);
8098 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
8099 SET_DECL_RTL (ddecl
, dval
);
8103 #ifdef ELF_ASCII_ESCAPES
8104 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
8107 default_elf_asm_output_limited_string (FILE *f
, const char *s
)
8112 fputs (STRING_ASM_OP
, f
);
8117 escape
= ELF_ASCII_ESCAPES
[c
];
8125 putc ('0'+((c
>>6)&7), f
);
8126 putc ('0'+((c
>>3)&7), f
);
8127 putc ('0'+(c
&7), f
);
8140 /* Default ASM_OUTPUT_ASCII for ELF targets. */
8143 default_elf_asm_output_ascii (FILE *f
, const char *s
, unsigned int len
)
8145 const char *limit
= s
+ len
;
8146 const char *last_null
= NULL
;
8147 unsigned bytes_in_chunk
= 0;
8151 for (; s
< limit
; s
++)
8155 if (bytes_in_chunk
>= 60)
8164 for (p
= s
; p
< limit
&& *p
!= '\0'; p
++)
8171 if (p
< limit
&& (p
- s
) <= (long) ELF_STRING_LIMIT
)
8173 if (bytes_in_chunk
> 0)
8180 default_elf_asm_output_limited_string (f
, s
);
8185 if (bytes_in_chunk
== 0)
8186 fputs (ASCII_DATA_ASM_OP
"\"", f
);
8189 escape
= ELF_ASCII_ESCAPES
[c
];
8198 putc ('0'+((c
>>6)&7), f
);
8199 putc ('0'+((c
>>3)&7), f
);
8200 putc ('0'+(c
&7), f
);
8201 bytes_in_chunk
+= 4;
8206 bytes_in_chunk
+= 2;
8213 if (bytes_in_chunk
> 0)
8221 static GTY(()) section
*elf_init_array_section
;
8222 static GTY(()) section
*elf_fini_array_section
;
8225 get_elf_initfini_array_priority_section (int priority
,
8229 if (priority
!= DEFAULT_INIT_PRIORITY
)
8232 sprintf (buf
, "%s.%.5u",
8233 constructor_p
? ".init_array" : ".fini_array",
8235 sec
= get_section (buf
, SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
8241 if (elf_init_array_section
== NULL
)
8242 elf_init_array_section
8243 = get_section (".init_array",
8244 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
8245 sec
= elf_init_array_section
;
8249 if (elf_fini_array_section
== NULL
)
8250 elf_fini_array_section
8251 = get_section (".fini_array",
8252 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
8253 sec
= elf_fini_array_section
;
8259 /* Use .init_array section for constructors. */
8262 default_elf_init_array_asm_out_constructor (rtx symbol
, int priority
)
8264 section
*sec
= get_elf_initfini_array_priority_section (priority
,
8266 assemble_addr_to_section (symbol
, sec
);
8269 /* Use .fini_array section for destructors. */
8272 default_elf_fini_array_asm_out_destructor (rtx symbol
, int priority
)
8274 section
*sec
= get_elf_initfini_array_priority_section (priority
,
8276 assemble_addr_to_section (symbol
, sec
);
8279 /* Default TARGET_ASM_OUTPUT_IDENT hook.
8281 This is a bit of a cheat. The real default is a no-op, but this
8282 hook is the default for all targets with a .ident directive. */
8285 default_asm_output_ident_directive (const char *ident_str
)
8287 const char *ident_asm_op
= "\t.ident\t";
8289 /* If we are still in the front end, do not write out the string
8290 to asm_out_file. Instead, add a fake top-level asm statement.
8291 This allows the front ends to use this hook without actually
8292 writing to asm_out_file, to handle #ident or Pragma Ident. */
8293 if (symtab
->state
== PARSING
)
8295 char *buf
= ACONCAT ((ident_asm_op
, "\"", ident_str
, "\"\n", NULL
));
8296 symtab
->finalize_toplevel_asm (build_string (strlen (buf
), buf
));
8299 fprintf (asm_out_file
, "%s\"%s\"\n", ident_asm_op
, ident_str
);
8303 /* This function ensures that vtable_map variables are not only
8304 in the comdat section, but that each variable has its own unique
8305 comdat name. Without this the variables end up in the same section
8306 with a single comdat name.
8308 FIXME: resolve_unique_section needs to deal better with
8309 decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
8310 that is fixed, this if-else statement can be replaced with
8311 a single call to "switch_to_section (sect)". */
8314 handle_vtv_comdat_section (section
*sect
, const_tree decl ATTRIBUTE_UNUSED
)
8316 #if defined (OBJECT_FORMAT_ELF)
8317 targetm
.asm_out
.named_section (sect
->named
.name
,
8318 sect
->named
.common
.flags
8323 /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
8324 Therefore the following check is used.
8325 In case a the target is PE or COFF a comdat group section
8326 is created, e.g. .vtable_map_vars$foo. The linker places
8327 everything in .vtable_map_vars at the end.
8329 A fix could be made in
8330 gcc/config/i386/winnt.c: i386_pe_unique_section. */
8335 if (TREE_CODE (DECL_NAME (decl
)) == IDENTIFIER_NODE
)
8336 name
= ACONCAT ((sect
->named
.name
, "$",
8337 IDENTIFIER_POINTER (DECL_NAME (decl
)), NULL
));
8339 name
= ACONCAT ((sect
->named
.name
, "$",
8340 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl
))),
8343 targetm
.asm_out
.named_section (name
,
8344 sect
->named
.common
.flags
8350 switch_to_section (sect
);
8354 #include "gt-varasm.h"