* target.h (asm_out.file_start, file_start_app_off,
[official-gcc.git] / gcc / varasm.c
bloba76d23ae1cb5f69dd6b6bbf22b7ae4c2a3b02921
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 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
10 version.
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
15 for more details.
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
20 02111-1307, USA. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
30 #include "config.h"
31 #include "system.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #include "rtl.h"
35 #include "tree.h"
36 #include "flags.h"
37 #include "function.h"
38 #include "expr.h"
39 #include "hard-reg-set.h"
40 #include "regs.h"
41 #include "real.h"
42 #include "output.h"
43 #include "toplev.h"
44 #include "hashtab.h"
45 #include "c-pragma.h"
46 #include "ggc.h"
47 #include "langhooks.h"
48 #include "tm_p.h"
49 #include "debug.h"
50 #include "target.h"
52 #ifdef XCOFF_DEBUGGING_INFO
53 #include "xcoffout.h" /* Needed for external data
54 declarations for e.g. AIX 4.x. */
55 #endif
57 #ifndef TRAMPOLINE_ALIGNMENT
58 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
59 #endif
61 #ifndef ASM_STABS_OP
62 #define ASM_STABS_OP "\t.stabs\t"
63 #endif
65 /* The (assembler) name of the first globally-visible object output. */
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
69 struct addr_const;
70 struct constant_descriptor_rtx;
71 struct rtx_const;
72 struct pool_constant;
74 #define MAX_RTX_HASH_TABLE 61
76 struct varasm_status GTY(())
78 /* Hash facility for making memory-constants
79 from constant rtl-expressions. It is used on RISC machines
80 where immediate integer arguments and constant addresses are restricted
81 so that such constants must be stored in memory.
83 This pool of constants is reinitialized for each function
84 so each function gets its own constants-pool that comes right before
85 it. */
86 struct constant_descriptor_rtx ** GTY ((length ("MAX_RTX_HASH_TABLE")))
87 x_const_rtx_hash_table;
88 struct pool_constant ** GTY ((length ("MAX_RTX_HASH_TABLE")))
89 x_const_rtx_sym_hash_table;
91 /* Pointers to first and last constant in pool. */
92 struct pool_constant *x_first_pool;
93 struct pool_constant *x_last_pool;
95 /* Current offset in constant pool (does not include any machine-specific
96 header). */
97 HOST_WIDE_INT x_pool_offset;
99 /* Number of tree-constants deferred during the expansion of this
100 function. */
101 unsigned int deferred_constants;
104 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
105 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
106 #define first_pool (cfun->varasm->x_first_pool)
107 #define last_pool (cfun->varasm->x_last_pool)
108 #define pool_offset (cfun->varasm->x_pool_offset)
109 #define n_deferred_constants (cfun->varasm->deferred_constants)
111 /* Number for making the label on the next
112 constant that is stored in memory. */
114 static GTY(()) int const_labelno;
116 /* Number for making the label on the next
117 static variable internal to a function. */
119 static GTY(()) int var_labelno;
121 /* Carry information from ASM_DECLARE_OBJECT_NAME
122 to ASM_FINISH_DECLARE_OBJECT. */
124 int size_directive_output;
126 /* The last decl for which assemble_variable was called,
127 if it did ASM_DECLARE_OBJECT_NAME.
128 If the last call to assemble_variable didn't do that,
129 this holds 0. */
131 tree last_assemble_variable_decl;
133 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
134 So giving constant the alias set for the type will allow such
135 initializations to appear to conflict with the load of the constant. We
136 avoid this by giving all constants an alias set for just constants.
137 Since there will be no stores to that alias set, nothing will ever
138 conflict with them. */
140 static HOST_WIDE_INT const_alias_set;
142 static const char *strip_reg_name PARAMS ((const char *));
143 static int contains_pointers_p PARAMS ((tree));
144 static void decode_addr_const PARAMS ((tree, struct addr_const *));
145 static hashval_t const_desc_hash PARAMS ((const void *));
146 static int const_desc_eq PARAMS ((const void *, const void *));
147 static hashval_t const_hash_1 PARAMS ((const tree));
148 static int compare_constant PARAMS ((const tree, const tree));
149 static tree copy_constant PARAMS ((tree));
150 static void output_constant_def_contents PARAMS ((rtx));
151 static void decode_rtx_const PARAMS ((enum machine_mode, rtx,
152 struct rtx_const *));
153 static unsigned int const_hash_rtx PARAMS ((enum machine_mode, rtx));
154 static int compare_constant_rtx
155 PARAMS ((enum machine_mode, rtx, struct constant_descriptor_rtx *));
156 static struct constant_descriptor_rtx * record_constant_rtx
157 PARAMS ((enum machine_mode, rtx));
158 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
159 static void mark_constant_pool PARAMS ((void));
160 static void mark_constants PARAMS ((rtx));
161 static int mark_constant PARAMS ((rtx *current_rtx, void *data));
162 static int output_addressed_constants PARAMS ((tree));
163 static unsigned HOST_WIDE_INT array_size_for_constructor PARAMS ((tree));
164 static unsigned min_align PARAMS ((unsigned, unsigned));
165 static void output_constructor PARAMS ((tree, unsigned HOST_WIDE_INT,
166 unsigned int));
167 static void globalize_decl PARAMS ((tree));
168 static void maybe_assemble_visibility PARAMS ((tree));
169 static int in_named_entry_eq PARAMS ((const void *, const void *));
170 static hashval_t in_named_entry_hash PARAMS ((const void *));
171 #ifdef ASM_OUTPUT_BSS
172 static void asm_output_bss PARAMS ((FILE *, tree, const char *,
173 unsigned HOST_WIDE_INT,
174 unsigned HOST_WIDE_INT));
175 #endif
176 #ifdef BSS_SECTION_ASM_OP
177 #ifdef ASM_OUTPUT_ALIGNED_BSS
178 static void asm_output_aligned_bss
179 PARAMS ((FILE *, tree, const char *,
180 unsigned HOST_WIDE_INT, int)) ATTRIBUTE_UNUSED;
181 #endif
182 #endif /* BSS_SECTION_ASM_OP */
183 static bool asm_emit_uninitialised PARAMS ((tree, const char*,
184 unsigned HOST_WIDE_INT,
185 unsigned HOST_WIDE_INT));
186 static void resolve_unique_section PARAMS ((tree, int, int));
187 static void mark_weak PARAMS ((tree));
189 enum in_section { no_section, in_text, in_data, in_named
190 #ifdef BSS_SECTION_ASM_OP
191 , in_bss
192 #endif
193 #ifdef CTORS_SECTION_ASM_OP
194 , in_ctors
195 #endif
196 #ifdef DTORS_SECTION_ASM_OP
197 , in_dtors
198 #endif
199 #ifdef READONLY_DATA_SECTION_ASM_OP
200 , in_readonly_data
201 #endif
202 #ifdef EXTRA_SECTIONS
203 , EXTRA_SECTIONS
204 #endif
206 static GTY(()) enum in_section in_section = no_section;
208 /* Return a nonzero value if DECL has a section attribute. */
209 #ifndef IN_NAMED_SECTION
210 #define IN_NAMED_SECTION(DECL) \
211 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
212 && DECL_SECTION_NAME (DECL) != NULL_TREE)
213 #endif
215 /* Text of section name when in_section == in_named. */
216 static GTY(()) const char *in_named_name;
218 /* Hash table of flags that have been used for a particular named section. */
220 struct in_named_entry GTY(())
222 const char *name;
223 unsigned int flags;
224 bool declared;
227 static GTY((param_is (struct in_named_entry))) htab_t in_named_htab;
229 /* Define functions like text_section for any extra sections. */
230 #ifdef EXTRA_SECTION_FUNCTIONS
231 EXTRA_SECTION_FUNCTIONS
232 #endif
234 /* Tell assembler to switch to text section. */
236 void
237 text_section ()
239 if (in_section != in_text)
241 in_section = in_text;
242 #ifdef TEXT_SECTION
243 TEXT_SECTION ();
244 #else
245 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
246 #endif
250 /* Tell assembler to switch to data section. */
252 void
253 data_section ()
255 if (in_section != in_data)
257 in_section = in_data;
258 if (flag_shared_data)
260 #ifdef SHARED_SECTION_ASM_OP
261 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
262 #else
263 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
264 #endif
266 else
267 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
271 /* Tell assembler to switch to read-only data section. This is normally
272 the text section. */
274 void
275 readonly_data_section ()
277 #ifdef READONLY_DATA_SECTION
278 READONLY_DATA_SECTION (); /* Note this can call data_section. */
279 #else
280 #ifdef READONLY_DATA_SECTION_ASM_OP
281 if (in_section != in_readonly_data)
283 in_section = in_readonly_data;
284 fputs (READONLY_DATA_SECTION_ASM_OP, asm_out_file);
285 fputc ('\n', asm_out_file);
287 #else
288 text_section ();
289 #endif
290 #endif
293 /* Determine if we're in the text section. */
296 in_text_section ()
298 return in_section == in_text;
301 /* Determine if we're in the data section. */
304 in_data_section ()
306 return in_section == in_data;
309 /* Helper routines for maintaining in_named_htab. */
311 static int
312 in_named_entry_eq (p1, p2)
313 const void *p1;
314 const void *p2;
316 const struct in_named_entry *old = p1;
317 const char *new = p2;
319 return strcmp (old->name, new) == 0;
322 static hashval_t
323 in_named_entry_hash (p)
324 const void *p;
326 const struct in_named_entry *old = p;
327 return htab_hash_string (old->name);
330 /* If SECTION has been seen before as a named section, return the flags
331 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
332 set of flags for a section to have, so 0 does not mean that the section
333 has not been seen. */
335 unsigned int
336 get_named_section_flags (section)
337 const char *section;
339 struct in_named_entry **slot;
341 slot = (struct in_named_entry **)
342 htab_find_slot_with_hash (in_named_htab, section,
343 htab_hash_string (section), NO_INSERT);
345 return slot ? (*slot)->flags : 0;
348 /* Returns true if the section has been declared before. Sets internal
349 flag on this section in in_named_hash so subsequent calls on this
350 section will return false. */
352 bool
353 named_section_first_declaration (name)
354 const char *name;
356 struct in_named_entry **slot;
358 slot = (struct in_named_entry **)
359 htab_find_slot_with_hash (in_named_htab, name,
360 htab_hash_string (name), NO_INSERT);
361 if (! (*slot)->declared)
363 (*slot)->declared = true;
364 return true;
366 else
368 return false;
373 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
374 different set of flags, return false. */
376 bool
377 set_named_section_flags (section, flags)
378 const char *section;
379 unsigned int flags;
381 struct in_named_entry **slot, *entry;
383 slot = (struct in_named_entry **)
384 htab_find_slot_with_hash (in_named_htab, section,
385 htab_hash_string (section), INSERT);
386 entry = *slot;
388 if (!entry)
390 entry = (struct in_named_entry *) ggc_alloc (sizeof (*entry));
391 *slot = entry;
392 entry->name = ggc_strdup (section);
393 entry->flags = flags;
394 entry->declared = false;
396 else if (entry->flags != flags)
397 return false;
399 return true;
402 /* Tell assembler to change to section NAME with attributes FLAGS. */
404 void
405 named_section_flags (name, flags)
406 const char *name;
407 unsigned int flags;
409 if (in_section != in_named || strcmp (name, in_named_name) != 0)
411 if (! set_named_section_flags (name, flags))
412 abort ();
414 (*targetm.asm_out.named_section) (name, flags);
416 if (flags & SECTION_FORGET)
417 in_section = no_section;
418 else
420 in_named_name = ggc_strdup (name);
421 in_section = in_named;
426 /* Tell assembler to change to section NAME for DECL.
427 If DECL is NULL, just switch to section NAME.
428 If NAME is NULL, get the name from DECL.
429 If RELOC is 1, the initializer for DECL contains relocs. */
431 void
432 named_section (decl, name, reloc)
433 tree decl;
434 const char *name;
435 int reloc;
437 unsigned int flags;
439 if (decl != NULL_TREE && !DECL_P (decl))
440 abort ();
441 if (name == NULL)
442 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
444 flags = (* targetm.section_type_flags) (decl, name, reloc);
446 /* Sanity check user variables for flag changes. Non-user
447 section flag changes will abort in named_section_flags.
448 However, don't complain if SECTION_OVERRIDE is set.
449 We trust that the setter knows that it is safe to ignore
450 the default flags for this decl. */
451 if (decl && ! set_named_section_flags (name, flags))
453 flags = get_named_section_flags (name);
454 if ((flags & SECTION_OVERRIDE) == 0)
455 error_with_decl (decl, "%s causes a section type conflict");
458 named_section_flags (name, flags);
461 /* If required, set DECL_SECTION_NAME to a unique name. */
463 static void
464 resolve_unique_section (decl, reloc, flag_function_or_data_sections)
465 tree decl;
466 int reloc ATTRIBUTE_UNUSED;
467 int flag_function_or_data_sections;
469 if (DECL_SECTION_NAME (decl) == NULL_TREE
470 && targetm.have_named_sections
471 && (flag_function_or_data_sections
472 || DECL_ONE_ONLY (decl)))
473 (*targetm.asm_out.unique_section) (decl, reloc);
476 #ifdef BSS_SECTION_ASM_OP
478 /* Tell the assembler to switch to the bss section. */
480 void
481 bss_section ()
483 if (in_section != in_bss)
485 #ifdef SHARED_BSS_SECTION_ASM_OP
486 if (flag_shared_data)
487 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
488 else
489 #endif
490 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
492 in_section = in_bss;
496 #ifdef ASM_OUTPUT_BSS
498 /* Utility function for ASM_OUTPUT_BSS for targets to use if
499 they don't support alignments in .bss.
500 ??? It is believed that this function will work in most cases so such
501 support is localized here. */
503 static void
504 asm_output_bss (file, decl, name, size, rounded)
505 FILE *file;
506 tree decl ATTRIBUTE_UNUSED;
507 const char *name;
508 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, rounded;
510 (*targetm.asm_out.globalize_label) (file, name);
511 bss_section ();
512 #ifdef ASM_DECLARE_OBJECT_NAME
513 last_assemble_variable_decl = decl;
514 ASM_DECLARE_OBJECT_NAME (file, name, decl);
515 #else
516 /* Standard thing is just output label for the object. */
517 ASM_OUTPUT_LABEL (file, name);
518 #endif /* ASM_DECLARE_OBJECT_NAME */
519 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
522 #endif
524 #ifdef ASM_OUTPUT_ALIGNED_BSS
526 /* Utility function for targets to use in implementing
527 ASM_OUTPUT_ALIGNED_BSS.
528 ??? It is believed that this function will work in most cases so such
529 support is localized here. */
531 static void
532 asm_output_aligned_bss (file, decl, name, size, align)
533 FILE *file;
534 tree decl ATTRIBUTE_UNUSED;
535 const char *name;
536 unsigned HOST_WIDE_INT size;
537 int align;
539 bss_section ();
540 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
541 #ifdef ASM_DECLARE_OBJECT_NAME
542 last_assemble_variable_decl = decl;
543 ASM_DECLARE_OBJECT_NAME (file, name, decl);
544 #else
545 /* Standard thing is just output label for the object. */
546 ASM_OUTPUT_LABEL (file, name);
547 #endif /* ASM_DECLARE_OBJECT_NAME */
548 ASM_OUTPUT_SKIP (file, size ? size : 1);
551 #endif
553 #endif /* BSS_SECTION_ASM_OP */
555 /* Switch to the section for function DECL.
557 If DECL is NULL_TREE, switch to the text section.
558 ??? It's not clear that we will ever be passed NULL_TREE, but it's
559 safer to handle it. */
561 void
562 function_section (decl)
563 tree decl;
565 if (decl != NULL_TREE
566 && DECL_SECTION_NAME (decl) != NULL_TREE)
567 named_section (decl, (char *) 0, 0);
568 else
569 text_section ();
572 /* Switch to section for variable DECL. RELOC is the same as the
573 argument to SELECT_SECTION. */
575 void
576 variable_section (decl, reloc)
577 tree decl;
578 int reloc;
580 if (IN_NAMED_SECTION (decl))
581 named_section (decl, NULL, reloc);
582 else
583 (*targetm.asm_out.select_section) (decl, reloc, DECL_ALIGN (decl));
586 /* Tell assembler to switch to the section for string merging. */
588 void
589 mergeable_string_section (decl, align, flags)
590 tree decl ATTRIBUTE_UNUSED;
591 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
592 unsigned int flags ATTRIBUTE_UNUSED;
594 #ifdef HAVE_GAS_SHF_MERGE
595 if (flag_merge_constants
596 && TREE_CODE (decl) == STRING_CST
597 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
598 && align <= 256
599 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
601 enum machine_mode mode;
602 unsigned int modesize;
603 const char *str;
604 int i, j, len, unit;
605 char name[30];
607 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
608 modesize = GET_MODE_BITSIZE (mode);
609 if (modesize >= 8 && modesize <= 256
610 && (modesize & (modesize - 1)) == 0)
612 if (align < modesize)
613 align = modesize;
615 str = TREE_STRING_POINTER (decl);
616 len = TREE_STRING_LENGTH (decl);
617 unit = GET_MODE_SIZE (mode);
619 /* Check for embedded NUL characters. */
620 for (i = 0; i < len; i += unit)
622 for (j = 0; j < unit; j++)
623 if (str[i + j] != '\0')
624 break;
625 if (j == unit)
626 break;
628 if (i == len - unit)
630 sprintf (name, ".rodata.str%d.%d", modesize / 8,
631 (int) (align / 8));
632 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
633 if (!i && modesize < align)
635 /* A "" string with requested alignment greater than
636 character size might cause a problem:
637 if some other string required even bigger
638 alignment than "", then linker might think the
639 "" is just part of padding after some other string
640 and not put it into the hash table initially.
641 But this means "" could have smaller alignment
642 than requested. */
643 #ifdef ASM_OUTPUT_SECTION_START
644 named_section_flags (name, flags);
645 ASM_OUTPUT_SECTION_START (asm_out_file);
646 #else
647 readonly_data_section ();
648 #endif
649 return;
652 named_section_flags (name, flags);
653 return;
657 #endif
658 readonly_data_section ();
661 /* Tell assembler to switch to the section for constant merging. */
663 void
664 mergeable_constant_section (mode, align, flags)
665 enum machine_mode mode ATTRIBUTE_UNUSED;
666 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
667 unsigned int flags ATTRIBUTE_UNUSED;
669 #ifdef HAVE_GAS_SHF_MERGE
670 unsigned int modesize = GET_MODE_BITSIZE (mode);
672 if (flag_merge_constants
673 && mode != VOIDmode
674 && mode != BLKmode
675 && modesize <= align
676 && align >= 8
677 && align <= 256
678 && (align & (align - 1)) == 0)
680 char name[24];
682 sprintf (name, ".rodata.cst%d", (int) (align / 8));
683 flags |= (align / 8) | SECTION_MERGE;
684 named_section_flags (name, flags);
685 return;
687 #endif
688 readonly_data_section ();
691 /* Given NAME, a putative register name, discard any customary prefixes. */
693 static const char *
694 strip_reg_name (name)
695 const char *name;
697 #ifdef REGISTER_PREFIX
698 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
699 name += strlen (REGISTER_PREFIX);
700 #endif
701 if (name[0] == '%' || name[0] == '#')
702 name++;
703 return name;
706 /* Decode an `asm' spec for a declaration as a register name.
707 Return the register number, or -1 if nothing specified,
708 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
709 or -3 if ASMSPEC is `cc' and is not recognized,
710 or -4 if ASMSPEC is `memory' and is not recognized.
711 Accept an exact spelling or a decimal number.
712 Prefixes such as % are optional. */
715 decode_reg_name (asmspec)
716 const char *asmspec;
718 if (asmspec != 0)
720 int i;
722 /* Get rid of confusing prefixes. */
723 asmspec = strip_reg_name (asmspec);
725 /* Allow a decimal number as a "register name". */
726 for (i = strlen (asmspec) - 1; i >= 0; i--)
727 if (! ISDIGIT (asmspec[i]))
728 break;
729 if (asmspec[0] != 0 && i < 0)
731 i = atoi (asmspec);
732 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
733 return i;
734 else
735 return -2;
738 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
739 if (reg_names[i][0]
740 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
741 return i;
743 #ifdef ADDITIONAL_REGISTER_NAMES
745 static const struct { const char *const name; const int number; } table[]
746 = ADDITIONAL_REGISTER_NAMES;
748 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
749 if (! strcmp (asmspec, table[i].name))
750 return table[i].number;
752 #endif /* ADDITIONAL_REGISTER_NAMES */
754 if (!strcmp (asmspec, "memory"))
755 return -4;
757 if (!strcmp (asmspec, "cc"))
758 return -3;
760 return -2;
763 return -1;
766 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
767 have static storage duration. In other words, it should not be an
768 automatic variable, including PARM_DECLs.
770 There is, however, one exception: this function handles variables
771 explicitly placed in a particular register by the user.
773 ASMSPEC, if not 0, is the string which the user specified as the
774 assembler symbol name.
776 This is never called for PARM_DECL nodes. */
778 void
779 make_decl_rtl (decl, asmspec)
780 tree decl;
781 const char *asmspec;
783 int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
784 const char *name = 0;
785 const char *new_name = 0;
786 int reg_number;
787 rtx x;
789 /* Check that we are not being given an automatic variable. */
790 /* A weak alias has TREE_PUBLIC set but not the other bits. */
791 if (TREE_CODE (decl) == PARM_DECL
792 || TREE_CODE (decl) == RESULT_DECL
793 || (TREE_CODE (decl) == VAR_DECL
794 && !TREE_STATIC (decl)
795 && !TREE_PUBLIC (decl)
796 && !DECL_EXTERNAL (decl)
797 && !DECL_REGISTER (decl)))
798 abort ();
799 /* And that we were not given a type or a label. */
800 else if (TREE_CODE (decl) == TYPE_DECL
801 || TREE_CODE (decl) == LABEL_DECL)
802 abort ();
804 /* For a duplicate declaration, we can be called twice on the
805 same DECL node. Don't discard the RTL already made. */
806 if (DECL_RTL_SET_P (decl))
808 /* If the old RTL had the wrong mode, fix the mode. */
809 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
810 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
811 DECL_MODE (decl), 0));
813 /* ??? Another way to do this would be to maintain a hashed
814 table of such critters. Instead of adding stuff to a DECL
815 to give certain attributes to it, we could use an external
816 hash map from DECL to set of attributes. */
818 /* Let the target reassign the RTL if it wants.
819 This is necessary, for example, when one machine specific
820 decl attribute overrides another. */
821 (* targetm.encode_section_info) (decl, DECL_RTL (decl), false);
822 return;
825 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
827 reg_number = decode_reg_name (asmspec);
828 if (reg_number == -2)
830 /* ASMSPEC is given, and not the name of a register. Mark the
831 name with a star so assemble_name won't munge it. */
832 char *starred = alloca (strlen (asmspec) + 2);
833 starred[0] = '*';
834 strcpy (starred + 1, asmspec);
835 new_name = starred;
838 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
840 /* First detect errors in declaring global registers. */
841 if (reg_number == -1)
842 error_with_decl (decl, "register name not specified for `%s'");
843 else if (reg_number < 0)
844 error_with_decl (decl, "invalid register name for `%s'");
845 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
846 error_with_decl (decl,
847 "data type of `%s' isn't suitable for a register");
848 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
849 error_with_decl (decl,
850 "register specified for `%s' isn't suitable for data type");
851 /* Now handle properly declared static register variables. */
852 else
854 int nregs;
856 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
858 DECL_INITIAL (decl) = 0;
859 error ("global register variable has initial value");
861 if (TREE_THIS_VOLATILE (decl))
862 warning ("volatile register variables don't work as you might wish");
864 /* If the user specified one of the eliminables registers here,
865 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
866 confused with that register and be eliminated. This usage is
867 somewhat suspect... */
869 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
870 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
871 REG_USERVAR_P (DECL_RTL (decl)) = 1;
873 if (TREE_STATIC (decl))
875 /* Make this register global, so not usable for anything
876 else. */
877 #ifdef ASM_DECLARE_REGISTER_GLOBAL
878 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
879 #endif
880 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
881 while (nregs > 0)
882 globalize_reg (reg_number + --nregs);
885 /* As a register variable, it has no section. */
886 return;
890 /* Now handle ordinary static variables and functions (in memory).
891 Also handle vars declared register invalidly. */
893 if (reg_number >= 0 || reg_number == -3)
894 error_with_decl (decl,
895 "register name given for non-register variable `%s'");
897 /* Specifying a section attribute on a variable forces it into a
898 non-.bss section, and thus it cannot be common. */
899 if (TREE_CODE (decl) == VAR_DECL
900 && DECL_SECTION_NAME (decl) != NULL_TREE
901 && DECL_INITIAL (decl) == NULL_TREE
902 && DECL_COMMON (decl))
903 DECL_COMMON (decl) = 0;
905 /* Variables can't be both common and weak. */
906 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
907 DECL_COMMON (decl) = 0;
909 /* Can't use just the variable's own name for a variable
910 whose scope is less than the whole file, unless it's a member
911 of a local class (which will already be unambiguous).
912 Concatenate a distinguishing number. */
913 if (!top_level && !TREE_PUBLIC (decl)
914 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
915 && asmspec == 0
916 && name == IDENTIFIER_POINTER (DECL_NAME (decl)))
918 char *label;
920 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
921 var_labelno++;
922 new_name = label;
925 if (name != new_name)
927 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
928 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
931 x = gen_rtx_SYMBOL_REF (Pmode, name);
932 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
933 SYMBOL_REF_DECL (x) = decl;
935 x = gen_rtx_MEM (DECL_MODE (decl), x);
936 if (TREE_CODE (decl) != FUNCTION_DECL)
937 set_mem_attributes (x, decl, 1);
938 SET_DECL_RTL (decl, x);
940 /* Optionally set flags or add text to the name to record information
941 such as that it is a function name.
942 If the name is changed, the macro ASM_OUTPUT_LABELREF
943 will have to know how to strip this information. */
944 (* targetm.encode_section_info) (decl, DECL_RTL (decl), true);
947 /* Make the rtl for variable VAR be volatile.
948 Use this only for static variables. */
950 void
951 make_var_volatile (var)
952 tree var;
954 if (GET_CODE (DECL_RTL (var)) != MEM)
955 abort ();
957 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
960 /* Output a string of literal assembler code
961 for an `asm' keyword used between functions. */
963 void
964 assemble_asm (string)
965 tree string;
967 app_enable ();
969 if (TREE_CODE (string) == ADDR_EXPR)
970 string = TREE_OPERAND (string, 0);
972 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
975 /* Record an element in the table of global destructors. SYMBOL is
976 a SYMBOL_REF of the function to be called; PRIORITY is a number
977 between 0 and MAX_INIT_PRIORITY. */
979 void
980 default_stabs_asm_out_destructor (symbol, priority)
981 rtx symbol;
982 int priority ATTRIBUTE_UNUSED;
984 /* Tell GNU LD that this is part of the static destructor set.
985 This will work for any system that uses stabs, most usefully
986 aout systems. */
987 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
988 assemble_name (asm_out_file, XSTR (symbol, 0));
989 fputc ('\n', asm_out_file);
992 void
993 default_named_section_asm_out_destructor (symbol, priority)
994 rtx symbol;
995 int priority;
997 const char *section = ".dtors";
998 char buf[16];
1000 /* ??? This only works reliably with the GNU linker. */
1001 if (priority != DEFAULT_INIT_PRIORITY)
1003 sprintf (buf, ".dtors.%.5u",
1004 /* Invert the numbering so the linker puts us in the proper
1005 order; constructors are run from right to left, and the
1006 linker sorts in increasing order. */
1007 MAX_INIT_PRIORITY - priority);
1008 section = buf;
1011 named_section_flags (section, SECTION_WRITE);
1012 assemble_align (POINTER_SIZE);
1013 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1016 #ifdef DTORS_SECTION_ASM_OP
1017 void
1018 dtors_section ()
1020 if (in_section != in_dtors)
1022 in_section = in_dtors;
1023 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1024 fputc ('\n', asm_out_file);
1028 void
1029 default_dtor_section_asm_out_destructor (symbol, priority)
1030 rtx symbol;
1031 int priority ATTRIBUTE_UNUSED;
1033 dtors_section ();
1034 assemble_align (POINTER_SIZE);
1035 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1037 #endif
1039 /* Likewise for global constructors. */
1041 void
1042 default_stabs_asm_out_constructor (symbol, priority)
1043 rtx symbol;
1044 int priority ATTRIBUTE_UNUSED;
1046 /* Tell GNU LD that this is part of the static destructor set.
1047 This will work for any system that uses stabs, most usefully
1048 aout systems. */
1049 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1050 assemble_name (asm_out_file, XSTR (symbol, 0));
1051 fputc ('\n', asm_out_file);
1054 void
1055 default_named_section_asm_out_constructor (symbol, priority)
1056 rtx symbol;
1057 int priority;
1059 const char *section = ".ctors";
1060 char buf[16];
1062 /* ??? This only works reliably with the GNU linker. */
1063 if (priority != DEFAULT_INIT_PRIORITY)
1065 sprintf (buf, ".ctors.%.5u",
1066 /* Invert the numbering so the linker puts us in the proper
1067 order; constructors are run from right to left, and the
1068 linker sorts in increasing order. */
1069 MAX_INIT_PRIORITY - priority);
1070 section = buf;
1073 named_section_flags (section, SECTION_WRITE);
1074 assemble_align (POINTER_SIZE);
1075 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1078 #ifdef CTORS_SECTION_ASM_OP
1079 void
1080 ctors_section ()
1082 if (in_section != in_ctors)
1084 in_section = in_ctors;
1085 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1086 fputc ('\n', asm_out_file);
1090 void
1091 default_ctor_section_asm_out_constructor (symbol, priority)
1092 rtx symbol;
1093 int priority ATTRIBUTE_UNUSED;
1095 ctors_section ();
1096 assemble_align (POINTER_SIZE);
1097 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1099 #endif
1101 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1102 a nonzero value if the constant pool should be output before the
1103 start of the function, or a zero value if the pool should output
1104 after the end of the function. The default is to put it before the
1105 start. */
1107 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1108 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1109 #endif
1111 /* Output assembler code for the constant pool of a function and associated
1112 with defining the name of the function. DECL describes the function.
1113 NAME is the function's name. For the constant pool, we use the current
1114 constant pool data. */
1116 void
1117 assemble_start_function (decl, fnname)
1118 tree decl;
1119 const char *fnname;
1121 int align;
1123 /* The following code does not need preprocessing in the assembler. */
1125 app_disable ();
1127 if (CONSTANT_POOL_BEFORE_FUNCTION)
1128 output_constant_pool (fnname, decl);
1130 resolve_unique_section (decl, 0, flag_function_sections);
1131 function_section (decl);
1133 /* Tell assembler to move to target machine's alignment for functions. */
1134 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1135 if (align < force_align_functions_log)
1136 align = force_align_functions_log;
1137 if (align > 0)
1139 ASM_OUTPUT_ALIGN (asm_out_file, align);
1142 /* Handle a user-specified function alignment.
1143 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1144 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1145 if (align_functions_log > align
1146 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1148 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1149 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1150 align_functions_log, align_functions - 1);
1151 #else
1152 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1153 #endif
1156 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1157 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1158 #endif
1160 (*debug_hooks->begin_function) (decl);
1162 /* Make function name accessible from other files, if appropriate. */
1164 if (TREE_PUBLIC (decl))
1166 if (! first_global_object_name)
1168 const char *p;
1169 char *name;
1171 p = (* targetm.strip_name_encoding) (fnname);
1172 name = xstrdup (p);
1174 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1175 first_global_object_name = name;
1176 else
1177 weak_global_object_name = name;
1180 globalize_decl (decl);
1182 maybe_assemble_visibility (decl);
1185 /* Do any machine/system dependent processing of the function name */
1186 #ifdef ASM_DECLARE_FUNCTION_NAME
1187 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1188 #else
1189 /* Standard thing is just output label for the function. */
1190 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1191 #endif /* ASM_DECLARE_FUNCTION_NAME */
1194 /* Output assembler code associated with defining the size of the
1195 function. DECL describes the function. NAME is the function's name. */
1197 void
1198 assemble_end_function (decl, fnname)
1199 tree decl;
1200 const char *fnname;
1202 #ifdef ASM_DECLARE_FUNCTION_SIZE
1203 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1204 #endif
1205 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1207 output_constant_pool (fnname, decl);
1208 function_section (decl); /* need to switch back */
1212 /* Assemble code to leave SIZE bytes of zeros. */
1214 void
1215 assemble_zeros (size)
1216 unsigned HOST_WIDE_INT size;
1218 /* Do no output if -fsyntax-only. */
1219 if (flag_syntax_only)
1220 return;
1222 #ifdef ASM_NO_SKIP_IN_TEXT
1223 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1224 so we must output 0s explicitly in the text section. */
1225 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1227 unsigned HOST_WIDE_INT i;
1228 for (i = 0; i < size; i++)
1229 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1231 else
1232 #endif
1233 if (size > 0)
1234 ASM_OUTPUT_SKIP (asm_out_file, size);
1237 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1239 void
1240 assemble_align (align)
1241 int align;
1243 if (align > BITS_PER_UNIT)
1245 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1249 /* Assemble a string constant with the specified C string as contents. */
1251 void
1252 assemble_string (p, size)
1253 const char *p;
1254 int size;
1256 int pos = 0;
1257 int maximum = 2000;
1259 /* If the string is very long, split it up. */
1261 while (pos < size)
1263 int thissize = size - pos;
1264 if (thissize > maximum)
1265 thissize = maximum;
1267 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1269 pos += thissize;
1270 p += thissize;
1275 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1276 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1277 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1278 #else
1279 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1280 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1281 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1282 #else
1283 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1284 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1285 #endif
1286 #endif
1288 #if defined ASM_OUTPUT_ALIGNED_BSS
1289 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1290 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1291 #else
1292 #if defined ASM_OUTPUT_BSS
1293 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1294 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1295 #else
1296 #undef ASM_EMIT_BSS
1297 #endif
1298 #endif
1300 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1301 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1302 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1303 #else
1304 #if defined ASM_OUTPUT_ALIGNED_COMMON
1305 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1306 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1307 #else
1308 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1309 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1310 #endif
1311 #endif
1313 static bool
1314 asm_emit_uninitialised (decl, name, size, rounded)
1315 tree decl;
1316 const char *name;
1317 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED;
1318 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED;
1320 enum
1322 asm_dest_common,
1323 asm_dest_bss,
1324 asm_dest_local
1326 destination = asm_dest_local;
1328 /* ??? We should handle .bss via select_section mechanisms rather than
1329 via special target hooks. That would eliminate this special case. */
1330 if (TREE_PUBLIC (decl))
1332 if (!DECL_COMMON (decl))
1333 #ifdef ASM_EMIT_BSS
1334 destination = asm_dest_bss;
1335 #else
1336 return false;
1337 #endif
1338 else
1339 destination = asm_dest_common;
1342 if (destination == asm_dest_bss)
1343 globalize_decl (decl);
1344 resolve_unique_section (decl, 0, flag_data_sections);
1346 if (flag_shared_data)
1348 switch (destination)
1350 #ifdef ASM_OUTPUT_SHARED_BSS
1351 case asm_dest_bss:
1352 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1353 return;
1354 #endif
1355 #ifdef ASM_OUTPUT_SHARED_COMMON
1356 case asm_dest_common:
1357 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1358 return;
1359 #endif
1360 #ifdef ASM_OUTPUT_SHARED_LOCAL
1361 case asm_dest_local:
1362 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1363 return;
1364 #endif
1365 default:
1366 break;
1370 switch (destination)
1372 #ifdef ASM_EMIT_BSS
1373 case asm_dest_bss:
1374 ASM_EMIT_BSS (decl, name, size, rounded);
1375 break;
1376 #endif
1377 case asm_dest_common:
1378 ASM_EMIT_COMMON (decl, name, size, rounded);
1379 break;
1380 case asm_dest_local:
1381 ASM_EMIT_LOCAL (decl, name, size, rounded);
1382 break;
1383 default:
1384 abort ();
1387 return true;
1390 /* Assemble everything that is needed for a variable or function declaration.
1391 Not used for automatic variables, and not used for function definitions.
1392 Should not be called for variables of incomplete structure type.
1394 TOP_LEVEL is nonzero if this variable has file scope.
1395 AT_END is nonzero if this is the special handling, at end of compilation,
1396 to define things that have had only tentative definitions.
1397 DONT_OUTPUT_DATA if nonzero means don't actually output the
1398 initial value (that will be done by the caller). */
1400 void
1401 assemble_variable (decl, top_level, at_end, dont_output_data)
1402 tree decl;
1403 int top_level ATTRIBUTE_UNUSED;
1404 int at_end ATTRIBUTE_UNUSED;
1405 int dont_output_data;
1407 const char *name;
1408 unsigned int align;
1409 int reloc = 0;
1410 rtx decl_rtl;
1412 last_assemble_variable_decl = 0;
1414 /* Normally no need to say anything here for external references,
1415 since assemble_external is called by the language-specific code
1416 when a declaration is first seen. */
1418 if (DECL_EXTERNAL (decl))
1419 return;
1421 /* Output no assembler code for a function declaration.
1422 Only definitions of functions output anything. */
1424 if (TREE_CODE (decl) == FUNCTION_DECL)
1425 return;
1427 /* Do nothing for global register variables. */
1428 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1430 TREE_ASM_WRITTEN (decl) = 1;
1431 return;
1434 /* If type was incomplete when the variable was declared,
1435 see if it is complete now. */
1437 if (DECL_SIZE (decl) == 0)
1438 layout_decl (decl, 0);
1440 /* Still incomplete => don't allocate it; treat the tentative defn
1441 (which is what it must have been) as an `extern' reference. */
1443 if (!dont_output_data && DECL_SIZE (decl) == 0)
1445 error ("%Hstorage size of `%s' isn't known",
1446 &DECL_SOURCE_LOCATION (decl),
1447 IDENTIFIER_POINTER (DECL_NAME (decl)));
1448 TREE_ASM_WRITTEN (decl) = 1;
1449 return;
1452 /* The first declaration of a variable that comes through this function
1453 decides whether it is global (in C, has external linkage)
1454 or local (in C, has internal linkage). So do nothing more
1455 if this function has already run. */
1457 if (TREE_ASM_WRITTEN (decl))
1458 return;
1460 /* Make sure targetm.encode_section_info is invoked before we set
1461 ASM_WRITTEN. */
1462 decl_rtl = DECL_RTL (decl);
1464 TREE_ASM_WRITTEN (decl) = 1;
1466 /* Do no output if -fsyntax-only. */
1467 if (flag_syntax_only)
1468 return;
1470 app_disable ();
1472 if (! dont_output_data
1473 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1475 error_with_decl (decl, "size of variable `%s' is too large");
1476 return;
1479 name = XSTR (XEXP (decl_rtl, 0), 0);
1480 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1481 && ! first_global_object_name
1482 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1483 || DECL_INITIAL (decl) == error_mark_node))
1484 && ! DECL_WEAK (decl)
1485 && ! DECL_ONE_ONLY (decl))
1487 const char *p;
1488 char *xname;
1490 p = (* targetm.strip_name_encoding) (name);
1491 xname = xstrdup (p);
1492 first_global_object_name = xname;
1495 /* Compute the alignment of this data. */
1497 align = DECL_ALIGN (decl);
1499 /* In the case for initialing an array whose length isn't specified,
1500 where we have not yet been able to do the layout,
1501 figure out the proper alignment now. */
1502 if (dont_output_data && DECL_SIZE (decl) == 0
1503 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1504 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1506 /* Some object file formats have a maximum alignment which they support.
1507 In particular, a.out format supports a maximum alignment of 4. */
1508 #ifndef MAX_OFILE_ALIGNMENT
1509 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1510 #endif
1511 if (align > MAX_OFILE_ALIGNMENT)
1513 warning_with_decl (decl,
1514 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1515 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1516 align = MAX_OFILE_ALIGNMENT;
1519 /* On some machines, it is good to increase alignment sometimes. */
1520 if (! DECL_USER_ALIGN (decl))
1522 #ifdef DATA_ALIGNMENT
1523 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1524 #endif
1525 #ifdef CONSTANT_ALIGNMENT
1526 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1527 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1528 #endif
1531 /* Reset the alignment in case we have made it tighter, so we can benefit
1532 from it in get_pointer_alignment. */
1533 DECL_ALIGN (decl) = align;
1534 set_mem_align (decl_rtl, align);
1536 if (TREE_PUBLIC (decl))
1537 maybe_assemble_visibility (decl);
1539 /* Output any data that we will need to use the address of. */
1540 if (DECL_INITIAL (decl) == error_mark_node)
1541 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1542 else if (DECL_INITIAL (decl))
1543 reloc = output_addressed_constants (DECL_INITIAL (decl));
1544 resolve_unique_section (decl, reloc, flag_data_sections);
1546 /* Handle uninitialized definitions. */
1548 /* If the decl has been given an explicit section name, then it
1549 isn't common, and shouldn't be handled as such. */
1550 if (DECL_SECTION_NAME (decl) || dont_output_data)
1552 /* We don't implement common thread-local data at present. */
1553 else if (DECL_THREAD_LOCAL (decl))
1555 if (DECL_COMMON (decl))
1556 sorry ("thread-local COMMON data not implemented");
1558 else if (DECL_INITIAL (decl) == 0
1559 || DECL_INITIAL (decl) == error_mark_node
1560 || (flag_zero_initialized_in_bss
1561 /* Leave constant zeroes in .rodata so they can be shared. */
1562 && !TREE_READONLY (decl)
1563 && initializer_zerop (DECL_INITIAL (decl))))
1565 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1566 unsigned HOST_WIDE_INT rounded = size;
1568 /* Don't allocate zero bytes of common,
1569 since that means "undefined external" in the linker. */
1570 if (size == 0)
1571 rounded = 1;
1573 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1574 so that each uninitialized object starts on such a boundary. */
1575 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1576 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1577 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1579 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1580 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1581 warning_with_decl
1582 (decl, "requested alignment for %s is greater than implemented alignment of %d",rounded);
1583 #endif
1585 /* If the target cannot output uninitialized but not common global data
1586 in .bss, then we have to use .data, so fall through. */
1587 if (asm_emit_uninitialised (decl, name, size, rounded))
1588 return;
1591 /* Handle initialized definitions.
1592 Also handle uninitialized global definitions if -fno-common and the
1593 target doesn't support ASM_OUTPUT_BSS. */
1595 /* First make the assembler name(s) global if appropriate. */
1596 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1597 globalize_decl (decl);
1599 /* Switch to the appropriate section. */
1600 variable_section (decl, reloc);
1602 /* dbxout.c needs to know this. */
1603 if (in_text_section ())
1604 DECL_IN_TEXT_SECTION (decl) = 1;
1606 /* Output the alignment of this data. */
1607 if (align > BITS_PER_UNIT)
1609 ASM_OUTPUT_ALIGN (asm_out_file,
1610 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1613 /* Do any machine/system dependent processing of the object. */
1614 #ifdef ASM_DECLARE_OBJECT_NAME
1615 last_assemble_variable_decl = decl;
1616 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1617 #else
1618 /* Standard thing is just output label for the object. */
1619 ASM_OUTPUT_LABEL (asm_out_file, name);
1620 #endif /* ASM_DECLARE_OBJECT_NAME */
1622 if (!dont_output_data)
1624 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
1625 /* Output the actual data. */
1626 output_constant (DECL_INITIAL (decl),
1627 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1628 align);
1629 else
1630 /* Leave space for it. */
1631 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1635 /* Return 1 if type TYPE contains any pointers. */
1637 static int
1638 contains_pointers_p (type)
1639 tree type;
1641 switch (TREE_CODE (type))
1643 case POINTER_TYPE:
1644 case REFERENCE_TYPE:
1645 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1646 so I'll play safe and return 1. */
1647 case OFFSET_TYPE:
1648 return 1;
1650 case RECORD_TYPE:
1651 case UNION_TYPE:
1652 case QUAL_UNION_TYPE:
1654 tree fields;
1655 /* For a type that has fields, see if the fields have pointers. */
1656 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1657 if (TREE_CODE (fields) == FIELD_DECL
1658 && contains_pointers_p (TREE_TYPE (fields)))
1659 return 1;
1660 return 0;
1663 case ARRAY_TYPE:
1664 /* An array type contains pointers if its element type does. */
1665 return contains_pointers_p (TREE_TYPE (type));
1667 default:
1668 return 0;
1672 /* Output something to declare an external symbol to the assembler.
1673 (Most assemblers don't need this, so we normally output nothing.)
1674 Do nothing if DECL is not external. */
1676 void
1677 assemble_external (decl)
1678 tree decl ATTRIBUTE_UNUSED;
1680 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1681 main body of this code is only rarely exercised. To provide some
1682 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1683 open. If it's not, we should not be calling this function. */
1684 if (!asm_out_file)
1685 abort ();
1687 #ifdef ASM_OUTPUT_EXTERNAL
1688 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1690 rtx rtl = DECL_RTL (decl);
1692 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1693 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1695 /* Some systems do require some output. */
1696 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1697 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1700 #endif
1703 /* Similar, for calling a library function FUN. */
1705 void
1706 assemble_external_libcall (fun)
1707 rtx fun ATTRIBUTE_UNUSED;
1709 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1710 /* Declare library function name external when first used, if nec. */
1711 if (! SYMBOL_REF_USED (fun))
1713 SYMBOL_REF_USED (fun) = 1;
1714 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1716 #endif
1719 /* Assemble a label named NAME. */
1721 void
1722 assemble_label (name)
1723 const char *name;
1725 ASM_OUTPUT_LABEL (asm_out_file, name);
1728 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1729 If NAME starts with a *, the rest of NAME is output verbatim.
1730 Otherwise NAME is transformed in an implementation-defined way
1731 (usually by the addition of an underscore).
1732 Many macros in the tm file are defined to call this function. */
1734 void
1735 assemble_name (file, name)
1736 FILE *file;
1737 const char *name;
1739 const char *real_name;
1740 tree id;
1742 real_name = (* targetm.strip_name_encoding) (name);
1744 id = maybe_get_identifier (real_name);
1745 if (id)
1746 TREE_SYMBOL_REFERENCED (id) = 1;
1748 if (name[0] == '*')
1749 fputs (&name[1], file);
1750 else
1751 ASM_OUTPUT_LABELREF (file, name);
1754 /* Allocate SIZE bytes writable static space with a gensym name
1755 and return an RTX to refer to its address. */
1758 assemble_static_space (size)
1759 unsigned HOST_WIDE_INT size;
1761 char name[12];
1762 const char *namestring;
1763 rtx x;
1765 #if 0
1766 if (flag_shared_data)
1767 data_section ();
1768 #endif
1770 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1771 ++const_labelno;
1772 namestring = ggc_strdup (name);
1774 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1775 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
1777 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1778 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1779 BIGGEST_ALIGNMENT);
1780 #else
1781 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1782 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1783 #else
1785 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1786 so that each uninitialized object starts on such a boundary. */
1787 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1788 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1789 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1790 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1791 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1792 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1794 #endif
1795 #endif
1796 return x;
1799 /* Assemble the static constant template for function entry trampolines.
1800 This is done at most once per compilation.
1801 Returns an RTX for the address of the template. */
1803 #ifdef TRAMPOLINE_TEMPLATE
1805 assemble_trampoline_template ()
1807 char label[256];
1808 const char *name;
1809 int align;
1810 rtx symbol;
1812 /* By default, put trampoline templates in read-only data section. */
1814 #ifdef TRAMPOLINE_SECTION
1815 TRAMPOLINE_SECTION ();
1816 #else
1817 readonly_data_section ();
1818 #endif
1820 /* Write the assembler code to define one. */
1821 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1822 if (align > 0)
1824 ASM_OUTPUT_ALIGN (asm_out_file, align);
1827 (*targetm.asm_out.internal_label) (asm_out_file, "LTRAMP", 0);
1828 TRAMPOLINE_TEMPLATE (asm_out_file);
1830 /* Record the rtl to refer to it. */
1831 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1832 name = ggc_strdup (label);
1833 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
1834 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
1836 return symbol;
1838 #endif
1840 /* A and B are either alignments or offsets. Return the minimum alignment
1841 that may be assumed after adding the two together. */
1843 static inline unsigned
1844 min_align (a, b)
1845 unsigned int a, b;
1847 return (a | b) & -(a | b);
1850 /* Return the assembler directive for creating a given kind of integer
1851 object. SIZE is the number of bytes in the object and ALIGNED_P
1852 indicates whether it is known to be aligned. Return NULL if the
1853 assembly dialect has no such directive.
1855 The returned string should be printed at the start of a new line and
1856 be followed immediately by the object's initial value. */
1858 const char *
1859 integer_asm_op (size, aligned_p)
1860 int size;
1861 int aligned_p;
1863 struct asm_int_op *ops;
1865 if (aligned_p)
1866 ops = &targetm.asm_out.aligned_op;
1867 else
1868 ops = &targetm.asm_out.unaligned_op;
1870 switch (size)
1872 case 1:
1873 return targetm.asm_out.byte_op;
1874 case 2:
1875 return ops->hi;
1876 case 4:
1877 return ops->si;
1878 case 8:
1879 return ops->di;
1880 case 16:
1881 return ops->ti;
1882 default:
1883 return NULL;
1887 /* Use directive OP to assemble an integer object X. Print OP at the
1888 start of the line, followed immediately by the value of X. */
1890 void
1891 assemble_integer_with_op (op, x)
1892 const char *op;
1893 rtx x;
1895 fputs (op, asm_out_file);
1896 output_addr_const (asm_out_file, x);
1897 fputc ('\n', asm_out_file);
1900 /* The default implementation of the asm_out.integer target hook. */
1902 bool
1903 default_assemble_integer (x, size, aligned_p)
1904 rtx x ATTRIBUTE_UNUSED;
1905 unsigned int size ATTRIBUTE_UNUSED;
1906 int aligned_p ATTRIBUTE_UNUSED;
1908 const char *op = integer_asm_op (size, aligned_p);
1909 return op && (assemble_integer_with_op (op, x), true);
1912 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1913 the alignment of the integer in bits. Return 1 if we were able to output
1914 the constant, otherwise 0. If FORCE is nonzero, abort if we can't output
1915 the constant. */
1917 bool
1918 assemble_integer (x, size, align, force)
1919 rtx x;
1920 unsigned int size;
1921 unsigned int align;
1922 int force;
1924 int aligned_p;
1926 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
1928 /* See if the target hook can handle this kind of object. */
1929 if ((*targetm.asm_out.integer) (x, size, aligned_p))
1930 return true;
1932 /* If the object is a multi-byte one, try splitting it up. Split
1933 it into words it if is multi-word, otherwise split it into bytes. */
1934 if (size > 1)
1936 enum machine_mode omode, imode;
1937 unsigned int subalign;
1938 unsigned int subsize, i;
1940 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
1941 subalign = MIN (align, subsize * BITS_PER_UNIT);
1942 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
1943 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1945 for (i = 0; i < size; i += subsize)
1947 rtx partial = simplify_subreg (omode, x, imode, i);
1948 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
1949 break;
1951 if (i == size)
1952 return true;
1954 /* If we've printed some of it, but not all of it, there's no going
1955 back now. */
1956 if (i > 0)
1957 abort ();
1960 if (force)
1961 abort ();
1963 return false;
1966 void
1967 assemble_real (d, mode, align)
1968 REAL_VALUE_TYPE d;
1969 enum machine_mode mode;
1970 unsigned int align;
1972 long data[4];
1973 long l;
1974 unsigned int nalign = min_align (align, 32);
1976 switch (BITS_PER_UNIT)
1978 case 8:
1979 switch (mode)
1981 case SFmode:
1982 REAL_VALUE_TO_TARGET_SINGLE (d, l);
1983 assemble_integer (GEN_INT (l), 4, align, 1);
1984 break;
1985 case DFmode:
1986 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
1987 assemble_integer (GEN_INT (data[0]), 4, align, 1);
1988 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
1989 break;
1990 case XFmode:
1991 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
1992 assemble_integer (GEN_INT (data[0]), 4, align, 1);
1993 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
1994 assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
1995 break;
1996 case TFmode:
1997 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
1998 assemble_integer (GEN_INT (data[0]), 4, align, 1);
1999 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2000 assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
2001 assemble_integer (GEN_INT (data[3]), 4, nalign, 1);
2002 break;
2003 default:
2004 abort ();
2006 break;
2008 case 16:
2009 switch (mode)
2011 case HFmode:
2012 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2013 assemble_integer (GEN_INT (l), 2, align, 1);
2014 break;
2015 case TQFmode:
2016 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2017 assemble_integer (GEN_INT (data[0]), 2, align, 1);
2018 assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2019 break;
2020 default:
2021 abort ();
2023 break;
2025 case 32:
2026 switch (mode)
2028 case QFmode:
2029 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2030 assemble_integer (GEN_INT (l), 1, align, 1);
2031 break;
2032 case HFmode:
2033 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2034 assemble_integer (GEN_INT (data[0]), 1, align, 1);
2035 assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2036 break;
2037 default:
2038 abort ();
2040 break;
2042 default:
2043 abort ();
2047 /* Given an expression EXP with a constant value,
2048 reduce it to the sum of an assembler symbol and an integer.
2049 Store them both in the structure *VALUE.
2050 Abort if EXP does not reduce. */
2052 struct addr_const GTY(())
2054 rtx base;
2055 HOST_WIDE_INT offset;
2058 static void
2059 decode_addr_const (exp, value)
2060 tree exp;
2061 struct addr_const *value;
2063 tree target = TREE_OPERAND (exp, 0);
2064 int offset = 0;
2065 rtx x;
2067 while (1)
2069 if (TREE_CODE (target) == COMPONENT_REF
2070 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2073 offset += int_byte_position (TREE_OPERAND (target, 1));
2074 target = TREE_OPERAND (target, 0);
2076 else if (TREE_CODE (target) == ARRAY_REF
2077 || TREE_CODE (target) == ARRAY_RANGE_REF)
2079 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2080 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2081 target = TREE_OPERAND (target, 0);
2083 else
2084 break;
2087 switch (TREE_CODE (target))
2089 case VAR_DECL:
2090 case FUNCTION_DECL:
2091 x = DECL_RTL (target);
2092 break;
2094 case LABEL_DECL:
2095 x = gen_rtx_MEM (FUNCTION_MODE,
2096 gen_rtx_LABEL_REF (VOIDmode, force_label_rtx (target)));
2097 break;
2099 case REAL_CST:
2100 case STRING_CST:
2101 case COMPLEX_CST:
2102 case CONSTRUCTOR:
2103 case INTEGER_CST:
2104 x = output_constant_def (target, 1);
2105 break;
2107 default:
2108 abort ();
2111 if (GET_CODE (x) != MEM)
2112 abort ();
2113 x = XEXP (x, 0);
2115 value->base = x;
2116 value->offset = offset;
2119 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */
2120 enum kind { RTX_UNKNOWN, RTX_DOUBLE, RTX_VECTOR, RTX_INT, RTX_UNSPEC };
2121 struct rtx_const GTY(())
2123 ENUM_BITFIELD(kind) kind : 16;
2124 ENUM_BITFIELD(machine_mode) mode : 16;
2125 union rtx_const_un {
2126 REAL_VALUE_TYPE GTY ((tag ("4"))) du;
2127 struct rtx_const_u_addr {
2128 rtx base;
2129 const char *symbol;
2130 HOST_WIDE_INT offset;
2131 } GTY ((tag ("1"))) addr;
2132 struct rtx_const_u_di {
2133 HOST_WIDE_INT high;
2134 HOST_WIDE_INT low;
2135 } GTY ((tag ("0"))) di;
2137 /* The max vector size we have is 16 wide; two variants for
2138 integral and floating point vectors. */
2139 struct rtx_const_int_vec {
2140 HOST_WIDE_INT high;
2141 HOST_WIDE_INT low;
2142 } GTY ((tag ("2"))) int_vec[16];
2144 REAL_VALUE_TYPE GTY ((tag ("3"))) fp_vec[8];
2146 } GTY ((desc ("%1.kind >= RTX_INT"), descbits ("1"))) un;
2149 /* Uniquize all constants that appear in memory.
2150 Each constant in memory thus far output is recorded
2151 in `const_hash_table'. */
2153 struct constant_descriptor_tree GTY(())
2155 /* A MEM for the constant. */
2156 rtx rtl;
2158 /* The value of the constant. */
2159 tree value;
2162 static GTY((param_is (struct constant_descriptor_tree)))
2163 htab_t const_desc_htab;
2165 static struct constant_descriptor_tree * build_constant_desc PARAMS ((tree));
2166 static void maybe_output_constant_def_contents
2167 PARAMS ((struct constant_descriptor_tree *, int));
2169 /* Compute a hash code for a constant expression. */
2171 static hashval_t
2172 const_desc_hash (ptr)
2173 const void *ptr;
2175 return const_hash_1 (((struct constant_descriptor_tree *)ptr)->value);
2178 static hashval_t
2179 const_hash_1 (exp)
2180 const tree exp;
2182 const char *p;
2183 hashval_t hi;
2184 int len, i;
2185 enum tree_code code = TREE_CODE (exp);
2187 /* Either set P and LEN to the address and len of something to hash and
2188 exit the switch or return a value. */
2190 switch (code)
2192 case INTEGER_CST:
2193 p = (char *) &TREE_INT_CST (exp);
2194 len = sizeof TREE_INT_CST (exp);
2195 break;
2197 case REAL_CST:
2198 return real_hash (TREE_REAL_CST_PTR (exp));
2200 case STRING_CST:
2201 p = TREE_STRING_POINTER (exp);
2202 len = TREE_STRING_LENGTH (exp);
2203 break;
2204 case COMPLEX_CST:
2205 return (const_hash_1 (TREE_REALPART (exp)) * 5
2206 + const_hash_1 (TREE_IMAGPART (exp)));
2208 case CONSTRUCTOR:
2209 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2211 char *tmp;
2213 len = int_size_in_bytes (TREE_TYPE (exp));
2214 tmp = (char *) alloca (len);
2215 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2216 p = tmp;
2217 break;
2219 else
2221 tree link;
2223 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2225 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2226 if (TREE_VALUE (link))
2227 hi = hi * 603 + const_hash_1 (TREE_VALUE (link));
2229 return hi;
2232 case ADDR_EXPR:
2233 case FDESC_EXPR:
2235 struct addr_const value;
2237 decode_addr_const (exp, &value);
2238 if (GET_CODE (value.base) == SYMBOL_REF)
2240 /* Don't hash the address of the SYMBOL_REF;
2241 only use the offset and the symbol name. */
2242 hi = value.offset;
2243 p = XSTR (value.base, 0);
2244 for (i = 0; p[i] != 0; i++)
2245 hi = ((hi * 613) + (unsigned) (p[i]));
2247 else if (GET_CODE (value.base) == LABEL_REF)
2248 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2249 else
2250 abort ();
2252 return hi;
2254 case PLUS_EXPR:
2255 case MINUS_EXPR:
2256 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2257 + const_hash_1 (TREE_OPERAND (exp, 1)));
2259 case NOP_EXPR:
2260 case CONVERT_EXPR:
2261 case NON_LVALUE_EXPR:
2262 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2264 default:
2265 /* A language specific constant. Just hash the code. */
2266 return code;
2269 /* Compute hashing function */
2270 hi = len;
2271 for (i = 0; i < len; i++)
2272 hi = ((hi * 613) + (unsigned) (p[i]));
2274 return hi;
2277 /* Wrapper of compare_constant, for the htab interface. */
2278 static int
2279 const_desc_eq (p1, p2)
2280 const void *p1;
2281 const void *p2;
2283 return compare_constant (((struct constant_descriptor_tree *)p1)->value,
2284 ((struct constant_descriptor_tree *)p2)->value);
2287 /* Compare t1 and t2, and return 1 only if they are known to result in
2288 the same bit pattern on output. */
2290 static int
2291 compare_constant (t1, t2)
2292 const tree t1;
2293 const tree t2;
2295 enum tree_code typecode;
2297 if (t1 == NULL_TREE)
2298 return t2 == NULL_TREE;
2299 if (t2 == NULL_TREE)
2300 return 0;
2302 if (TREE_CODE (t1) != TREE_CODE (t2))
2303 return 0;
2305 switch (TREE_CODE (t1))
2307 case INTEGER_CST:
2308 /* Integer constants are the same only if the same width of type. */
2309 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2310 return 0;
2311 return tree_int_cst_equal (t1, t2);
2313 case REAL_CST:
2314 /* Real constants are the same only if the same width of type. */
2315 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2316 return 0;
2318 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2320 case STRING_CST:
2321 if (flag_writable_strings)
2322 return 0;
2324 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2325 return 0;
2327 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2328 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2329 TREE_STRING_LENGTH (t1)));
2331 case COMPLEX_CST:
2332 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2333 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2335 case CONSTRUCTOR:
2336 typecode = TREE_CODE (TREE_TYPE (t1));
2337 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2338 return 0;
2340 if (typecode == SET_TYPE)
2342 int len = int_size_in_bytes (TREE_TYPE (t2));
2343 unsigned char *tmp1, *tmp2;
2345 if (int_size_in_bytes (TREE_TYPE (t1)) != len)
2346 return 0;
2348 tmp1 = (unsigned char *) alloca (len);
2349 tmp2 = (unsigned char *) alloca (len);
2351 if (get_set_constructor_bytes (t1, tmp1, len) != NULL_TREE)
2352 return 0;
2353 if (get_set_constructor_bytes (t2, tmp2, len) != NULL_TREE)
2354 return 0;
2356 return memcmp (tmp1, tmp2, len) != 0;
2358 else
2360 tree l1, l2;
2362 if (typecode == ARRAY_TYPE)
2364 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2365 /* For arrays, check that the sizes all match. */
2366 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2367 || size_1 == -1
2368 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2369 return 0;
2371 else
2373 /* For record and union constructors, require exact type
2374 equality. */
2375 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2376 return 0;
2379 for (l1 = CONSTRUCTOR_ELTS (t1), l2 = CONSTRUCTOR_ELTS (t2);
2380 l1 && l2;
2381 l1 = TREE_CHAIN (l1), l2 = TREE_CHAIN (l2))
2383 /* Check that each value is the same... */
2384 if (! compare_constant (TREE_VALUE (l1), TREE_VALUE (l2)))
2385 return 0;
2386 /* ... and that they apply to the same fields! */
2387 if (typecode == ARRAY_TYPE)
2389 if (! compare_constant (TREE_PURPOSE (l1),
2390 TREE_PURPOSE (l2)))
2391 return 0;
2393 else
2395 if (TREE_PURPOSE (l1) != TREE_PURPOSE (l2))
2396 return 0;
2400 return l1 == NULL_TREE && l2 == NULL_TREE;
2403 case ADDR_EXPR:
2404 case FDESC_EXPR:
2406 struct addr_const value1, value2;
2408 decode_addr_const (t1, &value1);
2409 decode_addr_const (t2, &value2);
2410 return (value1.offset == value2.offset
2411 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2414 case PLUS_EXPR:
2415 case MINUS_EXPR:
2416 case RANGE_EXPR:
2417 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2418 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2420 case NOP_EXPR:
2421 case CONVERT_EXPR:
2422 case NON_LVALUE_EXPR:
2423 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2425 default:
2427 tree nt1, nt2;
2428 nt1 = (*lang_hooks.expand_constant) (t1);
2429 nt2 = (*lang_hooks.expand_constant) (t2);
2430 if (nt1 != t1 || nt2 != t2)
2431 return compare_constant (nt1, nt2);
2432 else
2433 return 0;
2437 /* Should not get here. */
2438 abort ();
2441 /* Make a copy of the whole tree structure for a constant. This
2442 handles the same types of nodes that compare_constant handles. */
2444 static tree
2445 copy_constant (exp)
2446 tree exp;
2448 switch (TREE_CODE (exp))
2450 case ADDR_EXPR:
2451 /* For ADDR_EXPR, we do not want to copy the decl whose address
2452 is requested. We do want to copy constants though. */
2453 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2454 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2455 copy_constant (TREE_OPERAND (exp, 0)));
2456 else
2457 return copy_node (exp);
2459 case INTEGER_CST:
2460 case REAL_CST:
2461 case STRING_CST:
2462 return copy_node (exp);
2464 case COMPLEX_CST:
2465 return build_complex (TREE_TYPE (exp),
2466 copy_constant (TREE_REALPART (exp)),
2467 copy_constant (TREE_IMAGPART (exp)));
2469 case PLUS_EXPR:
2470 case MINUS_EXPR:
2471 return build (TREE_CODE (exp), TREE_TYPE (exp),
2472 copy_constant (TREE_OPERAND (exp, 0)),
2473 copy_constant (TREE_OPERAND (exp, 1)));
2475 case NOP_EXPR:
2476 case CONVERT_EXPR:
2477 case NON_LVALUE_EXPR:
2478 case VIEW_CONVERT_EXPR:
2479 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2480 copy_constant (TREE_OPERAND (exp, 0)));
2482 case CONSTRUCTOR:
2484 tree copy = copy_node (exp);
2485 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2486 tree tail;
2488 CONSTRUCTOR_ELTS (copy) = list;
2489 for (tail = list; tail; tail = TREE_CHAIN (tail))
2490 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2491 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2492 for (tail = list; tail; tail = TREE_CHAIN (tail))
2493 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2495 return copy;
2498 default:
2500 tree t;
2501 t = (*lang_hooks.expand_constant) (exp);
2502 if (t != exp)
2503 return copy_constant (t);
2504 else
2505 abort ();
2510 /* Subroutine of output_constant_def:
2511 No constant equal to EXP is known to have been output.
2512 Make a constant descriptor to enter EXP in the hash table.
2513 Assign the label number and construct RTL to refer to the
2514 constant's location in memory.
2515 Caller is responsible for updating the hash table. */
2517 static struct constant_descriptor_tree *
2518 build_constant_desc (exp)
2519 tree exp;
2521 rtx symbol;
2522 rtx rtl;
2523 char label[256];
2524 int labelno;
2525 struct constant_descriptor_tree *desc;
2527 desc = ggc_alloc (sizeof (*desc));
2528 desc->value = copy_constant (exp);
2530 /* Create a string containing the label name, in LABEL. */
2531 labelno = const_labelno++;
2532 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2534 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2535 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2536 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2537 SYMBOL_REF_DECL (symbol) = desc->value;
2538 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2540 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2541 set_mem_attributes (rtl, exp, 1);
2542 set_mem_alias_set (rtl, 0);
2543 set_mem_alias_set (rtl, const_alias_set);
2545 /* Set flags or add text to the name to record information, such as
2546 that it is a local symbol. If the name is changed, the macro
2547 ASM_OUTPUT_LABELREF will have to know how to strip this
2548 information. This call might invalidate our local variable
2549 SYMBOL; we can't use it afterward. */
2551 (*targetm.encode_section_info) (exp, rtl, true);
2553 desc->rtl = rtl;
2555 return desc;
2558 /* Return an rtx representing a reference to constant data in memory
2559 for the constant expression EXP.
2561 If assembler code for such a constant has already been output,
2562 return an rtx to refer to it.
2563 Otherwise, output such a constant in memory
2564 and generate an rtx for it.
2566 If DEFER is nonzero, this constant can be deferred and output only
2567 if referenced in the function after all optimizations.
2569 The const_hash_table records which constants already have label strings. */
2572 output_constant_def (exp, defer)
2573 tree exp;
2574 int defer;
2576 struct constant_descriptor_tree *desc;
2577 struct constant_descriptor_tree key;
2578 void **loc;
2580 /* Look up EXP in the table of constant descriptors. If we didn't find
2581 it, create a new one. */
2582 key.value = exp;
2583 loc = htab_find_slot (const_desc_htab, &key, INSERT);
2585 desc = *loc;
2586 if (desc == 0)
2588 desc = build_constant_desc (exp);
2589 *loc = desc;
2592 maybe_output_constant_def_contents (desc, defer);
2593 return desc->rtl;
2596 /* Subroutine of output_constant_def: Decide whether or not we need to
2597 output the constant DESC now, and if so, do it. */
2598 static void
2599 maybe_output_constant_def_contents (desc, defer)
2600 struct constant_descriptor_tree *desc;
2601 int defer;
2603 rtx symbol = XEXP (desc->rtl, 0);
2604 tree exp = desc->value;
2606 if (flag_syntax_only)
2607 return;
2609 if (TREE_ASM_WRITTEN (exp))
2610 /* Already output; don't do it again. */
2611 return;
2613 /* The only constants that cannot safely be deferred, assuming the
2614 context allows it, are strings under flag_writable_strings. */
2615 if (defer && (TREE_CODE (exp) != STRING_CST || !flag_writable_strings))
2617 /* Increment n_deferred_constants if it exists. It needs to be at
2618 least as large as the number of constants actually referred to
2619 by the function. If it's too small we'll stop looking too early
2620 and fail to emit constants; if it's too large we'll only look
2621 through the entire function when we could have stopped earlier. */
2622 if (cfun)
2623 n_deferred_constants++;
2624 return;
2627 output_constant_def_contents (symbol);
2630 /* We must output the constant data referred to by SYMBOL; do so. */
2632 static void
2633 output_constant_def_contents (symbol)
2634 rtx symbol;
2636 tree exp = SYMBOL_REF_DECL (symbol);
2637 const char *label = XSTR (symbol, 0);
2639 /* Make sure any other constants whose addresses appear in EXP
2640 are assigned label numbers. */
2641 int reloc = output_addressed_constants (exp);
2643 /* Align the location counter as required by EXP's data type. */
2644 int align = TYPE_ALIGN (TREE_TYPE (exp));
2645 #ifdef CONSTANT_ALIGNMENT
2646 align = CONSTANT_ALIGNMENT (exp, align);
2647 #endif
2649 /* We are no longer deferring this constant. */
2650 TREE_ASM_WRITTEN (exp) = 1;
2652 if (IN_NAMED_SECTION (exp))
2653 named_section (exp, NULL, reloc);
2654 else
2655 (*targetm.asm_out.select_section) (exp, reloc, align);
2657 if (align > BITS_PER_UNIT)
2659 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2662 /* Output the label itself. */
2663 ASM_OUTPUT_LABEL (asm_out_file, label);
2665 /* Output the value of EXP. */
2666 output_constant (exp,
2667 (TREE_CODE (exp) == STRING_CST
2668 ? MAX (TREE_STRING_LENGTH (exp),
2669 int_size_in_bytes (TREE_TYPE (exp)))
2670 : int_size_in_bytes (TREE_TYPE (exp))),
2671 align);
2675 /* A constant which was deferred in its original location has been
2676 inserted by the RTL inliner into a different function. The
2677 current function's deferred constant count must be incremented. */
2678 void
2679 notice_rtl_inlining_of_deferred_constant ()
2681 n_deferred_constants++;
2684 /* Used in the hash tables to avoid outputting the same constant
2685 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2686 are output once per function, not once per file; there seems
2687 to be no reason for the difference. */
2689 struct constant_descriptor_rtx GTY(())
2691 /* More constant_descriptors with the same hash code. */
2692 struct constant_descriptor_rtx *next;
2694 /* A MEM for the constant. */
2695 rtx rtl;
2697 /* The value of the constant. */
2698 struct rtx_const value;
2701 /* Structure to represent sufficient information about a constant so that
2702 it can be output when the constant pool is output, so that function
2703 integration can be done, and to simplify handling on machines that reference
2704 constant pool as base+displacement. */
2706 struct pool_constant GTY(())
2708 struct constant_descriptor_rtx *desc;
2709 struct pool_constant *next;
2710 struct pool_constant *next_sym;
2711 rtx constant;
2712 enum machine_mode mode;
2713 int labelno;
2714 unsigned int align;
2715 HOST_WIDE_INT offset;
2716 int mark;
2719 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2720 The argument is XSTR (... , 0) */
2722 #define SYMHASH(LABEL) (((unsigned long) (LABEL)) % MAX_RTX_HASH_TABLE)
2724 /* Initialize constant pool hashing for a new function. */
2726 void
2727 init_varasm_status (f)
2728 struct function *f;
2730 struct varasm_status *p;
2731 p = (struct varasm_status *) ggc_alloc (sizeof (struct varasm_status));
2732 f->varasm = p;
2733 p->x_const_rtx_hash_table
2734 = ((struct constant_descriptor_rtx **)
2735 ggc_alloc_cleared (MAX_RTX_HASH_TABLE
2736 * sizeof (struct constant_descriptor_rtx *)));
2737 p->x_const_rtx_sym_hash_table
2738 = ((struct pool_constant **)
2739 ggc_alloc_cleared (MAX_RTX_HASH_TABLE
2740 * sizeof (struct pool_constant *)));
2742 p->x_first_pool = p->x_last_pool = 0;
2743 p->x_pool_offset = 0;
2744 p->deferred_constants = 0;
2748 /* Express an rtx for a constant integer (perhaps symbolic)
2749 as the sum of a symbol or label plus an explicit integer.
2750 They are stored into VALUE. */
2752 static void
2753 decode_rtx_const (mode, x, value)
2754 enum machine_mode mode;
2755 rtx x;
2756 struct rtx_const *value;
2758 /* Clear the whole structure, including any gaps. */
2759 memset (value, 0, sizeof (struct rtx_const));
2761 value->kind = RTX_INT; /* Most usual kind. */
2762 value->mode = mode;
2764 switch (GET_CODE (x))
2766 case CONST_DOUBLE:
2767 value->kind = RTX_DOUBLE;
2768 if (GET_MODE (x) != VOIDmode)
2770 const REAL_VALUE_TYPE *r = CONST_DOUBLE_REAL_VALUE (x);
2772 value->mode = GET_MODE (x);
2774 /* Copy the REAL_VALUE_TYPE by members so that we don't
2775 copy garbage from the original structure into our
2776 carefully cleaned hashing structure. */
2777 value->un.du.class = r->class;
2778 value->un.du.sign = r->sign;
2779 switch (r->class)
2781 case rvc_zero:
2782 case rvc_inf:
2783 break;
2784 case rvc_normal:
2785 value->un.du.exp = r->exp;
2786 /* FALLTHRU */
2787 case rvc_nan:
2788 memcpy (value->un.du.sig, r->sig, sizeof (r->sig));
2789 break;
2790 default:
2791 abort ();
2794 else
2796 value->un.di.low = CONST_DOUBLE_LOW (x);
2797 value->un.di.high = CONST_DOUBLE_HIGH (x);
2799 break;
2801 case CONST_VECTOR:
2803 int units, i;
2805 units = CONST_VECTOR_NUNITS (x);
2806 value->kind = RTX_VECTOR;
2807 value->mode = mode;
2809 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
2811 for (i = 0; i < units; ++i)
2813 rtx elt = CONST_VECTOR_ELT (x, i);
2814 if (GET_CODE (elt) == CONST_INT)
2816 value->un.int_vec[i].low = INTVAL (elt);
2817 value->un.int_vec[i].high = 0;
2819 else
2821 value->un.int_vec[i].low = CONST_DOUBLE_LOW (elt);
2822 value->un.int_vec[i].high = CONST_DOUBLE_HIGH (elt);
2826 else if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
2828 for (i = 0; i < units; ++i)
2830 const REAL_VALUE_TYPE *r
2831 = CONST_DOUBLE_REAL_VALUE (CONST_VECTOR_ELT (x, i));
2832 REAL_VALUE_TYPE *d = &value->un.fp_vec[i];
2834 /* Copy the REAL_VALUE_TYPE by members so that we don't
2835 copy garbage from the original structure into our
2836 carefully cleaned hashing structure. */
2837 d->class = r->class;
2838 d->sign = r->sign;
2839 switch (r->class)
2841 case rvc_zero:
2842 case rvc_inf:
2843 break;
2844 case rvc_normal:
2845 d->exp = r->exp;
2846 /* FALLTHRU */
2847 case rvc_nan:
2848 memcpy (d->sig, r->sig, sizeof (r->sig));
2849 break;
2850 default:
2851 abort ();
2855 else
2856 abort ();
2858 break;
2860 case CONST_INT:
2861 value->un.addr.offset = INTVAL (x);
2862 break;
2864 case SYMBOL_REF:
2865 case LABEL_REF:
2866 case PC:
2867 value->un.addr.base = x;
2868 break;
2870 case CONST:
2871 x = XEXP (x, 0);
2872 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
2874 value->un.addr.base = XEXP (x, 0);
2875 value->un.addr.offset = INTVAL (XEXP (x, 1));
2877 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
2879 value->un.addr.base = XEXP (x, 0);
2880 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2882 else
2884 value->un.addr.base = x;
2885 value->un.addr.offset = 0;
2887 break;
2889 default:
2890 value->kind = RTX_UNKNOWN;
2891 break;
2894 if (value->kind == RTX_INT && value->un.addr.base != 0
2895 && GET_CODE (value->un.addr.base) == UNSPEC)
2897 /* For a simple UNSPEC, the base is set to the
2898 operand, the kind field is set to the index of
2899 the unspec expression.
2900 Together with the code below, in case that
2901 the operand is a SYMBOL_REF or LABEL_REF,
2902 the address of the string or the code_label
2903 is taken as base. */
2904 if (XVECLEN (value->un.addr.base, 0) == 1)
2906 value->kind = RTX_UNSPEC + XINT (value->un.addr.base, 1);
2907 value->un.addr.base = XVECEXP (value->un.addr.base, 0, 0);
2911 if (value->kind >= RTX_INT && value->un.addr.base != 0)
2912 switch (GET_CODE (value->un.addr.base))
2914 case SYMBOL_REF:
2915 /* Use the string's address, not the SYMBOL_REF's address,
2916 for the sake of addresses of library routines. */
2917 value->un.addr.symbol = XSTR (value->un.addr.base, 0);
2918 value->un.addr.base = NULL_RTX;
2919 break;
2921 case LABEL_REF:
2922 /* For a LABEL_REF, compare labels. */
2923 value->un.addr.base = XEXP (value->un.addr.base, 0);
2925 default:
2926 break;
2930 /* Given a MINUS expression, simplify it if both sides
2931 include the same symbol. */
2934 simplify_subtraction (x)
2935 rtx x;
2937 struct rtx_const val0, val1;
2939 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2940 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2942 if (val0.kind >= RTX_INT
2943 && val0.kind == val1.kind
2944 && val0.un.addr.base == val1.un.addr.base
2945 && val0.un.addr.symbol == val1.un.addr.symbol)
2946 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2948 return x;
2951 /* Compute a hash code for a constant RTL expression. */
2953 static unsigned int
2954 const_hash_rtx (mode, x)
2955 enum machine_mode mode;
2956 rtx x;
2958 union {
2959 struct rtx_const value;
2960 unsigned int data[sizeof(struct rtx_const) / sizeof (unsigned int)];
2961 } u;
2963 unsigned int hi;
2964 size_t i;
2966 decode_rtx_const (mode, x, &u.value);
2968 /* Compute hashing function */
2969 hi = 0;
2970 for (i = 0; i < ARRAY_SIZE (u.data); i++)
2971 hi = hi * 613 + u.data[i];
2973 return hi % MAX_RTX_HASH_TABLE;
2976 /* Compare a constant rtl object X with a constant-descriptor DESC.
2977 Return 1 if DESC describes a constant with the same value as X. */
2979 static int
2980 compare_constant_rtx (mode, x, desc)
2981 enum machine_mode mode;
2982 rtx x;
2983 struct constant_descriptor_rtx *desc;
2985 struct rtx_const value;
2987 decode_rtx_const (mode, x, &value);
2989 /* Compare constant contents. */
2990 return memcmp (&value, &desc->value, sizeof (struct rtx_const)) == 0;
2993 /* Construct a constant descriptor for the rtl-expression X.
2994 It is up to the caller to enter the descriptor in the hash table. */
2996 static struct constant_descriptor_rtx *
2997 record_constant_rtx (mode, x)
2998 enum machine_mode mode;
2999 rtx x;
3001 struct constant_descriptor_rtx *ptr;
3003 ptr = (struct constant_descriptor_rtx *) ggc_alloc (sizeof (*ptr));
3004 decode_rtx_const (mode, x, &ptr->value);
3006 return ptr;
3009 /* Given a constant rtx X, return a MEM for the location in memory at which
3010 this constant has been placed. Return 0 if it not has been placed yet. */
3013 mem_for_const_double (x)
3014 rtx x;
3016 enum machine_mode mode = GET_MODE (x);
3017 struct constant_descriptor_rtx *desc;
3019 for (desc = const_rtx_hash_table[const_hash_rtx (mode, x)]; desc;
3020 desc = desc->next)
3021 if (compare_constant_rtx (mode, x, desc))
3022 return desc->rtl;
3024 return 0;
3027 /* Given a constant rtx X, make (or find) a memory constant for its value
3028 and return a MEM rtx to refer to it in memory. */
3031 force_const_mem (mode, x)
3032 enum machine_mode mode;
3033 rtx x;
3035 int hash;
3036 struct constant_descriptor_rtx *desc;
3037 char label[256];
3038 rtx def, symbol;
3039 struct pool_constant *pool;
3040 unsigned int align;
3042 /* If we're not allowed to drop X into the constant pool, don't. */
3043 if ((*targetm.cannot_force_const_mem) (x))
3044 return NULL_RTX;
3046 /* Compute hash code of X. Search the descriptors for that hash code
3047 to see if any of them describes X. If yes, we have an rtx to use. */
3048 hash = const_hash_rtx (mode, x);
3049 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3050 if (compare_constant_rtx (mode, x, desc))
3051 return desc->rtl;
3053 /* No constant equal to X is known to have been output.
3054 Make a constant descriptor to enter X in the hash table
3055 and make a MEM for it. */
3056 desc = record_constant_rtx (mode, x);
3057 desc->next = const_rtx_hash_table[hash];
3058 const_rtx_hash_table[hash] = desc;
3060 /* Align the location counter as required by EXP's data type. */
3061 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3062 #ifdef CONSTANT_ALIGNMENT
3064 tree type = (*lang_hooks.types.type_for_mode) (mode, 0);
3065 if (type != NULL_TREE)
3066 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3068 #endif
3070 pool_offset += (align / BITS_PER_UNIT) - 1;
3071 pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
3073 if (GET_CODE (x) == LABEL_REF)
3074 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3076 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3077 pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3078 pool->desc = desc;
3079 pool->constant = x;
3080 pool->mode = mode;
3081 pool->labelno = const_labelno;
3082 pool->align = align;
3083 pool->offset = pool_offset;
3084 pool->mark = 1;
3085 pool->next = 0;
3087 if (last_pool == 0)
3088 first_pool = pool;
3089 else
3090 last_pool->next = pool;
3092 last_pool = pool;
3093 pool_offset += GET_MODE_SIZE (mode);
3095 /* Create a string containing the label name, in LABEL. */
3096 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3098 ++const_labelno;
3100 /* Construct the SYMBOL_REF and the MEM. */
3102 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3103 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
3105 pool->desc->rtl = def = gen_rtx_MEM (mode, symbol);
3106 set_mem_attributes (def, (*lang_hooks.types.type_for_mode) (mode, 0), 1);
3107 RTX_UNCHANGING_P (def) = 1;
3109 /* Add label to symbol hash table. */
3110 hash = SYMHASH (XSTR (symbol, 0));
3111 pool->next_sym = const_rtx_sym_hash_table[hash];
3112 const_rtx_sym_hash_table[hash] = pool;
3114 /* Mark the symbol_ref as belonging to this constants pool. */
3115 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3116 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
3117 current_function_uses_const_pool = 1;
3119 return def;
3122 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3123 the corresponding pool_constant structure. */
3125 static struct pool_constant *
3126 find_pool_constant (f, addr)
3127 struct function *f;
3128 rtx addr;
3130 struct pool_constant *pool;
3131 const char *label = XSTR (addr, 0);
3133 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3134 pool = pool->next_sym)
3135 if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label)
3136 return pool;
3138 abort ();
3141 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3144 get_pool_constant (addr)
3145 rtx addr;
3147 return (find_pool_constant (cfun, addr))->constant;
3150 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3151 and whether it has been output or not. */
3154 get_pool_constant_mark (addr, pmarked)
3155 rtx addr;
3156 bool *pmarked;
3158 struct pool_constant *pool = find_pool_constant (cfun, addr);
3159 *pmarked = (pool->mark != 0);
3160 return pool->constant;
3163 /* Likewise, but for the constant pool of a specific function. */
3166 get_pool_constant_for_function (f, addr)
3167 struct function *f;
3168 rtx addr;
3170 return (find_pool_constant (f, addr))->constant;
3173 /* Similar, return the mode. */
3175 enum machine_mode
3176 get_pool_mode (addr)
3177 rtx addr;
3179 return (find_pool_constant (cfun, addr))->mode;
3182 enum machine_mode
3183 get_pool_mode_for_function (f, addr)
3184 struct function *f;
3185 rtx addr;
3187 return (find_pool_constant (f, addr))->mode;
3190 /* Similar, return the offset in the constant pool. */
3193 get_pool_offset (addr)
3194 rtx addr;
3196 return (find_pool_constant (cfun, addr))->offset;
3199 /* Return the size of the constant pool. */
3202 get_pool_size ()
3204 return pool_offset;
3207 /* Write all the constants in the constant pool. */
3209 void
3210 output_constant_pool (fnname, fndecl)
3211 const char *fnname ATTRIBUTE_UNUSED;
3212 tree fndecl ATTRIBUTE_UNUSED;
3214 struct pool_constant *pool;
3215 rtx x;
3216 REAL_VALUE_TYPE r;
3218 /* It is possible for gcc to call force_const_mem and then to later
3219 discard the instructions which refer to the constant. In such a
3220 case we do not need to output the constant. */
3221 mark_constant_pool ();
3223 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3224 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3225 #endif
3227 for (pool = first_pool; pool; pool = pool->next)
3229 rtx tmp;
3231 x = pool->constant;
3233 if (! pool->mark)
3234 continue;
3236 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3237 whose CODE_LABEL has been deleted. This can occur if a jump table
3238 is eliminated by optimization. If so, write a constant of zero
3239 instead. Note that this can also happen by turning the
3240 CODE_LABEL into a NOTE. */
3241 /* ??? This seems completely and utterly wrong. Certainly it's
3242 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3243 functioning even with INSN_DELETED_P and friends. */
3245 tmp = x;
3246 switch (GET_CODE (x))
3248 case CONST:
3249 if (GET_CODE (XEXP (x, 0)) != PLUS
3250 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3251 break;
3252 tmp = XEXP (XEXP (x, 0), 0);
3253 /* FALLTHRU */
3255 case LABEL_REF:
3256 tmp = XEXP (x, 0);
3257 if (INSN_DELETED_P (tmp)
3258 || (GET_CODE (tmp) == NOTE
3259 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
3261 abort ();
3262 x = const0_rtx;
3264 break;
3266 default:
3267 break;
3270 /* First switch to correct section. */
3271 (*targetm.asm_out.select_rtx_section) (pool->mode, x, pool->align);
3273 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3274 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3275 pool->align, pool->labelno, done);
3276 #endif
3278 assemble_align (pool->align);
3280 /* Output the label. */
3281 (*targetm.asm_out.internal_label) (asm_out_file, "LC", pool->labelno);
3283 /* Output the value of the constant itself. */
3284 switch (GET_MODE_CLASS (pool->mode))
3286 case MODE_FLOAT:
3287 if (GET_CODE (x) != CONST_DOUBLE)
3288 abort ();
3290 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3291 assemble_real (r, pool->mode, pool->align);
3292 break;
3294 case MODE_INT:
3295 case MODE_PARTIAL_INT:
3296 assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
3297 break;
3299 case MODE_VECTOR_FLOAT:
3301 int i, units;
3302 rtx elt;
3304 if (GET_CODE (x) != CONST_VECTOR)
3305 abort ();
3307 units = CONST_VECTOR_NUNITS (x);
3309 for (i = 0; i < units; i++)
3311 elt = CONST_VECTOR_ELT (x, i);
3312 REAL_VALUE_FROM_CONST_DOUBLE (r, elt);
3313 assemble_real (r, GET_MODE_INNER (pool->mode), pool->align);
3316 break;
3318 case MODE_VECTOR_INT:
3320 int i, units;
3321 rtx elt;
3323 if (GET_CODE (x) != CONST_VECTOR)
3324 abort ();
3326 units = CONST_VECTOR_NUNITS (x);
3328 for (i = 0; i < units; i++)
3330 elt = CONST_VECTOR_ELT (x, i);
3331 assemble_integer (elt, GET_MODE_UNIT_SIZE (pool->mode),
3332 pool->align, 1);
3335 break;
3337 default:
3338 abort ();
3341 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3342 sections have proper size. */
3343 if (pool->align > GET_MODE_BITSIZE (pool->mode)
3344 && in_section == in_named
3345 && get_named_section_flags (in_named_name) & SECTION_MERGE)
3346 assemble_align (pool->align);
3348 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3349 done: ;
3350 #endif
3353 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3354 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3355 #endif
3357 /* Done with this pool. */
3358 first_pool = last_pool = 0;
3361 /* Look through the instructions for this function, and mark all the
3362 entries in the constant pool which are actually being used. Emit
3363 deferred constants which have indeed been used. */
3365 static void
3366 mark_constant_pool ()
3368 rtx insn;
3369 rtx link;
3370 struct pool_constant *pool;
3372 if (first_pool == 0 && n_deferred_constants == 0)
3373 return;
3375 for (pool = first_pool; pool; pool = pool->next)
3376 pool->mark = 0;
3378 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3379 if (INSN_P (insn))
3380 mark_constants (PATTERN (insn));
3382 for (link = current_function_epilogue_delay_list;
3383 link;
3384 link = XEXP (link, 1))
3386 insn = XEXP (link, 0);
3388 if (INSN_P (insn))
3389 mark_constants (PATTERN (insn));
3393 /* Look through appropriate parts of X, marking all entries in the
3394 constant pool which are actually being used. Entries that are only
3395 referenced by other constants are also marked as used. Emit
3396 deferred strings that are used. */
3398 static void
3399 mark_constants (x)
3400 rtx x;
3402 int i;
3403 const char *format_ptr;
3405 if (x == 0)
3406 return;
3408 if (GET_CODE (x) == SYMBOL_REF)
3410 mark_constant (&x, NULL);
3411 return;
3414 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3415 insns, not any notes that may be attached. We don't want to mark
3416 a constant just because it happens to appear in a REG_EQUIV note. */
3417 if (INSN_P (x))
3419 mark_constants (PATTERN (x));
3420 return;
3423 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3425 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3427 switch (*format_ptr++)
3429 case 'e':
3430 mark_constants (XEXP (x, i));
3431 break;
3433 case 'E':
3434 if (XVEC (x, i) != 0)
3436 int j;
3438 for (j = 0; j < XVECLEN (x, i); j++)
3439 mark_constants (XVECEXP (x, i, j));
3441 break;
3443 case 'S':
3444 case 's':
3445 case '0':
3446 case 'i':
3447 case 'w':
3448 case 'n':
3449 case 'u':
3450 case 'B':
3451 break;
3453 default:
3454 abort ();
3459 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3460 to as used. Emit referenced deferred strings. This function can
3461 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3463 static int
3464 mark_constant (current_rtx, data)
3465 rtx *current_rtx;
3466 void *data ATTRIBUTE_UNUSED;
3468 rtx x = *current_rtx;
3470 if (x == NULL_RTX)
3471 return 0;
3473 else if (GET_CODE (x) == SYMBOL_REF)
3475 if (CONSTANT_POOL_ADDRESS_P (x))
3477 struct pool_constant *pool = find_pool_constant (cfun, x);
3478 if (pool->mark == 0)
3480 pool->mark = 1;
3481 for_each_rtx (&(pool->constant), &mark_constant, NULL);
3483 else
3484 return -1;
3486 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3488 tree exp = SYMBOL_REF_DECL (x);
3489 if (!TREE_ASM_WRITTEN (exp))
3491 n_deferred_constants--;
3492 output_constant_def_contents (x);
3496 return 0;
3499 /* Find all the constants whose addresses are referenced inside of EXP,
3500 and make sure assembler code with a label has been output for each one.
3501 Indicate whether an ADDR_EXPR has been encountered. */
3503 static int
3504 output_addressed_constants (exp)
3505 tree exp;
3507 int reloc = 0, reloc2;
3508 tree tem;
3510 /* Give the front-end a chance to convert VALUE to something that
3511 looks more like a constant to the back-end. */
3512 exp = (*lang_hooks.expand_constant) (exp);
3514 switch (TREE_CODE (exp))
3516 case ADDR_EXPR:
3517 case FDESC_EXPR:
3518 /* Go inside any operations that get_inner_reference can handle and see
3519 if what's inside is a constant: no need to do anything here for
3520 addresses of variables or functions. */
3521 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3522 tem = TREE_OPERAND (tem, 0))
3525 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
3526 || TREE_CODE (tem) == CONSTRUCTOR)
3527 output_constant_def (tem, 0);
3529 if (TREE_PUBLIC (tem))
3530 reloc |= 2;
3531 else
3532 reloc |= 1;
3533 break;
3535 case PLUS_EXPR:
3536 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3537 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3538 break;
3540 case MINUS_EXPR:
3541 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3542 reloc2 = output_addressed_constants (TREE_OPERAND (exp, 1));
3543 /* The difference of two local labels is computable at link time. */
3544 if (reloc == 1 && reloc2 == 1)
3545 reloc = 0;
3546 else
3547 reloc |= reloc2;
3548 break;
3550 case NOP_EXPR:
3551 case CONVERT_EXPR:
3552 case NON_LVALUE_EXPR:
3553 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3554 break;
3556 case CONSTRUCTOR:
3557 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3558 if (TREE_VALUE (tem) != 0)
3559 reloc |= output_addressed_constants (TREE_VALUE (tem));
3561 break;
3563 default:
3564 break;
3566 return reloc;
3569 /* Return nonzero if VALUE is a valid constant-valued expression
3570 for use in initializing a static variable; one that can be an
3571 element of a "constant" initializer.
3573 Return null_pointer_node if the value is absolute;
3574 if it is relocatable, return the variable that determines the relocation.
3575 We assume that VALUE has been folded as much as possible;
3576 therefore, we do not need to check for such things as
3577 arithmetic-combinations of integers. */
3579 tree
3580 initializer_constant_valid_p (value, endtype)
3581 tree value;
3582 tree endtype;
3584 /* Give the front-end a chance to convert VALUE to something that
3585 looks more like a constant to the back-end. */
3586 value = (*lang_hooks.expand_constant) (value);
3588 switch (TREE_CODE (value))
3590 case CONSTRUCTOR:
3591 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
3592 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
3593 && TREE_CONSTANT (value)
3594 && CONSTRUCTOR_ELTS (value))
3595 return
3596 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
3597 endtype);
3599 return TREE_STATIC (value) ? null_pointer_node : 0;
3601 case INTEGER_CST:
3602 case VECTOR_CST:
3603 case REAL_CST:
3604 case STRING_CST:
3605 case COMPLEX_CST:
3606 return null_pointer_node;
3608 case ADDR_EXPR:
3609 case FDESC_EXPR:
3610 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
3612 case VIEW_CONVERT_EXPR:
3613 case NON_LVALUE_EXPR:
3614 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3616 case CONVERT_EXPR:
3617 case NOP_EXPR:
3618 /* Allow conversions between pointer types. */
3619 if (POINTER_TYPE_P (TREE_TYPE (value))
3620 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3621 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3623 /* Allow conversions between real types. */
3624 if (FLOAT_TYPE_P (TREE_TYPE (value))
3625 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3626 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3628 /* Allow length-preserving conversions between integer types. */
3629 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3630 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3631 && (TYPE_PRECISION (TREE_TYPE (value))
3632 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3633 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3635 /* Allow conversions between other integer types only if
3636 explicit value. */
3637 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3638 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3640 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3641 endtype);
3642 if (inner == null_pointer_node)
3643 return null_pointer_node;
3644 break;
3647 /* Allow (int) &foo provided int is as wide as a pointer. */
3648 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3649 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3650 && (TYPE_PRECISION (TREE_TYPE (value))
3651 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3652 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3653 endtype);
3655 /* Likewise conversions from int to pointers, but also allow
3656 conversions from 0. */
3657 if (POINTER_TYPE_P (TREE_TYPE (value))
3658 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3660 if (integer_zerop (TREE_OPERAND (value, 0)))
3661 return null_pointer_node;
3662 else if (TYPE_PRECISION (TREE_TYPE (value))
3663 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
3664 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3665 endtype);
3668 /* Allow conversions to union types if the value inside is okay. */
3669 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
3670 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3671 endtype);
3672 break;
3674 case PLUS_EXPR:
3675 if (! INTEGRAL_TYPE_P (endtype)
3676 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3678 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3679 endtype);
3680 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3681 endtype);
3682 /* If either term is absolute, use the other terms relocation. */
3683 if (valid0 == null_pointer_node)
3684 return valid1;
3685 if (valid1 == null_pointer_node)
3686 return valid0;
3688 break;
3690 case MINUS_EXPR:
3691 if (! INTEGRAL_TYPE_P (endtype)
3692 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3694 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3695 endtype);
3696 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3697 endtype);
3698 /* Win if second argument is absolute. */
3699 if (valid1 == null_pointer_node)
3700 return valid0;
3701 /* Win if both arguments have the same relocation.
3702 Then the value is absolute. */
3703 if (valid0 == valid1 && valid0 != 0)
3704 return null_pointer_node;
3706 /* Since GCC guarantees that string constants are unique in the
3707 generated code, a subtraction between two copies of the same
3708 constant string is absolute. */
3709 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
3710 valid1 && TREE_CODE (valid1) == STRING_CST &&
3711 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
3712 return null_pointer_node;
3715 /* Support differences between labels. */
3716 if (INTEGRAL_TYPE_P (endtype))
3718 tree op0, op1;
3719 op0 = TREE_OPERAND (value, 0);
3720 op1 = TREE_OPERAND (value, 1);
3722 /* Like STRIP_NOPS except allow the operand mode to widen.
3723 This works around a feature of fold that simplifies
3724 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3725 that the narrower operation is cheaper. */
3727 while (TREE_CODE (op0) == NOP_EXPR
3728 || TREE_CODE (op0) == CONVERT_EXPR
3729 || TREE_CODE (op0) == NON_LVALUE_EXPR)
3731 tree inner = TREE_OPERAND (op0, 0);
3732 if (inner == error_mark_node
3733 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3734 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3735 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3736 break;
3737 op0 = inner;
3740 while (TREE_CODE (op1) == NOP_EXPR
3741 || TREE_CODE (op1) == CONVERT_EXPR
3742 || TREE_CODE (op1) == NON_LVALUE_EXPR)
3744 tree inner = TREE_OPERAND (op1, 0);
3745 if (inner == error_mark_node
3746 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3747 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3748 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3749 break;
3750 op1 = inner;
3753 if (TREE_CODE (op0) == ADDR_EXPR
3754 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
3755 && TREE_CODE (op1) == ADDR_EXPR
3756 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
3757 return null_pointer_node;
3759 break;
3761 default:
3762 break;
3765 return 0;
3768 /* Output assembler code for constant EXP to FILE, with no label.
3769 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3770 Assumes output_addressed_constants has been done on EXP already.
3772 Generate exactly SIZE bytes of assembler data, padding at the end
3773 with zeros if necessary. SIZE must always be specified.
3775 SIZE is important for structure constructors,
3776 since trailing members may have been omitted from the constructor.
3777 It is also important for initialization of arrays from string constants
3778 since the full length of the string constant might not be wanted.
3779 It is also needed for initialization of unions, where the initializer's
3780 type is just one member, and that may not be as long as the union.
3782 There a case in which we would fail to output exactly SIZE bytes:
3783 for a structure constructor that wants to produce more than SIZE bytes.
3784 But such constructors will never be generated for any possible input.
3786 ALIGN is the alignment of the data in bits. */
3788 void
3789 output_constant (exp, size, align)
3790 tree exp;
3791 unsigned HOST_WIDE_INT size;
3792 unsigned int align;
3794 enum tree_code code;
3795 unsigned HOST_WIDE_INT thissize;
3797 /* Some front-ends use constants other than the standard language-independent
3798 varieties, but which may still be output directly. Give the front-end a
3799 chance to convert EXP to a language-independent representation. */
3800 exp = (*lang_hooks.expand_constant) (exp);
3802 if (size == 0 || flag_syntax_only)
3803 return;
3805 /* Eliminate any conversions since we'll be outputting the underlying
3806 constant. */
3807 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3808 || TREE_CODE (exp) == NON_LVALUE_EXPR
3809 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
3810 exp = TREE_OPERAND (exp, 0);
3812 code = TREE_CODE (TREE_TYPE (exp));
3813 thissize = int_size_in_bytes (TREE_TYPE (exp));
3815 /* Allow a constructor with no elements for any data type.
3816 This means to fill the space with zeros. */
3817 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3819 assemble_zeros (size);
3820 return;
3823 if (TREE_CODE (exp) == FDESC_EXPR)
3825 #ifdef ASM_OUTPUT_FDESC
3826 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
3827 tree decl = TREE_OPERAND (exp, 0);
3828 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
3829 #else
3830 abort ();
3831 #endif
3832 return;
3835 /* Now output the underlying data. If we've handling the padding, return.
3836 Otherwise, break and ensure THISSIZE is the size written. */
3837 switch (code)
3839 case CHAR_TYPE:
3840 case BOOLEAN_TYPE:
3841 case INTEGER_TYPE:
3842 case ENUMERAL_TYPE:
3843 case POINTER_TYPE:
3844 case REFERENCE_TYPE:
3845 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3846 EXPAND_INITIALIZER),
3847 size, align, 0))
3848 error ("initializer for integer value is too complicated");
3849 break;
3851 case REAL_TYPE:
3852 if (TREE_CODE (exp) != REAL_CST)
3853 error ("initializer for floating value is not a floating constant");
3855 assemble_real (TREE_REAL_CST (exp),
3856 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0),
3857 align);
3858 break;
3860 case COMPLEX_TYPE:
3861 output_constant (TREE_REALPART (exp), thissize / 2, align);
3862 output_constant (TREE_IMAGPART (exp), thissize / 2,
3863 min_align (align, BITS_PER_UNIT * (thissize / 2)));
3864 break;
3866 case ARRAY_TYPE:
3867 case VECTOR_TYPE:
3868 if (TREE_CODE (exp) == CONSTRUCTOR)
3870 output_constructor (exp, size, align);
3871 return;
3873 else if (TREE_CODE (exp) == STRING_CST)
3875 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
3876 size);
3877 assemble_string (TREE_STRING_POINTER (exp), thissize);
3879 else if (TREE_CODE (exp) == VECTOR_CST)
3881 int elt_size;
3882 tree link;
3883 unsigned int nalign;
3884 enum machine_mode inner;
3886 inner = GET_MODE_INNER (TYPE_MODE (TREE_TYPE (exp)));
3887 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
3889 elt_size = GET_MODE_UNIT_SIZE (TYPE_MODE (TREE_TYPE (exp)));
3891 link = TREE_VECTOR_CST_ELTS (exp);
3892 output_constant (TREE_VALUE (link), elt_size, align);
3893 while ((link = TREE_CHAIN (link)) != NULL)
3894 output_constant (TREE_VALUE (link), elt_size, nalign);
3896 else
3897 abort ();
3898 break;
3900 case RECORD_TYPE:
3901 case UNION_TYPE:
3902 if (TREE_CODE (exp) == CONSTRUCTOR)
3903 output_constructor (exp, size, align);
3904 else
3905 abort ();
3906 return;
3908 case SET_TYPE:
3909 if (TREE_CODE (exp) == INTEGER_CST)
3910 assemble_integer (expand_expr (exp, NULL_RTX,
3911 VOIDmode, EXPAND_INITIALIZER),
3912 thissize, align, 1);
3913 else if (TREE_CODE (exp) == CONSTRUCTOR)
3915 unsigned char *buffer = (unsigned char *) alloca (thissize);
3916 if (get_set_constructor_bytes (exp, buffer, thissize))
3917 abort ();
3918 assemble_string ((char *) buffer, thissize);
3920 else
3921 error ("unknown set constructor type");
3922 return;
3924 case ERROR_MARK:
3925 return;
3927 default:
3928 abort ();
3931 if (size > thissize)
3932 assemble_zeros (size - thissize);
3936 /* Subroutine of output_constructor, used for computing the size of
3937 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3938 type with an unspecified upper bound. */
3940 static unsigned HOST_WIDE_INT
3941 array_size_for_constructor (val)
3942 tree val;
3944 tree max_index, i;
3946 /* This code used to attempt to handle string constants that are not
3947 arrays of single-bytes, but nothing else does, so there's no point in
3948 doing it here. */
3949 if (TREE_CODE (val) == STRING_CST)
3950 return TREE_STRING_LENGTH (val);
3952 max_index = NULL_TREE;
3953 for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i))
3955 tree index = TREE_PURPOSE (i);
3957 if (TREE_CODE (index) == RANGE_EXPR)
3958 index = TREE_OPERAND (index, 1);
3959 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
3960 max_index = index;
3963 if (max_index == NULL_TREE)
3964 return 0;
3966 /* Compute the total number of array elements. */
3967 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
3968 convert (sizetype,
3969 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
3970 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
3972 /* Multiply by the array element unit size to find number of bytes. */
3973 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
3975 return tree_low_cst (i, 1);
3978 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3979 Generate at least SIZE bytes, padding if necessary. */
3981 static void
3982 output_constructor (exp, size, align)
3983 tree exp;
3984 unsigned HOST_WIDE_INT size;
3985 unsigned int align;
3987 tree type = TREE_TYPE (exp);
3988 tree link, field = 0;
3989 tree min_index = 0;
3990 /* Number of bytes output or skipped so far.
3991 In other words, current position within the constructor. */
3992 HOST_WIDE_INT total_bytes = 0;
3993 /* Nonzero means BYTE contains part of a byte, to be output. */
3994 int byte_buffer_in_use = 0;
3995 int byte = 0;
3997 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3998 abort ();
4000 if (TREE_CODE (type) == RECORD_TYPE)
4001 field = TYPE_FIELDS (type);
4003 if (TREE_CODE (type) == ARRAY_TYPE
4004 && TYPE_DOMAIN (type) != 0)
4005 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4007 /* As LINK goes through the elements of the constant,
4008 FIELD goes through the structure fields, if the constant is a structure.
4009 if the constant is a union, then we override this,
4010 by getting the field from the TREE_LIST element.
4011 But the constant could also be an array. Then FIELD is zero.
4013 There is always a maximum of one element in the chain LINK for unions
4014 (even if the initializer in a source program incorrectly contains
4015 more one). */
4016 for (link = CONSTRUCTOR_ELTS (exp);
4017 link;
4018 link = TREE_CHAIN (link),
4019 field = field ? TREE_CHAIN (field) : 0)
4021 tree val = TREE_VALUE (link);
4022 tree index = 0;
4024 /* The element in a union constructor specifies the proper field
4025 or index. */
4026 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4027 || TREE_CODE (type) == QUAL_UNION_TYPE)
4028 && TREE_PURPOSE (link) != 0)
4029 field = TREE_PURPOSE (link);
4031 else if (TREE_CODE (type) == ARRAY_TYPE)
4032 index = TREE_PURPOSE (link);
4034 /* Eliminate the marker that makes a cast not be an lvalue. */
4035 if (val != 0)
4036 STRIP_NOPS (val);
4038 if (index && TREE_CODE (index) == RANGE_EXPR)
4040 unsigned HOST_WIDE_INT fieldsize
4041 = int_size_in_bytes (TREE_TYPE (type));
4042 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4043 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4044 HOST_WIDE_INT index;
4045 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4047 for (index = lo_index; index <= hi_index; index++)
4049 /* Output the element's initial value. */
4050 if (val == 0)
4051 assemble_zeros (fieldsize);
4052 else
4053 output_constant (val, fieldsize, align2);
4055 /* Count its size. */
4056 total_bytes += fieldsize;
4059 else if (field == 0 || !DECL_BIT_FIELD (field))
4061 /* An element that is not a bit-field. */
4063 unsigned HOST_WIDE_INT fieldsize;
4064 /* Since this structure is static,
4065 we know the positions are constant. */
4066 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4067 unsigned int align2;
4069 if (index != 0)
4070 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4071 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4073 /* Output any buffered-up bit-fields preceding this element. */
4074 if (byte_buffer_in_use)
4076 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4077 total_bytes++;
4078 byte_buffer_in_use = 0;
4081 /* Advance to offset of this element.
4082 Note no alignment needed in an array, since that is guaranteed
4083 if each element has the proper size. */
4084 if ((field != 0 || index != 0) && pos != total_bytes)
4086 assemble_zeros (pos - total_bytes);
4087 total_bytes = pos;
4090 /* Find the alignment of this element. */
4091 align2 = min_align (align, BITS_PER_UNIT * pos);
4093 /* Determine size this element should occupy. */
4094 if (field)
4096 fieldsize = 0;
4098 /* If this is an array with an unspecified upper bound,
4099 the initializer determines the size. */
4100 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4101 but we cannot do this until the deprecated support for
4102 initializing zero-length array members is removed. */
4103 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4104 && TYPE_DOMAIN (TREE_TYPE (field))
4105 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4107 fieldsize = array_size_for_constructor (val);
4108 /* Given a non-empty initialization, this field had
4109 better be last. */
4110 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4111 abort ();
4113 else if (DECL_SIZE_UNIT (field))
4115 /* ??? This can't be right. If the decl size overflows
4116 a host integer we will silently emit no data. */
4117 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4118 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4121 else
4122 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4124 /* Output the element's initial value. */
4125 if (val == 0)
4126 assemble_zeros (fieldsize);
4127 else
4128 output_constant (val, fieldsize, align2);
4130 /* Count its size. */
4131 total_bytes += fieldsize;
4133 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4134 error ("invalid initial value for member `%s'",
4135 IDENTIFIER_POINTER (DECL_NAME (field)));
4136 else
4138 /* Element that is a bit-field. */
4140 HOST_WIDE_INT next_offset = int_bit_position (field);
4141 HOST_WIDE_INT end_offset
4142 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4144 if (val == 0)
4145 val = integer_zero_node;
4147 /* If this field does not start in this (or, next) byte,
4148 skip some bytes. */
4149 if (next_offset / BITS_PER_UNIT != total_bytes)
4151 /* Output remnant of any bit field in previous bytes. */
4152 if (byte_buffer_in_use)
4154 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4155 total_bytes++;
4156 byte_buffer_in_use = 0;
4159 /* If still not at proper byte, advance to there. */
4160 if (next_offset / BITS_PER_UNIT != total_bytes)
4162 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4163 total_bytes = next_offset / BITS_PER_UNIT;
4167 if (! byte_buffer_in_use)
4168 byte = 0;
4170 /* We must split the element into pieces that fall within
4171 separate bytes, and combine each byte with previous or
4172 following bit-fields. */
4174 /* next_offset is the offset n fbits from the beginning of
4175 the structure to the next bit of this element to be processed.
4176 end_offset is the offset of the first bit past the end of
4177 this element. */
4178 while (next_offset < end_offset)
4180 int this_time;
4181 int shift;
4182 HOST_WIDE_INT value;
4183 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4184 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4186 /* Advance from byte to byte
4187 within this element when necessary. */
4188 while (next_byte != total_bytes)
4190 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4191 total_bytes++;
4192 byte = 0;
4195 /* Number of bits we can process at once
4196 (all part of the same byte). */
4197 this_time = MIN (end_offset - next_offset,
4198 BITS_PER_UNIT - next_bit);
4199 if (BYTES_BIG_ENDIAN)
4201 /* On big-endian machine, take the most significant bits
4202 first (of the bits that are significant)
4203 and put them into bytes from the most significant end. */
4204 shift = end_offset - next_offset - this_time;
4206 /* Don't try to take a bunch of bits that cross
4207 the word boundary in the INTEGER_CST. We can
4208 only select bits from the LOW or HIGH part
4209 not from both. */
4210 if (shift < HOST_BITS_PER_WIDE_INT
4211 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4213 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4214 shift = HOST_BITS_PER_WIDE_INT;
4217 /* Now get the bits from the appropriate constant word. */
4218 if (shift < HOST_BITS_PER_WIDE_INT)
4219 value = TREE_INT_CST_LOW (val);
4220 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4222 value = TREE_INT_CST_HIGH (val);
4223 shift -= HOST_BITS_PER_WIDE_INT;
4225 else
4226 abort ();
4228 /* Get the result. This works only when:
4229 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4230 byte |= (((value >> shift)
4231 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4232 << (BITS_PER_UNIT - this_time - next_bit));
4234 else
4236 /* On little-endian machines,
4237 take first the least significant bits of the value
4238 and pack them starting at the least significant
4239 bits of the bytes. */
4240 shift = next_offset - int_bit_position (field);
4242 /* Don't try to take a bunch of bits that cross
4243 the word boundary in the INTEGER_CST. We can
4244 only select bits from the LOW or HIGH part
4245 not from both. */
4246 if (shift < HOST_BITS_PER_WIDE_INT
4247 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4248 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4250 /* Now get the bits from the appropriate constant word. */
4251 if (shift < HOST_BITS_PER_WIDE_INT)
4252 value = TREE_INT_CST_LOW (val);
4253 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4255 value = TREE_INT_CST_HIGH (val);
4256 shift -= HOST_BITS_PER_WIDE_INT;
4258 else
4259 abort ();
4261 /* Get the result. This works only when:
4262 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4263 byte |= (((value >> shift)
4264 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4265 << next_bit);
4268 next_offset += this_time;
4269 byte_buffer_in_use = 1;
4274 if (byte_buffer_in_use)
4276 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4277 total_bytes++;
4280 if ((unsigned HOST_WIDE_INT)total_bytes < size)
4281 assemble_zeros (size - total_bytes);
4284 /* This TREE_LIST contains any weak symbol declarations waiting
4285 to be emitted. */
4286 static GTY(()) tree weak_decls;
4288 /* Mark DECL as weak. */
4290 static void
4291 mark_weak (decl)
4292 tree decl;
4294 DECL_WEAK (decl) = 1;
4296 if (DECL_RTL_SET_P (decl)
4297 && GET_CODE (DECL_RTL (decl)) == MEM
4298 && XEXP (DECL_RTL (decl), 0)
4299 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4300 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4303 /* Merge weak status between NEWDECL and OLDDECL. */
4305 void
4306 merge_weak (newdecl, olddecl)
4307 tree newdecl;
4308 tree olddecl;
4310 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4311 return;
4313 if (DECL_WEAK (newdecl))
4315 tree wd;
4317 /* NEWDECL is weak, but OLDDECL is not. */
4319 /* If we already output the OLDDECL, we're in trouble; we can't
4320 go back and make it weak. This error cannot caught in
4321 declare_weak because the NEWDECL and OLDDECL was not yet
4322 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4323 if (TREE_ASM_WRITTEN (olddecl))
4324 error_with_decl (newdecl,
4325 "weak declaration of `%s' must precede definition");
4327 /* If we've already generated rtl referencing OLDDECL, we may
4328 have done so in a way that will not function properly with
4329 a weak symbol. */
4330 else if (TREE_USED (olddecl)
4331 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4332 warning_with_decl (newdecl, "weak declaration of `%s' after first use results in unspecified behavior");
4334 if (SUPPORTS_WEAK)
4336 /* We put the NEWDECL on the weak_decls list at some point.
4337 Replace it with the OLDDECL. */
4338 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4339 if (TREE_VALUE (wd) == newdecl)
4341 TREE_VALUE (wd) = olddecl;
4342 break;
4344 /* We may not find the entry on the list. If NEWDECL is a
4345 weak alias, then we will have already called
4346 globalize_decl to remove the entry; in that case, we do
4347 not need to do anything. */
4350 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4351 mark_weak (olddecl);
4353 else
4354 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4355 weak. Just update NEWDECL to indicate that it's weak too. */
4356 mark_weak (newdecl);
4359 /* Declare DECL to be a weak symbol. */
4361 void
4362 declare_weak (decl)
4363 tree decl;
4365 if (! TREE_PUBLIC (decl))
4366 error_with_decl (decl, "weak declaration of `%s' must be public");
4367 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4368 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4369 else if (SUPPORTS_WEAK)
4371 if (! DECL_WEAK (decl))
4372 weak_decls = tree_cons (NULL, decl, weak_decls);
4374 else
4375 warning_with_decl (decl, "weak declaration of `%s' not supported");
4377 mark_weak (decl);
4380 /* Emit any pending weak declarations. */
4382 void
4383 weak_finish ()
4385 tree t;
4387 for (t = weak_decls; t; t = TREE_CHAIN (t))
4389 tree decl = TREE_VALUE (t);
4390 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4391 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4392 #endif
4394 if (! TREE_USED (decl))
4395 continue;
4397 #ifdef ASM_WEAKEN_DECL
4398 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4399 #else
4400 #ifdef ASM_WEAKEN_LABEL
4401 ASM_WEAKEN_LABEL (asm_out_file, name);
4402 #else
4403 #ifdef ASM_OUTPUT_WEAK_ALIAS
4404 warning ("only weak aliases are supported in this configuration");
4405 return;
4406 #endif
4407 #endif
4408 #endif
4412 /* Emit the assembly bits to indicate that DECL is globally visible. */
4414 static void
4415 globalize_decl (decl)
4416 tree decl;
4418 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4420 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4421 if (DECL_WEAK (decl))
4423 tree *p, t;
4425 #ifdef ASM_WEAKEN_DECL
4426 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4427 #else
4428 ASM_WEAKEN_LABEL (asm_out_file, name);
4429 #endif
4431 /* Remove this function from the pending weak list so that
4432 we do not emit multiple .weak directives for it. */
4433 for (p = &weak_decls; (t = *p) ; )
4435 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4436 *p = TREE_CHAIN (t);
4437 else
4438 p = &TREE_CHAIN (t);
4440 return;
4442 #endif
4444 (*targetm.asm_out.globalize_label) (asm_out_file, name);
4447 /* Emit an assembler directive to make the symbol for DECL an alias to
4448 the symbol for TARGET. */
4450 void
4451 assemble_alias (decl, target)
4452 tree decl, target ATTRIBUTE_UNUSED;
4454 const char *name;
4456 /* We must force creation of DECL_RTL for debug info generation, even though
4457 we don't use it here. */
4458 make_decl_rtl (decl, NULL);
4460 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4462 #ifdef ASM_OUTPUT_DEF
4463 /* Make name accessible from other files, if appropriate. */
4465 if (TREE_PUBLIC (decl))
4467 globalize_decl (decl);
4468 maybe_assemble_visibility (decl);
4471 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4472 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4473 #else
4474 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4475 #endif
4476 #else /* !ASM_OUTPUT_DEF */
4477 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4478 if (! DECL_WEAK (decl))
4479 warning ("only weak aliases are supported in this configuration");
4481 #ifdef ASM_WEAKEN_DECL
4482 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4483 #else
4484 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4485 #endif
4486 #else
4487 warning ("alias definitions not supported in this configuration; ignored");
4488 #endif
4489 #endif
4491 TREE_USED (decl) = 1;
4492 TREE_ASM_WRITTEN (decl) = 1;
4493 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4496 /* Emit an assembler directive to set symbol for DECL visibility to
4497 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4499 void
4500 default_assemble_visibility (decl, vis)
4501 tree decl;
4502 int vis;
4504 static const char * const visibility_types[] = {
4505 NULL, "internal", "hidden", "protected"
4508 const char *name, *type;
4510 name = (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4511 type = visibility_types[vis];
4513 #ifdef HAVE_GAS_HIDDEN
4514 fprintf (asm_out_file, "\t.%s\t", type);
4515 assemble_name (asm_out_file, name);
4516 fprintf (asm_out_file, "\n");
4517 #else
4518 warning ("visibility attribute not supported in this configuration; ignored");
4519 #endif
4522 /* A helper function to call assemble_visibility when needed for a decl. */
4524 static void
4525 maybe_assemble_visibility (decl)
4526 tree decl;
4528 enum symbol_visibility vis = decl_visibility (decl);
4530 if (vis != VISIBILITY_DEFAULT)
4531 (* targetm.asm_out.visibility) (decl, vis);
4534 /* Returns 1 if the target configuration supports defining public symbols
4535 so that one of them will be chosen at link time instead of generating a
4536 multiply-defined symbol error, whether through the use of weak symbols or
4537 a target-specific mechanism for having duplicates discarded. */
4540 supports_one_only ()
4542 if (SUPPORTS_ONE_ONLY)
4543 return 1;
4544 return SUPPORTS_WEAK;
4547 /* Set up DECL as a public symbol that can be defined in multiple
4548 translation units without generating a linker error. */
4550 void
4551 make_decl_one_only (decl)
4552 tree decl;
4554 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4555 abort ();
4557 TREE_PUBLIC (decl) = 1;
4559 if (TREE_CODE (decl) == VAR_DECL
4560 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4561 DECL_COMMON (decl) = 1;
4562 else if (SUPPORTS_ONE_ONLY)
4564 #ifdef MAKE_DECL_ONE_ONLY
4565 MAKE_DECL_ONE_ONLY (decl);
4566 #endif
4567 DECL_ONE_ONLY (decl) = 1;
4569 else if (SUPPORTS_WEAK)
4570 DECL_WEAK (decl) = 1;
4571 else
4572 abort ();
4575 void
4576 init_varasm_once ()
4578 in_named_htab = htab_create_ggc (31, in_named_entry_hash,
4579 in_named_entry_eq, NULL);
4580 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
4581 const_desc_eq, NULL);
4583 const_alias_set = new_alias_set ();
4586 enum tls_model
4587 decl_tls_model (decl)
4588 tree decl;
4590 enum tls_model kind;
4591 tree attr = lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl));
4592 bool is_local;
4594 if (attr)
4596 attr = TREE_VALUE (TREE_VALUE (attr));
4597 if (TREE_CODE (attr) != STRING_CST)
4598 abort ();
4599 if (!strcmp (TREE_STRING_POINTER (attr), "local-exec"))
4600 kind = TLS_MODEL_LOCAL_EXEC;
4601 else if (!strcmp (TREE_STRING_POINTER (attr), "initial-exec"))
4602 kind = TLS_MODEL_INITIAL_EXEC;
4603 else if (!strcmp (TREE_STRING_POINTER (attr), "local-dynamic"))
4604 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
4605 else if (!strcmp (TREE_STRING_POINTER (attr), "global-dynamic"))
4606 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4607 else
4608 abort ();
4609 return kind;
4612 is_local = (*targetm.binds_local_p) (decl);
4613 if (!flag_pic)
4615 if (is_local)
4616 kind = TLS_MODEL_LOCAL_EXEC;
4617 else
4618 kind = TLS_MODEL_INITIAL_EXEC;
4620 /* Local dynamic is inefficient when we're not combining the
4621 parts of the address. */
4622 else if (optimize && is_local)
4623 kind = TLS_MODEL_LOCAL_DYNAMIC;
4624 else
4625 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4626 if (kind < flag_tls_default)
4627 kind = flag_tls_default;
4629 return kind;
4632 enum symbol_visibility
4633 decl_visibility (decl)
4634 tree decl;
4636 tree attr = lookup_attribute ("visibility", DECL_ATTRIBUTES (decl));
4638 if (attr)
4640 const char *which = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
4642 if (strcmp (which, "default") == 0)
4643 return VISIBILITY_DEFAULT;
4644 if (strcmp (which, "internal") == 0)
4645 return VISIBILITY_INTERNAL;
4646 if (strcmp (which, "hidden") == 0)
4647 return VISIBILITY_HIDDEN;
4648 if (strcmp (which, "protected") == 0)
4649 return VISIBILITY_PROTECTED;
4651 abort ();
4654 return VISIBILITY_DEFAULT;
4657 /* Select a set of attributes for section NAME based on the properties
4658 of DECL and whether or not RELOC indicates that DECL's initializer
4659 might contain runtime relocations.
4661 We make the section read-only and executable for a function decl,
4662 read-only for a const data decl, and writable for a non-const data decl. */
4664 unsigned int
4665 default_section_type_flags (decl, name, reloc)
4666 tree decl;
4667 const char *name;
4668 int reloc;
4670 return default_section_type_flags_1 (decl, name, reloc, flag_pic);
4673 unsigned int
4674 default_section_type_flags_1 (decl, name, reloc, shlib)
4675 tree decl;
4676 const char *name;
4677 int reloc;
4678 int shlib;
4680 unsigned int flags;
4682 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4683 flags = SECTION_CODE;
4684 else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
4685 flags = 0;
4686 else
4687 flags = SECTION_WRITE;
4689 if (decl && DECL_ONE_ONLY (decl))
4690 flags |= SECTION_LINKONCE;
4692 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4693 flags |= SECTION_TLS | SECTION_WRITE;
4695 if (strcmp (name, ".bss") == 0
4696 || strncmp (name, ".bss.", 5) == 0
4697 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
4698 || strcmp (name, ".sbss") == 0
4699 || strncmp (name, ".sbss.", 6) == 0
4700 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0
4701 || strcmp (name, ".tbss") == 0
4702 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4703 flags |= SECTION_BSS;
4705 if (strcmp (name, ".tdata") == 0
4706 || strcmp (name, ".tbss") == 0
4707 || strncmp (name, ".gnu.linkonce.td.", 17) == 0
4708 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4709 flags |= SECTION_TLS;
4711 /* These three sections have special ELF types. They are neither
4712 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4713 want to print a section type (@progbits or @nobits). If someone
4714 is silly enough to emit code or TLS variables to one of these
4715 sections, then don't handle them specially. */
4716 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
4717 && (strcmp (name, ".init_array") == 0
4718 || strcmp (name, ".fini_array") == 0
4719 || strcmp (name, ".preinit_array") == 0))
4720 flags |= SECTION_NOTYPE;
4722 return flags;
4725 /* Output assembly to switch to section NAME with attribute FLAGS.
4726 Four variants for common object file formats. */
4728 void
4729 default_no_named_section (name, flags)
4730 const char *name ATTRIBUTE_UNUSED;
4731 unsigned int flags ATTRIBUTE_UNUSED;
4733 /* Some object formats don't support named sections at all. The
4734 front-end should already have flagged this as an error. */
4735 abort ();
4738 void
4739 default_elf_asm_named_section (name, flags)
4740 const char *name;
4741 unsigned int flags;
4743 char flagchars[10], *f = flagchars;
4745 if (! named_section_first_declaration (name))
4747 fprintf (asm_out_file, "\t.section\t%s\n", name);
4748 return;
4751 if (!(flags & SECTION_DEBUG))
4752 *f++ = 'a';
4753 if (flags & SECTION_WRITE)
4754 *f++ = 'w';
4755 if (flags & SECTION_CODE)
4756 *f++ = 'x';
4757 if (flags & SECTION_SMALL)
4758 *f++ = 's';
4759 if (flags & SECTION_MERGE)
4760 *f++ = 'M';
4761 if (flags & SECTION_STRINGS)
4762 *f++ = 'S';
4763 if (flags & SECTION_TLS)
4764 *f++ = 'T';
4765 *f = '\0';
4767 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
4769 if (!(flags & SECTION_NOTYPE))
4771 const char *type;
4773 if (flags & SECTION_BSS)
4774 type = "nobits";
4775 else
4776 type = "progbits";
4778 fprintf (asm_out_file, ",@%s", type);
4780 if (flags & SECTION_ENTSIZE)
4781 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
4784 putc ('\n', asm_out_file);
4787 void
4788 default_coff_asm_named_section (name, flags)
4789 const char *name;
4790 unsigned int flags;
4792 char flagchars[8], *f = flagchars;
4794 if (flags & SECTION_WRITE)
4795 *f++ = 'w';
4796 if (flags & SECTION_CODE)
4797 *f++ = 'x';
4798 *f = '\0';
4800 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
4803 void
4804 default_pe_asm_named_section (name, flags)
4805 const char *name;
4806 unsigned int flags;
4808 default_coff_asm_named_section (name, flags);
4810 if (flags & SECTION_LINKONCE)
4812 /* Functions may have been compiled at various levels of
4813 optimization so we can't use `same_size' here.
4814 Instead, have the linker pick one. */
4815 fprintf (asm_out_file, "\t.linkonce %s\n",
4816 (flags & SECTION_CODE ? "discard" : "same_size"));
4820 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
4821 from SYMBOL is used in all classes derived from SYMBOL. */
4823 void
4824 assemble_vtable_entry (symbol, offset)
4825 rtx symbol;
4826 HOST_WIDE_INT offset;
4828 fputs ("\t.vtable_entry ", asm_out_file);
4829 output_addr_const (asm_out_file, symbol);
4830 fprintf (asm_out_file, ", " HOST_WIDE_INT_PRINT_DEC "\n", offset);
4833 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
4834 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
4836 void
4837 assemble_vtable_inherit (child, parent)
4838 rtx child, parent;
4840 fputs ("\t.vtable_inherit ", asm_out_file);
4841 output_addr_const (asm_out_file, child);
4842 fputs (", ", asm_out_file);
4843 output_addr_const (asm_out_file, parent);
4844 fputc ('\n', asm_out_file);
4847 /* The lame default section selector. */
4849 void
4850 default_select_section (decl, reloc, align)
4851 tree decl;
4852 int reloc;
4853 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
4855 bool readonly = false;
4857 if (DECL_P (decl))
4859 if (decl_readonly_section (decl, reloc))
4860 readonly = true;
4862 else if (TREE_CODE (decl) == CONSTRUCTOR)
4864 if (! ((flag_pic && reloc)
4865 || !TREE_READONLY (decl)
4866 || TREE_SIDE_EFFECTS (decl)
4867 || !TREE_CONSTANT (decl)))
4868 readonly = true;
4870 else if (TREE_CODE (decl) == STRING_CST)
4871 readonly = !flag_writable_strings;
4872 else if (! (flag_pic && reloc))
4873 readonly = true;
4875 if (readonly)
4876 readonly_data_section ();
4877 else
4878 data_section ();
4881 /* A helper function for default_elf_select_section and
4882 default_elf_unique_section. Categorizes the DECL. */
4884 enum section_category
4886 SECCAT_TEXT,
4888 SECCAT_RODATA,
4889 SECCAT_RODATA_MERGE_STR,
4890 SECCAT_RODATA_MERGE_STR_INIT,
4891 SECCAT_RODATA_MERGE_CONST,
4892 SECCAT_SRODATA,
4894 SECCAT_DATA,
4896 /* To optimize loading of shared programs, define following subsections
4897 of data section:
4898 _REL Contains data that has relocations, so they get grouped
4899 together and dynamic linker will visit fewer pages in memory.
4900 _RO Contains data that is otherwise read-only. This is useful
4901 with prelinking as most relocations won't be dynamically
4902 linked and thus stay read only.
4903 _LOCAL Marks data containing relocations only to local objects.
4904 These relocations will get fully resolved by prelinking. */
4905 SECCAT_DATA_REL,
4906 SECCAT_DATA_REL_LOCAL,
4907 SECCAT_DATA_REL_RO,
4908 SECCAT_DATA_REL_RO_LOCAL,
4910 SECCAT_SDATA,
4911 SECCAT_TDATA,
4913 SECCAT_BSS,
4914 SECCAT_SBSS,
4915 SECCAT_TBSS
4918 static enum section_category
4919 categorize_decl_for_section PARAMS ((tree, int, int));
4921 static enum section_category
4922 categorize_decl_for_section (decl, reloc, shlib)
4923 tree decl;
4924 int reloc;
4925 int shlib;
4927 enum section_category ret;
4929 if (TREE_CODE (decl) == FUNCTION_DECL)
4930 return SECCAT_TEXT;
4931 else if (TREE_CODE (decl) == STRING_CST)
4933 if (flag_writable_strings)
4934 return SECCAT_DATA;
4935 else
4936 return SECCAT_RODATA_MERGE_STR;
4938 else if (TREE_CODE (decl) == VAR_DECL)
4940 if (DECL_INITIAL (decl) == NULL
4941 || DECL_INITIAL (decl) == error_mark_node)
4942 ret = SECCAT_BSS;
4943 else if (! TREE_READONLY (decl)
4944 || TREE_SIDE_EFFECTS (decl)
4945 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
4947 if (shlib && (reloc & 2))
4948 ret = SECCAT_DATA_REL;
4949 else if (shlib && reloc)
4950 ret = SECCAT_DATA_REL_LOCAL;
4951 else
4952 ret = SECCAT_DATA;
4954 else if (shlib && (reloc & 2))
4955 ret = SECCAT_DATA_REL_RO;
4956 else if (shlib && reloc)
4957 ret = SECCAT_DATA_REL_RO_LOCAL;
4958 else if (reloc || flag_merge_constants < 2)
4959 /* C and C++ don't allow different variables to share the same
4960 location. -fmerge-all-constants allows even that (at the
4961 expense of not conforming). */
4962 ret = SECCAT_RODATA;
4963 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
4964 ret = SECCAT_RODATA_MERGE_STR_INIT;
4965 else
4966 ret = SECCAT_RODATA_MERGE_CONST;
4968 else if (TREE_CODE (decl) == CONSTRUCTOR)
4970 if ((shlib && reloc)
4971 || TREE_SIDE_EFFECTS (decl)
4972 || ! TREE_CONSTANT (decl))
4973 ret = SECCAT_DATA;
4974 else
4975 ret = SECCAT_RODATA;
4977 else
4978 ret = SECCAT_RODATA;
4980 /* There are no read-only thread-local sections. */
4981 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4983 if (ret == SECCAT_BSS)
4984 ret = SECCAT_TBSS;
4985 else
4986 ret = SECCAT_TDATA;
4989 /* If the target uses small data sections, select it. */
4990 else if ((*targetm.in_small_data_p) (decl))
4992 if (ret == SECCAT_BSS)
4993 ret = SECCAT_SBSS;
4994 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
4995 ret = SECCAT_SRODATA;
4996 else
4997 ret = SECCAT_SDATA;
5000 return ret;
5003 bool
5004 decl_readonly_section (decl, reloc)
5005 tree decl;
5006 int reloc;
5008 return decl_readonly_section_1 (decl, reloc, flag_pic);
5011 bool
5012 decl_readonly_section_1 (decl, reloc, shlib)
5013 tree decl;
5014 int reloc;
5015 int shlib;
5017 switch (categorize_decl_for_section (decl, reloc, shlib))
5019 case SECCAT_RODATA:
5020 case SECCAT_RODATA_MERGE_STR:
5021 case SECCAT_RODATA_MERGE_STR_INIT:
5022 case SECCAT_RODATA_MERGE_CONST:
5023 case SECCAT_SRODATA:
5024 return true;
5025 break;
5026 default:
5027 return false;
5028 break;
5032 /* Select a section based on the above categorization. */
5034 void
5035 default_elf_select_section (decl, reloc, align)
5036 tree decl;
5037 int reloc;
5038 unsigned HOST_WIDE_INT align;
5040 default_elf_select_section_1 (decl, reloc, align, flag_pic);
5043 void
5044 default_elf_select_section_1 (decl, reloc, align, shlib)
5045 tree decl;
5046 int reloc;
5047 unsigned HOST_WIDE_INT align;
5048 int shlib;
5050 switch (categorize_decl_for_section (decl, reloc, shlib))
5052 case SECCAT_TEXT:
5053 /* We're not supposed to be called on FUNCTION_DECLs. */
5054 abort ();
5055 case SECCAT_RODATA:
5056 readonly_data_section ();
5057 break;
5058 case SECCAT_RODATA_MERGE_STR:
5059 mergeable_string_section (decl, align, 0);
5060 break;
5061 case SECCAT_RODATA_MERGE_STR_INIT:
5062 mergeable_string_section (DECL_INITIAL (decl), align, 0);
5063 break;
5064 case SECCAT_RODATA_MERGE_CONST:
5065 mergeable_constant_section (DECL_MODE (decl), align, 0);
5066 break;
5067 case SECCAT_SRODATA:
5068 named_section (NULL_TREE, ".sdata2", reloc);
5069 break;
5070 case SECCAT_DATA:
5071 data_section ();
5072 break;
5073 case SECCAT_DATA_REL:
5074 named_section (NULL_TREE, ".data.rel", reloc);
5075 break;
5076 case SECCAT_DATA_REL_LOCAL:
5077 named_section (NULL_TREE, ".data.rel.local", reloc);
5078 break;
5079 case SECCAT_DATA_REL_RO:
5080 named_section (NULL_TREE, ".data.rel.ro", reloc);
5081 break;
5082 case SECCAT_DATA_REL_RO_LOCAL:
5083 named_section (NULL_TREE, ".data.rel.ro.local", reloc);
5084 break;
5085 case SECCAT_SDATA:
5086 named_section (NULL_TREE, ".sdata", reloc);
5087 break;
5088 case SECCAT_TDATA:
5089 named_section (NULL_TREE, ".tdata", reloc);
5090 break;
5091 case SECCAT_BSS:
5092 #ifdef BSS_SECTION_ASM_OP
5093 bss_section ();
5094 #else
5095 named_section (NULL_TREE, ".bss", reloc);
5096 #endif
5097 break;
5098 case SECCAT_SBSS:
5099 named_section (NULL_TREE, ".sbss", reloc);
5100 break;
5101 case SECCAT_TBSS:
5102 named_section (NULL_TREE, ".tbss", reloc);
5103 break;
5104 default:
5105 abort ();
5109 /* Construct a unique section name based on the decl name and the
5110 categorization performed above. */
5112 void
5113 default_unique_section (decl, reloc)
5114 tree decl;
5115 int reloc;
5117 default_unique_section_1 (decl, reloc, flag_pic);
5120 void
5121 default_unique_section_1 (decl, reloc, shlib)
5122 tree decl;
5123 int reloc;
5124 int shlib;
5126 bool one_only = DECL_ONE_ONLY (decl);
5127 const char *prefix, *name;
5128 size_t nlen, plen;
5129 char *string;
5131 switch (categorize_decl_for_section (decl, reloc, shlib))
5133 case SECCAT_TEXT:
5134 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
5135 break;
5136 case SECCAT_RODATA:
5137 case SECCAT_RODATA_MERGE_STR:
5138 case SECCAT_RODATA_MERGE_STR_INIT:
5139 case SECCAT_RODATA_MERGE_CONST:
5140 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
5141 break;
5142 case SECCAT_SRODATA:
5143 prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
5144 break;
5145 case SECCAT_DATA:
5146 case SECCAT_DATA_REL:
5147 case SECCAT_DATA_REL_LOCAL:
5148 case SECCAT_DATA_REL_RO:
5149 case SECCAT_DATA_REL_RO_LOCAL:
5150 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
5151 break;
5152 case SECCAT_SDATA:
5153 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
5154 break;
5155 case SECCAT_BSS:
5156 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
5157 break;
5158 case SECCAT_SBSS:
5159 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
5160 break;
5161 case SECCAT_TDATA:
5162 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
5163 break;
5164 case SECCAT_TBSS:
5165 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
5166 break;
5167 default:
5168 abort ();
5170 plen = strlen (prefix);
5172 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5173 name = (* targetm.strip_name_encoding) (name);
5174 nlen = strlen (name);
5176 string = alloca (nlen + plen + 1);
5177 memcpy (string, prefix, plen);
5178 memcpy (string + plen, name, nlen + 1);
5180 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
5183 void
5184 default_select_rtx_section (mode, x, align)
5185 enum machine_mode mode ATTRIBUTE_UNUSED;
5186 rtx x;
5187 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
5189 if (flag_pic)
5190 switch (GET_CODE (x))
5192 case CONST:
5193 case SYMBOL_REF:
5194 case LABEL_REF:
5195 data_section ();
5196 return;
5198 default:
5199 break;
5202 readonly_data_section ();
5205 void
5206 default_elf_select_rtx_section (mode, x, align)
5207 enum machine_mode mode;
5208 rtx x;
5209 unsigned HOST_WIDE_INT align;
5211 /* ??? Handle small data here somehow. */
5213 if (flag_pic)
5214 switch (GET_CODE (x))
5216 case CONST:
5217 case SYMBOL_REF:
5218 named_section (NULL_TREE, ".data.rel.ro", 3);
5219 return;
5221 case LABEL_REF:
5222 named_section (NULL_TREE, ".data.rel.ro.local", 1);
5223 return;
5225 default:
5226 break;
5229 mergeable_constant_section (mode, align, 0);
5232 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5234 void
5235 default_encode_section_info (decl, rtl, first)
5236 tree decl;
5237 rtx rtl;
5238 int first ATTRIBUTE_UNUSED;
5240 rtx symbol;
5241 int flags;
5243 /* Careful not to prod global register variables. */
5244 if (GET_CODE (rtl) != MEM)
5245 return;
5246 symbol = XEXP (rtl, 0);
5247 if (GET_CODE (symbol) != SYMBOL_REF)
5248 return;
5250 flags = 0;
5251 if (TREE_CODE (decl) == FUNCTION_DECL)
5252 flags |= SYMBOL_FLAG_FUNCTION;
5253 if ((*targetm.binds_local_p) (decl))
5254 flags |= SYMBOL_FLAG_LOCAL;
5255 if ((*targetm.in_small_data_p) (decl))
5256 flags |= SYMBOL_FLAG_SMALL;
5257 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
5258 flags |= decl_tls_model (decl) << SYMBOL_FLAG_TLS_SHIFT;
5259 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5260 being PUBLIC, the thing *must* be defined in this translation unit.
5261 Prevent this buglet from being propagated into rtl code as well. */
5262 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
5263 flags |= SYMBOL_FLAG_EXTERNAL;
5265 SYMBOL_REF_FLAGS (symbol) = flags;
5268 /* By default, we do nothing for encode_section_info, so we need not
5269 do anything but discard the '*' marker. */
5271 const char *
5272 default_strip_name_encoding (str)
5273 const char *str;
5275 return str + (*str == '*');
5278 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5279 wrt cross-module name binding. */
5281 bool
5282 default_binds_local_p (exp)
5283 tree exp;
5285 return default_binds_local_p_1 (exp, flag_shlib);
5288 bool
5289 default_binds_local_p_1 (exp, shlib)
5290 tree exp;
5291 int shlib;
5293 bool local_p;
5295 /* A non-decl is an entry in the constant pool. */
5296 if (!DECL_P (exp))
5297 local_p = true;
5298 /* Static variables are always local. */
5299 else if (! TREE_PUBLIC (exp))
5300 local_p = true;
5301 /* A variable is local if the user tells us so. */
5302 else if (decl_visibility (exp) != VISIBILITY_DEFAULT)
5303 local_p = true;
5304 /* Otherwise, variables defined outside this object may not be local. */
5305 else if (DECL_EXTERNAL (exp))
5306 local_p = false;
5307 /* Linkonce and weak data are never local. */
5308 else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
5309 local_p = false;
5310 /* If PIC, then assume that any global name can be overridden by
5311 symbols resolved from other modules. */
5312 else if (shlib)
5313 local_p = false;
5314 /* Uninitialized COMMON variable may be unified with symbols
5315 resolved from other modules. */
5316 else if (DECL_COMMON (exp)
5317 && (DECL_INITIAL (exp) == NULL
5318 || DECL_INITIAL (exp) == error_mark_node))
5319 local_p = false;
5320 /* Otherwise we're left with initialized (or non-common) global data
5321 which is of necessity defined locally. */
5322 else
5323 local_p = true;
5325 return local_p;
5328 /* Determine whether or not a pointer mode is valid. Assume defaults
5329 of ptr_mode or Pmode - can be overridden. */
5330 bool
5331 default_valid_pointer_mode (mode)
5332 enum machine_mode mode;
5334 return (mode == ptr_mode || mode == Pmode);
5337 /* Default function to output code that will globalize a label. A
5338 target must define GLOBAL_ASM_OP or provide it's own function to
5339 globalize a label. */
5340 #ifdef GLOBAL_ASM_OP
5341 void
5342 default_globalize_label (stream, name)
5343 FILE * stream;
5344 const char *name;
5346 fputs (GLOBAL_ASM_OP, stream);
5347 assemble_name (stream, name);
5348 putc ('\n', stream);
5350 #endif /* GLOBAL_ASM_OP */
5352 /* This is how to output an internal numbered label where PREFIX is
5353 the class of label and LABELNO is the number within the class. */
5355 void
5356 default_internal_label (stream, prefix, labelno)
5357 FILE *stream;
5358 const char *prefix;
5359 unsigned long labelno;
5361 char *const buf = alloca (40 + strlen (prefix));
5362 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
5363 ASM_OUTPUT_LABEL (stream, buf);
5366 /* This is the default behavior at the beginning of a file. It's
5367 controlled by two other target-hook toggles. */
5368 void
5369 default_file_start ()
5371 if (targetm.file_start_app_off && !flag_verbose_asm)
5372 fputs (ASM_APP_OFF, asm_out_file);
5374 if (targetm.file_start_file_directive)
5375 output_file_directive (asm_out_file, main_input_filename);
5378 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5379 which emits a special section directive used to indicate whether or
5380 not this object file needs an executable stack. This is primarily
5381 a GNU extension to ELF but could be used on other targets. */
5382 void
5383 file_end_indicate_exec_stack ()
5385 unsigned int flags = SECTION_DEBUG;
5386 if (trampolines_created)
5387 flags |= SECTION_CODE;
5389 named_section_flags (".note.GNU-stack", flags);
5392 #include "gt-varasm.h"