1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987-2020 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 /* This file handles generation of all the assembler code
22 *except* the instructions of a function.
23 This includes declarations of variables and their initial values.
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
30 #include "coretypes.h"
38 #include "stringpool.h"
42 #include "diagnostic-core.h"
43 #include "fold-const.h"
44 #include "stor-layout.h"
52 #include "langhooks.h"
54 #include "common/common-target.h"
55 #include "stringpool.h"
59 #include "file-prefix-map.h" /* remap_debug_filename() */
60 #include "alloc-pool.h"
62 #ifdef XCOFF_DEBUGGING_INFO
63 #include "xcoffout.h" /* Needed for external data declarations. */
66 /* The (assembler) name of the first globally-visible object output. */
67 extern GTY(()) const char *first_global_object_name
;
68 extern GTY(()) const char *weak_global_object_name
;
70 const char *first_global_object_name
;
71 const char *weak_global_object_name
;
74 class constant_descriptor_rtx
;
75 struct rtx_constant_pool
;
77 #define n_deferred_constants (crtl->varasm.deferred_constants)
79 /* Number for making the label on the next
80 constant that is stored in memory. */
82 static GTY(()) int const_labelno
;
84 /* Carry information from ASM_DECLARE_OBJECT_NAME
85 to ASM_FINISH_DECLARE_OBJECT. */
87 int size_directive_output
;
89 /* The last decl for which assemble_variable was called,
90 if it did ASM_DECLARE_OBJECT_NAME.
91 If the last call to assemble_variable didn't do that,
94 tree last_assemble_variable_decl
;
96 /* The following global variable indicates if the first basic block
97 in a function belongs to the cold partition or not. */
99 bool first_function_block_is_cold
;
101 /* Whether we saw any functions with no_split_stack. */
103 static bool saw_no_split_stack
;
105 static const char *strip_reg_name (const char *);
106 static int contains_pointers_p (tree
);
107 #ifdef ASM_OUTPUT_EXTERNAL
108 static bool incorporeal_function_p (tree
);
110 static void decode_addr_const (tree
, class addr_const
*);
111 static hashval_t
const_hash_1 (const tree
);
112 static int compare_constant (const tree
, const tree
);
113 static void output_constant_def_contents (rtx
);
114 static void output_addressed_constants (tree
, int);
115 static unsigned HOST_WIDE_INT
output_constant (tree
, unsigned HOST_WIDE_INT
,
116 unsigned int, bool, bool);
117 static void globalize_decl (tree
);
118 static bool decl_readonly_section_1 (enum section_category
);
119 #ifdef BSS_SECTION_ASM_OP
120 #ifdef ASM_OUTPUT_ALIGNED_BSS
121 static void asm_output_aligned_bss (FILE *, tree
, const char *,
122 unsigned HOST_WIDE_INT
, int)
125 #endif /* BSS_SECTION_ASM_OP */
126 static void mark_weak (tree
);
127 static void output_constant_pool (const char *, tree
);
128 static void handle_vtv_comdat_section (section
*, const_tree
);
130 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
131 section
*text_section
;
132 section
*data_section
;
133 section
*readonly_data_section
;
134 section
*sdata_section
;
135 section
*ctors_section
;
136 section
*dtors_section
;
137 section
*bss_section
;
138 section
*sbss_section
;
140 /* Various forms of common section. All are guaranteed to be nonnull. */
141 section
*tls_comm_section
;
142 section
*comm_section
;
143 section
*lcomm_section
;
145 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
147 section
*bss_noswitch_section
;
149 /* The section that holds the main exception table, when known. The section
150 is set either by the target's init_sections hook or by the first call to
151 switch_to_exception_section. */
152 section
*exception_section
;
154 /* The section that holds the DWARF2 frame unwind information, when known.
155 The section is set either by the target's init_sections hook or by the
156 first call to switch_to_eh_frame_section. */
157 section
*eh_frame_section
;
159 /* asm_out_file's current section. This is NULL if no section has yet
160 been selected or if we lose track of what the current section is. */
163 /* True if code for the current function is currently being directed
164 at the cold section. */
165 bool in_cold_section_p
;
167 /* The following global holds the "function name" for the code in the
168 cold section of a function, if hot/cold function splitting is enabled
169 and there was actually code that went into the cold section. A
170 pseudo function name is needed for the cold section of code for some
171 debugging tools that perform symbolization. */
172 tree cold_function_name
= NULL_TREE
;
174 /* A linked list of all the unnamed sections. */
175 static GTY(()) section
*unnamed_sections
;
177 /* Return a nonzero value if DECL has a section attribute. */
178 #define IN_NAMED_SECTION(DECL) \
179 (VAR_OR_FUNCTION_DECL_P (DECL) && DECL_SECTION_NAME (DECL) != NULL)
181 struct section_hasher
: ggc_ptr_hash
<section
>
183 typedef const char *compare_type
;
185 static hashval_t
hash (section
*);
186 static bool equal (section
*, const char *);
189 /* Hash table of named sections. */
190 static GTY(()) hash_table
<section_hasher
> *section_htab
;
192 struct object_block_hasher
: ggc_ptr_hash
<object_block
>
194 typedef const section
*compare_type
;
196 static hashval_t
hash (object_block
*);
197 static bool equal (object_block
*, const section
*);
200 /* A table of object_blocks, indexed by section. */
201 static GTY(()) hash_table
<object_block_hasher
> *object_block_htab
;
203 /* The next number to use for internal anchor labels. */
204 static GTY(()) int anchor_labelno
;
206 /* A pool of constants that can be shared between functions. */
207 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
209 /* Helper routines for maintaining section_htab. */
212 section_hasher::equal (section
*old
, const char *new_name
)
214 return strcmp (old
->named
.name
, new_name
) == 0;
218 section_hasher::hash (section
*old
)
220 return htab_hash_string (old
->named
.name
);
223 /* Return a hash value for section SECT. */
226 hash_section (section
*sect
)
228 if (sect
->common
.flags
& SECTION_NAMED
)
229 return htab_hash_string (sect
->named
.name
);
230 return sect
->common
.flags
& ~SECTION_DECLARED
;
233 /* Helper routines for maintaining object_block_htab. */
236 object_block_hasher::equal (object_block
*old
, const section
*new_section
)
238 return old
->sect
== new_section
;
242 object_block_hasher::hash (object_block
*old
)
244 return hash_section (old
->sect
);
247 /* Return a new unnamed section with the given fields. */
250 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
255 sect
= ggc_alloc
<section
> ();
256 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
257 sect
->unnamed
.callback
= callback
;
258 sect
->unnamed
.data
= data
;
259 sect
->unnamed
.next
= unnamed_sections
;
261 unnamed_sections
= sect
;
265 /* Return a SECTION_NOSWITCH section with the given fields. */
268 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
272 sect
= ggc_alloc
<section
> ();
273 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
274 sect
->noswitch
.callback
= callback
;
279 /* Return the named section structure associated with NAME. Create
280 a new section with the given fields if no such structure exists.
281 When NOT_EXISTING, then fail if the section already exists. */
284 get_section (const char *name
, unsigned int flags
, tree decl
,
287 section
*sect
, **slot
;
289 slot
= section_htab
->find_slot_with_hash (name
, htab_hash_string (name
),
291 flags
|= SECTION_NAMED
;
292 if (HAVE_GAS_SHF_GNU_RETAIN
294 && DECL_PRESERVE_P (decl
))
295 flags
|= SECTION_RETAIN
;
298 sect
= ggc_alloc
<section
> ();
299 sect
->named
.common
.flags
= flags
;
300 sect
->named
.name
= ggc_strdup (name
);
301 sect
->named
.decl
= decl
;
307 internal_error ("Section already exists: %qs", name
);
310 /* It is fine if one of the sections has SECTION_NOTYPE as long as
311 the other has none of the contrary flags (see the logic at the end
312 of default_section_type_flags, below). */
313 if (((sect
->common
.flags
^ flags
) & SECTION_NOTYPE
)
314 && !((sect
->common
.flags
| flags
)
315 & (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
| SECTION_ENTSIZE
316 | (HAVE_COMDAT_GROUP
? SECTION_LINKONCE
: 0))))
318 sect
->common
.flags
|= SECTION_NOTYPE
;
319 flags
|= SECTION_NOTYPE
;
321 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
322 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
324 /* It is fine if one of the section flags is
325 SECTION_WRITE | SECTION_RELRO and the other has none of these
326 flags (i.e. read-only) in named sections and either the
327 section hasn't been declared yet or has been declared as writable.
328 In that case just make sure the resulting flags are
329 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
331 if (((sect
->common
.flags
^ flags
) & (SECTION_WRITE
| SECTION_RELRO
))
332 == (SECTION_WRITE
| SECTION_RELRO
)
333 && (sect
->common
.flags
334 & ~(SECTION_DECLARED
| SECTION_WRITE
| SECTION_RELRO
))
335 == (flags
& ~(SECTION_WRITE
| SECTION_RELRO
))
336 && ((sect
->common
.flags
& SECTION_DECLARED
) == 0
337 || (sect
->common
.flags
& SECTION_WRITE
)))
339 sect
->common
.flags
|= (SECTION_WRITE
| SECTION_RELRO
);
342 /* Sanity check user variables for flag changes. */
343 if (sect
->named
.decl
!= NULL
344 && DECL_P (sect
->named
.decl
)
345 && decl
!= sect
->named
.decl
)
347 if (decl
!= NULL
&& DECL_P (decl
))
348 error ("%+qD causes a section type conflict with %qD",
349 decl
, sect
->named
.decl
);
351 error ("section type conflict with %qD", sect
->named
.decl
);
352 inform (DECL_SOURCE_LOCATION (sect
->named
.decl
),
353 "%qD was declared here", sect
->named
.decl
);
355 else if (decl
!= NULL
&& DECL_P (decl
))
356 error ("%+qD causes a section type conflict", decl
);
358 error ("section type conflict");
359 /* Make sure we don't error about one section multiple times. */
360 sect
->common
.flags
|= SECTION_OVERRIDE
;
366 /* Return true if the current compilation mode benefits from having
367 objects grouped into blocks. */
370 use_object_blocks_p (void)
372 return flag_section_anchors
;
375 /* Return the object_block structure for section SECT. Create a new
376 structure if we haven't created one already. Return null if SECT
377 itself is null. Return also null for mergeable sections since
378 section anchors can't be used in mergeable sections anyway,
379 because the linker might move objects around, and using the
380 object blocks infrastructure in that case is both a waste and a
381 maintenance burden. */
383 static struct object_block
*
384 get_block_for_section (section
*sect
)
386 struct object_block
*block
;
391 if (sect
->common
.flags
& SECTION_MERGE
)
395 = object_block_htab
->find_slot_with_hash (sect
, hash_section (sect
),
400 block
= ggc_cleared_alloc
<object_block
> ();
407 /* Create a symbol with label LABEL and place it at byte offset
408 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
409 is not yet known. LABEL must be a garbage-collected string. */
412 create_block_symbol (const char *label
, struct object_block
*block
,
413 HOST_WIDE_INT offset
)
418 /* Create the extended SYMBOL_REF. */
419 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
420 symbol
= (rtx
) ggc_internal_alloc (size
);
422 /* Initialize the normal SYMBOL_REF fields. */
423 memset (symbol
, 0, size
);
424 PUT_CODE (symbol
, SYMBOL_REF
);
425 PUT_MODE (symbol
, Pmode
);
426 XSTR (symbol
, 0) = label
;
427 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
429 /* Initialize the block_symbol stuff. */
430 SYMBOL_REF_BLOCK (symbol
) = block
;
431 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
436 /* Return a section with a particular name and with whatever SECTION_*
437 flags section_type_flags deems appropriate. The name of the section
438 is taken from NAME if nonnull, otherwise it is taken from DECL's
439 DECL_SECTION_NAME. DECL is the decl associated with the section
440 (see the section comment for details) and RELOC is as for
441 section_type_flags. */
444 get_named_section (tree decl
, const char *name
, int reloc
)
450 gcc_assert (decl
&& DECL_P (decl
) && DECL_SECTION_NAME (decl
));
451 name
= DECL_SECTION_NAME (decl
);
454 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
455 return get_section (name
, flags
, decl
);
458 /* Worker for resolve_unique_section. */
461 set_implicit_section (struct symtab_node
*n
, void *data ATTRIBUTE_UNUSED
)
463 n
->implicit_section
= true;
467 /* If required, set DECL_SECTION_NAME to a unique name. */
470 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
471 int flag_function_or_data_sections
)
473 if (DECL_SECTION_NAME (decl
) == NULL
474 && targetm_common
.have_named_sections
475 && (flag_function_or_data_sections
476 || (HAVE_GAS_SHF_GNU_RETAIN
&& DECL_PRESERVE_P (decl
))
477 || DECL_COMDAT_GROUP (decl
)))
479 targetm
.asm_out
.unique_section (decl
, reloc
);
480 if (DECL_SECTION_NAME (decl
))
481 symtab_node::get (decl
)->call_for_symbol_and_aliases
482 (set_implicit_section
, NULL
, true);
486 #ifdef BSS_SECTION_ASM_OP
488 #ifdef ASM_OUTPUT_ALIGNED_BSS
490 /* Utility function for targets to use in implementing
491 ASM_OUTPUT_ALIGNED_BSS.
492 ??? It is believed that this function will work in most cases so such
493 support is localized here. */
496 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
497 const char *name
, unsigned HOST_WIDE_INT size
,
500 switch_to_section (bss_section
);
501 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
502 #ifdef ASM_DECLARE_OBJECT_NAME
503 last_assemble_variable_decl
= decl
;
504 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
506 /* Standard thing is just output label for the object. */
507 ASM_OUTPUT_LABEL (file
, name
);
508 #endif /* ASM_DECLARE_OBJECT_NAME */
509 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
514 #endif /* BSS_SECTION_ASM_OP */
516 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
517 /* Return the hot section for function DECL. Return text_section for
521 hot_function_section (tree decl
)
523 if (decl
!= NULL_TREE
524 && DECL_SECTION_NAME (decl
) != NULL
525 && targetm_common
.have_named_sections
)
526 return get_named_section (decl
, NULL
, 0);
532 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
535 When DECL_SECTION_NAME is non-NULL and it is implicit section and
536 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
537 concatenate the name with NAMED_SECTION_SUFFIX.
538 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
541 get_named_text_section (tree decl
,
542 const char *text_section_name
,
543 const char *named_section_suffix
)
545 if (decl
&& DECL_SECTION_NAME (decl
))
547 if (named_section_suffix
)
549 const char *dsn
= DECL_SECTION_NAME (decl
);
550 const char *stripped_name
;
553 name
= (char *) alloca (strlen (dsn
) + 1);
557 stripped_name
= targetm
.strip_name_encoding (name
);
559 buffer
= ACONCAT ((stripped_name
, named_section_suffix
, NULL
));
560 return get_named_section (decl
, buffer
, 0);
562 else if (symtab_node::get (decl
)->implicit_section
)
566 /* Do not try to split gnu_linkonce functions. This gets somewhat
568 if (DECL_COMDAT_GROUP (decl
) && !HAVE_COMDAT_GROUP
)
570 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
571 name
= targetm
.strip_name_encoding (name
);
572 return get_named_section (decl
, ACONCAT ((text_section_name
, ".",
578 return get_named_section (decl
, text_section_name
, 0);
581 /* Choose named function section based on its frequency. */
584 default_function_section (tree decl
, enum node_frequency freq
,
585 bool startup
, bool exit
)
587 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
588 /* Old GNU linkers have buggy --gc-section support, which sometimes
589 results in .gcc_except_table* sections being garbage collected. */
591 && symtab_node::get (decl
)->implicit_section
)
595 if (!flag_reorder_functions
596 || !targetm_common
.have_named_sections
)
598 /* Startup code should go to startup subsection unless it is
599 unlikely executed (this happens especially with function splitting
600 where we can split away unnecessary parts of static constructors. */
601 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
603 /* During LTO the tp_first_run profiling will naturally place all
604 initialization code first. Using separate section is counter-productive
605 because startup only code may call functions which are no longer
608 || !cgraph_node::get (decl
)->tp_first_run
609 || !opt_for_fn (decl
, flag_profile_reorder_functions
))
610 return get_named_text_section (decl
, ".text.startup", NULL
);
615 /* Similarly for exit. */
616 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
617 return get_named_text_section (decl
, ".text.exit", NULL
);
619 /* Group cold functions together, similarly for hot code. */
622 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
623 return get_named_text_section (decl
, ".text.unlikely", NULL
);
624 case NODE_FREQUENCY_HOT
:
625 return get_named_text_section (decl
, ".text.hot", NULL
);
632 /* Return the section for function DECL.
634 If DECL is NULL_TREE, return the text section. We can be passed
635 NULL_TREE under some circumstances by dbxout.c at least.
637 If FORCE_COLD is true, return cold function section ignoring
638 the frequency info of cgraph_node. */
641 function_section_1 (tree decl
, bool force_cold
)
643 section
*section
= NULL
;
644 enum node_frequency freq
= NODE_FREQUENCY_NORMAL
;
645 bool startup
= false, exit
= false;
649 struct cgraph_node
*node
= cgraph_node::get (decl
);
653 freq
= node
->frequency
;
654 startup
= node
->only_called_at_startup
;
655 exit
= node
->only_called_at_exit
;
659 freq
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
661 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
662 if (decl
!= NULL_TREE
663 && DECL_SECTION_NAME (decl
) != NULL
)
665 if (targetm
.asm_out
.function_section
)
666 section
= targetm
.asm_out
.function_section (decl
, freq
,
670 return get_named_section (decl
, NULL
, 0);
673 return targetm
.asm_out
.select_section
674 (decl
, freq
== NODE_FREQUENCY_UNLIKELY_EXECUTED
,
675 symtab_node::get (decl
)->definition_alignment ());
677 if (targetm
.asm_out
.function_section
)
678 section
= targetm
.asm_out
.function_section (decl
, freq
, startup
, exit
);
681 return hot_function_section (decl
);
685 /* Return the section for function DECL.
687 If DECL is NULL_TREE, return the text section. We can be passed
688 NULL_TREE under some circumstances by dbxout.c at least. */
691 function_section (tree decl
)
693 /* Handle cases where function splitting code decides
694 to put function entry point into unlikely executed section
695 despite the fact that the function itself is not cold
696 (i.e. it is called rarely but contains a hot loop that is
697 better to live in hot subsection for the code locality). */
698 return function_section_1 (decl
,
699 first_function_block_is_cold
);
702 /* Return the section for the current function, take IN_COLD_SECTION_P
706 current_function_section (void)
708 return function_section_1 (current_function_decl
, in_cold_section_p
);
711 /* Tell assembler to switch to unlikely-to-be-executed text section. */
714 unlikely_text_section (void)
716 return function_section_1 (current_function_decl
, true);
719 /* When called within a function context, return true if the function
720 has been assigned a cold text section and if SECT is that section.
721 When called outside a function context, return true if SECT is the
722 default cold section. */
725 unlikely_text_section_p (section
*sect
)
727 return sect
== function_section_1 (current_function_decl
, true);
730 /* Switch to the other function partition (if inside of hot section
731 into cold section, otherwise into the hot section). */
734 switch_to_other_text_partition (void)
736 in_cold_section_p
= !in_cold_section_p
;
737 switch_to_section (current_function_section ());
740 /* Return the read-only or relocated read-only data section
741 associated with function DECL. */
744 default_function_rodata_section (tree decl
, bool relocatable
)
753 sname
= ".data.rel.ro.local";
754 flags
= (SECTION_WRITE
| SECTION_RELRO
);
759 if (decl
&& DECL_SECTION_NAME (decl
))
761 const char *name
= DECL_SECTION_NAME (decl
);
763 if (DECL_COMDAT_GROUP (decl
) && HAVE_COMDAT_GROUP
)
769 dot
= strchr (name
+ 1, '.');
772 len
= strlen (dot
) + strlen (sname
) + 1;
773 rname
= (char *) alloca (len
);
775 strcpy (rname
, sname
);
777 return get_section (rname
, (SECTION_LINKONCE
| flags
), decl
);
779 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo or
780 .gnu.linkonce.d.rel.ro.local.foo if the jump table is relocatable. */
781 else if (DECL_COMDAT_GROUP (decl
)
782 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
789 len
= strlen (name
) + strlen (".rel.ro.local") + 1;
790 rname
= (char *) alloca (len
);
792 strcpy (rname
, ".gnu.linkonce.d.rel.ro.local");
793 strcat (rname
, name
+ 15);
797 len
= strlen (name
) + 1;
798 rname
= (char *) alloca (len
);
800 memcpy (rname
, name
, len
);
803 return get_section (rname
, (SECTION_LINKONCE
| flags
), decl
);
805 /* For .text.foo we want to use .rodata.foo. */
806 else if (flag_function_sections
&& flag_data_sections
807 && strncmp (name
, ".text.", 6) == 0)
809 size_t len
= strlen (name
) + 1;
810 char *rname
= (char *) alloca (len
+ strlen (sname
) - 5);
812 memcpy (rname
, sname
, strlen (sname
));
813 memcpy (rname
+ strlen (sname
), name
+ 5, len
- 5);
814 return get_section (rname
, flags
, decl
);
819 return get_section (sname
, flags
, decl
);
821 return readonly_data_section
;
824 /* Return the read-only data section associated with function DECL
825 for targets where that section should be always the single
826 readonly data section. */
829 default_no_function_rodata_section (tree
, bool)
831 return readonly_data_section
;
834 /* A subroutine of mergeable_string_section and mergeable_constant_section. */
837 function_mergeable_rodata_prefix (void)
839 section
*s
= targetm
.asm_out
.function_rodata_section (current_function_decl
,
841 if (SECTION_STYLE (s
) == SECTION_NAMED
)
842 return s
->named
.name
;
844 return targetm
.asm_out
.mergeable_rodata_prefix
;
847 /* Return the section to use for string merging. */
850 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
851 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
852 unsigned int flags ATTRIBUTE_UNUSED
)
856 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
857 && TREE_CODE (decl
) == STRING_CST
858 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
860 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
861 && TREE_STRING_LENGTH (decl
) == len
)
863 scalar_int_mode mode
;
864 unsigned int modesize
;
868 const char *prefix
= function_mergeable_rodata_prefix ();
869 char *name
= (char *) alloca (strlen (prefix
) + 30);
871 mode
= SCALAR_INT_TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
872 modesize
= GET_MODE_BITSIZE (mode
);
873 if (modesize
>= 8 && modesize
<= 256
874 && (modesize
& (modesize
- 1)) == 0)
876 if (align
< modesize
)
879 if (!HAVE_LD_ALIGNED_SHF_MERGE
&& align
> 8)
880 return readonly_data_section
;
882 str
= TREE_STRING_POINTER (decl
);
883 unit
= GET_MODE_SIZE (mode
);
885 /* Check for embedded NUL characters. */
886 for (i
= 0; i
< len
; i
+= unit
)
888 for (j
= 0; j
< unit
; j
++)
889 if (str
[i
+ j
] != '\0')
894 if (i
== len
- unit
|| (unit
== 1 && i
== len
))
896 sprintf (name
, "%s.str%d.%d", prefix
,
897 modesize
/ 8, (int) (align
/ 8));
898 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
899 return get_section (name
, flags
, NULL
);
904 return readonly_data_section
;
907 /* Return the section to use for constant merging. */
910 mergeable_constant_section (machine_mode mode ATTRIBUTE_UNUSED
,
911 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
912 unsigned int flags ATTRIBUTE_UNUSED
)
914 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
917 && known_le (GET_MODE_BITSIZE (mode
), align
)
920 && (align
& (align
- 1)) == 0
921 && (HAVE_LD_ALIGNED_SHF_MERGE
? 1 : align
== 8))
923 const char *prefix
= function_mergeable_rodata_prefix ();
924 char *name
= (char *) alloca (strlen (prefix
) + 30);
926 sprintf (name
, "%s.cst%d", prefix
, (int) (align
/ 8));
927 flags
|= (align
/ 8) | SECTION_MERGE
;
928 return get_section (name
, flags
, NULL
);
930 return readonly_data_section
;
933 /* Given NAME, a putative register name, discard any customary prefixes. */
936 strip_reg_name (const char *name
)
938 #ifdef REGISTER_PREFIX
939 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
940 name
+= strlen (REGISTER_PREFIX
);
942 if (name
[0] == '%' || name
[0] == '#')
947 /* The user has asked for a DECL to have a particular name. Set (or
948 change) it in such a way that we don't prefix an underscore to
951 set_user_assembler_name (tree decl
, const char *name
)
953 char *starred
= (char *) alloca (strlen (name
) + 2);
955 strcpy (starred
+ 1, name
);
956 symtab
->change_decl_assembler_name (decl
, get_identifier (starred
));
957 SET_DECL_RTL (decl
, NULL_RTX
);
960 /* Decode an `asm' spec for a declaration as a register name.
961 Return the register number, or -1 if nothing specified,
962 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
963 or -3 if ASMSPEC is `cc' and is not recognized,
964 or -4 if ASMSPEC is `memory' and is not recognized.
965 Accept an exact spelling or a decimal number.
966 Prefixes such as % are optional. */
969 decode_reg_name_and_count (const char *asmspec
, int *pnregs
)
971 /* Presume just one register is clobbered. */
978 /* Get rid of confusing prefixes. */
979 asmspec
= strip_reg_name (asmspec
);
981 /* Allow a decimal number as a "register name". */
982 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
983 if (! ISDIGIT (asmspec
[i
]))
985 if (asmspec
[0] != 0 && i
< 0)
988 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0 && reg_names
[i
][0])
994 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
996 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
999 #ifdef OVERLAPPING_REGISTER_NAMES
1003 const char *const name
;
1006 } table
[] = OVERLAPPING_REGISTER_NAMES
;
1008 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
1009 if (table
[i
].name
[0]
1010 && ! strcmp (asmspec
, table
[i
].name
))
1012 *pnregs
= table
[i
].nregs
;
1013 return table
[i
].number
;
1016 #endif /* OVERLAPPING_REGISTER_NAMES */
1018 #ifdef ADDITIONAL_REGISTER_NAMES
1020 static const struct { const char *const name
; const int number
; } table
[]
1021 = ADDITIONAL_REGISTER_NAMES
;
1023 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
1024 if (table
[i
].name
[0]
1025 && ! strcmp (asmspec
, table
[i
].name
)
1026 && reg_names
[table
[i
].number
][0])
1027 return table
[i
].number
;
1029 #endif /* ADDITIONAL_REGISTER_NAMES */
1031 if (!strcmp (asmspec
, "memory"))
1034 if (!strcmp (asmspec
, "cc"))
1044 decode_reg_name (const char *name
)
1047 return decode_reg_name_and_count (name
, &count
);
1051 /* Return true if DECL's initializer is suitable for a BSS section. */
1054 bss_initializer_p (const_tree decl
, bool named
)
1056 /* Do not put non-common constants into the .bss section, they belong in
1057 a readonly section, except when NAMED is true. */
1058 return ((!TREE_READONLY (decl
) || DECL_COMMON (decl
) || named
)
1059 && (DECL_INITIAL (decl
) == NULL
1060 /* In LTO we have no errors in program; error_mark_node is used
1061 to mark offlined constructors. */
1062 || (DECL_INITIAL (decl
) == error_mark_node
1064 || (flag_zero_initialized_in_bss
1065 && initializer_zerop (DECL_INITIAL (decl
))
1066 /* A decl with the "persistent" attribute applied and
1067 explicitly initialized to 0 should not be treated as a BSS
1069 && !DECL_PERSISTENT_P (decl
))));
1072 /* Compute the alignment of variable specified by DECL.
1073 DONT_OUTPUT_DATA is from assemble_variable. */
1076 align_variable (tree decl
, bool dont_output_data
)
1078 unsigned int align
= DECL_ALIGN (decl
);
1080 /* In the case for initialing an array whose length isn't specified,
1081 where we have not yet been able to do the layout,
1082 figure out the proper alignment now. */
1083 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1084 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1085 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1087 /* Some object file formats have a maximum alignment which they support.
1088 In particular, a.out format supports a maximum alignment of 4. */
1089 if (align
> MAX_OFILE_ALIGNMENT
)
1091 error ("alignment of %q+D is greater than maximum object "
1092 "file alignment %d", decl
,
1093 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1094 align
= MAX_OFILE_ALIGNMENT
;
1097 if (! DECL_USER_ALIGN (decl
))
1099 #ifdef DATA_ABI_ALIGNMENT
1100 unsigned int data_abi_align
1101 = DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1102 /* For backwards compatibility, don't assume the ABI alignment for
1104 if (! DECL_THREAD_LOCAL_P (decl
) || data_abi_align
<= BITS_PER_WORD
)
1105 align
= data_abi_align
;
1108 /* On some machines, it is good to increase alignment sometimes.
1109 But as DECL_ALIGN is used both for actually emitting the variable
1110 and for code accessing the variable as guaranteed alignment, we
1111 can only increase the alignment if it is a performance optimization
1112 if the references to it must bind to the current definition. */
1113 if (decl_binds_to_current_def_p (decl
)
1114 && !DECL_VIRTUAL_P (decl
))
1116 #ifdef DATA_ALIGNMENT
1117 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1118 /* Don't increase alignment too much for TLS variables - TLS space
1120 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
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
1129 = targetm
.constant_alignment (DECL_INITIAL (decl
), align
);
1130 /* Don't increase alignment too much for TLS variables - TLS
1131 space is too precious. */
1132 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1133 align
= const_align
;
1138 /* Reset the alignment in case we have made it tighter, so we can benefit
1139 from it in get_pointer_alignment. */
1140 SET_DECL_ALIGN (decl
, align
);
1143 /* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1144 beyond what align_variable returned. */
1147 get_variable_align (tree decl
)
1149 unsigned int align
= DECL_ALIGN (decl
);
1151 /* For user aligned vars or static vars align_variable already did
1153 if (DECL_USER_ALIGN (decl
) || !TREE_PUBLIC (decl
))
1156 #ifdef DATA_ABI_ALIGNMENT
1157 if (DECL_THREAD_LOCAL_P (decl
))
1158 align
= DATA_ABI_ALIGNMENT (TREE_TYPE (decl
), align
);
1161 /* For decls that bind to the current definition, align_variable
1162 did also everything, except for not assuming ABI required alignment
1163 of TLS variables. For other vars, increase the alignment here
1164 as an optimization. */
1165 if (!decl_binds_to_current_def_p (decl
))
1167 /* On some machines, it is good to increase alignment sometimes. */
1168 #ifdef DATA_ALIGNMENT
1169 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1170 /* Don't increase alignment too much for TLS variables - TLS space
1172 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1175 if (DECL_INITIAL (decl
) != 0
1176 /* In LTO we have no errors in program; error_mark_node is used
1177 to mark offlined constructors. */
1178 && (in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
))
1180 unsigned int const_align
1181 = targetm
.constant_alignment (DECL_INITIAL (decl
), align
);
1182 /* Don't increase alignment too much for TLS variables - TLS space
1184 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1185 align
= const_align
;
1192 /* Return the section into which the given VAR_DECL or CONST_DECL
1193 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1194 section should be used wherever possible. */
1197 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1199 addr_space_t as
= ADDR_SPACE_GENERIC
;
1201 varpool_node
*vnode
= varpool_node::get (decl
);
1204 vnode
= vnode
->ultimate_alias_target ();
1208 if (TREE_TYPE (decl
) != error_mark_node
)
1209 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1211 /* We need the constructor to figure out reloc flag. */
1213 vnode
->get_constructor ();
1215 if (DECL_COMMON (decl
)
1216 && !(HAVE_GAS_SHF_GNU_RETAIN
&& DECL_PRESERVE_P (decl
)))
1218 /* If the decl has been given an explicit section name, or it resides
1219 in a non-generic address space, then it isn't common, and shouldn't
1220 be handled as such. */
1221 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1222 && ADDR_SPACE_GENERIC_P (as
));
1223 if (DECL_THREAD_LOCAL_P (decl
))
1224 return tls_comm_section
;
1225 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1226 return comm_section
;
1229 if (DECL_INITIAL (decl
) == error_mark_node
)
1230 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1231 else if (DECL_INITIAL (decl
))
1232 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1236 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1237 if (IN_NAMED_SECTION (decl
))
1239 section
*sect
= get_named_section (decl
, NULL
, reloc
);
1241 if ((sect
->common
.flags
& SECTION_BSS
)
1242 && !bss_initializer_p (decl
, true))
1244 error_at (DECL_SOURCE_LOCATION (decl
),
1245 "only zero initializers are allowed in section %qs",
1247 DECL_INITIAL (decl
) = error_mark_node
;
1252 if (ADDR_SPACE_GENERIC_P (as
)
1253 && !DECL_THREAD_LOCAL_P (decl
)
1254 && !DECL_NOINIT_P (decl
)
1255 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1256 && bss_initializer_p (decl
))
1258 if (!TREE_PUBLIC (decl
)
1259 && !((flag_sanitize
& SANITIZE_ADDRESS
)
1260 && asan_protect_global (decl
)))
1261 return lcomm_section
;
1262 if (bss_noswitch_section
)
1263 return bss_noswitch_section
;
1266 return targetm
.asm_out
.select_section (decl
, reloc
,
1267 get_variable_align (decl
));
1270 /* Return the block into which object_block DECL should be placed. */
1272 static struct object_block
*
1273 get_block_for_decl (tree decl
)
1279 /* The object must be defined in this translation unit. */
1280 if (DECL_EXTERNAL (decl
))
1283 /* There's no point using object blocks for something that is
1284 isolated by definition. */
1285 if (DECL_COMDAT_GROUP (decl
))
1289 /* We can only calculate block offsets if the decl has a known
1291 if (DECL_SIZE_UNIT (decl
) == NULL
)
1293 if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl
)))
1296 /* Find out which section should contain DECL. We cannot put it into
1297 an object block if it requires a standalone definition. */
1299 align_variable (decl
, 0);
1300 sect
= get_variable_section (decl
, true);
1301 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1304 return get_block_for_section (sect
);
1307 /* Make sure block symbol SYMBOL is in block BLOCK. */
1310 change_symbol_block (rtx symbol
, struct object_block
*block
)
1312 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1314 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1315 SYMBOL_REF_BLOCK (symbol
) = block
;
1319 /* Return true if it is possible to put DECL in an object_block. */
1322 use_blocks_for_decl_p (tree decl
)
1324 struct symtab_node
*snode
;
1326 /* Only data DECLs can be placed into object blocks. */
1327 if (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
1330 /* DECL_INITIAL (decl) set to decl is a hack used for some decls that
1331 are never used from code directly and we never want object block handling
1333 if (DECL_INITIAL (decl
) == decl
)
1336 /* If this decl is an alias, then we don't want to emit a
1339 && (snode
= symtab_node::get (decl
)) != NULL
1343 return targetm
.use_blocks_for_decl_p (decl
);
1346 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1347 until we find an identifier that is not itself a transparent alias.
1348 Modify the alias passed to it by reference (and all aliases on the
1349 way to the ultimate target), such that they do not have to be
1350 followed again, and return the ultimate target of the alias
1354 ultimate_transparent_alias_target (tree
*alias
)
1356 tree target
= *alias
;
1358 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
1360 gcc_assert (TREE_CHAIN (target
));
1361 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
1362 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
1363 && ! TREE_CHAIN (target
));
1370 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1371 have static storage duration. In other words, it should not be an
1372 automatic variable, including PARM_DECLs.
1374 There is, however, one exception: this function handles variables
1375 explicitly placed in a particular register by the user.
1377 This is never called for PARM_DECL nodes. */
1380 make_decl_rtl (tree decl
)
1382 const char *name
= 0;
1387 /* Check that we are not being given an automatic variable. */
1388 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1389 && TREE_CODE (decl
) != RESULT_DECL
);
1391 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1392 gcc_assert (!VAR_P (decl
)
1393 || TREE_STATIC (decl
)
1394 || TREE_PUBLIC (decl
)
1395 || DECL_EXTERNAL (decl
)
1396 || DECL_REGISTER (decl
));
1398 /* And that we were not given a type or a label. */
1399 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1400 && TREE_CODE (decl
) != LABEL_DECL
);
1402 /* For a duplicate declaration, we can be called twice on the
1403 same DECL node. Don't discard the RTL already made. */
1404 if (DECL_RTL_SET_P (decl
))
1406 /* If the old RTL had the wrong mode, fix the mode. */
1407 x
= DECL_RTL (decl
);
1408 if (GET_MODE (x
) != DECL_MODE (decl
))
1409 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1411 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1414 /* ??? Another way to do this would be to maintain a hashed
1415 table of such critters. Instead of adding stuff to a DECL
1416 to give certain attributes to it, we could use an external
1417 hash map from DECL to set of attributes. */
1419 /* Let the target reassign the RTL if it wants.
1420 This is necessary, for example, when one machine specific
1421 decl attribute overrides another. */
1422 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1424 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1425 on the new decl information. */
1427 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1428 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1429 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1434 /* If this variable belongs to the global constant pool, retrieve the
1435 pre-computed RTL or recompute it in LTO mode. */
1436 if (VAR_P (decl
) && DECL_IN_CONSTANT_POOL (decl
))
1438 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1442 id
= DECL_ASSEMBLER_NAME (decl
);
1443 name
= IDENTIFIER_POINTER (id
);
1445 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1446 && DECL_REGISTER (decl
))
1448 error ("register name not specified for %q+D", decl
);
1450 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1452 const char *asmspec
= name
+1;
1453 machine_mode mode
= DECL_MODE (decl
);
1454 reg_number
= decode_reg_name (asmspec
);
1455 /* First detect errors in declaring global registers. */
1456 if (reg_number
== -1)
1457 error ("register name not specified for %q+D", decl
);
1458 else if (reg_number
< 0)
1459 error ("invalid register name for %q+D", decl
);
1460 else if (mode
== BLKmode
)
1461 error ("data type of %q+D isn%'t suitable for a register",
1463 else if (!in_hard_reg_set_p (accessible_reg_set
, mode
, reg_number
))
1464 error ("the register specified for %q+D cannot be accessed"
1465 " by the current target", decl
);
1466 else if (!in_hard_reg_set_p (operand_reg_set
, mode
, reg_number
))
1467 error ("the register specified for %q+D is not general enough"
1468 " to be used as a register variable", decl
);
1469 else if (!targetm
.hard_regno_mode_ok (reg_number
, mode
))
1470 error ("register specified for %q+D isn%'t suitable for data type",
1472 /* Now handle properly declared static register variables. */
1477 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1479 DECL_INITIAL (decl
) = 0;
1480 error ("global register variable has initial value");
1482 if (TREE_THIS_VOLATILE (decl
))
1483 warning (OPT_Wvolatile_register_var
,
1484 "optimization may eliminate reads and/or "
1485 "writes to register variables");
1487 /* If the user specified one of the eliminables registers here,
1488 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1489 confused with that register and be eliminated. This usage is
1490 somewhat suspect... */
1492 SET_DECL_RTL (decl
, gen_raw_REG (mode
, reg_number
));
1493 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1494 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1496 if (TREE_STATIC (decl
))
1498 /* Make this register global, so not usable for anything
1500 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1501 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1502 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1504 nregs
= hard_regno_nregs (reg_number
, mode
);
1506 globalize_reg (decl
, reg_number
+ --nregs
);
1509 /* As a register variable, it has no section. */
1512 /* Avoid internal errors from invalid register
1514 SET_DECL_ASSEMBLER_NAME (decl
, NULL_TREE
);
1515 DECL_HARD_REGISTER (decl
) = 0;
1516 /* Also avoid SSA inconsistencies by pretending this is an external
1518 DECL_EXTERNAL (decl
) = 1;
1521 /* Now handle ordinary static variables and functions (in memory).
1522 Also handle vars declared register invalidly. */
1523 else if (name
[0] == '*')
1525 #ifdef REGISTER_PREFIX
1526 if (strlen (REGISTER_PREFIX
) != 0)
1528 reg_number
= decode_reg_name (name
);
1529 if (reg_number
>= 0 || reg_number
== -3)
1530 error ("register name given for non-register variable %q+D", decl
);
1535 /* Specifying a section attribute on a variable forces it into a
1536 non-.bss section, and thus it cannot be common. */
1537 /* FIXME: In general this code should not be necessary because
1538 visibility pass is doing the same work. But notice_global_symbol
1539 is called early and it needs to make DECL_RTL to get the name.
1540 we take care of recomputing the DECL_RTL after visibility is changed. */
1542 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
1543 && DECL_SECTION_NAME (decl
) != NULL
1544 && DECL_INITIAL (decl
) == NULL_TREE
1545 && DECL_COMMON (decl
))
1546 DECL_COMMON (decl
) = 0;
1548 /* Variables can't be both common and weak. */
1549 if (VAR_P (decl
) && DECL_WEAK (decl
))
1550 DECL_COMMON (decl
) = 0;
1552 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1553 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1556 machine_mode address_mode
= Pmode
;
1557 if (TREE_TYPE (decl
) != error_mark_node
)
1559 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1560 address_mode
= targetm
.addr_space
.address_mode (as
);
1562 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1564 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1565 SET_SYMBOL_REF_DECL (x
, decl
);
1567 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1568 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1569 set_mem_attributes (x
, decl
, 1);
1570 SET_DECL_RTL (decl
, x
);
1572 /* Optionally set flags or add text to the name to record information
1573 such as that it is a function name.
1574 If the name is changed, the macro ASM_OUTPUT_LABELREF
1575 will have to know how to strip this information. */
1576 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1579 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1580 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1584 make_decl_rtl_for_debug (tree decl
)
1586 unsigned int save_aliasing_flag
;
1589 if (DECL_RTL_SET_P (decl
))
1590 return DECL_RTL (decl
);
1592 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1593 call new_alias_set. If running with -fcompare-debug, sometimes
1594 we do not want to create alias sets that will throw the alias
1595 numbers off in the comparison dumps. So... clearing
1596 flag_strict_aliasing will keep new_alias_set() from creating a
1598 save_aliasing_flag
= flag_strict_aliasing
;
1599 flag_strict_aliasing
= 0;
1601 rtl
= DECL_RTL (decl
);
1602 /* Reset DECL_RTL back, as various parts of the compiler expects
1603 DECL_RTL set meaning it is actually going to be output. */
1604 SET_DECL_RTL (decl
, NULL
);
1606 flag_strict_aliasing
= save_aliasing_flag
;
1610 /* Output a string of literal assembler code
1611 for an `asm' keyword used between functions. */
1614 assemble_asm (tree string
)
1619 if (TREE_CODE (string
) == ADDR_EXPR
)
1620 string
= TREE_OPERAND (string
, 0);
1622 p
= TREE_STRING_POINTER (string
);
1623 fprintf (asm_out_file
, "%s%s\n", p
[0] == '\t' ? "" : "\t", p
);
1626 /* Write the address of the entity given by SYMBOL to SEC. */
1628 assemble_addr_to_section (rtx symbol
, section
*sec
)
1630 switch_to_section (sec
);
1631 assemble_align (POINTER_SIZE
);
1632 assemble_integer (symbol
, POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
1635 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1636 not) section for PRIORITY. */
1638 get_cdtor_priority_section (int priority
, bool constructor_p
)
1640 /* Buffer conservatively large enough for the full range of a 32-bit
1641 int plus the text below. */
1644 /* ??? This only works reliably with the GNU linker. */
1645 sprintf (buf
, "%s.%.5u",
1646 constructor_p
? ".ctors" : ".dtors",
1647 /* Invert the numbering so the linker puts us in the proper
1648 order; constructors are run from right to left, and the
1649 linker sorts in increasing order. */
1650 MAX_INIT_PRIORITY
- priority
);
1651 return get_section (buf
, SECTION_WRITE
, NULL
);
1655 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1659 if (priority
!= DEFAULT_INIT_PRIORITY
)
1660 sec
= get_cdtor_priority_section (priority
,
1661 /*constructor_p=*/false);
1663 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1665 assemble_addr_to_section (symbol
, sec
);
1668 #ifdef DTORS_SECTION_ASM_OP
1670 default_dtor_section_asm_out_destructor (rtx symbol
,
1671 int priority ATTRIBUTE_UNUSED
)
1673 assemble_addr_to_section (symbol
, dtors_section
);
1678 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1682 if (priority
!= DEFAULT_INIT_PRIORITY
)
1683 sec
= get_cdtor_priority_section (priority
,
1684 /*constructor_p=*/true);
1686 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1688 assemble_addr_to_section (symbol
, sec
);
1691 #ifdef CTORS_SECTION_ASM_OP
1693 default_ctor_section_asm_out_constructor (rtx symbol
,
1694 int priority ATTRIBUTE_UNUSED
)
1696 assemble_addr_to_section (symbol
, ctors_section
);
1700 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1701 a nonzero value if the constant pool should be output before the
1702 start of the function, or a zero value if the pool should output
1703 after the end of the function. The default is to put it before the
1706 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1707 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1710 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1711 to be output to assembler.
1712 Set first_global_object_name and weak_global_object_name as appropriate. */
1715 notice_global_symbol (tree decl
)
1717 const char **t
= &first_global_object_name
;
1719 if (first_global_object_name
1720 || !TREE_PUBLIC (decl
)
1721 || DECL_EXTERNAL (decl
)
1722 || !DECL_NAME (decl
)
1723 || (VAR_P (decl
) && DECL_HARD_REGISTER (decl
))
1724 || (TREE_CODE (decl
) != FUNCTION_DECL
1726 || (DECL_COMMON (decl
)
1727 && (DECL_INITIAL (decl
) == 0
1728 || DECL_INITIAL (decl
) == error_mark_node
)))))
1731 /* We win when global object is found, but it is useful to know about weak
1732 symbol as well so we can produce nicer unique names. */
1733 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1734 t
= &weak_global_object_name
;
1738 tree id
= DECL_ASSEMBLER_NAME (decl
);
1739 ultimate_transparent_alias_target (&id
);
1740 *t
= ggc_strdup (targetm
.strip_name_encoding (IDENTIFIER_POINTER (id
)));
1744 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1745 current function goes into the cold section, so that targets can use
1746 current_function_section during RTL expansion. DECL describes the
1750 decide_function_section (tree decl
)
1752 first_function_block_is_cold
= false;
1754 if (DECL_SECTION_NAME (decl
))
1756 struct cgraph_node
*node
= cgraph_node::get (current_function_decl
);
1757 /* Calls to function_section rely on first_function_block_is_cold
1759 first_function_block_is_cold
= (node
1761 == NODE_FREQUENCY_UNLIKELY_EXECUTED
);
1764 in_cold_section_p
= first_function_block_is_cold
;
1767 /* Get the function's name, as described by its RTL. This may be
1768 different from the DECL_NAME name used in the source file. */
1770 get_fnname_from_decl (tree decl
)
1772 rtx x
= DECL_RTL (decl
);
1773 gcc_assert (MEM_P (x
));
1775 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
1779 /* Output assembler code for the constant pool of a function and associated
1780 with defining the name of the function. DECL describes the function.
1781 NAME is the function's name. For the constant pool, we use the current
1782 constant pool data. */
1785 assemble_start_function (tree decl
, const char *fnname
)
1788 char tmp_label
[100];
1789 bool hot_label_written
= false;
1791 if (crtl
->has_bb_partition
)
1793 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1794 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1795 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1796 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1797 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1798 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1799 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1800 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1802 cold_function_name
= NULL_TREE
;
1806 crtl
->subsections
.hot_section_label
= NULL
;
1807 crtl
->subsections
.cold_section_label
= NULL
;
1808 crtl
->subsections
.hot_section_end_label
= NULL
;
1809 crtl
->subsections
.cold_section_end_label
= NULL
;
1812 /* The following code does not need preprocessing in the assembler. */
1816 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1817 output_constant_pool (fnname
, decl
);
1819 align
= symtab_node::get (decl
)->definition_alignment ();
1821 /* Make sure the not and cold text (code) sections are properly
1822 aligned. This is necessary here in the case where the function
1823 has both hot and cold sections, because we don't want to re-set
1824 the alignment when the section switch happens mid-function. */
1826 if (crtl
->has_bb_partition
)
1828 first_function_block_is_cold
= false;
1830 switch_to_section (unlikely_text_section ());
1831 assemble_align (align
);
1832 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1834 /* When the function starts with a cold section, we need to explicitly
1835 align the hot section and write out the hot section label.
1836 But if the current function is a thunk, we do not have a CFG. */
1838 && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun
)->next_bb
) == BB_COLD_PARTITION
)
1840 switch_to_section (text_section
);
1841 assemble_align (align
);
1842 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1843 hot_label_written
= true;
1844 first_function_block_is_cold
= true;
1846 in_cold_section_p
= first_function_block_is_cold
;
1850 /* Switch to the correct text section for the start of the function. */
1852 switch_to_section (function_section (decl
));
1853 if (crtl
->has_bb_partition
&& !hot_label_written
)
1854 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1856 /* Tell assembler to move to target machine's alignment for functions. */
1857 align
= floor_log2 (align
/ BITS_PER_UNIT
);
1860 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1863 /* Handle a user-specified function alignment.
1864 Note that we still need to align to DECL_ALIGN, as above,
1865 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1866 if (! DECL_USER_ALIGN (decl
)
1867 && align_functions
.levels
[0].log
> align
1868 && optimize_function_for_speed_p (cfun
))
1870 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1871 int align_log
= align_functions
.levels
[0].log
;
1873 int max_skip
= align_functions
.levels
[0].maxskip
;
1874 if (flag_limit_function_alignment
&& crtl
->max_insn_address
> 0
1875 && max_skip
>= crtl
->max_insn_address
)
1876 max_skip
= crtl
->max_insn_address
- 1;
1878 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1879 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
, align_log
, max_skip
);
1880 if (max_skip
== align_functions
.levels
[0].maxskip
)
1881 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1882 align_functions
.levels
[1].log
,
1883 align_functions
.levels
[1].maxskip
);
1885 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions
.levels
[0].log
);
1889 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1890 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1893 if (!DECL_IGNORED_P (decl
))
1894 (*debug_hooks
->begin_function
) (decl
);
1896 /* Make function name accessible from other files, if appropriate. */
1898 if (TREE_PUBLIC (decl
))
1900 notice_global_symbol (decl
);
1902 globalize_decl (decl
);
1904 maybe_assemble_visibility (decl
);
1907 if (DECL_PRESERVE_P (decl
))
1908 targetm
.asm_out
.mark_decl_preserved (fnname
);
1910 unsigned short patch_area_size
= crtl
->patch_area_size
;
1911 unsigned short patch_area_entry
= crtl
->patch_area_entry
;
1913 /* Emit the patching area before the entry label, if any. */
1914 if (patch_area_entry
> 0)
1915 targetm
.asm_out
.print_patchable_function_entry (asm_out_file
,
1916 patch_area_entry
, true);
1918 /* Do any machine/system dependent processing of the function name. */
1919 #ifdef ASM_DECLARE_FUNCTION_NAME
1920 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1922 /* Standard thing is just output label for the function. */
1923 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1924 #endif /* ASM_DECLARE_FUNCTION_NAME */
1926 /* And the area after the label. Record it if we haven't done so yet. */
1927 if (patch_area_size
> patch_area_entry
)
1928 targetm
.asm_out
.print_patchable_function_entry (asm_out_file
,
1931 patch_area_entry
== 0);
1933 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1934 saw_no_split_stack
= true;
1937 /* Output assembler code associated with defining the size of the
1938 function. DECL describes the function. NAME is the function's name. */
1941 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1943 #ifdef ASM_DECLARE_FUNCTION_SIZE
1944 /* We could have switched section in the middle of the function. */
1945 if (crtl
->has_bb_partition
)
1946 switch_to_section (function_section (decl
));
1947 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1949 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1951 output_constant_pool (fnname
, decl
);
1952 switch_to_section (function_section (decl
)); /* need to switch back */
1954 /* Output labels for end of hot/cold text sections (to be used by
1956 if (crtl
->has_bb_partition
)
1958 section
*save_text_section
;
1960 save_text_section
= in_section
;
1961 switch_to_section (unlikely_text_section ());
1962 #ifdef ASM_DECLARE_COLD_FUNCTION_SIZE
1963 if (cold_function_name
!= NULL_TREE
)
1964 ASM_DECLARE_COLD_FUNCTION_SIZE (asm_out_file
,
1965 IDENTIFIER_POINTER (cold_function_name
),
1968 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1969 if (first_function_block_is_cold
)
1970 switch_to_section (text_section
);
1972 switch_to_section (function_section (decl
));
1973 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1974 switch_to_section (save_text_section
);
1978 /* Assemble code to leave SIZE bytes of zeros. */
1981 assemble_zeros (unsigned HOST_WIDE_INT size
)
1983 /* Do no output if -fsyntax-only. */
1984 if (flag_syntax_only
)
1987 #ifdef ASM_NO_SKIP_IN_TEXT
1988 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1989 so we must output 0s explicitly in the text section. */
1990 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1992 unsigned HOST_WIDE_INT i
;
1993 for (i
= 0; i
< size
; i
++)
1994 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1999 ASM_OUTPUT_SKIP (asm_out_file
, size
);
2002 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
2005 assemble_align (unsigned int align
)
2007 if (align
> BITS_PER_UNIT
)
2009 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2013 /* Assemble a string constant with the specified C string as contents. */
2016 assemble_string (const char *p
, int size
)
2021 /* If the string is very long, split it up. */
2025 int thissize
= size
- pos
;
2026 if (thissize
> maximum
)
2029 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
2037 /* A noswitch_section_callback for lcomm_section. */
2040 emit_local (tree decl ATTRIBUTE_UNUSED
,
2041 const char *name ATTRIBUTE_UNUSED
,
2042 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2043 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2045 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
2046 unsigned int align
= symtab_node::get (decl
)->definition_alignment ();
2047 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
2050 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
2051 unsigned int align
= symtab_node::get (decl
)->definition_alignment ();
2052 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, align
);
2055 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2060 /* A noswitch_section_callback for bss_noswitch_section. */
2062 #if defined ASM_OUTPUT_ALIGNED_BSS
2064 emit_bss (tree decl ATTRIBUTE_UNUSED
,
2065 const char *name ATTRIBUTE_UNUSED
,
2066 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2067 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2069 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
,
2070 get_variable_align (decl
));
2075 /* A noswitch_section_callback for comm_section. */
2078 emit_common (tree decl ATTRIBUTE_UNUSED
,
2079 const char *name ATTRIBUTE_UNUSED
,
2080 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2081 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2083 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
2084 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
2085 size
, get_variable_align (decl
));
2087 #elif defined ASM_OUTPUT_ALIGNED_COMMON
2088 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
2089 get_variable_align (decl
));
2092 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
2097 /* A noswitch_section_callback for tls_comm_section. */
2100 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
2101 const char *name ATTRIBUTE_UNUSED
,
2102 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2103 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2105 #ifdef ASM_OUTPUT_TLS_COMMON
2106 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
2109 sorry ("thread-local COMMON data not implemented");
2114 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2115 NAME is the name of DECL's SYMBOL_REF. */
2118 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
,
2121 unsigned HOST_WIDE_INT size
, rounded
;
2123 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2126 if ((flag_sanitize
& SANITIZE_ADDRESS
) && asan_protect_global (decl
))
2127 size
+= asan_red_zone_size (size
);
2129 /* Don't allocate zero bytes of common,
2130 since that means "undefined external" in the linker. */
2134 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2135 so that each uninitialized object starts on such a boundary. */
2136 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
2137 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2138 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2140 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
2141 && (unsigned HOST_WIDE_INT
) (align
/ BITS_PER_UNIT
) > rounded
)
2142 error ("requested alignment for %q+D is greater than "
2143 "implemented alignment of %wu", decl
, rounded
);
2146 /* A subroutine of assemble_variable. Output the label and contents of
2147 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2148 is as for assemble_variable. */
2151 assemble_variable_contents (tree decl
, const char *name
,
2152 bool dont_output_data
, bool merge_strings
)
2154 /* Do any machine/system dependent processing of the object. */
2155 #ifdef ASM_DECLARE_OBJECT_NAME
2156 last_assemble_variable_decl
= decl
;
2157 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
2159 /* Standard thing is just output label for the object. */
2160 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2161 #endif /* ASM_DECLARE_OBJECT_NAME */
2163 if (!dont_output_data
)
2165 /* Caller is supposed to use varpool_get_constructor when it wants
2166 to output the body. */
2167 gcc_assert (!in_lto_p
|| DECL_INITIAL (decl
) != error_mark_node
);
2168 if (DECL_INITIAL (decl
)
2169 && DECL_INITIAL (decl
) != error_mark_node
2170 && !initializer_zerop (DECL_INITIAL (decl
)))
2171 /* Output the actual data. */
2172 output_constant (DECL_INITIAL (decl
),
2173 tree_to_uhwi (DECL_SIZE_UNIT (decl
)),
2174 get_variable_align (decl
),
2175 false, merge_strings
);
2177 /* Leave space for it. */
2178 assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl
)));
2179 targetm
.asm_out
.decl_end ();
2183 /* Write out assembly for the variable DECL, which is not defined in
2184 the current translation unit. */
2186 assemble_undefined_decl (tree decl
)
2188 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
2189 targetm
.asm_out
.assemble_undefined_decl (asm_out_file
, name
, decl
);
2192 /* Assemble everything that is needed for a variable or function declaration.
2193 Not used for automatic variables, and not used for function definitions.
2194 Should not be called for variables of incomplete structure type.
2196 TOP_LEVEL is nonzero if this variable has file scope.
2197 AT_END is nonzero if this is the special handling, at end of compilation,
2198 to define things that have had only tentative definitions.
2199 DONT_OUTPUT_DATA if nonzero means don't actually output the
2200 initial value (that will be done by the caller). */
2203 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
2204 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
2207 rtx decl_rtl
, symbol
;
2210 bool asan_protected
= false;
2212 /* This function is supposed to handle VARIABLES. Ensure we have one. */
2213 gcc_assert (VAR_P (decl
));
2215 /* Emulated TLS had better not get this far. */
2216 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
2218 last_assemble_variable_decl
= 0;
2220 /* Normally no need to say anything here for external references,
2221 since assemble_external is called by the language-specific code
2222 when a declaration is first seen. */
2224 if (DECL_EXTERNAL (decl
))
2227 /* Do nothing for global register variables. */
2228 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2230 TREE_ASM_WRITTEN (decl
) = 1;
2234 /* If type was incomplete when the variable was declared,
2235 see if it is complete now. */
2237 if (DECL_SIZE (decl
) == 0)
2238 layout_decl (decl
, 0);
2240 /* Still incomplete => don't allocate it; treat the tentative defn
2241 (which is what it must have been) as an `extern' reference. */
2243 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2245 error ("storage size of %q+D isn%'t known", decl
);
2246 TREE_ASM_WRITTEN (decl
) = 1;
2250 /* The first declaration of a variable that comes through this function
2251 decides whether it is global (in C, has external linkage)
2252 or local (in C, has internal linkage). So do nothing more
2253 if this function has already run. */
2255 if (TREE_ASM_WRITTEN (decl
))
2258 /* Make sure targetm.encode_section_info is invoked before we set
2260 decl_rtl
= DECL_RTL (decl
);
2262 TREE_ASM_WRITTEN (decl
) = 1;
2264 /* Do no output if -fsyntax-only. */
2265 if (flag_syntax_only
)
2268 if (! dont_output_data
2269 && ! valid_constant_size_p (DECL_SIZE_UNIT (decl
)))
2271 error ("size of variable %q+D is too large", decl
);
2275 gcc_assert (MEM_P (decl_rtl
));
2276 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2277 symbol
= XEXP (decl_rtl
, 0);
2279 /* If this symbol belongs to the tree constant pool, output the constant
2280 if it hasn't already been written. */
2281 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
2283 tree decl
= SYMBOL_REF_DECL (symbol
);
2284 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2285 output_constant_def_contents (symbol
);
2291 name
= XSTR (symbol
, 0);
2292 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2293 notice_global_symbol (decl
);
2295 /* Compute the alignment of this data. */
2297 align_variable (decl
, dont_output_data
);
2299 if ((flag_sanitize
& SANITIZE_ADDRESS
)
2300 && asan_protect_global (decl
))
2302 asan_protected
= true;
2303 SET_DECL_ALIGN (decl
, MAX (DECL_ALIGN (decl
),
2304 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
));
2307 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2309 align
= get_variable_align (decl
);
2311 if (TREE_PUBLIC (decl
))
2312 maybe_assemble_visibility (decl
);
2314 if (DECL_PRESERVE_P (decl
))
2315 targetm
.asm_out
.mark_decl_preserved (name
);
2317 /* First make the assembler name(s) global if appropriate. */
2318 sect
= get_variable_section (decl
, false);
2319 if (TREE_PUBLIC (decl
)
2320 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2321 globalize_decl (decl
);
2323 /* Output any data that we will need to use the address of. */
2324 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2325 output_addressed_constants (DECL_INITIAL (decl
), 0);
2327 /* dbxout.c needs to know this. */
2328 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2329 DECL_IN_TEXT_SECTION (decl
) = 1;
2331 /* If the decl is part of an object_block, make sure that the decl
2332 has been positioned within its block, but do not write out its
2333 definition yet. output_object_blocks will do that later. */
2334 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2336 gcc_assert (!dont_output_data
);
2337 place_block_symbol (symbol
);
2339 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2340 assemble_noswitch_variable (decl
, name
, sect
, align
);
2343 /* Special-case handling of vtv comdat sections. */
2344 if (sect
->named
.name
2345 && (strcmp (sect
->named
.name
, ".vtable_map_vars") == 0))
2346 handle_vtv_comdat_section (sect
, decl
);
2348 switch_to_section (sect
);
2349 if (align
> BITS_PER_UNIT
)
2350 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2351 assemble_variable_contents (decl
, name
, dont_output_data
,
2352 (sect
->common
.flags
& SECTION_MERGE
)
2353 && (sect
->common
.flags
& SECTION_STRINGS
));
2356 unsigned HOST_WIDE_INT
int size
2357 = tree_to_uhwi (DECL_SIZE_UNIT (decl
));
2358 assemble_zeros (asan_red_zone_size (size
));
2364 /* Given a function declaration (FN_DECL), this function assembles the
2365 function into the .preinit_array section. */
2368 assemble_vtv_preinit_initializer (tree fn_decl
)
2371 unsigned flags
= SECTION_WRITE
;
2372 rtx symbol
= XEXP (DECL_RTL (fn_decl
), 0);
2374 flags
|= SECTION_NOTYPE
;
2375 sect
= get_section (".preinit_array", flags
, fn_decl
);
2376 switch_to_section (sect
);
2377 assemble_addr_to_section (symbol
, sect
);
2380 /* Return 1 if type TYPE contains any pointers. */
2383 contains_pointers_p (tree type
)
2385 switch (TREE_CODE (type
))
2388 case REFERENCE_TYPE
:
2389 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2390 so I'll play safe and return 1. */
2396 case QUAL_UNION_TYPE
:
2399 /* For a type that has fields, see if the fields have pointers. */
2400 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
2401 if (TREE_CODE (fields
) == FIELD_DECL
2402 && contains_pointers_p (TREE_TYPE (fields
)))
2408 /* An array type contains pointers if its element type does. */
2409 return contains_pointers_p (TREE_TYPE (type
));
2416 /* We delay assemble_external processing until
2417 the compilation unit is finalized. This is the best we can do for
2418 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2419 it all the way to final. See PR 17982 for further discussion. */
2420 static GTY(()) tree pending_assemble_externals
;
2422 #ifdef ASM_OUTPUT_EXTERNAL
2423 /* Some targets delay some output to final using TARGET_ASM_FILE_END.
2424 As a result, assemble_external can be called after the list of externals
2425 is processed and the pointer set destroyed. */
2426 static bool pending_assemble_externals_processed
;
2428 /* Avoid O(external_decls**2) lookups in the pending_assemble_externals
2429 TREE_LIST in assemble_external. */
2430 static hash_set
<tree
> *pending_assemble_externals_set
;
2432 /* True if DECL is a function decl for which no out-of-line copy exists.
2433 It is assumed that DECL's assembler name has been set. */
2436 incorporeal_function_p (tree decl
)
2438 if (TREE_CODE (decl
) == FUNCTION_DECL
&& fndecl_built_in_p (decl
))
2442 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2443 && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl
)))
2446 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2447 /* Atomic or sync builtins which have survived this far will be
2448 resolved externally and therefore are not incorporeal. */
2449 if (strncmp (name
, "__builtin_", 10) == 0)
2455 /* Actually do the tests to determine if this is necessary, and invoke
2456 ASM_OUTPUT_EXTERNAL. */
2458 assemble_external_real (tree decl
)
2460 rtx rtl
= DECL_RTL (decl
);
2462 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2463 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2464 && !incorporeal_function_p (decl
))
2466 /* Some systems do require some output. */
2467 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2468 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2474 process_pending_assemble_externals (void)
2476 #ifdef ASM_OUTPUT_EXTERNAL
2478 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2479 assemble_external_real (TREE_VALUE (list
));
2481 pending_assemble_externals
= 0;
2482 pending_assemble_externals_processed
= true;
2483 delete pending_assemble_externals_set
;
2487 /* This TREE_LIST contains any weak symbol declarations waiting
2489 static GTY(()) tree weak_decls
;
2491 /* Output something to declare an external symbol to the assembler,
2492 and qualifiers such as weakness. (Most assemblers don't need
2493 extern declaration, so we normally output nothing.) Do nothing if
2494 DECL is not external. */
2497 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2499 /* Make sure that the ASM_OUT_FILE is open.
2500 If it's not, we should not be calling this function. */
2501 gcc_assert (asm_out_file
);
2503 /* In a perfect world, the following condition would be true.
2504 Sadly, the Go front end emit assembly *from the front end*,
2505 bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2507 /* This function should only be called if we are expanding, or have
2509 Ideally, only final.c would be calling this function, but it is
2510 not clear whether that would break things somehow. See PR 17982
2511 for further discussion. */
2512 gcc_assert (state
== EXPANSION
2513 || state
== FINISHED
);
2516 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2519 /* We want to output annotation for weak and external symbols at
2520 very last to check if they are references or not. */
2522 if (TARGET_SUPPORTS_WEAK
2524 /* TREE_STATIC is a weird and abused creature which is not
2525 generally the right test for whether an entity has been
2526 locally emitted, inlined or otherwise not-really-extern, but
2527 for declarations that can be weak, it happens to be
2529 && !TREE_STATIC (decl
)
2530 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2531 && value_member (decl
, weak_decls
) == NULL_TREE
)
2532 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2534 #ifdef ASM_OUTPUT_EXTERNAL
2535 if (pending_assemble_externals_processed
)
2537 assemble_external_real (decl
);
2541 if (! pending_assemble_externals_set
->add (decl
))
2542 pending_assemble_externals
= tree_cons (NULL
, decl
,
2543 pending_assemble_externals
);
2547 /* Similar, for calling a library function FUN. */
2550 assemble_external_libcall (rtx fun
)
2552 /* Declare library function name external when first used, if nec. */
2553 if (! SYMBOL_REF_USED (fun
))
2555 SYMBOL_REF_USED (fun
) = 1;
2556 targetm
.asm_out
.external_libcall (fun
);
2560 /* Assemble a label named NAME. */
2563 assemble_label (FILE *file
, const char *name
)
2565 ASM_OUTPUT_LABEL (file
, name
);
2568 /* Set the symbol_referenced flag for ID. */
2570 mark_referenced (tree id
)
2572 TREE_SYMBOL_REFERENCED (id
) = 1;
2575 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2577 mark_decl_referenced (tree decl
)
2579 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2581 /* Extern inline functions don't become needed when referenced.
2582 If we know a method will be emitted in other TU and no new
2583 functions can be marked reachable, just use the external
2585 struct cgraph_node
*node
= cgraph_node::get_create (decl
);
2586 if (!DECL_EXTERNAL (decl
)
2587 && !node
->definition
)
2588 node
->mark_force_output ();
2590 else if (VAR_P (decl
))
2592 varpool_node
*node
= varpool_node::get_create (decl
);
2593 /* C++ frontend use mark_decl_references to force COMDAT variables
2594 to be output that might appear dead otherwise. */
2595 node
->force_output
= true;
2597 /* else do nothing - we can get various sorts of CST nodes here,
2598 which do not need to be marked. */
2602 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2603 starts with a *, the rest of NAME is output verbatim. Otherwise
2604 NAME is transformed in a target-specific way (usually by the
2605 addition of an underscore). */
2608 assemble_name_raw (FILE *file
, const char *name
)
2611 fputs (&name
[1], file
);
2613 ASM_OUTPUT_LABELREF (file
, name
);
2616 /* Return NAME that should actually be emitted, looking through
2617 transparent aliases. If NAME refers to an entity that is also
2618 represented as a tree (like a function or variable), mark the entity
2621 assemble_name_resolve (const char *name
)
2623 const char *real_name
= targetm
.strip_name_encoding (name
);
2624 tree id
= maybe_get_identifier (real_name
);
2630 mark_referenced (id
);
2631 ultimate_transparent_alias_target (&id
);
2633 name
= IDENTIFIER_POINTER (id
);
2634 gcc_assert (! TREE_CHAIN (id
));
2640 /* Like assemble_name_raw, but should be used when NAME might refer to
2641 an entity that is also represented as a tree (like a function or
2642 variable). If NAME does refer to such an entity, that entity will
2643 be marked as referenced. */
2646 assemble_name (FILE *file
, const char *name
)
2648 assemble_name_raw (file
, assemble_name_resolve (name
));
2651 /* Allocate SIZE bytes writable static space with a gensym name
2652 and return an RTX to refer to its address. */
2655 assemble_static_space (unsigned HOST_WIDE_INT size
)
2658 const char *namestring
;
2661 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2663 namestring
= ggc_strdup (name
);
2665 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2666 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2668 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2669 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2672 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2673 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2676 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2677 so that each uninitialized object starts on such a boundary. */
2678 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2679 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2680 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2681 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2682 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2683 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2690 /* Assemble the static constant template for function entry trampolines.
2691 This is done at most once per compilation.
2692 Returns an RTX for the address of the template. */
2694 static GTY(()) rtx initial_trampoline
;
2697 assemble_trampoline_template (void)
2704 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2706 if (initial_trampoline
)
2707 return initial_trampoline
;
2709 /* By default, put trampoline templates in read-only data section. */
2711 #ifdef TRAMPOLINE_SECTION
2712 switch_to_section (TRAMPOLINE_SECTION
);
2714 switch_to_section (readonly_data_section
);
2717 /* Write the assembler code to define one. */
2718 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2720 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2722 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2723 targetm
.asm_out
.trampoline_template (asm_out_file
);
2725 /* Record the rtl to refer to it. */
2726 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2727 name
= ggc_strdup (label
);
2728 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2729 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2731 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2732 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2733 set_mem_size (initial_trampoline
, TRAMPOLINE_SIZE
);
2735 return initial_trampoline
;
2738 /* A and B are either alignments or offsets. Return the minimum alignment
2739 that may be assumed after adding the two together. */
2741 static inline unsigned
2742 min_align (unsigned int a
, unsigned int b
)
2744 return least_bit_hwi (a
| b
);
2747 /* Return the assembler directive for creating a given kind of integer
2748 object. SIZE is the number of bytes in the object and ALIGNED_P
2749 indicates whether it is known to be aligned. Return NULL if the
2750 assembly dialect has no such directive.
2752 The returned string should be printed at the start of a new line and
2753 be followed immediately by the object's initial value. */
2756 integer_asm_op (int size
, int aligned_p
)
2758 struct asm_int_op
*ops
;
2761 ops
= &targetm
.asm_out
.aligned_op
;
2763 ops
= &targetm
.asm_out
.unaligned_op
;
2768 return targetm
.asm_out
.byte_op
;
2796 /* Use directive OP to assemble an integer object X. Print OP at the
2797 start of the line, followed immediately by the value of X. */
2800 assemble_integer_with_op (const char *op
, rtx x
)
2802 fputs (op
, asm_out_file
);
2803 output_addr_const (asm_out_file
, x
);
2804 fputc ('\n', asm_out_file
);
2807 /* The default implementation of the asm_out.integer target hook. */
2810 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2811 unsigned int size ATTRIBUTE_UNUSED
,
2812 int aligned_p ATTRIBUTE_UNUSED
)
2814 const char *op
= integer_asm_op (size
, aligned_p
);
2815 /* Avoid GAS bugs for large values. Specifically negative values whose
2816 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2817 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE_UNITS
)
2819 return op
&& (assemble_integer_with_op (op
, x
), true);
2822 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2823 the alignment of the integer in bits. Return 1 if we were able to output
2824 the constant, otherwise 0. We must be able to output the constant,
2825 if FORCE is nonzero. */
2828 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2832 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2834 /* See if the target hook can handle this kind of object. */
2835 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2838 /* If the object is a multi-byte one, try splitting it up. Split
2839 it into words it if is multi-word, otherwise split it into bytes. */
2842 machine_mode omode
, imode
;
2843 unsigned int subalign
;
2844 unsigned int subsize
, i
;
2845 enum mode_class mclass
;
2847 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2848 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2849 if (GET_CODE (x
) == CONST_FIXED
)
2850 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2854 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0).require ();
2855 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0).require ();
2857 for (i
= 0; i
< size
; i
+= subsize
)
2859 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2860 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2866 /* If we've printed some of it, but not all of it, there's no going
2871 gcc_assert (!force
);
2876 /* Assemble the floating-point constant D into an object of size MODE. ALIGN
2877 is the alignment of the constant in bits. If REVERSE is true, D is output
2878 in reverse storage order. */
2881 assemble_real (REAL_VALUE_TYPE d
, scalar_float_mode mode
, unsigned int align
,
2884 long data
[4] = {0, 0, 0, 0};
2885 int bitsize
, nelts
, nunits
, units_per
;
2888 /* This is hairy. We have a quantity of known size. real_to_target
2889 will put it into an array of *host* longs, 32 bits per element
2890 (even if long is more than 32 bits). We need to determine the
2891 number of array elements that are occupied (nelts) and the number
2892 of *target* min-addressable units that will be occupied in the
2893 object file (nunits). We cannot assume that 32 divides the
2894 mode's bitsize (size * BITS_PER_UNIT) evenly.
2896 size * BITS_PER_UNIT is used here to make sure that padding bits
2897 (which might appear at either end of the value; real_to_target
2898 will include the padding bits in its output array) are included. */
2900 nunits
= GET_MODE_SIZE (mode
);
2901 bitsize
= nunits
* BITS_PER_UNIT
;
2902 nelts
= CEIL (bitsize
, 32);
2903 units_per
= 32 / BITS_PER_UNIT
;
2905 real_to_target (data
, &d
, mode
);
2907 /* Put out the first word with the specified alignment. */
2908 unsigned int chunk_nunits
= MIN (nunits
, units_per
);
2910 elt
= flip_storage_order (SImode
, gen_int_mode (data
[nelts
- 1], SImode
));
2912 elt
= GEN_INT (sext_hwi (data
[0], chunk_nunits
* BITS_PER_UNIT
));
2913 assemble_integer (elt
, chunk_nunits
, align
, 1);
2914 nunits
-= chunk_nunits
;
2916 /* Subsequent words need only 32-bit alignment. */
2917 align
= min_align (align
, 32);
2919 for (int i
= 1; i
< nelts
; i
++)
2921 chunk_nunits
= MIN (nunits
, units_per
);
2923 elt
= flip_storage_order (SImode
,
2924 gen_int_mode (data
[nelts
- 1 - i
], SImode
));
2926 elt
= GEN_INT (sext_hwi (data
[i
], chunk_nunits
* BITS_PER_UNIT
));
2927 assemble_integer (elt
, chunk_nunits
, align
, 1);
2928 nunits
-= chunk_nunits
;
2932 /* Given an expression EXP with a constant value,
2933 reduce it to the sum of an assembler symbol and an integer.
2934 Store them both in the structure *VALUE.
2935 EXP must be reducible. */
2944 decode_addr_const (tree exp
, class addr_const
*value
)
2946 tree target
= TREE_OPERAND (exp
, 0);
2947 poly_int64 offset
= 0;
2953 if (TREE_CODE (target
) == COMPONENT_REF
2954 && poly_int_tree_p (byte_position (TREE_OPERAND (target
, 1)),
2958 target
= TREE_OPERAND (target
, 0);
2960 else if (TREE_CODE (target
) == ARRAY_REF
2961 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2963 /* Truncate big offset. */
2965 += (TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (target
)))
2966 * wi::to_poly_widest (TREE_OPERAND (target
, 1)).force_shwi ());
2967 target
= TREE_OPERAND (target
, 0);
2969 else if (TREE_CODE (target
) == MEM_REF
2970 && TREE_CODE (TREE_OPERAND (target
, 0)) == ADDR_EXPR
)
2972 offset
+= mem_ref_offset (target
).force_shwi ();
2973 target
= TREE_OPERAND (TREE_OPERAND (target
, 0), 0);
2975 else if (TREE_CODE (target
) == INDIRECT_REF
2976 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2977 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2979 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2984 switch (TREE_CODE (target
))
2988 x
= DECL_RTL (target
);
2992 x
= gen_rtx_MEM (FUNCTION_MODE
,
2993 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
3002 x
= lookup_constant_def (target
);
3003 /* Should have been added by output_addressed_constants. */
3008 /* This deals with absolute addresses. */
3009 offset
+= tree_to_shwi (TREE_OPERAND (target
, 0));
3010 x
= gen_rtx_MEM (QImode
,
3011 gen_rtx_SYMBOL_REF (Pmode
, "origin of addresses"));
3014 case COMPOUND_LITERAL_EXPR
:
3015 gcc_assert (COMPOUND_LITERAL_EXPR_DECL (target
));
3016 x
= DECL_RTL (COMPOUND_LITERAL_EXPR_DECL (target
));
3023 gcc_assert (MEM_P (x
));
3027 value
->offset
= offset
;
3030 static GTY(()) hash_table
<tree_descriptor_hasher
> *const_desc_htab
;
3032 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
3034 /* Constant pool accessor function. */
3036 hash_table
<tree_descriptor_hasher
> *
3037 constant_pool_htab (void)
3039 return const_desc_htab
;
3042 /* Compute a hash code for a constant expression. */
3045 tree_descriptor_hasher::hash (constant_descriptor_tree
*ptr
)
3051 const_hash_1 (const tree exp
)
3056 enum tree_code code
= TREE_CODE (exp
);
3058 /* Either set P and LEN to the address and len of something to hash and
3059 exit the switch or return a value. */
3064 p
= (char *) &TREE_INT_CST_ELT (exp
, 0);
3065 len
= TREE_INT_CST_NUNITS (exp
) * sizeof (HOST_WIDE_INT
);
3069 return real_hash (TREE_REAL_CST_PTR (exp
));
3072 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
3075 p
= TREE_STRING_POINTER (exp
);
3076 len
= TREE_STRING_LENGTH (exp
);
3080 return (const_hash_1 (TREE_REALPART (exp
)) * 5
3081 + const_hash_1 (TREE_IMAGPART (exp
)));
3085 hi
= 7 + VECTOR_CST_NPATTERNS (exp
);
3086 hi
= hi
* 563 + VECTOR_CST_NELTS_PER_PATTERN (exp
);
3087 unsigned int count
= vector_cst_encoded_nelts (exp
);
3088 for (unsigned int i
= 0; i
< count
; ++i
)
3089 hi
= hi
* 563 + const_hash_1 (VECTOR_CST_ENCODED_ELT (exp
, i
));
3095 unsigned HOST_WIDE_INT idx
;
3098 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
3100 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
3102 hi
= hi
* 603 + const_hash_1 (value
);
3108 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
3109 return const_hash_1 (TREE_OPERAND (exp
, 0));
3114 class addr_const value
;
3116 decode_addr_const (exp
, &value
);
3117 switch (GET_CODE (value
.base
))
3120 /* Don't hash the address of the SYMBOL_REF;
3121 only use the offset and the symbol name. */
3122 hi
= value
.offset
.coeffs
[0];
3123 p
= XSTR (value
.base
, 0);
3124 for (i
= 0; p
[i
] != 0; i
++)
3125 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
3129 hi
= (value
.offset
.coeffs
[0]
3130 + CODE_LABEL_NUMBER (label_ref_label (value
.base
)) * 13);
3140 case POINTER_PLUS_EXPR
:
3142 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
3143 + const_hash_1 (TREE_OPERAND (exp
, 1)));
3146 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
3149 /* A language specific constant. Just hash the code. */
3153 /* Compute hashing function. */
3155 for (i
= 0; i
< len
; i
++)
3156 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
3161 /* Wrapper of compare_constant, for the htab interface. */
3163 tree_descriptor_hasher::equal (constant_descriptor_tree
*c1
,
3164 constant_descriptor_tree
*c2
)
3166 if (c1
->hash
!= c2
->hash
)
3168 return compare_constant (c1
->value
, c2
->value
);
3171 /* Compare t1 and t2, and return 1 only if they are known to result in
3172 the same bit pattern on output. */
3175 compare_constant (const tree t1
, const tree t2
)
3177 enum tree_code typecode
;
3179 if (t1
== NULL_TREE
)
3180 return t2
== NULL_TREE
;
3181 if (t2
== NULL_TREE
)
3184 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3187 switch (TREE_CODE (t1
))
3190 /* Integer constants are the same only if the same width of type. */
3191 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3193 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3195 return tree_int_cst_equal (t1
, t2
);
3198 /* Real constants are the same only if the same width of type. In
3199 addition to the same width, we need to check whether the modes are the
3200 same. There might be two floating point modes that are the same size
3201 but have different representations, such as the PowerPC that has 2
3202 different 128-bit floating point types (IBM extended double and IEEE
3203 128-bit floating point). */
3204 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3206 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3208 return real_identical (&TREE_REAL_CST (t1
), &TREE_REAL_CST (t2
));
3211 /* Fixed constants are the same only if the same width of type. */
3212 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3215 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
3218 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3219 || int_size_in_bytes (TREE_TYPE (t1
))
3220 != int_size_in_bytes (TREE_TYPE (t2
)))
3223 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3224 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3225 TREE_STRING_LENGTH (t1
)));
3228 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
3229 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
3233 if (VECTOR_CST_NPATTERNS (t1
)
3234 != VECTOR_CST_NPATTERNS (t2
))
3237 if (VECTOR_CST_NELTS_PER_PATTERN (t1
)
3238 != VECTOR_CST_NELTS_PER_PATTERN (t2
))
3241 unsigned int count
= vector_cst_encoded_nelts (t1
);
3242 for (unsigned int i
= 0; i
< count
; ++i
)
3243 if (!compare_constant (VECTOR_CST_ENCODED_ELT (t1
, i
),
3244 VECTOR_CST_ENCODED_ELT (t2
, i
)))
3252 vec
<constructor_elt
, va_gc
> *v1
, *v2
;
3253 unsigned HOST_WIDE_INT idx
;
3255 typecode
= TREE_CODE (TREE_TYPE (t1
));
3256 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3259 if (typecode
== ARRAY_TYPE
)
3261 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3262 /* For arrays, check that mode, size and storage order match. */
3263 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3265 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
))
3266 || TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t1
))
3267 != TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t2
)))
3272 /* For record and union constructors, require exact type
3274 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3278 v1
= CONSTRUCTOR_ELTS (t1
);
3279 v2
= CONSTRUCTOR_ELTS (t2
);
3280 if (vec_safe_length (v1
) != vec_safe_length (v2
))
3283 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
3285 constructor_elt
*c1
= &(*v1
)[idx
];
3286 constructor_elt
*c2
= &(*v2
)[idx
];
3288 /* Check that each value is the same... */
3289 if (!compare_constant (c1
->value
, c2
->value
))
3291 /* ... and that they apply to the same fields! */
3292 if (typecode
== ARRAY_TYPE
)
3294 if (!compare_constant (c1
->index
, c2
->index
))
3299 if (c1
->index
!= c2
->index
)
3310 class addr_const value1
, value2
;
3314 decode_addr_const (t1
, &value1
);
3315 decode_addr_const (t2
, &value2
);
3317 if (maybe_ne (value1
.offset
, value2
.offset
))
3320 code
= GET_CODE (value1
.base
);
3321 if (code
!= GET_CODE (value2
.base
))
3327 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3331 ret
= (CODE_LABEL_NUMBER (label_ref_label (value1
.base
))
3332 == CODE_LABEL_NUMBER (label_ref_label (value2
.base
)));
3342 case POINTER_PLUS_EXPR
:
3345 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3346 && compare_constant (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3349 case VIEW_CONVERT_EXPR
:
3350 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3359 /* Return the section into which constant EXP should be placed. */
3362 get_constant_section (tree exp
, unsigned int align
)
3364 return targetm
.asm_out
.select_section (exp
,
3365 compute_reloc_for_constant (exp
),
3369 /* Return the size of constant EXP in bytes. */
3371 static HOST_WIDE_INT
3372 get_constant_size (tree exp
)
3376 size
= int_size_in_bytes (TREE_TYPE (exp
));
3377 gcc_checking_assert (size
>= 0);
3378 gcc_checking_assert (TREE_CODE (exp
) != STRING_CST
3379 || size
>= TREE_STRING_LENGTH (exp
));
3383 /* Subroutine of output_constant_def:
3384 No constant equal to EXP is known to have been output.
3385 Make a constant descriptor to enter EXP in the hash table.
3386 Assign the label number and construct RTL to refer to the
3387 constant's location in memory.
3388 Caller is responsible for updating the hash table. */
3390 static struct constant_descriptor_tree
*
3391 build_constant_desc (tree exp
)
3393 struct constant_descriptor_tree
*desc
;
3399 desc
= ggc_alloc
<constant_descriptor_tree
> ();
3402 /* Create a string containing the label name, in LABEL. */
3403 labelno
= const_labelno
++;
3404 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3406 /* Construct the VAR_DECL associated with the constant. */
3407 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3409 DECL_ARTIFICIAL (decl
) = 1;
3410 DECL_IGNORED_P (decl
) = 1;
3411 TREE_READONLY (decl
) = 1;
3412 TREE_STATIC (decl
) = 1;
3413 TREE_ADDRESSABLE (decl
) = 1;
3414 /* We don't set the RTL yet as this would cause varpool to assume that the
3415 variable is referenced. Moreover, it would just be dropped in LTO mode.
3416 Instead we set the flag that will be recognized in make_decl_rtl. */
3417 DECL_IN_CONSTANT_POOL (decl
) = 1;
3418 DECL_INITIAL (decl
) = desc
->value
;
3419 /* ??? targetm.constant_alignment hasn't been updated for vector types on
3420 most architectures so use DATA_ALIGNMENT as well, except for strings. */
3421 if (TREE_CODE (exp
) == STRING_CST
)
3422 SET_DECL_ALIGN (decl
, targetm
.constant_alignment (exp
, DECL_ALIGN (decl
)));
3425 align_variable (decl
, 0);
3426 if (DECL_ALIGN (decl
) < GET_MODE_ALIGNMENT (DECL_MODE (decl
))
3427 && ((optab_handler (movmisalign_optab
, DECL_MODE (decl
))
3428 != CODE_FOR_nothing
)
3429 || targetm
.slow_unaligned_access (DECL_MODE (decl
),
3430 DECL_ALIGN (decl
))))
3431 SET_DECL_ALIGN (decl
, GET_MODE_ALIGNMENT (DECL_MODE (decl
)));
3434 /* Now construct the SYMBOL_REF and the MEM. */
3435 if (use_object_blocks_p ())
3437 int align
= (TREE_CODE (decl
) == CONST_DECL
3438 || (VAR_P (decl
) && DECL_IN_CONSTANT_POOL (decl
))
3440 : symtab_node::get (decl
)->definition_alignment ());
3441 section
*sect
= get_constant_section (exp
, align
);
3442 symbol
= create_block_symbol (ggc_strdup (label
),
3443 get_block_for_section (sect
), -1);
3446 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3447 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3448 SET_SYMBOL_REF_DECL (symbol
, decl
);
3449 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3451 rtl
= gen_const_mem (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3452 set_mem_alias_set (rtl
, 0);
3454 /* Putting EXP into the literal pool might have imposed a different
3455 alignment which should be visible in the RTX as well. */
3456 set_mem_align (rtl
, DECL_ALIGN (decl
));
3458 /* We cannot share RTX'es in pool entries.
3459 Mark this piece of RTL as required for unsharing. */
3460 RTX_FLAG (rtl
, used
) = 1;
3462 /* Set flags or add text to the name to record information, such as
3463 that it is a local symbol. If the name is changed, the macro
3464 ASM_OUTPUT_LABELREF will have to know how to strip this
3465 information. This call might invalidate our local variable
3466 SYMBOL; we can't use it afterward. */
3467 targetm
.encode_section_info (exp
, rtl
, true);
3474 /* Subroutine of output_constant_def and tree_output_constant_def:
3475 Add a constant to the hash table that tracks which constants
3476 already have labels. */
3478 static constant_descriptor_tree
*
3479 add_constant_to_table (tree exp
, int defer
)
3481 /* The hash table methods may call output_constant_def for addressed
3482 constants, so handle them first. */
3483 output_addressed_constants (exp
, defer
);
3485 /* Sanity check to catch recursive insertion. */
3486 static bool inserting
;
3487 gcc_assert (!inserting
);
3490 /* Look up EXP in the table of constant descriptors. If we didn't
3491 find it, create a new one. */
3492 struct constant_descriptor_tree key
;
3494 key
.hash
= const_hash_1 (exp
);
3495 constant_descriptor_tree
**loc
3496 = const_desc_htab
->find_slot_with_hash (&key
, key
.hash
, INSERT
);
3500 struct constant_descriptor_tree
*desc
= *loc
;
3503 desc
= build_constant_desc (exp
);
3504 desc
->hash
= key
.hash
;
3511 /* Return an rtx representing a reference to constant data in memory
3512 for the constant expression EXP.
3514 If assembler code for such a constant has already been output,
3515 return an rtx to refer to it.
3516 Otherwise, output such a constant in memory
3517 and generate an rtx for it.
3519 If DEFER is nonzero, this constant can be deferred and output only
3520 if referenced in the function after all optimizations.
3522 `const_desc_table' records which constants already have label strings. */
3525 output_constant_def (tree exp
, int defer
)
3527 struct constant_descriptor_tree
*desc
= add_constant_to_table (exp
, defer
);
3528 maybe_output_constant_def_contents (desc
, defer
);
3532 /* Subroutine of output_constant_def: Decide whether or not we need to
3533 output the constant DESC now, and if so, do it. */
3535 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3538 rtx symbol
= XEXP (desc
->rtl
, 0);
3539 tree exp
= desc
->value
;
3541 if (flag_syntax_only
)
3544 if (TREE_ASM_WRITTEN (exp
))
3545 /* Already output; don't do it again. */
3548 /* We can always defer constants as long as the context allows
3552 /* Increment n_deferred_constants if it exists. It needs to be at
3553 least as large as the number of constants actually referred to
3554 by the function. If it's too small we'll stop looking too early
3555 and fail to emit constants; if it's too large we'll only look
3556 through the entire function when we could have stopped earlier. */
3558 n_deferred_constants
++;
3562 output_constant_def_contents (symbol
);
3565 /* Subroutine of output_constant_def_contents. Output the definition
3566 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3567 constant's alignment in bits. */
3570 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
,
3575 size
= get_constant_size (exp
);
3577 /* Do any machine/system dependent processing of the constant. */
3578 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3580 /* Output the value of EXP. */
3581 output_constant (exp
, size
, align
, false, merge_strings
);
3583 targetm
.asm_out
.decl_end ();
3586 /* We must output the constant data referred to by SYMBOL; do so. */
3589 output_constant_def_contents (rtx symbol
)
3591 tree decl
= SYMBOL_REF_DECL (symbol
);
3592 tree exp
= DECL_INITIAL (decl
);
3593 bool asan_protected
= false;
3595 /* Make sure any other constants whose addresses appear in EXP
3596 are assigned label numbers. */
3597 output_addressed_constants (exp
, 0);
3599 /* We are no longer deferring this constant. */
3600 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3602 if ((flag_sanitize
& SANITIZE_ADDRESS
)
3603 && TREE_CODE (exp
) == STRING_CST
3604 && asan_protect_global (exp
))
3606 asan_protected
= true;
3607 SET_DECL_ALIGN (decl
, MAX (DECL_ALIGN (decl
),
3608 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
));
3611 /* If the constant is part of an object block, make sure that the
3612 decl has been positioned within its block, but do not write out
3613 its definition yet. output_object_blocks will do that later. */
3614 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3615 place_block_symbol (symbol
);
3618 int align
= (TREE_CODE (decl
) == CONST_DECL
3619 || (VAR_P (decl
) && DECL_IN_CONSTANT_POOL (decl
))
3621 : symtab_node::get (decl
)->definition_alignment ());
3622 section
*sect
= get_constant_section (exp
, align
);
3623 switch_to_section (sect
);
3624 if (align
> BITS_PER_UNIT
)
3625 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3626 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
,
3627 (sect
->common
.flags
& SECTION_MERGE
)
3628 && (sect
->common
.flags
& SECTION_STRINGS
));
3631 HOST_WIDE_INT size
= get_constant_size (exp
);
3632 assemble_zeros (asan_red_zone_size (size
));
3637 /* Look up EXP in the table of constant descriptors. Return the rtl
3638 if it has been emitted, else null. */
3641 lookup_constant_def (tree exp
)
3643 struct constant_descriptor_tree key
;
3646 key
.hash
= const_hash_1 (exp
);
3647 constant_descriptor_tree
*desc
3648 = const_desc_htab
->find_with_hash (&key
, key
.hash
);
3650 return (desc
? desc
->rtl
: NULL_RTX
);
3653 /* Return a tree representing a reference to constant data in memory
3654 for the constant expression EXP.
3656 This is the counterpart of output_constant_def at the Tree level. */
3659 tree_output_constant_def (tree exp
)
3661 struct constant_descriptor_tree
*desc
= add_constant_to_table (exp
, 1);
3662 tree decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3663 varpool_node::finalize_decl (decl
);
3667 class GTY((chain_next ("%h.next"), for_user
)) constant_descriptor_rtx
{
3669 class constant_descriptor_rtx
*next
;
3673 HOST_WIDE_INT offset
;
3675 fixed_size_mode mode
;
3681 struct const_rtx_desc_hasher
: ggc_ptr_hash
<constant_descriptor_rtx
>
3683 static hashval_t
hash (constant_descriptor_rtx
*);
3684 static bool equal (constant_descriptor_rtx
*, constant_descriptor_rtx
*);
3687 /* Used in the hash tables to avoid outputting the same constant
3688 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3689 are output once per function, not once per file. */
3690 /* ??? Only a few targets need per-function constant pools. Most
3691 can use one per-file pool. Should add a targetm bit to tell the
3694 struct GTY(()) rtx_constant_pool
{
3695 /* Pointers to first and last constant in pool, as ordered by offset. */
3696 class constant_descriptor_rtx
*first
;
3697 class constant_descriptor_rtx
*last
;
3699 /* Hash facility for making memory-constants from constant rtl-expressions.
3700 It is used on RISC machines where immediate integer arguments and
3701 constant addresses are restricted so that such constants must be stored
3703 hash_table
<const_rtx_desc_hasher
> *const_rtx_htab
;
3705 /* Current offset in constant pool (does not include any
3706 machine-specific header). */
3707 HOST_WIDE_INT offset
;
3710 /* Hash and compare functions for const_rtx_htab. */
3713 const_rtx_desc_hasher::hash (constant_descriptor_rtx
*desc
)
3719 const_rtx_desc_hasher::equal (constant_descriptor_rtx
*x
,
3720 constant_descriptor_rtx
*y
)
3722 if (x
->mode
!= y
->mode
)
3724 return rtx_equal_p (x
->constant
, y
->constant
);
3727 /* Hash one component of a constant. */
3730 const_rtx_hash_1 (const_rtx x
)
3732 unsigned HOST_WIDE_INT hwi
;
3738 code
= GET_CODE (x
);
3739 mode
= GET_MODE (x
);
3740 h
= (hashval_t
) code
* 1048573 + mode
;
3749 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3750 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3752 h
^= (hashval_t
) hwi
;
3753 for (i
= 1; i
< n
; ++i
)
3756 h
^= (hashval_t
) hwi
;
3761 case CONST_WIDE_INT
:
3764 for (i
= 0; i
< CONST_WIDE_INT_NUNITS (x
); i
++)
3765 hwi
^= CONST_WIDE_INT_ELT (x
, i
);
3770 if (TARGET_SUPPORTS_WIDE_INT
== 0 && mode
== VOIDmode
)
3772 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3776 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3780 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3784 h
^= htab_hash_string (XSTR (x
, 0));
3788 h
= h
* 251 + CODE_LABEL_NUMBER (label_ref_label (x
));
3792 case UNSPEC_VOLATILE
:
3793 h
= h
* 251 + XINT (x
, 1);
3803 /* Compute a hash value for X, which should be a constant. */
3806 const_rtx_hash (rtx x
)
3809 subrtx_iterator::array_type array
;
3810 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
3811 h
= h
* 509 + const_rtx_hash_1 (*iter
);
3816 /* Create and return a new rtx constant pool. */
3818 static struct rtx_constant_pool
*
3819 create_constant_pool (void)
3821 struct rtx_constant_pool
*pool
;
3823 pool
= ggc_alloc
<rtx_constant_pool
> ();
3824 pool
->const_rtx_htab
= hash_table
<const_rtx_desc_hasher
>::create_ggc (31);
3831 /* Initialize constant pool hashing for a new function. */
3834 init_varasm_status (void)
3836 crtl
->varasm
.pool
= create_constant_pool ();
3837 crtl
->varasm
.deferred_constants
= 0;
3840 /* Given a MINUS expression, simplify it if both sides
3841 include the same symbol. */
3844 simplify_subtraction (rtx x
)
3846 rtx r
= simplify_rtx (x
);
3850 /* Given a constant rtx X, make (or find) a memory constant for its value
3851 and return a MEM rtx to refer to it in memory. IN_MODE is the mode
3855 force_const_mem (machine_mode in_mode
, rtx x
)
3857 class constant_descriptor_rtx
*desc
, tmp
;
3858 struct rtx_constant_pool
*pool
;
3863 constant_descriptor_rtx
**slot
;
3864 fixed_size_mode mode
;
3866 /* We can't force variable-sized objects to memory. */
3867 if (!is_a
<fixed_size_mode
> (in_mode
, &mode
))
3870 /* If we're not allowed to drop X into the constant pool, don't. */
3871 if (targetm
.cannot_force_const_mem (mode
, x
))
3874 /* Record that this function has used a constant pool entry. */
3875 crtl
->uses_const_pool
= 1;
3877 /* Decide which pool to use. */
3878 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3879 ? shared_constant_pool
3880 : crtl
->varasm
.pool
);
3882 /* Lookup the value in the hashtable. */
3885 hash
= const_rtx_hash (x
);
3886 slot
= pool
->const_rtx_htab
->find_slot_with_hash (&tmp
, hash
, INSERT
);
3889 /* If the constant was already present, return its memory. */
3891 return copy_rtx (desc
->mem
);
3893 /* Otherwise, create a new descriptor. */
3894 desc
= ggc_alloc
<constant_descriptor_rtx
> ();
3897 /* Align the location counter as required by EXP's data type. */
3898 machine_mode align_mode
= (mode
== VOIDmode
? word_mode
: mode
);
3899 align
= targetm
.static_rtx_alignment (align_mode
);
3901 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3902 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3905 desc
->constant
= copy_rtx (tmp
.constant
);
3906 desc
->offset
= pool
->offset
;
3909 desc
->align
= align
;
3910 desc
->labelno
= const_labelno
;
3913 pool
->offset
+= GET_MODE_SIZE (mode
);
3915 pool
->last
->next
= desc
;
3917 pool
->first
= pool
->last
= desc
;
3920 /* Create a string containing the label name, in LABEL. */
3921 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3924 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3925 the constants pool. */
3926 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3928 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3929 symbol
= create_block_symbol (ggc_strdup (label
),
3930 get_block_for_section (sect
), -1);
3933 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3935 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3936 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3937 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3939 /* Construct the MEM. */
3940 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3941 set_mem_align (def
, align
);
3943 /* If we're dropping a label to the constant pool, make sure we
3945 if (GET_CODE (x
) == LABEL_REF
)
3946 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3948 return copy_rtx (def
);
3951 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3954 get_pool_constant (const_rtx addr
)
3956 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3959 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3960 and whether it has been output or not. */
3963 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3965 class constant_descriptor_rtx
*desc
;
3967 desc
= SYMBOL_REF_CONSTANT (addr
);
3968 *pmarked
= (desc
->mark
!= 0);
3969 return desc
->constant
;
3972 /* Similar, return the mode. */
3975 get_pool_mode (const_rtx addr
)
3977 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3980 /* Return TRUE if and only if the constant pool has no entries. Note
3981 that even entries we might end up choosing not to emit are counted
3982 here, so there is the potential for missed optimizations. */
3985 constant_pool_empty_p (void)
3987 return crtl
->varasm
.pool
->first
== NULL
;
3990 /* Worker function for output_constant_pool_1. Emit assembly for X
3991 in MODE with known alignment ALIGN. */
3994 output_constant_pool_2 (fixed_size_mode mode
, rtx x
, unsigned int align
)
3996 switch (GET_MODE_CLASS (mode
))
3999 case MODE_DECIMAL_FLOAT
:
4001 gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x
));
4002 assemble_real (*CONST_DOUBLE_REAL_VALUE (x
),
4003 as_a
<scalar_float_mode
> (mode
), align
, false);
4008 case MODE_PARTIAL_INT
:
4013 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
4016 case MODE_VECTOR_BOOL
:
4018 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
4020 /* Pick the smallest integer mode that contains at least one
4021 whole element. Often this is byte_mode and contains more
4022 than one element. */
4023 unsigned int nelts
= GET_MODE_NUNITS (mode
);
4024 unsigned int elt_bits
= GET_MODE_BITSIZE (mode
) / nelts
;
4025 unsigned int int_bits
= MAX (elt_bits
, BITS_PER_UNIT
);
4026 scalar_int_mode int_mode
= int_mode_for_size (int_bits
, 0).require ();
4028 /* Build the constant up one integer at a time. */
4029 unsigned int elts_per_int
= int_bits
/ elt_bits
;
4030 for (unsigned int i
= 0; i
< nelts
; i
+= elts_per_int
)
4032 unsigned HOST_WIDE_INT value
= 0;
4033 unsigned int limit
= MIN (nelts
- i
, elts_per_int
);
4034 for (unsigned int j
= 0; j
< limit
; ++j
)
4035 if (INTVAL (CONST_VECTOR_ELT (x
, i
+ j
)) != 0)
4036 value
|= 1 << (j
* elt_bits
);
4037 output_constant_pool_2 (int_mode
, gen_int_mode (value
, int_mode
),
4038 i
!= 0 ? MIN (align
, int_bits
) : align
);
4042 case MODE_VECTOR_FLOAT
:
4043 case MODE_VECTOR_INT
:
4044 case MODE_VECTOR_FRACT
:
4045 case MODE_VECTOR_UFRACT
:
4046 case MODE_VECTOR_ACCUM
:
4047 case MODE_VECTOR_UACCUM
:
4050 scalar_mode submode
= GET_MODE_INNER (mode
);
4051 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
4053 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
4054 units
= GET_MODE_NUNITS (mode
);
4056 for (i
= 0; i
< units
; i
++)
4058 rtx elt
= CONST_VECTOR_ELT (x
, i
);
4059 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
4069 /* Worker function for output_constant_pool. Emit constant DESC,
4070 giving it ALIGN bits of alignment. */
4073 output_constant_pool_1 (class constant_descriptor_rtx
*desc
,
4080 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
4081 whose CODE_LABEL has been deleted. This can occur if a jump table
4082 is eliminated by optimization. If so, write a constant of zero
4083 instead. Note that this can also happen by turning the
4084 CODE_LABEL into a NOTE. */
4085 /* ??? This seems completely and utterly wrong. Certainly it's
4086 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
4087 functioning even with rtx_insn::deleted and friends. */
4090 switch (GET_CODE (tmp
))
4093 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
4094 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
4096 tmp
= XEXP (XEXP (tmp
, 0), 0);
4101 rtx_insn
*insn
= label_ref_label (tmp
);
4102 gcc_assert (!insn
->deleted ());
4103 gcc_assert (!NOTE_P (insn
)
4104 || NOTE_KIND (insn
) != NOTE_INSN_DELETED
);
4112 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4113 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
4114 align
, desc
->labelno
, done
);
4117 assemble_align (align
);
4119 /* Output the label. */
4120 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
4123 Pass actual alignment value while emitting string constant to asm code
4124 as function 'output_constant_pool_1' explicitly passes the alignment as 1
4125 assuming that the data is already aligned which prevents the generation
4126 of fix-up table entries. */
4127 output_constant_pool_2 (desc
->mode
, x
, desc
->align
);
4129 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
4130 sections have proper size. */
4131 if (align
> GET_MODE_BITSIZE (desc
->mode
)
4133 && (in_section
->common
.flags
& SECTION_MERGE
))
4134 assemble_align (align
);
4136 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4142 /* Recompute the offsets of entries in POOL, and the overall size of
4143 POOL. Do this after calling mark_constant_pool to ensure that we
4144 are computing the offset values for the pool which we will actually
4148 recompute_pool_offsets (struct rtx_constant_pool
*pool
)
4150 class constant_descriptor_rtx
*desc
;
4153 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
4156 /* Recalculate offset. */
4157 unsigned int align
= desc
->align
;
4158 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
4159 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
4160 desc
->offset
= pool
->offset
;
4161 pool
->offset
+= GET_MODE_SIZE (desc
->mode
);
4165 /* Mark all constants that are referenced by SYMBOL_REFs in X.
4166 Emit referenced deferred strings. */
4169 mark_constants_in_pattern (rtx insn
)
4171 subrtx_iterator::array_type array
;
4172 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), ALL
)
4174 const_rtx x
= *iter
;
4175 if (GET_CODE (x
) == SYMBOL_REF
)
4177 if (CONSTANT_POOL_ADDRESS_P (x
))
4179 class constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
4180 if (desc
->mark
== 0)
4183 iter
.substitute (desc
->constant
);
4186 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
4188 tree decl
= SYMBOL_REF_DECL (x
);
4189 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
4191 n_deferred_constants
--;
4192 output_constant_def_contents (CONST_CAST_RTX (x
));
4199 /* Look through appropriate parts of INSN, marking all entries in the
4200 constant pool which are actually being used. Entries that are only
4201 referenced by other constants are also marked as used. Emit
4202 deferred strings that are used. */
4205 mark_constants (rtx_insn
*insn
)
4210 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4211 insns, not any notes that may be attached. We don't want to mark
4212 a constant just because it happens to appear in a REG_EQUIV note. */
4213 if (rtx_sequence
*seq
= dyn_cast
<rtx_sequence
*> (PATTERN (insn
)))
4215 int i
, n
= seq
->len ();
4216 for (i
= 0; i
< n
; ++i
)
4218 rtx subinsn
= seq
->element (i
);
4219 if (INSN_P (subinsn
))
4220 mark_constants_in_pattern (subinsn
);
4224 mark_constants_in_pattern (insn
);
4227 /* Look through the instructions for this function, and mark all the
4228 entries in POOL which are actually being used. Emit deferred constants
4229 which have indeed been used. */
4232 mark_constant_pool (void)
4236 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
4239 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4240 mark_constants (insn
);
4243 /* Write all the constants in POOL. */
4246 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
4248 class constant_descriptor_rtx
*desc
;
4250 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
4253 #ifdef ASM_OUTPUT_DEF
4254 const char *name
= targetm
.strip_name_encoding (XSTR (desc
->sym
, 0));
4256 char buffer
[256 + 32];
4259 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", ~desc
->mark
);
4260 p
= targetm
.strip_name_encoding (label
);
4263 sprintf (buffer
, "%s+%ld", p
, (long) (desc
->offset
));
4266 ASM_OUTPUT_DEF (asm_out_file
, name
, p
);
4271 else if (desc
->mark
)
4273 /* If the constant is part of an object_block, make sure that
4274 the constant has been positioned within its block, but do not
4275 write out its definition yet. output_object_blocks will do
4277 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
4278 && SYMBOL_REF_BLOCK (desc
->sym
))
4279 place_block_symbol (desc
->sym
);
4282 switch_to_section (targetm
.asm_out
.select_rtx_section
4283 (desc
->mode
, desc
->constant
, desc
->align
));
4284 output_constant_pool_1 (desc
, desc
->align
);
4289 struct constant_descriptor_rtx_data
{
4290 constant_descriptor_rtx
*desc
;
4292 unsigned short size
;
4293 unsigned short offset
;
4297 /* qsort callback to sort constant_descriptor_rtx_data * vector by
4301 constant_descriptor_rtx_data_cmp (const void *p1
, const void *p2
)
4303 constant_descriptor_rtx_data
*const data1
4304 = *(constant_descriptor_rtx_data
* const *) p1
;
4305 constant_descriptor_rtx_data
*const data2
4306 = *(constant_descriptor_rtx_data
* const *) p2
;
4307 if (data1
->size
> data2
->size
)
4309 if (data1
->size
< data2
->size
)
4311 if (data1
->hash
< data2
->hash
)
4313 gcc_assert (data1
->hash
> data2
->hash
);
4317 struct const_rtx_data_hasher
: nofree_ptr_hash
<constant_descriptor_rtx_data
>
4319 static hashval_t
hash (constant_descriptor_rtx_data
*);
4320 static bool equal (constant_descriptor_rtx_data
*,
4321 constant_descriptor_rtx_data
*);
4324 /* Hash and compare functions for const_rtx_data_htab. */
4327 const_rtx_data_hasher::hash (constant_descriptor_rtx_data
*data
)
4333 const_rtx_data_hasher::equal (constant_descriptor_rtx_data
*x
,
4334 constant_descriptor_rtx_data
*y
)
4336 if (x
->hash
!= y
->hash
|| x
->size
!= y
->size
)
4338 unsigned int align1
= x
->desc
->align
;
4339 unsigned int align2
= y
->desc
->align
;
4340 unsigned int offset1
= (x
->offset
* BITS_PER_UNIT
) & (align1
- 1);
4341 unsigned int offset2
= (y
->offset
* BITS_PER_UNIT
) & (align2
- 1);
4343 align1
= least_bit_hwi (offset1
);
4345 align2
= least_bit_hwi (offset2
);
4346 if (align2
> align1
)
4348 if (memcmp (x
->bytes
, y
->bytes
, x
->size
* sizeof (target_unit
)) != 0)
4353 /* Attempt to optimize constant pool POOL. If it contains both CONST_VECTOR
4354 constants and scalar constants with the values of CONST_VECTOR elements,
4355 try to alias the scalar constants with the CONST_VECTOR elements. */
4358 optimize_constant_pool (struct rtx_constant_pool
*pool
)
4360 auto_vec
<target_unit
, 128> buffer
;
4361 auto_vec
<constant_descriptor_rtx_data
*, 128> vec
;
4362 object_allocator
<constant_descriptor_rtx_data
>
4363 data_pool ("constant_descriptor_rtx_data_pool");
4366 for (constant_descriptor_rtx
*desc
= pool
->first
; desc
; desc
= desc
->next
)
4368 && ! (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
4369 && SYMBOL_REF_BLOCK (desc
->sym
)))
4371 buffer
.truncate (0);
4372 buffer
.reserve (GET_MODE_SIZE (desc
->mode
));
4373 if (native_encode_rtx (desc
->mode
, desc
->constant
, buffer
, 0,
4374 GET_MODE_SIZE (desc
->mode
)))
4376 constant_descriptor_rtx_data
*data
= data_pool
.allocate ();
4379 data
->size
= GET_MODE_SIZE (desc
->mode
);
4383 vec
.safe_push (data
);
4388 vec
.qsort (constant_descriptor_rtx_data_cmp
);
4389 unsigned min_size
= vec
.last ()->size
;
4390 target_unit
*bytes
= XNEWVEC (target_unit
, size
);
4392 constant_descriptor_rtx_data
*data
;
4393 hash_table
<const_rtx_data_hasher
> * htab
4394 = new hash_table
<const_rtx_data_hasher
> (31);
4396 FOR_EACH_VEC_ELT (vec
, i
, data
)
4398 buffer
.truncate (0);
4399 native_encode_rtx (data
->desc
->mode
, data
->desc
->constant
,
4400 buffer
, 0, data
->size
);
4401 memcpy (bytes
+ size
, buffer
.address (), data
->size
);
4402 data
->bytes
= bytes
+ size
;
4403 data
->hash
= iterative_hash (data
->bytes
,
4404 data
->size
* sizeof (target_unit
), 0);
4406 constant_descriptor_rtx_data
**slot
4407 = htab
->find_slot_with_hash (data
, data
->hash
, INSERT
);
4410 data
->desc
->mark
= ~(*slot
)->desc
->labelno
;
4411 data
->desc
->offset
= (*slot
)->offset
;
4415 unsigned int sz
= 1 << floor_log2 (data
->size
);
4418 for (sz
>>= 1; sz
>= min_size
; sz
>>= 1)
4419 for (unsigned off
= 0; off
+ sz
<= data
->size
; off
+= sz
)
4421 constant_descriptor_rtx_data tmp
;
4422 tmp
.desc
= data
->desc
;
4423 tmp
.bytes
= data
->bytes
+ off
;
4426 tmp
.hash
= iterative_hash (tmp
.bytes
,
4427 sz
* sizeof (target_unit
), 0);
4428 slot
= htab
->find_slot_with_hash (&tmp
, tmp
.hash
, INSERT
);
4431 *slot
= data_pool
.allocate ();
4440 data_pool
.release ();
4443 /* Mark all constants that are used in the current function, then write
4444 out the function's private constant pool. */
4447 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
4448 tree fndecl ATTRIBUTE_UNUSED
)
4450 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
4452 /* It is possible for gcc to call force_const_mem and then to later
4453 discard the instructions which refer to the constant. In such a
4454 case we do not need to output the constant. */
4455 mark_constant_pool ();
4457 /* Having marked the constant pool entries we'll actually emit, we
4458 now need to rebuild the offset information, which may have become
4460 recompute_pool_offsets (pool
);
4462 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4463 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4466 output_constant_pool_contents (pool
);
4468 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4469 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4473 /* Write the contents of the shared constant pool. */
4476 output_shared_constant_pool (void)
4479 && TARGET_SUPPORTS_ALIASES
)
4480 optimize_constant_pool (shared_constant_pool
);
4482 output_constant_pool_contents (shared_constant_pool
);
4485 /* Determine what kind of relocations EXP may need. */
4488 compute_reloc_for_constant (tree exp
)
4490 int reloc
= 0, reloc2
;
4493 switch (TREE_CODE (exp
))
4497 /* Go inside any operations that get_inner_reference can handle and see
4498 if what's inside is a constant: no need to do anything here for
4499 addresses of variables or functions. */
4500 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4501 tem
= TREE_OPERAND (tem
, 0))
4504 if (TREE_CODE (tem
) == MEM_REF
4505 && TREE_CODE (TREE_OPERAND (tem
, 0)) == ADDR_EXPR
)
4507 reloc
= compute_reloc_for_constant (TREE_OPERAND (tem
, 0));
4511 if (!targetm
.binds_local_p (tem
))
4518 case POINTER_PLUS_EXPR
:
4519 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4520 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4524 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4525 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4526 /* The difference of two local labels is computable at link time. */
4527 if (reloc
== 1 && reloc2
== 1)
4534 case VIEW_CONVERT_EXPR
:
4535 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4540 unsigned HOST_WIDE_INT idx
;
4541 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4543 reloc
|= compute_reloc_for_constant (tem
);
4553 /* Find all the constants whose addresses are referenced inside of EXP,
4554 and make sure assembler code with a label has been output for each one.
4555 Indicate whether an ADDR_EXPR has been encountered. */
4558 output_addressed_constants (tree exp
, int defer
)
4562 switch (TREE_CODE (exp
))
4566 /* Go inside any operations that get_inner_reference can handle and see
4567 if what's inside is a constant: no need to do anything here for
4568 addresses of variables or functions. */
4569 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4570 tem
= TREE_OPERAND (tem
, 0))
4573 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4574 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4575 tem
= DECL_INITIAL (tem
);
4577 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4578 output_constant_def (tem
, defer
);
4580 if (TREE_CODE (tem
) == MEM_REF
)
4581 output_addressed_constants (TREE_OPERAND (tem
, 0), defer
);
4585 case POINTER_PLUS_EXPR
:
4587 output_addressed_constants (TREE_OPERAND (exp
, 1), defer
);
4591 case VIEW_CONVERT_EXPR
:
4592 output_addressed_constants (TREE_OPERAND (exp
, 0), defer
);
4597 unsigned HOST_WIDE_INT idx
;
4598 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4600 output_addressed_constants (tem
, defer
);
4609 /* Whether a constructor CTOR is a valid static constant initializer if all
4610 its elements are. This used to be internal to initializer_constant_valid_p
4611 and has been exposed to let other functions like categorize_ctor_elements
4612 evaluate the property while walking a constructor for other purposes. */
4615 constructor_static_from_elts_p (const_tree ctor
)
4617 return (TREE_CONSTANT (ctor
)
4618 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4619 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
4620 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
4623 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4626 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4627 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4628 which are valid when ENDTYPE is an integer of any size; in
4629 particular, this does not accept a pointer minus a constant. This
4630 returns null_pointer_node if the VALUE is an absolute constant
4631 which can be used to initialize a static variable. Otherwise it
4635 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4639 if (!INTEGRAL_TYPE_P (endtype
))
4642 op0
= TREE_OPERAND (value
, 0);
4643 op1
= TREE_OPERAND (value
, 1);
4645 /* Like STRIP_NOPS except allow the operand mode to widen. This
4646 works around a feature of fold that simplifies (int)(p1 - p2) to
4647 ((int)p1 - (int)p2) under the theory that the narrower operation
4650 while (CONVERT_EXPR_P (op0
)
4651 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4653 tree inner
= TREE_OPERAND (op0
, 0);
4654 if (inner
== error_mark_node
4655 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4656 || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op0
)))
4657 > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner
)))))
4662 while (CONVERT_EXPR_P (op1
)
4663 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4665 tree inner
= TREE_OPERAND (op1
, 0);
4666 if (inner
== error_mark_node
4667 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4668 || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op1
)))
4669 > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner
)))))
4674 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4678 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4679 cache
? cache
+ 2 : NULL
);
4680 /* Both initializers must be known. */
4684 && (op0
== null_pointer_node
4685 || TREE_CODE (value
) == MINUS_EXPR
))
4686 return null_pointer_node
;
4688 /* Support differences between labels. */
4689 if (TREE_CODE (op0
) == LABEL_DECL
4690 && TREE_CODE (op1
) == LABEL_DECL
)
4691 return null_pointer_node
;
4693 if (TREE_CODE (op0
) == STRING_CST
4694 && TREE_CODE (op1
) == STRING_CST
4695 && operand_equal_p (op0
, op1
, 1))
4696 return null_pointer_node
;
4702 /* Helper function of initializer_constant_valid_p.
4703 Return nonzero if VALUE is a valid constant-valued expression
4704 for use in initializing a static variable; one that can be an
4705 element of a "constant" initializer.
4707 Return null_pointer_node if the value is absolute;
4708 if it is relocatable, return the variable that determines the relocation.
4709 We assume that VALUE has been folded as much as possible;
4710 therefore, we do not need to check for such things as
4711 arithmetic-combinations of integers.
4713 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4716 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4720 switch (TREE_CODE (value
))
4723 if (constructor_static_from_elts_p (value
))
4725 unsigned HOST_WIDE_INT idx
;
4727 bool absolute
= true;
4729 if (cache
&& cache
[0] == value
)
4731 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4734 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4737 /* An absolute value is required with reverse SSO. */
4738 || (reloc
!= null_pointer_node
4739 && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (value
))
4740 && !AGGREGATE_TYPE_P (TREE_TYPE (elt
))))
4745 cache
[1] = NULL_TREE
;
4749 if (reloc
!= null_pointer_node
)
4752 /* For a non-absolute relocation, there is no single
4753 variable that can be "the variable that determines the
4758 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4760 return absolute
? null_pointer_node
: error_mark_node
;
4763 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4771 return null_pointer_node
;
4776 tree op0
= staticp (TREE_OPERAND (value
, 0));
4779 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4780 to be a constant, this is old-skool offsetof-like nonsense. */
4781 if (TREE_CODE (op0
) == INDIRECT_REF
4782 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4783 return null_pointer_node
;
4784 /* Taking the address of a nested function involves a trampoline,
4785 unless we don't need or want one. */
4786 if (TREE_CODE (op0
) == FUNCTION_DECL
4787 && DECL_STATIC_CHAIN (op0
)
4788 && !TREE_NO_TRAMPOLINE (value
))
4790 /* "&{...}" requires a temporary to hold the constructed
4792 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4798 case NON_LVALUE_EXPR
:
4799 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4802 case VIEW_CONVERT_EXPR
:
4804 tree src
= TREE_OPERAND (value
, 0);
4805 tree src_type
= TREE_TYPE (src
);
4806 tree dest_type
= TREE_TYPE (value
);
4808 /* Allow view-conversions from aggregate to non-aggregate type only
4809 if the bit pattern is fully preserved afterwards; otherwise, the
4810 RTL expander won't be able to apply a subsequent transformation
4811 to the underlying constructor. */
4812 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4814 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4815 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4820 /* Allow all other kinds of view-conversion. */
4821 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4826 tree src
= TREE_OPERAND (value
, 0);
4827 tree src_type
= TREE_TYPE (src
);
4828 tree dest_type
= TREE_TYPE (value
);
4830 /* Allow conversions between pointer types, floating-point
4831 types, and offset types. */
4832 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4833 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4834 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4835 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4836 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4838 /* Allow length-preserving conversions between integer types. */
4839 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4840 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4841 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4843 /* Allow conversions between other integer types only if
4844 explicit value. Don't allow sign-extension to a type larger
4845 than word and pointer, there aren't relocations that would
4846 allow to sign extend it to a wider type. */
4847 if (INTEGRAL_TYPE_P (dest_type
)
4848 && INTEGRAL_TYPE_P (src_type
)
4849 && (TYPE_UNSIGNED (src_type
)
4850 || TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
)
4851 || TYPE_PRECISION (dest_type
) <= BITS_PER_WORD
4852 || TYPE_PRECISION (dest_type
) <= POINTER_SIZE
))
4854 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4855 if (inner
== null_pointer_node
)
4856 return null_pointer_node
;
4860 /* Allow (int) &foo provided int is as wide as a pointer. */
4861 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4862 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4863 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4865 /* Likewise conversions from int to pointers, but also allow
4866 conversions from 0. */
4867 if ((POINTER_TYPE_P (dest_type
)
4868 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4869 && INTEGRAL_TYPE_P (src_type
))
4871 if (TREE_CODE (src
) == INTEGER_CST
4872 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4873 return null_pointer_node
;
4874 if (integer_zerop (src
))
4875 return null_pointer_node
;
4876 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4877 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4880 /* Allow conversions to struct or union types if the value
4882 if (TREE_CODE (dest_type
) == RECORD_TYPE
4883 || TREE_CODE (dest_type
) == UNION_TYPE
)
4884 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4888 case POINTER_PLUS_EXPR
:
4890 /* Any valid floating-point constants will have been folded by now;
4891 with -frounding-math we hit this with addition of two constants. */
4892 if (TREE_CODE (endtype
) == REAL_TYPE
)
4894 if (cache
&& cache
[0] == value
)
4896 if (! INTEGRAL_TYPE_P (endtype
)
4897 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4899 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4901 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4904 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4905 endtype
, ncache
+ 2);
4906 /* If either term is absolute, use the other term's relocation. */
4907 if (valid0
== null_pointer_node
)
4909 else if (valid1
== null_pointer_node
)
4911 /* Support narrowing pointer differences. */
4913 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4917 /* Support narrowing pointer differences. */
4918 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4926 case POINTER_DIFF_EXPR
:
4928 if (TREE_CODE (endtype
) == REAL_TYPE
)
4930 if (cache
&& cache
[0] == value
)
4932 if (! INTEGRAL_TYPE_P (endtype
)
4933 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4935 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4937 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4940 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4941 endtype
, ncache
+ 2);
4942 /* Win if second argument is absolute. */
4943 if (valid1
== null_pointer_node
)
4945 /* Win if both arguments have the same relocation.
4946 Then the value is absolute. */
4947 else if (valid0
== valid1
&& valid0
!= 0)
4948 ret
= null_pointer_node
;
4949 /* Since GCC guarantees that string constants are unique in the
4950 generated code, a subtraction between two copies of the same
4951 constant string is absolute. */
4952 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4953 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4954 && operand_equal_p (valid0
, valid1
, 1))
4955 ret
= null_pointer_node
;
4956 /* Support narrowing differences. */
4958 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4962 /* Support narrowing differences. */
4963 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4978 /* Return nonzero if VALUE is a valid constant-valued expression
4979 for use in initializing a static variable; one that can be an
4980 element of a "constant" initializer.
4982 Return null_pointer_node if the value is absolute;
4983 if it is relocatable, return the variable that determines the relocation.
4984 We assume that VALUE has been folded as much as possible;
4985 therefore, we do not need to check for such things as
4986 arithmetic-combinations of integers. */
4988 initializer_constant_valid_p (tree value
, tree endtype
, bool reverse
)
4990 tree reloc
= initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4992 /* An absolute value is required with reverse storage order. */
4994 && reloc
!= null_pointer_node
4996 && !AGGREGATE_TYPE_P (endtype
)
4997 && !VECTOR_TYPE_P (endtype
))
5003 /* Return true if VALUE is a valid constant-valued expression
5004 for use in initializing a static bit-field; one that can be
5005 an element of a "constant" initializer. */
5008 initializer_constant_valid_for_bitfield_p (tree value
)
5010 /* For bitfields we support integer constants or possibly nested aggregates
5012 switch (TREE_CODE (value
))
5016 unsigned HOST_WIDE_INT idx
;
5019 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
5020 if (!initializer_constant_valid_for_bitfield_p (elt
))
5029 case VIEW_CONVERT_EXPR
:
5030 case NON_LVALUE_EXPR
:
5032 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
5041 /* Check if a STRING_CST fits into the field.
5042 Tolerate only the case when the NUL termination
5043 does not fit into the field. */
5046 check_string_literal (tree string
, unsigned HOST_WIDE_INT size
)
5048 tree type
= TREE_TYPE (string
);
5049 tree eltype
= TREE_TYPE (type
);
5050 unsigned HOST_WIDE_INT elts
= tree_to_uhwi (TYPE_SIZE_UNIT (eltype
));
5051 unsigned HOST_WIDE_INT mem_size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
5052 int len
= TREE_STRING_LENGTH (string
);
5054 if (elts
!= 1 && elts
!= 2 && elts
!= 4)
5056 if (len
< 0 || len
% elts
!= 0)
5058 if (size
< (unsigned)len
)
5060 if (mem_size
!= size
)
5065 /* output_constructor outer state of relevance in recursive calls, typically
5066 for nested aggregate bitfields. */
5068 struct oc_outer_state
{
5069 unsigned int bit_offset
; /* current position in ... */
5070 int byte
; /* ... the outer byte buffer. */
5073 static unsigned HOST_WIDE_INT
5074 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int, bool,
5077 /* Output assembler code for constant EXP, with no label.
5078 This includes the pseudo-op such as ".int" or ".byte", and a newline.
5079 Assumes output_addressed_constants has been done on EXP already.
5081 Generate at least SIZE bytes of assembler data, padding at the end
5082 with zeros if necessary. SIZE must always be specified. The returned
5083 value is the actual number of bytes of assembler data generated, which
5084 may be bigger than SIZE if the object contains a variable length field.
5086 SIZE is important for structure constructors,
5087 since trailing members may have been omitted from the constructor.
5088 It is also important for initialization of arrays from string constants
5089 since the full length of the string constant might not be wanted.
5090 It is also needed for initialization of unions, where the initializer's
5091 type is just one member, and that may not be as long as the union.
5093 There a case in which we would fail to output exactly SIZE bytes:
5094 for a structure constructor that wants to produce more than SIZE bytes.
5095 But such constructors will never be generated for any possible input.
5097 ALIGN is the alignment of the data in bits.
5099 If REVERSE is true, EXP is output in reverse storage order. */
5101 static unsigned HOST_WIDE_INT
5102 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
,
5103 bool reverse
, bool merge_strings
)
5105 enum tree_code code
;
5106 unsigned HOST_WIDE_INT thissize
;
5109 if (size
== 0 || flag_syntax_only
)
5112 /* See if we're trying to initialize a pointer in a non-default mode
5113 to the address of some declaration somewhere. If the target says
5114 the mode is valid for pointers, assume the target has a way of
5116 if (TREE_CODE (exp
) == NOP_EXPR
5117 && POINTER_TYPE_P (TREE_TYPE (exp
))
5118 && targetm
.addr_space
.valid_pointer_mode
5119 (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp
)),
5120 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
5122 tree saved_type
= TREE_TYPE (exp
);
5124 /* Peel off any intermediate conversions-to-pointer for valid
5126 while (TREE_CODE (exp
) == NOP_EXPR
5127 && POINTER_TYPE_P (TREE_TYPE (exp
))
5128 && targetm
.addr_space
.valid_pointer_mode
5129 (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp
)),
5130 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
5131 exp
= TREE_OPERAND (exp
, 0);
5133 /* If what we're left with is the address of something, we can
5134 convert the address to the final type and output it that
5136 if (TREE_CODE (exp
) == ADDR_EXPR
)
5137 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
5138 /* Likewise for constant ints. */
5139 else if (TREE_CODE (exp
) == INTEGER_CST
)
5140 exp
= fold_convert (saved_type
, exp
);
5144 /* Eliminate any conversions since we'll be outputting the underlying
5146 while (CONVERT_EXPR_P (exp
)
5147 || TREE_CODE (exp
) == NON_LVALUE_EXPR
5148 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
5150 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
5151 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
5153 /* Make sure eliminating the conversion is really a no-op, except with
5154 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
5155 union types to allow for Ada unchecked unions. */
5156 if (type_size
> op_size
5157 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
5158 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
5159 /* Keep the conversion. */
5162 exp
= TREE_OPERAND (exp
, 0);
5165 code
= TREE_CODE (TREE_TYPE (exp
));
5166 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
5168 /* Allow a constructor with no elements for any data type.
5169 This means to fill the space with zeros. */
5170 if (TREE_CODE (exp
) == CONSTRUCTOR
5171 && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp
)))
5173 assemble_zeros (size
);
5177 if (TREE_CODE (exp
) == FDESC_EXPR
)
5179 #ifdef ASM_OUTPUT_FDESC
5180 HOST_WIDE_INT part
= tree_to_shwi (TREE_OPERAND (exp
, 1));
5181 tree decl
= TREE_OPERAND (exp
, 0);
5182 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
5189 /* Now output the underlying data. If we've handling the padding, return.
5190 Otherwise, break and ensure SIZE is the size written. */
5197 case REFERENCE_TYPE
:
5199 case FIXED_POINT_TYPE
:
5201 cst
= expand_expr (exp
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
5203 cst
= flip_storage_order (TYPE_MODE (TREE_TYPE (exp
)), cst
);
5204 if (!assemble_integer (cst
, MIN (size
, thissize
), align
, 0))
5205 error ("initializer for integer/fixed-point value is too complicated");
5209 if (TREE_CODE (exp
) != REAL_CST
)
5210 error ("initializer for floating value is not a floating constant");
5212 assemble_real (TREE_REAL_CST (exp
),
5213 SCALAR_FLOAT_TYPE_MODE (TREE_TYPE (exp
)),
5218 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
,
5220 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
5221 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)),
5227 switch (TREE_CODE (exp
))
5230 return output_constructor (exp
, size
, align
, reverse
, NULL
);
5232 thissize
= (unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
);
5235 || TREE_STRING_POINTER (exp
) [thissize
- 1] != '\0'))
5237 gcc_checking_assert (check_string_literal (exp
, size
));
5238 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
5242 scalar_mode inner
= SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
5243 unsigned int nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
5244 int elt_size
= GET_MODE_SIZE (inner
);
5245 output_constant (VECTOR_CST_ELT (exp
, 0), elt_size
, align
,
5247 thissize
= elt_size
;
5248 /* Static constants must have a fixed size. */
5249 unsigned int nunits
= VECTOR_CST_NELTS (exp
).to_constant ();
5250 for (unsigned int i
= 1; i
< nunits
; i
++)
5252 output_constant (VECTOR_CST_ELT (exp
, i
), elt_size
, nalign
,
5254 thissize
+= elt_size
;
5265 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
5266 return output_constructor (exp
, size
, align
, reverse
, NULL
);
5275 if (size
> thissize
)
5276 assemble_zeros (size
- thissize
);
5281 /* Subroutine of output_constructor, used for computing the size of
5282 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
5283 type with an unspecified upper bound. */
5285 static unsigned HOST_WIDE_INT
5286 array_size_for_constructor (tree val
)
5289 unsigned HOST_WIDE_INT cnt
;
5290 tree index
, value
, tmp
;
5293 /* This code used to attempt to handle string constants that are not
5294 arrays of single-bytes, but nothing else does, so there's no point in
5296 if (TREE_CODE (val
) == STRING_CST
)
5297 return TREE_STRING_LENGTH (val
);
5299 max_index
= NULL_TREE
;
5300 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
5302 if (TREE_CODE (index
) == RANGE_EXPR
)
5303 index
= TREE_OPERAND (index
, 1);
5304 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
5308 if (max_index
== NULL_TREE
)
5311 /* Compute the total number of array elements. */
5312 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
5313 i
= wi::to_offset (max_index
) - wi::to_offset (tmp
) + 1;
5315 /* Multiply by the array element unit size to find number of bytes. */
5316 i
*= wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
5318 gcc_assert (wi::fits_uhwi_p (i
));
5319 return i
.to_uhwi ();
5322 /* Other datastructures + helpers for output_constructor. */
5324 /* output_constructor local state to support interaction with helpers. */
5326 struct oc_local_state
{
5328 /* Received arguments. */
5329 tree exp
; /* Constructor expression. */
5330 tree type
; /* Type of constructor expression. */
5331 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
5332 unsigned int align
; /* Known initial alignment. */
5333 tree min_index
; /* Lower bound if specified for an array. */
5335 /* Output processing state. */
5336 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
5337 int byte
; /* Part of a bitfield byte yet to be output. */
5338 int last_relative_index
; /* Implicit or explicit index of the last
5339 array element output within a bitfield. */
5340 bool byte_buffer_in_use
; /* Whether BYTE is in use. */
5341 bool reverse
; /* Whether reverse storage order is in use. */
5343 /* Current element. */
5344 tree field
; /* Current field decl in a record. */
5345 tree val
; /* Current element value. */
5346 tree index
; /* Current element index. */
5350 /* Helper for output_constructor. From the current LOCAL state, output a
5351 RANGE_EXPR element. */
5354 output_constructor_array_range (oc_local_state
*local
)
5356 /* Perform the index calculation in modulo arithmetic but
5357 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5358 but we are using an unsigned sizetype. */
5359 unsigned prec
= TYPE_PRECISION (sizetype
);
5360 offset_int idx
= wi::sext (wi::to_offset (TREE_OPERAND (local
->index
, 0))
5361 - wi::to_offset (local
->min_index
), prec
);
5362 tree valtype
= TREE_TYPE (local
->val
);
5363 HOST_WIDE_INT fieldpos
5364 = (idx
* wi::to_offset (TYPE_SIZE_UNIT (valtype
))).to_short_addr ();
5366 /* Advance to offset of this element. */
5367 if (fieldpos
> local
->total_bytes
)
5369 assemble_zeros (fieldpos
- local
->total_bytes
);
5370 local
->total_bytes
= fieldpos
;
5373 /* Must not go backwards. */
5374 gcc_assert (fieldpos
== local
->total_bytes
);
5376 unsigned HOST_WIDE_INT fieldsize
5377 = int_size_in_bytes (TREE_TYPE (local
->type
));
5379 HOST_WIDE_INT lo_index
5380 = tree_to_shwi (TREE_OPERAND (local
->index
, 0));
5381 HOST_WIDE_INT hi_index
5382 = tree_to_shwi (TREE_OPERAND (local
->index
, 1));
5383 HOST_WIDE_INT index
;
5386 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
5388 for (index
= lo_index
; index
<= hi_index
; index
++)
5390 /* Output the element's initial value. */
5391 if (local
->val
== NULL_TREE
)
5392 assemble_zeros (fieldsize
);
5394 fieldsize
= output_constant (local
->val
, fieldsize
, align2
,
5395 local
->reverse
, false);
5397 /* Count its size. */
5398 local
->total_bytes
+= fieldsize
;
5402 /* Helper for output_constructor. From the current LOCAL state, output a
5403 field element that is not true bitfield or part of an outer one. */
5406 output_constructor_regular_field (oc_local_state
*local
)
5408 /* Field size and position. Since this structure is static, we know the
5409 positions are constant. */
5410 unsigned HOST_WIDE_INT fieldsize
;
5411 HOST_WIDE_INT fieldpos
;
5413 unsigned int align2
;
5415 /* Output any buffered-up bit-fields preceding this element. */
5416 if (local
->byte_buffer_in_use
)
5418 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5419 local
->total_bytes
++;
5420 local
->byte_buffer_in_use
= false;
5423 if (local
->index
!= NULL_TREE
)
5425 /* Perform the index calculation in modulo arithmetic but
5426 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5427 but we are using an unsigned sizetype. */
5428 unsigned prec
= TYPE_PRECISION (sizetype
);
5429 offset_int idx
= wi::sext (wi::to_offset (local
->index
)
5430 - wi::to_offset (local
->min_index
), prec
);
5431 fieldpos
= (idx
* wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
))))
5434 else if (local
->field
!= NULL_TREE
)
5435 fieldpos
= int_byte_position (local
->field
);
5439 /* Advance to offset of this element.
5440 Note no alignment needed in an array, since that is guaranteed
5441 if each element has the proper size. */
5442 if (local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
5444 if (fieldpos
> local
->total_bytes
)
5446 assemble_zeros (fieldpos
- local
->total_bytes
);
5447 local
->total_bytes
= fieldpos
;
5450 /* Must not go backwards. */
5451 gcc_assert (fieldpos
== local
->total_bytes
);
5454 /* Find the alignment of this element. */
5455 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
5457 /* Determine size this element should occupy. */
5462 /* If this is an array with an unspecified upper bound,
5463 the initializer determines the size. */
5464 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5465 but we cannot do this until the deprecated support for
5466 initializing zero-length array members is removed. */
5467 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
5468 && (!TYPE_DOMAIN (TREE_TYPE (local
->field
))
5469 || !TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
)))))
5471 fieldsize
= array_size_for_constructor (local
->val
);
5472 /* Given a non-empty initialization, this field had better
5473 be last. Given a flexible array member, the next field
5474 on the chain is a TYPE_DECL of the enclosing struct. */
5475 const_tree next
= DECL_CHAIN (local
->field
);
5476 gcc_assert (!fieldsize
|| !next
|| TREE_CODE (next
) != FIELD_DECL
);
5477 tree size
= TYPE_SIZE_UNIT (TREE_TYPE (local
->val
));
5478 gcc_checking_assert (compare_tree_int (size
, fieldsize
) == 0);
5481 fieldsize
= tree_to_uhwi (DECL_SIZE_UNIT (local
->field
));
5484 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
5486 /* Output the element's initial value. */
5487 if (local
->val
== NULL_TREE
)
5488 assemble_zeros (fieldsize
);
5490 fieldsize
= output_constant (local
->val
, fieldsize
, align2
,
5491 local
->reverse
, false);
5493 /* Count its size. */
5494 local
->total_bytes
+= fieldsize
;
5497 /* Helper for output_constructor. From the LOCAL state, output an element
5498 that is a true bitfield or part of an outer one. BIT_OFFSET is the offset
5499 from the start of a possibly ongoing outer byte buffer. */
5502 output_constructor_bitfield (oc_local_state
*local
, unsigned int bit_offset
)
5504 /* Bit size of this element. */
5505 HOST_WIDE_INT ebitsize
5507 ? tree_to_uhwi (DECL_SIZE (local
->field
))
5508 : tree_to_uhwi (TYPE_SIZE (TREE_TYPE (local
->type
))));
5510 /* Relative index of this element if this is an array component. */
5511 HOST_WIDE_INT relative_index
5514 ? (tree_to_shwi (local
->index
)
5515 - tree_to_shwi (local
->min_index
))
5516 : local
->last_relative_index
+ 1)
5519 /* Bit position of this element from the start of the containing
5521 HOST_WIDE_INT constructor_relative_ebitpos
5523 ? int_bit_position (local
->field
)
5524 : ebitsize
* relative_index
);
5526 /* Bit position of this element from the start of a possibly ongoing
5527 outer byte buffer. */
5528 HOST_WIDE_INT byte_relative_ebitpos
5529 = bit_offset
+ constructor_relative_ebitpos
;
5531 /* From the start of a possibly ongoing outer byte buffer, offsets to
5532 the first bit of this element and to the first bit past the end of
5534 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
5535 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
5537 local
->last_relative_index
= relative_index
;
5539 if (local
->val
== NULL_TREE
)
5540 local
->val
= integer_zero_node
;
5542 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
5543 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
5544 local
->val
= TREE_OPERAND (local
->val
, 0);
5546 if (TREE_CODE (local
->val
) != INTEGER_CST
5547 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
5549 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
5553 /* If this field does not start in this (or next) byte, skip some bytes. */
5554 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5556 /* Output remnant of any bit field in previous bytes. */
5557 if (local
->byte_buffer_in_use
)
5559 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5560 local
->total_bytes
++;
5561 local
->byte_buffer_in_use
= false;
5564 /* If still not at proper byte, advance to there. */
5565 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5567 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
5568 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
5569 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
5573 /* Set up the buffer if necessary. */
5574 if (!local
->byte_buffer_in_use
)
5578 local
->byte_buffer_in_use
= true;
5581 /* If this is nested constructor, recurse passing the bit offset and the
5582 pending data, then retrieve the new pending data afterwards. */
5583 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
5585 oc_outer_state temp_state
;
5586 temp_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
5587 temp_state
.byte
= local
->byte
;
5589 += output_constructor (local
->val
, 0, 0, local
->reverse
, &temp_state
);
5590 local
->byte
= temp_state
.byte
;
5594 /* Otherwise, we must split the element into pieces that fall within
5595 separate bytes, and combine each byte with previous or following
5597 while (next_offset
< end_offset
)
5601 unsigned HOST_WIDE_INT value
;
5602 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5603 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5605 /* Advance from byte to byte within this element when necessary. */
5606 while (next_byte
!= local
->total_bytes
)
5608 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5609 local
->total_bytes
++;
5613 /* Number of bits we can process at once (all part of the same byte). */
5614 this_time
= MIN (end_offset
- next_offset
, BITS_PER_UNIT
- next_bit
);
5615 if (local
->reverse
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
)
5617 /* For big-endian data, take the most significant bits (of the
5618 bits that are significant) first and put them into bytes from
5619 the most significant end. */
5620 shift
= end_offset
- next_offset
- this_time
;
5622 /* Don't try to take a bunch of bits that cross
5623 the word boundary in the INTEGER_CST. We can
5624 only select bits from one element. */
5625 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5626 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5628 const int end
= shift
+ this_time
- 1;
5629 shift
= end
& -HOST_BITS_PER_WIDE_INT
;
5630 this_time
= end
- shift
+ 1;
5633 /* Now get the bits we want to insert. */
5634 value
= wi::extract_uhwi (wi::to_widest (local
->val
),
5637 /* Get the result. This works only when:
5638 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5639 local
->byte
|= value
<< (BITS_PER_UNIT
- this_time
- next_bit
);
5643 /* On little-endian machines, take the least significant bits of
5644 the value first and pack them starting at the least significant
5645 bits of the bytes. */
5646 shift
= next_offset
- byte_relative_ebitpos
;
5648 /* Don't try to take a bunch of bits that cross
5649 the word boundary in the INTEGER_CST. We can
5650 only select bits from one element. */
5651 if ((shift
/ HOST_BITS_PER_WIDE_INT
)
5652 != ((shift
+ this_time
- 1) / HOST_BITS_PER_WIDE_INT
))
5654 = HOST_BITS_PER_WIDE_INT
- (shift
& (HOST_BITS_PER_WIDE_INT
- 1));
5656 /* Now get the bits we want to insert. */
5657 value
= wi::extract_uhwi (wi::to_widest (local
->val
),
5660 /* Get the result. This works only when:
5661 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5662 local
->byte
|= value
<< next_bit
;
5665 next_offset
+= this_time
;
5666 local
->byte_buffer_in_use
= true;
5670 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5671 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5672 caller output state of relevance in recursive invocations. */
5674 static unsigned HOST_WIDE_INT
5675 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
,
5676 bool reverse
, oc_outer_state
*outer
)
5678 unsigned HOST_WIDE_INT cnt
;
5679 constructor_elt
*ce
;
5680 oc_local_state local
;
5682 /* Setup our local state to communicate with helpers. */
5684 local
.type
= TREE_TYPE (exp
);
5686 local
.align
= align
;
5687 if (TREE_CODE (local
.type
) == ARRAY_TYPE
&& TYPE_DOMAIN (local
.type
))
5688 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5690 local
.min_index
= integer_zero_node
;
5692 local
.total_bytes
= 0;
5693 local
.byte_buffer_in_use
= outer
!= NULL
;
5694 local
.byte
= outer
? outer
->byte
: 0;
5695 local
.last_relative_index
= -1;
5696 /* The storage order is specified for every aggregate type. */
5697 if (AGGREGATE_TYPE_P (local
.type
))
5698 local
.reverse
= TYPE_REVERSE_STORAGE_ORDER (local
.type
);
5700 local
.reverse
= reverse
;
5702 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5704 /* As CE goes through the elements of the constant, FIELD goes through the
5705 structure fields if the constant is a structure. If the constant is a
5706 union, we override this by getting the field from the TREE_LIST element.
5707 But the constant could also be an array. Then FIELD is zero.
5709 There is always a maximum of one element in the chain LINK for unions
5710 (even if the initializer in a source program incorrectly contains
5713 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5714 local
.field
= TYPE_FIELDS (local
.type
);
5716 local
.field
= NULL_TREE
;
5719 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), cnt
, &ce
);
5720 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
5722 local
.val
= ce
->value
;
5723 local
.index
= NULL_TREE
;
5725 /* The element in a union constructor specifies the proper field
5727 if (RECORD_OR_UNION_TYPE_P (local
.type
) && ce
->index
!= NULL_TREE
)
5728 local
.field
= ce
->index
;
5730 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5731 local
.index
= ce
->index
;
5733 if (local
.field
&& flag_verbose_asm
)
5734 fprintf (asm_out_file
, "%s %s:\n",
5736 DECL_NAME (local
.field
)
5737 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5740 /* Eliminate the marker that makes a cast not be an lvalue. */
5741 if (local
.val
!= NULL_TREE
)
5742 STRIP_NOPS (local
.val
);
5744 /* Output the current element, using the appropriate helper ... */
5746 /* For an array slice not part of an outer bitfield. */
5748 && local
.index
!= NULL_TREE
5749 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5750 output_constructor_array_range (&local
);
5752 /* For a field that is neither a true bitfield nor part of an outer one,
5753 known to be at least byte aligned and multiple-of-bytes long. */
5755 && (local
.field
== NULL_TREE
5756 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5757 output_constructor_regular_field (&local
);
5759 /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
5760 supported for scalar fields, so we may need to convert first. */
5763 if (TREE_CODE (local
.val
) == REAL_CST
)
5765 = fold_unary (VIEW_CONVERT_EXPR
,
5766 build_nonstandard_integer_type
5767 (TYPE_PRECISION (TREE_TYPE (local
.val
)), 0),
5769 output_constructor_bitfield (&local
, outer
? outer
->bit_offset
: 0);
5773 /* If we are not at toplevel, save the pending data for our caller.
5774 Otherwise output the pending data and padding zeros as needed. */
5776 outer
->byte
= local
.byte
;
5779 if (local
.byte_buffer_in_use
)
5781 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5782 local
.total_bytes
++;
5785 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5787 assemble_zeros (local
.size
- local
.total_bytes
);
5788 local
.total_bytes
= local
.size
;
5792 return local
.total_bytes
;
5795 /* Mark DECL as weak. */
5798 mark_weak (tree decl
)
5800 if (DECL_WEAK (decl
))
5803 struct symtab_node
*n
= symtab_node::get (decl
);
5804 if (n
&& n
->refuse_visibility_changes
)
5805 error ("%+qD declared weak after being used", decl
);
5806 DECL_WEAK (decl
) = 1;
5808 if (DECL_RTL_SET_P (decl
)
5809 && MEM_P (DECL_RTL (decl
))
5810 && XEXP (DECL_RTL (decl
), 0)
5811 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5812 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5815 /* Merge weak status between NEWDECL and OLDDECL. */
5818 merge_weak (tree newdecl
, tree olddecl
)
5820 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5822 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5825 /* We put the NEWDECL on the weak_decls list at some point
5826 and OLDDECL as well. Keep just OLDDECL on the list. */
5827 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5828 if (TREE_VALUE (*pwd
) == newdecl
)
5830 *pwd
= TREE_CHAIN (*pwd
);
5837 if (DECL_WEAK (newdecl
))
5841 /* NEWDECL is weak, but OLDDECL is not. */
5843 /* If we already output the OLDDECL, we're in trouble; we can't
5844 go back and make it weak. This should never happen in
5845 unit-at-a-time compilation. */
5846 gcc_assert (!TREE_ASM_WRITTEN (olddecl
));
5848 /* If we've already generated rtl referencing OLDDECL, we may
5849 have done so in a way that will not function properly with
5850 a weak symbol. Again in unit-at-a-time this should be
5852 gcc_assert (!TREE_USED (olddecl
)
5853 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)));
5855 /* PR 49899: You cannot convert a static function into a weak, public function. */
5856 if (! TREE_PUBLIC (olddecl
) && TREE_PUBLIC (newdecl
))
5857 error ("weak declaration of %q+D being applied to a already "
5858 "existing, static definition", newdecl
);
5860 if (TARGET_SUPPORTS_WEAK
)
5862 /* We put the NEWDECL on the weak_decls list at some point.
5863 Replace it with the OLDDECL. */
5864 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5865 if (TREE_VALUE (wd
) == newdecl
)
5867 TREE_VALUE (wd
) = olddecl
;
5870 /* We may not find the entry on the list. If NEWDECL is a
5871 weak alias, then we will have already called
5872 globalize_decl to remove the entry; in that case, we do
5873 not need to do anything. */
5876 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5877 mark_weak (olddecl
);
5880 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5881 weak. Just update NEWDECL to indicate that it's weak too. */
5882 mark_weak (newdecl
);
5885 /* Declare DECL to be a weak symbol. */
5888 declare_weak (tree decl
)
5890 gcc_assert (TREE_CODE (decl
) != FUNCTION_DECL
|| !TREE_ASM_WRITTEN (decl
));
5891 if (! TREE_PUBLIC (decl
))
5893 error ("weak declaration of %q+D must be public", decl
);
5896 else if (!TARGET_SUPPORTS_WEAK
)
5897 warning (0, "weak declaration of %q+D not supported", decl
);
5900 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5901 DECL_ATTRIBUTES (decl
)
5902 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5906 weak_finish_1 (tree decl
)
5908 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5909 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5912 if (! TREE_USED (decl
))
5915 #ifdef ASM_WEAKEN_DECL
5916 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5918 #ifdef ASM_WEAKEN_LABEL
5919 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5921 #ifdef ASM_OUTPUT_WEAK_ALIAS
5923 static bool warn_once
= 0;
5926 warning (0, "only weak aliases are supported in this configuration");
5936 /* Fiven an assembly name, find the decl it is associated with. */
5938 find_decl (tree target
)
5940 symtab_node
*node
= symtab_node::get_for_asmname (target
);
5946 /* This TREE_LIST contains weakref targets. */
5948 static GTY(()) tree weakref_targets
;
5950 /* Emit any pending weak declarations. */
5957 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5959 tree alias_decl
= TREE_PURPOSE (t
);
5960 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5962 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
))
5963 || TREE_SYMBOL_REFERENCED (target
))
5964 /* Remove alias_decl from the weak list, but leave entries for
5965 the target alone. */
5967 #ifndef ASM_OUTPUT_WEAKREF
5968 else if (! TREE_SYMBOL_REFERENCED (target
))
5970 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5971 defined, otherwise we and weak_finish_1 would use
5972 different macros. */
5973 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5974 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5976 tree decl
= find_decl (target
);
5980 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5981 TREE_CODE (alias_decl
), target
,
5982 TREE_TYPE (alias_decl
));
5984 DECL_EXTERNAL (decl
) = 1;
5985 TREE_PUBLIC (decl
) = 1;
5986 DECL_ARTIFICIAL (decl
) = 1;
5987 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5988 TREE_USED (decl
) = 1;
5991 weak_finish_1 (decl
);
6000 /* Remove the alias and the target from the pending weak list
6001 so that we do not emit any .weak directives for the former,
6002 nor multiple .weak directives for the latter. */
6003 for (p
= &weak_decls
; (t2
= *p
) ; )
6005 if (TREE_VALUE (t2
) == alias_decl
6006 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
6007 *p
= TREE_CHAIN (t2
);
6009 p
= &TREE_CHAIN (t2
);
6012 /* Remove other weakrefs to the same target, to speed things up. */
6013 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
6015 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
6016 *p
= TREE_CHAIN (t2
);
6018 p
= &TREE_CHAIN (t2
);
6023 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
6025 tree decl
= TREE_VALUE (t
);
6027 weak_finish_1 (decl
);
6031 /* Emit the assembly bits to indicate that DECL is globally visible. */
6034 globalize_decl (tree decl
)
6037 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
6038 if (DECL_WEAK (decl
))
6040 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6043 #ifdef ASM_WEAKEN_DECL
6044 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
6046 ASM_WEAKEN_LABEL (asm_out_file
, name
);
6049 /* Remove this function from the pending weak list so that
6050 we do not emit multiple .weak directives for it. */
6051 for (p
= &weak_decls
; (t
= *p
) ; )
6053 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
6054 *p
= TREE_CHAIN (t
);
6056 p
= &TREE_CHAIN (t
);
6059 /* Remove weakrefs to the same target from the pending weakref
6060 list, for the same reason. */
6061 for (p
= &weakref_targets
; (t
= *p
) ; )
6063 if (DECL_ASSEMBLER_NAME (decl
)
6064 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
6065 *p
= TREE_CHAIN (t
);
6067 p
= &TREE_CHAIN (t
);
6074 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
6077 vec
<alias_pair
, va_gc
> *alias_pairs
;
6079 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
6080 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
6081 tree node is DECL to have the value of the tree node TARGET. */
6084 do_assemble_alias (tree decl
, tree target
)
6088 /* Emulated TLS had better not get this var. */
6089 gcc_assert (!(!targetm
.have_tls
6091 && DECL_THREAD_LOCAL_P (decl
)));
6093 if (TREE_ASM_WRITTEN (decl
))
6096 id
= DECL_ASSEMBLER_NAME (decl
);
6097 ultimate_transparent_alias_target (&id
);
6098 ultimate_transparent_alias_target (&target
);
6100 /* We must force creation of DECL_RTL for debug info generation, even though
6101 we don't use it here. */
6102 make_decl_rtl (decl
);
6104 TREE_ASM_WRITTEN (decl
) = 1;
6105 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
6106 TREE_ASM_WRITTEN (id
) = 1;
6108 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
6110 if (!TREE_SYMBOL_REFERENCED (target
))
6111 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
6113 #ifdef ASM_OUTPUT_WEAKREF
6114 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
6115 IDENTIFIER_POINTER (id
),
6116 IDENTIFIER_POINTER (target
));
6118 if (!TARGET_SUPPORTS_WEAK
)
6120 error_at (DECL_SOURCE_LOCATION (decl
),
6121 "weakref is not supported in this configuration");
6128 #ifdef ASM_OUTPUT_DEF
6129 tree orig_decl
= decl
;
6131 /* Make name accessible from other files, if appropriate. */
6133 if (TREE_PUBLIC (decl
) || TREE_PUBLIC (orig_decl
))
6135 globalize_decl (decl
);
6136 maybe_assemble_visibility (decl
);
6138 if (TREE_CODE (decl
) == FUNCTION_DECL
6139 && cgraph_node::get (decl
)->ifunc_resolver
)
6141 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
6142 if (targetm
.has_ifunc_p ())
6143 ASM_OUTPUT_TYPE_DIRECTIVE
6144 (asm_out_file
, IDENTIFIER_POINTER (id
),
6148 error_at (DECL_SOURCE_LOCATION (decl
),
6149 "%qs is not supported on this target", "ifunc");
6152 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
6153 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
6155 ASM_OUTPUT_DEF (asm_out_file
,
6156 IDENTIFIER_POINTER (id
),
6157 IDENTIFIER_POINTER (target
));
6159 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
6164 name
= IDENTIFIER_POINTER (id
);
6165 # ifdef ASM_WEAKEN_DECL
6166 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
6168 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
6170 /* Remove this function from the pending weak list so that
6171 we do not emit multiple .weak directives for it. */
6172 for (p
= &weak_decls
; (t
= *p
) ; )
6173 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
))
6174 || id
== DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
6175 *p
= TREE_CHAIN (t
);
6177 p
= &TREE_CHAIN (t
);
6179 /* Remove weakrefs to the same target from the pending weakref
6180 list, for the same reason. */
6181 for (p
= &weakref_targets
; (t
= *p
) ; )
6183 if (id
== ultimate_transparent_alias_target (&TREE_VALUE (t
)))
6184 *p
= TREE_CHAIN (t
);
6186 p
= &TREE_CHAIN (t
);
6192 /* Output .symver directive. */
6195 do_assemble_symver (tree decl
, tree target
)
6197 tree id
= DECL_ASSEMBLER_NAME (decl
);
6198 ultimate_transparent_alias_target (&id
);
6199 ultimate_transparent_alias_target (&target
);
6200 #ifdef ASM_OUTPUT_SYMVER_DIRECTIVE
6201 ASM_OUTPUT_SYMVER_DIRECTIVE (asm_out_file
,
6202 IDENTIFIER_POINTER (target
),
6203 IDENTIFIER_POINTER (id
));
6205 error ("symver is only supported on ELF platforms");
6209 /* Emit an assembler directive to make the symbol for DECL an alias to
6210 the symbol for TARGET. */
6213 assemble_alias (tree decl
, tree target
)
6217 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
6219 tree alias
= DECL_ASSEMBLER_NAME (decl
);
6221 ultimate_transparent_alias_target (&target
);
6223 if (alias
== target
)
6224 error ("%qs symbol %q+D ultimately targets itself", "weakref", decl
);
6225 if (TREE_PUBLIC (decl
))
6226 error ("%qs symbol %q+D must have static linkage", "weakref", decl
);
6230 #if !defined (ASM_OUTPUT_DEF)
6231 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
6232 error_at (DECL_SOURCE_LOCATION (decl
),
6233 "alias definitions not supported in this configuration");
6234 TREE_ASM_WRITTEN (decl
) = 1;
6237 if (!DECL_WEAK (decl
))
6239 /* NB: ifunc_resolver isn't set when an error is detected. */
6240 if (TREE_CODE (decl
) == FUNCTION_DECL
6241 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
6242 error_at (DECL_SOURCE_LOCATION (decl
),
6243 "%qs is not supported in this configuration", "ifunc");
6245 error_at (DECL_SOURCE_LOCATION (decl
),
6246 "only weak aliases are supported in this configuration");
6247 TREE_ASM_WRITTEN (decl
) = 1;
6253 TREE_USED (decl
) = 1;
6255 /* Allow aliases to aliases. */
6256 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6257 cgraph_node::get_create (decl
)->alias
= true;
6259 varpool_node::get_create (decl
)->alias
= true;
6261 /* If the target has already been emitted, we don't have to queue the
6262 alias. This saves a tad of memory. */
6263 if (symtab
->global_info_ready
)
6264 target_decl
= find_decl (target
);
6267 if ((target_decl
&& TREE_ASM_WRITTEN (target_decl
))
6268 || symtab
->state
>= EXPANSION
)
6269 do_assemble_alias (decl
, target
);
6272 alias_pair p
= {decl
, target
};
6273 vec_safe_push (alias_pairs
, p
);
6277 /* Record and output a table of translations from original function
6278 to its transaction aware clone. Note that tm_pure functions are
6279 considered to be their own clone. */
6281 struct tm_clone_hasher
: ggc_cache_ptr_hash
<tree_map
>
6283 static hashval_t
hash (tree_map
*m
) { return tree_map_hash (m
); }
6284 static bool equal (tree_map
*a
, tree_map
*b
) { return tree_map_eq (a
, b
); }
6287 keep_cache_entry (tree_map
*&e
)
6289 return ggc_marked_p (e
->base
.from
);
6293 static GTY((cache
)) hash_table
<tm_clone_hasher
> *tm_clone_hash
;
6296 record_tm_clone_pair (tree o
, tree n
)
6298 struct tree_map
**slot
, *h
;
6300 if (tm_clone_hash
== NULL
)
6301 tm_clone_hash
= hash_table
<tm_clone_hasher
>::create_ggc (32);
6303 h
= ggc_alloc
<tree_map
> ();
6304 h
->hash
= htab_hash_pointer (o
);
6308 slot
= tm_clone_hash
->find_slot_with_hash (h
, h
->hash
, INSERT
);
6313 get_tm_clone_pair (tree o
)
6317 struct tree_map
*h
, in
;
6320 in
.hash
= htab_hash_pointer (o
);
6321 h
= tm_clone_hash
->find_with_hash (&in
, in
.hash
);
6328 struct tm_alias_pair
6336 /* Dump the actual pairs to the .tm_clone_table section. */
6339 dump_tm_clone_pairs (vec
<tm_alias_pair
> tm_alias_pairs
)
6343 bool switched
= false;
6345 FOR_EACH_VEC_ELT (tm_alias_pairs
, i
, p
)
6349 struct cgraph_node
*src_n
= cgraph_node::get (src
);
6350 struct cgraph_node
*dst_n
= cgraph_node::get (dst
);
6352 /* The function ipa_tm_create_version() marks the clone as needed if
6353 the original function was needed. But we also mark the clone as
6354 needed if we ever called the clone indirectly through
6355 TM_GETTMCLONE. If neither of these are true, we didn't generate
6356 a clone, and we didn't call it indirectly... no sense keeping it
6357 in the clone table. */
6358 if (!dst_n
|| !dst_n
->definition
)
6361 /* This covers the case where we have optimized the original
6362 function away, and only access the transactional clone. */
6363 if (!src_n
|| !src_n
->definition
)
6368 switch_to_section (targetm
.asm_out
.tm_clone_table_section ());
6369 assemble_align (POINTER_SIZE
);
6373 assemble_integer (XEXP (DECL_RTL (src
), 0),
6374 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
6375 assemble_integer (XEXP (DECL_RTL (dst
), 0),
6376 POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
6380 /* Provide a default for the tm_clone_table section. */
6383 default_clone_table_section (void)
6385 return get_named_section (NULL
, ".tm_clone_table", 3);
6388 /* Helper comparison function for qsorting by the DECL_UID stored in
6389 alias_pair->emitted_diags. */
6392 tm_alias_pair_cmp (const void *x
, const void *y
)
6394 const tm_alias_pair
*p1
= (const tm_alias_pair
*) x
;
6395 const tm_alias_pair
*p2
= (const tm_alias_pair
*) y
;
6396 if (p1
->uid
< p2
->uid
)
6398 if (p1
->uid
> p2
->uid
)
6404 finish_tm_clone_pairs (void)
6406 vec
<tm_alias_pair
> tm_alias_pairs
= vNULL
;
6408 if (tm_clone_hash
== NULL
)
6411 /* We need a determenistic order for the .tm_clone_table, otherwise
6412 we will get bootstrap comparison failures, so dump the hash table
6413 to a vector, sort it, and dump the vector. */
6415 /* Dump the hashtable to a vector. */
6417 hash_table
<tm_clone_hasher
>::iterator iter
;
6418 FOR_EACH_HASH_TABLE_ELEMENT (*tm_clone_hash
, map
, tree_map
*, iter
)
6420 tm_alias_pair p
= {DECL_UID (map
->base
.from
), map
->base
.from
, map
->to
};
6421 tm_alias_pairs
.safe_push (p
);
6424 tm_alias_pairs
.qsort (tm_alias_pair_cmp
);
6427 dump_tm_clone_pairs (tm_alias_pairs
);
6429 tm_clone_hash
->empty ();
6430 tm_clone_hash
= NULL
;
6431 tm_alias_pairs
.release ();
6435 /* Emit an assembler directive to set symbol for DECL visibility to
6436 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
6439 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
6440 int vis ATTRIBUTE_UNUSED
)
6442 #ifdef HAVE_GAS_HIDDEN
6443 static const char * const visibility_types
[] = {
6444 NULL
, "protected", "hidden", "internal"
6447 const char *name
, *type
;
6450 id
= DECL_ASSEMBLER_NAME (decl
);
6451 ultimate_transparent_alias_target (&id
);
6452 name
= IDENTIFIER_POINTER (id
);
6454 type
= visibility_types
[vis
];
6456 fprintf (asm_out_file
, "\t.%s\t", type
);
6457 assemble_name (asm_out_file
, name
);
6458 fprintf (asm_out_file
, "\n");
6460 if (!DECL_ARTIFICIAL (decl
))
6461 warning (OPT_Wattributes
, "visibility attribute not supported "
6462 "in this configuration; ignored");
6466 /* A helper function to call assemble_visibility when needed for a decl. */
6469 maybe_assemble_visibility (tree decl
)
6471 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
6472 if (vis
!= VISIBILITY_DEFAULT
)
6474 targetm
.asm_out
.assemble_visibility (decl
, vis
);
6481 /* Returns 1 if the target configuration supports defining public symbols
6482 so that one of them will be chosen at link time instead of generating a
6483 multiply-defined symbol error, whether through the use of weak symbols or
6484 a target-specific mechanism for having duplicates discarded. */
6487 supports_one_only (void)
6489 if (SUPPORTS_ONE_ONLY
)
6491 return TARGET_SUPPORTS_WEAK
;
6494 /* Set up DECL as a public symbol that can be defined in multiple
6495 translation units without generating a linker error. */
6498 make_decl_one_only (tree decl
, tree comdat_group
)
6500 struct symtab_node
*symbol
;
6501 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
6503 TREE_PUBLIC (decl
) = 1;
6506 symbol
= varpool_node::get_create (decl
);
6508 symbol
= cgraph_node::get_create (decl
);
6510 if (SUPPORTS_ONE_ONLY
)
6512 #ifdef MAKE_DECL_ONE_ONLY
6513 MAKE_DECL_ONE_ONLY (decl
);
6515 symbol
->set_comdat_group (comdat_group
);
6517 else if (VAR_P (decl
)
6518 && (DECL_INITIAL (decl
) == 0
6519 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
6520 DECL_COMMON (decl
) = 1;
6523 gcc_assert (TARGET_SUPPORTS_WEAK
);
6524 DECL_WEAK (decl
) = 1;
6529 init_varasm_once (void)
6531 section_htab
= hash_table
<section_hasher
>::create_ggc (31);
6532 object_block_htab
= hash_table
<object_block_hasher
>::create_ggc (31);
6533 const_desc_htab
= hash_table
<tree_descriptor_hasher
>::create_ggc (1009);
6535 shared_constant_pool
= create_constant_pool ();
6537 #ifdef TEXT_SECTION_ASM_OP
6538 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
6539 TEXT_SECTION_ASM_OP
);
6542 #ifdef DATA_SECTION_ASM_OP
6543 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6544 DATA_SECTION_ASM_OP
);
6547 #ifdef SDATA_SECTION_ASM_OP
6548 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6549 SDATA_SECTION_ASM_OP
);
6552 #ifdef READONLY_DATA_SECTION_ASM_OP
6553 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
6554 READONLY_DATA_SECTION_ASM_OP
);
6557 #ifdef CTORS_SECTION_ASM_OP
6558 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
6559 CTORS_SECTION_ASM_OP
);
6562 #ifdef DTORS_SECTION_ASM_OP
6563 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
6564 DTORS_SECTION_ASM_OP
);
6567 #ifdef BSS_SECTION_ASM_OP
6568 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6569 output_section_asm_op
,
6570 BSS_SECTION_ASM_OP
);
6573 #ifdef SBSS_SECTION_ASM_OP
6574 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6575 output_section_asm_op
,
6576 SBSS_SECTION_ASM_OP
);
6579 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6580 | SECTION_COMMON
, emit_tls_common
);
6581 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6582 | SECTION_COMMON
, emit_local
);
6583 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6584 | SECTION_COMMON
, emit_common
);
6586 #if defined ASM_OUTPUT_ALIGNED_BSS
6587 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
6591 targetm
.asm_out
.init_sections ();
6593 if (readonly_data_section
== NULL
)
6594 readonly_data_section
= text_section
;
6596 #ifdef ASM_OUTPUT_EXTERNAL
6597 pending_assemble_externals_set
= new hash_set
<tree
>;
6602 decl_default_tls_model (const_tree decl
)
6604 enum tls_model kind
;
6607 is_local
= targetm
.binds_local_p (decl
);
6611 kind
= TLS_MODEL_LOCAL_EXEC
;
6613 kind
= TLS_MODEL_INITIAL_EXEC
;
6616 /* Local dynamic is inefficient when we're not combining the
6617 parts of the address. */
6618 else if (optimize
&& is_local
)
6619 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6621 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6622 if (kind
< flag_tls_default
)
6623 kind
= flag_tls_default
;
6628 /* Select a set of attributes for section NAME based on the properties
6629 of DECL and whether or not RELOC indicates that DECL's initializer
6630 might contain runtime relocations.
6632 We make the section read-only and executable for a function decl,
6633 read-only for a const data decl, and writable for a non-const data decl. */
6636 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6640 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6641 flags
= SECTION_CODE
;
6644 enum section_category category
6645 = categorize_decl_for_section (decl
, reloc
);
6646 if (decl_readonly_section_1 (category
))
6648 else if (category
== SECCAT_DATA_REL_RO
6649 || category
== SECCAT_DATA_REL_RO_LOCAL
)
6650 flags
= SECTION_WRITE
| SECTION_RELRO
;
6652 flags
= SECTION_WRITE
;
6656 flags
= SECTION_WRITE
;
6657 if (strcmp (name
, ".data.rel.ro") == 0
6658 || strcmp (name
, ".data.rel.ro.local") == 0)
6659 flags
|= SECTION_RELRO
;
6662 if (decl
&& DECL_P (decl
) && DECL_COMDAT_GROUP (decl
))
6663 flags
|= SECTION_LINKONCE
;
6665 if (strcmp (name
, ".vtable_map_vars") == 0)
6666 flags
|= SECTION_LINKONCE
;
6668 if (decl
&& VAR_P (decl
) && DECL_THREAD_LOCAL_P (decl
))
6669 flags
|= SECTION_TLS
| SECTION_WRITE
;
6671 if (strcmp (name
, ".bss") == 0
6672 || strncmp (name
, ".bss.", 5) == 0
6673 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6674 || strcmp (name
, ".persistent.bss") == 0
6675 || strcmp (name
, ".sbss") == 0
6676 || strncmp (name
, ".sbss.", 6) == 0
6677 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6678 flags
|= SECTION_BSS
;
6680 if (strcmp (name
, ".tdata") == 0
6681 || strncmp (name
, ".tdata.", 7) == 0
6682 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6683 flags
|= SECTION_TLS
;
6685 if (strcmp (name
, ".tbss") == 0
6686 || strncmp (name
, ".tbss.", 6) == 0
6687 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6688 flags
|= SECTION_TLS
| SECTION_BSS
;
6690 if (strcmp (name
, ".noinit") == 0)
6691 flags
|= SECTION_WRITE
| SECTION_BSS
| SECTION_NOTYPE
;
6693 if (strcmp (name
, ".persistent") == 0)
6694 flags
|= SECTION_WRITE
| SECTION_NOTYPE
;
6696 /* Various sections have special ELF types that the assembler will
6697 assign by default based on the name. They are neither SHT_PROGBITS
6698 nor SHT_NOBITS, so when changing sections we don't want to print a
6699 section type (@progbits or @nobits). Rather than duplicating the
6700 assembler's knowledge of what those special name patterns are, just
6701 let the assembler choose the type if we don't know a specific
6702 reason to set it to something other than the default. SHT_PROGBITS
6703 is the default for sections whose name is not specially known to
6704 the assembler, so it does no harm to leave the choice to the
6705 assembler when @progbits is the best thing we know to use. If
6706 someone is silly enough to emit code or TLS variables to one of
6707 these sections, then don't handle them specially.
6709 default_elf_asm_named_section (below) handles the BSS, TLS, ENTSIZE, and
6710 LINKONCE cases when NOTYPE is not set, so leave those to its logic. */
6711 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
| SECTION_ENTSIZE
))
6712 && !(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
)))
6713 flags
|= SECTION_NOTYPE
;
6718 /* Return true if the target supports some form of global BSS,
6719 either through bss_noswitch_section, or by selecting a BSS
6720 section in TARGET_ASM_SELECT_SECTION. */
6723 have_global_bss_p (void)
6725 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6728 /* Output assembly to switch to section NAME with attribute FLAGS.
6729 Four variants for common object file formats. */
6732 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6733 unsigned int flags ATTRIBUTE_UNUSED
,
6734 tree decl ATTRIBUTE_UNUSED
)
6736 /* Some object formats don't support named sections at all. The
6737 front-end should already have flagged this as an error. */
6741 #ifndef TLS_SECTION_ASM_FLAG
6742 #define TLS_SECTION_ASM_FLAG 'T'
6746 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6749 char flagchars
[11], *f
= flagchars
;
6750 unsigned int numeric_value
= 0;
6752 /* If we have already declared this section, we can use an
6753 abbreviated form to switch back to it -- unless this section is
6754 part of a COMDAT groups or with SHF_GNU_RETAIN, in which case GAS
6755 requires the full declaration every time. */
6756 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6757 && !(flags
& SECTION_RETAIN
)
6758 && (flags
& SECTION_DECLARED
))
6760 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6764 /* If we have a machine specific flag, then use the numeric value to pass
6766 if (targetm
.asm_out
.elf_flags_numeric (flags
, &numeric_value
))
6767 snprintf (f
, sizeof (flagchars
), "0x%08x", numeric_value
);
6770 if (!(flags
& SECTION_DEBUG
))
6772 #if HAVE_GAS_SECTION_EXCLUDE
6773 if (flags
& SECTION_EXCLUDE
)
6776 if (flags
& SECTION_WRITE
)
6778 if (flags
& SECTION_CODE
)
6780 if (flags
& SECTION_SMALL
)
6782 if (flags
& SECTION_MERGE
)
6784 if (flags
& SECTION_STRINGS
)
6786 if (flags
& SECTION_TLS
)
6787 *f
++ = TLS_SECTION_ASM_FLAG
;
6788 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6790 if (flags
& SECTION_RETAIN
)
6792 if (flags
& SECTION_LINK_ORDER
)
6794 #ifdef MACH_DEP_SECTION_ASM_FLAG
6795 if (flags
& SECTION_MACH_DEP
)
6796 *f
++ = MACH_DEP_SECTION_ASM_FLAG
;
6801 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6803 /* default_section_type_flags (above) knows which flags need special
6804 handling here, and sets NOTYPE when none of these apply so that the
6805 assembler's logic for default types can apply to user-chosen
6807 if (!(flags
& SECTION_NOTYPE
))
6812 if (flags
& SECTION_BSS
)
6818 /* On platforms that use "@" as the assembly comment character,
6820 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6822 fprintf (asm_out_file
, format
, type
);
6824 if (flags
& SECTION_ENTSIZE
)
6825 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6826 if (flags
& SECTION_LINK_ORDER
)
6828 tree id
= DECL_ASSEMBLER_NAME (decl
);
6829 ultimate_transparent_alias_target (&id
);
6830 const char *name
= IDENTIFIER_POINTER (id
);
6831 name
= targetm
.strip_name_encoding (name
);
6832 fprintf (asm_out_file
, ",%s", name
);
6834 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6836 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6837 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6839 fprintf (asm_out_file
, ",%s,comdat",
6840 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6844 putc ('\n', asm_out_file
);
6848 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6849 tree decl ATTRIBUTE_UNUSED
)
6851 char flagchars
[8], *f
= flagchars
;
6853 if (flags
& SECTION_WRITE
)
6855 if (flags
& SECTION_CODE
)
6859 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6863 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6866 default_coff_asm_named_section (name
, flags
, decl
);
6868 if (flags
& SECTION_LINKONCE
)
6870 /* Functions may have been compiled at various levels of
6871 optimization so we can't use `same_size' here.
6872 Instead, have the linker pick one. */
6873 fprintf (asm_out_file
, "\t.linkonce %s\n",
6874 (flags
& SECTION_CODE
? "discard" : "same_size"));
6878 /* The lame default section selector. */
6881 default_select_section (tree decl
, int reloc
,
6882 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6886 if (decl_readonly_section (decl
, reloc
))
6887 return readonly_data_section
;
6889 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6891 if (! ((flag_pic
&& reloc
)
6892 || !TREE_READONLY (decl
)
6893 || TREE_SIDE_EFFECTS (decl
)
6894 || !TREE_CONSTANT (decl
)))
6895 return readonly_data_section
;
6897 else if (TREE_CODE (decl
) == STRING_CST
)
6898 return readonly_data_section
;
6899 else if (! (flag_pic
&& reloc
))
6900 return readonly_data_section
;
6902 return data_section
;
6905 enum section_category
6906 categorize_decl_for_section (const_tree decl
, int reloc
)
6908 enum section_category ret
;
6910 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6912 else if (TREE_CODE (decl
) == STRING_CST
)
6914 if ((flag_sanitize
& SANITIZE_ADDRESS
)
6915 && asan_protect_global (CONST_CAST_TREE (decl
)))
6916 /* or !flag_merge_constants */
6917 return SECCAT_RODATA
;
6919 return SECCAT_RODATA_MERGE_STR
;
6921 else if (VAR_P (decl
))
6923 tree d
= CONST_CAST_TREE (decl
);
6924 if (bss_initializer_p (decl
))
6926 else if (! TREE_READONLY (decl
)
6927 || TREE_SIDE_EFFECTS (decl
)
6928 || (DECL_INITIAL (decl
)
6929 && ! TREE_CONSTANT (DECL_INITIAL (decl
))))
6931 /* Here the reloc_rw_mask is not testing whether the section should
6932 be read-only or not, but whether the dynamic link will have to
6933 do something. If so, we wish to segregate the data in order to
6934 minimize cache misses inside the dynamic linker. */
6935 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6936 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6940 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6941 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6942 else if (reloc
|| flag_merge_constants
< 2
6943 || ((flag_sanitize
& SANITIZE_ADDRESS
)
6944 /* PR 81697: for architectures that use section anchors we
6945 need to ignore DECL_RTL_SET_P (decl) for string constants
6946 inside this asan_protect_global call because otherwise
6947 we'll wrongly put them into SECCAT_RODATA_MERGE_CONST
6948 section, set DECL_RTL (decl) later on and add DECL to
6949 protected globals via successive asan_protect_global
6950 calls. In this scenario we'll end up with wrong
6951 alignment of these strings at runtime and possible ASan
6953 && asan_protect_global (d
, use_object_blocks_p ()
6954 && use_blocks_for_decl_p (d
))))
6955 /* C and C++ don't allow different variables to share the same
6956 location. -fmerge-all-constants allows even that (at the
6957 expense of not conforming). */
6958 ret
= SECCAT_RODATA
;
6959 else if (DECL_INITIAL (decl
)
6960 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6961 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6963 ret
= SECCAT_RODATA_MERGE_CONST
;
6965 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6967 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6968 || TREE_SIDE_EFFECTS (decl
)
6969 || ! TREE_CONSTANT (decl
))
6972 ret
= SECCAT_RODATA
;
6975 ret
= SECCAT_RODATA
;
6977 /* There are no read-only thread-local sections. */
6978 if (VAR_P (decl
) && DECL_THREAD_LOCAL_P (decl
))
6980 /* Note that this would be *just* SECCAT_BSS, except that there's
6981 no concept of a read-only thread-local-data section. */
6982 if (ret
== SECCAT_BSS
6983 || DECL_INITIAL (decl
) == NULL
6984 || (flag_zero_initialized_in_bss
6985 && initializer_zerop (DECL_INITIAL (decl
))))
6991 /* If the target uses small data sections, select it. */
6992 else if (targetm
.in_small_data_p (decl
))
6994 if (ret
== SECCAT_BSS
)
6996 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6997 ret
= SECCAT_SRODATA
;
7006 decl_readonly_section_1 (enum section_category category
)
7011 case SECCAT_RODATA_MERGE_STR
:
7012 case SECCAT_RODATA_MERGE_STR_INIT
:
7013 case SECCAT_RODATA_MERGE_CONST
:
7014 case SECCAT_SRODATA
:
7022 decl_readonly_section (const_tree decl
, int reloc
)
7024 return decl_readonly_section_1 (categorize_decl_for_section (decl
, reloc
));
7027 /* Select a section based on the above categorization. */
7030 default_elf_select_section (tree decl
, int reloc
,
7031 unsigned HOST_WIDE_INT align
)
7035 switch (categorize_decl_for_section (decl
, reloc
))
7038 /* We're not supposed to be called on FUNCTION_DECLs. */
7041 return readonly_data_section
;
7042 case SECCAT_RODATA_MERGE_STR
:
7043 return mergeable_string_section (decl
, align
, 0);
7044 case SECCAT_RODATA_MERGE_STR_INIT
:
7045 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
7046 case SECCAT_RODATA_MERGE_CONST
:
7047 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
7048 case SECCAT_SRODATA
:
7052 if (DECL_P (decl
) && DECL_PERSISTENT_P (decl
))
7054 sname
= ".persistent";
7057 return data_section
;
7058 case SECCAT_DATA_REL
:
7059 sname
= ".data.rel";
7061 case SECCAT_DATA_REL_LOCAL
:
7062 sname
= ".data.rel.local";
7064 case SECCAT_DATA_REL_RO
:
7065 sname
= ".data.rel.ro";
7067 case SECCAT_DATA_REL_RO_LOCAL
:
7068 sname
= ".data.rel.ro.local";
7077 if (DECL_P (decl
) && DECL_NOINIT_P (decl
))
7096 return get_named_section (decl
, sname
, reloc
);
7099 /* Construct a unique section name based on the decl name and the
7100 categorization performed above. */
7103 default_unique_section (tree decl
, int reloc
)
7105 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
7106 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
7107 const char *prefix
, *name
, *linkonce
;
7111 switch (categorize_decl_for_section (decl
, reloc
))
7114 prefix
= one_only
? ".t" : ".text";
7117 case SECCAT_RODATA_MERGE_STR
:
7118 case SECCAT_RODATA_MERGE_STR_INIT
:
7119 case SECCAT_RODATA_MERGE_CONST
:
7120 prefix
= one_only
? ".r" : ".rodata";
7122 case SECCAT_SRODATA
:
7123 prefix
= one_only
? ".s2" : ".sdata2";
7126 prefix
= one_only
? ".d" : ".data";
7127 if (DECL_P (decl
) && DECL_PERSISTENT_P (decl
))
7129 prefix
= one_only
? ".p" : ".persistent";
7133 case SECCAT_DATA_REL
:
7134 prefix
= one_only
? ".d.rel" : ".data.rel";
7136 case SECCAT_DATA_REL_LOCAL
:
7137 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
7139 case SECCAT_DATA_REL_RO
:
7140 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
7142 case SECCAT_DATA_REL_RO_LOCAL
:
7143 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
7146 prefix
= one_only
? ".s" : ".sdata";
7149 if (DECL_P (decl
) && DECL_NOINIT_P (decl
))
7151 prefix
= one_only
? ".n" : ".noinit";
7154 prefix
= one_only
? ".b" : ".bss";
7157 prefix
= one_only
? ".sb" : ".sbss";
7160 prefix
= one_only
? ".td" : ".tdata";
7163 prefix
= one_only
? ".tb" : ".tbss";
7169 id
= DECL_ASSEMBLER_NAME (decl
);
7170 ultimate_transparent_alias_target (&id
);
7171 name
= IDENTIFIER_POINTER (id
);
7172 name
= targetm
.strip_name_encoding (name
);
7174 /* If we're using one_only, then there needs to be a .gnu.linkonce
7175 prefix to the section name. */
7176 linkonce
= one_only
? ".gnu.linkonce" : "";
7178 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
7180 set_decl_section_name (decl
, string
);
7183 /* Subroutine of compute_reloc_for_rtx for leaf rtxes. */
7186 compute_reloc_for_rtx_1 (const_rtx x
)
7188 switch (GET_CODE (x
))
7191 return SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
7199 /* Like compute_reloc_for_constant, except for an RTX. The return value
7200 is a mask for which bit 1 indicates a global relocation, and bit 0
7201 indicates a local relocation. */
7204 compute_reloc_for_rtx (const_rtx x
)
7206 switch (GET_CODE (x
))
7210 return compute_reloc_for_rtx_1 (x
);
7215 subrtx_iterator::array_type array
;
7216 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
7217 reloc
|= compute_reloc_for_rtx_1 (*iter
);
7227 default_select_rtx_section (machine_mode mode ATTRIBUTE_UNUSED
,
7229 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
7231 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
7232 return data_section
;
7234 return readonly_data_section
;
7238 default_elf_select_rtx_section (machine_mode mode
, rtx x
,
7239 unsigned HOST_WIDE_INT align
)
7241 int reloc
= compute_reloc_for_rtx (x
);
7243 /* ??? Handle small data here somehow. */
7245 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
7248 return get_named_section (NULL
, ".data.rel.ro.local", 1);
7250 return get_named_section (NULL
, ".data.rel.ro", 3);
7253 return mergeable_constant_section (mode
, align
, 0);
7256 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
7259 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
7264 /* Careful not to prod global register variables. */
7267 symbol
= XEXP (rtl
, 0);
7268 if (GET_CODE (symbol
) != SYMBOL_REF
)
7271 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
7272 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7273 flags
|= SYMBOL_FLAG_FUNCTION
;
7274 if (targetm
.binds_local_p (decl
))
7275 flags
|= SYMBOL_FLAG_LOCAL
;
7276 if (VAR_P (decl
) && DECL_THREAD_LOCAL_P (decl
))
7277 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
7278 else if (targetm
.in_small_data_p (decl
))
7279 flags
|= SYMBOL_FLAG_SMALL
;
7280 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
7281 being PUBLIC, the thing *must* be defined in this translation unit.
7282 Prevent this buglet from being propagated into rtl code as well. */
7283 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
7284 flags
|= SYMBOL_FLAG_EXTERNAL
;
7286 SYMBOL_REF_FLAGS (symbol
) = flags
;
7289 /* By default, we do nothing for encode_section_info, so we need not
7290 do anything but discard the '*' marker. */
7293 default_strip_name_encoding (const char *str
)
7295 return str
+ (*str
== '*');
7298 #ifdef ASM_OUTPUT_DEF
7299 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
7300 anchor relative to ".", the current section position. */
7303 default_asm_output_anchor (rtx symbol
)
7307 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
7308 SYMBOL_REF_BLOCK_OFFSET (symbol
));
7309 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
7313 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
7316 default_use_anchors_for_symbol_p (const_rtx symbol
)
7319 section
*sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
7321 /* This function should only be called with non-zero SYMBOL_REF_BLOCK,
7322 furthermore get_block_for_section should not create object blocks
7323 for mergeable sections. */
7324 gcc_checking_assert (sect
&& !(sect
->common
.flags
& SECTION_MERGE
));
7326 /* Don't use anchors for small data sections. The small data register
7327 acts as an anchor for such sections. */
7328 if (sect
->common
.flags
& SECTION_SMALL
)
7331 decl
= SYMBOL_REF_DECL (symbol
);
7332 if (decl
&& DECL_P (decl
))
7334 /* Don't use section anchors for decls that might be defined or
7335 usurped by other modules. */
7336 if (TREE_PUBLIC (decl
) && !decl_binds_to_current_def_p (decl
))
7339 /* Don't use section anchors for decls that will be placed in a
7340 small data section. */
7341 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
7342 one above. The problem is that we only use SECTION_SMALL for
7343 sections that should be marked as small in the section directive. */
7344 if (targetm
.in_small_data_p (decl
))
7347 /* Don't use section anchors for decls that won't fit inside a single
7348 anchor range to reduce the amount of instructions required to refer
7349 to the entire declaration. */
7350 if (DECL_SIZE_UNIT (decl
) == NULL_TREE
7351 || !tree_fits_uhwi_p (DECL_SIZE_UNIT (decl
))
7352 || (tree_to_uhwi (DECL_SIZE_UNIT (decl
))
7353 >= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
))
7360 /* Return true when RESOLUTION indicate that symbol will be bound to the
7361 definition provided by current .o file. */
7364 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
7366 return (resolution
== LDPR_PREVAILING_DEF
7367 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
7368 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
7371 /* Return true when RESOLUTION indicate that symbol will be bound locally
7372 within current executable or DSO. */
7375 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
7377 return (resolution
== LDPR_PREVAILING_DEF
7378 || resolution
== LDPR_PREVAILING_DEF_IRONLY
7379 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
7380 || resolution
== LDPR_PREEMPTED_REG
7381 || resolution
== LDPR_PREEMPTED_IR
7382 || resolution
== LDPR_RESOLVED_IR
7383 || resolution
== LDPR_RESOLVED_EXEC
);
7386 /* COMMON_LOCAL_P is true means that the linker can guarantee that an
7387 uninitialized common symbol in the executable will still be defined
7388 (through COPY relocation) in the executable. */
7391 default_binds_local_p_3 (const_tree exp
, bool shlib
, bool weak_dominate
,
7392 bool extern_protected_data
, bool common_local_p
)
7394 /* A non-decl is an entry in the constant pool. */
7398 /* Weakrefs may not bind locally, even though the weakref itself is always
7399 static and therefore local. Similarly, the resolver for ifunc functions
7400 might resolve to a non-local function.
7401 FIXME: We can resolve the weakref case more curefuly by looking at the
7403 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
))
7404 || (TREE_CODE (exp
) == FUNCTION_DECL
7405 && cgraph_node::get (exp
)
7406 && cgraph_node::get (exp
)->ifunc_resolver
))
7409 /* Static variables are always local. */
7410 if (! TREE_PUBLIC (exp
))
7413 /* With resolution file in hand, take look into resolutions.
7414 We can't just return true for resolved_locally symbols,
7415 because dynamic linking might overwrite symbols
7416 in shared libraries. */
7417 bool resolved_locally
= false;
7419 bool uninited_common
= (DECL_COMMON (exp
)
7420 && (DECL_INITIAL (exp
) == NULL
7422 && DECL_INITIAL (exp
) == error_mark_node
)));
7424 /* A non-external variable is defined locally only if it isn't
7425 uninitialized COMMON variable or common_local_p is true. */
7426 bool defined_locally
= (!DECL_EXTERNAL (exp
)
7427 && (!uninited_common
|| common_local_p
));
7428 if (symtab_node
*node
= symtab_node::get (exp
))
7430 if (node
->in_other_partition
)
7431 defined_locally
= true;
7432 if (node
->can_be_discarded_p ())
7434 else if (resolution_to_local_definition_p (node
->resolution
))
7435 defined_locally
= resolved_locally
= true;
7436 else if (resolution_local_p (node
->resolution
))
7437 resolved_locally
= true;
7439 if (defined_locally
&& weak_dominate
&& !shlib
)
7440 resolved_locally
= true;
7442 /* Undefined weak symbols are never defined locally. */
7443 if (DECL_WEAK (exp
) && !defined_locally
)
7446 /* A symbol is local if the user has said explicitly that it will be,
7447 or if we have a definition for the symbol. We cannot infer visibility
7448 for undefined symbols. */
7449 if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
7450 && (TREE_CODE (exp
) == FUNCTION_DECL
7451 || !extern_protected_data
7452 || DECL_VISIBILITY (exp
) != VISIBILITY_PROTECTED
)
7453 && (DECL_VISIBILITY_SPECIFIED (exp
) || defined_locally
))
7456 /* If PIC, then assume that any global name can be overridden by
7457 symbols resolved from other modules. */
7461 /* Variables defined outside this object might not be local. */
7462 if (DECL_EXTERNAL (exp
) && !resolved_locally
)
7465 /* Non-dominant weak symbols are not defined locally. */
7466 if (DECL_WEAK (exp
) && !resolved_locally
)
7469 /* Uninitialized COMMON variable may be unified with symbols
7470 resolved from other modules. */
7471 if (uninited_common
&& !resolved_locally
)
7474 /* Otherwise we're left with initialized (or non-common) global data
7475 which is of necessity defined locally. */
7479 /* Assume ELF-ish defaults, since that's pretty much the most liberal
7480 wrt cross-module name binding. */
7483 default_binds_local_p (const_tree exp
)
7485 return default_binds_local_p_3 (exp
, flag_shlib
!= 0, true, false, false);
7488 /* Similar to default_binds_local_p, but common symbol may be local and
7489 extern protected data is non-local. */
7492 default_binds_local_p_2 (const_tree exp
)
7494 return default_binds_local_p_3 (exp
, flag_shlib
!= 0, true, true,
7499 default_binds_local_p_1 (const_tree exp
, int shlib
)
7501 return default_binds_local_p_3 (exp
, shlib
!= 0, false, false, false);
7504 /* Return true when references to DECL must bind to current definition in
7507 The condition is usually equivalent to whether the function binds to the
7508 current module (shared library or executable), that is to binds_local_p.
7509 We use this fact to avoid need for another target hook and implement
7510 the logic using binds_local_p and just special cases where
7511 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
7512 the weak definitions (that can be overwritten at linktime by other
7513 definition from different object file) and when resolution info is available
7514 we simply use the knowledge passed to us by linker plugin. */
7516 decl_binds_to_current_def_p (const_tree decl
)
7518 gcc_assert (DECL_P (decl
));
7519 if (!targetm
.binds_local_p (decl
))
7521 if (!TREE_PUBLIC (decl
))
7524 /* When resolution is available, just use it. */
7525 if (symtab_node
*node
= symtab_node::get (decl
))
7527 if (node
->resolution
!= LDPR_UNKNOWN
7528 && !node
->can_be_discarded_p ())
7529 return resolution_to_local_definition_p (node
->resolution
);
7532 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
7533 binds locally but still can be overwritten), DECL_COMMON (can be merged
7534 with a non-common definition somewhere in the same module) or
7536 This rely on fact that binds_local_p behave as decl_replaceable_p
7537 for all other declaration types. */
7538 if (DECL_WEAK (decl
))
7540 if (DECL_COMMON (decl
)
7541 && (DECL_INITIAL (decl
) == NULL
7542 || (!in_lto_p
&& DECL_INITIAL (decl
) == error_mark_node
)))
7544 if (DECL_EXTERNAL (decl
))
7549 /* A replaceable function or variable is one which may be replaced
7550 at link-time with an entirely different definition, provided that the
7551 replacement has the same type. For example, functions declared
7552 with __attribute__((weak)) on most systems are replaceable.
7554 COMDAT functions are not replaceable, since all definitions of the
7555 function must be equivalent. It is important that COMDAT functions
7556 not be treated as replaceable so that use of C++ template
7557 instantiations is not penalized. */
7560 decl_replaceable_p (tree decl
)
7562 gcc_assert (DECL_P (decl
));
7563 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
7565 if (!flag_semantic_interposition
7566 && !DECL_WEAK (decl
))
7568 return !decl_binds_to_current_def_p (decl
);
7571 /* Default function to output code that will globalize a label. A
7572 target must define GLOBAL_ASM_OP or provide its own function to
7573 globalize a label. */
7574 #ifdef GLOBAL_ASM_OP
7576 default_globalize_label (FILE * stream
, const char *name
)
7578 fputs (GLOBAL_ASM_OP
, stream
);
7579 assemble_name (stream
, name
);
7580 putc ('\n', stream
);
7582 #endif /* GLOBAL_ASM_OP */
7584 /* Default function to output code that will globalize a declaration. */
7586 default_globalize_decl_name (FILE * stream
, tree decl
)
7588 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
7589 targetm
.asm_out
.globalize_label (stream
, name
);
7592 /* Default function to output a label for unwind information. The
7593 default is to do nothing. A target that needs nonlocal labels for
7594 unwind information must provide its own function to do this. */
7596 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
7597 tree decl ATTRIBUTE_UNUSED
,
7598 int for_eh ATTRIBUTE_UNUSED
,
7599 int empty ATTRIBUTE_UNUSED
)
7603 /* Default function to output a label to divide up the exception table.
7604 The default is to do nothing. A target that needs/wants to divide
7605 up the table must provide it's own function to do this. */
7607 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
7611 /* This is how to output an internal numbered label where PREFIX is
7612 the class of label and LABELNO is the number within the class. */
7615 default_generate_internal_label (char *buf
, const char *prefix
,
7616 unsigned long labelno
)
7618 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
7621 /* This is how to output an internal numbered label where PREFIX is
7622 the class of label and LABELNO is the number within the class. */
7625 default_internal_label (FILE *stream
, const char *prefix
,
7626 unsigned long labelno
)
7628 char *const buf
= (char *) alloca (40 + strlen (prefix
));
7629 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
7630 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
7634 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
7637 default_asm_declare_constant_name (FILE *file
, const char *name
,
7638 const_tree exp ATTRIBUTE_UNUSED
,
7639 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
7641 assemble_label (file
, name
);
7644 /* This is the default behavior at the beginning of a file. It's
7645 controlled by two other target-hook toggles. */
7647 default_file_start (void)
7649 if (targetm
.asm_file_start_app_off
7650 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
7651 fputs (ASM_APP_OFF
, asm_out_file
);
7653 if (targetm
.asm_file_start_file_directive
)
7655 /* LTO produced units have no meaningful main_input_filename. */
7657 output_file_directive (asm_out_file
, "<artificial>");
7659 output_file_directive (asm_out_file
, main_input_filename
);
7663 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
7664 which emits a special section directive used to indicate whether or
7665 not this object file needs an executable stack. This is primarily
7666 a GNU extension to ELF but could be used on other targets. */
7668 int trampolines_created
;
7671 file_end_indicate_exec_stack (void)
7673 unsigned int flags
= SECTION_DEBUG
;
7674 if (trampolines_created
)
7675 flags
|= SECTION_CODE
;
7677 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
7680 /* Emit a special section directive to indicate that this object file
7681 was compiled with -fsplit-stack. This is used to let the linker
7682 detect calls between split-stack code and non-split-stack code, so
7683 that it can modify the split-stack code to allocate a sufficiently
7684 large stack. We emit another special section if there are any
7685 functions in this file which have the no_split_stack attribute, to
7686 prevent the linker from warning about being unable to convert the
7687 functions if they call non-split-stack code. */
7690 file_end_indicate_split_stack (void)
7692 if (flag_split_stack
)
7694 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
7696 if (saw_no_split_stack
)
7697 switch_to_section (get_section (".note.GNU-no-split-stack",
7698 SECTION_DEBUG
, NULL
));
7702 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
7703 a get_unnamed_section callback. */
7706 output_section_asm_op (const void *directive
)
7708 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
7711 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
7712 the current section is NEW_SECTION. */
7715 switch_to_section (section
*new_section
)
7717 if (in_section
== new_section
)
7720 if (new_section
->common
.flags
& SECTION_FORGET
)
7723 in_section
= new_section
;
7725 switch (SECTION_STYLE (new_section
))
7728 targetm
.asm_out
.named_section (new_section
->named
.name
,
7729 new_section
->named
.common
.flags
,
7730 new_section
->named
.decl
);
7733 case SECTION_UNNAMED
:
7734 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
7737 case SECTION_NOSWITCH
:
7742 new_section
->common
.flags
|= SECTION_DECLARED
;
7745 /* If block symbol SYMBOL has not yet been assigned an offset, place
7746 it at the end of its block. */
7749 place_block_symbol (rtx symbol
)
7751 unsigned HOST_WIDE_INT size
, mask
, offset
;
7752 class constant_descriptor_rtx
*desc
;
7753 unsigned int alignment
;
7754 struct object_block
*block
;
7757 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
7758 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
7761 /* Work out the symbol's size and alignment. */
7762 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7764 desc
= SYMBOL_REF_CONSTANT (symbol
);
7765 alignment
= desc
->align
;
7766 size
= GET_MODE_SIZE (desc
->mode
);
7768 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7770 decl
= SYMBOL_REF_DECL (symbol
);
7771 gcc_checking_assert (DECL_IN_CONSTANT_POOL (decl
));
7772 alignment
= DECL_ALIGN (decl
);
7773 size
= get_constant_size (DECL_INITIAL (decl
));
7774 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7775 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7776 && asan_protect_global (DECL_INITIAL (decl
)))
7778 size
+= asan_red_zone_size (size
);
7779 alignment
= MAX (alignment
,
7780 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
7785 struct symtab_node
*snode
;
7786 decl
= SYMBOL_REF_DECL (symbol
);
7788 snode
= symtab_node::get (decl
);
7791 rtx target
= DECL_RTL (snode
->ultimate_alias_target ()->decl
);
7793 gcc_assert (MEM_P (target
)
7794 && GET_CODE (XEXP (target
, 0)) == SYMBOL_REF
7795 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (target
, 0)));
7796 target
= XEXP (target
, 0);
7797 place_block_symbol (target
);
7798 SYMBOL_REF_BLOCK_OFFSET (symbol
) = SYMBOL_REF_BLOCK_OFFSET (target
);
7801 alignment
= get_variable_align (decl
);
7802 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7803 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7804 && asan_protect_global (decl
))
7806 size
+= asan_red_zone_size (size
);
7807 alignment
= MAX (alignment
,
7808 ASAN_RED_ZONE_SIZE
* BITS_PER_UNIT
);
7812 /* Calculate the object's offset from the start of the block. */
7813 block
= SYMBOL_REF_BLOCK (symbol
);
7814 mask
= alignment
/ BITS_PER_UNIT
- 1;
7815 offset
= (block
->size
+ mask
) & ~mask
;
7816 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
7818 /* Record the block's new alignment and size. */
7819 block
->alignment
= MAX (block
->alignment
, alignment
);
7820 block
->size
= offset
+ size
;
7822 vec_safe_push (block
->objects
, symbol
);
7825 /* Return the anchor that should be used to address byte offset OFFSET
7826 from the first object in BLOCK. MODEL is the TLS model used
7830 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7831 enum tls_model model
)
7834 unsigned int begin
, middle
, end
;
7835 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7838 /* Work out the anchor's offset. Use an offset of 0 for the first
7839 anchor so that we don't pessimize the case where we take the address
7840 of a variable at the beginning of the block. This is particularly
7841 useful when a block has only one variable assigned to it.
7843 We try to place anchors RANGE bytes apart, so there can then be
7844 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7845 a ptr_mode offset. With some target settings, the lowest such
7846 anchor might be out of range for the lowest ptr_mode offset;
7847 likewise the highest anchor for the highest offset. Use anchors
7848 at the extreme ends of the ptr_mode range in such cases.
7850 All arithmetic uses unsigned integers in order to avoid
7852 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7853 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7854 range
= max_offset
- min_offset
+ 1;
7859 bias
= HOST_WIDE_INT_1U
<< (GET_MODE_BITSIZE (ptr_mode
) - 1);
7862 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7863 delta
-= delta
% range
;
7866 offset
= (HOST_WIDE_INT
) (-delta
);
7870 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7871 delta
-= delta
% range
;
7872 if (delta
> bias
- 1)
7874 offset
= (HOST_WIDE_INT
) delta
;
7878 /* Do a binary search to see if there's already an anchor we can use.
7879 Set BEGIN to the new anchor's index if not. */
7881 end
= vec_safe_length (block
->anchors
);
7882 while (begin
!= end
)
7884 middle
= (end
+ begin
) / 2;
7885 anchor
= (*block
->anchors
)[middle
];
7886 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7888 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7890 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7892 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7898 /* Create a new anchor with a unique label. */
7899 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7900 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7901 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7902 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7904 /* Insert it at index BEGIN. */
7905 vec_safe_insert (block
->anchors
, begin
, anchor
);
7909 /* Output the objects in BLOCK. */
7912 output_object_block (struct object_block
*block
)
7914 class constant_descriptor_rtx
*desc
;
7916 HOST_WIDE_INT offset
;
7920 if (!block
->objects
)
7923 /* Switch to the section and make sure that the first byte is
7924 suitably aligned. */
7925 /* Special case VTV comdat sections similar to assemble_variable. */
7926 if (SECTION_STYLE (block
->sect
) == SECTION_NAMED
7927 && block
->sect
->named
.name
7928 && (strcmp (block
->sect
->named
.name
, ".vtable_map_vars") == 0))
7929 handle_vtv_comdat_section (block
->sect
, block
->sect
->named
.decl
);
7931 switch_to_section (block
->sect
);
7933 gcc_checking_assert (!(block
->sect
->common
.flags
& SECTION_MERGE
));
7934 assemble_align (block
->alignment
);
7936 /* Define the values of all anchors relative to the current section
7938 FOR_EACH_VEC_SAFE_ELT (block
->anchors
, i
, symbol
)
7939 targetm
.asm_out
.output_anchor (symbol
);
7941 /* Output the objects themselves. */
7943 FOR_EACH_VEC_ELT (*block
->objects
, i
, symbol
)
7945 /* Move to the object's offset, padding with zeros if necessary. */
7946 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7947 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7948 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7950 desc
= SYMBOL_REF_CONSTANT (symbol
);
7951 /* Pass 1 for align as we have already laid out everything in the block.
7952 So aligning shouldn't be necessary. */
7953 output_constant_pool_1 (desc
, 1);
7954 offset
+= GET_MODE_SIZE (desc
->mode
);
7956 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7959 decl
= SYMBOL_REF_DECL (symbol
);
7960 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
7961 DECL_ALIGN (decl
), false);
7963 size
= get_constant_size (DECL_INITIAL (decl
));
7965 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7966 && TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
7967 && asan_protect_global (DECL_INITIAL (decl
)))
7969 size
= asan_red_zone_size (size
);
7970 assemble_zeros (size
);
7977 decl
= SYMBOL_REF_DECL (symbol
);
7978 assemble_variable_contents (decl
, XSTR (symbol
, 0), false, false);
7979 size
= tree_to_uhwi (DECL_SIZE_UNIT (decl
));
7981 if ((flag_sanitize
& SANITIZE_ADDRESS
)
7982 && asan_protect_global (decl
))
7984 size
= asan_red_zone_size (size
);
7985 assemble_zeros (size
);
7992 /* A callback for qsort to compare object_blocks. */
7995 output_object_block_compare (const void *x
, const void *y
)
7997 object_block
*p1
= *(object_block
* const*)x
;
7998 object_block
*p2
= *(object_block
* const*)y
;
8000 if (p1
->sect
->common
.flags
& SECTION_NAMED
8001 && !(p2
->sect
->common
.flags
& SECTION_NAMED
))
8004 if (!(p1
->sect
->common
.flags
& SECTION_NAMED
)
8005 && p2
->sect
->common
.flags
& SECTION_NAMED
)
8008 if (p1
->sect
->common
.flags
& SECTION_NAMED
8009 && p2
->sect
->common
.flags
& SECTION_NAMED
)
8010 return strcmp (p1
->sect
->named
.name
, p2
->sect
->named
.name
);
8012 unsigned f1
= p1
->sect
->common
.flags
;
8013 unsigned f2
= p2
->sect
->common
.flags
;
8016 return f1
< f2
? -1 : 1;
8019 /* Output the definitions of all object_blocks. */
8022 output_object_blocks (void)
8024 vec
<object_block
*, va_heap
> v
;
8025 v
.create (object_block_htab
->elements ());
8027 hash_table
<object_block_hasher
>::iterator hi
;
8029 FOR_EACH_HASH_TABLE_ELEMENT (*object_block_htab
, obj
, object_block
*, hi
)
8032 /* Sort them in order to output them in a deterministic manner,
8033 otherwise we may get .rodata sections in different orders with
8035 v
.qsort (output_object_block_compare
);
8037 FOR_EACH_VEC_ELT (v
, i
, obj
)
8038 output_object_block (obj
);
8043 /* This function provides a possible implementation of the
8044 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
8045 by -frecord-gcc-switches it creates a new mergeable, string section in the
8046 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
8047 contains the switches in ASCII format.
8049 FIXME: This code does not correctly handle double quote characters
8050 that appear inside strings, (it strips them rather than preserving them).
8051 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
8052 characters - instead it treats them as sub-string separators. Since
8053 we want to emit NUL strings terminators into the object file we have to use
8057 elf_record_gcc_switches (print_switch_type type
, const char * name
)
8061 case SWITCH_TYPE_PASSED
:
8062 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
8063 ASM_OUTPUT_SKIP (asm_out_file
, HOST_WIDE_INT_1U
);
8066 case SWITCH_TYPE_DESCRIPTIVE
:
8069 /* Distinguish between invocations where name is NULL. */
8070 static bool started
= false;
8076 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
8080 | (SECTION_ENTSIZE
& 1),
8082 switch_to_section (sec
);
8091 /* The return value is currently ignored by the caller, but must be 0.
8092 For -fverbose-asm the return value would be the number of characters
8093 emitted into the assembler file. */
8097 /* Emit text to declare externally defined symbols. It is needed to
8098 properly support non-default visibility. */
8100 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
8102 const char *name ATTRIBUTE_UNUSED
)
8104 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
8105 set in order to avoid putting out names that are never really
8106 used. Always output visibility specified in the source. */
8107 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
8108 && (DECL_VISIBILITY_SPECIFIED (decl
)
8109 || targetm
.binds_local_p (decl
)))
8110 maybe_assemble_visibility (decl
);
8113 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
8116 default_asm_output_source_filename (FILE *file
, const char *name
)
8118 #ifdef ASM_OUTPUT_SOURCE_FILENAME
8119 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
8121 fprintf (file
, "\t.file\t");
8122 output_quoted_string (file
, name
);
8127 /* Output a file name in the form wanted by System V. */
8130 output_file_directive (FILE *asm_file
, const char *input_name
)
8135 if (input_name
== NULL
)
8136 input_name
= "<stdin>";
8138 input_name
= remap_debug_filename (input_name
);
8140 len
= strlen (input_name
);
8141 na
= input_name
+ len
;
8143 /* NA gets INPUT_NAME sans directory names. */
8144 while (na
> input_name
)
8146 if (IS_DIR_SEPARATOR (na
[-1]))
8151 targetm
.asm_out
.output_source_filename (asm_file
, na
);
8154 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
8157 make_debug_expr_from_rtl (const_rtx exp
)
8159 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
8160 machine_mode mode
= GET_MODE (exp
);
8163 DECL_ARTIFICIAL (ddecl
) = 1;
8164 if (REG_P (exp
) && REG_EXPR (exp
))
8165 type
= TREE_TYPE (REG_EXPR (exp
));
8166 else if (MEM_P (exp
) && MEM_EXPR (exp
))
8167 type
= TREE_TYPE (MEM_EXPR (exp
));
8170 if (type
&& TYPE_MODE (type
) == mode
)
8171 TREE_TYPE (ddecl
) = type
;
8173 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
8174 SET_DECL_MODE (ddecl
, mode
);
8175 dval
= gen_rtx_DEBUG_EXPR (mode
);
8176 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
8177 SET_DECL_RTL (ddecl
, dval
);
8181 #ifdef ELF_ASCII_ESCAPES
8182 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
8185 default_elf_asm_output_limited_string (FILE *f
, const char *s
)
8190 fputs (STRING_ASM_OP
, f
);
8195 escape
= ELF_ASCII_ESCAPES
[c
];
8203 putc ('0'+((c
>>6)&7), f
);
8204 putc ('0'+((c
>>3)&7), f
);
8205 putc ('0'+(c
&7), f
);
8218 /* Default ASM_OUTPUT_ASCII for ELF targets. */
8221 default_elf_asm_output_ascii (FILE *f
, const char *s
, unsigned int len
)
8223 const char *limit
= s
+ len
;
8224 const char *last_null
= NULL
;
8225 unsigned bytes_in_chunk
= 0;
8229 for (; s
< limit
; s
++)
8233 if (bytes_in_chunk
>= 60)
8242 for (p
= s
; p
< limit
&& *p
!= '\0'; p
++)
8249 if (p
< limit
&& (p
- s
) <= (long) ELF_STRING_LIMIT
)
8251 if (bytes_in_chunk
> 0)
8258 default_elf_asm_output_limited_string (f
, s
);
8263 if (bytes_in_chunk
== 0)
8264 fputs (ASCII_DATA_ASM_OP
"\"", f
);
8267 escape
= ELF_ASCII_ESCAPES
[c
];
8276 putc ('0'+((c
>>6)&7), f
);
8277 putc ('0'+((c
>>3)&7), f
);
8278 putc ('0'+(c
&7), f
);
8279 bytes_in_chunk
+= 4;
8284 bytes_in_chunk
+= 2;
8291 if (bytes_in_chunk
> 0)
8299 static GTY(()) section
*elf_init_array_section
;
8300 static GTY(()) section
*elf_fini_array_section
;
8303 get_elf_initfini_array_priority_section (int priority
,
8307 if (priority
!= DEFAULT_INIT_PRIORITY
)
8310 sprintf (buf
, "%s.%.5u",
8311 constructor_p
? ".init_array" : ".fini_array",
8313 sec
= get_section (buf
, SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
8319 if (elf_init_array_section
== NULL
)
8320 elf_init_array_section
8321 = get_section (".init_array",
8322 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
8323 sec
= elf_init_array_section
;
8327 if (elf_fini_array_section
== NULL
)
8328 elf_fini_array_section
8329 = get_section (".fini_array",
8330 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
8331 sec
= elf_fini_array_section
;
8337 /* Use .init_array section for constructors. */
8340 default_elf_init_array_asm_out_constructor (rtx symbol
, int priority
)
8342 section
*sec
= get_elf_initfini_array_priority_section (priority
,
8344 assemble_addr_to_section (symbol
, sec
);
8347 /* Use .fini_array section for destructors. */
8350 default_elf_fini_array_asm_out_destructor (rtx symbol
, int priority
)
8352 section
*sec
= get_elf_initfini_array_priority_section (priority
,
8354 assemble_addr_to_section (symbol
, sec
);
8357 /* Default TARGET_ASM_OUTPUT_IDENT hook.
8359 This is a bit of a cheat. The real default is a no-op, but this
8360 hook is the default for all targets with a .ident directive. */
8363 default_asm_output_ident_directive (const char *ident_str
)
8365 const char *ident_asm_op
= "\t.ident\t";
8367 /* If we are still in the front end, do not write out the string
8368 to asm_out_file. Instead, add a fake top-level asm statement.
8369 This allows the front ends to use this hook without actually
8370 writing to asm_out_file, to handle #ident or Pragma Ident. */
8371 if (symtab
->state
== PARSING
)
8373 char *buf
= ACONCAT ((ident_asm_op
, "\"", ident_str
, "\"\n", NULL
));
8374 symtab
->finalize_toplevel_asm (build_string (strlen (buf
), buf
));
8377 fprintf (asm_out_file
, "%s\"%s\"\n", ident_asm_op
, ident_str
);
8381 /* This function ensures that vtable_map variables are not only
8382 in the comdat section, but that each variable has its own unique
8383 comdat name. Without this the variables end up in the same section
8384 with a single comdat name.
8386 FIXME: resolve_unique_section needs to deal better with
8387 decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
8388 that is fixed, this if-else statement can be replaced with
8389 a single call to "switch_to_section (sect)". */
8392 handle_vtv_comdat_section (section
*sect
, const_tree decl ATTRIBUTE_UNUSED
)
8394 #if defined (OBJECT_FORMAT_ELF)
8395 targetm
.asm_out
.named_section (sect
->named
.name
,
8396 sect
->named
.common
.flags
8401 /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
8402 Therefore the following check is used.
8403 In case a the target is PE or COFF a comdat group section
8404 is created, e.g. .vtable_map_vars$foo. The linker places
8405 everything in .vtable_map_vars at the end.
8407 A fix could be made in
8408 gcc/config/i386/winnt.c: i386_pe_unique_section. */
8413 if (TREE_CODE (DECL_NAME (decl
)) == IDENTIFIER_NODE
)
8414 name
= ACONCAT ((sect
->named
.name
, "$",
8415 IDENTIFIER_POINTER (DECL_NAME (decl
)), NULL
));
8417 name
= ACONCAT ((sect
->named
.name
, "$",
8418 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl
))),
8421 targetm
.asm_out
.named_section (name
,
8422 sect
->named
.common
.flags
8428 switch_to_section (sect
);
8432 #include "gt-varasm.h"