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
;
156 /* The section that holds the main exception table, when known. The section
157 is set either by the target's init_sections hook or by the first call to
158 switch_to_exception_section. */
159 section
*exception_section
;
161 /* The section that holds the DWARF2 frame unwind information, when known.
162 The section is set either by the target's init_sections hook or by the
163 first call to switch_to_eh_frame_section. */
164 section
*eh_frame_section
;
166 /* asm_out_file's current section. This is NULL if no section has yet
167 been selected or if we lose track of what the current section is. */
170 /* 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
);
233 flags
|= SECTION_NAMED
;
236 sect
= ggc_alloc (sizeof (struct named_section
));
237 sect
->named
.common
.flags
= flags
;
238 sect
->named
.name
= ggc_strdup (name
);
239 sect
->named
.decl
= decl
;
245 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
246 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
248 /* Sanity check user variables for flag changes. */
250 decl
= sect
->named
.decl
;
252 error ("%+D causes a section type conflict", decl
);
261 initialize_cold_section_name (void)
263 const char *stripped_name
;
267 gcc_assert (cfun
&& current_function_decl
);
268 if (cfun
->unlikely_text_section_name
)
271 dsn
= DECL_SECTION_NAME (current_function_decl
);
272 if (flag_function_sections
&& dsn
)
274 name
= alloca (TREE_STRING_LENGTH (dsn
) + 1);
275 memcpy (name
, TREE_STRING_POINTER (dsn
), TREE_STRING_LENGTH (dsn
) + 1);
277 stripped_name
= targetm
.strip_name_encoding (name
);
279 buffer
= ACONCAT ((stripped_name
, "_unlikely", NULL
));
280 cfun
->unlikely_text_section_name
= ggc_strdup (buffer
);
283 cfun
->unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
286 /* Tell assembler to switch to unlikely-to-be-executed text section. */
289 unlikely_text_section (void)
293 if (!cfun
->unlikely_text_section_name
)
294 initialize_cold_section_name ();
296 return get_named_section (NULL
, cfun
->unlikely_text_section_name
, 0);
299 return get_named_section (NULL
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
, 0);
302 /* When called within a function context, return true if the function
303 has been assigned a cold text section and if SECT is that section.
304 When called outside a function context, return true if SECT is the
305 default cold section. */
308 unlikely_text_section_p (section
*sect
)
313 name
= cfun
->unlikely_text_section_name
;
315 name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
319 && (sect
->common
.flags
& SECTION_NAMED
) != 0
320 && strcmp (name
, sect
->named
.name
) == 0);
323 /* Return a section with a particular name and with whatever SECTION_*
324 flags section_type_flags deems appropriate. The name of the section
325 is taken from NAME if nonnull, otherwise it is taken from DECL's
326 DECL_SECTION_NAME. DECL is the decl associated with the section
327 (see the section comment for details) and RELOC is as for
328 section_type_flags. */
331 get_named_section (tree decl
, const char *name
, int reloc
)
335 gcc_assert (!decl
|| DECL_P (decl
));
337 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
339 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
341 return get_section (name
, flags
, decl
);
344 /* If required, set DECL_SECTION_NAME to a unique name. */
347 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
348 int flag_function_or_data_sections
)
350 if (DECL_SECTION_NAME (decl
) == NULL_TREE
351 && targetm
.have_named_sections
352 && (flag_function_or_data_sections
353 || DECL_ONE_ONLY (decl
)))
354 targetm
.asm_out
.unique_section (decl
, reloc
);
357 #ifdef BSS_SECTION_ASM_OP
359 #ifdef ASM_OUTPUT_BSS
361 /* Utility function for ASM_OUTPUT_BSS for targets to use if
362 they don't support alignments in .bss.
363 ??? It is believed that this function will work in most cases so such
364 support is localized here. */
367 asm_output_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
369 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
370 unsigned HOST_WIDE_INT rounded
)
372 targetm
.asm_out
.globalize_label (file
, name
);
373 switch_to_section (bss_section
);
374 #ifdef ASM_DECLARE_OBJECT_NAME
375 last_assemble_variable_decl
= decl
;
376 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
378 /* Standard thing is just output label for the object. */
379 ASM_OUTPUT_LABEL (file
, name
);
380 #endif /* ASM_DECLARE_OBJECT_NAME */
381 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
386 #ifdef ASM_OUTPUT_ALIGNED_BSS
388 /* Utility function for targets to use in implementing
389 ASM_OUTPUT_ALIGNED_BSS.
390 ??? It is believed that this function will work in most cases so such
391 support is localized here. */
394 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
395 const char *name
, unsigned HOST_WIDE_INT size
,
398 switch_to_section (bss_section
);
399 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
400 #ifdef ASM_DECLARE_OBJECT_NAME
401 last_assemble_variable_decl
= decl
;
402 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
404 /* Standard thing is just output label for the object. */
405 ASM_OUTPUT_LABEL (file
, name
);
406 #endif /* ASM_DECLARE_OBJECT_NAME */
407 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
412 #endif /* BSS_SECTION_ASM_OP */
414 /* Return the section for function DECL.
416 If DECL is NULL_TREE, return the text section. We can be passed
417 NULL_TREE under some circumstances by dbxout.c at least. */
420 function_section (tree decl
)
424 if (first_function_block_is_cold
)
427 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
428 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
430 if (decl
!= NULL_TREE
431 && DECL_SECTION_NAME (decl
) != NULL_TREE
432 && targetm
.have_named_sections
)
433 return get_named_section (decl
, NULL
, 0);
440 current_function_section (void)
442 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
445 if (unlikely_text_section_p (last_text_section
))
448 return targetm
.asm_out
.select_section (current_function_decl
, reloc
,
449 DECL_ALIGN (current_function_decl
));
451 if (last_text_section
)
452 return last_text_section
;
453 return function_section (current_function_decl
);
457 /* Return the read-only data section associated with function DECL. */
460 default_function_rodata_section (tree decl
)
462 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
464 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
466 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
468 size_t len
= strlen (name
) + 3;
469 char* rname
= alloca (len
);
471 strcpy (rname
, ".rodata");
472 strcat (rname
, name
+ 5);
473 return get_section (rname
, SECTION_LINKONCE
, decl
);
475 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
476 else if (DECL_ONE_ONLY (decl
)
477 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
479 size_t len
= strlen (name
) + 1;
480 char *rname
= alloca (len
);
482 memcpy (rname
, name
, len
);
484 return get_section (rname
, SECTION_LINKONCE
, decl
);
486 /* For .text.foo we want to use .rodata.foo. */
487 else if (flag_function_sections
&& flag_data_sections
488 && strncmp (name
, ".text.", 6) == 0)
490 size_t len
= strlen (name
) + 1;
491 char *rname
= alloca (len
+ 2);
493 memcpy (rname
, ".rodata", 7);
494 memcpy (rname
+ 7, name
+ 5, len
- 5);
495 return get_section (rname
, 0, decl
);
499 return readonly_data_section
;
502 /* Return the read-only data section associated with function DECL
503 for targets where that section should be always the single
504 readonly data section. */
507 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
509 return readonly_data_section
;
512 /* Switch to section for variable DECL. RELOC is the same as the
513 argument to SELECT_SECTION. */
516 variable_section (tree decl
, int reloc
)
518 if (IN_NAMED_SECTION (decl
))
519 switch_to_section (get_named_section (decl
, NULL
, reloc
));
521 switch_to_section (targetm
.asm_out
.select_section (decl
, reloc
,
525 /* Return the section to use for string merging. */
528 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
529 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
530 unsigned int flags ATTRIBUTE_UNUSED
)
532 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
533 && TREE_CODE (decl
) == STRING_CST
534 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
536 && TREE_STRING_LENGTH (decl
) >= int_size_in_bytes (TREE_TYPE (decl
)))
538 enum machine_mode mode
;
539 unsigned int modesize
;
544 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
545 modesize
= GET_MODE_BITSIZE (mode
);
546 if (modesize
>= 8 && modesize
<= 256
547 && (modesize
& (modesize
- 1)) == 0)
549 if (align
< modesize
)
552 str
= TREE_STRING_POINTER (decl
);
553 len
= TREE_STRING_LENGTH (decl
);
554 unit
= GET_MODE_SIZE (mode
);
556 /* Check for embedded NUL characters. */
557 for (i
= 0; i
< len
; i
+= unit
)
559 for (j
= 0; j
< unit
; j
++)
560 if (str
[i
+ j
] != '\0')
567 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
569 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
570 return get_section (name
, flags
, NULL
);
575 return readonly_data_section
;
578 /* Return the section to use for constant merging. */
581 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
582 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
583 unsigned int flags ATTRIBUTE_UNUSED
)
585 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
587 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
593 && (align
& (align
- 1)) == 0)
597 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
598 flags
|= (align
/ 8) | SECTION_MERGE
;
599 return get_section (name
, flags
, NULL
);
601 return readonly_data_section
;
604 /* Given NAME, a putative register name, discard any customary prefixes. */
607 strip_reg_name (const char *name
)
609 #ifdef REGISTER_PREFIX
610 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
611 name
+= strlen (REGISTER_PREFIX
);
613 if (name
[0] == '%' || name
[0] == '#')
618 /* The user has asked for a DECL to have a particular name. Set (or
619 change) it in such a way that we don't prefix an underscore to
622 set_user_assembler_name (tree decl
, const char *name
)
624 char *starred
= alloca (strlen (name
) + 2);
626 strcpy (starred
+ 1, name
);
627 change_decl_assembler_name (decl
, get_identifier (starred
));
628 SET_DECL_RTL (decl
, NULL_RTX
);
631 /* Decode an `asm' spec for a declaration as a register name.
632 Return the register number, or -1 if nothing specified,
633 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
634 or -3 if ASMSPEC is `cc' and is not recognized,
635 or -4 if ASMSPEC is `memory' and is not recognized.
636 Accept an exact spelling or a decimal number.
637 Prefixes such as % are optional. */
640 decode_reg_name (const char *asmspec
)
646 /* Get rid of confusing prefixes. */
647 asmspec
= strip_reg_name (asmspec
);
649 /* Allow a decimal number as a "register name". */
650 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
651 if (! ISDIGIT (asmspec
[i
]))
653 if (asmspec
[0] != 0 && i
< 0)
656 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
662 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
664 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
667 #ifdef ADDITIONAL_REGISTER_NAMES
669 static const struct { const char *const name
; const int number
; } table
[]
670 = ADDITIONAL_REGISTER_NAMES
;
672 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
674 && ! strcmp (asmspec
, table
[i
].name
))
675 return table
[i
].number
;
677 #endif /* ADDITIONAL_REGISTER_NAMES */
679 if (!strcmp (asmspec
, "memory"))
682 if (!strcmp (asmspec
, "cc"))
691 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
692 have static storage duration. In other words, it should not be an
693 automatic variable, including PARM_DECLs.
695 There is, however, one exception: this function handles variables
696 explicitly placed in a particular register by the user.
698 This is never called for PARM_DECL nodes. */
701 make_decl_rtl (tree decl
)
703 const char *name
= 0;
707 /* Check that we are not being given an automatic variable. */
708 gcc_assert (TREE_CODE (decl
) != PARM_DECL
709 && TREE_CODE (decl
) != RESULT_DECL
);
711 /* A weak alias has TREE_PUBLIC set but not the other bits. */
712 gcc_assert (TREE_CODE (decl
) != VAR_DECL
713 || TREE_STATIC (decl
)
714 || TREE_PUBLIC (decl
)
715 || DECL_EXTERNAL (decl
)
716 || DECL_REGISTER (decl
));
718 /* And that we were not given a type or a label. */
719 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
720 && TREE_CODE (decl
) != LABEL_DECL
);
722 /* For a duplicate declaration, we can be called twice on the
723 same DECL node. Don't discard the RTL already made. */
724 if (DECL_RTL_SET_P (decl
))
726 /* If the old RTL had the wrong mode, fix the mode. */
727 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
728 SET_DECL_RTL (decl
, adjust_address_nv (DECL_RTL (decl
),
729 DECL_MODE (decl
), 0));
731 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
734 /* ??? Another way to do this would be to maintain a hashed
735 table of such critters. Instead of adding stuff to a DECL
736 to give certain attributes to it, we could use an external
737 hash map from DECL to set of attributes. */
739 /* Let the target reassign the RTL if it wants.
740 This is necessary, for example, when one machine specific
741 decl attribute overrides another. */
742 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
744 /* Make this function static known to the mudflap runtime. */
745 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
746 mudflap_enqueue_decl (decl
);
751 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
753 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
754 && DECL_REGISTER (decl
))
756 error ("register name not specified for %q+D", decl
);
758 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
760 const char *asmspec
= name
+1;
761 reg_number
= decode_reg_name (asmspec
);
762 /* First detect errors in declaring global registers. */
763 if (reg_number
== -1)
764 error ("register name not specified for %q+D", decl
);
765 else if (reg_number
< 0)
766 error ("invalid register name for %q+D", decl
);
767 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
768 error ("data type of %q+D isn%'t suitable for a register",
770 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
771 error ("register specified for %q+D isn%'t suitable for data type",
773 /* Now handle properly declared static register variables. */
778 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
780 DECL_INITIAL (decl
) = 0;
781 error ("global register variable has initial value");
783 if (TREE_THIS_VOLATILE (decl
))
784 warning (OPT_Wvolatile_register_var
,
785 "optimization may eliminate reads and/or "
786 "writes to register variables");
788 /* If the user specified one of the eliminables registers here,
789 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
790 confused with that register and be eliminated. This usage is
791 somewhat suspect... */
793 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
794 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
795 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
797 if (TREE_STATIC (decl
))
799 /* Make this register global, so not usable for anything
801 #ifdef ASM_DECLARE_REGISTER_GLOBAL
802 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
803 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
805 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
807 globalize_reg (reg_number
+ --nregs
);
810 /* As a register variable, it has no section. */
814 /* Now handle ordinary static variables and functions (in memory).
815 Also handle vars declared register invalidly. */
816 else if (name
[0] == '*')
818 #ifdef REGISTER_PREFIX
819 if (strlen (REGISTER_PREFIX
) != 0)
821 reg_number
= decode_reg_name (name
);
822 if (reg_number
>= 0 || reg_number
== -3)
823 error ("register name given for non-register variable %q+D", decl
);
828 /* Specifying a section attribute on a variable forces it into a
829 non-.bss section, and thus it cannot be common. */
830 if (TREE_CODE (decl
) == VAR_DECL
831 && DECL_SECTION_NAME (decl
) != NULL_TREE
832 && DECL_INITIAL (decl
) == NULL_TREE
833 && DECL_COMMON (decl
))
834 DECL_COMMON (decl
) = 0;
836 /* Variables can't be both common and weak. */
837 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
838 DECL_COMMON (decl
) = 0;
840 x
= gen_rtx_SYMBOL_REF (Pmode
, name
);
841 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
842 SYMBOL_REF_DECL (x
) = decl
;
844 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
845 if (TREE_CODE (decl
) != FUNCTION_DECL
)
846 set_mem_attributes (x
, decl
, 1);
847 SET_DECL_RTL (decl
, x
);
849 /* Optionally set flags or add text to the name to record information
850 such as that it is a function name.
851 If the name is changed, the macro ASM_OUTPUT_LABELREF
852 will have to know how to strip this information. */
853 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
855 /* Make this function static known to the mudflap runtime. */
856 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
857 mudflap_enqueue_decl (decl
);
860 /* Make the rtl for variable VAR be volatile.
861 Use this only for static variables. */
864 make_var_volatile (tree var
)
866 gcc_assert (MEM_P (DECL_RTL (var
)));
868 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
871 /* Output a string of literal assembler code
872 for an `asm' keyword used between functions. */
875 assemble_asm (tree string
)
879 if (TREE_CODE (string
) == ADDR_EXPR
)
880 string
= TREE_OPERAND (string
, 0);
882 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
885 /* Record an element in the table of global destructors. SYMBOL is
886 a SYMBOL_REF of the function to be called; PRIORITY is a number
887 between 0 and MAX_INIT_PRIORITY. */
890 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
891 int priority ATTRIBUTE_UNUSED
)
893 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
894 /* Tell GNU LD that this is part of the static destructor set.
895 This will work for any system that uses stabs, most usefully
897 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
898 dbxout_stab_value_label (XSTR (symbol
, 0));
900 sorry ("global destructors not supported on this target");
905 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
907 const char *section
= ".dtors";
910 /* ??? This only works reliably with the GNU linker. */
911 if (priority
!= DEFAULT_INIT_PRIORITY
)
913 sprintf (buf
, ".dtors.%.5u",
914 /* Invert the numbering so the linker puts us in the proper
915 order; constructors are run from right to left, and the
916 linker sorts in increasing order. */
917 MAX_INIT_PRIORITY
- priority
);
921 switch_to_section (get_section (section
, SECTION_WRITE
, NULL
));
922 assemble_align (POINTER_SIZE
);
923 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
926 #ifdef DTORS_SECTION_ASM_OP
928 default_dtor_section_asm_out_destructor (rtx symbol
,
929 int priority ATTRIBUTE_UNUSED
)
931 switch_to_section (dtors_section
);
932 assemble_align (POINTER_SIZE
);
933 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
937 /* Likewise for global constructors. */
940 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
941 int priority ATTRIBUTE_UNUSED
)
943 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
944 /* Tell GNU LD that this is part of the static destructor set.
945 This will work for any system that uses stabs, most usefully
947 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
948 dbxout_stab_value_label (XSTR (symbol
, 0));
950 sorry ("global constructors not supported on this target");
955 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
957 const char *section
= ".ctors";
960 /* ??? This only works reliably with the GNU linker. */
961 if (priority
!= DEFAULT_INIT_PRIORITY
)
963 sprintf (buf
, ".ctors.%.5u",
964 /* Invert the numbering so the linker puts us in the proper
965 order; constructors are run from right to left, and the
966 linker sorts in increasing order. */
967 MAX_INIT_PRIORITY
- priority
);
971 switch_to_section (get_section (section
, SECTION_WRITE
, NULL
));
972 assemble_align (POINTER_SIZE
);
973 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
976 #ifdef CTORS_SECTION_ASM_OP
978 default_ctor_section_asm_out_constructor (rtx symbol
,
979 int priority ATTRIBUTE_UNUSED
)
981 switch_to_section (ctors_section
);
982 assemble_align (POINTER_SIZE
);
983 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
987 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
988 a nonzero value if the constant pool should be output before the
989 start of the function, or a zero value if the pool should output
990 after the end of the function. The default is to put it before the
993 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
994 #define CONSTANT_POOL_BEFORE_FUNCTION 1
997 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
998 to be output to assembler.
999 Set first_global_object_name and weak_global_object_name as appropriate. */
1002 notice_global_symbol (tree decl
)
1004 const char **type
= &first_global_object_name
;
1006 if (first_global_object_name
1007 || !TREE_PUBLIC (decl
) || DECL_EXTERNAL (decl
)
1008 || !DECL_NAME (decl
)
1009 || (TREE_CODE (decl
) != FUNCTION_DECL
1010 && (TREE_CODE (decl
) != VAR_DECL
1011 || (DECL_COMMON (decl
)
1012 && (DECL_INITIAL (decl
) == 0
1013 || DECL_INITIAL (decl
) == error_mark_node
))))
1014 || !MEM_P (DECL_RTL (decl
)))
1017 /* We win when global object is found, but it is useful to know about weak
1018 symbol as well so we can produce nicer unique names. */
1019 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
))
1020 type
= &weak_global_object_name
;
1026 rtx decl_rtl
= DECL_RTL (decl
);
1028 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1029 name
= ggc_strdup (p
);
1035 /* Output assembler code for the constant pool of a function and associated
1036 with defining the name of the function. DECL describes the function.
1037 NAME is the function's name. For the constant pool, we use the current
1038 constant pool data. */
1041 assemble_start_function (tree decl
, const char *fnname
)
1044 char tmp_label
[100];
1045 bool hot_label_written
= false;
1047 cfun
->unlikely_text_section_name
= NULL
;
1049 first_function_block_is_cold
= false;
1050 if (flag_reorder_blocks_and_partition
)
1052 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1053 cfun
->hot_section_label
= ggc_strdup (tmp_label
);
1054 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1055 cfun
->cold_section_label
= ggc_strdup (tmp_label
);
1056 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1057 cfun
->hot_section_end_label
= ggc_strdup (tmp_label
);
1058 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1059 cfun
->cold_section_end_label
= ggc_strdup (tmp_label
);
1064 cfun
->hot_section_label
= NULL
;
1065 cfun
->cold_section_label
= NULL
;
1066 cfun
->hot_section_end_label
= NULL
;
1067 cfun
->cold_section_end_label
= NULL
;
1070 /* The following code does not need preprocessing in the assembler. */
1074 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1075 output_constant_pool (fnname
, decl
);
1077 resolve_unique_section (decl
, 0, flag_function_sections
);
1079 /* Make sure the not and cold text (code) sections are properly
1080 aligned. This is necessary here in the case where the function
1081 has both hot and cold sections, because we don't want to re-set
1082 the alignment when the section switch happens mid-function. */
1084 if (flag_reorder_blocks_and_partition
)
1086 unlikely_text_section ();
1087 assemble_align (FUNCTION_BOUNDARY
);
1088 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->cold_section_label
);
1090 /* When the function starts with a cold section, we need to explicitly
1091 align the hot section and write out the hot section label.
1092 But if the current function is a thunk, we do not have a CFG. */
1093 if (!current_function_is_thunk
1094 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1096 switch_to_section (text_section
);
1097 assemble_align (FUNCTION_BOUNDARY
);
1098 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->hot_section_label
);
1099 hot_label_written
= true;
1100 first_function_block_is_cold
= true;
1103 else if (DECL_SECTION_NAME (decl
))
1105 /* Calls to function_section rely on first_function_block_is_cold
1106 being accurate. The first block may be cold even if we aren't
1107 doing partitioning, if the entire function was decided by
1108 choose_function_section (predict.c) to be cold. */
1110 initialize_cold_section_name ();
1112 if (cfun
->unlikely_text_section_name
1113 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
1114 cfun
->unlikely_text_section_name
) == 0)
1115 first_function_block_is_cold
= true;
1118 last_text_section
= NULL
;
1120 /* Switch to the correct text section for the start of the function. */
1122 switch_to_section (function_section (decl
));
1123 if (flag_reorder_blocks_and_partition
1124 && !hot_label_written
)
1125 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->hot_section_label
);
1127 /* Tell assembler to move to target machine's alignment for functions. */
1128 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1129 if (align
< force_align_functions_log
)
1130 align
= force_align_functions_log
;
1133 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1136 /* Handle a user-specified function alignment.
1137 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1138 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1139 if (align_functions_log
> align
1140 && cfun
->function_frequency
!= FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
)
1142 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1143 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1144 align_functions_log
, align_functions
- 1);
1146 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1150 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1151 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1154 (*debug_hooks
->begin_function
) (decl
);
1156 /* Make function name accessible from other files, if appropriate. */
1158 if (TREE_PUBLIC (decl
))
1160 notice_global_symbol (decl
);
1162 globalize_decl (decl
);
1164 maybe_assemble_visibility (decl
);
1167 if (DECL_PRESERVE_P (decl
))
1168 targetm
.asm_out
.mark_decl_preserved (fnname
);
1170 /* Do any machine/system dependent processing of the function name. */
1171 #ifdef ASM_DECLARE_FUNCTION_NAME
1172 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1174 /* Standard thing is just output label for the function. */
1175 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1176 #endif /* ASM_DECLARE_FUNCTION_NAME */
1179 /* Output assembler code associated with defining the size of the
1180 function. DECL describes the function. NAME is the function's name. */
1183 assemble_end_function (tree decl
, const char *fnname
)
1185 #ifdef ASM_DECLARE_FUNCTION_SIZE
1186 /* We could have switched section in the middle of the function. */
1187 if (flag_reorder_blocks_and_partition
)
1188 switch_to_section (function_section (decl
));
1189 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1191 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1193 output_constant_pool (fnname
, decl
);
1194 switch_to_section (function_section (decl
)); /* need to switch back */
1196 /* Output labels for end of hot/cold text sections (to be used by
1198 if (flag_reorder_blocks_and_partition
)
1200 section
*save_text_section
;
1202 save_text_section
= in_section
;
1203 unlikely_text_section ();
1204 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->cold_section_end_label
);
1205 if (first_function_block_is_cold
)
1206 switch_to_section (text_section
);
1208 switch_to_section (function_section (decl
));
1209 ASM_OUTPUT_LABEL (asm_out_file
, cfun
->hot_section_end_label
);
1210 switch_to_section (save_text_section
);
1214 /* Assemble code to leave SIZE bytes of zeros. */
1217 assemble_zeros (unsigned HOST_WIDE_INT size
)
1219 /* Do no output if -fsyntax-only. */
1220 if (flag_syntax_only
)
1223 #ifdef ASM_NO_SKIP_IN_TEXT
1224 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1225 so we must output 0s explicitly in the text section. */
1226 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1228 unsigned HOST_WIDE_INT i
;
1229 for (i
= 0; i
< size
; i
++)
1230 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1235 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1238 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1241 assemble_align (int align
)
1243 if (align
> BITS_PER_UNIT
)
1245 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1249 /* Assemble a string constant with the specified C string as contents. */
1252 assemble_string (const char *p
, int size
)
1257 /* If the string is very long, split it up. */
1261 int thissize
= size
- pos
;
1262 if (thissize
> maximum
)
1265 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1273 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1274 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1275 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1277 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1278 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1279 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1281 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1282 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1286 #if defined ASM_OUTPUT_ALIGNED_BSS
1287 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1288 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1290 #if defined ASM_OUTPUT_BSS
1291 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1292 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1298 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1299 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1300 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1302 #if defined ASM_OUTPUT_ALIGNED_COMMON
1303 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1304 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1306 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1307 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1312 asm_emit_uninitialised (tree decl
, const char *name
,
1313 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1314 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1322 destination
= asm_dest_local
;
1324 /* ??? We should handle .bss via select_section mechanisms rather than
1325 via special target hooks. That would eliminate this special case. */
1326 if (TREE_PUBLIC (decl
))
1328 if (!DECL_COMMON (decl
))
1330 destination
= asm_dest_bss
;
1335 destination
= asm_dest_common
;
1338 if (destination
!= asm_dest_common
)
1340 resolve_unique_section (decl
, 0, flag_data_sections
);
1341 /* Custom sections don't belong here. */
1342 if (DECL_SECTION_NAME (decl
))
1346 if (destination
== asm_dest_bss
)
1347 globalize_decl (decl
);
1349 if (flag_shared_data
)
1351 switch (destination
)
1353 #ifdef ASM_OUTPUT_SHARED_BSS
1355 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1358 #ifdef ASM_OUTPUT_SHARED_COMMON
1359 case asm_dest_common
:
1360 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1363 #ifdef ASM_OUTPUT_SHARED_LOCAL
1364 case asm_dest_local
:
1365 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1373 switch (destination
)
1377 ASM_EMIT_BSS (decl
, name
, size
, rounded
);
1380 case asm_dest_common
:
1381 ASM_EMIT_COMMON (decl
, name
, size
, rounded
);
1383 case asm_dest_local
:
1384 ASM_EMIT_LOCAL (decl
, name
, size
, rounded
);
1393 /* Assemble everything that is needed for a variable or function declaration.
1394 Not used for automatic variables, and not used for function definitions.
1395 Should not be called for variables of incomplete structure type.
1397 TOP_LEVEL is nonzero if this variable has file scope.
1398 AT_END is nonzero if this is the special handling, at end of compilation,
1399 to define things that have had only tentative definitions.
1400 DONT_OUTPUT_DATA if nonzero means don't actually output the
1401 initial value (that will be done by the caller). */
1404 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
1405 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
1412 if (lang_hooks
.decls
.prepare_assemble_variable
)
1413 lang_hooks
.decls
.prepare_assemble_variable (decl
);
1415 last_assemble_variable_decl
= 0;
1417 /* Normally no need to say anything here for external references,
1418 since assemble_external is called by the language-specific code
1419 when a declaration is first seen. */
1421 if (DECL_EXTERNAL (decl
))
1424 /* Output no assembler code for a function declaration.
1425 Only definitions of functions output anything. */
1427 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1430 /* Do nothing for global register variables. */
1431 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
1433 TREE_ASM_WRITTEN (decl
) = 1;
1437 /* If type was incomplete when the variable was declared,
1438 see if it is complete now. */
1440 if (DECL_SIZE (decl
) == 0)
1441 layout_decl (decl
, 0);
1443 /* Still incomplete => don't allocate it; treat the tentative defn
1444 (which is what it must have been) as an `extern' reference. */
1446 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1448 error ("storage size of %q+D isn%'t known", decl
);
1449 TREE_ASM_WRITTEN (decl
) = 1;
1453 /* The first declaration of a variable that comes through this function
1454 decides whether it is global (in C, has external linkage)
1455 or local (in C, has internal linkage). So do nothing more
1456 if this function has already run. */
1458 if (TREE_ASM_WRITTEN (decl
))
1461 /* Make sure targetm.encode_section_info is invoked before we set
1463 decl_rtl
= DECL_RTL (decl
);
1465 TREE_ASM_WRITTEN (decl
) = 1;
1467 /* Do no output if -fsyntax-only. */
1468 if (flag_syntax_only
)
1473 if (! dont_output_data
1474 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1476 error ("size of variable %q+D is too large", decl
);
1480 name
= XSTR (XEXP (decl_rtl
, 0), 0);
1481 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1482 notice_global_symbol (decl
);
1484 /* Compute the alignment of this data. */
1486 align
= DECL_ALIGN (decl
);
1488 /* In the case for initialing an array whose length isn't specified,
1489 where we have not yet been able to do the layout,
1490 figure out the proper alignment now. */
1491 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1492 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1493 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1495 /* Some object file formats have a maximum alignment which they support.
1496 In particular, a.out format supports a maximum alignment of 4. */
1497 if (align
> MAX_OFILE_ALIGNMENT
)
1499 warning (0, "alignment of %q+D is greater than maximum object "
1500 "file alignment. Using %d", decl
,
1501 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1502 align
= MAX_OFILE_ALIGNMENT
;
1505 /* On some machines, it is good to increase alignment sometimes. */
1506 if (! DECL_USER_ALIGN (decl
))
1508 #ifdef DATA_ALIGNMENT
1509 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1511 #ifdef CONSTANT_ALIGNMENT
1512 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1513 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1517 /* Reset the alignment in case we have made it tighter, so we can benefit
1518 from it in get_pointer_alignment. */
1519 DECL_ALIGN (decl
) = align
;
1520 set_mem_align (decl_rtl
, align
);
1522 if (TREE_PUBLIC (decl
))
1523 maybe_assemble_visibility (decl
);
1525 if (DECL_PRESERVE_P (decl
))
1526 targetm
.asm_out
.mark_decl_preserved (name
);
1528 /* Handle uninitialized definitions. */
1530 /* If the decl has been given an explicit section name, then it
1531 isn't common, and shouldn't be handled as such. */
1532 if (DECL_SECTION_NAME (decl
) || dont_output_data
)
1534 /* We don't implement common thread-local data at present. */
1535 else if (DECL_THREAD_LOCAL_P (decl
))
1537 if (DECL_COMMON (decl
))
1538 sorry ("thread-local COMMON data not implemented");
1540 else if (DECL_INITIAL (decl
) == 0
1541 || DECL_INITIAL (decl
) == error_mark_node
1542 || (flag_zero_initialized_in_bss
1543 /* Leave constant zeroes in .rodata so they can be shared. */
1544 && !TREE_READONLY (decl
)
1545 && initializer_zerop (DECL_INITIAL (decl
))))
1547 unsigned HOST_WIDE_INT size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1548 unsigned HOST_WIDE_INT rounded
= size
;
1550 /* Don't allocate zero bytes of common,
1551 since that means "undefined external" in the linker. */
1555 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1556 so that each uninitialized object starts on such a boundary. */
1557 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1558 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1559 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1561 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1562 if ((unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
1563 warning (0, "requested alignment for %q+D is greater than "
1564 "implemented alignment of %wu", decl
, rounded
);
1567 /* If the target cannot output uninitialized but not common global data
1568 in .bss, then we have to use .data, so fall through. */
1569 if (asm_emit_uninitialised (decl
, name
, size
, rounded
))
1573 /* Handle initialized definitions.
1574 Also handle uninitialized global definitions if -fno-common and the
1575 target doesn't support ASM_OUTPUT_BSS. */
1577 /* First make the assembler name(s) global if appropriate. */
1578 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1579 globalize_decl (decl
);
1581 /* Output any data that we will need to use the address of. */
1582 if (DECL_INITIAL (decl
) == error_mark_node
)
1583 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1584 else if (DECL_INITIAL (decl
))
1586 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1587 output_addressed_constants (DECL_INITIAL (decl
));
1590 /* Switch to the appropriate section. */
1591 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1592 variable_section (decl
, reloc
);
1594 /* dbxout.c needs to know this. */
1595 if (in_section
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1596 DECL_IN_TEXT_SECTION (decl
) = 1;
1598 /* Output the alignment of this data. */
1599 if (align
> BITS_PER_UNIT
)
1600 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
1602 /* Do any machine/system dependent processing of the object. */
1603 #ifdef ASM_DECLARE_OBJECT_NAME
1604 last_assemble_variable_decl
= decl
;
1605 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1607 /* Standard thing is just output label for the object. */
1608 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1609 #endif /* ASM_DECLARE_OBJECT_NAME */
1611 if (!dont_output_data
)
1613 if (DECL_INITIAL (decl
)
1614 && DECL_INITIAL (decl
) != error_mark_node
1615 && !initializer_zerop (DECL_INITIAL (decl
)))
1616 /* Output the actual data. */
1617 output_constant (DECL_INITIAL (decl
),
1618 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1621 /* Leave space for it. */
1622 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1626 /* Return 1 if type TYPE contains any pointers. */
1629 contains_pointers_p (tree type
)
1631 switch (TREE_CODE (type
))
1634 case REFERENCE_TYPE
:
1635 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1636 so I'll play safe and return 1. */
1642 case QUAL_UNION_TYPE
:
1645 /* For a type that has fields, see if the fields have pointers. */
1646 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1647 if (TREE_CODE (fields
) == FIELD_DECL
1648 && contains_pointers_p (TREE_TYPE (fields
)))
1654 /* An array type contains pointers if its element type does. */
1655 return contains_pointers_p (TREE_TYPE (type
));
1662 /* In unit-at-a-time mode, we delay assemble_external processing until
1663 the compilation unit is finalized. This is the best we can do for
1664 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
1665 it all the way to final. See PR 17982 for further discussion. */
1666 static GTY(()) tree pending_assemble_externals
;
1668 #ifdef ASM_OUTPUT_EXTERNAL
1669 /* True if DECL is a function decl for which no out-of-line copy exists.
1670 It is assumed that DECL's assembler name has been set. */
1673 incorporeal_function_p (tree decl
)
1675 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
1679 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
1680 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
1683 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1684 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
1690 /* Actually do the tests to determine if this is necessary, and invoke
1691 ASM_OUTPUT_EXTERNAL. */
1693 assemble_external_real (tree decl
)
1695 rtx rtl
= DECL_RTL (decl
);
1697 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1698 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
1699 && !incorporeal_function_p (decl
))
1701 /* Some systems do require some output. */
1702 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1703 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1709 process_pending_assemble_externals (void)
1711 #ifdef ASM_OUTPUT_EXTERNAL
1713 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
1714 assemble_external_real (TREE_VALUE (list
));
1716 pending_assemble_externals
= 0;
1720 /* Output something to declare an external symbol to the assembler.
1721 (Most assemblers don't need this, so we normally output nothing.)
1722 Do nothing if DECL is not external. */
1725 assemble_external (tree decl ATTRIBUTE_UNUSED
)
1727 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1728 main body of this code is only rarely exercised. To provide some
1729 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1730 open. If it's not, we should not be calling this function. */
1731 gcc_assert (asm_out_file
);
1733 #ifdef ASM_OUTPUT_EXTERNAL
1734 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
1737 if (flag_unit_at_a_time
)
1738 pending_assemble_externals
= tree_cons (0, decl
,
1739 pending_assemble_externals
);
1741 assemble_external_real (decl
);
1745 /* Similar, for calling a library function FUN. */
1748 assemble_external_libcall (rtx fun
)
1750 /* Declare library function name external when first used, if nec. */
1751 if (! SYMBOL_REF_USED (fun
))
1753 SYMBOL_REF_USED (fun
) = 1;
1754 targetm
.asm_out
.external_libcall (fun
);
1758 /* Assemble a label named NAME. */
1761 assemble_label (const char *name
)
1763 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1766 /* Set the symbol_referenced flag for ID. */
1768 mark_referenced (tree id
)
1770 TREE_SYMBOL_REFERENCED (id
) = 1;
1773 /* Set the symbol_referenced flag for DECL and notify callgraph. */
1775 mark_decl_referenced (tree decl
)
1777 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1779 /* Extern inline functions don't become needed when referenced.
1780 If we know a method will be emitted in other TU and no new
1781 functions can be marked reachable, just use the external
1783 struct cgraph_node
*node
= cgraph_node (decl
);
1784 if (!DECL_EXTERNAL (decl
)
1785 && (!node
->local
.vtable_method
|| !cgraph_global_info_ready
1786 || !node
->local
.finalized
))
1787 cgraph_mark_needed_node (node
);
1789 else if (TREE_CODE (decl
) == VAR_DECL
)
1791 struct cgraph_varpool_node
*node
= cgraph_varpool_node (decl
);
1792 cgraph_varpool_mark_needed_node (node
);
1793 /* C++ frontend use mark_decl_references to force COMDAT variables
1794 to be output that might appear dead otherwise. */
1795 node
->force_output
= true;
1797 /* else do nothing - we can get various sorts of CST nodes here,
1798 which do not need to be marked. */
1802 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1803 until we find an identifier that is not itself a transparent alias.
1804 Modify the alias passed to it by reference (and all aliases on the
1805 way to the ultimate target), such that they do not have to be
1806 followed again, and return the ultimate target of the alias
1810 ultimate_transparent_alias_target (tree
*alias
)
1812 tree target
= *alias
;
1814 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
1816 gcc_assert (TREE_CHAIN (target
));
1817 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
1818 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
1819 && ! TREE_CHAIN (target
));
1826 /* Output to FILE (an assembly file) a reference to NAME. If NAME
1827 starts with a *, the rest of NAME is output verbatim. Otherwise
1828 NAME is transformed in a target-specific way (usually by the
1829 addition of an underscore). */
1832 assemble_name_raw (FILE *file
, const char *name
)
1835 fputs (&name
[1], file
);
1837 ASM_OUTPUT_LABELREF (file
, name
);
1840 /* Like assemble_name_raw, but should be used when NAME might refer to
1841 an entity that is also represented as a tree (like a function or
1842 variable). If NAME does refer to such an entity, that entity will
1843 be marked as referenced. */
1846 assemble_name (FILE *file
, const char *name
)
1848 const char *real_name
;
1851 real_name
= targetm
.strip_name_encoding (name
);
1853 id
= maybe_get_identifier (real_name
);
1858 mark_referenced (id
);
1859 ultimate_transparent_alias_target (&id
);
1861 name
= IDENTIFIER_POINTER (id
);
1862 gcc_assert (! TREE_CHAIN (id
));
1865 assemble_name_raw (file
, name
);
1868 /* Allocate SIZE bytes writable static space with a gensym name
1869 and return an RTX to refer to its address. */
1872 assemble_static_space (unsigned HOST_WIDE_INT size
)
1875 const char *namestring
;
1879 if (flag_shared_data
)
1880 switch_to_section (data_section
);
1883 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1885 namestring
= ggc_strdup (name
);
1887 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1888 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
1890 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1891 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1894 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1895 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1898 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1899 so that each uninitialized object starts on such a boundary. */
1900 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1901 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1902 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1903 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1904 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1905 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1912 /* Assemble the static constant template for function entry trampolines.
1913 This is done at most once per compilation.
1914 Returns an RTX for the address of the template. */
1916 static GTY(()) rtx initial_trampoline
;
1918 #ifdef TRAMPOLINE_TEMPLATE
1920 assemble_trampoline_template (void)
1927 if (initial_trampoline
)
1928 return initial_trampoline
;
1930 /* By default, put trampoline templates in read-only data section. */
1932 #ifdef TRAMPOLINE_SECTION
1933 switch_to_section (TRAMPOLINE_SECTION
);
1935 switch_to_section (readonly_data_section
);
1938 /* Write the assembler code to define one. */
1939 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1942 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1945 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
1946 TRAMPOLINE_TEMPLATE (asm_out_file
);
1948 /* Record the rtl to refer to it. */
1949 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1950 name
= ggc_strdup (label
);
1951 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
1952 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
1954 initial_trampoline
= gen_rtx_MEM (BLKmode
, symbol
);
1955 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
1957 return initial_trampoline
;
1961 /* A and B are either alignments or offsets. Return the minimum alignment
1962 that may be assumed after adding the two together. */
1964 static inline unsigned
1965 min_align (unsigned int a
, unsigned int b
)
1967 return (a
| b
) & -(a
| b
);
1970 /* Return the assembler directive for creating a given kind of integer
1971 object. SIZE is the number of bytes in the object and ALIGNED_P
1972 indicates whether it is known to be aligned. Return NULL if the
1973 assembly dialect has no such directive.
1975 The returned string should be printed at the start of a new line and
1976 be followed immediately by the object's initial value. */
1979 integer_asm_op (int size
, int aligned_p
)
1981 struct asm_int_op
*ops
;
1984 ops
= &targetm
.asm_out
.aligned_op
;
1986 ops
= &targetm
.asm_out
.unaligned_op
;
1991 return targetm
.asm_out
.byte_op
;
2005 /* Use directive OP to assemble an integer object X. Print OP at the
2006 start of the line, followed immediately by the value of X. */
2009 assemble_integer_with_op (const char *op
, rtx x
)
2011 fputs (op
, asm_out_file
);
2012 output_addr_const (asm_out_file
, x
);
2013 fputc ('\n', asm_out_file
);
2016 /* The default implementation of the asm_out.integer target hook. */
2019 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2020 unsigned int size ATTRIBUTE_UNUSED
,
2021 int aligned_p ATTRIBUTE_UNUSED
)
2023 const char *op
= integer_asm_op (size
, aligned_p
);
2024 /* Avoid GAS bugs for large values. Specifically negative values whose
2025 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2026 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2028 return op
&& (assemble_integer_with_op (op
, x
), true);
2031 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2032 the alignment of the integer in bits. Return 1 if we were able to output
2033 the constant, otherwise 0. We must be able to output the constant,
2034 if FORCE is nonzero. */
2037 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2041 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2043 /* See if the target hook can handle this kind of object. */
2044 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2047 /* If the object is a multi-byte one, try splitting it up. Split
2048 it into words it if is multi-word, otherwise split it into bytes. */
2051 enum machine_mode omode
, imode
;
2052 unsigned int subalign
;
2053 unsigned int subsize
, i
;
2055 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2056 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2057 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, MODE_INT
, 0);
2058 imode
= mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
2060 for (i
= 0; i
< size
; i
+= subsize
)
2062 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2063 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2069 /* If we've printed some of it, but not all of it, there's no going
2074 gcc_assert (!force
);
2080 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2084 int bitsize
, nelts
, nunits
, units_per
;
2086 /* This is hairy. We have a quantity of known size. real_to_target
2087 will put it into an array of *host* longs, 32 bits per element
2088 (even if long is more than 32 bits). We need to determine the
2089 number of array elements that are occupied (nelts) and the number
2090 of *target* min-addressable units that will be occupied in the
2091 object file (nunits). We cannot assume that 32 divides the
2092 mode's bitsize (size * BITS_PER_UNIT) evenly.
2094 size * BITS_PER_UNIT is used here to make sure that padding bits
2095 (which might appear at either end of the value; real_to_target
2096 will include the padding bits in its output array) are included. */
2098 nunits
= GET_MODE_SIZE (mode
);
2099 bitsize
= nunits
* BITS_PER_UNIT
;
2100 nelts
= CEIL (bitsize
, 32);
2101 units_per
= 32 / BITS_PER_UNIT
;
2103 real_to_target (data
, &d
, mode
);
2105 /* Put out the first word with the specified alignment. */
2106 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2107 nunits
-= units_per
;
2109 /* Subsequent words need only 32-bit alignment. */
2110 align
= min_align (align
, 32);
2112 for (i
= 1; i
< nelts
; i
++)
2114 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2115 nunits
-= units_per
;
2119 /* Given an expression EXP with a constant value,
2120 reduce it to the sum of an assembler symbol and an integer.
2121 Store them both in the structure *VALUE.
2122 EXP must be reducible. */
2124 struct addr_const
GTY(())
2127 HOST_WIDE_INT offset
;
2131 decode_addr_const (tree exp
, struct addr_const
*value
)
2133 tree target
= TREE_OPERAND (exp
, 0);
2139 if (TREE_CODE (target
) == COMPONENT_REF
2140 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2143 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2144 target
= TREE_OPERAND (target
, 0);
2146 else if (TREE_CODE (target
) == ARRAY_REF
2147 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2149 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2150 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2151 target
= TREE_OPERAND (target
, 0);
2157 switch (TREE_CODE (target
))
2161 x
= DECL_RTL (target
);
2165 x
= gen_rtx_MEM (FUNCTION_MODE
,
2166 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2174 x
= output_constant_def (target
, 1);
2181 gcc_assert (MEM_P (x
));
2185 value
->offset
= offset
;
2188 /* Uniquize all constants that appear in memory.
2189 Each constant in memory thus far output is recorded
2190 in `const_desc_table'. */
2192 struct constant_descriptor_tree
GTY(())
2194 /* A MEM for the constant. */
2197 /* The value of the constant. */
2200 /* Hash of value. Computing the hash from value each time
2201 hashfn is called can't work properly, as that means recursive
2202 use of the hash table during hash table expansion. */
2206 static GTY((param_is (struct constant_descriptor_tree
)))
2207 htab_t const_desc_htab
;
2209 static struct constant_descriptor_tree
* build_constant_desc (tree
);
2210 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2212 /* Compute a hash code for a constant expression. */
2215 const_desc_hash (const void *ptr
)
2217 return ((struct constant_descriptor_tree
*)ptr
)->hash
;
2221 const_hash_1 (const tree exp
)
2226 enum tree_code code
= TREE_CODE (exp
);
2228 /* Either set P and LEN to the address and len of something to hash and
2229 exit the switch or return a value. */
2234 p
= (char *) &TREE_INT_CST (exp
);
2235 len
= sizeof TREE_INT_CST (exp
);
2239 return real_hash (TREE_REAL_CST_PTR (exp
));
2242 p
= TREE_STRING_POINTER (exp
);
2243 len
= TREE_STRING_LENGTH (exp
);
2247 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2248 + const_hash_1 (TREE_IMAGPART (exp
)));
2252 unsigned HOST_WIDE_INT idx
;
2255 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2257 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2259 hi
= hi
* 603 + const_hash_1 (value
);
2267 struct addr_const value
;
2269 decode_addr_const (exp
, &value
);
2270 switch (GET_CODE (value
.base
))
2273 /* Don't hash the address of the SYMBOL_REF;
2274 only use the offset and the symbol name. */
2276 p
= XSTR (value
.base
, 0);
2277 for (i
= 0; p
[i
] != 0; i
++)
2278 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2282 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2293 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2294 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2298 case NON_LVALUE_EXPR
:
2299 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2302 /* A language specific constant. Just hash the code. */
2306 /* Compute hashing function. */
2308 for (i
= 0; i
< len
; i
++)
2309 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2314 /* Wrapper of compare_constant, for the htab interface. */
2316 const_desc_eq (const void *p1
, const void *p2
)
2318 const struct constant_descriptor_tree
*c1
= p1
;
2319 const struct constant_descriptor_tree
*c2
= p2
;
2320 if (c1
->hash
!= c2
->hash
)
2322 return compare_constant (c1
->value
, c2
->value
);
2325 /* Compare t1 and t2, and return 1 only if they are known to result in
2326 the same bit pattern on output. */
2329 compare_constant (const tree t1
, const tree t2
)
2331 enum tree_code typecode
;
2333 if (t1
== NULL_TREE
)
2334 return t2
== NULL_TREE
;
2335 if (t2
== NULL_TREE
)
2338 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2341 switch (TREE_CODE (t1
))
2344 /* Integer constants are the same only if the same width of type. */
2345 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2347 return tree_int_cst_equal (t1
, t2
);
2350 /* Real constants are the same only if the same width of type. */
2351 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2354 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2357 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2360 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2361 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2362 TREE_STRING_LENGTH (t1
)));
2365 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2366 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2370 VEC(constructor_elt
, gc
) *v1
, *v2
;
2371 unsigned HOST_WIDE_INT idx
;
2373 typecode
= TREE_CODE (TREE_TYPE (t1
));
2374 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
2377 if (typecode
== ARRAY_TYPE
)
2379 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
2380 /* For arrays, check that the sizes all match. */
2381 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
2383 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
2388 /* For record and union constructors, require exact type
2390 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
2394 v1
= CONSTRUCTOR_ELTS (t1
);
2395 v2
= CONSTRUCTOR_ELTS (t2
);
2396 if (VEC_length (constructor_elt
, v1
)
2397 != VEC_length (constructor_elt
, v2
))
2400 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
2402 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
2403 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
2405 /* Check that each value is the same... */
2406 if (!compare_constant (c1
->value
, c2
->value
))
2408 /* ... and that they apply to the same fields! */
2409 if (typecode
== ARRAY_TYPE
)
2411 if (!compare_constant (c1
->index
, c2
->index
))
2416 if (c1
->index
!= c2
->index
)
2427 struct addr_const value1
, value2
;
2429 decode_addr_const (t1
, &value1
);
2430 decode_addr_const (t2
, &value2
);
2431 return (value1
.offset
== value2
.offset
2432 && strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
2438 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2439 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2443 case NON_LVALUE_EXPR
:
2444 case VIEW_CONVERT_EXPR
:
2445 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2450 nt1
= lang_hooks
.expand_constant (t1
);
2451 nt2
= lang_hooks
.expand_constant (t2
);
2452 if (nt1
!= t1
|| nt2
!= t2
)
2453 return compare_constant (nt1
, nt2
);
2462 /* Make a copy of the whole tree structure for a constant. This
2463 handles the same types of nodes that compare_constant handles. */
2466 copy_constant (tree exp
)
2468 switch (TREE_CODE (exp
))
2471 /* For ADDR_EXPR, we do not want to copy the decl whose address
2472 is requested. We do want to copy constants though. */
2473 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
2474 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2475 copy_constant (TREE_OPERAND (exp
, 0)));
2477 return copy_node (exp
);
2482 return copy_node (exp
);
2485 return build_complex (TREE_TYPE (exp
),
2486 copy_constant (TREE_REALPART (exp
)),
2487 copy_constant (TREE_IMAGPART (exp
)));
2491 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
2492 copy_constant (TREE_OPERAND (exp
, 0)),
2493 copy_constant (TREE_OPERAND (exp
, 1)));
2497 case NON_LVALUE_EXPR
:
2498 case VIEW_CONVERT_EXPR
:
2499 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2500 copy_constant (TREE_OPERAND (exp
, 0)));
2504 tree copy
= copy_node (exp
);
2505 VEC(constructor_elt
, gc
) *v
;
2506 unsigned HOST_WIDE_INT idx
;
2507 tree purpose
, value
;
2509 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
2510 CONSTRUCTOR_ELTS (exp
)));
2511 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
2513 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
2514 ce
->index
= purpose
;
2515 ce
->value
= copy_constant (value
);
2517 CONSTRUCTOR_ELTS (copy
) = v
;
2523 tree t
= lang_hooks
.expand_constant (exp
);
2525 gcc_assert (t
== exp
);
2526 return copy_constant (t
);
2531 /* Subroutine of output_constant_def:
2532 No constant equal to EXP is known to have been output.
2533 Make a constant descriptor to enter EXP in the hash table.
2534 Assign the label number and construct RTL to refer to the
2535 constant's location in memory.
2536 Caller is responsible for updating the hash table. */
2538 static struct constant_descriptor_tree
*
2539 build_constant_desc (tree exp
)
2545 struct constant_descriptor_tree
*desc
;
2547 desc
= ggc_alloc (sizeof (*desc
));
2548 desc
->value
= copy_constant (exp
);
2550 /* Propagate marked-ness to copied constant. */
2551 if (flag_mudflap
&& mf_marked_p (exp
))
2552 mf_mark (desc
->value
);
2554 /* Create a string containing the label name, in LABEL. */
2555 labelno
= const_labelno
++;
2556 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
2558 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2559 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
2560 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2561 SYMBOL_REF_DECL (symbol
) = desc
->value
;
2562 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
2564 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
2565 set_mem_attributes (rtl
, exp
, 1);
2566 set_mem_alias_set (rtl
, 0);
2567 set_mem_alias_set (rtl
, const_alias_set
);
2569 /* Set flags or add text to the name to record information, such as
2570 that it is a local symbol. If the name is changed, the macro
2571 ASM_OUTPUT_LABELREF will have to know how to strip this
2572 information. This call might invalidate our local variable
2573 SYMBOL; we can't use it afterward. */
2575 targetm
.encode_section_info (exp
, rtl
, true);
2582 /* Return an rtx representing a reference to constant data in memory
2583 for the constant expression EXP.
2585 If assembler code for such a constant has already been output,
2586 return an rtx to refer to it.
2587 Otherwise, output such a constant in memory
2588 and generate an rtx for it.
2590 If DEFER is nonzero, this constant can be deferred and output only
2591 if referenced in the function after all optimizations.
2593 `const_desc_table' records which constants already have label strings. */
2596 output_constant_def (tree exp
, int defer
)
2598 struct constant_descriptor_tree
*desc
;
2599 struct constant_descriptor_tree key
;
2602 /* Look up EXP in the table of constant descriptors. If we didn't find
2603 it, create a new one. */
2605 key
.hash
= const_hash_1 (exp
);
2606 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
2611 desc
= build_constant_desc (exp
);
2612 desc
->hash
= key
.hash
;
2616 maybe_output_constant_def_contents (desc
, defer
);
2620 /* Subroutine of output_constant_def: Decide whether or not we need to
2621 output the constant DESC now, and if so, do it. */
2623 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
2626 rtx symbol
= XEXP (desc
->rtl
, 0);
2627 tree exp
= desc
->value
;
2629 if (flag_syntax_only
)
2632 if (TREE_ASM_WRITTEN (exp
))
2633 /* Already output; don't do it again. */
2636 /* We can always defer constants as long as the context allows
2640 /* Increment n_deferred_constants if it exists. It needs to be at
2641 least as large as the number of constants actually referred to
2642 by the function. If it's too small we'll stop looking too early
2643 and fail to emit constants; if it's too large we'll only look
2644 through the entire function when we could have stopped earlier. */
2646 n_deferred_constants
++;
2650 output_constant_def_contents (symbol
);
2653 /* We must output the constant data referred to by SYMBOL; do so. */
2656 output_constant_def_contents (rtx symbol
)
2658 tree exp
= SYMBOL_REF_DECL (symbol
);
2659 const char *label
= XSTR (symbol
, 0);
2662 /* Make sure any other constants whose addresses appear in EXP
2663 are assigned label numbers. */
2664 int reloc
= compute_reloc_for_constant (exp
);
2666 /* Align the location counter as required by EXP's data type. */
2667 unsigned int align
= TYPE_ALIGN (TREE_TYPE (exp
));
2668 #ifdef CONSTANT_ALIGNMENT
2669 align
= CONSTANT_ALIGNMENT (exp
, align
);
2672 output_addressed_constants (exp
);
2674 /* We are no longer deferring this constant. */
2675 TREE_ASM_WRITTEN (exp
) = 1;
2677 if (IN_NAMED_SECTION (exp
))
2678 switch_to_section (get_named_section (exp
, NULL
, reloc
));
2680 switch_to_section (targetm
.asm_out
.select_section (exp
, reloc
, align
));
2682 if (align
> BITS_PER_UNIT
)
2684 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2687 size
= int_size_in_bytes (TREE_TYPE (exp
));
2688 if (TREE_CODE (exp
) == STRING_CST
)
2689 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
2691 /* Do any machine/system dependent processing of the constant. */
2692 #ifdef ASM_DECLARE_CONSTANT_NAME
2693 ASM_DECLARE_CONSTANT_NAME (asm_out_file
, label
, exp
, size
);
2695 /* Standard thing is just output label for the constant. */
2696 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2697 #endif /* ASM_DECLARE_CONSTANT_NAME */
2699 /* Output the value of EXP. */
2700 output_constant (exp
, size
, align
);
2702 mudflap_enqueue_constant (exp
);
2705 /* Look up EXP in the table of constant descriptors. Return the rtl
2706 if it has been emitted, else null. */
2709 lookup_constant_def (tree exp
)
2711 struct constant_descriptor_tree
*desc
;
2712 struct constant_descriptor_tree key
;
2715 key
.hash
= const_hash_1 (exp
);
2716 desc
= htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
2718 return (desc
? desc
->rtl
: NULL_RTX
);
2721 /* Used in the hash tables to avoid outputting the same constant
2722 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2723 are output once per function, not once per file. */
2724 /* ??? Only a few targets need per-function constant pools. Most
2725 can use one per-file pool. Should add a targetm bit to tell the
2728 struct rtx_constant_pool
GTY(())
2730 /* Pointers to first and last constant in pool, as ordered by offset. */
2731 struct constant_descriptor_rtx
*first
;
2732 struct constant_descriptor_rtx
*last
;
2734 /* Hash facility for making memory-constants from constant rtl-expressions.
2735 It is used on RISC machines where immediate integer arguments and
2736 constant addresses are restricted so that such constants must be stored
2738 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
2739 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_sym_htab
;
2741 /* Current offset in constant pool (does not include any
2742 machine-specific header). */
2743 HOST_WIDE_INT offset
;
2746 struct constant_descriptor_rtx
GTY((chain_next ("%h.next")))
2748 struct constant_descriptor_rtx
*next
;
2752 HOST_WIDE_INT offset
;
2754 enum machine_mode mode
;
2760 /* Hash and compare functions for const_rtx_htab. */
2763 const_desc_rtx_hash (const void *ptr
)
2765 const struct constant_descriptor_rtx
*desc
= ptr
;
2770 const_desc_rtx_eq (const void *a
, const void *b
)
2772 const struct constant_descriptor_rtx
*x
= a
;
2773 const struct constant_descriptor_rtx
*y
= b
;
2775 if (x
->mode
!= y
->mode
)
2777 return rtx_equal_p (x
->constant
, y
->constant
);
2780 /* Hash and compare functions for const_rtx_sym_htab. */
2783 const_desc_rtx_sym_hash (const void *ptr
)
2785 const struct constant_descriptor_rtx
*desc
= ptr
;
2786 return htab_hash_string (XSTR (desc
->sym
, 0));
2790 const_desc_rtx_sym_eq (const void *a
, const void *b
)
2792 const struct constant_descriptor_rtx
*x
= a
;
2793 const struct constant_descriptor_rtx
*y
= b
;
2794 return XSTR (x
->sym
, 0) == XSTR (y
->sym
, 0);
2797 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
2800 const_rtx_hash_1 (rtx
*xp
, void *data
)
2802 unsigned HOST_WIDE_INT hwi
;
2803 enum machine_mode mode
;
2809 code
= GET_CODE (x
);
2810 mode
= GET_MODE (x
);
2811 h
= (hashval_t
) code
* 1048573 + mode
;
2819 const int shift
= sizeof (hashval_t
) * CHAR_BIT
;
2820 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
2823 h
^= (hashval_t
) hwi
;
2824 for (i
= 1; i
< n
; ++i
)
2827 h
^= (hashval_t
) hwi
;
2833 if (mode
== VOIDmode
)
2835 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
2839 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
2845 for (i
= XVECLEN (x
, 0); i
-- > 0; )
2846 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
2851 h
^= htab_hash_string (XSTR (x
, 0));
2855 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
2859 case UNSPEC_VOLATILE
:
2860 h
= h
* 251 + XINT (x
, 1);
2868 *hp
= *hp
* 509 + h
;
2872 /* Compute a hash value for X, which should be a constant. */
2875 const_rtx_hash (rtx x
)
2878 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
2883 /* Initialize constant pool hashing for a new function. */
2886 init_varasm_status (struct function
*f
)
2888 struct varasm_status
*p
;
2889 struct rtx_constant_pool
*pool
;
2891 p
= ggc_alloc (sizeof (struct varasm_status
));
2894 pool
= ggc_alloc (sizeof (struct rtx_constant_pool
));
2896 p
->deferred_constants
= 0;
2898 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
2899 const_desc_rtx_eq
, NULL
);
2900 pool
->const_rtx_sym_htab
= htab_create_ggc (31, const_desc_rtx_sym_hash
,
2901 const_desc_rtx_sym_eq
, NULL
);
2902 pool
->first
= pool
->last
= NULL
;
2906 /* Given a MINUS expression, simplify it if both sides
2907 include the same symbol. */
2910 simplify_subtraction (rtx x
)
2912 rtx r
= simplify_rtx (x
);
2916 /* Given a constant rtx X, make (or find) a memory constant for its value
2917 and return a MEM rtx to refer to it in memory. */
2920 force_const_mem (enum machine_mode mode
, rtx x
)
2922 struct constant_descriptor_rtx
*desc
, tmp
;
2923 struct rtx_constant_pool
*pool
= cfun
->varasm
->pool
;
2930 /* If we're not allowed to drop X into the constant pool, don't. */
2931 if (targetm
.cannot_force_const_mem (x
))
2934 /* Lookup the value in the hashtable. */
2937 hash
= const_rtx_hash (x
);
2938 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
2941 /* If the constant was already present, return its memory. */
2943 return copy_rtx (desc
->mem
);
2945 /* Otherwise, create a new descriptor. */
2946 desc
= ggc_alloc (sizeof (*desc
));
2949 /* Align the location counter as required by EXP's data type. */
2950 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
2951 #ifdef CONSTANT_ALIGNMENT
2953 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
2954 if (type
!= NULL_TREE
)
2955 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
2959 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
2960 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
2963 desc
->constant
= tmp
.constant
;
2964 desc
->offset
= pool
->offset
;
2967 desc
->align
= align
;
2968 desc
->labelno
= const_labelno
;
2971 pool
->offset
+= GET_MODE_SIZE (mode
);
2973 pool
->last
->next
= desc
;
2975 pool
->first
= pool
->last
= desc
;
2978 /* Create a string containing the label name, in LABEL. */
2979 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2982 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
2983 the constants pool. */
2984 desc
->sym
= symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
2985 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2986 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
2987 current_function_uses_const_pool
= 1;
2989 /* Insert the descriptor into the symbol cross-reference table too. */
2990 slot
= htab_find_slot (pool
->const_rtx_sym_htab
, desc
, INSERT
);
2991 gcc_assert (!*slot
);
2994 /* Construct the MEM. */
2995 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
2996 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
2997 set_mem_align (def
, align
);
2999 /* If we're dropping a label to the constant pool, make sure we
3001 if (GET_CODE (x
) == LABEL_REF
)
3002 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3004 return copy_rtx (def
);
3007 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3008 the corresponding constant_descriptor_rtx structure. */
3010 static struct constant_descriptor_rtx
*
3011 find_pool_constant (struct rtx_constant_pool
*pool
, rtx sym
)
3013 struct constant_descriptor_rtx tmp
;
3015 return htab_find (pool
->const_rtx_sym_htab
, &tmp
);
3018 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3021 get_pool_constant (rtx addr
)
3023 return find_pool_constant (cfun
->varasm
->pool
, addr
)->constant
;
3026 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3027 and whether it has been output or not. */
3030 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3032 struct constant_descriptor_rtx
*desc
;
3034 desc
= find_pool_constant (cfun
->varasm
->pool
, addr
);
3035 *pmarked
= (desc
->mark
!= 0);
3036 return desc
->constant
;
3039 /* Likewise, but for the constant pool of a specific function. */
3042 get_pool_constant_for_function (struct function
*f
, rtx addr
)
3044 return find_pool_constant (f
->varasm
->pool
, addr
)->constant
;
3047 /* Similar, return the mode. */
3050 get_pool_mode (rtx addr
)
3052 return find_pool_constant (cfun
->varasm
->pool
, addr
)->mode
;
3055 /* Return the size of the constant pool. */
3058 get_pool_size (void)
3060 return cfun
->varasm
->pool
->offset
;
3063 /* Worker function for output_constant_pool_1. Emit assembly for X
3064 in MODE with known alignment ALIGN. */
3067 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3069 switch (GET_MODE_CLASS (mode
))
3075 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3076 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3077 assemble_real (r
, mode
, align
);
3082 case MODE_PARTIAL_INT
:
3083 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3086 case MODE_VECTOR_FLOAT
:
3087 case MODE_VECTOR_INT
:
3090 enum machine_mode submode
= GET_MODE_INNER (mode
);
3091 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3093 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3094 units
= CONST_VECTOR_NUNITS (x
);
3096 for (i
= 0; i
< units
; i
++)
3098 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3099 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3109 /* Worker function for output_constant_pool. Emit POOL. */
3112 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
)
3120 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3121 whose CODE_LABEL has been deleted. This can occur if a jump table
3122 is eliminated by optimization. If so, write a constant of zero
3123 instead. Note that this can also happen by turning the
3124 CODE_LABEL into a NOTE. */
3125 /* ??? This seems completely and utterly wrong. Certainly it's
3126 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3127 functioning even with INSN_DELETED_P and friends. */
3130 switch (GET_CODE (x
))
3133 if (GET_CODE (XEXP (x
, 0)) != PLUS
3134 || GET_CODE (XEXP (XEXP (x
, 0), 0)) != LABEL_REF
)
3136 tmp
= XEXP (XEXP (x
, 0), 0);
3141 gcc_assert (!INSN_DELETED_P (tmp
));
3142 gcc_assert (!NOTE_P (tmp
)
3143 || NOTE_LINE_NUMBER (tmp
) != NOTE_INSN_DELETED
);
3150 /* First switch to correct section. */
3151 switch_to_section (targetm
.asm_out
.select_rtx_section (desc
->mode
, x
,
3154 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3155 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3156 desc
->align
, desc
->labelno
, done
);
3159 assemble_align (desc
->align
);
3161 /* Output the label. */
3162 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3164 /* Output the data. */
3165 output_constant_pool_2 (desc
->mode
, x
, desc
->align
);
3167 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3168 sections have proper size. */
3169 if (desc
->align
> GET_MODE_BITSIZE (desc
->mode
)
3171 && (in_section
->common
.flags
& SECTION_MERGE
))
3172 assemble_align (desc
->align
);
3174 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3180 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3181 to as used. Emit referenced deferred strings. This function can
3182 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3185 mark_constant (rtx
*current_rtx
, void *data
)
3187 struct rtx_constant_pool
*pool
= data
;
3188 rtx x
= *current_rtx
;
3190 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3193 if (CONSTANT_POOL_ADDRESS_P (x
))
3195 struct constant_descriptor_rtx
*desc
= find_pool_constant (pool
, x
);
3196 if (desc
->mark
== 0)
3199 for_each_rtx (&desc
->constant
, mark_constant
, pool
);
3202 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
3204 tree exp
= SYMBOL_REF_DECL (x
);
3205 if (!TREE_ASM_WRITTEN (exp
))
3207 n_deferred_constants
--;
3208 output_constant_def_contents (x
);
3215 /* Look through appropriate parts of INSN, marking all entries in the
3216 constant pool which are actually being used. Entries that are only
3217 referenced by other constants are also marked as used. Emit
3218 deferred strings that are used. */
3221 mark_constants (struct rtx_constant_pool
*pool
, rtx insn
)
3226 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3227 insns, not any notes that may be attached. We don't want to mark
3228 a constant just because it happens to appear in a REG_EQUIV note. */
3229 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3231 rtx seq
= PATTERN (insn
);
3232 int i
, n
= XVECLEN (seq
, 0);
3233 for (i
= 0; i
< n
; ++i
)
3235 rtx subinsn
= XVECEXP (seq
, 0, i
);
3236 if (INSN_P (subinsn
))
3237 for_each_rtx (&PATTERN (subinsn
), mark_constant
, pool
);
3241 for_each_rtx (&PATTERN (insn
), mark_constant
, pool
);
3244 /* Look through the instructions for this function, and mark all the
3245 entries in POOL which are actually being used. Emit deferred constants
3246 which have indeed been used. */
3249 mark_constant_pool (struct rtx_constant_pool
*pool
)
3253 if (pool
->first
== 0 && n_deferred_constants
== 0)
3256 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3257 mark_constants (pool
, insn
);
3259 for (link
= current_function_epilogue_delay_list
;
3261 link
= XEXP (link
, 1))
3262 mark_constants (pool
, XEXP (link
, 0));
3265 /* Write all the constants in the constant pool. */
3268 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
3269 tree fndecl ATTRIBUTE_UNUSED
)
3271 struct rtx_constant_pool
*pool
= cfun
->varasm
->pool
;
3272 struct constant_descriptor_rtx
*desc
;
3274 /* It is possible for gcc to call force_const_mem and then to later
3275 discard the instructions which refer to the constant. In such a
3276 case we do not need to output the constant. */
3277 mark_constant_pool (pool
);
3279 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3280 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3283 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
3284 output_constant_pool_1 (desc
);
3286 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3287 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
3291 /* Determine what kind of relocations EXP may need. */
3294 compute_reloc_for_constant (tree exp
)
3296 int reloc
= 0, reloc2
;
3299 /* Give the front-end a chance to convert VALUE to something that
3300 looks more like a constant to the back-end. */
3301 exp
= lang_hooks
.expand_constant (exp
);
3303 switch (TREE_CODE (exp
))
3307 /* Go inside any operations that get_inner_reference can handle and see
3308 if what's inside is a constant: no need to do anything here for
3309 addresses of variables or functions. */
3310 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3311 tem
= TREE_OPERAND (tem
, 0))
3314 if (TREE_PUBLIC (tem
))
3321 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3322 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3326 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3327 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
3328 /* The difference of two local labels is computable at link time. */
3329 if (reloc
== 1 && reloc2
== 1)
3337 case NON_LVALUE_EXPR
:
3338 case VIEW_CONVERT_EXPR
:
3339 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
3344 unsigned HOST_WIDE_INT idx
;
3345 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3347 reloc
|= compute_reloc_for_constant (tem
);
3357 /* Find all the constants whose addresses are referenced inside of EXP,
3358 and make sure assembler code with a label has been output for each one.
3359 Indicate whether an ADDR_EXPR has been encountered. */
3362 output_addressed_constants (tree exp
)
3366 /* Give the front-end a chance to convert VALUE to something that
3367 looks more like a constant to the back-end. */
3368 exp
= lang_hooks
.expand_constant (exp
);
3370 switch (TREE_CODE (exp
))
3374 /* Go inside any operations that get_inner_reference can handle and see
3375 if what's inside is a constant: no need to do anything here for
3376 addresses of variables or functions. */
3377 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3378 tem
= TREE_OPERAND (tem
, 0))
3381 /* If we have an initialized CONST_DECL, retrieve the initializer. */
3382 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
3383 tem
= DECL_INITIAL (tem
);
3385 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
3386 output_constant_def (tem
, 0);
3391 output_addressed_constants (TREE_OPERAND (exp
, 1));
3396 case NON_LVALUE_EXPR
:
3397 case VIEW_CONVERT_EXPR
:
3398 output_addressed_constants (TREE_OPERAND (exp
, 0));
3403 unsigned HOST_WIDE_INT idx
;
3404 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
3406 output_addressed_constants (tem
);
3415 /* Return nonzero if VALUE is a valid constant-valued expression
3416 for use in initializing a static variable; one that can be an
3417 element of a "constant" initializer.
3419 Return null_pointer_node if the value is absolute;
3420 if it is relocatable, return the variable that determines the relocation.
3421 We assume that VALUE has been folded as much as possible;
3422 therefore, we do not need to check for such things as
3423 arithmetic-combinations of integers. */
3426 initializer_constant_valid_p (tree value
, tree endtype
)
3428 /* Give the front-end a chance to convert VALUE to something that
3429 looks more like a constant to the back-end. */
3430 value
= lang_hooks
.expand_constant (value
);
3432 switch (TREE_CODE (value
))
3435 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
3436 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
3437 && TREE_CONSTANT (value
)
3438 && !VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (value
)))
3440 unsigned HOST_WIDE_INT idx
;
3442 bool absolute
= true;
3444 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
3447 reloc
= initializer_constant_valid_p (elt
, TREE_TYPE (elt
));
3450 if (reloc
!= null_pointer_node
)
3453 /* For a non-absolute relocation, there is no single
3454 variable that can be "the variable that determines the
3456 return absolute
? null_pointer_node
: error_mark_node
;
3459 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
3466 return null_pointer_node
;
3470 value
= staticp (TREE_OPERAND (value
, 0));
3471 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to
3472 be a constant, this is old-skool offsetof-like nonsense. */
3474 && TREE_CODE (value
) == INDIRECT_REF
3475 && TREE_CONSTANT (TREE_OPERAND (value
, 0)))
3476 return null_pointer_node
;
3477 /* Taking the address of a nested function involves a trampoline. */
3479 && TREE_CODE (value
) == FUNCTION_DECL
3480 && ((decl_function_context (value
) && !DECL_NO_STATIC_CHAIN (value
))
3481 || DECL_DLLIMPORT_P (value
)))
3485 case VIEW_CONVERT_EXPR
:
3486 case NON_LVALUE_EXPR
:
3487 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3496 src
= TREE_OPERAND (value
, 0);
3497 src_type
= TREE_TYPE (src
);
3498 dest_type
= TREE_TYPE (value
);
3500 /* Allow conversions between pointer types, floating-point
3501 types, and offset types. */
3502 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
3503 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
3504 || (TREE_CODE (dest_type
) == OFFSET_TYPE
3505 && TREE_CODE (src_type
) == OFFSET_TYPE
))
3506 return initializer_constant_valid_p (src
, endtype
);
3508 /* Allow length-preserving conversions between integer types. */
3509 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
3510 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
3511 return initializer_constant_valid_p (src
, endtype
);
3513 /* Allow conversions between other integer types only if
3515 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
3517 tree inner
= initializer_constant_valid_p (src
, endtype
);
3518 if (inner
== null_pointer_node
)
3519 return null_pointer_node
;
3523 /* Allow (int) &foo provided int is as wide as a pointer. */
3524 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
3525 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
3526 return initializer_constant_valid_p (src
, endtype
);
3528 /* Likewise conversions from int to pointers, but also allow
3529 conversions from 0. */
3530 if ((POINTER_TYPE_P (dest_type
)
3531 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
3532 && INTEGRAL_TYPE_P (src_type
))
3534 if (integer_zerop (src
))
3535 return null_pointer_node
;
3536 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
3537 return initializer_constant_valid_p (src
, endtype
);
3540 /* Allow conversions to struct or union types if the value
3542 if (TREE_CODE (dest_type
) == RECORD_TYPE
3543 || TREE_CODE (dest_type
) == UNION_TYPE
)
3544 return initializer_constant_valid_p (src
, endtype
);
3549 if (! INTEGRAL_TYPE_P (endtype
)
3550 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
3552 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3554 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
3556 /* If either term is absolute, use the other terms relocation. */
3557 if (valid0
== null_pointer_node
)
3559 if (valid1
== null_pointer_node
)
3565 if (! INTEGRAL_TYPE_P (endtype
)
3566 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
3568 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3570 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
3572 /* Win if second argument is absolute. */
3573 if (valid1
== null_pointer_node
)
3575 /* Win if both arguments have the same relocation.
3576 Then the value is absolute. */
3577 if (valid0
== valid1
&& valid0
!= 0)
3578 return null_pointer_node
;
3580 /* Since GCC guarantees that string constants are unique in the
3581 generated code, a subtraction between two copies of the same
3582 constant string is absolute. */
3583 if (valid0
&& TREE_CODE (valid0
) == STRING_CST
3584 && valid1
&& TREE_CODE (valid1
) == STRING_CST
3585 && operand_equal_p (valid0
, valid1
, 1))
3586 return null_pointer_node
;
3589 /* Support narrowing differences. */
3590 if (INTEGRAL_TYPE_P (endtype
))
3594 op0
= TREE_OPERAND (value
, 0);
3595 op1
= TREE_OPERAND (value
, 1);
3597 /* Like STRIP_NOPS except allow the operand mode to widen.
3598 This works around a feature of fold that simplifies
3599 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3600 that the narrower operation is cheaper. */
3602 while (TREE_CODE (op0
) == NOP_EXPR
3603 || TREE_CODE (op0
) == CONVERT_EXPR
3604 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
3606 tree inner
= TREE_OPERAND (op0
, 0);
3607 if (inner
== error_mark_node
3608 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3609 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
3610 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3615 while (TREE_CODE (op1
) == NOP_EXPR
3616 || TREE_CODE (op1
) == CONVERT_EXPR
3617 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
3619 tree inner
= TREE_OPERAND (op1
, 0);
3620 if (inner
== error_mark_node
3621 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3622 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
3623 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3628 op0
= initializer_constant_valid_p (op0
, endtype
);
3629 op1
= initializer_constant_valid_p (op1
, endtype
);
3631 /* Both initializers must be known. */
3635 return null_pointer_node
;
3637 /* Support differences between labels. */
3638 if (TREE_CODE (op0
) == LABEL_DECL
3639 && TREE_CODE (op1
) == LABEL_DECL
)
3640 return null_pointer_node
;
3642 if (TREE_CODE (op0
) == STRING_CST
3643 && TREE_CODE (op1
) == STRING_CST
3644 && operand_equal_p (op0
, op1
, 1))
3645 return null_pointer_node
;
3657 /* Output assembler code for constant EXP to FILE, with no label.
3658 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3659 Assumes output_addressed_constants has been done on EXP already.
3661 Generate exactly SIZE bytes of assembler data, padding at the end
3662 with zeros if necessary. SIZE must always be specified.
3664 SIZE is important for structure constructors,
3665 since trailing members may have been omitted from the constructor.
3666 It is also important for initialization of arrays from string constants
3667 since the full length of the string constant might not be wanted.
3668 It is also needed for initialization of unions, where the initializer's
3669 type is just one member, and that may not be as long as the union.
3671 There a case in which we would fail to output exactly SIZE bytes:
3672 for a structure constructor that wants to produce more than SIZE bytes.
3673 But such constructors will never be generated for any possible input.
3675 ALIGN is the alignment of the data in bits. */
3678 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
3680 enum tree_code code
;
3681 unsigned HOST_WIDE_INT thissize
;
3683 /* Some front-ends use constants other than the standard language-independent
3684 varieties, but which may still be output directly. Give the front-end a
3685 chance to convert EXP to a language-independent representation. */
3686 exp
= lang_hooks
.expand_constant (exp
);
3688 if (size
== 0 || flag_syntax_only
)
3691 /* See if we're trying to initialize a pointer in a non-default mode
3692 to the address of some declaration somewhere. If the target says
3693 the mode is valid for pointers, assume the target has a way of
3695 if (TREE_CODE (exp
) == NOP_EXPR
3696 && POINTER_TYPE_P (TREE_TYPE (exp
))
3697 && targetm
.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp
))))
3699 tree saved_type
= TREE_TYPE (exp
);
3701 /* Peel off any intermediate conversions-to-pointer for valid
3703 while (TREE_CODE (exp
) == NOP_EXPR
3704 && POINTER_TYPE_P (TREE_TYPE (exp
))
3705 && targetm
.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp
))))
3706 exp
= TREE_OPERAND (exp
, 0);
3708 /* If what we're left with is the address of something, we can
3709 convert the address to the final type and output it that
3711 if (TREE_CODE (exp
) == ADDR_EXPR
)
3712 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
3715 /* Eliminate any conversions since we'll be outputting the underlying
3717 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
3718 || TREE_CODE (exp
) == NON_LVALUE_EXPR
3719 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
3721 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
3722 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
3724 /* Make sure eliminating the conversion is really a no-op, except with
3725 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
3726 union types to allow for Ada unchecked unions. */
3727 if (type_size
> op_size
3728 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
3729 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
3730 internal_error ("no-op convert from %wd to %wd bytes in initializer",
3731 op_size
, type_size
);
3733 exp
= TREE_OPERAND (exp
, 0);
3736 code
= TREE_CODE (TREE_TYPE (exp
));
3737 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
3739 /* Allow a constructor with no elements for any data type.
3740 This means to fill the space with zeros. */
3741 if (TREE_CODE (exp
) == CONSTRUCTOR
3742 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
3744 assemble_zeros (size
);
3748 if (TREE_CODE (exp
) == FDESC_EXPR
)
3750 #ifdef ASM_OUTPUT_FDESC
3751 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
3752 tree decl
= TREE_OPERAND (exp
, 0);
3753 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
3760 /* Now output the underlying data. If we've handling the padding, return.
3761 Otherwise, break and ensure SIZE is the size written. */
3769 case REFERENCE_TYPE
:
3771 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
3772 EXPAND_INITIALIZER
),
3773 MIN (size
, thissize
), align
, 0))
3774 error ("initializer for integer value is too complicated");
3778 if (TREE_CODE (exp
) != REAL_CST
)
3779 error ("initializer for floating value is not a floating constant");
3781 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
3785 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
3786 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
3787 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
3792 switch (TREE_CODE (exp
))
3795 output_constructor (exp
, size
, align
);
3798 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
3800 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
3807 unsigned int nalign
;
3808 enum machine_mode inner
;
3810 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
3811 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
3813 elt_size
= GET_MODE_SIZE (inner
);
3815 link
= TREE_VECTOR_CST_ELTS (exp
);
3816 output_constant (TREE_VALUE (link
), elt_size
, align
);
3817 while ((link
= TREE_CHAIN (link
)) != NULL
)
3818 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
3828 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
3829 output_constructor (exp
, size
, align
);
3839 if (size
> thissize
)
3840 assemble_zeros (size
- thissize
);
3844 /* Subroutine of output_constructor, used for computing the size of
3845 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3846 type with an unspecified upper bound. */
3848 static unsigned HOST_WIDE_INT
3849 array_size_for_constructor (tree val
)
3852 unsigned HOST_WIDE_INT cnt
;
3855 /* This code used to attempt to handle string constants that are not
3856 arrays of single-bytes, but nothing else does, so there's no point in
3858 if (TREE_CODE (val
) == STRING_CST
)
3859 return TREE_STRING_LENGTH (val
);
3861 max_index
= NULL_TREE
;
3862 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
3864 if (TREE_CODE (index
) == RANGE_EXPR
)
3865 index
= TREE_OPERAND (index
, 1);
3866 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
3870 if (max_index
== NULL_TREE
)
3873 /* Compute the total number of array elements. */
3874 i
= size_binop (MINUS_EXPR
, convert (sizetype
, max_index
),
3876 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)))));
3877 i
= size_binop (PLUS_EXPR
, i
, convert (sizetype
, integer_one_node
));
3879 /* Multiply by the array element unit size to find number of bytes. */
3880 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
3882 return tree_low_cst (i
, 1);
3885 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3886 Generate at least SIZE bytes, padding if necessary. */
3889 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
3892 tree type
= TREE_TYPE (exp
);
3895 /* Number of bytes output or skipped so far.
3896 In other words, current position within the constructor. */
3897 HOST_WIDE_INT total_bytes
= 0;
3898 /* Nonzero means BYTE contains part of a byte, to be output. */
3899 int byte_buffer_in_use
= 0;
3901 unsigned HOST_WIDE_INT cnt
;
3902 constructor_elt
*ce
;
3904 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
3906 if (TREE_CODE (type
) == RECORD_TYPE
)
3907 field
= TYPE_FIELDS (type
);
3909 if (TREE_CODE (type
) == ARRAY_TYPE
3910 && TYPE_DOMAIN (type
) != 0)
3911 min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
3913 /* As LINK goes through the elements of the constant,
3914 FIELD goes through the structure fields, if the constant is a structure.
3915 if the constant is a union, then we override this,
3916 by getting the field from the TREE_LIST element.
3917 But the constant could also be an array. Then FIELD is zero.
3919 There is always a maximum of one element in the chain LINK for unions
3920 (even if the initializer in a source program incorrectly contains
3923 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
3924 cnt
++, field
= field
? TREE_CHAIN (field
) : 0)
3926 tree val
= ce
->value
;
3929 /* The element in a union constructor specifies the proper field
3931 if ((TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
3932 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
3936 else if (TREE_CODE (type
) == ARRAY_TYPE
)
3939 #ifdef ASM_COMMENT_START
3940 if (field
&& flag_verbose_asm
)
3941 fprintf (asm_out_file
, "%s %s:\n",
3944 ? IDENTIFIER_POINTER (DECL_NAME (field
))
3948 /* Eliminate the marker that makes a cast not be an lvalue. */
3952 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
3954 unsigned HOST_WIDE_INT fieldsize
3955 = int_size_in_bytes (TREE_TYPE (type
));
3956 HOST_WIDE_INT lo_index
= tree_low_cst (TREE_OPERAND (index
, 0), 0);
3957 HOST_WIDE_INT hi_index
= tree_low_cst (TREE_OPERAND (index
, 1), 0);
3958 HOST_WIDE_INT index
;
3959 unsigned int align2
= min_align (align
, fieldsize
* BITS_PER_UNIT
);
3961 for (index
= lo_index
; index
<= hi_index
; index
++)
3963 /* Output the element's initial value. */
3965 assemble_zeros (fieldsize
);
3967 output_constant (val
, fieldsize
, align2
);
3969 /* Count its size. */
3970 total_bytes
+= fieldsize
;
3973 else if (field
== 0 || !DECL_BIT_FIELD (field
))
3975 /* An element that is not a bit-field. */
3977 unsigned HOST_WIDE_INT fieldsize
;
3978 /* Since this structure is static,
3979 we know the positions are constant. */
3980 HOST_WIDE_INT pos
= field
? int_byte_position (field
) : 0;
3981 unsigned int align2
;
3984 pos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val
)), 1)
3985 * (tree_low_cst (index
, 0) - tree_low_cst (min_index
, 0)));
3987 /* Output any buffered-up bit-fields preceding this element. */
3988 if (byte_buffer_in_use
)
3990 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
3992 byte_buffer_in_use
= 0;
3995 /* Advance to offset of this element.
3996 Note no alignment needed in an array, since that is guaranteed
3997 if each element has the proper size. */
3998 if ((field
!= 0 || index
!= 0) && pos
!= total_bytes
)
4000 gcc_assert (pos
>= total_bytes
);
4001 assemble_zeros (pos
- total_bytes
);
4005 /* Find the alignment of this element. */
4006 align2
= min_align (align
, BITS_PER_UNIT
* pos
);
4008 /* Determine size this element should occupy. */
4013 /* If this is an array with an unspecified upper bound,
4014 the initializer determines the size. */
4015 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4016 but we cannot do this until the deprecated support for
4017 initializing zero-length array members is removed. */
4018 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
4019 && TYPE_DOMAIN (TREE_TYPE (field
))
4020 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
4022 fieldsize
= array_size_for_constructor (val
);
4023 /* Given a non-empty initialization, this field had
4025 gcc_assert (!fieldsize
|| !TREE_CHAIN (field
));
4027 else if (DECL_SIZE_UNIT (field
))
4029 /* ??? This can't be right. If the decl size overflows
4030 a host integer we will silently emit no data. */
4031 if (host_integerp (DECL_SIZE_UNIT (field
), 1))
4032 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 1);
4036 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
4038 /* Output the element's initial value. */
4040 assemble_zeros (fieldsize
);
4042 output_constant (val
, fieldsize
, align2
);
4044 /* Count its size. */
4045 total_bytes
+= fieldsize
;
4047 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4048 error ("invalid initial value for member %qs",
4049 IDENTIFIER_POINTER (DECL_NAME (field
)));
4052 /* Element that is a bit-field. */
4054 HOST_WIDE_INT next_offset
= int_bit_position (field
);
4055 HOST_WIDE_INT end_offset
4056 = (next_offset
+ tree_low_cst (DECL_SIZE (field
), 1));
4059 val
= integer_zero_node
;
4061 /* If this field does not start in this (or, next) byte,
4063 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4065 /* Output remnant of any bit field in previous bytes. */
4066 if (byte_buffer_in_use
)
4068 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4070 byte_buffer_in_use
= 0;
4073 /* If still not at proper byte, advance to there. */
4074 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4076 gcc_assert (next_offset
/ BITS_PER_UNIT
>= total_bytes
);
4077 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4078 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4082 if (! byte_buffer_in_use
)
4085 /* We must split the element into pieces that fall within
4086 separate bytes, and combine each byte with previous or
4087 following bit-fields. */
4089 /* next_offset is the offset n fbits from the beginning of
4090 the structure to the next bit of this element to be processed.
4091 end_offset is the offset of the first bit past the end of
4093 while (next_offset
< end_offset
)
4097 HOST_WIDE_INT value
;
4098 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4099 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4101 /* Advance from byte to byte
4102 within this element when necessary. */
4103 while (next_byte
!= total_bytes
)
4105 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4110 /* Number of bits we can process at once
4111 (all part of the same byte). */
4112 this_time
= MIN (end_offset
- next_offset
,
4113 BITS_PER_UNIT
- next_bit
);
4114 if (BYTES_BIG_ENDIAN
)
4116 /* On big-endian machine, take the most significant bits
4117 first (of the bits that are significant)
4118 and put them into bytes from the most significant end. */
4119 shift
= end_offset
- next_offset
- this_time
;
4121 /* Don't try to take a bunch of bits that cross
4122 the word boundary in the INTEGER_CST. We can
4123 only select bits from the LOW or HIGH part
4125 if (shift
< HOST_BITS_PER_WIDE_INT
4126 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4128 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4129 shift
= HOST_BITS_PER_WIDE_INT
;
4132 /* Now get the bits from the appropriate constant word. */
4133 if (shift
< HOST_BITS_PER_WIDE_INT
)
4134 value
= TREE_INT_CST_LOW (val
);
4137 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4138 value
= TREE_INT_CST_HIGH (val
);
4139 shift
-= HOST_BITS_PER_WIDE_INT
;
4142 /* Get the result. This works only when:
4143 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4144 byte
|= (((value
>> shift
)
4145 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4146 << (BITS_PER_UNIT
- this_time
- next_bit
));
4150 /* On little-endian machines,
4151 take first the least significant bits of the value
4152 and pack them starting at the least significant
4153 bits of the bytes. */
4154 shift
= next_offset
- int_bit_position (field
);
4156 /* Don't try to take a bunch of bits that cross
4157 the word boundary in the INTEGER_CST. We can
4158 only select bits from the LOW or HIGH part
4160 if (shift
< HOST_BITS_PER_WIDE_INT
4161 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4162 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4164 /* Now get the bits from the appropriate constant word. */
4165 if (shift
< HOST_BITS_PER_WIDE_INT
)
4166 value
= TREE_INT_CST_LOW (val
);
4169 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
4170 value
= TREE_INT_CST_HIGH (val
);
4171 shift
-= HOST_BITS_PER_WIDE_INT
;
4174 /* Get the result. This works only when:
4175 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4176 byte
|= (((value
>> shift
)
4177 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4181 next_offset
+= this_time
;
4182 byte_buffer_in_use
= 1;
4187 if (byte_buffer_in_use
)
4189 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4193 if ((unsigned HOST_WIDE_INT
)total_bytes
< size
)
4194 assemble_zeros (size
- total_bytes
);
4197 /* This TREE_LIST contains any weak symbol declarations waiting
4199 static GTY(()) tree weak_decls
;
4201 /* Mark DECL as weak. */
4204 mark_weak (tree decl
)
4206 DECL_WEAK (decl
) = 1;
4208 if (DECL_RTL_SET_P (decl
)
4209 && MEM_P (DECL_RTL (decl
))
4210 && XEXP (DECL_RTL (decl
), 0)
4211 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
4212 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
4215 /* Merge weak status between NEWDECL and OLDDECL. */
4218 merge_weak (tree newdecl
, tree olddecl
)
4220 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
4222 if (DECL_WEAK (newdecl
) && SUPPORTS_WEAK
)
4225 /* We put the NEWDECL on the weak_decls list at some point
4226 and OLDDECL as well. Keep just OLDDECL on the list. */
4227 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
4228 if (TREE_VALUE (*pwd
) == newdecl
)
4230 *pwd
= TREE_CHAIN (*pwd
);
4237 if (DECL_WEAK (newdecl
))
4241 /* NEWDECL is weak, but OLDDECL is not. */
4243 /* If we already output the OLDDECL, we're in trouble; we can't
4244 go back and make it weak. This error cannot caught in
4245 declare_weak because the NEWDECL and OLDDECL was not yet
4246 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4247 if (TREE_ASM_WRITTEN (olddecl
))
4248 error ("weak declaration of %q+D must precede definition",
4251 /* If we've already generated rtl referencing OLDDECL, we may
4252 have done so in a way that will not function properly with
4254 else if (TREE_USED (olddecl
)
4255 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
4256 warning (0, "weak declaration of %q+D after first use results "
4257 "in unspecified behavior", newdecl
);
4261 /* We put the NEWDECL on the weak_decls list at some point.
4262 Replace it with the OLDDECL. */
4263 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
4264 if (TREE_VALUE (wd
) == newdecl
)
4266 TREE_VALUE (wd
) = olddecl
;
4269 /* We may not find the entry on the list. If NEWDECL is a
4270 weak alias, then we will have already called
4271 globalize_decl to remove the entry; in that case, we do
4272 not need to do anything. */
4275 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4276 mark_weak (olddecl
);
4279 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4280 weak. Just update NEWDECL to indicate that it's weak too. */
4281 mark_weak (newdecl
);
4284 /* Declare DECL to be a weak symbol. */
4287 declare_weak (tree decl
)
4289 if (! TREE_PUBLIC (decl
))
4290 error ("weak declaration of %q+D must be public", decl
);
4291 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
4292 error ("weak declaration of %q+D must precede definition", decl
);
4293 else if (SUPPORTS_WEAK
)
4295 if (! DECL_WEAK (decl
))
4296 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
4299 warning (0, "weak declaration of %q+D not supported", decl
);
4305 weak_finish_1 (tree decl
)
4307 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4308 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4311 if (! TREE_USED (decl
))
4314 #ifdef ASM_WEAKEN_DECL
4315 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
4317 #ifdef ASM_WEAKEN_LABEL
4318 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4320 #ifdef ASM_OUTPUT_WEAK_ALIAS
4322 static bool warn_once
= 0;
4325 warning (0, "only weak aliases are supported in this configuration");
4335 /* This TREE_LIST contains weakref targets. */
4337 static GTY(()) tree weakref_targets
;
4339 /* Forward declaration. */
4340 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
4342 /* Emit any pending weak declarations. */
4349 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
4351 tree alias_decl
= TREE_PURPOSE (t
);
4352 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
4354 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
4355 /* Remove alias_decl from the weak list, but leave entries for
4356 the target alone. */
4358 #ifndef ASM_OUTPUT_WEAKREF
4359 else if (! TREE_SYMBOL_REFERENCED (target
))
4361 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
4362 defined, otherwise we and weak_finish_1 would use a
4363 different macros. */
4364 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
4365 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
4367 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
4371 decl
= build_decl (TREE_CODE (alias_decl
), target
,
4372 TREE_TYPE (alias_decl
));
4374 DECL_EXTERNAL (decl
) = 1;
4375 TREE_PUBLIC (decl
) = 1;
4376 DECL_ARTIFICIAL (decl
) = 1;
4377 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
4378 TREE_USED (decl
) = 1;
4381 weak_finish_1 (decl
);
4390 /* Remove the alias and the target from the pending weak list
4391 so that we do not emit any .weak directives for the former,
4392 nor multiple .weak directives for the latter. */
4393 for (p
= &weak_decls
; (t2
= *p
) ; )
4395 if (TREE_VALUE (t2
) == alias_decl
4396 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
4397 *p
= TREE_CHAIN (t2
);
4399 p
= &TREE_CHAIN (t2
);
4402 /* Remove other weakrefs to the same target, to speed things up. */
4403 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
4405 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
4406 *p
= TREE_CHAIN (t2
);
4408 p
= &TREE_CHAIN (t2
);
4413 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
4415 tree decl
= TREE_VALUE (t
);
4417 weak_finish_1 (decl
);
4421 /* Emit the assembly bits to indicate that DECL is globally visible. */
4424 globalize_decl (tree decl
)
4426 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4428 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4429 if (DECL_WEAK (decl
))
4433 #ifdef ASM_WEAKEN_DECL
4434 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
4436 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4439 /* Remove this function from the pending weak list so that
4440 we do not emit multiple .weak directives for it. */
4441 for (p
= &weak_decls
; (t
= *p
) ; )
4443 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
4444 *p
= TREE_CHAIN (t
);
4446 p
= &TREE_CHAIN (t
);
4449 /* Remove weakrefs to the same target from the pending weakref
4450 list, for the same reason. */
4451 for (p
= &weakref_targets
; (t
= *p
) ; )
4453 if (DECL_ASSEMBLER_NAME (decl
)
4454 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
4455 *p
= TREE_CHAIN (t
);
4457 p
= &TREE_CHAIN (t
);
4462 #elif defined(ASM_MAKE_LABEL_LINKONCE)
4463 if (DECL_ONE_ONLY (decl
))
4464 ASM_MAKE_LABEL_LINKONCE (asm_out_file
, name
);
4467 targetm
.asm_out
.globalize_label (asm_out_file
, name
);
4470 /* We have to be able to tell cgraph about the needed-ness of the target
4471 of an alias. This requires that the decl have been defined. Aliases
4472 that precede their definition have to be queued for later processing. */
4474 typedef struct alias_pair
GTY(())
4480 /* Define gc'd vector type. */
4481 DEF_VEC_O(alias_pair
);
4482 DEF_VEC_ALLOC_O(alias_pair
,gc
);
4484 static GTY(()) VEC(alias_pair
,gc
) *alias_pairs
;
4486 /* Given an assembly name, find the decl it is associated with. At the
4487 same time, mark it needed for cgraph. */
4490 find_decl_and_mark_needed (tree decl
, tree target
)
4492 struct cgraph_node
*fnode
= NULL
;
4493 struct cgraph_varpool_node
*vnode
= NULL
;
4495 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4497 fnode
= cgraph_node_for_asm (target
);
4499 vnode
= cgraph_varpool_node_for_asm (target
);
4503 vnode
= cgraph_varpool_node_for_asm (target
);
4505 fnode
= cgraph_node_for_asm (target
);
4510 /* We can't mark function nodes as used after cgraph global info
4511 is finished. This wouldn't generally be necessary, but C++
4512 virtual table thunks are introduced late in the game and
4513 might seem like they need marking, although in fact they
4515 if (! cgraph_global_info_ready
)
4516 cgraph_mark_needed_node (fnode
);
4521 cgraph_varpool_mark_needed_node (vnode
);
4528 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
4529 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
4530 tree node is DECL to have the value of the tree node TARGET. */
4533 do_assemble_alias (tree decl
, tree target
)
4535 if (TREE_ASM_WRITTEN (decl
))
4538 TREE_ASM_WRITTEN (decl
) = 1;
4539 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
4541 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
4543 ultimate_transparent_alias_target (&target
);
4545 if (!TREE_SYMBOL_REFERENCED (target
))
4546 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
4548 #ifdef ASM_OUTPUT_WEAKREF
4549 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
4550 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
4551 IDENTIFIER_POINTER (target
));
4555 error ("%Jweakref is not supported in this configuration", decl
);
4562 #ifdef ASM_OUTPUT_DEF
4563 /* Make name accessible from other files, if appropriate. */
4565 if (TREE_PUBLIC (decl
))
4567 globalize_decl (decl
);
4568 maybe_assemble_visibility (decl
);
4571 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
4572 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4574 ASM_OUTPUT_DEF (asm_out_file
,
4575 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
4576 IDENTIFIER_POINTER (target
));
4578 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4583 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4584 # ifdef ASM_WEAKEN_DECL
4585 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
4587 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4589 /* Remove this function from the pending weak list so that
4590 we do not emit multiple .weak directives for it. */
4591 for (p
= &weak_decls
; (t
= *p
) ; )
4592 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
4593 *p
= TREE_CHAIN (t
);
4595 p
= &TREE_CHAIN (t
);
4597 /* Remove weakrefs to the same target from the pending weakref
4598 list, for the same reason. */
4599 for (p
= &weakref_targets
; (t
= *p
) ; )
4601 if (DECL_ASSEMBLER_NAME (decl
)
4602 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
4603 *p
= TREE_CHAIN (t
);
4605 p
= &TREE_CHAIN (t
);
4611 /* First pass of completing pending aliases. Make sure that cgraph knows
4612 which symbols will be required. */
4615 finish_aliases_1 (void)
4620 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
4624 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
4625 if (target_decl
== NULL
)
4627 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
4628 error ("%q+D aliased to undefined symbol %qs",
4629 p
->decl
, IDENTIFIER_POINTER (p
->target
));
4631 else if (DECL_EXTERNAL (target_decl
)
4632 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
4633 error ("%q+D aliased to external symbol %qs",
4634 p
->decl
, IDENTIFIER_POINTER (p
->target
));
4638 /* Second pass of completing pending aliases. Emit the actual assembly.
4639 This happens at the end of compilation and thus it is assured that the
4640 target symbol has been emitted. */
4643 finish_aliases_2 (void)
4648 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
4649 do_assemble_alias (p
->decl
, p
->target
);
4651 VEC_truncate (alias_pair
, alias_pairs
, 0);
4654 /* Emit an assembler directive to make the symbol for DECL an alias to
4655 the symbol for TARGET. */
4658 assemble_alias (tree decl
, tree target
)
4661 bool is_weakref
= false;
4663 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
4665 tree alias
= DECL_ASSEMBLER_NAME (decl
);
4669 ultimate_transparent_alias_target (&target
);
4671 if (alias
== target
)
4672 error ("weakref %q+D ultimately targets itself", decl
);
4675 #ifndef ASM_OUTPUT_WEAKREF
4676 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
4677 TREE_CHAIN (alias
) = target
;
4680 if (TREE_PUBLIC (decl
))
4681 error ("weakref %q+D must have static linkage", decl
);
4685 #if !defined (ASM_OUTPUT_DEF)
4686 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
4687 error ("%Jalias definitions not supported in this configuration", decl
);
4690 if (!DECL_WEAK (decl
))
4692 error ("%Jonly weak aliases are supported in this configuration", decl
);
4699 /* We must force creation of DECL_RTL for debug info generation, even though
4700 we don't use it here. */
4701 make_decl_rtl (decl
);
4702 TREE_USED (decl
) = 1;
4704 /* A quirk of the initial implementation of aliases required that the user
4705 add "extern" to all of them. Which is silly, but now historical. Do
4706 note that the symbol is in fact locally defined. */
4708 DECL_EXTERNAL (decl
) = 0;
4710 /* Allow aliases to aliases. */
4711 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4712 cgraph_node (decl
)->alias
= true;
4714 cgraph_varpool_node (decl
)->alias
= true;
4716 /* If the target has already been emitted, we don't have to queue the
4717 alias. This saves a tad o memory. */
4718 target_decl
= find_decl_and_mark_needed (decl
, target
);
4719 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
4720 do_assemble_alias (decl
, target
);
4723 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
4729 /* Emit an assembler directive to set symbol for DECL visibility to
4730 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4733 default_assemble_visibility (tree decl
, int vis
)
4735 static const char * const visibility_types
[] = {
4736 NULL
, "internal", "hidden", "protected"
4739 const char *name
, *type
;
4741 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4742 type
= visibility_types
[vis
];
4744 #ifdef HAVE_GAS_HIDDEN
4745 fprintf (asm_out_file
, "\t.%s\t", type
);
4746 assemble_name (asm_out_file
, name
);
4747 fprintf (asm_out_file
, "\n");
4749 warning (OPT_Wattributes
, "visibility attribute not supported "
4750 "in this configuration; ignored");
4754 /* A helper function to call assemble_visibility when needed for a decl. */
4757 maybe_assemble_visibility (tree decl
)
4759 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
4761 if (vis
!= VISIBILITY_DEFAULT
)
4762 targetm
.asm_out
.visibility (decl
, vis
);
4765 /* Returns 1 if the target configuration supports defining public symbols
4766 so that one of them will be chosen at link time instead of generating a
4767 multiply-defined symbol error, whether through the use of weak symbols or
4768 a target-specific mechanism for having duplicates discarded. */
4771 supports_one_only (void)
4773 if (SUPPORTS_ONE_ONLY
)
4775 return SUPPORTS_WEAK
;
4778 /* Set up DECL as a public symbol that can be defined in multiple
4779 translation units without generating a linker error. */
4782 make_decl_one_only (tree decl
)
4784 gcc_assert (TREE_CODE (decl
) == VAR_DECL
4785 || TREE_CODE (decl
) == FUNCTION_DECL
);
4787 TREE_PUBLIC (decl
) = 1;
4789 if (SUPPORTS_ONE_ONLY
)
4791 #ifdef MAKE_DECL_ONE_ONLY
4792 MAKE_DECL_ONE_ONLY (decl
);
4794 DECL_ONE_ONLY (decl
) = 1;
4796 else if (TREE_CODE (decl
) == VAR_DECL
4797 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
4798 DECL_COMMON (decl
) = 1;
4801 gcc_assert (SUPPORTS_WEAK
);
4802 DECL_WEAK (decl
) = 1;
4807 init_varasm_once (void)
4809 section_htab
= htab_create_ggc (31, section_entry_hash
,
4810 section_entry_eq
, NULL
);
4811 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
4812 const_desc_eq
, NULL
);
4814 const_alias_set
= new_alias_set ();
4816 #ifdef TEXT_SECTION_ASM_OP
4817 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
4818 TEXT_SECTION_ASM_OP
);
4821 #ifdef DATA_SECTION_ASM_OP
4822 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
4823 DATA_SECTION_ASM_OP
);
4826 #ifdef SDATA_SECTION_ASM_OP
4827 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
4828 SDATA_SECTION_ASM_OP
);
4831 #ifdef READONLY_DATA_SECTION_ASM_OP
4832 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
4833 READONLY_DATA_SECTION_ASM_OP
);
4836 #ifdef CTORS_SECTION_ASM_OP
4837 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
4838 CTORS_SECTION_ASM_OP
);
4841 #ifdef DTORS_SECTION_ASM_OP
4842 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
4843 DTORS_SECTION_ASM_OP
);
4846 #ifdef BSS_SECTION_ASM_OP
4847 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
4848 output_section_asm_op
,
4849 BSS_SECTION_ASM_OP
);
4852 #ifdef SBSS_SECTION_ASM_OP
4853 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
4854 output_section_asm_op
,
4855 SBSS_SECTION_ASM_OP
);
4858 targetm
.asm_out
.init_sections ();
4860 if (readonly_data_section
== NULL
)
4861 readonly_data_section
= text_section
;
4865 decl_default_tls_model (tree decl
)
4867 enum tls_model kind
;
4870 is_local
= targetm
.binds_local_p (decl
);
4874 kind
= TLS_MODEL_LOCAL_EXEC
;
4876 kind
= TLS_MODEL_INITIAL_EXEC
;
4879 /* Local dynamic is inefficient when we're not combining the
4880 parts of the address. */
4881 else if (optimize
&& is_local
)
4882 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
4884 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
4885 if (kind
< flag_tls_default
)
4886 kind
= flag_tls_default
;
4891 /* Select a set of attributes for section NAME based on the properties
4892 of DECL and whether or not RELOC indicates that DECL's initializer
4893 might contain runtime relocations.
4895 We make the section read-only and executable for a function decl,
4896 read-only for a const data decl, and writable for a non-const data decl. */
4899 default_section_type_flags (tree decl
, const char *name
, int reloc
)
4901 return default_section_type_flags_1 (decl
, name
, reloc
, flag_pic
);
4905 default_section_type_flags_1 (tree decl
, const char *name
, int reloc
,
4910 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
4911 flags
= SECTION_CODE
;
4912 else if (decl
&& decl_readonly_section_1 (decl
, reloc
, shlib
))
4914 else if (current_function_decl
4916 && cfun
->unlikely_text_section_name
4917 && strcmp (name
, cfun
->unlikely_text_section_name
) == 0)
4918 flags
= SECTION_CODE
;
4920 && (!current_function_decl
|| !cfun
)
4921 && strcmp (name
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
4922 flags
= SECTION_CODE
;
4924 flags
= SECTION_WRITE
;
4926 if (decl
&& DECL_ONE_ONLY (decl
))
4927 flags
|= SECTION_LINKONCE
;
4929 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
4930 flags
|= SECTION_TLS
| SECTION_WRITE
;
4932 if (strcmp (name
, ".bss") == 0
4933 || strncmp (name
, ".bss.", 5) == 0
4934 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
4935 || strcmp (name
, ".sbss") == 0
4936 || strncmp (name
, ".sbss.", 6) == 0
4937 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
4938 flags
|= SECTION_BSS
;
4940 if (strcmp (name
, ".tdata") == 0
4941 || strncmp (name
, ".tdata.", 7) == 0
4942 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
4943 flags
|= SECTION_TLS
;
4945 if (strcmp (name
, ".tbss") == 0
4946 || strncmp (name
, ".tbss.", 6) == 0
4947 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
4948 flags
|= SECTION_TLS
| SECTION_BSS
;
4950 /* These three sections have special ELF types. They are neither
4951 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4952 want to print a section type (@progbits or @nobits). If someone
4953 is silly enough to emit code or TLS variables to one of these
4954 sections, then don't handle them specially. */
4955 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
4956 && (strcmp (name
, ".init_array") == 0
4957 || strcmp (name
, ".fini_array") == 0
4958 || strcmp (name
, ".preinit_array") == 0))
4959 flags
|= SECTION_NOTYPE
;
4964 /* Output assembly to switch to section NAME with attribute FLAGS.
4965 Four variants for common object file formats. */
4968 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
4969 unsigned int flags ATTRIBUTE_UNUSED
,
4970 tree decl ATTRIBUTE_UNUSED
)
4972 /* Some object formats don't support named sections at all. The
4973 front-end should already have flagged this as an error. */
4978 default_elf_asm_named_section (const char *name
, unsigned int flags
,
4979 tree decl ATTRIBUTE_UNUSED
)
4981 char flagchars
[10], *f
= flagchars
;
4983 /* If we have already declared this section, we can use an
4984 abbreviated form to switch back to it -- unless this section is
4985 part of a COMDAT groups, in which case GAS requires the full
4986 declaration every time. */
4987 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
4988 && (flags
& SECTION_DECLARED
))
4990 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
4994 if (!(flags
& SECTION_DEBUG
))
4996 if (flags
& SECTION_WRITE
)
4998 if (flags
& SECTION_CODE
)
5000 if (flags
& SECTION_SMALL
)
5002 if (flags
& SECTION_MERGE
)
5004 if (flags
& SECTION_STRINGS
)
5006 if (flags
& SECTION_TLS
)
5008 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5012 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
5014 if (!(flags
& SECTION_NOTYPE
))
5019 if (flags
& SECTION_BSS
)
5025 #ifdef ASM_COMMENT_START
5026 /* On platforms that use "@" as the assembly comment character,
5028 if (strcmp (ASM_COMMENT_START
, "@") == 0)
5031 fprintf (asm_out_file
, format
, type
);
5033 if (flags
& SECTION_ENTSIZE
)
5034 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
5035 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
5036 fprintf (asm_out_file
, ",%s,comdat",
5037 lang_hooks
.decls
.comdat_group (decl
));
5040 putc ('\n', asm_out_file
);
5044 default_coff_asm_named_section (const char *name
, unsigned int flags
,
5045 tree decl ATTRIBUTE_UNUSED
)
5047 char flagchars
[8], *f
= flagchars
;
5049 if (flags
& SECTION_WRITE
)
5051 if (flags
& SECTION_CODE
)
5055 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
5059 default_pe_asm_named_section (const char *name
, unsigned int flags
,
5062 default_coff_asm_named_section (name
, flags
, decl
);
5064 if (flags
& SECTION_LINKONCE
)
5066 /* Functions may have been compiled at various levels of
5067 optimization so we can't use `same_size' here.
5068 Instead, have the linker pick one. */
5069 fprintf (asm_out_file
, "\t.linkonce %s\n",
5070 (flags
& SECTION_CODE
? "discard" : "same_size"));
5074 /* The lame default section selector. */
5077 default_select_section (tree decl
, int reloc
,
5078 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
5082 if (decl_readonly_section (decl
, reloc
))
5083 return readonly_data_section
;
5085 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5087 if (! ((flag_pic
&& reloc
)
5088 || !TREE_READONLY (decl
)
5089 || TREE_SIDE_EFFECTS (decl
)
5090 || !TREE_CONSTANT (decl
)))
5091 return readonly_data_section
;
5093 else if (TREE_CODE (decl
) == STRING_CST
)
5094 return readonly_data_section
;
5095 else if (! (flag_pic
&& reloc
))
5096 return readonly_data_section
;
5098 return data_section
;
5101 enum section_category
5102 categorize_decl_for_section (tree decl
, int reloc
, int shlib
)
5104 enum section_category ret
;
5106 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5108 else if (TREE_CODE (decl
) == STRING_CST
)
5110 if (flag_mudflap
) /* or !flag_merge_constants */
5111 return SECCAT_RODATA
;
5113 return SECCAT_RODATA_MERGE_STR
;
5115 else if (TREE_CODE (decl
) == VAR_DECL
)
5117 if (DECL_INITIAL (decl
) == NULL
5118 || DECL_INITIAL (decl
) == error_mark_node
5119 || (flag_zero_initialized_in_bss
5120 /* Leave constant zeroes in .rodata so they can be shared. */
5121 && !TREE_READONLY (decl
)
5122 && initializer_zerop (DECL_INITIAL (decl
))))
5124 else if (! TREE_READONLY (decl
)
5125 || TREE_SIDE_EFFECTS (decl
)
5126 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
5128 if (shlib
&& (reloc
& 2))
5129 ret
= SECCAT_DATA_REL
;
5130 else if (shlib
&& reloc
)
5131 ret
= SECCAT_DATA_REL_LOCAL
;
5135 else if (shlib
&& (reloc
& 2))
5136 ret
= SECCAT_DATA_REL_RO
;
5137 else if (shlib
&& reloc
)
5138 ret
= SECCAT_DATA_REL_RO_LOCAL
;
5139 else if (reloc
|| flag_merge_constants
< 2)
5140 /* C and C++ don't allow different variables to share the same
5141 location. -fmerge-all-constants allows even that (at the
5142 expense of not conforming). */
5143 ret
= SECCAT_RODATA
;
5144 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
5145 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
5147 ret
= SECCAT_RODATA_MERGE_CONST
;
5149 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5151 if ((shlib
&& reloc
)
5152 || TREE_SIDE_EFFECTS (decl
)
5153 || ! TREE_CONSTANT (decl
))
5156 ret
= SECCAT_RODATA
;
5159 ret
= SECCAT_RODATA
;
5161 /* There are no read-only thread-local sections. */
5162 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
5164 /* Note that this would be *just* SECCAT_BSS, except that there's
5165 no concept of a read-only thread-local-data section. */
5166 if (ret
== SECCAT_BSS
5167 || (flag_zero_initialized_in_bss
5168 && initializer_zerop (DECL_INITIAL (decl
))))
5174 /* If the target uses small data sections, select it. */
5175 else if (targetm
.in_small_data_p (decl
))
5177 if (ret
== SECCAT_BSS
)
5179 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
5180 ret
= SECCAT_SRODATA
;
5189 decl_readonly_section (tree decl
, int reloc
)
5191 return decl_readonly_section_1 (decl
, reloc
, flag_pic
);
5195 decl_readonly_section_1 (tree decl
, int reloc
, int shlib
)
5197 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5200 case SECCAT_RODATA_MERGE_STR
:
5201 case SECCAT_RODATA_MERGE_STR_INIT
:
5202 case SECCAT_RODATA_MERGE_CONST
:
5203 case SECCAT_SRODATA
:
5212 /* Select a section based on the above categorization. */
5215 default_elf_select_section (tree decl
, int reloc
,
5216 unsigned HOST_WIDE_INT align
)
5218 return default_elf_select_section_1 (decl
, reloc
, align
, flag_pic
);
5222 default_elf_select_section_1 (tree decl
, int reloc
,
5223 unsigned HOST_WIDE_INT align
, int shlib
)
5226 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5229 /* We're not supposed to be called on FUNCTION_DECLs. */
5232 return readonly_data_section
;
5233 case SECCAT_RODATA_MERGE_STR
:
5234 return mergeable_string_section (decl
, align
, 0);
5235 case SECCAT_RODATA_MERGE_STR_INIT
:
5236 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
5237 case SECCAT_RODATA_MERGE_CONST
:
5238 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
5239 case SECCAT_SRODATA
:
5243 return data_section
;
5244 case SECCAT_DATA_REL
:
5245 sname
= ".data.rel";
5247 case SECCAT_DATA_REL_LOCAL
:
5248 sname
= ".data.rel.local";
5250 case SECCAT_DATA_REL_RO
:
5251 sname
= ".data.rel.ro";
5253 case SECCAT_DATA_REL_RO_LOCAL
:
5254 sname
= ".data.rel.ro.local";
5279 return get_named_section (decl
, sname
, reloc
);
5282 /* Construct a unique section name based on the decl name and the
5283 categorization performed above. */
5286 default_unique_section (tree decl
, int reloc
)
5288 default_unique_section_1 (decl
, reloc
, flag_pic
);
5292 default_unique_section_1 (tree decl
, int reloc
, int shlib
)
5294 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
5295 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
5296 const char *prefix
, *name
;
5300 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5303 prefix
= one_only
? ".gnu.linkonce.t." : ".text.";
5306 case SECCAT_RODATA_MERGE_STR
:
5307 case SECCAT_RODATA_MERGE_STR_INIT
:
5308 case SECCAT_RODATA_MERGE_CONST
:
5309 prefix
= one_only
? ".gnu.linkonce.r." : ".rodata.";
5311 case SECCAT_SRODATA
:
5312 prefix
= one_only
? ".gnu.linkonce.s2." : ".sdata2.";
5315 case SECCAT_DATA_REL
:
5316 case SECCAT_DATA_REL_LOCAL
:
5317 case SECCAT_DATA_REL_RO
:
5318 case SECCAT_DATA_REL_RO_LOCAL
:
5319 prefix
= one_only
? ".gnu.linkonce.d." : ".data.";
5322 prefix
= one_only
? ".gnu.linkonce.s." : ".sdata.";
5325 prefix
= one_only
? ".gnu.linkonce.b." : ".bss.";
5328 prefix
= one_only
? ".gnu.linkonce.sb." : ".sbss.";
5331 prefix
= one_only
? ".gnu.linkonce.td." : ".tdata.";
5334 prefix
= one_only
? ".gnu.linkonce.tb." : ".tbss.";
5339 plen
= strlen (prefix
);
5341 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5342 name
= targetm
.strip_name_encoding (name
);
5343 nlen
= strlen (name
);
5345 string
= alloca (nlen
+ plen
+ 1);
5346 memcpy (string
, prefix
, plen
);
5347 memcpy (string
+ plen
, name
, nlen
+ 1);
5349 DECL_SECTION_NAME (decl
) = build_string (nlen
+ plen
, string
);
5353 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
5355 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
5358 switch (GET_CODE (x
))
5363 return data_section
;
5369 return readonly_data_section
;
5373 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
5374 unsigned HOST_WIDE_INT align
)
5376 /* ??? Handle small data here somehow. */
5379 switch (GET_CODE (x
))
5383 return get_named_section (NULL
, ".data.rel.ro", 3);
5386 return get_named_section (NULL
, ".data.rel.ro.local", 1);
5392 return mergeable_constant_section (mode
, align
, 0);
5395 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5398 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
5403 /* Careful not to prod global register variables. */
5406 symbol
= XEXP (rtl
, 0);
5407 if (GET_CODE (symbol
) != SYMBOL_REF
)
5411 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5412 flags
|= SYMBOL_FLAG_FUNCTION
;
5413 if (targetm
.binds_local_p (decl
))
5414 flags
|= SYMBOL_FLAG_LOCAL
;
5415 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
5416 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
5417 else if (targetm
.in_small_data_p (decl
))
5418 flags
|= SYMBOL_FLAG_SMALL
;
5419 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5420 being PUBLIC, the thing *must* be defined in this translation unit.
5421 Prevent this buglet from being propagated into rtl code as well. */
5422 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
5423 flags
|= SYMBOL_FLAG_EXTERNAL
;
5425 SYMBOL_REF_FLAGS (symbol
) = flags
;
5428 /* By default, we do nothing for encode_section_info, so we need not
5429 do anything but discard the '*' marker. */
5432 default_strip_name_encoding (const char *str
)
5434 return str
+ (*str
== '*');
5437 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5438 wrt cross-module name binding. */
5441 default_binds_local_p (tree exp
)
5443 return default_binds_local_p_1 (exp
, flag_shlib
);
5447 default_binds_local_p_1 (tree exp
, int shlib
)
5451 /* A non-decl is an entry in the constant pool. */
5454 /* Weakrefs may not bind locally, even though the weakref itself is
5455 always static and therefore local. */
5456 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
5458 /* Static variables are always local. */
5459 else if (! TREE_PUBLIC (exp
))
5461 /* A variable is local if the user has said explicitly that it will
5463 else if (DECL_VISIBILITY_SPECIFIED (exp
)
5464 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
5466 /* Variables defined outside this object might not be local. */
5467 else if (DECL_EXTERNAL (exp
))
5469 /* If defined in this object and visibility is not default, must be
5471 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
5473 /* Default visibility weak data can be overridden by a strong symbol
5474 in another module and so are not local. */
5475 else if (DECL_WEAK (exp
))
5477 /* If PIC, then assume that any global name can be overridden by
5478 symbols resolved from other modules. */
5481 /* Uninitialized COMMON variable may be unified with symbols
5482 resolved from other modules. */
5483 else if (DECL_COMMON (exp
)
5484 && (DECL_INITIAL (exp
) == NULL
5485 || DECL_INITIAL (exp
) == error_mark_node
))
5487 /* Otherwise we're left with initialized (or non-common) global data
5488 which is of necessity defined locally. */
5495 /* Determine whether or not a pointer mode is valid. Assume defaults
5496 of ptr_mode or Pmode - can be overridden. */
5498 default_valid_pointer_mode (enum machine_mode mode
)
5500 return (mode
== ptr_mode
|| mode
== Pmode
);
5503 /* Default function to output code that will globalize a label. A
5504 target must define GLOBAL_ASM_OP or provide its own function to
5505 globalize a label. */
5506 #ifdef GLOBAL_ASM_OP
5508 default_globalize_label (FILE * stream
, const char *name
)
5510 fputs (GLOBAL_ASM_OP
, stream
);
5511 assemble_name (stream
, name
);
5512 putc ('\n', stream
);
5514 #endif /* GLOBAL_ASM_OP */
5516 /* Default function to output a label for unwind information. The
5517 default is to do nothing. A target that needs nonlocal labels for
5518 unwind information must provide its own function to do this. */
5520 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
5521 tree decl ATTRIBUTE_UNUSED
,
5522 int for_eh ATTRIBUTE_UNUSED
,
5523 int empty ATTRIBUTE_UNUSED
)
5527 /* This is how to output an internal numbered label where PREFIX is
5528 the class of label and LABELNO is the number within the class. */
5531 default_internal_label (FILE *stream
, const char *prefix
,
5532 unsigned long labelno
)
5534 char *const buf
= alloca (40 + strlen (prefix
));
5535 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
5536 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
5539 /* This is the default behavior at the beginning of a file. It's
5540 controlled by two other target-hook toggles. */
5542 default_file_start (void)
5544 if (targetm
.file_start_app_off
&& !flag_verbose_asm
)
5545 fputs (ASM_APP_OFF
, asm_out_file
);
5547 if (targetm
.file_start_file_directive
)
5548 output_file_directive (asm_out_file
, main_input_filename
);
5551 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5552 which emits a special section directive used to indicate whether or
5553 not this object file needs an executable stack. This is primarily
5554 a GNU extension to ELF but could be used on other targets. */
5556 int trampolines_created
;
5559 file_end_indicate_exec_stack (void)
5561 unsigned int flags
= SECTION_DEBUG
;
5562 if (trampolines_created
)
5563 flags
|= SECTION_CODE
;
5565 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
5568 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
5569 a get_unnamed_section callback. */
5572 output_section_asm_op (const void *directive
)
5574 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
5577 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
5578 the current section is NEW_SECTION. */
5581 switch_to_section (section
*new_section
)
5583 if (in_section
== new_section
)
5586 if (new_section
->common
.flags
& SECTION_FORGET
)
5590 in_section
= new_section
;
5591 if (new_section
->common
.flags
& SECTION_CODE
)
5592 last_text_section
= in_section
;
5595 if (new_section
->common
.flags
& SECTION_NAMED
)
5598 && !cfun
->unlikely_text_section_name
5599 && strcmp (new_section
->named
.name
,
5600 UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
5601 cfun
->unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
5603 targetm
.asm_out
.named_section (new_section
->named
.name
,
5604 new_section
->named
.common
.flags
,
5605 new_section
->named
.decl
);
5608 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
5610 new_section
->common
.flags
|= SECTION_DECLARED
;
5613 #include "gt-varasm.h"