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
4 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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 /* This file handles generation of all the assembler code
25 *except* the instructions of a function.
26 This includes declarations of variables and their initial values.
28 We also output the assembler code for constants stored in memory
29 and are responsible for combining constants with the same value. */
33 #include "coretypes.h"
40 #include "hard-reg-set.h"
48 #include "langhooks.h"
52 #include "tree-mudflap.h"
54 #include "cfglayout.h"
55 #include "basic-block.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 struct varasm_status
GTY(())
75 /* If we're using a per-function constant pool, this is it. */
76 struct rtx_constant_pool
*pool
;
78 /* Number of tree-constants deferred during the expansion of this
80 unsigned int deferred_constants
;
83 #define n_deferred_constants (cfun->varasm->deferred_constants)
85 /* Number for making the label on the next
86 constant that is stored in memory. */
88 static GTY(()) int const_labelno
;
90 /* Carry information from ASM_DECLARE_OBJECT_NAME
91 to ASM_FINISH_DECLARE_OBJECT. */
93 int size_directive_output
;
95 /* The last decl for which assemble_variable was called,
96 if it did ASM_DECLARE_OBJECT_NAME.
97 If the last call to assemble_variable didn't do that,
100 tree last_assemble_variable_decl
;
102 /* The following global variable indicates if the first basic block
103 in a function belongs to the cold partition or not. */
105 bool first_function_block_is_cold
;
107 /* We give all constants their own alias set. Perhaps redundant with
108 MEM_READONLY_P, but pre-dates it. */
110 static HOST_WIDE_INT const_alias_set
;
112 static const char *strip_reg_name (const char *);
113 static int contains_pointers_p (tree
);
114 #ifdef ASM_OUTPUT_EXTERNAL
115 static bool incorporeal_function_p (tree
);
117 static void decode_addr_const (tree
, struct addr_const
*);
118 static hashval_t
const_desc_hash (const void *);
119 static int const_desc_eq (const void *, const void *);
120 static hashval_t
const_hash_1 (const tree
);
121 static int compare_constant (const tree
, const tree
);
122 static tree
copy_constant (tree
);
123 static void output_constant_def_contents (rtx
);
124 static void output_addressed_constants (tree
);
125 static unsigned HOST_WIDE_INT
array_size_for_constructor (tree
);
126 static unsigned min_align (unsigned, unsigned);
127 static void output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int);
128 static void globalize_decl (tree
);
129 static void maybe_assemble_visibility (tree
);
130 #ifdef BSS_SECTION_ASM_OP
131 #ifdef ASM_OUTPUT_BSS
132 static void asm_output_bss (FILE *, tree
, const char *,
133 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
135 #ifdef ASM_OUTPUT_ALIGNED_BSS
136 static void asm_output_aligned_bss (FILE *, tree
, const char *,
137 unsigned HOST_WIDE_INT
, int)
140 #endif /* BSS_SECTION_ASM_OP */
141 static bool asm_emit_uninitialised (tree
, const char*,
142 unsigned HOST_WIDE_INT
,
143 unsigned HOST_WIDE_INT
);
144 static void mark_weak (tree
);
146 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
147 section
*text_section
;
148 section
*data_section
;
149 section
*readonly_data_section
;
150 section
*sdata_section
;
151 section
*ctors_section
;
152 section
*dtors_section
;
153 section
*bss_section
;
154 section
*sbss_section
;
155 section
*init_section
;
156 section
*fini_section
;
158 /* The section that holds the main exception table. */
159 section
*exception_section
;
161 /* The section that holds the DWARF2 frame unwind information. If it
162 is null, we will place the unwind information in the data section
163 and emit special labels to guide collect2. */
164 section
*eh_frame_section
;
166 /* asm_out_file's current section. This is NULL if no section has yet
167 been selected or if we lose track of what the current section is. */
170 /* The last text section used by asm_out_file. */
171 section
*last_text_section
;
173 /* A linked list of all the unnamed sections. */
174 static GTY(()) section
*unnamed_sections
;
176 /* Return a nonzero value if DECL has a section attribute. */
177 #ifndef IN_NAMED_SECTION
178 #define IN_NAMED_SECTION(DECL) \
179 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
180 && DECL_SECTION_NAME (DECL) != NULL_TREE)
183 /* Hash table of named sections. */
184 static GTY((param_is (section
))) htab_t section_htab
;
186 /* Helper routines for maintaining section_htab. */
189 section_entry_eq (const void *p1
, const void *p2
)
191 const section
*old
= p1
;
192 const char *new = p2
;
194 return strcmp (old
->named
.name
, new) == 0;
198 section_entry_hash (const void *p
)
200 const section
*old
= p
;
201 return htab_hash_string (old
->named
.name
);
204 /* Return a new unnamed section with the given fields. */
207 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
212 sect
= ggc_alloc (sizeof (struct unnamed_section
));
213 sect
->unnamed
.common
.flags
= flags
;
214 sect
->unnamed
.callback
= callback
;
215 sect
->unnamed
.data
= data
;
216 sect
->unnamed
.next
= unnamed_sections
;
218 unnamed_sections
= sect
;
222 /* Return the named section structure associated with NAME. Create
223 a new section with the given fields if no such structure exists. */
226 get_section (const char *name
, unsigned int flags
, tree decl
)
228 section
*sect
, **slot
;
231 htab_find_slot_with_hash (section_htab
, name
,
232 htab_hash_string (name
), INSERT
);
235 sect
= ggc_alloc (sizeof (struct named_section
));
236 sect
->named
.common
.flags
= flags
| SECTION_NAMED
;
237 sect
->named
.name
= ggc_strdup (name
);
238 sect
->named
.decl
= decl
;
244 if ((sect
->common
.flags
& ~(SECTION_DECLARED
| SECTION_NAMED
)) != flags
245 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
247 /* Sanity check user variables for flag changes. */
249 decl
= sect
->named
.decl
;
251 error ("%+D causes a section type conflict", decl
);
260 initialize_cold_section_name (void)
262 const char *stripped_name
;
266 gcc_assert (cfun
&& current_function_decl
);
267 if (cfun
->unlikely_text_section_name
)
270 dsn
= DECL_SECTION_NAME (current_function_decl
);
271 if (flag_function_sections
&& dsn
)
273 name
= alloca (TREE_STRING_LENGTH (dsn
) + 1);
274 memcpy (name
, TREE_STRING_POINTER (dsn
), TREE_STRING_LENGTH (dsn
) + 1);
276 stripped_name
= targetm
.strip_name_encoding (name
);
278 buffer
= ACONCAT ((stripped_name
, "_unlikely", NULL
));
279 cfun
->unlikely_text_section_name
= ggc_strdup (buffer
);
282 cfun
->unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
285 /* Tell assembler to switch to unlikely-to-be-executed text section. */
288 unlikely_text_section (void)
292 if (!cfun
->unlikely_text_section_name
)
293 initialize_cold_section_name ();
295 return get_named_section (NULL
, cfun
->unlikely_text_section_name
, 0);
298 return get_named_section (NULL
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
, 0);
301 /* When called within a function context, return true if the function
302 has been assigned a cold text section and if SECT is that section.
303 When called outside a function context, return true if SECT is the
304 default cold section. */
307 unlikely_text_section_p (section
*sect
)
312 name
= cfun
->unlikely_text_section_name
;
314 name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
318 && (sect
->common
.flags
& SECTION_NAMED
) != 0
319 && strcmp (name
, sect
->named
.name
) == 0);
322 /* Return a section with a particular name and with whatever SECTION_*
323 flags section_type_flags deems appropriate. The name of the section
324 is taken from NAME if nonnull, otherwise it is taken from DECL's
325 DECL_SECTION_NAME. DECL is the decl associated with the section
326 (see the section comment for details) and RELOC is as for
327 section_type_flags. */
330 get_named_section (tree decl
, const char *name
, int reloc
)
334 gcc_assert (!decl
|| DECL_P (decl
));
336 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
338 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
340 return get_section (name
, flags
, decl
);
343 /* If required, set DECL_SECTION_NAME to a unique name. */
346 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
347 int flag_function_or_data_sections
)
349 if (DECL_SECTION_NAME (decl
) == NULL_TREE
350 && targetm
.have_named_sections
351 && (flag_function_or_data_sections
352 || DECL_ONE_ONLY (decl
)))
353 targetm
.asm_out
.unique_section (decl
, reloc
);
356 #ifdef BSS_SECTION_ASM_OP
358 #ifdef ASM_OUTPUT_BSS
360 /* Utility function for ASM_OUTPUT_BSS for targets to use if
361 they don't support alignments in .bss.
362 ??? It is believed that this function will work in most cases so such
363 support is localized here. */
366 asm_output_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
368 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
369 unsigned HOST_WIDE_INT rounded
)
371 targetm
.asm_out
.globalize_label (file
, name
);
372 switch_to_section (bss_section
);
373 #ifdef ASM_DECLARE_OBJECT_NAME
374 last_assemble_variable_decl
= decl
;
375 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
377 /* Standard thing is just output label for the object. */
378 ASM_OUTPUT_LABEL (file
, name
);
379 #endif /* ASM_DECLARE_OBJECT_NAME */
380 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
385 #ifdef ASM_OUTPUT_ALIGNED_BSS
387 /* Utility function for targets to use in implementing
388 ASM_OUTPUT_ALIGNED_BSS.
389 ??? It is believed that this function will work in most cases so such
390 support is localized here. */
393 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
394 const char *name
, unsigned HOST_WIDE_INT size
,
397 switch_to_section (bss_section
);
398 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
399 #ifdef ASM_DECLARE_OBJECT_NAME
400 last_assemble_variable_decl
= decl
;
401 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
403 /* Standard thing is just output label for the object. */
404 ASM_OUTPUT_LABEL (file
, name
);
405 #endif /* ASM_DECLARE_OBJECT_NAME */
406 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
411 #endif /* BSS_SECTION_ASM_OP */
413 /* Return the section for function DECL.
415 If DECL is NULL_TREE, return the text section. We can be passed
416 NULL_TREE under some circumstances by dbxout.c at least. */
419 function_section (tree decl
)
423 if (first_function_block_is_cold
)
426 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
427 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
429 if (decl
!= NULL_TREE
430 && DECL_SECTION_NAME (decl
) != NULL_TREE
431 && targetm
.have_named_sections
)
432 return get_named_section (decl
, NULL
, 0);
439 current_function_section (void)
441 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
444 if (unlikely_text_section_p (last_text_section
))
447 return targetm
.asm_out
.select_section (current_function_decl
, reloc
,
448 DECL_ALIGN (current_function_decl
));
450 if (last_text_section
)
451 return last_text_section
;
452 return function_section (current_function_decl
);
456 /* Return the read-only data section associated with function DECL. */
459 default_function_rodata_section (tree decl
)
461 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
463 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
465 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
467 size_t len
= strlen (name
) + 3;
468 char* rname
= alloca (len
);
470 strcpy (rname
, ".rodata");
471 strcat (rname
, name
+ 5);
472 return get_section (rname
, SECTION_LINKONCE
, decl
);
474 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
475 else if (DECL_ONE_ONLY (decl
)
476 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
478 size_t len
= strlen (name
) + 1;
479 char *rname
= alloca (len
);
481 memcpy (rname
, name
, len
);
483 return get_section (rname
, SECTION_LINKONCE
, decl
);
485 /* For .text.foo we want to use .rodata.foo. */
486 else if (flag_function_sections
&& flag_data_sections
487 && strncmp (name
, ".text.", 6) == 0)
489 size_t len
= strlen (name
) + 1;
490 char *rname
= alloca (len
+ 2);
492 memcpy (rname
, ".rodata", 7);
493 memcpy (rname
+ 7, name
+ 5, len
- 5);
494 return get_section (rname
, 0, decl
);
498 return readonly_data_section
;
501 /* Return the read-only data section associated with function DECL
502 for targets where that section should be always the single
503 readonly data section. */
506 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
508 return readonly_data_section
;
511 /* Switch to section for variable DECL. RELOC is the same as the
512 argument to SELECT_SECTION. */
515 variable_section (tree decl
, int reloc
)
517 if (IN_NAMED_SECTION (decl
))
518 switch_to_section (get_named_section (decl
, NULL
, reloc
));
520 switch_to_section (targetm
.asm_out
.select_section (decl
, reloc
,
524 /* Return the section to use for string merging. */
527 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
528 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
529 unsigned int flags ATTRIBUTE_UNUSED
)
531 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
532 && TREE_CODE (decl
) == STRING_CST
533 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
535 && TREE_STRING_LENGTH (decl
) >= int_size_in_bytes (TREE_TYPE (decl
)))
537 enum machine_mode mode
;
538 unsigned int modesize
;
543 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
544 modesize
= GET_MODE_BITSIZE (mode
);
545 if (modesize
>= 8 && modesize
<= 256
546 && (modesize
& (modesize
- 1)) == 0)
548 if (align
< modesize
)
551 str
= TREE_STRING_POINTER (decl
);
552 len
= TREE_STRING_LENGTH (decl
);
553 unit
= GET_MODE_SIZE (mode
);
555 /* Check for embedded NUL characters. */
556 for (i
= 0; i
< len
; i
+= unit
)
558 for (j
= 0; j
< unit
; j
++)
559 if (str
[i
+ j
] != '\0')
566 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
568 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
569 return get_section (name
, flags
, NULL
);
574 return readonly_data_section
;
577 /* Return the section to use for constant merging. */
580 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
581 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
582 unsigned int flags ATTRIBUTE_UNUSED
)
584 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
586 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
592 && (align
& (align
- 1)) == 0)
596 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
597 flags
|= (align
/ 8) | SECTION_MERGE
;
598 return get_section (name
, flags
, NULL
);
600 return readonly_data_section
;
603 /* Given NAME, a putative register name, discard any customary prefixes. */
606 strip_reg_name (const char *name
)
608 #ifdef REGISTER_PREFIX
609 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
610 name
+= strlen (REGISTER_PREFIX
);
612 if (name
[0] == '%' || name
[0] == '#')
617 /* The user has asked for a DECL to have a particular name. Set (or
618 change) it in such a way that we don't prefix an underscore to
621 set_user_assembler_name (tree decl
, const char *name
)
623 char *starred
= alloca (strlen (name
) + 2);
625 strcpy (starred
+ 1, name
);
626 change_decl_assembler_name (decl
, get_identifier (starred
));
627 SET_DECL_RTL (decl
, NULL_RTX
);
630 /* Decode an `asm' spec for a declaration as a register name.
631 Return the register number, or -1 if nothing specified,
632 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
633 or -3 if ASMSPEC is `cc' and is not recognized,
634 or -4 if ASMSPEC is `memory' and is not recognized.
635 Accept an exact spelling or a decimal number.
636 Prefixes such as % are optional. */
639 decode_reg_name (const char *asmspec
)
645 /* Get rid of confusing prefixes. */
646 asmspec
= strip_reg_name (asmspec
);
648 /* Allow a decimal number as a "register name". */
649 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
650 if (! ISDIGIT (asmspec
[i
]))
652 if (asmspec
[0] != 0 && i
< 0)
655 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
661 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
663 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
666 #ifdef ADDITIONAL_REGISTER_NAMES
668 static const struct { const char *const name
; const int number
; } table
[]
669 = ADDITIONAL_REGISTER_NAMES
;
671 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
673 && ! strcmp (asmspec
, table
[i
].name
))
674 return table
[i
].number
;
676 #endif /* ADDITIONAL_REGISTER_NAMES */
678 if (!strcmp (asmspec
, "memory"))
681 if (!strcmp (asmspec
, "cc"))
690 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
691 have static storage duration. In other words, it should not be an
692 automatic variable, including PARM_DECLs.
694 There is, however, one exception: this function handles variables
695 explicitly placed in a particular register by the user.
697 This is never called for PARM_DECL nodes. */
700 make_decl_rtl (tree decl
)
702 const char *name
= 0;
706 /* Check that we are not being given an automatic variable. */
707 gcc_assert (TREE_CODE (decl
) != PARM_DECL
708 && TREE_CODE (decl
) != RESULT_DECL
);
710 /* A weak alias has TREE_PUBLIC set but not the other bits. */
711 gcc_assert (TREE_CODE (decl
) != VAR_DECL
712 || TREE_STATIC (decl
)
713 || TREE_PUBLIC (decl
)
714 || DECL_EXTERNAL (decl
)
715 || DECL_REGISTER (decl
));
717 /* And that we were not given a type or a label. */
718 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
719 && TREE_CODE (decl
) != LABEL_DECL
);
721 /* For a duplicate declaration, we can be called twice on the
722 same DECL node. Don't discard the RTL already made. */
723 if (DECL_RTL_SET_P (decl
))
725 /* If the old RTL had the wrong mode, fix the mode. */
726 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
727 SET_DECL_RTL (decl
, adjust_address_nv (DECL_RTL (decl
),
728 DECL_MODE (decl
), 0));
730 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
733 /* ??? Another way to do this would be to maintain a hashed
734 table of such critters. Instead of adding stuff to a DECL
735 to give certain attributes to it, we could use an external
736 hash map from DECL to set of attributes. */
738 /* Let the target reassign the RTL if it wants.
739 This is necessary, for example, when one machine specific
740 decl attribute overrides another. */
741 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
743 /* Make this function static known to the mudflap runtime. */
744 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
745 mudflap_enqueue_decl (decl
);
750 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
752 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
753 && DECL_REGISTER (decl
))
755 error ("register name not specified for %q+D", decl
);
757 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
759 const char *asmspec
= name
+1;
760 reg_number
= decode_reg_name (asmspec
);
761 /* First detect errors in declaring global registers. */
762 if (reg_number
== -1)
763 error ("register name not specified for %q+D", decl
);
764 else if (reg_number
< 0)
765 error ("invalid register name for %q+D", decl
);
766 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
767 error ("data type of %q+D isn%'t suitable for a register",
769 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
770 error ("register specified for %q+D isn%'t suitable for data type",
772 /* Now handle properly declared static register variables. */
777 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
779 DECL_INITIAL (decl
) = 0;
780 error ("global register variable has initial value");
782 if (TREE_THIS_VOLATILE (decl
))
783 warning (OPT_Wvolatile_register_var
,
784 "optimization may eliminate reads and/or "
785 "writes to register variables");
787 /* If the user specified one of the eliminables registers here,
788 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
789 confused with that register and be eliminated. This usage is
790 somewhat suspect... */
792 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
793 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
794 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
796 if (TREE_STATIC (decl
))
798 /* Make this register global, so not usable for anything
800 #ifdef ASM_DECLARE_REGISTER_GLOBAL
801 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
802 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
804 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
806 globalize_reg (reg_number
+ --nregs
);
809 /* As a register variable, it has no section. */
813 /* Now handle ordinary static variables and functions (in memory).
814 Also handle vars declared register invalidly. */
815 else if (name
[0] == '*')
817 #ifdef REGISTER_PREFIX
818 if (strlen (REGISTER_PREFIX
) != 0)
820 reg_number
= decode_reg_name (name
);
821 if (reg_number
>= 0 || reg_number
== -3)
822 error ("register name given for non-register variable %q+D", decl
);
827 /* Specifying a section attribute on a variable forces it into a
828 non-.bss section, and thus it cannot be common. */
829 if (TREE_CODE (decl
) == VAR_DECL
830 && DECL_SECTION_NAME (decl
) != NULL_TREE
831 && DECL_INITIAL (decl
) == NULL_TREE
832 && DECL_COMMON (decl
))
833 DECL_COMMON (decl
) = 0;
835 /* Variables can't be both common and weak. */
836 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
837 DECL_COMMON (decl
) = 0;
839 x
= gen_rtx_SYMBOL_REF (Pmode
, name
);
840 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
841 SYMBOL_REF_DECL (x
) = decl
;
843 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
844 if (TREE_CODE (decl
) != FUNCTION_DECL
)
845 set_mem_attributes (x
, decl
, 1);
846 SET_DECL_RTL (decl
, x
);
848 /* Optionally set flags or add text to the name to record information
849 such as that it is a function name.
850 If the name is changed, the macro ASM_OUTPUT_LABELREF
851 will have to know how to strip this information. */
852 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
854 /* Make this function static known to the mudflap runtime. */
855 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
856 mudflap_enqueue_decl (decl
);
859 /* Make the rtl for variable VAR be volatile.
860 Use this only for static variables. */
863 make_var_volatile (tree var
)
865 gcc_assert (MEM_P (DECL_RTL (var
)));
867 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
870 /* Output a string of literal assembler code
871 for an `asm' keyword used between functions. */
874 assemble_asm (tree string
)
878 if (TREE_CODE (string
) == ADDR_EXPR
)
879 string
= TREE_OPERAND (string
, 0);
881 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
884 /* Record an element in the table of global destructors. SYMBOL is
885 a SYMBOL_REF of the function to be called; PRIORITY is a number
886 between 0 and MAX_INIT_PRIORITY. */
889 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
890 int priority ATTRIBUTE_UNUSED
)
892 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
893 /* Tell GNU LD that this is part of the static destructor set.
894 This will work for any system that uses stabs, most usefully
896 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
897 dbxout_stab_value_label (XSTR (symbol
, 0));
899 sorry ("global destructors not supported on this target");
904 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
906 const char *section
= ".dtors";
909 /* ??? This only works reliably with the GNU linker. */
910 if (priority
!= DEFAULT_INIT_PRIORITY
)
912 sprintf (buf
, ".dtors.%.5u",
913 /* Invert the numbering so the linker puts us in the proper
914 order; constructors are run from right to left, and the
915 linker sorts in increasing order. */
916 MAX_INIT_PRIORITY
- priority
);
920 switch_to_section (get_section (section
, SECTION_WRITE
, NULL
));
921 assemble_align (POINTER_SIZE
);
922 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
925 #ifdef DTORS_SECTION_ASM_OP
927 default_dtor_section_asm_out_destructor (rtx symbol
,
928 int priority ATTRIBUTE_UNUSED
)
930 switch_to_section (dtors_section
);
931 assemble_align (POINTER_SIZE
);
932 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
936 /* Likewise for global constructors. */
939 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
940 int priority ATTRIBUTE_UNUSED
)
942 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
943 /* Tell GNU LD that this is part of the static destructor set.
944 This will work for any system that uses stabs, most usefully
946 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
947 dbxout_stab_value_label (XSTR (symbol
, 0));
949 sorry ("global constructors not supported on this target");
954 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
956 const char *section
= ".ctors";
959 /* ??? This only works reliably with the GNU linker. */
960 if (priority
!= DEFAULT_INIT_PRIORITY
)
962 sprintf (buf
, ".ctors.%.5u",
963 /* Invert the numbering so the linker puts us in the proper
964 order; constructors are run from right to left, and the
965 linker sorts in increasing order. */
966 MAX_INIT_PRIORITY
- priority
);
970 switch_to_section (get_section (section
, SECTION_WRITE
, NULL
));
971 assemble_align (POINTER_SIZE
);
972 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
975 #ifdef CTORS_SECTION_ASM_OP
977 default_ctor_section_asm_out_constructor (rtx symbol
,
978 int priority ATTRIBUTE_UNUSED
)
980 switch_to_section (ctors_section
);
981 assemble_align (POINTER_SIZE
);
982 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
986 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
987 a nonzero value if the constant pool should be output before the
988 start of the function, or a zero value if the pool should output
989 after the end of the function. The default is to put it before the
992 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
993 #define CONSTANT_POOL_BEFORE_FUNCTION 1
996 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
997 to be output to assembler.
998 Set first_global_object_name and weak_global_object_name as appropriate. */
1001 notice_global_symbol (tree decl
)
1003 const char **type
= &first_global_object_name
;
1005 if (first_global_object_name
1006 || !TREE_PUBLIC (decl
) || DECL_EXTERNAL (decl
)
1007 || !DECL_NAME (decl
)
1008 || (TREE_CODE (decl
) != FUNCTION_DECL
1009 && (TREE_CODE (decl
) != VAR_DECL
1010 || (DECL_COMMON (decl
)
1011 && (DECL_INITIAL (decl
) == 0
1012 || DECL_INITIAL (decl
) == error_mark_node
))))
1013 || !MEM_P (DECL_RTL (decl
)))
1016 /* We win when global object is found, but it is useful to know about weak
1017 symbol as well so we can produce nicer unique names. */
1018 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
))
1019 type
= &weak_global_object_name
;
1025 rtx decl_rtl
= DECL_RTL (decl
);
1027 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1028 name
= ggc_strdup (p
);
1034 /* Output assembler code for the constant pool of a function and associated
1035 with defining the name of the function. DECL describes the function.
1036 NAME is the function's name. For the constant pool, we use the current
1037 constant pool data. */
1040 assemble_start_function (tree decl
, const char *fnname
)
1043 char tmp_label
[100];
1044 bool hot_label_written
= false;
1046 cfun
->unlikely_text_section_name
= NULL
;
1048 first_function_block_is_cold
= false;
1049 if (flag_reorder_blocks_and_partition
)
1051 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1052 cfun
->hot_section_label
= ggc_strdup (tmp_label
);
1053 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1054 cfun
->cold_section_label
= ggc_strdup (tmp_label
);
1055 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1056 cfun
->hot_section_end_label
= ggc_strdup (tmp_label
);
1057 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1058 cfun
->cold_section_end_label
= ggc_strdup (tmp_label
);
1063 cfun
->hot_section_label
= NULL
;
1064 cfun
->cold_section_label
= NULL
;
1065 cfun
->hot_section_end_label
= NULL
;
1066 cfun
->cold_section_end_label
= NULL
;
1069 /* The following code does not need preprocessing in the assembler. */
1073 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1074 output_constant_pool (fnname
, decl
);
1076 resolve_unique_section (decl
, 0, flag_function_sections
);
1078 /* Make sure the not and cold text (code) sections are properly
1079 aligned. This is necessary here in the case where the function
1080 has both hot and cold sections, because we don't want to re-set
1081 the alignment when the section switch happens mid-function. */
1083 if (flag_reorder_blocks_and_partition
)
1085 unlikely_text_section ();
1086 assemble_align (FUNCTION_BOUNDARY
);
1087 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->cold_section_label
);
1089 /* When the function starts with a cold section, we need to explicitly
1090 align the hot section and write out the hot section label.
1091 But if the current function is a thunk, we do not have a CFG. */
1092 if (!current_function_is_thunk
1093 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1095 switch_to_section (text_section
);
1096 assemble_align (FUNCTION_BOUNDARY
);
1097 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->hot_section_label
);
1098 hot_label_written
= true;
1099 first_function_block_is_cold
= true;
1102 else if (DECL_SECTION_NAME (decl
))
1104 /* Calls to function_section rely on first_function_block_is_cold
1105 being accurate. The first block may be cold even if we aren't
1106 doing partitioning, if the entire function was decided by
1107 choose_function_section (predict.c) to be cold. */
1109 initialize_cold_section_name ();
1111 if (cfun
->unlikely_text_section_name
1112 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
1113 cfun
->unlikely_text_section_name
) == 0)
1114 first_function_block_is_cold
= true;
1117 last_text_section
= NULL
;
1119 /* Switch to the correct text section for the start of the function. */
1121 switch_to_section (function_section (decl
));
1122 if (flag_reorder_blocks_and_partition
1123 && !hot_label_written
)
1124 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->hot_section_label
);
1126 /* Tell assembler to move to target machine's alignment for functions. */
1127 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1128 if (align
< force_align_functions_log
)
1129 align
= force_align_functions_log
;
1132 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1135 /* Handle a user-specified function alignment.
1136 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1137 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1138 if (align_functions_log
> align
1139 && cfun
->function_frequency
!= FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
)
1141 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1142 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1143 align_functions_log
, align_functions
- 1);
1145 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1149 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1150 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1153 (*debug_hooks
->begin_function
) (decl
);
1155 /* Make function name accessible from other files, if appropriate. */
1157 if (TREE_PUBLIC (decl
))
1159 notice_global_symbol (decl
);
1161 globalize_decl (decl
);
1163 maybe_assemble_visibility (decl
);
1166 if (DECL_PRESERVE_P (decl
))
1167 targetm
.asm_out
.mark_decl_preserved (fnname
);
1169 /* Do any machine/system dependent processing of the function name. */
1170 #ifdef ASM_DECLARE_FUNCTION_NAME
1171 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1173 /* Standard thing is just output label for the function. */
1174 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1175 #endif /* ASM_DECLARE_FUNCTION_NAME */
1178 /* Output assembler code associated with defining the size of the
1179 function. DECL describes the function. NAME is the function's name. */
1182 assemble_end_function (tree decl
, const char *fnname
)
1184 #ifdef ASM_DECLARE_FUNCTION_SIZE
1185 /* We could have switched section in the middle of the function. */
1186 if (flag_reorder_blocks_and_partition
)
1187 switch_to_section (function_section (decl
));
1188 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1190 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1192 output_constant_pool (fnname
, decl
);
1193 switch_to_section (function_section (decl
)); /* need to switch back */
1195 /* Output labels for end of hot/cold text sections (to be used by
1197 if (flag_reorder_blocks_and_partition
)
1199 section
*save_text_section
;
1201 save_text_section
= in_section
;
1202 unlikely_text_section ();
1203 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->cold_section_end_label
);
1204 if (first_function_block_is_cold
)
1205 switch_to_section (text_section
);
1207 switch_to_section (function_section (decl
));
1208 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->hot_section_end_label
);
1209 switch_to_section (save_text_section
);
1213 /* Assemble code to leave SIZE bytes of zeros. */
1216 assemble_zeros (unsigned HOST_WIDE_INT size
)
1218 /* Do no output if -fsyntax-only. */
1219 if (flag_syntax_only
)
1222 #ifdef ASM_NO_SKIP_IN_TEXT
1223 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1224 so we must output 0s explicitly in the text section. */
1225 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1227 unsigned HOST_WIDE_INT i
;
1228 for (i
= 0; i
< size
; i
++)
1229 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1234 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1237 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1240 assemble_align (int align
)
1242 if (align
> BITS_PER_UNIT
)
1244 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1248 /* Assemble a string constant with the specified C string as contents. */
1251 assemble_string (const char *p
, int size
)
1256 /* If the string is very long, split it up. */
1260 int thissize
= size
- pos
;
1261 if (thissize
> maximum
)
1264 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1272 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1273 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1274 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1276 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1277 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1278 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1280 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1281 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1285 #if defined ASM_OUTPUT_ALIGNED_BSS
1286 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1287 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1289 #if defined ASM_OUTPUT_BSS
1290 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1291 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1297 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1298 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1299 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1301 #if defined ASM_OUTPUT_ALIGNED_COMMON
1302 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1303 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1305 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1306 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1311 asm_emit_uninitialised (tree decl
, const char *name
,
1312 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1313 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1321 destination
= asm_dest_local
;
1323 /* ??? We should handle .bss via select_section mechanisms rather than
1324 via special target hooks. That would eliminate this special case. */
1325 if (TREE_PUBLIC (decl
))
1327 if (!DECL_COMMON (decl
))
1329 destination
= asm_dest_bss
;
1334 destination
= asm_dest_common
;
1337 if (destination
!= asm_dest_common
)
1339 resolve_unique_section (decl
, 0, flag_data_sections
);
1340 /* Custom sections don't belong here. */
1341 if (DECL_SECTION_NAME (decl
))
1345 if (destination
== asm_dest_bss
)
1346 globalize_decl (decl
);
1348 if (flag_shared_data
)
1350 switch (destination
)
1352 #ifdef ASM_OUTPUT_SHARED_BSS
1354 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1357 #ifdef ASM_OUTPUT_SHARED_COMMON
1358 case asm_dest_common
:
1359 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1362 #ifdef ASM_OUTPUT_SHARED_LOCAL
1363 case asm_dest_local
:
1364 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1372 switch (destination
)
1376 ASM_EMIT_BSS (decl
, name
, size
, rounded
);
1379 case asm_dest_common
:
1380 ASM_EMIT_COMMON (decl
, name
, size
, rounded
);
1382 case asm_dest_local
:
1383 ASM_EMIT_LOCAL (decl
, name
, size
, rounded
);
1392 /* Assemble everything that is needed for a variable or function declaration.
1393 Not used for automatic variables, and not used for function definitions.
1394 Should not be called for variables of incomplete structure type.
1396 TOP_LEVEL is nonzero if this variable has file scope.
1397 AT_END is nonzero if this is the special handling, at end of compilation,
1398 to define things that have had only tentative definitions.
1399 DONT_OUTPUT_DATA if nonzero means don't actually output the
1400 initial value (that will be done by the caller). */
1403 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
1404 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
1411 if (lang_hooks
.decls
.prepare_assemble_variable
)
1412 lang_hooks
.decls
.prepare_assemble_variable (decl
);
1414 last_assemble_variable_decl
= 0;
1416 /* Normally no need to say anything here for external references,
1417 since assemble_external is called by the language-specific code
1418 when a declaration is first seen. */
1420 if (DECL_EXTERNAL (decl
))
1423 /* Output no assembler code for a function declaration.
1424 Only definitions of functions output anything. */
1426 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1429 /* Do nothing for global register variables. */
1430 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
1432 TREE_ASM_WRITTEN (decl
) = 1;
1436 /* If type was incomplete when the variable was declared,
1437 see if it is complete now. */
1439 if (DECL_SIZE (decl
) == 0)
1440 layout_decl (decl
, 0);
1442 /* Still incomplete => don't allocate it; treat the tentative defn
1443 (which is what it must have been) as an `extern' reference. */
1445 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1447 error ("storage size of %q+D isn%'t known", decl
);
1448 TREE_ASM_WRITTEN (decl
) = 1;
1452 /* The first declaration of a variable that comes through this function
1453 decides whether it is global (in C, has external linkage)
1454 or local (in C, has internal linkage). So do nothing more
1455 if this function has already run. */
1457 if (TREE_ASM_WRITTEN (decl
))
1460 /* Make sure targetm.encode_section_info is invoked before we set
1462 decl_rtl
= DECL_RTL (decl
);
1464 TREE_ASM_WRITTEN (decl
) = 1;
1466 /* Do no output if -fsyntax-only. */
1467 if (flag_syntax_only
)
1472 if (! dont_output_data
1473 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1475 error ("size of variable %q+D is too large", decl
);
1479 name
= XSTR (XEXP (decl_rtl
, 0), 0);
1480 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1481 notice_global_symbol (decl
);
1483 /* Compute the alignment of this data. */
1485 align
= DECL_ALIGN (decl
);
1487 /* In the case for initialing an array whose length isn't specified,
1488 where we have not yet been able to do the layout,
1489 figure out the proper alignment now. */
1490 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1491 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1492 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1494 /* Some object file formats have a maximum alignment which they support.
1495 In particular, a.out format supports a maximum alignment of 4. */
1496 if (align
> MAX_OFILE_ALIGNMENT
)
1498 warning (0, "alignment of %q+D is greater than maximum object "
1499 "file alignment. Using %d", decl
,
1500 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1501 align
= MAX_OFILE_ALIGNMENT
;
1504 /* On some machines, it is good to increase alignment sometimes. */
1505 if (! DECL_USER_ALIGN (decl
))
1507 #ifdef DATA_ALIGNMENT
1508 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1510 #ifdef CONSTANT_ALIGNMENT
1511 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1512 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1516 /* Reset the alignment in case we have made it tighter, so we can benefit
1517 from it in get_pointer_alignment. */
1518 DECL_ALIGN (decl
) = align
;
1519 set_mem_align (decl_rtl
, align
);
1521 if (TREE_PUBLIC (decl
))
1522 maybe_assemble_visibility (decl
);
1524 if (DECL_PRESERVE_P (decl
))
1525 targetm
.asm_out
.mark_decl_preserved (name
);
1527 /* Handle uninitialized definitions. */
1529 /* If the decl has been given an explicit section name, then it
1530 isn't common, and shouldn't be handled as such. */
1531 if (DECL_SECTION_NAME (decl
) || dont_output_data
)
1533 /* We don't implement common thread-local data at present. */
1534 else if (DECL_THREAD_LOCAL_P (decl
))
1536 if (DECL_COMMON (decl
))
1537 sorry ("thread-local COMMON data not implemented");
1539 else if (DECL_INITIAL (decl
) == 0
1540 || DECL_INITIAL (decl
) == error_mark_node
1541 || (flag_zero_initialized_in_bss
1542 /* Leave constant zeroes in .rodata so they can be shared. */
1543 && !TREE_READONLY (decl
)
1544 && initializer_zerop (DECL_INITIAL (decl
))))
1546 unsigned HOST_WIDE_INT size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1547 unsigned HOST_WIDE_INT rounded
= size
;
1549 /* Don't allocate zero bytes of common,
1550 since that means "undefined external" in the linker. */
1554 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1555 so that each uninitialized object starts on such a boundary. */
1556 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1557 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1558 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1560 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1561 if ((unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
1562 warning (0, "requested alignment for %q+D is greater than "
1563 "implemented alignment of %wu", decl
, rounded
);
1566 /* If the target cannot output uninitialized but not common global data
1567 in .bss, then we have to use .data, so fall through. */
1568 if (asm_emit_uninitialised (decl
, name
, size
, rounded
))
1572 /* Handle initialized definitions.
1573 Also handle uninitialized global definitions if -fno-common and the
1574 target doesn't support ASM_OUTPUT_BSS. */
1576 /* First make the assembler name(s) global if appropriate. */
1577 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1578 globalize_decl (decl
);
1580 /* Output any data that we will need to use the address of. */
1581 if (DECL_INITIAL (decl
) == error_mark_node
)
1582 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1583 else if (DECL_INITIAL (decl
))
1585 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1586 output_addressed_constants (DECL_INITIAL (decl
));
1589 /* Switch to the appropriate section. */
1590 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1591 variable_section (decl
, reloc
);
1593 /* dbxout.c needs to know this. */
1594 if (in_section
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1595 DECL_IN_TEXT_SECTION (decl
) = 1;
1597 /* Output the alignment of this data. */
1598 if (align
> BITS_PER_UNIT
)
1599 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
1601 /* Do any machine/system dependent processing of the object. */
1602 #ifdef ASM_DECLARE_OBJECT_NAME
1603 last_assemble_variable_decl
= decl
;
1604 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1606 /* Standard thing is just output label for the object. */
1607 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1608 #endif /* ASM_DECLARE_OBJECT_NAME */
1610 if (!dont_output_data
)
1612 if (DECL_INITIAL (decl
)
1613 && DECL_INITIAL (decl
) != error_mark_node
1614 && !initializer_zerop (DECL_INITIAL (decl
)))
1615 /* Output the actual data. */
1616 output_constant (DECL_INITIAL (decl
),
1617 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1620 /* Leave space for it. */
1621 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1625 /* Return 1 if type TYPE contains any pointers. */
1628 contains_pointers_p (tree type
)
1630 switch (TREE_CODE (type
))
1633 case REFERENCE_TYPE
:
1634 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1635 so I'll play safe and return 1. */
1641 case QUAL_UNION_TYPE
:
1644 /* For a type that has fields, see if the fields have pointers. */
1645 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1646 if (TREE_CODE (fields
) == FIELD_DECL
1647 && contains_pointers_p (TREE_TYPE (fields
)))
1653 /* An array type contains pointers if its element type does. */
1654 return contains_pointers_p (TREE_TYPE (type
));
1661 /* In unit-at-a-time mode, we delay assemble_external processing until
1662 the compilation unit is finalized. This is the best we can do for
1663 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
1664 it all the way to final. See PR 17982 for further discussion. */
1665 static GTY(()) tree pending_assemble_externals
;
1667 #ifdef ASM_OUTPUT_EXTERNAL
1668 /* True if DECL is a function decl for which no out-of-line copy exists.
1669 It is assumed that DECL's assembler name has been set. */
1672 incorporeal_function_p (tree decl
)
1674 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
1678 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
1679 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
1682 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1683 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
1689 /* Actually do the tests to determine if this is necessary, and invoke
1690 ASM_OUTPUT_EXTERNAL. */
1692 assemble_external_real (tree decl
)
1694 rtx rtl
= DECL_RTL (decl
);
1696 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1697 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
1698 && !incorporeal_function_p (decl
))
1700 /* Some systems do require some output. */
1701 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1702 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1708 process_pending_assemble_externals (void)
1710 #ifdef ASM_OUTPUT_EXTERNAL
1712 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
1713 assemble_external_real (TREE_VALUE (list
));
1715 pending_assemble_externals
= 0;
1719 /* Output something to declare an external symbol to the assembler.
1720 (Most assemblers don't need this, so we normally output nothing.)
1721 Do nothing if DECL is not external. */
1724 assemble_external (tree decl ATTRIBUTE_UNUSED
)
1726 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1727 main body of this code is only rarely exercised. To provide some
1728 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1729 open. If it's not, we should not be calling this function. */
1730 gcc_assert (asm_out_file
);
1732 #ifdef ASM_OUTPUT_EXTERNAL
1733 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
1736 if (flag_unit_at_a_time
)
1737 pending_assemble_externals
= tree_cons (0, decl
,
1738 pending_assemble_externals
);
1740 assemble_external_real (decl
);
1744 /* Similar, for calling a library function FUN. */
1747 assemble_external_libcall (rtx fun
)
1749 /* Declare library function name external when first used, if nec. */
1750 if (! SYMBOL_REF_USED (fun
))
1752 SYMBOL_REF_USED (fun
) = 1;
1753 targetm
.asm_out
.external_libcall (fun
);
1757 /* Assemble a label named NAME. */
1760 assemble_label (const char *name
)
1762 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1765 /* Set the symbol_referenced flag for ID. */
1767 mark_referenced (tree id
)
1769 TREE_SYMBOL_REFERENCED (id
) = 1;
1772 /* Set the symbol_referenced flag for DECL and notify callgraph. */
1774 mark_decl_referenced (tree decl
)
1776 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1778 /* Extern inline functions don't become needed when referenced.
1779 If we know a method will be emitted in other TU and no new
1780 functions can be marked reachable, just use the external
1782 struct cgraph_node
*node
= cgraph_node (decl
);
1783 if (!DECL_EXTERNAL (decl
)
1784 && (!node
->local
.vtable_method
|| !cgraph_global_info_ready
1785 || !node
->local
.finalized
))
1786 cgraph_mark_needed_node (node
);
1788 else if (TREE_CODE (decl
) == VAR_DECL
)
1790 struct cgraph_varpool_node
*node
= cgraph_varpool_node (decl
);
1791 cgraph_varpool_mark_needed_node (node
);
1792 /* C++ frontend use mark_decl_references to force COMDAT variables
1793 to be output that might appear dead otherwise. */
1794 node
->force_output
= true;
1796 /* else do nothing - we can get various sorts of CST nodes here,
1797 which do not need to be marked. */
1801 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1802 until we find an identifier that is not itself a transparent alias.
1803 Modify the alias passed to it by reference (and all aliases on the
1804 way to the ultimate target), such that they do not have to be
1805 followed again, and return the ultimate target of the alias
1809 ultimate_transparent_alias_target (tree
*alias
)
1811 tree target
= *alias
;
1813 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
1815 gcc_assert (TREE_CHAIN (target
));
1816 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
1817 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
1818 && ! TREE_CHAIN (target
));
1825 /* Output to FILE (an assembly file) a reference to NAME. If NAME
1826 starts with a *, the rest of NAME is output verbatim. Otherwise
1827 NAME is transformed in a target-specific way (usually by the
1828 addition of an underscore). */
1831 assemble_name_raw (FILE *file
, const char *name
)
1834 fputs (&name
[1], file
);
1836 ASM_OUTPUT_LABELREF (file
, name
);
1839 /* Like assemble_name_raw, but should be used when NAME might refer to
1840 an entity that is also represented as a tree (like a function or
1841 variable). If NAME does refer to such an entity, that entity will
1842 be marked as referenced. */
1845 assemble_name (FILE *file
, const char *name
)
1847 const char *real_name
;
1850 real_name
= targetm
.strip_name_encoding (name
);
1852 id
= maybe_get_identifier (real_name
);
1857 mark_referenced (id
);
1858 ultimate_transparent_alias_target (&id
);
1860 name
= IDENTIFIER_POINTER (id
);
1861 gcc_assert (! TREE_CHAIN (id
));
1864 assemble_name_raw (file
, name
);
1867 /* Allocate SIZE bytes writable static space with a gensym name
1868 and return an RTX to refer to its address. */
1871 assemble_static_space (unsigned HOST_WIDE_INT size
)
1874 const char *namestring
;
1878 if (flag_shared_data
)
1879 switch_to_section (data_section
);
1882 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1884 namestring
= ggc_strdup (name
);
1886 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1887 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
1889 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1890 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1893 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1894 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1897 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1898 so that each uninitialized object starts on such a boundary. */
1899 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1900 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1901 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1902 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1903 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1904 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1911 /* Assemble the static constant template for function entry trampolines.
1912 This is done at most once per compilation.
1913 Returns an RTX for the address of the template. */
1915 static GTY(()) rtx initial_trampoline
;
1917 #ifdef TRAMPOLINE_TEMPLATE
1919 assemble_trampoline_template (void)
1926 if (initial_trampoline
)
1927 return initial_trampoline
;
1929 /* By default, put trampoline templates in read-only data section. */
1931 #ifdef TRAMPOLINE_SECTION
1932 switch_to_section (TRAMPOLINE_SECTION
);
1934 switch_to_section (readonly_data_section
);
1937 /* Write the assembler code to define one. */
1938 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1941 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1944 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
1945 TRAMPOLINE_TEMPLATE (asm_out_file
);
1947 /* Record the rtl to refer to it. */
1948 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1949 name
= ggc_strdup (label
);
1950 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
1951 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
1953 initial_trampoline
= gen_rtx_MEM (BLKmode
, symbol
);
1954 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
1956 return initial_trampoline
;
1960 /* A and B are either alignments or offsets. Return the minimum alignment
1961 that may be assumed after adding the two together. */
1963 static inline unsigned
1964 min_align (unsigned int a
, unsigned int b
)
1966 return (a
| b
) & -(a
| b
);
1969 /* Return the assembler directive for creating a given kind of integer
1970 object. SIZE is the number of bytes in the object and ALIGNED_P
1971 indicates whether it is known to be aligned. Return NULL if the
1972 assembly dialect has no such directive.
1974 The returned string should be printed at the start of a new line and
1975 be followed immediately by the object's initial value. */
1978 integer_asm_op (int size
, int aligned_p
)
1980 struct asm_int_op
*ops
;
1983 ops
= &targetm
.asm_out
.aligned_op
;
1985 ops
= &targetm
.asm_out
.unaligned_op
;
1990 return targetm
.asm_out
.byte_op
;
2004 /* Use directive OP to assemble an integer object X. Print OP at the
2005 start of the line, followed immediately by the value of X. */
2008 assemble_integer_with_op (const char *op
, rtx x
)
2010 fputs (op
, asm_out_file
);
2011 output_addr_const (asm_out_file
, x
);
2012 fputc ('\n', asm_out_file
);
2015 /* The default implementation of the asm_out.integer target hook. */
2018 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2019 unsigned int size ATTRIBUTE_UNUSED
,
2020 int aligned_p ATTRIBUTE_UNUSED
)
2022 const char *op
= integer_asm_op (size
, aligned_p
);
2023 /* Avoid GAS bugs for large values. Specifically negative values whose
2024 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2025 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2027 return op
&& (assemble_integer_with_op (op
, x
), true);
2030 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2031 the alignment of the integer in bits. Return 1 if we were able to output
2032 the constant, otherwise 0. We must be able to output the constant,
2033 if FORCE is nonzero. */
2036 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2040 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2042 /* See if the target hook can handle this kind of object. */
2043 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2046 /* If the object is a multi-byte one, try splitting it up. Split
2047 it into words it if is multi-word, otherwise split it into bytes. */
2050 enum machine_mode omode
, imode
;
2051 unsigned int subalign
;
2052 unsigned int subsize
, i
;
2054 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2055 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2056 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, MODE_INT
, 0);
2057 imode
= mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
2059 for (i
= 0; i
< size
; i
+= subsize
)
2061 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2062 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2068 /* If we've printed some of it, but not all of it, there's no going
2073 gcc_assert (!force
);
2079 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2083 int bitsize
, nelts
, nunits
, units_per
;
2085 /* This is hairy. We have a quantity of known size. real_to_target
2086 will put it into an array of *host* longs, 32 bits per element
2087 (even if long is more than 32 bits). We need to determine the
2088 number of array elements that are occupied (nelts) and the number
2089 of *target* min-addressable units that will be occupied in the
2090 object file (nunits). We cannot assume that 32 divides the
2091 mode's bitsize (size * BITS_PER_UNIT) evenly.
2093 size * BITS_PER_UNIT is used here to make sure that padding bits
2094 (which might appear at either end of the value; real_to_target
2095 will include the padding bits in its output array) are included. */
2097 nunits
= GET_MODE_SIZE (mode
);
2098 bitsize
= nunits
* BITS_PER_UNIT
;
2099 nelts
= CEIL (bitsize
, 32);
2100 units_per
= 32 / BITS_PER_UNIT
;
2102 real_to_target (data
, &d
, mode
);
2104 /* Put out the first word with the specified alignment. */
2105 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2106 nunits
-= units_per
;
2108 /* Subsequent words need only 32-bit alignment. */
2109 align
= min_align (align
, 32);
2111 for (i
= 1; i
< nelts
; i
++)
2113 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2114 nunits
-= units_per
;
2118 /* Given an expression EXP with a constant value,
2119 reduce it to the sum of an assembler symbol and an integer.
2120 Store them both in the structure *VALUE.
2121 EXP must be reducible. */
2123 struct addr_const
GTY(())
2126 HOST_WIDE_INT offset
;
2130 decode_addr_const (tree exp
, struct addr_const
*value
)
2132 tree target
= TREE_OPERAND (exp
, 0);
2138 if (TREE_CODE (target
) == COMPONENT_REF
2139 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2142 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2143 target
= TREE_OPERAND (target
, 0);
2145 else if (TREE_CODE (target
) == ARRAY_REF
2146 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2148 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2149 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2150 target
= TREE_OPERAND (target
, 0);
2156 switch (TREE_CODE (target
))
2160 x
= DECL_RTL (target
);
2164 x
= gen_rtx_MEM (FUNCTION_MODE
,
2165 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2173 x
= output_constant_def (target
, 1);
2180 gcc_assert (MEM_P (x
));
2184 value
->offset
= offset
;
2187 /* Uniquize all constants that appear in memory.
2188 Each constant in memory thus far output is recorded
2189 in `const_desc_table'. */
2191 struct constant_descriptor_tree
GTY(())
2193 /* A MEM for the constant. */
2196 /* The value of the constant. */
2199 /* Hash of value. Computing the hash from value each time
2200 hashfn is called can't work properly, as that means recursive
2201 use of the hash table during hash table expansion. */
2205 static GTY((param_is (struct constant_descriptor_tree
)))
2206 htab_t const_desc_htab
;
2208 static struct constant_descriptor_tree
* build_constant_desc (tree
);
2209 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2211 /* Compute a hash code for a constant expression. */
2214 const_desc_hash (const void *ptr
)
2216 return ((struct constant_descriptor_tree
*)ptr
)->hash
;
2220 const_hash_1 (const tree exp
)
2225 enum tree_code code
= TREE_CODE (exp
);
2227 /* Either set P and LEN to the address and len of something to hash and
2228 exit the switch or return a value. */
2233 p
= (char *) &TREE_INT_CST (exp
);
2234 len
= sizeof TREE_INT_CST (exp
);
2238 return real_hash (TREE_REAL_CST_PTR (exp
));
2241 p
= TREE_STRING_POINTER (exp
);
2242 len
= TREE_STRING_LENGTH (exp
);
2246 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2247 + const_hash_1 (TREE_IMAGPART (exp
)));
2251 unsigned HOST_WIDE_INT idx
;
2254 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2256 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2258 hi
= hi
* 603 + const_hash_1 (value
);
2266 struct addr_const value
;
2268 decode_addr_const (exp
, &value
);
2269 switch (GET_CODE (value
.base
))
2272 /* Don't hash the address of the SYMBOL_REF;
2273 only use the offset and the symbol name. */
2275 p
= XSTR (value
.base
, 0);
2276 for (i
= 0; p
[i
] != 0; i
++)
2277 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2281 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2292 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2293 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2297 case NON_LVALUE_EXPR
:
2298 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2301 /* A language specific constant. Just hash the code. */
2305 /* Compute hashing function. */
2307 for (i
= 0; i
< len
; i
++)
2308 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2313 /* Wrapper of compare_constant, for the htab interface. */
2315 const_desc_eq (const void *p1
, const void *p2
)
2317 const struct constant_descriptor_tree
*c1
= p1
;
2318 const struct constant_descriptor_tree
*c2
= p2
;
2319 if (c1
->hash
!= c2
->hash
)
2321 return compare_constant (c1
->value
, c2
->value
);
2324 /* Compare t1 and t2, and return 1 only if they are known to result in
2325 the same bit pattern on output. */
2328 compare_constant (const tree t1
, const tree t2
)
2330 enum tree_code typecode
;
2332 if (t1
== NULL_TREE
)
2333 return t2
== NULL_TREE
;
2334 if (t2
== NULL_TREE
)
2337 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2340 switch (TREE_CODE (t1
))
2343 /* Integer constants are the same only if the same width of type. */
2344 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2346 return tree_int_cst_equal (t1
, t2
);
2349 /* Real constants are the same only if the same width of type. */
2350 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2353 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2356 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2359 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2360 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2361 TREE_STRING_LENGTH (t1
)));
2364 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2365 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2369 VEC(constructor_elt
, gc
) *v1
, *v2
;
2370 unsigned HOST_WIDE_INT idx
;
2372 typecode
= TREE_CODE (TREE_TYPE (t1
));
2373 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
2376 if (typecode
== ARRAY_TYPE
)
2378 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
2379 /* For arrays, check that the sizes all match. */
2380 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
2382 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
2387 /* For record and union constructors, require exact type
2389 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
2393 v1
= CONSTRUCTOR_ELTS (t1
);
2394 v2
= CONSTRUCTOR_ELTS (t2
);
2395 if (VEC_length (constructor_elt
, v1
)
2396 != VEC_length (constructor_elt
, v2
))
2399 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
2401 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
2402 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
2404 /* Check that each value is the same... */
2405 if (!compare_constant (c1
->value
, c2
->value
))
2407 /* ... and that they apply to the same fields! */
2408 if (typecode
== ARRAY_TYPE
)
2410 if (!compare_constant (c1
->index
, c2
->index
))
2415 if (c1
->index
!= c2
->index
)
2426 struct addr_const value1
, value2
;
2428 decode_addr_const (t1
, &value1
);
2429 decode_addr_const (t2
, &value2
);
2430 return (value1
.offset
== value2
.offset
2431 && strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
2437 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2438 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2442 case NON_LVALUE_EXPR
:
2443 case VIEW_CONVERT_EXPR
:
2444 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2449 nt1
= lang_hooks
.expand_constant (t1
);
2450 nt2
= lang_hooks
.expand_constant (t2
);
2451 if (nt1
!= t1
|| nt2
!= t2
)
2452 return compare_constant (nt1
, nt2
);
2461 /* Make a copy of the whole tree structure for a constant. This
2462 handles the same types of nodes that compare_constant handles. */
2465 copy_constant (tree exp
)
2467 switch (TREE_CODE (exp
))
2470 /* For ADDR_EXPR, we do not want to copy the decl whose address
2471 is requested. We do want to copy constants though. */
2472 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
2473 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2474 copy_constant (TREE_OPERAND (exp
, 0)));
2476 return copy_node (exp
);
2481 return copy_node (exp
);
2484 return build_complex (TREE_TYPE (exp
),
2485 copy_constant (TREE_REALPART (exp
)),
2486 copy_constant (TREE_IMAGPART (exp
)));
2490 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
2491 copy_constant (TREE_OPERAND (exp
, 0)),
2492 copy_constant (TREE_OPERAND (exp
, 1)));
2496 case NON_LVALUE_EXPR
:
2497 case VIEW_CONVERT_EXPR
:
2498 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2499 copy_constant (TREE_OPERAND (exp
, 0)));
2503 tree copy
= copy_node (exp
);
2504 VEC(constructor_elt
, gc
) *v
;
2505 unsigned HOST_WIDE_INT idx
;
2506 tree purpose
, value
;
2508 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
2509 CONSTRUCTOR_ELTS (exp
)));
2510 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
2512 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
2513 ce
->index
= purpose
;
2514 ce
->value
= copy_constant (value
);
2516 CONSTRUCTOR_ELTS (copy
) = v
;
2522 tree t
= lang_hooks
.expand_constant (exp
);
2524 gcc_assert (t
== exp
);
2525 return copy_constant (t
);
2530 /* Subroutine of output_constant_def:
2531 No constant equal to EXP is known to have been output.
2532 Make a constant descriptor to enter EXP in the hash table.
2533 Assign the label number and construct RTL to refer to the
2534 constant's location in memory.
2535 Caller is responsible for updating the hash table. */
2537 static struct constant_descriptor_tree
*
2538 build_constant_desc (tree exp
)
2544 struct constant_descriptor_tree
*desc
;
2546 desc
= ggc_alloc (sizeof (*desc
));
2547 desc
->value
= copy_constant (exp
);
2549 /* Propagate marked-ness to copied constant. */
2550 if (flag_mudflap
&& mf_marked_p (exp
))
2551 mf_mark (desc
->value
);
2553 /* Create a string containing the label name, in LABEL. */
2554 labelno
= const_labelno
++;
2555 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
2557 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2558 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
2559 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2560 SYMBOL_REF_DECL (symbol
) = desc
->value
;
2561 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
2563 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
2564 set_mem_attributes (rtl
, exp
, 1);
2565 set_mem_alias_set (rtl
, 0);
2566 set_mem_alias_set (rtl
, const_alias_set
);
2568 /* Set flags or add text to the name to record information, such as
2569 that it is a local symbol. If the name is changed, the macro
2570 ASM_OUTPUT_LABELREF will have to know how to strip this
2571 information. This call might invalidate our local variable
2572 SYMBOL; we can't use it afterward. */
2574 targetm
.encode_section_info (exp
, rtl
, true);
2581 /* Return an rtx representing a reference to constant data in memory
2582 for the constant expression EXP.
2584 If assembler code for such a constant has already been output,
2585 return an rtx to refer to it.
2586 Otherwise, output such a constant in memory
2587 and generate an rtx for it.
2589 If DEFER is nonzero, this constant can be deferred and output only
2590 if referenced in the function after all optimizations.
2592 `const_desc_table' records which constants already have label strings. */
2595 output_constant_def (tree exp
, int defer
)
2597 struct constant_descriptor_tree
*desc
;
2598 struct constant_descriptor_tree key
;
2601 /* Look up EXP in the table of constant descriptors. If we didn't find
2602 it, create a new one. */
2604 key
.hash
= const_hash_1 (exp
);
2605 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
2610 desc
= build_constant_desc (exp
);
2611 desc
->hash
= key
.hash
;
2615 maybe_output_constant_def_contents (desc
, defer
);
2619 /* Subroutine of output_constant_def: Decide whether or not we need to
2620 output the constant DESC now, and if so, do it. */
2622 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
2625 rtx symbol
= XEXP (desc
->rtl
, 0);
2626 tree exp
= desc
->value
;
2628 if (flag_syntax_only
)
2631 if (TREE_ASM_WRITTEN (exp
))
2632 /* Already output; don't do it again. */
2635 /* We can always defer constants as long as the context allows
2639 /* Increment n_deferred_constants if it exists. It needs to be at
2640 least as large as the number of constants actually referred to
2641 by the function. If it's too small we'll stop looking too early
2642 and fail to emit constants; if it's too large we'll only look
2643 through the entire function when we could have stopped earlier. */
2645 n_deferred_constants
++;
2649 output_constant_def_contents (symbol
);
2652 /* We must output the constant data referred to by SYMBOL; do so. */
2655 output_constant_def_contents (rtx symbol
)
2657 tree exp
= SYMBOL_REF_DECL (symbol
);
2658 const char *label
= XSTR (symbol
, 0);
2661 /* Make sure any other constants whose addresses appear in EXP
2662 are assigned label numbers. */
2663 int reloc
= compute_reloc_for_constant (exp
);
2665 /* Align the location counter as required by EXP's data type. */
2666 unsigned int align
= TYPE_ALIGN (TREE_TYPE (exp
));
2667 #ifdef CONSTANT_ALIGNMENT
2668 align
= CONSTANT_ALIGNMENT (exp
, align
);
2671 output_addressed_constants (exp
);
2673 /* We are no longer deferring this constant. */
2674 TREE_ASM_WRITTEN (exp
) = 1;
2676 if (IN_NAMED_SECTION (exp
))
2677 switch_to_section (get_named_section (exp
, NULL
, reloc
));
2679 switch_to_section (targetm
.asm_out
.select_section (exp
, reloc
, align
));
2681 if (align
> BITS_PER_UNIT
)
2683 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2686 size
= int_size_in_bytes (TREE_TYPE (exp
));
2687 if (TREE_CODE (exp
) == STRING_CST
)
2688 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
2690 /* Do any machine/system dependent processing of the constant. */
2691 #ifdef ASM_DECLARE_CONSTANT_NAME
2692 ASM_DECLARE_CONSTANT_NAME (asm_out_file
, label
, exp
, size
);
2694 /* Standard thing is just output label for the constant. */
2695 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2696 #endif /* ASM_DECLARE_CONSTANT_NAME */
2698 /* Output the value of EXP. */
2699 output_constant (exp
, size
, align
);
2701 mudflap_enqueue_constant (exp
);
2704 /* Look up EXP in the table of constant descriptors. Return the rtl
2705 if it has been emitted, else null. */
2708 lookup_constant_def (tree exp
)
2710 struct constant_descriptor_tree
*desc
;
2711 struct constant_descriptor_tree key
;
2714 key
.hash
= const_hash_1 (exp
);
2715 desc
= htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
2717 return (desc
? desc
->rtl
: NULL_RTX
);
2720 /* Used in the hash tables to avoid outputting the same constant
2721 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2722 are output once per function, not once per file. */
2723 /* ??? Only a few targets need per-function constant pools. Most
2724 can use one per-file pool. Should add a targetm bit to tell the
2727 struct rtx_constant_pool
GTY(())
2729 /* Pointers to first and last constant in pool, as ordered by offset. */
2730 struct constant_descriptor_rtx
*first
;
2731 struct constant_descriptor_rtx
*last
;
2733 /* Hash facility for making memory-constants from constant rtl-expressions.
2734 It is used on RISC machines where immediate integer arguments and
2735 constant addresses are restricted so that such constants must be stored
2737 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
2738 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_sym_htab
;
2740 /* Current offset in constant pool (does not include any
2741 machine-specific header). */
2742 HOST_WIDE_INT offset
;
2745 struct constant_descriptor_rtx
GTY((chain_next ("%h.next")))
2747 struct constant_descriptor_rtx
*next
;
2751 HOST_WIDE_INT offset
;
2753 enum machine_mode mode
;
2759 /* Hash and compare functions for const_rtx_htab. */
2762 const_desc_rtx_hash (const void *ptr
)
2764 const struct constant_descriptor_rtx
*desc
= ptr
;
2769 const_desc_rtx_eq (const void *a
, const void *b
)
2771 const struct constant_descriptor_rtx
*x
= a
;
2772 const struct constant_descriptor_rtx
*y
= b
;
2774 if (x
->mode
!= y
->mode
)
2776 return rtx_equal_p (x
->constant
, y
->constant
);
2779 /* Hash and compare functions for const_rtx_sym_htab. */
2782 const_desc_rtx_sym_hash (const void *ptr
)
2784 const struct constant_descriptor_rtx
*desc
= ptr
;
2785 return htab_hash_string (XSTR (desc
->sym
, 0));
2789 const_desc_rtx_sym_eq (const void *a
, const void *b
)
2791 const struct constant_descriptor_rtx
*x
= a
;
2792 const struct constant_descriptor_rtx
*y
= b
;
2793 return XSTR (x
->sym
, 0) == XSTR (y
->sym
, 0);
2796 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
2799 const_rtx_hash_1 (rtx
*xp
, void *data
)
2801 unsigned HOST_WIDE_INT hwi
;
2802 enum machine_mode mode
;
2808 code
= GET_CODE (x
);
2809 mode
= GET_MODE (x
);
2810 h
= (hashval_t
) code
* 1048573 + mode
;
2818 const int shift
= sizeof (hashval_t
) * CHAR_BIT
;
2819 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
2822 h
^= (hashval_t
) hwi
;
2823 for (i
= 1; i
< n
; ++i
)
2826 h
^= (hashval_t
) hwi
;
2832 if (mode
== VOIDmode
)
2834 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
2838 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
2844 for (i
= XVECLEN (x
, 0); i
-- > 0; )
2845 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
2850 h
^= htab_hash_string (XSTR (x
, 0));
2854 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
2858 case UNSPEC_VOLATILE
:
2859 h
= h
* 251 + XINT (x
, 1);
2867 *hp
= *hp
* 509 + h
;
2871 /* Compute a hash value for X, which should be a constant. */
2874 const_rtx_hash (rtx x
)
2877 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
2882 /* Initialize constant pool hashing for a new function. */
2885 init_varasm_status (struct function
*f
)
2887 struct varasm_status
*p
;
2888 struct rtx_constant_pool
*pool
;
2890 p
= ggc_alloc (sizeof (struct varasm_status
));
2893 pool
= ggc_alloc (sizeof (struct rtx_constant_pool
));
2895 p
->deferred_constants
= 0;
2897 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
2898 const_desc_rtx_eq
, NULL
);
2899 pool
->const_rtx_sym_htab
= htab_create_ggc (31, const_desc_rtx_sym_hash
,
2900 const_desc_rtx_sym_eq
, NULL
);
2901 pool
->first
= pool
->last
= NULL
;
2905 /* Given a MINUS expression, simplify it if both sides
2906 include the same symbol. */
2909 simplify_subtraction (rtx x
)
2911 rtx r
= simplify_rtx (x
);
2915 /* Given a constant rtx X, make (or find) a memory constant for its value
2916 and return a MEM rtx to refer to it in memory. */
2919 force_const_mem (enum machine_mode mode
, rtx x
)
2921 struct constant_descriptor_rtx
*desc
, tmp
;
2922 struct rtx_constant_pool
*pool
= cfun
->varasm
->pool
;
2929 /* If we're not allowed to drop X into the constant pool, don't. */
2930 if (targetm
.cannot_force_const_mem (x
))
2933 /* Lookup the value in the hashtable. */
2936 hash
= const_rtx_hash (x
);
2937 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
2940 /* If the constant was already present, return its memory. */
2942 return copy_rtx (desc
->mem
);
2944 /* Otherwise, create a new descriptor. */
2945 desc
= ggc_alloc (sizeof (*desc
));
2948 /* Align the location counter as required by EXP's data type. */
2949 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
2950 #ifdef CONSTANT_ALIGNMENT
2952 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
2953 if (type
!= NULL_TREE
)
2954 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
2958 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
2959 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
2962 desc
->constant
= tmp
.constant
;
2963 desc
->offset
= pool
->offset
;
2966 desc
->align
= align
;
2967 desc
->labelno
= const_labelno
;
2970 pool
->offset
+= GET_MODE_SIZE (mode
);
2972 pool
->last
->next
= desc
;
2974 pool
->first
= pool
->last
= desc
;
2977 /* Create a string containing the label name, in LABEL. */
2978 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2981 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
2982 the constants pool. */
2983 desc
->sym
= symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
2984 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2985 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
2986 current_function_uses_const_pool
= 1;
2988 /* Insert the descriptor into the symbol cross-reference table too. */
2989 slot
= htab_find_slot (pool
->const_rtx_sym_htab
, desc
, INSERT
);
2990 gcc_assert (!*slot
);
2993 /* Construct the MEM. */
2994 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
2995 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
2996 set_mem_align (def
, align
);
2998 /* If we're dropping a label to the constant pool, make sure we
3000 if (GET_CODE (x
) == LABEL_REF
)
3001 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3003 return copy_rtx (def
);
3006 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3007 the corresponding constant_descriptor_rtx structure. */
3009 static struct constant_descriptor_rtx
*
3010 find_pool_constant (struct rtx_constant_pool
*pool
, rtx sym
)
3012 struct constant_descriptor_rtx tmp
;
3014 return htab_find (pool
->const_rtx_sym_htab
, &tmp
);
3017 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3020 get_pool_constant (rtx addr
)
3022 return find_pool_constant (cfun
->varasm
->pool
, addr
)->constant
;
3025 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3026 and whether it has been output or not. */
3029 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3031 struct constant_descriptor_rtx
*desc
;
3033 desc
= find_pool_constant (cfun
->varasm
->pool
, addr
);
3034 *pmarked
= (desc
->mark
!= 0);
3035 return desc
->constant
;
3038 /* Likewise, but for the constant pool of a specific function. */
3041 get_pool_constant_for_function (struct function
*f
, rtx addr
)
3043 return find_pool_constant (f
->varasm
->pool
, addr
)->constant
;
3046 /* Similar, return the mode. */
3049 get_pool_mode (rtx addr
)
3051 return find_pool_constant (cfun
->varasm
->pool
, addr
)->mode
;
3054 /* Return the size of the constant pool. */
3057 get_pool_size (void)
3059 return cfun
->varasm
->pool
->offset
;
3062 /* Worker function for output_constant_pool_1. Emit assembly for X
3063 in MODE with known alignment ALIGN. */
3066 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3068 switch (GET_MODE_CLASS (mode
))
3074 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3075 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3076 assemble_real (r
, mode
, align
);
3081 case MODE_PARTIAL_INT
:
3082 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3085 case MODE_VECTOR_FLOAT
:
3086 case MODE_VECTOR_INT
:
3089 enum machine_mode submode
= GET_MODE_INNER (mode
);
3090 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3092 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3093 units
= CONST_VECTOR_NUNITS (x
);
3095 for (i
= 0; i
< units
; i
++)
3097 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3098 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3108 /* Worker function for output_constant_pool. Emit POOL. */
3111 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
)
3119 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3120 whose CODE_LABEL has been deleted. This can occur if a jump table
3121 is eliminated by optimization. If so, write a constant of zero
3122 instead. Note that this can also happen by turning the
3123 CODE_LABEL into a NOTE. */
3124 /* ??? This seems completely and utterly wrong. Certainly it's
3125 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3126 functioning even with INSN_DELETED_P and friends. */
3129 switch (GET_CODE (x
))
3132 if (GET_CODE (XEXP (x
, 0)) != PLUS
3133 || GET_CODE (XEXP (XEXP (x
, 0), 0)) != LABEL_REF
)
3135 tmp
= XEXP (XEXP (x
, 0), 0);
3140 gcc_assert (!INSN_DELETED_P (tmp
));
3141 gcc_assert (!NOTE_P (tmp
)
3142 || NOTE_LINE_NUMBER (tmp
) != NOTE_INSN_DELETED
);
3149 /* First switch to correct section. */
3150 switch_to_section (targetm
.asm_out
.select_rtx_section (desc
->mode
, x
,
3153 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3154 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3155 desc
->align
, desc
->labelno
, done
);
3158 assemble_align (desc
->align
);
3160 /* Output the label. */
3161 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3163 /* Output the data. */
3164 output_constant_pool_2 (desc
->mode
, x
, desc
->align
);
3166 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3167 sections have proper size. */
3168 if (desc
->align
> GET_MODE_BITSIZE (desc
->mode
)
3170 && (in_section
->common
.flags
& SECTION_MERGE
))
3171 assemble_align (desc
->align
);
3173 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3179 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3180 to as used. Emit referenced deferred strings. This function can
3181 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3184 mark_constant (rtx
*current_rtx
, void *data
)
3186 struct rtx_constant_pool
*pool
= data
;
3187 rtx x
= *current_rtx
;
3189 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3192 if (CONSTANT_POOL_ADDRESS_P (x
))
3194 struct constant_descriptor_rtx
*desc
= find_pool_constant (pool
, x
);
3195 if (desc
->mark
== 0)
3198 for_each_rtx (&desc
->constant
, mark_constant
, pool
);
3201 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3203 tree exp
= SYMBOL_REF_DECL (x
);
3204 if (!TREE_ASM_WRITTEN (exp
))
3206 n_deferred_constants
--;
3207 output_constant_def_contents (x
);
3214 /* Look through appropriate parts of INSN, marking all entries in the
3215 constant pool which are actually being used. Entries that are only
3216 referenced by other constants are also marked as used. Emit
3217 deferred strings that are used. */
3220 mark_constants (struct rtx_constant_pool
*pool
, rtx insn
)
3225 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3226 insns, not any notes that may be attached. We don't want to mark
3227 a constant just because it happens to appear in a REG_EQUIV note. */
3228 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3230 rtx seq
= PATTERN (insn
);
3231 int i
, n
= XVECLEN (seq
, 0);
3232 for (i
= 0; i
< n
; ++i
)
3234 rtx subinsn
= XVECEXP (seq
, 0, i
);
3235 if (INSN_P (subinsn
))
3236 for_each_rtx (&PATTERN (subinsn
), mark_constant
, pool
);
3240 for_each_rtx (&PATTERN (insn
), mark_constant
, pool
);
3243 /* Look through the instructions for this function, and mark all the
3244 entries in POOL which are actually being used. Emit deferred constants
3245 which have indeed been used. */
3248 mark_constant_pool (struct rtx_constant_pool
*pool
)
3252 if (pool
->first
== 0 && n_deferred_constants
== 0)
3255 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3256 mark_constants (pool
, insn
);
3258 for (link
= current_function_epilogue_delay_list
;
3260 link
= XEXP (link
, 1))
3261 mark_constants (pool
, XEXP (link
, 0));
3264 /* Write all the constants in the constant pool. */
3267 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3268 tree fndecl ATTRIBUTE_UNUSED
)
3270 struct rtx_constant_pool
*pool
= cfun
->varasm
->pool
;
3271 struct constant_descriptor_rtx
*desc
;
3273 /* It is possible for gcc to call force_const_mem and then to later
3274 discard the instructions which refer to the constant. In such a
3275 case we do not need to output the constant. */
3276 mark_constant_pool (pool
);
3278 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3279 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3282 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3283 output_constant_pool_1 (desc
);
3285 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3286 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3290 /* Determine what kind of relocations EXP may need. */
3293 compute_reloc_for_constant (tree exp
)
3295 int reloc
= 0, reloc2
;
3298 /* Give the front-end a chance to convert VALUE to something that
3299 looks more like a constant to the back-end. */
3300 exp
= lang_hooks
.expand_constant (exp
);
3302 switch (TREE_CODE (exp
))
3306 /* Go inside any operations that get_inner_reference can handle and see
3307 if what's inside is a constant: no need to do anything here for
3308 addresses of variables or functions. */
3309 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3310 tem
= TREE_OPERAND (tem
, 0))
3313 if (TREE_PUBLIC (tem
))
3320 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3321 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3325 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3326 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3327 /* The difference of two local labels is computable at link time. */
3328 if (reloc
== 1 && reloc2
== 1)
3336 case NON_LVALUE_EXPR
:
3337 case VIEW_CONVERT_EXPR
:
3338 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3343 unsigned HOST_WIDE_INT idx
;
3344 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3346 reloc
|= compute_reloc_for_constant (tem
);
3356 /* Find all the constants whose addresses are referenced inside of EXP,
3357 and make sure assembler code with a label has been output for each one.
3358 Indicate whether an ADDR_EXPR has been encountered. */
3361 output_addressed_constants (tree exp
)
3365 /* Give the front-end a chance to convert VALUE to something that
3366 looks more like a constant to the back-end. */
3367 exp
= lang_hooks
.expand_constant (exp
);
3369 switch (TREE_CODE (exp
))
3373 /* Go inside any operations that get_inner_reference can handle and see
3374 if what's inside is a constant: no need to do anything here for
3375 addresses of variables or functions. */
3376 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3377 tem
= TREE_OPERAND (tem
, 0))
3380 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3381 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
3382 tem
= DECL_INITIAL (tem
);
3384 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
3385 output_constant_def (tem
, 0);
3390 output_addressed_constants (TREE_OPERAND (exp
, 1));
3395 case NON_LVALUE_EXPR
:
3396 case VIEW_CONVERT_EXPR
:
3397 output_addressed_constants (TREE_OPERAND (exp
, 0));
3402 unsigned HOST_WIDE_INT idx
;
3403 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3405 output_addressed_constants (tem
);
3414 /* Return nonzero if VALUE is a valid constant-valued expression
3415 for use in initializing a static variable; one that can be an
3416 element of a "constant" initializer.
3418 Return null_pointer_node if the value is absolute;
3419 if it is relocatable, return the variable that determines the relocation.
3420 We assume that VALUE has been folded as much as possible;
3421 therefore, we do not need to check for such things as
3422 arithmetic-combinations of integers. */
3425 initializer_constant_valid_p (tree value
, tree endtype
)
3427 /* Give the front-end a chance to convert VALUE to something that
3428 looks more like a constant to the back-end. */
3429 value
= lang_hooks
.expand_constant (value
);
3431 switch (TREE_CODE (value
))
3434 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
3435 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
3436 && TREE_CONSTANT (value
)
3437 && !VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (value
)))
3439 unsigned HOST_WIDE_INT idx
;
3441 bool absolute
= true;
3443 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
3446 reloc
= initializer_constant_valid_p (elt
, TREE_TYPE (elt
));
3449 if (reloc
!= null_pointer_node
)
3452 /* For a non-absolute relocation, there is no single
3453 variable that can be "the variable that determines the
3455 return absolute
? null_pointer_node
: error_mark_node
;
3458 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
3465 return null_pointer_node
;
3469 value
= staticp (TREE_OPERAND (value
, 0));
3470 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to
3471 be a constant, this is old-skool offsetof-like nonsense. */
3473 && TREE_CODE (value
) == INDIRECT_REF
3474 && TREE_CONSTANT (TREE_OPERAND (value
, 0)))
3475 return null_pointer_node
;
3476 /* Taking the address of a nested function involves a trampoline. */
3478 && TREE_CODE (value
) == FUNCTION_DECL
3479 && ((decl_function_context (value
) && !DECL_NO_STATIC_CHAIN (value
))
3480 || DECL_DLLIMPORT_P (value
)))
3484 case VIEW_CONVERT_EXPR
:
3485 case NON_LVALUE_EXPR
:
3486 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3495 src
= TREE_OPERAND (value
, 0);
3496 src_type
= TREE_TYPE (src
);
3497 dest_type
= TREE_TYPE (value
);
3499 /* Allow conversions between pointer types, floating-point
3500 types, and offset types. */
3501 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
3502 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
3503 || (TREE_CODE (dest_type
) == OFFSET_TYPE
3504 && TREE_CODE (src_type
) == OFFSET_TYPE
))
3505 return initializer_constant_valid_p (src
, endtype
);
3507 /* Allow length-preserving conversions between integer types. */
3508 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
3509 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
3510 return initializer_constant_valid_p (src
, endtype
);
3512 /* Allow conversions between other integer types only if
3514 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
3516 tree inner
= initializer_constant_valid_p (src
, endtype
);
3517 if (inner
== null_pointer_node
)
3518 return null_pointer_node
;
3522 /* Allow (int) &foo provided int is as wide as a pointer. */
3523 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
3524 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
3525 return initializer_constant_valid_p (src
, endtype
);
3527 /* Likewise conversions from int to pointers, but also allow
3528 conversions from 0. */
3529 if ((POINTER_TYPE_P (dest_type
)
3530 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
3531 && INTEGRAL_TYPE_P (src_type
))
3533 if (integer_zerop (src
))
3534 return null_pointer_node
;
3535 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
3536 return initializer_constant_valid_p (src
, endtype
);
3539 /* Allow conversions to struct or union types if the value
3541 if (TREE_CODE (dest_type
) == RECORD_TYPE
3542 || TREE_CODE (dest_type
) == UNION_TYPE
)
3543 return initializer_constant_valid_p (src
, endtype
);
3548 if (! INTEGRAL_TYPE_P (endtype
)
3549 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
3551 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3553 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
3555 /* If either term is absolute, use the other terms relocation. */
3556 if (valid0
== null_pointer_node
)
3558 if (valid1
== null_pointer_node
)
3564 if (! INTEGRAL_TYPE_P (endtype
)
3565 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
3567 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3569 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
3571 /* Win if second argument is absolute. */
3572 if (valid1
== null_pointer_node
)
3574 /* Win if both arguments have the same relocation.
3575 Then the value is absolute. */
3576 if (valid0
== valid1
&& valid0
!= 0)
3577 return null_pointer_node
;
3579 /* Since GCC guarantees that string constants are unique in the
3580 generated code, a subtraction between two copies of the same
3581 constant string is absolute. */
3582 if (valid0
&& TREE_CODE (valid0
) == STRING_CST
3583 && valid1
&& TREE_CODE (valid1
) == STRING_CST
3584 && operand_equal_p (valid0
, valid1
, 1))
3585 return null_pointer_node
;
3588 /* Support narrowing differences. */
3589 if (INTEGRAL_TYPE_P (endtype
))
3593 op0
= TREE_OPERAND (value
, 0);
3594 op1
= TREE_OPERAND (value
, 1);
3596 /* Like STRIP_NOPS except allow the operand mode to widen.
3597 This works around a feature of fold that simplifies
3598 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3599 that the narrower operation is cheaper. */
3601 while (TREE_CODE (op0
) == NOP_EXPR
3602 || TREE_CODE (op0
) == CONVERT_EXPR
3603 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
3605 tree inner
= TREE_OPERAND (op0
, 0);
3606 if (inner
== error_mark_node
3607 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3608 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
3609 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3614 while (TREE_CODE (op1
) == NOP_EXPR
3615 || TREE_CODE (op1
) == CONVERT_EXPR
3616 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
3618 tree inner
= TREE_OPERAND (op1
, 0);
3619 if (inner
== error_mark_node
3620 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3621 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
3622 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3627 op0
= initializer_constant_valid_p (op0
, endtype
);
3628 op1
= initializer_constant_valid_p (op1
, endtype
);
3630 /* Both initializers must be known. */
3634 return null_pointer_node
;
3636 /* Support differences between labels. */
3637 if (TREE_CODE (op0
) == LABEL_DECL
3638 && TREE_CODE (op1
) == LABEL_DECL
)
3639 return null_pointer_node
;
3641 if (TREE_CODE (op0
) == STRING_CST
3642 && TREE_CODE (op1
) == STRING_CST
3643 && operand_equal_p (op0
, op1
, 1))
3644 return null_pointer_node
;
3656 /* Output assembler code for constant EXP to FILE, with no label.
3657 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3658 Assumes output_addressed_constants has been done on EXP already.
3660 Generate exactly SIZE bytes of assembler data, padding at the end
3661 with zeros if necessary. SIZE must always be specified.
3663 SIZE is important for structure constructors,
3664 since trailing members may have been omitted from the constructor.
3665 It is also important for initialization of arrays from string constants
3666 since the full length of the string constant might not be wanted.
3667 It is also needed for initialization of unions, where the initializer's
3668 type is just one member, and that may not be as long as the union.
3670 There a case in which we would fail to output exactly SIZE bytes:
3671 for a structure constructor that wants to produce more than SIZE bytes.
3672 But such constructors will never be generated for any possible input.
3674 ALIGN is the alignment of the data in bits. */
3677 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
3679 enum tree_code code
;
3680 unsigned HOST_WIDE_INT thissize
;
3682 /* Some front-ends use constants other than the standard language-independent
3683 varieties, but which may still be output directly. Give the front-end a
3684 chance to convert EXP to a language-independent representation. */
3685 exp
= lang_hooks
.expand_constant (exp
);
3687 if (size
== 0 || flag_syntax_only
)
3690 /* See if we're trying to initialize a pointer in a non-default mode
3691 to the address of some declaration somewhere. If the target says
3692 the mode is valid for pointers, assume the target has a way of
3694 if (TREE_CODE (exp
) == NOP_EXPR
3695 && POINTER_TYPE_P (TREE_TYPE (exp
))
3696 && targetm
.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp
))))
3698 tree saved_type
= TREE_TYPE (exp
);
3700 /* Peel off any intermediate conversions-to-pointer for valid
3702 while (TREE_CODE (exp
) == NOP_EXPR
3703 && POINTER_TYPE_P (TREE_TYPE (exp
))
3704 && targetm
.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp
))))
3705 exp
= TREE_OPERAND (exp
, 0);
3707 /* If what we're left with is the address of something, we can
3708 convert the address to the final type and output it that
3710 if (TREE_CODE (exp
) == ADDR_EXPR
)
3711 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
3714 /* Eliminate any conversions since we'll be outputting the underlying
3716 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
3717 || TREE_CODE (exp
) == NON_LVALUE_EXPR
3718 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
3720 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
3721 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
3723 /* Make sure eliminating the conversion is really a no-op, except with
3724 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
3725 union types to allow for Ada unchecked unions. */
3726 if (type_size
> op_size
3727 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
3728 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
3729 internal_error ("no-op convert from %wd to %wd bytes in initializer",
3730 op_size
, type_size
);
3732 exp
= TREE_OPERAND (exp
, 0);
3735 code
= TREE_CODE (TREE_TYPE (exp
));
3736 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
3738 /* Allow a constructor with no elements for any data type.
3739 This means to fill the space with zeros. */
3740 if (TREE_CODE (exp
) == CONSTRUCTOR
3741 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
3743 assemble_zeros (size
);
3747 if (TREE_CODE (exp
) == FDESC_EXPR
)
3749 #ifdef ASM_OUTPUT_FDESC
3750 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
3751 tree decl
= TREE_OPERAND (exp
, 0);
3752 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
3759 /* Now output the underlying data. If we've handling the padding, return.
3760 Otherwise, break and ensure SIZE is the size written. */
3768 case REFERENCE_TYPE
:
3770 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
3771 EXPAND_INITIALIZER
),
3772 MIN (size
, thissize
), align
, 0))
3773 error ("initializer for integer value is too complicated");
3777 if (TREE_CODE (exp
) != REAL_CST
)
3778 error ("initializer for floating value is not a floating constant");
3780 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
3784 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
3785 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
3786 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
3791 switch (TREE_CODE (exp
))
3794 output_constructor (exp
, size
, align
);
3797 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
3799 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
3806 unsigned int nalign
;
3807 enum machine_mode inner
;
3809 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
3810 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
3812 elt_size
= GET_MODE_SIZE (inner
);
3814 link
= TREE_VECTOR_CST_ELTS (exp
);
3815 output_constant (TREE_VALUE (link
), elt_size
, align
);
3816 while ((link
= TREE_CHAIN (link
)) != NULL
)
3817 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
3827 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
3828 output_constructor (exp
, size
, align
);
3838 if (size
> thissize
)
3839 assemble_zeros (size
- thissize
);
3843 /* Subroutine of output_constructor, used for computing the size of
3844 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3845 type with an unspecified upper bound. */
3847 static unsigned HOST_WIDE_INT
3848 array_size_for_constructor (tree val
)
3851 unsigned HOST_WIDE_INT cnt
;
3854 /* This code used to attempt to handle string constants that are not
3855 arrays of single-bytes, but nothing else does, so there's no point in
3857 if (TREE_CODE (val
) == STRING_CST
)
3858 return TREE_STRING_LENGTH (val
);
3860 max_index
= NULL_TREE
;
3861 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
3863 if (TREE_CODE (index
) == RANGE_EXPR
)
3864 index
= TREE_OPERAND (index
, 1);
3865 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
3869 if (max_index
== NULL_TREE
)
3872 /* Compute the total number of array elements. */
3873 i
= size_binop (MINUS_EXPR
, convert (sizetype
, max_index
),
3875 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)))));
3876 i
= size_binop (PLUS_EXPR
, i
, convert (sizetype
, integer_one_node
));
3878 /* Multiply by the array element unit size to find number of bytes. */
3879 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
3881 return tree_low_cst (i
, 1);
3884 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3885 Generate at least SIZE bytes, padding if necessary. */
3888 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
3891 tree type
= TREE_TYPE (exp
);
3894 /* Number of bytes output or skipped so far.
3895 In other words, current position within the constructor. */
3896 HOST_WIDE_INT total_bytes
= 0;
3897 /* Nonzero means BYTE contains part of a byte, to be output. */
3898 int byte_buffer_in_use
= 0;
3900 unsigned HOST_WIDE_INT cnt
;
3901 constructor_elt
*ce
;
3903 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
3905 if (TREE_CODE (type
) == RECORD_TYPE
)
3906 field
= TYPE_FIELDS (type
);
3908 if (TREE_CODE (type
) == ARRAY_TYPE
3909 && TYPE_DOMAIN (type
) != 0)
3910 min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
3912 /* As LINK goes through the elements of the constant,
3913 FIELD goes through the structure fields, if the constant is a structure.
3914 if the constant is a union, then we override this,
3915 by getting the field from the TREE_LIST element.
3916 But the constant could also be an array. Then FIELD is zero.
3918 There is always a maximum of one element in the chain LINK for unions
3919 (even if the initializer in a source program incorrectly contains
3922 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
3923 cnt
++, field
= field
? TREE_CHAIN (field
) : 0)
3925 tree val
= ce
->value
;
3928 /* The element in a union constructor specifies the proper field
3930 if ((TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
3931 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
3935 else if (TREE_CODE (type
) == ARRAY_TYPE
)
3938 #ifdef ASM_COMMENT_START
3939 if (field
&& flag_verbose_asm
)
3940 fprintf (asm_out_file
, "%s %s:\n",
3943 ? IDENTIFIER_POINTER (DECL_NAME (field
))
3947 /* Eliminate the marker that makes a cast not be an lvalue. */
3951 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
3953 unsigned HOST_WIDE_INT fieldsize
3954 = int_size_in_bytes (TREE_TYPE (type
));
3955 HOST_WIDE_INT lo_index
= tree_low_cst (TREE_OPERAND (index
, 0), 0);
3956 HOST_WIDE_INT hi_index
= tree_low_cst (TREE_OPERAND (index
, 1), 0);
3957 HOST_WIDE_INT index
;
3958 unsigned int align2
= min_align (align
, fieldsize
* BITS_PER_UNIT
);
3960 for (index
= lo_index
; index
<= hi_index
; index
++)
3962 /* Output the element's initial value. */
3964 assemble_zeros (fieldsize
);
3966 output_constant (val
, fieldsize
, align2
);
3968 /* Count its size. */
3969 total_bytes
+= fieldsize
;
3972 else if (field
== 0 || !DECL_BIT_FIELD (field
))
3974 /* An element that is not a bit-field. */
3976 unsigned HOST_WIDE_INT fieldsize
;
3977 /* Since this structure is static,
3978 we know the positions are constant. */
3979 HOST_WIDE_INT pos
= field
? int_byte_position (field
) : 0;
3980 unsigned int align2
;
3983 pos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val
)), 1)
3984 * (tree_low_cst (index
, 0) - tree_low_cst (min_index
, 0)));
3986 /* Output any buffered-up bit-fields preceding this element. */
3987 if (byte_buffer_in_use
)
3989 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
3991 byte_buffer_in_use
= 0;
3994 /* Advance to offset of this element.
3995 Note no alignment needed in an array, since that is guaranteed
3996 if each element has the proper size. */
3997 if ((field
!= 0 || index
!= 0) && pos
!= total_bytes
)
3999 gcc_assert (pos
>= total_bytes
);
4000 assemble_zeros (pos
- total_bytes
);
4004 /* Find the alignment of this element. */
4005 align2
= min_align (align
, BITS_PER_UNIT
* pos
);
4007 /* Determine size this element should occupy. */
4012 /* If this is an array with an unspecified upper bound,
4013 the initializer determines the size. */
4014 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4015 but we cannot do this until the deprecated support for
4016 initializing zero-length array members is removed. */
4017 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
4018 && TYPE_DOMAIN (TREE_TYPE (field
))
4019 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
4021 fieldsize
= array_size_for_constructor (val
);
4022 /* Given a non-empty initialization, this field had
4024 gcc_assert (!fieldsize
|| !TREE_CHAIN (field
));
4026 else if (DECL_SIZE_UNIT (field
))
4028 /* ??? This can't be right. If the decl size overflows
4029 a host integer we will silently emit no data. */
4030 if (host_integerp (DECL_SIZE_UNIT (field
), 1))
4031 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 1);
4035 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
4037 /* Output the element's initial value. */
4039 assemble_zeros (fieldsize
);
4041 output_constant (val
, fieldsize
, align2
);
4043 /* Count its size. */
4044 total_bytes
+= fieldsize
;
4046 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4047 error ("invalid initial value for member %qs",
4048 IDENTIFIER_POINTER (DECL_NAME (field
)));
4051 /* Element that is a bit-field. */
4053 HOST_WIDE_INT next_offset
= int_bit_position (field
);
4054 HOST_WIDE_INT end_offset
4055 = (next_offset
+ tree_low_cst (DECL_SIZE (field
), 1));
4058 val
= integer_zero_node
;
4060 /* If this field does not start in this (or, next) byte,
4062 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4064 /* Output remnant of any bit field in previous bytes. */
4065 if (byte_buffer_in_use
)
4067 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4069 byte_buffer_in_use
= 0;
4072 /* If still not at proper byte, advance to there. */
4073 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4075 gcc_assert (next_offset
/ BITS_PER_UNIT
>= total_bytes
);
4076 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4077 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4081 if (! byte_buffer_in_use
)
4084 /* We must split the element into pieces that fall within
4085 separate bytes, and combine each byte with previous or
4086 following bit-fields. */
4088 /* next_offset is the offset n fbits from the beginning of
4089 the structure to the next bit of this element to be processed.
4090 end_offset is the offset of the first bit past the end of
4092 while (next_offset
< end_offset
)
4096 HOST_WIDE_INT value
;
4097 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4098 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4100 /* Advance from byte to byte
4101 within this element when necessary. */
4102 while (next_byte
!= total_bytes
)
4104 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4109 /* Number of bits we can process at once
4110 (all part of the same byte). */
4111 this_time
= MIN (end_offset
- next_offset
,
4112 BITS_PER_UNIT
- next_bit
);
4113 if (BYTES_BIG_ENDIAN
)
4115 /* On big-endian machine, take the most significant bits
4116 first (of the bits that are significant)
4117 and put them into bytes from the most significant end. */
4118 shift
= end_offset
- next_offset
- this_time
;
4120 /* Don't try to take a bunch of bits that cross
4121 the word boundary in the INTEGER_CST. We can
4122 only select bits from the LOW or HIGH part
4124 if (shift
< HOST_BITS_PER_WIDE_INT
4125 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4127 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4128 shift
= HOST_BITS_PER_WIDE_INT
;
4131 /* Now get the bits from the appropriate constant word. */
4132 if (shift
< HOST_BITS_PER_WIDE_INT
)
4133 value
= TREE_INT_CST_LOW (val
);
4136 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4137 value
= TREE_INT_CST_HIGH (val
);
4138 shift
-= HOST_BITS_PER_WIDE_INT
;
4141 /* Get the result. This works only when:
4142 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4143 byte
|= (((value
>> shift
)
4144 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4145 << (BITS_PER_UNIT
- this_time
- next_bit
));
4149 /* On little-endian machines,
4150 take first the least significant bits of the value
4151 and pack them starting at the least significant
4152 bits of the bytes. */
4153 shift
= next_offset
- int_bit_position (field
);
4155 /* Don't try to take a bunch of bits that cross
4156 the word boundary in the INTEGER_CST. We can
4157 only select bits from the LOW or HIGH part
4159 if (shift
< HOST_BITS_PER_WIDE_INT
4160 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4161 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4163 /* Now get the bits from the appropriate constant word. */
4164 if (shift
< HOST_BITS_PER_WIDE_INT
)
4165 value
= TREE_INT_CST_LOW (val
);
4168 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4169 value
= TREE_INT_CST_HIGH (val
);
4170 shift
-= HOST_BITS_PER_WIDE_INT
;
4173 /* Get the result. This works only when:
4174 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4175 byte
|= (((value
>> shift
)
4176 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4180 next_offset
+= this_time
;
4181 byte_buffer_in_use
= 1;
4186 if (byte_buffer_in_use
)
4188 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4192 if ((unsigned HOST_WIDE_INT
)total_bytes
< size
)
4193 assemble_zeros (size
- total_bytes
);
4196 /* This TREE_LIST contains any weak symbol declarations waiting
4198 static GTY(()) tree weak_decls
;
4200 /* Mark DECL as weak. */
4203 mark_weak (tree decl
)
4205 DECL_WEAK (decl
) = 1;
4207 if (DECL_RTL_SET_P (decl
)
4208 && MEM_P (DECL_RTL (decl
))
4209 && XEXP (DECL_RTL (decl
), 0)
4210 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
4211 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
4214 /* Merge weak status between NEWDECL and OLDDECL. */
4217 merge_weak (tree newdecl
, tree olddecl
)
4219 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
4221 if (DECL_WEAK (newdecl
) && SUPPORTS_WEAK
)
4224 /* We put the NEWDECL on the weak_decls list at some point
4225 and OLDDECL as well. Keep just OLDDECL on the list. */
4226 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
4227 if (TREE_VALUE (*pwd
) == newdecl
)
4229 *pwd
= TREE_CHAIN (*pwd
);
4236 if (DECL_WEAK (newdecl
))
4240 /* NEWDECL is weak, but OLDDECL is not. */
4242 /* If we already output the OLDDECL, we're in trouble; we can't
4243 go back and make it weak. This error cannot caught in
4244 declare_weak because the NEWDECL and OLDDECL was not yet
4245 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4246 if (TREE_ASM_WRITTEN (olddecl
))
4247 error ("weak declaration of %q+D must precede definition",
4250 /* If we've already generated rtl referencing OLDDECL, we may
4251 have done so in a way that will not function properly with
4253 else if (TREE_USED (olddecl
)
4254 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
4255 warning (0, "weak declaration of %q+D after first use results "
4256 "in unspecified behavior", newdecl
);
4260 /* We put the NEWDECL on the weak_decls list at some point.
4261 Replace it with the OLDDECL. */
4262 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
4263 if (TREE_VALUE (wd
) == newdecl
)
4265 TREE_VALUE (wd
) = olddecl
;
4268 /* We may not find the entry on the list. If NEWDECL is a
4269 weak alias, then we will have already called
4270 globalize_decl to remove the entry; in that case, we do
4271 not need to do anything. */
4274 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4275 mark_weak (olddecl
);
4278 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4279 weak. Just update NEWDECL to indicate that it's weak too. */
4280 mark_weak (newdecl
);
4283 /* Declare DECL to be a weak symbol. */
4286 declare_weak (tree decl
)
4288 if (! TREE_PUBLIC (decl
))
4289 error ("weak declaration of %q+D must be public", decl
);
4290 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
4291 error ("weak declaration of %q+D must precede definition", decl
);
4292 else if (SUPPORTS_WEAK
)
4294 if (! DECL_WEAK (decl
))
4295 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
4298 warning (0, "weak declaration of %q+D not supported", decl
);
4304 weak_finish_1 (tree decl
)
4306 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4307 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4310 if (! TREE_USED (decl
))
4313 #ifdef ASM_WEAKEN_DECL
4314 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
4316 #ifdef ASM_WEAKEN_LABEL
4317 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4319 #ifdef ASM_OUTPUT_WEAK_ALIAS
4321 static bool warn_once
= 0;
4324 warning (0, "only weak aliases are supported in this configuration");
4334 /* This TREE_LIST contains weakref targets. */
4336 static GTY(()) tree weakref_targets
;
4338 /* Forward declaration. */
4339 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
4341 /* Emit any pending weak declarations. */
4348 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
4350 tree alias_decl
= TREE_PURPOSE (t
);
4351 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
4353 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
4354 /* Remove alias_decl from the weak list, but leave entries for
4355 the target alone. */
4357 #ifndef ASM_OUTPUT_WEAKREF
4358 else if (! TREE_SYMBOL_REFERENCED (target
))
4360 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
4361 defined, otherwise we and weak_finish_1 would use a
4362 different macros. */
4363 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
4364 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
4366 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
4370 decl
= build_decl (TREE_CODE (alias_decl
), target
,
4371 TREE_TYPE (alias_decl
));
4373 DECL_EXTERNAL (decl
) = 1;
4374 TREE_PUBLIC (decl
) = 1;
4375 DECL_ARTIFICIAL (decl
) = 1;
4376 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
4377 TREE_USED (decl
) = 1;
4380 weak_finish_1 (decl
);
4389 /* Remove the alias and the target from the pending weak list
4390 so that we do not emit any .weak directives for the former,
4391 nor multiple .weak directives for the latter. */
4392 for (p
= &weak_decls
; (t2
= *p
) ; )
4394 if (TREE_VALUE (t2
) == alias_decl
4395 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
4396 *p
= TREE_CHAIN (t2
);
4398 p
= &TREE_CHAIN (t2
);
4401 /* Remove other weakrefs to the same target, to speed things up. */
4402 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
4404 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
4405 *p
= TREE_CHAIN (t2
);
4407 p
= &TREE_CHAIN (t2
);
4412 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
4414 tree decl
= TREE_VALUE (t
);
4416 weak_finish_1 (decl
);
4420 /* Emit the assembly bits to indicate that DECL is globally visible. */
4423 globalize_decl (tree decl
)
4425 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4427 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4428 if (DECL_WEAK (decl
))
4432 #ifdef ASM_WEAKEN_DECL
4433 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
4435 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4438 /* Remove this function from the pending weak list so that
4439 we do not emit multiple .weak directives for it. */
4440 for (p
= &weak_decls
; (t
= *p
) ; )
4442 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
4443 *p
= TREE_CHAIN (t
);
4445 p
= &TREE_CHAIN (t
);
4448 /* Remove weakrefs to the same target from the pending weakref
4449 list, for the same reason. */
4450 for (p
= &weakref_targets
; (t
= *p
) ; )
4452 if (DECL_ASSEMBLER_NAME (decl
)
4453 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
4454 *p
= TREE_CHAIN (t
);
4456 p
= &TREE_CHAIN (t
);
4461 #elif defined(ASM_MAKE_LABEL_LINKONCE)
4462 if (DECL_ONE_ONLY (decl
))
4463 ASM_MAKE_LABEL_LINKONCE (asm_out_file
, name
);
4466 targetm
.asm_out
.globalize_label (asm_out_file
, name
);
4469 /* We have to be able to tell cgraph about the needed-ness of the target
4470 of an alias. This requires that the decl have been defined. Aliases
4471 that precede their definition have to be queued for later processing. */
4473 typedef struct alias_pair
GTY(())
4479 /* Define gc'd vector type. */
4480 DEF_VEC_O(alias_pair
);
4481 DEF_VEC_ALLOC_O(alias_pair
,gc
);
4483 static GTY(()) VEC(alias_pair
,gc
) *alias_pairs
;
4485 /* Given an assembly name, find the decl it is associated with. At the
4486 same time, mark it needed for cgraph. */
4489 find_decl_and_mark_needed (tree decl
, tree target
)
4491 struct cgraph_node
*fnode
= NULL
;
4492 struct cgraph_varpool_node
*vnode
= NULL
;
4494 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4496 fnode
= cgraph_node_for_asm (target
);
4498 vnode
= cgraph_varpool_node_for_asm (target
);
4502 vnode
= cgraph_varpool_node_for_asm (target
);
4504 fnode
= cgraph_node_for_asm (target
);
4509 /* We can't mark function nodes as used after cgraph global info
4510 is finished. This wouldn't generally be necessary, but C++
4511 virtual table thunks are introduced late in the game and
4512 might seem like they need marking, although in fact they
4514 if (! cgraph_global_info_ready
)
4515 cgraph_mark_needed_node (fnode
);
4520 cgraph_varpool_mark_needed_node (vnode
);
4527 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
4528 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
4529 tree node is DECL to have the value of the tree node TARGET. */
4532 do_assemble_alias (tree decl
, tree target
)
4534 if (TREE_ASM_WRITTEN (decl
))
4537 TREE_ASM_WRITTEN (decl
) = 1;
4538 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
4540 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
4542 ultimate_transparent_alias_target (&target
);
4544 if (!TREE_SYMBOL_REFERENCED (target
))
4545 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
4547 #ifdef ASM_OUTPUT_WEAKREF
4548 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
4549 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
4550 IDENTIFIER_POINTER (target
));
4554 error ("%Jweakref is not supported in this configuration", decl
);
4561 #ifdef ASM_OUTPUT_DEF
4562 /* Make name accessible from other files, if appropriate. */
4564 if (TREE_PUBLIC (decl
))
4566 globalize_decl (decl
);
4567 maybe_assemble_visibility (decl
);
4570 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
4571 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4573 ASM_OUTPUT_DEF (asm_out_file
,
4574 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
4575 IDENTIFIER_POINTER (target
));
4577 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4582 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4583 # ifdef ASM_WEAKEN_DECL
4584 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
4586 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4588 /* Remove this function from the pending weak list so that
4589 we do not emit multiple .weak directives for it. */
4590 for (p
= &weak_decls
; (t
= *p
) ; )
4591 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
4592 *p
= TREE_CHAIN (t
);
4594 p
= &TREE_CHAIN (t
);
4596 /* Remove weakrefs to the same target from the pending weakref
4597 list, for the same reason. */
4598 for (p
= &weakref_targets
; (t
= *p
) ; )
4600 if (DECL_ASSEMBLER_NAME (decl
)
4601 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
4602 *p
= TREE_CHAIN (t
);
4604 p
= &TREE_CHAIN (t
);
4610 /* First pass of completing pending aliases. Make sure that cgraph knows
4611 which symbols will be required. */
4614 finish_aliases_1 (void)
4619 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
4623 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
4624 if (target_decl
== NULL
)
4626 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
4627 error ("%q+D aliased to undefined symbol %qs",
4628 p
->decl
, IDENTIFIER_POINTER (p
->target
));
4630 else if (DECL_EXTERNAL (target_decl
)
4631 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
4632 error ("%q+D aliased to external symbol %qs",
4633 p
->decl
, IDENTIFIER_POINTER (p
->target
));
4637 /* Second pass of completing pending aliases. Emit the actual assembly.
4638 This happens at the end of compilation and thus it is assured that the
4639 target symbol has been emitted. */
4642 finish_aliases_2 (void)
4647 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
4648 do_assemble_alias (p
->decl
, p
->target
);
4650 VEC_truncate (alias_pair
, alias_pairs
, 0);
4653 /* Emit an assembler directive to make the symbol for DECL an alias to
4654 the symbol for TARGET. */
4657 assemble_alias (tree decl
, tree target
)
4660 bool is_weakref
= false;
4662 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
4664 tree alias
= DECL_ASSEMBLER_NAME (decl
);
4668 ultimate_transparent_alias_target (&target
);
4670 if (alias
== target
)
4671 error ("weakref %q+D ultimately targets itself", decl
);
4674 #ifndef ASM_OUTPUT_WEAKREF
4675 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
4676 TREE_CHAIN (alias
) = target
;
4679 if (TREE_PUBLIC (decl
))
4680 error ("weakref %q+D must have static linkage", decl
);
4684 #if !defined (ASM_OUTPUT_DEF)
4685 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
4686 error ("%Jalias definitions not supported in this configuration", decl
);
4689 if (!DECL_WEAK (decl
))
4691 error ("%Jonly weak aliases are supported in this configuration", decl
);
4698 /* We must force creation of DECL_RTL for debug info generation, even though
4699 we don't use it here. */
4700 make_decl_rtl (decl
);
4701 TREE_USED (decl
) = 1;
4703 /* A quirk of the initial implementation of aliases required that the user
4704 add "extern" to all of them. Which is silly, but now historical. Do
4705 note that the symbol is in fact locally defined. */
4707 DECL_EXTERNAL (decl
) = 0;
4709 /* Allow aliases to aliases. */
4710 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4711 cgraph_node (decl
)->alias
= true;
4713 cgraph_varpool_node (decl
)->alias
= true;
4715 /* If the target has already been emitted, we don't have to queue the
4716 alias. This saves a tad o memory. */
4717 target_decl
= find_decl_and_mark_needed (decl
, target
);
4718 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
4719 do_assemble_alias (decl
, target
);
4722 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
4728 /* Emit an assembler directive to set symbol for DECL visibility to
4729 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4732 default_assemble_visibility (tree decl
, int vis
)
4734 static const char * const visibility_types
[] = {
4735 NULL
, "internal", "hidden", "protected"
4738 const char *name
, *type
;
4740 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4741 type
= visibility_types
[vis
];
4743 #ifdef HAVE_GAS_HIDDEN
4744 fprintf (asm_out_file
, "\t.%s\t", type
);
4745 assemble_name (asm_out_file
, name
);
4746 fprintf (asm_out_file
, "\n");
4748 warning (OPT_Wattributes
, "visibility attribute not supported "
4749 "in this configuration; ignored");
4753 /* A helper function to call assemble_visibility when needed for a decl. */
4756 maybe_assemble_visibility (tree decl
)
4758 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
4760 if (vis
!= VISIBILITY_DEFAULT
)
4761 targetm
.asm_out
.visibility (decl
, vis
);
4764 /* Returns 1 if the target configuration supports defining public symbols
4765 so that one of them will be chosen at link time instead of generating a
4766 multiply-defined symbol error, whether through the use of weak symbols or
4767 a target-specific mechanism for having duplicates discarded. */
4770 supports_one_only (void)
4772 if (SUPPORTS_ONE_ONLY
)
4774 return SUPPORTS_WEAK
;
4777 /* Set up DECL as a public symbol that can be defined in multiple
4778 translation units without generating a linker error. */
4781 make_decl_one_only (tree decl
)
4783 gcc_assert (TREE_CODE (decl
) == VAR_DECL
4784 || TREE_CODE (decl
) == FUNCTION_DECL
);
4786 TREE_PUBLIC (decl
) = 1;
4788 if (SUPPORTS_ONE_ONLY
)
4790 #ifdef MAKE_DECL_ONE_ONLY
4791 MAKE_DECL_ONE_ONLY (decl
);
4793 DECL_ONE_ONLY (decl
) = 1;
4795 else if (TREE_CODE (decl
) == VAR_DECL
4796 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
4797 DECL_COMMON (decl
) = 1;
4800 gcc_assert (SUPPORTS_WEAK
);
4801 DECL_WEAK (decl
) = 1;
4806 init_varasm_once (void)
4808 section_htab
= htab_create_ggc (31, section_entry_hash
,
4809 section_entry_eq
, NULL
);
4810 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
4811 const_desc_eq
, NULL
);
4813 const_alias_set
= new_alias_set ();
4815 #ifdef TEXT_SECTION_ASM_OP
4816 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
4817 TEXT_SECTION_ASM_OP
);
4820 #ifdef DATA_SECTION_ASM_OP
4821 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
4822 DATA_SECTION_ASM_OP
);
4825 #ifdef SDATA_SECTION_ASM_OP
4826 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
4827 SDATA_SECTION_ASM_OP
);
4830 #ifdef READONLY_DATA_SECTION_ASM_OP
4831 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
4832 READONLY_DATA_SECTION_ASM_OP
);
4835 #ifdef CTORS_SECTION_ASM_OP
4836 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
4837 CTORS_SECTION_ASM_OP
);
4840 #ifdef DTORS_SECTION_ASM_OP
4841 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
4842 DTORS_SECTION_ASM_OP
);
4845 #ifdef BSS_SECTION_ASM_OP
4846 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
4847 output_section_asm_op
,
4848 BSS_SECTION_ASM_OP
);
4851 #ifdef SBSS_SECTION_ASM_OP
4852 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
4853 output_section_asm_op
,
4854 SBSS_SECTION_ASM_OP
);
4857 #ifdef INIT_SECTION_ASM_OP
4858 init_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
4859 INIT_SECTION_ASM_OP
);
4862 #ifdef FINI_SECTION_ASM_OP
4863 fini_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
4864 FINI_SECTION_ASM_OP
);
4867 targetm
.asm_out
.init_sections ();
4869 if (readonly_data_section
== NULL
)
4870 readonly_data_section
= text_section
;
4871 if (exception_section
== NULL
)
4872 exception_section
= default_exception_section ();
4873 if (eh_frame_section
== NULL
)
4874 eh_frame_section
= default_eh_frame_section ();
4878 decl_default_tls_model (tree decl
)
4880 enum tls_model kind
;
4883 is_local
= targetm
.binds_local_p (decl
);
4887 kind
= TLS_MODEL_LOCAL_EXEC
;
4889 kind
= TLS_MODEL_INITIAL_EXEC
;
4892 /* Local dynamic is inefficient when we're not combining the
4893 parts of the address. */
4894 else if (optimize
&& is_local
)
4895 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
4897 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
4898 if (kind
< flag_tls_default
)
4899 kind
= flag_tls_default
;
4904 /* Select a set of attributes for section NAME based on the properties
4905 of DECL and whether or not RELOC indicates that DECL's initializer
4906 might contain runtime relocations.
4908 We make the section read-only and executable for a function decl,
4909 read-only for a const data decl, and writable for a non-const data decl. */
4912 default_section_type_flags (tree decl
, const char *name
, int reloc
)
4914 return default_section_type_flags_1 (decl
, name
, reloc
, flag_pic
);
4918 default_section_type_flags_1 (tree decl
, const char *name
, int reloc
,
4923 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
4924 flags
= SECTION_CODE
;
4925 else if (decl
&& decl_readonly_section_1 (decl
, reloc
, shlib
))
4927 else if (current_function_decl
4929 && cfun
->unlikely_text_section_name
4930 && strcmp (name
, cfun
->unlikely_text_section_name
) == 0)
4931 flags
= SECTION_CODE
;
4933 && (!current_function_decl
|| !cfun
)
4934 && strcmp (name
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
4935 flags
= SECTION_CODE
;
4937 flags
= SECTION_WRITE
;
4939 if (decl
&& DECL_ONE_ONLY (decl
))
4940 flags
|= SECTION_LINKONCE
;
4942 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
4943 flags
|= SECTION_TLS
| SECTION_WRITE
;
4945 if (strcmp (name
, ".bss") == 0
4946 || strncmp (name
, ".bss.", 5) == 0
4947 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
4948 || strcmp (name
, ".sbss") == 0
4949 || strncmp (name
, ".sbss.", 6) == 0
4950 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
4951 flags
|= SECTION_BSS
;
4953 if (strcmp (name
, ".tdata") == 0
4954 || strncmp (name
, ".tdata.", 7) == 0
4955 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
4956 flags
|= SECTION_TLS
;
4958 if (strcmp (name
, ".tbss") == 0
4959 || strncmp (name
, ".tbss.", 6) == 0
4960 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
4961 flags
|= SECTION_TLS
| SECTION_BSS
;
4963 /* These three sections have special ELF types. They are neither
4964 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4965 want to print a section type (@progbits or @nobits). If someone
4966 is silly enough to emit code or TLS variables to one of these
4967 sections, then don't handle them specially. */
4968 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
4969 && (strcmp (name
, ".init_array") == 0
4970 || strcmp (name
, ".fini_array") == 0
4971 || strcmp (name
, ".preinit_array") == 0))
4972 flags
|= SECTION_NOTYPE
;
4977 /* Output assembly to switch to section NAME with attribute FLAGS.
4978 Four variants for common object file formats. */
4981 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
4982 unsigned int flags ATTRIBUTE_UNUSED
,
4983 tree decl ATTRIBUTE_UNUSED
)
4985 /* Some object formats don't support named sections at all. The
4986 front-end should already have flagged this as an error. */
4991 default_elf_asm_named_section (const char *name
, unsigned int flags
,
4992 tree decl ATTRIBUTE_UNUSED
)
4994 char flagchars
[10], *f
= flagchars
;
4996 /* If we have already declared this section, we can use an
4997 abbreviated form to switch back to it -- unless this section is
4998 part of a COMDAT groups, in which case GAS requires the full
4999 declaration every time. */
5000 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5001 && (flags
& SECTION_DECLARED
))
5003 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
5007 if (!(flags
& SECTION_DEBUG
))
5009 if (flags
& SECTION_WRITE
)
5011 if (flags
& SECTION_CODE
)
5013 if (flags
& SECTION_SMALL
)
5015 if (flags
& SECTION_MERGE
)
5017 if (flags
& SECTION_STRINGS
)
5019 if (flags
& SECTION_TLS
)
5021 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5025 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
5027 if (!(flags
& SECTION_NOTYPE
))
5032 if (flags
& SECTION_BSS
)
5038 #ifdef ASM_COMMENT_START
5039 /* On platforms that use "@" as the assembly comment character,
5041 if (strcmp (ASM_COMMENT_START
, "@") == 0)
5044 fprintf (asm_out_file
, format
, type
);
5046 if (flags
& SECTION_ENTSIZE
)
5047 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
5048 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5049 fprintf (asm_out_file
, ",%s,comdat",
5050 lang_hooks
.decls
.comdat_group (decl
));
5053 putc ('\n', asm_out_file
);
5057 default_coff_asm_named_section (const char *name
, unsigned int flags
,
5058 tree decl ATTRIBUTE_UNUSED
)
5060 char flagchars
[8], *f
= flagchars
;
5062 if (flags
& SECTION_WRITE
)
5064 if (flags
& SECTION_CODE
)
5068 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
5072 default_pe_asm_named_section (const char *name
, unsigned int flags
,
5075 default_coff_asm_named_section (name
, flags
, decl
);
5077 if (flags
& SECTION_LINKONCE
)
5079 /* Functions may have been compiled at various levels of
5080 optimization so we can't use `same_size' here.
5081 Instead, have the linker pick one. */
5082 fprintf (asm_out_file
, "\t.linkonce %s\n",
5083 (flags
& SECTION_CODE
? "discard" : "same_size"));
5087 /* The lame default section selector. */
5090 default_select_section (tree decl
, int reloc
,
5091 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
5095 if (decl_readonly_section (decl
, reloc
))
5096 return readonly_data_section
;
5098 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5100 if (! ((flag_pic
&& reloc
)
5101 || !TREE_READONLY (decl
)
5102 || TREE_SIDE_EFFECTS (decl
)
5103 || !TREE_CONSTANT (decl
)))
5104 return readonly_data_section
;
5106 else if (TREE_CODE (decl
) == STRING_CST
)
5107 return readonly_data_section
;
5108 else if (! (flag_pic
&& reloc
))
5109 return readonly_data_section
;
5111 return data_section
;
5114 enum section_category
5115 categorize_decl_for_section (tree decl
, int reloc
, int shlib
)
5117 enum section_category ret
;
5119 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5121 else if (TREE_CODE (decl
) == STRING_CST
)
5123 if (flag_mudflap
) /* or !flag_merge_constants */
5124 return SECCAT_RODATA
;
5126 return SECCAT_RODATA_MERGE_STR
;
5128 else if (TREE_CODE (decl
) == VAR_DECL
)
5130 if (DECL_INITIAL (decl
) == NULL
5131 || DECL_INITIAL (decl
) == error_mark_node
5132 || (flag_zero_initialized_in_bss
5133 /* Leave constant zeroes in .rodata so they can be shared. */
5134 && !TREE_READONLY (decl
)
5135 && initializer_zerop (DECL_INITIAL (decl
))))
5137 else if (! TREE_READONLY (decl
)
5138 || TREE_SIDE_EFFECTS (decl
)
5139 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
5141 if (shlib
&& (reloc
& 2))
5142 ret
= SECCAT_DATA_REL
;
5143 else if (shlib
&& reloc
)
5144 ret
= SECCAT_DATA_REL_LOCAL
;
5148 else if (shlib
&& (reloc
& 2))
5149 ret
= SECCAT_DATA_REL_RO
;
5150 else if (shlib
&& reloc
)
5151 ret
= SECCAT_DATA_REL_RO_LOCAL
;
5152 else if (reloc
|| flag_merge_constants
< 2)
5153 /* C and C++ don't allow different variables to share the same
5154 location. -fmerge-all-constants allows even that (at the
5155 expense of not conforming). */
5156 ret
= SECCAT_RODATA
;
5157 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
5158 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
5160 ret
= SECCAT_RODATA_MERGE_CONST
;
5162 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5164 if ((shlib
&& reloc
)
5165 || TREE_SIDE_EFFECTS (decl
)
5166 || ! TREE_CONSTANT (decl
))
5169 ret
= SECCAT_RODATA
;
5172 ret
= SECCAT_RODATA
;
5174 /* There are no read-only thread-local sections. */
5175 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
5177 /* Note that this would be *just* SECCAT_BSS, except that there's
5178 no concept of a read-only thread-local-data section. */
5179 if (ret
== SECCAT_BSS
5180 || (flag_zero_initialized_in_bss
5181 && initializer_zerop (DECL_INITIAL (decl
))))
5187 /* If the target uses small data sections, select it. */
5188 else if (targetm
.in_small_data_p (decl
))
5190 if (ret
== SECCAT_BSS
)
5192 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
5193 ret
= SECCAT_SRODATA
;
5202 decl_readonly_section (tree decl
, int reloc
)
5204 return decl_readonly_section_1 (decl
, reloc
, flag_pic
);
5208 decl_readonly_section_1 (tree decl
, int reloc
, int shlib
)
5210 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5213 case SECCAT_RODATA_MERGE_STR
:
5214 case SECCAT_RODATA_MERGE_STR_INIT
:
5215 case SECCAT_RODATA_MERGE_CONST
:
5216 case SECCAT_SRODATA
:
5225 /* Select a section based on the above categorization. */
5228 default_elf_select_section (tree decl
, int reloc
,
5229 unsigned HOST_WIDE_INT align
)
5231 return default_elf_select_section_1 (decl
, reloc
, align
, flag_pic
);
5235 default_elf_select_section_1 (tree decl
, int reloc
,
5236 unsigned HOST_WIDE_INT align
, int shlib
)
5239 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5242 /* We're not supposed to be called on FUNCTION_DECLs. */
5245 return readonly_data_section
;
5246 case SECCAT_RODATA_MERGE_STR
:
5247 return mergeable_string_section (decl
, align
, 0);
5248 case SECCAT_RODATA_MERGE_STR_INIT
:
5249 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
5250 case SECCAT_RODATA_MERGE_CONST
:
5251 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
5252 case SECCAT_SRODATA
:
5256 return data_section
;
5257 case SECCAT_DATA_REL
:
5258 sname
= ".data.rel";
5260 case SECCAT_DATA_REL_LOCAL
:
5261 sname
= ".data.rel.local";
5263 case SECCAT_DATA_REL_RO
:
5264 sname
= ".data.rel.ro";
5266 case SECCAT_DATA_REL_RO_LOCAL
:
5267 sname
= ".data.rel.ro.local";
5292 return get_named_section (decl
, sname
, reloc
);
5295 /* Construct a unique section name based on the decl name and the
5296 categorization performed above. */
5299 default_unique_section (tree decl
, int reloc
)
5301 default_unique_section_1 (decl
, reloc
, flag_pic
);
5305 default_unique_section_1 (tree decl
, int reloc
, int shlib
)
5307 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
5308 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
5309 const char *prefix
, *name
;
5313 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5316 prefix
= one_only
? ".gnu.linkonce.t." : ".text.";
5319 case SECCAT_RODATA_MERGE_STR
:
5320 case SECCAT_RODATA_MERGE_STR_INIT
:
5321 case SECCAT_RODATA_MERGE_CONST
:
5322 prefix
= one_only
? ".gnu.linkonce.r." : ".rodata.";
5324 case SECCAT_SRODATA
:
5325 prefix
= one_only
? ".gnu.linkonce.s2." : ".sdata2.";
5328 case SECCAT_DATA_REL
:
5329 case SECCAT_DATA_REL_LOCAL
:
5330 case SECCAT_DATA_REL_RO
:
5331 case SECCAT_DATA_REL_RO_LOCAL
:
5332 prefix
= one_only
? ".gnu.linkonce.d." : ".data.";
5335 prefix
= one_only
? ".gnu.linkonce.s." : ".sdata.";
5338 prefix
= one_only
? ".gnu.linkonce.b." : ".bss.";
5341 prefix
= one_only
? ".gnu.linkonce.sb." : ".sbss.";
5344 prefix
= one_only
? ".gnu.linkonce.td." : ".tdata.";
5347 prefix
= one_only
? ".gnu.linkonce.tb." : ".tbss.";
5352 plen
= strlen (prefix
);
5354 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5355 name
= targetm
.strip_name_encoding (name
);
5356 nlen
= strlen (name
);
5358 string
= alloca (nlen
+ plen
+ 1);
5359 memcpy (string
, prefix
, plen
);
5360 memcpy (string
+ plen
, name
, nlen
+ 1);
5362 DECL_SECTION_NAME (decl
) = build_string (nlen
+ plen
, string
);
5366 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
5368 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
5371 switch (GET_CODE (x
))
5376 return data_section
;
5382 return readonly_data_section
;
5386 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
5387 unsigned HOST_WIDE_INT align
)
5389 /* ??? Handle small data here somehow. */
5392 switch (GET_CODE (x
))
5396 return get_named_section (NULL
, ".data.rel.ro", 3);
5399 return get_named_section (NULL
, ".data.rel.ro.local", 1);
5405 return mergeable_constant_section (mode
, align
, 0);
5408 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5411 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
5416 /* Careful not to prod global register variables. */
5419 symbol
= XEXP (rtl
, 0);
5420 if (GET_CODE (symbol
) != SYMBOL_REF
)
5424 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5425 flags
|= SYMBOL_FLAG_FUNCTION
;
5426 if (targetm
.binds_local_p (decl
))
5427 flags
|= SYMBOL_FLAG_LOCAL
;
5428 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
5429 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
5430 else if (targetm
.in_small_data_p (decl
))
5431 flags
|= SYMBOL_FLAG_SMALL
;
5432 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5433 being PUBLIC, the thing *must* be defined in this translation unit.
5434 Prevent this buglet from being propagated into rtl code as well. */
5435 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
5436 flags
|= SYMBOL_FLAG_EXTERNAL
;
5438 SYMBOL_REF_FLAGS (symbol
) = flags
;
5441 /* By default, we do nothing for encode_section_info, so we need not
5442 do anything but discard the '*' marker. */
5445 default_strip_name_encoding (const char *str
)
5447 return str
+ (*str
== '*');
5450 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5451 wrt cross-module name binding. */
5454 default_binds_local_p (tree exp
)
5456 return default_binds_local_p_1 (exp
, flag_shlib
);
5460 default_binds_local_p_1 (tree exp
, int shlib
)
5464 /* A non-decl is an entry in the constant pool. */
5467 /* Weakrefs may not bind locally, even though the weakref itself is
5468 always static and therefore local. */
5469 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
5471 /* Static variables are always local. */
5472 else if (! TREE_PUBLIC (exp
))
5474 /* A variable is local if the user has said explicitly that it will
5476 else if (DECL_VISIBILITY_SPECIFIED (exp
)
5477 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
5479 /* Variables defined outside this object might not be local. */
5480 else if (DECL_EXTERNAL (exp
))
5482 /* If defined in this object and visibility is not default, must be
5484 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
5486 /* Default visibility weak data can be overridden by a strong symbol
5487 in another module and so are not local. */
5488 else if (DECL_WEAK (exp
))
5490 /* If PIC, then assume that any global name can be overridden by
5491 symbols resolved from other modules. */
5494 /* Uninitialized COMMON variable may be unified with symbols
5495 resolved from other modules. */
5496 else if (DECL_COMMON (exp
)
5497 && (DECL_INITIAL (exp
) == NULL
5498 || DECL_INITIAL (exp
) == error_mark_node
))
5500 /* Otherwise we're left with initialized (or non-common) global data
5501 which is of necessity defined locally. */
5508 /* Determine whether or not a pointer mode is valid. Assume defaults
5509 of ptr_mode or Pmode - can be overridden. */
5511 default_valid_pointer_mode (enum machine_mode mode
)
5513 return (mode
== ptr_mode
|| mode
== Pmode
);
5516 /* Default function to output code that will globalize a label. A
5517 target must define GLOBAL_ASM_OP or provide its own function to
5518 globalize a label. */
5519 #ifdef GLOBAL_ASM_OP
5521 default_globalize_label (FILE * stream
, const char *name
)
5523 fputs (GLOBAL_ASM_OP
, stream
);
5524 assemble_name (stream
, name
);
5525 putc ('\n', stream
);
5527 #endif /* GLOBAL_ASM_OP */
5529 /* Default function to output a label for unwind information. The
5530 default is to do nothing. A target that needs nonlocal labels for
5531 unwind information must provide its own function to do this. */
5533 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
5534 tree decl ATTRIBUTE_UNUSED
,
5535 int for_eh ATTRIBUTE_UNUSED
,
5536 int empty ATTRIBUTE_UNUSED
)
5540 /* This is how to output an internal numbered label where PREFIX is
5541 the class of label and LABELNO is the number within the class. */
5544 default_internal_label (FILE *stream
, const char *prefix
,
5545 unsigned long labelno
)
5547 char *const buf
= alloca (40 + strlen (prefix
));
5548 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
5549 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
5552 /* This is the default behavior at the beginning of a file. It's
5553 controlled by two other target-hook toggles. */
5555 default_file_start (void)
5557 if (targetm
.file_start_app_off
&& !flag_verbose_asm
)
5558 fputs (ASM_APP_OFF
, asm_out_file
);
5560 if (targetm
.file_start_file_directive
)
5561 output_file_directive (asm_out_file
, main_input_filename
);
5564 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5565 which emits a special section directive used to indicate whether or
5566 not this object file needs an executable stack. This is primarily
5567 a GNU extension to ELF but could be used on other targets. */
5569 int trampolines_created
;
5572 file_end_indicate_exec_stack (void)
5574 unsigned int flags
= SECTION_DEBUG
;
5575 if (trampolines_created
)
5576 flags
|= SECTION_CODE
;
5578 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
5581 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
5582 a get_unnamed_section callback. */
5585 output_section_asm_op (const void *directive
)
5587 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
5590 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
5591 the current section is NEW_SECTION. */
5594 switch_to_section (section
*new_section
)
5596 if (in_section
== new_section
)
5599 if (new_section
->common
.flags
& SECTION_FORGET
)
5603 in_section
= new_section
;
5604 if (new_section
->common
.flags
& SECTION_CODE
)
5605 last_text_section
= in_section
;
5608 if (new_section
->common
.flags
& SECTION_NAMED
)
5611 && !cfun
->unlikely_text_section_name
5612 && strcmp (new_section
->named
.name
,
5613 UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
5614 cfun
->unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
5616 targetm
.asm_out
.named_section (new_section
->named
.name
,
5617 new_section
->named
.common
.flags
,
5618 new_section
->named
.decl
);
5621 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
5623 new_section
->common
.flags
|= SECTION_DECLARED
;
5626 #include "gt-varasm.h"