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
4 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 2, or (at your option) any later
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
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 /* This file handles generation of all the assembler code
25 *except* the instructions of a function.
26 This includes declarations of variables and their initial values.
28 We also output the assembler code for constants stored in memory
29 and are responsible for combining constants with the same value. */
33 #include "coretypes.h"
40 #include "hard-reg-set.h"
48 #include "langhooks.h"
52 #include "tree-mudflap.h"
54 #include "cfglayout.h"
56 #ifdef XCOFF_DEBUGGING_INFO
57 #include "xcoffout.h" /* Needed for external data
58 declarations for e.g. AIX 4.x. */
61 /* The (assembler) name of the first globally-visible object output. */
62 const char *first_global_object_name;
63 const char *weak_global_object_name;
66 struct constant_descriptor_rtx;
67 struct rtx_constant_pool;
69 struct varasm_status GTY(())
71 /* If we're using a per-function constant pool, this is it. */
72 struct rtx_constant_pool *pool;
74 /* Number of tree-constants deferred during the expansion of this
76 unsigned int deferred_constants;
79 #define n_deferred_constants (cfun->varasm->deferred_constants)
81 /* Number for making the label on the next
82 constant that is stored in memory. */
84 static GTY(()) int const_labelno;
86 /* Carry information from ASM_DECLARE_OBJECT_NAME
87 to ASM_FINISH_DECLARE_OBJECT. */
89 int size_directive_output;
91 /* The last decl for which assemble_variable was called,
92 if it did ASM_DECLARE_OBJECT_NAME.
93 If the last call to assemble_variable didn't do that,
96 tree last_assemble_variable_decl;
98 /* The following global variable indicates if the section label for the
99 "cold" section of code has been output yet to the assembler. The
100 label is useful when running gdb. This is part of the optimization that
101 partitions hot and cold basic blocks into separate sections of the .o
104 static bool unlikely_section_label_printed = false;
106 /* The following global variable indicates the label name to be put at
107 the start of the first cold section within each function, when
108 partitioning basic blocks into hot and cold sections. */
110 static char *unlikely_section_label = NULL;
112 /* The following global variable indicates the section name to be used
113 for the current cold section, when partitioning hot and cold basic
114 blocks into separate sections. */
116 static char *unlikely_text_section_name = NULL;
118 /* We give all constants their own alias set. Perhaps redundant with
119 MEM_READONLY_P, but pre-dates it. */
121 static HOST_WIDE_INT const_alias_set;
123 static const char *strip_reg_name (const char *);
124 static int contains_pointers_p (tree);
125 #ifdef ASM_OUTPUT_EXTERNAL
126 static bool incorporeal_function_p (tree);
128 static void decode_addr_const (tree, struct addr_const *);
129 static hashval_t const_desc_hash (const void *);
130 static int const_desc_eq (const void *, const void *);
131 static hashval_t const_hash_1 (const tree);
132 static int compare_constant (const tree, const tree);
133 static tree copy_constant (tree);
134 static void output_constant_def_contents (rtx);
135 static void output_addressed_constants (tree);
136 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
137 static unsigned min_align (unsigned, unsigned);
138 static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int);
139 static void globalize_decl (tree);
140 static void maybe_assemble_visibility (tree);
141 static int in_named_entry_eq (const void *, const void *);
142 static hashval_t in_named_entry_hash (const void *);
143 #ifdef BSS_SECTION_ASM_OP
144 #ifdef ASM_OUTPUT_BSS
145 static void asm_output_bss (FILE *, tree, const char *,
146 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
148 #ifdef ASM_OUTPUT_ALIGNED_BSS
149 static void asm_output_aligned_bss (FILE *, tree, const char *,
150 unsigned HOST_WIDE_INT, int)
153 #endif /* BSS_SECTION_ASM_OP */
154 static bool asm_emit_uninitialised (tree, const char*,
155 unsigned HOST_WIDE_INT,
156 unsigned HOST_WIDE_INT);
157 static void mark_weak (tree);
159 enum in_section { no_section, in_text, in_unlikely_executed_text, in_data,
161 #ifdef BSS_SECTION_ASM_OP
164 #ifdef CTORS_SECTION_ASM_OP
167 #ifdef DTORS_SECTION_ASM_OP
170 #ifdef READONLY_DATA_SECTION_ASM_OP
173 #ifdef EXTRA_SECTIONS
177 static GTY(()) enum in_section in_section = no_section;
179 /* Return a nonzero value if DECL has a section attribute. */
180 #ifndef IN_NAMED_SECTION
181 #define IN_NAMED_SECTION(DECL) \
182 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
183 && DECL_SECTION_NAME (DECL) != NULL_TREE)
186 /* Text of section name when in_section == in_named. */
187 static GTY(()) const char *in_named_name;
189 /* Hash table of flags that have been used for a particular named section. */
191 struct in_named_entry GTY(())
198 static GTY((param_is (struct in_named_entry))) htab_t in_named_htab;
200 /* Define functions like text_section for any extra sections. */
201 #ifdef EXTRA_SECTION_FUNCTIONS
202 EXTRA_SECTION_FUNCTIONS
205 /* Tell assembler to switch to text section. */
210 if (in_section != in_text)
212 in_section = in_text;
213 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
217 /* Tell assembler to switch to unlikely-to-be-executed text section. */
220 unlikely_text_section (void)
225 if (! unlikely_text_section_name)
227 if (DECL_SECTION_NAME (current_function_decl)
228 && (strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME
229 (current_function_decl)),
230 HOT_TEXT_SECTION_NAME) != 0)
231 && (strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME
232 (current_function_decl)),
233 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) != 0))
235 name = TREE_STRING_POINTER (DECL_SECTION_NAME
236 (current_function_decl));
238 unlikely_text_section_name = xmalloc ((len + 10) * sizeof (char));
239 strcpy (unlikely_text_section_name, name);
240 strcat (unlikely_text_section_name, "_unlikely");
244 len = strlen (UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
245 unlikely_text_section_name = xmalloc (len+1 * sizeof (char));
246 strcpy (unlikely_text_section_name,
247 UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
251 if ((in_section != in_unlikely_executed_text)
252 && (in_section != in_named
253 || strcmp (in_named_name, unlikely_text_section_name) != 0))
255 named_section (NULL_TREE, unlikely_text_section_name, 0);
256 in_section = in_unlikely_executed_text;
258 if (!unlikely_section_label_printed)
260 ASM_OUTPUT_LABEL (asm_out_file, unlikely_section_label);
261 unlikely_section_label_printed = true;
266 /* Tell assembler to switch to data section. */
271 if (in_section != in_data)
273 in_section = in_data;
274 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
278 /* Tell assembler to switch to read-only data section. This is normally
282 readonly_data_section (void)
284 #ifdef READONLY_DATA_SECTION
285 READONLY_DATA_SECTION (); /* Note this can call data_section. */
287 #ifdef READONLY_DATA_SECTION_ASM_OP
288 if (in_section != in_readonly_data)
290 in_section = in_readonly_data;
291 fputs (READONLY_DATA_SECTION_ASM_OP, asm_out_file);
292 fputc ('\n', asm_out_file);
300 /* Determine if we're in the text section. */
303 in_text_section (void)
305 return in_section == in_text;
308 /* Determine if we're in the unlikely-to-be-executed text section. */
311 in_unlikely_text_section (void)
315 ret_val = ((in_section == in_unlikely_executed_text)
316 || (in_section == in_named
317 && unlikely_text_section_name
318 && strcmp (in_named_name, unlikely_text_section_name) == 0));
323 /* Determine if we're in the data section. */
326 in_data_section (void)
328 return in_section == in_data;
331 /* Helper routines for maintaining in_named_htab. */
334 in_named_entry_eq (const void *p1, const void *p2)
336 const struct in_named_entry *old = p1;
337 const char *new = p2;
339 return strcmp (old->name, new) == 0;
343 in_named_entry_hash (const void *p)
345 const struct in_named_entry *old = p;
346 return htab_hash_string (old->name);
349 /* If SECTION has been seen before as a named section, return the flags
350 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
351 set of flags for a section to have, so 0 does not mean that the section
352 has not been seen. */
355 get_named_section_flags (const char *section)
357 struct in_named_entry **slot;
359 slot = (struct in_named_entry **)
360 htab_find_slot_with_hash (in_named_htab, section,
361 htab_hash_string (section), NO_INSERT);
363 return slot ? (*slot)->flags : 0;
366 /* Returns true if the section has been declared before. Sets internal
367 flag on this section in in_named_hash so subsequent calls on this
368 section will return false. */
371 named_section_first_declaration (const char *name)
373 struct in_named_entry **slot;
375 slot = (struct in_named_entry **)
376 htab_find_slot_with_hash (in_named_htab, name,
377 htab_hash_string (name), NO_INSERT);
378 if (! (*slot)->declared)
380 (*slot)->declared = true;
390 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
391 different set of flags, return false. */
394 set_named_section_flags (const char *section, unsigned int flags)
396 struct in_named_entry **slot, *entry;
398 slot = (struct in_named_entry **)
399 htab_find_slot_with_hash (in_named_htab, section,
400 htab_hash_string (section), INSERT);
405 entry = ggc_alloc (sizeof (*entry));
407 entry->name = ggc_strdup (section);
408 entry->flags = flags;
409 entry->declared = false;
411 else if (entry->flags != flags)
417 /* Tell assembler to change to section NAME with attributes FLAGS. If
418 DECL is non-NULL, it is the VAR_DECL or FUNCTION_DECL with which
419 this section is associated. */
422 named_section_real (const char *name, unsigned int flags, tree decl)
424 if (in_section != in_named || strcmp (name, in_named_name) != 0)
426 bool unchanged = set_named_section_flags (name, flags);
428 gcc_assert (unchanged);
430 targetm.asm_out.named_section (name, flags, decl);
432 if (flags & SECTION_FORGET)
433 in_section = no_section;
436 in_named_name = ggc_strdup (name);
437 in_section = in_named;
442 /* Tell assembler to change to section NAME for DECL.
443 If DECL is NULL, just switch to section NAME.
444 If NAME is NULL, get the name from DECL.
445 If RELOC is 1, the initializer for DECL contains relocs. */
448 named_section (tree decl, const char *name, int reloc)
452 gcc_assert (!decl || DECL_P (decl));
454 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
456 if (strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0
457 && !unlikely_text_section_name)
458 unlikely_text_section_name =
459 xstrdup (UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
461 flags = targetm.section_type_flags (decl, name, reloc);
463 /* Sanity check user variables for flag changes. Non-user
464 section flag changes will abort in named_section_flags.
465 However, don't complain if SECTION_OVERRIDE is set.
466 We trust that the setter knows that it is safe to ignore
467 the default flags for this decl. */
468 if (decl && ! set_named_section_flags (name, flags))
470 flags = get_named_section_flags (name);
471 if ((flags & SECTION_OVERRIDE) == 0)
472 error ("%J%D causes a section type conflict", decl, decl);
475 named_section_real (name, flags, decl);
478 /* If required, set DECL_SECTION_NAME to a unique name. */
481 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
482 int flag_function_or_data_sections)
484 if (DECL_SECTION_NAME (decl) == NULL_TREE
485 && targetm.have_named_sections
486 && (flag_function_or_data_sections
487 || DECL_ONE_ONLY (decl)))
488 targetm.asm_out.unique_section (decl, reloc);
491 #ifdef BSS_SECTION_ASM_OP
493 /* Tell the assembler to switch to the bss section. */
498 if (in_section != in_bss)
500 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
505 #ifdef ASM_OUTPUT_BSS
507 /* Utility function for ASM_OUTPUT_BSS for targets to use if
508 they don't support alignments in .bss.
509 ??? It is believed that this function will work in most cases so such
510 support is localized here. */
513 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
515 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
516 unsigned HOST_WIDE_INT rounded)
518 targetm.asm_out.globalize_label (file, name);
520 #ifdef ASM_DECLARE_OBJECT_NAME
521 last_assemble_variable_decl = decl;
522 ASM_DECLARE_OBJECT_NAME (file, name, decl);
524 /* Standard thing is just output label for the object. */
525 ASM_OUTPUT_LABEL (file, name);
526 #endif /* ASM_DECLARE_OBJECT_NAME */
527 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
532 #ifdef ASM_OUTPUT_ALIGNED_BSS
534 /* Utility function for targets to use in implementing
535 ASM_OUTPUT_ALIGNED_BSS.
536 ??? It is believed that this function will work in most cases so such
537 support is localized here. */
540 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
541 const char *name, unsigned HOST_WIDE_INT size,
545 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
546 #ifdef ASM_DECLARE_OBJECT_NAME
547 last_assemble_variable_decl = decl;
548 ASM_DECLARE_OBJECT_NAME (file, name, decl);
550 /* Standard thing is just output label for the object. */
551 ASM_OUTPUT_LABEL (file, name);
552 #endif /* ASM_DECLARE_OBJECT_NAME */
553 ASM_OUTPUT_SKIP (file, size ? size : 1);
558 #endif /* BSS_SECTION_ASM_OP */
560 /* Switch to the section for function DECL.
562 If DECL is NULL_TREE, switch to the text section. We can be passed
563 NULL_TREE under some circumstances by dbxout.c at least. */
566 function_section (tree decl)
568 if (decl == NULL_TREE)
572 /* ??? Typical use of this function maybe shouldn't be looking
573 for unlikely blocks at all - in the event that an entire
574 function is going into the unlikely-execute section, that
575 should be reflected in its DECL_SECTION_NAME. */
576 rtx insns = cfun && cfun->emit ? get_insns () : 0;
577 bool unlikely = insns && scan_ahead_for_unlikely_executed_note (insns);
579 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
580 targetm.asm_out.select_section (decl, unlikely, DECL_ALIGN (decl));
583 unlikely_text_section ();
584 else if (DECL_SECTION_NAME (decl))
585 named_section (decl, 0, 0);
592 /* Switch to read-only data section associated with function DECL. */
595 default_function_rodata_section (tree decl)
597 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
599 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
601 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
602 if (DECL_ONE_ONLY (decl) && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
604 size_t len = strlen (name) + 1;
605 char *rname = alloca (len);
607 memcpy (rname, name, len);
609 named_section_real (rname, SECTION_LINKONCE, decl);
612 /* For .text.foo we want to use .rodata.foo. */
613 else if (flag_function_sections && flag_data_sections
614 && strncmp (name, ".text.", 6) == 0)
616 size_t len = strlen (name) + 1;
617 char *rname = alloca (len + 2);
619 memcpy (rname, ".rodata", 7);
620 memcpy (rname + 7, name + 5, len - 5);
621 named_section_flags (rname, 0);
626 readonly_data_section ();
629 /* Switch to read-only data section associated with function DECL
630 for targets where that section should be always the single
631 readonly data section. */
634 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
636 readonly_data_section ();
639 /* Switch to section for variable DECL. RELOC is the same as the
640 argument to SELECT_SECTION. */
643 variable_section (tree decl, int reloc)
645 if (IN_NAMED_SECTION (decl))
646 named_section (decl, NULL, reloc);
648 targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
651 /* Tell assembler to switch to the section for string merging. */
654 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
655 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
656 unsigned int flags ATTRIBUTE_UNUSED)
658 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
659 && TREE_CODE (decl) == STRING_CST
660 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
662 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
664 enum machine_mode mode;
665 unsigned int modesize;
670 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
671 modesize = GET_MODE_BITSIZE (mode);
672 if (modesize >= 8 && modesize <= 256
673 && (modesize & (modesize - 1)) == 0)
675 if (align < modesize)
678 str = TREE_STRING_POINTER (decl);
679 len = TREE_STRING_LENGTH (decl);
680 unit = GET_MODE_SIZE (mode);
682 /* Check for embedded NUL characters. */
683 for (i = 0; i < len; i += unit)
685 for (j = 0; j < unit; j++)
686 if (str[i + j] != '\0')
693 sprintf (name, ".rodata.str%d.%d", modesize / 8,
695 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
696 if (!i && modesize < align)
698 /* A "" string with requested alignment greater than
699 character size might cause a problem:
700 if some other string required even bigger
701 alignment than "", then linker might think the
702 "" is just part of padding after some other string
703 and not put it into the hash table initially.
704 But this means "" could have smaller alignment
706 #ifdef ASM_OUTPUT_SECTION_START
707 named_section_flags (name, flags);
708 ASM_OUTPUT_SECTION_START (asm_out_file);
710 readonly_data_section ();
715 named_section_flags (name, flags);
721 readonly_data_section ();
724 /* Tell assembler to switch to the section for constant merging. */
727 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
728 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
729 unsigned int flags ATTRIBUTE_UNUSED)
731 unsigned int modesize = GET_MODE_BITSIZE (mode);
733 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
739 && (align & (align - 1)) == 0)
743 sprintf (name, ".rodata.cst%d", (int) (align / 8));
744 flags |= (align / 8) | SECTION_MERGE;
745 named_section_flags (name, flags);
749 readonly_data_section ();
752 /* Given NAME, a putative register name, discard any customary prefixes. */
755 strip_reg_name (const char *name)
757 #ifdef REGISTER_PREFIX
758 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
759 name += strlen (REGISTER_PREFIX);
761 if (name[0] == '%' || name[0] == '#')
766 /* The user has asked for a DECL to have a particular name. Set (or
767 change) it in such a way that we don't prefix an underscore to
770 set_user_assembler_name (tree decl, const char *name)
772 char *starred = alloca (strlen (name) + 2);
774 strcpy (starred + 1, name);
775 change_decl_assembler_name (decl, get_identifier (starred));
776 SET_DECL_RTL (decl, NULL_RTX);
779 /* Decode an `asm' spec for a declaration as a register name.
780 Return the register number, or -1 if nothing specified,
781 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
782 or -3 if ASMSPEC is `cc' and is not recognized,
783 or -4 if ASMSPEC is `memory' and is not recognized.
784 Accept an exact spelling or a decimal number.
785 Prefixes such as % are optional. */
788 decode_reg_name (const char *asmspec)
794 /* Get rid of confusing prefixes. */
795 asmspec = strip_reg_name (asmspec);
797 /* Allow a decimal number as a "register name". */
798 for (i = strlen (asmspec) - 1; i >= 0; i--)
799 if (! ISDIGIT (asmspec[i]))
801 if (asmspec[0] != 0 && i < 0)
804 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
810 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
812 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
815 #ifdef ADDITIONAL_REGISTER_NAMES
817 static const struct { const char *const name; const int number; } table[]
818 = ADDITIONAL_REGISTER_NAMES;
820 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
821 if (! strcmp (asmspec, table[i].name))
822 return table[i].number;
824 #endif /* ADDITIONAL_REGISTER_NAMES */
826 if (!strcmp (asmspec, "memory"))
829 if (!strcmp (asmspec, "cc"))
838 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
839 have static storage duration. In other words, it should not be an
840 automatic variable, including PARM_DECLs.
842 There is, however, one exception: this function handles variables
843 explicitly placed in a particular register by the user.
845 This is never called for PARM_DECL nodes. */
848 make_decl_rtl (tree decl)
850 const char *name = 0;
854 /* Check that we are not being given an automatic variable. */
855 gcc_assert (TREE_CODE (decl) != PARM_DECL
856 && TREE_CODE (decl) != RESULT_DECL);
858 /* A weak alias has TREE_PUBLIC set but not the other bits. */
859 gcc_assert (TREE_CODE (decl) != VAR_DECL
860 || TREE_STATIC (decl)
861 || TREE_PUBLIC (decl)
862 || DECL_EXTERNAL (decl)
863 || DECL_REGISTER (decl));
865 /* And that we were not given a type or a label. */
866 gcc_assert (TREE_CODE (decl) != TYPE_DECL
867 && TREE_CODE (decl) != LABEL_DECL);
869 /* For a duplicate declaration, we can be called twice on the
870 same DECL node. Don't discard the RTL already made. */
871 if (DECL_RTL_SET_P (decl))
873 /* If the old RTL had the wrong mode, fix the mode. */
874 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
875 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
876 DECL_MODE (decl), 0));
878 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
881 /* ??? Another way to do this would be to maintain a hashed
882 table of such critters. Instead of adding stuff to a DECL
883 to give certain attributes to it, we could use an external
884 hash map from DECL to set of attributes. */
886 /* Let the target reassign the RTL if it wants.
887 This is necessary, for example, when one machine specific
888 decl attribute overrides another. */
889 targetm.encode_section_info (decl, DECL_RTL (decl), false);
891 /* Make this function static known to the mudflap runtime. */
892 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
893 mudflap_enqueue_decl (decl);
898 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
900 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
902 reg_number = decode_reg_name (name);
903 /* First detect errors in declaring global registers. */
904 if (reg_number == -1)
905 error ("%Jregister name not specified for %qD", decl, decl);
906 else if (reg_number < 0)
907 error ("%Jinvalid register name for %qD", decl, decl);
908 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
909 error ("%Jdata type of %qD isn%'t suitable for a register",
911 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
912 error ("%Jregister specified for %qD isn%'t suitable for data type",
914 /* Now handle properly declared static register variables. */
919 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
921 DECL_INITIAL (decl) = 0;
922 error ("global register variable has initial value");
924 if (TREE_THIS_VOLATILE (decl))
925 warning ("volatile register variables don%'t "
926 "work as you might wish");
928 /* If the user specified one of the eliminables registers here,
929 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
930 confused with that register and be eliminated. This usage is
931 somewhat suspect... */
933 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
934 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
935 REG_USERVAR_P (DECL_RTL (decl)) = 1;
937 if (TREE_STATIC (decl))
939 /* Make this register global, so not usable for anything
941 #ifdef ASM_DECLARE_REGISTER_GLOBAL
942 name = IDENTIFIER_POINTER (DECL_NAME (decl));
943 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
945 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
947 globalize_reg (reg_number + --nregs);
950 /* As a register variable, it has no section. */
954 /* Now handle ordinary static variables and functions (in memory).
955 Also handle vars declared register invalidly. */
956 else if (name[0] == '*')
958 #ifdef REGISTER_PREFIX
959 if (strlen (REGISTER_PREFIX) != 0)
961 reg_number = decode_reg_name (name);
962 if (reg_number >= 0 || reg_number == -3)
963 error ("%Jregister name given for non-register variable %qD", decl, decl);
968 /* Specifying a section attribute on a variable forces it into a
969 non-.bss section, and thus it cannot be common. */
970 if (TREE_CODE (decl) == VAR_DECL
971 && DECL_SECTION_NAME (decl) != NULL_TREE
972 && DECL_INITIAL (decl) == NULL_TREE
973 && DECL_COMMON (decl))
974 DECL_COMMON (decl) = 0;
976 /* Variables can't be both common and weak. */
977 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
978 DECL_COMMON (decl) = 0;
980 x = gen_rtx_SYMBOL_REF (Pmode, name);
981 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
982 SYMBOL_REF_DECL (x) = decl;
984 x = gen_rtx_MEM (DECL_MODE (decl), x);
985 if (TREE_CODE (decl) != FUNCTION_DECL)
986 set_mem_attributes (x, decl, 1);
987 SET_DECL_RTL (decl, x);
989 /* Optionally set flags or add text to the name to record information
990 such as that it is a function name.
991 If the name is changed, the macro ASM_OUTPUT_LABELREF
992 will have to know how to strip this information. */
993 targetm.encode_section_info (decl, DECL_RTL (decl), true);
995 /* Make this function static known to the mudflap runtime. */
996 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
997 mudflap_enqueue_decl (decl);
1000 /* Make the rtl for variable VAR be volatile.
1001 Use this only for static variables. */
1004 make_var_volatile (tree var)
1006 gcc_assert (MEM_P (DECL_RTL (var)));
1008 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
1011 /* Output a string of literal assembler code
1012 for an `asm' keyword used between functions. */
1015 assemble_asm (tree string)
1019 if (TREE_CODE (string) == ADDR_EXPR)
1020 string = TREE_OPERAND (string, 0);
1022 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1025 /* Record an element in the table of global destructors. SYMBOL is
1026 a SYMBOL_REF of the function to be called; PRIORITY is a number
1027 between 0 and MAX_INIT_PRIORITY. */
1030 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1031 int priority ATTRIBUTE_UNUSED)
1033 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1034 /* Tell GNU LD that this is part of the static destructor set.
1035 This will work for any system that uses stabs, most usefully
1037 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1038 dbxout_stab_value_label (XSTR (symbol, 0));
1040 sorry ("global destructors not supported on this target");
1045 default_named_section_asm_out_destructor (rtx symbol, int priority)
1047 const char *section = ".dtors";
1050 /* ??? This only works reliably with the GNU linker. */
1051 if (priority != DEFAULT_INIT_PRIORITY)
1053 sprintf (buf, ".dtors.%.5u",
1054 /* Invert the numbering so the linker puts us in the proper
1055 order; constructors are run from right to left, and the
1056 linker sorts in increasing order. */
1057 MAX_INIT_PRIORITY - priority);
1061 named_section_flags (section, SECTION_WRITE);
1062 assemble_align (POINTER_SIZE);
1063 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1066 #ifdef DTORS_SECTION_ASM_OP
1068 dtors_section (void)
1070 if (in_section != in_dtors)
1072 in_section = in_dtors;
1073 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1074 fputc ('\n', asm_out_file);
1079 default_dtor_section_asm_out_destructor (rtx symbol,
1080 int priority ATTRIBUTE_UNUSED)
1083 assemble_align (POINTER_SIZE);
1084 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1088 /* Likewise for global constructors. */
1091 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1092 int priority ATTRIBUTE_UNUSED)
1094 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1095 /* Tell GNU LD that this is part of the static destructor set.
1096 This will work for any system that uses stabs, most usefully
1098 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1099 dbxout_stab_value_label (XSTR (symbol, 0));
1101 sorry ("global constructors not supported on this target");
1106 default_named_section_asm_out_constructor (rtx symbol, int priority)
1108 const char *section = ".ctors";
1111 /* ??? This only works reliably with the GNU linker. */
1112 if (priority != DEFAULT_INIT_PRIORITY)
1114 sprintf (buf, ".ctors.%.5u",
1115 /* Invert the numbering so the linker puts us in the proper
1116 order; constructors are run from right to left, and the
1117 linker sorts in increasing order. */
1118 MAX_INIT_PRIORITY - priority);
1122 named_section_flags (section, SECTION_WRITE);
1123 assemble_align (POINTER_SIZE);
1124 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1127 #ifdef CTORS_SECTION_ASM_OP
1129 ctors_section (void)
1131 if (in_section != in_ctors)
1133 in_section = in_ctors;
1134 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1135 fputc ('\n', asm_out_file);
1140 default_ctor_section_asm_out_constructor (rtx symbol,
1141 int priority ATTRIBUTE_UNUSED)
1144 assemble_align (POINTER_SIZE);
1145 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1149 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1150 a nonzero value if the constant pool should be output before the
1151 start of the function, or a zero value if the pool should output
1152 after the end of the function. The default is to put it before the
1155 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1156 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1159 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1160 to be output to assembler.
1161 Set first_global_object_name and weak_global_object_name as appropriate. */
1164 notice_global_symbol (tree decl)
1166 const char **type = &first_global_object_name;
1168 if (first_global_object_name
1169 || !TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
1170 || !DECL_NAME (decl)
1171 || (TREE_CODE (decl) != FUNCTION_DECL
1172 && (TREE_CODE (decl) != VAR_DECL
1173 || (DECL_COMMON (decl)
1174 && (DECL_INITIAL (decl) == 0
1175 || DECL_INITIAL (decl) == error_mark_node))))
1176 || !MEM_P (DECL_RTL (decl)))
1179 /* We win when global object is found, but it is useful to know about weak
1180 symbol as well so we can produce nicer unique names. */
1181 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl))
1182 type = &weak_global_object_name;
1188 rtx decl_rtl = DECL_RTL (decl);
1190 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1197 /* Output assembler code for the constant pool of a function and associated
1198 with defining the name of the function. DECL describes the function.
1199 NAME is the function's name. For the constant pool, we use the current
1200 constant pool data. */
1203 assemble_start_function (tree decl, const char *fnname)
1207 if (unlikely_text_section_name)
1208 free (unlikely_text_section_name);
1210 unlikely_section_label_printed = false;
1211 unlikely_text_section_name = NULL;
1213 unlikely_section_label = reconcat (unlikely_section_label,
1214 fnname, ".unlikely_section", NULL);
1216 /* The following code does not need preprocessing in the assembler. */
1220 if (CONSTANT_POOL_BEFORE_FUNCTION)
1221 output_constant_pool (fnname, decl);
1223 /* Make sure the cold text (code) section is properly aligned. This
1224 is necessary here in the case where the function has both hot and
1225 cold sections, because we don't want to re-set the alignment when the
1226 section switch happens mid-function. We don't need to set the hot
1227 section alignment here, because code further down in this function
1228 sets the alignment for whichever section comes first, and if there
1229 is a hot section it is guaranteed to be first. */
1231 if (flag_reorder_blocks_and_partition)
1233 unlikely_text_section ();
1234 assemble_align (FUNCTION_BOUNDARY);
1237 resolve_unique_section (decl, 0, flag_function_sections);
1238 function_section (decl);
1240 /* Tell assembler to move to target machine's alignment for functions. */
1241 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1242 if (align < force_align_functions_log)
1243 align = force_align_functions_log;
1246 ASM_OUTPUT_ALIGN (asm_out_file, align);
1249 /* Handle a user-specified function alignment.
1250 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1251 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1252 if (align_functions_log > align
1253 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1255 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1256 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1257 align_functions_log, align_functions - 1);
1259 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1263 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1264 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1267 (*debug_hooks->begin_function) (decl);
1269 /* Make function name accessible from other files, if appropriate. */
1271 if (TREE_PUBLIC (decl))
1273 notice_global_symbol (decl);
1275 globalize_decl (decl);
1277 maybe_assemble_visibility (decl);
1280 if (DECL_PRESERVE_P (decl))
1281 targetm.asm_out.mark_decl_preserved (fnname);
1283 /* Do any machine/system dependent processing of the function name. */
1284 #ifdef ASM_DECLARE_FUNCTION_NAME
1285 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1287 /* Standard thing is just output label for the function. */
1288 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1289 #endif /* ASM_DECLARE_FUNCTION_NAME */
1291 if (in_unlikely_text_section ()
1292 && !unlikely_section_label_printed)
1294 ASM_OUTPUT_LABEL (asm_out_file, unlikely_section_label);
1295 unlikely_section_label_printed = true;
1299 /* Output assembler code associated with defining the size of the
1300 function. DECL describes the function. NAME is the function's name. */
1303 assemble_end_function (tree decl, const char *fnname)
1305 #ifdef ASM_DECLARE_FUNCTION_SIZE
1306 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1308 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1310 output_constant_pool (fnname, decl);
1311 function_section (decl); /* need to switch back */
1315 /* Assemble code to leave SIZE bytes of zeros. */
1318 assemble_zeros (unsigned HOST_WIDE_INT size)
1320 /* Do no output if -fsyntax-only. */
1321 if (flag_syntax_only)
1324 #ifdef ASM_NO_SKIP_IN_TEXT
1325 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1326 so we must output 0s explicitly in the text section. */
1327 if ((ASM_NO_SKIP_IN_TEXT && in_text_section ())
1328 || (ASM_NO_SKIP_IN_TEXT && in_unlikely_text_section ()))
1330 unsigned HOST_WIDE_INT i;
1331 for (i = 0; i < size; i++)
1332 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1337 ASM_OUTPUT_SKIP (asm_out_file, size);
1340 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1343 assemble_align (int align)
1345 if (align > BITS_PER_UNIT)
1347 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1351 /* Assemble a string constant with the specified C string as contents. */
1354 assemble_string (const char *p, int size)
1359 /* If the string is very long, split it up. */
1363 int thissize = size - pos;
1364 if (thissize > maximum)
1367 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1375 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1376 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1377 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1379 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1380 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1381 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1383 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1384 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1388 #if defined ASM_OUTPUT_ALIGNED_BSS
1389 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1390 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1392 #if defined ASM_OUTPUT_BSS
1393 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1394 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1400 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1401 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1402 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1404 #if defined ASM_OUTPUT_ALIGNED_COMMON
1405 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1406 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1408 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1409 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1414 asm_emit_uninitialised (tree decl, const char *name,
1415 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1416 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1424 destination = asm_dest_local;
1426 /* ??? We should handle .bss via select_section mechanisms rather than
1427 via special target hooks. That would eliminate this special case. */
1428 if (TREE_PUBLIC (decl))
1430 if (!DECL_COMMON (decl))
1432 destination = asm_dest_bss;
1437 destination = asm_dest_common;
1440 if (destination != asm_dest_common)
1442 resolve_unique_section (decl, 0, flag_data_sections);
1443 /* Custom sections don't belong here. */
1444 if (DECL_SECTION_NAME (decl))
1448 if (destination == asm_dest_bss)
1449 globalize_decl (decl);
1451 if (flag_shared_data)
1453 switch (destination)
1455 #ifdef ASM_OUTPUT_SHARED_BSS
1457 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1460 #ifdef ASM_OUTPUT_SHARED_COMMON
1461 case asm_dest_common:
1462 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1465 #ifdef ASM_OUTPUT_SHARED_LOCAL
1466 case asm_dest_local:
1467 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1475 switch (destination)
1479 ASM_EMIT_BSS (decl, name, size, rounded);
1482 case asm_dest_common:
1483 ASM_EMIT_COMMON (decl, name, size, rounded);
1485 case asm_dest_local:
1486 ASM_EMIT_LOCAL (decl, name, size, rounded);
1495 /* Assemble everything that is needed for a variable or function declaration.
1496 Not used for automatic variables, and not used for function definitions.
1497 Should not be called for variables of incomplete structure type.
1499 TOP_LEVEL is nonzero if this variable has file scope.
1500 AT_END is nonzero if this is the special handling, at end of compilation,
1501 to define things that have had only tentative definitions.
1502 DONT_OUTPUT_DATA if nonzero means don't actually output the
1503 initial value (that will be done by the caller). */
1506 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1507 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1514 if (lang_hooks.decls.prepare_assemble_variable)
1515 lang_hooks.decls.prepare_assemble_variable (decl);
1517 last_assemble_variable_decl = 0;
1519 /* Normally no need to say anything here for external references,
1520 since assemble_external is called by the language-specific code
1521 when a declaration is first seen. */
1523 if (DECL_EXTERNAL (decl))
1526 /* Output no assembler code for a function declaration.
1527 Only definitions of functions output anything. */
1529 if (TREE_CODE (decl) == FUNCTION_DECL)
1532 /* Do nothing for global register variables. */
1533 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1535 TREE_ASM_WRITTEN (decl) = 1;
1539 /* If type was incomplete when the variable was declared,
1540 see if it is complete now. */
1542 if (DECL_SIZE (decl) == 0)
1543 layout_decl (decl, 0);
1545 /* Still incomplete => don't allocate it; treat the tentative defn
1546 (which is what it must have been) as an `extern' reference. */
1548 if (!dont_output_data && DECL_SIZE (decl) == 0)
1550 error ("%Jstorage size of %qD isn%'t known", decl, decl);
1551 TREE_ASM_WRITTEN (decl) = 1;
1555 /* The first declaration of a variable that comes through this function
1556 decides whether it is global (in C, has external linkage)
1557 or local (in C, has internal linkage). So do nothing more
1558 if this function has already run. */
1560 if (TREE_ASM_WRITTEN (decl))
1563 /* Make sure targetm.encode_section_info is invoked before we set
1565 decl_rtl = DECL_RTL (decl);
1567 TREE_ASM_WRITTEN (decl) = 1;
1569 /* Do no output if -fsyntax-only. */
1570 if (flag_syntax_only)
1575 if (! dont_output_data
1576 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1578 error ("%Jsize of variable %qD is too large", decl, decl);
1582 name = XSTR (XEXP (decl_rtl, 0), 0);
1583 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1584 notice_global_symbol (decl);
1586 /* Compute the alignment of this data. */
1588 align = DECL_ALIGN (decl);
1590 /* In the case for initialing an array whose length isn't specified,
1591 where we have not yet been able to do the layout,
1592 figure out the proper alignment now. */
1593 if (dont_output_data && DECL_SIZE (decl) == 0
1594 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1595 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1597 /* Some object file formats have a maximum alignment which they support.
1598 In particular, a.out format supports a maximum alignment of 4. */
1599 if (align > MAX_OFILE_ALIGNMENT)
1601 warning ("%Jalignment of %qD is greater than maximum object "
1602 "file alignment. Using %d", decl, decl,
1603 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1604 align = MAX_OFILE_ALIGNMENT;
1607 /* On some machines, it is good to increase alignment sometimes. */
1608 if (! DECL_USER_ALIGN (decl))
1610 #ifdef DATA_ALIGNMENT
1611 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1613 #ifdef CONSTANT_ALIGNMENT
1614 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1615 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1619 /* Reset the alignment in case we have made it tighter, so we can benefit
1620 from it in get_pointer_alignment. */
1621 DECL_ALIGN (decl) = align;
1622 set_mem_align (decl_rtl, align);
1624 if (TREE_PUBLIC (decl))
1625 maybe_assemble_visibility (decl);
1627 if (DECL_PRESERVE_P (decl))
1628 targetm.asm_out.mark_decl_preserved (name);
1630 /* Handle uninitialized definitions. */
1632 /* If the decl has been given an explicit section name, then it
1633 isn't common, and shouldn't be handled as such. */
1634 if (DECL_SECTION_NAME (decl) || dont_output_data)
1636 /* We don't implement common thread-local data at present. */
1637 else if (DECL_THREAD_LOCAL (decl))
1639 if (DECL_COMMON (decl))
1640 sorry ("thread-local COMMON data not implemented");
1642 else if (DECL_INITIAL (decl) == 0
1643 || DECL_INITIAL (decl) == error_mark_node
1644 || (flag_zero_initialized_in_bss
1645 /* Leave constant zeroes in .rodata so they can be shared. */
1646 && !TREE_READONLY (decl)
1647 && initializer_zerop (DECL_INITIAL (decl))))
1649 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1650 unsigned HOST_WIDE_INT rounded = size;
1652 /* Don't allocate zero bytes of common,
1653 since that means "undefined external" in the linker. */
1657 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1658 so that each uninitialized object starts on such a boundary. */
1659 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1660 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1661 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1663 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1664 if ((unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1665 warning ("%Jrequested alignment for %qD is greater than "
1666 "implemented alignment of %d", decl, decl, rounded);
1669 /* If the target cannot output uninitialized but not common global data
1670 in .bss, then we have to use .data, so fall through. */
1671 if (asm_emit_uninitialised (decl, name, size, rounded))
1675 /* Handle initialized definitions.
1676 Also handle uninitialized global definitions if -fno-common and the
1677 target doesn't support ASM_OUTPUT_BSS. */
1679 /* First make the assembler name(s) global if appropriate. */
1680 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1681 globalize_decl (decl);
1683 /* Output any data that we will need to use the address of. */
1684 if (DECL_INITIAL (decl) == error_mark_node)
1685 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1686 else if (DECL_INITIAL (decl))
1688 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1689 output_addressed_constants (DECL_INITIAL (decl));
1692 /* Switch to the appropriate section. */
1693 resolve_unique_section (decl, reloc, flag_data_sections);
1694 variable_section (decl, reloc);
1696 /* dbxout.c needs to know this. */
1697 if (in_text_section () || in_unlikely_text_section ())
1698 DECL_IN_TEXT_SECTION (decl) = 1;
1700 /* Output the alignment of this data. */
1701 if (align > BITS_PER_UNIT)
1702 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
1704 /* Do any machine/system dependent processing of the object. */
1705 #ifdef ASM_DECLARE_OBJECT_NAME
1706 last_assemble_variable_decl = decl;
1707 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1709 /* Standard thing is just output label for the object. */
1710 ASM_OUTPUT_LABEL (asm_out_file, name);
1711 #endif /* ASM_DECLARE_OBJECT_NAME */
1713 if (!dont_output_data)
1715 if (DECL_INITIAL (decl)
1716 && DECL_INITIAL (decl) != error_mark_node
1717 && !initializer_zerop (DECL_INITIAL (decl)))
1718 /* Output the actual data. */
1719 output_constant (DECL_INITIAL (decl),
1720 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1723 /* Leave space for it. */
1724 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1728 /* Return 1 if type TYPE contains any pointers. */
1731 contains_pointers_p (tree type)
1733 switch (TREE_CODE (type))
1736 case REFERENCE_TYPE:
1737 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1738 so I'll play safe and return 1. */
1744 case QUAL_UNION_TYPE:
1747 /* For a type that has fields, see if the fields have pointers. */
1748 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1749 if (TREE_CODE (fields) == FIELD_DECL
1750 && contains_pointers_p (TREE_TYPE (fields)))
1756 /* An array type contains pointers if its element type does. */
1757 return contains_pointers_p (TREE_TYPE (type));
1764 /* In unit-at-a-time mode, we delay assemble_external processing until
1765 the compilation unit is finalized. This is the best we can do for
1766 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
1767 it all the way to final. See PR 17982 for further discussion. */
1768 static GTY(()) tree pending_assemble_externals;
1770 #ifdef ASM_OUTPUT_EXTERNAL
1771 /* True if DECL is a function decl for which no out-of-line copy exists.
1772 It is assumed that DECL's assembler name has been set. */
1775 incorporeal_function_p (tree decl)
1777 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1781 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
1782 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
1785 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1786 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
1792 /* Actually do the tests to determine if this is necessary, and invoke
1793 ASM_OUTPUT_EXTERNAL. */
1795 assemble_external_real (tree decl)
1797 rtx rtl = DECL_RTL (decl);
1799 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1800 && !SYMBOL_REF_USED (XEXP (rtl, 0))
1801 && !incorporeal_function_p (decl))
1803 /* Some systems do require some output. */
1804 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1805 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1811 process_pending_assemble_externals (void)
1813 #ifdef ASM_OUTPUT_EXTERNAL
1815 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
1816 assemble_external_real (TREE_VALUE (list));
1818 pending_assemble_externals = 0;
1822 /* Output something to declare an external symbol to the assembler.
1823 (Most assemblers don't need this, so we normally output nothing.)
1824 Do nothing if DECL is not external. */
1827 assemble_external (tree decl ATTRIBUTE_UNUSED)
1829 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1830 main body of this code is only rarely exercised. To provide some
1831 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1832 open. If it's not, we should not be calling this function. */
1833 gcc_assert (asm_out_file);
1835 #ifdef ASM_OUTPUT_EXTERNAL
1836 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
1839 if (flag_unit_at_a_time)
1840 pending_assemble_externals = tree_cons (0, decl,
1841 pending_assemble_externals);
1843 assemble_external_real (decl);
1847 /* Similar, for calling a library function FUN. */
1850 assemble_external_libcall (rtx fun)
1852 /* Declare library function name external when first used, if nec. */
1853 if (! SYMBOL_REF_USED (fun))
1855 SYMBOL_REF_USED (fun) = 1;
1856 targetm.asm_out.external_libcall (fun);
1860 /* Assemble a label named NAME. */
1863 assemble_label (const char *name)
1865 ASM_OUTPUT_LABEL (asm_out_file, name);
1868 /* Set the symbol_referenced flag for ID. */
1870 mark_referenced (tree id)
1872 TREE_SYMBOL_REFERENCED (id) = 1;
1875 /* Set the symbol_referenced flag for DECL and notify callgraph. */
1877 mark_decl_referenced (tree decl)
1879 if (TREE_CODE (decl) == FUNCTION_DECL)
1881 /* Extern inline functions don't become needed when referenced. */
1882 if (!DECL_EXTERNAL (decl))
1883 cgraph_mark_needed_node (cgraph_node (decl));
1885 else if (TREE_CODE (decl) == VAR_DECL)
1887 struct cgraph_varpool_node *node = cgraph_varpool_node (decl);
1888 cgraph_varpool_mark_needed_node (node);
1889 /* C++ frontend use mark_decl_references to force COMDAT variables
1890 to be output that might appear dead otherwise. */
1891 node->force_output = true;
1893 /* else do nothing - we can get various sorts of CST nodes here,
1894 which do not need to be marked. */
1897 /* Output to FILE (an assembly file) a reference to NAME. If NAME
1898 starts with a *, the rest of NAME is output verbatim. Otherwise
1899 NAME is transformed in a target-specific way (usually by the
1900 addition of an underscore). */
1903 assemble_name_raw (FILE *file, const char *name)
1906 fputs (&name[1], file);
1908 ASM_OUTPUT_LABELREF (file, name);
1911 /* Like assemble_name_raw, but should be used when NAME might refer to
1912 an entity that is also represented as a tree (like a function or
1913 variable). If NAME does refer to such an entity, that entity will
1914 be marked as referenced. */
1917 assemble_name (FILE *file, const char *name)
1919 const char *real_name;
1922 real_name = targetm.strip_name_encoding (name);
1924 id = maybe_get_identifier (real_name);
1926 mark_referenced (id);
1928 assemble_name_raw (file, name);
1931 /* Allocate SIZE bytes writable static space with a gensym name
1932 and return an RTX to refer to its address. */
1935 assemble_static_space (unsigned HOST_WIDE_INT size)
1938 const char *namestring;
1942 if (flag_shared_data)
1946 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1948 namestring = ggc_strdup (name);
1950 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1951 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
1953 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1954 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1957 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1958 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1961 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1962 so that each uninitialized object starts on such a boundary. */
1963 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1964 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1965 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1966 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1967 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1968 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1975 /* Assemble the static constant template for function entry trampolines.
1976 This is done at most once per compilation.
1977 Returns an RTX for the address of the template. */
1979 static GTY(()) rtx initial_trampoline;
1981 #ifdef TRAMPOLINE_TEMPLATE
1983 assemble_trampoline_template (void)
1990 if (initial_trampoline)
1991 return initial_trampoline;
1993 /* By default, put trampoline templates in read-only data section. */
1995 #ifdef TRAMPOLINE_SECTION
1996 TRAMPOLINE_SECTION ();
1998 readonly_data_section ();
2001 /* Write the assembler code to define one. */
2002 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2005 ASM_OUTPUT_ALIGN (asm_out_file, align);
2008 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2009 TRAMPOLINE_TEMPLATE (asm_out_file);
2011 /* Record the rtl to refer to it. */
2012 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2013 name = ggc_strdup (label);
2014 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2015 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2017 initial_trampoline = gen_rtx_MEM (BLKmode, symbol);
2018 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2020 return initial_trampoline;
2024 /* A and B are either alignments or offsets. Return the minimum alignment
2025 that may be assumed after adding the two together. */
2027 static inline unsigned
2028 min_align (unsigned int a, unsigned int b)
2030 return (a | b) & -(a | b);
2033 /* Return the assembler directive for creating a given kind of integer
2034 object. SIZE is the number of bytes in the object and ALIGNED_P
2035 indicates whether it is known to be aligned. Return NULL if the
2036 assembly dialect has no such directive.
2038 The returned string should be printed at the start of a new line and
2039 be followed immediately by the object's initial value. */
2042 integer_asm_op (int size, int aligned_p)
2044 struct asm_int_op *ops;
2047 ops = &targetm.asm_out.aligned_op;
2049 ops = &targetm.asm_out.unaligned_op;
2054 return targetm.asm_out.byte_op;
2068 /* Use directive OP to assemble an integer object X. Print OP at the
2069 start of the line, followed immediately by the value of X. */
2072 assemble_integer_with_op (const char *op, rtx x)
2074 fputs (op, asm_out_file);
2075 output_addr_const (asm_out_file, x);
2076 fputc ('\n', asm_out_file);
2079 /* The default implementation of the asm_out.integer target hook. */
2082 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2083 unsigned int size ATTRIBUTE_UNUSED,
2084 int aligned_p ATTRIBUTE_UNUSED)
2086 const char *op = integer_asm_op (size, aligned_p);
2087 /* Avoid GAS bugs for large values. Specifically negative values whose
2088 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2089 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2091 return op && (assemble_integer_with_op (op, x), true);
2094 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2095 the alignment of the integer in bits. Return 1 if we were able to output
2096 the constant, otherwise 0. If FORCE is nonzero, abort if we can't output
2100 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2104 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2106 /* See if the target hook can handle this kind of object. */
2107 if (targetm.asm_out.integer (x, size, aligned_p))
2110 /* If the object is a multi-byte one, try splitting it up. Split
2111 it into words it if is multi-word, otherwise split it into bytes. */
2114 enum machine_mode omode, imode;
2115 unsigned int subalign;
2116 unsigned int subsize, i;
2118 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2119 subalign = MIN (align, subsize * BITS_PER_UNIT);
2120 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
2121 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2123 for (i = 0; i < size; i += subsize)
2125 rtx partial = simplify_subreg (omode, x, imode, i);
2126 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2132 /* If we've printed some of it, but not all of it, there's no going
2137 gcc_assert (!force);
2143 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2147 int bitsize, nelts, nunits, units_per;
2149 /* This is hairy. We have a quantity of known size. real_to_target
2150 will put it into an array of *host* longs, 32 bits per element
2151 (even if long is more than 32 bits). We need to determine the
2152 number of array elements that are occupied (nelts) and the number
2153 of *target* min-addressable units that will be occupied in the
2154 object file (nunits). We cannot assume that 32 divides the
2155 mode's bitsize (size * BITS_PER_UNIT) evenly.
2157 size * BITS_PER_UNIT is used here to make sure that padding bits
2158 (which might appear at either end of the value; real_to_target
2159 will include the padding bits in its output array) are included. */
2161 nunits = GET_MODE_SIZE (mode);
2162 bitsize = nunits * BITS_PER_UNIT;
2163 nelts = CEIL (bitsize, 32);
2164 units_per = 32 / BITS_PER_UNIT;
2166 real_to_target (data, &d, mode);
2168 /* Put out the first word with the specified alignment. */
2169 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2170 nunits -= units_per;
2172 /* Subsequent words need only 32-bit alignment. */
2173 align = min_align (align, 32);
2175 for (i = 1; i < nelts; i++)
2177 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2178 nunits -= units_per;
2182 /* Given an expression EXP with a constant value,
2183 reduce it to the sum of an assembler symbol and an integer.
2184 Store them both in the structure *VALUE.
2185 Abort if EXP does not reduce. */
2187 struct addr_const GTY(())
2190 HOST_WIDE_INT offset;
2194 decode_addr_const (tree exp, struct addr_const *value)
2196 tree target = TREE_OPERAND (exp, 0);
2202 if (TREE_CODE (target) == COMPONENT_REF
2203 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2206 offset += int_byte_position (TREE_OPERAND (target, 1));
2207 target = TREE_OPERAND (target, 0);
2209 else if (TREE_CODE (target) == ARRAY_REF
2210 || TREE_CODE (target) == ARRAY_RANGE_REF)
2212 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2213 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2214 target = TREE_OPERAND (target, 0);
2220 switch (TREE_CODE (target))
2224 x = DECL_RTL (target);
2228 x = gen_rtx_MEM (FUNCTION_MODE,
2229 gen_rtx_LABEL_REF (VOIDmode, force_label_rtx (target)));
2237 x = output_constant_def (target, 1);
2244 gcc_assert (MEM_P (x));
2248 value->offset = offset;
2251 /* Uniquize all constants that appear in memory.
2252 Each constant in memory thus far output is recorded
2253 in `const_desc_table'. */
2255 struct constant_descriptor_tree GTY(())
2257 /* A MEM for the constant. */
2260 /* The value of the constant. */
2264 static GTY((param_is (struct constant_descriptor_tree)))
2265 htab_t const_desc_htab;
2267 static struct constant_descriptor_tree * build_constant_desc (tree);
2268 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2270 /* Compute a hash code for a constant expression. */
2273 const_desc_hash (const void *ptr)
2275 return const_hash_1 (((struct constant_descriptor_tree *)ptr)->value);
2279 const_hash_1 (const tree exp)
2284 enum tree_code code = TREE_CODE (exp);
2286 /* Either set P and LEN to the address and len of something to hash and
2287 exit the switch or return a value. */
2292 p = (char *) &TREE_INT_CST (exp);
2293 len = sizeof TREE_INT_CST (exp);
2297 return real_hash (TREE_REAL_CST_PTR (exp));
2300 p = TREE_STRING_POINTER (exp);
2301 len = TREE_STRING_LENGTH (exp);
2305 return (const_hash_1 (TREE_REALPART (exp)) * 5
2306 + const_hash_1 (TREE_IMAGPART (exp)));
2312 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2314 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2315 if (TREE_VALUE (link))
2316 hi = hi * 603 + const_hash_1 (TREE_VALUE (link));
2324 struct addr_const value;
2326 decode_addr_const (exp, &value);
2327 switch (GET_CODE (value.base))
2330 /* Don't hash the address of the SYMBOL_REF;
2331 only use the offset and the symbol name. */
2333 p = XSTR (value.base, 0);
2334 for (i = 0; p[i] != 0; i++)
2335 hi = ((hi * 613) + (unsigned) (p[i]));
2339 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2350 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2351 + const_hash_1 (TREE_OPERAND (exp, 1)));
2355 case NON_LVALUE_EXPR:
2356 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2359 /* A language specific constant. Just hash the code. */
2363 /* Compute hashing function. */
2365 for (i = 0; i < len; i++)
2366 hi = ((hi * 613) + (unsigned) (p[i]));
2371 /* Wrapper of compare_constant, for the htab interface. */
2373 const_desc_eq (const void *p1, const void *p2)
2375 return compare_constant (((struct constant_descriptor_tree *)p1)->value,
2376 ((struct constant_descriptor_tree *)p2)->value);
2379 /* Compare t1 and t2, and return 1 only if they are known to result in
2380 the same bit pattern on output. */
2383 compare_constant (const tree t1, const tree t2)
2385 enum tree_code typecode;
2387 if (t1 == NULL_TREE)
2388 return t2 == NULL_TREE;
2389 if (t2 == NULL_TREE)
2392 if (TREE_CODE (t1) != TREE_CODE (t2))
2395 switch (TREE_CODE (t1))
2398 /* Integer constants are the same only if the same width of type. */
2399 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2401 return tree_int_cst_equal (t1, t2);
2404 /* Real constants are the same only if the same width of type. */
2405 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2408 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2411 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2414 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2415 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2416 TREE_STRING_LENGTH (t1)));
2419 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2420 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2426 typecode = TREE_CODE (TREE_TYPE (t1));
2427 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2430 if (typecode == ARRAY_TYPE)
2432 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2433 /* For arrays, check that the sizes all match. */
2434 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2436 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2441 /* For record and union constructors, require exact type
2443 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2447 for (l1 = CONSTRUCTOR_ELTS (t1), l2 = CONSTRUCTOR_ELTS (t2);
2449 l1 = TREE_CHAIN (l1), l2 = TREE_CHAIN (l2))
2451 /* Check that each value is the same... */
2452 if (! compare_constant (TREE_VALUE (l1), TREE_VALUE (l2)))
2454 /* ... and that they apply to the same fields! */
2455 if (typecode == ARRAY_TYPE)
2457 if (! compare_constant (TREE_PURPOSE (l1),
2463 if (TREE_PURPOSE (l1) != TREE_PURPOSE (l2))
2468 return l1 == NULL_TREE && l2 == NULL_TREE;
2474 struct addr_const value1, value2;
2476 decode_addr_const (t1, &value1);
2477 decode_addr_const (t2, &value2);
2478 return (value1.offset == value2.offset
2479 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2485 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2486 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2490 case NON_LVALUE_EXPR:
2491 case VIEW_CONVERT_EXPR:
2492 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2497 nt1 = lang_hooks.expand_constant (t1);
2498 nt2 = lang_hooks.expand_constant (t2);
2499 if (nt1 != t1 || nt2 != t2)
2500 return compare_constant (nt1, nt2);
2509 /* Make a copy of the whole tree structure for a constant. This
2510 handles the same types of nodes that compare_constant handles. */
2513 copy_constant (tree exp)
2515 switch (TREE_CODE (exp))
2518 /* For ADDR_EXPR, we do not want to copy the decl whose address
2519 is requested. We do want to copy constants though. */
2520 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
2521 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2522 copy_constant (TREE_OPERAND (exp, 0)));
2524 return copy_node (exp);
2529 return copy_node (exp);
2532 return build_complex (TREE_TYPE (exp),
2533 copy_constant (TREE_REALPART (exp)),
2534 copy_constant (TREE_IMAGPART (exp)));
2538 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
2539 copy_constant (TREE_OPERAND (exp, 0)),
2540 copy_constant (TREE_OPERAND (exp, 1)));
2544 case NON_LVALUE_EXPR:
2545 case VIEW_CONVERT_EXPR:
2546 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2547 copy_constant (TREE_OPERAND (exp, 0)));
2551 tree copy = copy_node (exp);
2552 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2555 CONSTRUCTOR_ELTS (copy) = list;
2556 for (tail = list; tail; tail = TREE_CHAIN (tail))
2557 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2564 tree t = lang_hooks.expand_constant (exp);
2566 gcc_assert (t == exp);
2567 return copy_constant (t);
2572 /* Subroutine of output_constant_def:
2573 No constant equal to EXP is known to have been output.
2574 Make a constant descriptor to enter EXP in the hash table.
2575 Assign the label number and construct RTL to refer to the
2576 constant's location in memory.
2577 Caller is responsible for updating the hash table. */
2579 static struct constant_descriptor_tree *
2580 build_constant_desc (tree exp)
2586 struct constant_descriptor_tree *desc;
2588 desc = ggc_alloc (sizeof (*desc));
2589 desc->value = copy_constant (exp);
2591 /* Propagate marked-ness to copied constant. */
2592 if (flag_mudflap && mf_marked_p (exp))
2593 mf_mark (desc->value);
2595 /* Create a string containing the label name, in LABEL. */
2596 labelno = const_labelno++;
2597 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2599 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2600 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2601 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2602 SYMBOL_REF_DECL (symbol) = desc->value;
2603 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2605 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2606 set_mem_attributes (rtl, exp, 1);
2607 set_mem_alias_set (rtl, 0);
2608 set_mem_alias_set (rtl, const_alias_set);
2610 /* Set flags or add text to the name to record information, such as
2611 that it is a local symbol. If the name is changed, the macro
2612 ASM_OUTPUT_LABELREF will have to know how to strip this
2613 information. This call might invalidate our local variable
2614 SYMBOL; we can't use it afterward. */
2616 targetm.encode_section_info (exp, rtl, true);
2623 /* Return an rtx representing a reference to constant data in memory
2624 for the constant expression EXP.
2626 If assembler code for such a constant has already been output,
2627 return an rtx to refer to it.
2628 Otherwise, output such a constant in memory
2629 and generate an rtx for it.
2631 If DEFER is nonzero, this constant can be deferred and output only
2632 if referenced in the function after all optimizations.
2634 `const_desc_table' records which constants already have label strings. */
2637 output_constant_def (tree exp, int defer)
2639 struct constant_descriptor_tree *desc;
2640 struct constant_descriptor_tree key;
2643 /* Look up EXP in the table of constant descriptors. If we didn't find
2644 it, create a new one. */
2646 loc = htab_find_slot (const_desc_htab, &key, INSERT);
2651 desc = build_constant_desc (exp);
2655 maybe_output_constant_def_contents (desc, defer);
2659 /* Subroutine of output_constant_def: Decide whether or not we need to
2660 output the constant DESC now, and if so, do it. */
2662 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
2665 rtx symbol = XEXP (desc->rtl, 0);
2666 tree exp = desc->value;
2668 if (flag_syntax_only)
2671 if (TREE_ASM_WRITTEN (exp))
2672 /* Already output; don't do it again. */
2675 /* We can always defer constants as long as the context allows
2679 /* Increment n_deferred_constants if it exists. It needs to be at
2680 least as large as the number of constants actually referred to
2681 by the function. If it's too small we'll stop looking too early
2682 and fail to emit constants; if it's too large we'll only look
2683 through the entire function when we could have stopped earlier. */
2685 n_deferred_constants++;
2689 output_constant_def_contents (symbol);
2692 /* We must output the constant data referred to by SYMBOL; do so. */
2695 output_constant_def_contents (rtx symbol)
2697 tree exp = SYMBOL_REF_DECL (symbol);
2698 const char *label = XSTR (symbol, 0);
2701 /* Make sure any other constants whose addresses appear in EXP
2702 are assigned label numbers. */
2703 int reloc = compute_reloc_for_constant (exp);
2705 /* Align the location counter as required by EXP's data type. */
2706 unsigned int align = TYPE_ALIGN (TREE_TYPE (exp));
2707 #ifdef CONSTANT_ALIGNMENT
2708 align = CONSTANT_ALIGNMENT (exp, align);
2711 output_addressed_constants (exp);
2713 /* We are no longer deferring this constant. */
2714 TREE_ASM_WRITTEN (exp) = 1;
2716 if (IN_NAMED_SECTION (exp))
2717 named_section (exp, NULL, reloc);
2719 targetm.asm_out.select_section (exp, reloc, align);
2721 if (align > BITS_PER_UNIT)
2723 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2726 size = int_size_in_bytes (TREE_TYPE (exp));
2727 if (TREE_CODE (exp) == STRING_CST)
2728 size = MAX (TREE_STRING_LENGTH (exp), size);
2730 /* Do any machine/system dependent processing of the constant. */
2731 #ifdef ASM_DECLARE_CONSTANT_NAME
2732 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
2734 /* Standard thing is just output label for the constant. */
2735 ASM_OUTPUT_LABEL (asm_out_file, label);
2736 #endif /* ASM_DECLARE_CONSTANT_NAME */
2738 /* Output the value of EXP. */
2739 output_constant (exp, size, align);
2741 mudflap_enqueue_constant (exp);
2744 /* Look up EXP in the table of constant descriptors. Return the rtl
2745 if it has been emitted, else null. */
2748 lookup_constant_def (tree exp)
2750 struct constant_descriptor_tree *desc;
2751 struct constant_descriptor_tree key;
2754 desc = htab_find (const_desc_htab, &key);
2756 return (desc ? desc->rtl : NULL_RTX);
2759 /* Used in the hash tables to avoid outputting the same constant
2760 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2761 are output once per function, not once per file. */
2762 /* ??? Only a few targets need per-function constant pools. Most
2763 can use one per-file pool. Should add a targetm bit to tell the
2766 struct rtx_constant_pool GTY(())
2768 /* Pointers to first and last constant in pool, as ordered by offset. */
2769 struct constant_descriptor_rtx *first;
2770 struct constant_descriptor_rtx *last;
2772 /* Hash facility for making memory-constants from constant rtl-expressions.
2773 It is used on RISC machines where immediate integer arguments and
2774 constant addresses are restricted so that such constants must be stored
2776 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
2777 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_sym_htab;
2779 /* Current offset in constant pool (does not include any
2780 machine-specific header). */
2781 HOST_WIDE_INT offset;
2784 struct constant_descriptor_rtx GTY((chain_next ("%h.next")))
2786 struct constant_descriptor_rtx *next;
2790 HOST_WIDE_INT offset;
2792 enum machine_mode mode;
2798 /* Hash and compare functions for const_rtx_htab. */
2801 const_desc_rtx_hash (const void *ptr)
2803 const struct constant_descriptor_rtx *desc = ptr;
2808 const_desc_rtx_eq (const void *a, const void *b)
2810 const struct constant_descriptor_rtx *x = a;
2811 const struct constant_descriptor_rtx *y = b;
2813 if (x->mode != y->mode)
2815 return rtx_equal_p (x->constant, y->constant);
2818 /* Hash and compare functions for const_rtx_sym_htab. */
2821 const_desc_rtx_sym_hash (const void *ptr)
2823 const struct constant_descriptor_rtx *desc = ptr;
2824 return htab_hash_string (XSTR (desc->sym, 0));
2828 const_desc_rtx_sym_eq (const void *a, const void *b)
2830 const struct constant_descriptor_rtx *x = a;
2831 const struct constant_descriptor_rtx *y = b;
2832 return XSTR (x->sym, 0) == XSTR (y->sym, 0);
2835 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
2838 const_rtx_hash_1 (rtx *xp, void *data)
2840 unsigned HOST_WIDE_INT hwi;
2841 enum machine_mode mode;
2847 code = GET_CODE (x);
2848 mode = GET_MODE (x);
2849 h = (hashval_t) code * 1048573 + mode;
2857 const int shift = sizeof (hashval_t) * CHAR_BIT;
2858 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
2861 h ^= (hashval_t) hwi;
2862 for (i = 1; i < n; ++i)
2865 h ^= (hashval_t) hwi;
2871 if (mode == VOIDmode)
2873 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
2877 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
2883 for (i = XVECLEN (x, 0); i-- > 0; )
2884 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
2889 h ^= htab_hash_string (XSTR (x, 0));
2893 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
2897 case UNSPEC_VOLATILE:
2898 h = h * 251 + XINT (x, 1);
2906 *hp = *hp * 509 + h;
2910 /* Compute a hash value for X, which should be a constant. */
2913 const_rtx_hash (rtx x)
2916 for_each_rtx (&x, const_rtx_hash_1, &h);
2921 /* Initialize constant pool hashing for a new function. */
2924 init_varasm_status (struct function *f)
2926 struct varasm_status *p;
2927 struct rtx_constant_pool *pool;
2929 p = ggc_alloc (sizeof (struct varasm_status));
2932 pool = ggc_alloc (sizeof (struct rtx_constant_pool));
2934 p->deferred_constants = 0;
2936 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
2937 const_desc_rtx_eq, NULL);
2938 pool->const_rtx_sym_htab = htab_create_ggc (31, const_desc_rtx_sym_hash,
2939 const_desc_rtx_sym_eq, NULL);
2940 pool->first = pool->last = NULL;
2944 /* Given a MINUS expression, simplify it if both sides
2945 include the same symbol. */
2948 simplify_subtraction (rtx x)
2950 rtx r = simplify_rtx (x);
2954 /* Given a constant rtx X, make (or find) a memory constant for its value
2955 and return a MEM rtx to refer to it in memory. */
2958 force_const_mem (enum machine_mode mode, rtx x)
2960 struct constant_descriptor_rtx *desc, tmp;
2961 struct rtx_constant_pool *pool = cfun->varasm->pool;
2968 /* If we're not allowed to drop X into the constant pool, don't. */
2969 if (targetm.cannot_force_const_mem (x))
2972 /* Lookup the value in the hashtable. */
2975 hash = const_rtx_hash (x);
2976 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
2979 /* If the constant was already present, return its memory. */
2981 return copy_rtx (desc->mem);
2983 /* Otherwise, create a new descriptor. */
2984 desc = ggc_alloc (sizeof (*desc));
2987 /* Align the location counter as required by EXP's data type. */
2988 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
2989 #ifdef CONSTANT_ALIGNMENT
2991 tree type = lang_hooks.types.type_for_mode (mode, 0);
2992 if (type != NULL_TREE)
2993 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
2997 pool->offset += (align / BITS_PER_UNIT) - 1;
2998 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3001 desc->constant = tmp.constant;
3002 desc->offset = pool->offset;
3005 desc->align = align;
3006 desc->labelno = const_labelno;
3009 pool->offset += GET_MODE_SIZE (mode);
3011 pool->last->next = desc;
3013 pool->first = pool->last = desc;
3016 /* Create a string containing the label name, in LABEL. */
3017 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3020 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3021 the constants pool. */
3022 desc->sym = symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3023 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
3024 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3025 current_function_uses_const_pool = 1;
3027 /* Insert the descriptor into the symbol cross-reference table too. */
3028 slot = htab_find_slot (pool->const_rtx_sym_htab, desc, INSERT);
3029 gcc_assert (!*slot);
3032 /* Construct the MEM. */
3033 desc->mem = def = gen_const_mem (mode, symbol);
3034 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3035 set_mem_align (def, align);
3037 /* If we're dropping a label to the constant pool, make sure we
3039 if (GET_CODE (x) == LABEL_REF)
3040 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3042 return copy_rtx (def);
3045 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3046 the corresponding constant_descriptor_rtx structure. */
3048 static struct constant_descriptor_rtx *
3049 find_pool_constant (struct rtx_constant_pool *pool, rtx sym)
3051 struct constant_descriptor_rtx tmp;
3053 return htab_find (pool->const_rtx_sym_htab, &tmp);
3056 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3059 get_pool_constant (rtx addr)
3061 return find_pool_constant (cfun->varasm->pool, addr)->constant;
3064 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3065 and whether it has been output or not. */
3068 get_pool_constant_mark (rtx addr, bool *pmarked)
3070 struct constant_descriptor_rtx *desc;
3072 desc = find_pool_constant (cfun->varasm->pool, addr);
3073 *pmarked = (desc->mark != 0);
3074 return desc->constant;
3077 /* Likewise, but for the constant pool of a specific function. */
3080 get_pool_constant_for_function (struct function *f, rtx addr)
3082 return find_pool_constant (f->varasm->pool, addr)->constant;
3085 /* Similar, return the mode. */
3088 get_pool_mode (rtx addr)
3090 return find_pool_constant (cfun->varasm->pool, addr)->mode;
3093 /* Return the size of the constant pool. */
3096 get_pool_size (void)
3098 return cfun->varasm->pool->offset;
3101 /* Worker function for output_constant_pool_1. Emit assembly for X
3102 in MODE with known alignment ALIGN. */
3105 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3107 switch (GET_MODE_CLASS (mode))
3113 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3114 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3115 assemble_real (r, mode, align);
3120 case MODE_PARTIAL_INT:
3121 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3124 case MODE_VECTOR_FLOAT:
3125 case MODE_VECTOR_INT:
3128 enum machine_mode submode = GET_MODE_INNER (mode);
3129 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3131 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3132 units = CONST_VECTOR_NUNITS (x);
3134 for (i = 0; i < units; i++)
3136 rtx elt = CONST_VECTOR_ELT (x, i);
3137 output_constant_pool_2 (submode, elt, i ? subalign : align);
3147 /* Worker function for output_constant_pool. Emit POOL. */
3150 output_constant_pool_1 (struct constant_descriptor_rtx *desc)
3158 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3159 whose CODE_LABEL has been deleted. This can occur if a jump table
3160 is eliminated by optimization. If so, write a constant of zero
3161 instead. Note that this can also happen by turning the
3162 CODE_LABEL into a NOTE. */
3163 /* ??? This seems completely and utterly wrong. Certainly it's
3164 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3165 functioning even with INSN_DELETED_P and friends. */
3168 switch (GET_CODE (x))
3171 if (GET_CODE (XEXP (x, 0)) != PLUS
3172 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3174 tmp = XEXP (XEXP (x, 0), 0);
3179 gcc_assert (!INSN_DELETED_P (tmp));
3180 gcc_assert (!NOTE_P (tmp)
3181 || NOTE_LINE_NUMBER (tmp) != NOTE_INSN_DELETED);
3188 /* First switch to correct section. */
3189 targetm.asm_out.select_rtx_section (desc->mode, x, desc->align);
3191 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3192 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3193 desc->align, desc->labelno, done);
3196 assemble_align (desc->align);
3198 /* Output the label. */
3199 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3201 /* Output the data. */
3202 output_constant_pool_2 (desc->mode, x, desc->align);
3204 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3205 sections have proper size. */
3206 if (desc->align > GET_MODE_BITSIZE (desc->mode)
3207 && in_section == in_named
3208 && get_named_section_flags (in_named_name) & SECTION_MERGE)
3209 assemble_align (desc->align);
3211 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3217 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3218 to as used. Emit referenced deferred strings. This function can
3219 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3222 mark_constant (rtx *current_rtx, void *data)
3224 struct rtx_constant_pool *pool = data;
3225 rtx x = *current_rtx;
3227 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3230 if (CONSTANT_POOL_ADDRESS_P (x))
3232 struct constant_descriptor_rtx *desc = find_pool_constant (pool, x);
3233 if (desc->mark == 0)
3236 for_each_rtx (&desc->constant, mark_constant, pool);
3239 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3241 tree exp = SYMBOL_REF_DECL (x);
3242 if (!TREE_ASM_WRITTEN (exp))
3244 n_deferred_constants--;
3245 output_constant_def_contents (x);
3252 /* Look through appropriate parts of INSN, marking all entries in the
3253 constant pool which are actually being used. Entries that are only
3254 referenced by other constants are also marked as used. Emit
3255 deferred strings that are used. */
3258 mark_constants (struct rtx_constant_pool *pool, rtx insn)
3263 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3264 insns, not any notes that may be attached. We don't want to mark
3265 a constant just because it happens to appear in a REG_EQUIV note. */
3266 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3268 rtx seq = PATTERN (insn);
3269 int i, n = XVECLEN (seq, 0);
3270 for (i = 0; i < n; ++i)
3272 rtx subinsn = XVECEXP (seq, 0, i);
3273 if (INSN_P (subinsn))
3274 for_each_rtx (&PATTERN (subinsn), mark_constant, pool);
3278 for_each_rtx (&PATTERN (insn), mark_constant, pool);
3281 /* Look through the instructions for this function, and mark all the
3282 entries in POOL which are actually being used. Emit deferred constants
3283 which have indeed been used. */
3286 mark_constant_pool (struct rtx_constant_pool *pool)
3290 if (pool->first == 0 && n_deferred_constants == 0)
3293 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3294 mark_constants (pool, insn);
3296 for (link = current_function_epilogue_delay_list;
3298 link = XEXP (link, 1))
3299 mark_constants (pool, XEXP (link, 0));
3302 /* Write all the constants in the constant pool. */
3305 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3306 tree fndecl ATTRIBUTE_UNUSED)
3308 struct rtx_constant_pool *pool = cfun->varasm->pool;
3309 struct constant_descriptor_rtx *desc;
3311 /* It is possible for gcc to call force_const_mem and then to later
3312 discard the instructions which refer to the constant. In such a
3313 case we do not need to output the constant. */
3314 mark_constant_pool (pool);
3316 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3317 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3320 for (desc = pool->first; desc ; desc = desc->next)
3321 output_constant_pool_1 (desc);
3323 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3324 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3328 /* Determine what kind of relocations EXP may need. */
3331 compute_reloc_for_constant (tree exp)
3333 int reloc = 0, reloc2;
3336 /* Give the front-end a chance to convert VALUE to something that
3337 looks more like a constant to the back-end. */
3338 exp = lang_hooks.expand_constant (exp);
3340 switch (TREE_CODE (exp))
3344 /* Go inside any operations that get_inner_reference can handle and see
3345 if what's inside is a constant: no need to do anything here for
3346 addresses of variables or functions. */
3347 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3348 tem = TREE_OPERAND (tem, 0))
3351 if (TREE_PUBLIC (tem))
3358 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3359 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3363 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3364 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3365 /* The difference of two local labels is computable at link time. */
3366 if (reloc == 1 && reloc2 == 1)
3374 case NON_LVALUE_EXPR:
3375 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3379 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3380 if (TREE_VALUE (tem) != 0)
3381 reloc |= compute_reloc_for_constant (TREE_VALUE (tem));
3391 /* Find all the constants whose addresses are referenced inside of EXP,
3392 and make sure assembler code with a label has been output for each one.
3393 Indicate whether an ADDR_EXPR has been encountered. */
3396 output_addressed_constants (tree exp)
3400 /* Give the front-end a chance to convert VALUE to something that
3401 looks more like a constant to the back-end. */
3402 exp = lang_hooks.expand_constant (exp);
3404 switch (TREE_CODE (exp))
3408 /* Go inside any operations that get_inner_reference can handle and see
3409 if what's inside is a constant: no need to do anything here for
3410 addresses of variables or functions. */
3411 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3412 tem = TREE_OPERAND (tem, 0))
3415 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3416 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
3417 tem = DECL_INITIAL (tem);
3419 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
3420 output_constant_def (tem, 0);
3425 output_addressed_constants (TREE_OPERAND (exp, 1));
3430 case NON_LVALUE_EXPR:
3431 output_addressed_constants (TREE_OPERAND (exp, 0));
3435 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3436 if (TREE_VALUE (tem) != 0)
3437 output_addressed_constants (TREE_VALUE (tem));
3446 /* Return nonzero if VALUE is a valid constant-valued expression
3447 for use in initializing a static variable; one that can be an
3448 element of a "constant" initializer.
3450 Return null_pointer_node if the value is absolute;
3451 if it is relocatable, return the variable that determines the relocation.
3452 We assume that VALUE has been folded as much as possible;
3453 therefore, we do not need to check for such things as
3454 arithmetic-combinations of integers. */
3457 initializer_constant_valid_p (tree value, tree endtype)
3459 /* Give the front-end a chance to convert VALUE to something that
3460 looks more like a constant to the back-end. */
3461 value = lang_hooks.expand_constant (value);
3463 switch (TREE_CODE (value))
3466 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
3467 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
3468 && TREE_CONSTANT (value)
3469 && CONSTRUCTOR_ELTS (value))
3472 bool absolute = true;
3474 for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt))
3477 value = TREE_VALUE (elt);
3478 reloc = initializer_constant_valid_p (value, TREE_TYPE (value));
3481 if (reloc != null_pointer_node)
3484 /* For a non-absolute relocation, there is no single
3485 variable that can be "the variable that determines the
3487 return absolute ? null_pointer_node : error_mark_node;
3490 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
3497 return null_pointer_node;
3501 value = staticp (TREE_OPERAND (value, 0));
3502 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to
3503 be a constant, this is old-skool offsetof-like nonsense. */
3505 && TREE_CODE (value) == INDIRECT_REF
3506 && TREE_CONSTANT (TREE_OPERAND (value, 0)))
3507 return null_pointer_node;
3508 /* Taking the address of a nested function involves a trampoline. */
3510 && TREE_CODE (value) == FUNCTION_DECL
3511 && ((decl_function_context (value) && !DECL_NO_STATIC_CHAIN (value))
3512 || DECL_NON_ADDR_CONST_P (value)))
3516 case VIEW_CONVERT_EXPR:
3517 case NON_LVALUE_EXPR:
3518 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3527 src = TREE_OPERAND (value, 0);
3528 src_type = TREE_TYPE (src);
3529 dest_type = TREE_TYPE (value);
3531 /* Allow conversions between pointer types, floating-point
3532 types, and offset types. */
3533 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
3534 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
3535 || (TREE_CODE (dest_type) == OFFSET_TYPE
3536 && TREE_CODE (src_type) == OFFSET_TYPE))
3537 return initializer_constant_valid_p (src, endtype);
3539 /* Allow length-preserving conversions between integer types. */
3540 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
3541 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
3542 return initializer_constant_valid_p (src, endtype);
3544 /* Allow conversions between other integer types only if
3546 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
3548 tree inner = initializer_constant_valid_p (src, endtype);
3549 if (inner == null_pointer_node)
3550 return null_pointer_node;
3554 /* Allow (int) &foo provided int is as wide as a pointer. */
3555 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
3556 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
3557 return initializer_constant_valid_p (src, endtype);
3559 /* Likewise conversions from int to pointers, but also allow
3560 conversions from 0. */
3561 if ((POINTER_TYPE_P (dest_type)
3562 || TREE_CODE (dest_type) == OFFSET_TYPE)
3563 && INTEGRAL_TYPE_P (src_type))
3565 if (integer_zerop (src))
3566 return null_pointer_node;
3567 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
3568 return initializer_constant_valid_p (src, endtype);
3571 /* Allow conversions to struct or union types if the value
3573 if (TREE_CODE (dest_type) == RECORD_TYPE
3574 || TREE_CODE (dest_type) == UNION_TYPE)
3575 return initializer_constant_valid_p (src, endtype);
3580 if (! INTEGRAL_TYPE_P (endtype)
3581 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3583 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3585 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3587 /* If either term is absolute, use the other terms relocation. */
3588 if (valid0 == null_pointer_node)
3590 if (valid1 == null_pointer_node)
3596 if (! INTEGRAL_TYPE_P (endtype)
3597 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3599 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3601 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3603 /* Win if second argument is absolute. */
3604 if (valid1 == null_pointer_node)
3606 /* Win if both arguments have the same relocation.
3607 Then the value is absolute. */
3608 if (valid0 == valid1 && valid0 != 0)
3609 return null_pointer_node;
3611 /* Since GCC guarantees that string constants are unique in the
3612 generated code, a subtraction between two copies of the same
3613 constant string is absolute. */
3614 if (valid0 && TREE_CODE (valid0) == STRING_CST
3615 && valid1 && TREE_CODE (valid1) == STRING_CST
3616 && operand_equal_p (valid0, valid1, 1))
3617 return null_pointer_node;
3620 /* Support narrowing differences. */
3621 if (INTEGRAL_TYPE_P (endtype))
3625 op0 = TREE_OPERAND (value, 0);
3626 op1 = TREE_OPERAND (value, 1);
3628 /* Like STRIP_NOPS except allow the operand mode to widen.
3629 This works around a feature of fold that simplifies
3630 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3631 that the narrower operation is cheaper. */
3633 while (TREE_CODE (op0) == NOP_EXPR
3634 || TREE_CODE (op0) == CONVERT_EXPR
3635 || TREE_CODE (op0) == NON_LVALUE_EXPR)
3637 tree inner = TREE_OPERAND (op0, 0);
3638 if (inner == error_mark_node
3639 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3640 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3641 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3646 while (TREE_CODE (op1) == NOP_EXPR
3647 || TREE_CODE (op1) == CONVERT_EXPR
3648 || TREE_CODE (op1) == NON_LVALUE_EXPR)
3650 tree inner = TREE_OPERAND (op1, 0);
3651 if (inner == error_mark_node
3652 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3653 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3654 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3659 op0 = initializer_constant_valid_p (op0, endtype);
3660 op1 = initializer_constant_valid_p (op1, endtype);
3662 /* Both initializers must be known. */
3666 return null_pointer_node;
3668 /* Support differences between labels. */
3669 if (TREE_CODE (op0) == LABEL_DECL
3670 && TREE_CODE (op1) == LABEL_DECL)
3671 return null_pointer_node;
3673 if (TREE_CODE (op0) == STRING_CST
3674 && TREE_CODE (op1) == STRING_CST
3675 && operand_equal_p (op0, op1, 1))
3676 return null_pointer_node;
3688 /* Output assembler code for constant EXP to FILE, with no label.
3689 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3690 Assumes output_addressed_constants has been done on EXP already.
3692 Generate exactly SIZE bytes of assembler data, padding at the end
3693 with zeros if necessary. SIZE must always be specified.
3695 SIZE is important for structure constructors,
3696 since trailing members may have been omitted from the constructor.
3697 It is also important for initialization of arrays from string constants
3698 since the full length of the string constant might not be wanted.
3699 It is also needed for initialization of unions, where the initializer's
3700 type is just one member, and that may not be as long as the union.
3702 There a case in which we would fail to output exactly SIZE bytes:
3703 for a structure constructor that wants to produce more than SIZE bytes.
3704 But such constructors will never be generated for any possible input.
3706 ALIGN is the alignment of the data in bits. */
3709 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
3711 enum tree_code code;
3712 unsigned HOST_WIDE_INT thissize;
3714 /* Some front-ends use constants other than the standard language-independent
3715 varieties, but which may still be output directly. Give the front-end a
3716 chance to convert EXP to a language-independent representation. */
3717 exp = lang_hooks.expand_constant (exp);
3719 if (size == 0 || flag_syntax_only)
3722 /* Eliminate any conversions since we'll be outputting the underlying
3724 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3725 || TREE_CODE (exp) == NON_LVALUE_EXPR
3726 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
3727 exp = TREE_OPERAND (exp, 0);
3729 code = TREE_CODE (TREE_TYPE (exp));
3730 thissize = int_size_in_bytes (TREE_TYPE (exp));
3732 /* Allow a constructor with no elements for any data type.
3733 This means to fill the space with zeros. */
3734 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3736 assemble_zeros (size);
3740 if (TREE_CODE (exp) == FDESC_EXPR)
3742 #ifdef ASM_OUTPUT_FDESC
3743 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
3744 tree decl = TREE_OPERAND (exp, 0);
3745 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
3752 /* Now output the underlying data. If we've handling the padding, return.
3753 Otherwise, break and ensure SIZE is the size written. */
3761 case REFERENCE_TYPE:
3763 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3764 EXPAND_INITIALIZER),
3765 MIN (size, thissize), align, 0))
3766 error ("initializer for integer value is too complicated");
3770 if (TREE_CODE (exp) != REAL_CST)
3771 error ("initializer for floating value is not a floating constant");
3773 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
3777 output_constant (TREE_REALPART (exp), thissize / 2, align);
3778 output_constant (TREE_IMAGPART (exp), thissize / 2,
3779 min_align (align, BITS_PER_UNIT * (thissize / 2)));
3784 switch (TREE_CODE (exp))
3787 output_constructor (exp, size, align);
3790 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
3792 assemble_string (TREE_STRING_POINTER (exp), thissize);
3799 unsigned int nalign;
3800 enum machine_mode inner;
3802 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
3803 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
3805 elt_size = GET_MODE_SIZE (inner);
3807 link = TREE_VECTOR_CST_ELTS (exp);
3808 output_constant (TREE_VALUE (link), elt_size, align);
3809 while ((link = TREE_CHAIN (link)) != NULL)
3810 output_constant (TREE_VALUE (link), elt_size, nalign);
3820 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
3821 output_constructor (exp, size, align);
3831 if (size > thissize)
3832 assemble_zeros (size - thissize);
3836 /* Subroutine of output_constructor, used for computing the size of
3837 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3838 type with an unspecified upper bound. */
3840 static unsigned HOST_WIDE_INT
3841 array_size_for_constructor (tree val)
3845 /* This code used to attempt to handle string constants that are not
3846 arrays of single-bytes, but nothing else does, so there's no point in
3848 if (TREE_CODE (val) == STRING_CST)
3849 return TREE_STRING_LENGTH (val);
3851 max_index = NULL_TREE;
3852 for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i))
3854 tree index = TREE_PURPOSE (i);
3856 if (TREE_CODE (index) == RANGE_EXPR)
3857 index = TREE_OPERAND (index, 1);
3858 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
3862 if (max_index == NULL_TREE)
3865 /* Compute the total number of array elements. */
3866 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
3868 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
3869 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
3871 /* Multiply by the array element unit size to find number of bytes. */
3872 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
3874 return tree_low_cst (i, 1);
3877 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3878 Generate at least SIZE bytes, padding if necessary. */
3881 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
3884 tree type = TREE_TYPE (exp);
3885 tree link, field = 0;
3887 /* Number of bytes output or skipped so far.
3888 In other words, current position within the constructor. */
3889 HOST_WIDE_INT total_bytes = 0;
3890 /* Nonzero means BYTE contains part of a byte, to be output. */
3891 int byte_buffer_in_use = 0;
3894 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
3896 if (TREE_CODE (type) == RECORD_TYPE)
3897 field = TYPE_FIELDS (type);
3899 if (TREE_CODE (type) == ARRAY_TYPE
3900 && TYPE_DOMAIN (type) != 0)
3901 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
3903 /* As LINK goes through the elements of the constant,
3904 FIELD goes through the structure fields, if the constant is a structure.
3905 if the constant is a union, then we override this,
3906 by getting the field from the TREE_LIST element.
3907 But the constant could also be an array. Then FIELD is zero.
3909 There is always a maximum of one element in the chain LINK for unions
3910 (even if the initializer in a source program incorrectly contains
3912 for (link = CONSTRUCTOR_ELTS (exp);
3914 link = TREE_CHAIN (link),
3915 field = field ? TREE_CHAIN (field) : 0)
3917 tree val = TREE_VALUE (link);
3920 /* The element in a union constructor specifies the proper field
3922 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
3923 || TREE_CODE (type) == QUAL_UNION_TYPE)
3924 && TREE_PURPOSE (link) != 0)
3925 field = TREE_PURPOSE (link);
3927 else if (TREE_CODE (type) == ARRAY_TYPE)
3928 index = TREE_PURPOSE (link);
3930 #ifdef ASM_COMMENT_START
3931 if (field && flag_verbose_asm)
3932 fprintf (asm_out_file, "%s %s:\n",
3935 ? IDENTIFIER_POINTER (DECL_NAME (field))
3939 /* Eliminate the marker that makes a cast not be an lvalue. */
3943 if (index && TREE_CODE (index) == RANGE_EXPR)
3945 unsigned HOST_WIDE_INT fieldsize
3946 = int_size_in_bytes (TREE_TYPE (type));
3947 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
3948 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
3949 HOST_WIDE_INT index;
3950 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
3952 for (index = lo_index; index <= hi_index; index++)
3954 /* Output the element's initial value. */
3956 assemble_zeros (fieldsize);
3958 output_constant (val, fieldsize, align2);
3960 /* Count its size. */
3961 total_bytes += fieldsize;
3964 else if (field == 0 || !DECL_BIT_FIELD (field))
3966 /* An element that is not a bit-field. */
3968 unsigned HOST_WIDE_INT fieldsize;
3969 /* Since this structure is static,
3970 we know the positions are constant. */
3971 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
3972 unsigned int align2;
3975 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
3976 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
3978 /* Output any buffered-up bit-fields preceding this element. */
3979 if (byte_buffer_in_use)
3981 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3983 byte_buffer_in_use = 0;
3986 /* Advance to offset of this element.
3987 Note no alignment needed in an array, since that is guaranteed
3988 if each element has the proper size. */
3989 if ((field != 0 || index != 0) && pos != total_bytes)
3991 assemble_zeros (pos - total_bytes);
3995 /* Find the alignment of this element. */
3996 align2 = min_align (align, BITS_PER_UNIT * pos);
3998 /* Determine size this element should occupy. */
4003 /* If this is an array with an unspecified upper bound,
4004 the initializer determines the size. */
4005 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4006 but we cannot do this until the deprecated support for
4007 initializing zero-length array members is removed. */
4008 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4009 && TYPE_DOMAIN (TREE_TYPE (field))
4010 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4012 fieldsize = array_size_for_constructor (val);
4013 /* Given a non-empty initialization, this field had
4015 gcc_assert (!fieldsize || !TREE_CHAIN (field));
4017 else if (DECL_SIZE_UNIT (field))
4019 /* ??? This can't be right. If the decl size overflows
4020 a host integer we will silently emit no data. */
4021 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4022 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4026 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4028 /* Output the element's initial value. */
4030 assemble_zeros (fieldsize);
4032 output_constant (val, fieldsize, align2);
4034 /* Count its size. */
4035 total_bytes += fieldsize;
4037 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4038 error ("invalid initial value for member %qs",
4039 IDENTIFIER_POINTER (DECL_NAME (field)));
4042 /* Element that is a bit-field. */
4044 HOST_WIDE_INT next_offset = int_bit_position (field);
4045 HOST_WIDE_INT end_offset
4046 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4049 val = integer_zero_node;
4051 /* If this field does not start in this (or, next) byte,
4053 if (next_offset / BITS_PER_UNIT != total_bytes)
4055 /* Output remnant of any bit field in previous bytes. */
4056 if (byte_buffer_in_use)
4058 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4060 byte_buffer_in_use = 0;
4063 /* If still not at proper byte, advance to there. */
4064 if (next_offset / BITS_PER_UNIT != total_bytes)
4066 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4067 total_bytes = next_offset / BITS_PER_UNIT;
4071 if (! byte_buffer_in_use)
4074 /* We must split the element into pieces that fall within
4075 separate bytes, and combine each byte with previous or
4076 following bit-fields. */
4078 /* next_offset is the offset n fbits from the beginning of
4079 the structure to the next bit of this element to be processed.
4080 end_offset is the offset of the first bit past the end of
4082 while (next_offset < end_offset)
4086 HOST_WIDE_INT value;
4087 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4088 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4090 /* Advance from byte to byte
4091 within this element when necessary. */
4092 while (next_byte != total_bytes)
4094 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4099 /* Number of bits we can process at once
4100 (all part of the same byte). */
4101 this_time = MIN (end_offset - next_offset,
4102 BITS_PER_UNIT - next_bit);
4103 if (BYTES_BIG_ENDIAN)
4105 /* On big-endian machine, take the most significant bits
4106 first (of the bits that are significant)
4107 and put them into bytes from the most significant end. */
4108 shift = end_offset - next_offset - this_time;
4110 /* Don't try to take a bunch of bits that cross
4111 the word boundary in the INTEGER_CST. We can
4112 only select bits from the LOW or HIGH part
4114 if (shift < HOST_BITS_PER_WIDE_INT
4115 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4117 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4118 shift = HOST_BITS_PER_WIDE_INT;
4121 /* Now get the bits from the appropriate constant word. */
4122 if (shift < HOST_BITS_PER_WIDE_INT)
4123 value = TREE_INT_CST_LOW (val);
4126 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4127 value = TREE_INT_CST_HIGH (val);
4128 shift -= HOST_BITS_PER_WIDE_INT;
4131 /* Get the result. This works only when:
4132 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4133 byte |= (((value >> shift)
4134 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4135 << (BITS_PER_UNIT - this_time - next_bit));
4139 /* On little-endian machines,
4140 take first the least significant bits of the value
4141 and pack them starting at the least significant
4142 bits of the bytes. */
4143 shift = next_offset - int_bit_position (field);
4145 /* Don't try to take a bunch of bits that cross
4146 the word boundary in the INTEGER_CST. We can
4147 only select bits from the LOW or HIGH part
4149 if (shift < HOST_BITS_PER_WIDE_INT
4150 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4151 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4153 /* Now get the bits from the appropriate constant word. */
4154 if (shift < HOST_BITS_PER_WIDE_INT)
4155 value = TREE_INT_CST_LOW (val);
4158 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4159 value = TREE_INT_CST_HIGH (val);
4160 shift -= HOST_BITS_PER_WIDE_INT;
4163 /* Get the result. This works only when:
4164 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4165 byte |= (((value >> shift)
4166 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4170 next_offset += this_time;
4171 byte_buffer_in_use = 1;
4176 if (byte_buffer_in_use)
4178 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4182 if ((unsigned HOST_WIDE_INT)total_bytes < size)
4183 assemble_zeros (size - total_bytes);
4186 /* This TREE_LIST contains any weak symbol declarations waiting
4188 static GTY(()) tree weak_decls;
4190 /* Mark DECL as weak. */
4193 mark_weak (tree decl)
4195 DECL_WEAK (decl) = 1;
4197 if (DECL_RTL_SET_P (decl)
4198 && MEM_P (DECL_RTL (decl))
4199 && XEXP (DECL_RTL (decl), 0)
4200 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4201 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4204 /* Merge weak status between NEWDECL and OLDDECL. */
4207 merge_weak (tree newdecl, tree olddecl)
4209 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4212 if (DECL_WEAK (newdecl))
4216 /* NEWDECL is weak, but OLDDECL is not. */
4218 /* If we already output the OLDDECL, we're in trouble; we can't
4219 go back and make it weak. This error cannot caught in
4220 declare_weak because the NEWDECL and OLDDECL was not yet
4221 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4222 if (TREE_ASM_WRITTEN (olddecl))
4223 error ("%Jweak declaration of %qD must precede definition",
4226 /* If we've already generated rtl referencing OLDDECL, we may
4227 have done so in a way that will not function properly with
4229 else if (TREE_USED (olddecl)
4230 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4231 warning ("%Jweak declaration of %qD after first use results "
4232 "in unspecified behavior", newdecl, newdecl);
4236 /* We put the NEWDECL on the weak_decls list at some point.
4237 Replace it with the OLDDECL. */
4238 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4239 if (TREE_VALUE (wd) == newdecl)
4241 TREE_VALUE (wd) = olddecl;
4244 /* We may not find the entry on the list. If NEWDECL is a
4245 weak alias, then we will have already called
4246 globalize_decl to remove the entry; in that case, we do
4247 not need to do anything. */
4250 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4251 mark_weak (olddecl);
4254 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4255 weak. Just update NEWDECL to indicate that it's weak too. */
4256 mark_weak (newdecl);
4259 /* Declare DECL to be a weak symbol. */
4262 declare_weak (tree decl)
4264 if (! TREE_PUBLIC (decl))
4265 error ("%Jweak declaration of %qD must be public", decl, decl);
4266 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4267 error ("%Jweak declaration of %qD must precede definition", decl, decl);
4268 else if (SUPPORTS_WEAK)
4270 if (! DECL_WEAK (decl))
4271 weak_decls = tree_cons (NULL, decl, weak_decls);
4274 warning ("%Jweak declaration of %qD not supported", decl, decl);
4279 /* Emit any pending weak declarations. */
4286 for (t = weak_decls; t; t = TREE_CHAIN (t))
4288 tree decl = TREE_VALUE (t);
4289 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4290 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4293 if (! TREE_USED (decl))
4296 #ifdef ASM_WEAKEN_DECL
4297 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4299 #ifdef ASM_WEAKEN_LABEL
4300 ASM_WEAKEN_LABEL (asm_out_file, name);
4302 #ifdef ASM_OUTPUT_WEAK_ALIAS
4303 warning ("only weak aliases are supported in this configuration");
4311 /* Emit the assembly bits to indicate that DECL is globally visible. */
4314 globalize_decl (tree decl)
4316 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4318 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4319 if (DECL_WEAK (decl))
4323 #ifdef ASM_WEAKEN_DECL
4324 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4326 ASM_WEAKEN_LABEL (asm_out_file, name);
4329 /* Remove this function from the pending weak list so that
4330 we do not emit multiple .weak directives for it. */
4331 for (p = &weak_decls; (t = *p) ; )
4333 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4334 *p = TREE_CHAIN (t);
4336 p = &TREE_CHAIN (t);
4340 #elif defined(ASM_MAKE_LABEL_LINKONCE)
4341 if (DECL_ONE_ONLY (decl))
4342 ASM_MAKE_LABEL_LINKONCE (asm_out_file, name);
4345 targetm.asm_out.globalize_label (asm_out_file, name);
4348 /* We have to be able to tell cgraph about the needed-ness of the target
4349 of an alias. This requires that the decl have been defined. Aliases
4350 that preceed their definition have to be queued for later processing. */
4352 struct alias_pair GTY(())
4357 typedef struct alias_pair *alias_pair;
4359 /* Define gc'd vector type. */
4360 DEF_VEC_GC_P(alias_pair);
4362 static GTY(()) VEC(alias_pair) *alias_pairs;
4364 /* Given an assembly name, find the decl it is associated with. At the
4365 same time, mark it needed for cgraph. */
4368 find_decl_and_mark_needed (tree decl, tree target)
4370 struct cgraph_node *fnode = NULL;
4371 struct cgraph_varpool_node *vnode = NULL;
4373 /* C++ thunk emitting code produces aliases late in the game.
4374 Avoid confusing cgraph code in that case. */
4375 if (!cgraph_global_info_ready)
4377 if (TREE_CODE (decl) == FUNCTION_DECL)
4379 fnode = cgraph_node_for_asm (target);
4381 vnode = cgraph_varpool_node_for_asm (target);
4385 vnode = cgraph_varpool_node_for_asm (target);
4387 fnode = cgraph_node_for_asm (target);
4393 cgraph_mark_needed_node (fnode);
4398 cgraph_varpool_mark_needed_node (vnode);
4405 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
4406 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
4407 tree node is DECL to have the value of the tree node TARGET. */
4410 do_assemble_alias (tree decl, tree target ATTRIBUTE_UNUSED)
4412 TREE_ASM_WRITTEN (decl) = 1;
4413 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4415 #ifdef ASM_OUTPUT_DEF
4416 /* Make name accessible from other files, if appropriate. */
4418 if (TREE_PUBLIC (decl))
4420 globalize_decl (decl);
4421 maybe_assemble_visibility (decl);
4424 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
4425 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4427 ASM_OUTPUT_DEF (asm_out_file,
4428 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
4429 IDENTIFIER_POINTER (target));
4431 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4436 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4437 # ifdef ASM_WEAKEN_DECL
4438 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4440 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4442 /* Remove this function from the pending weak list so that
4443 we do not emit multiple .weak directives for it. */
4444 for (p = &weak_decls; (t = *p) ; )
4445 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4446 *p = TREE_CHAIN (t);
4448 p = &TREE_CHAIN (t);
4453 /* First pass of completing pending aliases. Make sure that cgraph knows
4454 which symbols will be required. */
4457 finish_aliases_1 (void)
4462 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
4466 target_decl = find_decl_and_mark_needed (p->decl, p->target);
4467 if (target_decl == NULL)
4468 error ("%J%qD aliased to undefined symbol %qE",
4469 p->decl, p->decl, p->target);
4470 else if (DECL_EXTERNAL (target_decl))
4471 error ("%J%qD aliased to external symbol %qE",
4472 p->decl, p->decl, p->target);
4476 /* Second pass of completing pending aliases. Emit the actual assembly.
4477 This happens at the end of compilation and thus it is assured that the
4478 target symbol has been emitted. */
4481 finish_aliases_2 (void)
4486 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
4487 do_assemble_alias (p->decl, p->target);
4492 /* Emit an assembler directive to make the symbol for DECL an alias to
4493 the symbol for TARGET. */
4496 assemble_alias (tree decl, tree target)
4500 #if !defined (ASM_OUTPUT_DEF)
4501 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
4502 error ("%Jalias definitions not supported in this configuration", decl);
4505 if (!DECL_WEAK (decl))
4507 error ("%Jonly weak aliases are supported in this configuration", decl);
4513 /* We must force creation of DECL_RTL for debug info generation, even though
4514 we don't use it here. */
4515 make_decl_rtl (decl);
4516 TREE_USED (decl) = 1;
4518 /* A quirk of the initial implementation of aliases required that the user
4519 add "extern" to all of them. Which is silly, but now historical. Do
4520 note that the symbol is in fact locally defined. */
4521 DECL_EXTERNAL (decl) = 0;
4523 /* Allow aliases to aliases. */
4524 if (TREE_CODE (decl) == FUNCTION_DECL)
4525 cgraph_node (decl)->alias = true;
4527 cgraph_varpool_node (decl)->alias = true;
4529 /* If the target has already been emitted, we don't have to queue the
4530 alias. This saves a tad o memory. */
4531 target_decl = find_decl_and_mark_needed (decl, target);
4532 if (target_decl && TREE_ASM_WRITTEN (target_decl))
4533 do_assemble_alias (decl, target);
4538 p = ggc_alloc (sizeof (struct alias_pair));
4541 VEC_safe_push (alias_pair, alias_pairs, p);
4545 /* Emit an assembler directive to set symbol for DECL visibility to
4546 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4549 default_assemble_visibility (tree decl, int vis)
4551 static const char * const visibility_types[] = {
4552 NULL, "internal", "hidden", "protected"
4555 const char *name, *type;
4557 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4558 type = visibility_types[vis];
4560 #ifdef HAVE_GAS_HIDDEN
4561 fprintf (asm_out_file, "\t.%s\t", type);
4562 assemble_name (asm_out_file, name);
4563 fprintf (asm_out_file, "\n");
4565 warning ("visibility attribute not supported in this configuration; ignored");
4569 /* A helper function to call assemble_visibility when needed for a decl. */
4572 maybe_assemble_visibility (tree decl)
4574 enum symbol_visibility vis = DECL_VISIBILITY (decl);
4576 if (vis != VISIBILITY_DEFAULT)
4577 targetm.asm_out.visibility (decl, vis);
4580 /* Returns 1 if the target configuration supports defining public symbols
4581 so that one of them will be chosen at link time instead of generating a
4582 multiply-defined symbol error, whether through the use of weak symbols or
4583 a target-specific mechanism for having duplicates discarded. */
4586 supports_one_only (void)
4588 if (SUPPORTS_ONE_ONLY)
4590 return SUPPORTS_WEAK;
4593 /* Set up DECL as a public symbol that can be defined in multiple
4594 translation units without generating a linker error. */
4597 make_decl_one_only (tree decl)
4599 gcc_assert (TREE_CODE (decl) == VAR_DECL
4600 || TREE_CODE (decl) == FUNCTION_DECL);
4602 TREE_PUBLIC (decl) = 1;
4604 if (SUPPORTS_ONE_ONLY)
4606 #ifdef MAKE_DECL_ONE_ONLY
4607 MAKE_DECL_ONE_ONLY (decl);
4609 DECL_ONE_ONLY (decl) = 1;
4611 else if (TREE_CODE (decl) == VAR_DECL
4612 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4613 DECL_COMMON (decl) = 1;
4616 gcc_assert (SUPPORTS_WEAK);
4617 DECL_WEAK (decl) = 1;
4622 init_varasm_once (void)
4624 in_named_htab = htab_create_ggc (31, in_named_entry_hash,
4625 in_named_entry_eq, NULL);
4626 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
4627 const_desc_eq, NULL);
4629 const_alias_set = new_alias_set ();
4632 static enum tls_model
4633 decl_tls_model (tree decl)
4635 enum tls_model kind;
4636 tree attr = lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl));
4641 attr = TREE_VALUE (TREE_VALUE (attr));
4642 gcc_assert (TREE_CODE (attr) == STRING_CST);
4644 if (!strcmp (TREE_STRING_POINTER (attr), "local-exec"))
4645 kind = TLS_MODEL_LOCAL_EXEC;
4646 else if (!strcmp (TREE_STRING_POINTER (attr), "initial-exec"))
4647 kind = TLS_MODEL_INITIAL_EXEC;
4648 else if (!strcmp (TREE_STRING_POINTER (attr), "local-dynamic"))
4649 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
4650 else if (!strcmp (TREE_STRING_POINTER (attr), "global-dynamic"))
4651 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4657 is_local = targetm.binds_local_p (decl);
4661 kind = TLS_MODEL_LOCAL_EXEC;
4663 kind = TLS_MODEL_INITIAL_EXEC;
4665 /* Local dynamic is inefficient when we're not combining the
4666 parts of the address. */
4667 else if (optimize && is_local)
4668 kind = TLS_MODEL_LOCAL_DYNAMIC;
4670 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4671 if (kind < flag_tls_default)
4672 kind = flag_tls_default;
4677 /* Select a set of attributes for section NAME based on the properties
4678 of DECL and whether or not RELOC indicates that DECL's initializer
4679 might contain runtime relocations.
4681 We make the section read-only and executable for a function decl,
4682 read-only for a const data decl, and writable for a non-const data decl. */
4685 default_section_type_flags (tree decl, const char *name, int reloc)
4687 return default_section_type_flags_1 (decl, name, reloc, flag_pic);
4691 default_section_type_flags_1 (tree decl, const char *name, int reloc,
4696 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4697 flags = SECTION_CODE;
4698 else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
4700 else if (unlikely_text_section_name
4701 && strcmp (name, unlikely_text_section_name) == 0)
4702 flags = SECTION_CODE;
4704 flags = SECTION_WRITE;
4706 if (decl && DECL_ONE_ONLY (decl))
4707 flags |= SECTION_LINKONCE;
4709 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4710 flags |= SECTION_TLS | SECTION_WRITE;
4712 if (strcmp (name, ".bss") == 0
4713 || strncmp (name, ".bss.", 5) == 0
4714 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
4715 || strcmp (name, ".sbss") == 0
4716 || strncmp (name, ".sbss.", 6) == 0
4717 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
4718 flags |= SECTION_BSS;
4720 if (strcmp (name, ".tdata") == 0
4721 || strncmp (name, ".tdata.", 7) == 0
4722 || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
4723 flags |= SECTION_TLS;
4725 if (strcmp (name, ".tbss") == 0
4726 || strncmp (name, ".tbss.", 6) == 0
4727 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4728 flags |= SECTION_TLS | SECTION_BSS;
4730 /* These three sections have special ELF types. They are neither
4731 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4732 want to print a section type (@progbits or @nobits). If someone
4733 is silly enough to emit code or TLS variables to one of these
4734 sections, then don't handle them specially. */
4735 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
4736 && (strcmp (name, ".init_array") == 0
4737 || strcmp (name, ".fini_array") == 0
4738 || strcmp (name, ".preinit_array") == 0))
4739 flags |= SECTION_NOTYPE;
4744 /* Output assembly to switch to section NAME with attribute FLAGS.
4745 Four variants for common object file formats. */
4748 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
4749 unsigned int flags ATTRIBUTE_UNUSED,
4750 tree decl ATTRIBUTE_UNUSED)
4752 /* Some object formats don't support named sections at all. The
4753 front-end should already have flagged this as an error. */
4758 default_elf_asm_named_section (const char *name, unsigned int flags,
4759 tree decl ATTRIBUTE_UNUSED)
4761 char flagchars[10], *f = flagchars;
4763 /* If we have already declared this section, we can use an
4764 abbreviated form to switch back to it -- unless this section is
4765 part of a COMDAT groups, in which case GAS requires the full
4766 declaration every time. */
4767 if (!(HAVE_GAS_COMDAT_GROUP && (flags & SECTION_LINKONCE))
4768 && ! named_section_first_declaration (name))
4770 fprintf (asm_out_file, "\t.section\t%s\n", name);
4774 if (!(flags & SECTION_DEBUG))
4776 if (flags & SECTION_WRITE)
4778 if (flags & SECTION_CODE)
4780 if (flags & SECTION_SMALL)
4782 if (flags & SECTION_MERGE)
4784 if (flags & SECTION_STRINGS)
4786 if (flags & SECTION_TLS)
4788 if (HAVE_GAS_COMDAT_GROUP && (flags & SECTION_LINKONCE))
4792 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
4794 if (!(flags & SECTION_NOTYPE))
4799 if (flags & SECTION_BSS)
4805 #ifdef ASM_COMMENT_START
4806 /* On platforms that use "@" as the assembly comment character,
4808 if (strcmp (ASM_COMMENT_START, "@") == 0)
4811 fprintf (asm_out_file, format, type);
4813 if (flags & SECTION_ENTSIZE)
4814 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
4815 if (HAVE_GAS_COMDAT_GROUP && (flags & SECTION_LINKONCE))
4816 fprintf (asm_out_file, ",%s,comdat",
4817 lang_hooks.decls.comdat_group (decl));
4820 putc ('\n', asm_out_file);
4824 default_coff_asm_named_section (const char *name, unsigned int flags,
4825 tree decl ATTRIBUTE_UNUSED)
4827 char flagchars[8], *f = flagchars;
4829 if (flags & SECTION_WRITE)
4831 if (flags & SECTION_CODE)
4835 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
4839 default_pe_asm_named_section (const char *name, unsigned int flags,
4842 default_coff_asm_named_section (name, flags, decl);
4844 if (flags & SECTION_LINKONCE)
4846 /* Functions may have been compiled at various levels of
4847 optimization so we can't use `same_size' here.
4848 Instead, have the linker pick one. */
4849 fprintf (asm_out_file, "\t.linkonce %s\n",
4850 (flags & SECTION_CODE ? "discard" : "same_size"));
4854 /* The lame default section selector. */
4857 default_select_section (tree decl, int reloc,
4858 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4860 bool readonly = false;
4864 if (decl_readonly_section (decl, reloc))
4867 else if (TREE_CODE (decl) == CONSTRUCTOR)
4869 if (! ((flag_pic && reloc)
4870 || !TREE_READONLY (decl)
4871 || TREE_SIDE_EFFECTS (decl)
4872 || !TREE_CONSTANT (decl)))
4875 else if (TREE_CODE (decl) == STRING_CST)
4877 else if (! (flag_pic && reloc))
4881 readonly_data_section ();
4886 /* A helper function for default_elf_select_section and
4887 default_elf_unique_section. Categorizes the DECL. */
4889 enum section_category
4894 SECCAT_RODATA_MERGE_STR,
4895 SECCAT_RODATA_MERGE_STR_INIT,
4896 SECCAT_RODATA_MERGE_CONST,
4901 /* To optimize loading of shared programs, define following subsections
4903 _REL Contains data that has relocations, so they get grouped
4904 together and dynamic linker will visit fewer pages in memory.
4905 _RO Contains data that is otherwise read-only. This is useful
4906 with prelinking as most relocations won't be dynamically
4907 linked and thus stay read only.
4908 _LOCAL Marks data containing relocations only to local objects.
4909 These relocations will get fully resolved by prelinking. */
4911 SECCAT_DATA_REL_LOCAL,
4913 SECCAT_DATA_REL_RO_LOCAL,
4923 static enum section_category
4924 categorize_decl_for_section (tree, int, int);
4926 static enum section_category
4927 categorize_decl_for_section (tree decl, int reloc, int shlib)
4929 enum section_category ret;
4931 if (TREE_CODE (decl) == FUNCTION_DECL)
4933 else if (TREE_CODE (decl) == STRING_CST)
4935 if (flag_mudflap) /* or !flag_merge_constants */
4936 return SECCAT_RODATA;
4938 return SECCAT_RODATA_MERGE_STR;
4940 else if (TREE_CODE (decl) == VAR_DECL)
4942 if (DECL_INITIAL (decl) == NULL
4943 || DECL_INITIAL (decl) == error_mark_node
4944 || (flag_zero_initialized_in_bss
4945 /* Leave constant zeroes in .rodata so they can be shared. */
4946 && !TREE_READONLY (decl)
4947 && initializer_zerop (DECL_INITIAL (decl))))
4949 else if (! TREE_READONLY (decl)
4950 || TREE_SIDE_EFFECTS (decl)
4951 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
4953 if (shlib && (reloc & 2))
4954 ret = SECCAT_DATA_REL;
4955 else if (shlib && reloc)
4956 ret = SECCAT_DATA_REL_LOCAL;
4960 else if (shlib && (reloc & 2))
4961 ret = SECCAT_DATA_REL_RO;
4962 else if (shlib && reloc)
4963 ret = SECCAT_DATA_REL_RO_LOCAL;
4964 else if (reloc || flag_merge_constants < 2)
4965 /* C and C++ don't allow different variables to share the same
4966 location. -fmerge-all-constants allows even that (at the
4967 expense of not conforming). */
4968 ret = SECCAT_RODATA;
4969 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
4970 ret = SECCAT_RODATA_MERGE_STR_INIT;
4972 ret = SECCAT_RODATA_MERGE_CONST;
4974 else if (TREE_CODE (decl) == CONSTRUCTOR)
4976 if ((shlib && reloc)
4977 || TREE_SIDE_EFFECTS (decl)
4978 || ! TREE_CONSTANT (decl))
4981 ret = SECCAT_RODATA;
4984 ret = SECCAT_RODATA;
4986 /* There are no read-only thread-local sections. */
4987 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4989 /* Note that this would be *just* SECCAT_BSS, except that there's
4990 no concept of a read-only thread-local-data section. */
4991 if (ret == SECCAT_BSS
4992 || (flag_zero_initialized_in_bss
4993 && initializer_zerop (DECL_INITIAL (decl))))
4999 /* If the target uses small data sections, select it. */
5000 else if (targetm.in_small_data_p (decl))
5002 if (ret == SECCAT_BSS)
5004 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
5005 ret = SECCAT_SRODATA;
5014 decl_readonly_section (tree decl, int reloc)
5016 return decl_readonly_section_1 (decl, reloc, flag_pic);
5020 decl_readonly_section_1 (tree decl, int reloc, int shlib)
5022 switch (categorize_decl_for_section (decl, reloc, shlib))
5025 case SECCAT_RODATA_MERGE_STR:
5026 case SECCAT_RODATA_MERGE_STR_INIT:
5027 case SECCAT_RODATA_MERGE_CONST:
5028 case SECCAT_SRODATA:
5037 /* Select a section based on the above categorization. */
5040 default_elf_select_section (tree decl, int reloc,
5041 unsigned HOST_WIDE_INT align)
5043 default_elf_select_section_1 (decl, reloc, align, flag_pic);
5047 default_elf_select_section_1 (tree decl, int reloc,
5048 unsigned HOST_WIDE_INT align, int shlib)
5051 switch (categorize_decl_for_section (decl, reloc, shlib))
5054 /* We're not supposed to be called on FUNCTION_DECLs. */
5057 readonly_data_section ();
5059 case SECCAT_RODATA_MERGE_STR:
5060 mergeable_string_section (decl, align, 0);
5062 case SECCAT_RODATA_MERGE_STR_INIT:
5063 mergeable_string_section (DECL_INITIAL (decl), align, 0);
5065 case SECCAT_RODATA_MERGE_CONST:
5066 mergeable_constant_section (DECL_MODE (decl), align, 0);
5068 case SECCAT_SRODATA:
5074 case SECCAT_DATA_REL:
5075 sname = ".data.rel";
5077 case SECCAT_DATA_REL_LOCAL:
5078 sname = ".data.rel.local";
5080 case SECCAT_DATA_REL_RO:
5081 sname = ".data.rel.ro";
5083 case SECCAT_DATA_REL_RO_LOCAL:
5084 sname = ".data.rel.ro.local";
5093 #ifdef BSS_SECTION_ASM_OP
5112 named_section (decl, sname, reloc);
5115 /* Construct a unique section name based on the decl name and the
5116 categorization performed above. */
5119 default_unique_section (tree decl, int reloc)
5121 default_unique_section_1 (decl, reloc, flag_pic);
5125 default_unique_section_1 (tree decl, int reloc, int shlib)
5127 bool one_only = DECL_ONE_ONLY (decl);
5128 const char *prefix, *name;
5132 switch (categorize_decl_for_section (decl, reloc, shlib))
5135 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
5138 case SECCAT_RODATA_MERGE_STR:
5139 case SECCAT_RODATA_MERGE_STR_INIT:
5140 case SECCAT_RODATA_MERGE_CONST:
5141 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
5143 case SECCAT_SRODATA:
5144 prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
5147 case SECCAT_DATA_REL:
5148 case SECCAT_DATA_REL_LOCAL:
5149 case SECCAT_DATA_REL_RO:
5150 case SECCAT_DATA_REL_RO_LOCAL:
5151 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
5154 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
5157 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
5160 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
5163 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
5166 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
5171 plen = strlen (prefix);
5173 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5174 name = targetm.strip_name_encoding (name);
5175 nlen = strlen (name);
5177 string = alloca (nlen + plen + 1);
5178 memcpy (string, prefix, plen);
5179 memcpy (string + plen, name, nlen + 1);
5181 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
5185 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
5187 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5190 switch (GET_CODE (x))
5202 readonly_data_section ();
5206 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
5207 unsigned HOST_WIDE_INT align)
5209 /* ??? Handle small data here somehow. */
5212 switch (GET_CODE (x))
5216 named_section (NULL_TREE, ".data.rel.ro", 3);
5220 named_section (NULL_TREE, ".data.rel.ro.local", 1);
5227 mergeable_constant_section (mode, align, 0);
5230 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5233 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
5238 /* Careful not to prod global register variables. */
5241 symbol = XEXP (rtl, 0);
5242 if (GET_CODE (symbol) != SYMBOL_REF)
5246 if (TREE_CODE (decl) == FUNCTION_DECL)
5247 flags |= SYMBOL_FLAG_FUNCTION;
5248 if (targetm.binds_local_p (decl))
5249 flags |= SYMBOL_FLAG_LOCAL;
5250 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
5251 flags |= decl_tls_model (decl) << SYMBOL_FLAG_TLS_SHIFT;
5252 else if (targetm.in_small_data_p (decl))
5253 flags |= SYMBOL_FLAG_SMALL;
5254 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5255 being PUBLIC, the thing *must* be defined in this translation unit.
5256 Prevent this buglet from being propagated into rtl code as well. */
5257 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
5258 flags |= SYMBOL_FLAG_EXTERNAL;
5260 SYMBOL_REF_FLAGS (symbol) = flags;
5263 /* By default, we do nothing for encode_section_info, so we need not
5264 do anything but discard the '*' marker. */
5267 default_strip_name_encoding (const char *str)
5269 return str + (*str == '*');
5272 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5273 wrt cross-module name binding. */
5276 default_binds_local_p (tree exp)
5278 return default_binds_local_p_1 (exp, flag_shlib);
5282 default_binds_local_p_1 (tree exp, int shlib)
5286 /* A non-decl is an entry in the constant pool. */
5289 /* Static variables are always local. */
5290 else if (! TREE_PUBLIC (exp))
5292 /* A variable is local if the user explicitly tells us so. */
5293 else if (DECL_VISIBILITY_SPECIFIED (exp) && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5295 /* Otherwise, variables defined outside this object may not be local. */
5296 else if (DECL_EXTERNAL (exp))
5298 /* Linkonce and weak data are never local. */
5299 else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
5301 /* If none of the above and visibility is not default, make local. */
5302 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5304 /* If PIC, then assume that any global name can be overridden by
5305 symbols resolved from other modules. */
5308 /* Uninitialized COMMON variable may be unified with symbols
5309 resolved from other modules. */
5310 else if (DECL_COMMON (exp)
5311 && (DECL_INITIAL (exp) == NULL
5312 || DECL_INITIAL (exp) == error_mark_node))
5314 /* Otherwise we're left with initialized (or non-common) global data
5315 which is of necessity defined locally. */
5322 /* Determine whether or not a pointer mode is valid. Assume defaults
5323 of ptr_mode or Pmode - can be overridden. */
5325 default_valid_pointer_mode (enum machine_mode mode)
5327 return (mode == ptr_mode || mode == Pmode);
5330 /* Default function to output code that will globalize a label. A
5331 target must define GLOBAL_ASM_OP or provide it's own function to
5332 globalize a label. */
5333 #ifdef GLOBAL_ASM_OP
5335 default_globalize_label (FILE * stream, const char *name)
5337 fputs (GLOBAL_ASM_OP, stream);
5338 assemble_name (stream, name);
5339 putc ('\n', stream);
5341 #endif /* GLOBAL_ASM_OP */
5343 /* Default function to output a label for unwind information. The
5344 default is to do nothing. A target that needs nonlocal labels for
5345 unwind information must provide its own function to do this. */
5347 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
5348 tree decl ATTRIBUTE_UNUSED,
5349 int for_eh ATTRIBUTE_UNUSED,
5350 int empty ATTRIBUTE_UNUSED)
5354 /* This is how to output an internal numbered label where PREFIX is
5355 the class of label and LABELNO is the number within the class. */
5358 default_internal_label (FILE *stream, const char *prefix,
5359 unsigned long labelno)
5361 char *const buf = alloca (40 + strlen (prefix));
5362 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
5363 ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
5366 /* This is the default behavior at the beginning of a file. It's
5367 controlled by two other target-hook toggles. */
5369 default_file_start (void)
5371 if (targetm.file_start_app_off && !flag_verbose_asm)
5372 fputs (ASM_APP_OFF, asm_out_file);
5374 if (targetm.file_start_file_directive)
5375 output_file_directive (asm_out_file, main_input_filename);
5378 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5379 which emits a special section directive used to indicate whether or
5380 not this object file needs an executable stack. This is primarily
5381 a GNU extension to ELF but could be used on other targets. */
5383 int trampolines_created;
5386 file_end_indicate_exec_stack (void)
5388 unsigned int flags = SECTION_DEBUG;
5389 if (trampolines_created)
5390 flags |= SECTION_CODE;
5392 named_section_flags (".note.GNU-stack", flags);
5395 #include "gt-varasm.h"