1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987-2014 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"
34 #include "stor-layout.h"
35 #include "stringpool.h"
36 #include "gcc-symtab.h"
41 #include "hard-reg-set.h"
44 #include "diagnostic-core.h"
47 #include "langhooks.h"
51 #include "common/common-target.h"
52 #include "targhooks.h"
54 #include "pointer-set.h"
56 #include "basic-block.h"
58 #ifdef XCOFF_DEBUGGING_INFO
59 #include "xcoffout.h" /* Needed for external data
60 declarations for e.g. AIX 4.x. */
63 /* The (assembler) name of the first globally-visible object output. */
64 extern GTY(()) const char *first_global_object_name
;
65 extern GTY(()) const char *weak_global_object_name
;
67 const char *first_global_object_name
;
68 const char *weak_global_object_name
;
71 struct constant_descriptor_rtx
;
72 struct rtx_constant_pool
;
74 #define n_deferred_constants (crtl->varasm.deferred_constants)
76 /* Number for making the label on the next
77 constant that is stored in memory. */
79 static GTY(()) int const_labelno
;
81 /* Carry information from ASM_DECLARE_OBJECT_NAME
82 to ASM_FINISH_DECLARE_OBJECT. */
84 int size_directive_output
;
86 /* The last decl for which assemble_variable was called,
87 if it did ASM_DECLARE_OBJECT_NAME.
88 If the last call to assemble_variable didn't do that,
91 tree last_assemble_variable_decl
;
93 /* The following global variable indicates if the first basic block
94 in a function belongs to the cold partition or not. */
96 bool first_function_block_is_cold
;
98 /* We give all constants their own alias set. Perhaps redundant with
99 MEM_READONLY_P, but pre-dates it. */
101 static alias_set_type const_alias_set
;
103 /* Whether we saw any functions with no_split_stack. */
105 static bool saw_no_split_stack
;
107 static const char *strip_reg_name (const char *);
108 static int contains_pointers_p (tree
);
109 #ifdef ASM_OUTPUT_EXTERNAL
110 static bool incorporeal_function_p (tree
);
112 static void decode_addr_const (tree
, struct addr_const
*);
113 static hashval_t
const_desc_hash (const void *);
114 static int const_desc_eq (const void *, const void *);
115 static hashval_t
const_hash_1 (const tree
);
116 static int compare_constant (const tree
, const tree
);
117 static void output_constant_def_contents (rtx
);
118 static void output_addressed_constants (tree
);
119 static unsigned HOST_WIDE_INT
output_constant (tree
, unsigned HOST_WIDE_INT
,
121 static void globalize_decl (tree
);
122 static bool decl_readonly_section_1 (enum section_category
);
123 #ifdef BSS_SECTION_ASM_OP
124 #ifdef ASM_OUTPUT_ALIGNED_BSS
125 static void asm_output_aligned_bss (FILE *, tree
, const char *,
126 unsigned HOST_WIDE_INT
, int)
129 #endif /* BSS_SECTION_ASM_OP */
130 static void mark_weak (tree
);
131 static void output_constant_pool (const char *, tree
);
133 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
134 section
*text_section
;
135 section
*data_section
;
136 section
*readonly_data_section
;
137 section
*sdata_section
;
138 section
*ctors_section
;
139 section
*dtors_section
;
140 section
*bss_section
;
141 section
*sbss_section
;
143 /* Various forms of common section. All are guaranteed to be nonnull. */
144 section
*tls_comm_section
;
145 section
*comm_section
;
146 section
*lcomm_section
;
148 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
150 section
*bss_noswitch_section
;
152 /* The section that holds the main exception table, when known. The section
153 is set either by the target's init_sections hook or by the first call to
154 switch_to_exception_section. */
155 section
*exception_section
;
157 /* The section that holds the DWARF2 frame unwind information, when known.
158 The section is set either by the target's init_sections hook or by the
159 first call to switch_to_eh_frame_section. */
160 section
*eh_frame_section
;
162 /* asm_out_file's current section. This is NULL if no section has yet
163 been selected or if we lose track of what the current section is. */
166 /* True if code for the current function is currently being directed
167 at the cold section. */
168 bool in_cold_section_p
;
170 /* A linked list of all the unnamed sections. */
171 static GTY(()) section
*unnamed_sections
;
173 /* Return a nonzero value if DECL has a section attribute. */
174 #define IN_NAMED_SECTION(DECL) \
175 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
176 && DECL_SECTION_NAME (DECL) != NULL_TREE)
178 /* Hash table of named sections. */
179 static GTY((param_is (section
))) htab_t section_htab
;
181 /* A table of object_blocks, indexed by section. */
182 static GTY((param_is (struct object_block
))) htab_t object_block_htab
;
184 /* The next number to use for internal anchor labels. */
185 static GTY(()) int anchor_labelno
;
187 /* A pool of constants that can be shared between functions. */
188 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
190 /* Helper routines for maintaining section_htab. */
193 section_entry_eq (const void *p1
, const void *p2
)
195 const section
*old
= (const section
*) p1
;
196 const char *new_name
= (const char *) p2
;
198 return strcmp (old
->named
.name
, new_name
) == 0;
202 section_entry_hash (const void *p
)
204 const section
*old
= (const section
*) p
;
205 return htab_hash_string (old
->named
.name
);
208 /* Return a hash value for section SECT. */
211 hash_section (section
*sect
)
213 if (sect
->common
.flags
& SECTION_NAMED
)
214 return htab_hash_string (sect
->named
.name
);
215 return sect
->common
.flags
;
218 /* Helper routines for maintaining object_block_htab. */
221 object_block_entry_eq (const void *p1
, const void *p2
)
223 const struct object_block
*old
= (const struct object_block
*) p1
;
224 const section
*new_section
= (const section
*) p2
;
226 return old
->sect
== new_section
;
230 object_block_entry_hash (const void *p
)
232 const struct object_block
*old
= (const struct object_block
*) p
;
233 return hash_section (old
->sect
);
236 /* Return a new unnamed section with the given fields. */
239 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
244 sect
= ggc_alloc
<section
> ();
245 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
246 sect
->unnamed
.callback
= callback
;
247 sect
->unnamed
.data
= data
;
248 sect
->unnamed
.next
= unnamed_sections
;
250 unnamed_sections
= sect
;
254 /* Return a SECTION_NOSWITCH section with the given fields. */
257 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
261 sect
= ggc_alloc
<section
> ();
262 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
263 sect
->noswitch
.callback
= callback
;
268 /* Return the named section structure associated with NAME. Create
269 a new section with the given fields if no such structure exists. */
272 get_section (const char *name
, unsigned int flags
, tree decl
)
274 section
*sect
, **slot
;
277 htab_find_slot_with_hash (section_htab
, name
,
278 htab_hash_string (name
), INSERT
);
279 flags
|= SECTION_NAMED
;
282 sect
= ggc_alloc
<section
> ();
283 sect
->named
.common
.flags
= flags
;
284 sect
->named
.name
= ggc_strdup (name
);
285 sect
->named
.decl
= decl
;
291 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
292 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
294 /* It is fine if one of the section flags is
295 SECTION_WRITE | SECTION_RELRO and the other has none of these
296 flags (i.e. read-only) in named sections and either the
297 section hasn't been declared yet or has been declared as writable.
298 In that case just make sure the resulting flags are
299 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
301 if (((sect
->common
.flags
^ flags
) & (SECTION_WRITE
| SECTION_RELRO
))
302 == (SECTION_WRITE
| SECTION_RELRO
)
303 && (sect
->common
.flags
304 & ~(SECTION_DECLARED
| SECTION_WRITE
| SECTION_RELRO
))
305 == (flags
& ~(SECTION_WRITE
| SECTION_RELRO
))
306 && ((sect
->common
.flags
& SECTION_DECLARED
) == 0
307 || (sect
->common
.flags
& SECTION_WRITE
)))
309 sect
->common
.flags
|= (SECTION_WRITE
| SECTION_RELRO
);
312 /* Sanity check user variables for flag changes. */
313 if (sect
->named
.decl
!= NULL
314 && DECL_P (sect
->named
.decl
)
315 && decl
!= sect
->named
.decl
)
317 if (decl
!= NULL
&& DECL_P (decl
))
318 error ("%+D causes a section type conflict with %D",
319 decl
, sect
->named
.decl
);
321 error ("section type conflict with %D", sect
->named
.decl
);
322 inform (DECL_SOURCE_LOCATION (sect
->named
.decl
),
323 "%qD was declared here", sect
->named
.decl
);
325 else if (decl
!= NULL
&& DECL_P (decl
))
326 error ("%+D causes a section type conflict", decl
);
328 error ("section type conflict");
329 /* Make sure we don't error about one section multiple times. */
330 sect
->common
.flags
|= SECTION_OVERRIDE
;
336 /* Return true if the current compilation mode benefits from having
337 objects grouped into blocks. */
340 use_object_blocks_p (void)
342 return flag_section_anchors
;
345 /* Return the object_block structure for section SECT. Create a new
346 structure if we haven't created one already. Return null if SECT
349 static struct object_block
*
350 get_block_for_section (section
*sect
)
352 struct object_block
*block
;
358 slot
= htab_find_slot_with_hash (object_block_htab
, sect
,
359 hash_section (sect
), INSERT
);
360 block
= (struct object_block
*) *slot
;
363 block
= ggc_cleared_alloc
<object_block
> ();
370 /* Create a symbol with label LABEL and place it at byte offset
371 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
372 is not yet known. LABEL must be a garbage-collected string. */
375 create_block_symbol (const char *label
, struct object_block
*block
,
376 HOST_WIDE_INT offset
)
381 /* Create the extended SYMBOL_REF. */
382 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
383 symbol
= (rtx
) ggc_internal_alloc (size
);
385 /* Initialize the normal SYMBOL_REF fields. */
386 memset (symbol
, 0, size
);
387 PUT_CODE (symbol
, SYMBOL_REF
);
388 PUT_MODE (symbol
, Pmode
);
389 XSTR (symbol
, 0) = label
;
390 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
392 /* Initialize the block_symbol stuff. */
393 SYMBOL_REF_BLOCK (symbol
) = block
;
394 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
399 /* Return a section with a particular name and with whatever SECTION_*
400 flags section_type_flags deems appropriate. The name of the section
401 is taken from NAME if nonnull, otherwise it is taken from DECL's
402 DECL_SECTION_NAME. DECL is the decl associated with the section
403 (see the section comment for details) and RELOC is as for
404 section_type_flags. */
407 get_named_section (tree decl
, const char *name
, int reloc
)
413 gcc_assert (decl
&& DECL_P (decl
) && DECL_SECTION_NAME (decl
));
414 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
417 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
418 return get_section (name
, flags
, decl
);
421 /* If required, set DECL_SECTION_NAME to a unique name. */
424 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
425 int flag_function_or_data_sections
)
427 if (DECL_SECTION_NAME (decl
) == NULL_TREE
428 && targetm_common
.have_named_sections
429 && (flag_function_or_data_sections
430 || DECL_COMDAT_GROUP (decl
)))
432 targetm
.asm_out
.unique_section (decl
, reloc
);
433 DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
) = true;
437 #ifdef BSS_SECTION_ASM_OP
439 #ifdef ASM_OUTPUT_ALIGNED_BSS
441 /* Utility function for targets to use in implementing
442 ASM_OUTPUT_ALIGNED_BSS.
443 ??? It is believed that this function will work in most cases so such
444 support is localized here. */
447 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
448 const char *name
, unsigned HOST_WIDE_INT size
,
451 switch_to_section (bss_section
);
452 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
453 #ifdef ASM_DECLARE_OBJECT_NAME
454 last_assemble_variable_decl
= decl
;
455 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
457 /* Standard thing is just output label for the object. */
458 ASM_OUTPUT_LABEL (file
, name
);
459 #endif /* ASM_DECLARE_OBJECT_NAME */
460 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
465 #endif /* BSS_SECTION_ASM_OP */
467 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
468 /* Return the hot section for function DECL. Return text_section for
472 hot_function_section (tree decl
)
474 if (decl
!= NULL_TREE
475 && DECL_SECTION_NAME (decl
) != NULL_TREE
476 && targetm_common
.have_named_sections
)
477 return get_named_section (decl
, NULL
, 0);
483 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
486 When DECL_SECTION_NAME is non-NULL and it is implicit section and
487 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
488 concatenate the name with NAMED_SECTION_SUFFIX.
489 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
492 get_named_text_section (tree decl
,
493 const char *text_section_name
,
494 const char *named_section_suffix
)
496 if (decl
&& DECL_SECTION_NAME (decl
))
498 if (named_section_suffix
)
500 tree dsn
= DECL_SECTION_NAME (decl
);
501 const char *stripped_name
;
504 name
= (char *) alloca (TREE_STRING_LENGTH (dsn
) + 1);
505 memcpy (name
, TREE_STRING_POINTER (dsn
),
506 TREE_STRING_LENGTH (dsn
) + 1);
508 stripped_name
= targetm
.strip_name_encoding (name
);
510 buffer
= ACONCAT ((stripped_name
, named_section_suffix
, NULL
));
511 return get_named_section (decl
, buffer
, 0);
513 else if (DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
))
517 /* Do not try to split gnu_linkonce functions. This gets somewhat
519 if (DECL_COMDAT_GROUP (decl
) && !HAVE_COMDAT_GROUP
)
521 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
522 name
= targetm
.strip_name_encoding (name
);
523 return get_named_section (decl
, ACONCAT ((text_section_name
, ".",
529 return get_named_section (decl
, text_section_name
, 0);
532 /* Choose named function section based on its frequency. */
535 default_function_section (tree decl
, enum node_frequency freq
,
536 bool startup
, bool exit
)
538 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
539 /* Old GNU linkers have buggy --gc-section support, which sometimes
540 results in .gcc_except_table* sections being garbage collected. */
542 && DECL_SECTION_NAME (decl
)
543 && DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
))
547 if (!flag_reorder_functions
548 || !targetm_common
.have_named_sections
)
550 /* Startup code should go to startup subsection unless it is
551 unlikely executed (this happens especially with function splitting
552 where we can split away unnecessary parts of static constructors. */
553 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
555 /* If we do have a profile or(and) LTO phase is executed, we do not need
556 these ELF section. */
557 if (!in_lto_p
|| !flag_profile_values
)
558 return get_named_text_section (decl
, ".text.startup", NULL
);
563 /* Similarly for exit. */
564 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
565 return get_named_text_section (decl
, ".text.exit", NULL
);
567 /* Group cold functions together, similarly for hot code. */
570 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
571 return get_named_text_section (decl
, ".text.unlikely", NULL
);
572 case NODE_FREQUENCY_HOT
:
573 /* If we do have a profile or(and) LTO phase is executed, we do not need
574 these ELF section. */
575 if (!in_lto_p
|| !flag_profile_values
)
576 return get_named_text_section (decl
, ".text.hot", NULL
);
582 /* Return the section for function DECL.
584 If DECL is NULL_TREE, return the text section. We can be passed
585 NULL_TREE under some circumstances by dbxout.c at least.
587 If FORCE_COLD is true, return cold function section ignoring
588 the frequency info of cgraph_node. */
591 function_section_1 (tree decl
, bool force_cold
)
593 section
*section
= NULL
;
594 enum node_frequency freq
= NODE_FREQUENCY_NORMAL
;
595 bool startup
= false, exit
= false;
599 struct cgraph_node
*node
= cgraph_get_node (decl
);
603 freq
= node
->frequency
;
604 startup
= node
->only_called_at_startup
;
605 exit
= node
->only_called_at_exit
;
609 freq
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
611 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
612 if (decl
!= NULL_TREE
613 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
615 if (targetm
.asm_out
.function_section
)
616 section
= targetm
.asm_out
.function_section (decl
, freq
,
620 return get_named_section (decl
, NULL
, 0);
623 return targetm
.asm_out
.select_section
624 (decl
, freq
== NODE_FREQUENCY_UNLIKELY_EXECUTED
,
627 if (targetm
.asm_out
.function_section
)
628 section
= targetm
.asm_out
.function_section (decl
, freq
, startup
, exit
);
631 return hot_function_section (decl
);
635 /* Return the section for function DECL.
637 If DECL is NULL_TREE, return the text section. We can be passed
638 NULL_TREE under some circumstances by dbxout.c at least. */
641 function_section (tree decl
)
643 /* Handle cases where function splitting code decides
644 to put function entry point into unlikely executed section
645 despite the fact that the function itself is not cold
646 (i.e. it is called rarely but contains a hot loop that is
647 better to live in hot subsection for the code locality). */
648 return function_section_1 (decl
,
649 first_function_block_is_cold
);
652 /* Return the section for the current function, take IN_COLD_SECTION_P
656 current_function_section (void)
658 return function_section_1 (current_function_decl
, in_cold_section_p
);
661 /* Tell assembler to switch to unlikely-to-be-executed text section. */
664 unlikely_text_section (void)
666 return function_section_1 (current_function_decl
, true);
669 /* When called within a function context, return true if the function
670 has been assigned a cold text section and if SECT is that section.
671 When called outside a function context, return true if SECT is the
672 default cold section. */
675 unlikely_text_section_p (section
*sect
)
677 return sect
== function_section_1 (current_function_decl
, true);
680 /* Return the read-only data section associated with function DECL. */
683 default_function_rodata_section (tree decl
)
685 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
687 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
689 if (DECL_COMDAT_GROUP (decl
) && HAVE_COMDAT_GROUP
)
695 dot
= strchr (name
+ 1, '.');
698 len
= strlen (dot
) + 8;
699 rname
= (char *) alloca (len
);
701 strcpy (rname
, ".rodata");
703 return get_section (rname
, SECTION_LINKONCE
, decl
);
705 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
706 else if (DECL_COMDAT_GROUP (decl
)
707 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
709 size_t len
= strlen (name
) + 1;
710 char *rname
= (char *) alloca (len
);
712 memcpy (rname
, name
, len
);
714 return get_section (rname
, SECTION_LINKONCE
, decl
);
716 /* For .text.foo we want to use .rodata.foo. */
717 else if (flag_function_sections
&& flag_data_sections
718 && strncmp (name
, ".text.", 6) == 0)
720 size_t len
= strlen (name
) + 1;
721 char *rname
= (char *) alloca (len
+ 2);
723 memcpy (rname
, ".rodata", 7);
724 memcpy (rname
+ 7, name
+ 5, len
- 5);
725 return get_section (rname
, 0, decl
);
729 return readonly_data_section
;
732 /* Return the read-only data section associated with function DECL
733 for targets where that section should be always the single
734 readonly data section. */
737 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
739 return readonly_data_section
;
742 /* Return the section to use for string merging. */
745 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
746 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
747 unsigned int flags ATTRIBUTE_UNUSED
)
751 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
752 && TREE_CODE (decl
) == STRING_CST
753 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
755 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
756 && TREE_STRING_LENGTH (decl
) >= len
)
758 enum machine_mode mode
;
759 unsigned int modesize
;
763 const char *prefix
= targetm
.asm_out
.mergeable_rodata_prefix
;
764 char *name
= (char *) alloca (strlen (prefix
) + 30);
766 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
767 modesize
= GET_MODE_BITSIZE (mode
);
768 if (modesize
>= 8 && modesize
<= 256
769 && (modesize
& (modesize
- 1)) == 0)
771 if (align
< modesize
)
774 str
= TREE_STRING_POINTER (decl
);
775 unit
= GET_MODE_SIZE (mode
);
777 /* Check for embedded NUL characters. */
778 for (i
= 0; i
< len
; i
+= unit
)
780 for (j
= 0; j
< unit
; j
++)
781 if (str
[i
+ j
] != '\0')
788 sprintf (name
, "%s.str%d.%d", prefix
,
789 modesize
/ 8, (int) (align
/ 8));
790 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
791 return get_section (name
, flags
, NULL
);
796 return readonly_data_section
;
799 /* Return the section to use for constant merging. */
802 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
803 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
804 unsigned int flags ATTRIBUTE_UNUSED
)
806 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
808 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
814 && (align
& (align
- 1)) == 0)
816 const char *prefix
= targetm
.asm_out
.mergeable_rodata_prefix
;
817 char *name
= (char *) alloca (strlen (prefix
) + 30);
819 sprintf (name
, "%s.cst%d", prefix
, (int) (align
/ 8));
820 flags
|= (align
/ 8) | SECTION_MERGE
;
821 return get_section (name
, flags
, NULL
);
823 return readonly_data_section
;
826 /* Given NAME, a putative register name, discard any customary prefixes. */
829 strip_reg_name (const char *name
)
831 #ifdef REGISTER_PREFIX
832 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
833 name
+= strlen (REGISTER_PREFIX
);
835 if (name
[0] == '%' || name
[0] == '#')
840 /* The user has asked for a DECL to have a particular name. Set (or
841 change) it in such a way that we don't prefix an underscore to
844 set_user_assembler_name (tree decl
, const char *name
)
846 char *starred
= (char *) alloca (strlen (name
) + 2);
848 strcpy (starred
+ 1, name
);
849 change_decl_assembler_name (decl
, get_identifier (starred
));
850 SET_DECL_RTL (decl
, NULL_RTX
);
853 /* Decode an `asm' spec for a declaration as a register name.
854 Return the register number, or -1 if nothing specified,
855 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
856 or -3 if ASMSPEC is `cc' and is not recognized,
857 or -4 if ASMSPEC is `memory' and is not recognized.
858 Accept an exact spelling or a decimal number.
859 Prefixes such as % are optional. */
862 decode_reg_name_and_count (const char *asmspec
, int *pnregs
)
864 /* Presume just one register is clobbered. */
871 /* Get rid of confusing prefixes. */
872 asmspec
= strip_reg_name (asmspec
);
874 /* Allow a decimal number as a "register name". */
875 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
876 if (! ISDIGIT (asmspec
[i
]))
878 if (asmspec
[0] != 0 && i
< 0)
881 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
887 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
889 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
892 #ifdef OVERLAPPING_REGISTER_NAMES
896 const char *const name
;
899 } table
[] = OVERLAPPING_REGISTER_NAMES
;
901 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
903 && ! strcmp (asmspec
, table
[i
].name
))
905 *pnregs
= table
[i
].nregs
;
906 return table
[i
].number
;
909 #endif /* OVERLAPPING_REGISTER_NAMES */
911 #ifdef ADDITIONAL_REGISTER_NAMES
913 static const struct { const char *const name
; const int number
; } table
[]
914 = ADDITIONAL_REGISTER_NAMES
;
916 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
918 && ! strcmp (asmspec
, table
[i
].name
))
919 return table
[i
].number
;
921 #endif /* ADDITIONAL_REGISTER_NAMES */
923 if (!strcmp (asmspec
, "memory"))
926 if (!strcmp (asmspec
, "cc"))
936 decode_reg_name (const char *name
)
939 return decode_reg_name_and_count (name
, &count
);
943 /* Return true if DECL's initializer is suitable for a BSS section. */
946 bss_initializer_p (const_tree decl
)
948 return (DECL_INITIAL (decl
) == NULL
949 || DECL_INITIAL (decl
) == error_mark_node
950 || (flag_zero_initialized_in_bss
951 /* Leave constant zeroes in .rodata so they
953 && !TREE_READONLY (decl
)
954 && initializer_zerop (DECL_INITIAL (decl
))));
957 /* Compute the alignment of variable specified by DECL.
958 DONT_OUTPUT_DATA is from assemble_variable. */
961 align_variable (tree decl
, bool dont_output_data
)
963 unsigned int align
= DECL_ALIGN (decl
);
965 /* In the case for initialing an array whose length isn't specified,
966 where we have not yet been able to do the layout,
967 figure out the proper alignment now. */
968 if (dont_output_data
&& DECL_SIZE (decl
) == 0
969 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
970 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
972 /* Some object file formats have a maximum alignment which they support.
973 In particular, a.out format supports a maximum alignment of 4. */
974 if (align
> MAX_OFILE_ALIGNMENT
)
976 error ("alignment of %q+D is greater than maximum object "
977 "file alignment %d", decl
,
978 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
979 align
= MAX_OFILE_ALIGNMENT
;
982 if (! DECL_USER_ALIGN (decl
))
984 #ifdef DATA_ABI_ALIGNMENT
985 unsigned int data_abi_align
986 = DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
987 /* For backwards compatibility, don't assume the ABI alignment for
989 if (! DECL_THREAD_LOCAL_P (decl
) || data_abi_align
<= BITS_PER_WORD
)
990 align
= data_abi_align
;
993 /* On some machines, it is good to increase alignment sometimes.
994 But as DECL_ALIGN is used both for actually emitting the variable
995 and for code accessing the variable as guaranteed alignment, we
996 can only increase the alignment if it is a performance optimization
997 if the references to it must bind to the current definition. */
998 if (decl_binds_to_current_def_p (decl
)
999 && !DECL_VIRTUAL_P (decl
))
1001 #ifdef DATA_ALIGNMENT
1002 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1003 /* Don't increase alignment too much for TLS variables - TLS space
1005 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1008 #ifdef CONSTANT_ALIGNMENT
1009 if (DECL_INITIAL (decl
) != 0
1010 && DECL_INITIAL (decl
) != error_mark_node
)
1012 unsigned int const_align
1013 = CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1014 /* Don't increase alignment too much for TLS variables - TLS
1015 space is too precious. */
1016 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1017 align
= const_align
;
1023 /* Reset the alignment in case we have made it tighter, so we can benefit
1024 from it in get_pointer_alignment. */
1025 DECL_ALIGN (decl
) = align
;
1028 /* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1029 beyond what align_variable returned. */
1032 get_variable_align (tree decl
)
1034 unsigned int align
= DECL_ALIGN (decl
);
1036 /* For user aligned vars or static vars align_variable already did
1038 if (DECL_USER_ALIGN (decl
) || !TREE_PUBLIC (decl
))
1041 #ifdef DATA_ABI_ALIGNMENT
1042 if (DECL_THREAD_LOCAL_P (decl
))
1043 align
= DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1046 /* For decls that bind to the current definition, align_variable
1047 did also everything, except for not assuming ABI required alignment
1048 of TLS variables. For other vars, increase the alignment here
1049 as an optimization. */
1050 if (!decl_binds_to_current_def_p (decl
))
1052 /* On some machines, it is good to increase alignment sometimes. */
1053 #ifdef DATA_ALIGNMENT
1054 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1055 /* Don't increase alignment too much for TLS variables - TLS space
1057 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1060 #ifdef CONSTANT_ALIGNMENT
1061 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1063 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
1065 /* Don't increase alignment too much for TLS variables - TLS space
1067 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1068 align
= const_align
;
1076 /* Return the section into which the given VAR_DECL or CONST_DECL
1077 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1078 section should be used wherever possible. */
1081 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1083 addr_space_t as
= ADDR_SPACE_GENERIC
;
1085 symtab_node
*snode
= symtab_get_node (decl
);
1087 decl
= symtab_alias_ultimate_target (snode
)->decl
;
1089 if (TREE_TYPE (decl
) != error_mark_node
)
1090 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1092 if (DECL_COMMON (decl
))
1094 /* If the decl has been given an explicit section name, or it resides
1095 in a non-generic address space, then it isn't common, and shouldn't
1096 be handled as such. */
1097 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1098 && ADDR_SPACE_GENERIC_P (as
));
1099 if (DECL_THREAD_LOCAL_P (decl
))
1100 return tls_comm_section
;
1101 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1102 return comm_section
;
1105 if (DECL_INITIAL (decl
) == error_mark_node
)
1106 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1107 else if (DECL_INITIAL (decl
))
1108 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1112 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1113 if (IN_NAMED_SECTION (decl
))
1114 return get_named_section (decl
, NULL
, reloc
);
1116 if (ADDR_SPACE_GENERIC_P (as
)
1117 && !DECL_THREAD_LOCAL_P (decl
)
1118 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1119 && bss_initializer_p (decl
))
1121 if (!TREE_PUBLIC (decl
)
1122 && !((flag_sanitize
& SANITIZE_ADDRESS
)
1123 && asan_protect_global (decl
)))
1124 return lcomm_section
;
1125 if (bss_noswitch_section
)
1126 return bss_noswitch_section
;
1129 return targetm
.asm_out
.select_section (decl
, reloc
,
1130 get_variable_align (decl
));
1133 /* Return the block into which object_block DECL should be placed. */
1135 static struct object_block
*
1136 get_block_for_decl (tree decl
)
1140 if (TREE_CODE (decl
) == VAR_DECL
)
1142 /* The object must be defined in this translation unit. */
1143 if (DECL_EXTERNAL (decl
))
1146 /* There's no point using object blocks for something that is
1147 isolated by definition. */
1148 if (DECL_COMDAT_GROUP (decl
))
1152 /* We can only calculate block offsets if the decl has a known
1154 if (DECL_SIZE_UNIT (decl
) == NULL
)
1156 if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl
)))
1159 /* Find out which section should contain DECL. We cannot put it into
1160 an object block if it requires a standalone definition. */
1161 if (TREE_CODE (decl
) == VAR_DECL
)
1162 align_variable (decl
, 0);
1163 sect
= get_variable_section (decl
, true);
1164 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1167 return get_block_for_section (sect
);
1170 /* Make sure block symbol SYMBOL is in block BLOCK. */
1173 change_symbol_block (rtx symbol
, struct object_block
*block
)
1175 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1177 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1178 SYMBOL_REF_BLOCK (symbol
) = block
;
1182 /* Return true if it is possible to put DECL in an object_block. */
1185 use_blocks_for_decl_p (tree decl
)
1187 struct symtab_node
*snode
;
1189 /* Only data DECLs can be placed into object blocks. */
1190 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
1193 /* Detect decls created by dw2_force_const_mem. Such decls are
1194 special because DECL_INITIAL doesn't specify the decl's true value.
1195 dw2_output_indirect_constants will instead call assemble_variable
1196 with dont_output_data set to 1 and then print the contents itself. */
1197 if (DECL_INITIAL (decl
) == decl
)
1200 /* If this decl is an alias, then we don't want to emit a
1202 if (TREE_CODE (decl
) == VAR_DECL
1203 && (snode
= symtab_get_node (decl
)) != NULL
1207 return targetm
.use_blocks_for_decl_p (decl
);
1210 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1211 have static storage duration. In other words, it should not be an
1212 automatic variable, including PARM_DECLs.
1214 There is, however, one exception: this function handles variables
1215 explicitly placed in a particular register by the user.
1217 This is never called for PARM_DECL nodes. */
1220 make_decl_rtl (tree decl
)
1222 const char *name
= 0;
1226 /* Check that we are not being given an automatic variable. */
1227 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1228 && TREE_CODE (decl
) != RESULT_DECL
);
1230 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1231 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1232 || TREE_STATIC (decl
)
1233 || TREE_PUBLIC (decl
)
1234 || DECL_EXTERNAL (decl
)
1235 || DECL_REGISTER (decl
));
1237 /* And that we were not given a type or a label. */
1238 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1239 && TREE_CODE (decl
) != LABEL_DECL
);
1241 /* For a duplicate declaration, we can be called twice on the
1242 same DECL node. Don't discard the RTL already made. */
1243 if (DECL_RTL_SET_P (decl
))
1245 /* If the old RTL had the wrong mode, fix the mode. */
1246 x
= DECL_RTL (decl
);
1247 if (GET_MODE (x
) != DECL_MODE (decl
))
1248 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1250 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1253 /* ??? Another way to do this would be to maintain a hashed
1254 table of such critters. Instead of adding stuff to a DECL
1255 to give certain attributes to it, we could use an external
1256 hash map from DECL to set of attributes. */
1258 /* Let the target reassign the RTL if it wants.
1259 This is necessary, for example, when one machine specific
1260 decl attribute overrides another. */
1261 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1263 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1264 on the new decl information. */
1266 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1267 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1268 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1273 /* If this variable belongs to the global constant pool, retrieve the
1274 pre-computed RTL or recompute it in LTO mode. */
1275 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1277 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1281 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1283 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1284 && DECL_REGISTER (decl
))
1286 error ("register name not specified for %q+D", decl
);
1288 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1290 const char *asmspec
= name
+1;
1291 enum machine_mode mode
= DECL_MODE (decl
);
1292 reg_number
= decode_reg_name (asmspec
);
1293 /* First detect errors in declaring global registers. */
1294 if (reg_number
== -1)
1295 error ("register name not specified for %q+D", decl
);
1296 else if (reg_number
< 0)
1297 error ("invalid register name for %q+D", decl
);
1298 else if (mode
== BLKmode
)
1299 error ("data type of %q+D isn%'t suitable for a register",
1301 else if (!in_hard_reg_set_p (accessible_reg_set
, mode
, reg_number
))
1302 error ("the register specified for %q+D cannot be accessed"
1303 " by the current target", decl
);
1304 else if (!in_hard_reg_set_p (operand_reg_set
, mode
, reg_number
))
1305 error ("the register specified for %q+D is not general enough"
1306 " to be used as a register variable", decl
);
1307 else if (!HARD_REGNO_MODE_OK (reg_number
, mode
))
1308 error ("register specified for %q+D isn%'t suitable for data type",
1310 /* Now handle properly declared static register variables. */
1315 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1317 DECL_INITIAL (decl
) = 0;
1318 error ("global register variable has initial value");
1320 if (TREE_THIS_VOLATILE (decl
))
1321 warning (OPT_Wvolatile_register_var
,
1322 "optimization may eliminate reads and/or "
1323 "writes to register variables");
1325 /* If the user specified one of the eliminables registers here,
1326 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1327 confused with that register and be eliminated. This usage is
1328 somewhat suspect... */
1330 SET_DECL_RTL (decl
, gen_rtx_raw_REG (mode
, reg_number
));
1331 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1332 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1334 if (TREE_STATIC (decl
))
1336 /* Make this register global, so not usable for anything
1338 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1339 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1340 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1342 nregs
= hard_regno_nregs
[reg_number
][mode
];
1344 globalize_reg (decl
, reg_number
+ --nregs
);
1347 /* As a register variable, it has no section. */
1351 /* Now handle ordinary static variables and functions (in memory).
1352 Also handle vars declared register invalidly. */
1353 else if (name
[0] == '*')
1355 #ifdef REGISTER_PREFIX
1356 if (strlen (REGISTER_PREFIX
) != 0)
1358 reg_number
= decode_reg_name (name
);
1359 if (reg_number
>= 0 || reg_number
== -3)
1360 error ("register name given for non-register variable %q+D", decl
);
1365 /* Specifying a section attribute on a variable forces it into a
1366 non-.bss section, and thus it cannot be common. */
1367 /* FIXME: In general this code should not be necessary because
1368 visibility pass is doing the same work. But notice_global_symbol
1369 is called early and it needs to make DECL_RTL to get the name.
1370 we take care of recomputing the DECL_RTL after visibility is changed. */
1371 if (TREE_CODE (decl
) == VAR_DECL
1372 && DECL_SECTION_NAME (decl
) != NULL_TREE
1373 && DECL_INITIAL (decl
) == NULL_TREE
1374 && DECL_COMMON (decl
))
1375 DECL_COMMON (decl
) = 0;
1377 /* Variables can't be both common and weak. */
1378 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1379 DECL_COMMON (decl
) = 0;
1381 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1382 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1385 enum machine_mode address_mode
= Pmode
;
1386 if (TREE_TYPE (decl
) != error_mark_node
)
1388 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1389 address_mode
= targetm
.addr_space
.address_mode (as
);
1391 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1393 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1394 SET_SYMBOL_REF_DECL (x
, decl
);
1396 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1397 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1398 set_mem_attributes (x
, decl
, 1);
1399 SET_DECL_RTL (decl
, x
);
1401 /* Optionally set flags or add text to the name to record information
1402 such as that it is a function name.
1403 If the name is changed, the macro ASM_OUTPUT_LABELREF
1404 will have to know how to strip this information. */
1405 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1408 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1409 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1413 make_decl_rtl_for_debug (tree decl
)
1415 unsigned int save_aliasing_flag
;
1418 if (DECL_RTL_SET_P (decl
))
1419 return DECL_RTL (decl
);
1421 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1422 call new_alias_set. If running with -fcompare-debug, sometimes
1423 we do not want to create alias sets that will throw the alias
1424 numbers off in the comparison dumps. So... clearing
1425 flag_strict_aliasing will keep new_alias_set() from creating a
1427 save_aliasing_flag
= flag_strict_aliasing
;
1428 flag_strict_aliasing
= 0;
1430 rtl
= DECL_RTL (decl
);
1431 /* Reset DECL_RTL back, as various parts of the compiler expects
1432 DECL_RTL set meaning it is actually going to be output. */
1433 SET_DECL_RTL (decl
, NULL
);
1435 flag_strict_aliasing
= save_aliasing_flag
;
1439 /* Output a string of literal assembler code
1440 for an `asm' keyword used between functions. */
1443 assemble_asm (tree string
)
1448 if (TREE_CODE (string
) == ADDR_EXPR
)
1449 string
= TREE_OPERAND (string
, 0);
1451 p
= TREE_STRING_POINTER (string
);
1452 fprintf (asm_out_file
, "%s%s\n", p
[0] == '\t' ? "" : "\t", p
);
1455 /* Write the address of the entity given by SYMBOL to SEC. */
1457 assemble_addr_to_section (rtx symbol
, section
*sec
)
1459 switch_to_section (sec
);
1460 assemble_align (POINTER_SIZE
);
1461 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1464 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1465 not) section for PRIORITY. */
1467 get_cdtor_priority_section (int priority
, bool constructor_p
)
1471 /* ??? This only works reliably with the GNU linker. */
1472 sprintf (buf
, "%s.%.5u",
1473 constructor_p
? ".ctors" : ".dtors",
1474 /* Invert the numbering so the linker puts us in the proper
1475 order; constructors are run from right to left, and the
1476 linker sorts in increasing order. */
1477 MAX_INIT_PRIORITY
- priority
);
1478 return get_section (buf
, SECTION_WRITE
, NULL
);
1482 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1486 if (priority
!= DEFAULT_INIT_PRIORITY
)
1487 sec
= get_cdtor_priority_section (priority
,
1488 /*constructor_p=*/false);
1490 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1492 assemble_addr_to_section (symbol
, sec
);
1495 #ifdef DTORS_SECTION_ASM_OP
1497 default_dtor_section_asm_out_destructor (rtx symbol
,
1498 int priority ATTRIBUTE_UNUSED
)
1500 assemble_addr_to_section (symbol
, dtors_section
);
1505 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1509 if (priority
!= DEFAULT_INIT_PRIORITY
)
1510 sec
= get_cdtor_priority_section (priority
,
1511 /*constructor_p=*/true);
1513 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1515 assemble_addr_to_section (symbol
, sec
);
1518 #ifdef CTORS_SECTION_ASM_OP
1520 default_ctor_section_asm_out_constructor (rtx symbol
,
1521 int priority ATTRIBUTE_UNUSED
)
1523 assemble_addr_to_section (symbol
, ctors_section
);
1527 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1528 a nonzero value if the constant pool should be output before the
1529 start of the function, or a zero value if the pool should output
1530 after the end of the function. The default is to put it before the
1533 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1534 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1537 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1538 to be output to assembler.
1539 Set first_global_object_name and weak_global_object_name as appropriate. */
1542 notice_global_symbol (tree decl
)
1544 const char **type
= &first_global_object_name
;
1546 if (first_global_object_name
1547 || !TREE_PUBLIC (decl
)
1548 || DECL_EXTERNAL (decl
)
1549 || !DECL_NAME (decl
)
1550 || (TREE_CODE (decl
) != FUNCTION_DECL
1551 && (TREE_CODE (decl
) != VAR_DECL
1552 || (DECL_COMMON (decl
)
1553 && (DECL_INITIAL (decl
) == 0
1554 || DECL_INITIAL (decl
) == error_mark_node
))))
1555 || !MEM_P (DECL_RTL (decl
)))
1558 /* We win when global object is found, but it is useful to know about weak
1559 symbol as well so we can produce nicer unique names. */
1560 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1561 type
= &weak_global_object_name
;
1567 rtx decl_rtl
= DECL_RTL (decl
);
1569 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1570 name
= ggc_strdup (p
);
1576 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1577 current function goes into the cold section, so that targets can use
1578 current_function_section during RTL expansion. DECL describes the
1582 decide_function_section (tree decl
)
1584 first_function_block_is_cold
= false;
1586 if (flag_reorder_blocks_and_partition
)
1587 /* We will decide in assemble_start_function. */
1590 if (DECL_SECTION_NAME (decl
))
1592 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
1593 /* Calls to function_section rely on first_function_block_is_cold
1595 first_function_block_is_cold
= (node
1597 == NODE_FREQUENCY_UNLIKELY_EXECUTED
);
1600 in_cold_section_p
= first_function_block_is_cold
;
1603 /* Output assembler code for the constant pool of a function and associated
1604 with defining the name of the function. DECL describes the function.
1605 NAME is the function's name. For the constant pool, we use the current
1606 constant pool data. */
1609 assemble_start_function (tree decl
, const char *fnname
)
1612 char tmp_label
[100];
1613 bool hot_label_written
= false;
1615 if (flag_reorder_blocks_and_partition
)
1617 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1618 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1619 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1620 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1621 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1622 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1623 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1624 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1629 crtl
->subsections
.hot_section_label
= NULL
;
1630 crtl
->subsections
.cold_section_label
= NULL
;
1631 crtl
->subsections
.hot_section_end_label
= NULL
;
1632 crtl
->subsections
.cold_section_end_label
= NULL
;
1635 /* The following code does not need preprocessing in the assembler. */
1639 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1640 output_constant_pool (fnname
, decl
);
1642 /* Make sure the not and cold text (code) sections are properly
1643 aligned. This is necessary here in the case where the function
1644 has both hot and cold sections, because we don't want to re-set
1645 the alignment when the section switch happens mid-function. */
1647 if (flag_reorder_blocks_and_partition
)
1649 first_function_block_is_cold
= false;
1651 switch_to_section (unlikely_text_section ());
1652 assemble_align (DECL_ALIGN (decl
));
1653 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1655 /* When the function starts with a cold section, we need to explicitly
1656 align the hot section and write out the hot section label.
1657 But if the current function is a thunk, we do not have a CFG. */
1659 && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun
)->next_bb
) == BB_COLD_PARTITION
)
1661 switch_to_section (text_section
);
1662 assemble_align (DECL_ALIGN (decl
));
1663 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1664 hot_label_written
= true;
1665 first_function_block_is_cold
= true;
1667 in_cold_section_p
= first_function_block_is_cold
;
1671 /* Switch to the correct text section for the start of the function. */
1673 switch_to_section (function_section (decl
));
1674 if (flag_reorder_blocks_and_partition
1675 && !hot_label_written
)
1676 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1678 /* Tell assembler to move to target machine's alignment for functions. */
1679 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1682 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1685 /* Handle a user-specified function alignment.
1686 Note that we still need to align to DECL_ALIGN, as above,
1687 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1688 if (! DECL_USER_ALIGN (decl
)
1689 && align_functions_log
> align
1690 && optimize_function_for_speed_p (cfun
))
1692 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1693 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1694 align_functions_log
, align_functions
- 1);
1696 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1700 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1701 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1704 if (!DECL_IGNORED_P (decl
))
1705 (*debug_hooks
->begin_function
) (decl
);
1707 /* Make function name accessible from other files, if appropriate. */
1709 if (TREE_PUBLIC (decl
))
1711 notice_global_symbol (decl
);
1713 globalize_decl (decl
);
1715 maybe_assemble_visibility (decl
);
1718 if (DECL_PRESERVE_P (decl
))
1719 targetm
.asm_out
.mark_decl_preserved (fnname
);
1721 /* Do any machine/system dependent processing of the function name. */
1722 #ifdef ASM_DECLARE_FUNCTION_NAME
1723 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1725 /* Standard thing is just output label for the function. */
1726 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1727 #endif /* ASM_DECLARE_FUNCTION_NAME */
1729 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1730 saw_no_split_stack
= true;
1733 /* Output assembler code associated with defining the size of the
1734 function. DECL describes the function. NAME is the function's name. */
1737 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1739 #ifdef ASM_DECLARE_FUNCTION_SIZE
1740 /* We could have switched section in the middle of the function. */
1741 if (flag_reorder_blocks_and_partition
)
1742 switch_to_section (function_section (decl
));
1743 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1745 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1747 output_constant_pool (fnname
, decl
);
1748 switch_to_section (function_section (decl
)); /* need to switch back */
1750 /* Output labels for end of hot/cold text sections (to be used by
1752 if (flag_reorder_blocks_and_partition
)
1754 section
*save_text_section
;
1756 save_text_section
= in_section
;
1757 switch_to_section (unlikely_text_section ());
1758 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1759 if (first_function_block_is_cold
)
1760 switch_to_section (text_section
);
1762 switch_to_section (function_section (decl
));
1763 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1764 switch_to_section (save_text_section
);
1768 /* Assemble code to leave SIZE bytes of zeros. */
1771 assemble_zeros (unsigned HOST_WIDE_INT size
)
1773 /* Do no output if -fsyntax-only. */
1774 if (flag_syntax_only
)
1777 #ifdef ASM_NO_SKIP_IN_TEXT
1778 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1779 so we must output 0s explicitly in the text section. */
1780 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1782 unsigned HOST_WIDE_INT i
;
1783 for (i
= 0; i
< size
; i
++)
1784 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1789 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1792 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1795 assemble_align (int align
)
1797 if (align
> BITS_PER_UNIT
)
1799 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1803 /* Assemble a string constant with the specified C string as contents. */
1806 assemble_string (const char *p
, int size
)
1811 /* If the string is very long, split it up. */
1815 int thissize
= size
- pos
;
1816 if (thissize
> maximum
)
1819 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1827 /* A noswitch_section_callback for lcomm_section. */
1830 emit_local (tree decl ATTRIBUTE_UNUSED
,
1831 const char *name ATTRIBUTE_UNUSED
,
1832 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1833 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1835 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1836 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1837 size
, DECL_ALIGN (decl
));
1839 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1840 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1843 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1848 /* A noswitch_section_callback for bss_noswitch_section. */
1850 #if defined ASM_OUTPUT_ALIGNED_BSS
1852 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1853 const char *name ATTRIBUTE_UNUSED
,
1854 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1855 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1857 #if defined ASM_OUTPUT_ALIGNED_BSS
1858 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
,
1859 get_variable_align (decl
));
1865 /* A noswitch_section_callback for comm_section. */
1868 emit_common (tree decl ATTRIBUTE_UNUSED
,
1869 const char *name ATTRIBUTE_UNUSED
,
1870 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1871 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1873 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1874 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1875 size
, get_variable_align (decl
));
1877 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1878 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
1879 get_variable_align (decl
));
1882 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1887 /* A noswitch_section_callback for tls_comm_section. */
1890 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1891 const char *name ATTRIBUTE_UNUSED
,
1892 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1893 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1895 #ifdef ASM_OUTPUT_TLS_COMMON
1896 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1899 sorry ("thread-local COMMON data not implemented");
1904 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1905 NAME is the name of DECL's SYMBOL_REF. */
1908 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
,
1911 unsigned HOST_WIDE_INT size
, rounded
;
1913 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
1916 if ((flag_sanitize
& SANITIZE_ADDRESS
) && asan_protect_global (decl
))
1917 size
+= asan_red_zone_size (size
);
1919 /* Don't allocate zero bytes of common,
1920 since that means "undefined external" in the linker. */
1924 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1925 so that each uninitialized object starts on such a boundary. */
1926 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1927 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1928 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1930 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
1931 && (unsigned HOST_WIDE_INT
) (align
/ BITS_PER_UNIT
) > rounded
)
1932 error ("requested alignment for %q+D is greater than "
1933 "implemented alignment of %wu", decl
, rounded
);
1936 /* A subroutine of assemble_variable. Output the label and contents of
1937 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1938 is as for assemble_variable. */
1941 assemble_variable_contents (tree decl
, const char *name
,
1942 bool dont_output_data
)
1944 /* Do any machine/system dependent processing of the object. */
1945 #ifdef ASM_DECLARE_OBJECT_NAME
1946 last_assemble_variable_decl
= decl
;
1947 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1949 /* Standard thing is just output label for the object. */
1950 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1951 #endif /* ASM_DECLARE_OBJECT_NAME */
1953 if (!dont_output_data
)
1955 if (DECL_INITIAL (decl
)
1956 && DECL_INITIAL (decl
) != error_mark_node
1957 && !initializer_zerop (DECL_INITIAL (decl
)))
1958 /* Output the actual data. */
1959 output_constant (DECL_INITIAL (decl
),
1960 tree_to_uhwi (DECL_SIZE_UNIT (decl
)),
1961 get_variable_align (decl
));
1963 /* Leave space for it. */
1964 assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl
)));
1968 /* Assemble everything that is needed for a variable or function declaration.
1969 Not used for automatic variables, and not used for function definitions.
1970 Should not be called for variables of incomplete structure type.
1972 TOP_LEVEL is nonzero if this variable has file scope.
1973 AT_END is nonzero if this is the special handling, at end of compilation,
1974 to define things that have had only tentative definitions.
1975 DONT_OUTPUT_DATA if nonzero means don't actually output the
1976 initial value (that will be done by the caller). */
1979 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
1980 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
1983 rtx decl_rtl
, symbol
;
1986 bool asan_protected
= false;
1988 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1989 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
1991 /* Emulated TLS had better not get this far. */
1992 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
1994 last_assemble_variable_decl
= 0;
1996 /* Normally no need to say anything here for external references,
1997 since assemble_external is called by the language-specific code
1998 when a declaration is first seen. */
2000 if (DECL_EXTERNAL (decl
))
2003 /* Do nothing for global register variables. */
2004 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2006 TREE_ASM_WRITTEN (decl
) = 1;
2010 /* If type was incomplete when the variable was declared,
2011 see if it is complete now. */
2013 if (DECL_SIZE (decl
) == 0)
2014 layout_decl (decl
, 0);
2016 /* Still incomplete => don't allocate it; treat the tentative defn
2017 (which is what it must have been) as an `extern' reference. */
2019 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2021 error ("storage size of %q+D isn%'t known", decl
);
2022 TREE_ASM_WRITTEN (decl
) = 1;
2026 /* The first declaration of a variable that comes through this function
2027 decides whether it is global (in C, has external linkage)
2028 or local (in C, has internal linkage). So do nothing more
2029 if this function has already run. */
2031 if (TREE_ASM_WRITTEN (decl
))
2034 /* Make sure targetm.encode_section_info is invoked before we set
2036 decl_rtl
= DECL_RTL (decl
);
2038 TREE_ASM_WRITTEN (decl
) = 1;
2040 /* Do no output if -fsyntax-only. */
2041 if (flag_syntax_only
)
2044 if (! dont_output_data
2045 && ! valid_constant_size_p (DECL_SIZE_UNIT (decl
)))
2047 error ("size of variable %q+D is too large", decl
);
2051 gcc_assert (MEM_P (decl_rtl
));
2052 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2053 symbol
= XEXP (decl_rtl
, 0);
2055 /* If this symbol belongs to the tree constant pool, output the constant
2056 if it hasn't already been written. */
2057 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
2059 tree decl
= SYMBOL_REF_DECL (symbol
);
2060 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2061 output_constant_def_contents (symbol
);
2067 name
= XSTR (symbol
, 0);
2068 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2069 notice_global_symbol (decl
);
2071 /* Compute the alignment of this data. */
2073 align_variable (decl
, dont_output_data
);
2075 if ((flag_sanitize
& SANITIZE_ADDRESS
)
2076 && asan_protect_global (decl
))
2078 asan_protected
= true;
2079 DECL_ALIGN (decl
) = MAX (DECL_ALIGN (decl
),
2080 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
2083 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2085 align
= get_variable_align (decl
);
2087 if (TREE_PUBLIC (decl
))
2088 maybe_assemble_visibility (decl
);
2090 if (DECL_PRESERVE_P (decl
))
2091 targetm
.asm_out
.mark_decl_preserved (name
);
2093 /* First make the assembler name(s) global if appropriate. */
2094 sect
= get_variable_section (decl
, false);
2095 if (TREE_PUBLIC (decl
)
2096 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2097 globalize_decl (decl
);
2099 /* Output any data that we will need to use the address of. */
2100 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2101 output_addressed_constants (DECL_INITIAL (decl
));
2103 /* dbxout.c needs to know this. */
2104 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2105 DECL_IN_TEXT_SECTION (decl
) = 1;
2107 /* If the decl is part of an object_block, make sure that the decl
2108 has been positioned within its block, but do not write out its
2109 definition yet. output_object_blocks will do that later. */
2110 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2112 gcc_assert (!dont_output_data
);
2113 place_block_symbol (symbol
);
2115 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2116 assemble_noswitch_variable (decl
, name
, sect
, align
);
2119 /* The following bit of code ensures that vtable_map
2120 variables are not only in the comdat section, but that
2121 each variable has its own unique comdat name. If this
2122 code is removed, the variables end up in the same section
2123 with a single comdat name.
2125 FIXME: resolve_unique_section needs to deal better with
2126 decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
2127 that is fixed, this if-else statement can be replaced with
2128 a single call to "switch_to_section (sect)". */
2129 if (sect
->named
.name
2130 && (strcmp (sect
->named
.name
, ".vtable_map_vars") == 0))
2132 #if defined (OBJECT_FORMAT_ELF)
2133 targetm
.asm_out
.named_section (sect
->named
.name
,
2134 sect
->named
.common
.flags
2139 switch_to_section (sect
);
2143 switch_to_section (sect
);
2144 if (align
> BITS_PER_UNIT
)
2145 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2146 assemble_variable_contents (decl
, name
, dont_output_data
);
2149 unsigned HOST_WIDE_INT
int size
2150 = tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2151 assemble_zeros (asan_red_zone_size (size
));
2157 /* Given a function declaration (FN_DECL), this function assembles the
2158 function into the .preinit_array section. */
2161 assemble_vtv_preinit_initializer (tree fn_decl
)
2164 unsigned flags
= SECTION_WRITE
;
2165 rtx symbol
= XEXP (DECL_RTL (fn_decl
), 0);
2167 flags
|= SECTION_NOTYPE
;
2168 sect
= get_section (".preinit_array", flags
, fn_decl
);
2169 switch_to_section (sect
);
2170 assemble_addr_to_section (symbol
, sect
);
2173 /* Return 1 if type TYPE contains any pointers. */
2176 contains_pointers_p (tree type
)
2178 switch (TREE_CODE (type
))
2181 case REFERENCE_TYPE
:
2182 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2183 so I'll play safe and return 1. */
2189 case QUAL_UNION_TYPE
:
2192 /* For a type that has fields, see if the fields have pointers. */
2193 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
2194 if (TREE_CODE (fields
) == FIELD_DECL
2195 && contains_pointers_p (TREE_TYPE (fields
)))
2201 /* An array type contains pointers if its element type does. */
2202 return contains_pointers_p (TREE_TYPE (type
));
2209 /* We delay assemble_external processing until
2210 the compilation unit is finalized. This is the best we can do for
2211 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2212 it all the way to final. See PR 17982 for further discussion. */
2213 static GTY(()) tree pending_assemble_externals
;
2215 #ifdef ASM_OUTPUT_EXTERNAL
2216 /* Some targets delay some output to final using TARGET_ASM_FILE_END.
2217 As a result, assemble_external can be called after the list of externals
2218 is processed and the pointer set destroyed. */
2219 static bool pending_assemble_externals_processed
;
2221 /* Avoid O(external_decls**2) lookups in the pending_assemble_externals
2222 TREE_LIST in assemble_external. */
2223 static struct pointer_set_t
*pending_assemble_externals_set
;
2225 /* True if DECL is a function decl for which no out-of-line copy exists.
2226 It is assumed that DECL's assembler name has been set. */
2229 incorporeal_function_p (tree decl
)
2231 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2235 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2236 && (DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
2237 || DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA_WITH_ALIGN
))
2240 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2241 /* Atomic or sync builtins which have survived this far will be
2242 resolved externally and therefore are not incorporeal. */
2243 if (strncmp (name
, "__builtin_", 10) == 0)
2249 /* Actually do the tests to determine if this is necessary, and invoke
2250 ASM_OUTPUT_EXTERNAL. */
2252 assemble_external_real (tree decl
)
2254 rtx rtl
= DECL_RTL (decl
);
2256 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2257 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2258 && !incorporeal_function_p (decl
))
2260 /* Some systems do require some output. */
2261 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2262 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2268 process_pending_assemble_externals (void)
2270 #ifdef ASM_OUTPUT_EXTERNAL
2272 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2273 assemble_external_real (TREE_VALUE (list
));
2275 pending_assemble_externals
= 0;
2276 pending_assemble_externals_processed
= true;
2277 pointer_set_destroy (pending_assemble_externals_set
);
2281 /* This TREE_LIST contains any weak symbol declarations waiting
2283 static GTY(()) tree weak_decls
;
2285 /* Output something to declare an external symbol to the assembler,
2286 and qualifiers such as weakness. (Most assemblers don't need
2287 extern declaration, so we normally output nothing.) Do nothing if
2288 DECL is not external. */
2291 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2293 /* Make sure that the ASM_OUT_FILE is open.
2294 If it's not, we should not be calling this function. */
2295 gcc_assert (asm_out_file
);
2297 /* In a perfect world, the following condition would be true.
2298 Sadly, the Java and Go front ends emit assembly *from the front end*,
2299 bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2301 /* This function should only be called if we are expanding, or have
2303 Ideally, only final.c would be calling this function, but it is
2304 not clear whether that would break things somehow. See PR 17982
2305 for further discussion. */
2306 gcc_assert (cgraph_state
== CGRAPH_STATE_EXPANSION
2307 || cgraph_state
== CGRAPH_STATE_FINISHED
);
2310 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2313 /* We want to output annotation for weak and external symbols at
2314 very last to check if they are references or not. */
2316 if (TARGET_SUPPORTS_WEAK
2318 /* TREE_STATIC is a weird and abused creature which is not
2319 generally the right test for whether an entity has been
2320 locally emitted, inlined or otherwise not-really-extern, but
2321 for declarations that can be weak, it happens to be
2323 && !TREE_STATIC (decl
)
2324 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2325 && value_member (decl
, weak_decls
) == NULL_TREE
)
2326 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2328 #ifdef ASM_OUTPUT_EXTERNAL
2329 if (pending_assemble_externals_processed
)
2331 assemble_external_real (decl
);
2335 if (! pointer_set_insert (pending_assemble_externals_set
, decl
))
2336 pending_assemble_externals
= tree_cons (NULL
, decl
,
2337 pending_assemble_externals
);
2341 /* Similar, for calling a library function FUN. */
2344 assemble_external_libcall (rtx fun
)
2346 /* Declare library function name external when first used, if nec. */
2347 if (! SYMBOL_REF_USED (fun
))
2349 SYMBOL_REF_USED (fun
) = 1;
2350 targetm
.asm_out
.external_libcall (fun
);
2354 /* Assemble a label named NAME. */
2357 assemble_label (FILE *file
, const char *name
)
2359 ASM_OUTPUT_LABEL (file
, name
);
2362 /* Set the symbol_referenced flag for ID. */
2364 mark_referenced (tree id
)
2366 TREE_SYMBOL_REFERENCED (id
) = 1;
2369 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2371 mark_decl_referenced (tree decl
)
2373 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2375 /* Extern inline functions don't become needed when referenced.
2376 If we know a method will be emitted in other TU and no new
2377 functions can be marked reachable, just use the external
2379 struct cgraph_node
*node
= cgraph_get_create_node (decl
);
2380 if (!DECL_EXTERNAL (decl
)
2381 && !node
->definition
)
2382 cgraph_mark_force_output_node (node
);
2384 else if (TREE_CODE (decl
) == VAR_DECL
)
2386 varpool_node
*node
= varpool_node_for_decl (decl
);
2387 /* C++ frontend use mark_decl_references to force COMDAT variables
2388 to be output that might appear dead otherwise. */
2389 node
->force_output
= true;
2391 /* else do nothing - we can get various sorts of CST nodes here,
2392 which do not need to be marked. */
2396 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2397 until we find an identifier that is not itself a transparent alias.
2398 Modify the alias passed to it by reference (and all aliases on the
2399 way to the ultimate target), such that they do not have to be
2400 followed again, and return the ultimate target of the alias
2404 ultimate_transparent_alias_target (tree
*alias
)
2406 tree target
= *alias
;
2408 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2410 gcc_assert (TREE_CHAIN (target
));
2411 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2412 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2413 && ! TREE_CHAIN (target
));
2420 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2421 starts with a *, the rest of NAME is output verbatim. Otherwise
2422 NAME is transformed in a target-specific way (usually by the
2423 addition of an underscore). */
2426 assemble_name_raw (FILE *file
, const char *name
)
2429 fputs (&name
[1], file
);
2431 ASM_OUTPUT_LABELREF (file
, name
);
2434 /* Like assemble_name_raw, but should be used when NAME might refer to
2435 an entity that is also represented as a tree (like a function or
2436 variable). If NAME does refer to such an entity, that entity will
2437 be marked as referenced. */
2440 assemble_name (FILE *file
, const char *name
)
2442 const char *real_name
;
2445 real_name
= targetm
.strip_name_encoding (name
);
2447 id
= maybe_get_identifier (real_name
);
2452 mark_referenced (id
);
2453 ultimate_transparent_alias_target (&id
);
2455 name
= IDENTIFIER_POINTER (id
);
2456 gcc_assert (! TREE_CHAIN (id
));
2459 assemble_name_raw (file
, name
);
2462 /* Allocate SIZE bytes writable static space with a gensym name
2463 and return an RTX to refer to its address. */
2466 assemble_static_space (unsigned HOST_WIDE_INT size
)
2469 const char *namestring
;
2472 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2474 namestring
= ggc_strdup (name
);
2476 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2477 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2479 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2480 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2483 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2484 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2487 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2488 so that each uninitialized object starts on such a boundary. */
2489 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2490 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2491 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2492 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2493 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2494 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2501 /* Assemble the static constant template for function entry trampolines.
2502 This is done at most once per compilation.
2503 Returns an RTX for the address of the template. */
2505 static GTY(()) rtx initial_trampoline
;
2508 assemble_trampoline_template (void)
2515 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2517 if (initial_trampoline
)
2518 return initial_trampoline
;
2520 /* By default, put trampoline templates in read-only data section. */
2522 #ifdef TRAMPOLINE_SECTION
2523 switch_to_section (TRAMPOLINE_SECTION
);
2525 switch_to_section (readonly_data_section
);
2528 /* Write the assembler code to define one. */
2529 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2531 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2533 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2534 targetm
.asm_out
.trampoline_template (asm_out_file
);
2536 /* Record the rtl to refer to it. */
2537 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2538 name
= ggc_strdup (label
);
2539 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2540 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2542 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2543 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2544 set_mem_size (initial_trampoline
, TRAMPOLINE_SIZE
);
2546 return initial_trampoline
;
2549 /* A and B are either alignments or offsets. Return the minimum alignment
2550 that may be assumed after adding the two together. */
2552 static inline unsigned
2553 min_align (unsigned int a
, unsigned int b
)
2555 return (a
| b
) & -(a
| b
);
2558 /* Return the assembler directive for creating a given kind of integer
2559 object. SIZE is the number of bytes in the object and ALIGNED_P
2560 indicates whether it is known to be aligned. Return NULL if the
2561 assembly dialect has no such directive.
2563 The returned string should be printed at the start of a new line and
2564 be followed immediately by the object's initial value. */
2567 integer_asm_op (int size
, int aligned_p
)
2569 struct asm_int_op
*ops
;
2572 ops
= &targetm
.asm_out
.aligned_op
;
2574 ops
= &targetm
.asm_out
.unaligned_op
;
2579 return targetm
.asm_out
.byte_op
;
2593 /* Use directive OP to assemble an integer object X. Print OP at the
2594 start of the line, followed immediately by the value of X. */
2597 assemble_integer_with_op (const char *op
, rtx x
)
2599 fputs (op
, asm_out_file
);
2600 output_addr_const (asm_out_file
, x
);
2601 fputc ('\n', asm_out_file
);
2604 /* The default implementation of the asm_out.integer target hook. */
2607 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2608 unsigned int size ATTRIBUTE_UNUSED
,
2609 int aligned_p ATTRIBUTE_UNUSED
)
2611 const char *op
= integer_asm_op (size
, aligned_p
);
2612 /* Avoid GAS bugs for large values. Specifically negative values whose
2613 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2614 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2616 return op
&& (assemble_integer_with_op (op
, x
), true);
2619 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2620 the alignment of the integer in bits. Return 1 if we were able to output
2621 the constant, otherwise 0. We must be able to output the constant,
2622 if FORCE is nonzero. */
2625 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2629 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2631 /* See if the target hook can handle this kind of object. */
2632 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2635 /* If the object is a multi-byte one, try splitting it up. Split
2636 it into words it if is multi-word, otherwise split it into bytes. */
2639 enum machine_mode omode
, imode
;
2640 unsigned int subalign
;
2641 unsigned int subsize
, i
;
2642 enum mode_class mclass
;
2644 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2645 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2646 if (GET_CODE (x
) == CONST_FIXED
)
2647 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2651 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2652 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2654 for (i
= 0; i
< size
; i
+= subsize
)
2656 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2657 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2663 /* If we've printed some of it, but not all of it, there's no going
2668 gcc_assert (!force
);
2674 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2676 long data
[4] = {0, 0, 0, 0};
2678 int bitsize
, nelts
, nunits
, units_per
;
2680 /* This is hairy. We have a quantity of known size. real_to_target
2681 will put it into an array of *host* longs, 32 bits per element
2682 (even if long is more than 32 bits). We need to determine the
2683 number of array elements that are occupied (nelts) and the number
2684 of *target* min-addressable units that will be occupied in the
2685 object file (nunits). We cannot assume that 32 divides the
2686 mode's bitsize (size * BITS_PER_UNIT) evenly.
2688 size * BITS_PER_UNIT is used here to make sure that padding bits
2689 (which might appear at either end of the value; real_to_target
2690 will include the padding bits in its output array) are included. */
2692 nunits
= GET_MODE_SIZE (mode
);
2693 bitsize
= nunits
* BITS_PER_UNIT
;
2694 nelts
= CEIL (bitsize
, 32);
2695 units_per
= 32 / BITS_PER_UNIT
;
2697 real_to_target (data
, &d
, mode
);
2699 /* Put out the first word with the specified alignment. */
2700 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2701 nunits
-= units_per
;
2703 /* Subsequent words need only 32-bit alignment. */
2704 align
= min_align (align
, 32);
2706 for (i
= 1; i
< nelts
; i
++)
2708 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2709 nunits
-= units_per
;
2713 /* Given an expression EXP with a constant value,
2714 reduce it to the sum of an assembler symbol and an integer.
2715 Store them both in the structure *VALUE.
2716 EXP must be reducible. */
2720 HOST_WIDE_INT offset
;
2724 decode_addr_const (tree exp
, struct addr_const
*value
)
2726 tree target
= TREE_OPERAND (exp
, 0);
2732 if (TREE_CODE (target
) == COMPONENT_REF
2733 && tree_fits_shwi_p (byte_position (TREE_OPERAND (target
, 1))))
2735 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2736 target
= TREE_OPERAND (target
, 0);
2738 else if (TREE_CODE (target
) == ARRAY_REF
2739 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2741 offset
+= (tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (target
)))
2742 * tree_to_shwi (TREE_OPERAND (target
, 1)));
2743 target
= TREE_OPERAND (target
, 0);
2745 else if (TREE_CODE (target
) == MEM_REF
2746 && TREE_CODE (TREE_OPERAND (target
, 0)) == ADDR_EXPR
)
2748 offset
+= mem_ref_offset (target
).to_short_addr ();
2749 target
= TREE_OPERAND (TREE_OPERAND (target
, 0), 0);
2751 else if (TREE_CODE (target
) == INDIRECT_REF
2752 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2753 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2755 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2760 switch (TREE_CODE (target
))
2764 x
= DECL_RTL (target
);
2768 x
= gen_rtx_MEM (FUNCTION_MODE
,
2769 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2778 x
= output_constant_def (target
, 1);
2785 gcc_assert (MEM_P (x
));
2789 value
->offset
= offset
;
2793 static GTY((param_is (struct constant_descriptor_tree
)))
2794 htab_t const_desc_htab
;
2796 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2798 /* Constant pool accessor function. */
2801 constant_pool_htab (void)
2803 return const_desc_htab
;
2806 /* Compute a hash code for a constant expression. */
2809 const_desc_hash (const void *ptr
)
2811 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2815 const_hash_1 (const tree exp
)
2820 enum tree_code code
= TREE_CODE (exp
);
2822 /* Either set P and LEN to the address and len of something to hash and
2823 exit the switch or return a value. */
2828 p
= (char *) &TREE_INT_CST_ELT (exp
, 0);
2829 len
= TREE_INT_CST_NUNITS (exp
) * sizeof (HOST_WIDE_INT
);
2833 return real_hash (TREE_REAL_CST_PTR (exp
));
2836 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2839 p
= TREE_STRING_POINTER (exp
);
2840 len
= TREE_STRING_LENGTH (exp
);
2844 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2845 + const_hash_1 (TREE_IMAGPART (exp
)));
2851 hi
= 7 + VECTOR_CST_NELTS (exp
);
2853 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
2854 hi
= hi
* 563 + const_hash_1 (VECTOR_CST_ELT (exp
, i
));
2861 unsigned HOST_WIDE_INT idx
;
2864 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2866 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2868 hi
= hi
* 603 + const_hash_1 (value
);
2876 struct addr_const value
;
2878 decode_addr_const (exp
, &value
);
2879 switch (GET_CODE (value
.base
))
2882 /* Don't hash the address of the SYMBOL_REF;
2883 only use the offset and the symbol name. */
2885 p
= XSTR (value
.base
, 0);
2886 for (i
= 0; p
[i
] != 0; i
++)
2887 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2891 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2901 case POINTER_PLUS_EXPR
:
2903 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2904 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2907 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2910 /* A language specific constant. Just hash the code. */
2914 /* Compute hashing function. */
2916 for (i
= 0; i
< len
; i
++)
2917 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2922 /* Wrapper of compare_constant, for the htab interface. */
2924 const_desc_eq (const void *p1
, const void *p2
)
2926 const struct constant_descriptor_tree
*const c1
2927 = (const struct constant_descriptor_tree
*) p1
;
2928 const struct constant_descriptor_tree
*const c2
2929 = (const struct constant_descriptor_tree
*) p2
;
2930 if (c1
->hash
!= c2
->hash
)
2932 return compare_constant (c1
->value
, c2
->value
);
2935 /* Compare t1 and t2, and return 1 only if they are known to result in
2936 the same bit pattern on output. */
2939 compare_constant (const tree t1
, const tree t2
)
2941 enum tree_code typecode
;
2943 if (t1
== NULL_TREE
)
2944 return t2
== NULL_TREE
;
2945 if (t2
== NULL_TREE
)
2948 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2951 switch (TREE_CODE (t1
))
2954 /* Integer constants are the same only if the same width of type. */
2955 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2957 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2959 return tree_int_cst_equal (t1
, t2
);
2962 /* Real constants are the same only if the same width of type. */
2963 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2966 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2969 /* Fixed constants are the same only if the same width of type. */
2970 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2973 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
2976 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2979 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2980 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2981 TREE_STRING_LENGTH (t1
)));
2984 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2985 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2991 if (VECTOR_CST_NELTS (t1
) != VECTOR_CST_NELTS (t2
))
2994 for (i
= 0; i
< VECTOR_CST_NELTS (t1
); ++i
)
2995 if (!compare_constant (VECTOR_CST_ELT (t1
, i
),
2996 VECTOR_CST_ELT (t2
, i
)))
3004 vec
<constructor_elt
, va_gc
> *v1
, *v2
;
3005 unsigned HOST_WIDE_INT idx
;
3007 typecode
= TREE_CODE (TREE_TYPE (t1
));
3008 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3011 if (typecode
== ARRAY_TYPE
)
3013 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3014 /* For arrays, check that the sizes all match. */
3015 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3017 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
3022 /* For record and union constructors, require exact type
3024 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3028 v1
= CONSTRUCTOR_ELTS (t1
);
3029 v2
= CONSTRUCTOR_ELTS (t2
);
3030 if (vec_safe_length (v1
) != vec_safe_length (v2
))
3033 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
3035 constructor_elt
*c1
= &(*v1
)[idx
];
3036 constructor_elt
*c2
= &(*v2
)[idx
];
3038 /* Check that each value is the same... */
3039 if (!compare_constant (c1
->value
, c2
->value
))
3041 /* ... and that they apply to the same fields! */
3042 if (typecode
== ARRAY_TYPE
)
3044 if (!compare_constant (c1
->index
, c2
->index
))
3049 if (c1
->index
!= c2
->index
)
3060 struct addr_const value1
, value2
;
3064 decode_addr_const (t1
, &value1
);
3065 decode_addr_const (t2
, &value2
);
3067 if (value1
.offset
!= value2
.offset
)
3070 code
= GET_CODE (value1
.base
);
3071 if (code
!= GET_CODE (value2
.base
))
3077 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3081 ret
= (CODE_LABEL_NUMBER (XEXP (value1
.base
, 0))
3082 == CODE_LABEL_NUMBER (XEXP (value2
.base
, 0)));
3092 case POINTER_PLUS_EXPR
:
3095 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3096 && compare_constant (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3099 case VIEW_CONVERT_EXPR
:
3100 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3109 /* Return the section into which constant EXP should be placed. */
3112 get_constant_section (tree exp
, unsigned int align
)
3114 return targetm
.asm_out
.select_section (exp
,
3115 compute_reloc_for_constant (exp
),
3119 /* Return the size of constant EXP in bytes. */
3121 static HOST_WIDE_INT
3122 get_constant_size (tree exp
)
3126 size
= int_size_in_bytes (TREE_TYPE (exp
));
3127 if (TREE_CODE (exp
) == STRING_CST
)
3128 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3132 /* Subroutine of output_constant_def:
3133 No constant equal to EXP is known to have been output.
3134 Make a constant descriptor to enter EXP in the hash table.
3135 Assign the label number and construct RTL to refer to the
3136 constant's location in memory.
3137 Caller is responsible for updating the hash table. */
3139 static struct constant_descriptor_tree
*
3140 build_constant_desc (tree exp
)
3142 struct constant_descriptor_tree
*desc
;
3148 desc
= ggc_alloc
<constant_descriptor_tree
> ();
3151 /* Create a string containing the label name, in LABEL. */
3152 labelno
= const_labelno
++;
3153 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3155 /* Construct the VAR_DECL associated with the constant. */
3156 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3158 DECL_ARTIFICIAL (decl
) = 1;
3159 DECL_IGNORED_P (decl
) = 1;
3160 TREE_READONLY (decl
) = 1;
3161 TREE_STATIC (decl
) = 1;
3162 TREE_ADDRESSABLE (decl
) = 1;
3163 /* We don't set the RTL yet as this would cause varpool to assume that the
3164 variable is referenced. Moreover, it would just be dropped in LTO mode.
3165 Instead we set the flag that will be recognized in make_decl_rtl. */
3166 DECL_IN_CONSTANT_POOL (decl
) = 1;
3167 DECL_INITIAL (decl
) = desc
->value
;
3168 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3169 architectures so use DATA_ALIGNMENT as well, except for strings. */
3170 if (TREE_CODE (exp
) == STRING_CST
)
3172 #ifdef CONSTANT_ALIGNMENT
3173 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
3177 align_variable (decl
, 0);
3179 /* Now construct the SYMBOL_REF and the MEM. */
3180 if (use_object_blocks_p ())
3182 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
3183 symbol
= create_block_symbol (ggc_strdup (label
),
3184 get_block_for_section (sect
), -1);
3187 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3188 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3189 SET_SYMBOL_REF_DECL (symbol
, decl
);
3190 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3192 rtl
= gen_const_mem (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3193 set_mem_attributes (rtl
, exp
, 1);
3194 set_mem_alias_set (rtl
, 0);
3195 set_mem_alias_set (rtl
, const_alias_set
);
3197 /* We cannot share RTX'es in pool entries.
3198 Mark this piece of RTL as required for unsharing. */
3199 RTX_FLAG (rtl
, used
) = 1;
3201 /* Set flags or add text to the name to record information, such as
3202 that it is a local symbol. If the name is changed, the macro
3203 ASM_OUTPUT_LABELREF will have to know how to strip this
3204 information. This call might invalidate our local variable
3205 SYMBOL; we can't use it afterward. */
3206 targetm
.encode_section_info (exp
, rtl
, true);
3213 /* Return an rtx representing a reference to constant data in memory
3214 for the constant expression EXP.
3216 If assembler code for such a constant has already been output,
3217 return an rtx to refer to it.
3218 Otherwise, output such a constant in memory
3219 and generate an rtx for it.
3221 If DEFER is nonzero, this constant can be deferred and output only
3222 if referenced in the function after all optimizations.
3224 `const_desc_table' records which constants already have label strings. */
3227 output_constant_def (tree exp
, int defer
)
3229 struct constant_descriptor_tree
*desc
;
3230 struct constant_descriptor_tree key
;
3233 /* Look up EXP in the table of constant descriptors. If we didn't find
3234 it, create a new one. */
3236 key
.hash
= const_hash_1 (exp
);
3237 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3239 desc
= (struct constant_descriptor_tree
*) *loc
;
3242 desc
= build_constant_desc (exp
);
3243 desc
->hash
= key
.hash
;
3247 maybe_output_constant_def_contents (desc
, defer
);
3251 /* Subroutine of output_constant_def: Decide whether or not we need to
3252 output the constant DESC now, and if so, do it. */
3254 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3257 rtx symbol
= XEXP (desc
->rtl
, 0);
3258 tree exp
= desc
->value
;
3260 if (flag_syntax_only
)
3263 if (TREE_ASM_WRITTEN (exp
))
3264 /* Already output; don't do it again. */
3267 /* We can always defer constants as long as the context allows
3271 /* Increment n_deferred_constants if it exists. It needs to be at
3272 least as large as the number of constants actually referred to
3273 by the function. If it's too small we'll stop looking too early
3274 and fail to emit constants; if it's too large we'll only look
3275 through the entire function when we could have stopped earlier. */
3277 n_deferred_constants
++;
3281 output_constant_def_contents (symbol
);
3284 /* Subroutine of output_constant_def_contents. Output the definition
3285 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3286 constant's alignment in bits. */
3289 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3293 size
= get_constant_size (exp
);
3295 /* Do any machine/system dependent processing of the constant. */
3296 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3298 /* Output the value of EXP. */
3299 output_constant (exp
, size
, align
);
3302 /* We must output the constant data referred to by SYMBOL; do so. */
3305 output_constant_def_contents (rtx symbol
)
3307 tree decl
= SYMBOL_REF_DECL (symbol
);
3308 tree exp
= DECL_INITIAL (decl
);
3310 bool asan_protected
= false;
3312 /* Make sure any other constants whose addresses appear in EXP
3313 are assigned label numbers. */
3314 output_addressed_constants (exp
);
3316 /* We are no longer deferring this constant. */
3317 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3319 if ((flag_sanitize
& SANITIZE_ADDRESS
)
3320 && TREE_CODE (exp
) == STRING_CST
3321 && asan_protect_global (exp
))
3323 asan_protected
= true;
3324 DECL_ALIGN (decl
) = MAX (DECL_ALIGN (decl
),
3325 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
3328 /* If the constant is part of an object block, make sure that the
3329 decl has been positioned within its block, but do not write out
3330 its definition yet. output_object_blocks will do that later. */
3331 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3332 place_block_symbol (symbol
);
3335 align
= DECL_ALIGN (decl
);
3336 switch_to_section (get_constant_section (exp
, align
));
3337 if (align
> BITS_PER_UNIT
)
3338 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3339 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3342 HOST_WIDE_INT size
= get_constant_size (exp
);
3343 assemble_zeros (asan_red_zone_size (size
));
3348 /* Look up EXP in the table of constant descriptors. Return the rtl
3349 if it has been emitted, else null. */
3352 lookup_constant_def (tree exp
)
3354 struct constant_descriptor_tree
*desc
;
3355 struct constant_descriptor_tree key
;
3358 key
.hash
= const_hash_1 (exp
);
3359 desc
= (struct constant_descriptor_tree
*)
3360 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3362 return (desc
? desc
->rtl
: NULL_RTX
);
3365 /* Return a tree representing a reference to constant data in memory
3366 for the constant expression EXP.
3368 This is the counterpart of output_constant_def at the Tree level. */
3371 tree_output_constant_def (tree exp
)
3373 struct constant_descriptor_tree
*desc
, key
;
3377 /* Look up EXP in the table of constant descriptors. If we didn't find
3378 it, create a new one. */
3380 key
.hash
= const_hash_1 (exp
);
3381 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3383 desc
= (struct constant_descriptor_tree
*) *loc
;
3386 desc
= build_constant_desc (exp
);
3387 desc
->hash
= key
.hash
;
3391 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3392 varpool_finalize_decl (decl
);
3396 /* Used in the hash tables to avoid outputting the same constant
3397 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3398 are output once per function, not once per file. */
3399 /* ??? Only a few targets need per-function constant pools. Most
3400 can use one per-file pool. Should add a targetm bit to tell the
3403 struct GTY(()) rtx_constant_pool
{
3404 /* Pointers to first and last constant in pool, as ordered by offset. */
3405 struct constant_descriptor_rtx
*first
;
3406 struct constant_descriptor_rtx
*last
;
3408 /* Hash facility for making memory-constants from constant rtl-expressions.
3409 It is used on RISC machines where immediate integer arguments and
3410 constant addresses are restricted so that such constants must be stored
3412 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3414 /* Current offset in constant pool (does not include any
3415 machine-specific header). */
3416 HOST_WIDE_INT offset
;
3419 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3420 struct constant_descriptor_rtx
*next
;
3424 HOST_WIDE_INT offset
;
3426 enum machine_mode mode
;
3432 /* Hash and compare functions for const_rtx_htab. */
3435 const_desc_rtx_hash (const void *ptr
)
3437 const struct constant_descriptor_rtx
*const desc
3438 = (const struct constant_descriptor_rtx
*) ptr
;
3443 const_desc_rtx_eq (const void *a
, const void *b
)
3445 const struct constant_descriptor_rtx
*const x
3446 = (const struct constant_descriptor_rtx
*) a
;
3447 const struct constant_descriptor_rtx
*const y
3448 = (const struct constant_descriptor_rtx
*) b
;
3450 if (x
->mode
!= y
->mode
)
3452 return rtx_equal_p (x
->constant
, y
->constant
);
3455 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3458 const_rtx_hash_1 (rtx
*xp
, void *data
)
3460 unsigned HOST_WIDE_INT hwi
;
3461 enum machine_mode mode
;
3468 code
= GET_CODE (x
);
3469 mode
= GET_MODE (x
);
3470 h
= (hashval_t
) code
* 1048573 + mode
;
3479 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3480 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3482 h
^= (hashval_t
) hwi
;
3483 for (i
= 1; i
< n
; ++i
)
3486 h
^= (hashval_t
) hwi
;
3491 case CONST_WIDE_INT
:
3492 hwi
= GET_MODE_PRECISION (mode
);
3494 for (i
= 0; i
< CONST_WIDE_INT_NUNITS (x
); i
++)
3495 hwi
^= CONST_WIDE_INT_ELT (x
, i
);
3500 if (TARGET_SUPPORTS_WIDE_INT
== 0 && mode
== VOIDmode
)
3502 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3506 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3510 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3516 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3517 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3522 h
^= htab_hash_string (XSTR (x
, 0));
3526 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3530 case UNSPEC_VOLATILE
:
3531 h
= h
* 251 + XINT (x
, 1);
3538 hp
= (hashval_t
*) data
;
3539 *hp
= *hp
* 509 + h
;
3543 /* Compute a hash value for X, which should be a constant. */
3546 const_rtx_hash (rtx x
)
3549 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3554 /* Create and return a new rtx constant pool. */
3556 static struct rtx_constant_pool
*
3557 create_constant_pool (void)
3559 struct rtx_constant_pool
*pool
;
3561 pool
= ggc_alloc
<rtx_constant_pool
> ();
3562 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3563 const_desc_rtx_eq
, NULL
);
3570 /* Initialize constant pool hashing for a new function. */
3573 init_varasm_status (void)
3575 crtl
->varasm
.pool
= create_constant_pool ();
3576 crtl
->varasm
.deferred_constants
= 0;
3579 /* Given a MINUS expression, simplify it if both sides
3580 include the same symbol. */
3583 simplify_subtraction (rtx x
)
3585 rtx r
= simplify_rtx (x
);
3589 /* Given a constant rtx X, make (or find) a memory constant for its value
3590 and return a MEM rtx to refer to it in memory. */
3593 force_const_mem (enum machine_mode mode
, rtx x
)
3595 struct constant_descriptor_rtx
*desc
, tmp
;
3596 struct rtx_constant_pool
*pool
;
3603 /* If we're not allowed to drop X into the constant pool, don't. */
3604 if (targetm
.cannot_force_const_mem (mode
, x
))
3607 /* Record that this function has used a constant pool entry. */
3608 crtl
->uses_const_pool
= 1;
3610 /* Decide which pool to use. */
3611 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3612 ? shared_constant_pool
3613 : crtl
->varasm
.pool
);
3615 /* Lookup the value in the hashtable. */
3618 hash
= const_rtx_hash (x
);
3619 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3620 desc
= (struct constant_descriptor_rtx
*) *slot
;
3622 /* If the constant was already present, return its memory. */
3624 return copy_rtx (desc
->mem
);
3626 /* Otherwise, create a new descriptor. */
3627 desc
= ggc_alloc
<constant_descriptor_rtx
> ();
3630 /* Align the location counter as required by EXP's data type. */
3631 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3632 #ifdef CONSTANT_ALIGNMENT
3634 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3635 if (type
!= NULL_TREE
)
3636 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3640 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3641 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3644 desc
->constant
= copy_rtx (tmp
.constant
);
3645 desc
->offset
= pool
->offset
;
3648 desc
->align
= align
;
3649 desc
->labelno
= const_labelno
;
3652 pool
->offset
+= GET_MODE_SIZE (mode
);
3654 pool
->last
->next
= desc
;
3656 pool
->first
= pool
->last
= desc
;
3659 /* Create a string containing the label name, in LABEL. */
3660 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3663 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3664 the constants pool. */
3665 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3667 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3668 symbol
= create_block_symbol (ggc_strdup (label
),
3669 get_block_for_section (sect
), -1);
3672 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3674 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3675 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3676 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3678 /* Construct the MEM. */
3679 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3680 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3681 set_mem_align (def
, align
);
3683 /* If we're dropping a label to the constant pool, make sure we
3685 if (GET_CODE (x
) == LABEL_REF
)
3686 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3688 return copy_rtx (def
);
3691 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3694 get_pool_constant (rtx addr
)
3696 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3699 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3700 and whether it has been output or not. */
3703 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3705 struct constant_descriptor_rtx
*desc
;
3707 desc
= SYMBOL_REF_CONSTANT (addr
);
3708 *pmarked
= (desc
->mark
!= 0);
3709 return desc
->constant
;
3712 /* Similar, return the mode. */
3715 get_pool_mode (const_rtx addr
)
3717 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3720 /* Return the size of the constant pool. */
3723 get_pool_size (void)
3725 return crtl
->varasm
.pool
->offset
;
3728 /* Worker function for output_constant_pool_1. Emit assembly for X
3729 in MODE with known alignment ALIGN. */
3732 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3734 switch (GET_MODE_CLASS (mode
))
3737 case MODE_DECIMAL_FLOAT
:
3741 gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x
));
3742 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3743 assemble_real (r
, mode
, align
);
3748 case MODE_PARTIAL_INT
:
3753 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3756 case MODE_VECTOR_FLOAT
:
3757 case MODE_VECTOR_INT
:
3758 case MODE_VECTOR_FRACT
:
3759 case MODE_VECTOR_UFRACT
:
3760 case MODE_VECTOR_ACCUM
:
3761 case MODE_VECTOR_UACCUM
:
3764 enum machine_mode submode
= GET_MODE_INNER (mode
);
3765 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3767 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3768 units
= CONST_VECTOR_NUNITS (x
);
3770 for (i
= 0; i
< units
; i
++)
3772 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3773 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3783 /* Worker function for output_constant_pool. Emit constant DESC,
3784 giving it ALIGN bits of alignment. */
3787 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3794 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3795 whose CODE_LABEL has been deleted. This can occur if a jump table
3796 is eliminated by optimization. If so, write a constant of zero
3797 instead. Note that this can also happen by turning the
3798 CODE_LABEL into a NOTE. */
3799 /* ??? This seems completely and utterly wrong. Certainly it's
3800 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3801 functioning even with INSN_DELETED_P and friends. */
3804 switch (GET_CODE (tmp
))
3807 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3808 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3810 tmp
= XEXP (XEXP (tmp
, 0), 0);
3814 tmp
= XEXP (tmp
, 0);
3815 gcc_assert (!INSN_DELETED_P (tmp
));
3816 gcc_assert (!NOTE_P (tmp
)
3817 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3824 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3825 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3826 align
, desc
->labelno
, done
);
3829 assemble_align (align
);
3831 /* Output the label. */
3832 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3834 /* Output the data. */
3835 output_constant_pool_2 (desc
->mode
, x
, align
);
3837 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3838 sections have proper size. */
3839 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3841 && (in_section
->common
.flags
& SECTION_MERGE
))
3842 assemble_align (align
);
3844 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3850 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3851 to as used. Emit referenced deferred strings. This function can
3852 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3855 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
3857 rtx x
= *current_rtx
;
3859 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3862 if (CONSTANT_POOL_ADDRESS_P (x
))
3864 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3865 if (desc
->mark
== 0)
3868 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
3871 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3873 tree decl
= SYMBOL_REF_DECL (x
);
3874 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
3876 n_deferred_constants
--;
3877 output_constant_def_contents (x
);
3884 /* Look through appropriate parts of INSN, marking all entries in the
3885 constant pool which are actually being used. Entries that are only
3886 referenced by other constants are also marked as used. Emit
3887 deferred strings that are used. */
3890 mark_constants (rtx insn
)
3895 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3896 insns, not any notes that may be attached. We don't want to mark
3897 a constant just because it happens to appear in a REG_EQUIV note. */
3898 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3900 rtx seq
= PATTERN (insn
);
3901 int i
, n
= XVECLEN (seq
, 0);
3902 for (i
= 0; i
< n
; ++i
)
3904 rtx subinsn
= XVECEXP (seq
, 0, i
);
3905 if (INSN_P (subinsn
))
3906 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
3910 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
3913 /* Look through the instructions for this function, and mark all the
3914 entries in POOL which are actually being used. Emit deferred constants
3915 which have indeed been used. */
3918 mark_constant_pool (void)
3922 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
3925 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3926 mark_constants (insn
);
3929 /* Write all the constants in POOL. */
3932 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
3934 struct constant_descriptor_rtx
*desc
;
3936 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3939 /* If the constant is part of an object_block, make sure that
3940 the constant has been positioned within its block, but do not
3941 write out its definition yet. output_object_blocks will do
3943 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
3944 && SYMBOL_REF_BLOCK (desc
->sym
))
3945 place_block_symbol (desc
->sym
);
3948 switch_to_section (targetm
.asm_out
.select_rtx_section
3949 (desc
->mode
, desc
->constant
, desc
->align
));
3950 output_constant_pool_1 (desc
, desc
->align
);
3955 /* Mark all constants that are used in the current function, then write
3956 out the function's private constant pool. */
3959 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3960 tree fndecl ATTRIBUTE_UNUSED
)
3962 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
3964 /* It is possible for gcc to call force_const_mem and then to later
3965 discard the instructions which refer to the constant. In such a
3966 case we do not need to output the constant. */
3967 mark_constant_pool ();
3969 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3970 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3973 output_constant_pool_contents (pool
);
3975 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3976 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3980 /* Write the contents of the shared constant pool. */
3983 output_shared_constant_pool (void)
3985 output_constant_pool_contents (shared_constant_pool
);
3988 /* Determine what kind of relocations EXP may need. */
3991 compute_reloc_for_constant (tree exp
)
3993 int reloc
= 0, reloc2
;
3996 switch (TREE_CODE (exp
))
4000 /* Go inside any operations that get_inner_reference can handle and see
4001 if what's inside is a constant: no need to do anything here for
4002 addresses of variables or functions. */
4003 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4004 tem
= TREE_OPERAND (tem
, 0))
4007 if (TREE_CODE (tem
) == MEM_REF
4008 && TREE_CODE (TREE_OPERAND (tem
, 0)) == ADDR_EXPR
)
4010 reloc
= compute_reloc_for_constant (TREE_OPERAND (tem
, 0));
4014 if (!targetm
.binds_local_p (tem
))
4021 case POINTER_PLUS_EXPR
:
4022 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4023 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4027 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4028 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4029 /* The difference of two local labels is computable at link time. */
4030 if (reloc
== 1 && reloc2
== 1)
4037 case VIEW_CONVERT_EXPR
:
4038 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4043 unsigned HOST_WIDE_INT idx
;
4044 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4046 reloc
|= compute_reloc_for_constant (tem
);
4056 /* Find all the constants whose addresses are referenced inside of EXP,
4057 and make sure assembler code with a label has been output for each one.
4058 Indicate whether an ADDR_EXPR has been encountered. */
4061 output_addressed_constants (tree exp
)
4065 switch (TREE_CODE (exp
))
4069 /* Go inside any operations that get_inner_reference can handle and see
4070 if what's inside is a constant: no need to do anything here for
4071 addresses of variables or functions. */
4072 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4073 tem
= TREE_OPERAND (tem
, 0))
4076 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4077 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4078 tem
= DECL_INITIAL (tem
);
4080 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4081 output_constant_def (tem
, 0);
4083 if (TREE_CODE (tem
) == MEM_REF
)
4084 output_addressed_constants (TREE_OPERAND (tem
, 0));
4088 case POINTER_PLUS_EXPR
:
4090 output_addressed_constants (TREE_OPERAND (exp
, 1));
4094 case VIEW_CONVERT_EXPR
:
4095 output_addressed_constants (TREE_OPERAND (exp
, 0));
4100 unsigned HOST_WIDE_INT idx
;
4101 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4103 output_addressed_constants (tem
);
4112 /* Whether a constructor CTOR is a valid static constant initializer if all
4113 its elements are. This used to be internal to initializer_constant_valid_p
4114 and has been exposed to let other functions like categorize_ctor_elements
4115 evaluate the property while walking a constructor for other purposes. */
4118 constructor_static_from_elts_p (const_tree ctor
)
4120 return (TREE_CONSTANT (ctor
)
4121 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4122 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
4123 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
4126 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4129 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4130 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4131 which are valid when ENDTYPE is an integer of any size; in
4132 particular, this does not accept a pointer minus a constant. This
4133 returns null_pointer_node if the VALUE is an absolute constant
4134 which can be used to initialize a static variable. Otherwise it
4138 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4142 if (!INTEGRAL_TYPE_P (endtype
))
4145 op0
= TREE_OPERAND (value
, 0);
4146 op1
= TREE_OPERAND (value
, 1);
4148 /* Like STRIP_NOPS except allow the operand mode to widen. This
4149 works around a feature of fold that simplifies (int)(p1 - p2) to
4150 ((int)p1 - (int)p2) under the theory that the narrower operation
4153 while (CONVERT_EXPR_P (op0
)
4154 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4156 tree inner
= TREE_OPERAND (op0
, 0);
4157 if (inner
== error_mark_node
4158 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4159 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4160 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4165 while (CONVERT_EXPR_P (op1
)
4166 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4168 tree inner
= TREE_OPERAND (op1
, 0);
4169 if (inner
== error_mark_node
4170 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4171 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4172 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4177 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4181 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4182 cache
? cache
+ 2 : NULL
);
4183 /* Both initializers must be known. */
4187 && (op0
== null_pointer_node
4188 || TREE_CODE (value
) == MINUS_EXPR
))
4189 return null_pointer_node
;
4191 /* Support differences between labels. */
4192 if (TREE_CODE (op0
) == LABEL_DECL
4193 && TREE_CODE (op1
) == LABEL_DECL
)
4194 return null_pointer_node
;
4196 if (TREE_CODE (op0
) == STRING_CST
4197 && TREE_CODE (op1
) == STRING_CST
4198 && operand_equal_p (op0
, op1
, 1))
4199 return null_pointer_node
;
4205 /* Helper function of initializer_constant_valid_p.
4206 Return nonzero if VALUE is a valid constant-valued expression
4207 for use in initializing a static variable; one that can be an
4208 element of a "constant" initializer.
4210 Return null_pointer_node if the value is absolute;
4211 if it is relocatable, return the variable that determines the relocation.
4212 We assume that VALUE has been folded as much as possible;
4213 therefore, we do not need to check for such things as
4214 arithmetic-combinations of integers.
4216 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4219 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4223 switch (TREE_CODE (value
))
4226 if (constructor_static_from_elts_p (value
))
4228 unsigned HOST_WIDE_INT idx
;
4230 bool absolute
= true;
4232 if (cache
&& cache
[0] == value
)
4234 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4237 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4244 cache
[1] = NULL_TREE
;
4248 if (reloc
!= null_pointer_node
)
4251 /* For a non-absolute relocation, there is no single
4252 variable that can be "the variable that determines the
4257 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4259 return absolute
? null_pointer_node
: error_mark_node
;
4262 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4270 return null_pointer_node
;
4275 tree op0
= staticp (TREE_OPERAND (value
, 0));
4278 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4279 to be a constant, this is old-skool offsetof-like nonsense. */
4280 if (TREE_CODE (op0
) == INDIRECT_REF
4281 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4282 return null_pointer_node
;
4283 /* Taking the address of a nested function involves a trampoline,
4284 unless we don't need or want one. */
4285 if (TREE_CODE (op0
) == FUNCTION_DECL
4286 && DECL_STATIC_CHAIN (op0
)
4287 && !TREE_NO_TRAMPOLINE (value
))
4289 /* "&{...}" requires a temporary to hold the constructed
4291 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4297 case NON_LVALUE_EXPR
:
4298 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4301 case VIEW_CONVERT_EXPR
:
4303 tree src
= TREE_OPERAND (value
, 0);
4304 tree src_type
= TREE_TYPE (src
);
4305 tree dest_type
= TREE_TYPE (value
);
4307 /* Allow view-conversions from aggregate to non-aggregate type only
4308 if the bit pattern is fully preserved afterwards; otherwise, the
4309 RTL expander won't be able to apply a subsequent transformation
4310 to the underlying constructor. */
4311 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4313 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4314 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4319 /* Allow all other kinds of view-conversion. */
4320 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4325 tree src
= TREE_OPERAND (value
, 0);
4326 tree src_type
= TREE_TYPE (src
);
4327 tree dest_type
= TREE_TYPE (value
);
4329 /* Allow conversions between pointer types, floating-point
4330 types, and offset types. */
4331 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4332 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4333 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4334 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4335 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4337 /* Allow length-preserving conversions between integer types. */
4338 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4339 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4340 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4342 /* Allow conversions between other integer types only if
4344 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4346 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4347 if (inner
== null_pointer_node
)
4348 return null_pointer_node
;
4352 /* Allow (int) &foo provided int is as wide as a pointer. */
4353 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4354 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4355 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4357 /* Likewise conversions from int to pointers, but also allow
4358 conversions from 0. */
4359 if ((POINTER_TYPE_P (dest_type
)
4360 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4361 && INTEGRAL_TYPE_P (src_type
))
4363 if (TREE_CODE (src
) == INTEGER_CST
4364 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4365 return null_pointer_node
;
4366 if (integer_zerop (src
))
4367 return null_pointer_node
;
4368 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4369 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4372 /* Allow conversions to struct or union types if the value
4374 if (TREE_CODE (dest_type
) == RECORD_TYPE
4375 || TREE_CODE (dest_type
) == UNION_TYPE
)
4376 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4380 case POINTER_PLUS_EXPR
:
4382 /* Any valid floating-point constants will have been folded by now;
4383 with -frounding-math we hit this with addition of two constants. */
4384 if (TREE_CODE (endtype
) == REAL_TYPE
)
4386 if (cache
&& cache
[0] == value
)
4388 if (! INTEGRAL_TYPE_P (endtype
)
4389 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4391 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4393 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4396 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4397 endtype
, ncache
+ 2);
4398 /* If either term is absolute, use the other term's relocation. */
4399 if (valid0
== null_pointer_node
)
4401 else if (valid1
== null_pointer_node
)
4403 /* Support narrowing pointer differences. */
4405 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4409 /* Support narrowing pointer differences. */
4410 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4419 if (TREE_CODE (endtype
) == REAL_TYPE
)
4421 if (cache
&& cache
[0] == value
)
4423 if (! INTEGRAL_TYPE_P (endtype
)
4424 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4426 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4428 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4431 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4432 endtype
, ncache
+ 2);
4433 /* Win if second argument is absolute. */
4434 if (valid1
== null_pointer_node
)
4436 /* Win if both arguments have the same relocation.
4437 Then the value is absolute. */
4438 else if (valid0
== valid1
&& valid0
!= 0)
4439 ret
= null_pointer_node
;
4440 /* Since GCC guarantees that string constants are unique in the
4441 generated code, a subtraction between two copies of the same
4442 constant string is absolute. */
4443 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4444 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4445 && operand_equal_p (valid0
, valid1
, 1))
4446 ret
= null_pointer_node
;
4447 /* Support narrowing differences. */
4449 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4453 /* Support narrowing differences. */
4454 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4469 /* Return nonzero if VALUE is a valid constant-valued expression
4470 for use in initializing a static variable; one that can be an
4471 element of a "constant" initializer.
4473 Return null_pointer_node if the value is absolute;
4474 if it is relocatable, return the variable that determines the relocation.
4475 We assume that VALUE has been folded as much as possible;
4476 therefore, we do not need to check for such things as
4477 arithmetic-combinations of integers. */
4479 initializer_constant_valid_p (tree value
, tree endtype
)
4481 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4484 /* Return true if VALUE is a valid constant-valued expression
4485 for use in initializing a static bit-field; one that can be
4486 an element of a "constant" initializer. */
4489 initializer_constant_valid_for_bitfield_p (tree value
)
4491 /* For bitfields we support integer constants or possibly nested aggregates
4493 switch (TREE_CODE (value
))
4497 unsigned HOST_WIDE_INT idx
;
4500 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4501 if (!initializer_constant_valid_for_bitfield_p (elt
))
4510 case VIEW_CONVERT_EXPR
:
4511 case NON_LVALUE_EXPR
:
4513 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4522 /* output_constructor outer state of relevance in recursive calls, typically
4523 for nested aggregate bitfields. */
4526 unsigned int bit_offset
; /* current position in ... */
4527 int byte
; /* ... the outer byte buffer. */
4530 static unsigned HOST_WIDE_INT
4531 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4534 /* Output assembler code for constant EXP, with no label.
4535 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4536 Assumes output_addressed_constants has been done on EXP already.
4538 Generate at least SIZE bytes of assembler data, padding at the end
4539 with zeros if necessary. SIZE must always be specified. The returned
4540 value is the actual number of bytes of assembler data generated, which
4541 may be bigger than SIZE if the object contains a variable length field.
4543 SIZE is important for structure constructors,
4544 since trailing members may have been omitted from the constructor.
4545 It is also important for initialization of arrays from string constants
4546 since the full length of the string constant might not be wanted.
4547 It is also needed for initialization of unions, where the initializer's
4548 type is just one member, and that may not be as long as the union.
4550 There a case in which we would fail to output exactly SIZE bytes:
4551 for a structure constructor that wants to produce more than SIZE bytes.
4552 But such constructors will never be generated for any possible input.
4554 ALIGN is the alignment of the data in bits. */
4556 static unsigned HOST_WIDE_INT
4557 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4559 enum tree_code code
;
4560 unsigned HOST_WIDE_INT thissize
;
4562 if (size
== 0 || flag_syntax_only
)
4565 /* See if we're trying to initialize a pointer in a non-default mode
4566 to the address of some declaration somewhere. If the target says
4567 the mode is valid for pointers, assume the target has a way of
4569 if (TREE_CODE (exp
) == NOP_EXPR
4570 && POINTER_TYPE_P (TREE_TYPE (exp
))
4571 && targetm
.addr_space
.valid_pointer_mode
4572 (TYPE_MODE (TREE_TYPE (exp
)),
4573 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4575 tree saved_type
= TREE_TYPE (exp
);
4577 /* Peel off any intermediate conversions-to-pointer for valid
4579 while (TREE_CODE (exp
) == NOP_EXPR
4580 && POINTER_TYPE_P (TREE_TYPE (exp
))
4581 && targetm
.addr_space
.valid_pointer_mode
4582 (TYPE_MODE (TREE_TYPE (exp
)),
4583 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4584 exp
= TREE_OPERAND (exp
, 0);
4586 /* If what we're left with is the address of something, we can
4587 convert the address to the final type and output it that
4589 if (TREE_CODE (exp
) == ADDR_EXPR
)
4590 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4591 /* Likewise for constant ints. */
4592 else if (TREE_CODE (exp
) == INTEGER_CST
)
4593 exp
= wide_int_to_tree (saved_type
, exp
);
4597 /* Eliminate any conversions since we'll be outputting the underlying
4599 while (CONVERT_EXPR_P (exp
)
4600 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4601 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4603 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4604 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4606 /* Make sure eliminating the conversion is really a no-op, except with
4607 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4608 union types to allow for Ada unchecked unions. */
4609 if (type_size
> op_size
4610 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4611 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4612 /* Keep the conversion. */
4615 exp
= TREE_OPERAND (exp
, 0);
4618 code
= TREE_CODE (TREE_TYPE (exp
));
4619 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4621 /* Allow a constructor with no elements for any data type.
4622 This means to fill the space with zeros. */
4623 if (TREE_CODE (exp
) == CONSTRUCTOR
4624 && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp
)))
4626 assemble_zeros (size
);
4630 if (TREE_CODE (exp
) == FDESC_EXPR
)
4632 #ifdef ASM_OUTPUT_FDESC
4633 HOST_WIDE_INT part
= tree_to_shwi (TREE_OPERAND (exp
, 1));
4634 tree decl
= TREE_OPERAND (exp
, 0);
4635 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4642 /* Now output the underlying data. If we've handling the padding, return.
4643 Otherwise, break and ensure SIZE is the size written. */
4650 case REFERENCE_TYPE
:
4652 case FIXED_POINT_TYPE
:
4654 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4655 EXPAND_INITIALIZER
),
4656 MIN (size
, thissize
), align
, 0))
4657 error ("initializer for integer/fixed-point value is too complicated");
4661 if (TREE_CODE (exp
) != REAL_CST
)
4662 error ("initializer for floating value is not a floating constant");
4664 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4668 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4669 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4670 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4675 switch (TREE_CODE (exp
))
4678 return output_constructor (exp
, size
, align
, NULL
);
4681 = MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
), size
);
4682 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4686 enum machine_mode inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4687 unsigned int nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4688 int elt_size
= GET_MODE_SIZE (inner
);
4689 output_constant (VECTOR_CST_ELT (exp
, 0), elt_size
, align
);
4690 thissize
= elt_size
;
4691 for (unsigned int i
= 1; i
< VECTOR_CST_NELTS (exp
); i
++)
4693 output_constant (VECTOR_CST_ELT (exp
, i
), elt_size
, nalign
);
4694 thissize
+= elt_size
;
4705 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4706 return output_constructor (exp
, size
, align
, NULL
);
4715 if (size
> thissize
)
4716 assemble_zeros (size
- thissize
);
4722 /* Subroutine of output_constructor, used for computing the size of
4723 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4724 type with an unspecified upper bound. */
4726 static unsigned HOST_WIDE_INT
4727 array_size_for_constructor (tree val
)
4730 unsigned HOST_WIDE_INT cnt
;
4731 tree index
, value
, tmp
;
4734 /* This code used to attempt to handle string constants that are not
4735 arrays of single-bytes, but nothing else does, so there's no point in
4737 if (TREE_CODE (val
) == STRING_CST
)
4738 return TREE_STRING_LENGTH (val
);
4740 max_index
= NULL_TREE
;
4741 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4743 if (TREE_CODE (index
) == RANGE_EXPR
)
4744 index
= TREE_OPERAND (index
, 1);
4745 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4749 if (max_index
== NULL_TREE
)
4752 /* Compute the total number of array elements. */
4753 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4754 i
= wi::to_offset (max_index
) - wi::to_offset (tmp
) + 1;
4756 /* Multiply by the array element unit size to find number of bytes. */
4757 i
*= wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4759 gcc_assert (wi::fits_uhwi_p (i
));
4760 return i
.to_uhwi ();
4763 /* Other datastructures + helpers for output_constructor. */
4765 /* output_constructor local state to support interaction with helpers. */
4769 /* Received arguments. */
4770 tree exp
; /* Constructor expression. */
4771 tree type
; /* Type of constructor expression. */
4772 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4773 unsigned int align
; /* Known initial alignment. */
4774 tree min_index
; /* Lower bound if specified for an array. */
4776 /* Output processing state. */
4777 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4778 int byte
; /* Part of a bitfield byte yet to be output. */
4779 int last_relative_index
; /* Implicit or explicit index of the last
4780 array element output within a bitfield. */
4781 bool byte_buffer_in_use
; /* Whether BYTE is in use. */
4783 /* Current element. */
4784 tree field
; /* Current field decl in a record. */
4785 tree val
; /* Current element value. */
4786 tree index
; /* Current element index. */
4790 /* Helper for output_constructor. From the current LOCAL state, output a
4791 RANGE_EXPR element. */
4794 output_constructor_array_range (oc_local_state
*local
)
4796 unsigned HOST_WIDE_INT fieldsize
4797 = int_size_in_bytes (TREE_TYPE (local
->type
));
4799 HOST_WIDE_INT lo_index
4800 = tree_to_shwi (TREE_OPERAND (local
->index
, 0));
4801 HOST_WIDE_INT hi_index
4802 = tree_to_shwi (TREE_OPERAND (local
->index
, 1));
4803 HOST_WIDE_INT index
;
4806 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4808 for (index
= lo_index
; index
<= hi_index
; index
++)
4810 /* Output the element's initial value. */
4811 if (local
->val
== NULL_TREE
)
4812 assemble_zeros (fieldsize
);
4814 fieldsize
= output_constant (local
->val
, fieldsize
, align2
);
4816 /* Count its size. */
4817 local
->total_bytes
+= fieldsize
;
4821 /* Helper for output_constructor. From the current LOCAL state, output a
4822 field element that is not true bitfield or part of an outer one. */
4825 output_constructor_regular_field (oc_local_state
*local
)
4827 /* Field size and position. Since this structure is static, we know the
4828 positions are constant. */
4829 unsigned HOST_WIDE_INT fieldsize
;
4830 HOST_WIDE_INT fieldpos
;
4832 unsigned int align2
;
4834 if (local
->index
!= NULL_TREE
)
4836 /* Perform the index calculation in modulo arithmetic but
4837 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
4838 but we are using an unsigned sizetype. */
4839 unsigned prec
= TYPE_PRECISION (sizetype
);
4840 offset_int idx
= wi::sext (wi::to_offset (local
->index
)
4841 - wi::to_offset (local
->min_index
), prec
);
4842 fieldpos
= (idx
* wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
))))
4845 else if (local
->field
!= NULL_TREE
)
4846 fieldpos
= int_byte_position (local
->field
);
4850 /* Output any buffered-up bit-fields preceding this element. */
4851 if (local
->byte_buffer_in_use
)
4853 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4854 local
->total_bytes
++;
4855 local
->byte_buffer_in_use
= false;
4858 /* Advance to offset of this element.
4859 Note no alignment needed in an array, since that is guaranteed
4860 if each element has the proper size. */
4861 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4862 && fieldpos
> local
->total_bytes
)
4864 assemble_zeros (fieldpos
- local
->total_bytes
);
4865 local
->total_bytes
= fieldpos
;
4868 /* Find the alignment of this element. */
4869 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
4871 /* Determine size this element should occupy. */
4876 /* If this is an array with an unspecified upper bound,
4877 the initializer determines the size. */
4878 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4879 but we cannot do this until the deprecated support for
4880 initializing zero-length array members is removed. */
4881 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
4882 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
4883 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
4885 fieldsize
= array_size_for_constructor (local
->val
);
4886 /* Given a non-empty initialization, this field had
4888 gcc_assert (!fieldsize
|| !DECL_CHAIN (local
->field
));
4891 fieldsize
= tree_to_uhwi (DECL_SIZE_UNIT (local
->field
));
4894 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
4896 /* Output the element's initial value. */
4897 if (local
->val
== NULL_TREE
)
4898 assemble_zeros (fieldsize
);
4900 fieldsize
= output_constant (local
->val
, fieldsize
, align2
);
4902 /* Count its size. */
4903 local
->total_bytes
+= fieldsize
;
4906 /* Helper for output_constructor. From the LOCAL state, output an element
4907 that is a true bitfield or part of an outer one. BIT_OFFSET is the offset
4908 from the start of a possibly ongoing outer byte buffer. */
4911 output_constructor_bitfield (oc_local_state
*local
, unsigned int bit_offset
)
4913 /* Bit size of this element. */
4914 HOST_WIDE_INT ebitsize
4916 ? tree_to_uhwi (DECL_SIZE (local
->field
))
4917 : tree_to_uhwi (TYPE_SIZE (TREE_TYPE (local
->type
))));
4919 /* Relative index of this element if this is an array component. */
4920 HOST_WIDE_INT relative_index
4923 ? (tree_to_shwi (local
->index
)
4924 - tree_to_shwi (local
->min_index
))
4925 : local
->last_relative_index
+ 1)
4928 /* Bit position of this element from the start of the containing
4930 HOST_WIDE_INT constructor_relative_ebitpos
4932 ? int_bit_position (local
->field
)
4933 : ebitsize
* relative_index
);
4935 /* Bit position of this element from the start of a possibly ongoing
4936 outer byte buffer. */
4937 HOST_WIDE_INT byte_relative_ebitpos
4938 = bit_offset
+ constructor_relative_ebitpos
;
4940 /* From the start of a possibly ongoing outer byte buffer, offsets to
4941 the first bit of this element and to the first bit past the end of
4943 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
4944 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
4946 local
->last_relative_index
= relative_index
;
4948 if (local
->val
== NULL_TREE
)
4949 local
->val
= integer_zero_node
;
4951 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
4952 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
4953 local
->val
= TREE_OPERAND (local
->val
, 0);
4955 if (TREE_CODE (local
->val
) != INTEGER_CST
4956 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
4958 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
4962 /* If this field does not start in this (or next) byte, skip some bytes. */
4963 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4965 /* Output remnant of any bit field in previous bytes. */
4966 if (local
->byte_buffer_in_use
)
4968 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4969 local
->total_bytes
++;
4970 local
->byte_buffer_in_use
= false;
4973 /* If still not at proper byte, advance to there. */
4974 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4976 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
4977 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
4978 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
4982 /* Set up the buffer if necessary. */
4983 if (!local
->byte_buffer_in_use
)
4987 local
->byte_buffer_in_use
= true;
4990 /* If this is nested constructor, recurse passing the bit offset and the
4991 pending data, then retrieve the new pending data afterwards. */
4992 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
4994 oc_outer_state temp_state
;
4995 temp_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
4996 temp_state
.byte
= local
->byte
;
4998 += output_constructor (local
->val
, 0, 0, &temp_state
);
4999 local
->byte
= temp_state
.byte
;
5003 /* Otherwise, we must split the element into pieces that fall within
5004 separate bytes, and combine each byte with previous or following
5006 while (next_offset
< end_offset
)
5010 HOST_WIDE_INT value
;
5011 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5012 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5014 /* Advance from byte to byte within this element when necessary. */
5015 while (next_byte
!= local
->total_bytes
)
5017 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5018 local
->total_bytes
++;
5022 /* Number of bits we can process at once (all part of the same byte). */
5023 this_time
= MIN (end_offset
- next_offset
, BITS_PER_UNIT
- next_bit
);
5024 if (BYTES_BIG_ENDIAN
)
5026 /* On big-endian machine, take the most significant bits (of the
5027 bits that are significant) first and put them into bytes from
5028 the most significant end. */
5029 shift
= end_offset
- next_offset
- this_time
;
5031 /* Don't try to take a bunch of bits that cross
5032 the word boundary in the INTEGER_CST. We can
5033 only select bits from one element. */
5034 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5035 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5037 const int end
= shift
+ this_time
- 1;
5038 shift
= end
& -HOST_BITS_PER_WIDE_INT
;
5039 this_time
= end
- shift
+ 1;
5042 /* Now get the bits from the appropriate constant word. */
5043 value
= TREE_INT_CST_ELT (local
->val
, shift
/ HOST_BITS_PER_WIDE_INT
);
5044 shift
= shift
& (HOST_BITS_PER_WIDE_INT
- 1);
5046 /* Get the result. This works only when:
5047 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5048 local
->byte
|= (((value
>> shift
)
5049 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5050 << (BITS_PER_UNIT
- this_time
- next_bit
));
5054 /* On little-endian machines, take the least significant bits of
5055 the value first and pack them starting at the least significant
5056 bits of the bytes. */
5057 shift
= next_offset
- byte_relative_ebitpos
;
5059 /* Don't try to take a bunch of bits that cross
5060 the word boundary in the INTEGER_CST. We can
5061 only select bits from one element. */
5062 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5063 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5065 = HOST_BITS_PER_WIDE_INT
- (shift
& (HOST_BITS_PER_WIDE_INT
- 1));
5067 /* Now get the bits from the appropriate constant word. */
5068 value
= TREE_INT_CST_ELT (local
->val
, shift
/ HOST_BITS_PER_WIDE_INT
);
5069 shift
= shift
& (HOST_BITS_PER_WIDE_INT
- 1);
5071 /* Get the result. This works only when:
5072 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5073 local
->byte
|= (((value
>> shift
)
5074 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5078 next_offset
+= this_time
;
5079 local
->byte_buffer_in_use
= true;
5083 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5084 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5085 caller output state of relevance in recursive invocations. */
5087 static unsigned HOST_WIDE_INT
5088 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5089 unsigned int align
, oc_outer_state
*outer
)
5091 unsigned HOST_WIDE_INT cnt
;
5092 constructor_elt
*ce
;
5094 oc_local_state local
;
5096 /* Setup our local state to communicate with helpers. */
5098 local
.type
= TREE_TYPE (exp
);
5100 local
.align
= align
;
5101 if (TREE_CODE (local
.type
) == ARRAY_TYPE
&& TYPE_DOMAIN (local
.type
))
5102 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5104 local
.min_index
= NULL_TREE
;
5106 local
.total_bytes
= 0;
5107 local
.byte_buffer_in_use
= outer
!= NULL
;
5108 local
.byte
= outer
? outer
->byte
: 0;
5109 local
.last_relative_index
= -1;
5111 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5113 /* As CE goes through the elements of the constant, FIELD goes through the
5114 structure fields if the constant is a structure. If the constant is a
5115 union, we override this by getting the field from the TREE_LIST element.
5116 But the constant could also be an array. Then FIELD is zero.
5118 There is always a maximum of one element in the chain LINK for unions
5119 (even if the initializer in a source program incorrectly contains
5122 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5123 local
.field
= TYPE_FIELDS (local
.type
);
5125 local
.field
= NULL_TREE
;
5128 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), cnt
, &ce
);
5129 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
5131 local
.val
= ce
->value
;
5132 local
.index
= NULL_TREE
;
5134 /* The element in a union constructor specifies the proper field
5136 if (RECORD_OR_UNION_TYPE_P (local
.type
) && ce
->index
!= NULL_TREE
)
5137 local
.field
= ce
->index
;
5139 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5140 local
.index
= ce
->index
;
5142 if (local
.field
&& flag_verbose_asm
)
5143 fprintf (asm_out_file
, "%s %s:\n",
5145 DECL_NAME (local
.field
)
5146 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5149 /* Eliminate the marker that makes a cast not be an lvalue. */
5150 if (local
.val
!= NULL_TREE
)
5151 STRIP_NOPS (local
.val
);
5153 /* Output the current element, using the appropriate helper ... */
5155 /* For an array slice not part of an outer bitfield. */
5157 && local
.index
!= NULL_TREE
5158 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5159 output_constructor_array_range (&local
);
5161 /* For a field that is neither a true bitfield nor part of an outer one,
5162 known to be at least byte aligned and multiple-of-bytes long. */
5164 && (local
.field
== NULL_TREE
5165 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5166 output_constructor_regular_field (&local
);
5168 /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
5169 supported for scalar fields, so we may need to convert first. */
5172 if (TREE_CODE (local
.val
) == REAL_CST
)
5174 = fold_unary (VIEW_CONVERT_EXPR
,
5175 build_nonstandard_integer_type
5176 (TYPE_PRECISION (TREE_TYPE (local
.val
)), 0),
5178 output_constructor_bitfield (&local
, outer
? outer
->bit_offset
: 0);
5182 /* If we are not at toplevel, save the pending data for our caller.
5183 Otherwise output the pending data and padding zeros as needed. */
5185 outer
->byte
= local
.byte
;
5188 if (local
.byte_buffer_in_use
)
5190 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5191 local
.total_bytes
++;
5194 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5196 assemble_zeros (local
.size
- local
.total_bytes
);
5197 local
.total_bytes
= local
.size
;
5201 return local
.total_bytes
;
5204 /* Mark DECL as weak. */
5207 mark_weak (tree decl
)
5209 DECL_WEAK (decl
) = 1;
5211 if (DECL_RTL_SET_P (decl
)
5212 && MEM_P (DECL_RTL (decl
))
5213 && XEXP (DECL_RTL (decl
), 0)
5214 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5215 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5218 /* Merge weak status between NEWDECL and OLDDECL. */
5221 merge_weak (tree newdecl
, tree olddecl
)
5223 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5225 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5228 /* We put the NEWDECL on the weak_decls list at some point
5229 and OLDDECL as well. Keep just OLDDECL on the list. */
5230 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5231 if (TREE_VALUE (*pwd
) == newdecl
)
5233 *pwd
= TREE_CHAIN (*pwd
);
5240 if (DECL_WEAK (newdecl
))
5244 /* NEWDECL is weak, but OLDDECL is not. */
5246 /* If we already output the OLDDECL, we're in trouble; we can't
5247 go back and make it weak. This should never happen in
5248 unit-at-a-time compilation. */
5249 gcc_assert (!TREE_ASM_WRITTEN (olddecl
));
5251 /* If we've already generated rtl referencing OLDDECL, we may
5252 have done so in a way that will not function properly with
5253 a weak symbol. Again in unit-at-a-time this should be
5255 gcc_assert (!TREE_USED (olddecl
)
5256 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)));
5258 if (TARGET_SUPPORTS_WEAK
)
5260 /* We put the NEWDECL on the weak_decls list at some point.
5261 Replace it with the OLDDECL. */
5262 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5263 if (TREE_VALUE (wd
) == newdecl
)
5265 TREE_VALUE (wd
) = olddecl
;
5268 /* We may not find the entry on the list. If NEWDECL is a
5269 weak alias, then we will have already called
5270 globalize_decl to remove the entry; in that case, we do
5271 not need to do anything. */
5274 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5275 mark_weak (olddecl
);
5278 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5279 weak. Just update NEWDECL to indicate that it's weak too. */
5280 mark_weak (newdecl
);
5283 /* Declare DECL to be a weak symbol. */
5286 declare_weak (tree decl
)
5288 gcc_assert (TREE_CODE (decl
) != FUNCTION_DECL
|| !TREE_ASM_WRITTEN (decl
));
5289 if (! TREE_PUBLIC (decl
))
5290 error ("weak declaration of %q+D must be public", decl
);
5291 else if (!TARGET_SUPPORTS_WEAK
)
5292 warning (0, "weak declaration of %q+D not supported", decl
);
5295 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5296 DECL_ATTRIBUTES (decl
)
5297 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5301 weak_finish_1 (tree decl
)
5303 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5304 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5307 if (! TREE_USED (decl
))
5310 #ifdef ASM_WEAKEN_DECL
5311 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5313 #ifdef ASM_WEAKEN_LABEL
5314 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5316 #ifdef ASM_OUTPUT_WEAK_ALIAS
5318 static bool warn_once
= 0;
5321 warning (0, "only weak aliases are supported in this configuration");
5331 /* Fiven an assembly name, find the decl it is associated with. */
5333 find_decl (tree target
)
5335 symtab_node
*node
= symtab_node_for_asm (target
);
5341 /* This TREE_LIST contains weakref targets. */
5343 static GTY(()) tree weakref_targets
;
5345 /* Emit any pending weak declarations. */
5352 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5354 tree alias_decl
= TREE_PURPOSE (t
);
5355 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5357 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5358 /* Remove alias_decl from the weak list, but leave entries for
5359 the target alone. */
5361 #ifndef ASM_OUTPUT_WEAKREF
5362 else if (! TREE_SYMBOL_REFERENCED (target
))
5364 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5365 defined, otherwise we and weak_finish_1 would use
5366 different macros. */
5367 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5368 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5370 tree decl
= find_decl (target
);
5374 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5375 TREE_CODE (alias_decl
), target
,
5376 TREE_TYPE (alias_decl
));
5378 DECL_EXTERNAL (decl
) = 1;
5379 TREE_PUBLIC (decl
) = 1;
5380 DECL_ARTIFICIAL (decl
) = 1;
5381 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5382 TREE_USED (decl
) = 1;
5385 weak_finish_1 (decl
);
5394 /* Remove the alias and the target from the pending weak list
5395 so that we do not emit any .weak directives for the former,
5396 nor multiple .weak directives for the latter. */
5397 for (p
= &weak_decls
; (t2
= *p
) ; )
5399 if (TREE_VALUE (t2
) == alias_decl
5400 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5401 *p
= TREE_CHAIN (t2
);
5403 p
= &TREE_CHAIN (t2
);
5406 /* Remove other weakrefs to the same target, to speed things up. */
5407 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5409 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5410 *p
= TREE_CHAIN (t2
);
5412 p
= &TREE_CHAIN (t2
);
5417 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5419 tree decl
= TREE_VALUE (t
);
5421 weak_finish_1 (decl
);
5425 /* Emit the assembly bits to indicate that DECL is globally visible. */
5428 globalize_decl (tree decl
)
5431 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5432 if (DECL_WEAK (decl
))
5434 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5437 #ifdef ASM_WEAKEN_DECL
5438 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5440 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5443 /* Remove this function from the pending weak list so that
5444 we do not emit multiple .weak directives for it. */
5445 for (p
= &weak_decls
; (t
= *p
) ; )
5447 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5448 *p
= TREE_CHAIN (t
);
5450 p
= &TREE_CHAIN (t
);
5453 /* Remove weakrefs to the same target from the pending weakref
5454 list, for the same reason. */
5455 for (p
= &weakref_targets
; (t
= *p
) ; )
5457 if (DECL_ASSEMBLER_NAME (decl
)
5458 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5459 *p
= TREE_CHAIN (t
);
5461 p
= &TREE_CHAIN (t
);
5468 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5471 vec
<alias_pair
, va_gc
> *alias_pairs
;
5473 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5474 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5475 tree node is DECL to have the value of the tree node TARGET. */
5478 do_assemble_alias (tree decl
, tree target
)
5480 /* Emulated TLS had better not get this var. */
5481 gcc_assert (!(!targetm
.have_tls
5482 && TREE_CODE (decl
) == VAR_DECL
5483 && DECL_THREAD_LOCAL_P (decl
)));
5485 if (TREE_ASM_WRITTEN (decl
))
5488 /* We must force creation of DECL_RTL for debug info generation, even though
5489 we don't use it here. */
5490 make_decl_rtl (decl
);
5492 TREE_ASM_WRITTEN (decl
) = 1;
5493 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5495 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5497 ultimate_transparent_alias_target (&target
);
5499 if (!TREE_SYMBOL_REFERENCED (target
))
5500 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5502 #ifdef ASM_OUTPUT_WEAKREF
5503 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5504 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5505 IDENTIFIER_POINTER (target
));
5507 if (!TARGET_SUPPORTS_WEAK
)
5509 error_at (DECL_SOURCE_LOCATION (decl
),
5510 "weakref is not supported in this configuration");
5517 #ifdef ASM_OUTPUT_DEF
5518 /* Make name accessible from other files, if appropriate. */
5520 if (TREE_PUBLIC (decl
))
5522 globalize_decl (decl
);
5523 maybe_assemble_visibility (decl
);
5525 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5527 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
5528 if (targetm
.has_ifunc_p ())
5529 ASM_OUTPUT_TYPE_DIRECTIVE
5530 (asm_out_file
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5534 error_at (DECL_SOURCE_LOCATION (decl
),
5535 "ifunc is not supported on this target");
5538 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5539 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5541 ASM_OUTPUT_DEF (asm_out_file
,
5542 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5543 IDENTIFIER_POINTER (target
));
5545 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5550 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5551 # ifdef ASM_WEAKEN_DECL
5552 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5554 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5556 /* Remove this function from the pending weak list so that
5557 we do not emit multiple .weak directives for it. */
5558 for (p
= &weak_decls
; (t
= *p
) ; )
5559 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5560 *p
= TREE_CHAIN (t
);
5562 p
= &TREE_CHAIN (t
);
5564 /* Remove weakrefs to the same target from the pending weakref
5565 list, for the same reason. */
5566 for (p
= &weakref_targets
; (t
= *p
) ; )
5568 if (DECL_ASSEMBLER_NAME (decl
)
5569 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5570 *p
= TREE_CHAIN (t
);
5572 p
= &TREE_CHAIN (t
);
5578 /* Emit an assembler directive to make the symbol for DECL an alias to
5579 the symbol for TARGET. */
5582 assemble_alias (tree decl
, tree target
)
5586 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5588 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5590 ultimate_transparent_alias_target (&target
);
5592 if (alias
== target
)
5593 error ("weakref %q+D ultimately targets itself", decl
);
5594 if (TREE_PUBLIC (decl
))
5595 error ("weakref %q+D must have static linkage", decl
);
5599 #if !defined (ASM_OUTPUT_DEF)
5600 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5601 error_at (DECL_SOURCE_LOCATION (decl
),
5602 "alias definitions not supported in this configuration");
5603 TREE_ASM_WRITTEN (decl
) = 1;
5606 if (!DECL_WEAK (decl
))
5608 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5609 error_at (DECL_SOURCE_LOCATION (decl
),
5610 "ifunc is not supported in this configuration");
5612 error_at (DECL_SOURCE_LOCATION (decl
),
5613 "only weak aliases are supported in this configuration");
5614 TREE_ASM_WRITTEN (decl
) = 1;
5620 TREE_USED (decl
) = 1;
5622 /* Allow aliases to aliases. */
5623 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5624 cgraph_get_create_node (decl
)->alias
= true;
5626 varpool_node_for_decl (decl
)->alias
= true;
5628 /* If the target has already been emitted, we don't have to queue the
5629 alias. This saves a tad of memory. */
5630 if (cgraph_global_info_ready
)
5631 target_decl
= find_decl (target
);
5634 if ((target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5635 || cgraph_state
>= CGRAPH_STATE_EXPANSION
)
5636 do_assemble_alias (decl
, target
);
5639 alias_pair p
= {decl
, target
};
5640 vec_safe_push (alias_pairs
, p
);
5644 /* Record and output a table of translations from original function
5645 to its transaction aware clone. Note that tm_pure functions are
5646 considered to be their own clone. */
5648 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
5649 htab_t tm_clone_hash
;
5652 record_tm_clone_pair (tree o
, tree n
)
5654 struct tree_map
**slot
, *h
;
5656 if (tm_clone_hash
== NULL
)
5657 tm_clone_hash
= htab_create_ggc (32, tree_map_hash
, tree_map_eq
, 0);
5659 h
= ggc_alloc
<tree_map
> ();
5660 h
->hash
= htab_hash_pointer (o
);
5664 slot
= (struct tree_map
**)
5665 htab_find_slot_with_hash (tm_clone_hash
, h
, h
->hash
, INSERT
);
5670 get_tm_clone_pair (tree o
)
5674 struct tree_map
*h
, in
;
5677 in
.hash
= htab_hash_pointer (o
);
5678 h
= (struct tree_map
*) htab_find_with_hash (tm_clone_hash
,
5686 typedef struct tm_alias_pair
5694 /* Helper function for finish_tm_clone_pairs. Dump a hash table entry
5695 into a VEC in INFO. */
5698 dump_tm_clone_to_vec (void **slot
, void *info
)
5700 struct tree_map
*map
= (struct tree_map
*) *slot
;
5701 vec
<tm_alias_pair
> *tm_alias_pairs
= (vec
<tm_alias_pair
> *) info
;
5702 tm_alias_pair p
= {DECL_UID (map
->base
.from
), map
->base
.from
, map
->to
};
5703 tm_alias_pairs
->safe_push (p
);
5707 /* Dump the actual pairs to the .tm_clone_table section. */
5710 dump_tm_clone_pairs (vec
<tm_alias_pair
> tm_alias_pairs
)
5714 bool switched
= false;
5716 FOR_EACH_VEC_ELT (tm_alias_pairs
, i
, p
)
5720 struct cgraph_node
*src_n
= cgraph_get_node (src
);
5721 struct cgraph_node
*dst_n
= cgraph_get_node (dst
);
5723 /* The function ipa_tm_create_version() marks the clone as needed if
5724 the original function was needed. But we also mark the clone as
5725 needed if we ever called the clone indirectly through
5726 TM_GETTMCLONE. If neither of these are true, we didn't generate
5727 a clone, and we didn't call it indirectly... no sense keeping it
5728 in the clone table. */
5729 if (!dst_n
|| !dst_n
->definition
)
5732 /* This covers the case where we have optimized the original
5733 function away, and only access the transactional clone. */
5734 if (!src_n
|| !src_n
->definition
)
5739 switch_to_section (targetm
.asm_out
.tm_clone_table_section ());
5740 assemble_align (POINTER_SIZE
);
5744 assemble_integer (XEXP (DECL_RTL (src
), 0),
5745 POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
5746 assemble_integer (XEXP (DECL_RTL (dst
), 0),
5747 POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
5751 /* Provide a default for the tm_clone_table section. */
5754 default_clone_table_section (void)
5756 return get_named_section (NULL
, ".tm_clone_table", 3);
5759 /* Helper comparison function for qsorting by the DECL_UID stored in
5760 alias_pair->emitted_diags. */
5763 tm_alias_pair_cmp (const void *x
, const void *y
)
5765 const tm_alias_pair
*p1
= (const tm_alias_pair
*) x
;
5766 const tm_alias_pair
*p2
= (const tm_alias_pair
*) y
;
5767 if (p1
->uid
< p2
->uid
)
5769 if (p1
->uid
> p2
->uid
)
5775 finish_tm_clone_pairs (void)
5777 vec
<tm_alias_pair
> tm_alias_pairs
= vNULL
;
5779 if (tm_clone_hash
== NULL
)
5782 /* We need a determenistic order for the .tm_clone_table, otherwise
5783 we will get bootstrap comparison failures, so dump the hash table
5784 to a vector, sort it, and dump the vector. */
5786 /* Dump the hashtable to a vector. */
5787 htab_traverse_noresize (tm_clone_hash
, dump_tm_clone_to_vec
,
5788 (void *) &tm_alias_pairs
);
5790 tm_alias_pairs
.qsort (tm_alias_pair_cmp
);
5793 dump_tm_clone_pairs (tm_alias_pairs
);
5795 htab_delete (tm_clone_hash
);
5796 tm_clone_hash
= NULL
;
5797 tm_alias_pairs
.release ();
5801 /* Emit an assembler directive to set symbol for DECL visibility to
5802 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5805 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5806 int vis ATTRIBUTE_UNUSED
)
5808 #ifdef HAVE_GAS_HIDDEN
5809 static const char * const visibility_types
[] = {
5810 NULL
, "protected", "hidden", "internal"
5813 const char *name
, *type
;
5815 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5816 type
= visibility_types
[vis
];
5818 fprintf (asm_out_file
, "\t.%s\t", type
);
5819 assemble_name (asm_out_file
, name
);
5820 fprintf (asm_out_file
, "\n");
5822 if (!DECL_ARTIFICIAL (decl
))
5823 warning (OPT_Wattributes
, "visibility attribute not supported "
5824 "in this configuration; ignored");
5828 /* A helper function to call assemble_visibility when needed for a decl. */
5831 maybe_assemble_visibility (tree decl
)
5833 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5835 if (vis
!= VISIBILITY_DEFAULT
)
5837 targetm
.asm_out
.assemble_visibility (decl
, vis
);
5844 /* Returns 1 if the target configuration supports defining public symbols
5845 so that one of them will be chosen at link time instead of generating a
5846 multiply-defined symbol error, whether through the use of weak symbols or
5847 a target-specific mechanism for having duplicates discarded. */
5850 supports_one_only (void)
5852 if (SUPPORTS_ONE_ONLY
)
5854 return TARGET_SUPPORTS_WEAK
;
5857 /* Set up DECL as a public symbol that can be defined in multiple
5858 translation units without generating a linker error. */
5861 make_decl_one_only (tree decl
, tree comdat_group
)
5863 struct symtab_node
*symbol
;
5864 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5865 || TREE_CODE (decl
) == FUNCTION_DECL
);
5867 TREE_PUBLIC (decl
) = 1;
5869 if (TREE_CODE (decl
) == VAR_DECL
)
5870 symbol
= varpool_node_for_decl (decl
);
5872 symbol
= cgraph_get_create_node (decl
);
5874 if (SUPPORTS_ONE_ONLY
)
5876 #ifdef MAKE_DECL_ONE_ONLY
5877 MAKE_DECL_ONE_ONLY (decl
);
5879 symbol
->set_comdat_group (comdat_group
);
5881 else if (TREE_CODE (decl
) == VAR_DECL
5882 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5883 DECL_COMMON (decl
) = 1;
5886 gcc_assert (TARGET_SUPPORTS_WEAK
);
5887 DECL_WEAK (decl
) = 1;
5892 init_varasm_once (void)
5894 section_htab
= htab_create_ggc (31, section_entry_hash
,
5895 section_entry_eq
, NULL
);
5896 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
5897 object_block_entry_eq
, NULL
);
5898 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
5899 const_desc_eq
, NULL
);
5901 const_alias_set
= new_alias_set ();
5902 shared_constant_pool
= create_constant_pool ();
5904 #ifdef TEXT_SECTION_ASM_OP
5905 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
5906 TEXT_SECTION_ASM_OP
);
5909 #ifdef DATA_SECTION_ASM_OP
5910 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5911 DATA_SECTION_ASM_OP
);
5914 #ifdef SDATA_SECTION_ASM_OP
5915 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5916 SDATA_SECTION_ASM_OP
);
5919 #ifdef READONLY_DATA_SECTION_ASM_OP
5920 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
5921 READONLY_DATA_SECTION_ASM_OP
);
5924 #ifdef CTORS_SECTION_ASM_OP
5925 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
5926 CTORS_SECTION_ASM_OP
);
5929 #ifdef DTORS_SECTION_ASM_OP
5930 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
5931 DTORS_SECTION_ASM_OP
);
5934 #ifdef BSS_SECTION_ASM_OP
5935 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5936 output_section_asm_op
,
5937 BSS_SECTION_ASM_OP
);
5940 #ifdef SBSS_SECTION_ASM_OP
5941 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5942 output_section_asm_op
,
5943 SBSS_SECTION_ASM_OP
);
5946 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5947 | SECTION_COMMON
, emit_tls_common
);
5948 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5949 | SECTION_COMMON
, emit_local
);
5950 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5951 | SECTION_COMMON
, emit_common
);
5953 #if defined ASM_OUTPUT_ALIGNED_BSS
5954 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
5958 targetm
.asm_out
.init_sections ();
5960 if (readonly_data_section
== NULL
)
5961 readonly_data_section
= text_section
;
5963 #ifdef ASM_OUTPUT_EXTERNAL
5964 pending_assemble_externals_set
= pointer_set_create ();
5969 decl_default_tls_model (const_tree decl
)
5971 enum tls_model kind
;
5974 is_local
= targetm
.binds_local_p (decl
);
5978 kind
= TLS_MODEL_LOCAL_EXEC
;
5980 kind
= TLS_MODEL_INITIAL_EXEC
;
5983 /* Local dynamic is inefficient when we're not combining the
5984 parts of the address. */
5985 else if (optimize
&& is_local
)
5986 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
5988 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
5989 if (kind
< flag_tls_default
)
5990 kind
= flag_tls_default
;
5995 /* Select a set of attributes for section NAME based on the properties
5996 of DECL and whether or not RELOC indicates that DECL's initializer
5997 might contain runtime relocations.
5999 We make the section read-only and executable for a function decl,
6000 read-only for a const data decl, and writable for a non-const data decl. */
6003 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6007 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6008 flags
= SECTION_CODE
;
6011 enum section_category category
6012 = categorize_decl_for_section (decl
, reloc
);
6013 if (decl_readonly_section_1 (category
))
6015 else if (category
== SECCAT_DATA_REL_RO
6016 || category
== SECCAT_DATA_REL_RO_LOCAL
)
6017 flags
= SECTION_WRITE
| SECTION_RELRO
;
6019 flags
= SECTION_WRITE
;
6023 flags
= SECTION_WRITE
;
6024 if (strcmp (name
, ".data.rel.ro") == 0
6025 || strcmp (name
, ".data.rel.ro.local") == 0)
6026 flags
|= SECTION_RELRO
;
6029 if (decl
&& DECL_P (decl
) && DECL_COMDAT_GROUP (decl
))
6030 flags
|= SECTION_LINKONCE
;
6032 if (strcmp (name
, ".vtable_map_vars") == 0)
6033 flags
|= SECTION_LINKONCE
;
6035 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6036 flags
|= SECTION_TLS
| SECTION_WRITE
;
6038 if (strcmp (name
, ".bss") == 0
6039 || strncmp (name
, ".bss.", 5) == 0
6040 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6041 || strcmp (name
, ".sbss") == 0
6042 || strncmp (name
, ".sbss.", 6) == 0
6043 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6044 flags
|= SECTION_BSS
;
6046 if (strcmp (name
, ".tdata") == 0
6047 || strncmp (name
, ".tdata.", 7) == 0
6048 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6049 flags
|= SECTION_TLS
;
6051 if (strcmp (name
, ".tbss") == 0
6052 || strncmp (name
, ".tbss.", 6) == 0
6053 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6054 flags
|= SECTION_TLS
| SECTION_BSS
;
6056 /* These three sections have special ELF types. They are neither
6057 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6058 want to print a section type (@progbits or @nobits). If someone
6059 is silly enough to emit code or TLS variables to one of these
6060 sections, then don't handle them specially. */
6061 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
6062 && (strcmp (name
, ".init_array") == 0
6063 || strcmp (name
, ".fini_array") == 0
6064 || strcmp (name
, ".preinit_array") == 0))
6065 flags
|= SECTION_NOTYPE
;
6070 /* Return true if the target supports some form of global BSS,
6071 either through bss_noswitch_section, or by selecting a BSS
6072 section in TARGET_ASM_SELECT_SECTION. */
6075 have_global_bss_p (void)
6077 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6080 /* Output assembly to switch to section NAME with attribute FLAGS.
6081 Four variants for common object file formats. */
6084 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6085 unsigned int flags ATTRIBUTE_UNUSED
,
6086 tree decl ATTRIBUTE_UNUSED
)
6088 /* Some object formats don't support named sections at all. The
6089 front-end should already have flagged this as an error. */
6093 #ifndef TLS_SECTION_ASM_FLAG
6094 #define TLS_SECTION_ASM_FLAG 'T'
6098 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6099 tree decl ATTRIBUTE_UNUSED
)
6101 char flagchars
[10], *f
= flagchars
;
6103 /* If we have already declared this section, we can use an
6104 abbreviated form to switch back to it -- unless this section is
6105 part of a COMDAT groups, in which case GAS requires the full
6106 declaration every time. */
6107 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6108 && (flags
& SECTION_DECLARED
))
6110 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6114 if (!(flags
& SECTION_DEBUG
))
6116 if (flags
& SECTION_EXCLUDE
)
6118 if (flags
& SECTION_WRITE
)
6120 if (flags
& SECTION_CODE
)
6122 if (flags
& SECTION_SMALL
)
6124 if (flags
& SECTION_MERGE
)
6126 if (flags
& SECTION_STRINGS
)
6128 if (flags
& SECTION_TLS
)
6129 *f
++ = TLS_SECTION_ASM_FLAG
;
6130 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6134 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6136 if (!(flags
& SECTION_NOTYPE
))
6141 if (flags
& SECTION_BSS
)
6147 /* On platforms that use "@" as the assembly comment character,
6149 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6151 fprintf (asm_out_file
, format
, type
);
6153 if (flags
& SECTION_ENTSIZE
)
6154 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6155 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6157 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6158 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6160 fprintf (asm_out_file
, ",%s,comdat",
6161 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6165 putc ('\n', asm_out_file
);
6169 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6170 tree decl ATTRIBUTE_UNUSED
)
6172 char flagchars
[8], *f
= flagchars
;
6174 if (flags
& SECTION_WRITE
)
6176 if (flags
& SECTION_CODE
)
6180 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6184 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6187 default_coff_asm_named_section (name
, flags
, decl
);
6189 if (flags
& SECTION_LINKONCE
)
6191 /* Functions may have been compiled at various levels of
6192 optimization so we can't use `same_size' here.
6193 Instead, have the linker pick one. */
6194 fprintf (asm_out_file
, "\t.linkonce %s\n",
6195 (flags
& SECTION_CODE
? "discard" : "same_size"));
6199 /* The lame default section selector. */
6202 default_select_section (tree decl
, int reloc
,
6203 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6207 if (decl_readonly_section (decl
, reloc
))
6208 return readonly_data_section
;
6210 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6212 if (! ((flag_pic
&& reloc
)
6213 || !TREE_READONLY (decl
)
6214 || TREE_SIDE_EFFECTS (decl
)
6215 || !TREE_CONSTANT (decl
)))
6216 return readonly_data_section
;
6218 else if (TREE_CODE (decl
) == STRING_CST
)
6219 return readonly_data_section
;
6220 else if (! (flag_pic
&& reloc
))
6221 return readonly_data_section
;
6223 return data_section
;
6226 enum section_category
6227 categorize_decl_for_section (const_tree decl
, int reloc
)
6229 enum section_category ret
;
6231 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6233 else if (TREE_CODE (decl
) == STRING_CST
)
6235 if ((flag_sanitize
& SANITIZE_ADDRESS
)
6236 && asan_protect_global (CONST_CAST_TREE (decl
)))
6237 /* or !flag_merge_constants */
6238 return SECCAT_RODATA
;
6240 return SECCAT_RODATA_MERGE_STR
;
6242 else if (TREE_CODE (decl
) == VAR_DECL
)
6244 if (bss_initializer_p (decl
))
6246 else if (! TREE_READONLY (decl
)
6247 || TREE_SIDE_EFFECTS (decl
)
6248 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6250 /* Here the reloc_rw_mask is not testing whether the section should
6251 be read-only or not, but whether the dynamic link will have to
6252 do something. If so, we wish to segregate the data in order to
6253 minimize cache misses inside the dynamic linker. */
6254 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6255 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6259 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6260 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6261 else if (reloc
|| flag_merge_constants
< 2
6262 || ((flag_sanitize
& SANITIZE_ADDRESS
)
6263 && asan_protect_global (CONST_CAST_TREE (decl
))))
6264 /* C and C++ don't allow different variables to share the same
6265 location. -fmerge-all-constants allows even that (at the
6266 expense of not conforming). */
6267 ret
= SECCAT_RODATA
;
6268 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6269 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6271 ret
= SECCAT_RODATA_MERGE_CONST
;
6273 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6275 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6276 || TREE_SIDE_EFFECTS (decl
)
6277 || ! TREE_CONSTANT (decl
))
6280 ret
= SECCAT_RODATA
;
6283 ret
= SECCAT_RODATA
;
6285 /* There are no read-only thread-local sections. */
6286 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6288 /* Note that this would be *just* SECCAT_BSS, except that there's
6289 no concept of a read-only thread-local-data section. */
6290 if (ret
== SECCAT_BSS
6291 || (flag_zero_initialized_in_bss
6292 && initializer_zerop (DECL_INITIAL (decl
))))
6298 /* If the target uses small data sections, select it. */
6299 else if (targetm
.in_small_data_p (decl
))
6301 if (ret
== SECCAT_BSS
)
6303 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6304 ret
= SECCAT_SRODATA
;
6313 decl_readonly_section_1 (enum section_category category
)
6318 case SECCAT_RODATA_MERGE_STR
:
6319 case SECCAT_RODATA_MERGE_STR_INIT
:
6320 case SECCAT_RODATA_MERGE_CONST
:
6321 case SECCAT_SRODATA
:
6329 decl_readonly_section (const_tree decl
, int reloc
)
6331 return decl_readonly_section_1 (categorize_decl_for_section (decl
, reloc
));
6334 /* Select a section based on the above categorization. */
6337 default_elf_select_section (tree decl
, int reloc
,
6338 unsigned HOST_WIDE_INT align
)
6341 switch (categorize_decl_for_section (decl
, reloc
))
6344 /* We're not supposed to be called on FUNCTION_DECLs. */
6347 return readonly_data_section
;
6348 case SECCAT_RODATA_MERGE_STR
:
6349 return mergeable_string_section (decl
, align
, 0);
6350 case SECCAT_RODATA_MERGE_STR_INIT
:
6351 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6352 case SECCAT_RODATA_MERGE_CONST
:
6353 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6354 case SECCAT_SRODATA
:
6358 return data_section
;
6359 case SECCAT_DATA_REL
:
6360 sname
= ".data.rel";
6362 case SECCAT_DATA_REL_LOCAL
:
6363 sname
= ".data.rel.local";
6365 case SECCAT_DATA_REL_RO
:
6366 sname
= ".data.rel.ro";
6368 case SECCAT_DATA_REL_RO_LOCAL
:
6369 sname
= ".data.rel.ro.local";
6392 return get_named_section (decl
, sname
, reloc
);
6395 /* Construct a unique section name based on the decl name and the
6396 categorization performed above. */
6399 default_unique_section (tree decl
, int reloc
)
6401 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6402 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6403 const char *prefix
, *name
, *linkonce
;
6406 switch (categorize_decl_for_section (decl
, reloc
))
6409 prefix
= one_only
? ".t" : ".text";
6412 case SECCAT_RODATA_MERGE_STR
:
6413 case SECCAT_RODATA_MERGE_STR_INIT
:
6414 case SECCAT_RODATA_MERGE_CONST
:
6415 prefix
= one_only
? ".r" : ".rodata";
6417 case SECCAT_SRODATA
:
6418 prefix
= one_only
? ".s2" : ".sdata2";
6421 prefix
= one_only
? ".d" : ".data";
6423 case SECCAT_DATA_REL
:
6424 prefix
= one_only
? ".d.rel" : ".data.rel";
6426 case SECCAT_DATA_REL_LOCAL
:
6427 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6429 case SECCAT_DATA_REL_RO
:
6430 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6432 case SECCAT_DATA_REL_RO_LOCAL
:
6433 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6436 prefix
= one_only
? ".s" : ".sdata";
6439 prefix
= one_only
? ".b" : ".bss";
6442 prefix
= one_only
? ".sb" : ".sbss";
6445 prefix
= one_only
? ".td" : ".tdata";
6448 prefix
= one_only
? ".tb" : ".tbss";
6454 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6455 name
= targetm
.strip_name_encoding (name
);
6457 /* If we're using one_only, then there needs to be a .gnu.linkonce
6458 prefix to the section name. */
6459 linkonce
= one_only
? ".gnu.linkonce" : "";
6461 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6463 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6466 /* Like compute_reloc_for_constant, except for an RTX. The return value
6467 is a mask for which bit 1 indicates a global relocation, and bit 0
6468 indicates a local relocation. */
6471 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6473 int *preloc
= (int *) data
;
6476 switch (GET_CODE (x
))
6479 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6492 compute_reloc_for_rtx (rtx x
)
6496 switch (GET_CODE (x
))
6502 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6511 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6513 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6515 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6516 return data_section
;
6518 return readonly_data_section
;
6522 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6523 unsigned HOST_WIDE_INT align
)
6525 int reloc
= compute_reloc_for_rtx (x
);
6527 /* ??? Handle small data here somehow. */
6529 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6532 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6534 return get_named_section (NULL
, ".data.rel.ro", 3);
6537 return mergeable_constant_section (mode
, align
, 0);
6540 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6543 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6548 /* Careful not to prod global register variables. */
6551 symbol
= XEXP (rtl
, 0);
6552 if (GET_CODE (symbol
) != SYMBOL_REF
)
6555 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6556 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6557 flags
|= SYMBOL_FLAG_FUNCTION
;
6558 if (targetm
.binds_local_p (decl
))
6559 flags
|= SYMBOL_FLAG_LOCAL
;
6560 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6561 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6562 else if (targetm
.in_small_data_p (decl
))
6563 flags
|= SYMBOL_FLAG_SMALL
;
6564 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6565 being PUBLIC, the thing *must* be defined in this translation unit.
6566 Prevent this buglet from being propagated into rtl code as well. */
6567 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6568 flags
|= SYMBOL_FLAG_EXTERNAL
;
6570 SYMBOL_REF_FLAGS (symbol
) = flags
;
6573 /* By default, we do nothing for encode_section_info, so we need not
6574 do anything but discard the '*' marker. */
6577 default_strip_name_encoding (const char *str
)
6579 return str
+ (*str
== '*');
6582 #ifdef ASM_OUTPUT_DEF
6583 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6584 anchor relative to ".", the current section position. */
6587 default_asm_output_anchor (rtx symbol
)
6591 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6592 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6593 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6597 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6600 default_use_anchors_for_symbol_p (const_rtx symbol
)
6605 /* Don't use anchors for mergeable sections. The linker might move
6606 the objects around. */
6607 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6608 if (sect
->common
.flags
& SECTION_MERGE
)
6611 /* Don't use anchors for small data sections. The small data register
6612 acts as an anchor for such sections. */
6613 if (sect
->common
.flags
& SECTION_SMALL
)
6616 decl
= SYMBOL_REF_DECL (symbol
);
6617 if (decl
&& DECL_P (decl
))
6619 /* Don't use section anchors for decls that might be defined or
6620 usurped by other modules. */
6621 if (TREE_PUBLIC (decl
) && !decl_binds_to_current_def_p (decl
))
6624 /* Don't use section anchors for decls that will be placed in a
6625 small data section. */
6626 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6627 one above. The problem is that we only use SECTION_SMALL for
6628 sections that should be marked as small in the section directive. */
6629 if (targetm
.in_small_data_p (decl
))
6635 /* Return true when RESOLUTION indicate that symbol will be bound to the
6636 definition provided by current .o file. */
6639 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
6641 return (resolution
== LDPR_PREVAILING_DEF
6642 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6643 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
6646 /* Return true when RESOLUTION indicate that symbol will be bound locally
6647 within current executable or DSO. */
6650 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
6652 return (resolution
== LDPR_PREVAILING_DEF
6653 || resolution
== LDPR_PREVAILING_DEF_IRONLY
6654 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6655 || resolution
== LDPR_PREEMPTED_REG
6656 || resolution
== LDPR_PREEMPTED_IR
6657 || resolution
== LDPR_RESOLVED_IR
6658 || resolution
== LDPR_RESOLVED_EXEC
);
6661 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6662 wrt cross-module name binding. */
6665 default_binds_local_p (const_tree exp
)
6667 return default_binds_local_p_1 (exp
, flag_shlib
);
6671 default_binds_local_p_1 (const_tree exp
, int shlib
)
6674 bool resolved_locally
= false;
6675 bool resolved_to_local_def
= false;
6677 /* With resolution file in hands, take look into resolutions.
6678 We can't just return true for resolved_locally symbols,
6679 because dynamic linking might overwrite symbols
6680 in shared libraries. */
6681 if (TREE_CODE (exp
) == VAR_DECL
&& TREE_PUBLIC (exp
)
6682 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
6684 varpool_node
*vnode
= varpool_get_node (exp
);
6685 if (vnode
&& (resolution_local_p (vnode
->resolution
) || vnode
->in_other_partition
))
6686 resolved_locally
= true;
6688 && resolution_to_local_definition_p (vnode
->resolution
))
6689 resolved_to_local_def
= true;
6691 else if (TREE_CODE (exp
) == FUNCTION_DECL
&& TREE_PUBLIC (exp
))
6693 struct cgraph_node
*node
= cgraph_get_node (exp
);
6695 && (resolution_local_p (node
->resolution
) || node
->in_other_partition
))
6696 resolved_locally
= true;
6698 && resolution_to_local_definition_p (node
->resolution
))
6699 resolved_to_local_def
= true;
6702 /* A non-decl is an entry in the constant pool. */
6705 /* Weakrefs may not bind locally, even though the weakref itself is always
6706 static and therefore local. Similarly, the resolver for ifunc functions
6707 might resolve to a non-local function.
6708 FIXME: We can resolve the weakref case more curefuly by looking at the
6710 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
))
6711 || (TREE_CODE (exp
) == FUNCTION_DECL
6712 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (exp
))))
6714 /* Static variables are always local. */
6715 else if (! TREE_PUBLIC (exp
))
6717 /* A variable is local if the user has said explicitly that it will
6719 else if ((DECL_VISIBILITY_SPECIFIED (exp
)
6720 || resolved_to_local_def
)
6721 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6723 /* Variables defined outside this object might not be local. */
6724 else if (DECL_EXTERNAL (exp
) && !resolved_locally
)
6726 /* If defined in this object and visibility is not default, must be
6728 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6730 /* Default visibility weak data can be overridden by a strong symbol
6731 in another module and so are not local. */
6732 else if (DECL_WEAK (exp
)
6733 && !resolved_locally
)
6735 /* If PIC, then assume that any global name can be overridden by
6736 symbols resolved from other modules. */
6739 /* Uninitialized COMMON variable may be unified with symbols
6740 resolved from other modules. */
6741 else if (DECL_COMMON (exp
)
6742 && !resolved_locally
6743 && (DECL_INITIAL (exp
) == NULL
6744 || DECL_INITIAL (exp
) == error_mark_node
))
6746 /* Otherwise we're left with initialized (or non-common) global data
6747 which is of necessity defined locally. */
6754 /* Return true when references to DECL must bind to current definition in
6757 The condition is usually equivalent to whether the function binds to the
6758 current module (shared library or executable), that is to binds_local_p.
6759 We use this fact to avoid need for another target hook and implement
6760 the logic using binds_local_p and just special cases where
6761 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
6762 the weak definitions (that can be overwritten at linktime by other
6763 definition from different object file) and when resolution info is available
6764 we simply use the knowledge passed to us by linker plugin. */
6766 decl_binds_to_current_def_p (tree decl
)
6768 gcc_assert (DECL_P (decl
));
6769 if (!targetm
.binds_local_p (decl
))
6771 if (!TREE_PUBLIC (decl
))
6773 /* When resolution is available, just use it. */
6774 if (TREE_CODE (decl
) == VAR_DECL
6775 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
6777 varpool_node
*vnode
= varpool_get_node (decl
);
6779 && vnode
->resolution
!= LDPR_UNKNOWN
)
6780 return resolution_to_local_definition_p (vnode
->resolution
);
6782 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
6784 struct cgraph_node
*node
= cgraph_get_node (decl
);
6786 && node
->resolution
!= LDPR_UNKNOWN
)
6787 return resolution_to_local_definition_p (node
->resolution
);
6789 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
6790 binds locally but still can be overwritten), DECL_COMMON (can be merged
6791 with a non-common definition somewhere in the same module) or
6793 This rely on fact that binds_local_p behave as decl_replaceable_p
6794 for all other declaration types. */
6795 if (DECL_WEAK (decl
))
6797 if (DECL_COMMON (decl
)
6798 && (DECL_INITIAL (decl
) == NULL
6799 || DECL_INITIAL (decl
) == error_mark_node
))
6801 if (DECL_EXTERNAL (decl
))
6806 /* A replaceable function or variable is one which may be replaced
6807 at link-time with an entirely different definition, provided that the
6808 replacement has the same type. For example, functions declared
6809 with __attribute__((weak)) on most systems are replaceable.
6811 COMDAT functions are not replaceable, since all definitions of the
6812 function must be equivalent. It is important that COMDAT functions
6813 not be treated as replaceable so that use of C++ template
6814 instantiations is not penalized. */
6817 decl_replaceable_p (tree decl
)
6819 gcc_assert (DECL_P (decl
));
6820 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
6822 return !decl_binds_to_current_def_p (decl
);
6825 /* Default function to output code that will globalize a label. A
6826 target must define GLOBAL_ASM_OP or provide its own function to
6827 globalize a label. */
6828 #ifdef GLOBAL_ASM_OP
6830 default_globalize_label (FILE * stream
, const char *name
)
6832 fputs (GLOBAL_ASM_OP
, stream
);
6833 assemble_name (stream
, name
);
6834 putc ('\n', stream
);
6836 #endif /* GLOBAL_ASM_OP */
6838 /* Default function to output code that will globalize a declaration. */
6840 default_globalize_decl_name (FILE * stream
, tree decl
)
6842 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6843 targetm
.asm_out
.globalize_label (stream
, name
);
6846 /* Default function to output a label for unwind information. The
6847 default is to do nothing. A target that needs nonlocal labels for
6848 unwind information must provide its own function to do this. */
6850 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6851 tree decl ATTRIBUTE_UNUSED
,
6852 int for_eh ATTRIBUTE_UNUSED
,
6853 int empty ATTRIBUTE_UNUSED
)
6857 /* Default function to output a label to divide up the exception table.
6858 The default is to do nothing. A target that needs/wants to divide
6859 up the table must provide it's own function to do this. */
6861 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6865 /* This is how to output an internal numbered label where PREFIX is
6866 the class of label and LABELNO is the number within the class. */
6869 default_generate_internal_label (char *buf
, const char *prefix
,
6870 unsigned long labelno
)
6872 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6875 /* This is how to output an internal numbered label where PREFIX is
6876 the class of label and LABELNO is the number within the class. */
6879 default_internal_label (FILE *stream
, const char *prefix
,
6880 unsigned long labelno
)
6882 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6883 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6884 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6888 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6891 default_asm_declare_constant_name (FILE *file
, const char *name
,
6892 const_tree exp ATTRIBUTE_UNUSED
,
6893 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
6895 assemble_label (file
, name
);
6898 /* This is the default behavior at the beginning of a file. It's
6899 controlled by two other target-hook toggles. */
6901 default_file_start (void)
6903 if (targetm
.asm_file_start_app_off
6904 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6905 fputs (ASM_APP_OFF
, asm_out_file
);
6907 if (targetm
.asm_file_start_file_directive
)
6908 output_file_directive (asm_out_file
, main_input_filename
);
6911 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6912 which emits a special section directive used to indicate whether or
6913 not this object file needs an executable stack. This is primarily
6914 a GNU extension to ELF but could be used on other targets. */
6916 int trampolines_created
;
6919 file_end_indicate_exec_stack (void)
6921 unsigned int flags
= SECTION_DEBUG
;
6922 if (trampolines_created
)
6923 flags
|= SECTION_CODE
;
6925 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6928 /* Emit a special section directive to indicate that this object file
6929 was compiled with -fsplit-stack. This is used to let the linker
6930 detect calls between split-stack code and non-split-stack code, so
6931 that it can modify the split-stack code to allocate a sufficiently
6932 large stack. We emit another special section if there are any
6933 functions in this file which have the no_split_stack attribute, to
6934 prevent the linker from warning about being unable to convert the
6935 functions if they call non-split-stack code. */
6938 file_end_indicate_split_stack (void)
6940 if (flag_split_stack
)
6942 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
6944 if (saw_no_split_stack
)
6945 switch_to_section (get_section (".note.GNU-no-split-stack",
6946 SECTION_DEBUG
, NULL
));
6950 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6951 a get_unnamed_section callback. */
6954 output_section_asm_op (const void *directive
)
6956 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
6959 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6960 the current section is NEW_SECTION. */
6963 switch_to_section (section
*new_section
)
6965 if (in_section
== new_section
)
6968 if (new_section
->common
.flags
& SECTION_FORGET
)
6971 in_section
= new_section
;
6973 switch (SECTION_STYLE (new_section
))
6976 targetm
.asm_out
.named_section (new_section
->named
.name
,
6977 new_section
->named
.common
.flags
,
6978 new_section
->named
.decl
);
6981 case SECTION_UNNAMED
:
6982 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
6985 case SECTION_NOSWITCH
:
6990 new_section
->common
.flags
|= SECTION_DECLARED
;
6993 /* If block symbol SYMBOL has not yet been assigned an offset, place
6994 it at the end of its block. */
6997 place_block_symbol (rtx symbol
)
6999 unsigned HOST_WIDE_INT size
, mask
, offset
;
7000 struct constant_descriptor_rtx
*desc
;
7001 unsigned int alignment
;
7002 struct object_block
*block
;
7005 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
7006 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
7009 /* Work out the symbol's size and alignment. */
7010 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7012 desc
= SYMBOL_REF_CONSTANT (symbol
);
7013 alignment
= desc
->align
;
7014 size
= GET_MODE_SIZE (desc
->mode
);
7016 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7018 decl
= SYMBOL_REF_DECL (symbol
);
7019 alignment
= DECL_ALIGN (decl
);
7020 size
= get_constant_size (DECL_INITIAL (decl
));
7021 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7022 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7023 && asan_protect_global (DECL_INITIAL (decl
)))
7024 size
+= asan_red_zone_size (size
);
7028 struct symtab_node
*snode
;
7029 decl
= SYMBOL_REF_DECL (symbol
);
7031 snode
= symtab_get_node (decl
);
7034 rtx target
= DECL_RTL (symtab_alias_ultimate_target (snode
)->decl
);
7036 place_block_symbol (target
);
7037 SYMBOL_REF_BLOCK_OFFSET (symbol
) = SYMBOL_REF_BLOCK_OFFSET (target
);
7040 alignment
= get_variable_align (decl
);
7041 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7042 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7043 && asan_protect_global (decl
))
7045 size
+= asan_red_zone_size (size
);
7046 alignment
= MAX (alignment
,
7047 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
7051 /* Calculate the object's offset from the start of the block. */
7052 block
= SYMBOL_REF_BLOCK (symbol
);
7053 mask
= alignment
/ BITS_PER_UNIT
- 1;
7054 offset
= (block
->size
+ mask
) & ~mask
;
7055 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
7057 /* Record the block's new alignment and size. */
7058 block
->alignment
= MAX (block
->alignment
, alignment
);
7059 block
->size
= offset
+ size
;
7061 vec_safe_push (block
->objects
, symbol
);
7064 /* Return the anchor that should be used to address byte offset OFFSET
7065 from the first object in BLOCK. MODEL is the TLS model used
7069 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7070 enum tls_model model
)
7073 unsigned int begin
, middle
, end
;
7074 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7077 /* Work out the anchor's offset. Use an offset of 0 for the first
7078 anchor so that we don't pessimize the case where we take the address
7079 of a variable at the beginning of the block. This is particularly
7080 useful when a block has only one variable assigned to it.
7082 We try to place anchors RANGE bytes apart, so there can then be
7083 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7084 a ptr_mode offset. With some target settings, the lowest such
7085 anchor might be out of range for the lowest ptr_mode offset;
7086 likewise the highest anchor for the highest offset. Use anchors
7087 at the extreme ends of the ptr_mode range in such cases.
7089 All arithmetic uses unsigned integers in order to avoid
7091 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7092 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7093 range
= max_offset
- min_offset
+ 1;
7098 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
7101 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7102 delta
-= delta
% range
;
7105 offset
= (HOST_WIDE_INT
) (-delta
);
7109 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7110 delta
-= delta
% range
;
7111 if (delta
> bias
- 1)
7113 offset
= (HOST_WIDE_INT
) delta
;
7117 /* Do a binary search to see if there's already an anchor we can use.
7118 Set BEGIN to the new anchor's index if not. */
7120 end
= vec_safe_length (block
->anchors
);
7121 while (begin
!= end
)
7123 middle
= (end
+ begin
) / 2;
7124 anchor
= (*block
->anchors
)[middle
];
7125 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7127 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7129 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7131 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7137 /* Create a new anchor with a unique label. */
7138 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7139 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7140 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7141 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7143 /* Insert it at index BEGIN. */
7144 vec_safe_insert (block
->anchors
, begin
, anchor
);
7148 /* Output the objects in BLOCK. */
7151 output_object_block (struct object_block
*block
)
7153 struct constant_descriptor_rtx
*desc
;
7155 HOST_WIDE_INT offset
;
7159 if (!block
->objects
)
7162 /* Switch to the section and make sure that the first byte is
7163 suitably aligned. */
7164 switch_to_section (block
->sect
);
7165 assemble_align (block
->alignment
);
7167 /* Define the values of all anchors relative to the current section
7169 FOR_EACH_VEC_SAFE_ELT (block
->anchors
, i
, symbol
)
7170 targetm
.asm_out
.output_anchor (symbol
);
7172 /* Output the objects themselves. */
7174 FOR_EACH_VEC_ELT (*block
->objects
, i
, symbol
)
7176 /* Move to the object's offset, padding with zeros if necessary. */
7177 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7178 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7179 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7181 desc
= SYMBOL_REF_CONSTANT (symbol
);
7182 output_constant_pool_1 (desc
, 1);
7183 offset
+= GET_MODE_SIZE (desc
->mode
);
7185 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7188 decl
= SYMBOL_REF_DECL (symbol
);
7189 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
7191 size
= get_constant_size (DECL_INITIAL (decl
));
7193 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7194 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7195 && asan_protect_global (DECL_INITIAL (decl
)))
7197 size
= asan_red_zone_size (size
);
7198 assemble_zeros (size
);
7205 decl
= SYMBOL_REF_DECL (symbol
);
7206 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
7207 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7209 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7210 && asan_protect_global (decl
))
7212 size
= asan_red_zone_size (size
);
7213 assemble_zeros (size
);
7220 /* A htab_traverse callback used to call output_object_block for
7221 each member of object_block_htab. */
7224 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
7226 output_object_block ((struct object_block
*) (*slot
));
7230 /* Output the definitions of all object_blocks. */
7233 output_object_blocks (void)
7235 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
7238 /* This function provides a possible implementation of the
7239 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7240 by -frecord-gcc-switches it creates a new mergeable, string section in the
7241 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7242 contains the switches in ASCII format.
7244 FIXME: This code does not correctly handle double quote characters
7245 that appear inside strings, (it strips them rather than preserving them).
7246 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7247 characters - instead it treats them as sub-string separators. Since
7248 we want to emit NUL strings terminators into the object file we have to use
7252 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7256 case SWITCH_TYPE_PASSED
:
7257 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
7258 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7261 case SWITCH_TYPE_DESCRIPTIVE
:
7264 /* Distinguish between invocations where name is NULL. */
7265 static bool started
= false;
7271 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7275 | (SECTION_ENTSIZE
& 1),
7277 switch_to_section (sec
);
7286 /* The return value is currently ignored by the caller, but must be 0.
7287 For -fverbose-asm the return value would be the number of characters
7288 emitted into the assembler file. */
7292 /* Emit text to declare externally defined symbols. It is needed to
7293 properly support non-default visibility. */
7295 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7297 const char *name ATTRIBUTE_UNUSED
)
7299 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7300 set in order to avoid putting out names that are never really
7302 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7303 && targetm
.binds_local_p (decl
))
7304 maybe_assemble_visibility (decl
);
7307 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7310 default_asm_output_source_filename (FILE *file
, const char *name
)
7312 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7313 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
7315 fprintf (file
, "\t.file\t");
7316 output_quoted_string (file
, name
);
7321 /* Output a file name in the form wanted by System V. */
7324 output_file_directive (FILE *asm_file
, const char *input_name
)
7329 if (input_name
== NULL
)
7330 input_name
= "<stdin>";
7332 input_name
= remap_debug_filename (input_name
);
7334 len
= strlen (input_name
);
7335 na
= input_name
+ len
;
7337 /* NA gets INPUT_NAME sans directory names. */
7338 while (na
> input_name
)
7340 if (IS_DIR_SEPARATOR (na
[-1]))
7345 targetm
.asm_out
.output_source_filename (asm_file
, na
);
7348 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7351 make_debug_expr_from_rtl (const_rtx exp
)
7353 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7354 enum machine_mode mode
= GET_MODE (exp
);
7357 DECL_ARTIFICIAL (ddecl
) = 1;
7358 if (REG_P (exp
) && REG_EXPR (exp
))
7359 type
= TREE_TYPE (REG_EXPR (exp
));
7360 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7361 type
= TREE_TYPE (MEM_EXPR (exp
));
7364 if (type
&& TYPE_MODE (type
) == mode
)
7365 TREE_TYPE (ddecl
) = type
;
7367 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7368 DECL_MODE (ddecl
) = mode
;
7369 dval
= gen_rtx_DEBUG_EXPR (mode
);
7370 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7371 SET_DECL_RTL (ddecl
, dval
);
7375 #ifdef ELF_ASCII_ESCAPES
7376 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
7379 default_elf_asm_output_limited_string (FILE *f
, const char *s
)
7384 fputs (STRING_ASM_OP
, f
);
7389 escape
= ELF_ASCII_ESCAPES
[c
];
7396 /* TODO: Print in hex with fast function, important for -flto. */
7397 fprintf (f
, "\\%03o", c
);
7410 /* Default ASM_OUTPUT_ASCII for ELF targets. */
7413 default_elf_asm_output_ascii (FILE *f
, const char *s
, unsigned int len
)
7415 const char *limit
= s
+ len
;
7416 const char *last_null
= NULL
;
7417 unsigned bytes_in_chunk
= 0;
7421 for (; s
< limit
; s
++)
7425 if (bytes_in_chunk
>= 60)
7434 for (p
= s
; p
< limit
&& *p
!= '\0'; p
++)
7441 if (p
< limit
&& (p
- s
) <= (long) ELF_STRING_LIMIT
)
7443 if (bytes_in_chunk
> 0)
7450 default_elf_asm_output_limited_string (f
, s
);
7455 if (bytes_in_chunk
== 0)
7456 fputs (ASCII_DATA_ASM_OP
"\"", f
);
7459 escape
= ELF_ASCII_ESCAPES
[c
];
7467 /* TODO: Print in hex with fast function, important for -flto. */
7468 fprintf (f
, "\\%03o", c
);
7469 bytes_in_chunk
+= 4;
7474 bytes_in_chunk
+= 2;
7481 if (bytes_in_chunk
> 0)
7489 static GTY(()) section
*elf_init_array_section
;
7490 static GTY(()) section
*elf_fini_array_section
;
7493 get_elf_initfini_array_priority_section (int priority
,
7497 if (priority
!= DEFAULT_INIT_PRIORITY
)
7500 sprintf (buf
, "%s.%.5u",
7501 constructor_p
? ".init_array" : ".fini_array",
7503 sec
= get_section (buf
, SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7509 if (elf_init_array_section
== NULL
)
7510 elf_init_array_section
7511 = get_section (".init_array",
7512 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7513 sec
= elf_init_array_section
;
7517 if (elf_fini_array_section
== NULL
)
7518 elf_fini_array_section
7519 = get_section (".fini_array",
7520 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7521 sec
= elf_fini_array_section
;
7527 /* Use .init_array section for constructors. */
7530 default_elf_init_array_asm_out_constructor (rtx symbol
, int priority
)
7532 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7534 assemble_addr_to_section (symbol
, sec
);
7537 /* Use .fini_array section for destructors. */
7540 default_elf_fini_array_asm_out_destructor (rtx symbol
, int priority
)
7542 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7544 assemble_addr_to_section (symbol
, sec
);
7547 /* Default TARGET_ASM_OUTPUT_IDENT hook.
7549 This is a bit of a cheat. The real default is a no-op, but this
7550 hook is the default for all targets with a .ident directive. */
7553 default_asm_output_ident_directive (const char *ident_str
)
7555 const char *ident_asm_op
= "\t.ident\t";
7557 /* If we are still in the front end, do not write out the string
7558 to asm_out_file. Instead, add a fake top-level asm statement.
7559 This allows the front ends to use this hook without actually
7560 writing to asm_out_file, to handle #ident or Pragma Ident. */
7561 if (cgraph_state
== CGRAPH_STATE_PARSING
)
7563 char *buf
= ACONCAT ((ident_asm_op
, "\"", ident_str
, "\"\n", NULL
));
7564 add_asm_node (build_string (strlen (buf
), buf
));
7567 fprintf (asm_out_file
, "%s\"%s\"\n", ident_asm_op
, ident_str
);
7570 #include "gt-varasm.h"