Fix mis-fired error on extern alias
[official-gcc.git] / main / gcc / varasm.c
blobb921788af5a5de21ff3e750c65759090af180017
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010, 2011 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
30 #include "config.h"
31 #include "system.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #include "rtl.h"
35 #include "tree.h"
36 #include "flags.h"
37 #include "function.h"
38 #include "expr.h"
39 #include "hard-reg-set.h"
40 #include "regs.h"
41 #include "output.h"
42 #include "diagnostic-core.h"
43 #include "hashtab.h"
44 #include "ggc.h"
45 #include "langhooks.h"
46 #include "tm_p.h"
47 #include "debug.h"
48 #include "target.h"
49 #include "common/common-target.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
52 #include "cgraph.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
56 #include "pointer-set.h"
57 #include "l-ipo.h"
59 #ifdef XCOFF_DEBUGGING_INFO
60 #include "xcoffout.h" /* Needed for external data
61 declarations for e.g. AIX 4.x. */
62 #endif
64 /* The (assembler) name of the first globally-visible object output. */
65 extern GTY(()) const char *first_global_object_name;
66 extern GTY(()) const char *weak_global_object_name;
68 const char *first_global_object_name;
69 const char *weak_global_object_name;
71 struct addr_const;
72 struct constant_descriptor_rtx;
73 struct rtx_constant_pool;
75 #define n_deferred_constants (crtl->varasm.deferred_constants)
77 /* Number for making the label on the next
78 constant that is stored in memory. */
80 static GTY(()) int const_labelno;
82 /* Carry information from ASM_DECLARE_OBJECT_NAME
83 to ASM_FINISH_DECLARE_OBJECT. */
85 int size_directive_output;
87 /* The last decl for which assemble_variable was called,
88 if it did ASM_DECLARE_OBJECT_NAME.
89 If the last call to assemble_variable didn't do that,
90 this holds 0. */
92 tree last_assemble_variable_decl;
94 /* The following global variable indicates if the first basic block
95 in a function belongs to the cold partition or not. */
97 bool first_function_block_is_cold;
99 /* We give all constants their own alias set. Perhaps redundant with
100 MEM_READONLY_P, but pre-dates it. */
102 static alias_set_type const_alias_set;
104 /* Whether we saw any functions with no_split_stack. */
106 static bool saw_no_split_stack;
108 static const char *strip_reg_name (const char *);
109 static int contains_pointers_p (tree);
110 #ifdef ASM_OUTPUT_EXTERNAL
111 static bool incorporeal_function_p (tree);
112 #endif
113 static void decode_addr_const (tree, struct addr_const *);
114 static hashval_t const_desc_hash (const void *);
115 static int const_desc_eq (const void *, const void *);
116 static hashval_t const_hash_1 (const tree);
117 static int compare_constant (const tree, const tree);
118 static tree copy_constant (tree);
119 static void output_constant_def_contents (rtx);
120 static void output_addressed_constants (tree);
121 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
122 static unsigned min_align (unsigned, unsigned);
123 static void globalize_decl (tree);
124 static bool decl_readonly_section_1 (enum section_category);
125 #ifdef BSS_SECTION_ASM_OP
126 #ifdef ASM_OUTPUT_ALIGNED_BSS
127 static void asm_output_aligned_bss (FILE *, tree, const char *,
128 unsigned HOST_WIDE_INT, int)
129 ATTRIBUTE_UNUSED;
130 #endif
131 #endif /* BSS_SECTION_ASM_OP */
132 static void mark_weak (tree);
133 static void output_constant_pool (const char *, tree);
135 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
136 section *text_section;
137 section *data_section;
138 section *readonly_data_section;
139 section *sdata_section;
140 section *ctors_section;
141 section *dtors_section;
142 section *bss_section;
143 section *sbss_section;
145 /* Various forms of common section. All are guaranteed to be nonnull. */
146 section *tls_comm_section;
147 section *comm_section;
148 section *lcomm_section;
150 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
151 May be null. */
152 section *bss_noswitch_section;
154 /* The section that holds the main exception table, when known. The section
155 is set either by the target's init_sections hook or by the first call to
156 switch_to_exception_section. */
157 section *exception_section;
159 /* The section that holds the DWARF2 frame unwind information, when known.
160 The section is set either by the target's init_sections hook or by the
161 first call to switch_to_eh_frame_section. */
162 section *eh_frame_section;
164 /* asm_out_file's current section. This is NULL if no section has yet
165 been selected or if we lose track of what the current section is. */
166 section *in_section;
168 /* True if code for the current function is currently being directed
169 at the cold section. */
170 bool in_cold_section_p;
172 /* A linked list of all the unnamed sections. */
173 static GTY(()) section *unnamed_sections;
175 /* Return a nonzero value if DECL has a section attribute. */
176 #define IN_NAMED_SECTION(DECL) \
177 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
178 && DECL_SECTION_NAME (DECL) != NULL_TREE)
180 /* Hash table of named sections. */
181 static GTY((param_is (section))) htab_t section_htab;
183 /* A table of object_blocks, indexed by section. */
184 static GTY((param_is (struct object_block))) htab_t object_block_htab;
186 /* The next number to use for internal anchor labels. */
187 static GTY(()) int anchor_labelno;
189 /* A pool of constants that can be shared between functions. */
190 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
192 /* Helper routines for maintaining section_htab. */
194 static int
195 section_entry_eq (const void *p1, const void *p2)
197 const section *old = (const section *) p1;
198 const char *new_name = (const char *) p2;
200 return strcmp (old->named.name, new_name) == 0;
203 static hashval_t
204 section_entry_hash (const void *p)
206 const section *old = (const section *) p;
207 return htab_hash_string (old->named.name);
210 /* Return a hash value for section SECT. */
212 static hashval_t
213 hash_section (section *sect)
215 if (sect->common.flags & SECTION_NAMED)
216 return htab_hash_string (sect->named.name);
217 return sect->common.flags;
220 /* Helper routines for maintaining object_block_htab. */
222 static int
223 object_block_entry_eq (const void *p1, const void *p2)
225 const struct object_block *old = (const struct object_block *) p1;
226 const section *new_section = (const section *) p2;
228 return old->sect == new_section;
231 static hashval_t
232 object_block_entry_hash (const void *p)
234 const struct object_block *old = (const struct object_block *) p;
235 return hash_section (old->sect);
238 /* Return a new unnamed section with the given fields. */
240 section *
241 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
242 const void *data)
244 section *sect;
246 sect = ggc_alloc_section ();
247 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
248 sect->unnamed.callback = callback;
249 sect->unnamed.data = data;
250 sect->unnamed.next = unnamed_sections;
252 unnamed_sections = sect;
253 return sect;
256 /* Return a SECTION_NOSWITCH section with the given fields. */
258 static section *
259 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
261 section *sect;
263 sect = ggc_alloc_section ();
264 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
265 sect->noswitch.callback = callback;
267 return sect;
270 /* Return the named section structure associated with NAME. Create
271 a new section with the given fields if no such structure exists. */
273 section *
274 get_section (const char *name, unsigned int flags, tree decl)
276 section *sect, **slot;
278 slot = (section **)
279 htab_find_slot_with_hash (section_htab, name,
280 htab_hash_string (name), INSERT);
281 flags |= SECTION_NAMED;
282 if (*slot == NULL)
284 sect = ggc_alloc_section ();
285 sect->named.common.flags = flags;
286 sect->named.name = ggc_strdup (name);
287 sect->named.decl = decl;
288 *slot = sect;
290 else
292 sect = *slot;
293 if ((sect->common.flags & ~SECTION_DECLARED) != flags
294 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
296 /* It is fine if one of the section flags is
297 SECTION_WRITE | SECTION_RELRO and the other has none of these
298 flags (i.e. read-only) in named sections and either the
299 section hasn't been declared yet or has been declared as writable.
300 In that case just make sure the resulting flags are
301 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
302 relocations. */
303 if (((sect->common.flags ^ flags) & (SECTION_WRITE | SECTION_RELRO))
304 == (SECTION_WRITE | SECTION_RELRO)
305 && (sect->common.flags
306 & ~(SECTION_DECLARED | SECTION_WRITE | SECTION_RELRO))
307 == (flags & ~(SECTION_WRITE | SECTION_RELRO))
308 && ((sect->common.flags & SECTION_DECLARED) == 0
309 || (sect->common.flags & SECTION_WRITE)))
311 sect->common.flags |= (SECTION_WRITE | SECTION_RELRO);
312 return sect;
314 /* Sanity check user variables for flag changes. */
315 if (decl == 0)
316 decl = sect->named.decl;
317 gcc_assert (decl);
318 error ("%+D causes a section type conflict with %D",
319 decl, sect->named.decl);
320 if (decl != sect->named.decl)
321 inform (DECL_SOURCE_LOCATION (sect->named.decl),
322 "%qD was declared here", sect->named.decl);
323 /* Make sure we don't error about one section multiple times. */
324 sect->common.flags |= SECTION_OVERRIDE;
327 return sect;
330 /* Return true if the current compilation mode benefits from having
331 objects grouped into blocks. */
333 static bool
334 use_object_blocks_p (void)
336 return flag_section_anchors;
339 /* Return the object_block structure for section SECT. Create a new
340 structure if we haven't created one already. Return null if SECT
341 itself is null. */
343 static struct object_block *
344 get_block_for_section (section *sect)
346 struct object_block *block;
347 void **slot;
349 if (sect == NULL)
350 return NULL;
352 slot = htab_find_slot_with_hash (object_block_htab, sect,
353 hash_section (sect), INSERT);
354 block = (struct object_block *) *slot;
355 if (block == NULL)
357 block = ggc_alloc_cleared_object_block ();
358 block->sect = sect;
359 *slot = block;
361 return block;
364 /* Create a symbol with label LABEL and place it at byte offset
365 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
366 is not yet known. LABEL must be a garbage-collected string. */
368 static rtx
369 create_block_symbol (const char *label, struct object_block *block,
370 HOST_WIDE_INT offset)
372 rtx symbol;
373 unsigned int size;
375 /* Create the extended SYMBOL_REF. */
376 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
377 symbol = ggc_alloc_zone_rtx_def (size, &rtl_zone);
379 /* Initialize the normal SYMBOL_REF fields. */
380 memset (symbol, 0, size);
381 PUT_CODE (symbol, SYMBOL_REF);
382 PUT_MODE (symbol, Pmode);
383 XSTR (symbol, 0) = label;
384 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
386 /* Initialize the block_symbol stuff. */
387 SYMBOL_REF_BLOCK (symbol) = block;
388 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
390 return symbol;
393 /* Return a section with a particular name and with whatever SECTION_*
394 flags section_type_flags deems appropriate. The name of the section
395 is taken from NAME if nonnull, otherwise it is taken from DECL's
396 DECL_SECTION_NAME. DECL is the decl associated with the section
397 (see the section comment for details) and RELOC is as for
398 section_type_flags. */
400 section *
401 get_named_section (tree decl, const char *name, int reloc)
403 unsigned int flags;
405 gcc_assert (!decl || DECL_P (decl));
406 if (name == NULL)
407 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
409 flags = targetm.section_type_flags (decl, name, reloc);
411 return get_section (name, flags, decl);
414 /* If required, set DECL_SECTION_NAME to a unique name. */
416 void
417 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
418 int flag_function_or_data_sections)
420 if (DECL_SECTION_NAME (decl) == NULL_TREE
421 && targetm_common.have_named_sections
422 && (flag_function_or_data_sections
423 || DECL_ONE_ONLY (decl)))
425 targetm.asm_out.unique_section (decl, reloc);
426 DECL_HAS_IMPLICIT_SECTION_NAME_P (decl) = true;
430 #ifdef BSS_SECTION_ASM_OP
432 #ifdef ASM_OUTPUT_ALIGNED_BSS
434 /* Utility function for targets to use in implementing
435 ASM_OUTPUT_ALIGNED_BSS.
436 ??? It is believed that this function will work in most cases so such
437 support is localized here. */
439 static void
440 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
441 const char *name, unsigned HOST_WIDE_INT size,
442 int align)
444 switch_to_section (bss_section);
445 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
446 #ifdef ASM_DECLARE_OBJECT_NAME
447 last_assemble_variable_decl = decl;
448 ASM_DECLARE_OBJECT_NAME (file, name, decl);
449 #else
450 /* Standard thing is just output label for the object. */
451 ASM_OUTPUT_LABEL (file, name);
452 #endif /* ASM_DECLARE_OBJECT_NAME */
453 ASM_OUTPUT_SKIP (file, size ? size : 1);
456 #endif
458 #endif /* BSS_SECTION_ASM_OP */
460 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
461 /* Return the hot section for function DECL. Return text_section for
462 null DECLs. */
464 static section *
465 hot_function_section (tree decl)
467 if (decl != NULL_TREE
468 && DECL_SECTION_NAME (decl) != NULL_TREE
469 && targetm_common.have_named_sections)
470 return get_named_section (decl, NULL, 0);
471 else
472 return text_section;
474 #endif
476 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
477 is NULL.
479 When DECL_SECTION_NAME is non-NULL and it is implicit section and
480 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
481 concatenate the name with NAMED_SECTION_SUFFIX.
482 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
484 section *
485 get_named_text_section (tree decl,
486 const char *text_section_name,
487 const char *named_section_suffix)
489 if (decl && DECL_SECTION_NAME (decl))
491 if (named_section_suffix)
493 tree dsn = DECL_SECTION_NAME (decl);
494 const char *stripped_name;
495 char *name, *buffer;
497 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
498 memcpy (name, TREE_STRING_POINTER (dsn),
499 TREE_STRING_LENGTH (dsn) + 1);
501 stripped_name = targetm.strip_name_encoding (name);
503 buffer = ACONCAT ((stripped_name, named_section_suffix, NULL));
504 return get_named_section (decl, buffer, 0);
506 else if (DECL_HAS_IMPLICIT_SECTION_NAME_P (decl))
508 const char *name;
510 /* Do not try to split gnu_linkonce functions. This gets somewhat
511 slipperly. */
512 if (DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP)
513 return NULL;
514 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
515 name = targetm.strip_name_encoding (name);
516 return get_named_section (decl, ACONCAT ((text_section_name, ".",
517 name, NULL)), 0);
519 else
520 return NULL;
522 return get_named_section (decl, text_section_name, 0);
525 /* Choose named function section based on its frequency. */
527 section *
528 default_function_section (tree decl, enum node_frequency freq,
529 bool startup, bool exit)
531 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
532 /* Old GNU linkers have buggy --gc-section support, which sometimes
533 results in .gcc_except_table* sections being garbage collected. */
534 if (decl
535 && DECL_SECTION_NAME (decl)
536 && DECL_HAS_IMPLICIT_SECTION_NAME_P (decl))
537 return NULL;
538 #endif
540 if (!flag_reorder_functions
541 || !targetm_common.have_named_sections)
542 return NULL;
543 /* Startup code should go to startup subsection unless it is
544 unlikely executed (this happens especially with function splitting
545 where we can split away unnecesary parts of static constructors. */
546 if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
547 return get_named_text_section (decl, ".text.startup", NULL);
549 /* Similarly for exit. */
550 if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
551 return get_named_text_section (decl, ".text.exit", NULL);
553 /* Group cold functions together, similarly for hot code. */
554 switch (freq)
556 case NODE_FREQUENCY_UNLIKELY_EXECUTED:
557 return get_named_text_section (decl, ".text.unlikely", NULL);
558 case NODE_FREQUENCY_HOT:
559 return get_named_text_section (decl, ".text.hot", NULL);
560 default:
561 return NULL;
565 /* Return the section for function DECL.
567 If DECL is NULL_TREE, return the text section. We can be passed
568 NULL_TREE under some circumstances by dbxout.c at least.
570 If FORCE_COLD is true, return cold function section ignoring
571 the frequency info of cgraph_node. */
573 static section *
574 function_section_1 (tree decl, bool force_cold)
576 section *section = NULL;
577 enum node_frequency freq = NODE_FREQUENCY_NORMAL;
578 bool startup = false, exit = false;
580 if (decl)
582 struct cgraph_node *node = cgraph_get_node (decl);
584 if (node)
586 freq = node->frequency;
587 startup = node->only_called_at_startup;
588 exit = node->only_called_at_exit;
591 if (force_cold)
592 freq = NODE_FREQUENCY_UNLIKELY_EXECUTED;
594 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
595 if (decl != NULL_TREE
596 && DECL_SECTION_NAME (decl) != NULL_TREE)
598 if (targetm.asm_out.function_section)
599 section = targetm.asm_out.function_section (decl, freq,
600 startup, exit);
601 if (section)
602 return section;
603 return get_named_section (decl, NULL, 0);
605 else
606 return targetm.asm_out.select_section
607 (decl, freq == NODE_FREQUENCY_UNLIKELY_EXECUTED,
608 DECL_ALIGN (decl));
609 #else
610 if (targetm.asm_out.function_section)
611 section = targetm.asm_out.function_section (decl, freq, startup, exit);
612 if (section)
613 return section;
614 return hot_function_section (decl);
615 #endif
618 /* Return the section for function DECL.
620 If DECL is NULL_TREE, return the text section. We can be passed
621 NULL_TREE under some circumstances by dbxout.c at least. */
623 section *
624 function_section (tree decl)
626 /* Handle cases where function splitting code decides
627 to put function entry point into unlikely executed section
628 despite the fact that the function itself is not cold
629 (i.e. it is called rarely but contains a hot loop that is
630 better to live in hot subsection for the code locality). */
631 return function_section_1 (decl,
632 first_function_block_is_cold);
635 /* Return the section for the current function, take IN_COLD_SECTION_P
636 into account. */
638 section *
639 current_function_section (void)
641 return function_section_1 (current_function_decl, in_cold_section_p);
644 /* Tell assembler to switch to unlikely-to-be-executed text section. */
646 section *
647 unlikely_text_section (void)
649 return function_section_1 (current_function_decl, true);
652 /* When called within a function context, return true if the function
653 has been assigned a cold text section and if SECT is that section.
654 When called outside a function context, return true if SECT is the
655 default cold section. */
657 bool
658 unlikely_text_section_p (section *sect)
660 return sect == function_section_1 (current_function_decl, true);
663 /* Return the read-only data section associated with function DECL. */
665 section *
666 default_function_rodata_section (tree decl)
668 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
670 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
672 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
674 const char *dot;
675 size_t len;
676 char* rname;
678 dot = strchr (name + 1, '.');
679 if (!dot)
680 dot = name;
681 len = strlen (dot) + 8;
682 rname = (char *) alloca (len);
684 strcpy (rname, ".rodata");
685 strcat (rname, dot);
686 return get_section (rname, SECTION_LINKONCE, decl);
688 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
689 else if (DECL_ONE_ONLY (decl)
690 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
692 size_t len = strlen (name) + 1;
693 char *rname = (char *) alloca (len);
695 memcpy (rname, name, len);
696 rname[14] = 'r';
697 return get_section (rname, SECTION_LINKONCE, decl);
699 /* For .text.foo we want to use .rodata.foo. */
700 else if (flag_function_sections && flag_data_sections
701 && strncmp (name, ".text.", 6) == 0)
703 size_t len = strlen (name) + 1;
704 char *rname = (char *) alloca (len + 2);
706 memcpy (rname, ".rodata", 7);
707 memcpy (rname + 7, name + 5, len - 5);
708 return get_section (rname, 0, decl);
712 return readonly_data_section;
715 /* Return the read-only data section associated with function DECL
716 for targets where that section should be always the single
717 readonly data section. */
719 section *
720 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
722 return readonly_data_section;
725 /* Return the section to use for string merging. */
727 static section *
728 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
729 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
730 unsigned int flags ATTRIBUTE_UNUSED)
732 HOST_WIDE_INT len;
734 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
735 && TREE_CODE (decl) == STRING_CST
736 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
737 && align <= 256
738 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
739 && TREE_STRING_LENGTH (decl) >= len)
741 enum machine_mode mode;
742 unsigned int modesize;
743 const char *str;
744 HOST_WIDE_INT i;
745 int j, unit;
746 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
747 char *name = (char *) alloca (strlen (prefix) + 30);
749 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
750 modesize = GET_MODE_BITSIZE (mode);
751 if (modesize >= 8 && modesize <= 256
752 && (modesize & (modesize - 1)) == 0)
754 if (align < modesize)
755 align = modesize;
757 str = TREE_STRING_POINTER (decl);
758 unit = GET_MODE_SIZE (mode);
760 /* Check for embedded NUL characters. */
761 for (i = 0; i < len; i += unit)
763 for (j = 0; j < unit; j++)
764 if (str[i + j] != '\0')
765 break;
766 if (j == unit)
767 break;
769 if (i == len - unit)
771 sprintf (name, "%s.str%d.%d", prefix,
772 modesize / 8, (int) (align / 8));
773 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
774 return get_section (name, flags, NULL);
779 return readonly_data_section;
782 /* Return the section to use for constant merging. */
784 section *
785 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
786 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
787 unsigned int flags ATTRIBUTE_UNUSED)
789 unsigned int modesize = GET_MODE_BITSIZE (mode);
791 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
792 && mode != VOIDmode
793 && mode != BLKmode
794 && modesize <= align
795 && align >= 8
796 && align <= 256
797 && (align & (align - 1)) == 0)
799 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
800 char *name = (char *) alloca (strlen (prefix) + 30);
802 sprintf (name, "%s.cst%d", prefix, (int) (align / 8));
803 flags |= (align / 8) | SECTION_MERGE;
804 return get_section (name, flags, NULL);
806 return readonly_data_section;
809 /* Given NAME, a putative register name, discard any customary prefixes. */
811 static const char *
812 strip_reg_name (const char *name)
814 #ifdef REGISTER_PREFIX
815 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
816 name += strlen (REGISTER_PREFIX);
817 #endif
818 if (name[0] == '%' || name[0] == '#')
819 name++;
820 return name;
823 /* The user has asked for a DECL to have a particular name. Set (or
824 change) it in such a way that we don't prefix an underscore to
825 it. */
826 void
827 set_user_assembler_name (tree decl, const char *name)
829 char *starred = (char *) alloca (strlen (name) + 2);
830 starred[0] = '*';
831 strcpy (starred + 1, name);
832 change_decl_assembler_name (decl, get_identifier (starred));
833 SET_DECL_RTL (decl, NULL_RTX);
836 /* Decode an `asm' spec for a declaration as a register name.
837 Return the register number, or -1 if nothing specified,
838 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
839 or -3 if ASMSPEC is `cc' and is not recognized,
840 or -4 if ASMSPEC is `memory' and is not recognized.
841 Accept an exact spelling or a decimal number.
842 Prefixes such as % are optional. */
845 decode_reg_name_and_count (const char *asmspec, int *pnregs)
847 /* Presume just one register is clobbered. */
848 *pnregs = 1;
850 if (asmspec != 0)
852 int i;
854 /* Get rid of confusing prefixes. */
855 asmspec = strip_reg_name (asmspec);
857 /* Allow a decimal number as a "register name". */
858 for (i = strlen (asmspec) - 1; i >= 0; i--)
859 if (! ISDIGIT (asmspec[i]))
860 break;
861 if (asmspec[0] != 0 && i < 0)
863 i = atoi (asmspec);
864 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
865 return i;
866 else
867 return -2;
870 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
871 if (reg_names[i][0]
872 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
873 return i;
875 #ifdef OVERLAPPING_REGISTER_NAMES
877 static const struct
879 const char *const name;
880 const int number;
881 const int nregs;
882 } table[] = OVERLAPPING_REGISTER_NAMES;
884 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
885 if (table[i].name[0]
886 && ! strcmp (asmspec, table[i].name))
888 *pnregs = table[i].nregs;
889 return table[i].number;
892 #endif /* OVERLAPPING_REGISTER_NAMES */
894 #ifdef ADDITIONAL_REGISTER_NAMES
896 static const struct { const char *const name; const int number; } table[]
897 = ADDITIONAL_REGISTER_NAMES;
899 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
900 if (table[i].name[0]
901 && ! strcmp (asmspec, table[i].name))
902 return table[i].number;
904 #endif /* ADDITIONAL_REGISTER_NAMES */
906 if (!strcmp (asmspec, "memory"))
907 return -4;
909 if (!strcmp (asmspec, "cc"))
910 return -3;
912 return -2;
915 return -1;
919 decode_reg_name (const char *name)
921 int count;
922 return decode_reg_name_and_count (name, &count);
926 /* Return true if DECL's initializer is suitable for a BSS section. */
928 static bool
929 bss_initializer_p (const_tree decl)
931 return (DECL_INITIAL (decl) == NULL
932 || DECL_INITIAL (decl) == error_mark_node
933 || (flag_zero_initialized_in_bss
934 /* Leave constant zeroes in .rodata so they
935 can be shared. */
936 && !TREE_READONLY (decl)
937 && initializer_zerop (DECL_INITIAL (decl))));
940 /* Compute the alignment of variable specified by DECL.
941 DONT_OUTPUT_DATA is from assemble_variable. */
943 void
944 align_variable (tree decl, bool dont_output_data)
946 unsigned int align = DECL_ALIGN (decl);
948 /* In the case for initialing an array whose length isn't specified,
949 where we have not yet been able to do the layout,
950 figure out the proper alignment now. */
951 if (dont_output_data && DECL_SIZE (decl) == 0
952 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
953 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
955 /* Some object file formats have a maximum alignment which they support.
956 In particular, a.out format supports a maximum alignment of 4. */
957 if (align > MAX_OFILE_ALIGNMENT)
959 warning (0, "alignment of %q+D is greater than maximum object "
960 "file alignment. Using %d", decl,
961 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
962 align = MAX_OFILE_ALIGNMENT;
965 /* On some machines, it is good to increase alignment sometimes. */
966 if (! DECL_USER_ALIGN (decl))
968 #ifdef DATA_ALIGNMENT
969 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
970 /* Don't increase alignment too much for TLS variables - TLS space
971 is too precious. */
972 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
973 align = data_align;
974 #endif
975 #ifdef CONSTANT_ALIGNMENT
976 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
978 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
979 align);
980 /* Don't increase alignment too much for TLS variables - TLS space
981 is too precious. */
982 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
983 align = const_align;
985 #endif
988 /* Reset the alignment in case we have made it tighter, so we can benefit
989 from it in get_pointer_alignment. */
990 DECL_ALIGN (decl) = align;
993 /* Return the section into which the given VAR_DECL or CONST_DECL
994 should be placed. PREFER_NOSWITCH_P is true if a noswitch
995 section should be used wherever possible. */
997 section *
998 get_variable_section (tree decl, bool prefer_noswitch_p)
1000 addr_space_t as = ADDR_SPACE_GENERIC;
1001 int reloc;
1003 if (TREE_TYPE (decl) != error_mark_node)
1004 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1006 if (DECL_COMMON (decl))
1008 /* If the decl has been given an explicit section name, or it resides
1009 in a non-generic address space, then it isn't common, and shouldn't
1010 be handled as such. */
1011 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1012 && ADDR_SPACE_GENERIC_P (as));
1013 if (DECL_THREAD_LOCAL_P (decl))
1014 return tls_comm_section;
1015 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1016 return comm_section;
1019 if (DECL_INITIAL (decl) == error_mark_node)
1020 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1021 else if (DECL_INITIAL (decl))
1022 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1023 else
1024 reloc = 0;
1026 resolve_unique_section (decl, reloc, flag_data_sections);
1027 if (IN_NAMED_SECTION (decl))
1028 return get_named_section (decl, NULL, reloc);
1030 if (ADDR_SPACE_GENERIC_P (as)
1031 && !DECL_THREAD_LOCAL_P (decl)
1032 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1033 && bss_initializer_p (decl))
1035 if (!TREE_PUBLIC (decl))
1036 return lcomm_section;
1037 if (bss_noswitch_section)
1038 return bss_noswitch_section;
1041 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1044 /* Return the block into which object_block DECL should be placed. */
1046 static struct object_block *
1047 get_block_for_decl (tree decl)
1049 section *sect;
1051 if (TREE_CODE (decl) == VAR_DECL)
1053 /* The object must be defined in this translation unit. */
1054 if (DECL_EXTERNAL (decl))
1055 return NULL;
1057 /* There's no point using object blocks for something that is
1058 isolated by definition. */
1059 if (DECL_ONE_ONLY (decl))
1060 return NULL;
1063 /* We can only calculate block offsets if the decl has a known
1064 constant size. */
1065 if (DECL_SIZE_UNIT (decl) == NULL)
1066 return NULL;
1067 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1068 return NULL;
1070 /* Find out which section should contain DECL. We cannot put it into
1071 an object block if it requires a standalone definition. */
1072 if (TREE_CODE (decl) == VAR_DECL)
1073 align_variable (decl, 0);
1074 sect = get_variable_section (decl, true);
1075 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1076 return NULL;
1078 return get_block_for_section (sect);
1081 /* Make sure block symbol SYMBOL is in block BLOCK. */
1083 static void
1084 change_symbol_block (rtx symbol, struct object_block *block)
1086 if (block != SYMBOL_REF_BLOCK (symbol))
1088 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1089 SYMBOL_REF_BLOCK (symbol) = block;
1093 /* Return true if it is possible to put DECL in an object_block. */
1095 static bool
1096 use_blocks_for_decl_p (tree decl)
1098 /* Only data DECLs can be placed into object blocks. */
1099 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1100 return false;
1102 /* Detect decls created by dw2_force_const_mem. Such decls are
1103 special because DECL_INITIAL doesn't specify the decl's true value.
1104 dw2_output_indirect_constants will instead call assemble_variable
1105 with dont_output_data set to 1 and then print the contents itself. */
1106 if (DECL_INITIAL (decl) == decl)
1107 return false;
1109 /* If this decl is an alias, then we don't want to emit a
1110 definition. */
1111 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1112 return false;
1114 return true;
1117 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1118 have static storage duration. In other words, it should not be an
1119 automatic variable, including PARM_DECLs.
1121 There is, however, one exception: this function handles variables
1122 explicitly placed in a particular register by the user.
1124 This is never called for PARM_DECL nodes. */
1126 void
1127 make_decl_rtl (tree decl)
1129 const char *name = 0;
1130 int reg_number;
1131 rtx x;
1133 /* Check that we are not being given an automatic variable. */
1134 gcc_assert (TREE_CODE (decl) != PARM_DECL
1135 && TREE_CODE (decl) != RESULT_DECL);
1137 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1138 gcc_assert (TREE_CODE (decl) != VAR_DECL
1139 || TREE_STATIC (decl)
1140 || TREE_PUBLIC (decl)
1141 || DECL_EXTERNAL (decl)
1142 || DECL_REGISTER (decl));
1144 /* And that we were not given a type or a label. */
1145 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1146 && TREE_CODE (decl) != LABEL_DECL);
1148 /* For a duplicate declaration, we can be called twice on the
1149 same DECL node. Don't discard the RTL already made. */
1150 if (DECL_RTL_SET_P (decl))
1152 /* If the old RTL had the wrong mode, fix the mode. */
1153 x = DECL_RTL (decl);
1154 if (GET_MODE (x) != DECL_MODE (decl))
1155 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1157 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1158 return;
1160 /* ??? Another way to do this would be to maintain a hashed
1161 table of such critters. Instead of adding stuff to a DECL
1162 to give certain attributes to it, we could use an external
1163 hash map from DECL to set of attributes. */
1165 /* Let the target reassign the RTL if it wants.
1166 This is necessary, for example, when one machine specific
1167 decl attribute overrides another. */
1168 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1170 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1171 on the new decl information. */
1172 if (MEM_P (x)
1173 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1174 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1175 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1177 /* Make this function static known to the mudflap runtime. */
1178 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1179 mudflap_enqueue_decl (decl);
1181 return;
1184 /* If this variable belongs to the global constant pool, retrieve the
1185 pre-computed RTL or recompute it in LTO mode. */
1186 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1188 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1189 return;
1192 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1194 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1195 && DECL_REGISTER (decl))
1197 error ("register name not specified for %q+D", decl);
1199 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1201 const char *asmspec = name+1;
1202 enum machine_mode mode = DECL_MODE (decl);
1203 reg_number = decode_reg_name (asmspec);
1204 /* First detect errors in declaring global registers. */
1205 if (reg_number == -1)
1206 error ("register name not specified for %q+D", decl);
1207 else if (reg_number < 0)
1208 error ("invalid register name for %q+D", decl);
1209 else if (mode == BLKmode)
1210 error ("data type of %q+D isn%'t suitable for a register",
1211 decl);
1212 else if (!in_hard_reg_set_p (accessible_reg_set, mode, reg_number))
1213 error ("the register specified for %q+D cannot be accessed"
1214 " by the current target", decl);
1215 else if (!in_hard_reg_set_p (operand_reg_set, mode, reg_number))
1216 error ("the register specified for %q+D is not general enough"
1217 " to be used as a register variable", decl);
1218 else if (!HARD_REGNO_MODE_OK (reg_number, mode))
1219 error ("register specified for %q+D isn%'t suitable for data type",
1220 decl);
1221 /* Now handle properly declared static register variables. */
1222 else
1224 int nregs;
1226 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1228 DECL_INITIAL (decl) = 0;
1229 error ("global register variable has initial value");
1231 if (TREE_THIS_VOLATILE (decl))
1232 warning (OPT_Wvolatile_register_var,
1233 "optimization may eliminate reads and/or "
1234 "writes to register variables");
1236 /* If the user specified one of the eliminables registers here,
1237 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1238 confused with that register and be eliminated. This usage is
1239 somewhat suspect... */
1241 SET_DECL_RTL (decl, gen_rtx_raw_REG (mode, reg_number));
1242 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1243 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1245 if (TREE_STATIC (decl))
1247 /* Make this register global, so not usable for anything
1248 else. */
1249 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1250 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1251 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1252 #endif
1253 nregs = hard_regno_nregs[reg_number][mode];
1254 while (nregs > 0)
1255 globalize_reg (decl, reg_number + --nregs);
1258 /* As a register variable, it has no section. */
1259 return;
1262 /* Now handle ordinary static variables and functions (in memory).
1263 Also handle vars declared register invalidly. */
1264 else if (name[0] == '*')
1266 #ifdef REGISTER_PREFIX
1267 if (strlen (REGISTER_PREFIX) != 0)
1269 reg_number = decode_reg_name (name);
1270 if (reg_number >= 0 || reg_number == -3)
1271 error ("register name given for non-register variable %q+D", decl);
1273 #endif
1276 /* Specifying a section attribute on a variable forces it into a
1277 non-.bss section, and thus it cannot be common. */
1278 /* FIXME: In general this code should not be necessary because
1279 visibility pass is doing the same work. But notice_global_symbol
1280 is called early and it needs to make DECL_RTL to get the name.
1281 we take care of recomputing the DECL_RTL after visibility is changed. */
1282 if (TREE_CODE (decl) == VAR_DECL
1283 && DECL_SECTION_NAME (decl) != NULL_TREE
1284 && DECL_INITIAL (decl) == NULL_TREE
1285 && DECL_COMMON (decl))
1286 DECL_COMMON (decl) = 0;
1288 /* Variables can't be both common and weak. */
1289 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1290 DECL_COMMON (decl) = 0;
1292 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1293 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1294 else
1296 enum machine_mode address_mode = Pmode;
1297 if (TREE_TYPE (decl) != error_mark_node)
1299 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1300 address_mode = targetm.addr_space.address_mode (as);
1302 x = gen_rtx_SYMBOL_REF (address_mode, name);
1304 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1305 SET_SYMBOL_REF_DECL (x, decl);
1307 x = gen_rtx_MEM (DECL_MODE (decl), x);
1308 if (TREE_CODE (decl) != FUNCTION_DECL)
1309 set_mem_attributes (x, decl, 1);
1310 SET_DECL_RTL (decl, x);
1312 /* Optionally set flags or add text to the name to record information
1313 such as that it is a function name.
1314 If the name is changed, the macro ASM_OUTPUT_LABELREF
1315 will have to know how to strip this information. */
1316 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1318 /* Make this function static known to the mudflap runtime. */
1319 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1320 mudflap_enqueue_decl (decl);
1323 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1324 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1325 rtl. */
1328 make_decl_rtl_for_debug (tree decl)
1330 unsigned int save_aliasing_flag, save_mudflap_flag;
1331 rtx rtl;
1333 if (DECL_RTL_SET_P (decl))
1334 return DECL_RTL (decl);
1336 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1337 call new_alias_set. If running with -fcompare-debug, sometimes
1338 we do not want to create alias sets that will throw the alias
1339 numbers off in the comparison dumps. So... clearing
1340 flag_strict_aliasing will keep new_alias_set() from creating a
1341 new set. It is undesirable to register decl with mudflap
1342 in this case as well. */
1343 save_aliasing_flag = flag_strict_aliasing;
1344 flag_strict_aliasing = 0;
1345 save_mudflap_flag = flag_mudflap;
1346 flag_mudflap = 0;
1348 rtl = DECL_RTL (decl);
1349 /* Reset DECL_RTL back, as various parts of the compiler expects
1350 DECL_RTL set meaning it is actually going to be output. */
1351 SET_DECL_RTL (decl, NULL);
1353 flag_strict_aliasing = save_aliasing_flag;
1354 flag_mudflap = save_mudflap_flag;
1356 return rtl;
1359 /* Output a string of literal assembler code
1360 for an `asm' keyword used between functions. */
1362 void
1363 assemble_asm (tree string)
1365 app_enable ();
1367 if (TREE_CODE (string) == ADDR_EXPR)
1368 string = TREE_OPERAND (string, 0);
1370 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1373 /* Record an element in the table of global destructors. SYMBOL is
1374 a SYMBOL_REF of the function to be called; PRIORITY is a number
1375 between 0 and MAX_INIT_PRIORITY. */
1377 void
1378 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1379 int priority ATTRIBUTE_UNUSED)
1381 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1382 /* Tell GNU LD that this is part of the static destructor set.
1383 This will work for any system that uses stabs, most usefully
1384 aout systems. */
1385 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1386 dbxout_stab_value_label (XSTR (symbol, 0));
1387 #else
1388 sorry ("global destructors not supported on this target");
1389 #endif
1392 /* Write the address of the entity given by SYMBOL to SEC. */
1393 void
1394 assemble_addr_to_section (rtx symbol, section *sec)
1396 switch_to_section (sec);
1397 assemble_align (POINTER_SIZE);
1398 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1401 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1402 not) section for PRIORITY. */
1403 section *
1404 get_cdtor_priority_section (int priority, bool constructor_p)
1406 char buf[16];
1408 /* ??? This only works reliably with the GNU linker. */
1409 sprintf (buf, "%s.%.5u",
1410 constructor_p ? ".ctors" : ".dtors",
1411 /* Invert the numbering so the linker puts us in the proper
1412 order; constructors are run from right to left, and the
1413 linker sorts in increasing order. */
1414 MAX_INIT_PRIORITY - priority);
1415 return get_section (buf, SECTION_WRITE, NULL);
1418 void
1419 default_named_section_asm_out_destructor (rtx symbol, int priority)
1421 section *sec;
1423 if (priority != DEFAULT_INIT_PRIORITY)
1424 sec = get_cdtor_priority_section (priority,
1425 /*constructor_p=*/false);
1426 else
1427 sec = get_section (".dtors", SECTION_WRITE, NULL);
1429 assemble_addr_to_section (symbol, sec);
1432 #ifdef DTORS_SECTION_ASM_OP
1433 void
1434 default_dtor_section_asm_out_destructor (rtx symbol,
1435 int priority ATTRIBUTE_UNUSED)
1437 assemble_addr_to_section (symbol, dtors_section);
1439 #endif
1441 /* Likewise for global constructors. */
1443 void
1444 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1445 int priority ATTRIBUTE_UNUSED)
1447 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1448 /* Tell GNU LD that this is part of the static destructor set.
1449 This will work for any system that uses stabs, most usefully
1450 aout systems. */
1451 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1452 dbxout_stab_value_label (XSTR (symbol, 0));
1453 #else
1454 sorry ("global constructors not supported on this target");
1455 #endif
1458 void
1459 default_named_section_asm_out_constructor (rtx symbol, int priority)
1461 section *sec;
1463 if (priority != DEFAULT_INIT_PRIORITY)
1464 sec = get_cdtor_priority_section (priority,
1465 /*constructor_p=*/true);
1466 else
1467 sec = get_section (".ctors", SECTION_WRITE, NULL);
1469 assemble_addr_to_section (symbol, sec);
1472 #ifdef CTORS_SECTION_ASM_OP
1473 void
1474 default_ctor_section_asm_out_constructor (rtx symbol,
1475 int priority ATTRIBUTE_UNUSED)
1477 assemble_addr_to_section (symbol, ctors_section);
1479 #endif
1481 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1482 a nonzero value if the constant pool should be output before the
1483 start of the function, or a zero value if the pool should output
1484 after the end of the function. The default is to put it before the
1485 start. */
1487 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1488 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1489 #endif
1491 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1492 to be output to assembler.
1493 Set first_global_object_name and weak_global_object_name as appropriate. */
1495 void
1496 notice_global_symbol (tree decl)
1498 const char **type = &first_global_object_name;
1500 if (first_global_object_name
1501 || !TREE_PUBLIC (decl)
1502 || DECL_EXTERNAL (decl)
1503 || !DECL_NAME (decl)
1504 || (TREE_CODE (decl) != FUNCTION_DECL
1505 && (TREE_CODE (decl) != VAR_DECL
1506 || (DECL_COMMON (decl)
1507 && (DECL_INITIAL (decl) == 0
1508 || DECL_INITIAL (decl) == error_mark_node))))
1509 || !MEM_P (DECL_RTL (decl)))
1510 return;
1512 if (L_IPO_COMP_MODE
1513 && ((TREE_CODE (decl) == FUNCTION_DECL
1514 && cgraph_is_auxiliary (decl))
1515 || (TREE_CODE (decl) == VAR_DECL
1516 && varpool_is_auxiliary (varpool_node (decl)))))
1517 return;
1519 /* We win when global object is found, but it is useful to know about weak
1520 symbol as well so we can produce nicer unique names. */
1521 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1522 type = &weak_global_object_name;
1524 if (!*type)
1526 const char *p;
1527 const char *name;
1528 rtx decl_rtl = DECL_RTL (decl);
1530 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1531 name = ggc_strdup (p);
1533 *type = name;
1537 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1538 current function goes into the cold section, so that targets can use
1539 current_function_section during RTL expansion. DECL describes the
1540 function. */
1542 void
1543 decide_function_section (tree decl)
1545 first_function_block_is_cold = false;
1547 if (flag_reorder_blocks_and_partition)
1548 /* We will decide in assemble_start_function. */
1549 return;
1551 if (DECL_SECTION_NAME (decl))
1553 struct cgraph_node *node = cgraph_get_node (current_function_decl);
1554 /* Calls to function_section rely on first_function_block_is_cold
1555 being accurate. */
1556 first_function_block_is_cold = (node
1557 && node->frequency
1558 == NODE_FREQUENCY_UNLIKELY_EXECUTED);
1561 in_cold_section_p = first_function_block_is_cold;
1564 /* Output assembler code for the constant pool of a function and associated
1565 with defining the name of the function. DECL describes the function.
1566 NAME is the function's name. For the constant pool, we use the current
1567 constant pool data. */
1569 void
1570 assemble_start_function (tree decl, const char *fnname)
1572 int align;
1573 char tmp_label[100];
1574 bool hot_label_written = false;
1576 if (flag_reorder_blocks_and_partition)
1578 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1579 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1580 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1581 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1582 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1583 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1584 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1585 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1586 const_labelno++;
1588 else
1590 crtl->subsections.hot_section_label = NULL;
1591 crtl->subsections.cold_section_label = NULL;
1592 crtl->subsections.hot_section_end_label = NULL;
1593 crtl->subsections.cold_section_end_label = NULL;
1596 /* The following code does not need preprocessing in the assembler. */
1598 app_disable ();
1600 if (CONSTANT_POOL_BEFORE_FUNCTION)
1601 output_constant_pool (fnname, decl);
1603 /* Make sure the not and cold text (code) sections are properly
1604 aligned. This is necessary here in the case where the function
1605 has both hot and cold sections, because we don't want to re-set
1606 the alignment when the section switch happens mid-function. */
1608 if (flag_reorder_blocks_and_partition)
1610 first_function_block_is_cold = false;
1612 switch_to_section (unlikely_text_section ());
1613 assemble_align (DECL_ALIGN (decl));
1614 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1616 /* When the function starts with a cold section, we need to explicitly
1617 align the hot section and write out the hot section label.
1618 But if the current function is a thunk, we do not have a CFG. */
1619 if (!cfun->is_thunk
1620 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1622 switch_to_section (text_section);
1623 assemble_align (DECL_ALIGN (decl));
1624 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1625 hot_label_written = true;
1626 first_function_block_is_cold = true;
1628 in_cold_section_p = first_function_block_is_cold;
1632 /* Switch to the correct text section for the start of the function. */
1634 switch_to_section (function_section (decl));
1635 if (flag_reorder_blocks_and_partition
1636 && !hot_label_written)
1637 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1639 /* Tell assembler to move to target machine's alignment for functions. */
1640 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1641 if (align > 0)
1643 ASM_OUTPUT_ALIGN (asm_out_file, align);
1646 /* Handle a user-specified function alignment.
1647 Note that we still need to align to DECL_ALIGN, as above,
1648 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1649 if (! DECL_USER_ALIGN (decl)
1650 && align_functions_log > align
1651 && optimize_function_for_speed_p (cfun))
1653 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1654 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1655 align_functions_log, align_functions - 1);
1656 #else
1657 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1658 #endif
1661 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1662 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1663 #endif
1665 if (!DECL_IGNORED_P (decl))
1666 (*debug_hooks->begin_function) (decl);
1668 /* Make function name accessible from other files, if appropriate. */
1670 if (TREE_PUBLIC (decl))
1672 notice_global_symbol (decl);
1674 globalize_decl (decl);
1676 maybe_assemble_visibility (decl);
1679 if (DECL_PRESERVE_P (decl))
1680 targetm.asm_out.mark_decl_preserved (fnname);
1682 /* Do any machine/system dependent processing of the function name. */
1683 #ifdef ASM_DECLARE_FUNCTION_NAME
1684 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1685 #else
1686 /* Standard thing is just output label for the function. */
1687 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
1688 #endif /* ASM_DECLARE_FUNCTION_NAME */
1690 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))
1691 saw_no_split_stack = true;
1694 /* Output assembler code associated with defining the size of the
1695 function. DECL describes the function. NAME is the function's name. */
1697 void
1698 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1700 #ifdef ASM_DECLARE_FUNCTION_SIZE
1701 /* We could have switched section in the middle of the function. */
1702 if (flag_reorder_blocks_and_partition)
1703 switch_to_section (function_section (decl));
1704 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1705 #endif
1706 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1708 output_constant_pool (fnname, decl);
1709 switch_to_section (function_section (decl)); /* need to switch back */
1711 /* Output labels for end of hot/cold text sections (to be used by
1712 debug info.) */
1713 if (flag_reorder_blocks_and_partition)
1715 section *save_text_section;
1717 save_text_section = in_section;
1718 switch_to_section (unlikely_text_section ());
1719 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1720 if (first_function_block_is_cold)
1721 switch_to_section (text_section);
1722 else
1723 switch_to_section (function_section (decl));
1724 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1725 switch_to_section (save_text_section);
1729 /* Assemble code to leave SIZE bytes of zeros. */
1731 void
1732 assemble_zeros (unsigned HOST_WIDE_INT size)
1734 /* Do no output if -fsyntax-only. */
1735 if (flag_syntax_only)
1736 return;
1738 #ifdef ASM_NO_SKIP_IN_TEXT
1739 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1740 so we must output 0s explicitly in the text section. */
1741 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1743 unsigned HOST_WIDE_INT i;
1744 for (i = 0; i < size; i++)
1745 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1747 else
1748 #endif
1749 if (size > 0)
1750 ASM_OUTPUT_SKIP (asm_out_file, size);
1753 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1755 void
1756 assemble_align (int align)
1758 if (align > BITS_PER_UNIT)
1760 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1764 /* Assemble a string constant with the specified C string as contents. */
1766 void
1767 assemble_string (const char *p, int size)
1769 int pos = 0;
1770 int maximum = 2000;
1772 /* If the string is very long, split it up. */
1774 while (pos < size)
1776 int thissize = size - pos;
1777 if (thissize > maximum)
1778 thissize = maximum;
1780 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1782 pos += thissize;
1783 p += thissize;
1788 /* A noswitch_section_callback for lcomm_section. */
1790 static bool
1791 emit_local (tree decl ATTRIBUTE_UNUSED,
1792 const char *name ATTRIBUTE_UNUSED,
1793 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1794 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1796 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1797 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1798 size, DECL_ALIGN (decl));
1799 return true;
1800 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1801 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1802 return true;
1803 #else
1804 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1805 return false;
1806 #endif
1809 /* A noswitch_section_callback for bss_noswitch_section. */
1811 #if defined ASM_OUTPUT_ALIGNED_BSS
1812 static bool
1813 emit_bss (tree decl ATTRIBUTE_UNUSED,
1814 const char *name ATTRIBUTE_UNUSED,
1815 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1816 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1818 #if defined ASM_OUTPUT_ALIGNED_BSS
1819 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1820 return true;
1821 #endif
1823 #endif
1825 /* A noswitch_section_callback for comm_section. */
1827 static bool
1828 emit_common (tree decl ATTRIBUTE_UNUSED,
1829 const char *name ATTRIBUTE_UNUSED,
1830 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1831 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1833 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1834 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1835 size, DECL_ALIGN (decl));
1836 return true;
1837 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1838 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1839 return true;
1840 #else
1841 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1842 return false;
1843 #endif
1846 /* A noswitch_section_callback for tls_comm_section. */
1848 static bool
1849 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1850 const char *name ATTRIBUTE_UNUSED,
1851 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1852 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1854 #ifdef ASM_OUTPUT_TLS_COMMON
1855 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1856 return true;
1857 #else
1858 sorry ("thread-local COMMON data not implemented");
1859 return true;
1860 #endif
1863 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1864 NAME is the name of DECL's SYMBOL_REF. */
1866 static void
1867 assemble_noswitch_variable (tree decl, const char *name, section *sect)
1869 unsigned HOST_WIDE_INT size, rounded;
1871 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1872 rounded = size;
1874 /* Don't allocate zero bytes of common,
1875 since that means "undefined external" in the linker. */
1876 if (size == 0)
1877 rounded = 1;
1879 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1880 so that each uninitialized object starts on such a boundary. */
1881 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1882 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1883 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1885 if (!sect->noswitch.callback (decl, name, size, rounded)
1886 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1887 warning (0, "requested alignment for %q+D is greater than "
1888 "implemented alignment of %wu", decl, rounded);
1891 /* A subroutine of assemble_variable. Output the label and contents of
1892 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1893 is as for assemble_variable. */
1895 static void
1896 assemble_variable_contents (tree decl, const char *name,
1897 bool dont_output_data)
1899 /* Do any machine/system dependent processing of the object. */
1900 #ifdef ASM_DECLARE_OBJECT_NAME
1901 last_assemble_variable_decl = decl;
1902 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1903 #else
1904 /* Standard thing is just output label for the object. */
1905 ASM_OUTPUT_LABEL (asm_out_file, name);
1906 #endif /* ASM_DECLARE_OBJECT_NAME */
1908 if (!dont_output_data)
1910 if (DECL_INITIAL (decl)
1911 && DECL_INITIAL (decl) != error_mark_node
1912 && !initializer_zerop (DECL_INITIAL (decl)))
1913 /* Output the actual data. */
1914 output_constant (DECL_INITIAL (decl),
1915 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1916 DECL_ALIGN (decl));
1917 else
1918 /* Leave space for it. */
1919 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1923 /* Assemble everything that is needed for a variable or function declaration.
1924 Not used for automatic variables, and not used for function definitions.
1925 Should not be called for variables of incomplete structure type.
1927 TOP_LEVEL is nonzero if this variable has file scope.
1928 AT_END is nonzero if this is the special handling, at end of compilation,
1929 to define things that have had only tentative definitions.
1930 DONT_OUTPUT_DATA if nonzero means don't actually output the
1931 initial value (that will be done by the caller). */
1933 void
1934 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1935 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1937 const char *name;
1938 rtx decl_rtl, symbol;
1939 section *sect;
1941 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1942 gcc_assert (TREE_CODE (decl) == VAR_DECL);
1944 /* Emulated TLS had better not get this far. */
1945 gcc_checking_assert (targetm.have_tls || !DECL_THREAD_LOCAL_P (decl));
1947 last_assemble_variable_decl = 0;
1949 /* Normally no need to say anything here for external references,
1950 since assemble_external is called by the language-specific code
1951 when a declaration is first seen. */
1953 if (DECL_EXTERNAL (decl))
1954 return;
1956 /* Do nothing for global register variables. */
1957 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1959 TREE_ASM_WRITTEN (decl) = 1;
1960 return;
1963 /* If type was incomplete when the variable was declared,
1964 see if it is complete now. */
1966 if (DECL_SIZE (decl) == 0)
1967 layout_decl (decl, 0);
1969 /* Still incomplete => don't allocate it; treat the tentative defn
1970 (which is what it must have been) as an `extern' reference. */
1972 if (!dont_output_data && DECL_SIZE (decl) == 0)
1974 error ("storage size of %q+D isn%'t known", decl);
1975 TREE_ASM_WRITTEN (decl) = 1;
1976 return;
1979 /* The first declaration of a variable that comes through this function
1980 decides whether it is global (in C, has external linkage)
1981 or local (in C, has internal linkage). So do nothing more
1982 if this function has already run. */
1984 if (TREE_ASM_WRITTEN (decl))
1985 return;
1987 /* Make sure targetm.encode_section_info is invoked before we set
1988 ASM_WRITTEN. */
1989 decl_rtl = DECL_RTL (decl);
1991 TREE_ASM_WRITTEN (decl) = 1;
1993 /* Do no output if -fsyntax-only. */
1994 if (flag_syntax_only)
1995 return;
1997 if (! dont_output_data
1998 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2000 error ("size of variable %q+D is too large", decl);
2001 return;
2004 gcc_assert (MEM_P (decl_rtl));
2005 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2006 symbol = XEXP (decl_rtl, 0);
2008 /* If this symbol belongs to the tree constant pool, output the constant
2009 if it hasn't already been written. */
2010 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2012 tree decl = SYMBOL_REF_DECL (symbol);
2013 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2014 output_constant_def_contents (symbol);
2015 return;
2018 app_disable ();
2020 name = XSTR (symbol, 0);
2021 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2022 notice_global_symbol (decl);
2024 /* Compute the alignment of this data. */
2026 align_variable (decl, dont_output_data);
2027 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2029 if (TREE_PUBLIC (decl))
2030 maybe_assemble_visibility (decl);
2032 if (DECL_PRESERVE_P (decl))
2033 targetm.asm_out.mark_decl_preserved (name);
2035 /* First make the assembler name(s) global if appropriate. */
2036 sect = get_variable_section (decl, false);
2037 if (TREE_PUBLIC (decl)
2038 && (sect->common.flags & SECTION_COMMON) == 0)
2039 globalize_decl (decl);
2041 /* Output any data that we will need to use the address of. */
2042 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2043 output_addressed_constants (DECL_INITIAL (decl));
2045 /* dbxout.c needs to know this. */
2046 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2047 DECL_IN_TEXT_SECTION (decl) = 1;
2049 /* If the decl is part of an object_block, make sure that the decl
2050 has been positioned within its block, but do not write out its
2051 definition yet. output_object_blocks will do that later. */
2052 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2054 gcc_assert (!dont_output_data);
2055 place_block_symbol (symbol);
2057 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2058 assemble_noswitch_variable (decl, name, sect);
2059 else
2061 switch_to_section (sect);
2062 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2063 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2064 assemble_variable_contents (decl, name, dont_output_data);
2068 /* Return 1 if type TYPE contains any pointers. */
2070 static int
2071 contains_pointers_p (tree type)
2073 switch (TREE_CODE (type))
2075 case POINTER_TYPE:
2076 case REFERENCE_TYPE:
2077 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2078 so I'll play safe and return 1. */
2079 case OFFSET_TYPE:
2080 return 1;
2082 case RECORD_TYPE:
2083 case UNION_TYPE:
2084 case QUAL_UNION_TYPE:
2086 tree fields;
2087 /* For a type that has fields, see if the fields have pointers. */
2088 for (fields = TYPE_FIELDS (type); fields; fields = DECL_CHAIN (fields))
2089 if (TREE_CODE (fields) == FIELD_DECL
2090 && contains_pointers_p (TREE_TYPE (fields)))
2091 return 1;
2092 return 0;
2095 case ARRAY_TYPE:
2096 /* An array type contains pointers if its element type does. */
2097 return contains_pointers_p (TREE_TYPE (type));
2099 default:
2100 return 0;
2104 /* We delay assemble_external processing until
2105 the compilation unit is finalized. This is the best we can do for
2106 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2107 it all the way to final. See PR 17982 for further discussion. */
2108 static GTY(()) tree pending_assemble_externals;
2110 #ifdef ASM_OUTPUT_EXTERNAL
2111 /* True if DECL is a function decl for which no out-of-line copy exists.
2112 It is assumed that DECL's assembler name has been set. */
2114 static bool
2115 incorporeal_function_p (tree decl)
2117 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2119 const char *name;
2121 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2122 && (DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA
2123 || DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA_WITH_ALIGN))
2124 return true;
2126 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2127 /* Atomic or sync builtins which have survived this far will be
2128 resolved externally and therefore are not incorporeal. */
2129 if (strncmp (name, "__builtin_", 10) == 0)
2130 return true;
2132 return false;
2135 /* Actually do the tests to determine if this is necessary, and invoke
2136 ASM_OUTPUT_EXTERNAL. */
2137 static void
2138 assemble_external_real (tree decl)
2140 rtx rtl = DECL_RTL (decl);
2142 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2143 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2144 && !incorporeal_function_p (decl))
2146 /* Some systems do require some output. */
2147 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2148 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2151 #endif
2153 void
2154 process_pending_assemble_externals (void)
2156 #ifdef ASM_OUTPUT_EXTERNAL
2157 tree list;
2158 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2159 assemble_external_real (TREE_VALUE (list));
2161 pending_assemble_externals = 0;
2162 #endif
2165 /* This TREE_LIST contains any weak symbol declarations waiting
2166 to be emitted. */
2167 static GTY(()) tree weak_decls;
2169 /* Output something to declare an external symbol to the assembler,
2170 and qualifiers such as weakness. (Most assemblers don't need
2171 extern declaration, so we normally output nothing.) Do nothing if
2172 DECL is not external. */
2174 void
2175 assemble_external (tree decl ATTRIBUTE_UNUSED)
2177 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2178 main body of this code is only rarely exercised. To provide some
2179 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2180 open. If it's not, we should not be calling this function. */
2181 gcc_assert (asm_out_file);
2183 /* Processing pending items from auxiliary modules are not supported
2184 which means platforms that requires ASM_OUTPUT_EXTERNAL may
2185 have issues. (TODO : one way is to flush the pending items from
2186 auxiliary modules at the end of parsing the module) */
2187 if (L_IPO_IS_AUXILIARY_MODULE)
2188 return;
2190 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2191 return;
2193 /* We want to output annotation for weak and external symbols at
2194 very last to check if they are references or not. */
2196 if (TARGET_SUPPORTS_WEAK
2197 && DECL_WEAK (decl)
2198 /* TREE_STATIC is a weird and abused creature which is not
2199 generally the right test for whether an entity has been
2200 locally emitted, inlined or otherwise not-really-extern, but
2201 for declarations that can be weak, it happens to be
2202 match. */
2203 && !TREE_STATIC (decl)
2204 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2205 && value_member (decl, weak_decls) == NULL_TREE)
2206 weak_decls = tree_cons (NULL, decl, weak_decls);
2208 #ifdef ASM_OUTPUT_EXTERNAL
2209 if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2210 pending_assemble_externals = tree_cons (NULL, decl,
2211 pending_assemble_externals);
2212 #endif
2215 /* Similar, for calling a library function FUN. */
2217 void
2218 assemble_external_libcall (rtx fun)
2220 /* Declare library function name external when first used, if nec. */
2221 if (! SYMBOL_REF_USED (fun))
2223 SYMBOL_REF_USED (fun) = 1;
2224 targetm.asm_out.external_libcall (fun);
2228 /* Assemble a label named NAME. */
2230 void
2231 assemble_label (FILE *file, const char *name)
2233 ASM_OUTPUT_LABEL (file, name);
2236 /* Set the symbol_referenced flag for ID. */
2237 void
2238 mark_referenced (tree id)
2240 TREE_SYMBOL_REFERENCED (id) = 1;
2243 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2244 void
2245 mark_decl_referenced (tree decl)
2247 if (TREE_CODE (decl) == FUNCTION_DECL)
2249 /* Extern inline functions don't become needed when referenced.
2250 If we know a method will be emitted in other TU and no new
2251 functions can be marked reachable, just use the external
2252 definition. */
2253 struct cgraph_node *node = cgraph_get_create_node (decl);
2254 if (!(DECL_EXTERNAL (decl) || cgraph_is_aux_decl_external (node))
2255 && !node->local.finalized)
2256 cgraph_mark_needed_node (node);
2258 else if (TREE_CODE (decl) == VAR_DECL)
2260 struct varpool_node *node = varpool_node (decl);
2261 varpool_mark_needed_node (node);
2262 /* C++ frontend use mark_decl_references to force COMDAT variables
2263 to be output that might appear dead otherwise. */
2264 node->force_output = true;
2266 /* else do nothing - we can get various sorts of CST nodes here,
2267 which do not need to be marked. */
2271 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2272 until we find an identifier that is not itself a transparent alias.
2273 Modify the alias passed to it by reference (and all aliases on the
2274 way to the ultimate target), such that they do not have to be
2275 followed again, and return the ultimate target of the alias
2276 chain. */
2278 static inline tree
2279 ultimate_transparent_alias_target (tree *alias)
2281 tree target = *alias;
2283 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2285 gcc_assert (TREE_CHAIN (target));
2286 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2287 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2288 && ! TREE_CHAIN (target));
2289 *alias = target;
2292 return target;
2295 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2296 starts with a *, the rest of NAME is output verbatim. Otherwise
2297 NAME is transformed in a target-specific way (usually by the
2298 addition of an underscore). */
2300 void
2301 assemble_name_raw (FILE *file, const char *name)
2303 if (name[0] == '*')
2304 fputs (&name[1], file);
2305 else
2306 ASM_OUTPUT_LABELREF (file, name);
2309 /* Like assemble_name_raw, but should be used when NAME might refer to
2310 an entity that is also represented as a tree (like a function or
2311 variable). If NAME does refer to such an entity, that entity will
2312 be marked as referenced. */
2314 void
2315 assemble_name (FILE *file, const char *name)
2317 const char *real_name;
2318 tree id;
2320 real_name = targetm.strip_name_encoding (name);
2322 id = maybe_get_identifier (real_name);
2323 if (id)
2325 tree id_orig = id;
2327 mark_referenced (id);
2328 ultimate_transparent_alias_target (&id);
2329 if (id != id_orig)
2330 name = IDENTIFIER_POINTER (id);
2331 gcc_assert (! TREE_CHAIN (id));
2334 assemble_name_raw (file, name);
2337 /* Allocate SIZE bytes writable static space with a gensym name
2338 and return an RTX to refer to its address. */
2341 assemble_static_space (unsigned HOST_WIDE_INT size)
2343 char name[12];
2344 const char *namestring;
2345 rtx x;
2347 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2348 ++const_labelno;
2349 namestring = ggc_strdup (name);
2351 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2352 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2354 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2355 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2356 BIGGEST_ALIGNMENT);
2357 #else
2358 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2359 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2360 #else
2362 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2363 so that each uninitialized object starts on such a boundary. */
2364 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2365 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2366 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2367 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2368 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2369 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2371 #endif
2372 #endif
2373 return x;
2376 /* Assemble the static constant template for function entry trampolines.
2377 This is done at most once per compilation.
2378 Returns an RTX for the address of the template. */
2380 static GTY(()) rtx initial_trampoline;
2383 assemble_trampoline_template (void)
2385 char label[256];
2386 const char *name;
2387 int align;
2388 rtx symbol;
2390 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2392 if (initial_trampoline)
2393 return initial_trampoline;
2395 /* By default, put trampoline templates in read-only data section. */
2397 #ifdef TRAMPOLINE_SECTION
2398 switch_to_section (TRAMPOLINE_SECTION);
2399 #else
2400 switch_to_section (readonly_data_section);
2401 #endif
2403 /* Write the assembler code to define one. */
2404 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2405 if (align > 0)
2406 ASM_OUTPUT_ALIGN (asm_out_file, align);
2408 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2409 targetm.asm_out.trampoline_template (asm_out_file);
2411 /* Record the rtl to refer to it. */
2412 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2413 name = ggc_strdup (label);
2414 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2415 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2417 initial_trampoline = gen_const_mem (BLKmode, symbol);
2418 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2419 set_mem_size (initial_trampoline, TRAMPOLINE_SIZE);
2421 return initial_trampoline;
2424 /* A and B are either alignments or offsets. Return the minimum alignment
2425 that may be assumed after adding the two together. */
2427 static inline unsigned
2428 min_align (unsigned int a, unsigned int b)
2430 return (a | b) & -(a | b);
2433 /* Return the assembler directive for creating a given kind of integer
2434 object. SIZE is the number of bytes in the object and ALIGNED_P
2435 indicates whether it is known to be aligned. Return NULL if the
2436 assembly dialect has no such directive.
2438 The returned string should be printed at the start of a new line and
2439 be followed immediately by the object's initial value. */
2441 const char *
2442 integer_asm_op (int size, int aligned_p)
2444 struct asm_int_op *ops;
2446 if (aligned_p)
2447 ops = &targetm.asm_out.aligned_op;
2448 else
2449 ops = &targetm.asm_out.unaligned_op;
2451 switch (size)
2453 case 1:
2454 return targetm.asm_out.byte_op;
2455 case 2:
2456 return ops->hi;
2457 case 4:
2458 return ops->si;
2459 case 8:
2460 return ops->di;
2461 case 16:
2462 return ops->ti;
2463 default:
2464 return NULL;
2468 /* Use directive OP to assemble an integer object X. Print OP at the
2469 start of the line, followed immediately by the value of X. */
2471 void
2472 assemble_integer_with_op (const char *op, rtx x)
2474 fputs (op, asm_out_file);
2475 output_addr_const (asm_out_file, x);
2476 fputc ('\n', asm_out_file);
2479 /* The default implementation of the asm_out.integer target hook. */
2481 bool
2482 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2483 unsigned int size ATTRIBUTE_UNUSED,
2484 int aligned_p ATTRIBUTE_UNUSED)
2486 const char *op = integer_asm_op (size, aligned_p);
2487 /* Avoid GAS bugs for large values. Specifically negative values whose
2488 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2489 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2490 return false;
2491 return op && (assemble_integer_with_op (op, x), true);
2494 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2495 the alignment of the integer in bits. Return 1 if we were able to output
2496 the constant, otherwise 0. We must be able to output the constant,
2497 if FORCE is nonzero. */
2499 bool
2500 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2502 int aligned_p;
2504 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2506 /* See if the target hook can handle this kind of object. */
2507 if (targetm.asm_out.integer (x, size, aligned_p))
2508 return true;
2510 /* If the object is a multi-byte one, try splitting it up. Split
2511 it into words it if is multi-word, otherwise split it into bytes. */
2512 if (size > 1)
2514 enum machine_mode omode, imode;
2515 unsigned int subalign;
2516 unsigned int subsize, i;
2517 enum mode_class mclass;
2519 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2520 subalign = MIN (align, subsize * BITS_PER_UNIT);
2521 if (GET_CODE (x) == CONST_FIXED)
2522 mclass = GET_MODE_CLASS (GET_MODE (x));
2523 else
2524 mclass = MODE_INT;
2526 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2527 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2529 for (i = 0; i < size; i += subsize)
2531 rtx partial = simplify_subreg (omode, x, imode, i);
2532 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2533 break;
2535 if (i == size)
2536 return true;
2538 /* If we've printed some of it, but not all of it, there's no going
2539 back now. */
2540 gcc_assert (!i);
2543 gcc_assert (!force);
2545 return false;
2548 void
2549 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2551 long data[4] = {0, 0, 0, 0};
2552 int i;
2553 int bitsize, nelts, nunits, units_per;
2555 /* This is hairy. We have a quantity of known size. real_to_target
2556 will put it into an array of *host* longs, 32 bits per element
2557 (even if long is more than 32 bits). We need to determine the
2558 number of array elements that are occupied (nelts) and the number
2559 of *target* min-addressable units that will be occupied in the
2560 object file (nunits). We cannot assume that 32 divides the
2561 mode's bitsize (size * BITS_PER_UNIT) evenly.
2563 size * BITS_PER_UNIT is used here to make sure that padding bits
2564 (which might appear at either end of the value; real_to_target
2565 will include the padding bits in its output array) are included. */
2567 nunits = GET_MODE_SIZE (mode);
2568 bitsize = nunits * BITS_PER_UNIT;
2569 nelts = CEIL (bitsize, 32);
2570 units_per = 32 / BITS_PER_UNIT;
2572 real_to_target (data, &d, mode);
2574 /* Put out the first word with the specified alignment. */
2575 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2576 nunits -= units_per;
2578 /* Subsequent words need only 32-bit alignment. */
2579 align = min_align (align, 32);
2581 for (i = 1; i < nelts; i++)
2583 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2584 nunits -= units_per;
2588 /* Given an expression EXP with a constant value,
2589 reduce it to the sum of an assembler symbol and an integer.
2590 Store them both in the structure *VALUE.
2591 EXP must be reducible. */
2593 struct addr_const {
2594 rtx base;
2595 HOST_WIDE_INT offset;
2598 static void
2599 decode_addr_const (tree exp, struct addr_const *value)
2601 tree target = TREE_OPERAND (exp, 0);
2602 int offset = 0;
2603 rtx x;
2605 while (1)
2607 if (TREE_CODE (target) == COMPONENT_REF
2608 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2610 offset += int_byte_position (TREE_OPERAND (target, 1));
2611 target = TREE_OPERAND (target, 0);
2613 else if (TREE_CODE (target) == ARRAY_REF
2614 || TREE_CODE (target) == ARRAY_RANGE_REF)
2616 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2617 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2618 target = TREE_OPERAND (target, 0);
2620 else if (TREE_CODE (target) == MEM_REF
2621 && TREE_CODE (TREE_OPERAND (target, 0)) == ADDR_EXPR)
2623 offset += mem_ref_offset (target).low;
2624 target = TREE_OPERAND (TREE_OPERAND (target, 0), 0);
2626 else if (TREE_CODE (target) == INDIRECT_REF
2627 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2628 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2629 == ADDR_EXPR)
2630 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2631 else
2632 break;
2635 switch (TREE_CODE (target))
2637 case VAR_DECL:
2638 case FUNCTION_DECL:
2639 x = DECL_RTL (target);
2640 break;
2642 case LABEL_DECL:
2643 x = gen_rtx_MEM (FUNCTION_MODE,
2644 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2645 break;
2647 case REAL_CST:
2648 case FIXED_CST:
2649 case STRING_CST:
2650 case COMPLEX_CST:
2651 case CONSTRUCTOR:
2652 case INTEGER_CST:
2653 x = output_constant_def (target, 1);
2654 break;
2656 default:
2657 gcc_unreachable ();
2660 gcc_assert (MEM_P (x));
2661 x = XEXP (x, 0);
2663 value->base = x;
2664 value->offset = offset;
2668 static GTY((param_is (struct constant_descriptor_tree)))
2669 htab_t const_desc_htab;
2671 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2673 /* Constant pool accessor function. */
2675 htab_t
2676 constant_pool_htab (void)
2678 return const_desc_htab;
2681 /* Compute a hash code for a constant expression. */
2683 static hashval_t
2684 const_desc_hash (const void *ptr)
2686 return ((const struct constant_descriptor_tree *)ptr)->hash;
2689 static hashval_t
2690 const_hash_1 (const tree exp)
2692 const char *p;
2693 hashval_t hi;
2694 int len, i;
2695 enum tree_code code = TREE_CODE (exp);
2697 /* Either set P and LEN to the address and len of something to hash and
2698 exit the switch or return a value. */
2700 switch (code)
2702 case INTEGER_CST:
2703 p = (char *) &TREE_INT_CST (exp);
2704 len = sizeof TREE_INT_CST (exp);
2705 break;
2707 case REAL_CST:
2708 return real_hash (TREE_REAL_CST_PTR (exp));
2710 case FIXED_CST:
2711 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2713 case STRING_CST:
2714 p = TREE_STRING_POINTER (exp);
2715 len = TREE_STRING_LENGTH (exp);
2716 break;
2718 case COMPLEX_CST:
2719 return (const_hash_1 (TREE_REALPART (exp)) * 5
2720 + const_hash_1 (TREE_IMAGPART (exp)));
2722 case VECTOR_CST:
2724 tree link;
2726 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2728 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2729 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2731 return hi;
2734 case CONSTRUCTOR:
2736 unsigned HOST_WIDE_INT idx;
2737 tree value;
2739 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2741 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2742 if (value)
2743 hi = hi * 603 + const_hash_1 (value);
2745 return hi;
2748 case ADDR_EXPR:
2749 case FDESC_EXPR:
2751 struct addr_const value;
2753 decode_addr_const (exp, &value);
2754 switch (GET_CODE (value.base))
2756 case SYMBOL_REF:
2757 /* Don't hash the address of the SYMBOL_REF;
2758 only use the offset and the symbol name. */
2759 hi = value.offset;
2760 p = XSTR (value.base, 0);
2761 for (i = 0; p[i] != 0; i++)
2762 hi = ((hi * 613) + (unsigned) (p[i]));
2763 break;
2765 case LABEL_REF:
2766 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2767 break;
2769 default:
2770 gcc_unreachable ();
2773 return hi;
2775 case PLUS_EXPR:
2776 case POINTER_PLUS_EXPR:
2777 case MINUS_EXPR:
2778 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2779 + const_hash_1 (TREE_OPERAND (exp, 1)));
2781 CASE_CONVERT:
2782 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2784 default:
2785 /* A language specific constant. Just hash the code. */
2786 return code;
2789 /* Compute hashing function. */
2790 hi = len;
2791 for (i = 0; i < len; i++)
2792 hi = ((hi * 613) + (unsigned) (p[i]));
2794 return hi;
2797 /* Wrapper of compare_constant, for the htab interface. */
2798 static int
2799 const_desc_eq (const void *p1, const void *p2)
2801 const struct constant_descriptor_tree *const c1
2802 = (const struct constant_descriptor_tree *) p1;
2803 const struct constant_descriptor_tree *const c2
2804 = (const struct constant_descriptor_tree *) p2;
2805 if (c1->hash != c2->hash)
2806 return 0;
2807 return compare_constant (c1->value, c2->value);
2810 /* Compare t1 and t2, and return 1 only if they are known to result in
2811 the same bit pattern on output. */
2813 static int
2814 compare_constant (const tree t1, const tree t2)
2816 enum tree_code typecode;
2818 if (t1 == NULL_TREE)
2819 return t2 == NULL_TREE;
2820 if (t2 == NULL_TREE)
2821 return 0;
2823 if (TREE_CODE (t1) != TREE_CODE (t2))
2824 return 0;
2826 switch (TREE_CODE (t1))
2828 case INTEGER_CST:
2829 /* Integer constants are the same only if the same width of type. */
2830 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2831 return 0;
2832 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2833 return 0;
2834 return tree_int_cst_equal (t1, t2);
2836 case REAL_CST:
2837 /* Real constants are the same only if the same width of type. */
2838 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2839 return 0;
2841 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2843 case FIXED_CST:
2844 /* Fixed constants are the same only if the same width of type. */
2845 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2846 return 0;
2848 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
2850 case STRING_CST:
2851 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2852 return 0;
2854 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2855 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2856 TREE_STRING_LENGTH (t1)));
2858 case COMPLEX_CST:
2859 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2860 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2862 case VECTOR_CST:
2864 tree link1, link2;
2866 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
2867 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
2868 return 0;
2870 link2 = TREE_VECTOR_CST_ELTS (t2);
2871 for (link1 = TREE_VECTOR_CST_ELTS (t1);
2872 link1;
2873 link1 = TREE_CHAIN (link1))
2875 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
2876 return 0;
2877 link2 = TREE_CHAIN (link2);
2880 return 1;
2883 case CONSTRUCTOR:
2885 VEC(constructor_elt, gc) *v1, *v2;
2886 unsigned HOST_WIDE_INT idx;
2888 typecode = TREE_CODE (TREE_TYPE (t1));
2889 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2890 return 0;
2892 if (typecode == ARRAY_TYPE)
2894 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2895 /* For arrays, check that the sizes all match. */
2896 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2897 || size_1 == -1
2898 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2899 return 0;
2901 else
2903 /* For record and union constructors, require exact type
2904 equality. */
2905 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2906 return 0;
2909 v1 = CONSTRUCTOR_ELTS (t1);
2910 v2 = CONSTRUCTOR_ELTS (t2);
2911 if (VEC_length (constructor_elt, v1)
2912 != VEC_length (constructor_elt, v2))
2913 return 0;
2915 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
2917 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
2918 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
2920 /* Check that each value is the same... */
2921 if (!compare_constant (c1->value, c2->value))
2922 return 0;
2923 /* ... and that they apply to the same fields! */
2924 if (typecode == ARRAY_TYPE)
2926 if (!compare_constant (c1->index, c2->index))
2927 return 0;
2929 else
2931 if (c1->index != c2->index)
2932 return 0;
2936 return 1;
2939 case ADDR_EXPR:
2940 case FDESC_EXPR:
2942 struct addr_const value1, value2;
2943 enum rtx_code code;
2944 int ret;
2946 decode_addr_const (t1, &value1);
2947 decode_addr_const (t2, &value2);
2949 if (value1.offset != value2.offset)
2950 return 0;
2952 code = GET_CODE (value1.base);
2953 if (code != GET_CODE (value2.base))
2954 return 0;
2956 switch (code)
2958 case SYMBOL_REF:
2959 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2960 break;
2962 case LABEL_REF:
2963 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
2964 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
2965 break;
2967 default:
2968 gcc_unreachable ();
2970 return ret;
2973 case PLUS_EXPR:
2974 case POINTER_PLUS_EXPR:
2975 case MINUS_EXPR:
2976 case RANGE_EXPR:
2977 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2978 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2980 CASE_CONVERT:
2981 case VIEW_CONVERT_EXPR:
2982 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2984 default:
2985 return 0;
2988 gcc_unreachable ();
2991 /* Make a copy of the whole tree structure for a constant. This
2992 handles the same types of nodes that compare_constant handles. */
2994 static tree
2995 copy_constant (tree exp)
2997 switch (TREE_CODE (exp))
2999 case ADDR_EXPR:
3000 /* For ADDR_EXPR, we do not want to copy the decl whose address
3001 is requested. We do want to copy constants though. */
3002 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3003 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3004 copy_constant (TREE_OPERAND (exp, 0)));
3005 else
3006 return copy_node (exp);
3008 case INTEGER_CST:
3009 case REAL_CST:
3010 case FIXED_CST:
3011 case STRING_CST:
3012 return copy_node (exp);
3014 case COMPLEX_CST:
3015 return build_complex (TREE_TYPE (exp),
3016 copy_constant (TREE_REALPART (exp)),
3017 copy_constant (TREE_IMAGPART (exp)));
3019 case PLUS_EXPR:
3020 case POINTER_PLUS_EXPR:
3021 case MINUS_EXPR:
3022 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3023 copy_constant (TREE_OPERAND (exp, 0)),
3024 copy_constant (TREE_OPERAND (exp, 1)));
3026 CASE_CONVERT:
3027 case VIEW_CONVERT_EXPR:
3028 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3029 copy_constant (TREE_OPERAND (exp, 0)));
3031 case VECTOR_CST:
3032 return build_vector (TREE_TYPE (exp),
3033 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3035 case CONSTRUCTOR:
3037 tree copy = copy_node (exp);
3038 VEC(constructor_elt, gc) *v;
3039 unsigned HOST_WIDE_INT idx;
3040 tree purpose, value;
3042 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3043 CONSTRUCTOR_ELTS (exp)));
3044 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3046 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3047 ce->index = purpose;
3048 ce->value = copy_constant (value);
3050 CONSTRUCTOR_ELTS (copy) = v;
3051 return copy;
3054 default:
3055 gcc_unreachable ();
3059 /* Return the section into which constant EXP should be placed. */
3061 static section *
3062 get_constant_section (tree exp, unsigned int align)
3064 return targetm.asm_out.select_section (exp,
3065 compute_reloc_for_constant (exp),
3066 align);
3069 /* Return the size of constant EXP in bytes. */
3071 static HOST_WIDE_INT
3072 get_constant_size (tree exp)
3074 HOST_WIDE_INT size;
3076 size = int_size_in_bytes (TREE_TYPE (exp));
3077 if (TREE_CODE (exp) == STRING_CST)
3078 size = MAX (TREE_STRING_LENGTH (exp), size);
3079 return size;
3082 /* Subroutine of output_constant_def:
3083 No constant equal to EXP is known to have been output.
3084 Make a constant descriptor to enter EXP in the hash table.
3085 Assign the label number and construct RTL to refer to the
3086 constant's location in memory.
3087 Caller is responsible for updating the hash table. */
3089 static struct constant_descriptor_tree *
3090 build_constant_desc (tree exp)
3092 struct constant_descriptor_tree *desc;
3093 rtx symbol, rtl;
3094 char label[256];
3095 int labelno;
3096 tree decl;
3098 desc = ggc_alloc_constant_descriptor_tree ();
3099 desc->value = copy_constant (exp);
3101 /* Propagate marked-ness to copied constant. */
3102 if (flag_mudflap && mf_marked_p (exp))
3103 mf_mark (desc->value);
3105 /* Create a string containing the label name, in LABEL. */
3106 labelno = const_labelno++;
3107 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3109 /* Construct the VAR_DECL associated with the constant. */
3110 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3111 TREE_TYPE (exp));
3112 DECL_ARTIFICIAL (decl) = 1;
3113 DECL_IGNORED_P (decl) = 1;
3114 TREE_READONLY (decl) = 1;
3115 TREE_STATIC (decl) = 1;
3116 TREE_ADDRESSABLE (decl) = 1;
3117 /* We don't set the RTL yet as this would cause varpool to assume that the
3118 variable is referenced. Moreover, it would just be dropped in LTO mode.
3119 Instead we set the flag that will be recognized in make_decl_rtl. */
3120 DECL_IN_CONSTANT_POOL (decl) = 1;
3121 DECL_INITIAL (decl) = desc->value;
3122 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3123 architectures so use DATA_ALIGNMENT as well, except for strings. */
3124 if (TREE_CODE (exp) == STRING_CST)
3126 #ifdef CONSTANT_ALIGNMENT
3127 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3128 #endif
3130 else
3131 align_variable (decl, 0);
3133 /* Now construct the SYMBOL_REF and the MEM. */
3134 if (use_object_blocks_p ())
3136 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3137 symbol = create_block_symbol (ggc_strdup (label),
3138 get_block_for_section (sect), -1);
3140 else
3141 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3142 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3143 SET_SYMBOL_REF_DECL (symbol, decl);
3144 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3146 rtl = gen_const_mem (TYPE_MODE (TREE_TYPE (exp)), symbol);
3147 set_mem_attributes (rtl, exp, 1);
3148 set_mem_alias_set (rtl, 0);
3149 set_mem_alias_set (rtl, const_alias_set);
3151 /* We cannot share RTX'es in pool entries.
3152 Mark this piece of RTL as required for unsharing. */
3153 RTX_FLAG (rtl, used) = 1;
3155 /* Set flags or add text to the name to record information, such as
3156 that it is a local symbol. If the name is changed, the macro
3157 ASM_OUTPUT_LABELREF will have to know how to strip this
3158 information. This call might invalidate our local variable
3159 SYMBOL; we can't use it afterward. */
3160 targetm.encode_section_info (exp, rtl, true);
3162 desc->rtl = rtl;
3164 return desc;
3167 /* Return an rtx representing a reference to constant data in memory
3168 for the constant expression EXP.
3170 If assembler code for such a constant has already been output,
3171 return an rtx to refer to it.
3172 Otherwise, output such a constant in memory
3173 and generate an rtx for it.
3175 If DEFER is nonzero, this constant can be deferred and output only
3176 if referenced in the function after all optimizations.
3178 `const_desc_table' records which constants already have label strings. */
3181 output_constant_def (tree exp, int defer)
3183 struct constant_descriptor_tree *desc;
3184 struct constant_descriptor_tree key;
3185 void **loc;
3187 /* Look up EXP in the table of constant descriptors. If we didn't find
3188 it, create a new one. */
3189 key.value = exp;
3190 key.hash = const_hash_1 (exp);
3191 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3193 desc = (struct constant_descriptor_tree *) *loc;
3194 if (desc == 0)
3196 desc = build_constant_desc (exp);
3197 desc->hash = key.hash;
3198 *loc = desc;
3201 maybe_output_constant_def_contents (desc, defer);
3202 return desc->rtl;
3205 /* Subroutine of output_constant_def: Decide whether or not we need to
3206 output the constant DESC now, and if so, do it. */
3207 static void
3208 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3209 int defer)
3211 rtx symbol = XEXP (desc->rtl, 0);
3212 tree exp = desc->value;
3214 if (flag_syntax_only)
3215 return;
3217 if (TREE_ASM_WRITTEN (exp))
3218 /* Already output; don't do it again. */
3219 return;
3221 /* We can always defer constants as long as the context allows
3222 doing so. */
3223 if (defer)
3225 /* Increment n_deferred_constants if it exists. It needs to be at
3226 least as large as the number of constants actually referred to
3227 by the function. If it's too small we'll stop looking too early
3228 and fail to emit constants; if it's too large we'll only look
3229 through the entire function when we could have stopped earlier. */
3230 if (cfun)
3231 n_deferred_constants++;
3232 return;
3235 output_constant_def_contents (symbol);
3238 /* Subroutine of output_constant_def_contents. Output the definition
3239 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3240 constant's alignment in bits. */
3242 static void
3243 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3245 HOST_WIDE_INT size;
3247 size = get_constant_size (exp);
3249 /* Do any machine/system dependent processing of the constant. */
3250 targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3252 /* Output the value of EXP. */
3253 output_constant (exp, size, align);
3256 /* We must output the constant data referred to by SYMBOL; do so. */
3258 static void
3259 output_constant_def_contents (rtx symbol)
3261 tree decl = SYMBOL_REF_DECL (symbol);
3262 tree exp = DECL_INITIAL (decl);
3263 unsigned int align;
3265 /* Make sure any other constants whose addresses appear in EXP
3266 are assigned label numbers. */
3267 output_addressed_constants (exp);
3269 /* We are no longer deferring this constant. */
3270 TREE_ASM_WRITTEN (decl) = TREE_ASM_WRITTEN (exp) = 1;
3272 /* If the constant is part of an object block, make sure that the
3273 decl has been positioned within its block, but do not write out
3274 its definition yet. output_object_blocks will do that later. */
3275 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3276 place_block_symbol (symbol);
3277 else
3279 align = DECL_ALIGN (decl);
3280 switch_to_section (get_constant_section (exp, align));
3281 if (align > BITS_PER_UNIT)
3282 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3283 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3285 if (flag_mudflap)
3286 mudflap_enqueue_constant (exp);
3289 /* Look up EXP in the table of constant descriptors. Return the rtl
3290 if it has been emitted, else null. */
3293 lookup_constant_def (tree exp)
3295 struct constant_descriptor_tree *desc;
3296 struct constant_descriptor_tree key;
3298 key.value = exp;
3299 key.hash = const_hash_1 (exp);
3300 desc = (struct constant_descriptor_tree *)
3301 htab_find_with_hash (const_desc_htab, &key, key.hash);
3303 return (desc ? desc->rtl : NULL_RTX);
3306 /* Return a tree representing a reference to constant data in memory
3307 for the constant expression EXP.
3309 This is the counterpart of output_constant_def at the Tree level. */
3311 tree
3312 tree_output_constant_def (tree exp)
3314 struct constant_descriptor_tree *desc, key;
3315 void **loc;
3316 tree decl;
3318 /* Look up EXP in the table of constant descriptors. If we didn't find
3319 it, create a new one. */
3320 key.value = exp;
3321 key.hash = const_hash_1 (exp);
3322 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3324 desc = (struct constant_descriptor_tree *) *loc;
3325 if (desc == 0)
3327 desc = build_constant_desc (exp);
3328 desc->hash = key.hash;
3329 *loc = desc;
3332 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3333 varpool_finalize_decl (decl);
3334 return decl;
3337 /* Used in the hash tables to avoid outputting the same constant
3338 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3339 are output once per function, not once per file. */
3340 /* ??? Only a few targets need per-function constant pools. Most
3341 can use one per-file pool. Should add a targetm bit to tell the
3342 difference. */
3344 struct GTY(()) rtx_constant_pool {
3345 /* Pointers to first and last constant in pool, as ordered by offset. */
3346 struct constant_descriptor_rtx *first;
3347 struct constant_descriptor_rtx *last;
3349 /* Hash facility for making memory-constants from constant rtl-expressions.
3350 It is used on RISC machines where immediate integer arguments and
3351 constant addresses are restricted so that such constants must be stored
3352 in memory. */
3353 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3355 /* Current offset in constant pool (does not include any
3356 machine-specific header). */
3357 HOST_WIDE_INT offset;
3360 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3361 struct constant_descriptor_rtx *next;
3362 rtx mem;
3363 rtx sym;
3364 rtx constant;
3365 HOST_WIDE_INT offset;
3366 hashval_t hash;
3367 enum machine_mode mode;
3368 unsigned int align;
3369 int labelno;
3370 int mark;
3373 /* Hash and compare functions for const_rtx_htab. */
3375 static hashval_t
3376 const_desc_rtx_hash (const void *ptr)
3378 const struct constant_descriptor_rtx *const desc
3379 = (const struct constant_descriptor_rtx *) ptr;
3380 return desc->hash;
3383 static int
3384 const_desc_rtx_eq (const void *a, const void *b)
3386 const struct constant_descriptor_rtx *const x
3387 = (const struct constant_descriptor_rtx *) a;
3388 const struct constant_descriptor_rtx *const y
3389 = (const struct constant_descriptor_rtx *) b;
3391 if (x->mode != y->mode)
3392 return 0;
3393 return rtx_equal_p (x->constant, y->constant);
3396 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3398 static int
3399 const_rtx_hash_1 (rtx *xp, void *data)
3401 unsigned HOST_WIDE_INT hwi;
3402 enum machine_mode mode;
3403 enum rtx_code code;
3404 hashval_t h, *hp;
3405 rtx x;
3407 x = *xp;
3408 code = GET_CODE (x);
3409 mode = GET_MODE (x);
3410 h = (hashval_t) code * 1048573 + mode;
3412 switch (code)
3414 case CONST_INT:
3415 hwi = INTVAL (x);
3416 fold_hwi:
3418 int shift = sizeof (hashval_t) * CHAR_BIT;
3419 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3420 int i;
3422 h ^= (hashval_t) hwi;
3423 for (i = 1; i < n; ++i)
3425 hwi >>= shift;
3426 h ^= (hashval_t) hwi;
3429 break;
3431 case CONST_DOUBLE:
3432 if (mode == VOIDmode)
3434 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3435 goto fold_hwi;
3437 else
3438 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3439 break;
3441 case CONST_FIXED:
3442 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3443 break;
3445 case CONST_VECTOR:
3447 int i;
3448 for (i = XVECLEN (x, 0); i-- > 0; )
3449 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3451 break;
3453 case SYMBOL_REF:
3454 h ^= htab_hash_string (XSTR (x, 0));
3455 break;
3457 case LABEL_REF:
3458 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3459 break;
3461 case UNSPEC:
3462 case UNSPEC_VOLATILE:
3463 h = h * 251 + XINT (x, 1);
3464 break;
3466 default:
3467 break;
3470 hp = (hashval_t *) data;
3471 *hp = *hp * 509 + h;
3472 return 0;
3475 /* Compute a hash value for X, which should be a constant. */
3477 static hashval_t
3478 const_rtx_hash (rtx x)
3480 hashval_t h = 0;
3481 for_each_rtx (&x, const_rtx_hash_1, &h);
3482 return h;
3486 /* Create and return a new rtx constant pool. */
3488 static struct rtx_constant_pool *
3489 create_constant_pool (void)
3491 struct rtx_constant_pool *pool;
3493 pool = ggc_alloc_rtx_constant_pool ();
3494 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3495 const_desc_rtx_eq, NULL);
3496 pool->first = NULL;
3497 pool->last = NULL;
3498 pool->offset = 0;
3499 return pool;
3502 /* Initialize constant pool hashing for a new function. */
3504 void
3505 init_varasm_status (void)
3507 crtl->varasm.pool = create_constant_pool ();
3508 crtl->varasm.deferred_constants = 0;
3511 /* Given a MINUS expression, simplify it if both sides
3512 include the same symbol. */
3515 simplify_subtraction (rtx x)
3517 rtx r = simplify_rtx (x);
3518 return r ? r : x;
3521 /* Given a constant rtx X, make (or find) a memory constant for its value
3522 and return a MEM rtx to refer to it in memory. */
3525 force_const_mem (enum machine_mode mode, rtx x)
3527 struct constant_descriptor_rtx *desc, tmp;
3528 struct rtx_constant_pool *pool;
3529 char label[256];
3530 rtx def, symbol;
3531 hashval_t hash;
3532 unsigned int align;
3533 void **slot;
3535 /* If we're not allowed to drop X into the constant pool, don't. */
3536 if (targetm.cannot_force_const_mem (mode, x))
3537 return NULL_RTX;
3539 /* Record that this function has used a constant pool entry. */
3540 crtl->uses_const_pool = 1;
3542 /* Decide which pool to use. */
3543 pool = (targetm.use_blocks_for_constant_p (mode, x)
3544 ? shared_constant_pool
3545 : crtl->varasm.pool);
3547 /* Lookup the value in the hashtable. */
3548 tmp.constant = x;
3549 tmp.mode = mode;
3550 hash = const_rtx_hash (x);
3551 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3552 desc = (struct constant_descriptor_rtx *) *slot;
3554 /* If the constant was already present, return its memory. */
3555 if (desc)
3556 return copy_rtx (desc->mem);
3558 /* Otherwise, create a new descriptor. */
3559 desc = ggc_alloc_constant_descriptor_rtx ();
3560 *slot = desc;
3562 /* Align the location counter as required by EXP's data type. */
3563 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3564 #ifdef CONSTANT_ALIGNMENT
3566 tree type = lang_hooks.types.type_for_mode (mode, 0);
3567 if (type != NULL_TREE)
3568 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3570 #endif
3572 pool->offset += (align / BITS_PER_UNIT) - 1;
3573 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3575 desc->next = NULL;
3576 desc->constant = copy_rtx (tmp.constant);
3577 desc->offset = pool->offset;
3578 desc->hash = hash;
3579 desc->mode = mode;
3580 desc->align = align;
3581 desc->labelno = const_labelno;
3582 desc->mark = 0;
3584 pool->offset += GET_MODE_SIZE (mode);
3585 if (pool->last)
3586 pool->last->next = desc;
3587 else
3588 pool->first = pool->last = desc;
3589 pool->last = desc;
3591 /* Create a string containing the label name, in LABEL. */
3592 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3593 ++const_labelno;
3595 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3596 the constants pool. */
3597 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3599 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3600 symbol = create_block_symbol (ggc_strdup (label),
3601 get_block_for_section (sect), -1);
3603 else
3604 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3605 desc->sym = symbol;
3606 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3607 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3608 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3610 /* Construct the MEM. */
3611 desc->mem = def = gen_const_mem (mode, symbol);
3612 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3613 set_mem_align (def, align);
3615 /* If we're dropping a label to the constant pool, make sure we
3616 don't delete it. */
3617 if (GET_CODE (x) == LABEL_REF)
3618 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3620 return copy_rtx (def);
3623 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3626 get_pool_constant (rtx addr)
3628 return SYMBOL_REF_CONSTANT (addr)->constant;
3631 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3632 and whether it has been output or not. */
3635 get_pool_constant_mark (rtx addr, bool *pmarked)
3637 struct constant_descriptor_rtx *desc;
3639 desc = SYMBOL_REF_CONSTANT (addr);
3640 *pmarked = (desc->mark != 0);
3641 return desc->constant;
3644 /* Similar, return the mode. */
3646 enum machine_mode
3647 get_pool_mode (const_rtx addr)
3649 return SYMBOL_REF_CONSTANT (addr)->mode;
3652 /* Return the size of the constant pool. */
3655 get_pool_size (void)
3657 return crtl->varasm.pool->offset;
3660 /* Worker function for output_constant_pool_1. Emit assembly for X
3661 in MODE with known alignment ALIGN. */
3663 static void
3664 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3666 switch (GET_MODE_CLASS (mode))
3668 case MODE_FLOAT:
3669 case MODE_DECIMAL_FLOAT:
3671 REAL_VALUE_TYPE r;
3673 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3674 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3675 assemble_real (r, mode, align);
3676 break;
3679 case MODE_INT:
3680 case MODE_PARTIAL_INT:
3681 case MODE_FRACT:
3682 case MODE_UFRACT:
3683 case MODE_ACCUM:
3684 case MODE_UACCUM:
3685 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3686 break;
3688 case MODE_VECTOR_FLOAT:
3689 case MODE_VECTOR_INT:
3690 case MODE_VECTOR_FRACT:
3691 case MODE_VECTOR_UFRACT:
3692 case MODE_VECTOR_ACCUM:
3693 case MODE_VECTOR_UACCUM:
3695 int i, units;
3696 enum machine_mode submode = GET_MODE_INNER (mode);
3697 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3699 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3700 units = CONST_VECTOR_NUNITS (x);
3702 for (i = 0; i < units; i++)
3704 rtx elt = CONST_VECTOR_ELT (x, i);
3705 output_constant_pool_2 (submode, elt, i ? subalign : align);
3708 break;
3710 default:
3711 gcc_unreachable ();
3715 /* Worker function for output_constant_pool. Emit constant DESC,
3716 giving it ALIGN bits of alignment. */
3718 static void
3719 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3720 unsigned int align)
3722 rtx x, tmp;
3724 x = desc->constant;
3726 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3727 whose CODE_LABEL has been deleted. This can occur if a jump table
3728 is eliminated by optimization. If so, write a constant of zero
3729 instead. Note that this can also happen by turning the
3730 CODE_LABEL into a NOTE. */
3731 /* ??? This seems completely and utterly wrong. Certainly it's
3732 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3733 functioning even with INSN_DELETED_P and friends. */
3735 tmp = x;
3736 switch (GET_CODE (tmp))
3738 case CONST:
3739 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3740 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3741 break;
3742 tmp = XEXP (XEXP (tmp, 0), 0);
3743 /* FALLTHRU */
3745 case LABEL_REF:
3746 tmp = XEXP (tmp, 0);
3747 gcc_assert (!INSN_DELETED_P (tmp));
3748 gcc_assert (!NOTE_P (tmp)
3749 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3750 break;
3752 default:
3753 break;
3756 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3757 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3758 align, desc->labelno, done);
3759 #endif
3761 assemble_align (align);
3763 /* Output the label. */
3764 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3766 /* Output the data. */
3767 output_constant_pool_2 (desc->mode, x, align);
3769 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3770 sections have proper size. */
3771 if (align > GET_MODE_BITSIZE (desc->mode)
3772 && in_section
3773 && (in_section->common.flags & SECTION_MERGE))
3774 assemble_align (align);
3776 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3777 done:
3778 #endif
3779 return;
3782 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3783 to as used. Emit referenced deferred strings. This function can
3784 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3786 static int
3787 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3789 rtx x = *current_rtx;
3791 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3792 return 0;
3794 if (CONSTANT_POOL_ADDRESS_P (x))
3796 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3797 if (desc->mark == 0)
3799 desc->mark = 1;
3800 for_each_rtx (&desc->constant, mark_constant, NULL);
3803 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3805 tree decl = SYMBOL_REF_DECL (x);
3806 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
3808 n_deferred_constants--;
3809 output_constant_def_contents (x);
3813 return -1;
3816 /* Look through appropriate parts of INSN, marking all entries in the
3817 constant pool which are actually being used. Entries that are only
3818 referenced by other constants are also marked as used. Emit
3819 deferred strings that are used. */
3821 static void
3822 mark_constants (rtx insn)
3824 if (!INSN_P (insn))
3825 return;
3827 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3828 insns, not any notes that may be attached. We don't want to mark
3829 a constant just because it happens to appear in a REG_EQUIV note. */
3830 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3832 rtx seq = PATTERN (insn);
3833 int i, n = XVECLEN (seq, 0);
3834 for (i = 0; i < n; ++i)
3836 rtx subinsn = XVECEXP (seq, 0, i);
3837 if (INSN_P (subinsn))
3838 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
3841 else
3842 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
3845 /* Look through the instructions for this function, and mark all the
3846 entries in POOL which are actually being used. Emit deferred constants
3847 which have indeed been used. */
3849 static void
3850 mark_constant_pool (void)
3852 rtx insn, link;
3854 if (!crtl->uses_const_pool && n_deferred_constants == 0)
3855 return;
3857 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3858 mark_constants (insn);
3860 for (link = crtl->epilogue_delay_list;
3861 link;
3862 link = XEXP (link, 1))
3863 mark_constants (XEXP (link, 0));
3866 /* Write all the constants in POOL. */
3868 static void
3869 output_constant_pool_contents (struct rtx_constant_pool *pool)
3871 struct constant_descriptor_rtx *desc;
3873 for (desc = pool->first; desc ; desc = desc->next)
3874 if (desc->mark)
3876 /* If the constant is part of an object_block, make sure that
3877 the constant has been positioned within its block, but do not
3878 write out its definition yet. output_object_blocks will do
3879 that later. */
3880 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
3881 && SYMBOL_REF_BLOCK (desc->sym))
3882 place_block_symbol (desc->sym);
3883 else
3885 switch_to_section (targetm.asm_out.select_rtx_section
3886 (desc->mode, desc->constant, desc->align));
3887 output_constant_pool_1 (desc, desc->align);
3892 /* Mark all constants that are used in the current function, then write
3893 out the function's private constant pool. */
3895 static void
3896 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3897 tree fndecl ATTRIBUTE_UNUSED)
3899 struct rtx_constant_pool *pool = crtl->varasm.pool;
3901 /* It is possible for gcc to call force_const_mem and then to later
3902 discard the instructions which refer to the constant. In such a
3903 case we do not need to output the constant. */
3904 mark_constant_pool ();
3906 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3907 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3908 #endif
3910 output_constant_pool_contents (pool);
3912 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3913 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3914 #endif
3917 /* Write the contents of the shared constant pool. */
3919 void
3920 output_shared_constant_pool (void)
3922 output_constant_pool_contents (shared_constant_pool);
3925 /* Determine what kind of relocations EXP may need. */
3928 compute_reloc_for_constant (tree exp)
3930 int reloc = 0, reloc2;
3931 tree tem;
3933 switch (TREE_CODE (exp))
3935 case ADDR_EXPR:
3936 case FDESC_EXPR:
3937 /* Go inside any operations that get_inner_reference can handle and see
3938 if what's inside is a constant: no need to do anything here for
3939 addresses of variables or functions. */
3940 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3941 tem = TREE_OPERAND (tem, 0))
3944 if (TREE_PUBLIC (tem))
3945 reloc |= 2;
3946 else
3947 reloc |= 1;
3948 break;
3950 case PLUS_EXPR:
3951 case POINTER_PLUS_EXPR:
3952 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3953 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3954 break;
3956 case MINUS_EXPR:
3957 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3958 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3959 /* The difference of two local labels is computable at link time. */
3960 if (reloc == 1 && reloc2 == 1)
3961 reloc = 0;
3962 else
3963 reloc |= reloc2;
3964 break;
3966 CASE_CONVERT:
3967 case VIEW_CONVERT_EXPR:
3968 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3969 break;
3971 case CONSTRUCTOR:
3973 unsigned HOST_WIDE_INT idx;
3974 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
3975 if (tem != 0)
3976 reloc |= compute_reloc_for_constant (tem);
3978 break;
3980 default:
3981 break;
3983 return reloc;
3986 /* Find all the constants whose addresses are referenced inside of EXP,
3987 and make sure assembler code with a label has been output for each one.
3988 Indicate whether an ADDR_EXPR has been encountered. */
3990 static void
3991 output_addressed_constants (tree exp)
3993 tree tem;
3995 switch (TREE_CODE (exp))
3997 case ADDR_EXPR:
3998 case FDESC_EXPR:
3999 /* Go inside any operations that get_inner_reference can handle and see
4000 if what's inside is a constant: no need to do anything here for
4001 addresses of variables or functions. */
4002 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4003 tem = TREE_OPERAND (tem, 0))
4006 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4007 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4008 tem = DECL_INITIAL (tem);
4010 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4011 output_constant_def (tem, 0);
4012 break;
4014 case PLUS_EXPR:
4015 case POINTER_PLUS_EXPR:
4016 case MINUS_EXPR:
4017 output_addressed_constants (TREE_OPERAND (exp, 1));
4018 /* Fall through. */
4020 CASE_CONVERT:
4021 case VIEW_CONVERT_EXPR:
4022 output_addressed_constants (TREE_OPERAND (exp, 0));
4023 break;
4025 case CONSTRUCTOR:
4027 unsigned HOST_WIDE_INT idx;
4028 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4029 if (tem != 0)
4030 output_addressed_constants (tem);
4032 break;
4034 default:
4035 break;
4039 /* Whether a constructor CTOR is a valid static constant initializer if all
4040 its elements are. This used to be internal to initializer_constant_valid_p
4041 and has been exposed to let other functions like categorize_ctor_elements
4042 evaluate the property while walking a constructor for other purposes. */
4044 bool
4045 constructor_static_from_elts_p (const_tree ctor)
4047 return (TREE_CONSTANT (ctor)
4048 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4049 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE
4050 || TREE_CODE (TREE_TYPE (ctor)) == ARRAY_TYPE));
4053 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4054 tree *cache);
4056 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4057 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4058 which are valid when ENDTYPE is an integer of any size; in
4059 particular, this does not accept a pointer minus a constant. This
4060 returns null_pointer_node if the VALUE is an absolute constant
4061 which can be used to initialize a static variable. Otherwise it
4062 returns NULL. */
4064 static tree
4065 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4067 tree op0, op1;
4069 if (!INTEGRAL_TYPE_P (endtype))
4070 return NULL_TREE;
4072 op0 = TREE_OPERAND (value, 0);
4073 op1 = TREE_OPERAND (value, 1);
4075 /* Like STRIP_NOPS except allow the operand mode to widen. This
4076 works around a feature of fold that simplifies (int)(p1 - p2) to
4077 ((int)p1 - (int)p2) under the theory that the narrower operation
4078 is cheaper. */
4080 while (CONVERT_EXPR_P (op0)
4081 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4083 tree inner = TREE_OPERAND (op0, 0);
4084 if (inner == error_mark_node
4085 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4086 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4087 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4088 break;
4089 op0 = inner;
4092 while (CONVERT_EXPR_P (op1)
4093 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4095 tree inner = TREE_OPERAND (op1, 0);
4096 if (inner == error_mark_node
4097 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4098 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4099 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4100 break;
4101 op1 = inner;
4104 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4105 if (!op0)
4106 return NULL_TREE;
4108 op1 = initializer_constant_valid_p_1 (op1, endtype,
4109 cache ? cache + 2 : NULL);
4110 /* Both initializers must be known. */
4111 if (op1)
4113 if (op0 == op1
4114 && (op0 == null_pointer_node
4115 || TREE_CODE (value) == MINUS_EXPR))
4116 return null_pointer_node;
4118 /* Support differences between labels. */
4119 if (TREE_CODE (op0) == LABEL_DECL
4120 && TREE_CODE (op1) == LABEL_DECL)
4121 return null_pointer_node;
4123 if (TREE_CODE (op0) == STRING_CST
4124 && TREE_CODE (op1) == STRING_CST
4125 && operand_equal_p (op0, op1, 1))
4126 return null_pointer_node;
4129 return NULL_TREE;
4132 /* Helper function of initializer_constant_valid_p.
4133 Return nonzero if VALUE is a valid constant-valued expression
4134 for use in initializing a static variable; one that can be an
4135 element of a "constant" initializer.
4137 Return null_pointer_node if the value is absolute;
4138 if it is relocatable, return the variable that determines the relocation.
4139 We assume that VALUE has been folded as much as possible;
4140 therefore, we do not need to check for such things as
4141 arithmetic-combinations of integers.
4143 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4145 static tree
4146 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4148 tree ret;
4150 switch (TREE_CODE (value))
4152 case CONSTRUCTOR:
4153 if (constructor_static_from_elts_p (value))
4155 unsigned HOST_WIDE_INT idx;
4156 tree elt;
4157 bool absolute = true;
4159 if (cache && cache[0] == value)
4160 return cache[1];
4161 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4163 tree reloc;
4164 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4165 NULL);
4166 if (!reloc)
4168 if (cache)
4170 cache[0] = value;
4171 cache[1] = NULL_TREE;
4173 return NULL_TREE;
4175 if (reloc != null_pointer_node)
4176 absolute = false;
4178 /* For a non-absolute relocation, there is no single
4179 variable that can be "the variable that determines the
4180 relocation." */
4181 if (cache)
4183 cache[0] = value;
4184 cache[1] = absolute ? null_pointer_node : error_mark_node;
4186 return absolute ? null_pointer_node : error_mark_node;
4189 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4191 case INTEGER_CST:
4192 case VECTOR_CST:
4193 case REAL_CST:
4194 case FIXED_CST:
4195 case STRING_CST:
4196 case COMPLEX_CST:
4197 return null_pointer_node;
4199 case ADDR_EXPR:
4200 case FDESC_EXPR:
4202 tree op0 = staticp (TREE_OPERAND (value, 0));
4203 if (op0)
4205 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4206 to be a constant, this is old-skool offsetof-like nonsense. */
4207 if (TREE_CODE (op0) == INDIRECT_REF
4208 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4209 return null_pointer_node;
4210 /* Taking the address of a nested function involves a trampoline,
4211 unless we don't need or want one. */
4212 if (TREE_CODE (op0) == FUNCTION_DECL
4213 && DECL_STATIC_CHAIN (op0)
4214 && !TREE_NO_TRAMPOLINE (value))
4215 return NULL_TREE;
4216 /* "&{...}" requires a temporary to hold the constructed
4217 object. */
4218 if (TREE_CODE (op0) == CONSTRUCTOR)
4219 return NULL_TREE;
4221 return op0;
4224 case NON_LVALUE_EXPR:
4225 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4226 endtype, cache);
4228 case VIEW_CONVERT_EXPR:
4230 tree src = TREE_OPERAND (value, 0);
4231 tree src_type = TREE_TYPE (src);
4232 tree dest_type = TREE_TYPE (value);
4234 /* Allow view-conversions from aggregate to non-aggregate type only
4235 if the bit pattern is fully preserved afterwards; otherwise, the
4236 RTL expander won't be able to apply a subsequent transformation
4237 to the underlying constructor. */
4238 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4240 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4241 return initializer_constant_valid_p_1 (src, endtype, cache);
4242 else
4243 return NULL_TREE;
4246 /* Allow all other kinds of view-conversion. */
4247 return initializer_constant_valid_p_1 (src, endtype, cache);
4250 CASE_CONVERT:
4252 tree src = TREE_OPERAND (value, 0);
4253 tree src_type = TREE_TYPE (src);
4254 tree dest_type = TREE_TYPE (value);
4256 /* Allow conversions between pointer types, floating-point
4257 types, and offset types. */
4258 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4259 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4260 || (TREE_CODE (dest_type) == OFFSET_TYPE
4261 && TREE_CODE (src_type) == OFFSET_TYPE))
4262 return initializer_constant_valid_p_1 (src, endtype, cache);
4264 /* Allow length-preserving conversions between integer types. */
4265 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4266 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4267 return initializer_constant_valid_p_1 (src, endtype, cache);
4269 /* Allow conversions between other integer types only if
4270 explicit value. */
4271 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4273 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4274 if (inner == null_pointer_node)
4275 return null_pointer_node;
4276 break;
4279 /* Allow (int) &foo provided int is as wide as a pointer. */
4280 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4281 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4282 return initializer_constant_valid_p_1 (src, endtype, cache);
4284 /* Likewise conversions from int to pointers, but also allow
4285 conversions from 0. */
4286 if ((POINTER_TYPE_P (dest_type)
4287 || TREE_CODE (dest_type) == OFFSET_TYPE)
4288 && INTEGRAL_TYPE_P (src_type))
4290 if (TREE_CODE (src) == INTEGER_CST
4291 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4292 return null_pointer_node;
4293 if (integer_zerop (src))
4294 return null_pointer_node;
4295 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4296 return initializer_constant_valid_p_1 (src, endtype, cache);
4299 /* Allow conversions to struct or union types if the value
4300 inside is okay. */
4301 if (TREE_CODE (dest_type) == RECORD_TYPE
4302 || TREE_CODE (dest_type) == UNION_TYPE)
4303 return initializer_constant_valid_p_1 (src, endtype, cache);
4305 break;
4307 case POINTER_PLUS_EXPR:
4308 case PLUS_EXPR:
4309 /* Any valid floating-point constants will have been folded by now;
4310 with -frounding-math we hit this with addition of two constants. */
4311 if (TREE_CODE (endtype) == REAL_TYPE)
4312 return NULL_TREE;
4313 if (cache && cache[0] == value)
4314 return cache[1];
4315 if (! INTEGRAL_TYPE_P (endtype)
4316 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4318 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4319 tree valid0
4320 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4321 endtype, ncache);
4322 tree valid1
4323 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4324 endtype, ncache + 2);
4325 /* If either term is absolute, use the other term's relocation. */
4326 if (valid0 == null_pointer_node)
4327 ret = valid1;
4328 else if (valid1 == null_pointer_node)
4329 ret = valid0;
4330 /* Support narrowing pointer differences. */
4331 else
4332 ret = narrowing_initializer_constant_valid_p (value, endtype,
4333 ncache);
4335 else
4336 /* Support narrowing pointer differences. */
4337 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4338 if (cache)
4340 cache[0] = value;
4341 cache[1] = ret;
4343 return ret;
4345 case MINUS_EXPR:
4346 if (TREE_CODE (endtype) == REAL_TYPE)
4347 return NULL_TREE;
4348 if (cache && cache[0] == value)
4349 return cache[1];
4350 if (! INTEGRAL_TYPE_P (endtype)
4351 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4353 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4354 tree valid0
4355 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4356 endtype, ncache);
4357 tree valid1
4358 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4359 endtype, ncache + 2);
4360 /* Win if second argument is absolute. */
4361 if (valid1 == null_pointer_node)
4362 ret = valid0;
4363 /* Win if both arguments have the same relocation.
4364 Then the value is absolute. */
4365 else if (valid0 == valid1 && valid0 != 0)
4366 ret = null_pointer_node;
4367 /* Since GCC guarantees that string constants are unique in the
4368 generated code, a subtraction between two copies of the same
4369 constant string is absolute. */
4370 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4371 && valid1 && TREE_CODE (valid1) == STRING_CST
4372 && operand_equal_p (valid0, valid1, 1))
4373 ret = null_pointer_node;
4374 /* Support narrowing differences. */
4375 else
4376 ret = narrowing_initializer_constant_valid_p (value, endtype,
4377 ncache);
4379 else
4380 /* Support narrowing differences. */
4381 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4382 if (cache)
4384 cache[0] = value;
4385 cache[1] = ret;
4387 return ret;
4389 default:
4390 break;
4393 return NULL_TREE;
4396 /* Return nonzero if VALUE is a valid constant-valued expression
4397 for use in initializing a static variable; one that can be an
4398 element of a "constant" initializer.
4400 Return null_pointer_node if the value is absolute;
4401 if it is relocatable, return the variable that determines the relocation.
4402 We assume that VALUE has been folded as much as possible;
4403 therefore, we do not need to check for such things as
4404 arithmetic-combinations of integers. */
4405 tree
4406 initializer_constant_valid_p (tree value, tree endtype)
4408 return initializer_constant_valid_p_1 (value, endtype, NULL);
4411 /* Return true if VALUE is a valid constant-valued expression
4412 for use in initializing a static bit-field; one that can be
4413 an element of a "constant" initializer. */
4415 bool
4416 initializer_constant_valid_for_bitfield_p (tree value)
4418 /* For bitfields we support integer constants or possibly nested aggregates
4419 of such. */
4420 switch (TREE_CODE (value))
4422 case CONSTRUCTOR:
4424 unsigned HOST_WIDE_INT idx;
4425 tree elt;
4427 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4428 if (!initializer_constant_valid_for_bitfield_p (elt))
4429 return false;
4430 return true;
4433 case INTEGER_CST:
4434 return true;
4436 case VIEW_CONVERT_EXPR:
4437 case NON_LVALUE_EXPR:
4438 return
4439 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4441 default:
4442 break;
4445 return false;
4448 /* output_constructor outer state of relevance in recursive calls, typically
4449 for nested aggregate bitfields. */
4451 typedef struct {
4452 unsigned int bit_offset; /* current position in ... */
4453 int byte; /* ... the outer byte buffer. */
4454 } oc_outer_state;
4456 static unsigned HOST_WIDE_INT
4457 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4458 oc_outer_state *);
4460 /* Output assembler code for constant EXP to FILE, with no label.
4461 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4462 Assumes output_addressed_constants has been done on EXP already.
4464 Generate exactly SIZE bytes of assembler data, padding at the end
4465 with zeros if necessary. SIZE must always be specified.
4467 SIZE is important for structure constructors,
4468 since trailing members may have been omitted from the constructor.
4469 It is also important for initialization of arrays from string constants
4470 since the full length of the string constant might not be wanted.
4471 It is also needed for initialization of unions, where the initializer's
4472 type is just one member, and that may not be as long as the union.
4474 There a case in which we would fail to output exactly SIZE bytes:
4475 for a structure constructor that wants to produce more than SIZE bytes.
4476 But such constructors will never be generated for any possible input.
4478 ALIGN is the alignment of the data in bits. */
4480 void
4481 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4483 enum tree_code code;
4484 unsigned HOST_WIDE_INT thissize;
4486 if (size == 0 || flag_syntax_only)
4487 return;
4489 /* See if we're trying to initialize a pointer in a non-default mode
4490 to the address of some declaration somewhere. If the target says
4491 the mode is valid for pointers, assume the target has a way of
4492 resolving it. */
4493 if (TREE_CODE (exp) == NOP_EXPR
4494 && POINTER_TYPE_P (TREE_TYPE (exp))
4495 && targetm.addr_space.valid_pointer_mode
4496 (TYPE_MODE (TREE_TYPE (exp)),
4497 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4499 tree saved_type = TREE_TYPE (exp);
4501 /* Peel off any intermediate conversions-to-pointer for valid
4502 pointer modes. */
4503 while (TREE_CODE (exp) == NOP_EXPR
4504 && POINTER_TYPE_P (TREE_TYPE (exp))
4505 && targetm.addr_space.valid_pointer_mode
4506 (TYPE_MODE (TREE_TYPE (exp)),
4507 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4508 exp = TREE_OPERAND (exp, 0);
4510 /* If what we're left with is the address of something, we can
4511 convert the address to the final type and output it that
4512 way. */
4513 if (TREE_CODE (exp) == ADDR_EXPR)
4514 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4515 /* Likewise for constant ints. */
4516 else if (TREE_CODE (exp) == INTEGER_CST)
4517 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4518 TREE_INT_CST_HIGH (exp));
4522 /* Eliminate any conversions since we'll be outputting the underlying
4523 constant. */
4524 while (CONVERT_EXPR_P (exp)
4525 || TREE_CODE (exp) == NON_LVALUE_EXPR
4526 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4528 HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
4529 HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
4531 /* Make sure eliminating the conversion is really a no-op, except with
4532 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4533 union types to allow for Ada unchecked unions. */
4534 if (type_size > op_size
4535 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
4536 && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
4537 /* Keep the conversion. */
4538 break;
4539 else
4540 exp = TREE_OPERAND (exp, 0);
4543 code = TREE_CODE (TREE_TYPE (exp));
4544 thissize = int_size_in_bytes (TREE_TYPE (exp));
4546 /* Allow a constructor with no elements for any data type.
4547 This means to fill the space with zeros. */
4548 if (TREE_CODE (exp) == CONSTRUCTOR
4549 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp)))
4551 assemble_zeros (size);
4552 return;
4555 if (TREE_CODE (exp) == FDESC_EXPR)
4557 #ifdef ASM_OUTPUT_FDESC
4558 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4559 tree decl = TREE_OPERAND (exp, 0);
4560 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4561 #else
4562 gcc_unreachable ();
4563 #endif
4564 return;
4567 /* Now output the underlying data. If we've handling the padding, return.
4568 Otherwise, break and ensure SIZE is the size written. */
4569 switch (code)
4571 case BOOLEAN_TYPE:
4572 case INTEGER_TYPE:
4573 case ENUMERAL_TYPE:
4574 case POINTER_TYPE:
4575 case REFERENCE_TYPE:
4576 case OFFSET_TYPE:
4577 case FIXED_POINT_TYPE:
4578 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4579 EXPAND_INITIALIZER),
4580 MIN (size, thissize), align, 0))
4581 error ("initializer for integer/fixed-point value is too complicated");
4582 break;
4584 case REAL_TYPE:
4585 if (TREE_CODE (exp) != REAL_CST)
4586 error ("initializer for floating value is not a floating constant");
4587 else
4588 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
4589 break;
4591 case COMPLEX_TYPE:
4592 output_constant (TREE_REALPART (exp), thissize / 2, align);
4593 output_constant (TREE_IMAGPART (exp), thissize / 2,
4594 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4595 break;
4597 case ARRAY_TYPE:
4598 case VECTOR_TYPE:
4599 switch (TREE_CODE (exp))
4601 case CONSTRUCTOR:
4602 output_constructor (exp, size, align, NULL);
4603 return;
4604 case STRING_CST:
4605 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4606 size);
4607 assemble_string (TREE_STRING_POINTER (exp), thissize);
4608 break;
4610 case VECTOR_CST:
4612 int elt_size;
4613 tree link;
4614 unsigned int nalign;
4615 enum machine_mode inner;
4617 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
4618 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
4620 elt_size = GET_MODE_SIZE (inner);
4622 link = TREE_VECTOR_CST_ELTS (exp);
4623 output_constant (TREE_VALUE (link), elt_size, align);
4624 thissize = elt_size;
4625 while ((link = TREE_CHAIN (link)) != NULL)
4627 output_constant (TREE_VALUE (link), elt_size, nalign);
4628 thissize += elt_size;
4630 break;
4632 default:
4633 gcc_unreachable ();
4635 break;
4637 case RECORD_TYPE:
4638 case UNION_TYPE:
4639 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4640 output_constructor (exp, size, align, NULL);
4641 return;
4643 case ERROR_MARK:
4644 return;
4646 default:
4647 gcc_unreachable ();
4650 if (size > thissize)
4651 assemble_zeros (size - thissize);
4655 /* Subroutine of output_constructor, used for computing the size of
4656 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4657 type with an unspecified upper bound. */
4659 static unsigned HOST_WIDE_INT
4660 array_size_for_constructor (tree val)
4662 tree max_index;
4663 unsigned HOST_WIDE_INT cnt;
4664 tree index, value, tmp;
4665 double_int i;
4667 /* This code used to attempt to handle string constants that are not
4668 arrays of single-bytes, but nothing else does, so there's no point in
4669 doing it here. */
4670 if (TREE_CODE (val) == STRING_CST)
4671 return TREE_STRING_LENGTH (val);
4673 max_index = NULL_TREE;
4674 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
4676 if (TREE_CODE (index) == RANGE_EXPR)
4677 index = TREE_OPERAND (index, 1);
4678 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4679 max_index = index;
4682 if (max_index == NULL_TREE)
4683 return 0;
4685 /* Compute the total number of array elements. */
4686 tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
4687 i = double_int_sub (tree_to_double_int (max_index), tree_to_double_int (tmp));
4688 i = double_int_add (i, double_int_one);
4690 /* Multiply by the array element unit size to find number of bytes. */
4691 i = double_int_mul (i, tree_to_double_int
4692 (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val)))));
4694 gcc_assert (double_int_fits_in_uhwi_p (i));
4695 return i.low;
4698 /* Other datastructures + helpers for output_constructor. */
4700 /* output_constructor local state to support interaction with helpers. */
4702 typedef struct {
4704 /* Received arguments. */
4705 tree exp; /* Constructor expression. */
4706 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4707 unsigned int align; /* Known initial alignment. */
4709 /* Constructor expression data. */
4710 tree type; /* Expression type. */
4711 tree field; /* Current field decl in a record. */
4712 tree min_index; /* Lower bound if specified for an array. */
4714 /* Output processing state. */
4715 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4716 bool byte_buffer_in_use; /* Whether byte ... */
4717 int byte; /* ... contains part of a bitfield byte yet to
4718 be output. */
4720 int last_relative_index; /* Implicit or explicit index of the last
4721 array element output within a bitfield. */
4722 /* Current element. */
4723 tree val; /* Current element value. */
4724 tree index; /* Current element index. */
4726 } oc_local_state;
4728 /* Helper for output_constructor. From the current LOCAL state, output a
4729 RANGE_EXPR element. */
4731 static void
4732 output_constructor_array_range (oc_local_state *local)
4734 unsigned HOST_WIDE_INT fieldsize
4735 = int_size_in_bytes (TREE_TYPE (local->type));
4737 HOST_WIDE_INT lo_index
4738 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4739 HOST_WIDE_INT hi_index
4740 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4741 HOST_WIDE_INT index;
4743 unsigned int align2
4744 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4746 for (index = lo_index; index <= hi_index; index++)
4748 /* Output the element's initial value. */
4749 if (local->val == NULL_TREE)
4750 assemble_zeros (fieldsize);
4751 else
4752 output_constant (local->val, fieldsize, align2);
4754 /* Count its size. */
4755 local->total_bytes += fieldsize;
4759 /* Helper for output_constructor. From the current LOCAL state, output a
4760 field element that is not true bitfield or part of an outer one. */
4762 static void
4763 output_constructor_regular_field (oc_local_state *local)
4765 /* Field size and position. Since this structure is static, we know the
4766 positions are constant. */
4767 unsigned HOST_WIDE_INT fieldsize;
4768 HOST_WIDE_INT fieldpos;
4770 unsigned int align2;
4772 if (local->index != NULL_TREE)
4774 double_int idx = double_int_sub (tree_to_double_int (local->index),
4775 tree_to_double_int (local->min_index));
4776 gcc_assert (double_int_fits_in_shwi_p (idx));
4777 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
4778 * idx.low);
4780 else if (local->field != NULL_TREE)
4781 fieldpos = int_byte_position (local->field);
4782 else
4783 fieldpos = 0;
4785 /* Output any buffered-up bit-fields preceding this element. */
4786 if (local->byte_buffer_in_use)
4788 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4789 local->total_bytes++;
4790 local->byte_buffer_in_use = false;
4793 /* Advance to offset of this element.
4794 Note no alignment needed in an array, since that is guaranteed
4795 if each element has the proper size. */
4796 if ((local->field != NULL_TREE || local->index != NULL_TREE)
4797 && fieldpos != local->total_bytes)
4799 gcc_assert (fieldpos >= local->total_bytes);
4800 assemble_zeros (fieldpos - local->total_bytes);
4801 local->total_bytes = fieldpos;
4804 /* Find the alignment of this element. */
4805 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
4807 /* Determine size this element should occupy. */
4808 if (local->field)
4810 fieldsize = 0;
4812 /* If this is an array with an unspecified upper bound,
4813 the initializer determines the size. */
4814 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4815 but we cannot do this until the deprecated support for
4816 initializing zero-length array members is removed. */
4817 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
4818 && TYPE_DOMAIN (TREE_TYPE (local->field))
4819 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
4821 fieldsize = array_size_for_constructor (local->val);
4822 /* Given a non-empty initialization, this field had
4823 better be last. */
4824 gcc_assert (!fieldsize || !DECL_CHAIN (local->field));
4826 else
4827 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
4829 else
4830 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
4832 /* Output the element's initial value. */
4833 if (local->val == NULL_TREE)
4834 assemble_zeros (fieldsize);
4835 else
4836 output_constant (local->val, fieldsize, align2);
4838 /* Count its size. */
4839 local->total_bytes += fieldsize;
4842 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4843 output an element that is a true bitfield or part of an outer one. */
4845 static void
4846 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
4848 /* Bit size of this element. */
4849 HOST_WIDE_INT ebitsize
4850 = (local->field
4851 ? tree_low_cst (DECL_SIZE (local->field), 1)
4852 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
4854 /* Relative index of this element if this is an array component. */
4855 HOST_WIDE_INT relative_index
4856 = (!local->field
4857 ? (local->index
4858 ? (tree_low_cst (local->index, 0)
4859 - tree_low_cst (local->min_index, 0))
4860 : local->last_relative_index + 1)
4861 : 0);
4863 /* Bit position of this element from the start of the containing
4864 constructor. */
4865 HOST_WIDE_INT constructor_relative_ebitpos
4866 = (local->field
4867 ? int_bit_position (local->field)
4868 : ebitsize * relative_index);
4870 /* Bit position of this element from the start of a possibly ongoing
4871 outer byte buffer. */
4872 HOST_WIDE_INT byte_relative_ebitpos
4873 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
4875 /* From the start of a possibly ongoing outer byte buffer, offsets to
4876 the first bit of this element and to the first bit past the end of
4877 this element. */
4878 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
4879 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
4881 local->last_relative_index = relative_index;
4883 if (local->val == NULL_TREE)
4884 local->val = integer_zero_node;
4886 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
4887 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
4888 local->val = TREE_OPERAND (local->val, 0);
4890 if (TREE_CODE (local->val) != INTEGER_CST
4891 && TREE_CODE (local->val) != CONSTRUCTOR)
4893 error ("invalid initial value for member %qE", DECL_NAME (local->field));
4894 return;
4897 /* If this field does not start in this (or, next) byte,
4898 skip some bytes. */
4899 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4901 /* Output remnant of any bit field in previous bytes. */
4902 if (local->byte_buffer_in_use)
4904 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4905 local->total_bytes++;
4906 local->byte_buffer_in_use = false;
4909 /* If still not at proper byte, advance to there. */
4910 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4912 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
4913 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
4914 local->total_bytes = next_offset / BITS_PER_UNIT;
4918 /* Set up the buffer if necessary. */
4919 if (!local->byte_buffer_in_use)
4921 local->byte = 0;
4922 if (ebitsize > 0)
4923 local->byte_buffer_in_use = true;
4926 /* If this is nested constructor, recurse passing the bit offset and the
4927 pending data, then retrieve the new pending data afterwards. */
4928 if (TREE_CODE (local->val) == CONSTRUCTOR)
4930 oc_outer_state output_state;
4932 output_state.bit_offset = next_offset % BITS_PER_UNIT;
4933 output_state.byte = local->byte;
4934 local->total_bytes
4935 += output_constructor (local->val, 0, 0, &output_state);
4936 local->byte = output_state.byte;
4937 return;
4940 /* Otherwise, we must split the element into pieces that fall within
4941 separate bytes, and combine each byte with previous or following
4942 bit-fields. */
4943 while (next_offset < end_offset)
4945 int this_time;
4946 int shift;
4947 HOST_WIDE_INT value;
4948 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4949 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4951 /* Advance from byte to byte
4952 within this element when necessary. */
4953 while (next_byte != local->total_bytes)
4955 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4956 local->total_bytes++;
4957 local->byte = 0;
4960 /* Number of bits we can process at once
4961 (all part of the same byte). */
4962 this_time = MIN (end_offset - next_offset,
4963 BITS_PER_UNIT - next_bit);
4964 if (BYTES_BIG_ENDIAN)
4966 /* On big-endian machine, take the most significant bits
4967 first (of the bits that are significant)
4968 and put them into bytes from the most significant end. */
4969 shift = end_offset - next_offset - this_time;
4971 /* Don't try to take a bunch of bits that cross
4972 the word boundary in the INTEGER_CST. We can
4973 only select bits from the LOW or HIGH part
4974 not from both. */
4975 if (shift < HOST_BITS_PER_WIDE_INT
4976 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4978 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4979 shift = HOST_BITS_PER_WIDE_INT;
4982 /* Now get the bits from the appropriate constant word. */
4983 if (shift < HOST_BITS_PER_WIDE_INT)
4984 value = TREE_INT_CST_LOW (local->val);
4985 else
4987 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4988 value = TREE_INT_CST_HIGH (local->val);
4989 shift -= HOST_BITS_PER_WIDE_INT;
4992 /* Get the result. This works only when:
4993 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4994 local->byte |= (((value >> shift)
4995 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4996 << (BITS_PER_UNIT - this_time - next_bit));
4998 else
5000 /* On little-endian machines,
5001 take first the least significant bits of the value
5002 and pack them starting at the least significant
5003 bits of the bytes. */
5004 shift = next_offset - byte_relative_ebitpos;
5006 /* Don't try to take a bunch of bits that cross
5007 the word boundary in the INTEGER_CST. We can
5008 only select bits from the LOW or HIGH part
5009 not from both. */
5010 if (shift < HOST_BITS_PER_WIDE_INT
5011 && shift + this_time > HOST_BITS_PER_WIDE_INT)
5012 this_time = (HOST_BITS_PER_WIDE_INT - shift);
5014 /* Now get the bits from the appropriate constant word. */
5015 if (shift < HOST_BITS_PER_WIDE_INT)
5016 value = TREE_INT_CST_LOW (local->val);
5017 else
5019 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
5020 value = TREE_INT_CST_HIGH (local->val);
5021 shift -= HOST_BITS_PER_WIDE_INT;
5024 /* Get the result. This works only when:
5025 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5026 local->byte |= (((value >> shift)
5027 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5028 << next_bit);
5031 next_offset += this_time;
5032 local->byte_buffer_in_use = true;
5036 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5037 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5038 caller output state of relevance in recursive invocations. */
5040 static unsigned HOST_WIDE_INT
5041 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
5042 unsigned int align, oc_outer_state * outer)
5044 unsigned HOST_WIDE_INT cnt;
5045 constructor_elt *ce;
5047 oc_local_state local;
5049 /* Setup our local state to communicate with helpers. */
5050 local.exp = exp;
5051 local.size = size;
5052 local.align = align;
5054 local.total_bytes = 0;
5055 local.byte_buffer_in_use = outer != NULL;
5056 local.byte = outer ? outer->byte : 0;
5058 local.type = TREE_TYPE (exp);
5060 local.last_relative_index = -1;
5062 local.min_index = NULL_TREE;
5063 if (TREE_CODE (local.type) == ARRAY_TYPE
5064 && TYPE_DOMAIN (local.type) != NULL_TREE)
5065 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5067 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
5069 /* As CE goes through the elements of the constant, FIELD goes through the
5070 structure fields if the constant is a structure. If the constant is a
5071 union, we override this by getting the field from the TREE_LIST element.
5072 But the constant could also be an array. Then FIELD is zero.
5074 There is always a maximum of one element in the chain LINK for unions
5075 (even if the initializer in a source program incorrectly contains
5076 more one). */
5078 local.field = NULL_TREE;
5079 if (TREE_CODE (local.type) == RECORD_TYPE)
5080 local.field = TYPE_FIELDS (local.type);
5082 for (cnt = 0;
5083 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
5084 cnt++, local.field = local.field ? DECL_CHAIN (local.field) : 0)
5086 local.val = ce->value;
5087 local.index = NULL_TREE;
5089 /* The element in a union constructor specifies the proper field
5090 or index. */
5091 if ((TREE_CODE (local.type) == RECORD_TYPE
5092 || TREE_CODE (local.type) == UNION_TYPE
5093 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
5094 && ce->index != NULL_TREE)
5095 local.field = ce->index;
5097 else if (TREE_CODE (local.type) == ARRAY_TYPE)
5098 local.index = ce->index;
5100 if (local.field && flag_verbose_asm)
5101 fprintf (asm_out_file, "%s %s:\n",
5102 ASM_COMMENT_START,
5103 DECL_NAME (local.field)
5104 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
5105 : "<anonymous>");
5107 /* Eliminate the marker that makes a cast not be an lvalue. */
5108 if (local.val != NULL_TREE)
5109 STRIP_NOPS (local.val);
5111 /* Output the current element, using the appropriate helper ... */
5113 /* For an array slice not part of an outer bitfield. */
5114 if (!outer
5115 && local.index != NULL_TREE
5116 && TREE_CODE (local.index) == RANGE_EXPR)
5117 output_constructor_array_range (&local);
5119 /* For a field that is neither a true bitfield nor part of an outer one,
5120 known to be at least byte aligned and multiple-of-bytes long. */
5121 else if (!outer
5122 && (local.field == NULL_TREE
5123 || !CONSTRUCTOR_BITFIELD_P (local.field)))
5124 output_constructor_regular_field (&local);
5126 /* For a true bitfield or part of an outer one. */
5127 else
5128 output_constructor_bitfield (&local, outer);
5131 /* If we are not at toplevel, save the pending data for our caller.
5132 Otherwise output the pending data and padding zeros as needed. */
5133 if (outer)
5134 outer->byte = local.byte;
5135 else
5137 if (local.byte_buffer_in_use)
5139 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
5140 local.total_bytes++;
5143 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
5145 assemble_zeros (local.size - local.total_bytes);
5146 local.total_bytes = local.size;
5150 return local.total_bytes;
5153 /* Mark DECL as weak. */
5155 static void
5156 mark_weak (tree decl)
5158 DECL_WEAK (decl) = 1;
5160 if (DECL_RTL_SET_P (decl)
5161 && MEM_P (DECL_RTL (decl))
5162 && XEXP (DECL_RTL (decl), 0)
5163 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5164 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5167 /* Merge weak status between NEWDECL and OLDDECL. */
5169 void
5170 merge_weak (tree newdecl, tree olddecl)
5172 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5174 if (DECL_WEAK (newdecl) && TARGET_SUPPORTS_WEAK)
5176 tree *pwd;
5177 /* We put the NEWDECL on the weak_decls list at some point
5178 and OLDDECL as well. Keep just OLDDECL on the list. */
5179 for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
5180 if (TREE_VALUE (*pwd) == newdecl)
5182 *pwd = TREE_CHAIN (*pwd);
5183 break;
5186 return;
5189 if (DECL_WEAK (newdecl))
5191 tree wd;
5193 /* NEWDECL is weak, but OLDDECL is not. */
5195 /* If we already output the OLDDECL, we're in trouble; we can't
5196 go back and make it weak. This should never happen in
5197 unit-at-a-time compilation. */
5198 gcc_assert (!TREE_ASM_WRITTEN (olddecl));
5200 /* If we've already generated rtl referencing OLDDECL, we may
5201 have done so in a way that will not function properly with
5202 a weak symbol. Again in unit-at-a-time this should be
5203 impossible. */
5204 gcc_assert (!TREE_USED (olddecl)
5205 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)));
5207 if (TARGET_SUPPORTS_WEAK)
5209 /* We put the NEWDECL on the weak_decls list at some point.
5210 Replace it with the OLDDECL. */
5211 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5212 if (TREE_VALUE (wd) == newdecl)
5214 TREE_VALUE (wd) = olddecl;
5215 break;
5217 /* We may not find the entry on the list. If NEWDECL is a
5218 weak alias, then we will have already called
5219 globalize_decl to remove the entry; in that case, we do
5220 not need to do anything. */
5223 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5224 mark_weak (olddecl);
5226 else
5227 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5228 weak. Just update NEWDECL to indicate that it's weak too. */
5229 mark_weak (newdecl);
5232 /* Declare DECL to be a weak symbol. */
5234 void
5235 declare_weak (tree decl)
5237 gcc_assert (TREE_CODE (decl) != FUNCTION_DECL || !TREE_ASM_WRITTEN (decl));
5238 if (! TREE_PUBLIC (decl))
5239 error ("weak declaration of %q+D must be public", decl);
5240 else if (!TARGET_SUPPORTS_WEAK)
5241 warning (0, "weak declaration of %q+D not supported", decl);
5243 mark_weak (decl);
5244 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5245 DECL_ATTRIBUTES (decl)
5246 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5249 static void
5250 weak_finish_1 (tree decl)
5252 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5253 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5254 #endif
5256 if (! TREE_USED (decl))
5257 return;
5259 #ifdef ASM_WEAKEN_DECL
5260 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5261 #else
5262 #ifdef ASM_WEAKEN_LABEL
5263 ASM_WEAKEN_LABEL (asm_out_file, name);
5264 #else
5265 #ifdef ASM_OUTPUT_WEAK_ALIAS
5267 static bool warn_once = 0;
5268 if (! warn_once)
5270 warning (0, "only weak aliases are supported in this configuration");
5271 warn_once = 1;
5273 return;
5275 #endif
5276 #endif
5277 #endif
5280 /* This TREE_LIST contains weakref targets. */
5282 static GTY(()) tree weakref_targets;
5284 /* Forward declaration. */
5285 static tree find_decl_and_mark_needed (tree decl, tree target);
5287 /* Emit any pending weak declarations. */
5289 void
5290 weak_finish (void)
5292 tree t;
5294 for (t = weakref_targets; t; t = TREE_CHAIN (t))
5296 tree alias_decl = TREE_PURPOSE (t);
5297 tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
5299 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl)))
5300 /* Remove alias_decl from the weak list, but leave entries for
5301 the target alone. */
5302 target = NULL_TREE;
5303 #ifndef ASM_OUTPUT_WEAKREF
5304 else if (! TREE_SYMBOL_REFERENCED (target))
5306 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5307 defined, otherwise we and weak_finish_1 would use
5308 different macros. */
5309 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5310 ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
5311 # else
5312 tree decl = find_decl_and_mark_needed (alias_decl, target);
5314 if (! decl)
5316 decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5317 TREE_CODE (alias_decl), target,
5318 TREE_TYPE (alias_decl));
5320 DECL_EXTERNAL (decl) = 1;
5321 TREE_PUBLIC (decl) = 1;
5322 DECL_ARTIFICIAL (decl) = 1;
5323 TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
5324 TREE_USED (decl) = 1;
5327 weak_finish_1 (decl);
5328 # endif
5330 #endif
5333 tree *p;
5334 tree t2;
5336 /* Remove the alias and the target from the pending weak list
5337 so that we do not emit any .weak directives for the former,
5338 nor multiple .weak directives for the latter. */
5339 for (p = &weak_decls; (t2 = *p) ; )
5341 if (TREE_VALUE (t2) == alias_decl
5342 || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
5343 *p = TREE_CHAIN (t2);
5344 else
5345 p = &TREE_CHAIN (t2);
5348 /* Remove other weakrefs to the same target, to speed things up. */
5349 for (p = &TREE_CHAIN (t); (t2 = *p) ; )
5351 if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
5352 *p = TREE_CHAIN (t2);
5353 else
5354 p = &TREE_CHAIN (t2);
5359 for (t = weak_decls; t; t = TREE_CHAIN (t))
5361 tree decl = TREE_VALUE (t);
5363 weak_finish_1 (decl);
5367 /* Emit the assembly bits to indicate that DECL is globally visible. */
5369 static void
5370 globalize_decl (tree decl)
5373 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5374 if (DECL_WEAK (decl))
5376 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5377 tree *p, t;
5379 #ifdef ASM_WEAKEN_DECL
5380 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5381 #else
5382 ASM_WEAKEN_LABEL (asm_out_file, name);
5383 #endif
5385 /* Remove this function from the pending weak list so that
5386 we do not emit multiple .weak directives for it. */
5387 for (p = &weak_decls; (t = *p) ; )
5389 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5390 *p = TREE_CHAIN (t);
5391 else
5392 p = &TREE_CHAIN (t);
5395 /* Remove weakrefs to the same target from the pending weakref
5396 list, for the same reason. */
5397 for (p = &weakref_targets; (t = *p) ; )
5399 if (DECL_ASSEMBLER_NAME (decl)
5400 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5401 *p = TREE_CHAIN (t);
5402 else
5403 p = &TREE_CHAIN (t);
5406 return;
5408 #endif
5410 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5413 VEC(alias_pair,gc) *alias_pairs;
5415 /* Given an assembly name, find the decl it is associated with. At the
5416 same time, mark it needed for cgraph. */
5418 static tree
5419 find_decl_and_mark_needed (tree decl, tree target)
5421 struct cgraph_node *fnode = NULL;
5422 struct varpool_node *vnode = NULL;
5424 if (TREE_CODE (decl) == FUNCTION_DECL)
5426 fnode = cgraph_node_for_asm (target);
5427 if (fnode == NULL)
5428 vnode = varpool_node_for_asm (target);
5430 else
5432 vnode = varpool_node_for_asm (target);
5433 if (vnode == NULL)
5434 fnode = cgraph_node_for_asm (target);
5437 if (fnode)
5439 if (!fnode->global.inlined_to)
5440 cgraph_mark_needed_node (fnode);
5441 return fnode->decl;
5443 else if (vnode)
5445 varpool_mark_needed_node (vnode);
5446 vnode->force_output = 1;
5447 return vnode->decl;
5449 else
5450 return NULL_TREE;
5453 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5454 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5455 tree node is DECL to have the value of the tree node TARGET. */
5457 static void
5458 do_assemble_alias (tree decl, tree target)
5460 /* Emulated TLS had better not get this var. */
5461 gcc_assert(!(!targetm.have_tls
5462 && TREE_CODE (decl) == VAR_DECL
5463 && DECL_THREAD_LOCAL_P (decl)));
5465 if (TREE_ASM_WRITTEN (decl))
5466 return;
5468 /* We must force creation of DECL_RTL for debug info generation, even though
5469 we don't use it here. */
5470 make_decl_rtl (decl);
5472 TREE_ASM_WRITTEN (decl) = 1;
5473 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5475 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5477 ultimate_transparent_alias_target (&target);
5479 if (!TREE_SYMBOL_REFERENCED (target))
5480 weakref_targets = tree_cons (decl, target, weakref_targets);
5482 #ifdef ASM_OUTPUT_WEAKREF
5483 ASM_OUTPUT_WEAKREF (asm_out_file, decl,
5484 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5485 IDENTIFIER_POINTER (target));
5486 #else
5487 if (!TARGET_SUPPORTS_WEAK)
5489 error_at (DECL_SOURCE_LOCATION (decl),
5490 "weakref is not supported in this configuration");
5491 return;
5493 #endif
5494 return;
5497 #ifdef ASM_OUTPUT_DEF
5498 /* Make name accessible from other files, if appropriate. */
5500 if (TREE_PUBLIC (decl))
5502 globalize_decl (decl);
5503 maybe_assemble_visibility (decl);
5505 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
5507 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
5508 ASM_OUTPUT_TYPE_DIRECTIVE
5509 (asm_out_file, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5510 IFUNC_ASM_TYPE);
5511 #else
5512 error_at (DECL_SOURCE_LOCATION (decl),
5513 "ifunc is not supported in this configuration");
5514 #endif
5517 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5518 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5519 # else
5520 ASM_OUTPUT_DEF (asm_out_file,
5521 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5522 IDENTIFIER_POINTER (target));
5523 # endif
5524 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5526 const char *name;
5527 tree *p, t;
5529 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5530 # ifdef ASM_WEAKEN_DECL
5531 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5532 # else
5533 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5534 # endif
5535 /* Remove this function from the pending weak list so that
5536 we do not emit multiple .weak directives for it. */
5537 for (p = &weak_decls; (t = *p) ; )
5538 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5539 *p = TREE_CHAIN (t);
5540 else
5541 p = &TREE_CHAIN (t);
5543 /* Remove weakrefs to the same target from the pending weakref
5544 list, for the same reason. */
5545 for (p = &weakref_targets; (t = *p) ; )
5547 if (DECL_ASSEMBLER_NAME (decl)
5548 == ultimate_transparent_alias_target (&TREE_VALUE (t)))
5549 *p = TREE_CHAIN (t);
5550 else
5551 p = &TREE_CHAIN (t);
5554 #endif
5558 /* Allocate and construct a symbol alias set. */
5560 static symbol_alias_set_t *
5561 symbol_alias_set_create (void)
5563 return pointer_set_create ();
5566 /* Destruct and free a symbol alias set. */
5568 void
5569 symbol_alias_set_destroy (symbol_alias_set_t *aset)
5571 pointer_set_destroy (aset);
5574 /* Test if a symbol alias set contains a given name. */
5577 symbol_alias_set_contains (const symbol_alias_set_t *aset, tree t)
5579 /* We accept either a DECL or an IDENTIFIER directly. */
5580 if (TREE_CODE (t) != IDENTIFIER_NODE)
5581 t = DECL_ASSEMBLER_NAME (t);
5582 t = targetm.asm_out.mangle_assembler_name (IDENTIFIER_POINTER (t));
5583 return pointer_set_contains (aset, t);
5586 /* Enter a new name into a symbol alias set. */
5588 static int
5589 symbol_alias_set_insert (symbol_alias_set_t *aset, tree t)
5591 /* We accept either a DECL or an IDENTIFIER directly. */
5592 if (TREE_CODE (t) != IDENTIFIER_NODE)
5593 t = DECL_ASSEMBLER_NAME (t);
5594 t = targetm.asm_out.mangle_assembler_name (IDENTIFIER_POINTER (t));
5595 return pointer_set_insert (aset, t);
5598 /* IN_SET_P is a predicate function assuming to be taken
5599 alias_pair->decl, alias_pair->target and DATA arguments.
5601 Compute set of aliases by including everything where TRIVIALLY_VISIBLE
5602 predeicate is true and propagate across aliases such that when
5603 alias DECL is included, its TARGET is included too. */
5605 static symbol_alias_set_t *
5606 propagate_aliases_forward (bool (*in_set_p)
5607 (tree decl, tree target, void *data),
5608 void *data)
5610 symbol_alias_set_t *set;
5611 unsigned i;
5612 alias_pair *p;
5613 bool changed;
5615 set = symbol_alias_set_create ();
5616 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); ++i)
5617 if (in_set_p (p->decl, p->target, data))
5618 symbol_alias_set_insert (set, p->decl);
5621 changed = false;
5622 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); ++i)
5623 if (symbol_alias_set_contains (set, p->decl)
5624 && !symbol_alias_set_insert (set, p->target))
5625 changed = true;
5627 while (changed);
5629 return set;
5632 /* Like propagate_aliases_forward but do backward propagation. */
5634 symbol_alias_set_t *
5635 propagate_aliases_backward (bool (*in_set_p)
5636 (tree decl, tree target, void *data),
5637 void *data)
5639 symbol_alias_set_t *set;
5640 unsigned i;
5641 alias_pair *p;
5642 bool changed;
5644 /* We have to compute the set of set nodes including aliases
5645 themselves. */
5646 set = symbol_alias_set_create ();
5647 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); ++i)
5648 if (in_set_p (p->decl, p->target, data))
5649 symbol_alias_set_insert (set, p->target);
5652 changed = false;
5653 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); ++i)
5654 if (symbol_alias_set_contains (set, p->target)
5655 && !symbol_alias_set_insert (set, p->decl))
5656 changed = true;
5658 while (changed);
5660 return set;
5662 /* See if the alias is trivially visible. This means
5663 1) alias is expoerted from the unit or
5664 2) alias is used in the code.
5665 We assume that unused cgraph/varpool nodes has been
5666 removed.
5667 Used as callback for propagate_aliases. */
5669 static bool
5670 trivially_visible_alias (tree decl, tree target ATTRIBUTE_UNUSED,
5671 void *data ATTRIBUTE_UNUSED)
5673 struct cgraph_node *fnode = NULL;
5674 struct varpool_node *vnode = NULL;
5676 if (!TREE_PUBLIC (decl))
5678 if (TREE_CODE (decl) == FUNCTION_DECL)
5679 fnode = cgraph_get_node (decl);
5680 else
5681 vnode = varpool_get_node (decl);
5682 return vnode || fnode;
5684 else
5685 return true;
5688 /* See if the target of alias is defined in this unit.
5689 Used as callback for propagate_aliases. */
5691 static bool
5692 trivially_defined_alias (tree decl ATTRIBUTE_UNUSED,
5693 tree target,
5694 void *data ATTRIBUTE_UNUSED)
5696 struct cgraph_node *fnode = NULL;
5697 struct varpool_node *vnode = NULL;
5699 fnode = cgraph_node_for_asm (target);
5700 vnode = (fnode == NULL) ? varpool_node_for_asm (target) : NULL;
5701 return (fnode && fnode->analyzed) || (vnode && vnode->finalized);
5704 /* Remove the alias pairing for functions that are no longer in the call
5705 graph. */
5707 void
5708 remove_unreachable_alias_pairs (void)
5710 symbol_alias_set_t *visible;
5711 unsigned i;
5712 alias_pair *p;
5714 if (alias_pairs == NULL)
5715 return;
5717 /* We have to compute the set of visible nodes including aliases
5718 themselves. */
5719 visible = propagate_aliases_forward (trivially_visible_alias, NULL);
5721 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5723 if (!DECL_EXTERNAL (p->decl)
5724 && !symbol_alias_set_contains (visible, p->decl))
5726 VEC_unordered_remove (alias_pair, alias_pairs, i);
5727 continue;
5730 i++;
5733 symbol_alias_set_destroy (visible);
5737 /* Returns true if alias target node can be found for
5738 assembler name TARGET. */
5740 static bool
5741 alias_target_node_exist_p (tree target)
5743 struct cgraph_node *node;
5744 tree real_target_decl = cgraph_find_decl (target);
5746 if (real_target_decl && !DECL_EXTERNAL (real_target_decl))
5747 return true;
5749 /* Now more expensive walk. */
5750 for (node = cgraph_nodes; node; node = node->next)
5751 if (!node->global.inlined_to && HAS_DECL_ASSEMBLER_NAME_P (node->decl))
5753 tree name = DECL_ASSEMBLER_NAME (node->decl);
5754 /* Assume the assembler names are commoned. */
5755 if (name == target && !DECL_EXTERNAL (node->decl))
5756 return true;
5759 return false;
5762 /* First pass of completing pending aliases. Make sure that cgraph knows
5763 which symbols will be required. */
5765 void
5766 finish_aliases_1 (void)
5768 symbol_alias_set_t *defined;
5769 unsigned i;
5770 alias_pair *p;
5772 if (alias_pairs == NULL)
5773 return;
5775 /* We have to compute the set of defined nodes including aliases
5776 themselves. */
5777 defined = propagate_aliases_backward (trivially_defined_alias, NULL);
5779 FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
5781 tree target_decl;
5783 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5784 if (target_decl == NULL)
5786 if (symbol_alias_set_contains (defined, p->target))
5787 continue;
5789 if (! (p->emitted_diags & ALIAS_DIAG_TO_UNDEF)
5790 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5793 if (L_IPO_COMP_MODE && alias_target_node_exist_p (p->target))
5794 continue;
5796 error ("%q+D aliased to undefined symbol %qE",
5797 p->decl, p->target);
5798 p->emitted_diags |= ALIAS_DIAG_TO_UNDEF;
5801 else if (! (p->emitted_diags & ALIAS_DIAG_TO_EXTERN)
5802 && DECL_EXTERNAL (target_decl)
5803 /* We use local aliases for C++ thunks to force the tailcall
5804 to bind locally. This is a hack - to keep it working do
5805 the following (which is not strictly correct). */
5806 && (! TREE_CODE (target_decl) == FUNCTION_DECL
5807 || ! DECL_VIRTUAL_P (target_decl))
5808 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5811 /* Note that the assembler name hashing management is broken in LIPO mode.
5812 The node mapped by an assembler name might be deleted or it might be
5813 mapped to a function that is not the one that is 'expanded' (and therefore
5814 marked as 'extern' -- even when it has body. This needs more cleanup.
5815 Since same_body_alias pairs are usually added late after the target
5816 function is expanded, it is usually safe to ignore the 'error' */
5818 if (!L_IPO_COMP_MODE || !alias_target_node_exist_p (p->target))
5820 error ("%q+D aliased to external symbol %qE",
5821 p->decl, p->target);
5822 p->emitted_diags |= ALIAS_DIAG_TO_EXTERN;
5827 symbol_alias_set_destroy (defined);
5830 /* Second pass of completing pending aliases. Emit the actual assembly.
5831 This happens at the end of compilation and thus it is assured that the
5832 target symbol has been emitted. */
5834 void
5835 finish_aliases_2 (void)
5837 unsigned i;
5838 alias_pair *p;
5840 FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
5841 do_assemble_alias (p->decl, p->target);
5843 VEC_truncate (alias_pair, alias_pairs, 0);
5846 /* Emit an assembler directive to make the symbol for DECL an alias to
5847 the symbol for TARGET. */
5849 void
5850 assemble_alias (tree decl, tree target)
5852 tree target_decl;
5854 if (L_IPO_IS_AUXILIARY_MODULE)
5855 return;
5857 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5859 tree alias = DECL_ASSEMBLER_NAME (decl);
5861 ultimate_transparent_alias_target (&target);
5863 if (alias == target)
5864 error ("weakref %q+D ultimately targets itself", decl);
5865 else
5867 #ifndef ASM_OUTPUT_WEAKREF
5868 IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1;
5869 TREE_CHAIN (alias) = target;
5870 #endif
5872 if (TREE_PUBLIC (decl))
5873 error ("weakref %q+D must have static linkage", decl);
5875 else
5877 #if !defined (ASM_OUTPUT_DEF)
5878 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5879 error_at (DECL_SOURCE_LOCATION (decl),
5880 "alias definitions not supported in this configuration");
5881 return;
5882 # else
5883 if (!DECL_WEAK (decl))
5885 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
5886 error_at (DECL_SOURCE_LOCATION (decl),
5887 "ifunc is not supported in this configuration");
5888 else
5889 error_at (DECL_SOURCE_LOCATION (decl),
5890 "only weak aliases are supported in this configuration");
5891 return;
5893 # endif
5894 #endif
5896 TREE_USED (decl) = 1;
5898 /* Allow aliases to aliases. */
5899 if (TREE_CODE (decl) == FUNCTION_DECL)
5900 cgraph_get_create_node (decl)->alias = true;
5901 else
5902 varpool_node (decl)->alias = true;
5904 /* If the target has already been emitted, we don't have to queue the
5905 alias. This saves a tad of memory. */
5906 if (cgraph_global_info_ready)
5907 target_decl = find_decl_and_mark_needed (decl, target);
5908 else
5909 target_decl= NULL;
5910 if (target_decl && TREE_ASM_WRITTEN (target_decl))
5911 do_assemble_alias (decl, target);
5912 else
5914 alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
5915 p->decl = decl;
5916 p->target = target;
5917 p->emitted_diags = ALIAS_DIAG_NONE;
5921 /* Record and output a table of translations from original function
5922 to its transaction aware clone. Note that tm_pure functions are
5923 considered to be their own clone. */
5925 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
5926 htab_t tm_clone_hash;
5928 void
5929 record_tm_clone_pair (tree o, tree n)
5931 struct tree_map **slot, *h;
5933 if (tm_clone_hash == NULL)
5934 tm_clone_hash = htab_create_ggc (32, tree_map_hash, tree_map_eq, 0);
5936 h = ggc_alloc_tree_map ();
5937 h->hash = htab_hash_pointer (o);
5938 h->base.from = o;
5939 h->to = n;
5941 slot = (struct tree_map **)
5942 htab_find_slot_with_hash (tm_clone_hash, h, h->hash, INSERT);
5943 *slot = h;
5946 tree
5947 get_tm_clone_pair (tree o)
5949 if (tm_clone_hash)
5951 struct tree_map *h, in;
5953 in.base.from = o;
5954 in.hash = htab_hash_pointer (o);
5955 h = (struct tree_map *) htab_find_with_hash (tm_clone_hash,
5956 &in, in.hash);
5957 if (h)
5958 return h->to;
5960 return NULL_TREE;
5963 typedef struct tm_alias_pair
5965 unsigned int uid;
5966 tree from;
5967 tree to;
5968 } tm_alias_pair;
5970 DEF_VEC_O(tm_alias_pair);
5971 DEF_VEC_ALLOC_O(tm_alias_pair,heap);
5973 /* Helper function for finish_tm_clone_pairs. Dump a hash table entry
5974 into a VEC in INFO. */
5976 static int
5977 dump_tm_clone_to_vec (void **slot, void *info)
5979 struct tree_map *map = (struct tree_map *) *slot;
5980 VEC(tm_alias_pair,heap) **tm_alias_pairs
5981 = (VEC(tm_alias_pair, heap) **) info;
5982 tm_alias_pair *p;
5984 p = VEC_safe_push (tm_alias_pair, heap, *tm_alias_pairs, NULL);
5985 p->from = map->base.from;
5986 p->to = map->to;
5987 p->uid = DECL_UID (p->from);
5988 return 1;
5991 /* Dump the actual pairs to the .tm_clone_table section. */
5993 static void
5994 dump_tm_clone_pairs (VEC(tm_alias_pair,heap) *tm_alias_pairs)
5996 unsigned i;
5997 tm_alias_pair *p;
5998 bool switched = false;
6000 FOR_EACH_VEC_ELT (tm_alias_pair, tm_alias_pairs, i, p)
6002 tree src = p->from;
6003 tree dst = p->to;
6004 struct cgraph_node *src_n = cgraph_get_node (src);
6005 struct cgraph_node *dst_n = cgraph_get_node (dst);
6007 /* The function ipa_tm_create_version() marks the clone as needed if
6008 the original function was needed. But we also mark the clone as
6009 needed if we ever called the clone indirectly through
6010 TM_GETTMCLONE. If neither of these are true, we didn't generate
6011 a clone, and we didn't call it indirectly... no sense keeping it
6012 in the clone table. */
6013 if (!dst_n || !dst_n->needed)
6014 continue;
6016 /* This covers the case where we have optimized the original
6017 function away, and only access the transactional clone. */
6018 if (!src_n || !src_n->needed)
6019 continue;
6021 if (!switched)
6023 switch_to_section (targetm.asm_out.tm_clone_table_section ());
6024 assemble_align (POINTER_SIZE);
6025 switched = true;
6028 assemble_integer (XEXP (DECL_RTL (src), 0),
6029 POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
6030 assemble_integer (XEXP (DECL_RTL (dst), 0),
6031 POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
6035 /* Provide a default for the tm_clone_table section. */
6037 section *
6038 default_clone_table_section (void)
6040 return get_named_section (NULL, ".tm_clone_table", 3);
6043 /* Helper comparison function for qsorting by the DECL_UID stored in
6044 alias_pair->emitted_diags. */
6046 static int
6047 tm_alias_pair_cmp (const void *x, const void *y)
6049 const tm_alias_pair *p1 = (const tm_alias_pair *) x;
6050 const tm_alias_pair *p2 = (const tm_alias_pair *) y;
6051 if (p1->uid < p2->uid)
6052 return -1;
6053 if (p1->uid > p2->uid)
6054 return 1;
6055 return 0;
6058 void
6059 finish_tm_clone_pairs (void)
6061 VEC(tm_alias_pair,heap) *tm_alias_pairs = NULL;
6063 if (tm_clone_hash == NULL)
6064 return;
6066 /* We need a determenistic order for the .tm_clone_table, otherwise
6067 we will get bootstrap comparison failures, so dump the hash table
6068 to a vector, sort it, and dump the vector. */
6070 /* Dump the hashtable to a vector. */
6071 htab_traverse_noresize (tm_clone_hash, dump_tm_clone_to_vec,
6072 (void *) &tm_alias_pairs);
6073 /* Sort it. */
6074 VEC_qsort (tm_alias_pair, tm_alias_pairs, tm_alias_pair_cmp);
6076 /* Dump it. */
6077 dump_tm_clone_pairs (tm_alias_pairs);
6079 htab_delete (tm_clone_hash);
6080 tm_clone_hash = NULL;
6081 VEC_free (tm_alias_pair, heap, tm_alias_pairs);
6085 /* Emit an assembler directive to set symbol for DECL visibility to
6086 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
6088 void
6089 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
6090 int vis ATTRIBUTE_UNUSED)
6092 #ifdef HAVE_GAS_HIDDEN
6093 static const char * const visibility_types[] = {
6094 NULL, "protected", "hidden", "internal"
6097 const char *name, *type;
6099 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6100 type = visibility_types[vis];
6102 fprintf (asm_out_file, "\t.%s\t", type);
6103 assemble_name (asm_out_file, name);
6104 fprintf (asm_out_file, "\n");
6105 #else
6106 warning (OPT_Wattributes, "visibility attribute not supported "
6107 "in this configuration; ignored");
6108 #endif
6111 /* A helper function to call assemble_visibility when needed for a decl. */
6114 maybe_assemble_visibility (tree decl)
6116 enum symbol_visibility vis = DECL_VISIBILITY (decl);
6118 if (vis != VISIBILITY_DEFAULT)
6120 targetm.asm_out.assemble_visibility (decl, vis);
6121 return 1;
6123 else
6124 return 0;
6127 /* Returns 1 if the target configuration supports defining public symbols
6128 so that one of them will be chosen at link time instead of generating a
6129 multiply-defined symbol error, whether through the use of weak symbols or
6130 a target-specific mechanism for having duplicates discarded. */
6133 supports_one_only (void)
6135 if (SUPPORTS_ONE_ONLY)
6136 return 1;
6137 return TARGET_SUPPORTS_WEAK;
6140 /* Set up DECL as a public symbol that can be defined in multiple
6141 translation units without generating a linker error. */
6143 void
6144 make_decl_one_only (tree decl, tree comdat_group)
6146 gcc_assert (TREE_CODE (decl) == VAR_DECL
6147 || TREE_CODE (decl) == FUNCTION_DECL);
6149 TREE_PUBLIC (decl) = 1;
6151 if (SUPPORTS_ONE_ONLY)
6153 #ifdef MAKE_DECL_ONE_ONLY
6154 MAKE_DECL_ONE_ONLY (decl);
6155 #endif
6156 DECL_COMDAT_GROUP (decl) = comdat_group;
6158 else if (TREE_CODE (decl) == VAR_DECL
6159 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
6160 DECL_COMMON (decl) = 1;
6161 else
6163 gcc_assert (TARGET_SUPPORTS_WEAK);
6164 DECL_WEAK (decl) = 1;
6168 void
6169 init_varasm_once (void)
6171 section_htab = htab_create_ggc (31, section_entry_hash,
6172 section_entry_eq, NULL);
6173 object_block_htab = htab_create_ggc (31, object_block_entry_hash,
6174 object_block_entry_eq, NULL);
6175 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
6176 const_desc_eq, NULL);
6178 const_alias_set = new_alias_set ();
6179 shared_constant_pool = create_constant_pool ();
6181 #ifdef TEXT_SECTION_ASM_OP
6182 text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
6183 TEXT_SECTION_ASM_OP);
6184 #endif
6186 #ifdef DATA_SECTION_ASM_OP
6187 data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6188 DATA_SECTION_ASM_OP);
6189 #endif
6191 #ifdef SDATA_SECTION_ASM_OP
6192 sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6193 SDATA_SECTION_ASM_OP);
6194 #endif
6196 #ifdef READONLY_DATA_SECTION_ASM_OP
6197 readonly_data_section = get_unnamed_section (0, output_section_asm_op,
6198 READONLY_DATA_SECTION_ASM_OP);
6199 #endif
6201 #ifdef CTORS_SECTION_ASM_OP
6202 ctors_section = get_unnamed_section (0, output_section_asm_op,
6203 CTORS_SECTION_ASM_OP);
6204 #endif
6206 #ifdef DTORS_SECTION_ASM_OP
6207 dtors_section = get_unnamed_section (0, output_section_asm_op,
6208 DTORS_SECTION_ASM_OP);
6209 #endif
6211 #ifdef BSS_SECTION_ASM_OP
6212 bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6213 output_section_asm_op,
6214 BSS_SECTION_ASM_OP);
6215 #endif
6217 #ifdef SBSS_SECTION_ASM_OP
6218 sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6219 output_section_asm_op,
6220 SBSS_SECTION_ASM_OP);
6221 #endif
6223 tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6224 | SECTION_COMMON, emit_tls_common);
6225 lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6226 | SECTION_COMMON, emit_local);
6227 comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6228 | SECTION_COMMON, emit_common);
6230 #if defined ASM_OUTPUT_ALIGNED_BSS
6231 bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
6232 emit_bss);
6233 #endif
6235 targetm.asm_out.init_sections ();
6237 if (readonly_data_section == NULL)
6238 readonly_data_section = text_section;
6241 enum tls_model
6242 decl_default_tls_model (const_tree decl)
6244 enum tls_model kind;
6245 bool is_local;
6247 is_local = targetm.binds_local_p (decl);
6248 if (!flag_shlib)
6250 if (is_local)
6251 kind = TLS_MODEL_LOCAL_EXEC;
6252 else
6253 kind = TLS_MODEL_INITIAL_EXEC;
6256 /* Local dynamic is inefficient when we're not combining the
6257 parts of the address. */
6258 else if (optimize && is_local)
6259 kind = TLS_MODEL_LOCAL_DYNAMIC;
6260 else
6261 kind = TLS_MODEL_GLOBAL_DYNAMIC;
6262 if (kind < flag_tls_default)
6263 kind = flag_tls_default;
6265 return kind;
6268 /* Select a set of attributes for section NAME based on the properties
6269 of DECL and whether or not RELOC indicates that DECL's initializer
6270 might contain runtime relocations.
6272 We make the section read-only and executable for a function decl,
6273 read-only for a const data decl, and writable for a non-const data decl. */
6275 unsigned int
6276 default_section_type_flags (tree decl, const char *name, int reloc)
6278 unsigned int flags;
6280 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
6281 flags = SECTION_CODE;
6282 else if (decl)
6284 enum section_category category
6285 = categorize_decl_for_section (decl, reloc);
6286 if (decl_readonly_section_1 (category))
6287 flags = 0;
6288 else if (category == SECCAT_DATA_REL_RO
6289 || category == SECCAT_DATA_REL_RO_LOCAL)
6290 flags = SECTION_WRITE | SECTION_RELRO;
6291 else
6292 flags = SECTION_WRITE;
6294 else
6296 flags = SECTION_WRITE;
6297 if (strcmp (name, ".data.rel.ro") == 0
6298 || strcmp (name, ".data.rel.ro.local") == 0)
6299 flags |= SECTION_RELRO;
6302 if (decl && DECL_ONE_ONLY (decl))
6303 flags |= SECTION_LINKONCE;
6305 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6306 flags |= SECTION_TLS | SECTION_WRITE;
6308 if (strcmp (name, ".bss") == 0
6309 || strncmp (name, ".bss.", 5) == 0
6310 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
6311 || strcmp (name, ".sbss") == 0
6312 || strncmp (name, ".sbss.", 6) == 0
6313 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
6314 flags |= SECTION_BSS;
6316 if (strcmp (name, ".tdata") == 0
6317 || strncmp (name, ".tdata.", 7) == 0
6318 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
6319 flags |= SECTION_TLS;
6321 if (strcmp (name, ".tbss") == 0
6322 || strncmp (name, ".tbss.", 6) == 0
6323 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
6324 flags |= SECTION_TLS | SECTION_BSS;
6326 /* These three sections have special ELF types. They are neither
6327 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6328 want to print a section type (@progbits or @nobits). If someone
6329 is silly enough to emit code or TLS variables to one of these
6330 sections, then don't handle them specially. */
6331 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
6332 && (strcmp (name, ".init_array") == 0
6333 || strcmp (name, ".fini_array") == 0
6334 || strcmp (name, ".preinit_array") == 0))
6335 flags |= SECTION_NOTYPE;
6337 return flags;
6340 /* Return true if the target supports some form of global BSS,
6341 either through bss_noswitch_section, or by selecting a BSS
6342 section in TARGET_ASM_SELECT_SECTION. */
6344 bool
6345 have_global_bss_p (void)
6347 return bss_noswitch_section || targetm.have_switchable_bss_sections;
6350 /* Output assembly to switch to section NAME with attribute FLAGS.
6351 Four variants for common object file formats. */
6353 void
6354 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
6355 unsigned int flags ATTRIBUTE_UNUSED,
6356 tree decl ATTRIBUTE_UNUSED)
6358 /* Some object formats don't support named sections at all. The
6359 front-end should already have flagged this as an error. */
6360 gcc_unreachable ();
6363 #ifndef TLS_SECTION_ASM_FLAG
6364 #define TLS_SECTION_ASM_FLAG 'T'
6365 #endif
6367 void
6368 default_elf_asm_named_section (const char *name, unsigned int flags,
6369 tree decl ATTRIBUTE_UNUSED)
6371 char flagchars[10], *f = flagchars;
6373 /* If we have already declared this section, we can use an
6374 abbreviated form to switch back to it -- unless this section is
6375 part of a COMDAT groups, in which case GAS requires the full
6376 declaration every time. */
6377 if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6378 && (flags & SECTION_DECLARED))
6380 fprintf (asm_out_file, "\t.section\t%s\n", name);
6381 return;
6384 if (!(flags & SECTION_DEBUG))
6385 *f++ = 'a';
6386 if (flags & SECTION_EXCLUDE)
6387 *f++ = 'e';
6388 if (flags & SECTION_WRITE)
6389 *f++ = 'w';
6390 if (flags & SECTION_CODE)
6391 *f++ = 'x';
6392 if (flags & SECTION_SMALL)
6393 *f++ = 's';
6394 if (flags & SECTION_MERGE)
6395 *f++ = 'M';
6396 if (flags & SECTION_STRINGS)
6397 *f++ = 'S';
6398 if (flags & SECTION_TLS)
6399 *f++ = TLS_SECTION_ASM_FLAG;
6400 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6401 *f++ = 'G';
6402 *f = '\0';
6404 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
6406 if (!(flags & SECTION_NOTYPE))
6408 const char *type;
6409 const char *format;
6411 if (flags & SECTION_BSS)
6412 type = "nobits";
6413 else
6414 type = "progbits";
6416 format = ",@%s";
6417 /* On platforms that use "@" as the assembly comment character,
6418 use "%" instead. */
6419 if (strcmp (ASM_COMMENT_START, "@") == 0)
6420 format = ",%%%s";
6421 fprintf (asm_out_file, format, type);
6423 if (flags & SECTION_ENTSIZE)
6424 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
6425 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
6427 if (TREE_CODE (decl) == IDENTIFIER_NODE)
6428 fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
6429 else
6430 fprintf (asm_out_file, ",%s,comdat",
6431 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
6435 putc ('\n', asm_out_file);
6438 void
6439 default_coff_asm_named_section (const char *name, unsigned int flags,
6440 tree decl ATTRIBUTE_UNUSED)
6442 char flagchars[8], *f = flagchars;
6444 if (flags & SECTION_WRITE)
6445 *f++ = 'w';
6446 if (flags & SECTION_CODE)
6447 *f++ = 'x';
6448 *f = '\0';
6450 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
6453 void
6454 default_pe_asm_named_section (const char *name, unsigned int flags,
6455 tree decl)
6457 default_coff_asm_named_section (name, flags, decl);
6459 if (flags & SECTION_LINKONCE)
6461 /* Functions may have been compiled at various levels of
6462 optimization so we can't use `same_size' here.
6463 Instead, have the linker pick one. */
6464 fprintf (asm_out_file, "\t.linkonce %s\n",
6465 (flags & SECTION_CODE ? "discard" : "same_size"));
6469 /* The lame default section selector. */
6471 section *
6472 default_select_section (tree decl, int reloc,
6473 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6475 if (DECL_P (decl))
6477 if (decl_readonly_section (decl, reloc))
6478 return readonly_data_section;
6480 else if (TREE_CODE (decl) == CONSTRUCTOR)
6482 if (! ((flag_pic && reloc)
6483 || !TREE_READONLY (decl)
6484 || TREE_SIDE_EFFECTS (decl)
6485 || !TREE_CONSTANT (decl)))
6486 return readonly_data_section;
6488 else if (TREE_CODE (decl) == STRING_CST)
6489 return readonly_data_section;
6490 else if (! (flag_pic && reloc))
6491 return readonly_data_section;
6493 return data_section;
6496 enum section_category
6497 categorize_decl_for_section (const_tree decl, int reloc)
6499 enum section_category ret;
6501 if (TREE_CODE (decl) == FUNCTION_DECL)
6502 return SECCAT_TEXT;
6503 else if (TREE_CODE (decl) == STRING_CST)
6505 if (flag_mudflap) /* or !flag_merge_constants */
6506 return SECCAT_RODATA;
6507 else
6508 return SECCAT_RODATA_MERGE_STR;
6510 else if (TREE_CODE (decl) == VAR_DECL)
6512 if (bss_initializer_p (decl))
6513 ret = SECCAT_BSS;
6514 else if (! TREE_READONLY (decl)
6515 || TREE_SIDE_EFFECTS (decl)
6516 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
6518 /* Here the reloc_rw_mask is not testing whether the section should
6519 be read-only or not, but whether the dynamic link will have to
6520 do something. If so, we wish to segregate the data in order to
6521 minimize cache misses inside the dynamic linker. */
6522 if (reloc & targetm.asm_out.reloc_rw_mask ())
6523 ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
6524 else
6525 ret = SECCAT_DATA;
6527 else if (reloc & targetm.asm_out.reloc_rw_mask ())
6528 ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
6529 else if (reloc || flag_merge_constants < 2)
6530 /* C and C++ don't allow different variables to share the same
6531 location. -fmerge-all-constants allows even that (at the
6532 expense of not conforming). */
6533 ret = SECCAT_RODATA;
6534 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
6535 ret = SECCAT_RODATA_MERGE_STR_INIT;
6536 else
6537 ret = SECCAT_RODATA_MERGE_CONST;
6539 else if (TREE_CODE (decl) == CONSTRUCTOR)
6541 if ((reloc & targetm.asm_out.reloc_rw_mask ())
6542 || TREE_SIDE_EFFECTS (decl)
6543 || ! TREE_CONSTANT (decl))
6544 ret = SECCAT_DATA;
6545 else
6546 ret = SECCAT_RODATA;
6548 else
6549 ret = SECCAT_RODATA;
6551 /* There are no read-only thread-local sections. */
6552 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6554 /* Note that this would be *just* SECCAT_BSS, except that there's
6555 no concept of a read-only thread-local-data section. */
6556 if (ret == SECCAT_BSS
6557 || (flag_zero_initialized_in_bss
6558 && initializer_zerop (DECL_INITIAL (decl))))
6559 ret = SECCAT_TBSS;
6560 else
6561 ret = SECCAT_TDATA;
6564 /* If the target uses small data sections, select it. */
6565 else if (targetm.in_small_data_p (decl))
6567 if (ret == SECCAT_BSS)
6568 ret = SECCAT_SBSS;
6569 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
6570 ret = SECCAT_SRODATA;
6571 else
6572 ret = SECCAT_SDATA;
6575 return ret;
6578 static bool
6579 decl_readonly_section_1 (enum section_category category)
6581 switch (category)
6583 case SECCAT_RODATA:
6584 case SECCAT_RODATA_MERGE_STR:
6585 case SECCAT_RODATA_MERGE_STR_INIT:
6586 case SECCAT_RODATA_MERGE_CONST:
6587 case SECCAT_SRODATA:
6588 return true;
6589 default:
6590 return false;
6594 bool
6595 decl_readonly_section (const_tree decl, int reloc)
6597 return decl_readonly_section_1 (categorize_decl_for_section (decl, reloc));
6600 /* Select a section based on the above categorization. */
6602 section *
6603 default_elf_select_section (tree decl, int reloc,
6604 unsigned HOST_WIDE_INT align)
6606 const char *sname;
6607 switch (categorize_decl_for_section (decl, reloc))
6609 case SECCAT_TEXT:
6610 /* We're not supposed to be called on FUNCTION_DECLs. */
6611 gcc_unreachable ();
6612 case SECCAT_RODATA:
6613 return readonly_data_section;
6614 case SECCAT_RODATA_MERGE_STR:
6615 return mergeable_string_section (decl, align, 0);
6616 case SECCAT_RODATA_MERGE_STR_INIT:
6617 return mergeable_string_section (DECL_INITIAL (decl), align, 0);
6618 case SECCAT_RODATA_MERGE_CONST:
6619 return mergeable_constant_section (DECL_MODE (decl), align, 0);
6620 case SECCAT_SRODATA:
6621 sname = ".sdata2";
6622 break;
6623 case SECCAT_DATA:
6624 return data_section;
6625 case SECCAT_DATA_REL:
6626 sname = ".data.rel";
6627 break;
6628 case SECCAT_DATA_REL_LOCAL:
6629 sname = ".data.rel.local";
6630 break;
6631 case SECCAT_DATA_REL_RO:
6632 sname = ".data.rel.ro";
6633 break;
6634 case SECCAT_DATA_REL_RO_LOCAL:
6635 sname = ".data.rel.ro.local";
6636 break;
6637 case SECCAT_SDATA:
6638 sname = ".sdata";
6639 break;
6640 case SECCAT_TDATA:
6641 sname = ".tdata";
6642 break;
6643 case SECCAT_BSS:
6644 if (bss_section)
6645 return bss_section;
6646 sname = ".bss";
6647 break;
6648 case SECCAT_SBSS:
6649 sname = ".sbss";
6650 break;
6651 case SECCAT_TBSS:
6652 sname = ".tbss";
6653 break;
6654 default:
6655 gcc_unreachable ();
6658 if (!DECL_P (decl))
6659 decl = NULL_TREE;
6660 return get_named_section (decl, sname, reloc);
6663 /* Construct a unique section name based on the decl name and the
6664 categorization performed above. */
6666 void
6667 default_unique_section (tree decl, int reloc)
6669 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6670 bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
6671 const char *prefix, *name, *linkonce;
6672 char *string;
6674 switch (categorize_decl_for_section (decl, reloc))
6676 case SECCAT_TEXT:
6677 prefix = one_only ? ".t" : ".text";
6678 break;
6679 case SECCAT_RODATA:
6680 case SECCAT_RODATA_MERGE_STR:
6681 case SECCAT_RODATA_MERGE_STR_INIT:
6682 case SECCAT_RODATA_MERGE_CONST:
6683 prefix = one_only ? ".r" : ".rodata";
6684 break;
6685 case SECCAT_SRODATA:
6686 prefix = one_only ? ".s2" : ".sdata2";
6687 break;
6688 case SECCAT_DATA:
6689 prefix = one_only ? ".d" : ".data";
6690 break;
6691 case SECCAT_DATA_REL:
6692 prefix = one_only ? ".d.rel" : ".data.rel";
6693 break;
6694 case SECCAT_DATA_REL_LOCAL:
6695 prefix = one_only ? ".d.rel.local" : ".data.rel.local";
6696 break;
6697 case SECCAT_DATA_REL_RO:
6698 prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
6699 break;
6700 case SECCAT_DATA_REL_RO_LOCAL:
6701 prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
6702 break;
6703 case SECCAT_SDATA:
6704 prefix = one_only ? ".s" : ".sdata";
6705 break;
6706 case SECCAT_BSS:
6707 prefix = one_only ? ".b" : ".bss";
6708 break;
6709 case SECCAT_SBSS:
6710 prefix = one_only ? ".sb" : ".sbss";
6711 break;
6712 case SECCAT_TDATA:
6713 prefix = one_only ? ".td" : ".tdata";
6714 break;
6715 case SECCAT_TBSS:
6716 prefix = one_only ? ".tb" : ".tbss";
6717 break;
6718 default:
6719 gcc_unreachable ();
6722 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6723 name = targetm.strip_name_encoding (name);
6725 /* If we're using one_only, then there needs to be a .gnu.linkonce
6726 prefix to the section name. */
6727 linkonce = one_only ? ".gnu.linkonce" : "";
6729 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6731 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6734 /* Like compute_reloc_for_constant, except for an RTX. The return value
6735 is a mask for which bit 1 indicates a global relocation, and bit 0
6736 indicates a local relocation. */
6738 static int
6739 compute_reloc_for_rtx_1 (rtx *xp, void *data)
6741 int *preloc = (int *) data;
6742 rtx x = *xp;
6744 switch (GET_CODE (x))
6746 case SYMBOL_REF:
6747 *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
6748 break;
6749 case LABEL_REF:
6750 *preloc |= 1;
6751 break;
6752 default:
6753 break;
6756 return 0;
6759 static int
6760 compute_reloc_for_rtx (rtx x)
6762 int reloc;
6764 switch (GET_CODE (x))
6766 case CONST:
6767 case SYMBOL_REF:
6768 case LABEL_REF:
6769 reloc = 0;
6770 for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc);
6771 return reloc;
6773 default:
6774 return 0;
6778 section *
6779 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
6780 rtx x,
6781 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
6783 if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
6784 return data_section;
6785 else
6786 return readonly_data_section;
6789 section *
6790 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
6791 unsigned HOST_WIDE_INT align)
6793 int reloc = compute_reloc_for_rtx (x);
6795 /* ??? Handle small data here somehow. */
6797 if (reloc & targetm.asm_out.reloc_rw_mask ())
6799 if (reloc == 1)
6800 return get_named_section (NULL, ".data.rel.ro.local", 1);
6801 else
6802 return get_named_section (NULL, ".data.rel.ro", 3);
6805 return mergeable_constant_section (mode, align, 0);
6808 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6810 void
6811 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
6813 rtx symbol;
6814 int flags;
6816 /* Careful not to prod global register variables. */
6817 if (!MEM_P (rtl))
6818 return;
6819 symbol = XEXP (rtl, 0);
6820 if (GET_CODE (symbol) != SYMBOL_REF)
6821 return;
6823 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6824 if (TREE_CODE (decl) == FUNCTION_DECL)
6825 flags |= SYMBOL_FLAG_FUNCTION;
6826 if (targetm.binds_local_p (decl))
6827 flags |= SYMBOL_FLAG_LOCAL;
6828 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
6829 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6830 else if (targetm.in_small_data_p (decl))
6831 flags |= SYMBOL_FLAG_SMALL;
6832 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6833 being PUBLIC, the thing *must* be defined in this translation unit.
6834 Prevent this buglet from being propagated into rtl code as well. */
6835 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
6836 flags |= SYMBOL_FLAG_EXTERNAL;
6838 SYMBOL_REF_FLAGS (symbol) = flags;
6841 /* By default, we do nothing for encode_section_info, so we need not
6842 do anything but discard the '*' marker. */
6844 const char *
6845 default_strip_name_encoding (const char *str)
6847 return str + (*str == '*');
6850 #ifdef ASM_OUTPUT_DEF
6851 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6852 anchor relative to ".", the current section position. */
6854 void
6855 default_asm_output_anchor (rtx symbol)
6857 char buffer[100];
6859 sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
6860 SYMBOL_REF_BLOCK_OFFSET (symbol));
6861 ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
6863 #endif
6865 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6867 bool
6868 default_use_anchors_for_symbol_p (const_rtx symbol)
6870 section *sect;
6871 tree decl;
6873 /* Don't use anchors for mergeable sections. The linker might move
6874 the objects around. */
6875 sect = SYMBOL_REF_BLOCK (symbol)->sect;
6876 if (sect->common.flags & SECTION_MERGE)
6877 return false;
6879 /* Don't use anchors for small data sections. The small data register
6880 acts as an anchor for such sections. */
6881 if (sect->common.flags & SECTION_SMALL)
6882 return false;
6884 decl = SYMBOL_REF_DECL (symbol);
6885 if (decl && DECL_P (decl))
6887 /* Don't use section anchors for decls that might be defined by
6888 other modules. */
6889 if (!targetm.binds_local_p (decl))
6890 return false;
6892 /* Don't use section anchors for decls that will be placed in a
6893 small data section. */
6894 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6895 one above. The problem is that we only use SECTION_SMALL for
6896 sections that should be marked as small in the section directive. */
6897 if (targetm.in_small_data_p (decl))
6898 return false;
6900 return true;
6903 /* Return true when RESOLUTION indicate that symbol will be bound to the
6904 definition provided by current .o file. */
6906 static bool
6907 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution)
6909 return (resolution == LDPR_PREVAILING_DEF
6910 || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
6911 || resolution == LDPR_PREVAILING_DEF_IRONLY);
6914 /* Return true when RESOLUTION indicate that symbol will be bound locally
6915 within current executable or DSO. */
6917 static bool
6918 resolution_local_p (enum ld_plugin_symbol_resolution resolution)
6920 return (resolution == LDPR_PREVAILING_DEF
6921 || resolution == LDPR_PREVAILING_DEF_IRONLY
6922 || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
6923 || resolution == LDPR_PREEMPTED_REG
6924 || resolution == LDPR_PREEMPTED_IR
6925 || resolution == LDPR_RESOLVED_IR
6926 || resolution == LDPR_RESOLVED_EXEC);
6929 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6930 wrt cross-module name binding. */
6932 bool
6933 default_binds_local_p (const_tree exp)
6935 return default_binds_local_p_1 (exp, flag_shlib);
6938 bool
6939 default_binds_local_p_1 (const_tree exp, int shlib)
6941 bool local_p;
6942 bool resolved_locally = false;
6943 bool resolved_to_local_def = false;
6945 /* With resolution file in hands, take look into resolutions.
6946 We can't just return true for resolved_locally symbols,
6947 because dynamic linking might overwrite symbols
6948 in shared libraries. */
6949 if (TREE_CODE (exp) == VAR_DECL && TREE_PUBLIC (exp)
6950 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
6952 struct varpool_node *vnode = varpool_get_node (exp);
6953 if (vnode && resolution_local_p (vnode->resolution))
6954 resolved_locally = true;
6955 if (vnode
6956 && resolution_to_local_definition_p (vnode->resolution))
6957 resolved_to_local_def = true;
6959 else if (TREE_CODE (exp) == FUNCTION_DECL && TREE_PUBLIC (exp))
6961 struct cgraph_node *node = cgraph_get_node (exp);
6962 if (node
6963 && resolution_local_p (node->resolution))
6964 resolved_locally = true;
6965 if (node
6966 && resolution_to_local_definition_p (node->resolution))
6967 resolved_to_local_def = true;
6970 /* A non-decl is an entry in the constant pool. */
6971 if (!DECL_P (exp))
6972 local_p = true;
6973 /* Weakrefs may not bind locally, even though the weakref itself is always
6974 static and therefore local. Similarly, the resolver for ifunc functions
6975 might resolve to a non-local function.
6976 FIXME: We can resolve the weakref case more curefuly by looking at the
6977 weakref alias. */
6978 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp))
6979 || (TREE_CODE (exp) == FUNCTION_DECL
6980 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (exp))))
6981 local_p = false;
6982 /* Static variables are always local. */
6983 else if (! TREE_PUBLIC (exp))
6984 local_p = true;
6985 /* A variable is local if the user has said explicitly that it will
6986 be. */
6987 else if ((DECL_VISIBILITY_SPECIFIED (exp)
6988 || resolved_to_local_def)
6989 && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6990 local_p = true;
6991 /* Variables defined outside this object might not be local. */
6992 else if (DECL_EXTERNAL (exp) && !resolved_locally)
6993 local_p = false;
6994 /* If defined in this object and visibility is not default, must be
6995 local. */
6996 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
6997 local_p = true;
6998 /* Default visibility weak data can be overridden by a strong symbol
6999 in another module and so are not local. */
7000 else if (DECL_WEAK (exp)
7001 && !resolved_locally)
7002 local_p = false;
7003 /* If PIC, then assume that any global name can be overridden by
7004 symbols resolved from other modules. */
7005 else if (shlib)
7006 local_p = false;
7007 /* Uninitialized COMMON variable may be unified with symbols
7008 resolved from other modules. */
7009 else if (DECL_COMMON (exp)
7010 && !resolved_locally
7011 && (DECL_INITIAL (exp) == NULL
7012 || DECL_INITIAL (exp) == error_mark_node))
7013 local_p = false;
7014 /* Otherwise we're left with initialized (or non-common) global data
7015 which is of necessity defined locally. */
7016 else
7017 local_p = true;
7019 return local_p;
7022 /* Return true when references to DECL must bind to current definition in
7023 final executable.
7025 The condition is usually equivalent to whether the function binds to the
7026 current module (shared library or executable), that is to binds_local_p.
7027 We use this fact to avoid need for another target hook and implement
7028 the logic using binds_local_p and just special cases where
7029 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
7030 the weak definitions (that can be overwritten at linktime by other
7031 definition from different object file) and when resolution info is available
7032 we simply use the knowledge passed to us by linker plugin. */
7033 bool
7034 decl_binds_to_current_def_p (tree decl)
7036 gcc_assert (DECL_P (decl));
7037 if (!TREE_PUBLIC (decl))
7038 return true;
7039 if (!targetm.binds_local_p (decl))
7040 return false;
7041 /* When resolution is available, just use it. */
7042 if (TREE_CODE (decl) == VAR_DECL
7043 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
7045 struct varpool_node *vnode = varpool_get_node (decl);
7046 if (vnode
7047 && vnode->resolution != LDPR_UNKNOWN)
7048 return resolution_to_local_definition_p (vnode->resolution);
7050 else if (TREE_CODE (decl) == FUNCTION_DECL)
7052 struct cgraph_node *node = cgraph_get_node (decl);
7053 if (node
7054 && node->resolution != LDPR_UNKNOWN)
7055 return resolution_to_local_definition_p (node->resolution);
7057 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
7058 binds locally but still can be overwritten).
7059 This rely on fact that binds_local_p behave as decl_replaceable_p
7060 for all other declaration types. */
7061 return !DECL_WEAK (decl);
7064 /* A replaceable function or variable is one which may be replaced
7065 at link-time with an entirely different definition, provided that the
7066 replacement has the same type. For example, functions declared
7067 with __attribute__((weak)) on most systems are replaceable.
7069 COMDAT functions are not replaceable, since all definitions of the
7070 function must be equivalent. It is important that COMDAT functions
7071 not be treated as replaceable so that use of C++ template
7072 instantiations is not penalized. */
7074 bool
7075 decl_replaceable_p (tree decl)
7077 gcc_assert (DECL_P (decl));
7078 if (!TREE_PUBLIC (decl) || DECL_COMDAT (decl))
7079 return false;
7080 return !decl_binds_to_current_def_p (decl);
7083 /* Default function to output code that will globalize a label. A
7084 target must define GLOBAL_ASM_OP or provide its own function to
7085 globalize a label. */
7086 #ifdef GLOBAL_ASM_OP
7087 void
7088 default_globalize_label (FILE * stream, const char *name)
7090 fputs (GLOBAL_ASM_OP, stream);
7091 assemble_name (stream, name);
7092 putc ('\n', stream);
7094 #endif /* GLOBAL_ASM_OP */
7096 /* Default function to output code that will globalize a declaration. */
7097 void
7098 default_globalize_decl_name (FILE * stream, tree decl)
7100 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
7101 targetm.asm_out.globalize_label (stream, name);
7104 /* Default function to output a label for unwind information. The
7105 default is to do nothing. A target that needs nonlocal labels for
7106 unwind information must provide its own function to do this. */
7107 void
7108 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
7109 tree decl ATTRIBUTE_UNUSED,
7110 int for_eh ATTRIBUTE_UNUSED,
7111 int empty ATTRIBUTE_UNUSED)
7115 /* Default function to output a label to divide up the exception table.
7116 The default is to do nothing. A target that needs/wants to divide
7117 up the table must provide it's own function to do this. */
7118 void
7119 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
7123 /* This is how to output an internal numbered label where PREFIX is
7124 the class of label and LABELNO is the number within the class. */
7126 void
7127 default_generate_internal_label (char *buf, const char *prefix,
7128 unsigned long labelno)
7130 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
7133 /* This is how to output an internal numbered label where PREFIX is
7134 the class of label and LABELNO is the number within the class. */
7136 void
7137 default_internal_label (FILE *stream, const char *prefix,
7138 unsigned long labelno)
7140 char *const buf = (char *) alloca (40 + strlen (prefix));
7141 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
7142 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
7146 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
7148 void
7149 default_asm_declare_constant_name (FILE *file, const char *name,
7150 const_tree exp ATTRIBUTE_UNUSED,
7151 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
7153 assemble_label (file, name);
7156 /* This is the default behavior at the beginning of a file. It's
7157 controlled by two other target-hook toggles. */
7158 void
7159 default_file_start (void)
7161 if (targetm.asm_file_start_app_off
7162 && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
7163 fputs (ASM_APP_OFF, asm_out_file);
7165 if (targetm.asm_file_start_file_directive)
7166 output_file_directive (asm_out_file, main_input_filename);
7169 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
7170 which emits a special section directive used to indicate whether or
7171 not this object file needs an executable stack. This is primarily
7172 a GNU extension to ELF but could be used on other targets. */
7174 int trampolines_created;
7176 void
7177 file_end_indicate_exec_stack (void)
7179 unsigned int flags = SECTION_DEBUG;
7180 if (trampolines_created)
7181 flags |= SECTION_CODE;
7183 switch_to_section (get_section (".note.GNU-stack", flags, NULL));
7186 /* Emit a special section directive to indicate that this object file
7187 was compiled with -fsplit-stack. This is used to let the linker
7188 detect calls between split-stack code and non-split-stack code, so
7189 that it can modify the split-stack code to allocate a sufficiently
7190 large stack. We emit another special section if there are any
7191 functions in this file which have the no_split_stack attribute, to
7192 prevent the linker from warning about being unable to convert the
7193 functions if they call non-split-stack code. */
7195 void
7196 file_end_indicate_split_stack (void)
7198 if (flag_split_stack)
7200 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG,
7201 NULL));
7202 if (saw_no_split_stack)
7203 switch_to_section (get_section (".note.GNU-no-split-stack",
7204 SECTION_DEBUG, NULL));
7208 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
7209 a get_unnamed_section callback. */
7211 void
7212 output_section_asm_op (const void *directive)
7214 fprintf (asm_out_file, "%s\n", (const char *) directive);
7217 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
7218 the current section is NEW_SECTION. */
7220 void
7221 switch_to_section (section *new_section)
7223 if (in_section == new_section)
7224 return;
7226 if (new_section->common.flags & SECTION_FORGET)
7227 in_section = NULL;
7228 else
7229 in_section = new_section;
7231 switch (SECTION_STYLE (new_section))
7233 case SECTION_NAMED:
7234 targetm.asm_out.named_section (new_section->named.name,
7235 new_section->named.common.flags,
7236 new_section->named.decl);
7237 break;
7239 case SECTION_UNNAMED:
7240 new_section->unnamed.callback (new_section->unnamed.data);
7241 break;
7243 case SECTION_NOSWITCH:
7244 gcc_unreachable ();
7245 break;
7248 new_section->common.flags |= SECTION_DECLARED;
7251 /* If block symbol SYMBOL has not yet been assigned an offset, place
7252 it at the end of its block. */
7254 void
7255 place_block_symbol (rtx symbol)
7257 unsigned HOST_WIDE_INT size, mask, offset;
7258 struct constant_descriptor_rtx *desc;
7259 unsigned int alignment;
7260 struct object_block *block;
7261 tree decl;
7263 gcc_assert (SYMBOL_REF_BLOCK (symbol));
7264 if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
7265 return;
7267 /* Work out the symbol's size and alignment. */
7268 if (CONSTANT_POOL_ADDRESS_P (symbol))
7270 desc = SYMBOL_REF_CONSTANT (symbol);
7271 alignment = desc->align;
7272 size = GET_MODE_SIZE (desc->mode);
7274 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7276 decl = SYMBOL_REF_DECL (symbol);
7277 alignment = DECL_ALIGN (decl);
7278 size = get_constant_size (DECL_INITIAL (decl));
7280 else
7282 decl = SYMBOL_REF_DECL (symbol);
7283 alignment = DECL_ALIGN (decl);
7284 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7287 /* Calculate the object's offset from the start of the block. */
7288 block = SYMBOL_REF_BLOCK (symbol);
7289 mask = alignment / BITS_PER_UNIT - 1;
7290 offset = (block->size + mask) & ~mask;
7291 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
7293 /* Record the block's new alignment and size. */
7294 block->alignment = MAX (block->alignment, alignment);
7295 block->size = offset + size;
7297 VEC_safe_push (rtx, gc, block->objects, symbol);
7300 /* Return the anchor that should be used to address byte offset OFFSET
7301 from the first object in BLOCK. MODEL is the TLS model used
7302 to access it. */
7305 get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
7306 enum tls_model model)
7308 char label[100];
7309 unsigned int begin, middle, end;
7310 unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
7311 rtx anchor;
7313 /* Work out the anchor's offset. Use an offset of 0 for the first
7314 anchor so that we don't pessimize the case where we take the address
7315 of a variable at the beginning of the block. This is particularly
7316 useful when a block has only one variable assigned to it.
7318 We try to place anchors RANGE bytes apart, so there can then be
7319 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7320 a ptr_mode offset. With some target settings, the lowest such
7321 anchor might be out of range for the lowest ptr_mode offset;
7322 likewise the highest anchor for the highest offset. Use anchors
7323 at the extreme ends of the ptr_mode range in such cases.
7325 All arithmetic uses unsigned integers in order to avoid
7326 signed overflow. */
7327 max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
7328 min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
7329 range = max_offset - min_offset + 1;
7330 if (range == 0)
7331 offset = 0;
7332 else
7334 bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
7335 if (offset < 0)
7337 delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
7338 delta -= delta % range;
7339 if (delta > bias)
7340 delta = bias;
7341 offset = (HOST_WIDE_INT) (-delta);
7343 else
7345 delta = (unsigned HOST_WIDE_INT) offset - min_offset;
7346 delta -= delta % range;
7347 if (delta > bias - 1)
7348 delta = bias - 1;
7349 offset = (HOST_WIDE_INT) delta;
7353 /* Do a binary search to see if there's already an anchor we can use.
7354 Set BEGIN to the new anchor's index if not. */
7355 begin = 0;
7356 end = VEC_length (rtx, block->anchors);
7357 while (begin != end)
7359 middle = (end + begin) / 2;
7360 anchor = VEC_index (rtx, block->anchors, middle);
7361 if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
7362 end = middle;
7363 else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
7364 begin = middle + 1;
7365 else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
7366 end = middle;
7367 else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
7368 begin = middle + 1;
7369 else
7370 return anchor;
7373 /* Create a new anchor with a unique label. */
7374 ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
7375 anchor = create_block_symbol (ggc_strdup (label), block, offset);
7376 SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
7377 SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
7379 /* Insert it at index BEGIN. */
7380 VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
7381 return anchor;
7384 /* Output the objects in BLOCK. */
7386 static void
7387 output_object_block (struct object_block *block)
7389 struct constant_descriptor_rtx *desc;
7390 unsigned int i;
7391 HOST_WIDE_INT offset;
7392 tree decl;
7393 rtx symbol;
7395 if (block->objects == NULL)
7396 return;
7398 /* Switch to the section and make sure that the first byte is
7399 suitably aligned. */
7400 switch_to_section (block->sect);
7401 assemble_align (block->alignment);
7403 /* Define the values of all anchors relative to the current section
7404 position. */
7405 FOR_EACH_VEC_ELT (rtx, block->anchors, i, symbol)
7406 targetm.asm_out.output_anchor (symbol);
7408 /* Output the objects themselves. */
7409 offset = 0;
7410 FOR_EACH_VEC_ELT (rtx, block->objects, i, symbol)
7412 /* Move to the object's offset, padding with zeros if necessary. */
7413 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
7414 offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
7415 if (CONSTANT_POOL_ADDRESS_P (symbol))
7417 desc = SYMBOL_REF_CONSTANT (symbol);
7418 output_constant_pool_1 (desc, 1);
7419 offset += GET_MODE_SIZE (desc->mode);
7421 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
7423 decl = SYMBOL_REF_DECL (symbol);
7424 assemble_constant_contents (DECL_INITIAL (decl), XSTR (symbol, 0),
7425 DECL_ALIGN (decl));
7426 offset += get_constant_size (DECL_INITIAL (decl));
7428 else
7430 decl = SYMBOL_REF_DECL (symbol);
7431 assemble_variable_contents (decl, XSTR (symbol, 0), false);
7432 offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
7437 /* A htab_traverse callback used to call output_object_block for
7438 each member of object_block_htab. */
7440 static int
7441 output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
7443 output_object_block ((struct object_block *) (*slot));
7444 return 1;
7447 /* Output the definitions of all object_blocks. */
7449 void
7450 output_object_blocks (void)
7452 htab_traverse (object_block_htab, output_object_block_htab, NULL);
7455 /* This function provides a possible implementation of the
7456 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7457 by -frecord-gcc-switches it creates a new mergeable, string section in the
7458 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7459 contains the switches in ASCII format.
7461 FIXME: This code does not correctly handle double quote characters
7462 that appear inside strings, (it strips them rather than preserving them).
7463 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7464 characters - instead it treats them as sub-string separators. Since
7465 we want to emit NUL strings terminators into the object file we have to use
7466 ASM_OUTPUT_SKIP. */
7469 elf_record_gcc_switches (print_switch_type type, const char * name)
7471 switch (type)
7473 case SWITCH_TYPE_PASSED:
7474 ASM_OUTPUT_ASCII (asm_out_file, name, strlen (name));
7475 ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
7476 break;
7478 case SWITCH_TYPE_DESCRIPTIVE:
7479 if (name == NULL)
7481 /* Distinguish between invocations where name is NULL. */
7482 static bool started = false;
7484 if (!started)
7486 section * sec;
7488 sec = get_section (targetm.asm_out.record_gcc_switches_section,
7489 SECTION_DEBUG
7490 | SECTION_MERGE
7491 | SECTION_STRINGS
7492 | (SECTION_ENTSIZE & 1),
7493 NULL);
7494 switch_to_section (sec);
7495 started = true;
7499 default:
7500 break;
7503 /* The return value is currently ignored by the caller, but must be 0.
7504 For -fverbose-asm the return value would be the number of characters
7505 emitted into the assembler file. */
7506 return 0;
7509 /* Emit text to declare externally defined symbols. It is needed to
7510 properly support non-default visibility. */
7511 void
7512 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
7513 tree decl,
7514 const char *name ATTRIBUTE_UNUSED)
7516 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7517 set in order to avoid putting out names that are never really
7518 used. */
7519 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
7520 && targetm.binds_local_p (decl))
7521 maybe_assemble_visibility (decl);
7524 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7526 void
7527 default_asm_output_source_filename (FILE *file, const char *name)
7529 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7530 ASM_OUTPUT_SOURCE_FILENAME (file, name);
7531 #else
7532 fprintf (file, "\t.file\t");
7533 output_quoted_string (file, name);
7534 putc ('\n', file);
7535 #endif
7538 /* Output a file name in the form wanted by System V. */
7540 void
7541 output_file_directive (FILE *asm_file, const char *input_name)
7543 int len;
7544 const char *na;
7546 if (input_name == NULL)
7547 input_name = "<stdin>";
7548 else
7549 input_name = remap_debug_filename (input_name);
7551 len = strlen (input_name);
7552 na = input_name + len;
7554 /* NA gets INPUT_NAME sans directory names. */
7555 while (na > input_name)
7557 if (IS_DIR_SEPARATOR (na[-1]))
7558 break;
7559 na--;
7562 targetm.asm_out.output_source_filename (asm_file, na);
7565 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7566 EXP. */
7568 make_debug_expr_from_rtl (const_rtx exp)
7570 tree ddecl = make_node (DEBUG_EXPR_DECL), type;
7571 enum machine_mode mode = GET_MODE (exp);
7572 rtx dval;
7574 DECL_ARTIFICIAL (ddecl) = 1;
7575 if (REG_P (exp) && REG_EXPR (exp))
7576 type = TREE_TYPE (REG_EXPR (exp));
7577 else if (MEM_P (exp) && MEM_EXPR (exp))
7578 type = TREE_TYPE (MEM_EXPR (exp));
7579 else
7580 type = NULL_TREE;
7581 if (type && TYPE_MODE (type) == mode)
7582 TREE_TYPE (ddecl) = type;
7583 else
7584 TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
7585 DECL_MODE (ddecl) = mode;
7586 dval = gen_rtx_DEBUG_EXPR (mode);
7587 DEBUG_EXPR_TREE_DECL (dval) = ddecl;
7588 SET_DECL_RTL (ddecl, dval);
7589 return dval;
7592 #ifdef ELF_ASCII_ESCAPES
7593 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
7595 void
7596 default_elf_asm_output_limited_string (FILE *f, const char *s)
7598 int escape;
7599 unsigned char c;
7601 fputs (STRING_ASM_OP, f);
7602 putc ('"', f);
7603 while (*s != '\0')
7605 c = *s;
7606 escape = ELF_ASCII_ESCAPES[c];
7607 switch (escape)
7609 case 0:
7610 putc (c, f);
7611 break;
7612 case 1:
7613 /* TODO: Print in hex with fast function, important for -flto. */
7614 fprintf (f, "\\%03o", c);
7615 break;
7616 default:
7617 putc ('\\', f);
7618 putc (escape, f);
7619 break;
7621 s++;
7623 putc ('\"', f);
7624 putc ('\n', f);
7627 /* Default ASM_OUTPUT_ASCII for ELF targets. */
7629 void
7630 default_elf_asm_output_ascii (FILE *f, const char *s, unsigned int len)
7632 const char *limit = s + len;
7633 const char *last_null = NULL;
7634 unsigned bytes_in_chunk = 0;
7635 unsigned char c;
7636 int escape;
7638 for (; s < limit; s++)
7640 const char *p;
7642 if (bytes_in_chunk >= 60)
7644 putc ('\"', f);
7645 putc ('\n', f);
7646 bytes_in_chunk = 0;
7649 if (s > last_null)
7651 for (p = s; p < limit && *p != '\0'; p++)
7652 continue;
7653 last_null = p;
7655 else
7656 p = last_null;
7658 if (p < limit && (p - s) <= (long) ELF_STRING_LIMIT)
7660 if (bytes_in_chunk > 0)
7662 putc ('\"', f);
7663 putc ('\n', f);
7664 bytes_in_chunk = 0;
7667 default_elf_asm_output_limited_string (f, s);
7668 s = p;
7670 else
7672 if (bytes_in_chunk == 0)
7673 fputs (ASCII_DATA_ASM_OP "\"", f);
7675 c = *s;
7676 escape = ELF_ASCII_ESCAPES[c];
7677 switch (escape)
7679 case 0:
7680 putc (c, f);
7681 bytes_in_chunk++;
7682 break;
7683 case 1:
7684 /* TODO: Print in hex with fast function, important for -flto. */
7685 fprintf (f, "\\%03o", c);
7686 bytes_in_chunk += 4;
7687 break;
7688 default:
7689 putc ('\\', f);
7690 putc (escape, f);
7691 bytes_in_chunk += 2;
7692 break;
7698 if (bytes_in_chunk > 0)
7700 putc ('\"', f);
7701 putc ('\n', f);
7704 #endif
7706 static GTY(()) section *elf_init_array_section;
7707 static GTY(()) section *elf_fini_array_section;
7709 static section *
7710 get_elf_initfini_array_priority_section (int priority,
7711 bool constructor_p)
7713 section *sec;
7714 if (priority != DEFAULT_INIT_PRIORITY)
7716 char buf[18];
7717 sprintf (buf, "%s.%.5u",
7718 constructor_p ? ".init_array" : ".fini_array",
7719 priority);
7720 sec = get_section (buf, SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
7722 else
7724 if (constructor_p)
7726 if (elf_init_array_section == NULL)
7727 elf_init_array_section
7728 = get_section (".init_array",
7729 SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
7730 sec = elf_init_array_section;
7732 else
7734 if (elf_fini_array_section == NULL)
7735 elf_fini_array_section
7736 = get_section (".fini_array",
7737 SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
7738 sec = elf_fini_array_section;
7741 return sec;
7744 /* Use .init_array section for constructors. */
7746 void
7747 default_elf_init_array_asm_out_constructor (rtx symbol, int priority)
7749 section *sec = get_elf_initfini_array_priority_section (priority,
7750 true);
7751 assemble_addr_to_section (symbol, sec);
7754 /* Use .fini_array section for destructors. */
7756 void
7757 default_elf_fini_array_asm_out_destructor (rtx symbol, int priority)
7759 section *sec = get_elf_initfini_array_priority_section (priority,
7760 false);
7761 assemble_addr_to_section (symbol, sec);
7764 #include "gt-varasm.h"