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 static const char *strip_reg_name (const char *);
103 static int contains_pointers_p (tree
);
104 #ifdef ASM_OUTPUT_EXTERNAL
105 static bool incorporeal_function_p (tree
);
107 static void decode_addr_const (tree
, struct addr_const
*);
108 static hashval_t
const_desc_hash (const void *);
109 static int const_desc_eq (const void *, const void *);
110 static hashval_t
const_hash_1 (const tree
);
111 static int compare_constant (const tree
, const tree
);
112 static tree
copy_constant (tree
);
113 static void output_constant_def_contents (rtx
);
114 static void output_addressed_constants (tree
);
115 static unsigned HOST_WIDE_INT
array_size_for_constructor (tree
);
116 static unsigned min_align (unsigned, unsigned);
117 static void globalize_decl (tree
);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_BSS
120 static void asm_output_bss (FILE *, tree
, const char *,
121 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
123 #ifdef ASM_OUTPUT_ALIGNED_BSS
124 static void asm_output_aligned_bss (FILE *, tree
, const char *,
125 unsigned HOST_WIDE_INT
, int)
128 #endif /* BSS_SECTION_ASM_OP */
129 static void mark_weak (tree
);
130 static void output_constant_pool (const char *, tree
);
132 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
133 section
*text_section
;
134 section
*data_section
;
135 section
*readonly_data_section
;
136 section
*sdata_section
;
137 section
*ctors_section
;
138 section
*dtors_section
;
139 section
*bss_section
;
140 section
*sbss_section
;
142 /* Various forms of common section. All are guaranteed to be nonnull. */
143 section
*tls_comm_section
;
144 section
*comm_section
;
145 section
*lcomm_section
;
147 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
149 section
*bss_noswitch_section
;
151 /* The section that holds the main exception table, when known. The section
152 is set either by the target's init_sections hook or by the first call to
153 switch_to_exception_section. */
154 section
*exception_section
;
156 /* The section that holds the DWARF2 frame unwind information, when known.
157 The section is set either by the target's init_sections hook or by the
158 first call to switch_to_eh_frame_section. */
159 section
*eh_frame_section
;
161 /* asm_out_file's current section. This is NULL if no section has yet
162 been selected or if we lose track of what the current section is. */
165 /* True if code for the current function is currently being directed
166 at the cold section. */
167 bool in_cold_section_p
;
169 /* A linked list of all the unnamed sections. */
170 static GTY(()) section
*unnamed_sections
;
172 /* Return a nonzero value if DECL has a section attribute. */
173 #define IN_NAMED_SECTION(DECL) \
174 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
175 && DECL_SECTION_NAME (DECL) != NULL_TREE)
177 /* Hash table of named sections. */
178 static GTY((param_is (section
))) htab_t section_htab
;
180 /* A table of object_blocks, indexed by section. */
181 static GTY((param_is (struct object_block
))) htab_t object_block_htab
;
183 /* The next number to use for internal anchor labels. */
184 static GTY(()) int anchor_labelno
;
186 /* A pool of constants that can be shared between functions. */
187 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
189 /* Helper routines for maintaining section_htab. */
192 section_entry_eq (const void *p1
, const void *p2
)
194 const section
*old
= (const section
*) p1
;
195 const char *new_name
= (const char *) p2
;
197 return strcmp (old
->named
.name
, new_name
) == 0;
201 section_entry_hash (const void *p
)
203 const section
*old
= (const section
*) p
;
204 return htab_hash_string (old
->named
.name
);
207 /* Return a hash value for section SECT. */
210 hash_section (section
*sect
)
212 if (sect
->common
.flags
& SECTION_NAMED
)
213 return htab_hash_string (sect
->named
.name
);
214 return sect
->common
.flags
;
217 /* Helper routines for maintaining object_block_htab. */
220 object_block_entry_eq (const void *p1
, const void *p2
)
222 const struct object_block
*old
= (const struct object_block
*) p1
;
223 const section
*new_section
= (const section
*) p2
;
225 return old
->sect
== new_section
;
229 object_block_entry_hash (const void *p
)
231 const struct object_block
*old
= (const struct object_block
*) p
;
232 return hash_section (old
->sect
);
235 /* Return a new unnamed section with the given fields. */
238 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
243 sect
= ggc_alloc_section ();
244 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
245 sect
->unnamed
.callback
= callback
;
246 sect
->unnamed
.data
= data
;
247 sect
->unnamed
.next
= unnamed_sections
;
249 unnamed_sections
= sect
;
253 /* Return a SECTION_NOSWITCH section with the given fields. */
256 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
260 sect
= ggc_alloc_section ();
261 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
262 sect
->noswitch
.callback
= callback
;
267 /* Return the named section structure associated with NAME. Create
268 a new section with the given fields if no such structure exists. */
271 get_section (const char *name
, unsigned int flags
, tree decl
)
273 section
*sect
, **slot
;
276 htab_find_slot_with_hash (section_htab
, name
,
277 htab_hash_string (name
), INSERT
);
278 flags
|= SECTION_NAMED
;
281 sect
= ggc_alloc_section ();
282 sect
->named
.common
.flags
= flags
;
283 sect
->named
.name
= ggc_strdup (name
);
284 sect
->named
.decl
= decl
;
290 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
291 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
293 /* Sanity check user variables for flag changes. */
295 decl
= sect
->named
.decl
;
297 error ("%+D causes a section type conflict", decl
);
303 /* Return true if the current compilation mode benefits from having
304 objects grouped into blocks. */
307 use_object_blocks_p (void)
309 return flag_section_anchors
;
312 /* Return the object_block structure for section SECT. Create a new
313 structure if we haven't created one already. Return null if SECT
316 static struct object_block
*
317 get_block_for_section (section
*sect
)
319 struct object_block
*block
;
325 slot
= htab_find_slot_with_hash (object_block_htab
, sect
,
326 hash_section (sect
), INSERT
);
327 block
= (struct object_block
*) *slot
;
330 block
= ggc_alloc_cleared_object_block ();
337 /* Create a symbol with label LABEL and place it at byte offset
338 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
339 is not yet known. LABEL must be a garbage-collected string. */
342 create_block_symbol (const char *label
, struct object_block
*block
,
343 HOST_WIDE_INT offset
)
348 /* Create the extended SYMBOL_REF. */
349 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
350 symbol
= ggc_alloc_zone_rtx_def (size
, &rtl_zone
);
352 /* Initialize the normal SYMBOL_REF fields. */
353 memset (symbol
, 0, size
);
354 PUT_CODE (symbol
, SYMBOL_REF
);
355 PUT_MODE (symbol
, Pmode
);
356 XSTR (symbol
, 0) = label
;
357 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
359 /* Initialize the block_symbol stuff. */
360 SYMBOL_REF_BLOCK (symbol
) = block
;
361 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
367 initialize_cold_section_name (void)
369 const char *stripped_name
;
373 gcc_assert (cfun
&& current_function_decl
);
374 if (crtl
->subsections
.unlikely_text_section_name
)
377 dsn
= DECL_SECTION_NAME (current_function_decl
);
378 if (flag_function_sections
&& dsn
)
380 name
= (char *) alloca (TREE_STRING_LENGTH (dsn
) + 1);
381 memcpy (name
, TREE_STRING_POINTER (dsn
), TREE_STRING_LENGTH (dsn
) + 1);
383 stripped_name
= targetm
.strip_name_encoding (name
);
385 buffer
= ACONCAT ((stripped_name
, "_unlikely", NULL
));
386 crtl
->subsections
.unlikely_text_section_name
= ggc_strdup (buffer
);
389 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
392 /* Tell assembler to switch to unlikely-to-be-executed text section. */
395 unlikely_text_section (void)
399 if (!crtl
->subsections
.unlikely_text_section_name
)
400 initialize_cold_section_name ();
402 return get_named_section (NULL
, crtl
->subsections
.unlikely_text_section_name
, 0);
405 return get_named_section (NULL
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
, 0);
408 /* When called within a function context, return true if the function
409 has been assigned a cold text section and if SECT is that section.
410 When called outside a function context, return true if SECT is the
411 default cold section. */
414 unlikely_text_section_p (section
*sect
)
419 name
= crtl
->subsections
.unlikely_text_section_name
;
421 name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
425 && SECTION_STYLE (sect
) == SECTION_NAMED
426 && strcmp (name
, sect
->named
.name
) == 0);
429 /* Return a section with a particular name and with whatever SECTION_*
430 flags section_type_flags deems appropriate. The name of the section
431 is taken from NAME if nonnull, otherwise it is taken from DECL's
432 DECL_SECTION_NAME. DECL is the decl associated with the section
433 (see the section comment for details) and RELOC is as for
434 section_type_flags. */
437 get_named_section (tree decl
, const char *name
, int reloc
)
441 gcc_assert (!decl
|| DECL_P (decl
));
443 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
445 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
447 return get_section (name
, flags
, decl
);
450 /* If required, set DECL_SECTION_NAME to a unique name. */
453 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
454 int flag_function_or_data_sections
)
456 if (DECL_SECTION_NAME (decl
) == NULL_TREE
457 && targetm
.have_named_sections
458 && (flag_function_or_data_sections
459 || DECL_ONE_ONLY (decl
)))
460 targetm
.asm_out
.unique_section (decl
, reloc
);
463 #ifdef BSS_SECTION_ASM_OP
465 #ifdef ASM_OUTPUT_BSS
467 /* Utility function for ASM_OUTPUT_BSS for targets to use if
468 they don't support alignments in .bss.
469 ??? It is believed that this function will work in most cases so such
470 support is localized here. */
473 asm_output_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
475 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
476 unsigned HOST_WIDE_INT rounded
)
478 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl
), 0), 0), name
) == 0);
479 targetm
.asm_out
.globalize_decl_name (file
, decl
);
480 switch_to_section (bss_section
);
481 #ifdef ASM_DECLARE_OBJECT_NAME
482 last_assemble_variable_decl
= decl
;
483 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
485 /* Standard thing is just output label for the object. */
486 ASM_OUTPUT_LABEL (file
, name
);
487 #endif /* ASM_DECLARE_OBJECT_NAME */
488 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
493 #ifdef ASM_OUTPUT_ALIGNED_BSS
495 /* Utility function for targets to use in implementing
496 ASM_OUTPUT_ALIGNED_BSS.
497 ??? It is believed that this function will work in most cases so such
498 support is localized here. */
501 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
502 const char *name
, unsigned HOST_WIDE_INT size
,
505 switch_to_section (bss_section
);
506 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
507 #ifdef ASM_DECLARE_OBJECT_NAME
508 last_assemble_variable_decl
= decl
;
509 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
511 /* Standard thing is just output label for the object. */
512 ASM_OUTPUT_LABEL (file
, name
);
513 #endif /* ASM_DECLARE_OBJECT_NAME */
514 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
519 #endif /* BSS_SECTION_ASM_OP */
521 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
522 /* Return the hot section for function DECL. Return text_section for
526 hot_function_section (tree decl
)
528 if (decl
!= NULL_TREE
529 && DECL_SECTION_NAME (decl
) != NULL_TREE
530 && targetm
.have_named_sections
)
531 return get_named_section (decl
, NULL
, 0);
537 /* Return the section for function DECL.
539 If DECL is NULL_TREE, return the text section. We can be passed
540 NULL_TREE under some circumstances by dbxout.c at least. */
543 function_section (tree decl
)
547 if (first_function_block_is_cold
)
550 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
551 if (decl
!= NULL_TREE
552 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
553 return reloc
? unlikely_text_section ()
554 : get_named_section (decl
, NULL
, 0);
556 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
558 return reloc
? unlikely_text_section () : hot_function_section (decl
);
563 current_function_section (void)
565 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
566 if (current_function_decl
!= NULL_TREE
567 && DECL_SECTION_NAME (current_function_decl
) != NULL_TREE
)
568 return in_cold_section_p
? unlikely_text_section ()
569 : get_named_section (current_function_decl
,
572 return targetm
.asm_out
.select_section (current_function_decl
,
574 DECL_ALIGN (current_function_decl
));
576 return (in_cold_section_p
577 ? unlikely_text_section ()
578 : hot_function_section (current_function_decl
));
582 /* Return the read-only data section associated with function DECL. */
585 default_function_rodata_section (tree decl
)
587 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
589 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
591 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
597 dot
= strchr (name
+ 1, '.');
600 len
= strlen (dot
) + 8;
601 rname
= (char *) alloca (len
);
603 strcpy (rname
, ".rodata");
605 return get_section (rname
, SECTION_LINKONCE
, decl
);
607 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
608 else if (DECL_ONE_ONLY (decl
)
609 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
611 size_t len
= strlen (name
) + 1;
612 char *rname
= (char *) alloca (len
);
614 memcpy (rname
, name
, len
);
616 return get_section (rname
, SECTION_LINKONCE
, decl
);
618 /* For .text.foo we want to use .rodata.foo. */
619 else if (flag_function_sections
&& flag_data_sections
620 && strncmp (name
, ".text.", 6) == 0)
622 size_t len
= strlen (name
) + 1;
623 char *rname
= (char *) alloca (len
+ 2);
625 memcpy (rname
, ".rodata", 7);
626 memcpy (rname
+ 7, name
+ 5, len
- 5);
627 return get_section (rname
, 0, decl
);
631 return readonly_data_section
;
634 /* Return the read-only data section associated with function DECL
635 for targets where that section should be always the single
636 readonly data section. */
639 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
641 return readonly_data_section
;
644 /* Return the section to use for string merging. */
647 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
648 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
649 unsigned int flags ATTRIBUTE_UNUSED
)
653 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
654 && TREE_CODE (decl
) == STRING_CST
655 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
657 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
658 && TREE_STRING_LENGTH (decl
) >= len
)
660 enum machine_mode mode
;
661 unsigned int modesize
;
667 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
668 modesize
= GET_MODE_BITSIZE (mode
);
669 if (modesize
>= 8 && modesize
<= 256
670 && (modesize
& (modesize
- 1)) == 0)
672 if (align
< modesize
)
675 str
= TREE_STRING_POINTER (decl
);
676 unit
= GET_MODE_SIZE (mode
);
678 /* Check for embedded NUL characters. */
679 for (i
= 0; i
< len
; i
+= unit
)
681 for (j
= 0; j
< unit
; j
++)
682 if (str
[i
+ j
] != '\0')
689 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
691 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
692 return get_section (name
, flags
, NULL
);
697 return readonly_data_section
;
700 /* Return the section to use for constant merging. */
703 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
704 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
705 unsigned int flags ATTRIBUTE_UNUSED
)
707 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
709 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
715 && (align
& (align
- 1)) == 0)
719 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
720 flags
|= (align
/ 8) | SECTION_MERGE
;
721 return get_section (name
, flags
, NULL
);
723 return readonly_data_section
;
726 /* Given NAME, a putative register name, discard any customary prefixes. */
729 strip_reg_name (const char *name
)
731 #ifdef REGISTER_PREFIX
732 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
733 name
+= strlen (REGISTER_PREFIX
);
735 if (name
[0] == '%' || name
[0] == '#')
740 /* The user has asked for a DECL to have a particular name. Set (or
741 change) it in such a way that we don't prefix an underscore to
744 set_user_assembler_name (tree decl
, const char *name
)
746 char *starred
= (char *) alloca (strlen (name
) + 2);
748 strcpy (starred
+ 1, name
);
749 change_decl_assembler_name (decl
, get_identifier (starred
));
750 SET_DECL_RTL (decl
, NULL_RTX
);
753 /* Decode an `asm' spec for a declaration as a register name.
754 Return the register number, or -1 if nothing specified,
755 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
756 or -3 if ASMSPEC is `cc' and is not recognized,
757 or -4 if ASMSPEC is `memory' and is not recognized.
758 Accept an exact spelling or a decimal number.
759 Prefixes such as % are optional. */
762 decode_reg_name (const char *asmspec
)
768 /* Get rid of confusing prefixes. */
769 asmspec
= strip_reg_name (asmspec
);
771 /* Allow a decimal number as a "register name". */
772 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
773 if (! ISDIGIT (asmspec
[i
]))
775 if (asmspec
[0] != 0 && i
< 0)
778 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
784 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
786 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
789 #ifdef ADDITIONAL_REGISTER_NAMES
791 static const struct { const char *const name
; const int number
; } table
[]
792 = ADDITIONAL_REGISTER_NAMES
;
794 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
796 && ! strcmp (asmspec
, table
[i
].name
))
797 return table
[i
].number
;
799 #endif /* ADDITIONAL_REGISTER_NAMES */
801 if (!strcmp (asmspec
, "memory"))
804 if (!strcmp (asmspec
, "cc"))
813 /* Return true if DECL's initializer is suitable for a BSS section. */
816 bss_initializer_p (const_tree decl
)
818 return (DECL_INITIAL (decl
) == NULL
819 || DECL_INITIAL (decl
) == error_mark_node
820 || (flag_zero_initialized_in_bss
821 /* Leave constant zeroes in .rodata so they
823 && !TREE_READONLY (decl
)
824 && initializer_zerop (DECL_INITIAL (decl
))));
827 /* Compute the alignment of variable specified by DECL.
828 DONT_OUTPUT_DATA is from assemble_variable. */
831 align_variable (tree decl
, bool dont_output_data
)
833 unsigned int align
= DECL_ALIGN (decl
);
835 /* In the case for initialing an array whose length isn't specified,
836 where we have not yet been able to do the layout,
837 figure out the proper alignment now. */
838 if (dont_output_data
&& DECL_SIZE (decl
) == 0
839 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
840 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
842 /* Some object file formats have a maximum alignment which they support.
843 In particular, a.out format supports a maximum alignment of 4. */
844 if (align
> MAX_OFILE_ALIGNMENT
)
846 warning (0, "alignment of %q+D is greater than maximum object "
847 "file alignment. Using %d", decl
,
848 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
849 align
= MAX_OFILE_ALIGNMENT
;
852 /* On some machines, it is good to increase alignment sometimes. */
853 if (! DECL_USER_ALIGN (decl
))
855 #ifdef DATA_ALIGNMENT
856 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
857 /* Don't increase alignment too much for TLS variables - TLS space
859 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
862 #ifdef CONSTANT_ALIGNMENT
863 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
865 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
867 /* Don't increase alignment too much for TLS variables - TLS space
869 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
875 /* Reset the alignment in case we have made it tighter, so we can benefit
876 from it in get_pointer_alignment. */
877 DECL_ALIGN (decl
) = align
;
880 /* Return the section into which the given VAR_DECL or CONST_DECL
881 should be placed. PREFER_NOSWITCH_P is true if a noswitch
882 section should be used wherever possible. */
885 get_variable_section (tree decl
, bool prefer_noswitch_p
)
887 addr_space_t as
= ADDR_SPACE_GENERIC
;
890 if (TREE_TYPE (decl
) != error_mark_node
)
891 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
893 if (DECL_COMMON (decl
))
895 /* If the decl has been given an explicit section name, or it resides
896 in a non-generic address space, then it isn't common, and shouldn't
897 be handled as such. */
898 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
899 && ADDR_SPACE_GENERIC_P (as
));
900 if (DECL_THREAD_LOCAL_P (decl
))
901 return tls_comm_section
;
902 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
906 if (DECL_INITIAL (decl
) == error_mark_node
)
907 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
908 else if (DECL_INITIAL (decl
))
909 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
913 resolve_unique_section (decl
, reloc
, flag_data_sections
);
914 if (IN_NAMED_SECTION (decl
))
915 return get_named_section (decl
, NULL
, reloc
);
917 if (ADDR_SPACE_GENERIC_P (as
)
918 && !DECL_THREAD_LOCAL_P (decl
)
919 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
920 && bss_initializer_p (decl
))
922 if (!TREE_PUBLIC (decl
))
923 return lcomm_section
;
924 if (bss_noswitch_section
)
925 return bss_noswitch_section
;
928 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
931 /* Return the block into which object_block DECL should be placed. */
933 static struct object_block
*
934 get_block_for_decl (tree decl
)
938 if (TREE_CODE (decl
) == VAR_DECL
)
940 /* The object must be defined in this translation unit. */
941 if (DECL_EXTERNAL (decl
))
944 /* There's no point using object blocks for something that is
945 isolated by definition. */
946 if (DECL_ONE_ONLY (decl
))
950 /* We can only calculate block offsets if the decl has a known
952 if (DECL_SIZE_UNIT (decl
) == NULL
)
954 if (!host_integerp (DECL_SIZE_UNIT (decl
), 1))
957 /* Find out which section should contain DECL. We cannot put it into
958 an object block if it requires a standalone definition. */
959 if (TREE_CODE (decl
) == VAR_DECL
)
960 align_variable (decl
, 0);
961 sect
= get_variable_section (decl
, true);
962 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
965 return get_block_for_section (sect
);
968 /* Make sure block symbol SYMBOL is in block BLOCK. */
971 change_symbol_block (rtx symbol
, struct object_block
*block
)
973 if (block
!= SYMBOL_REF_BLOCK (symbol
))
975 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
976 SYMBOL_REF_BLOCK (symbol
) = block
;
980 /* Return true if it is possible to put DECL in an object_block. */
983 use_blocks_for_decl_p (tree decl
)
985 /* Only data DECLs can be placed into object blocks. */
986 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
989 /* Detect decls created by dw2_force_const_mem. Such decls are
990 special because DECL_INITIAL doesn't specify the decl's true value.
991 dw2_output_indirect_constants will instead call assemble_variable
992 with dont_output_data set to 1 and then print the contents itself. */
993 if (DECL_INITIAL (decl
) == decl
)
996 /* If this decl is an alias, then we don't want to emit a definition. */
997 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl
)))
1003 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1004 have static storage duration. In other words, it should not be an
1005 automatic variable, including PARM_DECLs.
1007 There is, however, one exception: this function handles variables
1008 explicitly placed in a particular register by the user.
1010 This is never called for PARM_DECL nodes. */
1013 make_decl_rtl (tree decl
)
1015 const char *name
= 0;
1019 /* Check that we are not being given an automatic variable. */
1020 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1021 && TREE_CODE (decl
) != RESULT_DECL
);
1023 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1024 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1025 || TREE_STATIC (decl
)
1026 || TREE_PUBLIC (decl
)
1027 || DECL_EXTERNAL (decl
)
1028 || DECL_REGISTER (decl
));
1030 /* And that we were not given a type or a label. */
1031 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1032 && TREE_CODE (decl
) != LABEL_DECL
);
1034 /* For a duplicate declaration, we can be called twice on the
1035 same DECL node. Don't discard the RTL already made. */
1036 if (DECL_RTL_SET_P (decl
))
1038 /* If the old RTL had the wrong mode, fix the mode. */
1039 x
= DECL_RTL (decl
);
1040 if (GET_MODE (x
) != DECL_MODE (decl
))
1041 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1043 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1046 /* ??? Another way to do this would be to maintain a hashed
1047 table of such critters. Instead of adding stuff to a DECL
1048 to give certain attributes to it, we could use an external
1049 hash map from DECL to set of attributes. */
1051 /* Let the target reassign the RTL if it wants.
1052 This is necessary, for example, when one machine specific
1053 decl attribute overrides another. */
1054 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1056 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1057 on the new decl information. */
1059 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1060 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1061 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1063 /* Make this function static known to the mudflap runtime. */
1064 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1065 mudflap_enqueue_decl (decl
);
1070 /* If this variable belongs to the global constant pool, retrieve the
1071 pre-computed RTL or recompute it in LTO mode. */
1072 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1074 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1078 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1080 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1081 && DECL_REGISTER (decl
))
1083 error ("register name not specified for %q+D", decl
);
1085 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1087 const char *asmspec
= name
+1;
1088 reg_number
= decode_reg_name (asmspec
);
1089 /* First detect errors in declaring global registers. */
1090 if (reg_number
== -1)
1091 error ("register name not specified for %q+D", decl
);
1092 else if (reg_number
< 0)
1093 error ("invalid register name for %q+D", decl
);
1094 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
1095 error ("data type of %q+D isn%'t suitable for a register",
1097 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
1098 error ("register specified for %q+D isn%'t suitable for data type",
1100 /* Now handle properly declared static register variables. */
1105 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1107 DECL_INITIAL (decl
) = 0;
1108 error ("global register variable has initial value");
1110 if (TREE_THIS_VOLATILE (decl
))
1111 warning (OPT_Wvolatile_register_var
,
1112 "optimization may eliminate reads and/or "
1113 "writes to register variables");
1115 /* If the user specified one of the eliminables registers here,
1116 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1117 confused with that register and be eliminated. This usage is
1118 somewhat suspect... */
1120 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
1121 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1122 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1124 if (TREE_STATIC (decl
))
1126 /* Make this register global, so not usable for anything
1128 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1129 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1130 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1132 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
1134 globalize_reg (reg_number
+ --nregs
);
1137 /* As a register variable, it has no section. */
1141 /* Now handle ordinary static variables and functions (in memory).
1142 Also handle vars declared register invalidly. */
1143 else if (name
[0] == '*')
1145 #ifdef REGISTER_PREFIX
1146 if (strlen (REGISTER_PREFIX
) != 0)
1148 reg_number
= decode_reg_name (name
);
1149 if (reg_number
>= 0 || reg_number
== -3)
1150 error ("register name given for non-register variable %q+D", decl
);
1155 /* Specifying a section attribute on a variable forces it into a
1156 non-.bss section, and thus it cannot be common. */
1157 /* FIXME: In general this code should not be necessary because
1158 visibility pass is doing the same work. But notice_global_symbol
1159 is called early and it needs to make DECL_RTL to get the name.
1160 we take care of recomputing the DECL_RTL after visibility is changed. */
1161 if (TREE_CODE (decl
) == VAR_DECL
1162 && DECL_SECTION_NAME (decl
) != NULL_TREE
1163 && DECL_INITIAL (decl
) == NULL_TREE
1164 && DECL_COMMON (decl
))
1165 DECL_COMMON (decl
) = 0;
1167 /* Variables can't be both common and weak. */
1168 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1169 DECL_COMMON (decl
) = 0;
1171 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1172 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1175 enum machine_mode address_mode
= Pmode
;
1176 if (TREE_TYPE (decl
) != error_mark_node
)
1178 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1179 address_mode
= targetm
.addr_space
.address_mode (as
);
1181 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1183 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1184 SET_SYMBOL_REF_DECL (x
, decl
);
1186 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1187 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1188 set_mem_attributes (x
, decl
, 1);
1189 SET_DECL_RTL (decl
, x
);
1191 /* Optionally set flags or add text to the name to record information
1192 such as that it is a function name.
1193 If the name is changed, the macro ASM_OUTPUT_LABELREF
1194 will have to know how to strip this information. */
1195 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1197 /* Make this function static known to the mudflap runtime. */
1198 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1199 mudflap_enqueue_decl (decl
);
1202 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1203 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1207 make_decl_rtl_for_debug (tree decl
)
1209 unsigned int save_aliasing_flag
, save_mudflap_flag
;
1212 if (DECL_RTL_SET_P (decl
))
1213 return DECL_RTL (decl
);
1215 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1216 call new_alias_set. If running with -fcompare-debug, sometimes
1217 we do not want to create alias sets that will throw the alias
1218 numbers off in the comparison dumps. So... clearing
1219 flag_strict_aliasing will keep new_alias_set() from creating a
1220 new set. It is undesirable to register decl with mudflap
1221 in this case as well. */
1222 save_aliasing_flag
= flag_strict_aliasing
;
1223 flag_strict_aliasing
= 0;
1224 save_mudflap_flag
= flag_mudflap
;
1227 rtl
= DECL_RTL (decl
);
1228 /* Reset DECL_RTL back, as various parts of the compiler expects
1229 DECL_RTL set meaning it is actually going to be output. */
1230 SET_DECL_RTL (decl
, NULL
);
1232 flag_strict_aliasing
= save_aliasing_flag
;
1233 flag_mudflap
= save_mudflap_flag
;
1238 /* Output a string of literal assembler code
1239 for an `asm' keyword used between functions. */
1242 assemble_asm (tree string
)
1246 if (TREE_CODE (string
) == ADDR_EXPR
)
1247 string
= TREE_OPERAND (string
, 0);
1249 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1252 /* Record an element in the table of global destructors. SYMBOL is
1253 a SYMBOL_REF of the function to be called; PRIORITY is a number
1254 between 0 and MAX_INIT_PRIORITY. */
1257 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
1258 int priority ATTRIBUTE_UNUSED
)
1260 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1261 /* Tell GNU LD that this is part of the static destructor set.
1262 This will work for any system that uses stabs, most usefully
1264 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1265 dbxout_stab_value_label (XSTR (symbol
, 0));
1267 sorry ("global destructors not supported on this target");
1271 /* Write the address of the entity given by SYMBOL to SEC. */
1273 assemble_addr_to_section (rtx symbol
, section
*sec
)
1275 switch_to_section (sec
);
1276 assemble_align (POINTER_SIZE
);
1277 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1280 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1281 not) section for PRIORITY. */
1283 get_cdtor_priority_section (int priority
, bool constructor_p
)
1287 /* ??? This only works reliably with the GNU linker. */
1288 sprintf (buf
, "%s.%.5u",
1289 constructor_p
? ".ctors" : ".dtors",
1290 /* Invert the numbering so the linker puts us in the proper
1291 order; constructors are run from right to left, and the
1292 linker sorts in increasing order. */
1293 MAX_INIT_PRIORITY
- priority
);
1294 return get_section (buf
, SECTION_WRITE
, NULL
);
1298 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1302 if (priority
!= DEFAULT_INIT_PRIORITY
)
1303 sec
= get_cdtor_priority_section (priority
,
1304 /*constructor_p=*/false);
1306 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1308 assemble_addr_to_section (symbol
, sec
);
1311 #ifdef DTORS_SECTION_ASM_OP
1313 default_dtor_section_asm_out_destructor (rtx symbol
,
1314 int priority ATTRIBUTE_UNUSED
)
1316 assemble_addr_to_section (symbol
, dtors_section
);
1320 /* Likewise for global constructors. */
1323 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
1324 int priority ATTRIBUTE_UNUSED
)
1326 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1327 /* Tell GNU LD that this is part of the static destructor set.
1328 This will work for any system that uses stabs, most usefully
1330 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1331 dbxout_stab_value_label (XSTR (symbol
, 0));
1333 sorry ("global constructors not supported on this target");
1338 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1342 if (priority
!= DEFAULT_INIT_PRIORITY
)
1343 sec
= get_cdtor_priority_section (priority
,
1344 /*constructor_p=*/true);
1346 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1348 assemble_addr_to_section (symbol
, sec
);
1351 #ifdef CTORS_SECTION_ASM_OP
1353 default_ctor_section_asm_out_constructor (rtx symbol
,
1354 int priority ATTRIBUTE_UNUSED
)
1356 assemble_addr_to_section (symbol
, ctors_section
);
1360 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1361 a nonzero value if the constant pool should be output before the
1362 start of the function, or a zero value if the pool should output
1363 after the end of the function. The default is to put it before the
1366 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1367 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1370 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1371 to be output to assembler.
1372 Set first_global_object_name and weak_global_object_name as appropriate. */
1375 notice_global_symbol (tree decl
)
1377 const char **type
= &first_global_object_name
;
1379 if (first_global_object_name
1380 || !TREE_PUBLIC (decl
)
1381 || DECL_EXTERNAL (decl
)
1382 || !DECL_NAME (decl
)
1383 || (TREE_CODE (decl
) != FUNCTION_DECL
1384 && (TREE_CODE (decl
) != VAR_DECL
1385 || (DECL_COMMON (decl
)
1386 && (DECL_INITIAL (decl
) == 0
1387 || DECL_INITIAL (decl
) == error_mark_node
))))
1388 || !MEM_P (DECL_RTL (decl
)))
1391 /* We win when global object is found, but it is useful to know about weak
1392 symbol as well so we can produce nicer unique names. */
1393 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1394 type
= &weak_global_object_name
;
1400 rtx decl_rtl
= DECL_RTL (decl
);
1402 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1403 name
= ggc_strdup (p
);
1409 /* Output assembler code for the constant pool of a function and associated
1410 with defining the name of the function. DECL describes the function.
1411 NAME is the function's name. For the constant pool, we use the current
1412 constant pool data. */
1415 assemble_start_function (tree decl
, const char *fnname
)
1418 char tmp_label
[100];
1419 bool hot_label_written
= false;
1421 crtl
->subsections
.unlikely_text_section_name
= NULL
;
1423 first_function_block_is_cold
= false;
1424 if (flag_reorder_blocks_and_partition
)
1426 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1427 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1428 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1429 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1430 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1431 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1432 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1433 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1438 crtl
->subsections
.hot_section_label
= NULL
;
1439 crtl
->subsections
.cold_section_label
= NULL
;
1440 crtl
->subsections
.hot_section_end_label
= NULL
;
1441 crtl
->subsections
.cold_section_end_label
= NULL
;
1444 /* The following code does not need preprocessing in the assembler. */
1448 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1449 output_constant_pool (fnname
, decl
);
1451 resolve_unique_section (decl
, 0, flag_function_sections
);
1453 /* Make sure the not and cold text (code) sections are properly
1454 aligned. This is necessary here in the case where the function
1455 has both hot and cold sections, because we don't want to re-set
1456 the alignment when the section switch happens mid-function. */
1458 if (flag_reorder_blocks_and_partition
)
1460 switch_to_section (unlikely_text_section ());
1461 assemble_align (DECL_ALIGN (decl
));
1462 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1464 /* When the function starts with a cold section, we need to explicitly
1465 align the hot section and write out the hot section label.
1466 But if the current function is a thunk, we do not have a CFG. */
1468 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1470 switch_to_section (text_section
);
1471 assemble_align (DECL_ALIGN (decl
));
1472 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1473 hot_label_written
= true;
1474 first_function_block_is_cold
= true;
1477 else if (DECL_SECTION_NAME (decl
))
1479 /* Calls to function_section rely on first_function_block_is_cold
1480 being accurate. The first block may be cold even if we aren't
1481 doing partitioning, if the entire function was decided by
1482 choose_function_section (predict.c) to be cold. */
1484 initialize_cold_section_name ();
1486 if (crtl
->subsections
.unlikely_text_section_name
1487 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
1488 crtl
->subsections
.unlikely_text_section_name
) == 0)
1489 first_function_block_is_cold
= true;
1492 in_cold_section_p
= first_function_block_is_cold
;
1494 /* Switch to the correct text section for the start of the function. */
1496 switch_to_section (function_section (decl
));
1497 if (flag_reorder_blocks_and_partition
1498 && !hot_label_written
)
1499 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1501 /* Tell assembler to move to target machine's alignment for functions. */
1502 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1505 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1508 /* Handle a user-specified function alignment.
1509 Note that we still need to align to DECL_ALIGN, as above,
1510 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1511 if (! DECL_USER_ALIGN (decl
)
1512 && align_functions_log
> align
1513 && optimize_function_for_speed_p (cfun
))
1515 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1516 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1517 align_functions_log
, align_functions
- 1);
1519 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1523 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1524 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1527 if (!DECL_IGNORED_P (decl
))
1528 (*debug_hooks
->begin_function
) (decl
);
1530 /* Make function name accessible from other files, if appropriate. */
1532 if (TREE_PUBLIC (decl
))
1534 notice_global_symbol (decl
);
1536 globalize_decl (decl
);
1538 maybe_assemble_visibility (decl
);
1541 if (DECL_PRESERVE_P (decl
))
1542 targetm
.asm_out
.mark_decl_preserved (fnname
);
1544 /* Do any machine/system dependent processing of the function name. */
1545 #ifdef ASM_DECLARE_FUNCTION_NAME
1546 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1548 /* Standard thing is just output label for the function. */
1549 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file
, fnname
, current_function_decl
);
1550 #endif /* ASM_DECLARE_FUNCTION_NAME */
1553 /* Output assembler code associated with defining the size of the
1554 function. DECL describes the function. NAME is the function's name. */
1557 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1559 #ifdef ASM_DECLARE_FUNCTION_SIZE
1560 /* We could have switched section in the middle of the function. */
1561 if (flag_reorder_blocks_and_partition
)
1562 switch_to_section (function_section (decl
));
1563 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1565 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1567 output_constant_pool (fnname
, decl
);
1568 switch_to_section (function_section (decl
)); /* need to switch back */
1570 /* Output labels for end of hot/cold text sections (to be used by
1572 if (flag_reorder_blocks_and_partition
)
1574 section
*save_text_section
;
1576 save_text_section
= in_section
;
1577 switch_to_section (unlikely_text_section ());
1578 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1579 if (first_function_block_is_cold
)
1580 switch_to_section (text_section
);
1582 switch_to_section (function_section (decl
));
1583 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1584 switch_to_section (save_text_section
);
1588 /* Assemble code to leave SIZE bytes of zeros. */
1591 assemble_zeros (unsigned HOST_WIDE_INT size
)
1593 /* Do no output if -fsyntax-only. */
1594 if (flag_syntax_only
)
1597 #ifdef ASM_NO_SKIP_IN_TEXT
1598 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1599 so we must output 0s explicitly in the text section. */
1600 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1602 unsigned HOST_WIDE_INT i
;
1603 for (i
= 0; i
< size
; i
++)
1604 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1609 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1612 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1615 assemble_align (int align
)
1617 if (align
> BITS_PER_UNIT
)
1619 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1623 /* Assemble a string constant with the specified C string as contents. */
1626 assemble_string (const char *p
, int size
)
1631 /* If the string is very long, split it up. */
1635 int thissize
= size
- pos
;
1636 if (thissize
> maximum
)
1639 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1647 /* A noswitch_section_callback for lcomm_section. */
1650 emit_local (tree decl ATTRIBUTE_UNUSED
,
1651 const char *name ATTRIBUTE_UNUSED
,
1652 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1653 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1655 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1656 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1657 size
, DECL_ALIGN (decl
));
1659 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1660 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1663 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1668 /* A noswitch_section_callback for bss_noswitch_section. */
1670 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1672 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1673 const char *name ATTRIBUTE_UNUSED
,
1674 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1675 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1677 #if defined ASM_OUTPUT_ALIGNED_BSS
1678 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
, DECL_ALIGN (decl
));
1681 ASM_OUTPUT_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1687 /* A noswitch_section_callback for comm_section. */
1690 emit_common (tree decl ATTRIBUTE_UNUSED
,
1691 const char *name ATTRIBUTE_UNUSED
,
1692 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1693 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1695 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1696 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1697 size
, DECL_ALIGN (decl
));
1699 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1700 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1703 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1708 /* A noswitch_section_callback for tls_comm_section. */
1711 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
1712 const char *name ATTRIBUTE_UNUSED
,
1713 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1714 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1716 #ifdef ASM_OUTPUT_TLS_COMMON
1717 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
1720 sorry ("thread-local COMMON data not implemented");
1725 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1726 NAME is the name of DECL's SYMBOL_REF. */
1729 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
)
1731 unsigned HOST_WIDE_INT size
, rounded
;
1733 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1736 /* Don't allocate zero bytes of common,
1737 since that means "undefined external" in the linker. */
1741 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1742 so that each uninitialized object starts on such a boundary. */
1743 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1744 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1745 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1747 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
1748 && (unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
1749 warning (0, "requested alignment for %q+D is greater than "
1750 "implemented alignment of %wu", decl
, rounded
);
1753 /* A subroutine of assemble_variable. Output the label and contents of
1754 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1755 is as for assemble_variable. */
1758 assemble_variable_contents (tree decl
, const char *name
,
1759 bool dont_output_data
)
1761 /* Do any machine/system dependent processing of the object. */
1762 #ifdef ASM_DECLARE_OBJECT_NAME
1763 last_assemble_variable_decl
= decl
;
1764 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1766 /* Standard thing is just output label for the object. */
1767 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1768 #endif /* ASM_DECLARE_OBJECT_NAME */
1770 if (!dont_output_data
)
1772 if (DECL_INITIAL (decl
)
1773 && DECL_INITIAL (decl
) != error_mark_node
1774 && !initializer_zerop (DECL_INITIAL (decl
)))
1775 /* Output the actual data. */
1776 output_constant (DECL_INITIAL (decl
),
1777 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1780 /* Leave space for it. */
1781 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1785 /* Assemble everything that is needed for a variable or function declaration.
1786 Not used for automatic variables, and not used for function definitions.
1787 Should not be called for variables of incomplete structure type.
1789 TOP_LEVEL is nonzero if this variable has file scope.
1790 AT_END is nonzero if this is the special handling, at end of compilation,
1791 to define things that have had only tentative definitions.
1792 DONT_OUTPUT_DATA if nonzero means don't actually output the
1793 initial value (that will be done by the caller). */
1796 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
1797 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
1800 rtx decl_rtl
, symbol
;
1803 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1804 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
1806 /* Emulated TLS had better not get this far. */
1807 gcc_checking_assert (targetm
.have_tls
|| !DECL_THREAD_LOCAL_P (decl
));
1809 last_assemble_variable_decl
= 0;
1811 /* Normally no need to say anything here for external references,
1812 since assemble_external is called by the language-specific code
1813 when a declaration is first seen. */
1815 if (DECL_EXTERNAL (decl
))
1818 /* Do nothing for global register variables. */
1819 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
1821 TREE_ASM_WRITTEN (decl
) = 1;
1825 /* If type was incomplete when the variable was declared,
1826 see if it is complete now. */
1828 if (DECL_SIZE (decl
) == 0)
1829 layout_decl (decl
, 0);
1831 /* Still incomplete => don't allocate it; treat the tentative defn
1832 (which is what it must have been) as an `extern' reference. */
1834 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1836 error ("storage size of %q+D isn%'t known", decl
);
1837 TREE_ASM_WRITTEN (decl
) = 1;
1841 /* The first declaration of a variable that comes through this function
1842 decides whether it is global (in C, has external linkage)
1843 or local (in C, has internal linkage). So do nothing more
1844 if this function has already run. */
1846 if (TREE_ASM_WRITTEN (decl
))
1849 /* Make sure targetm.encode_section_info is invoked before we set
1851 decl_rtl
= DECL_RTL (decl
);
1853 TREE_ASM_WRITTEN (decl
) = 1;
1855 /* Do no output if -fsyntax-only. */
1856 if (flag_syntax_only
)
1859 if (! dont_output_data
1860 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1862 error ("size of variable %q+D is too large", decl
);
1866 gcc_assert (MEM_P (decl_rtl
));
1867 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
1868 symbol
= XEXP (decl_rtl
, 0);
1870 /* If this symbol belongs to the tree constant pool, output the constant
1871 if it hasn't already been written. */
1872 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
1874 tree decl
= SYMBOL_REF_DECL (symbol
);
1875 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
1876 output_constant_def_contents (symbol
);
1882 name
= XSTR (symbol
, 0);
1883 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1884 notice_global_symbol (decl
);
1886 /* Compute the alignment of this data. */
1888 align_variable (decl
, dont_output_data
);
1889 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
1891 if (TREE_PUBLIC (decl
))
1892 maybe_assemble_visibility (decl
);
1894 if (DECL_PRESERVE_P (decl
))
1895 targetm
.asm_out
.mark_decl_preserved (name
);
1897 /* First make the assembler name(s) global if appropriate. */
1898 sect
= get_variable_section (decl
, false);
1899 if (TREE_PUBLIC (decl
)
1900 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
1901 globalize_decl (decl
);
1903 /* Output any data that we will need to use the address of. */
1904 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
1905 output_addressed_constants (DECL_INITIAL (decl
));
1907 /* dbxout.c needs to know this. */
1908 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
1909 DECL_IN_TEXT_SECTION (decl
) = 1;
1911 /* If the decl is part of an object_block, make sure that the decl
1912 has been positioned within its block, but do not write out its
1913 definition yet. output_object_blocks will do that later. */
1914 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
1916 gcc_assert (!dont_output_data
);
1917 place_block_symbol (symbol
);
1919 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1920 assemble_noswitch_variable (decl
, name
, sect
);
1923 switch_to_section (sect
);
1924 if (DECL_ALIGN (decl
) > BITS_PER_UNIT
)
1925 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
1926 assemble_variable_contents (decl
, name
, dont_output_data
);
1930 /* Return 1 if type TYPE contains any pointers. */
1933 contains_pointers_p (tree type
)
1935 switch (TREE_CODE (type
))
1938 case REFERENCE_TYPE
:
1939 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1940 so I'll play safe and return 1. */
1946 case QUAL_UNION_TYPE
:
1949 /* For a type that has fields, see if the fields have pointers. */
1950 for (fields
= TYPE_FIELDS (type
); fields
; fields
= DECL_CHAIN (fields
))
1951 if (TREE_CODE (fields
) == FIELD_DECL
1952 && contains_pointers_p (TREE_TYPE (fields
)))
1958 /* An array type contains pointers if its element type does. */
1959 return contains_pointers_p (TREE_TYPE (type
));
1966 /* We delay assemble_external processing until
1967 the compilation unit is finalized. This is the best we can do for
1968 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
1969 it all the way to final. See PR 17982 for further discussion. */
1970 static GTY(()) tree pending_assemble_externals
;
1972 #ifdef ASM_OUTPUT_EXTERNAL
1973 /* True if DECL is a function decl for which no out-of-line copy exists.
1974 It is assumed that DECL's assembler name has been set. */
1977 incorporeal_function_p (tree decl
)
1979 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
1983 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
1984 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
1987 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1988 if (is_builtin_name (name
))
1994 /* Actually do the tests to determine if this is necessary, and invoke
1995 ASM_OUTPUT_EXTERNAL. */
1997 assemble_external_real (tree decl
)
1999 rtx rtl
= DECL_RTL (decl
);
2001 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2002 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2003 && !incorporeal_function_p (decl
))
2005 /* Some systems do require some output. */
2006 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2007 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2013 process_pending_assemble_externals (void)
2015 #ifdef ASM_OUTPUT_EXTERNAL
2017 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2018 assemble_external_real (TREE_VALUE (list
));
2020 pending_assemble_externals
= 0;
2024 /* This TREE_LIST contains any weak symbol declarations waiting
2026 static GTY(()) tree weak_decls
;
2028 /* Output something to declare an external symbol to the assembler,
2029 and qualifiers such as weakness. (Most assemblers don't need
2030 extern declaration, so we normally output nothing.) Do nothing if
2031 DECL is not external. */
2034 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2036 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2037 main body of this code is only rarely exercised. To provide some
2038 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2039 open. If it's not, we should not be calling this function. */
2040 gcc_assert (asm_out_file
);
2042 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2045 /* We want to output annotation for weak and external symbols at
2046 very last to check if they are references or not. */
2050 /* TREE_STATIC is a weird and abused creature which is not
2051 generally the right test for whether an entity has been
2052 locally emitted, inlined or otherwise not-really-extern, but
2053 for declarations that can be weak, it happens to be
2055 && !TREE_STATIC (decl
)
2056 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2057 && value_member (decl
, weak_decls
) == NULL_TREE
)
2058 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2060 #ifdef ASM_OUTPUT_EXTERNAL
2061 if (value_member (decl
, pending_assemble_externals
) == NULL_TREE
)
2062 pending_assemble_externals
= tree_cons (NULL
, decl
,
2063 pending_assemble_externals
);
2067 /* Similar, for calling a library function FUN. */
2070 assemble_external_libcall (rtx fun
)
2072 /* Declare library function name external when first used, if nec. */
2073 if (! SYMBOL_REF_USED (fun
))
2075 SYMBOL_REF_USED (fun
) = 1;
2076 targetm
.asm_out
.external_libcall (fun
);
2080 /* Assemble a label named NAME. */
2083 assemble_label (FILE *file
, const char *name
)
2085 ASM_OUTPUT_LABEL (file
, name
);
2088 /* Set the symbol_referenced flag for ID. */
2090 mark_referenced (tree id
)
2092 TREE_SYMBOL_REFERENCED (id
) = 1;
2095 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2097 mark_decl_referenced (tree decl
)
2099 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2101 /* Extern inline functions don't become needed when referenced.
2102 If we know a method will be emitted in other TU and no new
2103 functions can be marked reachable, just use the external
2105 struct cgraph_node
*node
= cgraph_node (decl
);
2106 if (!DECL_EXTERNAL (decl
)
2107 && (!node
->local
.vtable_method
|| !cgraph_global_info_ready
2108 || !node
->local
.finalized
))
2109 cgraph_mark_needed_node (node
);
2111 else if (TREE_CODE (decl
) == VAR_DECL
)
2113 struct varpool_node
*node
= varpool_node (decl
);
2114 varpool_mark_needed_node (node
);
2115 /* C++ frontend use mark_decl_references to force COMDAT variables
2116 to be output that might appear dead otherwise. */
2117 node
->force_output
= true;
2119 /* else do nothing - we can get various sorts of CST nodes here,
2120 which do not need to be marked. */
2124 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2125 until we find an identifier that is not itself a transparent alias.
2126 Modify the alias passed to it by reference (and all aliases on the
2127 way to the ultimate target), such that they do not have to be
2128 followed again, and return the ultimate target of the alias
2132 ultimate_transparent_alias_target (tree
*alias
)
2134 tree target
= *alias
;
2136 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2138 gcc_assert (TREE_CHAIN (target
));
2139 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2140 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2141 && ! TREE_CHAIN (target
));
2148 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2149 starts with a *, the rest of NAME is output verbatim. Otherwise
2150 NAME is transformed in a target-specific way (usually by the
2151 addition of an underscore). */
2154 assemble_name_raw (FILE *file
, const char *name
)
2157 fputs (&name
[1], file
);
2159 ASM_OUTPUT_LABELREF (file
, name
);
2162 /* Like assemble_name_raw, but should be used when NAME might refer to
2163 an entity that is also represented as a tree (like a function or
2164 variable). If NAME does refer to such an entity, that entity will
2165 be marked as referenced. */
2168 assemble_name (FILE *file
, const char *name
)
2170 const char *real_name
;
2173 real_name
= targetm
.strip_name_encoding (name
);
2175 id
= maybe_get_identifier (real_name
);
2180 mark_referenced (id
);
2181 ultimate_transparent_alias_target (&id
);
2183 name
= IDENTIFIER_POINTER (id
);
2184 gcc_assert (! TREE_CHAIN (id
));
2187 assemble_name_raw (file
, name
);
2190 /* Allocate SIZE bytes writable static space with a gensym name
2191 and return an RTX to refer to its address. */
2194 assemble_static_space (unsigned HOST_WIDE_INT size
)
2197 const char *namestring
;
2200 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2202 namestring
= ggc_strdup (name
);
2204 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2205 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2207 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2208 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2211 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2212 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2215 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2216 so that each uninitialized object starts on such a boundary. */
2217 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2218 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2219 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2220 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2221 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2222 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2229 /* Assemble the static constant template for function entry trampolines.
2230 This is done at most once per compilation.
2231 Returns an RTX for the address of the template. */
2233 static GTY(()) rtx initial_trampoline
;
2236 assemble_trampoline_template (void)
2243 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2245 if (initial_trampoline
)
2246 return initial_trampoline
;
2248 /* By default, put trampoline templates in read-only data section. */
2250 #ifdef TRAMPOLINE_SECTION
2251 switch_to_section (TRAMPOLINE_SECTION
);
2253 switch_to_section (readonly_data_section
);
2256 /* Write the assembler code to define one. */
2257 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2259 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2261 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2262 targetm
.asm_out
.trampoline_template (asm_out_file
);
2264 /* Record the rtl to refer to it. */
2265 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2266 name
= ggc_strdup (label
);
2267 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2268 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2270 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2271 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2272 set_mem_size (initial_trampoline
, GEN_INT (TRAMPOLINE_SIZE
));
2274 return initial_trampoline
;
2277 /* A and B are either alignments or offsets. Return the minimum alignment
2278 that may be assumed after adding the two together. */
2280 static inline unsigned
2281 min_align (unsigned int a
, unsigned int b
)
2283 return (a
| b
) & -(a
| b
);
2286 /* Return the assembler directive for creating a given kind of integer
2287 object. SIZE is the number of bytes in the object and ALIGNED_P
2288 indicates whether it is known to be aligned. Return NULL if the
2289 assembly dialect has no such directive.
2291 The returned string should be printed at the start of a new line and
2292 be followed immediately by the object's initial value. */
2295 integer_asm_op (int size
, int aligned_p
)
2297 struct asm_int_op
*ops
;
2300 ops
= &targetm
.asm_out
.aligned_op
;
2302 ops
= &targetm
.asm_out
.unaligned_op
;
2307 return targetm
.asm_out
.byte_op
;
2321 /* Use directive OP to assemble an integer object X. Print OP at the
2322 start of the line, followed immediately by the value of X. */
2325 assemble_integer_with_op (const char *op
, rtx x
)
2327 fputs (op
, asm_out_file
);
2328 output_addr_const (asm_out_file
, x
);
2329 fputc ('\n', asm_out_file
);
2332 /* The default implementation of the asm_out.integer target hook. */
2335 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2336 unsigned int size ATTRIBUTE_UNUSED
,
2337 int aligned_p ATTRIBUTE_UNUSED
)
2339 const char *op
= integer_asm_op (size
, aligned_p
);
2340 /* Avoid GAS bugs for large values. Specifically negative values whose
2341 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2342 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2344 return op
&& (assemble_integer_with_op (op
, x
), true);
2347 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2348 the alignment of the integer in bits. Return 1 if we were able to output
2349 the constant, otherwise 0. We must be able to output the constant,
2350 if FORCE is nonzero. */
2353 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2357 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2359 /* See if the target hook can handle this kind of object. */
2360 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2363 /* If the object is a multi-byte one, try splitting it up. Split
2364 it into words it if is multi-word, otherwise split it into bytes. */
2367 enum machine_mode omode
, imode
;
2368 unsigned int subalign
;
2369 unsigned int subsize
, i
;
2370 enum mode_class mclass
;
2372 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2373 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2374 if (GET_CODE (x
) == CONST_FIXED
)
2375 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2379 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2380 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2382 for (i
= 0; i
< size
; i
+= subsize
)
2384 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2385 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2391 /* If we've printed some of it, but not all of it, there's no going
2396 gcc_assert (!force
);
2402 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2404 long data
[4] = {0, 0, 0, 0};
2406 int bitsize
, nelts
, nunits
, units_per
;
2408 /* This is hairy. We have a quantity of known size. real_to_target
2409 will put it into an array of *host* longs, 32 bits per element
2410 (even if long is more than 32 bits). We need to determine the
2411 number of array elements that are occupied (nelts) and the number
2412 of *target* min-addressable units that will be occupied in the
2413 object file (nunits). We cannot assume that 32 divides the
2414 mode's bitsize (size * BITS_PER_UNIT) evenly.
2416 size * BITS_PER_UNIT is used here to make sure that padding bits
2417 (which might appear at either end of the value; real_to_target
2418 will include the padding bits in its output array) are included. */
2420 nunits
= GET_MODE_SIZE (mode
);
2421 bitsize
= nunits
* BITS_PER_UNIT
;
2422 nelts
= CEIL (bitsize
, 32);
2423 units_per
= 32 / BITS_PER_UNIT
;
2425 real_to_target (data
, &d
, mode
);
2427 /* Put out the first word with the specified alignment. */
2428 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2429 nunits
-= units_per
;
2431 /* Subsequent words need only 32-bit alignment. */
2432 align
= min_align (align
, 32);
2434 for (i
= 1; i
< nelts
; i
++)
2436 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2437 nunits
-= units_per
;
2441 /* Given an expression EXP with a constant value,
2442 reduce it to the sum of an assembler symbol and an integer.
2443 Store them both in the structure *VALUE.
2444 EXP must be reducible. */
2446 struct GTY(()) addr_const
{
2448 HOST_WIDE_INT offset
;
2452 decode_addr_const (tree exp
, struct addr_const
*value
)
2454 tree target
= TREE_OPERAND (exp
, 0);
2460 if (TREE_CODE (target
) == COMPONENT_REF
2461 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2463 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2464 target
= TREE_OPERAND (target
, 0);
2466 else if (TREE_CODE (target
) == ARRAY_REF
2467 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2469 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2470 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2471 target
= TREE_OPERAND (target
, 0);
2473 else if (TREE_CODE (target
) == INDIRECT_REF
2474 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2475 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2477 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2482 switch (TREE_CODE (target
))
2486 x
= DECL_RTL (target
);
2490 x
= gen_rtx_MEM (FUNCTION_MODE
,
2491 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2500 x
= output_constant_def (target
, 1);
2507 gcc_assert (MEM_P (x
));
2511 value
->offset
= offset
;
2515 static GTY((param_is (struct constant_descriptor_tree
)))
2516 htab_t const_desc_htab
;
2518 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2520 /* Constant pool accessor function. */
2523 constant_pool_htab (void)
2525 return const_desc_htab
;
2528 /* Compute a hash code for a constant expression. */
2531 const_desc_hash (const void *ptr
)
2533 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2537 const_hash_1 (const tree exp
)
2542 enum tree_code code
= TREE_CODE (exp
);
2544 /* Either set P and LEN to the address and len of something to hash and
2545 exit the switch or return a value. */
2550 p
= (char *) &TREE_INT_CST (exp
);
2551 len
= sizeof TREE_INT_CST (exp
);
2555 return real_hash (TREE_REAL_CST_PTR (exp
));
2558 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2561 p
= TREE_STRING_POINTER (exp
);
2562 len
= TREE_STRING_LENGTH (exp
);
2566 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2567 + const_hash_1 (TREE_IMAGPART (exp
)));
2573 hi
= 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
));
2575 for (link
= TREE_VECTOR_CST_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2576 hi
= hi
* 563 + const_hash_1 (TREE_VALUE (link
));
2583 unsigned HOST_WIDE_INT idx
;
2586 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2588 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2590 hi
= hi
* 603 + const_hash_1 (value
);
2598 struct addr_const value
;
2600 decode_addr_const (exp
, &value
);
2601 switch (GET_CODE (value
.base
))
2604 /* Don't hash the address of the SYMBOL_REF;
2605 only use the offset and the symbol name. */
2607 p
= XSTR (value
.base
, 0);
2608 for (i
= 0; p
[i
] != 0; i
++)
2609 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2613 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2623 case POINTER_PLUS_EXPR
:
2625 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2626 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2629 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2632 /* A language specific constant. Just hash the code. */
2636 /* Compute hashing function. */
2638 for (i
= 0; i
< len
; i
++)
2639 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2644 /* Wrapper of compare_constant, for the htab interface. */
2646 const_desc_eq (const void *p1
, const void *p2
)
2648 const struct constant_descriptor_tree
*const c1
2649 = (const struct constant_descriptor_tree
*) p1
;
2650 const struct constant_descriptor_tree
*const c2
2651 = (const struct constant_descriptor_tree
*) p2
;
2652 if (c1
->hash
!= c2
->hash
)
2654 return compare_constant (c1
->value
, c2
->value
);
2657 /* Compare t1 and t2, and return 1 only if they are known to result in
2658 the same bit pattern on output. */
2661 compare_constant (const tree t1
, const tree t2
)
2663 enum tree_code typecode
;
2665 if (t1
== NULL_TREE
)
2666 return t2
== NULL_TREE
;
2667 if (t2
== NULL_TREE
)
2670 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2673 switch (TREE_CODE (t1
))
2676 /* Integer constants are the same only if the same width of type. */
2677 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2679 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2681 return tree_int_cst_equal (t1
, t2
);
2684 /* Real constants are the same only if the same width of type. */
2685 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2688 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2691 /* Fixed constants are the same only if the same width of type. */
2692 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2695 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
2698 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2701 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2702 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2703 TREE_STRING_LENGTH (t1
)));
2706 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2707 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2713 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1
))
2714 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2
)))
2717 link2
= TREE_VECTOR_CST_ELTS (t2
);
2718 for (link1
= TREE_VECTOR_CST_ELTS (t1
);
2720 link1
= TREE_CHAIN (link1
))
2722 if (!compare_constant (TREE_VALUE (link1
), TREE_VALUE (link2
)))
2724 link2
= TREE_CHAIN (link2
);
2732 VEC(constructor_elt
, gc
) *v1
, *v2
;
2733 unsigned HOST_WIDE_INT idx
;
2735 typecode
= TREE_CODE (TREE_TYPE (t1
));
2736 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
2739 if (typecode
== ARRAY_TYPE
)
2741 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
2742 /* For arrays, check that the sizes all match. */
2743 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
2745 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
2750 /* For record and union constructors, require exact type
2752 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
2756 v1
= CONSTRUCTOR_ELTS (t1
);
2757 v2
= CONSTRUCTOR_ELTS (t2
);
2758 if (VEC_length (constructor_elt
, v1
)
2759 != VEC_length (constructor_elt
, v2
))
2762 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
2764 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
2765 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
2767 /* Check that each value is the same... */
2768 if (!compare_constant (c1
->value
, c2
->value
))
2770 /* ... and that they apply to the same fields! */
2771 if (typecode
== ARRAY_TYPE
)
2773 if (!compare_constant (c1
->index
, c2
->index
))
2778 if (c1
->index
!= c2
->index
)
2789 struct addr_const value1
, value2
;
2793 decode_addr_const (t1
, &value1
);
2794 decode_addr_const (t2
, &value2
);
2796 if (value1
.offset
!= value2
.offset
)
2799 code
= GET_CODE (value1
.base
);
2800 if (code
!= GET_CODE (value2
.base
))
2806 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
2810 ret
= (CODE_LABEL_NUMBER (XEXP (value1
.base
, 0))
2811 == CODE_LABEL_NUMBER (XEXP (value2
.base
, 0)));
2821 case POINTER_PLUS_EXPR
:
2824 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2825 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2828 case VIEW_CONVERT_EXPR
:
2829 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2838 /* Make a copy of the whole tree structure for a constant. This
2839 handles the same types of nodes that compare_constant handles. */
2842 copy_constant (tree exp
)
2844 switch (TREE_CODE (exp
))
2847 /* For ADDR_EXPR, we do not want to copy the decl whose address
2848 is requested. We do want to copy constants though. */
2849 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
2850 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2851 copy_constant (TREE_OPERAND (exp
, 0)));
2853 return copy_node (exp
);
2859 return copy_node (exp
);
2862 return build_complex (TREE_TYPE (exp
),
2863 copy_constant (TREE_REALPART (exp
)),
2864 copy_constant (TREE_IMAGPART (exp
)));
2867 case POINTER_PLUS_EXPR
:
2869 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
2870 copy_constant (TREE_OPERAND (exp
, 0)),
2871 copy_constant (TREE_OPERAND (exp
, 1)));
2874 case VIEW_CONVERT_EXPR
:
2875 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2876 copy_constant (TREE_OPERAND (exp
, 0)));
2879 return build_vector (TREE_TYPE (exp
),
2880 copy_list (TREE_VECTOR_CST_ELTS (exp
)));
2884 tree copy
= copy_node (exp
);
2885 VEC(constructor_elt
, gc
) *v
;
2886 unsigned HOST_WIDE_INT idx
;
2887 tree purpose
, value
;
2889 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
2890 CONSTRUCTOR_ELTS (exp
)));
2891 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
2893 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
2894 ce
->index
= purpose
;
2895 ce
->value
= copy_constant (value
);
2897 CONSTRUCTOR_ELTS (copy
) = v
;
2906 /* Return the section into which constant EXP should be placed. */
2909 get_constant_section (tree exp
, unsigned int align
)
2911 return targetm
.asm_out
.select_section (exp
,
2912 compute_reloc_for_constant (exp
),
2916 /* Return the size of constant EXP in bytes. */
2918 static HOST_WIDE_INT
2919 get_constant_size (tree exp
)
2923 size
= int_size_in_bytes (TREE_TYPE (exp
));
2924 if (TREE_CODE (exp
) == STRING_CST
)
2925 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
2929 /* Subroutine of output_constant_def:
2930 No constant equal to EXP is known to have been output.
2931 Make a constant descriptor to enter EXP in the hash table.
2932 Assign the label number and construct RTL to refer to the
2933 constant's location in memory.
2934 Caller is responsible for updating the hash table. */
2936 static struct constant_descriptor_tree
*
2937 build_constant_desc (tree exp
)
2939 struct constant_descriptor_tree
*desc
;
2945 desc
= ggc_alloc_constant_descriptor_tree ();
2946 desc
->value
= copy_constant (exp
);
2948 /* Propagate marked-ness to copied constant. */
2949 if (flag_mudflap
&& mf_marked_p (exp
))
2950 mf_mark (desc
->value
);
2952 /* Create a string containing the label name, in LABEL. */
2953 labelno
= const_labelno
++;
2954 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
2956 /* Construct the VAR_DECL associated with the constant. */
2957 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
2959 DECL_ARTIFICIAL (decl
) = 1;
2960 DECL_IGNORED_P (decl
) = 1;
2961 TREE_READONLY (decl
) = 1;
2962 TREE_STATIC (decl
) = 1;
2963 TREE_ADDRESSABLE (decl
) = 1;
2964 /* We don't set the RTL yet as this would cause varpool to assume that the
2965 variable is referenced. Moreover, it would just be dropped in LTO mode.
2966 Instead we set the flag that will be recognized in make_decl_rtl. */
2967 DECL_IN_CONSTANT_POOL (decl
) = 1;
2968 DECL_INITIAL (decl
) = desc
->value
;
2969 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
2970 architectures so use DATA_ALIGNMENT as well, except for strings. */
2971 if (TREE_CODE (exp
) == STRING_CST
)
2973 #ifdef CONSTANT_ALIGNMENT
2974 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
2978 align_variable (decl
, 0);
2980 /* Now construct the SYMBOL_REF and the MEM. */
2981 if (use_object_blocks_p ())
2983 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
2984 symbol
= create_block_symbol (ggc_strdup (label
),
2985 get_block_for_section (sect
), -1);
2988 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
2989 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
2990 SET_SYMBOL_REF_DECL (symbol
, decl
);
2991 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
2993 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
2994 set_mem_attributes (rtl
, exp
, 1);
2995 set_mem_alias_set (rtl
, 0);
2996 set_mem_alias_set (rtl
, const_alias_set
);
2998 /* We cannot share RTX'es in pool entries.
2999 Mark this piece of RTL as required for unsharing. */
3000 RTX_FLAG (rtl
, used
) = 1;
3002 /* Set flags or add text to the name to record information, such as
3003 that it is a local symbol. If the name is changed, the macro
3004 ASM_OUTPUT_LABELREF will have to know how to strip this
3005 information. This call might invalidate our local variable
3006 SYMBOL; we can't use it afterward. */
3007 targetm
.encode_section_info (exp
, rtl
, true);
3014 /* Return an rtx representing a reference to constant data in memory
3015 for the constant expression EXP.
3017 If assembler code for such a constant has already been output,
3018 return an rtx to refer to it.
3019 Otherwise, output such a constant in memory
3020 and generate an rtx for it.
3022 If DEFER is nonzero, this constant can be deferred and output only
3023 if referenced in the function after all optimizations.
3025 `const_desc_table' records which constants already have label strings. */
3028 output_constant_def (tree exp
, int defer
)
3030 struct constant_descriptor_tree
*desc
;
3031 struct constant_descriptor_tree key
;
3034 /* Look up EXP in the table of constant descriptors. If we didn't find
3035 it, create a new one. */
3037 key
.hash
= const_hash_1 (exp
);
3038 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3040 desc
= (struct constant_descriptor_tree
*) *loc
;
3043 desc
= build_constant_desc (exp
);
3044 desc
->hash
= key
.hash
;
3048 maybe_output_constant_def_contents (desc
, defer
);
3052 /* Subroutine of output_constant_def: Decide whether or not we need to
3053 output the constant DESC now, and if so, do it. */
3055 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3058 rtx symbol
= XEXP (desc
->rtl
, 0);
3059 tree exp
= desc
->value
;
3061 if (flag_syntax_only
)
3064 if (TREE_ASM_WRITTEN (exp
))
3065 /* Already output; don't do it again. */
3068 /* We can always defer constants as long as the context allows
3072 /* Increment n_deferred_constants if it exists. It needs to be at
3073 least as large as the number of constants actually referred to
3074 by the function. If it's too small we'll stop looking too early
3075 and fail to emit constants; if it's too large we'll only look
3076 through the entire function when we could have stopped earlier. */
3078 n_deferred_constants
++;
3082 output_constant_def_contents (symbol
);
3085 /* Subroutine of output_constant_def_contents. Output the definition
3086 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3087 constant's alignment in bits. */
3090 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3094 size
= get_constant_size (exp
);
3096 /* Do any machine/system dependent processing of the constant. */
3097 targetm
.asm_out
.declare_constant_name (asm_out_file
, label
, exp
, size
);
3099 /* Output the value of EXP. */
3100 output_constant (exp
, size
, align
);
3103 /* We must output the constant data referred to by SYMBOL; do so. */
3106 output_constant_def_contents (rtx symbol
)
3108 tree decl
= SYMBOL_REF_DECL (symbol
);
3109 tree exp
= DECL_INITIAL (decl
);
3112 /* Make sure any other constants whose addresses appear in EXP
3113 are assigned label numbers. */
3114 output_addressed_constants (exp
);
3116 /* We are no longer deferring this constant. */
3117 TREE_ASM_WRITTEN (exp
) = 1;
3119 /* If the constant is part of an object block, make sure that the
3120 decl has been positioned within its block, but do not write out
3121 its definition yet. output_object_blocks will do that later. */
3122 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3123 place_block_symbol (symbol
);
3126 align
= DECL_ALIGN (decl
);
3127 switch_to_section (get_constant_section (exp
, align
));
3128 if (align
> BITS_PER_UNIT
)
3129 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3130 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3133 mudflap_enqueue_constant (exp
);
3136 /* Look up EXP in the table of constant descriptors. Return the rtl
3137 if it has been emitted, else null. */
3140 lookup_constant_def (tree exp
)
3142 struct constant_descriptor_tree
*desc
;
3143 struct constant_descriptor_tree key
;
3146 key
.hash
= const_hash_1 (exp
);
3147 desc
= (struct constant_descriptor_tree
*)
3148 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3150 return (desc
? desc
->rtl
: NULL_RTX
);
3153 /* Return a tree representing a reference to constant data in memory
3154 for the constant expression EXP.
3156 This is the counterpart of output_constant_def at the Tree level. */
3159 tree_output_constant_def (tree exp
)
3161 struct constant_descriptor_tree
*desc
, key
;
3165 /* Look up EXP in the table of constant descriptors. If we didn't find
3166 it, create a new one. */
3168 key
.hash
= const_hash_1 (exp
);
3169 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3171 desc
= (struct constant_descriptor_tree
*) *loc
;
3174 desc
= build_constant_desc (exp
);
3175 desc
->hash
= key
.hash
;
3179 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3180 varpool_finalize_decl (decl
);
3184 /* Used in the hash tables to avoid outputting the same constant
3185 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3186 are output once per function, not once per file. */
3187 /* ??? Only a few targets need per-function constant pools. Most
3188 can use one per-file pool. Should add a targetm bit to tell the
3191 struct GTY(()) rtx_constant_pool
{
3192 /* Pointers to first and last constant in pool, as ordered by offset. */
3193 struct constant_descriptor_rtx
*first
;
3194 struct constant_descriptor_rtx
*last
;
3196 /* Hash facility for making memory-constants from constant rtl-expressions.
3197 It is used on RISC machines where immediate integer arguments and
3198 constant addresses are restricted so that such constants must be stored
3200 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3202 /* Current offset in constant pool (does not include any
3203 machine-specific header). */
3204 HOST_WIDE_INT offset
;
3207 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3208 struct constant_descriptor_rtx
*next
;
3212 HOST_WIDE_INT offset
;
3214 enum machine_mode mode
;
3220 /* Hash and compare functions for const_rtx_htab. */
3223 const_desc_rtx_hash (const void *ptr
)
3225 const struct constant_descriptor_rtx
*const desc
3226 = (const struct constant_descriptor_rtx
*) ptr
;
3231 const_desc_rtx_eq (const void *a
, const void *b
)
3233 const struct constant_descriptor_rtx
*const x
3234 = (const struct constant_descriptor_rtx
*) a
;
3235 const struct constant_descriptor_rtx
*const y
3236 = (const struct constant_descriptor_rtx
*) b
;
3238 if (x
->mode
!= y
->mode
)
3240 return rtx_equal_p (x
->constant
, y
->constant
);
3243 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3246 const_rtx_hash_1 (rtx
*xp
, void *data
)
3248 unsigned HOST_WIDE_INT hwi
;
3249 enum machine_mode mode
;
3255 code
= GET_CODE (x
);
3256 mode
= GET_MODE (x
);
3257 h
= (hashval_t
) code
* 1048573 + mode
;
3265 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3266 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3269 h
^= (hashval_t
) hwi
;
3270 for (i
= 1; i
< n
; ++i
)
3273 h
^= (hashval_t
) hwi
;
3279 if (mode
== VOIDmode
)
3281 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3285 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3289 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3295 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3296 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3301 h
^= htab_hash_string (XSTR (x
, 0));
3305 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3309 case UNSPEC_VOLATILE
:
3310 h
= h
* 251 + XINT (x
, 1);
3317 hp
= (hashval_t
*) data
;
3318 *hp
= *hp
* 509 + h
;
3322 /* Compute a hash value for X, which should be a constant. */
3325 const_rtx_hash (rtx x
)
3328 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3333 /* Create and return a new rtx constant pool. */
3335 static struct rtx_constant_pool
*
3336 create_constant_pool (void)
3338 struct rtx_constant_pool
*pool
;
3340 pool
= ggc_alloc_rtx_constant_pool ();
3341 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3342 const_desc_rtx_eq
, NULL
);
3349 /* Initialize constant pool hashing for a new function. */
3352 init_varasm_status (void)
3354 crtl
->varasm
.pool
= create_constant_pool ();
3355 crtl
->varasm
.deferred_constants
= 0;
3358 /* Given a MINUS expression, simplify it if both sides
3359 include the same symbol. */
3362 simplify_subtraction (rtx x
)
3364 rtx r
= simplify_rtx (x
);
3368 /* Given a constant rtx X, make (or find) a memory constant for its value
3369 and return a MEM rtx to refer to it in memory. */
3372 force_const_mem (enum machine_mode mode
, rtx x
)
3374 struct constant_descriptor_rtx
*desc
, tmp
;
3375 struct rtx_constant_pool
*pool
;
3382 /* If we're not allowed to drop X into the constant pool, don't. */
3383 if (targetm
.cannot_force_const_mem (x
))
3386 /* Record that this function has used a constant pool entry. */
3387 crtl
->uses_const_pool
= 1;
3389 /* Decide which pool to use. */
3390 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3391 ? shared_constant_pool
3392 : crtl
->varasm
.pool
);
3394 /* Lookup the value in the hashtable. */
3397 hash
= const_rtx_hash (x
);
3398 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3399 desc
= (struct constant_descriptor_rtx
*) *slot
;
3401 /* If the constant was already present, return its memory. */
3403 return copy_rtx (desc
->mem
);
3405 /* Otherwise, create a new descriptor. */
3406 desc
= ggc_alloc_constant_descriptor_rtx ();
3409 /* Align the location counter as required by EXP's data type. */
3410 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3411 #ifdef CONSTANT_ALIGNMENT
3413 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3414 if (type
!= NULL_TREE
)
3415 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3419 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3420 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3423 desc
->constant
= tmp
.constant
;
3424 desc
->offset
= pool
->offset
;
3427 desc
->align
= align
;
3428 desc
->labelno
= const_labelno
;
3431 pool
->offset
+= GET_MODE_SIZE (mode
);
3433 pool
->last
->next
= desc
;
3435 pool
->first
= pool
->last
= desc
;
3438 /* Create a string containing the label name, in LABEL. */
3439 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3442 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3443 the constants pool. */
3444 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3446 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3447 symbol
= create_block_symbol (ggc_strdup (label
),
3448 get_block_for_section (sect
), -1);
3451 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3453 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3454 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3455 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3457 /* Construct the MEM. */
3458 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3459 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3460 set_mem_align (def
, align
);
3462 /* If we're dropping a label to the constant pool, make sure we
3464 if (GET_CODE (x
) == LABEL_REF
)
3465 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3467 return copy_rtx (def
);
3470 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3473 get_pool_constant (rtx addr
)
3475 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3478 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3479 and whether it has been output or not. */
3482 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3484 struct constant_descriptor_rtx
*desc
;
3486 desc
= SYMBOL_REF_CONSTANT (addr
);
3487 *pmarked
= (desc
->mark
!= 0);
3488 return desc
->constant
;
3491 /* Similar, return the mode. */
3494 get_pool_mode (const_rtx addr
)
3496 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3499 /* Return the size of the constant pool. */
3502 get_pool_size (void)
3504 return crtl
->varasm
.pool
->offset
;
3507 /* Worker function for output_constant_pool_1. Emit assembly for X
3508 in MODE with known alignment ALIGN. */
3511 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3513 switch (GET_MODE_CLASS (mode
))
3516 case MODE_DECIMAL_FLOAT
:
3520 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3521 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3522 assemble_real (r
, mode
, align
);
3527 case MODE_PARTIAL_INT
:
3532 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3535 case MODE_VECTOR_FLOAT
:
3536 case MODE_VECTOR_INT
:
3537 case MODE_VECTOR_FRACT
:
3538 case MODE_VECTOR_UFRACT
:
3539 case MODE_VECTOR_ACCUM
:
3540 case MODE_VECTOR_UACCUM
:
3543 enum machine_mode submode
= GET_MODE_INNER (mode
);
3544 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3546 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3547 units
= CONST_VECTOR_NUNITS (x
);
3549 for (i
= 0; i
< units
; i
++)
3551 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3552 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3562 /* Worker function for output_constant_pool. Emit constant DESC,
3563 giving it ALIGN bits of alignment. */
3566 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3573 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3574 whose CODE_LABEL has been deleted. This can occur if a jump table
3575 is eliminated by optimization. If so, write a constant of zero
3576 instead. Note that this can also happen by turning the
3577 CODE_LABEL into a NOTE. */
3578 /* ??? This seems completely and utterly wrong. Certainly it's
3579 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3580 functioning even with INSN_DELETED_P and friends. */
3583 switch (GET_CODE (tmp
))
3586 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3587 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3589 tmp
= XEXP (XEXP (tmp
, 0), 0);
3593 tmp
= XEXP (tmp
, 0);
3594 gcc_assert (!INSN_DELETED_P (tmp
));
3595 gcc_assert (!NOTE_P (tmp
)
3596 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3603 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3604 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3605 align
, desc
->labelno
, done
);
3608 assemble_align (align
);
3610 /* Output the label. */
3611 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3613 /* Output the data. */
3614 output_constant_pool_2 (desc
->mode
, x
, align
);
3616 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3617 sections have proper size. */
3618 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3620 && (in_section
->common
.flags
& SECTION_MERGE
))
3621 assemble_align (align
);
3623 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3629 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3630 to as used. Emit referenced deferred strings. This function can
3631 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3634 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
3636 rtx x
= *current_rtx
;
3638 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3641 if (CONSTANT_POOL_ADDRESS_P (x
))
3643 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
3644 if (desc
->mark
== 0)
3647 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
3650 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3652 tree decl
= SYMBOL_REF_DECL (x
);
3653 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
3655 n_deferred_constants
--;
3656 output_constant_def_contents (x
);
3663 /* Look through appropriate parts of INSN, marking all entries in the
3664 constant pool which are actually being used. Entries that are only
3665 referenced by other constants are also marked as used. Emit
3666 deferred strings that are used. */
3669 mark_constants (rtx insn
)
3674 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3675 insns, not any notes that may be attached. We don't want to mark
3676 a constant just because it happens to appear in a REG_EQUIV note. */
3677 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3679 rtx seq
= PATTERN (insn
);
3680 int i
, n
= XVECLEN (seq
, 0);
3681 for (i
= 0; i
< n
; ++i
)
3683 rtx subinsn
= XVECEXP (seq
, 0, i
);
3684 if (INSN_P (subinsn
))
3685 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
3689 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
3692 /* Look through the instructions for this function, and mark all the
3693 entries in POOL which are actually being used. Emit deferred constants
3694 which have indeed been used. */
3697 mark_constant_pool (void)
3701 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
3704 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3705 mark_constants (insn
);
3707 for (link
= crtl
->epilogue_delay_list
;
3709 link
= XEXP (link
, 1))
3710 mark_constants (XEXP (link
, 0));
3713 /* Write all the constants in POOL. */
3716 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
3718 struct constant_descriptor_rtx
*desc
;
3720 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3723 /* If the constant is part of an object_block, make sure that
3724 the constant has been positioned within its block, but do not
3725 write out its definition yet. output_object_blocks will do
3727 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
3728 && SYMBOL_REF_BLOCK (desc
->sym
))
3729 place_block_symbol (desc
->sym
);
3732 switch_to_section (targetm
.asm_out
.select_rtx_section
3733 (desc
->mode
, desc
->constant
, desc
->align
));
3734 output_constant_pool_1 (desc
, desc
->align
);
3739 /* Mark all constants that are used in the current function, then write
3740 out the function's private constant pool. */
3743 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3744 tree fndecl ATTRIBUTE_UNUSED
)
3746 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
3748 /* It is possible for gcc to call force_const_mem and then to later
3749 discard the instructions which refer to the constant. In such a
3750 case we do not need to output the constant. */
3751 mark_constant_pool ();
3753 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3754 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3757 output_constant_pool_contents (pool
);
3759 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3760 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3764 /* Write the contents of the shared constant pool. */
3767 output_shared_constant_pool (void)
3769 output_constant_pool_contents (shared_constant_pool
);
3772 /* Determine what kind of relocations EXP may need. */
3775 compute_reloc_for_constant (tree exp
)
3777 int reloc
= 0, reloc2
;
3780 switch (TREE_CODE (exp
))
3784 /* Go inside any operations that get_inner_reference can handle and see
3785 if what's inside is a constant: no need to do anything here for
3786 addresses of variables or functions. */
3787 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3788 tem
= TREE_OPERAND (tem
, 0))
3791 if (TREE_PUBLIC (tem
))
3798 case POINTER_PLUS_EXPR
:
3799 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3800 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3804 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3805 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3806 /* The difference of two local labels is computable at link time. */
3807 if (reloc
== 1 && reloc2
== 1)
3814 case VIEW_CONVERT_EXPR
:
3815 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3820 unsigned HOST_WIDE_INT idx
;
3821 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3823 reloc
|= compute_reloc_for_constant (tem
);
3833 /* Find all the constants whose addresses are referenced inside of EXP,
3834 and make sure assembler code with a label has been output for each one.
3835 Indicate whether an ADDR_EXPR has been encountered. */
3838 output_addressed_constants (tree exp
)
3842 switch (TREE_CODE (exp
))
3846 /* Go inside any operations that get_inner_reference can handle and see
3847 if what's inside is a constant: no need to do anything here for
3848 addresses of variables or functions. */
3849 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3850 tem
= TREE_OPERAND (tem
, 0))
3853 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3854 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
3855 tem
= DECL_INITIAL (tem
);
3857 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
3858 output_constant_def (tem
, 0);
3862 case POINTER_PLUS_EXPR
:
3864 output_addressed_constants (TREE_OPERAND (exp
, 1));
3868 case VIEW_CONVERT_EXPR
:
3869 output_addressed_constants (TREE_OPERAND (exp
, 0));
3874 unsigned HOST_WIDE_INT idx
;
3875 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3877 output_addressed_constants (tem
);
3886 /* Whether a constructor CTOR is a valid static constant initializer if all
3887 its elements are. This used to be internal to initializer_constant_valid_p
3888 and has been exposed to let other functions like categorize_ctor_elements
3889 evaluate the property while walking a constructor for other purposes. */
3892 constructor_static_from_elts_p (const_tree ctor
)
3894 return (TREE_CONSTANT (ctor
)
3895 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
3896 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
)
3897 && !VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (ctor
)));
3900 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
3903 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
3904 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
3905 which are valid when ENDTYPE is an integer of any size; in
3906 particular, this does not accept a pointer minus a constant. This
3907 returns null_pointer_node if the VALUE is an absolute constant
3908 which can be used to initialize a static variable. Otherwise it
3912 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
3916 if (!INTEGRAL_TYPE_P (endtype
))
3919 op0
= TREE_OPERAND (value
, 0);
3920 op1
= TREE_OPERAND (value
, 1);
3922 /* Like STRIP_NOPS except allow the operand mode to widen. This
3923 works around a feature of fold that simplifies (int)(p1 - p2) to
3924 ((int)p1 - (int)p2) under the theory that the narrower operation
3927 while (CONVERT_EXPR_P (op0
)
3928 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
3930 tree inner
= TREE_OPERAND (op0
, 0);
3931 if (inner
== error_mark_node
3932 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3933 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
3934 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3939 while (CONVERT_EXPR_P (op1
)
3940 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
3942 tree inner
= TREE_OPERAND (op1
, 0);
3943 if (inner
== error_mark_node
3944 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3945 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
3946 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3951 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
3955 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
3956 cache
? cache
+ 2 : NULL
);
3957 /* Both initializers must be known. */
3961 && (op0
== null_pointer_node
3962 || TREE_CODE (value
) == MINUS_EXPR
))
3963 return null_pointer_node
;
3965 /* Support differences between labels. */
3966 if (TREE_CODE (op0
) == LABEL_DECL
3967 && TREE_CODE (op1
) == LABEL_DECL
)
3968 return null_pointer_node
;
3970 if (TREE_CODE (op0
) == STRING_CST
3971 && TREE_CODE (op1
) == STRING_CST
3972 && operand_equal_p (op0
, op1
, 1))
3973 return null_pointer_node
;
3979 /* Helper function of initializer_constant_valid_p.
3980 Return nonzero if VALUE is a valid constant-valued expression
3981 for use in initializing a static variable; one that can be an
3982 element of a "constant" initializer.
3984 Return null_pointer_node if the value is absolute;
3985 if it is relocatable, return the variable that determines the relocation.
3986 We assume that VALUE has been folded as much as possible;
3987 therefore, we do not need to check for such things as
3988 arithmetic-combinations of integers.
3990 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
3993 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
3997 switch (TREE_CODE (value
))
4000 if (constructor_static_from_elts_p (value
))
4002 unsigned HOST_WIDE_INT idx
;
4004 bool absolute
= true;
4006 if (cache
&& cache
[0] == value
)
4008 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4011 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4018 cache
[1] = NULL_TREE
;
4022 if (reloc
!= null_pointer_node
)
4025 /* For a non-absolute relocation, there is no single
4026 variable that can be "the variable that determines the
4031 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4033 return absolute
? null_pointer_node
: error_mark_node
;
4036 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4044 return null_pointer_node
;
4049 tree op0
= staticp (TREE_OPERAND (value
, 0));
4052 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4053 to be a constant, this is old-skool offsetof-like nonsense. */
4054 if (TREE_CODE (op0
) == INDIRECT_REF
4055 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4056 return null_pointer_node
;
4057 /* Taking the address of a nested function involves a trampoline,
4058 unless we don't need or want one. */
4059 if (TREE_CODE (op0
) == FUNCTION_DECL
4060 && DECL_STATIC_CHAIN (op0
)
4061 && !TREE_NO_TRAMPOLINE (value
))
4063 /* "&{...}" requires a temporary to hold the constructed
4065 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4071 case NON_LVALUE_EXPR
:
4072 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4075 case VIEW_CONVERT_EXPR
:
4077 tree src
= TREE_OPERAND (value
, 0);
4078 tree src_type
= TREE_TYPE (src
);
4079 tree dest_type
= TREE_TYPE (value
);
4081 /* Allow view-conversions from aggregate to non-aggregate type only
4082 if the bit pattern is fully preserved afterwards; otherwise, the
4083 RTL expander won't be able to apply a subsequent transformation
4084 to the underlying constructor. */
4085 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4087 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4088 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4093 /* Allow all other kinds of view-conversion. */
4094 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4099 tree src
= TREE_OPERAND (value
, 0);
4100 tree src_type
= TREE_TYPE (src
);
4101 tree dest_type
= TREE_TYPE (value
);
4103 /* Allow conversions between pointer types, floating-point
4104 types, and offset types. */
4105 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4106 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4107 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4108 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4109 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4111 /* Allow length-preserving conversions between integer types. */
4112 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4113 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4114 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4116 /* Allow conversions between other integer types only if
4118 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4120 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4121 if (inner
== null_pointer_node
)
4122 return null_pointer_node
;
4126 /* Allow (int) &foo provided int is as wide as a pointer. */
4127 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4128 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4129 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4131 /* Likewise conversions from int to pointers, but also allow
4132 conversions from 0. */
4133 if ((POINTER_TYPE_P (dest_type
)
4134 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4135 && INTEGRAL_TYPE_P (src_type
))
4137 if (TREE_CODE (src
) == INTEGER_CST
4138 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4139 return null_pointer_node
;
4140 if (integer_zerop (src
))
4141 return null_pointer_node
;
4142 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4143 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4146 /* Allow conversions to struct or union types if the value
4148 if (TREE_CODE (dest_type
) == RECORD_TYPE
4149 || TREE_CODE (dest_type
) == UNION_TYPE
)
4150 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4154 case POINTER_PLUS_EXPR
:
4156 /* Any valid floating-point constants will have been folded by now;
4157 with -frounding-math we hit this with addition of two constants. */
4158 if (TREE_CODE (endtype
) == REAL_TYPE
)
4160 if (cache
&& cache
[0] == value
)
4162 if (! INTEGRAL_TYPE_P (endtype
)
4163 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4165 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4167 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4170 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4171 endtype
, ncache
+ 2);
4172 /* If either term is absolute, use the other term's relocation. */
4173 if (valid0
== null_pointer_node
)
4175 else if (valid1
== null_pointer_node
)
4177 /* Support narrowing pointer differences. */
4179 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4183 /* Support narrowing pointer differences. */
4184 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4193 if (TREE_CODE (endtype
) == REAL_TYPE
)
4195 if (cache
&& cache
[0] == value
)
4197 if (! INTEGRAL_TYPE_P (endtype
)
4198 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4200 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4202 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4205 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4206 endtype
, ncache
+ 2);
4207 /* Win if second argument is absolute. */
4208 if (valid1
== null_pointer_node
)
4210 /* Win if both arguments have the same relocation.
4211 Then the value is absolute. */
4212 else if (valid0
== valid1
&& valid0
!= 0)
4213 ret
= null_pointer_node
;
4214 /* Since GCC guarantees that string constants are unique in the
4215 generated code, a subtraction between two copies of the same
4216 constant string is absolute. */
4217 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4218 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4219 && operand_equal_p (valid0
, valid1
, 1))
4220 ret
= null_pointer_node
;
4221 /* Support narrowing differences. */
4223 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4227 /* Support narrowing differences. */
4228 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4243 /* Return nonzero if VALUE is a valid constant-valued expression
4244 for use in initializing a static variable; one that can be an
4245 element of a "constant" initializer.
4247 Return null_pointer_node if the value is absolute;
4248 if it is relocatable, return the variable that determines the relocation.
4249 We assume that VALUE has been folded as much as possible;
4250 therefore, we do not need to check for such things as
4251 arithmetic-combinations of integers. */
4253 initializer_constant_valid_p (tree value
, tree endtype
)
4255 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4258 /* Return true if VALUE is a valid constant-valued expression
4259 for use in initializing a static bit-field; one that can be
4260 an element of a "constant" initializer. */
4263 initializer_constant_valid_for_bitfield_p (tree value
)
4265 /* For bitfields we support integer constants or possibly nested aggregates
4267 switch (TREE_CODE (value
))
4271 unsigned HOST_WIDE_INT idx
;
4274 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4275 if (!initializer_constant_valid_for_bitfield_p (elt
))
4283 case VIEW_CONVERT_EXPR
:
4284 case NON_LVALUE_EXPR
:
4286 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4295 /* output_constructor outer state of relevance in recursive calls, typically
4296 for nested aggregate bitfields. */
4299 unsigned int bit_offset
; /* current position in ... */
4300 int byte
; /* ... the outer byte buffer. */
4303 static unsigned HOST_WIDE_INT
4304 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4307 /* Output assembler code for constant EXP to FILE, with no label.
4308 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4309 Assumes output_addressed_constants has been done on EXP already.
4311 Generate exactly SIZE bytes of assembler data, padding at the end
4312 with zeros if necessary. SIZE must always be specified.
4314 SIZE is important for structure constructors,
4315 since trailing members may have been omitted from the constructor.
4316 It is also important for initialization of arrays from string constants
4317 since the full length of the string constant might not be wanted.
4318 It is also needed for initialization of unions, where the initializer's
4319 type is just one member, and that may not be as long as the union.
4321 There a case in which we would fail to output exactly SIZE bytes:
4322 for a structure constructor that wants to produce more than SIZE bytes.
4323 But such constructors will never be generated for any possible input.
4325 ALIGN is the alignment of the data in bits. */
4328 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4330 enum tree_code code
;
4331 unsigned HOST_WIDE_INT thissize
;
4333 if (size
== 0 || flag_syntax_only
)
4336 /* See if we're trying to initialize a pointer in a non-default mode
4337 to the address of some declaration somewhere. If the target says
4338 the mode is valid for pointers, assume the target has a way of
4340 if (TREE_CODE (exp
) == NOP_EXPR
4341 && POINTER_TYPE_P (TREE_TYPE (exp
))
4342 && targetm
.addr_space
.valid_pointer_mode
4343 (TYPE_MODE (TREE_TYPE (exp
)),
4344 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4346 tree saved_type
= TREE_TYPE (exp
);
4348 /* Peel off any intermediate conversions-to-pointer for valid
4350 while (TREE_CODE (exp
) == NOP_EXPR
4351 && POINTER_TYPE_P (TREE_TYPE (exp
))
4352 && targetm
.addr_space
.valid_pointer_mode
4353 (TYPE_MODE (TREE_TYPE (exp
)),
4354 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4355 exp
= TREE_OPERAND (exp
, 0);
4357 /* If what we're left with is the address of something, we can
4358 convert the address to the final type and output it that
4360 if (TREE_CODE (exp
) == ADDR_EXPR
)
4361 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4362 /* Likewise for constant ints. */
4363 else if (TREE_CODE (exp
) == INTEGER_CST
)
4364 exp
= build_int_cst_wide (saved_type
, TREE_INT_CST_LOW (exp
),
4365 TREE_INT_CST_HIGH (exp
));
4369 /* Eliminate any conversions since we'll be outputting the underlying
4371 while (CONVERT_EXPR_P (exp
)
4372 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4373 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4375 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4376 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4378 /* Make sure eliminating the conversion is really a no-op, except with
4379 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4380 union types to allow for Ada unchecked unions. */
4381 if (type_size
> op_size
4382 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4383 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4384 /* Keep the conversion. */
4387 exp
= TREE_OPERAND (exp
, 0);
4390 code
= TREE_CODE (TREE_TYPE (exp
));
4391 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4393 /* Allow a constructor with no elements for any data type.
4394 This means to fill the space with zeros. */
4395 if (TREE_CODE (exp
) == CONSTRUCTOR
4396 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
4398 assemble_zeros (size
);
4402 if (TREE_CODE (exp
) == FDESC_EXPR
)
4404 #ifdef ASM_OUTPUT_FDESC
4405 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4406 tree decl
= TREE_OPERAND (exp
, 0);
4407 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4414 /* Now output the underlying data. If we've handling the padding, return.
4415 Otherwise, break and ensure SIZE is the size written. */
4422 case REFERENCE_TYPE
:
4424 case FIXED_POINT_TYPE
:
4425 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4426 EXPAND_INITIALIZER
),
4427 MIN (size
, thissize
), align
, 0))
4428 error ("initializer for integer/fixed-point value is too complicated");
4432 if (TREE_CODE (exp
) != REAL_CST
)
4433 error ("initializer for floating value is not a floating constant");
4435 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4439 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4440 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4441 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4446 switch (TREE_CODE (exp
))
4449 output_constructor (exp
, size
, align
, NULL
);
4452 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
4454 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4461 unsigned int nalign
;
4462 enum machine_mode inner
;
4464 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4465 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4467 elt_size
= GET_MODE_SIZE (inner
);
4469 link
= TREE_VECTOR_CST_ELTS (exp
);
4470 output_constant (TREE_VALUE (link
), elt_size
, align
);
4471 thissize
= elt_size
;
4472 while ((link
= TREE_CHAIN (link
)) != NULL
)
4474 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
4475 thissize
+= elt_size
;
4486 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4487 output_constructor (exp
, size
, align
, NULL
);
4497 if (size
> thissize
)
4498 assemble_zeros (size
- thissize
);
4502 /* Subroutine of output_constructor, used for computing the size of
4503 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4504 type with an unspecified upper bound. */
4506 static unsigned HOST_WIDE_INT
4507 array_size_for_constructor (tree val
)
4510 unsigned HOST_WIDE_INT cnt
;
4511 tree index
, value
, tmp
;
4513 /* This code used to attempt to handle string constants that are not
4514 arrays of single-bytes, but nothing else does, so there's no point in
4516 if (TREE_CODE (val
) == STRING_CST
)
4517 return TREE_STRING_LENGTH (val
);
4519 max_index
= NULL_TREE
;
4520 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4522 if (TREE_CODE (index
) == RANGE_EXPR
)
4523 index
= TREE_OPERAND (index
, 1);
4524 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4528 if (max_index
== NULL_TREE
)
4531 /* Compute the total number of array elements. */
4532 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4533 i
= size_binop (MINUS_EXPR
, fold_convert (sizetype
, max_index
),
4534 fold_convert (sizetype
, tmp
));
4535 i
= size_binop (PLUS_EXPR
, i
, size_one_node
);
4537 /* Multiply by the array element unit size to find number of bytes. */
4538 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4540 return tree_low_cst (i
, 1);
4543 /* Other datastructures + helpers for output_constructor. */
4545 /* output_constructor local state to support interaction with helpers. */
4549 /* Received arguments. */
4550 tree exp
; /* Constructor expression. */
4551 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4552 unsigned int align
; /* Known initial alignment. */
4554 /* Constructor expression data. */
4555 tree type
; /* Expression type. */
4556 tree field
; /* Current field decl in a record. */
4557 tree min_index
; /* Lower bound if specified for an array. */
4559 /* Output processing state. */
4560 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4561 bool byte_buffer_in_use
; /* Whether byte ... */
4562 int byte
; /* ... contains part of a bitfield byte yet to
4565 int last_relative_index
; /* Implicit or explicit index of the last
4566 array element output within a bitfield. */
4567 /* Current element. */
4568 tree val
; /* Current element value. */
4569 tree index
; /* Current element index. */
4573 /* Helper for output_constructor. From the current LOCAL state, output a
4574 RANGE_EXPR element. */
4577 output_constructor_array_range (oc_local_state
*local
)
4579 unsigned HOST_WIDE_INT fieldsize
4580 = int_size_in_bytes (TREE_TYPE (local
->type
));
4582 HOST_WIDE_INT lo_index
4583 = tree_low_cst (TREE_OPERAND (local
->index
, 0), 0);
4584 HOST_WIDE_INT hi_index
4585 = tree_low_cst (TREE_OPERAND (local
->index
, 1), 0);
4586 HOST_WIDE_INT index
;
4589 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4591 for (index
= lo_index
; index
<= hi_index
; index
++)
4593 /* Output the element's initial value. */
4594 if (local
->val
== NULL_TREE
)
4595 assemble_zeros (fieldsize
);
4597 output_constant (local
->val
, fieldsize
, align2
);
4599 /* Count its size. */
4600 local
->total_bytes
+= fieldsize
;
4604 /* Helper for output_constructor. From the current LOCAL state, output a
4605 field element that is not true bitfield or part of an outer one. */
4608 output_constructor_regular_field (oc_local_state
*local
)
4610 /* Field size and position. Since this structure is static, we know the
4611 positions are constant. */
4612 unsigned HOST_WIDE_INT fieldsize
;
4613 HOST_WIDE_INT fieldpos
;
4615 unsigned int align2
;
4617 if (local
->index
!= NULL_TREE
)
4618 fieldpos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
)), 1)
4619 * ((tree_low_cst (local
->index
, 0)
4620 - tree_low_cst (local
->min_index
, 0))));
4621 else if (local
->field
!= NULL_TREE
)
4622 fieldpos
= int_byte_position (local
->field
);
4626 /* Output any buffered-up bit-fields preceding this element. */
4627 if (local
->byte_buffer_in_use
)
4629 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4630 local
->total_bytes
++;
4631 local
->byte_buffer_in_use
= false;
4634 /* Advance to offset of this element.
4635 Note no alignment needed in an array, since that is guaranteed
4636 if each element has the proper size. */
4637 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4638 && fieldpos
!= local
->total_bytes
)
4640 gcc_assert (fieldpos
>= local
->total_bytes
);
4641 assemble_zeros (fieldpos
- local
->total_bytes
);
4642 local
->total_bytes
= fieldpos
;
4645 /* Find the alignment of this element. */
4646 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
4648 /* Determine size this element should occupy. */
4653 /* If this is an array with an unspecified upper bound,
4654 the initializer determines the size. */
4655 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4656 but we cannot do this until the deprecated support for
4657 initializing zero-length array members is removed. */
4658 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
4659 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
4660 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
4662 fieldsize
= array_size_for_constructor (local
->val
);
4663 /* Given a non-empty initialization, this field had
4665 gcc_assert (!fieldsize
|| !DECL_CHAIN (local
->field
));
4667 else if (DECL_SIZE_UNIT (local
->field
))
4669 /* ??? This can't be right. If the decl size overflows
4670 a host integer we will silently emit no data. */
4671 if (host_integerp (DECL_SIZE_UNIT (local
->field
), 1))
4672 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (local
->field
), 1);
4676 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
4678 /* Output the element's initial value. */
4679 if (local
->val
== NULL_TREE
)
4680 assemble_zeros (fieldsize
);
4682 output_constant (local
->val
, fieldsize
, align2
);
4684 /* Count its size. */
4685 local
->total_bytes
+= fieldsize
;
4688 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4689 output an element that is a true bitfield or part of an outer one. */
4692 output_constructor_bitfield (oc_local_state
*local
, oc_outer_state
*outer
)
4694 /* Bit size of this element. */
4695 HOST_WIDE_INT ebitsize
4697 ? tree_low_cst (DECL_SIZE (local
->field
), 1)
4698 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local
->type
)), 1));
4700 /* Relative index of this element if this is an array component. */
4701 HOST_WIDE_INT relative_index
4704 ? (tree_low_cst (local
->index
, 0)
4705 - tree_low_cst (local
->min_index
, 0))
4706 : local
->last_relative_index
+ 1)
4709 /* Bit position of this element from the start of the containing
4711 HOST_WIDE_INT constructor_relative_ebitpos
4713 ? int_bit_position (local
->field
)
4714 : ebitsize
* relative_index
);
4716 /* Bit position of this element from the start of a possibly ongoing
4717 outer byte buffer. */
4718 HOST_WIDE_INT byte_relative_ebitpos
4719 = ((outer
? outer
->bit_offset
: 0) + constructor_relative_ebitpos
);
4721 /* From the start of a possibly ongoing outer byte buffer, offsets to
4722 the first bit of this element and to the first bit past the end of
4724 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
4725 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
4727 local
->last_relative_index
= relative_index
;
4729 if (local
->val
== NULL_TREE
)
4730 local
->val
= integer_zero_node
;
4732 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
4733 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
4734 local
->val
= TREE_OPERAND (local
->val
, 0);
4736 if (TREE_CODE (local
->val
) != INTEGER_CST
4737 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
4739 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
4743 /* If this field does not start in this (or, next) byte,
4745 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4747 /* Output remnant of any bit field in previous bytes. */
4748 if (local
->byte_buffer_in_use
)
4750 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4751 local
->total_bytes
++;
4752 local
->byte_buffer_in_use
= false;
4755 /* If still not at proper byte, advance to there. */
4756 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
4758 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
4759 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
4760 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
4764 /* Set up the buffer if necessary. */
4765 if (!local
->byte_buffer_in_use
)
4769 local
->byte_buffer_in_use
= true;
4772 /* If this is nested constructor, recurse passing the bit offset and the
4773 pending data, then retrieve the new pending data afterwards. */
4774 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
4776 oc_outer_state output_state
;
4778 output_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
4779 output_state
.byte
= local
->byte
;
4781 += output_constructor (local
->val
, 0, 0, &output_state
);
4782 local
->byte
= output_state
.byte
;
4786 /* Otherwise, we must split the element into pieces that fall within
4787 separate bytes, and combine each byte with previous or following
4789 while (next_offset
< end_offset
)
4793 HOST_WIDE_INT value
;
4794 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4795 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4797 /* Advance from byte to byte
4798 within this element when necessary. */
4799 while (next_byte
!= local
->total_bytes
)
4801 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4802 local
->total_bytes
++;
4806 /* Number of bits we can process at once
4807 (all part of the same byte). */
4808 this_time
= MIN (end_offset
- next_offset
,
4809 BITS_PER_UNIT
- next_bit
);
4810 if (BYTES_BIG_ENDIAN
)
4812 /* On big-endian machine, take the most significant bits
4813 first (of the bits that are significant)
4814 and put them into bytes from the most significant end. */
4815 shift
= end_offset
- next_offset
- this_time
;
4817 /* Don't try to take a bunch of bits that cross
4818 the word boundary in the INTEGER_CST. We can
4819 only select bits from the LOW or HIGH part
4821 if (shift
< HOST_BITS_PER_WIDE_INT
4822 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4824 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4825 shift
= HOST_BITS_PER_WIDE_INT
;
4828 /* Now get the bits from the appropriate constant word. */
4829 if (shift
< HOST_BITS_PER_WIDE_INT
)
4830 value
= TREE_INT_CST_LOW (local
->val
);
4833 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4834 value
= TREE_INT_CST_HIGH (local
->val
);
4835 shift
-= HOST_BITS_PER_WIDE_INT
;
4838 /* Get the result. This works only when:
4839 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4840 local
->byte
|= (((value
>> shift
)
4841 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4842 << (BITS_PER_UNIT
- this_time
- next_bit
));
4846 /* On little-endian machines,
4847 take first the least significant bits of the value
4848 and pack them starting at the least significant
4849 bits of the bytes. */
4850 shift
= next_offset
- byte_relative_ebitpos
;
4852 /* Don't try to take a bunch of bits that cross
4853 the word boundary in the INTEGER_CST. We can
4854 only select bits from the LOW or HIGH part
4856 if (shift
< HOST_BITS_PER_WIDE_INT
4857 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4858 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4860 /* Now get the bits from the appropriate constant word. */
4861 if (shift
< HOST_BITS_PER_WIDE_INT
)
4862 value
= TREE_INT_CST_LOW (local
->val
);
4865 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4866 value
= TREE_INT_CST_HIGH (local
->val
);
4867 shift
-= HOST_BITS_PER_WIDE_INT
;
4870 /* Get the result. This works only when:
4871 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4872 local
->byte
|= (((value
>> shift
)
4873 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4877 next_offset
+= this_time
;
4878 local
->byte_buffer_in_use
= true;
4882 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4883 Generate at least SIZE bytes, padding if necessary. OUTER designates the
4884 caller output state of relevance in recursive invocations. */
4886 static unsigned HOST_WIDE_INT
4887 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
4888 unsigned int align
, oc_outer_state
* outer
)
4890 unsigned HOST_WIDE_INT cnt
;
4891 constructor_elt
*ce
;
4893 oc_local_state local
;
4895 /* Setup our local state to communicate with helpers. */
4898 local
.align
= align
;
4900 local
.total_bytes
= 0;
4901 local
.byte_buffer_in_use
= outer
!= NULL
;
4902 local
.byte
= outer
? outer
->byte
: 0;
4904 local
.type
= TREE_TYPE (exp
);
4906 local
.last_relative_index
= -1;
4908 local
.min_index
= NULL_TREE
;
4909 if (TREE_CODE (local
.type
) == ARRAY_TYPE
4910 && TYPE_DOMAIN (local
.type
) != NULL_TREE
)
4911 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
4913 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
4915 /* As CE goes through the elements of the constant, FIELD goes through the
4916 structure fields if the constant is a structure. If the constant is a
4917 union, we override this by getting the field from the TREE_LIST element.
4918 But the constant could also be an array. Then FIELD is zero.
4920 There is always a maximum of one element in the chain LINK for unions
4921 (even if the initializer in a source program incorrectly contains
4924 local
.field
= NULL_TREE
;
4925 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
4926 local
.field
= TYPE_FIELDS (local
.type
);
4929 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
4930 cnt
++, local
.field
= local
.field
? DECL_CHAIN (local
.field
) : 0)
4932 local
.val
= ce
->value
;
4933 local
.index
= NULL_TREE
;
4935 /* The element in a union constructor specifies the proper field
4937 if ((TREE_CODE (local
.type
) == RECORD_TYPE
4938 || TREE_CODE (local
.type
) == UNION_TYPE
4939 || TREE_CODE (local
.type
) == QUAL_UNION_TYPE
)
4940 && ce
->index
!= NULL_TREE
)
4941 local
.field
= ce
->index
;
4943 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
4944 local
.index
= ce
->index
;
4946 #ifdef ASM_COMMENT_START
4947 if (local
.field
&& flag_verbose_asm
)
4948 fprintf (asm_out_file
, "%s %s:\n",
4950 DECL_NAME (local
.field
)
4951 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
4955 /* Eliminate the marker that makes a cast not be an lvalue. */
4956 if (local
.val
!= NULL_TREE
)
4957 STRIP_NOPS (local
.val
);
4959 /* Output the current element, using the appropriate helper ... */
4961 /* For an array slice not part of an outer bitfield. */
4963 && local
.index
!= NULL_TREE
4964 && TREE_CODE (local
.index
) == RANGE_EXPR
)
4965 output_constructor_array_range (&local
);
4967 /* For a field that is neither a true bitfield nor part of an outer one,
4968 known to be at least byte aligned and multiple-of-bytes long. */
4970 && (local
.field
== NULL_TREE
4971 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
4972 output_constructor_regular_field (&local
);
4974 /* For a true bitfield or part of an outer one. */
4976 output_constructor_bitfield (&local
, outer
);
4979 /* If we are not at toplevel, save the pending data for our caller.
4980 Otherwise output the pending data and padding zeros as needed. */
4982 outer
->byte
= local
.byte
;
4985 if (local
.byte_buffer_in_use
)
4987 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
4988 local
.total_bytes
++;
4991 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
4993 assemble_zeros (local
.size
- local
.total_bytes
);
4994 local
.total_bytes
= local
.size
;
4998 return local
.total_bytes
;
5001 /* Mark DECL as weak. */
5004 mark_weak (tree decl
)
5006 DECL_WEAK (decl
) = 1;
5008 if (DECL_RTL_SET_P (decl
)
5009 && MEM_P (DECL_RTL (decl
))
5010 && XEXP (DECL_RTL (decl
), 0)
5011 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5012 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5015 /* Merge weak status between NEWDECL and OLDDECL. */
5018 merge_weak (tree newdecl
, tree olddecl
)
5020 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5022 if (DECL_WEAK (newdecl
) && SUPPORTS_WEAK
)
5025 /* We put the NEWDECL on the weak_decls list at some point
5026 and OLDDECL as well. Keep just OLDDECL on the list. */
5027 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5028 if (TREE_VALUE (*pwd
) == newdecl
)
5030 *pwd
= TREE_CHAIN (*pwd
);
5037 if (DECL_WEAK (newdecl
))
5041 /* NEWDECL is weak, but OLDDECL is not. */
5043 /* If we already output the OLDDECL, we're in trouble; we can't
5044 go back and make it weak. This error cannot be caught in
5045 declare_weak because the NEWDECL and OLDDECL was not yet
5046 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5047 if (TREE_ASM_WRITTEN (olddecl
))
5048 error ("weak declaration of %q+D must precede definition",
5051 /* If we've already generated rtl referencing OLDDECL, we may
5052 have done so in a way that will not function properly with
5054 else if (TREE_USED (olddecl
)
5055 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
5056 warning (0, "weak declaration of %q+D after first use results "
5057 "in unspecified behavior", newdecl
);
5061 /* We put the NEWDECL on the weak_decls list at some point.
5062 Replace it with the OLDDECL. */
5063 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5064 if (TREE_VALUE (wd
) == newdecl
)
5066 TREE_VALUE (wd
) = olddecl
;
5069 /* We may not find the entry on the list. If NEWDECL is a
5070 weak alias, then we will have already called
5071 globalize_decl to remove the entry; in that case, we do
5072 not need to do anything. */
5075 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5076 mark_weak (olddecl
);
5079 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5080 weak. Just update NEWDECL to indicate that it's weak too. */
5081 mark_weak (newdecl
);
5084 /* Declare DECL to be a weak symbol. */
5087 declare_weak (tree decl
)
5089 if (! TREE_PUBLIC (decl
))
5090 error ("weak declaration of %q+D must be public", decl
);
5091 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
5092 error ("weak declaration of %q+D must precede definition", decl
);
5093 else if (!SUPPORTS_WEAK
)
5094 warning (0, "weak declaration of %q+D not supported", decl
);
5097 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5098 DECL_ATTRIBUTES (decl
)
5099 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5103 weak_finish_1 (tree decl
)
5105 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5106 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5109 if (! TREE_USED (decl
))
5112 #ifdef ASM_WEAKEN_DECL
5113 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5115 #ifdef ASM_WEAKEN_LABEL
5116 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5118 #ifdef ASM_OUTPUT_WEAK_ALIAS
5120 static bool warn_once
= 0;
5123 warning (0, "only weak aliases are supported in this configuration");
5133 /* This TREE_LIST contains weakref targets. */
5135 static GTY(()) tree weakref_targets
;
5137 /* Forward declaration. */
5138 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
5140 /* Emit any pending weak declarations. */
5147 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5149 tree alias_decl
= TREE_PURPOSE (t
);
5150 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5152 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5153 /* Remove alias_decl from the weak list, but leave entries for
5154 the target alone. */
5156 #ifndef ASM_OUTPUT_WEAKREF
5157 else if (! TREE_SYMBOL_REFERENCED (target
))
5159 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5160 defined, otherwise we and weak_finish_1 would use
5161 different macros. */
5162 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5163 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5165 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
5169 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5170 TREE_CODE (alias_decl
), target
,
5171 TREE_TYPE (alias_decl
));
5173 DECL_EXTERNAL (decl
) = 1;
5174 TREE_PUBLIC (decl
) = 1;
5175 DECL_ARTIFICIAL (decl
) = 1;
5176 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5177 TREE_USED (decl
) = 1;
5180 weak_finish_1 (decl
);
5189 /* Remove the alias and the target from the pending weak list
5190 so that we do not emit any .weak directives for the former,
5191 nor multiple .weak directives for the latter. */
5192 for (p
= &weak_decls
; (t2
= *p
) ; )
5194 if (TREE_VALUE (t2
) == alias_decl
5195 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5196 *p
= TREE_CHAIN (t2
);
5198 p
= &TREE_CHAIN (t2
);
5201 /* Remove other weakrefs to the same target, to speed things up. */
5202 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5204 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5205 *p
= TREE_CHAIN (t2
);
5207 p
= &TREE_CHAIN (t2
);
5212 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5214 tree decl
= TREE_VALUE (t
);
5216 weak_finish_1 (decl
);
5220 /* Emit the assembly bits to indicate that DECL is globally visible. */
5223 globalize_decl (tree decl
)
5226 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5227 if (DECL_WEAK (decl
))
5229 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5232 #ifdef ASM_WEAKEN_DECL
5233 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5235 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5238 /* Remove this function from the pending weak list so that
5239 we do not emit multiple .weak directives for it. */
5240 for (p
= &weak_decls
; (t
= *p
) ; )
5242 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5243 *p
= TREE_CHAIN (t
);
5245 p
= &TREE_CHAIN (t
);
5248 /* Remove weakrefs to the same target from the pending weakref
5249 list, for the same reason. */
5250 for (p
= &weakref_targets
; (t
= *p
) ; )
5252 if (DECL_ASSEMBLER_NAME (decl
)
5253 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5254 *p
= TREE_CHAIN (t
);
5256 p
= &TREE_CHAIN (t
);
5263 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5266 VEC(alias_pair
,gc
) *alias_pairs
;
5268 /* Given an assembly name, find the decl it is associated with. At the
5269 same time, mark it needed for cgraph. */
5272 find_decl_and_mark_needed (tree decl
, tree target
)
5274 struct cgraph_node
*fnode
= NULL
;
5275 struct varpool_node
*vnode
= NULL
;
5277 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5279 fnode
= cgraph_node_for_asm (target
);
5281 vnode
= varpool_node_for_asm (target
);
5285 vnode
= varpool_node_for_asm (target
);
5287 fnode
= cgraph_node_for_asm (target
);
5292 cgraph_mark_needed_node (fnode
);
5297 varpool_mark_needed_node (vnode
);
5298 vnode
->force_output
= 1;
5305 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5306 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5307 tree node is DECL to have the value of the tree node TARGET. */
5310 do_assemble_alias (tree decl
, tree target
)
5312 /* Emulated TLS had better not get this var. */
5313 gcc_assert(!(!targetm
.have_tls
5314 && TREE_CODE (decl
) == VAR_DECL
5315 && DECL_THREAD_LOCAL_P (decl
)));
5317 if (TREE_ASM_WRITTEN (decl
))
5320 /* We must force creation of DECL_RTL for debug info generation, even though
5321 we don't use it here. */
5322 make_decl_rtl (decl
);
5324 TREE_ASM_WRITTEN (decl
) = 1;
5325 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5327 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5329 ultimate_transparent_alias_target (&target
);
5331 if (!TREE_SYMBOL_REFERENCED (target
))
5332 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5334 #ifdef ASM_OUTPUT_WEAKREF
5335 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5336 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5337 IDENTIFIER_POINTER (target
));
5341 error_at (DECL_SOURCE_LOCATION (decl
),
5342 "weakref is not supported in this configuration");
5349 #ifdef ASM_OUTPUT_DEF
5350 /* Make name accessible from other files, if appropriate. */
5352 if (TREE_PUBLIC (decl
))
5354 globalize_decl (decl
);
5355 maybe_assemble_visibility (decl
);
5358 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5359 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5361 ASM_OUTPUT_DEF (asm_out_file
,
5362 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5363 IDENTIFIER_POINTER (target
));
5365 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5370 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5371 # ifdef ASM_WEAKEN_DECL
5372 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5374 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5376 /* Remove this function from the pending weak list so that
5377 we do not emit multiple .weak directives for it. */
5378 for (p
= &weak_decls
; (t
= *p
) ; )
5379 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5380 *p
= TREE_CHAIN (t
);
5382 p
= &TREE_CHAIN (t
);
5384 /* Remove weakrefs to the same target from the pending weakref
5385 list, for the same reason. */
5386 for (p
= &weakref_targets
; (t
= *p
) ; )
5388 if (DECL_ASSEMBLER_NAME (decl
)
5389 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5390 *p
= TREE_CHAIN (t
);
5392 p
= &TREE_CHAIN (t
);
5399 /* Remove the alias pairing for functions that are no longer in the call
5403 remove_unreachable_alias_pairs (void)
5408 if (alias_pairs
== NULL
)
5411 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); )
5413 if (!DECL_EXTERNAL (p
->decl
))
5415 struct cgraph_node
*fnode
= NULL
;
5416 struct varpool_node
*vnode
= NULL
;
5417 fnode
= cgraph_node_for_asm (p
->target
);
5418 vnode
= (fnode
== NULL
) ? varpool_node_for_asm (p
->target
) : NULL
;
5419 if (fnode
== NULL
&& vnode
== NULL
)
5421 VEC_unordered_remove (alias_pair
, alias_pairs
, i
);
5431 /* First pass of completing pending aliases. Make sure that cgraph knows
5432 which symbols will be required. */
5435 finish_aliases_1 (void)
5440 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5444 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
5445 if (target_decl
== NULL
)
5447 if (! (p
->emitted_diags
& ALIAS_DIAG_TO_UNDEF
)
5448 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5450 error ("%q+D aliased to undefined symbol %qE",
5451 p
->decl
, p
->target
);
5452 p
->emitted_diags
|= ALIAS_DIAG_TO_UNDEF
;
5455 else if (! (p
->emitted_diags
& ALIAS_DIAG_TO_EXTERN
)
5456 && DECL_EXTERNAL (target_decl
)
5457 /* We use local aliases for C++ thunks to force the tailcall
5458 to bind locally. This is a hack - to keep it working do
5459 the following (which is not strictly correct). */
5460 && (! TREE_CODE (target_decl
) == FUNCTION_DECL
5461 || ! DECL_VIRTUAL_P (target_decl
))
5462 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5464 error ("%q+D aliased to external symbol %qE",
5465 p
->decl
, p
->target
);
5466 p
->emitted_diags
|= ALIAS_DIAG_TO_EXTERN
;
5471 /* Second pass of completing pending aliases. Emit the actual assembly.
5472 This happens at the end of compilation and thus it is assured that the
5473 target symbol has been emitted. */
5476 finish_aliases_2 (void)
5481 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5482 do_assemble_alias (p
->decl
, p
->target
);
5484 VEC_truncate (alias_pair
, alias_pairs
, 0);
5487 /* Emit an assembler directive to make the symbol for DECL an alias to
5488 the symbol for TARGET. */
5491 assemble_alias (tree decl
, tree target
)
5494 bool is_weakref
= false;
5496 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5498 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5502 ultimate_transparent_alias_target (&target
);
5504 if (alias
== target
)
5505 error ("weakref %q+D ultimately targets itself", decl
);
5508 #ifndef ASM_OUTPUT_WEAKREF
5509 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
5510 TREE_CHAIN (alias
) = target
;
5513 if (TREE_PUBLIC (decl
))
5514 error ("weakref %q+D must have static linkage", decl
);
5518 #if !defined (ASM_OUTPUT_DEF)
5519 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5520 error_at (DECL_SOURCE_LOCATION (decl
),
5521 "alias definitions not supported in this configuration");
5524 if (!DECL_WEAK (decl
))
5526 error_at (DECL_SOURCE_LOCATION (decl
),
5527 "only weak aliases are supported in this configuration");
5533 TREE_USED (decl
) = 1;
5535 /* A quirk of the initial implementation of aliases required that the user
5536 add "extern" to all of them. Which is silly, but now historical. Do
5537 note that the symbol is in fact locally defined. */
5539 DECL_EXTERNAL (decl
) = 0;
5541 /* Allow aliases to aliases. */
5542 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5543 cgraph_node (decl
)->alias
= true;
5545 varpool_node (decl
)->alias
= true;
5547 /* If the target has already been emitted, we don't have to queue the
5548 alias. This saves a tad of memory. */
5549 if (cgraph_global_info_ready
)
5550 target_decl
= find_decl_and_mark_needed (decl
, target
);
5553 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5554 do_assemble_alias (decl
, target
);
5557 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
5560 p
->emitted_diags
= ALIAS_DIAG_NONE
;
5564 /* Emit an assembler directive to set symbol for DECL visibility to
5565 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5568 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5569 int vis ATTRIBUTE_UNUSED
)
5571 #ifdef HAVE_GAS_HIDDEN
5572 static const char * const visibility_types
[] = {
5573 NULL
, "protected", "hidden", "internal"
5576 const char *name
, *type
;
5578 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5579 type
= visibility_types
[vis
];
5581 fprintf (asm_out_file
, "\t.%s\t", type
);
5582 assemble_name (asm_out_file
, name
);
5583 fprintf (asm_out_file
, "\n");
5585 warning (OPT_Wattributes
, "visibility attribute not supported "
5586 "in this configuration; ignored");
5590 /* A helper function to call assemble_visibility when needed for a decl. */
5593 maybe_assemble_visibility (tree decl
)
5595 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5597 if (vis
!= VISIBILITY_DEFAULT
)
5599 targetm
.asm_out
.assemble_visibility (decl
, vis
);
5606 /* Returns 1 if the target configuration supports defining public symbols
5607 so that one of them will be chosen at link time instead of generating a
5608 multiply-defined symbol error, whether through the use of weak symbols or
5609 a target-specific mechanism for having duplicates discarded. */
5612 supports_one_only (void)
5614 if (SUPPORTS_ONE_ONLY
)
5616 return SUPPORTS_WEAK
;
5619 /* Set up DECL as a public symbol that can be defined in multiple
5620 translation units without generating a linker error. */
5623 make_decl_one_only (tree decl
, tree comdat_group
)
5625 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5626 || TREE_CODE (decl
) == FUNCTION_DECL
);
5628 TREE_PUBLIC (decl
) = 1;
5630 if (SUPPORTS_ONE_ONLY
)
5632 #ifdef MAKE_DECL_ONE_ONLY
5633 MAKE_DECL_ONE_ONLY (decl
);
5635 DECL_COMDAT_GROUP (decl
) = comdat_group
;
5637 else if (TREE_CODE (decl
) == VAR_DECL
5638 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5639 DECL_COMMON (decl
) = 1;
5642 gcc_assert (SUPPORTS_WEAK
);
5643 DECL_WEAK (decl
) = 1;
5648 init_varasm_once (void)
5650 section_htab
= htab_create_ggc (31, section_entry_hash
,
5651 section_entry_eq
, NULL
);
5652 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
5653 object_block_entry_eq
, NULL
);
5654 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
5655 const_desc_eq
, NULL
);
5657 const_alias_set
= new_alias_set ();
5658 shared_constant_pool
= create_constant_pool ();
5660 #ifdef TEXT_SECTION_ASM_OP
5661 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
5662 TEXT_SECTION_ASM_OP
);
5665 #ifdef DATA_SECTION_ASM_OP
5666 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5667 DATA_SECTION_ASM_OP
);
5670 #ifdef SDATA_SECTION_ASM_OP
5671 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
5672 SDATA_SECTION_ASM_OP
);
5675 #ifdef READONLY_DATA_SECTION_ASM_OP
5676 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
5677 READONLY_DATA_SECTION_ASM_OP
);
5680 #ifdef CTORS_SECTION_ASM_OP
5681 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
5682 CTORS_SECTION_ASM_OP
);
5685 #ifdef DTORS_SECTION_ASM_OP
5686 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
5687 DTORS_SECTION_ASM_OP
);
5690 #ifdef BSS_SECTION_ASM_OP
5691 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5692 output_section_asm_op
,
5693 BSS_SECTION_ASM_OP
);
5696 #ifdef SBSS_SECTION_ASM_OP
5697 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
5698 output_section_asm_op
,
5699 SBSS_SECTION_ASM_OP
);
5702 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5703 | SECTION_COMMON
, emit_tls_common
);
5704 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5705 | SECTION_COMMON
, emit_local
);
5706 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
5707 | SECTION_COMMON
, emit_common
);
5709 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
5710 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
5714 targetm
.asm_out
.init_sections ();
5716 if (readonly_data_section
== NULL
)
5717 readonly_data_section
= text_section
;
5721 decl_default_tls_model (const_tree decl
)
5723 enum tls_model kind
;
5726 is_local
= targetm
.binds_local_p (decl
);
5730 kind
= TLS_MODEL_LOCAL_EXEC
;
5732 kind
= TLS_MODEL_INITIAL_EXEC
;
5735 /* Local dynamic is inefficient when we're not combining the
5736 parts of the address. */
5737 else if (optimize
&& is_local
)
5738 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
5740 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
5741 if (kind
< flag_tls_default
)
5742 kind
= flag_tls_default
;
5747 /* Select a set of attributes for section NAME based on the properties
5748 of DECL and whether or not RELOC indicates that DECL's initializer
5749 might contain runtime relocations.
5751 We make the section read-only and executable for a function decl,
5752 read-only for a const data decl, and writable for a non-const data decl. */
5755 default_section_type_flags (tree decl
, const char *name
, int reloc
)
5759 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
5760 flags
= SECTION_CODE
;
5761 else if (decl
&& decl_readonly_section (decl
, reloc
))
5763 else if (current_function_decl
5765 && crtl
->subsections
.unlikely_text_section_name
5766 && strcmp (name
, crtl
->subsections
.unlikely_text_section_name
) == 0)
5767 flags
= SECTION_CODE
;
5769 && (!current_function_decl
|| !cfun
)
5770 && strcmp (name
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
5771 flags
= SECTION_CODE
;
5773 flags
= SECTION_WRITE
;
5775 if (decl
&& DECL_ONE_ONLY (decl
))
5776 flags
|= SECTION_LINKONCE
;
5778 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
5779 flags
|= SECTION_TLS
| SECTION_WRITE
;
5781 if (strcmp (name
, ".bss") == 0
5782 || strncmp (name
, ".bss.", 5) == 0
5783 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
5784 || strcmp (name
, ".sbss") == 0
5785 || strncmp (name
, ".sbss.", 6) == 0
5786 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
5787 flags
|= SECTION_BSS
;
5789 if (strcmp (name
, ".tdata") == 0
5790 || strncmp (name
, ".tdata.", 7) == 0
5791 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
5792 flags
|= SECTION_TLS
;
5794 if (strcmp (name
, ".tbss") == 0
5795 || strncmp (name
, ".tbss.", 6) == 0
5796 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
5797 flags
|= SECTION_TLS
| SECTION_BSS
;
5799 /* These three sections have special ELF types. They are neither
5800 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
5801 want to print a section type (@progbits or @nobits). If someone
5802 is silly enough to emit code or TLS variables to one of these
5803 sections, then don't handle them specially. */
5804 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
5805 && (strcmp (name
, ".init_array") == 0
5806 || strcmp (name
, ".fini_array") == 0
5807 || strcmp (name
, ".preinit_array") == 0))
5808 flags
|= SECTION_NOTYPE
;
5813 /* Return true if the target supports some form of global BSS,
5814 either through bss_noswitch_section, or by selecting a BSS
5815 section in TARGET_ASM_SELECT_SECTION. */
5818 have_global_bss_p (void)
5820 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
5823 /* Output assembly to switch to section NAME with attribute FLAGS.
5824 Four variants for common object file formats. */
5827 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
5828 unsigned int flags ATTRIBUTE_UNUSED
,
5829 tree decl ATTRIBUTE_UNUSED
)
5831 /* Some object formats don't support named sections at all. The
5832 front-end should already have flagged this as an error. */
5836 #ifndef TLS_SECTION_ASM_FLAG
5837 #define TLS_SECTION_ASM_FLAG 'T'
5841 default_elf_asm_named_section (const char *name
, unsigned int flags
,
5842 tree decl ATTRIBUTE_UNUSED
)
5844 char flagchars
[10], *f
= flagchars
;
5846 /* If we have already declared this section, we can use an
5847 abbreviated form to switch back to it -- unless this section is
5848 part of a COMDAT groups, in which case GAS requires the full
5849 declaration every time. */
5850 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5851 && (flags
& SECTION_DECLARED
))
5853 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
5857 if (!(flags
& SECTION_DEBUG
))
5859 if (flags
& SECTION_WRITE
)
5861 if (flags
& SECTION_CODE
)
5863 if (flags
& SECTION_SMALL
)
5865 if (flags
& SECTION_MERGE
)
5867 if (flags
& SECTION_STRINGS
)
5869 if (flags
& SECTION_TLS
)
5870 *f
++ = TLS_SECTION_ASM_FLAG
;
5871 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5875 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
5877 if (!(flags
& SECTION_NOTYPE
))
5882 if (flags
& SECTION_BSS
)
5888 #ifdef ASM_COMMENT_START
5889 /* On platforms that use "@" as the assembly comment character,
5891 if (strcmp (ASM_COMMENT_START
, "@") == 0)
5894 fprintf (asm_out_file
, format
, type
);
5896 if (flags
& SECTION_ENTSIZE
)
5897 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
5898 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5900 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
5901 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
5903 fprintf (asm_out_file
, ",%s,comdat",
5904 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
5908 putc ('\n', asm_out_file
);
5912 default_coff_asm_named_section (const char *name
, unsigned int flags
,
5913 tree decl ATTRIBUTE_UNUSED
)
5915 char flagchars
[8], *f
= flagchars
;
5917 if (flags
& SECTION_WRITE
)
5919 if (flags
& SECTION_CODE
)
5923 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
5927 default_pe_asm_named_section (const char *name
, unsigned int flags
,
5930 default_coff_asm_named_section (name
, flags
, decl
);
5932 if (flags
& SECTION_LINKONCE
)
5934 /* Functions may have been compiled at various levels of
5935 optimization so we can't use `same_size' here.
5936 Instead, have the linker pick one. */
5937 fprintf (asm_out_file
, "\t.linkonce %s\n",
5938 (flags
& SECTION_CODE
? "discard" : "same_size"));
5942 /* The lame default section selector. */
5945 default_select_section (tree decl
, int reloc
,
5946 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
5950 if (decl_readonly_section (decl
, reloc
))
5951 return readonly_data_section
;
5953 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5955 if (! ((flag_pic
&& reloc
)
5956 || !TREE_READONLY (decl
)
5957 || TREE_SIDE_EFFECTS (decl
)
5958 || !TREE_CONSTANT (decl
)))
5959 return readonly_data_section
;
5961 else if (TREE_CODE (decl
) == STRING_CST
)
5962 return readonly_data_section
;
5963 else if (! (flag_pic
&& reloc
))
5964 return readonly_data_section
;
5966 return data_section
;
5969 enum section_category
5970 categorize_decl_for_section (const_tree decl
, int reloc
)
5972 enum section_category ret
;
5974 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5976 else if (TREE_CODE (decl
) == STRING_CST
)
5978 if (flag_mudflap
) /* or !flag_merge_constants */
5979 return SECCAT_RODATA
;
5981 return SECCAT_RODATA_MERGE_STR
;
5983 else if (TREE_CODE (decl
) == VAR_DECL
)
5985 if (bss_initializer_p (decl
))
5987 else if (! TREE_READONLY (decl
)
5988 || TREE_SIDE_EFFECTS (decl
)
5989 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
5991 /* Here the reloc_rw_mask is not testing whether the section should
5992 be read-only or not, but whether the dynamic link will have to
5993 do something. If so, we wish to segregate the data in order to
5994 minimize cache misses inside the dynamic linker. */
5995 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
5996 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6000 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6001 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6002 else if (reloc
|| flag_merge_constants
< 2)
6003 /* C and C++ don't allow different variables to share the same
6004 location. -fmerge-all-constants allows even that (at the
6005 expense of not conforming). */
6006 ret
= SECCAT_RODATA
;
6007 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6008 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6010 ret
= SECCAT_RODATA_MERGE_CONST
;
6012 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6014 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6015 || TREE_SIDE_EFFECTS (decl
)
6016 || ! TREE_CONSTANT (decl
))
6019 ret
= SECCAT_RODATA
;
6022 ret
= SECCAT_RODATA
;
6024 /* There are no read-only thread-local sections. */
6025 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6027 /* Note that this would be *just* SECCAT_BSS, except that there's
6028 no concept of a read-only thread-local-data section. */
6029 if (ret
== SECCAT_BSS
6030 || (flag_zero_initialized_in_bss
6031 && initializer_zerop (DECL_INITIAL (decl
))))
6037 /* If the target uses small data sections, select it. */
6038 else if (targetm
.in_small_data_p (decl
))
6040 if (ret
== SECCAT_BSS
)
6042 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6043 ret
= SECCAT_SRODATA
;
6052 decl_readonly_section (const_tree decl
, int reloc
)
6054 switch (categorize_decl_for_section (decl
, reloc
))
6057 case SECCAT_RODATA_MERGE_STR
:
6058 case SECCAT_RODATA_MERGE_STR_INIT
:
6059 case SECCAT_RODATA_MERGE_CONST
:
6060 case SECCAT_SRODATA
:
6069 /* Select a section based on the above categorization. */
6072 default_elf_select_section (tree decl
, int reloc
,
6073 unsigned HOST_WIDE_INT align
)
6076 switch (categorize_decl_for_section (decl
, reloc
))
6079 /* We're not supposed to be called on FUNCTION_DECLs. */
6082 return readonly_data_section
;
6083 case SECCAT_RODATA_MERGE_STR
:
6084 return mergeable_string_section (decl
, align
, 0);
6085 case SECCAT_RODATA_MERGE_STR_INIT
:
6086 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6087 case SECCAT_RODATA_MERGE_CONST
:
6088 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6089 case SECCAT_SRODATA
:
6093 return data_section
;
6094 case SECCAT_DATA_REL
:
6095 sname
= ".data.rel";
6097 case SECCAT_DATA_REL_LOCAL
:
6098 sname
= ".data.rel.local";
6100 case SECCAT_DATA_REL_RO
:
6101 sname
= ".data.rel.ro";
6103 case SECCAT_DATA_REL_RO_LOCAL
:
6104 sname
= ".data.rel.ro.local";
6129 return get_named_section (decl
, sname
, reloc
);
6132 /* Construct a unique section name based on the decl name and the
6133 categorization performed above. */
6136 default_unique_section (tree decl
, int reloc
)
6138 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6139 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6140 const char *prefix
, *name
, *linkonce
;
6143 switch (categorize_decl_for_section (decl
, reloc
))
6146 prefix
= one_only
? ".t" : ".text";
6149 case SECCAT_RODATA_MERGE_STR
:
6150 case SECCAT_RODATA_MERGE_STR_INIT
:
6151 case SECCAT_RODATA_MERGE_CONST
:
6152 prefix
= one_only
? ".r" : ".rodata";
6154 case SECCAT_SRODATA
:
6155 prefix
= one_only
? ".s2" : ".sdata2";
6158 prefix
= one_only
? ".d" : ".data";
6160 case SECCAT_DATA_REL
:
6161 prefix
= one_only
? ".d.rel" : ".data.rel";
6163 case SECCAT_DATA_REL_LOCAL
:
6164 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6166 case SECCAT_DATA_REL_RO
:
6167 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6169 case SECCAT_DATA_REL_RO_LOCAL
:
6170 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6173 prefix
= one_only
? ".s" : ".sdata";
6176 prefix
= one_only
? ".b" : ".bss";
6179 prefix
= one_only
? ".sb" : ".sbss";
6182 prefix
= one_only
? ".td" : ".tdata";
6185 prefix
= one_only
? ".tb" : ".tbss";
6191 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6192 name
= targetm
.strip_name_encoding (name
);
6194 /* If we're using one_only, then there needs to be a .gnu.linkonce
6195 prefix to the section name. */
6196 linkonce
= one_only
? ".gnu.linkonce" : "";
6198 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6200 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6203 /* Like compute_reloc_for_constant, except for an RTX. The return value
6204 is a mask for which bit 1 indicates a global relocation, and bit 0
6205 indicates a local relocation. */
6208 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6210 int *preloc
= (int *) data
;
6213 switch (GET_CODE (x
))
6216 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6229 compute_reloc_for_rtx (rtx x
)
6233 switch (GET_CODE (x
))
6239 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6248 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6250 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6252 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6253 return data_section
;
6255 return readonly_data_section
;
6259 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6260 unsigned HOST_WIDE_INT align
)
6262 int reloc
= compute_reloc_for_rtx (x
);
6264 /* ??? Handle small data here somehow. */
6266 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6269 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6271 return get_named_section (NULL
, ".data.rel.ro", 3);
6274 return mergeable_constant_section (mode
, align
, 0);
6277 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6280 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6285 /* Careful not to prod global register variables. */
6288 symbol
= XEXP (rtl
, 0);
6289 if (GET_CODE (symbol
) != SYMBOL_REF
)
6292 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6293 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6294 flags
|= SYMBOL_FLAG_FUNCTION
;
6295 if (targetm
.binds_local_p (decl
))
6296 flags
|= SYMBOL_FLAG_LOCAL
;
6297 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6298 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6299 else if (targetm
.in_small_data_p (decl
))
6300 flags
|= SYMBOL_FLAG_SMALL
;
6301 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6302 being PUBLIC, the thing *must* be defined in this translation unit.
6303 Prevent this buglet from being propagated into rtl code as well. */
6304 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6305 flags
|= SYMBOL_FLAG_EXTERNAL
;
6307 SYMBOL_REF_FLAGS (symbol
) = flags
;
6310 /* By default, we do nothing for encode_section_info, so we need not
6311 do anything but discard the '*' marker. */
6314 default_strip_name_encoding (const char *str
)
6316 return str
+ (*str
== '*');
6319 #ifdef ASM_OUTPUT_DEF
6320 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6321 anchor relative to ".", the current section position. */
6324 default_asm_output_anchor (rtx symbol
)
6328 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6329 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6330 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6334 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6337 default_use_anchors_for_symbol_p (const_rtx symbol
)
6342 /* Don't use anchors for mergeable sections. The linker might move
6343 the objects around. */
6344 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6345 if (sect
->common
.flags
& SECTION_MERGE
)
6348 /* Don't use anchors for small data sections. The small data register
6349 acts as an anchor for such sections. */
6350 if (sect
->common
.flags
& SECTION_SMALL
)
6353 decl
= SYMBOL_REF_DECL (symbol
);
6354 if (decl
&& DECL_P (decl
))
6356 /* Don't use section anchors for decls that might be defined by
6358 if (!targetm
.binds_local_p (decl
))
6361 /* Don't use section anchors for decls that will be placed in a
6362 small data section. */
6363 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6364 one above. The problem is that we only use SECTION_SMALL for
6365 sections that should be marked as small in the section directive. */
6366 if (targetm
.in_small_data_p (decl
))
6372 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6373 wrt cross-module name binding. */
6376 default_binds_local_p (const_tree exp
)
6378 return default_binds_local_p_1 (exp
, flag_shlib
);
6382 default_binds_local_p_1 (const_tree exp
, int shlib
)
6386 /* A non-decl is an entry in the constant pool. */
6389 /* Weakrefs may not bind locally, even though the weakref itself is
6390 always static and therefore local. */
6391 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
6393 /* Static variables are always local. */
6394 else if (! TREE_PUBLIC (exp
))
6396 /* A variable is local if the user has said explicitly that it will
6398 else if (DECL_VISIBILITY_SPECIFIED (exp
)
6399 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6401 /* Variables defined outside this object might not be local. */
6402 else if (DECL_EXTERNAL (exp
))
6404 /* If defined in this object and visibility is not default, must be
6406 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6408 /* Default visibility weak data can be overridden by a strong symbol
6409 in another module and so are not local. */
6410 else if (DECL_WEAK (exp
))
6412 /* If PIC, then assume that any global name can be overridden by
6413 symbols resolved from other modules, unless we are compiling with
6414 -fwhole-program, which assumes that names are local. */
6416 local_p
= flag_whole_program
;
6417 /* Uninitialized COMMON variable may be unified with symbols
6418 resolved from other modules. */
6419 else if (DECL_COMMON (exp
)
6420 && (DECL_INITIAL (exp
) == NULL
6421 || DECL_INITIAL (exp
) == error_mark_node
))
6423 /* Otherwise we're left with initialized (or non-common) global data
6424 which is of necessity defined locally. */
6431 /* Default function to output code that will globalize a label. A
6432 target must define GLOBAL_ASM_OP or provide its own function to
6433 globalize a label. */
6434 #ifdef GLOBAL_ASM_OP
6436 default_globalize_label (FILE * stream
, const char *name
)
6438 fputs (GLOBAL_ASM_OP
, stream
);
6439 assemble_name (stream
, name
);
6440 putc ('\n', stream
);
6442 #endif /* GLOBAL_ASM_OP */
6444 /* Default function to output code that will globalize a declaration. */
6446 default_globalize_decl_name (FILE * stream
, tree decl
)
6448 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6449 targetm
.asm_out
.globalize_label (stream
, name
);
6452 /* Default function to output a label for unwind information. The
6453 default is to do nothing. A target that needs nonlocal labels for
6454 unwind information must provide its own function to do this. */
6456 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6457 tree decl ATTRIBUTE_UNUSED
,
6458 int for_eh ATTRIBUTE_UNUSED
,
6459 int empty ATTRIBUTE_UNUSED
)
6463 /* Default function to output a label to divide up the exception table.
6464 The default is to do nothing. A target that needs/wants to divide
6465 up the table must provide it's own function to do this. */
6467 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6471 /* This is how to output an internal numbered label where PREFIX is
6472 the class of label and LABELNO is the number within the class. */
6475 default_internal_label (FILE *stream
, const char *prefix
,
6476 unsigned long labelno
)
6478 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6479 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6480 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6484 /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
6487 default_asm_declare_constant_name (FILE *file
, const char *name
,
6488 const_tree exp ATTRIBUTE_UNUSED
,
6489 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
6491 assemble_label (file
, name
);
6494 /* This is the default behavior at the beginning of a file. It's
6495 controlled by two other target-hook toggles. */
6497 default_file_start (void)
6499 if (targetm
.asm_file_start_app_off
6500 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6501 fputs (ASM_APP_OFF
, asm_out_file
);
6503 if (targetm
.asm_file_start_file_directive
)
6504 output_file_directive (asm_out_file
, main_input_filename
);
6507 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6508 which emits a special section directive used to indicate whether or
6509 not this object file needs an executable stack. This is primarily
6510 a GNU extension to ELF but could be used on other targets. */
6512 int trampolines_created
;
6515 file_end_indicate_exec_stack (void)
6517 unsigned int flags
= SECTION_DEBUG
;
6518 if (trampolines_created
)
6519 flags
|= SECTION_CODE
;
6521 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6524 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6525 a get_unnamed_section callback. */
6528 output_section_asm_op (const void *directive
)
6530 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
6533 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6534 the current section is NEW_SECTION. */
6537 switch_to_section (section
*new_section
)
6539 if (in_section
== new_section
)
6542 if (new_section
->common
.flags
& SECTION_FORGET
)
6545 in_section
= new_section
;
6547 switch (SECTION_STYLE (new_section
))
6551 && !crtl
->subsections
.unlikely_text_section_name
6552 && strcmp (new_section
->named
.name
,
6553 UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6554 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
6556 targetm
.asm_out
.named_section (new_section
->named
.name
,
6557 new_section
->named
.common
.flags
,
6558 new_section
->named
.decl
);
6561 case SECTION_UNNAMED
:
6562 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
6565 case SECTION_NOSWITCH
:
6570 new_section
->common
.flags
|= SECTION_DECLARED
;
6573 /* If block symbol SYMBOL has not yet been assigned an offset, place
6574 it at the end of its block. */
6577 place_block_symbol (rtx symbol
)
6579 unsigned HOST_WIDE_INT size
, mask
, offset
;
6580 struct constant_descriptor_rtx
*desc
;
6581 unsigned int alignment
;
6582 struct object_block
*block
;
6585 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
6586 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
6589 /* Work out the symbol's size and alignment. */
6590 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6592 desc
= SYMBOL_REF_CONSTANT (symbol
);
6593 alignment
= desc
->align
;
6594 size
= GET_MODE_SIZE (desc
->mode
);
6596 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6598 decl
= SYMBOL_REF_DECL (symbol
);
6599 alignment
= DECL_ALIGN (decl
);
6600 size
= get_constant_size (DECL_INITIAL (decl
));
6604 decl
= SYMBOL_REF_DECL (symbol
);
6605 alignment
= DECL_ALIGN (decl
);
6606 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
6609 /* Calculate the object's offset from the start of the block. */
6610 block
= SYMBOL_REF_BLOCK (symbol
);
6611 mask
= alignment
/ BITS_PER_UNIT
- 1;
6612 offset
= (block
->size
+ mask
) & ~mask
;
6613 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
6615 /* Record the block's new alignment and size. */
6616 block
->alignment
= MAX (block
->alignment
, alignment
);
6617 block
->size
= offset
+ size
;
6619 VEC_safe_push (rtx
, gc
, block
->objects
, symbol
);
6622 /* Return the anchor that should be used to address byte offset OFFSET
6623 from the first object in BLOCK. MODEL is the TLS model used
6627 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
6628 enum tls_model model
)
6631 unsigned int begin
, middle
, end
;
6632 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
6635 /* Work out the anchor's offset. Use an offset of 0 for the first
6636 anchor so that we don't pessimize the case where we take the address
6637 of a variable at the beginning of the block. This is particularly
6638 useful when a block has only one variable assigned to it.
6640 We try to place anchors RANGE bytes apart, so there can then be
6641 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
6642 a ptr_mode offset. With some target settings, the lowest such
6643 anchor might be out of range for the lowest ptr_mode offset;
6644 likewise the highest anchor for the highest offset. Use anchors
6645 at the extreme ends of the ptr_mode range in such cases.
6647 All arithmetic uses unsigned integers in order to avoid
6649 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
6650 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
6651 range
= max_offset
- min_offset
+ 1;
6656 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
6659 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
6660 delta
-= delta
% range
;
6663 offset
= (HOST_WIDE_INT
) (-delta
);
6667 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
6668 delta
-= delta
% range
;
6669 if (delta
> bias
- 1)
6671 offset
= (HOST_WIDE_INT
) delta
;
6675 /* Do a binary search to see if there's already an anchor we can use.
6676 Set BEGIN to the new anchor's index if not. */
6678 end
= VEC_length (rtx
, block
->anchors
);
6679 while (begin
!= end
)
6681 middle
= (end
+ begin
) / 2;
6682 anchor
= VEC_index (rtx
, block
->anchors
, middle
);
6683 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
6685 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
6687 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
6689 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
6695 /* Create a new anchor with a unique label. */
6696 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
6697 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
6698 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
6699 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
6701 /* Insert it at index BEGIN. */
6702 VEC_safe_insert (rtx
, gc
, block
->anchors
, begin
, anchor
);
6706 /* Output the objects in BLOCK. */
6709 output_object_block (struct object_block
*block
)
6711 struct constant_descriptor_rtx
*desc
;
6713 HOST_WIDE_INT offset
;
6717 if (block
->objects
== NULL
)
6720 /* Switch to the section and make sure that the first byte is
6721 suitably aligned. */
6722 switch_to_section (block
->sect
);
6723 assemble_align (block
->alignment
);
6725 /* Define the values of all anchors relative to the current section
6727 FOR_EACH_VEC_ELT (rtx
, block
->anchors
, i
, symbol
)
6728 targetm
.asm_out
.output_anchor (symbol
);
6730 /* Output the objects themselves. */
6732 FOR_EACH_VEC_ELT (rtx
, block
->objects
, i
, symbol
)
6734 /* Move to the object's offset, padding with zeros if necessary. */
6735 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
6736 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
6737 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6739 desc
= SYMBOL_REF_CONSTANT (symbol
);
6740 output_constant_pool_1 (desc
, 1);
6741 offset
+= GET_MODE_SIZE (desc
->mode
);
6743 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6745 decl
= SYMBOL_REF_DECL (symbol
);
6746 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
6748 offset
+= get_constant_size (DECL_INITIAL (decl
));
6752 decl
= SYMBOL_REF_DECL (symbol
);
6753 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
6754 offset
+= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
6759 /* A htab_traverse callback used to call output_object_block for
6760 each member of object_block_htab. */
6763 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
6765 output_object_block ((struct object_block
*) (*slot
));
6769 /* Output the definitions of all object_blocks. */
6772 output_object_blocks (void)
6774 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
6777 /* This function provides a possible implementation of the
6778 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
6779 by -frecord-gcc-switches it creates a new mergeable, string section in the
6780 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
6781 contains the switches in ASCII format.
6783 FIXME: This code does not correctly handle double quote characters
6784 that appear inside strings, (it strips them rather than preserving them).
6785 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
6786 characters - instead it treats them as sub-string separators. Since
6787 we want to emit NUL strings terminators into the object file we have to use
6791 elf_record_gcc_switches (print_switch_type type
, const char * name
)
6795 case SWITCH_TYPE_PASSED
:
6796 ASM_OUTPUT_ASCII (asm_out_file
, name
, strlen (name
));
6797 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
6800 case SWITCH_TYPE_DESCRIPTIVE
:
6803 /* Distinguish between invocations where name is NULL. */
6804 static bool started
= false;
6810 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
6814 | (SECTION_ENTSIZE
& 1),
6816 switch_to_section (sec
);
6825 /* The return value is currently ignored by the caller, but must be 0.
6826 For -fverbose-asm the return value would be the number of characters
6827 emitted into the assembler file. */
6831 /* Emit text to declare externally defined symbols. It is needed to
6832 properly support non-default visibility. */
6834 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
6836 const char *name ATTRIBUTE_UNUSED
)
6838 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
6839 set in order to avoid putting out names that are never really
6841 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
6842 && targetm
.binds_local_p (decl
))
6843 maybe_assemble_visibility (decl
);
6846 /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
6849 default_asm_output_source_filename (FILE *file
, const char *name
)
6851 #ifdef ASM_OUTPUT_SOURCE_FILENAME
6852 ASM_OUTPUT_SOURCE_FILENAME (file
, name
);
6854 fprintf (file
, "\t.file\t");
6855 output_quoted_string (file
, name
);
6860 /* Output a file name in the form wanted by System V. */
6863 output_file_directive (FILE *asm_file
, const char *input_name
)
6868 if (input_name
== NULL
)
6869 input_name
= "<stdin>";
6871 input_name
= remap_debug_filename (input_name
);
6873 len
= strlen (input_name
);
6874 na
= input_name
+ len
;
6876 /* NA gets INPUT_NAME sans directory names. */
6877 while (na
> input_name
)
6879 if (IS_DIR_SEPARATOR (na
[-1]))
6884 targetm
.asm_out
.output_source_filename (asm_file
, na
);
6887 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
6890 make_debug_expr_from_rtl (const_rtx exp
)
6892 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
6893 enum machine_mode mode
= GET_MODE (exp
);
6896 DECL_ARTIFICIAL (ddecl
) = 1;
6897 if (REG_P (exp
) && REG_EXPR (exp
))
6898 type
= TREE_TYPE (REG_EXPR (exp
));
6899 else if (MEM_P (exp
) && MEM_EXPR (exp
))
6900 type
= TREE_TYPE (MEM_EXPR (exp
));
6903 if (type
&& TYPE_MODE (type
) == mode
)
6904 TREE_TYPE (ddecl
) = type
;
6906 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
6907 DECL_MODE (ddecl
) = mode
;
6908 dval
= gen_rtx_DEBUG_EXPR (mode
);
6909 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
6910 SET_DECL_RTL (ddecl
, dval
);
6914 #include "gt-varasm.h"