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 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"
46 #include "langhooks.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
56 #include "pointer-set.h"
58 #ifdef XCOFF_DEBUGGING_INFO
59 #include "xcoffout.h" /* Needed for external data
60 declarations for e.g. AIX 4.x. */
63 /* The (assembler) name of the first globally-visible object output. */
64 extern GTY(()) const char *first_global_object_name
;
65 extern GTY(()) const char *weak_global_object_name
;
67 const char *first_global_object_name
;
68 const char *weak_global_object_name
;
71 struct constant_descriptor_rtx
;
72 struct rtx_constant_pool
;
74 #define n_deferred_constants (crtl->varasm.deferred_constants)
76 /* Number for making the label on the next
77 constant that is stored in memory. */
79 static GTY(()) int const_labelno
;
81 /* Carry information from ASM_DECLARE_OBJECT_NAME
82 to ASM_FINISH_DECLARE_OBJECT. */
84 int size_directive_output
;
86 /* The last decl for which assemble_variable was called,
87 if it did ASM_DECLARE_OBJECT_NAME.
88 If the last call to assemble_variable didn't do that,
91 tree last_assemble_variable_decl
;
93 /* The following global variable indicates if the first basic block
94 in a function belongs to the cold partition or not. */
96 bool first_function_block_is_cold
;
98 /* We give all constants their own alias set. Perhaps redundant with
99 MEM_READONLY_P, but pre-dates it. */
101 static alias_set_type const_alias_set
;
103 /* Whether we saw any functions with no_split_stack. */
105 static bool saw_no_split_stack
;
107 static const char *strip_reg_name (const char *);
108 static int contains_pointers_p (tree
);
109 #ifdef ASM_OUTPUT_EXTERNAL
110 static bool incorporeal_function_p (tree
);
112 static void decode_addr_const (tree
, struct addr_const
*);
113 static hashval_t
const_desc_hash (const void *);
114 static int const_desc_eq (const void *, const void *);
115 static hashval_t
const_hash_1 (const tree
);
116 static int compare_constant (const tree
, const tree
);
117 static tree
copy_constant (tree
);
118 static void output_constant_def_contents (rtx
);
119 static void output_addressed_constants (tree
);
120 static unsigned HOST_WIDE_INT
array_size_for_constructor (tree
);
121 static unsigned min_align (unsigned, unsigned);
122 static void globalize_decl (tree
);
123 #ifdef BSS_SECTION_ASM_OP
124 #ifdef ASM_OUTPUT_BSS
125 static void asm_output_bss (FILE *, tree
, const char *,
126 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
128 #ifdef ASM_OUTPUT_ALIGNED_BSS
129 static void asm_output_aligned_bss (FILE *, tree
, const char *,
130 unsigned HOST_WIDE_INT
, int)
133 #endif /* BSS_SECTION_ASM_OP */
134 static void mark_weak (tree
);
135 static void output_constant_pool (const char *, tree
);
137 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
138 section
*text_section
;
139 section
*data_section
;
140 section
*readonly_data_section
;
141 section
*sdata_section
;
142 section
*ctors_section
;
143 section
*dtors_section
;
144 section
*bss_section
;
145 section
*sbss_section
;
147 /* Various forms of common section. All are guaranteed to be nonnull. */
148 section
*tls_comm_section
;
149 section
*comm_section
;
150 section
*lcomm_section
;
152 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
154 section
*bss_noswitch_section
;
156 /* The section that holds the main exception table, when known. The section
157 is set either by the target's init_sections hook or by the first call to
158 switch_to_exception_section. */
159 section
*exception_section
;
161 /* The section that holds the DWARF2 frame unwind information, when known.
162 The section is set either by the target's init_sections hook or by the
163 first call to switch_to_eh_frame_section. */
164 section
*eh_frame_section
;
166 /* asm_out_file's current section. This is NULL if no section has yet
167 been selected or if we lose track of what the current section is. */
170 /* True if code for the current function is currently being directed
171 at the cold section. */
172 bool in_cold_section_p
;
174 /* A linked list of all the unnamed sections. */
175 static GTY(()) section
*unnamed_sections
;
177 /* Return a nonzero value if DECL has a section attribute. */
178 #define IN_NAMED_SECTION(DECL) \
179 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
180 && DECL_SECTION_NAME (DECL) != NULL_TREE)
182 /* Hash table of named sections. */
183 static GTY((param_is (section
))) htab_t section_htab
;
185 /* A table of object_blocks, indexed by section. */
186 static GTY((param_is (struct object_block
))) htab_t object_block_htab
;
188 /* The next number to use for internal anchor labels. */
189 static GTY(()) int anchor_labelno
;
191 /* A pool of constants that can be shared between functions. */
192 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
194 /* Helper routines for maintaining section_htab. */
197 section_entry_eq (const void *p1
, const void *p2
)
199 const section
*old
= (const section
*) p1
;
200 const char *new_name
= (const char *) p2
;
202 return strcmp (old
->named
.name
, new_name
) == 0;
206 section_entry_hash (const void *p
)
208 const section
*old
= (const section
*) p
;
209 return htab_hash_string (old
->named
.name
);
212 /* Return a hash value for section SECT. */
215 hash_section (section
*sect
)
217 if (sect
->common
.flags
& SECTION_NAMED
)
218 return htab_hash_string (sect
->named
.name
);
219 return sect
->common
.flags
;
222 /* Helper routines for maintaining object_block_htab. */
225 object_block_entry_eq (const void *p1
, const void *p2
)
227 const struct object_block
*old
= (const struct object_block
*) p1
;
228 const section
*new_section
= (const section
*) p2
;
230 return old
->sect
== new_section
;
234 object_block_entry_hash (const void *p
)
236 const struct object_block
*old
= (const struct object_block
*) p
;
237 return hash_section (old
->sect
);
240 /* Return a new unnamed section with the given fields. */
243 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
248 sect
= ggc_alloc_section ();
249 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
250 sect
->unnamed
.callback
= callback
;
251 sect
->unnamed
.data
= data
;
252 sect
->unnamed
.next
= unnamed_sections
;
254 unnamed_sections
= sect
;
258 /* Return a SECTION_NOSWITCH section with the given fields. */
261 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
265 sect
= ggc_alloc_section ();
266 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
267 sect
->noswitch
.callback
= callback
;
272 /* Return the named section structure associated with NAME. Create
273 a new section with the given fields if no such structure exists. */
276 get_section (const char *name
, unsigned int flags
, tree decl
)
278 section
*sect
, **slot
;
281 htab_find_slot_with_hash (section_htab
, name
,
282 htab_hash_string (name
), INSERT
);
283 flags
|= SECTION_NAMED
;
286 sect
= ggc_alloc_section ();
287 sect
->named
.common
.flags
= flags
;
288 sect
->named
.name
= ggc_strdup (name
);
289 sect
->named
.decl
= decl
;
295 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
296 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
298 /* Sanity check user variables for flag changes. */
300 decl
= sect
->named
.decl
;
302 error ("%+D causes a section type conflict", decl
);
308 /* Return true if the current compilation mode benefits from having
309 objects grouped into blocks. */
312 use_object_blocks_p (void)
314 return flag_section_anchors
;
317 /* Return the object_block structure for section SECT. Create a new
318 structure if we haven't created one already. Return null if SECT
321 static struct object_block
*
322 get_block_for_section (section
*sect
)
324 struct object_block
*block
;
330 slot
= htab_find_slot_with_hash (object_block_htab
, sect
,
331 hash_section (sect
), INSERT
);
332 block
= (struct object_block
*) *slot
;
335 block
= ggc_alloc_cleared_object_block ();
342 /* Create a symbol with label LABEL and place it at byte offset
343 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
344 is not yet known. LABEL must be a garbage-collected string. */
347 create_block_symbol (const char *label
, struct object_block
*block
,
348 HOST_WIDE_INT offset
)
353 /* Create the extended SYMBOL_REF. */
354 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
355 symbol
= ggc_alloc_zone_rtx_def (size
, &rtl_zone
);
357 /* Initialize the normal SYMBOL_REF fields. */
358 memset (symbol
, 0, size
);
359 PUT_CODE (symbol
, SYMBOL_REF
);
360 PUT_MODE (symbol
, Pmode
);
361 XSTR (symbol
, 0) = label
;
362 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
364 /* Initialize the block_symbol stuff. */
365 SYMBOL_REF_BLOCK (symbol
) = block
;
366 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
372 initialize_cold_section_name (void)
374 const char *stripped_name
;
378 gcc_assert (cfun
&& current_function_decl
);
379 if (crtl
->subsections
.unlikely_text_section_name
)
382 dsn
= DECL_SECTION_NAME (current_function_decl
);
383 if (flag_function_sections
&& dsn
)
385 name
= (char *) alloca (TREE_STRING_LENGTH (dsn
) + 1);
386 memcpy (name
, TREE_STRING_POINTER (dsn
), TREE_STRING_LENGTH (dsn
) + 1);
388 stripped_name
= targetm
.strip_name_encoding (name
);
390 buffer
= ACONCAT ((stripped_name
, "_unlikely", NULL
));
391 crtl
->subsections
.unlikely_text_section_name
= ggc_strdup (buffer
);
394 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
397 /* Tell assembler to switch to unlikely-to-be-executed text section. */
400 unlikely_text_section (void)
404 if (!crtl
->subsections
.unlikely_text_section_name
)
405 initialize_cold_section_name ();
407 return get_named_section (NULL
, crtl
->subsections
.unlikely_text_section_name
, 0);
410 return get_named_section (NULL
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
, 0);
413 /* When called within a function context, return true if the function
414 has been assigned a cold text section and if SECT is that section.
415 When called outside a function context, return true if SECT is the
416 default cold section. */
419 unlikely_text_section_p (section
*sect
)
424 name
= crtl
->subsections
.unlikely_text_section_name
;
426 name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
430 && SECTION_STYLE (sect
) == SECTION_NAMED
431 && strcmp (name
, sect
->named
.name
) == 0);
434 /* Return a section with a particular name and with whatever SECTION_*
435 flags section_type_flags deems appropriate. The name of the section
436 is taken from NAME if nonnull, otherwise it is taken from DECL's
437 DECL_SECTION_NAME. DECL is the decl associated with the section
438 (see the section comment for details) and RELOC is as for
439 section_type_flags. */
442 get_named_section (tree decl
, const char *name
, int reloc
)
446 gcc_assert (!decl
|| DECL_P (decl
));
448 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
450 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
452 return get_section (name
, flags
, decl
);
455 /* If required, set DECL_SECTION_NAME to a unique name. */
458 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
459 int flag_function_or_data_sections
)
461 if (DECL_SECTION_NAME (decl
) == NULL_TREE
462 && targetm
.have_named_sections
463 && (flag_function_or_data_sections
464 || DECL_ONE_ONLY (decl
)))
465 targetm
.asm_out
.unique_section (decl
, reloc
);
468 #ifdef BSS_SECTION_ASM_OP
470 #ifdef ASM_OUTPUT_BSS
472 /* Utility function for ASM_OUTPUT_BSS for targets to use if
473 they don't support alignments in .bss.
474 ??? It is believed that this function will work in most cases so such
475 support is localized here. */
477 static void ATTRIBUTE_UNUSED
478 asm_output_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
480 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
481 unsigned HOST_WIDE_INT rounded
)
483 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl
), 0), 0), name
) == 0);
484 targetm
.asm_out
.globalize_decl_name (file
, decl
);
485 switch_to_section (bss_section
);
486 #ifdef ASM_DECLARE_OBJECT_NAME
487 last_assemble_variable_decl
= decl
;
488 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
490 /* Standard thing is just output label for the object. */
491 ASM_OUTPUT_LABEL (file
, name
);
492 #endif /* ASM_DECLARE_OBJECT_NAME */
493 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
498 #ifdef ASM_OUTPUT_ALIGNED_BSS
500 /* Utility function for targets to use in implementing
501 ASM_OUTPUT_ALIGNED_BSS.
502 ??? It is believed that this function will work in most cases so such
503 support is localized here. */
506 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
507 const char *name
, unsigned HOST_WIDE_INT size
,
510 switch_to_section (bss_section
);
511 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
512 #ifdef ASM_DECLARE_OBJECT_NAME
513 last_assemble_variable_decl
= decl
;
514 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
516 /* Standard thing is just output label for the object. */
517 ASM_OUTPUT_LABEL (file
, name
);
518 #endif /* ASM_DECLARE_OBJECT_NAME */
519 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
524 #endif /* BSS_SECTION_ASM_OP */
526 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
527 /* Return the hot section for function DECL. Return text_section for
531 hot_function_section (tree decl
)
533 if (decl
!= NULL_TREE
534 && DECL_SECTION_NAME (decl
) != NULL_TREE
535 && targetm
.have_named_sections
)
536 return get_named_section (decl
, NULL
, 0);
542 /* Return the section for function DECL.
544 If DECL is NULL_TREE, return the text section. We can be passed
545 NULL_TREE under some circumstances by dbxout.c at least. */
548 function_section (tree decl
)
552 if (first_function_block_is_cold
)
555 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
556 if (decl
!= NULL_TREE
557 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
558 return reloc
? unlikely_text_section ()
559 : get_named_section (decl
, NULL
, 0);
561 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
563 return reloc
? unlikely_text_section () : hot_function_section (decl
);
568 current_function_section (void)
570 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
571 if (current_function_decl
!= NULL_TREE
572 && DECL_SECTION_NAME (current_function_decl
) != NULL_TREE
)
573 return in_cold_section_p
? unlikely_text_section ()
574 : get_named_section (current_function_decl
,
577 return targetm
.asm_out
.select_section (current_function_decl
,
579 DECL_ALIGN (current_function_decl
));
581 return (in_cold_section_p
582 ? unlikely_text_section ()
583 : hot_function_section (current_function_decl
));
587 /* Return the read-only data section associated with function DECL. */
590 default_function_rodata_section (tree decl
)
592 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
594 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
596 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
602 dot
= strchr (name
+ 1, '.');
605 len
= strlen (dot
) + 8;
606 rname
= (char *) alloca (len
);
608 strcpy (rname
, ".rodata");
610 return get_section (rname
, SECTION_LINKONCE
, decl
);
612 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
613 else if (DECL_ONE_ONLY (decl
)
614 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
616 size_t len
= strlen (name
) + 1;
617 char *rname
= (char *) alloca (len
);
619 memcpy (rname
, name
, len
);
621 return get_section (rname
, SECTION_LINKONCE
, decl
);
623 /* For .text.foo we want to use .rodata.foo. */
624 else if (flag_function_sections
&& flag_data_sections
625 && strncmp (name
, ".text.", 6) == 0)
627 size_t len
= strlen (name
) + 1;
628 char *rname
= (char *) alloca (len
+ 2);
630 memcpy (rname
, ".rodata", 7);
631 memcpy (rname
+ 7, name
+ 5, len
- 5);
632 return get_section (rname
, 0, decl
);
636 return readonly_data_section
;
639 /* Return the read-only data section associated with function DECL
640 for targets where that section should be always the single
641 readonly data section. */
644 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
646 return readonly_data_section
;
649 /* Return the section to use for string merging. */
652 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
653 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
654 unsigned int flags ATTRIBUTE_UNUSED
)
658 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
659 && TREE_CODE (decl
) == STRING_CST
660 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
662 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
663 && TREE_STRING_LENGTH (decl
) >= len
)
665 enum machine_mode mode
;
666 unsigned int modesize
;
672 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
673 modesize
= GET_MODE_BITSIZE (mode
);
674 if (modesize
>= 8 && modesize
<= 256
675 && (modesize
& (modesize
- 1)) == 0)
677 if (align
< modesize
)
680 str
= TREE_STRING_POINTER (decl
);
681 unit
= GET_MODE_SIZE (mode
);
683 /* Check for embedded NUL characters. */
684 for (i
= 0; i
< len
; i
+= unit
)
686 for (j
= 0; j
< unit
; j
++)
687 if (str
[i
+ j
] != '\0')
694 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
696 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
697 return get_section (name
, flags
, NULL
);
702 return readonly_data_section
;
705 /* Return the section to use for constant merging. */
708 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
709 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
710 unsigned int flags ATTRIBUTE_UNUSED
)
712 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
714 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
720 && (align
& (align
- 1)) == 0)
724 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
725 flags
|= (align
/ 8) | SECTION_MERGE
;
726 return get_section (name
, flags
, NULL
);
728 return readonly_data_section
;
731 /* Given NAME, a putative register name, discard any customary prefixes. */
734 strip_reg_name (const char *name
)
736 #ifdef REGISTER_PREFIX
737 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
738 name
+= strlen (REGISTER_PREFIX
);
740 if (name
[0] == '%' || name
[0] == '#')
745 /* The user has asked for a DECL to have a particular name. Set (or
746 change) it in such a way that we don't prefix an underscore to
749 set_user_assembler_name (tree decl
, const char *name
)
751 char *starred
= (char *) alloca (strlen (name
) + 2);
753 strcpy (starred
+ 1, name
);
754 change_decl_assembler_name (decl
, get_identifier (starred
));
755 SET_DECL_RTL (decl
, NULL_RTX
);
758 /* Decode an `asm' spec for a declaration as a register name.
759 Return the register number, or -1 if nothing specified,
760 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
761 or -3 if ASMSPEC is `cc' and is not recognized,
762 or -4 if ASMSPEC is `memory' and is not recognized.
763 Accept an exact spelling or a decimal number.
764 Prefixes such as % are optional. */
767 decode_reg_name (const char *asmspec
)
773 /* Get rid of confusing prefixes. */
774 asmspec
= strip_reg_name (asmspec
);
776 /* Allow a decimal number as a "register name". */
777 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
778 if (! ISDIGIT (asmspec
[i
]))
780 if (asmspec
[0] != 0 && i
< 0)
783 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
789 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
791 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
794 #ifdef ADDITIONAL_REGISTER_NAMES
796 static const struct { const char *const name
; const int number
; } table
[]
797 = ADDITIONAL_REGISTER_NAMES
;
799 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
801 && ! strcmp (asmspec
, table
[i
].name
))
802 return table
[i
].number
;
804 #endif /* ADDITIONAL_REGISTER_NAMES */
806 if (!strcmp (asmspec
, "memory"))
809 if (!strcmp (asmspec
, "cc"))
818 /* Return true if DECL's initializer is suitable for a BSS section. */
821 bss_initializer_p (const_tree decl
)
823 return (DECL_INITIAL (decl
) == NULL
824 || DECL_INITIAL (decl
) == error_mark_node
825 || (flag_zero_initialized_in_bss
826 /* Leave constant zeroes in .rodata so they
828 && !TREE_READONLY (decl
)
829 && initializer_zerop (DECL_INITIAL (decl
))));
832 /* Compute the alignment of variable specified by DECL.
833 DONT_OUTPUT_DATA is from assemble_variable. */
836 align_variable (tree decl
, bool dont_output_data
)
838 unsigned int align
= DECL_ALIGN (decl
);
840 /* In the case for initialing an array whose length isn't specified,
841 where we have not yet been able to do the layout,
842 figure out the proper alignment now. */
843 if (dont_output_data
&& DECL_SIZE (decl
) == 0
844 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
845 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
847 /* Some object file formats have a maximum alignment which they support.
848 In particular, a.out format supports a maximum alignment of 4. */
849 if (align
> MAX_OFILE_ALIGNMENT
)
851 warning (0, "alignment of %q+D is greater than maximum object "
852 "file alignment. Using %d", decl
,
853 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
854 align
= MAX_OFILE_ALIGNMENT
;
857 /* On some machines, it is good to increase alignment sometimes. */
858 if (! DECL_USER_ALIGN (decl
))
860 #ifdef DATA_ALIGNMENT
861 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
862 /* Don't increase alignment too much for TLS variables - TLS space
864 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
867 #ifdef CONSTANT_ALIGNMENT
868 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
870 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
872 /* Don't increase alignment too much for TLS variables - TLS space
874 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
880 /* Reset the alignment in case we have made it tighter, so we can benefit
881 from it in get_pointer_alignment. */
882 DECL_ALIGN (decl
) = align
;
885 /* Return the section into which the given VAR_DECL or CONST_DECL
886 should be placed. PREFER_NOSWITCH_P is true if a noswitch
887 section should be used wherever possible. */
890 get_variable_section (tree decl
, bool prefer_noswitch_p
)
892 addr_space_t as
= ADDR_SPACE_GENERIC
;
895 if (TREE_TYPE (decl
) != error_mark_node
)
896 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
898 if (DECL_COMMON (decl
))
900 /* If the decl has been given an explicit section name, or it resides
901 in a non-generic address space, then it isn't common, and shouldn't
902 be handled as such. */
903 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
904 && ADDR_SPACE_GENERIC_P (as
));
905 if (DECL_THREAD_LOCAL_P (decl
))
906 return tls_comm_section
;
907 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
911 if (DECL_INITIAL (decl
) == error_mark_node
)
912 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
913 else if (DECL_INITIAL (decl
))
914 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
918 resolve_unique_section (decl
, reloc
, flag_data_sections
);
919 if (IN_NAMED_SECTION (decl
))
920 return get_named_section (decl
, NULL
, reloc
);
922 if (ADDR_SPACE_GENERIC_P (as
)
923 && !DECL_THREAD_LOCAL_P (decl
)
924 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
925 && bss_initializer_p (decl
))
927 if (!TREE_PUBLIC (decl
))
928 return lcomm_section
;
929 if (bss_noswitch_section
)
930 return bss_noswitch_section
;
933 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
936 /* Return the block into which object_block DECL should be placed. */
938 static struct object_block
*
939 get_block_for_decl (tree decl
)
943 if (TREE_CODE (decl
) == VAR_DECL
)
945 /* The object must be defined in this translation unit. */
946 if (DECL_EXTERNAL (decl
))
949 /* There's no point using object blocks for something that is
950 isolated by definition. */
951 if (DECL_ONE_ONLY (decl
))
955 /* We can only calculate block offsets if the decl has a known
957 if (DECL_SIZE_UNIT (decl
) == NULL
)
959 if (!host_integerp (DECL_SIZE_UNIT (decl
), 1))
962 /* Find out which section should contain DECL. We cannot put it into
963 an object block if it requires a standalone definition. */
964 if (TREE_CODE (decl
) == VAR_DECL
)
965 align_variable (decl
, 0);
966 sect
= get_variable_section (decl
, true);
967 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
970 return get_block_for_section (sect
);
973 /* Make sure block symbol SYMBOL is in block BLOCK. */
976 change_symbol_block (rtx symbol
, struct object_block
*block
)
978 if (block
!= SYMBOL_REF_BLOCK (symbol
))
980 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
981 SYMBOL_REF_BLOCK (symbol
) = block
;
985 /* Return true if it is possible to put DECL in an object_block. */
988 use_blocks_for_decl_p (tree decl
)
990 /* Only data DECLs can be placed into object blocks. */
991 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
994 /* Detect decls created by dw2_force_const_mem. Such decls are
995 special because DECL_INITIAL doesn't specify the decl's true value.
996 dw2_output_indirect_constants will instead call assemble_variable
997 with dont_output_data set to 1 and then print the contents itself. */
998 if (DECL_INITIAL (decl
) == decl
)
1001 /* If this decl is an alias, then we don't want to emit a
1003 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl
)))
1009 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1010 have static storage duration. In other words, it should not be an
1011 automatic variable, including PARM_DECLs.
1013 There is, however, one exception: this function handles variables
1014 explicitly placed in a particular register by the user.
1016 This is never called for PARM_DECL nodes. */
1019 make_decl_rtl (tree decl
)
1021 const char *name
= 0;
1025 /* Check that we are not being given an automatic variable. */
1026 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1027 && TREE_CODE (decl
) != RESULT_DECL
);
1029 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1030 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1031 || TREE_STATIC (decl
)
1032 || TREE_PUBLIC (decl
)
1033 || DECL_EXTERNAL (decl
)
1034 || DECL_REGISTER (decl
));
1036 /* And that we were not given a type or a label. */
1037 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1038 && TREE_CODE (decl
) != LABEL_DECL
);
1040 /* For a duplicate declaration, we can be called twice on the
1041 same DECL node. Don't discard the RTL already made. */
1042 if (DECL_RTL_SET_P (decl
))
1044 /* If the old RTL had the wrong mode, fix the mode. */
1045 x
= DECL_RTL (decl
);
1046 if (GET_MODE (x
) != DECL_MODE (decl
))
1047 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1049 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1052 /* ??? Another way to do this would be to maintain a hashed
1053 table of such critters. Instead of adding stuff to a DECL
1054 to give certain attributes to it, we could use an external
1055 hash map from DECL to set of attributes. */
1057 /* Let the target reassign the RTL if it wants.
1058 This is necessary, for example, when one machine specific
1059 decl attribute overrides another. */
1060 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1062 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1063 on the new decl information. */
1065 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1066 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1067 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1069 /* Make this function static known to the mudflap runtime. */
1070 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1071 mudflap_enqueue_decl (decl
);
1076 /* If this variable belongs to the global constant pool, retrieve the
1077 pre-computed RTL or recompute it in LTO mode. */
1078 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1080 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1084 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1086 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1087 && DECL_REGISTER (decl
))
1089 error ("register name not specified for %q+D", decl
);
1091 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1093 const char *asmspec
= name
+1;
1094 reg_number
= decode_reg_name (asmspec
);
1095 /* First detect errors in declaring global registers. */
1096 if (reg_number
== -1)
1097 error ("register name not specified for %q+D", decl
);
1098 else if (reg_number
< 0)
1099 error ("invalid register name for %q+D", decl
);
1100 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
1101 error ("data type of %q+D isn%'t suitable for a register",
1103 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
1104 error ("register specified for %q+D isn%'t suitable for data type",
1106 /* Now handle properly declared static register variables. */
1111 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1113 DECL_INITIAL (decl
) = 0;
1114 error ("global register variable has initial value");
1116 if (TREE_THIS_VOLATILE (decl
))
1117 warning (OPT_Wvolatile_register_var
,
1118 "optimization may eliminate reads and/or "
1119 "writes to register variables");
1121 /* If the user specified one of the eliminables registers here,
1122 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1123 confused with that register and be eliminated. This usage is
1124 somewhat suspect... */
1126 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
1127 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1128 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1130 if (TREE_STATIC (decl
))
1132 /* Make this register global, so not usable for anything
1134 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1135 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1136 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1138 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
1140 globalize_reg (reg_number
+ --nregs
);
1143 /* As a register variable, it has no section. */
1147 /* Now handle ordinary static variables and functions (in memory).
1148 Also handle vars declared register invalidly. */
1149 else if (name
[0] == '*')
1151 #ifdef REGISTER_PREFIX
1152 if (strlen (REGISTER_PREFIX
) != 0)
1154 reg_number
= decode_reg_name (name
);
1155 if (reg_number
>= 0 || reg_number
== -3)
1156 error ("register name given for non-register variable %q+D", decl
);
1161 /* Specifying a section attribute on a variable forces it into a
1162 non-.bss section, and thus it cannot be common. */
1163 /* FIXME: In general this code should not be necessary because
1164 visibility pass is doing the same work. But notice_global_symbol
1165 is called early and it needs to make DECL_RTL to get the name.
1166 we take care of recomputing the DECL_RTL after visibility is changed. */
1167 if (TREE_CODE (decl
) == VAR_DECL
1168 && DECL_SECTION_NAME (decl
) != NULL_TREE
1169 && DECL_INITIAL (decl
) == NULL_TREE
1170 && DECL_COMMON (decl
))
1171 DECL_COMMON (decl
) = 0;
1173 /* Variables can't be both common and weak. */
1174 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1175 DECL_COMMON (decl
) = 0;
1177 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1178 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1181 enum machine_mode address_mode
= Pmode
;
1182 if (TREE_TYPE (decl
) != error_mark_node
)
1184 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1185 address_mode
= targetm
.addr_space
.address_mode (as
);
1187 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1189 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1190 SET_SYMBOL_REF_DECL (x
, decl
);
1192 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1193 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1194 set_mem_attributes (x
, decl
, 1);
1195 SET_DECL_RTL (decl
, x
);
1197 /* Optionally set flags or add text to the name to record information
1198 such as that it is a function name.
1199 If the name is changed, the macro ASM_OUTPUT_LABELREF
1200 will have to know how to strip this information. */
1201 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1203 /* Make this function static known to the mudflap runtime. */
1204 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1205 mudflap_enqueue_decl (decl
);
1208 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1209 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1213 make_decl_rtl_for_debug (tree decl
)
1215 unsigned int save_aliasing_flag
, save_mudflap_flag
;
1218 if (DECL_RTL_SET_P (decl
))
1219 return DECL_RTL (decl
);
1221 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1222 call new_alias_set. If running with -fcompare-debug, sometimes
1223 we do not want to create alias sets that will throw the alias
1224 numbers off in the comparison dumps. So... clearing
1225 flag_strict_aliasing will keep new_alias_set() from creating a
1226 new set. It is undesirable to register decl with mudflap
1227 in this case as well. */
1228 save_aliasing_flag
= flag_strict_aliasing
;
1229 flag_strict_aliasing
= 0;
1230 save_mudflap_flag
= flag_mudflap
;
1233 rtl
= DECL_RTL (decl
);
1234 /* Reset DECL_RTL back, as various parts of the compiler expects
1235 DECL_RTL set meaning it is actually going to be output. */
1236 SET_DECL_RTL (decl
, NULL
);
1238 flag_strict_aliasing
= save_aliasing_flag
;
1239 flag_mudflap
= save_mudflap_flag
;
1244 /* Output a string of literal assembler code
1245 for an `asm' keyword used between functions. */
1248 assemble_asm (tree string
)
1252 if (TREE_CODE (string
) == ADDR_EXPR
)
1253 string
= TREE_OPERAND (string
, 0);
1255 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1258 /* Record an element in the table of global destructors. SYMBOL is
1259 a SYMBOL_REF of the function to be called; PRIORITY is a number
1260 between 0 and MAX_INIT_PRIORITY. */
1263 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
1264 int priority ATTRIBUTE_UNUSED
)
1266 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1267 /* Tell GNU LD that this is part of the static destructor set.
1268 This will work for any system that uses stabs, most usefully
1270 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1271 dbxout_stab_value_label (XSTR (symbol
, 0));
1273 sorry ("global destructors not supported on this target");
1277 /* Write the address of the entity given by SYMBOL to SEC. */
1279 assemble_addr_to_section (rtx symbol
, section
*sec
)
1281 switch_to_section (sec
);
1282 assemble_align (POINTER_SIZE
);
1283 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1286 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1287 not) section for PRIORITY. */
1289 get_cdtor_priority_section (int priority
, bool constructor_p
)
1293 /* ??? This only works reliably with the GNU linker. */
1294 sprintf (buf
, "%s.%.5u",
1295 constructor_p
? ".ctors" : ".dtors",
1296 /* Invert the numbering so the linker puts us in the proper
1297 order; constructors are run from right to left, and the
1298 linker sorts in increasing order. */
1299 MAX_INIT_PRIORITY
- priority
);
1300 return get_section (buf
, SECTION_WRITE
, NULL
);
1304 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1308 if (priority
!= DEFAULT_INIT_PRIORITY
)
1309 sec
= get_cdtor_priority_section (priority
,
1310 /*constructor_p=*/false);
1312 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1314 assemble_addr_to_section (symbol
, sec
);
1317 #ifdef DTORS_SECTION_ASM_OP
1319 default_dtor_section_asm_out_destructor (rtx symbol
,
1320 int priority ATTRIBUTE_UNUSED
)
1322 assemble_addr_to_section (symbol
, dtors_section
);
1326 /* Likewise for global constructors. */
1329 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
1330 int priority ATTRIBUTE_UNUSED
)
1332 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1333 /* Tell GNU LD that this is part of the static destructor set.
1334 This will work for any system that uses stabs, most usefully
1336 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1337 dbxout_stab_value_label (XSTR (symbol
, 0));
1339 sorry ("global constructors not supported on this target");
1344 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1348 if (priority
!= DEFAULT_INIT_PRIORITY
)
1349 sec
= get_cdtor_priority_section (priority
,
1350 /*constructor_p=*/true);
1352 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1354 assemble_addr_to_section (symbol
, sec
);
1357 #ifdef CTORS_SECTION_ASM_OP
1359 default_ctor_section_asm_out_constructor (rtx symbol
,
1360 int priority ATTRIBUTE_UNUSED
)
1362 assemble_addr_to_section (symbol
, ctors_section
);
1366 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1367 a nonzero value if the constant pool should be output before the
1368 start of the function, or a zero value if the pool should output
1369 after the end of the function. The default is to put it before the
1372 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1373 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1376 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1377 to be output to assembler.
1378 Set first_global_object_name and weak_global_object_name as appropriate. */
1381 notice_global_symbol (tree decl
)
1383 const char **type
= &first_global_object_name
;
1385 if (first_global_object_name
1386 || !TREE_PUBLIC (decl
)
1387 || DECL_EXTERNAL (decl
)
1388 || !DECL_NAME (decl
)
1389 || (TREE_CODE (decl
) != FUNCTION_DECL
1390 && (TREE_CODE (decl
) != VAR_DECL
1391 || (DECL_COMMON (decl
)
1392 && (DECL_INITIAL (decl
) == 0
1393 || DECL_INITIAL (decl
) == error_mark_node
))))
1394 || !MEM_P (DECL_RTL (decl
)))
1397 /* We win when global object is found, but it is useful to know about weak
1398 symbol as well so we can produce nicer unique names. */
1399 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1400 type
= &weak_global_object_name
;
1406 rtx decl_rtl
= DECL_RTL (decl
);
1408 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1409 name
= ggc_strdup (p
);
1415 /* Output assembler code for the constant pool of a function and associated
1416 with defining the name of the function. DECL describes the function.
1417 NAME is the function's name. For the constant pool, we use the current
1418 constant pool data. */
1421 assemble_start_function (tree decl
, const char *fnname
)
1424 char tmp_label
[100];
1425 bool hot_label_written
= false;
1427 crtl
->subsections
.unlikely_text_section_name
= NULL
;
1429 first_function_block_is_cold
= false;
1430 if (flag_reorder_blocks_and_partition
)
1432 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1433 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1434 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1435 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1436 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1437 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1438 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1439 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1444 crtl
->subsections
.hot_section_label
= NULL
;
1445 crtl
->subsections
.cold_section_label
= NULL
;
1446 crtl
->subsections
.hot_section_end_label
= NULL
;
1447 crtl
->subsections
.cold_section_end_label
= NULL
;
1450 /* The following code does not need preprocessing in the assembler. */
1454 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1455 output_constant_pool (fnname
, decl
);
1457 resolve_unique_section (decl
, 0, flag_function_sections
);
1459 /* Make sure the not and cold text (code) sections are properly
1460 aligned. This is necessary here in the case where the function
1461 has both hot and cold sections, because we don't want to re-set
1462 the alignment when the section switch happens mid-function. */
1464 if (flag_reorder_blocks_and_partition
)
1466 switch_to_section (unlikely_text_section ());
1467 assemble_align (DECL_ALIGN (decl
));
1468 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1470 /* When the function starts with a cold section, we need to explicitly
1471 align the hot section and write out the hot section label.
1472 But if the current function is a thunk, we do not have a CFG. */
1474 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1476 switch_to_section (text_section
);
1477 assemble_align (DECL_ALIGN (decl
));
1478 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1479 hot_label_written
= true;
1480 first_function_block_is_cold
= true;
1483 else if (DECL_SECTION_NAME (decl
))
1485 /* Calls to function_section rely on first_function_block_is_cold
1486 being accurate. The first block may be cold even if we aren't
1487 doing partitioning, if the entire function was decided by
1488 choose_function_section (predict.c) to be cold. */
1490 initialize_cold_section_name ();
1492 if (crtl
->subsections
.unlikely_text_section_name
1493 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
1494 crtl
->subsections
.unlikely_text_section_name
) == 0)
1495 first_function_block_is_cold
= true;
1498 in_cold_section_p
= first_function_block_is_cold
;
1500 /* Switch to the correct text section for the start of the function. */
1502 switch_to_section (function_section (decl
));
1503 if (flag_reorder_blocks_and_partition
1504 && !hot_label_written
)
1505 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1507 /* Tell assembler to move to target machine's alignment for functions. */
1508 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1511 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1514 /* Handle a user-specified function alignment.
1515 Note that we still need to align to DECL_ALIGN, as above,
1516 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1517 if (! DECL_USER_ALIGN (decl
)
1518 && align_functions_log
> align
1519 && optimize_function_for_speed_p (cfun
))
1521 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1522 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1523 align_functions_log
, align_functions
- 1);
1525 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1529 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1530 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1533 if (!DECL_IGNORED_P (decl
))
1534 (*debug_hooks
->begin_function
) (decl
);
1536 /* Make function name accessible from other files, if appropriate. */
1538 if (TREE_PUBLIC (decl
))
1540 notice_global_symbol (decl
);
1542 globalize_decl (decl
);
1544 maybe_assemble_visibility (decl
);
1547 if (DECL_PRESERVE_P (decl
))
1548 targetm
.asm_out
.mark_decl_preserved (fnname
);
1550 /* Do any machine/system dependent processing of the function name. */
1551 #ifdef ASM_DECLARE_FUNCTION_NAME
1552 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1554 /* Standard thing is just output label for the function. */
1555 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1556 #endif /* ASM_DECLARE_FUNCTION_NAME */
1558 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1559 saw_no_split_stack
= true;
1562 /* Output assembler code associated with defining the size of the
1563 function. DECL describes the function. NAME is the function's name. */
1566 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1568 #ifdef ASM_DECLARE_FUNCTION_SIZE
1569 /* We could have switched section in the middle of the function. */
1570 if (flag_reorder_blocks_and_partition
)
1571 switch_to_section (function_section (decl
));
1572 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1574 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1576 output_constant_pool (fnname
, decl
);
1577 switch_to_section (function_section (decl
)); /* need to switch back */
1579 /* Output labels for end of hot/cold text sections (to be used by
1581 if (flag_reorder_blocks_and_partition
)
1583 section
*save_text_section
;
1585 save_text_section
= in_section
;
1586 switch_to_section (unlikely_text_section ());
1587 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1588 if (first_function_block_is_cold
)
1589 switch_to_section (text_section
);
1591 switch_to_section (function_section (decl
));
1592 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1593 switch_to_section (save_text_section
);
1597 /* Assemble code to leave SIZE bytes of zeros. */
1600 assemble_zeros (unsigned HOST_WIDE_INT size
)
1602 /* Do no output if -fsyntax-only. */
1603 if (flag_syntax_only
)
1606 #ifdef ASM_NO_SKIP_IN_TEXT
1607 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1608 so we must output 0s explicitly in the text section. */
1609 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1611 unsigned HOST_WIDE_INT i
;
1612 for (i
= 0; i
< size
; i
++)
1613 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1618 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1621 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1624 assemble_align (int align
)
1626 if (align
> BITS_PER_UNIT
)
1628 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1632 /* Assemble a string constant with the specified C string as contents. */
1635 assemble_string (const char *p
, int size
)
1640 /* If the string is very long, split it up. */
1644 int thissize
= size
- pos
;
1645 if (thissize
> maximum
)
1648 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1656 /* A noswitch_section_callback for lcomm_section. */
1659 emit_local (tree decl ATTRIBUTE_UNUSED
,
1660 const char *name ATTRIBUTE_UNUSED
,
1661 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1662 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1664 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1665 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1666 size
, DECL_ALIGN (decl
));
1668 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1669 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1672 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1677 /* A noswitch_section_callback for bss_noswitch_section. */
1679 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1681 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1682 const char *name ATTRIBUTE_UNUSED
,
1683 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1684 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1686 #if defined ASM_OUTPUT_ALIGNED_BSS
1687 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
, DECL_ALIGN (decl
));
1690 ASM_OUTPUT_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1696 /* A noswitch_section_callback for comm_section. */
1699 emit_common (tree decl ATTRIBUTE_UNUSED
,
1700 const char *name ATTRIBUTE_UNUSED
,
1701 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1702 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1704 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1705 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1706 size
, DECL_ALIGN (decl
));
1708 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1709 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1712 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1717 /* A noswitch_section_callback for tls_comm_section. */
1720 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1721 const char *name ATTRIBUTE_UNUSED
,
1722 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1723 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1725 #ifdef ASM_OUTPUT_TLS_COMMON
1726 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1729 sorry ("thread-local COMMON data not implemented");
1734 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1735 NAME is the name of DECL's SYMBOL_REF. */
1738 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
)
1740 unsigned HOST_WIDE_INT size
, rounded
;
1742 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1745 /* Don't allocate zero bytes of common,
1746 since that means "undefined external" in the linker. */
1750 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1751 so that each uninitialized object starts on such a boundary. */
1752 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1753 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1754 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1756 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
1757 && (unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
1758 warning (0, "requested alignment for %q+D is greater than "
1759 "implemented alignment of %wu", decl
, rounded
);
1762 /* A subroutine of assemble_variable. Output the label and contents of
1763 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1764 is as for assemble_variable. */
1767 assemble_variable_contents (tree decl
, const char *name
,
1768 bool dont_output_data
)
1770 /* Do any machine/system dependent processing of the object. */
1771 #ifdef ASM_DECLARE_OBJECT_NAME
1772 last_assemble_variable_decl
= decl
;
1773 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1775 /* Standard thing is just output label for the object. */
1776 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1777 #endif /* ASM_DECLARE_OBJECT_NAME */
1779 if (!dont_output_data
)
1781 if (DECL_INITIAL (decl
)
1782 && DECL_INITIAL (decl
) != error_mark_node
1783 && !initializer_zerop (DECL_INITIAL (decl
)))
1784 /* Output the actual data. */
1785 output_constant (DECL_INITIAL (decl
),
1786 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1789 /* Leave space for it. */
1790 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1794 /* Assemble everything that is needed for a variable or function declaration.
1795 Not used for automatic variables, and not used for function definitions.
1796 Should not be called for variables of incomplete structure type.
1798 TOP_LEVEL is nonzero if this variable has file scope.
1799 AT_END is nonzero if this is the special handling, at end of compilation,
1800 to define things that have had only tentative definitions.
1801 DONT_OUTPUT_DATA if nonzero means don't actually output the
1802 initial value (that will be done by the caller). */
1805 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
1806 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
1809 rtx decl_rtl
, symbol
;
1812 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1813 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
1815 /* Emulated TLS had better not get this far. */
1816 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
1818 last_assemble_variable_decl
= 0;
1820 /* Normally no need to say anything here for external references,
1821 since assemble_external is called by the language-specific code
1822 when a declaration is first seen. */
1824 if (DECL_EXTERNAL (decl
))
1827 /* Do nothing for global register variables. */
1828 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
1830 TREE_ASM_WRITTEN (decl
) = 1;
1834 /* If type was incomplete when the variable was declared,
1835 see if it is complete now. */
1837 if (DECL_SIZE (decl
) == 0)
1838 layout_decl (decl
, 0);
1840 /* Still incomplete => don't allocate it; treat the tentative defn
1841 (which is what it must have been) as an `extern' reference. */
1843 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1845 error ("storage size of %q+D isn%'t known", decl
);
1846 TREE_ASM_WRITTEN (decl
) = 1;
1850 /* The first declaration of a variable that comes through this function
1851 decides whether it is global (in C, has external linkage)
1852 or local (in C, has internal linkage). So do nothing more
1853 if this function has already run. */
1855 if (TREE_ASM_WRITTEN (decl
))
1858 /* Make sure targetm.encode_section_info is invoked before we set
1860 decl_rtl
= DECL_RTL (decl
);
1862 TREE_ASM_WRITTEN (decl
) = 1;
1864 /* Do no output if -fsyntax-only. */
1865 if (flag_syntax_only
)
1868 if (! dont_output_data
1869 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1871 error ("size of variable %q+D is too large", decl
);
1875 gcc_assert (MEM_P (decl_rtl
));
1876 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
1877 symbol
= XEXP (decl_rtl
, 0);
1879 /* If this symbol belongs to the tree constant pool, output the constant
1880 if it hasn't already been written. */
1881 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
1883 tree decl
= SYMBOL_REF_DECL (symbol
);
1884 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
1885 output_constant_def_contents (symbol
);
1891 name
= XSTR (symbol
, 0);
1892 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1893 notice_global_symbol (decl
);
1895 /* Compute the alignment of this data. */
1897 align_variable (decl
, dont_output_data
);
1898 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
1900 if (TREE_PUBLIC (decl
))
1901 maybe_assemble_visibility (decl
);
1903 if (DECL_PRESERVE_P (decl
))
1904 targetm
.asm_out
.mark_decl_preserved (name
);
1906 /* First make the assembler name(s) global if appropriate. */
1907 sect
= get_variable_section (decl
, false);
1908 if (TREE_PUBLIC (decl
)
1909 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
1910 globalize_decl (decl
);
1912 /* Output any data that we will need to use the address of. */
1913 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
1914 output_addressed_constants (DECL_INITIAL (decl
));
1916 /* dbxout.c needs to know this. */
1917 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
1918 DECL_IN_TEXT_SECTION (decl
) = 1;
1920 /* If the decl is part of an object_block, make sure that the decl
1921 has been positioned within its block, but do not write out its
1922 definition yet. output_object_blocks will do that later. */
1923 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
1925 gcc_assert (!dont_output_data
);
1926 place_block_symbol (symbol
);
1928 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1929 assemble_noswitch_variable (decl
, name
, sect
);
1932 switch_to_section (sect
);
1933 if (DECL_ALIGN (decl
) > BITS_PER_UNIT
)
1934 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
1935 assemble_variable_contents (decl
, name
, dont_output_data
);
1939 /* Return 1 if type TYPE contains any pointers. */
1942 contains_pointers_p (tree type
)
1944 switch (TREE_CODE (type
))
1947 case REFERENCE_TYPE
:
1948 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1949 so I'll play safe and return 1. */
1955 case QUAL_UNION_TYPE
:
1958 /* For a type that has fields, see if the fields have pointers. */
1959 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
1960 if (TREE_CODE (fields
) == FIELD_DECL
1961 && contains_pointers_p (TREE_TYPE (fields
)))
1967 /* An array type contains pointers if its element type does. */
1968 return contains_pointers_p (TREE_TYPE (type
));
1975 /* We delay assemble_external processing until
1976 the compilation unit is finalized. This is the best we can do for
1977 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
1978 it all the way to final. See PR 17982 for further discussion. */
1979 static GTY(()) tree pending_assemble_externals
;
1981 #ifdef ASM_OUTPUT_EXTERNAL
1982 /* True if DECL is a function decl for which no out-of-line copy exists.
1983 It is assumed that DECL's assembler name has been set. */
1986 incorporeal_function_p (tree decl
)
1988 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
1992 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
1993 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
1996 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1997 if (is_builtin_name (name
))
2003 /* Actually do the tests to determine if this is necessary, and invoke
2004 ASM_OUTPUT_EXTERNAL. */
2006 assemble_external_real (tree decl
)
2008 rtx rtl
= DECL_RTL (decl
);
2010 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2011 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2012 && !incorporeal_function_p (decl
))
2014 /* Some systems do require some output. */
2015 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2016 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2022 process_pending_assemble_externals (void)
2024 #ifdef ASM_OUTPUT_EXTERNAL
2026 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2027 assemble_external_real (TREE_VALUE (list
));
2029 pending_assemble_externals
= 0;
2033 /* This TREE_LIST contains any weak symbol declarations waiting
2035 static GTY(()) tree weak_decls
;
2037 /* Output something to declare an external symbol to the assembler,
2038 and qualifiers such as weakness. (Most assemblers don't need
2039 extern declaration, so we normally output nothing.) Do nothing if
2040 DECL is not external. */
2043 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2045 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2046 main body of this code is only rarely exercised. To provide some
2047 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2048 open. If it's not, we should not be calling this function. */
2049 gcc_assert (asm_out_file
);
2051 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2054 /* We want to output annotation for weak and external symbols at
2055 very last to check if they are references or not. */
2057 if (TARGET_SUPPORTS_WEAK
2059 /* TREE_STATIC is a weird and abused creature which is not
2060 generally the right test for whether an entity has been
2061 locally emitted, inlined or otherwise not-really-extern, but
2062 for declarations that can be weak, it happens to be
2064 && !TREE_STATIC (decl
)
2065 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2066 && value_member (decl
, weak_decls
) == NULL_TREE
)
2067 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2069 #ifdef ASM_OUTPUT_EXTERNAL
2070 if (value_member (decl
, pending_assemble_externals
) == NULL_TREE
)
2071 pending_assemble_externals
= tree_cons (NULL
, decl
,
2072 pending_assemble_externals
);
2076 /* Similar, for calling a library function FUN. */
2079 assemble_external_libcall (rtx fun
)
2081 /* Declare library function name external when first used, if nec. */
2082 if (! SYMBOL_REF_USED (fun
))
2084 SYMBOL_REF_USED (fun
) = 1;
2085 targetm
.asm_out
.external_libcall (fun
);
2089 /* Assemble a label named NAME. */
2092 assemble_label (FILE *file
, const char *name
)
2094 ASM_OUTPUT_LABEL (file
, name
);
2097 /* Set the symbol_referenced flag for ID. */
2099 mark_referenced (tree id
)
2101 TREE_SYMBOL_REFERENCED (id
) = 1;
2104 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2106 mark_decl_referenced (tree decl
)
2108 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2110 /* Extern inline functions don't become needed when referenced.
2111 If we know a method will be emitted in other TU and no new
2112 functions can be marked reachable, just use the external
2114 struct cgraph_node
*node
= cgraph_node (decl
);
2115 if (!DECL_EXTERNAL (decl
)
2116 && (!node
->local
.vtable_method
|| !cgraph_global_info_ready
2117 || !node
->local
.finalized
))
2118 cgraph_mark_needed_node (node
);
2120 else if (TREE_CODE (decl
) == VAR_DECL
)
2122 struct varpool_node
*node
= varpool_node (decl
);
2123 varpool_mark_needed_node (node
);
2124 /* C++ frontend use mark_decl_references to force COMDAT variables
2125 to be output that might appear dead otherwise. */
2126 node
->force_output
= true;
2128 /* else do nothing - we can get various sorts of CST nodes here,
2129 which do not need to be marked. */
2133 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2134 until we find an identifier that is not itself a transparent alias.
2135 Modify the alias passed to it by reference (and all aliases on the
2136 way to the ultimate target), such that they do not have to be
2137 followed again, and return the ultimate target of the alias
2141 ultimate_transparent_alias_target (tree
*alias
)
2143 tree target
= *alias
;
2145 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2147 gcc_assert (TREE_CHAIN (target
));
2148 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2149 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2150 && ! TREE_CHAIN (target
));
2157 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2158 starts with a *, the rest of NAME is output verbatim. Otherwise
2159 NAME is transformed in a target-specific way (usually by the
2160 addition of an underscore). */
2163 assemble_name_raw (FILE *file
, const char *name
)
2166 fputs (&name
[1], file
);
2168 ASM_OUTPUT_LABELREF (file
, name
);
2171 /* Like assemble_name_raw, but should be used when NAME might refer to
2172 an entity that is also represented as a tree (like a function or
2173 variable). If NAME does refer to such an entity, that entity will
2174 be marked as referenced. */
2177 assemble_name (FILE *file
, const char *name
)
2179 const char *real_name
;
2182 real_name
= targetm
.strip_name_encoding (name
);
2184 id
= maybe_get_identifier (real_name
);
2189 mark_referenced (id
);
2190 ultimate_transparent_alias_target (&id
);
2192 name
= IDENTIFIER_POINTER (id
);
2193 gcc_assert (! TREE_CHAIN (id
));
2196 assemble_name_raw (file
, name
);
2199 /* Allocate SIZE bytes writable static space with a gensym name
2200 and return an RTX to refer to its address. */
2203 assemble_static_space (unsigned HOST_WIDE_INT size
)
2206 const char *namestring
;
2209 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2211 namestring
= ggc_strdup (name
);
2213 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2214 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2216 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2217 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2220 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2221 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2224 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2225 so that each uninitialized object starts on such a boundary. */
2226 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2227 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2228 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2229 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2230 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2231 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2238 /* Assemble the static constant template for function entry trampolines.
2239 This is done at most once per compilation.
2240 Returns an RTX for the address of the template. */
2242 static GTY(()) rtx initial_trampoline
;
2245 assemble_trampoline_template (void)
2252 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2254 if (initial_trampoline
)
2255 return initial_trampoline
;
2257 /* By default, put trampoline templates in read-only data section. */
2259 #ifdef TRAMPOLINE_SECTION
2260 switch_to_section (TRAMPOLINE_SECTION
);
2262 switch_to_section (readonly_data_section
);
2265 /* Write the assembler code to define one. */
2266 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2268 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2270 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2271 targetm
.asm_out
.trampoline_template (asm_out_file
);
2273 /* Record the rtl to refer to it. */
2274 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2275 name
= ggc_strdup (label
);
2276 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2277 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2279 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2280 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2281 set_mem_size (initial_trampoline
, GEN_INT (TRAMPOLINE_SIZE
));
2283 return initial_trampoline
;
2286 /* A and B are either alignments or offsets. Return the minimum alignment
2287 that may be assumed after adding the two together. */
2289 static inline unsigned
2290 min_align (unsigned int a
, unsigned int b
)
2292 return (a
| b
) & -(a
| b
);
2295 /* Return the assembler directive for creating a given kind of integer
2296 object. SIZE is the number of bytes in the object and ALIGNED_P
2297 indicates whether it is known to be aligned. Return NULL if the
2298 assembly dialect has no such directive.
2300 The returned string should be printed at the start of a new line and
2301 be followed immediately by the object's initial value. */
2304 integer_asm_op (int size
, int aligned_p
)
2306 struct asm_int_op
*ops
;
2309 ops
= &targetm
.asm_out
.aligned_op
;
2311 ops
= &targetm
.asm_out
.unaligned_op
;
2316 return targetm
.asm_out
.byte_op
;
2330 /* Use directive OP to assemble an integer object X. Print OP at the
2331 start of the line, followed immediately by the value of X. */
2334 assemble_integer_with_op (const char *op
, rtx x
)
2336 fputs (op
, asm_out_file
);
2337 output_addr_const (asm_out_file
, x
);
2338 fputc ('\n', asm_out_file
);
2341 /* The default implementation of the asm_out.integer target hook. */
2344 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2345 unsigned int size ATTRIBUTE_UNUSED
,
2346 int aligned_p ATTRIBUTE_UNUSED
)
2348 const char *op
= integer_asm_op (size
, aligned_p
);
2349 /* Avoid GAS bugs for large values. Specifically negative values whose
2350 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2351 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2353 return op
&& (assemble_integer_with_op (op
, x
), true);
2356 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2357 the alignment of the integer in bits. Return 1 if we were able to output
2358 the constant, otherwise 0. We must be able to output the constant,
2359 if FORCE is nonzero. */
2362 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2366 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2368 /* See if the target hook can handle this kind of object. */
2369 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2372 /* If the object is a multi-byte one, try splitting it up. Split
2373 it into words it if is multi-word, otherwise split it into bytes. */
2376 enum machine_mode omode
, imode
;
2377 unsigned int subalign
;
2378 unsigned int subsize
, i
;
2379 enum mode_class mclass
;
2381 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2382 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2383 if (GET_CODE (x
) == CONST_FIXED
)
2384 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2388 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2389 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2391 for (i
= 0; i
< size
; i
+= subsize
)
2393 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2394 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2400 /* If we've printed some of it, but not all of it, there's no going
2405 gcc_assert (!force
);
2411 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2413 long data
[4] = {0, 0, 0, 0};
2415 int bitsize
, nelts
, nunits
, units_per
;
2417 /* This is hairy. We have a quantity of known size. real_to_target
2418 will put it into an array of *host* longs, 32 bits per element
2419 (even if long is more than 32 bits). We need to determine the
2420 number of array elements that are occupied (nelts) and the number
2421 of *target* min-addressable units that will be occupied in the
2422 object file (nunits). We cannot assume that 32 divides the
2423 mode's bitsize (size * BITS_PER_UNIT) evenly.
2425 size * BITS_PER_UNIT is used here to make sure that padding bits
2426 (which might appear at either end of the value; real_to_target
2427 will include the padding bits in its output array) are included. */
2429 nunits
= GET_MODE_SIZE (mode
);
2430 bitsize
= nunits
* BITS_PER_UNIT
;
2431 nelts
= CEIL (bitsize
, 32);
2432 units_per
= 32 / BITS_PER_UNIT
;
2434 real_to_target (data
, &d
, mode
);
2436 /* Put out the first word with the specified alignment. */
2437 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2438 nunits
-= units_per
;
2440 /* Subsequent words need only 32-bit alignment. */
2441 align
= min_align (align
, 32);
2443 for (i
= 1; i
< nelts
; i
++)
2445 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2446 nunits
-= units_per
;
2450 /* Given an expression EXP with a constant value,
2451 reduce it to the sum of an assembler symbol and an integer.
2452 Store them both in the structure *VALUE.
2453 EXP must be reducible. */
2455 struct GTY(()) addr_const
{
2457 HOST_WIDE_INT offset
;
2461 decode_addr_const (tree exp
, struct addr_const
*value
)
2463 tree target
= TREE_OPERAND (exp
, 0);
2469 if (TREE_CODE (target
) == COMPONENT_REF
2470 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2472 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2473 target
= TREE_OPERAND (target
, 0);
2475 else if (TREE_CODE (target
) == ARRAY_REF
2476 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2478 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2479 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2480 target
= TREE_OPERAND (target
, 0);
2482 else if (TREE_CODE (target
) == INDIRECT_REF
2483 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2484 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2486 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2491 switch (TREE_CODE (target
))
2495 x
= DECL_RTL (target
);
2499 x
= gen_rtx_MEM (FUNCTION_MODE
,
2500 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2509 x
= output_constant_def (target
, 1);
2516 gcc_assert (MEM_P (x
));
2520 value
->offset
= offset
;
2524 static GTY((param_is (struct constant_descriptor_tree
)))
2525 htab_t const_desc_htab
;
2527 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2529 /* Constant pool accessor function. */
2532 constant_pool_htab (void)
2534 return const_desc_htab
;
2537 /* Compute a hash code for a constant expression. */
2540 const_desc_hash (const void *ptr
)
2542 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2546 const_hash_1 (const tree exp
)
2551 enum tree_code code
= TREE_CODE (exp
);
2553 /* Either set P and LEN to the address and len of something to hash and
2554 exit the switch or return a value. */
2559 p
= (char *) &TREE_INT_CST (exp
);
2560 len
= sizeof TREE_INT_CST (exp
);
2564 return real_hash (TREE_REAL_CST_PTR (exp
));
2567 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2570 p
= TREE_STRING_POINTER (exp
);
2571 len
= TREE_STRING_LENGTH (exp
);
2575 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2576 + const_hash_1 (TREE_IMAGPART (exp
)));
2582 hi
= 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
));
2584 for (link
= TREE_VECTOR_CST_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2585 hi
= hi
* 563 + const_hash_1 (TREE_VALUE (link
));
2592 unsigned HOST_WIDE_INT idx
;
2595 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2597 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2599 hi
= hi
* 603 + const_hash_1 (value
);
2607 struct addr_const value
;
2609 decode_addr_const (exp
, &value
);
2610 switch (GET_CODE (value
.base
))
2613 /* Don't hash the address of the SYMBOL_REF;
2614 only use the offset and the symbol name. */
2616 p
= XSTR (value
.base
, 0);
2617 for (i
= 0; p
[i
] != 0; i
++)
2618 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2622 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2632 case POINTER_PLUS_EXPR
:
2634 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2635 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2638 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2641 /* A language specific constant. Just hash the code. */
2645 /* Compute hashing function. */
2647 for (i
= 0; i
< len
; i
++)
2648 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2653 /* Wrapper of compare_constant, for the htab interface. */
2655 const_desc_eq (const void *p1
, const void *p2
)
2657 const struct constant_descriptor_tree
*const c1
2658 = (const struct constant_descriptor_tree
*) p1
;
2659 const struct constant_descriptor_tree
*const c2
2660 = (const struct constant_descriptor_tree
*) p2
;
2661 if (c1
->hash
!= c2
->hash
)
2663 return compare_constant (c1
->value
, c2
->value
);
2666 /* Compare t1 and t2, and return 1 only if they are known to result in
2667 the same bit pattern on output. */
2670 compare_constant (const tree t1
, const tree t2
)
2672 enum tree_code typecode
;
2674 if (t1
== NULL_TREE
)
2675 return t2
== NULL_TREE
;
2676 if (t2
== NULL_TREE
)
2679 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2682 switch (TREE_CODE (t1
))
2685 /* Integer constants are the same only if the same width of type. */
2686 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2688 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2690 return tree_int_cst_equal (t1
, t2
);
2693 /* Real constants are the same only if the same width of type. */
2694 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2697 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2700 /* Fixed constants are the same only if the same width of type. */
2701 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2704 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
2707 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2710 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2711 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2712 TREE_STRING_LENGTH (t1
)));
2715 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2716 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2722 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1
))
2723 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2
)))
2726 link2
= TREE_VECTOR_CST_ELTS (t2
);
2727 for (link1
= TREE_VECTOR_CST_ELTS (t1
);
2729 link1
= TREE_CHAIN (link1
))
2731 if (!compare_constant (TREE_VALUE (link1
), TREE_VALUE (link2
)))
2733 link2
= TREE_CHAIN (link2
);
2741 VEC(constructor_elt
, gc
) *v1
, *v2
;
2742 unsigned HOST_WIDE_INT idx
;
2744 typecode
= TREE_CODE (TREE_TYPE (t1
));
2745 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
2748 if (typecode
== ARRAY_TYPE
)
2750 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
2751 /* For arrays, check that the sizes all match. */
2752 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
2754 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
2759 /* For record and union constructors, require exact type
2761 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
2765 v1
= CONSTRUCTOR_ELTS (t1
);
2766 v2
= CONSTRUCTOR_ELTS (t2
);
2767 if (VEC_length (constructor_elt
, v1
)
2768 != VEC_length (constructor_elt
, v2
))
2771 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
2773 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
2774 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
2776 /* Check that each value is the same... */
2777 if (!compare_constant (c1
->value
, c2
->value
))
2779 /* ... and that they apply to the same fields! */
2780 if (typecode
== ARRAY_TYPE
)
2782 if (!compare_constant (c1
->index
, c2
->index
))
2787 if (c1
->index
!= c2
->index
)
2798 struct addr_const value1
, value2
;
2802 decode_addr_const (t1
, &value1
);
2803 decode_addr_const (t2
, &value2
);
2805 if (value1
.offset
!= value2
.offset
)
2808 code
= GET_CODE (value1
.base
);
2809 if (code
!= GET_CODE (value2
.base
))
2815 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
2819 ret
= (CODE_LABEL_NUMBER (XEXP (value1
.base
, 0))
2820 == CODE_LABEL_NUMBER (XEXP (value2
.base
, 0)));
2830 case POINTER_PLUS_EXPR
:
2833 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2834 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2837 case VIEW_CONVERT_EXPR
:
2838 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2847 /* Make a copy of the whole tree structure for a constant. This
2848 handles the same types of nodes that compare_constant handles. */
2851 copy_constant (tree exp
)
2853 switch (TREE_CODE (exp
))
2856 /* For ADDR_EXPR, we do not want to copy the decl whose address
2857 is requested. We do want to copy constants though. */
2858 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
2859 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2860 copy_constant (TREE_OPERAND (exp
, 0)));
2862 return copy_node (exp
);
2868 return copy_node (exp
);
2871 return build_complex (TREE_TYPE (exp
),
2872 copy_constant (TREE_REALPART (exp
)),
2873 copy_constant (TREE_IMAGPART (exp
)));
2876 case POINTER_PLUS_EXPR
:
2878 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
2879 copy_constant (TREE_OPERAND (exp
, 0)),
2880 copy_constant (TREE_OPERAND (exp
, 1)));
2883 case VIEW_CONVERT_EXPR
:
2884 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2885 copy_constant (TREE_OPERAND (exp
, 0)));
2888 return build_vector (TREE_TYPE (exp
),
2889 copy_list (TREE_VECTOR_CST_ELTS (exp
)));
2893 tree copy
= copy_node (exp
);
2894 VEC(constructor_elt
, gc
) *v
;
2895 unsigned HOST_WIDE_INT idx
;
2896 tree purpose
, value
;
2898 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
2899 CONSTRUCTOR_ELTS (exp
)));
2900 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
2902 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
2903 ce
->index
= purpose
;
2904 ce
->value
= copy_constant (value
);
2906 CONSTRUCTOR_ELTS (copy
) = v
;
2915 /* Return the section into which constant EXP should be placed. */
2918 get_constant_section (tree exp
, unsigned int align
)
2920 return targetm
.asm_out
.select_section (exp
,
2921 compute_reloc_for_constant (exp
),
2925 /* Return the size of constant EXP in bytes. */
2927 static HOST_WIDE_INT
2928 get_constant_size (tree exp
)
2932 size
= int_size_in_bytes (TREE_TYPE (exp
));
2933 if (TREE_CODE (exp
) == STRING_CST
)
2934 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
2938 /* Subroutine of output_constant_def:
2939 No constant equal to EXP is known to have been output.
2940 Make a constant descriptor to enter EXP in the hash table.
2941 Assign the label number and construct RTL to refer to the
2942 constant's location in memory.
2943 Caller is responsible for updating the hash table. */
2945 static struct constant_descriptor_tree
*
2946 build_constant_desc (tree exp
)
2948 struct constant_descriptor_tree
*desc
;
2954 desc
= ggc_alloc_constant_descriptor_tree ();
2955 desc
->value
= copy_constant (exp
);
2957 /* Propagate marked-ness to copied constant. */
2958 if (flag_mudflap
&& mf_marked_p (exp
))
2959 mf_mark (desc
->value
);
2961 /* Create a string containing the label name, in LABEL. */
2962 labelno
= const_labelno
++;
2963 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
2965 /* Construct the VAR_DECL associated with the constant. */
2966 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
2968 DECL_ARTIFICIAL (decl
) = 1;
2969 DECL_IGNORED_P (decl
) = 1;
2970 TREE_READONLY (decl
) = 1;
2971 TREE_STATIC (decl
) = 1;
2972 TREE_ADDRESSABLE (decl
) = 1;
2973 /* We don't set the RTL yet as this would cause varpool to assume that the
2974 variable is referenced. Moreover, it would just be dropped in LTO mode.
2975 Instead we set the flag that will be recognized in make_decl_rtl. */
2976 DECL_IN_CONSTANT_POOL (decl
) = 1;
2977 DECL_INITIAL (decl
) = desc
->value
;
2978 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
2979 architectures so use DATA_ALIGNMENT as well, except for strings. */
2980 if (TREE_CODE (exp
) == STRING_CST
)
2982 #ifdef CONSTANT_ALIGNMENT
2983 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
2987 align_variable (decl
, 0);
2989 /* Now construct the SYMBOL_REF and the MEM. */
2990 if (use_object_blocks_p ())
2992 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
2993 symbol
= create_block_symbol (ggc_strdup (label
),
2994 get_block_for_section (sect
), -1);
2997 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
2998 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
2999 SET_SYMBOL_REF_DECL (symbol
, decl
);
3000 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3002 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3003 set_mem_attributes (rtl
, exp
, 1);
3004 set_mem_alias_set (rtl
, 0);
3005 set_mem_alias_set (rtl
, const_alias_set
);
3007 /* We cannot share RTX'es in pool entries.
3008 Mark this piece of RTL as required for unsharing. */
3009 RTX_FLAG (rtl
, used
) = 1;
3011 /* Set flags or add text to the name to record information, such as
3012 that it is a local symbol. If the name is changed, the macro
3013 ASM_OUTPUT_LABELREF will have to know how to strip this
3014 information. This call might invalidate our local variable
3015 SYMBOL; we can't use it afterward. */
3016 targetm
.encode_section_info (exp
, rtl
, true);
3023 /* Return an rtx representing a reference to constant data in memory
3024 for the constant expression EXP.
3026 If assembler code for such a constant has already been output,
3027 return an rtx to refer to it.
3028 Otherwise, output such a constant in memory
3029 and generate an rtx for it.
3031 If DEFER is nonzero, this constant can be deferred and output only
3032 if referenced in the function after all optimizations.
3034 `const_desc_table' records which constants already have label strings. */
3037 output_constant_def (tree exp
, int defer
)
3039 struct constant_descriptor_tree
*desc
;
3040 struct constant_descriptor_tree key
;
3043 /* Look up EXP in the table of constant descriptors. If we didn't find
3044 it, create a new one. */
3046 key
.hash
= const_hash_1 (exp
);
3047 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3049 desc
= (struct constant_descriptor_tree
*) *loc
;
3052 desc
= build_constant_desc (exp
);
3053 desc
->hash
= key
.hash
;
3057 maybe_output_constant_def_contents (desc
, defer
);
3061 /* Subroutine of output_constant_def: Decide whether or not we need to
3062 output the constant DESC now, and if so, do it. */
3064 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3067 rtx symbol
= XEXP (desc
->rtl
, 0);
3068 tree exp
= desc
->value
;
3070 if (flag_syntax_only
)
3073 if (TREE_ASM_WRITTEN (exp
))
3074 /* Already output; don't do it again. */
3077 /* We can always defer constants as long as the context allows
3081 /* Increment n_deferred_constants if it exists. It needs to be at
3082 least as large as the number of constants actually referred to
3083 by the function. If it's too small we'll stop looking too early
3084 and fail to emit constants; if it's too large we'll only look
3085 through the entire function when we could have stopped earlier. */
3087 n_deferred_constants
++;
3091 output_constant_def_contents (symbol
);
3094 /* Subroutine of output_constant_def_contents. Output the definition
3095 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3096 constant's alignment in bits. */
3099 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3103 size
= get_constant_size (exp
);
3105 /* Do any machine/system dependent processing of the constant. */
3106 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3108 /* Output the value of EXP. */
3109 output_constant (exp
, size
, align
);
3112 /* We must output the constant data referred to by SYMBOL; do so. */
3115 output_constant_def_contents (rtx symbol
)
3117 tree decl
= SYMBOL_REF_DECL (symbol
);
3118 tree exp
= DECL_INITIAL (decl
);
3121 /* Make sure any other constants whose addresses appear in EXP
3122 are assigned label numbers. */
3123 output_addressed_constants (exp
);
3125 /* We are no longer deferring this constant. */
3126 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3128 /* If the constant is part of an object block, make sure that the
3129 decl has been positioned within its block, but do not write out
3130 its definition yet. output_object_blocks will do that later. */
3131 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3132 place_block_symbol (symbol
);
3135 align
= DECL_ALIGN (decl
);
3136 switch_to_section (get_constant_section (exp
, align
));
3137 if (align
> BITS_PER_UNIT
)
3138 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3139 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3142 mudflap_enqueue_constant (exp
);
3145 /* Look up EXP in the table of constant descriptors. Return the rtl
3146 if it has been emitted, else null. */
3149 lookup_constant_def (tree exp
)
3151 struct constant_descriptor_tree
*desc
;
3152 struct constant_descriptor_tree key
;
3155 key
.hash
= const_hash_1 (exp
);
3156 desc
= (struct constant_descriptor_tree
*)
3157 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3159 return (desc
? desc
->rtl
: NULL_RTX
);
3162 /* Return a tree representing a reference to constant data in memory
3163 for the constant expression EXP.
3165 This is the counterpart of output_constant_def at the Tree level. */
3168 tree_output_constant_def (tree exp
)
3170 struct constant_descriptor_tree
*desc
, key
;
3174 /* Look up EXP in the table of constant descriptors. If we didn't find
3175 it, create a new one. */
3177 key
.hash
= const_hash_1 (exp
);
3178 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3180 desc
= (struct constant_descriptor_tree
*) *loc
;
3183 desc
= build_constant_desc (exp
);
3184 desc
->hash
= key
.hash
;
3188 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3189 varpool_finalize_decl (decl
);
3193 /* Used in the hash tables to avoid outputting the same constant
3194 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3195 are output once per function, not once per file. */
3196 /* ??? Only a few targets need per-function constant pools. Most
3197 can use one per-file pool. Should add a targetm bit to tell the
3200 struct GTY(()) rtx_constant_pool
{
3201 /* Pointers to first and last constant in pool, as ordered by offset. */
3202 struct constant_descriptor_rtx
*first
;
3203 struct constant_descriptor_rtx
*last
;
3205 /* Hash facility for making memory-constants from constant rtl-expressions.
3206 It is used on RISC machines where immediate integer arguments and
3207 constant addresses are restricted so that such constants must be stored
3209 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3211 /* Current offset in constant pool (does not include any
3212 machine-specific header). */
3213 HOST_WIDE_INT offset
;
3216 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3217 struct constant_descriptor_rtx
*next
;
3221 HOST_WIDE_INT offset
;
3223 enum machine_mode mode
;
3229 /* Hash and compare functions for const_rtx_htab. */
3232 const_desc_rtx_hash (const void *ptr
)
3234 const struct constant_descriptor_rtx
*const desc
3235 = (const struct constant_descriptor_rtx
*) ptr
;
3240 const_desc_rtx_eq (const void *a
, const void *b
)
3242 const struct constant_descriptor_rtx
*const x
3243 = (const struct constant_descriptor_rtx
*) a
;
3244 const struct constant_descriptor_rtx
*const y
3245 = (const struct constant_descriptor_rtx
*) b
;
3247 if (x
->mode
!= y
->mode
)
3249 return rtx_equal_p (x
->constant
, y
->constant
);
3252 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3255 const_rtx_hash_1 (rtx
*xp
, void *data
)
3257 unsigned HOST_WIDE_INT hwi
;
3258 enum machine_mode mode
;
3264 code
= GET_CODE (x
);
3265 mode
= GET_MODE (x
);
3266 h
= (hashval_t
) code
* 1048573 + mode
;
3274 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3275 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3278 h
^= (hashval_t
) hwi
;
3279 for (i
= 1; i
< n
; ++i
)
3282 h
^= (hashval_t
) hwi
;
3288 if (mode
== VOIDmode
)
3290 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3294 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3298 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3304 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3305 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3310 h
^= htab_hash_string (XSTR (x
, 0));
3314 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3318 case UNSPEC_VOLATILE
:
3319 h
= h
* 251 + XINT (x
, 1);
3326 hp
= (hashval_t
*) data
;
3327 *hp
= *hp
* 509 + h
;
3331 /* Compute a hash value for X, which should be a constant. */
3334 const_rtx_hash (rtx x
)
3337 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3342 /* Create and return a new rtx constant pool. */
3344 static struct rtx_constant_pool
*
3345 create_constant_pool (void)
3347 struct rtx_constant_pool
*pool
;
3349 pool
= ggc_alloc_rtx_constant_pool ();
3350 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3351 const_desc_rtx_eq
, NULL
);
3358 /* Initialize constant pool hashing for a new function. */
3361 init_varasm_status (void)
3363 crtl
->varasm
.pool
= create_constant_pool ();
3364 crtl
->varasm
.deferred_constants
= 0;
3367 /* Given a MINUS expression, simplify it if both sides
3368 include the same symbol. */
3371 simplify_subtraction (rtx x
)
3373 rtx r
= simplify_rtx (x
);
3377 /* Given a constant rtx X, make (or find) a memory constant for its value
3378 and return a MEM rtx to refer to it in memory. */
3381 force_const_mem (enum machine_mode mode
, rtx x
)
3383 struct constant_descriptor_rtx
*desc
, tmp
;
3384 struct rtx_constant_pool
*pool
;
3391 /* If we're not allowed to drop X into the constant pool, don't. */
3392 if (targetm
.cannot_force_const_mem (x
))
3395 /* Record that this function has used a constant pool entry. */
3396 crtl
->uses_const_pool
= 1;
3398 /* Decide which pool to use. */
3399 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3400 ? shared_constant_pool
3401 : crtl
->varasm
.pool
);
3403 /* Lookup the value in the hashtable. */
3406 hash
= const_rtx_hash (x
);
3407 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3408 desc
= (struct constant_descriptor_rtx
*) *slot
;
3410 /* If the constant was already present, return its memory. */
3412 return copy_rtx (desc
->mem
);
3414 /* Otherwise, create a new descriptor. */
3415 desc
= ggc_alloc_constant_descriptor_rtx ();
3418 /* Align the location counter as required by EXP's data type. */
3419 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3420 #ifdef CONSTANT_ALIGNMENT
3422 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3423 if (type
!= NULL_TREE
)
3424 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3428 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3429 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3432 desc
->constant
= tmp
.constant
;
3433 desc
->offset
= pool
->offset
;
3436 desc
->align
= align
;
3437 desc
->labelno
= const_labelno
;
3440 pool
->offset
+= GET_MODE_SIZE (mode
);
3442 pool
->last
->next
= desc
;
3444 pool
->first
= pool
->last
= desc
;
3447 /* Create a string containing the label name, in LABEL. */
3448 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3451 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3452 the constants pool. */
3453 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3455 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3456 symbol
= create_block_symbol (ggc_strdup (label
),
3457 get_block_for_section (sect
), -1);
3460 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3462 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3463 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3464 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3466 /* Construct the MEM. */
3467 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3468 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3469 set_mem_align (def
, align
);
3471 /* If we're dropping a label to the constant pool, make sure we
3473 if (GET_CODE (x
) == LABEL_REF
)
3474 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3476 return copy_rtx (def
);
3479 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3482 get_pool_constant (rtx addr
)
3484 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3487 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3488 and whether it has been output or not. */
3491 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3493 struct constant_descriptor_rtx
*desc
;
3495 desc
= SYMBOL_REF_CONSTANT (addr
);
3496 *pmarked
= (desc
->mark
!= 0);
3497 return desc
->constant
;
3500 /* Similar, return the mode. */
3503 get_pool_mode (const_rtx addr
)
3505 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3508 /* Return the size of the constant pool. */
3511 get_pool_size (void)
3513 return crtl
->varasm
.pool
->offset
;
3516 /* Worker function for output_constant_pool_1. Emit assembly for X
3517 in MODE with known alignment ALIGN. */
3520 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3522 switch (GET_MODE_CLASS (mode
))
3525 case MODE_DECIMAL_FLOAT
:
3529 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3530 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3531 assemble_real (r
, mode
, align
);
3536 case MODE_PARTIAL_INT
:
3541 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3544 case MODE_VECTOR_FLOAT
:
3545 case MODE_VECTOR_INT
:
3546 case MODE_VECTOR_FRACT
:
3547 case MODE_VECTOR_UFRACT
:
3548 case MODE_VECTOR_ACCUM
:
3549 case MODE_VECTOR_UACCUM
:
3552 enum machine_mode submode
= GET_MODE_INNER (mode
);
3553 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3555 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3556 units
= CONST_VECTOR_NUNITS (x
);
3558 for (i
= 0; i
< units
; i
++)
3560 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3561 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3571 /* Worker function for output_constant_pool. Emit constant DESC,
3572 giving it ALIGN bits of alignment. */
3575 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3582 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3583 whose CODE_LABEL has been deleted. This can occur if a jump table
3584 is eliminated by optimization. If so, write a constant of zero
3585 instead. Note that this can also happen by turning the
3586 CODE_LABEL into a NOTE. */
3587 /* ??? This seems completely and utterly wrong. Certainly it's
3588 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3589 functioning even with INSN_DELETED_P and friends. */
3592 switch (GET_CODE (tmp
))
3595 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3596 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3598 tmp
= XEXP (XEXP (tmp
, 0), 0);
3602 tmp
= XEXP (tmp
, 0);
3603 gcc_assert (!INSN_DELETED_P (tmp
));
3604 gcc_assert (!NOTE_P (tmp
)
3605 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3612 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3613 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3614 align
, desc
->labelno
, done
);
3617 assemble_align (align
);
3619 /* Output the label. */
3620 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3622 /* Output the data. */
3623 output_constant_pool_2 (desc
->mode
, x
, align
);
3625 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3626 sections have proper size. */
3627 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3629 && (in_section
->common
.flags
& SECTION_MERGE
))
3630 assemble_align (align
);
3632 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3638 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3639 to as used. Emit referenced deferred strings. This function can
3640 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3643 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
3645 rtx x
= *current_rtx
;
3647 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3650 if (CONSTANT_POOL_ADDRESS_P (x
))
3652 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3653 if (desc
->mark
== 0)
3656 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
3659 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3661 tree decl
= SYMBOL_REF_DECL (x
);
3662 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
3664 n_deferred_constants
--;
3665 output_constant_def_contents (x
);
3672 /* Look through appropriate parts of INSN, marking all entries in the
3673 constant pool which are actually being used. Entries that are only
3674 referenced by other constants are also marked as used. Emit
3675 deferred strings that are used. */
3678 mark_constants (rtx insn
)
3683 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3684 insns, not any notes that may be attached. We don't want to mark
3685 a constant just because it happens to appear in a REG_EQUIV note. */
3686 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3688 rtx seq
= PATTERN (insn
);
3689 int i
, n
= XVECLEN (seq
, 0);
3690 for (i
= 0; i
< n
; ++i
)
3692 rtx subinsn
= XVECEXP (seq
, 0, i
);
3693 if (INSN_P (subinsn
))
3694 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
3698 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
3701 /* Look through the instructions for this function, and mark all the
3702 entries in POOL which are actually being used. Emit deferred constants
3703 which have indeed been used. */
3706 mark_constant_pool (void)
3710 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
3713 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3714 mark_constants (insn
);
3716 for (link
= crtl
->epilogue_delay_list
;
3718 link
= XEXP (link
, 1))
3719 mark_constants (XEXP (link
, 0));
3722 /* Write all the constants in POOL. */
3725 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
3727 struct constant_descriptor_rtx
*desc
;
3729 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3732 /* If the constant is part of an object_block, make sure that
3733 the constant has been positioned within its block, but do not
3734 write out its definition yet. output_object_blocks will do
3736 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
3737 && SYMBOL_REF_BLOCK (desc
->sym
))
3738 place_block_symbol (desc
->sym
);
3741 switch_to_section (targetm
.asm_out
.select_rtx_section
3742 (desc
->mode
, desc
->constant
, desc
->align
));
3743 output_constant_pool_1 (desc
, desc
->align
);
3748 /* Mark all constants that are used in the current function, then write
3749 out the function's private constant pool. */
3752 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3753 tree fndecl ATTRIBUTE_UNUSED
)
3755 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
3757 /* It is possible for gcc to call force_const_mem and then to later
3758 discard the instructions which refer to the constant. In such a
3759 case we do not need to output the constant. */
3760 mark_constant_pool ();
3762 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3763 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3766 output_constant_pool_contents (pool
);
3768 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3769 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3773 /* Write the contents of the shared constant pool. */
3776 output_shared_constant_pool (void)
3778 output_constant_pool_contents (shared_constant_pool
);
3781 /* Determine what kind of relocations EXP may need. */
3784 compute_reloc_for_constant (tree exp
)
3786 int reloc
= 0, reloc2
;
3789 switch (TREE_CODE (exp
))
3793 /* Go inside any operations that get_inner_reference can handle and see
3794 if what's inside is a constant: no need to do anything here for
3795 addresses of variables or functions. */
3796 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3797 tem
= TREE_OPERAND (tem
, 0))
3800 if (TREE_PUBLIC (tem
))
3807 case POINTER_PLUS_EXPR
:
3808 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3809 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3813 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3814 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3815 /* The difference of two local labels is computable at link time. */
3816 if (reloc
== 1 && reloc2
== 1)
3823 case VIEW_CONVERT_EXPR
:
3824 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3829 unsigned HOST_WIDE_INT idx
;
3830 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3832 reloc
|= compute_reloc_for_constant (tem
);
3842 /* Find all the constants whose addresses are referenced inside of EXP,
3843 and make sure assembler code with a label has been output for each one.
3844 Indicate whether an ADDR_EXPR has been encountered. */
3847 output_addressed_constants (tree exp
)
3851 switch (TREE_CODE (exp
))
3855 /* Go inside any operations that get_inner_reference can handle and see
3856 if what's inside is a constant: no need to do anything here for
3857 addresses of variables or functions. */
3858 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3859 tem
= TREE_OPERAND (tem
, 0))
3862 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3863 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
3864 tem
= DECL_INITIAL (tem
);
3866 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
3867 output_constant_def (tem
, 0);
3871 case POINTER_PLUS_EXPR
:
3873 output_addressed_constants (TREE_OPERAND (exp
, 1));
3877 case VIEW_CONVERT_EXPR
:
3878 output_addressed_constants (TREE_OPERAND (exp
, 0));
3883 unsigned HOST_WIDE_INT idx
;
3884 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3886 output_addressed_constants (tem
);
3895 /* Whether a constructor CTOR is a valid static constant initializer if all
3896 its elements are. This used to be internal to initializer_constant_valid_p
3897 and has been exposed to let other functions like categorize_ctor_elements
3898 evaluate the property while walking a constructor for other purposes. */
3901 constructor_static_from_elts_p (const_tree ctor
)
3903 return (TREE_CONSTANT (ctor
)
3904 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
3905 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
3906 || TREE_CODE (TREE_TYPE (ctor
)) == ARRAY_TYPE
));
3909 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
3912 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
3913 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
3914 which are valid when ENDTYPE is an integer of any size; in
3915 particular, this does not accept a pointer minus a constant. This
3916 returns null_pointer_node if the VALUE is an absolute constant
3917 which can be used to initialize a static variable. Otherwise it
3921 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
3925 if (!INTEGRAL_TYPE_P (endtype
))
3928 op0
= TREE_OPERAND (value
, 0);
3929 op1
= TREE_OPERAND (value
, 1);
3931 /* Like STRIP_NOPS except allow the operand mode to widen. This
3932 works around a feature of fold that simplifies (int)(p1 - p2) to
3933 ((int)p1 - (int)p2) under the theory that the narrower operation
3936 while (CONVERT_EXPR_P (op0
)
3937 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
3939 tree inner
= TREE_OPERAND (op0
, 0);
3940 if (inner
== error_mark_node
3941 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3942 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
3943 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3948 while (CONVERT_EXPR_P (op1
)
3949 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
3951 tree inner
= TREE_OPERAND (op1
, 0);
3952 if (inner
== error_mark_node
3953 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3954 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
3955 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3960 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
3964 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
3965 cache
? cache
+ 2 : NULL
);
3966 /* Both initializers must be known. */
3970 && (op0
== null_pointer_node
3971 || TREE_CODE (value
) == MINUS_EXPR
))
3972 return null_pointer_node
;
3974 /* Support differences between labels. */
3975 if (TREE_CODE (op0
) == LABEL_DECL
3976 && TREE_CODE (op1
) == LABEL_DECL
)
3977 return null_pointer_node
;
3979 if (TREE_CODE (op0
) == STRING_CST
3980 && TREE_CODE (op1
) == STRING_CST
3981 && operand_equal_p (op0
, op1
, 1))
3982 return null_pointer_node
;
3988 /* Helper function of initializer_constant_valid_p.
3989 Return nonzero if VALUE is a valid constant-valued expression
3990 for use in initializing a static variable; one that can be an
3991 element of a "constant" initializer.
3993 Return null_pointer_node if the value is absolute;
3994 if it is relocatable, return the variable that determines the relocation.
3995 We assume that VALUE has been folded as much as possible;
3996 therefore, we do not need to check for such things as
3997 arithmetic-combinations of integers.
3999 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4002 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4006 switch (TREE_CODE (value
))
4009 if (constructor_static_from_elts_p (value
))
4011 unsigned HOST_WIDE_INT idx
;
4013 bool absolute
= true;
4015 if (cache
&& cache
[0] == value
)
4017 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4020 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4027 cache
[1] = NULL_TREE
;
4031 if (reloc
!= null_pointer_node
)
4034 /* For a non-absolute relocation, there is no single
4035 variable that can be "the variable that determines the
4040 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4042 return absolute
? null_pointer_node
: error_mark_node
;
4045 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4053 return null_pointer_node
;
4058 tree op0
= staticp (TREE_OPERAND (value
, 0));
4061 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4062 to be a constant, this is old-skool offsetof-like nonsense. */
4063 if (TREE_CODE (op0
) == INDIRECT_REF
4064 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4065 return null_pointer_node
;
4066 /* Taking the address of a nested function involves a trampoline,
4067 unless we don't need or want one. */
4068 if (TREE_CODE (op0
) == FUNCTION_DECL
4069 && DECL_STATIC_CHAIN (op0
)
4070 && !TREE_NO_TRAMPOLINE (value
))
4072 /* "&{...}" requires a temporary to hold the constructed
4074 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4080 case NON_LVALUE_EXPR
:
4081 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4084 case VIEW_CONVERT_EXPR
:
4086 tree src
= TREE_OPERAND (value
, 0);
4087 tree src_type
= TREE_TYPE (src
);
4088 tree dest_type
= TREE_TYPE (value
);
4090 /* Allow view-conversions from aggregate to non-aggregate type only
4091 if the bit pattern is fully preserved afterwards; otherwise, the
4092 RTL expander won't be able to apply a subsequent transformation
4093 to the underlying constructor. */
4094 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4096 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4097 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4102 /* Allow all other kinds of view-conversion. */
4103 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4108 tree src
= TREE_OPERAND (value
, 0);
4109 tree src_type
= TREE_TYPE (src
);
4110 tree dest_type
= TREE_TYPE (value
);
4112 /* Allow conversions between pointer types, floating-point
4113 types, and offset types. */
4114 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4115 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4116 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4117 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4118 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4120 /* Allow length-preserving conversions between integer types. */
4121 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4122 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4123 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4125 /* Allow conversions between other integer types only if
4127 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4129 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4130 if (inner
== null_pointer_node
)
4131 return null_pointer_node
;
4135 /* Allow (int) &foo provided int is as wide as a pointer. */
4136 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4137 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4138 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4140 /* Likewise conversions from int to pointers, but also allow
4141 conversions from 0. */
4142 if ((POINTER_TYPE_P (dest_type
)
4143 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4144 && INTEGRAL_TYPE_P (src_type
))
4146 if (TREE_CODE (src
) == INTEGER_CST
4147 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4148 return null_pointer_node
;
4149 if (integer_zerop (src
))
4150 return null_pointer_node
;
4151 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4152 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4155 /* Allow conversions to struct or union types if the value
4157 if (TREE_CODE (dest_type
) == RECORD_TYPE
4158 || TREE_CODE (dest_type
) == UNION_TYPE
)
4159 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4163 case POINTER_PLUS_EXPR
:
4165 /* Any valid floating-point constants will have been folded by now;
4166 with -frounding-math we hit this with addition of two constants. */
4167 if (TREE_CODE (endtype
) == REAL_TYPE
)
4169 if (cache
&& cache
[0] == value
)
4171 if (! INTEGRAL_TYPE_P (endtype
)
4172 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4174 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4176 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4179 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4180 endtype
, ncache
+ 2);
4181 /* If either term is absolute, use the other term's relocation. */
4182 if (valid0
== null_pointer_node
)
4184 else if (valid1
== null_pointer_node
)
4186 /* Support narrowing pointer differences. */
4188 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4192 /* Support narrowing pointer differences. */
4193 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4202 if (TREE_CODE (endtype
) == REAL_TYPE
)
4204 if (cache
&& cache
[0] == value
)
4206 if (! INTEGRAL_TYPE_P (endtype
)
4207 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4209 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4211 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4214 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4215 endtype
, ncache
+ 2);
4216 /* Win if second argument is absolute. */
4217 if (valid1
== null_pointer_node
)
4219 /* Win if both arguments have the same relocation.
4220 Then the value is absolute. */
4221 else if (valid0
== valid1
&& valid0
!= 0)
4222 ret
= null_pointer_node
;
4223 /* Since GCC guarantees that string constants are unique in the
4224 generated code, a subtraction between two copies of the same
4225 constant string is absolute. */
4226 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4227 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4228 && operand_equal_p (valid0
, valid1
, 1))
4229 ret
= null_pointer_node
;
4230 /* Support narrowing differences. */
4232 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4236 /* Support narrowing differences. */
4237 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4252 /* Return nonzero if VALUE is a valid constant-valued expression
4253 for use in initializing a static variable; one that can be an
4254 element of a "constant" initializer.
4256 Return null_pointer_node if the value is absolute;
4257 if it is relocatable, return the variable that determines the relocation.
4258 We assume that VALUE has been folded as much as possible;
4259 therefore, we do not need to check for such things as
4260 arithmetic-combinations of integers. */
4262 initializer_constant_valid_p (tree value
, tree endtype
)
4264 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4267 /* Return true if VALUE is a valid constant-valued expression
4268 for use in initializing a static bit-field; one that can be
4269 an element of a "constant" initializer. */
4272 initializer_constant_valid_for_bitfield_p (tree value
)
4274 /* For bitfields we support integer constants or possibly nested aggregates
4276 switch (TREE_CODE (value
))
4280 unsigned HOST_WIDE_INT idx
;
4283 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4284 if (!initializer_constant_valid_for_bitfield_p (elt
))
4292 case VIEW_CONVERT_EXPR
:
4293 case NON_LVALUE_EXPR
:
4295 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4304 /* output_constructor outer state of relevance in recursive calls, typically
4305 for nested aggregate bitfields. */
4308 unsigned int bit_offset
; /* current position in ... */
4309 int byte
; /* ... the outer byte buffer. */
4312 static unsigned HOST_WIDE_INT
4313 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4316 /* Output assembler code for constant EXP to FILE, with no label.
4317 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4318 Assumes output_addressed_constants has been done on EXP already.
4320 Generate exactly SIZE bytes of assembler data, padding at the end
4321 with zeros if necessary. SIZE must always be specified.
4323 SIZE is important for structure constructors,
4324 since trailing members may have been omitted from the constructor.
4325 It is also important for initialization of arrays from string constants
4326 since the full length of the string constant might not be wanted.
4327 It is also needed for initialization of unions, where the initializer's
4328 type is just one member, and that may not be as long as the union.
4330 There a case in which we would fail to output exactly SIZE bytes:
4331 for a structure constructor that wants to produce more than SIZE bytes.
4332 But such constructors will never be generated for any possible input.
4334 ALIGN is the alignment of the data in bits. */
4337 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4339 enum tree_code code
;
4340 unsigned HOST_WIDE_INT thissize
;
4342 if (size
== 0 || flag_syntax_only
)
4345 /* See if we're trying to initialize a pointer in a non-default mode
4346 to the address of some declaration somewhere. If the target says
4347 the mode is valid for pointers, assume the target has a way of
4349 if (TREE_CODE (exp
) == NOP_EXPR
4350 && POINTER_TYPE_P (TREE_TYPE (exp
))
4351 && targetm
.addr_space
.valid_pointer_mode
4352 (TYPE_MODE (TREE_TYPE (exp
)),
4353 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4355 tree saved_type
= TREE_TYPE (exp
);
4357 /* Peel off any intermediate conversions-to-pointer for valid
4359 while (TREE_CODE (exp
) == NOP_EXPR
4360 && POINTER_TYPE_P (TREE_TYPE (exp
))
4361 && targetm
.addr_space
.valid_pointer_mode
4362 (TYPE_MODE (TREE_TYPE (exp
)),
4363 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4364 exp
= TREE_OPERAND (exp
, 0);
4366 /* If what we're left with is the address of something, we can
4367 convert the address to the final type and output it that
4369 if (TREE_CODE (exp
) == ADDR_EXPR
)
4370 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4371 /* Likewise for constant ints. */
4372 else if (TREE_CODE (exp
) == INTEGER_CST
)
4373 exp
= build_int_cst_wide (saved_type
, TREE_INT_CST_LOW (exp
),
4374 TREE_INT_CST_HIGH (exp
));
4378 /* Eliminate any conversions since we'll be outputting the underlying
4380 while (CONVERT_EXPR_P (exp
)
4381 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4382 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4384 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4385 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4387 /* Make sure eliminating the conversion is really a no-op, except with
4388 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4389 union types to allow for Ada unchecked unions. */
4390 if (type_size
> op_size
4391 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4392 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4393 /* Keep the conversion. */
4396 exp
= TREE_OPERAND (exp
, 0);
4399 code
= TREE_CODE (TREE_TYPE (exp
));
4400 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4402 /* Allow a constructor with no elements for any data type.
4403 This means to fill the space with zeros. */
4404 if (TREE_CODE (exp
) == CONSTRUCTOR
4405 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
4407 assemble_zeros (size
);
4411 if (TREE_CODE (exp
) == FDESC_EXPR
)
4413 #ifdef ASM_OUTPUT_FDESC
4414 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4415 tree decl
= TREE_OPERAND (exp
, 0);
4416 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4423 /* Now output the underlying data. If we've handling the padding, return.
4424 Otherwise, break and ensure SIZE is the size written. */
4431 case REFERENCE_TYPE
:
4433 case FIXED_POINT_TYPE
:
4434 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4435 EXPAND_INITIALIZER
),
4436 MIN (size
, thissize
), align
, 0))
4437 error ("initializer for integer/fixed-point value is too complicated");
4441 if (TREE_CODE (exp
) != REAL_CST
)
4442 error ("initializer for floating value is not a floating constant");
4444 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4448 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4449 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4450 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4455 switch (TREE_CODE (exp
))
4458 output_constructor (exp
, size
, align
, NULL
);
4461 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
4463 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4470 unsigned int nalign
;
4471 enum machine_mode inner
;
4473 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4474 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4476 elt_size
= GET_MODE_SIZE (inner
);
4478 link
= TREE_VECTOR_CST_ELTS (exp
);
4479 output_constant (TREE_VALUE (link
), elt_size
, align
);
4480 thissize
= elt_size
;
4481 while ((link
= TREE_CHAIN (link
)) != NULL
)
4483 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
4484 thissize
+= elt_size
;
4495 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4496 output_constructor (exp
, size
, align
, NULL
);
4506 if (size
> thissize
)
4507 assemble_zeros (size
- thissize
);
4511 /* Subroutine of output_constructor, used for computing the size of
4512 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4513 type with an unspecified upper bound. */
4515 static unsigned HOST_WIDE_INT
4516 array_size_for_constructor (tree val
)
4519 unsigned HOST_WIDE_INT cnt
;
4520 tree index
, value
, tmp
;
4522 /* This code used to attempt to handle string constants that are not
4523 arrays of single-bytes, but nothing else does, so there's no point in
4525 if (TREE_CODE (val
) == STRING_CST
)
4526 return TREE_STRING_LENGTH (val
);
4528 max_index
= NULL_TREE
;
4529 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4531 if (TREE_CODE (index
) == RANGE_EXPR
)
4532 index
= TREE_OPERAND (index
, 1);
4533 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4537 if (max_index
== NULL_TREE
)
4540 /* Compute the total number of array elements. */
4541 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4542 i
= size_binop (MINUS_EXPR
, fold_convert (sizetype
, max_index
),
4543 fold_convert (sizetype
, tmp
));
4544 i
= size_binop (PLUS_EXPR
, i
, size_one_node
);
4546 /* Multiply by the array element unit size to find number of bytes. */
4547 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4549 return tree_low_cst (i
, 1);
4552 /* Other datastructures + helpers for output_constructor. */
4554 /* output_constructor local state to support interaction with helpers. */
4558 /* Received arguments. */
4559 tree exp
; /* Constructor expression. */
4560 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4561 unsigned int align
; /* Known initial alignment. */
4563 /* Constructor expression data. */
4564 tree type
; /* Expression type. */
4565 tree field
; /* Current field decl in a record. */
4566 tree min_index
; /* Lower bound if specified for an array. */
4568 /* Output processing state. */
4569 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4570 bool byte_buffer_in_use
; /* Whether byte ... */
4571 int byte
; /* ... contains part of a bitfield byte yet to
4574 int last_relative_index
; /* Implicit or explicit index of the last
4575 array element output within a bitfield. */
4576 /* Current element. */
4577 tree val
; /* Current element value. */
4578 tree index
; /* Current element index. */
4582 /* Helper for output_constructor. From the current LOCAL state, output a
4583 RANGE_EXPR element. */
4586 output_constructor_array_range (oc_local_state
*local
)
4588 unsigned HOST_WIDE_INT fieldsize
4589 = int_size_in_bytes (TREE_TYPE (local
->type
));
4591 HOST_WIDE_INT lo_index
4592 = tree_low_cst (TREE_OPERAND (local
->index
, 0), 0);
4593 HOST_WIDE_INT hi_index
4594 = tree_low_cst (TREE_OPERAND (local
->index
, 1), 0);
4595 HOST_WIDE_INT index
;
4598 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4600 for (index
= lo_index
; index
<= hi_index
; index
++)
4602 /* Output the element's initial value. */
4603 if (local
->val
== NULL_TREE
)
4604 assemble_zeros (fieldsize
);
4606 output_constant (local
->val
, fieldsize
, align2
);
4608 /* Count its size. */
4609 local
->total_bytes
+= fieldsize
;
4613 /* Helper for output_constructor. From the current LOCAL state, output a
4614 field element that is not true bitfield or part of an outer one. */
4617 output_constructor_regular_field (oc_local_state
*local
)
4619 /* Field size and position. Since this structure is static, we know the
4620 positions are constant. */
4621 unsigned HOST_WIDE_INT fieldsize
;
4622 HOST_WIDE_INT fieldpos
;
4624 unsigned int align2
;
4626 if (local
->index
!= NULL_TREE
)
4627 fieldpos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
)), 1)
4628 * ((tree_low_cst (local
->index
, 0)
4629 - tree_low_cst (local
->min_index
, 0))));
4630 else if (local
->field
!= NULL_TREE
)
4631 fieldpos
= int_byte_position (local
->field
);
4635 /* Output any buffered-up bit-fields preceding this element. */
4636 if (local
->byte_buffer_in_use
)
4638 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4639 local
->total_bytes
++;
4640 local
->byte_buffer_in_use
= false;
4643 /* Advance to offset of this element.
4644 Note no alignment needed in an array, since that is guaranteed
4645 if each element has the proper size. */
4646 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4647 && fieldpos
!= local
->total_bytes
)
4649 gcc_assert (fieldpos
>= local
->total_bytes
);
4650 assemble_zeros (fieldpos
- local
->total_bytes
);
4651 local
->total_bytes
= fieldpos
;
4654 /* Find the alignment of this element. */
4655 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
4657 /* Determine size this element should occupy. */
4662 /* If this is an array with an unspecified upper bound,
4663 the initializer determines the size. */
4664 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4665 but we cannot do this until the deprecated support for
4666 initializing zero-length array members is removed. */
4667 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
4668 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
4669 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
4671 fieldsize
= array_size_for_constructor (local
->val
);
4672 /* Given a non-empty initialization, this field had
4674 gcc_assert (!fieldsize
|| !DECL_CHAIN (local
->field
));
4676 else if (DECL_SIZE_UNIT (local
->field
))
4678 /* ??? This can't be right. If the decl size overflows
4679 a host integer we will silently emit no data. */
4680 if (host_integerp (DECL_SIZE_UNIT (local
->field
), 1))
4681 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (local
->field
), 1);
4685 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
4687 /* Output the element's initial value. */
4688 if (local
->val
== NULL_TREE
)
4689 assemble_zeros (fieldsize
);
4691 output_constant (local
->val
, fieldsize
, align2
);
4693 /* Count its size. */
4694 local
->total_bytes
+= fieldsize
;
4697 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4698 output an element that is a true bitfield or part of an outer one. */
4701 output_constructor_bitfield (oc_local_state
*local
, oc_outer_state
*outer
)
4703 /* Bit size of this element. */
4704 HOST_WIDE_INT ebitsize
4706 ? tree_low_cst (DECL_SIZE (local
->field
), 1)
4707 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local
->type
)), 1));
4709 /* Relative index of this element if this is an array component. */
4710 HOST_WIDE_INT relative_index
4713 ? (tree_low_cst (local
->index
, 0)
4714 - tree_low_cst (local
->min_index
, 0))
4715 : local
->last_relative_index
+ 1)
4718 /* Bit position of this element from the start of the containing
4720 HOST_WIDE_INT constructor_relative_ebitpos
4722 ? int_bit_position (local
->field
)
4723 : ebitsize
* relative_index
);
4725 /* Bit position of this element from the start of a possibly ongoing
4726 outer byte buffer. */
4727 HOST_WIDE_INT byte_relative_ebitpos
4728 = ((outer
? outer
->bit_offset
: 0) + constructor_relative_ebitpos
);
4730 /* From the start of a possibly ongoing outer byte buffer, offsets to
4731 the first bit of this element and to the first bit past the end of
4733 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
4734 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
4736 local
->last_relative_index
= relative_index
;
4738 if (local
->val
== NULL_TREE
)
4739 local
->val
= integer_zero_node
;
4741 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
4742 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
4743 local
->val
= TREE_OPERAND (local
->val
, 0);
4745 if (TREE_CODE (local
->val
) != INTEGER_CST
4746 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
4748 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
4752 /* If this field does not start in this (or, next) byte,
4754 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4756 /* Output remnant of any bit field in previous bytes. */
4757 if (local
->byte_buffer_in_use
)
4759 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4760 local
->total_bytes
++;
4761 local
->byte_buffer_in_use
= false;
4764 /* If still not at proper byte, advance to there. */
4765 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4767 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
4768 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
4769 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
4773 /* Set up the buffer if necessary. */
4774 if (!local
->byte_buffer_in_use
)
4778 local
->byte_buffer_in_use
= true;
4781 /* If this is nested constructor, recurse passing the bit offset and the
4782 pending data, then retrieve the new pending data afterwards. */
4783 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
4785 oc_outer_state output_state
;
4787 output_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
4788 output_state
.byte
= local
->byte
;
4790 += output_constructor (local
->val
, 0, 0, &output_state
);
4791 local
->byte
= output_state
.byte
;
4795 /* Otherwise, we must split the element into pieces that fall within
4796 separate bytes, and combine each byte with previous or following
4798 while (next_offset
< end_offset
)
4802 HOST_WIDE_INT value
;
4803 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4804 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4806 /* Advance from byte to byte
4807 within this element when necessary. */
4808 while (next_byte
!= local
->total_bytes
)
4810 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4811 local
->total_bytes
++;
4815 /* Number of bits we can process at once
4816 (all part of the same byte). */
4817 this_time
= MIN (end_offset
- next_offset
,
4818 BITS_PER_UNIT
- next_bit
);
4819 if (BYTES_BIG_ENDIAN
)
4821 /* On big-endian machine, take the most significant bits
4822 first (of the bits that are significant)
4823 and put them into bytes from the most significant end. */
4824 shift
= end_offset
- next_offset
- this_time
;
4826 /* Don't try to take a bunch of bits that cross
4827 the word boundary in the INTEGER_CST. We can
4828 only select bits from the LOW or HIGH part
4830 if (shift
< HOST_BITS_PER_WIDE_INT
4831 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4833 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4834 shift
= HOST_BITS_PER_WIDE_INT
;
4837 /* Now get the bits from the appropriate constant word. */
4838 if (shift
< HOST_BITS_PER_WIDE_INT
)
4839 value
= TREE_INT_CST_LOW (local
->val
);
4842 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4843 value
= TREE_INT_CST_HIGH (local
->val
);
4844 shift
-= HOST_BITS_PER_WIDE_INT
;
4847 /* Get the result. This works only when:
4848 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4849 local
->byte
|= (((value
>> shift
)
4850 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4851 << (BITS_PER_UNIT
- this_time
- next_bit
));
4855 /* On little-endian machines,
4856 take first the least significant bits of the value
4857 and pack them starting at the least significant
4858 bits of the bytes. */
4859 shift
= next_offset
- byte_relative_ebitpos
;
4861 /* Don't try to take a bunch of bits that cross
4862 the word boundary in the INTEGER_CST. We can
4863 only select bits from the LOW or HIGH part
4865 if (shift
< HOST_BITS_PER_WIDE_INT
4866 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4867 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4869 /* Now get the bits from the appropriate constant word. */
4870 if (shift
< HOST_BITS_PER_WIDE_INT
)
4871 value
= TREE_INT_CST_LOW (local
->val
);
4874 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4875 value
= TREE_INT_CST_HIGH (local
->val
);
4876 shift
-= HOST_BITS_PER_WIDE_INT
;
4879 /* Get the result. This works only when:
4880 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4881 local
->byte
|= (((value
>> shift
)
4882 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4886 next_offset
+= this_time
;
4887 local
->byte_buffer_in_use
= true;
4891 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4892 Generate at least SIZE bytes, padding if necessary. OUTER designates the
4893 caller output state of relevance in recursive invocations. */
4895 static unsigned HOST_WIDE_INT
4896 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
4897 unsigned int align
, oc_outer_state
* outer
)
4899 unsigned HOST_WIDE_INT cnt
;
4900 constructor_elt
*ce
;
4902 oc_local_state local
;
4904 /* Setup our local state to communicate with helpers. */
4907 local
.align
= align
;
4909 local
.total_bytes
= 0;
4910 local
.byte_buffer_in_use
= outer
!= NULL
;
4911 local
.byte
= outer
? outer
->byte
: 0;
4913 local
.type
= TREE_TYPE (exp
);
4915 local
.last_relative_index
= -1;
4917 local
.min_index
= NULL_TREE
;
4918 if (TREE_CODE (local
.type
) == ARRAY_TYPE
4919 && TYPE_DOMAIN (local
.type
) != NULL_TREE
)
4920 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
4922 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
4924 /* As CE goes through the elements of the constant, FIELD goes through the
4925 structure fields if the constant is a structure. If the constant is a
4926 union, we override this by getting the field from the TREE_LIST element.
4927 But the constant could also be an array. Then FIELD is zero.
4929 There is always a maximum of one element in the chain LINK for unions
4930 (even if the initializer in a source program incorrectly contains
4933 local
.field
= NULL_TREE
;
4934 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
4935 local
.field
= TYPE_FIELDS (local
.type
);
4938 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
4939 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
4941 local
.val
= ce
->value
;
4942 local
.index
= NULL_TREE
;
4944 /* The element in a union constructor specifies the proper field
4946 if ((TREE_CODE (local
.type
) == RECORD_TYPE
4947 || TREE_CODE (local
.type
) == UNION_TYPE
4948 || TREE_CODE (local
.type
) == QUAL_UNION_TYPE
)
4949 && ce
->index
!= NULL_TREE
)
4950 local
.field
= ce
->index
;
4952 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
4953 local
.index
= ce
->index
;
4955 #ifdef ASM_COMMENT_START
4956 if (local
.field
&& flag_verbose_asm
)
4957 fprintf (asm_out_file
, "%s %s:\n",
4959 DECL_NAME (local
.field
)
4960 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
4964 /* Eliminate the marker that makes a cast not be an lvalue. */
4965 if (local
.val
!= NULL_TREE
)
4966 STRIP_NOPS (local
.val
);
4968 /* Output the current element, using the appropriate helper ... */
4970 /* For an array slice not part of an outer bitfield. */
4972 && local
.index
!= NULL_TREE
4973 && TREE_CODE (local
.index
) == RANGE_EXPR
)
4974 output_constructor_array_range (&local
);
4976 /* For a field that is neither a true bitfield nor part of an outer one,
4977 known to be at least byte aligned and multiple-of-bytes long. */
4979 && (local
.field
== NULL_TREE
4980 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
4981 output_constructor_regular_field (&local
);
4983 /* For a true bitfield or part of an outer one. */
4985 output_constructor_bitfield (&local
, outer
);
4988 /* If we are not at toplevel, save the pending data for our caller.
4989 Otherwise output the pending data and padding zeros as needed. */
4991 outer
->byte
= local
.byte
;
4994 if (local
.byte_buffer_in_use
)
4996 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
4997 local
.total_bytes
++;
5000 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5002 assemble_zeros (local
.size
- local
.total_bytes
);
5003 local
.total_bytes
= local
.size
;
5007 return local
.total_bytes
;
5010 /* Mark DECL as weak. */
5013 mark_weak (tree decl
)
5015 DECL_WEAK (decl
) = 1;
5017 if (DECL_RTL_SET_P (decl
)
5018 && MEM_P (DECL_RTL (decl
))
5019 && XEXP (DECL_RTL (decl
), 0)
5020 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5021 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5024 /* Merge weak status between NEWDECL and OLDDECL. */
5027 merge_weak (tree newdecl
, tree olddecl
)
5029 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5031 if (DECL_WEAK (newdecl
) && TARGET_SUPPORTS_WEAK
)
5034 /* We put the NEWDECL on the weak_decls list at some point
5035 and OLDDECL as well. Keep just OLDDECL on the list. */
5036 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5037 if (TREE_VALUE (*pwd
) == newdecl
)
5039 *pwd
= TREE_CHAIN (*pwd
);
5046 if (DECL_WEAK (newdecl
))
5050 /* NEWDECL is weak, but OLDDECL is not. */
5052 /* If we already output the OLDDECL, we're in trouble; we can't
5053 go back and make it weak. This error cannot be caught in
5054 declare_weak because the NEWDECL and OLDDECL was not yet
5055 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5056 if (TREE_ASM_WRITTEN (olddecl
))
5057 error ("weak declaration of %q+D must precede definition",
5060 /* If we've already generated rtl referencing OLDDECL, we may
5061 have done so in a way that will not function properly with
5063 else if (TREE_USED (olddecl
)
5064 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
5065 warning (0, "weak declaration of %q+D after first use results "
5066 "in unspecified behavior", newdecl
);
5068 if (TARGET_SUPPORTS_WEAK
)
5070 /* We put the NEWDECL on the weak_decls list at some point.
5071 Replace it with the OLDDECL. */
5072 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5073 if (TREE_VALUE (wd
) == newdecl
)
5075 TREE_VALUE (wd
) = olddecl
;
5078 /* We may not find the entry on the list. If NEWDECL is a
5079 weak alias, then we will have already called
5080 globalize_decl to remove the entry; in that case, we do
5081 not need to do anything. */
5084 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5085 mark_weak (olddecl
);
5088 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5089 weak. Just update NEWDECL to indicate that it's weak too. */
5090 mark_weak (newdecl
);
5093 /* Declare DECL to be a weak symbol. */
5096 declare_weak (tree decl
)
5098 if (! TREE_PUBLIC (decl
))
5099 error ("weak declaration of %q+D must be public", decl
);
5100 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
5101 error ("weak declaration of %q+D must precede definition", decl
);
5102 else if (!TARGET_SUPPORTS_WEAK
)
5103 warning (0, "weak declaration of %q+D not supported", decl
);
5106 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5107 DECL_ATTRIBUTES (decl
)
5108 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5112 weak_finish_1 (tree decl
)
5114 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5115 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5118 if (! TREE_USED (decl
))
5121 #ifdef ASM_WEAKEN_DECL
5122 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5124 #ifdef ASM_WEAKEN_LABEL
5125 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5127 #ifdef ASM_OUTPUT_WEAK_ALIAS
5129 static bool warn_once
= 0;
5132 warning (0, "only weak aliases are supported in this configuration");
5142 /* This TREE_LIST contains weakref targets. */
5144 static GTY(()) tree weakref_targets
;
5146 /* Forward declaration. */
5147 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
5149 /* Emit any pending weak declarations. */
5156 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5158 tree alias_decl
= TREE_PURPOSE (t
);
5159 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5161 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5162 /* Remove alias_decl from the weak list, but leave entries for
5163 the target alone. */
5165 #ifndef ASM_OUTPUT_WEAKREF
5166 else if (! TREE_SYMBOL_REFERENCED (target
))
5168 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5169 defined, otherwise we and weak_finish_1 would use
5170 different macros. */
5171 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5172 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5174 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
5178 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5179 TREE_CODE (alias_decl
), target
,
5180 TREE_TYPE (alias_decl
));
5182 DECL_EXTERNAL (decl
) = 1;
5183 TREE_PUBLIC (decl
) = 1;
5184 DECL_ARTIFICIAL (decl
) = 1;
5185 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5186 TREE_USED (decl
) = 1;
5189 weak_finish_1 (decl
);
5198 /* Remove the alias and the target from the pending weak list
5199 so that we do not emit any .weak directives for the former,
5200 nor multiple .weak directives for the latter. */
5201 for (p
= &weak_decls
; (t2
= *p
) ; )
5203 if (TREE_VALUE (t2
) == alias_decl
5204 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5205 *p
= TREE_CHAIN (t2
);
5207 p
= &TREE_CHAIN (t2
);
5210 /* Remove other weakrefs to the same target, to speed things up. */
5211 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5213 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5214 *p
= TREE_CHAIN (t2
);
5216 p
= &TREE_CHAIN (t2
);
5221 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5223 tree decl
= TREE_VALUE (t
);
5225 weak_finish_1 (decl
);
5229 /* Emit the assembly bits to indicate that DECL is globally visible. */
5232 globalize_decl (tree decl
)
5235 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5236 if (DECL_WEAK (decl
))
5238 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5241 #ifdef ASM_WEAKEN_DECL
5242 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5244 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5247 /* Remove this function from the pending weak list so that
5248 we do not emit multiple .weak directives for it. */
5249 for (p
= &weak_decls
; (t
= *p
) ; )
5251 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5252 *p
= TREE_CHAIN (t
);
5254 p
= &TREE_CHAIN (t
);
5257 /* Remove weakrefs to the same target from the pending weakref
5258 list, for the same reason. */
5259 for (p
= &weakref_targets
; (t
= *p
) ; )
5261 if (DECL_ASSEMBLER_NAME (decl
)
5262 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5263 *p
= TREE_CHAIN (t
);
5265 p
= &TREE_CHAIN (t
);
5272 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5275 VEC(alias_pair
,gc
) *alias_pairs
;
5277 /* Given an assembly name, find the decl it is associated with. At the
5278 same time, mark it needed for cgraph. */
5281 find_decl_and_mark_needed (tree decl
, tree target
)
5283 struct cgraph_node
*fnode
= NULL
;
5284 struct varpool_node
*vnode
= NULL
;
5286 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5288 fnode
= cgraph_node_for_asm (target
);
5290 vnode
= varpool_node_for_asm (target
);
5294 vnode
= varpool_node_for_asm (target
);
5296 fnode
= cgraph_node_for_asm (target
);
5301 cgraph_mark_needed_node (fnode
);
5306 varpool_mark_needed_node (vnode
);
5307 vnode
->force_output
= 1;
5314 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5315 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5316 tree node is DECL to have the value of the tree node TARGET. */
5319 do_assemble_alias (tree decl
, tree target
)
5321 /* Emulated TLS had better not get this var. */
5322 gcc_assert(!(!targetm
.have_tls
5323 && TREE_CODE (decl
) == VAR_DECL
5324 && DECL_THREAD_LOCAL_P (decl
)));
5326 if (TREE_ASM_WRITTEN (decl
))
5329 /* We must force creation of DECL_RTL for debug info generation, even though
5330 we don't use it here. */
5331 make_decl_rtl (decl
);
5333 TREE_ASM_WRITTEN (decl
) = 1;
5334 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5336 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5338 ultimate_transparent_alias_target (&target
);
5340 if (!TREE_SYMBOL_REFERENCED (target
))
5341 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5343 #ifdef ASM_OUTPUT_WEAKREF
5344 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5345 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5346 IDENTIFIER_POINTER (target
));
5348 if (!TARGET_SUPPORTS_WEAK
)
5350 error_at (DECL_SOURCE_LOCATION (decl
),
5351 "weakref is not supported in this configuration");
5358 #ifdef ASM_OUTPUT_DEF
5359 /* Make name accessible from other files, if appropriate. */
5361 if (TREE_PUBLIC (decl
))
5363 globalize_decl (decl
);
5364 maybe_assemble_visibility (decl
);
5366 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5368 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
5369 ASM_OUTPUT_TYPE_DIRECTIVE
5370 (asm_out_file
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5373 error_at (DECL_SOURCE_LOCATION (decl
),
5374 "ifunc is not supported in this configuration");
5378 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5379 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5381 ASM_OUTPUT_DEF (asm_out_file
,
5382 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5383 IDENTIFIER_POINTER (target
));
5385 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5390 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5391 # ifdef ASM_WEAKEN_DECL
5392 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5394 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5396 /* Remove this function from the pending weak list so that
5397 we do not emit multiple .weak directives for it. */
5398 for (p
= &weak_decls
; (t
= *p
) ; )
5399 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5400 *p
= TREE_CHAIN (t
);
5402 p
= &TREE_CHAIN (t
);
5404 /* Remove weakrefs to the same target from the pending weakref
5405 list, for the same reason. */
5406 for (p
= &weakref_targets
; (t
= *p
) ; )
5408 if (DECL_ASSEMBLER_NAME (decl
)
5409 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5410 *p
= TREE_CHAIN (t
);
5412 p
= &TREE_CHAIN (t
);
5419 /* Compute the set of indentifier nodes that is generated by aliases
5420 whose targets are reachable. */
5422 static struct pointer_set_t
*
5423 compute_visible_aliases (void)
5425 struct pointer_set_t
*visible
;
5430 /* We have to compute the set of visible nodes including aliases
5432 visible
= pointer_set_create ();
5436 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); ++i
)
5438 struct cgraph_node
*fnode
= NULL
;
5439 struct varpool_node
*vnode
= NULL
;
5440 fnode
= cgraph_node_for_asm (p
->target
);
5441 vnode
= (fnode
== NULL
) ? varpool_node_for_asm (p
->target
) : NULL
;
5444 || pointer_set_contains (visible
, p
->target
))
5445 && !pointer_set_insert (visible
, DECL_ASSEMBLER_NAME (p
->decl
)))
5454 /* Remove the alias pairing for functions that are no longer in the call
5458 remove_unreachable_alias_pairs (void)
5460 struct pointer_set_t
*visible
;
5464 if (alias_pairs
== NULL
)
5467 /* We have to compute the set of visible nodes including aliases
5469 visible
= compute_visible_aliases ();
5471 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); )
5473 if (!DECL_EXTERNAL (p
->decl
))
5475 struct cgraph_node
*fnode
= NULL
;
5476 struct varpool_node
*vnode
= NULL
;
5477 fnode
= cgraph_node_for_asm (p
->target
);
5478 vnode
= (fnode
== NULL
) ? varpool_node_for_asm (p
->target
) : NULL
;
5481 && !pointer_set_contains (visible
, p
->target
))
5483 VEC_unordered_remove (alias_pair
, alias_pairs
, i
);
5491 pointer_set_destroy (visible
);
5495 /* First pass of completing pending aliases. Make sure that cgraph knows
5496 which symbols will be required. */
5499 finish_aliases_1 (void)
5501 struct pointer_set_t
*visible
;
5505 if (alias_pairs
== NULL
)
5508 /* We have to compute the set of visible nodes including aliases
5510 visible
= compute_visible_aliases ();
5512 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5516 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
5517 if (target_decl
== NULL
)
5519 if (pointer_set_contains (visible
, p
->target
))
5522 if (! (p
->emitted_diags
& ALIAS_DIAG_TO_UNDEF
)
5523 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5525 error ("%q+D aliased to undefined symbol %qE",
5526 p
->decl
, p
->target
);
5527 p
->emitted_diags
|= ALIAS_DIAG_TO_UNDEF
;
5530 else if (! (p
->emitted_diags
& ALIAS_DIAG_TO_EXTERN
)
5531 && DECL_EXTERNAL (target_decl
)
5532 /* We use local aliases for C++ thunks to force the tailcall
5533 to bind locally. This is a hack - to keep it working do
5534 the following (which is not strictly correct). */
5535 && (! TREE_CODE (target_decl
) == FUNCTION_DECL
5536 || ! DECL_VIRTUAL_P (target_decl
))
5537 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5539 error ("%q+D aliased to external symbol %qE",
5540 p
->decl
, p
->target
);
5541 p
->emitted_diags
|= ALIAS_DIAG_TO_EXTERN
;
5545 pointer_set_destroy (visible
);
5548 /* Second pass of completing pending aliases. Emit the actual assembly.
5549 This happens at the end of compilation and thus it is assured that the
5550 target symbol has been emitted. */
5553 finish_aliases_2 (void)
5558 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5559 do_assemble_alias (p
->decl
, p
->target
);
5561 VEC_truncate (alias_pair
, alias_pairs
, 0);
5564 /* Emit an assembler directive to make the symbol for DECL an alias to
5565 the symbol for TARGET. */
5568 assemble_alias (tree decl
, tree target
)
5571 bool is_weakref
= false;
5573 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5575 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5579 ultimate_transparent_alias_target (&target
);
5581 if (alias
== target
)
5582 error ("weakref %q+D ultimately targets itself", decl
);
5585 #ifndef ASM_OUTPUT_WEAKREF
5586 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
5587 TREE_CHAIN (alias
) = target
;
5590 if (TREE_PUBLIC (decl
))
5591 error ("weakref %q+D must have static linkage", decl
);
5595 #if !defined (ASM_OUTPUT_DEF)
5596 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5597 error_at (DECL_SOURCE_LOCATION (decl
),
5598 "alias definitions not supported in this configuration");
5601 if (!DECL_WEAK (decl
))
5603 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5604 error_at (DECL_SOURCE_LOCATION (decl
),
5605 "ifunc is not supported in this configuration");
5607 error_at (DECL_SOURCE_LOCATION (decl
),
5608 "only weak aliases are supported in this configuration");
5614 TREE_USED (decl
) = 1;
5616 /* A quirk of the initial implementation of aliases required that the user
5617 add "extern" to all of them. Which is silly, but now historical. Do
5618 note that the symbol is in fact locally defined. */
5620 DECL_EXTERNAL (decl
) = 0;
5622 /* Allow aliases to aliases. */
5623 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5624 cgraph_node (decl
)->alias
= true;
5626 varpool_node (decl
)->alias
= true;
5628 /* If the target has already been emitted, we don't have to queue the
5629 alias. This saves a tad of memory. */
5630 if (cgraph_global_info_ready
)
5631 target_decl
= find_decl_and_mark_needed (decl
, target
);
5634 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5635 do_assemble_alias (decl
, target
);
5638 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
5641 p
->emitted_diags
= ALIAS_DIAG_NONE
;
5645 /* Emit an assembler directive to set symbol for DECL visibility to
5646 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5649 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5650 int vis ATTRIBUTE_UNUSED
)
5652 #ifdef HAVE_GAS_HIDDEN
5653 static const char * const visibility_types
[] = {
5654 NULL
, "protected", "hidden", "internal"
5657 const char *name
, *type
;
5659 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5660 type
= visibility_types
[vis
];
5662 fprintf (asm_out_file
, "\t.%s\t", type
);
5663 assemble_name (asm_out_file
, name
);
5664 fprintf (asm_out_file
, "\n");
5666 warning (OPT_Wattributes
, "visibility attribute not supported "
5667 "in this configuration; ignored");
5671 /* A helper function to call assemble_visibility when needed for a decl. */
5674 maybe_assemble_visibility (tree decl
)
5676 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5678 if (vis
!= VISIBILITY_DEFAULT
)
5680 targetm
.asm_out
.assemble_visibility (decl
, vis
);
5687 /* Returns 1 if the target configuration supports defining public symbols
5688 so that one of them will be chosen at link time instead of generating a
5689 multiply-defined symbol error, whether through the use of weak symbols or
5690 a target-specific mechanism for having duplicates discarded. */
5693 supports_one_only (void)
5695 if (SUPPORTS_ONE_ONLY
)
5697 return TARGET_SUPPORTS_WEAK
;
5700 /* Set up DECL as a public symbol that can be defined in multiple
5701 translation units without generating a linker error. */
5704 make_decl_one_only (tree decl
, tree comdat_group
)
5706 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5707 || TREE_CODE (decl
) == FUNCTION_DECL
);
5709 TREE_PUBLIC (decl
) = 1;
5711 if (SUPPORTS_ONE_ONLY
)
5713 #ifdef MAKE_DECL_ONE_ONLY
5714 MAKE_DECL_ONE_ONLY (decl
);
5716 DECL_COMDAT_GROUP (decl
) = comdat_group
;
5718 else if (TREE_CODE (decl
) == VAR_DECL
5719 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5720 DECL_COMMON (decl
) = 1;
5723 gcc_assert (TARGET_SUPPORTS_WEAK
);
5724 DECL_WEAK (decl
) = 1;
5729 init_varasm_once (void)
5731 section_htab
= htab_create_ggc (31, section_entry_hash
,
5732 section_entry_eq
, NULL
);
5733 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
5734 object_block_entry_eq
, NULL
);
5735 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
5736 const_desc_eq
, NULL
);
5738 const_alias_set
= new_alias_set ();
5739 shared_constant_pool
= create_constant_pool ();
5741 #ifdef TEXT_SECTION_ASM_OP
5742 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
5743 TEXT_SECTION_ASM_OP
);
5746 #ifdef DATA_SECTION_ASM_OP
5747 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5748 DATA_SECTION_ASM_OP
);
5751 #ifdef SDATA_SECTION_ASM_OP
5752 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5753 SDATA_SECTION_ASM_OP
);
5756 #ifdef READONLY_DATA_SECTION_ASM_OP
5757 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
5758 READONLY_DATA_SECTION_ASM_OP
);
5761 #ifdef CTORS_SECTION_ASM_OP
5762 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
5763 CTORS_SECTION_ASM_OP
);
5766 #ifdef DTORS_SECTION_ASM_OP
5767 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
5768 DTORS_SECTION_ASM_OP
);
5771 #ifdef BSS_SECTION_ASM_OP
5772 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5773 output_section_asm_op
,
5774 BSS_SECTION_ASM_OP
);
5777 #ifdef SBSS_SECTION_ASM_OP
5778 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5779 output_section_asm_op
,
5780 SBSS_SECTION_ASM_OP
);
5783 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5784 | SECTION_COMMON
, emit_tls_common
);
5785 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5786 | SECTION_COMMON
, emit_local
);
5787 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5788 | SECTION_COMMON
, emit_common
);
5790 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5791 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
5795 targetm
.asm_out
.init_sections ();
5797 if (readonly_data_section
== NULL
)
5798 readonly_data_section
= text_section
;
5802 decl_default_tls_model (const_tree decl
)
5804 enum tls_model kind
;
5807 is_local
= targetm
.binds_local_p (decl
);
5811 kind
= TLS_MODEL_LOCAL_EXEC
;
5813 kind
= TLS_MODEL_INITIAL_EXEC
;
5816 /* Local dynamic is inefficient when we're not combining the
5817 parts of the address. */
5818 else if (optimize
&& is_local
)
5819 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
5821 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
5822 if (kind
< flag_tls_default
)
5823 kind
= flag_tls_default
;
5828 /* Select a set of attributes for section NAME based on the properties
5829 of DECL and whether or not RELOC indicates that DECL's initializer
5830 might contain runtime relocations.
5832 We make the section read-only and executable for a function decl,
5833 read-only for a const data decl, and writable for a non-const data decl. */
5836 default_section_type_flags (tree decl
, const char *name
, int reloc
)
5840 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
5841 flags
= SECTION_CODE
;
5842 else if (decl
&& decl_readonly_section (decl
, reloc
))
5844 else if (current_function_decl
5846 && crtl
->subsections
.unlikely_text_section_name
5847 && strcmp (name
, crtl
->subsections
.unlikely_text_section_name
) == 0)
5848 flags
= SECTION_CODE
;
5850 && (!current_function_decl
|| !cfun
)
5851 && strcmp (name
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
5852 flags
= SECTION_CODE
;
5854 flags
= SECTION_WRITE
;
5856 if (decl
&& DECL_ONE_ONLY (decl
))
5857 flags
|= SECTION_LINKONCE
;
5859 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
5860 flags
|= SECTION_TLS
| SECTION_WRITE
;
5862 if (strcmp (name
, ".bss") == 0
5863 || strncmp (name
, ".bss.", 5) == 0
5864 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
5865 || strcmp (name
, ".sbss") == 0
5866 || strncmp (name
, ".sbss.", 6) == 0
5867 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
5868 flags
|= SECTION_BSS
;
5870 if (strcmp (name
, ".tdata") == 0
5871 || strncmp (name
, ".tdata.", 7) == 0
5872 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
5873 flags
|= SECTION_TLS
;
5875 if (strcmp (name
, ".tbss") == 0
5876 || strncmp (name
, ".tbss.", 6) == 0
5877 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
5878 flags
|= SECTION_TLS
| SECTION_BSS
;
5880 /* These three sections have special ELF types. They are neither
5881 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
5882 want to print a section type (@progbits or @nobits). If someone
5883 is silly enough to emit code or TLS variables to one of these
5884 sections, then don't handle them specially. */
5885 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
5886 && (strcmp (name
, ".init_array") == 0
5887 || strcmp (name
, ".fini_array") == 0
5888 || strcmp (name
, ".preinit_array") == 0))
5889 flags
|= SECTION_NOTYPE
;
5894 /* Return true if the target supports some form of global BSS,
5895 either through bss_noswitch_section, or by selecting a BSS
5896 section in TARGET_ASM_SELECT_SECTION. */
5899 have_global_bss_p (void)
5901 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
5904 /* Output assembly to switch to section NAME with attribute FLAGS.
5905 Four variants for common object file formats. */
5908 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
5909 unsigned int flags ATTRIBUTE_UNUSED
,
5910 tree decl ATTRIBUTE_UNUSED
)
5912 /* Some object formats don't support named sections at all. The
5913 front-end should already have flagged this as an error. */
5917 #ifndef TLS_SECTION_ASM_FLAG
5918 #define TLS_SECTION_ASM_FLAG 'T'
5922 default_elf_asm_named_section (const char *name
, unsigned int flags
,
5923 tree decl ATTRIBUTE_UNUSED
)
5925 char flagchars
[10], *f
= flagchars
;
5927 /* If we have already declared this section, we can use an
5928 abbreviated form to switch back to it -- unless this section is
5929 part of a COMDAT groups, in which case GAS requires the full
5930 declaration every time. */
5931 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5932 && (flags
& SECTION_DECLARED
))
5934 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
5938 if (!(flags
& SECTION_DEBUG
))
5940 if (flags
& SECTION_WRITE
)
5942 if (flags
& SECTION_CODE
)
5944 if (flags
& SECTION_SMALL
)
5946 if (flags
& SECTION_MERGE
)
5948 if (flags
& SECTION_STRINGS
)
5950 if (flags
& SECTION_TLS
)
5951 *f
++ = TLS_SECTION_ASM_FLAG
;
5952 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5956 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
5958 if (!(flags
& SECTION_NOTYPE
))
5963 if (flags
& SECTION_BSS
)
5969 #ifdef ASM_COMMENT_START
5970 /* On platforms that use "@" as the assembly comment character,
5972 if (strcmp (ASM_COMMENT_START
, "@") == 0)
5975 fprintf (asm_out_file
, format
, type
);
5977 if (flags
& SECTION_ENTSIZE
)
5978 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
5979 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5981 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
5982 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
5984 fprintf (asm_out_file
, ",%s,comdat",
5985 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
5989 putc ('\n', asm_out_file
);
5993 default_coff_asm_named_section (const char *name
, unsigned int flags
,
5994 tree decl ATTRIBUTE_UNUSED
)
5996 char flagchars
[8], *f
= flagchars
;
5998 if (flags
& SECTION_WRITE
)
6000 if (flags
& SECTION_CODE
)
6004 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6008 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6011 default_coff_asm_named_section (name
, flags
, decl
);
6013 if (flags
& SECTION_LINKONCE
)
6015 /* Functions may have been compiled at various levels of
6016 optimization so we can't use `same_size' here.
6017 Instead, have the linker pick one. */
6018 fprintf (asm_out_file
, "\t.linkonce %s\n",
6019 (flags
& SECTION_CODE
? "discard" : "same_size"));
6023 /* The lame default section selector. */
6026 default_select_section (tree decl
, int reloc
,
6027 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6031 if (decl_readonly_section (decl
, reloc
))
6032 return readonly_data_section
;
6034 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6036 if (! ((flag_pic
&& reloc
)
6037 || !TREE_READONLY (decl
)
6038 || TREE_SIDE_EFFECTS (decl
)
6039 || !TREE_CONSTANT (decl
)))
6040 return readonly_data_section
;
6042 else if (TREE_CODE (decl
) == STRING_CST
)
6043 return readonly_data_section
;
6044 else if (! (flag_pic
&& reloc
))
6045 return readonly_data_section
;
6047 return data_section
;
6050 enum section_category
6051 categorize_decl_for_section (const_tree decl
, int reloc
)
6053 enum section_category ret
;
6055 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6057 else if (TREE_CODE (decl
) == STRING_CST
)
6059 if (flag_mudflap
) /* or !flag_merge_constants */
6060 return SECCAT_RODATA
;
6062 return SECCAT_RODATA_MERGE_STR
;
6064 else if (TREE_CODE (decl
) == VAR_DECL
)
6066 if (bss_initializer_p (decl
))
6068 else if (! TREE_READONLY (decl
)
6069 || TREE_SIDE_EFFECTS (decl
)
6070 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6072 /* Here the reloc_rw_mask is not testing whether the section should
6073 be read-only or not, but whether the dynamic link will have to
6074 do something. If so, we wish to segregate the data in order to
6075 minimize cache misses inside the dynamic linker. */
6076 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6077 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6081 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6082 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6083 else if (reloc
|| flag_merge_constants
< 2)
6084 /* C and C++ don't allow different variables to share the same
6085 location. -fmerge-all-constants allows even that (at the
6086 expense of not conforming). */
6087 ret
= SECCAT_RODATA
;
6088 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6089 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6091 ret
= SECCAT_RODATA_MERGE_CONST
;
6093 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6095 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6096 || TREE_SIDE_EFFECTS (decl
)
6097 || ! TREE_CONSTANT (decl
))
6100 ret
= SECCAT_RODATA
;
6103 ret
= SECCAT_RODATA
;
6105 /* There are no read-only thread-local sections. */
6106 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6108 /* Note that this would be *just* SECCAT_BSS, except that there's
6109 no concept of a read-only thread-local-data section. */
6110 if (ret
== SECCAT_BSS
6111 || (flag_zero_initialized_in_bss
6112 && initializer_zerop (DECL_INITIAL (decl
))))
6118 /* If the target uses small data sections, select it. */
6119 else if (targetm
.in_small_data_p (decl
))
6121 if (ret
== SECCAT_BSS
)
6123 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6124 ret
= SECCAT_SRODATA
;
6133 decl_readonly_section (const_tree decl
, int reloc
)
6135 switch (categorize_decl_for_section (decl
, reloc
))
6138 case SECCAT_RODATA_MERGE_STR
:
6139 case SECCAT_RODATA_MERGE_STR_INIT
:
6140 case SECCAT_RODATA_MERGE_CONST
:
6141 case SECCAT_SRODATA
:
6150 /* Select a section based on the above categorization. */
6153 default_elf_select_section (tree decl
, int reloc
,
6154 unsigned HOST_WIDE_INT align
)
6157 switch (categorize_decl_for_section (decl
, reloc
))
6160 /* We're not supposed to be called on FUNCTION_DECLs. */
6163 return readonly_data_section
;
6164 case SECCAT_RODATA_MERGE_STR
:
6165 return mergeable_string_section (decl
, align
, 0);
6166 case SECCAT_RODATA_MERGE_STR_INIT
:
6167 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6168 case SECCAT_RODATA_MERGE_CONST
:
6169 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6170 case SECCAT_SRODATA
:
6174 return data_section
;
6175 case SECCAT_DATA_REL
:
6176 sname
= ".data.rel";
6178 case SECCAT_DATA_REL_LOCAL
:
6179 sname
= ".data.rel.local";
6181 case SECCAT_DATA_REL_RO
:
6182 sname
= ".data.rel.ro";
6184 case SECCAT_DATA_REL_RO_LOCAL
:
6185 sname
= ".data.rel.ro.local";
6210 return get_named_section (decl
, sname
, reloc
);
6213 /* Construct a unique section name based on the decl name and the
6214 categorization performed above. */
6217 default_unique_section (tree decl
, int reloc
)
6219 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6220 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6221 const char *prefix
, *name
, *linkonce
;
6224 switch (categorize_decl_for_section (decl
, reloc
))
6227 prefix
= one_only
? ".t" : ".text";
6230 case SECCAT_RODATA_MERGE_STR
:
6231 case SECCAT_RODATA_MERGE_STR_INIT
:
6232 case SECCAT_RODATA_MERGE_CONST
:
6233 prefix
= one_only
? ".r" : ".rodata";
6235 case SECCAT_SRODATA
:
6236 prefix
= one_only
? ".s2" : ".sdata2";
6239 prefix
= one_only
? ".d" : ".data";
6241 case SECCAT_DATA_REL
:
6242 prefix
= one_only
? ".d.rel" : ".data.rel";
6244 case SECCAT_DATA_REL_LOCAL
:
6245 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6247 case SECCAT_DATA_REL_RO
:
6248 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6250 case SECCAT_DATA_REL_RO_LOCAL
:
6251 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6254 prefix
= one_only
? ".s" : ".sdata";
6257 prefix
= one_only
? ".b" : ".bss";
6260 prefix
= one_only
? ".sb" : ".sbss";
6263 prefix
= one_only
? ".td" : ".tdata";
6266 prefix
= one_only
? ".tb" : ".tbss";
6272 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6273 name
= targetm
.strip_name_encoding (name
);
6275 /* If we're using one_only, then there needs to be a .gnu.linkonce
6276 prefix to the section name. */
6277 linkonce
= one_only
? ".gnu.linkonce" : "";
6279 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6281 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6284 /* Like compute_reloc_for_constant, except for an RTX. The return value
6285 is a mask for which bit 1 indicates a global relocation, and bit 0
6286 indicates a local relocation. */
6289 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6291 int *preloc
= (int *) data
;
6294 switch (GET_CODE (x
))
6297 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6310 compute_reloc_for_rtx (rtx x
)
6314 switch (GET_CODE (x
))
6320 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6329 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6331 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6333 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6334 return data_section
;
6336 return readonly_data_section
;
6340 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6341 unsigned HOST_WIDE_INT align
)
6343 int reloc
= compute_reloc_for_rtx (x
);
6345 /* ??? Handle small data here somehow. */
6347 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6350 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6352 return get_named_section (NULL
, ".data.rel.ro", 3);
6355 return mergeable_constant_section (mode
, align
, 0);
6358 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6361 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6366 /* Careful not to prod global register variables. */
6369 symbol
= XEXP (rtl
, 0);
6370 if (GET_CODE (symbol
) != SYMBOL_REF
)
6373 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6374 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6375 flags
|= SYMBOL_FLAG_FUNCTION
;
6376 if (targetm
.binds_local_p (decl
))
6377 flags
|= SYMBOL_FLAG_LOCAL
;
6378 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6379 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6380 else if (targetm
.in_small_data_p (decl
))
6381 flags
|= SYMBOL_FLAG_SMALL
;
6382 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6383 being PUBLIC, the thing *must* be defined in this translation unit.
6384 Prevent this buglet from being propagated into rtl code as well. */
6385 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6386 flags
|= SYMBOL_FLAG_EXTERNAL
;
6388 SYMBOL_REF_FLAGS (symbol
) = flags
;
6391 /* By default, we do nothing for encode_section_info, so we need not
6392 do anything but discard the '*' marker. */
6395 default_strip_name_encoding (const char *str
)
6397 return str
+ (*str
== '*');
6400 #ifdef ASM_OUTPUT_DEF
6401 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6402 anchor relative to ".", the current section position. */
6405 default_asm_output_anchor (rtx symbol
)
6409 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6410 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6411 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6415 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6418 default_use_anchors_for_symbol_p (const_rtx symbol
)
6423 /* Don't use anchors for mergeable sections. The linker might move
6424 the objects around. */
6425 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6426 if (sect
->common
.flags
& SECTION_MERGE
)
6429 /* Don't use anchors for small data sections. The small data register
6430 acts as an anchor for such sections. */
6431 if (sect
->common
.flags
& SECTION_SMALL
)
6434 decl
= SYMBOL_REF_DECL (symbol
);
6435 if (decl
&& DECL_P (decl
))
6437 /* Don't use section anchors for decls that might be defined by
6439 if (!targetm
.binds_local_p (decl
))
6442 /* Don't use section anchors for decls that will be placed in a
6443 small data section. */
6444 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6445 one above. The problem is that we only use SECTION_SMALL for
6446 sections that should be marked as small in the section directive. */
6447 if (targetm
.in_small_data_p (decl
))
6453 /* Return true when RESOLUTION indicate that symbol will be bound to the
6454 definition provided by current .o file. */
6457 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
6459 return (resolution
== LDPR_PREVAILING_DEF
6460 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
6463 /* Return true when RESOLUTION indicate that symbol will be bound locally
6464 within current executable or DSO. */
6467 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
6469 return (resolution
== LDPR_PREVAILING_DEF
6470 || resolution
== LDPR_PREVAILING_DEF_IRONLY
6471 || resolution
== LDPR_PREEMPTED_REG
6472 || resolution
== LDPR_PREEMPTED_IR
6473 || resolution
== LDPR_RESOLVED_IR
6474 || resolution
== LDPR_RESOLVED_EXEC
);
6477 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6478 wrt cross-module name binding. */
6481 default_binds_local_p (const_tree exp
)
6483 return default_binds_local_p_1 (exp
, flag_shlib
);
6487 default_binds_local_p_1 (const_tree exp
, int shlib
)
6490 bool resolved_locally
= false;
6491 bool resolved_to_local_def
= false;
6493 /* With resolution file in hands, take look into resolutions.
6494 We can't just return true for resolved_localy symbols,
6495 because dynamic linking might overwrite symbols
6496 in shared libraries. */
6497 if (TREE_CODE (exp
) == VAR_DECL
&& TREE_PUBLIC (exp
)
6498 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
6500 struct varpool_node
*vnode
= varpool_get_node (exp
);
6501 if (vnode
&& resolution_local_p (vnode
->resolution
))
6502 resolved_locally
= true;
6504 && resolution_to_local_definition_p (vnode
->resolution
))
6505 resolved_to_local_def
= true;
6507 else if (TREE_CODE (exp
) == FUNCTION_DECL
&& TREE_PUBLIC (exp
))
6509 struct cgraph_node
*node
= cgraph_get_node_or_alias (exp
);
6511 && resolution_local_p (node
->resolution
))
6512 resolved_locally
= true;
6514 && resolution_to_local_definition_p (node
->resolution
))
6515 resolved_to_local_def
= true;
6518 /* A non-decl is an entry in the constant pool. */
6521 /* Weakrefs may not bind locally, even though the weakref itself is
6522 always static and therefore local.
6523 FIXME: We can resolve this more curefuly by looking at the weakref
6525 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
6527 /* Static variables are always local. */
6528 else if (! TREE_PUBLIC (exp
))
6530 /* A variable is local if the user has said explicitly that it will
6532 else if ((DECL_VISIBILITY_SPECIFIED (exp
)
6533 || resolved_to_local_def
)
6534 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6536 /* Variables defined outside this object might not be local. */
6537 else if (DECL_EXTERNAL (exp
) && !resolved_locally
)
6539 /* If defined in this object and visibility is not default, must be
6541 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6543 /* Default visibility weak data can be overridden by a strong symbol
6544 in another module and so are not local. */
6545 else if (DECL_WEAK (exp
)
6546 && !resolved_locally
)
6548 /* If PIC, then assume that any global name can be overridden by
6549 symbols resolved from other modules. */
6552 /* Uninitialized COMMON variable may be unified with symbols
6553 resolved from other modules. */
6554 else if (DECL_COMMON (exp
)
6555 && !resolved_locally
6556 && (DECL_INITIAL (exp
) == NULL
6557 || DECL_INITIAL (exp
) == error_mark_node
))
6559 /* Otherwise we're left with initialized (or non-common) global data
6560 which is of necessity defined locally. */
6567 /* Return true when references to DECL must bind to current definition in
6570 The condition is usually equivalent to whether the function binds to the
6571 current module (shared library or executable), that is to binds_local_p.
6572 We use this fact to avoid need for another target hook and implement
6573 the logic using binds_local_p and just special cases where
6574 decl_binds_to_current_def_p is stronger than binds local_p. In particular
6575 the weak definitions (that can be overwritten at linktime by other
6576 definition from different object file) and when resolution info is available
6577 we simply use the knowledge passed to us by linker plugin. */
6579 decl_binds_to_current_def_p (tree decl
)
6581 gcc_assert (DECL_P (decl
));
6582 if (!TREE_PUBLIC (decl
))
6584 if (!targetm
.binds_local_p (decl
))
6586 /* When resolution is available, just use it. */
6587 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_PUBLIC (decl
)
6588 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
6590 struct varpool_node
*vnode
= varpool_get_node (decl
);
6592 && vnode
->resolution
!= LDPR_UNKNOWN
)
6593 return resolution_to_local_definition_p (vnode
->resolution
);
6595 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
))
6597 struct cgraph_node
*node
= cgraph_get_node_or_alias (decl
);
6599 && node
->resolution
!= LDPR_UNKNOWN
)
6600 return resolution_to_local_definition_p (node
->resolution
);
6602 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
6603 binds localy but still can be overwritten).
6604 This rely on fact that binds_local_p behave as decl_replaceable_p
6605 for all other declaration types. */
6606 return !DECL_WEAK (decl
);
6609 /* A replaceable function or variable is one which may be replaced
6610 at link-time with an entirely different definition, provided that the
6611 replacement has the same type. For example, functions declared
6612 with __attribute__((weak)) on most systems are replaceable.
6614 COMDAT functions are not replaceable, since all definitions of the
6615 function must be equivalent. It is important that COMDAT functions
6616 not be treated as replaceable so that use of C++ template
6617 instantiations is not penalized. */
6620 decl_replaceable_p (tree decl
)
6622 gcc_assert (DECL_P (decl
));
6623 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
6625 return !decl_binds_to_current_def_p (decl
);
6628 /* Default function to output code that will globalize a label. A
6629 target must define GLOBAL_ASM_OP or provide its own function to
6630 globalize a label. */
6631 #ifdef GLOBAL_ASM_OP
6633 default_globalize_label (FILE * stream
, const char *name
)
6635 fputs (GLOBAL_ASM_OP
, stream
);
6636 assemble_name (stream
, name
);
6637 putc ('\n', stream
);
6639 #endif /* GLOBAL_ASM_OP */
6641 /* Default function to output code that will globalize a declaration. */
6643 default_globalize_decl_name (FILE * stream
, tree decl
)
6645 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6646 targetm
.asm_out
.globalize_label (stream
, name
);
6649 /* Default function to output a label for unwind information. The
6650 default is to do nothing. A target that needs nonlocal labels for
6651 unwind information must provide its own function to do this. */
6653 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6654 tree decl ATTRIBUTE_UNUSED
,
6655 int for_eh ATTRIBUTE_UNUSED
,
6656 int empty ATTRIBUTE_UNUSED
)
6660 /* Default function to output a label to divide up the exception table.
6661 The default is to do nothing. A target that needs/wants to divide
6662 up the table must provide it's own function to do this. */
6664 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6668 /* This is how to output an internal numbered label where PREFIX is
6669 the class of label and LABELNO is the number within the class. */
6672 default_generate_internal_label (char *buf
, const char *prefix
,
6673 unsigned long labelno
)
6675 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6678 /* This is how to output an internal numbered label where PREFIX is
6679 the class of label and LABELNO is the number within the class. */
6682 default_internal_label (FILE *stream
, const char *prefix
,
6683 unsigned long labelno
)
6685 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6686 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6687 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6691 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6694 default_asm_declare_constant_name (FILE *file
, const char *name
,
6695 const_tree exp ATTRIBUTE_UNUSED
,
6696 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
6698 assemble_label (file
, name
);
6701 /* This is the default behavior at the beginning of a file. It's
6702 controlled by two other target-hook toggles. */
6704 default_file_start (void)
6706 if (targetm
.asm_file_start_app_off
6707 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6708 fputs (ASM_APP_OFF
, asm_out_file
);
6710 if (targetm
.asm_file_start_file_directive
)
6711 output_file_directive (asm_out_file
, main_input_filename
);
6714 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6715 which emits a special section directive used to indicate whether or
6716 not this object file needs an executable stack. This is primarily
6717 a GNU extension to ELF but could be used on other targets. */
6719 int trampolines_created
;
6722 file_end_indicate_exec_stack (void)
6724 unsigned int flags
= SECTION_DEBUG
;
6725 if (trampolines_created
)
6726 flags
|= SECTION_CODE
;
6728 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6731 /* Emit a special section directive to indicate that this object file
6732 was compiled with -fsplit-stack. This is used to let the linker
6733 detect calls between split-stack code and non-split-stack code, so
6734 that it can modify the split-stack code to allocate a sufficiently
6735 large stack. We emit another special section if there are any
6736 functions in this file which have the no_split_stack attribute, to
6737 prevent the linker from warning about being unable to convert the
6738 functions if they call non-split-stack code. */
6741 file_end_indicate_split_stack (void)
6743 if (flag_split_stack
)
6745 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
6747 if (saw_no_split_stack
)
6748 switch_to_section (get_section (".note.GNU-no-split-stack",
6749 SECTION_DEBUG
, NULL
));
6753 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6754 a get_unnamed_section callback. */
6757 output_section_asm_op (const void *directive
)
6759 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
6762 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6763 the current section is NEW_SECTION. */
6766 switch_to_section (section
*new_section
)
6768 if (in_section
== new_section
)
6771 if (new_section
->common
.flags
& SECTION_FORGET
)
6774 in_section
= new_section
;
6776 switch (SECTION_STYLE (new_section
))
6780 && !crtl
->subsections
.unlikely_text_section_name
6781 && strcmp (new_section
->named
.name
,
6782 UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6783 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
6785 targetm
.asm_out
.named_section (new_section
->named
.name
,
6786 new_section
->named
.common
.flags
,
6787 new_section
->named
.decl
);
6790 case SECTION_UNNAMED
:
6791 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
6794 case SECTION_NOSWITCH
:
6799 new_section
->common
.flags
|= SECTION_DECLARED
;
6802 /* If block symbol SYMBOL has not yet been assigned an offset, place
6803 it at the end of its block. */
6806 place_block_symbol (rtx symbol
)
6808 unsigned HOST_WIDE_INT size
, mask
, offset
;
6809 struct constant_descriptor_rtx
*desc
;
6810 unsigned int alignment
;
6811 struct object_block
*block
;
6814 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
6815 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
6818 /* Work out the symbol's size and alignment. */
6819 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6821 desc
= SYMBOL_REF_CONSTANT (symbol
);
6822 alignment
= desc
->align
;
6823 size
= GET_MODE_SIZE (desc
->mode
);
6825 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6827 decl
= SYMBOL_REF_DECL (symbol
);
6828 alignment
= DECL_ALIGN (decl
);
6829 size
= get_constant_size (DECL_INITIAL (decl
));
6833 decl
= SYMBOL_REF_DECL (symbol
);
6834 alignment
= DECL_ALIGN (decl
);
6835 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
6838 /* Calculate the object's offset from the start of the block. */
6839 block
= SYMBOL_REF_BLOCK (symbol
);
6840 mask
= alignment
/ BITS_PER_UNIT
- 1;
6841 offset
= (block
->size
+ mask
) & ~mask
;
6842 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
6844 /* Record the block's new alignment and size. */
6845 block
->alignment
= MAX (block
->alignment
, alignment
);
6846 block
->size
= offset
+ size
;
6848 VEC_safe_push (rtx
, gc
, block
->objects
, symbol
);
6851 /* Return the anchor that should be used to address byte offset OFFSET
6852 from the first object in BLOCK. MODEL is the TLS model used
6856 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
6857 enum tls_model model
)
6860 unsigned int begin
, middle
, end
;
6861 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
6864 /* Work out the anchor's offset. Use an offset of 0 for the first
6865 anchor so that we don't pessimize the case where we take the address
6866 of a variable at the beginning of the block. This is particularly
6867 useful when a block has only one variable assigned to it.
6869 We try to place anchors RANGE bytes apart, so there can then be
6870 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6871 a ptr_mode offset. With some target settings, the lowest such
6872 anchor might be out of range for the lowest ptr_mode offset;
6873 likewise the highest anchor for the highest offset. Use anchors
6874 at the extreme ends of the ptr_mode range in such cases.
6876 All arithmetic uses unsigned integers in order to avoid
6878 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
6879 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
6880 range
= max_offset
- min_offset
+ 1;
6885 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
6888 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
6889 delta
-= delta
% range
;
6892 offset
= (HOST_WIDE_INT
) (-delta
);
6896 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
6897 delta
-= delta
% range
;
6898 if (delta
> bias
- 1)
6900 offset
= (HOST_WIDE_INT
) delta
;
6904 /* Do a binary search to see if there's already an anchor we can use.
6905 Set BEGIN to the new anchor's index if not. */
6907 end
= VEC_length (rtx
, block
->anchors
);
6908 while (begin
!= end
)
6910 middle
= (end
+ begin
) / 2;
6911 anchor
= VEC_index (rtx
, block
->anchors
, middle
);
6912 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
6914 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
6916 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
6918 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
6924 /* Create a new anchor with a unique label. */
6925 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
6926 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
6927 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
6928 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
6930 /* Insert it at index BEGIN. */
6931 VEC_safe_insert (rtx
, gc
, block
->anchors
, begin
, anchor
);
6935 /* Output the objects in BLOCK. */
6938 output_object_block (struct object_block
*block
)
6940 struct constant_descriptor_rtx
*desc
;
6942 HOST_WIDE_INT offset
;
6946 if (block
->objects
== NULL
)
6949 /* Switch to the section and make sure that the first byte is
6950 suitably aligned. */
6951 switch_to_section (block
->sect
);
6952 assemble_align (block
->alignment
);
6954 /* Define the values of all anchors relative to the current section
6956 FOR_EACH_VEC_ELT (rtx
, block
->anchors
, i
, symbol
)
6957 targetm
.asm_out
.output_anchor (symbol
);
6959 /* Output the objects themselves. */
6961 FOR_EACH_VEC_ELT (rtx
, block
->objects
, i
, symbol
)
6963 /* Move to the object's offset, padding with zeros if necessary. */
6964 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
6965 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
6966 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6968 desc
= SYMBOL_REF_CONSTANT (symbol
);
6969 output_constant_pool_1 (desc
, 1);
6970 offset
+= GET_MODE_SIZE (desc
->mode
);
6972 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6974 decl
= SYMBOL_REF_DECL (symbol
);
6975 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
6977 offset
+= get_constant_size (DECL_INITIAL (decl
));
6981 decl
= SYMBOL_REF_DECL (symbol
);
6982 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
6983 offset
+= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
6988 /* A htab_traverse callback used to call output_object_block for
6989 each member of object_block_htab. */
6992 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
6994 output_object_block ((struct object_block
*) (*slot
));
6998 /* Output the definitions of all object_blocks. */
7001 output_object_blocks (void)
7003 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
7006 /* This function provides a possible implementation of the
7007 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7008 by -frecord-gcc-switches it creates a new mergeable, string section in the
7009 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7010 contains the switches in ASCII format.
7012 FIXME: This code does not correctly handle double quote characters
7013 that appear inside strings, (it strips them rather than preserving them).
7014 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7015 characters - instead it treats them as sub-string separators. Since
7016 we want to emit NUL strings terminators into the object file we have to use
7020 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7024 case SWITCH_TYPE_PASSED
:
7025 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
7026 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7029 case SWITCH_TYPE_DESCRIPTIVE
:
7032 /* Distinguish between invocations where name is NULL. */
7033 static bool started
= false;
7039 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7043 | (SECTION_ENTSIZE
& 1),
7045 switch_to_section (sec
);
7054 /* The return value is currently ignored by the caller, but must be 0.
7055 For -fverbose-asm the return value would be the number of characters
7056 emitted into the assembler file. */
7060 /* Emit text to declare externally defined symbols. It is needed to
7061 properly support non-default visibility. */
7063 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7065 const char *name ATTRIBUTE_UNUSED
)
7067 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7068 set in order to avoid putting out names that are never really
7070 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7071 && targetm
.binds_local_p (decl
))
7072 maybe_assemble_visibility (decl
);
7075 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7078 default_asm_output_source_filename (FILE *file
, const char *name
)
7080 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7081 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
7083 fprintf (file
, "\t.file\t");
7084 output_quoted_string (file
, name
);
7089 /* Output a file name in the form wanted by System V. */
7092 output_file_directive (FILE *asm_file
, const char *input_name
)
7097 if (input_name
== NULL
)
7098 input_name
= "<stdin>";
7100 input_name
= remap_debug_filename (input_name
);
7102 len
= strlen (input_name
);
7103 na
= input_name
+ len
;
7105 /* NA gets INPUT_NAME sans directory names. */
7106 while (na
> input_name
)
7108 if (IS_DIR_SEPARATOR (na
[-1]))
7113 targetm
.asm_out
.output_source_filename (asm_file
, na
);
7116 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7119 make_debug_expr_from_rtl (const_rtx exp
)
7121 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7122 enum machine_mode mode
= GET_MODE (exp
);
7125 DECL_ARTIFICIAL (ddecl
) = 1;
7126 if (REG_P (exp
) && REG_EXPR (exp
))
7127 type
= TREE_TYPE (REG_EXPR (exp
));
7128 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7129 type
= TREE_TYPE (MEM_EXPR (exp
));
7132 if (type
&& TYPE_MODE (type
) == mode
)
7133 TREE_TYPE (ddecl
) = type
;
7135 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7136 DECL_MODE (ddecl
) = mode
;
7137 dval
= gen_rtx_DEBUG_EXPR (mode
);
7138 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7139 SET_DECL_RTL (ddecl
, dval
);
7143 #include "gt-varasm.h"