1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 /* This file handles generation of all the assembler code
22 *except* the instructions of a function.
23 This includes declarations of variables and their initial values.
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
30 #include "coretypes.h"
36 #include "double-int.h"
43 #include "fold-const.h"
44 #include "stor-layout.h"
45 #include "stringpool.h"
48 #include "hard-reg-set.h"
51 #include "statistics.h"
53 #include "fixed-value.h"
54 #include "insn-config.h"
64 #include "diagnostic-core.h"
66 #include "langhooks.h"
70 #include "common/common-target.h"
71 #include "targhooks.h"
73 #include "dominance.h"
75 #include "basic-block.h"
78 #include "plugin-api.h"
83 #include "tree-chkp.h"
85 #ifdef XCOFF_DEBUGGING_INFO
86 #include "xcoffout.h" /* Needed for external data
87 declarations for e.g. AIX 4.x. */
90 /* The (assembler) name of the first globally-visible object output. */
91 extern GTY(()) const char *first_global_object_name
;
92 extern GTY(()) const char *weak_global_object_name
;
94 const char *first_global_object_name
;
95 const char *weak_global_object_name
;
98 struct constant_descriptor_rtx
;
99 struct rtx_constant_pool
;
101 #define n_deferred_constants (crtl->varasm.deferred_constants)
103 /* Number for making the label on the next
104 constant that is stored in memory. */
106 static GTY(()) int const_labelno
;
108 /* Carry information from ASM_DECLARE_OBJECT_NAME
109 to ASM_FINISH_DECLARE_OBJECT. */
111 int size_directive_output
;
113 /* The last decl for which assemble_variable was called,
114 if it did ASM_DECLARE_OBJECT_NAME.
115 If the last call to assemble_variable didn't do that,
118 tree last_assemble_variable_decl
;
120 /* The following global variable indicates if the first basic block
121 in a function belongs to the cold partition or not. */
123 bool first_function_block_is_cold
;
125 /* Whether we saw any functions with no_split_stack. */
127 static bool saw_no_split_stack
;
129 static const char *strip_reg_name (const char *);
130 static int contains_pointers_p (tree
);
131 #ifdef ASM_OUTPUT_EXTERNAL
132 static bool incorporeal_function_p (tree
);
134 static void decode_addr_const (tree
, struct addr_const
*);
135 static hashval_t
const_hash_1 (const tree
);
136 static int compare_constant (const tree
, const tree
);
137 static void output_constant_def_contents (rtx
);
138 static void output_addressed_constants (tree
);
139 static unsigned HOST_WIDE_INT
output_constant (tree
, unsigned HOST_WIDE_INT
,
141 static void globalize_decl (tree
);
142 static bool decl_readonly_section_1 (enum section_category
);
143 #ifdef BSS_SECTION_ASM_OP
144 #ifdef ASM_OUTPUT_ALIGNED_BSS
145 static void asm_output_aligned_bss (FILE *, tree
, const char *,
146 unsigned HOST_WIDE_INT
, int)
149 #endif /* BSS_SECTION_ASM_OP */
150 static void mark_weak (tree
);
151 static void output_constant_pool (const char *, tree
);
153 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
154 section
*text_section
;
155 section
*data_section
;
156 section
*readonly_data_section
;
157 section
*sdata_section
;
158 section
*ctors_section
;
159 section
*dtors_section
;
160 section
*bss_section
;
161 section
*sbss_section
;
163 /* Various forms of common section. All are guaranteed to be nonnull. */
164 section
*tls_comm_section
;
165 section
*comm_section
;
166 section
*lcomm_section
;
168 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
170 section
*bss_noswitch_section
;
172 /* The section that holds the main exception table, when known. The section
173 is set either by the target's init_sections hook or by the first call to
174 switch_to_exception_section. */
175 section
*exception_section
;
177 /* The section that holds the DWARF2 frame unwind information, when known.
178 The section is set either by the target's init_sections hook or by the
179 first call to switch_to_eh_frame_section. */
180 section
*eh_frame_section
;
182 /* asm_out_file's current section. This is NULL if no section has yet
183 been selected or if we lose track of what the current section is. */
186 /* True if code for the current function is currently being directed
187 at the cold section. */
188 bool in_cold_section_p
;
190 /* The following global holds the "function name" for the code in the
191 cold section of a function, if hot/cold function splitting is enabled
192 and there was actually code that went into the cold section. A
193 pseudo function name is needed for the cold section of code for some
194 debugging tools that perform symbolization. */
195 tree cold_function_name
= NULL_TREE
;
197 /* A linked list of all the unnamed sections. */
198 static GTY(()) section
*unnamed_sections
;
200 /* Return a nonzero value if DECL has a section attribute. */
201 #define IN_NAMED_SECTION(DECL) \
202 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
203 && DECL_SECTION_NAME (DECL) != NULL)
205 struct section_hasher
: ggc_hasher
<section
*>
207 typedef const char *compare_type
;
209 static hashval_t
hash (section
*);
210 static bool equal (section
*, const char *);
213 /* Hash table of named sections. */
214 static GTY(()) hash_table
<section_hasher
> *section_htab
;
216 struct object_block_hasher
: ggc_hasher
<object_block
*>
218 typedef const section
*compare_type
;
220 static hashval_t
hash (object_block
*);
221 static bool equal (object_block
*, const section
*);
224 /* A table of object_blocks, indexed by section. */
225 static GTY(()) hash_table
<object_block_hasher
> *object_block_htab
;
227 /* The next number to use for internal anchor labels. */
228 static GTY(()) int anchor_labelno
;
230 /* A pool of constants that can be shared between functions. */
231 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
233 /* Helper routines for maintaining section_htab. */
236 section_hasher::equal (section
*old
, const char *new_name
)
238 return strcmp (old
->named
.name
, new_name
) == 0;
242 section_hasher::hash (section
*old
)
244 return htab_hash_string (old
->named
.name
);
247 /* Return a hash value for section SECT. */
250 hash_section (section
*sect
)
252 if (sect
->common
.flags
& SECTION_NAMED
)
253 return htab_hash_string (sect
->named
.name
);
254 return sect
->common
.flags
;
257 /* Helper routines for maintaining object_block_htab. */
260 object_block_hasher::equal (object_block
*old
, const section
*new_section
)
262 return old
->sect
== new_section
;
266 object_block_hasher::hash (object_block
*old
)
268 return hash_section (old
->sect
);
271 /* Return a new unnamed section with the given fields. */
274 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
279 sect
= ggc_alloc
<section
> ();
280 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
281 sect
->unnamed
.callback
= callback
;
282 sect
->unnamed
.data
= data
;
283 sect
->unnamed
.next
= unnamed_sections
;
285 unnamed_sections
= sect
;
289 /* Return a SECTION_NOSWITCH section with the given fields. */
292 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
296 sect
= ggc_alloc
<section
> ();
297 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
298 sect
->noswitch
.callback
= callback
;
303 /* Return the named section structure associated with NAME. Create
304 a new section with the given fields if no such structure exists. */
307 get_section (const char *name
, unsigned int flags
, tree decl
)
309 section
*sect
, **slot
;
311 slot
= section_htab
->find_slot_with_hash (name
, htab_hash_string (name
),
313 flags
|= SECTION_NAMED
;
316 sect
= ggc_alloc
<section
> ();
317 sect
->named
.common
.flags
= flags
;
318 sect
->named
.name
= ggc_strdup (name
);
319 sect
->named
.decl
= decl
;
325 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
326 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
328 /* It is fine if one of the section flags is
329 SECTION_WRITE | SECTION_RELRO and the other has none of these
330 flags (i.e. read-only) in named sections and either the
331 section hasn't been declared yet or has been declared as writable.
332 In that case just make sure the resulting flags are
333 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
335 if (((sect
->common
.flags
^ flags
) & (SECTION_WRITE
| SECTION_RELRO
))
336 == (SECTION_WRITE
| SECTION_RELRO
)
337 && (sect
->common
.flags
338 & ~(SECTION_DECLARED
| SECTION_WRITE
| SECTION_RELRO
))
339 == (flags
& ~(SECTION_WRITE
| SECTION_RELRO
))
340 && ((sect
->common
.flags
& SECTION_DECLARED
) == 0
341 || (sect
->common
.flags
& SECTION_WRITE
)))
343 sect
->common
.flags
|= (SECTION_WRITE
| SECTION_RELRO
);
346 /* Sanity check user variables for flag changes. */
347 if (sect
->named
.decl
!= NULL
348 && DECL_P (sect
->named
.decl
)
349 && decl
!= sect
->named
.decl
)
351 if (decl
!= NULL
&& DECL_P (decl
))
352 error ("%+D causes a section type conflict with %D",
353 decl
, sect
->named
.decl
);
355 error ("section type conflict with %D", sect
->named
.decl
);
356 inform (DECL_SOURCE_LOCATION (sect
->named
.decl
),
357 "%qD was declared here", sect
->named
.decl
);
359 else if (decl
!= NULL
&& DECL_P (decl
))
360 error ("%+D causes a section type conflict", decl
);
362 error ("section type conflict");
363 /* Make sure we don't error about one section multiple times. */
364 sect
->common
.flags
|= SECTION_OVERRIDE
;
370 /* Return true if the current compilation mode benefits from having
371 objects grouped into blocks. */
374 use_object_blocks_p (void)
376 return flag_section_anchors
;
379 /* Return the object_block structure for section SECT. Create a new
380 structure if we haven't created one already. Return null if SECT
383 static struct object_block
*
384 get_block_for_section (section
*sect
)
386 struct object_block
*block
;
392 = object_block_htab
->find_slot_with_hash (sect
, hash_section (sect
),
397 block
= ggc_cleared_alloc
<object_block
> ();
404 /* Create a symbol with label LABEL and place it at byte offset
405 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
406 is not yet known. LABEL must be a garbage-collected string. */
409 create_block_symbol (const char *label
, struct object_block
*block
,
410 HOST_WIDE_INT offset
)
415 /* Create the extended SYMBOL_REF. */
416 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
417 symbol
= (rtx
) ggc_internal_alloc (size
);
419 /* Initialize the normal SYMBOL_REF fields. */
420 memset (symbol
, 0, size
);
421 PUT_CODE (symbol
, SYMBOL_REF
);
422 PUT_MODE (symbol
, Pmode
);
423 XSTR (symbol
, 0) = label
;
424 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
426 /* Initialize the block_symbol stuff. */
427 SYMBOL_REF_BLOCK (symbol
) = block
;
428 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
433 /* Return a section with a particular name and with whatever SECTION_*
434 flags section_type_flags deems appropriate. The name of the section
435 is taken from NAME if nonnull, otherwise it is taken from DECL's
436 DECL_SECTION_NAME. DECL is the decl associated with the section
437 (see the section comment for details) and RELOC is as for
438 section_type_flags. */
441 get_named_section (tree decl
, const char *name
, int reloc
)
447 gcc_assert (decl
&& DECL_P (decl
) && DECL_SECTION_NAME (decl
));
448 name
= DECL_SECTION_NAME (decl
);
451 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
452 return get_section (name
, flags
, decl
);
455 /* Worker for resolve_unique_section. */
458 set_implicit_section (struct symtab_node
*n
, void *data ATTRIBUTE_UNUSED
)
460 n
->implicit_section
= true;
464 /* If required, set DECL_SECTION_NAME to a unique name. */
467 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
468 int flag_function_or_data_sections
)
470 if (DECL_SECTION_NAME (decl
) == NULL
471 && targetm_common
.have_named_sections
472 && (flag_function_or_data_sections
473 || DECL_COMDAT_GROUP (decl
)))
475 targetm
.asm_out
.unique_section (decl
, reloc
);
476 if (DECL_SECTION_NAME (decl
))
477 symtab_node::get (decl
)->call_for_symbol_and_aliases
478 (set_implicit_section
, NULL
, true);
482 #ifdef BSS_SECTION_ASM_OP
484 #ifdef ASM_OUTPUT_ALIGNED_BSS
486 /* Utility function for targets to use in implementing
487 ASM_OUTPUT_ALIGNED_BSS.
488 ??? It is believed that this function will work in most cases so such
489 support is localized here. */
492 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
493 const char *name
, unsigned HOST_WIDE_INT size
,
496 switch_to_section (bss_section
);
497 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
498 #ifdef ASM_DECLARE_OBJECT_NAME
499 last_assemble_variable_decl
= decl
;
500 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
502 /* Standard thing is just output label for the object. */
503 ASM_OUTPUT_LABEL (file
, name
);
504 #endif /* ASM_DECLARE_OBJECT_NAME */
505 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
510 #endif /* BSS_SECTION_ASM_OP */
512 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
513 /* Return the hot section for function DECL. Return text_section for
517 hot_function_section (tree decl
)
519 if (decl
!= NULL_TREE
520 && DECL_SECTION_NAME (decl
) != NULL
521 && targetm_common
.have_named_sections
)
522 return get_named_section (decl
, NULL
, 0);
528 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
531 When DECL_SECTION_NAME is non-NULL and it is implicit section and
532 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
533 concatenate the name with NAMED_SECTION_SUFFIX.
534 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
537 get_named_text_section (tree decl
,
538 const char *text_section_name
,
539 const char *named_section_suffix
)
541 if (decl
&& DECL_SECTION_NAME (decl
))
543 if (named_section_suffix
)
545 const char *dsn
= DECL_SECTION_NAME (decl
);
546 const char *stripped_name
;
549 name
= (char *) alloca (strlen (dsn
) + 1);
553 stripped_name
= targetm
.strip_name_encoding (name
);
555 buffer
= ACONCAT ((stripped_name
, named_section_suffix
, NULL
));
556 return get_named_section (decl
, buffer
, 0);
558 else if (symtab_node::get (decl
)->implicit_section
)
562 /* Do not try to split gnu_linkonce functions. This gets somewhat
564 if (DECL_COMDAT_GROUP (decl
) && !HAVE_COMDAT_GROUP
)
566 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
567 name
= targetm
.strip_name_encoding (name
);
568 return get_named_section (decl
, ACONCAT ((text_section_name
, ".",
574 return get_named_section (decl
, text_section_name
, 0);
577 /* Choose named function section based on its frequency. */
580 default_function_section (tree decl
, enum node_frequency freq
,
581 bool startup
, bool exit
)
583 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
584 /* Old GNU linkers have buggy --gc-section support, which sometimes
585 results in .gcc_except_table* sections being garbage collected. */
587 && symtab_node::get (decl
)->implicit_section
)
591 if (!flag_reorder_functions
592 || !targetm_common
.have_named_sections
)
594 /* Startup code should go to startup subsection unless it is
595 unlikely executed (this happens especially with function splitting
596 where we can split away unnecessary parts of static constructors. */
597 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
599 /* If we do have a profile or(and) LTO phase is executed, we do not need
600 these ELF section. */
601 if (!in_lto_p
|| !flag_profile_values
)
602 return get_named_text_section (decl
, ".text.startup", NULL
);
607 /* Similarly for exit. */
608 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
609 return get_named_text_section (decl
, ".text.exit", NULL
);
611 /* Group cold functions together, similarly for hot code. */
614 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
615 return get_named_text_section (decl
, ".text.unlikely", NULL
);
616 case NODE_FREQUENCY_HOT
:
617 /* If we do have a profile or(and) LTO phase is executed, we do not need
618 these ELF section. */
619 if (!in_lto_p
|| !flag_profile_values
)
620 return get_named_text_section (decl
, ".text.hot", NULL
);
626 /* Return the section for function DECL.
628 If DECL is NULL_TREE, return the text section. We can be passed
629 NULL_TREE under some circumstances by dbxout.c at least.
631 If FORCE_COLD is true, return cold function section ignoring
632 the frequency info of cgraph_node. */
635 function_section_1 (tree decl
, bool force_cold
)
637 section
*section
= NULL
;
638 enum node_frequency freq
= NODE_FREQUENCY_NORMAL
;
639 bool startup
= false, exit
= false;
643 struct cgraph_node
*node
= cgraph_node::get (decl
);
647 freq
= node
->frequency
;
648 startup
= node
->only_called_at_startup
;
649 exit
= node
->only_called_at_exit
;
653 freq
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
655 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
656 if (decl
!= NULL_TREE
657 && DECL_SECTION_NAME (decl
) != NULL
)
659 if (targetm
.asm_out
.function_section
)
660 section
= targetm
.asm_out
.function_section (decl
, freq
,
664 return get_named_section (decl
, NULL
, 0);
667 return targetm
.asm_out
.select_section
668 (decl
, freq
== NODE_FREQUENCY_UNLIKELY_EXECUTED
,
669 symtab_node::get (decl
)->definition_alignment ());
671 if (targetm
.asm_out
.function_section
)
672 section
= targetm
.asm_out
.function_section (decl
, freq
, startup
, exit
);
675 return hot_function_section (decl
);
679 /* Return the section for function DECL.
681 If DECL is NULL_TREE, return the text section. We can be passed
682 NULL_TREE under some circumstances by dbxout.c at least. */
685 function_section (tree decl
)
687 /* Handle cases where function splitting code decides
688 to put function entry point into unlikely executed section
689 despite the fact that the function itself is not cold
690 (i.e. it is called rarely but contains a hot loop that is
691 better to live in hot subsection for the code locality). */
692 return function_section_1 (decl
,
693 first_function_block_is_cold
);
696 /* Return the section for the current function, take IN_COLD_SECTION_P
700 current_function_section (void)
702 return function_section_1 (current_function_decl
, in_cold_section_p
);
705 /* Tell assembler to switch to unlikely-to-be-executed text section. */
708 unlikely_text_section (void)
710 return function_section_1 (current_function_decl
, true);
713 /* When called within a function context, return true if the function
714 has been assigned a cold text section and if SECT is that section.
715 When called outside a function context, return true if SECT is the
716 default cold section. */
719 unlikely_text_section_p (section
*sect
)
721 return sect
== function_section_1 (current_function_decl
, true);
724 /* Return the read-only data section associated with function DECL. */
727 default_function_rodata_section (tree decl
)
729 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
731 const char *name
= DECL_SECTION_NAME (decl
);
733 if (DECL_COMDAT_GROUP (decl
) && HAVE_COMDAT_GROUP
)
739 dot
= strchr (name
+ 1, '.');
742 len
= strlen (dot
) + 8;
743 rname
= (char *) alloca (len
);
745 strcpy (rname
, ".rodata");
747 return get_section (rname
, SECTION_LINKONCE
, decl
);
749 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
750 else if (DECL_COMDAT_GROUP (decl
)
751 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
753 size_t len
= strlen (name
) + 1;
754 char *rname
= (char *) alloca (len
);
756 memcpy (rname
, name
, len
);
758 return get_section (rname
, SECTION_LINKONCE
, decl
);
760 /* For .text.foo we want to use .rodata.foo. */
761 else if (flag_function_sections
&& flag_data_sections
762 && strncmp (name
, ".text.", 6) == 0)
764 size_t len
= strlen (name
) + 1;
765 char *rname
= (char *) alloca (len
+ 2);
767 memcpy (rname
, ".rodata", 7);
768 memcpy (rname
+ 7, name
+ 5, len
- 5);
769 return get_section (rname
, 0, decl
);
773 return readonly_data_section
;
776 /* Return the read-only data section associated with function DECL
777 for targets where that section should be always the single
778 readonly data section. */
781 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
783 return readonly_data_section
;
786 /* A subroutine of mergeable_string_section and mergeable_constant_section. */
789 function_mergeable_rodata_prefix (void)
791 section
*s
= targetm
.asm_out
.function_rodata_section (current_function_decl
);
792 if (SECTION_STYLE (s
) == SECTION_NAMED
)
793 return s
->named
.name
;
795 return targetm
.asm_out
.mergeable_rodata_prefix
;
798 /* Return the section to use for string merging. */
801 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
802 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
803 unsigned int flags ATTRIBUTE_UNUSED
)
807 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
808 && TREE_CODE (decl
) == STRING_CST
809 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
811 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
812 && TREE_STRING_LENGTH (decl
) >= len
)
815 unsigned int modesize
;
819 const char *prefix
= function_mergeable_rodata_prefix ();
820 char *name
= (char *) alloca (strlen (prefix
) + 30);
822 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
823 modesize
= GET_MODE_BITSIZE (mode
);
824 if (modesize
>= 8 && modesize
<= 256
825 && (modesize
& (modesize
- 1)) == 0)
827 if (align
< modesize
)
830 str
= TREE_STRING_POINTER (decl
);
831 unit
= GET_MODE_SIZE (mode
);
833 /* Check for embedded NUL characters. */
834 for (i
= 0; i
< len
; i
+= unit
)
836 for (j
= 0; j
< unit
; j
++)
837 if (str
[i
+ j
] != '\0')
844 sprintf (name
, "%s.str%d.%d", prefix
,
845 modesize
/ 8, (int) (align
/ 8));
846 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
847 return get_section (name
, flags
, NULL
);
852 return readonly_data_section
;
855 /* Return the section to use for constant merging. */
858 mergeable_constant_section (machine_mode mode ATTRIBUTE_UNUSED
,
859 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
860 unsigned int flags ATTRIBUTE_UNUSED
)
862 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
864 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
870 && (align
& (align
- 1)) == 0)
872 const char *prefix
= function_mergeable_rodata_prefix ();
873 char *name
= (char *) alloca (strlen (prefix
) + 30);
875 sprintf (name
, "%s.cst%d", prefix
, (int) (align
/ 8));
876 flags
|= (align
/ 8) | SECTION_MERGE
;
877 return get_section (name
, flags
, NULL
);
879 return readonly_data_section
;
882 /* Given NAME, a putative register name, discard any customary prefixes. */
885 strip_reg_name (const char *name
)
887 #ifdef REGISTER_PREFIX
888 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
889 name
+= strlen (REGISTER_PREFIX
);
891 if (name
[0] == '%' || name
[0] == '#')
896 /* The user has asked for a DECL to have a particular name. Set (or
897 change) it in such a way that we don't prefix an underscore to
900 set_user_assembler_name (tree decl
, const char *name
)
902 char *starred
= (char *) alloca (strlen (name
) + 2);
904 strcpy (starred
+ 1, name
);
905 symtab
->change_decl_assembler_name (decl
, get_identifier (starred
));
906 SET_DECL_RTL (decl
, NULL_RTX
);
909 /* Decode an `asm' spec for a declaration as a register name.
910 Return the register number, or -1 if nothing specified,
911 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
912 or -3 if ASMSPEC is `cc' and is not recognized,
913 or -4 if ASMSPEC is `memory' and is not recognized.
914 Accept an exact spelling or a decimal number.
915 Prefixes such as % are optional. */
918 decode_reg_name_and_count (const char *asmspec
, int *pnregs
)
920 /* Presume just one register is clobbered. */
927 /* Get rid of confusing prefixes. */
928 asmspec
= strip_reg_name (asmspec
);
930 /* Allow a decimal number as a "register name". */
931 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
932 if (! ISDIGIT (asmspec
[i
]))
934 if (asmspec
[0] != 0 && i
< 0)
937 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0 && reg_names
[i
][0])
943 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
945 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
948 #ifdef OVERLAPPING_REGISTER_NAMES
952 const char *const name
;
955 } table
[] = OVERLAPPING_REGISTER_NAMES
;
957 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
959 && ! strcmp (asmspec
, table
[i
].name
))
961 *pnregs
= table
[i
].nregs
;
962 return table
[i
].number
;
965 #endif /* OVERLAPPING_REGISTER_NAMES */
967 #ifdef ADDITIONAL_REGISTER_NAMES
969 static const struct { const char *const name
; const int number
; } table
[]
970 = ADDITIONAL_REGISTER_NAMES
;
972 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
974 && ! strcmp (asmspec
, table
[i
].name
)
975 && reg_names
[table
[i
].number
][0])
976 return table
[i
].number
;
978 #endif /* ADDITIONAL_REGISTER_NAMES */
980 if (!strcmp (asmspec
, "memory"))
983 if (!strcmp (asmspec
, "cc"))
993 decode_reg_name (const char *name
)
996 return decode_reg_name_and_count (name
, &count
);
1000 /* Return true if DECL's initializer is suitable for a BSS section. */
1003 bss_initializer_p (const_tree decl
)
1005 return (DECL_INITIAL (decl
) == NULL
1006 /* In LTO we have no errors in program; error_mark_node is used
1007 to mark offlined constructors. */
1008 || (DECL_INITIAL (decl
) == error_mark_node
1010 || (flag_zero_initialized_in_bss
1011 /* Leave constant zeroes in .rodata so they
1013 && !TREE_READONLY (decl
)
1014 && initializer_zerop (DECL_INITIAL (decl
))));
1017 /* Compute the alignment of variable specified by DECL.
1018 DONT_OUTPUT_DATA is from assemble_variable. */
1021 align_variable (tree decl
, bool dont_output_data
)
1023 unsigned int align
= DECL_ALIGN (decl
);
1025 /* In the case for initialing an array whose length isn't specified,
1026 where we have not yet been able to do the layout,
1027 figure out the proper alignment now. */
1028 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1029 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1030 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1032 /* Some object file formats have a maximum alignment which they support.
1033 In particular, a.out format supports a maximum alignment of 4. */
1034 if (align
> MAX_OFILE_ALIGNMENT
)
1036 error ("alignment of %q+D is greater than maximum object "
1037 "file alignment %d", decl
,
1038 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1039 align
= MAX_OFILE_ALIGNMENT
;
1042 if (! DECL_USER_ALIGN (decl
))
1044 #ifdef DATA_ABI_ALIGNMENT
1045 unsigned int data_abi_align
1046 = DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1047 /* For backwards compatibility, don't assume the ABI alignment for
1049 if (! DECL_THREAD_LOCAL_P (decl
) || data_abi_align
<= BITS_PER_WORD
)
1050 align
= data_abi_align
;
1053 /* On some machines, it is good to increase alignment sometimes.
1054 But as DECL_ALIGN is used both for actually emitting the variable
1055 and for code accessing the variable as guaranteed alignment, we
1056 can only increase the alignment if it is a performance optimization
1057 if the references to it must bind to the current definition. */
1058 if (decl_binds_to_current_def_p (decl
)
1059 && !DECL_VIRTUAL_P (decl
))
1061 #ifdef DATA_ALIGNMENT
1062 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1063 /* Don't increase alignment too much for TLS variables - TLS space
1065 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1068 #ifdef CONSTANT_ALIGNMENT
1069 if (DECL_INITIAL (decl
) != 0
1070 /* In LTO we have no errors in program; error_mark_node is used
1071 to mark offlined constructors. */
1072 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1074 unsigned int const_align
1075 = CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1076 /* Don't increase alignment too much for TLS variables - TLS
1077 space is too precious. */
1078 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1079 align
= const_align
;
1085 /* Reset the alignment in case we have made it tighter, so we can benefit
1086 from it in get_pointer_alignment. */
1087 DECL_ALIGN (decl
) = align
;
1090 /* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1091 beyond what align_variable returned. */
1094 get_variable_align (tree decl
)
1096 unsigned int align
= DECL_ALIGN (decl
);
1098 /* For user aligned vars or static vars align_variable already did
1100 if (DECL_USER_ALIGN (decl
) || !TREE_PUBLIC (decl
))
1103 #ifdef DATA_ABI_ALIGNMENT
1104 if (DECL_THREAD_LOCAL_P (decl
))
1105 align
= DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1108 /* For decls that bind to the current definition, align_variable
1109 did also everything, except for not assuming ABI required alignment
1110 of TLS variables. For other vars, increase the alignment here
1111 as an optimization. */
1112 if (!decl_binds_to_current_def_p (decl
))
1114 /* On some machines, it is good to increase alignment sometimes. */
1115 #ifdef DATA_ALIGNMENT
1116 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1117 /* Don't increase alignment too much for TLS variables - TLS space
1119 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1122 #ifdef CONSTANT_ALIGNMENT
1123 if (DECL_INITIAL (decl
) != 0
1124 /* In LTO we have no errors in program; error_mark_node is used
1125 to mark offlined constructors. */
1126 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1128 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
1130 /* Don't increase alignment too much for TLS variables - TLS space
1132 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1133 align
= const_align
;
1141 /* Return the section into which the given VAR_DECL or CONST_DECL
1142 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1143 section should be used wherever possible. */
1146 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1148 addr_space_t as
= ADDR_SPACE_GENERIC
;
1150 varpool_node
*vnode
= varpool_node::get (decl
);
1153 vnode
= vnode
->ultimate_alias_target ();
1157 if (TREE_TYPE (decl
) != error_mark_node
)
1158 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1160 /* We need the constructor to figure out reloc flag. */
1162 vnode
->get_constructor ();
1164 if (DECL_COMMON (decl
))
1166 /* If the decl has been given an explicit section name, or it resides
1167 in a non-generic address space, then it isn't common, and shouldn't
1168 be handled as such. */
1169 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1170 && ADDR_SPACE_GENERIC_P (as
));
1171 if (DECL_THREAD_LOCAL_P (decl
))
1172 return tls_comm_section
;
1173 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1174 return comm_section
;
1177 if (DECL_INITIAL (decl
) == error_mark_node
)
1178 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1179 else if (DECL_INITIAL (decl
))
1180 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1184 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1185 if (IN_NAMED_SECTION (decl
))
1186 return get_named_section (decl
, NULL
, reloc
);
1188 if (ADDR_SPACE_GENERIC_P (as
)
1189 && !DECL_THREAD_LOCAL_P (decl
)
1190 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1191 && bss_initializer_p (decl
))
1193 if (!TREE_PUBLIC (decl
)
1194 && !((flag_sanitize
& SANITIZE_ADDRESS
)
1195 && asan_protect_global (decl
)))
1196 return lcomm_section
;
1197 if (bss_noswitch_section
)
1198 return bss_noswitch_section
;
1201 return targetm
.asm_out
.select_section (decl
, reloc
,
1202 get_variable_align (decl
));
1205 /* Return the block into which object_block DECL should be placed. */
1207 static struct object_block
*
1208 get_block_for_decl (tree decl
)
1212 if (TREE_CODE (decl
) == VAR_DECL
)
1214 /* The object must be defined in this translation unit. */
1215 if (DECL_EXTERNAL (decl
))
1218 /* There's no point using object blocks for something that is
1219 isolated by definition. */
1220 if (DECL_COMDAT_GROUP (decl
))
1224 /* We can only calculate block offsets if the decl has a known
1226 if (DECL_SIZE_UNIT (decl
) == NULL
)
1228 if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl
)))
1231 /* Find out which section should contain DECL. We cannot put it into
1232 an object block if it requires a standalone definition. */
1233 if (TREE_CODE (decl
) == VAR_DECL
)
1234 align_variable (decl
, 0);
1235 sect
= get_variable_section (decl
, true);
1236 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1239 return get_block_for_section (sect
);
1242 /* Make sure block symbol SYMBOL is in block BLOCK. */
1245 change_symbol_block (rtx symbol
, struct object_block
*block
)
1247 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1249 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1250 SYMBOL_REF_BLOCK (symbol
) = block
;
1254 /* Return true if it is possible to put DECL in an object_block. */
1257 use_blocks_for_decl_p (tree decl
)
1259 struct symtab_node
*snode
;
1261 /* Only data DECLs can be placed into object blocks. */
1262 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
1265 /* Detect decls created by dw2_force_const_mem. Such decls are
1266 special because DECL_INITIAL doesn't specify the decl's true value.
1267 dw2_output_indirect_constants will instead call assemble_variable
1268 with dont_output_data set to 1 and then print the contents itself. */
1269 if (DECL_INITIAL (decl
) == decl
)
1272 /* If this decl is an alias, then we don't want to emit a
1274 if (TREE_CODE (decl
) == VAR_DECL
1275 && (snode
= symtab_node::get (decl
)) != NULL
1279 return targetm
.use_blocks_for_decl_p (decl
);
1282 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1283 until we find an identifier that is not itself a transparent alias.
1284 Modify the alias passed to it by reference (and all aliases on the
1285 way to the ultimate target), such that they do not have to be
1286 followed again, and return the ultimate target of the alias
1290 ultimate_transparent_alias_target (tree
*alias
)
1292 tree target
= *alias
;
1294 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
1296 gcc_assert (TREE_CHAIN (target
));
1297 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
1298 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
1299 && ! TREE_CHAIN (target
));
1306 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1307 have static storage duration. In other words, it should not be an
1308 automatic variable, including PARM_DECLs.
1310 There is, however, one exception: this function handles variables
1311 explicitly placed in a particular register by the user.
1313 This is never called for PARM_DECL nodes. */
1316 make_decl_rtl (tree decl
)
1318 const char *name
= 0;
1323 /* Check that we are not being given an automatic variable. */
1324 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1325 && TREE_CODE (decl
) != RESULT_DECL
);
1327 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1328 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1329 || TREE_STATIC (decl
)
1330 || TREE_PUBLIC (decl
)
1331 || DECL_EXTERNAL (decl
)
1332 || DECL_REGISTER (decl
));
1334 /* And that we were not given a type or a label. */
1335 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1336 && TREE_CODE (decl
) != LABEL_DECL
);
1338 /* For a duplicate declaration, we can be called twice on the
1339 same DECL node. Don't discard the RTL already made. */
1340 if (DECL_RTL_SET_P (decl
))
1342 /* If the old RTL had the wrong mode, fix the mode. */
1343 x
= DECL_RTL (decl
);
1344 if (GET_MODE (x
) != DECL_MODE (decl
))
1345 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1347 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1350 /* ??? Another way to do this would be to maintain a hashed
1351 table of such critters. Instead of adding stuff to a DECL
1352 to give certain attributes to it, we could use an external
1353 hash map from DECL to set of attributes. */
1355 /* Let the target reassign the RTL if it wants.
1356 This is necessary, for example, when one machine specific
1357 decl attribute overrides another. */
1358 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1360 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1361 on the new decl information. */
1363 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1364 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1365 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1370 /* If this variable belongs to the global constant pool, retrieve the
1371 pre-computed RTL or recompute it in LTO mode. */
1372 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1374 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1378 id
= DECL_ASSEMBLER_NAME (decl
);
1379 if (TREE_CODE (decl
) == FUNCTION_DECL
1380 && cgraph_node::get (decl
)
1381 && cgraph_node::get (decl
)->instrumentation_clone
)
1382 ultimate_transparent_alias_target (&id
);
1383 name
= IDENTIFIER_POINTER (id
);
1385 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1386 && DECL_REGISTER (decl
))
1388 error ("register name not specified for %q+D", decl
);
1390 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1392 const char *asmspec
= name
+1;
1393 machine_mode mode
= DECL_MODE (decl
);
1394 reg_number
= decode_reg_name (asmspec
);
1395 /* First detect errors in declaring global registers. */
1396 if (reg_number
== -1)
1397 error ("register name not specified for %q+D", decl
);
1398 else if (reg_number
< 0)
1399 error ("invalid register name for %q+D", decl
);
1400 else if (mode
== BLKmode
)
1401 error ("data type of %q+D isn%'t suitable for a register",
1403 else if (!in_hard_reg_set_p (accessible_reg_set
, mode
, reg_number
))
1404 error ("the register specified for %q+D cannot be accessed"
1405 " by the current target", decl
);
1406 else if (!in_hard_reg_set_p (operand_reg_set
, mode
, reg_number
))
1407 error ("the register specified for %q+D is not general enough"
1408 " to be used as a register variable", decl
);
1409 else if (!HARD_REGNO_MODE_OK (reg_number
, mode
))
1410 error ("register specified for %q+D isn%'t suitable for data type",
1412 /* Now handle properly declared static register variables. */
1417 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1419 DECL_INITIAL (decl
) = 0;
1420 error ("global register variable has initial value");
1422 if (TREE_THIS_VOLATILE (decl
))
1423 warning (OPT_Wvolatile_register_var
,
1424 "optimization may eliminate reads and/or "
1425 "writes to register variables");
1427 /* If the user specified one of the eliminables registers here,
1428 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1429 confused with that register and be eliminated. This usage is
1430 somewhat suspect... */
1432 SET_DECL_RTL (decl
, gen_rtx_raw_REG (mode
, reg_number
));
1433 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1434 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1436 if (TREE_STATIC (decl
))
1438 /* Make this register global, so not usable for anything
1440 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1441 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1442 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1444 nregs
= hard_regno_nregs
[reg_number
][mode
];
1446 globalize_reg (decl
, reg_number
+ --nregs
);
1449 /* As a register variable, it has no section. */
1452 /* Avoid internal errors from invalid register
1454 SET_DECL_ASSEMBLER_NAME (decl
, NULL_TREE
);
1455 DECL_HARD_REGISTER (decl
) = 0;
1458 /* Now handle ordinary static variables and functions (in memory).
1459 Also handle vars declared register invalidly. */
1460 else if (name
[0] == '*')
1462 #ifdef REGISTER_PREFIX
1463 if (strlen (REGISTER_PREFIX
) != 0)
1465 reg_number
= decode_reg_name (name
);
1466 if (reg_number
>= 0 || reg_number
== -3)
1467 error ("register name given for non-register variable %q+D", decl
);
1472 /* Specifying a section attribute on a variable forces it into a
1473 non-.bss section, and thus it cannot be common. */
1474 /* FIXME: In general this code should not be necessary because
1475 visibility pass is doing the same work. But notice_global_symbol
1476 is called early and it needs to make DECL_RTL to get the name.
1477 we take care of recomputing the DECL_RTL after visibility is changed. */
1478 if (TREE_CODE (decl
) == VAR_DECL
1479 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
1480 && DECL_SECTION_NAME (decl
) != NULL
1481 && DECL_INITIAL (decl
) == NULL_TREE
1482 && DECL_COMMON (decl
))
1483 DECL_COMMON (decl
) = 0;
1485 /* Variables can't be both common and weak. */
1486 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1487 DECL_COMMON (decl
) = 0;
1489 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1490 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1493 machine_mode address_mode
= Pmode
;
1494 if (TREE_TYPE (decl
) != error_mark_node
)
1496 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1497 address_mode
= targetm
.addr_space
.address_mode (as
);
1499 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1501 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1502 SET_SYMBOL_REF_DECL (x
, decl
);
1504 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1505 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1506 set_mem_attributes (x
, decl
, 1);
1507 SET_DECL_RTL (decl
, x
);
1509 /* Optionally set flags or add text to the name to record information
1510 such as that it is a function name.
1511 If the name is changed, the macro ASM_OUTPUT_LABELREF
1512 will have to know how to strip this information. */
1513 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1516 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1517 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1521 make_decl_rtl_for_debug (tree decl
)
1523 unsigned int save_aliasing_flag
;
1526 if (DECL_RTL_SET_P (decl
))
1527 return DECL_RTL (decl
);
1529 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1530 call new_alias_set. If running with -fcompare-debug, sometimes
1531 we do not want to create alias sets that will throw the alias
1532 numbers off in the comparison dumps. So... clearing
1533 flag_strict_aliasing will keep new_alias_set() from creating a
1535 save_aliasing_flag
= flag_strict_aliasing
;
1536 flag_strict_aliasing
= 0;
1538 rtl
= DECL_RTL (decl
);
1539 /* Reset DECL_RTL back, as various parts of the compiler expects
1540 DECL_RTL set meaning it is actually going to be output. */
1541 SET_DECL_RTL (decl
, NULL
);
1543 flag_strict_aliasing
= save_aliasing_flag
;
1547 /* Output a string of literal assembler code
1548 for an `asm' keyword used between functions. */
1551 assemble_asm (tree string
)
1556 if (TREE_CODE (string
) == ADDR_EXPR
)
1557 string
= TREE_OPERAND (string
, 0);
1559 p
= TREE_STRING_POINTER (string
);
1560 fprintf (asm_out_file
, "%s%s\n", p
[0] == '\t' ? "" : "\t", p
);
1563 /* Write the address of the entity given by SYMBOL to SEC. */
1565 assemble_addr_to_section (rtx symbol
, section
*sec
)
1567 switch_to_section (sec
);
1568 assemble_align (POINTER_SIZE
);
1569 assemble_integer (symbol
, POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
1572 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1573 not) section for PRIORITY. */
1575 get_cdtor_priority_section (int priority
, bool constructor_p
)
1579 /* ??? This only works reliably with the GNU linker. */
1580 sprintf (buf
, "%s.%.5u",
1581 constructor_p
? ".ctors" : ".dtors",
1582 /* Invert the numbering so the linker puts us in the proper
1583 order; constructors are run from right to left, and the
1584 linker sorts in increasing order. */
1585 MAX_INIT_PRIORITY
- priority
);
1586 return get_section (buf
, SECTION_WRITE
, NULL
);
1590 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1594 if (priority
!= DEFAULT_INIT_PRIORITY
)
1595 sec
= get_cdtor_priority_section (priority
,
1596 /*constructor_p=*/false);
1598 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1600 assemble_addr_to_section (symbol
, sec
);
1603 #ifdef DTORS_SECTION_ASM_OP
1605 default_dtor_section_asm_out_destructor (rtx symbol
,
1606 int priority ATTRIBUTE_UNUSED
)
1608 assemble_addr_to_section (symbol
, dtors_section
);
1613 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1617 if (priority
!= DEFAULT_INIT_PRIORITY
)
1618 sec
= get_cdtor_priority_section (priority
,
1619 /*constructor_p=*/true);
1621 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1623 assemble_addr_to_section (symbol
, sec
);
1626 #ifdef CTORS_SECTION_ASM_OP
1628 default_ctor_section_asm_out_constructor (rtx symbol
,
1629 int priority ATTRIBUTE_UNUSED
)
1631 assemble_addr_to_section (symbol
, ctors_section
);
1635 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1636 a nonzero value if the constant pool should be output before the
1637 start of the function, or a zero value if the pool should output
1638 after the end of the function. The default is to put it before the
1641 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1642 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1645 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1646 to be output to assembler.
1647 Set first_global_object_name and weak_global_object_name as appropriate. */
1650 notice_global_symbol (tree decl
)
1652 const char **t
= &first_global_object_name
;
1654 if (first_global_object_name
1655 || !TREE_PUBLIC (decl
)
1656 || DECL_EXTERNAL (decl
)
1657 || !DECL_NAME (decl
)
1658 || (TREE_CODE (decl
) == VAR_DECL
&& DECL_HARD_REGISTER (decl
))
1659 || (TREE_CODE (decl
) != FUNCTION_DECL
1660 && (TREE_CODE (decl
) != VAR_DECL
1661 || (DECL_COMMON (decl
)
1662 && (DECL_INITIAL (decl
) == 0
1663 || DECL_INITIAL (decl
) == error_mark_node
)))))
1666 /* We win when global object is found, but it is useful to know about weak
1667 symbol as well so we can produce nicer unique names. */
1668 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1669 t
= &weak_global_object_name
;
1673 tree id
= DECL_ASSEMBLER_NAME (decl
);
1674 ultimate_transparent_alias_target (&id
);
1675 *t
= ggc_strdup (targetm
.strip_name_encoding (IDENTIFIER_POINTER (id
)));
1679 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1680 current function goes into the cold section, so that targets can use
1681 current_function_section during RTL expansion. DECL describes the
1685 decide_function_section (tree decl
)
1687 first_function_block_is_cold
= false;
1689 if (flag_reorder_blocks_and_partition
)
1690 /* We will decide in assemble_start_function. */
1693 if (DECL_SECTION_NAME (decl
))
1695 struct cgraph_node
*node
= cgraph_node::get (current_function_decl
);
1696 /* Calls to function_section rely on first_function_block_is_cold
1698 first_function_block_is_cold
= (node
1700 == NODE_FREQUENCY_UNLIKELY_EXECUTED
);
1703 in_cold_section_p
= first_function_block_is_cold
;
1706 /* Get the function's name, as described by its RTL. This may be
1707 different from the DECL_NAME name used in the source file. */
1709 get_fnname_from_decl (tree decl
)
1711 rtx x
= DECL_RTL (decl
);
1712 gcc_assert (MEM_P (x
));
1714 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
1718 /* Output assembler code for the constant pool of a function and associated
1719 with defining the name of the function. DECL describes the function.
1720 NAME is the function's name. For the constant pool, we use the current
1721 constant pool data. */
1724 assemble_start_function (tree decl
, const char *fnname
)
1727 char tmp_label
[100];
1728 bool hot_label_written
= false;
1730 if (flag_reorder_blocks_and_partition
)
1732 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1733 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1734 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1735 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1736 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1737 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1738 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1739 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1741 cold_function_name
= NULL_TREE
;
1745 crtl
->subsections
.hot_section_label
= NULL
;
1746 crtl
->subsections
.cold_section_label
= NULL
;
1747 crtl
->subsections
.hot_section_end_label
= NULL
;
1748 crtl
->subsections
.cold_section_end_label
= NULL
;
1751 /* The following code does not need preprocessing in the assembler. */
1755 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1756 output_constant_pool (fnname
, decl
);
1758 align
= symtab_node::get (decl
)->definition_alignment ();
1760 /* Make sure the not and cold text (code) sections are properly
1761 aligned. This is necessary here in the case where the function
1762 has both hot and cold sections, because we don't want to re-set
1763 the alignment when the section switch happens mid-function. */
1765 if (flag_reorder_blocks_and_partition
)
1767 first_function_block_is_cold
= false;
1769 switch_to_section (unlikely_text_section ());
1770 assemble_align (align
);
1771 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1773 /* When the function starts with a cold section, we need to explicitly
1774 align the hot section and write out the hot section label.
1775 But if the current function is a thunk, we do not have a CFG. */
1777 && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun
)->next_bb
) == BB_COLD_PARTITION
)
1779 switch_to_section (text_section
);
1780 assemble_align (align
);
1781 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1782 hot_label_written
= true;
1783 first_function_block_is_cold
= true;
1785 in_cold_section_p
= first_function_block_is_cold
;
1789 /* Switch to the correct text section for the start of the function. */
1791 switch_to_section (function_section (decl
));
1792 if (flag_reorder_blocks_and_partition
1793 && !hot_label_written
)
1794 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1796 /* Tell assembler to move to target machine's alignment for functions. */
1797 align
= floor_log2 (align
/ BITS_PER_UNIT
);
1800 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1803 /* Handle a user-specified function alignment.
1804 Note that we still need to align to DECL_ALIGN, as above,
1805 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1806 if (! DECL_USER_ALIGN (decl
)
1807 && align_functions_log
> align
1808 && optimize_function_for_speed_p (cfun
))
1810 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1811 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1812 align_functions_log
, align_functions
- 1);
1814 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1818 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1819 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1822 if (!DECL_IGNORED_P (decl
))
1823 (*debug_hooks
->begin_function
) (decl
);
1825 /* Make function name accessible from other files, if appropriate. */
1827 if (TREE_PUBLIC (decl
)
1828 || (cgraph_node::get (decl
)->instrumentation_clone
1829 && cgraph_node::get (decl
)->instrumented_version
1830 && TREE_PUBLIC (cgraph_node::get (decl
)->instrumented_version
->decl
)))
1832 notice_global_symbol (decl
);
1834 globalize_decl (decl
);
1836 maybe_assemble_visibility (decl
);
1839 if (DECL_PRESERVE_P (decl
))
1840 targetm
.asm_out
.mark_decl_preserved (fnname
);
1842 /* Do any machine/system dependent processing of the function name. */
1843 #ifdef ASM_DECLARE_FUNCTION_NAME
1844 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1846 /* Standard thing is just output label for the function. */
1847 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1848 #endif /* ASM_DECLARE_FUNCTION_NAME */
1850 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1851 saw_no_split_stack
= true;
1854 /* Output assembler code associated with defining the size of the
1855 function. DECL describes the function. NAME is the function's name. */
1858 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1860 #ifdef ASM_DECLARE_FUNCTION_SIZE
1861 /* We could have switched section in the middle of the function. */
1862 if (flag_reorder_blocks_and_partition
)
1863 switch_to_section (function_section (decl
));
1864 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1866 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1868 output_constant_pool (fnname
, decl
);
1869 switch_to_section (function_section (decl
)); /* need to switch back */
1871 /* Output labels for end of hot/cold text sections (to be used by
1873 if (flag_reorder_blocks_and_partition
)
1875 section
*save_text_section
;
1877 save_text_section
= in_section
;
1878 switch_to_section (unlikely_text_section ());
1879 #ifdef ASM_DECLARE_COLD_FUNCTION_SIZE
1880 if (cold_function_name
!= NULL_TREE
)
1881 ASM_DECLARE_COLD_FUNCTION_SIZE (asm_out_file
,
1882 IDENTIFIER_POINTER (cold_function_name
),
1885 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1886 if (first_function_block_is_cold
)
1887 switch_to_section (text_section
);
1889 switch_to_section (function_section (decl
));
1890 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1891 switch_to_section (save_text_section
);
1895 /* Assemble code to leave SIZE bytes of zeros. */
1898 assemble_zeros (unsigned HOST_WIDE_INT size
)
1900 /* Do no output if -fsyntax-only. */
1901 if (flag_syntax_only
)
1904 #ifdef ASM_NO_SKIP_IN_TEXT
1905 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1906 so we must output 0s explicitly in the text section. */
1907 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1909 unsigned HOST_WIDE_INT i
;
1910 for (i
= 0; i
< size
; i
++)
1911 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1916 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1919 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1922 assemble_align (int align
)
1924 if (align
> BITS_PER_UNIT
)
1926 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1930 /* Assemble a string constant with the specified C string as contents. */
1933 assemble_string (const char *p
, int size
)
1938 /* If the string is very long, split it up. */
1942 int thissize
= size
- pos
;
1943 if (thissize
> maximum
)
1946 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1954 /* A noswitch_section_callback for lcomm_section. */
1957 emit_local (tree decl ATTRIBUTE_UNUSED
,
1958 const char *name ATTRIBUTE_UNUSED
,
1959 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1960 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1962 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1963 int align
= symtab_node::get (decl
)->definition_alignment ();
1964 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1967 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1968 int align
= symtab_node::get (decl
)->definition_alignment ();
1969 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, align
);
1972 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1977 /* A noswitch_section_callback for bss_noswitch_section. */
1979 #if defined ASM_OUTPUT_ALIGNED_BSS
1981 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1982 const char *name ATTRIBUTE_UNUSED
,
1983 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1984 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1986 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
,
1987 get_variable_align (decl
));
1992 /* A noswitch_section_callback for comm_section. */
1995 emit_common (tree decl ATTRIBUTE_UNUSED
,
1996 const char *name ATTRIBUTE_UNUSED
,
1997 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1998 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2000 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
2001 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
2002 size
, get_variable_align (decl
));
2004 #elif defined ASM_OUTPUT_ALIGNED_COMMON
2005 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
2006 get_variable_align (decl
));
2009 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
2014 /* A noswitch_section_callback for tls_comm_section. */
2017 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
2018 const char *name ATTRIBUTE_UNUSED
,
2019 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2020 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2022 #ifdef ASM_OUTPUT_TLS_COMMON
2023 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
2026 sorry ("thread-local COMMON data not implemented");
2031 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2032 NAME is the name of DECL's SYMBOL_REF. */
2035 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
,
2038 unsigned HOST_WIDE_INT size
, rounded
;
2040 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2043 if ((flag_sanitize
& SANITIZE_ADDRESS
) && asan_protect_global (decl
))
2044 size
+= asan_red_zone_size (size
);
2046 /* Don't allocate zero bytes of common,
2047 since that means "undefined external" in the linker. */
2051 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2052 so that each uninitialized object starts on such a boundary. */
2053 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
2054 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2055 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2057 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
2058 && (unsigned HOST_WIDE_INT
) (align
/ BITS_PER_UNIT
) > rounded
)
2059 error ("requested alignment for %q+D is greater than "
2060 "implemented alignment of %wu", decl
, rounded
);
2063 /* A subroutine of assemble_variable. Output the label and contents of
2064 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2065 is as for assemble_variable. */
2068 assemble_variable_contents (tree decl
, const char *name
,
2069 bool dont_output_data
)
2071 /* Do any machine/system dependent processing of the object. */
2072 #ifdef ASM_DECLARE_OBJECT_NAME
2073 last_assemble_variable_decl
= decl
;
2074 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
2076 /* Standard thing is just output label for the object. */
2077 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2078 #endif /* ASM_DECLARE_OBJECT_NAME */
2080 if (!dont_output_data
)
2082 /* Caller is supposed to use varpool_get_constructor when it wants
2083 to output the body. */
2084 gcc_assert (!in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
);
2085 if (DECL_INITIAL (decl
)
2086 && DECL_INITIAL (decl
) != error_mark_node
2087 && !initializer_zerop (DECL_INITIAL (decl
)))
2088 /* Output the actual data. */
2089 output_constant (DECL_INITIAL (decl
),
2090 tree_to_uhwi (DECL_SIZE_UNIT (decl
)),
2091 get_variable_align (decl
));
2093 /* Leave space for it. */
2094 assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl
)));
2095 targetm
.asm_out
.decl_end ();
2099 /* Write out assembly for the variable DECL, which is not defined in
2100 the current translation unit. */
2102 assemble_undefined_decl (tree decl
)
2104 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
2105 targetm
.asm_out
.assemble_undefined_decl (asm_out_file
, name
, decl
);
2108 /* Assemble everything that is needed for a variable or function declaration.
2109 Not used for automatic variables, and not used for function definitions.
2110 Should not be called for variables of incomplete structure type.
2112 TOP_LEVEL is nonzero if this variable has file scope.
2113 AT_END is nonzero if this is the special handling, at end of compilation,
2114 to define things that have had only tentative definitions.
2115 DONT_OUTPUT_DATA if nonzero means don't actually output the
2116 initial value (that will be done by the caller). */
2119 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
2120 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
2123 rtx decl_rtl
, symbol
;
2126 bool asan_protected
= false;
2128 /* This function is supposed to handle VARIABLES. Ensure we have one. */
2129 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
2131 /* Emulated TLS had better not get this far. */
2132 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
2134 last_assemble_variable_decl
= 0;
2136 /* Normally no need to say anything here for external references,
2137 since assemble_external is called by the language-specific code
2138 when a declaration is first seen. */
2140 if (DECL_EXTERNAL (decl
))
2143 /* Do nothing for global register variables. */
2144 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2146 TREE_ASM_WRITTEN (decl
) = 1;
2150 /* If type was incomplete when the variable was declared,
2151 see if it is complete now. */
2153 if (DECL_SIZE (decl
) == 0)
2154 layout_decl (decl
, 0);
2156 /* Still incomplete => don't allocate it; treat the tentative defn
2157 (which is what it must have been) as an `extern' reference. */
2159 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2161 error ("storage size of %q+D isn%'t known", decl
);
2162 TREE_ASM_WRITTEN (decl
) = 1;
2166 /* The first declaration of a variable that comes through this function
2167 decides whether it is global (in C, has external linkage)
2168 or local (in C, has internal linkage). So do nothing more
2169 if this function has already run. */
2171 if (TREE_ASM_WRITTEN (decl
))
2174 /* Make sure targetm.encode_section_info is invoked before we set
2176 decl_rtl
= DECL_RTL (decl
);
2178 TREE_ASM_WRITTEN (decl
) = 1;
2180 /* Do no output if -fsyntax-only. */
2181 if (flag_syntax_only
)
2184 if (! dont_output_data
2185 && ! valid_constant_size_p (DECL_SIZE_UNIT (decl
)))
2187 error ("size of variable %q+D is too large", decl
);
2191 gcc_assert (MEM_P (decl_rtl
));
2192 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2193 symbol
= XEXP (decl_rtl
, 0);
2195 /* If this symbol belongs to the tree constant pool, output the constant
2196 if it hasn't already been written. */
2197 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
2199 tree decl
= SYMBOL_REF_DECL (symbol
);
2200 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2201 output_constant_def_contents (symbol
);
2207 name
= XSTR (symbol
, 0);
2208 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2209 notice_global_symbol (decl
);
2211 /* Compute the alignment of this data. */
2213 align_variable (decl
, dont_output_data
);
2215 if ((flag_sanitize
& SANITIZE_ADDRESS
)
2216 && asan_protect_global (decl
))
2218 asan_protected
= true;
2219 DECL_ALIGN (decl
) = MAX (DECL_ALIGN (decl
),
2220 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
2223 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2225 align
= get_variable_align (decl
);
2227 if (TREE_PUBLIC (decl
))
2228 maybe_assemble_visibility (decl
);
2230 if (DECL_PRESERVE_P (decl
))
2231 targetm
.asm_out
.mark_decl_preserved (name
);
2233 /* First make the assembler name(s) global if appropriate. */
2234 sect
= get_variable_section (decl
, false);
2235 if (TREE_PUBLIC (decl
)
2236 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2237 globalize_decl (decl
);
2239 /* Output any data that we will need to use the address of. */
2240 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2241 output_addressed_constants (DECL_INITIAL (decl
));
2243 /* dbxout.c needs to know this. */
2244 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2245 DECL_IN_TEXT_SECTION (decl
) = 1;
2247 /* If the decl is part of an object_block, make sure that the decl
2248 has been positioned within its block, but do not write out its
2249 definition yet. output_object_blocks will do that later. */
2250 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2252 gcc_assert (!dont_output_data
);
2253 place_block_symbol (symbol
);
2255 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2256 assemble_noswitch_variable (decl
, name
, sect
, align
);
2259 /* The following bit of code ensures that vtable_map
2260 variables are not only in the comdat section, but that
2261 each variable has its own unique comdat name. If this
2262 code is removed, the variables end up in the same section
2263 with a single comdat name.
2265 FIXME: resolve_unique_section needs to deal better with
2266 decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
2267 that is fixed, this if-else statement can be replaced with
2268 a single call to "switch_to_section (sect)". */
2269 if (sect
->named
.name
2270 && (strcmp (sect
->named
.name
, ".vtable_map_vars") == 0))
2272 #if defined (OBJECT_FORMAT_ELF)
2273 targetm
.asm_out
.named_section (sect
->named
.name
,
2274 sect
->named
.common
.flags
2278 #elif defined (TARGET_PECOFF)
2279 /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
2280 Therefore the following check is used.
2281 In case a the target is PE or COFF a comdat group section
2282 is created, e.g. .vtable_map_vars$foo. The linker places
2283 everything in .vtable_map_vars at the end.
2285 A fix could be made in
2286 gcc/config/i386/winnt.c: i386_pe_unique_section. */
2291 if (TREE_CODE (DECL_NAME (decl
)) == IDENTIFIER_NODE
)
2292 name
= ACONCAT ((sect
->named
.name
, "$",
2293 IDENTIFIER_POINTER (DECL_NAME (decl
)), NULL
));
2295 name
= ACONCAT ((sect
->named
.name
, "$",
2296 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl
))),
2299 targetm
.asm_out
.named_section (name
,
2300 sect
->named
.common
.flags
2306 switch_to_section (sect
);
2310 switch_to_section (sect
);
2311 if (align
> BITS_PER_UNIT
)
2312 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2313 assemble_variable_contents (decl
, name
, dont_output_data
);
2316 unsigned HOST_WIDE_INT
int size
2317 = tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2318 assemble_zeros (asan_red_zone_size (size
));
2324 /* Given a function declaration (FN_DECL), this function assembles the
2325 function into the .preinit_array section. */
2328 assemble_vtv_preinit_initializer (tree fn_decl
)
2331 unsigned flags
= SECTION_WRITE
;
2332 rtx symbol
= XEXP (DECL_RTL (fn_decl
), 0);
2334 flags
|= SECTION_NOTYPE
;
2335 sect
= get_section (".preinit_array", flags
, fn_decl
);
2336 switch_to_section (sect
);
2337 assemble_addr_to_section (symbol
, sect
);
2340 /* Return 1 if type TYPE contains any pointers. */
2343 contains_pointers_p (tree type
)
2345 switch (TREE_CODE (type
))
2348 case REFERENCE_TYPE
:
2349 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2350 so I'll play safe and return 1. */
2356 case QUAL_UNION_TYPE
:
2359 /* For a type that has fields, see if the fields have pointers. */
2360 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
2361 if (TREE_CODE (fields
) == FIELD_DECL
2362 && contains_pointers_p (TREE_TYPE (fields
)))
2368 /* An array type contains pointers if its element type does. */
2369 return contains_pointers_p (TREE_TYPE (type
));
2376 /* We delay assemble_external processing until
2377 the compilation unit is finalized. This is the best we can do for
2378 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2379 it all the way to final. See PR 17982 for further discussion. */
2380 static GTY(()) tree pending_assemble_externals
;
2382 #ifdef ASM_OUTPUT_EXTERNAL
2383 /* Some targets delay some output to final using TARGET_ASM_FILE_END.
2384 As a result, assemble_external can be called after the list of externals
2385 is processed and the pointer set destroyed. */
2386 static bool pending_assemble_externals_processed
;
2388 /* Avoid O(external_decls**2) lookups in the pending_assemble_externals
2389 TREE_LIST in assemble_external. */
2390 static hash_set
<tree
> *pending_assemble_externals_set
;
2392 /* True if DECL is a function decl for which no out-of-line copy exists.
2393 It is assumed that DECL's assembler name has been set. */
2396 incorporeal_function_p (tree decl
)
2398 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2402 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2403 && (DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
2404 || DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA_WITH_ALIGN
))
2407 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2408 /* Atomic or sync builtins which have survived this far will be
2409 resolved externally and therefore are not incorporeal. */
2410 if (strncmp (name
, "__builtin_", 10) == 0)
2416 /* Actually do the tests to determine if this is necessary, and invoke
2417 ASM_OUTPUT_EXTERNAL. */
2419 assemble_external_real (tree decl
)
2421 rtx rtl
= DECL_RTL (decl
);
2423 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2424 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2425 && !incorporeal_function_p (decl
))
2427 /* Some systems do require some output. */
2428 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2429 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2435 process_pending_assemble_externals (void)
2437 #ifdef ASM_OUTPUT_EXTERNAL
2439 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2440 assemble_external_real (TREE_VALUE (list
));
2442 pending_assemble_externals
= 0;
2443 pending_assemble_externals_processed
= true;
2444 delete pending_assemble_externals_set
;
2448 /* This TREE_LIST contains any weak symbol declarations waiting
2450 static GTY(()) tree weak_decls
;
2452 /* Output something to declare an external symbol to the assembler,
2453 and qualifiers such as weakness. (Most assemblers don't need
2454 extern declaration, so we normally output nothing.) Do nothing if
2455 DECL is not external. */
2458 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2460 /* Make sure that the ASM_OUT_FILE is open.
2461 If it's not, we should not be calling this function. */
2462 gcc_assert (asm_out_file
);
2464 /* In a perfect world, the following condition would be true.
2465 Sadly, the Java and Go front ends emit assembly *from the front end*,
2466 bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2468 /* This function should only be called if we are expanding, or have
2470 Ideally, only final.c would be calling this function, but it is
2471 not clear whether that would break things somehow. See PR 17982
2472 for further discussion. */
2473 gcc_assert (state
== EXPANSION
2474 || state
== FINISHED
);
2477 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2480 /* We want to output annotation for weak and external symbols at
2481 very last to check if they are references or not. */
2483 if (TARGET_SUPPORTS_WEAK
2485 /* TREE_STATIC is a weird and abused creature which is not
2486 generally the right test for whether an entity has been
2487 locally emitted, inlined or otherwise not-really-extern, but
2488 for declarations that can be weak, it happens to be
2490 && !TREE_STATIC (decl
)
2491 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2492 && value_member (decl
, weak_decls
) == NULL_TREE
)
2493 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2495 #ifdef ASM_OUTPUT_EXTERNAL
2496 if (pending_assemble_externals_processed
)
2498 assemble_external_real (decl
);
2502 if (! pending_assemble_externals_set
->add (decl
))
2503 pending_assemble_externals
= tree_cons (NULL
, decl
,
2504 pending_assemble_externals
);
2508 /* Similar, for calling a library function FUN. */
2511 assemble_external_libcall (rtx fun
)
2513 /* Declare library function name external when first used, if nec. */
2514 if (! SYMBOL_REF_USED (fun
))
2516 SYMBOL_REF_USED (fun
) = 1;
2517 targetm
.asm_out
.external_libcall (fun
);
2521 /* Assemble a label named NAME. */
2524 assemble_label (FILE *file
, const char *name
)
2526 ASM_OUTPUT_LABEL (file
, name
);
2529 /* Set the symbol_referenced flag for ID. */
2531 mark_referenced (tree id
)
2533 TREE_SYMBOL_REFERENCED (id
) = 1;
2536 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2538 mark_decl_referenced (tree decl
)
2540 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2542 /* Extern inline functions don't become needed when referenced.
2543 If we know a method will be emitted in other TU and no new
2544 functions can be marked reachable, just use the external
2546 struct cgraph_node
*node
= cgraph_node::get_create (decl
);
2547 if (!DECL_EXTERNAL (decl
)
2548 && !node
->definition
)
2549 node
->mark_force_output ();
2551 else if (TREE_CODE (decl
) == VAR_DECL
)
2553 varpool_node
*node
= varpool_node::get_create (decl
);
2554 /* C++ frontend use mark_decl_references to force COMDAT variables
2555 to be output that might appear dead otherwise. */
2556 node
->force_output
= true;
2558 /* else do nothing - we can get various sorts of CST nodes here,
2559 which do not need to be marked. */
2563 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2564 starts with a *, the rest of NAME is output verbatim. Otherwise
2565 NAME is transformed in a target-specific way (usually by the
2566 addition of an underscore). */
2569 assemble_name_raw (FILE *file
, const char *name
)
2572 fputs (&name
[1], file
);
2574 ASM_OUTPUT_LABELREF (file
, name
);
2577 /* Like assemble_name_raw, but should be used when NAME might refer to
2578 an entity that is also represented as a tree (like a function or
2579 variable). If NAME does refer to such an entity, that entity will
2580 be marked as referenced. */
2583 assemble_name (FILE *file
, const char *name
)
2585 const char *real_name
;
2588 real_name
= targetm
.strip_name_encoding (name
);
2590 id
= maybe_get_identifier (real_name
);
2595 mark_referenced (id
);
2596 ultimate_transparent_alias_target (&id
);
2598 name
= IDENTIFIER_POINTER (id
);
2599 gcc_assert (! TREE_CHAIN (id
));
2602 assemble_name_raw (file
, name
);
2605 /* Allocate SIZE bytes writable static space with a gensym name
2606 and return an RTX to refer to its address. */
2609 assemble_static_space (unsigned HOST_WIDE_INT size
)
2612 const char *namestring
;
2615 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2617 namestring
= ggc_strdup (name
);
2619 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2620 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2622 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2623 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2626 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2627 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2630 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2631 so that each uninitialized object starts on such a boundary. */
2632 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2633 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2634 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2635 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2636 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2637 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2644 /* Assemble the static constant template for function entry trampolines.
2645 This is done at most once per compilation.
2646 Returns an RTX for the address of the template. */
2648 static GTY(()) rtx initial_trampoline
;
2651 assemble_trampoline_template (void)
2658 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2660 if (initial_trampoline
)
2661 return initial_trampoline
;
2663 /* By default, put trampoline templates in read-only data section. */
2665 #ifdef TRAMPOLINE_SECTION
2666 switch_to_section (TRAMPOLINE_SECTION
);
2668 switch_to_section (readonly_data_section
);
2671 /* Write the assembler code to define one. */
2672 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2674 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2676 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2677 targetm
.asm_out
.trampoline_template (asm_out_file
);
2679 /* Record the rtl to refer to it. */
2680 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2681 name
= ggc_strdup (label
);
2682 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2683 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2685 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2686 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2687 set_mem_size (initial_trampoline
, TRAMPOLINE_SIZE
);
2689 return initial_trampoline
;
2692 /* A and B are either alignments or offsets. Return the minimum alignment
2693 that may be assumed after adding the two together. */
2695 static inline unsigned
2696 min_align (unsigned int a
, unsigned int b
)
2698 return (a
| b
) & -(a
| b
);
2701 /* Return the assembler directive for creating a given kind of integer
2702 object. SIZE is the number of bytes in the object and ALIGNED_P
2703 indicates whether it is known to be aligned. Return NULL if the
2704 assembly dialect has no such directive.
2706 The returned string should be printed at the start of a new line and
2707 be followed immediately by the object's initial value. */
2710 integer_asm_op (int size
, int aligned_p
)
2712 struct asm_int_op
*ops
;
2715 ops
= &targetm
.asm_out
.aligned_op
;
2717 ops
= &targetm
.asm_out
.unaligned_op
;
2722 return targetm
.asm_out
.byte_op
;
2736 /* Use directive OP to assemble an integer object X. Print OP at the
2737 start of the line, followed immediately by the value of X. */
2740 assemble_integer_with_op (const char *op
, rtx x
)
2742 fputs (op
, asm_out_file
);
2743 output_addr_const (asm_out_file
, x
);
2744 fputc ('\n', asm_out_file
);
2747 /* The default implementation of the asm_out.integer target hook. */
2750 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2751 unsigned int size ATTRIBUTE_UNUSED
,
2752 int aligned_p ATTRIBUTE_UNUSED
)
2754 const char *op
= integer_asm_op (size
, aligned_p
);
2755 /* Avoid GAS bugs for large values. Specifically negative values whose
2756 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2757 if (size
> (unsigned int) UNITS_PER_WORD
2758 && size
> (unsigned int) POINTER_SIZE_UNITS
)
2760 return op
&& (assemble_integer_with_op (op
, x
), true);
2763 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2764 the alignment of the integer in bits. Return 1 if we were able to output
2765 the constant, otherwise 0. We must be able to output the constant,
2766 if FORCE is nonzero. */
2769 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2773 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2775 /* See if the target hook can handle this kind of object. */
2776 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2779 /* If the object is a multi-byte one, try splitting it up. Split
2780 it into words it if is multi-word, otherwise split it into bytes. */
2783 machine_mode omode
, imode
;
2784 unsigned int subalign
;
2785 unsigned int subsize
, i
;
2786 enum mode_class mclass
;
2788 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2789 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2790 if (GET_CODE (x
) == CONST_FIXED
)
2791 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2795 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2796 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2798 for (i
= 0; i
< size
; i
+= subsize
)
2800 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2801 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2807 /* If we've printed some of it, but not all of it, there's no going
2812 gcc_assert (!force
);
2818 assemble_real (REAL_VALUE_TYPE d
, machine_mode mode
, unsigned int align
)
2820 long data
[4] = {0, 0, 0, 0};
2822 int bitsize
, nelts
, nunits
, units_per
;
2824 /* This is hairy. We have a quantity of known size. real_to_target
2825 will put it into an array of *host* longs, 32 bits per element
2826 (even if long is more than 32 bits). We need to determine the
2827 number of array elements that are occupied (nelts) and the number
2828 of *target* min-addressable units that will be occupied in the
2829 object file (nunits). We cannot assume that 32 divides the
2830 mode's bitsize (size * BITS_PER_UNIT) evenly.
2832 size * BITS_PER_UNIT is used here to make sure that padding bits
2833 (which might appear at either end of the value; real_to_target
2834 will include the padding bits in its output array) are included. */
2836 nunits
= GET_MODE_SIZE (mode
);
2837 bitsize
= nunits
* BITS_PER_UNIT
;
2838 nelts
= CEIL (bitsize
, 32);
2839 units_per
= 32 / BITS_PER_UNIT
;
2841 real_to_target (data
, &d
, mode
);
2843 /* Put out the first word with the specified alignment. */
2844 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2845 nunits
-= units_per
;
2847 /* Subsequent words need only 32-bit alignment. */
2848 align
= min_align (align
, 32);
2850 for (i
= 1; i
< nelts
; i
++)
2852 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2853 nunits
-= units_per
;
2857 /* Given an expression EXP with a constant value,
2858 reduce it to the sum of an assembler symbol and an integer.
2859 Store them both in the structure *VALUE.
2860 EXP must be reducible. */
2864 HOST_WIDE_INT offset
;
2868 decode_addr_const (tree exp
, struct addr_const
*value
)
2870 tree target
= TREE_OPERAND (exp
, 0);
2876 if (TREE_CODE (target
) == COMPONENT_REF
2877 && tree_fits_shwi_p (byte_position (TREE_OPERAND (target
, 1))))
2879 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2880 target
= TREE_OPERAND (target
, 0);
2882 else if (TREE_CODE (target
) == ARRAY_REF
2883 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2885 offset
+= (tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (target
)))
2886 * tree_to_shwi (TREE_OPERAND (target
, 1)));
2887 target
= TREE_OPERAND (target
, 0);
2889 else if (TREE_CODE (target
) == MEM_REF
2890 && TREE_CODE (TREE_OPERAND (target
, 0)) == ADDR_EXPR
)
2892 offset
+= mem_ref_offset (target
).to_short_addr ();
2893 target
= TREE_OPERAND (TREE_OPERAND (target
, 0), 0);
2895 else if (TREE_CODE (target
) == INDIRECT_REF
2896 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2897 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2899 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2904 switch (TREE_CODE (target
))
2908 x
= DECL_RTL (target
);
2912 x
= gen_rtx_MEM (FUNCTION_MODE
,
2913 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2922 x
= output_constant_def (target
, 1);
2929 gcc_assert (MEM_P (x
));
2933 value
->offset
= offset
;
2936 static GTY(()) hash_table
<tree_descriptor_hasher
> *const_desc_htab
;
2938 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2940 /* Constant pool accessor function. */
2942 hash_table
<tree_descriptor_hasher
> *
2943 constant_pool_htab (void)
2945 return const_desc_htab
;
2948 /* Compute a hash code for a constant expression. */
2951 tree_descriptor_hasher::hash (constant_descriptor_tree
*ptr
)
2957 const_hash_1 (const tree exp
)
2962 enum tree_code code
= TREE_CODE (exp
);
2964 /* Either set P and LEN to the address and len of something to hash and
2965 exit the switch or return a value. */
2970 p
= (char *) &TREE_INT_CST_ELT (exp
, 0);
2971 len
= TREE_INT_CST_NUNITS (exp
) * sizeof (HOST_WIDE_INT
);
2975 return real_hash (TREE_REAL_CST_PTR (exp
));
2978 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2981 p
= TREE_STRING_POINTER (exp
);
2982 len
= TREE_STRING_LENGTH (exp
);
2986 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2987 + const_hash_1 (TREE_IMAGPART (exp
)));
2993 hi
= 7 + VECTOR_CST_NELTS (exp
);
2995 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
2996 hi
= hi
* 563 + const_hash_1 (VECTOR_CST_ELT (exp
, i
));
3003 unsigned HOST_WIDE_INT idx
;
3006 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
3008 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
3010 hi
= hi
* 603 + const_hash_1 (value
);
3018 struct addr_const value
;
3020 decode_addr_const (exp
, &value
);
3021 switch (GET_CODE (value
.base
))
3024 /* Don't hash the address of the SYMBOL_REF;
3025 only use the offset and the symbol name. */
3027 p
= XSTR (value
.base
, 0);
3028 for (i
= 0; p
[i
] != 0; i
++)
3029 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
3034 + CODE_LABEL_NUMBER (LABEL_REF_LABEL (value
.base
)) * 13);
3044 case POINTER_PLUS_EXPR
:
3046 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
3047 + const_hash_1 (TREE_OPERAND (exp
, 1)));
3050 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
3053 /* A language specific constant. Just hash the code. */
3057 /* Compute hashing function. */
3059 for (i
= 0; i
< len
; i
++)
3060 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
3065 /* Wrapper of compare_constant, for the htab interface. */
3067 tree_descriptor_hasher::equal (constant_descriptor_tree
*c1
,
3068 constant_descriptor_tree
*c2
)
3070 if (c1
->hash
!= c2
->hash
)
3072 return compare_constant (c1
->value
, c2
->value
);
3075 /* Compare t1 and t2, and return 1 only if they are known to result in
3076 the same bit pattern on output. */
3079 compare_constant (const tree t1
, const tree t2
)
3081 enum tree_code typecode
;
3083 if (t1
== NULL_TREE
)
3084 return t2
== NULL_TREE
;
3085 if (t2
== NULL_TREE
)
3088 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3091 switch (TREE_CODE (t1
))
3094 /* Integer constants are the same only if the same width of type. */
3095 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3097 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3099 return tree_int_cst_equal (t1
, t2
);
3102 /* Real constants are the same only if the same width of type. */
3103 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3106 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
3109 /* Fixed constants are the same only if the same width of type. */
3110 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3113 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
3116 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3119 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3120 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3121 TREE_STRING_LENGTH (t1
)));
3124 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
3125 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
3131 if (VECTOR_CST_NELTS (t1
) != VECTOR_CST_NELTS (t2
))
3134 for (i
= 0; i
< VECTOR_CST_NELTS (t1
); ++i
)
3135 if (!compare_constant (VECTOR_CST_ELT (t1
, i
),
3136 VECTOR_CST_ELT (t2
, i
)))
3144 vec
<constructor_elt
, va_gc
> *v1
, *v2
;
3145 unsigned HOST_WIDE_INT idx
;
3147 typecode
= TREE_CODE (TREE_TYPE (t1
));
3148 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3151 if (typecode
== ARRAY_TYPE
)
3153 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3154 /* For arrays, check that the sizes all match. */
3155 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3157 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
3162 /* For record and union constructors, require exact type
3164 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3168 v1
= CONSTRUCTOR_ELTS (t1
);
3169 v2
= CONSTRUCTOR_ELTS (t2
);
3170 if (vec_safe_length (v1
) != vec_safe_length (v2
))
3173 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
3175 constructor_elt
*c1
= &(*v1
)[idx
];
3176 constructor_elt
*c2
= &(*v2
)[idx
];
3178 /* Check that each value is the same... */
3179 if (!compare_constant (c1
->value
, c2
->value
))
3181 /* ... and that they apply to the same fields! */
3182 if (typecode
== ARRAY_TYPE
)
3184 if (!compare_constant (c1
->index
, c2
->index
))
3189 if (c1
->index
!= c2
->index
)
3200 struct addr_const value1
, value2
;
3204 decode_addr_const (t1
, &value1
);
3205 decode_addr_const (t2
, &value2
);
3207 if (value1
.offset
!= value2
.offset
)
3210 code
= GET_CODE (value1
.base
);
3211 if (code
!= GET_CODE (value2
.base
))
3217 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3221 ret
= (CODE_LABEL_NUMBER (LABEL_REF_LABEL (value1
.base
))
3222 == CODE_LABEL_NUMBER (LABEL_REF_LABEL (value2
.base
)));
3232 case POINTER_PLUS_EXPR
:
3235 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3236 && compare_constant (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3239 case VIEW_CONVERT_EXPR
:
3240 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3249 /* Return the section into which constant EXP should be placed. */
3252 get_constant_section (tree exp
, unsigned int align
)
3254 return targetm
.asm_out
.select_section (exp
,
3255 compute_reloc_for_constant (exp
),
3259 /* Return the size of constant EXP in bytes. */
3261 static HOST_WIDE_INT
3262 get_constant_size (tree exp
)
3266 size
= int_size_in_bytes (TREE_TYPE (exp
));
3267 if (TREE_CODE (exp
) == STRING_CST
)
3268 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3272 /* Subroutine of output_constant_def:
3273 No constant equal to EXP is known to have been output.
3274 Make a constant descriptor to enter EXP in the hash table.
3275 Assign the label number and construct RTL to refer to the
3276 constant's location in memory.
3277 Caller is responsible for updating the hash table. */
3279 static struct constant_descriptor_tree
*
3280 build_constant_desc (tree exp
)
3282 struct constant_descriptor_tree
*desc
;
3288 desc
= ggc_alloc
<constant_descriptor_tree
> ();
3291 /* Create a string containing the label name, in LABEL. */
3292 labelno
= const_labelno
++;
3293 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3295 /* Construct the VAR_DECL associated with the constant. */
3296 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3298 DECL_ARTIFICIAL (decl
) = 1;
3299 DECL_IGNORED_P (decl
) = 1;
3300 TREE_READONLY (decl
) = 1;
3301 TREE_STATIC (decl
) = 1;
3302 TREE_ADDRESSABLE (decl
) = 1;
3303 /* We don't set the RTL yet as this would cause varpool to assume that the
3304 variable is referenced. Moreover, it would just be dropped in LTO mode.
3305 Instead we set the flag that will be recognized in make_decl_rtl. */
3306 DECL_IN_CONSTANT_POOL (decl
) = 1;
3307 DECL_INITIAL (decl
) = desc
->value
;
3308 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3309 architectures so use DATA_ALIGNMENT as well, except for strings. */
3310 if (TREE_CODE (exp
) == STRING_CST
)
3312 #ifdef CONSTANT_ALIGNMENT
3313 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
3317 align_variable (decl
, 0);
3319 /* Now construct the SYMBOL_REF and the MEM. */
3320 if (use_object_blocks_p ())
3322 int align
= (TREE_CODE (decl
) == CONST_DECL
3323 || (TREE_CODE (decl
) == VAR_DECL
3324 && DECL_IN_CONSTANT_POOL (decl
))
3326 : symtab_node::get (decl
)->definition_alignment ());
3327 section
*sect
= get_constant_section (exp
, align
);
3328 symbol
= create_block_symbol (ggc_strdup (label
),
3329 get_block_for_section (sect
), -1);
3332 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3333 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3334 SET_SYMBOL_REF_DECL (symbol
, decl
);
3335 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3337 rtl
= gen_const_mem (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3338 set_mem_attributes (rtl
, exp
, 1);
3339 set_mem_alias_set (rtl
, 0);
3341 /* We cannot share RTX'es in pool entries.
3342 Mark this piece of RTL as required for unsharing. */
3343 RTX_FLAG (rtl
, used
) = 1;
3345 /* Set flags or add text to the name to record information, such as
3346 that it is a local symbol. If the name is changed, the macro
3347 ASM_OUTPUT_LABELREF will have to know how to strip this
3348 information. This call might invalidate our local variable
3349 SYMBOL; we can't use it afterward. */
3350 targetm
.encode_section_info (exp
, rtl
, true);
3357 /* Return an rtx representing a reference to constant data in memory
3358 for the constant expression EXP.
3360 If assembler code for such a constant has already been output,
3361 return an rtx to refer to it.
3362 Otherwise, output such a constant in memory
3363 and generate an rtx for it.
3365 If DEFER is nonzero, this constant can be deferred and output only
3366 if referenced in the function after all optimizations.
3368 `const_desc_table' records which constants already have label strings. */
3371 output_constant_def (tree exp
, int defer
)
3373 struct constant_descriptor_tree
*desc
;
3374 struct constant_descriptor_tree key
;
3376 /* Look up EXP in the table of constant descriptors. If we didn't find
3377 it, create a new one. */
3379 key
.hash
= const_hash_1 (exp
);
3380 constant_descriptor_tree
**loc
3381 = const_desc_htab
->find_slot_with_hash (&key
, key
.hash
, INSERT
);
3386 desc
= build_constant_desc (exp
);
3387 desc
->hash
= key
.hash
;
3391 maybe_output_constant_def_contents (desc
, defer
);
3395 /* Subroutine of output_constant_def: Decide whether or not we need to
3396 output the constant DESC now, and if so, do it. */
3398 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3401 rtx symbol
= XEXP (desc
->rtl
, 0);
3402 tree exp
= desc
->value
;
3404 if (flag_syntax_only
)
3407 if (TREE_ASM_WRITTEN (exp
))
3408 /* Already output; don't do it again. */
3411 /* We can always defer constants as long as the context allows
3415 /* Increment n_deferred_constants if it exists. It needs to be at
3416 least as large as the number of constants actually referred to
3417 by the function. If it's too small we'll stop looking too early
3418 and fail to emit constants; if it's too large we'll only look
3419 through the entire function when we could have stopped earlier. */
3421 n_deferred_constants
++;
3425 output_constant_def_contents (symbol
);
3428 /* Subroutine of output_constant_def_contents. Output the definition
3429 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3430 constant's alignment in bits. */
3433 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3437 size
= get_constant_size (exp
);
3439 /* Do any machine/system dependent processing of the constant. */
3440 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3442 /* Output the value of EXP. */
3443 output_constant (exp
, size
, align
);
3445 targetm
.asm_out
.decl_end ();
3448 /* We must output the constant data referred to by SYMBOL; do so. */
3451 output_constant_def_contents (rtx symbol
)
3453 tree decl
= SYMBOL_REF_DECL (symbol
);
3454 tree exp
= DECL_INITIAL (decl
);
3455 bool asan_protected
= false;
3457 /* Make sure any other constants whose addresses appear in EXP
3458 are assigned label numbers. */
3459 output_addressed_constants (exp
);
3461 /* We are no longer deferring this constant. */
3462 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3464 if ((flag_sanitize
& SANITIZE_ADDRESS
)
3465 && TREE_CODE (exp
) == STRING_CST
3466 && asan_protect_global (exp
))
3468 asan_protected
= true;
3469 DECL_ALIGN (decl
) = MAX (DECL_ALIGN (decl
),
3470 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
3473 /* If the constant is part of an object block, make sure that the
3474 decl has been positioned within its block, but do not write out
3475 its definition yet. output_object_blocks will do that later. */
3476 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3477 place_block_symbol (symbol
);
3480 int align
= (TREE_CODE (decl
) == CONST_DECL
3481 || (TREE_CODE (decl
) == VAR_DECL
3482 && DECL_IN_CONSTANT_POOL (decl
))
3484 : symtab_node::get (decl
)->definition_alignment ());
3485 switch_to_section (get_constant_section (exp
, align
));
3486 if (align
> BITS_PER_UNIT
)
3487 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3488 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3491 HOST_WIDE_INT size
= get_constant_size (exp
);
3492 assemble_zeros (asan_red_zone_size (size
));
3497 /* Look up EXP in the table of constant descriptors. Return the rtl
3498 if it has been emitted, else null. */
3501 lookup_constant_def (tree exp
)
3503 struct constant_descriptor_tree key
;
3506 key
.hash
= const_hash_1 (exp
);
3507 constant_descriptor_tree
*desc
3508 = const_desc_htab
->find_with_hash (&key
, key
.hash
);
3510 return (desc
? desc
->rtl
: NULL_RTX
);
3513 /* Return a tree representing a reference to constant data in memory
3514 for the constant expression EXP.
3516 This is the counterpart of output_constant_def at the Tree level. */
3519 tree_output_constant_def (tree exp
)
3521 struct constant_descriptor_tree
*desc
, key
;
3524 /* Look up EXP in the table of constant descriptors. If we didn't find
3525 it, create a new one. */
3527 key
.hash
= const_hash_1 (exp
);
3528 constant_descriptor_tree
**loc
3529 = const_desc_htab
->find_slot_with_hash (&key
, key
.hash
, INSERT
);
3534 desc
= build_constant_desc (exp
);
3535 desc
->hash
= key
.hash
;
3539 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3540 varpool_node::finalize_decl (decl
);
3544 struct GTY((chain_next ("%h.next"), for_user
)) constant_descriptor_rtx
{
3545 struct constant_descriptor_rtx
*next
;
3549 HOST_WIDE_INT offset
;
3557 struct const_rtx_desc_hasher
: ggc_hasher
<constant_descriptor_rtx
*>
3559 static hashval_t
hash (constant_descriptor_rtx
*);
3560 static bool equal (constant_descriptor_rtx
*, constant_descriptor_rtx
*);
3563 /* Used in the hash tables to avoid outputting the same constant
3564 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3565 are output once per function, not once per file. */
3566 /* ??? Only a few targets need per-function constant pools. Most
3567 can use one per-file pool. Should add a targetm bit to tell the
3570 struct GTY(()) rtx_constant_pool
{
3571 /* Pointers to first and last constant in pool, as ordered by offset. */
3572 struct constant_descriptor_rtx
*first
;
3573 struct constant_descriptor_rtx
*last
;
3575 /* Hash facility for making memory-constants from constant rtl-expressions.
3576 It is used on RISC machines where immediate integer arguments and
3577 constant addresses are restricted so that such constants must be stored
3579 hash_table
<const_rtx_desc_hasher
> *const_rtx_htab
;
3581 /* Current offset in constant pool (does not include any
3582 machine-specific header). */
3583 HOST_WIDE_INT offset
;
3586 /* Hash and compare functions for const_rtx_htab. */
3589 const_rtx_desc_hasher::hash (constant_descriptor_rtx
*desc
)
3595 const_rtx_desc_hasher::equal (constant_descriptor_rtx
*x
,
3596 constant_descriptor_rtx
*y
)
3598 if (x
->mode
!= y
->mode
)
3600 return rtx_equal_p (x
->constant
, y
->constant
);
3603 /* Hash one component of a constant. */
3606 const_rtx_hash_1 (const_rtx x
)
3608 unsigned HOST_WIDE_INT hwi
;
3614 code
= GET_CODE (x
);
3615 mode
= GET_MODE (x
);
3616 h
= (hashval_t
) code
* 1048573 + mode
;
3625 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3626 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3628 h
^= (hashval_t
) hwi
;
3629 for (i
= 1; i
< n
; ++i
)
3632 h
^= (hashval_t
) hwi
;
3637 case CONST_WIDE_INT
:
3638 hwi
= GET_MODE_PRECISION (mode
);
3640 for (i
= 0; i
< CONST_WIDE_INT_NUNITS (x
); i
++)
3641 hwi
^= CONST_WIDE_INT_ELT (x
, i
);
3646 if (TARGET_SUPPORTS_WIDE_INT
== 0 && mode
== VOIDmode
)
3648 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3652 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3656 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3660 h
^= htab_hash_string (XSTR (x
, 0));
3664 h
= h
* 251 + CODE_LABEL_NUMBER (LABEL_REF_LABEL (x
));
3668 case UNSPEC_VOLATILE
:
3669 h
= h
* 251 + XINT (x
, 1);
3679 /* Compute a hash value for X, which should be a constant. */
3682 const_rtx_hash (rtx x
)
3685 subrtx_iterator::array_type array
;
3686 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
3687 h
= h
* 509 + const_rtx_hash_1 (*iter
);
3692 /* Create and return a new rtx constant pool. */
3694 static struct rtx_constant_pool
*
3695 create_constant_pool (void)
3697 struct rtx_constant_pool
*pool
;
3699 pool
= ggc_alloc
<rtx_constant_pool
> ();
3700 pool
->const_rtx_htab
= hash_table
<const_rtx_desc_hasher
>::create_ggc (31);
3707 /* Initialize constant pool hashing for a new function. */
3710 init_varasm_status (void)
3712 crtl
->varasm
.pool
= create_constant_pool ();
3713 crtl
->varasm
.deferred_constants
= 0;
3716 /* Given a MINUS expression, simplify it if both sides
3717 include the same symbol. */
3720 simplify_subtraction (rtx x
)
3722 rtx r
= simplify_rtx (x
);
3726 /* Given a constant rtx X, make (or find) a memory constant for its value
3727 and return a MEM rtx to refer to it in memory. */
3730 force_const_mem (machine_mode mode
, rtx x
)
3732 struct constant_descriptor_rtx
*desc
, tmp
;
3733 struct rtx_constant_pool
*pool
;
3738 constant_descriptor_rtx
**slot
;
3740 /* If we're not allowed to drop X into the constant pool, don't. */
3741 if (targetm
.cannot_force_const_mem (mode
, x
))
3744 /* Record that this function has used a constant pool entry. */
3745 crtl
->uses_const_pool
= 1;
3747 /* Decide which pool to use. */
3748 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3749 ? shared_constant_pool
3750 : crtl
->varasm
.pool
);
3752 /* Lookup the value in the hashtable. */
3755 hash
= const_rtx_hash (x
);
3756 slot
= pool
->const_rtx_htab
->find_slot_with_hash (&tmp
, hash
, INSERT
);
3759 /* If the constant was already present, return its memory. */
3761 return copy_rtx (desc
->mem
);
3763 /* Otherwise, create a new descriptor. */
3764 desc
= ggc_alloc
<constant_descriptor_rtx
> ();
3767 /* Align the location counter as required by EXP's data type. */
3768 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3769 #ifdef CONSTANT_ALIGNMENT
3771 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3772 if (type
!= NULL_TREE
)
3773 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3777 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3778 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3781 desc
->constant
= copy_rtx (tmp
.constant
);
3782 desc
->offset
= pool
->offset
;
3785 desc
->align
= align
;
3786 desc
->labelno
= const_labelno
;
3789 pool
->offset
+= GET_MODE_SIZE (mode
);
3791 pool
->last
->next
= desc
;
3793 pool
->first
= pool
->last
= desc
;
3796 /* Create a string containing the label name, in LABEL. */
3797 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3800 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3801 the constants pool. */
3802 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3804 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3805 symbol
= create_block_symbol (ggc_strdup (label
),
3806 get_block_for_section (sect
), -1);
3809 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3811 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3812 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3813 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3815 /* Construct the MEM. */
3816 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3817 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3818 set_mem_align (def
, align
);
3820 /* If we're dropping a label to the constant pool, make sure we
3822 if (GET_CODE (x
) == LABEL_REF
)
3823 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3825 return copy_rtx (def
);
3828 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3831 get_pool_constant (const_rtx addr
)
3833 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3836 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3837 and whether it has been output or not. */
3840 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3842 struct constant_descriptor_rtx
*desc
;
3844 desc
= SYMBOL_REF_CONSTANT (addr
);
3845 *pmarked
= (desc
->mark
!= 0);
3846 return desc
->constant
;
3849 /* Similar, return the mode. */
3852 get_pool_mode (const_rtx addr
)
3854 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3857 /* Return the size of the constant pool. */
3860 get_pool_size (void)
3862 return crtl
->varasm
.pool
->offset
;
3865 /* Worker function for output_constant_pool_1. Emit assembly for X
3866 in MODE with known alignment ALIGN. */
3869 output_constant_pool_2 (machine_mode mode
, rtx x
, unsigned int align
)
3871 switch (GET_MODE_CLASS (mode
))
3874 case MODE_DECIMAL_FLOAT
:
3878 gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x
));
3879 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3880 assemble_real (r
, mode
, align
);
3885 case MODE_PARTIAL_INT
:
3890 case MODE_POINTER_BOUNDS
:
3891 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3894 case MODE_VECTOR_FLOAT
:
3895 case MODE_VECTOR_INT
:
3896 case MODE_VECTOR_FRACT
:
3897 case MODE_VECTOR_UFRACT
:
3898 case MODE_VECTOR_ACCUM
:
3899 case MODE_VECTOR_UACCUM
:
3902 machine_mode submode
= GET_MODE_INNER (mode
);
3903 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3905 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3906 units
= CONST_VECTOR_NUNITS (x
);
3908 for (i
= 0; i
< units
; i
++)
3910 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3911 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3921 /* Worker function for output_constant_pool. Emit constant DESC,
3922 giving it ALIGN bits of alignment. */
3925 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3932 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3933 whose CODE_LABEL has been deleted. This can occur if a jump table
3934 is eliminated by optimization. If so, write a constant of zero
3935 instead. Note that this can also happen by turning the
3936 CODE_LABEL into a NOTE. */
3937 /* ??? This seems completely and utterly wrong. Certainly it's
3938 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3939 functioning even with rtx_insn::deleted and friends. */
3942 switch (GET_CODE (tmp
))
3945 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3946 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3948 tmp
= XEXP (XEXP (tmp
, 0), 0);
3952 tmp
= LABEL_REF_LABEL (tmp
);
3953 gcc_assert (!as_a
<rtx_insn
*> (tmp
)->deleted ());
3954 gcc_assert (!NOTE_P (tmp
)
3955 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3962 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3963 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3964 align
, desc
->labelno
, done
);
3967 assemble_align (align
);
3969 /* Output the label. */
3970 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3972 /* Output the data. */
3973 output_constant_pool_2 (desc
->mode
, x
, align
);
3975 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3976 sections have proper size. */
3977 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3979 && (in_section
->common
.flags
& SECTION_MERGE
))
3980 assemble_align (align
);
3982 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3988 /* Mark all constants that are referenced by SYMBOL_REFs in X.
3989 Emit referenced deferred strings. */
3992 mark_constants_in_pattern (rtx insn
)
3994 subrtx_iterator::array_type array
;
3995 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), ALL
)
3997 const_rtx x
= *iter
;
3998 if (GET_CODE (x
) == SYMBOL_REF
)
4000 if (CONSTANT_POOL_ADDRESS_P (x
))
4002 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
4003 if (desc
->mark
== 0)
4006 iter
.substitute (desc
->constant
);
4009 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
4011 tree decl
= SYMBOL_REF_DECL (x
);
4012 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
4014 n_deferred_constants
--;
4015 output_constant_def_contents (CONST_CAST_RTX (x
));
4022 /* Look through appropriate parts of INSN, marking all entries in the
4023 constant pool which are actually being used. Entries that are only
4024 referenced by other constants are also marked as used. Emit
4025 deferred strings that are used. */
4028 mark_constants (rtx_insn
*insn
)
4033 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4034 insns, not any notes that may be attached. We don't want to mark
4035 a constant just because it happens to appear in a REG_EQUIV note. */
4036 if (rtx_sequence
*seq
= dyn_cast
<rtx_sequence
*> (PATTERN (insn
)))
4038 int i
, n
= seq
->len ();
4039 for (i
= 0; i
< n
; ++i
)
4041 rtx subinsn
= seq
->element (i
);
4042 if (INSN_P (subinsn
))
4043 mark_constants_in_pattern (subinsn
);
4047 mark_constants_in_pattern (insn
);
4050 /* Look through the instructions for this function, and mark all the
4051 entries in POOL which are actually being used. Emit deferred constants
4052 which have indeed been used. */
4055 mark_constant_pool (void)
4059 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
4062 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4063 mark_constants (insn
);
4066 /* Write all the constants in POOL. */
4069 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
4071 struct constant_descriptor_rtx
*desc
;
4073 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
4076 /* If the constant is part of an object_block, make sure that
4077 the constant has been positioned within its block, but do not
4078 write out its definition yet. output_object_blocks will do
4080 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
4081 && SYMBOL_REF_BLOCK (desc
->sym
))
4082 place_block_symbol (desc
->sym
);
4085 switch_to_section (targetm
.asm_out
.select_rtx_section
4086 (desc
->mode
, desc
->constant
, desc
->align
));
4087 output_constant_pool_1 (desc
, desc
->align
);
4092 /* Mark all constants that are used in the current function, then write
4093 out the function's private constant pool. */
4096 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
4097 tree fndecl ATTRIBUTE_UNUSED
)
4099 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
4101 /* It is possible for gcc to call force_const_mem and then to later
4102 discard the instructions which refer to the constant. In such a
4103 case we do not need to output the constant. */
4104 mark_constant_pool ();
4106 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4107 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4110 output_constant_pool_contents (pool
);
4112 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4113 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4117 /* Write the contents of the shared constant pool. */
4120 output_shared_constant_pool (void)
4122 output_constant_pool_contents (shared_constant_pool
);
4125 /* Determine what kind of relocations EXP may need. */
4128 compute_reloc_for_constant (tree exp
)
4130 int reloc
= 0, reloc2
;
4133 switch (TREE_CODE (exp
))
4137 /* Go inside any operations that get_inner_reference can handle and see
4138 if what's inside is a constant: no need to do anything here for
4139 addresses of variables or functions. */
4140 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4141 tem
= TREE_OPERAND (tem
, 0))
4144 if (TREE_CODE (tem
) == MEM_REF
4145 && TREE_CODE (TREE_OPERAND (tem
, 0)) == ADDR_EXPR
)
4147 reloc
= compute_reloc_for_constant (TREE_OPERAND (tem
, 0));
4151 if (!targetm
.binds_local_p (tem
))
4158 case POINTER_PLUS_EXPR
:
4159 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4160 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4164 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4165 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4166 /* The difference of two local labels is computable at link time. */
4167 if (reloc
== 1 && reloc2
== 1)
4174 case VIEW_CONVERT_EXPR
:
4175 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4180 unsigned HOST_WIDE_INT idx
;
4181 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4183 reloc
|= compute_reloc_for_constant (tem
);
4193 /* Find all the constants whose addresses are referenced inside of EXP,
4194 and make sure assembler code with a label has been output for each one.
4195 Indicate whether an ADDR_EXPR has been encountered. */
4198 output_addressed_constants (tree exp
)
4202 switch (TREE_CODE (exp
))
4206 /* Go inside any operations that get_inner_reference can handle and see
4207 if what's inside is a constant: no need to do anything here for
4208 addresses of variables or functions. */
4209 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4210 tem
= TREE_OPERAND (tem
, 0))
4213 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4214 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4215 tem
= DECL_INITIAL (tem
);
4217 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4218 output_constant_def (tem
, 0);
4220 if (TREE_CODE (tem
) == MEM_REF
)
4221 output_addressed_constants (TREE_OPERAND (tem
, 0));
4225 case POINTER_PLUS_EXPR
:
4227 output_addressed_constants (TREE_OPERAND (exp
, 1));
4231 case VIEW_CONVERT_EXPR
:
4232 output_addressed_constants (TREE_OPERAND (exp
, 0));
4237 unsigned HOST_WIDE_INT idx
;
4238 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4240 output_addressed_constants (tem
);
4249 /* Whether a constructor CTOR is a valid static constant initializer if all
4250 its elements are. This used to be internal to initializer_constant_valid_p
4251 and has been exposed to let other functions like categorize_ctor_elements
4252 evaluate the property while walking a constructor for other purposes. */
4255 constructor_static_from_elts_p (const_tree ctor
)
4257 return (TREE_CONSTANT (ctor
)
4258 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4259 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
4260 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
4263 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4266 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4267 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4268 which are valid when ENDTYPE is an integer of any size; in
4269 particular, this does not accept a pointer minus a constant. This
4270 returns null_pointer_node if the VALUE is an absolute constant
4271 which can be used to initialize a static variable. Otherwise it
4275 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4279 if (!INTEGRAL_TYPE_P (endtype
))
4282 op0
= TREE_OPERAND (value
, 0);
4283 op1
= TREE_OPERAND (value
, 1);
4285 /* Like STRIP_NOPS except allow the operand mode to widen. This
4286 works around a feature of fold that simplifies (int)(p1 - p2) to
4287 ((int)p1 - (int)p2) under the theory that the narrower operation
4290 while (CONVERT_EXPR_P (op0
)
4291 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4293 tree inner
= TREE_OPERAND (op0
, 0);
4294 if (inner
== error_mark_node
4295 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4296 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4297 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4302 while (CONVERT_EXPR_P (op1
)
4303 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4305 tree inner
= TREE_OPERAND (op1
, 0);
4306 if (inner
== error_mark_node
4307 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4308 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4309 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4314 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4318 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4319 cache
? cache
+ 2 : NULL
);
4320 /* Both initializers must be known. */
4324 && (op0
== null_pointer_node
4325 || TREE_CODE (value
) == MINUS_EXPR
))
4326 return null_pointer_node
;
4328 /* Support differences between labels. */
4329 if (TREE_CODE (op0
) == LABEL_DECL
4330 && TREE_CODE (op1
) == LABEL_DECL
)
4331 return null_pointer_node
;
4333 if (TREE_CODE (op0
) == STRING_CST
4334 && TREE_CODE (op1
) == STRING_CST
4335 && operand_equal_p (op0
, op1
, 1))
4336 return null_pointer_node
;
4342 /* Helper function of initializer_constant_valid_p.
4343 Return nonzero if VALUE is a valid constant-valued expression
4344 for use in initializing a static variable; one that can be an
4345 element of a "constant" initializer.
4347 Return null_pointer_node if the value is absolute;
4348 if it is relocatable, return the variable that determines the relocation.
4349 We assume that VALUE has been folded as much as possible;
4350 therefore, we do not need to check for such things as
4351 arithmetic-combinations of integers.
4353 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4356 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4360 switch (TREE_CODE (value
))
4363 if (constructor_static_from_elts_p (value
))
4365 unsigned HOST_WIDE_INT idx
;
4367 bool absolute
= true;
4369 if (cache
&& cache
[0] == value
)
4371 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4374 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4381 cache
[1] = NULL_TREE
;
4385 if (reloc
!= null_pointer_node
)
4388 /* For a non-absolute relocation, there is no single
4389 variable that can be "the variable that determines the
4394 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4396 return absolute
? null_pointer_node
: error_mark_node
;
4399 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4407 return null_pointer_node
;
4412 tree op0
= staticp (TREE_OPERAND (value
, 0));
4415 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4416 to be a constant, this is old-skool offsetof-like nonsense. */
4417 if (TREE_CODE (op0
) == INDIRECT_REF
4418 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4419 return null_pointer_node
;
4420 /* Taking the address of a nested function involves a trampoline,
4421 unless we don't need or want one. */
4422 if (TREE_CODE (op0
) == FUNCTION_DECL
4423 && DECL_STATIC_CHAIN (op0
)
4424 && !TREE_NO_TRAMPOLINE (value
))
4426 /* "&{...}" requires a temporary to hold the constructed
4428 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4434 case NON_LVALUE_EXPR
:
4435 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4438 case VIEW_CONVERT_EXPR
:
4440 tree src
= TREE_OPERAND (value
, 0);
4441 tree src_type
= TREE_TYPE (src
);
4442 tree dest_type
= TREE_TYPE (value
);
4444 /* Allow view-conversions from aggregate to non-aggregate type only
4445 if the bit pattern is fully preserved afterwards; otherwise, the
4446 RTL expander won't be able to apply a subsequent transformation
4447 to the underlying constructor. */
4448 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4450 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4451 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4456 /* Allow all other kinds of view-conversion. */
4457 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4462 tree src
= TREE_OPERAND (value
, 0);
4463 tree src_type
= TREE_TYPE (src
);
4464 tree dest_type
= TREE_TYPE (value
);
4466 /* Allow conversions between pointer types, floating-point
4467 types, and offset types. */
4468 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4469 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4470 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4471 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4472 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4474 /* Allow length-preserving conversions between integer types. */
4475 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4476 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4477 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4479 /* Allow conversions between other integer types only if
4481 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4483 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4484 if (inner
== null_pointer_node
)
4485 return null_pointer_node
;
4489 /* Allow (int) &foo provided int is as wide as a pointer. */
4490 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4491 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4492 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4494 /* Likewise conversions from int to pointers, but also allow
4495 conversions from 0. */
4496 if ((POINTER_TYPE_P (dest_type
)
4497 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4498 && INTEGRAL_TYPE_P (src_type
))
4500 if (TREE_CODE (src
) == INTEGER_CST
4501 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4502 return null_pointer_node
;
4503 if (integer_zerop (src
))
4504 return null_pointer_node
;
4505 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4506 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4509 /* Allow conversions to struct or union types if the value
4511 if (TREE_CODE (dest_type
) == RECORD_TYPE
4512 || TREE_CODE (dest_type
) == UNION_TYPE
)
4513 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4517 case POINTER_PLUS_EXPR
:
4519 /* Any valid floating-point constants will have been folded by now;
4520 with -frounding-math we hit this with addition of two constants. */
4521 if (TREE_CODE (endtype
) == REAL_TYPE
)
4523 if (cache
&& cache
[0] == value
)
4525 if (! INTEGRAL_TYPE_P (endtype
)
4526 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4528 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4530 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4533 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4534 endtype
, ncache
+ 2);
4535 /* If either term is absolute, use the other term's relocation. */
4536 if (valid0
== null_pointer_node
)
4538 else if (valid1
== null_pointer_node
)
4540 /* Support narrowing pointer differences. */
4542 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4546 /* Support narrowing pointer differences. */
4547 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4556 if (TREE_CODE (endtype
) == REAL_TYPE
)
4558 if (cache
&& cache
[0] == value
)
4560 if (! INTEGRAL_TYPE_P (endtype
)
4561 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4563 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4565 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4568 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4569 endtype
, ncache
+ 2);
4570 /* Win if second argument is absolute. */
4571 if (valid1
== null_pointer_node
)
4573 /* Win if both arguments have the same relocation.
4574 Then the value is absolute. */
4575 else if (valid0
== valid1
&& valid0
!= 0)
4576 ret
= null_pointer_node
;
4577 /* Since GCC guarantees that string constants are unique in the
4578 generated code, a subtraction between two copies of the same
4579 constant string is absolute. */
4580 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4581 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4582 && operand_equal_p (valid0
, valid1
, 1))
4583 ret
= null_pointer_node
;
4584 /* Support narrowing differences. */
4586 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4590 /* Support narrowing differences. */
4591 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4606 /* Return nonzero if VALUE is a valid constant-valued expression
4607 for use in initializing a static variable; one that can be an
4608 element of a "constant" initializer.
4610 Return null_pointer_node if the value is absolute;
4611 if it is relocatable, return the variable that determines the relocation.
4612 We assume that VALUE has been folded as much as possible;
4613 therefore, we do not need to check for such things as
4614 arithmetic-combinations of integers. */
4616 initializer_constant_valid_p (tree value
, tree endtype
)
4618 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4621 /* Return true if VALUE is a valid constant-valued expression
4622 for use in initializing a static bit-field; one that can be
4623 an element of a "constant" initializer. */
4626 initializer_constant_valid_for_bitfield_p (tree value
)
4628 /* For bitfields we support integer constants or possibly nested aggregates
4630 switch (TREE_CODE (value
))
4634 unsigned HOST_WIDE_INT idx
;
4637 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4638 if (!initializer_constant_valid_for_bitfield_p (elt
))
4647 case VIEW_CONVERT_EXPR
:
4648 case NON_LVALUE_EXPR
:
4650 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4659 /* output_constructor outer state of relevance in recursive calls, typically
4660 for nested aggregate bitfields. */
4663 unsigned int bit_offset
; /* current position in ... */
4664 int byte
; /* ... the outer byte buffer. */
4667 static unsigned HOST_WIDE_INT
4668 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4671 /* Output assembler code for constant EXP, with no label.
4672 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4673 Assumes output_addressed_constants has been done on EXP already.
4675 Generate at least SIZE bytes of assembler data, padding at the end
4676 with zeros if necessary. SIZE must always be specified. The returned
4677 value is the actual number of bytes of assembler data generated, which
4678 may be bigger than SIZE if the object contains a variable length field.
4680 SIZE is important for structure constructors,
4681 since trailing members may have been omitted from the constructor.
4682 It is also important for initialization of arrays from string constants
4683 since the full length of the string constant might not be wanted.
4684 It is also needed for initialization of unions, where the initializer's
4685 type is just one member, and that may not be as long as the union.
4687 There a case in which we would fail to output exactly SIZE bytes:
4688 for a structure constructor that wants to produce more than SIZE bytes.
4689 But such constructors will never be generated for any possible input.
4691 ALIGN is the alignment of the data in bits. */
4693 static unsigned HOST_WIDE_INT
4694 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4696 enum tree_code code
;
4697 unsigned HOST_WIDE_INT thissize
;
4699 if (size
== 0 || flag_syntax_only
)
4702 /* See if we're trying to initialize a pointer in a non-default mode
4703 to the address of some declaration somewhere. If the target says
4704 the mode is valid for pointers, assume the target has a way of
4706 if (TREE_CODE (exp
) == NOP_EXPR
4707 && POINTER_TYPE_P (TREE_TYPE (exp
))
4708 && targetm
.addr_space
.valid_pointer_mode
4709 (TYPE_MODE (TREE_TYPE (exp
)),
4710 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4712 tree saved_type
= TREE_TYPE (exp
);
4714 /* Peel off any intermediate conversions-to-pointer for valid
4716 while (TREE_CODE (exp
) == NOP_EXPR
4717 && POINTER_TYPE_P (TREE_TYPE (exp
))
4718 && targetm
.addr_space
.valid_pointer_mode
4719 (TYPE_MODE (TREE_TYPE (exp
)),
4720 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4721 exp
= TREE_OPERAND (exp
, 0);
4723 /* If what we're left with is the address of something, we can
4724 convert the address to the final type and output it that
4726 if (TREE_CODE (exp
) == ADDR_EXPR
)
4727 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4728 /* Likewise for constant ints. */
4729 else if (TREE_CODE (exp
) == INTEGER_CST
)
4730 exp
= wide_int_to_tree (saved_type
, exp
);
4734 /* Eliminate any conversions since we'll be outputting the underlying
4736 while (CONVERT_EXPR_P (exp
)
4737 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4738 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4740 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4741 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4743 /* Make sure eliminating the conversion is really a no-op, except with
4744 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4745 union types to allow for Ada unchecked unions. */
4746 if (type_size
> op_size
4747 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4748 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4749 /* Keep the conversion. */
4752 exp
= TREE_OPERAND (exp
, 0);
4755 code
= TREE_CODE (TREE_TYPE (exp
));
4756 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4758 /* Allow a constructor with no elements for any data type.
4759 This means to fill the space with zeros. */
4760 if (TREE_CODE (exp
) == CONSTRUCTOR
4761 && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp
)))
4763 assemble_zeros (size
);
4767 if (TREE_CODE (exp
) == FDESC_EXPR
)
4769 #ifdef ASM_OUTPUT_FDESC
4770 HOST_WIDE_INT part
= tree_to_shwi (TREE_OPERAND (exp
, 1));
4771 tree decl
= TREE_OPERAND (exp
, 0);
4772 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4779 /* Now output the underlying data. If we've handling the padding, return.
4780 Otherwise, break and ensure SIZE is the size written. */
4787 case REFERENCE_TYPE
:
4789 case FIXED_POINT_TYPE
:
4790 case POINTER_BOUNDS_TYPE
:
4792 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4793 EXPAND_INITIALIZER
),
4794 MIN (size
, thissize
), align
, 0))
4795 error ("initializer for integer/fixed-point value is too complicated");
4799 if (TREE_CODE (exp
) != REAL_CST
)
4800 error ("initializer for floating value is not a floating constant");
4802 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4806 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4807 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4808 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4813 switch (TREE_CODE (exp
))
4816 return output_constructor (exp
, size
, align
, NULL
);
4819 = MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
), size
);
4820 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4824 machine_mode inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4825 unsigned int nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4826 int elt_size
= GET_MODE_SIZE (inner
);
4827 output_constant (VECTOR_CST_ELT (exp
, 0), elt_size
, align
);
4828 thissize
= elt_size
;
4829 for (unsigned int i
= 1; i
< VECTOR_CST_NELTS (exp
); i
++)
4831 output_constant (VECTOR_CST_ELT (exp
, i
), elt_size
, nalign
);
4832 thissize
+= elt_size
;
4843 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4844 return output_constructor (exp
, size
, align
, NULL
);
4853 if (size
> thissize
)
4854 assemble_zeros (size
- thissize
);
4860 /* Subroutine of output_constructor, used for computing the size of
4861 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4862 type with an unspecified upper bound. */
4864 static unsigned HOST_WIDE_INT
4865 array_size_for_constructor (tree val
)
4868 unsigned HOST_WIDE_INT cnt
;
4869 tree index
, value
, tmp
;
4872 /* This code used to attempt to handle string constants that are not
4873 arrays of single-bytes, but nothing else does, so there's no point in
4875 if (TREE_CODE (val
) == STRING_CST
)
4876 return TREE_STRING_LENGTH (val
);
4878 max_index
= NULL_TREE
;
4879 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4881 if (TREE_CODE (index
) == RANGE_EXPR
)
4882 index
= TREE_OPERAND (index
, 1);
4883 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4887 if (max_index
== NULL_TREE
)
4890 /* Compute the total number of array elements. */
4891 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4892 i
= wi::to_offset (max_index
) - wi::to_offset (tmp
) + 1;
4894 /* Multiply by the array element unit size to find number of bytes. */
4895 i
*= wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4897 gcc_assert (wi::fits_uhwi_p (i
));
4898 return i
.to_uhwi ();
4901 /* Other datastructures + helpers for output_constructor. */
4903 /* output_constructor local state to support interaction with helpers. */
4907 /* Received arguments. */
4908 tree exp
; /* Constructor expression. */
4909 tree type
; /* Type of constructor expression. */
4910 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4911 unsigned int align
; /* Known initial alignment. */
4912 tree min_index
; /* Lower bound if specified for an array. */
4914 /* Output processing state. */
4915 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4916 int byte
; /* Part of a bitfield byte yet to be output. */
4917 int last_relative_index
; /* Implicit or explicit index of the last
4918 array element output within a bitfield. */
4919 bool byte_buffer_in_use
; /* Whether BYTE is in use. */
4921 /* Current element. */
4922 tree field
; /* Current field decl in a record. */
4923 tree val
; /* Current element value. */
4924 tree index
; /* Current element index. */
4928 /* Helper for output_constructor. From the current LOCAL state, output a
4929 RANGE_EXPR element. */
4932 output_constructor_array_range (oc_local_state
*local
)
4934 unsigned HOST_WIDE_INT fieldsize
4935 = int_size_in_bytes (TREE_TYPE (local
->type
));
4937 HOST_WIDE_INT lo_index
4938 = tree_to_shwi (TREE_OPERAND (local
->index
, 0));
4939 HOST_WIDE_INT hi_index
4940 = tree_to_shwi (TREE_OPERAND (local
->index
, 1));
4941 HOST_WIDE_INT index
;
4944 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4946 for (index
= lo_index
; index
<= hi_index
; index
++)
4948 /* Output the element's initial value. */
4949 if (local
->val
== NULL_TREE
)
4950 assemble_zeros (fieldsize
);
4952 fieldsize
= output_constant (local
->val
, fieldsize
, align2
);
4954 /* Count its size. */
4955 local
->total_bytes
+= fieldsize
;
4959 /* Helper for output_constructor. From the current LOCAL state, output a
4960 field element that is not true bitfield or part of an outer one. */
4963 output_constructor_regular_field (oc_local_state
*local
)
4965 /* Field size and position. Since this structure is static, we know the
4966 positions are constant. */
4967 unsigned HOST_WIDE_INT fieldsize
;
4968 HOST_WIDE_INT fieldpos
;
4970 unsigned int align2
;
4972 if (local
->index
!= NULL_TREE
)
4974 /* Perform the index calculation in modulo arithmetic but
4975 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
4976 but we are using an unsigned sizetype. */
4977 unsigned prec
= TYPE_PRECISION (sizetype
);
4978 offset_int idx
= wi::sext (wi::to_offset (local
->index
)
4979 - wi::to_offset (local
->min_index
), prec
);
4980 fieldpos
= (idx
* wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
))))
4983 else if (local
->field
!= NULL_TREE
)
4984 fieldpos
= int_byte_position (local
->field
);
4988 /* Output any buffered-up bit-fields preceding this element. */
4989 if (local
->byte_buffer_in_use
)
4991 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4992 local
->total_bytes
++;
4993 local
->byte_buffer_in_use
= false;
4996 /* Advance to offset of this element.
4997 Note no alignment needed in an array, since that is guaranteed
4998 if each element has the proper size. */
4999 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
5000 && fieldpos
> local
->total_bytes
)
5002 assemble_zeros (fieldpos
- local
->total_bytes
);
5003 local
->total_bytes
= fieldpos
;
5006 /* Find the alignment of this element. */
5007 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
5009 /* Determine size this element should occupy. */
5014 /* If this is an array with an unspecified upper bound,
5015 the initializer determines the size. */
5016 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5017 but we cannot do this until the deprecated support for
5018 initializing zero-length array members is removed. */
5019 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
5020 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
5021 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
5023 fieldsize
= array_size_for_constructor (local
->val
);
5024 /* Given a non-empty initialization, this field had
5026 gcc_assert (!fieldsize
|| !DECL_CHAIN (local
->field
));
5029 fieldsize
= tree_to_uhwi (DECL_SIZE_UNIT (local
->field
));
5032 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
5034 /* Output the element's initial value. */
5035 if (local
->val
== NULL_TREE
)
5036 assemble_zeros (fieldsize
);
5038 fieldsize
= output_constant (local
->val
, fieldsize
, align2
);
5040 /* Count its size. */
5041 local
->total_bytes
+= fieldsize
;
5044 /* Helper for output_constructor. From the LOCAL state, output an element
5045 that is a true bitfield or part of an outer one. BIT_OFFSET is the offset
5046 from the start of a possibly ongoing outer byte buffer. */
5049 output_constructor_bitfield (oc_local_state
*local
, unsigned int bit_offset
)
5051 /* Bit size of this element. */
5052 HOST_WIDE_INT ebitsize
5054 ? tree_to_uhwi (DECL_SIZE (local
->field
))
5055 : tree_to_uhwi (TYPE_SIZE (TREE_TYPE (local
->type
))));
5057 /* Relative index of this element if this is an array component. */
5058 HOST_WIDE_INT relative_index
5061 ? (tree_to_shwi (local
->index
)
5062 - tree_to_shwi (local
->min_index
))
5063 : local
->last_relative_index
+ 1)
5066 /* Bit position of this element from the start of the containing
5068 HOST_WIDE_INT constructor_relative_ebitpos
5070 ? int_bit_position (local
->field
)
5071 : ebitsize
* relative_index
);
5073 /* Bit position of this element from the start of a possibly ongoing
5074 outer byte buffer. */
5075 HOST_WIDE_INT byte_relative_ebitpos
5076 = bit_offset
+ constructor_relative_ebitpos
;
5078 /* From the start of a possibly ongoing outer byte buffer, offsets to
5079 the first bit of this element and to the first bit past the end of
5081 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
5082 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
5084 local
->last_relative_index
= relative_index
;
5086 if (local
->val
== NULL_TREE
)
5087 local
->val
= integer_zero_node
;
5089 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
5090 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
5091 local
->val
= TREE_OPERAND (local
->val
, 0);
5092 local
->val
= fold (local
->val
);
5094 if (TREE_CODE (local
->val
) != INTEGER_CST
5095 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
5097 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
5101 /* If this field does not start in this (or next) byte, skip some bytes. */
5102 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5104 /* Output remnant of any bit field in previous bytes. */
5105 if (local
->byte_buffer_in_use
)
5107 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5108 local
->total_bytes
++;
5109 local
->byte_buffer_in_use
= false;
5112 /* If still not at proper byte, advance to there. */
5113 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5115 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
5116 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
5117 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
5121 /* Set up the buffer if necessary. */
5122 if (!local
->byte_buffer_in_use
)
5126 local
->byte_buffer_in_use
= true;
5129 /* If this is nested constructor, recurse passing the bit offset and the
5130 pending data, then retrieve the new pending data afterwards. */
5131 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
5133 oc_outer_state temp_state
;
5134 temp_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
5135 temp_state
.byte
= local
->byte
;
5137 += output_constructor (local
->val
, 0, 0, &temp_state
);
5138 local
->byte
= temp_state
.byte
;
5142 /* Otherwise, we must split the element into pieces that fall within
5143 separate bytes, and combine each byte with previous or following
5145 while (next_offset
< end_offset
)
5149 HOST_WIDE_INT value
;
5150 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5151 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5153 /* Advance from byte to byte within this element when necessary. */
5154 while (next_byte
!= local
->total_bytes
)
5156 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5157 local
->total_bytes
++;
5161 /* Number of bits we can process at once (all part of the same byte). */
5162 this_time
= MIN (end_offset
- next_offset
, BITS_PER_UNIT
- next_bit
);
5163 if (BYTES_BIG_ENDIAN
)
5165 /* On big-endian machine, take the most significant bits (of the
5166 bits that are significant) first and put them into bytes from
5167 the most significant end. */
5168 shift
= end_offset
- next_offset
- this_time
;
5170 /* Don't try to take a bunch of bits that cross
5171 the word boundary in the INTEGER_CST. We can
5172 only select bits from one element. */
5173 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5174 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5176 const int end
= shift
+ this_time
- 1;
5177 shift
= end
& -HOST_BITS_PER_WIDE_INT
;
5178 this_time
= end
- shift
+ 1;
5181 /* Now get the bits from the appropriate constant word. */
5182 value
= TREE_INT_CST_ELT (local
->val
, shift
/ HOST_BITS_PER_WIDE_INT
);
5183 shift
= shift
& (HOST_BITS_PER_WIDE_INT
- 1);
5185 /* Get the result. This works only when:
5186 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5187 local
->byte
|= (((value
>> shift
)
5188 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5189 << (BITS_PER_UNIT
- this_time
- next_bit
));
5193 /* On little-endian machines, take the least significant bits of
5194 the value first and pack them starting at the least significant
5195 bits of the bytes. */
5196 shift
= next_offset
- byte_relative_ebitpos
;
5198 /* Don't try to take a bunch of bits that cross
5199 the word boundary in the INTEGER_CST. We can
5200 only select bits from one element. */
5201 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5202 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5204 = HOST_BITS_PER_WIDE_INT
- (shift
& (HOST_BITS_PER_WIDE_INT
- 1));
5206 /* Now get the bits from the appropriate constant word. */
5207 value
= TREE_INT_CST_ELT (local
->val
, shift
/ HOST_BITS_PER_WIDE_INT
);
5208 shift
= shift
& (HOST_BITS_PER_WIDE_INT
- 1);
5210 /* Get the result. This works only when:
5211 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5212 local
->byte
|= (((value
>> shift
)
5213 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5217 next_offset
+= this_time
;
5218 local
->byte_buffer_in_use
= true;
5222 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5223 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5224 caller output state of relevance in recursive invocations. */
5226 static unsigned HOST_WIDE_INT
5227 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5228 unsigned int align
, oc_outer_state
*outer
)
5230 unsigned HOST_WIDE_INT cnt
;
5231 constructor_elt
*ce
;
5233 oc_local_state local
;
5235 /* Setup our local state to communicate with helpers. */
5237 local
.type
= TREE_TYPE (exp
);
5239 local
.align
= align
;
5240 if (TREE_CODE (local
.type
) == ARRAY_TYPE
&& TYPE_DOMAIN (local
.type
))
5241 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5243 local
.min_index
= NULL_TREE
;
5245 local
.total_bytes
= 0;
5246 local
.byte_buffer_in_use
= outer
!= NULL
;
5247 local
.byte
= outer
? outer
->byte
: 0;
5248 local
.last_relative_index
= -1;
5250 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5252 /* As CE goes through the elements of the constant, FIELD goes through the
5253 structure fields if the constant is a structure. If the constant is a
5254 union, we override this by getting the field from the TREE_LIST element.
5255 But the constant could also be an array. Then FIELD is zero.
5257 There is always a maximum of one element in the chain LINK for unions
5258 (even if the initializer in a source program incorrectly contains
5261 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5262 local
.field
= TYPE_FIELDS (local
.type
);
5264 local
.field
= NULL_TREE
;
5267 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), cnt
, &ce
);
5268 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
5270 local
.val
= ce
->value
;
5271 local
.index
= NULL_TREE
;
5273 /* The element in a union constructor specifies the proper field
5275 if (RECORD_OR_UNION_TYPE_P (local
.type
) && ce
->index
!= NULL_TREE
)
5276 local
.field
= ce
->index
;
5278 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5279 local
.index
= ce
->index
;
5281 if (local
.field
&& flag_verbose_asm
)
5282 fprintf (asm_out_file
, "%s %s:\n",
5284 DECL_NAME (local
.field
)
5285 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5288 /* Eliminate the marker that makes a cast not be an lvalue. */
5289 if (local
.val
!= NULL_TREE
)
5290 STRIP_NOPS (local
.val
);
5292 /* Output the current element, using the appropriate helper ... */
5294 /* For an array slice not part of an outer bitfield. */
5296 && local
.index
!= NULL_TREE
5297 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5298 output_constructor_array_range (&local
);
5300 /* For a field that is neither a true bitfield nor part of an outer one,
5301 known to be at least byte aligned and multiple-of-bytes long. */
5303 && (local
.field
== NULL_TREE
5304 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5305 output_constructor_regular_field (&local
);
5307 /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
5308 supported for scalar fields, so we may need to convert first. */
5311 if (TREE_CODE (local
.val
) == REAL_CST
)
5313 = fold_unary (VIEW_CONVERT_EXPR
,
5314 build_nonstandard_integer_type
5315 (TYPE_PRECISION (TREE_TYPE (local
.val
)), 0),
5317 output_constructor_bitfield (&local
, outer
? outer
->bit_offset
: 0);
5321 /* If we are not at toplevel, save the pending data for our caller.
5322 Otherwise output the pending data and padding zeros as needed. */
5324 outer
->byte
= local
.byte
;
5327 if (local
.byte_buffer_in_use
)
5329 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5330 local
.total_bytes
++;
5333 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5335 assemble_zeros (local
.size
- local
.total_bytes
);
5336 local
.total_bytes
= local
.size
;
5340 return local
.total_bytes
;
5343 /* Mark DECL as weak. */
5346 mark_weak (tree decl
)
5348 if (DECL_WEAK (decl
))
5351 struct symtab_node
*n
= symtab_node::get (decl
);
5352 if (n
&& n
->refuse_visibility_changes
)
5353 error ("%+D declared weak after being used", decl
);
5354 DECL_WEAK (decl
) = 1;
5356 if (DECL_RTL_SET_P (decl
)
5357 && MEM_P (DECL_RTL (decl
))
5358 && XEXP (DECL_RTL (decl
), 0)
5359 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5360 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5363 /* Merge weak status between NEWDECL and OLDDECL. */
5366 merge_weak (tree newdecl
, tree olddecl
)
5368 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5370 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5373 /* We put the NEWDECL on the weak_decls list at some point
5374 and OLDDECL as well. Keep just OLDDECL on the list. */
5375 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5376 if (TREE_VALUE (*pwd
) == newdecl
)
5378 *pwd
= TREE_CHAIN (*pwd
);
5385 if (DECL_WEAK (newdecl
))
5389 /* NEWDECL is weak, but OLDDECL is not. */
5391 /* If we already output the OLDDECL, we're in trouble; we can't
5392 go back and make it weak. This should never happen in
5393 unit-at-a-time compilation. */
5394 gcc_assert (!TREE_ASM_WRITTEN (olddecl
));
5396 /* If we've already generated rtl referencing OLDDECL, we may
5397 have done so in a way that will not function properly with
5398 a weak symbol. Again in unit-at-a-time this should be
5400 gcc_assert (!TREE_USED (olddecl
)
5401 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)));
5403 if (TARGET_SUPPORTS_WEAK
)
5405 /* We put the NEWDECL on the weak_decls list at some point.
5406 Replace it with the OLDDECL. */
5407 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5408 if (TREE_VALUE (wd
) == newdecl
)
5410 TREE_VALUE (wd
) = olddecl
;
5413 /* We may not find the entry on the list. If NEWDECL is a
5414 weak alias, then we will have already called
5415 globalize_decl to remove the entry; in that case, we do
5416 not need to do anything. */
5419 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5420 mark_weak (olddecl
);
5423 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5424 weak. Just update NEWDECL to indicate that it's weak too. */
5425 mark_weak (newdecl
);
5428 /* Declare DECL to be a weak symbol. */
5431 declare_weak (tree decl
)
5433 gcc_assert (TREE_CODE (decl
) != FUNCTION_DECL
|| !TREE_ASM_WRITTEN (decl
));
5434 if (! TREE_PUBLIC (decl
))
5435 error ("weak declaration of %q+D must be public", decl
);
5436 else if (!TARGET_SUPPORTS_WEAK
)
5437 warning (0, "weak declaration of %q+D not supported", decl
);
5440 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5441 DECL_ATTRIBUTES (decl
)
5442 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5446 weak_finish_1 (tree decl
)
5448 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5449 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5452 if (! TREE_USED (decl
))
5455 #ifdef ASM_WEAKEN_DECL
5456 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5458 #ifdef ASM_WEAKEN_LABEL
5459 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5461 #ifdef ASM_OUTPUT_WEAK_ALIAS
5463 static bool warn_once
= 0;
5466 warning (0, "only weak aliases are supported in this configuration");
5476 /* Fiven an assembly name, find the decl it is associated with. */
5478 find_decl (tree target
)
5480 symtab_node
*node
= symtab_node::get_for_asmname (target
);
5486 /* This TREE_LIST contains weakref targets. */
5488 static GTY(()) tree weakref_targets
;
5490 /* Emit any pending weak declarations. */
5497 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5499 tree alias_decl
= TREE_PURPOSE (t
);
5500 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5502 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5503 /* Remove alias_decl from the weak list, but leave entries for
5504 the target alone. */
5506 #ifndef ASM_OUTPUT_WEAKREF
5507 else if (! TREE_SYMBOL_REFERENCED (target
))
5509 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5510 defined, otherwise we and weak_finish_1 would use
5511 different macros. */
5512 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5513 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5515 tree decl
= find_decl (target
);
5519 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5520 TREE_CODE (alias_decl
), target
,
5521 TREE_TYPE (alias_decl
));
5523 DECL_EXTERNAL (decl
) = 1;
5524 TREE_PUBLIC (decl
) = 1;
5525 DECL_ARTIFICIAL (decl
) = 1;
5526 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5527 TREE_USED (decl
) = 1;
5530 weak_finish_1 (decl
);
5539 /* Remove the alias and the target from the pending weak list
5540 so that we do not emit any .weak directives for the former,
5541 nor multiple .weak directives for the latter. */
5542 for (p
= &weak_decls
; (t2
= *p
) ; )
5544 if (TREE_VALUE (t2
) == alias_decl
5545 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5546 *p
= TREE_CHAIN (t2
);
5548 p
= &TREE_CHAIN (t2
);
5551 /* Remove other weakrefs to the same target, to speed things up. */
5552 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5554 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5555 *p
= TREE_CHAIN (t2
);
5557 p
= &TREE_CHAIN (t2
);
5562 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5564 tree decl
= TREE_VALUE (t
);
5566 weak_finish_1 (decl
);
5570 /* Emit the assembly bits to indicate that DECL is globally visible. */
5573 globalize_decl (tree decl
)
5576 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5577 if (DECL_WEAK (decl
))
5579 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5582 #ifdef ASM_WEAKEN_DECL
5583 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5585 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5588 /* Remove this function from the pending weak list so that
5589 we do not emit multiple .weak directives for it. */
5590 for (p
= &weak_decls
; (t
= *p
) ; )
5592 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5593 *p
= TREE_CHAIN (t
);
5595 p
= &TREE_CHAIN (t
);
5598 /* Remove weakrefs to the same target from the pending weakref
5599 list, for the same reason. */
5600 for (p
= &weakref_targets
; (t
= *p
) ; )
5602 if (DECL_ASSEMBLER_NAME (decl
)
5603 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5604 *p
= TREE_CHAIN (t
);
5606 p
= &TREE_CHAIN (t
);
5613 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5616 vec
<alias_pair
, va_gc
> *alias_pairs
;
5618 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5619 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5620 tree node is DECL to have the value of the tree node TARGET. */
5623 do_assemble_alias (tree decl
, tree target
)
5627 /* Emulated TLS had better not get this var. */
5628 gcc_assert (!(!targetm
.have_tls
5629 && TREE_CODE (decl
) == VAR_DECL
5630 && DECL_THREAD_LOCAL_P (decl
)));
5632 if (TREE_ASM_WRITTEN (decl
))
5635 id
= DECL_ASSEMBLER_NAME (decl
);
5636 ultimate_transparent_alias_target (&id
);
5637 ultimate_transparent_alias_target (&target
);
5639 /* We must force creation of DECL_RTL for debug info generation, even though
5640 we don't use it here. */
5641 make_decl_rtl (decl
);
5643 TREE_ASM_WRITTEN (decl
) = 1;
5644 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5645 TREE_ASM_WRITTEN (id
) = 1;
5647 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5649 if (!TREE_SYMBOL_REFERENCED (target
))
5650 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5652 #ifdef ASM_OUTPUT_WEAKREF
5653 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5654 IDENTIFIER_POINTER (id
),
5655 IDENTIFIER_POINTER (target
));
5657 if (!TARGET_SUPPORTS_WEAK
)
5659 error_at (DECL_SOURCE_LOCATION (decl
),
5660 "weakref is not supported in this configuration");
5667 #ifdef ASM_OUTPUT_DEF
5668 tree orig_decl
= decl
;
5670 if (TREE_CODE (decl
) == FUNCTION_DECL
5671 && cgraph_node::get (decl
)->instrumentation_clone
5672 && cgraph_node::get (decl
)->instrumented_version
)
5673 orig_decl
= cgraph_node::get (decl
)->instrumented_version
->decl
;
5675 /* Make name accessible from other files, if appropriate. */
5677 if (TREE_PUBLIC (decl
) || TREE_PUBLIC (orig_decl
))
5679 globalize_decl (decl
);
5680 maybe_assemble_visibility (decl
);
5682 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5684 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
5685 if (targetm
.has_ifunc_p ())
5686 ASM_OUTPUT_TYPE_DIRECTIVE
5687 (asm_out_file
, IDENTIFIER_POINTER (id
),
5691 error_at (DECL_SOURCE_LOCATION (decl
),
5692 "ifunc is not supported on this target");
5695 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5696 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5698 ASM_OUTPUT_DEF (asm_out_file
,
5699 IDENTIFIER_POINTER (id
),
5700 IDENTIFIER_POINTER (target
));
5702 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5707 name
= IDENTIFIER_POINTER (id
);
5708 # ifdef ASM_WEAKEN_DECL
5709 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5711 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5713 /* Remove this function from the pending weak list so that
5714 we do not emit multiple .weak directives for it. */
5715 for (p
= &weak_decls
; (t
= *p
) ; )
5716 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
))
5717 || id
== DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5718 *p
= TREE_CHAIN (t
);
5720 p
= &TREE_CHAIN (t
);
5722 /* Remove weakrefs to the same target from the pending weakref
5723 list, for the same reason. */
5724 for (p
= &weakref_targets
; (t
= *p
) ; )
5726 if (id
== ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5727 *p
= TREE_CHAIN (t
);
5729 p
= &TREE_CHAIN (t
);
5735 /* Emit an assembler directive to make the symbol for DECL an alias to
5736 the symbol for TARGET. */
5739 assemble_alias (tree decl
, tree target
)
5743 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5745 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5747 ultimate_transparent_alias_target (&target
);
5749 if (alias
== target
)
5750 error ("weakref %q+D ultimately targets itself", decl
);
5751 if (TREE_PUBLIC (decl
))
5752 error ("weakref %q+D must have static linkage", decl
);
5756 #if !defined (ASM_OUTPUT_DEF)
5757 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5758 error_at (DECL_SOURCE_LOCATION (decl
),
5759 "alias definitions not supported in this configuration");
5760 TREE_ASM_WRITTEN (decl
) = 1;
5763 if (!DECL_WEAK (decl
))
5765 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5766 error_at (DECL_SOURCE_LOCATION (decl
),
5767 "ifunc is not supported in this configuration");
5769 error_at (DECL_SOURCE_LOCATION (decl
),
5770 "only weak aliases are supported in this configuration");
5771 TREE_ASM_WRITTEN (decl
) = 1;
5777 TREE_USED (decl
) = 1;
5779 /* Allow aliases to aliases. */
5780 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5781 cgraph_node::get_create (decl
)->alias
= true;
5783 varpool_node::get_create (decl
)->alias
= true;
5785 /* If the target has already been emitted, we don't have to queue the
5786 alias. This saves a tad of memory. */
5787 if (symtab
->global_info_ready
)
5788 target_decl
= find_decl (target
);
5791 if ((target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5792 || symtab
->state
>= EXPANSION
)
5793 do_assemble_alias (decl
, target
);
5796 alias_pair p
= {decl
, target
};
5797 vec_safe_push (alias_pairs
, p
);
5801 /* Record and output a table of translations from original function
5802 to its transaction aware clone. Note that tm_pure functions are
5803 considered to be their own clone. */
5805 struct tm_clone_hasher
: ggc_cache_hasher
<tree_map
*>
5807 static hashval_t
hash (tree_map
*m
) { return tree_map_hash (m
); }
5808 static bool equal (tree_map
*a
, tree_map
*b
) { return tree_map_eq (a
, b
); }
5811 handle_cache_entry (tree_map
*&e
)
5813 extern void gt_ggc_mx (tree_map
*&);
5814 if (e
== HTAB_EMPTY_ENTRY
|| e
== HTAB_DELETED_ENTRY
)
5816 else if (ggc_marked_p (e
->base
.from
))
5819 e
= static_cast<tree_map
*> (HTAB_DELETED_ENTRY
);
5823 static GTY((cache
)) hash_table
<tm_clone_hasher
> *tm_clone_hash
;
5826 record_tm_clone_pair (tree o
, tree n
)
5828 struct tree_map
**slot
, *h
;
5830 if (tm_clone_hash
== NULL
)
5831 tm_clone_hash
= hash_table
<tm_clone_hasher
>::create_ggc (32);
5833 h
= ggc_alloc
<tree_map
> ();
5834 h
->hash
= htab_hash_pointer (o
);
5838 slot
= tm_clone_hash
->find_slot_with_hash (h
, h
->hash
, INSERT
);
5843 get_tm_clone_pair (tree o
)
5847 struct tree_map
*h
, in
;
5850 in
.hash
= htab_hash_pointer (o
);
5851 h
= tm_clone_hash
->find_with_hash (&in
, in
.hash
);
5858 typedef struct tm_alias_pair
5866 /* Dump the actual pairs to the .tm_clone_table section. */
5869 dump_tm_clone_pairs (vec
<tm_alias_pair
> tm_alias_pairs
)
5873 bool switched
= false;
5875 FOR_EACH_VEC_ELT (tm_alias_pairs
, i
, p
)
5879 struct cgraph_node
*src_n
= cgraph_node::get (src
);
5880 struct cgraph_node
*dst_n
= cgraph_node::get (dst
);
5882 /* The function ipa_tm_create_version() marks the clone as needed if
5883 the original function was needed. But we also mark the clone as
5884 needed if we ever called the clone indirectly through
5885 TM_GETTMCLONE. If neither of these are true, we didn't generate
5886 a clone, and we didn't call it indirectly... no sense keeping it
5887 in the clone table. */
5888 if (!dst_n
|| !dst_n
->definition
)
5891 /* This covers the case where we have optimized the original
5892 function away, and only access the transactional clone. */
5893 if (!src_n
|| !src_n
->definition
)
5898 switch_to_section (targetm
.asm_out
.tm_clone_table_section ());
5899 assemble_align (POINTER_SIZE
);
5903 assemble_integer (XEXP (DECL_RTL (src
), 0),
5904 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
5905 assemble_integer (XEXP (DECL_RTL (dst
), 0),
5906 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
5910 /* Provide a default for the tm_clone_table section. */
5913 default_clone_table_section (void)
5915 return get_named_section (NULL
, ".tm_clone_table", 3);
5918 /* Helper comparison function for qsorting by the DECL_UID stored in
5919 alias_pair->emitted_diags. */
5922 tm_alias_pair_cmp (const void *x
, const void *y
)
5924 const tm_alias_pair
*p1
= (const tm_alias_pair
*) x
;
5925 const tm_alias_pair
*p2
= (const tm_alias_pair
*) y
;
5926 if (p1
->uid
< p2
->uid
)
5928 if (p1
->uid
> p2
->uid
)
5934 finish_tm_clone_pairs (void)
5936 vec
<tm_alias_pair
> tm_alias_pairs
= vNULL
;
5938 if (tm_clone_hash
== NULL
)
5941 /* We need a determenistic order for the .tm_clone_table, otherwise
5942 we will get bootstrap comparison failures, so dump the hash table
5943 to a vector, sort it, and dump the vector. */
5945 /* Dump the hashtable to a vector. */
5947 hash_table
<tm_clone_hasher
>::iterator iter
;
5948 FOR_EACH_HASH_TABLE_ELEMENT (*tm_clone_hash
, map
, tree_map
*, iter
)
5950 tm_alias_pair p
= {DECL_UID (map
->base
.from
), map
->base
.from
, map
->to
};
5951 tm_alias_pairs
.safe_push (p
);
5954 tm_alias_pairs
.qsort (tm_alias_pair_cmp
);
5957 dump_tm_clone_pairs (tm_alias_pairs
);
5959 tm_clone_hash
->empty ();
5960 tm_clone_hash
= NULL
;
5961 tm_alias_pairs
.release ();
5965 /* Emit an assembler directive to set symbol for DECL visibility to
5966 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5969 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5970 int vis ATTRIBUTE_UNUSED
)
5972 #ifdef HAVE_GAS_HIDDEN
5973 static const char * const visibility_types
[] = {
5974 NULL
, "protected", "hidden", "internal"
5977 const char *name
, *type
;
5980 id
= DECL_ASSEMBLER_NAME (decl
);
5981 ultimate_transparent_alias_target (&id
);
5982 name
= IDENTIFIER_POINTER (id
);
5984 type
= visibility_types
[vis
];
5986 fprintf (asm_out_file
, "\t.%s\t", type
);
5987 assemble_name (asm_out_file
, name
);
5988 fprintf (asm_out_file
, "\n");
5990 if (!DECL_ARTIFICIAL (decl
))
5991 warning (OPT_Wattributes
, "visibility attribute not supported "
5992 "in this configuration; ignored");
5996 /* A helper function to call assemble_visibility when needed for a decl. */
5999 maybe_assemble_visibility (tree decl
)
6001 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
6003 if (TREE_CODE (decl
) == FUNCTION_DECL
6004 && cgraph_node::get (decl
)
6005 && cgraph_node::get (decl
)->instrumentation_clone
6006 && cgraph_node::get (decl
)->instrumented_version
)
6007 vis
= DECL_VISIBILITY (cgraph_node::get (decl
)->instrumented_version
->decl
);
6009 if (vis
!= VISIBILITY_DEFAULT
)
6011 targetm
.asm_out
.assemble_visibility (decl
, vis
);
6018 /* Returns 1 if the target configuration supports defining public symbols
6019 so that one of them will be chosen at link time instead of generating a
6020 multiply-defined symbol error, whether through the use of weak symbols or
6021 a target-specific mechanism for having duplicates discarded. */
6024 supports_one_only (void)
6026 if (SUPPORTS_ONE_ONLY
)
6028 return TARGET_SUPPORTS_WEAK
;
6031 /* Set up DECL as a public symbol that can be defined in multiple
6032 translation units without generating a linker error. */
6035 make_decl_one_only (tree decl
, tree comdat_group
)
6037 struct symtab_node
*symbol
;
6038 gcc_assert (TREE_CODE (decl
) == VAR_DECL
6039 || TREE_CODE (decl
) == FUNCTION_DECL
);
6041 TREE_PUBLIC (decl
) = 1;
6043 if (TREE_CODE (decl
) == VAR_DECL
)
6044 symbol
= varpool_node::get_create (decl
);
6046 symbol
= cgraph_node::get_create (decl
);
6048 if (SUPPORTS_ONE_ONLY
)
6050 #ifdef MAKE_DECL_ONE_ONLY
6051 MAKE_DECL_ONE_ONLY (decl
);
6053 symbol
->set_comdat_group (comdat_group
);
6055 else if (TREE_CODE (decl
) == VAR_DECL
6056 && (DECL_INITIAL (decl
) == 0
6057 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
6058 DECL_COMMON (decl
) = 1;
6061 gcc_assert (TARGET_SUPPORTS_WEAK
);
6062 DECL_WEAK (decl
) = 1;
6067 init_varasm_once (void)
6069 section_htab
= hash_table
<section_hasher
>::create_ggc (31);
6070 object_block_htab
= hash_table
<object_block_hasher
>::create_ggc (31);
6071 const_desc_htab
= hash_table
<tree_descriptor_hasher
>::create_ggc (1009);
6073 shared_constant_pool
= create_constant_pool ();
6075 #ifdef TEXT_SECTION_ASM_OP
6076 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
6077 TEXT_SECTION_ASM_OP
);
6080 #ifdef DATA_SECTION_ASM_OP
6081 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6082 DATA_SECTION_ASM_OP
);
6085 #ifdef SDATA_SECTION_ASM_OP
6086 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6087 SDATA_SECTION_ASM_OP
);
6090 #ifdef READONLY_DATA_SECTION_ASM_OP
6091 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
6092 READONLY_DATA_SECTION_ASM_OP
);
6095 #ifdef CTORS_SECTION_ASM_OP
6096 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
6097 CTORS_SECTION_ASM_OP
);
6100 #ifdef DTORS_SECTION_ASM_OP
6101 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
6102 DTORS_SECTION_ASM_OP
);
6105 #ifdef BSS_SECTION_ASM_OP
6106 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6107 output_section_asm_op
,
6108 BSS_SECTION_ASM_OP
);
6111 #ifdef SBSS_SECTION_ASM_OP
6112 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6113 output_section_asm_op
,
6114 SBSS_SECTION_ASM_OP
);
6117 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6118 | SECTION_COMMON
, emit_tls_common
);
6119 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6120 | SECTION_COMMON
, emit_local
);
6121 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6122 | SECTION_COMMON
, emit_common
);
6124 #if defined ASM_OUTPUT_ALIGNED_BSS
6125 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
6129 targetm
.asm_out
.init_sections ();
6131 if (readonly_data_section
== NULL
)
6132 readonly_data_section
= text_section
;
6134 #ifdef ASM_OUTPUT_EXTERNAL
6135 pending_assemble_externals_set
= new hash_set
<tree
>;
6140 decl_default_tls_model (const_tree decl
)
6142 enum tls_model kind
;
6145 is_local
= targetm
.binds_local_p (decl
);
6149 kind
= TLS_MODEL_LOCAL_EXEC
;
6151 kind
= TLS_MODEL_INITIAL_EXEC
;
6154 /* Local dynamic is inefficient when we're not combining the
6155 parts of the address. */
6156 else if (optimize
&& is_local
)
6157 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6159 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6160 if (kind
< flag_tls_default
)
6161 kind
= flag_tls_default
;
6166 /* Select a set of attributes for section NAME based on the properties
6167 of DECL and whether or not RELOC indicates that DECL's initializer
6168 might contain runtime relocations.
6170 We make the section read-only and executable for a function decl,
6171 read-only for a const data decl, and writable for a non-const data decl. */
6174 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6178 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6179 flags
= SECTION_CODE
;
6182 enum section_category category
6183 = categorize_decl_for_section (decl
, reloc
);
6184 if (decl_readonly_section_1 (category
))
6186 else if (category
== SECCAT_DATA_REL_RO
6187 || category
== SECCAT_DATA_REL_RO_LOCAL
)
6188 flags
= SECTION_WRITE
| SECTION_RELRO
;
6190 flags
= SECTION_WRITE
;
6194 flags
= SECTION_WRITE
;
6195 if (strcmp (name
, ".data.rel.ro") == 0
6196 || strcmp (name
, ".data.rel.ro.local") == 0)
6197 flags
|= SECTION_RELRO
;
6200 if (decl
&& DECL_P (decl
) && DECL_COMDAT_GROUP (decl
))
6201 flags
|= SECTION_LINKONCE
;
6203 if (strcmp (name
, ".vtable_map_vars") == 0)
6204 flags
|= SECTION_LINKONCE
;
6206 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6207 flags
|= SECTION_TLS
| SECTION_WRITE
;
6209 if (strcmp (name
, ".bss") == 0
6210 || strncmp (name
, ".bss.", 5) == 0
6211 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6212 || strcmp (name
, ".persistent.bss") == 0
6213 || strcmp (name
, ".sbss") == 0
6214 || strncmp (name
, ".sbss.", 6) == 0
6215 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6216 flags
|= SECTION_BSS
;
6218 if (strcmp (name
, ".tdata") == 0
6219 || strncmp (name
, ".tdata.", 7) == 0
6220 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6221 flags
|= SECTION_TLS
;
6223 if (strcmp (name
, ".tbss") == 0
6224 || strncmp (name
, ".tbss.", 6) == 0
6225 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6226 flags
|= SECTION_TLS
| SECTION_BSS
;
6228 /* These three sections have special ELF types. They are neither
6229 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6230 want to print a section type (@progbits or @nobits). If someone
6231 is silly enough to emit code or TLS variables to one of these
6232 sections, then don't handle them specially. */
6233 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
6234 && (strcmp (name
, ".init_array") == 0
6235 || strcmp (name
, ".fini_array") == 0
6236 || strcmp (name
, ".preinit_array") == 0))
6237 flags
|= SECTION_NOTYPE
;
6242 /* Return true if the target supports some form of global BSS,
6243 either through bss_noswitch_section, or by selecting a BSS
6244 section in TARGET_ASM_SELECT_SECTION. */
6247 have_global_bss_p (void)
6249 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6252 /* Output assembly to switch to section NAME with attribute FLAGS.
6253 Four variants for common object file formats. */
6256 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6257 unsigned int flags ATTRIBUTE_UNUSED
,
6258 tree decl ATTRIBUTE_UNUSED
)
6260 /* Some object formats don't support named sections at all. The
6261 front-end should already have flagged this as an error. */
6265 #ifndef TLS_SECTION_ASM_FLAG
6266 #define TLS_SECTION_ASM_FLAG 'T'
6270 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6271 tree decl ATTRIBUTE_UNUSED
)
6273 char flagchars
[10], *f
= flagchars
;
6275 /* If we have already declared this section, we can use an
6276 abbreviated form to switch back to it -- unless this section is
6277 part of a COMDAT groups, in which case GAS requires the full
6278 declaration every time. */
6279 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6280 && (flags
& SECTION_DECLARED
))
6282 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6286 if (!(flags
& SECTION_DEBUG
))
6288 #if defined (HAVE_GAS_SECTION_EXCLUDE) && HAVE_GAS_SECTION_EXCLUDE == 1
6289 if (flags
& SECTION_EXCLUDE
)
6292 if (flags
& SECTION_WRITE
)
6294 if (flags
& SECTION_CODE
)
6296 if (flags
& SECTION_SMALL
)
6298 if (flags
& SECTION_MERGE
)
6300 if (flags
& SECTION_STRINGS
)
6302 if (flags
& SECTION_TLS
)
6303 *f
++ = TLS_SECTION_ASM_FLAG
;
6304 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6308 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6310 if (!(flags
& SECTION_NOTYPE
))
6315 if (flags
& SECTION_BSS
)
6321 /* On platforms that use "@" as the assembly comment character,
6323 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6325 fprintf (asm_out_file
, format
, type
);
6327 if (flags
& SECTION_ENTSIZE
)
6328 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6329 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6331 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6332 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6334 fprintf (asm_out_file
, ",%s,comdat",
6335 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6339 putc ('\n', asm_out_file
);
6343 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6344 tree decl ATTRIBUTE_UNUSED
)
6346 char flagchars
[8], *f
= flagchars
;
6348 if (flags
& SECTION_WRITE
)
6350 if (flags
& SECTION_CODE
)
6354 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6358 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6361 default_coff_asm_named_section (name
, flags
, decl
);
6363 if (flags
& SECTION_LINKONCE
)
6365 /* Functions may have been compiled at various levels of
6366 optimization so we can't use `same_size' here.
6367 Instead, have the linker pick one. */
6368 fprintf (asm_out_file
, "\t.linkonce %s\n",
6369 (flags
& SECTION_CODE
? "discard" : "same_size"));
6373 /* The lame default section selector. */
6376 default_select_section (tree decl
, int reloc
,
6377 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6381 if (decl_readonly_section (decl
, reloc
))
6382 return readonly_data_section
;
6384 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6386 if (! ((flag_pic
&& reloc
)
6387 || !TREE_READONLY (decl
)
6388 || TREE_SIDE_EFFECTS (decl
)
6389 || !TREE_CONSTANT (decl
)))
6390 return readonly_data_section
;
6392 else if (TREE_CODE (decl
) == STRING_CST
)
6393 return readonly_data_section
;
6394 else if (! (flag_pic
&& reloc
))
6395 return readonly_data_section
;
6397 return data_section
;
6400 enum section_category
6401 categorize_decl_for_section (const_tree decl
, int reloc
)
6403 enum section_category ret
;
6405 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6407 else if (TREE_CODE (decl
) == STRING_CST
)
6409 if ((flag_sanitize
& SANITIZE_ADDRESS
)
6410 && asan_protect_global (CONST_CAST_TREE (decl
)))
6411 /* or !flag_merge_constants */
6412 return SECCAT_RODATA
;
6414 return SECCAT_RODATA_MERGE_STR
;
6416 else if (TREE_CODE (decl
) == VAR_DECL
)
6418 if (bss_initializer_p (decl
))
6420 else if (! TREE_READONLY (decl
)
6421 || TREE_SIDE_EFFECTS (decl
)
6422 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6424 /* Here the reloc_rw_mask is not testing whether the section should
6425 be read-only or not, but whether the dynamic link will have to
6426 do something. If so, we wish to segregate the data in order to
6427 minimize cache misses inside the dynamic linker. */
6428 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6429 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6433 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6434 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6435 else if (reloc
|| flag_merge_constants
< 2
6436 || ((flag_sanitize
& SANITIZE_ADDRESS
)
6437 && asan_protect_global (CONST_CAST_TREE (decl
))))
6438 /* C and C++ don't allow different variables to share the same
6439 location. -fmerge-all-constants allows even that (at the
6440 expense of not conforming). */
6441 ret
= SECCAT_RODATA
;
6442 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6443 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6445 ret
= SECCAT_RODATA_MERGE_CONST
;
6447 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6449 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6450 || TREE_SIDE_EFFECTS (decl
)
6451 || ! TREE_CONSTANT (decl
))
6454 ret
= SECCAT_RODATA
;
6457 ret
= SECCAT_RODATA
;
6459 /* There are no read-only thread-local sections. */
6460 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6462 /* Note that this would be *just* SECCAT_BSS, except that there's
6463 no concept of a read-only thread-local-data section. */
6464 if (ret
== SECCAT_BSS
6465 || (flag_zero_initialized_in_bss
6466 && initializer_zerop (DECL_INITIAL (decl
))))
6472 /* If the target uses small data sections, select it. */
6473 else if (targetm
.in_small_data_p (decl
))
6475 if (ret
== SECCAT_BSS
)
6477 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6478 ret
= SECCAT_SRODATA
;
6487 decl_readonly_section_1 (enum section_category category
)
6492 case SECCAT_RODATA_MERGE_STR
:
6493 case SECCAT_RODATA_MERGE_STR_INIT
:
6494 case SECCAT_RODATA_MERGE_CONST
:
6495 case SECCAT_SRODATA
:
6503 decl_readonly_section (const_tree decl
, int reloc
)
6505 return decl_readonly_section_1 (categorize_decl_for_section (decl
, reloc
));
6508 /* Select a section based on the above categorization. */
6511 default_elf_select_section (tree decl
, int reloc
,
6512 unsigned HOST_WIDE_INT align
)
6515 switch (categorize_decl_for_section (decl
, reloc
))
6518 /* We're not supposed to be called on FUNCTION_DECLs. */
6521 return readonly_data_section
;
6522 case SECCAT_RODATA_MERGE_STR
:
6523 return mergeable_string_section (decl
, align
, 0);
6524 case SECCAT_RODATA_MERGE_STR_INIT
:
6525 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6526 case SECCAT_RODATA_MERGE_CONST
:
6527 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6528 case SECCAT_SRODATA
:
6532 return data_section
;
6533 case SECCAT_DATA_REL
:
6534 sname
= ".data.rel";
6536 case SECCAT_DATA_REL_LOCAL
:
6537 sname
= ".data.rel.local";
6539 case SECCAT_DATA_REL_RO
:
6540 sname
= ".data.rel.ro";
6542 case SECCAT_DATA_REL_RO_LOCAL
:
6543 sname
= ".data.rel.ro.local";
6566 return get_named_section (decl
, sname
, reloc
);
6569 /* Construct a unique section name based on the decl name and the
6570 categorization performed above. */
6573 default_unique_section (tree decl
, int reloc
)
6575 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6576 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6577 const char *prefix
, *name
, *linkonce
;
6581 switch (categorize_decl_for_section (decl
, reloc
))
6584 prefix
= one_only
? ".t" : ".text";
6587 case SECCAT_RODATA_MERGE_STR
:
6588 case SECCAT_RODATA_MERGE_STR_INIT
:
6589 case SECCAT_RODATA_MERGE_CONST
:
6590 prefix
= one_only
? ".r" : ".rodata";
6592 case SECCAT_SRODATA
:
6593 prefix
= one_only
? ".s2" : ".sdata2";
6596 prefix
= one_only
? ".d" : ".data";
6598 case SECCAT_DATA_REL
:
6599 prefix
= one_only
? ".d.rel" : ".data.rel";
6601 case SECCAT_DATA_REL_LOCAL
:
6602 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6604 case SECCAT_DATA_REL_RO
:
6605 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6607 case SECCAT_DATA_REL_RO_LOCAL
:
6608 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6611 prefix
= one_only
? ".s" : ".sdata";
6614 prefix
= one_only
? ".b" : ".bss";
6617 prefix
= one_only
? ".sb" : ".sbss";
6620 prefix
= one_only
? ".td" : ".tdata";
6623 prefix
= one_only
? ".tb" : ".tbss";
6629 id
= DECL_ASSEMBLER_NAME (decl
);
6630 ultimate_transparent_alias_target (&id
);
6631 name
= IDENTIFIER_POINTER (id
);
6632 name
= targetm
.strip_name_encoding (name
);
6634 /* If we're using one_only, then there needs to be a .gnu.linkonce
6635 prefix to the section name. */
6636 linkonce
= one_only
? ".gnu.linkonce" : "";
6638 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6640 set_decl_section_name (decl
, string
);
6643 /* Subroutine of compute_reloc_for_rtx for leaf rtxes. */
6646 compute_reloc_for_rtx_1 (const_rtx x
)
6648 switch (GET_CODE (x
))
6651 return SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6659 /* Like compute_reloc_for_constant, except for an RTX. The return value
6660 is a mask for which bit 1 indicates a global relocation, and bit 0
6661 indicates a local relocation. */
6664 compute_reloc_for_rtx (const_rtx x
)
6666 switch (GET_CODE (x
))
6670 return compute_reloc_for_rtx_1 (x
);
6675 subrtx_iterator::array_type array
;
6676 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
6677 reloc
|= compute_reloc_for_rtx_1 (*iter
);
6687 default_select_rtx_section (machine_mode mode ATTRIBUTE_UNUSED
,
6689 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6691 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6692 return data_section
;
6694 return readonly_data_section
;
6698 default_elf_select_rtx_section (machine_mode mode
, rtx x
,
6699 unsigned HOST_WIDE_INT align
)
6701 int reloc
= compute_reloc_for_rtx (x
);
6703 /* ??? Handle small data here somehow. */
6705 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6708 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6710 return get_named_section (NULL
, ".data.rel.ro", 3);
6713 return mergeable_constant_section (mode
, align
, 0);
6716 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6719 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6724 /* Careful not to prod global register variables. */
6727 symbol
= XEXP (rtl
, 0);
6728 if (GET_CODE (symbol
) != SYMBOL_REF
)
6731 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6732 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6733 flags
|= SYMBOL_FLAG_FUNCTION
;
6734 if (targetm
.binds_local_p (decl
))
6735 flags
|= SYMBOL_FLAG_LOCAL
;
6736 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6737 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6738 else if (targetm
.in_small_data_p (decl
))
6739 flags
|= SYMBOL_FLAG_SMALL
;
6740 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6741 being PUBLIC, the thing *must* be defined in this translation unit.
6742 Prevent this buglet from being propagated into rtl code as well. */
6743 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6744 flags
|= SYMBOL_FLAG_EXTERNAL
;
6746 SYMBOL_REF_FLAGS (symbol
) = flags
;
6749 /* By default, we do nothing for encode_section_info, so we need not
6750 do anything but discard the '*' marker. */
6753 default_strip_name_encoding (const char *str
)
6755 return str
+ (*str
== '*');
6758 #ifdef ASM_OUTPUT_DEF
6759 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6760 anchor relative to ".", the current section position. */
6763 default_asm_output_anchor (rtx symbol
)
6767 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6768 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6769 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6773 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6776 default_use_anchors_for_symbol_p (const_rtx symbol
)
6781 /* Don't use anchors for mergeable sections. The linker might move
6782 the objects around. */
6783 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6784 if (sect
->common
.flags
& SECTION_MERGE
)
6787 /* Don't use anchors for small data sections. The small data register
6788 acts as an anchor for such sections. */
6789 if (sect
->common
.flags
& SECTION_SMALL
)
6792 decl
= SYMBOL_REF_DECL (symbol
);
6793 if (decl
&& DECL_P (decl
))
6795 /* Don't use section anchors for decls that might be defined or
6796 usurped by other modules. */
6797 if (TREE_PUBLIC (decl
) && !decl_binds_to_current_def_p (decl
))
6800 /* Don't use section anchors for decls that will be placed in a
6801 small data section. */
6802 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6803 one above. The problem is that we only use SECTION_SMALL for
6804 sections that should be marked as small in the section directive. */
6805 if (targetm
.in_small_data_p (decl
))
6811 /* Return true when RESOLUTION indicate that symbol will be bound to the
6812 definition provided by current .o file. */
6815 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
6817 return (resolution
== LDPR_PREVAILING_DEF
6818 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6819 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
6822 /* Return true when RESOLUTION indicate that symbol will be bound locally
6823 within current executable or DSO. */
6826 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
6828 return (resolution
== LDPR_PREVAILING_DEF
6829 || resolution
== LDPR_PREVAILING_DEF_IRONLY
6830 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6831 || resolution
== LDPR_PREEMPTED_REG
6832 || resolution
== LDPR_PREEMPTED_IR
6833 || resolution
== LDPR_RESOLVED_IR
6834 || resolution
== LDPR_RESOLVED_EXEC
);
6837 /* COMMON_LOCAL_P is true means that the linker can guarantee that an
6838 uninitialized common symbol in the executable will still be defined
6839 (through COPY relocation) in the executable. */
6842 default_binds_local_p_3 (const_tree exp
, bool shlib
, bool weak_dominate
,
6843 bool extern_protected_data
, bool common_local_p
)
6845 /* A non-decl is an entry in the constant pool. */
6849 /* Weakrefs may not bind locally, even though the weakref itself is always
6850 static and therefore local. Similarly, the resolver for ifunc functions
6851 might resolve to a non-local function.
6852 FIXME: We can resolve the weakref case more curefuly by looking at the
6854 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
))
6855 || (TREE_CODE (exp
) == FUNCTION_DECL
6856 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (exp
))))
6859 /* Static variables are always local. */
6860 if (! TREE_PUBLIC (exp
))
6863 /* With resolution file in hand, take look into resolutions.
6864 We can't just return true for resolved_locally symbols,
6865 because dynamic linking might overwrite symbols
6866 in shared libraries. */
6867 bool resolved_locally
= false;
6869 bool uninited_common
= (DECL_COMMON (exp
)
6870 && (DECL_INITIAL (exp
) == NULL
6872 && DECL_INITIAL (exp
) == error_mark_node
)));
6874 /* A non-external variable is defined locally only if it isn't
6875 uninitialized COMMON variable or common_local_p is true. */
6876 bool defined_locally
= (!DECL_EXTERNAL (exp
)
6877 && (!uninited_common
|| common_local_p
));
6878 if (symtab_node
*node
= symtab_node::get (exp
))
6880 if (node
->in_other_partition
)
6881 defined_locally
= true;
6882 if (resolution_to_local_definition_p (node
->resolution
))
6883 defined_locally
= resolved_locally
= true;
6884 else if (resolution_local_p (node
->resolution
))
6885 resolved_locally
= true;
6887 if (defined_locally
&& weak_dominate
&& !shlib
)
6888 resolved_locally
= true;
6890 /* Undefined weak symbols are never defined locally. */
6891 if (DECL_WEAK (exp
) && !defined_locally
)
6894 /* A symbol is local if the user has said explicitly that it will be,
6895 or if we have a definition for the symbol. We cannot infer visibility
6896 for undefined symbols. */
6897 if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
6898 && (TREE_CODE (exp
) == FUNCTION_DECL
6899 || !extern_protected_data
6900 || DECL_VISIBILITY (exp
) != VISIBILITY_PROTECTED
)
6901 && (DECL_VISIBILITY_SPECIFIED (exp
) || defined_locally
))
6904 /* If PIC, then assume that any global name can be overridden by
6905 symbols resolved from other modules. */
6909 /* Variables defined outside this object might not be local. */
6910 if (DECL_EXTERNAL (exp
) && !resolved_locally
)
6913 /* Non-dominant weak symbols are not defined locally. */
6914 if (DECL_WEAK (exp
) && !resolved_locally
)
6917 /* Uninitialized COMMON variable may be unified with symbols
6918 resolved from other modules. */
6919 if (uninited_common
&& !resolved_locally
)
6922 /* Otherwise we're left with initialized (or non-common) global data
6923 which is of necessity defined locally. */
6927 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6928 wrt cross-module name binding. */
6931 default_binds_local_p (const_tree exp
)
6933 return default_binds_local_p_3 (exp
, flag_shlib
!= 0, true, false, false);
6936 /* Similar to default_binds_local_p, but common symbol may be local. */
6939 default_binds_local_p_2 (const_tree exp
)
6941 return default_binds_local_p_3 (exp
, flag_shlib
!= 0, true, false,
6946 default_binds_local_p_1 (const_tree exp
, int shlib
)
6948 return default_binds_local_p_3 (exp
, shlib
!= 0, false, false, false);
6951 /* Return true when references to DECL must bind to current definition in
6954 The condition is usually equivalent to whether the function binds to the
6955 current module (shared library or executable), that is to binds_local_p.
6956 We use this fact to avoid need for another target hook and implement
6957 the logic using binds_local_p and just special cases where
6958 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
6959 the weak definitions (that can be overwritten at linktime by other
6960 definition from different object file) and when resolution info is available
6961 we simply use the knowledge passed to us by linker plugin. */
6963 decl_binds_to_current_def_p (const_tree decl
)
6965 gcc_assert (DECL_P (decl
));
6966 if (!targetm
.binds_local_p (decl
))
6968 if (!TREE_PUBLIC (decl
))
6971 /* When resolution is available, just use it. */
6972 if (symtab_node
*node
= symtab_node::get (decl
))
6974 if (node
->resolution
!= LDPR_UNKNOWN
)
6975 return resolution_to_local_definition_p (node
->resolution
);
6978 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
6979 binds locally but still can be overwritten), DECL_COMMON (can be merged
6980 with a non-common definition somewhere in the same module) or
6982 This rely on fact that binds_local_p behave as decl_replaceable_p
6983 for all other declaration types. */
6984 if (DECL_WEAK (decl
))
6986 if (DECL_COMMON (decl
)
6987 && (DECL_INITIAL (decl
) == NULL
6988 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
6990 if (DECL_EXTERNAL (decl
))
6995 /* A replaceable function or variable is one which may be replaced
6996 at link-time with an entirely different definition, provided that the
6997 replacement has the same type. For example, functions declared
6998 with __attribute__((weak)) on most systems are replaceable.
7000 COMDAT functions are not replaceable, since all definitions of the
7001 function must be equivalent. It is important that COMDAT functions
7002 not be treated as replaceable so that use of C++ template
7003 instantiations is not penalized. */
7006 decl_replaceable_p (tree decl
)
7008 gcc_assert (DECL_P (decl
));
7009 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
7011 if (!flag_semantic_interposition
7012 && !DECL_WEAK (decl
))
7014 return !decl_binds_to_current_def_p (decl
);
7017 /* Default function to output code that will globalize a label. A
7018 target must define GLOBAL_ASM_OP or provide its own function to
7019 globalize a label. */
7020 #ifdef GLOBAL_ASM_OP
7022 default_globalize_label (FILE * stream
, const char *name
)
7024 fputs (GLOBAL_ASM_OP
, stream
);
7025 assemble_name (stream
, name
);
7026 putc ('\n', stream
);
7028 #endif /* GLOBAL_ASM_OP */
7030 /* Default function to output code that will globalize a declaration. */
7032 default_globalize_decl_name (FILE * stream
, tree decl
)
7034 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
7035 targetm
.asm_out
.globalize_label (stream
, name
);
7038 /* Default function to output a label for unwind information. The
7039 default is to do nothing. A target that needs nonlocal labels for
7040 unwind information must provide its own function to do this. */
7042 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
7043 tree decl ATTRIBUTE_UNUSED
,
7044 int for_eh ATTRIBUTE_UNUSED
,
7045 int empty ATTRIBUTE_UNUSED
)
7049 /* Default function to output a label to divide up the exception table.
7050 The default is to do nothing. A target that needs/wants to divide
7051 up the table must provide it's own function to do this. */
7053 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
7057 /* This is how to output an internal numbered label where PREFIX is
7058 the class of label and LABELNO is the number within the class. */
7061 default_generate_internal_label (char *buf
, const char *prefix
,
7062 unsigned long labelno
)
7064 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
7067 /* This is how to output an internal numbered label where PREFIX is
7068 the class of label and LABELNO is the number within the class. */
7071 default_internal_label (FILE *stream
, const char *prefix
,
7072 unsigned long labelno
)
7074 char *const buf
= (char *) alloca (40 + strlen (prefix
));
7075 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
7076 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
7080 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
7083 default_asm_declare_constant_name (FILE *file
, const char *name
,
7084 const_tree exp ATTRIBUTE_UNUSED
,
7085 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
7087 assemble_label (file
, name
);
7090 /* This is the default behavior at the beginning of a file. It's
7091 controlled by two other target-hook toggles. */
7093 default_file_start (void)
7095 if (targetm
.asm_file_start_app_off
7096 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
7097 fputs (ASM_APP_OFF
, asm_out_file
);
7099 if (targetm
.asm_file_start_file_directive
)
7101 /* LTO produced units have no meaningful main_input_filename. */
7103 output_file_directive (asm_out_file
, "<artificial>");
7105 output_file_directive (asm_out_file
, main_input_filename
);
7109 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
7110 which emits a special section directive used to indicate whether or
7111 not this object file needs an executable stack. This is primarily
7112 a GNU extension to ELF but could be used on other targets. */
7114 int trampolines_created
;
7117 file_end_indicate_exec_stack (void)
7119 unsigned int flags
= SECTION_DEBUG
;
7120 if (trampolines_created
)
7121 flags
|= SECTION_CODE
;
7123 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
7126 /* Emit a special section directive to indicate that this object file
7127 was compiled with -fsplit-stack. This is used to let the linker
7128 detect calls between split-stack code and non-split-stack code, so
7129 that it can modify the split-stack code to allocate a sufficiently
7130 large stack. We emit another special section if there are any
7131 functions in this file which have the no_split_stack attribute, to
7132 prevent the linker from warning about being unable to convert the
7133 functions if they call non-split-stack code. */
7136 file_end_indicate_split_stack (void)
7138 if (flag_split_stack
)
7140 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
7142 if (saw_no_split_stack
)
7143 switch_to_section (get_section (".note.GNU-no-split-stack",
7144 SECTION_DEBUG
, NULL
));
7148 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
7149 a get_unnamed_section callback. */
7152 output_section_asm_op (const void *directive
)
7154 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
7157 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
7158 the current section is NEW_SECTION. */
7161 switch_to_section (section
*new_section
)
7163 if (in_section
== new_section
)
7166 if (new_section
->common
.flags
& SECTION_FORGET
)
7169 in_section
= new_section
;
7171 switch (SECTION_STYLE (new_section
))
7174 targetm
.asm_out
.named_section (new_section
->named
.name
,
7175 new_section
->named
.common
.flags
,
7176 new_section
->named
.decl
);
7179 case SECTION_UNNAMED
:
7180 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
7183 case SECTION_NOSWITCH
:
7188 new_section
->common
.flags
|= SECTION_DECLARED
;
7191 /* If block symbol SYMBOL has not yet been assigned an offset, place
7192 it at the end of its block. */
7195 place_block_symbol (rtx symbol
)
7197 unsigned HOST_WIDE_INT size
, mask
, offset
;
7198 struct constant_descriptor_rtx
*desc
;
7199 unsigned int alignment
;
7200 struct object_block
*block
;
7203 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
7204 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
7207 /* Work out the symbol's size and alignment. */
7208 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7210 desc
= SYMBOL_REF_CONSTANT (symbol
);
7211 alignment
= desc
->align
;
7212 size
= GET_MODE_SIZE (desc
->mode
);
7214 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7216 decl
= SYMBOL_REF_DECL (symbol
);
7217 gcc_checking_assert (DECL_IN_CONSTANT_POOL (decl
));
7218 alignment
= DECL_ALIGN (decl
);
7219 size
= get_constant_size (DECL_INITIAL (decl
));
7220 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7221 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7222 && asan_protect_global (DECL_INITIAL (decl
)))
7223 size
+= asan_red_zone_size (size
);
7227 struct symtab_node
*snode
;
7228 decl
= SYMBOL_REF_DECL (symbol
);
7230 snode
= symtab_node::get (decl
);
7233 rtx target
= DECL_RTL (snode
->ultimate_alias_target ()->decl
);
7235 gcc_assert (MEM_P (target
)
7236 && GET_CODE (XEXP (target
, 0)) == SYMBOL_REF
7237 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (target
, 0)));
7238 target
= XEXP (target
, 0);
7239 place_block_symbol (target
);
7240 SYMBOL_REF_BLOCK_OFFSET (symbol
) = SYMBOL_REF_BLOCK_OFFSET (target
);
7243 alignment
= get_variable_align (decl
);
7244 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7245 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7246 && asan_protect_global (decl
))
7248 size
+= asan_red_zone_size (size
);
7249 alignment
= MAX (alignment
,
7250 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
7254 /* Calculate the object's offset from the start of the block. */
7255 block
= SYMBOL_REF_BLOCK (symbol
);
7256 mask
= alignment
/ BITS_PER_UNIT
- 1;
7257 offset
= (block
->size
+ mask
) & ~mask
;
7258 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
7260 /* Record the block's new alignment and size. */
7261 block
->alignment
= MAX (block
->alignment
, alignment
);
7262 block
->size
= offset
+ size
;
7264 vec_safe_push (block
->objects
, symbol
);
7267 /* Return the anchor that should be used to address byte offset OFFSET
7268 from the first object in BLOCK. MODEL is the TLS model used
7272 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7273 enum tls_model model
)
7276 unsigned int begin
, middle
, end
;
7277 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7280 /* Work out the anchor's offset. Use an offset of 0 for the first
7281 anchor so that we don't pessimize the case where we take the address
7282 of a variable at the beginning of the block. This is particularly
7283 useful when a block has only one variable assigned to it.
7285 We try to place anchors RANGE bytes apart, so there can then be
7286 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7287 a ptr_mode offset. With some target settings, the lowest such
7288 anchor might be out of range for the lowest ptr_mode offset;
7289 likewise the highest anchor for the highest offset. Use anchors
7290 at the extreme ends of the ptr_mode range in such cases.
7292 All arithmetic uses unsigned integers in order to avoid
7294 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7295 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7296 range
= max_offset
- min_offset
+ 1;
7301 bias
= HOST_WIDE_INT_1U
<< (GET_MODE_BITSIZE (ptr_mode
) - 1);
7304 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7305 delta
-= delta
% range
;
7308 offset
= (HOST_WIDE_INT
) (-delta
);
7312 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7313 delta
-= delta
% range
;
7314 if (delta
> bias
- 1)
7316 offset
= (HOST_WIDE_INT
) delta
;
7320 /* Do a binary search to see if there's already an anchor we can use.
7321 Set BEGIN to the new anchor's index if not. */
7323 end
= vec_safe_length (block
->anchors
);
7324 while (begin
!= end
)
7326 middle
= (end
+ begin
) / 2;
7327 anchor
= (*block
->anchors
)[middle
];
7328 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7330 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7332 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7334 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7340 /* Create a new anchor with a unique label. */
7341 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7342 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7343 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7344 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7346 /* Insert it at index BEGIN. */
7347 vec_safe_insert (block
->anchors
, begin
, anchor
);
7351 /* Output the objects in BLOCK. */
7354 output_object_block (struct object_block
*block
)
7356 struct constant_descriptor_rtx
*desc
;
7358 HOST_WIDE_INT offset
;
7362 if (!block
->objects
)
7365 /* Switch to the section and make sure that the first byte is
7366 suitably aligned. */
7367 switch_to_section (block
->sect
);
7368 assemble_align (block
->alignment
);
7370 /* Define the values of all anchors relative to the current section
7372 FOR_EACH_VEC_SAFE_ELT (block
->anchors
, i
, symbol
)
7373 targetm
.asm_out
.output_anchor (symbol
);
7375 /* Output the objects themselves. */
7377 FOR_EACH_VEC_ELT (*block
->objects
, i
, symbol
)
7379 /* Move to the object's offset, padding with zeros if necessary. */
7380 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7381 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7382 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7384 desc
= SYMBOL_REF_CONSTANT (symbol
);
7385 output_constant_pool_1 (desc
, 1);
7386 offset
+= GET_MODE_SIZE (desc
->mode
);
7388 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7391 decl
= SYMBOL_REF_DECL (symbol
);
7392 assemble_constant_contents
7393 (DECL_INITIAL (decl
), XSTR (symbol
, 0), DECL_ALIGN (decl
));
7395 size
= get_constant_size (DECL_INITIAL (decl
));
7397 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7398 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7399 && asan_protect_global (DECL_INITIAL (decl
)))
7401 size
= asan_red_zone_size (size
);
7402 assemble_zeros (size
);
7409 decl
= SYMBOL_REF_DECL (symbol
);
7410 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
7411 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7413 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7414 && asan_protect_global (decl
))
7416 size
= asan_red_zone_size (size
);
7417 assemble_zeros (size
);
7424 /* A htab_traverse callback used to call output_object_block for
7425 each member of object_block_htab. */
7428 output_object_block_htab (object_block
**slot
, void *)
7430 output_object_block (*slot
);
7434 /* Output the definitions of all object_blocks. */
7437 output_object_blocks (void)
7439 object_block_htab
->traverse
<void *, output_object_block_htab
> (NULL
);
7442 /* This function provides a possible implementation of the
7443 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7444 by -frecord-gcc-switches it creates a new mergeable, string section in the
7445 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7446 contains the switches in ASCII format.
7448 FIXME: This code does not correctly handle double quote characters
7449 that appear inside strings, (it strips them rather than preserving them).
7450 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7451 characters - instead it treats them as sub-string separators. Since
7452 we want to emit NUL strings terminators into the object file we have to use
7456 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7460 case SWITCH_TYPE_PASSED
:
7461 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
7462 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7465 case SWITCH_TYPE_DESCRIPTIVE
:
7468 /* Distinguish between invocations where name is NULL. */
7469 static bool started
= false;
7475 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7479 | (SECTION_ENTSIZE
& 1),
7481 switch_to_section (sec
);
7490 /* The return value is currently ignored by the caller, but must be 0.
7491 For -fverbose-asm the return value would be the number of characters
7492 emitted into the assembler file. */
7496 /* Emit text to declare externally defined symbols. It is needed to
7497 properly support non-default visibility. */
7499 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7501 const char *name ATTRIBUTE_UNUSED
)
7503 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7504 set in order to avoid putting out names that are never really
7505 used. Always output visibility specified in the source. */
7506 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7507 && (DECL_VISIBILITY_SPECIFIED (decl
)
7508 || targetm
.binds_local_p (decl
)))
7509 maybe_assemble_visibility (decl
);
7512 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7515 default_asm_output_source_filename (FILE *file
, const char *name
)
7517 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7518 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
7520 fprintf (file
, "\t.file\t");
7521 output_quoted_string (file
, name
);
7526 /* Output a file name in the form wanted by System V. */
7529 output_file_directive (FILE *asm_file
, const char *input_name
)
7534 if (input_name
== NULL
)
7535 input_name
= "<stdin>";
7537 input_name
= remap_debug_filename (input_name
);
7539 len
= strlen (input_name
);
7540 na
= input_name
+ len
;
7542 /* NA gets INPUT_NAME sans directory names. */
7543 while (na
> input_name
)
7545 if (IS_DIR_SEPARATOR (na
[-1]))
7550 targetm
.asm_out
.output_source_filename (asm_file
, na
);
7553 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7556 make_debug_expr_from_rtl (const_rtx exp
)
7558 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7559 machine_mode mode
= GET_MODE (exp
);
7562 DECL_ARTIFICIAL (ddecl
) = 1;
7563 if (REG_P (exp
) && REG_EXPR (exp
))
7564 type
= TREE_TYPE (REG_EXPR (exp
));
7565 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7566 type
= TREE_TYPE (MEM_EXPR (exp
));
7569 if (type
&& TYPE_MODE (type
) == mode
)
7570 TREE_TYPE (ddecl
) = type
;
7572 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7573 DECL_MODE (ddecl
) = mode
;
7574 dval
= gen_rtx_DEBUG_EXPR (mode
);
7575 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7576 SET_DECL_RTL (ddecl
, dval
);
7580 #ifdef ELF_ASCII_ESCAPES
7581 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
7584 default_elf_asm_output_limited_string (FILE *f
, const char *s
)
7589 fputs (STRING_ASM_OP
, f
);
7594 escape
= ELF_ASCII_ESCAPES
[c
];
7601 /* TODO: Print in hex with fast function, important for -flto. */
7602 fprintf (f
, "\\%03o", c
);
7615 /* Default ASM_OUTPUT_ASCII for ELF targets. */
7618 default_elf_asm_output_ascii (FILE *f
, const char *s
, unsigned int len
)
7620 const char *limit
= s
+ len
;
7621 const char *last_null
= NULL
;
7622 unsigned bytes_in_chunk
= 0;
7626 for (; s
< limit
; s
++)
7630 if (bytes_in_chunk
>= 60)
7639 for (p
= s
; p
< limit
&& *p
!= '\0'; p
++)
7646 if (p
< limit
&& (p
- s
) <= (long) ELF_STRING_LIMIT
)
7648 if (bytes_in_chunk
> 0)
7655 default_elf_asm_output_limited_string (f
, s
);
7660 if (bytes_in_chunk
== 0)
7661 fputs (ASCII_DATA_ASM_OP
"\"", f
);
7664 escape
= ELF_ASCII_ESCAPES
[c
];
7672 /* TODO: Print in hex with fast function, important for -flto. */
7673 fprintf (f
, "\\%03o", c
);
7674 bytes_in_chunk
+= 4;
7679 bytes_in_chunk
+= 2;
7686 if (bytes_in_chunk
> 0)
7694 static GTY(()) section
*elf_init_array_section
;
7695 static GTY(()) section
*elf_fini_array_section
;
7698 get_elf_initfini_array_priority_section (int priority
,
7702 if (priority
!= DEFAULT_INIT_PRIORITY
)
7705 sprintf (buf
, "%s.%.5u",
7706 constructor_p
? ".init_array" : ".fini_array",
7708 sec
= get_section (buf
, SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7714 if (elf_init_array_section
== NULL
)
7715 elf_init_array_section
7716 = get_section (".init_array",
7717 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7718 sec
= elf_init_array_section
;
7722 if (elf_fini_array_section
== NULL
)
7723 elf_fini_array_section
7724 = get_section (".fini_array",
7725 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7726 sec
= elf_fini_array_section
;
7732 /* Use .init_array section for constructors. */
7735 default_elf_init_array_asm_out_constructor (rtx symbol
, int priority
)
7737 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7739 assemble_addr_to_section (symbol
, sec
);
7742 /* Use .fini_array section for destructors. */
7745 default_elf_fini_array_asm_out_destructor (rtx symbol
, int priority
)
7747 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7749 assemble_addr_to_section (symbol
, sec
);
7752 /* Default TARGET_ASM_OUTPUT_IDENT hook.
7754 This is a bit of a cheat. The real default is a no-op, but this
7755 hook is the default for all targets with a .ident directive. */
7758 default_asm_output_ident_directive (const char *ident_str
)
7760 const char *ident_asm_op
= "\t.ident\t";
7762 /* If we are still in the front end, do not write out the string
7763 to asm_out_file. Instead, add a fake top-level asm statement.
7764 This allows the front ends to use this hook without actually
7765 writing to asm_out_file, to handle #ident or Pragma Ident. */
7766 if (symtab
->state
== PARSING
)
7768 char *buf
= ACONCAT ((ident_asm_op
, "\"", ident_str
, "\"\n", NULL
));
7769 symtab
->finalize_toplevel_asm (build_string (strlen (buf
), buf
));
7772 fprintf (asm_out_file
, "%s\"%s\"\n", ident_asm_op
, ident_str
);
7775 #include "gt-varasm.h"