1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010, 2011, 2012 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
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 COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
42 #include "diagnostic-core.h"
45 #include "langhooks.h"
49 #include "common/common-target.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
53 #include "pointer-set.h"
55 #ifdef XCOFF_DEBUGGING_INFO
56 #include "xcoffout.h" /* Needed for external data
57 declarations for e.g. AIX 4.x. */
60 /* The (assembler) name of the first globally-visible object output. */
61 extern GTY(()) const char *first_global_object_name
;
62 extern GTY(()) const char *weak_global_object_name
;
64 const char *first_global_object_name
;
65 const char *weak_global_object_name
;
68 struct constant_descriptor_rtx
;
69 struct rtx_constant_pool
;
71 #define n_deferred_constants (crtl->varasm.deferred_constants)
73 /* Number for making the label on the next
74 constant that is stored in memory. */
76 static GTY(()) int const_labelno
;
78 /* Carry information from ASM_DECLARE_OBJECT_NAME
79 to ASM_FINISH_DECLARE_OBJECT. */
81 int size_directive_output
;
83 /* The last decl for which assemble_variable was called,
84 if it did ASM_DECLARE_OBJECT_NAME.
85 If the last call to assemble_variable didn't do that,
88 tree last_assemble_variable_decl
;
90 /* The following global variable indicates if the first basic block
91 in a function belongs to the cold partition or not. */
93 bool first_function_block_is_cold
;
95 /* We give all constants their own alias set. Perhaps redundant with
96 MEM_READONLY_P, but pre-dates it. */
98 static alias_set_type const_alias_set
;
100 /* Whether we saw any functions with no_split_stack. */
102 static bool saw_no_split_stack
;
104 static const char *strip_reg_name (const char *);
105 static int contains_pointers_p (tree
);
106 #ifdef ASM_OUTPUT_EXTERNAL
107 static bool incorporeal_function_p (tree
);
109 static void decode_addr_const (tree
, struct addr_const
*);
110 static hashval_t
const_desc_hash (const void *);
111 static int const_desc_eq (const void *, const void *);
112 static hashval_t
const_hash_1 (const tree
);
113 static int compare_constant (const tree
, const tree
);
114 static tree
copy_constant (tree
);
115 static void output_constant_def_contents (rtx
);
116 static void output_addressed_constants (tree
);
117 static unsigned HOST_WIDE_INT
array_size_for_constructor (tree
);
118 static unsigned min_align (unsigned, unsigned);
119 static void globalize_decl (tree
);
120 static bool decl_readonly_section_1 (enum section_category
);
121 #ifdef BSS_SECTION_ASM_OP
122 #ifdef ASM_OUTPUT_ALIGNED_BSS
123 static void asm_output_aligned_bss (FILE *, tree
, const char *,
124 unsigned HOST_WIDE_INT
, int)
127 #endif /* BSS_SECTION_ASM_OP */
128 static void mark_weak (tree
);
129 static void output_constant_pool (const char *, tree
);
131 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
132 section
*text_section
;
133 section
*data_section
;
134 section
*readonly_data_section
;
135 section
*sdata_section
;
136 section
*ctors_section
;
137 section
*dtors_section
;
138 section
*bss_section
;
139 section
*sbss_section
;
141 /* Various forms of common section. All are guaranteed to be nonnull. */
142 section
*tls_comm_section
;
143 section
*comm_section
;
144 section
*lcomm_section
;
146 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
148 section
*bss_noswitch_section
;
150 /* The section that holds the main exception table, when known. The section
151 is set either by the target's init_sections hook or by the first call to
152 switch_to_exception_section. */
153 section
*exception_section
;
155 /* The section that holds the DWARF2 frame unwind information, when known.
156 The section is set either by the target's init_sections hook or by the
157 first call to switch_to_eh_frame_section. */
158 section
*eh_frame_section
;
160 /* asm_out_file's current section. This is NULL if no section has yet
161 been selected or if we lose track of what the current section is. */
164 /* True if code for the current function is currently being directed
165 at the cold section. */
166 bool in_cold_section_p
;
168 /* A linked list of all the unnamed sections. */
169 static GTY(()) section
*unnamed_sections
;
171 /* Return a nonzero value if DECL has a section attribute. */
172 #define IN_NAMED_SECTION(DECL) \
173 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
174 && DECL_SECTION_NAME (DECL) != NULL_TREE)
176 /* Hash table of named sections. */
177 static GTY((param_is (section
))) htab_t section_htab
;
179 /* A table of object_blocks, indexed by section. */
180 static GTY((param_is (struct object_block
))) htab_t object_block_htab
;
182 /* The next number to use for internal anchor labels. */
183 static GTY(()) int anchor_labelno
;
185 /* A pool of constants that can be shared between functions. */
186 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
188 /* Helper routines for maintaining section_htab. */
191 section_entry_eq (const void *p1
, const void *p2
)
193 const section
*old
= (const section
*) p1
;
194 const char *new_name
= (const char *) p2
;
196 return strcmp (old
->named
.name
, new_name
) == 0;
200 section_entry_hash (const void *p
)
202 const section
*old
= (const section
*) p
;
203 return htab_hash_string (old
->named
.name
);
206 /* Return a hash value for section SECT. */
209 hash_section (section
*sect
)
211 if (sect
->common
.flags
& SECTION_NAMED
)
212 return htab_hash_string (sect
->named
.name
);
213 return sect
->common
.flags
;
216 /* Helper routines for maintaining object_block_htab. */
219 object_block_entry_eq (const void *p1
, const void *p2
)
221 const struct object_block
*old
= (const struct object_block
*) p1
;
222 const section
*new_section
= (const section
*) p2
;
224 return old
->sect
== new_section
;
228 object_block_entry_hash (const void *p
)
230 const struct object_block
*old
= (const struct object_block
*) p
;
231 return hash_section (old
->sect
);
234 /* Return a new unnamed section with the given fields. */
237 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
242 sect
= ggc_alloc_section ();
243 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
244 sect
->unnamed
.callback
= callback
;
245 sect
->unnamed
.data
= data
;
246 sect
->unnamed
.next
= unnamed_sections
;
248 unnamed_sections
= sect
;
252 /* Return a SECTION_NOSWITCH section with the given fields. */
255 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
259 sect
= ggc_alloc_section ();
260 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
261 sect
->noswitch
.callback
= callback
;
266 /* Return the named section structure associated with NAME. Create
267 a new section with the given fields if no such structure exists. */
270 get_section (const char *name
, unsigned int flags
, tree decl
)
272 section
*sect
, **slot
;
275 htab_find_slot_with_hash (section_htab
, name
,
276 htab_hash_string (name
), INSERT
);
277 flags
|= SECTION_NAMED
;
280 sect
= ggc_alloc_section ();
281 sect
->named
.common
.flags
= flags
;
282 sect
->named
.name
= ggc_strdup (name
);
283 sect
->named
.decl
= decl
;
289 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
290 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
292 /* It is fine if one of the section flags is
293 SECTION_WRITE | SECTION_RELRO and the other has none of these
294 flags (i.e. read-only) in named sections and either the
295 section hasn't been declared yet or has been declared as writable.
296 In that case just make sure the resulting flags are
297 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
299 if (((sect
->common
.flags
^ flags
) & (SECTION_WRITE
| SECTION_RELRO
))
300 == (SECTION_WRITE
| SECTION_RELRO
)
301 && (sect
->common
.flags
302 & ~(SECTION_DECLARED
| SECTION_WRITE
| SECTION_RELRO
))
303 == (flags
& ~(SECTION_WRITE
| SECTION_RELRO
))
304 && ((sect
->common
.flags
& SECTION_DECLARED
) == 0
305 || (sect
->common
.flags
& SECTION_WRITE
)))
307 sect
->common
.flags
|= (SECTION_WRITE
| SECTION_RELRO
);
310 /* Sanity check user variables for flag changes. */
312 decl
= sect
->named
.decl
;
314 if (sect
->named
.decl
== NULL
)
315 error ("%+D causes a section type conflict", decl
);
318 error ("%+D causes a section type conflict with %D",
319 decl
, sect
->named
.decl
);
320 if (decl
!= sect
->named
.decl
)
321 inform (DECL_SOURCE_LOCATION (sect
->named
.decl
),
322 "%qD was declared here", sect
->named
.decl
);
324 /* Make sure we don't error about one section multiple times. */
325 sect
->common
.flags
|= SECTION_OVERRIDE
;
331 /* Return true if the current compilation mode benefits from having
332 objects grouped into blocks. */
335 use_object_blocks_p (void)
337 return flag_section_anchors
;
340 /* Return the object_block structure for section SECT. Create a new
341 structure if we haven't created one already. Return null if SECT
344 static struct object_block
*
345 get_block_for_section (section
*sect
)
347 struct object_block
*block
;
353 slot
= htab_find_slot_with_hash (object_block_htab
, sect
,
354 hash_section (sect
), INSERT
);
355 block
= (struct object_block
*) *slot
;
358 block
= ggc_alloc_cleared_object_block ();
365 /* Create a symbol with label LABEL and place it at byte offset
366 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
367 is not yet known. LABEL must be a garbage-collected string. */
370 create_block_symbol (const char *label
, struct object_block
*block
,
371 HOST_WIDE_INT offset
)
376 /* Create the extended SYMBOL_REF. */
377 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
378 symbol
= ggc_alloc_zone_rtx_def (size
, &rtl_zone
);
380 /* Initialize the normal SYMBOL_REF fields. */
381 memset (symbol
, 0, size
);
382 PUT_CODE (symbol
, SYMBOL_REF
);
383 PUT_MODE (symbol
, Pmode
);
384 XSTR (symbol
, 0) = label
;
385 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
387 /* Initialize the block_symbol stuff. */
388 SYMBOL_REF_BLOCK (symbol
) = block
;
389 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
394 /* Return a section with a particular name and with whatever SECTION_*
395 flags section_type_flags deems appropriate. The name of the section
396 is taken from NAME if nonnull, otherwise it is taken from DECL's
397 DECL_SECTION_NAME. DECL is the decl associated with the section
398 (see the section comment for details) and RELOC is as for
399 section_type_flags. */
402 get_named_section (tree decl
, const char *name
, int reloc
)
406 gcc_assert (!decl
|| DECL_P (decl
));
408 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
410 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
412 return get_section (name
, flags
, decl
);
415 /* If required, set DECL_SECTION_NAME to a unique name. */
418 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
419 int flag_function_or_data_sections
)
421 if (DECL_SECTION_NAME (decl
) == NULL_TREE
422 && targetm_common
.have_named_sections
423 && (flag_function_or_data_sections
424 || DECL_ONE_ONLY (decl
)))
426 targetm
.asm_out
.unique_section (decl
, reloc
);
427 DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
) = true;
431 #ifdef BSS_SECTION_ASM_OP
433 #ifdef ASM_OUTPUT_ALIGNED_BSS
435 /* Utility function for targets to use in implementing
436 ASM_OUTPUT_ALIGNED_BSS.
437 ??? It is believed that this function will work in most cases so such
438 support is localized here. */
441 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
442 const char *name
, unsigned HOST_WIDE_INT size
,
445 switch_to_section (bss_section
);
446 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
447 #ifdef ASM_DECLARE_OBJECT_NAME
448 last_assemble_variable_decl
= decl
;
449 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
451 /* Standard thing is just output label for the object. */
452 ASM_OUTPUT_LABEL (file
, name
);
453 #endif /* ASM_DECLARE_OBJECT_NAME */
454 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
459 #endif /* BSS_SECTION_ASM_OP */
461 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
462 /* Return the hot section for function DECL. Return text_section for
466 hot_function_section (tree decl
)
468 if (decl
!= NULL_TREE
469 && DECL_SECTION_NAME (decl
) != NULL_TREE
470 && targetm_common
.have_named_sections
)
471 return get_named_section (decl
, NULL
, 0);
477 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
480 When DECL_SECTION_NAME is non-NULL and it is implicit section and
481 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
482 concatenate the name with NAMED_SECTION_SUFFIX.
483 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
486 get_named_text_section (tree decl
,
487 const char *text_section_name
,
488 const char *named_section_suffix
)
490 if (decl
&& DECL_SECTION_NAME (decl
))
492 if (named_section_suffix
)
494 tree dsn
= DECL_SECTION_NAME (decl
);
495 const char *stripped_name
;
498 name
= (char *) alloca (TREE_STRING_LENGTH (dsn
) + 1);
499 memcpy (name
, TREE_STRING_POINTER (dsn
),
500 TREE_STRING_LENGTH (dsn
) + 1);
502 stripped_name
= targetm
.strip_name_encoding (name
);
504 buffer
= ACONCAT ((stripped_name
, named_section_suffix
, NULL
));
505 return get_named_section (decl
, buffer
, 0);
507 else if (DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
))
511 /* Do not try to split gnu_linkonce functions. This gets somewhat
513 if (DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
)
515 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
516 name
= targetm
.strip_name_encoding (name
);
517 return get_named_section (decl
, ACONCAT ((text_section_name
, ".",
523 return get_named_section (decl
, text_section_name
, 0);
526 /* Choose named function section based on its frequency. */
529 default_function_section (tree decl
, enum node_frequency freq
,
530 bool startup
, bool exit
)
532 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
533 /* Old GNU linkers have buggy --gc-section support, which sometimes
534 results in .gcc_except_table* sections being garbage collected. */
536 && DECL_SECTION_NAME (decl
)
537 && DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
))
541 if (!flag_reorder_functions
542 || !targetm_common
.have_named_sections
)
544 /* Startup code should go to startup subsection unless it is
545 unlikely executed (this happens especially with function splitting
546 where we can split away unnecessary parts of static constructors. */
547 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
548 return get_named_text_section (decl
, ".text.startup", NULL
);
550 /* Similarly for exit. */
551 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
552 return get_named_text_section (decl
, ".text.exit", NULL
);
554 /* Group cold functions together, similarly for hot code. */
557 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
558 return get_named_text_section (decl
, ".text.unlikely", NULL
);
559 case NODE_FREQUENCY_HOT
:
560 return get_named_text_section (decl
, ".text.hot", NULL
);
566 /* Return the section for function DECL.
568 If DECL is NULL_TREE, return the text section. We can be passed
569 NULL_TREE under some circumstances by dbxout.c at least.
571 If FORCE_COLD is true, return cold function section ignoring
572 the frequency info of cgraph_node. */
575 function_section_1 (tree decl
, bool force_cold
)
577 section
*section
= NULL
;
578 enum node_frequency freq
= NODE_FREQUENCY_NORMAL
;
579 bool startup
= false, exit
= false;
583 struct cgraph_node
*node
= cgraph_get_node (decl
);
587 freq
= node
->frequency
;
588 startup
= node
->only_called_at_startup
;
589 exit
= node
->only_called_at_exit
;
593 freq
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
595 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
596 if (decl
!= NULL_TREE
597 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
599 if (targetm
.asm_out
.function_section
)
600 section
= targetm
.asm_out
.function_section (decl
, freq
,
604 return get_named_section (decl
, NULL
, 0);
607 return targetm
.asm_out
.select_section
608 (decl
, freq
== NODE_FREQUENCY_UNLIKELY_EXECUTED
,
611 if (targetm
.asm_out
.function_section
)
612 section
= targetm
.asm_out
.function_section (decl
, freq
, startup
, exit
);
615 return hot_function_section (decl
);
619 /* Return the section for function DECL.
621 If DECL is NULL_TREE, return the text section. We can be passed
622 NULL_TREE under some circumstances by dbxout.c at least. */
625 function_section (tree decl
)
627 /* Handle cases where function splitting code decides
628 to put function entry point into unlikely executed section
629 despite the fact that the function itself is not cold
630 (i.e. it is called rarely but contains a hot loop that is
631 better to live in hot subsection for the code locality). */
632 return function_section_1 (decl
,
633 first_function_block_is_cold
);
636 /* Return the section for the current function, take IN_COLD_SECTION_P
640 current_function_section (void)
642 return function_section_1 (current_function_decl
, in_cold_section_p
);
645 /* Tell assembler to switch to unlikely-to-be-executed text section. */
648 unlikely_text_section (void)
650 return function_section_1 (current_function_decl
, true);
653 /* When called within a function context, return true if the function
654 has been assigned a cold text section and if SECT is that section.
655 When called outside a function context, return true if SECT is the
656 default cold section. */
659 unlikely_text_section_p (section
*sect
)
661 return sect
== function_section_1 (current_function_decl
, true);
664 /* Return the read-only data section associated with function DECL. */
667 default_function_rodata_section (tree decl
)
669 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
671 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
673 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
679 dot
= strchr (name
+ 1, '.');
682 len
= strlen (dot
) + 8;
683 rname
= (char *) alloca (len
);
685 strcpy (rname
, ".rodata");
687 return get_section (rname
, SECTION_LINKONCE
, decl
);
689 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
690 else if (DECL_ONE_ONLY (decl
)
691 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
693 size_t len
= strlen (name
) + 1;
694 char *rname
= (char *) alloca (len
);
696 memcpy (rname
, name
, len
);
698 return get_section (rname
, SECTION_LINKONCE
, decl
);
700 /* For .text.foo we want to use .rodata.foo. */
701 else if (flag_function_sections
&& flag_data_sections
702 && strncmp (name
, ".text.", 6) == 0)
704 size_t len
= strlen (name
) + 1;
705 char *rname
= (char *) alloca (len
+ 2);
707 memcpy (rname
, ".rodata", 7);
708 memcpy (rname
+ 7, name
+ 5, len
- 5);
709 return get_section (rname
, 0, decl
);
713 return readonly_data_section
;
716 /* Return the read-only data section associated with function DECL
717 for targets where that section should be always the single
718 readonly data section. */
721 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
723 return readonly_data_section
;
726 /* Return the section to use for string merging. */
729 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
730 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
731 unsigned int flags ATTRIBUTE_UNUSED
)
735 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
736 && TREE_CODE (decl
) == STRING_CST
737 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
739 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
740 && TREE_STRING_LENGTH (decl
) >= len
)
742 enum machine_mode mode
;
743 unsigned int modesize
;
747 const char *prefix
= targetm
.asm_out
.mergeable_rodata_prefix
;
748 char *name
= (char *) alloca (strlen (prefix
) + 30);
750 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
751 modesize
= GET_MODE_BITSIZE (mode
);
752 if (modesize
>= 8 && modesize
<= 256
753 && (modesize
& (modesize
- 1)) == 0)
755 if (align
< modesize
)
758 str
= TREE_STRING_POINTER (decl
);
759 unit
= GET_MODE_SIZE (mode
);
761 /* Check for embedded NUL characters. */
762 for (i
= 0; i
< len
; i
+= unit
)
764 for (j
= 0; j
< unit
; j
++)
765 if (str
[i
+ j
] != '\0')
772 sprintf (name
, "%s.str%d.%d", prefix
,
773 modesize
/ 8, (int) (align
/ 8));
774 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
775 return get_section (name
, flags
, NULL
);
780 return readonly_data_section
;
783 /* Return the section to use for constant merging. */
786 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
787 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
788 unsigned int flags ATTRIBUTE_UNUSED
)
790 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
792 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
798 && (align
& (align
- 1)) == 0)
800 const char *prefix
= targetm
.asm_out
.mergeable_rodata_prefix
;
801 char *name
= (char *) alloca (strlen (prefix
) + 30);
803 sprintf (name
, "%s.cst%d", prefix
, (int) (align
/ 8));
804 flags
|= (align
/ 8) | SECTION_MERGE
;
805 return get_section (name
, flags
, NULL
);
807 return readonly_data_section
;
810 /* Given NAME, a putative register name, discard any customary prefixes. */
813 strip_reg_name (const char *name
)
815 #ifdef REGISTER_PREFIX
816 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
817 name
+= strlen (REGISTER_PREFIX
);
819 if (name
[0] == '%' || name
[0] == '#')
824 /* The user has asked for a DECL to have a particular name. Set (or
825 change) it in such a way that we don't prefix an underscore to
828 set_user_assembler_name (tree decl
, const char *name
)
830 char *starred
= (char *) alloca (strlen (name
) + 2);
832 strcpy (starred
+ 1, name
);
833 change_decl_assembler_name (decl
, get_identifier (starred
));
834 SET_DECL_RTL (decl
, NULL_RTX
);
837 /* Decode an `asm' spec for a declaration as a register name.
838 Return the register number, or -1 if nothing specified,
839 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
840 or -3 if ASMSPEC is `cc' and is not recognized,
841 or -4 if ASMSPEC is `memory' and is not recognized.
842 Accept an exact spelling or a decimal number.
843 Prefixes such as % are optional. */
846 decode_reg_name_and_count (const char *asmspec
, int *pnregs
)
848 /* Presume just one register is clobbered. */
855 /* Get rid of confusing prefixes. */
856 asmspec
= strip_reg_name (asmspec
);
858 /* Allow a decimal number as a "register name". */
859 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
860 if (! ISDIGIT (asmspec
[i
]))
862 if (asmspec
[0] != 0 && i
< 0)
865 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
871 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
873 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
876 #ifdef OVERLAPPING_REGISTER_NAMES
880 const char *const name
;
883 } table
[] = OVERLAPPING_REGISTER_NAMES
;
885 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
887 && ! strcmp (asmspec
, table
[i
].name
))
889 *pnregs
= table
[i
].nregs
;
890 return table
[i
].number
;
893 #endif /* OVERLAPPING_REGISTER_NAMES */
895 #ifdef ADDITIONAL_REGISTER_NAMES
897 static const struct { const char *const name
; const int number
; } table
[]
898 = ADDITIONAL_REGISTER_NAMES
;
900 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
902 && ! strcmp (asmspec
, table
[i
].name
))
903 return table
[i
].number
;
905 #endif /* ADDITIONAL_REGISTER_NAMES */
907 if (!strcmp (asmspec
, "memory"))
910 if (!strcmp (asmspec
, "cc"))
920 decode_reg_name (const char *name
)
923 return decode_reg_name_and_count (name
, &count
);
927 /* Return true if DECL's initializer is suitable for a BSS section. */
930 bss_initializer_p (const_tree decl
)
932 return (DECL_INITIAL (decl
) == NULL
933 || DECL_INITIAL (decl
) == error_mark_node
934 || (flag_zero_initialized_in_bss
935 /* Leave constant zeroes in .rodata so they
937 && !TREE_READONLY (decl
)
938 && initializer_zerop (DECL_INITIAL (decl
))));
941 /* Compute the alignment of variable specified by DECL.
942 DONT_OUTPUT_DATA is from assemble_variable. */
945 align_variable (tree decl
, bool dont_output_data
)
947 unsigned int align
= DECL_ALIGN (decl
);
949 /* In the case for initialing an array whose length isn't specified,
950 where we have not yet been able to do the layout,
951 figure out the proper alignment now. */
952 if (dont_output_data
&& DECL_SIZE (decl
) == 0
953 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
954 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
956 /* Some object file formats have a maximum alignment which they support.
957 In particular, a.out format supports a maximum alignment of 4. */
958 if (align
> MAX_OFILE_ALIGNMENT
)
960 warning (0, "alignment of %q+D is greater than maximum object "
961 "file alignment. Using %d", decl
,
962 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
963 align
= MAX_OFILE_ALIGNMENT
;
966 /* On some machines, it is good to increase alignment sometimes. */
967 if (! DECL_USER_ALIGN (decl
))
969 #ifdef DATA_ALIGNMENT
970 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
971 /* Don't increase alignment too much for TLS variables - TLS space
973 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
976 #ifdef CONSTANT_ALIGNMENT
977 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
979 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
981 /* Don't increase alignment too much for TLS variables - TLS space
983 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
989 /* Reset the alignment in case we have made it tighter, so we can benefit
990 from it in get_pointer_alignment. */
991 DECL_ALIGN (decl
) = align
;
994 /* Return the section into which the given VAR_DECL or CONST_DECL
995 should be placed. PREFER_NOSWITCH_P is true if a noswitch
996 section should be used wherever possible. */
999 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1001 addr_space_t as
= ADDR_SPACE_GENERIC
;
1004 if (TREE_TYPE (decl
) != error_mark_node
)
1005 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1007 if (DECL_COMMON (decl
))
1009 /* If the decl has been given an explicit section name, or it resides
1010 in a non-generic address space, then it isn't common, and shouldn't
1011 be handled as such. */
1012 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1013 && ADDR_SPACE_GENERIC_P (as
));
1014 if (DECL_THREAD_LOCAL_P (decl
))
1015 return tls_comm_section
;
1016 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1017 return comm_section
;
1020 if (DECL_INITIAL (decl
) == error_mark_node
)
1021 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1022 else if (DECL_INITIAL (decl
))
1023 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1027 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1028 if (IN_NAMED_SECTION (decl
))
1029 return get_named_section (decl
, NULL
, reloc
);
1031 if (ADDR_SPACE_GENERIC_P (as
)
1032 && !DECL_THREAD_LOCAL_P (decl
)
1033 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1034 && bss_initializer_p (decl
))
1036 if (!TREE_PUBLIC (decl
))
1037 return lcomm_section
;
1038 if (bss_noswitch_section
)
1039 return bss_noswitch_section
;
1042 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
1045 /* Return the block into which object_block DECL should be placed. */
1047 static struct object_block
*
1048 get_block_for_decl (tree decl
)
1052 if (TREE_CODE (decl
) == VAR_DECL
)
1054 /* The object must be defined in this translation unit. */
1055 if (DECL_EXTERNAL (decl
))
1058 /* There's no point using object blocks for something that is
1059 isolated by definition. */
1060 if (DECL_ONE_ONLY (decl
))
1064 /* We can only calculate block offsets if the decl has a known
1066 if (DECL_SIZE_UNIT (decl
) == NULL
)
1068 if (!host_integerp (DECL_SIZE_UNIT (decl
), 1))
1071 /* Find out which section should contain DECL. We cannot put it into
1072 an object block if it requires a standalone definition. */
1073 if (TREE_CODE (decl
) == VAR_DECL
)
1074 align_variable (decl
, 0);
1075 sect
= get_variable_section (decl
, true);
1076 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1079 return get_block_for_section (sect
);
1082 /* Make sure block symbol SYMBOL is in block BLOCK. */
1085 change_symbol_block (rtx symbol
, struct object_block
*block
)
1087 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1089 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1090 SYMBOL_REF_BLOCK (symbol
) = block
;
1094 /* Return true if it is possible to put DECL in an object_block. */
1097 use_blocks_for_decl_p (tree decl
)
1099 /* Only data DECLs can be placed into object blocks. */
1100 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
1103 /* Detect decls created by dw2_force_const_mem. Such decls are
1104 special because DECL_INITIAL doesn't specify the decl's true value.
1105 dw2_output_indirect_constants will instead call assemble_variable
1106 with dont_output_data set to 1 and then print the contents itself. */
1107 if (DECL_INITIAL (decl
) == decl
)
1110 /* If this decl is an alias, then we don't want to emit a
1112 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl
)))
1118 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1119 have static storage duration. In other words, it should not be an
1120 automatic variable, including PARM_DECLs.
1122 There is, however, one exception: this function handles variables
1123 explicitly placed in a particular register by the user.
1125 This is never called for PARM_DECL nodes. */
1128 make_decl_rtl (tree decl
)
1130 const char *name
= 0;
1134 /* Check that we are not being given an automatic variable. */
1135 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1136 && TREE_CODE (decl
) != RESULT_DECL
);
1138 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1139 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1140 || TREE_STATIC (decl
)
1141 || TREE_PUBLIC (decl
)
1142 || DECL_EXTERNAL (decl
)
1143 || DECL_REGISTER (decl
));
1145 /* And that we were not given a type or a label. */
1146 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1147 && TREE_CODE (decl
) != LABEL_DECL
);
1149 /* For a duplicate declaration, we can be called twice on the
1150 same DECL node. Don't discard the RTL already made. */
1151 if (DECL_RTL_SET_P (decl
))
1153 /* If the old RTL had the wrong mode, fix the mode. */
1154 x
= DECL_RTL (decl
);
1155 if (GET_MODE (x
) != DECL_MODE (decl
))
1156 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1158 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1161 /* ??? Another way to do this would be to maintain a hashed
1162 table of such critters. Instead of adding stuff to a DECL
1163 to give certain attributes to it, we could use an external
1164 hash map from DECL to set of attributes. */
1166 /* Let the target reassign the RTL if it wants.
1167 This is necessary, for example, when one machine specific
1168 decl attribute overrides another. */
1169 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1171 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1172 on the new decl information. */
1174 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1175 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1176 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1178 /* Make this function static known to the mudflap runtime. */
1179 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1180 mudflap_enqueue_decl (decl
);
1185 /* If this variable belongs to the global constant pool, retrieve the
1186 pre-computed RTL or recompute it in LTO mode. */
1187 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1189 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1193 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1195 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1196 && DECL_REGISTER (decl
))
1198 error ("register name not specified for %q+D", decl
);
1200 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1202 const char *asmspec
= name
+1;
1203 enum machine_mode mode
= DECL_MODE (decl
);
1204 reg_number
= decode_reg_name (asmspec
);
1205 /* First detect errors in declaring global registers. */
1206 if (reg_number
== -1)
1207 error ("register name not specified for %q+D", decl
);
1208 else if (reg_number
< 0)
1209 error ("invalid register name for %q+D", decl
);
1210 else if (mode
== BLKmode
)
1211 error ("data type of %q+D isn%'t suitable for a register",
1213 else if (!in_hard_reg_set_p (accessible_reg_set
, mode
, reg_number
))
1214 error ("the register specified for %q+D cannot be accessed"
1215 " by the current target", decl
);
1216 else if (!in_hard_reg_set_p (operand_reg_set
, mode
, reg_number
))
1217 error ("the register specified for %q+D is not general enough"
1218 " to be used as a register variable", decl
);
1219 else if (!HARD_REGNO_MODE_OK (reg_number
, mode
))
1220 error ("register specified for %q+D isn%'t suitable for data type",
1222 /* Now handle properly declared static register variables. */
1227 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1229 DECL_INITIAL (decl
) = 0;
1230 error ("global register variable has initial value");
1232 if (TREE_THIS_VOLATILE (decl
))
1233 warning (OPT_Wvolatile_register_var
,
1234 "optimization may eliminate reads and/or "
1235 "writes to register variables");
1237 /* If the user specified one of the eliminables registers here,
1238 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1239 confused with that register and be eliminated. This usage is
1240 somewhat suspect... */
1242 SET_DECL_RTL (decl
, gen_rtx_raw_REG (mode
, reg_number
));
1243 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1244 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1246 if (TREE_STATIC (decl
))
1248 /* Make this register global, so not usable for anything
1250 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1251 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1252 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1254 nregs
= hard_regno_nregs
[reg_number
][mode
];
1256 globalize_reg (decl
, reg_number
+ --nregs
);
1259 /* As a register variable, it has no section. */
1263 /* Now handle ordinary static variables and functions (in memory).
1264 Also handle vars declared register invalidly. */
1265 else if (name
[0] == '*')
1267 #ifdef REGISTER_PREFIX
1268 if (strlen (REGISTER_PREFIX
) != 0)
1270 reg_number
= decode_reg_name (name
);
1271 if (reg_number
>= 0 || reg_number
== -3)
1272 error ("register name given for non-register variable %q+D", decl
);
1277 /* Specifying a section attribute on a variable forces it into a
1278 non-.bss section, and thus it cannot be common. */
1279 /* FIXME: In general this code should not be necessary because
1280 visibility pass is doing the same work. But notice_global_symbol
1281 is called early and it needs to make DECL_RTL to get the name.
1282 we take care of recomputing the DECL_RTL after visibility is changed. */
1283 if (TREE_CODE (decl
) == VAR_DECL
1284 && DECL_SECTION_NAME (decl
) != NULL_TREE
1285 && DECL_INITIAL (decl
) == NULL_TREE
1286 && DECL_COMMON (decl
))
1287 DECL_COMMON (decl
) = 0;
1289 /* Variables can't be both common and weak. */
1290 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1291 DECL_COMMON (decl
) = 0;
1293 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1294 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1297 enum machine_mode address_mode
= Pmode
;
1298 if (TREE_TYPE (decl
) != error_mark_node
)
1300 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1301 address_mode
= targetm
.addr_space
.address_mode (as
);
1303 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1305 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1306 SET_SYMBOL_REF_DECL (x
, decl
);
1308 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1309 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1310 set_mem_attributes (x
, decl
, 1);
1311 SET_DECL_RTL (decl
, x
);
1313 /* Optionally set flags or add text to the name to record information
1314 such as that it is a function name.
1315 If the name is changed, the macro ASM_OUTPUT_LABELREF
1316 will have to know how to strip this information. */
1317 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1319 /* Make this function static known to the mudflap runtime. */
1320 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1321 mudflap_enqueue_decl (decl
);
1324 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1325 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1329 make_decl_rtl_for_debug (tree decl
)
1331 unsigned int save_aliasing_flag
, save_mudflap_flag
;
1334 if (DECL_RTL_SET_P (decl
))
1335 return DECL_RTL (decl
);
1337 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1338 call new_alias_set. If running with -fcompare-debug, sometimes
1339 we do not want to create alias sets that will throw the alias
1340 numbers off in the comparison dumps. So... clearing
1341 flag_strict_aliasing will keep new_alias_set() from creating a
1342 new set. It is undesirable to register decl with mudflap
1343 in this case as well. */
1344 save_aliasing_flag
= flag_strict_aliasing
;
1345 flag_strict_aliasing
= 0;
1346 save_mudflap_flag
= flag_mudflap
;
1349 rtl
= DECL_RTL (decl
);
1350 /* Reset DECL_RTL back, as various parts of the compiler expects
1351 DECL_RTL set meaning it is actually going to be output. */
1352 SET_DECL_RTL (decl
, NULL
);
1354 flag_strict_aliasing
= save_aliasing_flag
;
1355 flag_mudflap
= save_mudflap_flag
;
1360 /* Output a string of literal assembler code
1361 for an `asm' keyword used between functions. */
1364 assemble_asm (tree string
)
1369 if (TREE_CODE (string
) == ADDR_EXPR
)
1370 string
= TREE_OPERAND (string
, 0);
1372 p
= TREE_STRING_POINTER (string
);
1373 fprintf (asm_out_file
, "%s%s\n", p
[0] == '\t' ? "" : "\t", p
);
1376 /* Write the address of the entity given by SYMBOL to SEC. */
1378 assemble_addr_to_section (rtx symbol
, section
*sec
)
1380 switch_to_section (sec
);
1381 assemble_align (POINTER_SIZE
);
1382 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1385 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1386 not) section for PRIORITY. */
1388 get_cdtor_priority_section (int priority
, bool constructor_p
)
1392 /* ??? This only works reliably with the GNU linker. */
1393 sprintf (buf
, "%s.%.5u",
1394 constructor_p
? ".ctors" : ".dtors",
1395 /* Invert the numbering so the linker puts us in the proper
1396 order; constructors are run from right to left, and the
1397 linker sorts in increasing order. */
1398 MAX_INIT_PRIORITY
- priority
);
1399 return get_section (buf
, SECTION_WRITE
, NULL
);
1403 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1407 if (priority
!= DEFAULT_INIT_PRIORITY
)
1408 sec
= get_cdtor_priority_section (priority
,
1409 /*constructor_p=*/false);
1411 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1413 assemble_addr_to_section (symbol
, sec
);
1416 #ifdef DTORS_SECTION_ASM_OP
1418 default_dtor_section_asm_out_destructor (rtx symbol
,
1419 int priority ATTRIBUTE_UNUSED
)
1421 assemble_addr_to_section (symbol
, dtors_section
);
1426 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1430 if (priority
!= DEFAULT_INIT_PRIORITY
)
1431 sec
= get_cdtor_priority_section (priority
,
1432 /*constructor_p=*/true);
1434 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1436 assemble_addr_to_section (symbol
, sec
);
1439 #ifdef CTORS_SECTION_ASM_OP
1441 default_ctor_section_asm_out_constructor (rtx symbol
,
1442 int priority ATTRIBUTE_UNUSED
)
1444 assemble_addr_to_section (symbol
, ctors_section
);
1448 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1449 a nonzero value if the constant pool should be output before the
1450 start of the function, or a zero value if the pool should output
1451 after the end of the function. The default is to put it before the
1454 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1455 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1458 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1459 to be output to assembler.
1460 Set first_global_object_name and weak_global_object_name as appropriate. */
1463 notice_global_symbol (tree decl
)
1465 const char **type
= &first_global_object_name
;
1467 if (first_global_object_name
1468 || !TREE_PUBLIC (decl
)
1469 || DECL_EXTERNAL (decl
)
1470 || !DECL_NAME (decl
)
1471 || (TREE_CODE (decl
) != FUNCTION_DECL
1472 && (TREE_CODE (decl
) != VAR_DECL
1473 || (DECL_COMMON (decl
)
1474 && (DECL_INITIAL (decl
) == 0
1475 || DECL_INITIAL (decl
) == error_mark_node
))))
1476 || !MEM_P (DECL_RTL (decl
)))
1479 /* We win when global object is found, but it is useful to know about weak
1480 symbol as well so we can produce nicer unique names. */
1481 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1482 type
= &weak_global_object_name
;
1488 rtx decl_rtl
= DECL_RTL (decl
);
1490 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1491 name
= ggc_strdup (p
);
1497 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1498 current function goes into the cold section, so that targets can use
1499 current_function_section during RTL expansion. DECL describes the
1503 decide_function_section (tree decl
)
1505 first_function_block_is_cold
= false;
1507 if (flag_reorder_blocks_and_partition
)
1508 /* We will decide in assemble_start_function. */
1511 if (DECL_SECTION_NAME (decl
))
1513 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
1514 /* Calls to function_section rely on first_function_block_is_cold
1516 first_function_block_is_cold
= (node
1518 == NODE_FREQUENCY_UNLIKELY_EXECUTED
);
1521 in_cold_section_p
= first_function_block_is_cold
;
1524 /* Output assembler code for the constant pool of a function and associated
1525 with defining the name of the function. DECL describes the function.
1526 NAME is the function's name. For the constant pool, we use the current
1527 constant pool data. */
1530 assemble_start_function (tree decl
, const char *fnname
)
1533 char tmp_label
[100];
1534 bool hot_label_written
= false;
1536 if (flag_reorder_blocks_and_partition
)
1538 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1539 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1540 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1541 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1542 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1543 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1544 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1545 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1550 crtl
->subsections
.hot_section_label
= NULL
;
1551 crtl
->subsections
.cold_section_label
= NULL
;
1552 crtl
->subsections
.hot_section_end_label
= NULL
;
1553 crtl
->subsections
.cold_section_end_label
= NULL
;
1556 /* The following code does not need preprocessing in the assembler. */
1560 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1561 output_constant_pool (fnname
, decl
);
1563 /* Make sure the not and cold text (code) sections are properly
1564 aligned. This is necessary here in the case where the function
1565 has both hot and cold sections, because we don't want to re-set
1566 the alignment when the section switch happens mid-function. */
1568 if (flag_reorder_blocks_and_partition
)
1570 first_function_block_is_cold
= false;
1572 switch_to_section (unlikely_text_section ());
1573 assemble_align (DECL_ALIGN (decl
));
1574 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1576 /* When the function starts with a cold section, we need to explicitly
1577 align the hot section and write out the hot section label.
1578 But if the current function is a thunk, we do not have a CFG. */
1580 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1582 switch_to_section (text_section
);
1583 assemble_align (DECL_ALIGN (decl
));
1584 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1585 hot_label_written
= true;
1586 first_function_block_is_cold
= true;
1588 in_cold_section_p
= first_function_block_is_cold
;
1592 /* Switch to the correct text section for the start of the function. */
1594 switch_to_section (function_section (decl
));
1595 if (flag_reorder_blocks_and_partition
1596 && !hot_label_written
)
1597 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1599 /* Tell assembler to move to target machine's alignment for functions. */
1600 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1603 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1606 /* Handle a user-specified function alignment.
1607 Note that we still need to align to DECL_ALIGN, as above,
1608 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1609 if (! DECL_USER_ALIGN (decl
)
1610 && align_functions_log
> align
1611 && optimize_function_for_speed_p (cfun
))
1613 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1614 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1615 align_functions_log
, align_functions
- 1);
1617 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1621 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1622 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1625 if (!DECL_IGNORED_P (decl
))
1626 (*debug_hooks
->begin_function
) (decl
);
1628 /* Make function name accessible from other files, if appropriate. */
1630 if (TREE_PUBLIC (decl
))
1632 notice_global_symbol (decl
);
1634 globalize_decl (decl
);
1636 maybe_assemble_visibility (decl
);
1639 if (DECL_PRESERVE_P (decl
))
1640 targetm
.asm_out
.mark_decl_preserved (fnname
);
1642 /* Do any machine/system dependent processing of the function name. */
1643 #ifdef ASM_DECLARE_FUNCTION_NAME
1644 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1646 /* Standard thing is just output label for the function. */
1647 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1648 #endif /* ASM_DECLARE_FUNCTION_NAME */
1650 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1651 saw_no_split_stack
= true;
1654 /* Output assembler code associated with defining the size of the
1655 function. DECL describes the function. NAME is the function's name. */
1658 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1660 #ifdef ASM_DECLARE_FUNCTION_SIZE
1661 /* We could have switched section in the middle of the function. */
1662 if (flag_reorder_blocks_and_partition
)
1663 switch_to_section (function_section (decl
));
1664 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1666 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1668 output_constant_pool (fnname
, decl
);
1669 switch_to_section (function_section (decl
)); /* need to switch back */
1671 /* Output labels for end of hot/cold text sections (to be used by
1673 if (flag_reorder_blocks_and_partition
)
1675 section
*save_text_section
;
1677 save_text_section
= in_section
;
1678 switch_to_section (unlikely_text_section ());
1679 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1680 if (first_function_block_is_cold
)
1681 switch_to_section (text_section
);
1683 switch_to_section (function_section (decl
));
1684 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1685 switch_to_section (save_text_section
);
1689 /* Assemble code to leave SIZE bytes of zeros. */
1692 assemble_zeros (unsigned HOST_WIDE_INT size
)
1694 /* Do no output if -fsyntax-only. */
1695 if (flag_syntax_only
)
1698 #ifdef ASM_NO_SKIP_IN_TEXT
1699 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1700 so we must output 0s explicitly in the text section. */
1701 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1703 unsigned HOST_WIDE_INT i
;
1704 for (i
= 0; i
< size
; i
++)
1705 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1710 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1713 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1716 assemble_align (int align
)
1718 if (align
> BITS_PER_UNIT
)
1720 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1724 /* Assemble a string constant with the specified C string as contents. */
1727 assemble_string (const char *p
, int size
)
1732 /* If the string is very long, split it up. */
1736 int thissize
= size
- pos
;
1737 if (thissize
> maximum
)
1740 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1748 /* A noswitch_section_callback for lcomm_section. */
1751 emit_local (tree decl ATTRIBUTE_UNUSED
,
1752 const char *name ATTRIBUTE_UNUSED
,
1753 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1754 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1756 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1757 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1758 size
, DECL_ALIGN (decl
));
1760 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1761 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1764 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1769 /* A noswitch_section_callback for bss_noswitch_section. */
1771 #if defined ASM_OUTPUT_ALIGNED_BSS
1773 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1774 const char *name ATTRIBUTE_UNUSED
,
1775 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1776 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1778 #if defined ASM_OUTPUT_ALIGNED_BSS
1779 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
, DECL_ALIGN (decl
));
1785 /* A noswitch_section_callback for comm_section. */
1788 emit_common (tree decl ATTRIBUTE_UNUSED
,
1789 const char *name ATTRIBUTE_UNUSED
,
1790 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1791 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1793 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1794 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1795 size
, DECL_ALIGN (decl
));
1797 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1798 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1801 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1806 /* A noswitch_section_callback for tls_comm_section. */
1809 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1810 const char *name ATTRIBUTE_UNUSED
,
1811 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1812 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1814 #ifdef ASM_OUTPUT_TLS_COMMON
1815 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1818 sorry ("thread-local COMMON data not implemented");
1823 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1824 NAME is the name of DECL's SYMBOL_REF. */
1827 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
)
1829 unsigned HOST_WIDE_INT size
, rounded
;
1831 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1834 /* Don't allocate zero bytes of common,
1835 since that means "undefined external" in the linker. */
1839 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1840 so that each uninitialized object starts on such a boundary. */
1841 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1842 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1843 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1845 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
1846 && (unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
1847 warning (0, "requested alignment for %q+D is greater than "
1848 "implemented alignment of %wu", decl
, rounded
);
1851 /* A subroutine of assemble_variable. Output the label and contents of
1852 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1853 is as for assemble_variable. */
1856 assemble_variable_contents (tree decl
, const char *name
,
1857 bool dont_output_data
)
1859 /* Do any machine/system dependent processing of the object. */
1860 #ifdef ASM_DECLARE_OBJECT_NAME
1861 last_assemble_variable_decl
= decl
;
1862 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1864 /* Standard thing is just output label for the object. */
1865 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1866 #endif /* ASM_DECLARE_OBJECT_NAME */
1868 if (!dont_output_data
)
1870 if (DECL_INITIAL (decl
)
1871 && DECL_INITIAL (decl
) != error_mark_node
1872 && !initializer_zerop (DECL_INITIAL (decl
)))
1873 /* Output the actual data. */
1874 output_constant (DECL_INITIAL (decl
),
1875 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1878 /* Leave space for it. */
1879 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1883 /* Assemble everything that is needed for a variable or function declaration.
1884 Not used for automatic variables, and not used for function definitions.
1885 Should not be called for variables of incomplete structure type.
1887 TOP_LEVEL is nonzero if this variable has file scope.
1888 AT_END is nonzero if this is the special handling, at end of compilation,
1889 to define things that have had only tentative definitions.
1890 DONT_OUTPUT_DATA if nonzero means don't actually output the
1891 initial value (that will be done by the caller). */
1894 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
1895 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
1898 rtx decl_rtl
, symbol
;
1901 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1902 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
1904 /* Emulated TLS had better not get this far. */
1905 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
1907 last_assemble_variable_decl
= 0;
1909 /* Normally no need to say anything here for external references,
1910 since assemble_external is called by the language-specific code
1911 when a declaration is first seen. */
1913 if (DECL_EXTERNAL (decl
))
1916 /* Do nothing for global register variables. */
1917 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
1919 TREE_ASM_WRITTEN (decl
) = 1;
1923 /* If type was incomplete when the variable was declared,
1924 see if it is complete now. */
1926 if (DECL_SIZE (decl
) == 0)
1927 layout_decl (decl
, 0);
1929 /* Still incomplete => don't allocate it; treat the tentative defn
1930 (which is what it must have been) as an `extern' reference. */
1932 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1934 error ("storage size of %q+D isn%'t known", decl
);
1935 TREE_ASM_WRITTEN (decl
) = 1;
1939 /* The first declaration of a variable that comes through this function
1940 decides whether it is global (in C, has external linkage)
1941 or local (in C, has internal linkage). So do nothing more
1942 if this function has already run. */
1944 if (TREE_ASM_WRITTEN (decl
))
1947 /* Make sure targetm.encode_section_info is invoked before we set
1949 decl_rtl
= DECL_RTL (decl
);
1951 TREE_ASM_WRITTEN (decl
) = 1;
1953 /* Do no output if -fsyntax-only. */
1954 if (flag_syntax_only
)
1957 if (! dont_output_data
1958 && ! valid_constant_size_p (DECL_SIZE_UNIT (decl
)))
1960 error ("size of variable %q+D is too large", decl
);
1964 gcc_assert (MEM_P (decl_rtl
));
1965 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
1966 symbol
= XEXP (decl_rtl
, 0);
1968 /* If this symbol belongs to the tree constant pool, output the constant
1969 if it hasn't already been written. */
1970 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
1972 tree decl
= SYMBOL_REF_DECL (symbol
);
1973 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
1974 output_constant_def_contents (symbol
);
1980 name
= XSTR (symbol
, 0);
1981 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1982 notice_global_symbol (decl
);
1984 /* Compute the alignment of this data. */
1986 align_variable (decl
, dont_output_data
);
1987 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
1989 if (TREE_PUBLIC (decl
))
1990 maybe_assemble_visibility (decl
);
1992 if (DECL_PRESERVE_P (decl
))
1993 targetm
.asm_out
.mark_decl_preserved (name
);
1995 /* First make the assembler name(s) global if appropriate. */
1996 sect
= get_variable_section (decl
, false);
1997 if (TREE_PUBLIC (decl
)
1998 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
1999 globalize_decl (decl
);
2001 /* Output any data that we will need to use the address of. */
2002 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2003 output_addressed_constants (DECL_INITIAL (decl
));
2005 /* dbxout.c needs to know this. */
2006 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2007 DECL_IN_TEXT_SECTION (decl
) = 1;
2009 /* If the decl is part of an object_block, make sure that the decl
2010 has been positioned within its block, but do not write out its
2011 definition yet. output_object_blocks will do that later. */
2012 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2014 gcc_assert (!dont_output_data
);
2015 place_block_symbol (symbol
);
2017 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2018 assemble_noswitch_variable (decl
, name
, sect
);
2021 switch_to_section (sect
);
2022 if (DECL_ALIGN (decl
) > BITS_PER_UNIT
)
2023 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
2024 assemble_variable_contents (decl
, name
, dont_output_data
);
2028 /* Return 1 if type TYPE contains any pointers. */
2031 contains_pointers_p (tree type
)
2033 switch (TREE_CODE (type
))
2036 case REFERENCE_TYPE
:
2037 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2038 so I'll play safe and return 1. */
2044 case QUAL_UNION_TYPE
:
2047 /* For a type that has fields, see if the fields have pointers. */
2048 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
2049 if (TREE_CODE (fields
) == FIELD_DECL
2050 && contains_pointers_p (TREE_TYPE (fields
)))
2056 /* An array type contains pointers if its element type does. */
2057 return contains_pointers_p (TREE_TYPE (type
));
2064 /* We delay assemble_external processing until
2065 the compilation unit is finalized. This is the best we can do for
2066 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2067 it all the way to final. See PR 17982 for further discussion. */
2068 static GTY(()) tree pending_assemble_externals
;
2070 #ifdef ASM_OUTPUT_EXTERNAL
2071 /* True if DECL is a function decl for which no out-of-line copy exists.
2072 It is assumed that DECL's assembler name has been set. */
2075 incorporeal_function_p (tree decl
)
2077 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2081 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2082 && (DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
2083 || DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA_WITH_ALIGN
))
2086 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2087 /* Atomic or sync builtins which have survived this far will be
2088 resolved externally and therefore are not incorporeal. */
2089 if (strncmp (name
, "__builtin_", 10) == 0)
2095 /* Actually do the tests to determine if this is necessary, and invoke
2096 ASM_OUTPUT_EXTERNAL. */
2098 assemble_external_real (tree decl
)
2100 rtx rtl
= DECL_RTL (decl
);
2102 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2103 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2104 && !incorporeal_function_p (decl
))
2106 /* Some systems do require some output. */
2107 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2108 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2114 process_pending_assemble_externals (void)
2116 #ifdef ASM_OUTPUT_EXTERNAL
2118 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2119 assemble_external_real (TREE_VALUE (list
));
2121 pending_assemble_externals
= 0;
2125 /* This TREE_LIST contains any weak symbol declarations waiting
2127 static GTY(()) tree weak_decls
;
2129 /* Output something to declare an external symbol to the assembler,
2130 and qualifiers such as weakness. (Most assemblers don't need
2131 extern declaration, so we normally output nothing.) Do nothing if
2132 DECL is not external. */
2135 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2137 /* Make sure that the ASM_OUT_FILE is open.
2138 If it's not, we should not be calling this function. */
2139 gcc_assert (asm_out_file
);
2141 /* In a perfect world, the following condition would be true.
2142 Sadly, the Java and Go front ends emit assembly *from the front end*,
2143 bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2145 /* This function should only be called if we are expanding, or have
2147 Ideally, only final.c would be calling this function, but it is
2148 not clear whether that would break things somehow. See PR 17982
2149 for further discussion. */
2150 gcc_assert (cgraph_state
== CGRAPH_STATE_EXPANSION
2151 || cgraph_state
== CGRAPH_STATE_FINISHED
);
2154 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2157 /* We want to output annotation for weak and external symbols at
2158 very last to check if they are references or not. */
2160 if (TARGET_SUPPORTS_WEAK
2162 /* TREE_STATIC is a weird and abused creature which is not
2163 generally the right test for whether an entity has been
2164 locally emitted, inlined or otherwise not-really-extern, but
2165 for declarations that can be weak, it happens to be
2167 && !TREE_STATIC (decl
)
2168 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2169 && value_member (decl
, weak_decls
) == NULL_TREE
)
2170 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2172 #ifdef ASM_OUTPUT_EXTERNAL
2173 if (value_member (decl
, pending_assemble_externals
) == NULL_TREE
)
2174 pending_assemble_externals
= tree_cons (NULL
, decl
,
2175 pending_assemble_externals
);
2179 /* Similar, for calling a library function FUN. */
2182 assemble_external_libcall (rtx fun
)
2184 /* Declare library function name external when first used, if nec. */
2185 if (! SYMBOL_REF_USED (fun
))
2187 SYMBOL_REF_USED (fun
) = 1;
2188 targetm
.asm_out
.external_libcall (fun
);
2192 /* Assemble a label named NAME. */
2195 assemble_label (FILE *file
, const char *name
)
2197 ASM_OUTPUT_LABEL (file
, name
);
2200 /* Set the symbol_referenced flag for ID. */
2202 mark_referenced (tree id
)
2204 TREE_SYMBOL_REFERENCED (id
) = 1;
2207 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2209 mark_decl_referenced (tree decl
)
2211 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2213 /* Extern inline functions don't become needed when referenced.
2214 If we know a method will be emitted in other TU and no new
2215 functions can be marked reachable, just use the external
2217 struct cgraph_node
*node
= cgraph_get_create_node (decl
);
2218 if (!DECL_EXTERNAL (decl
)
2219 && !node
->local
.finalized
)
2220 cgraph_mark_force_output_node (node
);
2222 else if (TREE_CODE (decl
) == VAR_DECL
)
2224 struct varpool_node
*node
= varpool_node (decl
);
2225 /* C++ frontend use mark_decl_references to force COMDAT variables
2226 to be output that might appear dead otherwise. */
2227 node
->symbol
.force_output
= true;
2229 /* else do nothing - we can get various sorts of CST nodes here,
2230 which do not need to be marked. */
2234 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2235 until we find an identifier that is not itself a transparent alias.
2236 Modify the alias passed to it by reference (and all aliases on the
2237 way to the ultimate target), such that they do not have to be
2238 followed again, and return the ultimate target of the alias
2242 ultimate_transparent_alias_target (tree
*alias
)
2244 tree target
= *alias
;
2246 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2248 gcc_assert (TREE_CHAIN (target
));
2249 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2250 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2251 && ! TREE_CHAIN (target
));
2258 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2259 starts with a *, the rest of NAME is output verbatim. Otherwise
2260 NAME is transformed in a target-specific way (usually by the
2261 addition of an underscore). */
2264 assemble_name_raw (FILE *file
, const char *name
)
2267 fputs (&name
[1], file
);
2269 ASM_OUTPUT_LABELREF (file
, name
);
2272 /* Like assemble_name_raw, but should be used when NAME might refer to
2273 an entity that is also represented as a tree (like a function or
2274 variable). If NAME does refer to such an entity, that entity will
2275 be marked as referenced. */
2278 assemble_name (FILE *file
, const char *name
)
2280 const char *real_name
;
2283 real_name
= targetm
.strip_name_encoding (name
);
2285 id
= maybe_get_identifier (real_name
);
2290 mark_referenced (id
);
2291 ultimate_transparent_alias_target (&id
);
2293 name
= IDENTIFIER_POINTER (id
);
2294 gcc_assert (! TREE_CHAIN (id
));
2297 assemble_name_raw (file
, name
);
2300 /* Allocate SIZE bytes writable static space with a gensym name
2301 and return an RTX to refer to its address. */
2304 assemble_static_space (unsigned HOST_WIDE_INT size
)
2307 const char *namestring
;
2310 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2312 namestring
= ggc_strdup (name
);
2314 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2315 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2317 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2318 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2321 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2322 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2325 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2326 so that each uninitialized object starts on such a boundary. */
2327 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2328 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2329 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2330 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2331 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2332 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2339 /* Assemble the static constant template for function entry trampolines.
2340 This is done at most once per compilation.
2341 Returns an RTX for the address of the template. */
2343 static GTY(()) rtx initial_trampoline
;
2346 assemble_trampoline_template (void)
2353 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2355 if (initial_trampoline
)
2356 return initial_trampoline
;
2358 /* By default, put trampoline templates in read-only data section. */
2360 #ifdef TRAMPOLINE_SECTION
2361 switch_to_section (TRAMPOLINE_SECTION
);
2363 switch_to_section (readonly_data_section
);
2366 /* Write the assembler code to define one. */
2367 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2369 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2371 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2372 targetm
.asm_out
.trampoline_template (asm_out_file
);
2374 /* Record the rtl to refer to it. */
2375 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2376 name
= ggc_strdup (label
);
2377 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2378 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2380 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2381 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2382 set_mem_size (initial_trampoline
, TRAMPOLINE_SIZE
);
2384 return initial_trampoline
;
2387 /* A and B are either alignments or offsets. Return the minimum alignment
2388 that may be assumed after adding the two together. */
2390 static inline unsigned
2391 min_align (unsigned int a
, unsigned int b
)
2393 return (a
| b
) & -(a
| b
);
2396 /* Return the assembler directive for creating a given kind of integer
2397 object. SIZE is the number of bytes in the object and ALIGNED_P
2398 indicates whether it is known to be aligned. Return NULL if the
2399 assembly dialect has no such directive.
2401 The returned string should be printed at the start of a new line and
2402 be followed immediately by the object's initial value. */
2405 integer_asm_op (int size
, int aligned_p
)
2407 struct asm_int_op
*ops
;
2410 ops
= &targetm
.asm_out
.aligned_op
;
2412 ops
= &targetm
.asm_out
.unaligned_op
;
2417 return targetm
.asm_out
.byte_op
;
2431 /* Use directive OP to assemble an integer object X. Print OP at the
2432 start of the line, followed immediately by the value of X. */
2435 assemble_integer_with_op (const char *op
, rtx x
)
2437 fputs (op
, asm_out_file
);
2438 output_addr_const (asm_out_file
, x
);
2439 fputc ('\n', asm_out_file
);
2442 /* The default implementation of the asm_out.integer target hook. */
2445 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2446 unsigned int size ATTRIBUTE_UNUSED
,
2447 int aligned_p ATTRIBUTE_UNUSED
)
2449 const char *op
= integer_asm_op (size
, aligned_p
);
2450 /* Avoid GAS bugs for large values. Specifically negative values whose
2451 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2452 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2454 return op
&& (assemble_integer_with_op (op
, x
), true);
2457 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2458 the alignment of the integer in bits. Return 1 if we were able to output
2459 the constant, otherwise 0. We must be able to output the constant,
2460 if FORCE is nonzero. */
2463 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2467 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2469 /* See if the target hook can handle this kind of object. */
2470 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2473 /* If the object is a multi-byte one, try splitting it up. Split
2474 it into words it if is multi-word, otherwise split it into bytes. */
2477 enum machine_mode omode
, imode
;
2478 unsigned int subalign
;
2479 unsigned int subsize
, i
;
2480 enum mode_class mclass
;
2482 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2483 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2484 if (GET_CODE (x
) == CONST_FIXED
)
2485 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2489 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2490 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2492 for (i
= 0; i
< size
; i
+= subsize
)
2494 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2495 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2501 /* If we've printed some of it, but not all of it, there's no going
2506 gcc_assert (!force
);
2512 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2514 long data
[4] = {0, 0, 0, 0};
2516 int bitsize
, nelts
, nunits
, units_per
;
2518 /* This is hairy. We have a quantity of known size. real_to_target
2519 will put it into an array of *host* longs, 32 bits per element
2520 (even if long is more than 32 bits). We need to determine the
2521 number of array elements that are occupied (nelts) and the number
2522 of *target* min-addressable units that will be occupied in the
2523 object file (nunits). We cannot assume that 32 divides the
2524 mode's bitsize (size * BITS_PER_UNIT) evenly.
2526 size * BITS_PER_UNIT is used here to make sure that padding bits
2527 (which might appear at either end of the value; real_to_target
2528 will include the padding bits in its output array) are included. */
2530 nunits
= GET_MODE_SIZE (mode
);
2531 bitsize
= nunits
* BITS_PER_UNIT
;
2532 nelts
= CEIL (bitsize
, 32);
2533 units_per
= 32 / BITS_PER_UNIT
;
2535 real_to_target (data
, &d
, mode
);
2537 /* Put out the first word with the specified alignment. */
2538 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2539 nunits
-= units_per
;
2541 /* Subsequent words need only 32-bit alignment. */
2542 align
= min_align (align
, 32);
2544 for (i
= 1; i
< nelts
; i
++)
2546 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2547 nunits
-= units_per
;
2551 /* Given an expression EXP with a constant value,
2552 reduce it to the sum of an assembler symbol and an integer.
2553 Store them both in the structure *VALUE.
2554 EXP must be reducible. */
2558 HOST_WIDE_INT offset
;
2562 decode_addr_const (tree exp
, struct addr_const
*value
)
2564 tree target
= TREE_OPERAND (exp
, 0);
2570 if (TREE_CODE (target
) == COMPONENT_REF
2571 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2573 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2574 target
= TREE_OPERAND (target
, 0);
2576 else if (TREE_CODE (target
) == ARRAY_REF
2577 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2579 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2580 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2581 target
= TREE_OPERAND (target
, 0);
2583 else if (TREE_CODE (target
) == MEM_REF
2584 && TREE_CODE (TREE_OPERAND (target
, 0)) == ADDR_EXPR
)
2586 offset
+= mem_ref_offset (target
).low
;
2587 target
= TREE_OPERAND (TREE_OPERAND (target
, 0), 0);
2589 else if (TREE_CODE (target
) == INDIRECT_REF
2590 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2591 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2593 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2598 switch (TREE_CODE (target
))
2602 x
= DECL_RTL (target
);
2606 x
= gen_rtx_MEM (FUNCTION_MODE
,
2607 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2616 x
= output_constant_def (target
, 1);
2623 gcc_assert (MEM_P (x
));
2627 value
->offset
= offset
;
2631 static GTY((param_is (struct constant_descriptor_tree
)))
2632 htab_t const_desc_htab
;
2634 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2636 /* Constant pool accessor function. */
2639 constant_pool_htab (void)
2641 return const_desc_htab
;
2644 /* Compute a hash code for a constant expression. */
2647 const_desc_hash (const void *ptr
)
2649 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2653 const_hash_1 (const tree exp
)
2658 enum tree_code code
= TREE_CODE (exp
);
2660 /* Either set P and LEN to the address and len of something to hash and
2661 exit the switch or return a value. */
2666 p
= (char *) &TREE_INT_CST (exp
);
2667 len
= sizeof TREE_INT_CST (exp
);
2671 return real_hash (TREE_REAL_CST_PTR (exp
));
2674 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2677 p
= TREE_STRING_POINTER (exp
);
2678 len
= TREE_STRING_LENGTH (exp
);
2682 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2683 + const_hash_1 (TREE_IMAGPART (exp
)));
2689 hi
= 7 + VECTOR_CST_NELTS (exp
);
2691 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
2692 hi
= hi
* 563 + const_hash_1 (VECTOR_CST_ELT (exp
, i
));
2699 unsigned HOST_WIDE_INT idx
;
2702 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2704 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2706 hi
= hi
* 603 + const_hash_1 (value
);
2714 struct addr_const value
;
2716 decode_addr_const (exp
, &value
);
2717 switch (GET_CODE (value
.base
))
2720 /* Don't hash the address of the SYMBOL_REF;
2721 only use the offset and the symbol name. */
2723 p
= XSTR (value
.base
, 0);
2724 for (i
= 0; p
[i
] != 0; i
++)
2725 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2729 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2739 case POINTER_PLUS_EXPR
:
2741 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2742 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2745 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2748 /* A language specific constant. Just hash the code. */
2752 /* Compute hashing function. */
2754 for (i
= 0; i
< len
; i
++)
2755 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2760 /* Wrapper of compare_constant, for the htab interface. */
2762 const_desc_eq (const void *p1
, const void *p2
)
2764 const struct constant_descriptor_tree
*const c1
2765 = (const struct constant_descriptor_tree
*) p1
;
2766 const struct constant_descriptor_tree
*const c2
2767 = (const struct constant_descriptor_tree
*) p2
;
2768 if (c1
->hash
!= c2
->hash
)
2770 return compare_constant (c1
->value
, c2
->value
);
2773 /* Compare t1 and t2, and return 1 only if they are known to result in
2774 the same bit pattern on output. */
2777 compare_constant (const tree t1
, const tree t2
)
2779 enum tree_code typecode
;
2781 if (t1
== NULL_TREE
)
2782 return t2
== NULL_TREE
;
2783 if (t2
== NULL_TREE
)
2786 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2789 switch (TREE_CODE (t1
))
2792 /* Integer constants are the same only if the same width of type. */
2793 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2795 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2797 return tree_int_cst_equal (t1
, t2
);
2800 /* Real constants are the same only if the same width of type. */
2801 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2804 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2807 /* Fixed constants are the same only if the same width of type. */
2808 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2811 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
2814 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2817 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2818 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2819 TREE_STRING_LENGTH (t1
)));
2822 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2823 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2829 if (VECTOR_CST_NELTS (t1
) != VECTOR_CST_NELTS (t2
))
2832 for (i
= 0; i
< VECTOR_CST_NELTS (t1
); ++i
)
2833 if (!compare_constant (VECTOR_CST_ELT (t1
, i
),
2834 VECTOR_CST_ELT (t2
, i
)))
2842 VEC(constructor_elt
, gc
) *v1
, *v2
;
2843 unsigned HOST_WIDE_INT idx
;
2845 typecode
= TREE_CODE (TREE_TYPE (t1
));
2846 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
2849 if (typecode
== ARRAY_TYPE
)
2851 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
2852 /* For arrays, check that the sizes all match. */
2853 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
2855 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
2860 /* For record and union constructors, require exact type
2862 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
2866 v1
= CONSTRUCTOR_ELTS (t1
);
2867 v2
= CONSTRUCTOR_ELTS (t2
);
2868 if (VEC_length (constructor_elt
, v1
)
2869 != VEC_length (constructor_elt
, v2
))
2872 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
2874 constructor_elt
*c1
= &VEC_index (constructor_elt
, v1
, idx
);
2875 constructor_elt
*c2
= &VEC_index (constructor_elt
, v2
, idx
);
2877 /* Check that each value is the same... */
2878 if (!compare_constant (c1
->value
, c2
->value
))
2880 /* ... and that they apply to the same fields! */
2881 if (typecode
== ARRAY_TYPE
)
2883 if (!compare_constant (c1
->index
, c2
->index
))
2888 if (c1
->index
!= c2
->index
)
2899 struct addr_const value1
, value2
;
2903 decode_addr_const (t1
, &value1
);
2904 decode_addr_const (t2
, &value2
);
2906 if (value1
.offset
!= value2
.offset
)
2909 code
= GET_CODE (value1
.base
);
2910 if (code
!= GET_CODE (value2
.base
))
2916 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
2920 ret
= (CODE_LABEL_NUMBER (XEXP (value1
.base
, 0))
2921 == CODE_LABEL_NUMBER (XEXP (value2
.base
, 0)));
2931 case POINTER_PLUS_EXPR
:
2934 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2935 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2938 case VIEW_CONVERT_EXPR
:
2939 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2948 /* Make a copy of the whole tree structure for a constant. This
2949 handles the same types of nodes that compare_constant handles. */
2952 copy_constant (tree exp
)
2954 switch (TREE_CODE (exp
))
2957 /* For ADDR_EXPR, we do not want to copy the decl whose address
2958 is requested. We do want to copy constants though. */
2959 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
2960 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2961 copy_constant (TREE_OPERAND (exp
, 0)));
2963 return copy_node (exp
);
2969 return copy_node (exp
);
2972 return build_complex (TREE_TYPE (exp
),
2973 copy_constant (TREE_REALPART (exp
)),
2974 copy_constant (TREE_IMAGPART (exp
)));
2977 case POINTER_PLUS_EXPR
:
2979 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
2980 copy_constant (TREE_OPERAND (exp
, 0)),
2981 copy_constant (TREE_OPERAND (exp
, 1)));
2984 case VIEW_CONVERT_EXPR
:
2985 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2986 copy_constant (TREE_OPERAND (exp
, 0)));
2989 return build_vector (TREE_TYPE (exp
), VECTOR_CST_ELTS (exp
));
2993 tree copy
= copy_node (exp
);
2994 VEC(constructor_elt
, gc
) *v
;
2995 unsigned HOST_WIDE_INT idx
;
2996 tree purpose
, value
;
2998 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
2999 CONSTRUCTOR_ELTS (exp
)));
3000 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
3002 constructor_elt ce
= {purpose
, copy_constant (value
)};
3003 VEC_quick_push (constructor_elt
, v
, ce
);
3005 CONSTRUCTOR_ELTS (copy
) = v
;
3014 /* Return the section into which constant EXP should be placed. */
3017 get_constant_section (tree exp
, unsigned int align
)
3019 return targetm
.asm_out
.select_section (exp
,
3020 compute_reloc_for_constant (exp
),
3024 /* Return the size of constant EXP in bytes. */
3026 static HOST_WIDE_INT
3027 get_constant_size (tree exp
)
3031 size
= int_size_in_bytes (TREE_TYPE (exp
));
3032 if (TREE_CODE (exp
) == STRING_CST
)
3033 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3037 /* Subroutine of output_constant_def:
3038 No constant equal to EXP is known to have been output.
3039 Make a constant descriptor to enter EXP in the hash table.
3040 Assign the label number and construct RTL to refer to the
3041 constant's location in memory.
3042 Caller is responsible for updating the hash table. */
3044 static struct constant_descriptor_tree
*
3045 build_constant_desc (tree exp
)
3047 struct constant_descriptor_tree
*desc
;
3053 desc
= ggc_alloc_constant_descriptor_tree ();
3054 desc
->value
= copy_constant (exp
);
3056 /* Propagate marked-ness to copied constant. */
3057 if (flag_mudflap
&& mf_marked_p (exp
))
3058 mf_mark (desc
->value
);
3060 /* Create a string containing the label name, in LABEL. */
3061 labelno
= const_labelno
++;
3062 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3064 /* Construct the VAR_DECL associated with the constant. */
3065 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3067 DECL_ARTIFICIAL (decl
) = 1;
3068 DECL_IGNORED_P (decl
) = 1;
3069 TREE_READONLY (decl
) = 1;
3070 TREE_STATIC (decl
) = 1;
3071 TREE_ADDRESSABLE (decl
) = 1;
3072 /* We don't set the RTL yet as this would cause varpool to assume that the
3073 variable is referenced. Moreover, it would just be dropped in LTO mode.
3074 Instead we set the flag that will be recognized in make_decl_rtl. */
3075 DECL_IN_CONSTANT_POOL (decl
) = 1;
3076 DECL_INITIAL (decl
) = desc
->value
;
3077 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3078 architectures so use DATA_ALIGNMENT as well, except for strings. */
3079 if (TREE_CODE (exp
) == STRING_CST
)
3081 #ifdef CONSTANT_ALIGNMENT
3082 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
3086 align_variable (decl
, 0);
3088 /* Now construct the SYMBOL_REF and the MEM. */
3089 if (use_object_blocks_p ())
3091 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
3092 symbol
= create_block_symbol (ggc_strdup (label
),
3093 get_block_for_section (sect
), -1);
3096 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3097 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3098 SET_SYMBOL_REF_DECL (symbol
, decl
);
3099 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3101 rtl
= gen_const_mem (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3102 set_mem_attributes (rtl
, exp
, 1);
3103 set_mem_alias_set (rtl
, 0);
3104 set_mem_alias_set (rtl
, const_alias_set
);
3106 /* We cannot share RTX'es in pool entries.
3107 Mark this piece of RTL as required for unsharing. */
3108 RTX_FLAG (rtl
, used
) = 1;
3110 /* Set flags or add text to the name to record information, such as
3111 that it is a local symbol. If the name is changed, the macro
3112 ASM_OUTPUT_LABELREF will have to know how to strip this
3113 information. This call might invalidate our local variable
3114 SYMBOL; we can't use it afterward. */
3115 targetm
.encode_section_info (exp
, rtl
, true);
3122 /* Return an rtx representing a reference to constant data in memory
3123 for the constant expression EXP.
3125 If assembler code for such a constant has already been output,
3126 return an rtx to refer to it.
3127 Otherwise, output such a constant in memory
3128 and generate an rtx for it.
3130 If DEFER is nonzero, this constant can be deferred and output only
3131 if referenced in the function after all optimizations.
3133 `const_desc_table' records which constants already have label strings. */
3136 output_constant_def (tree exp
, int defer
)
3138 struct constant_descriptor_tree
*desc
;
3139 struct constant_descriptor_tree key
;
3142 /* Look up EXP in the table of constant descriptors. If we didn't find
3143 it, create a new one. */
3145 key
.hash
= const_hash_1 (exp
);
3146 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3148 desc
= (struct constant_descriptor_tree
*) *loc
;
3151 desc
= build_constant_desc (exp
);
3152 desc
->hash
= key
.hash
;
3156 maybe_output_constant_def_contents (desc
, defer
);
3160 /* Subroutine of output_constant_def: Decide whether or not we need to
3161 output the constant DESC now, and if so, do it. */
3163 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3166 rtx symbol
= XEXP (desc
->rtl
, 0);
3167 tree exp
= desc
->value
;
3169 if (flag_syntax_only
)
3172 if (TREE_ASM_WRITTEN (exp
))
3173 /* Already output; don't do it again. */
3176 /* We can always defer constants as long as the context allows
3180 /* Increment n_deferred_constants if it exists. It needs to be at
3181 least as large as the number of constants actually referred to
3182 by the function. If it's too small we'll stop looking too early
3183 and fail to emit constants; if it's too large we'll only look
3184 through the entire function when we could have stopped earlier. */
3186 n_deferred_constants
++;
3190 output_constant_def_contents (symbol
);
3193 /* Subroutine of output_constant_def_contents. Output the definition
3194 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3195 constant's alignment in bits. */
3198 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3202 size
= get_constant_size (exp
);
3204 /* Do any machine/system dependent processing of the constant. */
3205 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3207 /* Output the value of EXP. */
3208 output_constant (exp
, size
, align
);
3211 /* We must output the constant data referred to by SYMBOL; do so. */
3214 output_constant_def_contents (rtx symbol
)
3216 tree decl
= SYMBOL_REF_DECL (symbol
);
3217 tree exp
= DECL_INITIAL (decl
);
3220 /* Make sure any other constants whose addresses appear in EXP
3221 are assigned label numbers. */
3222 output_addressed_constants (exp
);
3224 /* We are no longer deferring this constant. */
3225 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3227 /* If the constant is part of an object block, make sure that the
3228 decl has been positioned within its block, but do not write out
3229 its definition yet. output_object_blocks will do that later. */
3230 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3231 place_block_symbol (symbol
);
3234 align
= DECL_ALIGN (decl
);
3235 switch_to_section (get_constant_section (exp
, align
));
3236 if (align
> BITS_PER_UNIT
)
3237 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3238 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3241 mudflap_enqueue_constant (exp
);
3244 /* Look up EXP in the table of constant descriptors. Return the rtl
3245 if it has been emitted, else null. */
3248 lookup_constant_def (tree exp
)
3250 struct constant_descriptor_tree
*desc
;
3251 struct constant_descriptor_tree key
;
3254 key
.hash
= const_hash_1 (exp
);
3255 desc
= (struct constant_descriptor_tree
*)
3256 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3258 return (desc
? desc
->rtl
: NULL_RTX
);
3261 /* Return a tree representing a reference to constant data in memory
3262 for the constant expression EXP.
3264 This is the counterpart of output_constant_def at the Tree level. */
3267 tree_output_constant_def (tree exp
)
3269 struct constant_descriptor_tree
*desc
, key
;
3273 /* Look up EXP in the table of constant descriptors. If we didn't find
3274 it, create a new one. */
3276 key
.hash
= const_hash_1 (exp
);
3277 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3279 desc
= (struct constant_descriptor_tree
*) *loc
;
3282 desc
= build_constant_desc (exp
);
3283 desc
->hash
= key
.hash
;
3287 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3288 varpool_finalize_decl (decl
);
3292 /* Used in the hash tables to avoid outputting the same constant
3293 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3294 are output once per function, not once per file. */
3295 /* ??? Only a few targets need per-function constant pools. Most
3296 can use one per-file pool. Should add a targetm bit to tell the
3299 struct GTY(()) rtx_constant_pool
{
3300 /* Pointers to first and last constant in pool, as ordered by offset. */
3301 struct constant_descriptor_rtx
*first
;
3302 struct constant_descriptor_rtx
*last
;
3304 /* Hash facility for making memory-constants from constant rtl-expressions.
3305 It is used on RISC machines where immediate integer arguments and
3306 constant addresses are restricted so that such constants must be stored
3308 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3310 /* Current offset in constant pool (does not include any
3311 machine-specific header). */
3312 HOST_WIDE_INT offset
;
3315 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3316 struct constant_descriptor_rtx
*next
;
3320 HOST_WIDE_INT offset
;
3322 enum machine_mode mode
;
3328 /* Hash and compare functions for const_rtx_htab. */
3331 const_desc_rtx_hash (const void *ptr
)
3333 const struct constant_descriptor_rtx
*const desc
3334 = (const struct constant_descriptor_rtx
*) ptr
;
3339 const_desc_rtx_eq (const void *a
, const void *b
)
3341 const struct constant_descriptor_rtx
*const x
3342 = (const struct constant_descriptor_rtx
*) a
;
3343 const struct constant_descriptor_rtx
*const y
3344 = (const struct constant_descriptor_rtx
*) b
;
3346 if (x
->mode
!= y
->mode
)
3348 return rtx_equal_p (x
->constant
, y
->constant
);
3351 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3354 const_rtx_hash_1 (rtx
*xp
, void *data
)
3356 unsigned HOST_WIDE_INT hwi
;
3357 enum machine_mode mode
;
3363 code
= GET_CODE (x
);
3364 mode
= GET_MODE (x
);
3365 h
= (hashval_t
) code
* 1048573 + mode
;
3373 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3374 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3377 h
^= (hashval_t
) hwi
;
3378 for (i
= 1; i
< n
; ++i
)
3381 h
^= (hashval_t
) hwi
;
3387 if (mode
== VOIDmode
)
3389 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3393 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3397 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3403 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3404 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3409 h
^= htab_hash_string (XSTR (x
, 0));
3413 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3417 case UNSPEC_VOLATILE
:
3418 h
= h
* 251 + XINT (x
, 1);
3425 hp
= (hashval_t
*) data
;
3426 *hp
= *hp
* 509 + h
;
3430 /* Compute a hash value for X, which should be a constant. */
3433 const_rtx_hash (rtx x
)
3436 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3441 /* Create and return a new rtx constant pool. */
3443 static struct rtx_constant_pool
*
3444 create_constant_pool (void)
3446 struct rtx_constant_pool
*pool
;
3448 pool
= ggc_alloc_rtx_constant_pool ();
3449 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3450 const_desc_rtx_eq
, NULL
);
3457 /* Initialize constant pool hashing for a new function. */
3460 init_varasm_status (void)
3462 crtl
->varasm
.pool
= create_constant_pool ();
3463 crtl
->varasm
.deferred_constants
= 0;
3466 /* Given a MINUS expression, simplify it if both sides
3467 include the same symbol. */
3470 simplify_subtraction (rtx x
)
3472 rtx r
= simplify_rtx (x
);
3476 /* Given a constant rtx X, make (or find) a memory constant for its value
3477 and return a MEM rtx to refer to it in memory. */
3480 force_const_mem (enum machine_mode mode
, rtx x
)
3482 struct constant_descriptor_rtx
*desc
, tmp
;
3483 struct rtx_constant_pool
*pool
;
3490 /* If we're not allowed to drop X into the constant pool, don't. */
3491 if (targetm
.cannot_force_const_mem (mode
, x
))
3494 /* Record that this function has used a constant pool entry. */
3495 crtl
->uses_const_pool
= 1;
3497 /* Decide which pool to use. */
3498 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3499 ? shared_constant_pool
3500 : crtl
->varasm
.pool
);
3502 /* Lookup the value in the hashtable. */
3505 hash
= const_rtx_hash (x
);
3506 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3507 desc
= (struct constant_descriptor_rtx
*) *slot
;
3509 /* If the constant was already present, return its memory. */
3511 return copy_rtx (desc
->mem
);
3513 /* Otherwise, create a new descriptor. */
3514 desc
= ggc_alloc_constant_descriptor_rtx ();
3517 /* Align the location counter as required by EXP's data type. */
3518 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3519 #ifdef CONSTANT_ALIGNMENT
3521 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3522 if (type
!= NULL_TREE
)
3523 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3527 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3528 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3531 desc
->constant
= copy_rtx (tmp
.constant
);
3532 desc
->offset
= pool
->offset
;
3535 desc
->align
= align
;
3536 desc
->labelno
= const_labelno
;
3539 pool
->offset
+= GET_MODE_SIZE (mode
);
3541 pool
->last
->next
= desc
;
3543 pool
->first
= pool
->last
= desc
;
3546 /* Create a string containing the label name, in LABEL. */
3547 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3550 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3551 the constants pool. */
3552 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3554 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3555 symbol
= create_block_symbol (ggc_strdup (label
),
3556 get_block_for_section (sect
), -1);
3559 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3561 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3562 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3563 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3565 /* Construct the MEM. */
3566 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3567 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3568 set_mem_align (def
, align
);
3570 /* If we're dropping a label to the constant pool, make sure we
3572 if (GET_CODE (x
) == LABEL_REF
)
3573 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3575 return copy_rtx (def
);
3578 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3581 get_pool_constant (rtx addr
)
3583 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3586 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3587 and whether it has been output or not. */
3590 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3592 struct constant_descriptor_rtx
*desc
;
3594 desc
= SYMBOL_REF_CONSTANT (addr
);
3595 *pmarked
= (desc
->mark
!= 0);
3596 return desc
->constant
;
3599 /* Similar, return the mode. */
3602 get_pool_mode (const_rtx addr
)
3604 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3607 /* Return the size of the constant pool. */
3610 get_pool_size (void)
3612 return crtl
->varasm
.pool
->offset
;
3615 /* Worker function for output_constant_pool_1. Emit assembly for X
3616 in MODE with known alignment ALIGN. */
3619 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3621 switch (GET_MODE_CLASS (mode
))
3624 case MODE_DECIMAL_FLOAT
:
3628 gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x
));
3629 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3630 assemble_real (r
, mode
, align
);
3635 case MODE_PARTIAL_INT
:
3640 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3643 case MODE_VECTOR_FLOAT
:
3644 case MODE_VECTOR_INT
:
3645 case MODE_VECTOR_FRACT
:
3646 case MODE_VECTOR_UFRACT
:
3647 case MODE_VECTOR_ACCUM
:
3648 case MODE_VECTOR_UACCUM
:
3651 enum machine_mode submode
= GET_MODE_INNER (mode
);
3652 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3654 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3655 units
= CONST_VECTOR_NUNITS (x
);
3657 for (i
= 0; i
< units
; i
++)
3659 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3660 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3670 /* Worker function for output_constant_pool. Emit constant DESC,
3671 giving it ALIGN bits of alignment. */
3674 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3681 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3682 whose CODE_LABEL has been deleted. This can occur if a jump table
3683 is eliminated by optimization. If so, write a constant of zero
3684 instead. Note that this can also happen by turning the
3685 CODE_LABEL into a NOTE. */
3686 /* ??? This seems completely and utterly wrong. Certainly it's
3687 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3688 functioning even with INSN_DELETED_P and friends. */
3691 switch (GET_CODE (tmp
))
3694 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3695 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3697 tmp
= XEXP (XEXP (tmp
, 0), 0);
3701 tmp
= XEXP (tmp
, 0);
3702 gcc_assert (!INSN_DELETED_P (tmp
));
3703 gcc_assert (!NOTE_P (tmp
)
3704 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3711 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3712 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3713 align
, desc
->labelno
, done
);
3716 assemble_align (align
);
3718 /* Output the label. */
3719 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3721 /* Output the data. */
3722 output_constant_pool_2 (desc
->mode
, x
, align
);
3724 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3725 sections have proper size. */
3726 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3728 && (in_section
->common
.flags
& SECTION_MERGE
))
3729 assemble_align (align
);
3731 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3737 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3738 to as used. Emit referenced deferred strings. This function can
3739 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3742 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
3744 rtx x
= *current_rtx
;
3746 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3749 if (CONSTANT_POOL_ADDRESS_P (x
))
3751 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3752 if (desc
->mark
== 0)
3755 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
3758 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3760 tree decl
= SYMBOL_REF_DECL (x
);
3761 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
3763 n_deferred_constants
--;
3764 output_constant_def_contents (x
);
3771 /* Look through appropriate parts of INSN, marking all entries in the
3772 constant pool which are actually being used. Entries that are only
3773 referenced by other constants are also marked as used. Emit
3774 deferred strings that are used. */
3777 mark_constants (rtx insn
)
3782 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3783 insns, not any notes that may be attached. We don't want to mark
3784 a constant just because it happens to appear in a REG_EQUIV note. */
3785 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3787 rtx seq
= PATTERN (insn
);
3788 int i
, n
= XVECLEN (seq
, 0);
3789 for (i
= 0; i
< n
; ++i
)
3791 rtx subinsn
= XVECEXP (seq
, 0, i
);
3792 if (INSN_P (subinsn
))
3793 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
3797 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
3800 /* Look through the instructions for this function, and mark all the
3801 entries in POOL which are actually being used. Emit deferred constants
3802 which have indeed been used. */
3805 mark_constant_pool (void)
3809 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
3812 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3813 mark_constants (insn
);
3815 for (link
= crtl
->epilogue_delay_list
;
3817 link
= XEXP (link
, 1))
3818 mark_constants (XEXP (link
, 0));
3821 /* Write all the constants in POOL. */
3824 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
3826 struct constant_descriptor_rtx
*desc
;
3828 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3831 /* If the constant is part of an object_block, make sure that
3832 the constant has been positioned within its block, but do not
3833 write out its definition yet. output_object_blocks will do
3835 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
3836 && SYMBOL_REF_BLOCK (desc
->sym
))
3837 place_block_symbol (desc
->sym
);
3840 switch_to_section (targetm
.asm_out
.select_rtx_section
3841 (desc
->mode
, desc
->constant
, desc
->align
));
3842 output_constant_pool_1 (desc
, desc
->align
);
3847 /* Mark all constants that are used in the current function, then write
3848 out the function's private constant pool. */
3851 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3852 tree fndecl ATTRIBUTE_UNUSED
)
3854 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
3856 /* It is possible for gcc to call force_const_mem and then to later
3857 discard the instructions which refer to the constant. In such a
3858 case we do not need to output the constant. */
3859 mark_constant_pool ();
3861 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3862 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3865 output_constant_pool_contents (pool
);
3867 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3868 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3872 /* Write the contents of the shared constant pool. */
3875 output_shared_constant_pool (void)
3877 output_constant_pool_contents (shared_constant_pool
);
3880 /* Determine what kind of relocations EXP may need. */
3883 compute_reloc_for_constant (tree exp
)
3885 int reloc
= 0, reloc2
;
3888 switch (TREE_CODE (exp
))
3892 /* Go inside any operations that get_inner_reference can handle and see
3893 if what's inside is a constant: no need to do anything here for
3894 addresses of variables or functions. */
3895 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3896 tem
= TREE_OPERAND (tem
, 0))
3899 if (TREE_CODE (tem
) == MEM_REF
3900 && TREE_CODE (TREE_OPERAND (tem
, 0)) == ADDR_EXPR
)
3902 reloc
= compute_reloc_for_constant (TREE_OPERAND (tem
, 0));
3906 if (TREE_PUBLIC (tem
))
3913 case POINTER_PLUS_EXPR
:
3914 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3915 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3919 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3920 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3921 /* The difference of two local labels is computable at link time. */
3922 if (reloc
== 1 && reloc2
== 1)
3929 case VIEW_CONVERT_EXPR
:
3930 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3935 unsigned HOST_WIDE_INT idx
;
3936 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3938 reloc
|= compute_reloc_for_constant (tem
);
3948 /* Find all the constants whose addresses are referenced inside of EXP,
3949 and make sure assembler code with a label has been output for each one.
3950 Indicate whether an ADDR_EXPR has been encountered. */
3953 output_addressed_constants (tree exp
)
3957 switch (TREE_CODE (exp
))
3961 /* Go inside any operations that get_inner_reference can handle and see
3962 if what's inside is a constant: no need to do anything here for
3963 addresses of variables or functions. */
3964 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3965 tem
= TREE_OPERAND (tem
, 0))
3968 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3969 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
3970 tem
= DECL_INITIAL (tem
);
3972 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
3973 output_constant_def (tem
, 0);
3975 if (TREE_CODE (tem
) == MEM_REF
)
3976 output_addressed_constants (TREE_OPERAND (tem
, 0));
3980 case POINTER_PLUS_EXPR
:
3982 output_addressed_constants (TREE_OPERAND (exp
, 1));
3986 case VIEW_CONVERT_EXPR
:
3987 output_addressed_constants (TREE_OPERAND (exp
, 0));
3992 unsigned HOST_WIDE_INT idx
;
3993 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3995 output_addressed_constants (tem
);
4004 /* Whether a constructor CTOR is a valid static constant initializer if all
4005 its elements are. This used to be internal to initializer_constant_valid_p
4006 and has been exposed to let other functions like categorize_ctor_elements
4007 evaluate the property while walking a constructor for other purposes. */
4010 constructor_static_from_elts_p (const_tree ctor
)
4012 return (TREE_CONSTANT (ctor
)
4013 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4014 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
4015 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
4018 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4021 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4022 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4023 which are valid when ENDTYPE is an integer of any size; in
4024 particular, this does not accept a pointer minus a constant. This
4025 returns null_pointer_node if the VALUE is an absolute constant
4026 which can be used to initialize a static variable. Otherwise it
4030 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4034 if (!INTEGRAL_TYPE_P (endtype
))
4037 op0
= TREE_OPERAND (value
, 0);
4038 op1
= TREE_OPERAND (value
, 1);
4040 /* Like STRIP_NOPS except allow the operand mode to widen. This
4041 works around a feature of fold that simplifies (int)(p1 - p2) to
4042 ((int)p1 - (int)p2) under the theory that the narrower operation
4045 while (CONVERT_EXPR_P (op0
)
4046 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4048 tree inner
= TREE_OPERAND (op0
, 0);
4049 if (inner
== error_mark_node
4050 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4051 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4052 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4057 while (CONVERT_EXPR_P (op1
)
4058 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4060 tree inner
= TREE_OPERAND (op1
, 0);
4061 if (inner
== error_mark_node
4062 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4063 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4064 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4069 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4073 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4074 cache
? cache
+ 2 : NULL
);
4075 /* Both initializers must be known. */
4079 && (op0
== null_pointer_node
4080 || TREE_CODE (value
) == MINUS_EXPR
))
4081 return null_pointer_node
;
4083 /* Support differences between labels. */
4084 if (TREE_CODE (op0
) == LABEL_DECL
4085 && TREE_CODE (op1
) == LABEL_DECL
)
4086 return null_pointer_node
;
4088 if (TREE_CODE (op0
) == STRING_CST
4089 && TREE_CODE (op1
) == STRING_CST
4090 && operand_equal_p (op0
, op1
, 1))
4091 return null_pointer_node
;
4097 /* Helper function of initializer_constant_valid_p.
4098 Return nonzero if VALUE is a valid constant-valued expression
4099 for use in initializing a static variable; one that can be an
4100 element of a "constant" initializer.
4102 Return null_pointer_node if the value is absolute;
4103 if it is relocatable, return the variable that determines the relocation.
4104 We assume that VALUE has been folded as much as possible;
4105 therefore, we do not need to check for such things as
4106 arithmetic-combinations of integers.
4108 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4111 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4115 switch (TREE_CODE (value
))
4118 if (constructor_static_from_elts_p (value
))
4120 unsigned HOST_WIDE_INT idx
;
4122 bool absolute
= true;
4124 if (cache
&& cache
[0] == value
)
4126 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4129 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4136 cache
[1] = NULL_TREE
;
4140 if (reloc
!= null_pointer_node
)
4143 /* For a non-absolute relocation, there is no single
4144 variable that can be "the variable that determines the
4149 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4151 return absolute
? null_pointer_node
: error_mark_node
;
4154 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4162 return null_pointer_node
;
4167 tree op0
= staticp (TREE_OPERAND (value
, 0));
4170 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4171 to be a constant, this is old-skool offsetof-like nonsense. */
4172 if (TREE_CODE (op0
) == INDIRECT_REF
4173 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4174 return null_pointer_node
;
4175 /* Taking the address of a nested function involves a trampoline,
4176 unless we don't need or want one. */
4177 if (TREE_CODE (op0
) == FUNCTION_DECL
4178 && DECL_STATIC_CHAIN (op0
)
4179 && !TREE_NO_TRAMPOLINE (value
))
4181 /* "&{...}" requires a temporary to hold the constructed
4183 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4189 case NON_LVALUE_EXPR
:
4190 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4193 case VIEW_CONVERT_EXPR
:
4195 tree src
= TREE_OPERAND (value
, 0);
4196 tree src_type
= TREE_TYPE (src
);
4197 tree dest_type
= TREE_TYPE (value
);
4199 /* Allow view-conversions from aggregate to non-aggregate type only
4200 if the bit pattern is fully preserved afterwards; otherwise, the
4201 RTL expander won't be able to apply a subsequent transformation
4202 to the underlying constructor. */
4203 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4205 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4206 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4211 /* Allow all other kinds of view-conversion. */
4212 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4217 tree src
= TREE_OPERAND (value
, 0);
4218 tree src_type
= TREE_TYPE (src
);
4219 tree dest_type
= TREE_TYPE (value
);
4221 /* Allow conversions between pointer types, floating-point
4222 types, and offset types. */
4223 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4224 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4225 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4226 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4227 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4229 /* Allow length-preserving conversions between integer types. */
4230 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4231 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4232 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4234 /* Allow conversions between other integer types only if
4236 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4238 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4239 if (inner
== null_pointer_node
)
4240 return null_pointer_node
;
4244 /* Allow (int) &foo provided int is as wide as a pointer. */
4245 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4246 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4247 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4249 /* Likewise conversions from int to pointers, but also allow
4250 conversions from 0. */
4251 if ((POINTER_TYPE_P (dest_type
)
4252 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4253 && INTEGRAL_TYPE_P (src_type
))
4255 if (TREE_CODE (src
) == INTEGER_CST
4256 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4257 return null_pointer_node
;
4258 if (integer_zerop (src
))
4259 return null_pointer_node
;
4260 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4261 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4264 /* Allow conversions to struct or union types if the value
4266 if (TREE_CODE (dest_type
) == RECORD_TYPE
4267 || TREE_CODE (dest_type
) == UNION_TYPE
)
4268 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4272 case POINTER_PLUS_EXPR
:
4274 /* Any valid floating-point constants will have been folded by now;
4275 with -frounding-math we hit this with addition of two constants. */
4276 if (TREE_CODE (endtype
) == REAL_TYPE
)
4278 if (cache
&& cache
[0] == value
)
4280 if (! INTEGRAL_TYPE_P (endtype
)
4281 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4283 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4285 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4288 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4289 endtype
, ncache
+ 2);
4290 /* If either term is absolute, use the other term's relocation. */
4291 if (valid0
== null_pointer_node
)
4293 else if (valid1
== null_pointer_node
)
4295 /* Support narrowing pointer differences. */
4297 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4301 /* Support narrowing pointer differences. */
4302 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4311 if (TREE_CODE (endtype
) == REAL_TYPE
)
4313 if (cache
&& cache
[0] == value
)
4315 if (! INTEGRAL_TYPE_P (endtype
)
4316 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4318 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4320 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4323 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4324 endtype
, ncache
+ 2);
4325 /* Win if second argument is absolute. */
4326 if (valid1
== null_pointer_node
)
4328 /* Win if both arguments have the same relocation.
4329 Then the value is absolute. */
4330 else if (valid0
== valid1
&& valid0
!= 0)
4331 ret
= null_pointer_node
;
4332 /* Since GCC guarantees that string constants are unique in the
4333 generated code, a subtraction between two copies of the same
4334 constant string is absolute. */
4335 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4336 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4337 && operand_equal_p (valid0
, valid1
, 1))
4338 ret
= null_pointer_node
;
4339 /* Support narrowing differences. */
4341 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4345 /* Support narrowing differences. */
4346 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4361 /* Return nonzero if VALUE is a valid constant-valued expression
4362 for use in initializing a static variable; one that can be an
4363 element of a "constant" initializer.
4365 Return null_pointer_node if the value is absolute;
4366 if it is relocatable, return the variable that determines the relocation.
4367 We assume that VALUE has been folded as much as possible;
4368 therefore, we do not need to check for such things as
4369 arithmetic-combinations of integers. */
4371 initializer_constant_valid_p (tree value
, tree endtype
)
4373 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4376 /* Return true if VALUE is a valid constant-valued expression
4377 for use in initializing a static bit-field; one that can be
4378 an element of a "constant" initializer. */
4381 initializer_constant_valid_for_bitfield_p (tree value
)
4383 /* For bitfields we support integer constants or possibly nested aggregates
4385 switch (TREE_CODE (value
))
4389 unsigned HOST_WIDE_INT idx
;
4392 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4393 if (!initializer_constant_valid_for_bitfield_p (elt
))
4402 case VIEW_CONVERT_EXPR
:
4403 case NON_LVALUE_EXPR
:
4405 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4414 /* output_constructor outer state of relevance in recursive calls, typically
4415 for nested aggregate bitfields. */
4418 unsigned int bit_offset
; /* current position in ... */
4419 int byte
; /* ... the outer byte buffer. */
4422 static unsigned HOST_WIDE_INT
4423 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4426 /* Output assembler code for constant EXP to FILE, with no label.
4427 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4428 Assumes output_addressed_constants has been done on EXP already.
4430 Generate exactly SIZE bytes of assembler data, padding at the end
4431 with zeros if necessary. SIZE must always be specified.
4433 SIZE is important for structure constructors,
4434 since trailing members may have been omitted from the constructor.
4435 It is also important for initialization of arrays from string constants
4436 since the full length of the string constant might not be wanted.
4437 It is also needed for initialization of unions, where the initializer's
4438 type is just one member, and that may not be as long as the union.
4440 There a case in which we would fail to output exactly SIZE bytes:
4441 for a structure constructor that wants to produce more than SIZE bytes.
4442 But such constructors will never be generated for any possible input.
4444 ALIGN is the alignment of the data in bits. */
4447 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4449 enum tree_code code
;
4450 unsigned HOST_WIDE_INT thissize
;
4452 if (size
== 0 || flag_syntax_only
)
4455 /* See if we're trying to initialize a pointer in a non-default mode
4456 to the address of some declaration somewhere. If the target says
4457 the mode is valid for pointers, assume the target has a way of
4459 if (TREE_CODE (exp
) == NOP_EXPR
4460 && POINTER_TYPE_P (TREE_TYPE (exp
))
4461 && targetm
.addr_space
.valid_pointer_mode
4462 (TYPE_MODE (TREE_TYPE (exp
)),
4463 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4465 tree saved_type
= TREE_TYPE (exp
);
4467 /* Peel off any intermediate conversions-to-pointer for valid
4469 while (TREE_CODE (exp
) == NOP_EXPR
4470 && POINTER_TYPE_P (TREE_TYPE (exp
))
4471 && targetm
.addr_space
.valid_pointer_mode
4472 (TYPE_MODE (TREE_TYPE (exp
)),
4473 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4474 exp
= TREE_OPERAND (exp
, 0);
4476 /* If what we're left with is the address of something, we can
4477 convert the address to the final type and output it that
4479 if (TREE_CODE (exp
) == ADDR_EXPR
)
4480 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4481 /* Likewise for constant ints. */
4482 else if (TREE_CODE (exp
) == INTEGER_CST
)
4483 exp
= build_int_cst_wide (saved_type
, TREE_INT_CST_LOW (exp
),
4484 TREE_INT_CST_HIGH (exp
));
4488 /* Eliminate any conversions since we'll be outputting the underlying
4490 while (CONVERT_EXPR_P (exp
)
4491 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4492 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4494 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4495 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4497 /* Make sure eliminating the conversion is really a no-op, except with
4498 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4499 union types to allow for Ada unchecked unions. */
4500 if (type_size
> op_size
4501 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4502 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4503 /* Keep the conversion. */
4506 exp
= TREE_OPERAND (exp
, 0);
4509 code
= TREE_CODE (TREE_TYPE (exp
));
4510 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4512 /* Allow a constructor with no elements for any data type.
4513 This means to fill the space with zeros. */
4514 if (TREE_CODE (exp
) == CONSTRUCTOR
4515 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
4517 assemble_zeros (size
);
4521 if (TREE_CODE (exp
) == FDESC_EXPR
)
4523 #ifdef ASM_OUTPUT_FDESC
4524 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4525 tree decl
= TREE_OPERAND (exp
, 0);
4526 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4533 /* Now output the underlying data. If we've handling the padding, return.
4534 Otherwise, break and ensure SIZE is the size written. */
4541 case REFERENCE_TYPE
:
4543 case FIXED_POINT_TYPE
:
4544 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4545 EXPAND_INITIALIZER
),
4546 MIN (size
, thissize
), align
, 0))
4547 error ("initializer for integer/fixed-point value is too complicated");
4551 if (TREE_CODE (exp
) != REAL_CST
)
4552 error ("initializer for floating value is not a floating constant");
4554 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4558 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4559 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4560 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4565 switch (TREE_CODE (exp
))
4568 output_constructor (exp
, size
, align
, NULL
);
4571 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
4573 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4579 unsigned int i
, nalign
;
4580 enum machine_mode inner
;
4582 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4583 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4585 elt_size
= GET_MODE_SIZE (inner
);
4587 output_constant (VECTOR_CST_ELT (exp
, 0), elt_size
, align
);
4588 thissize
= elt_size
;
4589 for (i
= 1; i
< VECTOR_CST_NELTS (exp
); ++i
)
4591 output_constant (VECTOR_CST_ELT (exp
, i
), elt_size
, nalign
);
4592 thissize
+= elt_size
;
4603 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4604 output_constructor (exp
, size
, align
, NULL
);
4614 if (size
> thissize
)
4615 assemble_zeros (size
- thissize
);
4619 /* Subroutine of output_constructor, used for computing the size of
4620 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4621 type with an unspecified upper bound. */
4623 static unsigned HOST_WIDE_INT
4624 array_size_for_constructor (tree val
)
4627 unsigned HOST_WIDE_INT cnt
;
4628 tree index
, value
, tmp
;
4631 /* This code used to attempt to handle string constants that are not
4632 arrays of single-bytes, but nothing else does, so there's no point in
4634 if (TREE_CODE (val
) == STRING_CST
)
4635 return TREE_STRING_LENGTH (val
);
4637 max_index
= NULL_TREE
;
4638 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4640 if (TREE_CODE (index
) == RANGE_EXPR
)
4641 index
= TREE_OPERAND (index
, 1);
4642 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4646 if (max_index
== NULL_TREE
)
4649 /* Compute the total number of array elements. */
4650 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4651 i
= tree_to_double_int (max_index
) - tree_to_double_int (tmp
);
4652 i
+= double_int_one
;
4654 /* Multiply by the array element unit size to find number of bytes. */
4655 i
*= tree_to_double_int (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4657 gcc_assert (i
.fits_uhwi ());
4661 /* Other datastructures + helpers for output_constructor. */
4663 /* output_constructor local state to support interaction with helpers. */
4667 /* Received arguments. */
4668 tree exp
; /* Constructor expression. */
4669 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4670 unsigned int align
; /* Known initial alignment. */
4672 /* Constructor expression data. */
4673 tree type
; /* Expression type. */
4674 tree field
; /* Current field decl in a record. */
4675 tree min_index
; /* Lower bound if specified for an array. */
4677 /* Output processing state. */
4678 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4679 bool byte_buffer_in_use
; /* Whether byte ... */
4680 int byte
; /* ... contains part of a bitfield byte yet to
4683 int last_relative_index
; /* Implicit or explicit index of the last
4684 array element output within a bitfield. */
4685 /* Current element. */
4686 tree val
; /* Current element value. */
4687 tree index
; /* Current element index. */
4691 /* Helper for output_constructor. From the current LOCAL state, output a
4692 RANGE_EXPR element. */
4695 output_constructor_array_range (oc_local_state
*local
)
4697 unsigned HOST_WIDE_INT fieldsize
4698 = int_size_in_bytes (TREE_TYPE (local
->type
));
4700 HOST_WIDE_INT lo_index
4701 = tree_low_cst (TREE_OPERAND (local
->index
, 0), 0);
4702 HOST_WIDE_INT hi_index
4703 = tree_low_cst (TREE_OPERAND (local
->index
, 1), 0);
4704 HOST_WIDE_INT index
;
4707 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4709 for (index
= lo_index
; index
<= hi_index
; index
++)
4711 /* Output the element's initial value. */
4712 if (local
->val
== NULL_TREE
)
4713 assemble_zeros (fieldsize
);
4715 output_constant (local
->val
, fieldsize
, align2
);
4717 /* Count its size. */
4718 local
->total_bytes
+= fieldsize
;
4722 /* Helper for output_constructor. From the current LOCAL state, output a
4723 field element that is not true bitfield or part of an outer one. */
4726 output_constructor_regular_field (oc_local_state
*local
)
4728 /* Field size and position. Since this structure is static, we know the
4729 positions are constant. */
4730 unsigned HOST_WIDE_INT fieldsize
;
4731 HOST_WIDE_INT fieldpos
;
4733 unsigned int align2
;
4735 if (local
->index
!= NULL_TREE
)
4737 /* Perform the index calculation in modulo arithmetic but
4738 sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
4739 but we are using an unsigned sizetype. */
4740 unsigned prec
= TYPE_PRECISION (sizetype
);
4741 double_int idx
= tree_to_double_int (local
->index
)
4742 - tree_to_double_int (local
->min_index
);
4743 idx
= idx
.sext (prec
);
4744 fieldpos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
)), 1)
4747 else if (local
->field
!= NULL_TREE
)
4748 fieldpos
= int_byte_position (local
->field
);
4752 /* Output any buffered-up bit-fields preceding this element. */
4753 if (local
->byte_buffer_in_use
)
4755 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4756 local
->total_bytes
++;
4757 local
->byte_buffer_in_use
= false;
4760 /* Advance to offset of this element.
4761 Note no alignment needed in an array, since that is guaranteed
4762 if each element has the proper size. */
4763 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4764 && fieldpos
!= local
->total_bytes
)
4766 gcc_assert (fieldpos
>= local
->total_bytes
);
4767 assemble_zeros (fieldpos
- local
->total_bytes
);
4768 local
->total_bytes
= fieldpos
;
4771 /* Find the alignment of this element. */
4772 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
4774 /* Determine size this element should occupy. */
4779 /* If this is an array with an unspecified upper bound,
4780 the initializer determines the size. */
4781 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4782 but we cannot do this until the deprecated support for
4783 initializing zero-length array members is removed. */
4784 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
4785 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
4786 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
4788 fieldsize
= array_size_for_constructor (local
->val
);
4789 /* Given a non-empty initialization, this field had
4791 gcc_assert (!fieldsize
|| !DECL_CHAIN (local
->field
));
4794 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (local
->field
), 1);
4797 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
4799 /* Output the element's initial value. */
4800 if (local
->val
== NULL_TREE
)
4801 assemble_zeros (fieldsize
);
4803 output_constant (local
->val
, fieldsize
, align2
);
4805 /* Count its size. */
4806 local
->total_bytes
+= fieldsize
;
4809 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4810 output an element that is a true bitfield or part of an outer one. */
4813 output_constructor_bitfield (oc_local_state
*local
, oc_outer_state
*outer
)
4815 /* Bit size of this element. */
4816 HOST_WIDE_INT ebitsize
4818 ? tree_low_cst (DECL_SIZE (local
->field
), 1)
4819 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local
->type
)), 1));
4821 /* Relative index of this element if this is an array component. */
4822 HOST_WIDE_INT relative_index
4825 ? (tree_low_cst (local
->index
, 0)
4826 - tree_low_cst (local
->min_index
, 0))
4827 : local
->last_relative_index
+ 1)
4830 /* Bit position of this element from the start of the containing
4832 HOST_WIDE_INT constructor_relative_ebitpos
4834 ? int_bit_position (local
->field
)
4835 : ebitsize
* relative_index
);
4837 /* Bit position of this element from the start of a possibly ongoing
4838 outer byte buffer. */
4839 HOST_WIDE_INT byte_relative_ebitpos
4840 = ((outer
? outer
->bit_offset
: 0) + constructor_relative_ebitpos
);
4842 /* From the start of a possibly ongoing outer byte buffer, offsets to
4843 the first bit of this element and to the first bit past the end of
4845 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
4846 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
4848 local
->last_relative_index
= relative_index
;
4850 if (local
->val
== NULL_TREE
)
4851 local
->val
= integer_zero_node
;
4853 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
4854 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
4855 local
->val
= TREE_OPERAND (local
->val
, 0);
4857 if (TREE_CODE (local
->val
) != INTEGER_CST
4858 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
4860 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
4864 /* If this field does not start in this (or, next) byte,
4866 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4868 /* Output remnant of any bit field in previous bytes. */
4869 if (local
->byte_buffer_in_use
)
4871 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4872 local
->total_bytes
++;
4873 local
->byte_buffer_in_use
= false;
4876 /* If still not at proper byte, advance to there. */
4877 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4879 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
4880 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
4881 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
4885 /* Set up the buffer if necessary. */
4886 if (!local
->byte_buffer_in_use
)
4890 local
->byte_buffer_in_use
= true;
4893 /* If this is nested constructor, recurse passing the bit offset and the
4894 pending data, then retrieve the new pending data afterwards. */
4895 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
4897 oc_outer_state output_state
;
4899 output_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
4900 output_state
.byte
= local
->byte
;
4902 += output_constructor (local
->val
, 0, 0, &output_state
);
4903 local
->byte
= output_state
.byte
;
4907 /* Otherwise, we must split the element into pieces that fall within
4908 separate bytes, and combine each byte with previous or following
4910 while (next_offset
< end_offset
)
4914 HOST_WIDE_INT value
;
4915 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4916 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4918 /* Advance from byte to byte
4919 within this element when necessary. */
4920 while (next_byte
!= local
->total_bytes
)
4922 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4923 local
->total_bytes
++;
4927 /* Number of bits we can process at once
4928 (all part of the same byte). */
4929 this_time
= MIN (end_offset
- next_offset
,
4930 BITS_PER_UNIT
- next_bit
);
4931 if (BYTES_BIG_ENDIAN
)
4933 /* On big-endian machine, take the most significant bits
4934 first (of the bits that are significant)
4935 and put them into bytes from the most significant end. */
4936 shift
= end_offset
- next_offset
- this_time
;
4938 /* Don't try to take a bunch of bits that cross
4939 the word boundary in the INTEGER_CST. We can
4940 only select bits from the LOW or HIGH part
4942 if (shift
< HOST_BITS_PER_WIDE_INT
4943 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4945 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4946 shift
= HOST_BITS_PER_WIDE_INT
;
4949 /* Now get the bits from the appropriate constant word. */
4950 if (shift
< HOST_BITS_PER_WIDE_INT
)
4951 value
= TREE_INT_CST_LOW (local
->val
);
4954 gcc_assert (shift
< HOST_BITS_PER_DOUBLE_INT
);
4955 value
= TREE_INT_CST_HIGH (local
->val
);
4956 shift
-= HOST_BITS_PER_WIDE_INT
;
4959 /* Get the result. This works only when:
4960 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4961 local
->byte
|= (((value
>> shift
)
4962 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4963 << (BITS_PER_UNIT
- this_time
- next_bit
));
4967 /* On little-endian machines,
4968 take first the least significant bits of the value
4969 and pack them starting at the least significant
4970 bits of the bytes. */
4971 shift
= next_offset
- byte_relative_ebitpos
;
4973 /* Don't try to take a bunch of bits that cross
4974 the word boundary in the INTEGER_CST. We can
4975 only select bits from the LOW or HIGH part
4977 if (shift
< HOST_BITS_PER_WIDE_INT
4978 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4979 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4981 /* Now get the bits from the appropriate constant word. */
4982 if (shift
< HOST_BITS_PER_WIDE_INT
)
4983 value
= TREE_INT_CST_LOW (local
->val
);
4986 gcc_assert (shift
< HOST_BITS_PER_DOUBLE_INT
);
4987 value
= TREE_INT_CST_HIGH (local
->val
);
4988 shift
-= HOST_BITS_PER_WIDE_INT
;
4991 /* Get the result. This works only when:
4992 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4993 local
->byte
|= (((value
>> shift
)
4994 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4998 next_offset
+= this_time
;
4999 local
->byte_buffer_in_use
= true;
5003 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5004 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5005 caller output state of relevance in recursive invocations. */
5007 static unsigned HOST_WIDE_INT
5008 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5009 unsigned int align
, oc_outer_state
* outer
)
5011 unsigned HOST_WIDE_INT cnt
;
5012 constructor_elt
*ce
;
5014 oc_local_state local
;
5016 /* Setup our local state to communicate with helpers. */
5019 local
.align
= align
;
5021 local
.total_bytes
= 0;
5022 local
.byte_buffer_in_use
= outer
!= NULL
;
5023 local
.byte
= outer
? outer
->byte
: 0;
5025 local
.type
= TREE_TYPE (exp
);
5027 local
.last_relative_index
= -1;
5029 local
.min_index
= NULL_TREE
;
5030 if (TREE_CODE (local
.type
) == ARRAY_TYPE
5031 && TYPE_DOMAIN (local
.type
) != NULL_TREE
)
5032 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5034 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5036 /* As CE goes through the elements of the constant, FIELD goes through the
5037 structure fields if the constant is a structure. If the constant is a
5038 union, we override this by getting the field from the TREE_LIST element.
5039 But the constant could also be an array. Then FIELD is zero.
5041 There is always a maximum of one element in the chain LINK for unions
5042 (even if the initializer in a source program incorrectly contains
5045 local
.field
= NULL_TREE
;
5046 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5047 local
.field
= TYPE_FIELDS (local
.type
);
5050 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
5051 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
5053 local
.val
= ce
->value
;
5054 local
.index
= NULL_TREE
;
5056 /* The element in a union constructor specifies the proper field
5058 if (RECORD_OR_UNION_TYPE_P (local
.type
) && ce
->index
!= NULL_TREE
)
5059 local
.field
= ce
->index
;
5061 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5062 local
.index
= ce
->index
;
5064 if (local
.field
&& flag_verbose_asm
)
5065 fprintf (asm_out_file
, "%s %s:\n",
5067 DECL_NAME (local
.field
)
5068 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5071 /* Eliminate the marker that makes a cast not be an lvalue. */
5072 if (local
.val
!= NULL_TREE
)
5073 STRIP_NOPS (local
.val
);
5075 /* Output the current element, using the appropriate helper ... */
5077 /* For an array slice not part of an outer bitfield. */
5079 && local
.index
!= NULL_TREE
5080 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5081 output_constructor_array_range (&local
);
5083 /* For a field that is neither a true bitfield nor part of an outer one,
5084 known to be at least byte aligned and multiple-of-bytes long. */
5086 && (local
.field
== NULL_TREE
5087 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5088 output_constructor_regular_field (&local
);
5090 /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
5091 supported for scalar fields, so we may need to convert first. */
5094 if (TREE_CODE (local
.val
) == REAL_CST
)
5096 = fold_unary (VIEW_CONVERT_EXPR
,
5097 build_nonstandard_integer_type
5098 (TYPE_PRECISION (TREE_TYPE (local
.val
)), 0),
5100 output_constructor_bitfield (&local
, outer
);
5104 /* If we are not at toplevel, save the pending data for our caller.
5105 Otherwise output the pending data and padding zeros as needed. */
5107 outer
->byte
= local
.byte
;
5110 if (local
.byte_buffer_in_use
)
5112 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5113 local
.total_bytes
++;
5116 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5118 assemble_zeros (local
.size
- local
.total_bytes
);
5119 local
.total_bytes
= local
.size
;
5123 return local
.total_bytes
;
5126 /* Mark DECL as weak. */
5129 mark_weak (tree decl
)
5131 DECL_WEAK (decl
) = 1;
5133 if (DECL_RTL_SET_P (decl
)
5134 && MEM_P (DECL_RTL (decl
))
5135 && XEXP (DECL_RTL (decl
), 0)
5136 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5137 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5140 /* Merge weak status between NEWDECL and OLDDECL. */
5143 merge_weak (tree newdecl
, tree olddecl
)
5145 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5147 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5150 /* We put the NEWDECL on the weak_decls list at some point
5151 and OLDDECL as well. Keep just OLDDECL on the list. */
5152 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5153 if (TREE_VALUE (*pwd
) == newdecl
)
5155 *pwd
= TREE_CHAIN (*pwd
);
5162 if (DECL_WEAK (newdecl
))
5166 /* NEWDECL is weak, but OLDDECL is not. */
5168 /* If we already output the OLDDECL, we're in trouble; we can't
5169 go back and make it weak. This should never happen in
5170 unit-at-a-time compilation. */
5171 gcc_assert (!TREE_ASM_WRITTEN (olddecl
));
5173 /* If we've already generated rtl referencing OLDDECL, we may
5174 have done so in a way that will not function properly with
5175 a weak symbol. Again in unit-at-a-time this should be
5177 gcc_assert (!TREE_USED (olddecl
)
5178 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)));
5180 if (TARGET_SUPPORTS_WEAK
)
5182 /* We put the NEWDECL on the weak_decls list at some point.
5183 Replace it with the OLDDECL. */
5184 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5185 if (TREE_VALUE (wd
) == newdecl
)
5187 TREE_VALUE (wd
) = olddecl
;
5190 /* We may not find the entry on the list. If NEWDECL is a
5191 weak alias, then we will have already called
5192 globalize_decl to remove the entry; in that case, we do
5193 not need to do anything. */
5196 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5197 mark_weak (olddecl
);
5200 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5201 weak. Just update NEWDECL to indicate that it's weak too. */
5202 mark_weak (newdecl
);
5205 /* Declare DECL to be a weak symbol. */
5208 declare_weak (tree decl
)
5210 gcc_assert (TREE_CODE (decl
) != FUNCTION_DECL
|| !TREE_ASM_WRITTEN (decl
));
5211 if (! TREE_PUBLIC (decl
))
5212 error ("weak declaration of %q+D must be public", decl
);
5213 else if (!TARGET_SUPPORTS_WEAK
)
5214 warning (0, "weak declaration of %q+D not supported", decl
);
5217 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5218 DECL_ATTRIBUTES (decl
)
5219 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5223 weak_finish_1 (tree decl
)
5225 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5226 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5229 if (! TREE_USED (decl
))
5232 #ifdef ASM_WEAKEN_DECL
5233 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5235 #ifdef ASM_WEAKEN_LABEL
5236 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5238 #ifdef ASM_OUTPUT_WEAK_ALIAS
5240 static bool warn_once
= 0;
5243 warning (0, "only weak aliases are supported in this configuration");
5253 /* Fiven an assembly name, find the decl it is associated with. */
5255 find_decl (tree target
)
5257 symtab_node node
= symtab_node_for_asm (target
);
5259 return node
->symbol
.decl
;
5263 /* This TREE_LIST contains weakref targets. */
5265 static GTY(()) tree weakref_targets
;
5267 /* Emit any pending weak declarations. */
5274 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5276 tree alias_decl
= TREE_PURPOSE (t
);
5277 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5279 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5280 /* Remove alias_decl from the weak list, but leave entries for
5281 the target alone. */
5283 #ifndef ASM_OUTPUT_WEAKREF
5284 else if (! TREE_SYMBOL_REFERENCED (target
))
5286 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5287 defined, otherwise we and weak_finish_1 would use
5288 different macros. */
5289 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5290 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5292 tree decl
= find_decl (target
);
5296 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5297 TREE_CODE (alias_decl
), target
,
5298 TREE_TYPE (alias_decl
));
5300 DECL_EXTERNAL (decl
) = 1;
5301 TREE_PUBLIC (decl
) = 1;
5302 DECL_ARTIFICIAL (decl
) = 1;
5303 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5304 TREE_USED (decl
) = 1;
5307 weak_finish_1 (decl
);
5316 /* Remove the alias and the target from the pending weak list
5317 so that we do not emit any .weak directives for the former,
5318 nor multiple .weak directives for the latter. */
5319 for (p
= &weak_decls
; (t2
= *p
) ; )
5321 if (TREE_VALUE (t2
) == alias_decl
5322 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5323 *p
= TREE_CHAIN (t2
);
5325 p
= &TREE_CHAIN (t2
);
5328 /* Remove other weakrefs to the same target, to speed things up. */
5329 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5331 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5332 *p
= TREE_CHAIN (t2
);
5334 p
= &TREE_CHAIN (t2
);
5339 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5341 tree decl
= TREE_VALUE (t
);
5343 weak_finish_1 (decl
);
5347 /* Emit the assembly bits to indicate that DECL is globally visible. */
5350 globalize_decl (tree decl
)
5353 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5354 if (DECL_WEAK (decl
))
5356 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5359 #ifdef ASM_WEAKEN_DECL
5360 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5362 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5365 /* Remove this function from the pending weak list so that
5366 we do not emit multiple .weak directives for it. */
5367 for (p
= &weak_decls
; (t
= *p
) ; )
5369 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5370 *p
= TREE_CHAIN (t
);
5372 p
= &TREE_CHAIN (t
);
5375 /* Remove weakrefs to the same target from the pending weakref
5376 list, for the same reason. */
5377 for (p
= &weakref_targets
; (t
= *p
) ; )
5379 if (DECL_ASSEMBLER_NAME (decl
)
5380 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5381 *p
= TREE_CHAIN (t
);
5383 p
= &TREE_CHAIN (t
);
5390 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5393 VEC(alias_pair
,gc
) *alias_pairs
;
5395 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5396 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5397 tree node is DECL to have the value of the tree node TARGET. */
5400 do_assemble_alias (tree decl
, tree target
)
5402 /* Emulated TLS had better not get this var. */
5403 gcc_assert(!(!targetm
.have_tls
5404 && TREE_CODE (decl
) == VAR_DECL
5405 && DECL_THREAD_LOCAL_P (decl
)));
5407 if (TREE_ASM_WRITTEN (decl
))
5410 /* We must force creation of DECL_RTL for debug info generation, even though
5411 we don't use it here. */
5412 make_decl_rtl (decl
);
5414 TREE_ASM_WRITTEN (decl
) = 1;
5415 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5417 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5419 ultimate_transparent_alias_target (&target
);
5421 if (!TREE_SYMBOL_REFERENCED (target
))
5422 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5424 #ifdef ASM_OUTPUT_WEAKREF
5425 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5426 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5427 IDENTIFIER_POINTER (target
));
5429 if (!TARGET_SUPPORTS_WEAK
)
5431 error_at (DECL_SOURCE_LOCATION (decl
),
5432 "weakref is not supported in this configuration");
5439 #ifdef ASM_OUTPUT_DEF
5440 /* Make name accessible from other files, if appropriate. */
5442 if (TREE_PUBLIC (decl
))
5444 globalize_decl (decl
);
5445 maybe_assemble_visibility (decl
);
5447 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5449 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
5450 ASM_OUTPUT_TYPE_DIRECTIVE
5451 (asm_out_file
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5454 error_at (DECL_SOURCE_LOCATION (decl
),
5455 "ifunc is not supported in this configuration");
5459 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5460 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5462 ASM_OUTPUT_DEF (asm_out_file
,
5463 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5464 IDENTIFIER_POINTER (target
));
5466 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5471 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5472 # ifdef ASM_WEAKEN_DECL
5473 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5475 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5477 /* Remove this function from the pending weak list so that
5478 we do not emit multiple .weak directives for it. */
5479 for (p
= &weak_decls
; (t
= *p
) ; )
5480 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5481 *p
= TREE_CHAIN (t
);
5483 p
= &TREE_CHAIN (t
);
5485 /* Remove weakrefs to the same target from the pending weakref
5486 list, for the same reason. */
5487 for (p
= &weakref_targets
; (t
= *p
) ; )
5489 if (DECL_ASSEMBLER_NAME (decl
)
5490 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5491 *p
= TREE_CHAIN (t
);
5493 p
= &TREE_CHAIN (t
);
5499 /* Emit an assembler directive to make the symbol for DECL an alias to
5500 the symbol for TARGET. */
5503 assemble_alias (tree decl
, tree target
)
5507 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5509 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5511 ultimate_transparent_alias_target (&target
);
5513 if (alias
== target
)
5514 error ("weakref %q+D ultimately targets itself", decl
);
5517 #ifndef ASM_OUTPUT_WEAKREF
5518 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
5519 TREE_CHAIN (alias
) = target
;
5522 if (TREE_PUBLIC (decl
))
5523 error ("weakref %q+D must have static linkage", decl
);
5527 #if !defined (ASM_OUTPUT_DEF)
5528 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5529 error_at (DECL_SOURCE_LOCATION (decl
),
5530 "alias definitions not supported in this configuration");
5533 if (!DECL_WEAK (decl
))
5535 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5536 error_at (DECL_SOURCE_LOCATION (decl
),
5537 "ifunc is not supported in this configuration");
5539 error_at (DECL_SOURCE_LOCATION (decl
),
5540 "only weak aliases are supported in this configuration");
5546 TREE_USED (decl
) = 1;
5548 /* Allow aliases to aliases. */
5549 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5550 cgraph_get_create_node (decl
)->alias
= true;
5552 varpool_node (decl
)->alias
= true;
5554 /* If the target has already been emitted, we don't have to queue the
5555 alias. This saves a tad of memory. */
5556 if (cgraph_global_info_ready
)
5557 target_decl
= find_decl (target
);
5560 if ((target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5561 || cgraph_state
>= CGRAPH_STATE_EXPANSION
)
5562 do_assemble_alias (decl
, target
);
5565 alias_pair p
= {decl
, target
};
5566 VEC_safe_push (alias_pair
, gc
, alias_pairs
, p
);
5570 /* Record and output a table of translations from original function
5571 to its transaction aware clone. Note that tm_pure functions are
5572 considered to be their own clone. */
5574 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
5575 htab_t tm_clone_hash
;
5578 record_tm_clone_pair (tree o
, tree n
)
5580 struct tree_map
**slot
, *h
;
5582 if (tm_clone_hash
== NULL
)
5583 tm_clone_hash
= htab_create_ggc (32, tree_map_hash
, tree_map_eq
, 0);
5585 h
= ggc_alloc_tree_map ();
5586 h
->hash
= htab_hash_pointer (o
);
5590 slot
= (struct tree_map
**)
5591 htab_find_slot_with_hash (tm_clone_hash
, h
, h
->hash
, INSERT
);
5596 get_tm_clone_pair (tree o
)
5600 struct tree_map
*h
, in
;
5603 in
.hash
= htab_hash_pointer (o
);
5604 h
= (struct tree_map
*) htab_find_with_hash (tm_clone_hash
,
5612 typedef struct tm_alias_pair
5619 DEF_VEC_O(tm_alias_pair
);
5620 DEF_VEC_ALLOC_O(tm_alias_pair
,heap
);
5622 /* Helper function for finish_tm_clone_pairs. Dump a hash table entry
5623 into a VEC in INFO. */
5626 dump_tm_clone_to_vec (void **slot
, void *info
)
5628 struct tree_map
*map
= (struct tree_map
*) *slot
;
5629 VEC(tm_alias_pair
,heap
) **tm_alias_pairs
= (VEC(tm_alias_pair
, heap
) **) info
;
5630 tm_alias_pair p
= {DECL_UID (map
->base
.from
), map
->base
.from
, map
->to
};
5631 VEC_safe_push (tm_alias_pair
, heap
, *tm_alias_pairs
, p
);
5635 /* Dump the actual pairs to the .tm_clone_table section. */
5638 dump_tm_clone_pairs (VEC(tm_alias_pair
,heap
) *tm_alias_pairs
)
5642 bool switched
= false;
5644 FOR_EACH_VEC_ELT (tm_alias_pair
, tm_alias_pairs
, i
, p
)
5648 struct cgraph_node
*src_n
= cgraph_get_node (src
);
5649 struct cgraph_node
*dst_n
= cgraph_get_node (dst
);
5651 /* The function ipa_tm_create_version() marks the clone as needed if
5652 the original function was needed. But we also mark the clone as
5653 needed if we ever called the clone indirectly through
5654 TM_GETTMCLONE. If neither of these are true, we didn't generate
5655 a clone, and we didn't call it indirectly... no sense keeping it
5656 in the clone table. */
5657 if (!dst_n
|| !dst_n
->analyzed
)
5660 /* This covers the case where we have optimized the original
5661 function away, and only access the transactional clone. */
5662 if (!src_n
|| !src_n
->analyzed
)
5667 switch_to_section (targetm
.asm_out
.tm_clone_table_section ());
5668 assemble_align (POINTER_SIZE
);
5672 assemble_integer (XEXP (DECL_RTL (src
), 0),
5673 POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
5674 assemble_integer (XEXP (DECL_RTL (dst
), 0),
5675 POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
5679 /* Provide a default for the tm_clone_table section. */
5682 default_clone_table_section (void)
5684 return get_named_section (NULL
, ".tm_clone_table", 3);
5687 /* Helper comparison function for qsorting by the DECL_UID stored in
5688 alias_pair->emitted_diags. */
5691 tm_alias_pair_cmp (const void *x
, const void *y
)
5693 const tm_alias_pair
*p1
= (const tm_alias_pair
*) x
;
5694 const tm_alias_pair
*p2
= (const tm_alias_pair
*) y
;
5695 if (p1
->uid
< p2
->uid
)
5697 if (p1
->uid
> p2
->uid
)
5703 finish_tm_clone_pairs (void)
5705 VEC(tm_alias_pair
,heap
) *tm_alias_pairs
= NULL
;
5707 if (tm_clone_hash
== NULL
)
5710 /* We need a determenistic order for the .tm_clone_table, otherwise
5711 we will get bootstrap comparison failures, so dump the hash table
5712 to a vector, sort it, and dump the vector. */
5714 /* Dump the hashtable to a vector. */
5715 htab_traverse_noresize (tm_clone_hash
, dump_tm_clone_to_vec
,
5716 (void *) &tm_alias_pairs
);
5718 VEC_qsort (tm_alias_pair
, tm_alias_pairs
, tm_alias_pair_cmp
);
5721 dump_tm_clone_pairs (tm_alias_pairs
);
5723 htab_delete (tm_clone_hash
);
5724 tm_clone_hash
= NULL
;
5725 VEC_free (tm_alias_pair
, heap
, tm_alias_pairs
);
5729 /* Emit an assembler directive to set symbol for DECL visibility to
5730 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5733 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5734 int vis ATTRIBUTE_UNUSED
)
5736 #ifdef HAVE_GAS_HIDDEN
5737 static const char * const visibility_types
[] = {
5738 NULL
, "protected", "hidden", "internal"
5741 const char *name
, *type
;
5743 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5744 type
= visibility_types
[vis
];
5746 fprintf (asm_out_file
, "\t.%s\t", type
);
5747 assemble_name (asm_out_file
, name
);
5748 fprintf (asm_out_file
, "\n");
5750 warning (OPT_Wattributes
, "visibility attribute not supported "
5751 "in this configuration; ignored");
5755 /* A helper function to call assemble_visibility when needed for a decl. */
5758 maybe_assemble_visibility (tree decl
)
5760 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5762 if (vis
!= VISIBILITY_DEFAULT
)
5764 targetm
.asm_out
.assemble_visibility (decl
, vis
);
5771 /* Returns 1 if the target configuration supports defining public symbols
5772 so that one of them will be chosen at link time instead of generating a
5773 multiply-defined symbol error, whether through the use of weak symbols or
5774 a target-specific mechanism for having duplicates discarded. */
5777 supports_one_only (void)
5779 if (SUPPORTS_ONE_ONLY
)
5781 return TARGET_SUPPORTS_WEAK
;
5784 /* Set up DECL as a public symbol that can be defined in multiple
5785 translation units without generating a linker error. */
5788 make_decl_one_only (tree decl
, tree comdat_group
)
5790 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5791 || TREE_CODE (decl
) == FUNCTION_DECL
);
5793 TREE_PUBLIC (decl
) = 1;
5795 if (SUPPORTS_ONE_ONLY
)
5797 #ifdef MAKE_DECL_ONE_ONLY
5798 MAKE_DECL_ONE_ONLY (decl
);
5800 DECL_COMDAT_GROUP (decl
) = comdat_group
;
5802 else if (TREE_CODE (decl
) == VAR_DECL
5803 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5804 DECL_COMMON (decl
) = 1;
5807 gcc_assert (TARGET_SUPPORTS_WEAK
);
5808 DECL_WEAK (decl
) = 1;
5813 init_varasm_once (void)
5815 section_htab
= htab_create_ggc (31, section_entry_hash
,
5816 section_entry_eq
, NULL
);
5817 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
5818 object_block_entry_eq
, NULL
);
5819 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
5820 const_desc_eq
, NULL
);
5822 const_alias_set
= new_alias_set ();
5823 shared_constant_pool
= create_constant_pool ();
5825 #ifdef TEXT_SECTION_ASM_OP
5826 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
5827 TEXT_SECTION_ASM_OP
);
5830 #ifdef DATA_SECTION_ASM_OP
5831 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5832 DATA_SECTION_ASM_OP
);
5835 #ifdef SDATA_SECTION_ASM_OP
5836 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5837 SDATA_SECTION_ASM_OP
);
5840 #ifdef READONLY_DATA_SECTION_ASM_OP
5841 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
5842 READONLY_DATA_SECTION_ASM_OP
);
5845 #ifdef CTORS_SECTION_ASM_OP
5846 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
5847 CTORS_SECTION_ASM_OP
);
5850 #ifdef DTORS_SECTION_ASM_OP
5851 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
5852 DTORS_SECTION_ASM_OP
);
5855 #ifdef BSS_SECTION_ASM_OP
5856 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5857 output_section_asm_op
,
5858 BSS_SECTION_ASM_OP
);
5861 #ifdef SBSS_SECTION_ASM_OP
5862 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5863 output_section_asm_op
,
5864 SBSS_SECTION_ASM_OP
);
5867 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5868 | SECTION_COMMON
, emit_tls_common
);
5869 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5870 | SECTION_COMMON
, emit_local
);
5871 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5872 | SECTION_COMMON
, emit_common
);
5874 #if defined ASM_OUTPUT_ALIGNED_BSS
5875 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
5879 targetm
.asm_out
.init_sections ();
5881 if (readonly_data_section
== NULL
)
5882 readonly_data_section
= text_section
;
5886 decl_default_tls_model (const_tree decl
)
5888 enum tls_model kind
;
5891 is_local
= targetm
.binds_local_p (decl
);
5895 kind
= TLS_MODEL_LOCAL_EXEC
;
5897 kind
= TLS_MODEL_INITIAL_EXEC
;
5900 /* Local dynamic is inefficient when we're not combining the
5901 parts of the address. */
5902 else if (optimize
&& is_local
)
5903 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
5905 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
5906 if (kind
< flag_tls_default
)
5907 kind
= flag_tls_default
;
5912 /* Select a set of attributes for section NAME based on the properties
5913 of DECL and whether or not RELOC indicates that DECL's initializer
5914 might contain runtime relocations.
5916 We make the section read-only and executable for a function decl,
5917 read-only for a const data decl, and writable for a non-const data decl. */
5920 default_section_type_flags (tree decl
, const char *name
, int reloc
)
5924 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
5925 flags
= SECTION_CODE
;
5928 enum section_category category
5929 = categorize_decl_for_section (decl
, reloc
);
5930 if (decl_readonly_section_1 (category
))
5932 else if (category
== SECCAT_DATA_REL_RO
5933 || category
== SECCAT_DATA_REL_RO_LOCAL
)
5934 flags
= SECTION_WRITE
| SECTION_RELRO
;
5936 flags
= SECTION_WRITE
;
5940 flags
= SECTION_WRITE
;
5941 if (strcmp (name
, ".data.rel.ro") == 0
5942 || strcmp (name
, ".data.rel.ro.local") == 0)
5943 flags
|= SECTION_RELRO
;
5946 if (decl
&& DECL_ONE_ONLY (decl
))
5947 flags
|= SECTION_LINKONCE
;
5949 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
5950 flags
|= SECTION_TLS
| SECTION_WRITE
;
5952 if (strcmp (name
, ".bss") == 0
5953 || strncmp (name
, ".bss.", 5) == 0
5954 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
5955 || strcmp (name
, ".sbss") == 0
5956 || strncmp (name
, ".sbss.", 6) == 0
5957 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
5958 flags
|= SECTION_BSS
;
5960 if (strcmp (name
, ".tdata") == 0
5961 || strncmp (name
, ".tdata.", 7) == 0
5962 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
5963 flags
|= SECTION_TLS
;
5965 if (strcmp (name
, ".tbss") == 0
5966 || strncmp (name
, ".tbss.", 6) == 0
5967 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
5968 flags
|= SECTION_TLS
| SECTION_BSS
;
5970 /* These three sections have special ELF types. They are neither
5971 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
5972 want to print a section type (@progbits or @nobits). If someone
5973 is silly enough to emit code or TLS variables to one of these
5974 sections, then don't handle them specially. */
5975 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
5976 && (strcmp (name
, ".init_array") == 0
5977 || strcmp (name
, ".fini_array") == 0
5978 || strcmp (name
, ".preinit_array") == 0))
5979 flags
|= SECTION_NOTYPE
;
5984 /* Return true if the target supports some form of global BSS,
5985 either through bss_noswitch_section, or by selecting a BSS
5986 section in TARGET_ASM_SELECT_SECTION. */
5989 have_global_bss_p (void)
5991 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
5994 /* Output assembly to switch to section NAME with attribute FLAGS.
5995 Four variants for common object file formats. */
5998 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
5999 unsigned int flags ATTRIBUTE_UNUSED
,
6000 tree decl ATTRIBUTE_UNUSED
)
6002 /* Some object formats don't support named sections at all. The
6003 front-end should already have flagged this as an error. */
6007 #ifndef TLS_SECTION_ASM_FLAG
6008 #define TLS_SECTION_ASM_FLAG 'T'
6012 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6013 tree decl ATTRIBUTE_UNUSED
)
6015 char flagchars
[10], *f
= flagchars
;
6017 /* If we have already declared this section, we can use an
6018 abbreviated form to switch back to it -- unless this section is
6019 part of a COMDAT groups, in which case GAS requires the full
6020 declaration every time. */
6021 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6022 && (flags
& SECTION_DECLARED
))
6024 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6028 if (!(flags
& SECTION_DEBUG
))
6030 if (flags
& SECTION_EXCLUDE
)
6032 if (flags
& SECTION_WRITE
)
6034 if (flags
& SECTION_CODE
)
6036 if (flags
& SECTION_SMALL
)
6038 if (flags
& SECTION_MERGE
)
6040 if (flags
& SECTION_STRINGS
)
6042 if (flags
& SECTION_TLS
)
6043 *f
++ = TLS_SECTION_ASM_FLAG
;
6044 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6048 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6050 if (!(flags
& SECTION_NOTYPE
))
6055 if (flags
& SECTION_BSS
)
6061 /* On platforms that use "@" as the assembly comment character,
6063 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6065 fprintf (asm_out_file
, format
, type
);
6067 if (flags
& SECTION_ENTSIZE
)
6068 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6069 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6071 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6072 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6074 fprintf (asm_out_file
, ",%s,comdat",
6075 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6079 putc ('\n', asm_out_file
);
6083 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6084 tree decl ATTRIBUTE_UNUSED
)
6086 char flagchars
[8], *f
= flagchars
;
6088 if (flags
& SECTION_WRITE
)
6090 if (flags
& SECTION_CODE
)
6094 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6098 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6101 default_coff_asm_named_section (name
, flags
, decl
);
6103 if (flags
& SECTION_LINKONCE
)
6105 /* Functions may have been compiled at various levels of
6106 optimization so we can't use `same_size' here.
6107 Instead, have the linker pick one. */
6108 fprintf (asm_out_file
, "\t.linkonce %s\n",
6109 (flags
& SECTION_CODE
? "discard" : "same_size"));
6113 /* The lame default section selector. */
6116 default_select_section (tree decl
, int reloc
,
6117 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6121 if (decl_readonly_section (decl
, reloc
))
6122 return readonly_data_section
;
6124 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6126 if (! ((flag_pic
&& reloc
)
6127 || !TREE_READONLY (decl
)
6128 || TREE_SIDE_EFFECTS (decl
)
6129 || !TREE_CONSTANT (decl
)))
6130 return readonly_data_section
;
6132 else if (TREE_CODE (decl
) == STRING_CST
)
6133 return readonly_data_section
;
6134 else if (! (flag_pic
&& reloc
))
6135 return readonly_data_section
;
6137 return data_section
;
6140 enum section_category
6141 categorize_decl_for_section (const_tree decl
, int reloc
)
6143 enum section_category ret
;
6145 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6147 else if (TREE_CODE (decl
) == STRING_CST
)
6149 if (flag_mudflap
) /* or !flag_merge_constants */
6150 return SECCAT_RODATA
;
6152 return SECCAT_RODATA_MERGE_STR
;
6154 else if (TREE_CODE (decl
) == VAR_DECL
)
6156 if (bss_initializer_p (decl
))
6158 else if (! TREE_READONLY (decl
)
6159 || TREE_SIDE_EFFECTS (decl
)
6160 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6162 /* Here the reloc_rw_mask is not testing whether the section should
6163 be read-only or not, but whether the dynamic link will have to
6164 do something. If so, we wish to segregate the data in order to
6165 minimize cache misses inside the dynamic linker. */
6166 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6167 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6171 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6172 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6173 else if (reloc
|| flag_merge_constants
< 2)
6174 /* C and C++ don't allow different variables to share the same
6175 location. -fmerge-all-constants allows even that (at the
6176 expense of not conforming). */
6177 ret
= SECCAT_RODATA
;
6178 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6179 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6181 ret
= SECCAT_RODATA_MERGE_CONST
;
6183 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6185 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6186 || TREE_SIDE_EFFECTS (decl
)
6187 || ! TREE_CONSTANT (decl
))
6190 ret
= SECCAT_RODATA
;
6193 ret
= SECCAT_RODATA
;
6195 /* There are no read-only thread-local sections. */
6196 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6198 /* Note that this would be *just* SECCAT_BSS, except that there's
6199 no concept of a read-only thread-local-data section. */
6200 if (ret
== SECCAT_BSS
6201 || (flag_zero_initialized_in_bss
6202 && initializer_zerop (DECL_INITIAL (decl
))))
6208 /* If the target uses small data sections, select it. */
6209 else if (targetm
.in_small_data_p (decl
))
6211 if (ret
== SECCAT_BSS
)
6213 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6214 ret
= SECCAT_SRODATA
;
6223 decl_readonly_section_1 (enum section_category category
)
6228 case SECCAT_RODATA_MERGE_STR
:
6229 case SECCAT_RODATA_MERGE_STR_INIT
:
6230 case SECCAT_RODATA_MERGE_CONST
:
6231 case SECCAT_SRODATA
:
6239 decl_readonly_section (const_tree decl
, int reloc
)
6241 return decl_readonly_section_1 (categorize_decl_for_section (decl
, reloc
));
6244 /* Select a section based on the above categorization. */
6247 default_elf_select_section (tree decl
, int reloc
,
6248 unsigned HOST_WIDE_INT align
)
6251 switch (categorize_decl_for_section (decl
, reloc
))
6254 /* We're not supposed to be called on FUNCTION_DECLs. */
6257 return readonly_data_section
;
6258 case SECCAT_RODATA_MERGE_STR
:
6259 return mergeable_string_section (decl
, align
, 0);
6260 case SECCAT_RODATA_MERGE_STR_INIT
:
6261 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6262 case SECCAT_RODATA_MERGE_CONST
:
6263 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6264 case SECCAT_SRODATA
:
6268 return data_section
;
6269 case SECCAT_DATA_REL
:
6270 sname
= ".data.rel";
6272 case SECCAT_DATA_REL_LOCAL
:
6273 sname
= ".data.rel.local";
6275 case SECCAT_DATA_REL_RO
:
6276 sname
= ".data.rel.ro";
6278 case SECCAT_DATA_REL_RO_LOCAL
:
6279 sname
= ".data.rel.ro.local";
6304 return get_named_section (decl
, sname
, reloc
);
6307 /* Construct a unique section name based on the decl name and the
6308 categorization performed above. */
6311 default_unique_section (tree decl
, int reloc
)
6313 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6314 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6315 const char *prefix
, *name
, *linkonce
;
6318 switch (categorize_decl_for_section (decl
, reloc
))
6321 prefix
= one_only
? ".t" : ".text";
6324 case SECCAT_RODATA_MERGE_STR
:
6325 case SECCAT_RODATA_MERGE_STR_INIT
:
6326 case SECCAT_RODATA_MERGE_CONST
:
6327 prefix
= one_only
? ".r" : ".rodata";
6329 case SECCAT_SRODATA
:
6330 prefix
= one_only
? ".s2" : ".sdata2";
6333 prefix
= one_only
? ".d" : ".data";
6335 case SECCAT_DATA_REL
:
6336 prefix
= one_only
? ".d.rel" : ".data.rel";
6338 case SECCAT_DATA_REL_LOCAL
:
6339 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6341 case SECCAT_DATA_REL_RO
:
6342 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6344 case SECCAT_DATA_REL_RO_LOCAL
:
6345 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6348 prefix
= one_only
? ".s" : ".sdata";
6351 prefix
= one_only
? ".b" : ".bss";
6354 prefix
= one_only
? ".sb" : ".sbss";
6357 prefix
= one_only
? ".td" : ".tdata";
6360 prefix
= one_only
? ".tb" : ".tbss";
6366 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6367 name
= targetm
.strip_name_encoding (name
);
6369 /* If we're using one_only, then there needs to be a .gnu.linkonce
6370 prefix to the section name. */
6371 linkonce
= one_only
? ".gnu.linkonce" : "";
6373 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6375 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6378 /* Like compute_reloc_for_constant, except for an RTX. The return value
6379 is a mask for which bit 1 indicates a global relocation, and bit 0
6380 indicates a local relocation. */
6383 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6385 int *preloc
= (int *) data
;
6388 switch (GET_CODE (x
))
6391 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6404 compute_reloc_for_rtx (rtx x
)
6408 switch (GET_CODE (x
))
6414 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6423 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6425 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6427 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6428 return data_section
;
6430 return readonly_data_section
;
6434 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6435 unsigned HOST_WIDE_INT align
)
6437 int reloc
= compute_reloc_for_rtx (x
);
6439 /* ??? Handle small data here somehow. */
6441 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6444 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6446 return get_named_section (NULL
, ".data.rel.ro", 3);
6449 return mergeable_constant_section (mode
, align
, 0);
6452 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6455 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6460 /* Careful not to prod global register variables. */
6463 symbol
= XEXP (rtl
, 0);
6464 if (GET_CODE (symbol
) != SYMBOL_REF
)
6467 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6468 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6469 flags
|= SYMBOL_FLAG_FUNCTION
;
6470 if (targetm
.binds_local_p (decl
))
6471 flags
|= SYMBOL_FLAG_LOCAL
;
6472 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6473 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6474 else if (targetm
.in_small_data_p (decl
))
6475 flags
|= SYMBOL_FLAG_SMALL
;
6476 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6477 being PUBLIC, the thing *must* be defined in this translation unit.
6478 Prevent this buglet from being propagated into rtl code as well. */
6479 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6480 flags
|= SYMBOL_FLAG_EXTERNAL
;
6482 SYMBOL_REF_FLAGS (symbol
) = flags
;
6485 /* By default, we do nothing for encode_section_info, so we need not
6486 do anything but discard the '*' marker. */
6489 default_strip_name_encoding (const char *str
)
6491 return str
+ (*str
== '*');
6494 #ifdef ASM_OUTPUT_DEF
6495 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6496 anchor relative to ".", the current section position. */
6499 default_asm_output_anchor (rtx symbol
)
6503 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6504 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6505 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6509 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6512 default_use_anchors_for_symbol_p (const_rtx symbol
)
6517 /* Don't use anchors for mergeable sections. The linker might move
6518 the objects around. */
6519 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6520 if (sect
->common
.flags
& SECTION_MERGE
)
6523 /* Don't use anchors for small data sections. The small data register
6524 acts as an anchor for such sections. */
6525 if (sect
->common
.flags
& SECTION_SMALL
)
6528 decl
= SYMBOL_REF_DECL (symbol
);
6529 if (decl
&& DECL_P (decl
))
6531 /* Don't use section anchors for decls that might be defined by
6533 if (!targetm
.binds_local_p (decl
))
6536 /* Don't use section anchors for decls that will be placed in a
6537 small data section. */
6538 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6539 one above. The problem is that we only use SECTION_SMALL for
6540 sections that should be marked as small in the section directive. */
6541 if (targetm
.in_small_data_p (decl
))
6547 /* Return true when RESOLUTION indicate that symbol will be bound to the
6548 definition provided by current .o file. */
6551 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
6553 return (resolution
== LDPR_PREVAILING_DEF
6554 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6555 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
6558 /* Return true when RESOLUTION indicate that symbol will be bound locally
6559 within current executable or DSO. */
6562 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
6564 return (resolution
== LDPR_PREVAILING_DEF
6565 || resolution
== LDPR_PREVAILING_DEF_IRONLY
6566 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6567 || resolution
== LDPR_PREEMPTED_REG
6568 || resolution
== LDPR_PREEMPTED_IR
6569 || resolution
== LDPR_RESOLVED_IR
6570 || resolution
== LDPR_RESOLVED_EXEC
);
6573 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6574 wrt cross-module name binding. */
6577 default_binds_local_p (const_tree exp
)
6579 return default_binds_local_p_1 (exp
, flag_shlib
);
6583 default_binds_local_p_1 (const_tree exp
, int shlib
)
6586 bool resolved_locally
= false;
6587 bool resolved_to_local_def
= false;
6589 /* With resolution file in hands, take look into resolutions.
6590 We can't just return true for resolved_locally symbols,
6591 because dynamic linking might overwrite symbols
6592 in shared libraries. */
6593 if (TREE_CODE (exp
) == VAR_DECL
&& TREE_PUBLIC (exp
)
6594 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
6596 struct varpool_node
*vnode
= varpool_get_node (exp
);
6597 if (vnode
&& resolution_local_p (vnode
->symbol
.resolution
))
6598 resolved_locally
= true;
6600 && resolution_to_local_definition_p (vnode
->symbol
.resolution
))
6601 resolved_to_local_def
= true;
6603 else if (TREE_CODE (exp
) == FUNCTION_DECL
&& TREE_PUBLIC (exp
))
6605 struct cgraph_node
*node
= cgraph_get_node (exp
);
6607 && resolution_local_p (node
->symbol
.resolution
))
6608 resolved_locally
= true;
6610 && resolution_to_local_definition_p (node
->symbol
.resolution
))
6611 resolved_to_local_def
= true;
6614 /* A non-decl is an entry in the constant pool. */
6617 /* Weakrefs may not bind locally, even though the weakref itself is always
6618 static and therefore local. Similarly, the resolver for ifunc functions
6619 might resolve to a non-local function.
6620 FIXME: We can resolve the weakref case more curefuly by looking at the
6622 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
))
6623 || (TREE_CODE (exp
) == FUNCTION_DECL
6624 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (exp
))))
6626 /* Static variables are always local. */
6627 else if (! TREE_PUBLIC (exp
))
6629 /* A variable is local if the user has said explicitly that it will
6631 else if ((DECL_VISIBILITY_SPECIFIED (exp
)
6632 || resolved_to_local_def
)
6633 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6635 /* Variables defined outside this object might not be local. */
6636 else if (DECL_EXTERNAL (exp
) && !resolved_locally
)
6638 /* If defined in this object and visibility is not default, must be
6640 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6642 /* Default visibility weak data can be overridden by a strong symbol
6643 in another module and so are not local. */
6644 else if (DECL_WEAK (exp
)
6645 && !resolved_locally
)
6647 /* If PIC, then assume that any global name can be overridden by
6648 symbols resolved from other modules. */
6651 /* Uninitialized COMMON variable may be unified with symbols
6652 resolved from other modules. */
6653 else if (DECL_COMMON (exp
)
6654 && !resolved_locally
6655 && (DECL_INITIAL (exp
) == NULL
6656 || DECL_INITIAL (exp
) == error_mark_node
))
6658 /* Otherwise we're left with initialized (or non-common) global data
6659 which is of necessity defined locally. */
6666 /* Return true when references to DECL must bind to current definition in
6669 The condition is usually equivalent to whether the function binds to the
6670 current module (shared library or executable), that is to binds_local_p.
6671 We use this fact to avoid need for another target hook and implement
6672 the logic using binds_local_p and just special cases where
6673 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
6674 the weak definitions (that can be overwritten at linktime by other
6675 definition from different object file) and when resolution info is available
6676 we simply use the knowledge passed to us by linker plugin. */
6678 decl_binds_to_current_def_p (tree decl
)
6680 gcc_assert (DECL_P (decl
));
6681 if (!TREE_PUBLIC (decl
))
6683 if (!targetm
.binds_local_p (decl
))
6685 /* When resolution is available, just use it. */
6686 if (TREE_CODE (decl
) == VAR_DECL
6687 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
6689 struct varpool_node
*vnode
= varpool_get_node (decl
);
6691 && vnode
->symbol
.resolution
!= LDPR_UNKNOWN
)
6692 return resolution_to_local_definition_p (vnode
->symbol
.resolution
);
6694 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
6696 struct cgraph_node
*node
= cgraph_get_node (decl
);
6698 && node
->symbol
.resolution
!= LDPR_UNKNOWN
)
6699 return resolution_to_local_definition_p (node
->symbol
.resolution
);
6701 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
6702 binds locally but still can be overwritten).
6703 This rely on fact that binds_local_p behave as decl_replaceable_p
6704 for all other declaration types. */
6705 return !DECL_WEAK (decl
);
6708 /* A replaceable function or variable is one which may be replaced
6709 at link-time with an entirely different definition, provided that the
6710 replacement has the same type. For example, functions declared
6711 with __attribute__((weak)) on most systems are replaceable.
6713 COMDAT functions are not replaceable, since all definitions of the
6714 function must be equivalent. It is important that COMDAT functions
6715 not be treated as replaceable so that use of C++ template
6716 instantiations is not penalized. */
6719 decl_replaceable_p (tree decl
)
6721 gcc_assert (DECL_P (decl
));
6722 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
6724 return !decl_binds_to_current_def_p (decl
);
6727 /* Default function to output code that will globalize a label. A
6728 target must define GLOBAL_ASM_OP or provide its own function to
6729 globalize a label. */
6730 #ifdef GLOBAL_ASM_OP
6732 default_globalize_label (FILE * stream
, const char *name
)
6734 fputs (GLOBAL_ASM_OP
, stream
);
6735 assemble_name (stream
, name
);
6736 putc ('\n', stream
);
6738 #endif /* GLOBAL_ASM_OP */
6740 /* Default function to output code that will globalize a declaration. */
6742 default_globalize_decl_name (FILE * stream
, tree decl
)
6744 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6745 targetm
.asm_out
.globalize_label (stream
, name
);
6748 /* Default function to output a label for unwind information. The
6749 default is to do nothing. A target that needs nonlocal labels for
6750 unwind information must provide its own function to do this. */
6752 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6753 tree decl ATTRIBUTE_UNUSED
,
6754 int for_eh ATTRIBUTE_UNUSED
,
6755 int empty ATTRIBUTE_UNUSED
)
6759 /* Default function to output a label to divide up the exception table.
6760 The default is to do nothing. A target that needs/wants to divide
6761 up the table must provide it's own function to do this. */
6763 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6767 /* This is how to output an internal numbered label where PREFIX is
6768 the class of label and LABELNO is the number within the class. */
6771 default_generate_internal_label (char *buf
, const char *prefix
,
6772 unsigned long labelno
)
6774 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6777 /* This is how to output an internal numbered label where PREFIX is
6778 the class of label and LABELNO is the number within the class. */
6781 default_internal_label (FILE *stream
, const char *prefix
,
6782 unsigned long labelno
)
6784 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6785 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6786 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6790 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6793 default_asm_declare_constant_name (FILE *file
, const char *name
,
6794 const_tree exp ATTRIBUTE_UNUSED
,
6795 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
6797 assemble_label (file
, name
);
6800 /* This is the default behavior at the beginning of a file. It's
6801 controlled by two other target-hook toggles. */
6803 default_file_start (void)
6805 if (targetm
.asm_file_start_app_off
6806 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6807 fputs (ASM_APP_OFF
, asm_out_file
);
6809 if (targetm
.asm_file_start_file_directive
)
6810 output_file_directive (asm_out_file
, main_input_filename
);
6813 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6814 which emits a special section directive used to indicate whether or
6815 not this object file needs an executable stack. This is primarily
6816 a GNU extension to ELF but could be used on other targets. */
6818 int trampolines_created
;
6821 file_end_indicate_exec_stack (void)
6823 unsigned int flags
= SECTION_DEBUG
;
6824 if (trampolines_created
)
6825 flags
|= SECTION_CODE
;
6827 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6830 /* Emit a special section directive to indicate that this object file
6831 was compiled with -fsplit-stack. This is used to let the linker
6832 detect calls between split-stack code and non-split-stack code, so
6833 that it can modify the split-stack code to allocate a sufficiently
6834 large stack. We emit another special section if there are any
6835 functions in this file which have the no_split_stack attribute, to
6836 prevent the linker from warning about being unable to convert the
6837 functions if they call non-split-stack code. */
6840 file_end_indicate_split_stack (void)
6842 if (flag_split_stack
)
6844 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
6846 if (saw_no_split_stack
)
6847 switch_to_section (get_section (".note.GNU-no-split-stack",
6848 SECTION_DEBUG
, NULL
));
6852 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6853 a get_unnamed_section callback. */
6856 output_section_asm_op (const void *directive
)
6858 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
6861 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6862 the current section is NEW_SECTION. */
6865 switch_to_section (section
*new_section
)
6867 if (in_section
== new_section
)
6870 if (new_section
->common
.flags
& SECTION_FORGET
)
6873 in_section
= new_section
;
6875 switch (SECTION_STYLE (new_section
))
6878 targetm
.asm_out
.named_section (new_section
->named
.name
,
6879 new_section
->named
.common
.flags
,
6880 new_section
->named
.decl
);
6883 case SECTION_UNNAMED
:
6884 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
6887 case SECTION_NOSWITCH
:
6892 new_section
->common
.flags
|= SECTION_DECLARED
;
6895 /* If block symbol SYMBOL has not yet been assigned an offset, place
6896 it at the end of its block. */
6899 place_block_symbol (rtx symbol
)
6901 unsigned HOST_WIDE_INT size
, mask
, offset
;
6902 struct constant_descriptor_rtx
*desc
;
6903 unsigned int alignment
;
6904 struct object_block
*block
;
6907 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
6908 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
6911 /* Work out the symbol's size and alignment. */
6912 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6914 desc
= SYMBOL_REF_CONSTANT (symbol
);
6915 alignment
= desc
->align
;
6916 size
= GET_MODE_SIZE (desc
->mode
);
6918 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6920 decl
= SYMBOL_REF_DECL (symbol
);
6921 alignment
= DECL_ALIGN (decl
);
6922 size
= get_constant_size (DECL_INITIAL (decl
));
6926 decl
= SYMBOL_REF_DECL (symbol
);
6927 alignment
= DECL_ALIGN (decl
);
6928 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
6931 /* Calculate the object's offset from the start of the block. */
6932 block
= SYMBOL_REF_BLOCK (symbol
);
6933 mask
= alignment
/ BITS_PER_UNIT
- 1;
6934 offset
= (block
->size
+ mask
) & ~mask
;
6935 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
6937 /* Record the block's new alignment and size. */
6938 block
->alignment
= MAX (block
->alignment
, alignment
);
6939 block
->size
= offset
+ size
;
6941 VEC_safe_push (rtx
, gc
, block
->objects
, symbol
);
6944 /* Return the anchor that should be used to address byte offset OFFSET
6945 from the first object in BLOCK. MODEL is the TLS model used
6949 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
6950 enum tls_model model
)
6953 unsigned int begin
, middle
, end
;
6954 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
6957 /* Work out the anchor's offset. Use an offset of 0 for the first
6958 anchor so that we don't pessimize the case where we take the address
6959 of a variable at the beginning of the block. This is particularly
6960 useful when a block has only one variable assigned to it.
6962 We try to place anchors RANGE bytes apart, so there can then be
6963 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6964 a ptr_mode offset. With some target settings, the lowest such
6965 anchor might be out of range for the lowest ptr_mode offset;
6966 likewise the highest anchor for the highest offset. Use anchors
6967 at the extreme ends of the ptr_mode range in such cases.
6969 All arithmetic uses unsigned integers in order to avoid
6971 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
6972 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
6973 range
= max_offset
- min_offset
+ 1;
6978 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
6981 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
6982 delta
-= delta
% range
;
6985 offset
= (HOST_WIDE_INT
) (-delta
);
6989 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
6990 delta
-= delta
% range
;
6991 if (delta
> bias
- 1)
6993 offset
= (HOST_WIDE_INT
) delta
;
6997 /* Do a binary search to see if there's already an anchor we can use.
6998 Set BEGIN to the new anchor's index if not. */
7000 end
= VEC_length (rtx
, block
->anchors
);
7001 while (begin
!= end
)
7003 middle
= (end
+ begin
) / 2;
7004 anchor
= VEC_index (rtx
, block
->anchors
, middle
);
7005 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7007 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7009 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7011 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7017 /* Create a new anchor with a unique label. */
7018 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7019 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7020 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7021 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7023 /* Insert it at index BEGIN. */
7024 VEC_safe_insert (rtx
, gc
, block
->anchors
, begin
, anchor
);
7028 /* Output the objects in BLOCK. */
7031 output_object_block (struct object_block
*block
)
7033 struct constant_descriptor_rtx
*desc
;
7035 HOST_WIDE_INT offset
;
7039 if (block
->objects
== NULL
)
7042 /* Switch to the section and make sure that the first byte is
7043 suitably aligned. */
7044 switch_to_section (block
->sect
);
7045 assemble_align (block
->alignment
);
7047 /* Define the values of all anchors relative to the current section
7049 FOR_EACH_VEC_ELT (rtx
, block
->anchors
, i
, symbol
)
7050 targetm
.asm_out
.output_anchor (symbol
);
7052 /* Output the objects themselves. */
7054 FOR_EACH_VEC_ELT (rtx
, block
->objects
, i
, symbol
)
7056 /* Move to the object's offset, padding with zeros if necessary. */
7057 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7058 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7059 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7061 desc
= SYMBOL_REF_CONSTANT (symbol
);
7062 output_constant_pool_1 (desc
, 1);
7063 offset
+= GET_MODE_SIZE (desc
->mode
);
7065 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7067 decl
= SYMBOL_REF_DECL (symbol
);
7068 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
7070 offset
+= get_constant_size (DECL_INITIAL (decl
));
7074 decl
= SYMBOL_REF_DECL (symbol
);
7075 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
7076 offset
+= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
7081 /* A htab_traverse callback used to call output_object_block for
7082 each member of object_block_htab. */
7085 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
7087 output_object_block ((struct object_block
*) (*slot
));
7091 /* Output the definitions of all object_blocks. */
7094 output_object_blocks (void)
7096 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
7099 /* This function provides a possible implementation of the
7100 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7101 by -frecord-gcc-switches it creates a new mergeable, string section in the
7102 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7103 contains the switches in ASCII format.
7105 FIXME: This code does not correctly handle double quote characters
7106 that appear inside strings, (it strips them rather than preserving them).
7107 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7108 characters - instead it treats them as sub-string separators. Since
7109 we want to emit NUL strings terminators into the object file we have to use
7113 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7117 case SWITCH_TYPE_PASSED
:
7118 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
7119 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7122 case SWITCH_TYPE_DESCRIPTIVE
:
7125 /* Distinguish between invocations where name is NULL. */
7126 static bool started
= false;
7132 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7136 | (SECTION_ENTSIZE
& 1),
7138 switch_to_section (sec
);
7147 /* The return value is currently ignored by the caller, but must be 0.
7148 For -fverbose-asm the return value would be the number of characters
7149 emitted into the assembler file. */
7153 /* Emit text to declare externally defined symbols. It is needed to
7154 properly support non-default visibility. */
7156 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7158 const char *name ATTRIBUTE_UNUSED
)
7160 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7161 set in order to avoid putting out names that are never really
7163 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7164 && targetm
.binds_local_p (decl
))
7165 maybe_assemble_visibility (decl
);
7168 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7171 default_asm_output_source_filename (FILE *file
, const char *name
)
7173 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7174 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
7176 fprintf (file
, "\t.file\t");
7177 output_quoted_string (file
, name
);
7182 /* Output a file name in the form wanted by System V. */
7185 output_file_directive (FILE *asm_file
, const char *input_name
)
7190 if (input_name
== NULL
)
7191 input_name
= "<stdin>";
7193 input_name
= remap_debug_filename (input_name
);
7195 len
= strlen (input_name
);
7196 na
= input_name
+ len
;
7198 /* NA gets INPUT_NAME sans directory names. */
7199 while (na
> input_name
)
7201 if (IS_DIR_SEPARATOR (na
[-1]))
7206 targetm
.asm_out
.output_source_filename (asm_file
, na
);
7209 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7212 make_debug_expr_from_rtl (const_rtx exp
)
7214 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7215 enum machine_mode mode
= GET_MODE (exp
);
7218 DECL_ARTIFICIAL (ddecl
) = 1;
7219 if (REG_P (exp
) && REG_EXPR (exp
))
7220 type
= TREE_TYPE (REG_EXPR (exp
));
7221 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7222 type
= TREE_TYPE (MEM_EXPR (exp
));
7225 if (type
&& TYPE_MODE (type
) == mode
)
7226 TREE_TYPE (ddecl
) = type
;
7228 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7229 DECL_MODE (ddecl
) = mode
;
7230 dval
= gen_rtx_DEBUG_EXPR (mode
);
7231 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7232 SET_DECL_RTL (ddecl
, dval
);
7236 #ifdef ELF_ASCII_ESCAPES
7237 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
7240 default_elf_asm_output_limited_string (FILE *f
, const char *s
)
7245 fputs (STRING_ASM_OP
, f
);
7250 escape
= ELF_ASCII_ESCAPES
[c
];
7257 /* TODO: Print in hex with fast function, important for -flto. */
7258 fprintf (f
, "\\%03o", c
);
7271 /* Default ASM_OUTPUT_ASCII for ELF targets. */
7274 default_elf_asm_output_ascii (FILE *f
, const char *s
, unsigned int len
)
7276 const char *limit
= s
+ len
;
7277 const char *last_null
= NULL
;
7278 unsigned bytes_in_chunk
= 0;
7282 for (; s
< limit
; s
++)
7286 if (bytes_in_chunk
>= 60)
7295 for (p
= s
; p
< limit
&& *p
!= '\0'; p
++)
7302 if (p
< limit
&& (p
- s
) <= (long) ELF_STRING_LIMIT
)
7304 if (bytes_in_chunk
> 0)
7311 default_elf_asm_output_limited_string (f
, s
);
7316 if (bytes_in_chunk
== 0)
7317 fputs (ASCII_DATA_ASM_OP
"\"", f
);
7320 escape
= ELF_ASCII_ESCAPES
[c
];
7328 /* TODO: Print in hex with fast function, important for -flto. */
7329 fprintf (f
, "\\%03o", c
);
7330 bytes_in_chunk
+= 4;
7335 bytes_in_chunk
+= 2;
7342 if (bytes_in_chunk
> 0)
7350 static GTY(()) section
*elf_init_array_section
;
7351 static GTY(()) section
*elf_fini_array_section
;
7354 get_elf_initfini_array_priority_section (int priority
,
7358 if (priority
!= DEFAULT_INIT_PRIORITY
)
7361 sprintf (buf
, "%s.%.5u",
7362 constructor_p
? ".init_array" : ".fini_array",
7364 sec
= get_section (buf
, SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7370 if (elf_init_array_section
== NULL
)
7371 elf_init_array_section
7372 = get_section (".init_array",
7373 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7374 sec
= elf_init_array_section
;
7378 if (elf_fini_array_section
== NULL
)
7379 elf_fini_array_section
7380 = get_section (".fini_array",
7381 SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
7382 sec
= elf_fini_array_section
;
7388 /* Use .init_array section for constructors. */
7391 default_elf_init_array_asm_out_constructor (rtx symbol
, int priority
)
7393 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7395 assemble_addr_to_section (symbol
, sec
);
7398 /* Use .fini_array section for destructors. */
7401 default_elf_fini_array_asm_out_destructor (rtx symbol
, int priority
)
7403 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7405 assemble_addr_to_section (symbol
, sec
);
7408 /* Default TARGET_ASM_OUTPUT_IDENT hook.
7410 This is a bit of a cheat. The real default is a no-op, but this
7411 hook is the default for all targets with a .ident directive. */
7414 default_asm_output_ident_directive (const char *ident_str
)
7416 const char *ident_asm_op
= "\t.ident\t";
7418 /* If we are still in the front end, do not write out the string
7419 to asm_out_file. Instead, add a fake top-level asm statement.
7420 This allows the front ends to use this hook without actually
7421 writing to asm_out_file, to handle #ident or Pragma Ident. */
7422 if (cgraph_state
== CGRAPH_STATE_PARSING
)
7424 char *buf
= ACONCAT ((ident_asm_op
, "\"", ident_str
, "\"\n", NULL
));
7425 add_asm_node (build_string (strlen (buf
), buf
));
7428 fprintf (asm_out_file
, "%s\"%s\"\n", ident_asm_op
, ident_str
);
7431 #include "gt-varasm.h"