1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 /* This file handles generation of all the assembler code
25 *except* the instructions of a function.
26 This includes declarations of variables and their initial values.
28 We also output the assembler code for constants stored in memory
29 and are responsible for combining constants with the same value. */
33 #include "coretypes.h"
40 #include "hard-reg-set.h"
48 #include "langhooks.h"
52 #include "tree-mudflap.h"
54 #include "cfglayout.h"
55 #include "basic-block.h"
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h" /* Needed for external data
59 declarations for e.g. AIX 4.x. */
62 /* The (assembler) name of the first globally-visible object output. */
63 extern GTY(()) const char *first_global_object_name
;
64 extern GTY(()) const char *weak_global_object_name
;
66 const char *first_global_object_name
;
67 const char *weak_global_object_name
;
70 struct constant_descriptor_rtx
;
71 struct rtx_constant_pool
;
73 struct varasm_status
GTY(())
75 /* If we're using a per-function constant pool, this is it. */
76 struct rtx_constant_pool
*pool
;
78 /* Number of tree-constants deferred during the expansion of this
80 unsigned int deferred_constants
;
83 #define n_deferred_constants (cfun->varasm->deferred_constants)
85 /* Number for making the label on the next
86 constant that is stored in memory. */
88 static GTY(()) int const_labelno
;
90 /* Carry information from ASM_DECLARE_OBJECT_NAME
91 to ASM_FINISH_DECLARE_OBJECT. */
93 int size_directive_output
;
95 /* The last decl for which assemble_variable was called,
96 if it did ASM_DECLARE_OBJECT_NAME.
97 If the last call to assemble_variable didn't do that,
100 tree last_assemble_variable_decl
;
102 /* The following global variable indicates if the first basic block
103 in a function belongs to the cold partition or not. */
105 bool first_function_block_is_cold
;
107 /* We give all constants their own alias set. Perhaps redundant with
108 MEM_READONLY_P, but pre-dates it. */
110 static HOST_WIDE_INT const_alias_set
;
112 static const char *strip_reg_name (const char *);
113 static int contains_pointers_p (tree
);
114 #ifdef ASM_OUTPUT_EXTERNAL
115 static bool incorporeal_function_p (tree
);
117 static void decode_addr_const (tree
, struct addr_const
*);
118 static hashval_t
const_desc_hash (const void *);
119 static int const_desc_eq (const void *, const void *);
120 static hashval_t
const_hash_1 (const tree
);
121 static int compare_constant (const tree
, const tree
);
122 static tree
copy_constant (tree
);
123 static void output_constant_def_contents (rtx
);
124 static void output_addressed_constants (tree
);
125 static unsigned HOST_WIDE_INT
array_size_for_constructor (tree
);
126 static unsigned min_align (unsigned, unsigned);
127 static void output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int);
128 static void globalize_decl (tree
);
129 static void maybe_assemble_visibility (tree
);
130 #ifdef BSS_SECTION_ASM_OP
131 #ifdef ASM_OUTPUT_BSS
132 static void asm_output_bss (FILE *, tree
, const char *,
133 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
135 #ifdef ASM_OUTPUT_ALIGNED_BSS
136 static void asm_output_aligned_bss (FILE *, tree
, const char *,
137 unsigned HOST_WIDE_INT
, int)
140 #endif /* BSS_SECTION_ASM_OP */
141 static bool asm_emit_uninitialised (tree
, const char*,
142 unsigned HOST_WIDE_INT
,
143 unsigned HOST_WIDE_INT
);
144 static void mark_weak (tree
);
146 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
147 section
*text_section
;
148 section
*data_section
;
149 section
*readonly_data_section
;
150 section
*sdata_section
;
151 section
*ctors_section
;
152 section
*dtors_section
;
153 section
*bss_section
;
154 section
*sbss_section
;
156 /* The section that holds the main exception table, when known. The section
157 is set either by the target's init_sections hook or by the first call to
158 switch_to_exception_section. */
159 section
*exception_section
;
161 /* The section that holds the DWARF2 frame unwind information, when known.
162 The section is set either by the target's init_sections hook or by the
163 first call to switch_to_eh_frame_section. */
164 section
*eh_frame_section
;
166 /* asm_out_file's current section. This is NULL if no section has yet
167 been selected or if we lose track of what the current section is. */
170 /* True if code for the current function is currently being directed
171 at the cold section. */
172 bool in_cold_section_p
;
174 /* A linked list of all the unnamed sections. */
175 static GTY(()) section
*unnamed_sections
;
177 /* Return a nonzero value if DECL has a section attribute. */
178 #ifndef IN_NAMED_SECTION
179 #define IN_NAMED_SECTION(DECL) \
180 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
181 && DECL_SECTION_NAME (DECL) != NULL_TREE)
184 /* Hash table of named sections. */
185 static GTY((param_is (section
))) htab_t section_htab
;
187 /* Helper routines for maintaining section_htab. */
190 section_entry_eq (const void *p1
, const void *p2
)
192 const section
*old
= p1
;
193 const char *new = p2
;
195 return strcmp (old
->named
.name
, new) == 0;
199 section_entry_hash (const void *p
)
201 const section
*old
= p
;
202 return htab_hash_string (old
->named
.name
);
205 /* Return a new unnamed section with the given fields. */
208 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
213 sect
= ggc_alloc (sizeof (struct unnamed_section
));
214 sect
->unnamed
.common
.flags
= flags
;
215 sect
->unnamed
.callback
= callback
;
216 sect
->unnamed
.data
= data
;
217 sect
->unnamed
.next
= unnamed_sections
;
219 unnamed_sections
= sect
;
223 /* Return the named section structure associated with NAME. Create
224 a new section with the given fields if no such structure exists. */
227 get_section (const char *name
, unsigned int flags
, tree decl
)
229 section
*sect
, **slot
;
232 htab_find_slot_with_hash (section_htab
, name
,
233 htab_hash_string (name
), INSERT
);
234 flags
|= SECTION_NAMED
;
237 sect
= ggc_alloc (sizeof (struct named_section
));
238 sect
->named
.common
.flags
= flags
;
239 sect
->named
.name
= ggc_strdup (name
);
240 sect
->named
.decl
= decl
;
246 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
247 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
249 /* Sanity check user variables for flag changes. */
251 decl
= sect
->named
.decl
;
253 error ("%+D causes a section type conflict", decl
);
260 initialize_cold_section_name (void)
262 const char *stripped_name
;
266 gcc_assert (cfun
&& current_function_decl
);
267 if (cfun
->unlikely_text_section_name
)
270 dsn
= DECL_SECTION_NAME (current_function_decl
);
271 if (flag_function_sections
&& dsn
)
273 name
= alloca (TREE_STRING_LENGTH (dsn
) + 1);
274 memcpy (name
, TREE_STRING_POINTER (dsn
), TREE_STRING_LENGTH (dsn
) + 1);
276 stripped_name
= targetm
.strip_name_encoding (name
);
278 buffer
= ACONCAT ((stripped_name
, "_unlikely", NULL
));
279 cfun
->unlikely_text_section_name
= ggc_strdup (buffer
);
282 cfun
->unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
285 /* Tell assembler to switch to unlikely-to-be-executed text section. */
288 unlikely_text_section (void)
292 if (!cfun
->unlikely_text_section_name
)
293 initialize_cold_section_name ();
295 return get_named_section (NULL
, cfun
->unlikely_text_section_name
, 0);
298 return get_named_section (NULL
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
, 0);
301 /* When called within a function context, return true if the function
302 has been assigned a cold text section and if SECT is that section.
303 When called outside a function context, return true if SECT is the
304 default cold section. */
307 unlikely_text_section_p (section
*sect
)
312 name
= cfun
->unlikely_text_section_name
;
314 name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
318 && (sect
->common
.flags
& SECTION_NAMED
) != 0
319 && strcmp (name
, sect
->named
.name
) == 0);
322 /* Return a section with a particular name and with whatever SECTION_*
323 flags section_type_flags deems appropriate. The name of the section
324 is taken from NAME if nonnull, otherwise it is taken from DECL's
325 DECL_SECTION_NAME. DECL is the decl associated with the section
326 (see the section comment for details) and RELOC is as for
327 section_type_flags. */
330 get_named_section (tree decl
, const char *name
, int reloc
)
334 gcc_assert (!decl
|| DECL_P (decl
));
336 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
338 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
340 return get_section (name
, flags
, decl
);
343 /* If required, set DECL_SECTION_NAME to a unique name. */
346 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
347 int flag_function_or_data_sections
)
349 if (DECL_SECTION_NAME (decl
) == NULL_TREE
350 && targetm
.have_named_sections
351 && (flag_function_or_data_sections
352 || DECL_ONE_ONLY (decl
)))
353 targetm
.asm_out
.unique_section (decl
, reloc
);
356 #ifdef BSS_SECTION_ASM_OP
358 #ifdef ASM_OUTPUT_BSS
360 /* Utility function for ASM_OUTPUT_BSS for targets to use if
361 they don't support alignments in .bss.
362 ??? It is believed that this function will work in most cases so such
363 support is localized here. */
366 asm_output_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
368 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
369 unsigned HOST_WIDE_INT rounded
)
371 targetm
.asm_out
.globalize_label (file
, name
);
372 switch_to_section (bss_section
);
373 #ifdef ASM_DECLARE_OBJECT_NAME
374 last_assemble_variable_decl
= decl
;
375 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
377 /* Standard thing is just output label for the object. */
378 ASM_OUTPUT_LABEL (file
, name
);
379 #endif /* ASM_DECLARE_OBJECT_NAME */
380 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
385 #ifdef ASM_OUTPUT_ALIGNED_BSS
387 /* Utility function for targets to use in implementing
388 ASM_OUTPUT_ALIGNED_BSS.
389 ??? It is believed that this function will work in most cases so such
390 support is localized here. */
393 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
394 const char *name
, unsigned HOST_WIDE_INT size
,
397 switch_to_section (bss_section
);
398 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
399 #ifdef ASM_DECLARE_OBJECT_NAME
400 last_assemble_variable_decl
= decl
;
401 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
403 /* Standard thing is just output label for the object. */
404 ASM_OUTPUT_LABEL (file
, name
);
405 #endif /* ASM_DECLARE_OBJECT_NAME */
406 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
411 #endif /* BSS_SECTION_ASM_OP */
413 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
414 /* Return the hot section for function DECL. Return text_section for
418 hot_function_section (tree decl
)
420 if (decl
!= NULL_TREE
421 && DECL_SECTION_NAME (decl
) != NULL_TREE
422 && targetm
.have_named_sections
)
423 return get_named_section (decl
, NULL
, 0);
429 /* Return the section for function DECL.
431 If DECL is NULL_TREE, return the text section. We can be passed
432 NULL_TREE under some circumstances by dbxout.c at least. */
435 function_section (tree decl
)
439 if (first_function_block_is_cold
)
442 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
443 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
445 return hot_function_section (decl
);
450 current_function_section (void)
452 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
453 return targetm
.asm_out
.select_section (current_function_decl
,
455 DECL_ALIGN (current_function_decl
));
457 return (in_cold_section_p
458 ? unlikely_text_section ()
459 : hot_function_section (current_function_decl
));
463 /* Return the read-only data section associated with function DECL. */
466 default_function_rodata_section (tree decl
)
468 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
470 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
472 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
474 size_t len
= strlen (name
) + 3;
475 char* rname
= alloca (len
);
477 strcpy (rname
, ".rodata");
478 strcat (rname
, name
+ 5);
479 return get_section (rname
, SECTION_LINKONCE
, decl
);
481 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
482 else if (DECL_ONE_ONLY (decl
)
483 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
485 size_t len
= strlen (name
) + 1;
486 char *rname
= alloca (len
);
488 memcpy (rname
, name
, len
);
490 return get_section (rname
, SECTION_LINKONCE
, decl
);
492 /* For .text.foo we want to use .rodata.foo. */
493 else if (flag_function_sections
&& flag_data_sections
494 && strncmp (name
, ".text.", 6) == 0)
496 size_t len
= strlen (name
) + 1;
497 char *rname
= alloca (len
+ 2);
499 memcpy (rname
, ".rodata", 7);
500 memcpy (rname
+ 7, name
+ 5, len
- 5);
501 return get_section (rname
, 0, decl
);
505 return readonly_data_section
;
508 /* Return the read-only data section associated with function DECL
509 for targets where that section should be always the single
510 readonly data section. */
513 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
515 return readonly_data_section
;
518 /* Switch to section for variable DECL. RELOC is the same as the
519 argument to SELECT_SECTION. */
522 variable_section (tree decl
, int reloc
)
524 if (IN_NAMED_SECTION (decl
))
525 switch_to_section (get_named_section (decl
, NULL
, reloc
));
527 switch_to_section (targetm
.asm_out
.select_section (decl
, reloc
,
531 /* Return the section to use for string merging. */
534 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
535 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
536 unsigned int flags ATTRIBUTE_UNUSED
)
538 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
539 && TREE_CODE (decl
) == STRING_CST
540 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
542 && TREE_STRING_LENGTH (decl
) >= int_size_in_bytes (TREE_TYPE (decl
)))
544 enum machine_mode mode
;
545 unsigned int modesize
;
550 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
551 modesize
= GET_MODE_BITSIZE (mode
);
552 if (modesize
>= 8 && modesize
<= 256
553 && (modesize
& (modesize
- 1)) == 0)
555 if (align
< modesize
)
558 str
= TREE_STRING_POINTER (decl
);
559 len
= TREE_STRING_LENGTH (decl
);
560 unit
= GET_MODE_SIZE (mode
);
562 /* Check for embedded NUL characters. */
563 for (i
= 0; i
< len
; i
+= unit
)
565 for (j
= 0; j
< unit
; j
++)
566 if (str
[i
+ j
] != '\0')
573 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
575 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
576 return get_section (name
, flags
, NULL
);
581 return readonly_data_section
;
584 /* Return the section to use for constant merging. */
587 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
588 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
589 unsigned int flags ATTRIBUTE_UNUSED
)
591 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
593 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
599 && (align
& (align
- 1)) == 0)
603 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
604 flags
|= (align
/ 8) | SECTION_MERGE
;
605 return get_section (name
, flags
, NULL
);
607 return readonly_data_section
;
610 /* Given NAME, a putative register name, discard any customary prefixes. */
613 strip_reg_name (const char *name
)
615 #ifdef REGISTER_PREFIX
616 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
617 name
+= strlen (REGISTER_PREFIX
);
619 if (name
[0] == '%' || name
[0] == '#')
624 /* The user has asked for a DECL to have a particular name. Set (or
625 change) it in such a way that we don't prefix an underscore to
628 set_user_assembler_name (tree decl
, const char *name
)
630 char *starred
= alloca (strlen (name
) + 2);
632 strcpy (starred
+ 1, name
);
633 change_decl_assembler_name (decl
, get_identifier (starred
));
634 SET_DECL_RTL (decl
, NULL_RTX
);
637 /* Decode an `asm' spec for a declaration as a register name.
638 Return the register number, or -1 if nothing specified,
639 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
640 or -3 if ASMSPEC is `cc' and is not recognized,
641 or -4 if ASMSPEC is `memory' and is not recognized.
642 Accept an exact spelling or a decimal number.
643 Prefixes such as % are optional. */
646 decode_reg_name (const char *asmspec
)
652 /* Get rid of confusing prefixes. */
653 asmspec
= strip_reg_name (asmspec
);
655 /* Allow a decimal number as a "register name". */
656 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
657 if (! ISDIGIT (asmspec
[i
]))
659 if (asmspec
[0] != 0 && i
< 0)
662 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
668 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
670 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
673 #ifdef ADDITIONAL_REGISTER_NAMES
675 static const struct { const char *const name
; const int number
; } table
[]
676 = ADDITIONAL_REGISTER_NAMES
;
678 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
680 && ! strcmp (asmspec
, table
[i
].name
))
681 return table
[i
].number
;
683 #endif /* ADDITIONAL_REGISTER_NAMES */
685 if (!strcmp (asmspec
, "memory"))
688 if (!strcmp (asmspec
, "cc"))
697 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
698 have static storage duration. In other words, it should not be an
699 automatic variable, including PARM_DECLs.
701 There is, however, one exception: this function handles variables
702 explicitly placed in a particular register by the user.
704 This is never called for PARM_DECL nodes. */
707 make_decl_rtl (tree decl
)
709 const char *name
= 0;
713 /* Check that we are not being given an automatic variable. */
714 gcc_assert (TREE_CODE (decl
) != PARM_DECL
715 && TREE_CODE (decl
) != RESULT_DECL
);
717 /* A weak alias has TREE_PUBLIC set but not the other bits. */
718 gcc_assert (TREE_CODE (decl
) != VAR_DECL
719 || TREE_STATIC (decl
)
720 || TREE_PUBLIC (decl
)
721 || DECL_EXTERNAL (decl
)
722 || DECL_REGISTER (decl
));
724 /* And that we were not given a type or a label. */
725 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
726 && TREE_CODE (decl
) != LABEL_DECL
);
728 /* For a duplicate declaration, we can be called twice on the
729 same DECL node. Don't discard the RTL already made. */
730 if (DECL_RTL_SET_P (decl
))
732 /* If the old RTL had the wrong mode, fix the mode. */
733 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
734 SET_DECL_RTL (decl
, adjust_address_nv (DECL_RTL (decl
),
735 DECL_MODE (decl
), 0));
737 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
740 /* ??? Another way to do this would be to maintain a hashed
741 table of such critters. Instead of adding stuff to a DECL
742 to give certain attributes to it, we could use an external
743 hash map from DECL to set of attributes. */
745 /* Let the target reassign the RTL if it wants.
746 This is necessary, for example, when one machine specific
747 decl attribute overrides another. */
748 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
750 /* Make this function static known to the mudflap runtime. */
751 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
752 mudflap_enqueue_decl (decl
);
757 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
759 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
760 && DECL_REGISTER (decl
))
762 error ("register name not specified for %q+D", decl
);
764 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
766 const char *asmspec
= name
+1;
767 reg_number
= decode_reg_name (asmspec
);
768 /* First detect errors in declaring global registers. */
769 if (reg_number
== -1)
770 error ("register name not specified for %q+D", decl
);
771 else if (reg_number
< 0)
772 error ("invalid register name for %q+D", decl
);
773 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
774 error ("data type of %q+D isn%'t suitable for a register",
776 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
777 error ("register specified for %q+D isn%'t suitable for data type",
779 /* Now handle properly declared static register variables. */
784 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
786 DECL_INITIAL (decl
) = 0;
787 error ("global register variable has initial value");
789 if (TREE_THIS_VOLATILE (decl
))
790 warning (OPT_Wvolatile_register_var
,
791 "optimization may eliminate reads and/or "
792 "writes to register variables");
794 /* If the user specified one of the eliminables registers here,
795 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
796 confused with that register and be eliminated. This usage is
797 somewhat suspect... */
799 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
800 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
801 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
803 if (TREE_STATIC (decl
))
805 /* Make this register global, so not usable for anything
807 #ifdef ASM_DECLARE_REGISTER_GLOBAL
808 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
809 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
811 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
813 globalize_reg (reg_number
+ --nregs
);
816 /* As a register variable, it has no section. */
820 /* Now handle ordinary static variables and functions (in memory).
821 Also handle vars declared register invalidly. */
822 else if (name
[0] == '*')
824 #ifdef REGISTER_PREFIX
825 if (strlen (REGISTER_PREFIX
) != 0)
827 reg_number
= decode_reg_name (name
);
828 if (reg_number
>= 0 || reg_number
== -3)
829 error ("register name given for non-register variable %q+D", decl
);
834 /* Specifying a section attribute on a variable forces it into a
835 non-.bss section, and thus it cannot be common. */
836 if (TREE_CODE (decl
) == VAR_DECL
837 && DECL_SECTION_NAME (decl
) != NULL_TREE
838 && DECL_INITIAL (decl
) == NULL_TREE
839 && DECL_COMMON (decl
))
840 DECL_COMMON (decl
) = 0;
842 /* Variables can't be both common and weak. */
843 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
844 DECL_COMMON (decl
) = 0;
846 x
= gen_rtx_SYMBOL_REF (Pmode
, name
);
847 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
848 SYMBOL_REF_DECL (x
) = decl
;
850 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
851 if (TREE_CODE (decl
) != FUNCTION_DECL
)
852 set_mem_attributes (x
, decl
, 1);
853 SET_DECL_RTL (decl
, x
);
855 /* Optionally set flags or add text to the name to record information
856 such as that it is a function name.
857 If the name is changed, the macro ASM_OUTPUT_LABELREF
858 will have to know how to strip this information. */
859 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
861 /* Make this function static known to the mudflap runtime. */
862 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
863 mudflap_enqueue_decl (decl
);
866 /* Make the rtl for variable VAR be volatile.
867 Use this only for static variables. */
870 make_var_volatile (tree var
)
872 gcc_assert (MEM_P (DECL_RTL (var
)));
874 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
877 /* Output a string of literal assembler code
878 for an `asm' keyword used between functions. */
881 assemble_asm (tree string
)
885 if (TREE_CODE (string
) == ADDR_EXPR
)
886 string
= TREE_OPERAND (string
, 0);
888 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
891 /* Record an element in the table of global destructors. SYMBOL is
892 a SYMBOL_REF of the function to be called; PRIORITY is a number
893 between 0 and MAX_INIT_PRIORITY. */
896 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
897 int priority ATTRIBUTE_UNUSED
)
899 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
900 /* Tell GNU LD that this is part of the static destructor set.
901 This will work for any system that uses stabs, most usefully
903 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
904 dbxout_stab_value_label (XSTR (symbol
, 0));
906 sorry ("global destructors not supported on this target");
911 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
913 const char *section
= ".dtors";
916 /* ??? This only works reliably with the GNU linker. */
917 if (priority
!= DEFAULT_INIT_PRIORITY
)
919 sprintf (buf
, ".dtors.%.5u",
920 /* Invert the numbering so the linker puts us in the proper
921 order; constructors are run from right to left, and the
922 linker sorts in increasing order. */
923 MAX_INIT_PRIORITY
- priority
);
927 switch_to_section (get_section (section
, SECTION_WRITE
, NULL
));
928 assemble_align (POINTER_SIZE
);
929 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
932 #ifdef DTORS_SECTION_ASM_OP
934 default_dtor_section_asm_out_destructor (rtx symbol
,
935 int priority ATTRIBUTE_UNUSED
)
937 switch_to_section (dtors_section
);
938 assemble_align (POINTER_SIZE
);
939 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
943 /* Likewise for global constructors. */
946 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
947 int priority ATTRIBUTE_UNUSED
)
949 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
950 /* Tell GNU LD that this is part of the static destructor set.
951 This will work for any system that uses stabs, most usefully
953 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
954 dbxout_stab_value_label (XSTR (symbol
, 0));
956 sorry ("global constructors not supported on this target");
961 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
963 const char *section
= ".ctors";
966 /* ??? This only works reliably with the GNU linker. */
967 if (priority
!= DEFAULT_INIT_PRIORITY
)
969 sprintf (buf
, ".ctors.%.5u",
970 /* Invert the numbering so the linker puts us in the proper
971 order; constructors are run from right to left, and the
972 linker sorts in increasing order. */
973 MAX_INIT_PRIORITY
- priority
);
977 switch_to_section (get_section (section
, SECTION_WRITE
, NULL
));
978 assemble_align (POINTER_SIZE
);
979 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
982 #ifdef CTORS_SECTION_ASM_OP
984 default_ctor_section_asm_out_constructor (rtx symbol
,
985 int priority ATTRIBUTE_UNUSED
)
987 switch_to_section (ctors_section
);
988 assemble_align (POINTER_SIZE
);
989 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
993 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
994 a nonzero value if the constant pool should be output before the
995 start of the function, or a zero value if the pool should output
996 after the end of the function. The default is to put it before the
999 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1000 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1003 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1004 to be output to assembler.
1005 Set first_global_object_name and weak_global_object_name as appropriate. */
1008 notice_global_symbol (tree decl
)
1010 const char **type
= &first_global_object_name
;
1012 if (first_global_object_name
1013 || !TREE_PUBLIC (decl
) || DECL_EXTERNAL (decl
)
1014 || !DECL_NAME (decl
)
1015 || (TREE_CODE (decl
) != FUNCTION_DECL
1016 && (TREE_CODE (decl
) != VAR_DECL
1017 || (DECL_COMMON (decl
)
1018 && (DECL_INITIAL (decl
) == 0
1019 || DECL_INITIAL (decl
) == error_mark_node
))))
1020 || !MEM_P (DECL_RTL (decl
)))
1023 /* We win when global object is found, but it is useful to know about weak
1024 symbol as well so we can produce nicer unique names. */
1025 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
))
1026 type
= &weak_global_object_name
;
1032 rtx decl_rtl
= DECL_RTL (decl
);
1034 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1035 name
= ggc_strdup (p
);
1041 /* Output assembler code for the constant pool of a function and associated
1042 with defining the name of the function. DECL describes the function.
1043 NAME is the function's name. For the constant pool, we use the current
1044 constant pool data. */
1047 assemble_start_function (tree decl
, const char *fnname
)
1050 char tmp_label
[100];
1051 bool hot_label_written
= false;
1053 cfun
->unlikely_text_section_name
= NULL
;
1055 first_function_block_is_cold
= false;
1056 if (flag_reorder_blocks_and_partition
)
1058 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1059 cfun
->hot_section_label
= ggc_strdup (tmp_label
);
1060 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1061 cfun
->cold_section_label
= ggc_strdup (tmp_label
);
1062 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1063 cfun
->hot_section_end_label
= ggc_strdup (tmp_label
);
1064 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1065 cfun
->cold_section_end_label
= ggc_strdup (tmp_label
);
1070 cfun
->hot_section_label
= NULL
;
1071 cfun
->cold_section_label
= NULL
;
1072 cfun
->hot_section_end_label
= NULL
;
1073 cfun
->cold_section_end_label
= NULL
;
1076 /* The following code does not need preprocessing in the assembler. */
1080 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1081 output_constant_pool (fnname
, decl
);
1083 resolve_unique_section (decl
, 0, flag_function_sections
);
1085 /* Make sure the not and cold text (code) sections are properly
1086 aligned. This is necessary here in the case where the function
1087 has both hot and cold sections, because we don't want to re-set
1088 the alignment when the section switch happens mid-function. */
1090 if (flag_reorder_blocks_and_partition
)
1092 switch_to_section (unlikely_text_section ());
1093 assemble_align (FUNCTION_BOUNDARY
);
1094 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->cold_section_label
);
1096 /* When the function starts with a cold section, we need to explicitly
1097 align the hot section and write out the hot section label.
1098 But if the current function is a thunk, we do not have a CFG. */
1099 if (!current_function_is_thunk
1100 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1102 switch_to_section (text_section
);
1103 assemble_align (FUNCTION_BOUNDARY
);
1104 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->hot_section_label
);
1105 hot_label_written
= true;
1106 first_function_block_is_cold
= true;
1109 else if (DECL_SECTION_NAME (decl
))
1111 /* Calls to function_section rely on first_function_block_is_cold
1112 being accurate. The first block may be cold even if we aren't
1113 doing partitioning, if the entire function was decided by
1114 choose_function_section (predict.c) to be cold. */
1116 initialize_cold_section_name ();
1118 if (cfun
->unlikely_text_section_name
1119 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
1120 cfun
->unlikely_text_section_name
) == 0)
1121 first_function_block_is_cold
= true;
1124 in_cold_section_p
= first_function_block_is_cold
;
1126 /* Switch to the correct text section for the start of the function. */
1128 switch_to_section (function_section (decl
));
1129 if (flag_reorder_blocks_and_partition
1130 && !hot_label_written
)
1131 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->hot_section_label
);
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
;
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);
1152 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1156 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1157 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1160 (*debug_hooks
->begin_function
) (decl
);
1162 /* Make function name accessible from other files, if appropriate. */
1164 if (TREE_PUBLIC (decl
))
1166 notice_global_symbol (decl
);
1168 globalize_decl (decl
);
1170 maybe_assemble_visibility (decl
);
1173 if (DECL_PRESERVE_P (decl
))
1174 targetm
.asm_out
.mark_decl_preserved (fnname
);
1176 /* Do any machine/system dependent processing of the function name. */
1177 #ifdef ASM_DECLARE_FUNCTION_NAME
1178 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1180 /* Standard thing is just output label for the function. */
1181 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1182 #endif /* ASM_DECLARE_FUNCTION_NAME */
1185 /* Output assembler code associated with defining the size of the
1186 function. DECL describes the function. NAME is the function's name. */
1189 assemble_end_function (tree decl
, const char *fnname
)
1191 #ifdef ASM_DECLARE_FUNCTION_SIZE
1192 /* We could have switched section in the middle of the function. */
1193 if (flag_reorder_blocks_and_partition
)
1194 switch_to_section (function_section (decl
));
1195 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1197 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1199 output_constant_pool (fnname
, decl
);
1200 switch_to_section (function_section (decl
)); /* need to switch back */
1202 /* Output labels for end of hot/cold text sections (to be used by
1204 if (flag_reorder_blocks_and_partition
)
1206 section
*save_text_section
;
1208 save_text_section
= in_section
;
1209 switch_to_section (unlikely_text_section ());
1210 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->cold_section_end_label
);
1211 if (first_function_block_is_cold
)
1212 switch_to_section (text_section
);
1214 switch_to_section (function_section (decl
));
1215 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->hot_section_end_label
);
1216 switch_to_section (save_text_section
);
1220 /* Assemble code to leave SIZE bytes of zeros. */
1223 assemble_zeros (unsigned HOST_WIDE_INT size
)
1225 /* Do no output if -fsyntax-only. */
1226 if (flag_syntax_only
)
1229 #ifdef ASM_NO_SKIP_IN_TEXT
1230 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1231 so we must output 0s explicitly in the text section. */
1232 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1234 unsigned HOST_WIDE_INT i
;
1235 for (i
= 0; i
< size
; i
++)
1236 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1241 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1244 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1247 assemble_align (int align
)
1249 if (align
> BITS_PER_UNIT
)
1251 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1255 /* Assemble a string constant with the specified C string as contents. */
1258 assemble_string (const char *p
, int size
)
1263 /* If the string is very long, split it up. */
1267 int thissize
= size
- pos
;
1268 if (thissize
> maximum
)
1271 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1279 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1280 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1281 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1283 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1284 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1285 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1287 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1288 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1292 #if defined ASM_OUTPUT_ALIGNED_BSS
1293 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1294 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1296 #if defined ASM_OUTPUT_BSS
1297 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1298 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1304 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1305 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1306 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1308 #if defined ASM_OUTPUT_ALIGNED_COMMON
1309 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1310 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1312 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1313 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1318 asm_emit_uninitialised (tree decl
, const char *name
,
1319 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1320 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1328 destination
= asm_dest_local
;
1330 /* ??? We should handle .bss via select_section mechanisms rather than
1331 via special target hooks. That would eliminate this special case. */
1332 if (TREE_PUBLIC (decl
))
1334 if (!DECL_COMMON (decl
))
1336 destination
= asm_dest_bss
;
1341 destination
= asm_dest_common
;
1344 if (destination
!= asm_dest_common
)
1346 resolve_unique_section (decl
, 0, flag_data_sections
);
1347 /* Custom sections don't belong here. */
1348 if (DECL_SECTION_NAME (decl
))
1352 if (destination
== asm_dest_bss
)
1353 globalize_decl (decl
);
1355 if (flag_shared_data
)
1357 switch (destination
)
1359 #ifdef ASM_OUTPUT_SHARED_BSS
1361 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1364 #ifdef ASM_OUTPUT_SHARED_COMMON
1365 case asm_dest_common
:
1366 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1369 #ifdef ASM_OUTPUT_SHARED_LOCAL
1370 case asm_dest_local
:
1371 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1379 switch (destination
)
1383 ASM_EMIT_BSS (decl
, name
, size
, rounded
);
1386 case asm_dest_common
:
1387 ASM_EMIT_COMMON (decl
, name
, size
, rounded
);
1389 case asm_dest_local
:
1390 ASM_EMIT_LOCAL (decl
, name
, size
, rounded
);
1399 /* Assemble everything that is needed for a variable or function declaration.
1400 Not used for automatic variables, and not used for function definitions.
1401 Should not be called for variables of incomplete structure type.
1403 TOP_LEVEL is nonzero if this variable has file scope.
1404 AT_END is nonzero if this is the special handling, at end of compilation,
1405 to define things that have had only tentative definitions.
1406 DONT_OUTPUT_DATA if nonzero means don't actually output the
1407 initial value (that will be done by the caller). */
1410 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
1411 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
1418 if (lang_hooks
.decls
.prepare_assemble_variable
)
1419 lang_hooks
.decls
.prepare_assemble_variable (decl
);
1421 last_assemble_variable_decl
= 0;
1423 /* Normally no need to say anything here for external references,
1424 since assemble_external is called by the language-specific code
1425 when a declaration is first seen. */
1427 if (DECL_EXTERNAL (decl
))
1430 /* Output no assembler code for a function declaration.
1431 Only definitions of functions output anything. */
1433 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1436 /* Do nothing for global register variables. */
1437 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
1439 TREE_ASM_WRITTEN (decl
) = 1;
1443 /* If type was incomplete when the variable was declared,
1444 see if it is complete now. */
1446 if (DECL_SIZE (decl
) == 0)
1447 layout_decl (decl
, 0);
1449 /* Still incomplete => don't allocate it; treat the tentative defn
1450 (which is what it must have been) as an `extern' reference. */
1452 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1454 error ("storage size of %q+D isn%'t known", decl
);
1455 TREE_ASM_WRITTEN (decl
) = 1;
1459 /* The first declaration of a variable that comes through this function
1460 decides whether it is global (in C, has external linkage)
1461 or local (in C, has internal linkage). So do nothing more
1462 if this function has already run. */
1464 if (TREE_ASM_WRITTEN (decl
))
1467 /* Make sure targetm.encode_section_info is invoked before we set
1469 decl_rtl
= DECL_RTL (decl
);
1471 TREE_ASM_WRITTEN (decl
) = 1;
1473 /* Do no output if -fsyntax-only. */
1474 if (flag_syntax_only
)
1479 if (! dont_output_data
1480 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1482 error ("size of variable %q+D is too large", decl
);
1486 name
= XSTR (XEXP (decl_rtl
, 0), 0);
1487 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1488 notice_global_symbol (decl
);
1490 /* Compute the alignment of this data. */
1492 align
= DECL_ALIGN (decl
);
1494 /* In the case for initialing an array whose length isn't specified,
1495 where we have not yet been able to do the layout,
1496 figure out the proper alignment now. */
1497 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1498 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1499 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1501 /* Some object file formats have a maximum alignment which they support.
1502 In particular, a.out format supports a maximum alignment of 4. */
1503 if (align
> MAX_OFILE_ALIGNMENT
)
1505 warning (0, "alignment of %q+D is greater than maximum object "
1506 "file alignment. Using %d", decl
,
1507 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1508 align
= MAX_OFILE_ALIGNMENT
;
1511 /* On some machines, it is good to increase alignment sometimes. */
1512 if (! DECL_USER_ALIGN (decl
))
1514 #ifdef DATA_ALIGNMENT
1515 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1517 #ifdef CONSTANT_ALIGNMENT
1518 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1519 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1523 /* Reset the alignment in case we have made it tighter, so we can benefit
1524 from it in get_pointer_alignment. */
1525 DECL_ALIGN (decl
) = align
;
1526 set_mem_align (decl_rtl
, align
);
1528 if (TREE_PUBLIC (decl
))
1529 maybe_assemble_visibility (decl
);
1531 if (DECL_PRESERVE_P (decl
))
1532 targetm
.asm_out
.mark_decl_preserved (name
);
1534 /* Handle uninitialized definitions. */
1536 /* If the decl has been given an explicit section name, then it
1537 isn't common, and shouldn't be handled as such. */
1538 if (DECL_SECTION_NAME (decl
) || dont_output_data
)
1540 else if (DECL_THREAD_LOCAL_P (decl
))
1542 if (DECL_COMMON (decl
))
1544 #ifdef ASM_OUTPUT_TLS_COMMON
1545 unsigned HOST_WIDE_INT size
;
1547 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1548 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1551 sorry ("thread-local COMMON data not implemented");
1555 else if (DECL_INITIAL (decl
) == 0
1556 || DECL_INITIAL (decl
) == error_mark_node
1557 || (flag_zero_initialized_in_bss
1558 /* Leave constant zeroes in .rodata so they can be shared. */
1559 && !TREE_READONLY (decl
)
1560 && initializer_zerop (DECL_INITIAL (decl
))))
1562 unsigned HOST_WIDE_INT size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1563 unsigned HOST_WIDE_INT rounded
= size
;
1565 /* Don't allocate zero bytes of common,
1566 since that means "undefined external" in the linker. */
1570 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1571 so that each uninitialized object starts on such a boundary. */
1572 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1573 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1574 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1576 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1577 if ((unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
1578 warning (0, "requested alignment for %q+D is greater than "
1579 "implemented alignment of %wu", decl
, rounded
);
1582 /* If the target cannot output uninitialized but not common global data
1583 in .bss, then we have to use .data, so fall through. */
1584 if (asm_emit_uninitialised (decl
, name
, size
, rounded
))
1588 /* Handle initialized definitions.
1589 Also handle uninitialized global definitions if -fno-common and the
1590 target doesn't support ASM_OUTPUT_BSS. */
1592 /* First make the assembler name(s) global if appropriate. */
1593 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1594 globalize_decl (decl
);
1596 /* Output any data that we will need to use the address of. */
1597 if (DECL_INITIAL (decl
) == error_mark_node
)
1598 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1599 else if (DECL_INITIAL (decl
))
1601 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1602 output_addressed_constants (DECL_INITIAL (decl
));
1605 /* Switch to the appropriate section. */
1606 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1607 variable_section (decl
, reloc
);
1609 /* dbxout.c needs to know this. */
1610 if (in_section
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1611 DECL_IN_TEXT_SECTION (decl
) = 1;
1613 /* Output the alignment of this data. */
1614 if (align
> BITS_PER_UNIT
)
1615 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
1617 /* Do any machine/system dependent processing of the object. */
1618 #ifdef ASM_DECLARE_OBJECT_NAME
1619 last_assemble_variable_decl
= decl
;
1620 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1622 /* Standard thing is just output label for the object. */
1623 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1624 #endif /* ASM_DECLARE_OBJECT_NAME */
1626 if (!dont_output_data
)
1628 if (DECL_INITIAL (decl
)
1629 && DECL_INITIAL (decl
) != error_mark_node
1630 && !initializer_zerop (DECL_INITIAL (decl
)))
1631 /* Output the actual data. */
1632 output_constant (DECL_INITIAL (decl
),
1633 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1636 /* Leave space for it. */
1637 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1641 /* Return 1 if type TYPE contains any pointers. */
1644 contains_pointers_p (tree type
)
1646 switch (TREE_CODE (type
))
1649 case REFERENCE_TYPE
:
1650 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1651 so I'll play safe and return 1. */
1657 case QUAL_UNION_TYPE
:
1660 /* For a type that has fields, see if the fields have pointers. */
1661 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1662 if (TREE_CODE (fields
) == FIELD_DECL
1663 && contains_pointers_p (TREE_TYPE (fields
)))
1669 /* An array type contains pointers if its element type does. */
1670 return contains_pointers_p (TREE_TYPE (type
));
1677 /* In unit-at-a-time mode, we delay assemble_external processing until
1678 the compilation unit is finalized. This is the best we can do for
1679 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
1680 it all the way to final. See PR 17982 for further discussion. */
1681 static GTY(()) tree pending_assemble_externals
;
1683 #ifdef ASM_OUTPUT_EXTERNAL
1684 /* True if DECL is a function decl for which no out-of-line copy exists.
1685 It is assumed that DECL's assembler name has been set. */
1688 incorporeal_function_p (tree decl
)
1690 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
1694 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
1695 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
1698 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1699 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
1705 /* Actually do the tests to determine if this is necessary, and invoke
1706 ASM_OUTPUT_EXTERNAL. */
1708 assemble_external_real (tree decl
)
1710 rtx rtl
= DECL_RTL (decl
);
1712 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1713 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
1714 && !incorporeal_function_p (decl
))
1716 /* Some systems do require some output. */
1717 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1718 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1724 process_pending_assemble_externals (void)
1726 #ifdef ASM_OUTPUT_EXTERNAL
1728 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
1729 assemble_external_real (TREE_VALUE (list
));
1731 pending_assemble_externals
= 0;
1735 /* Output something to declare an external symbol to the assembler.
1736 (Most assemblers don't need this, so we normally output nothing.)
1737 Do nothing if DECL is not external. */
1740 assemble_external (tree decl ATTRIBUTE_UNUSED
)
1742 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1743 main body of this code is only rarely exercised. To provide some
1744 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1745 open. If it's not, we should not be calling this function. */
1746 gcc_assert (asm_out_file
);
1748 #ifdef ASM_OUTPUT_EXTERNAL
1749 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
1752 if (flag_unit_at_a_time
)
1753 pending_assemble_externals
= tree_cons (0, decl
,
1754 pending_assemble_externals
);
1756 assemble_external_real (decl
);
1760 /* Similar, for calling a library function FUN. */
1763 assemble_external_libcall (rtx fun
)
1765 /* Declare library function name external when first used, if nec. */
1766 if (! SYMBOL_REF_USED (fun
))
1768 SYMBOL_REF_USED (fun
) = 1;
1769 targetm
.asm_out
.external_libcall (fun
);
1773 /* Assemble a label named NAME. */
1776 assemble_label (const char *name
)
1778 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1781 /* Set the symbol_referenced flag for ID. */
1783 mark_referenced (tree id
)
1785 TREE_SYMBOL_REFERENCED (id
) = 1;
1788 /* Set the symbol_referenced flag for DECL and notify callgraph. */
1790 mark_decl_referenced (tree decl
)
1792 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1794 /* Extern inline functions don't become needed when referenced.
1795 If we know a method will be emitted in other TU and no new
1796 functions can be marked reachable, just use the external
1798 struct cgraph_node
*node
= cgraph_node (decl
);
1799 if (!DECL_EXTERNAL (decl
)
1800 && (!node
->local
.vtable_method
|| !cgraph_global_info_ready
1801 || !node
->local
.finalized
))
1802 cgraph_mark_needed_node (node
);
1804 else if (TREE_CODE (decl
) == VAR_DECL
)
1806 struct cgraph_varpool_node
*node
= cgraph_varpool_node (decl
);
1807 cgraph_varpool_mark_needed_node (node
);
1808 /* C++ frontend use mark_decl_references to force COMDAT variables
1809 to be output that might appear dead otherwise. */
1810 node
->force_output
= true;
1812 /* else do nothing - we can get various sorts of CST nodes here,
1813 which do not need to be marked. */
1817 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1818 until we find an identifier that is not itself a transparent alias.
1819 Modify the alias passed to it by reference (and all aliases on the
1820 way to the ultimate target), such that they do not have to be
1821 followed again, and return the ultimate target of the alias
1825 ultimate_transparent_alias_target (tree
*alias
)
1827 tree target
= *alias
;
1829 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
1831 gcc_assert (TREE_CHAIN (target
));
1832 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
1833 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
1834 && ! TREE_CHAIN (target
));
1841 /* Output to FILE (an assembly file) a reference to NAME. If NAME
1842 starts with a *, the rest of NAME is output verbatim. Otherwise
1843 NAME is transformed in a target-specific way (usually by the
1844 addition of an underscore). */
1847 assemble_name_raw (FILE *file
, const char *name
)
1850 fputs (&name
[1], file
);
1852 ASM_OUTPUT_LABELREF (file
, name
);
1855 /* Like assemble_name_raw, but should be used when NAME might refer to
1856 an entity that is also represented as a tree (like a function or
1857 variable). If NAME does refer to such an entity, that entity will
1858 be marked as referenced. */
1861 assemble_name (FILE *file
, const char *name
)
1863 const char *real_name
;
1866 real_name
= targetm
.strip_name_encoding (name
);
1868 id
= maybe_get_identifier (real_name
);
1873 mark_referenced (id
);
1874 ultimate_transparent_alias_target (&id
);
1876 name
= IDENTIFIER_POINTER (id
);
1877 gcc_assert (! TREE_CHAIN (id
));
1880 assemble_name_raw (file
, name
);
1883 /* Allocate SIZE bytes writable static space with a gensym name
1884 and return an RTX to refer to its address. */
1887 assemble_static_space (unsigned HOST_WIDE_INT size
)
1890 const char *namestring
;
1894 if (flag_shared_data
)
1895 switch_to_section (data_section
);
1898 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1900 namestring
= ggc_strdup (name
);
1902 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1903 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
1905 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1906 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1909 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1910 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1913 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1914 so that each uninitialized object starts on such a boundary. */
1915 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1916 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1917 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1918 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1919 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1920 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1927 /* Assemble the static constant template for function entry trampolines.
1928 This is done at most once per compilation.
1929 Returns an RTX for the address of the template. */
1931 static GTY(()) rtx initial_trampoline
;
1933 #ifdef TRAMPOLINE_TEMPLATE
1935 assemble_trampoline_template (void)
1942 if (initial_trampoline
)
1943 return initial_trampoline
;
1945 /* By default, put trampoline templates in read-only data section. */
1947 #ifdef TRAMPOLINE_SECTION
1948 switch_to_section (TRAMPOLINE_SECTION
);
1950 switch_to_section (readonly_data_section
);
1953 /* Write the assembler code to define one. */
1954 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1957 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1960 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
1961 TRAMPOLINE_TEMPLATE (asm_out_file
);
1963 /* Record the rtl to refer to it. */
1964 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1965 name
= ggc_strdup (label
);
1966 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
1967 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
1969 initial_trampoline
= gen_rtx_MEM (BLKmode
, symbol
);
1970 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
1972 return initial_trampoline
;
1976 /* A and B are either alignments or offsets. Return the minimum alignment
1977 that may be assumed after adding the two together. */
1979 static inline unsigned
1980 min_align (unsigned int a
, unsigned int b
)
1982 return (a
| b
) & -(a
| b
);
1985 /* Return the assembler directive for creating a given kind of integer
1986 object. SIZE is the number of bytes in the object and ALIGNED_P
1987 indicates whether it is known to be aligned. Return NULL if the
1988 assembly dialect has no such directive.
1990 The returned string should be printed at the start of a new line and
1991 be followed immediately by the object's initial value. */
1994 integer_asm_op (int size
, int aligned_p
)
1996 struct asm_int_op
*ops
;
1999 ops
= &targetm
.asm_out
.aligned_op
;
2001 ops
= &targetm
.asm_out
.unaligned_op
;
2006 return targetm
.asm_out
.byte_op
;
2020 /* Use directive OP to assemble an integer object X. Print OP at the
2021 start of the line, followed immediately by the value of X. */
2024 assemble_integer_with_op (const char *op
, rtx x
)
2026 fputs (op
, asm_out_file
);
2027 output_addr_const (asm_out_file
, x
);
2028 fputc ('\n', asm_out_file
);
2031 /* The default implementation of the asm_out.integer target hook. */
2034 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2035 unsigned int size ATTRIBUTE_UNUSED
,
2036 int aligned_p ATTRIBUTE_UNUSED
)
2038 const char *op
= integer_asm_op (size
, aligned_p
);
2039 /* Avoid GAS bugs for large values. Specifically negative values whose
2040 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2041 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2043 return op
&& (assemble_integer_with_op (op
, x
), true);
2046 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2047 the alignment of the integer in bits. Return 1 if we were able to output
2048 the constant, otherwise 0. We must be able to output the constant,
2049 if FORCE is nonzero. */
2052 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2056 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2058 /* See if the target hook can handle this kind of object. */
2059 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2062 /* If the object is a multi-byte one, try splitting it up. Split
2063 it into words it if is multi-word, otherwise split it into bytes. */
2066 enum machine_mode omode
, imode
;
2067 unsigned int subalign
;
2068 unsigned int subsize
, i
;
2070 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2071 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2072 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, MODE_INT
, 0);
2073 imode
= mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
2075 for (i
= 0; i
< size
; i
+= subsize
)
2077 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2078 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2084 /* If we've printed some of it, but not all of it, there's no going
2089 gcc_assert (!force
);
2095 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2099 int bitsize
, nelts
, nunits
, units_per
;
2101 /* This is hairy. We have a quantity of known size. real_to_target
2102 will put it into an array of *host* longs, 32 bits per element
2103 (even if long is more than 32 bits). We need to determine the
2104 number of array elements that are occupied (nelts) and the number
2105 of *target* min-addressable units that will be occupied in the
2106 object file (nunits). We cannot assume that 32 divides the
2107 mode's bitsize (size * BITS_PER_UNIT) evenly.
2109 size * BITS_PER_UNIT is used here to make sure that padding bits
2110 (which might appear at either end of the value; real_to_target
2111 will include the padding bits in its output array) are included. */
2113 nunits
= GET_MODE_SIZE (mode
);
2114 bitsize
= nunits
* BITS_PER_UNIT
;
2115 nelts
= CEIL (bitsize
, 32);
2116 units_per
= 32 / BITS_PER_UNIT
;
2118 real_to_target (data
, &d
, mode
);
2120 /* Put out the first word with the specified alignment. */
2121 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2122 nunits
-= units_per
;
2124 /* Subsequent words need only 32-bit alignment. */
2125 align
= min_align (align
, 32);
2127 for (i
= 1; i
< nelts
; i
++)
2129 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2130 nunits
-= units_per
;
2134 /* Given an expression EXP with a constant value,
2135 reduce it to the sum of an assembler symbol and an integer.
2136 Store them both in the structure *VALUE.
2137 EXP must be reducible. */
2139 struct addr_const
GTY(())
2142 HOST_WIDE_INT offset
;
2146 decode_addr_const (tree exp
, struct addr_const
*value
)
2148 tree target
= TREE_OPERAND (exp
, 0);
2154 if (TREE_CODE (target
) == COMPONENT_REF
2155 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2158 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2159 target
= TREE_OPERAND (target
, 0);
2161 else if (TREE_CODE (target
) == ARRAY_REF
2162 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2164 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2165 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2166 target
= TREE_OPERAND (target
, 0);
2172 switch (TREE_CODE (target
))
2176 x
= DECL_RTL (target
);
2180 x
= gen_rtx_MEM (FUNCTION_MODE
,
2181 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2189 x
= output_constant_def (target
, 1);
2196 gcc_assert (MEM_P (x
));
2200 value
->offset
= offset
;
2203 /* Uniquize all constants that appear in memory.
2204 Each constant in memory thus far output is recorded
2205 in `const_desc_table'. */
2207 struct constant_descriptor_tree
GTY(())
2209 /* A MEM for the constant. */
2212 /* The value of the constant. */
2215 /* Hash of value. Computing the hash from value each time
2216 hashfn is called can't work properly, as that means recursive
2217 use of the hash table during hash table expansion. */
2221 static GTY((param_is (struct constant_descriptor_tree
)))
2222 htab_t const_desc_htab
;
2224 static struct constant_descriptor_tree
* build_constant_desc (tree
);
2225 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2227 /* Compute a hash code for a constant expression. */
2230 const_desc_hash (const void *ptr
)
2232 return ((struct constant_descriptor_tree
*)ptr
)->hash
;
2236 const_hash_1 (const tree exp
)
2241 enum tree_code code
= TREE_CODE (exp
);
2243 /* Either set P and LEN to the address and len of something to hash and
2244 exit the switch or return a value. */
2249 p
= (char *) &TREE_INT_CST (exp
);
2250 len
= sizeof TREE_INT_CST (exp
);
2254 return real_hash (TREE_REAL_CST_PTR (exp
));
2257 p
= TREE_STRING_POINTER (exp
);
2258 len
= TREE_STRING_LENGTH (exp
);
2262 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2263 + const_hash_1 (TREE_IMAGPART (exp
)));
2267 unsigned HOST_WIDE_INT idx
;
2270 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2272 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2274 hi
= hi
* 603 + const_hash_1 (value
);
2282 struct addr_const value
;
2284 decode_addr_const (exp
, &value
);
2285 switch (GET_CODE (value
.base
))
2288 /* Don't hash the address of the SYMBOL_REF;
2289 only use the offset and the symbol name. */
2291 p
= XSTR (value
.base
, 0);
2292 for (i
= 0; p
[i
] != 0; i
++)
2293 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2297 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2308 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2309 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2313 case NON_LVALUE_EXPR
:
2314 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2317 /* A language specific constant. Just hash the code. */
2321 /* Compute hashing function. */
2323 for (i
= 0; i
< len
; i
++)
2324 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2329 /* Wrapper of compare_constant, for the htab interface. */
2331 const_desc_eq (const void *p1
, const void *p2
)
2333 const struct constant_descriptor_tree
*c1
= p1
;
2334 const struct constant_descriptor_tree
*c2
= p2
;
2335 if (c1
->hash
!= c2
->hash
)
2337 return compare_constant (c1
->value
, c2
->value
);
2340 /* Compare t1 and t2, and return 1 only if they are known to result in
2341 the same bit pattern on output. */
2344 compare_constant (const tree t1
, const tree t2
)
2346 enum tree_code typecode
;
2348 if (t1
== NULL_TREE
)
2349 return t2
== NULL_TREE
;
2350 if (t2
== NULL_TREE
)
2353 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2356 switch (TREE_CODE (t1
))
2359 /* Integer constants are the same only if the same width of type. */
2360 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2362 return tree_int_cst_equal (t1
, t2
);
2365 /* Real constants are the same only if the same width of type. */
2366 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2369 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2372 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2375 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2376 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2377 TREE_STRING_LENGTH (t1
)));
2380 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2381 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2385 VEC(constructor_elt
, gc
) *v1
, *v2
;
2386 unsigned HOST_WIDE_INT idx
;
2388 typecode
= TREE_CODE (TREE_TYPE (t1
));
2389 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
2392 if (typecode
== ARRAY_TYPE
)
2394 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
2395 /* For arrays, check that the sizes all match. */
2396 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
2398 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
2403 /* For record and union constructors, require exact type
2405 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
2409 v1
= CONSTRUCTOR_ELTS (t1
);
2410 v2
= CONSTRUCTOR_ELTS (t2
);
2411 if (VEC_length (constructor_elt
, v1
)
2412 != VEC_length (constructor_elt
, v2
))
2415 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
2417 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
2418 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
2420 /* Check that each value is the same... */
2421 if (!compare_constant (c1
->value
, c2
->value
))
2423 /* ... and that they apply to the same fields! */
2424 if (typecode
== ARRAY_TYPE
)
2426 if (!compare_constant (c1
->index
, c2
->index
))
2431 if (c1
->index
!= c2
->index
)
2442 struct addr_const value1
, value2
;
2444 decode_addr_const (t1
, &value1
);
2445 decode_addr_const (t2
, &value2
);
2446 return (value1
.offset
== value2
.offset
2447 && strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
2453 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2454 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2458 case NON_LVALUE_EXPR
:
2459 case VIEW_CONVERT_EXPR
:
2460 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2465 nt1
= lang_hooks
.expand_constant (t1
);
2466 nt2
= lang_hooks
.expand_constant (t2
);
2467 if (nt1
!= t1
|| nt2
!= t2
)
2468 return compare_constant (nt1
, nt2
);
2477 /* Make a copy of the whole tree structure for a constant. This
2478 handles the same types of nodes that compare_constant handles. */
2481 copy_constant (tree exp
)
2483 switch (TREE_CODE (exp
))
2486 /* For ADDR_EXPR, we do not want to copy the decl whose address
2487 is requested. We do want to copy constants though. */
2488 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
2489 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2490 copy_constant (TREE_OPERAND (exp
, 0)));
2492 return copy_node (exp
);
2497 return copy_node (exp
);
2500 return build_complex (TREE_TYPE (exp
),
2501 copy_constant (TREE_REALPART (exp
)),
2502 copy_constant (TREE_IMAGPART (exp
)));
2506 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
2507 copy_constant (TREE_OPERAND (exp
, 0)),
2508 copy_constant (TREE_OPERAND (exp
, 1)));
2512 case NON_LVALUE_EXPR
:
2513 case VIEW_CONVERT_EXPR
:
2514 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2515 copy_constant (TREE_OPERAND (exp
, 0)));
2519 tree copy
= copy_node (exp
);
2520 VEC(constructor_elt
, gc
) *v
;
2521 unsigned HOST_WIDE_INT idx
;
2522 tree purpose
, value
;
2524 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
2525 CONSTRUCTOR_ELTS (exp
)));
2526 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
2528 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
2529 ce
->index
= purpose
;
2530 ce
->value
= copy_constant (value
);
2532 CONSTRUCTOR_ELTS (copy
) = v
;
2538 tree t
= lang_hooks
.expand_constant (exp
);
2540 gcc_assert (t
== exp
);
2541 return copy_constant (t
);
2546 /* Subroutine of output_constant_def:
2547 No constant equal to EXP is known to have been output.
2548 Make a constant descriptor to enter EXP in the hash table.
2549 Assign the label number and construct RTL to refer to the
2550 constant's location in memory.
2551 Caller is responsible for updating the hash table. */
2553 static struct constant_descriptor_tree
*
2554 build_constant_desc (tree exp
)
2560 struct constant_descriptor_tree
*desc
;
2562 desc
= ggc_alloc (sizeof (*desc
));
2563 desc
->value
= copy_constant (exp
);
2565 /* Propagate marked-ness to copied constant. */
2566 if (flag_mudflap
&& mf_marked_p (exp
))
2567 mf_mark (desc
->value
);
2569 /* Create a string containing the label name, in LABEL. */
2570 labelno
= const_labelno
++;
2571 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
2573 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2574 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
2575 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2576 SYMBOL_REF_DECL (symbol
) = desc
->value
;
2577 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
2579 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
2580 set_mem_attributes (rtl
, exp
, 1);
2581 set_mem_alias_set (rtl
, 0);
2582 set_mem_alias_set (rtl
, const_alias_set
);
2584 /* Set flags or add text to the name to record information, such as
2585 that it is a local symbol. If the name is changed, the macro
2586 ASM_OUTPUT_LABELREF will have to know how to strip this
2587 information. This call might invalidate our local variable
2588 SYMBOL; we can't use it afterward. */
2590 targetm
.encode_section_info (exp
, rtl
, true);
2597 /* Return an rtx representing a reference to constant data in memory
2598 for the constant expression EXP.
2600 If assembler code for such a constant has already been output,
2601 return an rtx to refer to it.
2602 Otherwise, output such a constant in memory
2603 and generate an rtx for it.
2605 If DEFER is nonzero, this constant can be deferred and output only
2606 if referenced in the function after all optimizations.
2608 `const_desc_table' records which constants already have label strings. */
2611 output_constant_def (tree exp
, int defer
)
2613 struct constant_descriptor_tree
*desc
;
2614 struct constant_descriptor_tree key
;
2617 /* Look up EXP in the table of constant descriptors. If we didn't find
2618 it, create a new one. */
2620 key
.hash
= const_hash_1 (exp
);
2621 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
2626 desc
= build_constant_desc (exp
);
2627 desc
->hash
= key
.hash
;
2631 maybe_output_constant_def_contents (desc
, defer
);
2635 /* Subroutine of output_constant_def: Decide whether or not we need to
2636 output the constant DESC now, and if so, do it. */
2638 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
2641 rtx symbol
= XEXP (desc
->rtl
, 0);
2642 tree exp
= desc
->value
;
2644 if (flag_syntax_only
)
2647 if (TREE_ASM_WRITTEN (exp
))
2648 /* Already output; don't do it again. */
2651 /* We can always defer constants as long as the context allows
2655 /* Increment n_deferred_constants if it exists. It needs to be at
2656 least as large as the number of constants actually referred to
2657 by the function. If it's too small we'll stop looking too early
2658 and fail to emit constants; if it's too large we'll only look
2659 through the entire function when we could have stopped earlier. */
2661 n_deferred_constants
++;
2665 output_constant_def_contents (symbol
);
2668 /* We must output the constant data referred to by SYMBOL; do so. */
2671 output_constant_def_contents (rtx symbol
)
2673 tree exp
= SYMBOL_REF_DECL (symbol
);
2674 const char *label
= XSTR (symbol
, 0);
2677 /* Make sure any other constants whose addresses appear in EXP
2678 are assigned label numbers. */
2679 int reloc
= compute_reloc_for_constant (exp
);
2681 /* Align the location counter as required by EXP's data type. */
2682 unsigned int align
= TYPE_ALIGN (TREE_TYPE (exp
));
2683 #ifdef CONSTANT_ALIGNMENT
2684 align
= CONSTANT_ALIGNMENT (exp
, align
);
2687 output_addressed_constants (exp
);
2689 /* We are no longer deferring this constant. */
2690 TREE_ASM_WRITTEN (exp
) = 1;
2692 if (IN_NAMED_SECTION (exp
))
2693 switch_to_section (get_named_section (exp
, NULL
, reloc
));
2695 switch_to_section (targetm
.asm_out
.select_section (exp
, reloc
, align
));
2697 if (align
> BITS_PER_UNIT
)
2699 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2702 size
= int_size_in_bytes (TREE_TYPE (exp
));
2703 if (TREE_CODE (exp
) == STRING_CST
)
2704 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
2706 /* Do any machine/system dependent processing of the constant. */
2707 #ifdef ASM_DECLARE_CONSTANT_NAME
2708 ASM_DECLARE_CONSTANT_NAME (asm_out_file
, label
, exp
, size
);
2710 /* Standard thing is just output label for the constant. */
2711 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2712 #endif /* ASM_DECLARE_CONSTANT_NAME */
2714 /* Output the value of EXP. */
2715 output_constant (exp
, size
, align
);
2717 mudflap_enqueue_constant (exp
);
2720 /* Look up EXP in the table of constant descriptors. Return the rtl
2721 if it has been emitted, else null. */
2724 lookup_constant_def (tree exp
)
2726 struct constant_descriptor_tree
*desc
;
2727 struct constant_descriptor_tree key
;
2730 key
.hash
= const_hash_1 (exp
);
2731 desc
= htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
2733 return (desc
? desc
->rtl
: NULL_RTX
);
2736 /* Used in the hash tables to avoid outputting the same constant
2737 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2738 are output once per function, not once per file. */
2739 /* ??? Only a few targets need per-function constant pools. Most
2740 can use one per-file pool. Should add a targetm bit to tell the
2743 struct rtx_constant_pool
GTY(())
2745 /* Pointers to first and last constant in pool, as ordered by offset. */
2746 struct constant_descriptor_rtx
*first
;
2747 struct constant_descriptor_rtx
*last
;
2749 /* Hash facility for making memory-constants from constant rtl-expressions.
2750 It is used on RISC machines where immediate integer arguments and
2751 constant addresses are restricted so that such constants must be stored
2753 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
2754 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_sym_htab
;
2756 /* Current offset in constant pool (does not include any
2757 machine-specific header). */
2758 HOST_WIDE_INT offset
;
2761 struct constant_descriptor_rtx
GTY((chain_next ("%h.next")))
2763 struct constant_descriptor_rtx
*next
;
2767 HOST_WIDE_INT offset
;
2769 enum machine_mode mode
;
2775 /* Hash and compare functions for const_rtx_htab. */
2778 const_desc_rtx_hash (const void *ptr
)
2780 const struct constant_descriptor_rtx
*desc
= ptr
;
2785 const_desc_rtx_eq (const void *a
, const void *b
)
2787 const struct constant_descriptor_rtx
*x
= a
;
2788 const struct constant_descriptor_rtx
*y
= b
;
2790 if (x
->mode
!= y
->mode
)
2792 return rtx_equal_p (x
->constant
, y
->constant
);
2795 /* Hash and compare functions for const_rtx_sym_htab. */
2798 const_desc_rtx_sym_hash (const void *ptr
)
2800 const struct constant_descriptor_rtx
*desc
= ptr
;
2801 return htab_hash_string (XSTR (desc
->sym
, 0));
2805 const_desc_rtx_sym_eq (const void *a
, const void *b
)
2807 const struct constant_descriptor_rtx
*x
= a
;
2808 const struct constant_descriptor_rtx
*y
= b
;
2809 return XSTR (x
->sym
, 0) == XSTR (y
->sym
, 0);
2812 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
2815 const_rtx_hash_1 (rtx
*xp
, void *data
)
2817 unsigned HOST_WIDE_INT hwi
;
2818 enum machine_mode mode
;
2824 code
= GET_CODE (x
);
2825 mode
= GET_MODE (x
);
2826 h
= (hashval_t
) code
* 1048573 + mode
;
2834 const int shift
= sizeof (hashval_t
) * CHAR_BIT
;
2835 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
2838 h
^= (hashval_t
) hwi
;
2839 for (i
= 1; i
< n
; ++i
)
2842 h
^= (hashval_t
) hwi
;
2848 if (mode
== VOIDmode
)
2850 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
2854 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
2860 for (i
= XVECLEN (x
, 0); i
-- > 0; )
2861 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
2866 h
^= htab_hash_string (XSTR (x
, 0));
2870 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
2874 case UNSPEC_VOLATILE
:
2875 h
= h
* 251 + XINT (x
, 1);
2883 *hp
= *hp
* 509 + h
;
2887 /* Compute a hash value for X, which should be a constant. */
2890 const_rtx_hash (rtx x
)
2893 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
2898 /* Initialize constant pool hashing for a new function. */
2901 init_varasm_status (struct function
*f
)
2903 struct varasm_status
*p
;
2904 struct rtx_constant_pool
*pool
;
2906 p
= ggc_alloc (sizeof (struct varasm_status
));
2909 pool
= ggc_alloc (sizeof (struct rtx_constant_pool
));
2911 p
->deferred_constants
= 0;
2913 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
2914 const_desc_rtx_eq
, NULL
);
2915 pool
->const_rtx_sym_htab
= htab_create_ggc (31, const_desc_rtx_sym_hash
,
2916 const_desc_rtx_sym_eq
, NULL
);
2917 pool
->first
= pool
->last
= NULL
;
2921 /* Given a MINUS expression, simplify it if both sides
2922 include the same symbol. */
2925 simplify_subtraction (rtx x
)
2927 rtx r
= simplify_rtx (x
);
2931 /* Given a constant rtx X, make (or find) a memory constant for its value
2932 and return a MEM rtx to refer to it in memory. */
2935 force_const_mem (enum machine_mode mode
, rtx x
)
2937 struct constant_descriptor_rtx
*desc
, tmp
;
2938 struct rtx_constant_pool
*pool
= cfun
->varasm
->pool
;
2945 /* If we're not allowed to drop X into the constant pool, don't. */
2946 if (targetm
.cannot_force_const_mem (x
))
2949 /* Lookup the value in the hashtable. */
2952 hash
= const_rtx_hash (x
);
2953 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
2956 /* If the constant was already present, return its memory. */
2958 return copy_rtx (desc
->mem
);
2960 /* Otherwise, create a new descriptor. */
2961 desc
= ggc_alloc (sizeof (*desc
));
2964 /* Align the location counter as required by EXP's data type. */
2965 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
2966 #ifdef CONSTANT_ALIGNMENT
2968 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
2969 if (type
!= NULL_TREE
)
2970 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
2974 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
2975 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
2978 desc
->constant
= tmp
.constant
;
2979 desc
->offset
= pool
->offset
;
2982 desc
->align
= align
;
2983 desc
->labelno
= const_labelno
;
2986 pool
->offset
+= GET_MODE_SIZE (mode
);
2988 pool
->last
->next
= desc
;
2990 pool
->first
= pool
->last
= desc
;
2993 /* Create a string containing the label name, in LABEL. */
2994 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2997 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
2998 the constants pool. */
2999 desc
->sym
= symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3000 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
3001 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3002 current_function_uses_const_pool
= 1;
3004 /* Insert the descriptor into the symbol cross-reference table too. */
3005 slot
= htab_find_slot (pool
->const_rtx_sym_htab
, desc
, INSERT
);
3006 gcc_assert (!*slot
);
3009 /* Construct the MEM. */
3010 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3011 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3012 set_mem_align (def
, align
);
3014 /* If we're dropping a label to the constant pool, make sure we
3016 if (GET_CODE (x
) == LABEL_REF
)
3017 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3019 return copy_rtx (def
);
3022 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3023 the corresponding constant_descriptor_rtx structure. */
3025 static struct constant_descriptor_rtx
*
3026 find_pool_constant (struct rtx_constant_pool
*pool
, rtx sym
)
3028 struct constant_descriptor_rtx tmp
;
3030 return htab_find (pool
->const_rtx_sym_htab
, &tmp
);
3033 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3036 get_pool_constant (rtx addr
)
3038 return find_pool_constant (cfun
->varasm
->pool
, addr
)->constant
;
3041 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3042 and whether it has been output or not. */
3045 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3047 struct constant_descriptor_rtx
*desc
;
3049 desc
= find_pool_constant (cfun
->varasm
->pool
, addr
);
3050 *pmarked
= (desc
->mark
!= 0);
3051 return desc
->constant
;
3054 /* Likewise, but for the constant pool of a specific function. */
3057 get_pool_constant_for_function (struct function
*f
, rtx addr
)
3059 return find_pool_constant (f
->varasm
->pool
, addr
)->constant
;
3062 /* Similar, return the mode. */
3065 get_pool_mode (rtx addr
)
3067 return find_pool_constant (cfun
->varasm
->pool
, addr
)->mode
;
3070 /* Return the size of the constant pool. */
3073 get_pool_size (void)
3075 return cfun
->varasm
->pool
->offset
;
3078 /* Worker function for output_constant_pool_1. Emit assembly for X
3079 in MODE with known alignment ALIGN. */
3082 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3084 switch (GET_MODE_CLASS (mode
))
3087 case MODE_DECIMAL_FLOAT
:
3091 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3092 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3093 assemble_real (r
, mode
, align
);
3098 case MODE_PARTIAL_INT
:
3099 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3102 case MODE_VECTOR_FLOAT
:
3103 case MODE_VECTOR_INT
:
3106 enum machine_mode submode
= GET_MODE_INNER (mode
);
3107 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3109 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3110 units
= CONST_VECTOR_NUNITS (x
);
3112 for (i
= 0; i
< units
; i
++)
3114 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3115 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3125 /* Worker function for output_constant_pool. Emit POOL. */
3128 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
)
3136 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3137 whose CODE_LABEL has been deleted. This can occur if a jump table
3138 is eliminated by optimization. If so, write a constant of zero
3139 instead. Note that this can also happen by turning the
3140 CODE_LABEL into a NOTE. */
3141 /* ??? This seems completely and utterly wrong. Certainly it's
3142 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3143 functioning even with INSN_DELETED_P and friends. */
3146 switch (GET_CODE (x
))
3149 if (GET_CODE (XEXP (x
, 0)) != PLUS
3150 || GET_CODE (XEXP (XEXP (x
, 0), 0)) != LABEL_REF
)
3152 tmp
= XEXP (XEXP (x
, 0), 0);
3157 gcc_assert (!INSN_DELETED_P (tmp
));
3158 gcc_assert (!NOTE_P (tmp
)
3159 || NOTE_LINE_NUMBER (tmp
) != NOTE_INSN_DELETED
);
3166 /* First switch to correct section. */
3167 switch_to_section (targetm
.asm_out
.select_rtx_section (desc
->mode
, x
,
3170 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3171 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3172 desc
->align
, desc
->labelno
, done
);
3175 assemble_align (desc
->align
);
3177 /* Output the label. */
3178 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3180 /* Output the data. */
3181 output_constant_pool_2 (desc
->mode
, x
, desc
->align
);
3183 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3184 sections have proper size. */
3185 if (desc
->align
> GET_MODE_BITSIZE (desc
->mode
)
3187 && (in_section
->common
.flags
& SECTION_MERGE
))
3188 assemble_align (desc
->align
);
3190 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3196 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3197 to as used. Emit referenced deferred strings. This function can
3198 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3201 mark_constant (rtx
*current_rtx
, void *data
)
3203 struct rtx_constant_pool
*pool
= data
;
3204 rtx x
= *current_rtx
;
3206 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3209 if (CONSTANT_POOL_ADDRESS_P (x
))
3211 struct constant_descriptor_rtx
*desc
= find_pool_constant (pool
, x
);
3212 if (desc
->mark
== 0)
3215 for_each_rtx (&desc
->constant
, mark_constant
, pool
);
3218 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3220 tree exp
= SYMBOL_REF_DECL (x
);
3221 if (!TREE_ASM_WRITTEN (exp
))
3223 n_deferred_constants
--;
3224 output_constant_def_contents (x
);
3231 /* Look through appropriate parts of INSN, marking all entries in the
3232 constant pool which are actually being used. Entries that are only
3233 referenced by other constants are also marked as used. Emit
3234 deferred strings that are used. */
3237 mark_constants (struct rtx_constant_pool
*pool
, rtx insn
)
3242 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3243 insns, not any notes that may be attached. We don't want to mark
3244 a constant just because it happens to appear in a REG_EQUIV note. */
3245 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3247 rtx seq
= PATTERN (insn
);
3248 int i
, n
= XVECLEN (seq
, 0);
3249 for (i
= 0; i
< n
; ++i
)
3251 rtx subinsn
= XVECEXP (seq
, 0, i
);
3252 if (INSN_P (subinsn
))
3253 for_each_rtx (&PATTERN (subinsn
), mark_constant
, pool
);
3257 for_each_rtx (&PATTERN (insn
), mark_constant
, pool
);
3260 /* Look through the instructions for this function, and mark all the
3261 entries in POOL which are actually being used. Emit deferred constants
3262 which have indeed been used. */
3265 mark_constant_pool (struct rtx_constant_pool
*pool
)
3269 if (pool
->first
== 0 && n_deferred_constants
== 0)
3272 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3273 mark_constants (pool
, insn
);
3275 for (link
= current_function_epilogue_delay_list
;
3277 link
= XEXP (link
, 1))
3278 mark_constants (pool
, XEXP (link
, 0));
3281 /* Write all the constants in the constant pool. */
3284 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3285 tree fndecl ATTRIBUTE_UNUSED
)
3287 struct rtx_constant_pool
*pool
= cfun
->varasm
->pool
;
3288 struct constant_descriptor_rtx
*desc
;
3290 /* It is possible for gcc to call force_const_mem and then to later
3291 discard the instructions which refer to the constant. In such a
3292 case we do not need to output the constant. */
3293 mark_constant_pool (pool
);
3295 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3296 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3299 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3300 output_constant_pool_1 (desc
);
3302 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3303 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3307 /* Determine what kind of relocations EXP may need. */
3310 compute_reloc_for_constant (tree exp
)
3312 int reloc
= 0, reloc2
;
3315 /* Give the front-end a chance to convert VALUE to something that
3316 looks more like a constant to the back-end. */
3317 exp
= lang_hooks
.expand_constant (exp
);
3319 switch (TREE_CODE (exp
))
3323 /* Go inside any operations that get_inner_reference can handle and see
3324 if what's inside is a constant: no need to do anything here for
3325 addresses of variables or functions. */
3326 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3327 tem
= TREE_OPERAND (tem
, 0))
3330 if (TREE_PUBLIC (tem
))
3337 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3338 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3342 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3343 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3344 /* The difference of two local labels is computable at link time. */
3345 if (reloc
== 1 && reloc2
== 1)
3353 case NON_LVALUE_EXPR
:
3354 case VIEW_CONVERT_EXPR
:
3355 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3360 unsigned HOST_WIDE_INT idx
;
3361 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3363 reloc
|= compute_reloc_for_constant (tem
);
3373 /* Find all the constants whose addresses are referenced inside of EXP,
3374 and make sure assembler code with a label has been output for each one.
3375 Indicate whether an ADDR_EXPR has been encountered. */
3378 output_addressed_constants (tree exp
)
3382 /* Give the front-end a chance to convert VALUE to something that
3383 looks more like a constant to the back-end. */
3384 exp
= lang_hooks
.expand_constant (exp
);
3386 switch (TREE_CODE (exp
))
3390 /* Go inside any operations that get_inner_reference can handle and see
3391 if what's inside is a constant: no need to do anything here for
3392 addresses of variables or functions. */
3393 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3394 tem
= TREE_OPERAND (tem
, 0))
3397 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3398 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
3399 tem
= DECL_INITIAL (tem
);
3401 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
3402 output_constant_def (tem
, 0);
3407 output_addressed_constants (TREE_OPERAND (exp
, 1));
3412 case NON_LVALUE_EXPR
:
3413 case VIEW_CONVERT_EXPR
:
3414 output_addressed_constants (TREE_OPERAND (exp
, 0));
3419 unsigned HOST_WIDE_INT idx
;
3420 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3422 output_addressed_constants (tem
);
3431 /* Return nonzero if VALUE is a valid constant-valued expression
3432 for use in initializing a static variable; one that can be an
3433 element of a "constant" initializer.
3435 Return null_pointer_node if the value is absolute;
3436 if it is relocatable, return the variable that determines the relocation.
3437 We assume that VALUE has been folded as much as possible;
3438 therefore, we do not need to check for such things as
3439 arithmetic-combinations of integers. */
3442 initializer_constant_valid_p (tree value
, tree endtype
)
3444 /* Give the front-end a chance to convert VALUE to something that
3445 looks more like a constant to the back-end. */
3446 value
= lang_hooks
.expand_constant (value
);
3448 switch (TREE_CODE (value
))
3451 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
3452 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
3453 && TREE_CONSTANT (value
)
3454 && !VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (value
)))
3456 unsigned HOST_WIDE_INT idx
;
3458 bool absolute
= true;
3460 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
3463 reloc
= initializer_constant_valid_p (elt
, TREE_TYPE (elt
));
3466 if (reloc
!= null_pointer_node
)
3469 /* For a non-absolute relocation, there is no single
3470 variable that can be "the variable that determines the
3472 return absolute
? null_pointer_node
: error_mark_node
;
3475 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
3482 return null_pointer_node
;
3486 value
= staticp (TREE_OPERAND (value
, 0));
3489 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to
3490 be a constant, this is old-skool offsetof-like nonsense. */
3491 if (TREE_CODE (value
) == INDIRECT_REF
3492 && TREE_CONSTANT (TREE_OPERAND (value
, 0)))
3493 return null_pointer_node
;
3494 /* Taking the address of a nested function involves a trampoline. */
3495 if (TREE_CODE (value
) == FUNCTION_DECL
3496 && ((decl_function_context (value
)
3497 && !DECL_NO_STATIC_CHAIN (value
))
3498 || DECL_DLLIMPORT_P (value
)))
3500 /* "&{...}" requires a temporary to hold the constructed
3502 if (TREE_CODE (value
) == CONSTRUCTOR
)
3507 case VIEW_CONVERT_EXPR
:
3508 case NON_LVALUE_EXPR
:
3509 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3518 src
= TREE_OPERAND (value
, 0);
3519 src_type
= TREE_TYPE (src
);
3520 dest_type
= TREE_TYPE (value
);
3522 /* Allow conversions between pointer types, floating-point
3523 types, and offset types. */
3524 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
3525 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
3526 || (TREE_CODE (dest_type
) == OFFSET_TYPE
3527 && TREE_CODE (src_type
) == OFFSET_TYPE
))
3528 return initializer_constant_valid_p (src
, endtype
);
3530 /* Allow length-preserving conversions between integer types. */
3531 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
3532 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
3533 return initializer_constant_valid_p (src
, endtype
);
3535 /* Allow conversions between other integer types only if
3537 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
3539 tree inner
= initializer_constant_valid_p (src
, endtype
);
3540 if (inner
== null_pointer_node
)
3541 return null_pointer_node
;
3545 /* Allow (int) &foo provided int is as wide as a pointer. */
3546 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
3547 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
3548 return initializer_constant_valid_p (src
, endtype
);
3550 /* Likewise conversions from int to pointers, but also allow
3551 conversions from 0. */
3552 if ((POINTER_TYPE_P (dest_type
)
3553 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
3554 && INTEGRAL_TYPE_P (src_type
))
3556 if (integer_zerop (src
))
3557 return null_pointer_node
;
3558 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
3559 return initializer_constant_valid_p (src
, endtype
);
3562 /* Allow conversions to struct or union types if the value
3564 if (TREE_CODE (dest_type
) == RECORD_TYPE
3565 || TREE_CODE (dest_type
) == UNION_TYPE
)
3566 return initializer_constant_valid_p (src
, endtype
);
3571 if (! INTEGRAL_TYPE_P (endtype
)
3572 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
3574 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3576 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
3578 /* If either term is absolute, use the other terms relocation. */
3579 if (valid0
== null_pointer_node
)
3581 if (valid1
== null_pointer_node
)
3587 if (! INTEGRAL_TYPE_P (endtype
)
3588 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
3590 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3592 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
3594 /* Win if second argument is absolute. */
3595 if (valid1
== null_pointer_node
)
3597 /* Win if both arguments have the same relocation.
3598 Then the value is absolute. */
3599 if (valid0
== valid1
&& valid0
!= 0)
3600 return null_pointer_node
;
3602 /* Since GCC guarantees that string constants are unique in the
3603 generated code, a subtraction between two copies of the same
3604 constant string is absolute. */
3605 if (valid0
&& TREE_CODE (valid0
) == STRING_CST
3606 && valid1
&& TREE_CODE (valid1
) == STRING_CST
3607 && operand_equal_p (valid0
, valid1
, 1))
3608 return null_pointer_node
;
3611 /* Support narrowing differences. */
3612 if (INTEGRAL_TYPE_P (endtype
))
3616 op0
= TREE_OPERAND (value
, 0);
3617 op1
= TREE_OPERAND (value
, 1);
3619 /* Like STRIP_NOPS except allow the operand mode to widen.
3620 This works around a feature of fold that simplifies
3621 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3622 that the narrower operation is cheaper. */
3624 while (TREE_CODE (op0
) == NOP_EXPR
3625 || TREE_CODE (op0
) == CONVERT_EXPR
3626 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
3628 tree inner
= TREE_OPERAND (op0
, 0);
3629 if (inner
== error_mark_node
3630 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3631 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
3632 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3637 while (TREE_CODE (op1
) == NOP_EXPR
3638 || TREE_CODE (op1
) == CONVERT_EXPR
3639 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
3641 tree inner
= TREE_OPERAND (op1
, 0);
3642 if (inner
== error_mark_node
3643 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3644 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
3645 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3650 op0
= initializer_constant_valid_p (op0
, endtype
);
3651 op1
= initializer_constant_valid_p (op1
, endtype
);
3653 /* Both initializers must be known. */
3657 return null_pointer_node
;
3659 /* Support differences between labels. */
3660 if (TREE_CODE (op0
) == LABEL_DECL
3661 && TREE_CODE (op1
) == LABEL_DECL
)
3662 return null_pointer_node
;
3664 if (TREE_CODE (op0
) == STRING_CST
3665 && TREE_CODE (op1
) == STRING_CST
3666 && operand_equal_p (op0
, op1
, 1))
3667 return null_pointer_node
;
3679 /* Output assembler code for constant EXP to FILE, with no label.
3680 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3681 Assumes output_addressed_constants has been done on EXP already.
3683 Generate exactly SIZE bytes of assembler data, padding at the end
3684 with zeros if necessary. SIZE must always be specified.
3686 SIZE is important for structure constructors,
3687 since trailing members may have been omitted from the constructor.
3688 It is also important for initialization of arrays from string constants
3689 since the full length of the string constant might not be wanted.
3690 It is also needed for initialization of unions, where the initializer's
3691 type is just one member, and that may not be as long as the union.
3693 There a case in which we would fail to output exactly SIZE bytes:
3694 for a structure constructor that wants to produce more than SIZE bytes.
3695 But such constructors will never be generated for any possible input.
3697 ALIGN is the alignment of the data in bits. */
3700 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
3702 enum tree_code code
;
3703 unsigned HOST_WIDE_INT thissize
;
3705 /* Some front-ends use constants other than the standard language-independent
3706 varieties, but which may still be output directly. Give the front-end a
3707 chance to convert EXP to a language-independent representation. */
3708 exp
= lang_hooks
.expand_constant (exp
);
3710 if (size
== 0 || flag_syntax_only
)
3713 /* See if we're trying to initialize a pointer in a non-default mode
3714 to the address of some declaration somewhere. If the target says
3715 the mode is valid for pointers, assume the target has a way of
3717 if (TREE_CODE (exp
) == NOP_EXPR
3718 && POINTER_TYPE_P (TREE_TYPE (exp
))
3719 && targetm
.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp
))))
3721 tree saved_type
= TREE_TYPE (exp
);
3723 /* Peel off any intermediate conversions-to-pointer for valid
3725 while (TREE_CODE (exp
) == NOP_EXPR
3726 && POINTER_TYPE_P (TREE_TYPE (exp
))
3727 && targetm
.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp
))))
3728 exp
= TREE_OPERAND (exp
, 0);
3730 /* If what we're left with is the address of something, we can
3731 convert the address to the final type and output it that
3733 if (TREE_CODE (exp
) == ADDR_EXPR
)
3734 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
3737 /* Eliminate any conversions since we'll be outputting the underlying
3739 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
3740 || TREE_CODE (exp
) == NON_LVALUE_EXPR
3741 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
3743 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
3744 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
3746 /* Make sure eliminating the conversion is really a no-op, except with
3747 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
3748 union types to allow for Ada unchecked unions. */
3749 if (type_size
> op_size
3750 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
3751 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
3752 internal_error ("no-op convert from %wd to %wd bytes in initializer",
3753 op_size
, type_size
);
3755 exp
= TREE_OPERAND (exp
, 0);
3758 code
= TREE_CODE (TREE_TYPE (exp
));
3759 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
3761 /* Allow a constructor with no elements for any data type.
3762 This means to fill the space with zeros. */
3763 if (TREE_CODE (exp
) == CONSTRUCTOR
3764 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
3766 assemble_zeros (size
);
3770 if (TREE_CODE (exp
) == FDESC_EXPR
)
3772 #ifdef ASM_OUTPUT_FDESC
3773 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
3774 tree decl
= TREE_OPERAND (exp
, 0);
3775 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
3782 /* Now output the underlying data. If we've handling the padding, return.
3783 Otherwise, break and ensure SIZE is the size written. */
3791 case REFERENCE_TYPE
:
3793 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
3794 EXPAND_INITIALIZER
),
3795 MIN (size
, thissize
), align
, 0))
3796 error ("initializer for integer value is too complicated");
3800 if (TREE_CODE (exp
) != REAL_CST
)
3801 error ("initializer for floating value is not a floating constant");
3803 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
3807 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
3808 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
3809 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
3814 switch (TREE_CODE (exp
))
3817 output_constructor (exp
, size
, align
);
3820 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
3822 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
3829 unsigned int nalign
;
3830 enum machine_mode inner
;
3832 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
3833 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
3835 elt_size
= GET_MODE_SIZE (inner
);
3837 link
= TREE_VECTOR_CST_ELTS (exp
);
3838 output_constant (TREE_VALUE (link
), elt_size
, align
);
3839 while ((link
= TREE_CHAIN (link
)) != NULL
)
3840 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
3850 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
3851 output_constructor (exp
, size
, align
);
3861 if (size
> thissize
)
3862 assemble_zeros (size
- thissize
);
3866 /* Subroutine of output_constructor, used for computing the size of
3867 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3868 type with an unspecified upper bound. */
3870 static unsigned HOST_WIDE_INT
3871 array_size_for_constructor (tree val
)
3874 unsigned HOST_WIDE_INT cnt
;
3877 /* This code used to attempt to handle string constants that are not
3878 arrays of single-bytes, but nothing else does, so there's no point in
3880 if (TREE_CODE (val
) == STRING_CST
)
3881 return TREE_STRING_LENGTH (val
);
3883 max_index
= NULL_TREE
;
3884 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
3886 if (TREE_CODE (index
) == RANGE_EXPR
)
3887 index
= TREE_OPERAND (index
, 1);
3888 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
3892 if (max_index
== NULL_TREE
)
3895 /* Compute the total number of array elements. */
3896 i
= size_binop (MINUS_EXPR
, convert (sizetype
, max_index
),
3898 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)))));
3899 i
= size_binop (PLUS_EXPR
, i
, build_int_cst (sizetype
, 1));
3901 /* Multiply by the array element unit size to find number of bytes. */
3902 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
3904 return tree_low_cst (i
, 1);
3907 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3908 Generate at least SIZE bytes, padding if necessary. */
3911 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
3914 tree type
= TREE_TYPE (exp
);
3917 /* Number of bytes output or skipped so far.
3918 In other words, current position within the constructor. */
3919 HOST_WIDE_INT total_bytes
= 0;
3920 /* Nonzero means BYTE contains part of a byte, to be output. */
3921 int byte_buffer_in_use
= 0;
3923 unsigned HOST_WIDE_INT cnt
;
3924 constructor_elt
*ce
;
3926 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
3928 if (TREE_CODE (type
) == RECORD_TYPE
)
3929 field
= TYPE_FIELDS (type
);
3931 if (TREE_CODE (type
) == ARRAY_TYPE
3932 && TYPE_DOMAIN (type
) != 0)
3933 min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
3935 /* As LINK goes through the elements of the constant,
3936 FIELD goes through the structure fields, if the constant is a structure.
3937 if the constant is a union, then we override this,
3938 by getting the field from the TREE_LIST element.
3939 But the constant could also be an array. Then FIELD is zero.
3941 There is always a maximum of one element in the chain LINK for unions
3942 (even if the initializer in a source program incorrectly contains
3945 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
3946 cnt
++, field
= field
? TREE_CHAIN (field
) : 0)
3948 tree val
= ce
->value
;
3951 /* The element in a union constructor specifies the proper field
3953 if ((TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
3954 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
3958 else if (TREE_CODE (type
) == ARRAY_TYPE
)
3961 #ifdef ASM_COMMENT_START
3962 if (field
&& flag_verbose_asm
)
3963 fprintf (asm_out_file
, "%s %s:\n",
3966 ? IDENTIFIER_POINTER (DECL_NAME (field
))
3970 /* Eliminate the marker that makes a cast not be an lvalue. */
3974 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
3976 unsigned HOST_WIDE_INT fieldsize
3977 = int_size_in_bytes (TREE_TYPE (type
));
3978 HOST_WIDE_INT lo_index
= tree_low_cst (TREE_OPERAND (index
, 0), 0);
3979 HOST_WIDE_INT hi_index
= tree_low_cst (TREE_OPERAND (index
, 1), 0);
3980 HOST_WIDE_INT index
;
3981 unsigned int align2
= min_align (align
, fieldsize
* BITS_PER_UNIT
);
3983 for (index
= lo_index
; index
<= hi_index
; index
++)
3985 /* Output the element's initial value. */
3987 assemble_zeros (fieldsize
);
3989 output_constant (val
, fieldsize
, align2
);
3991 /* Count its size. */
3992 total_bytes
+= fieldsize
;
3995 else if (field
== 0 || !DECL_BIT_FIELD (field
))
3997 /* An element that is not a bit-field. */
3999 unsigned HOST_WIDE_INT fieldsize
;
4000 /* Since this structure is static,
4001 we know the positions are constant. */
4002 HOST_WIDE_INT pos
= field
? int_byte_position (field
) : 0;
4003 unsigned int align2
;
4006 pos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val
)), 1)
4007 * (tree_low_cst (index
, 0) - tree_low_cst (min_index
, 0)));
4009 /* Output any buffered-up bit-fields preceding this element. */
4010 if (byte_buffer_in_use
)
4012 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4014 byte_buffer_in_use
= 0;
4017 /* Advance to offset of this element.
4018 Note no alignment needed in an array, since that is guaranteed
4019 if each element has the proper size. */
4020 if ((field
!= 0 || index
!= 0) && pos
!= total_bytes
)
4022 gcc_assert (pos
>= total_bytes
);
4023 assemble_zeros (pos
- total_bytes
);
4027 /* Find the alignment of this element. */
4028 align2
= min_align (align
, BITS_PER_UNIT
* pos
);
4030 /* Determine size this element should occupy. */
4035 /* If this is an array with an unspecified upper bound,
4036 the initializer determines the size. */
4037 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4038 but we cannot do this until the deprecated support for
4039 initializing zero-length array members is removed. */
4040 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
4041 && TYPE_DOMAIN (TREE_TYPE (field
))
4042 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
4044 fieldsize
= array_size_for_constructor (val
);
4045 /* Given a non-empty initialization, this field had
4047 gcc_assert (!fieldsize
|| !TREE_CHAIN (field
));
4049 else if (DECL_SIZE_UNIT (field
))
4051 /* ??? This can't be right. If the decl size overflows
4052 a host integer we will silently emit no data. */
4053 if (host_integerp (DECL_SIZE_UNIT (field
), 1))
4054 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 1);
4058 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
4060 /* Output the element's initial value. */
4062 assemble_zeros (fieldsize
);
4064 output_constant (val
, fieldsize
, align2
);
4066 /* Count its size. */
4067 total_bytes
+= fieldsize
;
4069 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4070 error ("invalid initial value for member %qs",
4071 IDENTIFIER_POINTER (DECL_NAME (field
)));
4074 /* Element that is a bit-field. */
4076 HOST_WIDE_INT next_offset
= int_bit_position (field
);
4077 HOST_WIDE_INT end_offset
4078 = (next_offset
+ tree_low_cst (DECL_SIZE (field
), 1));
4081 val
= integer_zero_node
;
4083 /* If this field does not start in this (or, next) byte,
4085 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4087 /* Output remnant of any bit field in previous bytes. */
4088 if (byte_buffer_in_use
)
4090 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4092 byte_buffer_in_use
= 0;
4095 /* If still not at proper byte, advance to there. */
4096 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4098 gcc_assert (next_offset
/ BITS_PER_UNIT
>= total_bytes
);
4099 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4100 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4104 if (! byte_buffer_in_use
)
4107 /* We must split the element into pieces that fall within
4108 separate bytes, and combine each byte with previous or
4109 following bit-fields. */
4111 /* next_offset is the offset n fbits from the beginning of
4112 the structure to the next bit of this element to be processed.
4113 end_offset is the offset of the first bit past the end of
4115 while (next_offset
< end_offset
)
4119 HOST_WIDE_INT value
;
4120 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4121 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4123 /* Advance from byte to byte
4124 within this element when necessary. */
4125 while (next_byte
!= total_bytes
)
4127 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4132 /* Number of bits we can process at once
4133 (all part of the same byte). */
4134 this_time
= MIN (end_offset
- next_offset
,
4135 BITS_PER_UNIT
- next_bit
);
4136 if (BYTES_BIG_ENDIAN
)
4138 /* On big-endian machine, take the most significant bits
4139 first (of the bits that are significant)
4140 and put them into bytes from the most significant end. */
4141 shift
= end_offset
- next_offset
- this_time
;
4143 /* Don't try to take a bunch of bits that cross
4144 the word boundary in the INTEGER_CST. We can
4145 only select bits from the LOW or HIGH part
4147 if (shift
< HOST_BITS_PER_WIDE_INT
4148 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4150 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4151 shift
= HOST_BITS_PER_WIDE_INT
;
4154 /* Now get the bits from the appropriate constant word. */
4155 if (shift
< HOST_BITS_PER_WIDE_INT
)
4156 value
= TREE_INT_CST_LOW (val
);
4159 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4160 value
= TREE_INT_CST_HIGH (val
);
4161 shift
-= HOST_BITS_PER_WIDE_INT
;
4164 /* Get the result. This works only when:
4165 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4166 byte
|= (((value
>> shift
)
4167 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4168 << (BITS_PER_UNIT
- this_time
- next_bit
));
4172 /* On little-endian machines,
4173 take first the least significant bits of the value
4174 and pack them starting at the least significant
4175 bits of the bytes. */
4176 shift
= next_offset
- int_bit_position (field
);
4178 /* Don't try to take a bunch of bits that cross
4179 the word boundary in the INTEGER_CST. We can
4180 only select bits from the LOW or HIGH part
4182 if (shift
< HOST_BITS_PER_WIDE_INT
4183 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4184 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4186 /* Now get the bits from the appropriate constant word. */
4187 if (shift
< HOST_BITS_PER_WIDE_INT
)
4188 value
= TREE_INT_CST_LOW (val
);
4191 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4192 value
= TREE_INT_CST_HIGH (val
);
4193 shift
-= HOST_BITS_PER_WIDE_INT
;
4196 /* Get the result. This works only when:
4197 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4198 byte
|= (((value
>> shift
)
4199 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4203 next_offset
+= this_time
;
4204 byte_buffer_in_use
= 1;
4209 if (byte_buffer_in_use
)
4211 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4215 if ((unsigned HOST_WIDE_INT
)total_bytes
< size
)
4216 assemble_zeros (size
- total_bytes
);
4219 /* This TREE_LIST contains any weak symbol declarations waiting
4221 static GTY(()) tree weak_decls
;
4223 /* Mark DECL as weak. */
4226 mark_weak (tree decl
)
4228 DECL_WEAK (decl
) = 1;
4230 if (DECL_RTL_SET_P (decl
)
4231 && MEM_P (DECL_RTL (decl
))
4232 && XEXP (DECL_RTL (decl
), 0)
4233 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
4234 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
4237 /* Merge weak status between NEWDECL and OLDDECL. */
4240 merge_weak (tree newdecl
, tree olddecl
)
4242 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
4244 if (DECL_WEAK (newdecl
) && SUPPORTS_WEAK
)
4247 /* We put the NEWDECL on the weak_decls list at some point
4248 and OLDDECL as well. Keep just OLDDECL on the list. */
4249 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
4250 if (TREE_VALUE (*pwd
) == newdecl
)
4252 *pwd
= TREE_CHAIN (*pwd
);
4259 if (DECL_WEAK (newdecl
))
4263 /* NEWDECL is weak, but OLDDECL is not. */
4265 /* If we already output the OLDDECL, we're in trouble; we can't
4266 go back and make it weak. This error cannot caught in
4267 declare_weak because the NEWDECL and OLDDECL was not yet
4268 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4269 if (TREE_ASM_WRITTEN (olddecl
))
4270 error ("weak declaration of %q+D must precede definition",
4273 /* If we've already generated rtl referencing OLDDECL, we may
4274 have done so in a way that will not function properly with
4276 else if (TREE_USED (olddecl
)
4277 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
4278 warning (0, "weak declaration of %q+D after first use results "
4279 "in unspecified behavior", newdecl
);
4283 /* We put the NEWDECL on the weak_decls list at some point.
4284 Replace it with the OLDDECL. */
4285 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
4286 if (TREE_VALUE (wd
) == newdecl
)
4288 TREE_VALUE (wd
) = olddecl
;
4291 /* We may not find the entry on the list. If NEWDECL is a
4292 weak alias, then we will have already called
4293 globalize_decl to remove the entry; in that case, we do
4294 not need to do anything. */
4297 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4298 mark_weak (olddecl
);
4301 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4302 weak. Just update NEWDECL to indicate that it's weak too. */
4303 mark_weak (newdecl
);
4306 /* Declare DECL to be a weak symbol. */
4309 declare_weak (tree decl
)
4311 if (! TREE_PUBLIC (decl
))
4312 error ("weak declaration of %q+D must be public", decl
);
4313 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
4314 error ("weak declaration of %q+D must precede definition", decl
);
4315 else if (SUPPORTS_WEAK
)
4317 if (! DECL_WEAK (decl
))
4318 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
4321 warning (0, "weak declaration of %q+D not supported", decl
);
4327 weak_finish_1 (tree decl
)
4329 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4330 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4333 if (! TREE_USED (decl
))
4336 #ifdef ASM_WEAKEN_DECL
4337 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
4339 #ifdef ASM_WEAKEN_LABEL
4340 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4342 #ifdef ASM_OUTPUT_WEAK_ALIAS
4344 static bool warn_once
= 0;
4347 warning (0, "only weak aliases are supported in this configuration");
4357 /* This TREE_LIST contains weakref targets. */
4359 static GTY(()) tree weakref_targets
;
4361 /* Forward declaration. */
4362 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
4364 /* Emit any pending weak declarations. */
4371 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
4373 tree alias_decl
= TREE_PURPOSE (t
);
4374 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
4376 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
4377 /* Remove alias_decl from the weak list, but leave entries for
4378 the target alone. */
4380 #ifndef ASM_OUTPUT_WEAKREF
4381 else if (! TREE_SYMBOL_REFERENCED (target
))
4383 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
4384 defined, otherwise we and weak_finish_1 would use a
4385 different macros. */
4386 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
4387 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
4389 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
4393 decl
= build_decl (TREE_CODE (alias_decl
), target
,
4394 TREE_TYPE (alias_decl
));
4396 DECL_EXTERNAL (decl
) = 1;
4397 TREE_PUBLIC (decl
) = 1;
4398 DECL_ARTIFICIAL (decl
) = 1;
4399 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
4400 TREE_USED (decl
) = 1;
4403 weak_finish_1 (decl
);
4412 /* Remove the alias and the target from the pending weak list
4413 so that we do not emit any .weak directives for the former,
4414 nor multiple .weak directives for the latter. */
4415 for (p
= &weak_decls
; (t2
= *p
) ; )
4417 if (TREE_VALUE (t2
) == alias_decl
4418 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
4419 *p
= TREE_CHAIN (t2
);
4421 p
= &TREE_CHAIN (t2
);
4424 /* Remove other weakrefs to the same target, to speed things up. */
4425 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
4427 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
4428 *p
= TREE_CHAIN (t2
);
4430 p
= &TREE_CHAIN (t2
);
4435 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
4437 tree decl
= TREE_VALUE (t
);
4439 weak_finish_1 (decl
);
4443 /* Emit the assembly bits to indicate that DECL is globally visible. */
4446 globalize_decl (tree decl
)
4448 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4450 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4451 if (DECL_WEAK (decl
))
4455 #ifdef ASM_WEAKEN_DECL
4456 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
4458 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4461 /* Remove this function from the pending weak list so that
4462 we do not emit multiple .weak directives for it. */
4463 for (p
= &weak_decls
; (t
= *p
) ; )
4465 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
4466 *p
= TREE_CHAIN (t
);
4468 p
= &TREE_CHAIN (t
);
4471 /* Remove weakrefs to the same target from the pending weakref
4472 list, for the same reason. */
4473 for (p
= &weakref_targets
; (t
= *p
) ; )
4475 if (DECL_ASSEMBLER_NAME (decl
)
4476 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
4477 *p
= TREE_CHAIN (t
);
4479 p
= &TREE_CHAIN (t
);
4484 #elif defined(ASM_MAKE_LABEL_LINKONCE)
4485 if (DECL_ONE_ONLY (decl
))
4486 ASM_MAKE_LABEL_LINKONCE (asm_out_file
, name
);
4489 targetm
.asm_out
.globalize_label (asm_out_file
, name
);
4492 /* We have to be able to tell cgraph about the needed-ness of the target
4493 of an alias. This requires that the decl have been defined. Aliases
4494 that precede their definition have to be queued for later processing. */
4496 typedef struct alias_pair
GTY(())
4502 /* Define gc'd vector type. */
4503 DEF_VEC_O(alias_pair
);
4504 DEF_VEC_ALLOC_O(alias_pair
,gc
);
4506 static GTY(()) VEC(alias_pair
,gc
) *alias_pairs
;
4508 /* Given an assembly name, find the decl it is associated with. At the
4509 same time, mark it needed for cgraph. */
4512 find_decl_and_mark_needed (tree decl
, tree target
)
4514 struct cgraph_node
*fnode
= NULL
;
4515 struct cgraph_varpool_node
*vnode
= NULL
;
4517 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4519 fnode
= cgraph_node_for_asm (target
);
4521 vnode
= cgraph_varpool_node_for_asm (target
);
4525 vnode
= cgraph_varpool_node_for_asm (target
);
4527 fnode
= cgraph_node_for_asm (target
);
4532 /* We can't mark function nodes as used after cgraph global info
4533 is finished. This wouldn't generally be necessary, but C++
4534 virtual table thunks are introduced late in the game and
4535 might seem like they need marking, although in fact they
4537 if (! cgraph_global_info_ready
)
4538 cgraph_mark_needed_node (fnode
);
4543 cgraph_varpool_mark_needed_node (vnode
);
4550 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
4551 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
4552 tree node is DECL to have the value of the tree node TARGET. */
4555 do_assemble_alias (tree decl
, tree target
)
4557 if (TREE_ASM_WRITTEN (decl
))
4560 TREE_ASM_WRITTEN (decl
) = 1;
4561 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
4563 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
4565 ultimate_transparent_alias_target (&target
);
4567 if (!TREE_SYMBOL_REFERENCED (target
))
4568 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
4570 #ifdef ASM_OUTPUT_WEAKREF
4571 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
4572 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
4573 IDENTIFIER_POINTER (target
));
4577 error ("%Jweakref is not supported in this configuration", decl
);
4584 #ifdef ASM_OUTPUT_DEF
4585 /* Make name accessible from other files, if appropriate. */
4587 if (TREE_PUBLIC (decl
))
4589 globalize_decl (decl
);
4590 maybe_assemble_visibility (decl
);
4593 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
4594 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4596 ASM_OUTPUT_DEF (asm_out_file
,
4597 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
4598 IDENTIFIER_POINTER (target
));
4600 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4605 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4606 # ifdef ASM_WEAKEN_DECL
4607 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
4609 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4611 /* Remove this function from the pending weak list so that
4612 we do not emit multiple .weak directives for it. */
4613 for (p
= &weak_decls
; (t
= *p
) ; )
4614 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
4615 *p
= TREE_CHAIN (t
);
4617 p
= &TREE_CHAIN (t
);
4619 /* Remove weakrefs to the same target from the pending weakref
4620 list, for the same reason. */
4621 for (p
= &weakref_targets
; (t
= *p
) ; )
4623 if (DECL_ASSEMBLER_NAME (decl
)
4624 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
4625 *p
= TREE_CHAIN (t
);
4627 p
= &TREE_CHAIN (t
);
4633 /* First pass of completing pending aliases. Make sure that cgraph knows
4634 which symbols will be required. */
4637 finish_aliases_1 (void)
4642 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
4646 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
4647 if (target_decl
== NULL
)
4649 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
4650 error ("%q+D aliased to undefined symbol %qs",
4651 p
->decl
, IDENTIFIER_POINTER (p
->target
));
4653 else if (DECL_EXTERNAL (target_decl
)
4654 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
4655 error ("%q+D aliased to external symbol %qs",
4656 p
->decl
, IDENTIFIER_POINTER (p
->target
));
4660 /* Second pass of completing pending aliases. Emit the actual assembly.
4661 This happens at the end of compilation and thus it is assured that the
4662 target symbol has been emitted. */
4665 finish_aliases_2 (void)
4670 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
4671 do_assemble_alias (p
->decl
, p
->target
);
4673 VEC_truncate (alias_pair
, alias_pairs
, 0);
4676 /* Emit an assembler directive to make the symbol for DECL an alias to
4677 the symbol for TARGET. */
4680 assemble_alias (tree decl
, tree target
)
4683 bool is_weakref
= false;
4685 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
4687 tree alias
= DECL_ASSEMBLER_NAME (decl
);
4691 ultimate_transparent_alias_target (&target
);
4693 if (alias
== target
)
4694 error ("weakref %q+D ultimately targets itself", decl
);
4697 #ifndef ASM_OUTPUT_WEAKREF
4698 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
4699 TREE_CHAIN (alias
) = target
;
4702 if (TREE_PUBLIC (decl
))
4703 error ("weakref %q+D must have static linkage", decl
);
4707 #if !defined (ASM_OUTPUT_DEF)
4708 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
4709 error ("%Jalias definitions not supported in this configuration", decl
);
4712 if (!DECL_WEAK (decl
))
4714 error ("%Jonly weak aliases are supported in this configuration", decl
);
4721 /* We must force creation of DECL_RTL for debug info generation, even though
4722 we don't use it here. */
4723 make_decl_rtl (decl
);
4724 TREE_USED (decl
) = 1;
4726 /* A quirk of the initial implementation of aliases required that the user
4727 add "extern" to all of them. Which is silly, but now historical. Do
4728 note that the symbol is in fact locally defined. */
4730 DECL_EXTERNAL (decl
) = 0;
4732 /* Allow aliases to aliases. */
4733 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4734 cgraph_node (decl
)->alias
= true;
4736 cgraph_varpool_node (decl
)->alias
= true;
4738 /* If the target has already been emitted, we don't have to queue the
4739 alias. This saves a tad o memory. */
4740 target_decl
= find_decl_and_mark_needed (decl
, target
);
4741 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
4742 do_assemble_alias (decl
, target
);
4745 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
4751 /* Emit an assembler directive to set symbol for DECL visibility to
4752 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4755 default_assemble_visibility (tree decl
, int vis
)
4757 static const char * const visibility_types
[] = {
4758 NULL
, "internal", "hidden", "protected"
4761 const char *name
, *type
;
4763 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4764 type
= visibility_types
[vis
];
4766 #ifdef HAVE_GAS_HIDDEN
4767 fprintf (asm_out_file
, "\t.%s\t", type
);
4768 assemble_name (asm_out_file
, name
);
4769 fprintf (asm_out_file
, "\n");
4771 warning (OPT_Wattributes
, "visibility attribute not supported "
4772 "in this configuration; ignored");
4776 /* A helper function to call assemble_visibility when needed for a decl. */
4779 maybe_assemble_visibility (tree decl
)
4781 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
4783 if (vis
!= VISIBILITY_DEFAULT
)
4784 targetm
.asm_out
.visibility (decl
, vis
);
4787 /* Returns 1 if the target configuration supports defining public symbols
4788 so that one of them will be chosen at link time instead of generating a
4789 multiply-defined symbol error, whether through the use of weak symbols or
4790 a target-specific mechanism for having duplicates discarded. */
4793 supports_one_only (void)
4795 if (SUPPORTS_ONE_ONLY
)
4797 return SUPPORTS_WEAK
;
4800 /* Set up DECL as a public symbol that can be defined in multiple
4801 translation units without generating a linker error. */
4804 make_decl_one_only (tree decl
)
4806 gcc_assert (TREE_CODE (decl
) == VAR_DECL
4807 || TREE_CODE (decl
) == FUNCTION_DECL
);
4809 TREE_PUBLIC (decl
) = 1;
4811 if (SUPPORTS_ONE_ONLY
)
4813 #ifdef MAKE_DECL_ONE_ONLY
4814 MAKE_DECL_ONE_ONLY (decl
);
4816 DECL_ONE_ONLY (decl
) = 1;
4818 else if (TREE_CODE (decl
) == VAR_DECL
4819 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
4820 DECL_COMMON (decl
) = 1;
4823 gcc_assert (SUPPORTS_WEAK
);
4824 DECL_WEAK (decl
) = 1;
4829 init_varasm_once (void)
4831 section_htab
= htab_create_ggc (31, section_entry_hash
,
4832 section_entry_eq
, NULL
);
4833 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
4834 const_desc_eq
, NULL
);
4836 const_alias_set
= new_alias_set ();
4838 #ifdef TEXT_SECTION_ASM_OP
4839 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
4840 TEXT_SECTION_ASM_OP
);
4843 #ifdef DATA_SECTION_ASM_OP
4844 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
4845 DATA_SECTION_ASM_OP
);
4848 #ifdef SDATA_SECTION_ASM_OP
4849 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
4850 SDATA_SECTION_ASM_OP
);
4853 #ifdef READONLY_DATA_SECTION_ASM_OP
4854 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
4855 READONLY_DATA_SECTION_ASM_OP
);
4858 #ifdef CTORS_SECTION_ASM_OP
4859 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
4860 CTORS_SECTION_ASM_OP
);
4863 #ifdef DTORS_SECTION_ASM_OP
4864 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
4865 DTORS_SECTION_ASM_OP
);
4868 #ifdef BSS_SECTION_ASM_OP
4869 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
4870 output_section_asm_op
,
4871 BSS_SECTION_ASM_OP
);
4874 #ifdef SBSS_SECTION_ASM_OP
4875 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
4876 output_section_asm_op
,
4877 SBSS_SECTION_ASM_OP
);
4880 targetm
.asm_out
.init_sections ();
4882 if (readonly_data_section
== NULL
)
4883 readonly_data_section
= text_section
;
4887 decl_default_tls_model (tree decl
)
4889 enum tls_model kind
;
4892 is_local
= targetm
.binds_local_p (decl
);
4896 kind
= TLS_MODEL_LOCAL_EXEC
;
4898 kind
= TLS_MODEL_INITIAL_EXEC
;
4901 /* Local dynamic is inefficient when we're not combining the
4902 parts of the address. */
4903 else if (optimize
&& is_local
)
4904 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
4906 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
4907 if (kind
< flag_tls_default
)
4908 kind
= flag_tls_default
;
4913 /* Select a set of attributes for section NAME based on the properties
4914 of DECL and whether or not RELOC indicates that DECL's initializer
4915 might contain runtime relocations.
4917 We make the section read-only and executable for a function decl,
4918 read-only for a const data decl, and writable for a non-const data decl. */
4921 default_section_type_flags (tree decl
, const char *name
, int reloc
)
4923 return default_section_type_flags_1 (decl
, name
, reloc
, flag_pic
);
4927 default_section_type_flags_1 (tree decl
, const char *name
, int reloc
,
4932 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
4933 flags
= SECTION_CODE
;
4934 else if (decl
&& decl_readonly_section_1 (decl
, reloc
, shlib
))
4936 else if (current_function_decl
4938 && cfun
->unlikely_text_section_name
4939 && strcmp (name
, cfun
->unlikely_text_section_name
) == 0)
4940 flags
= SECTION_CODE
;
4942 && (!current_function_decl
|| !cfun
)
4943 && strcmp (name
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
4944 flags
= SECTION_CODE
;
4946 flags
= SECTION_WRITE
;
4948 if (decl
&& DECL_ONE_ONLY (decl
))
4949 flags
|= SECTION_LINKONCE
;
4951 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
4952 flags
|= SECTION_TLS
| SECTION_WRITE
;
4954 if (strcmp (name
, ".bss") == 0
4955 || strncmp (name
, ".bss.", 5) == 0
4956 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
4957 || strcmp (name
, ".sbss") == 0
4958 || strncmp (name
, ".sbss.", 6) == 0
4959 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
4960 flags
|= SECTION_BSS
;
4962 if (strcmp (name
, ".tdata") == 0
4963 || strncmp (name
, ".tdata.", 7) == 0
4964 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
4965 flags
|= SECTION_TLS
;
4967 if (strcmp (name
, ".tbss") == 0
4968 || strncmp (name
, ".tbss.", 6) == 0
4969 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
4970 flags
|= SECTION_TLS
| SECTION_BSS
;
4972 /* These three sections have special ELF types. They are neither
4973 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4974 want to print a section type (@progbits or @nobits). If someone
4975 is silly enough to emit code or TLS variables to one of these
4976 sections, then don't handle them specially. */
4977 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
4978 && (strcmp (name
, ".init_array") == 0
4979 || strcmp (name
, ".fini_array") == 0
4980 || strcmp (name
, ".preinit_array") == 0))
4981 flags
|= SECTION_NOTYPE
;
4986 /* Output assembly to switch to section NAME with attribute FLAGS.
4987 Four variants for common object file formats. */
4990 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
4991 unsigned int flags ATTRIBUTE_UNUSED
,
4992 tree decl ATTRIBUTE_UNUSED
)
4994 /* Some object formats don't support named sections at all. The
4995 front-end should already have flagged this as an error. */
5000 default_elf_asm_named_section (const char *name
, unsigned int flags
,
5001 tree decl ATTRIBUTE_UNUSED
)
5003 char flagchars
[10], *f
= flagchars
;
5005 /* If we have already declared this section, we can use an
5006 abbreviated form to switch back to it -- unless this section is
5007 part of a COMDAT groups, in which case GAS requires the full
5008 declaration every time. */
5009 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5010 && (flags
& SECTION_DECLARED
))
5012 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
5016 if (!(flags
& SECTION_DEBUG
))
5018 if (flags
& SECTION_WRITE
)
5020 if (flags
& SECTION_CODE
)
5022 if (flags
& SECTION_SMALL
)
5024 if (flags
& SECTION_MERGE
)
5026 if (flags
& SECTION_STRINGS
)
5028 if (flags
& SECTION_TLS
)
5030 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5034 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
5036 if (!(flags
& SECTION_NOTYPE
))
5041 if (flags
& SECTION_BSS
)
5047 #ifdef ASM_COMMENT_START
5048 /* On platforms that use "@" as the assembly comment character,
5050 if (strcmp (ASM_COMMENT_START
, "@") == 0)
5053 fprintf (asm_out_file
, format
, type
);
5055 if (flags
& SECTION_ENTSIZE
)
5056 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
5057 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5058 fprintf (asm_out_file
, ",%s,comdat",
5059 lang_hooks
.decls
.comdat_group (decl
));
5062 putc ('\n', asm_out_file
);
5066 default_coff_asm_named_section (const char *name
, unsigned int flags
,
5067 tree decl ATTRIBUTE_UNUSED
)
5069 char flagchars
[8], *f
= flagchars
;
5071 if (flags
& SECTION_WRITE
)
5073 if (flags
& SECTION_CODE
)
5077 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
5081 default_pe_asm_named_section (const char *name
, unsigned int flags
,
5084 default_coff_asm_named_section (name
, flags
, decl
);
5086 if (flags
& SECTION_LINKONCE
)
5088 /* Functions may have been compiled at various levels of
5089 optimization so we can't use `same_size' here.
5090 Instead, have the linker pick one. */
5091 fprintf (asm_out_file
, "\t.linkonce %s\n",
5092 (flags
& SECTION_CODE
? "discard" : "same_size"));
5096 /* The lame default section selector. */
5099 default_select_section (tree decl
, int reloc
,
5100 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
5104 if (decl_readonly_section (decl
, reloc
))
5105 return readonly_data_section
;
5107 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5109 if (! ((flag_pic
&& reloc
)
5110 || !TREE_READONLY (decl
)
5111 || TREE_SIDE_EFFECTS (decl
)
5112 || !TREE_CONSTANT (decl
)))
5113 return readonly_data_section
;
5115 else if (TREE_CODE (decl
) == STRING_CST
)
5116 return readonly_data_section
;
5117 else if (! (flag_pic
&& reloc
))
5118 return readonly_data_section
;
5120 return data_section
;
5123 enum section_category
5124 categorize_decl_for_section (tree decl
, int reloc
, int shlib
)
5126 enum section_category ret
;
5128 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5130 else if (TREE_CODE (decl
) == STRING_CST
)
5132 if (flag_mudflap
) /* or !flag_merge_constants */
5133 return SECCAT_RODATA
;
5135 return SECCAT_RODATA_MERGE_STR
;
5137 else if (TREE_CODE (decl
) == VAR_DECL
)
5139 if (DECL_INITIAL (decl
) == NULL
5140 || DECL_INITIAL (decl
) == error_mark_node
5141 || (flag_zero_initialized_in_bss
5142 /* Leave constant zeroes in .rodata so they can be shared. */
5143 && !TREE_READONLY (decl
)
5144 && initializer_zerop (DECL_INITIAL (decl
))))
5146 else if (! TREE_READONLY (decl
)
5147 || TREE_SIDE_EFFECTS (decl
)
5148 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
5150 if (shlib
&& (reloc
& 2))
5151 ret
= SECCAT_DATA_REL
;
5152 else if (shlib
&& reloc
)
5153 ret
= SECCAT_DATA_REL_LOCAL
;
5157 else if (shlib
&& (reloc
& 2))
5158 ret
= SECCAT_DATA_REL_RO
;
5159 else if (shlib
&& reloc
)
5160 ret
= SECCAT_DATA_REL_RO_LOCAL
;
5161 else if (reloc
|| flag_merge_constants
< 2)
5162 /* C and C++ don't allow different variables to share the same
5163 location. -fmerge-all-constants allows even that (at the
5164 expense of not conforming). */
5165 ret
= SECCAT_RODATA
;
5166 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
5167 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
5169 ret
= SECCAT_RODATA_MERGE_CONST
;
5171 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5173 if ((shlib
&& reloc
)
5174 || TREE_SIDE_EFFECTS (decl
)
5175 || ! TREE_CONSTANT (decl
))
5178 ret
= SECCAT_RODATA
;
5181 ret
= SECCAT_RODATA
;
5183 /* There are no read-only thread-local sections. */
5184 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
5186 /* Note that this would be *just* SECCAT_BSS, except that there's
5187 no concept of a read-only thread-local-data section. */
5188 if (ret
== SECCAT_BSS
5189 || (flag_zero_initialized_in_bss
5190 && initializer_zerop (DECL_INITIAL (decl
))))
5196 /* If the target uses small data sections, select it. */
5197 else if (targetm
.in_small_data_p (decl
))
5199 if (ret
== SECCAT_BSS
)
5201 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
5202 ret
= SECCAT_SRODATA
;
5211 decl_readonly_section (tree decl
, int reloc
)
5213 return decl_readonly_section_1 (decl
, reloc
, flag_pic
);
5217 decl_readonly_section_1 (tree decl
, int reloc
, int shlib
)
5219 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5222 case SECCAT_RODATA_MERGE_STR
:
5223 case SECCAT_RODATA_MERGE_STR_INIT
:
5224 case SECCAT_RODATA_MERGE_CONST
:
5225 case SECCAT_SRODATA
:
5234 /* Select a section based on the above categorization. */
5237 default_elf_select_section (tree decl
, int reloc
,
5238 unsigned HOST_WIDE_INT align
)
5240 return default_elf_select_section_1 (decl
, reloc
, align
, flag_pic
);
5244 default_elf_select_section_1 (tree decl
, int reloc
,
5245 unsigned HOST_WIDE_INT align
, int shlib
)
5248 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5251 /* We're not supposed to be called on FUNCTION_DECLs. */
5254 return readonly_data_section
;
5255 case SECCAT_RODATA_MERGE_STR
:
5256 return mergeable_string_section (decl
, align
, 0);
5257 case SECCAT_RODATA_MERGE_STR_INIT
:
5258 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
5259 case SECCAT_RODATA_MERGE_CONST
:
5260 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
5261 case SECCAT_SRODATA
:
5265 return data_section
;
5266 case SECCAT_DATA_REL
:
5267 sname
= ".data.rel";
5269 case SECCAT_DATA_REL_LOCAL
:
5270 sname
= ".data.rel.local";
5272 case SECCAT_DATA_REL_RO
:
5273 sname
= ".data.rel.ro";
5275 case SECCAT_DATA_REL_RO_LOCAL
:
5276 sname
= ".data.rel.ro.local";
5301 return get_named_section (decl
, sname
, reloc
);
5304 /* Construct a unique section name based on the decl name and the
5305 categorization performed above. */
5308 default_unique_section (tree decl
, int reloc
)
5310 default_unique_section_1 (decl
, reloc
, flag_pic
);
5314 default_unique_section_1 (tree decl
, int reloc
, int shlib
)
5316 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
5317 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
5318 const char *prefix
, *name
;
5322 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5325 prefix
= one_only
? ".gnu.linkonce.t." : ".text.";
5328 case SECCAT_RODATA_MERGE_STR
:
5329 case SECCAT_RODATA_MERGE_STR_INIT
:
5330 case SECCAT_RODATA_MERGE_CONST
:
5331 prefix
= one_only
? ".gnu.linkonce.r." : ".rodata.";
5333 case SECCAT_SRODATA
:
5334 prefix
= one_only
? ".gnu.linkonce.s2." : ".sdata2.";
5337 prefix
= one_only
? ".gnu.linkonce.d." : ".data.";
5339 case SECCAT_DATA_REL
:
5340 prefix
= one_only
? ".gnu.linkonce.d.rel." : ".data.rel.";
5342 case SECCAT_DATA_REL_LOCAL
:
5343 prefix
= one_only
? ".gnu.linkonce.d.rel.local." : ".data.rel.local.";
5345 case SECCAT_DATA_REL_RO
:
5346 prefix
= one_only
? ".gnu.linkonce.d.rel.ro." : ".data.rel.ro.";
5348 case SECCAT_DATA_REL_RO_LOCAL
:
5349 prefix
= one_only
? ".gnu.linkonce.d.rel.ro.local."
5350 : ".data.rel.ro.local.";
5353 prefix
= one_only
? ".gnu.linkonce.s." : ".sdata.";
5356 prefix
= one_only
? ".gnu.linkonce.b." : ".bss.";
5359 prefix
= one_only
? ".gnu.linkonce.sb." : ".sbss.";
5362 prefix
= one_only
? ".gnu.linkonce.td." : ".tdata.";
5365 prefix
= one_only
? ".gnu.linkonce.tb." : ".tbss.";
5370 plen
= strlen (prefix
);
5372 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5373 name
= targetm
.strip_name_encoding (name
);
5374 nlen
= strlen (name
);
5376 string
= alloca (nlen
+ plen
+ 1);
5377 memcpy (string
, prefix
, plen
);
5378 memcpy (string
+ plen
, name
, nlen
+ 1);
5380 DECL_SECTION_NAME (decl
) = build_string (nlen
+ plen
, string
);
5384 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
5386 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
5389 switch (GET_CODE (x
))
5394 return data_section
;
5400 return readonly_data_section
;
5404 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
5405 unsigned HOST_WIDE_INT align
)
5407 /* ??? Handle small data here somehow. */
5410 switch (GET_CODE (x
))
5414 return get_named_section (NULL
, ".data.rel.ro", 3);
5417 return get_named_section (NULL
, ".data.rel.ro.local", 1);
5423 return mergeable_constant_section (mode
, align
, 0);
5426 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5429 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
5434 /* Careful not to prod global register variables. */
5437 symbol
= XEXP (rtl
, 0);
5438 if (GET_CODE (symbol
) != SYMBOL_REF
)
5442 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5443 flags
|= SYMBOL_FLAG_FUNCTION
;
5444 if (targetm
.binds_local_p (decl
))
5445 flags
|= SYMBOL_FLAG_LOCAL
;
5446 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
5447 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
5448 else if (targetm
.in_small_data_p (decl
))
5449 flags
|= SYMBOL_FLAG_SMALL
;
5450 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5451 being PUBLIC, the thing *must* be defined in this translation unit.
5452 Prevent this buglet from being propagated into rtl code as well. */
5453 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
5454 flags
|= SYMBOL_FLAG_EXTERNAL
;
5456 SYMBOL_REF_FLAGS (symbol
) = flags
;
5459 /* By default, we do nothing for encode_section_info, so we need not
5460 do anything but discard the '*' marker. */
5463 default_strip_name_encoding (const char *str
)
5465 return str
+ (*str
== '*');
5468 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5469 wrt cross-module name binding. */
5472 default_binds_local_p (tree exp
)
5474 return default_binds_local_p_1 (exp
, flag_shlib
);
5478 default_binds_local_p_1 (tree exp
, int shlib
)
5482 /* A non-decl is an entry in the constant pool. */
5485 /* Weakrefs may not bind locally, even though the weakref itself is
5486 always static and therefore local. */
5487 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
5489 /* Static variables are always local. */
5490 else if (! TREE_PUBLIC (exp
))
5492 /* A variable is local if the user has said explicitly that it will
5494 else if (DECL_VISIBILITY_SPECIFIED (exp
)
5495 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
5497 /* Variables defined outside this object might not be local. */
5498 else if (DECL_EXTERNAL (exp
))
5500 /* If defined in this object and visibility is not default, must be
5502 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
5504 /* Default visibility weak data can be overridden by a strong symbol
5505 in another module and so are not local. */
5506 else if (DECL_WEAK (exp
))
5508 /* If PIC, then assume that any global name can be overridden by
5509 symbols resolved from other modules. */
5512 /* Uninitialized COMMON variable may be unified with symbols
5513 resolved from other modules. */
5514 else if (DECL_COMMON (exp
)
5515 && (DECL_INITIAL (exp
) == NULL
5516 || DECL_INITIAL (exp
) == error_mark_node
))
5518 /* Otherwise we're left with initialized (or non-common) global data
5519 which is of necessity defined locally. */
5526 /* Determine whether or not a pointer mode is valid. Assume defaults
5527 of ptr_mode or Pmode - can be overridden. */
5529 default_valid_pointer_mode (enum machine_mode mode
)
5531 return (mode
== ptr_mode
|| mode
== Pmode
);
5534 /* Default function to output code that will globalize a label. A
5535 target must define GLOBAL_ASM_OP or provide its own function to
5536 globalize a label. */
5537 #ifdef GLOBAL_ASM_OP
5539 default_globalize_label (FILE * stream
, const char *name
)
5541 fputs (GLOBAL_ASM_OP
, stream
);
5542 assemble_name (stream
, name
);
5543 putc ('\n', stream
);
5545 #endif /* GLOBAL_ASM_OP */
5547 /* Default function to output a label for unwind information. The
5548 default is to do nothing. A target that needs nonlocal labels for
5549 unwind information must provide its own function to do this. */
5551 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
5552 tree decl ATTRIBUTE_UNUSED
,
5553 int for_eh ATTRIBUTE_UNUSED
,
5554 int empty ATTRIBUTE_UNUSED
)
5558 /* Default function to output a label to divide up the exception table.
5559 The default is to do nothing. A target that needs/wants to divide
5560 up the table must provide it's own function to do this. */
5562 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
5566 /* This is how to output an internal numbered label where PREFIX is
5567 the class of label and LABELNO is the number within the class. */
5570 default_internal_label (FILE *stream
, const char *prefix
,
5571 unsigned long labelno
)
5573 char *const buf
= alloca (40 + strlen (prefix
));
5574 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
5575 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
5578 /* This is the default behavior at the beginning of a file. It's
5579 controlled by two other target-hook toggles. */
5581 default_file_start (void)
5583 if (targetm
.file_start_app_off
&& !flag_verbose_asm
)
5584 fputs (ASM_APP_OFF
, asm_out_file
);
5586 if (targetm
.file_start_file_directive
)
5587 output_file_directive (asm_out_file
, main_input_filename
);
5590 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5591 which emits a special section directive used to indicate whether or
5592 not this object file needs an executable stack. This is primarily
5593 a GNU extension to ELF but could be used on other targets. */
5595 int trampolines_created
;
5598 file_end_indicate_exec_stack (void)
5600 unsigned int flags
= SECTION_DEBUG
;
5601 if (trampolines_created
)
5602 flags
|= SECTION_CODE
;
5604 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
5607 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
5608 a get_unnamed_section callback. */
5611 output_section_asm_op (const void *directive
)
5613 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
5616 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
5617 the current section is NEW_SECTION. */
5620 switch_to_section (section
*new_section
)
5622 if (in_section
== new_section
)
5625 if (new_section
->common
.flags
& SECTION_FORGET
)
5628 in_section
= new_section
;
5630 if (new_section
->common
.flags
& SECTION_NAMED
)
5633 && !cfun
->unlikely_text_section_name
5634 && strcmp (new_section
->named
.name
,
5635 UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
5636 cfun
->unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
5638 targetm
.asm_out
.named_section (new_section
->named
.name
,
5639 new_section
->named
.common
.flags
,
5640 new_section
->named
.decl
);
5643 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
5645 new_section
->common
.flags
|= SECTION_DECLARED
;
5648 #include "gt-varasm.h"