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 "targhooks.h"
50 #include "tree-mudflap.h"
52 #include "cfglayout.h"
53 #include "basic-block.h"
54 #include "tree-iterator.h"
55 #include "pointer-set.h"
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h" /* Needed for external data
59 declarations for e.g. AIX 4.x. */
62 /* The (assembler) name of the first globally-visible object output. */
63 extern GTY(()) const char *first_global_object_name
;
64 extern GTY(()) const char *weak_global_object_name
;
66 const char *first_global_object_name
;
67 const char *weak_global_object_name
;
70 struct constant_descriptor_rtx
;
71 struct rtx_constant_pool
;
73 #define n_deferred_constants (crtl->varasm.deferred_constants)
75 /* Number for making the label on the next
76 constant that is stored in memory. */
78 static GTY(()) int const_labelno
;
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81 to ASM_FINISH_DECLARE_OBJECT. */
83 int size_directive_output
;
85 /* The last decl for which assemble_variable was called,
86 if it did ASM_DECLARE_OBJECT_NAME.
87 If the last call to assemble_variable didn't do that,
90 tree last_assemble_variable_decl
;
92 /* The following global variable indicates if the first basic block
93 in a function belongs to the cold partition or not. */
95 bool first_function_block_is_cold
;
97 /* We give all constants their own alias set. Perhaps redundant with
98 MEM_READONLY_P, but pre-dates it. */
100 static alias_set_type const_alias_set
;
102 /* Whether we saw any functions with no_split_stack. */
104 static bool saw_no_split_stack
;
106 static const char *strip_reg_name (const char *);
107 static int contains_pointers_p (tree
);
108 #ifdef ASM_OUTPUT_EXTERNAL
109 static bool incorporeal_function_p (tree
);
111 static void decode_addr_const (tree
, struct addr_const
*);
112 static hashval_t
const_desc_hash (const void *);
113 static int const_desc_eq (const void *, const void *);
114 static hashval_t
const_hash_1 (const tree
);
115 static int compare_constant (const tree
, const tree
);
116 static tree
copy_constant (tree
);
117 static void output_constant_def_contents (rtx
);
118 static void output_addressed_constants (tree
);
119 static unsigned HOST_WIDE_INT
array_size_for_constructor (tree
);
120 static unsigned min_align (unsigned, unsigned);
121 static void globalize_decl (tree
);
122 static bool decl_readonly_section_1 (enum section_category
);
123 #ifdef BSS_SECTION_ASM_OP
124 #ifdef ASM_OUTPUT_ALIGNED_BSS
125 static void asm_output_aligned_bss (FILE *, tree
, const char *,
126 unsigned HOST_WIDE_INT
, int)
129 #endif /* BSS_SECTION_ASM_OP */
130 static void mark_weak (tree
);
131 static void output_constant_pool (const char *, tree
);
133 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
134 section
*text_section
;
135 section
*data_section
;
136 section
*readonly_data_section
;
137 section
*sdata_section
;
138 section
*ctors_section
;
139 section
*dtors_section
;
140 section
*bss_section
;
141 section
*sbss_section
;
143 /* Various forms of common section. All are guaranteed to be nonnull. */
144 section
*tls_comm_section
;
145 section
*comm_section
;
146 section
*lcomm_section
;
148 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
150 section
*bss_noswitch_section
;
152 /* The section that holds the main exception table, when known. The section
153 is set either by the target's init_sections hook or by the first call to
154 switch_to_exception_section. */
155 section
*exception_section
;
157 /* The section that holds the DWARF2 frame unwind information, when known.
158 The section is set either by the target's init_sections hook or by the
159 first call to switch_to_eh_frame_section. */
160 section
*eh_frame_section
;
162 /* asm_out_file's current section. This is NULL if no section has yet
163 been selected or if we lose track of what the current section is. */
166 /* True if code for the current function is currently being directed
167 at the cold section. */
168 bool in_cold_section_p
;
170 /* A linked list of all the unnamed sections. */
171 static GTY(()) section
*unnamed_sections
;
173 /* Return a nonzero value if DECL has a section attribute. */
174 #define IN_NAMED_SECTION(DECL) \
175 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
176 && DECL_SECTION_NAME (DECL) != NULL_TREE)
178 /* Hash table of named sections. */
179 static GTY((param_is (section
))) htab_t section_htab
;
181 /* A table of object_blocks, indexed by section. */
182 static GTY((param_is (struct object_block
))) htab_t object_block_htab
;
184 /* The next number to use for internal anchor labels. */
185 static GTY(()) int anchor_labelno
;
187 /* A pool of constants that can be shared between functions. */
188 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
190 /* Helper routines for maintaining section_htab. */
193 section_entry_eq (const void *p1
, const void *p2
)
195 const section
*old
= (const section
*) p1
;
196 const char *new_name
= (const char *) p2
;
198 return strcmp (old
->named
.name
, new_name
) == 0;
202 section_entry_hash (const void *p
)
204 const section
*old
= (const section
*) p
;
205 return htab_hash_string (old
->named
.name
);
208 /* Return a hash value for section SECT. */
211 hash_section (section
*sect
)
213 if (sect
->common
.flags
& SECTION_NAMED
)
214 return htab_hash_string (sect
->named
.name
);
215 return sect
->common
.flags
;
218 /* Helper routines for maintaining object_block_htab. */
221 object_block_entry_eq (const void *p1
, const void *p2
)
223 const struct object_block
*old
= (const struct object_block
*) p1
;
224 const section
*new_section
= (const section
*) p2
;
226 return old
->sect
== new_section
;
230 object_block_entry_hash (const void *p
)
232 const struct object_block
*old
= (const struct object_block
*) p
;
233 return hash_section (old
->sect
);
236 /* Return a new unnamed section with the given fields. */
239 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
244 sect
= ggc_alloc_section ();
245 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
246 sect
->unnamed
.callback
= callback
;
247 sect
->unnamed
.data
= data
;
248 sect
->unnamed
.next
= unnamed_sections
;
250 unnamed_sections
= sect
;
254 /* Return a SECTION_NOSWITCH section with the given fields. */
257 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
261 sect
= ggc_alloc_section ();
262 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
263 sect
->noswitch
.callback
= callback
;
268 /* Return the named section structure associated with NAME. Create
269 a new section with the given fields if no such structure exists. */
272 get_section (const char *name
, unsigned int flags
, tree decl
)
274 section
*sect
, **slot
;
277 htab_find_slot_with_hash (section_htab
, name
,
278 htab_hash_string (name
), INSERT
);
279 flags
|= SECTION_NAMED
;
282 sect
= ggc_alloc_section ();
283 sect
->named
.common
.flags
= flags
;
284 sect
->named
.name
= ggc_strdup (name
);
285 sect
->named
.decl
= decl
;
291 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
292 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
294 /* It is fine if one of the section flags is
295 SECTION_WRITE | SECTION_RELRO and the other has none of these
296 flags (i.e. read-only) in named sections and either the
297 section hasn't been declared yet or has been declared as writable.
298 In that case just make sure the resulting flags are
299 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
301 if (((sect
->common
.flags
^ flags
) & (SECTION_WRITE
| SECTION_RELRO
))
302 == (SECTION_WRITE
| SECTION_RELRO
)
303 && (sect
->common
.flags
304 & ~(SECTION_DECLARED
| SECTION_WRITE
| SECTION_RELRO
))
305 == (flags
& ~(SECTION_WRITE
| SECTION_RELRO
))
306 && ((sect
->common
.flags
& SECTION_DECLARED
) == 0
307 || (sect
->common
.flags
& SECTION_WRITE
)))
309 sect
->common
.flags
|= (SECTION_WRITE
| SECTION_RELRO
);
312 /* Sanity check user variables for flag changes. */
314 decl
= sect
->named
.decl
;
316 error ("%+D causes a section type conflict", decl
);
317 /* Make sure we don't error about one section multiple times. */
318 sect
->common
.flags
|= SECTION_OVERRIDE
;
324 /* Return true if the current compilation mode benefits from having
325 objects grouped into blocks. */
328 use_object_blocks_p (void)
330 return flag_section_anchors
;
333 /* Return the object_block structure for section SECT. Create a new
334 structure if we haven't created one already. Return null if SECT
337 static struct object_block
*
338 get_block_for_section (section
*sect
)
340 struct object_block
*block
;
346 slot
= htab_find_slot_with_hash (object_block_htab
, sect
,
347 hash_section (sect
), INSERT
);
348 block
= (struct object_block
*) *slot
;
351 block
= ggc_alloc_cleared_object_block ();
358 /* Create a symbol with label LABEL and place it at byte offset
359 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
360 is not yet known. LABEL must be a garbage-collected string. */
363 create_block_symbol (const char *label
, struct object_block
*block
,
364 HOST_WIDE_INT offset
)
369 /* Create the extended SYMBOL_REF. */
370 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
371 symbol
= ggc_alloc_zone_rtx_def (size
, &rtl_zone
);
373 /* Initialize the normal SYMBOL_REF fields. */
374 memset (symbol
, 0, size
);
375 PUT_CODE (symbol
, SYMBOL_REF
);
376 PUT_MODE (symbol
, Pmode
);
377 XSTR (symbol
, 0) = label
;
378 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
380 /* Initialize the block_symbol stuff. */
381 SYMBOL_REF_BLOCK (symbol
) = block
;
382 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
387 /* Return a section with a particular name and with whatever SECTION_*
388 flags section_type_flags deems appropriate. The name of the section
389 is taken from NAME if nonnull, otherwise it is taken from DECL's
390 DECL_SECTION_NAME. DECL is the decl associated with the section
391 (see the section comment for details) and RELOC is as for
392 section_type_flags. */
395 get_named_section (tree decl
, const char *name
, int reloc
)
399 gcc_assert (!decl
|| DECL_P (decl
));
401 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
403 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
405 return get_section (name
, flags
, decl
);
408 /* If required, set DECL_SECTION_NAME to a unique name. */
411 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
412 int flag_function_or_data_sections
)
414 if (DECL_SECTION_NAME (decl
) == NULL_TREE
415 && targetm
.have_named_sections
416 && (flag_function_or_data_sections
417 || DECL_ONE_ONLY (decl
)))
419 targetm
.asm_out
.unique_section (decl
, reloc
);
420 DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
) = true;
424 #ifdef BSS_SECTION_ASM_OP
426 #ifdef ASM_OUTPUT_ALIGNED_BSS
428 /* Utility function for targets to use in implementing
429 ASM_OUTPUT_ALIGNED_BSS.
430 ??? It is believed that this function will work in most cases so such
431 support is localized here. */
434 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
435 const char *name
, unsigned HOST_WIDE_INT size
,
438 switch_to_section (bss_section
);
439 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
440 #ifdef ASM_DECLARE_OBJECT_NAME
441 last_assemble_variable_decl
= decl
;
442 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
444 /* Standard thing is just output label for the object. */
445 ASM_OUTPUT_LABEL (file
, name
);
446 #endif /* ASM_DECLARE_OBJECT_NAME */
447 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
452 #endif /* BSS_SECTION_ASM_OP */
454 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
455 /* Return the hot section for function DECL. Return text_section for
459 hot_function_section (tree decl
)
461 if (decl
!= NULL_TREE
462 && DECL_SECTION_NAME (decl
) != NULL_TREE
463 && targetm
.have_named_sections
)
464 return get_named_section (decl
, NULL
, 0);
470 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
473 When DECL_SECTION_NAME is non-NULL and it is implicit section and
474 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
475 concatenate the name with NAMED_SECTION_SUFFIX.
476 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
479 get_named_text_section (tree decl
,
480 const char *text_section_name
,
481 const char *named_section_suffix
)
483 if (decl
&& DECL_SECTION_NAME (decl
))
485 if (named_section_suffix
)
487 tree dsn
= DECL_SECTION_NAME (decl
);
488 const char *stripped_name
;
491 name
= (char *) alloca (TREE_STRING_LENGTH (dsn
) + 1);
492 memcpy (name
, TREE_STRING_POINTER (dsn
),
493 TREE_STRING_LENGTH (dsn
) + 1);
495 stripped_name
= targetm
.strip_name_encoding (name
);
497 buffer
= ACONCAT ((stripped_name
, named_section_suffix
, NULL
));
498 return get_named_section (decl
, buffer
, 0);
500 else if (DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
))
504 /* Do not try to split gnu_linkonce functions. This gets somewhat
506 if (DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
)
508 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
509 name
= targetm
.strip_name_encoding (name
);
510 return get_named_section (decl
, ACONCAT ((text_section_name
, ".",
516 return get_named_section (decl
, text_section_name
, 0);
519 /* Choose named function section based on its frequency. */
522 default_function_section (tree decl
, enum node_frequency freq
,
523 bool startup
, bool exit
)
525 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
526 /* Old GNU linkers have buggy --gc-section support, which sometimes
527 results in .gcc_except_table* sections being garbage collected. */
529 && DECL_SECTION_NAME (decl
)
530 && DECL_HAS_IMPLICIT_SECTION_NAME_P (decl
))
534 if (!flag_reorder_functions
535 || !targetm
.have_named_sections
)
537 /* Startup code should go to startup subsection unless it is
538 unlikely executed (this happens especially with function splitting
539 where we can split away unnecesary parts of static constructors. */
540 if (startup
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
541 return get_named_text_section (decl
, ".text.startup", NULL
);
543 /* Similarly for exit. */
544 if (exit
&& freq
!= NODE_FREQUENCY_UNLIKELY_EXECUTED
)
545 return get_named_text_section (decl
, ".text.exit", NULL
);
547 /* Group cold functions together, similarly for hot code. */
550 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
551 return get_named_text_section (decl
, ".text.unlikely", NULL
);
552 case NODE_FREQUENCY_HOT
:
553 return get_named_text_section (decl
, ".text.hot", NULL
);
559 /* Return the section for function DECL.
561 If DECL is NULL_TREE, return the text section. We can be passed
562 NULL_TREE under some circumstances by dbxout.c at least.
564 If FORCE_COLD is true, return cold function section ignoring
565 the frequency info of cgraph_node. */
568 function_section_1 (tree decl
, bool force_cold
)
570 section
*section
= NULL
;
571 enum node_frequency freq
= NODE_FREQUENCY_NORMAL
;
572 bool startup
= false, exit
= false;
576 struct cgraph_node
*node
= cgraph_get_node (decl
);
580 freq
= node
->frequency
;
581 startup
= node
->only_called_at_startup
;
582 exit
= node
->only_called_at_exit
;
586 freq
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
588 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
589 if (decl
!= NULL_TREE
590 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
592 if (targetm
.asm_out
.function_section
)
593 section
= targetm
.asm_out
.function_section (decl
, freq
,
597 return get_named_section (decl
, NULL
, 0);
600 return targetm
.asm_out
.select_section
601 (decl
, freq
== NODE_FREQUENCY_UNLIKELY_EXECUTED
,
604 if (targetm
.asm_out
.function_section
)
605 section
= targetm
.asm_out
.function_section (decl
, freq
, startup
, exit
);
608 return hot_function_section (decl
);
612 /* Return the section for function DECL.
614 If DECL is NULL_TREE, return the text section. We can be passed
615 NULL_TREE under some circumstances by dbxout.c at least. */
618 function_section (tree decl
)
620 /* Handle cases where function splitting code decides
621 to put function entry point into unlikely executed section
622 despite the fact that the function itself is not cold
623 (i.e. it is called rarely but contains a hot loop that is
624 better to live in hot subsection for the code locality). */
625 return function_section_1 (decl
,
626 first_function_block_is_cold
);
629 /* Return the section for the current function, take IN_COLD_SECTION_P
633 current_function_section (void)
635 return function_section_1 (current_function_decl
, in_cold_section_p
);
638 /* Tell assembler to switch to unlikely-to-be-executed text section. */
641 unlikely_text_section (void)
643 return function_section_1 (current_function_decl
, true);
646 /* When called within a function context, return true if the function
647 has been assigned a cold text section and if SECT is that section.
648 When called outside a function context, return true if SECT is the
649 default cold section. */
652 unlikely_text_section_p (section
*sect
)
654 return sect
== function_section_1 (current_function_decl
, true);
657 /* Return the read-only data section associated with function DECL. */
660 default_function_rodata_section (tree decl
)
662 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
664 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
666 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
672 dot
= strchr (name
+ 1, '.');
675 len
= strlen (dot
) + 8;
676 rname
= (char *) alloca (len
);
678 strcpy (rname
, ".rodata");
680 return get_section (rname
, SECTION_LINKONCE
, decl
);
682 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
683 else if (DECL_ONE_ONLY (decl
)
684 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
686 size_t len
= strlen (name
) + 1;
687 char *rname
= (char *) alloca (len
);
689 memcpy (rname
, name
, len
);
691 return get_section (rname
, SECTION_LINKONCE
, decl
);
693 /* For .text.foo we want to use .rodata.foo. */
694 else if (flag_function_sections
&& flag_data_sections
695 && strncmp (name
, ".text.", 6) == 0)
697 size_t len
= strlen (name
) + 1;
698 char *rname
= (char *) alloca (len
+ 2);
700 memcpy (rname
, ".rodata", 7);
701 memcpy (rname
+ 7, name
+ 5, len
- 5);
702 return get_section (rname
, 0, decl
);
706 return readonly_data_section
;
709 /* Return the read-only data section associated with function DECL
710 for targets where that section should be always the single
711 readonly data section. */
714 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
716 return readonly_data_section
;
719 /* Return the section to use for string merging. */
722 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
723 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
724 unsigned int flags ATTRIBUTE_UNUSED
)
728 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
729 && TREE_CODE (decl
) == STRING_CST
730 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
732 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
733 && TREE_STRING_LENGTH (decl
) >= len
)
735 enum machine_mode mode
;
736 unsigned int modesize
;
742 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
743 modesize
= GET_MODE_BITSIZE (mode
);
744 if (modesize
>= 8 && modesize
<= 256
745 && (modesize
& (modesize
- 1)) == 0)
747 if (align
< modesize
)
750 str
= TREE_STRING_POINTER (decl
);
751 unit
= GET_MODE_SIZE (mode
);
753 /* Check for embedded NUL characters. */
754 for (i
= 0; i
< len
; i
+= unit
)
756 for (j
= 0; j
< unit
; j
++)
757 if (str
[i
+ j
] != '\0')
764 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
766 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
767 return get_section (name
, flags
, NULL
);
772 return readonly_data_section
;
775 /* Return the section to use for constant merging. */
778 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
779 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
780 unsigned int flags ATTRIBUTE_UNUSED
)
782 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
784 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
790 && (align
& (align
- 1)) == 0)
794 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
795 flags
|= (align
/ 8) | SECTION_MERGE
;
796 return get_section (name
, flags
, NULL
);
798 return readonly_data_section
;
801 /* Given NAME, a putative register name, discard any customary prefixes. */
804 strip_reg_name (const char *name
)
806 #ifdef REGISTER_PREFIX
807 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
808 name
+= strlen (REGISTER_PREFIX
);
810 if (name
[0] == '%' || name
[0] == '#')
815 /* The user has asked for a DECL to have a particular name. Set (or
816 change) it in such a way that we don't prefix an underscore to
819 set_user_assembler_name (tree decl
, const char *name
)
821 char *starred
= (char *) alloca (strlen (name
) + 2);
823 strcpy (starred
+ 1, name
);
824 change_decl_assembler_name (decl
, get_identifier (starred
));
825 SET_DECL_RTL (decl
, NULL_RTX
);
828 /* Decode an `asm' spec for a declaration as a register name.
829 Return the register number, or -1 if nothing specified,
830 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
831 or -3 if ASMSPEC is `cc' and is not recognized,
832 or -4 if ASMSPEC is `memory' and is not recognized.
833 Accept an exact spelling or a decimal number.
834 Prefixes such as % are optional. */
837 decode_reg_name_and_count (const char *asmspec
, int *pnregs
)
839 /* Presume just one register is clobbered. */
846 /* Get rid of confusing prefixes. */
847 asmspec
= strip_reg_name (asmspec
);
849 /* Allow a decimal number as a "register name". */
850 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
851 if (! ISDIGIT (asmspec
[i
]))
853 if (asmspec
[0] != 0 && i
< 0)
856 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
862 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
864 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
867 #ifdef OVERLAPPING_REGISTER_NAMES
871 const char *const name
;
874 } table
[] = OVERLAPPING_REGISTER_NAMES
;
876 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
878 && ! strcmp (asmspec
, table
[i
].name
))
880 *pnregs
= table
[i
].nregs
;
881 return table
[i
].number
;
884 #endif /* OVERLAPPING_REGISTER_NAMES */
886 #ifdef ADDITIONAL_REGISTER_NAMES
888 static const struct { const char *const name
; const int number
; } table
[]
889 = ADDITIONAL_REGISTER_NAMES
;
891 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
893 && ! strcmp (asmspec
, table
[i
].name
))
894 return table
[i
].number
;
896 #endif /* ADDITIONAL_REGISTER_NAMES */
898 if (!strcmp (asmspec
, "memory"))
901 if (!strcmp (asmspec
, "cc"))
911 decode_reg_name (const char *name
)
914 return decode_reg_name_and_count (name
, &count
);
918 /* Return true if DECL's initializer is suitable for a BSS section. */
921 bss_initializer_p (const_tree decl
)
923 return (DECL_INITIAL (decl
) == NULL
924 || DECL_INITIAL (decl
) == error_mark_node
925 || (flag_zero_initialized_in_bss
926 /* Leave constant zeroes in .rodata so they
928 && !TREE_READONLY (decl
)
929 && initializer_zerop (DECL_INITIAL (decl
))));
932 /* Compute the alignment of variable specified by DECL.
933 DONT_OUTPUT_DATA is from assemble_variable. */
936 align_variable (tree decl
, bool dont_output_data
)
938 unsigned int align
= DECL_ALIGN (decl
);
940 /* In the case for initialing an array whose length isn't specified,
941 where we have not yet been able to do the layout,
942 figure out the proper alignment now. */
943 if (dont_output_data
&& DECL_SIZE (decl
) == 0
944 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
945 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
947 /* Some object file formats have a maximum alignment which they support.
948 In particular, a.out format supports a maximum alignment of 4. */
949 if (align
> MAX_OFILE_ALIGNMENT
)
951 warning (0, "alignment of %q+D is greater than maximum object "
952 "file alignment. Using %d", decl
,
953 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
954 align
= MAX_OFILE_ALIGNMENT
;
957 /* On some machines, it is good to increase alignment sometimes. */
958 if (! DECL_USER_ALIGN (decl
))
960 #ifdef DATA_ALIGNMENT
961 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
962 /* Don't increase alignment too much for TLS variables - TLS space
964 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
967 #ifdef CONSTANT_ALIGNMENT
968 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
970 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
972 /* Don't increase alignment too much for TLS variables - TLS space
974 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
980 /* Reset the alignment in case we have made it tighter, so we can benefit
981 from it in get_pointer_alignment. */
982 DECL_ALIGN (decl
) = align
;
985 /* Return the section into which the given VAR_DECL or CONST_DECL
986 should be placed. PREFER_NOSWITCH_P is true if a noswitch
987 section should be used wherever possible. */
990 get_variable_section (tree decl
, bool prefer_noswitch_p
)
992 addr_space_t as
= ADDR_SPACE_GENERIC
;
995 if (TREE_TYPE (decl
) != error_mark_node
)
996 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
998 if (DECL_COMMON (decl
))
1000 /* If the decl has been given an explicit section name, or it resides
1001 in a non-generic address space, then it isn't common, and shouldn't
1002 be handled as such. */
1003 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1004 && ADDR_SPACE_GENERIC_P (as
));
1005 if (DECL_THREAD_LOCAL_P (decl
))
1006 return tls_comm_section
;
1007 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1008 return comm_section
;
1011 if (DECL_INITIAL (decl
) == error_mark_node
)
1012 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1013 else if (DECL_INITIAL (decl
))
1014 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1018 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1019 if (IN_NAMED_SECTION (decl
))
1020 return get_named_section (decl
, NULL
, reloc
);
1022 if (ADDR_SPACE_GENERIC_P (as
)
1023 && !DECL_THREAD_LOCAL_P (decl
)
1024 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1025 && bss_initializer_p (decl
))
1027 if (!TREE_PUBLIC (decl
))
1028 return lcomm_section
;
1029 if (bss_noswitch_section
)
1030 return bss_noswitch_section
;
1033 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
1036 /* Return the block into which object_block DECL should be placed. */
1038 static struct object_block
*
1039 get_block_for_decl (tree decl
)
1043 if (TREE_CODE (decl
) == VAR_DECL
)
1045 /* The object must be defined in this translation unit. */
1046 if (DECL_EXTERNAL (decl
))
1049 /* There's no point using object blocks for something that is
1050 isolated by definition. */
1051 if (DECL_ONE_ONLY (decl
))
1055 /* We can only calculate block offsets if the decl has a known
1057 if (DECL_SIZE_UNIT (decl
) == NULL
)
1059 if (!host_integerp (DECL_SIZE_UNIT (decl
), 1))
1062 /* Find out which section should contain DECL. We cannot put it into
1063 an object block if it requires a standalone definition. */
1064 if (TREE_CODE (decl
) == VAR_DECL
)
1065 align_variable (decl
, 0);
1066 sect
= get_variable_section (decl
, true);
1067 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1070 return get_block_for_section (sect
);
1073 /* Make sure block symbol SYMBOL is in block BLOCK. */
1076 change_symbol_block (rtx symbol
, struct object_block
*block
)
1078 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1080 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1081 SYMBOL_REF_BLOCK (symbol
) = block
;
1085 /* Return true if it is possible to put DECL in an object_block. */
1088 use_blocks_for_decl_p (tree decl
)
1090 /* Only data DECLs can be placed into object blocks. */
1091 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
1094 /* Detect decls created by dw2_force_const_mem. Such decls are
1095 special because DECL_INITIAL doesn't specify the decl's true value.
1096 dw2_output_indirect_constants will instead call assemble_variable
1097 with dont_output_data set to 1 and then print the contents itself. */
1098 if (DECL_INITIAL (decl
) == decl
)
1101 /* If this decl is an alias, then we don't want to emit a
1103 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl
)))
1109 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1110 have static storage duration. In other words, it should not be an
1111 automatic variable, including PARM_DECLs.
1113 There is, however, one exception: this function handles variables
1114 explicitly placed in a particular register by the user.
1116 This is never called for PARM_DECL nodes. */
1119 make_decl_rtl (tree decl
)
1121 const char *name
= 0;
1125 /* Check that we are not being given an automatic variable. */
1126 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1127 && TREE_CODE (decl
) != RESULT_DECL
);
1129 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1130 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1131 || TREE_STATIC (decl
)
1132 || TREE_PUBLIC (decl
)
1133 || DECL_EXTERNAL (decl
)
1134 || DECL_REGISTER (decl
));
1136 /* And that we were not given a type or a label. */
1137 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1138 && TREE_CODE (decl
) != LABEL_DECL
);
1140 /* For a duplicate declaration, we can be called twice on the
1141 same DECL node. Don't discard the RTL already made. */
1142 if (DECL_RTL_SET_P (decl
))
1144 /* If the old RTL had the wrong mode, fix the mode. */
1145 x
= DECL_RTL (decl
);
1146 if (GET_MODE (x
) != DECL_MODE (decl
))
1147 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1149 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1152 /* ??? Another way to do this would be to maintain a hashed
1153 table of such critters. Instead of adding stuff to a DECL
1154 to give certain attributes to it, we could use an external
1155 hash map from DECL to set of attributes. */
1157 /* Let the target reassign the RTL if it wants.
1158 This is necessary, for example, when one machine specific
1159 decl attribute overrides another. */
1160 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1162 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1163 on the new decl information. */
1165 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1166 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1167 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1169 /* Make this function static known to the mudflap runtime. */
1170 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1171 mudflap_enqueue_decl (decl
);
1176 /* If this variable belongs to the global constant pool, retrieve the
1177 pre-computed RTL or recompute it in LTO mode. */
1178 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1180 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1184 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1186 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1187 && DECL_REGISTER (decl
))
1189 error ("register name not specified for %q+D", decl
);
1191 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1193 const char *asmspec
= name
+1;
1194 reg_number
= decode_reg_name (asmspec
);
1195 /* First detect errors in declaring global registers. */
1196 if (reg_number
== -1)
1197 error ("register name not specified for %q+D", decl
);
1198 else if (reg_number
< 0)
1199 error ("invalid register name for %q+D", decl
);
1200 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
1201 error ("data type of %q+D isn%'t suitable for a register",
1203 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
1204 error ("register specified for %q+D isn%'t suitable for data type",
1206 /* Now handle properly declared static register variables. */
1211 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1213 DECL_INITIAL (decl
) = 0;
1214 error ("global register variable has initial value");
1216 if (TREE_THIS_VOLATILE (decl
))
1217 warning (OPT_Wvolatile_register_var
,
1218 "optimization may eliminate reads and/or "
1219 "writes to register variables");
1221 /* If the user specified one of the eliminables registers here,
1222 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1223 confused with that register and be eliminated. This usage is
1224 somewhat suspect... */
1226 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
1227 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1228 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1230 if (TREE_STATIC (decl
))
1232 /* Make this register global, so not usable for anything
1234 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1235 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1236 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1238 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
1240 globalize_reg (reg_number
+ --nregs
);
1243 /* As a register variable, it has no section. */
1247 /* Now handle ordinary static variables and functions (in memory).
1248 Also handle vars declared register invalidly. */
1249 else if (name
[0] == '*')
1251 #ifdef REGISTER_PREFIX
1252 if (strlen (REGISTER_PREFIX
) != 0)
1254 reg_number
= decode_reg_name (name
);
1255 if (reg_number
>= 0 || reg_number
== -3)
1256 error ("register name given for non-register variable %q+D", decl
);
1261 /* Specifying a section attribute on a variable forces it into a
1262 non-.bss section, and thus it cannot be common. */
1263 /* FIXME: In general this code should not be necessary because
1264 visibility pass is doing the same work. But notice_global_symbol
1265 is called early and it needs to make DECL_RTL to get the name.
1266 we take care of recomputing the DECL_RTL after visibility is changed. */
1267 if (TREE_CODE (decl
) == VAR_DECL
1268 && DECL_SECTION_NAME (decl
) != NULL_TREE
1269 && DECL_INITIAL (decl
) == NULL_TREE
1270 && DECL_COMMON (decl
))
1271 DECL_COMMON (decl
) = 0;
1273 /* Variables can't be both common and weak. */
1274 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1275 DECL_COMMON (decl
) = 0;
1277 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1278 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1281 enum machine_mode address_mode
= Pmode
;
1282 if (TREE_TYPE (decl
) != error_mark_node
)
1284 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1285 address_mode
= targetm
.addr_space
.address_mode (as
);
1287 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1289 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1290 SET_SYMBOL_REF_DECL (x
, decl
);
1292 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1293 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1294 set_mem_attributes (x
, decl
, 1);
1295 SET_DECL_RTL (decl
, x
);
1297 /* Optionally set flags or add text to the name to record information
1298 such as that it is a function name.
1299 If the name is changed, the macro ASM_OUTPUT_LABELREF
1300 will have to know how to strip this information. */
1301 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1303 /* Make this function static known to the mudflap runtime. */
1304 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1305 mudflap_enqueue_decl (decl
);
1308 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1309 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1313 make_decl_rtl_for_debug (tree decl
)
1315 unsigned int save_aliasing_flag
, save_mudflap_flag
;
1318 if (DECL_RTL_SET_P (decl
))
1319 return DECL_RTL (decl
);
1321 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1322 call new_alias_set. If running with -fcompare-debug, sometimes
1323 we do not want to create alias sets that will throw the alias
1324 numbers off in the comparison dumps. So... clearing
1325 flag_strict_aliasing will keep new_alias_set() from creating a
1326 new set. It is undesirable to register decl with mudflap
1327 in this case as well. */
1328 save_aliasing_flag
= flag_strict_aliasing
;
1329 flag_strict_aliasing
= 0;
1330 save_mudflap_flag
= flag_mudflap
;
1333 rtl
= DECL_RTL (decl
);
1334 /* Reset DECL_RTL back, as various parts of the compiler expects
1335 DECL_RTL set meaning it is actually going to be output. */
1336 SET_DECL_RTL (decl
, NULL
);
1338 flag_strict_aliasing
= save_aliasing_flag
;
1339 flag_mudflap
= save_mudflap_flag
;
1344 /* Output a string of literal assembler code
1345 for an `asm' keyword used between functions. */
1348 assemble_asm (tree string
)
1352 if (TREE_CODE (string
) == ADDR_EXPR
)
1353 string
= TREE_OPERAND (string
, 0);
1355 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1358 /* Record an element in the table of global destructors. SYMBOL is
1359 a SYMBOL_REF of the function to be called; PRIORITY is a number
1360 between 0 and MAX_INIT_PRIORITY. */
1363 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
1364 int priority ATTRIBUTE_UNUSED
)
1366 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1367 /* Tell GNU LD that this is part of the static destructor set.
1368 This will work for any system that uses stabs, most usefully
1370 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1371 dbxout_stab_value_label (XSTR (symbol
, 0));
1373 sorry ("global destructors not supported on this target");
1377 /* Write the address of the entity given by SYMBOL to SEC. */
1379 assemble_addr_to_section (rtx symbol
, section
*sec
)
1381 switch_to_section (sec
);
1382 assemble_align (POINTER_SIZE
);
1383 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1386 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1387 not) section for PRIORITY. */
1389 get_cdtor_priority_section (int priority
, bool constructor_p
)
1393 /* ??? This only works reliably with the GNU linker. */
1394 sprintf (buf
, "%s.%.5u",
1395 constructor_p
? ".ctors" : ".dtors",
1396 /* Invert the numbering so the linker puts us in the proper
1397 order; constructors are run from right to left, and the
1398 linker sorts in increasing order. */
1399 MAX_INIT_PRIORITY
- priority
);
1400 return get_section (buf
, SECTION_WRITE
, NULL
);
1404 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1408 if (priority
!= DEFAULT_INIT_PRIORITY
)
1409 sec
= get_cdtor_priority_section (priority
,
1410 /*constructor_p=*/false);
1412 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1414 assemble_addr_to_section (symbol
, sec
);
1417 #ifdef DTORS_SECTION_ASM_OP
1419 default_dtor_section_asm_out_destructor (rtx symbol
,
1420 int priority ATTRIBUTE_UNUSED
)
1422 assemble_addr_to_section (symbol
, dtors_section
);
1426 /* Likewise for global constructors. */
1429 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
1430 int priority ATTRIBUTE_UNUSED
)
1432 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1433 /* Tell GNU LD that this is part of the static destructor set.
1434 This will work for any system that uses stabs, most usefully
1436 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1437 dbxout_stab_value_label (XSTR (symbol
, 0));
1439 sorry ("global constructors not supported on this target");
1444 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1448 if (priority
!= DEFAULT_INIT_PRIORITY
)
1449 sec
= get_cdtor_priority_section (priority
,
1450 /*constructor_p=*/true);
1452 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1454 assemble_addr_to_section (symbol
, sec
);
1457 #ifdef CTORS_SECTION_ASM_OP
1459 default_ctor_section_asm_out_constructor (rtx symbol
,
1460 int priority ATTRIBUTE_UNUSED
)
1462 assemble_addr_to_section (symbol
, ctors_section
);
1466 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1467 a nonzero value if the constant pool should be output before the
1468 start of the function, or a zero value if the pool should output
1469 after the end of the function. The default is to put it before the
1472 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1473 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1476 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1477 to be output to assembler.
1478 Set first_global_object_name and weak_global_object_name as appropriate. */
1481 notice_global_symbol (tree decl
)
1483 const char **type
= &first_global_object_name
;
1485 if (first_global_object_name
1486 || !TREE_PUBLIC (decl
)
1487 || DECL_EXTERNAL (decl
)
1488 || !DECL_NAME (decl
)
1489 || (TREE_CODE (decl
) != FUNCTION_DECL
1490 && (TREE_CODE (decl
) != VAR_DECL
1491 || (DECL_COMMON (decl
)
1492 && (DECL_INITIAL (decl
) == 0
1493 || DECL_INITIAL (decl
) == error_mark_node
))))
1494 || !MEM_P (DECL_RTL (decl
)))
1497 /* We win when global object is found, but it is useful to know about weak
1498 symbol as well so we can produce nicer unique names. */
1499 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1500 type
= &weak_global_object_name
;
1506 rtx decl_rtl
= DECL_RTL (decl
);
1508 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1509 name
= ggc_strdup (p
);
1515 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1516 current function goes into the cold section, so that targets can use
1517 current_function_section during RTL expansion. DECL describes the
1521 decide_function_section (tree decl
)
1523 first_function_block_is_cold
= false;
1525 if (flag_reorder_blocks_and_partition
)
1526 /* We will decide in assemble_start_function. */
1529 if (DECL_SECTION_NAME (decl
))
1531 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
1532 /* Calls to function_section rely on first_function_block_is_cold
1534 first_function_block_is_cold
= (node
1536 == NODE_FREQUENCY_UNLIKELY_EXECUTED
);
1539 in_cold_section_p
= first_function_block_is_cold
;
1542 /* Output assembler code for the constant pool of a function and associated
1543 with defining the name of the function. DECL describes the function.
1544 NAME is the function's name. For the constant pool, we use the current
1545 constant pool data. */
1548 assemble_start_function (tree decl
, const char *fnname
)
1551 char tmp_label
[100];
1552 bool hot_label_written
= false;
1554 if (flag_reorder_blocks_and_partition
)
1556 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1557 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1558 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1559 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1560 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1561 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1562 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1563 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1568 crtl
->subsections
.hot_section_label
= NULL
;
1569 crtl
->subsections
.cold_section_label
= NULL
;
1570 crtl
->subsections
.hot_section_end_label
= NULL
;
1571 crtl
->subsections
.cold_section_end_label
= NULL
;
1574 /* The following code does not need preprocessing in the assembler. */
1578 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1579 output_constant_pool (fnname
, decl
);
1581 /* Make sure the not and cold text (code) sections are properly
1582 aligned. This is necessary here in the case where the function
1583 has both hot and cold sections, because we don't want to re-set
1584 the alignment when the section switch happens mid-function. */
1586 if (flag_reorder_blocks_and_partition
)
1588 first_function_block_is_cold
= false;
1590 switch_to_section (unlikely_text_section ());
1591 assemble_align (DECL_ALIGN (decl
));
1592 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1594 /* When the function starts with a cold section, we need to explicitly
1595 align the hot section and write out the hot section label.
1596 But if the current function is a thunk, we do not have a CFG. */
1598 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1600 switch_to_section (text_section
);
1601 assemble_align (DECL_ALIGN (decl
));
1602 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1603 hot_label_written
= true;
1604 first_function_block_is_cold
= true;
1606 in_cold_section_p
= first_function_block_is_cold
;
1610 /* Switch to the correct text section for the start of the function. */
1612 switch_to_section (function_section (decl
));
1613 if (flag_reorder_blocks_and_partition
1614 && !hot_label_written
)
1615 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1617 /* Tell assembler to move to target machine's alignment for functions. */
1618 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1621 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1624 /* Handle a user-specified function alignment.
1625 Note that we still need to align to DECL_ALIGN, as above,
1626 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1627 if (! DECL_USER_ALIGN (decl
)
1628 && align_functions_log
> align
1629 && optimize_function_for_speed_p (cfun
))
1631 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1632 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1633 align_functions_log
, align_functions
- 1);
1635 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1639 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1640 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1643 if (!DECL_IGNORED_P (decl
))
1644 (*debug_hooks
->begin_function
) (decl
);
1646 /* Make function name accessible from other files, if appropriate. */
1648 if (TREE_PUBLIC (decl
))
1650 notice_global_symbol (decl
);
1652 globalize_decl (decl
);
1654 maybe_assemble_visibility (decl
);
1657 if (DECL_PRESERVE_P (decl
))
1658 targetm
.asm_out
.mark_decl_preserved (fnname
);
1660 /* Do any machine/system dependent processing of the function name. */
1661 #ifdef ASM_DECLARE_FUNCTION_NAME
1662 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1664 /* Standard thing is just output label for the function. */
1665 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1666 #endif /* ASM_DECLARE_FUNCTION_NAME */
1668 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1669 saw_no_split_stack
= true;
1672 /* Output assembler code associated with defining the size of the
1673 function. DECL describes the function. NAME is the function's name. */
1676 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1678 #ifdef ASM_DECLARE_FUNCTION_SIZE
1679 /* We could have switched section in the middle of the function. */
1680 if (flag_reorder_blocks_and_partition
)
1681 switch_to_section (function_section (decl
));
1682 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1684 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1686 output_constant_pool (fnname
, decl
);
1687 switch_to_section (function_section (decl
)); /* need to switch back */
1689 /* Output labels for end of hot/cold text sections (to be used by
1691 if (flag_reorder_blocks_and_partition
)
1693 section
*save_text_section
;
1695 save_text_section
= in_section
;
1696 switch_to_section (unlikely_text_section ());
1697 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1698 if (first_function_block_is_cold
)
1699 switch_to_section (text_section
);
1701 switch_to_section (function_section (decl
));
1702 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1703 switch_to_section (save_text_section
);
1707 /* Assemble code to leave SIZE bytes of zeros. */
1710 assemble_zeros (unsigned HOST_WIDE_INT size
)
1712 /* Do no output if -fsyntax-only. */
1713 if (flag_syntax_only
)
1716 #ifdef ASM_NO_SKIP_IN_TEXT
1717 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1718 so we must output 0s explicitly in the text section. */
1719 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1721 unsigned HOST_WIDE_INT i
;
1722 for (i
= 0; i
< size
; i
++)
1723 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1728 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1731 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1734 assemble_align (int align
)
1736 if (align
> BITS_PER_UNIT
)
1738 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1742 /* Assemble a string constant with the specified C string as contents. */
1745 assemble_string (const char *p
, int size
)
1750 /* If the string is very long, split it up. */
1754 int thissize
= size
- pos
;
1755 if (thissize
> maximum
)
1758 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1766 /* A noswitch_section_callback for lcomm_section. */
1769 emit_local (tree decl ATTRIBUTE_UNUSED
,
1770 const char *name ATTRIBUTE_UNUSED
,
1771 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1772 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1774 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1775 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1776 size
, DECL_ALIGN (decl
));
1778 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1779 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1782 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1787 /* A noswitch_section_callback for bss_noswitch_section. */
1789 #if defined ASM_OUTPUT_ALIGNED_BSS
1791 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1792 const char *name ATTRIBUTE_UNUSED
,
1793 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1794 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1796 #if defined ASM_OUTPUT_ALIGNED_BSS
1797 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
, DECL_ALIGN (decl
));
1803 /* A noswitch_section_callback for comm_section. */
1806 emit_common (tree decl ATTRIBUTE_UNUSED
,
1807 const char *name ATTRIBUTE_UNUSED
,
1808 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1809 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1811 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1812 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1813 size
, DECL_ALIGN (decl
));
1815 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1816 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1819 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1824 /* A noswitch_section_callback for tls_comm_section. */
1827 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1828 const char *name ATTRIBUTE_UNUSED
,
1829 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1830 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1832 #ifdef ASM_OUTPUT_TLS_COMMON
1833 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1836 sorry ("thread-local COMMON data not implemented");
1841 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1842 NAME is the name of DECL's SYMBOL_REF. */
1845 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
)
1847 unsigned HOST_WIDE_INT size
, rounded
;
1849 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1852 /* Don't allocate zero bytes of common,
1853 since that means "undefined external" in the linker. */
1857 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1858 so that each uninitialized object starts on such a boundary. */
1859 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1860 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1861 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1863 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
1864 && (unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
1865 warning (0, "requested alignment for %q+D is greater than "
1866 "implemented alignment of %wu", decl
, rounded
);
1869 /* A subroutine of assemble_variable. Output the label and contents of
1870 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1871 is as for assemble_variable. */
1874 assemble_variable_contents (tree decl
, const char *name
,
1875 bool dont_output_data
)
1877 /* Do any machine/system dependent processing of the object. */
1878 #ifdef ASM_DECLARE_OBJECT_NAME
1879 last_assemble_variable_decl
= decl
;
1880 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1882 /* Standard thing is just output label for the object. */
1883 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1884 #endif /* ASM_DECLARE_OBJECT_NAME */
1886 if (!dont_output_data
)
1888 if (DECL_INITIAL (decl
)
1889 && DECL_INITIAL (decl
) != error_mark_node
1890 && !initializer_zerop (DECL_INITIAL (decl
)))
1891 /* Output the actual data. */
1892 output_constant (DECL_INITIAL (decl
),
1893 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1896 /* Leave space for it. */
1897 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1901 /* Assemble everything that is needed for a variable or function declaration.
1902 Not used for automatic variables, and not used for function definitions.
1903 Should not be called for variables of incomplete structure type.
1905 TOP_LEVEL is nonzero if this variable has file scope.
1906 AT_END is nonzero if this is the special handling, at end of compilation,
1907 to define things that have had only tentative definitions.
1908 DONT_OUTPUT_DATA if nonzero means don't actually output the
1909 initial value (that will be done by the caller). */
1912 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
1913 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
1916 rtx decl_rtl
, symbol
;
1919 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1920 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
1922 /* Emulated TLS had better not get this far. */
1923 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
1925 last_assemble_variable_decl
= 0;
1927 /* Normally no need to say anything here for external references,
1928 since assemble_external is called by the language-specific code
1929 when a declaration is first seen. */
1931 if (DECL_EXTERNAL (decl
))
1934 /* Do nothing for global register variables. */
1935 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
1937 TREE_ASM_WRITTEN (decl
) = 1;
1941 /* If type was incomplete when the variable was declared,
1942 see if it is complete now. */
1944 if (DECL_SIZE (decl
) == 0)
1945 layout_decl (decl
, 0);
1947 /* Still incomplete => don't allocate it; treat the tentative defn
1948 (which is what it must have been) as an `extern' reference. */
1950 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1952 error ("storage size of %q+D isn%'t known", decl
);
1953 TREE_ASM_WRITTEN (decl
) = 1;
1957 /* The first declaration of a variable that comes through this function
1958 decides whether it is global (in C, has external linkage)
1959 or local (in C, has internal linkage). So do nothing more
1960 if this function has already run. */
1962 if (TREE_ASM_WRITTEN (decl
))
1965 /* Make sure targetm.encode_section_info is invoked before we set
1967 decl_rtl
= DECL_RTL (decl
);
1969 TREE_ASM_WRITTEN (decl
) = 1;
1971 /* Do no output if -fsyntax-only. */
1972 if (flag_syntax_only
)
1975 if (! dont_output_data
1976 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1978 error ("size of variable %q+D is too large", decl
);
1982 gcc_assert (MEM_P (decl_rtl
));
1983 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
1984 symbol
= XEXP (decl_rtl
, 0);
1986 /* If this symbol belongs to the tree constant pool, output the constant
1987 if it hasn't already been written. */
1988 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
1990 tree decl
= SYMBOL_REF_DECL (symbol
);
1991 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
1992 output_constant_def_contents (symbol
);
1998 name
= XSTR (symbol
, 0);
1999 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2000 notice_global_symbol (decl
);
2002 /* Compute the alignment of this data. */
2004 align_variable (decl
, dont_output_data
);
2005 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2007 if (TREE_PUBLIC (decl
))
2008 maybe_assemble_visibility (decl
);
2010 if (DECL_PRESERVE_P (decl
))
2011 targetm
.asm_out
.mark_decl_preserved (name
);
2013 /* First make the assembler name(s) global if appropriate. */
2014 sect
= get_variable_section (decl
, false);
2015 if (TREE_PUBLIC (decl
)
2016 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2017 globalize_decl (decl
);
2019 /* Output any data that we will need to use the address of. */
2020 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2021 output_addressed_constants (DECL_INITIAL (decl
));
2023 /* dbxout.c needs to know this. */
2024 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2025 DECL_IN_TEXT_SECTION (decl
) = 1;
2027 /* If the decl is part of an object_block, make sure that the decl
2028 has been positioned within its block, but do not write out its
2029 definition yet. output_object_blocks will do that later. */
2030 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2032 gcc_assert (!dont_output_data
);
2033 place_block_symbol (symbol
);
2035 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2036 assemble_noswitch_variable (decl
, name
, sect
);
2039 switch_to_section (sect
);
2040 if (DECL_ALIGN (decl
) > BITS_PER_UNIT
)
2041 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
2042 assemble_variable_contents (decl
, name
, dont_output_data
);
2046 /* Return 1 if type TYPE contains any pointers. */
2049 contains_pointers_p (tree type
)
2051 switch (TREE_CODE (type
))
2054 case REFERENCE_TYPE
:
2055 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2056 so I'll play safe and return 1. */
2062 case QUAL_UNION_TYPE
:
2065 /* For a type that has fields, see if the fields have pointers. */
2066 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
2067 if (TREE_CODE (fields
) == FIELD_DECL
2068 && contains_pointers_p (TREE_TYPE (fields
)))
2074 /* An array type contains pointers if its element type does. */
2075 return contains_pointers_p (TREE_TYPE (type
));
2082 /* We delay assemble_external processing until
2083 the compilation unit is finalized. This is the best we can do for
2084 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2085 it all the way to final. See PR 17982 for further discussion. */
2086 static GTY(()) tree pending_assemble_externals
;
2088 #ifdef ASM_OUTPUT_EXTERNAL
2089 /* True if DECL is a function decl for which no out-of-line copy exists.
2090 It is assumed that DECL's assembler name has been set. */
2093 incorporeal_function_p (tree decl
)
2095 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2099 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2100 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
2103 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2104 if (is_builtin_name (name
))
2110 /* Actually do the tests to determine if this is necessary, and invoke
2111 ASM_OUTPUT_EXTERNAL. */
2113 assemble_external_real (tree decl
)
2115 rtx rtl
= DECL_RTL (decl
);
2117 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2118 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2119 && !incorporeal_function_p (decl
))
2121 /* Some systems do require some output. */
2122 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2123 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2129 process_pending_assemble_externals (void)
2131 #ifdef ASM_OUTPUT_EXTERNAL
2133 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2134 assemble_external_real (TREE_VALUE (list
));
2136 pending_assemble_externals
= 0;
2140 /* This TREE_LIST contains any weak symbol declarations waiting
2142 static GTY(()) tree weak_decls
;
2144 /* Output something to declare an external symbol to the assembler,
2145 and qualifiers such as weakness. (Most assemblers don't need
2146 extern declaration, so we normally output nothing.) Do nothing if
2147 DECL is not external. */
2150 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2152 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2153 main body of this code is only rarely exercised. To provide some
2154 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2155 open. If it's not, we should not be calling this function. */
2156 gcc_assert (asm_out_file
);
2158 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2161 /* We want to output annotation for weak and external symbols at
2162 very last to check if they are references or not. */
2164 if (TARGET_SUPPORTS_WEAK
2166 /* TREE_STATIC is a weird and abused creature which is not
2167 generally the right test for whether an entity has been
2168 locally emitted, inlined or otherwise not-really-extern, but
2169 for declarations that can be weak, it happens to be
2171 && !TREE_STATIC (decl
)
2172 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2173 && value_member (decl
, weak_decls
) == NULL_TREE
)
2174 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2176 #ifdef ASM_OUTPUT_EXTERNAL
2177 if (value_member (decl
, pending_assemble_externals
) == NULL_TREE
)
2178 pending_assemble_externals
= tree_cons (NULL
, decl
,
2179 pending_assemble_externals
);
2183 /* Similar, for calling a library function FUN. */
2186 assemble_external_libcall (rtx fun
)
2188 /* Declare library function name external when first used, if nec. */
2189 if (! SYMBOL_REF_USED (fun
))
2191 SYMBOL_REF_USED (fun
) = 1;
2192 targetm
.asm_out
.external_libcall (fun
);
2196 /* Assemble a label named NAME. */
2199 assemble_label (FILE *file
, const char *name
)
2201 ASM_OUTPUT_LABEL (file
, name
);
2204 /* Set the symbol_referenced flag for ID. */
2206 mark_referenced (tree id
)
2208 TREE_SYMBOL_REFERENCED (id
) = 1;
2211 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2213 mark_decl_referenced (tree decl
)
2215 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2217 /* Extern inline functions don't become needed when referenced.
2218 If we know a method will be emitted in other TU and no new
2219 functions can be marked reachable, just use the external
2221 struct cgraph_node
*node
= cgraph_get_create_node (decl
);
2222 if (!DECL_EXTERNAL (decl
)
2223 && !node
->local
.finalized
)
2224 cgraph_mark_needed_node (node
);
2226 else if (TREE_CODE (decl
) == VAR_DECL
)
2228 struct varpool_node
*node
= varpool_node (decl
);
2229 varpool_mark_needed_node (node
);
2230 /* C++ frontend use mark_decl_references to force COMDAT variables
2231 to be output that might appear dead otherwise. */
2232 node
->force_output
= true;
2234 /* else do nothing - we can get various sorts of CST nodes here,
2235 which do not need to be marked. */
2239 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2240 until we find an identifier that is not itself a transparent alias.
2241 Modify the alias passed to it by reference (and all aliases on the
2242 way to the ultimate target), such that they do not have to be
2243 followed again, and return the ultimate target of the alias
2247 ultimate_transparent_alias_target (tree
*alias
)
2249 tree target
= *alias
;
2251 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2253 gcc_assert (TREE_CHAIN (target
));
2254 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2255 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2256 && ! TREE_CHAIN (target
));
2263 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2264 starts with a *, the rest of NAME is output verbatim. Otherwise
2265 NAME is transformed in a target-specific way (usually by the
2266 addition of an underscore). */
2269 assemble_name_raw (FILE *file
, const char *name
)
2272 fputs (&name
[1], file
);
2274 ASM_OUTPUT_LABELREF (file
, name
);
2277 /* Like assemble_name_raw, but should be used when NAME might refer to
2278 an entity that is also represented as a tree (like a function or
2279 variable). If NAME does refer to such an entity, that entity will
2280 be marked as referenced. */
2283 assemble_name (FILE *file
, const char *name
)
2285 const char *real_name
;
2288 real_name
= targetm
.strip_name_encoding (name
);
2290 id
= maybe_get_identifier (real_name
);
2295 mark_referenced (id
);
2296 ultimate_transparent_alias_target (&id
);
2298 name
= IDENTIFIER_POINTER (id
);
2301 assemble_name_raw (file
, name
);
2304 /* Allocate SIZE bytes writable static space with a gensym name
2305 and return an RTX to refer to its address. */
2308 assemble_static_space (unsigned HOST_WIDE_INT size
)
2311 const char *namestring
;
2314 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2316 namestring
= ggc_strdup (name
);
2318 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2319 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2321 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2322 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2325 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2326 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2329 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2330 so that each uninitialized object starts on such a boundary. */
2331 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2332 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2333 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2334 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2335 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2336 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2343 /* Assemble the static constant template for function entry trampolines.
2344 This is done at most once per compilation.
2345 Returns an RTX for the address of the template. */
2347 static GTY(()) rtx initial_trampoline
;
2350 assemble_trampoline_template (void)
2357 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2359 if (initial_trampoline
)
2360 return initial_trampoline
;
2362 /* By default, put trampoline templates in read-only data section. */
2364 #ifdef TRAMPOLINE_SECTION
2365 switch_to_section (TRAMPOLINE_SECTION
);
2367 switch_to_section (readonly_data_section
);
2370 /* Write the assembler code to define one. */
2371 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2373 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2375 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2376 targetm
.asm_out
.trampoline_template (asm_out_file
);
2378 /* Record the rtl to refer to it. */
2379 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2380 name
= ggc_strdup (label
);
2381 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2382 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2384 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2385 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2386 set_mem_size (initial_trampoline
, GEN_INT (TRAMPOLINE_SIZE
));
2388 return initial_trampoline
;
2391 /* A and B are either alignments or offsets. Return the minimum alignment
2392 that may be assumed after adding the two together. */
2394 static inline unsigned
2395 min_align (unsigned int a
, unsigned int b
)
2397 return (a
| b
) & -(a
| b
);
2400 /* Return the assembler directive for creating a given kind of integer
2401 object. SIZE is the number of bytes in the object and ALIGNED_P
2402 indicates whether it is known to be aligned. Return NULL if the
2403 assembly dialect has no such directive.
2405 The returned string should be printed at the start of a new line and
2406 be followed immediately by the object's initial value. */
2409 integer_asm_op (int size
, int aligned_p
)
2411 struct asm_int_op
*ops
;
2414 ops
= &targetm
.asm_out
.aligned_op
;
2416 ops
= &targetm
.asm_out
.unaligned_op
;
2421 return targetm
.asm_out
.byte_op
;
2435 /* Use directive OP to assemble an integer object X. Print OP at the
2436 start of the line, followed immediately by the value of X. */
2439 assemble_integer_with_op (const char *op
, rtx x
)
2441 fputs (op
, asm_out_file
);
2442 output_addr_const (asm_out_file
, x
);
2443 fputc ('\n', asm_out_file
);
2446 /* The default implementation of the asm_out.integer target hook. */
2449 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2450 unsigned int size ATTRIBUTE_UNUSED
,
2451 int aligned_p ATTRIBUTE_UNUSED
)
2453 const char *op
= integer_asm_op (size
, aligned_p
);
2454 /* Avoid GAS bugs for large values. Specifically negative values whose
2455 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2456 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2458 return op
&& (assemble_integer_with_op (op
, x
), true);
2461 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2462 the alignment of the integer in bits. Return 1 if we were able to output
2463 the constant, otherwise 0. We must be able to output the constant,
2464 if FORCE is nonzero. */
2467 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2471 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2473 /* See if the target hook can handle this kind of object. */
2474 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2477 /* If the object is a multi-byte one, try splitting it up. Split
2478 it into words it if is multi-word, otherwise split it into bytes. */
2481 enum machine_mode omode
, imode
;
2482 unsigned int subalign
;
2483 unsigned int subsize
, i
;
2484 enum mode_class mclass
;
2486 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2487 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2488 if (GET_CODE (x
) == CONST_FIXED
)
2489 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2493 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2494 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2496 for (i
= 0; i
< size
; i
+= subsize
)
2498 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2499 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2505 /* If we've printed some of it, but not all of it, there's no going
2510 gcc_assert (!force
);
2516 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2518 long data
[4] = {0, 0, 0, 0};
2520 int bitsize
, nelts
, nunits
, units_per
;
2522 /* This is hairy. We have a quantity of known size. real_to_target
2523 will put it into an array of *host* longs, 32 bits per element
2524 (even if long is more than 32 bits). We need to determine the
2525 number of array elements that are occupied (nelts) and the number
2526 of *target* min-addressable units that will be occupied in the
2527 object file (nunits). We cannot assume that 32 divides the
2528 mode's bitsize (size * BITS_PER_UNIT) evenly.
2530 size * BITS_PER_UNIT is used here to make sure that padding bits
2531 (which might appear at either end of the value; real_to_target
2532 will include the padding bits in its output array) are included. */
2534 nunits
= GET_MODE_SIZE (mode
);
2535 bitsize
= nunits
* BITS_PER_UNIT
;
2536 nelts
= CEIL (bitsize
, 32);
2537 units_per
= 32 / BITS_PER_UNIT
;
2539 real_to_target (data
, &d
, mode
);
2541 /* Put out the first word with the specified alignment. */
2542 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2543 nunits
-= units_per
;
2545 /* Subsequent words need only 32-bit alignment. */
2546 align
= min_align (align
, 32);
2548 for (i
= 1; i
< nelts
; i
++)
2550 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2551 nunits
-= units_per
;
2555 /* Given an expression EXP with a constant value,
2556 reduce it to the sum of an assembler symbol and an integer.
2557 Store them both in the structure *VALUE.
2558 EXP must be reducible. */
2562 HOST_WIDE_INT offset
;
2566 decode_addr_const (tree exp
, struct addr_const
*value
)
2568 tree target
= TREE_OPERAND (exp
, 0);
2574 if (TREE_CODE (target
) == COMPONENT_REF
2575 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2577 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2578 target
= TREE_OPERAND (target
, 0);
2580 else if (TREE_CODE (target
) == ARRAY_REF
2581 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2583 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2584 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2585 target
= TREE_OPERAND (target
, 0);
2587 else if (TREE_CODE (target
) == INDIRECT_REF
2588 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2589 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2591 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2596 switch (TREE_CODE (target
))
2600 x
= DECL_RTL (target
);
2604 x
= gen_rtx_MEM (FUNCTION_MODE
,
2605 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2614 x
= output_constant_def (target
, 1);
2621 gcc_assert (MEM_P (x
));
2625 value
->offset
= offset
;
2629 static GTY((param_is (struct constant_descriptor_tree
)))
2630 htab_t const_desc_htab
;
2632 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2634 /* Constant pool accessor function. */
2637 constant_pool_htab (void)
2639 return const_desc_htab
;
2642 /* Compute a hash code for a constant expression. */
2645 const_desc_hash (const void *ptr
)
2647 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2651 const_hash_1 (const tree exp
)
2656 enum tree_code code
= TREE_CODE (exp
);
2658 /* Either set P and LEN to the address and len of something to hash and
2659 exit the switch or return a value. */
2664 p
= (char *) &TREE_INT_CST (exp
);
2665 len
= sizeof TREE_INT_CST (exp
);
2669 return real_hash (TREE_REAL_CST_PTR (exp
));
2672 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2675 p
= TREE_STRING_POINTER (exp
);
2676 len
= TREE_STRING_LENGTH (exp
);
2680 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2681 + const_hash_1 (TREE_IMAGPART (exp
)));
2687 hi
= 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
));
2689 for (link
= TREE_VECTOR_CST_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2690 hi
= hi
* 563 + const_hash_1 (TREE_VALUE (link
));
2697 unsigned HOST_WIDE_INT idx
;
2700 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2702 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2704 hi
= hi
* 603 + const_hash_1 (value
);
2712 struct addr_const value
;
2714 decode_addr_const (exp
, &value
);
2715 switch (GET_CODE (value
.base
))
2718 /* Don't hash the address of the SYMBOL_REF;
2719 only use the offset and the symbol name. */
2721 p
= XSTR (value
.base
, 0);
2722 for (i
= 0; p
[i
] != 0; i
++)
2723 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2727 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2737 case POINTER_PLUS_EXPR
:
2739 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2740 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2743 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2746 /* A language specific constant. Just hash the code. */
2750 /* Compute hashing function. */
2752 for (i
= 0; i
< len
; i
++)
2753 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2758 /* Wrapper of compare_constant, for the htab interface. */
2760 const_desc_eq (const void *p1
, const void *p2
)
2762 const struct constant_descriptor_tree
*const c1
2763 = (const struct constant_descriptor_tree
*) p1
;
2764 const struct constant_descriptor_tree
*const c2
2765 = (const struct constant_descriptor_tree
*) p2
;
2766 if (c1
->hash
!= c2
->hash
)
2768 return compare_constant (c1
->value
, c2
->value
);
2771 /* Compare t1 and t2, and return 1 only if they are known to result in
2772 the same bit pattern on output. */
2775 compare_constant (const tree t1
, const tree t2
)
2777 enum tree_code typecode
;
2779 if (t1
== NULL_TREE
)
2780 return t2
== NULL_TREE
;
2781 if (t2
== NULL_TREE
)
2784 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2787 switch (TREE_CODE (t1
))
2790 /* Integer constants are the same only if the same width of type. */
2791 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2793 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2795 return tree_int_cst_equal (t1
, t2
);
2798 /* Real constants are the same only if the same width of type. */
2799 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2802 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2805 /* Fixed constants are the same only if the same width of type. */
2806 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2809 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
2812 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2815 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2816 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2817 TREE_STRING_LENGTH (t1
)));
2820 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2821 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2827 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1
))
2828 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2
)))
2831 link2
= TREE_VECTOR_CST_ELTS (t2
);
2832 for (link1
= TREE_VECTOR_CST_ELTS (t1
);
2834 link1
= TREE_CHAIN (link1
))
2836 if (!compare_constant (TREE_VALUE (link1
), TREE_VALUE (link2
)))
2838 link2
= TREE_CHAIN (link2
);
2846 VEC(constructor_elt
, gc
) *v1
, *v2
;
2847 unsigned HOST_WIDE_INT idx
;
2849 typecode
= TREE_CODE (TREE_TYPE (t1
));
2850 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
2853 if (typecode
== ARRAY_TYPE
)
2855 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
2856 /* For arrays, check that the sizes all match. */
2857 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
2859 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
2864 /* For record and union constructors, require exact type
2866 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
2870 v1
= CONSTRUCTOR_ELTS (t1
);
2871 v2
= CONSTRUCTOR_ELTS (t2
);
2872 if (VEC_length (constructor_elt
, v1
)
2873 != VEC_length (constructor_elt
, v2
))
2876 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
2878 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
2879 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
2881 /* Check that each value is the same... */
2882 if (!compare_constant (c1
->value
, c2
->value
))
2884 /* ... and that they apply to the same fields! */
2885 if (typecode
== ARRAY_TYPE
)
2887 if (!compare_constant (c1
->index
, c2
->index
))
2892 if (c1
->index
!= c2
->index
)
2903 struct addr_const value1
, value2
;
2907 decode_addr_const (t1
, &value1
);
2908 decode_addr_const (t2
, &value2
);
2910 if (value1
.offset
!= value2
.offset
)
2913 code
= GET_CODE (value1
.base
);
2914 if (code
!= GET_CODE (value2
.base
))
2920 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
2924 ret
= (CODE_LABEL_NUMBER (XEXP (value1
.base
, 0))
2925 == CODE_LABEL_NUMBER (XEXP (value2
.base
, 0)));
2935 case POINTER_PLUS_EXPR
:
2938 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2939 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2942 case VIEW_CONVERT_EXPR
:
2943 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2952 /* Make a copy of the whole tree structure for a constant. This
2953 handles the same types of nodes that compare_constant handles. */
2956 copy_constant (tree exp
)
2958 switch (TREE_CODE (exp
))
2961 /* For ADDR_EXPR, we do not want to copy the decl whose address
2962 is requested. We do want to copy constants though. */
2963 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
2964 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2965 copy_constant (TREE_OPERAND (exp
, 0)));
2967 return copy_node (exp
);
2973 return copy_node (exp
);
2976 return build_complex (TREE_TYPE (exp
),
2977 copy_constant (TREE_REALPART (exp
)),
2978 copy_constant (TREE_IMAGPART (exp
)));
2981 case POINTER_PLUS_EXPR
:
2983 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
2984 copy_constant (TREE_OPERAND (exp
, 0)),
2985 copy_constant (TREE_OPERAND (exp
, 1)));
2988 case VIEW_CONVERT_EXPR
:
2989 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2990 copy_constant (TREE_OPERAND (exp
, 0)));
2993 return build_vector (TREE_TYPE (exp
),
2994 copy_list (TREE_VECTOR_CST_ELTS (exp
)));
2998 tree copy
= copy_node (exp
);
2999 VEC(constructor_elt
, gc
) *v
;
3000 unsigned HOST_WIDE_INT idx
;
3001 tree purpose
, value
;
3003 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
3004 CONSTRUCTOR_ELTS (exp
)));
3005 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
3007 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
3008 ce
->index
= purpose
;
3009 ce
->value
= copy_constant (value
);
3011 CONSTRUCTOR_ELTS (copy
) = v
;
3020 /* Return the section into which constant EXP should be placed. */
3023 get_constant_section (tree exp
, unsigned int align
)
3025 return targetm
.asm_out
.select_section (exp
,
3026 compute_reloc_for_constant (exp
),
3030 /* Return the size of constant EXP in bytes. */
3032 static HOST_WIDE_INT
3033 get_constant_size (tree exp
)
3037 size
= int_size_in_bytes (TREE_TYPE (exp
));
3038 if (TREE_CODE (exp
) == STRING_CST
)
3039 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3043 /* Subroutine of output_constant_def:
3044 No constant equal to EXP is known to have been output.
3045 Make a constant descriptor to enter EXP in the hash table.
3046 Assign the label number and construct RTL to refer to the
3047 constant's location in memory.
3048 Caller is responsible for updating the hash table. */
3050 static struct constant_descriptor_tree
*
3051 build_constant_desc (tree exp
)
3053 struct constant_descriptor_tree
*desc
;
3059 desc
= ggc_alloc_constant_descriptor_tree ();
3060 desc
->value
= copy_constant (exp
);
3062 /* Propagate marked-ness to copied constant. */
3063 if (flag_mudflap
&& mf_marked_p (exp
))
3064 mf_mark (desc
->value
);
3066 /* Create a string containing the label name, in LABEL. */
3067 labelno
= const_labelno
++;
3068 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3070 /* Construct the VAR_DECL associated with the constant. */
3071 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3073 DECL_ARTIFICIAL (decl
) = 1;
3074 DECL_IGNORED_P (decl
) = 1;
3075 TREE_READONLY (decl
) = 1;
3076 TREE_STATIC (decl
) = 1;
3077 TREE_ADDRESSABLE (decl
) = 1;
3078 /* We don't set the RTL yet as this would cause varpool to assume that the
3079 variable is referenced. Moreover, it would just be dropped in LTO mode.
3080 Instead we set the flag that will be recognized in make_decl_rtl. */
3081 DECL_IN_CONSTANT_POOL (decl
) = 1;
3082 DECL_INITIAL (decl
) = desc
->value
;
3083 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3084 architectures so use DATA_ALIGNMENT as well, except for strings. */
3085 if (TREE_CODE (exp
) == STRING_CST
)
3087 #ifdef CONSTANT_ALIGNMENT
3088 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
3092 align_variable (decl
, 0);
3094 /* Now construct the SYMBOL_REF and the MEM. */
3095 if (use_object_blocks_p ())
3097 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
3098 symbol
= create_block_symbol (ggc_strdup (label
),
3099 get_block_for_section (sect
), -1);
3102 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3103 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3104 SET_SYMBOL_REF_DECL (symbol
, decl
);
3105 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3107 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3108 set_mem_attributes (rtl
, exp
, 1);
3109 set_mem_alias_set (rtl
, 0);
3110 set_mem_alias_set (rtl
, const_alias_set
);
3112 /* We cannot share RTX'es in pool entries.
3113 Mark this piece of RTL as required for unsharing. */
3114 RTX_FLAG (rtl
, used
) = 1;
3116 /* Set flags or add text to the name to record information, such as
3117 that it is a local symbol. If the name is changed, the macro
3118 ASM_OUTPUT_LABELREF will have to know how to strip this
3119 information. This call might invalidate our local variable
3120 SYMBOL; we can't use it afterward. */
3121 targetm
.encode_section_info (exp
, rtl
, true);
3128 /* Return an rtx representing a reference to constant data in memory
3129 for the constant expression EXP.
3131 If assembler code for such a constant has already been output,
3132 return an rtx to refer to it.
3133 Otherwise, output such a constant in memory
3134 and generate an rtx for it.
3136 If DEFER is nonzero, this constant can be deferred and output only
3137 if referenced in the function after all optimizations.
3139 `const_desc_table' records which constants already have label strings. */
3142 output_constant_def (tree exp
, int defer
)
3144 struct constant_descriptor_tree
*desc
;
3145 struct constant_descriptor_tree key
;
3148 /* Look up EXP in the table of constant descriptors. If we didn't find
3149 it, create a new one. */
3151 key
.hash
= const_hash_1 (exp
);
3152 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3154 desc
= (struct constant_descriptor_tree
*) *loc
;
3157 desc
= build_constant_desc (exp
);
3158 desc
->hash
= key
.hash
;
3162 maybe_output_constant_def_contents (desc
, defer
);
3166 /* Subroutine of output_constant_def: Decide whether or not we need to
3167 output the constant DESC now, and if so, do it. */
3169 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3172 rtx symbol
= XEXP (desc
->rtl
, 0);
3173 tree exp
= desc
->value
;
3175 if (flag_syntax_only
)
3178 if (TREE_ASM_WRITTEN (exp
))
3179 /* Already output; don't do it again. */
3182 /* We can always defer constants as long as the context allows
3186 /* Increment n_deferred_constants if it exists. It needs to be at
3187 least as large as the number of constants actually referred to
3188 by the function. If it's too small we'll stop looking too early
3189 and fail to emit constants; if it's too large we'll only look
3190 through the entire function when we could have stopped earlier. */
3192 n_deferred_constants
++;
3196 output_constant_def_contents (symbol
);
3199 /* Subroutine of output_constant_def_contents. Output the definition
3200 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3201 constant's alignment in bits. */
3204 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3208 size
= get_constant_size (exp
);
3210 /* Do any machine/system dependent processing of the constant. */
3211 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3213 /* Output the value of EXP. */
3214 output_constant (exp
, size
, align
);
3217 /* We must output the constant data referred to by SYMBOL; do so. */
3220 output_constant_def_contents (rtx symbol
)
3222 tree decl
= SYMBOL_REF_DECL (symbol
);
3223 tree exp
= DECL_INITIAL (decl
);
3226 /* Make sure any other constants whose addresses appear in EXP
3227 are assigned label numbers. */
3228 output_addressed_constants (exp
);
3230 /* We are no longer deferring this constant. */
3231 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3233 /* If the constant is part of an object block, make sure that the
3234 decl has been positioned within its block, but do not write out
3235 its definition yet. output_object_blocks will do that later. */
3236 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3237 place_block_symbol (symbol
);
3240 align
= DECL_ALIGN (decl
);
3241 switch_to_section (get_constant_section (exp
, align
));
3242 if (align
> BITS_PER_UNIT
)
3243 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3244 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3247 mudflap_enqueue_constant (exp
);
3250 /* Look up EXP in the table of constant descriptors. Return the rtl
3251 if it has been emitted, else null. */
3254 lookup_constant_def (tree exp
)
3256 struct constant_descriptor_tree
*desc
;
3257 struct constant_descriptor_tree key
;
3260 key
.hash
= const_hash_1 (exp
);
3261 desc
= (struct constant_descriptor_tree
*)
3262 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3264 return (desc
? desc
->rtl
: NULL_RTX
);
3267 /* Return a tree representing a reference to constant data in memory
3268 for the constant expression EXP.
3270 This is the counterpart of output_constant_def at the Tree level. */
3273 tree_output_constant_def (tree exp
)
3275 struct constant_descriptor_tree
*desc
, key
;
3279 /* Look up EXP in the table of constant descriptors. If we didn't find
3280 it, create a new one. */
3282 key
.hash
= const_hash_1 (exp
);
3283 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3285 desc
= (struct constant_descriptor_tree
*) *loc
;
3288 desc
= build_constant_desc (exp
);
3289 desc
->hash
= key
.hash
;
3293 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3294 varpool_finalize_decl (decl
);
3298 /* Used in the hash tables to avoid outputting the same constant
3299 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3300 are output once per function, not once per file. */
3301 /* ??? Only a few targets need per-function constant pools. Most
3302 can use one per-file pool. Should add a targetm bit to tell the
3305 struct GTY(()) rtx_constant_pool
{
3306 /* Pointers to first and last constant in pool, as ordered by offset. */
3307 struct constant_descriptor_rtx
*first
;
3308 struct constant_descriptor_rtx
*last
;
3310 /* Hash facility for making memory-constants from constant rtl-expressions.
3311 It is used on RISC machines where immediate integer arguments and
3312 constant addresses are restricted so that such constants must be stored
3314 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3316 /* Current offset in constant pool (does not include any
3317 machine-specific header). */
3318 HOST_WIDE_INT offset
;
3321 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3322 struct constant_descriptor_rtx
*next
;
3326 HOST_WIDE_INT offset
;
3328 enum machine_mode mode
;
3334 /* Hash and compare functions for const_rtx_htab. */
3337 const_desc_rtx_hash (const void *ptr
)
3339 const struct constant_descriptor_rtx
*const desc
3340 = (const struct constant_descriptor_rtx
*) ptr
;
3345 const_desc_rtx_eq (const void *a
, const void *b
)
3347 const struct constant_descriptor_rtx
*const x
3348 = (const struct constant_descriptor_rtx
*) a
;
3349 const struct constant_descriptor_rtx
*const y
3350 = (const struct constant_descriptor_rtx
*) b
;
3352 if (x
->mode
!= y
->mode
)
3354 return rtx_equal_p (x
->constant
, y
->constant
);
3357 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3360 const_rtx_hash_1 (rtx
*xp
, void *data
)
3362 unsigned HOST_WIDE_INT hwi
;
3363 enum machine_mode mode
;
3369 code
= GET_CODE (x
);
3370 mode
= GET_MODE (x
);
3371 h
= (hashval_t
) code
* 1048573 + mode
;
3379 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3380 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3383 h
^= (hashval_t
) hwi
;
3384 for (i
= 1; i
< n
; ++i
)
3387 h
^= (hashval_t
) hwi
;
3393 if (mode
== VOIDmode
)
3395 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3399 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3403 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3409 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3410 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3415 h
^= htab_hash_string (XSTR (x
, 0));
3419 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3423 case UNSPEC_VOLATILE
:
3424 h
= h
* 251 + XINT (x
, 1);
3431 hp
= (hashval_t
*) data
;
3432 *hp
= *hp
* 509 + h
;
3436 /* Compute a hash value for X, which should be a constant. */
3439 const_rtx_hash (rtx x
)
3442 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3447 /* Create and return a new rtx constant pool. */
3449 static struct rtx_constant_pool
*
3450 create_constant_pool (void)
3452 struct rtx_constant_pool
*pool
;
3454 pool
= ggc_alloc_rtx_constant_pool ();
3455 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3456 const_desc_rtx_eq
, NULL
);
3463 /* Initialize constant pool hashing for a new function. */
3466 init_varasm_status (void)
3468 crtl
->varasm
.pool
= create_constant_pool ();
3469 crtl
->varasm
.deferred_constants
= 0;
3472 /* Given a MINUS expression, simplify it if both sides
3473 include the same symbol. */
3476 simplify_subtraction (rtx x
)
3478 rtx r
= simplify_rtx (x
);
3482 /* Given a constant rtx X, make (or find) a memory constant for its value
3483 and return a MEM rtx to refer to it in memory. */
3486 force_const_mem (enum machine_mode mode
, rtx x
)
3488 struct constant_descriptor_rtx
*desc
, tmp
;
3489 struct rtx_constant_pool
*pool
;
3496 /* If we're not allowed to drop X into the constant pool, don't. */
3497 if (targetm
.cannot_force_const_mem (mode
, x
))
3500 /* Record that this function has used a constant pool entry. */
3501 crtl
->uses_const_pool
= 1;
3503 /* Decide which pool to use. */
3504 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3505 ? shared_constant_pool
3506 : crtl
->varasm
.pool
);
3508 /* Lookup the value in the hashtable. */
3511 hash
= const_rtx_hash (x
);
3512 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3513 desc
= (struct constant_descriptor_rtx
*) *slot
;
3515 /* If the constant was already present, return its memory. */
3517 return copy_rtx (desc
->mem
);
3519 /* Otherwise, create a new descriptor. */
3520 desc
= ggc_alloc_constant_descriptor_rtx ();
3523 /* Align the location counter as required by EXP's data type. */
3524 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3525 #ifdef CONSTANT_ALIGNMENT
3527 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3528 if (type
!= NULL_TREE
)
3529 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3533 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3534 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3537 desc
->constant
= copy_rtx (tmp
.constant
);
3538 desc
->offset
= pool
->offset
;
3541 desc
->align
= align
;
3542 desc
->labelno
= const_labelno
;
3545 pool
->offset
+= GET_MODE_SIZE (mode
);
3547 pool
->last
->next
= desc
;
3549 pool
->first
= pool
->last
= desc
;
3552 /* Create a string containing the label name, in LABEL. */
3553 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3556 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3557 the constants pool. */
3558 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3560 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3561 symbol
= create_block_symbol (ggc_strdup (label
),
3562 get_block_for_section (sect
), -1);
3565 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3567 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3568 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3569 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3571 /* Construct the MEM. */
3572 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3573 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3574 set_mem_align (def
, align
);
3576 /* If we're dropping a label to the constant pool, make sure we
3578 if (GET_CODE (x
) == LABEL_REF
)
3579 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3581 return copy_rtx (def
);
3584 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3587 get_pool_constant (rtx addr
)
3589 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3592 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3593 and whether it has been output or not. */
3596 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3598 struct constant_descriptor_rtx
*desc
;
3600 desc
= SYMBOL_REF_CONSTANT (addr
);
3601 *pmarked
= (desc
->mark
!= 0);
3602 return desc
->constant
;
3605 /* Similar, return the mode. */
3608 get_pool_mode (const_rtx addr
)
3610 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3613 /* Return the size of the constant pool. */
3616 get_pool_size (void)
3618 return crtl
->varasm
.pool
->offset
;
3621 /* Worker function for output_constant_pool_1. Emit assembly for X
3622 in MODE with known alignment ALIGN. */
3625 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3627 switch (GET_MODE_CLASS (mode
))
3630 case MODE_DECIMAL_FLOAT
:
3634 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3635 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3636 assemble_real (r
, mode
, align
);
3641 case MODE_PARTIAL_INT
:
3646 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3649 case MODE_VECTOR_FLOAT
:
3650 case MODE_VECTOR_INT
:
3651 case MODE_VECTOR_FRACT
:
3652 case MODE_VECTOR_UFRACT
:
3653 case MODE_VECTOR_ACCUM
:
3654 case MODE_VECTOR_UACCUM
:
3657 enum machine_mode submode
= GET_MODE_INNER (mode
);
3658 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3660 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3661 units
= CONST_VECTOR_NUNITS (x
);
3663 for (i
= 0; i
< units
; i
++)
3665 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3666 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3676 /* Worker function for output_constant_pool. Emit constant DESC,
3677 giving it ALIGN bits of alignment. */
3680 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3687 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3688 whose CODE_LABEL has been deleted. This can occur if a jump table
3689 is eliminated by optimization. If so, write a constant of zero
3690 instead. Note that this can also happen by turning the
3691 CODE_LABEL into a NOTE. */
3692 /* ??? This seems completely and utterly wrong. Certainly it's
3693 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3694 functioning even with INSN_DELETED_P and friends. */
3697 switch (GET_CODE (tmp
))
3700 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3701 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3703 tmp
= XEXP (XEXP (tmp
, 0), 0);
3707 tmp
= XEXP (tmp
, 0);
3708 gcc_assert (!INSN_DELETED_P (tmp
));
3709 gcc_assert (!NOTE_P (tmp
)
3710 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3717 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3718 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3719 align
, desc
->labelno
, done
);
3722 assemble_align (align
);
3724 /* Output the label. */
3725 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3727 /* Output the data. */
3728 output_constant_pool_2 (desc
->mode
, x
, align
);
3730 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3731 sections have proper size. */
3732 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3734 && (in_section
->common
.flags
& SECTION_MERGE
))
3735 assemble_align (align
);
3737 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3743 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3744 to as used. Emit referenced deferred strings. This function can
3745 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3748 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
3750 rtx x
= *current_rtx
;
3752 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3755 if (CONSTANT_POOL_ADDRESS_P (x
))
3757 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3758 if (desc
->mark
== 0)
3761 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
3764 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3766 tree decl
= SYMBOL_REF_DECL (x
);
3767 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
3769 n_deferred_constants
--;
3770 output_constant_def_contents (x
);
3777 /* Look through appropriate parts of INSN, marking all entries in the
3778 constant pool which are actually being used. Entries that are only
3779 referenced by other constants are also marked as used. Emit
3780 deferred strings that are used. */
3783 mark_constants (rtx insn
)
3788 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3789 insns, not any notes that may be attached. We don't want to mark
3790 a constant just because it happens to appear in a REG_EQUIV note. */
3791 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3793 rtx seq
= PATTERN (insn
);
3794 int i
, n
= XVECLEN (seq
, 0);
3795 for (i
= 0; i
< n
; ++i
)
3797 rtx subinsn
= XVECEXP (seq
, 0, i
);
3798 if (INSN_P (subinsn
))
3799 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
3803 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
3806 /* Look through the instructions for this function, and mark all the
3807 entries in POOL which are actually being used. Emit deferred constants
3808 which have indeed been used. */
3811 mark_constant_pool (void)
3815 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
3818 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3819 mark_constants (insn
);
3821 for (link
= crtl
->epilogue_delay_list
;
3823 link
= XEXP (link
, 1))
3824 mark_constants (XEXP (link
, 0));
3827 /* Write all the constants in POOL. */
3830 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
3832 struct constant_descriptor_rtx
*desc
;
3834 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3837 /* If the constant is part of an object_block, make sure that
3838 the constant has been positioned within its block, but do not
3839 write out its definition yet. output_object_blocks will do
3841 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
3842 && SYMBOL_REF_BLOCK (desc
->sym
))
3843 place_block_symbol (desc
->sym
);
3846 switch_to_section (targetm
.asm_out
.select_rtx_section
3847 (desc
->mode
, desc
->constant
, desc
->align
));
3848 output_constant_pool_1 (desc
, desc
->align
);
3853 /* Mark all constants that are used in the current function, then write
3854 out the function's private constant pool. */
3857 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3858 tree fndecl ATTRIBUTE_UNUSED
)
3860 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
3862 /* It is possible for gcc to call force_const_mem and then to later
3863 discard the instructions which refer to the constant. In such a
3864 case we do not need to output the constant. */
3865 mark_constant_pool ();
3867 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3868 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3871 output_constant_pool_contents (pool
);
3873 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3874 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3878 /* Write the contents of the shared constant pool. */
3881 output_shared_constant_pool (void)
3883 output_constant_pool_contents (shared_constant_pool
);
3886 /* Determine what kind of relocations EXP may need. */
3889 compute_reloc_for_constant (tree exp
)
3891 int reloc
= 0, reloc2
;
3894 switch (TREE_CODE (exp
))
3898 /* Go inside any operations that get_inner_reference can handle and see
3899 if what's inside is a constant: no need to do anything here for
3900 addresses of variables or functions. */
3901 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3902 tem
= TREE_OPERAND (tem
, 0))
3905 if (TREE_PUBLIC (tem
))
3912 case POINTER_PLUS_EXPR
:
3913 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3914 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3918 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3919 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3920 /* The difference of two local labels is computable at link time. */
3921 if (reloc
== 1 && reloc2
== 1)
3928 case VIEW_CONVERT_EXPR
:
3929 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3934 unsigned HOST_WIDE_INT idx
;
3935 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3937 reloc
|= compute_reloc_for_constant (tem
);
3947 /* Find all the constants whose addresses are referenced inside of EXP,
3948 and make sure assembler code with a label has been output for each one.
3949 Indicate whether an ADDR_EXPR has been encountered. */
3952 output_addressed_constants (tree exp
)
3956 switch (TREE_CODE (exp
))
3960 /* Go inside any operations that get_inner_reference can handle and see
3961 if what's inside is a constant: no need to do anything here for
3962 addresses of variables or functions. */
3963 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3964 tem
= TREE_OPERAND (tem
, 0))
3967 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3968 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
3969 tem
= DECL_INITIAL (tem
);
3971 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
3972 output_constant_def (tem
, 0);
3976 case POINTER_PLUS_EXPR
:
3978 output_addressed_constants (TREE_OPERAND (exp
, 1));
3982 case VIEW_CONVERT_EXPR
:
3983 output_addressed_constants (TREE_OPERAND (exp
, 0));
3988 unsigned HOST_WIDE_INT idx
;
3989 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3991 output_addressed_constants (tem
);
4000 /* Whether a constructor CTOR is a valid static constant initializer if all
4001 its elements are. This used to be internal to initializer_constant_valid_p
4002 and has been exposed to let other functions like categorize_ctor_elements
4003 evaluate the property while walking a constructor for other purposes. */
4006 constructor_static_from_elts_p (const_tree ctor
)
4008 return (TREE_CONSTANT (ctor
)
4009 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4010 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
4011 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
4014 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4017 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4018 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4019 which are valid when ENDTYPE is an integer of any size; in
4020 particular, this does not accept a pointer minus a constant. This
4021 returns null_pointer_node if the VALUE is an absolute constant
4022 which can be used to initialize a static variable. Otherwise it
4026 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4030 if (!INTEGRAL_TYPE_P (endtype
))
4033 op0
= TREE_OPERAND (value
, 0);
4034 op1
= TREE_OPERAND (value
, 1);
4036 /* Like STRIP_NOPS except allow the operand mode to widen. This
4037 works around a feature of fold that simplifies (int)(p1 - p2) to
4038 ((int)p1 - (int)p2) under the theory that the narrower operation
4041 while (CONVERT_EXPR_P (op0
)
4042 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4044 tree inner
= TREE_OPERAND (op0
, 0);
4045 if (inner
== error_mark_node
4046 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4047 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4048 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4053 while (CONVERT_EXPR_P (op1
)
4054 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4056 tree inner
= TREE_OPERAND (op1
, 0);
4057 if (inner
== error_mark_node
4058 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4059 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4060 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4065 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4069 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4070 cache
? cache
+ 2 : NULL
);
4071 /* Both initializers must be known. */
4075 && (op0
== null_pointer_node
4076 || TREE_CODE (value
) == MINUS_EXPR
))
4077 return null_pointer_node
;
4079 /* Support differences between labels. */
4080 if (TREE_CODE (op0
) == LABEL_DECL
4081 && TREE_CODE (op1
) == LABEL_DECL
)
4082 return null_pointer_node
;
4084 if (TREE_CODE (op0
) == STRING_CST
4085 && TREE_CODE (op1
) == STRING_CST
4086 && operand_equal_p (op0
, op1
, 1))
4087 return null_pointer_node
;
4093 /* Helper function of initializer_constant_valid_p.
4094 Return nonzero if VALUE is a valid constant-valued expression
4095 for use in initializing a static variable; one that can be an
4096 element of a "constant" initializer.
4098 Return null_pointer_node if the value is absolute;
4099 if it is relocatable, return the variable that determines the relocation.
4100 We assume that VALUE has been folded as much as possible;
4101 therefore, we do not need to check for such things as
4102 arithmetic-combinations of integers.
4104 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4107 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4111 switch (TREE_CODE (value
))
4114 if (constructor_static_from_elts_p (value
))
4116 unsigned HOST_WIDE_INT idx
;
4118 bool absolute
= true;
4120 if (cache
&& cache
[0] == value
)
4122 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4125 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4132 cache
[1] = NULL_TREE
;
4136 if (reloc
!= null_pointer_node
)
4139 /* For a non-absolute relocation, there is no single
4140 variable that can be "the variable that determines the
4145 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4147 return absolute
? null_pointer_node
: error_mark_node
;
4150 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4158 return null_pointer_node
;
4163 tree op0
= staticp (TREE_OPERAND (value
, 0));
4166 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4167 to be a constant, this is old-skool offsetof-like nonsense. */
4168 if (TREE_CODE (op0
) == INDIRECT_REF
4169 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4170 return null_pointer_node
;
4171 /* Taking the address of a nested function involves a trampoline,
4172 unless we don't need or want one. */
4173 if (TREE_CODE (op0
) == FUNCTION_DECL
4174 && DECL_STATIC_CHAIN (op0
)
4175 && !TREE_NO_TRAMPOLINE (value
))
4177 /* "&{...}" requires a temporary to hold the constructed
4179 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4185 case NON_LVALUE_EXPR
:
4186 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4189 case VIEW_CONVERT_EXPR
:
4191 tree src
= TREE_OPERAND (value
, 0);
4192 tree src_type
= TREE_TYPE (src
);
4193 tree dest_type
= TREE_TYPE (value
);
4195 /* Allow view-conversions from aggregate to non-aggregate type only
4196 if the bit pattern is fully preserved afterwards; otherwise, the
4197 RTL expander won't be able to apply a subsequent transformation
4198 to the underlying constructor. */
4199 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4201 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4202 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4207 /* Allow all other kinds of view-conversion. */
4208 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4213 tree src
= TREE_OPERAND (value
, 0);
4214 tree src_type
= TREE_TYPE (src
);
4215 tree dest_type
= TREE_TYPE (value
);
4217 /* Allow conversions between pointer types, floating-point
4218 types, and offset types. */
4219 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4220 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4221 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4222 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4223 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4225 /* Allow length-preserving conversions between integer types. */
4226 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4227 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4228 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4230 /* Allow conversions between other integer types only if
4232 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4234 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4235 if (inner
== null_pointer_node
)
4236 return null_pointer_node
;
4240 /* Allow (int) &foo provided int is as wide as a pointer. */
4241 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4242 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4243 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4245 /* Likewise conversions from int to pointers, but also allow
4246 conversions from 0. */
4247 if ((POINTER_TYPE_P (dest_type
)
4248 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4249 && INTEGRAL_TYPE_P (src_type
))
4251 if (TREE_CODE (src
) == INTEGER_CST
4252 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4253 return null_pointer_node
;
4254 if (integer_zerop (src
))
4255 return null_pointer_node
;
4256 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4257 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4260 /* Allow conversions to struct or union types if the value
4262 if (TREE_CODE (dest_type
) == RECORD_TYPE
4263 || TREE_CODE (dest_type
) == UNION_TYPE
)
4264 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4268 case POINTER_PLUS_EXPR
:
4270 /* Any valid floating-point constants will have been folded by now;
4271 with -frounding-math we hit this with addition of two constants. */
4272 if (TREE_CODE (endtype
) == REAL_TYPE
)
4274 if (cache
&& cache
[0] == value
)
4276 if (! INTEGRAL_TYPE_P (endtype
)
4277 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4279 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4281 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4284 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4285 endtype
, ncache
+ 2);
4286 /* If either term is absolute, use the other term's relocation. */
4287 if (valid0
== null_pointer_node
)
4289 else if (valid1
== null_pointer_node
)
4291 /* Support narrowing pointer differences. */
4293 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4297 /* Support narrowing pointer differences. */
4298 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4307 if (TREE_CODE (endtype
) == REAL_TYPE
)
4309 if (cache
&& cache
[0] == value
)
4311 if (! INTEGRAL_TYPE_P (endtype
)
4312 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4314 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4316 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4319 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4320 endtype
, ncache
+ 2);
4321 /* Win if second argument is absolute. */
4322 if (valid1
== null_pointer_node
)
4324 /* Win if both arguments have the same relocation.
4325 Then the value is absolute. */
4326 else if (valid0
== valid1
&& valid0
!= 0)
4327 ret
= null_pointer_node
;
4328 /* Since GCC guarantees that string constants are unique in the
4329 generated code, a subtraction between two copies of the same
4330 constant string is absolute. */
4331 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4332 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4333 && operand_equal_p (valid0
, valid1
, 1))
4334 ret
= null_pointer_node
;
4335 /* Support narrowing differences. */
4337 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4341 /* Support narrowing differences. */
4342 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4357 /* Return nonzero if VALUE is a valid constant-valued expression
4358 for use in initializing a static variable; one that can be an
4359 element of a "constant" initializer.
4361 Return null_pointer_node if the value is absolute;
4362 if it is relocatable, return the variable that determines the relocation.
4363 We assume that VALUE has been folded as much as possible;
4364 therefore, we do not need to check for such things as
4365 arithmetic-combinations of integers. */
4367 initializer_constant_valid_p (tree value
, tree endtype
)
4369 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4372 /* Return true if VALUE is a valid constant-valued expression
4373 for use in initializing a static bit-field; one that can be
4374 an element of a "constant" initializer. */
4377 initializer_constant_valid_for_bitfield_p (tree value
)
4379 /* For bitfields we support integer constants or possibly nested aggregates
4381 switch (TREE_CODE (value
))
4385 unsigned HOST_WIDE_INT idx
;
4388 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4389 if (!initializer_constant_valid_for_bitfield_p (elt
))
4397 case VIEW_CONVERT_EXPR
:
4398 case NON_LVALUE_EXPR
:
4400 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4409 /* output_constructor outer state of relevance in recursive calls, typically
4410 for nested aggregate bitfields. */
4413 unsigned int bit_offset
; /* current position in ... */
4414 int byte
; /* ... the outer byte buffer. */
4417 static unsigned HOST_WIDE_INT
4418 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4421 /* Output assembler code for constant EXP to FILE, with no label.
4422 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4423 Assumes output_addressed_constants has been done on EXP already.
4425 Generate exactly SIZE bytes of assembler data, padding at the end
4426 with zeros if necessary. SIZE must always be specified.
4428 SIZE is important for structure constructors,
4429 since trailing members may have been omitted from the constructor.
4430 It is also important for initialization of arrays from string constants
4431 since the full length of the string constant might not be wanted.
4432 It is also needed for initialization of unions, where the initializer's
4433 type is just one member, and that may not be as long as the union.
4435 There a case in which we would fail to output exactly SIZE bytes:
4436 for a structure constructor that wants to produce more than SIZE bytes.
4437 But such constructors will never be generated for any possible input.
4439 ALIGN is the alignment of the data in bits. */
4442 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4444 enum tree_code code
;
4445 unsigned HOST_WIDE_INT thissize
;
4447 if (size
== 0 || flag_syntax_only
)
4450 /* See if we're trying to initialize a pointer in a non-default mode
4451 to the address of some declaration somewhere. If the target says
4452 the mode is valid for pointers, assume the target has a way of
4454 if (TREE_CODE (exp
) == NOP_EXPR
4455 && POINTER_TYPE_P (TREE_TYPE (exp
))
4456 && targetm
.addr_space
.valid_pointer_mode
4457 (TYPE_MODE (TREE_TYPE (exp
)),
4458 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4460 tree saved_type
= TREE_TYPE (exp
);
4462 /* Peel off any intermediate conversions-to-pointer for valid
4464 while (TREE_CODE (exp
) == NOP_EXPR
4465 && POINTER_TYPE_P (TREE_TYPE (exp
))
4466 && targetm
.addr_space
.valid_pointer_mode
4467 (TYPE_MODE (TREE_TYPE (exp
)),
4468 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4469 exp
= TREE_OPERAND (exp
, 0);
4471 /* If what we're left with is the address of something, we can
4472 convert the address to the final type and output it that
4474 if (TREE_CODE (exp
) == ADDR_EXPR
)
4475 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4476 /* Likewise for constant ints. */
4477 else if (TREE_CODE (exp
) == INTEGER_CST
)
4478 exp
= build_int_cst_wide (saved_type
, TREE_INT_CST_LOW (exp
),
4479 TREE_INT_CST_HIGH (exp
));
4483 /* Eliminate any conversions since we'll be outputting the underlying
4485 while (CONVERT_EXPR_P (exp
)
4486 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4487 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4489 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4490 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4492 /* Make sure eliminating the conversion is really a no-op, except with
4493 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4494 union types to allow for Ada unchecked unions. */
4495 if (type_size
> op_size
4496 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4497 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4498 /* Keep the conversion. */
4501 exp
= TREE_OPERAND (exp
, 0);
4504 code
= TREE_CODE (TREE_TYPE (exp
));
4505 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4507 /* Allow a constructor with no elements for any data type.
4508 This means to fill the space with zeros. */
4509 if (TREE_CODE (exp
) == CONSTRUCTOR
4510 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
4512 assemble_zeros (size
);
4516 if (TREE_CODE (exp
) == FDESC_EXPR
)
4518 #ifdef ASM_OUTPUT_FDESC
4519 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4520 tree decl
= TREE_OPERAND (exp
, 0);
4521 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4528 /* Now output the underlying data. If we've handling the padding, return.
4529 Otherwise, break and ensure SIZE is the size written. */
4536 case REFERENCE_TYPE
:
4538 case FIXED_POINT_TYPE
:
4539 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4540 EXPAND_INITIALIZER
),
4541 MIN (size
, thissize
), align
, 0))
4542 error ("initializer for integer/fixed-point value is too complicated");
4546 if (TREE_CODE (exp
) != REAL_CST
)
4547 error ("initializer for floating value is not a floating constant");
4549 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4553 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4554 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4555 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4560 switch (TREE_CODE (exp
))
4563 output_constructor (exp
, size
, align
, NULL
);
4566 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
4568 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4575 unsigned int nalign
;
4576 enum machine_mode inner
;
4578 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4579 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4581 elt_size
= GET_MODE_SIZE (inner
);
4583 link
= TREE_VECTOR_CST_ELTS (exp
);
4584 output_constant (TREE_VALUE (link
), elt_size
, align
);
4585 thissize
= elt_size
;
4586 while ((link
= TREE_CHAIN (link
)) != NULL
)
4588 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
4589 thissize
+= elt_size
;
4600 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4601 output_constructor (exp
, size
, align
, NULL
);
4611 if (size
> thissize
)
4612 assemble_zeros (size
- thissize
);
4616 /* Subroutine of output_constructor, used for computing the size of
4617 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4618 type with an unspecified upper bound. */
4620 static unsigned HOST_WIDE_INT
4621 array_size_for_constructor (tree val
)
4624 unsigned HOST_WIDE_INT cnt
;
4625 tree index
, value
, tmp
;
4627 /* This code used to attempt to handle string constants that are not
4628 arrays of single-bytes, but nothing else does, so there's no point in
4630 if (TREE_CODE (val
) == STRING_CST
)
4631 return TREE_STRING_LENGTH (val
);
4633 max_index
= NULL_TREE
;
4634 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4636 if (TREE_CODE (index
) == RANGE_EXPR
)
4637 index
= TREE_OPERAND (index
, 1);
4638 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4642 if (max_index
== NULL_TREE
)
4645 /* Compute the total number of array elements. */
4646 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4647 i
= size_binop (MINUS_EXPR
, fold_convert (sizetype
, max_index
),
4648 fold_convert (sizetype
, tmp
));
4649 i
= size_binop (PLUS_EXPR
, i
, size_one_node
);
4651 /* Multiply by the array element unit size to find number of bytes. */
4652 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4654 return tree_low_cst (i
, 1);
4657 /* Other datastructures + helpers for output_constructor. */
4659 /* output_constructor local state to support interaction with helpers. */
4663 /* Received arguments. */
4664 tree exp
; /* Constructor expression. */
4665 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4666 unsigned int align
; /* Known initial alignment. */
4668 /* Constructor expression data. */
4669 tree type
; /* Expression type. */
4670 tree field
; /* Current field decl in a record. */
4671 tree min_index
; /* Lower bound if specified for an array. */
4673 /* Output processing state. */
4674 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4675 bool byte_buffer_in_use
; /* Whether byte ... */
4676 int byte
; /* ... contains part of a bitfield byte yet to
4679 int last_relative_index
; /* Implicit or explicit index of the last
4680 array element output within a bitfield. */
4681 /* Current element. */
4682 tree val
; /* Current element value. */
4683 tree index
; /* Current element index. */
4687 /* Helper for output_constructor. From the current LOCAL state, output a
4688 RANGE_EXPR element. */
4691 output_constructor_array_range (oc_local_state
*local
)
4693 unsigned HOST_WIDE_INT fieldsize
4694 = int_size_in_bytes (TREE_TYPE (local
->type
));
4696 HOST_WIDE_INT lo_index
4697 = tree_low_cst (TREE_OPERAND (local
->index
, 0), 0);
4698 HOST_WIDE_INT hi_index
4699 = tree_low_cst (TREE_OPERAND (local
->index
, 1), 0);
4700 HOST_WIDE_INT index
;
4703 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4705 for (index
= lo_index
; index
<= hi_index
; index
++)
4707 /* Output the element's initial value. */
4708 if (local
->val
== NULL_TREE
)
4709 assemble_zeros (fieldsize
);
4711 output_constant (local
->val
, fieldsize
, align2
);
4713 /* Count its size. */
4714 local
->total_bytes
+= fieldsize
;
4718 /* Helper for output_constructor. From the current LOCAL state, output a
4719 field element that is not true bitfield or part of an outer one. */
4722 output_constructor_regular_field (oc_local_state
*local
)
4724 /* Field size and position. Since this structure is static, we know the
4725 positions are constant. */
4726 unsigned HOST_WIDE_INT fieldsize
;
4727 HOST_WIDE_INT fieldpos
;
4729 unsigned int align2
;
4731 if (local
->index
!= NULL_TREE
)
4733 double_int idx
= double_int_sub (tree_to_double_int (local
->index
),
4734 tree_to_double_int (local
->min_index
));
4735 gcc_assert (double_int_fits_in_shwi_p (idx
));
4736 fieldpos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
)), 1)
4739 else if (local
->field
!= NULL_TREE
)
4740 fieldpos
= int_byte_position (local
->field
);
4744 /* Output any buffered-up bit-fields preceding this element. */
4745 if (local
->byte_buffer_in_use
)
4747 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4748 local
->total_bytes
++;
4749 local
->byte_buffer_in_use
= false;
4752 /* Advance to offset of this element.
4753 Note no alignment needed in an array, since that is guaranteed
4754 if each element has the proper size. */
4755 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4756 && fieldpos
!= local
->total_bytes
)
4758 gcc_assert (fieldpos
>= local
->total_bytes
);
4759 assemble_zeros (fieldpos
- local
->total_bytes
);
4760 local
->total_bytes
= fieldpos
;
4763 /* Find the alignment of this element. */
4764 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
4766 /* Determine size this element should occupy. */
4771 /* If this is an array with an unspecified upper bound,
4772 the initializer determines the size. */
4773 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4774 but we cannot do this until the deprecated support for
4775 initializing zero-length array members is removed. */
4776 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
4777 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
4778 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
4780 fieldsize
= array_size_for_constructor (local
->val
);
4781 /* Given a non-empty initialization, this field had
4783 gcc_assert (!fieldsize
|| !DECL_CHAIN (local
->field
));
4786 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (local
->field
), 1);
4789 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
4791 /* Output the element's initial value. */
4792 if (local
->val
== NULL_TREE
)
4793 assemble_zeros (fieldsize
);
4795 output_constant (local
->val
, fieldsize
, align2
);
4797 /* Count its size. */
4798 local
->total_bytes
+= fieldsize
;
4801 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4802 output an element that is a true bitfield or part of an outer one. */
4805 output_constructor_bitfield (oc_local_state
*local
, oc_outer_state
*outer
)
4807 /* Bit size of this element. */
4808 HOST_WIDE_INT ebitsize
4810 ? tree_low_cst (DECL_SIZE (local
->field
), 1)
4811 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local
->type
)), 1));
4813 /* Relative index of this element if this is an array component. */
4814 HOST_WIDE_INT relative_index
4817 ? (tree_low_cst (local
->index
, 0)
4818 - tree_low_cst (local
->min_index
, 0))
4819 : local
->last_relative_index
+ 1)
4822 /* Bit position of this element from the start of the containing
4824 HOST_WIDE_INT constructor_relative_ebitpos
4826 ? int_bit_position (local
->field
)
4827 : ebitsize
* relative_index
);
4829 /* Bit position of this element from the start of a possibly ongoing
4830 outer byte buffer. */
4831 HOST_WIDE_INT byte_relative_ebitpos
4832 = ((outer
? outer
->bit_offset
: 0) + constructor_relative_ebitpos
);
4834 /* From the start of a possibly ongoing outer byte buffer, offsets to
4835 the first bit of this element and to the first bit past the end of
4837 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
4838 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
4840 local
->last_relative_index
= relative_index
;
4842 if (local
->val
== NULL_TREE
)
4843 local
->val
= integer_zero_node
;
4845 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
4846 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
4847 local
->val
= TREE_OPERAND (local
->val
, 0);
4849 if (TREE_CODE (local
->val
) != INTEGER_CST
4850 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
4852 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
4856 /* If this field does not start in this (or, next) byte,
4858 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4860 /* Output remnant of any bit field in previous bytes. */
4861 if (local
->byte_buffer_in_use
)
4863 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4864 local
->total_bytes
++;
4865 local
->byte_buffer_in_use
= false;
4868 /* If still not at proper byte, advance to there. */
4869 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4871 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
4872 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
4873 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
4877 /* Set up the buffer if necessary. */
4878 if (!local
->byte_buffer_in_use
)
4882 local
->byte_buffer_in_use
= true;
4885 /* If this is nested constructor, recurse passing the bit offset and the
4886 pending data, then retrieve the new pending data afterwards. */
4887 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
4889 oc_outer_state output_state
;
4891 output_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
4892 output_state
.byte
= local
->byte
;
4894 += output_constructor (local
->val
, 0, 0, &output_state
);
4895 local
->byte
= output_state
.byte
;
4899 /* Otherwise, we must split the element into pieces that fall within
4900 separate bytes, and combine each byte with previous or following
4902 while (next_offset
< end_offset
)
4906 HOST_WIDE_INT value
;
4907 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4908 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4910 /* Advance from byte to byte
4911 within this element when necessary. */
4912 while (next_byte
!= local
->total_bytes
)
4914 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4915 local
->total_bytes
++;
4919 /* Number of bits we can process at once
4920 (all part of the same byte). */
4921 this_time
= MIN (end_offset
- next_offset
,
4922 BITS_PER_UNIT
- next_bit
);
4923 if (BYTES_BIG_ENDIAN
)
4925 /* On big-endian machine, take the most significant bits
4926 first (of the bits that are significant)
4927 and put them into bytes from the most significant end. */
4928 shift
= end_offset
- next_offset
- this_time
;
4930 /* Don't try to take a bunch of bits that cross
4931 the word boundary in the INTEGER_CST. We can
4932 only select bits from the LOW or HIGH part
4934 if (shift
< HOST_BITS_PER_WIDE_INT
4935 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4937 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4938 shift
= HOST_BITS_PER_WIDE_INT
;
4941 /* Now get the bits from the appropriate constant word. */
4942 if (shift
< HOST_BITS_PER_WIDE_INT
)
4943 value
= TREE_INT_CST_LOW (local
->val
);
4946 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4947 value
= TREE_INT_CST_HIGH (local
->val
);
4948 shift
-= HOST_BITS_PER_WIDE_INT
;
4951 /* Get the result. This works only when:
4952 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4953 local
->byte
|= (((value
>> shift
)
4954 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4955 << (BITS_PER_UNIT
- this_time
- next_bit
));
4959 /* On little-endian machines,
4960 take first the least significant bits of the value
4961 and pack them starting at the least significant
4962 bits of the bytes. */
4963 shift
= next_offset
- byte_relative_ebitpos
;
4965 /* Don't try to take a bunch of bits that cross
4966 the word boundary in the INTEGER_CST. We can
4967 only select bits from the LOW or HIGH part
4969 if (shift
< HOST_BITS_PER_WIDE_INT
4970 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4971 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4973 /* Now get the bits from the appropriate constant word. */
4974 if (shift
< HOST_BITS_PER_WIDE_INT
)
4975 value
= TREE_INT_CST_LOW (local
->val
);
4978 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4979 value
= TREE_INT_CST_HIGH (local
->val
);
4980 shift
-= HOST_BITS_PER_WIDE_INT
;
4983 /* Get the result. This works only when:
4984 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4985 local
->byte
|= (((value
>> shift
)
4986 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4990 next_offset
+= this_time
;
4991 local
->byte_buffer_in_use
= true;
4995 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4996 Generate at least SIZE bytes, padding if necessary. OUTER designates the
4997 caller output state of relevance in recursive invocations. */
4999 static unsigned HOST_WIDE_INT
5000 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5001 unsigned int align
, oc_outer_state
* outer
)
5003 unsigned HOST_WIDE_INT cnt
;
5004 constructor_elt
*ce
;
5006 oc_local_state local
;
5008 /* Setup our local state to communicate with helpers. */
5011 local
.align
= align
;
5013 local
.total_bytes
= 0;
5014 local
.byte_buffer_in_use
= outer
!= NULL
;
5015 local
.byte
= outer
? outer
->byte
: 0;
5017 local
.type
= TREE_TYPE (exp
);
5019 local
.last_relative_index
= -1;
5021 local
.min_index
= NULL_TREE
;
5022 if (TREE_CODE (local
.type
) == ARRAY_TYPE
5023 && TYPE_DOMAIN (local
.type
) != NULL_TREE
)
5024 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5026 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5028 /* As CE goes through the elements of the constant, FIELD goes through the
5029 structure fields if the constant is a structure. If the constant is a
5030 union, we override this by getting the field from the TREE_LIST element.
5031 But the constant could also be an array. Then FIELD is zero.
5033 There is always a maximum of one element in the chain LINK for unions
5034 (even if the initializer in a source program incorrectly contains
5037 local
.field
= NULL_TREE
;
5038 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5039 local
.field
= TYPE_FIELDS (local
.type
);
5042 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
5043 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
5045 local
.val
= ce
->value
;
5046 local
.index
= NULL_TREE
;
5048 /* The element in a union constructor specifies the proper field
5050 if ((TREE_CODE (local
.type
) == RECORD_TYPE
5051 || TREE_CODE (local
.type
) == UNION_TYPE
5052 || TREE_CODE (local
.type
) == QUAL_UNION_TYPE
)
5053 && ce
->index
!= NULL_TREE
)
5054 local
.field
= ce
->index
;
5056 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5057 local
.index
= ce
->index
;
5059 #ifdef ASM_COMMENT_START
5060 if (local
.field
&& flag_verbose_asm
)
5061 fprintf (asm_out_file
, "%s %s:\n",
5063 DECL_NAME (local
.field
)
5064 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5068 /* Eliminate the marker that makes a cast not be an lvalue. */
5069 if (local
.val
!= NULL_TREE
)
5070 STRIP_NOPS (local
.val
);
5072 /* Output the current element, using the appropriate helper ... */
5074 /* For an array slice not part of an outer bitfield. */
5076 && local
.index
!= NULL_TREE
5077 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5078 output_constructor_array_range (&local
);
5080 /* For a field that is neither a true bitfield nor part of an outer one,
5081 known to be at least byte aligned and multiple-of-bytes long. */
5083 && (local
.field
== NULL_TREE
5084 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5085 output_constructor_regular_field (&local
);
5087 /* For a true bitfield or part of an outer one. */
5089 output_constructor_bitfield (&local
, outer
);
5092 /* If we are not at toplevel, save the pending data for our caller.
5093 Otherwise output the pending data and padding zeros as needed. */
5095 outer
->byte
= local
.byte
;
5098 if (local
.byte_buffer_in_use
)
5100 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5101 local
.total_bytes
++;
5104 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5106 assemble_zeros (local
.size
- local
.total_bytes
);
5107 local
.total_bytes
= local
.size
;
5111 return local
.total_bytes
;
5114 /* Mark DECL as weak. */
5117 mark_weak (tree decl
)
5119 DECL_WEAK (decl
) = 1;
5121 if (DECL_RTL_SET_P (decl
)
5122 && MEM_P (DECL_RTL (decl
))
5123 && XEXP (DECL_RTL (decl
), 0)
5124 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5125 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5128 /* Merge weak status between NEWDECL and OLDDECL. */
5131 merge_weak (tree newdecl
, tree olddecl
)
5133 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5135 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5138 /* We put the NEWDECL on the weak_decls list at some point
5139 and OLDDECL as well. Keep just OLDDECL on the list. */
5140 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5141 if (TREE_VALUE (*pwd
) == newdecl
)
5143 *pwd
= TREE_CHAIN (*pwd
);
5150 if (DECL_WEAK (newdecl
))
5154 /* NEWDECL is weak, but OLDDECL is not. */
5156 /* If we already output the OLDDECL, we're in trouble; we can't
5157 go back and make it weak. This should never happen in
5158 unit-at-a-time compilation. */
5159 gcc_assert (!TREE_ASM_WRITTEN (olddecl
));
5161 /* If we've already generated rtl referencing OLDDECL, we may
5162 have done so in a way that will not function properly with
5163 a weak symbol. Again in unit-at-a-time this should be
5165 gcc_assert (!TREE_USED (olddecl
)
5166 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)));
5168 if (TARGET_SUPPORTS_WEAK
)
5170 /* We put the NEWDECL on the weak_decls list at some point.
5171 Replace it with the OLDDECL. */
5172 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5173 if (TREE_VALUE (wd
) == newdecl
)
5175 TREE_VALUE (wd
) = olddecl
;
5178 /* We may not find the entry on the list. If NEWDECL is a
5179 weak alias, then we will have already called
5180 globalize_decl to remove the entry; in that case, we do
5181 not need to do anything. */
5184 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5185 mark_weak (olddecl
);
5188 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5189 weak. Just update NEWDECL to indicate that it's weak too. */
5190 mark_weak (newdecl
);
5193 /* Declare DECL to be a weak symbol. */
5196 declare_weak (tree decl
)
5198 gcc_assert (TREE_CODE (decl
) != FUNCTION_DECL
|| !TREE_ASM_WRITTEN (decl
));
5199 if (! TREE_PUBLIC (decl
))
5200 error ("weak declaration of %q+D must be public", decl
);
5201 else if (!TARGET_SUPPORTS_WEAK
)
5202 warning (0, "weak declaration of %q+D not supported", decl
);
5205 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5206 DECL_ATTRIBUTES (decl
)
5207 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5211 weak_finish_1 (tree decl
)
5213 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5214 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5217 if (! TREE_USED (decl
))
5220 #ifdef ASM_WEAKEN_DECL
5221 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5223 #ifdef ASM_WEAKEN_LABEL
5224 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5226 #ifdef ASM_OUTPUT_WEAK_ALIAS
5228 static bool warn_once
= 0;
5231 warning (0, "only weak aliases are supported in this configuration");
5241 /* This TREE_LIST contains weakref targets. */
5243 static GTY(()) tree weakref_targets
;
5245 /* Forward declaration. */
5246 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
5248 /* Emit any pending weak declarations. */
5255 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5257 tree alias_decl
= TREE_PURPOSE (t
);
5258 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5260 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5261 /* Remove alias_decl from the weak list, but leave entries for
5262 the target alone. */
5264 #ifndef ASM_OUTPUT_WEAKREF
5265 else if (! TREE_SYMBOL_REFERENCED (target
))
5267 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5268 defined, otherwise we and weak_finish_1 would use
5269 different macros. */
5270 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5271 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5273 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
5277 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5278 TREE_CODE (alias_decl
), target
,
5279 TREE_TYPE (alias_decl
));
5281 DECL_EXTERNAL (decl
) = 1;
5282 TREE_PUBLIC (decl
) = 1;
5283 DECL_ARTIFICIAL (decl
) = 1;
5284 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5285 TREE_USED (decl
) = 1;
5288 weak_finish_1 (decl
);
5297 /* Remove the alias and the target from the pending weak list
5298 so that we do not emit any .weak directives for the former,
5299 nor multiple .weak directives for the latter. */
5300 for (p
= &weak_decls
; (t2
= *p
) ; )
5302 if (TREE_VALUE (t2
) == alias_decl
5303 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5304 *p
= TREE_CHAIN (t2
);
5306 p
= &TREE_CHAIN (t2
);
5309 /* Remove other weakrefs to the same target, to speed things up. */
5310 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5312 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5313 *p
= TREE_CHAIN (t2
);
5315 p
= &TREE_CHAIN (t2
);
5320 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5322 tree decl
= TREE_VALUE (t
);
5324 weak_finish_1 (decl
);
5328 /* Emit the assembly bits to indicate that DECL is globally visible. */
5331 globalize_decl (tree decl
)
5334 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5335 if (DECL_WEAK (decl
))
5337 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5340 #ifdef ASM_WEAKEN_DECL
5341 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5343 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5346 /* Remove this function from the pending weak list so that
5347 we do not emit multiple .weak directives for it. */
5348 for (p
= &weak_decls
; (t
= *p
) ; )
5350 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5351 *p
= TREE_CHAIN (t
);
5353 p
= &TREE_CHAIN (t
);
5356 /* Remove weakrefs to the same target from the pending weakref
5357 list, for the same reason. */
5358 for (p
= &weakref_targets
; (t
= *p
) ; )
5360 if (DECL_ASSEMBLER_NAME (decl
)
5361 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5362 *p
= TREE_CHAIN (t
);
5364 p
= &TREE_CHAIN (t
);
5371 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5374 VEC(alias_pair
,gc
) *alias_pairs
;
5376 /* Given an assembly name, find the decl it is associated with. At the
5377 same time, mark it needed for cgraph. */
5380 find_decl_and_mark_needed (tree decl
, tree target
)
5382 struct cgraph_node
*fnode
= NULL
;
5383 struct varpool_node
*vnode
= NULL
;
5385 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5387 fnode
= cgraph_node_for_asm (target
);
5389 vnode
= varpool_node_for_asm (target
);
5393 vnode
= varpool_node_for_asm (target
);
5395 fnode
= cgraph_node_for_asm (target
);
5400 cgraph_mark_needed_node (fnode
);
5405 varpool_mark_needed_node (vnode
);
5406 vnode
->force_output
= 1;
5413 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5414 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5415 tree node is DECL to have the value of the tree node TARGET. */
5418 do_assemble_alias (tree decl
, tree target
)
5420 /* Emulated TLS had better not get this var. */
5421 gcc_assert(!(!targetm
.have_tls
5422 && TREE_CODE (decl
) == VAR_DECL
5423 && DECL_THREAD_LOCAL_P (decl
)));
5425 if (TREE_ASM_WRITTEN (decl
))
5428 /* We must force creation of DECL_RTL for debug info generation, even though
5429 we don't use it here. */
5430 make_decl_rtl (decl
);
5432 TREE_ASM_WRITTEN (decl
) = 1;
5433 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5435 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5437 ultimate_transparent_alias_target (&target
);
5439 if (!TREE_SYMBOL_REFERENCED (target
))
5440 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5442 #ifdef ASM_OUTPUT_WEAKREF
5443 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5444 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5445 IDENTIFIER_POINTER (target
));
5447 if (!TARGET_SUPPORTS_WEAK
)
5449 error_at (DECL_SOURCE_LOCATION (decl
),
5450 "weakref is not supported in this configuration");
5457 #ifdef ASM_OUTPUT_DEF
5458 /* Make name accessible from other files, if appropriate. */
5460 if (TREE_PUBLIC (decl
))
5462 globalize_decl (decl
);
5463 maybe_assemble_visibility (decl
);
5465 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5467 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
5468 ASM_OUTPUT_TYPE_DIRECTIVE
5469 (asm_out_file
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5472 error_at (DECL_SOURCE_LOCATION (decl
),
5473 "ifunc is not supported in this configuration");
5477 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5478 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5480 ASM_OUTPUT_DEF (asm_out_file
,
5481 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5482 IDENTIFIER_POINTER (target
));
5484 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5489 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5490 # ifdef ASM_WEAKEN_DECL
5491 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5493 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5495 /* Remove this function from the pending weak list so that
5496 we do not emit multiple .weak directives for it. */
5497 for (p
= &weak_decls
; (t
= *p
) ; )
5498 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5499 *p
= TREE_CHAIN (t
);
5501 p
= &TREE_CHAIN (t
);
5503 /* Remove weakrefs to the same target from the pending weakref
5504 list, for the same reason. */
5505 for (p
= &weakref_targets
; (t
= *p
) ; )
5507 if (DECL_ASSEMBLER_NAME (decl
)
5508 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5509 *p
= TREE_CHAIN (t
);
5511 p
= &TREE_CHAIN (t
);
5518 /* Allocate and construct a symbol alias set. */
5520 static symbol_alias_set_t
*
5521 symbol_alias_set_create (void)
5523 return pointer_set_create ();
5526 /* Destruct and free a symbol alias set. */
5529 symbol_alias_set_destroy (symbol_alias_set_t
*aset
)
5531 pointer_set_destroy (aset
);
5534 /* Test if a symbol alias set contains a given name. */
5537 symbol_alias_set_contains (const symbol_alias_set_t
*aset
, tree t
)
5539 /* We accept either a DECL or an IDENTIFIER directly. */
5540 if (TREE_CODE (t
) != IDENTIFIER_NODE
)
5541 t
= DECL_ASSEMBLER_NAME (t
);
5542 t
= targetm
.asm_out
.mangle_assembler_name (IDENTIFIER_POINTER (t
));
5543 return pointer_set_contains (aset
, t
);
5546 /* Enter a new name into a symbol alias set. */
5549 symbol_alias_set_insert (symbol_alias_set_t
*aset
, tree t
)
5551 /* We accept either a DECL or an IDENTIFIER directly. */
5552 if (TREE_CODE (t
) != IDENTIFIER_NODE
)
5553 t
= DECL_ASSEMBLER_NAME (t
);
5554 t
= targetm
.asm_out
.mangle_assembler_name (IDENTIFIER_POINTER (t
));
5555 return pointer_set_insert (aset
, t
);
5558 /* IN_SET_P is a predicate function assuming to be taken
5559 alias_pair->decl, alias_pair->target and DATA arguments.
5561 Compute set of aliases by including everything where TRIVIALLY_VISIBLE
5562 predeicate is true and propagate across aliases such that when
5563 alias DECL is included, its TARGET is included too. */
5565 static symbol_alias_set_t
*
5566 propagate_aliases_forward (bool (*in_set_p
)
5567 (tree decl
, tree target
, void *data
),
5570 symbol_alias_set_t
*set
;
5575 set
= symbol_alias_set_create ();
5576 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); ++i
)
5577 if (in_set_p (p
->decl
, p
->target
, data
))
5578 symbol_alias_set_insert (set
, p
->decl
);
5582 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); ++i
)
5583 if (symbol_alias_set_contains (set
, p
->decl
)
5584 && !symbol_alias_set_insert (set
, p
->target
))
5592 /* Like propagate_aliases_forward but do backward propagation. */
5594 symbol_alias_set_t
*
5595 propagate_aliases_backward (bool (*in_set_p
)
5596 (tree decl
, tree target
, void *data
),
5599 symbol_alias_set_t
*set
;
5604 /* We have to compute the set of set nodes including aliases
5606 set
= symbol_alias_set_create ();
5607 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); ++i
)
5608 if (in_set_p (p
->decl
, p
->target
, data
))
5609 symbol_alias_set_insert (set
, p
->target
);
5613 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); ++i
)
5614 if (symbol_alias_set_contains (set
, p
->target
)
5615 && !symbol_alias_set_insert (set
, p
->decl
))
5622 /* See if the alias is trivially visible. This means
5623 1) alias is expoerted from the unit or
5624 2) alias is used in the code.
5625 We assume that unused cgraph/varpool nodes has been
5627 Used as callback for propagate_aliases. */
5630 trivially_visible_alias (tree decl
, tree target ATTRIBUTE_UNUSED
,
5631 void *data ATTRIBUTE_UNUSED
)
5633 struct cgraph_node
*fnode
= NULL
;
5634 struct varpool_node
*vnode
= NULL
;
5636 if (!TREE_PUBLIC (decl
))
5638 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5639 fnode
= cgraph_get_node (decl
);
5641 vnode
= varpool_get_node (decl
);
5642 return vnode
|| fnode
;
5648 /* See if the target of alias is defined in this unit.
5649 Used as callback for propagate_aliases. */
5652 trivially_defined_alias (tree decl ATTRIBUTE_UNUSED
,
5654 void *data ATTRIBUTE_UNUSED
)
5656 struct cgraph_node
*fnode
= NULL
;
5657 struct varpool_node
*vnode
= NULL
;
5659 fnode
= cgraph_node_for_asm (target
);
5660 vnode
= (fnode
== NULL
) ? varpool_node_for_asm (target
) : NULL
;
5661 return (fnode
&& fnode
->analyzed
) || (vnode
&& vnode
->finalized
);
5664 /* Remove the alias pairing for functions that are no longer in the call
5668 remove_unreachable_alias_pairs (void)
5670 symbol_alias_set_t
*visible
;
5674 if (alias_pairs
== NULL
)
5677 /* We have to compute the set of visible nodes including aliases
5679 visible
= propagate_aliases_forward (trivially_visible_alias
, NULL
);
5681 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); )
5683 if (!DECL_EXTERNAL (p
->decl
)
5684 && !symbol_alias_set_contains (visible
, p
->decl
))
5686 VEC_unordered_remove (alias_pair
, alias_pairs
, i
);
5693 symbol_alias_set_destroy (visible
);
5697 /* First pass of completing pending aliases. Make sure that cgraph knows
5698 which symbols will be required. */
5701 finish_aliases_1 (void)
5703 symbol_alias_set_t
*defined
;
5707 if (alias_pairs
== NULL
)
5710 /* We have to compute the set of defined nodes including aliases
5712 defined
= propagate_aliases_backward (trivially_defined_alias
, NULL
);
5714 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5718 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
5719 if (target_decl
== NULL
)
5721 if (symbol_alias_set_contains (defined
, p
->target
))
5724 if (! (p
->emitted_diags
& ALIAS_DIAG_TO_UNDEF
)
5725 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5727 error ("%q+D aliased to undefined symbol %qE",
5728 p
->decl
, p
->target
);
5729 p
->emitted_diags
|= ALIAS_DIAG_TO_UNDEF
;
5732 else if (! (p
->emitted_diags
& ALIAS_DIAG_TO_EXTERN
)
5733 && DECL_EXTERNAL (target_decl
)
5734 /* We use local aliases for C++ thunks to force the tailcall
5735 to bind locally. This is a hack - to keep it working do
5736 the following (which is not strictly correct). */
5737 && (! TREE_CODE (target_decl
) == FUNCTION_DECL
5738 || ! DECL_VIRTUAL_P (target_decl
))
5739 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5741 error ("%q+D aliased to external symbol %qE",
5742 p
->decl
, p
->target
);
5743 p
->emitted_diags
|= ALIAS_DIAG_TO_EXTERN
;
5747 symbol_alias_set_destroy (defined
);
5750 /* Second pass of completing pending aliases. Emit the actual assembly.
5751 This happens at the end of compilation and thus it is assured that the
5752 target symbol has been emitted. */
5755 finish_aliases_2 (void)
5760 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5761 do_assemble_alias (p
->decl
, p
->target
);
5763 VEC_truncate (alias_pair
, alias_pairs
, 0);
5766 /* Emit an assembler directive to make the symbol for DECL an alias to
5767 the symbol for TARGET. */
5770 assemble_alias (tree decl
, tree target
)
5773 bool is_weakref
= false;
5775 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5777 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5781 ultimate_transparent_alias_target (&target
);
5783 if (alias
== target
)
5784 error ("weakref %q+D ultimately targets itself", decl
);
5787 #ifndef ASM_OUTPUT_WEAKREF
5788 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
5789 TREE_CHAIN (alias
) = target
;
5792 if (TREE_PUBLIC (decl
))
5793 error ("weakref %q+D must have static linkage", decl
);
5797 #if !defined (ASM_OUTPUT_DEF)
5798 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5799 error_at (DECL_SOURCE_LOCATION (decl
),
5800 "alias definitions not supported in this configuration");
5803 if (!DECL_WEAK (decl
))
5805 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5806 error_at (DECL_SOURCE_LOCATION (decl
),
5807 "ifunc is not supported in this configuration");
5809 error_at (DECL_SOURCE_LOCATION (decl
),
5810 "only weak aliases are supported in this configuration");
5816 TREE_USED (decl
) = 1;
5818 /* A quirk of the initial implementation of aliases required that the user
5819 add "extern" to all of them. Which is silly, but now historical. Do
5820 note that the symbol is in fact locally defined. */
5822 DECL_EXTERNAL (decl
) = 0;
5824 /* Allow aliases to aliases. */
5825 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5826 cgraph_get_create_node (decl
)->alias
= true;
5828 varpool_node (decl
)->alias
= true;
5830 /* If the target has already been emitted, we don't have to queue the
5831 alias. This saves a tad of memory. */
5832 if (cgraph_global_info_ready
)
5833 target_decl
= find_decl_and_mark_needed (decl
, target
);
5836 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5837 do_assemble_alias (decl
, target
);
5840 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
5843 p
->emitted_diags
= ALIAS_DIAG_NONE
;
5847 /* Emit an assembler directive to set symbol for DECL visibility to
5848 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5851 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5852 int vis ATTRIBUTE_UNUSED
)
5854 #ifdef HAVE_GAS_HIDDEN
5855 static const char * const visibility_types
[] = {
5856 NULL
, "protected", "hidden", "internal"
5859 const char *name
, *type
;
5861 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5862 type
= visibility_types
[vis
];
5864 fprintf (asm_out_file
, "\t.%s\t", type
);
5865 assemble_name (asm_out_file
, name
);
5866 fprintf (asm_out_file
, "\n");
5868 warning (OPT_Wattributes
, "visibility attribute not supported "
5869 "in this configuration; ignored");
5873 /* A helper function to call assemble_visibility when needed for a decl. */
5876 maybe_assemble_visibility (tree decl
)
5878 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5880 if (vis
!= VISIBILITY_DEFAULT
)
5882 targetm
.asm_out
.assemble_visibility (decl
, vis
);
5889 /* Returns 1 if the target configuration supports defining public symbols
5890 so that one of them will be chosen at link time instead of generating a
5891 multiply-defined symbol error, whether through the use of weak symbols or
5892 a target-specific mechanism for having duplicates discarded. */
5895 supports_one_only (void)
5897 if (SUPPORTS_ONE_ONLY
)
5899 return TARGET_SUPPORTS_WEAK
;
5902 /* Set up DECL as a public symbol that can be defined in multiple
5903 translation units without generating a linker error. */
5906 make_decl_one_only (tree decl
, tree comdat_group
)
5908 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5909 || TREE_CODE (decl
) == FUNCTION_DECL
);
5911 TREE_PUBLIC (decl
) = 1;
5913 if (SUPPORTS_ONE_ONLY
)
5915 #ifdef MAKE_DECL_ONE_ONLY
5916 MAKE_DECL_ONE_ONLY (decl
);
5918 DECL_COMDAT_GROUP (decl
) = comdat_group
;
5920 else if (TREE_CODE (decl
) == VAR_DECL
5921 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5922 DECL_COMMON (decl
) = 1;
5925 gcc_assert (TARGET_SUPPORTS_WEAK
);
5926 DECL_WEAK (decl
) = 1;
5931 init_varasm_once (void)
5933 section_htab
= htab_create_ggc (31, section_entry_hash
,
5934 section_entry_eq
, NULL
);
5935 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
5936 object_block_entry_eq
, NULL
);
5937 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
5938 const_desc_eq
, NULL
);
5940 const_alias_set
= new_alias_set ();
5941 shared_constant_pool
= create_constant_pool ();
5943 #ifdef TEXT_SECTION_ASM_OP
5944 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
5945 TEXT_SECTION_ASM_OP
);
5948 #ifdef DATA_SECTION_ASM_OP
5949 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5950 DATA_SECTION_ASM_OP
);
5953 #ifdef SDATA_SECTION_ASM_OP
5954 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5955 SDATA_SECTION_ASM_OP
);
5958 #ifdef READONLY_DATA_SECTION_ASM_OP
5959 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
5960 READONLY_DATA_SECTION_ASM_OP
);
5963 #ifdef CTORS_SECTION_ASM_OP
5964 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
5965 CTORS_SECTION_ASM_OP
);
5968 #ifdef DTORS_SECTION_ASM_OP
5969 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
5970 DTORS_SECTION_ASM_OP
);
5973 #ifdef BSS_SECTION_ASM_OP
5974 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5975 output_section_asm_op
,
5976 BSS_SECTION_ASM_OP
);
5979 #ifdef SBSS_SECTION_ASM_OP
5980 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5981 output_section_asm_op
,
5982 SBSS_SECTION_ASM_OP
);
5985 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5986 | SECTION_COMMON
, emit_tls_common
);
5987 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5988 | SECTION_COMMON
, emit_local
);
5989 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5990 | SECTION_COMMON
, emit_common
);
5992 #if defined ASM_OUTPUT_ALIGNED_BSS
5993 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
5997 targetm
.asm_out
.init_sections ();
5999 if (readonly_data_section
== NULL
)
6000 readonly_data_section
= text_section
;
6004 decl_default_tls_model (const_tree decl
)
6006 enum tls_model kind
;
6009 is_local
= targetm
.binds_local_p (decl
);
6013 kind
= TLS_MODEL_LOCAL_EXEC
;
6015 kind
= TLS_MODEL_INITIAL_EXEC
;
6018 /* Local dynamic is inefficient when we're not combining the
6019 parts of the address. */
6020 else if (optimize
&& is_local
)
6021 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6023 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6024 if (kind
< flag_tls_default
)
6025 kind
= flag_tls_default
;
6030 /* Select a set of attributes for section NAME based on the properties
6031 of DECL and whether or not RELOC indicates that DECL's initializer
6032 might contain runtime relocations.
6034 We make the section read-only and executable for a function decl,
6035 read-only for a const data decl, and writable for a non-const data decl. */
6038 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6042 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6043 flags
= SECTION_CODE
;
6046 enum section_category category
6047 = categorize_decl_for_section (decl
, reloc
);
6048 if (decl_readonly_section_1 (category
))
6050 else if (category
== SECCAT_DATA_REL_RO
6051 || category
== SECCAT_DATA_REL_RO_LOCAL
)
6052 flags
= SECTION_WRITE
| SECTION_RELRO
;
6054 flags
= SECTION_WRITE
;
6058 flags
= SECTION_WRITE
;
6059 if (strcmp (name
, ".data.rel.ro") == 0
6060 || strcmp (name
, ".data.rel.ro.local") == 0)
6061 flags
|= SECTION_RELRO
;
6064 if (decl
&& DECL_ONE_ONLY (decl
))
6065 flags
|= SECTION_LINKONCE
;
6067 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6068 flags
|= SECTION_TLS
| SECTION_WRITE
;
6070 if (strcmp (name
, ".bss") == 0
6071 || strncmp (name
, ".bss.", 5) == 0
6072 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6073 || strcmp (name
, ".sbss") == 0
6074 || strncmp (name
, ".sbss.", 6) == 0
6075 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6076 flags
|= SECTION_BSS
;
6078 if (strcmp (name
, ".tdata") == 0
6079 || strncmp (name
, ".tdata.", 7) == 0
6080 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6081 flags
|= SECTION_TLS
;
6083 if (strcmp (name
, ".tbss") == 0
6084 || strncmp (name
, ".tbss.", 6) == 0
6085 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6086 flags
|= SECTION_TLS
| SECTION_BSS
;
6088 /* These three sections have special ELF types. They are neither
6089 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6090 want to print a section type (@progbits or @nobits). If someone
6091 is silly enough to emit code or TLS variables to one of these
6092 sections, then don't handle them specially. */
6093 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
6094 && (strcmp (name
, ".init_array") == 0
6095 || strcmp (name
, ".fini_array") == 0
6096 || strcmp (name
, ".preinit_array") == 0))
6097 flags
|= SECTION_NOTYPE
;
6102 /* Return true if the target supports some form of global BSS,
6103 either through bss_noswitch_section, or by selecting a BSS
6104 section in TARGET_ASM_SELECT_SECTION. */
6107 have_global_bss_p (void)
6109 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6112 /* Output assembly to switch to section NAME with attribute FLAGS.
6113 Four variants for common object file formats. */
6116 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6117 unsigned int flags ATTRIBUTE_UNUSED
,
6118 tree decl ATTRIBUTE_UNUSED
)
6120 /* Some object formats don't support named sections at all. The
6121 front-end should already have flagged this as an error. */
6125 #ifndef TLS_SECTION_ASM_FLAG
6126 #define TLS_SECTION_ASM_FLAG 'T'
6130 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6131 tree decl ATTRIBUTE_UNUSED
)
6133 char flagchars
[10], *f
= flagchars
;
6135 /* If we have already declared this section, we can use an
6136 abbreviated form to switch back to it -- unless this section is
6137 part of a COMDAT groups, in which case GAS requires the full
6138 declaration every time. */
6139 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6140 && (flags
& SECTION_DECLARED
))
6142 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6146 if (!(flags
& SECTION_DEBUG
))
6148 if (flags
& SECTION_WRITE
)
6150 if (flags
& SECTION_CODE
)
6152 if (flags
& SECTION_SMALL
)
6154 if (flags
& SECTION_MERGE
)
6156 if (flags
& SECTION_STRINGS
)
6158 if (flags
& SECTION_TLS
)
6159 *f
++ = TLS_SECTION_ASM_FLAG
;
6160 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6164 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6166 if (!(flags
& SECTION_NOTYPE
))
6171 if (flags
& SECTION_BSS
)
6177 #ifdef ASM_COMMENT_START
6178 /* On platforms that use "@" as the assembly comment character,
6180 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6183 fprintf (asm_out_file
, format
, type
);
6185 if (flags
& SECTION_ENTSIZE
)
6186 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6187 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6189 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6190 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6192 fprintf (asm_out_file
, ",%s,comdat",
6193 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6197 putc ('\n', asm_out_file
);
6201 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6202 tree decl ATTRIBUTE_UNUSED
)
6204 char flagchars
[8], *f
= flagchars
;
6206 if (flags
& SECTION_WRITE
)
6208 if (flags
& SECTION_CODE
)
6212 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6216 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6219 default_coff_asm_named_section (name
, flags
, decl
);
6221 if (flags
& SECTION_LINKONCE
)
6223 /* Functions may have been compiled at various levels of
6224 optimization so we can't use `same_size' here.
6225 Instead, have the linker pick one. */
6226 fprintf (asm_out_file
, "\t.linkonce %s\n",
6227 (flags
& SECTION_CODE
? "discard" : "same_size"));
6231 /* The lame default section selector. */
6234 default_select_section (tree decl
, int reloc
,
6235 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6239 if (decl_readonly_section (decl
, reloc
))
6240 return readonly_data_section
;
6242 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6244 if (! ((flag_pic
&& reloc
)
6245 || !TREE_READONLY (decl
)
6246 || TREE_SIDE_EFFECTS (decl
)
6247 || !TREE_CONSTANT (decl
)))
6248 return readonly_data_section
;
6250 else if (TREE_CODE (decl
) == STRING_CST
)
6251 return readonly_data_section
;
6252 else if (! (flag_pic
&& reloc
))
6253 return readonly_data_section
;
6255 return data_section
;
6258 enum section_category
6259 categorize_decl_for_section (const_tree decl
, int reloc
)
6261 enum section_category ret
;
6263 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6265 else if (TREE_CODE (decl
) == STRING_CST
)
6267 if (flag_mudflap
) /* or !flag_merge_constants */
6268 return SECCAT_RODATA
;
6270 return SECCAT_RODATA_MERGE_STR
;
6272 else if (TREE_CODE (decl
) == VAR_DECL
)
6274 if (bss_initializer_p (decl
))
6276 else if (! TREE_READONLY (decl
)
6277 || TREE_SIDE_EFFECTS (decl
)
6278 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6280 /* Here the reloc_rw_mask is not testing whether the section should
6281 be read-only or not, but whether the dynamic link will have to
6282 do something. If so, we wish to segregate the data in order to
6283 minimize cache misses inside the dynamic linker. */
6284 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6285 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6289 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6290 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6291 else if (reloc
|| flag_merge_constants
< 2)
6292 /* C and C++ don't allow different variables to share the same
6293 location. -fmerge-all-constants allows even that (at the
6294 expense of not conforming). */
6295 ret
= SECCAT_RODATA
;
6296 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6297 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6299 ret
= SECCAT_RODATA_MERGE_CONST
;
6301 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6303 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6304 || TREE_SIDE_EFFECTS (decl
)
6305 || ! TREE_CONSTANT (decl
))
6308 ret
= SECCAT_RODATA
;
6311 ret
= SECCAT_RODATA
;
6313 /* There are no read-only thread-local sections. */
6314 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6316 /* Note that this would be *just* SECCAT_BSS, except that there's
6317 no concept of a read-only thread-local-data section. */
6318 if (ret
== SECCAT_BSS
6319 || (flag_zero_initialized_in_bss
6320 && initializer_zerop (DECL_INITIAL (decl
))))
6326 /* If the target uses small data sections, select it. */
6327 else if (targetm
.in_small_data_p (decl
))
6329 if (ret
== SECCAT_BSS
)
6331 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6332 ret
= SECCAT_SRODATA
;
6341 decl_readonly_section_1 (enum section_category category
)
6346 case SECCAT_RODATA_MERGE_STR
:
6347 case SECCAT_RODATA_MERGE_STR_INIT
:
6348 case SECCAT_RODATA_MERGE_CONST
:
6349 case SECCAT_SRODATA
:
6357 decl_readonly_section (const_tree decl
, int reloc
)
6359 return decl_readonly_section_1 (categorize_decl_for_section (decl
, reloc
));
6362 /* Select a section based on the above categorization. */
6365 default_elf_select_section (tree decl
, int reloc
,
6366 unsigned HOST_WIDE_INT align
)
6369 switch (categorize_decl_for_section (decl
, reloc
))
6372 /* We're not supposed to be called on FUNCTION_DECLs. */
6375 return readonly_data_section
;
6376 case SECCAT_RODATA_MERGE_STR
:
6377 return mergeable_string_section (decl
, align
, 0);
6378 case SECCAT_RODATA_MERGE_STR_INIT
:
6379 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6380 case SECCAT_RODATA_MERGE_CONST
:
6381 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6382 case SECCAT_SRODATA
:
6386 return data_section
;
6387 case SECCAT_DATA_REL
:
6388 sname
= ".data.rel";
6390 case SECCAT_DATA_REL_LOCAL
:
6391 sname
= ".data.rel.local";
6393 case SECCAT_DATA_REL_RO
:
6394 sname
= ".data.rel.ro";
6396 case SECCAT_DATA_REL_RO_LOCAL
:
6397 sname
= ".data.rel.ro.local";
6422 return get_named_section (decl
, sname
, reloc
);
6425 /* Construct a unique section name based on the decl name and the
6426 categorization performed above. */
6429 default_unique_section (tree decl
, int reloc
)
6431 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6432 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6433 const char *prefix
, *name
, *linkonce
;
6436 switch (categorize_decl_for_section (decl
, reloc
))
6439 prefix
= one_only
? ".t" : ".text";
6442 case SECCAT_RODATA_MERGE_STR
:
6443 case SECCAT_RODATA_MERGE_STR_INIT
:
6444 case SECCAT_RODATA_MERGE_CONST
:
6445 prefix
= one_only
? ".r" : ".rodata";
6447 case SECCAT_SRODATA
:
6448 prefix
= one_only
? ".s2" : ".sdata2";
6451 prefix
= one_only
? ".d" : ".data";
6453 case SECCAT_DATA_REL
:
6454 prefix
= one_only
? ".d.rel" : ".data.rel";
6456 case SECCAT_DATA_REL_LOCAL
:
6457 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6459 case SECCAT_DATA_REL_RO
:
6460 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6462 case SECCAT_DATA_REL_RO_LOCAL
:
6463 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6466 prefix
= one_only
? ".s" : ".sdata";
6469 prefix
= one_only
? ".b" : ".bss";
6472 prefix
= one_only
? ".sb" : ".sbss";
6475 prefix
= one_only
? ".td" : ".tdata";
6478 prefix
= one_only
? ".tb" : ".tbss";
6484 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6485 name
= targetm
.strip_name_encoding (name
);
6487 /* If we're using one_only, then there needs to be a .gnu.linkonce
6488 prefix to the section name. */
6489 linkonce
= one_only
? ".gnu.linkonce" : "";
6491 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6493 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6496 /* Like compute_reloc_for_constant, except for an RTX. The return value
6497 is a mask for which bit 1 indicates a global relocation, and bit 0
6498 indicates a local relocation. */
6501 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6503 int *preloc
= (int *) data
;
6506 switch (GET_CODE (x
))
6509 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6522 compute_reloc_for_rtx (rtx x
)
6526 switch (GET_CODE (x
))
6532 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6541 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6543 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6545 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6546 return data_section
;
6548 return readonly_data_section
;
6552 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6553 unsigned HOST_WIDE_INT align
)
6555 int reloc
= compute_reloc_for_rtx (x
);
6557 /* ??? Handle small data here somehow. */
6559 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6562 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6564 return get_named_section (NULL
, ".data.rel.ro", 3);
6567 return mergeable_constant_section (mode
, align
, 0);
6570 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6573 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6578 /* Careful not to prod global register variables. */
6581 symbol
= XEXP (rtl
, 0);
6582 if (GET_CODE (symbol
) != SYMBOL_REF
)
6585 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6586 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6587 flags
|= SYMBOL_FLAG_FUNCTION
;
6588 if (targetm
.binds_local_p (decl
))
6589 flags
|= SYMBOL_FLAG_LOCAL
;
6590 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6591 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6592 else if (targetm
.in_small_data_p (decl
))
6593 flags
|= SYMBOL_FLAG_SMALL
;
6594 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6595 being PUBLIC, the thing *must* be defined in this translation unit.
6596 Prevent this buglet from being propagated into rtl code as well. */
6597 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6598 flags
|= SYMBOL_FLAG_EXTERNAL
;
6600 SYMBOL_REF_FLAGS (symbol
) = flags
;
6603 /* By default, we do nothing for encode_section_info, so we need not
6604 do anything but discard the '*' marker. */
6607 default_strip_name_encoding (const char *str
)
6609 return str
+ (*str
== '*');
6612 #ifdef ASM_OUTPUT_DEF
6613 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6614 anchor relative to ".", the current section position. */
6617 default_asm_output_anchor (rtx symbol
)
6621 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6622 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6623 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6627 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6630 default_use_anchors_for_symbol_p (const_rtx symbol
)
6635 /* Don't use anchors for mergeable sections. The linker might move
6636 the objects around. */
6637 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6638 if (sect
->common
.flags
& SECTION_MERGE
)
6641 /* Don't use anchors for small data sections. The small data register
6642 acts as an anchor for such sections. */
6643 if (sect
->common
.flags
& SECTION_SMALL
)
6646 decl
= SYMBOL_REF_DECL (symbol
);
6647 if (decl
&& DECL_P (decl
))
6649 /* Don't use section anchors for decls that might be defined by
6651 if (!targetm
.binds_local_p (decl
))
6654 /* Don't use section anchors for decls that will be placed in a
6655 small data section. */
6656 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6657 one above. The problem is that we only use SECTION_SMALL for
6658 sections that should be marked as small in the section directive. */
6659 if (targetm
.in_small_data_p (decl
))
6665 /* Return true when RESOLUTION indicate that symbol will be bound to the
6666 definition provided by current .o file. */
6669 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
6671 return (resolution
== LDPR_PREVAILING_DEF
6672 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
6675 /* Return true when RESOLUTION indicate that symbol will be bound locally
6676 within current executable or DSO. */
6679 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
6681 return (resolution
== LDPR_PREVAILING_DEF
6682 || resolution
== LDPR_PREVAILING_DEF_IRONLY
6683 || resolution
== LDPR_PREEMPTED_REG
6684 || resolution
== LDPR_PREEMPTED_IR
6685 || resolution
== LDPR_RESOLVED_IR
6686 || resolution
== LDPR_RESOLVED_EXEC
);
6689 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6690 wrt cross-module name binding. */
6693 default_binds_local_p (const_tree exp
)
6695 return default_binds_local_p_1 (exp
, flag_shlib
);
6699 default_binds_local_p_1 (const_tree exp
, int shlib
)
6702 bool resolved_locally
= false;
6703 bool resolved_to_local_def
= false;
6705 /* With resolution file in hands, take look into resolutions.
6706 We can't just return true for resolved_localy symbols,
6707 because dynamic linking might overwrite symbols
6708 in shared libraries. */
6709 if (TREE_CODE (exp
) == VAR_DECL
&& TREE_PUBLIC (exp
)
6710 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
6712 struct varpool_node
*vnode
= varpool_get_node (exp
);
6713 if (vnode
&& resolution_local_p (vnode
->resolution
))
6714 resolved_locally
= true;
6716 && resolution_to_local_definition_p (vnode
->resolution
))
6717 resolved_to_local_def
= true;
6719 else if (TREE_CODE (exp
) == FUNCTION_DECL
&& TREE_PUBLIC (exp
))
6721 struct cgraph_node
*node
= cgraph_get_node_or_alias (exp
);
6723 && resolution_local_p (node
->resolution
))
6724 resolved_locally
= true;
6726 && resolution_to_local_definition_p (node
->resolution
))
6727 resolved_to_local_def
= true;
6730 /* A non-decl is an entry in the constant pool. */
6733 /* Weakrefs may not bind locally, even though the weakref itself is
6734 always static and therefore local.
6735 FIXME: We can resolve this more curefuly by looking at the weakref
6737 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
6739 /* Static variables are always local. */
6740 else if (! TREE_PUBLIC (exp
))
6742 /* A variable is local if the user has said explicitly that it will
6744 else if ((DECL_VISIBILITY_SPECIFIED (exp
)
6745 || resolved_to_local_def
)
6746 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6748 /* Variables defined outside this object might not be local. */
6749 else if (DECL_EXTERNAL (exp
) && !resolved_locally
)
6751 /* If defined in this object and visibility is not default, must be
6753 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6755 /* Default visibility weak data can be overridden by a strong symbol
6756 in another module and so are not local. */
6757 else if (DECL_WEAK (exp
)
6758 && !resolved_locally
)
6760 /* If PIC, then assume that any global name can be overridden by
6761 symbols resolved from other modules. */
6764 /* Uninitialized COMMON variable may be unified with symbols
6765 resolved from other modules. */
6766 else if (DECL_COMMON (exp
)
6767 && !resolved_locally
6768 && (DECL_INITIAL (exp
) == NULL
6769 || DECL_INITIAL (exp
) == error_mark_node
))
6771 /* Otherwise we're left with initialized (or non-common) global data
6772 which is of necessity defined locally. */
6779 /* Return true when references to DECL must bind to current definition in
6782 The condition is usually equivalent to whether the function binds to the
6783 current module (shared library or executable), that is to binds_local_p.
6784 We use this fact to avoid need for another target hook and implement
6785 the logic using binds_local_p and just special cases where
6786 decl_binds_to_current_def_p is stronger than binds_local_p. In particular
6787 the weak definitions (that can be overwritten at linktime by other
6788 definition from different object file) and when resolution info is available
6789 we simply use the knowledge passed to us by linker plugin. */
6791 decl_binds_to_current_def_p (tree decl
)
6793 gcc_assert (DECL_P (decl
));
6794 if (!TREE_PUBLIC (decl
))
6796 if (!targetm
.binds_local_p (decl
))
6798 /* When resolution is available, just use it. */
6799 if (TREE_CODE (decl
) == VAR_DECL
6800 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
6802 struct varpool_node
*vnode
= varpool_get_node (decl
);
6804 && vnode
->resolution
!= LDPR_UNKNOWN
)
6805 return resolution_to_local_definition_p (vnode
->resolution
);
6807 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
6809 struct cgraph_node
*node
= cgraph_get_node_or_alias (decl
);
6811 && node
->resolution
!= LDPR_UNKNOWN
)
6812 return resolution_to_local_definition_p (node
->resolution
);
6814 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
6815 binds localy but still can be overwritten).
6816 This rely on fact that binds_local_p behave as decl_replaceable_p
6817 for all other declaration types. */
6818 return !DECL_WEAK (decl
);
6821 /* A replaceable function or variable is one which may be replaced
6822 at link-time with an entirely different definition, provided that the
6823 replacement has the same type. For example, functions declared
6824 with __attribute__((weak)) on most systems are replaceable.
6826 COMDAT functions are not replaceable, since all definitions of the
6827 function must be equivalent. It is important that COMDAT functions
6828 not be treated as replaceable so that use of C++ template
6829 instantiations is not penalized. */
6832 decl_replaceable_p (tree decl
)
6834 gcc_assert (DECL_P (decl
));
6835 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
6837 return !decl_binds_to_current_def_p (decl
);
6840 /* Default function to output code that will globalize a label. A
6841 target must define GLOBAL_ASM_OP or provide its own function to
6842 globalize a label. */
6843 #ifdef GLOBAL_ASM_OP
6845 default_globalize_label (FILE * stream
, const char *name
)
6847 fputs (GLOBAL_ASM_OP
, stream
);
6848 assemble_name (stream
, name
);
6849 putc ('\n', stream
);
6851 #endif /* GLOBAL_ASM_OP */
6853 /* Default function to output code that will globalize a declaration. */
6855 default_globalize_decl_name (FILE * stream
, tree decl
)
6857 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6858 targetm
.asm_out
.globalize_label (stream
, name
);
6861 /* Default function to output a label for unwind information. The
6862 default is to do nothing. A target that needs nonlocal labels for
6863 unwind information must provide its own function to do this. */
6865 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6866 tree decl ATTRIBUTE_UNUSED
,
6867 int for_eh ATTRIBUTE_UNUSED
,
6868 int empty ATTRIBUTE_UNUSED
)
6872 /* Default function to output a label to divide up the exception table.
6873 The default is to do nothing. A target that needs/wants to divide
6874 up the table must provide it's own function to do this. */
6876 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6880 /* This is how to output an internal numbered label where PREFIX is
6881 the class of label and LABELNO is the number within the class. */
6884 default_generate_internal_label (char *buf
, const char *prefix
,
6885 unsigned long labelno
)
6887 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6890 /* This is how to output an internal numbered label where PREFIX is
6891 the class of label and LABELNO is the number within the class. */
6894 default_internal_label (FILE *stream
, const char *prefix
,
6895 unsigned long labelno
)
6897 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6898 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6899 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6903 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6906 default_asm_declare_constant_name (FILE *file
, const char *name
,
6907 const_tree exp ATTRIBUTE_UNUSED
,
6908 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
6910 assemble_label (file
, name
);
6913 /* This is the default behavior at the beginning of a file. It's
6914 controlled by two other target-hook toggles. */
6916 default_file_start (void)
6918 if (targetm
.asm_file_start_app_off
6919 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6920 fputs (ASM_APP_OFF
, asm_out_file
);
6922 if (targetm
.asm_file_start_file_directive
)
6923 output_file_directive (asm_out_file
, main_input_filename
);
6926 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6927 which emits a special section directive used to indicate whether or
6928 not this object file needs an executable stack. This is primarily
6929 a GNU extension to ELF but could be used on other targets. */
6931 int trampolines_created
;
6934 file_end_indicate_exec_stack (void)
6936 unsigned int flags
= SECTION_DEBUG
;
6937 if (trampolines_created
)
6938 flags
|= SECTION_CODE
;
6940 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6943 /* Emit a special section directive to indicate that this object file
6944 was compiled with -fsplit-stack. This is used to let the linker
6945 detect calls between split-stack code and non-split-stack code, so
6946 that it can modify the split-stack code to allocate a sufficiently
6947 large stack. We emit another special section if there are any
6948 functions in this file which have the no_split_stack attribute, to
6949 prevent the linker from warning about being unable to convert the
6950 functions if they call non-split-stack code. */
6953 file_end_indicate_split_stack (void)
6955 if (flag_split_stack
)
6957 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
6959 if (saw_no_split_stack
)
6960 switch_to_section (get_section (".note.GNU-no-split-stack",
6961 SECTION_DEBUG
, NULL
));
6965 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6966 a get_unnamed_section callback. */
6969 output_section_asm_op (const void *directive
)
6971 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
6974 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6975 the current section is NEW_SECTION. */
6978 switch_to_section (section
*new_section
)
6980 if (in_section
== new_section
)
6983 if (new_section
->common
.flags
& SECTION_FORGET
)
6986 in_section
= new_section
;
6988 switch (SECTION_STYLE (new_section
))
6991 targetm
.asm_out
.named_section (new_section
->named
.name
,
6992 new_section
->named
.common
.flags
,
6993 new_section
->named
.decl
);
6996 case SECTION_UNNAMED
:
6997 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
7000 case SECTION_NOSWITCH
:
7005 new_section
->common
.flags
|= SECTION_DECLARED
;
7008 /* If block symbol SYMBOL has not yet been assigned an offset, place
7009 it at the end of its block. */
7012 place_block_symbol (rtx symbol
)
7014 unsigned HOST_WIDE_INT size
, mask
, offset
;
7015 struct constant_descriptor_rtx
*desc
;
7016 unsigned int alignment
;
7017 struct object_block
*block
;
7020 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
7021 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
7024 /* Work out the symbol's size and alignment. */
7025 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7027 desc
= SYMBOL_REF_CONSTANT (symbol
);
7028 alignment
= desc
->align
;
7029 size
= GET_MODE_SIZE (desc
->mode
);
7031 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7033 decl
= SYMBOL_REF_DECL (symbol
);
7034 alignment
= DECL_ALIGN (decl
);
7035 size
= get_constant_size (DECL_INITIAL (decl
));
7039 decl
= SYMBOL_REF_DECL (symbol
);
7040 alignment
= DECL_ALIGN (decl
);
7041 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
7044 /* Calculate the object's offset from the start of the block. */
7045 block
= SYMBOL_REF_BLOCK (symbol
);
7046 mask
= alignment
/ BITS_PER_UNIT
- 1;
7047 offset
= (block
->size
+ mask
) & ~mask
;
7048 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
7050 /* Record the block's new alignment and size. */
7051 block
->alignment
= MAX (block
->alignment
, alignment
);
7052 block
->size
= offset
+ size
;
7054 VEC_safe_push (rtx
, gc
, block
->objects
, symbol
);
7057 /* Return the anchor that should be used to address byte offset OFFSET
7058 from the first object in BLOCK. MODEL is the TLS model used
7062 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7063 enum tls_model model
)
7066 unsigned int begin
, middle
, end
;
7067 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7070 /* Work out the anchor's offset. Use an offset of 0 for the first
7071 anchor so that we don't pessimize the case where we take the address
7072 of a variable at the beginning of the block. This is particularly
7073 useful when a block has only one variable assigned to it.
7075 We try to place anchors RANGE bytes apart, so there can then be
7076 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7077 a ptr_mode offset. With some target settings, the lowest such
7078 anchor might be out of range for the lowest ptr_mode offset;
7079 likewise the highest anchor for the highest offset. Use anchors
7080 at the extreme ends of the ptr_mode range in such cases.
7082 All arithmetic uses unsigned integers in order to avoid
7084 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7085 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7086 range
= max_offset
- min_offset
+ 1;
7091 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
7094 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7095 delta
-= delta
% range
;
7098 offset
= (HOST_WIDE_INT
) (-delta
);
7102 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7103 delta
-= delta
% range
;
7104 if (delta
> bias
- 1)
7106 offset
= (HOST_WIDE_INT
) delta
;
7110 /* Do a binary search to see if there's already an anchor we can use.
7111 Set BEGIN to the new anchor's index if not. */
7113 end
= VEC_length (rtx
, block
->anchors
);
7114 while (begin
!= end
)
7116 middle
= (end
+ begin
) / 2;
7117 anchor
= VEC_index (rtx
, block
->anchors
, middle
);
7118 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7120 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7122 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7124 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7130 /* Create a new anchor with a unique label. */
7131 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7132 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7133 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7134 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7136 /* Insert it at index BEGIN. */
7137 VEC_safe_insert (rtx
, gc
, block
->anchors
, begin
, anchor
);
7141 /* Output the objects in BLOCK. */
7144 output_object_block (struct object_block
*block
)
7146 struct constant_descriptor_rtx
*desc
;
7148 HOST_WIDE_INT offset
;
7152 if (block
->objects
== NULL
)
7155 /* Switch to the section and make sure that the first byte is
7156 suitably aligned. */
7157 switch_to_section (block
->sect
);
7158 assemble_align (block
->alignment
);
7160 /* Define the values of all anchors relative to the current section
7162 FOR_EACH_VEC_ELT (rtx
, block
->anchors
, i
, symbol
)
7163 targetm
.asm_out
.output_anchor (symbol
);
7165 /* Output the objects themselves. */
7167 FOR_EACH_VEC_ELT (rtx
, block
->objects
, i
, symbol
)
7169 /* Move to the object's offset, padding with zeros if necessary. */
7170 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7171 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7172 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7174 desc
= SYMBOL_REF_CONSTANT (symbol
);
7175 output_constant_pool_1 (desc
, 1);
7176 offset
+= GET_MODE_SIZE (desc
->mode
);
7178 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7180 decl
= SYMBOL_REF_DECL (symbol
);
7181 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
7183 offset
+= get_constant_size (DECL_INITIAL (decl
));
7187 decl
= SYMBOL_REF_DECL (symbol
);
7188 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
7189 offset
+= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
7194 /* A htab_traverse callback used to call output_object_block for
7195 each member of object_block_htab. */
7198 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
7200 output_object_block ((struct object_block
*) (*slot
));
7204 /* Output the definitions of all object_blocks. */
7207 output_object_blocks (void)
7209 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
7212 /* This function provides a possible implementation of the
7213 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7214 by -frecord-gcc-switches it creates a new mergeable, string section in the
7215 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7216 contains the switches in ASCII format.
7218 FIXME: This code does not correctly handle double quote characters
7219 that appear inside strings, (it strips them rather than preserving them).
7220 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7221 characters - instead it treats them as sub-string separators. Since
7222 we want to emit NUL strings terminators into the object file we have to use
7226 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7230 case SWITCH_TYPE_PASSED
:
7231 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
7232 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7235 case SWITCH_TYPE_DESCRIPTIVE
:
7238 /* Distinguish between invocations where name is NULL. */
7239 static bool started
= false;
7245 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7249 | (SECTION_ENTSIZE
& 1),
7251 switch_to_section (sec
);
7260 /* The return value is currently ignored by the caller, but must be 0.
7261 For -fverbose-asm the return value would be the number of characters
7262 emitted into the assembler file. */
7266 /* Emit text to declare externally defined symbols. It is needed to
7267 properly support non-default visibility. */
7269 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7271 const char *name ATTRIBUTE_UNUSED
)
7273 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7274 set in order to avoid putting out names that are never really
7276 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7277 && targetm
.binds_local_p (decl
))
7278 maybe_assemble_visibility (decl
);
7281 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7284 default_asm_output_source_filename (FILE *file
, const char *name
)
7286 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7287 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
7289 fprintf (file
, "\t.file\t");
7290 output_quoted_string (file
, name
);
7295 /* Output a file name in the form wanted by System V. */
7298 output_file_directive (FILE *asm_file
, const char *input_name
)
7303 if (input_name
== NULL
)
7304 input_name
= "<stdin>";
7306 input_name
= remap_debug_filename (input_name
);
7308 len
= strlen (input_name
);
7309 na
= input_name
+ len
;
7311 /* NA gets INPUT_NAME sans directory names. */
7312 while (na
> input_name
)
7314 if (IS_DIR_SEPARATOR (na
[-1]))
7319 targetm
.asm_out
.output_source_filename (asm_file
, na
);
7322 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7325 make_debug_expr_from_rtl (const_rtx exp
)
7327 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7328 enum machine_mode mode
= GET_MODE (exp
);
7331 DECL_ARTIFICIAL (ddecl
) = 1;
7332 if (REG_P (exp
) && REG_EXPR (exp
))
7333 type
= TREE_TYPE (REG_EXPR (exp
));
7334 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7335 type
= TREE_TYPE (MEM_EXPR (exp
));
7338 if (type
&& TYPE_MODE (type
) == mode
)
7339 TREE_TYPE (ddecl
) = type
;
7341 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7342 DECL_MODE (ddecl
) = mode
;
7343 dval
= gen_rtx_DEBUG_EXPR (mode
);
7344 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7345 SET_DECL_RTL (ddecl
, dval
);
7349 #include "gt-varasm.h"