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"
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h" /* Needed for external data
59 declarations for e.g. AIX 4.x. */
62 /* The (assembler) name of the first globally-visible object output. */
63 extern GTY(()) const char *first_global_object_name
;
64 extern GTY(()) const char *weak_global_object_name
;
66 const char *first_global_object_name
;
67 const char *weak_global_object_name
;
70 struct constant_descriptor_rtx
;
71 struct rtx_constant_pool
;
73 #define n_deferred_constants (crtl->varasm.deferred_constants)
75 /* Number for making the label on the next
76 constant that is stored in memory. */
78 static GTY(()) int const_labelno
;
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81 to ASM_FINISH_DECLARE_OBJECT. */
83 int size_directive_output
;
85 /* The last decl for which assemble_variable was called,
86 if it did ASM_DECLARE_OBJECT_NAME.
87 If the last call to assemble_variable didn't do that,
90 tree last_assemble_variable_decl
;
92 /* The following global variable indicates if the first basic block
93 in a function belongs to the cold partition or not. */
95 bool first_function_block_is_cold
;
97 /* We give all constants their own alias set. Perhaps redundant with
98 MEM_READONLY_P, but pre-dates it. */
100 static alias_set_type const_alias_set
;
102 /* Whether we saw any functions with no_split_stack. */
104 static bool saw_no_split_stack
;
106 static const char *strip_reg_name (const char *);
107 static int contains_pointers_p (tree
);
108 #ifdef ASM_OUTPUT_EXTERNAL
109 static bool incorporeal_function_p (tree
);
111 static void decode_addr_const (tree
, struct addr_const
*);
112 static hashval_t
const_desc_hash (const void *);
113 static int const_desc_eq (const void *, const void *);
114 static hashval_t
const_hash_1 (const tree
);
115 static int compare_constant (const tree
, const tree
);
116 static tree
copy_constant (tree
);
117 static void output_constant_def_contents (rtx
);
118 static void output_addressed_constants (tree
);
119 static unsigned HOST_WIDE_INT
array_size_for_constructor (tree
);
120 static unsigned min_align (unsigned, unsigned);
121 static void globalize_decl (tree
);
122 #ifdef BSS_SECTION_ASM_OP
123 #ifdef ASM_OUTPUT_BSS
124 static void asm_output_bss (FILE *, tree
, const char *,
125 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
127 #ifdef ASM_OUTPUT_ALIGNED_BSS
128 static void asm_output_aligned_bss (FILE *, tree
, const char *,
129 unsigned HOST_WIDE_INT
, int)
132 #endif /* BSS_SECTION_ASM_OP */
133 static void mark_weak (tree
);
134 static void output_constant_pool (const char *, tree
);
136 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
137 section
*text_section
;
138 section
*data_section
;
139 section
*readonly_data_section
;
140 section
*sdata_section
;
141 section
*ctors_section
;
142 section
*dtors_section
;
143 section
*bss_section
;
144 section
*sbss_section
;
146 /* Various forms of common section. All are guaranteed to be nonnull. */
147 section
*tls_comm_section
;
148 section
*comm_section
;
149 section
*lcomm_section
;
151 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
153 section
*bss_noswitch_section
;
155 /* The section that holds the main exception table, when known. The section
156 is set either by the target's init_sections hook or by the first call to
157 switch_to_exception_section. */
158 section
*exception_section
;
160 /* The section that holds the DWARF2 frame unwind information, when known.
161 The section is set either by the target's init_sections hook or by the
162 first call to switch_to_eh_frame_section. */
163 section
*eh_frame_section
;
165 /* asm_out_file's current section. This is NULL if no section has yet
166 been selected or if we lose track of what the current section is. */
169 /* True if code for the current function is currently being directed
170 at the cold section. */
171 bool in_cold_section_p
;
173 /* A linked list of all the unnamed sections. */
174 static GTY(()) section
*unnamed_sections
;
176 /* Return a nonzero value if DECL has a section attribute. */
177 #define IN_NAMED_SECTION(DECL) \
178 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
179 && DECL_SECTION_NAME (DECL) != NULL_TREE)
181 /* Hash table of named sections. */
182 static GTY((param_is (section
))) htab_t section_htab
;
184 /* A table of object_blocks, indexed by section. */
185 static GTY((param_is (struct object_block
))) htab_t object_block_htab
;
187 /* The next number to use for internal anchor labels. */
188 static GTY(()) int anchor_labelno
;
190 /* A pool of constants that can be shared between functions. */
191 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
193 /* Helper routines for maintaining section_htab. */
196 section_entry_eq (const void *p1
, const void *p2
)
198 const section
*old
= (const section
*) p1
;
199 const char *new_name
= (const char *) p2
;
201 return strcmp (old
->named
.name
, new_name
) == 0;
205 section_entry_hash (const void *p
)
207 const section
*old
= (const section
*) p
;
208 return htab_hash_string (old
->named
.name
);
211 /* Return a hash value for section SECT. */
214 hash_section (section
*sect
)
216 if (sect
->common
.flags
& SECTION_NAMED
)
217 return htab_hash_string (sect
->named
.name
);
218 return sect
->common
.flags
;
221 /* Helper routines for maintaining object_block_htab. */
224 object_block_entry_eq (const void *p1
, const void *p2
)
226 const struct object_block
*old
= (const struct object_block
*) p1
;
227 const section
*new_section
= (const section
*) p2
;
229 return old
->sect
== new_section
;
233 object_block_entry_hash (const void *p
)
235 const struct object_block
*old
= (const struct object_block
*) p
;
236 return hash_section (old
->sect
);
239 /* Return a new unnamed section with the given fields. */
242 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
247 sect
= ggc_alloc_section ();
248 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
249 sect
->unnamed
.callback
= callback
;
250 sect
->unnamed
.data
= data
;
251 sect
->unnamed
.next
= unnamed_sections
;
253 unnamed_sections
= sect
;
257 /* Return a SECTION_NOSWITCH section with the given fields. */
260 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
264 sect
= ggc_alloc_section ();
265 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
266 sect
->noswitch
.callback
= callback
;
271 /* Return the named section structure associated with NAME. Create
272 a new section with the given fields if no such structure exists. */
275 get_section (const char *name
, unsigned int flags
, tree decl
)
277 section
*sect
, **slot
;
280 htab_find_slot_with_hash (section_htab
, name
,
281 htab_hash_string (name
), INSERT
);
282 flags
|= SECTION_NAMED
;
285 sect
= ggc_alloc_section ();
286 sect
->named
.common
.flags
= flags
;
287 sect
->named
.name
= ggc_strdup (name
);
288 sect
->named
.decl
= decl
;
294 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
295 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
297 /* Sanity check user variables for flag changes. */
299 decl
= sect
->named
.decl
;
301 error ("%+D causes a section type conflict", decl
);
307 /* Return true if the current compilation mode benefits from having
308 objects grouped into blocks. */
311 use_object_blocks_p (void)
313 return flag_section_anchors
;
316 /* Return the object_block structure for section SECT. Create a new
317 structure if we haven't created one already. Return null if SECT
320 static struct object_block
*
321 get_block_for_section (section
*sect
)
323 struct object_block
*block
;
329 slot
= htab_find_slot_with_hash (object_block_htab
, sect
,
330 hash_section (sect
), INSERT
);
331 block
= (struct object_block
*) *slot
;
334 block
= ggc_alloc_cleared_object_block ();
341 /* Create a symbol with label LABEL and place it at byte offset
342 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
343 is not yet known. LABEL must be a garbage-collected string. */
346 create_block_symbol (const char *label
, struct object_block
*block
,
347 HOST_WIDE_INT offset
)
352 /* Create the extended SYMBOL_REF. */
353 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
354 symbol
= ggc_alloc_zone_rtx_def (size
, &rtl_zone
);
356 /* Initialize the normal SYMBOL_REF fields. */
357 memset (symbol
, 0, size
);
358 PUT_CODE (symbol
, SYMBOL_REF
);
359 PUT_MODE (symbol
, Pmode
);
360 XSTR (symbol
, 0) = label
;
361 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
363 /* Initialize the block_symbol stuff. */
364 SYMBOL_REF_BLOCK (symbol
) = block
;
365 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
371 initialize_cold_section_name (void)
373 const char *stripped_name
;
377 gcc_assert (cfun
&& current_function_decl
);
378 if (crtl
->subsections
.unlikely_text_section_name
)
381 dsn
= DECL_SECTION_NAME (current_function_decl
);
382 if (flag_function_sections
&& dsn
)
384 name
= (char *) alloca (TREE_STRING_LENGTH (dsn
) + 1);
385 memcpy (name
, TREE_STRING_POINTER (dsn
), TREE_STRING_LENGTH (dsn
) + 1);
387 stripped_name
= targetm
.strip_name_encoding (name
);
389 buffer
= ACONCAT ((stripped_name
, "_unlikely", NULL
));
390 crtl
->subsections
.unlikely_text_section_name
= ggc_strdup (buffer
);
393 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
396 /* Tell assembler to switch to unlikely-to-be-executed text section. */
399 unlikely_text_section (void)
403 if (!crtl
->subsections
.unlikely_text_section_name
)
404 initialize_cold_section_name ();
406 return get_named_section (NULL
, crtl
->subsections
.unlikely_text_section_name
, 0);
409 return get_named_section (NULL
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
, 0);
412 /* When called within a function context, return true if the function
413 has been assigned a cold text section and if SECT is that section.
414 When called outside a function context, return true if SECT is the
415 default cold section. */
418 unlikely_text_section_p (section
*sect
)
423 name
= crtl
->subsections
.unlikely_text_section_name
;
425 name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
429 && SECTION_STYLE (sect
) == SECTION_NAMED
430 && strcmp (name
, sect
->named
.name
) == 0);
433 /* Return a section with a particular name and with whatever SECTION_*
434 flags section_type_flags deems appropriate. The name of the section
435 is taken from NAME if nonnull, otherwise it is taken from DECL's
436 DECL_SECTION_NAME. DECL is the decl associated with the section
437 (see the section comment for details) and RELOC is as for
438 section_type_flags. */
441 get_named_section (tree decl
, const char *name
, int reloc
)
445 gcc_assert (!decl
|| DECL_P (decl
));
447 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
449 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
451 return get_section (name
, flags
, decl
);
454 /* If required, set DECL_SECTION_NAME to a unique name. */
457 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
458 int flag_function_or_data_sections
)
460 if (DECL_SECTION_NAME (decl
) == NULL_TREE
461 && targetm
.have_named_sections
462 && (flag_function_or_data_sections
463 || DECL_ONE_ONLY (decl
)))
464 targetm
.asm_out
.unique_section (decl
, reloc
);
467 #ifdef BSS_SECTION_ASM_OP
469 #ifdef ASM_OUTPUT_BSS
471 /* Utility function for ASM_OUTPUT_BSS for targets to use if
472 they don't support alignments in .bss.
473 ??? It is believed that this function will work in most cases so such
474 support is localized here. */
477 asm_output_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
479 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
480 unsigned HOST_WIDE_INT rounded
)
482 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl
), 0), 0), name
) == 0);
483 targetm
.asm_out
.globalize_decl_name (file
, decl
);
484 switch_to_section (bss_section
);
485 #ifdef ASM_DECLARE_OBJECT_NAME
486 last_assemble_variable_decl
= decl
;
487 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
489 /* Standard thing is just output label for the object. */
490 ASM_OUTPUT_LABEL (file
, name
);
491 #endif /* ASM_DECLARE_OBJECT_NAME */
492 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
497 #ifdef ASM_OUTPUT_ALIGNED_BSS
499 /* Utility function for targets to use in implementing
500 ASM_OUTPUT_ALIGNED_BSS.
501 ??? It is believed that this function will work in most cases so such
502 support is localized here. */
505 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
506 const char *name
, unsigned HOST_WIDE_INT size
,
509 switch_to_section (bss_section
);
510 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
511 #ifdef ASM_DECLARE_OBJECT_NAME
512 last_assemble_variable_decl
= decl
;
513 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
515 /* Standard thing is just output label for the object. */
516 ASM_OUTPUT_LABEL (file
, name
);
517 #endif /* ASM_DECLARE_OBJECT_NAME */
518 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
523 #endif /* BSS_SECTION_ASM_OP */
525 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
526 /* Return the hot section for function DECL. Return text_section for
530 hot_function_section (tree decl
)
532 if (decl
!= NULL_TREE
533 && DECL_SECTION_NAME (decl
) != NULL_TREE
534 && targetm
.have_named_sections
)
535 return get_named_section (decl
, NULL
, 0);
541 /* Return the section for function DECL.
543 If DECL is NULL_TREE, return the text section. We can be passed
544 NULL_TREE under some circumstances by dbxout.c at least. */
547 function_section (tree decl
)
551 if (first_function_block_is_cold
)
554 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
555 if (decl
!= NULL_TREE
556 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
557 return reloc
? unlikely_text_section ()
558 : get_named_section (decl
, NULL
, 0);
560 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
562 return reloc
? unlikely_text_section () : hot_function_section (decl
);
567 current_function_section (void)
569 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
570 if (current_function_decl
!= NULL_TREE
571 && DECL_SECTION_NAME (current_function_decl
) != NULL_TREE
)
572 return in_cold_section_p
? unlikely_text_section ()
573 : get_named_section (current_function_decl
,
576 return targetm
.asm_out
.select_section (current_function_decl
,
578 DECL_ALIGN (current_function_decl
));
580 return (in_cold_section_p
581 ? unlikely_text_section ()
582 : hot_function_section (current_function_decl
));
586 /* Return the read-only data section associated with function DECL. */
589 default_function_rodata_section (tree decl
)
591 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
593 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
595 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
601 dot
= strchr (name
+ 1, '.');
604 len
= strlen (dot
) + 8;
605 rname
= (char *) alloca (len
);
607 strcpy (rname
, ".rodata");
609 return get_section (rname
, SECTION_LINKONCE
, decl
);
611 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
612 else if (DECL_ONE_ONLY (decl
)
613 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
615 size_t len
= strlen (name
) + 1;
616 char *rname
= (char *) alloca (len
);
618 memcpy (rname
, name
, len
);
620 return get_section (rname
, SECTION_LINKONCE
, decl
);
622 /* For .text.foo we want to use .rodata.foo. */
623 else if (flag_function_sections
&& flag_data_sections
624 && strncmp (name
, ".text.", 6) == 0)
626 size_t len
= strlen (name
) + 1;
627 char *rname
= (char *) alloca (len
+ 2);
629 memcpy (rname
, ".rodata", 7);
630 memcpy (rname
+ 7, name
+ 5, len
- 5);
631 return get_section (rname
, 0, decl
);
635 return readonly_data_section
;
638 /* Return the read-only data section associated with function DECL
639 for targets where that section should be always the single
640 readonly data section. */
643 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
645 return readonly_data_section
;
648 /* Return the section to use for string merging. */
651 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
652 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
653 unsigned int flags ATTRIBUTE_UNUSED
)
657 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
658 && TREE_CODE (decl
) == STRING_CST
659 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
661 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
662 && TREE_STRING_LENGTH (decl
) >= len
)
664 enum machine_mode mode
;
665 unsigned int modesize
;
671 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
672 modesize
= GET_MODE_BITSIZE (mode
);
673 if (modesize
>= 8 && modesize
<= 256
674 && (modesize
& (modesize
- 1)) == 0)
676 if (align
< modesize
)
679 str
= TREE_STRING_POINTER (decl
);
680 unit
= GET_MODE_SIZE (mode
);
682 /* Check for embedded NUL characters. */
683 for (i
= 0; i
< len
; i
+= unit
)
685 for (j
= 0; j
< unit
; j
++)
686 if (str
[i
+ j
] != '\0')
693 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
695 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
696 return get_section (name
, flags
, NULL
);
701 return readonly_data_section
;
704 /* Return the section to use for constant merging. */
707 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
708 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
709 unsigned int flags ATTRIBUTE_UNUSED
)
711 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
713 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
719 && (align
& (align
- 1)) == 0)
723 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
724 flags
|= (align
/ 8) | SECTION_MERGE
;
725 return get_section (name
, flags
, NULL
);
727 return readonly_data_section
;
730 /* Given NAME, a putative register name, discard any customary prefixes. */
733 strip_reg_name (const char *name
)
735 #ifdef REGISTER_PREFIX
736 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
737 name
+= strlen (REGISTER_PREFIX
);
739 if (name
[0] == '%' || name
[0] == '#')
744 /* The user has asked for a DECL to have a particular name. Set (or
745 change) it in such a way that we don't prefix an underscore to
748 set_user_assembler_name (tree decl
, const char *name
)
750 char *starred
= (char *) alloca (strlen (name
) + 2);
752 strcpy (starred
+ 1, name
);
753 change_decl_assembler_name (decl
, get_identifier (starred
));
754 SET_DECL_RTL (decl
, NULL_RTX
);
757 /* Decode an `asm' spec for a declaration as a register name.
758 Return the register number, or -1 if nothing specified,
759 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
760 or -3 if ASMSPEC is `cc' and is not recognized,
761 or -4 if ASMSPEC is `memory' and is not recognized.
762 Accept an exact spelling or a decimal number.
763 Prefixes such as % are optional. */
766 decode_reg_name (const char *asmspec
)
772 /* Get rid of confusing prefixes. */
773 asmspec
= strip_reg_name (asmspec
);
775 /* Allow a decimal number as a "register name". */
776 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
777 if (! ISDIGIT (asmspec
[i
]))
779 if (asmspec
[0] != 0 && i
< 0)
782 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
788 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
790 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
793 #ifdef ADDITIONAL_REGISTER_NAMES
795 static const struct { const char *const name
; const int number
; } table
[]
796 = ADDITIONAL_REGISTER_NAMES
;
798 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
800 && ! strcmp (asmspec
, table
[i
].name
))
801 return table
[i
].number
;
803 #endif /* ADDITIONAL_REGISTER_NAMES */
805 if (!strcmp (asmspec
, "memory"))
808 if (!strcmp (asmspec
, "cc"))
817 /* Return true if DECL's initializer is suitable for a BSS section. */
820 bss_initializer_p (const_tree decl
)
822 return (DECL_INITIAL (decl
) == NULL
823 || DECL_INITIAL (decl
) == error_mark_node
824 || (flag_zero_initialized_in_bss
825 /* Leave constant zeroes in .rodata so they
827 && !TREE_READONLY (decl
)
828 && initializer_zerop (DECL_INITIAL (decl
))));
831 /* Compute the alignment of variable specified by DECL.
832 DONT_OUTPUT_DATA is from assemble_variable. */
835 align_variable (tree decl
, bool dont_output_data
)
837 unsigned int align
= DECL_ALIGN (decl
);
839 /* In the case for initialing an array whose length isn't specified,
840 where we have not yet been able to do the layout,
841 figure out the proper alignment now. */
842 if (dont_output_data
&& DECL_SIZE (decl
) == 0
843 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
844 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
846 /* Some object file formats have a maximum alignment which they support.
847 In particular, a.out format supports a maximum alignment of 4. */
848 if (align
> MAX_OFILE_ALIGNMENT
)
850 warning (0, "alignment of %q+D is greater than maximum object "
851 "file alignment. Using %d", decl
,
852 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
853 align
= MAX_OFILE_ALIGNMENT
;
856 /* On some machines, it is good to increase alignment sometimes. */
857 if (! DECL_USER_ALIGN (decl
))
859 #ifdef DATA_ALIGNMENT
860 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
861 /* Don't increase alignment too much for TLS variables - TLS space
863 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
866 #ifdef CONSTANT_ALIGNMENT
867 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
869 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
871 /* Don't increase alignment too much for TLS variables - TLS space
873 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
879 /* Reset the alignment in case we have made it tighter, so we can benefit
880 from it in get_pointer_alignment. */
881 DECL_ALIGN (decl
) = align
;
884 /* Return the section into which the given VAR_DECL or CONST_DECL
885 should be placed. PREFER_NOSWITCH_P is true if a noswitch
886 section should be used wherever possible. */
889 get_variable_section (tree decl
, bool prefer_noswitch_p
)
891 addr_space_t as
= ADDR_SPACE_GENERIC
;
894 if (TREE_TYPE (decl
) != error_mark_node
)
895 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
897 if (DECL_COMMON (decl
))
899 /* If the decl has been given an explicit section name, or it resides
900 in a non-generic address space, then it isn't common, and shouldn't
901 be handled as such. */
902 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
903 && ADDR_SPACE_GENERIC_P (as
));
904 if (DECL_THREAD_LOCAL_P (decl
))
905 return tls_comm_section
;
906 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
910 if (DECL_INITIAL (decl
) == error_mark_node
)
911 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
912 else if (DECL_INITIAL (decl
))
913 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
917 resolve_unique_section (decl
, reloc
, flag_data_sections
);
918 if (IN_NAMED_SECTION (decl
))
919 return get_named_section (decl
, NULL
, reloc
);
921 if (ADDR_SPACE_GENERIC_P (as
)
922 && !DECL_THREAD_LOCAL_P (decl
)
923 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
924 && bss_initializer_p (decl
))
926 if (!TREE_PUBLIC (decl
))
927 return lcomm_section
;
928 if (bss_noswitch_section
)
929 return bss_noswitch_section
;
932 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
935 /* Return the block into which object_block DECL should be placed. */
937 static struct object_block
*
938 get_block_for_decl (tree decl
)
942 if (TREE_CODE (decl
) == VAR_DECL
)
944 /* The object must be defined in this translation unit. */
945 if (DECL_EXTERNAL (decl
))
948 /* There's no point using object blocks for something that is
949 isolated by definition. */
950 if (DECL_ONE_ONLY (decl
))
954 /* We can only calculate block offsets if the decl has a known
956 if (DECL_SIZE_UNIT (decl
) == NULL
)
958 if (!host_integerp (DECL_SIZE_UNIT (decl
), 1))
961 /* Find out which section should contain DECL. We cannot put it into
962 an object block if it requires a standalone definition. */
963 if (TREE_CODE (decl
) == VAR_DECL
)
964 align_variable (decl
, 0);
965 sect
= get_variable_section (decl
, true);
966 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
969 return get_block_for_section (sect
);
972 /* Make sure block symbol SYMBOL is in block BLOCK. */
975 change_symbol_block (rtx symbol
, struct object_block
*block
)
977 if (block
!= SYMBOL_REF_BLOCK (symbol
))
979 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
980 SYMBOL_REF_BLOCK (symbol
) = block
;
984 /* Return true if it is possible to put DECL in an object_block. */
987 use_blocks_for_decl_p (tree decl
)
989 /* Only data DECLs can be placed into object blocks. */
990 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
993 /* Detect decls created by dw2_force_const_mem. Such decls are
994 special because DECL_INITIAL doesn't specify the decl's true value.
995 dw2_output_indirect_constants will instead call assemble_variable
996 with dont_output_data set to 1 and then print the contents itself. */
997 if (DECL_INITIAL (decl
) == decl
)
1000 /* If this decl is an alias, then we don't want to emit a
1002 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl
)))
1008 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1009 have static storage duration. In other words, it should not be an
1010 automatic variable, including PARM_DECLs.
1012 There is, however, one exception: this function handles variables
1013 explicitly placed in a particular register by the user.
1015 This is never called for PARM_DECL nodes. */
1018 make_decl_rtl (tree decl
)
1020 const char *name
= 0;
1024 /* Check that we are not being given an automatic variable. */
1025 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1026 && TREE_CODE (decl
) != RESULT_DECL
);
1028 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1029 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1030 || TREE_STATIC (decl
)
1031 || TREE_PUBLIC (decl
)
1032 || DECL_EXTERNAL (decl
)
1033 || DECL_REGISTER (decl
));
1035 /* And that we were not given a type or a label. */
1036 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1037 && TREE_CODE (decl
) != LABEL_DECL
);
1039 /* For a duplicate declaration, we can be called twice on the
1040 same DECL node. Don't discard the RTL already made. */
1041 if (DECL_RTL_SET_P (decl
))
1043 /* If the old RTL had the wrong mode, fix the mode. */
1044 x
= DECL_RTL (decl
);
1045 if (GET_MODE (x
) != DECL_MODE (decl
))
1046 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1048 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1051 /* ??? Another way to do this would be to maintain a hashed
1052 table of such critters. Instead of adding stuff to a DECL
1053 to give certain attributes to it, we could use an external
1054 hash map from DECL to set of attributes. */
1056 /* Let the target reassign the RTL if it wants.
1057 This is necessary, for example, when one machine specific
1058 decl attribute overrides another. */
1059 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1061 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1062 on the new decl information. */
1064 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1065 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1066 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1068 /* Make this function static known to the mudflap runtime. */
1069 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1070 mudflap_enqueue_decl (decl
);
1075 /* If this variable belongs to the global constant pool, retrieve the
1076 pre-computed RTL or recompute it in LTO mode. */
1077 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1079 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1083 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1085 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1086 && DECL_REGISTER (decl
))
1088 error ("register name not specified for %q+D", decl
);
1090 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1092 const char *asmspec
= name
+1;
1093 reg_number
= decode_reg_name (asmspec
);
1094 /* First detect errors in declaring global registers. */
1095 if (reg_number
== -1)
1096 error ("register name not specified for %q+D", decl
);
1097 else if (reg_number
< 0)
1098 error ("invalid register name for %q+D", decl
);
1099 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
1100 error ("data type of %q+D isn%'t suitable for a register",
1102 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
1103 error ("register specified for %q+D isn%'t suitable for data type",
1105 /* Now handle properly declared static register variables. */
1110 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1112 DECL_INITIAL (decl
) = 0;
1113 error ("global register variable has initial value");
1115 if (TREE_THIS_VOLATILE (decl
))
1116 warning (OPT_Wvolatile_register_var
,
1117 "optimization may eliminate reads and/or "
1118 "writes to register variables");
1120 /* If the user specified one of the eliminables registers here,
1121 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1122 confused with that register and be eliminated. This usage is
1123 somewhat suspect... */
1125 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
1126 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1127 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1129 if (TREE_STATIC (decl
))
1131 /* Make this register global, so not usable for anything
1133 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1134 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1135 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1137 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
1139 globalize_reg (reg_number
+ --nregs
);
1142 /* As a register variable, it has no section. */
1146 /* Now handle ordinary static variables and functions (in memory).
1147 Also handle vars declared register invalidly. */
1148 else if (name
[0] == '*')
1150 #ifdef REGISTER_PREFIX
1151 if (strlen (REGISTER_PREFIX
) != 0)
1153 reg_number
= decode_reg_name (name
);
1154 if (reg_number
>= 0 || reg_number
== -3)
1155 error ("register name given for non-register variable %q+D", decl
);
1160 /* Specifying a section attribute on a variable forces it into a
1161 non-.bss section, and thus it cannot be common. */
1162 /* FIXME: In general this code should not be necessary because
1163 visibility pass is doing the same work. But notice_global_symbol
1164 is called early and it needs to make DECL_RTL to get the name.
1165 we take care of recomputing the DECL_RTL after visibility is changed. */
1166 if (TREE_CODE (decl
) == VAR_DECL
1167 && DECL_SECTION_NAME (decl
) != NULL_TREE
1168 && DECL_INITIAL (decl
) == NULL_TREE
1169 && DECL_COMMON (decl
))
1170 DECL_COMMON (decl
) = 0;
1172 /* Variables can't be both common and weak. */
1173 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1174 DECL_COMMON (decl
) = 0;
1176 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1177 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1180 enum machine_mode address_mode
= Pmode
;
1181 if (TREE_TYPE (decl
) != error_mark_node
)
1183 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1184 address_mode
= targetm
.addr_space
.address_mode (as
);
1186 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1188 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1189 SET_SYMBOL_REF_DECL (x
, decl
);
1191 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1192 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1193 set_mem_attributes (x
, decl
, 1);
1194 SET_DECL_RTL (decl
, x
);
1196 /* Optionally set flags or add text to the name to record information
1197 such as that it is a function name.
1198 If the name is changed, the macro ASM_OUTPUT_LABELREF
1199 will have to know how to strip this information. */
1200 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1202 /* Make this function static known to the mudflap runtime. */
1203 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1204 mudflap_enqueue_decl (decl
);
1207 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1208 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1212 make_decl_rtl_for_debug (tree decl
)
1214 unsigned int save_aliasing_flag
, save_mudflap_flag
;
1217 if (DECL_RTL_SET_P (decl
))
1218 return DECL_RTL (decl
);
1220 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1221 call new_alias_set. If running with -fcompare-debug, sometimes
1222 we do not want to create alias sets that will throw the alias
1223 numbers off in the comparison dumps. So... clearing
1224 flag_strict_aliasing will keep new_alias_set() from creating a
1225 new set. It is undesirable to register decl with mudflap
1226 in this case as well. */
1227 save_aliasing_flag
= flag_strict_aliasing
;
1228 flag_strict_aliasing
= 0;
1229 save_mudflap_flag
= flag_mudflap
;
1232 rtl
= DECL_RTL (decl
);
1233 /* Reset DECL_RTL back, as various parts of the compiler expects
1234 DECL_RTL set meaning it is actually going to be output. */
1235 SET_DECL_RTL (decl
, NULL
);
1237 flag_strict_aliasing
= save_aliasing_flag
;
1238 flag_mudflap
= save_mudflap_flag
;
1243 /* Output a string of literal assembler code
1244 for an `asm' keyword used between functions. */
1247 assemble_asm (tree string
)
1251 if (TREE_CODE (string
) == ADDR_EXPR
)
1252 string
= TREE_OPERAND (string
, 0);
1254 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1257 /* Record an element in the table of global destructors. SYMBOL is
1258 a SYMBOL_REF of the function to be called; PRIORITY is a number
1259 between 0 and MAX_INIT_PRIORITY. */
1262 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
1263 int priority ATTRIBUTE_UNUSED
)
1265 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1266 /* Tell GNU LD that this is part of the static destructor set.
1267 This will work for any system that uses stabs, most usefully
1269 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1270 dbxout_stab_value_label (XSTR (symbol
, 0));
1272 sorry ("global destructors not supported on this target");
1276 /* Write the address of the entity given by SYMBOL to SEC. */
1278 assemble_addr_to_section (rtx symbol
, section
*sec
)
1280 switch_to_section (sec
);
1281 assemble_align (POINTER_SIZE
);
1282 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1285 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1286 not) section for PRIORITY. */
1288 get_cdtor_priority_section (int priority
, bool constructor_p
)
1292 /* ??? This only works reliably with the GNU linker. */
1293 sprintf (buf
, "%s.%.5u",
1294 constructor_p
? ".ctors" : ".dtors",
1295 /* Invert the numbering so the linker puts us in the proper
1296 order; constructors are run from right to left, and the
1297 linker sorts in increasing order. */
1298 MAX_INIT_PRIORITY
- priority
);
1299 return get_section (buf
, SECTION_WRITE
, NULL
);
1303 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1307 if (priority
!= DEFAULT_INIT_PRIORITY
)
1308 sec
= get_cdtor_priority_section (priority
,
1309 /*constructor_p=*/false);
1311 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1313 assemble_addr_to_section (symbol
, sec
);
1316 #ifdef DTORS_SECTION_ASM_OP
1318 default_dtor_section_asm_out_destructor (rtx symbol
,
1319 int priority ATTRIBUTE_UNUSED
)
1321 assemble_addr_to_section (symbol
, dtors_section
);
1325 /* Likewise for global constructors. */
1328 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
1329 int priority ATTRIBUTE_UNUSED
)
1331 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1332 /* Tell GNU LD that this is part of the static destructor set.
1333 This will work for any system that uses stabs, most usefully
1335 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1336 dbxout_stab_value_label (XSTR (symbol
, 0));
1338 sorry ("global constructors not supported on this target");
1343 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1347 if (priority
!= DEFAULT_INIT_PRIORITY
)
1348 sec
= get_cdtor_priority_section (priority
,
1349 /*constructor_p=*/true);
1351 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1353 assemble_addr_to_section (symbol
, sec
);
1356 #ifdef CTORS_SECTION_ASM_OP
1358 default_ctor_section_asm_out_constructor (rtx symbol
,
1359 int priority ATTRIBUTE_UNUSED
)
1361 assemble_addr_to_section (symbol
, ctors_section
);
1365 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1366 a nonzero value if the constant pool should be output before the
1367 start of the function, or a zero value if the pool should output
1368 after the end of the function. The default is to put it before the
1371 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1372 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1375 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1376 to be output to assembler.
1377 Set first_global_object_name and weak_global_object_name as appropriate. */
1380 notice_global_symbol (tree decl
)
1382 const char **type
= &first_global_object_name
;
1384 if (first_global_object_name
1385 || !TREE_PUBLIC (decl
)
1386 || DECL_EXTERNAL (decl
)
1387 || !DECL_NAME (decl
)
1388 || (TREE_CODE (decl
) != FUNCTION_DECL
1389 && (TREE_CODE (decl
) != VAR_DECL
1390 || (DECL_COMMON (decl
)
1391 && (DECL_INITIAL (decl
) == 0
1392 || DECL_INITIAL (decl
) == error_mark_node
))))
1393 || !MEM_P (DECL_RTL (decl
)))
1396 /* We win when global object is found, but it is useful to know about weak
1397 symbol as well so we can produce nicer unique names. */
1398 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1399 type
= &weak_global_object_name
;
1405 rtx decl_rtl
= DECL_RTL (decl
);
1407 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1408 name
= ggc_strdup (p
);
1414 /* Output assembler code for the constant pool of a function and associated
1415 with defining the name of the function. DECL describes the function.
1416 NAME is the function's name. For the constant pool, we use the current
1417 constant pool data. */
1420 assemble_start_function (tree decl
, const char *fnname
)
1423 char tmp_label
[100];
1424 bool hot_label_written
= false;
1426 crtl
->subsections
.unlikely_text_section_name
= NULL
;
1428 first_function_block_is_cold
= false;
1429 if (flag_reorder_blocks_and_partition
)
1431 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1432 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1433 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1434 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1435 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1436 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1437 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1438 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1443 crtl
->subsections
.hot_section_label
= NULL
;
1444 crtl
->subsections
.cold_section_label
= NULL
;
1445 crtl
->subsections
.hot_section_end_label
= NULL
;
1446 crtl
->subsections
.cold_section_end_label
= NULL
;
1449 /* The following code does not need preprocessing in the assembler. */
1453 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1454 output_constant_pool (fnname
, decl
);
1456 resolve_unique_section (decl
, 0, flag_function_sections
);
1458 /* Make sure the not and cold text (code) sections are properly
1459 aligned. This is necessary here in the case where the function
1460 has both hot and cold sections, because we don't want to re-set
1461 the alignment when the section switch happens mid-function. */
1463 if (flag_reorder_blocks_and_partition
)
1465 switch_to_section (unlikely_text_section ());
1466 assemble_align (DECL_ALIGN (decl
));
1467 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1469 /* When the function starts with a cold section, we need to explicitly
1470 align the hot section and write out the hot section label.
1471 But if the current function is a thunk, we do not have a CFG. */
1473 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1475 switch_to_section (text_section
);
1476 assemble_align (DECL_ALIGN (decl
));
1477 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1478 hot_label_written
= true;
1479 first_function_block_is_cold
= true;
1482 else if (DECL_SECTION_NAME (decl
))
1484 /* Calls to function_section rely on first_function_block_is_cold
1485 being accurate. The first block may be cold even if we aren't
1486 doing partitioning, if the entire function was decided by
1487 choose_function_section (predict.c) to be cold. */
1489 initialize_cold_section_name ();
1491 if (crtl
->subsections
.unlikely_text_section_name
1492 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
1493 crtl
->subsections
.unlikely_text_section_name
) == 0)
1494 first_function_block_is_cold
= true;
1497 in_cold_section_p
= first_function_block_is_cold
;
1499 /* Switch to the correct text section for the start of the function. */
1501 switch_to_section (function_section (decl
));
1502 if (flag_reorder_blocks_and_partition
1503 && !hot_label_written
)
1504 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1506 /* Tell assembler to move to target machine's alignment for functions. */
1507 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1510 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1513 /* Handle a user-specified function alignment.
1514 Note that we still need to align to DECL_ALIGN, as above,
1515 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1516 if (! DECL_USER_ALIGN (decl
)
1517 && align_functions_log
> align
1518 && optimize_function_for_speed_p (cfun
))
1520 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1521 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1522 align_functions_log
, align_functions
- 1);
1524 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1528 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1529 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1532 if (!DECL_IGNORED_P (decl
))
1533 (*debug_hooks
->begin_function
) (decl
);
1535 /* Make function name accessible from other files, if appropriate. */
1537 if (TREE_PUBLIC (decl
))
1539 notice_global_symbol (decl
);
1541 globalize_decl (decl
);
1543 maybe_assemble_visibility (decl
);
1546 if (DECL_PRESERVE_P (decl
))
1547 targetm
.asm_out
.mark_decl_preserved (fnname
);
1549 /* Do any machine/system dependent processing of the function name. */
1550 #ifdef ASM_DECLARE_FUNCTION_NAME
1551 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1553 /* Standard thing is just output label for the function. */
1554 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1555 #endif /* ASM_DECLARE_FUNCTION_NAME */
1557 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl
)))
1558 saw_no_split_stack
= true;
1561 /* Output assembler code associated with defining the size of the
1562 function. DECL describes the function. NAME is the function's name. */
1565 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1567 #ifdef ASM_DECLARE_FUNCTION_SIZE
1568 /* We could have switched section in the middle of the function. */
1569 if (flag_reorder_blocks_and_partition
)
1570 switch_to_section (function_section (decl
));
1571 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1573 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1575 output_constant_pool (fnname
, decl
);
1576 switch_to_section (function_section (decl
)); /* need to switch back */
1578 /* Output labels for end of hot/cold text sections (to be used by
1580 if (flag_reorder_blocks_and_partition
)
1582 section
*save_text_section
;
1584 save_text_section
= in_section
;
1585 switch_to_section (unlikely_text_section ());
1586 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1587 if (first_function_block_is_cold
)
1588 switch_to_section (text_section
);
1590 switch_to_section (function_section (decl
));
1591 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1592 switch_to_section (save_text_section
);
1596 /* Assemble code to leave SIZE bytes of zeros. */
1599 assemble_zeros (unsigned HOST_WIDE_INT size
)
1601 /* Do no output if -fsyntax-only. */
1602 if (flag_syntax_only
)
1605 #ifdef ASM_NO_SKIP_IN_TEXT
1606 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1607 so we must output 0s explicitly in the text section. */
1608 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1610 unsigned HOST_WIDE_INT i
;
1611 for (i
= 0; i
< size
; i
++)
1612 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1617 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1620 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1623 assemble_align (int align
)
1625 if (align
> BITS_PER_UNIT
)
1627 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1631 /* Assemble a string constant with the specified C string as contents. */
1634 assemble_string (const char *p
, int size
)
1639 /* If the string is very long, split it up. */
1643 int thissize
= size
- pos
;
1644 if (thissize
> maximum
)
1647 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1655 /* A noswitch_section_callback for lcomm_section. */
1658 emit_local (tree decl ATTRIBUTE_UNUSED
,
1659 const char *name ATTRIBUTE_UNUSED
,
1660 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1661 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1663 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1664 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1665 size
, DECL_ALIGN (decl
));
1667 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1668 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1671 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1676 /* A noswitch_section_callback for bss_noswitch_section. */
1678 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1680 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1681 const char *name ATTRIBUTE_UNUSED
,
1682 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1683 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1685 #if defined ASM_OUTPUT_ALIGNED_BSS
1686 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
, DECL_ALIGN (decl
));
1689 ASM_OUTPUT_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1695 /* A noswitch_section_callback for comm_section. */
1698 emit_common (tree decl ATTRIBUTE_UNUSED
,
1699 const char *name ATTRIBUTE_UNUSED
,
1700 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1701 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1703 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1704 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1705 size
, DECL_ALIGN (decl
));
1707 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1708 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1711 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1716 /* A noswitch_section_callback for tls_comm_section. */
1719 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1720 const char *name ATTRIBUTE_UNUSED
,
1721 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1722 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1724 #ifdef ASM_OUTPUT_TLS_COMMON
1725 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1728 sorry ("thread-local COMMON data not implemented");
1733 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1734 NAME is the name of DECL's SYMBOL_REF. */
1737 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
)
1739 unsigned HOST_WIDE_INT size
, rounded
;
1741 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1744 /* Don't allocate zero bytes of common,
1745 since that means "undefined external" in the linker. */
1749 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1750 so that each uninitialized object starts on such a boundary. */
1751 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1752 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1753 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1755 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
1756 && (unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
1757 warning (0, "requested alignment for %q+D is greater than "
1758 "implemented alignment of %wu", decl
, rounded
);
1761 /* A subroutine of assemble_variable. Output the label and contents of
1762 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1763 is as for assemble_variable. */
1766 assemble_variable_contents (tree decl
, const char *name
,
1767 bool dont_output_data
)
1769 /* Do any machine/system dependent processing of the object. */
1770 #ifdef ASM_DECLARE_OBJECT_NAME
1771 last_assemble_variable_decl
= decl
;
1772 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1774 /* Standard thing is just output label for the object. */
1775 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1776 #endif /* ASM_DECLARE_OBJECT_NAME */
1778 if (!dont_output_data
)
1780 if (DECL_INITIAL (decl
)
1781 && DECL_INITIAL (decl
) != error_mark_node
1782 && !initializer_zerop (DECL_INITIAL (decl
)))
1783 /* Output the actual data. */
1784 output_constant (DECL_INITIAL (decl
),
1785 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1788 /* Leave space for it. */
1789 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1793 /* Assemble everything that is needed for a variable or function declaration.
1794 Not used for automatic variables, and not used for function definitions.
1795 Should not be called for variables of incomplete structure type.
1797 TOP_LEVEL is nonzero if this variable has file scope.
1798 AT_END is nonzero if this is the special handling, at end of compilation,
1799 to define things that have had only tentative definitions.
1800 DONT_OUTPUT_DATA if nonzero means don't actually output the
1801 initial value (that will be done by the caller). */
1804 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
1805 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
1808 rtx decl_rtl
, symbol
;
1811 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1812 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
1814 /* Emulated TLS had better not get this far. */
1815 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
1817 last_assemble_variable_decl
= 0;
1819 /* Normally no need to say anything here for external references,
1820 since assemble_external is called by the language-specific code
1821 when a declaration is first seen. */
1823 if (DECL_EXTERNAL (decl
))
1826 /* Do nothing for global register variables. */
1827 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
1829 TREE_ASM_WRITTEN (decl
) = 1;
1833 /* If type was incomplete when the variable was declared,
1834 see if it is complete now. */
1836 if (DECL_SIZE (decl
) == 0)
1837 layout_decl (decl
, 0);
1839 /* Still incomplete => don't allocate it; treat the tentative defn
1840 (which is what it must have been) as an `extern' reference. */
1842 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1844 error ("storage size of %q+D isn%'t known", decl
);
1845 TREE_ASM_WRITTEN (decl
) = 1;
1849 /* The first declaration of a variable that comes through this function
1850 decides whether it is global (in C, has external linkage)
1851 or local (in C, has internal linkage). So do nothing more
1852 if this function has already run. */
1854 if (TREE_ASM_WRITTEN (decl
))
1857 /* Make sure targetm.encode_section_info is invoked before we set
1859 decl_rtl
= DECL_RTL (decl
);
1861 TREE_ASM_WRITTEN (decl
) = 1;
1863 /* Do no output if -fsyntax-only. */
1864 if (flag_syntax_only
)
1867 if (! dont_output_data
1868 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1870 error ("size of variable %q+D is too large", decl
);
1874 gcc_assert (MEM_P (decl_rtl
));
1875 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
1876 symbol
= XEXP (decl_rtl
, 0);
1878 /* If this symbol belongs to the tree constant pool, output the constant
1879 if it hasn't already been written. */
1880 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
1882 tree decl
= SYMBOL_REF_DECL (symbol
);
1883 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
1884 output_constant_def_contents (symbol
);
1890 name
= XSTR (symbol
, 0);
1891 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1892 notice_global_symbol (decl
);
1894 /* Compute the alignment of this data. */
1896 align_variable (decl
, dont_output_data
);
1897 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
1899 if (TREE_PUBLIC (decl
))
1900 maybe_assemble_visibility (decl
);
1902 if (DECL_PRESERVE_P (decl
))
1903 targetm
.asm_out
.mark_decl_preserved (name
);
1905 /* First make the assembler name(s) global if appropriate. */
1906 sect
= get_variable_section (decl
, false);
1907 if (TREE_PUBLIC (decl
)
1908 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
1909 globalize_decl (decl
);
1911 /* Output any data that we will need to use the address of. */
1912 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
1913 output_addressed_constants (DECL_INITIAL (decl
));
1915 /* dbxout.c needs to know this. */
1916 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
1917 DECL_IN_TEXT_SECTION (decl
) = 1;
1919 /* If the decl is part of an object_block, make sure that the decl
1920 has been positioned within its block, but do not write out its
1921 definition yet. output_object_blocks will do that later. */
1922 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
1924 gcc_assert (!dont_output_data
);
1925 place_block_symbol (symbol
);
1927 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1928 assemble_noswitch_variable (decl
, name
, sect
);
1931 switch_to_section (sect
);
1932 if (DECL_ALIGN (decl
) > BITS_PER_UNIT
)
1933 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
1934 assemble_variable_contents (decl
, name
, dont_output_data
);
1938 /* Return 1 if type TYPE contains any pointers. */
1941 contains_pointers_p (tree type
)
1943 switch (TREE_CODE (type
))
1946 case REFERENCE_TYPE
:
1947 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1948 so I'll play safe and return 1. */
1954 case QUAL_UNION_TYPE
:
1957 /* For a type that has fields, see if the fields have pointers. */
1958 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
1959 if (TREE_CODE (fields
) == FIELD_DECL
1960 && contains_pointers_p (TREE_TYPE (fields
)))
1966 /* An array type contains pointers if its element type does. */
1967 return contains_pointers_p (TREE_TYPE (type
));
1974 /* We delay assemble_external processing until
1975 the compilation unit is finalized. This is the best we can do for
1976 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
1977 it all the way to final. See PR 17982 for further discussion. */
1978 static GTY(()) tree pending_assemble_externals
;
1980 #ifdef ASM_OUTPUT_EXTERNAL
1981 /* True if DECL is a function decl for which no out-of-line copy exists.
1982 It is assumed that DECL's assembler name has been set. */
1985 incorporeal_function_p (tree decl
)
1987 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
1991 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
1992 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
1995 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1996 if (is_builtin_name (name
))
2002 /* Actually do the tests to determine if this is necessary, and invoke
2003 ASM_OUTPUT_EXTERNAL. */
2005 assemble_external_real (tree decl
)
2007 rtx rtl
= DECL_RTL (decl
);
2009 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2010 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2011 && !incorporeal_function_p (decl
))
2013 /* Some systems do require some output. */
2014 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2015 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2021 process_pending_assemble_externals (void)
2023 #ifdef ASM_OUTPUT_EXTERNAL
2025 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2026 assemble_external_real (TREE_VALUE (list
));
2028 pending_assemble_externals
= 0;
2032 /* This TREE_LIST contains any weak symbol declarations waiting
2034 static GTY(()) tree weak_decls
;
2036 /* Output something to declare an external symbol to the assembler,
2037 and qualifiers such as weakness. (Most assemblers don't need
2038 extern declaration, so we normally output nothing.) Do nothing if
2039 DECL is not external. */
2042 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2044 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2045 main body of this code is only rarely exercised. To provide some
2046 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2047 open. If it's not, we should not be calling this function. */
2048 gcc_assert (asm_out_file
);
2050 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2053 /* We want to output annotation for weak and external symbols at
2054 very last to check if they are references or not. */
2058 /* TREE_STATIC is a weird and abused creature which is not
2059 generally the right test for whether an entity has been
2060 locally emitted, inlined or otherwise not-really-extern, but
2061 for declarations that can be weak, it happens to be
2063 && !TREE_STATIC (decl
)
2064 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2065 && value_member (decl
, weak_decls
) == NULL_TREE
)
2066 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2068 #ifdef ASM_OUTPUT_EXTERNAL
2069 if (value_member (decl
, pending_assemble_externals
) == NULL_TREE
)
2070 pending_assemble_externals
= tree_cons (NULL
, decl
,
2071 pending_assemble_externals
);
2075 /* Similar, for calling a library function FUN. */
2078 assemble_external_libcall (rtx fun
)
2080 /* Declare library function name external when first used, if nec. */
2081 if (! SYMBOL_REF_USED (fun
))
2083 SYMBOL_REF_USED (fun
) = 1;
2084 targetm
.asm_out
.external_libcall (fun
);
2088 /* Assemble a label named NAME. */
2091 assemble_label (FILE *file
, const char *name
)
2093 ASM_OUTPUT_LABEL (file
, name
);
2096 /* Set the symbol_referenced flag for ID. */
2098 mark_referenced (tree id
)
2100 TREE_SYMBOL_REFERENCED (id
) = 1;
2103 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2105 mark_decl_referenced (tree decl
)
2107 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2109 /* Extern inline functions don't become needed when referenced.
2110 If we know a method will be emitted in other TU and no new
2111 functions can be marked reachable, just use the external
2113 struct cgraph_node
*node
= cgraph_node (decl
);
2114 if (!DECL_EXTERNAL (decl
)
2115 && (!node
->local
.vtable_method
|| !cgraph_global_info_ready
2116 || !node
->local
.finalized
))
2117 cgraph_mark_needed_node (node
);
2119 else if (TREE_CODE (decl
) == VAR_DECL
)
2121 struct varpool_node
*node
= varpool_node (decl
);
2122 varpool_mark_needed_node (node
);
2123 /* C++ frontend use mark_decl_references to force COMDAT variables
2124 to be output that might appear dead otherwise. */
2125 node
->force_output
= true;
2127 /* else do nothing - we can get various sorts of CST nodes here,
2128 which do not need to be marked. */
2132 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2133 until we find an identifier that is not itself a transparent alias.
2134 Modify the alias passed to it by reference (and all aliases on the
2135 way to the ultimate target), such that they do not have to be
2136 followed again, and return the ultimate target of the alias
2140 ultimate_transparent_alias_target (tree
*alias
)
2142 tree target
= *alias
;
2144 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2146 gcc_assert (TREE_CHAIN (target
));
2147 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2148 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2149 && ! TREE_CHAIN (target
));
2156 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2157 starts with a *, the rest of NAME is output verbatim. Otherwise
2158 NAME is transformed in a target-specific way (usually by the
2159 addition of an underscore). */
2162 assemble_name_raw (FILE *file
, const char *name
)
2165 fputs (&name
[1], file
);
2167 ASM_OUTPUT_LABELREF (file
, name
);
2170 /* Like assemble_name_raw, but should be used when NAME might refer to
2171 an entity that is also represented as a tree (like a function or
2172 variable). If NAME does refer to such an entity, that entity will
2173 be marked as referenced. */
2176 assemble_name (FILE *file
, const char *name
)
2178 const char *real_name
;
2181 real_name
= targetm
.strip_name_encoding (name
);
2183 id
= maybe_get_identifier (real_name
);
2188 mark_referenced (id
);
2189 ultimate_transparent_alias_target (&id
);
2191 name
= IDENTIFIER_POINTER (id
);
2192 gcc_assert (! TREE_CHAIN (id
));
2195 assemble_name_raw (file
, name
);
2198 /* Allocate SIZE bytes writable static space with a gensym name
2199 and return an RTX to refer to its address. */
2202 assemble_static_space (unsigned HOST_WIDE_INT size
)
2205 const char *namestring
;
2208 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2210 namestring
= ggc_strdup (name
);
2212 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2213 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2215 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2216 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2219 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2220 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2223 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2224 so that each uninitialized object starts on such a boundary. */
2225 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2226 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2227 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2228 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2229 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2230 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2237 /* Assemble the static constant template for function entry trampolines.
2238 This is done at most once per compilation.
2239 Returns an RTX for the address of the template. */
2241 static GTY(()) rtx initial_trampoline
;
2244 assemble_trampoline_template (void)
2251 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2253 if (initial_trampoline
)
2254 return initial_trampoline
;
2256 /* By default, put trampoline templates in read-only data section. */
2258 #ifdef TRAMPOLINE_SECTION
2259 switch_to_section (TRAMPOLINE_SECTION
);
2261 switch_to_section (readonly_data_section
);
2264 /* Write the assembler code to define one. */
2265 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2267 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2269 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2270 targetm
.asm_out
.trampoline_template (asm_out_file
);
2272 /* Record the rtl to refer to it. */
2273 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2274 name
= ggc_strdup (label
);
2275 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2276 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2278 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2279 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2280 set_mem_size (initial_trampoline
, GEN_INT (TRAMPOLINE_SIZE
));
2282 return initial_trampoline
;
2285 /* A and B are either alignments or offsets. Return the minimum alignment
2286 that may be assumed after adding the two together. */
2288 static inline unsigned
2289 min_align (unsigned int a
, unsigned int b
)
2291 return (a
| b
) & -(a
| b
);
2294 /* Return the assembler directive for creating a given kind of integer
2295 object. SIZE is the number of bytes in the object and ALIGNED_P
2296 indicates whether it is known to be aligned. Return NULL if the
2297 assembly dialect has no such directive.
2299 The returned string should be printed at the start of a new line and
2300 be followed immediately by the object's initial value. */
2303 integer_asm_op (int size
, int aligned_p
)
2305 struct asm_int_op
*ops
;
2308 ops
= &targetm
.asm_out
.aligned_op
;
2310 ops
= &targetm
.asm_out
.unaligned_op
;
2315 return targetm
.asm_out
.byte_op
;
2329 /* Use directive OP to assemble an integer object X. Print OP at the
2330 start of the line, followed immediately by the value of X. */
2333 assemble_integer_with_op (const char *op
, rtx x
)
2335 fputs (op
, asm_out_file
);
2336 output_addr_const (asm_out_file
, x
);
2337 fputc ('\n', asm_out_file
);
2340 /* The default implementation of the asm_out.integer target hook. */
2343 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2344 unsigned int size ATTRIBUTE_UNUSED
,
2345 int aligned_p ATTRIBUTE_UNUSED
)
2347 const char *op
= integer_asm_op (size
, aligned_p
);
2348 /* Avoid GAS bugs for large values. Specifically negative values whose
2349 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2350 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2352 return op
&& (assemble_integer_with_op (op
, x
), true);
2355 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2356 the alignment of the integer in bits. Return 1 if we were able to output
2357 the constant, otherwise 0. We must be able to output the constant,
2358 if FORCE is nonzero. */
2361 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2365 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2367 /* See if the target hook can handle this kind of object. */
2368 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2371 /* If the object is a multi-byte one, try splitting it up. Split
2372 it into words it if is multi-word, otherwise split it into bytes. */
2375 enum machine_mode omode
, imode
;
2376 unsigned int subalign
;
2377 unsigned int subsize
, i
;
2378 enum mode_class mclass
;
2380 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2381 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2382 if (GET_CODE (x
) == CONST_FIXED
)
2383 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2387 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2388 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2390 for (i
= 0; i
< size
; i
+= subsize
)
2392 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2393 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2399 /* If we've printed some of it, but not all of it, there's no going
2404 gcc_assert (!force
);
2410 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2412 long data
[4] = {0, 0, 0, 0};
2414 int bitsize
, nelts
, nunits
, units_per
;
2416 /* This is hairy. We have a quantity of known size. real_to_target
2417 will put it into an array of *host* longs, 32 bits per element
2418 (even if long is more than 32 bits). We need to determine the
2419 number of array elements that are occupied (nelts) and the number
2420 of *target* min-addressable units that will be occupied in the
2421 object file (nunits). We cannot assume that 32 divides the
2422 mode's bitsize (size * BITS_PER_UNIT) evenly.
2424 size * BITS_PER_UNIT is used here to make sure that padding bits
2425 (which might appear at either end of the value; real_to_target
2426 will include the padding bits in its output array) are included. */
2428 nunits
= GET_MODE_SIZE (mode
);
2429 bitsize
= nunits
* BITS_PER_UNIT
;
2430 nelts
= CEIL (bitsize
, 32);
2431 units_per
= 32 / BITS_PER_UNIT
;
2433 real_to_target (data
, &d
, mode
);
2435 /* Put out the first word with the specified alignment. */
2436 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2437 nunits
-= units_per
;
2439 /* Subsequent words need only 32-bit alignment. */
2440 align
= min_align (align
, 32);
2442 for (i
= 1; i
< nelts
; i
++)
2444 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2445 nunits
-= units_per
;
2449 /* Given an expression EXP with a constant value,
2450 reduce it to the sum of an assembler symbol and an integer.
2451 Store them both in the structure *VALUE.
2452 EXP must be reducible. */
2454 struct GTY(()) addr_const
{
2456 HOST_WIDE_INT offset
;
2460 decode_addr_const (tree exp
, struct addr_const
*value
)
2462 tree target
= TREE_OPERAND (exp
, 0);
2468 if (TREE_CODE (target
) == COMPONENT_REF
2469 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2471 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2472 target
= TREE_OPERAND (target
, 0);
2474 else if (TREE_CODE (target
) == ARRAY_REF
2475 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2477 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2478 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2479 target
= TREE_OPERAND (target
, 0);
2481 else if (TREE_CODE (target
) == INDIRECT_REF
2482 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2483 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2485 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2490 switch (TREE_CODE (target
))
2494 x
= DECL_RTL (target
);
2498 x
= gen_rtx_MEM (FUNCTION_MODE
,
2499 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2508 x
= output_constant_def (target
, 1);
2515 gcc_assert (MEM_P (x
));
2519 value
->offset
= offset
;
2523 static GTY((param_is (struct constant_descriptor_tree
)))
2524 htab_t const_desc_htab
;
2526 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2528 /* Constant pool accessor function. */
2531 constant_pool_htab (void)
2533 return const_desc_htab
;
2536 /* Compute a hash code for a constant expression. */
2539 const_desc_hash (const void *ptr
)
2541 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2545 const_hash_1 (const tree exp
)
2550 enum tree_code code
= TREE_CODE (exp
);
2552 /* Either set P and LEN to the address and len of something to hash and
2553 exit the switch or return a value. */
2558 p
= (char *) &TREE_INT_CST (exp
);
2559 len
= sizeof TREE_INT_CST (exp
);
2563 return real_hash (TREE_REAL_CST_PTR (exp
));
2566 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2569 p
= TREE_STRING_POINTER (exp
);
2570 len
= TREE_STRING_LENGTH (exp
);
2574 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2575 + const_hash_1 (TREE_IMAGPART (exp
)));
2581 hi
= 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
));
2583 for (link
= TREE_VECTOR_CST_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2584 hi
= hi
* 563 + const_hash_1 (TREE_VALUE (link
));
2591 unsigned HOST_WIDE_INT idx
;
2594 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2596 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2598 hi
= hi
* 603 + const_hash_1 (value
);
2606 struct addr_const value
;
2608 decode_addr_const (exp
, &value
);
2609 switch (GET_CODE (value
.base
))
2612 /* Don't hash the address of the SYMBOL_REF;
2613 only use the offset and the symbol name. */
2615 p
= XSTR (value
.base
, 0);
2616 for (i
= 0; p
[i
] != 0; i
++)
2617 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2621 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2631 case POINTER_PLUS_EXPR
:
2633 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2634 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2637 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2640 /* A language specific constant. Just hash the code. */
2644 /* Compute hashing function. */
2646 for (i
= 0; i
< len
; i
++)
2647 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2652 /* Wrapper of compare_constant, for the htab interface. */
2654 const_desc_eq (const void *p1
, const void *p2
)
2656 const struct constant_descriptor_tree
*const c1
2657 = (const struct constant_descriptor_tree
*) p1
;
2658 const struct constant_descriptor_tree
*const c2
2659 = (const struct constant_descriptor_tree
*) p2
;
2660 if (c1
->hash
!= c2
->hash
)
2662 return compare_constant (c1
->value
, c2
->value
);
2665 /* Compare t1 and t2, and return 1 only if they are known to result in
2666 the same bit pattern on output. */
2669 compare_constant (const tree t1
, const tree t2
)
2671 enum tree_code typecode
;
2673 if (t1
== NULL_TREE
)
2674 return t2
== NULL_TREE
;
2675 if (t2
== NULL_TREE
)
2678 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2681 switch (TREE_CODE (t1
))
2684 /* Integer constants are the same only if the same width of type. */
2685 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2687 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2689 return tree_int_cst_equal (t1
, t2
);
2692 /* Real constants are the same only if the same width of type. */
2693 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2696 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2699 /* Fixed constants are the same only if the same width of type. */
2700 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2703 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
2706 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2709 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2710 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2711 TREE_STRING_LENGTH (t1
)));
2714 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2715 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2721 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1
))
2722 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2
)))
2725 link2
= TREE_VECTOR_CST_ELTS (t2
);
2726 for (link1
= TREE_VECTOR_CST_ELTS (t1
);
2728 link1
= TREE_CHAIN (link1
))
2730 if (!compare_constant (TREE_VALUE (link1
), TREE_VALUE (link2
)))
2732 link2
= TREE_CHAIN (link2
);
2740 VEC(constructor_elt
, gc
) *v1
, *v2
;
2741 unsigned HOST_WIDE_INT idx
;
2743 typecode
= TREE_CODE (TREE_TYPE (t1
));
2744 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
2747 if (typecode
== ARRAY_TYPE
)
2749 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
2750 /* For arrays, check that the sizes all match. */
2751 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
2753 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
2758 /* For record and union constructors, require exact type
2760 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
2764 v1
= CONSTRUCTOR_ELTS (t1
);
2765 v2
= CONSTRUCTOR_ELTS (t2
);
2766 if (VEC_length (constructor_elt
, v1
)
2767 != VEC_length (constructor_elt
, v2
))
2770 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
2772 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
2773 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
2775 /* Check that each value is the same... */
2776 if (!compare_constant (c1
->value
, c2
->value
))
2778 /* ... and that they apply to the same fields! */
2779 if (typecode
== ARRAY_TYPE
)
2781 if (!compare_constant (c1
->index
, c2
->index
))
2786 if (c1
->index
!= c2
->index
)
2797 struct addr_const value1
, value2
;
2801 decode_addr_const (t1
, &value1
);
2802 decode_addr_const (t2
, &value2
);
2804 if (value1
.offset
!= value2
.offset
)
2807 code
= GET_CODE (value1
.base
);
2808 if (code
!= GET_CODE (value2
.base
))
2814 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
2818 ret
= (CODE_LABEL_NUMBER (XEXP (value1
.base
, 0))
2819 == CODE_LABEL_NUMBER (XEXP (value2
.base
, 0)));
2829 case POINTER_PLUS_EXPR
:
2832 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2833 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2836 case VIEW_CONVERT_EXPR
:
2837 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2846 /* Make a copy of the whole tree structure for a constant. This
2847 handles the same types of nodes that compare_constant handles. */
2850 copy_constant (tree exp
)
2852 switch (TREE_CODE (exp
))
2855 /* For ADDR_EXPR, we do not want to copy the decl whose address
2856 is requested. We do want to copy constants though. */
2857 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
2858 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2859 copy_constant (TREE_OPERAND (exp
, 0)));
2861 return copy_node (exp
);
2867 return copy_node (exp
);
2870 return build_complex (TREE_TYPE (exp
),
2871 copy_constant (TREE_REALPART (exp
)),
2872 copy_constant (TREE_IMAGPART (exp
)));
2875 case POINTER_PLUS_EXPR
:
2877 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
2878 copy_constant (TREE_OPERAND (exp
, 0)),
2879 copy_constant (TREE_OPERAND (exp
, 1)));
2882 case VIEW_CONVERT_EXPR
:
2883 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2884 copy_constant (TREE_OPERAND (exp
, 0)));
2887 return build_vector (TREE_TYPE (exp
),
2888 copy_list (TREE_VECTOR_CST_ELTS (exp
)));
2892 tree copy
= copy_node (exp
);
2893 VEC(constructor_elt
, gc
) *v
;
2894 unsigned HOST_WIDE_INT idx
;
2895 tree purpose
, value
;
2897 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
2898 CONSTRUCTOR_ELTS (exp
)));
2899 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
2901 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
2902 ce
->index
= purpose
;
2903 ce
->value
= copy_constant (value
);
2905 CONSTRUCTOR_ELTS (copy
) = v
;
2914 /* Return the section into which constant EXP should be placed. */
2917 get_constant_section (tree exp
, unsigned int align
)
2919 return targetm
.asm_out
.select_section (exp
,
2920 compute_reloc_for_constant (exp
),
2924 /* Return the size of constant EXP in bytes. */
2926 static HOST_WIDE_INT
2927 get_constant_size (tree exp
)
2931 size
= int_size_in_bytes (TREE_TYPE (exp
));
2932 if (TREE_CODE (exp
) == STRING_CST
)
2933 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
2937 /* Subroutine of output_constant_def:
2938 No constant equal to EXP is known to have been output.
2939 Make a constant descriptor to enter EXP in the hash table.
2940 Assign the label number and construct RTL to refer to the
2941 constant's location in memory.
2942 Caller is responsible for updating the hash table. */
2944 static struct constant_descriptor_tree
*
2945 build_constant_desc (tree exp
)
2947 struct constant_descriptor_tree
*desc
;
2953 desc
= ggc_alloc_constant_descriptor_tree ();
2954 desc
->value
= copy_constant (exp
);
2956 /* Propagate marked-ness to copied constant. */
2957 if (flag_mudflap
&& mf_marked_p (exp
))
2958 mf_mark (desc
->value
);
2960 /* Create a string containing the label name, in LABEL. */
2961 labelno
= const_labelno
++;
2962 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
2964 /* Construct the VAR_DECL associated with the constant. */
2965 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
2967 DECL_ARTIFICIAL (decl
) = 1;
2968 DECL_IGNORED_P (decl
) = 1;
2969 TREE_READONLY (decl
) = 1;
2970 TREE_STATIC (decl
) = 1;
2971 TREE_ADDRESSABLE (decl
) = 1;
2972 /* We don't set the RTL yet as this would cause varpool to assume that the
2973 variable is referenced. Moreover, it would just be dropped in LTO mode.
2974 Instead we set the flag that will be recognized in make_decl_rtl. */
2975 DECL_IN_CONSTANT_POOL (decl
) = 1;
2976 DECL_INITIAL (decl
) = desc
->value
;
2977 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
2978 architectures so use DATA_ALIGNMENT as well, except for strings. */
2979 if (TREE_CODE (exp
) == STRING_CST
)
2981 #ifdef CONSTANT_ALIGNMENT
2982 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
2986 align_variable (decl
, 0);
2988 /* Now construct the SYMBOL_REF and the MEM. */
2989 if (use_object_blocks_p ())
2991 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
2992 symbol
= create_block_symbol (ggc_strdup (label
),
2993 get_block_for_section (sect
), -1);
2996 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
2997 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
2998 SET_SYMBOL_REF_DECL (symbol
, decl
);
2999 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3001 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3002 set_mem_attributes (rtl
, exp
, 1);
3003 set_mem_alias_set (rtl
, 0);
3004 set_mem_alias_set (rtl
, const_alias_set
);
3006 /* We cannot share RTX'es in pool entries.
3007 Mark this piece of RTL as required for unsharing. */
3008 RTX_FLAG (rtl
, used
) = 1;
3010 /* Set flags or add text to the name to record information, such as
3011 that it is a local symbol. If the name is changed, the macro
3012 ASM_OUTPUT_LABELREF will have to know how to strip this
3013 information. This call might invalidate our local variable
3014 SYMBOL; we can't use it afterward. */
3015 targetm
.encode_section_info (exp
, rtl
, true);
3022 /* Return an rtx representing a reference to constant data in memory
3023 for the constant expression EXP.
3025 If assembler code for such a constant has already been output,
3026 return an rtx to refer to it.
3027 Otherwise, output such a constant in memory
3028 and generate an rtx for it.
3030 If DEFER is nonzero, this constant can be deferred and output only
3031 if referenced in the function after all optimizations.
3033 `const_desc_table' records which constants already have label strings. */
3036 output_constant_def (tree exp
, int defer
)
3038 struct constant_descriptor_tree
*desc
;
3039 struct constant_descriptor_tree key
;
3042 /* Look up EXP in the table of constant descriptors. If we didn't find
3043 it, create a new one. */
3045 key
.hash
= const_hash_1 (exp
);
3046 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3048 desc
= (struct constant_descriptor_tree
*) *loc
;
3051 desc
= build_constant_desc (exp
);
3052 desc
->hash
= key
.hash
;
3056 maybe_output_constant_def_contents (desc
, defer
);
3060 /* Subroutine of output_constant_def: Decide whether or not we need to
3061 output the constant DESC now, and if so, do it. */
3063 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3066 rtx symbol
= XEXP (desc
->rtl
, 0);
3067 tree exp
= desc
->value
;
3069 if (flag_syntax_only
)
3072 if (TREE_ASM_WRITTEN (exp
))
3073 /* Already output; don't do it again. */
3076 /* We can always defer constants as long as the context allows
3080 /* Increment n_deferred_constants if it exists. It needs to be at
3081 least as large as the number of constants actually referred to
3082 by the function. If it's too small we'll stop looking too early
3083 and fail to emit constants; if it's too large we'll only look
3084 through the entire function when we could have stopped earlier. */
3086 n_deferred_constants
++;
3090 output_constant_def_contents (symbol
);
3093 /* Subroutine of output_constant_def_contents. Output the definition
3094 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3095 constant's alignment in bits. */
3098 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3102 size
= get_constant_size (exp
);
3104 /* Do any machine/system dependent processing of the constant. */
3105 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3107 /* Output the value of EXP. */
3108 output_constant (exp
, size
, align
);
3111 /* We must output the constant data referred to by SYMBOL; do so. */
3114 output_constant_def_contents (rtx symbol
)
3116 tree decl
= SYMBOL_REF_DECL (symbol
);
3117 tree exp
= DECL_INITIAL (decl
);
3120 /* Make sure any other constants whose addresses appear in EXP
3121 are assigned label numbers. */
3122 output_addressed_constants (exp
);
3124 /* We are no longer deferring this constant. */
3125 TREE_ASM_WRITTEN (decl
) = TREE_ASM_WRITTEN (exp
) = 1;
3127 /* If the constant is part of an object block, make sure that the
3128 decl has been positioned within its block, but do not write out
3129 its definition yet. output_object_blocks will do that later. */
3130 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3131 place_block_symbol (symbol
);
3134 align
= DECL_ALIGN (decl
);
3135 switch_to_section (get_constant_section (exp
, align
));
3136 if (align
> BITS_PER_UNIT
)
3137 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3138 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3141 mudflap_enqueue_constant (exp
);
3144 /* Look up EXP in the table of constant descriptors. Return the rtl
3145 if it has been emitted, else null. */
3148 lookup_constant_def (tree exp
)
3150 struct constant_descriptor_tree
*desc
;
3151 struct constant_descriptor_tree key
;
3154 key
.hash
= const_hash_1 (exp
);
3155 desc
= (struct constant_descriptor_tree
*)
3156 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3158 return (desc
? desc
->rtl
: NULL_RTX
);
3161 /* Return a tree representing a reference to constant data in memory
3162 for the constant expression EXP.
3164 This is the counterpart of output_constant_def at the Tree level. */
3167 tree_output_constant_def (tree exp
)
3169 struct constant_descriptor_tree
*desc
, key
;
3173 /* Look up EXP in the table of constant descriptors. If we didn't find
3174 it, create a new one. */
3176 key
.hash
= const_hash_1 (exp
);
3177 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3179 desc
= (struct constant_descriptor_tree
*) *loc
;
3182 desc
= build_constant_desc (exp
);
3183 desc
->hash
= key
.hash
;
3187 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3188 varpool_finalize_decl (decl
);
3192 /* Used in the hash tables to avoid outputting the same constant
3193 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3194 are output once per function, not once per file. */
3195 /* ??? Only a few targets need per-function constant pools. Most
3196 can use one per-file pool. Should add a targetm bit to tell the
3199 struct GTY(()) rtx_constant_pool
{
3200 /* Pointers to first and last constant in pool, as ordered by offset. */
3201 struct constant_descriptor_rtx
*first
;
3202 struct constant_descriptor_rtx
*last
;
3204 /* Hash facility for making memory-constants from constant rtl-expressions.
3205 It is used on RISC machines where immediate integer arguments and
3206 constant addresses are restricted so that such constants must be stored
3208 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3210 /* Current offset in constant pool (does not include any
3211 machine-specific header). */
3212 HOST_WIDE_INT offset
;
3215 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3216 struct constant_descriptor_rtx
*next
;
3220 HOST_WIDE_INT offset
;
3222 enum machine_mode mode
;
3228 /* Hash and compare functions for const_rtx_htab. */
3231 const_desc_rtx_hash (const void *ptr
)
3233 const struct constant_descriptor_rtx
*const desc
3234 = (const struct constant_descriptor_rtx
*) ptr
;
3239 const_desc_rtx_eq (const void *a
, const void *b
)
3241 const struct constant_descriptor_rtx
*const x
3242 = (const struct constant_descriptor_rtx
*) a
;
3243 const struct constant_descriptor_rtx
*const y
3244 = (const struct constant_descriptor_rtx
*) b
;
3246 if (x
->mode
!= y
->mode
)
3248 return rtx_equal_p (x
->constant
, y
->constant
);
3251 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3254 const_rtx_hash_1 (rtx
*xp
, void *data
)
3256 unsigned HOST_WIDE_INT hwi
;
3257 enum machine_mode mode
;
3263 code
= GET_CODE (x
);
3264 mode
= GET_MODE (x
);
3265 h
= (hashval_t
) code
* 1048573 + mode
;
3273 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3274 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3277 h
^= (hashval_t
) hwi
;
3278 for (i
= 1; i
< n
; ++i
)
3281 h
^= (hashval_t
) hwi
;
3287 if (mode
== VOIDmode
)
3289 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3293 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3297 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3303 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3304 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3309 h
^= htab_hash_string (XSTR (x
, 0));
3313 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3317 case UNSPEC_VOLATILE
:
3318 h
= h
* 251 + XINT (x
, 1);
3325 hp
= (hashval_t
*) data
;
3326 *hp
= *hp
* 509 + h
;
3330 /* Compute a hash value for X, which should be a constant. */
3333 const_rtx_hash (rtx x
)
3336 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3341 /* Create and return a new rtx constant pool. */
3343 static struct rtx_constant_pool
*
3344 create_constant_pool (void)
3346 struct rtx_constant_pool
*pool
;
3348 pool
= ggc_alloc_rtx_constant_pool ();
3349 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3350 const_desc_rtx_eq
, NULL
);
3357 /* Initialize constant pool hashing for a new function. */
3360 init_varasm_status (void)
3362 crtl
->varasm
.pool
= create_constant_pool ();
3363 crtl
->varasm
.deferred_constants
= 0;
3366 /* Given a MINUS expression, simplify it if both sides
3367 include the same symbol. */
3370 simplify_subtraction (rtx x
)
3372 rtx r
= simplify_rtx (x
);
3376 /* Given a constant rtx X, make (or find) a memory constant for its value
3377 and return a MEM rtx to refer to it in memory. */
3380 force_const_mem (enum machine_mode mode
, rtx x
)
3382 struct constant_descriptor_rtx
*desc
, tmp
;
3383 struct rtx_constant_pool
*pool
;
3390 /* If we're not allowed to drop X into the constant pool, don't. */
3391 if (targetm
.cannot_force_const_mem (x
))
3394 /* Record that this function has used a constant pool entry. */
3395 crtl
->uses_const_pool
= 1;
3397 /* Decide which pool to use. */
3398 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3399 ? shared_constant_pool
3400 : crtl
->varasm
.pool
);
3402 /* Lookup the value in the hashtable. */
3405 hash
= const_rtx_hash (x
);
3406 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3407 desc
= (struct constant_descriptor_rtx
*) *slot
;
3409 /* If the constant was already present, return its memory. */
3411 return copy_rtx (desc
->mem
);
3413 /* Otherwise, create a new descriptor. */
3414 desc
= ggc_alloc_constant_descriptor_rtx ();
3417 /* Align the location counter as required by EXP's data type. */
3418 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3419 #ifdef CONSTANT_ALIGNMENT
3421 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3422 if (type
!= NULL_TREE
)
3423 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3427 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3428 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3431 desc
->constant
= tmp
.constant
;
3432 desc
->offset
= pool
->offset
;
3435 desc
->align
= align
;
3436 desc
->labelno
= const_labelno
;
3439 pool
->offset
+= GET_MODE_SIZE (mode
);
3441 pool
->last
->next
= desc
;
3443 pool
->first
= pool
->last
= desc
;
3446 /* Create a string containing the label name, in LABEL. */
3447 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3450 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3451 the constants pool. */
3452 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3454 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3455 symbol
= create_block_symbol (ggc_strdup (label
),
3456 get_block_for_section (sect
), -1);
3459 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3461 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3462 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3463 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3465 /* Construct the MEM. */
3466 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3467 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3468 set_mem_align (def
, align
);
3470 /* If we're dropping a label to the constant pool, make sure we
3472 if (GET_CODE (x
) == LABEL_REF
)
3473 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3475 return copy_rtx (def
);
3478 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3481 get_pool_constant (rtx addr
)
3483 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3486 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3487 and whether it has been output or not. */
3490 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3492 struct constant_descriptor_rtx
*desc
;
3494 desc
= SYMBOL_REF_CONSTANT (addr
);
3495 *pmarked
= (desc
->mark
!= 0);
3496 return desc
->constant
;
3499 /* Similar, return the mode. */
3502 get_pool_mode (const_rtx addr
)
3504 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3507 /* Return the size of the constant pool. */
3510 get_pool_size (void)
3512 return crtl
->varasm
.pool
->offset
;
3515 /* Worker function for output_constant_pool_1. Emit assembly for X
3516 in MODE with known alignment ALIGN. */
3519 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3521 switch (GET_MODE_CLASS (mode
))
3524 case MODE_DECIMAL_FLOAT
:
3528 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3529 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3530 assemble_real (r
, mode
, align
);
3535 case MODE_PARTIAL_INT
:
3540 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3543 case MODE_VECTOR_FLOAT
:
3544 case MODE_VECTOR_INT
:
3545 case MODE_VECTOR_FRACT
:
3546 case MODE_VECTOR_UFRACT
:
3547 case MODE_VECTOR_ACCUM
:
3548 case MODE_VECTOR_UACCUM
:
3551 enum machine_mode submode
= GET_MODE_INNER (mode
);
3552 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3554 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3555 units
= CONST_VECTOR_NUNITS (x
);
3557 for (i
= 0; i
< units
; i
++)
3559 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3560 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3570 /* Worker function for output_constant_pool. Emit constant DESC,
3571 giving it ALIGN bits of alignment. */
3574 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3581 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3582 whose CODE_LABEL has been deleted. This can occur if a jump table
3583 is eliminated by optimization. If so, write a constant of zero
3584 instead. Note that this can also happen by turning the
3585 CODE_LABEL into a NOTE. */
3586 /* ??? This seems completely and utterly wrong. Certainly it's
3587 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3588 functioning even with INSN_DELETED_P and friends. */
3591 switch (GET_CODE (tmp
))
3594 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3595 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3597 tmp
= XEXP (XEXP (tmp
, 0), 0);
3601 tmp
= XEXP (tmp
, 0);
3602 gcc_assert (!INSN_DELETED_P (tmp
));
3603 gcc_assert (!NOTE_P (tmp
)
3604 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3611 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3612 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3613 align
, desc
->labelno
, done
);
3616 assemble_align (align
);
3618 /* Output the label. */
3619 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3621 /* Output the data. */
3622 output_constant_pool_2 (desc
->mode
, x
, align
);
3624 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3625 sections have proper size. */
3626 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3628 && (in_section
->common
.flags
& SECTION_MERGE
))
3629 assemble_align (align
);
3631 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3637 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3638 to as used. Emit referenced deferred strings. This function can
3639 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3642 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
3644 rtx x
= *current_rtx
;
3646 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3649 if (CONSTANT_POOL_ADDRESS_P (x
))
3651 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3652 if (desc
->mark
== 0)
3655 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
3658 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3660 tree decl
= SYMBOL_REF_DECL (x
);
3661 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
3663 n_deferred_constants
--;
3664 output_constant_def_contents (x
);
3671 /* Look through appropriate parts of INSN, marking all entries in the
3672 constant pool which are actually being used. Entries that are only
3673 referenced by other constants are also marked as used. Emit
3674 deferred strings that are used. */
3677 mark_constants (rtx insn
)
3682 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3683 insns, not any notes that may be attached. We don't want to mark
3684 a constant just because it happens to appear in a REG_EQUIV note. */
3685 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3687 rtx seq
= PATTERN (insn
);
3688 int i
, n
= XVECLEN (seq
, 0);
3689 for (i
= 0; i
< n
; ++i
)
3691 rtx subinsn
= XVECEXP (seq
, 0, i
);
3692 if (INSN_P (subinsn
))
3693 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
3697 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
3700 /* Look through the instructions for this function, and mark all the
3701 entries in POOL which are actually being used. Emit deferred constants
3702 which have indeed been used. */
3705 mark_constant_pool (void)
3709 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
3712 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3713 mark_constants (insn
);
3715 for (link
= crtl
->epilogue_delay_list
;
3717 link
= XEXP (link
, 1))
3718 mark_constants (XEXP (link
, 0));
3721 /* Write all the constants in POOL. */
3724 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
3726 struct constant_descriptor_rtx
*desc
;
3728 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3731 /* If the constant is part of an object_block, make sure that
3732 the constant has been positioned within its block, but do not
3733 write out its definition yet. output_object_blocks will do
3735 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
3736 && SYMBOL_REF_BLOCK (desc
->sym
))
3737 place_block_symbol (desc
->sym
);
3740 switch_to_section (targetm
.asm_out
.select_rtx_section
3741 (desc
->mode
, desc
->constant
, desc
->align
));
3742 output_constant_pool_1 (desc
, desc
->align
);
3747 /* Mark all constants that are used in the current function, then write
3748 out the function's private constant pool. */
3751 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3752 tree fndecl ATTRIBUTE_UNUSED
)
3754 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
3756 /* It is possible for gcc to call force_const_mem and then to later
3757 discard the instructions which refer to the constant. In such a
3758 case we do not need to output the constant. */
3759 mark_constant_pool ();
3761 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3762 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3765 output_constant_pool_contents (pool
);
3767 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3768 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3772 /* Write the contents of the shared constant pool. */
3775 output_shared_constant_pool (void)
3777 output_constant_pool_contents (shared_constant_pool
);
3780 /* Determine what kind of relocations EXP may need. */
3783 compute_reloc_for_constant (tree exp
)
3785 int reloc
= 0, reloc2
;
3788 switch (TREE_CODE (exp
))
3792 /* Go inside any operations that get_inner_reference can handle and see
3793 if what's inside is a constant: no need to do anything here for
3794 addresses of variables or functions. */
3795 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3796 tem
= TREE_OPERAND (tem
, 0))
3799 if (TREE_PUBLIC (tem
))
3806 case POINTER_PLUS_EXPR
:
3807 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3808 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3812 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3813 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3814 /* The difference of two local labels is computable at link time. */
3815 if (reloc
== 1 && reloc2
== 1)
3822 case VIEW_CONVERT_EXPR
:
3823 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3828 unsigned HOST_WIDE_INT idx
;
3829 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3831 reloc
|= compute_reloc_for_constant (tem
);
3841 /* Find all the constants whose addresses are referenced inside of EXP,
3842 and make sure assembler code with a label has been output for each one.
3843 Indicate whether an ADDR_EXPR has been encountered. */
3846 output_addressed_constants (tree exp
)
3850 switch (TREE_CODE (exp
))
3854 /* Go inside any operations that get_inner_reference can handle and see
3855 if what's inside is a constant: no need to do anything here for
3856 addresses of variables or functions. */
3857 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3858 tem
= TREE_OPERAND (tem
, 0))
3861 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3862 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
3863 tem
= DECL_INITIAL (tem
);
3865 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
3866 output_constant_def (tem
, 0);
3870 case POINTER_PLUS_EXPR
:
3872 output_addressed_constants (TREE_OPERAND (exp
, 1));
3876 case VIEW_CONVERT_EXPR
:
3877 output_addressed_constants (TREE_OPERAND (exp
, 0));
3882 unsigned HOST_WIDE_INT idx
;
3883 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3885 output_addressed_constants (tem
);
3894 /* Whether a constructor CTOR is a valid static constant initializer if all
3895 its elements are. This used to be internal to initializer_constant_valid_p
3896 and has been exposed to let other functions like categorize_ctor_elements
3897 evaluate the property while walking a constructor for other purposes. */
3900 constructor_static_from_elts_p (const_tree ctor
)
3902 return (TREE_CONSTANT (ctor
)
3903 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
3904 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
)
3905 && !VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (ctor
)));
3908 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
3911 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
3912 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
3913 which are valid when ENDTYPE is an integer of any size; in
3914 particular, this does not accept a pointer minus a constant. This
3915 returns null_pointer_node if the VALUE is an absolute constant
3916 which can be used to initialize a static variable. Otherwise it
3920 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
3924 if (!INTEGRAL_TYPE_P (endtype
))
3927 op0
= TREE_OPERAND (value
, 0);
3928 op1
= TREE_OPERAND (value
, 1);
3930 /* Like STRIP_NOPS except allow the operand mode to widen. This
3931 works around a feature of fold that simplifies (int)(p1 - p2) to
3932 ((int)p1 - (int)p2) under the theory that the narrower operation
3935 while (CONVERT_EXPR_P (op0
)
3936 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
3938 tree inner
= TREE_OPERAND (op0
, 0);
3939 if (inner
== error_mark_node
3940 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3941 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
3942 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3947 while (CONVERT_EXPR_P (op1
)
3948 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
3950 tree inner
= TREE_OPERAND (op1
, 0);
3951 if (inner
== error_mark_node
3952 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3953 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
3954 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3959 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
3963 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
3964 cache
? cache
+ 2 : NULL
);
3965 /* Both initializers must be known. */
3969 && (op0
== null_pointer_node
3970 || TREE_CODE (value
) == MINUS_EXPR
))
3971 return null_pointer_node
;
3973 /* Support differences between labels. */
3974 if (TREE_CODE (op0
) == LABEL_DECL
3975 && TREE_CODE (op1
) == LABEL_DECL
)
3976 return null_pointer_node
;
3978 if (TREE_CODE (op0
) == STRING_CST
3979 && TREE_CODE (op1
) == STRING_CST
3980 && operand_equal_p (op0
, op1
, 1))
3981 return null_pointer_node
;
3987 /* Helper function of initializer_constant_valid_p.
3988 Return nonzero if VALUE is a valid constant-valued expression
3989 for use in initializing a static variable; one that can be an
3990 element of a "constant" initializer.
3992 Return null_pointer_node if the value is absolute;
3993 if it is relocatable, return the variable that determines the relocation.
3994 We assume that VALUE has been folded as much as possible;
3995 therefore, we do not need to check for such things as
3996 arithmetic-combinations of integers.
3998 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4001 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4005 switch (TREE_CODE (value
))
4008 if (constructor_static_from_elts_p (value
))
4010 unsigned HOST_WIDE_INT idx
;
4012 bool absolute
= true;
4014 if (cache
&& cache
[0] == value
)
4016 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4019 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4026 cache
[1] = NULL_TREE
;
4030 if (reloc
!= null_pointer_node
)
4033 /* For a non-absolute relocation, there is no single
4034 variable that can be "the variable that determines the
4039 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4041 return absolute
? null_pointer_node
: error_mark_node
;
4044 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4052 return null_pointer_node
;
4057 tree op0
= staticp (TREE_OPERAND (value
, 0));
4060 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4061 to be a constant, this is old-skool offsetof-like nonsense. */
4062 if (TREE_CODE (op0
) == INDIRECT_REF
4063 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4064 return null_pointer_node
;
4065 /* Taking the address of a nested function involves a trampoline,
4066 unless we don't need or want one. */
4067 if (TREE_CODE (op0
) == FUNCTION_DECL
4068 && DECL_STATIC_CHAIN (op0
)
4069 && !TREE_NO_TRAMPOLINE (value
))
4071 /* "&{...}" requires a temporary to hold the constructed
4073 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4079 case NON_LVALUE_EXPR
:
4080 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4083 case VIEW_CONVERT_EXPR
:
4085 tree src
= TREE_OPERAND (value
, 0);
4086 tree src_type
= TREE_TYPE (src
);
4087 tree dest_type
= TREE_TYPE (value
);
4089 /* Allow view-conversions from aggregate to non-aggregate type only
4090 if the bit pattern is fully preserved afterwards; otherwise, the
4091 RTL expander won't be able to apply a subsequent transformation
4092 to the underlying constructor. */
4093 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4095 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4096 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4101 /* Allow all other kinds of view-conversion. */
4102 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4107 tree src
= TREE_OPERAND (value
, 0);
4108 tree src_type
= TREE_TYPE (src
);
4109 tree dest_type
= TREE_TYPE (value
);
4111 /* Allow conversions between pointer types, floating-point
4112 types, and offset types. */
4113 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4114 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4115 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4116 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4117 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4119 /* Allow length-preserving conversions between integer types. */
4120 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4121 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4122 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4124 /* Allow conversions between other integer types only if
4126 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4128 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4129 if (inner
== null_pointer_node
)
4130 return null_pointer_node
;
4134 /* Allow (int) &foo provided int is as wide as a pointer. */
4135 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4136 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4137 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4139 /* Likewise conversions from int to pointers, but also allow
4140 conversions from 0. */
4141 if ((POINTER_TYPE_P (dest_type
)
4142 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4143 && INTEGRAL_TYPE_P (src_type
))
4145 if (TREE_CODE (src
) == INTEGER_CST
4146 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4147 return null_pointer_node
;
4148 if (integer_zerop (src
))
4149 return null_pointer_node
;
4150 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4151 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4154 /* Allow conversions to struct or union types if the value
4156 if (TREE_CODE (dest_type
) == RECORD_TYPE
4157 || TREE_CODE (dest_type
) == UNION_TYPE
)
4158 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4162 case POINTER_PLUS_EXPR
:
4164 /* Any valid floating-point constants will have been folded by now;
4165 with -frounding-math we hit this with addition of two constants. */
4166 if (TREE_CODE (endtype
) == REAL_TYPE
)
4168 if (cache
&& cache
[0] == value
)
4170 if (! INTEGRAL_TYPE_P (endtype
)
4171 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4173 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4175 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4178 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4179 endtype
, ncache
+ 2);
4180 /* If either term is absolute, use the other term's relocation. */
4181 if (valid0
== null_pointer_node
)
4183 else if (valid1
== null_pointer_node
)
4185 /* Support narrowing pointer differences. */
4187 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4191 /* Support narrowing pointer differences. */
4192 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4201 if (TREE_CODE (endtype
) == REAL_TYPE
)
4203 if (cache
&& cache
[0] == value
)
4205 if (! INTEGRAL_TYPE_P (endtype
)
4206 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4208 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4210 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4213 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4214 endtype
, ncache
+ 2);
4215 /* Win if second argument is absolute. */
4216 if (valid1
== null_pointer_node
)
4218 /* Win if both arguments have the same relocation.
4219 Then the value is absolute. */
4220 else if (valid0
== valid1
&& valid0
!= 0)
4221 ret
= null_pointer_node
;
4222 /* Since GCC guarantees that string constants are unique in the
4223 generated code, a subtraction between two copies of the same
4224 constant string is absolute. */
4225 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4226 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4227 && operand_equal_p (valid0
, valid1
, 1))
4228 ret
= null_pointer_node
;
4229 /* Support narrowing differences. */
4231 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4235 /* Support narrowing differences. */
4236 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4251 /* Return nonzero if VALUE is a valid constant-valued expression
4252 for use in initializing a static variable; one that can be an
4253 element of a "constant" initializer.
4255 Return null_pointer_node if the value is absolute;
4256 if it is relocatable, return the variable that determines the relocation.
4257 We assume that VALUE has been folded as much as possible;
4258 therefore, we do not need to check for such things as
4259 arithmetic-combinations of integers. */
4261 initializer_constant_valid_p (tree value
, tree endtype
)
4263 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4266 /* Return true if VALUE is a valid constant-valued expression
4267 for use in initializing a static bit-field; one that can be
4268 an element of a "constant" initializer. */
4271 initializer_constant_valid_for_bitfield_p (tree value
)
4273 /* For bitfields we support integer constants or possibly nested aggregates
4275 switch (TREE_CODE (value
))
4279 unsigned HOST_WIDE_INT idx
;
4282 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4283 if (!initializer_constant_valid_for_bitfield_p (elt
))
4291 case VIEW_CONVERT_EXPR
:
4292 case NON_LVALUE_EXPR
:
4294 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4303 /* output_constructor outer state of relevance in recursive calls, typically
4304 for nested aggregate bitfields. */
4307 unsigned int bit_offset
; /* current position in ... */
4308 int byte
; /* ... the outer byte buffer. */
4311 static unsigned HOST_WIDE_INT
4312 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4315 /* Output assembler code for constant EXP to FILE, with no label.
4316 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4317 Assumes output_addressed_constants has been done on EXP already.
4319 Generate exactly SIZE bytes of assembler data, padding at the end
4320 with zeros if necessary. SIZE must always be specified.
4322 SIZE is important for structure constructors,
4323 since trailing members may have been omitted from the constructor.
4324 It is also important for initialization of arrays from string constants
4325 since the full length of the string constant might not be wanted.
4326 It is also needed for initialization of unions, where the initializer's
4327 type is just one member, and that may not be as long as the union.
4329 There a case in which we would fail to output exactly SIZE bytes:
4330 for a structure constructor that wants to produce more than SIZE bytes.
4331 But such constructors will never be generated for any possible input.
4333 ALIGN is the alignment of the data in bits. */
4336 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4338 enum tree_code code
;
4339 unsigned HOST_WIDE_INT thissize
;
4341 if (size
== 0 || flag_syntax_only
)
4344 /* See if we're trying to initialize a pointer in a non-default mode
4345 to the address of some declaration somewhere. If the target says
4346 the mode is valid for pointers, assume the target has a way of
4348 if (TREE_CODE (exp
) == NOP_EXPR
4349 && POINTER_TYPE_P (TREE_TYPE (exp
))
4350 && targetm
.addr_space
.valid_pointer_mode
4351 (TYPE_MODE (TREE_TYPE (exp
)),
4352 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4354 tree saved_type
= TREE_TYPE (exp
);
4356 /* Peel off any intermediate conversions-to-pointer for valid
4358 while (TREE_CODE (exp
) == NOP_EXPR
4359 && POINTER_TYPE_P (TREE_TYPE (exp
))
4360 && targetm
.addr_space
.valid_pointer_mode
4361 (TYPE_MODE (TREE_TYPE (exp
)),
4362 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4363 exp
= TREE_OPERAND (exp
, 0);
4365 /* If what we're left with is the address of something, we can
4366 convert the address to the final type and output it that
4368 if (TREE_CODE (exp
) == ADDR_EXPR
)
4369 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4370 /* Likewise for constant ints. */
4371 else if (TREE_CODE (exp
) == INTEGER_CST
)
4372 exp
= build_int_cst_wide (saved_type
, TREE_INT_CST_LOW (exp
),
4373 TREE_INT_CST_HIGH (exp
));
4377 /* Eliminate any conversions since we'll be outputting the underlying
4379 while (CONVERT_EXPR_P (exp
)
4380 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4381 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4383 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4384 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4386 /* Make sure eliminating the conversion is really a no-op, except with
4387 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4388 union types to allow for Ada unchecked unions. */
4389 if (type_size
> op_size
4390 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4391 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4392 /* Keep the conversion. */
4395 exp
= TREE_OPERAND (exp
, 0);
4398 code
= TREE_CODE (TREE_TYPE (exp
));
4399 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4401 /* Allow a constructor with no elements for any data type.
4402 This means to fill the space with zeros. */
4403 if (TREE_CODE (exp
) == CONSTRUCTOR
4404 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
4406 assemble_zeros (size
);
4410 if (TREE_CODE (exp
) == FDESC_EXPR
)
4412 #ifdef ASM_OUTPUT_FDESC
4413 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4414 tree decl
= TREE_OPERAND (exp
, 0);
4415 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4422 /* Now output the underlying data. If we've handling the padding, return.
4423 Otherwise, break and ensure SIZE is the size written. */
4430 case REFERENCE_TYPE
:
4432 case FIXED_POINT_TYPE
:
4433 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4434 EXPAND_INITIALIZER
),
4435 MIN (size
, thissize
), align
, 0))
4436 error ("initializer for integer/fixed-point value is too complicated");
4440 if (TREE_CODE (exp
) != REAL_CST
)
4441 error ("initializer for floating value is not a floating constant");
4443 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4447 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4448 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4449 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4454 switch (TREE_CODE (exp
))
4457 output_constructor (exp
, size
, align
, NULL
);
4460 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
4462 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4469 unsigned int nalign
;
4470 enum machine_mode inner
;
4472 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4473 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4475 elt_size
= GET_MODE_SIZE (inner
);
4477 link
= TREE_VECTOR_CST_ELTS (exp
);
4478 output_constant (TREE_VALUE (link
), elt_size
, align
);
4479 thissize
= elt_size
;
4480 while ((link
= TREE_CHAIN (link
)) != NULL
)
4482 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
4483 thissize
+= elt_size
;
4494 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4495 output_constructor (exp
, size
, align
, NULL
);
4505 if (size
> thissize
)
4506 assemble_zeros (size
- thissize
);
4510 /* Subroutine of output_constructor, used for computing the size of
4511 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4512 type with an unspecified upper bound. */
4514 static unsigned HOST_WIDE_INT
4515 array_size_for_constructor (tree val
)
4518 unsigned HOST_WIDE_INT cnt
;
4519 tree index
, value
, tmp
;
4521 /* This code used to attempt to handle string constants that are not
4522 arrays of single-bytes, but nothing else does, so there's no point in
4524 if (TREE_CODE (val
) == STRING_CST
)
4525 return TREE_STRING_LENGTH (val
);
4527 max_index
= NULL_TREE
;
4528 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4530 if (TREE_CODE (index
) == RANGE_EXPR
)
4531 index
= TREE_OPERAND (index
, 1);
4532 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4536 if (max_index
== NULL_TREE
)
4539 /* Compute the total number of array elements. */
4540 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4541 i
= size_binop (MINUS_EXPR
, fold_convert (sizetype
, max_index
),
4542 fold_convert (sizetype
, tmp
));
4543 i
= size_binop (PLUS_EXPR
, i
, size_one_node
);
4545 /* Multiply by the array element unit size to find number of bytes. */
4546 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4548 return tree_low_cst (i
, 1);
4551 /* Other datastructures + helpers for output_constructor. */
4553 /* output_constructor local state to support interaction with helpers. */
4557 /* Received arguments. */
4558 tree exp
; /* Constructor expression. */
4559 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4560 unsigned int align
; /* Known initial alignment. */
4562 /* Constructor expression data. */
4563 tree type
; /* Expression type. */
4564 tree field
; /* Current field decl in a record. */
4565 tree min_index
; /* Lower bound if specified for an array. */
4567 /* Output processing state. */
4568 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4569 bool byte_buffer_in_use
; /* Whether byte ... */
4570 int byte
; /* ... contains part of a bitfield byte yet to
4573 int last_relative_index
; /* Implicit or explicit index of the last
4574 array element output within a bitfield. */
4575 /* Current element. */
4576 tree val
; /* Current element value. */
4577 tree index
; /* Current element index. */
4581 /* Helper for output_constructor. From the current LOCAL state, output a
4582 RANGE_EXPR element. */
4585 output_constructor_array_range (oc_local_state
*local
)
4587 unsigned HOST_WIDE_INT fieldsize
4588 = int_size_in_bytes (TREE_TYPE (local
->type
));
4590 HOST_WIDE_INT lo_index
4591 = tree_low_cst (TREE_OPERAND (local
->index
, 0), 0);
4592 HOST_WIDE_INT hi_index
4593 = tree_low_cst (TREE_OPERAND (local
->index
, 1), 0);
4594 HOST_WIDE_INT index
;
4597 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4599 for (index
= lo_index
; index
<= hi_index
; index
++)
4601 /* Output the element's initial value. */
4602 if (local
->val
== NULL_TREE
)
4603 assemble_zeros (fieldsize
);
4605 output_constant (local
->val
, fieldsize
, align2
);
4607 /* Count its size. */
4608 local
->total_bytes
+= fieldsize
;
4612 /* Helper for output_constructor. From the current LOCAL state, output a
4613 field element that is not true bitfield or part of an outer one. */
4616 output_constructor_regular_field (oc_local_state
*local
)
4618 /* Field size and position. Since this structure is static, we know the
4619 positions are constant. */
4620 unsigned HOST_WIDE_INT fieldsize
;
4621 HOST_WIDE_INT fieldpos
;
4623 unsigned int align2
;
4625 if (local
->index
!= NULL_TREE
)
4626 fieldpos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
)), 1)
4627 * ((tree_low_cst (local
->index
, 0)
4628 - tree_low_cst (local
->min_index
, 0))));
4629 else if (local
->field
!= NULL_TREE
)
4630 fieldpos
= int_byte_position (local
->field
);
4634 /* Output any buffered-up bit-fields preceding this element. */
4635 if (local
->byte_buffer_in_use
)
4637 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4638 local
->total_bytes
++;
4639 local
->byte_buffer_in_use
= false;
4642 /* Advance to offset of this element.
4643 Note no alignment needed in an array, since that is guaranteed
4644 if each element has the proper size. */
4645 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4646 && fieldpos
!= local
->total_bytes
)
4648 gcc_assert (fieldpos
>= local
->total_bytes
);
4649 assemble_zeros (fieldpos
- local
->total_bytes
);
4650 local
->total_bytes
= fieldpos
;
4653 /* Find the alignment of this element. */
4654 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
4656 /* Determine size this element should occupy. */
4661 /* If this is an array with an unspecified upper bound,
4662 the initializer determines the size. */
4663 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4664 but we cannot do this until the deprecated support for
4665 initializing zero-length array members is removed. */
4666 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
4667 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
4668 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
4670 fieldsize
= array_size_for_constructor (local
->val
);
4671 /* Given a non-empty initialization, this field had
4673 gcc_assert (!fieldsize
|| !DECL_CHAIN (local
->field
));
4675 else if (DECL_SIZE_UNIT (local
->field
))
4677 /* ??? This can't be right. If the decl size overflows
4678 a host integer we will silently emit no data. */
4679 if (host_integerp (DECL_SIZE_UNIT (local
->field
), 1))
4680 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (local
->field
), 1);
4684 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
4686 /* Output the element's initial value. */
4687 if (local
->val
== NULL_TREE
)
4688 assemble_zeros (fieldsize
);
4690 output_constant (local
->val
, fieldsize
, align2
);
4692 /* Count its size. */
4693 local
->total_bytes
+= fieldsize
;
4696 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4697 output an element that is a true bitfield or part of an outer one. */
4700 output_constructor_bitfield (oc_local_state
*local
, oc_outer_state
*outer
)
4702 /* Bit size of this element. */
4703 HOST_WIDE_INT ebitsize
4705 ? tree_low_cst (DECL_SIZE (local
->field
), 1)
4706 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local
->type
)), 1));
4708 /* Relative index of this element if this is an array component. */
4709 HOST_WIDE_INT relative_index
4712 ? (tree_low_cst (local
->index
, 0)
4713 - tree_low_cst (local
->min_index
, 0))
4714 : local
->last_relative_index
+ 1)
4717 /* Bit position of this element from the start of the containing
4719 HOST_WIDE_INT constructor_relative_ebitpos
4721 ? int_bit_position (local
->field
)
4722 : ebitsize
* relative_index
);
4724 /* Bit position of this element from the start of a possibly ongoing
4725 outer byte buffer. */
4726 HOST_WIDE_INT byte_relative_ebitpos
4727 = ((outer
? outer
->bit_offset
: 0) + constructor_relative_ebitpos
);
4729 /* From the start of a possibly ongoing outer byte buffer, offsets to
4730 the first bit of this element and to the first bit past the end of
4732 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
4733 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
4735 local
->last_relative_index
= relative_index
;
4737 if (local
->val
== NULL_TREE
)
4738 local
->val
= integer_zero_node
;
4740 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
4741 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
4742 local
->val
= TREE_OPERAND (local
->val
, 0);
4744 if (TREE_CODE (local
->val
) != INTEGER_CST
4745 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
4747 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
4751 /* If this field does not start in this (or, next) byte,
4753 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4755 /* Output remnant of any bit field in previous bytes. */
4756 if (local
->byte_buffer_in_use
)
4758 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4759 local
->total_bytes
++;
4760 local
->byte_buffer_in_use
= false;
4763 /* If still not at proper byte, advance to there. */
4764 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4766 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
4767 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
4768 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
4772 /* Set up the buffer if necessary. */
4773 if (!local
->byte_buffer_in_use
)
4777 local
->byte_buffer_in_use
= true;
4780 /* If this is nested constructor, recurse passing the bit offset and the
4781 pending data, then retrieve the new pending data afterwards. */
4782 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
4784 oc_outer_state output_state
;
4786 output_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
4787 output_state
.byte
= local
->byte
;
4789 += output_constructor (local
->val
, 0, 0, &output_state
);
4790 local
->byte
= output_state
.byte
;
4794 /* Otherwise, we must split the element into pieces that fall within
4795 separate bytes, and combine each byte with previous or following
4797 while (next_offset
< end_offset
)
4801 HOST_WIDE_INT value
;
4802 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4803 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4805 /* Advance from byte to byte
4806 within this element when necessary. */
4807 while (next_byte
!= local
->total_bytes
)
4809 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4810 local
->total_bytes
++;
4814 /* Number of bits we can process at once
4815 (all part of the same byte). */
4816 this_time
= MIN (end_offset
- next_offset
,
4817 BITS_PER_UNIT
- next_bit
);
4818 if (BYTES_BIG_ENDIAN
)
4820 /* On big-endian machine, take the most significant bits
4821 first (of the bits that are significant)
4822 and put them into bytes from the most significant end. */
4823 shift
= end_offset
- next_offset
- this_time
;
4825 /* Don't try to take a bunch of bits that cross
4826 the word boundary in the INTEGER_CST. We can
4827 only select bits from the LOW or HIGH part
4829 if (shift
< HOST_BITS_PER_WIDE_INT
4830 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4832 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4833 shift
= HOST_BITS_PER_WIDE_INT
;
4836 /* Now get the bits from the appropriate constant word. */
4837 if (shift
< HOST_BITS_PER_WIDE_INT
)
4838 value
= TREE_INT_CST_LOW (local
->val
);
4841 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4842 value
= TREE_INT_CST_HIGH (local
->val
);
4843 shift
-= HOST_BITS_PER_WIDE_INT
;
4846 /* Get the result. This works only when:
4847 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4848 local
->byte
|= (((value
>> shift
)
4849 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4850 << (BITS_PER_UNIT
- this_time
- next_bit
));
4854 /* On little-endian machines,
4855 take first the least significant bits of the value
4856 and pack them starting at the least significant
4857 bits of the bytes. */
4858 shift
= next_offset
- byte_relative_ebitpos
;
4860 /* Don't try to take a bunch of bits that cross
4861 the word boundary in the INTEGER_CST. We can
4862 only select bits from the LOW or HIGH part
4864 if (shift
< HOST_BITS_PER_WIDE_INT
4865 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4866 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4868 /* Now get the bits from the appropriate constant word. */
4869 if (shift
< HOST_BITS_PER_WIDE_INT
)
4870 value
= TREE_INT_CST_LOW (local
->val
);
4873 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4874 value
= TREE_INT_CST_HIGH (local
->val
);
4875 shift
-= HOST_BITS_PER_WIDE_INT
;
4878 /* Get the result. This works only when:
4879 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4880 local
->byte
|= (((value
>> shift
)
4881 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4885 next_offset
+= this_time
;
4886 local
->byte_buffer_in_use
= true;
4890 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4891 Generate at least SIZE bytes, padding if necessary. OUTER designates the
4892 caller output state of relevance in recursive invocations. */
4894 static unsigned HOST_WIDE_INT
4895 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
4896 unsigned int align
, oc_outer_state
* outer
)
4898 unsigned HOST_WIDE_INT cnt
;
4899 constructor_elt
*ce
;
4901 oc_local_state local
;
4903 /* Setup our local state to communicate with helpers. */
4906 local
.align
= align
;
4908 local
.total_bytes
= 0;
4909 local
.byte_buffer_in_use
= outer
!= NULL
;
4910 local
.byte
= outer
? outer
->byte
: 0;
4912 local
.type
= TREE_TYPE (exp
);
4914 local
.last_relative_index
= -1;
4916 local
.min_index
= NULL_TREE
;
4917 if (TREE_CODE (local
.type
) == ARRAY_TYPE
4918 && TYPE_DOMAIN (local
.type
) != NULL_TREE
)
4919 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
4921 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
4923 /* As CE goes through the elements of the constant, FIELD goes through the
4924 structure fields if the constant is a structure. If the constant is a
4925 union, we override this by getting the field from the TREE_LIST element.
4926 But the constant could also be an array. Then FIELD is zero.
4928 There is always a maximum of one element in the chain LINK for unions
4929 (even if the initializer in a source program incorrectly contains
4932 local
.field
= NULL_TREE
;
4933 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
4934 local
.field
= TYPE_FIELDS (local
.type
);
4937 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
4938 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
4940 local
.val
= ce
->value
;
4941 local
.index
= NULL_TREE
;
4943 /* The element in a union constructor specifies the proper field
4945 if ((TREE_CODE (local
.type
) == RECORD_TYPE
4946 || TREE_CODE (local
.type
) == UNION_TYPE
4947 || TREE_CODE (local
.type
) == QUAL_UNION_TYPE
)
4948 && ce
->index
!= NULL_TREE
)
4949 local
.field
= ce
->index
;
4951 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
4952 local
.index
= ce
->index
;
4954 #ifdef ASM_COMMENT_START
4955 if (local
.field
&& flag_verbose_asm
)
4956 fprintf (asm_out_file
, "%s %s:\n",
4958 DECL_NAME (local
.field
)
4959 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
4963 /* Eliminate the marker that makes a cast not be an lvalue. */
4964 if (local
.val
!= NULL_TREE
)
4965 STRIP_NOPS (local
.val
);
4967 /* Output the current element, using the appropriate helper ... */
4969 /* For an array slice not part of an outer bitfield. */
4971 && local
.index
!= NULL_TREE
4972 && TREE_CODE (local
.index
) == RANGE_EXPR
)
4973 output_constructor_array_range (&local
);
4975 /* For a field that is neither a true bitfield nor part of an outer one,
4976 known to be at least byte aligned and multiple-of-bytes long. */
4978 && (local
.field
== NULL_TREE
4979 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
4980 output_constructor_regular_field (&local
);
4982 /* For a true bitfield or part of an outer one. */
4984 output_constructor_bitfield (&local
, outer
);
4987 /* If we are not at toplevel, save the pending data for our caller.
4988 Otherwise output the pending data and padding zeros as needed. */
4990 outer
->byte
= local
.byte
;
4993 if (local
.byte_buffer_in_use
)
4995 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
4996 local
.total_bytes
++;
4999 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5001 assemble_zeros (local
.size
- local
.total_bytes
);
5002 local
.total_bytes
= local
.size
;
5006 return local
.total_bytes
;
5009 /* Mark DECL as weak. */
5012 mark_weak (tree decl
)
5014 DECL_WEAK (decl
) = 1;
5016 if (DECL_RTL_SET_P (decl
)
5017 && MEM_P (DECL_RTL (decl
))
5018 && XEXP (DECL_RTL (decl
), 0)
5019 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5020 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5023 /* Merge weak status between NEWDECL and OLDDECL. */
5026 merge_weak (tree newdecl
, tree olddecl
)
5028 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5030 if (DECL_WEAK (newdecl
) && SUPPORTS_WEAK
)
5033 /* We put the NEWDECL on the weak_decls list at some point
5034 and OLDDECL as well. Keep just OLDDECL on the list. */
5035 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5036 if (TREE_VALUE (*pwd
) == newdecl
)
5038 *pwd
= TREE_CHAIN (*pwd
);
5045 if (DECL_WEAK (newdecl
))
5049 /* NEWDECL is weak, but OLDDECL is not. */
5051 /* If we already output the OLDDECL, we're in trouble; we can't
5052 go back and make it weak. This error cannot be caught in
5053 declare_weak because the NEWDECL and OLDDECL was not yet
5054 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5055 if (TREE_ASM_WRITTEN (olddecl
))
5056 error ("weak declaration of %q+D must precede definition",
5059 /* If we've already generated rtl referencing OLDDECL, we may
5060 have done so in a way that will not function properly with
5062 else if (TREE_USED (olddecl
)
5063 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
5064 warning (0, "weak declaration of %q+D after first use results "
5065 "in unspecified behavior", newdecl
);
5069 /* We put the NEWDECL on the weak_decls list at some point.
5070 Replace it with the OLDDECL. */
5071 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5072 if (TREE_VALUE (wd
) == newdecl
)
5074 TREE_VALUE (wd
) = olddecl
;
5077 /* We may not find the entry on the list. If NEWDECL is a
5078 weak alias, then we will have already called
5079 globalize_decl to remove the entry; in that case, we do
5080 not need to do anything. */
5083 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5084 mark_weak (olddecl
);
5087 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5088 weak. Just update NEWDECL to indicate that it's weak too. */
5089 mark_weak (newdecl
);
5092 /* Declare DECL to be a weak symbol. */
5095 declare_weak (tree decl
)
5097 if (! TREE_PUBLIC (decl
))
5098 error ("weak declaration of %q+D must be public", decl
);
5099 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
5100 error ("weak declaration of %q+D must precede definition", decl
);
5101 else if (!SUPPORTS_WEAK
)
5102 warning (0, "weak declaration of %q+D not supported", decl
);
5105 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5106 DECL_ATTRIBUTES (decl
)
5107 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5111 weak_finish_1 (tree decl
)
5113 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5114 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5117 if (! TREE_USED (decl
))
5120 #ifdef ASM_WEAKEN_DECL
5121 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5123 #ifdef ASM_WEAKEN_LABEL
5124 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5126 #ifdef ASM_OUTPUT_WEAK_ALIAS
5128 static bool warn_once
= 0;
5131 warning (0, "only weak aliases are supported in this configuration");
5141 /* This TREE_LIST contains weakref targets. */
5143 static GTY(()) tree weakref_targets
;
5145 /* Forward declaration. */
5146 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
5148 /* Emit any pending weak declarations. */
5155 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5157 tree alias_decl
= TREE_PURPOSE (t
);
5158 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5160 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5161 /* Remove alias_decl from the weak list, but leave entries for
5162 the target alone. */
5164 #ifndef ASM_OUTPUT_WEAKREF
5165 else if (! TREE_SYMBOL_REFERENCED (target
))
5167 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5168 defined, otherwise we and weak_finish_1 would use
5169 different macros. */
5170 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5171 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5173 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
5177 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5178 TREE_CODE (alias_decl
), target
,
5179 TREE_TYPE (alias_decl
));
5181 DECL_EXTERNAL (decl
) = 1;
5182 TREE_PUBLIC (decl
) = 1;
5183 DECL_ARTIFICIAL (decl
) = 1;
5184 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5185 TREE_USED (decl
) = 1;
5188 weak_finish_1 (decl
);
5197 /* Remove the alias and the target from the pending weak list
5198 so that we do not emit any .weak directives for the former,
5199 nor multiple .weak directives for the latter. */
5200 for (p
= &weak_decls
; (t2
= *p
) ; )
5202 if (TREE_VALUE (t2
) == alias_decl
5203 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5204 *p
= TREE_CHAIN (t2
);
5206 p
= &TREE_CHAIN (t2
);
5209 /* Remove other weakrefs to the same target, to speed things up. */
5210 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5212 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5213 *p
= TREE_CHAIN (t2
);
5215 p
= &TREE_CHAIN (t2
);
5220 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5222 tree decl
= TREE_VALUE (t
);
5224 weak_finish_1 (decl
);
5228 /* Emit the assembly bits to indicate that DECL is globally visible. */
5231 globalize_decl (tree decl
)
5234 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5235 if (DECL_WEAK (decl
))
5237 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5240 #ifdef ASM_WEAKEN_DECL
5241 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5243 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5246 /* Remove this function from the pending weak list so that
5247 we do not emit multiple .weak directives for it. */
5248 for (p
= &weak_decls
; (t
= *p
) ; )
5250 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5251 *p
= TREE_CHAIN (t
);
5253 p
= &TREE_CHAIN (t
);
5256 /* Remove weakrefs to the same target from the pending weakref
5257 list, for the same reason. */
5258 for (p
= &weakref_targets
; (t
= *p
) ; )
5260 if (DECL_ASSEMBLER_NAME (decl
)
5261 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5262 *p
= TREE_CHAIN (t
);
5264 p
= &TREE_CHAIN (t
);
5271 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5274 VEC(alias_pair
,gc
) *alias_pairs
;
5276 /* Given an assembly name, find the decl it is associated with. At the
5277 same time, mark it needed for cgraph. */
5280 find_decl_and_mark_needed (tree decl
, tree target
)
5282 struct cgraph_node
*fnode
= NULL
;
5283 struct varpool_node
*vnode
= NULL
;
5285 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5287 fnode
= cgraph_node_for_asm (target
);
5289 vnode
= varpool_node_for_asm (target
);
5293 vnode
= varpool_node_for_asm (target
);
5295 fnode
= cgraph_node_for_asm (target
);
5300 cgraph_mark_needed_node (fnode
);
5305 varpool_mark_needed_node (vnode
);
5306 vnode
->force_output
= 1;
5313 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5314 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5315 tree node is DECL to have the value of the tree node TARGET. */
5318 do_assemble_alias (tree decl
, tree target
)
5320 /* Emulated TLS had better not get this var. */
5321 gcc_assert(!(!targetm
.have_tls
5322 && TREE_CODE (decl
) == VAR_DECL
5323 && DECL_THREAD_LOCAL_P (decl
)));
5325 if (TREE_ASM_WRITTEN (decl
))
5328 /* We must force creation of DECL_RTL for debug info generation, even though
5329 we don't use it here. */
5330 make_decl_rtl (decl
);
5332 TREE_ASM_WRITTEN (decl
) = 1;
5333 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5335 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5337 ultimate_transparent_alias_target (&target
);
5339 if (!TREE_SYMBOL_REFERENCED (target
))
5340 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5342 #ifdef ASM_OUTPUT_WEAKREF
5343 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5344 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5345 IDENTIFIER_POINTER (target
));
5349 error_at (DECL_SOURCE_LOCATION (decl
),
5350 "weakref is not supported in this configuration");
5357 #ifdef ASM_OUTPUT_DEF
5358 /* Make name accessible from other files, if appropriate. */
5360 if (TREE_PUBLIC (decl
))
5362 globalize_decl (decl
);
5363 maybe_assemble_visibility (decl
);
5365 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5367 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
5368 ASM_OUTPUT_TYPE_DIRECTIVE
5369 (asm_out_file
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5372 error_at (DECL_SOURCE_LOCATION (decl
),
5373 "ifunc is not supported in this configuration");
5377 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5378 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5380 ASM_OUTPUT_DEF (asm_out_file
,
5381 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5382 IDENTIFIER_POINTER (target
));
5384 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5389 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5390 # ifdef ASM_WEAKEN_DECL
5391 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5393 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5395 /* Remove this function from the pending weak list so that
5396 we do not emit multiple .weak directives for it. */
5397 for (p
= &weak_decls
; (t
= *p
) ; )
5398 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5399 *p
= TREE_CHAIN (t
);
5401 p
= &TREE_CHAIN (t
);
5403 /* Remove weakrefs to the same target from the pending weakref
5404 list, for the same reason. */
5405 for (p
= &weakref_targets
; (t
= *p
) ; )
5407 if (DECL_ASSEMBLER_NAME (decl
)
5408 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5409 *p
= TREE_CHAIN (t
);
5411 p
= &TREE_CHAIN (t
);
5418 /* Remove the alias pairing for functions that are no longer in the call
5422 remove_unreachable_alias_pairs (void)
5427 if (alias_pairs
== NULL
)
5430 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); )
5432 if (!DECL_EXTERNAL (p
->decl
))
5434 struct cgraph_node
*fnode
= NULL
;
5435 struct varpool_node
*vnode
= NULL
;
5436 fnode
= cgraph_node_for_asm (p
->target
);
5437 vnode
= (fnode
== NULL
) ? varpool_node_for_asm (p
->target
) : NULL
;
5438 if (fnode
== NULL
&& vnode
== NULL
)
5440 VEC_unordered_remove (alias_pair
, alias_pairs
, i
);
5450 /* First pass of completing pending aliases. Make sure that cgraph knows
5451 which symbols will be required. */
5454 finish_aliases_1 (void)
5459 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5463 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
5464 if (target_decl
== NULL
)
5466 if (! (p
->emitted_diags
& ALIAS_DIAG_TO_UNDEF
)
5467 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5469 error ("%q+D aliased to undefined symbol %qE",
5470 p
->decl
, p
->target
);
5471 p
->emitted_diags
|= ALIAS_DIAG_TO_UNDEF
;
5474 else if (! (p
->emitted_diags
& ALIAS_DIAG_TO_EXTERN
)
5475 && DECL_EXTERNAL (target_decl
)
5476 /* We use local aliases for C++ thunks to force the tailcall
5477 to bind locally. This is a hack - to keep it working do
5478 the following (which is not strictly correct). */
5479 && (! TREE_CODE (target_decl
) == FUNCTION_DECL
5480 || ! DECL_VIRTUAL_P (target_decl
))
5481 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5483 error ("%q+D aliased to external symbol %qE",
5484 p
->decl
, p
->target
);
5485 p
->emitted_diags
|= ALIAS_DIAG_TO_EXTERN
;
5490 /* Second pass of completing pending aliases. Emit the actual assembly.
5491 This happens at the end of compilation and thus it is assured that the
5492 target symbol has been emitted. */
5495 finish_aliases_2 (void)
5500 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5501 do_assemble_alias (p
->decl
, p
->target
);
5503 VEC_truncate (alias_pair
, alias_pairs
, 0);
5506 /* Emit an assembler directive to make the symbol for DECL an alias to
5507 the symbol for TARGET. */
5510 assemble_alias (tree decl
, tree target
)
5513 bool is_weakref
= false;
5515 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5517 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5521 ultimate_transparent_alias_target (&target
);
5523 if (alias
== target
)
5524 error ("weakref %q+D ultimately targets itself", decl
);
5527 #ifndef ASM_OUTPUT_WEAKREF
5528 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
5529 TREE_CHAIN (alias
) = target
;
5532 if (TREE_PUBLIC (decl
))
5533 error ("weakref %q+D must have static linkage", decl
);
5537 #if !defined (ASM_OUTPUT_DEF)
5538 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5539 error_at (DECL_SOURCE_LOCATION (decl
),
5540 "alias definitions not supported in this configuration");
5543 if (!DECL_WEAK (decl
))
5545 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
5546 error_at (DECL_SOURCE_LOCATION (decl
),
5547 "ifunc is not supported in this configuration");
5549 error_at (DECL_SOURCE_LOCATION (decl
),
5550 "only weak aliases are supported in this configuration");
5556 TREE_USED (decl
) = 1;
5558 /* A quirk of the initial implementation of aliases required that the user
5559 add "extern" to all of them. Which is silly, but now historical. Do
5560 note that the symbol is in fact locally defined. */
5562 DECL_EXTERNAL (decl
) = 0;
5564 /* Allow aliases to aliases. */
5565 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5566 cgraph_node (decl
)->alias
= true;
5568 varpool_node (decl
)->alias
= true;
5570 /* If the target has already been emitted, we don't have to queue the
5571 alias. This saves a tad of memory. */
5572 if (cgraph_global_info_ready
)
5573 target_decl
= find_decl_and_mark_needed (decl
, target
);
5576 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5577 do_assemble_alias (decl
, target
);
5580 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
5583 p
->emitted_diags
= ALIAS_DIAG_NONE
;
5587 /* Emit an assembler directive to set symbol for DECL visibility to
5588 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5591 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5592 int vis ATTRIBUTE_UNUSED
)
5594 #ifdef HAVE_GAS_HIDDEN
5595 static const char * const visibility_types
[] = {
5596 NULL
, "protected", "hidden", "internal"
5599 const char *name
, *type
;
5601 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5602 type
= visibility_types
[vis
];
5604 fprintf (asm_out_file
, "\t.%s\t", type
);
5605 assemble_name (asm_out_file
, name
);
5606 fprintf (asm_out_file
, "\n");
5608 warning (OPT_Wattributes
, "visibility attribute not supported "
5609 "in this configuration; ignored");
5613 /* A helper function to call assemble_visibility when needed for a decl. */
5616 maybe_assemble_visibility (tree decl
)
5618 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5620 if (vis
!= VISIBILITY_DEFAULT
)
5622 targetm
.asm_out
.assemble_visibility (decl
, vis
);
5629 /* Returns 1 if the target configuration supports defining public symbols
5630 so that one of them will be chosen at link time instead of generating a
5631 multiply-defined symbol error, whether through the use of weak symbols or
5632 a target-specific mechanism for having duplicates discarded. */
5635 supports_one_only (void)
5637 if (SUPPORTS_ONE_ONLY
)
5639 return SUPPORTS_WEAK
;
5642 /* Set up DECL as a public symbol that can be defined in multiple
5643 translation units without generating a linker error. */
5646 make_decl_one_only (tree decl
, tree comdat_group
)
5648 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5649 || TREE_CODE (decl
) == FUNCTION_DECL
);
5651 TREE_PUBLIC (decl
) = 1;
5653 if (SUPPORTS_ONE_ONLY
)
5655 #ifdef MAKE_DECL_ONE_ONLY
5656 MAKE_DECL_ONE_ONLY (decl
);
5658 DECL_COMDAT_GROUP (decl
) = comdat_group
;
5660 else if (TREE_CODE (decl
) == VAR_DECL
5661 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5662 DECL_COMMON (decl
) = 1;
5665 gcc_assert (SUPPORTS_WEAK
);
5666 DECL_WEAK (decl
) = 1;
5671 init_varasm_once (void)
5673 section_htab
= htab_create_ggc (31, section_entry_hash
,
5674 section_entry_eq
, NULL
);
5675 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
5676 object_block_entry_eq
, NULL
);
5677 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
5678 const_desc_eq
, NULL
);
5680 const_alias_set
= new_alias_set ();
5681 shared_constant_pool
= create_constant_pool ();
5683 #ifdef TEXT_SECTION_ASM_OP
5684 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
5685 TEXT_SECTION_ASM_OP
);
5688 #ifdef DATA_SECTION_ASM_OP
5689 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5690 DATA_SECTION_ASM_OP
);
5693 #ifdef SDATA_SECTION_ASM_OP
5694 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5695 SDATA_SECTION_ASM_OP
);
5698 #ifdef READONLY_DATA_SECTION_ASM_OP
5699 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
5700 READONLY_DATA_SECTION_ASM_OP
);
5703 #ifdef CTORS_SECTION_ASM_OP
5704 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
5705 CTORS_SECTION_ASM_OP
);
5708 #ifdef DTORS_SECTION_ASM_OP
5709 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
5710 DTORS_SECTION_ASM_OP
);
5713 #ifdef BSS_SECTION_ASM_OP
5714 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5715 output_section_asm_op
,
5716 BSS_SECTION_ASM_OP
);
5719 #ifdef SBSS_SECTION_ASM_OP
5720 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5721 output_section_asm_op
,
5722 SBSS_SECTION_ASM_OP
);
5725 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5726 | SECTION_COMMON
, emit_tls_common
);
5727 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5728 | SECTION_COMMON
, emit_local
);
5729 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5730 | SECTION_COMMON
, emit_common
);
5732 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5733 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
5737 targetm
.asm_out
.init_sections ();
5739 if (readonly_data_section
== NULL
)
5740 readonly_data_section
= text_section
;
5744 decl_default_tls_model (const_tree decl
)
5746 enum tls_model kind
;
5749 is_local
= targetm
.binds_local_p (decl
);
5753 kind
= TLS_MODEL_LOCAL_EXEC
;
5755 kind
= TLS_MODEL_INITIAL_EXEC
;
5758 /* Local dynamic is inefficient when we're not combining the
5759 parts of the address. */
5760 else if (optimize
&& is_local
)
5761 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
5763 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
5764 if (kind
< flag_tls_default
)
5765 kind
= flag_tls_default
;
5770 /* Select a set of attributes for section NAME based on the properties
5771 of DECL and whether or not RELOC indicates that DECL's initializer
5772 might contain runtime relocations.
5774 We make the section read-only and executable for a function decl,
5775 read-only for a const data decl, and writable for a non-const data decl. */
5778 default_section_type_flags (tree decl
, const char *name
, int reloc
)
5782 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
5783 flags
= SECTION_CODE
;
5784 else if (decl
&& decl_readonly_section (decl
, reloc
))
5786 else if (current_function_decl
5788 && crtl
->subsections
.unlikely_text_section_name
5789 && strcmp (name
, crtl
->subsections
.unlikely_text_section_name
) == 0)
5790 flags
= SECTION_CODE
;
5792 && (!current_function_decl
|| !cfun
)
5793 && strcmp (name
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
5794 flags
= SECTION_CODE
;
5796 flags
= SECTION_WRITE
;
5798 if (decl
&& DECL_ONE_ONLY (decl
))
5799 flags
|= SECTION_LINKONCE
;
5801 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
5802 flags
|= SECTION_TLS
| SECTION_WRITE
;
5804 if (strcmp (name
, ".bss") == 0
5805 || strncmp (name
, ".bss.", 5) == 0
5806 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
5807 || strcmp (name
, ".sbss") == 0
5808 || strncmp (name
, ".sbss.", 6) == 0
5809 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
5810 flags
|= SECTION_BSS
;
5812 if (strcmp (name
, ".tdata") == 0
5813 || strncmp (name
, ".tdata.", 7) == 0
5814 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
5815 flags
|= SECTION_TLS
;
5817 if (strcmp (name
, ".tbss") == 0
5818 || strncmp (name
, ".tbss.", 6) == 0
5819 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
5820 flags
|= SECTION_TLS
| SECTION_BSS
;
5822 /* These three sections have special ELF types. They are neither
5823 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
5824 want to print a section type (@progbits or @nobits). If someone
5825 is silly enough to emit code or TLS variables to one of these
5826 sections, then don't handle them specially. */
5827 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
5828 && (strcmp (name
, ".init_array") == 0
5829 || strcmp (name
, ".fini_array") == 0
5830 || strcmp (name
, ".preinit_array") == 0))
5831 flags
|= SECTION_NOTYPE
;
5836 /* Return true if the target supports some form of global BSS,
5837 either through bss_noswitch_section, or by selecting a BSS
5838 section in TARGET_ASM_SELECT_SECTION. */
5841 have_global_bss_p (void)
5843 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
5846 /* Output assembly to switch to section NAME with attribute FLAGS.
5847 Four variants for common object file formats. */
5850 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
5851 unsigned int flags ATTRIBUTE_UNUSED
,
5852 tree decl ATTRIBUTE_UNUSED
)
5854 /* Some object formats don't support named sections at all. The
5855 front-end should already have flagged this as an error. */
5859 #ifndef TLS_SECTION_ASM_FLAG
5860 #define TLS_SECTION_ASM_FLAG 'T'
5864 default_elf_asm_named_section (const char *name
, unsigned int flags
,
5865 tree decl ATTRIBUTE_UNUSED
)
5867 char flagchars
[10], *f
= flagchars
;
5869 /* If we have already declared this section, we can use an
5870 abbreviated form to switch back to it -- unless this section is
5871 part of a COMDAT groups, in which case GAS requires the full
5872 declaration every time. */
5873 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5874 && (flags
& SECTION_DECLARED
))
5876 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
5880 if (!(flags
& SECTION_DEBUG
))
5882 if (flags
& SECTION_WRITE
)
5884 if (flags
& SECTION_CODE
)
5886 if (flags
& SECTION_SMALL
)
5888 if (flags
& SECTION_MERGE
)
5890 if (flags
& SECTION_STRINGS
)
5892 if (flags
& SECTION_TLS
)
5893 *f
++ = TLS_SECTION_ASM_FLAG
;
5894 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5898 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
5900 if (!(flags
& SECTION_NOTYPE
))
5905 if (flags
& SECTION_BSS
)
5911 #ifdef ASM_COMMENT_START
5912 /* On platforms that use "@" as the assembly comment character,
5914 if (strcmp (ASM_COMMENT_START
, "@") == 0)
5917 fprintf (asm_out_file
, format
, type
);
5919 if (flags
& SECTION_ENTSIZE
)
5920 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
5921 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5923 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
5924 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
5926 fprintf (asm_out_file
, ",%s,comdat",
5927 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
5931 putc ('\n', asm_out_file
);
5935 default_coff_asm_named_section (const char *name
, unsigned int flags
,
5936 tree decl ATTRIBUTE_UNUSED
)
5938 char flagchars
[8], *f
= flagchars
;
5940 if (flags
& SECTION_WRITE
)
5942 if (flags
& SECTION_CODE
)
5946 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
5950 default_pe_asm_named_section (const char *name
, unsigned int flags
,
5953 default_coff_asm_named_section (name
, flags
, decl
);
5955 if (flags
& SECTION_LINKONCE
)
5957 /* Functions may have been compiled at various levels of
5958 optimization so we can't use `same_size' here.
5959 Instead, have the linker pick one. */
5960 fprintf (asm_out_file
, "\t.linkonce %s\n",
5961 (flags
& SECTION_CODE
? "discard" : "same_size"));
5965 /* The lame default section selector. */
5968 default_select_section (tree decl
, int reloc
,
5969 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
5973 if (decl_readonly_section (decl
, reloc
))
5974 return readonly_data_section
;
5976 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5978 if (! ((flag_pic
&& reloc
)
5979 || !TREE_READONLY (decl
)
5980 || TREE_SIDE_EFFECTS (decl
)
5981 || !TREE_CONSTANT (decl
)))
5982 return readonly_data_section
;
5984 else if (TREE_CODE (decl
) == STRING_CST
)
5985 return readonly_data_section
;
5986 else if (! (flag_pic
&& reloc
))
5987 return readonly_data_section
;
5989 return data_section
;
5992 enum section_category
5993 categorize_decl_for_section (const_tree decl
, int reloc
)
5995 enum section_category ret
;
5997 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5999 else if (TREE_CODE (decl
) == STRING_CST
)
6001 if (flag_mudflap
) /* or !flag_merge_constants */
6002 return SECCAT_RODATA
;
6004 return SECCAT_RODATA_MERGE_STR
;
6006 else if (TREE_CODE (decl
) == VAR_DECL
)
6008 if (bss_initializer_p (decl
))
6010 else if (! TREE_READONLY (decl
)
6011 || TREE_SIDE_EFFECTS (decl
)
6012 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6014 /* Here the reloc_rw_mask is not testing whether the section should
6015 be read-only or not, but whether the dynamic link will have to
6016 do something. If so, we wish to segregate the data in order to
6017 minimize cache misses inside the dynamic linker. */
6018 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6019 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6023 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6024 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6025 else if (reloc
|| flag_merge_constants
< 2)
6026 /* C and C++ don't allow different variables to share the same
6027 location. -fmerge-all-constants allows even that (at the
6028 expense of not conforming). */
6029 ret
= SECCAT_RODATA
;
6030 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6031 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6033 ret
= SECCAT_RODATA_MERGE_CONST
;
6035 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6037 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6038 || TREE_SIDE_EFFECTS (decl
)
6039 || ! TREE_CONSTANT (decl
))
6042 ret
= SECCAT_RODATA
;
6045 ret
= SECCAT_RODATA
;
6047 /* There are no read-only thread-local sections. */
6048 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6050 /* Note that this would be *just* SECCAT_BSS, except that there's
6051 no concept of a read-only thread-local-data section. */
6052 if (ret
== SECCAT_BSS
6053 || (flag_zero_initialized_in_bss
6054 && initializer_zerop (DECL_INITIAL (decl
))))
6060 /* If the target uses small data sections, select it. */
6061 else if (targetm
.in_small_data_p (decl
))
6063 if (ret
== SECCAT_BSS
)
6065 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6066 ret
= SECCAT_SRODATA
;
6075 decl_readonly_section (const_tree decl
, int reloc
)
6077 switch (categorize_decl_for_section (decl
, reloc
))
6080 case SECCAT_RODATA_MERGE_STR
:
6081 case SECCAT_RODATA_MERGE_STR_INIT
:
6082 case SECCAT_RODATA_MERGE_CONST
:
6083 case SECCAT_SRODATA
:
6092 /* Select a section based on the above categorization. */
6095 default_elf_select_section (tree decl
, int reloc
,
6096 unsigned HOST_WIDE_INT align
)
6099 switch (categorize_decl_for_section (decl
, reloc
))
6102 /* We're not supposed to be called on FUNCTION_DECLs. */
6105 return readonly_data_section
;
6106 case SECCAT_RODATA_MERGE_STR
:
6107 return mergeable_string_section (decl
, align
, 0);
6108 case SECCAT_RODATA_MERGE_STR_INIT
:
6109 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6110 case SECCAT_RODATA_MERGE_CONST
:
6111 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6112 case SECCAT_SRODATA
:
6116 return data_section
;
6117 case SECCAT_DATA_REL
:
6118 sname
= ".data.rel";
6120 case SECCAT_DATA_REL_LOCAL
:
6121 sname
= ".data.rel.local";
6123 case SECCAT_DATA_REL_RO
:
6124 sname
= ".data.rel.ro";
6126 case SECCAT_DATA_REL_RO_LOCAL
:
6127 sname
= ".data.rel.ro.local";
6152 return get_named_section (decl
, sname
, reloc
);
6155 /* Construct a unique section name based on the decl name and the
6156 categorization performed above. */
6159 default_unique_section (tree decl
, int reloc
)
6161 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6162 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6163 const char *prefix
, *name
, *linkonce
;
6166 switch (categorize_decl_for_section (decl
, reloc
))
6169 prefix
= one_only
? ".t" : ".text";
6172 case SECCAT_RODATA_MERGE_STR
:
6173 case SECCAT_RODATA_MERGE_STR_INIT
:
6174 case SECCAT_RODATA_MERGE_CONST
:
6175 prefix
= one_only
? ".r" : ".rodata";
6177 case SECCAT_SRODATA
:
6178 prefix
= one_only
? ".s2" : ".sdata2";
6181 prefix
= one_only
? ".d" : ".data";
6183 case SECCAT_DATA_REL
:
6184 prefix
= one_only
? ".d.rel" : ".data.rel";
6186 case SECCAT_DATA_REL_LOCAL
:
6187 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6189 case SECCAT_DATA_REL_RO
:
6190 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6192 case SECCAT_DATA_REL_RO_LOCAL
:
6193 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6196 prefix
= one_only
? ".s" : ".sdata";
6199 prefix
= one_only
? ".b" : ".bss";
6202 prefix
= one_only
? ".sb" : ".sbss";
6205 prefix
= one_only
? ".td" : ".tdata";
6208 prefix
= one_only
? ".tb" : ".tbss";
6214 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6215 name
= targetm
.strip_name_encoding (name
);
6217 /* If we're using one_only, then there needs to be a .gnu.linkonce
6218 prefix to the section name. */
6219 linkonce
= one_only
? ".gnu.linkonce" : "";
6221 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6223 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6226 /* Like compute_reloc_for_constant, except for an RTX. The return value
6227 is a mask for which bit 1 indicates a global relocation, and bit 0
6228 indicates a local relocation. */
6231 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6233 int *preloc
= (int *) data
;
6236 switch (GET_CODE (x
))
6239 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6252 compute_reloc_for_rtx (rtx x
)
6256 switch (GET_CODE (x
))
6262 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6271 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6273 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6275 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6276 return data_section
;
6278 return readonly_data_section
;
6282 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6283 unsigned HOST_WIDE_INT align
)
6285 int reloc
= compute_reloc_for_rtx (x
);
6287 /* ??? Handle small data here somehow. */
6289 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6292 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6294 return get_named_section (NULL
, ".data.rel.ro", 3);
6297 return mergeable_constant_section (mode
, align
, 0);
6300 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6303 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6308 /* Careful not to prod global register variables. */
6311 symbol
= XEXP (rtl
, 0);
6312 if (GET_CODE (symbol
) != SYMBOL_REF
)
6315 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6316 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6317 flags
|= SYMBOL_FLAG_FUNCTION
;
6318 if (targetm
.binds_local_p (decl
))
6319 flags
|= SYMBOL_FLAG_LOCAL
;
6320 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6321 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6322 else if (targetm
.in_small_data_p (decl
))
6323 flags
|= SYMBOL_FLAG_SMALL
;
6324 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6325 being PUBLIC, the thing *must* be defined in this translation unit.
6326 Prevent this buglet from being propagated into rtl code as well. */
6327 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6328 flags
|= SYMBOL_FLAG_EXTERNAL
;
6330 SYMBOL_REF_FLAGS (symbol
) = flags
;
6333 /* By default, we do nothing for encode_section_info, so we need not
6334 do anything but discard the '*' marker. */
6337 default_strip_name_encoding (const char *str
)
6339 return str
+ (*str
== '*');
6342 #ifdef ASM_OUTPUT_DEF
6343 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6344 anchor relative to ".", the current section position. */
6347 default_asm_output_anchor (rtx symbol
)
6351 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6352 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6353 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6357 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6360 default_use_anchors_for_symbol_p (const_rtx symbol
)
6365 /* Don't use anchors for mergeable sections. The linker might move
6366 the objects around. */
6367 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6368 if (sect
->common
.flags
& SECTION_MERGE
)
6371 /* Don't use anchors for small data sections. The small data register
6372 acts as an anchor for such sections. */
6373 if (sect
->common
.flags
& SECTION_SMALL
)
6376 decl
= SYMBOL_REF_DECL (symbol
);
6377 if (decl
&& DECL_P (decl
))
6379 /* Don't use section anchors for decls that might be defined by
6381 if (!targetm
.binds_local_p (decl
))
6384 /* Don't use section anchors for decls that will be placed in a
6385 small data section. */
6386 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6387 one above. The problem is that we only use SECTION_SMALL for
6388 sections that should be marked as small in the section directive. */
6389 if (targetm
.in_small_data_p (decl
))
6395 /* Return true when RESOLUTION indicate that symbol will be bound to the
6396 definition provided by current .o file. */
6399 resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution
)
6401 return (resolution
== LDPR_PREVAILING_DEF
6402 || resolution
== LDPR_PREVAILING_DEF_IRONLY
);
6405 /* Return true when RESOLUTION indicate that symbol will be bound locally
6406 within current executable or DSO. */
6409 resolution_local_p (enum ld_plugin_symbol_resolution resolution
)
6411 return (resolution
== LDPR_PREVAILING_DEF
6412 || resolution
== LDPR_PREVAILING_DEF_IRONLY
6413 || resolution
== LDPR_PREEMPTED_REG
6414 || resolution
== LDPR_PREEMPTED_IR
6415 || resolution
== LDPR_RESOLVED_IR
6416 || resolution
== LDPR_RESOLVED_EXEC
);
6419 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6420 wrt cross-module name binding. */
6423 default_binds_local_p (const_tree exp
)
6425 return default_binds_local_p_1 (exp
, flag_shlib
);
6429 default_binds_local_p_1 (const_tree exp
, int shlib
)
6432 bool resolved_locally
= false;
6433 bool resolved_to_local_def
= false;
6435 /* With resolution file in hands, take look into resolutions.
6436 We can't just return true for resolved_localy symbols,
6437 because dynamic linking might overwrite symbols
6438 in shared libraries. */
6439 if (TREE_CODE (exp
) == VAR_DECL
&& TREE_PUBLIC (exp
)
6440 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
6442 struct varpool_node
*vnode
= varpool_get_node (exp
);
6443 if (vnode
&& resolution_local_p (vnode
->resolution
))
6444 resolved_locally
= true;
6446 && resolution_to_local_definition_p (vnode
->resolution
))
6447 resolved_to_local_def
= true;
6449 else if (TREE_CODE (exp
) == FUNCTION_DECL
&& TREE_PUBLIC (exp
))
6451 struct cgraph_node
*node
= cgraph_get_node_or_alias (exp
);
6453 && resolution_local_p (node
->resolution
))
6454 resolved_locally
= true;
6456 && resolution_to_local_definition_p (node
->resolution
))
6457 resolved_to_local_def
= true;
6460 /* A non-decl is an entry in the constant pool. */
6463 /* Weakrefs may not bind locally, even though the weakref itself is
6464 always static and therefore local.
6465 FIXME: We can resolve this more curefuly by looking at the weakref
6467 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
6469 /* Static variables are always local. */
6470 else if (! TREE_PUBLIC (exp
))
6472 /* A variable is local if the user has said explicitly that it will
6474 else if ((DECL_VISIBILITY_SPECIFIED (exp
)
6475 || resolved_to_local_def
)
6476 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6478 /* Variables defined outside this object might not be local. */
6479 else if (DECL_EXTERNAL (exp
) && !resolved_locally
)
6481 /* If defined in this object and visibility is not default, must be
6483 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6485 /* Default visibility weak data can be overridden by a strong symbol
6486 in another module and so are not local. */
6487 else if (DECL_WEAK (exp
)
6488 && !resolved_locally
)
6490 /* If PIC, then assume that any global name can be overridden by
6491 symbols resolved from other modules. */
6494 /* Uninitialized COMMON variable may be unified with symbols
6495 resolved from other modules. */
6496 else if (DECL_COMMON (exp
)
6497 && !resolved_locally
6498 && (DECL_INITIAL (exp
) == NULL
6499 || DECL_INITIAL (exp
) == error_mark_node
))
6501 /* Otherwise we're left with initialized (or non-common) global data
6502 which is of necessity defined locally. */
6509 /* Return true when references to DECL must bind to current definition in
6512 The condition is usually equivalent to whether the function binds to the
6513 current module (shared library or executable), that is to binds_local_p.
6514 We use this fact to avoid need for another target hook and implement
6515 the logic using binds_local_p and just special cases where
6516 decl_binds_to_current_def_p is stronger than binds local_p. In particular
6517 the weak definitions (that can be overwritten at linktime by other
6518 definition from different object file) and when resolution info is available
6519 we simply use the knowledge passed to us by linker plugin. */
6521 decl_binds_to_current_def_p (tree decl
)
6523 gcc_assert (DECL_P (decl
));
6524 if (!TREE_PUBLIC (decl
))
6526 if (!targetm
.binds_local_p (decl
))
6528 /* When resolution is available, just use it. */
6529 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_PUBLIC (decl
)
6530 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
6532 struct varpool_node
*vnode
= varpool_get_node (decl
);
6534 && vnode
->resolution
!= LDPR_UNKNOWN
)
6535 return resolution_to_local_definition_p (vnode
->resolution
);
6537 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
))
6539 struct cgraph_node
*node
= cgraph_get_node_or_alias (decl
);
6541 && node
->resolution
!= LDPR_UNKNOWN
)
6542 return resolution_to_local_definition_p (node
->resolution
);
6544 /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
6545 binds localy but still can be overwritten).
6546 This rely on fact that binds_local_p behave as decl_replaceable_p
6547 for all other declaration types. */
6548 return !DECL_WEAK (decl
);
6551 /* A replaceable function or variable is one which may be replaced
6552 at link-time with an entirely different definition, provided that the
6553 replacement has the same type. For example, functions declared
6554 with __attribute__((weak)) on most systems are replaceable.
6556 COMDAT functions are not replaceable, since all definitions of the
6557 function must be equivalent. It is important that COMDAT functions
6558 not be treated as replaceable so that use of C++ template
6559 instantiations is not penalized. */
6562 decl_replaceable_p (tree decl
)
6564 gcc_assert (DECL_P (decl
));
6565 if (!TREE_PUBLIC (decl
) || DECL_COMDAT (decl
))
6567 return !decl_binds_to_current_def_p (decl
);
6570 /* Default function to output code that will globalize a label. A
6571 target must define GLOBAL_ASM_OP or provide its own function to
6572 globalize a label. */
6573 #ifdef GLOBAL_ASM_OP
6575 default_globalize_label (FILE * stream
, const char *name
)
6577 fputs (GLOBAL_ASM_OP
, stream
);
6578 assemble_name (stream
, name
);
6579 putc ('\n', stream
);
6581 #endif /* GLOBAL_ASM_OP */
6583 /* Default function to output code that will globalize a declaration. */
6585 default_globalize_decl_name (FILE * stream
, tree decl
)
6587 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6588 targetm
.asm_out
.globalize_label (stream
, name
);
6591 /* Default function to output a label for unwind information. The
6592 default is to do nothing. A target that needs nonlocal labels for
6593 unwind information must provide its own function to do this. */
6595 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6596 tree decl ATTRIBUTE_UNUSED
,
6597 int for_eh ATTRIBUTE_UNUSED
,
6598 int empty ATTRIBUTE_UNUSED
)
6602 /* Default function to output a label to divide up the exception table.
6603 The default is to do nothing. A target that needs/wants to divide
6604 up the table must provide it's own function to do this. */
6606 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6610 /* This is how to output an internal numbered label where PREFIX is
6611 the class of label and LABELNO is the number within the class. */
6614 default_internal_label (FILE *stream
, const char *prefix
,
6615 unsigned long labelno
)
6617 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6618 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6619 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6623 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6626 default_asm_declare_constant_name (FILE *file
, const char *name
,
6627 const_tree exp ATTRIBUTE_UNUSED
,
6628 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
6630 assemble_label (file
, name
);
6633 /* This is the default behavior at the beginning of a file. It's
6634 controlled by two other target-hook toggles. */
6636 default_file_start (void)
6638 if (targetm
.asm_file_start_app_off
6639 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6640 fputs (ASM_APP_OFF
, asm_out_file
);
6642 if (targetm
.asm_file_start_file_directive
)
6643 output_file_directive (asm_out_file
, main_input_filename
);
6646 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6647 which emits a special section directive used to indicate whether or
6648 not this object file needs an executable stack. This is primarily
6649 a GNU extension to ELF but could be used on other targets. */
6651 int trampolines_created
;
6654 file_end_indicate_exec_stack (void)
6656 unsigned int flags
= SECTION_DEBUG
;
6657 if (trampolines_created
)
6658 flags
|= SECTION_CODE
;
6660 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6663 /* Emit a special section directive to indicate that this object file
6664 was compiled with -fsplit-stack. This is used to let the linker
6665 detect calls between split-stack code and non-split-stack code, so
6666 that it can modify the split-stack code to allocate a sufficiently
6667 large stack. We emit another special section if there are any
6668 functions in this file which have the no_split_stack attribute, to
6669 prevent the linker from warning about being unable to convert the
6670 functions if they call non-split-stack code. */
6673 file_end_indicate_split_stack (void)
6675 if (flag_split_stack
)
6677 switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG
,
6679 if (saw_no_split_stack
)
6680 switch_to_section (get_section (".note.GNU-no-split-stack",
6681 SECTION_DEBUG
, NULL
));
6685 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6686 a get_unnamed_section callback. */
6689 output_section_asm_op (const void *directive
)
6691 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
6694 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6695 the current section is NEW_SECTION. */
6698 switch_to_section (section
*new_section
)
6700 if (in_section
== new_section
)
6703 if (new_section
->common
.flags
& SECTION_FORGET
)
6706 in_section
= new_section
;
6708 switch (SECTION_STYLE (new_section
))
6712 && !crtl
->subsections
.unlikely_text_section_name
6713 && strcmp (new_section
->named
.name
,
6714 UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6715 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
6717 targetm
.asm_out
.named_section (new_section
->named
.name
,
6718 new_section
->named
.common
.flags
,
6719 new_section
->named
.decl
);
6722 case SECTION_UNNAMED
:
6723 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
6726 case SECTION_NOSWITCH
:
6731 new_section
->common
.flags
|= SECTION_DECLARED
;
6734 /* If block symbol SYMBOL has not yet been assigned an offset, place
6735 it at the end of its block. */
6738 place_block_symbol (rtx symbol
)
6740 unsigned HOST_WIDE_INT size
, mask
, offset
;
6741 struct constant_descriptor_rtx
*desc
;
6742 unsigned int alignment
;
6743 struct object_block
*block
;
6746 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
6747 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
6750 /* Work out the symbol's size and alignment. */
6751 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6753 desc
= SYMBOL_REF_CONSTANT (symbol
);
6754 alignment
= desc
->align
;
6755 size
= GET_MODE_SIZE (desc
->mode
);
6757 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6759 decl
= SYMBOL_REF_DECL (symbol
);
6760 alignment
= DECL_ALIGN (decl
);
6761 size
= get_constant_size (DECL_INITIAL (decl
));
6765 decl
= SYMBOL_REF_DECL (symbol
);
6766 alignment
= DECL_ALIGN (decl
);
6767 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
6770 /* Calculate the object's offset from the start of the block. */
6771 block
= SYMBOL_REF_BLOCK (symbol
);
6772 mask
= alignment
/ BITS_PER_UNIT
- 1;
6773 offset
= (block
->size
+ mask
) & ~mask
;
6774 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
6776 /* Record the block's new alignment and size. */
6777 block
->alignment
= MAX (block
->alignment
, alignment
);
6778 block
->size
= offset
+ size
;
6780 VEC_safe_push (rtx
, gc
, block
->objects
, symbol
);
6783 /* Return the anchor that should be used to address byte offset OFFSET
6784 from the first object in BLOCK. MODEL is the TLS model used
6788 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
6789 enum tls_model model
)
6792 unsigned int begin
, middle
, end
;
6793 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
6796 /* Work out the anchor's offset. Use an offset of 0 for the first
6797 anchor so that we don't pessimize the case where we take the address
6798 of a variable at the beginning of the block. This is particularly
6799 useful when a block has only one variable assigned to it.
6801 We try to place anchors RANGE bytes apart, so there can then be
6802 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6803 a ptr_mode offset. With some target settings, the lowest such
6804 anchor might be out of range for the lowest ptr_mode offset;
6805 likewise the highest anchor for the highest offset. Use anchors
6806 at the extreme ends of the ptr_mode range in such cases.
6808 All arithmetic uses unsigned integers in order to avoid
6810 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
6811 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
6812 range
= max_offset
- min_offset
+ 1;
6817 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
6820 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
6821 delta
-= delta
% range
;
6824 offset
= (HOST_WIDE_INT
) (-delta
);
6828 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
6829 delta
-= delta
% range
;
6830 if (delta
> bias
- 1)
6832 offset
= (HOST_WIDE_INT
) delta
;
6836 /* Do a binary search to see if there's already an anchor we can use.
6837 Set BEGIN to the new anchor's index if not. */
6839 end
= VEC_length (rtx
, block
->anchors
);
6840 while (begin
!= end
)
6842 middle
= (end
+ begin
) / 2;
6843 anchor
= VEC_index (rtx
, block
->anchors
, middle
);
6844 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
6846 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
6848 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
6850 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
6856 /* Create a new anchor with a unique label. */
6857 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
6858 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
6859 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
6860 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
6862 /* Insert it at index BEGIN. */
6863 VEC_safe_insert (rtx
, gc
, block
->anchors
, begin
, anchor
);
6867 /* Output the objects in BLOCK. */
6870 output_object_block (struct object_block
*block
)
6872 struct constant_descriptor_rtx
*desc
;
6874 HOST_WIDE_INT offset
;
6878 if (block
->objects
== NULL
)
6881 /* Switch to the section and make sure that the first byte is
6882 suitably aligned. */
6883 switch_to_section (block
->sect
);
6884 assemble_align (block
->alignment
);
6886 /* Define the values of all anchors relative to the current section
6888 FOR_EACH_VEC_ELT (rtx
, block
->anchors
, i
, symbol
)
6889 targetm
.asm_out
.output_anchor (symbol
);
6891 /* Output the objects themselves. */
6893 FOR_EACH_VEC_ELT (rtx
, block
->objects
, i
, symbol
)
6895 /* Move to the object's offset, padding with zeros if necessary. */
6896 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
6897 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
6898 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6900 desc
= SYMBOL_REF_CONSTANT (symbol
);
6901 output_constant_pool_1 (desc
, 1);
6902 offset
+= GET_MODE_SIZE (desc
->mode
);
6904 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6906 decl
= SYMBOL_REF_DECL (symbol
);
6907 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
6909 offset
+= get_constant_size (DECL_INITIAL (decl
));
6913 decl
= SYMBOL_REF_DECL (symbol
);
6914 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
6915 offset
+= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
6920 /* A htab_traverse callback used to call output_object_block for
6921 each member of object_block_htab. */
6924 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
6926 output_object_block ((struct object_block
*) (*slot
));
6930 /* Output the definitions of all object_blocks. */
6933 output_object_blocks (void)
6935 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
6938 /* This function provides a possible implementation of the
6939 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
6940 by -frecord-gcc-switches it creates a new mergeable, string section in the
6941 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
6942 contains the switches in ASCII format.
6944 FIXME: This code does not correctly handle double quote characters
6945 that appear inside strings, (it strips them rather than preserving them).
6946 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
6947 characters - instead it treats them as sub-string separators. Since
6948 we want to emit NUL strings terminators into the object file we have to use
6952 elf_record_gcc_switches (print_switch_type type
, const char * name
)
6956 case SWITCH_TYPE_PASSED
:
6957 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
6958 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
6961 case SWITCH_TYPE_DESCRIPTIVE
:
6964 /* Distinguish between invocations where name is NULL. */
6965 static bool started
= false;
6971 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
6975 | (SECTION_ENTSIZE
& 1),
6977 switch_to_section (sec
);
6986 /* The return value is currently ignored by the caller, but must be 0.
6987 For -fverbose-asm the return value would be the number of characters
6988 emitted into the assembler file. */
6992 /* Emit text to declare externally defined symbols. It is needed to
6993 properly support non-default visibility. */
6995 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
6997 const char *name ATTRIBUTE_UNUSED
)
6999 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7000 set in order to avoid putting out names that are never really
7002 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7003 && targetm
.binds_local_p (decl
))
7004 maybe_assemble_visibility (decl
);
7007 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
7010 default_asm_output_source_filename (FILE *file
, const char *name
)
7012 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7013 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
7015 fprintf (file
, "\t.file\t");
7016 output_quoted_string (file
, name
);
7021 /* Output a file name in the form wanted by System V. */
7024 output_file_directive (FILE *asm_file
, const char *input_name
)
7029 if (input_name
== NULL
)
7030 input_name
= "<stdin>";
7032 input_name
= remap_debug_filename (input_name
);
7034 len
= strlen (input_name
);
7035 na
= input_name
+ len
;
7037 /* NA gets INPUT_NAME sans directory names. */
7038 while (na
> input_name
)
7040 if (IS_DIR_SEPARATOR (na
[-1]))
7045 targetm
.asm_out
.output_source_filename (asm_file
, na
);
7048 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7051 make_debug_expr_from_rtl (const_rtx exp
)
7053 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7054 enum machine_mode mode
= GET_MODE (exp
);
7057 DECL_ARTIFICIAL (ddecl
) = 1;
7058 if (REG_P (exp
) && REG_EXPR (exp
))
7059 type
= TREE_TYPE (REG_EXPR (exp
));
7060 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7061 type
= TREE_TYPE (MEM_EXPR (exp
));
7064 if (type
&& TYPE_MODE (type
) == mode
)
7065 TREE_TYPE (ddecl
) = type
;
7067 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7068 DECL_MODE (ddecl
) = mode
;
7069 dval
= gen_rtx_DEBUG_EXPR (mode
);
7070 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7071 SET_DECL_RTL (ddecl
, dval
);
7075 #include "gt-varasm.h"