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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
47 #include "langhooks.h"
52 #include "cfglayout.h"
54 #ifdef XCOFF_DEBUGGING_INFO
55 #include "xcoffout.h" /* Needed for external data
56 declarations for e.g. AIX 4.x. */
59 #ifndef TRAMPOLINE_ALIGNMENT
60 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
64 #define ASM_STABS_OP "\t.stabs\t"
67 /* The (assembler) name of the first globally-visible object output. */
68 const char *first_global_object_name;
69 const char *weak_global_object_name;
72 struct constant_descriptor_rtx;
73 struct rtx_constant_pool;
75 struct varasm_status GTY(())
77 /* If we're using a per-function constant pool, this is it. */
78 struct rtx_constant_pool *pool;
80 /* Number of tree-constants deferred during the expansion of this
82 unsigned int deferred_constants;
85 #define n_deferred_constants (cfun->varasm->deferred_constants)
87 /* Number for making the label on the next
88 constant that is stored in memory. */
90 static GTY(()) int const_labelno;
92 /* Carry information from ASM_DECLARE_OBJECT_NAME
93 to ASM_FINISH_DECLARE_OBJECT. */
95 int size_directive_output;
97 /* The last decl for which assemble_variable was called,
98 if it did ASM_DECLARE_OBJECT_NAME.
99 If the last call to assemble_variable didn't do that,
102 tree last_assemble_variable_decl;
104 /* The following global variable indicates if the section label for the
105 "cold" section of code has been output yet to the assembler. The
106 label is useful when running gdb. This is part of the optimization that
107 partitions hot and cold basic blocks into separate sections of the .o
110 bool unlikely_section_label_printed = false;
112 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
113 So giving constant the alias set for the type will allow such
114 initializations to appear to conflict with the load of the constant. We
115 avoid this by giving all constants an alias set for just constants.
116 Since there will be no stores to that alias set, nothing will ever
117 conflict with them. */
119 static HOST_WIDE_INT const_alias_set;
121 static const char *strip_reg_name (const char *);
122 static int contains_pointers_p (tree);
123 #ifdef ASM_OUTPUT_EXTERNAL
124 static bool incorporeal_function_p (tree);
126 static void decode_addr_const (tree, struct addr_const *);
127 static hashval_t const_desc_hash (const void *);
128 static int const_desc_eq (const void *, const void *);
129 static hashval_t const_hash_1 (const tree);
130 static int compare_constant (const tree, const tree);
131 static tree copy_constant (tree);
132 static void output_constant_def_contents (rtx);
133 static void output_addressed_constants (tree);
134 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
135 static unsigned min_align (unsigned, unsigned);
136 static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int);
137 static void globalize_decl (tree);
138 static void maybe_assemble_visibility (tree);
139 static int in_named_entry_eq (const void *, const void *);
140 static hashval_t in_named_entry_hash (const void *);
141 #ifdef ASM_OUTPUT_BSS
142 static void asm_output_bss (FILE *, tree, const char *,
143 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
145 #ifdef BSS_SECTION_ASM_OP
146 #ifdef ASM_OUTPUT_ALIGNED_BSS
147 static void asm_output_aligned_bss (FILE *, tree, const char *,
148 unsigned HOST_WIDE_INT, int)
151 #endif /* BSS_SECTION_ASM_OP */
152 static bool asm_emit_uninitialised (tree, const char*,
153 unsigned HOST_WIDE_INT,
154 unsigned HOST_WIDE_INT);
155 static void mark_weak (tree);
157 enum in_section { no_section, in_text, in_unlikely_executed_text, in_data,
159 #ifdef BSS_SECTION_ASM_OP
162 #ifdef CTORS_SECTION_ASM_OP
165 #ifdef DTORS_SECTION_ASM_OP
168 #ifdef READONLY_DATA_SECTION_ASM_OP
171 #ifdef EXTRA_SECTIONS
175 static GTY(()) enum in_section in_section = no_section;
177 /* Return a nonzero value if DECL has a section attribute. */
178 #ifndef IN_NAMED_SECTION
179 #define IN_NAMED_SECTION(DECL) \
180 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
181 && DECL_SECTION_NAME (DECL) != NULL_TREE)
184 /* Text of section name when in_section == in_named. */
185 static GTY(()) const char *in_named_name;
187 /* Hash table of flags that have been used for a particular named section. */
189 struct in_named_entry GTY(())
196 static GTY((param_is (struct in_named_entry))) htab_t in_named_htab;
198 /* Define functions like text_section for any extra sections. */
199 #ifdef EXTRA_SECTION_FUNCTIONS
200 EXTRA_SECTION_FUNCTIONS
203 /* Tell assembler to switch to text section. */
208 if (in_section != in_text)
210 in_section = in_text;
211 fprintf (asm_out_file, SECTION_FORMAT_STRING, NORMAL_TEXT_SECTION_NAME);
215 /* Tell assembler to switch to unlikely-to-be-executed text section. */
218 unlikely_text_section (void)
220 if ((in_section != in_unlikely_executed_text)
221 && (in_section != in_named
222 || strcmp (in_named_name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) != 0))
224 #ifdef TARGET_ASM_NAMED_SECTION
226 named_section (NULL_TREE, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
229 in_section = in_unlikely_executed_text;
230 fprintf (asm_out_file, SECTION_FORMAT_STRING,
231 UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
232 #endif /* ifdef TARGET_ASM_NAMED_SECTION */
233 if (!unlikely_section_label_printed)
235 fprintf (asm_out_file, "__%s_unlikely_section:\n",
236 current_function_name ());
237 unlikely_section_label_printed = true;
242 /* Tell assembler to switch to data section. */
247 if (in_section != in_data)
249 in_section = in_data;
250 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
254 /* Tell assembler to switch to read-only data section. This is normally
258 readonly_data_section (void)
260 #ifdef READONLY_DATA_SECTION
261 READONLY_DATA_SECTION (); /* Note this can call data_section. */
263 #ifdef READONLY_DATA_SECTION_ASM_OP
264 if (in_section != in_readonly_data)
266 in_section = in_readonly_data;
267 fputs (READONLY_DATA_SECTION_ASM_OP, asm_out_file);
268 fputc ('\n', asm_out_file);
276 /* Determine if we're in the text section. */
279 in_text_section (void)
281 return in_section == in_text;
284 /* Determine if we're in the unlikely-to-be-executed text section. */
287 in_unlikely_text_section (void)
289 return in_section == in_unlikely_executed_text;
292 /* Determine if we're in the data section. */
295 in_data_section (void)
297 return in_section == in_data;
300 /* Helper routines for maintaining in_named_htab. */
303 in_named_entry_eq (const void *p1, const void *p2)
305 const struct in_named_entry *old = p1;
306 const char *new = p2;
308 return strcmp (old->name, new) == 0;
312 in_named_entry_hash (const void *p)
314 const struct in_named_entry *old = p;
315 return htab_hash_string (old->name);
318 /* If SECTION has been seen before as a named section, return the flags
319 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
320 set of flags for a section to have, so 0 does not mean that the section
321 has not been seen. */
324 get_named_section_flags (const char *section)
326 struct in_named_entry **slot;
328 slot = (struct in_named_entry **)
329 htab_find_slot_with_hash (in_named_htab, section,
330 htab_hash_string (section), NO_INSERT);
332 return slot ? (*slot)->flags : 0;
335 /* Returns true if the section has been declared before. Sets internal
336 flag on this section in in_named_hash so subsequent calls on this
337 section will return false. */
340 named_section_first_declaration (const char *name)
342 struct in_named_entry **slot;
344 slot = (struct in_named_entry **)
345 htab_find_slot_with_hash (in_named_htab, name,
346 htab_hash_string (name), NO_INSERT);
347 if (! (*slot)->declared)
349 (*slot)->declared = true;
359 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
360 different set of flags, return false. */
363 set_named_section_flags (const char *section, unsigned int flags)
365 struct in_named_entry **slot, *entry;
367 slot = (struct in_named_entry **)
368 htab_find_slot_with_hash (in_named_htab, section,
369 htab_hash_string (section), INSERT);
374 entry = ggc_alloc (sizeof (*entry));
376 entry->name = ggc_strdup (section);
377 entry->flags = flags;
378 entry->declared = false;
380 else if (entry->flags != flags)
386 /* Tell assembler to change to section NAME with attributes FLAGS. */
389 named_section_flags (const char *name, unsigned int flags)
391 if (in_section != in_named || strcmp (name, in_named_name) != 0)
393 if (! set_named_section_flags (name, flags))
396 targetm.asm_out.named_section (name, flags);
398 if (flags & SECTION_FORGET)
399 in_section = no_section;
402 in_named_name = ggc_strdup (name);
403 in_section = in_named;
408 /* Tell assembler to change to section NAME for DECL.
409 If DECL is NULL, just switch to section NAME.
410 If NAME is NULL, get the name from DECL.
411 If RELOC is 1, the initializer for DECL contains relocs. */
414 named_section (tree decl, const char *name, int reloc)
418 if (decl != NULL_TREE && !DECL_P (decl))
421 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
423 flags = targetm.section_type_flags (decl, name, reloc);
425 /* Sanity check user variables for flag changes. Non-user
426 section flag changes will abort in named_section_flags.
427 However, don't complain if SECTION_OVERRIDE is set.
428 We trust that the setter knows that it is safe to ignore
429 the default flags for this decl. */
430 if (decl && ! set_named_section_flags (name, flags))
432 flags = get_named_section_flags (name);
433 if ((flags & SECTION_OVERRIDE) == 0)
434 error ("%J%D causes a section type conflict", decl, decl);
437 named_section_flags (name, flags);
440 /* If required, set DECL_SECTION_NAME to a unique name. */
443 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
444 int flag_function_or_data_sections)
446 if (DECL_SECTION_NAME (decl) == NULL_TREE
447 && targetm.have_named_sections
448 && (flag_function_or_data_sections
449 || DECL_ONE_ONLY (decl)))
450 targetm.asm_out.unique_section (decl, reloc);
453 #ifdef BSS_SECTION_ASM_OP
455 /* Tell the assembler to switch to the bss section. */
460 if (in_section != in_bss)
462 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
467 #ifdef ASM_OUTPUT_BSS
469 /* Utility function for ASM_OUTPUT_BSS for targets to use if
470 they don't support alignments in .bss.
471 ??? It is believed that this function will work in most cases so such
472 support is localized here. */
475 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
477 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
478 unsigned HOST_WIDE_INT rounded)
480 targetm.asm_out.globalize_label (file, name);
482 #ifdef ASM_DECLARE_OBJECT_NAME
483 last_assemble_variable_decl = decl;
484 ASM_DECLARE_OBJECT_NAME (file, name, decl);
486 /* Standard thing is just output label for the object. */
487 ASM_OUTPUT_LABEL (file, name);
488 #endif /* ASM_DECLARE_OBJECT_NAME */
489 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
494 #ifdef ASM_OUTPUT_ALIGNED_BSS
496 /* Utility function for targets to use in implementing
497 ASM_OUTPUT_ALIGNED_BSS.
498 ??? It is believed that this function will work in most cases so such
499 support is localized here. */
502 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
503 const char *name, unsigned HOST_WIDE_INT size,
507 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
508 #ifdef ASM_DECLARE_OBJECT_NAME
509 last_assemble_variable_decl = decl;
510 ASM_DECLARE_OBJECT_NAME (file, name, decl);
512 /* Standard thing is just output label for the object. */
513 ASM_OUTPUT_LABEL (file, name);
514 #endif /* ASM_DECLARE_OBJECT_NAME */
515 ASM_OUTPUT_SKIP (file, size ? size : 1);
520 #endif /* BSS_SECTION_ASM_OP */
522 /* Switch to the section for function DECL.
524 If DECL is NULL_TREE, switch to the text section.
525 ??? It's not clear that we will ever be passed NULL_TREE, but it's
526 safer to handle it. */
529 function_section (tree decl)
531 if (scan_ahead_for_unlikely_executed_note (get_insns()))
532 unlikely_text_section ();
535 if (decl != NULL_TREE
536 && DECL_SECTION_NAME (decl) != NULL_TREE)
537 named_section (decl, (char *) 0, 0);
543 /* Switch to section for variable DECL. RELOC is the same as the
544 argument to SELECT_SECTION. */
547 variable_section (tree decl, int reloc)
549 if (IN_NAMED_SECTION (decl))
550 named_section (decl, NULL, reloc);
552 targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
555 /* Tell assembler to switch to the section for string merging. */
558 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
559 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
560 unsigned int flags ATTRIBUTE_UNUSED)
562 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
563 && TREE_CODE (decl) == STRING_CST
564 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
566 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
568 enum machine_mode mode;
569 unsigned int modesize;
574 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
575 modesize = GET_MODE_BITSIZE (mode);
576 if (modesize >= 8 && modesize <= 256
577 && (modesize & (modesize - 1)) == 0)
579 if (align < modesize)
582 str = TREE_STRING_POINTER (decl);
583 len = TREE_STRING_LENGTH (decl);
584 unit = GET_MODE_SIZE (mode);
586 /* Check for embedded NUL characters. */
587 for (i = 0; i < len; i += unit)
589 for (j = 0; j < unit; j++)
590 if (str[i + j] != '\0')
597 sprintf (name, ".rodata.str%d.%d", modesize / 8,
599 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
600 if (!i && modesize < align)
602 /* A "" string with requested alignment greater than
603 character size might cause a problem:
604 if some other string required even bigger
605 alignment than "", then linker might think the
606 "" is just part of padding after some other string
607 and not put it into the hash table initially.
608 But this means "" could have smaller alignment
610 #ifdef ASM_OUTPUT_SECTION_START
611 named_section_flags (name, flags);
612 ASM_OUTPUT_SECTION_START (asm_out_file);
614 readonly_data_section ();
619 named_section_flags (name, flags);
625 readonly_data_section ();
628 /* Tell assembler to switch to the section for constant merging. */
631 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
632 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
633 unsigned int flags ATTRIBUTE_UNUSED)
635 unsigned int modesize = GET_MODE_BITSIZE (mode);
637 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
643 && (align & (align - 1)) == 0)
647 sprintf (name, ".rodata.cst%d", (int) (align / 8));
648 flags |= (align / 8) | SECTION_MERGE;
649 named_section_flags (name, flags);
653 readonly_data_section ();
656 /* Given NAME, a putative register name, discard any customary prefixes. */
659 strip_reg_name (const char *name)
661 #ifdef REGISTER_PREFIX
662 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
663 name += strlen (REGISTER_PREFIX);
665 if (name[0] == '%' || name[0] == '#')
670 /* Decode an `asm' spec for a declaration as a register name.
671 Return the register number, or -1 if nothing specified,
672 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
673 or -3 if ASMSPEC is `cc' and is not recognized,
674 or -4 if ASMSPEC is `memory' and is not recognized.
675 Accept an exact spelling or a decimal number.
676 Prefixes such as % are optional. */
679 decode_reg_name (const char *asmspec)
685 /* Get rid of confusing prefixes. */
686 asmspec = strip_reg_name (asmspec);
688 /* Allow a decimal number as a "register name". */
689 for (i = strlen (asmspec) - 1; i >= 0; i--)
690 if (! ISDIGIT (asmspec[i]))
692 if (asmspec[0] != 0 && i < 0)
695 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
701 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
703 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
706 #ifdef ADDITIONAL_REGISTER_NAMES
708 static const struct { const char *const name; const int number; } table[]
709 = ADDITIONAL_REGISTER_NAMES;
711 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
712 if (! strcmp (asmspec, table[i].name))
713 return table[i].number;
715 #endif /* ADDITIONAL_REGISTER_NAMES */
717 if (!strcmp (asmspec, "memory"))
720 if (!strcmp (asmspec, "cc"))
729 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
730 have static storage duration. In other words, it should not be an
731 automatic variable, including PARM_DECLs.
733 There is, however, one exception: this function handles variables
734 explicitly placed in a particular register by the user.
736 ASMSPEC, if not 0, is the string which the user specified as the
737 assembler symbol name.
739 This is never called for PARM_DECL nodes. */
742 make_decl_rtl (tree decl, const char *asmspec)
744 const char *name = 0;
748 /* Check that we are not being given an automatic variable. */
749 /* A weak alias has TREE_PUBLIC set but not the other bits. */
750 if (TREE_CODE (decl) == PARM_DECL
751 || TREE_CODE (decl) == RESULT_DECL
752 || (TREE_CODE (decl) == VAR_DECL
753 && !TREE_STATIC (decl)
754 && !TREE_PUBLIC (decl)
755 && !DECL_EXTERNAL (decl)
756 && !DECL_REGISTER (decl)))
758 /* And that we were not given a type or a label. */
759 else if (TREE_CODE (decl) == TYPE_DECL
760 || TREE_CODE (decl) == LABEL_DECL)
763 /* For a duplicate declaration, we can be called twice on the
764 same DECL node. Don't discard the RTL already made. */
765 if (DECL_RTL_SET_P (decl))
767 /* If the old RTL had the wrong mode, fix the mode. */
768 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
769 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
770 DECL_MODE (decl), 0));
772 /* ??? Another way to do this would be to maintain a hashed
773 table of such critters. Instead of adding stuff to a DECL
774 to give certain attributes to it, we could use an external
775 hash map from DECL to set of attributes. */
777 /* Let the target reassign the RTL if it wants.
778 This is necessary, for example, when one machine specific
779 decl attribute overrides another. */
780 targetm.encode_section_info (decl, DECL_RTL (decl), false);
784 reg_number = decode_reg_name (asmspec);
785 if (reg_number == -2)
787 /* ASMSPEC is given, and not the name of a register. Mark the
788 name with a star so assemble_name won't munge it. */
789 char *starred = alloca (strlen (asmspec) + 2);
791 strcpy (starred + 1, asmspec);
792 change_decl_assembler_name (decl, get_identifier (starred));
795 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
797 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
799 /* First detect errors in declaring global registers. */
800 if (reg_number == -1)
801 error ("%Jregister name not specified for '%D'", decl, decl);
802 else if (reg_number < 0)
803 error ("%Jinvalid register name for '%D'", decl, decl);
804 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
805 error ("%Jdata type of '%D' isn't suitable for a register",
807 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
808 error ("%Jregister specified for '%D' isn't suitable for data type",
810 /* Now handle properly declared static register variables. */
815 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
817 DECL_INITIAL (decl) = 0;
818 error ("global register variable has initial value");
820 if (TREE_THIS_VOLATILE (decl))
821 warning ("volatile register variables don't work as you might wish");
823 /* If the user specified one of the eliminables registers here,
824 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
825 confused with that register and be eliminated. This usage is
826 somewhat suspect... */
828 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
829 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
830 REG_USERVAR_P (DECL_RTL (decl)) = 1;
832 if (TREE_STATIC (decl))
834 /* Make this register global, so not usable for anything
836 #ifdef ASM_DECLARE_REGISTER_GLOBAL
837 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
839 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
841 globalize_reg (reg_number + --nregs);
844 /* As a register variable, it has no section. */
849 /* Now handle ordinary static variables and functions (in memory).
850 Also handle vars declared register invalidly. */
852 if (reg_number >= 0 || reg_number == -3)
853 error ("%Jregister name given for non-register variable '%D'", decl, decl);
855 /* Specifying a section attribute on a variable forces it into a
856 non-.bss section, and thus it cannot be common. */
857 if (TREE_CODE (decl) == VAR_DECL
858 && DECL_SECTION_NAME (decl) != NULL_TREE
859 && DECL_INITIAL (decl) == NULL_TREE
860 && DECL_COMMON (decl))
861 DECL_COMMON (decl) = 0;
863 /* Variables can't be both common and weak. */
864 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
865 DECL_COMMON (decl) = 0;
867 x = gen_rtx_SYMBOL_REF (Pmode, name);
868 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
869 SYMBOL_REF_DECL (x) = decl;
871 x = gen_rtx_MEM (DECL_MODE (decl), x);
872 if (TREE_CODE (decl) != FUNCTION_DECL)
873 set_mem_attributes (x, decl, 1);
874 SET_DECL_RTL (decl, x);
876 /* Optionally set flags or add text to the name to record information
877 such as that it is a function name.
878 If the name is changed, the macro ASM_OUTPUT_LABELREF
879 will have to know how to strip this information. */
880 targetm.encode_section_info (decl, DECL_RTL (decl), true);
883 /* Make the rtl for variable VAR be volatile.
884 Use this only for static variables. */
887 make_var_volatile (tree var)
889 if (GET_CODE (DECL_RTL (var)) != MEM)
892 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
895 /* Output a string of literal assembler code
896 for an `asm' keyword used between functions. */
899 assemble_asm (tree string)
903 if (TREE_CODE (string) == ADDR_EXPR)
904 string = TREE_OPERAND (string, 0);
906 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
909 /* Record an element in the table of global destructors. SYMBOL is
910 a SYMBOL_REF of the function to be called; PRIORITY is a number
911 between 0 and MAX_INIT_PRIORITY. */
914 default_stabs_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
916 /* Tell GNU LD that this is part of the static destructor set.
917 This will work for any system that uses stabs, most usefully
919 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
920 assemble_name (asm_out_file, XSTR (symbol, 0));
921 fputc ('\n', asm_out_file);
925 default_named_section_asm_out_destructor (rtx symbol, int priority)
927 const char *section = ".dtors";
930 /* ??? This only works reliably with the GNU linker. */
931 if (priority != DEFAULT_INIT_PRIORITY)
933 sprintf (buf, ".dtors.%.5u",
934 /* Invert the numbering so the linker puts us in the proper
935 order; constructors are run from right to left, and the
936 linker sorts in increasing order. */
937 MAX_INIT_PRIORITY - priority);
941 named_section_flags (section, SECTION_WRITE);
942 assemble_align (POINTER_SIZE);
943 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
946 #ifdef DTORS_SECTION_ASM_OP
950 if (in_section != in_dtors)
952 in_section = in_dtors;
953 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
954 fputc ('\n', asm_out_file);
959 default_dtor_section_asm_out_destructor (rtx symbol,
960 int priority ATTRIBUTE_UNUSED)
963 assemble_align (POINTER_SIZE);
964 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
968 /* Likewise for global constructors. */
971 default_stabs_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
973 /* Tell GNU LD that this is part of the static destructor set.
974 This will work for any system that uses stabs, most usefully
976 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
977 assemble_name (asm_out_file, XSTR (symbol, 0));
978 fputc ('\n', asm_out_file);
982 default_named_section_asm_out_constructor (rtx symbol, int priority)
984 const char *section = ".ctors";
987 /* ??? This only works reliably with the GNU linker. */
988 if (priority != DEFAULT_INIT_PRIORITY)
990 sprintf (buf, ".ctors.%.5u",
991 /* Invert the numbering so the linker puts us in the proper
992 order; constructors are run from right to left, and the
993 linker sorts in increasing order. */
994 MAX_INIT_PRIORITY - priority);
998 named_section_flags (section, SECTION_WRITE);
999 assemble_align (POINTER_SIZE);
1000 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1003 #ifdef CTORS_SECTION_ASM_OP
1005 ctors_section (void)
1007 if (in_section != in_ctors)
1009 in_section = in_ctors;
1010 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1011 fputc ('\n', asm_out_file);
1016 default_ctor_section_asm_out_constructor (rtx symbol,
1017 int priority ATTRIBUTE_UNUSED)
1020 assemble_align (POINTER_SIZE);
1021 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1025 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1026 a nonzero value if the constant pool should be output before the
1027 start of the function, or a zero value if the pool should output
1028 after the end of the function. The default is to put it before the
1031 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1032 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1035 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1036 to be output to assembler.
1037 Set first_global_object_name and weak_global_object_name as appropriate. */
1040 notice_global_symbol (tree decl)
1042 const char **type = &first_global_object_name;
1044 if (first_global_object_name
1045 || !TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
1046 || !DECL_NAME (decl)
1047 || (TREE_CODE (decl) != FUNCTION_DECL
1048 && (TREE_CODE (decl) != VAR_DECL
1049 || (DECL_COMMON (decl)
1050 && (DECL_INITIAL (decl) == 0
1051 || DECL_INITIAL (decl) == error_mark_node))))
1052 || GET_CODE (DECL_RTL (decl)) != MEM)
1055 /* We win when global object is found, but it is useful to know about weak
1056 symbol as well so we can produce nicer unique names. */
1057 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl))
1058 type = &weak_global_object_name;
1064 rtx decl_rtl = DECL_RTL (decl);
1066 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1073 /* Output assembler code for the constant pool of a function and associated
1074 with defining the name of the function. DECL describes the function.
1075 NAME is the function's name. For the constant pool, we use the current
1076 constant pool data. */
1079 assemble_start_function (tree decl, const char *fnname)
1083 unlikely_section_label_printed = false;
1085 /* The following code does not need preprocessing in the assembler. */
1089 if (CONSTANT_POOL_BEFORE_FUNCTION)
1090 output_constant_pool (fnname, decl);
1092 resolve_unique_section (decl, 0, flag_function_sections);
1093 function_section (decl);
1095 /* Tell assembler to move to target machine's alignment for functions. */
1096 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1097 if (align < force_align_functions_log)
1098 align = force_align_functions_log;
1101 ASM_OUTPUT_ALIGN (asm_out_file, align);
1104 /* Handle a user-specified function alignment.
1105 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1106 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1107 if (align_functions_log > align
1108 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1110 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1111 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1112 align_functions_log, align_functions - 1);
1114 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1118 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1119 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1122 (*debug_hooks->begin_function) (decl);
1124 /* Make function name accessible from other files, if appropriate. */
1126 if (TREE_PUBLIC (decl))
1128 notice_global_symbol (decl);
1130 globalize_decl (decl);
1132 maybe_assemble_visibility (decl);
1135 /* Do any machine/system dependent processing of the function name. */
1136 #ifdef ASM_DECLARE_FUNCTION_NAME
1137 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1139 /* Standard thing is just output label for the function. */
1140 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1141 #endif /* ASM_DECLARE_FUNCTION_NAME */
1144 /* Output assembler code associated with defining the size of the
1145 function. DECL describes the function. NAME is the function's name. */
1148 assemble_end_function (tree decl, const char *fnname)
1150 #ifdef ASM_DECLARE_FUNCTION_SIZE
1151 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1153 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1155 output_constant_pool (fnname, decl);
1156 function_section (decl); /* need to switch back */
1160 /* Assemble code to leave SIZE bytes of zeros. */
1163 assemble_zeros (unsigned HOST_WIDE_INT size)
1165 /* Do no output if -fsyntax-only. */
1166 if (flag_syntax_only)
1169 #ifdef ASM_NO_SKIP_IN_TEXT
1170 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1171 so we must output 0s explicitly in the text section. */
1172 if ((ASM_NO_SKIP_IN_TEXT && in_text_section ())
1173 || (ASM_NO_SKIP_IN_TEXT && in_unlikely_text_section ()))
1175 unsigned HOST_WIDE_INT i;
1176 for (i = 0; i < size; i++)
1177 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1182 ASM_OUTPUT_SKIP (asm_out_file, size);
1185 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1188 assemble_align (int align)
1190 if (align > BITS_PER_UNIT)
1192 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1196 /* Assemble a string constant with the specified C string as contents. */
1199 assemble_string (const char *p, int size)
1204 /* If the string is very long, split it up. */
1208 int thissize = size - pos;
1209 if (thissize > maximum)
1212 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1220 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1221 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1222 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1224 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1225 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1226 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1228 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1229 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1233 #if defined ASM_OUTPUT_ALIGNED_BSS
1234 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1235 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1237 #if defined ASM_OUTPUT_BSS
1238 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1239 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1245 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1246 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1247 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1249 #if defined ASM_OUTPUT_ALIGNED_COMMON
1250 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1251 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1253 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1254 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1259 asm_emit_uninitialised (tree decl, const char *name,
1260 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1261 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1269 destination = asm_dest_local;
1271 /* ??? We should handle .bss via select_section mechanisms rather than
1272 via special target hooks. That would eliminate this special case. */
1273 if (TREE_PUBLIC (decl))
1275 if (!DECL_COMMON (decl))
1277 destination = asm_dest_bss;
1282 destination = asm_dest_common;
1285 if (destination == asm_dest_bss)
1286 globalize_decl (decl);
1287 resolve_unique_section (decl, 0, flag_data_sections);
1289 if (flag_shared_data)
1291 switch (destination)
1293 #ifdef ASM_OUTPUT_SHARED_BSS
1295 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1298 #ifdef ASM_OUTPUT_SHARED_COMMON
1299 case asm_dest_common:
1300 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1303 #ifdef ASM_OUTPUT_SHARED_LOCAL
1304 case asm_dest_local:
1305 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1313 switch (destination)
1317 ASM_EMIT_BSS (decl, name, size, rounded);
1320 case asm_dest_common:
1321 ASM_EMIT_COMMON (decl, name, size, rounded);
1323 case asm_dest_local:
1324 ASM_EMIT_LOCAL (decl, name, size, rounded);
1333 /* Assemble everything that is needed for a variable or function declaration.
1334 Not used for automatic variables, and not used for function definitions.
1335 Should not be called for variables of incomplete structure type.
1337 TOP_LEVEL is nonzero if this variable has file scope.
1338 AT_END is nonzero if this is the special handling, at end of compilation,
1339 to define things that have had only tentative definitions.
1340 DONT_OUTPUT_DATA if nonzero means don't actually output the
1341 initial value (that will be done by the caller). */
1344 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1345 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1352 if (lang_hooks.decls.prepare_assemble_variable)
1353 lang_hooks.decls.prepare_assemble_variable (decl);
1355 last_assemble_variable_decl = 0;
1357 /* Normally no need to say anything here for external references,
1358 since assemble_external is called by the language-specific code
1359 when a declaration is first seen. */
1361 if (DECL_EXTERNAL (decl))
1364 /* Output no assembler code for a function declaration.
1365 Only definitions of functions output anything. */
1367 if (TREE_CODE (decl) == FUNCTION_DECL)
1370 /* Do nothing for global register variables. */
1371 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1373 TREE_ASM_WRITTEN (decl) = 1;
1377 /* If type was incomplete when the variable was declared,
1378 see if it is complete now. */
1380 if (DECL_SIZE (decl) == 0)
1381 layout_decl (decl, 0);
1383 /* Still incomplete => don't allocate it; treat the tentative defn
1384 (which is what it must have been) as an `extern' reference. */
1386 if (!dont_output_data && DECL_SIZE (decl) == 0)
1388 error ("%Jstorage size of `%D' isn't known", decl, decl);
1389 TREE_ASM_WRITTEN (decl) = 1;
1393 /* The first declaration of a variable that comes through this function
1394 decides whether it is global (in C, has external linkage)
1395 or local (in C, has internal linkage). So do nothing more
1396 if this function has already run. */
1398 if (TREE_ASM_WRITTEN (decl))
1401 /* Make sure targetm.encode_section_info is invoked before we set
1403 decl_rtl = DECL_RTL (decl);
1405 TREE_ASM_WRITTEN (decl) = 1;
1407 /* Do no output if -fsyntax-only. */
1408 if (flag_syntax_only)
1413 if (! dont_output_data
1414 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1416 error ("%Jsize of variable '%D' is too large", decl, decl);
1420 name = XSTR (XEXP (decl_rtl, 0), 0);
1421 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1422 notice_global_symbol (decl);
1424 /* Compute the alignment of this data. */
1426 align = DECL_ALIGN (decl);
1428 /* In the case for initialing an array whose length isn't specified,
1429 where we have not yet been able to do the layout,
1430 figure out the proper alignment now. */
1431 if (dont_output_data && DECL_SIZE (decl) == 0
1432 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1433 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1435 /* Some object file formats have a maximum alignment which they support.
1436 In particular, a.out format supports a maximum alignment of 4. */
1437 #ifndef MAX_OFILE_ALIGNMENT
1438 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1440 if (align > MAX_OFILE_ALIGNMENT)
1442 warning ("%Jalignment of '%D' is greater than maximum object "
1443 "file alignment. Using %d", decl, decl,
1444 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1445 align = MAX_OFILE_ALIGNMENT;
1448 /* On some machines, it is good to increase alignment sometimes. */
1449 if (! DECL_USER_ALIGN (decl))
1451 #ifdef DATA_ALIGNMENT
1452 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1454 #ifdef CONSTANT_ALIGNMENT
1455 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1456 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1460 /* Reset the alignment in case we have made it tighter, so we can benefit
1461 from it in get_pointer_alignment. */
1462 DECL_ALIGN (decl) = align;
1463 set_mem_align (decl_rtl, align);
1465 if (TREE_PUBLIC (decl))
1466 maybe_assemble_visibility (decl);
1468 /* Output any data that we will need to use the address of. */
1469 if (DECL_INITIAL (decl) == error_mark_node)
1470 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1471 else if (DECL_INITIAL (decl))
1473 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1474 output_addressed_constants (DECL_INITIAL (decl));
1476 resolve_unique_section (decl, reloc, flag_data_sections);
1478 /* Handle uninitialized definitions. */
1480 /* If the decl has been given an explicit section name, then it
1481 isn't common, and shouldn't be handled as such. */
1482 if (DECL_SECTION_NAME (decl) || dont_output_data)
1484 /* We don't implement common thread-local data at present. */
1485 else if (DECL_THREAD_LOCAL (decl))
1487 if (DECL_COMMON (decl))
1488 sorry ("thread-local COMMON data not implemented");
1490 else if (DECL_INITIAL (decl) == 0
1491 || DECL_INITIAL (decl) == error_mark_node
1492 || (flag_zero_initialized_in_bss
1493 /* Leave constant zeroes in .rodata so they can be shared. */
1494 && !TREE_READONLY (decl)
1495 && initializer_zerop (DECL_INITIAL (decl))))
1497 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1498 unsigned HOST_WIDE_INT rounded = size;
1500 /* Don't allocate zero bytes of common,
1501 since that means "undefined external" in the linker. */
1505 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1506 so that each uninitialized object starts on such a boundary. */
1507 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1508 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1509 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1511 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1512 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1513 warning ("%Jrequested alignment for '%D' is greater than "
1514 "implemented alignment of %d", decl, decl, rounded);
1517 /* If the target cannot output uninitialized but not common global data
1518 in .bss, then we have to use .data, so fall through. */
1519 if (asm_emit_uninitialised (decl, name, size, rounded))
1523 /* Handle initialized definitions.
1524 Also handle uninitialized global definitions if -fno-common and the
1525 target doesn't support ASM_OUTPUT_BSS. */
1527 /* First make the assembler name(s) global if appropriate. */
1528 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1529 globalize_decl (decl);
1531 /* Switch to the appropriate section. */
1532 variable_section (decl, reloc);
1534 /* dbxout.c needs to know this. */
1535 if (in_text_section () || in_unlikely_text_section ())
1536 DECL_IN_TEXT_SECTION (decl) = 1;
1538 /* Output the alignment of this data. */
1539 if (align > BITS_PER_UNIT)
1541 ASM_OUTPUT_ALIGN (asm_out_file,
1542 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1545 /* Do any machine/system dependent processing of the object. */
1546 #ifdef ASM_DECLARE_OBJECT_NAME
1547 last_assemble_variable_decl = decl;
1548 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1550 /* Standard thing is just output label for the object. */
1551 ASM_OUTPUT_LABEL (asm_out_file, name);
1552 #endif /* ASM_DECLARE_OBJECT_NAME */
1554 if (!dont_output_data)
1556 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
1557 /* Output the actual data. */
1558 output_constant (DECL_INITIAL (decl),
1559 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1562 /* Leave space for it. */
1563 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1567 /* Return 1 if type TYPE contains any pointers. */
1570 contains_pointers_p (tree type)
1572 switch (TREE_CODE (type))
1575 case REFERENCE_TYPE:
1576 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1577 so I'll play safe and return 1. */
1583 case QUAL_UNION_TYPE:
1586 /* For a type that has fields, see if the fields have pointers. */
1587 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1588 if (TREE_CODE (fields) == FIELD_DECL
1589 && contains_pointers_p (TREE_TYPE (fields)))
1595 /* An array type contains pointers if its element type does. */
1596 return contains_pointers_p (TREE_TYPE (type));
1603 #ifdef ASM_OUTPUT_EXTERNAL
1604 /* True if DECL is a function decl for which no out-of-line copy exists.
1605 It is assumed that DECL's assembler name has been set. */
1608 incorporeal_function_p (tree decl)
1610 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1614 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
1615 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
1618 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1619 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
1626 /* Output something to declare an external symbol to the assembler.
1627 (Most assemblers don't need this, so we normally output nothing.)
1628 Do nothing if DECL is not external. */
1631 assemble_external (tree decl ATTRIBUTE_UNUSED)
1633 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1634 main body of this code is only rarely exercised. To provide some
1635 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1636 open. If it's not, we should not be calling this function. */
1640 #ifdef ASM_OUTPUT_EXTERNAL
1641 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1643 rtx rtl = DECL_RTL (decl);
1645 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1646 && !SYMBOL_REF_USED (XEXP (rtl, 0))
1647 && !incorporeal_function_p (decl))
1649 /* Some systems do require some output. */
1650 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1651 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1657 /* Similar, for calling a library function FUN. */
1660 assemble_external_libcall (rtx fun)
1662 /* Declare library function name external when first used, if nec. */
1663 if (! SYMBOL_REF_USED (fun))
1665 SYMBOL_REF_USED (fun) = 1;
1666 targetm.asm_out.external_libcall (fun);
1670 /* Assemble a label named NAME. */
1673 assemble_label (const char *name)
1675 ASM_OUTPUT_LABEL (asm_out_file, name);
1678 /* Set the symbol_referenced flag for ID and notify callgraph code. */
1680 mark_referenced (tree id)
1682 if (!TREE_SYMBOL_REFERENCED (id))
1684 struct cgraph_node *node;
1685 struct cgraph_varpool_node *vnode;
1687 if (!cgraph_global_info_ready)
1689 node = cgraph_node_for_identifier (id);
1691 cgraph_mark_needed_node (node);
1694 vnode = cgraph_varpool_node_for_identifier (id);
1696 cgraph_varpool_mark_needed_node (vnode);
1698 TREE_SYMBOL_REFERENCED (id) = 1;
1701 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1702 If NAME starts with a *, the rest of NAME is output verbatim.
1703 Otherwise NAME is transformed in an implementation-defined way
1704 (usually by the addition of an underscore).
1705 Many macros in the tm file are defined to call this function. */
1708 assemble_name (FILE *file, const char *name)
1710 const char *real_name;
1713 real_name = targetm.strip_name_encoding (name);
1715 id = maybe_get_identifier (real_name);
1717 mark_referenced (id);
1720 fputs (&name[1], file);
1722 ASM_OUTPUT_LABELREF (file, name);
1725 /* Allocate SIZE bytes writable static space with a gensym name
1726 and return an RTX to refer to its address. */
1729 assemble_static_space (unsigned HOST_WIDE_INT size)
1732 const char *namestring;
1736 if (flag_shared_data)
1740 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1742 namestring = ggc_strdup (name);
1744 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1745 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
1747 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1748 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1751 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1752 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1755 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1756 so that each uninitialized object starts on such a boundary. */
1757 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1758 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1759 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1760 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1761 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1762 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1769 /* Assemble the static constant template for function entry trampolines.
1770 This is done at most once per compilation.
1771 Returns an RTX for the address of the template. */
1773 #ifdef TRAMPOLINE_TEMPLATE
1775 assemble_trampoline_template (void)
1782 /* By default, put trampoline templates in read-only data section. */
1784 #ifdef TRAMPOLINE_SECTION
1785 TRAMPOLINE_SECTION ();
1787 readonly_data_section ();
1790 /* Write the assembler code to define one. */
1791 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1794 ASM_OUTPUT_ALIGN (asm_out_file, align);
1797 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
1798 TRAMPOLINE_TEMPLATE (asm_out_file);
1800 /* Record the rtl to refer to it. */
1801 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1802 name = ggc_strdup (label);
1803 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
1804 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
1810 /* A and B are either alignments or offsets. Return the minimum alignment
1811 that may be assumed after adding the two together. */
1813 static inline unsigned
1814 min_align (unsigned int a, unsigned int b)
1816 return (a | b) & -(a | b);
1819 /* Return the assembler directive for creating a given kind of integer
1820 object. SIZE is the number of bytes in the object and ALIGNED_P
1821 indicates whether it is known to be aligned. Return NULL if the
1822 assembly dialect has no such directive.
1824 The returned string should be printed at the start of a new line and
1825 be followed immediately by the object's initial value. */
1828 integer_asm_op (int size, int aligned_p)
1830 struct asm_int_op *ops;
1833 ops = &targetm.asm_out.aligned_op;
1835 ops = &targetm.asm_out.unaligned_op;
1840 return targetm.asm_out.byte_op;
1854 /* Use directive OP to assemble an integer object X. Print OP at the
1855 start of the line, followed immediately by the value of X. */
1858 assemble_integer_with_op (const char *op, rtx x)
1860 fputs (op, asm_out_file);
1861 output_addr_const (asm_out_file, x);
1862 fputc ('\n', asm_out_file);
1865 /* The default implementation of the asm_out.integer target hook. */
1868 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
1869 unsigned int size ATTRIBUTE_UNUSED,
1870 int aligned_p ATTRIBUTE_UNUSED)
1872 const char *op = integer_asm_op (size, aligned_p);
1873 return op && (assemble_integer_with_op (op, x), true);
1876 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1877 the alignment of the integer in bits. Return 1 if we were able to output
1878 the constant, otherwise 0. If FORCE is nonzero, abort if we can't output
1882 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
1886 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
1888 /* See if the target hook can handle this kind of object. */
1889 if (targetm.asm_out.integer (x, size, aligned_p))
1892 /* If the object is a multi-byte one, try splitting it up. Split
1893 it into words it if is multi-word, otherwise split it into bytes. */
1896 enum machine_mode omode, imode;
1897 unsigned int subalign;
1898 unsigned int subsize, i;
1900 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
1901 subalign = MIN (align, subsize * BITS_PER_UNIT);
1902 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
1903 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1905 for (i = 0; i < size; i += subsize)
1907 rtx partial = simplify_subreg (omode, x, imode, i);
1908 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
1914 /* If we've printed some of it, but not all of it, there's no going
1927 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
1931 int bitsize, nelts, nunits, units_per;
1933 /* This is hairy. We have a quantity of known size. real_to_target
1934 will put it into an array of *host* longs, 32 bits per element
1935 (even if long is more than 32 bits). We need to determine the
1936 number of array elements that are occupied (nelts) and the number
1937 of *target* min-addressable units that will be occupied in the
1938 object file (nunits). We cannot assume that 32 divides the
1939 mode's bitsize (size * BITS_PER_UNIT) evenly.
1941 size * BITS_PER_UNIT is used here to make sure that padding bits
1942 (which might appear at either end of the value; real_to_target
1943 will include the padding bits in its output array) are included. */
1945 nunits = GET_MODE_SIZE (mode);
1946 bitsize = nunits * BITS_PER_UNIT;
1947 nelts = CEIL (bitsize, 32);
1948 units_per = 32 / BITS_PER_UNIT;
1950 real_to_target (data, &d, mode);
1952 /* Put out the first word with the specified alignment. */
1953 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
1954 nunits -= units_per;
1956 /* Subsequent words need only 32-bit alignment. */
1957 align = min_align (align, 32);
1959 for (i = 1; i < nelts; i++)
1961 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
1962 nunits -= units_per;
1966 /* Given an expression EXP with a constant value,
1967 reduce it to the sum of an assembler symbol and an integer.
1968 Store them both in the structure *VALUE.
1969 Abort if EXP does not reduce. */
1971 struct addr_const GTY(())
1974 HOST_WIDE_INT offset;
1978 decode_addr_const (tree exp, struct addr_const *value)
1980 tree target = TREE_OPERAND (exp, 0);
1986 if (TREE_CODE (target) == COMPONENT_REF
1987 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
1990 offset += int_byte_position (TREE_OPERAND (target, 1));
1991 target = TREE_OPERAND (target, 0);
1993 else if (TREE_CODE (target) == ARRAY_REF
1994 || TREE_CODE (target) == ARRAY_RANGE_REF)
1996 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
1997 * tree_low_cst (TREE_OPERAND (target, 1), 0));
1998 target = TREE_OPERAND (target, 0);
2004 switch (TREE_CODE (target))
2008 x = DECL_RTL (target);
2012 x = gen_rtx_MEM (FUNCTION_MODE,
2013 gen_rtx_LABEL_REF (VOIDmode, force_label_rtx (target)));
2021 x = output_constant_def (target, 1);
2028 if (GET_CODE (x) != MEM)
2033 value->offset = offset;
2036 /* Uniquize all constants that appear in memory.
2037 Each constant in memory thus far output is recorded
2038 in `const_desc_table'. */
2040 struct constant_descriptor_tree GTY(())
2042 /* A MEM for the constant. */
2045 /* The value of the constant. */
2049 static GTY((param_is (struct constant_descriptor_tree)))
2050 htab_t const_desc_htab;
2052 static struct constant_descriptor_tree * build_constant_desc (tree);
2053 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2055 /* Compute a hash code for a constant expression. */
2058 const_desc_hash (const void *ptr)
2060 return const_hash_1 (((struct constant_descriptor_tree *)ptr)->value);
2064 const_hash_1 (const tree exp)
2069 enum tree_code code = TREE_CODE (exp);
2071 /* Either set P and LEN to the address and len of something to hash and
2072 exit the switch or return a value. */
2077 p = (char *) &TREE_INT_CST (exp);
2078 len = sizeof TREE_INT_CST (exp);
2082 return real_hash (TREE_REAL_CST_PTR (exp));
2085 p = TREE_STRING_POINTER (exp);
2086 len = TREE_STRING_LENGTH (exp);
2090 return (const_hash_1 (TREE_REALPART (exp)) * 5
2091 + const_hash_1 (TREE_IMAGPART (exp)));
2094 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2098 len = int_size_in_bytes (TREE_TYPE (exp));
2100 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2108 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2110 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2111 if (TREE_VALUE (link))
2112 hi = hi * 603 + const_hash_1 (TREE_VALUE (link));
2120 struct addr_const value;
2122 decode_addr_const (exp, &value);
2123 if (GET_CODE (value.base) == SYMBOL_REF)
2125 /* Don't hash the address of the SYMBOL_REF;
2126 only use the offset and the symbol name. */
2128 p = XSTR (value.base, 0);
2129 for (i = 0; p[i] != 0; i++)
2130 hi = ((hi * 613) + (unsigned) (p[i]));
2132 else if (GET_CODE (value.base) == LABEL_REF)
2133 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2141 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2142 + const_hash_1 (TREE_OPERAND (exp, 1)));
2146 case NON_LVALUE_EXPR:
2147 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2150 /* A language specific constant. Just hash the code. */
2154 /* Compute hashing function. */
2156 for (i = 0; i < len; i++)
2157 hi = ((hi * 613) + (unsigned) (p[i]));
2162 /* Wrapper of compare_constant, for the htab interface. */
2164 const_desc_eq (const void *p1, const void *p2)
2166 return compare_constant (((struct constant_descriptor_tree *)p1)->value,
2167 ((struct constant_descriptor_tree *)p2)->value);
2170 /* Compare t1 and t2, and return 1 only if they are known to result in
2171 the same bit pattern on output. */
2174 compare_constant (const tree t1, const tree t2)
2176 enum tree_code typecode;
2178 if (t1 == NULL_TREE)
2179 return t2 == NULL_TREE;
2180 if (t2 == NULL_TREE)
2183 if (TREE_CODE (t1) != TREE_CODE (t2))
2186 switch (TREE_CODE (t1))
2189 /* Integer constants are the same only if the same width of type. */
2190 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2192 return tree_int_cst_equal (t1, t2);
2195 /* Real constants are the same only if the same width of type. */
2196 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2199 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2202 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2205 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2206 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2207 TREE_STRING_LENGTH (t1)));
2210 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2211 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2214 typecode = TREE_CODE (TREE_TYPE (t1));
2215 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2218 if (typecode == SET_TYPE)
2220 int len = int_size_in_bytes (TREE_TYPE (t2));
2221 unsigned char *tmp1, *tmp2;
2223 if (int_size_in_bytes (TREE_TYPE (t1)) != len)
2226 tmp1 = alloca (len);
2227 tmp2 = alloca (len);
2229 if (get_set_constructor_bytes (t1, tmp1, len) != NULL_TREE)
2231 if (get_set_constructor_bytes (t2, tmp2, len) != NULL_TREE)
2234 return memcmp (tmp1, tmp2, len) == 0;
2240 if (typecode == ARRAY_TYPE)
2242 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2243 /* For arrays, check that the sizes all match. */
2244 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2246 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2251 /* For record and union constructors, require exact type
2253 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2257 for (l1 = CONSTRUCTOR_ELTS (t1), l2 = CONSTRUCTOR_ELTS (t2);
2259 l1 = TREE_CHAIN (l1), l2 = TREE_CHAIN (l2))
2261 /* Check that each value is the same... */
2262 if (! compare_constant (TREE_VALUE (l1), TREE_VALUE (l2)))
2264 /* ... and that they apply to the same fields! */
2265 if (typecode == ARRAY_TYPE)
2267 if (! compare_constant (TREE_PURPOSE (l1),
2273 if (TREE_PURPOSE (l1) != TREE_PURPOSE (l2))
2278 return l1 == NULL_TREE && l2 == NULL_TREE;
2284 struct addr_const value1, value2;
2286 decode_addr_const (t1, &value1);
2287 decode_addr_const (t2, &value2);
2288 return (value1.offset == value2.offset
2289 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2295 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2296 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2300 case NON_LVALUE_EXPR:
2301 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2306 nt1 = lang_hooks.expand_constant (t1);
2307 nt2 = lang_hooks.expand_constant (t2);
2308 if (nt1 != t1 || nt2 != t2)
2309 return compare_constant (nt1, nt2);
2315 /* Should not get here. */
2319 /* Make a copy of the whole tree structure for a constant. This
2320 handles the same types of nodes that compare_constant handles. */
2323 copy_constant (tree exp)
2325 switch (TREE_CODE (exp))
2328 /* For ADDR_EXPR, we do not want to copy the decl whose address
2329 is requested. We do want to copy constants though. */
2330 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2331 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2332 copy_constant (TREE_OPERAND (exp, 0)));
2334 return copy_node (exp);
2339 return copy_node (exp);
2342 return build_complex (TREE_TYPE (exp),
2343 copy_constant (TREE_REALPART (exp)),
2344 copy_constant (TREE_IMAGPART (exp)));
2348 return build (TREE_CODE (exp), TREE_TYPE (exp),
2349 copy_constant (TREE_OPERAND (exp, 0)),
2350 copy_constant (TREE_OPERAND (exp, 1)));
2354 case NON_LVALUE_EXPR:
2355 case VIEW_CONVERT_EXPR:
2356 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2357 copy_constant (TREE_OPERAND (exp, 0)));
2361 tree copy = copy_node (exp);
2362 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2365 CONSTRUCTOR_ELTS (copy) = list;
2366 for (tail = list; tail; tail = TREE_CHAIN (tail))
2367 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2368 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2369 for (tail = list; tail; tail = TREE_CHAIN (tail))
2370 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2378 t = lang_hooks.expand_constant (exp);
2380 return copy_constant (t);
2387 /* Subroutine of output_constant_def:
2388 No constant equal to EXP is known to have been output.
2389 Make a constant descriptor to enter EXP in the hash table.
2390 Assign the label number and construct RTL to refer to the
2391 constant's location in memory.
2392 Caller is responsible for updating the hash table. */
2394 static struct constant_descriptor_tree *
2395 build_constant_desc (tree exp)
2401 struct constant_descriptor_tree *desc;
2403 desc = ggc_alloc (sizeof (*desc));
2404 desc->value = copy_constant (exp);
2406 /* Create a string containing the label name, in LABEL. */
2407 labelno = const_labelno++;
2408 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2410 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2411 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2412 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2413 SYMBOL_REF_DECL (symbol) = desc->value;
2414 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2416 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2417 set_mem_attributes (rtl, exp, 1);
2418 set_mem_alias_set (rtl, 0);
2419 set_mem_alias_set (rtl, const_alias_set);
2421 /* Set flags or add text to the name to record information, such as
2422 that it is a local symbol. If the name is changed, the macro
2423 ASM_OUTPUT_LABELREF will have to know how to strip this
2424 information. This call might invalidate our local variable
2425 SYMBOL; we can't use it afterward. */
2427 targetm.encode_section_info (exp, rtl, true);
2434 /* Return an rtx representing a reference to constant data in memory
2435 for the constant expression EXP.
2437 If assembler code for such a constant has already been output,
2438 return an rtx to refer to it.
2439 Otherwise, output such a constant in memory
2440 and generate an rtx for it.
2442 If DEFER is nonzero, this constant can be deferred and output only
2443 if referenced in the function after all optimizations.
2445 `const_desc_table' records which constants already have label strings. */
2448 output_constant_def (tree exp, int defer)
2450 struct constant_descriptor_tree *desc;
2451 struct constant_descriptor_tree key;
2454 /* Look up EXP in the table of constant descriptors. If we didn't find
2455 it, create a new one. */
2457 loc = htab_find_slot (const_desc_htab, &key, INSERT);
2462 desc = build_constant_desc (exp);
2466 maybe_output_constant_def_contents (desc, defer);
2470 /* Subroutine of output_constant_def: Decide whether or not we need to
2471 output the constant DESC now, and if so, do it. */
2473 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
2476 rtx symbol = XEXP (desc->rtl, 0);
2477 tree exp = desc->value;
2479 if (flag_syntax_only)
2482 if (TREE_ASM_WRITTEN (exp))
2483 /* Already output; don't do it again. */
2486 /* We can always defer constants as long as the context allows
2490 /* Increment n_deferred_constants if it exists. It needs to be at
2491 least as large as the number of constants actually referred to
2492 by the function. If it's too small we'll stop looking too early
2493 and fail to emit constants; if it's too large we'll only look
2494 through the entire function when we could have stopped earlier. */
2496 n_deferred_constants++;
2500 output_constant_def_contents (symbol);
2503 /* We must output the constant data referred to by SYMBOL; do so. */
2506 output_constant_def_contents (rtx symbol)
2508 tree exp = SYMBOL_REF_DECL (symbol);
2509 const char *label = XSTR (symbol, 0);
2512 /* Make sure any other constants whose addresses appear in EXP
2513 are assigned label numbers. */
2514 int reloc = compute_reloc_for_constant (exp);
2516 /* Align the location counter as required by EXP's data type. */
2517 int align = TYPE_ALIGN (TREE_TYPE (exp));
2518 #ifdef CONSTANT_ALIGNMENT
2519 align = CONSTANT_ALIGNMENT (exp, align);
2522 output_addressed_constants (exp);
2524 /* We are no longer deferring this constant. */
2525 TREE_ASM_WRITTEN (exp) = 1;
2527 if (IN_NAMED_SECTION (exp))
2528 named_section (exp, NULL, reloc);
2530 targetm.asm_out.select_section (exp, reloc, align);
2532 if (align > BITS_PER_UNIT)
2534 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2537 size = int_size_in_bytes (TREE_TYPE (exp));
2538 if (TREE_CODE (exp) == STRING_CST)
2539 size = MAX (TREE_STRING_LENGTH (exp), size);
2541 /* Do any machine/system dependent processing of the constant. */
2542 #ifdef ASM_DECLARE_CONSTANT_NAME
2543 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
2545 /* Standard thing is just output label for the constant. */
2546 ASM_OUTPUT_LABEL (asm_out_file, label);
2547 #endif /* ASM_DECLARE_CONSTANT_NAME */
2549 /* Output the value of EXP. */
2550 output_constant (exp, size, align);
2553 /* A constant which was deferred in its original location has been
2554 inserted by the RTL inliner into a different function. The
2555 current function's deferred constant count must be incremented. */
2557 notice_rtl_inlining_of_deferred_constant (void)
2559 n_deferred_constants++;
2562 /* Look up EXP in the table of constant descriptors. Return the rtl
2563 if it has been emitted, else null. */
2566 lookup_constant_def (tree exp)
2568 struct constant_descriptor_tree *desc;
2569 struct constant_descriptor_tree key;
2572 desc = htab_find (const_desc_htab, &key);
2574 return (desc ? desc->rtl : NULL_RTX);
2577 /* Used in the hash tables to avoid outputting the same constant
2578 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2579 are output once per function, not once per file. */
2580 /* ??? Only a few targets need per-function constant pools. Most
2581 can use one per-file pool. Should add a targetm bit to tell the
2584 struct rtx_constant_pool GTY(())
2586 /* Pointers to first and last constant in pool, as ordered by offset. */
2587 struct constant_descriptor_rtx *first;
2588 struct constant_descriptor_rtx *last;
2590 /* Hash facility for making memory-constants from constant rtl-expressions.
2591 It is used on RISC machines where immediate integer arguments and
2592 constant addresses are restricted so that such constants must be stored
2594 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
2595 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_sym_htab;
2597 /* Current offset in constant pool (does not include any
2598 machine-specific header). */
2599 HOST_WIDE_INT offset;
2602 struct constant_descriptor_rtx GTY((chain_next ("%h.next")))
2604 struct constant_descriptor_rtx *next;
2608 HOST_WIDE_INT offset;
2610 enum machine_mode mode;
2616 /* Hash and compare functions for const_rtx_htab. */
2619 const_desc_rtx_hash (const void *ptr)
2621 const struct constant_descriptor_rtx *desc = ptr;
2626 const_desc_rtx_eq (const void *a, const void *b)
2628 const struct constant_descriptor_rtx *x = a;
2629 const struct constant_descriptor_rtx *y = b;
2631 if (x->mode != y->mode)
2633 return rtx_equal_p (x->constant, y->constant);
2636 /* Hash and compare functions for const_rtx_sym_htab. */
2639 const_desc_rtx_sym_hash (const void *ptr)
2641 const struct constant_descriptor_rtx *desc = ptr;
2642 return htab_hash_string (XSTR (desc->sym, 0));
2646 const_desc_rtx_sym_eq (const void *a, const void *b)
2648 const struct constant_descriptor_rtx *x = a;
2649 const struct constant_descriptor_rtx *y = b;
2650 return XSTR (x->sym, 0) == XSTR (y->sym, 0);
2653 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
2656 const_rtx_hash_1 (rtx *xp, void *data)
2658 unsigned HOST_WIDE_INT hwi;
2659 enum machine_mode mode;
2665 code = GET_CODE (x);
2666 mode = GET_MODE (x);
2667 h = (hashval_t) code * 1048573 + mode;
2675 const int shift = sizeof (hashval_t) * CHAR_BIT;
2676 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
2679 h ^= (hashval_t) hwi;
2680 for (i = 1; i < n; ++i)
2683 h ^= (hashval_t) hwi;
2689 if (mode == VOIDmode)
2691 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
2695 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
2699 h ^= htab_hash_string (XSTR (x, 0));
2703 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
2707 case UNSPEC_VOLATILE:
2708 h = h * 251 + XINT (x, 1);
2716 *hp = *hp * 509 + h;
2720 /* Compute a hash value for X, which should be a constant. */
2723 const_rtx_hash (rtx x)
2726 for_each_rtx (&x, const_rtx_hash_1, &h);
2731 /* Initialize constant pool hashing for a new function. */
2734 init_varasm_status (struct function *f)
2736 struct varasm_status *p;
2737 struct rtx_constant_pool *pool;
2739 p = ggc_alloc (sizeof (struct varasm_status));
2742 pool = ggc_alloc (sizeof (struct rtx_constant_pool));
2744 p->deferred_constants = 0;
2746 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
2747 const_desc_rtx_eq, NULL);
2748 pool->const_rtx_sym_htab = htab_create_ggc (31, const_desc_rtx_sym_hash,
2749 const_desc_rtx_sym_eq, NULL);
2750 pool->first = pool->last = NULL;
2754 /* Given a MINUS expression, simplify it if both sides
2755 include the same symbol. */
2758 simplify_subtraction (rtx x)
2760 rtx r = simplify_rtx (x);
2764 /* Given a constant rtx X, make (or find) a memory constant for its value
2765 and return a MEM rtx to refer to it in memory. */
2768 force_const_mem (enum machine_mode mode, rtx x)
2770 struct constant_descriptor_rtx *desc, tmp;
2771 struct rtx_constant_pool *pool = cfun->varasm->pool;
2778 /* If we're not allowed to drop X into the constant pool, don't. */
2779 if (targetm.cannot_force_const_mem (x))
2782 /* Lookup the value in the hashtable. */
2785 hash = const_rtx_hash (x);
2786 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
2789 /* If the constant was already present, return its memory. */
2791 return copy_rtx (desc->mem);
2793 /* Otherwise, create a new descriptor. */
2794 desc = ggc_alloc (sizeof (*desc));
2797 /* Align the location counter as required by EXP's data type. */
2798 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
2799 #ifdef CONSTANT_ALIGNMENT
2801 tree type = lang_hooks.types.type_for_mode (mode, 0);
2802 if (type != NULL_TREE)
2803 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
2807 pool->offset += (align / BITS_PER_UNIT) - 1;
2808 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
2811 desc->constant = tmp.constant;
2812 desc->offset = pool->offset;
2815 desc->align = align;
2816 desc->labelno = const_labelno;
2819 pool->offset += GET_MODE_SIZE (mode);
2821 pool->last->next = desc;
2823 pool->first = pool->last = desc;
2826 /* Create a string containing the label name, in LABEL. */
2827 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2830 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
2831 the constants pool. */
2832 desc->sym = symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2833 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2834 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2835 current_function_uses_const_pool = 1;
2837 /* Insert the descriptor into the symbol cross-reference table too. */
2838 slot = htab_find_slot (pool->const_rtx_sym_htab, desc, INSERT);
2843 /* Construct the MEM. */
2844 desc->mem = def = gen_rtx_MEM (mode, symbol);
2845 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
2846 RTX_UNCHANGING_P (def) = 1;
2848 /* If we're dropping a label to the constant pool, make sure we
2850 if (GET_CODE (x) == LABEL_REF)
2851 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
2853 return copy_rtx (def);
2856 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2857 the corresponding constant_descriptor_rtx structure. */
2859 static struct constant_descriptor_rtx *
2860 find_pool_constant (struct rtx_constant_pool *pool, rtx sym)
2862 struct constant_descriptor_rtx tmp;
2864 return htab_find (pool->const_rtx_sym_htab, &tmp);
2867 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2870 get_pool_constant (rtx addr)
2872 return find_pool_constant (cfun->varasm->pool, addr)->constant;
2875 /* Given a constant pool SYMBOL_REF, return the corresponding constant
2876 and whether it has been output or not. */
2879 get_pool_constant_mark (rtx addr, bool *pmarked)
2881 struct constant_descriptor_rtx *desc;
2883 desc = find_pool_constant (cfun->varasm->pool, addr);
2884 *pmarked = (desc->mark != 0);
2885 return desc->constant;
2888 /* Likewise, but for the constant pool of a specific function. */
2891 get_pool_constant_for_function (struct function *f, rtx addr)
2893 return find_pool_constant (f->varasm->pool, addr)->constant;
2896 /* Similar, return the mode. */
2899 get_pool_mode (rtx addr)
2901 return find_pool_constant (cfun->varasm->pool, addr)->mode;
2905 get_pool_mode_for_function (struct function *f, rtx addr)
2907 return find_pool_constant (f->varasm->pool, addr)->mode;
2910 /* Similar, return the offset in the constant pool. */
2913 get_pool_offset (rtx addr)
2915 return find_pool_constant (cfun->varasm->pool, addr)->offset;
2918 /* Return the size of the constant pool. */
2921 get_pool_size (void)
2923 return cfun->varasm->pool->offset;
2926 /* Worker function for output_constant_pool_1. Emit assembly for X
2927 in MODE with known alignment ALIGN. */
2930 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
2932 switch (GET_MODE_CLASS (mode))
2935 if (GET_CODE (x) != CONST_DOUBLE)
2940 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2941 assemble_real (r, mode, align);
2946 case MODE_PARTIAL_INT:
2947 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
2950 case MODE_VECTOR_FLOAT:
2951 case MODE_VECTOR_INT:
2954 enum machine_mode submode = GET_MODE_INNER (mode);
2955 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
2957 if (GET_CODE (x) != CONST_VECTOR)
2959 units = CONST_VECTOR_NUNITS (x);
2961 for (i = 0; i < units; i++)
2963 rtx elt = CONST_VECTOR_ELT (x, i);
2964 output_constant_pool_2 (submode, elt, i ? subalign : align);
2974 /* Worker function for output_constant_pool. Emit POOL. */
2977 output_constant_pool_1 (struct constant_descriptor_rtx *desc)
2985 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2986 whose CODE_LABEL has been deleted. This can occur if a jump table
2987 is eliminated by optimization. If so, write a constant of zero
2988 instead. Note that this can also happen by turning the
2989 CODE_LABEL into a NOTE. */
2990 /* ??? This seems completely and utterly wrong. Certainly it's
2991 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
2992 functioning even with INSN_DELETED_P and friends. */
2995 switch (GET_CODE (x))
2998 if (GET_CODE (XEXP (x, 0)) != PLUS
2999 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3001 tmp = XEXP (XEXP (x, 0), 0);
3006 if (INSN_DELETED_P (tmp)
3007 || (GET_CODE (tmp) == NOTE
3008 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
3019 /* First switch to correct section. */
3020 targetm.asm_out.select_rtx_section (desc->mode, x, desc->align);
3022 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3023 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3024 desc->align, desc->labelno, done);
3027 assemble_align (desc->align);
3029 /* Output the label. */
3030 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3032 /* Output the data. */
3033 output_constant_pool_2 (desc->mode, x, desc->align);
3035 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3036 sections have proper size. */
3037 if (desc->align > GET_MODE_BITSIZE (desc->mode)
3038 && in_section == in_named
3039 && get_named_section_flags (in_named_name) & SECTION_MERGE)
3040 assemble_align (desc->align);
3042 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3048 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3049 to as used. Emit referenced deferred strings. This function can
3050 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3053 mark_constant (rtx *current_rtx, void *data)
3055 struct rtx_constant_pool *pool = data;
3056 rtx x = *current_rtx;
3058 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3061 if (CONSTANT_POOL_ADDRESS_P (x))
3063 struct constant_descriptor_rtx *desc = find_pool_constant (pool, x);
3064 if (desc->mark == 0)
3067 for_each_rtx (&desc->constant, mark_constant, pool);
3070 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3072 tree exp = SYMBOL_REF_DECL (x);
3073 if (!TREE_ASM_WRITTEN (exp))
3075 n_deferred_constants--;
3076 output_constant_def_contents (x);
3083 /* Look through appropriate parts of INSN, marking all entries in the
3084 constant pool which are actually being used. Entries that are only
3085 referenced by other constants are also marked as used. Emit
3086 deferred strings that are used. */
3089 mark_constants (struct rtx_constant_pool *pool, rtx insn)
3094 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3095 insns, not any notes that may be attached. We don't want to mark
3096 a constant just because it happens to appear in a REG_EQUIV note. */
3097 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3099 rtx seq = PATTERN (insn);
3100 int i, n = XVECLEN (seq, 0);
3101 for (i = 0; i < n; ++i)
3103 rtx subinsn = XVECEXP (seq, 0, i);
3104 if (INSN_P (subinsn))
3105 for_each_rtx (&PATTERN (subinsn), mark_constant, pool);
3109 for_each_rtx (&PATTERN (insn), mark_constant, pool);
3112 /* Look through the instructions for this function, and mark all the
3113 entries in POOL which are actually being used. Emit deferred constants
3114 which have indeed been used. */
3117 mark_constant_pool (struct rtx_constant_pool *pool)
3121 if (pool->first == 0 && n_deferred_constants == 0)
3124 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3125 mark_constants (pool, insn);
3127 for (link = current_function_epilogue_delay_list;
3129 link = XEXP (link, 1))
3130 mark_constants (pool, XEXP (link, 0));
3133 /* Write all the constants in the constant pool. */
3136 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3137 tree fndecl ATTRIBUTE_UNUSED)
3139 struct rtx_constant_pool *pool = cfun->varasm->pool;
3140 struct constant_descriptor_rtx *desc;
3142 /* It is possible for gcc to call force_const_mem and then to later
3143 discard the instructions which refer to the constant. In such a
3144 case we do not need to output the constant. */
3145 mark_constant_pool (pool);
3147 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3148 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3151 for (desc = pool->first; desc ; desc = desc->next)
3152 output_constant_pool_1 (desc);
3154 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3155 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3159 /* Determine what kind of relocations EXP may need. */
3162 compute_reloc_for_constant (tree exp)
3164 int reloc = 0, reloc2;
3167 /* Give the front-end a chance to convert VALUE to something that
3168 looks more like a constant to the back-end. */
3169 exp = lang_hooks.expand_constant (exp);
3171 switch (TREE_CODE (exp))
3175 /* Go inside any operations that get_inner_reference can handle and see
3176 if what's inside is a constant: no need to do anything here for
3177 addresses of variables or functions. */
3178 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3179 tem = TREE_OPERAND (tem, 0))
3182 if (TREE_PUBLIC (tem))
3189 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3190 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3194 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3195 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3196 /* The difference of two local labels is computable at link time. */
3197 if (reloc == 1 && reloc2 == 1)
3205 case NON_LVALUE_EXPR:
3206 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3210 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3211 if (TREE_VALUE (tem) != 0)
3212 reloc |= compute_reloc_for_constant (TREE_VALUE (tem));
3222 /* Find all the constants whose addresses are referenced inside of EXP,
3223 and make sure assembler code with a label has been output for each one.
3224 Indicate whether an ADDR_EXPR has been encountered. */
3227 output_addressed_constants (tree exp)
3231 /* Give the front-end a chance to convert VALUE to something that
3232 looks more like a constant to the back-end. */
3233 exp = lang_hooks.expand_constant (exp);
3235 switch (TREE_CODE (exp))
3239 /* Go inside any operations that get_inner_reference can handle and see
3240 if what's inside is a constant: no need to do anything here for
3241 addresses of variables or functions. */
3242 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3243 tem = TREE_OPERAND (tem, 0))
3246 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
3247 || TREE_CODE (tem) == CONSTRUCTOR)
3248 output_constant_def (tem, 0);
3253 output_addressed_constants (TREE_OPERAND (exp, 1));
3258 case NON_LVALUE_EXPR:
3259 output_addressed_constants (TREE_OPERAND (exp, 0));
3263 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3264 if (TREE_VALUE (tem) != 0)
3265 output_addressed_constants (TREE_VALUE (tem));
3274 /* Return nonzero if VALUE is a valid constant-valued expression
3275 for use in initializing a static variable; one that can be an
3276 element of a "constant" initializer.
3278 Return null_pointer_node if the value is absolute;
3279 if it is relocatable, return the variable that determines the relocation.
3280 We assume that VALUE has been folded as much as possible;
3281 therefore, we do not need to check for such things as
3282 arithmetic-combinations of integers. */
3285 initializer_constant_valid_p (tree value, tree endtype)
3287 /* Give the front-end a chance to convert VALUE to something that
3288 looks more like a constant to the back-end. */
3289 value = lang_hooks.expand_constant (value);
3291 switch (TREE_CODE (value))
3294 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
3295 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
3296 && TREE_CONSTANT (value)
3297 && CONSTRUCTOR_ELTS (value))
3300 bool absolute = true;
3302 for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt))
3305 value = TREE_VALUE (elt);
3306 reloc = initializer_constant_valid_p (value, TREE_TYPE (value));
3309 if (reloc != null_pointer_node)
3312 /* For a non-absolute relocation, there is no single
3313 variable that can be "the variable that determines the
3315 return absolute ? null_pointer_node : error_mark_node;
3318 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
3325 return null_pointer_node;
3329 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
3331 case VIEW_CONVERT_EXPR:
3332 case NON_LVALUE_EXPR:
3333 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3337 /* Allow conversions between pointer types. */
3338 if (POINTER_TYPE_P (TREE_TYPE (value))
3339 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3340 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3342 /* Allow conversions between real types. */
3343 if (FLOAT_TYPE_P (TREE_TYPE (value))
3344 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3345 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3347 /* Allow length-preserving conversions between integer types. */
3348 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3349 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3350 && (TYPE_PRECISION (TREE_TYPE (value))
3351 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3352 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3354 /* Allow conversions between other integer types only if
3356 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3357 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3359 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3361 if (inner == null_pointer_node)
3362 return null_pointer_node;
3366 /* Allow (int) &foo provided int is as wide as a pointer. */
3367 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3368 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3369 && (TYPE_PRECISION (TREE_TYPE (value))
3370 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3371 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3374 /* Likewise conversions from int to pointers, but also allow
3375 conversions from 0. */
3376 if ((POINTER_TYPE_P (TREE_TYPE (value))
3377 || TREE_CODE (TREE_TYPE (value)) == OFFSET_TYPE)
3378 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3380 if (integer_zerop (TREE_OPERAND (value, 0)))
3381 return null_pointer_node;
3382 else if (TYPE_PRECISION (TREE_TYPE (value))
3383 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
3384 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3388 /* Allow conversions to struct or union types if the value
3390 if (TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE
3391 || TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
3392 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3397 if (! INTEGRAL_TYPE_P (endtype)
3398 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3400 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3402 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3404 /* If either term is absolute, use the other terms relocation. */
3405 if (valid0 == null_pointer_node)
3407 if (valid1 == null_pointer_node)
3413 if (! INTEGRAL_TYPE_P (endtype)
3414 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3416 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3418 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3420 /* Win if second argument is absolute. */
3421 if (valid1 == null_pointer_node)
3423 /* Win if both arguments have the same relocation.
3424 Then the value is absolute. */
3425 if (valid0 == valid1 && valid0 != 0)
3426 return null_pointer_node;
3428 /* Since GCC guarantees that string constants are unique in the
3429 generated code, a subtraction between two copies of the same
3430 constant string is absolute. */
3431 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
3432 valid1 && TREE_CODE (valid1) == STRING_CST &&
3433 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
3434 return null_pointer_node;
3437 /* Support differences between labels. */
3438 if (INTEGRAL_TYPE_P (endtype))
3441 op0 = TREE_OPERAND (value, 0);
3442 op1 = TREE_OPERAND (value, 1);
3444 /* Like STRIP_NOPS except allow the operand mode to widen.
3445 This works around a feature of fold that simplifies
3446 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3447 that the narrower operation is cheaper. */
3449 while (TREE_CODE (op0) == NOP_EXPR
3450 || TREE_CODE (op0) == CONVERT_EXPR
3451 || TREE_CODE (op0) == NON_LVALUE_EXPR)
3453 tree inner = TREE_OPERAND (op0, 0);
3454 if (inner == error_mark_node
3455 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3456 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3457 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3462 while (TREE_CODE (op1) == NOP_EXPR
3463 || TREE_CODE (op1) == CONVERT_EXPR
3464 || TREE_CODE (op1) == NON_LVALUE_EXPR)
3466 tree inner = TREE_OPERAND (op1, 0);
3467 if (inner == error_mark_node
3468 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3469 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3470 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3475 if (TREE_CODE (op0) == ADDR_EXPR
3476 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
3477 && TREE_CODE (op1) == ADDR_EXPR
3478 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
3479 return null_pointer_node;
3490 /* Output assembler code for constant EXP to FILE, with no label.
3491 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3492 Assumes output_addressed_constants has been done on EXP already.
3494 Generate exactly SIZE bytes of assembler data, padding at the end
3495 with zeros if necessary. SIZE must always be specified.
3497 SIZE is important for structure constructors,
3498 since trailing members may have been omitted from the constructor.
3499 It is also important for initialization of arrays from string constants
3500 since the full length of the string constant might not be wanted.
3501 It is also needed for initialization of unions, where the initializer's
3502 type is just one member, and that may not be as long as the union.
3504 There a case in which we would fail to output exactly SIZE bytes:
3505 for a structure constructor that wants to produce more than SIZE bytes.
3506 But such constructors will never be generated for any possible input.
3508 ALIGN is the alignment of the data in bits. */
3511 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
3513 enum tree_code code;
3514 unsigned HOST_WIDE_INT thissize;
3516 /* Some front-ends use constants other than the standard language-independent
3517 varieties, but which may still be output directly. Give the front-end a
3518 chance to convert EXP to a language-independent representation. */
3519 exp = lang_hooks.expand_constant (exp);
3521 if (size == 0 || flag_syntax_only)
3524 /* Eliminate any conversions since we'll be outputting the underlying
3526 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3527 || TREE_CODE (exp) == NON_LVALUE_EXPR
3528 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
3529 exp = TREE_OPERAND (exp, 0);
3531 code = TREE_CODE (TREE_TYPE (exp));
3532 thissize = int_size_in_bytes (TREE_TYPE (exp));
3534 /* Allow a constructor with no elements for any data type.
3535 This means to fill the space with zeros. */
3536 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3538 assemble_zeros (size);
3542 if (TREE_CODE (exp) == FDESC_EXPR)
3544 #ifdef ASM_OUTPUT_FDESC
3545 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
3546 tree decl = TREE_OPERAND (exp, 0);
3547 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
3554 /* Now output the underlying data. If we've handling the padding, return.
3555 Otherwise, break and ensure THISSIZE is the size written. */
3563 case REFERENCE_TYPE:
3565 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3566 EXPAND_INITIALIZER),
3568 error ("initializer for integer value is too complicated");
3572 if (TREE_CODE (exp) != REAL_CST)
3573 error ("initializer for floating value is not a floating constant");
3575 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
3579 output_constant (TREE_REALPART (exp), thissize / 2, align);
3580 output_constant (TREE_IMAGPART (exp), thissize / 2,
3581 min_align (align, BITS_PER_UNIT * (thissize / 2)));
3586 if (TREE_CODE (exp) == CONSTRUCTOR)
3588 output_constructor (exp, size, align);
3591 else if (TREE_CODE (exp) == STRING_CST)
3593 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
3595 assemble_string (TREE_STRING_POINTER (exp), thissize);
3597 else if (TREE_CODE (exp) == VECTOR_CST)
3601 unsigned int nalign;
3602 enum machine_mode inner;
3604 inner = GET_MODE_INNER (TYPE_MODE (TREE_TYPE (exp)));
3605 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
3607 elt_size = GET_MODE_UNIT_SIZE (TYPE_MODE (TREE_TYPE (exp)));
3609 link = TREE_VECTOR_CST_ELTS (exp);
3610 output_constant (TREE_VALUE (link), elt_size, align);
3611 while ((link = TREE_CHAIN (link)) != NULL)
3612 output_constant (TREE_VALUE (link), elt_size, nalign);
3620 if (TREE_CODE (exp) == CONSTRUCTOR)
3621 output_constructor (exp, size, align);
3627 if (TREE_CODE (exp) == INTEGER_CST)
3628 assemble_integer (expand_expr (exp, NULL_RTX,
3629 VOIDmode, EXPAND_INITIALIZER),
3630 thissize, align, 1);
3631 else if (TREE_CODE (exp) == CONSTRUCTOR)
3633 unsigned char *buffer = alloca (thissize);
3634 if (get_set_constructor_bytes (exp, buffer, thissize))
3636 assemble_string ((char *) buffer, thissize);
3639 error ("unknown set constructor type");
3649 if (size > thissize)
3650 assemble_zeros (size - thissize);
3654 /* Subroutine of output_constructor, used for computing the size of
3655 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3656 type with an unspecified upper bound. */
3658 static unsigned HOST_WIDE_INT
3659 array_size_for_constructor (tree val)
3663 /* This code used to attempt to handle string constants that are not
3664 arrays of single-bytes, but nothing else does, so there's no point in
3666 if (TREE_CODE (val) == STRING_CST)
3667 return TREE_STRING_LENGTH (val);
3669 max_index = NULL_TREE;
3670 for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i))
3672 tree index = TREE_PURPOSE (i);
3674 if (TREE_CODE (index) == RANGE_EXPR)
3675 index = TREE_OPERAND (index, 1);
3676 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
3680 if (max_index == NULL_TREE)
3683 /* Compute the total number of array elements. */
3684 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
3686 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
3687 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
3689 /* Multiply by the array element unit size to find number of bytes. */
3690 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
3692 return tree_low_cst (i, 1);
3695 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3696 Generate at least SIZE bytes, padding if necessary. */
3699 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
3702 tree type = TREE_TYPE (exp);
3703 tree link, field = 0;
3705 /* Number of bytes output or skipped so far.
3706 In other words, current position within the constructor. */
3707 HOST_WIDE_INT total_bytes = 0;
3708 /* Nonzero means BYTE contains part of a byte, to be output. */
3709 int byte_buffer_in_use = 0;
3712 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3715 if (TREE_CODE (type) == RECORD_TYPE)
3716 field = TYPE_FIELDS (type);
3718 if (TREE_CODE (type) == ARRAY_TYPE
3719 && TYPE_DOMAIN (type) != 0)
3720 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
3722 /* As LINK goes through the elements of the constant,
3723 FIELD goes through the structure fields, if the constant is a structure.
3724 if the constant is a union, then we override this,
3725 by getting the field from the TREE_LIST element.
3726 But the constant could also be an array. Then FIELD is zero.
3728 There is always a maximum of one element in the chain LINK for unions
3729 (even if the initializer in a source program incorrectly contains
3731 for (link = CONSTRUCTOR_ELTS (exp);
3733 link = TREE_CHAIN (link),
3734 field = field ? TREE_CHAIN (field) : 0)
3736 tree val = TREE_VALUE (link);
3739 /* The element in a union constructor specifies the proper field
3741 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
3742 || TREE_CODE (type) == QUAL_UNION_TYPE)
3743 && TREE_PURPOSE (link) != 0)
3744 field = TREE_PURPOSE (link);
3746 else if (TREE_CODE (type) == ARRAY_TYPE)
3747 index = TREE_PURPOSE (link);
3749 #ifdef ASM_COMMENT_START
3750 if (field && flag_verbose_asm)
3751 fprintf (asm_out_file, "%s %s:\n",
3754 ? IDENTIFIER_POINTER (DECL_NAME (field))
3758 /* Eliminate the marker that makes a cast not be an lvalue. */
3762 if (index && TREE_CODE (index) == RANGE_EXPR)
3764 unsigned HOST_WIDE_INT fieldsize
3765 = int_size_in_bytes (TREE_TYPE (type));
3766 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
3767 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
3768 HOST_WIDE_INT index;
3769 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
3771 for (index = lo_index; index <= hi_index; index++)
3773 /* Output the element's initial value. */
3775 assemble_zeros (fieldsize);
3777 output_constant (val, fieldsize, align2);
3779 /* Count its size. */
3780 total_bytes += fieldsize;
3783 else if (field == 0 || !DECL_BIT_FIELD (field))
3785 /* An element that is not a bit-field. */
3787 unsigned HOST_WIDE_INT fieldsize;
3788 /* Since this structure is static,
3789 we know the positions are constant. */
3790 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
3791 unsigned int align2;
3794 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
3795 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
3797 /* Output any buffered-up bit-fields preceding this element. */
3798 if (byte_buffer_in_use)
3800 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3802 byte_buffer_in_use = 0;
3805 /* Advance to offset of this element.
3806 Note no alignment needed in an array, since that is guaranteed
3807 if each element has the proper size. */
3808 if ((field != 0 || index != 0) && pos != total_bytes)
3810 assemble_zeros (pos - total_bytes);
3814 /* Find the alignment of this element. */
3815 align2 = min_align (align, BITS_PER_UNIT * pos);
3817 /* Determine size this element should occupy. */
3822 /* If this is an array with an unspecified upper bound,
3823 the initializer determines the size. */
3824 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
3825 but we cannot do this until the deprecated support for
3826 initializing zero-length array members is removed. */
3827 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
3828 && TYPE_DOMAIN (TREE_TYPE (field))
3829 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
3831 fieldsize = array_size_for_constructor (val);
3832 /* Given a non-empty initialization, this field had
3834 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
3837 else if (DECL_SIZE_UNIT (field))
3839 /* ??? This can't be right. If the decl size overflows
3840 a host integer we will silently emit no data. */
3841 if (host_integerp (DECL_SIZE_UNIT (field), 1))
3842 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
3846 fieldsize = int_size_in_bytes (TREE_TYPE (type));
3848 /* Output the element's initial value. */
3850 assemble_zeros (fieldsize);
3852 output_constant (val, fieldsize, align2);
3854 /* Count its size. */
3855 total_bytes += fieldsize;
3857 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3858 error ("invalid initial value for member `%s'",
3859 IDENTIFIER_POINTER (DECL_NAME (field)));
3862 /* Element that is a bit-field. */
3864 HOST_WIDE_INT next_offset = int_bit_position (field);
3865 HOST_WIDE_INT end_offset
3866 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
3869 val = integer_zero_node;
3871 /* If this field does not start in this (or, next) byte,
3873 if (next_offset / BITS_PER_UNIT != total_bytes)
3875 /* Output remnant of any bit field in previous bytes. */
3876 if (byte_buffer_in_use)
3878 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3880 byte_buffer_in_use = 0;
3883 /* If still not at proper byte, advance to there. */
3884 if (next_offset / BITS_PER_UNIT != total_bytes)
3886 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3887 total_bytes = next_offset / BITS_PER_UNIT;
3891 if (! byte_buffer_in_use)
3894 /* We must split the element into pieces that fall within
3895 separate bytes, and combine each byte with previous or
3896 following bit-fields. */
3898 /* next_offset is the offset n fbits from the beginning of
3899 the structure to the next bit of this element to be processed.
3900 end_offset is the offset of the first bit past the end of
3902 while (next_offset < end_offset)
3906 HOST_WIDE_INT value;
3907 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
3908 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
3910 /* Advance from byte to byte
3911 within this element when necessary. */
3912 while (next_byte != total_bytes)
3914 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3919 /* Number of bits we can process at once
3920 (all part of the same byte). */
3921 this_time = MIN (end_offset - next_offset,
3922 BITS_PER_UNIT - next_bit);
3923 if (BYTES_BIG_ENDIAN)
3925 /* On big-endian machine, take the most significant bits
3926 first (of the bits that are significant)
3927 and put them into bytes from the most significant end. */
3928 shift = end_offset - next_offset - this_time;
3930 /* Don't try to take a bunch of bits that cross
3931 the word boundary in the INTEGER_CST. We can
3932 only select bits from the LOW or HIGH part
3934 if (shift < HOST_BITS_PER_WIDE_INT
3935 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3937 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
3938 shift = HOST_BITS_PER_WIDE_INT;
3941 /* Now get the bits from the appropriate constant word. */
3942 if (shift < HOST_BITS_PER_WIDE_INT)
3943 value = TREE_INT_CST_LOW (val);
3944 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3946 value = TREE_INT_CST_HIGH (val);
3947 shift -= HOST_BITS_PER_WIDE_INT;
3952 /* Get the result. This works only when:
3953 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
3954 byte |= (((value >> shift)
3955 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
3956 << (BITS_PER_UNIT - this_time - next_bit));
3960 /* On little-endian machines,
3961 take first the least significant bits of the value
3962 and pack them starting at the least significant
3963 bits of the bytes. */
3964 shift = next_offset - int_bit_position (field);
3966 /* Don't try to take a bunch of bits that cross
3967 the word boundary in the INTEGER_CST. We can
3968 only select bits from the LOW or HIGH part
3970 if (shift < HOST_BITS_PER_WIDE_INT
3971 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3972 this_time = (HOST_BITS_PER_WIDE_INT - shift);
3974 /* Now get the bits from the appropriate constant word. */
3975 if (shift < HOST_BITS_PER_WIDE_INT)
3976 value = TREE_INT_CST_LOW (val);
3977 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3979 value = TREE_INT_CST_HIGH (val);
3980 shift -= HOST_BITS_PER_WIDE_INT;
3985 /* Get the result. This works only when:
3986 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
3987 byte |= (((value >> shift)
3988 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
3992 next_offset += this_time;
3993 byte_buffer_in_use = 1;
3998 if (byte_buffer_in_use)
4000 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4004 if ((unsigned HOST_WIDE_INT)total_bytes < size)
4005 assemble_zeros (size - total_bytes);
4008 /* This TREE_LIST contains any weak symbol declarations waiting
4010 static GTY(()) tree weak_decls;
4012 /* Mark DECL as weak. */
4015 mark_weak (tree decl)
4017 DECL_WEAK (decl) = 1;
4019 if (DECL_RTL_SET_P (decl)
4020 && GET_CODE (DECL_RTL (decl)) == MEM
4021 && XEXP (DECL_RTL (decl), 0)
4022 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4023 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4026 /* Merge weak status between NEWDECL and OLDDECL. */
4029 merge_weak (tree newdecl, tree olddecl)
4031 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4034 if (DECL_WEAK (newdecl))
4038 /* NEWDECL is weak, but OLDDECL is not. */
4040 /* If we already output the OLDDECL, we're in trouble; we can't
4041 go back and make it weak. This error cannot caught in
4042 declare_weak because the NEWDECL and OLDDECL was not yet
4043 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4044 if (TREE_ASM_WRITTEN (olddecl))
4045 error ("%Jweak declaration of '%D' must precede definition",
4048 /* If we've already generated rtl referencing OLDDECL, we may
4049 have done so in a way that will not function properly with
4051 else if (TREE_USED (olddecl)
4052 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4053 warning ("%Jweak declaration of '%D' after first use results "
4054 "in unspecified behavior", newdecl, newdecl);
4058 /* We put the NEWDECL on the weak_decls list at some point.
4059 Replace it with the OLDDECL. */
4060 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4061 if (TREE_VALUE (wd) == newdecl)
4063 TREE_VALUE (wd) = olddecl;
4066 /* We may not find the entry on the list. If NEWDECL is a
4067 weak alias, then we will have already called
4068 globalize_decl to remove the entry; in that case, we do
4069 not need to do anything. */
4072 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4073 mark_weak (olddecl);
4076 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4077 weak. Just update NEWDECL to indicate that it's weak too. */
4078 mark_weak (newdecl);
4081 /* Declare DECL to be a weak symbol. */
4084 declare_weak (tree decl)
4086 if (! TREE_PUBLIC (decl))
4087 error ("%Jweak declaration of '%D' must be public", decl, decl);
4088 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4089 error ("%Jweak declaration of '%D' must precede definition", decl, decl);
4090 else if (SUPPORTS_WEAK)
4092 if (! DECL_WEAK (decl))
4093 weak_decls = tree_cons (NULL, decl, weak_decls);
4096 warning ("%Jweak declaration of '%D' not supported", decl, decl);
4101 /* Emit any pending weak declarations. */
4108 for (t = weak_decls; t; t = TREE_CHAIN (t))
4110 tree decl = TREE_VALUE (t);
4111 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4112 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4115 if (! TREE_USED (decl))
4118 #ifdef ASM_WEAKEN_DECL
4119 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4121 #ifdef ASM_WEAKEN_LABEL
4122 ASM_WEAKEN_LABEL (asm_out_file, name);
4124 #ifdef ASM_OUTPUT_WEAK_ALIAS
4125 warning ("only weak aliases are supported in this configuration");
4133 /* Emit the assembly bits to indicate that DECL is globally visible. */
4136 globalize_decl (tree decl)
4138 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4140 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4141 if (DECL_WEAK (decl))
4145 #ifdef ASM_WEAKEN_DECL
4146 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4148 ASM_WEAKEN_LABEL (asm_out_file, name);
4151 /* Remove this function from the pending weak list so that
4152 we do not emit multiple .weak directives for it. */
4153 for (p = &weak_decls; (t = *p) ; )
4155 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4156 *p = TREE_CHAIN (t);
4158 p = &TREE_CHAIN (t);
4162 #elif defined(ASM_MAKE_LABEL_LINKONCE)
4163 if (DECL_ONE_ONLY (decl))
4164 ASM_MAKE_LABEL_LINKONCE (asm_out_file, name);
4167 targetm.asm_out.globalize_label (asm_out_file, name);
4170 /* Emit an assembler directive to make the symbol for DECL an alias to
4171 the symbol for TARGET. */
4174 assemble_alias (tree decl, tree target ATTRIBUTE_UNUSED)
4178 /* We must force creation of DECL_RTL for debug info generation, even though
4179 we don't use it here. */
4180 make_decl_rtl (decl, NULL);
4182 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4184 #ifdef ASM_OUTPUT_DEF
4185 /* Make name accessible from other files, if appropriate. */
4187 if (TREE_PUBLIC (decl))
4189 globalize_decl (decl);
4190 maybe_assemble_visibility (decl);
4193 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4194 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4196 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4198 #else /* !ASM_OUTPUT_DEF */
4199 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4200 if (DECL_WEAK (decl))
4203 #ifdef ASM_WEAKEN_DECL
4204 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4206 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4208 /* Remove this function from the pending weak list so that
4209 we do not emit multiple .weak directives for it. */
4210 for (p = &weak_decls; (t = *p) ; )
4211 if (DECL_ASSEMBLER_NAME (decl)
4212 == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4213 *p = TREE_CHAIN (t);
4215 p = &TREE_CHAIN (t);
4218 warning ("only weak aliases are supported in this configuration");
4221 warning ("alias definitions not supported in this configuration; ignored");
4225 TREE_USED (decl) = 1;
4226 TREE_ASM_WRITTEN (decl) = 1;
4227 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4230 /* Emit an assembler directive to set symbol for DECL visibility to
4231 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4234 default_assemble_visibility (tree decl, int vis)
4236 static const char * const visibility_types[] = {
4237 NULL, "internal", "hidden", "protected"
4240 const char *name, *type;
4242 name = (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4243 type = visibility_types[vis];
4245 #ifdef HAVE_GAS_HIDDEN
4246 fprintf (asm_out_file, "\t.%s\t", type);
4247 assemble_name (asm_out_file, name);
4248 fprintf (asm_out_file, "\n");
4250 warning ("visibility attribute not supported in this configuration; ignored");
4254 /* A helper function to call assemble_visibility when needed for a decl. */
4257 maybe_assemble_visibility (tree decl)
4259 enum symbol_visibility vis = DECL_VISIBILITY (decl);
4261 if (vis != VISIBILITY_DEFAULT)
4262 targetm.asm_out.visibility (decl, vis);
4265 /* Returns 1 if the target configuration supports defining public symbols
4266 so that one of them will be chosen at link time instead of generating a
4267 multiply-defined symbol error, whether through the use of weak symbols or
4268 a target-specific mechanism for having duplicates discarded. */
4271 supports_one_only (void)
4273 if (SUPPORTS_ONE_ONLY)
4275 return SUPPORTS_WEAK;
4278 /* Set up DECL as a public symbol that can be defined in multiple
4279 translation units without generating a linker error. */
4282 make_decl_one_only (tree decl)
4284 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4287 TREE_PUBLIC (decl) = 1;
4289 if (SUPPORTS_ONE_ONLY)
4291 #ifdef MAKE_DECL_ONE_ONLY
4292 MAKE_DECL_ONE_ONLY (decl);
4294 DECL_ONE_ONLY (decl) = 1;
4296 else if (TREE_CODE (decl) == VAR_DECL
4297 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4298 DECL_COMMON (decl) = 1;
4299 else if (SUPPORTS_WEAK)
4300 DECL_WEAK (decl) = 1;
4306 init_varasm_once (void)
4308 in_named_htab = htab_create_ggc (31, in_named_entry_hash,
4309 in_named_entry_eq, NULL);
4310 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
4311 const_desc_eq, NULL);
4313 const_alias_set = new_alias_set ();
4317 decl_tls_model (tree decl)
4319 enum tls_model kind;
4320 tree attr = lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl));
4325 attr = TREE_VALUE (TREE_VALUE (attr));
4326 if (TREE_CODE (attr) != STRING_CST)
4328 if (!strcmp (TREE_STRING_POINTER (attr), "local-exec"))
4329 kind = TLS_MODEL_LOCAL_EXEC;
4330 else if (!strcmp (TREE_STRING_POINTER (attr), "initial-exec"))
4331 kind = TLS_MODEL_INITIAL_EXEC;
4332 else if (!strcmp (TREE_STRING_POINTER (attr), "local-dynamic"))
4333 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
4334 else if (!strcmp (TREE_STRING_POINTER (attr), "global-dynamic"))
4335 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4341 is_local = targetm.binds_local_p (decl);
4345 kind = TLS_MODEL_LOCAL_EXEC;
4347 kind = TLS_MODEL_INITIAL_EXEC;
4349 /* Local dynamic is inefficient when we're not combining the
4350 parts of the address. */
4351 else if (optimize && is_local)
4352 kind = TLS_MODEL_LOCAL_DYNAMIC;
4354 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4355 if (kind < flag_tls_default)
4356 kind = flag_tls_default;
4361 /* Select a set of attributes for section NAME based on the properties
4362 of DECL and whether or not RELOC indicates that DECL's initializer
4363 might contain runtime relocations.
4365 We make the section read-only and executable for a function decl,
4366 read-only for a const data decl, and writable for a non-const data decl. */
4369 default_section_type_flags (tree decl, const char *name, int reloc)
4371 return default_section_type_flags_1 (decl, name, reloc, flag_pic);
4375 default_section_type_flags_1 (tree decl, const char *name, int reloc,
4380 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4381 flags = SECTION_CODE;
4382 else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
4384 else if (strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
4385 flags = SECTION_CODE;
4387 flags = SECTION_WRITE;
4389 if (decl && DECL_ONE_ONLY (decl))
4390 flags |= SECTION_LINKONCE;
4392 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4393 flags |= SECTION_TLS | SECTION_WRITE;
4395 if (strcmp (name, ".bss") == 0
4396 || strncmp (name, ".bss.", 5) == 0
4397 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
4398 || strcmp (name, ".sbss") == 0
4399 || strncmp (name, ".sbss.", 6) == 0
4400 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0
4401 || strcmp (name, ".tbss") == 0
4402 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4403 flags |= SECTION_BSS;
4405 if (strcmp (name, ".tdata") == 0
4406 || strcmp (name, ".tbss") == 0
4407 || strncmp (name, ".gnu.linkonce.td.", 17) == 0
4408 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4409 flags |= SECTION_TLS;
4411 /* These three sections have special ELF types. They are neither
4412 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4413 want to print a section type (@progbits or @nobits). If someone
4414 is silly enough to emit code or TLS variables to one of these
4415 sections, then don't handle them specially. */
4416 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
4417 && (strcmp (name, ".init_array") == 0
4418 || strcmp (name, ".fini_array") == 0
4419 || strcmp (name, ".preinit_array") == 0))
4420 flags |= SECTION_NOTYPE;
4425 /* Output assembly to switch to section NAME with attribute FLAGS.
4426 Four variants for common object file formats. */
4429 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
4430 unsigned int flags ATTRIBUTE_UNUSED)
4432 /* Some object formats don't support named sections at all. The
4433 front-end should already have flagged this as an error. */
4438 default_elf_asm_named_section (const char *name, unsigned int flags)
4440 char flagchars[10], *f = flagchars;
4442 if (! named_section_first_declaration (name))
4444 fprintf (asm_out_file, "\t.section\t%s\n", name);
4448 if (!(flags & SECTION_DEBUG))
4450 if (flags & SECTION_WRITE)
4452 if (flags & SECTION_CODE)
4454 if (flags & SECTION_SMALL)
4456 if (flags & SECTION_MERGE)
4458 if (flags & SECTION_STRINGS)
4460 if (flags & SECTION_TLS)
4464 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
4466 if (!(flags & SECTION_NOTYPE))
4470 if (flags & SECTION_BSS)
4475 fprintf (asm_out_file, ",@%s", type);
4477 if (flags & SECTION_ENTSIZE)
4478 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
4481 putc ('\n', asm_out_file);
4485 default_coff_asm_named_section (const char *name, unsigned int flags)
4487 char flagchars[8], *f = flagchars;
4489 if (flags & SECTION_WRITE)
4491 if (flags & SECTION_CODE)
4495 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
4499 default_pe_asm_named_section (const char *name, unsigned int flags)
4501 default_coff_asm_named_section (name, flags);
4503 if (flags & SECTION_LINKONCE)
4505 /* Functions may have been compiled at various levels of
4506 optimization so we can't use `same_size' here.
4507 Instead, have the linker pick one. */
4508 fprintf (asm_out_file, "\t.linkonce %s\n",
4509 (flags & SECTION_CODE ? "discard" : "same_size"));
4513 /* The lame default section selector. */
4516 default_select_section (tree decl, int reloc,
4517 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4519 bool readonly = false;
4523 if (decl_readonly_section (decl, reloc))
4526 else if (TREE_CODE (decl) == CONSTRUCTOR)
4528 if (! ((flag_pic && reloc)
4529 || !TREE_READONLY (decl)
4530 || TREE_SIDE_EFFECTS (decl)
4531 || !TREE_CONSTANT (decl)))
4534 else if (TREE_CODE (decl) == STRING_CST)
4536 else if (! (flag_pic && reloc))
4540 readonly_data_section ();
4545 /* A helper function for default_elf_select_section and
4546 default_elf_unique_section. Categorizes the DECL. */
4548 enum section_category
4553 SECCAT_RODATA_MERGE_STR,
4554 SECCAT_RODATA_MERGE_STR_INIT,
4555 SECCAT_RODATA_MERGE_CONST,
4560 /* To optimize loading of shared programs, define following subsections
4562 _REL Contains data that has relocations, so they get grouped
4563 together and dynamic linker will visit fewer pages in memory.
4564 _RO Contains data that is otherwise read-only. This is useful
4565 with prelinking as most relocations won't be dynamically
4566 linked and thus stay read only.
4567 _LOCAL Marks data containing relocations only to local objects.
4568 These relocations will get fully resolved by prelinking. */
4570 SECCAT_DATA_REL_LOCAL,
4572 SECCAT_DATA_REL_RO_LOCAL,
4582 static enum section_category
4583 categorize_decl_for_section (tree, int, int);
4585 static enum section_category
4586 categorize_decl_for_section (tree decl, int reloc, int shlib)
4588 enum section_category ret;
4590 if (TREE_CODE (decl) == FUNCTION_DECL)
4592 else if (TREE_CODE (decl) == STRING_CST)
4593 return SECCAT_RODATA_MERGE_STR;
4594 else if (TREE_CODE (decl) == VAR_DECL)
4596 if (DECL_INITIAL (decl) == NULL
4597 || DECL_INITIAL (decl) == error_mark_node)
4599 else if (! TREE_READONLY (decl)
4600 || TREE_SIDE_EFFECTS (decl)
4601 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
4603 if (shlib && (reloc & 2))
4604 ret = SECCAT_DATA_REL;
4605 else if (shlib && reloc)
4606 ret = SECCAT_DATA_REL_LOCAL;
4610 else if (shlib && (reloc & 2))
4611 ret = SECCAT_DATA_REL_RO;
4612 else if (shlib && reloc)
4613 ret = SECCAT_DATA_REL_RO_LOCAL;
4614 else if (reloc || flag_merge_constants < 2)
4615 /* C and C++ don't allow different variables to share the same
4616 location. -fmerge-all-constants allows even that (at the
4617 expense of not conforming). */
4618 ret = SECCAT_RODATA;
4619 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
4620 ret = SECCAT_RODATA_MERGE_STR_INIT;
4622 ret = SECCAT_RODATA_MERGE_CONST;
4624 else if (TREE_CODE (decl) == CONSTRUCTOR)
4626 if ((shlib && reloc)
4627 || TREE_SIDE_EFFECTS (decl)
4628 || ! TREE_CONSTANT (decl))
4631 ret = SECCAT_RODATA;
4634 ret = SECCAT_RODATA;
4636 /* There are no read-only thread-local sections. */
4637 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4639 if (ret == SECCAT_BSS)
4645 /* If the target uses small data sections, select it. */
4646 else if (targetm.in_small_data_p (decl))
4648 if (ret == SECCAT_BSS)
4650 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
4651 ret = SECCAT_SRODATA;
4660 decl_readonly_section (tree decl, int reloc)
4662 return decl_readonly_section_1 (decl, reloc, flag_pic);
4666 decl_readonly_section_1 (tree decl, int reloc, int shlib)
4668 switch (categorize_decl_for_section (decl, reloc, shlib))
4671 case SECCAT_RODATA_MERGE_STR:
4672 case SECCAT_RODATA_MERGE_STR_INIT:
4673 case SECCAT_RODATA_MERGE_CONST:
4674 case SECCAT_SRODATA:
4683 /* Select a section based on the above categorization. */
4686 default_elf_select_section (tree decl, int reloc,
4687 unsigned HOST_WIDE_INT align)
4689 default_elf_select_section_1 (decl, reloc, align, flag_pic);
4693 default_elf_select_section_1 (tree decl, int reloc,
4694 unsigned HOST_WIDE_INT align, int shlib)
4696 switch (categorize_decl_for_section (decl, reloc, shlib))
4699 /* We're not supposed to be called on FUNCTION_DECLs. */
4702 readonly_data_section ();
4704 case SECCAT_RODATA_MERGE_STR:
4705 mergeable_string_section (decl, align, 0);
4707 case SECCAT_RODATA_MERGE_STR_INIT:
4708 mergeable_string_section (DECL_INITIAL (decl), align, 0);
4710 case SECCAT_RODATA_MERGE_CONST:
4711 mergeable_constant_section (DECL_MODE (decl), align, 0);
4713 case SECCAT_SRODATA:
4714 named_section (NULL_TREE, ".sdata2", reloc);
4719 case SECCAT_DATA_REL:
4720 named_section (NULL_TREE, ".data.rel", reloc);
4722 case SECCAT_DATA_REL_LOCAL:
4723 named_section (NULL_TREE, ".data.rel.local", reloc);
4725 case SECCAT_DATA_REL_RO:
4726 named_section (NULL_TREE, ".data.rel.ro", reloc);
4728 case SECCAT_DATA_REL_RO_LOCAL:
4729 named_section (NULL_TREE, ".data.rel.ro.local", reloc);
4732 named_section (NULL_TREE, ".sdata", reloc);
4735 named_section (NULL_TREE, ".tdata", reloc);
4738 #ifdef BSS_SECTION_ASM_OP
4741 named_section (NULL_TREE, ".bss", reloc);
4745 named_section (NULL_TREE, ".sbss", reloc);
4748 named_section (NULL_TREE, ".tbss", reloc);
4755 /* Construct a unique section name based on the decl name and the
4756 categorization performed above. */
4759 default_unique_section (tree decl, int reloc)
4761 default_unique_section_1 (decl, reloc, flag_pic);
4765 default_unique_section_1 (tree decl, int reloc, int shlib)
4767 bool one_only = DECL_ONE_ONLY (decl);
4768 const char *prefix, *name;
4772 switch (categorize_decl_for_section (decl, reloc, shlib))
4775 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
4778 case SECCAT_RODATA_MERGE_STR:
4779 case SECCAT_RODATA_MERGE_STR_INIT:
4780 case SECCAT_RODATA_MERGE_CONST:
4781 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
4783 case SECCAT_SRODATA:
4784 prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
4787 case SECCAT_DATA_REL:
4788 case SECCAT_DATA_REL_LOCAL:
4789 case SECCAT_DATA_REL_RO:
4790 case SECCAT_DATA_REL_RO_LOCAL:
4791 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
4794 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
4797 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
4800 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
4803 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
4806 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
4811 plen = strlen (prefix);
4813 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4814 name = targetm.strip_name_encoding (name);
4815 nlen = strlen (name);
4817 string = alloca (nlen + plen + 1);
4818 memcpy (string, prefix, plen);
4819 memcpy (string + plen, name, nlen + 1);
4821 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
4825 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
4827 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4830 switch (GET_CODE (x))
4842 readonly_data_section ();
4846 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
4847 unsigned HOST_WIDE_INT align)
4849 /* ??? Handle small data here somehow. */
4852 switch (GET_CODE (x))
4856 named_section (NULL_TREE, ".data.rel.ro", 3);
4860 named_section (NULL_TREE, ".data.rel.ro.local", 1);
4867 mergeable_constant_section (mode, align, 0);
4870 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
4873 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
4878 /* Careful not to prod global register variables. */
4879 if (GET_CODE (rtl) != MEM)
4881 symbol = XEXP (rtl, 0);
4882 if (GET_CODE (symbol) != SYMBOL_REF)
4886 if (TREE_CODE (decl) == FUNCTION_DECL)
4887 flags |= SYMBOL_FLAG_FUNCTION;
4888 if (targetm.binds_local_p (decl))
4889 flags |= SYMBOL_FLAG_LOCAL;
4890 if (targetm.in_small_data_p (decl))
4891 flags |= SYMBOL_FLAG_SMALL;
4892 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4893 flags |= decl_tls_model (decl) << SYMBOL_FLAG_TLS_SHIFT;
4894 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
4895 being PUBLIC, the thing *must* be defined in this translation unit.
4896 Prevent this buglet from being propagated into rtl code as well. */
4897 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
4898 flags |= SYMBOL_FLAG_EXTERNAL;
4900 SYMBOL_REF_FLAGS (symbol) = flags;
4903 /* By default, we do nothing for encode_section_info, so we need not
4904 do anything but discard the '*' marker. */
4907 default_strip_name_encoding (const char *str)
4909 return str + (*str == '*');
4912 /* Assume ELF-ish defaults, since that's pretty much the most liberal
4913 wrt cross-module name binding. */
4916 default_binds_local_p (tree exp)
4918 return default_binds_local_p_1 (exp, flag_shlib);
4922 default_binds_local_p_1 (tree exp, int shlib)
4926 /* A non-decl is an entry in the constant pool. */
4929 /* Static variables are always local. */
4930 else if (! TREE_PUBLIC (exp))
4932 /* A variable is local if the user tells us so. */
4933 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
4935 /* Otherwise, variables defined outside this object may not be local. */
4936 else if (DECL_EXTERNAL (exp))
4938 /* Linkonce and weak data are never local. */
4939 else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
4941 /* If PIC, then assume that any global name can be overridden by
4942 symbols resolved from other modules. */
4945 /* Uninitialized COMMON variable may be unified with symbols
4946 resolved from other modules. */
4947 else if (DECL_COMMON (exp)
4948 && (DECL_INITIAL (exp) == NULL
4949 || DECL_INITIAL (exp) == error_mark_node))
4951 /* Otherwise we're left with initialized (or non-common) global data
4952 which is of necessity defined locally. */
4959 /* Determine whether or not a pointer mode is valid. Assume defaults
4960 of ptr_mode or Pmode - can be overridden. */
4962 default_valid_pointer_mode (enum machine_mode mode)
4964 return (mode == ptr_mode || mode == Pmode);
4967 /* Default function to output code that will globalize a label. A
4968 target must define GLOBAL_ASM_OP or provide it's own function to
4969 globalize a label. */
4970 #ifdef GLOBAL_ASM_OP
4972 default_globalize_label (FILE * stream, const char *name)
4974 fputs (GLOBAL_ASM_OP, stream);
4975 assemble_name (stream, name);
4976 putc ('\n', stream);
4978 #endif /* GLOBAL_ASM_OP */
4980 /* Default function to output a label for unwind information. The
4981 default is to do nothing. A target that needs nonlocal labels for
4982 unwind information must provide its own function to do this. */
4984 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
4985 tree decl ATTRIBUTE_UNUSED,
4986 int empty ATTRIBUTE_UNUSED)
4990 /* This is how to output an internal numbered label where PREFIX is
4991 the class of label and LABELNO is the number within the class. */
4994 default_internal_label (FILE *stream, const char *prefix,
4995 unsigned long labelno)
4997 char *const buf = alloca (40 + strlen (prefix));
4998 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
4999 ASM_OUTPUT_LABEL (stream, buf);
5002 /* This is the default behavior at the beginning of a file. It's
5003 controlled by two other target-hook toggles. */
5005 default_file_start (void)
5007 if (targetm.file_start_app_off && !flag_verbose_asm)
5008 fputs (ASM_APP_OFF, asm_out_file);
5010 if (targetm.file_start_file_directive)
5011 output_file_directive (asm_out_file, main_input_filename);
5014 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5015 which emits a special section directive used to indicate whether or
5016 not this object file needs an executable stack. This is primarily
5017 a GNU extension to ELF but could be used on other targets. */
5019 file_end_indicate_exec_stack (void)
5021 unsigned int flags = SECTION_DEBUG;
5022 if (trampolines_created)
5023 flags |= SECTION_CODE;
5025 named_section_flags (".note.GNU-stack", flags);
5028 #include "gt-varasm.h"