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 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 "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
56 #include "pointer-set.h"
58 #ifdef XCOFF_DEBUGGING_INFO
59 #include "xcoffout.h" /* Needed for external data
60 declarations for e.g. AIX 4.x. */
63 /* The (assembler) name of the first globally-visible object output. */
64 extern GTY(()) const char *first_global_object_name
;
65 extern GTY(()) const char *weak_global_object_name
;
67 const char *first_global_object_name
;
68 const char *weak_global_object_name
;
71 struct constant_descriptor_rtx
;
72 struct rtx_constant_pool
;
74 #define n_deferred_constants (crtl->varasm.deferred_constants)
76 /* Number for making the label on the next
77 constant that is stored in memory. */
79 static GTY(()) int const_labelno
;
81 /* Carry information from ASM_DECLARE_OBJECT_NAME
82 to ASM_FINISH_DECLARE_OBJECT. */
84 int size_directive_output
;
86 /* The last decl for which assemble_variable was called,
87 if it did ASM_DECLARE_OBJECT_NAME.
88 If the last call to assemble_variable didn't do that,
91 tree last_assemble_variable_decl
;
93 /* The following global variable indicates if the first basic block
94 in a function belongs to the cold partition or not. */
96 bool first_function_block_is_cold
;
98 /* We give all constants their own alias set. Perhaps redundant with
99 MEM_READONLY_P, but pre-dates it. */
101 static alias_set_type const_alias_set
;
103 /* Whether we saw any functions with no_split_stack. */
105 static bool saw_no_split_stack
;
107 static const char *strip_reg_name (const char *);
108 static int contains_pointers_p (tree
);
109 #ifdef ASM_OUTPUT_EXTERNAL
110 static bool incorporeal_function_p (tree
);
112 static void decode_addr_const (tree
, struct addr_const
*);
113 static hashval_t
const_desc_hash (const void *);
114 static int const_desc_eq (const void *, const void *);
115 static hashval_t
const_hash_1 (const tree
);
116 static int compare_constant (const tree
, const tree
);
117 static tree
copy_constant (tree
);
118 static void output_constant_def_contents (rtx
);
119 static void output_addressed_constants (tree
);
120 static unsigned HOST_WIDE_INT
array_size_for_constructor (tree
);
121 static unsigned min_align (unsigned, unsigned);
122 static void globalize_decl (tree
);
123 static bool decl_readonly_section_1 (enum section_category
);
124 #ifdef BSS_SECTION_ASM_OP
125 #ifdef ASM_OUTPUT_ALIGNED_BSS
126 static void asm_output_aligned_bss (FILE *, tree
, const char *,
127 unsigned HOST_WIDE_INT
, int)
130 #endif /* BSS_SECTION_ASM_OP */
131 static void mark_weak (tree
);
132 static void output_constant_pool (const char *, tree
);
134 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
135 section
*text_section
;
136 section
*data_section
;
137 section
*readonly_data_section
;
138 section
*sdata_section
;
139 section
*ctors_section
;
140 section
*dtors_section
;
141 section
*bss_section
;
142 section
*sbss_section
;
144 /* Various forms of common section. All are guaranteed to be nonnull. */
145 section
*tls_comm_section
;
146 section
*comm_section
;
147 section
*lcomm_section
;
149 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
151 section
*bss_noswitch_section
;
153 /* The section that holds the main exception table, when known. The section
154 is set either by the target's init_sections hook or by the first call to
155 switch_to_exception_section. */
156 section
*exception_section
;
158 /* The section that holds the DWARF2 frame unwind information, when known.
159 The section is set either by the target's init_sections hook or by the
160 first call to switch_to_eh_frame_section. */
161 section
*eh_frame_section
;
163 /* asm_out_file's current section. This is NULL if no section has yet
164 been selected or if we lose track of what the current section is. */
167 /* True if code for the current function is currently being directed
168 at the cold section. */
169 bool in_cold_section_p
;
171 /* A linked list of all the unnamed sections. */
172 static GTY(()) section
*unnamed_sections
;
174 /* Return a nonzero value if DECL has a section attribute. */
175 #define IN_NAMED_SECTION(DECL) \
176 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
177 && DECL_SECTION_NAME (DECL) != NULL_TREE)
179 /* Hash table of named sections. */
180 static GTY((param_is (section
))) htab_t section_htab
;
182 /* A table of object_blocks, indexed by section. */
183 static GTY((param_is (struct object_block
))) htab_t object_block_htab
;
185 /* The next number to use for internal anchor labels. */
186 static GTY(()) int anchor_labelno
;
188 /* A pool of constants that can be shared between functions. */
189 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
191 /* Helper routines for maintaining section_htab. */
194 section_entry_eq (const void *p1
, const void *p2
)
196 const section
*old
= (const section
*) p1
;
197 const char *new_name
= (const char *) p2
;
199 return strcmp (old
->named
.name
, new_name
) == 0;
203 section_entry_hash (const void *p
)
205 const section
*old
= (const section
*) p
;
206 return htab_hash_string (old
->named
.name
);
209 /* Return a hash value for section SECT. */
212 hash_section (section
*sect
)
214 if (sect
->common
.flags
& SECTION_NAMED
)
215 return htab_hash_string (sect
->named
.name
);
216 return sect
->common
.flags
;
219 /* Helper routines for maintaining object_block_htab. */
222 object_block_entry_eq (const void *p1
, const void *p2
)
224 const struct object_block
*old
= (const struct object_block
*) p1
;
225 const section
*new_section
= (const section
*) p2
;
227 return old
->sect
== new_section
;
231 object_block_entry_hash (const void *p
)
233 const struct object_block
*old
= (const struct object_block
*) p
;
234 return hash_section (old
->sect
);
237 /* Return a new unnamed section with the given fields. */
240 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
245 sect
= ggc_alloc_section ();
246 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
247 sect
->unnamed
.callback
= callback
;
248 sect
->unnamed
.data
= data
;
249 sect
->unnamed
.next
= unnamed_sections
;
251 unnamed_sections
= sect
;
255 /* Return a SECTION_NOSWITCH section with the given fields. */
258 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
262 sect
= ggc_alloc_section ();
263 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
264 sect
->noswitch
.callback
= callback
;
269 /* Return the named section structure associated with NAME. Create
270 a new section with the given fields if no such structure exists. */
273 get_section (const char *name
, unsigned int flags
, tree decl
)
275 section
*sect
, **slot
;
278 htab_find_slot_with_hash (section_htab
, name
,
279 htab_hash_string (name
), INSERT
);
280 flags
|= SECTION_NAMED
;
283 sect
= ggc_alloc_section ();
284 sect
->named
.common
.flags
= flags
;
285 sect
->named
.name
= ggc_strdup (name
);
286 sect
->named
.decl
= decl
;
292 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
293 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
295 /* It is fine if one of the section flags is
296 SECTION_WRITE | SECTION_RELRO and the other has none of these
297 flags (i.e. read-only) in named sections and either the
298 section hasn't been declared yet or has been declared as writable.
299 In that case just make sure the resulting flags are
300 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
302 if (((sect
->common
.flags
^ flags
) & (SECTION_WRITE
| SECTION_RELRO
))
303 == (SECTION_WRITE
| SECTION_RELRO
)
304 && (sect
->common
.flags
305 & ~(SECTION_DECLARED
| SECTION_WRITE
| SECTION_RELRO
))
306 == (flags
& ~(SECTION_WRITE
| SECTION_RELRO
))
307 && ((sect
->common
.flags
& SECTION_DECLARED
) == 0
308 || (sect
->common
.flags
& SECTION_WRITE
)))
310 sect
->common
.flags
|= (SECTION_WRITE
| SECTION_RELRO
);
313 /* Sanity check user variables for flag changes. */
315 decl
= sect
->named
.decl
;
317 error ("%+D causes a section type conflict with %D",
318 decl
, sect
->named
.decl
);
319 if (decl
!= sect
->named
.decl
)
320 inform (DECL_SOURCE_LOCATION (sect
->named
.decl
),
321 "%qD was declared here", sect
->named
.decl
);
322 /* Make sure we don't error about one section multiple times. */
323 sect
->common
.flags
|= SECTION_OVERRIDE
;
329 /* Return true if the current compilation mode benefits from having
330 objects grouped into blocks. */
333 use_object_blocks_p (void)
335 return flag_section_anchors
;
338 /* Return the object_block structure for section SECT. Create a new
339 structure if we haven't created one already. Return null if SECT
342 static struct object_block
*
343 get_block_for_section (section
*sect
)
345 struct object_block
*block
;
351 slot
= htab_find_slot_with_hash (object_block_htab
, sect
,
352 hash_section (sect
), INSERT
);
353 block
= (struct object_block
*) *slot
;
356 block
= ggc_alloc_cleared_object_block ();
363 /* Create a symbol with label LABEL and place it at byte offset
364 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
365 is not yet known. LABEL must be a garbage-collected string. */
368 create_block_symbol (const char *label
, struct object_block
*block
,
369 HOST_WIDE_INT offset
)
374 /* Create the extended SYMBOL_REF. */
375 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
376 symbol
= ggc_alloc_zone_rtx_def (size
, &rtl_zone
);
378 /* Initialize the normal SYMBOL_REF fields. */
379 memset (symbol
, 0, size
);
380 PUT_CODE (symbol
, SYMBOL_REF
);
381 PUT_MODE (symbol
, Pmode
);
382 XSTR (symbol
, 0) = label
;
383 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
385 /* Initialize the block_symbol stuff. */
386 SYMBOL_REF_BLOCK (symbol
) = block
;
387 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
392 /* Return a section with a particular name and with whatever SECTION_*
393 flags section_type_flags deems appropriate. The name of the section
394 is taken from NAME if nonnull, otherwise it is taken from DECL's
395 DECL_SECTION_NAME. DECL is the decl associated with the section
396 (see the section comment for details) and RELOC is as for
397 section_type_flags. */
400 get_named_section (tree decl
, const char *name
, int reloc
)
404 gcc_assert (!decl
|| DECL_P (decl
));
406 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
408 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
410 return get_section (name
, flags
, decl
);
413 /* If required, set DECL_SECTION_NAME to a unique name. */
416 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
417 int flag_function_or_data_sections
)
419 if (DECL_SECTION_NAME (decl
) == NULL_TREE
420 && targetm_common
.have_named_sections
421 && (flag_function_or_data_sections
422 || DECL_ONE_ONLY (decl
)))
424 targetm
.asm_out
.unique_section (decl
, reloc
);
425 DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
) = true;
429 #ifdef BSS_SECTION_ASM_OP
431 #ifdef ASM_OUTPUT_ALIGNED_BSS
433 /* Utility function for targets to use in implementing
434 ASM_OUTPUT_ALIGNED_BSS.
435 ??? It is believed that this function will work in most cases so such
436 support is localized here. */
439 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
440 const char *name
, unsigned HOST_WIDE_INT size
,
443 switch_to_section (bss_section
);
444 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
445 #ifdef ASM_DECLARE_OBJECT_NAME
446 last_assemble_variable_decl
= decl
;
447 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
449 /* Standard thing is just output label for the object. */
450 ASM_OUTPUT_LABEL (file
, name
);
451 #endif /* ASM_DECLARE_OBJECT_NAME */
452 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
457 #endif /* BSS_SECTION_ASM_OP */
459 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
460 /* Return the hot section for function DECL. Return text_section for
464 hot_function_section (tree decl
)
466 if (decl
!= NULL_TREE
467 && DECL_SECTION_NAME (decl
) != NULL_TREE
468 && targetm_common
.have_named_sections
)
469 return get_named_section (decl
, NULL
, 0);
475 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
478 When DECL_SECTION_NAME is non-NULL and it is implicit section and
479 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
480 concatenate the name with NAMED_SECTION_SUFFIX.
481 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
484 get_named_text_section (tree decl
,
485 const char *text_section_name
,
486 const char *named_section_suffix
)
488 if (decl
&& DECL_SECTION_NAME (decl
))
490 if (named_section_suffix
)
492 tree dsn
= DECL_SECTION_NAME (decl
);
493 const char *stripped_name
;
496 name
= (char *) alloca (TREE_STRING_LENGTH (dsn
) + 1);
497 memcpy (name
, TREE_STRING_POINTER (dsn
),
498 TREE_STRING_LENGTH (dsn
) + 1);
500 stripped_name
= targetm
.strip_name_encoding (name
);
502 buffer
= ACONCAT ((stripped_name
, named_section_suffix
, NULL
));
503 return get_named_section (decl
, buffer
, 0);
505 else if (DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
))
509 /* Do not try to split gnu_linkonce functions. This gets somewhat
511 if (DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
)
513 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
514 name
= targetm
.strip_name_encoding (name
);
515 return get_named_section (decl
, ACONCAT ((text_section_name
, ".",
521 return get_named_section (decl
, text_section_name
, 0);
524 /* Choose named function section based on its frequency. */
527 default_function_section (tree decl
, enum node_frequency freq
,
528 bool startup
, bool exit
)
530 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
531 /* Old GNU linkers have buggy --gc-section support, which sometimes
532 results in .gcc_except_table* sections being garbage collected. */
534 && DECL_SECTION_NAME (decl
)
535 && DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
))
539 if (!flag_reorder_functions
540 || !targetm_common
.have_named_sections
)
542 /* Startup code should go to startup subsection unless it is
543 unlikely executed (this happens especially with function splitting
544 where we can split away unnecesary parts of static constructors. */
545 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
546 return get_named_text_section (decl
, ".text.startup", NULL
);
548 /* Similarly for exit. */
549 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
550 return get_named_text_section (decl
, ".text.exit", NULL
);
552 /* Group cold functions together, similarly for hot code. */
555 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
556 return get_named_text_section (decl
, ".text.unlikely", NULL
);
557 case NODE_FREQUENCY_HOT
:
558 return get_named_text_section (decl
, ".text.hot", NULL
);
564 /* Return the section for function DECL.
566 If DECL is NULL_TREE, return the text section. We can be passed
567 NULL_TREE under some circumstances by dbxout.c at least.
569 If FORCE_COLD is true, return cold function section ignoring
570 the frequency info of cgraph_node. */
573 function_section_1 (tree decl
, bool force_cold
)
575 section
*section
= NULL
;
576 enum node_frequency freq
= NODE_FREQUENCY_NORMAL
;
577 bool startup
= false, exit
= false;
581 struct cgraph_node
*node
= cgraph_get_node (decl
);
585 freq
= node
->frequency
;
586 startup
= node
->only_called_at_startup
;
587 exit
= node
->only_called_at_exit
;
591 freq
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
593 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
594 if (decl
!= NULL_TREE
595 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
597 if (targetm
.asm_out
.function_section
)
598 section
= targetm
.asm_out
.function_section (decl
, freq
,
602 return get_named_section (decl
, NULL
, 0);
605 return targetm
.asm_out
.select_section
606 (decl
, freq
== NODE_FREQUENCY_UNLIKELY_EXECUTED
,
609 if (targetm
.asm_out
.function_section
)
610 section
= targetm
.asm_out
.function_section (decl
, freq
, startup
, exit
);
613 return hot_function_section (decl
);
617 /* Return the section for function DECL.
619 If DECL is NULL_TREE, return the text section. We can be passed
620 NULL_TREE under some circumstances by dbxout.c at least. */
623 function_section (tree decl
)
625 /* Handle cases where function splitting code decides
626 to put function entry point into unlikely executed section
627 despite the fact that the function itself is not cold
628 (i.e. it is called rarely but contains a hot loop that is
629 better to live in hot subsection for the code locality). */
630 return function_section_1 (decl
,
631 first_function_block_is_cold
);
634 /* Return the section for the current function, take IN_COLD_SECTION_P
638 current_function_section (void)
640 return function_section_1 (current_function_decl
, in_cold_section_p
);
643 /* Tell assembler to switch to unlikely-to-be-executed text section. */
646 unlikely_text_section (void)
648 return function_section_1 (current_function_decl
, true);
651 /* When called within a function context, return true if the function
652 has been assigned a cold text section and if SECT is that section.
653 When called outside a function context, return true if SECT is the
654 default cold section. */
657 unlikely_text_section_p (section
*sect
)
659 return sect
== function_section_1 (current_function_decl
, true);
662 /* Return the read-only data section associated with function DECL. */
665 default_function_rodata_section (tree decl
)
667 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
669 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
671 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
677 dot
= strchr (name
+ 1, '.');
680 len
= strlen (dot
) + 8;
681 rname
= (char *) alloca (len
);
683 strcpy (rname
, ".rodata");
685 return get_section (rname
, SECTION_LINKONCE
, decl
);
687 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
688 else if (DECL_ONE_ONLY (decl
)
689 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
691 size_t len
= strlen (name
) + 1;
692 char *rname
= (char *) alloca (len
);
694 memcpy (rname
, name
, len
);
696 return get_section (rname
, SECTION_LINKONCE
, decl
);
698 /* For .text.foo we want to use .rodata.foo. */
699 else if (flag_function_sections
&& flag_data_sections
700 && strncmp (name
, ".text.", 6) == 0)
702 size_t len
= strlen (name
) + 1;
703 char *rname
= (char *) alloca (len
+ 2);
705 memcpy (rname
, ".rodata", 7);
706 memcpy (rname
+ 7, name
+ 5, len
- 5);
707 return get_section (rname
, 0, decl
);
711 return readonly_data_section
;
714 /* Return the read-only data section associated with function DECL
715 for targets where that section should be always the single
716 readonly data section. */
719 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
721 return readonly_data_section
;
724 /* Return the section to use for string merging. */
727 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
728 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
729 unsigned int flags ATTRIBUTE_UNUSED
)
733 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
734 && TREE_CODE (decl
) == STRING_CST
735 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
737 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
738 && TREE_STRING_LENGTH (decl
) >= len
)
740 enum machine_mode mode
;
741 unsigned int modesize
;
745 const char *prefix
= targetm
.asm_out
.mergeable_rodata_prefix
;
746 char *name
= (char *) alloca (strlen (prefix
) + 30);
748 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
749 modesize
= GET_MODE_BITSIZE (mode
);
750 if (modesize
>= 8 && modesize
<= 256
751 && (modesize
& (modesize
- 1)) == 0)
753 if (align
< modesize
)
756 str
= TREE_STRING_POINTER (decl
);
757 unit
= GET_MODE_SIZE (mode
);
759 /* Check for embedded NUL characters. */
760 for (i
= 0; i
< len
; i
+= unit
)
762 for (j
= 0; j
< unit
; j
++)
763 if (str
[i
+ j
] != '\0')
770 sprintf (name
, "%s.str%d.%d", prefix
,
771 modesize
/ 8, (int) (align
/ 8));
772 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
773 return get_section (name
, flags
, NULL
);
778 return readonly_data_section
;
781 /* Return the section to use for constant merging. */
784 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
785 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
786 unsigned int flags ATTRIBUTE_UNUSED
)
788 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
790 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
796 && (align
& (align
- 1)) == 0)
798 const char *prefix
= targetm
.asm_out
.mergeable_rodata_prefix
;
799 char *name
= (char *) alloca (strlen (prefix
) + 30);
801 sprintf (name
, "%s.cst%d", prefix
, (int) (align
/ 8));
802 flags
|= (align
/ 8) | SECTION_MERGE
;
803 return get_section (name
, flags
, NULL
);
805 return readonly_data_section
;
808 /* Given NAME, a putative register name, discard any customary prefixes. */
811 strip_reg_name (const char *name
)
813 #ifdef REGISTER_PREFIX
814 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
815 name
+= strlen (REGISTER_PREFIX
);
817 if (name
[0] == '%' || name
[0] == '#')
822 /* The user has asked for a DECL to have a particular name. Set (or
823 change) it in such a way that we don't prefix an underscore to
826 set_user_assembler_name (tree decl
, const char *name
)
828 char *starred
= (char *) alloca (strlen (name
) + 2);
830 strcpy (starred
+ 1, name
);
831 change_decl_assembler_name (decl
, get_identifier (starred
));
832 SET_DECL_RTL (decl
, NULL_RTX
);
835 /* Decode an `asm' spec for a declaration as a register name.
836 Return the register number, or -1 if nothing specified,
837 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
838 or -3 if ASMSPEC is `cc' and is not recognized,
839 or -4 if ASMSPEC is `memory' and is not recognized.
840 Accept an exact spelling or a decimal number.
841 Prefixes such as % are optional. */
844 decode_reg_name_and_count (const char *asmspec
, int *pnregs
)
846 /* Presume just one register is clobbered. */
853 /* Get rid of confusing prefixes. */
854 asmspec
= strip_reg_name (asmspec
);
856 /* Allow a decimal number as a "register name". */
857 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
858 if (! ISDIGIT (asmspec
[i
]))
860 if (asmspec
[0] != 0 && i
< 0)
863 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
869 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
871 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
874 #ifdef OVERLAPPING_REGISTER_NAMES
878 const char *const name
;
881 } table
[] = OVERLAPPING_REGISTER_NAMES
;
883 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
885 && ! strcmp (asmspec
, table
[i
].name
))
887 *pnregs
= table
[i
].nregs
;
888 return table
[i
].number
;
891 #endif /* OVERLAPPING_REGISTER_NAMES */
893 #ifdef ADDITIONAL_REGISTER_NAMES
895 static const struct { const char *const name
; const int number
; } table
[]
896 = ADDITIONAL_REGISTER_NAMES
;
898 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
900 && ! strcmp (asmspec
, table
[i
].name
))
901 return table
[i
].number
;
903 #endif /* ADDITIONAL_REGISTER_NAMES */
905 if (!strcmp (asmspec
, "memory"))
908 if (!strcmp (asmspec
, "cc"))
918 decode_reg_name (const char *name
)
921 return decode_reg_name_and_count (name
, &count
);
925 /* Return true if DECL's initializer is suitable for a BSS section. */
928 bss_initializer_p (const_tree decl
)
930 return (DECL_INITIAL (decl
) == NULL
931 || DECL_INITIAL (decl
) == error_mark_node
932 || (flag_zero_initialized_in_bss
933 /* Leave constant zeroes in .rodata so they
935 && !TREE_READONLY (decl
)
936 && initializer_zerop (DECL_INITIAL (decl
))));
939 /* Compute the alignment of variable specified by DECL.
940 DONT_OUTPUT_DATA is from assemble_variable. */
943 align_variable (tree decl
, bool dont_output_data
)
945 unsigned int align
= DECL_ALIGN (decl
);
947 /* In the case for initialing an array whose length isn't specified,
948 where we have not yet been able to do the layout,
949 figure out the proper alignment now. */
950 if (dont_output_data
&& DECL_SIZE (decl
) == 0
951 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
952 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
954 /* Some object file formats have a maximum alignment which they support.
955 In particular, a.out format supports a maximum alignment of 4. */
956 if (align
> MAX_OFILE_ALIGNMENT
)
958 warning (0, "alignment of %q+D is greater than maximum object "
959 "file alignment. Using %d", decl
,
960 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
961 align
= MAX_OFILE_ALIGNMENT
;
964 /* On some machines, it is good to increase alignment sometimes. */
965 if (! DECL_USER_ALIGN (decl
))
967 #ifdef DATA_ALIGNMENT
968 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
969 /* Don't increase alignment too much for TLS variables - TLS space
971 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
974 #ifdef CONSTANT_ALIGNMENT
975 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
977 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
979 /* Don't increase alignment too much for TLS variables - TLS space
981 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
987 /* Reset the alignment in case we have made it tighter, so we can benefit
988 from it in get_pointer_alignment. */
989 DECL_ALIGN (decl
) = align
;
992 /* Return the section into which the given VAR_DECL or CONST_DECL
993 should be placed. PREFER_NOSWITCH_P is true if a noswitch
994 section should be used wherever possible. */
997 get_variable_section (tree decl
, bool prefer_noswitch_p
)
999 addr_space_t as
= ADDR_SPACE_GENERIC
;
1002 if (TREE_TYPE (decl
) != error_mark_node
)
1003 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1005 if (DECL_COMMON (decl
))
1007 /* If the decl has been given an explicit section name, or it resides
1008 in a non-generic address space, then it isn't common, and shouldn't
1009 be handled as such. */
1010 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1011 && ADDR_SPACE_GENERIC_P (as
));
1012 if (DECL_THREAD_LOCAL_P (decl
))
1013 return tls_comm_section
;
1014 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1015 return comm_section
;
1018 if (DECL_INITIAL (decl
) == error_mark_node
)
1019 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1020 else if (DECL_INITIAL (decl
))
1021 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1025 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1026 if (IN_NAMED_SECTION (decl
))
1027 return get_named_section (decl
, NULL
, reloc
);
1029 if (ADDR_SPACE_GENERIC_P (as
)
1030 && !DECL_THREAD_LOCAL_P (decl
)
1031 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1032 && bss_initializer_p (decl
))
1034 if (!TREE_PUBLIC (decl
))
1035 return lcomm_section
;
1036 if (bss_noswitch_section
)
1037 return bss_noswitch_section
;
1040 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
1043 /* Return the block into which object_block DECL should be placed. */
1045 static struct object_block
*
1046 get_block_for_decl (tree decl
)
1050 if (TREE_CODE (decl
) == VAR_DECL
)
1052 /* The object must be defined in this translation unit. */
1053 if (DECL_EXTERNAL (decl
))
1056 /* There's no point using object blocks for something that is
1057 isolated by definition. */
1058 if (DECL_ONE_ONLY (decl
))
1062 /* We can only calculate block offsets if the decl has a known
1064 if (DECL_SIZE_UNIT (decl
) == NULL
)
1066 if (!host_integerp (DECL_SIZE_UNIT (decl
), 1))
1069 /* Find out which section should contain DECL. We cannot put it into
1070 an object block if it requires a standalone definition. */
1071 if (TREE_CODE (decl
) == VAR_DECL
)
1072 align_variable (decl
, 0);
1073 sect
= get_variable_section (decl
, true);
1074 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1077 return get_block_for_section (sect
);
1080 /* Make sure block symbol SYMBOL is in block BLOCK. */
1083 change_symbol_block (rtx symbol
, struct object_block
*block
)
1085 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1087 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1088 SYMBOL_REF_BLOCK (symbol
) = block
;
1092 /* Return true if it is possible to put DECL in an object_block. */
1095 use_blocks_for_decl_p (tree decl
)
1097 /* Only data DECLs can be placed into object blocks. */
1098 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
1101 /* Detect decls created by dw2_force_const_mem. Such decls are
1102 special because DECL_INITIAL doesn't specify the decl's true value.
1103 dw2_output_indirect_constants will instead call assemble_variable
1104 with dont_output_data set to 1 and then print the contents itself. */
1105 if (DECL_INITIAL (decl
) == decl
)
1108 /* If this decl is an alias, then we don't want to emit a
1110 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl
)))
1116 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1117 have static storage duration. In other words, it should not be an
1118 automatic variable, including PARM_DECLs.
1120 There is, however, one exception: this function handles variables
1121 explicitly placed in a particular register by the user.
1123 This is never called for PARM_DECL nodes. */
1126 make_decl_rtl (tree decl
)
1128 const char *name
= 0;
1132 /* Check that we are not being given an automatic variable. */
1133 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1134 && TREE_CODE (decl
) != RESULT_DECL
);
1136 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1137 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1138 || TREE_STATIC (decl
)
1139 || TREE_PUBLIC (decl
)
1140 || DECL_EXTERNAL (decl
)
1141 || DECL_REGISTER (decl
));
1143 /* And that we were not given a type or a label. */
1144 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1145 && TREE_CODE (decl
) != LABEL_DECL
);
1147 /* For a duplicate declaration, we can be called twice on the
1148 same DECL node. Don't discard the RTL already made. */
1149 if (DECL_RTL_SET_P (decl
))
1151 /* If the old RTL had the wrong mode, fix the mode. */
1152 x
= DECL_RTL (decl
);
1153 if (GET_MODE (x
) != DECL_MODE (decl
))
1154 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1156 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1159 /* ??? Another way to do this would be to maintain a hashed
1160 table of such critters. Instead of adding stuff to a DECL
1161 to give certain attributes to it, we could use an external
1162 hash map from DECL to set of attributes. */
1164 /* Let the target reassign the RTL if it wants.
1165 This is necessary, for example, when one machine specific
1166 decl attribute overrides another. */
1167 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1169 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1170 on the new decl information. */
1172 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1173 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1174 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1176 /* Make this function static known to the mudflap runtime. */
1177 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1178 mudflap_enqueue_decl (decl
);
1183 /* If this variable belongs to the global constant pool, retrieve the
1184 pre-computed RTL or recompute it in LTO mode. */
1185 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1187 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1191 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1193 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1194 && DECL_REGISTER (decl
))
1196 error ("register name not specified for %q+D", decl
);
1198 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1200 const char *asmspec
= name
+1;
1201 enum machine_mode mode
= DECL_MODE (decl
);
1202 reg_number
= decode_reg_name (asmspec
);
1203 /* First detect errors in declaring global registers. */
1204 if (reg_number
== -1)
1205 error ("register name not specified for %q+D", decl
);
1206 else if (reg_number
< 0)
1207 error ("invalid register name for %q+D", decl
);
1208 else if (mode
== BLKmode
)
1209 error ("data type of %q+D isn%'t suitable for a register",
1211 else if (!in_hard_reg_set_p (accessible_reg_set
, mode
, reg_number
))
1212 error ("the register specified for %q+D cannot be accessed"
1213 " by the current target", decl
);
1214 else if (!in_hard_reg_set_p (operand_reg_set
, mode
, reg_number
))
1215 error ("the register specified for %q+D is not general enough"
1216 " to be used as a register variable", decl
);
1217 else if (!HARD_REGNO_MODE_OK (reg_number
, mode
))
1218 error ("register specified for %q+D isn%'t suitable for data type",
1220 /* Now handle properly declared static register variables. */
1225 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1227 DECL_INITIAL (decl
) = 0;
1228 error ("global register variable has initial value");
1230 if (TREE_THIS_VOLATILE (decl
))
1231 warning (OPT_Wvolatile_register_var
,
1232 "optimization may eliminate reads and/or "
1233 "writes to register variables");
1235 /* If the user specified one of the eliminables registers here,
1236 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1237 confused with that register and be eliminated. This usage is
1238 somewhat suspect... */
1240 SET_DECL_RTL (decl
, gen_rtx_raw_REG (mode
, reg_number
));
1241 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1242 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1244 if (TREE_STATIC (decl
))
1246 /* Make this register global, so not usable for anything
1248 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1249 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1250 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1252 nregs
= hard_regno_nregs
[reg_number
][mode
];
1254 globalize_reg (decl
, reg_number
+ --nregs
);
1257 /* As a register variable, it has no section. */
1261 /* Now handle ordinary static variables and functions (in memory).
1262 Also handle vars declared register invalidly. */
1263 else if (name
[0] == '*')
1265 #ifdef REGISTER_PREFIX
1266 if (strlen (REGISTER_PREFIX
) != 0)
1268 reg_number
= decode_reg_name (name
);
1269 if (reg_number
>= 0 || reg_number
== -3)
1270 error ("register name given for non-register variable %q+D", decl
);
1275 /* Specifying a section attribute on a variable forces it into a
1276 non-.bss section, and thus it cannot be common. */
1277 /* FIXME: In general this code should not be necessary because
1278 visibility pass is doing the same work. But notice_global_symbol
1279 is called early and it needs to make DECL_RTL to get the name.
1280 we take care of recomputing the DECL_RTL after visibility is changed. */
1281 if (TREE_CODE (decl
) == VAR_DECL
1282 && DECL_SECTION_NAME (decl
) != NULL_TREE
1283 && DECL_INITIAL (decl
) == NULL_TREE
1284 && DECL_COMMON (decl
))
1285 DECL_COMMON (decl
) = 0;
1287 /* Variables can't be both common and weak. */
1288 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1289 DECL_COMMON (decl
) = 0;
1291 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1292 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1295 enum machine_mode address_mode
= Pmode
;
1296 if (TREE_TYPE (decl
) != error_mark_node
)
1298 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1299 address_mode
= targetm
.addr_space
.address_mode (as
);
1301 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1303 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1304 SET_SYMBOL_REF_DECL (x
, decl
);
1306 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1307 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1308 set_mem_attributes (x
, decl
, 1);
1309 SET_DECL_RTL (decl
, x
);
1311 /* Optionally set flags or add text to the name to record information
1312 such as that it is a function name.
1313 If the name is changed, the macro ASM_OUTPUT_LABELREF
1314 will have to know how to strip this information. */
1315 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1317 /* Make this function static known to the mudflap runtime. */
1318 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1319 mudflap_enqueue_decl (decl
);
1322 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1323 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1327 make_decl_rtl_for_debug (tree decl
)
1329 unsigned int save_aliasing_flag
, save_mudflap_flag
;
1332 if (DECL_RTL_SET_P (decl
))
1333 return DECL_RTL (decl
);
1335 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1336 call new_alias_set. If running with -fcompare-debug, sometimes
1337 we do not want to create alias sets that will throw the alias
1338 numbers off in the comparison dumps. So... clearing
1339 flag_strict_aliasing will keep new_alias_set() from creating a
1340 new set. It is undesirable to register decl with mudflap
1341 in this case as well. */
1342 save_aliasing_flag
= flag_strict_aliasing
;
1343 flag_strict_aliasing
= 0;
1344 save_mudflap_flag
= flag_mudflap
;
1347 rtl
= DECL_RTL (decl
);
1348 /* Reset DECL_RTL back, as various parts of the compiler expects
1349 DECL_RTL set meaning it is actually going to be output. */
1350 SET_DECL_RTL (decl
, NULL
);
1352 flag_strict_aliasing
= save_aliasing_flag
;
1353 flag_mudflap
= save_mudflap_flag
;
1358 /* Output a string of literal assembler code
1359 for an `asm' keyword used between functions. */
1362 assemble_asm (tree string
)
1366 if (TREE_CODE (string
) == ADDR_EXPR
)
1367 string
= TREE_OPERAND (string
, 0);
1369 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1372 /* Record an element in the table of global destructors. SYMBOL is
1373 a SYMBOL_REF of the function to be called; PRIORITY is a number
1374 between 0 and MAX_INIT_PRIORITY. */
1377 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
1378 int priority ATTRIBUTE_UNUSED
)
1380 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1381 /* Tell GNU LD that this is part of the static destructor set.
1382 This will work for any system that uses stabs, most usefully
1384 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1385 dbxout_stab_value_label (XSTR (symbol
, 0));
1387 sorry ("global destructors not supported on this target");
1391 /* Write the address of the entity given by SYMBOL to SEC. */
1393 assemble_addr_to_section (rtx symbol
, section
*sec
)
1395 switch_to_section (sec
);
1396 assemble_align (POINTER_SIZE
);
1397 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1400 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1401 not) section for PRIORITY. */
1403 get_cdtor_priority_section (int priority
, bool constructor_p
)
1407 /* ??? This only works reliably with the GNU linker. */
1408 sprintf (buf
, "%s.%.5u",
1409 constructor_p
? ".ctors" : ".dtors",
1410 /* Invert the numbering so the linker puts us in the proper
1411 order; constructors are run from right to left, and the
1412 linker sorts in increasing order. */
1413 MAX_INIT_PRIORITY
- priority
);
1414 return get_section (buf
, SECTION_WRITE
, NULL
);
1418 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1422 if (priority
!= DEFAULT_INIT_PRIORITY
)
1423 sec
= get_cdtor_priority_section (priority
,
1424 /*constructor_p=*/false);
1426 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1428 assemble_addr_to_section (symbol
, sec
);
1431 #ifdef DTORS_SECTION_ASM_OP
1433 default_dtor_section_asm_out_destructor (rtx symbol
,
1434 int priority ATTRIBUTE_UNUSED
)
1436 assemble_addr_to_section (symbol
, dtors_section
);
1440 /* Likewise for global constructors. */
1443 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
1444 int priority ATTRIBUTE_UNUSED
)
1446 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1447 /* Tell GNU LD that this is part of the static destructor set.
1448 This will work for any system that uses stabs, most usefully
1450 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1451 dbxout_stab_value_label (XSTR (symbol
, 0));
1453 sorry ("global constructors not supported on this target");
1458 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1462 if (priority
!= DEFAULT_INIT_PRIORITY
)
1463 sec
= get_cdtor_priority_section (priority
,
1464 /*constructor_p=*/true);
1466 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1468 assemble_addr_to_section (symbol
, sec
);
1471 #ifdef CTORS_SECTION_ASM_OP
1473 default_ctor_section_asm_out_constructor (rtx symbol
,
1474 int priority ATTRIBUTE_UNUSED
)
1476 assemble_addr_to_section (symbol
, ctors_section
);
1480 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1481 a nonzero value if the constant pool should be output before the
1482 start of the function, or a zero value if the pool should output
1483 after the end of the function. The default is to put it before the
1486 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1487 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1490 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1491 to be output to assembler.
1492 Set first_global_object_name and weak_global_object_name as appropriate. */
1495 notice_global_symbol (tree decl
)
1497 const char **type
= &first_global_object_name
;
1499 if (first_global_object_name
1500 || !TREE_PUBLIC (decl
)
1501 || DECL_EXTERNAL (decl
)
1502 || !DECL_NAME (decl
)
1503 || (TREE_CODE (decl
) != FUNCTION_DECL
1504 && (TREE_CODE (decl
) != VAR_DECL
1505 || (DECL_COMMON (decl
)
1506 && (DECL_INITIAL (decl
) == 0
1507 || DECL_INITIAL (decl
) == error_mark_node
))))
1508 || !MEM_P (DECL_RTL (decl
)))
1511 /* We win when global object is found, but it is useful to know about weak
1512 symbol as well so we can produce nicer unique names. */
1513 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1514 type
= &weak_global_object_name
;
1520 rtx decl_rtl
= DECL_RTL (decl
);
1522 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1523 name
= ggc_strdup (p
);
1529 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1530 current function goes into the cold section, so that targets can use
1531 current_function_section during RTL expansion. DECL describes the
1535 decide_function_section (tree decl
)
1537 first_function_block_is_cold
= false;
1539 if (flag_reorder_blocks_and_partition
)
1540 /* We will decide in assemble_start_function. */
1543 if (DECL_SECTION_NAME (decl
))
1545 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
1546 /* Calls to function_section rely on first_function_block_is_cold
1548 first_function_block_is_cold
= (node
1550 == NODE_FREQUENCY_UNLIKELY_EXECUTED
);
1553 in_cold_section_p
= first_function_block_is_cold
;
1556 /* Output assembler code for the constant pool of a function and associated
1557 with defining the name of the function. DECL describes the function.
1558 NAME is the function's name. For the constant pool, we use the current
1559 constant pool data. */
1562 assemble_start_function (tree decl
, const char *fnname
)
1565 char tmp_label
[100];
1566 bool hot_label_written
= false;
1568 if (flag_reorder_blocks_and_partition
)
1570 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1571 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1572 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1573 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1574 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1575 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1576 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1577 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1582 crtl
->subsections
.hot_section_label
= NULL
;
1583 crtl
->subsections
.cold_section_label
= NULL
;
1584 crtl
->subsections
.hot_section_end_label
= NULL
;
1585 crtl
->subsections
.cold_section_end_label
= NULL
;
1588 /* The following code does not need preprocessing in the assembler. */
1592 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1593 output_constant_pool (fnname
, decl
);
1595 /* Make sure the not and cold text (code) sections are properly
1596 aligned. This is necessary here in the case where the function
1597 has both hot and cold sections, because we don't want to re-set
1598 the alignment when the section switch happens mid-function. */
1600 if (flag_reorder_blocks_and_partition
)
1602 first_function_block_is_cold
= false;
1604 switch_to_section (unlikely_text_section ());
1605 assemble_align (DECL_ALIGN (decl
));
1606 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1608 /* When the function starts with a cold section, we need to explicitly
1609 align the hot section and write out the hot section label.
1610 But if the current function is a thunk, we do not have a CFG. */
1612 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1614 switch_to_section (text_section
);
1615 assemble_align (DECL_ALIGN (decl
));
1616 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1617 hot_label_written
= true;
1618 first_function_block_is_cold
= true;
1620 in_cold_section_p
= first_function_block_is_cold
;
1624 /* Switch to the correct text section for the start of the function. */
1626 switch_to_section (function_section (decl
));
1627 if (flag_reorder_blocks_and_partition
1628 && !hot_label_written
)
1629 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1631 /* Tell assembler to move to target machine's alignment for functions. */
1632 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1635 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1638 /* Handle a user-specified function alignment.
1639 Note that we still need to align to DECL_ALIGN, as above,
1640 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1641 if (! DECL_USER_ALIGN (decl
)
1642 && align_functions_log
> align
1643 && optimize_function_for_speed_p (cfun
))
1645 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1646 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1647 align_functions_log
, align_functions
- 1);
1649 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1653 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1654 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1657 if (!DECL_IGNORED_P (decl
))
1658 (*debug_hooks
->begin_function
) (decl
);
1660 /* Make function name accessible from other files, if appropriate. */
1662 if (TREE_PUBLIC (decl
))
1664 notice_global_symbol (decl
);
1666 globalize_decl (decl
);
1668 maybe_assemble_visibility (decl
);
1671 if (DECL_PRESERVE_P (decl
))
1672 targetm
.asm_out
.mark_decl_preserved (fnname
);
1674 /* Do any machine/system dependent processing of the function name. */
1675 #ifdef ASM_DECLARE_FUNCTION_NAME
1676 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1678 /* Standard thing is just output label for the function. */
1679 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1680 #endif /* ASM_DECLARE_FUNCTION_NAME */
1682 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1683 saw_no_split_stack
= true;
1686 /* Output assembler code associated with defining the size of the
1687 function. DECL describes the function. NAME is the function's name. */
1690 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1692 #ifdef ASM_DECLARE_FUNCTION_SIZE
1693 /* We could have switched section in the middle of the function. */
1694 if (flag_reorder_blocks_and_partition
)
1695 switch_to_section (function_section (decl
));
1696 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1698 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1700 output_constant_pool (fnname
, decl
);
1701 switch_to_section (function_section (decl
)); /* need to switch back */
1703 /* Output labels for end of hot/cold text sections (to be used by
1705 if (flag_reorder_blocks_and_partition
)
1707 section
*save_text_section
;
1709 save_text_section
= in_section
;
1710 switch_to_section (unlikely_text_section ());
1711 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1712 if (first_function_block_is_cold
)
1713 switch_to_section (text_section
);
1715 switch_to_section (function_section (decl
));
1716 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1717 switch_to_section (save_text_section
);
1721 /* Assemble code to leave SIZE bytes of zeros. */
1724 assemble_zeros (unsigned HOST_WIDE_INT size
)
1726 /* Do no output if -fsyntax-only. */
1727 if (flag_syntax_only
)
1730 #ifdef ASM_NO_SKIP_IN_TEXT
1731 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1732 so we must output 0s explicitly in the text section. */
1733 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1735 unsigned HOST_WIDE_INT i
;
1736 for (i
= 0; i
< size
; i
++)
1737 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1742 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1745 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1748 assemble_align (int align
)
1750 if (align
> BITS_PER_UNIT
)
1752 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1756 /* Assemble a string constant with the specified C string as contents. */
1759 assemble_string (const char *p
, int size
)
1764 /* If the string is very long, split it up. */
1768 int thissize
= size
- pos
;
1769 if (thissize
> maximum
)
1772 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1780 /* A noswitch_section_callback for lcomm_section. */
1783 emit_local (tree decl ATTRIBUTE_UNUSED
,
1784 const char *name ATTRIBUTE_UNUSED
,
1785 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1786 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1788 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1789 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1790 size
, DECL_ALIGN (decl
));
1792 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1793 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1796 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1801 /* A noswitch_section_callback for bss_noswitch_section. */
1803 #if defined ASM_OUTPUT_ALIGNED_BSS
1805 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1806 const char *name ATTRIBUTE_UNUSED
,
1807 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1808 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1810 #if defined ASM_OUTPUT_ALIGNED_BSS
1811 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
, DECL_ALIGN (decl
));
1817 /* A noswitch_section_callback for comm_section. */
1820 emit_common (tree decl ATTRIBUTE_UNUSED
,
1821 const char *name ATTRIBUTE_UNUSED
,
1822 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1823 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1825 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1826 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1827 size
, DECL_ALIGN (decl
));
1829 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1830 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1833 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1838 /* A noswitch_section_callback for tls_comm_section. */
1841 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1842 const char *name ATTRIBUTE_UNUSED
,
1843 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1844 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1846 #ifdef ASM_OUTPUT_TLS_COMMON
1847 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1850 sorry ("thread-local COMMON data not implemented");
1855 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1856 NAME is the name of DECL's SYMBOL_REF. */
1859 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
)
1861 unsigned HOST_WIDE_INT size
, rounded
;
1863 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1866 /* Don't allocate zero bytes of common,
1867 since that means "undefined external" in the linker. */
1871 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1872 so that each uninitialized object starts on such a boundary. */
1873 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1874 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1875 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1877 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
1878 && (unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
1879 warning (0, "requested alignment for %q+D is greater than "
1880 "implemented alignment of %wu", decl
, rounded
);
1883 /* A subroutine of assemble_variable. Output the label and contents of
1884 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1885 is as for assemble_variable. */
1888 assemble_variable_contents (tree decl
, const char *name
,
1889 bool dont_output_data
)
1891 /* Do any machine/system dependent processing of the object. */
1892 #ifdef ASM_DECLARE_OBJECT_NAME
1893 last_assemble_variable_decl
= decl
;
1894 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1896 /* Standard thing is just output label for the object. */
1897 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1898 #endif /* ASM_DECLARE_OBJECT_NAME */
1900 if (!dont_output_data
)
1902 if (DECL_INITIAL (decl
)
1903 && DECL_INITIAL (decl
) != error_mark_node
1904 && !initializer_zerop (DECL_INITIAL (decl
)))
1905 /* Output the actual data. */
1906 output_constant (DECL_INITIAL (decl
),
1907 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1910 /* Leave space for it. */
1911 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1915 /* Assemble everything that is needed for a variable or function declaration.
1916 Not used for automatic variables, and not used for function definitions.
1917 Should not be called for variables of incomplete structure type.
1919 TOP_LEVEL is nonzero if this variable has file scope.
1920 AT_END is nonzero if this is the special handling, at end of compilation,
1921 to define things that have had only tentative definitions.
1922 DONT_OUTPUT_DATA if nonzero means don't actually output the
1923 initial value (that will be done by the caller). */
1926 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
1927 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
1930 rtx decl_rtl
, symbol
;
1933 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1934 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
1936 /* Emulated TLS had better not get this far. */
1937 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
1939 last_assemble_variable_decl
= 0;
1941 /* Normally no need to say anything here for external references,
1942 since assemble_external is called by the language-specific code
1943 when a declaration is first seen. */
1945 if (DECL_EXTERNAL (decl
))
1948 /* Do nothing for global register variables. */
1949 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
1951 TREE_ASM_WRITTEN (decl
) = 1;
1955 /* If type was incomplete when the variable was declared,
1956 see if it is complete now. */
1958 if (DECL_SIZE (decl
) == 0)
1959 layout_decl (decl
, 0);
1961 /* Still incomplete => don't allocate it; treat the tentative defn
1962 (which is what it must have been) as an `extern' reference. */
1964 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1966 error ("storage size of %q+D isn%'t known", decl
);
1967 TREE_ASM_WRITTEN (decl
) = 1;
1971 /* The first declaration of a variable that comes through this function
1972 decides whether it is global (in C, has external linkage)
1973 or local (in C, has internal linkage). So do nothing more
1974 if this function has already run. */
1976 if (TREE_ASM_WRITTEN (decl
))
1979 /* Make sure targetm.encode_section_info is invoked before we set
1981 decl_rtl
= DECL_RTL (decl
);
1983 TREE_ASM_WRITTEN (decl
) = 1;
1985 /* Do no output if -fsyntax-only. */
1986 if (flag_syntax_only
)
1989 if (! dont_output_data
1990 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1992 error ("size of variable %q+D is too large", decl
);
1996 gcc_assert (MEM_P (decl_rtl
));
1997 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
1998 symbol
= XEXP (decl_rtl
, 0);
2000 /* If this symbol belongs to the tree constant pool, output the constant
2001 if it hasn't already been written. */
2002 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
2004 tree decl
= SYMBOL_REF_DECL (symbol
);
2005 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2006 output_constant_def_contents (symbol
);
2012 name
= XSTR (symbol
, 0);
2013 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2014 notice_global_symbol (decl
);
2016 /* Compute the alignment of this data. */
2018 align_variable (decl
, dont_output_data
);
2019 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2021 if (TREE_PUBLIC (decl
))
2022 maybe_assemble_visibility (decl
);
2024 if (DECL_PRESERVE_P (decl
))
2025 targetm
.asm_out
.mark_decl_preserved (name
);
2027 /* First make the assembler name(s) global if appropriate. */
2028 sect
= get_variable_section (decl
, false);
2029 if (TREE_PUBLIC (decl
)
2030 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2031 globalize_decl (decl
);
2033 /* Output any data that we will need to use the address of. */
2034 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2035 output_addressed_constants (DECL_INITIAL (decl
));
2037 /* dbxout.c needs to know this. */
2038 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2039 DECL_IN_TEXT_SECTION (decl
) = 1;
2041 /* If the decl is part of an object_block, make sure that the decl
2042 has been positioned within its block, but do not write out its
2043 definition yet. output_object_blocks will do that later. */
2044 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2046 gcc_assert (!dont_output_data
);
2047 place_block_symbol (symbol
);
2049 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2050 assemble_noswitch_variable (decl
, name
, sect
);
2053 switch_to_section (sect
);
2054 if (DECL_ALIGN (decl
) > BITS_PER_UNIT
)
2055 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
2056 assemble_variable_contents (decl
, name
, dont_output_data
);
2060 /* Return 1 if type TYPE contains any pointers. */
2063 contains_pointers_p (tree type
)
2065 switch (TREE_CODE (type
))
2068 case REFERENCE_TYPE
:
2069 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2070 so I'll play safe and return 1. */
2076 case QUAL_UNION_TYPE
:
2079 /* For a type that has fields, see if the fields have pointers. */
2080 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
2081 if (TREE_CODE (fields
) == FIELD_DECL
2082 && contains_pointers_p (TREE_TYPE (fields
)))
2088 /* An array type contains pointers if its element type does. */
2089 return contains_pointers_p (TREE_TYPE (type
));
2096 /* We delay assemble_external processing until
2097 the compilation unit is finalized. This is the best we can do for
2098 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2099 it all the way to final. See PR 17982 for further discussion. */
2100 static GTY(()) tree pending_assemble_externals
;
2102 #ifdef ASM_OUTPUT_EXTERNAL
2103 /* True if DECL is a function decl for which no out-of-line copy exists.
2104 It is assumed that DECL's assembler name has been set. */
2107 incorporeal_function_p (tree decl
)
2109 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2113 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2114 && (DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
2115 || DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA_WITH_ALIGN
))
2118 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2119 /* Atomic or sync builtins which have survived this far will be
2120 resolved externally and therefore are not incorporeal. */
2121 if (strncmp (name
, "__builtin_", 10) == 0)
2127 /* Actually do the tests to determine if this is necessary, and invoke
2128 ASM_OUTPUT_EXTERNAL. */
2130 assemble_external_real (tree decl
)
2132 rtx rtl
= DECL_RTL (decl
);
2134 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2135 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2136 && !incorporeal_function_p (decl
))
2138 /* Some systems do require some output. */
2139 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2140 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2146 process_pending_assemble_externals (void)
2148 #ifdef ASM_OUTPUT_EXTERNAL
2150 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2151 assemble_external_real (TREE_VALUE (list
));
2153 pending_assemble_externals
= 0;
2157 /* This TREE_LIST contains any weak symbol declarations waiting
2159 static GTY(()) tree weak_decls
;
2161 /* Output something to declare an external symbol to the assembler,
2162 and qualifiers such as weakness. (Most assemblers don't need
2163 extern declaration, so we normally output nothing.) Do nothing if
2164 DECL is not external. */
2167 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2169 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2170 main body of this code is only rarely exercised. To provide some
2171 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2172 open. If it's not, we should not be calling this function. */
2173 gcc_assert (asm_out_file
);
2175 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2178 /* We want to output annotation for weak and external symbols at
2179 very last to check if they are references or not. */
2181 if (TARGET_SUPPORTS_WEAK
2183 /* TREE_STATIC is a weird and abused creature which is not
2184 generally the right test for whether an entity has been
2185 locally emitted, inlined or otherwise not-really-extern, but
2186 for declarations that can be weak, it happens to be
2188 && !TREE_STATIC (decl
)
2189 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2190 && value_member (decl
, weak_decls
) == NULL_TREE
)
2191 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2193 #ifdef ASM_OUTPUT_EXTERNAL
2194 if (value_member (decl
, pending_assemble_externals
) == NULL_TREE
)
2195 pending_assemble_externals
= tree_cons (NULL
, decl
,
2196 pending_assemble_externals
);
2200 /* Similar, for calling a library function FUN. */
2203 assemble_external_libcall (rtx fun
)
2205 /* Declare library function name external when first used, if nec. */
2206 if (! SYMBOL_REF_USED (fun
))
2208 SYMBOL_REF_USED (fun
) = 1;
2209 targetm
.asm_out
.external_libcall (fun
);
2213 /* Assemble a label named NAME. */
2216 assemble_label (FILE *file
, const char *name
)
2218 ASM_OUTPUT_LABEL (file
, name
);
2221 /* Set the symbol_referenced flag for ID. */
2223 mark_referenced (tree id
)
2225 TREE_SYMBOL_REFERENCED (id
) = 1;
2228 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2230 mark_decl_referenced (tree decl
)
2232 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2234 /* Extern inline functions don't become needed when referenced.
2235 If we know a method will be emitted in other TU and no new
2236 functions can be marked reachable, just use the external
2238 struct cgraph_node
*node
= cgraph_get_create_node (decl
);
2239 if (!DECL_EXTERNAL (decl
)
2240 && !node
->local
.finalized
)
2241 cgraph_mark_needed_node (node
);
2243 else if (TREE_CODE (decl
) == VAR_DECL
)
2245 struct varpool_node
*node
= varpool_node (decl
);
2246 varpool_mark_needed_node (node
);
2247 /* C++ frontend use mark_decl_references to force COMDAT variables
2248 to be output that might appear dead otherwise. */
2249 node
->force_output
= true;
2251 /* else do nothing - we can get various sorts of CST nodes here,
2252 which do not need to be marked. */
2256 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2257 until we find an identifier that is not itself a transparent alias.
2258 Modify the alias passed to it by reference (and all aliases on the
2259 way to the ultimate target), such that they do not have to be
2260 followed again, and return the ultimate target of the alias
2264 ultimate_transparent_alias_target (tree
*alias
)
2266 tree target
= *alias
;
2268 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2270 gcc_assert (TREE_CHAIN (target
));
2271 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2272 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2273 && ! TREE_CHAIN (target
));
2280 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2281 starts with a *, the rest of NAME is output verbatim. Otherwise
2282 NAME is transformed in a target-specific way (usually by the
2283 addition of an underscore). */
2286 assemble_name_raw (FILE *file
, const char *name
)
2289 fputs (&name
[1], file
);
2291 ASM_OUTPUT_LABELREF (file
, name
);
2294 /* Like assemble_name_raw, but should be used when NAME might refer to
2295 an entity that is also represented as a tree (like a function or
2296 variable). If NAME does refer to such an entity, that entity will
2297 be marked as referenced. */
2300 assemble_name (FILE *file
, const char *name
)
2302 const char *real_name
;
2305 real_name
= targetm
.strip_name_encoding (name
);
2307 id
= maybe_get_identifier (real_name
);
2312 mark_referenced (id
);
2313 ultimate_transparent_alias_target (&id
);
2315 name
= IDENTIFIER_POINTER (id
);
2316 gcc_assert (! TREE_CHAIN (id
));
2319 assemble_name_raw (file
, name
);
2322 /* Allocate SIZE bytes writable static space with a gensym name
2323 and return an RTX to refer to its address. */
2326 assemble_static_space (unsigned HOST_WIDE_INT size
)
2329 const char *namestring
;
2332 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2334 namestring
= ggc_strdup (name
);
2336 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2337 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2339 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2340 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2343 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2344 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2347 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2348 so that each uninitialized object starts on such a boundary. */
2349 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2350 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2351 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2352 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2353 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2354 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2361 /* Assemble the static constant template for function entry trampolines.
2362 This is done at most once per compilation.
2363 Returns an RTX for the address of the template. */
2365 static GTY(()) rtx initial_trampoline
;
2368 assemble_trampoline_template (void)
2375 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2377 if (initial_trampoline
)
2378 return initial_trampoline
;
2380 /* By default, put trampoline templates in read-only data section. */
2382 #ifdef TRAMPOLINE_SECTION
2383 switch_to_section (TRAMPOLINE_SECTION
);
2385 switch_to_section (readonly_data_section
);
2388 /* Write the assembler code to define one. */
2389 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2391 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2393 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2394 targetm
.asm_out
.trampoline_template (asm_out_file
);
2396 /* Record the rtl to refer to it. */
2397 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2398 name
= ggc_strdup (label
);
2399 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2400 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2402 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2403 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2404 set_mem_size (initial_trampoline
, TRAMPOLINE_SIZE
);
2406 return initial_trampoline
;
2409 /* A and B are either alignments or offsets. Return the minimum alignment
2410 that may be assumed after adding the two together. */
2412 static inline unsigned
2413 min_align (unsigned int a
, unsigned int b
)
2415 return (a
| b
) & -(a
| b
);
2418 /* Return the assembler directive for creating a given kind of integer
2419 object. SIZE is the number of bytes in the object and ALIGNED_P
2420 indicates whether it is known to be aligned. Return NULL if the
2421 assembly dialect has no such directive.
2423 The returned string should be printed at the start of a new line and
2424 be followed immediately by the object's initial value. */
2427 integer_asm_op (int size
, int aligned_p
)
2429 struct asm_int_op
*ops
;
2432 ops
= &targetm
.asm_out
.aligned_op
;
2434 ops
= &targetm
.asm_out
.unaligned_op
;
2439 return targetm
.asm_out
.byte_op
;
2453 /* Use directive OP to assemble an integer object X. Print OP at the
2454 start of the line, followed immediately by the value of X. */
2457 assemble_integer_with_op (const char *op
, rtx x
)
2459 fputs (op
, asm_out_file
);
2460 output_addr_const (asm_out_file
, x
);
2461 fputc ('\n', asm_out_file
);
2464 /* The default implementation of the asm_out.integer target hook. */
2467 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2468 unsigned int size ATTRIBUTE_UNUSED
,
2469 int aligned_p ATTRIBUTE_UNUSED
)
2471 const char *op
= integer_asm_op (size
, aligned_p
);
2472 /* Avoid GAS bugs for large values. Specifically negative values whose
2473 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2474 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2476 return op
&& (assemble_integer_with_op (op
, x
), true);
2479 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2480 the alignment of the integer in bits. Return 1 if we were able to output
2481 the constant, otherwise 0. We must be able to output the constant,
2482 if FORCE is nonzero. */
2485 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2489 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2491 /* See if the target hook can handle this kind of object. */
2492 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2495 /* If the object is a multi-byte one, try splitting it up. Split
2496 it into words it if is multi-word, otherwise split it into bytes. */
2499 enum machine_mode omode
, imode
;
2500 unsigned int subalign
;
2501 unsigned int subsize
, i
;
2502 enum mode_class mclass
;
2504 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2505 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2506 if (GET_CODE (x
) == CONST_FIXED
)
2507 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2511 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2512 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2514 for (i
= 0; i
< size
; i
+= subsize
)
2516 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2517 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2523 /* If we've printed some of it, but not all of it, there's no going
2528 gcc_assert (!force
);
2534 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2536 long data
[4] = {0, 0, 0, 0};
2538 int bitsize
, nelts
, nunits
, units_per
;
2540 /* This is hairy. We have a quantity of known size. real_to_target
2541 will put it into an array of *host* longs, 32 bits per element
2542 (even if long is more than 32 bits). We need to determine the
2543 number of array elements that are occupied (nelts) and the number
2544 of *target* min-addressable units that will be occupied in the
2545 object file (nunits). We cannot assume that 32 divides the
2546 mode's bitsize (size * BITS_PER_UNIT) evenly.
2548 size * BITS_PER_UNIT is used here to make sure that padding bits
2549 (which might appear at either end of the value; real_to_target
2550 will include the padding bits in its output array) are included. */
2552 nunits
= GET_MODE_SIZE (mode
);
2553 bitsize
= nunits
* BITS_PER_UNIT
;
2554 nelts
= CEIL (bitsize
, 32);
2555 units_per
= 32 / BITS_PER_UNIT
;
2557 real_to_target (data
, &d
, mode
);
2559 /* Put out the first word with the specified alignment. */
2560 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2561 nunits
-= units_per
;
2563 /* Subsequent words need only 32-bit alignment. */
2564 align
= min_align (align
, 32);
2566 for (i
= 1; i
< nelts
; i
++)
2568 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2569 nunits
-= units_per
;
2573 /* Given an expression EXP with a constant value,
2574 reduce it to the sum of an assembler symbol and an integer.
2575 Store them both in the structure *VALUE.
2576 EXP must be reducible. */
2580 HOST_WIDE_INT offset
;
2584 decode_addr_const (tree exp
, struct addr_const
*value
)
2586 tree target
= TREE_OPERAND (exp
, 0);
2592 if (TREE_CODE (target
) == COMPONENT_REF
2593 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2595 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2596 target
= TREE_OPERAND (target
, 0);
2598 else if (TREE_CODE (target
) == ARRAY_REF
2599 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2601 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2602 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2603 target
= TREE_OPERAND (target
, 0);
2605 else if (TREE_CODE (target
) == MEM_REF
2606 && TREE_CODE (TREE_OPERAND (target
, 0)) == ADDR_EXPR
)
2608 offset
+= mem_ref_offset (target
).low
;
2609 target
= TREE_OPERAND (TREE_OPERAND (target
, 0), 0);
2611 else if (TREE_CODE (target
) == INDIRECT_REF
2612 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2613 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2615 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2620 switch (TREE_CODE (target
))
2624 x
= DECL_RTL (target
);
2628 x
= gen_rtx_MEM (FUNCTION_MODE
,
2629 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2638 x
= output_constant_def (target
, 1);
2645 gcc_assert (MEM_P (x
));
2649 value
->offset
= offset
;
2653 static GTY((param_is (struct constant_descriptor_tree
)))
2654 htab_t const_desc_htab
;
2656 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2658 /* Constant pool accessor function. */
2661 constant_pool_htab (void)
2663 return const_desc_htab
;
2666 /* Compute a hash code for a constant expression. */
2669 const_desc_hash (const void *ptr
)
2671 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2675 const_hash_1 (const tree exp
)
2680 enum tree_code code
= TREE_CODE (exp
);
2682 /* Either set P and LEN to the address and len of something to hash and
2683 exit the switch or return a value. */
2688 p
= (char *) &TREE_INT_CST (exp
);
2689 len
= sizeof TREE_INT_CST (exp
);
2693 return real_hash (TREE_REAL_CST_PTR (exp
));
2696 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2699 p
= TREE_STRING_POINTER (exp
);
2700 len
= TREE_STRING_LENGTH (exp
);
2704 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2705 + const_hash_1 (TREE_IMAGPART (exp
)));
2711 hi
= 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
));
2713 for (link
= TREE_VECTOR_CST_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2714 hi
= hi
* 563 + const_hash_1 (TREE_VALUE (link
));
2721 unsigned HOST_WIDE_INT idx
;
2724 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2726 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2728 hi
= hi
* 603 + const_hash_1 (value
);
2736 struct addr_const value
;
2738 decode_addr_const (exp
, &value
);
2739 switch (GET_CODE (value
.base
))
2742 /* Don't hash the address of the SYMBOL_REF;
2743 only use the offset and the symbol name. */
2745 p
= XSTR (value
.base
, 0);
2746 for (i
= 0; p
[i
] != 0; i
++)
2747 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2751 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2761 case POINTER_PLUS_EXPR
:
2763 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2764 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2767 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2770 /* A language specific constant. Just hash the code. */
2774 /* Compute hashing function. */
2776 for (i
= 0; i
< len
; i
++)
2777 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2782 /* Wrapper of compare_constant, for the htab interface. */
2784 const_desc_eq (const void *p1
, const void *p2
)
2786 const struct constant_descriptor_tree
*const c1
2787 = (const struct constant_descriptor_tree
*) p1
;
2788 const struct constant_descriptor_tree
*const c2
2789 = (const struct constant_descriptor_tree
*) p2
;
2790 if (c1
->hash
!= c2
->hash
)
2792 return compare_constant (c1
->value
, c2
->value
);
2795 /* Compare t1 and t2, and return 1 only if they are known to result in
2796 the same bit pattern on output. */
2799 compare_constant (const tree t1
, const tree t2
)
2801 enum tree_code typecode
;
2803 if (t1
== NULL_TREE
)
2804 return t2
== NULL_TREE
;
2805 if (t2
== NULL_TREE
)
2808 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2811 switch (TREE_CODE (t1
))
2814 /* Integer constants are the same only if the same width of type. */
2815 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2817 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2819 return tree_int_cst_equal (t1
, t2
);
2822 /* Real constants are the same only if the same width of type. */
2823 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2826 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2829 /* Fixed constants are the same only if the same width of type. */
2830 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2833 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
2836 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2839 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2840 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2841 TREE_STRING_LENGTH (t1
)));
2844 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2845 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2851 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1
))
2852 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2
)))
2855 link2
= TREE_VECTOR_CST_ELTS (t2
);
2856 for (link1
= TREE_VECTOR_CST_ELTS (t1
);
2858 link1
= TREE_CHAIN (link1
))
2860 if (!compare_constant (TREE_VALUE (link1
), TREE_VALUE (link2
)))
2862 link2
= TREE_CHAIN (link2
);
2870 VEC(constructor_elt
, gc
) *v1
, *v2
;
2871 unsigned HOST_WIDE_INT idx
;
2873 typecode
= TREE_CODE (TREE_TYPE (t1
));
2874 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
2877 if (typecode
== ARRAY_TYPE
)
2879 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
2880 /* For arrays, check that the sizes all match. */
2881 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
2883 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
2888 /* For record and union constructors, require exact type
2890 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
2894 v1
= CONSTRUCTOR_ELTS (t1
);
2895 v2
= CONSTRUCTOR_ELTS (t2
);
2896 if (VEC_length (constructor_elt
, v1
)
2897 != VEC_length (constructor_elt
, v2
))
2900 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
2902 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
2903 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
2905 /* Check that each value is the same... */
2906 if (!compare_constant (c1
->value
, c2
->value
))
2908 /* ... and that they apply to the same fields! */
2909 if (typecode
== ARRAY_TYPE
)
2911 if (!compare_constant (c1
->index
, c2
->index
))
2916 if (c1
->index
!= c2
->index
)
2927 struct addr_const value1
, value2
;
2931 decode_addr_const (t1
, &value1
);
2932 decode_addr_const (t2
, &value2
);
2934 if (value1
.offset
!= value2
.offset
)
2937 code
= GET_CODE (value1
.base
);
2938 if (code
!= GET_CODE (value2
.base
))
2944 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
2948 ret
= (CODE_LABEL_NUMBER (XEXP (value1
.base
, 0))
2949 == CODE_LABEL_NUMBER (XEXP (value2
.base
, 0)));
2959 case POINTER_PLUS_EXPR
:
2962 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2963 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2966 case VIEW_CONVERT_EXPR
:
2967 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2976 /* Make a copy of the whole tree structure for a constant. This
2977 handles the same types of nodes that compare_constant handles. */
2980 copy_constant (tree exp
)
2982 switch (TREE_CODE (exp
))
2985 /* For ADDR_EXPR, we do not want to copy the decl whose address
2986 is requested. We do want to copy constants though. */
2987 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
2988 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2989 copy_constant (TREE_OPERAND (exp
, 0)));
2991 return copy_node (exp
);
2997 return copy_node (exp
);
3000 return build_complex (TREE_TYPE (exp
),
3001 copy_constant (TREE_REALPART (exp
)),
3002 copy_constant (TREE_IMAGPART (exp
)));
3005 case POINTER_PLUS_EXPR
:
3007 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
3008 copy_constant (TREE_OPERAND (exp
, 0)),
3009 copy_constant (TREE_OPERAND (exp
, 1)));
3012 case VIEW_CONVERT_EXPR
:
3013 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3014 copy_constant (TREE_OPERAND (exp
, 0)));
3017 return build_vector (TREE_TYPE (exp
),
3018 copy_list (TREE_VECTOR_CST_ELTS (exp
)));
3022 tree copy
= copy_node (exp
);
3023 VEC(constructor_elt
, gc
) *v
;
3024 unsigned HOST_WIDE_INT idx
;
3025 tree purpose
, value
;
3027 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
3028 CONSTRUCTOR_ELTS (exp
)));
3029 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
3031 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
3032 ce
->index
= purpose
;
3033 ce
->value
= copy_constant (value
);
3035 CONSTRUCTOR_ELTS (copy
) = v
;
3044 /* Return the section into which constant EXP should be placed. */
3047 get_constant_section (tree exp
, unsigned int align
)
3049 return targetm
.asm_out
.select_section (exp
,
3050 compute_reloc_for_constant (exp
),
3054 /* Return the size of constant EXP in bytes. */
3056 static HOST_WIDE_INT
3057 get_constant_size (tree exp
)
3061 size
= int_size_in_bytes (TREE_TYPE (exp
));
3062 if (TREE_CODE (exp
) == STRING_CST
)
3063 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3067 /* Subroutine of output_constant_def:
3068 No constant equal to EXP is known to have been output.
3069 Make a constant descriptor to enter EXP in the hash table.
3070 Assign the label number and construct RTL to refer to the
3071 constant's location in memory.
3072 Caller is responsible for updating the hash table. */
3074 static struct constant_descriptor_tree
*
3075 build_constant_desc (tree exp
)
3077 struct constant_descriptor_tree
*desc
;
3083 desc
= ggc_alloc_constant_descriptor_tree ();
3084 desc
->value
= copy_constant (exp
);
3086 /* Propagate marked-ness to copied constant. */
3087 if (flag_mudflap
&& mf_marked_p (exp
))
3088 mf_mark (desc
->value
);
3090 /* Create a string containing the label name, in LABEL. */
3091 labelno
= const_labelno
++;
3092 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3094 /* Construct the VAR_DECL associated with the constant. */
3095 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3097 DECL_ARTIFICIAL (decl
) = 1;
3098 DECL_IGNORED_P (decl
) = 1;
3099 TREE_READONLY (decl
) = 1;
3100 TREE_STATIC (decl
) = 1;
3101 TREE_ADDRESSABLE (decl
) = 1;
3102 /* We don't set the RTL yet as this would cause varpool to assume that the
3103 variable is referenced. Moreover, it would just be dropped in LTO mode.
3104 Instead we set the flag that will be recognized in make_decl_rtl. */
3105 DECL_IN_CONSTANT_POOL (decl
) = 1;
3106 DECL_INITIAL (decl
) = desc
->value
;
3107 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3108 architectures so use DATA_ALIGNMENT as well, except for strings. */
3109 if (TREE_CODE (exp
) == STRING_CST
)
3111 #ifdef CONSTANT_ALIGNMENT
3112 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
3116 align_variable (decl
, 0);
3118 /* Now construct the SYMBOL_REF and the MEM. */
3119 if (use_object_blocks_p ())
3121 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
3122 symbol
= create_block_symbol (ggc_strdup (label
),
3123 get_block_for_section (sect
), -1);
3126 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3127 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3128 SET_SYMBOL_REF_DECL (symbol
, decl
);
3129 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3131 rtl
= gen_const_mem (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3132 set_mem_attributes (rtl
, exp
, 1);
3133 set_mem_alias_set (rtl
, 0);
3134 set_mem_alias_set (rtl
, const_alias_set
);
3136 /* We cannot share RTX'es in pool entries.
3137 Mark this piece of RTL as required for unsharing. */
3138 RTX_FLAG (rtl
, used
) = 1;
3140 /* Set flags or add text to the name to record information, such as
3141 that it is a local symbol. If the name is changed, the macro
3142 ASM_OUTPUT_LABELREF will have to know how to strip this
3143 information. This call might invalidate our local variable
3144 SYMBOL; we can't use it afterward. */
3145 targetm
.encode_section_info (exp
, rtl
, true);
3152 /* Return an rtx representing a reference to constant data in memory
3153 for the constant expression EXP.
3155 If assembler code for such a constant has already been output,
3156 return an rtx to refer to it.
3157 Otherwise, output such a constant in memory
3158 and generate an rtx for it.
3160 If DEFER is nonzero, this constant can be deferred and output only
3161 if referenced in the function after all optimizations.
3163 `const_desc_table' records which constants already have label strings. */
3166 output_constant_def (tree exp
, int defer
)
3168 struct constant_descriptor_tree
*desc
;
3169 struct constant_descriptor_tree key
;
3172 /* Look up EXP in the table of constant descriptors. If we didn't find
3173 it, create a new one. */
3175 key
.hash
= const_hash_1 (exp
);
3176 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3178 desc
= (struct constant_descriptor_tree
*) *loc
;
3181 desc
= build_constant_desc (exp
);
3182 desc
->hash
= key
.hash
;
3186 maybe_output_constant_def_contents (desc
, defer
);
3190 /* Subroutine of output_constant_def: Decide whether or not we need to
3191 output the constant DESC now, and if so, do it. */
3193 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3196 rtx symbol
= XEXP (desc
->rtl
, 0);
3197 tree exp
= desc
->value
;
3199 if (flag_syntax_only
)
3202 if (TREE_ASM_WRITTEN (exp
))
3203 /* Already output; don't do it again. */
3206 /* We can always defer constants as long as the context allows
3210 /* Increment n_deferred_constants if it exists. It needs to be at
3211 least as large as the number of constants actually referred to
3212 by the function. If it's too small we'll stop looking too early
3213 and fail to emit constants; if it's too large we'll only look
3214 through the entire function when we could have stopped earlier. */
3216 n_deferred_constants
++;
3220 output_constant_def_contents (symbol
);
3223 /* Subroutine of output_constant_def_contents. Output the definition
3224 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3225 constant's alignment in bits. */
3228 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3232 size
= get_constant_size (exp
);
3234 /* Do any machine/system dependent processing of the constant. */
3235 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3237 /* Output the value of EXP. */
3238 output_constant (exp
, size
, align
);
3241 /* We must output the constant data referred to by SYMBOL; do so. */
3244 output_constant_def_contents (rtx symbol
)
3246 tree decl
= SYMBOL_REF_DECL (symbol
);
3247 tree exp
= DECL_INITIAL (decl
);
3250 /* Make sure any other constants whose addresses appear in EXP
3251 are assigned label numbers. */
3252 output_addressed_constants (exp
);
3254 /* We are no longer deferring this constant. */
3255 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3257 /* If the constant is part of an object block, make sure that the
3258 decl has been positioned within its block, but do not write out
3259 its definition yet. output_object_blocks will do that later. */
3260 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3261 place_block_symbol (symbol
);
3264 align
= DECL_ALIGN (decl
);
3265 switch_to_section (get_constant_section (exp
, align
));
3266 if (align
> BITS_PER_UNIT
)
3267 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3268 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3271 mudflap_enqueue_constant (exp
);
3274 /* Look up EXP in the table of constant descriptors. Return the rtl
3275 if it has been emitted, else null. */
3278 lookup_constant_def (tree exp
)
3280 struct constant_descriptor_tree
*desc
;
3281 struct constant_descriptor_tree key
;
3284 key
.hash
= const_hash_1 (exp
);
3285 desc
= (struct constant_descriptor_tree
*)
3286 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3288 return (desc
? desc
->rtl
: NULL_RTX
);
3291 /* Return a tree representing a reference to constant data in memory
3292 for the constant expression EXP.
3294 This is the counterpart of output_constant_def at the Tree level. */
3297 tree_output_constant_def (tree exp
)
3299 struct constant_descriptor_tree
*desc
, key
;
3303 /* Look up EXP in the table of constant descriptors. If we didn't find
3304 it, create a new one. */
3306 key
.hash
= const_hash_1 (exp
);
3307 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3309 desc
= (struct constant_descriptor_tree
*) *loc
;
3312 desc
= build_constant_desc (exp
);
3313 desc
->hash
= key
.hash
;
3317 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3318 varpool_finalize_decl (decl
);
3322 /* Used in the hash tables to avoid outputting the same constant
3323 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3324 are output once per function, not once per file. */
3325 /* ??? Only a few targets need per-function constant pools. Most
3326 can use one per-file pool. Should add a targetm bit to tell the
3329 struct GTY(()) rtx_constant_pool
{
3330 /* Pointers to first and last constant in pool, as ordered by offset. */
3331 struct constant_descriptor_rtx
*first
;
3332 struct constant_descriptor_rtx
*last
;
3334 /* Hash facility for making memory-constants from constant rtl-expressions.
3335 It is used on RISC machines where immediate integer arguments and
3336 constant addresses are restricted so that such constants must be stored
3338 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3340 /* Current offset in constant pool (does not include any
3341 machine-specific header). */
3342 HOST_WIDE_INT offset
;
3345 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3346 struct constant_descriptor_rtx
*next
;
3350 HOST_WIDE_INT offset
;
3352 enum machine_mode mode
;
3358 /* Hash and compare functions for const_rtx_htab. */
3361 const_desc_rtx_hash (const void *ptr
)
3363 const struct constant_descriptor_rtx
*const desc
3364 = (const struct constant_descriptor_rtx
*) ptr
;
3369 const_desc_rtx_eq (const void *a
, const void *b
)
3371 const struct constant_descriptor_rtx
*const x
3372 = (const struct constant_descriptor_rtx
*) a
;
3373 const struct constant_descriptor_rtx
*const y
3374 = (const struct constant_descriptor_rtx
*) b
;
3376 if (x
->mode
!= y
->mode
)
3378 return rtx_equal_p (x
->constant
, y
->constant
);
3381 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3384 const_rtx_hash_1 (rtx
*xp
, void *data
)
3386 unsigned HOST_WIDE_INT hwi
;
3387 enum machine_mode mode
;
3393 code
= GET_CODE (x
);
3394 mode
= GET_MODE (x
);
3395 h
= (hashval_t
) code
* 1048573 + mode
;
3403 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3404 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3407 h
^= (hashval_t
) hwi
;
3408 for (i
= 1; i
< n
; ++i
)
3411 h
^= (hashval_t
) hwi
;
3417 if (mode
== VOIDmode
)
3419 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3423 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3427 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3433 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3434 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3439 h
^= htab_hash_string (XSTR (x
, 0));
3443 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3447 case UNSPEC_VOLATILE
:
3448 h
= h
* 251 + XINT (x
, 1);
3455 hp
= (hashval_t
*) data
;
3456 *hp
= *hp
* 509 + h
;
3460 /* Compute a hash value for X, which should be a constant. */
3463 const_rtx_hash (rtx x
)
3466 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3471 /* Create and return a new rtx constant pool. */
3473 static struct rtx_constant_pool
*
3474 create_constant_pool (void)
3476 struct rtx_constant_pool
*pool
;
3478 pool
= ggc_alloc_rtx_constant_pool ();
3479 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3480 const_desc_rtx_eq
, NULL
);
3487 /* Initialize constant pool hashing for a new function. */
3490 init_varasm_status (void)
3492 crtl
->varasm
.pool
= create_constant_pool ();
3493 crtl
->varasm
.deferred_constants
= 0;
3496 /* Given a MINUS expression, simplify it if both sides
3497 include the same symbol. */
3500 simplify_subtraction (rtx x
)
3502 rtx r
= simplify_rtx (x
);
3506 /* Given a constant rtx X, make (or find) a memory constant for its value
3507 and return a MEM rtx to refer to it in memory. */
3510 force_const_mem (enum machine_mode mode
, rtx x
)
3512 struct constant_descriptor_rtx
*desc
, tmp
;
3513 struct rtx_constant_pool
*pool
;
3520 /* If we're not allowed to drop X into the constant pool, don't. */
3521 if (targetm
.cannot_force_const_mem (mode
, x
))
3524 /* Record that this function has used a constant pool entry. */
3525 crtl
->uses_const_pool
= 1;
3527 /* Decide which pool to use. */
3528 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3529 ? shared_constant_pool
3530 : crtl
->varasm
.pool
);
3532 /* Lookup the value in the hashtable. */
3535 hash
= const_rtx_hash (x
);
3536 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3537 desc
= (struct constant_descriptor_rtx
*) *slot
;
3539 /* If the constant was already present, return its memory. */
3541 return copy_rtx (desc
->mem
);
3543 /* Otherwise, create a new descriptor. */
3544 desc
= ggc_alloc_constant_descriptor_rtx ();
3547 /* Align the location counter as required by EXP's data type. */
3548 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3549 #ifdef CONSTANT_ALIGNMENT
3551 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3552 if (type
!= NULL_TREE
)
3553 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3557 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3558 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3561 desc
->constant
= copy_rtx (tmp
.constant
);
3562 desc
->offset
= pool
->offset
;
3565 desc
->align
= align
;
3566 desc
->labelno
= const_labelno
;
3569 pool
->offset
+= GET_MODE_SIZE (mode
);
3571 pool
->last
->next
= desc
;
3573 pool
->first
= pool
->last
= desc
;
3576 /* Create a string containing the label name, in LABEL. */
3577 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3580 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3581 the constants pool. */
3582 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3584 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3585 symbol
= create_block_symbol (ggc_strdup (label
),
3586 get_block_for_section (sect
), -1);
3589 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3591 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3592 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3593 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3595 /* Construct the MEM. */
3596 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3597 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3598 set_mem_align (def
, align
);
3600 /* If we're dropping a label to the constant pool, make sure we
3602 if (GET_CODE (x
) == LABEL_REF
)
3603 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3605 return copy_rtx (def
);
3608 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3611 get_pool_constant (rtx addr
)
3613 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3616 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3617 and whether it has been output or not. */
3620 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3622 struct constant_descriptor_rtx
*desc
;
3624 desc
= SYMBOL_REF_CONSTANT (addr
);
3625 *pmarked
= (desc
->mark
!= 0);
3626 return desc
->constant
;
3629 /* Similar, return the mode. */
3632 get_pool_mode (const_rtx addr
)
3634 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3637 /* Return the size of the constant pool. */
3640 get_pool_size (void)
3642 return crtl
->varasm
.pool
->offset
;
3645 /* Worker function for output_constant_pool_1. Emit assembly for X
3646 in MODE with known alignment ALIGN. */
3649 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3651 switch (GET_MODE_CLASS (mode
))
3654 case MODE_DECIMAL_FLOAT
:
3658 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3659 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3660 assemble_real (r
, mode
, align
);
3665 case MODE_PARTIAL_INT
:
3670 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3673 case MODE_VECTOR_FLOAT
:
3674 case MODE_VECTOR_INT
:
3675 case MODE_VECTOR_FRACT
:
3676 case MODE_VECTOR_UFRACT
:
3677 case MODE_VECTOR_ACCUM
:
3678 case MODE_VECTOR_UACCUM
:
3681 enum machine_mode submode
= GET_MODE_INNER (mode
);
3682 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3684 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3685 units
= CONST_VECTOR_NUNITS (x
);
3687 for (i
= 0; i
< units
; i
++)
3689 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3690 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3700 /* Worker function for output_constant_pool. Emit constant DESC,
3701 giving it ALIGN bits of alignment. */
3704 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3711 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3712 whose CODE_LABEL has been deleted. This can occur if a jump table
3713 is eliminated by optimization. If so, write a constant of zero
3714 instead. Note that this can also happen by turning the
3715 CODE_LABEL into a NOTE. */
3716 /* ??? This seems completely and utterly wrong. Certainly it's
3717 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3718 functioning even with INSN_DELETED_P and friends. */
3721 switch (GET_CODE (tmp
))
3724 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3725 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3727 tmp
= XEXP (XEXP (tmp
, 0), 0);
3731 tmp
= XEXP (tmp
, 0);
3732 gcc_assert (!INSN_DELETED_P (tmp
));
3733 gcc_assert (!NOTE_P (tmp
)
3734 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3741 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3742 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3743 align
, desc
->labelno
, done
);
3746 assemble_align (align
);
3748 /* Output the label. */
3749 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3751 /* Output the data. */
3752 output_constant_pool_2 (desc
->mode
, x
, align
);
3754 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3755 sections have proper size. */
3756 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3758 && (in_section
->common
.flags
& SECTION_MERGE
))
3759 assemble_align (align
);
3761 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3767 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3768 to as used. Emit referenced deferred strings. This function can
3769 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3772 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
3774 rtx x
= *current_rtx
;
3776 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3779 if (CONSTANT_POOL_ADDRESS_P (x
))
3781 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3782 if (desc
->mark
== 0)
3785 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
3788 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3790 tree decl
= SYMBOL_REF_DECL (x
);
3791 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
3793 n_deferred_constants
--;
3794 output_constant_def_contents (x
);
3801 /* Look through appropriate parts of INSN, marking all entries in the
3802 constant pool which are actually being used. Entries that are only
3803 referenced by other constants are also marked as used. Emit
3804 deferred strings that are used. */
3807 mark_constants (rtx insn
)
3812 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3813 insns, not any notes that may be attached. We don't want to mark
3814 a constant just because it happens to appear in a REG_EQUIV note. */
3815 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3817 rtx seq
= PATTERN (insn
);
3818 int i
, n
= XVECLEN (seq
, 0);
3819 for (i
= 0; i
< n
; ++i
)
3821 rtx subinsn
= XVECEXP (seq
, 0, i
);
3822 if (INSN_P (subinsn
))
3823 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
3827 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
3830 /* Look through the instructions for this function, and mark all the
3831 entries in POOL which are actually being used. Emit deferred constants
3832 which have indeed been used. */
3835 mark_constant_pool (void)
3839 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
3842 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3843 mark_constants (insn
);
3845 for (link
= crtl
->epilogue_delay_list
;
3847 link
= XEXP (link
, 1))
3848 mark_constants (XEXP (link
, 0));
3851 /* Write all the constants in POOL. */
3854 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
3856 struct constant_descriptor_rtx
*desc
;
3858 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3861 /* If the constant is part of an object_block, make sure that
3862 the constant has been positioned within its block, but do not
3863 write out its definition yet. output_object_blocks will do
3865 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
3866 && SYMBOL_REF_BLOCK (desc
->sym
))
3867 place_block_symbol (desc
->sym
);
3870 switch_to_section (targetm
.asm_out
.select_rtx_section
3871 (desc
->mode
, desc
->constant
, desc
->align
));
3872 output_constant_pool_1 (desc
, desc
->align
);
3877 /* Mark all constants that are used in the current function, then write
3878 out the function's private constant pool. */
3881 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3882 tree fndecl ATTRIBUTE_UNUSED
)
3884 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
3886 /* It is possible for gcc to call force_const_mem and then to later
3887 discard the instructions which refer to the constant. In such a
3888 case we do not need to output the constant. */
3889 mark_constant_pool ();
3891 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3892 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3895 output_constant_pool_contents (pool
);
3897 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3898 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3902 /* Write the contents of the shared constant pool. */
3905 output_shared_constant_pool (void)
3907 output_constant_pool_contents (shared_constant_pool
);
3910 /* Determine what kind of relocations EXP may need. */
3913 compute_reloc_for_constant (tree exp
)
3915 int reloc
= 0, reloc2
;
3918 switch (TREE_CODE (exp
))
3922 /* Go inside any operations that get_inner_reference can handle and see
3923 if what's inside is a constant: no need to do anything here for
3924 addresses of variables or functions. */
3925 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3926 tem
= TREE_OPERAND (tem
, 0))
3929 if (TREE_PUBLIC (tem
))
3936 case POINTER_PLUS_EXPR
:
3937 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3938 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3942 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3943 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3944 /* The difference of two local labels is computable at link time. */
3945 if (reloc
== 1 && reloc2
== 1)
3952 case VIEW_CONVERT_EXPR
:
3953 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3958 unsigned HOST_WIDE_INT idx
;
3959 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3961 reloc
|= compute_reloc_for_constant (tem
);
3971 /* Find all the constants whose addresses are referenced inside of EXP,
3972 and make sure assembler code with a label has been output for each one.
3973 Indicate whether an ADDR_EXPR has been encountered. */
3976 output_addressed_constants (tree exp
)
3980 switch (TREE_CODE (exp
))
3984 /* Go inside any operations that get_inner_reference can handle and see
3985 if what's inside is a constant: no need to do anything here for
3986 addresses of variables or functions. */
3987 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3988 tem
= TREE_OPERAND (tem
, 0))
3991 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3992 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
3993 tem
= DECL_INITIAL (tem
);
3995 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
3996 output_constant_def (tem
, 0);
4000 case POINTER_PLUS_EXPR
:
4002 output_addressed_constants (TREE_OPERAND (exp
, 1));
4006 case VIEW_CONVERT_EXPR
:
4007 output_addressed_constants (TREE_OPERAND (exp
, 0));
4012 unsigned HOST_WIDE_INT idx
;
4013 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4015 output_addressed_constants (tem
);
4024 /* Whether a constructor CTOR is a valid static constant initializer if all
4025 its elements are. This used to be internal to initializer_constant_valid_p
4026 and has been exposed to let other functions like categorize_ctor_elements
4027 evaluate the property while walking a constructor for other purposes. */
4030 constructor_static_from_elts_p (const_tree ctor
)
4032 return (TREE_CONSTANT (ctor
)
4033 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4034 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
4035 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
4038 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4041 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4042 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4043 which are valid when ENDTYPE is an integer of any size; in
4044 particular, this does not accept a pointer minus a constant. This
4045 returns null_pointer_node if the VALUE is an absolute constant
4046 which can be used to initialize a static variable. Otherwise it
4050 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4054 if (!INTEGRAL_TYPE_P (endtype
))
4057 op0
= TREE_OPERAND (value
, 0);
4058 op1
= TREE_OPERAND (value
, 1);
4060 /* Like STRIP_NOPS except allow the operand mode to widen. This
4061 works around a feature of fold that simplifies (int)(p1 - p2) to
4062 ((int)p1 - (int)p2) under the theory that the narrower operation
4065 while (CONVERT_EXPR_P (op0
)
4066 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4068 tree inner
= TREE_OPERAND (op0
, 0);
4069 if (inner
== error_mark_node
4070 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4071 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4072 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4077 while (CONVERT_EXPR_P (op1
)
4078 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4080 tree inner
= TREE_OPERAND (op1
, 0);
4081 if (inner
== error_mark_node
4082 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4083 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4084 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4089 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4093 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4094 cache
? cache
+ 2 : NULL
);
4095 /* Both initializers must be known. */
4099 && (op0
== null_pointer_node
4100 || TREE_CODE (value
) == MINUS_EXPR
))
4101 return null_pointer_node
;
4103 /* Support differences between labels. */
4104 if (TREE_CODE (op0
) == LABEL_DECL
4105 && TREE_CODE (op1
) == LABEL_DECL
)
4106 return null_pointer_node
;
4108 if (TREE_CODE (op0
) == STRING_CST
4109 && TREE_CODE (op1
) == STRING_CST
4110 && operand_equal_p (op0
, op1
, 1))
4111 return null_pointer_node
;
4117 /* Helper function of initializer_constant_valid_p.
4118 Return nonzero if VALUE is a valid constant-valued expression
4119 for use in initializing a static variable; one that can be an
4120 element of a "constant" initializer.
4122 Return null_pointer_node if the value is absolute;
4123 if it is relocatable, return the variable that determines the relocation.
4124 We assume that VALUE has been folded as much as possible;
4125 therefore, we do not need to check for such things as
4126 arithmetic-combinations of integers.
4128 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4131 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4135 switch (TREE_CODE (value
))
4138 if (constructor_static_from_elts_p (value
))
4140 unsigned HOST_WIDE_INT idx
;
4142 bool absolute
= true;
4144 if (cache
&& cache
[0] == value
)
4146 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4149 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4156 cache
[1] = NULL_TREE
;
4160 if (reloc
!= null_pointer_node
)
4163 /* For a non-absolute relocation, there is no single
4164 variable that can be "the variable that determines the
4169 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4171 return absolute
? null_pointer_node
: error_mark_node
;
4174 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4182 return null_pointer_node
;
4187 tree op0
= staticp (TREE_OPERAND (value
, 0));
4190 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4191 to be a constant, this is old-skool offsetof-like nonsense. */
4192 if (TREE_CODE (op0
) == INDIRECT_REF
4193 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4194 return null_pointer_node
;
4195 /* Taking the address of a nested function involves a trampoline,
4196 unless we don't need or want one. */
4197 if (TREE_CODE (op0
) == FUNCTION_DECL
4198 && DECL_STATIC_CHAIN (op0
)
4199 && !TREE_NO_TRAMPOLINE (value
))
4201 /* "&{...}" requires a temporary to hold the constructed
4203 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4209 case NON_LVALUE_EXPR
:
4210 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4213 case VIEW_CONVERT_EXPR
:
4215 tree src
= TREE_OPERAND (value
, 0);
4216 tree src_type
= TREE_TYPE (src
);
4217 tree dest_type
= TREE_TYPE (value
);
4219 /* Allow view-conversions from aggregate to non-aggregate type only
4220 if the bit pattern is fully preserved afterwards; otherwise, the
4221 RTL expander won't be able to apply a subsequent transformation
4222 to the underlying constructor. */
4223 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4225 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4226 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4231 /* Allow all other kinds of view-conversion. */
4232 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4237 tree src
= TREE_OPERAND (value
, 0);
4238 tree src_type
= TREE_TYPE (src
);
4239 tree dest_type
= TREE_TYPE (value
);
4241 /* Allow conversions between pointer types, floating-point
4242 types, and offset types. */
4243 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4244 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4245 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4246 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4247 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4249 /* Allow length-preserving conversions between integer types. */
4250 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4251 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4252 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4254 /* Allow conversions between other integer types only if
4256 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4258 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4259 if (inner
== null_pointer_node
)
4260 return null_pointer_node
;
4264 /* Allow (int) &foo provided int is as wide as a pointer. */
4265 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4266 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4267 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4269 /* Likewise conversions from int to pointers, but also allow
4270 conversions from 0. */
4271 if ((POINTER_TYPE_P (dest_type
)
4272 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4273 && INTEGRAL_TYPE_P (src_type
))
4275 if (TREE_CODE (src
) == INTEGER_CST
4276 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4277 return null_pointer_node
;
4278 if (integer_zerop (src
))
4279 return null_pointer_node
;
4280 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4281 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4284 /* Allow conversions to struct or union types if the value
4286 if (TREE_CODE (dest_type
) == RECORD_TYPE
4287 || TREE_CODE (dest_type
) == UNION_TYPE
)
4288 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4292 case POINTER_PLUS_EXPR
:
4294 /* Any valid floating-point constants will have been folded by now;
4295 with -frounding-math we hit this with addition of two constants. */
4296 if (TREE_CODE (endtype
) == REAL_TYPE
)
4298 if (cache
&& cache
[0] == value
)
4300 if (! INTEGRAL_TYPE_P (endtype
)
4301 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4303 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4305 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4308 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4309 endtype
, ncache
+ 2);
4310 /* If either term is absolute, use the other term's relocation. */
4311 if (valid0
== null_pointer_node
)
4313 else if (valid1
== null_pointer_node
)
4315 /* Support narrowing pointer differences. */
4317 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4321 /* Support narrowing pointer differences. */
4322 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4331 if (TREE_CODE (endtype
) == REAL_TYPE
)
4333 if (cache
&& cache
[0] == value
)
4335 if (! INTEGRAL_TYPE_P (endtype
)
4336 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4338 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4340 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4343 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4344 endtype
, ncache
+ 2);
4345 /* Win if second argument is absolute. */
4346 if (valid1
== null_pointer_node
)
4348 /* Win if both arguments have the same relocation.
4349 Then the value is absolute. */
4350 else if (valid0
== valid1
&& valid0
!= 0)
4351 ret
= null_pointer_node
;
4352 /* Since GCC guarantees that string constants are unique in the
4353 generated code, a subtraction between two copies of the same
4354 constant string is absolute. */
4355 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4356 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4357 && operand_equal_p (valid0
, valid1
, 1))
4358 ret
= null_pointer_node
;
4359 /* Support narrowing differences. */
4361 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4365 /* Support narrowing differences. */
4366 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4381 /* Return nonzero if VALUE is a valid constant-valued expression
4382 for use in initializing a static variable; one that can be an
4383 element of a "constant" initializer.
4385 Return null_pointer_node if the value is absolute;
4386 if it is relocatable, return the variable that determines the relocation.
4387 We assume that VALUE has been folded as much as possible;
4388 therefore, we do not need to check for such things as
4389 arithmetic-combinations of integers. */
4391 initializer_constant_valid_p (tree value
, tree endtype
)
4393 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4396 /* Return true if VALUE is a valid constant-valued expression
4397 for use in initializing a static bit-field; one that can be
4398 an element of a "constant" initializer. */
4401 initializer_constant_valid_for_bitfield_p (tree value
)
4403 /* For bitfields we support integer constants or possibly nested aggregates
4405 switch (TREE_CODE (value
))
4409 unsigned HOST_WIDE_INT idx
;
4412 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4413 if (!initializer_constant_valid_for_bitfield_p (elt
))
4421 case VIEW_CONVERT_EXPR
:
4422 case NON_LVALUE_EXPR
:
4424 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4433 /* output_constructor outer state of relevance in recursive calls, typically
4434 for nested aggregate bitfields. */
4437 unsigned int bit_offset
; /* current position in ... */
4438 int byte
; /* ... the outer byte buffer. */
4441 static unsigned HOST_WIDE_INT
4442 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4445 /* Output assembler code for constant EXP to FILE, with no label.
4446 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4447 Assumes output_addressed_constants has been done on EXP already.
4449 Generate exactly SIZE bytes of assembler data, padding at the end
4450 with zeros if necessary. SIZE must always be specified.
4452 SIZE is important for structure constructors,
4453 since trailing members may have been omitted from the constructor.
4454 It is also important for initialization of arrays from string constants
4455 since the full length of the string constant might not be wanted.
4456 It is also needed for initialization of unions, where the initializer's
4457 type is just one member, and that may not be as long as the union.
4459 There a case in which we would fail to output exactly SIZE bytes:
4460 for a structure constructor that wants to produce more than SIZE bytes.
4461 But such constructors will never be generated for any possible input.
4463 ALIGN is the alignment of the data in bits. */
4466 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4468 enum tree_code code
;
4469 unsigned HOST_WIDE_INT thissize
;
4471 if (size
== 0 || flag_syntax_only
)
4474 /* See if we're trying to initialize a pointer in a non-default mode
4475 to the address of some declaration somewhere. If the target says
4476 the mode is valid for pointers, assume the target has a way of
4478 if (TREE_CODE (exp
) == NOP_EXPR
4479 && POINTER_TYPE_P (TREE_TYPE (exp
))
4480 && targetm
.addr_space
.valid_pointer_mode
4481 (TYPE_MODE (TREE_TYPE (exp
)),
4482 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4484 tree saved_type
= TREE_TYPE (exp
);
4486 /* Peel off any intermediate conversions-to-pointer for valid
4488 while (TREE_CODE (exp
) == NOP_EXPR
4489 && POINTER_TYPE_P (TREE_TYPE (exp
))
4490 && targetm
.addr_space
.valid_pointer_mode
4491 (TYPE_MODE (TREE_TYPE (exp
)),
4492 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4493 exp
= TREE_OPERAND (exp
, 0);
4495 /* If what we're left with is the address of something, we can
4496 convert the address to the final type and output it that
4498 if (TREE_CODE (exp
) == ADDR_EXPR
)
4499 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4500 /* Likewise for constant ints. */
4501 else if (TREE_CODE (exp
) == INTEGER_CST
)
4502 exp
= build_int_cst_wide (saved_type
, TREE_INT_CST_LOW (exp
),
4503 TREE_INT_CST_HIGH (exp
));
4507 /* Eliminate any conversions since we'll be outputting the underlying
4509 while (CONVERT_EXPR_P (exp
)
4510 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4511 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4513 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4514 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4516 /* Make sure eliminating the conversion is really a no-op, except with
4517 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4518 union types to allow for Ada unchecked unions. */
4519 if (type_size
> op_size
4520 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4521 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4522 /* Keep the conversion. */
4525 exp
= TREE_OPERAND (exp
, 0);
4528 code
= TREE_CODE (TREE_TYPE (exp
));
4529 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4531 /* Allow a constructor with no elements for any data type.
4532 This means to fill the space with zeros. */
4533 if (TREE_CODE (exp
) == CONSTRUCTOR
4534 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
4536 assemble_zeros (size
);
4540 if (TREE_CODE (exp
) == FDESC_EXPR
)
4542 #ifdef ASM_OUTPUT_FDESC
4543 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4544 tree decl
= TREE_OPERAND (exp
, 0);
4545 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4552 /* Now output the underlying data. If we've handling the padding, return.
4553 Otherwise, break and ensure SIZE is the size written. */
4560 case REFERENCE_TYPE
:
4562 case FIXED_POINT_TYPE
:
4563 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4564 EXPAND_INITIALIZER
),
4565 MIN (size
, thissize
), align
, 0))
4566 error ("initializer for integer/fixed-point value is too complicated");
4570 if (TREE_CODE (exp
) != REAL_CST
)
4571 error ("initializer for floating value is not a floating constant");
4573 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4577 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4578 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4579 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4584 switch (TREE_CODE (exp
))
4587 output_constructor (exp
, size
, align
, NULL
);
4590 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
4592 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4599 unsigned int nalign
;
4600 enum machine_mode inner
;
4602 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4603 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4605 elt_size
= GET_MODE_SIZE (inner
);
4607 link
= TREE_VECTOR_CST_ELTS (exp
);
4608 output_constant (TREE_VALUE (link
), elt_size
, align
);
4609 thissize
= elt_size
;
4610 while ((link
= TREE_CHAIN (link
)) != NULL
)
4612 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
4613 thissize
+= elt_size
;
4624 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4625 output_constructor (exp
, size
, align
, NULL
);
4635 if (size
> thissize
)
4636 assemble_zeros (size
- thissize
);
4640 /* Subroutine of output_constructor, used for computing the size of
4641 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4642 type with an unspecified upper bound. */
4644 static unsigned HOST_WIDE_INT
4645 array_size_for_constructor (tree val
)
4648 unsigned HOST_WIDE_INT cnt
;
4649 tree index
, value
, tmp
;
4652 /* This code used to attempt to handle string constants that are not
4653 arrays of single-bytes, but nothing else does, so there's no point in
4655 if (TREE_CODE (val
) == STRING_CST
)
4656 return TREE_STRING_LENGTH (val
);
4658 max_index
= NULL_TREE
;
4659 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4661 if (TREE_CODE (index
) == RANGE_EXPR
)
4662 index
= TREE_OPERAND (index
, 1);
4663 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4667 if (max_index
== NULL_TREE
)
4670 /* Compute the total number of array elements. */
4671 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4672 i
= double_int_sub (tree_to_double_int (max_index
), tree_to_double_int (tmp
));
4673 i
= double_int_add (i
, double_int_one
);
4675 /* Multiply by the array element unit size to find number of bytes. */
4676 i
= double_int_mul (i
, tree_to_double_int
4677 (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
)))));
4679 gcc_assert (double_int_fits_in_uhwi_p (i
));
4683 /* Other datastructures + helpers for output_constructor. */
4685 /* output_constructor local state to support interaction with helpers. */
4689 /* Received arguments. */
4690 tree exp
; /* Constructor expression. */
4691 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4692 unsigned int align
; /* Known initial alignment. */
4694 /* Constructor expression data. */
4695 tree type
; /* Expression type. */
4696 tree field
; /* Current field decl in a record. */
4697 tree min_index
; /* Lower bound if specified for an array. */
4699 /* Output processing state. */
4700 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4701 bool byte_buffer_in_use
; /* Whether byte ... */
4702 int byte
; /* ... contains part of a bitfield byte yet to
4705 int last_relative_index
; /* Implicit or explicit index of the last
4706 array element output within a bitfield. */
4707 /* Current element. */
4708 tree val
; /* Current element value. */
4709 tree index
; /* Current element index. */
4713 /* Helper for output_constructor. From the current LOCAL state, output a
4714 RANGE_EXPR element. */
4717 output_constructor_array_range (oc_local_state
*local
)
4719 unsigned HOST_WIDE_INT fieldsize
4720 = int_size_in_bytes (TREE_TYPE (local
->type
));
4722 HOST_WIDE_INT lo_index
4723 = tree_low_cst (TREE_OPERAND (local
->index
, 0), 0);
4724 HOST_WIDE_INT hi_index
4725 = tree_low_cst (TREE_OPERAND (local
->index
, 1), 0);
4726 HOST_WIDE_INT index
;
4729 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4731 for (index
= lo_index
; index
<= hi_index
; index
++)
4733 /* Output the element's initial value. */
4734 if (local
->val
== NULL_TREE
)
4735 assemble_zeros (fieldsize
);
4737 output_constant (local
->val
, fieldsize
, align2
);
4739 /* Count its size. */
4740 local
->total_bytes
+= fieldsize
;
4744 /* Helper for output_constructor. From the current LOCAL state, output a
4745 field element that is not true bitfield or part of an outer one. */
4748 output_constructor_regular_field (oc_local_state
*local
)
4750 /* Field size and position. Since this structure is static, we know the
4751 positions are constant. */
4752 unsigned HOST_WIDE_INT fieldsize
;
4753 HOST_WIDE_INT fieldpos
;
4755 unsigned int align2
;
4757 if (local
->index
!= NULL_TREE
)
4759 double_int idx
= double_int_sub (tree_to_double_int (local
->index
),
4760 tree_to_double_int (local
->min_index
));
4761 gcc_assert (double_int_fits_in_shwi_p (idx
));
4762 fieldpos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
)), 1)
4765 else if (local
->field
!= NULL_TREE
)
4766 fieldpos
= int_byte_position (local
->field
);
4770 /* Output any buffered-up bit-fields preceding this element. */
4771 if (local
->byte_buffer_in_use
)
4773 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4774 local
->total_bytes
++;
4775 local
->byte_buffer_in_use
= false;
4778 /* Advance to offset of this element.
4779 Note no alignment needed in an array, since that is guaranteed
4780 if each element has the proper size. */
4781 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4782 && fieldpos
!= local
->total_bytes
)
4784 gcc_assert (fieldpos
>= local
->total_bytes
);
4785 assemble_zeros (fieldpos
- local
->total_bytes
);
4786 local
->total_bytes
= fieldpos
;
4789 /* Find the alignment of this element. */
4790 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
4792 /* Determine size this element should occupy. */
4797 /* If this is an array with an unspecified upper bound,
4798 the initializer determines the size. */
4799 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4800 but we cannot do this until the deprecated support for
4801 initializing zero-length array members is removed. */
4802 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
4803 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
4804 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
4806 fieldsize
= array_size_for_constructor (local
->val
);
4807 /* Given a non-empty initialization, this field had
4809 gcc_assert (!fieldsize
|| !DECL_CHAIN (local
->field
));
4812 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (local
->field
), 1);
4815 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
4817 /* Output the element's initial value. */
4818 if (local
->val
== NULL_TREE
)
4819 assemble_zeros (fieldsize
);
4821 output_constant (local
->val
, fieldsize
, align2
);
4823 /* Count its size. */
4824 local
->total_bytes
+= fieldsize
;
4827 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4828 output an element that is a true bitfield or part of an outer one. */
4831 output_constructor_bitfield (oc_local_state
*local
, oc_outer_state
*outer
)
4833 /* Bit size of this element. */
4834 HOST_WIDE_INT ebitsize
4836 ? tree_low_cst (DECL_SIZE (local
->field
), 1)
4837 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local
->type
)), 1));
4839 /* Relative index of this element if this is an array component. */
4840 HOST_WIDE_INT relative_index
4843 ? (tree_low_cst (local
->index
, 0)
4844 - tree_low_cst (local
->min_index
, 0))
4845 : local
->last_relative_index
+ 1)
4848 /* Bit position of this element from the start of the containing
4850 HOST_WIDE_INT constructor_relative_ebitpos
4852 ? int_bit_position (local
->field
)
4853 : ebitsize
* relative_index
);
4855 /* Bit position of this element from the start of a possibly ongoing
4856 outer byte buffer. */
4857 HOST_WIDE_INT byte_relative_ebitpos
4858 = ((outer
? outer
->bit_offset
: 0) + constructor_relative_ebitpos
);
4860 /* From the start of a possibly ongoing outer byte buffer, offsets to
4861 the first bit of this element and to the first bit past the end of
4863 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
4864 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
4866 local
->last_relative_index
= relative_index
;
4868 if (local
->val
== NULL_TREE
)
4869 local
->val
= integer_zero_node
;
4871 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
4872 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
4873 local
->val
= TREE_OPERAND (local
->val
, 0);
4875 if (TREE_CODE (local
->val
) != INTEGER_CST
4876 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
4878 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
4882 /* If this field does not start in this (or, next) byte,
4884 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4886 /* Output remnant of any bit field in previous bytes. */
4887 if (local
->byte_buffer_in_use
)
4889 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4890 local
->total_bytes
++;
4891 local
->byte_buffer_in_use
= false;
4894 /* If still not at proper byte, advance to there. */
4895 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4897 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
4898 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
4899 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
4903 /* Set up the buffer if necessary. */
4904 if (!local
->byte_buffer_in_use
)
4908 local
->byte_buffer_in_use
= true;
4911 /* If this is nested constructor, recurse passing the bit offset and the
4912 pending data, then retrieve the new pending data afterwards. */
4913 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
4915 oc_outer_state output_state
;
4917 output_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
4918 output_state
.byte
= local
->byte
;
4920 += output_constructor (local
->val
, 0, 0, &output_state
);
4921 local
->byte
= output_state
.byte
;
4925 /* Otherwise, we must split the element into pieces that fall within
4926 separate bytes, and combine each byte with previous or following
4928 while (next_offset
< end_offset
)
4932 HOST_WIDE_INT value
;
4933 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4934 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4936 /* Advance from byte to byte
4937 within this element when necessary. */
4938 while (next_byte
!= local
->total_bytes
)
4940 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4941 local
->total_bytes
++;
4945 /* Number of bits we can process at once
4946 (all part of the same byte). */
4947 this_time
= MIN (end_offset
- next_offset
,
4948 BITS_PER_UNIT
- next_bit
);
4949 if (BYTES_BIG_ENDIAN
)
4951 /* On big-endian machine, take the most significant bits
4952 first (of the bits that are significant)
4953 and put them into bytes from the most significant end. */
4954 shift
= end_offset
- next_offset
- this_time
;
4956 /* Don't try to take a bunch of bits that cross
4957 the word boundary in the INTEGER_CST. We can
4958 only select bits from the LOW or HIGH part
4960 if (shift
< HOST_BITS_PER_WIDE_INT
4961 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4963 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4964 shift
= HOST_BITS_PER_WIDE_INT
;
4967 /* Now get the bits from the appropriate constant word. */
4968 if (shift
< HOST_BITS_PER_WIDE_INT
)
4969 value
= TREE_INT_CST_LOW (local
->val
);
4972 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4973 value
= TREE_INT_CST_HIGH (local
->val
);
4974 shift
-= HOST_BITS_PER_WIDE_INT
;
4977 /* Get the result. This works only when:
4978 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4979 local
->byte
|= (((value
>> shift
)
4980 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4981 << (BITS_PER_UNIT
- this_time
- next_bit
));
4985 /* On little-endian machines,
4986 take first the least significant bits of the value
4987 and pack them starting at the least significant
4988 bits of the bytes. */
4989 shift
= next_offset
- byte_relative_ebitpos
;
4991 /* Don't try to take a bunch of bits that cross
4992 the word boundary in the INTEGER_CST. We can
4993 only select bits from the LOW or HIGH part
4995 if (shift
< HOST_BITS_PER_WIDE_INT
4996 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4997 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4999 /* Now get the bits from the appropriate constant word. */
5000 if (shift
< HOST_BITS_PER_WIDE_INT
)
5001 value
= TREE_INT_CST_LOW (local
->val
);
5004 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
5005 value
= TREE_INT_CST_HIGH (local
->val
);
5006 shift
-= HOST_BITS_PER_WIDE_INT
;
5009 /* Get the result. This works only when:
5010 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5011 local
->byte
|= (((value
>> shift
)
5012 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5016 next_offset
+= this_time
;
5017 local
->byte_buffer_in_use
= true;
5021 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5022 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5023 caller output state of relevance in recursive invocations. */
5025 static unsigned HOST_WIDE_INT
5026 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5027 unsigned int align
, oc_outer_state
* outer
)
5029 unsigned HOST_WIDE_INT cnt
;
5030 constructor_elt
*ce
;
5032 oc_local_state local
;
5034 /* Setup our local state to communicate with helpers. */
5037 local
.align
= align
;
5039 local
.total_bytes
= 0;
5040 local
.byte_buffer_in_use
= outer
!= NULL
;
5041 local
.byte
= outer
? outer
->byte
: 0;
5043 local
.type
= TREE_TYPE (exp
);
5045 local
.last_relative_index
= -1;
5047 local
.min_index
= NULL_TREE
;
5048 if (TREE_CODE (local
.type
) == ARRAY_TYPE
5049 && TYPE_DOMAIN (local
.type
) != NULL_TREE
)
5050 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5052 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5054 /* As CE goes through the elements of the constant, FIELD goes through the
5055 structure fields if the constant is a structure. If the constant is a
5056 union, we override this by getting the field from the TREE_LIST element.
5057 But the constant could also be an array. Then FIELD is zero.
5059 There is always a maximum of one element in the chain LINK for unions
5060 (even if the initializer in a source program incorrectly contains
5063 local
.field
= NULL_TREE
;
5064 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5065 local
.field
= TYPE_FIELDS (local
.type
);
5068 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
5069 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
5071 local
.val
= ce
->value
;
5072 local
.index
= NULL_TREE
;
5074 /* The element in a union constructor specifies the proper field
5076 if ((TREE_CODE (local
.type
) == RECORD_TYPE
5077 || TREE_CODE (local
.type
) == UNION_TYPE
5078 || TREE_CODE (local
.type
) == QUAL_UNION_TYPE
)
5079 && ce
->index
!= NULL_TREE
)
5080 local
.field
= ce
->index
;
5082 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5083 local
.index
= ce
->index
;
5085 if (local
.field
&& flag_verbose_asm
)
5086 fprintf (asm_out_file
, "%s %s:\n",
5088 DECL_NAME (local
.field
)
5089 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5092 /* Eliminate the marker that makes a cast not be an lvalue. */
5093 if (local
.val
!= NULL_TREE
)
5094 STRIP_NOPS (local
.val
);
5096 /* Output the current element, using the appropriate helper ... */
5098 /* For an array slice not part of an outer bitfield. */
5100 && local
.index
!= NULL_TREE
5101 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5102 output_constructor_array_range (&local
);
5104 /* For a field that is neither a true bitfield nor part of an outer one,
5105 known to be at least byte aligned and multiple-of-bytes long. */
5107 && (local
.field
== NULL_TREE
5108 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5109 output_constructor_regular_field (&local
);
5111 /* For a true bitfield or part of an outer one. */
5113 output_constructor_bitfield (&local
, outer
);
5116 /* If we are not at toplevel, save the pending data for our caller.
5117 Otherwise output the pending data and padding zeros as needed. */
5119 outer
->byte
= local
.byte
;
5122 if (local
.byte_buffer_in_use
)
5124 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5125 local
.total_bytes
++;
5128 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5130 assemble_zeros (local
.size
- local
.total_bytes
);
5131 local
.total_bytes
= local
.size
;
5135 return local
.total_bytes
;
5138 /* Mark DECL as weak. */
5141 mark_weak (tree decl
)
5143 DECL_WEAK (decl
) = 1;
5145 if (DECL_RTL_SET_P (decl
)
5146 && MEM_P (DECL_RTL (decl
))
5147 && XEXP (DECL_RTL (decl
), 0)
5148 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5149 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5152 /* Merge weak status between NEWDECL and OLDDECL. */
5155 merge_weak (tree newdecl
, tree olddecl
)
5157 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5159 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5162 /* We put the NEWDECL on the weak_decls list at some point
5163 and OLDDECL as well. Keep just OLDDECL on the list. */
5164 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5165 if (TREE_VALUE (*pwd
) == newdecl
)
5167 *pwd
= TREE_CHAIN (*pwd
);
5174 if (DECL_WEAK (newdecl
))
5178 /* NEWDECL is weak, but OLDDECL is not. */
5180 /* If we already output the OLDDECL, we're in trouble; we can't
5181 go back and make it weak. This should never happen in
5182 unit-at-a-time compilation. */
5183 gcc_assert (!TREE_ASM_WRITTEN (olddecl
));
5185 /* If we've already generated rtl referencing OLDDECL, we may
5186 have done so in a way that will not function properly with
5187 a weak symbol. Again in unit-at-a-time this should be
5189 gcc_assert (!TREE_USED (olddecl
)
5190 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)));
5192 if (TARGET_SUPPORTS_WEAK
)
5194 /* We put the NEWDECL on the weak_decls list at some point.
5195 Replace it with the OLDDECL. */
5196 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5197 if (TREE_VALUE (wd
) == newdecl
)
5199 TREE_VALUE (wd
) = olddecl
;
5202 /* We may not find the entry on the list. If NEWDECL is a
5203 weak alias, then we will have already called
5204 globalize_decl to remove the entry; in that case, we do
5205 not need to do anything. */
5208 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5209 mark_weak (olddecl
);
5212 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5213 weak. Just update NEWDECL to indicate that it's weak too. */
5214 mark_weak (newdecl
);
5217 /* Declare DECL to be a weak symbol. */
5220 declare_weak (tree decl
)
5222 gcc_assert (TREE_CODE (decl
) != FUNCTION_DECL
|| !TREE_ASM_WRITTEN (decl
));
5223 if (! TREE_PUBLIC (decl
))
5224 error ("weak declaration of %q+D must be public", decl
);
5225 else if (!TARGET_SUPPORTS_WEAK
)
5226 warning (0, "weak declaration of %q+D not supported", decl
);
5229 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5230 DECL_ATTRIBUTES (decl
)
5231 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5235 weak_finish_1 (tree decl
)
5237 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5238 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5241 if (! TREE_USED (decl
))
5244 #ifdef ASM_WEAKEN_DECL
5245 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5247 #ifdef ASM_WEAKEN_LABEL
5248 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5250 #ifdef ASM_OUTPUT_WEAK_ALIAS
5252 static bool warn_once
= 0;
5255 warning (0, "only weak aliases are supported in this configuration");
5265 /* This TREE_LIST contains weakref targets. */
5267 static GTY(()) tree weakref_targets
;
5269 /* Forward declaration. */
5270 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
5272 /* Emit any pending weak declarations. */
5279 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5281 tree alias_decl
= TREE_PURPOSE (t
);
5282 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5284 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5285 /* Remove alias_decl from the weak list, but leave entries for
5286 the target alone. */
5288 #ifndef ASM_OUTPUT_WEAKREF
5289 else if (! TREE_SYMBOL_REFERENCED (target
))
5291 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5292 defined, otherwise we and weak_finish_1 would use
5293 different macros. */
5294 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5295 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5297 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
5301 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5302 TREE_CODE (alias_decl
), target
,
5303 TREE_TYPE (alias_decl
));
5305 DECL_EXTERNAL (decl
) = 1;
5306 TREE_PUBLIC (decl
) = 1;
5307 DECL_ARTIFICIAL (decl
) = 1;
5308 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5309 TREE_USED (decl
) = 1;
5312 weak_finish_1 (decl
);
5321 /* Remove the alias and the target from the pending weak list
5322 so that we do not emit any .weak directives for the former,
5323 nor multiple .weak directives for the latter. */
5324 for (p
= &weak_decls
; (t2
= *p
) ; )
5326 if (TREE_VALUE (t2
) == alias_decl
5327 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5328 *p
= TREE_CHAIN (t2
);
5330 p
= &TREE_CHAIN (t2
);
5333 /* Remove other weakrefs to the same target, to speed things up. */
5334 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5336 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5337 *p
= TREE_CHAIN (t2
);
5339 p
= &TREE_CHAIN (t2
);
5344 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5346 tree decl
= TREE_VALUE (t
);
5348 weak_finish_1 (decl
);
5352 /* Emit the assembly bits to indicate that DECL is globally visible. */
5355 globalize_decl (tree decl
)
5358 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5359 if (DECL_WEAK (decl
))
5361 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5364 #ifdef ASM_WEAKEN_DECL
5365 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5367 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5370 /* Remove this function from the pending weak list so that
5371 we do not emit multiple .weak directives for it. */
5372 for (p
= &weak_decls
; (t
= *p
) ; )
5374 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5375 *p
= TREE_CHAIN (t
);
5377 p
= &TREE_CHAIN (t
);
5380 /* Remove weakrefs to the same target from the pending weakref
5381 list, for the same reason. */
5382 for (p
= &weakref_targets
; (t
= *p
) ; )
5384 if (DECL_ASSEMBLER_NAME (decl
)
5385 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5386 *p
= TREE_CHAIN (t
);
5388 p
= &TREE_CHAIN (t
);
5395 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5398 VEC(alias_pair
,gc
) *alias_pairs
;
5400 /* Given an assembly name, find the decl it is associated with. At the
5401 same time, mark it needed for cgraph. */
5404 find_decl_and_mark_needed (tree decl
, tree target
)
5406 struct cgraph_node
*fnode
= NULL
;
5407 struct varpool_node
*vnode
= NULL
;
5409 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5411 fnode
= cgraph_node_for_asm (target
);
5413 vnode
= varpool_node_for_asm (target
);
5417 vnode
= varpool_node_for_asm (target
);
5419 fnode
= cgraph_node_for_asm (target
);
5424 cgraph_mark_needed_node (fnode
);
5429 varpool_mark_needed_node (vnode
);
5430 vnode
->force_output
= 1;
5437 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5438 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5439 tree node is DECL to have the value of the tree node TARGET. */
5442 do_assemble_alias (tree decl
, tree target
)
5444 /* Emulated TLS had better not get this var. */
5445 gcc_assert(!(!targetm
.have_tls
5446 && TREE_CODE (decl
) == VAR_DECL
5447 && DECL_THREAD_LOCAL_P (decl
)));
5449 if (TREE_ASM_WRITTEN (decl
))
5452 /* We must force creation of DECL_RTL for debug info generation, even though
5453 we don't use it here. */
5454 make_decl_rtl (decl
);
5456 TREE_ASM_WRITTEN (decl
) = 1;
5457 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5459 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5461 ultimate_transparent_alias_target (&target
);
5463 if (!TREE_SYMBOL_REFERENCED (target
))
5464 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5466 #ifdef ASM_OUTPUT_WEAKREF
5467 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5468 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5469 IDENTIFIER_POINTER (target
));
5471 if (!TARGET_SUPPORTS_WEAK
)
5473 error_at (DECL_SOURCE_LOCATION (decl
),
5474 "weakref is not supported in this configuration");
5481 #ifdef ASM_OUTPUT_DEF
5482 /* Make name accessible from other files, if appropriate. */
5484 if (TREE_PUBLIC (decl
))
5486 globalize_decl (decl
);
5487 maybe_assemble_visibility (decl
);
5489 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5491 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
5492 ASM_OUTPUT_TYPE_DIRECTIVE
5493 (asm_out_file
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5496 error_at (DECL_SOURCE_LOCATION (decl
),
5497 "ifunc is not supported in this configuration");
5501 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5502 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5504 ASM_OUTPUT_DEF (asm_out_file
,
5505 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5506 IDENTIFIER_POINTER (target
));
5508 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5513 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5514 # ifdef ASM_WEAKEN_DECL
5515 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5517 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5519 /* Remove this function from the pending weak list so that
5520 we do not emit multiple .weak directives for it. */
5521 for (p
= &weak_decls
; (t
= *p
) ; )
5522 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5523 *p
= TREE_CHAIN (t
);
5525 p
= &TREE_CHAIN (t
);
5527 /* Remove weakrefs to the same target from the pending weakref
5528 list, for the same reason. */
5529 for (p
= &weakref_targets
; (t
= *p
) ; )
5531 if (DECL_ASSEMBLER_NAME (decl
)
5532 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5533 *p
= TREE_CHAIN (t
);
5535 p
= &TREE_CHAIN (t
);
5542 /* Allocate and construct a symbol alias set. */
5544 static symbol_alias_set_t
*
5545 symbol_alias_set_create (void)
5547 return pointer_set_create ();
5550 /* Destruct and free a symbol alias set. */
5553 symbol_alias_set_destroy (symbol_alias_set_t
*aset
)
5555 pointer_set_destroy (aset
);
5558 /* Test if a symbol alias set contains a given name. */
5561 symbol_alias_set_contains (const symbol_alias_set_t
*aset
, tree t
)
5563 /* We accept either a DECL or an IDENTIFIER directly. */
5564 if (TREE_CODE (t
) != IDENTIFIER_NODE
)
5565 t
= DECL_ASSEMBLER_NAME (t
);
5566 t
= targetm
.asm_out
.mangle_assembler_name (IDENTIFIER_POINTER (t
));
5567 return pointer_set_contains (aset
, t
);
5570 /* Enter a new name into a symbol alias set. */
5573 symbol_alias_set_insert (symbol_alias_set_t
*aset
, tree t
)
5575 /* We accept either a DECL or an IDENTIFIER directly. */
5576 if (TREE_CODE (t
) != IDENTIFIER_NODE
)
5577 t
= DECL_ASSEMBLER_NAME (t
);
5578 t
= targetm
.asm_out
.mangle_assembler_name (IDENTIFIER_POINTER (t
));
5579 return pointer_set_insert (aset
, t
);
5582 /* IN_SET_P is a predicate function assuming to be taken
5583 alias_pair->decl, alias_pair->target and DATA arguments.
5585 Compute set of aliases by including everything where TRIVIALLY_VISIBLE
5586 predeicate is true and propagate across aliases such that when
5587 alias DECL is included, its TARGET is included too. */
5589 static symbol_alias_set_t
*
5590 propagate_aliases_forward (bool (*in_set_p
)
5591 (tree decl
, tree target
, void *data
),
5594 symbol_alias_set_t
*set
;
5599 set
= symbol_alias_set_create ();
5600 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); ++i
)
5601 if (in_set_p (p
->decl
, p
->target
, data
))
5602 symbol_alias_set_insert (set
, p
->decl
);
5606 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); ++i
)
5607 if (symbol_alias_set_contains (set
, p
->decl
)
5608 && !symbol_alias_set_insert (set
, p
->target
))
5616 /* Like propagate_aliases_forward but do backward propagation. */
5618 symbol_alias_set_t
*
5619 propagate_aliases_backward (bool (*in_set_p
)
5620 (tree decl
, tree target
, void *data
),
5623 symbol_alias_set_t
*set
;
5628 /* We have to compute the set of set nodes including aliases
5630 set
= symbol_alias_set_create ();
5631 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); ++i
)
5632 if (in_set_p (p
->decl
, p
->target
, data
))
5633 symbol_alias_set_insert (set
, p
->target
);
5637 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); ++i
)
5638 if (symbol_alias_set_contains (set
, p
->target
)
5639 && !symbol_alias_set_insert (set
, p
->decl
))
5646 /* See if the alias is trivially visible. This means
5647 1) alias is expoerted from the unit or
5648 2) alias is used in the code.
5649 We assume that unused cgraph/varpool nodes has been
5651 Used as callback for propagate_aliases. */
5654 trivially_visible_alias (tree decl
, tree target ATTRIBUTE_UNUSED
,
5655 void *data ATTRIBUTE_UNUSED
)
5657 struct cgraph_node
*fnode
= NULL
;
5658 struct varpool_node
*vnode
= NULL
;
5660 if (!TREE_PUBLIC (decl
))
5662 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5663 fnode
= cgraph_get_node (decl
);
5665 vnode
= varpool_get_node (decl
);
5666 return vnode
|| fnode
;
5672 /* See if the target of alias is defined in this unit.
5673 Used as callback for propagate_aliases. */
5676 trivially_defined_alias (tree decl ATTRIBUTE_UNUSED
,
5678 void *data ATTRIBUTE_UNUSED
)
5680 struct cgraph_node
*fnode
= NULL
;
5681 struct varpool_node
*vnode
= NULL
;
5683 fnode
= cgraph_node_for_asm (target
);
5684 vnode
= (fnode
== NULL
) ? varpool_node_for_asm (target
) : NULL
;
5685 return (fnode
&& fnode
->analyzed
) || (vnode
&& vnode
->finalized
);
5688 /* Remove the alias pairing for functions that are no longer in the call
5692 remove_unreachable_alias_pairs (void)
5694 symbol_alias_set_t
*visible
;
5698 if (alias_pairs
== NULL
)
5701 /* We have to compute the set of visible nodes including aliases
5703 visible
= propagate_aliases_forward (trivially_visible_alias
, NULL
);
5705 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); )
5707 if (!DECL_EXTERNAL (p
->decl
)
5708 && !symbol_alias_set_contains (visible
, p
->decl
))
5710 VEC_unordered_remove (alias_pair
, alias_pairs
, i
);
5717 symbol_alias_set_destroy (visible
);
5721 /* First pass of completing pending aliases. Make sure that cgraph knows
5722 which symbols will be required. */
5725 finish_aliases_1 (void)
5727 symbol_alias_set_t
*defined
;
5731 if (alias_pairs
== NULL
)
5734 /* We have to compute the set of defined nodes including aliases
5736 defined
= propagate_aliases_backward (trivially_defined_alias
, NULL
);
5738 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5742 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
5743 if (target_decl
== NULL
)
5745 if (symbol_alias_set_contains (defined
, p
->target
))
5748 if (! (p
->emitted_diags
& ALIAS_DIAG_TO_UNDEF
)
5749 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5751 error ("%q+D aliased to undefined symbol %qE",
5752 p
->decl
, p
->target
);
5753 p
->emitted_diags
|= ALIAS_DIAG_TO_UNDEF
;
5756 else if (! (p
->emitted_diags
& ALIAS_DIAG_TO_EXTERN
)
5757 && DECL_EXTERNAL (target_decl
)
5758 /* We use local aliases for C++ thunks to force the tailcall
5759 to bind locally. This is a hack - to keep it working do
5760 the following (which is not strictly correct). */
5761 && (! TREE_CODE (target_decl
) == FUNCTION_DECL
5762 || ! DECL_VIRTUAL_P (target_decl
))
5763 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5765 error ("%q+D aliased to external symbol %qE",
5766 p
->decl
, p
->target
);
5767 p
->emitted_diags
|= ALIAS_DIAG_TO_EXTERN
;
5771 symbol_alias_set_destroy (defined
);
5774 /* Second pass of completing pending aliases. Emit the actual assembly.
5775 This happens at the end of compilation and thus it is assured that the
5776 target symbol has been emitted. */
5779 finish_aliases_2 (void)
5784 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5785 do_assemble_alias (p
->decl
, p
->target
);
5787 VEC_truncate (alias_pair
, alias_pairs
, 0);
5790 /* Emit an assembler directive to make the symbol for DECL an alias to
5791 the symbol for TARGET. */
5794 assemble_alias (tree decl
, tree target
)
5798 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5800 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5802 ultimate_transparent_alias_target (&target
);
5804 if (alias
== target
)
5805 error ("weakref %q+D ultimately targets itself", decl
);
5808 #ifndef ASM_OUTPUT_WEAKREF
5809 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
5810 TREE_CHAIN (alias
) = target
;
5813 if (TREE_PUBLIC (decl
))
5814 error ("weakref %q+D must have static linkage", decl
);
5818 #if !defined (ASM_OUTPUT_DEF)
5819 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5820 error_at (DECL_SOURCE_LOCATION (decl
),
5821 "alias definitions not supported in this configuration");
5824 if (!DECL_WEAK (decl
))
5826 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5827 error_at (DECL_SOURCE_LOCATION (decl
),
5828 "ifunc is not supported in this configuration");
5830 error_at (DECL_SOURCE_LOCATION (decl
),
5831 "only weak aliases are supported in this configuration");
5837 TREE_USED (decl
) = 1;
5839 /* Allow aliases to aliases. */
5840 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5841 cgraph_get_create_node (decl
)->alias
= true;
5843 varpool_node (decl
)->alias
= true;
5845 /* If the target has already been emitted, we don't have to queue the
5846 alias. This saves a tad of memory. */
5847 if (cgraph_global_info_ready
)
5848 target_decl
= find_decl_and_mark_needed (decl
, target
);
5851 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5852 do_assemble_alias (decl
, target
);
5855 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
5858 p
->emitted_diags
= ALIAS_DIAG_NONE
;
5862 /* Record and output a table of translations from original function
5863 to its transaction aware clone. Note that tm_pure functions are
5864 considered to be their own clone. */
5866 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
5867 htab_t tm_clone_hash
;
5870 record_tm_clone_pair (tree o
, tree n
)
5872 struct tree_map
**slot
, *h
;
5874 if (tm_clone_hash
== NULL
)
5875 tm_clone_hash
= htab_create_ggc (32, tree_map_hash
, tree_map_eq
, 0);
5877 h
= ggc_alloc_tree_map ();
5878 h
->hash
= htab_hash_pointer (o
);
5882 slot
= (struct tree_map
**)
5883 htab_find_slot_with_hash (tm_clone_hash
, h
, h
->hash
, INSERT
);
5888 get_tm_clone_pair (tree o
)
5892 struct tree_map
*h
, in
;
5895 in
.hash
= htab_hash_pointer (o
);
5896 h
= (struct tree_map
*) htab_find_with_hash (tm_clone_hash
,
5904 typedef struct tm_alias_pair
5911 DEF_VEC_O(tm_alias_pair
);
5912 DEF_VEC_ALLOC_O(tm_alias_pair
,heap
);
5914 /* Helper function for finish_tm_clone_pairs. Dump a hash table entry
5915 into a VEC in INFO. */
5918 dump_tm_clone_to_vec (void **slot
, void *info
)
5920 struct tree_map
*map
= (struct tree_map
*) *slot
;
5921 VEC(tm_alias_pair
,heap
) **tm_alias_pairs
5922 = (VEC(tm_alias_pair
, heap
) **) info
;
5925 p
= VEC_safe_push (tm_alias_pair
, heap
, *tm_alias_pairs
, NULL
);
5926 p
->from
= map
->base
.from
;
5928 p
->uid
= DECL_UID (p
->from
);
5932 /* Dump the actual pairs to the .tm_clone_table section. */
5935 dump_tm_clone_pairs (VEC(tm_alias_pair
,heap
) *tm_alias_pairs
)
5939 bool switched
= false;
5941 FOR_EACH_VEC_ELT (tm_alias_pair
, tm_alias_pairs
, i
, p
)
5945 struct cgraph_node
*src_n
= cgraph_get_node (src
);
5946 struct cgraph_node
*dst_n
= cgraph_get_node (dst
);
5948 /* The function ipa_tm_create_version() marks the clone as needed if
5949 the original function was needed. But we also mark the clone as
5950 needed if we ever called the clone indirectly through
5951 TM_GETTMCLONE. If neither of these are true, we didn't generate
5952 a clone, and we didn't call it indirectly... no sense keeping it
5953 in the clone table. */
5954 if (!dst_n
|| !dst_n
->needed
)
5957 /* This covers the case where we have optimized the original
5958 function away, and only access the transactional clone. */
5959 if (!src_n
|| !src_n
->needed
)
5964 switch_to_section (targetm
.asm_out
.tm_clone_table_section ());
5965 assemble_align (POINTER_SIZE
);
5969 assemble_integer (XEXP (DECL_RTL (src
), 0),
5970 POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
5971 assemble_integer (XEXP (DECL_RTL (dst
), 0),
5972 POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
5976 /* Provide a default for the tm_clone_table section. */
5979 default_clone_table_section (void)
5981 return get_named_section (NULL
, ".tm_clone_table", 3);
5984 /* Helper comparison function for qsorting by the DECL_UID stored in
5985 alias_pair->emitted_diags. */
5988 tm_alias_pair_cmp (const void *x
, const void *y
)
5990 const tm_alias_pair
*p1
= (const tm_alias_pair
*) x
;
5991 const tm_alias_pair
*p2
= (const tm_alias_pair
*) y
;
5992 if (p1
->uid
< p2
->uid
)
5994 if (p1
->uid
> p2
->uid
)
6000 finish_tm_clone_pairs (void)
6002 VEC(tm_alias_pair
,heap
) *tm_alias_pairs
= NULL
;
6004 if (tm_clone_hash
== NULL
)
6007 /* We need a determenistic order for the .tm_clone_table, otherwise
6008 we will get bootstrap comparison failures, so dump the hash table
6009 to a vector, sort it, and dump the vector. */
6011 /* Dump the hashtable to a vector. */
6012 htab_traverse_noresize (tm_clone_hash
, dump_tm_clone_to_vec
,
6013 (void *) &tm_alias_pairs
);
6015 VEC_qsort (tm_alias_pair
, tm_alias_pairs
, tm_alias_pair_cmp
);
6018 dump_tm_clone_pairs (tm_alias_pairs
);
6020 htab_delete (tm_clone_hash
);
6021 tm_clone_hash
= NULL
;
6022 VEC_free (tm_alias_pair
, heap
, tm_alias_pairs
);
6026 /* Emit an assembler directive to set symbol for DECL visibility to
6027 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
6030 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
6031 int vis ATTRIBUTE_UNUSED
)
6033 #ifdef HAVE_GAS_HIDDEN
6034 static const char * const visibility_types
[] = {
6035 NULL
, "protected", "hidden", "internal"
6038 const char *name
, *type
;
6040 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6041 type
= visibility_types
[vis
];
6043 fprintf (asm_out_file
, "\t.%s\t", type
);
6044 assemble_name (asm_out_file
, name
);
6045 fprintf (asm_out_file
, "\n");
6047 warning (OPT_Wattributes
, "visibility attribute not supported "
6048 "in this configuration; ignored");
6052 /* A helper function to call assemble_visibility when needed for a decl. */
6055 maybe_assemble_visibility (tree decl
)
6057 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
6059 if (vis
!= VISIBILITY_DEFAULT
)
6061 targetm
.asm_out
.assemble_visibility (decl
, vis
);
6068 /* Returns 1 if the target configuration supports defining public symbols
6069 so that one of them will be chosen at link time instead of generating a
6070 multiply-defined symbol error, whether through the use of weak symbols or
6071 a target-specific mechanism for having duplicates discarded. */
6074 supports_one_only (void)
6076 if (SUPPORTS_ONE_ONLY
)
6078 return TARGET_SUPPORTS_WEAK
;
6081 /* Set up DECL as a public symbol that can be defined in multiple
6082 translation units without generating a linker error. */
6085 make_decl_one_only (tree decl
, tree comdat_group
)
6087 gcc_assert (TREE_CODE (decl
) == VAR_DECL
6088 || TREE_CODE (decl
) == FUNCTION_DECL
);
6090 TREE_PUBLIC (decl
) = 1;
6092 if (SUPPORTS_ONE_ONLY
)
6094 #ifdef MAKE_DECL_ONE_ONLY
6095 MAKE_DECL_ONE_ONLY (decl
);
6097 DECL_COMDAT_GROUP (decl
) = comdat_group
;
6099 else if (TREE_CODE (decl
) == VAR_DECL
6100 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
6101 DECL_COMMON (decl
) = 1;
6104 gcc_assert (TARGET_SUPPORTS_WEAK
);
6105 DECL_WEAK (decl
) = 1;
6110 init_varasm_once (void)
6112 section_htab
= htab_create_ggc (31, section_entry_hash
,
6113 section_entry_eq
, NULL
);
6114 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
6115 object_block_entry_eq
, NULL
);
6116 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
6117 const_desc_eq
, NULL
);
6119 const_alias_set
= new_alias_set ();
6120 shared_constant_pool
= create_constant_pool ();
6122 #ifdef TEXT_SECTION_ASM_OP
6123 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
6124 TEXT_SECTION_ASM_OP
);
6127 #ifdef DATA_SECTION_ASM_OP
6128 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6129 DATA_SECTION_ASM_OP
);
6132 #ifdef SDATA_SECTION_ASM_OP
6133 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6134 SDATA_SECTION_ASM_OP
);
6137 #ifdef READONLY_DATA_SECTION_ASM_OP
6138 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
6139 READONLY_DATA_SECTION_ASM_OP
);
6142 #ifdef CTORS_SECTION_ASM_OP
6143 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
6144 CTORS_SECTION_ASM_OP
);
6147 #ifdef DTORS_SECTION_ASM_OP
6148 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
6149 DTORS_SECTION_ASM_OP
);
6152 #ifdef BSS_SECTION_ASM_OP
6153 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6154 output_section_asm_op
,
6155 BSS_SECTION_ASM_OP
);
6158 #ifdef SBSS_SECTION_ASM_OP
6159 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6160 output_section_asm_op
,
6161 SBSS_SECTION_ASM_OP
);
6164 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6165 | SECTION_COMMON
, emit_tls_common
);
6166 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6167 | SECTION_COMMON
, emit_local
);
6168 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6169 | SECTION_COMMON
, emit_common
);
6171 #if defined ASM_OUTPUT_ALIGNED_BSS
6172 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
6176 targetm
.asm_out
.init_sections ();
6178 if (readonly_data_section
== NULL
)
6179 readonly_data_section
= text_section
;
6183 decl_default_tls_model (const_tree decl
)
6185 enum tls_model kind
;
6188 is_local
= targetm
.binds_local_p (decl
);
6192 kind
= TLS_MODEL_LOCAL_EXEC
;
6194 kind
= TLS_MODEL_INITIAL_EXEC
;
6197 /* Local dynamic is inefficient when we're not combining the
6198 parts of the address. */
6199 else if (optimize
&& is_local
)
6200 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6202 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6203 if (kind
< flag_tls_default
)
6204 kind
= flag_tls_default
;
6209 /* Select a set of attributes for section NAME based on the properties
6210 of DECL and whether or not RELOC indicates that DECL's initializer
6211 might contain runtime relocations.
6213 We make the section read-only and executable for a function decl,
6214 read-only for a const data decl, and writable for a non-const data decl. */
6217 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6221 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6222 flags
= SECTION_CODE
;
6225 enum section_category category
6226 = categorize_decl_for_section (decl
, reloc
);
6227 if (decl_readonly_section_1 (category
))
6229 else if (category
== SECCAT_DATA_REL_RO
6230 || category
== SECCAT_DATA_REL_RO_LOCAL
)
6231 flags
= SECTION_WRITE
| SECTION_RELRO
;
6233 flags
= SECTION_WRITE
;
6237 flags
= SECTION_WRITE
;
6238 if (strcmp (name
, ".data.rel.ro") == 0
6239 || strcmp (name
, ".data.rel.ro.local") == 0)
6240 flags
|= SECTION_RELRO
;
6243 if (decl
&& DECL_ONE_ONLY (decl
))
6244 flags
|= SECTION_LINKONCE
;
6246 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6247 flags
|= SECTION_TLS
| SECTION_WRITE
;
6249 if (strcmp (name
, ".bss") == 0
6250 || strncmp (name
, ".bss.", 5) == 0
6251 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6252 || strcmp (name
, ".sbss") == 0
6253 || strncmp (name
, ".sbss.", 6) == 0
6254 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6255 flags
|= SECTION_BSS
;
6257 if (strcmp (name
, ".tdata") == 0
6258 || strncmp (name
, ".tdata.", 7) == 0
6259 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6260 flags
|= SECTION_TLS
;
6262 if (strcmp (name
, ".tbss") == 0
6263 || strncmp (name
, ".tbss.", 6) == 0
6264 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6265 flags
|= SECTION_TLS
| SECTION_BSS
;
6267 /* These three sections have special ELF types. They are neither
6268 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6269 want to print a section type (@progbits or @nobits). If someone
6270 is silly enough to emit code or TLS variables to one of these
6271 sections, then don't handle them specially. */
6272 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
6273 && (strcmp (name
, ".init_array") == 0
6274 || strcmp (name
, ".fini_array") == 0
6275 || strcmp (name
, ".preinit_array") == 0))
6276 flags
|= SECTION_NOTYPE
;
6281 /* Return true if the target supports some form of global BSS,
6282 either through bss_noswitch_section, or by selecting a BSS
6283 section in TARGET_ASM_SELECT_SECTION. */
6286 have_global_bss_p (void)
6288 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6291 /* Output assembly to switch to section NAME with attribute FLAGS.
6292 Four variants for common object file formats. */
6295 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6296 unsigned int flags ATTRIBUTE_UNUSED
,
6297 tree decl ATTRIBUTE_UNUSED
)
6299 /* Some object formats don't support named sections at all. The
6300 front-end should already have flagged this as an error. */
6304 #ifndef TLS_SECTION_ASM_FLAG
6305 #define TLS_SECTION_ASM_FLAG 'T'
6309 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6310 tree decl ATTRIBUTE_UNUSED
)
6312 char flagchars
[10], *f
= flagchars
;
6314 /* If we have already declared this section, we can use an
6315 abbreviated form to switch back to it -- unless this section is
6316 part of a COMDAT groups, in which case GAS requires the full
6317 declaration every time. */
6318 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6319 && (flags
& SECTION_DECLARED
))
6321 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6325 if (!(flags
& SECTION_DEBUG
))
6327 if (flags
& SECTION_EXCLUDE
)
6329 if (flags
& SECTION_WRITE
)
6331 if (flags
& SECTION_CODE
)
6333 if (flags
& SECTION_SMALL
)
6335 if (flags
& SECTION_MERGE
)
6337 if (flags
& SECTION_STRINGS
)
6339 if (flags
& SECTION_TLS
)
6340 *f
++ = TLS_SECTION_ASM_FLAG
;
6341 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6345 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6347 if (!(flags
& SECTION_NOTYPE
))
6352 if (flags
& SECTION_BSS
)
6358 /* On platforms that use "@" as the assembly comment character,
6360 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6362 fprintf (asm_out_file
, format
, type
);
6364 if (flags
& SECTION_ENTSIZE
)
6365 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6366 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6368 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6369 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6371 fprintf (asm_out_file
, ",%s,comdat",
6372 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6376 putc ('\n', asm_out_file
);
6380 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6381 tree decl ATTRIBUTE_UNUSED
)
6383 char flagchars
[8], *f
= flagchars
;
6385 if (flags
& SECTION_WRITE
)
6387 if (flags
& SECTION_CODE
)
6391 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6395 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6398 default_coff_asm_named_section (name
, flags
, decl
);
6400 if (flags
& SECTION_LINKONCE
)
6402 /* Functions may have been compiled at various levels of
6403 optimization so we can't use `same_size' here.
6404 Instead, have the linker pick one. */
6405 fprintf (asm_out_file
, "\t.linkonce %s\n",
6406 (flags
& SECTION_CODE
? "discard" : "same_size"));
6410 /* The lame default section selector. */
6413 default_select_section (tree decl
, int reloc
,
6414 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6418 if (decl_readonly_section (decl
, reloc
))
6419 return readonly_data_section
;
6421 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6423 if (! ((flag_pic
&& reloc
)
6424 || !TREE_READONLY (decl
)
6425 || TREE_SIDE_EFFECTS (decl
)
6426 || !TREE_CONSTANT (decl
)))
6427 return readonly_data_section
;
6429 else if (TREE_CODE (decl
) == STRING_CST
)
6430 return readonly_data_section
;
6431 else if (! (flag_pic
&& reloc
))
6432 return readonly_data_section
;
6434 return data_section
;
6437 enum section_category
6438 categorize_decl_for_section (const_tree decl
, int reloc
)
6440 enum section_category ret
;
6442 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6444 else if (TREE_CODE (decl
) == STRING_CST
)
6446 if (flag_mudflap
) /* or !flag_merge_constants */
6447 return SECCAT_RODATA
;
6449 return SECCAT_RODATA_MERGE_STR
;
6451 else if (TREE_CODE (decl
) == VAR_DECL
)
6453 if (bss_initializer_p (decl
))
6455 else if (! TREE_READONLY (decl
)
6456 || TREE_SIDE_EFFECTS (decl
)
6457 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6459 /* Here the reloc_rw_mask is not testing whether the section should
6460 be read-only or not, but whether the dynamic link will have to
6461 do something. If so, we wish to segregate the data in order to
6462 minimize cache misses inside the dynamic linker. */
6463 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6464 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6468 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6469 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6470 else if (reloc
|| flag_merge_constants
< 2)
6471 /* C and C++ don't allow different variables to share the same
6472 location. -fmerge-all-constants allows even that (at the
6473 expense of not conforming). */
6474 ret
= SECCAT_RODATA
;
6475 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6476 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6478 ret
= SECCAT_RODATA_MERGE_CONST
;
6480 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6482 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6483 || TREE_SIDE_EFFECTS (decl
)
6484 || ! TREE_CONSTANT (decl
))
6487 ret
= SECCAT_RODATA
;
6490 ret
= SECCAT_RODATA
;
6492 /* There are no read-only thread-local sections. */
6493 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6495 /* Note that this would be *just* SECCAT_BSS, except that there's
6496 no concept of a read-only thread-local-data section. */
6497 if (ret
== SECCAT_BSS
6498 || (flag_zero_initialized_in_bss
6499 && initializer_zerop (DECL_INITIAL (decl
))))
6505 /* If the target uses small data sections, select it. */
6506 else if (targetm
.in_small_data_p (decl
))
6508 if (ret
== SECCAT_BSS
)
6510 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6511 ret
= SECCAT_SRODATA
;
6520 decl_readonly_section_1 (enum section_category category
)
6525 case SECCAT_RODATA_MERGE_STR
:
6526 case SECCAT_RODATA_MERGE_STR_INIT
:
6527 case SECCAT_RODATA_MERGE_CONST
:
6528 case SECCAT_SRODATA
:
6536 decl_readonly_section (const_tree decl
, int reloc
)
6538 return decl_readonly_section_1 (categorize_decl_for_section (decl
, reloc
));
6541 /* Select a section based on the above categorization. */
6544 default_elf_select_section (tree decl
, int reloc
,
6545 unsigned HOST_WIDE_INT align
)
6548 switch (categorize_decl_for_section (decl
, reloc
))
6551 /* We're not supposed to be called on FUNCTION_DECLs. */
6554 return readonly_data_section
;
6555 case SECCAT_RODATA_MERGE_STR
:
6556 return mergeable_string_section (decl
, align
, 0);
6557 case SECCAT_RODATA_MERGE_STR_INIT
:
6558 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6559 case SECCAT_RODATA_MERGE_CONST
:
6560 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6561 case SECCAT_SRODATA
:
6565 return data_section
;
6566 case SECCAT_DATA_REL
:
6567 sname
= ".data.rel";
6569 case SECCAT_DATA_REL_LOCAL
:
6570 sname
= ".data.rel.local";
6572 case SECCAT_DATA_REL_RO
:
6573 sname
= ".data.rel.ro";
6575 case SECCAT_DATA_REL_RO_LOCAL
:
6576 sname
= ".data.rel.ro.local";
6601 return get_named_section (decl
, sname
, reloc
);
6604 /* Construct a unique section name based on the decl name and the
6605 categorization performed above. */
6608 default_unique_section (tree decl
, int reloc
)
6610 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6611 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6612 const char *prefix
, *name
, *linkonce
;
6615 switch (categorize_decl_for_section (decl
, reloc
))
6618 prefix
= one_only
? ".t" : ".text";
6621 case SECCAT_RODATA_MERGE_STR
:
6622 case SECCAT_RODATA_MERGE_STR_INIT
:
6623 case SECCAT_RODATA_MERGE_CONST
:
6624 prefix
= one_only
? ".r" : ".rodata";
6626 case SECCAT_SRODATA
:
6627 prefix
= one_only
? ".s2" : ".sdata2";
6630 prefix
= one_only
? ".d" : ".data";
6632 case SECCAT_DATA_REL
:
6633 prefix
= one_only
? ".d.rel" : ".data.rel";
6635 case SECCAT_DATA_REL_LOCAL
:
6636 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6638 case SECCAT_DATA_REL_RO
:
6639 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6641 case SECCAT_DATA_REL_RO_LOCAL
:
6642 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6645 prefix
= one_only
? ".s" : ".sdata";
6648 prefix
= one_only
? ".b" : ".bss";
6651 prefix
= one_only
? ".sb" : ".sbss";
6654 prefix
= one_only
? ".td" : ".tdata";
6657 prefix
= one_only
? ".tb" : ".tbss";
6663 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6664 name
= targetm
.strip_name_encoding (name
);
6666 /* If we're using one_only, then there needs to be a .gnu.linkonce
6667 prefix to the section name. */
6668 linkonce
= one_only
? ".gnu.linkonce" : "";
6670 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6672 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6675 /* Like compute_reloc_for_constant, except for an RTX. The return value
6676 is a mask for which bit 1 indicates a global relocation, and bit 0
6677 indicates a local relocation. */
6680 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6682 int *preloc
= (int *) data
;
6685 switch (GET_CODE (x
))
6688 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6701 compute_reloc_for_rtx (rtx x
)
6705 switch (GET_CODE (x
))
6711 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6720 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6722 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6724 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6725 return data_section
;
6727 return readonly_data_section
;
6731 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6732 unsigned HOST_WIDE_INT align
)
6734 int reloc
= compute_reloc_for_rtx (x
);
6736 /* ??? Handle small data here somehow. */
6738 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6741 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6743 return get_named_section (NULL
, ".data.rel.ro", 3);
6746 return mergeable_constant_section (mode
, align
, 0);
6749 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6752 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6757 /* Careful not to prod global register variables. */
6760 symbol
= XEXP (rtl
, 0);
6761 if (GET_CODE (symbol
) != SYMBOL_REF
)
6764 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6765 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6766 flags
|= SYMBOL_FLAG_FUNCTION
;
6767 if (targetm
.binds_local_p (decl
))
6768 flags
|= SYMBOL_FLAG_LOCAL
;
6769 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6770 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6771 else if (targetm
.in_small_data_p (decl
))
6772 flags
|= SYMBOL_FLAG_SMALL
;
6773 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6774 being PUBLIC, the thing *must* be defined in this translation unit.
6775 Prevent this buglet from being propagated into rtl code as well. */
6776 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6777 flags
|= SYMBOL_FLAG_EXTERNAL
;
6779 SYMBOL_REF_FLAGS (symbol
) = flags
;
6782 /* By default, we do nothing for encode_section_info, so we need not
6783 do anything but discard the '*' marker. */
6786 default_strip_name_encoding (const char *str
)
6788 return str
+ (*str
== '*');
6791 #ifdef ASM_OUTPUT_DEF
6792 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6793 anchor relative to ".", the current section position. */
6796 default_asm_output_anchor (rtx symbol
)
6800 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6801 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6802 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6806 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6809 default_use_anchors_for_symbol_p (const_rtx symbol
)
6814 /* Don't use anchors for mergeable sections. The linker might move
6815 the objects around. */
6816 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6817 if (sect
->common
.flags
& SECTION_MERGE
)
6820 /* Don't use anchors for small data sections. The small data register
6821 acts as an anchor for such sections. */
6822 if (sect
->common
.flags
& SECTION_SMALL
)
6825 decl
= SYMBOL_REF_DECL (symbol
);
6826 if (decl
&& DECL_P (decl
))
6828 /* Don't use section anchors for decls that might be defined by
6830 if (!targetm
.binds_local_p (decl
))
6833 /* Don't use section anchors for decls that will be placed in a
6834 small data section. */
6835 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6836 one above. The problem is that we only use SECTION_SMALL for
6837 sections that should be marked as small in the section directive. */
6838 if (targetm
.in_small_data_p (decl
))
6844 /* Return true when RESOLUTION indicate that symbol will be bound to the
6845 definition provided by current .o file. */
6848 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
6850 return (resolution
== LDPR_PREVAILING_DEF
6851 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6852 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
6855 /* Return true when RESOLUTION indicate that symbol will be bound locally
6856 within current executable or DSO. */
6859 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
6861 return (resolution
== LDPR_PREVAILING_DEF
6862 || resolution
== LDPR_PREVAILING_DEF_IRONLY
6863 || resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
6864 || resolution
== LDPR_PREEMPTED_REG
6865 || resolution
== LDPR_PREEMPTED_IR
6866 || resolution
== LDPR_RESOLVED_IR
6867 || resolution
== LDPR_RESOLVED_EXEC
);
6870 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6871 wrt cross-module name binding. */
6874 default_binds_local_p (const_tree exp
)
6876 return default_binds_local_p_1 (exp
, flag_shlib
);
6880 default_binds_local_p_1 (const_tree exp
, int shlib
)
6883 bool resolved_locally
= false;
6884 bool resolved_to_local_def
= false;
6886 /* With resolution file in hands, take look into resolutions.
6887 We can't just return true for resolved_locally symbols,
6888 because dynamic linking might overwrite symbols
6889 in shared libraries. */
6890 if (TREE_CODE (exp
) == VAR_DECL
&& TREE_PUBLIC (exp
)
6891 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
6893 struct varpool_node
*vnode
= varpool_get_node (exp
);
6894 if (vnode
&& resolution_local_p (vnode
->resolution
))
6895 resolved_locally
= true;
6897 && resolution_to_local_definition_p (vnode
->resolution
))
6898 resolved_to_local_def
= true;
6900 else if (TREE_CODE (exp
) == FUNCTION_DECL
&& TREE_PUBLIC (exp
))
6902 struct cgraph_node
*node
= cgraph_get_node (exp
);
6904 && resolution_local_p (node
->resolution
))
6905 resolved_locally
= true;
6907 && resolution_to_local_definition_p (node
->resolution
))
6908 resolved_to_local_def
= true;
6911 /* A non-decl is an entry in the constant pool. */
6914 /* Weakrefs may not bind locally, even though the weakref itself is always
6915 static and therefore local. Similarly, the resolver for ifunc functions
6916 might resolve to a non-local function.
6917 FIXME: We can resolve the weakref case more curefuly by looking at the
6919 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
))
6920 || (TREE_CODE (exp
) == FUNCTION_DECL
6921 && lookup_attribute ("ifunc", DECL_ATTRIBUTES (exp
))))
6923 /* Static variables are always local. */
6924 else if (! TREE_PUBLIC (exp
))
6926 /* A variable is local if the user has said explicitly that it will
6928 else if ((DECL_VISIBILITY_SPECIFIED (exp
)
6929 || resolved_to_local_def
)
6930 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6932 /* Variables defined outside this object might not be local. */
6933 else if (DECL_EXTERNAL (exp
) && !resolved_locally
)
6935 /* If defined in this object and visibility is not default, must be
6937 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6939 /* Default visibility weak data can be overridden by a strong symbol
6940 in another module and so are not local. */
6941 else if (DECL_WEAK (exp
)
6942 && !resolved_locally
)
6944 /* If PIC, then assume that any global name can be overridden by
6945 symbols resolved from other modules. */
6948 /* Uninitialized COMMON variable may be unified with symbols
6949 resolved from other modules. */
6950 else if (DECL_COMMON (exp
)
6951 && !resolved_locally
6952 && (DECL_INITIAL (exp
) == NULL
6953 || DECL_INITIAL (exp
) == error_mark_node
))
6955 /* Otherwise we're left with initialized (or non-common) global data
6956 which is of necessity defined locally. */
6963 /* Return true when references to DECL must bind to current definition in
6966 The condition is usually equivalent to whether the function binds to the
6967 current module (shared library or executable), that is to binds_local_p.
6968 We use this fact to avoid need for another target hook and implement
6969 the logic using binds_local_p and just special cases where
6970 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
6971 the weak definitions (that can be overwritten at linktime by other
6972 definition from different object file) and when resolution info is available
6973 we simply use the knowledge passed to us by linker plugin. */
6975 decl_binds_to_current_def_p (tree decl
)
6977 gcc_assert (DECL_P (decl
));
6978 if (!TREE_PUBLIC (decl
))
6980 if (!targetm
.binds_local_p (decl
))
6982 /* When resolution is available, just use it. */
6983 if (TREE_CODE (decl
) == VAR_DECL
6984 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
6986 struct varpool_node
*vnode
= varpool_get_node (decl
);
6988 && vnode
->resolution
!= LDPR_UNKNOWN
)
6989 return resolution_to_local_definition_p (vnode
->resolution
);
6991 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
6993 struct cgraph_node
*node
= cgraph_get_node (decl
);
6995 && node
->resolution
!= LDPR_UNKNOWN
)
6996 return resolution_to_local_definition_p (node
->resolution
);
6998 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
6999 binds locally but still can be overwritten).
7000 This rely on fact that binds_local_p behave as decl_replaceable_p
7001 for all other declaration types. */
7002 return !DECL_WEAK (decl
);
7005 /* A replaceable function or variable is one which may be replaced
7006 at link-time with an entirely different definition, provided that the
7007 replacement has the same type. For example, functions declared
7008 with __attribute__((weak)) on most systems are replaceable.
7010 COMDAT functions are not replaceable, since all definitions of the
7011 function must be equivalent. It is important that COMDAT functions
7012 not be treated as replaceable so that use of C++ template
7013 instantiations is not penalized. */
7016 decl_replaceable_p (tree decl
)
7018 gcc_assert (DECL_P (decl
));
7019 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
7021 return !decl_binds_to_current_def_p (decl
);
7024 /* Default function to output code that will globalize a label. A
7025 target must define GLOBAL_ASM_OP or provide its own function to
7026 globalize a label. */
7027 #ifdef GLOBAL_ASM_OP
7029 default_globalize_label (FILE * stream
, const char *name
)
7031 fputs (GLOBAL_ASM_OP
, stream
);
7032 assemble_name (stream
, name
);
7033 putc ('\n', stream
);
7035 #endif /* GLOBAL_ASM_OP */
7037 /* Default function to output code that will globalize a declaration. */
7039 default_globalize_decl_name (FILE * stream
, tree decl
)
7041 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
7042 targetm
.asm_out
.globalize_label (stream
, name
);
7045 /* Default function to output a label for unwind information. The
7046 default is to do nothing. A target that needs nonlocal labels for
7047 unwind information must provide its own function to do this. */
7049 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
7050 tree decl ATTRIBUTE_UNUSED
,
7051 int for_eh ATTRIBUTE_UNUSED
,
7052 int empty ATTRIBUTE_UNUSED
)
7056 /* Default function to output a label to divide up the exception table.
7057 The default is to do nothing. A target that needs/wants to divide
7058 up the table must provide it's own function to do this. */
7060 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
7064 /* This is how to output an internal numbered label where PREFIX is
7065 the class of label and LABELNO is the number within the class. */
7068 default_generate_internal_label (char *buf
, const char *prefix
,
7069 unsigned long labelno
)
7071 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
7074 /* This is how to output an internal numbered label where PREFIX is
7075 the class of label and LABELNO is the number within the class. */
7078 default_internal_label (FILE *stream
, const char *prefix
,
7079 unsigned long labelno
)
7081 char *const buf
= (char *) alloca (40 + strlen (prefix
));
7082 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
7083 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
7087 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
7090 default_asm_declare_constant_name (FILE *file
, const char *name
,
7091 const_tree exp ATTRIBUTE_UNUSED
,
7092 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
7094 assemble_label (file
, name
);
7097 /* This is the default behavior at the beginning of a file. It's
7098 controlled by two other target-hook toggles. */
7100 default_file_start (void)
7102 if (targetm
.asm_file_start_app_off
7103 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
7104 fputs (ASM_APP_OFF
, asm_out_file
);
7106 if (targetm
.asm_file_start_file_directive
)
7107 output_file_directive (asm_out_file
, main_input_filename
);
7110 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
7111 which emits a special section directive used to indicate whether or
7112 not this object file needs an executable stack. This is primarily
7113 a GNU extension to ELF but could be used on other targets. */
7115 int trampolines_created
;
7118 file_end_indicate_exec_stack (void)
7120 unsigned int flags
= SECTION_DEBUG
;
7121 if (trampolines_created
)
7122 flags
|= SECTION_CODE
;
7124 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
7127 /* Emit a special section directive to indicate that this object file
7128 was compiled with -fsplit-stack. This is used to let the linker
7129 detect calls between split-stack code and non-split-stack code, so
7130 that it can modify the split-stack code to allocate a sufficiently
7131 large stack. We emit another special section if there are any
7132 functions in this file which have the no_split_stack attribute, to
7133 prevent the linker from warning about being unable to convert the
7134 functions if they call non-split-stack code. */
7137 file_end_indicate_split_stack (void)
7139 if (flag_split_stack
)
7141 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
7143 if (saw_no_split_stack
)
7144 switch_to_section (get_section (".note.GNU-no-split-stack",
7145 SECTION_DEBUG
, NULL
));
7149 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
7150 a get_unnamed_section callback. */
7153 output_section_asm_op (const void *directive
)
7155 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
7158 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
7159 the current section is NEW_SECTION. */
7162 switch_to_section (section
*new_section
)
7164 if (in_section
== new_section
)
7167 if (new_section
->common
.flags
& SECTION_FORGET
)
7170 in_section
= new_section
;
7172 switch (SECTION_STYLE (new_section
))
7175 targetm
.asm_out
.named_section (new_section
->named
.name
,
7176 new_section
->named
.common
.flags
,
7177 new_section
->named
.decl
);
7180 case SECTION_UNNAMED
:
7181 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
7184 case SECTION_NOSWITCH
:
7189 new_section
->common
.flags
|= SECTION_DECLARED
;
7192 /* If block symbol SYMBOL has not yet been assigned an offset, place
7193 it at the end of its block. */
7196 place_block_symbol (rtx symbol
)
7198 unsigned HOST_WIDE_INT size
, mask
, offset
;
7199 struct constant_descriptor_rtx
*desc
;
7200 unsigned int alignment
;
7201 struct object_block
*block
;
7204 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
7205 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
7208 /* Work out the symbol's size and alignment. */
7209 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7211 desc
= SYMBOL_REF_CONSTANT (symbol
);
7212 alignment
= desc
->align
;
7213 size
= GET_MODE_SIZE (desc
->mode
);
7215 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7217 decl
= SYMBOL_REF_DECL (symbol
);
7218 alignment
= DECL_ALIGN (decl
);
7219 size
= get_constant_size (DECL_INITIAL (decl
));
7223 decl
= SYMBOL_REF_DECL (symbol
);
7224 alignment
= DECL_ALIGN (decl
);
7225 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
7228 /* Calculate the object's offset from the start of the block. */
7229 block
= SYMBOL_REF_BLOCK (symbol
);
7230 mask
= alignment
/ BITS_PER_UNIT
- 1;
7231 offset
= (block
->size
+ mask
) & ~mask
;
7232 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
7234 /* Record the block's new alignment and size. */
7235 block
->alignment
= MAX (block
->alignment
, alignment
);
7236 block
->size
= offset
+ size
;
7238 VEC_safe_push (rtx
, gc
, block
->objects
, symbol
);
7241 /* Return the anchor that should be used to address byte offset OFFSET
7242 from the first object in BLOCK. MODEL is the TLS model used
7246 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7247 enum tls_model model
)
7250 unsigned int begin
, middle
, end
;
7251 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7254 /* Work out the anchor's offset. Use an offset of 0 for the first
7255 anchor so that we don't pessimize the case where we take the address
7256 of a variable at the beginning of the block. This is particularly
7257 useful when a block has only one variable assigned to it.
7259 We try to place anchors RANGE bytes apart, so there can then be
7260 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7261 a ptr_mode offset. With some target settings, the lowest such
7262 anchor might be out of range for the lowest ptr_mode offset;
7263 likewise the highest anchor for the highest offset. Use anchors
7264 at the extreme ends of the ptr_mode range in such cases.
7266 All arithmetic uses unsigned integers in order to avoid
7268 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7269 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7270 range
= max_offset
- min_offset
+ 1;
7275 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
7278 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7279 delta
-= delta
% range
;
7282 offset
= (HOST_WIDE_INT
) (-delta
);
7286 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7287 delta
-= delta
% range
;
7288 if (delta
> bias
- 1)
7290 offset
= (HOST_WIDE_INT
) delta
;
7294 /* Do a binary search to see if there's already an anchor we can use.
7295 Set BEGIN to the new anchor's index if not. */
7297 end
= VEC_length (rtx
, block
->anchors
);
7298 while (begin
!= end
)
7300 middle
= (end
+ begin
) / 2;
7301 anchor
= VEC_index (rtx
, block
->anchors
, middle
);
7302 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7304 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7306 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7308 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7314 /* Create a new anchor with a unique label. */
7315 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7316 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7317 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7318 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7320 /* Insert it at index BEGIN. */
7321 VEC_safe_insert (rtx
, gc
, block
->anchors
, begin
, anchor
);
7325 /* Output the objects in BLOCK. */
7328 output_object_block (struct object_block
*block
)
7330 struct constant_descriptor_rtx
*desc
;
7332 HOST_WIDE_INT offset
;
7336 if (block
->objects
== NULL
)
7339 /* Switch to the section and make sure that the first byte is
7340 suitably aligned. */
7341 switch_to_section (block
->sect
);
7342 assemble_align (block
->alignment
);
7344 /* Define the values of all anchors relative to the current section
7346 FOR_EACH_VEC_ELT (rtx
, block
->anchors
, i
, symbol
)
7347 targetm
.asm_out
.output_anchor (symbol
);
7349 /* Output the objects themselves. */
7351 FOR_EACH_VEC_ELT (rtx
, block
->objects
, i
, symbol
)
7353 /* Move to the object's offset, padding with zeros if necessary. */
7354 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7355 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7356 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7358 desc
= SYMBOL_REF_CONSTANT (symbol
);
7359 output_constant_pool_1 (desc
, 1);
7360 offset
+= GET_MODE_SIZE (desc
->mode
);
7362 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7364 decl
= SYMBOL_REF_DECL (symbol
);
7365 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
7367 offset
+= get_constant_size (DECL_INITIAL (decl
));
7371 decl
= SYMBOL_REF_DECL (symbol
);
7372 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
7373 offset
+= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
7378 /* A htab_traverse callback used to call output_object_block for
7379 each member of object_block_htab. */
7382 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
7384 output_object_block ((struct object_block
*) (*slot
));
7388 /* Output the definitions of all object_blocks. */
7391 output_object_blocks (void)
7393 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
7396 /* This function provides a possible implementation of the
7397 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7398 by -frecord-gcc-switches it creates a new mergeable, string section in the
7399 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7400 contains the switches in ASCII format.
7402 FIXME: This code does not correctly handle double quote characters
7403 that appear inside strings, (it strips them rather than preserving them).
7404 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7405 characters - instead it treats them as sub-string separators. Since
7406 we want to emit NUL strings terminators into the object file we have to use
7410 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7414 case SWITCH_TYPE_PASSED
:
7415 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
7416 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7419 case SWITCH_TYPE_DESCRIPTIVE
:
7422 /* Distinguish between invocations where name is NULL. */
7423 static bool started
= false;
7429 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7433 | (SECTION_ENTSIZE
& 1),
7435 switch_to_section (sec
);
7444 /* The return value is currently ignored by the caller, but must be 0.
7445 For -fverbose-asm the return value would be the number of characters
7446 emitted into the assembler file. */
7450 /* Emit text to declare externally defined symbols. It is needed to
7451 properly support non-default visibility. */
7453 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7455 const char *name ATTRIBUTE_UNUSED
)
7457 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7458 set in order to avoid putting out names that are never really
7460 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7461 && targetm
.binds_local_p (decl
))
7462 maybe_assemble_visibility (decl
);
7465 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7468 default_asm_output_source_filename (FILE *file
, const char *name
)
7470 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7471 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
7473 fprintf (file
, "\t.file\t");
7474 output_quoted_string (file
, name
);
7479 /* Output a file name in the form wanted by System V. */
7482 output_file_directive (FILE *asm_file
, const char *input_name
)
7487 if (input_name
== NULL
)
7488 input_name
= "<stdin>";
7490 input_name
= remap_debug_filename (input_name
);
7492 len
= strlen (input_name
);
7493 na
= input_name
+ len
;
7495 /* NA gets INPUT_NAME sans directory names. */
7496 while (na
> input_name
)
7498 if (IS_DIR_SEPARATOR (na
[-1]))
7503 targetm
.asm_out
.output_source_filename (asm_file
, na
);
7506 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7509 make_debug_expr_from_rtl (const_rtx exp
)
7511 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7512 enum machine_mode mode
= GET_MODE (exp
);
7515 DECL_ARTIFICIAL (ddecl
) = 1;
7516 if (REG_P (exp
) && REG_EXPR (exp
))
7517 type
= TREE_TYPE (REG_EXPR (exp
));
7518 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7519 type
= TREE_TYPE (MEM_EXPR (exp
));
7522 if (type
&& TYPE_MODE (type
) == mode
)
7523 TREE_TYPE (ddecl
) = type
;
7525 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7526 DECL_MODE (ddecl
) = mode
;
7527 dval
= gen_rtx_DEBUG_EXPR (mode
);
7528 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7529 SET_DECL_RTL (ddecl
, dval
);
7533 #ifdef ELF_ASCII_ESCAPES
7534 /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
7537 default_elf_asm_output_limited_string (FILE *f
, const char *s
)
7542 fputs (STRING_ASM_OP
, f
);
7547 escape
= ELF_ASCII_ESCAPES
[c
];
7554 /* TODO: Print in hex with fast function, important for -flto. */
7555 fprintf (f
, "\\%03o", c
);
7568 /* Default ASM_OUTPUT_ASCII for ELF targets. */
7571 default_elf_asm_output_ascii (FILE *f
, const char *s
, unsigned int len
)
7573 const char *limit
= s
+ len
;
7574 const char *last_null
= NULL
;
7575 unsigned bytes_in_chunk
= 0;
7579 for (; s
< limit
; s
++)
7583 if (bytes_in_chunk
>= 60)
7592 for (p
= s
; p
< limit
&& *p
!= '\0'; p
++)
7599 if (p
< limit
&& (p
- s
) <= (long) ELF_STRING_LIMIT
)
7601 if (bytes_in_chunk
> 0)
7608 default_elf_asm_output_limited_string (f
, s
);
7613 if (bytes_in_chunk
== 0)
7614 fputs (ASCII_DATA_ASM_OP
"\"", f
);
7617 escape
= ELF_ASCII_ESCAPES
[c
];
7625 /* TODO: Print in hex with fast function, important for -flto. */
7626 fprintf (f
, "\\%03o", c
);
7627 bytes_in_chunk
+= 4;
7632 bytes_in_chunk
+= 2;
7639 if (bytes_in_chunk
> 0)
7647 static GTY(()) section
*elf_init_array_section
;
7648 static GTY(()) section
*elf_fini_array_section
;
7651 get_elf_initfini_array_priority_section (int priority
,
7655 if (priority
!= DEFAULT_INIT_PRIORITY
)
7658 sprintf (buf
, "%s.%.5u",
7659 constructor_p
? ".init_array" : ".fini_array",
7661 sec
= get_section (buf
, SECTION_WRITE
, NULL_TREE
);
7667 if (elf_init_array_section
== NULL
)
7668 elf_init_array_section
7669 = get_unnamed_section (0, output_section_asm_op
,
7670 "\t.section\t.init_array");
7671 sec
= elf_init_array_section
;
7675 if (elf_fini_array_section
== NULL
)
7676 elf_fini_array_section
7677 = get_unnamed_section (0, output_section_asm_op
,
7678 "\t.section\t.fini_array");
7679 sec
= elf_fini_array_section
;
7685 /* Use .init_array section for constructors. */
7688 default_elf_init_array_asm_out_constructor (rtx symbol
, int priority
)
7690 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7692 assemble_addr_to_section (symbol
, sec
);
7695 /* Use .fini_array section for destructors. */
7698 default_elf_fini_array_asm_out_destructor (rtx symbol
, int priority
)
7700 section
*sec
= get_elf_initfini_array_priority_section (priority
,
7702 assemble_addr_to_section (symbol
, sec
);
7705 #include "gt-varasm.h"