1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987-2015 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"
37 #include "stringpool.h"
41 #include "diagnostic-core.h"
42 #include "fold-const.h"
43 #include "stor-layout.h"
49 #include "langhooks.h"
51 #include "common/common-target.h"
55 #ifdef XCOFF_DEBUGGING_INFO
56 #include "xcoffout.h" /* Needed for external data declarations. */
59 /* The (assembler) name of the first globally-visible object output. */
60 extern GTY(()) const char *first_global_object_name
;
61 extern GTY(()) const char *weak_global_object_name
;
63 const char *first_global_object_name
;
64 const char *weak_global_object_name
;
67 struct constant_descriptor_rtx
;
68 struct rtx_constant_pool
;
70 #define n_deferred_constants (crtl->varasm.deferred_constants)
72 /* Number for making the label on the next
73 constant that is stored in memory. */
75 static GTY(()) int const_labelno
;
77 /* Carry information from ASM_DECLARE_OBJECT_NAME
78 to ASM_FINISH_DECLARE_OBJECT. */
80 int size_directive_output
;
82 /* The last decl for which assemble_variable was called,
83 if it did ASM_DECLARE_OBJECT_NAME.
84 If the last call to assemble_variable didn't do that,
87 tree last_assemble_variable_decl
;
89 /* The following global variable indicates if the first basic block
90 in a function belongs to the cold partition or not. */
92 bool first_function_block_is_cold
;
94 /* Whether we saw any functions with no_split_stack. */
96 static bool saw_no_split_stack
;
98 static const char *strip_reg_name (const char *);
99 static int contains_pointers_p (tree
);
100 #ifdef ASM_OUTPUT_EXTERNAL
101 static bool incorporeal_function_p (tree
);
103 static void decode_addr_const (tree
, struct addr_const
*);
104 static hashval_t
const_hash_1 (const tree
);
105 static int compare_constant (const tree
, const tree
);
106 static void output_constant_def_contents (rtx
);
107 static void output_addressed_constants (tree
);
108 static unsigned HOST_WIDE_INT
output_constant (tree
, unsigned HOST_WIDE_INT
,
110 static void globalize_decl (tree
);
111 static bool decl_readonly_section_1 (enum section_category
);
112 #ifdef BSS_SECTION_ASM_OP
113 #ifdef ASM_OUTPUT_ALIGNED_BSS
114 static void asm_output_aligned_bss (FILE *, tree
, const char *,
115 unsigned HOST_WIDE_INT
, int)
118 #endif /* BSS_SECTION_ASM_OP */
119 static void mark_weak (tree
);
120 static void output_constant_pool (const char *, tree
);
121 static void handle_vtv_comdat_section (section
*, const_tree
);
123 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
124 section
*text_section
;
125 section
*data_section
;
126 section
*readonly_data_section
;
127 section
*sdata_section
;
128 section
*ctors_section
;
129 section
*dtors_section
;
130 section
*bss_section
;
131 section
*sbss_section
;
133 /* Various forms of common section. All are guaranteed to be nonnull. */
134 section
*tls_comm_section
;
135 section
*comm_section
;
136 section
*lcomm_section
;
138 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
140 section
*bss_noswitch_section
;
142 /* The section that holds the main exception table, when known. The section
143 is set either by the target's init_sections hook or by the first call to
144 switch_to_exception_section. */
145 section
*exception_section
;
147 /* The section that holds the DWARF2 frame unwind information, when known.
148 The section is set either by the target's init_sections hook or by the
149 first call to switch_to_eh_frame_section. */
150 section
*eh_frame_section
;
152 /* asm_out_file's current section. This is NULL if no section has yet
153 been selected or if we lose track of what the current section is. */
156 /* True if code for the current function is currently being directed
157 at the cold section. */
158 bool in_cold_section_p
;
160 /* The following global holds the "function name" for the code in the
161 cold section of a function, if hot/cold function splitting is enabled
162 and there was actually code that went into the cold section. A
163 pseudo function name is needed for the cold section of code for some
164 debugging tools that perform symbolization. */
165 tree cold_function_name
= NULL_TREE
;
167 /* A linked list of all the unnamed sections. */
168 static GTY(()) section
*unnamed_sections
;
170 /* Return a nonzero value if DECL has a section attribute. */
171 #define IN_NAMED_SECTION(DECL) \
172 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
173 && DECL_SECTION_NAME (DECL) != NULL)
175 struct section_hasher
: ggc_ptr_hash
<section
>
177 typedef const char *compare_type
;
179 static hashval_t
hash (section
*);
180 static bool equal (section
*, const char *);
183 /* Hash table of named sections. */
184 static GTY(()) hash_table
<section_hasher
> *section_htab
;
186 struct object_block_hasher
: ggc_ptr_hash
<object_block
>
188 typedef const section
*compare_type
;
190 static hashval_t
hash (object_block
*);
191 static bool equal (object_block
*, const section
*);
194 /* A table of object_blocks, indexed by section. */
195 static GTY(()) hash_table
<object_block_hasher
> *object_block_htab
;
197 /* The next number to use for internal anchor labels. */
198 static GTY(()) int anchor_labelno
;
200 /* A pool of constants that can be shared between functions. */
201 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
203 /* Helper routines for maintaining section_htab. */
206 section_hasher::equal (section
*old
, const char *new_name
)
208 return strcmp (old
->named
.name
, new_name
) == 0;
212 section_hasher::hash (section
*old
)
214 return htab_hash_string (old
->named
.name
);
217 /* Return a hash value for section SECT. */
220 hash_section (section
*sect
)
222 if (sect
->common
.flags
& SECTION_NAMED
)
223 return htab_hash_string (sect
->named
.name
);
224 return sect
->common
.flags
;
227 /* Helper routines for maintaining object_block_htab. */
230 object_block_hasher::equal (object_block
*old
, const section
*new_section
)
232 return old
->sect
== new_section
;
236 object_block_hasher::hash (object_block
*old
)
238 return hash_section (old
->sect
);
241 /* Return a new unnamed section with the given fields. */
244 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
249 sect
= ggc_alloc
<section
> ();
250 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
251 sect
->unnamed
.callback
= callback
;
252 sect
->unnamed
.data
= data
;
253 sect
->unnamed
.next
= unnamed_sections
;
255 unnamed_sections
= sect
;
259 /* Return a SECTION_NOSWITCH section with the given fields. */
262 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
266 sect
= ggc_alloc
<section
> ();
267 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
268 sect
->noswitch
.callback
= callback
;
273 /* Return the named section structure associated with NAME. Create
274 a new section with the given fields if no such structure exists. */
277 get_section (const char *name
, unsigned int flags
, tree decl
)
279 section
*sect
, **slot
;
281 slot
= section_htab
->find_slot_with_hash (name
, htab_hash_string (name
),
283 flags
|= SECTION_NAMED
;
286 sect
= ggc_alloc
<section
> ();
287 sect
->named
.common
.flags
= flags
;
288 sect
->named
.name
= ggc_strdup (name
);
289 sect
->named
.decl
= decl
;
295 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
296 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
298 /* It is fine if one of the section flags is
299 SECTION_WRITE | SECTION_RELRO and the other has none of these
300 flags (i.e. read-only) in named sections and either the
301 section hasn't been declared yet or has been declared as writable.
302 In that case just make sure the resulting flags are
303 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
305 if (((sect
->common
.flags
^ flags
) & (SECTION_WRITE
| SECTION_RELRO
))
306 == (SECTION_WRITE
| SECTION_RELRO
)
307 && (sect
->common
.flags
308 & ~(SECTION_DECLARED
| SECTION_WRITE
| SECTION_RELRO
))
309 == (flags
& ~(SECTION_WRITE
| SECTION_RELRO
))
310 && ((sect
->common
.flags
& SECTION_DECLARED
) == 0
311 || (sect
->common
.flags
& SECTION_WRITE
)))
313 sect
->common
.flags
|= (SECTION_WRITE
| SECTION_RELRO
);
316 /* Sanity check user variables for flag changes. */
317 if (sect
->named
.decl
!= NULL
318 && DECL_P (sect
->named
.decl
)
319 && decl
!= sect
->named
.decl
)
321 if (decl
!= NULL
&& DECL_P (decl
))
322 error ("%+D causes a section type conflict with %D",
323 decl
, sect
->named
.decl
);
325 error ("section type conflict with %D", sect
->named
.decl
);
326 inform (DECL_SOURCE_LOCATION (sect
->named
.decl
),
327 "%qD was declared here", sect
->named
.decl
);
329 else if (decl
!= NULL
&& DECL_P (decl
))
330 error ("%+D causes a section type conflict", decl
);
332 error ("section type conflict");
333 /* Make sure we don't error about one section multiple times. */
334 sect
->common
.flags
|= SECTION_OVERRIDE
;
340 /* Return true if the current compilation mode benefits from having
341 objects grouped into blocks. */
344 use_object_blocks_p (void)
346 return flag_section_anchors
;
349 /* Return the object_block structure for section SECT. Create a new
350 structure if we haven't created one already. Return null if SECT
353 static struct object_block
*
354 get_block_for_section (section
*sect
)
356 struct object_block
*block
;
362 = object_block_htab
->find_slot_with_hash (sect
, hash_section (sect
),
367 block
= ggc_cleared_alloc
<object_block
> ();
374 /* Create a symbol with label LABEL and place it at byte offset
375 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
376 is not yet known. LABEL must be a garbage-collected string. */
379 create_block_symbol (const char *label
, struct object_block
*block
,
380 HOST_WIDE_INT offset
)
385 /* Create the extended SYMBOL_REF. */
386 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
387 symbol
= (rtx
) ggc_internal_alloc (size
);
389 /* Initialize the normal SYMBOL_REF fields. */
390 memset (symbol
, 0, size
);
391 PUT_CODE (symbol
, SYMBOL_REF
);
392 PUT_MODE (symbol
, Pmode
);
393 XSTR (symbol
, 0) = label
;
394 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
396 /* Initialize the block_symbol stuff. */
397 SYMBOL_REF_BLOCK (symbol
) = block
;
398 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
403 /* Return a section with a particular name and with whatever SECTION_*
404 flags section_type_flags deems appropriate. The name of the section
405 is taken from NAME if nonnull, otherwise it is taken from DECL's
406 DECL_SECTION_NAME. DECL is the decl associated with the section
407 (see the section comment for details) and RELOC is as for
408 section_type_flags. */
411 get_named_section (tree decl
, const char *name
, int reloc
)
417 gcc_assert (decl
&& DECL_P (decl
) && DECL_SECTION_NAME (decl
));
418 name
= DECL_SECTION_NAME (decl
);
421 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
422 return get_section (name
, flags
, decl
);
425 /* Worker for resolve_unique_section. */
428 set_implicit_section (struct symtab_node
*n
, void *data ATTRIBUTE_UNUSED
)
430 n
->implicit_section
= true;
434 /* If required, set DECL_SECTION_NAME to a unique name. */
437 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
438 int flag_function_or_data_sections
)
440 if (DECL_SECTION_NAME (decl
) == NULL
441 && targetm_common
.have_named_sections
442 && (flag_function_or_data_sections
443 || DECL_COMDAT_GROUP (decl
)))
445 targetm
.asm_out
.unique_section (decl
, reloc
);
446 if (DECL_SECTION_NAME (decl
))
447 symtab_node::get (decl
)->call_for_symbol_and_aliases
448 (set_implicit_section
, NULL
, true);
452 #ifdef BSS_SECTION_ASM_OP
454 #ifdef ASM_OUTPUT_ALIGNED_BSS
456 /* Utility function for targets to use in implementing
457 ASM_OUTPUT_ALIGNED_BSS.
458 ??? It is believed that this function will work in most cases so such
459 support is localized here. */
462 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
463 const char *name
, unsigned HOST_WIDE_INT size
,
466 switch_to_section (bss_section
);
467 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
468 #ifdef ASM_DECLARE_OBJECT_NAME
469 last_assemble_variable_decl
= decl
;
470 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
472 /* Standard thing is just output label for the object. */
473 ASM_OUTPUT_LABEL (file
, name
);
474 #endif /* ASM_DECLARE_OBJECT_NAME */
475 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
480 #endif /* BSS_SECTION_ASM_OP */
482 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
483 /* Return the hot section for function DECL. Return text_section for
487 hot_function_section (tree decl
)
489 if (decl
!= NULL_TREE
490 && DECL_SECTION_NAME (decl
) != NULL
491 && targetm_common
.have_named_sections
)
492 return get_named_section (decl
, NULL
, 0);
498 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
501 When DECL_SECTION_NAME is non-NULL and it is implicit section and
502 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
503 concatenate the name with NAMED_SECTION_SUFFIX.
504 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
507 get_named_text_section (tree decl
,
508 const char *text_section_name
,
509 const char *named_section_suffix
)
511 if (decl
&& DECL_SECTION_NAME (decl
))
513 if (named_section_suffix
)
515 const char *dsn
= DECL_SECTION_NAME (decl
);
516 const char *stripped_name
;
519 name
= (char *) alloca (strlen (dsn
) + 1);
523 stripped_name
= targetm
.strip_name_encoding (name
);
525 buffer
= ACONCAT ((stripped_name
, named_section_suffix
, NULL
));
526 return get_named_section (decl
, buffer
, 0);
528 else if (symtab_node::get (decl
)->implicit_section
)
532 /* Do not try to split gnu_linkonce functions. This gets somewhat
534 if (DECL_COMDAT_GROUP (decl
) && !HAVE_COMDAT_GROUP
)
536 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
537 name
= targetm
.strip_name_encoding (name
);
538 return get_named_section (decl
, ACONCAT ((text_section_name
, ".",
544 return get_named_section (decl
, text_section_name
, 0);
547 /* Choose named function section based on its frequency. */
550 default_function_section (tree decl
, enum node_frequency freq
,
551 bool startup
, bool exit
)
553 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
554 /* Old GNU linkers have buggy --gc-section support, which sometimes
555 results in .gcc_except_table* sections being garbage collected. */
557 && symtab_node::get (decl
)->implicit_section
)
561 if (!flag_reorder_functions
562 || !targetm_common
.have_named_sections
)
564 /* Startup code should go to startup subsection unless it is
565 unlikely executed (this happens especially with function splitting
566 where we can split away unnecessary parts of static constructors. */
567 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
569 /* If we do have a profile or(and) LTO phase is executed, we do not need
570 these ELF section. */
571 if (!in_lto_p
|| !flag_profile_values
)
572 return get_named_text_section (decl
, ".text.startup", NULL
);
577 /* Similarly for exit. */
578 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
579 return get_named_text_section (decl
, ".text.exit", NULL
);
581 /* Group cold functions together, similarly for hot code. */
584 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
585 return get_named_text_section (decl
, ".text.unlikely", NULL
);
586 case NODE_FREQUENCY_HOT
:
587 /* If we do have a profile or(and) LTO phase is executed, we do not need
588 these ELF section. */
589 if (!in_lto_p
|| !flag_profile_values
)
590 return get_named_text_section (decl
, ".text.hot", NULL
);
596 /* Return the section for function DECL.
598 If DECL is NULL_TREE, return the text section. We can be passed
599 NULL_TREE under some circumstances by dbxout.c at least.
601 If FORCE_COLD is true, return cold function section ignoring
602 the frequency info of cgraph_node. */
605 function_section_1 (tree decl
, bool force_cold
)
607 section
*section
= NULL
;
608 enum node_frequency freq
= NODE_FREQUENCY_NORMAL
;
609 bool startup
= false, exit
= false;
613 struct cgraph_node
*node
= cgraph_node::get (decl
);
617 freq
= node
->frequency
;
618 startup
= node
->only_called_at_startup
;
619 exit
= node
->only_called_at_exit
;
623 freq
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
625 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
626 if (decl
!= NULL_TREE
627 && DECL_SECTION_NAME (decl
) != NULL
)
629 if (targetm
.asm_out
.function_section
)
630 section
= targetm
.asm_out
.function_section (decl
, freq
,
634 return get_named_section (decl
, NULL
, 0);
637 return targetm
.asm_out
.select_section
638 (decl
, freq
== NODE_FREQUENCY_UNLIKELY_EXECUTED
,
639 symtab_node::get (decl
)->definition_alignment ());
641 if (targetm
.asm_out
.function_section
)
642 section
= targetm
.asm_out
.function_section (decl
, freq
, startup
, exit
);
645 return hot_function_section (decl
);
649 /* Return the section for function DECL.
651 If DECL is NULL_TREE, return the text section. We can be passed
652 NULL_TREE under some circumstances by dbxout.c at least. */
655 function_section (tree decl
)
657 /* Handle cases where function splitting code decides
658 to put function entry point into unlikely executed section
659 despite the fact that the function itself is not cold
660 (i.e. it is called rarely but contains a hot loop that is
661 better to live in hot subsection for the code locality). */
662 return function_section_1 (decl
,
663 first_function_block_is_cold
);
666 /* Return the section for the current function, take IN_COLD_SECTION_P
670 current_function_section (void)
672 return function_section_1 (current_function_decl
, in_cold_section_p
);
675 /* Tell assembler to switch to unlikely-to-be-executed text section. */
678 unlikely_text_section (void)
680 return function_section_1 (current_function_decl
, true);
683 /* When called within a function context, return true if the function
684 has been assigned a cold text section and if SECT is that section.
685 When called outside a function context, return true if SECT is the
686 default cold section. */
689 unlikely_text_section_p (section
*sect
)
691 return sect
== function_section_1 (current_function_decl
, true);
694 /* Return the read-only data section associated with function DECL. */
697 default_function_rodata_section (tree decl
)
699 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
701 const char *name
= DECL_SECTION_NAME (decl
);
703 if (DECL_COMDAT_GROUP (decl
) && HAVE_COMDAT_GROUP
)
709 dot
= strchr (name
+ 1, '.');
712 len
= strlen (dot
) + 8;
713 rname
= (char *) alloca (len
);
715 strcpy (rname
, ".rodata");
717 return get_section (rname
, SECTION_LINKONCE
, decl
);
719 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
720 else if (DECL_COMDAT_GROUP (decl
)
721 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
723 size_t len
= strlen (name
) + 1;
724 char *rname
= (char *) alloca (len
);
726 memcpy (rname
, name
, len
);
728 return get_section (rname
, SECTION_LINKONCE
, decl
);
730 /* For .text.foo we want to use .rodata.foo. */
731 else if (flag_function_sections
&& flag_data_sections
732 && strncmp (name
, ".text.", 6) == 0)
734 size_t len
= strlen (name
) + 1;
735 char *rname
= (char *) alloca (len
+ 2);
737 memcpy (rname
, ".rodata", 7);
738 memcpy (rname
+ 7, name
+ 5, len
- 5);
739 return get_section (rname
, 0, decl
);
743 return readonly_data_section
;
746 /* Return the read-only data section associated with function DECL
747 for targets where that section should be always the single
748 readonly data section. */
751 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
753 return readonly_data_section
;
756 /* A subroutine of mergeable_string_section and mergeable_constant_section. */
759 function_mergeable_rodata_prefix (void)
761 section
*s
= targetm
.asm_out
.function_rodata_section (current_function_decl
);
762 if (SECTION_STYLE (s
) == SECTION_NAMED
)
763 return s
->named
.name
;
765 return targetm
.asm_out
.mergeable_rodata_prefix
;
768 /* Return the section to use for string merging. */
771 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
772 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
773 unsigned int flags ATTRIBUTE_UNUSED
)
777 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
778 && TREE_CODE (decl
) == STRING_CST
779 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
781 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
782 && TREE_STRING_LENGTH (decl
) >= len
)
785 unsigned int modesize
;
789 const char *prefix
= function_mergeable_rodata_prefix ();
790 char *name
= (char *) alloca (strlen (prefix
) + 30);
792 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
793 modesize
= GET_MODE_BITSIZE (mode
);
794 if (modesize
>= 8 && modesize
<= 256
795 && (modesize
& (modesize
- 1)) == 0)
797 if (align
< modesize
)
800 str
= TREE_STRING_POINTER (decl
);
801 unit
= GET_MODE_SIZE (mode
);
803 /* Check for embedded NUL characters. */
804 for (i
= 0; i
< len
; i
+= unit
)
806 for (j
= 0; j
< unit
; j
++)
807 if (str
[i
+ j
] != '\0')
814 sprintf (name
, "%s.str%d.%d", prefix
,
815 modesize
/ 8, (int) (align
/ 8));
816 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
817 return get_section (name
, flags
, NULL
);
822 return readonly_data_section
;
825 /* Return the section to use for constant merging. */
828 mergeable_constant_section (machine_mode mode ATTRIBUTE_UNUSED
,
829 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
830 unsigned int flags ATTRIBUTE_UNUSED
)
832 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
834 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
840 && (align
& (align
- 1)) == 0)
842 const char *prefix
= function_mergeable_rodata_prefix ();
843 char *name
= (char *) alloca (strlen (prefix
) + 30);
845 sprintf (name
, "%s.cst%d", prefix
, (int) (align
/ 8));
846 flags
|= (align
/ 8) | SECTION_MERGE
;
847 return get_section (name
, flags
, NULL
);
849 return readonly_data_section
;
852 /* Given NAME, a putative register name, discard any customary prefixes. */
855 strip_reg_name (const char *name
)
857 #ifdef REGISTER_PREFIX
858 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
859 name
+= strlen (REGISTER_PREFIX
);
861 if (name
[0] == '%' || name
[0] == '#')
866 /* The user has asked for a DECL to have a particular name. Set (or
867 change) it in such a way that we don't prefix an underscore to
870 set_user_assembler_name (tree decl
, const char *name
)
872 char *starred
= (char *) alloca (strlen (name
) + 2);
874 strcpy (starred
+ 1, name
);
875 symtab
->change_decl_assembler_name (decl
, get_identifier (starred
));
876 SET_DECL_RTL (decl
, NULL_RTX
);
879 /* Decode an `asm' spec for a declaration as a register name.
880 Return the register number, or -1 if nothing specified,
881 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
882 or -3 if ASMSPEC is `cc' and is not recognized,
883 or -4 if ASMSPEC is `memory' and is not recognized.
884 Accept an exact spelling or a decimal number.
885 Prefixes such as % are optional. */
888 decode_reg_name_and_count (const char *asmspec
, int *pnregs
)
890 /* Presume just one register is clobbered. */
897 /* Get rid of confusing prefixes. */
898 asmspec
= strip_reg_name (asmspec
);
900 /* Allow a decimal number as a "register name". */
901 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
902 if (! ISDIGIT (asmspec
[i
]))
904 if (asmspec
[0] != 0 && i
< 0)
907 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0 && reg_names
[i
][0])
913 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
915 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
918 #ifdef OVERLAPPING_REGISTER_NAMES
922 const char *const name
;
925 } table
[] = OVERLAPPING_REGISTER_NAMES
;
927 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
929 && ! strcmp (asmspec
, table
[i
].name
))
931 *pnregs
= table
[i
].nregs
;
932 return table
[i
].number
;
935 #endif /* OVERLAPPING_REGISTER_NAMES */
937 #ifdef ADDITIONAL_REGISTER_NAMES
939 static const struct { const char *const name
; const int number
; } table
[]
940 = ADDITIONAL_REGISTER_NAMES
;
942 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
944 && ! strcmp (asmspec
, table
[i
].name
)
945 && reg_names
[table
[i
].number
][0])
946 return table
[i
].number
;
948 #endif /* ADDITIONAL_REGISTER_NAMES */
950 if (!strcmp (asmspec
, "memory"))
953 if (!strcmp (asmspec
, "cc"))
963 decode_reg_name (const char *name
)
966 return decode_reg_name_and_count (name
, &count
);
970 /* Return true if DECL's initializer is suitable for a BSS section. */
973 bss_initializer_p (const_tree decl
)
975 return (DECL_INITIAL (decl
) == NULL
976 /* In LTO we have no errors in program; error_mark_node is used
977 to mark offlined constructors. */
978 || (DECL_INITIAL (decl
) == error_mark_node
980 || (flag_zero_initialized_in_bss
981 /* Leave constant zeroes in .rodata so they
983 && !TREE_READONLY (decl
)
984 && initializer_zerop (DECL_INITIAL (decl
))));
987 /* Compute the alignment of variable specified by DECL.
988 DONT_OUTPUT_DATA is from assemble_variable. */
991 align_variable (tree decl
, bool dont_output_data
)
993 unsigned int align
= DECL_ALIGN (decl
);
995 /* In the case for initialing an array whose length isn't specified,
996 where we have not yet been able to do the layout,
997 figure out the proper alignment now. */
998 if (dont_output_data
&& DECL_SIZE (decl
) == 0
999 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1000 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1002 /* Some object file formats have a maximum alignment which they support.
1003 In particular, a.out format supports a maximum alignment of 4. */
1004 if (align
> MAX_OFILE_ALIGNMENT
)
1006 error ("alignment of %q+D is greater than maximum object "
1007 "file alignment %d", decl
,
1008 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1009 align
= MAX_OFILE_ALIGNMENT
;
1012 if (! DECL_USER_ALIGN (decl
))
1014 #ifdef DATA_ABI_ALIGNMENT
1015 unsigned int data_abi_align
1016 = DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1017 /* For backwards compatibility, don't assume the ABI alignment for
1019 if (! DECL_THREAD_LOCAL_P (decl
) || data_abi_align
<= BITS_PER_WORD
)
1020 align
= data_abi_align
;
1023 /* On some machines, it is good to increase alignment sometimes.
1024 But as DECL_ALIGN is used both for actually emitting the variable
1025 and for code accessing the variable as guaranteed alignment, we
1026 can only increase the alignment if it is a performance optimization
1027 if the references to it must bind to the current definition. */
1028 if (decl_binds_to_current_def_p (decl
)
1029 && !DECL_VIRTUAL_P (decl
))
1031 #ifdef DATA_ALIGNMENT
1032 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1033 /* Don't increase alignment too much for TLS variables - TLS space
1035 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1038 if (DECL_INITIAL (decl
) != 0
1039 /* In LTO we have no errors in program; error_mark_node is used
1040 to mark offlined constructors. */
1041 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1043 unsigned int const_align
1044 = CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1045 /* Don't increase alignment too much for TLS variables - TLS
1046 space is too precious. */
1047 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1048 align
= const_align
;
1053 /* Reset the alignment in case we have made it tighter, so we can benefit
1054 from it in get_pointer_alignment. */
1055 DECL_ALIGN (decl
) = align
;
1058 /* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1059 beyond what align_variable returned. */
1062 get_variable_align (tree decl
)
1064 unsigned int align
= DECL_ALIGN (decl
);
1066 /* For user aligned vars or static vars align_variable already did
1068 if (DECL_USER_ALIGN (decl
) || !TREE_PUBLIC (decl
))
1071 #ifdef DATA_ABI_ALIGNMENT
1072 if (DECL_THREAD_LOCAL_P (decl
))
1073 align
= DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1076 /* For decls that bind to the current definition, align_variable
1077 did also everything, except for not assuming ABI required alignment
1078 of TLS variables. For other vars, increase the alignment here
1079 as an optimization. */
1080 if (!decl_binds_to_current_def_p (decl
))
1082 /* On some machines, it is good to increase alignment sometimes. */
1083 #ifdef DATA_ALIGNMENT
1084 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1085 /* Don't increase alignment too much for TLS variables - TLS space
1087 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1090 if (DECL_INITIAL (decl
) != 0
1091 /* In LTO we have no errors in program; error_mark_node is used
1092 to mark offlined constructors. */
1093 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1095 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
1097 /* Don't increase alignment too much for TLS variables - TLS space
1099 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1100 align
= const_align
;
1107 /* Return the section into which the given VAR_DECL or CONST_DECL
1108 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1109 section should be used wherever possible. */
1112 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1114 addr_space_t as
= ADDR_SPACE_GENERIC
;
1116 varpool_node
*vnode
= varpool_node::get (decl
);
1119 vnode
= vnode
->ultimate_alias_target ();
1123 if (TREE_TYPE (decl
) != error_mark_node
)
1124 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1126 /* We need the constructor to figure out reloc flag. */
1128 vnode
->get_constructor ();
1130 if (DECL_COMMON (decl
))
1132 /* If the decl has been given an explicit section name, or it resides
1133 in a non-generic address space, then it isn't common, and shouldn't
1134 be handled as such. */
1135 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1136 && ADDR_SPACE_GENERIC_P (as
));
1137 if (DECL_THREAD_LOCAL_P (decl
))
1138 return tls_comm_section
;
1139 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1140 return comm_section
;
1143 if (DECL_INITIAL (decl
) == error_mark_node
)
1144 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1145 else if (DECL_INITIAL (decl
))
1146 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1150 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1151 if (IN_NAMED_SECTION (decl
))
1152 return get_named_section (decl
, NULL
, reloc
);
1154 if (ADDR_SPACE_GENERIC_P (as
)
1155 && !DECL_THREAD_LOCAL_P (decl
)
1156 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1157 && bss_initializer_p (decl
))
1159 if (!TREE_PUBLIC (decl
)
1160 && !((flag_sanitize
& SANITIZE_ADDRESS
)
1161 && asan_protect_global (decl
)))
1162 return lcomm_section
;
1163 if (bss_noswitch_section
)
1164 return bss_noswitch_section
;
1167 return targetm
.asm_out
.select_section (decl
, reloc
,
1168 get_variable_align (decl
));
1171 /* Return the block into which object_block DECL should be placed. */
1173 static struct object_block
*
1174 get_block_for_decl (tree decl
)
1178 if (TREE_CODE (decl
) == VAR_DECL
)
1180 /* The object must be defined in this translation unit. */
1181 if (DECL_EXTERNAL (decl
))
1184 /* There's no point using object blocks for something that is
1185 isolated by definition. */
1186 if (DECL_COMDAT_GROUP (decl
))
1190 /* We can only calculate block offsets if the decl has a known
1192 if (DECL_SIZE_UNIT (decl
) == NULL
)
1194 if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl
)))
1197 /* Find out which section should contain DECL. We cannot put it into
1198 an object block if it requires a standalone definition. */
1199 if (TREE_CODE (decl
) == VAR_DECL
)
1200 align_variable (decl
, 0);
1201 sect
= get_variable_section (decl
, true);
1202 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1205 return get_block_for_section (sect
);
1208 /* Make sure block symbol SYMBOL is in block BLOCK. */
1211 change_symbol_block (rtx symbol
, struct object_block
*block
)
1213 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1215 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1216 SYMBOL_REF_BLOCK (symbol
) = block
;
1220 /* Return true if it is possible to put DECL in an object_block. */
1223 use_blocks_for_decl_p (tree decl
)
1225 struct symtab_node
*snode
;
1227 /* Only data DECLs can be placed into object blocks. */
1228 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
1231 /* Detect decls created by dw2_force_const_mem. Such decls are
1232 special because DECL_INITIAL doesn't specify the decl's true value.
1233 dw2_output_indirect_constants will instead call assemble_variable
1234 with dont_output_data set to 1 and then print the contents itself. */
1235 if (DECL_INITIAL (decl
) == decl
)
1238 /* If this decl is an alias, then we don't want to emit a
1240 if (TREE_CODE (decl
) == VAR_DECL
1241 && (snode
= symtab_node::get (decl
)) != NULL
1245 return targetm
.use_blocks_for_decl_p (decl
);
1248 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1249 until we find an identifier that is not itself a transparent alias.
1250 Modify the alias passed to it by reference (and all aliases on the
1251 way to the ultimate target), such that they do not have to be
1252 followed again, and return the ultimate target of the alias
1256 ultimate_transparent_alias_target (tree
*alias
)
1258 tree target
= *alias
;
1260 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
1262 gcc_assert (TREE_CHAIN (target
));
1263 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
1264 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
1265 && ! TREE_CHAIN (target
));
1272 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1273 have static storage duration. In other words, it should not be an
1274 automatic variable, including PARM_DECLs.
1276 There is, however, one exception: this function handles variables
1277 explicitly placed in a particular register by the user.
1279 This is never called for PARM_DECL nodes. */
1282 make_decl_rtl (tree decl
)
1284 const char *name
= 0;
1289 /* Check that we are not being given an automatic variable. */
1290 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1291 && TREE_CODE (decl
) != RESULT_DECL
);
1293 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1294 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1295 || TREE_STATIC (decl
)
1296 || TREE_PUBLIC (decl
)
1297 || DECL_EXTERNAL (decl
)
1298 || DECL_REGISTER (decl
));
1300 /* And that we were not given a type or a label. */
1301 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1302 && TREE_CODE (decl
) != LABEL_DECL
);
1304 /* For a duplicate declaration, we can be called twice on the
1305 same DECL node. Don't discard the RTL already made. */
1306 if (DECL_RTL_SET_P (decl
))
1308 /* If the old RTL had the wrong mode, fix the mode. */
1309 x
= DECL_RTL (decl
);
1310 if (GET_MODE (x
) != DECL_MODE (decl
))
1311 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1313 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1316 /* ??? Another way to do this would be to maintain a hashed
1317 table of such critters. Instead of adding stuff to a DECL
1318 to give certain attributes to it, we could use an external
1319 hash map from DECL to set of attributes. */
1321 /* Let the target reassign the RTL if it wants.
1322 This is necessary, for example, when one machine specific
1323 decl attribute overrides another. */
1324 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1326 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1327 on the new decl information. */
1329 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1330 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1331 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1336 /* If this variable belongs to the global constant pool, retrieve the
1337 pre-computed RTL or recompute it in LTO mode. */
1338 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1340 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1344 id
= DECL_ASSEMBLER_NAME (decl
);
1345 if (TREE_CODE (decl
) == FUNCTION_DECL
1346 && cgraph_node::get (decl
)
1347 && cgraph_node::get (decl
)->instrumentation_clone
)
1348 ultimate_transparent_alias_target (&id
);
1349 name
= IDENTIFIER_POINTER (id
);
1351 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1352 && DECL_REGISTER (decl
))
1354 error ("register name not specified for %q+D", decl
);
1356 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1358 const char *asmspec
= name
+1;
1359 machine_mode mode
= DECL_MODE (decl
);
1360 reg_number
= decode_reg_name (asmspec
);
1361 /* First detect errors in declaring global registers. */
1362 if (reg_number
== -1)
1363 error ("register name not specified for %q+D", decl
);
1364 else if (reg_number
< 0)
1365 error ("invalid register name for %q+D", decl
);
1366 else if (mode
== BLKmode
)
1367 error ("data type of %q+D isn%'t suitable for a register",
1369 else if (!in_hard_reg_set_p (accessible_reg_set
, mode
, reg_number
))
1370 error ("the register specified for %q+D cannot be accessed"
1371 " by the current target", decl
);
1372 else if (!in_hard_reg_set_p (operand_reg_set
, mode
, reg_number
))
1373 error ("the register specified for %q+D is not general enough"
1374 " to be used as a register variable", decl
);
1375 else if (!HARD_REGNO_MODE_OK (reg_number
, mode
))
1376 error ("register specified for %q+D isn%'t suitable for data type",
1378 /* Now handle properly declared static register variables. */
1383 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1385 DECL_INITIAL (decl
) = 0;
1386 error ("global register variable has initial value");
1388 if (TREE_THIS_VOLATILE (decl
))
1389 warning (OPT_Wvolatile_register_var
,
1390 "optimization may eliminate reads and/or "
1391 "writes to register variables");
1393 /* If the user specified one of the eliminables registers here,
1394 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1395 confused with that register and be eliminated. This usage is
1396 somewhat suspect... */
1398 SET_DECL_RTL (decl
, gen_raw_REG (mode
, reg_number
));
1399 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1400 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1402 if (TREE_STATIC (decl
))
1404 /* Make this register global, so not usable for anything
1406 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1407 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1408 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1410 nregs
= hard_regno_nregs
[reg_number
][mode
];
1412 globalize_reg (decl
, reg_number
+ --nregs
);
1415 /* As a register variable, it has no section. */
1418 /* Avoid internal errors from invalid register
1420 SET_DECL_ASSEMBLER_NAME (decl
, NULL_TREE
);
1421 DECL_HARD_REGISTER (decl
) = 0;
1424 /* Now handle ordinary static variables and functions (in memory).
1425 Also handle vars declared register invalidly. */
1426 else if (name
[0] == '*')
1428 #ifdef REGISTER_PREFIX
1429 if (strlen (REGISTER_PREFIX
) != 0)
1431 reg_number
= decode_reg_name (name
);
1432 if (reg_number
>= 0 || reg_number
== -3)
1433 error ("register name given for non-register variable %q+D", decl
);
1438 /* Specifying a section attribute on a variable forces it into a
1439 non-.bss section, and thus it cannot be common. */
1440 /* FIXME: In general this code should not be necessary because
1441 visibility pass is doing the same work. But notice_global_symbol
1442 is called early and it needs to make DECL_RTL to get the name.
1443 we take care of recomputing the DECL_RTL after visibility is changed. */
1444 if (TREE_CODE (decl
) == VAR_DECL
1445 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
1446 && DECL_SECTION_NAME (decl
) != NULL
1447 && DECL_INITIAL (decl
) == NULL_TREE
1448 && DECL_COMMON (decl
))
1449 DECL_COMMON (decl
) = 0;
1451 /* Variables can't be both common and weak. */
1452 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1453 DECL_COMMON (decl
) = 0;
1455 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1456 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1459 machine_mode address_mode
= Pmode
;
1460 if (TREE_TYPE (decl
) != error_mark_node
)
1462 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1463 address_mode
= targetm
.addr_space
.address_mode (as
);
1465 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1467 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1468 SET_SYMBOL_REF_DECL (x
, decl
);
1470 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1471 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1472 set_mem_attributes (x
, decl
, 1);
1473 SET_DECL_RTL (decl
, x
);
1475 /* Optionally set flags or add text to the name to record information
1476 such as that it is a function name.
1477 If the name is changed, the macro ASM_OUTPUT_LABELREF
1478 will have to know how to strip this information. */
1479 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1482 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1483 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1487 make_decl_rtl_for_debug (tree decl
)
1489 unsigned int save_aliasing_flag
;
1492 if (DECL_RTL_SET_P (decl
))
1493 return DECL_RTL (decl
);
1495 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1496 call new_alias_set. If running with -fcompare-debug, sometimes
1497 we do not want to create alias sets that will throw the alias
1498 numbers off in the comparison dumps. So... clearing
1499 flag_strict_aliasing will keep new_alias_set() from creating a
1501 save_aliasing_flag
= flag_strict_aliasing
;
1502 flag_strict_aliasing
= 0;
1504 rtl
= DECL_RTL (decl
);
1505 /* Reset DECL_RTL back, as various parts of the compiler expects
1506 DECL_RTL set meaning it is actually going to be output. */
1507 SET_DECL_RTL (decl
, NULL
);
1509 flag_strict_aliasing
= save_aliasing_flag
;
1513 /* Output a string of literal assembler code
1514 for an `asm' keyword used between functions. */
1517 assemble_asm (tree string
)
1522 if (TREE_CODE (string
) == ADDR_EXPR
)
1523 string
= TREE_OPERAND (string
, 0);
1525 p
= TREE_STRING_POINTER (string
);
1526 fprintf (asm_out_file
, "%s%s\n", p
[0] == '\t' ? "" : "\t", p
);
1529 /* Write the address of the entity given by SYMBOL to SEC. */
1531 assemble_addr_to_section (rtx symbol
, section
*sec
)
1533 switch_to_section (sec
);
1534 assemble_align (POINTER_SIZE
);
1535 assemble_integer (symbol
, POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
1538 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1539 not) section for PRIORITY. */
1541 get_cdtor_priority_section (int priority
, bool constructor_p
)
1545 /* ??? This only works reliably with the GNU linker. */
1546 sprintf (buf
, "%s.%.5u",
1547 constructor_p
? ".ctors" : ".dtors",
1548 /* Invert the numbering so the linker puts us in the proper
1549 order; constructors are run from right to left, and the
1550 linker sorts in increasing order. */
1551 MAX_INIT_PRIORITY
- priority
);
1552 return get_section (buf
, SECTION_WRITE
, NULL
);
1556 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1560 if (priority
!= DEFAULT_INIT_PRIORITY
)
1561 sec
= get_cdtor_priority_section (priority
,
1562 /*constructor_p=*/false);
1564 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1566 assemble_addr_to_section (symbol
, sec
);
1569 #ifdef DTORS_SECTION_ASM_OP
1571 default_dtor_section_asm_out_destructor (rtx symbol
,
1572 int priority ATTRIBUTE_UNUSED
)
1574 assemble_addr_to_section (symbol
, dtors_section
);
1579 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1583 if (priority
!= DEFAULT_INIT_PRIORITY
)
1584 sec
= get_cdtor_priority_section (priority
,
1585 /*constructor_p=*/true);
1587 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1589 assemble_addr_to_section (symbol
, sec
);
1592 #ifdef CTORS_SECTION_ASM_OP
1594 default_ctor_section_asm_out_constructor (rtx symbol
,
1595 int priority ATTRIBUTE_UNUSED
)
1597 assemble_addr_to_section (symbol
, ctors_section
);
1601 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1602 a nonzero value if the constant pool should be output before the
1603 start of the function, or a zero value if the pool should output
1604 after the end of the function. The default is to put it before the
1607 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1608 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1611 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1612 to be output to assembler.
1613 Set first_global_object_name and weak_global_object_name as appropriate. */
1616 notice_global_symbol (tree decl
)
1618 const char **t
= &first_global_object_name
;
1620 if (first_global_object_name
1621 || !TREE_PUBLIC (decl
)
1622 || DECL_EXTERNAL (decl
)
1623 || !DECL_NAME (decl
)
1624 || (TREE_CODE (decl
) == VAR_DECL
&& DECL_HARD_REGISTER (decl
))
1625 || (TREE_CODE (decl
) != FUNCTION_DECL
1626 && (TREE_CODE (decl
) != VAR_DECL
1627 || (DECL_COMMON (decl
)
1628 && (DECL_INITIAL (decl
) == 0
1629 || DECL_INITIAL (decl
) == error_mark_node
)))))
1632 /* We win when global object is found, but it is useful to know about weak
1633 symbol as well so we can produce nicer unique names. */
1634 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1635 t
= &weak_global_object_name
;
1639 tree id
= DECL_ASSEMBLER_NAME (decl
);
1640 ultimate_transparent_alias_target (&id
);
1641 *t
= ggc_strdup (targetm
.strip_name_encoding (IDENTIFIER_POINTER (id
)));
1645 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1646 current function goes into the cold section, so that targets can use
1647 current_function_section during RTL expansion. DECL describes the
1651 decide_function_section (tree decl
)
1653 first_function_block_is_cold
= false;
1655 if (flag_reorder_blocks_and_partition
)
1656 /* We will decide in assemble_start_function. */
1659 if (DECL_SECTION_NAME (decl
))
1661 struct cgraph_node
*node
= cgraph_node::get (current_function_decl
);
1662 /* Calls to function_section rely on first_function_block_is_cold
1664 first_function_block_is_cold
= (node
1666 == NODE_FREQUENCY_UNLIKELY_EXECUTED
);
1669 in_cold_section_p
= first_function_block_is_cold
;
1672 /* Get the function's name, as described by its RTL. This may be
1673 different from the DECL_NAME name used in the source file. */
1675 get_fnname_from_decl (tree decl
)
1677 rtx x
= DECL_RTL (decl
);
1678 gcc_assert (MEM_P (x
));
1680 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
1684 /* Output assembler code for the constant pool of a function and associated
1685 with defining the name of the function. DECL describes the function.
1686 NAME is the function's name. For the constant pool, we use the current
1687 constant pool data. */
1690 assemble_start_function (tree decl
, const char *fnname
)
1693 char tmp_label
[100];
1694 bool hot_label_written
= false;
1696 if (flag_reorder_blocks_and_partition
)
1698 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1699 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1700 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1701 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1702 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1703 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1704 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1705 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1707 cold_function_name
= NULL_TREE
;
1711 crtl
->subsections
.hot_section_label
= NULL
;
1712 crtl
->subsections
.cold_section_label
= NULL
;
1713 crtl
->subsections
.hot_section_end_label
= NULL
;
1714 crtl
->subsections
.cold_section_end_label
= NULL
;
1717 /* The following code does not need preprocessing in the assembler. */
1721 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1722 output_constant_pool (fnname
, decl
);
1724 align
= symtab_node::get (decl
)->definition_alignment ();
1726 /* Make sure the not and cold text (code) sections are properly
1727 aligned. This is necessary here in the case where the function
1728 has both hot and cold sections, because we don't want to re-set
1729 the alignment when the section switch happens mid-function. */
1731 if (flag_reorder_blocks_and_partition
)
1733 first_function_block_is_cold
= false;
1735 switch_to_section (unlikely_text_section ());
1736 assemble_align (align
);
1737 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1739 /* When the function starts with a cold section, we need to explicitly
1740 align the hot section and write out the hot section label.
1741 But if the current function is a thunk, we do not have a CFG. */
1743 && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun
)->next_bb
) == BB_COLD_PARTITION
)
1745 switch_to_section (text_section
);
1746 assemble_align (align
);
1747 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1748 hot_label_written
= true;
1749 first_function_block_is_cold
= true;
1751 in_cold_section_p
= first_function_block_is_cold
;
1755 /* Switch to the correct text section for the start of the function. */
1757 switch_to_section (function_section (decl
));
1758 if (flag_reorder_blocks_and_partition
1759 && !hot_label_written
)
1760 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1762 /* Tell assembler to move to target machine's alignment for functions. */
1763 align
= floor_log2 (align
/ BITS_PER_UNIT
);
1766 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1769 /* Handle a user-specified function alignment.
1770 Note that we still need to align to DECL_ALIGN, as above,
1771 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1772 if (! DECL_USER_ALIGN (decl
)
1773 && align_functions_log
> align
1774 && optimize_function_for_speed_p (cfun
))
1776 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1777 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1778 align_functions_log
, align_functions
- 1);
1780 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1784 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1785 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1788 if (!DECL_IGNORED_P (decl
))
1789 (*debug_hooks
->begin_function
) (decl
);
1791 /* Make function name accessible from other files, if appropriate. */
1793 if (TREE_PUBLIC (decl
)
1794 || (cgraph_node::get (decl
)->instrumentation_clone
1795 && cgraph_node::get (decl
)->instrumented_version
1796 && TREE_PUBLIC (cgraph_node::get (decl
)->instrumented_version
->decl
)))
1798 notice_global_symbol (decl
);
1800 globalize_decl (decl
);
1802 maybe_assemble_visibility (decl
);
1805 if (DECL_PRESERVE_P (decl
))
1806 targetm
.asm_out
.mark_decl_preserved (fnname
);
1808 /* Do any machine/system dependent processing of the function name. */
1809 #ifdef ASM_DECLARE_FUNCTION_NAME
1810 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1812 /* Standard thing is just output label for the function. */
1813 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1814 #endif /* ASM_DECLARE_FUNCTION_NAME */
1816 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1817 saw_no_split_stack
= true;
1820 /* Output assembler code associated with defining the size of the
1821 function. DECL describes the function. NAME is the function's name. */
1824 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1826 #ifdef ASM_DECLARE_FUNCTION_SIZE
1827 /* We could have switched section in the middle of the function. */
1828 if (flag_reorder_blocks_and_partition
)
1829 switch_to_section (function_section (decl
));
1830 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1832 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1834 output_constant_pool (fnname
, decl
);
1835 switch_to_section (function_section (decl
)); /* need to switch back */
1837 /* Output labels for end of hot/cold text sections (to be used by
1839 if (flag_reorder_blocks_and_partition
)
1841 section
*save_text_section
;
1843 save_text_section
= in_section
;
1844 switch_to_section (unlikely_text_section ());
1845 #ifdef ASM_DECLARE_COLD_FUNCTION_SIZE
1846 if (cold_function_name
!= NULL_TREE
)
1847 ASM_DECLARE_COLD_FUNCTION_SIZE (asm_out_file
,
1848 IDENTIFIER_POINTER (cold_function_name
),
1851 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1852 if (first_function_block_is_cold
)
1853 switch_to_section (text_section
);
1855 switch_to_section (function_section (decl
));
1856 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1857 switch_to_section (save_text_section
);
1861 /* Assemble code to leave SIZE bytes of zeros. */
1864 assemble_zeros (unsigned HOST_WIDE_INT size
)
1866 /* Do no output if -fsyntax-only. */
1867 if (flag_syntax_only
)
1870 #ifdef ASM_NO_SKIP_IN_TEXT
1871 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1872 so we must output 0s explicitly in the text section. */
1873 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1875 unsigned HOST_WIDE_INT i
;
1876 for (i
= 0; i
< size
; i
++)
1877 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1882 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1885 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1888 assemble_align (int align
)
1890 if (align
> BITS_PER_UNIT
)
1892 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1896 /* Assemble a string constant with the specified C string as contents. */
1899 assemble_string (const char *p
, int size
)
1904 /* If the string is very long, split it up. */
1908 int thissize
= size
- pos
;
1909 if (thissize
> maximum
)
1912 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1920 /* A noswitch_section_callback for lcomm_section. */
1923 emit_local (tree decl ATTRIBUTE_UNUSED
,
1924 const char *name ATTRIBUTE_UNUSED
,
1925 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1926 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1928 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1929 unsigned int align
= symtab_node::get (decl
)->definition_alignment ();
1930 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1933 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1934 unsigned int align
= symtab_node::get (decl
)->definition_alignment ();
1935 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, align
);
1938 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1943 /* A noswitch_section_callback for bss_noswitch_section. */
1945 #if defined ASM_OUTPUT_ALIGNED_BSS
1947 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1948 const char *name ATTRIBUTE_UNUSED
,
1949 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1950 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1952 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
,
1953 get_variable_align (decl
));
1958 /* A noswitch_section_callback for comm_section. */
1961 emit_common (tree decl ATTRIBUTE_UNUSED
,
1962 const char *name ATTRIBUTE_UNUSED
,
1963 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1964 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1966 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1967 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1968 size
, get_variable_align (decl
));
1970 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1971 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
1972 get_variable_align (decl
));
1975 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1980 /* A noswitch_section_callback for tls_comm_section. */
1983 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1984 const char *name ATTRIBUTE_UNUSED
,
1985 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1986 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1988 #ifdef ASM_OUTPUT_TLS_COMMON
1989 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1992 sorry ("thread-local COMMON data not implemented");
1997 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1998 NAME is the name of DECL's SYMBOL_REF. */
2001 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
,
2004 unsigned HOST_WIDE_INT size
, rounded
;
2006 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2009 if ((flag_sanitize
& SANITIZE_ADDRESS
) && asan_protect_global (decl
))
2010 size
+= asan_red_zone_size (size
);
2012 /* Don't allocate zero bytes of common,
2013 since that means "undefined external" in the linker. */
2017 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2018 so that each uninitialized object starts on such a boundary. */
2019 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
2020 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2021 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2023 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
2024 && (unsigned HOST_WIDE_INT
) (align
/ BITS_PER_UNIT
) > rounded
)
2025 error ("requested alignment for %q+D is greater than "
2026 "implemented alignment of %wu", decl
, rounded
);
2029 /* A subroutine of assemble_variable. Output the label and contents of
2030 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2031 is as for assemble_variable. */
2034 assemble_variable_contents (tree decl
, const char *name
,
2035 bool dont_output_data
)
2037 /* Do any machine/system dependent processing of the object. */
2038 #ifdef ASM_DECLARE_OBJECT_NAME
2039 last_assemble_variable_decl
= decl
;
2040 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
2042 /* Standard thing is just output label for the object. */
2043 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2044 #endif /* ASM_DECLARE_OBJECT_NAME */
2046 if (!dont_output_data
)
2048 /* Caller is supposed to use varpool_get_constructor when it wants
2049 to output the body. */
2050 gcc_assert (!in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
);
2051 if (DECL_INITIAL (decl
)
2052 && DECL_INITIAL (decl
) != error_mark_node
2053 && !initializer_zerop (DECL_INITIAL (decl
)))
2054 /* Output the actual data. */
2055 output_constant (DECL_INITIAL (decl
),
2056 tree_to_uhwi (DECL_SIZE_UNIT (decl
)),
2057 get_variable_align (decl
));
2059 /* Leave space for it. */
2060 assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl
)));
2061 targetm
.asm_out
.decl_end ();
2065 /* Write out assembly for the variable DECL, which is not defined in
2066 the current translation unit. */
2068 assemble_undefined_decl (tree decl
)
2070 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
2071 targetm
.asm_out
.assemble_undefined_decl (asm_out_file
, name
, decl
);
2074 /* Assemble everything that is needed for a variable or function declaration.
2075 Not used for automatic variables, and not used for function definitions.
2076 Should not be called for variables of incomplete structure type.
2078 TOP_LEVEL is nonzero if this variable has file scope.
2079 AT_END is nonzero if this is the special handling, at end of compilation,
2080 to define things that have had only tentative definitions.
2081 DONT_OUTPUT_DATA if nonzero means don't actually output the
2082 initial value (that will be done by the caller). */
2085 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
2086 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
2089 rtx decl_rtl
, symbol
;
2092 bool asan_protected
= false;
2094 /* This function is supposed to handle VARIABLES. Ensure we have one. */
2095 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
2097 /* Emulated TLS had better not get this far. */
2098 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
2100 last_assemble_variable_decl
= 0;
2102 /* Normally no need to say anything here for external references,
2103 since assemble_external is called by the language-specific code
2104 when a declaration is first seen. */
2106 if (DECL_EXTERNAL (decl
))
2109 /* Do nothing for global register variables. */
2110 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2112 TREE_ASM_WRITTEN (decl
) = 1;
2116 /* If type was incomplete when the variable was declared,
2117 see if it is complete now. */
2119 if (DECL_SIZE (decl
) == 0)
2120 layout_decl (decl
, 0);
2122 /* Still incomplete => don't allocate it; treat the tentative defn
2123 (which is what it must have been) as an `extern' reference. */
2125 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2127 error ("storage size of %q+D isn%'t known", decl
);
2128 TREE_ASM_WRITTEN (decl
) = 1;
2132 /* The first declaration of a variable that comes through this function
2133 decides whether it is global (in C, has external linkage)
2134 or local (in C, has internal linkage). So do nothing more
2135 if this function has already run. */
2137 if (TREE_ASM_WRITTEN (decl
))
2140 /* Make sure targetm.encode_section_info is invoked before we set
2142 decl_rtl
= DECL_RTL (decl
);
2144 TREE_ASM_WRITTEN (decl
) = 1;
2146 /* Do no output if -fsyntax-only. */
2147 if (flag_syntax_only
)
2150 if (! dont_output_data
2151 && ! valid_constant_size_p (DECL_SIZE_UNIT (decl
)))
2153 error ("size of variable %q+D is too large", decl
);
2157 gcc_assert (MEM_P (decl_rtl
));
2158 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2159 symbol
= XEXP (decl_rtl
, 0);
2161 /* If this symbol belongs to the tree constant pool, output the constant
2162 if it hasn't already been written. */
2163 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
2165 tree decl
= SYMBOL_REF_DECL (symbol
);
2166 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2167 output_constant_def_contents (symbol
);
2173 name
= XSTR (symbol
, 0);
2174 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2175 notice_global_symbol (decl
);
2177 /* Compute the alignment of this data. */
2179 align_variable (decl
, dont_output_data
);
2181 if ((flag_sanitize
& SANITIZE_ADDRESS
)
2182 && asan_protect_global (decl
))
2184 asan_protected
= true;
2185 DECL_ALIGN (decl
) = MAX (DECL_ALIGN (decl
),
2186 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
2189 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2191 align
= get_variable_align (decl
);
2193 if (TREE_PUBLIC (decl
))
2194 maybe_assemble_visibility (decl
);
2196 if (DECL_PRESERVE_P (decl
))
2197 targetm
.asm_out
.mark_decl_preserved (name
);
2199 /* First make the assembler name(s) global if appropriate. */
2200 sect
= get_variable_section (decl
, false);
2201 if (TREE_PUBLIC (decl
)
2202 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2203 globalize_decl (decl
);
2205 /* Output any data that we will need to use the address of. */
2206 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2207 output_addressed_constants (DECL_INITIAL (decl
));
2209 /* dbxout.c needs to know this. */
2210 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2211 DECL_IN_TEXT_SECTION (decl
) = 1;
2213 /* If the decl is part of an object_block, make sure that the decl
2214 has been positioned within its block, but do not write out its
2215 definition yet. output_object_blocks will do that later. */
2216 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2218 gcc_assert (!dont_output_data
);
2219 place_block_symbol (symbol
);
2221 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2222 assemble_noswitch_variable (decl
, name
, sect
, align
);
2225 /* Special-case handling of vtv comdat sections. */
2226 if (sect
->named
.name
2227 && (strcmp (sect
->named
.name
, ".vtable_map_vars") == 0))
2228 handle_vtv_comdat_section (sect
, decl
);
2230 switch_to_section (sect
);
2231 if (align
> BITS_PER_UNIT
)
2232 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2233 assemble_variable_contents (decl
, name
, dont_output_data
);
2236 unsigned HOST_WIDE_INT
int size
2237 = tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2238 assemble_zeros (asan_red_zone_size (size
));
2244 /* Given a function declaration (FN_DECL), this function assembles the
2245 function into the .preinit_array section. */
2248 assemble_vtv_preinit_initializer (tree fn_decl
)
2251 unsigned flags
= SECTION_WRITE
;
2252 rtx symbol
= XEXP (DECL_RTL (fn_decl
), 0);
2254 flags
|= SECTION_NOTYPE
;
2255 sect
= get_section (".preinit_array", flags
, fn_decl
);
2256 switch_to_section (sect
);
2257 assemble_addr_to_section (symbol
, sect
);
2260 /* Return 1 if type TYPE contains any pointers. */
2263 contains_pointers_p (tree type
)
2265 switch (TREE_CODE (type
))
2268 case REFERENCE_TYPE
:
2269 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2270 so I'll play safe and return 1. */
2276 case QUAL_UNION_TYPE
:
2279 /* For a type that has fields, see if the fields have pointers. */
2280 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
2281 if (TREE_CODE (fields
) == FIELD_DECL
2282 && contains_pointers_p (TREE_TYPE (fields
)))
2288 /* An array type contains pointers if its element type does. */
2289 return contains_pointers_p (TREE_TYPE (type
));
2296 /* We delay assemble_external processing until
2297 the compilation unit is finalized. This is the best we can do for
2298 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2299 it all the way to final. See PR 17982 for further discussion. */
2300 static GTY(()) tree pending_assemble_externals
;
2302 #ifdef ASM_OUTPUT_EXTERNAL
2303 /* Some targets delay some output to final using TARGET_ASM_FILE_END.
2304 As a result, assemble_external can be called after the list of externals
2305 is processed and the pointer set destroyed. */
2306 static bool pending_assemble_externals_processed
;
2308 /* Avoid O(external_decls**2) lookups in the pending_assemble_externals
2309 TREE_LIST in assemble_external. */
2310 static hash_set
<tree
> *pending_assemble_externals_set
;
2312 /* True if DECL is a function decl for which no out-of-line copy exists.
2313 It is assumed that DECL's assembler name has been set. */
2316 incorporeal_function_p (tree decl
)
2318 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2322 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2323 && (DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
2324 || DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA_WITH_ALIGN
))
2327 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2328 /* Atomic or sync builtins which have survived this far will be
2329 resolved externally and therefore are not incorporeal. */
2330 if (strncmp (name
, "__builtin_", 10) == 0)
2336 /* Actually do the tests to determine if this is necessary, and invoke
2337 ASM_OUTPUT_EXTERNAL. */
2339 assemble_external_real (tree decl
)
2341 rtx rtl
= DECL_RTL (decl
);
2343 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2344 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2345 && !incorporeal_function_p (decl
))
2347 /* Some systems do require some output. */
2348 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2349 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2355 process_pending_assemble_externals (void)
2357 #ifdef ASM_OUTPUT_EXTERNAL
2359 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2360 assemble_external_real (TREE_VALUE (list
));
2362 pending_assemble_externals
= 0;
2363 pending_assemble_externals_processed
= true;
2364 delete pending_assemble_externals_set
;
2368 /* This TREE_LIST contains any weak symbol declarations waiting
2370 static GTY(()) tree weak_decls
;
2372 /* Output something to declare an external symbol to the assembler,
2373 and qualifiers such as weakness. (Most assemblers don't need
2374 extern declaration, so we normally output nothing.) Do nothing if
2375 DECL is not external. */
2378 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2380 /* Make sure that the ASM_OUT_FILE is open.
2381 If it's not, we should not be calling this function. */
2382 gcc_assert (asm_out_file
);
2384 /* In a perfect world, the following condition would be true.
2385 Sadly, the Java and Go front ends emit assembly *from the front end*,
2386 bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2388 /* This function should only be called if we are expanding, or have
2390 Ideally, only final.c would be calling this function, but it is
2391 not clear whether that would break things somehow. See PR 17982
2392 for further discussion. */
2393 gcc_assert (state
== EXPANSION
2394 || state
== FINISHED
);
2397 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2400 /* We want to output annotation for weak and external symbols at
2401 very last to check if they are references or not. */
2403 if (TARGET_SUPPORTS_WEAK
2405 /* TREE_STATIC is a weird and abused creature which is not
2406 generally the right test for whether an entity has been
2407 locally emitted, inlined or otherwise not-really-extern, but
2408 for declarations that can be weak, it happens to be
2410 && !TREE_STATIC (decl
)
2411 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2412 && value_member (decl
, weak_decls
) == NULL_TREE
)
2413 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2415 #ifdef ASM_OUTPUT_EXTERNAL
2416 if (pending_assemble_externals_processed
)
2418 assemble_external_real (decl
);
2422 if (! pending_assemble_externals_set
->add (decl
))
2423 pending_assemble_externals
= tree_cons (NULL
, decl
,
2424 pending_assemble_externals
);
2428 /* Similar, for calling a library function FUN. */
2431 assemble_external_libcall (rtx fun
)
2433 /* Declare library function name external when first used, if nec. */
2434 if (! SYMBOL_REF_USED (fun
))
2436 SYMBOL_REF_USED (fun
) = 1;
2437 targetm
.asm_out
.external_libcall (fun
);
2441 /* Assemble a label named NAME. */
2444 assemble_label (FILE *file
, const char *name
)
2446 ASM_OUTPUT_LABEL (file
, name
);
2449 /* Set the symbol_referenced flag for ID. */
2451 mark_referenced (tree id
)
2453 TREE_SYMBOL_REFERENCED (id
) = 1;
2456 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2458 mark_decl_referenced (tree decl
)
2460 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2462 /* Extern inline functions don't become needed when referenced.
2463 If we know a method will be emitted in other TU and no new
2464 functions can be marked reachable, just use the external
2466 struct cgraph_node
*node
= cgraph_node::get_create (decl
);
2467 if (!DECL_EXTERNAL (decl
)
2468 && !node
->definition
)
2469 node
->mark_force_output ();
2471 else if (TREE_CODE (decl
) == VAR_DECL
)
2473 varpool_node
*node
= varpool_node::get_create (decl
);
2474 /* C++ frontend use mark_decl_references to force COMDAT variables
2475 to be output that might appear dead otherwise. */
2476 node
->force_output
= true;
2478 /* else do nothing - we can get various sorts of CST nodes here,
2479 which do not need to be marked. */
2483 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2484 starts with a *, the rest of NAME is output verbatim. Otherwise
2485 NAME is transformed in a target-specific way (usually by the
2486 addition of an underscore). */
2489 assemble_name_raw (FILE *file
, const char *name
)
2492 fputs (&name
[1], file
);
2494 ASM_OUTPUT_LABELREF (file
, name
);
2497 /* Like assemble_name_raw, but should be used when NAME might refer to
2498 an entity that is also represented as a tree (like a function or
2499 variable). If NAME does refer to such an entity, that entity will
2500 be marked as referenced. */
2503 assemble_name (FILE *file
, const char *name
)
2505 const char *real_name
;
2508 real_name
= targetm
.strip_name_encoding (name
);
2510 id
= maybe_get_identifier (real_name
);
2515 mark_referenced (id
);
2516 ultimate_transparent_alias_target (&id
);
2518 name
= IDENTIFIER_POINTER (id
);
2519 gcc_assert (! TREE_CHAIN (id
));
2522 assemble_name_raw (file
, name
);
2525 /* Allocate SIZE bytes writable static space with a gensym name
2526 and return an RTX to refer to its address. */
2529 assemble_static_space (unsigned HOST_WIDE_INT size
)
2532 const char *namestring
;
2535 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2537 namestring
= ggc_strdup (name
);
2539 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2540 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2542 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2543 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2546 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2547 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2550 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2551 so that each uninitialized object starts on such a boundary. */
2552 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2553 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2554 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2555 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2556 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2557 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2564 /* Assemble the static constant template for function entry trampolines.
2565 This is done at most once per compilation.
2566 Returns an RTX for the address of the template. */
2568 static GTY(()) rtx initial_trampoline
;
2571 assemble_trampoline_template (void)
2578 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2580 if (initial_trampoline
)
2581 return initial_trampoline
;
2583 /* By default, put trampoline templates in read-only data section. */
2585 #ifdef TRAMPOLINE_SECTION
2586 switch_to_section (TRAMPOLINE_SECTION
);
2588 switch_to_section (readonly_data_section
);
2591 /* Write the assembler code to define one. */
2592 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2594 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2596 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2597 targetm
.asm_out
.trampoline_template (asm_out_file
);
2599 /* Record the rtl to refer to it. */
2600 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2601 name
= ggc_strdup (label
);
2602 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2603 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2605 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2606 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2607 set_mem_size (initial_trampoline
, TRAMPOLINE_SIZE
);
2609 return initial_trampoline
;
2612 /* A and B are either alignments or offsets. Return the minimum alignment
2613 that may be assumed after adding the two together. */
2615 static inline unsigned
2616 min_align (unsigned int a
, unsigned int b
)
2618 return (a
| b
) & -(a
| b
);
2621 /* Return the assembler directive for creating a given kind of integer
2622 object. SIZE is the number of bytes in the object and ALIGNED_P
2623 indicates whether it is known to be aligned. Return NULL if the
2624 assembly dialect has no such directive.
2626 The returned string should be printed at the start of a new line and
2627 be followed immediately by the object's initial value. */
2630 integer_asm_op (int size
, int aligned_p
)
2632 struct asm_int_op
*ops
;
2635 ops
= &targetm
.asm_out
.aligned_op
;
2637 ops
= &targetm
.asm_out
.unaligned_op
;
2642 return targetm
.asm_out
.byte_op
;
2656 /* Use directive OP to assemble an integer object X. Print OP at the
2657 start of the line, followed immediately by the value of X. */
2660 assemble_integer_with_op (const char *op
, rtx x
)
2662 fputs (op
, asm_out_file
);
2663 output_addr_const (asm_out_file
, x
);
2664 fputc ('\n', asm_out_file
);
2667 /* The default implementation of the asm_out.integer target hook. */
2670 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2671 unsigned int size ATTRIBUTE_UNUSED
,
2672 int aligned_p ATTRIBUTE_UNUSED
)
2674 const char *op
= integer_asm_op (size
, aligned_p
);
2675 /* Avoid GAS bugs for large values. Specifically negative values whose
2676 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2677 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE_UNITS
)
2679 return op
&& (assemble_integer_with_op (op
, x
), true);
2682 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2683 the alignment of the integer in bits. Return 1 if we were able to output
2684 the constant, otherwise 0. We must be able to output the constant,
2685 if FORCE is nonzero. */
2688 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2692 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2694 /* See if the target hook can handle this kind of object. */
2695 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2698 /* If the object is a multi-byte one, try splitting it up. Split
2699 it into words it if is multi-word, otherwise split it into bytes. */
2702 machine_mode omode
, imode
;
2703 unsigned int subalign
;
2704 unsigned int subsize
, i
;
2705 enum mode_class mclass
;
2707 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2708 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2709 if (GET_CODE (x
) == CONST_FIXED
)
2710 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2714 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2715 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2717 for (i
= 0; i
< size
; i
+= subsize
)
2719 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2720 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2726 /* If we've printed some of it, but not all of it, there's no going
2731 gcc_assert (!force
);
2737 assemble_real (REAL_VALUE_TYPE d
, machine_mode mode
, unsigned int align
)
2739 long data
[4] = {0, 0, 0, 0};
2741 int bitsize
, nelts
, nunits
, units_per
;
2743 /* This is hairy. We have a quantity of known size. real_to_target
2744 will put it into an array of *host* longs, 32 bits per element
2745 (even if long is more than 32 bits). We need to determine the
2746 number of array elements that are occupied (nelts) and the number
2747 of *target* min-addressable units that will be occupied in the
2748 object file (nunits). We cannot assume that 32 divides the
2749 mode's bitsize (size * BITS_PER_UNIT) evenly.
2751 size * BITS_PER_UNIT is used here to make sure that padding bits
2752 (which might appear at either end of the value; real_to_target
2753 will include the padding bits in its output array) are included. */
2755 nunits
= GET_MODE_SIZE (mode
);
2756 bitsize
= nunits
* BITS_PER_UNIT
;
2757 nelts
= CEIL (bitsize
, 32);
2758 units_per
= 32 / BITS_PER_UNIT
;
2760 real_to_target (data
, &d
, mode
);
2762 /* Put out the first word with the specified alignment. */
2763 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2764 nunits
-= units_per
;
2766 /* Subsequent words need only 32-bit alignment. */
2767 align
= min_align (align
, 32);
2769 for (i
= 1; i
< nelts
; i
++)
2771 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2772 nunits
-= units_per
;
2776 /* Given an expression EXP with a constant value,
2777 reduce it to the sum of an assembler symbol and an integer.
2778 Store them both in the structure *VALUE.
2779 EXP must be reducible. */
2783 HOST_WIDE_INT offset
;
2787 decode_addr_const (tree exp
, struct addr_const
*value
)
2789 tree target
= TREE_OPERAND (exp
, 0);
2795 if (TREE_CODE (target
) == COMPONENT_REF
2796 && tree_fits_shwi_p (byte_position (TREE_OPERAND (target
, 1))))
2798 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2799 target
= TREE_OPERAND (target
, 0);
2801 else if (TREE_CODE (target
) == ARRAY_REF
2802 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2804 offset
+= (tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (target
)))
2805 * tree_to_shwi (TREE_OPERAND (target
, 1)));
2806 target
= TREE_OPERAND (target
, 0);
2808 else if (TREE_CODE (target
) == MEM_REF
2809 && TREE_CODE (TREE_OPERAND (target
, 0)) == ADDR_EXPR
)
2811 offset
+= mem_ref_offset (target
).to_short_addr ();
2812 target
= TREE_OPERAND (TREE_OPERAND (target
, 0), 0);
2814 else if (TREE_CODE (target
) == INDIRECT_REF
2815 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2816 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2818 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2823 switch (TREE_CODE (target
))
2827 x
= DECL_RTL (target
);
2831 x
= gen_rtx_MEM (FUNCTION_MODE
,
2832 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2841 x
= output_constant_def (target
, 1);
2848 gcc_assert (MEM_P (x
));
2852 value
->offset
= offset
;
2855 static GTY(()) hash_table
<tree_descriptor_hasher
> *const_desc_htab
;
2857 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2859 /* Constant pool accessor function. */
2861 hash_table
<tree_descriptor_hasher
> *
2862 constant_pool_htab (void)
2864 return const_desc_htab
;
2867 /* Compute a hash code for a constant expression. */
2870 tree_descriptor_hasher::hash (constant_descriptor_tree
*ptr
)
2876 const_hash_1 (const tree exp
)
2881 enum tree_code code
= TREE_CODE (exp
);
2883 /* Either set P and LEN to the address and len of something to hash and
2884 exit the switch or return a value. */
2889 p
= (char *) &TREE_INT_CST_ELT (exp
, 0);
2890 len
= TREE_INT_CST_NUNITS (exp
) * sizeof (HOST_WIDE_INT
);
2894 return real_hash (TREE_REAL_CST_PTR (exp
));
2897 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2900 p
= TREE_STRING_POINTER (exp
);
2901 len
= TREE_STRING_LENGTH (exp
);
2905 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2906 + const_hash_1 (TREE_IMAGPART (exp
)));
2912 hi
= 7 + VECTOR_CST_NELTS (exp
);
2914 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
2915 hi
= hi
* 563 + const_hash_1 (VECTOR_CST_ELT (exp
, i
));
2922 unsigned HOST_WIDE_INT idx
;
2925 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2927 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2929 hi
= hi
* 603 + const_hash_1 (value
);
2937 struct addr_const value
;
2939 decode_addr_const (exp
, &value
);
2940 switch (GET_CODE (value
.base
))
2943 /* Don't hash the address of the SYMBOL_REF;
2944 only use the offset and the symbol name. */
2946 p
= XSTR (value
.base
, 0);
2947 for (i
= 0; p
[i
] != 0; i
++)
2948 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2953 + CODE_LABEL_NUMBER (LABEL_REF_LABEL (value
.base
)) * 13);
2963 case POINTER_PLUS_EXPR
:
2965 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2966 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2969 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2972 /* A language specific constant. Just hash the code. */
2976 /* Compute hashing function. */
2978 for (i
= 0; i
< len
; i
++)
2979 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2984 /* Wrapper of compare_constant, for the htab interface. */
2986 tree_descriptor_hasher::equal (constant_descriptor_tree
*c1
,
2987 constant_descriptor_tree
*c2
)
2989 if (c1
->hash
!= c2
->hash
)
2991 return compare_constant (c1
->value
, c2
->value
);
2994 /* Compare t1 and t2, and return 1 only if they are known to result in
2995 the same bit pattern on output. */
2998 compare_constant (const tree t1
, const tree t2
)
3000 enum tree_code typecode
;
3002 if (t1
== NULL_TREE
)
3003 return t2
== NULL_TREE
;
3004 if (t2
== NULL_TREE
)
3007 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3010 switch (TREE_CODE (t1
))
3013 /* Integer constants are the same only if the same width of type. */
3014 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3016 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3018 return tree_int_cst_equal (t1
, t2
);
3021 /* Real constants are the same only if the same width of type. */
3022 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3025 return real_identical (&TREE_REAL_CST (t1
), &TREE_REAL_CST (t2
));
3028 /* Fixed constants are the same only if the same width of type. */
3029 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3032 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
3035 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3038 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3039 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3040 TREE_STRING_LENGTH (t1
)));
3043 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
3044 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
3050 if (VECTOR_CST_NELTS (t1
) != VECTOR_CST_NELTS (t2
))
3053 for (i
= 0; i
< VECTOR_CST_NELTS (t1
); ++i
)
3054 if (!compare_constant (VECTOR_CST_ELT (t1
, i
),
3055 VECTOR_CST_ELT (t2
, i
)))
3063 vec
<constructor_elt
, va_gc
> *v1
, *v2
;
3064 unsigned HOST_WIDE_INT idx
;
3066 typecode
= TREE_CODE (TREE_TYPE (t1
));
3067 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3070 if (typecode
== ARRAY_TYPE
)
3072 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3073 /* For arrays, check that the sizes all match. */
3074 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3076 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
3081 /* For record and union constructors, require exact type
3083 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3087 v1
= CONSTRUCTOR_ELTS (t1
);
3088 v2
= CONSTRUCTOR_ELTS (t2
);
3089 if (vec_safe_length (v1
) != vec_safe_length (v2
))
3092 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
3094 constructor_elt
*c1
= &(*v1
)[idx
];
3095 constructor_elt
*c2
= &(*v2
)[idx
];
3097 /* Check that each value is the same... */
3098 if (!compare_constant (c1
->value
, c2
->value
))
3100 /* ... and that they apply to the same fields! */
3101 if (typecode
== ARRAY_TYPE
)
3103 if (!compare_constant (c1
->index
, c2
->index
))
3108 if (c1
->index
!= c2
->index
)
3119 struct addr_const value1
, value2
;
3123 decode_addr_const (t1
, &value1
);
3124 decode_addr_const (t2
, &value2
);
3126 if (value1
.offset
!= value2
.offset
)
3129 code
= GET_CODE (value1
.base
);
3130 if (code
!= GET_CODE (value2
.base
))
3136 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3140 ret
= (CODE_LABEL_NUMBER (LABEL_REF_LABEL (value1
.base
))
3141 == CODE_LABEL_NUMBER (LABEL_REF_LABEL (value2
.base
)));
3151 case POINTER_PLUS_EXPR
:
3154 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3155 && compare_constant (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3158 case VIEW_CONVERT_EXPR
:
3159 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3168 /* Return the section into which constant EXP should be placed. */
3171 get_constant_section (tree exp
, unsigned int align
)
3173 return targetm
.asm_out
.select_section (exp
,
3174 compute_reloc_for_constant (exp
),
3178 /* Return the size of constant EXP in bytes. */
3180 static HOST_WIDE_INT
3181 get_constant_size (tree exp
)
3185 size
= int_size_in_bytes (TREE_TYPE (exp
));
3186 if (TREE_CODE (exp
) == STRING_CST
)
3187 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3191 /* Subroutine of output_constant_def:
3192 No constant equal to EXP is known to have been output.
3193 Make a constant descriptor to enter EXP in the hash table.
3194 Assign the label number and construct RTL to refer to the
3195 constant's location in memory.
3196 Caller is responsible for updating the hash table. */
3198 static struct constant_descriptor_tree
*
3199 build_constant_desc (tree exp
)
3201 struct constant_descriptor_tree
*desc
;
3207 desc
= ggc_alloc
<constant_descriptor_tree
> ();
3210 /* Create a string containing the label name, in LABEL. */
3211 labelno
= const_labelno
++;
3212 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3214 /* Construct the VAR_DECL associated with the constant. */
3215 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3217 DECL_ARTIFICIAL (decl
) = 1;
3218 DECL_IGNORED_P (decl
) = 1;
3219 TREE_READONLY (decl
) = 1;
3220 TREE_STATIC (decl
) = 1;
3221 TREE_ADDRESSABLE (decl
) = 1;
3222 /* We don't set the RTL yet as this would cause varpool to assume that the
3223 variable is referenced. Moreover, it would just be dropped in LTO mode.
3224 Instead we set the flag that will be recognized in make_decl_rtl. */
3225 DECL_IN_CONSTANT_POOL (decl
) = 1;
3226 DECL_INITIAL (decl
) = desc
->value
;
3227 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3228 architectures so use DATA_ALIGNMENT as well, except for strings. */
3229 if (TREE_CODE (exp
) == STRING_CST
)
3231 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
3234 align_variable (decl
, 0);
3236 /* Now construct the SYMBOL_REF and the MEM. */
3237 if (use_object_blocks_p ())
3239 int align
= (TREE_CODE (decl
) == CONST_DECL
3240 || (TREE_CODE (decl
) == VAR_DECL
3241 && DECL_IN_CONSTANT_POOL (decl
))
3243 : symtab_node::get (decl
)->definition_alignment ());
3244 section
*sect
= get_constant_section (exp
, align
);
3245 symbol
= create_block_symbol (ggc_strdup (label
),
3246 get_block_for_section (sect
), -1);
3249 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3250 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3251 SET_SYMBOL_REF_DECL (symbol
, decl
);
3252 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3254 rtl
= gen_const_mem (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3255 set_mem_attributes (rtl
, exp
, 1);
3256 set_mem_alias_set (rtl
, 0);
3258 /* We cannot share RTX'es in pool entries.
3259 Mark this piece of RTL as required for unsharing. */
3260 RTX_FLAG (rtl
, used
) = 1;
3262 /* Set flags or add text to the name to record information, such as
3263 that it is a local symbol. If the name is changed, the macro
3264 ASM_OUTPUT_LABELREF will have to know how to strip this
3265 information. This call might invalidate our local variable
3266 SYMBOL; we can't use it afterward. */
3267 targetm
.encode_section_info (exp
, rtl
, true);
3274 /* Return an rtx representing a reference to constant data in memory
3275 for the constant expression EXP.
3277 If assembler code for such a constant has already been output,
3278 return an rtx to refer to it.
3279 Otherwise, output such a constant in memory
3280 and generate an rtx for it.
3282 If DEFER is nonzero, this constant can be deferred and output only
3283 if referenced in the function after all optimizations.
3285 `const_desc_table' records which constants already have label strings. */
3288 output_constant_def (tree exp
, int defer
)
3290 struct constant_descriptor_tree
*desc
;
3291 struct constant_descriptor_tree key
;
3293 /* Look up EXP in the table of constant descriptors. If we didn't find
3294 it, create a new one. */
3296 key
.hash
= const_hash_1 (exp
);
3297 constant_descriptor_tree
**loc
3298 = const_desc_htab
->find_slot_with_hash (&key
, key
.hash
, INSERT
);
3303 desc
= build_constant_desc (exp
);
3304 desc
->hash
= key
.hash
;
3308 maybe_output_constant_def_contents (desc
, defer
);
3312 /* Subroutine of output_constant_def: Decide whether or not we need to
3313 output the constant DESC now, and if so, do it. */
3315 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3318 rtx symbol
= XEXP (desc
->rtl
, 0);
3319 tree exp
= desc
->value
;
3321 if (flag_syntax_only
)
3324 if (TREE_ASM_WRITTEN (exp
))
3325 /* Already output; don't do it again. */
3328 /* We can always defer constants as long as the context allows
3332 /* Increment n_deferred_constants if it exists. It needs to be at
3333 least as large as the number of constants actually referred to
3334 by the function. If it's too small we'll stop looking too early
3335 and fail to emit constants; if it's too large we'll only look
3336 through the entire function when we could have stopped earlier. */
3338 n_deferred_constants
++;
3342 output_constant_def_contents (symbol
);
3345 /* Subroutine of output_constant_def_contents. Output the definition
3346 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3347 constant's alignment in bits. */
3350 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3354 size
= get_constant_size (exp
);
3356 /* Do any machine/system dependent processing of the constant. */
3357 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3359 /* Output the value of EXP. */
3360 output_constant (exp
, size
, align
);
3362 targetm
.asm_out
.decl_end ();
3365 /* We must output the constant data referred to by SYMBOL; do so. */
3368 output_constant_def_contents (rtx symbol
)
3370 tree decl
= SYMBOL_REF_DECL (symbol
);
3371 tree exp
= DECL_INITIAL (decl
);
3372 bool asan_protected
= false;
3374 /* Make sure any other constants whose addresses appear in EXP
3375 are assigned label numbers. */
3376 output_addressed_constants (exp
);
3378 /* We are no longer deferring this constant. */
3379 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3381 if ((flag_sanitize
& SANITIZE_ADDRESS
)
3382 && TREE_CODE (exp
) == STRING_CST
3383 && asan_protect_global (exp
))
3385 asan_protected
= true;
3386 DECL_ALIGN (decl
) = MAX (DECL_ALIGN (decl
),
3387 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
3390 /* If the constant is part of an object block, make sure that the
3391 decl has been positioned within its block, but do not write out
3392 its definition yet. output_object_blocks will do that later. */
3393 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3394 place_block_symbol (symbol
);
3397 int align
= (TREE_CODE (decl
) == CONST_DECL
3398 || (TREE_CODE (decl
) == VAR_DECL
3399 && DECL_IN_CONSTANT_POOL (decl
))
3401 : symtab_node::get (decl
)->definition_alignment ());
3402 switch_to_section (get_constant_section (exp
, align
));
3403 if (align
> BITS_PER_UNIT
)
3404 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3405 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3408 HOST_WIDE_INT size
= get_constant_size (exp
);
3409 assemble_zeros (asan_red_zone_size (size
));
3414 /* Look up EXP in the table of constant descriptors. Return the rtl
3415 if it has been emitted, else null. */
3418 lookup_constant_def (tree exp
)
3420 struct constant_descriptor_tree key
;
3423 key
.hash
= const_hash_1 (exp
);
3424 constant_descriptor_tree
*desc
3425 = const_desc_htab
->find_with_hash (&key
, key
.hash
);
3427 return (desc
? desc
->rtl
: NULL_RTX
);
3430 /* Return a tree representing a reference to constant data in memory
3431 for the constant expression EXP.
3433 This is the counterpart of output_constant_def at the Tree level. */
3436 tree_output_constant_def (tree exp
)
3438 struct constant_descriptor_tree
*desc
, key
;
3441 /* Look up EXP in the table of constant descriptors. If we didn't find
3442 it, create a new one. */
3444 key
.hash
= const_hash_1 (exp
);
3445 constant_descriptor_tree
**loc
3446 = const_desc_htab
->find_slot_with_hash (&key
, key
.hash
, INSERT
);
3451 desc
= build_constant_desc (exp
);
3452 desc
->hash
= key
.hash
;
3456 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3457 varpool_node::finalize_decl (decl
);
3461 struct GTY((chain_next ("%h.next"), for_user
)) constant_descriptor_rtx
{
3462 struct constant_descriptor_rtx
*next
;
3466 HOST_WIDE_INT offset
;
3474 struct const_rtx_desc_hasher
: ggc_ptr_hash
<constant_descriptor_rtx
>
3476 static hashval_t
hash (constant_descriptor_rtx
*);
3477 static bool equal (constant_descriptor_rtx
*, constant_descriptor_rtx
*);
3480 /* Used in the hash tables to avoid outputting the same constant
3481 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3482 are output once per function, not once per file. */
3483 /* ??? Only a few targets need per-function constant pools. Most
3484 can use one per-file pool. Should add a targetm bit to tell the
3487 struct GTY(()) rtx_constant_pool
{
3488 /* Pointers to first and last constant in pool, as ordered by offset. */
3489 struct constant_descriptor_rtx
*first
;
3490 struct constant_descriptor_rtx
*last
;
3492 /* Hash facility for making memory-constants from constant rtl-expressions.
3493 It is used on RISC machines where immediate integer arguments and
3494 constant addresses are restricted so that such constants must be stored
3496 hash_table
<const_rtx_desc_hasher
> *const_rtx_htab
;
3498 /* Current offset in constant pool (does not include any
3499 machine-specific header). */
3500 HOST_WIDE_INT offset
;
3503 /* Hash and compare functions for const_rtx_htab. */
3506 const_rtx_desc_hasher::hash (constant_descriptor_rtx
*desc
)
3512 const_rtx_desc_hasher::equal (constant_descriptor_rtx
*x
,
3513 constant_descriptor_rtx
*y
)
3515 if (x
->mode
!= y
->mode
)
3517 return rtx_equal_p (x
->constant
, y
->constant
);
3520 /* Hash one component of a constant. */
3523 const_rtx_hash_1 (const_rtx x
)
3525 unsigned HOST_WIDE_INT hwi
;
3531 code
= GET_CODE (x
);
3532 mode
= GET_MODE (x
);
3533 h
= (hashval_t
) code
* 1048573 + mode
;
3542 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3543 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3545 h
^= (hashval_t
) hwi
;
3546 for (i
= 1; i
< n
; ++i
)
3549 h
^= (hashval_t
) hwi
;
3554 case CONST_WIDE_INT
:
3555 hwi
= GET_MODE_PRECISION (mode
);
3557 for (i
= 0; i
< CONST_WIDE_INT_NUNITS (x
); i
++)
3558 hwi
^= CONST_WIDE_INT_ELT (x
, i
);
3563 if (TARGET_SUPPORTS_WIDE_INT
== 0 && mode
== VOIDmode
)
3565 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3569 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3573 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3577 h
^= htab_hash_string (XSTR (x
, 0));
3581 h
= h
* 251 + CODE_LABEL_NUMBER (LABEL_REF_LABEL (x
));
3585 case UNSPEC_VOLATILE
:
3586 h
= h
* 251 + XINT (x
, 1);
3596 /* Compute a hash value for X, which should be a constant. */
3599 const_rtx_hash (rtx x
)
3602 subrtx_iterator::array_type array
;
3603 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
3604 h
= h
* 509 + const_rtx_hash_1 (*iter
);
3609 /* Create and return a new rtx constant pool. */
3611 static struct rtx_constant_pool
*
3612 create_constant_pool (void)
3614 struct rtx_constant_pool
*pool
;
3616 pool
= ggc_alloc
<rtx_constant_pool
> ();
3617 pool
->const_rtx_htab
= hash_table
<const_rtx_desc_hasher
>::create_ggc (31);
3624 /* Initialize constant pool hashing for a new function. */
3627 init_varasm_status (void)
3629 crtl
->varasm
.pool
= create_constant_pool ();
3630 crtl
->varasm
.deferred_constants
= 0;
3633 /* Given a MINUS expression, simplify it if both sides
3634 include the same symbol. */
3637 simplify_subtraction (rtx x
)
3639 rtx r
= simplify_rtx (x
);
3643 /* Given a constant rtx X, make (or find) a memory constant for its value
3644 and return a MEM rtx to refer to it in memory. */
3647 force_const_mem (machine_mode mode
, rtx x
)
3649 struct constant_descriptor_rtx
*desc
, tmp
;
3650 struct rtx_constant_pool
*pool
;
3655 constant_descriptor_rtx
**slot
;
3657 /* If we're not allowed to drop X into the constant pool, don't. */
3658 if (targetm
.cannot_force_const_mem (mode
, x
))
3661 /* Record that this function has used a constant pool entry. */
3662 crtl
->uses_const_pool
= 1;
3664 /* Decide which pool to use. */
3665 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3666 ? shared_constant_pool
3667 : crtl
->varasm
.pool
);
3669 /* Lookup the value in the hashtable. */
3672 hash
= const_rtx_hash (x
);
3673 slot
= pool
->const_rtx_htab
->find_slot_with_hash (&tmp
, hash
, INSERT
);
3676 /* If the constant was already present, return its memory. */
3678 return copy_rtx (desc
->mem
);
3680 /* Otherwise, create a new descriptor. */
3681 desc
= ggc_alloc
<constant_descriptor_rtx
> ();
3684 /* Align the location counter as required by EXP's data type. */
3685 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3687 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3688 if (type
!= NULL_TREE
)
3689 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3691 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3692 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3695 desc
->constant
= copy_rtx (tmp
.constant
);
3696 desc
->offset
= pool
->offset
;
3699 desc
->align
= align
;
3700 desc
->labelno
= const_labelno
;
3703 pool
->offset
+= GET_MODE_SIZE (mode
);
3705 pool
->last
->next
= desc
;
3707 pool
->first
= pool
->last
= desc
;
3710 /* Create a string containing the label name, in LABEL. */
3711 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3714 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3715 the constants pool. */
3716 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3718 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3719 symbol
= create_block_symbol (ggc_strdup (label
),
3720 get_block_for_section (sect
), -1);
3723 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3725 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3726 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3727 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3729 /* Construct the MEM. */
3730 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3731 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3732 set_mem_align (def
, align
);
3734 /* If we're dropping a label to the constant pool, make sure we
3736 if (GET_CODE (x
) == LABEL_REF
)
3737 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3739 return copy_rtx (def
);
3742 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3745 get_pool_constant (const_rtx addr
)
3747 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3750 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3751 and whether it has been output or not. */
3754 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3756 struct constant_descriptor_rtx
*desc
;
3758 desc
= SYMBOL_REF_CONSTANT (addr
);
3759 *pmarked
= (desc
->mark
!= 0);
3760 return desc
->constant
;
3763 /* Similar, return the mode. */
3766 get_pool_mode (const_rtx addr
)
3768 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3771 /* Return the size of the constant pool. */
3774 get_pool_size (void)
3776 return crtl
->varasm
.pool
->offset
;
3779 /* Worker function for output_constant_pool_1. Emit assembly for X
3780 in MODE with known alignment ALIGN. */
3783 output_constant_pool_2 (machine_mode mode
, rtx x
, unsigned int align
)
3785 switch (GET_MODE_CLASS (mode
))
3788 case MODE_DECIMAL_FLOAT
:
3790 gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x
));
3791 assemble_real (*CONST_DOUBLE_REAL_VALUE (x
), mode
, align
);
3796 case MODE_PARTIAL_INT
:
3801 case MODE_POINTER_BOUNDS
:
3802 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3805 case MODE_VECTOR_FLOAT
:
3806 case MODE_VECTOR_INT
:
3807 case MODE_VECTOR_FRACT
:
3808 case MODE_VECTOR_UFRACT
:
3809 case MODE_VECTOR_ACCUM
:
3810 case MODE_VECTOR_UACCUM
:
3813 machine_mode submode
= GET_MODE_INNER (mode
);
3814 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3816 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3817 units
= CONST_VECTOR_NUNITS (x
);
3819 for (i
= 0; i
< units
; i
++)
3821 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3822 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3832 /* Worker function for output_constant_pool. Emit constant DESC,
3833 giving it ALIGN bits of alignment. */
3836 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3843 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3844 whose CODE_LABEL has been deleted. This can occur if a jump table
3845 is eliminated by optimization. If so, write a constant of zero
3846 instead. Note that this can also happen by turning the
3847 CODE_LABEL into a NOTE. */
3848 /* ??? This seems completely and utterly wrong. Certainly it's
3849 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3850 functioning even with rtx_insn::deleted and friends. */
3853 switch (GET_CODE (tmp
))
3856 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3857 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3859 tmp
= XEXP (XEXP (tmp
, 0), 0);
3863 tmp
= LABEL_REF_LABEL (tmp
);
3864 gcc_assert (!as_a
<rtx_insn
*> (tmp
)->deleted ());
3865 gcc_assert (!NOTE_P (tmp
)
3866 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3873 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3874 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3875 align
, desc
->labelno
, done
);
3878 assemble_align (align
);
3880 /* Output the label. */
3881 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3884 Pass actual alignment value while emitting string constant to asm code
3885 as function 'output_constant_pool_1' explicitly passes the alignment as 1
3886 assuming that the data is already aligned which prevents the generation
3887 of fix-up table entries. */
3888 output_constant_pool_2 (desc
->mode
, x
, desc
->align
);
3890 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3891 sections have proper size. */
3892 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3894 && (in_section
->common
.flags
& SECTION_MERGE
))
3895 assemble_align (align
);
3897 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3903 /* Mark all constants that are referenced by SYMBOL_REFs in X.
3904 Emit referenced deferred strings. */
3907 mark_constants_in_pattern (rtx insn
)
3909 subrtx_iterator::array_type array
;
3910 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), ALL
)
3912 const_rtx x
= *iter
;
3913 if (GET_CODE (x
) == SYMBOL_REF
)
3915 if (CONSTANT_POOL_ADDRESS_P (x
))
3917 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3918 if (desc
->mark
== 0)
3921 iter
.substitute (desc
->constant
);
3924 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3926 tree decl
= SYMBOL_REF_DECL (x
);
3927 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
3929 n_deferred_constants
--;
3930 output_constant_def_contents (CONST_CAST_RTX (x
));
3937 /* Look through appropriate parts of INSN, marking all entries in the
3938 constant pool which are actually being used. Entries that are only
3939 referenced by other constants are also marked as used. Emit
3940 deferred strings that are used. */
3943 mark_constants (rtx_insn
*insn
)
3948 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3949 insns, not any notes that may be attached. We don't want to mark
3950 a constant just because it happens to appear in a REG_EQUIV note. */
3951 if (rtx_sequence
*seq
= dyn_cast
<rtx_sequence
*> (PATTERN (insn
)))
3953 int i
, n
= seq
->len ();
3954 for (i
= 0; i
< n
; ++i
)
3956 rtx subinsn
= seq
->element (i
);
3957 if (INSN_P (subinsn
))
3958 mark_constants_in_pattern (subinsn
);
3962 mark_constants_in_pattern (insn
);
3965 /* Look through the instructions for this function, and mark all the
3966 entries in POOL which are actually being used. Emit deferred constants
3967 which have indeed been used. */
3970 mark_constant_pool (void)
3974 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
3977 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3978 mark_constants (insn
);
3981 /* Write all the constants in POOL. */
3984 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
3986 struct constant_descriptor_rtx
*desc
;
3988 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3991 /* If the constant is part of an object_block, make sure that
3992 the constant has been positioned within its block, but do not
3993 write out its definition yet. output_object_blocks will do
3995 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
3996 && SYMBOL_REF_BLOCK (desc
->sym
))
3997 place_block_symbol (desc
->sym
);
4000 switch_to_section (targetm
.asm_out
.select_rtx_section
4001 (desc
->mode
, desc
->constant
, desc
->align
));
4002 output_constant_pool_1 (desc
, desc
->align
);
4007 /* Mark all constants that are used in the current function, then write
4008 out the function's private constant pool. */
4011 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
4012 tree fndecl ATTRIBUTE_UNUSED
)
4014 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
4016 /* It is possible for gcc to call force_const_mem and then to later
4017 discard the instructions which refer to the constant. In such a
4018 case we do not need to output the constant. */
4019 mark_constant_pool ();
4021 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4022 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4025 output_constant_pool_contents (pool
);
4027 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4028 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4032 /* Write the contents of the shared constant pool. */
4035 output_shared_constant_pool (void)
4037 output_constant_pool_contents (shared_constant_pool
);
4040 /* Determine what kind of relocations EXP may need. */
4043 compute_reloc_for_constant (tree exp
)
4045 int reloc
= 0, reloc2
;
4048 switch (TREE_CODE (exp
))
4052 /* Go inside any operations that get_inner_reference can handle and see
4053 if what's inside is a constant: no need to do anything here for
4054 addresses of variables or functions. */
4055 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4056 tem
= TREE_OPERAND (tem
, 0))
4059 if (TREE_CODE (tem
) == MEM_REF
4060 && TREE_CODE (TREE_OPERAND (tem
, 0)) == ADDR_EXPR
)
4062 reloc
= compute_reloc_for_constant (TREE_OPERAND (tem
, 0));
4066 if (!targetm
.binds_local_p (tem
))
4073 case POINTER_PLUS_EXPR
:
4074 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4075 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4079 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4080 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4081 /* The difference of two local labels is computable at link time. */
4082 if (reloc
== 1 && reloc2
== 1)
4089 case VIEW_CONVERT_EXPR
:
4090 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4095 unsigned HOST_WIDE_INT idx
;
4096 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4098 reloc
|= compute_reloc_for_constant (tem
);
4108 /* Find all the constants whose addresses are referenced inside of EXP,
4109 and make sure assembler code with a label has been output for each one.
4110 Indicate whether an ADDR_EXPR has been encountered. */
4113 output_addressed_constants (tree exp
)
4117 switch (TREE_CODE (exp
))
4121 /* Go inside any operations that get_inner_reference can handle and see
4122 if what's inside is a constant: no need to do anything here for
4123 addresses of variables or functions. */
4124 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4125 tem
= TREE_OPERAND (tem
, 0))
4128 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4129 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4130 tem
= DECL_INITIAL (tem
);
4132 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4133 output_constant_def (tem
, 0);
4135 if (TREE_CODE (tem
) == MEM_REF
)
4136 output_addressed_constants (TREE_OPERAND (tem
, 0));
4140 case POINTER_PLUS_EXPR
:
4142 output_addressed_constants (TREE_OPERAND (exp
, 1));
4146 case VIEW_CONVERT_EXPR
:
4147 output_addressed_constants (TREE_OPERAND (exp
, 0));
4152 unsigned HOST_WIDE_INT idx
;
4153 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4155 output_addressed_constants (tem
);
4164 /* Whether a constructor CTOR is a valid static constant initializer if all
4165 its elements are. This used to be internal to initializer_constant_valid_p
4166 and has been exposed to let other functions like categorize_ctor_elements
4167 evaluate the property while walking a constructor for other purposes. */
4170 constructor_static_from_elts_p (const_tree ctor
)
4172 return (TREE_CONSTANT (ctor
)
4173 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4174 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
4175 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
4178 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4181 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4182 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4183 which are valid when ENDTYPE is an integer of any size; in
4184 particular, this does not accept a pointer minus a constant. This
4185 returns null_pointer_node if the VALUE is an absolute constant
4186 which can be used to initialize a static variable. Otherwise it
4190 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4194 if (!INTEGRAL_TYPE_P (endtype
))
4197 op0
= TREE_OPERAND (value
, 0);
4198 op1
= TREE_OPERAND (value
, 1);
4200 /* Like STRIP_NOPS except allow the operand mode to widen. This
4201 works around a feature of fold that simplifies (int)(p1 - p2) to
4202 ((int)p1 - (int)p2) under the theory that the narrower operation
4205 while (CONVERT_EXPR_P (op0
)
4206 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4208 tree inner
= TREE_OPERAND (op0
, 0);
4209 if (inner
== error_mark_node
4210 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4211 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4212 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4217 while (CONVERT_EXPR_P (op1
)
4218 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4220 tree inner
= TREE_OPERAND (op1
, 0);
4221 if (inner
== error_mark_node
4222 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4223 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4224 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4229 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4233 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4234 cache
? cache
+ 2 : NULL
);
4235 /* Both initializers must be known. */
4239 && (op0
== null_pointer_node
4240 || TREE_CODE (value
) == MINUS_EXPR
))
4241 return null_pointer_node
;
4243 /* Support differences between labels. */
4244 if (TREE_CODE (op0
) == LABEL_DECL
4245 && TREE_CODE (op1
) == LABEL_DECL
)
4246 return null_pointer_node
;
4248 if (TREE_CODE (op0
) == STRING_CST
4249 && TREE_CODE (op1
) == STRING_CST
4250 && operand_equal_p (op0
, op1
, 1))
4251 return null_pointer_node
;
4257 /* Helper function of initializer_constant_valid_p.
4258 Return nonzero if VALUE is a valid constant-valued expression
4259 for use in initializing a static variable; one that can be an
4260 element of a "constant" initializer.
4262 Return null_pointer_node if the value is absolute;
4263 if it is relocatable, return the variable that determines the relocation.
4264 We assume that VALUE has been folded as much as possible;
4265 therefore, we do not need to check for such things as
4266 arithmetic-combinations of integers.
4268 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4271 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4275 switch (TREE_CODE (value
))
4278 if (constructor_static_from_elts_p (value
))
4280 unsigned HOST_WIDE_INT idx
;
4282 bool absolute
= true;
4284 if (cache
&& cache
[0] == value
)
4286 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4289 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4296 cache
[1] = NULL_TREE
;
4300 if (reloc
!= null_pointer_node
)
4303 /* For a non-absolute relocation, there is no single
4304 variable that can be "the variable that determines the
4309 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4311 return absolute
? null_pointer_node
: error_mark_node
;
4314 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4322 return null_pointer_node
;
4327 tree op0
= staticp (TREE_OPERAND (value
, 0));
4330 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4331 to be a constant, this is old-skool offsetof-like nonsense. */
4332 if (TREE_CODE (op0
) == INDIRECT_REF
4333 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4334 return null_pointer_node
;
4335 /* Taking the address of a nested function involves a trampoline,
4336 unless we don't need or want one. */
4337 if (TREE_CODE (op0
) == FUNCTION_DECL
4338 && DECL_STATIC_CHAIN (op0
)
4339 && !TREE_NO_TRAMPOLINE (value
))
4341 /* "&{...}" requires a temporary to hold the constructed
4343 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4349 case NON_LVALUE_EXPR
:
4350 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4353 case VIEW_CONVERT_EXPR
:
4355 tree src
= TREE_OPERAND (value
, 0);
4356 tree src_type
= TREE_TYPE (src
);
4357 tree dest_type
= TREE_TYPE (value
);
4359 /* Allow view-conversions from aggregate to non-aggregate type only
4360 if the bit pattern is fully preserved afterwards; otherwise, the
4361 RTL expander won't be able to apply a subsequent transformation
4362 to the underlying constructor. */
4363 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4365 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4366 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4371 /* Allow all other kinds of view-conversion. */
4372 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4377 tree src
= TREE_OPERAND (value
, 0);
4378 tree src_type
= TREE_TYPE (src
);
4379 tree dest_type
= TREE_TYPE (value
);
4381 /* Allow conversions between pointer types, floating-point
4382 types, and offset types. */
4383 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4384 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4385 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4386 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4387 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4389 /* Allow length-preserving conversions between integer types. */
4390 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4391 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4392 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4394 /* Allow conversions between other integer types only if
4396 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4398 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4399 if (inner
== null_pointer_node
)
4400 return null_pointer_node
;
4404 /* Allow (int) &foo provided int is as wide as a pointer. */
4405 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4406 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4407 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4409 /* Likewise conversions from int to pointers, but also allow
4410 conversions from 0. */
4411 if ((POINTER_TYPE_P (dest_type
)
4412 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4413 && INTEGRAL_TYPE_P (src_type
))
4415 if (TREE_CODE (src
) == INTEGER_CST
4416 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4417 return null_pointer_node
;
4418 if (integer_zerop (src
))
4419 return null_pointer_node
;
4420 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4421 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4424 /* Allow conversions to struct or union types if the value
4426 if (TREE_CODE (dest_type
) == RECORD_TYPE
4427 || TREE_CODE (dest_type
) == UNION_TYPE
)
4428 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4432 case POINTER_PLUS_EXPR
:
4434 /* Any valid floating-point constants will have been folded by now;
4435 with -frounding-math we hit this with addition of two constants. */
4436 if (TREE_CODE (endtype
) == REAL_TYPE
)
4438 if (cache
&& cache
[0] == value
)
4440 if (! INTEGRAL_TYPE_P (endtype
)
4441 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4443 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4445 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4448 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4449 endtype
, ncache
+ 2);
4450 /* If either term is absolute, use the other term's relocation. */
4451 if (valid0
== null_pointer_node
)
4453 else if (valid1
== null_pointer_node
)
4455 /* Support narrowing pointer differences. */
4457 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4461 /* Support narrowing pointer differences. */
4462 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4471 if (TREE_CODE (endtype
) == REAL_TYPE
)
4473 if (cache
&& cache
[0] == value
)
4475 if (! INTEGRAL_TYPE_P (endtype
)
4476 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4478 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4480 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4483 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4484 endtype
, ncache
+ 2);
4485 /* Win if second argument is absolute. */
4486 if (valid1
== null_pointer_node
)
4488 /* Win if both arguments have the same relocation.
4489 Then the value is absolute. */
4490 else if (valid0
== valid1
&& valid0
!= 0)
4491 ret
= null_pointer_node
;
4492 /* Since GCC guarantees that string constants are unique in the
4493 generated code, a subtraction between two copies of the same
4494 constant string is absolute. */
4495 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4496 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4497 && operand_equal_p (valid0
, valid1
, 1))
4498 ret
= null_pointer_node
;
4499 /* Support narrowing differences. */
4501 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4505 /* Support narrowing differences. */
4506 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4521 /* Return nonzero if VALUE is a valid constant-valued expression
4522 for use in initializing a static variable; one that can be an
4523 element of a "constant" initializer.
4525 Return null_pointer_node if the value is absolute;
4526 if it is relocatable, return the variable that determines the relocation.
4527 We assume that VALUE has been folded as much as possible;
4528 therefore, we do not need to check for such things as
4529 arithmetic-combinations of integers. */
4531 initializer_constant_valid_p (tree value
, tree endtype
)
4533 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4536 /* Return true if VALUE is a valid constant-valued expression
4537 for use in initializing a static bit-field; one that can be
4538 an element of a "constant" initializer. */
4541 initializer_constant_valid_for_bitfield_p (tree value
)
4543 /* For bitfields we support integer constants or possibly nested aggregates
4545 switch (TREE_CODE (value
))
4549 unsigned HOST_WIDE_INT idx
;
4552 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4553 if (!initializer_constant_valid_for_bitfield_p (elt
))
4562 case VIEW_CONVERT_EXPR
:
4563 case NON_LVALUE_EXPR
:
4565 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4574 /* output_constructor outer state of relevance in recursive calls, typically
4575 for nested aggregate bitfields. */
4577 struct oc_outer_state
{
4578 unsigned int bit_offset
; /* current position in ... */
4579 int byte
; /* ... the outer byte buffer. */
4582 static unsigned HOST_WIDE_INT
4583 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4586 /* Output assembler code for constant EXP, with no label.
4587 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4588 Assumes output_addressed_constants has been done on EXP already.
4590 Generate at least SIZE bytes of assembler data, padding at the end
4591 with zeros if necessary. SIZE must always be specified. The returned
4592 value is the actual number of bytes of assembler data generated, which
4593 may be bigger than SIZE if the object contains a variable length field.
4595 SIZE is important for structure constructors,
4596 since trailing members may have been omitted from the constructor.
4597 It is also important for initialization of arrays from string constants
4598 since the full length of the string constant might not be wanted.
4599 It is also needed for initialization of unions, where the initializer's
4600 type is just one member, and that may not be as long as the union.
4602 There a case in which we would fail to output exactly SIZE bytes:
4603 for a structure constructor that wants to produce more than SIZE bytes.
4604 But such constructors will never be generated for any possible input.
4606 ALIGN is the alignment of the data in bits. */
4608 static unsigned HOST_WIDE_INT
4609 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4611 enum tree_code code
;
4612 unsigned HOST_WIDE_INT thissize
;
4614 if (size
== 0 || flag_syntax_only
)
4617 /* See if we're trying to initialize a pointer in a non-default mode
4618 to the address of some declaration somewhere. If the target says
4619 the mode is valid for pointers, assume the target has a way of
4621 if (TREE_CODE (exp
) == NOP_EXPR
4622 && POINTER_TYPE_P (TREE_TYPE (exp
))
4623 && targetm
.addr_space
.valid_pointer_mode
4624 (TYPE_MODE (TREE_TYPE (exp
)),
4625 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4627 tree saved_type
= TREE_TYPE (exp
);
4629 /* Peel off any intermediate conversions-to-pointer for valid
4631 while (TREE_CODE (exp
) == NOP_EXPR
4632 && POINTER_TYPE_P (TREE_TYPE (exp
))
4633 && targetm
.addr_space
.valid_pointer_mode
4634 (TYPE_MODE (TREE_TYPE (exp
)),
4635 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4636 exp
= TREE_OPERAND (exp
, 0);
4638 /* If what we're left with is the address of something, we can
4639 convert the address to the final type and output it that
4641 if (TREE_CODE (exp
) == ADDR_EXPR
)
4642 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4643 /* Likewise for constant ints. */
4644 else if (TREE_CODE (exp
) == INTEGER_CST
)
4645 exp
= fold_convert (saved_type
, exp
);
4649 /* Eliminate any conversions since we'll be outputting the underlying
4651 while (CONVERT_EXPR_P (exp
)
4652 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4653 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4655 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4656 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4658 /* Make sure eliminating the conversion is really a no-op, except with
4659 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4660 union types to allow for Ada unchecked unions. */
4661 if (type_size
> op_size
4662 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4663 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4664 /* Keep the conversion. */
4667 exp
= TREE_OPERAND (exp
, 0);
4670 code
= TREE_CODE (TREE_TYPE (exp
));
4671 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4673 /* Allow a constructor with no elements for any data type.
4674 This means to fill the space with zeros. */
4675 if (TREE_CODE (exp
) == CONSTRUCTOR
4676 && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp
)))
4678 assemble_zeros (size
);
4682 if (TREE_CODE (exp
) == FDESC_EXPR
)
4684 #ifdef ASM_OUTPUT_FDESC
4685 HOST_WIDE_INT part
= tree_to_shwi (TREE_OPERAND (exp
, 1));
4686 tree decl
= TREE_OPERAND (exp
, 0);
4687 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4694 /* Now output the underlying data. If we've handling the padding, return.
4695 Otherwise, break and ensure SIZE is the size written. */
4702 case REFERENCE_TYPE
:
4704 case FIXED_POINT_TYPE
:
4705 case POINTER_BOUNDS_TYPE
:
4707 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4708 EXPAND_INITIALIZER
),
4709 MIN (size
, thissize
), align
, 0))
4710 error ("initializer for integer/fixed-point value is too complicated");
4714 if (TREE_CODE (exp
) != REAL_CST
)
4715 error ("initializer for floating value is not a floating constant");
4717 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4721 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4722 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4723 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4728 switch (TREE_CODE (exp
))
4731 return output_constructor (exp
, size
, align
, NULL
);
4734 = MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
), size
);
4735 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4739 machine_mode inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4740 unsigned int nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4741 int elt_size
= GET_MODE_SIZE (inner
);
4742 output_constant (VECTOR_CST_ELT (exp
, 0), elt_size
, align
);
4743 thissize
= elt_size
;
4744 for (unsigned int i
= 1; i
< VECTOR_CST_NELTS (exp
); i
++)
4746 output_constant (VECTOR_CST_ELT (exp
, i
), elt_size
, nalign
);
4747 thissize
+= elt_size
;
4758 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4759 return output_constructor (exp
, size
, align
, NULL
);
4768 if (size
> thissize
)
4769 assemble_zeros (size
- thissize
);
4775 /* Subroutine of output_constructor, used for computing the size of
4776 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4777 type with an unspecified upper bound. */
4779 static unsigned HOST_WIDE_INT
4780 array_size_for_constructor (tree val
)
4783 unsigned HOST_WIDE_INT cnt
;
4784 tree index
, value
, tmp
;
4787 /* This code used to attempt to handle string constants that are not
4788 arrays of single-bytes, but nothing else does, so there's no point in
4790 if (TREE_CODE (val
) == STRING_CST
)
4791 return TREE_STRING_LENGTH (val
);
4793 max_index
= NULL_TREE
;
4794 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4796 if (TREE_CODE (index
) == RANGE_EXPR
)
4797 index
= TREE_OPERAND (index
, 1);
4798 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4802 if (max_index
== NULL_TREE
)
4805 /* Compute the total number of array elements. */
4806 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4807 i
= wi::to_offset (max_index
) - wi::to_offset (tmp
) + 1;
4809 /* Multiply by the array element unit size to find number of bytes. */
4810 i
*= wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4812 gcc_assert (wi::fits_uhwi_p (i
));
4813 return i
.to_uhwi ();
4816 /* Other datastructures + helpers for output_constructor. */
4818 /* output_constructor local state to support interaction with helpers. */
4820 struct oc_local_state
{
4822 /* Received arguments. */
4823 tree exp
; /* Constructor expression. */
4824 tree type
; /* Type of constructor expression. */
4825 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4826 unsigned int align
; /* Known initial alignment. */
4827 tree min_index
; /* Lower bound if specified for an array. */
4829 /* Output processing state. */
4830 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4831 int byte
; /* Part of a bitfield byte yet to be output. */
4832 int last_relative_index
; /* Implicit or explicit index of the last
4833 array element output within a bitfield. */
4834 bool byte_buffer_in_use
; /* Whether BYTE is in use. */
4836 /* Current element. */
4837 tree field
; /* Current field decl in a record. */
4838 tree val
; /* Current element value. */
4839 tree index
; /* Current element index. */
4843 /* Helper for output_constructor. From the current LOCAL state, output a
4844 RANGE_EXPR element. */
4847 output_constructor_array_range (oc_local_state
*local
)
4849 unsigned HOST_WIDE_INT fieldsize
4850 = int_size_in_bytes (TREE_TYPE (local
->type
));
4852 HOST_WIDE_INT lo_index
4853 = tree_to_shwi (TREE_OPERAND (local
->index
, 0));
4854 HOST_WIDE_INT hi_index
4855 = tree_to_shwi (TREE_OPERAND (local
->index
, 1));
4856 HOST_WIDE_INT index
;
4859 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4861 for (index
= lo_index
; index
<= hi_index
; index
++)
4863 /* Output the element's initial value. */
4864 if (local
->val
== NULL_TREE
)
4865 assemble_zeros (fieldsize
);
4867 fieldsize
= output_constant (local
->val
, fieldsize
, align2
);
4869 /* Count its size. */
4870 local
->total_bytes
+= fieldsize
;
4874 /* Helper for output_constructor. From the current LOCAL state, output a
4875 field element that is not true bitfield or part of an outer one. */
4878 output_constructor_regular_field (oc_local_state
*local
)
4880 /* Field size and position. Since this structure is static, we know the
4881 positions are constant. */
4882 unsigned HOST_WIDE_INT fieldsize
;
4883 HOST_WIDE_INT fieldpos
;
4885 unsigned int align2
;
4887 if (local
->index
!= NULL_TREE
)
4889 /* Perform the index calculation in modulo arithmetic but
4890 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
4891 but we are using an unsigned sizetype. */
4892 unsigned prec
= TYPE_PRECISION (sizetype
);
4893 offset_int idx
= wi::sext (wi::to_offset (local
->index
)
4894 - wi::to_offset (local
->min_index
), prec
);
4895 fieldpos
= (idx
* wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
))))
4898 else if (local
->field
!= NULL_TREE
)
4899 fieldpos
= int_byte_position (local
->field
);
4903 /* Output any buffered-up bit-fields preceding this element. */
4904 if (local
->byte_buffer_in_use
)
4906 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4907 local
->total_bytes
++;
4908 local
->byte_buffer_in_use
= false;
4911 /* Advance to offset of this element.
4912 Note no alignment needed in an array, since that is guaranteed
4913 if each element has the proper size. */
4914 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4915 && fieldpos
> local
->total_bytes
)
4917 assemble_zeros (fieldpos
- local
->total_bytes
);
4918 local
->total_bytes
= fieldpos
;
4921 /* Find the alignment of this element. */
4922 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
4924 /* Determine size this element should occupy. */
4929 /* If this is an array with an unspecified upper bound,
4930 the initializer determines the size. */
4931 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4932 but we cannot do this until the deprecated support for
4933 initializing zero-length array members is removed. */
4934 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
4935 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
4936 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
4938 fieldsize
= array_size_for_constructor (local
->val
);
4939 /* Given a non-empty initialization, this field had
4941 gcc_assert (!fieldsize
|| !DECL_CHAIN (local
->field
));
4944 fieldsize
= tree_to_uhwi (DECL_SIZE_UNIT (local
->field
));
4947 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
4949 /* Output the element's initial value. */
4950 if (local
->val
== NULL_TREE
)
4951 assemble_zeros (fieldsize
);
4953 fieldsize
= output_constant (local
->val
, fieldsize
, align2
);
4955 /* Count its size. */
4956 local
->total_bytes
+= fieldsize
;
4959 /* Helper for output_constructor. From the LOCAL state, output an element
4960 that is a true bitfield or part of an outer one. BIT_OFFSET is the offset
4961 from the start of a possibly ongoing outer byte buffer. */
4964 output_constructor_bitfield (oc_local_state
*local
, unsigned int bit_offset
)
4966 /* Bit size of this element. */
4967 HOST_WIDE_INT ebitsize
4969 ? tree_to_uhwi (DECL_SIZE (local
->field
))
4970 : tree_to_uhwi (TYPE_SIZE (TREE_TYPE (local
->type
))));
4972 /* Relative index of this element if this is an array component. */
4973 HOST_WIDE_INT relative_index
4976 ? (tree_to_shwi (local
->index
)
4977 - tree_to_shwi (local
->min_index
))
4978 : local
->last_relative_index
+ 1)
4981 /* Bit position of this element from the start of the containing
4983 HOST_WIDE_INT constructor_relative_ebitpos
4985 ? int_bit_position (local
->field
)
4986 : ebitsize
* relative_index
);
4988 /* Bit position of this element from the start of a possibly ongoing
4989 outer byte buffer. */
4990 HOST_WIDE_INT byte_relative_ebitpos
4991 = bit_offset
+ constructor_relative_ebitpos
;
4993 /* From the start of a possibly ongoing outer byte buffer, offsets to
4994 the first bit of this element and to the first bit past the end of
4996 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
4997 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
4999 local
->last_relative_index
= relative_index
;
5001 if (local
->val
== NULL_TREE
)
5002 local
->val
= integer_zero_node
;
5004 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
5005 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
5006 local
->val
= TREE_OPERAND (local
->val
, 0);
5008 if (TREE_CODE (local
->val
) != INTEGER_CST
5009 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
5011 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
5015 /* If this field does not start in this (or next) byte, skip some bytes. */
5016 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5018 /* Output remnant of any bit field in previous bytes. */
5019 if (local
->byte_buffer_in_use
)
5021 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5022 local
->total_bytes
++;
5023 local
->byte_buffer_in_use
= false;
5026 /* If still not at proper byte, advance to there. */
5027 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5029 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
5030 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
5031 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
5035 /* Set up the buffer if necessary. */
5036 if (!local
->byte_buffer_in_use
)
5040 local
->byte_buffer_in_use
= true;
5043 /* If this is nested constructor, recurse passing the bit offset and the
5044 pending data, then retrieve the new pending data afterwards. */
5045 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
5047 oc_outer_state temp_state
;
5048 temp_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
5049 temp_state
.byte
= local
->byte
;
5051 += output_constructor (local
->val
, 0, 0, &temp_state
);
5052 local
->byte
= temp_state
.byte
;
5056 /* Otherwise, we must split the element into pieces that fall within
5057 separate bytes, and combine each byte with previous or following
5059 while (next_offset
< end_offset
)
5063 HOST_WIDE_INT value
;
5064 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5065 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5067 /* Advance from byte to byte within this element when necessary. */
5068 while (next_byte
!= local
->total_bytes
)
5070 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5071 local
->total_bytes
++;
5075 /* Number of bits we can process at once (all part of the same byte). */
5076 this_time
= MIN (end_offset
- next_offset
, BITS_PER_UNIT
- next_bit
);
5077 if (BYTES_BIG_ENDIAN
)
5079 /* On big-endian machine, take the most significant bits (of the
5080 bits that are significant) first and put them into bytes from
5081 the most significant end. */
5082 shift
= end_offset
- next_offset
- this_time
;
5084 /* Don't try to take a bunch of bits that cross
5085 the word boundary in the INTEGER_CST. We can
5086 only select bits from one element. */
5087 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5088 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5090 const int end
= shift
+ this_time
- 1;
5091 shift
= end
& -HOST_BITS_PER_WIDE_INT
;
5092 this_time
= end
- shift
+ 1;
5095 /* Now get the bits from the appropriate constant word. */
5096 value
= TREE_INT_CST_ELT (local
->val
, shift
/ HOST_BITS_PER_WIDE_INT
);
5097 shift
= shift
& (HOST_BITS_PER_WIDE_INT
- 1);
5099 /* Get the result. This works only when:
5100 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5101 local
->byte
|= (((value
>> shift
)
5102 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5103 << (BITS_PER_UNIT
- this_time
- next_bit
));
5107 /* On little-endian machines, take the least significant bits of
5108 the value first and pack them starting at the least significant
5109 bits of the bytes. */
5110 shift
= next_offset
- byte_relative_ebitpos
;
5112 /* Don't try to take a bunch of bits that cross
5113 the word boundary in the INTEGER_CST. We can
5114 only select bits from one element. */
5115 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5116 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5118 = HOST_BITS_PER_WIDE_INT
- (shift
& (HOST_BITS_PER_WIDE_INT
- 1));
5120 /* Now get the bits from the appropriate constant word. */
5121 value
= TREE_INT_CST_ELT (local
->val
, shift
/ HOST_BITS_PER_WIDE_INT
);
5122 shift
= shift
& (HOST_BITS_PER_WIDE_INT
- 1);
5124 /* Get the result. This works only when:
5125 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5126 local
->byte
|= (((value
>> shift
)
5127 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5131 next_offset
+= this_time
;
5132 local
->byte_buffer_in_use
= true;
5136 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5137 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5138 caller output state of relevance in recursive invocations. */
5140 static unsigned HOST_WIDE_INT
5141 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5142 unsigned int align
, oc_outer_state
*outer
)
5144 unsigned HOST_WIDE_INT cnt
;
5145 constructor_elt
*ce
;
5147 oc_local_state local
;
5149 /* Setup our local state to communicate with helpers. */
5151 local
.type
= TREE_TYPE (exp
);
5153 local
.align
= align
;
5154 if (TREE_CODE (local
.type
) == ARRAY_TYPE
&& TYPE_DOMAIN (local
.type
))
5155 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5157 local
.min_index
= NULL_TREE
;
5159 local
.total_bytes
= 0;
5160 local
.byte_buffer_in_use
= outer
!= NULL
;
5161 local
.byte
= outer
? outer
->byte
: 0;
5162 local
.last_relative_index
= -1;
5164 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5166 /* As CE goes through the elements of the constant, FIELD goes through the
5167 structure fields if the constant is a structure. If the constant is a
5168 union, we override this by getting the field from the TREE_LIST element.
5169 But the constant could also be an array. Then FIELD is zero.
5171 There is always a maximum of one element in the chain LINK for unions
5172 (even if the initializer in a source program incorrectly contains
5175 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5176 local
.field
= TYPE_FIELDS (local
.type
);
5178 local
.field
= NULL_TREE
;
5181 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), cnt
, &ce
);
5182 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
5184 local
.val
= ce
->value
;
5185 local
.index
= NULL_TREE
;
5187 /* The element in a union constructor specifies the proper field
5189 if (RECORD_OR_UNION_TYPE_P (local
.type
) && ce
->index
!= NULL_TREE
)
5190 local
.field
= ce
->index
;
5192 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5193 local
.index
= ce
->index
;
5195 if (local
.field
&& flag_verbose_asm
)
5196 fprintf (asm_out_file
, "%s %s:\n",
5198 DECL_NAME (local
.field
)
5199 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5202 /* Eliminate the marker that makes a cast not be an lvalue. */
5203 if (local
.val
!= NULL_TREE
)
5204 STRIP_NOPS (local
.val
);
5206 /* Output the current element, using the appropriate helper ... */
5208 /* For an array slice not part of an outer bitfield. */
5210 && local
.index
!= NULL_TREE
5211 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5212 output_constructor_array_range (&local
);
5214 /* For a field that is neither a true bitfield nor part of an outer one,
5215 known to be at least byte aligned and multiple-of-bytes long. */
5217 && (local
.field
== NULL_TREE
5218 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5219 output_constructor_regular_field (&local
);
5221 /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
5222 supported for scalar fields, so we may need to convert first. */
5225 if (TREE_CODE (local
.val
) == REAL_CST
)
5227 = fold_unary (VIEW_CONVERT_EXPR
,
5228 build_nonstandard_integer_type
5229 (TYPE_PRECISION (TREE_TYPE (local
.val
)), 0),
5231 output_constructor_bitfield (&local
, outer
? outer
->bit_offset
: 0);
5235 /* If we are not at toplevel, save the pending data for our caller.
5236 Otherwise output the pending data and padding zeros as needed. */
5238 outer
->byte
= local
.byte
;
5241 if (local
.byte_buffer_in_use
)
5243 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5244 local
.total_bytes
++;
5247 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5249 assemble_zeros (local
.size
- local
.total_bytes
);
5250 local
.total_bytes
= local
.size
;
5254 return local
.total_bytes
;
5257 /* Mark DECL as weak. */
5260 mark_weak (tree decl
)
5262 if (DECL_WEAK (decl
))
5265 struct symtab_node
*n
= symtab_node::get (decl
);
5266 if (n
&& n
->refuse_visibility_changes
)
5267 error ("%+D declared weak after being used", decl
);
5268 DECL_WEAK (decl
) = 1;
5270 if (DECL_RTL_SET_P (decl
)
5271 && MEM_P (DECL_RTL (decl
))
5272 && XEXP (DECL_RTL (decl
), 0)
5273 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5274 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5277 /* Merge weak status between NEWDECL and OLDDECL. */
5280 merge_weak (tree newdecl
, tree olddecl
)
5282 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5284 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5287 /* We put the NEWDECL on the weak_decls list at some point
5288 and OLDDECL as well. Keep just OLDDECL on the list. */
5289 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5290 if (TREE_VALUE (*pwd
) == newdecl
)
5292 *pwd
= TREE_CHAIN (*pwd
);
5299 if (DECL_WEAK (newdecl
))
5303 /* NEWDECL is weak, but OLDDECL is not. */
5305 /* If we already output the OLDDECL, we're in trouble; we can't
5306 go back and make it weak. This should never happen in
5307 unit-at-a-time compilation. */
5308 gcc_assert (!TREE_ASM_WRITTEN (olddecl
));
5310 /* If we've already generated rtl referencing OLDDECL, we may
5311 have done so in a way that will not function properly with
5312 a weak symbol. Again in unit-at-a-time this should be
5314 gcc_assert (!TREE_USED (olddecl
)
5315 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)));
5317 if (TARGET_SUPPORTS_WEAK
)
5319 /* We put the NEWDECL on the weak_decls list at some point.
5320 Replace it with the OLDDECL. */
5321 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5322 if (TREE_VALUE (wd
) == newdecl
)
5324 TREE_VALUE (wd
) = olddecl
;
5327 /* We may not find the entry on the list. If NEWDECL is a
5328 weak alias, then we will have already called
5329 globalize_decl to remove the entry; in that case, we do
5330 not need to do anything. */
5333 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5334 mark_weak (olddecl
);
5337 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5338 weak. Just update NEWDECL to indicate that it's weak too. */
5339 mark_weak (newdecl
);
5342 /* Declare DECL to be a weak symbol. */
5345 declare_weak (tree decl
)
5347 gcc_assert (TREE_CODE (decl
) != FUNCTION_DECL
|| !TREE_ASM_WRITTEN (decl
));
5348 if (! TREE_PUBLIC (decl
))
5350 error ("weak declaration of %q+D must be public", decl
);
5353 else if (!TARGET_SUPPORTS_WEAK
)
5354 warning (0, "weak declaration of %q+D not supported", decl
);
5357 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5358 DECL_ATTRIBUTES (decl
)
5359 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5363 weak_finish_1 (tree decl
)
5365 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5366 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5369 if (! TREE_USED (decl
))
5372 #ifdef ASM_WEAKEN_DECL
5373 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5375 #ifdef ASM_WEAKEN_LABEL
5376 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5378 #ifdef ASM_OUTPUT_WEAK_ALIAS
5380 static bool warn_once
= 0;
5383 warning (0, "only weak aliases are supported in this configuration");
5393 /* Fiven an assembly name, find the decl it is associated with. */
5395 find_decl (tree target
)
5397 symtab_node
*node
= symtab_node::get_for_asmname (target
);
5403 /* This TREE_LIST contains weakref targets. */
5405 static GTY(()) tree weakref_targets
;
5407 /* Emit any pending weak declarations. */
5414 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5416 tree alias_decl
= TREE_PURPOSE (t
);
5417 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5419 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5420 /* Remove alias_decl from the weak list, but leave entries for
5421 the target alone. */
5423 #ifndef ASM_OUTPUT_WEAKREF
5424 else if (! TREE_SYMBOL_REFERENCED (target
))
5426 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5427 defined, otherwise we and weak_finish_1 would use
5428 different macros. */
5429 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5430 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5432 tree decl
= find_decl (target
);
5436 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5437 TREE_CODE (alias_decl
), target
,
5438 TREE_TYPE (alias_decl
));
5440 DECL_EXTERNAL (decl
) = 1;
5441 TREE_PUBLIC (decl
) = 1;
5442 DECL_ARTIFICIAL (decl
) = 1;
5443 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5444 TREE_USED (decl
) = 1;
5447 weak_finish_1 (decl
);
5456 /* Remove the alias and the target from the pending weak list
5457 so that we do not emit any .weak directives for the former,
5458 nor multiple .weak directives for the latter. */
5459 for (p
= &weak_decls
; (t2
= *p
) ; )
5461 if (TREE_VALUE (t2
) == alias_decl
5462 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5463 *p
= TREE_CHAIN (t2
);
5465 p
= &TREE_CHAIN (t2
);
5468 /* Remove other weakrefs to the same target, to speed things up. */
5469 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5471 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5472 *p
= TREE_CHAIN (t2
);
5474 p
= &TREE_CHAIN (t2
);
5479 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5481 tree decl
= TREE_VALUE (t
);
5483 weak_finish_1 (decl
);
5487 /* Emit the assembly bits to indicate that DECL is globally visible. */
5490 globalize_decl (tree decl
)
5493 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5494 if (DECL_WEAK (decl
))
5496 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5499 #ifdef ASM_WEAKEN_DECL
5500 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5502 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5505 /* Remove this function from the pending weak list so that
5506 we do not emit multiple .weak directives for it. */
5507 for (p
= &weak_decls
; (t
= *p
) ; )
5509 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5510 *p
= TREE_CHAIN (t
);
5512 p
= &TREE_CHAIN (t
);
5515 /* Remove weakrefs to the same target from the pending weakref
5516 list, for the same reason. */
5517 for (p
= &weakref_targets
; (t
= *p
) ; )
5519 if (DECL_ASSEMBLER_NAME (decl
)
5520 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5521 *p
= TREE_CHAIN (t
);
5523 p
= &TREE_CHAIN (t
);
5530 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5533 vec
<alias_pair
, va_gc
> *alias_pairs
;
5535 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5536 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5537 tree node is DECL to have the value of the tree node TARGET. */
5540 do_assemble_alias (tree decl
, tree target
)
5544 /* Emulated TLS had better not get this var. */
5545 gcc_assert (!(!targetm
.have_tls
5546 && TREE_CODE (decl
) == VAR_DECL
5547 && DECL_THREAD_LOCAL_P (decl
)));
5549 if (TREE_ASM_WRITTEN (decl
))
5552 id
= DECL_ASSEMBLER_NAME (decl
);
5553 ultimate_transparent_alias_target (&id
);
5554 ultimate_transparent_alias_target (&target
);
5556 /* We must force creation of DECL_RTL for debug info generation, even though
5557 we don't use it here. */
5558 make_decl_rtl (decl
);
5560 TREE_ASM_WRITTEN (decl
) = 1;
5561 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5562 TREE_ASM_WRITTEN (id
) = 1;
5564 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5566 if (!TREE_SYMBOL_REFERENCED (target
))
5567 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5569 #ifdef ASM_OUTPUT_WEAKREF
5570 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5571 IDENTIFIER_POINTER (id
),
5572 IDENTIFIER_POINTER (target
));
5574 if (!TARGET_SUPPORTS_WEAK
)
5576 error_at (DECL_SOURCE_LOCATION (decl
),
5577 "weakref is not supported in this configuration");
5584 #ifdef ASM_OUTPUT_DEF
5585 tree orig_decl
= decl
;
5587 if (TREE_CODE (decl
) == FUNCTION_DECL
5588 && cgraph_node::get (decl
)->instrumentation_clone
5589 && cgraph_node::get (decl
)->instrumented_version
)
5590 orig_decl
= cgraph_node::get (decl
)->instrumented_version
->decl
;
5592 /* Make name accessible from other files, if appropriate. */
5594 if (TREE_PUBLIC (decl
) || TREE_PUBLIC (orig_decl
))
5596 globalize_decl (decl
);
5597 maybe_assemble_visibility (decl
);
5599 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5601 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
5602 if (targetm
.has_ifunc_p ())
5603 ASM_OUTPUT_TYPE_DIRECTIVE
5604 (asm_out_file
, IDENTIFIER_POINTER (id
),
5608 error_at (DECL_SOURCE_LOCATION (decl
),
5609 "ifunc is not supported on this target");
5612 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5613 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5615 ASM_OUTPUT_DEF (asm_out_file
,
5616 IDENTIFIER_POINTER (id
),
5617 IDENTIFIER_POINTER (target
));
5619 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5624 name
= IDENTIFIER_POINTER (id
);
5625 # ifdef ASM_WEAKEN_DECL
5626 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5628 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5630 /* Remove this function from the pending weak list so that
5631 we do not emit multiple .weak directives for it. */
5632 for (p
= &weak_decls
; (t
= *p
) ; )
5633 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
))
5634 || id
== DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5635 *p
= TREE_CHAIN (t
);
5637 p
= &TREE_CHAIN (t
);
5639 /* Remove weakrefs to the same target from the pending weakref
5640 list, for the same reason. */
5641 for (p
= &weakref_targets
; (t
= *p
) ; )
5643 if (id
== ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5644 *p
= TREE_CHAIN (t
);
5646 p
= &TREE_CHAIN (t
);
5652 /* Emit an assembler directive to make the symbol for DECL an alias to
5653 the symbol for TARGET. */
5656 assemble_alias (tree decl
, tree target
)
5660 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5662 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5664 ultimate_transparent_alias_target (&target
);
5666 if (alias
== target
)
5667 error ("weakref %q+D ultimately targets itself", decl
);
5668 if (TREE_PUBLIC (decl
))
5669 error ("weakref %q+D must have static linkage", decl
);
5673 #if !defined (ASM_OUTPUT_DEF)
5674 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5675 error_at (DECL_SOURCE_LOCATION (decl
),
5676 "alias definitions not supported in this configuration");
5677 TREE_ASM_WRITTEN (decl
) = 1;
5680 if (!DECL_WEAK (decl
))
5682 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5683 error_at (DECL_SOURCE_LOCATION (decl
),
5684 "ifunc is not supported in this configuration");
5686 error_at (DECL_SOURCE_LOCATION (decl
),
5687 "only weak aliases are supported in this configuration");
5688 TREE_ASM_WRITTEN (decl
) = 1;
5694 TREE_USED (decl
) = 1;
5696 /* Allow aliases to aliases. */
5697 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5698 cgraph_node::get_create (decl
)->alias
= true;
5700 varpool_node::get_create (decl
)->alias
= true;
5702 /* If the target has already been emitted, we don't have to queue the
5703 alias. This saves a tad of memory. */
5704 if (symtab
->global_info_ready
)
5705 target_decl
= find_decl (target
);
5708 if ((target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5709 || symtab
->state
>= EXPANSION
)
5710 do_assemble_alias (decl
, target
);
5713 alias_pair p
= {decl
, target
};
5714 vec_safe_push (alias_pairs
, p
);
5718 /* Record and output a table of translations from original function
5719 to its transaction aware clone. Note that tm_pure functions are
5720 considered to be their own clone. */
5722 struct tm_clone_hasher
: ggc_cache_ptr_hash
<tree_map
>
5724 static hashval_t
hash (tree_map
*m
) { return tree_map_hash (m
); }
5725 static bool equal (tree_map
*a
, tree_map
*b
) { return tree_map_eq (a
, b
); }
5728 keep_cache_entry (tree_map
*&e
)
5730 return ggc_marked_p (e
->base
.from
);
5734 static GTY((cache
)) hash_table
<tm_clone_hasher
> *tm_clone_hash
;
5737 record_tm_clone_pair (tree o
, tree n
)
5739 struct tree_map
**slot
, *h
;
5741 if (tm_clone_hash
== NULL
)
5742 tm_clone_hash
= hash_table
<tm_clone_hasher
>::create_ggc (32);
5744 h
= ggc_alloc
<tree_map
> ();
5745 h
->hash
= htab_hash_pointer (o
);
5749 slot
= tm_clone_hash
->find_slot_with_hash (h
, h
->hash
, INSERT
);
5754 get_tm_clone_pair (tree o
)
5758 struct tree_map
*h
, in
;
5761 in
.hash
= htab_hash_pointer (o
);
5762 h
= tm_clone_hash
->find_with_hash (&in
, in
.hash
);
5769 struct tm_alias_pair
5777 /* Dump the actual pairs to the .tm_clone_table section. */
5780 dump_tm_clone_pairs (vec
<tm_alias_pair
> tm_alias_pairs
)
5784 bool switched
= false;
5786 FOR_EACH_VEC_ELT (tm_alias_pairs
, i
, p
)
5790 struct cgraph_node
*src_n
= cgraph_node::get (src
);
5791 struct cgraph_node
*dst_n
= cgraph_node::get (dst
);
5793 /* The function ipa_tm_create_version() marks the clone as needed if
5794 the original function was needed. But we also mark the clone as
5795 needed if we ever called the clone indirectly through
5796 TM_GETTMCLONE. If neither of these are true, we didn't generate
5797 a clone, and we didn't call it indirectly... no sense keeping it
5798 in the clone table. */
5799 if (!dst_n
|| !dst_n
->definition
)
5802 /* This covers the case where we have optimized the original
5803 function away, and only access the transactional clone. */
5804 if (!src_n
|| !src_n
->definition
)
5809 switch_to_section (targetm
.asm_out
.tm_clone_table_section ());
5810 assemble_align (POINTER_SIZE
);
5814 assemble_integer (XEXP (DECL_RTL (src
), 0),
5815 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
5816 assemble_integer (XEXP (DECL_RTL (dst
), 0),
5817 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
5821 /* Provide a default for the tm_clone_table section. */
5824 default_clone_table_section (void)
5826 return get_named_section (NULL
, ".tm_clone_table", 3);
5829 /* Helper comparison function for qsorting by the DECL_UID stored in
5830 alias_pair->emitted_diags. */
5833 tm_alias_pair_cmp (const void *x
, const void *y
)
5835 const tm_alias_pair
*p1
= (const tm_alias_pair
*) x
;
5836 const tm_alias_pair
*p2
= (const tm_alias_pair
*) y
;
5837 if (p1
->uid
< p2
->uid
)
5839 if (p1
->uid
> p2
->uid
)
5845 finish_tm_clone_pairs (void)
5847 vec
<tm_alias_pair
> tm_alias_pairs
= vNULL
;
5849 if (tm_clone_hash
== NULL
)
5852 /* We need a determenistic order for the .tm_clone_table, otherwise
5853 we will get bootstrap comparison failures, so dump the hash table
5854 to a vector, sort it, and dump the vector. */
5856 /* Dump the hashtable to a vector. */
5858 hash_table
<tm_clone_hasher
>::iterator iter
;
5859 FOR_EACH_HASH_TABLE_ELEMENT (*tm_clone_hash
, map
, tree_map
*, iter
)
5861 tm_alias_pair p
= {DECL_UID (map
->base
.from
), map
->base
.from
, map
->to
};
5862 tm_alias_pairs
.safe_push (p
);
5865 tm_alias_pairs
.qsort (tm_alias_pair_cmp
);
5868 dump_tm_clone_pairs (tm_alias_pairs
);
5870 tm_clone_hash
->empty ();
5871 tm_clone_hash
= NULL
;
5872 tm_alias_pairs
.release ();
5876 /* Emit an assembler directive to set symbol for DECL visibility to
5877 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5880 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5881 int vis ATTRIBUTE_UNUSED
)
5883 #ifdef HAVE_GAS_HIDDEN
5884 static const char * const visibility_types
[] = {
5885 NULL
, "protected", "hidden", "internal"
5888 const char *name
, *type
;
5891 id
= DECL_ASSEMBLER_NAME (decl
);
5892 ultimate_transparent_alias_target (&id
);
5893 name
= IDENTIFIER_POINTER (id
);
5895 type
= visibility_types
[vis
];
5897 fprintf (asm_out_file
, "\t.%s\t", type
);
5898 assemble_name (asm_out_file
, name
);
5899 fprintf (asm_out_file
, "\n");
5901 if (!DECL_ARTIFICIAL (decl
))
5902 warning (OPT_Wattributes
, "visibility attribute not supported "
5903 "in this configuration; ignored");
5907 /* A helper function to call assemble_visibility when needed for a decl. */
5910 maybe_assemble_visibility (tree decl
)
5912 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5914 if (TREE_CODE (decl
) == FUNCTION_DECL
5915 && cgraph_node::get (decl
)
5916 && cgraph_node::get (decl
)->instrumentation_clone
5917 && cgraph_node::get (decl
)->instrumented_version
)
5918 vis
= DECL_VISIBILITY (cgraph_node::get (decl
)->instrumented_version
->decl
);
5920 if (vis
!= VISIBILITY_DEFAULT
)
5922 targetm
.asm_out
.assemble_visibility (decl
, vis
);
5929 /* Returns 1 if the target configuration supports defining public symbols
5930 so that one of them will be chosen at link time instead of generating a
5931 multiply-defined symbol error, whether through the use of weak symbols or
5932 a target-specific mechanism for having duplicates discarded. */
5935 supports_one_only (void)
5937 if (SUPPORTS_ONE_ONLY
)
5939 return TARGET_SUPPORTS_WEAK
;
5942 /* Set up DECL as a public symbol that can be defined in multiple
5943 translation units without generating a linker error. */
5946 make_decl_one_only (tree decl
, tree comdat_group
)
5948 struct symtab_node
*symbol
;
5949 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5950 || TREE_CODE (decl
) == FUNCTION_DECL
);
5952 TREE_PUBLIC (decl
) = 1;
5954 if (TREE_CODE (decl
) == VAR_DECL
)
5955 symbol
= varpool_node::get_create (decl
);
5957 symbol
= cgraph_node::get_create (decl
);
5959 if (SUPPORTS_ONE_ONLY
)
5961 #ifdef MAKE_DECL_ONE_ONLY
5962 MAKE_DECL_ONE_ONLY (decl
);
5964 symbol
->set_comdat_group (comdat_group
);
5966 else if (TREE_CODE (decl
) == VAR_DECL
5967 && (DECL_INITIAL (decl
) == 0
5968 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
5969 DECL_COMMON (decl
) = 1;
5972 gcc_assert (TARGET_SUPPORTS_WEAK
);
5973 DECL_WEAK (decl
) = 1;
5978 init_varasm_once (void)
5980 section_htab
= hash_table
<section_hasher
>::create_ggc (31);
5981 object_block_htab
= hash_table
<object_block_hasher
>::create_ggc (31);
5982 const_desc_htab
= hash_table
<tree_descriptor_hasher
>::create_ggc (1009);
5984 shared_constant_pool
= create_constant_pool ();
5986 #ifdef TEXT_SECTION_ASM_OP
5987 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
5988 TEXT_SECTION_ASM_OP
);
5991 #ifdef DATA_SECTION_ASM_OP
5992 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5993 DATA_SECTION_ASM_OP
);
5996 #ifdef SDATA_SECTION_ASM_OP
5997 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5998 SDATA_SECTION_ASM_OP
);
6001 #ifdef READONLY_DATA_SECTION_ASM_OP
6002 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
6003 READONLY_DATA_SECTION_ASM_OP
);
6006 #ifdef CTORS_SECTION_ASM_OP
6007 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
6008 CTORS_SECTION_ASM_OP
);
6011 #ifdef DTORS_SECTION_ASM_OP
6012 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
6013 DTORS_SECTION_ASM_OP
);
6016 #ifdef BSS_SECTION_ASM_OP
6017 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6018 output_section_asm_op
,
6019 BSS_SECTION_ASM_OP
);
6022 #ifdef SBSS_SECTION_ASM_OP
6023 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6024 output_section_asm_op
,
6025 SBSS_SECTION_ASM_OP
);
6028 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6029 | SECTION_COMMON
, emit_tls_common
);
6030 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6031 | SECTION_COMMON
, emit_local
);
6032 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6033 | SECTION_COMMON
, emit_common
);
6035 #if defined ASM_OUTPUT_ALIGNED_BSS
6036 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
6040 targetm
.asm_out
.init_sections ();
6042 if (readonly_data_section
== NULL
)
6043 readonly_data_section
= text_section
;
6045 #ifdef ASM_OUTPUT_EXTERNAL
6046 pending_assemble_externals_set
= new hash_set
<tree
>;
6051 decl_default_tls_model (const_tree decl
)
6053 enum tls_model kind
;
6056 is_local
= targetm
.binds_local_p (decl
);
6060 kind
= TLS_MODEL_LOCAL_EXEC
;
6062 kind
= TLS_MODEL_INITIAL_EXEC
;
6065 /* Local dynamic is inefficient when we're not combining the
6066 parts of the address. */
6067 else if (optimize
&& is_local
)
6068 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6070 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6071 if (kind
< flag_tls_default
)
6072 kind
= flag_tls_default
;
6077 /* Select a set of attributes for section NAME based on the properties
6078 of DECL and whether or not RELOC indicates that DECL's initializer
6079 might contain runtime relocations.
6081 We make the section read-only and executable for a function decl,
6082 read-only for a const data decl, and writable for a non-const data decl. */
6085 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6089 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6090 flags
= SECTION_CODE
;
6093 enum section_category category
6094 = categorize_decl_for_section (decl
, reloc
);
6095 if (decl_readonly_section_1 (category
))
6097 else if (category
== SECCAT_DATA_REL_RO
6098 || category
== SECCAT_DATA_REL_RO_LOCAL
)
6099 flags
= SECTION_WRITE
| SECTION_RELRO
;
6101 flags
= SECTION_WRITE
;
6105 flags
= SECTION_WRITE
;
6106 if (strcmp (name
, ".data.rel.ro") == 0
6107 || strcmp (name
, ".data.rel.ro.local") == 0)
6108 flags
|= SECTION_RELRO
;
6111 if (decl
&& DECL_P (decl
) && DECL_COMDAT_GROUP (decl
))
6112 flags
|= SECTION_LINKONCE
;
6114 if (strcmp (name
, ".vtable_map_vars") == 0)
6115 flags
|= SECTION_LINKONCE
;
6117 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6118 flags
|= SECTION_TLS
| SECTION_WRITE
;
6120 if (strcmp (name
, ".bss") == 0
6121 || strncmp (name
, ".bss.", 5) == 0
6122 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6123 || strcmp (name
, ".persistent.bss") == 0
6124 || strcmp (name
, ".sbss") == 0
6125 || strncmp (name
, ".sbss.", 6) == 0
6126 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6127 flags
|= SECTION_BSS
;
6129 if (strcmp (name
, ".tdata") == 0
6130 || strncmp (name
, ".tdata.", 7) == 0
6131 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6132 flags
|= SECTION_TLS
;
6134 if (strcmp (name
, ".tbss") == 0
6135 || strncmp (name
, ".tbss.", 6) == 0
6136 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6137 flags
|= SECTION_TLS
| SECTION_BSS
;
6139 /* These three sections have special ELF types. They are neither
6140 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6141 want to print a section type (@progbits or @nobits). If someone
6142 is silly enough to emit code or TLS variables to one of these
6143 sections, then don't handle them specially. */
6144 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
6145 && (strcmp (name
, ".init_array") == 0
6146 || strcmp (name
, ".fini_array") == 0
6147 || strcmp (name
, ".preinit_array") == 0))
6148 flags
|= SECTION_NOTYPE
;
6153 /* Return true if the target supports some form of global BSS,
6154 either through bss_noswitch_section, or by selecting a BSS
6155 section in TARGET_ASM_SELECT_SECTION. */
6158 have_global_bss_p (void)
6160 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6163 /* Output assembly to switch to section NAME with attribute FLAGS.
6164 Four variants for common object file formats. */
6167 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6168 unsigned int flags ATTRIBUTE_UNUSED
,
6169 tree decl ATTRIBUTE_UNUSED
)
6171 /* Some object formats don't support named sections at all. The
6172 front-end should already have flagged this as an error. */
6176 #ifndef TLS_SECTION_ASM_FLAG
6177 #define TLS_SECTION_ASM_FLAG 'T'
6181 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6184 char flagchars
[10], *f
= flagchars
;
6186 /* If we have already declared this section, we can use an
6187 abbreviated form to switch back to it -- unless this section is
6188 part of a COMDAT groups, in which case GAS requires the full
6189 declaration every time. */
6190 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6191 && (flags
& SECTION_DECLARED
))
6193 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6197 if (!(flags
& SECTION_DEBUG
))
6199 #if defined (HAVE_GAS_SECTION_EXCLUDE) && HAVE_GAS_SECTION_EXCLUDE == 1
6200 if (flags
& SECTION_EXCLUDE
)
6203 if (flags
& SECTION_WRITE
)
6205 if (flags
& SECTION_CODE
)
6207 if (flags
& SECTION_SMALL
)
6209 if (flags
& SECTION_MERGE
)
6211 if (flags
& SECTION_STRINGS
)
6213 if (flags
& SECTION_TLS
)
6214 *f
++ = TLS_SECTION_ASM_FLAG
;
6215 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6219 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6221 if (!(flags
& SECTION_NOTYPE
))
6226 if (flags
& SECTION_BSS
)
6232 /* On platforms that use "@" as the assembly comment character,
6234 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6236 fprintf (asm_out_file
, format
, type
);
6238 if (flags
& SECTION_ENTSIZE
)
6239 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6240 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6242 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6243 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6245 fprintf (asm_out_file
, ",%s,comdat",
6246 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6250 putc ('\n', asm_out_file
);
6254 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6255 tree decl ATTRIBUTE_UNUSED
)
6257 char flagchars
[8], *f
= flagchars
;
6259 if (flags
& SECTION_WRITE
)
6261 if (flags
& SECTION_CODE
)
6265 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6269 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6272 default_coff_asm_named_section (name
, flags
, decl
);
6274 if (flags
& SECTION_LINKONCE
)
6276 /* Functions may have been compiled at various levels of
6277 optimization so we can't use `same_size' here.
6278 Instead, have the linker pick one. */
6279 fprintf (asm_out_file
, "\t.linkonce %s\n",
6280 (flags
& SECTION_CODE
? "discard" : "same_size"));
6284 /* The lame default section selector. */
6287 default_select_section (tree decl
, int reloc
,
6288 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6292 if (decl_readonly_section (decl
, reloc
))
6293 return readonly_data_section
;
6295 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6297 if (! ((flag_pic
&& reloc
)
6298 || !TREE_READONLY (decl
)
6299 || TREE_SIDE_EFFECTS (decl
)
6300 || !TREE_CONSTANT (decl
)))
6301 return readonly_data_section
;
6303 else if (TREE_CODE (decl
) == STRING_CST
)
6304 return readonly_data_section
;
6305 else if (! (flag_pic
&& reloc
))
6306 return readonly_data_section
;
6308 return data_section
;
6311 enum section_category
6312 categorize_decl_for_section (const_tree decl
, int reloc
)
6314 enum section_category ret
;
6316 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6318 else if (TREE_CODE (decl
) == STRING_CST
)
6320 if ((flag_sanitize
& SANITIZE_ADDRESS
)
6321 && asan_protect_global (CONST_CAST_TREE (decl
)))
6322 /* or !flag_merge_constants */
6323 return SECCAT_RODATA
;
6325 return SECCAT_RODATA_MERGE_STR
;
6327 else if (TREE_CODE (decl
) == VAR_DECL
)
6329 if (bss_initializer_p (decl
))
6331 else if (! TREE_READONLY (decl
)
6332 || TREE_SIDE_EFFECTS (decl
)
6333 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6335 /* Here the reloc_rw_mask is not testing whether the section should
6336 be read-only or not, but whether the dynamic link will have to
6337 do something. If so, we wish to segregate the data in order to
6338 minimize cache misses inside the dynamic linker. */
6339 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6340 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6344 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6345 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6346 else if (reloc
|| flag_merge_constants
< 2
6347 || ((flag_sanitize
& SANITIZE_ADDRESS
)
6348 && asan_protect_global (CONST_CAST_TREE (decl
))))
6349 /* C and C++ don't allow different variables to share the same
6350 location. -fmerge-all-constants allows even that (at the
6351 expense of not conforming). */
6352 ret
= SECCAT_RODATA
;
6353 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6354 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6356 ret
= SECCAT_RODATA_MERGE_CONST
;
6358 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6360 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6361 || TREE_SIDE_EFFECTS (decl
)
6362 || ! TREE_CONSTANT (decl
))
6365 ret
= SECCAT_RODATA
;
6368 ret
= SECCAT_RODATA
;
6370 /* There are no read-only thread-local sections. */
6371 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6373 /* Note that this would be *just* SECCAT_BSS, except that there's
6374 no concept of a read-only thread-local-data section. */
6375 if (ret
== SECCAT_BSS
6376 || (flag_zero_initialized_in_bss
6377 && initializer_zerop (DECL_INITIAL (decl
))))
6383 /* If the target uses small data sections, select it. */
6384 else if (targetm
.in_small_data_p (decl
))
6386 if (ret
== SECCAT_BSS
)
6388 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6389 ret
= SECCAT_SRODATA
;
6398 decl_readonly_section_1 (enum section_category category
)
6403 case SECCAT_RODATA_MERGE_STR
:
6404 case SECCAT_RODATA_MERGE_STR_INIT
:
6405 case SECCAT_RODATA_MERGE_CONST
:
6406 case SECCAT_SRODATA
:
6414 decl_readonly_section (const_tree decl
, int reloc
)
6416 return decl_readonly_section_1 (categorize_decl_for_section (decl
, reloc
));
6419 /* Select a section based on the above categorization. */
6422 default_elf_select_section (tree decl
, int reloc
,
6423 unsigned HOST_WIDE_INT align
)
6426 switch (categorize_decl_for_section (decl
, reloc
))
6429 /* We're not supposed to be called on FUNCTION_DECLs. */
6432 return readonly_data_section
;
6433 case SECCAT_RODATA_MERGE_STR
:
6434 return mergeable_string_section (decl
, align
, 0);
6435 case SECCAT_RODATA_MERGE_STR_INIT
:
6436 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6437 case SECCAT_RODATA_MERGE_CONST
:
6438 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6439 case SECCAT_SRODATA
:
6443 return data_section
;
6444 case SECCAT_DATA_REL
:
6445 sname
= ".data.rel";
6447 case SECCAT_DATA_REL_LOCAL
:
6448 sname
= ".data.rel.local";
6450 case SECCAT_DATA_REL_RO
:
6451 sname
= ".data.rel.ro";
6453 case SECCAT_DATA_REL_RO_LOCAL
:
6454 sname
= ".data.rel.ro.local";
6477 return get_named_section (decl
, sname
, reloc
);
6480 /* Construct a unique section name based on the decl name and the
6481 categorization performed above. */
6484 default_unique_section (tree decl
, int reloc
)
6486 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6487 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6488 const char *prefix
, *name
, *linkonce
;
6492 switch (categorize_decl_for_section (decl
, reloc
))
6495 prefix
= one_only
? ".t" : ".text";
6498 case SECCAT_RODATA_MERGE_STR
:
6499 case SECCAT_RODATA_MERGE_STR_INIT
:
6500 case SECCAT_RODATA_MERGE_CONST
:
6501 prefix
= one_only
? ".r" : ".rodata";
6503 case SECCAT_SRODATA
:
6504 prefix
= one_only
? ".s2" : ".sdata2";
6507 prefix
= one_only
? ".d" : ".data";
6509 case SECCAT_DATA_REL
:
6510 prefix
= one_only
? ".d.rel" : ".data.rel";
6512 case SECCAT_DATA_REL_LOCAL
:
6513 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6515 case SECCAT_DATA_REL_RO
:
6516 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6518 case SECCAT_DATA_REL_RO_LOCAL
:
6519 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6522 prefix
= one_only
? ".s" : ".sdata";
6525 prefix
= one_only
? ".b" : ".bss";
6528 prefix
= one_only
? ".sb" : ".sbss";
6531 prefix
= one_only
? ".td" : ".tdata";
6534 prefix
= one_only
? ".tb" : ".tbss";
6540 id
= DECL_ASSEMBLER_NAME (decl
);
6541 ultimate_transparent_alias_target (&id
);
6542 name
= IDENTIFIER_POINTER (id
);
6543 name
= targetm
.strip_name_encoding (name
);
6545 /* If we're using one_only, then there needs to be a .gnu.linkonce
6546 prefix to the section name. */
6547 linkonce
= one_only
? ".gnu.linkonce" : "";
6549 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6551 set_decl_section_name (decl
, string
);
6554 /* Subroutine of compute_reloc_for_rtx for leaf rtxes. */
6557 compute_reloc_for_rtx_1 (const_rtx x
)
6559 switch (GET_CODE (x
))
6562 return SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6570 /* Like compute_reloc_for_constant, except for an RTX. The return value
6571 is a mask for which bit 1 indicates a global relocation, and bit 0
6572 indicates a local relocation. */
6575 compute_reloc_for_rtx (const_rtx x
)
6577 switch (GET_CODE (x
))
6581 return compute_reloc_for_rtx_1 (x
);
6586 subrtx_iterator::array_type array
;
6587 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
6588 reloc
|= compute_reloc_for_rtx_1 (*iter
);
6598 default_select_rtx_section (machine_mode mode ATTRIBUTE_UNUSED
,
6600 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6602 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6603 return data_section
;
6605 return readonly_data_section
;
6609 default_elf_select_rtx_section (machine_mode mode
, rtx x
,
6610 unsigned HOST_WIDE_INT align
)
6612 int reloc
= compute_reloc_for_rtx (x
);
6614 /* ??? Handle small data here somehow. */
6616 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6619 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6621 return get_named_section (NULL
, ".data.rel.ro", 3);
6624 return mergeable_constant_section (mode
, align
, 0);
6627 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6630 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6635 /* Careful not to prod global register variables. */
6638 symbol
= XEXP (rtl
, 0);
6639 if (GET_CODE (symbol
) != SYMBOL_REF
)
6642 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6643 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6644 flags
|= SYMBOL_FLAG_FUNCTION
;
6645 if (targetm
.binds_local_p (decl
))
6646 flags
|= SYMBOL_FLAG_LOCAL
;
6647 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6648 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6649 else if (targetm
.in_small_data_p (decl
))
6650 flags
|= SYMBOL_FLAG_SMALL
;
6651 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6652 being PUBLIC, the thing *must* be defined in this translation unit.
6653 Prevent this buglet from being propagated into rtl code as well. */
6654 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6655 flags
|= SYMBOL_FLAG_EXTERNAL
;
6657 SYMBOL_REF_FLAGS (symbol
) = flags
;
6660 /* By default, we do nothing for encode_section_info, so we need not
6661 do anything but discard the '*' marker. */
6664 default_strip_name_encoding (const char *str
)
6666 return str
+ (*str
== '*');
6669 #ifdef ASM_OUTPUT_DEF
6670 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6671 anchor relative to ".", the current section position. */
6674 default_asm_output_anchor (rtx symbol
)
6678 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6679 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6680 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6684 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6687 default_use_anchors_for_symbol_p (const_rtx symbol
)
6692 /* Don't use anchors for mergeable sections. The linker might move
6693 the objects around. */
6694 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6695 if (sect
->common
.flags
& SECTION_MERGE
)
6698 /* Don't use anchors for small data sections. The small data register
6699 acts as an anchor for such sections. */
6700 if (sect
->common
.flags
& SECTION_SMALL
)
6703 decl
= SYMBOL_REF_DECL (symbol
);
6704 if (decl
&& DECL_P (decl
))
6706 /* Don't use section anchors for decls that might be defined or
6707 usurped by other modules. */
6708 if (TREE_PUBLIC (decl
) && !decl_binds_to_current_def_p (decl
))
6711 /* Don't use section anchors for decls that will be placed in a
6712 small data section. */
6713 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6714 one above. The problem is that we only use SECTION_SMALL for
6715 sections that should be marked as small in the section directive. */
6716 if (targetm
.in_small_data_p (decl
))
6722 /* Return true when RESOLUTION indicate that symbol will be bound to the
6723 definition provided by current .o file. */
6726 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
6728 return (resolution
== LDPR_PREVAILING_DEF
6729 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6730 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
6733 /* Return true when RESOLUTION indicate that symbol will be bound locally
6734 within current executable or DSO. */
6737 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
6739 return (resolution
== LDPR_PREVAILING_DEF
6740 || resolution
== LDPR_PREVAILING_DEF_IRONLY
6741 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6742 || resolution
== LDPR_PREEMPTED_REG
6743 || resolution
== LDPR_PREEMPTED_IR
6744 || resolution
== LDPR_RESOLVED_IR
6745 || resolution
== LDPR_RESOLVED_EXEC
);
6748 /* COMMON_LOCAL_P is true means that the linker can guarantee that an
6749 uninitialized common symbol in the executable will still be defined
6750 (through COPY relocation) in the executable. */
6753 default_binds_local_p_3 (const_tree exp
, bool shlib
, bool weak_dominate
,
6754 bool extern_protected_data
, bool common_local_p
)
6756 /* A non-decl is an entry in the constant pool. */
6760 /* Weakrefs may not bind locally, even though the weakref itself is always
6761 static and therefore local. Similarly, the resolver for ifunc functions
6762 might resolve to a non-local function.
6763 FIXME: We can resolve the weakref case more curefuly by looking at the
6765 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
))
6766 || (TREE_CODE (exp
) == FUNCTION_DECL
6767 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (exp
))))
6770 /* Static variables are always local. */
6771 if (! TREE_PUBLIC (exp
))
6774 /* With resolution file in hand, take look into resolutions.
6775 We can't just return true for resolved_locally symbols,
6776 because dynamic linking might overwrite symbols
6777 in shared libraries. */
6778 bool resolved_locally
= false;
6780 bool uninited_common
= (DECL_COMMON (exp
)
6781 && (DECL_INITIAL (exp
) == NULL
6783 && DECL_INITIAL (exp
) == error_mark_node
)));
6785 /* A non-external variable is defined locally only if it isn't
6786 uninitialized COMMON variable or common_local_p is true. */
6787 bool defined_locally
= (!DECL_EXTERNAL (exp
)
6788 && (!uninited_common
|| common_local_p
));
6789 if (symtab_node
*node
= symtab_node::get (exp
))
6791 if (node
->in_other_partition
)
6792 defined_locally
= true;
6793 if (resolution_to_local_definition_p (node
->resolution
))
6794 defined_locally
= resolved_locally
= true;
6795 else if (resolution_local_p (node
->resolution
))
6796 resolved_locally
= true;
6798 if (defined_locally
&& weak_dominate
&& !shlib
)
6799 resolved_locally
= true;
6801 /* Undefined weak symbols are never defined locally. */
6802 if (DECL_WEAK (exp
) && !defined_locally
)
6805 /* A symbol is local if the user has said explicitly that it will be,
6806 or if we have a definition for the symbol. We cannot infer visibility
6807 for undefined symbols. */
6808 if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
6809 && (TREE_CODE (exp
) == FUNCTION_DECL
6810 || !extern_protected_data
6811 || DECL_VISIBILITY (exp
) != VISIBILITY_PROTECTED
)
6812 && (DECL_VISIBILITY_SPECIFIED (exp
) || defined_locally
))
6815 /* If PIC, then assume that any global name can be overridden by
6816 symbols resolved from other modules. */
6820 /* Variables defined outside this object might not be local. */
6821 if (DECL_EXTERNAL (exp
) && !resolved_locally
)
6824 /* Non-dominant weak symbols are not defined locally. */
6825 if (DECL_WEAK (exp
) && !resolved_locally
)
6828 /* Uninitialized COMMON variable may be unified with symbols
6829 resolved from other modules. */
6830 if (uninited_common
&& !resolved_locally
)
6833 /* Otherwise we're left with initialized (or non-common) global data
6834 which is of necessity defined locally. */
6838 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6839 wrt cross-module name binding. */
6842 default_binds_local_p (const_tree exp
)
6844 return default_binds_local_p_3 (exp
, flag_shlib
!= 0, true, false, false);
6847 /* Similar to default_binds_local_p, but common symbol may be local and
6848 extern protected data is non-local. */
6851 default_binds_local_p_2 (const_tree exp
)
6853 return default_binds_local_p_3 (exp
, flag_shlib
!= 0, true, true,
6858 default_binds_local_p_1 (const_tree exp
, int shlib
)
6860 return default_binds_local_p_3 (exp
, shlib
!= 0, false, false, false);
6863 /* Return true when references to DECL must bind to current definition in
6866 The condition is usually equivalent to whether the function binds to the
6867 current module (shared library or executable), that is to binds_local_p.
6868 We use this fact to avoid need for another target hook and implement
6869 the logic using binds_local_p and just special cases where
6870 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
6871 the weak definitions (that can be overwritten at linktime by other
6872 definition from different object file) and when resolution info is available
6873 we simply use the knowledge passed to us by linker plugin. */
6875 decl_binds_to_current_def_p (const_tree decl
)
6877 gcc_assert (DECL_P (decl
));
6878 if (!targetm
.binds_local_p (decl
))
6880 if (!TREE_PUBLIC (decl
))
6883 /* When resolution is available, just use it. */
6884 if (symtab_node
*node
= symtab_node::get (decl
))
6886 if (node
->resolution
!= LDPR_UNKNOWN
)
6887 return resolution_to_local_definition_p (node
->resolution
);
6890 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
6891 binds locally but still can be overwritten), DECL_COMMON (can be merged
6892 with a non-common definition somewhere in the same module) or
6894 This rely on fact that binds_local_p behave as decl_replaceable_p
6895 for all other declaration types. */
6896 if (DECL_WEAK (decl
))
6898 if (DECL_COMMON (decl
)
6899 && (DECL_INITIAL (decl
) == NULL
6900 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
6902 if (DECL_EXTERNAL (decl
))
6907 /* A replaceable function or variable is one which may be replaced
6908 at link-time with an entirely different definition, provided that the
6909 replacement has the same type. For example, functions declared
6910 with __attribute__((weak)) on most systems are replaceable.
6912 COMDAT functions are not replaceable, since all definitions of the
6913 function must be equivalent. It is important that COMDAT functions
6914 not be treated as replaceable so that use of C++ template
6915 instantiations is not penalized. */
6918 decl_replaceable_p (tree decl
)
6920 gcc_assert (DECL_P (decl
));
6921 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
6923 if (!flag_semantic_interposition
6924 && !DECL_WEAK (decl
))
6926 return !decl_binds_to_current_def_p (decl
);
6929 /* Default function to output code that will globalize a label. A
6930 target must define GLOBAL_ASM_OP or provide its own function to
6931 globalize a label. */
6932 #ifdef GLOBAL_ASM_OP
6934 default_globalize_label (FILE * stream
, const char *name
)
6936 fputs (GLOBAL_ASM_OP
, stream
);
6937 assemble_name (stream
, name
);
6938 putc ('\n', stream
);
6940 #endif /* GLOBAL_ASM_OP */
6942 /* Default function to output code that will globalize a declaration. */
6944 default_globalize_decl_name (FILE * stream
, tree decl
)
6946 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6947 targetm
.asm_out
.globalize_label (stream
, name
);
6950 /* Default function to output a label for unwind information. The
6951 default is to do nothing. A target that needs nonlocal labels for
6952 unwind information must provide its own function to do this. */
6954 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6955 tree decl ATTRIBUTE_UNUSED
,
6956 int for_eh ATTRIBUTE_UNUSED
,
6957 int empty ATTRIBUTE_UNUSED
)
6961 /* Default function to output a label to divide up the exception table.
6962 The default is to do nothing. A target that needs/wants to divide
6963 up the table must provide it's own function to do this. */
6965 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6969 /* This is how to output an internal numbered label where PREFIX is
6970 the class of label and LABELNO is the number within the class. */
6973 default_generate_internal_label (char *buf
, const char *prefix
,
6974 unsigned long labelno
)
6976 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6979 /* This is how to output an internal numbered label where PREFIX is
6980 the class of label and LABELNO is the number within the class. */
6983 default_internal_label (FILE *stream
, const char *prefix
,
6984 unsigned long labelno
)
6986 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6987 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6988 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6992 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6995 default_asm_declare_constant_name (FILE *file
, const char *name
,
6996 const_tree exp ATTRIBUTE_UNUSED
,
6997 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
6999 assemble_label (file
, name
);
7002 /* This is the default behavior at the beginning of a file. It's
7003 controlled by two other target-hook toggles. */
7005 default_file_start (void)
7007 if (targetm
.asm_file_start_app_off
7008 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
7009 fputs (ASM_APP_OFF
, asm_out_file
);
7011 if (targetm
.asm_file_start_file_directive
)
7013 /* LTO produced units have no meaningful main_input_filename. */
7015 output_file_directive (asm_out_file
, "<artificial>");
7017 output_file_directive (asm_out_file
, main_input_filename
);
7021 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
7022 which emits a special section directive used to indicate whether or
7023 not this object file needs an executable stack. This is primarily
7024 a GNU extension to ELF but could be used on other targets. */
7026 int trampolines_created
;
7029 file_end_indicate_exec_stack (void)
7031 unsigned int flags
= SECTION_DEBUG
;
7032 if (trampolines_created
)
7033 flags
|= SECTION_CODE
;
7035 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
7038 /* Emit a special section directive to indicate that this object file
7039 was compiled with -fsplit-stack. This is used to let the linker
7040 detect calls between split-stack code and non-split-stack code, so
7041 that it can modify the split-stack code to allocate a sufficiently
7042 large stack. We emit another special section if there are any
7043 functions in this file which have the no_split_stack attribute, to
7044 prevent the linker from warning about being unable to convert the
7045 functions if they call non-split-stack code. */
7048 file_end_indicate_split_stack (void)
7050 if (flag_split_stack
)
7052 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
7054 if (saw_no_split_stack
)
7055 switch_to_section (get_section (".note.GNU-no-split-stack",
7056 SECTION_DEBUG
, NULL
));
7060 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
7061 a get_unnamed_section callback. */
7064 output_section_asm_op (const void *directive
)
7066 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
7069 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
7070 the current section is NEW_SECTION. */
7073 switch_to_section (section
*new_section
)
7075 if (in_section
== new_section
)
7078 if (new_section
->common
.flags
& SECTION_FORGET
)
7081 in_section
= new_section
;
7083 switch (SECTION_STYLE (new_section
))
7086 targetm
.asm_out
.named_section (new_section
->named
.name
,
7087 new_section
->named
.common
.flags
,
7088 new_section
->named
.decl
);
7091 case SECTION_UNNAMED
:
7092 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
7095 case SECTION_NOSWITCH
:
7100 new_section
->common
.flags
|= SECTION_DECLARED
;
7103 /* If block symbol SYMBOL has not yet been assigned an offset, place
7104 it at the end of its block. */
7107 place_block_symbol (rtx symbol
)
7109 unsigned HOST_WIDE_INT size
, mask
, offset
;
7110 struct constant_descriptor_rtx
*desc
;
7111 unsigned int alignment
;
7112 struct object_block
*block
;
7115 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
7116 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
7119 /* Work out the symbol's size and alignment. */
7120 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7122 desc
= SYMBOL_REF_CONSTANT (symbol
);
7123 alignment
= desc
->align
;
7124 size
= GET_MODE_SIZE (desc
->mode
);
7126 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7128 decl
= SYMBOL_REF_DECL (symbol
);
7129 gcc_checking_assert (DECL_IN_CONSTANT_POOL (decl
));
7130 alignment
= DECL_ALIGN (decl
);
7131 size
= get_constant_size (DECL_INITIAL (decl
));
7132 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7133 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7134 && asan_protect_global (DECL_INITIAL (decl
)))
7135 size
+= asan_red_zone_size (size
);
7139 struct symtab_node
*snode
;
7140 decl
= SYMBOL_REF_DECL (symbol
);
7142 snode
= symtab_node::get (decl
);
7145 rtx target
= DECL_RTL (snode
->ultimate_alias_target ()->decl
);
7147 gcc_assert (MEM_P (target
)
7148 && GET_CODE (XEXP (target
, 0)) == SYMBOL_REF
7149 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (target
, 0)));
7150 target
= XEXP (target
, 0);
7151 place_block_symbol (target
);
7152 SYMBOL_REF_BLOCK_OFFSET (symbol
) = SYMBOL_REF_BLOCK_OFFSET (target
);
7155 alignment
= get_variable_align (decl
);
7156 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7157 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7158 && asan_protect_global (decl
))
7160 size
+= asan_red_zone_size (size
);
7161 alignment
= MAX (alignment
,
7162 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
7166 /* Calculate the object's offset from the start of the block. */
7167 block
= SYMBOL_REF_BLOCK (symbol
);
7168 mask
= alignment
/ BITS_PER_UNIT
- 1;
7169 offset
= (block
->size
+ mask
) & ~mask
;
7170 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
7172 /* Record the block's new alignment and size. */
7173 block
->alignment
= MAX (block
->alignment
, alignment
);
7174 block
->size
= offset
+ size
;
7176 vec_safe_push (block
->objects
, symbol
);
7179 /* Return the anchor that should be used to address byte offset OFFSET
7180 from the first object in BLOCK. MODEL is the TLS model used
7184 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7185 enum tls_model model
)
7188 unsigned int begin
, middle
, end
;
7189 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7192 /* Work out the anchor's offset. Use an offset of 0 for the first
7193 anchor so that we don't pessimize the case where we take the address
7194 of a variable at the beginning of the block. This is particularly
7195 useful when a block has only one variable assigned to it.
7197 We try to place anchors RANGE bytes apart, so there can then be
7198 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7199 a ptr_mode offset. With some target settings, the lowest such
7200 anchor might be out of range for the lowest ptr_mode offset;
7201 likewise the highest anchor for the highest offset. Use anchors
7202 at the extreme ends of the ptr_mode range in such cases.
7204 All arithmetic uses unsigned integers in order to avoid
7206 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7207 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7208 range
= max_offset
- min_offset
+ 1;
7213 bias
= HOST_WIDE_INT_1U
<< (GET_MODE_BITSIZE (ptr_mode
) - 1);
7216 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7217 delta
-= delta
% range
;
7220 offset
= (HOST_WIDE_INT
) (-delta
);
7224 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7225 delta
-= delta
% range
;
7226 if (delta
> bias
- 1)
7228 offset
= (HOST_WIDE_INT
) delta
;
7232 /* Do a binary search to see if there's already an anchor we can use.
7233 Set BEGIN to the new anchor's index if not. */
7235 end
= vec_safe_length (block
->anchors
);
7236 while (begin
!= end
)
7238 middle
= (end
+ begin
) / 2;
7239 anchor
= (*block
->anchors
)[middle
];
7240 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7242 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7244 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7246 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7252 /* Create a new anchor with a unique label. */
7253 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7254 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7255 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7256 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7258 /* Insert it at index BEGIN. */
7259 vec_safe_insert (block
->anchors
, begin
, anchor
);
7263 /* Output the objects in BLOCK. */
7266 output_object_block (struct object_block
*block
)
7268 struct constant_descriptor_rtx
*desc
;
7270 HOST_WIDE_INT offset
;
7274 if (!block
->objects
)
7277 /* Switch to the section and make sure that the first byte is
7278 suitably aligned. */
7279 /* Special case VTV comdat sections similar to assemble_variable. */
7280 if (SECTION_STYLE (block
->sect
) == SECTION_NAMED
7281 && block
->sect
->named
.name
7282 && (strcmp (block
->sect
->named
.name
, ".vtable_map_vars") == 0))
7283 handle_vtv_comdat_section (block
->sect
, block
->sect
->named
.decl
);
7285 switch_to_section (block
->sect
);
7287 assemble_align (block
->alignment
);
7289 /* Define the values of all anchors relative to the current section
7291 FOR_EACH_VEC_SAFE_ELT (block
->anchors
, i
, symbol
)
7292 targetm
.asm_out
.output_anchor (symbol
);
7294 /* Output the objects themselves. */
7296 FOR_EACH_VEC_ELT (*block
->objects
, i
, symbol
)
7298 /* Move to the object's offset, padding with zeros if necessary. */
7299 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7300 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7301 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7303 desc
= SYMBOL_REF_CONSTANT (symbol
);
7304 /* Pass 1 for align as we have already laid out everything in the block.
7305 So aligning shouldn't be necessary. */
7306 output_constant_pool_1 (desc
, 1);
7307 offset
+= GET_MODE_SIZE (desc
->mode
);
7309 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7312 decl
= SYMBOL_REF_DECL (symbol
);
7313 assemble_constant_contents
7314 (DECL_INITIAL (decl
), XSTR (symbol
, 0), DECL_ALIGN (decl
));
7316 size
= get_constant_size (DECL_INITIAL (decl
));
7318 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7319 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7320 && asan_protect_global (DECL_INITIAL (decl
)))
7322 size
= asan_red_zone_size (size
);
7323 assemble_zeros (size
);
7330 decl
= SYMBOL_REF_DECL (symbol
);
7331 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
7332 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7334 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7335 && asan_protect_global (decl
))
7337 size
= asan_red_zone_size (size
);
7338 assemble_zeros (size
);
7345 /* A callback for qsort to compare object_blocks. */
7348 output_object_block_compare (const void *x
, const void *y
)
7350 object_block
*p1
= *(object_block
* const*)x
;
7351 object_block
*p2
= *(object_block
* const*)y
;
7353 if (p1
->sect
->common
.flags
& SECTION_NAMED
7354 && !(p2
->sect
->common
.flags
& SECTION_NAMED
))
7357 if (!(p1
->sect
->common
.flags
& SECTION_NAMED
)
7358 && p2
->sect
->common
.flags
& SECTION_NAMED
)
7361 if (p1
->sect
->common
.flags
& SECTION_NAMED
7362 && p2
->sect
->common
.flags
& SECTION_NAMED
)
7363 return strcmp (p1
->sect
->named
.name
, p2
->sect
->named
.name
);
7365 unsigned f1
= p1
->sect
->common
.flags
;
7366 unsigned f2
= p2
->sect
->common
.flags
;
7369 return f1
< f2
? -1 : 1;
7372 /* Output the definitions of all object_blocks. */
7375 output_object_blocks (void)
7377 vec
<object_block
*, va_heap
> v
;
7378 v
.create (object_block_htab
->elements ());
7380 hash_table
<object_block_hasher
>::iterator hi
;
7382 FOR_EACH_HASH_TABLE_ELEMENT (*object_block_htab
, obj
, object_block
*, hi
)
7385 /* Sort them in order to output them in a deterministic manner,
7386 otherwise we may get .rodata sections in different orders with
7388 v
.qsort (output_object_block_compare
);
7390 FOR_EACH_VEC_ELT (v
, i
, obj
)
7391 output_object_block (obj
);
7396 /* This function provides a possible implementation of the
7397 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7398 by -frecord-gcc-switches it creates a new mergeable, string section in the
7399 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7400 contains the switches in ASCII format.
7402 FIXME: This code does not correctly handle double quote characters
7403 that appear inside strings, (it strips them rather than preserving them).
7404 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7405 characters - instead it treats them as sub-string separators. Since
7406 we want to emit NUL strings terminators into the object file we have to use
7410 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7414 case SWITCH_TYPE_PASSED
:
7415 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
7416 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7419 case SWITCH_TYPE_DESCRIPTIVE
:
7422 /* Distinguish between invocations where name is NULL. */
7423 static bool started
= false;
7429 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7433 | (SECTION_ENTSIZE
& 1),
7435 switch_to_section (sec
);
7444 /* The return value is currently ignored by the caller, but must be 0.
7445 For -fverbose-asm the return value would be the number of characters
7446 emitted into the assembler file. */
7450 /* Emit text to declare externally defined symbols. It is needed to
7451 properly support non-default visibility. */
7453 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7455 const char *name ATTRIBUTE_UNUSED
)
7457 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7458 set in order to avoid putting out names that are never really
7459 used. Always output visibility specified in the source. */
7460 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7461 && (DECL_VISIBILITY_SPECIFIED (decl
)
7462 || targetm
.binds_local_p (decl
)))
7463 maybe_assemble_visibility (decl
);
7466 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7469 default_asm_output_source_filename (FILE *file
, const char *name
)
7471 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7472 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
7474 fprintf (file
, "\t.file\t");
7475 output_quoted_string (file
, name
);
7480 /* Output a file name in the form wanted by System V. */
7483 output_file_directive (FILE *asm_file
, const char *input_name
)
7488 if (input_name
== NULL
)
7489 input_name
= "<stdin>";
7491 input_name
= remap_debug_filename (input_name
);
7493 len
= strlen (input_name
);
7494 na
= input_name
+ len
;
7496 /* NA gets INPUT_NAME sans directory names. */
7497 while (na
> input_name
)
7499 if (IS_DIR_SEPARATOR (na
[-1]))
7504 targetm
.asm_out
.output_source_filename (asm_file
, na
);
7507 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7510 make_debug_expr_from_rtl (const_rtx exp
)
7512 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7513 machine_mode mode
= GET_MODE (exp
);
7516 DECL_ARTIFICIAL (ddecl
) = 1;
7517 if (REG_P (exp
) && REG_EXPR (exp
))
7518 type
= TREE_TYPE (REG_EXPR (exp
));
7519 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7520 type
= TREE_TYPE (MEM_EXPR (exp
));
7523 if (type
&& TYPE_MODE (type
) == mode
)
7524 TREE_TYPE (ddecl
) = type
;
7526 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7527 DECL_MODE (ddecl
) = mode
;
7528 dval
= gen_rtx_DEBUG_EXPR (mode
);
7529 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7530 SET_DECL_RTL (ddecl
, dval
);
7534 #ifdef ELF_ASCII_ESCAPES
7535 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
7538 default_elf_asm_output_limited_string (FILE *f
, const char *s
)
7543 fputs (STRING_ASM_OP
, f
);
7548 escape
= ELF_ASCII_ESCAPES
[c
];
7555 /* TODO: Print in hex with fast function, important for -flto. */
7556 fprintf (f
, "\\%03o", c
);
7569 /* Default ASM_OUTPUT_ASCII for ELF targets. */
7572 default_elf_asm_output_ascii (FILE *f
, const char *s
, unsigned int len
)
7574 const char *limit
= s
+ len
;
7575 const char *last_null
= NULL
;
7576 unsigned bytes_in_chunk
= 0;
7580 for (; s
< limit
; s
++)
7584 if (bytes_in_chunk
>= 60)
7593 for (p
= s
; p
< limit
&& *p
!= '\0'; p
++)
7600 if (p
< limit
&& (p
- s
) <= (long) ELF_STRING_LIMIT
)
7602 if (bytes_in_chunk
> 0)
7609 default_elf_asm_output_limited_string (f
, s
);
7614 if (bytes_in_chunk
== 0)
7615 fputs (ASCII_DATA_ASM_OP
"\"", f
);
7618 escape
= ELF_ASCII_ESCAPES
[c
];
7626 /* TODO: Print in hex with fast function, important for -flto. */
7627 fprintf (f
, "\\%03o", c
);
7628 bytes_in_chunk
+= 4;
7633 bytes_in_chunk
+= 2;
7640 if (bytes_in_chunk
> 0)
7648 static GTY(()) section
*elf_init_array_section
;
7649 static GTY(()) section
*elf_fini_array_section
;
7652 get_elf_initfini_array_priority_section (int priority
,
7656 if (priority
!= DEFAULT_INIT_PRIORITY
)
7659 sprintf (buf
, "%s.%.5u",
7660 constructor_p
? ".init_array" : ".fini_array",
7662 sec
= get_section (buf
, SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7668 if (elf_init_array_section
== NULL
)
7669 elf_init_array_section
7670 = get_section (".init_array",
7671 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7672 sec
= elf_init_array_section
;
7676 if (elf_fini_array_section
== NULL
)
7677 elf_fini_array_section
7678 = get_section (".fini_array",
7679 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7680 sec
= elf_fini_array_section
;
7686 /* Use .init_array section for constructors. */
7689 default_elf_init_array_asm_out_constructor (rtx symbol
, int priority
)
7691 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7693 assemble_addr_to_section (symbol
, sec
);
7696 /* Use .fini_array section for destructors. */
7699 default_elf_fini_array_asm_out_destructor (rtx symbol
, int priority
)
7701 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7703 assemble_addr_to_section (symbol
, sec
);
7706 /* Default TARGET_ASM_OUTPUT_IDENT hook.
7708 This is a bit of a cheat. The real default is a no-op, but this
7709 hook is the default for all targets with a .ident directive. */
7712 default_asm_output_ident_directive (const char *ident_str
)
7714 const char *ident_asm_op
= "\t.ident\t";
7716 /* If we are still in the front end, do not write out the string
7717 to asm_out_file. Instead, add a fake top-level asm statement.
7718 This allows the front ends to use this hook without actually
7719 writing to asm_out_file, to handle #ident or Pragma Ident. */
7720 if (symtab
->state
== PARSING
)
7722 char *buf
= ACONCAT ((ident_asm_op
, "\"", ident_str
, "\"\n", NULL
));
7723 symtab
->finalize_toplevel_asm (build_string (strlen (buf
), buf
));
7726 fprintf (asm_out_file
, "%s\"%s\"\n", ident_asm_op
, ident_str
);
7730 /* This function ensures that vtable_map variables are not only
7731 in the comdat section, but that each variable has its own unique
7732 comdat name. Without this the variables end up in the same section
7733 with a single comdat name.
7735 FIXME: resolve_unique_section needs to deal better with
7736 decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
7737 that is fixed, this if-else statement can be replaced with
7738 a single call to "switch_to_section (sect)". */
7741 handle_vtv_comdat_section (section
*sect
, const_tree decl ATTRIBUTE_UNUSED
)
7743 #if defined (OBJECT_FORMAT_ELF)
7744 targetm
.asm_out
.named_section (sect
->named
.name
,
7745 sect
->named
.common
.flags
7749 #elif defined (TARGET_PECOFF)
7750 /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
7751 Therefore the following check is used.
7752 In case a the target is PE or COFF a comdat group section
7753 is created, e.g. .vtable_map_vars$foo. The linker places
7754 everything in .vtable_map_vars at the end.
7756 A fix could be made in
7757 gcc/config/i386/winnt.c: i386_pe_unique_section. */
7762 if (TREE_CODE (DECL_NAME (decl
)) == IDENTIFIER_NODE
)
7763 name
= ACONCAT ((sect
->named
.name
, "$",
7764 IDENTIFIER_POINTER (DECL_NAME (decl
)), NULL
));
7766 name
= ACONCAT ((sect
->named
.name
, "$",
7767 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl
))),
7770 targetm
.asm_out
.named_section (name
,
7771 sect
->named
.common
.flags
7777 switch_to_section (sect
);
7781 #include "gt-varasm.h"