Update gcc-50 to SVN version 222321 (gcc-5-branch)
[dragonfly.git] / contrib / gcc-5.0 / gcc / varasm.c
CommitLineData
dda118e3
JM
1/* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20
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.
24
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
27
28#include "config.h"
29#include "system.h"
30#include "coretypes.h"
31#include "tm.h"
32#include "rtl.h"
33#include "hash-set.h"
34#include "machmode.h"
35#include "vec.h"
36#include "double-int.h"
37#include "input.h"
38#include "alias.h"
39#include "symtab.h"
40#include "wide-int.h"
41#include "inchash.h"
42#include "tree.h"
43#include "fold-const.h"
44#include "stor-layout.h"
45#include "stringpool.h"
46#include "varasm.h"
47#include "flags.h"
48#include "hard-reg-set.h"
49#include "function.h"
50#include "hashtab.h"
51#include "statistics.h"
52#include "real.h"
53#include "fixed-value.h"
54#include "insn-config.h"
55#include "expmed.h"
56#include "dojump.h"
57#include "explow.h"
58#include "calls.h"
59#include "emit-rtl.h"
60#include "stmt.h"
61#include "expr.h"
62#include "regs.h"
63#include "output.h"
64#include "diagnostic-core.h"
65#include "ggc.h"
66#include "langhooks.h"
67#include "tm_p.h"
68#include "debug.h"
69#include "target.h"
70#include "common/common-target.h"
71#include "targhooks.h"
72#include "predict.h"
73#include "dominance.h"
74#include "cfg.h"
75#include "basic-block.h"
76#include "hash-map.h"
77#include "is-a.h"
78#include "plugin-api.h"
79#include "ipa-ref.h"
80#include "cgraph.h"
81#include "asan.h"
82#include "rtl-iter.h"
83#include "tree-chkp.h"
84
85#ifdef XCOFF_DEBUGGING_INFO
86#include "xcoffout.h" /* Needed for external data
87 declarations for e.g. AIX 4.x. */
88#endif
89
90/* The (assembler) name of the first globally-visible object output. */
91extern GTY(()) const char *first_global_object_name;
92extern GTY(()) const char *weak_global_object_name;
93
94const char *first_global_object_name;
95const char *weak_global_object_name;
96
97struct addr_const;
98struct constant_descriptor_rtx;
99struct rtx_constant_pool;
100
101#define n_deferred_constants (crtl->varasm.deferred_constants)
102
103/* Number for making the label on the next
104 constant that is stored in memory. */
105
106static GTY(()) int const_labelno;
107
108/* Carry information from ASM_DECLARE_OBJECT_NAME
109 to ASM_FINISH_DECLARE_OBJECT. */
110
111int size_directive_output;
112
113/* The last decl for which assemble_variable was called,
114 if it did ASM_DECLARE_OBJECT_NAME.
115 If the last call to assemble_variable didn't do that,
116 this holds 0. */
117
118tree last_assemble_variable_decl;
119
120/* The following global variable indicates if the first basic block
121 in a function belongs to the cold partition or not. */
122
123bool first_function_block_is_cold;
124
125/* Whether we saw any functions with no_split_stack. */
126
127static bool saw_no_split_stack;
128
129static const char *strip_reg_name (const char *);
130static int contains_pointers_p (tree);
131#ifdef ASM_OUTPUT_EXTERNAL
132static bool incorporeal_function_p (tree);
133#endif
134static void decode_addr_const (tree, struct addr_const *);
135static hashval_t const_hash_1 (const tree);
136static int compare_constant (const tree, const tree);
137static void output_constant_def_contents (rtx);
138static void output_addressed_constants (tree);
139static unsigned HOST_WIDE_INT output_constant (tree, unsigned HOST_WIDE_INT,
140 unsigned int);
141static void globalize_decl (tree);
142static bool decl_readonly_section_1 (enum section_category);
143#ifdef BSS_SECTION_ASM_OP
144#ifdef ASM_OUTPUT_ALIGNED_BSS
145static void asm_output_aligned_bss (FILE *, tree, const char *,
146 unsigned HOST_WIDE_INT, int)
147 ATTRIBUTE_UNUSED;
148#endif
149#endif /* BSS_SECTION_ASM_OP */
150static void mark_weak (tree);
151static void output_constant_pool (const char *, tree);
152\f
153/* Well-known sections, each one associated with some sort of *_ASM_OP. */
154section *text_section;
155section *data_section;
156section *readonly_data_section;
157section *sdata_section;
158section *ctors_section;
159section *dtors_section;
160section *bss_section;
161section *sbss_section;
162
163/* Various forms of common section. All are guaranteed to be nonnull. */
164section *tls_comm_section;
165section *comm_section;
166section *lcomm_section;
167
168/* A SECTION_NOSWITCH section used for declaring global BSS variables.
169 May be null. */
170section *bss_noswitch_section;
171
172/* The section that holds the main exception table, when known. The section
173 is set either by the target's init_sections hook or by the first call to
174 switch_to_exception_section. */
175section *exception_section;
176
177/* The section that holds the DWARF2 frame unwind information, when known.
178 The section is set either by the target's init_sections hook or by the
179 first call to switch_to_eh_frame_section. */
180section *eh_frame_section;
181
182/* asm_out_file's current section. This is NULL if no section has yet
183 been selected or if we lose track of what the current section is. */
184section *in_section;
185
186/* True if code for the current function is currently being directed
187 at the cold section. */
188bool in_cold_section_p;
189
190/* A linked list of all the unnamed sections. */
191static GTY(()) section *unnamed_sections;
192
193/* Return a nonzero value if DECL has a section attribute. */
194#define IN_NAMED_SECTION(DECL) \
195 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
196 && DECL_SECTION_NAME (DECL) != NULL)
197
198struct section_hasher : ggc_hasher<section *>
199{
200 typedef const char *compare_type;
201
202 static hashval_t hash (section *);
203 static bool equal (section *, const char *);
204};
205
206/* Hash table of named sections. */
207static GTY(()) hash_table<section_hasher> *section_htab;
208
209struct object_block_hasher : ggc_hasher<object_block *>
210{
211 typedef const section *compare_type;
212
213 static hashval_t hash (object_block *);
214 static bool equal (object_block *, const section *);
215};
216
217/* A table of object_blocks, indexed by section. */
218static GTY(()) hash_table<object_block_hasher> *object_block_htab;
219
220/* The next number to use for internal anchor labels. */
221static GTY(()) int anchor_labelno;
222
223/* A pool of constants that can be shared between functions. */
224static GTY(()) struct rtx_constant_pool *shared_constant_pool;
225
226/* Helper routines for maintaining section_htab. */
227
228bool
229section_hasher::equal (section *old, const char *new_name)
230{
231 return strcmp (old->named.name, new_name) == 0;
232}
233
234hashval_t
235section_hasher::hash (section *old)
236{
237 return htab_hash_string (old->named.name);
238}
239
240/* Return a hash value for section SECT. */
241
242static hashval_t
243hash_section (section *sect)
244{
245 if (sect->common.flags & SECTION_NAMED)
246 return htab_hash_string (sect->named.name);
247 return sect->common.flags;
248}
249
250/* Helper routines for maintaining object_block_htab. */
251
252inline bool
253object_block_hasher::equal (object_block *old, const section *new_section)
254{
255 return old->sect == new_section;
256}
257
258hashval_t
259object_block_hasher::hash (object_block *old)
260{
261 return hash_section (old->sect);
262}
263
264/* Return a new unnamed section with the given fields. */
265
266section *
267get_unnamed_section (unsigned int flags, void (*callback) (const void *),
268 const void *data)
269{
270 section *sect;
271
272 sect = ggc_alloc<section> ();
273 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
274 sect->unnamed.callback = callback;
275 sect->unnamed.data = data;
276 sect->unnamed.next = unnamed_sections;
277
278 unnamed_sections = sect;
279 return sect;
280}
281
282/* Return a SECTION_NOSWITCH section with the given fields. */
283
284static section *
285get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
286{
287 section *sect;
288
289 sect = ggc_alloc<section> ();
290 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
291 sect->noswitch.callback = callback;
292
293 return sect;
294}
295
296/* Return the named section structure associated with NAME. Create
297 a new section with the given fields if no such structure exists. */
298
299section *
300get_section (const char *name, unsigned int flags, tree decl)
301{
302 section *sect, **slot;
303
304 slot = section_htab->find_slot_with_hash (name, htab_hash_string (name),
305 INSERT);
306 flags |= SECTION_NAMED;
307 if (*slot == NULL)
308 {
309 sect = ggc_alloc<section> ();
310 sect->named.common.flags = flags;
311 sect->named.name = ggc_strdup (name);
312 sect->named.decl = decl;
313 *slot = sect;
314 }
315 else
316 {
317 sect = *slot;
318 if ((sect->common.flags & ~SECTION_DECLARED) != flags
319 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
320 {
321 /* It is fine if one of the section flags is
322 SECTION_WRITE | SECTION_RELRO and the other has none of these
323 flags (i.e. read-only) in named sections and either the
324 section hasn't been declared yet or has been declared as writable.
325 In that case just make sure the resulting flags are
326 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
327 relocations. */
328 if (((sect->common.flags ^ flags) & (SECTION_WRITE | SECTION_RELRO))
329 == (SECTION_WRITE | SECTION_RELRO)
330 && (sect->common.flags
331 & ~(SECTION_DECLARED | SECTION_WRITE | SECTION_RELRO))
332 == (flags & ~(SECTION_WRITE | SECTION_RELRO))
333 && ((sect->common.flags & SECTION_DECLARED) == 0
334 || (sect->common.flags & SECTION_WRITE)))
335 {
336 sect->common.flags |= (SECTION_WRITE | SECTION_RELRO);
337 return sect;
338 }
339 /* Sanity check user variables for flag changes. */
340 if (sect->named.decl != NULL
341 && DECL_P (sect->named.decl)
342 && decl != sect->named.decl)
343 {
344 if (decl != NULL && DECL_P (decl))
345 error ("%+D causes a section type conflict with %D",
346 decl, sect->named.decl);
347 else
348 error ("section type conflict with %D", sect->named.decl);
349 inform (DECL_SOURCE_LOCATION (sect->named.decl),
350 "%qD was declared here", sect->named.decl);
351 }
352 else if (decl != NULL && DECL_P (decl))
353 error ("%+D causes a section type conflict", decl);
354 else
355 error ("section type conflict");
356 /* Make sure we don't error about one section multiple times. */
357 sect->common.flags |= SECTION_OVERRIDE;
358 }
359 }
360 return sect;
361}
362
363/* Return true if the current compilation mode benefits from having
364 objects grouped into blocks. */
365
366static bool
367use_object_blocks_p (void)
368{
369 return flag_section_anchors;
370}
371
372/* Return the object_block structure for section SECT. Create a new
373 structure if we haven't created one already. Return null if SECT
374 itself is null. */
375
376static struct object_block *
377get_block_for_section (section *sect)
378{
379 struct object_block *block;
380
381 if (sect == NULL)
382 return NULL;
383
384 object_block **slot
385 = object_block_htab->find_slot_with_hash (sect, hash_section (sect),
386 INSERT);
387 block = *slot;
388 if (block == NULL)
389 {
390 block = ggc_cleared_alloc<object_block> ();
391 block->sect = sect;
392 *slot = block;
393 }
394 return block;
395}
396
397/* Create a symbol with label LABEL and place it at byte offset
398 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
399 is not yet known. LABEL must be a garbage-collected string. */
400
401static rtx
402create_block_symbol (const char *label, struct object_block *block,
403 HOST_WIDE_INT offset)
404{
405 rtx symbol;
406 unsigned int size;
407
408 /* Create the extended SYMBOL_REF. */
409 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
410 symbol = (rtx) ggc_internal_alloc (size);
411
412 /* Initialize the normal SYMBOL_REF fields. */
413 memset (symbol, 0, size);
414 PUT_CODE (symbol, SYMBOL_REF);
415 PUT_MODE (symbol, Pmode);
416 XSTR (symbol, 0) = label;
417 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
418
419 /* Initialize the block_symbol stuff. */
420 SYMBOL_REF_BLOCK (symbol) = block;
421 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
422
423 return symbol;
424}
425
426/* Return a section with a particular name and with whatever SECTION_*
427 flags section_type_flags deems appropriate. The name of the section
428 is taken from NAME if nonnull, otherwise it is taken from DECL's
429 DECL_SECTION_NAME. DECL is the decl associated with the section
430 (see the section comment for details) and RELOC is as for
431 section_type_flags. */
432
433section *
434get_named_section (tree decl, const char *name, int reloc)
435{
436 unsigned int flags;
437
438 if (name == NULL)
439 {
440 gcc_assert (decl && DECL_P (decl) && DECL_SECTION_NAME (decl));
441 name = DECL_SECTION_NAME (decl);
442 }
443
444 flags = targetm.section_type_flags (decl, name, reloc);
445 return get_section (name, flags, decl);
446}
447
448/* Worker for resolve_unique_section. */
449
450static bool
451set_implicit_section (struct symtab_node *n, void *data ATTRIBUTE_UNUSED)
452{
453 n->implicit_section = true;
454 return false;
455}
456
457/* If required, set DECL_SECTION_NAME to a unique name. */
458
459void
460resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
461 int flag_function_or_data_sections)
462{
463 if (DECL_SECTION_NAME (decl) == NULL
464 && targetm_common.have_named_sections
465 && (flag_function_or_data_sections
466 || DECL_COMDAT_GROUP (decl)))
467 {
468 targetm.asm_out.unique_section (decl, reloc);
469 if (DECL_SECTION_NAME (decl))
470 symtab_node::get (decl)->call_for_symbol_and_aliases
471 (set_implicit_section, NULL, true);
472 }
473}
474
475#ifdef BSS_SECTION_ASM_OP
476
477#ifdef ASM_OUTPUT_ALIGNED_BSS
478
479/* Utility function for targets to use in implementing
480 ASM_OUTPUT_ALIGNED_BSS.
481 ??? It is believed that this function will work in most cases so such
482 support is localized here. */
483
484static void
485asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
486 const char *name, unsigned HOST_WIDE_INT size,
487 int align)
488{
489 switch_to_section (bss_section);
490 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
491#ifdef ASM_DECLARE_OBJECT_NAME
492 last_assemble_variable_decl = decl;
493 ASM_DECLARE_OBJECT_NAME (file, name, decl);
494#else
495 /* Standard thing is just output label for the object. */
496 ASM_OUTPUT_LABEL (file, name);
497#endif /* ASM_DECLARE_OBJECT_NAME */
498 ASM_OUTPUT_SKIP (file, size ? size : 1);
499}
500
501#endif
502
503#endif /* BSS_SECTION_ASM_OP */
504
505#ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
506/* Return the hot section for function DECL. Return text_section for
507 null DECLs. */
508
509static section *
510hot_function_section (tree decl)
511{
512 if (decl != NULL_TREE
513 && DECL_SECTION_NAME (decl) != NULL
514 && targetm_common.have_named_sections)
515 return get_named_section (decl, NULL, 0);
516 else
517 return text_section;
518}
519#endif
520
521/* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
522 is NULL.
523
524 When DECL_SECTION_NAME is non-NULL and it is implicit section and
525 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
526 concatenate the name with NAMED_SECTION_SUFFIX.
527 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
528
529section *
530get_named_text_section (tree decl,
531 const char *text_section_name,
532 const char *named_section_suffix)
533{
534 if (decl && DECL_SECTION_NAME (decl))
535 {
536 if (named_section_suffix)
537 {
538 const char *dsn = DECL_SECTION_NAME (decl);
539 const char *stripped_name;
540 char *name, *buffer;
541
542 name = (char *) alloca (strlen (dsn) + 1);
543 memcpy (name, dsn,
544 strlen (dsn) + 1);
545
546 stripped_name = targetm.strip_name_encoding (name);
547
548 buffer = ACONCAT ((stripped_name, named_section_suffix, NULL));
549 return get_named_section (decl, buffer, 0);
550 }
551 else if (symtab_node::get (decl)->implicit_section)
552 {
553 const char *name;
554
555 /* Do not try to split gnu_linkonce functions. This gets somewhat
556 slipperly. */
557 if (DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP)
558 return NULL;
559 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
560 name = targetm.strip_name_encoding (name);
561 return get_named_section (decl, ACONCAT ((text_section_name, ".",
562 name, NULL)), 0);
563 }
564 else
565 return NULL;
566 }
567 return get_named_section (decl, text_section_name, 0);
568}
569
570/* Choose named function section based on its frequency. */
571
572section *
573default_function_section (tree decl, enum node_frequency freq,
574 bool startup, bool exit)
575{
576#if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
577 /* Old GNU linkers have buggy --gc-section support, which sometimes
578 results in .gcc_except_table* sections being garbage collected. */
579 if (decl
580 && symtab_node::get (decl)->implicit_section)
581 return NULL;
582#endif
583
584 if (!flag_reorder_functions
585 || !targetm_common.have_named_sections)
586 return NULL;
587 /* Startup code should go to startup subsection unless it is
588 unlikely executed (this happens especially with function splitting
589 where we can split away unnecessary parts of static constructors. */
590 if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
591 {
592 /* If we do have a profile or(and) LTO phase is executed, we do not need
593 these ELF section. */
594 if (!in_lto_p || !flag_profile_values)
595 return get_named_text_section (decl, ".text.startup", NULL);
596 else
597 return NULL;
598 }
599
600 /* Similarly for exit. */
601 if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
602 return get_named_text_section (decl, ".text.exit", NULL);
603
604 /* Group cold functions together, similarly for hot code. */
605 switch (freq)
606 {
607 case NODE_FREQUENCY_UNLIKELY_EXECUTED:
608 return get_named_text_section (decl, ".text.unlikely", NULL);
609 case NODE_FREQUENCY_HOT:
610 /* If we do have a profile or(and) LTO phase is executed, we do not need
611 these ELF section. */
612 if (!in_lto_p || !flag_profile_values)
613 return get_named_text_section (decl, ".text.hot", NULL);
614 default:
615 return NULL;
616 }
617}
618
619/* Return the section for function DECL.
620
621 If DECL is NULL_TREE, return the text section. We can be passed
622 NULL_TREE under some circumstances by dbxout.c at least.
623
624 If FORCE_COLD is true, return cold function section ignoring
625 the frequency info of cgraph_node. */
626
627static section *
628function_section_1 (tree decl, bool force_cold)
629{
630 section *section = NULL;
631 enum node_frequency freq = NODE_FREQUENCY_NORMAL;
632 bool startup = false, exit = false;
633
634 if (decl)
635 {
636 struct cgraph_node *node = cgraph_node::get (decl);
637
638 if (node)
639 {
640 freq = node->frequency;
641 startup = node->only_called_at_startup;
642 exit = node->only_called_at_exit;
643 }
644 }
645 if (force_cold)
646 freq = NODE_FREQUENCY_UNLIKELY_EXECUTED;
647
648#ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
649 if (decl != NULL_TREE
650 && DECL_SECTION_NAME (decl) != NULL)
651 {
652 if (targetm.asm_out.function_section)
653 section = targetm.asm_out.function_section (decl, freq,
654 startup, exit);
655 if (section)
656 return section;
657 return get_named_section (decl, NULL, 0);
658 }
659 else
660 return targetm.asm_out.select_section
661 (decl, freq == NODE_FREQUENCY_UNLIKELY_EXECUTED,
f09a3553 662 symtab_node::get (decl)->definition_alignment ());
dda118e3
JM
663#else
664 if (targetm.asm_out.function_section)
665 section = targetm.asm_out.function_section (decl, freq, startup, exit);
666 if (section)
667 return section;
668 return hot_function_section (decl);
669#endif
670}
671
672/* Return the section for function DECL.
673
674 If DECL is NULL_TREE, return the text section. We can be passed
675 NULL_TREE under some circumstances by dbxout.c at least. */
676
677section *
678function_section (tree decl)
679{
680 /* Handle cases where function splitting code decides
681 to put function entry point into unlikely executed section
682 despite the fact that the function itself is not cold
683 (i.e. it is called rarely but contains a hot loop that is
684 better to live in hot subsection for the code locality). */
685 return function_section_1 (decl,
686 first_function_block_is_cold);
687}
688
689/* Return the section for the current function, take IN_COLD_SECTION_P
690 into account. */
691
692section *
693current_function_section (void)
694{
695 return function_section_1 (current_function_decl, in_cold_section_p);
696}
697
698/* Tell assembler to switch to unlikely-to-be-executed text section. */
699
700section *
701unlikely_text_section (void)
702{
703 return function_section_1 (current_function_decl, true);
704}
705
706/* When called within a function context, return true if the function
707 has been assigned a cold text section and if SECT is that section.
708 When called outside a function context, return true if SECT is the
709 default cold section. */
710
711bool
712unlikely_text_section_p (section *sect)
713{
714 return sect == function_section_1 (current_function_decl, true);
715}
716
717/* Return the read-only data section associated with function DECL. */
718
719section *
720default_function_rodata_section (tree decl)
721{
722 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
723 {
724 const char *name = DECL_SECTION_NAME (decl);
725
726 if (DECL_COMDAT_GROUP (decl) && HAVE_COMDAT_GROUP)
727 {
728 const char *dot;
729 size_t len;
730 char* rname;
731
732 dot = strchr (name + 1, '.');
733 if (!dot)
734 dot = name;
735 len = strlen (dot) + 8;
736 rname = (char *) alloca (len);
737
738 strcpy (rname, ".rodata");
739 strcat (rname, dot);
740 return get_section (rname, SECTION_LINKONCE, decl);
741 }
742 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
743 else if (DECL_COMDAT_GROUP (decl)
744 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
745 {
746 size_t len = strlen (name) + 1;
747 char *rname = (char *) alloca (len);
748
749 memcpy (rname, name, len);
750 rname[14] = 'r';
751 return get_section (rname, SECTION_LINKONCE, decl);
752 }
753 /* For .text.foo we want to use .rodata.foo. */
754 else if (flag_function_sections && flag_data_sections
755 && strncmp (name, ".text.", 6) == 0)
756 {
757 size_t len = strlen (name) + 1;
758 char *rname = (char *) alloca (len + 2);
759
760 memcpy (rname, ".rodata", 7);
761 memcpy (rname + 7, name + 5, len - 5);
762 return get_section (rname, 0, decl);
763 }
764 }
765
766 return readonly_data_section;
767}
768
769/* Return the read-only data section associated with function DECL
770 for targets where that section should be always the single
771 readonly data section. */
772
773section *
774default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
775{
776 return readonly_data_section;
777}
778
779/* Return the section to use for string merging. */
780
781static section *
782mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
783 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
784 unsigned int flags ATTRIBUTE_UNUSED)
785{
786 HOST_WIDE_INT len;
787
788 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
789 && TREE_CODE (decl) == STRING_CST
790 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
791 && align <= 256
792 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
793 && TREE_STRING_LENGTH (decl) >= len)
794 {
795 machine_mode mode;
796 unsigned int modesize;
797 const char *str;
798 HOST_WIDE_INT i;
799 int j, unit;
800 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
801 char *name = (char *) alloca (strlen (prefix) + 30);
802
803 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
804 modesize = GET_MODE_BITSIZE (mode);
805 if (modesize >= 8 && modesize <= 256
806 && (modesize & (modesize - 1)) == 0)
807 {
808 if (align < modesize)
809 align = modesize;
810
811 str = TREE_STRING_POINTER (decl);
812 unit = GET_MODE_SIZE (mode);
813
814 /* Check for embedded NUL characters. */
815 for (i = 0; i < len; i += unit)
816 {
817 for (j = 0; j < unit; j++)
818 if (str[i + j] != '\0')
819 break;
820 if (j == unit)
821 break;
822 }
823 if (i == len - unit)
824 {
825 sprintf (name, "%s.str%d.%d", prefix,
826 modesize / 8, (int) (align / 8));
827 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
828 return get_section (name, flags, NULL);
829 }
830 }
831 }
832
833 return readonly_data_section;
834}
835
836/* Return the section to use for constant merging. */
837
838section *
839mergeable_constant_section (machine_mode mode ATTRIBUTE_UNUSED,
840 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
841 unsigned int flags ATTRIBUTE_UNUSED)
842{
843 unsigned int modesize = GET_MODE_BITSIZE (mode);
844
845 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
846 && mode != VOIDmode
847 && mode != BLKmode
848 && modesize <= align
849 && align >= 8
850 && align <= 256
851 && (align & (align - 1)) == 0)
852 {
853 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
854 char *name = (char *) alloca (strlen (prefix) + 30);
855
856 sprintf (name, "%s.cst%d", prefix, (int) (align / 8));
857 flags |= (align / 8) | SECTION_MERGE;
858 return get_section (name, flags, NULL);
859 }
860 return readonly_data_section;
861}
862\f
863/* Given NAME, a putative register name, discard any customary prefixes. */
864
865static const char *
866strip_reg_name (const char *name)
867{
868#ifdef REGISTER_PREFIX
869 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
870 name += strlen (REGISTER_PREFIX);
871#endif
872 if (name[0] == '%' || name[0] == '#')
873 name++;
874 return name;
875}
876\f
877/* The user has asked for a DECL to have a particular name. Set (or
878 change) it in such a way that we don't prefix an underscore to
879 it. */
880void
881set_user_assembler_name (tree decl, const char *name)
882{
883 char *starred = (char *) alloca (strlen (name) + 2);
884 starred[0] = '*';
885 strcpy (starred + 1, name);
886 symtab->change_decl_assembler_name (decl, get_identifier (starred));
887 SET_DECL_RTL (decl, NULL_RTX);
888}
889\f
890/* Decode an `asm' spec for a declaration as a register name.
891 Return the register number, or -1 if nothing specified,
892 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
893 or -3 if ASMSPEC is `cc' and is not recognized,
894 or -4 if ASMSPEC is `memory' and is not recognized.
895 Accept an exact spelling or a decimal number.
896 Prefixes such as % are optional. */
897
898int
899decode_reg_name_and_count (const char *asmspec, int *pnregs)
900{
901 /* Presume just one register is clobbered. */
902 *pnregs = 1;
903
904 if (asmspec != 0)
905 {
906 int i;
907
908 /* Get rid of confusing prefixes. */
909 asmspec = strip_reg_name (asmspec);
910
911 /* Allow a decimal number as a "register name". */
912 for (i = strlen (asmspec) - 1; i >= 0; i--)
913 if (! ISDIGIT (asmspec[i]))
914 break;
915 if (asmspec[0] != 0 && i < 0)
916 {
917 i = atoi (asmspec);
918 if (i < FIRST_PSEUDO_REGISTER && i >= 0 && reg_names[i][0])
919 return i;
920 else
921 return -2;
922 }
923
924 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
925 if (reg_names[i][0]
926 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
927 return i;
928
929#ifdef OVERLAPPING_REGISTER_NAMES
930 {
931 static const struct
932 {
933 const char *const name;
934 const int number;
935 const int nregs;
936 } table[] = OVERLAPPING_REGISTER_NAMES;
937
938 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
939 if (table[i].name[0]
940 && ! strcmp (asmspec, table[i].name))
941 {
942 *pnregs = table[i].nregs;
943 return table[i].number;
944 }
945 }
946#endif /* OVERLAPPING_REGISTER_NAMES */
947
948#ifdef ADDITIONAL_REGISTER_NAMES
949 {
950 static const struct { const char *const name; const int number; } table[]
951 = ADDITIONAL_REGISTER_NAMES;
952
953 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
954 if (table[i].name[0]
955 && ! strcmp (asmspec, table[i].name)
956 && reg_names[table[i].number][0])
957 return table[i].number;
958 }
959#endif /* ADDITIONAL_REGISTER_NAMES */
960
961 if (!strcmp (asmspec, "memory"))
962 return -4;
963
964 if (!strcmp (asmspec, "cc"))
965 return -3;
966
967 return -2;
968 }
969
970 return -1;
971}
972
973int
974decode_reg_name (const char *name)
975{
976 int count;
977 return decode_reg_name_and_count (name, &count);
978}
979
980\f
981/* Return true if DECL's initializer is suitable for a BSS section. */
982
983bool
984bss_initializer_p (const_tree decl)
985{
986 return (DECL_INITIAL (decl) == NULL
987 /* In LTO we have no errors in program; error_mark_node is used
988 to mark offlined constructors. */
989 || (DECL_INITIAL (decl) == error_mark_node
990 && !in_lto_p)
991 || (flag_zero_initialized_in_bss
992 /* Leave constant zeroes in .rodata so they
993 can be shared. */
994 && !TREE_READONLY (decl)
995 && initializer_zerop (DECL_INITIAL (decl))));
996}
997
998/* Compute the alignment of variable specified by DECL.
999 DONT_OUTPUT_DATA is from assemble_variable. */
1000
1001void
1002align_variable (tree decl, bool dont_output_data)
1003{
1004 unsigned int align = DECL_ALIGN (decl);
1005
1006 /* In the case for initialing an array whose length isn't specified,
1007 where we have not yet been able to do the layout,
1008 figure out the proper alignment now. */
1009 if (dont_output_data && DECL_SIZE (decl) == 0
1010 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1011 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1012
1013 /* Some object file formats have a maximum alignment which they support.
1014 In particular, a.out format supports a maximum alignment of 4. */
1015 if (align > MAX_OFILE_ALIGNMENT)
1016 {
1017 error ("alignment of %q+D is greater than maximum object "
1018 "file alignment %d", decl,
1019 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1020 align = MAX_OFILE_ALIGNMENT;
1021 }
1022
1023 if (! DECL_USER_ALIGN (decl))
1024 {
1025#ifdef DATA_ABI_ALIGNMENT
1026 unsigned int data_abi_align
1027 = DATA_ABI_ALIGNMENT (TREE_TYPE (decl), align);
1028 /* For backwards compatibility, don't assume the ABI alignment for
1029 TLS variables. */
1030 if (! DECL_THREAD_LOCAL_P (decl) || data_abi_align <= BITS_PER_WORD)
1031 align = data_abi_align;
1032#endif
1033
1034 /* On some machines, it is good to increase alignment sometimes.
1035 But as DECL_ALIGN is used both for actually emitting the variable
1036 and for code accessing the variable as guaranteed alignment, we
1037 can only increase the alignment if it is a performance optimization
1038 if the references to it must bind to the current definition. */
1039 if (decl_binds_to_current_def_p (decl)
1040 && !DECL_VIRTUAL_P (decl))
1041 {
1042#ifdef DATA_ALIGNMENT
1043 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1044 /* Don't increase alignment too much for TLS variables - TLS space
1045 is too precious. */
1046 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1047 align = data_align;
1048#endif
1049#ifdef CONSTANT_ALIGNMENT
1050 if (DECL_INITIAL (decl) != 0
1051 /* In LTO we have no errors in program; error_mark_node is used
1052 to mark offlined constructors. */
1053 && (in_lto_p || DECL_INITIAL (decl) != error_mark_node))
1054 {
1055 unsigned int const_align
1056 = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1057 /* Don't increase alignment too much for TLS variables - TLS
1058 space is too precious. */
1059 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1060 align = const_align;
1061 }
1062#endif
1063 }
1064 }
1065
1066 /* Reset the alignment in case we have made it tighter, so we can benefit
1067 from it in get_pointer_alignment. */
1068 DECL_ALIGN (decl) = align;
1069}
1070
1071/* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1072 beyond what align_variable returned. */
1073
1074static unsigned int
1075get_variable_align (tree decl)
1076{
1077 unsigned int align = DECL_ALIGN (decl);
1078
1079 /* For user aligned vars or static vars align_variable already did
1080 everything. */
1081 if (DECL_USER_ALIGN (decl) || !TREE_PUBLIC (decl))
1082 return align;
1083
1084#ifdef DATA_ABI_ALIGNMENT
1085 if (DECL_THREAD_LOCAL_P (decl))
1086 align = DATA_ABI_ALIGNMENT (TREE_TYPE (decl), align);
1087#endif
1088
1089 /* For decls that bind to the current definition, align_variable
1090 did also everything, except for not assuming ABI required alignment
1091 of TLS variables. For other vars, increase the alignment here
1092 as an optimization. */
1093 if (!decl_binds_to_current_def_p (decl))
1094 {
1095 /* On some machines, it is good to increase alignment sometimes. */
1096#ifdef DATA_ALIGNMENT
1097 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1098 /* Don't increase alignment too much for TLS variables - TLS space
1099 is too precious. */
1100 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1101 align = data_align;
1102#endif
1103#ifdef CONSTANT_ALIGNMENT
1104 if (DECL_INITIAL (decl) != 0
1105 /* In LTO we have no errors in program; error_mark_node is used
1106 to mark offlined constructors. */
1107 && (in_lto_p || DECL_INITIAL (decl) != error_mark_node))
1108 {
1109 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
1110 align);
1111 /* Don't increase alignment too much for TLS variables - TLS space
1112 is too precious. */
1113 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1114 align = const_align;
1115 }
1116#endif
1117 }
1118
1119 return align;
1120}
1121
1122/* Return the section into which the given VAR_DECL or CONST_DECL
1123 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1124 section should be used wherever possible. */
1125
1126section *
1127get_variable_section (tree decl, bool prefer_noswitch_p)
1128{
1129 addr_space_t as = ADDR_SPACE_GENERIC;
1130 int reloc;
1131 varpool_node *vnode = varpool_node::get (decl);
1132 if (vnode)
1133 {
1134 vnode = vnode->ultimate_alias_target ();
1135 decl = vnode->decl;
1136 }
1137
1138 if (TREE_TYPE (decl) != error_mark_node)
1139 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1140
1141 /* We need the constructor to figure out reloc flag. */
1142 if (vnode)
1143 vnode->get_constructor ();
1144
1145 if (DECL_COMMON (decl))
1146 {
1147 /* If the decl has been given an explicit section name, or it resides
1148 in a non-generic address space, then it isn't common, and shouldn't
1149 be handled as such. */
1150 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1151 && ADDR_SPACE_GENERIC_P (as));
1152 if (DECL_THREAD_LOCAL_P (decl))
1153 return tls_comm_section;
1154 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1155 return comm_section;
1156 }
1157
1158 if (DECL_INITIAL (decl) == error_mark_node)
1159 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1160 else if (DECL_INITIAL (decl))
1161 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1162 else
1163 reloc = 0;
1164
1165 resolve_unique_section (decl, reloc, flag_data_sections);
1166 if (IN_NAMED_SECTION (decl))
1167 return get_named_section (decl, NULL, reloc);
1168
1169 if (ADDR_SPACE_GENERIC_P (as)
1170 && !DECL_THREAD_LOCAL_P (decl)
1171 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1172 && bss_initializer_p (decl))
1173 {
1174 if (!TREE_PUBLIC (decl)
1175 && !((flag_sanitize & SANITIZE_ADDRESS)
1176 && asan_protect_global (decl)))
1177 return lcomm_section;
1178 if (bss_noswitch_section)
1179 return bss_noswitch_section;
1180 }
1181
1182 return targetm.asm_out.select_section (decl, reloc,
1183 get_variable_align (decl));
1184}
1185
1186/* Return the block into which object_block DECL should be placed. */
1187
1188static struct object_block *
1189get_block_for_decl (tree decl)
1190{
1191 section *sect;
1192
1193 if (TREE_CODE (decl) == VAR_DECL)
1194 {
1195 /* The object must be defined in this translation unit. */
1196 if (DECL_EXTERNAL (decl))
1197 return NULL;
1198
1199 /* There's no point using object blocks for something that is
1200 isolated by definition. */
1201 if (DECL_COMDAT_GROUP (decl))
1202 return NULL;
1203 }
1204
1205 /* We can only calculate block offsets if the decl has a known
1206 constant size. */
1207 if (DECL_SIZE_UNIT (decl) == NULL)
1208 return NULL;
1209 if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl)))
1210 return NULL;
1211
1212 /* Find out which section should contain DECL. We cannot put it into
1213 an object block if it requires a standalone definition. */
1214 if (TREE_CODE (decl) == VAR_DECL)
1215 align_variable (decl, 0);
1216 sect = get_variable_section (decl, true);
1217 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1218 return NULL;
1219
1220 return get_block_for_section (sect);
1221}
1222
1223/* Make sure block symbol SYMBOL is in block BLOCK. */
1224
1225static void
1226change_symbol_block (rtx symbol, struct object_block *block)
1227{
1228 if (block != SYMBOL_REF_BLOCK (symbol))
1229 {
1230 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1231 SYMBOL_REF_BLOCK (symbol) = block;
1232 }
1233}
1234
1235/* Return true if it is possible to put DECL in an object_block. */
1236
1237static bool
1238use_blocks_for_decl_p (tree decl)
1239{
1240 struct symtab_node *snode;
1241
1242 /* Only data DECLs can be placed into object blocks. */
1243 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1244 return false;
1245
1246 /* Detect decls created by dw2_force_const_mem. Such decls are
1247 special because DECL_INITIAL doesn't specify the decl's true value.
1248 dw2_output_indirect_constants will instead call assemble_variable
1249 with dont_output_data set to 1 and then print the contents itself. */
1250 if (DECL_INITIAL (decl) == decl)
1251 return false;
1252
1253 /* If this decl is an alias, then we don't want to emit a
1254 definition. */
1255 if (TREE_CODE (decl) == VAR_DECL
1256 && (snode = symtab_node::get (decl)) != NULL
1257 && snode->alias)
1258 return false;
1259
1260 return targetm.use_blocks_for_decl_p (decl);
1261}
1262
1263/* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1264 until we find an identifier that is not itself a transparent alias.
1265 Modify the alias passed to it by reference (and all aliases on the
1266 way to the ultimate target), such that they do not have to be
1267 followed again, and return the ultimate target of the alias
1268 chain. */
1269
1270static inline tree
1271ultimate_transparent_alias_target (tree *alias)
1272{
1273 tree target = *alias;
1274
1275 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
1276 {
1277 gcc_assert (TREE_CHAIN (target));
1278 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
1279 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
1280 && ! TREE_CHAIN (target));
1281 *alias = target;
1282 }
1283
1284 return target;
1285}
1286
1287/* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1288 have static storage duration. In other words, it should not be an
1289 automatic variable, including PARM_DECLs.
1290
1291 There is, however, one exception: this function handles variables
1292 explicitly placed in a particular register by the user.
1293
1294 This is never called for PARM_DECL nodes. */
1295
1296void
1297make_decl_rtl (tree decl)
1298{
1299 const char *name = 0;
1300 int reg_number;
1301 tree id;
1302 rtx x;
1303
1304 /* Check that we are not being given an automatic variable. */
1305 gcc_assert (TREE_CODE (decl) != PARM_DECL
1306 && TREE_CODE (decl) != RESULT_DECL);
1307
1308 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1309 gcc_assert (TREE_CODE (decl) != VAR_DECL
1310 || TREE_STATIC (decl)
1311 || TREE_PUBLIC (decl)
1312 || DECL_EXTERNAL (decl)
1313 || DECL_REGISTER (decl));
1314
1315 /* And that we were not given a type or a label. */
1316 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1317 && TREE_CODE (decl) != LABEL_DECL);
1318
1319 /* For a duplicate declaration, we can be called twice on the
1320 same DECL node. Don't discard the RTL already made. */
1321 if (DECL_RTL_SET_P (decl))
1322 {
1323 /* If the old RTL had the wrong mode, fix the mode. */
1324 x = DECL_RTL (decl);
1325 if (GET_MODE (x) != DECL_MODE (decl))
1326 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1327
1328 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1329 return;
1330
1331 /* ??? Another way to do this would be to maintain a hashed
1332 table of such critters. Instead of adding stuff to a DECL
1333 to give certain attributes to it, we could use an external
1334 hash map from DECL to set of attributes. */
1335
1336 /* Let the target reassign the RTL if it wants.
1337 This is necessary, for example, when one machine specific
1338 decl attribute overrides another. */
1339 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1340
1341 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1342 on the new decl information. */
1343 if (MEM_P (x)
1344 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1345 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1346 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1347
1348 return;
1349 }
1350
1351 /* If this variable belongs to the global constant pool, retrieve the
1352 pre-computed RTL or recompute it in LTO mode. */
1353 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1354 {
1355 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1356 return;
1357 }
1358
1359 id = DECL_ASSEMBLER_NAME (decl);
1360 if (TREE_CODE (decl) == FUNCTION_DECL
1361 && cgraph_node::get (decl)
1362 && cgraph_node::get (decl)->instrumentation_clone)
1363 ultimate_transparent_alias_target (&id);
1364 name = IDENTIFIER_POINTER (id);
1365
1366 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1367 && DECL_REGISTER (decl))
1368 {
1369 error ("register name not specified for %q+D", decl);
1370 }
1371 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1372 {
1373 const char *asmspec = name+1;
1374 machine_mode mode = DECL_MODE (decl);
1375 reg_number = decode_reg_name (asmspec);
1376 /* First detect errors in declaring global registers. */
1377 if (reg_number == -1)
1378 error ("register name not specified for %q+D", decl);
1379 else if (reg_number < 0)
1380 error ("invalid register name for %q+D", decl);
1381 else if (mode == BLKmode)
1382 error ("data type of %q+D isn%'t suitable for a register",
1383 decl);
1384 else if (!in_hard_reg_set_p (accessible_reg_set, mode, reg_number))
1385 error ("the register specified for %q+D cannot be accessed"
1386 " by the current target", decl);
1387 else if (!in_hard_reg_set_p (operand_reg_set, mode, reg_number))
1388 error ("the register specified for %q+D is not general enough"
1389 " to be used as a register variable", decl);
1390 else if (!HARD_REGNO_MODE_OK (reg_number, mode))
1391 error ("register specified for %q+D isn%'t suitable for data type",
1392 decl);
1393 /* Now handle properly declared static register variables. */
1394 else
1395 {
1396 int nregs;
1397
1398 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1399 {
1400 DECL_INITIAL (decl) = 0;
1401 error ("global register variable has initial value");
1402 }
1403 if (TREE_THIS_VOLATILE (decl))
1404 warning (OPT_Wvolatile_register_var,
1405 "optimization may eliminate reads and/or "
1406 "writes to register variables");
1407
1408 /* If the user specified one of the eliminables registers here,
1409 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1410 confused with that register and be eliminated. This usage is
1411 somewhat suspect... */
1412
1413 SET_DECL_RTL (decl, gen_rtx_raw_REG (mode, reg_number));
1414 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1415 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1416
1417 if (TREE_STATIC (decl))
1418 {
1419 /* Make this register global, so not usable for anything
1420 else. */
1421#ifdef ASM_DECLARE_REGISTER_GLOBAL
1422 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1423 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1424#endif
1425 nregs = hard_regno_nregs[reg_number][mode];
1426 while (nregs > 0)
1427 globalize_reg (decl, reg_number + --nregs);
1428 }
1429
1430 /* As a register variable, it has no section. */
1431 return;
1432 }
1433 /* Avoid internal errors from invalid register
1434 specifications. */
1435 SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
1436 DECL_HARD_REGISTER (decl) = 0;
1437 return;
1438 }
1439 /* Now handle ordinary static variables and functions (in memory).
1440 Also handle vars declared register invalidly. */
1441 else if (name[0] == '*')
1442 {
1443#ifdef REGISTER_PREFIX
1444 if (strlen (REGISTER_PREFIX) != 0)
1445 {
1446 reg_number = decode_reg_name (name);
1447 if (reg_number >= 0 || reg_number == -3)
1448 error ("register name given for non-register variable %q+D", decl);
1449 }
1450#endif
1451 }
1452
1453 /* Specifying a section attribute on a variable forces it into a
1454 non-.bss section, and thus it cannot be common. */
1455 /* FIXME: In general this code should not be necessary because
1456 visibility pass is doing the same work. But notice_global_symbol
1457 is called early and it needs to make DECL_RTL to get the name.
1458 we take care of recomputing the DECL_RTL after visibility is changed. */
1459 if (TREE_CODE (decl) == VAR_DECL
1460 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
1461 && DECL_SECTION_NAME (decl) != NULL
1462 && DECL_INITIAL (decl) == NULL_TREE
1463 && DECL_COMMON (decl))
1464 DECL_COMMON (decl) = 0;
1465
1466 /* Variables can't be both common and weak. */
1467 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1468 DECL_COMMON (decl) = 0;
1469
1470 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1471 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1472 else
1473 {
1474 machine_mode address_mode = Pmode;
1475 if (TREE_TYPE (decl) != error_mark_node)
1476 {
1477 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1478 address_mode = targetm.addr_space.address_mode (as);
1479 }
1480 x = gen_rtx_SYMBOL_REF (address_mode, name);
1481 }
1482 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1483 SET_SYMBOL_REF_DECL (x, decl);
1484
1485 x = gen_rtx_MEM (DECL_MODE (decl), x);
1486 if (TREE_CODE (decl) != FUNCTION_DECL)
1487 set_mem_attributes (x, decl, 1);
1488 SET_DECL_RTL (decl, x);
1489
1490 /* Optionally set flags or add text to the name to record information
1491 such as that it is a function name.
1492 If the name is changed, the macro ASM_OUTPUT_LABELREF
1493 will have to know how to strip this information. */
1494 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1495}
1496
1497/* Like make_decl_rtl, but inhibit creation of new alias sets when
1498 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1499 rtl. */
1500
1501rtx
1502make_decl_rtl_for_debug (tree decl)
1503{
1504 unsigned int save_aliasing_flag;
1505 rtx rtl;
1506
1507 if (DECL_RTL_SET_P (decl))
1508 return DECL_RTL (decl);
1509
1510 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1511 call new_alias_set. If running with -fcompare-debug, sometimes
1512 we do not want to create alias sets that will throw the alias
1513 numbers off in the comparison dumps. So... clearing
1514 flag_strict_aliasing will keep new_alias_set() from creating a
1515 new set. */
1516 save_aliasing_flag = flag_strict_aliasing;
1517 flag_strict_aliasing = 0;
1518
1519 rtl = DECL_RTL (decl);
1520 /* Reset DECL_RTL back, as various parts of the compiler expects
1521 DECL_RTL set meaning it is actually going to be output. */
1522 SET_DECL_RTL (decl, NULL);
1523
1524 flag_strict_aliasing = save_aliasing_flag;
1525 return rtl;
1526}
1527\f
1528/* Output a string of literal assembler code
1529 for an `asm' keyword used between functions. */
1530
1531void
1532assemble_asm (tree string)
1533{
1534 const char *p;
1535 app_enable ();
1536
1537 if (TREE_CODE (string) == ADDR_EXPR)
1538 string = TREE_OPERAND (string, 0);
1539
1540 p = TREE_STRING_POINTER (string);
1541 fprintf (asm_out_file, "%s%s\n", p[0] == '\t' ? "" : "\t", p);
1542}
1543
1544/* Write the address of the entity given by SYMBOL to SEC. */
1545void
1546assemble_addr_to_section (rtx symbol, section *sec)
1547{
1548 switch_to_section (sec);
1549 assemble_align (POINTER_SIZE);
1550 assemble_integer (symbol, POINTER_SIZE_UNITS, POINTER_SIZE, 1);
1551}
1552
1553/* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1554 not) section for PRIORITY. */
1555section *
1556get_cdtor_priority_section (int priority, bool constructor_p)
1557{
1558 char buf[16];
1559
1560 /* ??? This only works reliably with the GNU linker. */
1561 sprintf (buf, "%s.%.5u",
1562 constructor_p ? ".ctors" : ".dtors",
1563 /* Invert the numbering so the linker puts us in the proper
1564 order; constructors are run from right to left, and the
1565 linker sorts in increasing order. */
1566 MAX_INIT_PRIORITY - priority);
1567 return get_section (buf, SECTION_WRITE, NULL);
1568}
1569
1570void
1571default_named_section_asm_out_destructor (rtx symbol, int priority)
1572{
1573 section *sec;
1574
1575 if (priority != DEFAULT_INIT_PRIORITY)
1576 sec = get_cdtor_priority_section (priority,
1577 /*constructor_p=*/false);
1578 else
1579 sec = get_section (".dtors", SECTION_WRITE, NULL);
1580
1581 assemble_addr_to_section (symbol, sec);
1582}
1583
1584#ifdef DTORS_SECTION_ASM_OP
1585void
1586default_dtor_section_asm_out_destructor (rtx symbol,
1587 int priority ATTRIBUTE_UNUSED)
1588{
1589 assemble_addr_to_section (symbol, dtors_section);
1590}
1591#endif
1592
1593void
1594default_named_section_asm_out_constructor (rtx symbol, int priority)
1595{
1596 section *sec;
1597
1598 if (priority != DEFAULT_INIT_PRIORITY)
1599 sec = get_cdtor_priority_section (priority,
1600 /*constructor_p=*/true);
1601 else
1602 sec = get_section (".ctors", SECTION_WRITE, NULL);
1603
1604 assemble_addr_to_section (symbol, sec);
1605}
1606
1607#ifdef CTORS_SECTION_ASM_OP
1608void
1609default_ctor_section_asm_out_constructor (rtx symbol,
1610 int priority ATTRIBUTE_UNUSED)
1611{
1612 assemble_addr_to_section (symbol, ctors_section);
1613}
1614#endif
1615\f
1616/* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1617 a nonzero value if the constant pool should be output before the
1618 start of the function, or a zero value if the pool should output
1619 after the end of the function. The default is to put it before the
1620 start. */
1621
1622#ifndef CONSTANT_POOL_BEFORE_FUNCTION
1623#define CONSTANT_POOL_BEFORE_FUNCTION 1
1624#endif
1625
1626/* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1627 to be output to assembler.
1628 Set first_global_object_name and weak_global_object_name as appropriate. */
1629
1630void
1631notice_global_symbol (tree decl)
1632{
f09a3553 1633 const char **t = &first_global_object_name;
dda118e3
JM
1634
1635 if (first_global_object_name
1636 || !TREE_PUBLIC (decl)
1637 || DECL_EXTERNAL (decl)
1638 || !DECL_NAME (decl)
f09a3553 1639 || (TREE_CODE (decl) == VAR_DECL && DECL_HARD_REGISTER (decl))
dda118e3
JM
1640 || (TREE_CODE (decl) != FUNCTION_DECL
1641 && (TREE_CODE (decl) != VAR_DECL
1642 || (DECL_COMMON (decl)
1643 && (DECL_INITIAL (decl) == 0
f09a3553 1644 || DECL_INITIAL (decl) == error_mark_node)))))
dda118e3
JM
1645 return;
1646
1647 /* We win when global object is found, but it is useful to know about weak
1648 symbol as well so we can produce nicer unique names. */
1649 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
f09a3553 1650 t = &weak_global_object_name;
dda118e3 1651
f09a3553 1652 if (!*t)
dda118e3 1653 {
f09a3553
JM
1654 tree id = DECL_ASSEMBLER_NAME (decl);
1655 ultimate_transparent_alias_target (&id);
1656 *t = ggc_strdup (targetm.strip_name_encoding (IDENTIFIER_POINTER (id)));
dda118e3
JM
1657 }
1658}
1659
1660/* If not using flag_reorder_blocks_and_partition, decide early whether the
1661 current function goes into the cold section, so that targets can use
1662 current_function_section during RTL expansion. DECL describes the
1663 function. */
1664
1665void
1666decide_function_section (tree decl)
1667{
1668 first_function_block_is_cold = false;
1669
1670 if (flag_reorder_blocks_and_partition)
1671 /* We will decide in assemble_start_function. */
1672 return;
1673
1674 if (DECL_SECTION_NAME (decl))
1675 {
1676 struct cgraph_node *node = cgraph_node::get (current_function_decl);
1677 /* Calls to function_section rely on first_function_block_is_cold
1678 being accurate. */
1679 first_function_block_is_cold = (node
1680 && node->frequency
1681 == NODE_FREQUENCY_UNLIKELY_EXECUTED);
1682 }
1683
1684 in_cold_section_p = first_function_block_is_cold;
1685}
1686
1687/* Get the function's name, as described by its RTL. This may be
1688 different from the DECL_NAME name used in the source file. */
1689const char *
1690get_fnname_from_decl (tree decl)
1691{
1692 rtx x = DECL_RTL (decl);
1693 gcc_assert (MEM_P (x));
1694 x = XEXP (x, 0);
1695 gcc_assert (GET_CODE (x) == SYMBOL_REF);
1696 return XSTR (x, 0);
1697}
1698
1699/* Output assembler code for the constant pool of a function and associated
1700 with defining the name of the function. DECL describes the function.
1701 NAME is the function's name. For the constant pool, we use the current
1702 constant pool data. */
1703
1704void
1705assemble_start_function (tree decl, const char *fnname)
1706{
1707 int align;
1708 char tmp_label[100];
1709 bool hot_label_written = false;
1710
1711 if (flag_reorder_blocks_and_partition)
1712 {
1713 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1714 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1715 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1716 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1717 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1718 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1719 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1720 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1721 const_labelno++;
1722 }
1723 else
1724 {
1725 crtl->subsections.hot_section_label = NULL;
1726 crtl->subsections.cold_section_label = NULL;
1727 crtl->subsections.hot_section_end_label = NULL;
1728 crtl->subsections.cold_section_end_label = NULL;
1729 }
1730
1731 /* The following code does not need preprocessing in the assembler. */
1732
1733 app_disable ();
1734
1735 if (CONSTANT_POOL_BEFORE_FUNCTION)
1736 output_constant_pool (fnname, decl);
1737
f09a3553
JM
1738 align = symtab_node::get (decl)->definition_alignment ();
1739
dda118e3
JM
1740 /* Make sure the not and cold text (code) sections are properly
1741 aligned. This is necessary here in the case where the function
1742 has both hot and cold sections, because we don't want to re-set
1743 the alignment when the section switch happens mid-function. */
1744
1745 if (flag_reorder_blocks_and_partition)
1746 {
1747 first_function_block_is_cold = false;
1748
1749 switch_to_section (unlikely_text_section ());
f09a3553 1750 assemble_align (align);
dda118e3
JM
1751 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1752
1753 /* When the function starts with a cold section, we need to explicitly
1754 align the hot section and write out the hot section label.
1755 But if the current function is a thunk, we do not have a CFG. */
1756 if (!cfun->is_thunk
1757 && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb) == BB_COLD_PARTITION)
1758 {
1759 switch_to_section (text_section);
f09a3553 1760 assemble_align (align);
dda118e3
JM
1761 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1762 hot_label_written = true;
1763 first_function_block_is_cold = true;
1764 }
1765 in_cold_section_p = first_function_block_is_cold;
1766 }
1767
1768
1769 /* Switch to the correct text section for the start of the function. */
1770
1771 switch_to_section (function_section (decl));
1772 if (flag_reorder_blocks_and_partition
1773 && !hot_label_written)
1774 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1775
1776 /* Tell assembler to move to target machine's alignment for functions. */
f09a3553 1777 align = floor_log2 (align / BITS_PER_UNIT);
dda118e3
JM
1778 if (align > 0)
1779 {
1780 ASM_OUTPUT_ALIGN (asm_out_file, align);
1781 }
1782
1783 /* Handle a user-specified function alignment.
1784 Note that we still need to align to DECL_ALIGN, as above,
1785 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1786 if (! DECL_USER_ALIGN (decl)
1787 && align_functions_log > align
1788 && optimize_function_for_speed_p (cfun))
1789 {
1790#ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1791 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1792 align_functions_log, align_functions - 1);
1793#else
1794 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1795#endif
1796 }
1797
1798#ifdef ASM_OUTPUT_FUNCTION_PREFIX
1799 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1800#endif
1801
1802 if (!DECL_IGNORED_P (decl))
1803 (*debug_hooks->begin_function) (decl);
1804
1805 /* Make function name accessible from other files, if appropriate. */
1806
1807 if (TREE_PUBLIC (decl)
1808 || (cgraph_node::get (decl)->instrumentation_clone
1809 && cgraph_node::get (decl)->instrumented_version
1810 && TREE_PUBLIC (cgraph_node::get (decl)->instrumented_version->decl)))
1811 {
1812 notice_global_symbol (decl);
1813
1814 globalize_decl (decl);
1815
1816 maybe_assemble_visibility (decl);
1817 }
1818
1819 if (DECL_PRESERVE_P (decl))
1820 targetm.asm_out.mark_decl_preserved (fnname);
1821
1822 /* Do any machine/system dependent processing of the function name. */
1823#ifdef ASM_DECLARE_FUNCTION_NAME
1824 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1825#else
1826 /* Standard thing is just output label for the function. */
1827 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
1828#endif /* ASM_DECLARE_FUNCTION_NAME */
1829
1830 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))
1831 saw_no_split_stack = true;
1832}
1833
1834/* Output assembler code associated with defining the size of the
1835 function. DECL describes the function. NAME is the function's name. */
1836
1837void
1838assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1839{
1840#ifdef ASM_DECLARE_FUNCTION_SIZE
1841 /* We could have switched section in the middle of the function. */
1842 if (flag_reorder_blocks_and_partition)
1843 switch_to_section (function_section (decl));
1844 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1845#endif
1846 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1847 {
1848 output_constant_pool (fnname, decl);
1849 switch_to_section (function_section (decl)); /* need to switch back */
1850 }
1851 /* Output labels for end of hot/cold text sections (to be used by
1852 debug info.) */
1853 if (flag_reorder_blocks_and_partition)
1854 {
1855 section *save_text_section;
1856
1857 save_text_section = in_section;
1858 switch_to_section (unlikely_text_section ());
1859 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1860 if (first_function_block_is_cold)
1861 switch_to_section (text_section);
1862 else
1863 switch_to_section (function_section (decl));
1864 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1865 switch_to_section (save_text_section);
1866 }
1867}
1868\f
1869/* Assemble code to leave SIZE bytes of zeros. */
1870
1871void
1872assemble_zeros (unsigned HOST_WIDE_INT size)
1873{
1874 /* Do no output if -fsyntax-only. */
1875 if (flag_syntax_only)
1876 return;
1877
1878#ifdef ASM_NO_SKIP_IN_TEXT
1879 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1880 so we must output 0s explicitly in the text section. */
1881 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1882 {
1883 unsigned HOST_WIDE_INT i;
1884 for (i = 0; i < size; i++)
1885 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1886 }
1887 else
1888#endif
1889 if (size > 0)
1890 ASM_OUTPUT_SKIP (asm_out_file, size);
1891}
1892
1893/* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1894
1895void
1896assemble_align (int align)
1897{
1898 if (align > BITS_PER_UNIT)
1899 {
1900 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1901 }
1902}
1903
1904/* Assemble a string constant with the specified C string as contents. */
1905
1906void
1907assemble_string (const char *p, int size)
1908{
1909 int pos = 0;
1910 int maximum = 2000;
1911
1912 /* If the string is very long, split it up. */
1913
1914 while (pos < size)
1915 {
1916 int thissize = size - pos;
1917 if (thissize > maximum)
1918 thissize = maximum;
1919
1920 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1921
1922 pos += thissize;
1923 p += thissize;
1924 }
1925}
1926
1927\f
1928/* A noswitch_section_callback for lcomm_section. */
1929
1930static bool
9168936a 1931emit_local (tree decl ATTRIBUTE_UNUSED,
dda118e3
JM
1932 const char *name ATTRIBUTE_UNUSED,
1933 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1934 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1935{
1936#if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
9168936a 1937 int align = symtab_node::get (decl)->definition_alignment ();
dda118e3 1938 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
f09a3553 1939 size, align);
dda118e3
JM
1940 return true;
1941#elif defined ASM_OUTPUT_ALIGNED_LOCAL
9168936a 1942 int align = symtab_node::get (decl)->definition_alignment ();
f09a3553 1943 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, align);
dda118e3
JM
1944 return true;
1945#else
1946 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1947 return false;
1948#endif
1949}
1950
1951/* A noswitch_section_callback for bss_noswitch_section. */
1952
1953#if defined ASM_OUTPUT_ALIGNED_BSS
1954static bool
1955emit_bss (tree decl ATTRIBUTE_UNUSED,
1956 const char *name ATTRIBUTE_UNUSED,
1957 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1958 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1959{
1960#if defined ASM_OUTPUT_ALIGNED_BSS
1961 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
1962 get_variable_align (decl));
1963 return true;
1964#endif
1965}
1966#endif
1967
1968/* A noswitch_section_callback for comm_section. */
1969
1970static bool
1971emit_common (tree decl ATTRIBUTE_UNUSED,
1972 const char *name ATTRIBUTE_UNUSED,
1973 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1974 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1975{
1976#if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1977 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1978 size, get_variable_align (decl));
1979 return true;
1980#elif defined ASM_OUTPUT_ALIGNED_COMMON
1981 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1982 get_variable_align (decl));
1983 return true;
1984#else
1985 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1986 return false;
1987#endif
1988}
1989
1990/* A noswitch_section_callback for tls_comm_section. */
1991
1992static bool
1993emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1994 const char *name ATTRIBUTE_UNUSED,
1995 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1996 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1997{
1998#ifdef ASM_OUTPUT_TLS_COMMON
1999 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
2000 return true;
2001#else
2002 sorry ("thread-local COMMON data not implemented");
2003 return true;
2004#endif
2005}
2006
2007/* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2008 NAME is the name of DECL's SYMBOL_REF. */
2009
2010static void
2011assemble_noswitch_variable (tree decl, const char *name, section *sect,
2012 unsigned int align)
2013{
2014 unsigned HOST_WIDE_INT size, rounded;
2015
2016 size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
2017 rounded = size;
2018
2019 if ((flag_sanitize & SANITIZE_ADDRESS) && asan_protect_global (decl))
2020 size += asan_red_zone_size (size);
2021
2022 /* Don't allocate zero bytes of common,
2023 since that means "undefined external" in the linker. */
2024 if (size == 0)
2025 rounded = 1;
2026
2027 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2028 so that each uninitialized object starts on such a boundary. */
2029 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
2030 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2031 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2032
2033 if (!sect->noswitch.callback (decl, name, size, rounded)
2034 && (unsigned HOST_WIDE_INT) (align / BITS_PER_UNIT) > rounded)
2035 error ("requested alignment for %q+D is greater than "
2036 "implemented alignment of %wu", decl, rounded);
2037}
2038
2039/* A subroutine of assemble_variable. Output the label and contents of
2040 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2041 is as for assemble_variable. */
2042
2043static void
2044assemble_variable_contents (tree decl, const char *name,
2045 bool dont_output_data)
2046{
2047 /* Do any machine/system dependent processing of the object. */
2048#ifdef ASM_DECLARE_OBJECT_NAME
2049 last_assemble_variable_decl = decl;
2050 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
2051#else
2052 /* Standard thing is just output label for the object. */
2053 ASM_OUTPUT_LABEL (asm_out_file, name);
2054#endif /* ASM_DECLARE_OBJECT_NAME */
2055
2056 if (!dont_output_data)
2057 {
2058 /* Caller is supposed to use varpool_get_constructor when it wants
2059 to output the body. */
2060 gcc_assert (!in_lto_p || DECL_INITIAL (decl) != error_mark_node);
2061 if (DECL_INITIAL (decl)
2062 && DECL_INITIAL (decl) != error_mark_node
2063 && !initializer_zerop (DECL_INITIAL (decl)))
2064 /* Output the actual data. */
2065 output_constant (DECL_INITIAL (decl),
2066 tree_to_uhwi (DECL_SIZE_UNIT (decl)),
2067 get_variable_align (decl));
2068 else
2069 /* Leave space for it. */
2070 assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl)));
2071 targetm.asm_out.decl_end ();
2072 }
2073}
2074
2075/* Write out assembly for the variable DECL, which is not defined in
2076 the current translation unit. */
2077void
2078assemble_undefined_decl (tree decl)
2079{
2080 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2081 targetm.asm_out.assemble_undefined_decl (asm_out_file, name, decl);
2082}
2083
2084/* Assemble everything that is needed for a variable or function declaration.
2085 Not used for automatic variables, and not used for function definitions.
2086 Should not be called for variables of incomplete structure type.
2087
2088 TOP_LEVEL is nonzero if this variable has file scope.
2089 AT_END is nonzero if this is the special handling, at end of compilation,
2090 to define things that have had only tentative definitions.
2091 DONT_OUTPUT_DATA if nonzero means don't actually output the
2092 initial value (that will be done by the caller). */
2093
2094void
2095assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2096 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2097{
2098 const char *name;
2099 rtx decl_rtl, symbol;
2100 section *sect;
2101 unsigned int align;
2102 bool asan_protected = false;
2103
2104 /* This function is supposed to handle VARIABLES. Ensure we have one. */
2105 gcc_assert (TREE_CODE (decl) == VAR_DECL);
2106
2107 /* Emulated TLS had better not get this far. */
2108 gcc_checking_assert (targetm.have_tls || !DECL_THREAD_LOCAL_P (decl));
2109
2110 last_assemble_variable_decl = 0;
2111
2112 /* Normally no need to say anything here for external references,
2113 since assemble_external is called by the language-specific code
2114 when a declaration is first seen. */
2115
2116 if (DECL_EXTERNAL (decl))
2117 return;
2118
2119 /* Do nothing for global register variables. */
2120 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2121 {
2122 TREE_ASM_WRITTEN (decl) = 1;
2123 return;
2124 }
2125
2126 /* If type was incomplete when the variable was declared,
2127 see if it is complete now. */
2128
2129 if (DECL_SIZE (decl) == 0)
2130 layout_decl (decl, 0);
2131
2132 /* Still incomplete => don't allocate it; treat the tentative defn
2133 (which is what it must have been) as an `extern' reference. */
2134
2135 if (!dont_output_data && DECL_SIZE (decl) == 0)
2136 {
2137 error ("storage size of %q+D isn%'t known", decl);
2138 TREE_ASM_WRITTEN (decl) = 1;
2139 return;
2140 }
2141
2142 /* The first declaration of a variable that comes through this function
2143 decides whether it is global (in C, has external linkage)
2144 or local (in C, has internal linkage). So do nothing more
2145 if this function has already run. */
2146
2147 if (TREE_ASM_WRITTEN (decl))
2148 return;
2149
2150 /* Make sure targetm.encode_section_info is invoked before we set
2151 ASM_WRITTEN. */
2152 decl_rtl = DECL_RTL (decl);
2153
2154 TREE_ASM_WRITTEN (decl) = 1;
2155
2156 /* Do no output if -fsyntax-only. */
2157 if (flag_syntax_only)
2158 return;
2159
2160 if (! dont_output_data
2161 && ! valid_constant_size_p (DECL_SIZE_UNIT (decl)))
2162 {
2163 error ("size of variable %q+D is too large", decl);
2164 return;
2165 }
2166
2167 gcc_assert (MEM_P (decl_rtl));
2168 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2169 symbol = XEXP (decl_rtl, 0);
2170
2171 /* If this symbol belongs to the tree constant pool, output the constant
2172 if it hasn't already been written. */
2173 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2174 {
2175 tree decl = SYMBOL_REF_DECL (symbol);
2176 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2177 output_constant_def_contents (symbol);
2178 return;
2179 }
2180
2181 app_disable ();
2182
2183 name = XSTR (symbol, 0);
2184 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2185 notice_global_symbol (decl);
2186
2187 /* Compute the alignment of this data. */
2188
2189 align_variable (decl, dont_output_data);
2190
2191 if ((flag_sanitize & SANITIZE_ADDRESS)
2192 && asan_protect_global (decl))
2193 {
2194 asan_protected = true;
2195 DECL_ALIGN (decl) = MAX (DECL_ALIGN (decl),
2196 ASAN_RED_ZONE_SIZE * BITS_PER_UNIT);
2197 }
2198
2199 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2200
2201 align = get_variable_align (decl);
2202
2203 if (TREE_PUBLIC (decl))
2204 maybe_assemble_visibility (decl);
2205
2206 if (DECL_PRESERVE_P (decl))
2207 targetm.asm_out.mark_decl_preserved (name);
2208
2209 /* First make the assembler name(s) global if appropriate. */
2210 sect = get_variable_section (decl, false);
2211 if (TREE_PUBLIC (decl)
2212 && (sect->common.flags & SECTION_COMMON) == 0)
2213 globalize_decl (decl);
2214
2215 /* Output any data that we will need to use the address of. */
2216 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2217 output_addressed_constants (DECL_INITIAL (decl));
2218
2219 /* dbxout.c needs to know this. */
2220 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2221 DECL_IN_TEXT_SECTION (decl) = 1;
2222
2223 /* If the decl is part of an object_block, make sure that the decl
2224 has been positioned within its block, but do not write out its
2225 definition yet. output_object_blocks will do that later. */
2226 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2227 {
2228 gcc_assert (!dont_output_data);
2229 place_block_symbol (symbol);
2230 }
2231 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2232 assemble_noswitch_variable (decl, name, sect, align);
2233 else
2234 {
2235 /* The following bit of code ensures that vtable_map
2236 variables are not only in the comdat section, but that
2237 each variable has its own unique comdat name. If this
2238 code is removed, the variables end up in the same section
2239 with a single comdat name.
2240
2241 FIXME: resolve_unique_section needs to deal better with
2242 decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
2243 that is fixed, this if-else statement can be replaced with
2244 a single call to "switch_to_section (sect)". */
2245 if (sect->named.name
2246 && (strcmp (sect->named.name, ".vtable_map_vars") == 0))
2247 {
2248#if defined (OBJECT_FORMAT_ELF)
2249 targetm.asm_out.named_section (sect->named.name,
2250 sect->named.common.flags
2251 | SECTION_LINKONCE,
2252 DECL_NAME (decl));
2253 in_section = sect;
2254#elif defined (TARGET_PECOFF)
2255 /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
2256 Therefore the following check is used.
2257 In case a the target is PE or COFF a comdat group section
2258 is created, e.g. .vtable_map_vars$foo. The linker places
2259 everything in .vtable_map_vars at the end.
2260
2261 A fix could be made in
2262 gcc/config/i386/winnt.c: i386_pe_unique_section. */
2263 if (TARGET_PECOFF)
2264 {
2265 char *name;
2266
2267 if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
2268 name = ACONCAT ((sect->named.name, "$",
2269 IDENTIFIER_POINTER (DECL_NAME (decl)), NULL));
2270 else
2271 name = ACONCAT ((sect->named.name, "$",
2272 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))),
2273 NULL));
2274
2275 targetm.asm_out.named_section (name,
2276 sect->named.common.flags
2277 | SECTION_LINKONCE,
2278 DECL_NAME (decl));
2279 in_section = sect;
2280 }
2281#else
2282 switch_to_section (sect);
2283#endif
2284 }
2285 else
2286 switch_to_section (sect);
2287 if (align > BITS_PER_UNIT)
2288 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2289 assemble_variable_contents (decl, name, dont_output_data);
2290 if (asan_protected)
2291 {
2292 unsigned HOST_WIDE_INT int size
2293 = tree_to_uhwi (DECL_SIZE_UNIT (decl));
2294 assemble_zeros (asan_red_zone_size (size));
2295 }
2296 }
2297}
2298
2299
2300/* Given a function declaration (FN_DECL), this function assembles the
2301 function into the .preinit_array section. */
2302
2303void
2304assemble_vtv_preinit_initializer (tree fn_decl)
2305{
2306 section *sect;
2307 unsigned flags = SECTION_WRITE;
2308 rtx symbol = XEXP (DECL_RTL (fn_decl), 0);
2309
2310 flags |= SECTION_NOTYPE;
2311 sect = get_section (".preinit_array", flags, fn_decl);
2312 switch_to_section (sect);
2313 assemble_addr_to_section (symbol, sect);
2314}
2315
2316/* Return 1 if type TYPE contains any pointers. */
2317
2318static int
2319contains_pointers_p (tree type)
2320{
2321 switch (TREE_CODE (type))
2322 {
2323 case POINTER_TYPE:
2324 case REFERENCE_TYPE:
2325 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2326 so I'll play safe and return 1. */
2327 case OFFSET_TYPE:
2328 return 1;
2329
2330 case RECORD_TYPE:
2331 case UNION_TYPE:
2332 case QUAL_UNION_TYPE:
2333 {
2334 tree fields;
2335 /* For a type that has fields, see if the fields have pointers. */
2336 for (fields = TYPE_FIELDS (type); fields; fields = DECL_CHAIN (fields))
2337 if (TREE_CODE (fields) == FIELD_DECL
2338 && contains_pointers_p (TREE_TYPE (fields)))
2339 return 1;
2340 return 0;
2341 }
2342
2343 case ARRAY_TYPE:
2344 /* An array type contains pointers if its element type does. */
2345 return contains_pointers_p (TREE_TYPE (type));
2346
2347 default:
2348 return 0;
2349 }
2350}
2351
2352/* We delay assemble_external processing until
2353 the compilation unit is finalized. This is the best we can do for
2354 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2355 it all the way to final. See PR 17982 for further discussion. */
2356static GTY(()) tree pending_assemble_externals;
2357
2358#ifdef ASM_OUTPUT_EXTERNAL
2359/* Some targets delay some output to final using TARGET_ASM_FILE_END.
2360 As a result, assemble_external can be called after the list of externals
2361 is processed and the pointer set destroyed. */
2362static bool pending_assemble_externals_processed;
2363
2364/* Avoid O(external_decls**2) lookups in the pending_assemble_externals
2365 TREE_LIST in assemble_external. */
2366static hash_set<tree> *pending_assemble_externals_set;
2367
2368/* True if DECL is a function decl for which no out-of-line copy exists.
2369 It is assumed that DECL's assembler name has been set. */
2370
2371static bool
2372incorporeal_function_p (tree decl)
2373{
2374 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2375 {
2376 const char *name;
2377
2378 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2379 && (DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA
2380 || DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA_WITH_ALIGN))
2381 return true;
2382
2383 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2384 /* Atomic or sync builtins which have survived this far will be
2385 resolved externally and therefore are not incorporeal. */
2386 if (strncmp (name, "__builtin_", 10) == 0)
2387 return true;
2388 }
2389 return false;
2390}
2391
2392/* Actually do the tests to determine if this is necessary, and invoke
2393 ASM_OUTPUT_EXTERNAL. */
2394static void
2395assemble_external_real (tree decl)
2396{
2397 rtx rtl = DECL_RTL (decl);
2398
2399 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2400 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2401 && !incorporeal_function_p (decl))
2402 {
2403 /* Some systems do require some output. */
2404 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2405 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2406 }
2407}
2408#endif
2409
2410void
2411process_pending_assemble_externals (void)
2412{
2413#ifdef ASM_OUTPUT_EXTERNAL
2414 tree list;
2415 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2416 assemble_external_real (TREE_VALUE (list));
2417
2418 pending_assemble_externals = 0;
2419 pending_assemble_externals_processed = true;
2420 delete pending_assemble_externals_set;
2421#endif
2422}
2423
2424/* This TREE_LIST contains any weak symbol declarations waiting
2425 to be emitted. */
2426static GTY(()) tree weak_decls;
2427
2428/* Output something to declare an external symbol to the assembler,
2429 and qualifiers such as weakness. (Most assemblers don't need
2430 extern declaration, so we normally output nothing.) Do nothing if
2431 DECL is not external. */
2432
2433void
2434assemble_external (tree decl ATTRIBUTE_UNUSED)
2435{
2436 /* Make sure that the ASM_OUT_FILE is open.
2437 If it's not, we should not be calling this function. */
2438 gcc_assert (asm_out_file);
2439
2440 /* In a perfect world, the following condition would be true.
2441 Sadly, the Java and Go front ends emit assembly *from the front end*,
2442 bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2443#if 0
2444 /* This function should only be called if we are expanding, or have
2445 expanded, to RTL.
2446 Ideally, only final.c would be calling this function, but it is
2447 not clear whether that would break things somehow. See PR 17982
2448 for further discussion. */
2449 gcc_assert (state == EXPANSION
2450 || state == FINISHED);
2451#endif
2452
2453 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2454 return;
2455
2456 /* We want to output annotation for weak and external symbols at
2457 very last to check if they are references or not. */
2458
2459 if (TARGET_SUPPORTS_WEAK
2460 && DECL_WEAK (decl)
2461 /* TREE_STATIC is a weird and abused creature which is not
2462 generally the right test for whether an entity has been
2463 locally emitted, inlined or otherwise not-really-extern, but
2464 for declarations that can be weak, it happens to be
2465 match. */
2466 && !TREE_STATIC (decl)
2467 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2468 && value_member (decl, weak_decls) == NULL_TREE)
2469 weak_decls = tree_cons (NULL, decl, weak_decls);
2470
2471#ifdef ASM_OUTPUT_EXTERNAL
2472 if (pending_assemble_externals_processed)
2473 {
2474 assemble_external_real (decl);
2475 return;
2476 }
2477
2478 if (! pending_assemble_externals_set->add (decl))
2479 pending_assemble_externals = tree_cons (NULL, decl,
2480 pending_assemble_externals);
2481#endif
2482}
2483
2484/* Similar, for calling a library function FUN. */
2485
2486void
2487assemble_external_libcall (rtx fun)
2488{
2489 /* Declare library function name external when first used, if nec. */
2490 if (! SYMBOL_REF_USED (fun))
2491 {
2492 SYMBOL_REF_USED (fun) = 1;
2493 targetm.asm_out.external_libcall (fun);
2494 }
2495}
2496
2497/* Assemble a label named NAME. */
2498
2499void
2500assemble_label (FILE *file, const char *name)
2501{
2502 ASM_OUTPUT_LABEL (file, name);
2503}
2504
2505/* Set the symbol_referenced flag for ID. */
2506void
2507mark_referenced (tree id)
2508{
2509 TREE_SYMBOL_REFERENCED (id) = 1;
2510}
2511
2512/* Set the symbol_referenced flag for DECL and notify callgraph. */
2513void
2514mark_decl_referenced (tree decl)
2515{
2516 if (TREE_CODE (decl) == FUNCTION_DECL)
2517 {
2518 /* Extern inline functions don't become needed when referenced.
2519 If we know a method will be emitted in other TU and no new
2520 functions can be marked reachable, just use the external
2521 definition. */
2522 struct cgraph_node *node = cgraph_node::get_create (decl);
2523 if (!DECL_EXTERNAL (decl)
2524 && !node->definition)
2525 node->mark_force_output ();
2526 }
2527 else if (TREE_CODE (decl) == VAR_DECL)
2528 {
2529 varpool_node *node = varpool_node::get_create (decl);
2530 /* C++ frontend use mark_decl_references to force COMDAT variables
2531 to be output that might appear dead otherwise. */
2532 node->force_output = true;
2533 }
2534 /* else do nothing - we can get various sorts of CST nodes here,
2535 which do not need to be marked. */
2536}
2537
2538
2539/* Output to FILE (an assembly file) a reference to NAME. If NAME
2540 starts with a *, the rest of NAME is output verbatim. Otherwise
2541 NAME is transformed in a target-specific way (usually by the
2542 addition of an underscore). */
2543
2544void
2545assemble_name_raw (FILE *file, const char *name)
2546{
2547 if (name[0] == '*')
2548 fputs (&name[1], file);
2549 else
2550 ASM_OUTPUT_LABELREF (file, name);
2551}
2552
2553/* Like assemble_name_raw, but should be used when NAME might refer to
2554 an entity that is also represented as a tree (like a function or
2555 variable). If NAME does refer to such an entity, that entity will
2556 be marked as referenced. */
2557
2558void
2559assemble_name (FILE *file, const char *name)
2560{
2561 const char *real_name;
2562 tree id;
2563
2564 real_name = targetm.strip_name_encoding (name);
2565
2566 id = maybe_get_identifier (real_name);
2567 if (id)
2568 {
2569 tree id_orig = id;
2570
2571 mark_referenced (id);
2572 ultimate_transparent_alias_target (&id);
2573 if (id != id_orig)
2574 name = IDENTIFIER_POINTER (id);
2575 gcc_assert (! TREE_CHAIN (id));
2576 }
2577
2578 assemble_name_raw (file, name);
2579}
2580
2581/* Allocate SIZE bytes writable static space with a gensym name
2582 and return an RTX to refer to its address. */
2583
2584rtx
2585assemble_static_space (unsigned HOST_WIDE_INT size)
2586{
2587 char name[12];
2588 const char *namestring;
2589 rtx x;
2590
2591 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2592 ++const_labelno;
2593 namestring = ggc_strdup (name);
2594
2595 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2596 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2597
2598#ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2599 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2600 BIGGEST_ALIGNMENT);
2601#else
2602#ifdef ASM_OUTPUT_ALIGNED_LOCAL
2603 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2604#else
2605 {
2606 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2607 so that each uninitialized object starts on such a boundary. */
2608 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2609 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2610 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2611 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2612 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2613 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2614 }
2615#endif
2616#endif
2617 return x;
2618}
2619
2620/* Assemble the static constant template for function entry trampolines.
2621 This is done at most once per compilation.
2622 Returns an RTX for the address of the template. */
2623
2624static GTY(()) rtx initial_trampoline;
2625
2626rtx
2627assemble_trampoline_template (void)
2628{
2629 char label[256];
2630 const char *name;
2631 int align;
2632 rtx symbol;
2633
2634 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2635
2636 if (initial_trampoline)
2637 return initial_trampoline;
2638
2639 /* By default, put trampoline templates in read-only data section. */
2640
2641#ifdef TRAMPOLINE_SECTION
2642 switch_to_section (TRAMPOLINE_SECTION);
2643#else
2644 switch_to_section (readonly_data_section);
2645#endif
2646
2647 /* Write the assembler code to define one. */
2648 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2649 if (align > 0)
2650 ASM_OUTPUT_ALIGN (asm_out_file, align);
2651
2652 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2653 targetm.asm_out.trampoline_template (asm_out_file);
2654
2655 /* Record the rtl to refer to it. */
2656 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2657 name = ggc_strdup (label);
2658 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2659 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2660
2661 initial_trampoline = gen_const_mem (BLKmode, symbol);
2662 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2663 set_mem_size (initial_trampoline, TRAMPOLINE_SIZE);
2664
2665 return initial_trampoline;
2666}
2667\f
2668/* A and B are either alignments or offsets. Return the minimum alignment
2669 that may be assumed after adding the two together. */
2670
2671static inline unsigned
2672min_align (unsigned int a, unsigned int b)
2673{
2674 return (a | b) & -(a | b);
2675}
2676
2677/* Return the assembler directive for creating a given kind of integer
2678 object. SIZE is the number of bytes in the object and ALIGNED_P
2679 indicates whether it is known to be aligned. Return NULL if the
2680 assembly dialect has no such directive.
2681
2682 The returned string should be printed at the start of a new line and
2683 be followed immediately by the object's initial value. */
2684
2685const char *
2686integer_asm_op (int size, int aligned_p)
2687{
2688 struct asm_int_op *ops;
2689
2690 if (aligned_p)
2691 ops = &targetm.asm_out.aligned_op;
2692 else
2693 ops = &targetm.asm_out.unaligned_op;
2694
2695 switch (size)
2696 {
2697 case 1:
2698 return targetm.asm_out.byte_op;
2699 case 2:
2700 return ops->hi;
2701 case 4:
2702 return ops->si;
2703 case 8:
2704 return ops->di;
2705 case 16:
2706 return ops->ti;
2707 default:
2708 return NULL;
2709 }
2710}
2711
2712/* Use directive OP to assemble an integer object X. Print OP at the
2713 start of the line, followed immediately by the value of X. */
2714
2715void
2716assemble_integer_with_op (const char *op, rtx x)
2717{
2718 fputs (op, asm_out_file);
2719 output_addr_const (asm_out_file, x);
2720 fputc ('\n', asm_out_file);
2721}
2722
2723/* The default implementation of the asm_out.integer target hook. */
2724
2725bool
2726default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2727 unsigned int size ATTRIBUTE_UNUSED,
2728 int aligned_p ATTRIBUTE_UNUSED)
2729{
2730 const char *op = integer_asm_op (size, aligned_p);
2731 /* Avoid GAS bugs for large values. Specifically negative values whose
2732 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2733 if (size > UNITS_PER_WORD && size > POINTER_SIZE_UNITS)
2734 return false;
2735 return op && (assemble_integer_with_op (op, x), true);
2736}
2737
2738/* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2739 the alignment of the integer in bits. Return 1 if we were able to output
2740 the constant, otherwise 0. We must be able to output the constant,
2741 if FORCE is nonzero. */
2742
2743bool
2744assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2745{
2746 int aligned_p;
2747
2748 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2749
2750 /* See if the target hook can handle this kind of object. */
2751 if (targetm.asm_out.integer (x, size, aligned_p))
2752 return true;
2753
2754 /* If the object is a multi-byte one, try splitting it up. Split
2755 it into words it if is multi-word, otherwise split it into bytes. */
2756 if (size > 1)
2757 {
2758 machine_mode omode, imode;
2759 unsigned int subalign;
2760 unsigned int subsize, i;
2761 enum mode_class mclass;
2762
2763 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2764 subalign = MIN (align, subsize * BITS_PER_UNIT);
2765 if (GET_CODE (x) == CONST_FIXED)
2766 mclass = GET_MODE_CLASS (GET_MODE (x));
2767 else
2768 mclass = MODE_INT;
2769
2770 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2771 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2772
2773 for (i = 0; i < size; i += subsize)
2774 {
2775 rtx partial = simplify_subreg (omode, x, imode, i);
2776 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2777 break;
2778 }
2779 if (i == size)
2780 return true;
2781
2782 /* If we've printed some of it, but not all of it, there's no going
2783 back now. */
2784 gcc_assert (!i);
2785 }
2786
2787 gcc_assert (!force);
2788
2789 return false;
2790}
2791\f
2792void
2793assemble_real (REAL_VALUE_TYPE d, machine_mode mode, unsigned int align)
2794{
2795 long data[4] = {0, 0, 0, 0};
2796 int i;
2797 int bitsize, nelts, nunits, units_per;
2798
2799 /* This is hairy. We have a quantity of known size. real_to_target
2800 will put it into an array of *host* longs, 32 bits per element
2801 (even if long is more than 32 bits). We need to determine the
2802 number of array elements that are occupied (nelts) and the number
2803 of *target* min-addressable units that will be occupied in the
2804 object file (nunits). We cannot assume that 32 divides the
2805 mode's bitsize (size * BITS_PER_UNIT) evenly.
2806
2807 size * BITS_PER_UNIT is used here to make sure that padding bits
2808 (which might appear at either end of the value; real_to_target
2809 will include the padding bits in its output array) are included. */
2810
2811 nunits = GET_MODE_SIZE (mode);
2812 bitsize = nunits * BITS_PER_UNIT;
2813 nelts = CEIL (bitsize, 32);
2814 units_per = 32 / BITS_PER_UNIT;
2815
2816 real_to_target (data, &d, mode);
2817
2818 /* Put out the first word with the specified alignment. */
2819 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2820 nunits -= units_per;
2821
2822 /* Subsequent words need only 32-bit alignment. */
2823 align = min_align (align, 32);
2824
2825 for (i = 1; i < nelts; i++)
2826 {
2827 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2828 nunits -= units_per;
2829 }
2830}
2831\f
2832/* Given an expression EXP with a constant value,
2833 reduce it to the sum of an assembler symbol and an integer.
2834 Store them both in the structure *VALUE.
2835 EXP must be reducible. */
2836
2837struct addr_const {
2838 rtx base;
2839 HOST_WIDE_INT offset;
2840};
2841
2842static void
2843decode_addr_const (tree exp, struct addr_const *value)
2844{
2845 tree target = TREE_OPERAND (exp, 0);
2846 int offset = 0;
2847 rtx x;
2848
2849 while (1)
2850 {
2851 if (TREE_CODE (target) == COMPONENT_REF
2852 && tree_fits_shwi_p (byte_position (TREE_OPERAND (target, 1))))
2853 {
2854 offset += int_byte_position (TREE_OPERAND (target, 1));
2855 target = TREE_OPERAND (target, 0);
2856 }
2857 else if (TREE_CODE (target) == ARRAY_REF
2858 || TREE_CODE (target) == ARRAY_RANGE_REF)
2859 {
2860 offset += (tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (target)))
2861 * tree_to_shwi (TREE_OPERAND (target, 1)));
2862 target = TREE_OPERAND (target, 0);
2863 }
2864 else if (TREE_CODE (target) == MEM_REF
2865 && TREE_CODE (TREE_OPERAND (target, 0)) == ADDR_EXPR)
2866 {
2867 offset += mem_ref_offset (target).to_short_addr ();
2868 target = TREE_OPERAND (TREE_OPERAND (target, 0), 0);
2869 }
2870 else if (TREE_CODE (target) == INDIRECT_REF
2871 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2872 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2873 == ADDR_EXPR)
2874 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2875 else
2876 break;
2877 }
2878
2879 switch (TREE_CODE (target))
2880 {
2881 case VAR_DECL:
2882 case FUNCTION_DECL:
2883 x = DECL_RTL (target);
2884 break;
2885
2886 case LABEL_DECL:
2887 x = gen_rtx_MEM (FUNCTION_MODE,
2888 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2889 break;
2890
2891 case REAL_CST:
2892 case FIXED_CST:
2893 case STRING_CST:
2894 case COMPLEX_CST:
2895 case CONSTRUCTOR:
2896 case INTEGER_CST:
2897 x = output_constant_def (target, 1);
2898 break;
2899
2900 default:
2901 gcc_unreachable ();
2902 }
2903
2904 gcc_assert (MEM_P (x));
2905 x = XEXP (x, 0);
2906
2907 value->base = x;
2908 value->offset = offset;
2909}
2910\f
2911static GTY(()) hash_table<tree_descriptor_hasher> *const_desc_htab;
2912
2913static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2914
2915/* Constant pool accessor function. */
2916
2917hash_table<tree_descriptor_hasher> *
2918constant_pool_htab (void)
2919{
2920 return const_desc_htab;
2921}
2922
2923/* Compute a hash code for a constant expression. */
2924
2925hashval_t
2926tree_descriptor_hasher::hash (constant_descriptor_tree *ptr)
2927{
2928 return ptr->hash;
2929}
2930
2931static hashval_t
2932const_hash_1 (const tree exp)
2933{
2934 const char *p;
2935 hashval_t hi;
2936 int len, i;
2937 enum tree_code code = TREE_CODE (exp);
2938
2939 /* Either set P and LEN to the address and len of something to hash and
2940 exit the switch or return a value. */
2941
2942 switch (code)
2943 {
2944 case INTEGER_CST:
2945 p = (char *) &TREE_INT_CST_ELT (exp, 0);
2946 len = TREE_INT_CST_NUNITS (exp) * sizeof (HOST_WIDE_INT);
2947 break;
2948
2949 case REAL_CST:
2950 return real_hash (TREE_REAL_CST_PTR (exp));
2951
2952 case FIXED_CST:
2953 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2954
2955 case STRING_CST:
2956 p = TREE_STRING_POINTER (exp);
2957 len = TREE_STRING_LENGTH (exp);
2958 break;
2959
2960 case COMPLEX_CST:
2961 return (const_hash_1 (TREE_REALPART (exp)) * 5
2962 + const_hash_1 (TREE_IMAGPART (exp)));
2963
2964 case VECTOR_CST:
2965 {
2966 unsigned i;
2967
2968 hi = 7 + VECTOR_CST_NELTS (exp);
2969
2970 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
2971 hi = hi * 563 + const_hash_1 (VECTOR_CST_ELT (exp, i));
2972
2973 return hi;
2974 }
2975
2976 case CONSTRUCTOR:
2977 {
2978 unsigned HOST_WIDE_INT idx;
2979 tree value;
2980
2981 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2982
2983 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2984 if (value)
2985 hi = hi * 603 + const_hash_1 (value);
2986
2987 return hi;
2988 }
2989
2990 case ADDR_EXPR:
2991 case FDESC_EXPR:
2992 {
2993 struct addr_const value;
2994
2995 decode_addr_const (exp, &value);
2996 switch (GET_CODE (value.base))
2997 {
2998 case SYMBOL_REF:
2999 /* Don't hash the address of the SYMBOL_REF;
3000 only use the offset and the symbol name. */
3001 hi = value.offset;
3002 p = XSTR (value.base, 0);
3003 for (i = 0; p[i] != 0; i++)
3004 hi = ((hi * 613) + (unsigned) (p[i]));
3005 break;
3006
3007 case LABEL_REF:
3008 hi = (value.offset
3009 + CODE_LABEL_NUMBER (LABEL_REF_LABEL (value.base)) * 13);
3010 break;
3011
3012 default:
3013 gcc_unreachable ();
3014 }
3015 }
3016 return hi;
3017
3018 case PLUS_EXPR:
3019 case POINTER_PLUS_EXPR:
3020 case MINUS_EXPR:
3021 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
3022 + const_hash_1 (TREE_OPERAND (exp, 1)));
3023
3024 CASE_CONVERT:
3025 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
3026
3027 default:
3028 /* A language specific constant. Just hash the code. */
3029 return code;
3030 }
3031
3032 /* Compute hashing function. */
3033 hi = len;
3034 for (i = 0; i < len; i++)
3035 hi = ((hi * 613) + (unsigned) (p[i]));
3036
3037 return hi;
3038}
3039
3040/* Wrapper of compare_constant, for the htab interface. */
3041bool
3042tree_descriptor_hasher::equal (constant_descriptor_tree *c1,
3043 constant_descriptor_tree *c2)
3044{
3045 if (c1->hash != c2->hash)
3046 return 0;
3047 return compare_constant (c1->value, c2->value);
3048}
3049
3050/* Compare t1 and t2, and return 1 only if they are known to result in
3051 the same bit pattern on output. */
3052
3053static int
3054compare_constant (const tree t1, const tree t2)
3055{
3056 enum tree_code typecode;
3057
3058 if (t1 == NULL_TREE)
3059 return t2 == NULL_TREE;
3060 if (t2 == NULL_TREE)
3061 return 0;
3062
3063 if (TREE_CODE (t1) != TREE_CODE (t2))
3064 return 0;
3065
3066 switch (TREE_CODE (t1))
3067 {
3068 case INTEGER_CST:
3069 /* Integer constants are the same only if the same width of type. */
3070 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3071 return 0;
3072 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3073 return 0;
3074 return tree_int_cst_equal (t1, t2);
3075
3076 case REAL_CST:
3077 /* Real constants are the same only if the same width of type. */
3078 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3079 return 0;
3080
3081 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3082
3083 case FIXED_CST:
3084 /* Fixed constants are the same only if the same width of type. */
3085 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3086 return 0;
3087
3088 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3089
3090 case STRING_CST:
3091 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3092 return 0;
3093
3094 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3095 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3096 TREE_STRING_LENGTH (t1)));
3097
3098 case COMPLEX_CST:
3099 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3100 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3101
3102 case VECTOR_CST:
3103 {
3104 unsigned i;
3105
3106 if (VECTOR_CST_NELTS (t1) != VECTOR_CST_NELTS (t2))
3107 return 0;
3108
3109 for (i = 0; i < VECTOR_CST_NELTS (t1); ++i)
3110 if (!compare_constant (VECTOR_CST_ELT (t1, i),
3111 VECTOR_CST_ELT (t2, i)))
3112 return 0;
3113
3114 return 1;
3115 }
3116
3117 case CONSTRUCTOR:
3118 {
3119 vec<constructor_elt, va_gc> *v1, *v2;
3120 unsigned HOST_WIDE_INT idx;
3121
3122 typecode = TREE_CODE (TREE_TYPE (t1));
3123 if (typecode != TREE_CODE (TREE_TYPE (t2)))
3124 return 0;
3125
3126 if (typecode == ARRAY_TYPE)
3127 {
3128 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3129 /* For arrays, check that the sizes all match. */
3130 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3131 || size_1 == -1
3132 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
3133 return 0;
3134 }
3135 else
3136 {
3137 /* For record and union constructors, require exact type
3138 equality. */
3139 if (TREE_TYPE (t1) != TREE_TYPE (t2))
3140 return 0;
3141 }
3142
3143 v1 = CONSTRUCTOR_ELTS (t1);
3144 v2 = CONSTRUCTOR_ELTS (t2);
3145 if (vec_safe_length (v1) != vec_safe_length (v2))
3146 return 0;
3147
3148 for (idx = 0; idx < vec_safe_length (v1); ++idx)
3149 {
3150 constructor_elt *c1 = &(*v1)[idx];
3151 constructor_elt *c2 = &(*v2)[idx];
3152
3153 /* Check that each value is the same... */
3154 if (!compare_constant (c1->value, c2->value))
3155 return 0;
3156 /* ... and that they apply to the same fields! */
3157 if (typecode == ARRAY_TYPE)
3158 {
3159 if (!compare_constant (c1->index, c2->index))
3160 return 0;
3161 }
3162 else
3163 {
3164 if (c1->index != c2->index)
3165 return 0;
3166 }
3167 }
3168
3169 return 1;
3170 }
3171
3172 case ADDR_EXPR:
3173 case FDESC_EXPR:
3174 {
3175 struct addr_const value1, value2;
3176 enum rtx_code code;
3177 int ret;
3178
3179 decode_addr_const (t1, &value1);
3180 decode_addr_const (t2, &value2);
3181
3182 if (value1.offset != value2.offset)
3183 return 0;
3184
3185 code = GET_CODE (value1.base);
3186 if (code != GET_CODE (value2.base))
3187 return 0;
3188
3189 switch (code)
3190 {
3191 case SYMBOL_REF:
3192 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3193 break;
3194
3195 case LABEL_REF:
3196 ret = (CODE_LABEL_NUMBER (LABEL_REF_LABEL (value1.base))
3197 == CODE_LABEL_NUMBER (LABEL_REF_LABEL (value2.base)));
3198 break;
3199
3200 default:
3201 gcc_unreachable ();
3202 }
3203 return ret;
3204 }
3205
3206 case PLUS_EXPR:
3207 case POINTER_PLUS_EXPR:
3208 case MINUS_EXPR:
3209 case RANGE_EXPR:
3210 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3211 && compare_constant (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3212
3213 CASE_CONVERT:
3214 case VIEW_CONVERT_EXPR:
3215 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3216
3217 default:
3218 return 0;
3219 }
3220
3221 gcc_unreachable ();
3222}
3223\f
3224/* Return the section into which constant EXP should be placed. */
3225
3226static section *
3227get_constant_section (tree exp, unsigned int align)
3228{
3229 return targetm.asm_out.select_section (exp,
3230 compute_reloc_for_constant (exp),
3231 align);
3232}
3233
3234/* Return the size of constant EXP in bytes. */
3235
3236static HOST_WIDE_INT
3237get_constant_size (tree exp)
3238{
3239 HOST_WIDE_INT size;
3240
3241 size = int_size_in_bytes (TREE_TYPE (exp));
3242 if (TREE_CODE (exp) == STRING_CST)
3243 size = MAX (TREE_STRING_LENGTH (exp), size);
3244 return size;
3245}
3246
3247/* Subroutine of output_constant_def:
3248 No constant equal to EXP is known to have been output.
3249 Make a constant descriptor to enter EXP in the hash table.
3250 Assign the label number and construct RTL to refer to the
3251 constant's location in memory.
3252 Caller is responsible for updating the hash table. */
3253
3254static struct constant_descriptor_tree *
3255build_constant_desc (tree exp)
3256{
3257 struct constant_descriptor_tree *desc;
3258 rtx symbol, rtl;
3259 char label[256];
3260 int labelno;
3261 tree decl;
3262
3263 desc = ggc_alloc<constant_descriptor_tree> ();
3264 desc->value = exp;
3265
3266 /* Create a string containing the label name, in LABEL. */
3267 labelno = const_labelno++;
3268 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3269
3270 /* Construct the VAR_DECL associated with the constant. */
3271 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3272 TREE_TYPE (exp));
3273 DECL_ARTIFICIAL (decl) = 1;
3274 DECL_IGNORED_P (decl) = 1;
3275 TREE_READONLY (decl) = 1;
3276 TREE_STATIC (decl) = 1;
3277 TREE_ADDRESSABLE (decl) = 1;
3278 /* We don't set the RTL yet as this would cause varpool to assume that the
3279 variable is referenced. Moreover, it would just be dropped in LTO mode.
3280 Instead we set the flag that will be recognized in make_decl_rtl. */
3281 DECL_IN_CONSTANT_POOL (decl) = 1;
3282 DECL_INITIAL (decl) = desc->value;
3283 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3284 architectures so use DATA_ALIGNMENT as well, except for strings. */
3285 if (TREE_CODE (exp) == STRING_CST)
3286 {
3287#ifdef CONSTANT_ALIGNMENT
3288 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3289#endif
3290 }
3291 else
3292 align_variable (decl, 0);
3293
3294 /* Now construct the SYMBOL_REF and the MEM. */
3295 if (use_object_blocks_p ())
3296 {
f09a3553
JM
3297 int align = (TREE_CODE (decl) == CONST_DECL
3298 || (TREE_CODE (decl) == VAR_DECL
3299 && DECL_IN_CONSTANT_POOL (decl))
3300 ? DECL_ALIGN (decl)
3301 : symtab_node::get (decl)->definition_alignment ());
3302 section *sect = get_constant_section (exp, align);
dda118e3
JM
3303 symbol = create_block_symbol (ggc_strdup (label),
3304 get_block_for_section (sect), -1);
3305 }
3306 else
3307 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3308 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3309 SET_SYMBOL_REF_DECL (symbol, decl);
3310 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3311
3312 rtl = gen_const_mem (TYPE_MODE (TREE_TYPE (exp)), symbol);
3313 set_mem_attributes (rtl, exp, 1);
3314 set_mem_alias_set (rtl, 0);
3315
3316 /* We cannot share RTX'es in pool entries.
3317 Mark this piece of RTL as required for unsharing. */
3318 RTX_FLAG (rtl, used) = 1;
3319
3320 /* Set flags or add text to the name to record information, such as
3321 that it is a local symbol. If the name is changed, the macro
3322 ASM_OUTPUT_LABELREF will have to know how to strip this
3323 information. This call might invalidate our local variable
3324 SYMBOL; we can't use it afterward. */
3325 targetm.encode_section_info (exp, rtl, true);
3326
3327 desc->rtl = rtl;
3328
3329 return desc;
3330}
3331
3332/* Return an rtx representing a reference to constant data in memory
3333 for the constant expression EXP.
3334
3335 If assembler code for such a constant has already been output,
3336 return an rtx to refer to it.
3337 Otherwise, output such a constant in memory
3338 and generate an rtx for it.
3339
3340 If DEFER is nonzero, this constant can be deferred and output only
3341 if referenced in the function after all optimizations.
3342
3343 `const_desc_table' records which constants already have label strings. */
3344
3345rtx
3346output_constant_def (tree exp, int defer)
3347{
3348 struct constant_descriptor_tree *desc;
3349 struct constant_descriptor_tree key;
3350
3351 /* Look up EXP in the table of constant descriptors. If we didn't find
3352 it, create a new one. */
3353 key.value = exp;
3354 key.hash = const_hash_1 (exp);
3355 constant_descriptor_tree **loc
3356 = const_desc_htab->find_slot_with_hash (&key, key.hash, INSERT);
3357
3358 desc = *loc;
3359 if (desc == 0)
3360 {
3361 desc = build_constant_desc (exp);
3362 desc->hash = key.hash;
3363 *loc = desc;
3364 }
3365
3366 maybe_output_constant_def_contents (desc, defer);
3367 return desc->rtl;
3368}
3369
3370/* Subroutine of output_constant_def: Decide whether or not we need to
3371 output the constant DESC now, and if so, do it. */
3372static void
3373maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3374 int defer)
3375{
3376 rtx symbol = XEXP (desc->rtl, 0);
3377 tree exp = desc->value;
3378
3379 if (flag_syntax_only)
3380 return;
3381
3382 if (TREE_ASM_WRITTEN (exp))
3383 /* Already output; don't do it again. */
3384 return;
3385
3386 /* We can always defer constants as long as the context allows
3387 doing so. */
3388 if (defer)
3389 {
3390 /* Increment n_deferred_constants if it exists. It needs to be at
3391 least as large as the number of constants actually referred to
3392 by the function. If it's too small we'll stop looking too early
3393 and fail to emit constants; if it's too large we'll only look
3394 through the entire function when we could have stopped earlier. */
3395 if (cfun)
3396 n_deferred_constants++;
3397 return;
3398 }
3399
3400 output_constant_def_contents (symbol);
3401}
3402
3403/* Subroutine of output_constant_def_contents. Output the definition
3404 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3405 constant's alignment in bits. */
3406
3407static void
3408assemble_constant_contents (tree exp, const char *label, unsigned int align)
3409{
3410 HOST_WIDE_INT size;
3411
3412 size = get_constant_size (exp);
3413
3414 /* Do any machine/system dependent processing of the constant. */
3415 targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3416
3417 /* Output the value of EXP. */
3418 output_constant (exp, size, align);
3419
3420 targetm.asm_out.decl_end ();
3421}
3422
3423/* We must output the constant data referred to by SYMBOL; do so. */
3424
3425static void
3426output_constant_def_contents (rtx symbol)
3427{
3428 tree decl = SYMBOL_REF_DECL (symbol);
3429 tree exp = DECL_INITIAL (decl);
dda118e3
JM
3430 bool asan_protected = false;
3431
3432 /* Make sure any other constants whose addresses appear in EXP
3433 are assigned label numbers. */
3434 output_addressed_constants (exp);
3435
3436 /* We are no longer deferring this constant. */
3437 TREE_ASM_WRITTEN (decl) = TREE_ASM_WRITTEN (exp) = 1;
3438
3439 if ((flag_sanitize & SANITIZE_ADDRESS)
3440 && TREE_CODE (exp) == STRING_CST
3441 && asan_protect_global (exp))
3442 {
3443 asan_protected = true;
3444 DECL_ALIGN (decl) = MAX (DECL_ALIGN (decl),
3445 ASAN_RED_ZONE_SIZE * BITS_PER_UNIT);
3446 }
3447
3448 /* If the constant is part of an object block, make sure that the
3449 decl has been positioned within its block, but do not write out
3450 its definition yet. output_object_blocks will do that later. */
3451 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3452 place_block_symbol (symbol);
3453 else
3454 {
f09a3553
JM
3455 int align = (TREE_CODE (decl) == CONST_DECL
3456 || (TREE_CODE (decl) == VAR_DECL
3457 && DECL_IN_CONSTANT_POOL (decl))
3458 ? DECL_ALIGN (decl)
3459 : symtab_node::get (decl)->definition_alignment ());
dda118e3
JM
3460 switch_to_section (get_constant_section (exp, align));
3461 if (align > BITS_PER_UNIT)
3462 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3463 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3464 if (asan_protected)
3465 {
3466 HOST_WIDE_INT size = get_constant_size (exp);
3467 assemble_zeros (asan_red_zone_size (size));
3468 }
3469 }
3470}
3471
3472/* Look up EXP in the table of constant descriptors. Return the rtl
3473 if it has been emitted, else null. */
3474
3475rtx
3476lookup_constant_def (tree exp)
3477{
3478 struct constant_descriptor_tree key;
3479
3480 key.value = exp;
3481 key.hash = const_hash_1 (exp);
3482 constant_descriptor_tree *desc
3483 = const_desc_htab->find_with_hash (&key, key.hash);
3484
3485 return (desc ? desc->rtl : NULL_RTX);
3486}
3487
3488/* Return a tree representing a reference to constant data in memory
3489 for the constant expression EXP.
3490
3491 This is the counterpart of output_constant_def at the Tree level. */
3492
3493tree
3494tree_output_constant_def (tree exp)
3495{
3496 struct constant_descriptor_tree *desc, key;
3497 tree decl;
3498
3499 /* Look up EXP in the table of constant descriptors. If we didn't find
3500 it, create a new one. */
3501 key.value = exp;
3502 key.hash = const_hash_1 (exp);
3503 constant_descriptor_tree **loc
3504 = const_desc_htab->find_slot_with_hash (&key, key.hash, INSERT);
3505
3506 desc = *loc;
3507 if (desc == 0)
3508 {
3509 desc = build_constant_desc (exp);
3510 desc->hash = key.hash;
3511 *loc = desc;
3512 }
3513
3514 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3515 varpool_node::finalize_decl (decl);
3516 return decl;
3517}
3518\f
3519struct GTY((chain_next ("%h.next"), for_user)) constant_descriptor_rtx {
3520 struct constant_descriptor_rtx *next;
3521 rtx mem;
3522 rtx sym;
3523 rtx constant;
3524 HOST_WIDE_INT offset;
3525 hashval_t hash;
3526 machine_mode mode;
3527 unsigned int align;
3528 int labelno;
3529 int mark;
3530};
3531
3532struct const_rtx_desc_hasher : ggc_hasher<constant_descriptor_rtx *>
3533{
3534 static hashval_t hash (constant_descriptor_rtx *);
3535 static bool equal (constant_descriptor_rtx *, constant_descriptor_rtx *);
3536};
3537
3538/* Used in the hash tables to avoid outputting the same constant
3539 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3540 are output once per function, not once per file. */
3541/* ??? Only a few targets need per-function constant pools. Most
3542 can use one per-file pool. Should add a targetm bit to tell the
3543 difference. */
3544
3545struct GTY(()) rtx_constant_pool {
3546 /* Pointers to first and last constant in pool, as ordered by offset. */
3547 struct constant_descriptor_rtx *first;
3548 struct constant_descriptor_rtx *last;
3549
3550 /* Hash facility for making memory-constants from constant rtl-expressions.
3551 It is used on RISC machines where immediate integer arguments and
3552 constant addresses are restricted so that such constants must be stored
3553 in memory. */
3554 hash_table<const_rtx_desc_hasher> *const_rtx_htab;
3555
3556 /* Current offset in constant pool (does not include any
3557 machine-specific header). */
3558 HOST_WIDE_INT offset;
3559};
3560
3561/* Hash and compare functions for const_rtx_htab. */
3562
3563hashval_t
3564const_rtx_desc_hasher::hash (constant_descriptor_rtx *desc)
3565{
3566 return desc->hash;
3567}
3568
3569bool
3570const_rtx_desc_hasher::equal (constant_descriptor_rtx *x,
3571 constant_descriptor_rtx *y)
3572{
3573 if (x->mode != y->mode)
3574 return 0;
3575 return rtx_equal_p (x->constant, y->constant);
3576}
3577
3578/* Hash one component of a constant. */
3579
3580static hashval_t
3581const_rtx_hash_1 (const_rtx x)
3582{
3583 unsigned HOST_WIDE_INT hwi;
3584 machine_mode mode;
3585 enum rtx_code code;
3586 hashval_t h;
3587 int i;
3588
3589 code = GET_CODE (x);
3590 mode = GET_MODE (x);
3591 h = (hashval_t) code * 1048573 + mode;
3592
3593 switch (code)
3594 {
3595 case CONST_INT:
3596 hwi = INTVAL (x);
3597
3598 fold_hwi:
3599 {
3600 int shift = sizeof (hashval_t) * CHAR_BIT;
3601 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3602
3603 h ^= (hashval_t) hwi;
3604 for (i = 1; i < n; ++i)
3605 {
3606 hwi >>= shift;
3607 h ^= (hashval_t) hwi;
3608 }
3609 }
3610 break;
3611
3612 case CONST_WIDE_INT:
3613 hwi = GET_MODE_PRECISION (mode);
3614 {
3615 for (i = 0; i < CONST_WIDE_INT_NUNITS (x); i++)
3616 hwi ^= CONST_WIDE_INT_ELT (x, i);
3617 goto fold_hwi;
3618 }
3619
3620 case CONST_DOUBLE:
3621 if (TARGET_SUPPORTS_WIDE_INT == 0 && mode == VOIDmode)
3622 {
3623 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3624 goto fold_hwi;
3625 }
3626 else
3627 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3628 break;
3629
3630 case CONST_FIXED:
3631 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3632 break;
3633
3634 case SYMBOL_REF:
3635 h ^= htab_hash_string (XSTR (x, 0));
3636 break;
3637
3638 case LABEL_REF:
3639 h = h * 251 + CODE_LABEL_NUMBER (LABEL_REF_LABEL (x));
3640 break;
3641
3642 case UNSPEC:
3643 case UNSPEC_VOLATILE:
3644 h = h * 251 + XINT (x, 1);
3645 break;
3646
3647 default:
3648 break;
3649 }
3650
3651 return h;
3652}
3653
3654/* Compute a hash value for X, which should be a constant. */
3655
3656static hashval_t
3657const_rtx_hash (rtx x)
3658{
3659 hashval_t h = 0;
3660 subrtx_iterator::array_type array;
3661 FOR_EACH_SUBRTX (iter, array, x, ALL)
3662 h = h * 509 + const_rtx_hash_1 (*iter);
3663 return h;
3664}
3665
3666\f
3667/* Create and return a new rtx constant pool. */
3668
3669static struct rtx_constant_pool *
3670create_constant_pool (void)
3671{
3672 struct rtx_constant_pool *pool;
3673
3674 pool = ggc_alloc<rtx_constant_pool> ();
3675 pool->const_rtx_htab = hash_table<const_rtx_desc_hasher>::create_ggc (31);
3676 pool->first = NULL;
3677 pool->last = NULL;
3678 pool->offset = 0;
3679 return pool;
3680}
3681
3682/* Initialize constant pool hashing for a new function. */
3683
3684void
3685init_varasm_status (void)
3686{
3687 crtl->varasm.pool = create_constant_pool ();
3688 crtl->varasm.deferred_constants = 0;
3689}
3690\f
3691/* Given a MINUS expression, simplify it if both sides
3692 include the same symbol. */
3693
3694rtx
3695simplify_subtraction (rtx x)
3696{
3697 rtx r = simplify_rtx (x);
3698 return r ? r : x;
3699}
3700\f
3701/* Given a constant rtx X, make (or find) a memory constant for its value
3702 and return a MEM rtx to refer to it in memory. */
3703
3704rtx
3705force_const_mem (machine_mode mode, rtx x)
3706{
3707 struct constant_descriptor_rtx *desc, tmp;
3708 struct rtx_constant_pool *pool;
3709 char label[256];
3710 rtx def, symbol;
3711 hashval_t hash;
3712 unsigned int align;
3713 constant_descriptor_rtx **slot;
3714
3715 /* If we're not allowed to drop X into the constant pool, don't. */
3716 if (targetm.cannot_force_const_mem (mode, x))
3717 return NULL_RTX;
3718
3719 /* Record that this function has used a constant pool entry. */
3720 crtl->uses_const_pool = 1;
3721
3722 /* Decide which pool to use. */
3723 pool = (targetm.use_blocks_for_constant_p (mode, x)
3724 ? shared_constant_pool
3725 : crtl->varasm.pool);
3726
3727 /* Lookup the value in the hashtable. */
3728 tmp.constant = x;
3729 tmp.mode = mode;
3730 hash = const_rtx_hash (x);
3731 slot = pool->const_rtx_htab->find_slot_with_hash (&tmp, hash, INSERT);
3732 desc = *slot;
3733
3734 /* If the constant was already present, return its memory. */
3735 if (desc)
3736 return copy_rtx (desc->mem);
3737
3738 /* Otherwise, create a new descriptor. */
3739 desc = ggc_alloc<constant_descriptor_rtx> ();
3740 *slot = desc;
3741
3742 /* Align the location counter as required by EXP's data type. */
3743 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3744#ifdef CONSTANT_ALIGNMENT
3745 {
3746 tree type = lang_hooks.types.type_for_mode (mode, 0);
3747 if (type != NULL_TREE)
3748 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3749 }
3750#endif
3751
3752 pool->offset += (align / BITS_PER_UNIT) - 1;
3753 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3754
3755 desc->next = NULL;
3756 desc->constant = copy_rtx (tmp.constant);
3757 desc->offset = pool->offset;
3758 desc->hash = hash;
3759 desc->mode = mode;
3760 desc->align = align;
3761 desc->labelno = const_labelno;
3762 desc->mark = 0;
3763
3764 pool->offset += GET_MODE_SIZE (mode);
3765 if (pool->last)
3766 pool->last->next = desc;
3767 else
3768 pool->first = pool->last = desc;
3769 pool->last = desc;
3770
3771 /* Create a string containing the label name, in LABEL. */
3772 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3773 ++const_labelno;
3774
3775 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3776 the constants pool. */
3777 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3778 {
3779 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3780 symbol = create_block_symbol (ggc_strdup (label),
3781 get_block_for_section (sect), -1);
3782 }
3783 else
3784 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3785 desc->sym = symbol;
3786 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3787 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3788 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3789
3790 /* Construct the MEM. */
3791 desc->mem = def = gen_const_mem (mode, symbol);
3792 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3793 set_mem_align (def, align);
3794
3795 /* If we're dropping a label to the constant pool, make sure we
3796 don't delete it. */
3797 if (GET_CODE (x) == LABEL_REF)
3798 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3799
3800 return copy_rtx (def);
3801}
3802\f
3803/* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3804
3805rtx
3806get_pool_constant (const_rtx addr)
3807{
3808 return SYMBOL_REF_CONSTANT (addr)->constant;
3809}
3810
3811/* Given a constant pool SYMBOL_REF, return the corresponding constant
3812 and whether it has been output or not. */
3813
3814rtx
3815get_pool_constant_mark (rtx addr, bool *pmarked)
3816{
3817 struct constant_descriptor_rtx *desc;
3818
3819 desc = SYMBOL_REF_CONSTANT (addr);
3820 *pmarked = (desc->mark != 0);
3821 return desc->constant;
3822}
3823
3824/* Similar, return the mode. */
3825
3826machine_mode
3827get_pool_mode (const_rtx addr)
3828{
3829 return SYMBOL_REF_CONSTANT (addr)->mode;
3830}
3831
3832/* Return the size of the constant pool. */
3833
3834int
3835get_pool_size (void)
3836{
3837 return crtl->varasm.pool->offset;
3838}
3839\f
3840/* Worker function for output_constant_pool_1. Emit assembly for X
3841 in MODE with known alignment ALIGN. */
3842
3843static void
3844output_constant_pool_2 (machine_mode mode, rtx x, unsigned int align)
3845{
3846 switch (GET_MODE_CLASS (mode))
3847 {
3848 case MODE_FLOAT:
3849 case MODE_DECIMAL_FLOAT:
3850 {
3851 REAL_VALUE_TYPE r;
3852
3853 gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x));
3854 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3855 assemble_real (r, mode, align);
3856 break;
3857 }
3858
3859 case MODE_INT:
3860 case MODE_PARTIAL_INT:
3861 case MODE_FRACT:
3862 case MODE_UFRACT:
3863 case MODE_ACCUM:
3864 case MODE_UACCUM:
3865 case MODE_POINTER_BOUNDS:
3866 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3867 break;
3868
3869 case MODE_VECTOR_FLOAT:
3870 case MODE_VECTOR_INT:
3871 case MODE_VECTOR_FRACT:
3872 case MODE_VECTOR_UFRACT:
3873 case MODE_VECTOR_ACCUM:
3874 case MODE_VECTOR_UACCUM:
3875 {
3876 int i, units;
3877 machine_mode submode = GET_MODE_INNER (mode);
3878 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3879
3880 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3881 units = CONST_VECTOR_NUNITS (x);
3882
3883 for (i = 0; i < units; i++)
3884 {
3885 rtx elt = CONST_VECTOR_ELT (x, i);
3886 output_constant_pool_2 (submode, elt, i ? subalign : align);
3887 }
3888 }
3889 break;
3890
3891 default:
3892 gcc_unreachable ();
3893 }
3894}
3895
3896/* Worker function for output_constant_pool. Emit constant DESC,
3897 giving it ALIGN bits of alignment. */
3898
3899static void
3900output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3901 unsigned int align)
3902{
3903 rtx x, tmp;
3904
3905 x = desc->constant;
3906
3907 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3908 whose CODE_LABEL has been deleted. This can occur if a jump table
3909 is eliminated by optimization. If so, write a constant of zero
3910 instead. Note that this can also happen by turning the
3911 CODE_LABEL into a NOTE. */
3912 /* ??? This seems completely and utterly wrong. Certainly it's
3913 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3914 functioning even with rtx_insn::deleted and friends. */
3915
3916 tmp = x;
3917 switch (GET_CODE (tmp))
3918 {
3919 case CONST:
3920 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3921 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3922 break;
3923 tmp = XEXP (XEXP (tmp, 0), 0);
3924 /* FALLTHRU */
3925
3926 case LABEL_REF:
3927 tmp = LABEL_REF_LABEL (tmp);
3928 gcc_assert (!as_a<rtx_insn *> (tmp)->deleted ());
3929 gcc_assert (!NOTE_P (tmp)
3930 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3931 break;
3932
3933 default:
3934 break;
3935 }
3936
3937#ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3938 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3939 align, desc->labelno, done);
3940#endif
3941
3942 assemble_align (align);
3943
3944 /* Output the label. */
3945 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3946
3947 /* Output the data. */
3948 output_constant_pool_2 (desc->mode, x, align);
3949
3950 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3951 sections have proper size. */
3952 if (align > GET_MODE_BITSIZE (desc->mode)
3953 && in_section
3954 && (in_section->common.flags & SECTION_MERGE))
3955 assemble_align (align);
3956
3957#ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3958 done:
3959#endif
3960 return;
3961}
3962
3963/* Mark all constants that are referenced by SYMBOL_REFs in X.