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"
42 #include "hard-reg-set.h"
48 #include "diagnostic-core.h"
50 #include "langhooks.h"
54 #include "common/common-target.h"
55 #include "targhooks.h"
57 #include "dominance.h"
59 #include "basic-block.h"
62 #include "plugin-api.h"
67 #include "tree-chkp.h"
69 #ifdef XCOFF_DEBUGGING_INFO
70 #include "xcoffout.h" /* Needed for external data
71 declarations for e.g. AIX 4.x. */
74 /* The (assembler) name of the first globally-visible object output. */
75 extern GTY(()) const char *first_global_object_name
;
76 extern GTY(()) const char *weak_global_object_name
;
78 const char *first_global_object_name
;
79 const char *weak_global_object_name
;
82 struct constant_descriptor_rtx
;
83 struct rtx_constant_pool
;
85 #define n_deferred_constants (crtl->varasm.deferred_constants)
87 /* Number for making the label on the next
88 constant that is stored in memory. */
90 static GTY(()) int const_labelno
;
92 /* Carry information from ASM_DECLARE_OBJECT_NAME
93 to ASM_FINISH_DECLARE_OBJECT. */
95 int size_directive_output
;
97 /* The last decl for which assemble_variable was called,
98 if it did ASM_DECLARE_OBJECT_NAME.
99 If the last call to assemble_variable didn't do that,
102 tree last_assemble_variable_decl
;
104 /* The following global variable indicates if the first basic block
105 in a function belongs to the cold partition or not. */
107 bool first_function_block_is_cold
;
109 /* Whether we saw any functions with no_split_stack. */
111 static bool saw_no_split_stack
;
113 static const char *strip_reg_name (const char *);
114 static int contains_pointers_p (tree
);
115 #ifdef ASM_OUTPUT_EXTERNAL
116 static bool incorporeal_function_p (tree
);
118 static void decode_addr_const (tree
, struct addr_const
*);
119 static hashval_t
const_hash_1 (const tree
);
120 static int compare_constant (const tree
, const tree
);
121 static void output_constant_def_contents (rtx
);
122 static void output_addressed_constants (tree
);
123 static unsigned HOST_WIDE_INT
output_constant (tree
, unsigned HOST_WIDE_INT
,
125 static void globalize_decl (tree
);
126 static bool decl_readonly_section_1 (enum section_category
);
127 #ifdef BSS_SECTION_ASM_OP
128 #ifdef ASM_OUTPUT_ALIGNED_BSS
129 static void asm_output_aligned_bss (FILE *, tree
, const char *,
130 unsigned HOST_WIDE_INT
, int)
133 #endif /* BSS_SECTION_ASM_OP */
134 static void mark_weak (tree
);
135 static void output_constant_pool (const char *, tree
);
137 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
138 section
*text_section
;
139 section
*data_section
;
140 section
*readonly_data_section
;
141 section
*sdata_section
;
142 section
*ctors_section
;
143 section
*dtors_section
;
144 section
*bss_section
;
145 section
*sbss_section
;
147 /* Various forms of common section. All are guaranteed to be nonnull. */
148 section
*tls_comm_section
;
149 section
*comm_section
;
150 section
*lcomm_section
;
152 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
154 section
*bss_noswitch_section
;
156 /* The section that holds the main exception table, when known. The section
157 is set either by the target's init_sections hook or by the first call to
158 switch_to_exception_section. */
159 section
*exception_section
;
161 /* The section that holds the DWARF2 frame unwind information, when known.
162 The section is set either by the target's init_sections hook or by the
163 first call to switch_to_eh_frame_section. */
164 section
*eh_frame_section
;
166 /* asm_out_file's current section. This is NULL if no section has yet
167 been selected or if we lose track of what the current section is. */
170 /* True if code for the current function is currently being directed
171 at the cold section. */
172 bool in_cold_section_p
;
174 /* A linked list of all the unnamed sections. */
175 static GTY(()) section
*unnamed_sections
;
177 /* Return a nonzero value if DECL has a section attribute. */
178 #define IN_NAMED_SECTION(DECL) \
179 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
180 && DECL_SECTION_NAME (DECL) != NULL)
182 struct section_hasher
: ggc_hasher
<section
*>
184 typedef const char *compare_type
;
186 static hashval_t
hash (section
*);
187 static bool equal (section
*, const char *);
190 /* Hash table of named sections. */
191 static GTY(()) hash_table
<section_hasher
> *section_htab
;
193 struct object_block_hasher
: ggc_hasher
<object_block
*>
195 typedef const section
*compare_type
;
197 static hashval_t
hash (object_block
*);
198 static bool equal (object_block
*, const section
*);
201 /* A table of object_blocks, indexed by section. */
202 static GTY(()) hash_table
<object_block_hasher
> *object_block_htab
;
204 /* The next number to use for internal anchor labels. */
205 static GTY(()) int anchor_labelno
;
207 /* A pool of constants that can be shared between functions. */
208 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
210 /* Helper routines for maintaining section_htab. */
213 section_hasher::equal (section
*old
, const char *new_name
)
215 return strcmp (old
->named
.name
, new_name
) == 0;
219 section_hasher::hash (section
*old
)
221 return htab_hash_string (old
->named
.name
);
224 /* Return a hash value for section SECT. */
227 hash_section (section
*sect
)
229 if (sect
->common
.flags
& SECTION_NAMED
)
230 return htab_hash_string (sect
->named
.name
);
231 return sect
->common
.flags
;
234 /* Helper routines for maintaining object_block_htab. */
237 object_block_hasher::equal (object_block
*old
, const section
*new_section
)
239 return old
->sect
== new_section
;
243 object_block_hasher::hash (object_block
*old
)
245 return hash_section (old
->sect
);
248 /* Return a new unnamed section with the given fields. */
251 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
256 sect
= ggc_alloc
<section
> ();
257 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
258 sect
->unnamed
.callback
= callback
;
259 sect
->unnamed
.data
= data
;
260 sect
->unnamed
.next
= unnamed_sections
;
262 unnamed_sections
= sect
;
266 /* Return a SECTION_NOSWITCH section with the given fields. */
269 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
273 sect
= ggc_alloc
<section
> ();
274 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
275 sect
->noswitch
.callback
= callback
;
280 /* Return the named section structure associated with NAME. Create
281 a new section with the given fields if no such structure exists. */
284 get_section (const char *name
, unsigned int flags
, tree decl
)
286 section
*sect
, **slot
;
288 slot
= section_htab
->find_slot_with_hash (name
, htab_hash_string (name
),
290 flags
|= SECTION_NAMED
;
293 sect
= ggc_alloc
<section
> ();
294 sect
->named
.common
.flags
= flags
;
295 sect
->named
.name
= ggc_strdup (name
);
296 sect
->named
.decl
= decl
;
302 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
303 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
305 /* It is fine if one of the section flags is
306 SECTION_WRITE | SECTION_RELRO and the other has none of these
307 flags (i.e. read-only) in named sections and either the
308 section hasn't been declared yet or has been declared as writable.
309 In that case just make sure the resulting flags are
310 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
312 if (((sect
->common
.flags
^ flags
) & (SECTION_WRITE
| SECTION_RELRO
))
313 == (SECTION_WRITE
| SECTION_RELRO
)
314 && (sect
->common
.flags
315 & ~(SECTION_DECLARED
| SECTION_WRITE
| SECTION_RELRO
))
316 == (flags
& ~(SECTION_WRITE
| SECTION_RELRO
))
317 && ((sect
->common
.flags
& SECTION_DECLARED
) == 0
318 || (sect
->common
.flags
& SECTION_WRITE
)))
320 sect
->common
.flags
|= (SECTION_WRITE
| SECTION_RELRO
);
323 /* Sanity check user variables for flag changes. */
324 if (sect
->named
.decl
!= NULL
325 && DECL_P (sect
->named
.decl
)
326 && decl
!= sect
->named
.decl
)
328 if (decl
!= NULL
&& DECL_P (decl
))
329 error ("%+D causes a section type conflict with %D",
330 decl
, sect
->named
.decl
);
332 error ("section type conflict with %D", sect
->named
.decl
);
333 inform (DECL_SOURCE_LOCATION (sect
->named
.decl
),
334 "%qD was declared here", sect
->named
.decl
);
336 else if (decl
!= NULL
&& DECL_P (decl
))
337 error ("%+D causes a section type conflict", decl
);
339 error ("section type conflict");
340 /* Make sure we don't error about one section multiple times. */
341 sect
->common
.flags
|= SECTION_OVERRIDE
;
347 /* Return true if the current compilation mode benefits from having
348 objects grouped into blocks. */
351 use_object_blocks_p (void)
353 return flag_section_anchors
;
356 /* Return the object_block structure for section SECT. Create a new
357 structure if we haven't created one already. Return null if SECT
360 static struct object_block
*
361 get_block_for_section (section
*sect
)
363 struct object_block
*block
;
369 = object_block_htab
->find_slot_with_hash (sect
, hash_section (sect
),
374 block
= ggc_cleared_alloc
<object_block
> ();
381 /* Create a symbol with label LABEL and place it at byte offset
382 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
383 is not yet known. LABEL must be a garbage-collected string. */
386 create_block_symbol (const char *label
, struct object_block
*block
,
387 HOST_WIDE_INT offset
)
392 /* Create the extended SYMBOL_REF. */
393 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
394 symbol
= (rtx
) ggc_internal_alloc (size
);
396 /* Initialize the normal SYMBOL_REF fields. */
397 memset (symbol
, 0, size
);
398 PUT_CODE (symbol
, SYMBOL_REF
);
399 PUT_MODE (symbol
, Pmode
);
400 XSTR (symbol
, 0) = label
;
401 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
403 /* Initialize the block_symbol stuff. */
404 SYMBOL_REF_BLOCK (symbol
) = block
;
405 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
410 /* Return a section with a particular name and with whatever SECTION_*
411 flags section_type_flags deems appropriate. The name of the section
412 is taken from NAME if nonnull, otherwise it is taken from DECL's
413 DECL_SECTION_NAME. DECL is the decl associated with the section
414 (see the section comment for details) and RELOC is as for
415 section_type_flags. */
418 get_named_section (tree decl
, const char *name
, int reloc
)
424 gcc_assert (decl
&& DECL_P (decl
) && DECL_SECTION_NAME (decl
));
425 name
= DECL_SECTION_NAME (decl
);
428 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
429 return get_section (name
, flags
, decl
);
432 /* Worker for resolve_unique_section. */
435 set_implicit_section (struct symtab_node
*n
, void *data ATTRIBUTE_UNUSED
)
437 n
->implicit_section
= true;
441 /* If required, set DECL_SECTION_NAME to a unique name. */
444 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
445 int flag_function_or_data_sections
)
447 if (DECL_SECTION_NAME (decl
) == NULL
448 && targetm_common
.have_named_sections
449 && (flag_function_or_data_sections
450 || DECL_COMDAT_GROUP (decl
)))
452 targetm
.asm_out
.unique_section (decl
, reloc
);
453 if (DECL_SECTION_NAME (decl
))
454 symtab_node::get (decl
)->call_for_symbol_and_aliases
455 (set_implicit_section
, NULL
, true);
459 #ifdef BSS_SECTION_ASM_OP
461 #ifdef ASM_OUTPUT_ALIGNED_BSS
463 /* Utility function for targets to use in implementing
464 ASM_OUTPUT_ALIGNED_BSS.
465 ??? It is believed that this function will work in most cases so such
466 support is localized here. */
469 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
470 const char *name
, unsigned HOST_WIDE_INT size
,
473 switch_to_section (bss_section
);
474 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
475 #ifdef ASM_DECLARE_OBJECT_NAME
476 last_assemble_variable_decl
= decl
;
477 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
479 /* Standard thing is just output label for the object. */
480 ASM_OUTPUT_LABEL (file
, name
);
481 #endif /* ASM_DECLARE_OBJECT_NAME */
482 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
487 #endif /* BSS_SECTION_ASM_OP */
489 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
490 /* Return the hot section for function DECL. Return text_section for
494 hot_function_section (tree decl
)
496 if (decl
!= NULL_TREE
497 && DECL_SECTION_NAME (decl
) != NULL
498 && targetm_common
.have_named_sections
)
499 return get_named_section (decl
, NULL
, 0);
505 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
508 When DECL_SECTION_NAME is non-NULL and it is implicit section and
509 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
510 concatenate the name with NAMED_SECTION_SUFFIX.
511 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
514 get_named_text_section (tree decl
,
515 const char *text_section_name
,
516 const char *named_section_suffix
)
518 if (decl
&& DECL_SECTION_NAME (decl
))
520 if (named_section_suffix
)
522 const char *dsn
= DECL_SECTION_NAME (decl
);
523 const char *stripped_name
;
526 name
= (char *) alloca (strlen (dsn
) + 1);
530 stripped_name
= targetm
.strip_name_encoding (name
);
532 buffer
= ACONCAT ((stripped_name
, named_section_suffix
, NULL
));
533 return get_named_section (decl
, buffer
, 0);
535 else if (symtab_node::get (decl
)->implicit_section
)
539 /* Do not try to split gnu_linkonce functions. This gets somewhat
541 if (DECL_COMDAT_GROUP (decl
) && !HAVE_COMDAT_GROUP
)
543 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
544 name
= targetm
.strip_name_encoding (name
);
545 return get_named_section (decl
, ACONCAT ((text_section_name
, ".",
551 return get_named_section (decl
, text_section_name
, 0);
554 /* Choose named function section based on its frequency. */
557 default_function_section (tree decl
, enum node_frequency freq
,
558 bool startup
, bool exit
)
560 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
561 /* Old GNU linkers have buggy --gc-section support, which sometimes
562 results in .gcc_except_table* sections being garbage collected. */
564 && symtab_node::get (decl
)->implicit_section
)
568 if (!flag_reorder_functions
569 || !targetm_common
.have_named_sections
)
571 /* Startup code should go to startup subsection unless it is
572 unlikely executed (this happens especially with function splitting
573 where we can split away unnecessary parts of static constructors. */
574 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
576 /* If we do have a profile or(and) LTO phase is executed, we do not need
577 these ELF section. */
578 if (!in_lto_p
|| !flag_profile_values
)
579 return get_named_text_section (decl
, ".text.startup", NULL
);
584 /* Similarly for exit. */
585 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
586 return get_named_text_section (decl
, ".text.exit", NULL
);
588 /* Group cold functions together, similarly for hot code. */
591 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
592 return get_named_text_section (decl
, ".text.unlikely", NULL
);
593 case NODE_FREQUENCY_HOT
:
594 /* If we do have a profile or(and) LTO phase is executed, we do not need
595 these ELF section. */
596 if (!in_lto_p
|| !flag_profile_values
)
597 return get_named_text_section (decl
, ".text.hot", NULL
);
603 /* Return the section for function DECL.
605 If DECL is NULL_TREE, return the text section. We can be passed
606 NULL_TREE under some circumstances by dbxout.c at least.
608 If FORCE_COLD is true, return cold function section ignoring
609 the frequency info of cgraph_node. */
612 function_section_1 (tree decl
, bool force_cold
)
614 section
*section
= NULL
;
615 enum node_frequency freq
= NODE_FREQUENCY_NORMAL
;
616 bool startup
= false, exit
= false;
620 struct cgraph_node
*node
= cgraph_node::get (decl
);
624 freq
= node
->frequency
;
625 startup
= node
->only_called_at_startup
;
626 exit
= node
->only_called_at_exit
;
630 freq
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
632 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
633 if (decl
!= NULL_TREE
634 && DECL_SECTION_NAME (decl
) != NULL
)
636 if (targetm
.asm_out
.function_section
)
637 section
= targetm
.asm_out
.function_section (decl
, freq
,
641 return get_named_section (decl
, NULL
, 0);
644 return targetm
.asm_out
.select_section
645 (decl
, freq
== NODE_FREQUENCY_UNLIKELY_EXECUTED
,
648 if (targetm
.asm_out
.function_section
)
649 section
= targetm
.asm_out
.function_section (decl
, freq
, startup
, exit
);
652 return hot_function_section (decl
);
656 /* Return the section for function DECL.
658 If DECL is NULL_TREE, return the text section. We can be passed
659 NULL_TREE under some circumstances by dbxout.c at least. */
662 function_section (tree decl
)
664 /* Handle cases where function splitting code decides
665 to put function entry point into unlikely executed section
666 despite the fact that the function itself is not cold
667 (i.e. it is called rarely but contains a hot loop that is
668 better to live in hot subsection for the code locality). */
669 return function_section_1 (decl
,
670 first_function_block_is_cold
);
673 /* Return the section for the current function, take IN_COLD_SECTION_P
677 current_function_section (void)
679 return function_section_1 (current_function_decl
, in_cold_section_p
);
682 /* Tell assembler to switch to unlikely-to-be-executed text section. */
685 unlikely_text_section (void)
687 return function_section_1 (current_function_decl
, true);
690 /* When called within a function context, return true if the function
691 has been assigned a cold text section and if SECT is that section.
692 When called outside a function context, return true if SECT is the
693 default cold section. */
696 unlikely_text_section_p (section
*sect
)
698 return sect
== function_section_1 (current_function_decl
, true);
701 /* Return the read-only data section associated with function DECL. */
704 default_function_rodata_section (tree decl
)
706 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
708 const char *name
= DECL_SECTION_NAME (decl
);
710 if (DECL_COMDAT_GROUP (decl
) && HAVE_COMDAT_GROUP
)
716 dot
= strchr (name
+ 1, '.');
719 len
= strlen (dot
) + 8;
720 rname
= (char *) alloca (len
);
722 strcpy (rname
, ".rodata");
724 return get_section (rname
, SECTION_LINKONCE
, decl
);
726 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
727 else if (DECL_COMDAT_GROUP (decl
)
728 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
730 size_t len
= strlen (name
) + 1;
731 char *rname
= (char *) alloca (len
);
733 memcpy (rname
, name
, len
);
735 return get_section (rname
, SECTION_LINKONCE
, decl
);
737 /* For .text.foo we want to use .rodata.foo. */
738 else if (flag_function_sections
&& flag_data_sections
739 && strncmp (name
, ".text.", 6) == 0)
741 size_t len
= strlen (name
) + 1;
742 char *rname
= (char *) alloca (len
+ 2);
744 memcpy (rname
, ".rodata", 7);
745 memcpy (rname
+ 7, name
+ 5, len
- 5);
746 return get_section (rname
, 0, decl
);
750 return readonly_data_section
;
753 /* Return the read-only data section associated with function DECL
754 for targets where that section should be always the single
755 readonly data section. */
758 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
760 return readonly_data_section
;
763 /* Return the section to use for string merging. */
766 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
767 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
768 unsigned int flags ATTRIBUTE_UNUSED
)
772 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
773 && TREE_CODE (decl
) == STRING_CST
774 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
776 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
777 && TREE_STRING_LENGTH (decl
) >= len
)
780 unsigned int modesize
;
784 const char *prefix
= targetm
.asm_out
.mergeable_rodata_prefix
;
785 char *name
= (char *) alloca (strlen (prefix
) + 30);
787 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
788 modesize
= GET_MODE_BITSIZE (mode
);
789 if (modesize
>= 8 && modesize
<= 256
790 && (modesize
& (modesize
- 1)) == 0)
792 if (align
< modesize
)
795 str
= TREE_STRING_POINTER (decl
);
796 unit
= GET_MODE_SIZE (mode
);
798 /* Check for embedded NUL characters. */
799 for (i
= 0; i
< len
; i
+= unit
)
801 for (j
= 0; j
< unit
; j
++)
802 if (str
[i
+ j
] != '\0')
809 sprintf (name
, "%s.str%d.%d", prefix
,
810 modesize
/ 8, (int) (align
/ 8));
811 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
812 return get_section (name
, flags
, NULL
);
817 return readonly_data_section
;
820 /* Return the section to use for constant merging. */
823 mergeable_constant_section (machine_mode mode ATTRIBUTE_UNUSED
,
824 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
825 unsigned int flags ATTRIBUTE_UNUSED
)
827 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
829 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
835 && (align
& (align
- 1)) == 0)
837 const char *prefix
= targetm
.asm_out
.mergeable_rodata_prefix
;
838 char *name
= (char *) alloca (strlen (prefix
) + 30);
840 sprintf (name
, "%s.cst%d", prefix
, (int) (align
/ 8));
841 flags
|= (align
/ 8) | SECTION_MERGE
;
842 return get_section (name
, flags
, NULL
);
844 return readonly_data_section
;
847 /* Given NAME, a putative register name, discard any customary prefixes. */
850 strip_reg_name (const char *name
)
852 #ifdef REGISTER_PREFIX
853 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
854 name
+= strlen (REGISTER_PREFIX
);
856 if (name
[0] == '%' || name
[0] == '#')
861 /* The user has asked for a DECL to have a particular name. Set (or
862 change) it in such a way that we don't prefix an underscore to
865 set_user_assembler_name (tree decl
, const char *name
)
867 char *starred
= (char *) alloca (strlen (name
) + 2);
869 strcpy (starred
+ 1, name
);
870 symtab
->change_decl_assembler_name (decl
, get_identifier (starred
));
871 SET_DECL_RTL (decl
, NULL_RTX
);
874 /* Decode an `asm' spec for a declaration as a register name.
875 Return the register number, or -1 if nothing specified,
876 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
877 or -3 if ASMSPEC is `cc' and is not recognized,
878 or -4 if ASMSPEC is `memory' and is not recognized.
879 Accept an exact spelling or a decimal number.
880 Prefixes such as % are optional. */
883 decode_reg_name_and_count (const char *asmspec
, int *pnregs
)
885 /* Presume just one register is clobbered. */
892 /* Get rid of confusing prefixes. */
893 asmspec
= strip_reg_name (asmspec
);
895 /* Allow a decimal number as a "register name". */
896 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
897 if (! ISDIGIT (asmspec
[i
]))
899 if (asmspec
[0] != 0 && i
< 0)
902 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0 && reg_names
[i
][0])
908 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
910 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
913 #ifdef OVERLAPPING_REGISTER_NAMES
917 const char *const name
;
920 } table
[] = OVERLAPPING_REGISTER_NAMES
;
922 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
924 && ! strcmp (asmspec
, table
[i
].name
))
926 *pnregs
= table
[i
].nregs
;
927 return table
[i
].number
;
930 #endif /* OVERLAPPING_REGISTER_NAMES */
932 #ifdef ADDITIONAL_REGISTER_NAMES
934 static const struct { const char *const name
; const int number
; } table
[]
935 = ADDITIONAL_REGISTER_NAMES
;
937 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
939 && ! strcmp (asmspec
, table
[i
].name
)
940 && reg_names
[table
[i
].number
][0])
941 return table
[i
].number
;
943 #endif /* ADDITIONAL_REGISTER_NAMES */
945 if (!strcmp (asmspec
, "memory"))
948 if (!strcmp (asmspec
, "cc"))
958 decode_reg_name (const char *name
)
961 return decode_reg_name_and_count (name
, &count
);
965 /* Return true if DECL's initializer is suitable for a BSS section. */
968 bss_initializer_p (const_tree decl
)
970 return (DECL_INITIAL (decl
) == NULL
971 /* In LTO we have no errors in program; error_mark_node is used
972 to mark offlined constructors. */
973 || (DECL_INITIAL (decl
) == error_mark_node
975 || (flag_zero_initialized_in_bss
976 /* Leave constant zeroes in .rodata so they
978 && !TREE_READONLY (decl
)
979 && initializer_zerop (DECL_INITIAL (decl
))));
982 /* Compute the alignment of variable specified by DECL.
983 DONT_OUTPUT_DATA is from assemble_variable. */
986 align_variable (tree decl
, bool dont_output_data
)
988 unsigned int align
= DECL_ALIGN (decl
);
990 /* In the case for initialing an array whose length isn't specified,
991 where we have not yet been able to do the layout,
992 figure out the proper alignment now. */
993 if (dont_output_data
&& DECL_SIZE (decl
) == 0
994 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
995 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
997 /* Some object file formats have a maximum alignment which they support.
998 In particular, a.out format supports a maximum alignment of 4. */
999 if (align
> MAX_OFILE_ALIGNMENT
)
1001 error ("alignment of %q+D is greater than maximum object "
1002 "file alignment %d", decl
,
1003 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1004 align
= MAX_OFILE_ALIGNMENT
;
1007 if (! DECL_USER_ALIGN (decl
))
1009 #ifdef DATA_ABI_ALIGNMENT
1010 unsigned int data_abi_align
1011 = DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1012 /* For backwards compatibility, don't assume the ABI alignment for
1014 if (! DECL_THREAD_LOCAL_P (decl
) || data_abi_align
<= BITS_PER_WORD
)
1015 align
= data_abi_align
;
1018 /* On some machines, it is good to increase alignment sometimes.
1019 But as DECL_ALIGN is used both for actually emitting the variable
1020 and for code accessing the variable as guaranteed alignment, we
1021 can only increase the alignment if it is a performance optimization
1022 if the references to it must bind to the current definition. */
1023 if (decl_binds_to_current_def_p (decl
)
1024 && !DECL_VIRTUAL_P (decl
))
1026 #ifdef DATA_ALIGNMENT
1027 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1028 /* Don't increase alignment too much for TLS variables - TLS space
1030 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1033 #ifdef CONSTANT_ALIGNMENT
1034 if (DECL_INITIAL (decl
) != 0
1035 /* In LTO we have no errors in program; error_mark_node is used
1036 to mark offlined constructors. */
1037 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1039 unsigned int const_align
1040 = CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1041 /* Don't increase alignment too much for TLS variables - TLS
1042 space is too precious. */
1043 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1044 align
= const_align
;
1050 /* Reset the alignment in case we have made it tighter, so we can benefit
1051 from it in get_pointer_alignment. */
1052 DECL_ALIGN (decl
) = align
;
1055 /* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1056 beyond what align_variable returned. */
1059 get_variable_align (tree decl
)
1061 unsigned int align
= DECL_ALIGN (decl
);
1063 /* For user aligned vars or static vars align_variable already did
1065 if (DECL_USER_ALIGN (decl
) || !TREE_PUBLIC (decl
))
1068 #ifdef DATA_ABI_ALIGNMENT
1069 if (DECL_THREAD_LOCAL_P (decl
))
1070 align
= DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1073 /* For decls that bind to the current definition, align_variable
1074 did also everything, except for not assuming ABI required alignment
1075 of TLS variables. For other vars, increase the alignment here
1076 as an optimization. */
1077 if (!decl_binds_to_current_def_p (decl
))
1079 /* On some machines, it is good to increase alignment sometimes. */
1080 #ifdef DATA_ALIGNMENT
1081 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1082 /* Don't increase alignment too much for TLS variables - TLS space
1084 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1087 #ifdef CONSTANT_ALIGNMENT
1088 if (DECL_INITIAL (decl
) != 0
1089 /* In LTO we have no errors in program; error_mark_node is used
1090 to mark offlined constructors. */
1091 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1093 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
1095 /* Don't increase alignment too much for TLS variables - TLS space
1097 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1098 align
= const_align
;
1106 /* Return the section into which the given VAR_DECL or CONST_DECL
1107 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1108 section should be used wherever possible. */
1111 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1113 addr_space_t as
= ADDR_SPACE_GENERIC
;
1115 varpool_node
*vnode
= varpool_node::get (decl
);
1118 vnode
= vnode
->ultimate_alias_target ();
1122 if (TREE_TYPE (decl
) != error_mark_node
)
1123 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1125 /* We need the constructor to figure out reloc flag. */
1127 vnode
->get_constructor ();
1129 if (DECL_COMMON (decl
))
1131 /* If the decl has been given an explicit section name, or it resides
1132 in a non-generic address space, then it isn't common, and shouldn't
1133 be handled as such. */
1134 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1135 && ADDR_SPACE_GENERIC_P (as
));
1136 if (DECL_THREAD_LOCAL_P (decl
))
1137 return tls_comm_section
;
1138 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1139 return comm_section
;
1142 if (DECL_INITIAL (decl
) == error_mark_node
)
1143 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1144 else if (DECL_INITIAL (decl
))
1145 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1149 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1150 if (IN_NAMED_SECTION (decl
))
1151 return get_named_section (decl
, NULL
, reloc
);
1153 if (ADDR_SPACE_GENERIC_P (as
)
1154 && !DECL_THREAD_LOCAL_P (decl
)
1155 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1156 && bss_initializer_p (decl
))
1158 if (!TREE_PUBLIC (decl
)
1159 && !((flag_sanitize
& SANITIZE_ADDRESS
)
1160 && asan_protect_global (decl
)))
1161 return lcomm_section
;
1162 if (bss_noswitch_section
)
1163 return bss_noswitch_section
;
1166 return targetm
.asm_out
.select_section (decl
, reloc
,
1167 get_variable_align (decl
));
1170 /* Return the block into which object_block DECL should be placed. */
1172 static struct object_block
*
1173 get_block_for_decl (tree decl
)
1177 if (TREE_CODE (decl
) == VAR_DECL
)
1179 /* The object must be defined in this translation unit. */
1180 if (DECL_EXTERNAL (decl
))
1183 /* There's no point using object blocks for something that is
1184 isolated by definition. */
1185 if (DECL_COMDAT_GROUP (decl
))
1189 /* We can only calculate block offsets if the decl has a known
1191 if (DECL_SIZE_UNIT (decl
) == NULL
)
1193 if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl
)))
1196 /* Find out which section should contain DECL. We cannot put it into
1197 an object block if it requires a standalone definition. */
1198 if (TREE_CODE (decl
) == VAR_DECL
)
1199 align_variable (decl
, 0);
1200 sect
= get_variable_section (decl
, true);
1201 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1204 return get_block_for_section (sect
);
1207 /* Make sure block symbol SYMBOL is in block BLOCK. */
1210 change_symbol_block (rtx symbol
, struct object_block
*block
)
1212 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1214 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1215 SYMBOL_REF_BLOCK (symbol
) = block
;
1219 /* Return true if it is possible to put DECL in an object_block. */
1222 use_blocks_for_decl_p (tree decl
)
1224 struct symtab_node
*snode
;
1226 /* Only data DECLs can be placed into object blocks. */
1227 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
1230 /* Detect decls created by dw2_force_const_mem. Such decls are
1231 special because DECL_INITIAL doesn't specify the decl's true value.
1232 dw2_output_indirect_constants will instead call assemble_variable
1233 with dont_output_data set to 1 and then print the contents itself. */
1234 if (DECL_INITIAL (decl
) == decl
)
1237 /* If this decl is an alias, then we don't want to emit a
1239 if (TREE_CODE (decl
) == VAR_DECL
1240 && (snode
= symtab_node::get (decl
)) != NULL
1244 return targetm
.use_blocks_for_decl_p (decl
);
1247 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1248 until we find an identifier that is not itself a transparent alias.
1249 Modify the alias passed to it by reference (and all aliases on the
1250 way to the ultimate target), such that they do not have to be
1251 followed again, and return the ultimate target of the alias
1255 ultimate_transparent_alias_target (tree
*alias
)
1257 tree target
= *alias
;
1259 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
1261 gcc_assert (TREE_CHAIN (target
));
1262 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
1263 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
1264 && ! TREE_CHAIN (target
));
1271 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1272 have static storage duration. In other words, it should not be an
1273 automatic variable, including PARM_DECLs.
1275 There is, however, one exception: this function handles variables
1276 explicitly placed in a particular register by the user.
1278 This is never called for PARM_DECL nodes. */
1281 make_decl_rtl (tree decl
)
1283 const char *name
= 0;
1288 /* Check that we are not being given an automatic variable. */
1289 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1290 && TREE_CODE (decl
) != RESULT_DECL
);
1292 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1293 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1294 || TREE_STATIC (decl
)
1295 || TREE_PUBLIC (decl
)
1296 || DECL_EXTERNAL (decl
)
1297 || DECL_REGISTER (decl
));
1299 /* And that we were not given a type or a label. */
1300 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1301 && TREE_CODE (decl
) != LABEL_DECL
);
1303 /* For a duplicate declaration, we can be called twice on the
1304 same DECL node. Don't discard the RTL already made. */
1305 if (DECL_RTL_SET_P (decl
))
1307 /* If the old RTL had the wrong mode, fix the mode. */
1308 x
= DECL_RTL (decl
);
1309 if (GET_MODE (x
) != DECL_MODE (decl
))
1310 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1312 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1315 /* ??? Another way to do this would be to maintain a hashed
1316 table of such critters. Instead of adding stuff to a DECL
1317 to give certain attributes to it, we could use an external
1318 hash map from DECL to set of attributes. */
1320 /* Let the target reassign the RTL if it wants.
1321 This is necessary, for example, when one machine specific
1322 decl attribute overrides another. */
1323 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1325 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1326 on the new decl information. */
1328 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1329 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1330 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1335 /* If this variable belongs to the global constant pool, retrieve the
1336 pre-computed RTL or recompute it in LTO mode. */
1337 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1339 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1343 id
= DECL_ASSEMBLER_NAME (decl
);
1344 if (TREE_CODE (decl
) == FUNCTION_DECL
1345 && cgraph_node::get (decl
)
1346 && cgraph_node::get (decl
)->instrumentation_clone
)
1347 ultimate_transparent_alias_target (&id
);
1348 name
= IDENTIFIER_POINTER (id
);
1350 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1351 && DECL_REGISTER (decl
))
1353 error ("register name not specified for %q+D", decl
);
1355 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1357 const char *asmspec
= name
+1;
1358 machine_mode mode
= DECL_MODE (decl
);
1359 reg_number
= decode_reg_name (asmspec
);
1360 /* First detect errors in declaring global registers. */
1361 if (reg_number
== -1)
1362 error ("register name not specified for %q+D", decl
);
1363 else if (reg_number
< 0)
1364 error ("invalid register name for %q+D", decl
);
1365 else if (mode
== BLKmode
)
1366 error ("data type of %q+D isn%'t suitable for a register",
1368 else if (!in_hard_reg_set_p (accessible_reg_set
, mode
, reg_number
))
1369 error ("the register specified for %q+D cannot be accessed"
1370 " by the current target", decl
);
1371 else if (!in_hard_reg_set_p (operand_reg_set
, mode
, reg_number
))
1372 error ("the register specified for %q+D is not general enough"
1373 " to be used as a register variable", decl
);
1374 else if (!HARD_REGNO_MODE_OK (reg_number
, mode
))
1375 error ("register specified for %q+D isn%'t suitable for data type",
1377 /* Now handle properly declared static register variables. */
1382 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1384 DECL_INITIAL (decl
) = 0;
1385 error ("global register variable has initial value");
1387 if (TREE_THIS_VOLATILE (decl
))
1388 warning (OPT_Wvolatile_register_var
,
1389 "optimization may eliminate reads and/or "
1390 "writes to register variables");
1392 /* If the user specified one of the eliminables registers here,
1393 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1394 confused with that register and be eliminated. This usage is
1395 somewhat suspect... */
1397 SET_DECL_RTL (decl
, gen_rtx_raw_REG (mode
, reg_number
));
1398 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1399 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1401 if (TREE_STATIC (decl
))
1403 /* Make this register global, so not usable for anything
1405 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1406 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1407 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1409 nregs
= hard_regno_nregs
[reg_number
][mode
];
1411 globalize_reg (decl
, reg_number
+ --nregs
);
1414 /* As a register variable, it has no section. */
1417 /* Avoid internal errors from invalid register
1419 SET_DECL_ASSEMBLER_NAME (decl
, NULL_TREE
);
1420 DECL_HARD_REGISTER (decl
) = 0;
1423 /* Now handle ordinary static variables and functions (in memory).
1424 Also handle vars declared register invalidly. */
1425 else if (name
[0] == '*')
1427 #ifdef REGISTER_PREFIX
1428 if (strlen (REGISTER_PREFIX
) != 0)
1430 reg_number
= decode_reg_name (name
);
1431 if (reg_number
>= 0 || reg_number
== -3)
1432 error ("register name given for non-register variable %q+D", decl
);
1437 /* Specifying a section attribute on a variable forces it into a
1438 non-.bss section, and thus it cannot be common. */
1439 /* FIXME: In general this code should not be necessary because
1440 visibility pass is doing the same work. But notice_global_symbol
1441 is called early and it needs to make DECL_RTL to get the name.
1442 we take care of recomputing the DECL_RTL after visibility is changed. */
1443 if (TREE_CODE (decl
) == VAR_DECL
1444 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
1445 && DECL_SECTION_NAME (decl
) != NULL
1446 && DECL_INITIAL (decl
) == NULL_TREE
1447 && DECL_COMMON (decl
))
1448 DECL_COMMON (decl
) = 0;
1450 /* Variables can't be both common and weak. */
1451 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1452 DECL_COMMON (decl
) = 0;
1454 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1455 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1458 machine_mode address_mode
= Pmode
;
1459 if (TREE_TYPE (decl
) != error_mark_node
)
1461 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1462 address_mode
= targetm
.addr_space
.address_mode (as
);
1464 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1466 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1467 SET_SYMBOL_REF_DECL (x
, decl
);
1469 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1470 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1471 set_mem_attributes (x
, decl
, 1);
1472 SET_DECL_RTL (decl
, x
);
1474 /* Optionally set flags or add text to the name to record information
1475 such as that it is a function name.
1476 If the name is changed, the macro ASM_OUTPUT_LABELREF
1477 will have to know how to strip this information. */
1478 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1481 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1482 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1486 make_decl_rtl_for_debug (tree decl
)
1488 unsigned int save_aliasing_flag
;
1491 if (DECL_RTL_SET_P (decl
))
1492 return DECL_RTL (decl
);
1494 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1495 call new_alias_set. If running with -fcompare-debug, sometimes
1496 we do not want to create alias sets that will throw the alias
1497 numbers off in the comparison dumps. So... clearing
1498 flag_strict_aliasing will keep new_alias_set() from creating a
1500 save_aliasing_flag
= flag_strict_aliasing
;
1501 flag_strict_aliasing
= 0;
1503 rtl
= DECL_RTL (decl
);
1504 /* Reset DECL_RTL back, as various parts of the compiler expects
1505 DECL_RTL set meaning it is actually going to be output. */
1506 SET_DECL_RTL (decl
, NULL
);
1508 flag_strict_aliasing
= save_aliasing_flag
;
1512 /* Output a string of literal assembler code
1513 for an `asm' keyword used between functions. */
1516 assemble_asm (tree string
)
1521 if (TREE_CODE (string
) == ADDR_EXPR
)
1522 string
= TREE_OPERAND (string
, 0);
1524 p
= TREE_STRING_POINTER (string
);
1525 fprintf (asm_out_file
, "%s%s\n", p
[0] == '\t' ? "" : "\t", p
);
1528 /* Write the address of the entity given by SYMBOL to SEC. */
1530 assemble_addr_to_section (rtx symbol
, section
*sec
)
1532 switch_to_section (sec
);
1533 assemble_align (POINTER_SIZE
);
1534 assemble_integer (symbol
, POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
1537 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1538 not) section for PRIORITY. */
1540 get_cdtor_priority_section (int priority
, bool constructor_p
)
1544 /* ??? This only works reliably with the GNU linker. */
1545 sprintf (buf
, "%s.%.5u",
1546 constructor_p
? ".ctors" : ".dtors",
1547 /* Invert the numbering so the linker puts us in the proper
1548 order; constructors are run from right to left, and the
1549 linker sorts in increasing order. */
1550 MAX_INIT_PRIORITY
- priority
);
1551 return get_section (buf
, SECTION_WRITE
, NULL
);
1555 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1559 if (priority
!= DEFAULT_INIT_PRIORITY
)
1560 sec
= get_cdtor_priority_section (priority
,
1561 /*constructor_p=*/false);
1563 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1565 assemble_addr_to_section (symbol
, sec
);
1568 #ifdef DTORS_SECTION_ASM_OP
1570 default_dtor_section_asm_out_destructor (rtx symbol
,
1571 int priority ATTRIBUTE_UNUSED
)
1573 assemble_addr_to_section (symbol
, dtors_section
);
1578 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1582 if (priority
!= DEFAULT_INIT_PRIORITY
)
1583 sec
= get_cdtor_priority_section (priority
,
1584 /*constructor_p=*/true);
1586 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1588 assemble_addr_to_section (symbol
, sec
);
1591 #ifdef CTORS_SECTION_ASM_OP
1593 default_ctor_section_asm_out_constructor (rtx symbol
,
1594 int priority ATTRIBUTE_UNUSED
)
1596 assemble_addr_to_section (symbol
, ctors_section
);
1600 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1601 a nonzero value if the constant pool should be output before the
1602 start of the function, or a zero value if the pool should output
1603 after the end of the function. The default is to put it before the
1606 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1607 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1610 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1611 to be output to assembler.
1612 Set first_global_object_name and weak_global_object_name as appropriate. */
1615 notice_global_symbol (tree decl
)
1617 const char **type
= &first_global_object_name
;
1619 if (first_global_object_name
1620 || !TREE_PUBLIC (decl
)
1621 || DECL_EXTERNAL (decl
)
1622 || !DECL_NAME (decl
)
1623 || (TREE_CODE (decl
) != FUNCTION_DECL
1624 && (TREE_CODE (decl
) != VAR_DECL
1625 || (DECL_COMMON (decl
)
1626 && (DECL_INITIAL (decl
) == 0
1627 || DECL_INITIAL (decl
) == error_mark_node
))))
1628 || !MEM_P (DECL_RTL (decl
)))
1631 /* We win when global object is found, but it is useful to know about weak
1632 symbol as well so we can produce nicer unique names. */
1633 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1634 type
= &weak_global_object_name
;
1640 rtx decl_rtl
= DECL_RTL (decl
);
1642 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1643 name
= ggc_strdup (p
);
1649 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1650 current function goes into the cold section, so that targets can use
1651 current_function_section during RTL expansion. DECL describes the
1655 decide_function_section (tree decl
)
1657 first_function_block_is_cold
= false;
1659 if (flag_reorder_blocks_and_partition
)
1660 /* We will decide in assemble_start_function. */
1663 if (DECL_SECTION_NAME (decl
))
1665 struct cgraph_node
*node
= cgraph_node::get (current_function_decl
);
1666 /* Calls to function_section rely on first_function_block_is_cold
1668 first_function_block_is_cold
= (node
1670 == NODE_FREQUENCY_UNLIKELY_EXECUTED
);
1673 in_cold_section_p
= first_function_block_is_cold
;
1676 /* Output assembler code for the constant pool of a function and associated
1677 with defining the name of the function. DECL describes the function.
1678 NAME is the function's name. For the constant pool, we use the current
1679 constant pool data. */
1682 assemble_start_function (tree decl
, const char *fnname
)
1685 char tmp_label
[100];
1686 bool hot_label_written
= false;
1688 if (flag_reorder_blocks_and_partition
)
1690 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1691 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1692 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1693 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1694 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1695 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1696 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1697 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1702 crtl
->subsections
.hot_section_label
= NULL
;
1703 crtl
->subsections
.cold_section_label
= NULL
;
1704 crtl
->subsections
.hot_section_end_label
= NULL
;
1705 crtl
->subsections
.cold_section_end_label
= NULL
;
1708 /* The following code does not need preprocessing in the assembler. */
1712 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1713 output_constant_pool (fnname
, decl
);
1715 /* Make sure the not and cold text (code) sections are properly
1716 aligned. This is necessary here in the case where the function
1717 has both hot and cold sections, because we don't want to re-set
1718 the alignment when the section switch happens mid-function. */
1720 if (flag_reorder_blocks_and_partition
)
1722 first_function_block_is_cold
= false;
1724 switch_to_section (unlikely_text_section ());
1725 assemble_align (DECL_ALIGN (decl
));
1726 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1728 /* When the function starts with a cold section, we need to explicitly
1729 align the hot section and write out the hot section label.
1730 But if the current function is a thunk, we do not have a CFG. */
1732 && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun
)->next_bb
) == BB_COLD_PARTITION
)
1734 switch_to_section (text_section
);
1735 assemble_align (DECL_ALIGN (decl
));
1736 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1737 hot_label_written
= true;
1738 first_function_block_is_cold
= true;
1740 in_cold_section_p
= first_function_block_is_cold
;
1744 /* Switch to the correct text section for the start of the function. */
1746 switch_to_section (function_section (decl
));
1747 if (flag_reorder_blocks_and_partition
1748 && !hot_label_written
)
1749 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1751 /* Tell assembler to move to target machine's alignment for functions. */
1752 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1755 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1758 /* Handle a user-specified function alignment.
1759 Note that we still need to align to DECL_ALIGN, as above,
1760 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1761 if (! DECL_USER_ALIGN (decl
)
1762 && align_functions_log
> align
1763 && optimize_function_for_speed_p (cfun
))
1765 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1766 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1767 align_functions_log
, align_functions
- 1);
1769 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1773 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1774 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1777 if (!DECL_IGNORED_P (decl
))
1778 (*debug_hooks
->begin_function
) (decl
);
1780 /* Make function name accessible from other files, if appropriate. */
1782 if (TREE_PUBLIC (decl
)
1783 || (cgraph_node::get (decl
)->instrumentation_clone
1784 && cgraph_node::get (decl
)->instrumented_version
1785 && TREE_PUBLIC (cgraph_node::get (decl
)->instrumented_version
->decl
)))
1787 notice_global_symbol (decl
);
1789 globalize_decl (decl
);
1791 maybe_assemble_visibility (decl
);
1794 if (DECL_PRESERVE_P (decl
))
1795 targetm
.asm_out
.mark_decl_preserved (fnname
);
1797 /* Do any machine/system dependent processing of the function name. */
1798 #ifdef ASM_DECLARE_FUNCTION_NAME
1799 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1801 /* Standard thing is just output label for the function. */
1802 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1803 #endif /* ASM_DECLARE_FUNCTION_NAME */
1805 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1806 saw_no_split_stack
= true;
1809 /* Output assembler code associated with defining the size of the
1810 function. DECL describes the function. NAME is the function's name. */
1813 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1815 #ifdef ASM_DECLARE_FUNCTION_SIZE
1816 /* We could have switched section in the middle of the function. */
1817 if (flag_reorder_blocks_and_partition
)
1818 switch_to_section (function_section (decl
));
1819 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1821 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1823 output_constant_pool (fnname
, decl
);
1824 switch_to_section (function_section (decl
)); /* need to switch back */
1826 /* Output labels for end of hot/cold text sections (to be used by
1828 if (flag_reorder_blocks_and_partition
)
1830 section
*save_text_section
;
1832 save_text_section
= in_section
;
1833 switch_to_section (unlikely_text_section ());
1834 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1835 if (first_function_block_is_cold
)
1836 switch_to_section (text_section
);
1838 switch_to_section (function_section (decl
));
1839 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1840 switch_to_section (save_text_section
);
1844 /* Assemble code to leave SIZE bytes of zeros. */
1847 assemble_zeros (unsigned HOST_WIDE_INT size
)
1849 /* Do no output if -fsyntax-only. */
1850 if (flag_syntax_only
)
1853 #ifdef ASM_NO_SKIP_IN_TEXT
1854 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1855 so we must output 0s explicitly in the text section. */
1856 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1858 unsigned HOST_WIDE_INT i
;
1859 for (i
= 0; i
< size
; i
++)
1860 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1865 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1868 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1871 assemble_align (int align
)
1873 if (align
> BITS_PER_UNIT
)
1875 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1879 /* Assemble a string constant with the specified C string as contents. */
1882 assemble_string (const char *p
, int size
)
1887 /* If the string is very long, split it up. */
1891 int thissize
= size
- pos
;
1892 if (thissize
> maximum
)
1895 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1903 /* A noswitch_section_callback for lcomm_section. */
1906 emit_local (tree decl ATTRIBUTE_UNUSED
,
1907 const char *name ATTRIBUTE_UNUSED
,
1908 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1909 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1911 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1912 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1913 size
, DECL_ALIGN (decl
));
1915 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1916 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1919 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1924 /* A noswitch_section_callback for bss_noswitch_section. */
1926 #if defined ASM_OUTPUT_ALIGNED_BSS
1928 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1929 const char *name ATTRIBUTE_UNUSED
,
1930 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1931 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1933 #if defined ASM_OUTPUT_ALIGNED_BSS
1934 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
,
1935 get_variable_align (decl
));
1941 /* A noswitch_section_callback for comm_section. */
1944 emit_common (tree decl ATTRIBUTE_UNUSED
,
1945 const char *name ATTRIBUTE_UNUSED
,
1946 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1947 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1949 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1950 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1951 size
, get_variable_align (decl
));
1953 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1954 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
1955 get_variable_align (decl
));
1958 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1963 /* A noswitch_section_callback for tls_comm_section. */
1966 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1967 const char *name ATTRIBUTE_UNUSED
,
1968 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1969 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1971 #ifdef ASM_OUTPUT_TLS_COMMON
1972 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1975 sorry ("thread-local COMMON data not implemented");
1980 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1981 NAME is the name of DECL's SYMBOL_REF. */
1984 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
,
1987 unsigned HOST_WIDE_INT size
, rounded
;
1989 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
1992 if ((flag_sanitize
& SANITIZE_ADDRESS
) && asan_protect_global (decl
))
1993 size
+= asan_red_zone_size (size
);
1995 /* Don't allocate zero bytes of common,
1996 since that means "undefined external" in the linker. */
2000 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2001 so that each uninitialized object starts on such a boundary. */
2002 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
2003 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2004 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2006 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
2007 && (unsigned HOST_WIDE_INT
) (align
/ BITS_PER_UNIT
) > rounded
)
2008 error ("requested alignment for %q+D is greater than "
2009 "implemented alignment of %wu", decl
, rounded
);
2012 /* A subroutine of assemble_variable. Output the label and contents of
2013 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2014 is as for assemble_variable. */
2017 assemble_variable_contents (tree decl
, const char *name
,
2018 bool dont_output_data
)
2020 /* Do any machine/system dependent processing of the object. */
2021 #ifdef ASM_DECLARE_OBJECT_NAME
2022 last_assemble_variable_decl
= decl
;
2023 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
2025 /* Standard thing is just output label for the object. */
2026 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2027 #endif /* ASM_DECLARE_OBJECT_NAME */
2029 if (!dont_output_data
)
2031 /* Caller is supposed to use varpool_get_constructor when it wants
2032 to output the body. */
2033 gcc_assert (!in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
);
2034 if (DECL_INITIAL (decl
)
2035 && DECL_INITIAL (decl
) != error_mark_node
2036 && !initializer_zerop (DECL_INITIAL (decl
)))
2037 /* Output the actual data. */
2038 output_constant (DECL_INITIAL (decl
),
2039 tree_to_uhwi (DECL_SIZE_UNIT (decl
)),
2040 get_variable_align (decl
));
2042 /* Leave space for it. */
2043 assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl
)));
2047 /* Assemble everything that is needed for a variable or function declaration.
2048 Not used for automatic variables, and not used for function definitions.
2049 Should not be called for variables of incomplete structure type.
2051 TOP_LEVEL is nonzero if this variable has file scope.
2052 AT_END is nonzero if this is the special handling, at end of compilation,
2053 to define things that have had only tentative definitions.
2054 DONT_OUTPUT_DATA if nonzero means don't actually output the
2055 initial value (that will be done by the caller). */
2058 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
2059 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
2062 rtx decl_rtl
, symbol
;
2065 bool asan_protected
= false;
2067 /* This function is supposed to handle VARIABLES. Ensure we have one. */
2068 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
2070 /* Emulated TLS had better not get this far. */
2071 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
2073 last_assemble_variable_decl
= 0;
2075 /* Normally no need to say anything here for external references,
2076 since assemble_external is called by the language-specific code
2077 when a declaration is first seen. */
2079 if (DECL_EXTERNAL (decl
))
2082 /* Do nothing for global register variables. */
2083 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2085 TREE_ASM_WRITTEN (decl
) = 1;
2089 /* If type was incomplete when the variable was declared,
2090 see if it is complete now. */
2092 if (DECL_SIZE (decl
) == 0)
2093 layout_decl (decl
, 0);
2095 /* Still incomplete => don't allocate it; treat the tentative defn
2096 (which is what it must have been) as an `extern' reference. */
2098 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2100 error ("storage size of %q+D isn%'t known", decl
);
2101 TREE_ASM_WRITTEN (decl
) = 1;
2105 /* The first declaration of a variable that comes through this function
2106 decides whether it is global (in C, has external linkage)
2107 or local (in C, has internal linkage). So do nothing more
2108 if this function has already run. */
2110 if (TREE_ASM_WRITTEN (decl
))
2113 /* Make sure targetm.encode_section_info is invoked before we set
2115 decl_rtl
= DECL_RTL (decl
);
2117 TREE_ASM_WRITTEN (decl
) = 1;
2119 /* Do no output if -fsyntax-only. */
2120 if (flag_syntax_only
)
2123 if (! dont_output_data
2124 && ! valid_constant_size_p (DECL_SIZE_UNIT (decl
)))
2126 error ("size of variable %q+D is too large", decl
);
2130 gcc_assert (MEM_P (decl_rtl
));
2131 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2132 symbol
= XEXP (decl_rtl
, 0);
2134 /* If this symbol belongs to the tree constant pool, output the constant
2135 if it hasn't already been written. */
2136 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
2138 tree decl
= SYMBOL_REF_DECL (symbol
);
2139 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2140 output_constant_def_contents (symbol
);
2146 name
= XSTR (symbol
, 0);
2147 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2148 notice_global_symbol (decl
);
2150 /* Compute the alignment of this data. */
2152 align_variable (decl
, dont_output_data
);
2154 if ((flag_sanitize
& SANITIZE_ADDRESS
)
2155 && asan_protect_global (decl
))
2157 asan_protected
= true;
2158 DECL_ALIGN (decl
) = MAX (DECL_ALIGN (decl
),
2159 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
2162 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2164 align
= get_variable_align (decl
);
2166 if (TREE_PUBLIC (decl
))
2167 maybe_assemble_visibility (decl
);
2169 if (DECL_PRESERVE_P (decl
))
2170 targetm
.asm_out
.mark_decl_preserved (name
);
2172 /* First make the assembler name(s) global if appropriate. */
2173 sect
= get_variable_section (decl
, false);
2174 if (TREE_PUBLIC (decl
)
2175 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2176 globalize_decl (decl
);
2178 /* Output any data that we will need to use the address of. */
2179 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2180 output_addressed_constants (DECL_INITIAL (decl
));
2182 /* dbxout.c needs to know this. */
2183 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2184 DECL_IN_TEXT_SECTION (decl
) = 1;
2186 /* If the decl is part of an object_block, make sure that the decl
2187 has been positioned within its block, but do not write out its
2188 definition yet. output_object_blocks will do that later. */
2189 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2191 gcc_assert (!dont_output_data
);
2192 place_block_symbol (symbol
);
2194 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2195 assemble_noswitch_variable (decl
, name
, sect
, align
);
2198 /* The following bit of code ensures that vtable_map
2199 variables are not only in the comdat section, but that
2200 each variable has its own unique comdat name. If this
2201 code is removed, the variables end up in the same section
2202 with a single comdat name.
2204 FIXME: resolve_unique_section needs to deal better with
2205 decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
2206 that is fixed, this if-else statement can be replaced with
2207 a single call to "switch_to_section (sect)". */
2208 if (sect
->named
.name
2209 && (strcmp (sect
->named
.name
, ".vtable_map_vars") == 0))
2211 #if defined (OBJECT_FORMAT_ELF)
2212 targetm
.asm_out
.named_section (sect
->named
.name
,
2213 sect
->named
.common
.flags
2218 switch_to_section (sect
);
2222 switch_to_section (sect
);
2223 if (align
> BITS_PER_UNIT
)
2224 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2225 assemble_variable_contents (decl
, name
, dont_output_data
);
2228 unsigned HOST_WIDE_INT
int size
2229 = tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2230 assemble_zeros (asan_red_zone_size (size
));
2236 /* Given a function declaration (FN_DECL), this function assembles the
2237 function into the .preinit_array section. */
2240 assemble_vtv_preinit_initializer (tree fn_decl
)
2243 unsigned flags
= SECTION_WRITE
;
2244 rtx symbol
= XEXP (DECL_RTL (fn_decl
), 0);
2246 flags
|= SECTION_NOTYPE
;
2247 sect
= get_section (".preinit_array", flags
, fn_decl
);
2248 switch_to_section (sect
);
2249 assemble_addr_to_section (symbol
, sect
);
2252 /* Return 1 if type TYPE contains any pointers. */
2255 contains_pointers_p (tree type
)
2257 switch (TREE_CODE (type
))
2260 case REFERENCE_TYPE
:
2261 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2262 so I'll play safe and return 1. */
2268 case QUAL_UNION_TYPE
:
2271 /* For a type that has fields, see if the fields have pointers. */
2272 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
2273 if (TREE_CODE (fields
) == FIELD_DECL
2274 && contains_pointers_p (TREE_TYPE (fields
)))
2280 /* An array type contains pointers if its element type does. */
2281 return contains_pointers_p (TREE_TYPE (type
));
2288 /* We delay assemble_external processing until
2289 the compilation unit is finalized. This is the best we can do for
2290 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2291 it all the way to final. See PR 17982 for further discussion. */
2292 static GTY(()) tree pending_assemble_externals
;
2294 #ifdef ASM_OUTPUT_EXTERNAL
2295 /* Some targets delay some output to final using TARGET_ASM_FILE_END.
2296 As a result, assemble_external can be called after the list of externals
2297 is processed and the pointer set destroyed. */
2298 static bool pending_assemble_externals_processed
;
2300 /* Avoid O(external_decls**2) lookups in the pending_assemble_externals
2301 TREE_LIST in assemble_external. */
2302 static hash_set
<tree
> *pending_assemble_externals_set
;
2304 /* True if DECL is a function decl for which no out-of-line copy exists.
2305 It is assumed that DECL's assembler name has been set. */
2308 incorporeal_function_p (tree decl
)
2310 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2314 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2315 && (DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
2316 || DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA_WITH_ALIGN
))
2319 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2320 /* Atomic or sync builtins which have survived this far will be
2321 resolved externally and therefore are not incorporeal. */
2322 if (strncmp (name
, "__builtin_", 10) == 0)
2328 /* Actually do the tests to determine if this is necessary, and invoke
2329 ASM_OUTPUT_EXTERNAL. */
2331 assemble_external_real (tree decl
)
2333 rtx rtl
= DECL_RTL (decl
);
2335 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2336 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2337 && !incorporeal_function_p (decl
))
2339 /* Some systems do require some output. */
2340 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2341 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2347 process_pending_assemble_externals (void)
2349 #ifdef ASM_OUTPUT_EXTERNAL
2351 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2352 assemble_external_real (TREE_VALUE (list
));
2354 pending_assemble_externals
= 0;
2355 pending_assemble_externals_processed
= true;
2356 delete pending_assemble_externals_set
;
2360 /* This TREE_LIST contains any weak symbol declarations waiting
2362 static GTY(()) tree weak_decls
;
2364 /* Output something to declare an external symbol to the assembler,
2365 and qualifiers such as weakness. (Most assemblers don't need
2366 extern declaration, so we normally output nothing.) Do nothing if
2367 DECL is not external. */
2370 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2372 /* Make sure that the ASM_OUT_FILE is open.
2373 If it's not, we should not be calling this function. */
2374 gcc_assert (asm_out_file
);
2376 /* In a perfect world, the following condition would be true.
2377 Sadly, the Java and Go front ends emit assembly *from the front end*,
2378 bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2380 /* This function should only be called if we are expanding, or have
2382 Ideally, only final.c would be calling this function, but it is
2383 not clear whether that would break things somehow. See PR 17982
2384 for further discussion. */
2385 gcc_assert (state
== EXPANSION
2386 || state
== FINISHED
);
2389 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2392 /* We want to output annotation for weak and external symbols at
2393 very last to check if they are references or not. */
2395 if (TARGET_SUPPORTS_WEAK
2397 /* TREE_STATIC is a weird and abused creature which is not
2398 generally the right test for whether an entity has been
2399 locally emitted, inlined or otherwise not-really-extern, but
2400 for declarations that can be weak, it happens to be
2402 && !TREE_STATIC (decl
)
2403 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2404 && value_member (decl
, weak_decls
) == NULL_TREE
)
2405 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2407 #ifdef ASM_OUTPUT_EXTERNAL
2408 if (pending_assemble_externals_processed
)
2410 assemble_external_real (decl
);
2414 if (! pending_assemble_externals_set
->add (decl
))
2415 pending_assemble_externals
= tree_cons (NULL
, decl
,
2416 pending_assemble_externals
);
2420 /* Similar, for calling a library function FUN. */
2423 assemble_external_libcall (rtx fun
)
2425 /* Declare library function name external when first used, if nec. */
2426 if (! SYMBOL_REF_USED (fun
))
2428 SYMBOL_REF_USED (fun
) = 1;
2429 targetm
.asm_out
.external_libcall (fun
);
2433 /* Assemble a label named NAME. */
2436 assemble_label (FILE *file
, const char *name
)
2438 ASM_OUTPUT_LABEL (file
, name
);
2441 /* Set the symbol_referenced flag for ID. */
2443 mark_referenced (tree id
)
2445 TREE_SYMBOL_REFERENCED (id
) = 1;
2448 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2450 mark_decl_referenced (tree decl
)
2452 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2454 /* Extern inline functions don't become needed when referenced.
2455 If we know a method will be emitted in other TU and no new
2456 functions can be marked reachable, just use the external
2458 struct cgraph_node
*node
= cgraph_node::get_create (decl
);
2459 if (!DECL_EXTERNAL (decl
)
2460 && !node
->definition
)
2461 node
->mark_force_output ();
2463 else if (TREE_CODE (decl
) == VAR_DECL
)
2465 varpool_node
*node
= varpool_node::get_create (decl
);
2466 /* C++ frontend use mark_decl_references to force COMDAT variables
2467 to be output that might appear dead otherwise. */
2468 node
->force_output
= true;
2470 /* else do nothing - we can get various sorts of CST nodes here,
2471 which do not need to be marked. */
2475 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2476 starts with a *, the rest of NAME is output verbatim. Otherwise
2477 NAME is transformed in a target-specific way (usually by the
2478 addition of an underscore). */
2481 assemble_name_raw (FILE *file
, const char *name
)
2484 fputs (&name
[1], file
);
2486 ASM_OUTPUT_LABELREF (file
, name
);
2489 /* Like assemble_name_raw, but should be used when NAME might refer to
2490 an entity that is also represented as a tree (like a function or
2491 variable). If NAME does refer to such an entity, that entity will
2492 be marked as referenced. */
2495 assemble_name (FILE *file
, const char *name
)
2497 const char *real_name
;
2500 real_name
= targetm
.strip_name_encoding (name
);
2502 id
= maybe_get_identifier (real_name
);
2507 mark_referenced (id
);
2508 ultimate_transparent_alias_target (&id
);
2510 name
= IDENTIFIER_POINTER (id
);
2511 gcc_assert (! TREE_CHAIN (id
));
2514 assemble_name_raw (file
, name
);
2517 /* Allocate SIZE bytes writable static space with a gensym name
2518 and return an RTX to refer to its address. */
2521 assemble_static_space (unsigned HOST_WIDE_INT size
)
2524 const char *namestring
;
2527 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2529 namestring
= ggc_strdup (name
);
2531 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2532 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2534 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2535 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2538 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2539 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2542 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2543 so that each uninitialized object starts on such a boundary. */
2544 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2545 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2546 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2547 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2548 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2549 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2556 /* Assemble the static constant template for function entry trampolines.
2557 This is done at most once per compilation.
2558 Returns an RTX for the address of the template. */
2560 static GTY(()) rtx initial_trampoline
;
2563 assemble_trampoline_template (void)
2570 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2572 if (initial_trampoline
)
2573 return initial_trampoline
;
2575 /* By default, put trampoline templates in read-only data section. */
2577 #ifdef TRAMPOLINE_SECTION
2578 switch_to_section (TRAMPOLINE_SECTION
);
2580 switch_to_section (readonly_data_section
);
2583 /* Write the assembler code to define one. */
2584 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2586 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2588 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2589 targetm
.asm_out
.trampoline_template (asm_out_file
);
2591 /* Record the rtl to refer to it. */
2592 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2593 name
= ggc_strdup (label
);
2594 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2595 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2597 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2598 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2599 set_mem_size (initial_trampoline
, TRAMPOLINE_SIZE
);
2601 return initial_trampoline
;
2604 /* A and B are either alignments or offsets. Return the minimum alignment
2605 that may be assumed after adding the two together. */
2607 static inline unsigned
2608 min_align (unsigned int a
, unsigned int b
)
2610 return (a
| b
) & -(a
| b
);
2613 /* Return the assembler directive for creating a given kind of integer
2614 object. SIZE is the number of bytes in the object and ALIGNED_P
2615 indicates whether it is known to be aligned. Return NULL if the
2616 assembly dialect has no such directive.
2618 The returned string should be printed at the start of a new line and
2619 be followed immediately by the object's initial value. */
2622 integer_asm_op (int size
, int aligned_p
)
2624 struct asm_int_op
*ops
;
2627 ops
= &targetm
.asm_out
.aligned_op
;
2629 ops
= &targetm
.asm_out
.unaligned_op
;
2634 return targetm
.asm_out
.byte_op
;
2648 /* Use directive OP to assemble an integer object X. Print OP at the
2649 start of the line, followed immediately by the value of X. */
2652 assemble_integer_with_op (const char *op
, rtx x
)
2654 fputs (op
, asm_out_file
);
2655 output_addr_const (asm_out_file
, x
);
2656 fputc ('\n', asm_out_file
);
2659 /* The default implementation of the asm_out.integer target hook. */
2662 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2663 unsigned int size ATTRIBUTE_UNUSED
,
2664 int aligned_p ATTRIBUTE_UNUSED
)
2666 const char *op
= integer_asm_op (size
, aligned_p
);
2667 /* Avoid GAS bugs for large values. Specifically negative values whose
2668 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2669 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE_UNITS
)
2671 return op
&& (assemble_integer_with_op (op
, x
), true);
2674 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2675 the alignment of the integer in bits. Return 1 if we were able to output
2676 the constant, otherwise 0. We must be able to output the constant,
2677 if FORCE is nonzero. */
2680 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2684 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2686 /* See if the target hook can handle this kind of object. */
2687 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2690 /* If the object is a multi-byte one, try splitting it up. Split
2691 it into words it if is multi-word, otherwise split it into bytes. */
2694 machine_mode omode
, imode
;
2695 unsigned int subalign
;
2696 unsigned int subsize
, i
;
2697 enum mode_class mclass
;
2699 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2700 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2701 if (GET_CODE (x
) == CONST_FIXED
)
2702 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2706 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2707 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2709 for (i
= 0; i
< size
; i
+= subsize
)
2711 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2712 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2718 /* If we've printed some of it, but not all of it, there's no going
2723 gcc_assert (!force
);
2729 assemble_real (REAL_VALUE_TYPE d
, machine_mode mode
, unsigned int align
)
2731 long data
[4] = {0, 0, 0, 0};
2733 int bitsize
, nelts
, nunits
, units_per
;
2735 /* This is hairy. We have a quantity of known size. real_to_target
2736 will put it into an array of *host* longs, 32 bits per element
2737 (even if long is more than 32 bits). We need to determine the
2738 number of array elements that are occupied (nelts) and the number
2739 of *target* min-addressable units that will be occupied in the
2740 object file (nunits). We cannot assume that 32 divides the
2741 mode's bitsize (size * BITS_PER_UNIT) evenly.
2743 size * BITS_PER_UNIT is used here to make sure that padding bits
2744 (which might appear at either end of the value; real_to_target
2745 will include the padding bits in its output array) are included. */
2747 nunits
= GET_MODE_SIZE (mode
);
2748 bitsize
= nunits
* BITS_PER_UNIT
;
2749 nelts
= CEIL (bitsize
, 32);
2750 units_per
= 32 / BITS_PER_UNIT
;
2752 real_to_target (data
, &d
, mode
);
2754 /* Put out the first word with the specified alignment. */
2755 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2756 nunits
-= units_per
;
2758 /* Subsequent words need only 32-bit alignment. */
2759 align
= min_align (align
, 32);
2761 for (i
= 1; i
< nelts
; i
++)
2763 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2764 nunits
-= units_per
;
2768 /* Given an expression EXP with a constant value,
2769 reduce it to the sum of an assembler symbol and an integer.
2770 Store them both in the structure *VALUE.
2771 EXP must be reducible. */
2775 HOST_WIDE_INT offset
;
2779 decode_addr_const (tree exp
, struct addr_const
*value
)
2781 tree target
= TREE_OPERAND (exp
, 0);
2787 if (TREE_CODE (target
) == COMPONENT_REF
2788 && tree_fits_shwi_p (byte_position (TREE_OPERAND (target
, 1))))
2790 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2791 target
= TREE_OPERAND (target
, 0);
2793 else if (TREE_CODE (target
) == ARRAY_REF
2794 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2796 offset
+= (tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (target
)))
2797 * tree_to_shwi (TREE_OPERAND (target
, 1)));
2798 target
= TREE_OPERAND (target
, 0);
2800 else if (TREE_CODE (target
) == MEM_REF
2801 && TREE_CODE (TREE_OPERAND (target
, 0)) == ADDR_EXPR
)
2803 offset
+= mem_ref_offset (target
).to_short_addr ();
2804 target
= TREE_OPERAND (TREE_OPERAND (target
, 0), 0);
2806 else if (TREE_CODE (target
) == INDIRECT_REF
2807 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2808 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2810 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2815 switch (TREE_CODE (target
))
2819 x
= DECL_RTL (target
);
2823 x
= gen_rtx_MEM (FUNCTION_MODE
,
2824 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2833 x
= output_constant_def (target
, 1);
2840 gcc_assert (MEM_P (x
));
2844 value
->offset
= offset
;
2847 static GTY(()) hash_table
<tree_descriptor_hasher
> *const_desc_htab
;
2849 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2851 /* Constant pool accessor function. */
2853 hash_table
<tree_descriptor_hasher
> *
2854 constant_pool_htab (void)
2856 return const_desc_htab
;
2859 /* Compute a hash code for a constant expression. */
2862 tree_descriptor_hasher::hash (constant_descriptor_tree
*ptr
)
2868 const_hash_1 (const tree exp
)
2873 enum tree_code code
= TREE_CODE (exp
);
2875 /* Either set P and LEN to the address and len of something to hash and
2876 exit the switch or return a value. */
2881 p
= (char *) &TREE_INT_CST_ELT (exp
, 0);
2882 len
= TREE_INT_CST_NUNITS (exp
) * sizeof (HOST_WIDE_INT
);
2886 return real_hash (TREE_REAL_CST_PTR (exp
));
2889 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2892 p
= TREE_STRING_POINTER (exp
);
2893 len
= TREE_STRING_LENGTH (exp
);
2897 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2898 + const_hash_1 (TREE_IMAGPART (exp
)));
2904 hi
= 7 + VECTOR_CST_NELTS (exp
);
2906 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
2907 hi
= hi
* 563 + const_hash_1 (VECTOR_CST_ELT (exp
, i
));
2914 unsigned HOST_WIDE_INT idx
;
2917 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2919 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2921 hi
= hi
* 603 + const_hash_1 (value
);
2929 struct addr_const value
;
2931 decode_addr_const (exp
, &value
);
2932 switch (GET_CODE (value
.base
))
2935 /* Don't hash the address of the SYMBOL_REF;
2936 only use the offset and the symbol name. */
2938 p
= XSTR (value
.base
, 0);
2939 for (i
= 0; p
[i
] != 0; i
++)
2940 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2945 + CODE_LABEL_NUMBER (LABEL_REF_LABEL (value
.base
)) * 13);
2955 case POINTER_PLUS_EXPR
:
2957 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2958 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2961 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2964 /* A language specific constant. Just hash the code. */
2968 /* Compute hashing function. */
2970 for (i
= 0; i
< len
; i
++)
2971 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2976 /* Wrapper of compare_constant, for the htab interface. */
2978 tree_descriptor_hasher::equal (constant_descriptor_tree
*c1
,
2979 constant_descriptor_tree
*c2
)
2981 if (c1
->hash
!= c2
->hash
)
2983 return compare_constant (c1
->value
, c2
->value
);
2986 /* Compare t1 and t2, and return 1 only if they are known to result in
2987 the same bit pattern on output. */
2990 compare_constant (const tree t1
, const tree t2
)
2992 enum tree_code typecode
;
2994 if (t1
== NULL_TREE
)
2995 return t2
== NULL_TREE
;
2996 if (t2
== NULL_TREE
)
2999 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3002 switch (TREE_CODE (t1
))
3005 /* Integer constants are the same only if the same width of type. */
3006 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3008 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3010 return tree_int_cst_equal (t1
, t2
);
3013 /* Real constants are the same only if the same width of type. */
3014 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3017 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
3020 /* Fixed constants are the same only if the same width of type. */
3021 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3024 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
3027 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3030 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3031 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3032 TREE_STRING_LENGTH (t1
)));
3035 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
3036 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
3042 if (VECTOR_CST_NELTS (t1
) != VECTOR_CST_NELTS (t2
))
3045 for (i
= 0; i
< VECTOR_CST_NELTS (t1
); ++i
)
3046 if (!compare_constant (VECTOR_CST_ELT (t1
, i
),
3047 VECTOR_CST_ELT (t2
, i
)))
3055 vec
<constructor_elt
, va_gc
> *v1
, *v2
;
3056 unsigned HOST_WIDE_INT idx
;
3058 typecode
= TREE_CODE (TREE_TYPE (t1
));
3059 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3062 if (typecode
== ARRAY_TYPE
)
3064 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3065 /* For arrays, check that the sizes all match. */
3066 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3068 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
3073 /* For record and union constructors, require exact type
3075 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3079 v1
= CONSTRUCTOR_ELTS (t1
);
3080 v2
= CONSTRUCTOR_ELTS (t2
);
3081 if (vec_safe_length (v1
) != vec_safe_length (v2
))
3084 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
3086 constructor_elt
*c1
= &(*v1
)[idx
];
3087 constructor_elt
*c2
= &(*v2
)[idx
];
3089 /* Check that each value is the same... */
3090 if (!compare_constant (c1
->value
, c2
->value
))
3092 /* ... and that they apply to the same fields! */
3093 if (typecode
== ARRAY_TYPE
)
3095 if (!compare_constant (c1
->index
, c2
->index
))
3100 if (c1
->index
!= c2
->index
)
3111 struct addr_const value1
, value2
;
3115 decode_addr_const (t1
, &value1
);
3116 decode_addr_const (t2
, &value2
);
3118 if (value1
.offset
!= value2
.offset
)
3121 code
= GET_CODE (value1
.base
);
3122 if (code
!= GET_CODE (value2
.base
))
3128 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3132 ret
= (CODE_LABEL_NUMBER (LABEL_REF_LABEL (value1
.base
))
3133 == CODE_LABEL_NUMBER (LABEL_REF_LABEL (value2
.base
)));
3143 case POINTER_PLUS_EXPR
:
3146 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3147 && compare_constant (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3150 case VIEW_CONVERT_EXPR
:
3151 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3160 /* Return the section into which constant EXP should be placed. */
3163 get_constant_section (tree exp
, unsigned int align
)
3165 return targetm
.asm_out
.select_section (exp
,
3166 compute_reloc_for_constant (exp
),
3170 /* Return the size of constant EXP in bytes. */
3172 static HOST_WIDE_INT
3173 get_constant_size (tree exp
)
3177 size
= int_size_in_bytes (TREE_TYPE (exp
));
3178 if (TREE_CODE (exp
) == STRING_CST
)
3179 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3183 /* Subroutine of output_constant_def:
3184 No constant equal to EXP is known to have been output.
3185 Make a constant descriptor to enter EXP in the hash table.
3186 Assign the label number and construct RTL to refer to the
3187 constant's location in memory.
3188 Caller is responsible for updating the hash table. */
3190 static struct constant_descriptor_tree
*
3191 build_constant_desc (tree exp
)
3193 struct constant_descriptor_tree
*desc
;
3199 desc
= ggc_alloc
<constant_descriptor_tree
> ();
3202 /* Create a string containing the label name, in LABEL. */
3203 labelno
= const_labelno
++;
3204 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3206 /* Construct the VAR_DECL associated with the constant. */
3207 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3209 DECL_ARTIFICIAL (decl
) = 1;
3210 DECL_IGNORED_P (decl
) = 1;
3211 TREE_READONLY (decl
) = 1;
3212 TREE_STATIC (decl
) = 1;
3213 TREE_ADDRESSABLE (decl
) = 1;
3214 /* We don't set the RTL yet as this would cause varpool to assume that the
3215 variable is referenced. Moreover, it would just be dropped in LTO mode.
3216 Instead we set the flag that will be recognized in make_decl_rtl. */
3217 DECL_IN_CONSTANT_POOL (decl
) = 1;
3218 DECL_INITIAL (decl
) = desc
->value
;
3219 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3220 architectures so use DATA_ALIGNMENT as well, except for strings. */
3221 if (TREE_CODE (exp
) == STRING_CST
)
3223 #ifdef CONSTANT_ALIGNMENT
3224 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
3228 align_variable (decl
, 0);
3230 /* Now construct the SYMBOL_REF and the MEM. */
3231 if (use_object_blocks_p ())
3233 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
3234 symbol
= create_block_symbol (ggc_strdup (label
),
3235 get_block_for_section (sect
), -1);
3238 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3239 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3240 SET_SYMBOL_REF_DECL (symbol
, decl
);
3241 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3243 rtl
= gen_const_mem (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3244 set_mem_attributes (rtl
, exp
, 1);
3245 set_mem_alias_set (rtl
, 0);
3247 /* We cannot share RTX'es in pool entries.
3248 Mark this piece of RTL as required for unsharing. */
3249 RTX_FLAG (rtl
, used
) = 1;
3251 /* Set flags or add text to the name to record information, such as
3252 that it is a local symbol. If the name is changed, the macro
3253 ASM_OUTPUT_LABELREF will have to know how to strip this
3254 information. This call might invalidate our local variable
3255 SYMBOL; we can't use it afterward. */
3256 targetm
.encode_section_info (exp
, rtl
, true);
3263 /* Return an rtx representing a reference to constant data in memory
3264 for the constant expression EXP.
3266 If assembler code for such a constant has already been output,
3267 return an rtx to refer to it.
3268 Otherwise, output such a constant in memory
3269 and generate an rtx for it.
3271 If DEFER is nonzero, this constant can be deferred and output only
3272 if referenced in the function after all optimizations.
3274 `const_desc_table' records which constants already have label strings. */
3277 output_constant_def (tree exp
, int defer
)
3279 struct constant_descriptor_tree
*desc
;
3280 struct constant_descriptor_tree key
;
3282 /* Look up EXP in the table of constant descriptors. If we didn't find
3283 it, create a new one. */
3285 key
.hash
= const_hash_1 (exp
);
3286 constant_descriptor_tree
**loc
3287 = const_desc_htab
->find_slot_with_hash (&key
, key
.hash
, INSERT
);
3292 desc
= build_constant_desc (exp
);
3293 desc
->hash
= key
.hash
;
3297 maybe_output_constant_def_contents (desc
, defer
);
3301 /* Subroutine of output_constant_def: Decide whether or not we need to
3302 output the constant DESC now, and if so, do it. */
3304 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3307 rtx symbol
= XEXP (desc
->rtl
, 0);
3308 tree exp
= desc
->value
;
3310 if (flag_syntax_only
)
3313 if (TREE_ASM_WRITTEN (exp
))
3314 /* Already output; don't do it again. */
3317 /* We can always defer constants as long as the context allows
3321 /* Increment n_deferred_constants if it exists. It needs to be at
3322 least as large as the number of constants actually referred to
3323 by the function. If it's too small we'll stop looking too early
3324 and fail to emit constants; if it's too large we'll only look
3325 through the entire function when we could have stopped earlier. */
3327 n_deferred_constants
++;
3331 output_constant_def_contents (symbol
);
3334 /* Subroutine of output_constant_def_contents. Output the definition
3335 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3336 constant's alignment in bits. */
3339 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3343 size
= get_constant_size (exp
);
3345 /* Do any machine/system dependent processing of the constant. */
3346 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3348 /* Output the value of EXP. */
3349 output_constant (exp
, size
, align
);
3352 /* We must output the constant data referred to by SYMBOL; do so. */
3355 output_constant_def_contents (rtx symbol
)
3357 tree decl
= SYMBOL_REF_DECL (symbol
);
3358 tree exp
= DECL_INITIAL (decl
);
3360 bool asan_protected
= false;
3362 /* Make sure any other constants whose addresses appear in EXP
3363 are assigned label numbers. */
3364 output_addressed_constants (exp
);
3366 /* We are no longer deferring this constant. */
3367 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3369 if ((flag_sanitize
& SANITIZE_ADDRESS
)
3370 && TREE_CODE (exp
) == STRING_CST
3371 && asan_protect_global (exp
))
3373 asan_protected
= true;
3374 DECL_ALIGN (decl
) = MAX (DECL_ALIGN (decl
),
3375 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
3378 /* If the constant is part of an object block, make sure that the
3379 decl has been positioned within its block, but do not write out
3380 its definition yet. output_object_blocks will do that later. */
3381 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3382 place_block_symbol (symbol
);
3385 align
= DECL_ALIGN (decl
);
3386 switch_to_section (get_constant_section (exp
, align
));
3387 if (align
> BITS_PER_UNIT
)
3388 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3389 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3392 HOST_WIDE_INT size
= get_constant_size (exp
);
3393 assemble_zeros (asan_red_zone_size (size
));
3398 /* Look up EXP in the table of constant descriptors. Return the rtl
3399 if it has been emitted, else null. */
3402 lookup_constant_def (tree exp
)
3404 struct constant_descriptor_tree key
;
3407 key
.hash
= const_hash_1 (exp
);
3408 constant_descriptor_tree
*desc
3409 = const_desc_htab
->find_with_hash (&key
, key
.hash
);
3411 return (desc
? desc
->rtl
: NULL_RTX
);
3414 /* Return a tree representing a reference to constant data in memory
3415 for the constant expression EXP.
3417 This is the counterpart of output_constant_def at the Tree level. */
3420 tree_output_constant_def (tree exp
)
3422 struct constant_descriptor_tree
*desc
, key
;
3425 /* Look up EXP in the table of constant descriptors. If we didn't find
3426 it, create a new one. */
3428 key
.hash
= const_hash_1 (exp
);
3429 constant_descriptor_tree
**loc
3430 = const_desc_htab
->find_slot_with_hash (&key
, key
.hash
, INSERT
);
3435 desc
= build_constant_desc (exp
);
3436 desc
->hash
= key
.hash
;
3440 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3441 varpool_node::finalize_decl (decl
);
3445 struct GTY((chain_next ("%h.next"), for_user
)) constant_descriptor_rtx
{
3446 struct constant_descriptor_rtx
*next
;
3450 HOST_WIDE_INT offset
;
3458 struct const_rtx_desc_hasher
: ggc_hasher
<constant_descriptor_rtx
*>
3460 static hashval_t
hash (constant_descriptor_rtx
*);
3461 static bool equal (constant_descriptor_rtx
*, constant_descriptor_rtx
*);
3464 /* Used in the hash tables to avoid outputting the same constant
3465 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3466 are output once per function, not once per file. */
3467 /* ??? Only a few targets need per-function constant pools. Most
3468 can use one per-file pool. Should add a targetm bit to tell the
3471 struct GTY(()) rtx_constant_pool
{
3472 /* Pointers to first and last constant in pool, as ordered by offset. */
3473 struct constant_descriptor_rtx
*first
;
3474 struct constant_descriptor_rtx
*last
;
3476 /* Hash facility for making memory-constants from constant rtl-expressions.
3477 It is used on RISC machines where immediate integer arguments and
3478 constant addresses are restricted so that such constants must be stored
3480 hash_table
<const_rtx_desc_hasher
> *const_rtx_htab
;
3482 /* Current offset in constant pool (does not include any
3483 machine-specific header). */
3484 HOST_WIDE_INT offset
;
3487 /* Hash and compare functions for const_rtx_htab. */
3490 const_rtx_desc_hasher::hash (constant_descriptor_rtx
*desc
)
3496 const_rtx_desc_hasher::equal (constant_descriptor_rtx
*x
,
3497 constant_descriptor_rtx
*y
)
3499 if (x
->mode
!= y
->mode
)
3501 return rtx_equal_p (x
->constant
, y
->constant
);
3504 /* Hash one component of a constant. */
3507 const_rtx_hash_1 (const_rtx x
)
3509 unsigned HOST_WIDE_INT hwi
;
3515 code
= GET_CODE (x
);
3516 mode
= GET_MODE (x
);
3517 h
= (hashval_t
) code
* 1048573 + mode
;
3526 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3527 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3529 h
^= (hashval_t
) hwi
;
3530 for (i
= 1; i
< n
; ++i
)
3533 h
^= (hashval_t
) hwi
;
3538 case CONST_WIDE_INT
:
3539 hwi
= GET_MODE_PRECISION (mode
);
3541 for (i
= 0; i
< CONST_WIDE_INT_NUNITS (x
); i
++)
3542 hwi
^= CONST_WIDE_INT_ELT (x
, i
);
3547 if (TARGET_SUPPORTS_WIDE_INT
== 0 && mode
== VOIDmode
)
3549 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3553 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3557 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3561 h
^= htab_hash_string (XSTR (x
, 0));
3565 h
= h
* 251 + CODE_LABEL_NUMBER (LABEL_REF_LABEL (x
));
3569 case UNSPEC_VOLATILE
:
3570 h
= h
* 251 + XINT (x
, 1);
3580 /* Compute a hash value for X, which should be a constant. */
3583 const_rtx_hash (rtx x
)
3586 subrtx_iterator::array_type array
;
3587 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
3588 h
= h
* 509 + const_rtx_hash_1 (*iter
);
3593 /* Create and return a new rtx constant pool. */
3595 static struct rtx_constant_pool
*
3596 create_constant_pool (void)
3598 struct rtx_constant_pool
*pool
;
3600 pool
= ggc_alloc
<rtx_constant_pool
> ();
3601 pool
->const_rtx_htab
= hash_table
<const_rtx_desc_hasher
>::create_ggc (31);
3608 /* Initialize constant pool hashing for a new function. */
3611 init_varasm_status (void)
3613 crtl
->varasm
.pool
= create_constant_pool ();
3614 crtl
->varasm
.deferred_constants
= 0;
3617 /* Given a MINUS expression, simplify it if both sides
3618 include the same symbol. */
3621 simplify_subtraction (rtx x
)
3623 rtx r
= simplify_rtx (x
);
3627 /* Given a constant rtx X, make (or find) a memory constant for its value
3628 and return a MEM rtx to refer to it in memory. */
3631 force_const_mem (machine_mode mode
, rtx x
)
3633 struct constant_descriptor_rtx
*desc
, tmp
;
3634 struct rtx_constant_pool
*pool
;
3639 constant_descriptor_rtx
**slot
;
3641 /* If we're not allowed to drop X into the constant pool, don't. */
3642 if (targetm
.cannot_force_const_mem (mode
, x
))
3645 /* Record that this function has used a constant pool entry. */
3646 crtl
->uses_const_pool
= 1;
3648 /* Decide which pool to use. */
3649 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3650 ? shared_constant_pool
3651 : crtl
->varasm
.pool
);
3653 /* Lookup the value in the hashtable. */
3656 hash
= const_rtx_hash (x
);
3657 slot
= pool
->const_rtx_htab
->find_slot_with_hash (&tmp
, hash
, INSERT
);
3660 /* If the constant was already present, return its memory. */
3662 return copy_rtx (desc
->mem
);
3664 /* Otherwise, create a new descriptor. */
3665 desc
= ggc_alloc
<constant_descriptor_rtx
> ();
3668 /* Align the location counter as required by EXP's data type. */
3669 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3670 #ifdef CONSTANT_ALIGNMENT
3672 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3673 if (type
!= NULL_TREE
)
3674 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3678 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3679 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3682 desc
->constant
= copy_rtx (tmp
.constant
);
3683 desc
->offset
= pool
->offset
;
3686 desc
->align
= align
;
3687 desc
->labelno
= const_labelno
;
3690 pool
->offset
+= GET_MODE_SIZE (mode
);
3692 pool
->last
->next
= desc
;
3694 pool
->first
= pool
->last
= desc
;
3697 /* Create a string containing the label name, in LABEL. */
3698 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3701 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3702 the constants pool. */
3703 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3705 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3706 symbol
= create_block_symbol (ggc_strdup (label
),
3707 get_block_for_section (sect
), -1);
3710 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3712 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3713 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3714 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3716 /* Construct the MEM. */
3717 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3718 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3719 set_mem_align (def
, align
);
3721 /* If we're dropping a label to the constant pool, make sure we
3723 if (GET_CODE (x
) == LABEL_REF
)
3724 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3726 return copy_rtx (def
);
3729 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3732 get_pool_constant (const_rtx addr
)
3734 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3737 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3738 and whether it has been output or not. */
3741 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3743 struct constant_descriptor_rtx
*desc
;
3745 desc
= SYMBOL_REF_CONSTANT (addr
);
3746 *pmarked
= (desc
->mark
!= 0);
3747 return desc
->constant
;
3750 /* Similar, return the mode. */
3753 get_pool_mode (const_rtx addr
)
3755 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3758 /* Return the size of the constant pool. */
3761 get_pool_size (void)
3763 return crtl
->varasm
.pool
->offset
;
3766 /* Worker function for output_constant_pool_1. Emit assembly for X
3767 in MODE with known alignment ALIGN. */
3770 output_constant_pool_2 (machine_mode mode
, rtx x
, unsigned int align
)
3772 switch (GET_MODE_CLASS (mode
))
3775 case MODE_DECIMAL_FLOAT
:
3779 gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x
));
3780 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3781 assemble_real (r
, mode
, align
);
3786 case MODE_PARTIAL_INT
:
3791 case MODE_POINTER_BOUNDS
:
3792 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3795 case MODE_VECTOR_FLOAT
:
3796 case MODE_VECTOR_INT
:
3797 case MODE_VECTOR_FRACT
:
3798 case MODE_VECTOR_UFRACT
:
3799 case MODE_VECTOR_ACCUM
:
3800 case MODE_VECTOR_UACCUM
:
3803 machine_mode submode
= GET_MODE_INNER (mode
);
3804 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3806 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3807 units
= CONST_VECTOR_NUNITS (x
);
3809 for (i
= 0; i
< units
; i
++)
3811 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3812 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3822 /* Worker function for output_constant_pool. Emit constant DESC,
3823 giving it ALIGN bits of alignment. */
3826 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3833 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3834 whose CODE_LABEL has been deleted. This can occur if a jump table
3835 is eliminated by optimization. If so, write a constant of zero
3836 instead. Note that this can also happen by turning the
3837 CODE_LABEL into a NOTE. */
3838 /* ??? This seems completely and utterly wrong. Certainly it's
3839 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3840 functioning even with rtx_insn::deleted and friends. */
3843 switch (GET_CODE (tmp
))
3846 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3847 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3849 tmp
= XEXP (XEXP (tmp
, 0), 0);
3853 tmp
= LABEL_REF_LABEL (tmp
);
3854 gcc_assert (!as_a
<rtx_insn
*> (tmp
)->deleted ());
3855 gcc_assert (!NOTE_P (tmp
)
3856 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3863 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3864 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3865 align
, desc
->labelno
, done
);
3868 assemble_align (align
);
3870 /* Output the label. */
3871 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3873 /* Output the data. */
3874 output_constant_pool_2 (desc
->mode
, x
, align
);
3876 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3877 sections have proper size. */
3878 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3880 && (in_section
->common
.flags
& SECTION_MERGE
))
3881 assemble_align (align
);
3883 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3889 /* Mark all constants that are referenced by SYMBOL_REFs in X.
3890 Emit referenced deferred strings. */
3893 mark_constants_in_pattern (rtx insn
)
3895 subrtx_iterator::array_type array
;
3896 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), ALL
)
3898 const_rtx x
= *iter
;
3899 if (GET_CODE (x
) == SYMBOL_REF
)
3901 if (CONSTANT_POOL_ADDRESS_P (x
))
3903 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3904 if (desc
->mark
== 0)
3907 iter
.substitute (desc
->constant
);
3910 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3912 tree decl
= SYMBOL_REF_DECL (x
);
3913 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
3915 n_deferred_constants
--;
3916 output_constant_def_contents (CONST_CAST_RTX (x
));
3923 /* Look through appropriate parts of INSN, marking all entries in the
3924 constant pool which are actually being used. Entries that are only
3925 referenced by other constants are also marked as used. Emit
3926 deferred strings that are used. */
3929 mark_constants (rtx_insn
*insn
)
3934 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3935 insns, not any notes that may be attached. We don't want to mark
3936 a constant just because it happens to appear in a REG_EQUIV note. */
3937 if (rtx_sequence
*seq
= dyn_cast
<rtx_sequence
*> (PATTERN (insn
)))
3939 int i
, n
= seq
->len ();
3940 for (i
= 0; i
< n
; ++i
)
3942 rtx subinsn
= seq
->element (i
);
3943 if (INSN_P (subinsn
))
3944 mark_constants_in_pattern (subinsn
);
3948 mark_constants_in_pattern (insn
);
3951 /* Look through the instructions for this function, and mark all the
3952 entries in POOL which are actually being used. Emit deferred constants
3953 which have indeed been used. */
3956 mark_constant_pool (void)
3960 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
3963 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3964 mark_constants (insn
);
3967 /* Write all the constants in POOL. */
3970 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
3972 struct constant_descriptor_rtx
*desc
;
3974 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3977 /* If the constant is part of an object_block, make sure that
3978 the constant has been positioned within its block, but do not
3979 write out its definition yet. output_object_blocks will do
3981 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
3982 && SYMBOL_REF_BLOCK (desc
->sym
))
3983 place_block_symbol (desc
->sym
);
3986 switch_to_section (targetm
.asm_out
.select_rtx_section
3987 (desc
->mode
, desc
->constant
, desc
->align
));
3988 output_constant_pool_1 (desc
, desc
->align
);
3993 /* Mark all constants that are used in the current function, then write
3994 out the function's private constant pool. */
3997 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3998 tree fndecl ATTRIBUTE_UNUSED
)
4000 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
4002 /* It is possible for gcc to call force_const_mem and then to later
4003 discard the instructions which refer to the constant. In such a
4004 case we do not need to output the constant. */
4005 mark_constant_pool ();
4007 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4008 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4011 output_constant_pool_contents (pool
);
4013 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4014 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4018 /* Write the contents of the shared constant pool. */
4021 output_shared_constant_pool (void)
4023 output_constant_pool_contents (shared_constant_pool
);
4026 /* Determine what kind of relocations EXP may need. */
4029 compute_reloc_for_constant (tree exp
)
4031 int reloc
= 0, reloc2
;
4034 switch (TREE_CODE (exp
))
4038 /* Go inside any operations that get_inner_reference can handle and see
4039 if what's inside is a constant: no need to do anything here for
4040 addresses of variables or functions. */
4041 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4042 tem
= TREE_OPERAND (tem
, 0))
4045 if (TREE_CODE (tem
) == MEM_REF
4046 && TREE_CODE (TREE_OPERAND (tem
, 0)) == ADDR_EXPR
)
4048 reloc
= compute_reloc_for_constant (TREE_OPERAND (tem
, 0));
4052 if (!targetm
.binds_local_p (tem
))
4059 case POINTER_PLUS_EXPR
:
4060 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4061 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4065 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4066 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4067 /* The difference of two local labels is computable at link time. */
4068 if (reloc
== 1 && reloc2
== 1)
4075 case VIEW_CONVERT_EXPR
:
4076 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4081 unsigned HOST_WIDE_INT idx
;
4082 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4084 reloc
|= compute_reloc_for_constant (tem
);
4094 /* Find all the constants whose addresses are referenced inside of EXP,
4095 and make sure assembler code with a label has been output for each one.
4096 Indicate whether an ADDR_EXPR has been encountered. */
4099 output_addressed_constants (tree exp
)
4103 switch (TREE_CODE (exp
))
4107 /* Go inside any operations that get_inner_reference can handle and see
4108 if what's inside is a constant: no need to do anything here for
4109 addresses of variables or functions. */
4110 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4111 tem
= TREE_OPERAND (tem
, 0))
4114 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4115 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4116 tem
= DECL_INITIAL (tem
);
4118 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4119 output_constant_def (tem
, 0);
4121 if (TREE_CODE (tem
) == MEM_REF
)
4122 output_addressed_constants (TREE_OPERAND (tem
, 0));
4126 case POINTER_PLUS_EXPR
:
4128 output_addressed_constants (TREE_OPERAND (exp
, 1));
4132 case VIEW_CONVERT_EXPR
:
4133 output_addressed_constants (TREE_OPERAND (exp
, 0));
4138 unsigned HOST_WIDE_INT idx
;
4139 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4141 output_addressed_constants (tem
);
4150 /* Whether a constructor CTOR is a valid static constant initializer if all
4151 its elements are. This used to be internal to initializer_constant_valid_p
4152 and has been exposed to let other functions like categorize_ctor_elements
4153 evaluate the property while walking a constructor for other purposes. */
4156 constructor_static_from_elts_p (const_tree ctor
)
4158 return (TREE_CONSTANT (ctor
)
4159 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4160 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
4161 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
4164 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4167 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4168 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4169 which are valid when ENDTYPE is an integer of any size; in
4170 particular, this does not accept a pointer minus a constant. This
4171 returns null_pointer_node if the VALUE is an absolute constant
4172 which can be used to initialize a static variable. Otherwise it
4176 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4180 if (!INTEGRAL_TYPE_P (endtype
))
4183 op0
= TREE_OPERAND (value
, 0);
4184 op1
= TREE_OPERAND (value
, 1);
4186 /* Like STRIP_NOPS except allow the operand mode to widen. This
4187 works around a feature of fold that simplifies (int)(p1 - p2) to
4188 ((int)p1 - (int)p2) under the theory that the narrower operation
4191 while (CONVERT_EXPR_P (op0
)
4192 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4194 tree inner
= TREE_OPERAND (op0
, 0);
4195 if (inner
== error_mark_node
4196 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4197 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4198 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4203 while (CONVERT_EXPR_P (op1
)
4204 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4206 tree inner
= TREE_OPERAND (op1
, 0);
4207 if (inner
== error_mark_node
4208 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4209 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4210 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4215 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4219 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4220 cache
? cache
+ 2 : NULL
);
4221 /* Both initializers must be known. */
4225 && (op0
== null_pointer_node
4226 || TREE_CODE (value
) == MINUS_EXPR
))
4227 return null_pointer_node
;
4229 /* Support differences between labels. */
4230 if (TREE_CODE (op0
) == LABEL_DECL
4231 && TREE_CODE (op1
) == LABEL_DECL
)
4232 return null_pointer_node
;
4234 if (TREE_CODE (op0
) == STRING_CST
4235 && TREE_CODE (op1
) == STRING_CST
4236 && operand_equal_p (op0
, op1
, 1))
4237 return null_pointer_node
;
4243 /* Helper function of initializer_constant_valid_p.
4244 Return nonzero if VALUE is a valid constant-valued expression
4245 for use in initializing a static variable; one that can be an
4246 element of a "constant" initializer.
4248 Return null_pointer_node if the value is absolute;
4249 if it is relocatable, return the variable that determines the relocation.
4250 We assume that VALUE has been folded as much as possible;
4251 therefore, we do not need to check for such things as
4252 arithmetic-combinations of integers.
4254 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4257 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4261 switch (TREE_CODE (value
))
4264 if (constructor_static_from_elts_p (value
))
4266 unsigned HOST_WIDE_INT idx
;
4268 bool absolute
= true;
4270 if (cache
&& cache
[0] == value
)
4272 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4275 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4282 cache
[1] = NULL_TREE
;
4286 if (reloc
!= null_pointer_node
)
4289 /* For a non-absolute relocation, there is no single
4290 variable that can be "the variable that determines the
4295 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4297 return absolute
? null_pointer_node
: error_mark_node
;
4300 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4308 return null_pointer_node
;
4313 tree op0
= staticp (TREE_OPERAND (value
, 0));
4316 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4317 to be a constant, this is old-skool offsetof-like nonsense. */
4318 if (TREE_CODE (op0
) == INDIRECT_REF
4319 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4320 return null_pointer_node
;
4321 /* Taking the address of a nested function involves a trampoline,
4322 unless we don't need or want one. */
4323 if (TREE_CODE (op0
) == FUNCTION_DECL
4324 && DECL_STATIC_CHAIN (op0
)
4325 && !TREE_NO_TRAMPOLINE (value
))
4327 /* "&{...}" requires a temporary to hold the constructed
4329 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4335 case NON_LVALUE_EXPR
:
4336 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4339 case VIEW_CONVERT_EXPR
:
4341 tree src
= TREE_OPERAND (value
, 0);
4342 tree src_type
= TREE_TYPE (src
);
4343 tree dest_type
= TREE_TYPE (value
);
4345 /* Allow view-conversions from aggregate to non-aggregate type only
4346 if the bit pattern is fully preserved afterwards; otherwise, the
4347 RTL expander won't be able to apply a subsequent transformation
4348 to the underlying constructor. */
4349 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4351 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4352 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4357 /* Allow all other kinds of view-conversion. */
4358 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4363 tree src
= TREE_OPERAND (value
, 0);
4364 tree src_type
= TREE_TYPE (src
);
4365 tree dest_type
= TREE_TYPE (value
);
4367 /* Allow conversions between pointer types, floating-point
4368 types, and offset types. */
4369 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4370 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4371 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4372 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4373 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4375 /* Allow length-preserving conversions between integer types. */
4376 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4377 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4378 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4380 /* Allow conversions between other integer types only if
4382 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4384 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4385 if (inner
== null_pointer_node
)
4386 return null_pointer_node
;
4390 /* Allow (int) &foo provided int is as wide as a pointer. */
4391 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4392 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4393 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4395 /* Likewise conversions from int to pointers, but also allow
4396 conversions from 0. */
4397 if ((POINTER_TYPE_P (dest_type
)
4398 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4399 && INTEGRAL_TYPE_P (src_type
))
4401 if (TREE_CODE (src
) == INTEGER_CST
4402 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4403 return null_pointer_node
;
4404 if (integer_zerop (src
))
4405 return null_pointer_node
;
4406 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4407 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4410 /* Allow conversions to struct or union types if the value
4412 if (TREE_CODE (dest_type
) == RECORD_TYPE
4413 || TREE_CODE (dest_type
) == UNION_TYPE
)
4414 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4418 case POINTER_PLUS_EXPR
:
4420 /* Any valid floating-point constants will have been folded by now;
4421 with -frounding-math we hit this with addition of two constants. */
4422 if (TREE_CODE (endtype
) == REAL_TYPE
)
4424 if (cache
&& cache
[0] == value
)
4426 if (! INTEGRAL_TYPE_P (endtype
)
4427 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4429 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4431 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4434 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4435 endtype
, ncache
+ 2);
4436 /* If either term is absolute, use the other term's relocation. */
4437 if (valid0
== null_pointer_node
)
4439 else if (valid1
== null_pointer_node
)
4441 /* Support narrowing pointer differences. */
4443 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4447 /* Support narrowing pointer differences. */
4448 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4457 if (TREE_CODE (endtype
) == REAL_TYPE
)
4459 if (cache
&& cache
[0] == value
)
4461 if (! INTEGRAL_TYPE_P (endtype
)
4462 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4464 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4466 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4469 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4470 endtype
, ncache
+ 2);
4471 /* Win if second argument is absolute. */
4472 if (valid1
== null_pointer_node
)
4474 /* Win if both arguments have the same relocation.
4475 Then the value is absolute. */
4476 else if (valid0
== valid1
&& valid0
!= 0)
4477 ret
= null_pointer_node
;
4478 /* Since GCC guarantees that string constants are unique in the
4479 generated code, a subtraction between two copies of the same
4480 constant string is absolute. */
4481 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4482 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4483 && operand_equal_p (valid0
, valid1
, 1))
4484 ret
= null_pointer_node
;
4485 /* Support narrowing differences. */
4487 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4491 /* Support narrowing differences. */
4492 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4507 /* Return nonzero if VALUE is a valid constant-valued expression
4508 for use in initializing a static variable; one that can be an
4509 element of a "constant" initializer.
4511 Return null_pointer_node if the value is absolute;
4512 if it is relocatable, return the variable that determines the relocation.
4513 We assume that VALUE has been folded as much as possible;
4514 therefore, we do not need to check for such things as
4515 arithmetic-combinations of integers. */
4517 initializer_constant_valid_p (tree value
, tree endtype
)
4519 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4522 /* Return true if VALUE is a valid constant-valued expression
4523 for use in initializing a static bit-field; one that can be
4524 an element of a "constant" initializer. */
4527 initializer_constant_valid_for_bitfield_p (tree value
)
4529 /* For bitfields we support integer constants or possibly nested aggregates
4531 switch (TREE_CODE (value
))
4535 unsigned HOST_WIDE_INT idx
;
4538 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4539 if (!initializer_constant_valid_for_bitfield_p (elt
))
4548 case VIEW_CONVERT_EXPR
:
4549 case NON_LVALUE_EXPR
:
4551 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4560 /* output_constructor outer state of relevance in recursive calls, typically
4561 for nested aggregate bitfields. */
4564 unsigned int bit_offset
; /* current position in ... */
4565 int byte
; /* ... the outer byte buffer. */
4568 static unsigned HOST_WIDE_INT
4569 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4572 /* Output assembler code for constant EXP, with no label.
4573 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4574 Assumes output_addressed_constants has been done on EXP already.
4576 Generate at least SIZE bytes of assembler data, padding at the end
4577 with zeros if necessary. SIZE must always be specified. The returned
4578 value is the actual number of bytes of assembler data generated, which
4579 may be bigger than SIZE if the object contains a variable length field.
4581 SIZE is important for structure constructors,
4582 since trailing members may have been omitted from the constructor.
4583 It is also important for initialization of arrays from string constants
4584 since the full length of the string constant might not be wanted.
4585 It is also needed for initialization of unions, where the initializer's
4586 type is just one member, and that may not be as long as the union.
4588 There a case in which we would fail to output exactly SIZE bytes:
4589 for a structure constructor that wants to produce more than SIZE bytes.
4590 But such constructors will never be generated for any possible input.
4592 ALIGN is the alignment of the data in bits. */
4594 static unsigned HOST_WIDE_INT
4595 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4597 enum tree_code code
;
4598 unsigned HOST_WIDE_INT thissize
;
4600 if (size
== 0 || flag_syntax_only
)
4603 /* See if we're trying to initialize a pointer in a non-default mode
4604 to the address of some declaration somewhere. If the target says
4605 the mode is valid for pointers, assume the target has a way of
4607 if (TREE_CODE (exp
) == NOP_EXPR
4608 && POINTER_TYPE_P (TREE_TYPE (exp
))
4609 && targetm
.addr_space
.valid_pointer_mode
4610 (TYPE_MODE (TREE_TYPE (exp
)),
4611 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4613 tree saved_type
= TREE_TYPE (exp
);
4615 /* Peel off any intermediate conversions-to-pointer for valid
4617 while (TREE_CODE (exp
) == NOP_EXPR
4618 && POINTER_TYPE_P (TREE_TYPE (exp
))
4619 && targetm
.addr_space
.valid_pointer_mode
4620 (TYPE_MODE (TREE_TYPE (exp
)),
4621 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4622 exp
= TREE_OPERAND (exp
, 0);
4624 /* If what we're left with is the address of something, we can
4625 convert the address to the final type and output it that
4627 if (TREE_CODE (exp
) == ADDR_EXPR
)
4628 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4629 /* Likewise for constant ints. */
4630 else if (TREE_CODE (exp
) == INTEGER_CST
)
4631 exp
= wide_int_to_tree (saved_type
, exp
);
4635 /* Eliminate any conversions since we'll be outputting the underlying
4637 while (CONVERT_EXPR_P (exp
)
4638 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4639 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4641 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4642 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4644 /* Make sure eliminating the conversion is really a no-op, except with
4645 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4646 union types to allow for Ada unchecked unions. */
4647 if (type_size
> op_size
4648 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4649 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4650 /* Keep the conversion. */
4653 exp
= TREE_OPERAND (exp
, 0);
4656 code
= TREE_CODE (TREE_TYPE (exp
));
4657 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4659 /* Allow a constructor with no elements for any data type.
4660 This means to fill the space with zeros. */
4661 if (TREE_CODE (exp
) == CONSTRUCTOR
4662 && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp
)))
4664 assemble_zeros (size
);
4668 if (TREE_CODE (exp
) == FDESC_EXPR
)
4670 #ifdef ASM_OUTPUT_FDESC
4671 HOST_WIDE_INT part
= tree_to_shwi (TREE_OPERAND (exp
, 1));
4672 tree decl
= TREE_OPERAND (exp
, 0);
4673 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4680 /* Now output the underlying data. If we've handling the padding, return.
4681 Otherwise, break and ensure SIZE is the size written. */
4688 case REFERENCE_TYPE
:
4690 case FIXED_POINT_TYPE
:
4691 case POINTER_BOUNDS_TYPE
:
4693 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4694 EXPAND_INITIALIZER
),
4695 MIN (size
, thissize
), align
, 0))
4696 error ("initializer for integer/fixed-point value is too complicated");
4700 if (TREE_CODE (exp
) != REAL_CST
)
4701 error ("initializer for floating value is not a floating constant");
4703 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4707 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4708 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4709 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4714 switch (TREE_CODE (exp
))
4717 return output_constructor (exp
, size
, align
, NULL
);
4720 = MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
), size
);
4721 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4725 machine_mode inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4726 unsigned int nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4727 int elt_size
= GET_MODE_SIZE (inner
);
4728 output_constant (VECTOR_CST_ELT (exp
, 0), elt_size
, align
);
4729 thissize
= elt_size
;
4730 for (unsigned int i
= 1; i
< VECTOR_CST_NELTS (exp
); i
++)
4732 output_constant (VECTOR_CST_ELT (exp
, i
), elt_size
, nalign
);
4733 thissize
+= elt_size
;
4744 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4745 return output_constructor (exp
, size
, align
, NULL
);
4754 if (size
> thissize
)
4755 assemble_zeros (size
- thissize
);
4761 /* Subroutine of output_constructor, used for computing the size of
4762 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4763 type with an unspecified upper bound. */
4765 static unsigned HOST_WIDE_INT
4766 array_size_for_constructor (tree val
)
4769 unsigned HOST_WIDE_INT cnt
;
4770 tree index
, value
, tmp
;
4773 /* This code used to attempt to handle string constants that are not
4774 arrays of single-bytes, but nothing else does, so there's no point in
4776 if (TREE_CODE (val
) == STRING_CST
)
4777 return TREE_STRING_LENGTH (val
);
4779 max_index
= NULL_TREE
;
4780 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4782 if (TREE_CODE (index
) == RANGE_EXPR
)
4783 index
= TREE_OPERAND (index
, 1);
4784 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4788 if (max_index
== NULL_TREE
)
4791 /* Compute the total number of array elements. */
4792 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4793 i
= wi::to_offset (max_index
) - wi::to_offset (tmp
) + 1;
4795 /* Multiply by the array element unit size to find number of bytes. */
4796 i
*= wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4798 gcc_assert (wi::fits_uhwi_p (i
));
4799 return i
.to_uhwi ();
4802 /* Other datastructures + helpers for output_constructor. */
4804 /* output_constructor local state to support interaction with helpers. */
4808 /* Received arguments. */
4809 tree exp
; /* Constructor expression. */
4810 tree type
; /* Type of constructor expression. */
4811 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4812 unsigned int align
; /* Known initial alignment. */
4813 tree min_index
; /* Lower bound if specified for an array. */
4815 /* Output processing state. */
4816 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4817 int byte
; /* Part of a bitfield byte yet to be output. */
4818 int last_relative_index
; /* Implicit or explicit index of the last
4819 array element output within a bitfield. */
4820 bool byte_buffer_in_use
; /* Whether BYTE is in use. */
4822 /* Current element. */
4823 tree field
; /* Current field decl in a record. */
4824 tree val
; /* Current element value. */
4825 tree index
; /* Current element index. */
4829 /* Helper for output_constructor. From the current LOCAL state, output a
4830 RANGE_EXPR element. */
4833 output_constructor_array_range (oc_local_state
*local
)
4835 unsigned HOST_WIDE_INT fieldsize
4836 = int_size_in_bytes (TREE_TYPE (local
->type
));
4838 HOST_WIDE_INT lo_index
4839 = tree_to_shwi (TREE_OPERAND (local
->index
, 0));
4840 HOST_WIDE_INT hi_index
4841 = tree_to_shwi (TREE_OPERAND (local
->index
, 1));
4842 HOST_WIDE_INT index
;
4845 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4847 for (index
= lo_index
; index
<= hi_index
; index
++)
4849 /* Output the element's initial value. */
4850 if (local
->val
== NULL_TREE
)
4851 assemble_zeros (fieldsize
);
4853 fieldsize
= output_constant (local
->val
, fieldsize
, align2
);
4855 /* Count its size. */
4856 local
->total_bytes
+= fieldsize
;
4860 /* Helper for output_constructor. From the current LOCAL state, output a
4861 field element that is not true bitfield or part of an outer one. */
4864 output_constructor_regular_field (oc_local_state
*local
)
4866 /* Field size and position. Since this structure is static, we know the
4867 positions are constant. */
4868 unsigned HOST_WIDE_INT fieldsize
;
4869 HOST_WIDE_INT fieldpos
;
4871 unsigned int align2
;
4873 if (local
->index
!= NULL_TREE
)
4875 /* Perform the index calculation in modulo arithmetic but
4876 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
4877 but we are using an unsigned sizetype. */
4878 unsigned prec
= TYPE_PRECISION (sizetype
);
4879 offset_int idx
= wi::sext (wi::to_offset (local
->index
)
4880 - wi::to_offset (local
->min_index
), prec
);
4881 fieldpos
= (idx
* wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
))))
4884 else if (local
->field
!= NULL_TREE
)
4885 fieldpos
= int_byte_position (local
->field
);
4889 /* Output any buffered-up bit-fields preceding this element. */
4890 if (local
->byte_buffer_in_use
)
4892 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4893 local
->total_bytes
++;
4894 local
->byte_buffer_in_use
= false;
4897 /* Advance to offset of this element.
4898 Note no alignment needed in an array, since that is guaranteed
4899 if each element has the proper size. */
4900 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4901 && fieldpos
> local
->total_bytes
)
4903 assemble_zeros (fieldpos
- local
->total_bytes
);
4904 local
->total_bytes
= fieldpos
;
4907 /* Find the alignment of this element. */
4908 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
4910 /* Determine size this element should occupy. */
4915 /* If this is an array with an unspecified upper bound,
4916 the initializer determines the size. */
4917 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4918 but we cannot do this until the deprecated support for
4919 initializing zero-length array members is removed. */
4920 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
4921 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
4922 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
4924 fieldsize
= array_size_for_constructor (local
->val
);
4925 /* Given a non-empty initialization, this field had
4927 gcc_assert (!fieldsize
|| !DECL_CHAIN (local
->field
));
4930 fieldsize
= tree_to_uhwi (DECL_SIZE_UNIT (local
->field
));
4933 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
4935 /* Output the element's initial value. */
4936 if (local
->val
== NULL_TREE
)
4937 assemble_zeros (fieldsize
);
4939 fieldsize
= output_constant (local
->val
, fieldsize
, align2
);
4941 /* Count its size. */
4942 local
->total_bytes
+= fieldsize
;
4945 /* Helper for output_constructor. From the LOCAL state, output an element
4946 that is a true bitfield or part of an outer one. BIT_OFFSET is the offset
4947 from the start of a possibly ongoing outer byte buffer. */
4950 output_constructor_bitfield (oc_local_state
*local
, unsigned int bit_offset
)
4952 /* Bit size of this element. */
4953 HOST_WIDE_INT ebitsize
4955 ? tree_to_uhwi (DECL_SIZE (local
->field
))
4956 : tree_to_uhwi (TYPE_SIZE (TREE_TYPE (local
->type
))));
4958 /* Relative index of this element if this is an array component. */
4959 HOST_WIDE_INT relative_index
4962 ? (tree_to_shwi (local
->index
)
4963 - tree_to_shwi (local
->min_index
))
4964 : local
->last_relative_index
+ 1)
4967 /* Bit position of this element from the start of the containing
4969 HOST_WIDE_INT constructor_relative_ebitpos
4971 ? int_bit_position (local
->field
)
4972 : ebitsize
* relative_index
);
4974 /* Bit position of this element from the start of a possibly ongoing
4975 outer byte buffer. */
4976 HOST_WIDE_INT byte_relative_ebitpos
4977 = bit_offset
+ constructor_relative_ebitpos
;
4979 /* From the start of a possibly ongoing outer byte buffer, offsets to
4980 the first bit of this element and to the first bit past the end of
4982 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
4983 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
4985 local
->last_relative_index
= relative_index
;
4987 if (local
->val
== NULL_TREE
)
4988 local
->val
= integer_zero_node
;
4990 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
4991 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
4992 local
->val
= TREE_OPERAND (local
->val
, 0);
4994 if (TREE_CODE (local
->val
) != INTEGER_CST
4995 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
4997 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
5001 /* If this field does not start in this (or next) byte, skip some bytes. */
5002 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5004 /* Output remnant of any bit field in previous bytes. */
5005 if (local
->byte_buffer_in_use
)
5007 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5008 local
->total_bytes
++;
5009 local
->byte_buffer_in_use
= false;
5012 /* If still not at proper byte, advance to there. */
5013 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5015 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
5016 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
5017 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
5021 /* Set up the buffer if necessary. */
5022 if (!local
->byte_buffer_in_use
)
5026 local
->byte_buffer_in_use
= true;
5029 /* If this is nested constructor, recurse passing the bit offset and the
5030 pending data, then retrieve the new pending data afterwards. */
5031 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
5033 oc_outer_state temp_state
;
5034 temp_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
5035 temp_state
.byte
= local
->byte
;
5037 += output_constructor (local
->val
, 0, 0, &temp_state
);
5038 local
->byte
= temp_state
.byte
;
5042 /* Otherwise, we must split the element into pieces that fall within
5043 separate bytes, and combine each byte with previous or following
5045 while (next_offset
< end_offset
)
5049 HOST_WIDE_INT value
;
5050 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5051 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5053 /* Advance from byte to byte within this element when necessary. */
5054 while (next_byte
!= local
->total_bytes
)
5056 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5057 local
->total_bytes
++;
5061 /* Number of bits we can process at once (all part of the same byte). */
5062 this_time
= MIN (end_offset
- next_offset
, BITS_PER_UNIT
- next_bit
);
5063 if (BYTES_BIG_ENDIAN
)
5065 /* On big-endian machine, take the most significant bits (of the
5066 bits that are significant) first and put them into bytes from
5067 the most significant end. */
5068 shift
= end_offset
- next_offset
- this_time
;
5070 /* Don't try to take a bunch of bits that cross
5071 the word boundary in the INTEGER_CST. We can
5072 only select bits from one element. */
5073 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5074 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5076 const int end
= shift
+ this_time
- 1;
5077 shift
= end
& -HOST_BITS_PER_WIDE_INT
;
5078 this_time
= end
- shift
+ 1;
5081 /* Now get the bits from the appropriate constant word. */
5082 value
= TREE_INT_CST_ELT (local
->val
, shift
/ HOST_BITS_PER_WIDE_INT
);
5083 shift
= shift
& (HOST_BITS_PER_WIDE_INT
- 1);
5085 /* Get the result. This works only when:
5086 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5087 local
->byte
|= (((value
>> shift
)
5088 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5089 << (BITS_PER_UNIT
- this_time
- next_bit
));
5093 /* On little-endian machines, take the least significant bits of
5094 the value first and pack them starting at the least significant
5095 bits of the bytes. */
5096 shift
= next_offset
- byte_relative_ebitpos
;
5098 /* Don't try to take a bunch of bits that cross
5099 the word boundary in the INTEGER_CST. We can
5100 only select bits from one element. */
5101 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5102 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5104 = HOST_BITS_PER_WIDE_INT
- (shift
& (HOST_BITS_PER_WIDE_INT
- 1));
5106 /* Now get the bits from the appropriate constant word. */
5107 value
= TREE_INT_CST_ELT (local
->val
, shift
/ HOST_BITS_PER_WIDE_INT
);
5108 shift
= shift
& (HOST_BITS_PER_WIDE_INT
- 1);
5110 /* Get the result. This works only when:
5111 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5112 local
->byte
|= (((value
>> shift
)
5113 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5117 next_offset
+= this_time
;
5118 local
->byte_buffer_in_use
= true;
5122 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5123 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5124 caller output state of relevance in recursive invocations. */
5126 static unsigned HOST_WIDE_INT
5127 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5128 unsigned int align
, oc_outer_state
*outer
)
5130 unsigned HOST_WIDE_INT cnt
;
5131 constructor_elt
*ce
;
5133 oc_local_state local
;
5135 /* Setup our local state to communicate with helpers. */
5137 local
.type
= TREE_TYPE (exp
);
5139 local
.align
= align
;
5140 if (TREE_CODE (local
.type
) == ARRAY_TYPE
&& TYPE_DOMAIN (local
.type
))
5141 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5143 local
.min_index
= NULL_TREE
;
5145 local
.total_bytes
= 0;
5146 local
.byte_buffer_in_use
= outer
!= NULL
;
5147 local
.byte
= outer
? outer
->byte
: 0;
5148 local
.last_relative_index
= -1;
5150 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5152 /* As CE goes through the elements of the constant, FIELD goes through the
5153 structure fields if the constant is a structure. If the constant is a
5154 union, we override this by getting the field from the TREE_LIST element.
5155 But the constant could also be an array. Then FIELD is zero.
5157 There is always a maximum of one element in the chain LINK for unions
5158 (even if the initializer in a source program incorrectly contains
5161 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5162 local
.field
= TYPE_FIELDS (local
.type
);
5164 local
.field
= NULL_TREE
;
5167 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), cnt
, &ce
);
5168 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
5170 local
.val
= ce
->value
;
5171 local
.index
= NULL_TREE
;
5173 /* The element in a union constructor specifies the proper field
5175 if (RECORD_OR_UNION_TYPE_P (local
.type
) && ce
->index
!= NULL_TREE
)
5176 local
.field
= ce
->index
;
5178 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5179 local
.index
= ce
->index
;
5181 if (local
.field
&& flag_verbose_asm
)
5182 fprintf (asm_out_file
, "%s %s:\n",
5184 DECL_NAME (local
.field
)
5185 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5188 /* Eliminate the marker that makes a cast not be an lvalue. */
5189 if (local
.val
!= NULL_TREE
)
5190 STRIP_NOPS (local
.val
);
5192 /* Output the current element, using the appropriate helper ... */
5194 /* For an array slice not part of an outer bitfield. */
5196 && local
.index
!= NULL_TREE
5197 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5198 output_constructor_array_range (&local
);
5200 /* For a field that is neither a true bitfield nor part of an outer one,
5201 known to be at least byte aligned and multiple-of-bytes long. */
5203 && (local
.field
== NULL_TREE
5204 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5205 output_constructor_regular_field (&local
);
5207 /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
5208 supported for scalar fields, so we may need to convert first. */
5211 if (TREE_CODE (local
.val
) == REAL_CST
)
5213 = fold_unary (VIEW_CONVERT_EXPR
,
5214 build_nonstandard_integer_type
5215 (TYPE_PRECISION (TREE_TYPE (local
.val
)), 0),
5217 output_constructor_bitfield (&local
, outer
? outer
->bit_offset
: 0);
5221 /* If we are not at toplevel, save the pending data for our caller.
5222 Otherwise output the pending data and padding zeros as needed. */
5224 outer
->byte
= local
.byte
;
5227 if (local
.byte_buffer_in_use
)
5229 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5230 local
.total_bytes
++;
5233 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5235 assemble_zeros (local
.size
- local
.total_bytes
);
5236 local
.total_bytes
= local
.size
;
5240 return local
.total_bytes
;
5243 /* Mark DECL as weak. */
5246 mark_weak (tree decl
)
5248 if (DECL_WEAK (decl
))
5251 struct symtab_node
*n
= symtab_node::get (decl
);
5252 if (n
&& n
->refuse_visibility_changes
)
5253 error ("%+D declared weak after being used", decl
);
5254 DECL_WEAK (decl
) = 1;
5256 if (DECL_RTL_SET_P (decl
)
5257 && MEM_P (DECL_RTL (decl
))
5258 && XEXP (DECL_RTL (decl
), 0)
5259 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5260 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5263 /* Merge weak status between NEWDECL and OLDDECL. */
5266 merge_weak (tree newdecl
, tree olddecl
)
5268 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5270 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5273 /* We put the NEWDECL on the weak_decls list at some point
5274 and OLDDECL as well. Keep just OLDDECL on the list. */
5275 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5276 if (TREE_VALUE (*pwd
) == newdecl
)
5278 *pwd
= TREE_CHAIN (*pwd
);
5285 if (DECL_WEAK (newdecl
))
5289 /* NEWDECL is weak, but OLDDECL is not. */
5291 /* If we already output the OLDDECL, we're in trouble; we can't
5292 go back and make it weak. This should never happen in
5293 unit-at-a-time compilation. */
5294 gcc_assert (!TREE_ASM_WRITTEN (olddecl
));
5296 /* If we've already generated rtl referencing OLDDECL, we may
5297 have done so in a way that will not function properly with
5298 a weak symbol. Again in unit-at-a-time this should be
5300 gcc_assert (!TREE_USED (olddecl
)
5301 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)));
5303 if (TARGET_SUPPORTS_WEAK
)
5305 /* We put the NEWDECL on the weak_decls list at some point.
5306 Replace it with the OLDDECL. */
5307 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5308 if (TREE_VALUE (wd
) == newdecl
)
5310 TREE_VALUE (wd
) = olddecl
;
5313 /* We may not find the entry on the list. If NEWDECL is a
5314 weak alias, then we will have already called
5315 globalize_decl to remove the entry; in that case, we do
5316 not need to do anything. */
5319 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5320 mark_weak (olddecl
);
5323 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5324 weak. Just update NEWDECL to indicate that it's weak too. */
5325 mark_weak (newdecl
);
5328 /* Declare DECL to be a weak symbol. */
5331 declare_weak (tree decl
)
5333 gcc_assert (TREE_CODE (decl
) != FUNCTION_DECL
|| !TREE_ASM_WRITTEN (decl
));
5334 if (! TREE_PUBLIC (decl
))
5335 error ("weak declaration of %q+D must be public", decl
);
5336 else if (!TARGET_SUPPORTS_WEAK
)
5337 warning (0, "weak declaration of %q+D not supported", decl
);
5340 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5341 DECL_ATTRIBUTES (decl
)
5342 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5346 weak_finish_1 (tree decl
)
5348 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5349 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5352 if (! TREE_USED (decl
))
5355 #ifdef ASM_WEAKEN_DECL
5356 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5358 #ifdef ASM_WEAKEN_LABEL
5359 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5361 #ifdef ASM_OUTPUT_WEAK_ALIAS
5363 static bool warn_once
= 0;
5366 warning (0, "only weak aliases are supported in this configuration");
5376 /* Fiven an assembly name, find the decl it is associated with. */
5378 find_decl (tree target
)
5380 symtab_node
*node
= symtab_node::get_for_asmname (target
);
5386 /* This TREE_LIST contains weakref targets. */
5388 static GTY(()) tree weakref_targets
;
5390 /* Emit any pending weak declarations. */
5397 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5399 tree alias_decl
= TREE_PURPOSE (t
);
5400 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5402 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5403 /* Remove alias_decl from the weak list, but leave entries for
5404 the target alone. */
5406 #ifndef ASM_OUTPUT_WEAKREF
5407 else if (! TREE_SYMBOL_REFERENCED (target
))
5409 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5410 defined, otherwise we and weak_finish_1 would use
5411 different macros. */
5412 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5413 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5415 tree decl
= find_decl (target
);
5419 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5420 TREE_CODE (alias_decl
), target
,
5421 TREE_TYPE (alias_decl
));
5423 DECL_EXTERNAL (decl
) = 1;
5424 TREE_PUBLIC (decl
) = 1;
5425 DECL_ARTIFICIAL (decl
) = 1;
5426 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5427 TREE_USED (decl
) = 1;
5430 weak_finish_1 (decl
);
5439 /* Remove the alias and the target from the pending weak list
5440 so that we do not emit any .weak directives for the former,
5441 nor multiple .weak directives for the latter. */
5442 for (p
= &weak_decls
; (t2
= *p
) ; )
5444 if (TREE_VALUE (t2
) == alias_decl
5445 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5446 *p
= TREE_CHAIN (t2
);
5448 p
= &TREE_CHAIN (t2
);
5451 /* Remove other weakrefs to the same target, to speed things up. */
5452 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5454 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5455 *p
= TREE_CHAIN (t2
);
5457 p
= &TREE_CHAIN (t2
);
5462 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5464 tree decl
= TREE_VALUE (t
);
5466 weak_finish_1 (decl
);
5470 /* Emit the assembly bits to indicate that DECL is globally visible. */
5473 globalize_decl (tree decl
)
5476 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5477 if (DECL_WEAK (decl
))
5479 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5482 #ifdef ASM_WEAKEN_DECL
5483 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5485 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5488 /* Remove this function from the pending weak list so that
5489 we do not emit multiple .weak directives for it. */
5490 for (p
= &weak_decls
; (t
= *p
) ; )
5492 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5493 *p
= TREE_CHAIN (t
);
5495 p
= &TREE_CHAIN (t
);
5498 /* Remove weakrefs to the same target from the pending weakref
5499 list, for the same reason. */
5500 for (p
= &weakref_targets
; (t
= *p
) ; )
5502 if (DECL_ASSEMBLER_NAME (decl
)
5503 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5504 *p
= TREE_CHAIN (t
);
5506 p
= &TREE_CHAIN (t
);
5513 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5516 vec
<alias_pair
, va_gc
> *alias_pairs
;
5518 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5519 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5520 tree node is DECL to have the value of the tree node TARGET. */
5523 do_assemble_alias (tree decl
, tree target
)
5527 /* Emulated TLS had better not get this var. */
5528 gcc_assert (!(!targetm
.have_tls
5529 && TREE_CODE (decl
) == VAR_DECL
5530 && DECL_THREAD_LOCAL_P (decl
)));
5532 if (TREE_ASM_WRITTEN (decl
))
5535 id
= DECL_ASSEMBLER_NAME (decl
);
5536 ultimate_transparent_alias_target (&id
);
5538 /* We must force creation of DECL_RTL for debug info generation, even though
5539 we don't use it here. */
5540 make_decl_rtl (decl
);
5542 TREE_ASM_WRITTEN (decl
) = 1;
5543 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5544 TREE_ASM_WRITTEN (id
) = 1;
5546 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5548 ultimate_transparent_alias_target (&target
);
5550 if (!TREE_SYMBOL_REFERENCED (target
))
5551 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5553 #ifdef ASM_OUTPUT_WEAKREF
5554 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5555 IDENTIFIER_POINTER (id
),
5556 IDENTIFIER_POINTER (target
));
5558 if (!TARGET_SUPPORTS_WEAK
)
5560 error_at (DECL_SOURCE_LOCATION (decl
),
5561 "weakref is not supported in this configuration");
5568 #ifdef ASM_OUTPUT_DEF
5569 tree orig_decl
= decl
;
5571 if (TREE_CODE (decl
) == FUNCTION_DECL
5572 && cgraph_node::get (decl
)->instrumentation_clone
5573 && cgraph_node::get (decl
)->instrumented_version
)
5574 orig_decl
= cgraph_node::get (decl
)->instrumented_version
->decl
;
5576 /* Make name accessible from other files, if appropriate. */
5578 if (TREE_PUBLIC (decl
) || TREE_PUBLIC (orig_decl
))
5580 globalize_decl (decl
);
5581 maybe_assemble_visibility (decl
);
5583 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5585 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
5586 if (targetm
.has_ifunc_p ())
5587 ASM_OUTPUT_TYPE_DIRECTIVE
5588 (asm_out_file
, IDENTIFIER_POINTER (id
),
5592 error_at (DECL_SOURCE_LOCATION (decl
),
5593 "ifunc is not supported on this target");
5596 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5597 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5599 ASM_OUTPUT_DEF (asm_out_file
,
5600 IDENTIFIER_POINTER (id
),
5601 IDENTIFIER_POINTER (target
));
5603 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5608 name
= IDENTIFIER_POINTER (id
);
5609 # ifdef ASM_WEAKEN_DECL
5610 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5612 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5614 /* Remove this function from the pending weak list so that
5615 we do not emit multiple .weak directives for it. */
5616 for (p
= &weak_decls
; (t
= *p
) ; )
5617 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
))
5618 || id
== DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5619 *p
= TREE_CHAIN (t
);
5621 p
= &TREE_CHAIN (t
);
5623 /* Remove weakrefs to the same target from the pending weakref
5624 list, for the same reason. */
5625 for (p
= &weakref_targets
; (t
= *p
) ; )
5627 if (id
== ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5628 *p
= TREE_CHAIN (t
);
5630 p
= &TREE_CHAIN (t
);
5636 /* Emit an assembler directive to make the symbol for DECL an alias to
5637 the symbol for TARGET. */
5640 assemble_alias (tree decl
, tree target
)
5644 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5646 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5648 ultimate_transparent_alias_target (&target
);
5650 if (alias
== target
)
5651 error ("weakref %q+D ultimately targets itself", decl
);
5652 if (TREE_PUBLIC (decl
))
5653 error ("weakref %q+D must have static linkage", decl
);
5657 #if !defined (ASM_OUTPUT_DEF)
5658 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5659 error_at (DECL_SOURCE_LOCATION (decl
),
5660 "alias definitions not supported in this configuration");
5661 TREE_ASM_WRITTEN (decl
) = 1;
5664 if (!DECL_WEAK (decl
))
5666 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5667 error_at (DECL_SOURCE_LOCATION (decl
),
5668 "ifunc is not supported in this configuration");
5670 error_at (DECL_SOURCE_LOCATION (decl
),
5671 "only weak aliases are supported in this configuration");
5672 TREE_ASM_WRITTEN (decl
) = 1;
5678 TREE_USED (decl
) = 1;
5680 /* Allow aliases to aliases. */
5681 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5682 cgraph_node::get_create (decl
)->alias
= true;
5684 varpool_node::get_create (decl
)->alias
= true;
5686 /* If the target has already been emitted, we don't have to queue the
5687 alias. This saves a tad of memory. */
5688 if (symtab
->global_info_ready
)
5689 target_decl
= find_decl (target
);
5692 if ((target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5693 || symtab
->state
>= EXPANSION
)
5694 do_assemble_alias (decl
, target
);
5697 alias_pair p
= {decl
, target
};
5698 vec_safe_push (alias_pairs
, p
);
5702 /* Record and output a table of translations from original function
5703 to its transaction aware clone. Note that tm_pure functions are
5704 considered to be their own clone. */
5706 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
5707 htab_t tm_clone_hash
;
5710 record_tm_clone_pair (tree o
, tree n
)
5712 struct tree_map
**slot
, *h
;
5714 if (tm_clone_hash
== NULL
)
5715 tm_clone_hash
= htab_create_ggc (32, tree_map_hash
, tree_map_eq
, 0);
5717 h
= ggc_alloc
<tree_map
> ();
5718 h
->hash
= htab_hash_pointer (o
);
5722 slot
= (struct tree_map
**)
5723 htab_find_slot_with_hash (tm_clone_hash
, h
, h
->hash
, INSERT
);
5728 get_tm_clone_pair (tree o
)
5732 struct tree_map
*h
, in
;
5735 in
.hash
= htab_hash_pointer (o
);
5736 h
= (struct tree_map
*) htab_find_with_hash (tm_clone_hash
,
5744 typedef struct tm_alias_pair
5752 /* Helper function for finish_tm_clone_pairs. Dump a hash table entry
5753 into a VEC in INFO. */
5756 dump_tm_clone_to_vec (void **slot
, void *info
)
5758 struct tree_map
*map
= (struct tree_map
*) *slot
;
5759 vec
<tm_alias_pair
> *tm_alias_pairs
= (vec
<tm_alias_pair
> *) info
;
5760 tm_alias_pair p
= {DECL_UID (map
->base
.from
), map
->base
.from
, map
->to
};
5761 tm_alias_pairs
->safe_push (p
);
5765 /* Dump the actual pairs to the .tm_clone_table section. */
5768 dump_tm_clone_pairs (vec
<tm_alias_pair
> tm_alias_pairs
)
5772 bool switched
= false;
5774 FOR_EACH_VEC_ELT (tm_alias_pairs
, i
, p
)
5778 struct cgraph_node
*src_n
= cgraph_node::get (src
);
5779 struct cgraph_node
*dst_n
= cgraph_node::get (dst
);
5781 /* The function ipa_tm_create_version() marks the clone as needed if
5782 the original function was needed. But we also mark the clone as
5783 needed if we ever called the clone indirectly through
5784 TM_GETTMCLONE. If neither of these are true, we didn't generate
5785 a clone, and we didn't call it indirectly... no sense keeping it
5786 in the clone table. */
5787 if (!dst_n
|| !dst_n
->definition
)
5790 /* This covers the case where we have optimized the original
5791 function away, and only access the transactional clone. */
5792 if (!src_n
|| !src_n
->definition
)
5797 switch_to_section (targetm
.asm_out
.tm_clone_table_section ());
5798 assemble_align (POINTER_SIZE
);
5802 assemble_integer (XEXP (DECL_RTL (src
), 0),
5803 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
5804 assemble_integer (XEXP (DECL_RTL (dst
), 0),
5805 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
5809 /* Provide a default for the tm_clone_table section. */
5812 default_clone_table_section (void)
5814 return get_named_section (NULL
, ".tm_clone_table", 3);
5817 /* Helper comparison function for qsorting by the DECL_UID stored in
5818 alias_pair->emitted_diags. */
5821 tm_alias_pair_cmp (const void *x
, const void *y
)
5823 const tm_alias_pair
*p1
= (const tm_alias_pair
*) x
;
5824 const tm_alias_pair
*p2
= (const tm_alias_pair
*) y
;
5825 if (p1
->uid
< p2
->uid
)
5827 if (p1
->uid
> p2
->uid
)
5833 finish_tm_clone_pairs (void)
5835 vec
<tm_alias_pair
> tm_alias_pairs
= vNULL
;
5837 if (tm_clone_hash
== NULL
)
5840 /* We need a determenistic order for the .tm_clone_table, otherwise
5841 we will get bootstrap comparison failures, so dump the hash table
5842 to a vector, sort it, and dump the vector. */
5844 /* Dump the hashtable to a vector. */
5845 htab_traverse_noresize (tm_clone_hash
, dump_tm_clone_to_vec
,
5846 (void *) &tm_alias_pairs
);
5848 tm_alias_pairs
.qsort (tm_alias_pair_cmp
);
5851 dump_tm_clone_pairs (tm_alias_pairs
);
5853 htab_delete (tm_clone_hash
);
5854 tm_clone_hash
= NULL
;
5855 tm_alias_pairs
.release ();
5859 /* Emit an assembler directive to set symbol for DECL visibility to
5860 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5863 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5864 int vis ATTRIBUTE_UNUSED
)
5866 #ifdef HAVE_GAS_HIDDEN
5867 static const char * const visibility_types
[] = {
5868 NULL
, "protected", "hidden", "internal"
5871 const char *name
, *type
;
5873 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5874 type
= visibility_types
[vis
];
5876 fprintf (asm_out_file
, "\t.%s\t", type
);
5877 assemble_name (asm_out_file
, name
);
5878 fprintf (asm_out_file
, "\n");
5880 if (!DECL_ARTIFICIAL (decl
))
5881 warning (OPT_Wattributes
, "visibility attribute not supported "
5882 "in this configuration; ignored");
5886 /* A helper function to call assemble_visibility when needed for a decl. */
5889 maybe_assemble_visibility (tree decl
)
5891 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5893 if (TREE_CODE (decl
) == FUNCTION_DECL
5894 && cgraph_node::get (decl
)
5895 && cgraph_node::get (decl
)->instrumentation_clone
5896 && cgraph_node::get (decl
)->instrumented_version
)
5897 vis
= DECL_VISIBILITY (cgraph_node::get (decl
)->instrumented_version
->decl
);
5899 if (vis
!= VISIBILITY_DEFAULT
)
5901 targetm
.asm_out
.assemble_visibility (decl
, vis
);
5908 /* Returns 1 if the target configuration supports defining public symbols
5909 so that one of them will be chosen at link time instead of generating a
5910 multiply-defined symbol error, whether through the use of weak symbols or
5911 a target-specific mechanism for having duplicates discarded. */
5914 supports_one_only (void)
5916 if (SUPPORTS_ONE_ONLY
)
5918 return TARGET_SUPPORTS_WEAK
;
5921 /* Set up DECL as a public symbol that can be defined in multiple
5922 translation units without generating a linker error. */
5925 make_decl_one_only (tree decl
, tree comdat_group
)
5927 struct symtab_node
*symbol
;
5928 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5929 || TREE_CODE (decl
) == FUNCTION_DECL
);
5931 TREE_PUBLIC (decl
) = 1;
5933 if (TREE_CODE (decl
) == VAR_DECL
)
5934 symbol
= varpool_node::get_create (decl
);
5936 symbol
= cgraph_node::get_create (decl
);
5938 if (SUPPORTS_ONE_ONLY
)
5940 #ifdef MAKE_DECL_ONE_ONLY
5941 MAKE_DECL_ONE_ONLY (decl
);
5943 symbol
->set_comdat_group (comdat_group
);
5945 else if (TREE_CODE (decl
) == VAR_DECL
5946 && (DECL_INITIAL (decl
) == 0
5947 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
5948 DECL_COMMON (decl
) = 1;
5951 gcc_assert (TARGET_SUPPORTS_WEAK
);
5952 DECL_WEAK (decl
) = 1;
5957 init_varasm_once (void)
5959 section_htab
= hash_table
<section_hasher
>::create_ggc (31);
5960 object_block_htab
= hash_table
<object_block_hasher
>::create_ggc (31);
5961 const_desc_htab
= hash_table
<tree_descriptor_hasher
>::create_ggc (1009);
5963 shared_constant_pool
= create_constant_pool ();
5965 #ifdef TEXT_SECTION_ASM_OP
5966 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
5967 TEXT_SECTION_ASM_OP
);
5970 #ifdef DATA_SECTION_ASM_OP
5971 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5972 DATA_SECTION_ASM_OP
);
5975 #ifdef SDATA_SECTION_ASM_OP
5976 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5977 SDATA_SECTION_ASM_OP
);
5980 #ifdef READONLY_DATA_SECTION_ASM_OP
5981 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
5982 READONLY_DATA_SECTION_ASM_OP
);
5985 #ifdef CTORS_SECTION_ASM_OP
5986 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
5987 CTORS_SECTION_ASM_OP
);
5990 #ifdef DTORS_SECTION_ASM_OP
5991 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
5992 DTORS_SECTION_ASM_OP
);
5995 #ifdef BSS_SECTION_ASM_OP
5996 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5997 output_section_asm_op
,
5998 BSS_SECTION_ASM_OP
);
6001 #ifdef SBSS_SECTION_ASM_OP
6002 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6003 output_section_asm_op
,
6004 SBSS_SECTION_ASM_OP
);
6007 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6008 | SECTION_COMMON
, emit_tls_common
);
6009 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6010 | SECTION_COMMON
, emit_local
);
6011 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6012 | SECTION_COMMON
, emit_common
);
6014 #if defined ASM_OUTPUT_ALIGNED_BSS
6015 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
6019 targetm
.asm_out
.init_sections ();
6021 if (readonly_data_section
== NULL
)
6022 readonly_data_section
= text_section
;
6024 #ifdef ASM_OUTPUT_EXTERNAL
6025 pending_assemble_externals_set
= new hash_set
<tree
>;
6030 decl_default_tls_model (const_tree decl
)
6032 enum tls_model kind
;
6035 is_local
= targetm
.binds_local_p (decl
);
6039 kind
= TLS_MODEL_LOCAL_EXEC
;
6041 kind
= TLS_MODEL_INITIAL_EXEC
;
6044 /* Local dynamic is inefficient when we're not combining the
6045 parts of the address. */
6046 else if (optimize
&& is_local
)
6047 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6049 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6050 if (kind
< flag_tls_default
)
6051 kind
= flag_tls_default
;
6056 /* Select a set of attributes for section NAME based on the properties
6057 of DECL and whether or not RELOC indicates that DECL's initializer
6058 might contain runtime relocations.
6060 We make the section read-only and executable for a function decl,
6061 read-only for a const data decl, and writable for a non-const data decl. */
6064 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6068 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6069 flags
= SECTION_CODE
;
6072 enum section_category category
6073 = categorize_decl_for_section (decl
, reloc
);
6074 if (decl_readonly_section_1 (category
))
6076 else if (category
== SECCAT_DATA_REL_RO
6077 || category
== SECCAT_DATA_REL_RO_LOCAL
)
6078 flags
= SECTION_WRITE
| SECTION_RELRO
;
6080 flags
= SECTION_WRITE
;
6084 flags
= SECTION_WRITE
;
6085 if (strcmp (name
, ".data.rel.ro") == 0
6086 || strcmp (name
, ".data.rel.ro.local") == 0)
6087 flags
|= SECTION_RELRO
;
6090 if (decl
&& DECL_P (decl
) && DECL_COMDAT_GROUP (decl
))
6091 flags
|= SECTION_LINKONCE
;
6093 if (strcmp (name
, ".vtable_map_vars") == 0)
6094 flags
|= SECTION_LINKONCE
;
6096 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6097 flags
|= SECTION_TLS
| SECTION_WRITE
;
6099 if (strcmp (name
, ".bss") == 0
6100 || strncmp (name
, ".bss.", 5) == 0
6101 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6102 || strcmp (name
, ".persistent.bss") == 0
6103 || strcmp (name
, ".sbss") == 0
6104 || strncmp (name
, ".sbss.", 6) == 0
6105 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6106 flags
|= SECTION_BSS
;
6108 if (strcmp (name
, ".tdata") == 0
6109 || strncmp (name
, ".tdata.", 7) == 0
6110 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6111 flags
|= SECTION_TLS
;
6113 if (strcmp (name
, ".tbss") == 0
6114 || strncmp (name
, ".tbss.", 6) == 0
6115 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6116 flags
|= SECTION_TLS
| SECTION_BSS
;
6118 /* These three sections have special ELF types. They are neither
6119 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6120 want to print a section type (@progbits or @nobits). If someone
6121 is silly enough to emit code or TLS variables to one of these
6122 sections, then don't handle them specially. */
6123 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
6124 && (strcmp (name
, ".init_array") == 0
6125 || strcmp (name
, ".fini_array") == 0
6126 || strcmp (name
, ".preinit_array") == 0))
6127 flags
|= SECTION_NOTYPE
;
6132 /* Return true if the target supports some form of global BSS,
6133 either through bss_noswitch_section, or by selecting a BSS
6134 section in TARGET_ASM_SELECT_SECTION. */
6137 have_global_bss_p (void)
6139 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6142 /* Output assembly to switch to section NAME with attribute FLAGS.
6143 Four variants for common object file formats. */
6146 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6147 unsigned int flags ATTRIBUTE_UNUSED
,
6148 tree decl ATTRIBUTE_UNUSED
)
6150 /* Some object formats don't support named sections at all. The
6151 front-end should already have flagged this as an error. */
6155 #ifndef TLS_SECTION_ASM_FLAG
6156 #define TLS_SECTION_ASM_FLAG 'T'
6160 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6161 tree decl ATTRIBUTE_UNUSED
)
6163 char flagchars
[10], *f
= flagchars
;
6165 /* If we have already declared this section, we can use an
6166 abbreviated form to switch back to it -- unless this section is
6167 part of a COMDAT groups, in which case GAS requires the full
6168 declaration every time. */
6169 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6170 && (flags
& SECTION_DECLARED
))
6172 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6176 if (!(flags
& SECTION_DEBUG
))
6178 #if defined (HAVE_GAS_SECTION_EXCLUDE) && HAVE_GAS_SECTION_EXCLUDE == 1
6179 if (flags
& SECTION_EXCLUDE
)
6182 if (flags
& SECTION_WRITE
)
6184 if (flags
& SECTION_CODE
)
6186 if (flags
& SECTION_SMALL
)
6188 if (flags
& SECTION_MERGE
)
6190 if (flags
& SECTION_STRINGS
)
6192 if (flags
& SECTION_TLS
)
6193 *f
++ = TLS_SECTION_ASM_FLAG
;
6194 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6198 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6200 if (!(flags
& SECTION_NOTYPE
))
6205 if (flags
& SECTION_BSS
)
6211 /* On platforms that use "@" as the assembly comment character,
6213 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6215 fprintf (asm_out_file
, format
, type
);
6217 if (flags
& SECTION_ENTSIZE
)
6218 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6219 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6221 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6222 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6224 fprintf (asm_out_file
, ",%s,comdat",
6225 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6229 putc ('\n', asm_out_file
);
6233 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6234 tree decl ATTRIBUTE_UNUSED
)
6236 char flagchars
[8], *f
= flagchars
;
6238 if (flags
& SECTION_WRITE
)
6240 if (flags
& SECTION_CODE
)
6244 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6248 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6251 default_coff_asm_named_section (name
, flags
, decl
);
6253 if (flags
& SECTION_LINKONCE
)
6255 /* Functions may have been compiled at various levels of
6256 optimization so we can't use `same_size' here.
6257 Instead, have the linker pick one. */
6258 fprintf (asm_out_file
, "\t.linkonce %s\n",
6259 (flags
& SECTION_CODE
? "discard" : "same_size"));
6263 /* The lame default section selector. */
6266 default_select_section (tree decl
, int reloc
,
6267 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6271 if (decl_readonly_section (decl
, reloc
))
6272 return readonly_data_section
;
6274 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6276 if (! ((flag_pic
&& reloc
)
6277 || !TREE_READONLY (decl
)
6278 || TREE_SIDE_EFFECTS (decl
)
6279 || !TREE_CONSTANT (decl
)))
6280 return readonly_data_section
;
6282 else if (TREE_CODE (decl
) == STRING_CST
)
6283 return readonly_data_section
;
6284 else if (! (flag_pic
&& reloc
))
6285 return readonly_data_section
;
6287 return data_section
;
6290 enum section_category
6291 categorize_decl_for_section (const_tree decl
, int reloc
)
6293 enum section_category ret
;
6295 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6297 else if (TREE_CODE (decl
) == STRING_CST
)
6299 if ((flag_sanitize
& SANITIZE_ADDRESS
)
6300 && asan_protect_global (CONST_CAST_TREE (decl
)))
6301 /* or !flag_merge_constants */
6302 return SECCAT_RODATA
;
6304 return SECCAT_RODATA_MERGE_STR
;
6306 else if (TREE_CODE (decl
) == VAR_DECL
)
6308 if (bss_initializer_p (decl
))
6310 else if (! TREE_READONLY (decl
)
6311 || TREE_SIDE_EFFECTS (decl
)
6312 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6314 /* Here the reloc_rw_mask is not testing whether the section should
6315 be read-only or not, but whether the dynamic link will have to
6316 do something. If so, we wish to segregate the data in order to
6317 minimize cache misses inside the dynamic linker. */
6318 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6319 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6323 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6324 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6325 else if (reloc
|| flag_merge_constants
< 2
6326 || ((flag_sanitize
& SANITIZE_ADDRESS
)
6327 && asan_protect_global (CONST_CAST_TREE (decl
))))
6328 /* C and C++ don't allow different variables to share the same
6329 location. -fmerge-all-constants allows even that (at the
6330 expense of not conforming). */
6331 ret
= SECCAT_RODATA
;
6332 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6333 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6335 ret
= SECCAT_RODATA_MERGE_CONST
;
6337 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6339 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6340 || TREE_SIDE_EFFECTS (decl
)
6341 || ! TREE_CONSTANT (decl
))
6344 ret
= SECCAT_RODATA
;
6347 ret
= SECCAT_RODATA
;
6349 /* There are no read-only thread-local sections. */
6350 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6352 /* Note that this would be *just* SECCAT_BSS, except that there's
6353 no concept of a read-only thread-local-data section. */
6354 if (ret
== SECCAT_BSS
6355 || (flag_zero_initialized_in_bss
6356 && initializer_zerop (DECL_INITIAL (decl
))))
6362 /* If the target uses small data sections, select it. */
6363 else if (targetm
.in_small_data_p (decl
))
6365 if (ret
== SECCAT_BSS
)
6367 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6368 ret
= SECCAT_SRODATA
;
6377 decl_readonly_section_1 (enum section_category category
)
6382 case SECCAT_RODATA_MERGE_STR
:
6383 case SECCAT_RODATA_MERGE_STR_INIT
:
6384 case SECCAT_RODATA_MERGE_CONST
:
6385 case SECCAT_SRODATA
:
6393 decl_readonly_section (const_tree decl
, int reloc
)
6395 return decl_readonly_section_1 (categorize_decl_for_section (decl
, reloc
));
6398 /* Select a section based on the above categorization. */
6401 default_elf_select_section (tree decl
, int reloc
,
6402 unsigned HOST_WIDE_INT align
)
6405 switch (categorize_decl_for_section (decl
, reloc
))
6408 /* We're not supposed to be called on FUNCTION_DECLs. */
6411 return readonly_data_section
;
6412 case SECCAT_RODATA_MERGE_STR
:
6413 return mergeable_string_section (decl
, align
, 0);
6414 case SECCAT_RODATA_MERGE_STR_INIT
:
6415 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6416 case SECCAT_RODATA_MERGE_CONST
:
6417 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6418 case SECCAT_SRODATA
:
6422 return data_section
;
6423 case SECCAT_DATA_REL
:
6424 sname
= ".data.rel";
6426 case SECCAT_DATA_REL_LOCAL
:
6427 sname
= ".data.rel.local";
6429 case SECCAT_DATA_REL_RO
:
6430 sname
= ".data.rel.ro";
6432 case SECCAT_DATA_REL_RO_LOCAL
:
6433 sname
= ".data.rel.ro.local";
6456 return get_named_section (decl
, sname
, reloc
);
6459 /* Construct a unique section name based on the decl name and the
6460 categorization performed above. */
6463 default_unique_section (tree decl
, int reloc
)
6465 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6466 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6467 const char *prefix
, *name
, *linkonce
;
6471 switch (categorize_decl_for_section (decl
, reloc
))
6474 prefix
= one_only
? ".t" : ".text";
6477 case SECCAT_RODATA_MERGE_STR
:
6478 case SECCAT_RODATA_MERGE_STR_INIT
:
6479 case SECCAT_RODATA_MERGE_CONST
:
6480 prefix
= one_only
? ".r" : ".rodata";
6482 case SECCAT_SRODATA
:
6483 prefix
= one_only
? ".s2" : ".sdata2";
6486 prefix
= one_only
? ".d" : ".data";
6488 case SECCAT_DATA_REL
:
6489 prefix
= one_only
? ".d.rel" : ".data.rel";
6491 case SECCAT_DATA_REL_LOCAL
:
6492 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6494 case SECCAT_DATA_REL_RO
:
6495 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6497 case SECCAT_DATA_REL_RO_LOCAL
:
6498 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6501 prefix
= one_only
? ".s" : ".sdata";
6504 prefix
= one_only
? ".b" : ".bss";
6507 prefix
= one_only
? ".sb" : ".sbss";
6510 prefix
= one_only
? ".td" : ".tdata";
6513 prefix
= one_only
? ".tb" : ".tbss";
6519 id
= DECL_ASSEMBLER_NAME (decl
);
6520 ultimate_transparent_alias_target (&id
);
6521 name
= IDENTIFIER_POINTER (id
);
6522 name
= targetm
.strip_name_encoding (name
);
6524 /* If we're using one_only, then there needs to be a .gnu.linkonce
6525 prefix to the section name. */
6526 linkonce
= one_only
? ".gnu.linkonce" : "";
6528 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6530 set_decl_section_name (decl
, string
);
6533 /* Subroutine of compute_reloc_for_rtx for leaf rtxes. */
6536 compute_reloc_for_rtx_1 (const_rtx x
)
6538 switch (GET_CODE (x
))
6541 return SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6549 /* Like compute_reloc_for_constant, except for an RTX. The return value
6550 is a mask for which bit 1 indicates a global relocation, and bit 0
6551 indicates a local relocation. */
6554 compute_reloc_for_rtx (const_rtx x
)
6556 switch (GET_CODE (x
))
6560 return compute_reloc_for_rtx_1 (x
);
6565 subrtx_iterator::array_type array
;
6566 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
6567 reloc
|= compute_reloc_for_rtx_1 (*iter
);
6577 default_select_rtx_section (machine_mode mode ATTRIBUTE_UNUSED
,
6579 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6581 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6582 return data_section
;
6584 return readonly_data_section
;
6588 default_elf_select_rtx_section (machine_mode mode
, rtx x
,
6589 unsigned HOST_WIDE_INT align
)
6591 int reloc
= compute_reloc_for_rtx (x
);
6593 /* ??? Handle small data here somehow. */
6595 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6598 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6600 return get_named_section (NULL
, ".data.rel.ro", 3);
6603 return mergeable_constant_section (mode
, align
, 0);
6606 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6609 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6614 /* Careful not to prod global register variables. */
6617 symbol
= XEXP (rtl
, 0);
6618 if (GET_CODE (symbol
) != SYMBOL_REF
)
6621 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6622 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6623 flags
|= SYMBOL_FLAG_FUNCTION
;
6624 if (targetm
.binds_local_p (decl
))
6625 flags
|= SYMBOL_FLAG_LOCAL
;
6626 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6627 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6628 else if (targetm
.in_small_data_p (decl
))
6629 flags
|= SYMBOL_FLAG_SMALL
;
6630 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6631 being PUBLIC, the thing *must* be defined in this translation unit.
6632 Prevent this buglet from being propagated into rtl code as well. */
6633 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6634 flags
|= SYMBOL_FLAG_EXTERNAL
;
6636 SYMBOL_REF_FLAGS (symbol
) = flags
;
6639 /* By default, we do nothing for encode_section_info, so we need not
6640 do anything but discard the '*' marker. */
6643 default_strip_name_encoding (const char *str
)
6645 return str
+ (*str
== '*');
6648 #ifdef ASM_OUTPUT_DEF
6649 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6650 anchor relative to ".", the current section position. */
6653 default_asm_output_anchor (rtx symbol
)
6657 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6658 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6659 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6663 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6666 default_use_anchors_for_symbol_p (const_rtx symbol
)
6671 /* Don't use anchors for mergeable sections. The linker might move
6672 the objects around. */
6673 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6674 if (sect
->common
.flags
& SECTION_MERGE
)
6677 /* Don't use anchors for small data sections. The small data register
6678 acts as an anchor for such sections. */
6679 if (sect
->common
.flags
& SECTION_SMALL
)
6682 decl
= SYMBOL_REF_DECL (symbol
);
6683 if (decl
&& DECL_P (decl
))
6685 /* Don't use section anchors for decls that might be defined or
6686 usurped by other modules. */
6687 if (TREE_PUBLIC (decl
) && !decl_binds_to_current_def_p (decl
))
6690 /* Don't use section anchors for decls that will be placed in a
6691 small data section. */
6692 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6693 one above. The problem is that we only use SECTION_SMALL for
6694 sections that should be marked as small in the section directive. */
6695 if (targetm
.in_small_data_p (decl
))
6701 /* Return true when RESOLUTION indicate that symbol will be bound to the
6702 definition provided by current .o file. */
6705 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
6707 return (resolution
== LDPR_PREVAILING_DEF
6708 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6709 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
6712 /* Return true when RESOLUTION indicate that symbol will be bound locally
6713 within current executable or DSO. */
6716 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
6718 return (resolution
== LDPR_PREVAILING_DEF
6719 || resolution
== LDPR_PREVAILING_DEF_IRONLY
6720 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6721 || resolution
== LDPR_PREEMPTED_REG
6722 || resolution
== LDPR_PREEMPTED_IR
6723 || resolution
== LDPR_RESOLVED_IR
6724 || resolution
== LDPR_RESOLVED_EXEC
);
6727 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6728 wrt cross-module name binding. */
6731 default_binds_local_p (const_tree exp
)
6733 return default_binds_local_p_1 (exp
, flag_shlib
);
6737 default_binds_local_p_1 (const_tree exp
, int shlib
)
6740 bool resolved_locally
= false;
6741 bool resolved_to_local_def
= false;
6743 /* With resolution file in hands, take look into resolutions.
6744 We can't just return true for resolved_locally symbols,
6745 because dynamic linking might overwrite symbols
6746 in shared libraries. */
6747 if (TREE_CODE (exp
) == VAR_DECL
&& TREE_PUBLIC (exp
)
6748 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
6750 varpool_node
*vnode
= varpool_node::get (exp
);
6751 if (vnode
&& (resolution_local_p (vnode
->resolution
) || vnode
->in_other_partition
))
6752 resolved_locally
= true;
6754 && resolution_to_local_definition_p (vnode
->resolution
))
6755 resolved_to_local_def
= true;
6757 else if (TREE_CODE (exp
) == FUNCTION_DECL
&& TREE_PUBLIC (exp
))
6759 struct cgraph_node
*node
= cgraph_node::get (exp
);
6761 && (resolution_local_p (node
->resolution
) || node
->in_other_partition
))
6762 resolved_locally
= true;
6764 && resolution_to_local_definition_p (node
->resolution
))
6765 resolved_to_local_def
= true;
6768 /* A non-decl is an entry in the constant pool. */
6771 /* Weakrefs may not bind locally, even though the weakref itself is always
6772 static and therefore local. Similarly, the resolver for ifunc functions
6773 might resolve to a non-local function.
6774 FIXME: We can resolve the weakref case more curefuly by looking at the
6776 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
))
6777 || (TREE_CODE (exp
) == FUNCTION_DECL
6778 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (exp
))))
6780 /* Static variables are always local. */
6781 else if (! TREE_PUBLIC (exp
))
6783 /* A variable is local if the user has said explicitly that it will
6785 else if ((DECL_VISIBILITY_SPECIFIED (exp
)
6786 || resolved_to_local_def
)
6787 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6789 /* Variables defined outside this object might not be local. */
6790 else if (DECL_EXTERNAL (exp
) && !resolved_locally
)
6792 /* If defined in this object and visibility is not default, must be
6794 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6796 /* Default visibility weak data can be overridden by a strong symbol
6797 in another module and so are not local. */
6798 else if (DECL_WEAK (exp
)
6799 && !resolved_locally
)
6801 /* If PIC, then assume that any global name can be overridden by
6802 symbols resolved from other modules. */
6805 /* Uninitialized COMMON variable may be unified with symbols
6806 resolved from other modules. */
6807 else if (DECL_COMMON (exp
)
6808 && !resolved_locally
6809 && (DECL_INITIAL (exp
) == NULL
6810 || (!in_lto_p
&& DECL_INITIAL (exp
) == error_mark_node
)))
6812 /* Otherwise we're left with initialized (or non-common) global data
6813 which is of necessity defined locally. */
6820 /* Return true when references to DECL must bind to current definition in
6823 The condition is usually equivalent to whether the function binds to the
6824 current module (shared library or executable), that is to binds_local_p.
6825 We use this fact to avoid need for another target hook and implement
6826 the logic using binds_local_p and just special cases where
6827 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
6828 the weak definitions (that can be overwritten at linktime by other
6829 definition from different object file) and when resolution info is available
6830 we simply use the knowledge passed to us by linker plugin. */
6832 decl_binds_to_current_def_p (const_tree decl
)
6834 gcc_assert (DECL_P (decl
));
6835 if (!targetm
.binds_local_p (decl
))
6837 if (!TREE_PUBLIC (decl
))
6839 /* When resolution is available, just use it. */
6840 if (TREE_CODE (decl
) == VAR_DECL
6841 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
6843 varpool_node
*vnode
= varpool_node::get (decl
);
6845 && vnode
->resolution
!= LDPR_UNKNOWN
)
6846 return resolution_to_local_definition_p (vnode
->resolution
);
6848 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
6850 struct cgraph_node
*node
= cgraph_node::get (decl
);
6852 && node
->resolution
!= LDPR_UNKNOWN
)
6853 return resolution_to_local_definition_p (node
->resolution
);
6855 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
6856 binds locally but still can be overwritten), DECL_COMMON (can be merged
6857 with a non-common definition somewhere in the same module) or
6859 This rely on fact that binds_local_p behave as decl_replaceable_p
6860 for all other declaration types. */
6861 if (DECL_WEAK (decl
))
6863 if (DECL_COMMON (decl
)
6864 && (DECL_INITIAL (decl
) == NULL
6865 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
6867 if (DECL_EXTERNAL (decl
))
6872 /* A replaceable function or variable is one which may be replaced
6873 at link-time with an entirely different definition, provided that the
6874 replacement has the same type. For example, functions declared
6875 with __attribute__((weak)) on most systems are replaceable.
6877 COMDAT functions are not replaceable, since all definitions of the
6878 function must be equivalent. It is important that COMDAT functions
6879 not be treated as replaceable so that use of C++ template
6880 instantiations is not penalized. */
6883 decl_replaceable_p (tree decl
)
6885 gcc_assert (DECL_P (decl
));
6886 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
6888 if (!flag_semantic_interposition
6889 && !DECL_WEAK (decl
))
6891 return !decl_binds_to_current_def_p (decl
);
6894 /* Default function to output code that will globalize a label. A
6895 target must define GLOBAL_ASM_OP or provide its own function to
6896 globalize a label. */
6897 #ifdef GLOBAL_ASM_OP
6899 default_globalize_label (FILE * stream
, const char *name
)
6901 fputs (GLOBAL_ASM_OP
, stream
);
6902 assemble_name (stream
, name
);
6903 putc ('\n', stream
);
6905 #endif /* GLOBAL_ASM_OP */
6907 /* Default function to output code that will globalize a declaration. */
6909 default_globalize_decl_name (FILE * stream
, tree decl
)
6911 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6912 targetm
.asm_out
.globalize_label (stream
, name
);
6915 /* Default function to output a label for unwind information. The
6916 default is to do nothing. A target that needs nonlocal labels for
6917 unwind information must provide its own function to do this. */
6919 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6920 tree decl ATTRIBUTE_UNUSED
,
6921 int for_eh ATTRIBUTE_UNUSED
,
6922 int empty ATTRIBUTE_UNUSED
)
6926 /* Default function to output a label to divide up the exception table.
6927 The default is to do nothing. A target that needs/wants to divide
6928 up the table must provide it's own function to do this. */
6930 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6934 /* This is how to output an internal numbered label where PREFIX is
6935 the class of label and LABELNO is the number within the class. */
6938 default_generate_internal_label (char *buf
, const char *prefix
,
6939 unsigned long labelno
)
6941 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6944 /* This is how to output an internal numbered label where PREFIX is
6945 the class of label and LABELNO is the number within the class. */
6948 default_internal_label (FILE *stream
, const char *prefix
,
6949 unsigned long labelno
)
6951 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6952 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6953 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6957 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6960 default_asm_declare_constant_name (FILE *file
, const char *name
,
6961 const_tree exp ATTRIBUTE_UNUSED
,
6962 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
6964 assemble_label (file
, name
);
6967 /* This is the default behavior at the beginning of a file. It's
6968 controlled by two other target-hook toggles. */
6970 default_file_start (void)
6972 if (targetm
.asm_file_start_app_off
6973 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6974 fputs (ASM_APP_OFF
, asm_out_file
);
6976 if (targetm
.asm_file_start_file_directive
)
6977 output_file_directive (asm_out_file
, main_input_filename
);
6980 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6981 which emits a special section directive used to indicate whether or
6982 not this object file needs an executable stack. This is primarily
6983 a GNU extension to ELF but could be used on other targets. */
6985 int trampolines_created
;
6988 file_end_indicate_exec_stack (void)
6990 unsigned int flags
= SECTION_DEBUG
;
6991 if (trampolines_created
)
6992 flags
|= SECTION_CODE
;
6994 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6997 /* Emit a special section directive to indicate that this object file
6998 was compiled with -fsplit-stack. This is used to let the linker
6999 detect calls between split-stack code and non-split-stack code, so
7000 that it can modify the split-stack code to allocate a sufficiently
7001 large stack. We emit another special section if there are any
7002 functions in this file which have the no_split_stack attribute, to
7003 prevent the linker from warning about being unable to convert the
7004 functions if they call non-split-stack code. */
7007 file_end_indicate_split_stack (void)
7009 if (flag_split_stack
)
7011 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
7013 if (saw_no_split_stack
)
7014 switch_to_section (get_section (".note.GNU-no-split-stack",
7015 SECTION_DEBUG
, NULL
));
7019 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
7020 a get_unnamed_section callback. */
7023 output_section_asm_op (const void *directive
)
7025 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
7028 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
7029 the current section is NEW_SECTION. */
7032 switch_to_section (section
*new_section
)
7034 if (in_section
== new_section
)
7037 if (new_section
->common
.flags
& SECTION_FORGET
)
7040 in_section
= new_section
;
7042 switch (SECTION_STYLE (new_section
))
7045 targetm
.asm_out
.named_section (new_section
->named
.name
,
7046 new_section
->named
.common
.flags
,
7047 new_section
->named
.decl
);
7050 case SECTION_UNNAMED
:
7051 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
7054 case SECTION_NOSWITCH
:
7059 new_section
->common
.flags
|= SECTION_DECLARED
;
7062 /* If block symbol SYMBOL has not yet been assigned an offset, place
7063 it at the end of its block. */
7066 place_block_symbol (rtx symbol
)
7068 unsigned HOST_WIDE_INT size
, mask
, offset
;
7069 struct constant_descriptor_rtx
*desc
;
7070 unsigned int alignment
;
7071 struct object_block
*block
;
7074 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
7075 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
7078 /* Work out the symbol's size and alignment. */
7079 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7081 desc
= SYMBOL_REF_CONSTANT (symbol
);
7082 alignment
= desc
->align
;
7083 size
= GET_MODE_SIZE (desc
->mode
);
7085 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7087 decl
= SYMBOL_REF_DECL (symbol
);
7088 alignment
= DECL_ALIGN (decl
);
7089 size
= get_constant_size (DECL_INITIAL (decl
));
7090 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7091 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7092 && asan_protect_global (DECL_INITIAL (decl
)))
7093 size
+= asan_red_zone_size (size
);
7097 struct symtab_node
*snode
;
7098 decl
= SYMBOL_REF_DECL (symbol
);
7100 snode
= symtab_node::get (decl
);
7103 rtx target
= DECL_RTL (snode
->ultimate_alias_target ()->decl
);
7105 place_block_symbol (target
);
7106 SYMBOL_REF_BLOCK_OFFSET (symbol
) = SYMBOL_REF_BLOCK_OFFSET (target
);
7109 alignment
= get_variable_align (decl
);
7110 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7111 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7112 && asan_protect_global (decl
))
7114 size
+= asan_red_zone_size (size
);
7115 alignment
= MAX (alignment
,
7116 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
7120 /* Calculate the object's offset from the start of the block. */
7121 block
= SYMBOL_REF_BLOCK (symbol
);
7122 mask
= alignment
/ BITS_PER_UNIT
- 1;
7123 offset
= (block
->size
+ mask
) & ~mask
;
7124 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
7126 /* Record the block's new alignment and size. */
7127 block
->alignment
= MAX (block
->alignment
, alignment
);
7128 block
->size
= offset
+ size
;
7130 vec_safe_push (block
->objects
, symbol
);
7133 /* Return the anchor that should be used to address byte offset OFFSET
7134 from the first object in BLOCK. MODEL is the TLS model used
7138 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7139 enum tls_model model
)
7142 unsigned int begin
, middle
, end
;
7143 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7146 /* Work out the anchor's offset. Use an offset of 0 for the first
7147 anchor so that we don't pessimize the case where we take the address
7148 of a variable at the beginning of the block. This is particularly
7149 useful when a block has only one variable assigned to it.
7151 We try to place anchors RANGE bytes apart, so there can then be
7152 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7153 a ptr_mode offset. With some target settings, the lowest such
7154 anchor might be out of range for the lowest ptr_mode offset;
7155 likewise the highest anchor for the highest offset. Use anchors
7156 at the extreme ends of the ptr_mode range in such cases.
7158 All arithmetic uses unsigned integers in order to avoid
7160 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7161 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7162 range
= max_offset
- min_offset
+ 1;
7167 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
7170 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7171 delta
-= delta
% range
;
7174 offset
= (HOST_WIDE_INT
) (-delta
);
7178 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7179 delta
-= delta
% range
;
7180 if (delta
> bias
- 1)
7182 offset
= (HOST_WIDE_INT
) delta
;
7186 /* Do a binary search to see if there's already an anchor we can use.
7187 Set BEGIN to the new anchor's index if not. */
7189 end
= vec_safe_length (block
->anchors
);
7190 while (begin
!= end
)
7192 middle
= (end
+ begin
) / 2;
7193 anchor
= (*block
->anchors
)[middle
];
7194 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7196 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7198 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7200 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7206 /* Create a new anchor with a unique label. */
7207 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7208 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7209 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7210 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7212 /* Insert it at index BEGIN. */
7213 vec_safe_insert (block
->anchors
, begin
, anchor
);
7217 /* Output the objects in BLOCK. */
7220 output_object_block (struct object_block
*block
)
7222 struct constant_descriptor_rtx
*desc
;
7224 HOST_WIDE_INT offset
;
7228 if (!block
->objects
)
7231 /* Switch to the section and make sure that the first byte is
7232 suitably aligned. */
7233 switch_to_section (block
->sect
);
7234 assemble_align (block
->alignment
);
7236 /* Define the values of all anchors relative to the current section
7238 FOR_EACH_VEC_SAFE_ELT (block
->anchors
, i
, symbol
)
7239 targetm
.asm_out
.output_anchor (symbol
);
7241 /* Output the objects themselves. */
7243 FOR_EACH_VEC_ELT (*block
->objects
, i
, symbol
)
7245 /* Move to the object's offset, padding with zeros if necessary. */
7246 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7247 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7248 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7250 desc
= SYMBOL_REF_CONSTANT (symbol
);
7251 output_constant_pool_1 (desc
, 1);
7252 offset
+= GET_MODE_SIZE (desc
->mode
);
7254 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7257 decl
= SYMBOL_REF_DECL (symbol
);
7258 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
7260 size
= get_constant_size (DECL_INITIAL (decl
));
7262 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7263 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7264 && asan_protect_global (DECL_INITIAL (decl
)))
7266 size
= asan_red_zone_size (size
);
7267 assemble_zeros (size
);
7274 decl
= SYMBOL_REF_DECL (symbol
);
7275 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
7276 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7278 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7279 && asan_protect_global (decl
))
7281 size
= asan_red_zone_size (size
);
7282 assemble_zeros (size
);
7289 /* A htab_traverse callback used to call output_object_block for
7290 each member of object_block_htab. */
7293 output_object_block_htab (object_block
**slot
, void *)
7295 output_object_block (*slot
);
7299 /* Output the definitions of all object_blocks. */
7302 output_object_blocks (void)
7304 object_block_htab
->traverse
<void *, output_object_block_htab
> (NULL
);
7307 /* This function provides a possible implementation of the
7308 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7309 by -frecord-gcc-switches it creates a new mergeable, string section in the
7310 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7311 contains the switches in ASCII format.
7313 FIXME: This code does not correctly handle double quote characters
7314 that appear inside strings, (it strips them rather than preserving them).
7315 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7316 characters - instead it treats them as sub-string separators. Since
7317 we want to emit NUL strings terminators into the object file we have to use
7321 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7325 case SWITCH_TYPE_PASSED
:
7326 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
7327 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7330 case SWITCH_TYPE_DESCRIPTIVE
:
7333 /* Distinguish between invocations where name is NULL. */
7334 static bool started
= false;
7340 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7344 | (SECTION_ENTSIZE
& 1),
7346 switch_to_section (sec
);
7355 /* The return value is currently ignored by the caller, but must be 0.
7356 For -fverbose-asm the return value would be the number of characters
7357 emitted into the assembler file. */
7361 /* Emit text to declare externally defined symbols. It is needed to
7362 properly support non-default visibility. */
7364 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7366 const char *name ATTRIBUTE_UNUSED
)
7368 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7369 set in order to avoid putting out names that are never really
7371 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7372 && targetm
.binds_local_p (decl
))
7373 maybe_assemble_visibility (decl
);
7376 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7379 default_asm_output_source_filename (FILE *file
, const char *name
)
7381 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7382 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
7384 fprintf (file
, "\t.file\t");
7385 output_quoted_string (file
, name
);
7390 /* Output a file name in the form wanted by System V. */
7393 output_file_directive (FILE *asm_file
, const char *input_name
)
7398 if (input_name
== NULL
)
7399 input_name
= "<stdin>";
7401 input_name
= remap_debug_filename (input_name
);
7403 len
= strlen (input_name
);
7404 na
= input_name
+ len
;
7406 /* NA gets INPUT_NAME sans directory names. */
7407 while (na
> input_name
)
7409 if (IS_DIR_SEPARATOR (na
[-1]))
7414 targetm
.asm_out
.output_source_filename (asm_file
, na
);
7417 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7420 make_debug_expr_from_rtl (const_rtx exp
)
7422 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7423 machine_mode mode
= GET_MODE (exp
);
7426 DECL_ARTIFICIAL (ddecl
) = 1;
7427 if (REG_P (exp
) && REG_EXPR (exp
))
7428 type
= TREE_TYPE (REG_EXPR (exp
));
7429 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7430 type
= TREE_TYPE (MEM_EXPR (exp
));
7433 if (type
&& TYPE_MODE (type
) == mode
)
7434 TREE_TYPE (ddecl
) = type
;
7436 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7437 DECL_MODE (ddecl
) = mode
;
7438 dval
= gen_rtx_DEBUG_EXPR (mode
);
7439 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7440 SET_DECL_RTL (ddecl
, dval
);
7444 #ifdef ELF_ASCII_ESCAPES
7445 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
7448 default_elf_asm_output_limited_string (FILE *f
, const char *s
)
7453 fputs (STRING_ASM_OP
, f
);
7458 escape
= ELF_ASCII_ESCAPES
[c
];
7465 /* TODO: Print in hex with fast function, important for -flto. */
7466 fprintf (f
, "\\%03o", c
);
7479 /* Default ASM_OUTPUT_ASCII for ELF targets. */
7482 default_elf_asm_output_ascii (FILE *f
, const char *s
, unsigned int len
)
7484 const char *limit
= s
+ len
;
7485 const char *last_null
= NULL
;
7486 unsigned bytes_in_chunk
= 0;
7490 for (; s
< limit
; s
++)
7494 if (bytes_in_chunk
>= 60)
7503 for (p
= s
; p
< limit
&& *p
!= '\0'; p
++)
7510 if (p
< limit
&& (p
- s
) <= (long) ELF_STRING_LIMIT
)
7512 if (bytes_in_chunk
> 0)
7519 default_elf_asm_output_limited_string (f
, s
);
7524 if (bytes_in_chunk
== 0)
7525 fputs (ASCII_DATA_ASM_OP
"\"", f
);
7528 escape
= ELF_ASCII_ESCAPES
[c
];
7536 /* TODO: Print in hex with fast function, important for -flto. */
7537 fprintf (f
, "\\%03o", c
);
7538 bytes_in_chunk
+= 4;
7543 bytes_in_chunk
+= 2;
7550 if (bytes_in_chunk
> 0)
7558 static GTY(()) section
*elf_init_array_section
;
7559 static GTY(()) section
*elf_fini_array_section
;
7562 get_elf_initfini_array_priority_section (int priority
,
7566 if (priority
!= DEFAULT_INIT_PRIORITY
)
7569 sprintf (buf
, "%s.%.5u",
7570 constructor_p
? ".init_array" : ".fini_array",
7572 sec
= get_section (buf
, SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7578 if (elf_init_array_section
== NULL
)
7579 elf_init_array_section
7580 = get_section (".init_array",
7581 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7582 sec
= elf_init_array_section
;
7586 if (elf_fini_array_section
== NULL
)
7587 elf_fini_array_section
7588 = get_section (".fini_array",
7589 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7590 sec
= elf_fini_array_section
;
7596 /* Use .init_array section for constructors. */
7599 default_elf_init_array_asm_out_constructor (rtx symbol
, int priority
)
7601 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7603 assemble_addr_to_section (symbol
, sec
);
7606 /* Use .fini_array section for destructors. */
7609 default_elf_fini_array_asm_out_destructor (rtx symbol
, int priority
)
7611 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7613 assemble_addr_to_section (symbol
, sec
);
7616 /* Default TARGET_ASM_OUTPUT_IDENT hook.
7618 This is a bit of a cheat. The real default is a no-op, but this
7619 hook is the default for all targets with a .ident directive. */
7622 default_asm_output_ident_directive (const char *ident_str
)
7624 const char *ident_asm_op
= "\t.ident\t";
7626 /* If we are still in the front end, do not write out the string
7627 to asm_out_file. Instead, add a fake top-level asm statement.
7628 This allows the front ends to use this hook without actually
7629 writing to asm_out_file, to handle #ident or Pragma Ident. */
7630 if (symtab
->state
== PARSING
)
7632 char *buf
= ACONCAT ((ident_asm_op
, "\"", ident_str
, "\"\n", NULL
));
7633 symtab
->finalize_toplevel_asm (build_string (strlen (buf
), buf
));
7636 fprintf (asm_out_file
, "%s\"%s\"\n", ident_asm_op
, ident_str
);
7639 #include "gt-varasm.h"