osf.h (TARGET_OS_CPP_BUILTINS): Define __STDC_VERSION__ to ISO C94 for C++.
[gcc.git] / gcc / varasm.c
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 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
26
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
29
30 #include "config.h"
31 #include "system.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #include "rtl.h"
35 #include "tree.h"
36 #include "flags.h"
37 #include "function.h"
38 #include "expr.h"
39 #include "hard-reg-set.h"
40 #include "regs.h"
41 #include "real.h"
42 #include "output.h"
43 #include "toplev.h"
44 #include "hashtab.h"
45 #include "c-pragma.h"
46 #include "ggc.h"
47 #include "langhooks.h"
48 #include "tm_p.h"
49 #include "debug.h"
50 #include "target.h"
51 #include "cgraph.h"
52
53 #ifdef XCOFF_DEBUGGING_INFO
54 #include "xcoffout.h" /* Needed for external data
55 declarations for e.g. AIX 4.x. */
56 #endif
57
58 #ifndef TRAMPOLINE_ALIGNMENT
59 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
60 #endif
61
62 #ifndef ASM_STABS_OP
63 #define ASM_STABS_OP "\t.stabs\t"
64 #endif
65
66 /* The (assembler) name of the first globally-visible object output. */
67 const char *first_global_object_name;
68 const char *weak_global_object_name;
69
70 struct addr_const;
71 struct constant_descriptor_rtx;
72 struct rtx_const;
73 struct pool_constant;
74
75 #define MAX_RTX_HASH_TABLE 61
76
77 struct varasm_status GTY(())
78 {
79 /* Hash facility for making memory-constants
80 from constant rtl-expressions. It is used on RISC machines
81 where immediate integer arguments and constant addresses are restricted
82 so that such constants must be stored in memory.
83
84 This pool of constants is reinitialized for each function
85 so each function gets its own constants-pool that comes right before
86 it. */
87 struct constant_descriptor_rtx ** GTY ((length ("MAX_RTX_HASH_TABLE")))
88 x_const_rtx_hash_table;
89 struct pool_constant ** GTY ((length ("MAX_RTX_HASH_TABLE")))
90 x_const_rtx_sym_hash_table;
91
92 /* Pointers to first and last constant in pool. */
93 struct pool_constant *x_first_pool;
94 struct pool_constant *x_last_pool;
95
96 /* Current offset in constant pool (does not include any machine-specific
97 header). */
98 HOST_WIDE_INT x_pool_offset;
99
100 /* Number of tree-constants deferred during the expansion of this
101 function. */
102 unsigned int deferred_constants;
103 };
104
105 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
106 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
107 #define first_pool (cfun->varasm->x_first_pool)
108 #define last_pool (cfun->varasm->x_last_pool)
109 #define pool_offset (cfun->varasm->x_pool_offset)
110 #define n_deferred_constants (cfun->varasm->deferred_constants)
111
112 /* Number for making the label on the next
113 constant that is stored in memory. */
114
115 static GTY(()) int const_labelno;
116
117 /* Carry information from ASM_DECLARE_OBJECT_NAME
118 to ASM_FINISH_DECLARE_OBJECT. */
119
120 int size_directive_output;
121
122 /* The last decl for which assemble_variable was called,
123 if it did ASM_DECLARE_OBJECT_NAME.
124 If the last call to assemble_variable didn't do that,
125 this holds 0. */
126
127 tree last_assemble_variable_decl;
128
129 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
130 So giving constant the alias set for the type will allow such
131 initializations to appear to conflict with the load of the constant. We
132 avoid this by giving all constants an alias set for just constants.
133 Since there will be no stores to that alias set, nothing will ever
134 conflict with them. */
135
136 static HOST_WIDE_INT const_alias_set;
137
138 static const char *strip_reg_name (const char *);
139 static int contains_pointers_p (tree);
140 #ifdef ASM_OUTPUT_EXTERNAL
141 static bool incorporeal_function_p (tree);
142 #endif
143 static void decode_addr_const (tree, struct addr_const *);
144 static hashval_t const_desc_hash (const void *);
145 static int const_desc_eq (const void *, const void *);
146 static hashval_t const_hash_1 (const tree);
147 static int compare_constant (const tree, const tree);
148 static tree copy_constant (tree);
149 static void output_constant_def_contents (rtx);
150 static void decode_rtx_const (enum machine_mode, rtx, struct rtx_const *);
151 static unsigned int const_hash_rtx (enum machine_mode, rtx);
152 static int compare_constant_rtx (enum machine_mode, rtx,
153 struct constant_descriptor_rtx *);
154 static struct constant_descriptor_rtx * record_constant_rtx
155 (enum machine_mode, rtx);
156 static struct pool_constant *find_pool_constant (struct function *, rtx);
157 static void mark_constant_pool (void);
158 static void mark_constants (rtx);
159 static int mark_constant (rtx *current_rtx, void *data);
160 static void output_addressed_constants (tree);
161 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
162 static unsigned min_align (unsigned, unsigned);
163 static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int);
164 static void globalize_decl (tree);
165 static void maybe_assemble_visibility (tree);
166 static int in_named_entry_eq (const void *, const void *);
167 static hashval_t in_named_entry_hash (const void *);
168 #ifdef ASM_OUTPUT_BSS
169 static void asm_output_bss (FILE *, tree, const char *,
170 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
171 #endif
172 #ifdef BSS_SECTION_ASM_OP
173 #ifdef ASM_OUTPUT_ALIGNED_BSS
174 static void asm_output_aligned_bss (FILE *, tree, const char *,
175 unsigned HOST_WIDE_INT, int)
176 ATTRIBUTE_UNUSED;
177 #endif
178 #endif /* BSS_SECTION_ASM_OP */
179 static bool asm_emit_uninitialised (tree, const char*,
180 unsigned HOST_WIDE_INT,
181 unsigned HOST_WIDE_INT);
182 static void mark_weak (tree);
183 \f
184 enum in_section { no_section, in_text, in_data, in_named
185 #ifdef BSS_SECTION_ASM_OP
186 , in_bss
187 #endif
188 #ifdef CTORS_SECTION_ASM_OP
189 , in_ctors
190 #endif
191 #ifdef DTORS_SECTION_ASM_OP
192 , in_dtors
193 #endif
194 #ifdef READONLY_DATA_SECTION_ASM_OP
195 , in_readonly_data
196 #endif
197 #ifdef EXTRA_SECTIONS
198 , EXTRA_SECTIONS
199 #endif
200 };
201 static GTY(()) enum in_section in_section = no_section;
202
203 /* Return a nonzero value if DECL has a section attribute. */
204 #ifndef IN_NAMED_SECTION
205 #define IN_NAMED_SECTION(DECL) \
206 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
207 && DECL_SECTION_NAME (DECL) != NULL_TREE)
208 #endif
209
210 /* Text of section name when in_section == in_named. */
211 static GTY(()) const char *in_named_name;
212
213 /* Hash table of flags that have been used for a particular named section. */
214
215 struct in_named_entry GTY(())
216 {
217 const char *name;
218 unsigned int flags;
219 bool declared;
220 };
221
222 static GTY((param_is (struct in_named_entry))) htab_t in_named_htab;
223
224 /* Define functions like text_section for any extra sections. */
225 #ifdef EXTRA_SECTION_FUNCTIONS
226 EXTRA_SECTION_FUNCTIONS
227 #endif
228
229 /* Tell assembler to switch to text section. */
230
231 void
232 text_section (void)
233 {
234 if (in_section != in_text)
235 {
236 in_section = in_text;
237 #ifdef TEXT_SECTION
238 TEXT_SECTION ();
239 #else
240 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
241 #endif
242 }
243 }
244
245 /* Tell assembler to switch to data section. */
246
247 void
248 data_section (void)
249 {
250 if (in_section != in_data)
251 {
252 in_section = in_data;
253 if (flag_shared_data)
254 {
255 #ifdef SHARED_SECTION_ASM_OP
256 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
257 #else
258 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
259 #endif
260 }
261 else
262 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
263 }
264 }
265
266 /* Tell assembler to switch to read-only data section. This is normally
267 the text section. */
268
269 void
270 readonly_data_section (void)
271 {
272 #ifdef READONLY_DATA_SECTION
273 READONLY_DATA_SECTION (); /* Note this can call data_section. */
274 #else
275 #ifdef READONLY_DATA_SECTION_ASM_OP
276 if (in_section != in_readonly_data)
277 {
278 in_section = in_readonly_data;
279 fputs (READONLY_DATA_SECTION_ASM_OP, asm_out_file);
280 fputc ('\n', asm_out_file);
281 }
282 #else
283 text_section ();
284 #endif
285 #endif
286 }
287
288 /* Determine if we're in the text section. */
289
290 int
291 in_text_section (void)
292 {
293 return in_section == in_text;
294 }
295
296 /* Determine if we're in the data section. */
297
298 int
299 in_data_section (void)
300 {
301 return in_section == in_data;
302 }
303
304 /* Helper routines for maintaining in_named_htab. */
305
306 static int
307 in_named_entry_eq (const void *p1, const void *p2)
308 {
309 const struct in_named_entry *old = p1;
310 const char *new = p2;
311
312 return strcmp (old->name, new) == 0;
313 }
314
315 static hashval_t
316 in_named_entry_hash (const void *p)
317 {
318 const struct in_named_entry *old = p;
319 return htab_hash_string (old->name);
320 }
321
322 /* If SECTION has been seen before as a named section, return the flags
323 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
324 set of flags for a section to have, so 0 does not mean that the section
325 has not been seen. */
326
327 unsigned int
328 get_named_section_flags (const char *section)
329 {
330 struct in_named_entry **slot;
331
332 slot = (struct in_named_entry **)
333 htab_find_slot_with_hash (in_named_htab, section,
334 htab_hash_string (section), NO_INSERT);
335
336 return slot ? (*slot)->flags : 0;
337 }
338
339 /* Returns true if the section has been declared before. Sets internal
340 flag on this section in in_named_hash so subsequent calls on this
341 section will return false. */
342
343 bool
344 named_section_first_declaration (const char *name)
345 {
346 struct in_named_entry **slot;
347
348 slot = (struct in_named_entry **)
349 htab_find_slot_with_hash (in_named_htab, name,
350 htab_hash_string (name), NO_INSERT);
351 if (! (*slot)->declared)
352 {
353 (*slot)->declared = true;
354 return true;
355 }
356 else
357 {
358 return false;
359 }
360 }
361
362
363 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
364 different set of flags, return false. */
365
366 bool
367 set_named_section_flags (const char *section, unsigned int flags)
368 {
369 struct in_named_entry **slot, *entry;
370
371 slot = (struct in_named_entry **)
372 htab_find_slot_with_hash (in_named_htab, section,
373 htab_hash_string (section), INSERT);
374 entry = *slot;
375
376 if (!entry)
377 {
378 entry = ggc_alloc (sizeof (*entry));
379 *slot = entry;
380 entry->name = ggc_strdup (section);
381 entry->flags = flags;
382 entry->declared = false;
383 }
384 else if (entry->flags != flags)
385 return false;
386
387 return true;
388 }
389
390 /* Tell assembler to change to section NAME with attributes FLAGS. */
391
392 void
393 named_section_flags (const char *name, unsigned int flags)
394 {
395 if (in_section != in_named || strcmp (name, in_named_name) != 0)
396 {
397 if (! set_named_section_flags (name, flags))
398 abort ();
399
400 (*targetm.asm_out.named_section) (name, flags);
401
402 if (flags & SECTION_FORGET)
403 in_section = no_section;
404 else
405 {
406 in_named_name = ggc_strdup (name);
407 in_section = in_named;
408 }
409 }
410 }
411
412 /* Tell assembler to change to section NAME for DECL.
413 If DECL is NULL, just switch to section NAME.
414 If NAME is NULL, get the name from DECL.
415 If RELOC is 1, the initializer for DECL contains relocs. */
416
417 void
418 named_section (tree decl, const char *name, int reloc)
419 {
420 unsigned int flags;
421
422 if (decl != NULL_TREE && !DECL_P (decl))
423 abort ();
424 if (name == NULL)
425 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
426
427 flags = (* targetm.section_type_flags) (decl, name, reloc);
428
429 /* Sanity check user variables for flag changes. Non-user
430 section flag changes will abort in named_section_flags.
431 However, don't complain if SECTION_OVERRIDE is set.
432 We trust that the setter knows that it is safe to ignore
433 the default flags for this decl. */
434 if (decl && ! set_named_section_flags (name, flags))
435 {
436 flags = get_named_section_flags (name);
437 if ((flags & SECTION_OVERRIDE) == 0)
438 error ("%J%D causes a section type conflict", decl, decl);
439 }
440
441 named_section_flags (name, flags);
442 }
443
444 /* If required, set DECL_SECTION_NAME to a unique name. */
445
446 void
447 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
448 int flag_function_or_data_sections)
449 {
450 if (DECL_SECTION_NAME (decl) == NULL_TREE
451 && targetm.have_named_sections
452 && (flag_function_or_data_sections
453 || DECL_ONE_ONLY (decl)))
454 (*targetm.asm_out.unique_section) (decl, reloc);
455 }
456
457 #ifdef BSS_SECTION_ASM_OP
458
459 /* Tell the assembler to switch to the bss section. */
460
461 void
462 bss_section (void)
463 {
464 if (in_section != in_bss)
465 {
466 #ifdef SHARED_BSS_SECTION_ASM_OP
467 if (flag_shared_data)
468 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
469 else
470 #endif
471 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
472
473 in_section = in_bss;
474 }
475 }
476
477 #ifdef ASM_OUTPUT_BSS
478
479 /* Utility function for ASM_OUTPUT_BSS for targets to use if
480 they don't support alignments in .bss.
481 ??? It is believed that this function will work in most cases so such
482 support is localized here. */
483
484 static void
485 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
486 const char *name,
487 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
488 unsigned HOST_WIDE_INT rounded)
489 {
490 (*targetm.asm_out.globalize_label) (file, name);
491 bss_section ();
492 #ifdef ASM_DECLARE_OBJECT_NAME
493 last_assemble_variable_decl = decl;
494 ASM_DECLARE_OBJECT_NAME (file, name, decl);
495 #else
496 /* Standard thing is just output label for the object. */
497 ASM_OUTPUT_LABEL (file, name);
498 #endif /* ASM_DECLARE_OBJECT_NAME */
499 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
500 }
501
502 #endif
503
504 #ifdef ASM_OUTPUT_ALIGNED_BSS
505
506 /* Utility function for targets to use in implementing
507 ASM_OUTPUT_ALIGNED_BSS.
508 ??? It is believed that this function will work in most cases so such
509 support is localized here. */
510
511 static void
512 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
513 const char *name, unsigned HOST_WIDE_INT size,
514 int align)
515 {
516 bss_section ();
517 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
518 #ifdef ASM_DECLARE_OBJECT_NAME
519 last_assemble_variable_decl = decl;
520 ASM_DECLARE_OBJECT_NAME (file, name, decl);
521 #else
522 /* Standard thing is just output label for the object. */
523 ASM_OUTPUT_LABEL (file, name);
524 #endif /* ASM_DECLARE_OBJECT_NAME */
525 ASM_OUTPUT_SKIP (file, size ? size : 1);
526 }
527
528 #endif
529
530 #endif /* BSS_SECTION_ASM_OP */
531
532 /* Switch to the section for function DECL.
533
534 If DECL is NULL_TREE, switch to the text section.
535 ??? It's not clear that we will ever be passed NULL_TREE, but it's
536 safer to handle it. */
537
538 void
539 function_section (tree decl)
540 {
541 if (decl != NULL_TREE
542 && DECL_SECTION_NAME (decl) != NULL_TREE)
543 named_section (decl, (char *) 0, 0);
544 else
545 text_section ();
546 }
547
548 /* Switch to section for variable DECL. RELOC is the same as the
549 argument to SELECT_SECTION. */
550
551 void
552 variable_section (tree decl, int reloc)
553 {
554 if (IN_NAMED_SECTION (decl))
555 named_section (decl, NULL, reloc);
556 else
557 (*targetm.asm_out.select_section) (decl, reloc, DECL_ALIGN (decl));
558 }
559
560 /* Tell assembler to switch to the section for string merging. */
561
562 void
563 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
564 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
565 unsigned int flags ATTRIBUTE_UNUSED)
566 {
567 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
568 && TREE_CODE (decl) == STRING_CST
569 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
570 && align <= 256
571 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
572 {
573 enum machine_mode mode;
574 unsigned int modesize;
575 const char *str;
576 int i, j, len, unit;
577 char name[30];
578
579 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
580 modesize = GET_MODE_BITSIZE (mode);
581 if (modesize >= 8 && modesize <= 256
582 && (modesize & (modesize - 1)) == 0)
583 {
584 if (align < modesize)
585 align = modesize;
586
587 str = TREE_STRING_POINTER (decl);
588 len = TREE_STRING_LENGTH (decl);
589 unit = GET_MODE_SIZE (mode);
590
591 /* Check for embedded NUL characters. */
592 for (i = 0; i < len; i += unit)
593 {
594 for (j = 0; j < unit; j++)
595 if (str[i + j] != '\0')
596 break;
597 if (j == unit)
598 break;
599 }
600 if (i == len - unit)
601 {
602 sprintf (name, ".rodata.str%d.%d", modesize / 8,
603 (int) (align / 8));
604 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
605 if (!i && modesize < align)
606 {
607 /* A "" string with requested alignment greater than
608 character size might cause a problem:
609 if some other string required even bigger
610 alignment than "", then linker might think the
611 "" is just part of padding after some other string
612 and not put it into the hash table initially.
613 But this means "" could have smaller alignment
614 than requested. */
615 #ifdef ASM_OUTPUT_SECTION_START
616 named_section_flags (name, flags);
617 ASM_OUTPUT_SECTION_START (asm_out_file);
618 #else
619 readonly_data_section ();
620 #endif
621 return;
622 }
623
624 named_section_flags (name, flags);
625 return;
626 }
627 }
628 }
629
630 readonly_data_section ();
631 }
632
633 /* Tell assembler to switch to the section for constant merging. */
634
635 void
636 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
637 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
638 unsigned int flags ATTRIBUTE_UNUSED)
639 {
640 unsigned int modesize = GET_MODE_BITSIZE (mode);
641
642 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
643 && mode != VOIDmode
644 && mode != BLKmode
645 && modesize <= align
646 && align >= 8
647 && align <= 256
648 && (align & (align - 1)) == 0)
649 {
650 char name[24];
651
652 sprintf (name, ".rodata.cst%d", (int) (align / 8));
653 flags |= (align / 8) | SECTION_MERGE;
654 named_section_flags (name, flags);
655 return;
656 }
657
658 readonly_data_section ();
659 }
660 \f
661 /* Given NAME, a putative register name, discard any customary prefixes. */
662
663 static const char *
664 strip_reg_name (const char *name)
665 {
666 #ifdef REGISTER_PREFIX
667 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
668 name += strlen (REGISTER_PREFIX);
669 #endif
670 if (name[0] == '%' || name[0] == '#')
671 name++;
672 return name;
673 }
674 \f
675 /* Decode an `asm' spec for a declaration as a register name.
676 Return the register number, or -1 if nothing specified,
677 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
678 or -3 if ASMSPEC is `cc' and is not recognized,
679 or -4 if ASMSPEC is `memory' and is not recognized.
680 Accept an exact spelling or a decimal number.
681 Prefixes such as % are optional. */
682
683 int
684 decode_reg_name (const char *asmspec)
685 {
686 if (asmspec != 0)
687 {
688 int i;
689
690 /* Get rid of confusing prefixes. */
691 asmspec = strip_reg_name (asmspec);
692
693 /* Allow a decimal number as a "register name". */
694 for (i = strlen (asmspec) - 1; i >= 0; i--)
695 if (! ISDIGIT (asmspec[i]))
696 break;
697 if (asmspec[0] != 0 && i < 0)
698 {
699 i = atoi (asmspec);
700 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
701 return i;
702 else
703 return -2;
704 }
705
706 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
707 if (reg_names[i][0]
708 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
709 return i;
710
711 #ifdef ADDITIONAL_REGISTER_NAMES
712 {
713 static const struct { const char *const name; const int number; } table[]
714 = ADDITIONAL_REGISTER_NAMES;
715
716 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
717 if (! strcmp (asmspec, table[i].name))
718 return table[i].number;
719 }
720 #endif /* ADDITIONAL_REGISTER_NAMES */
721
722 if (!strcmp (asmspec, "memory"))
723 return -4;
724
725 if (!strcmp (asmspec, "cc"))
726 return -3;
727
728 return -2;
729 }
730
731 return -1;
732 }
733 \f
734 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
735 have static storage duration. In other words, it should not be an
736 automatic variable, including PARM_DECLs.
737
738 There is, however, one exception: this function handles variables
739 explicitly placed in a particular register by the user.
740
741 ASMSPEC, if not 0, is the string which the user specified as the
742 assembler symbol name.
743
744 This is never called for PARM_DECL nodes. */
745
746 void
747 make_decl_rtl (tree decl, const char *asmspec)
748 {
749 const char *name = 0;
750 int reg_number;
751 rtx x;
752
753 /* Check that we are not being given an automatic variable. */
754 /* A weak alias has TREE_PUBLIC set but not the other bits. */
755 if (TREE_CODE (decl) == PARM_DECL
756 || TREE_CODE (decl) == RESULT_DECL
757 || (TREE_CODE (decl) == VAR_DECL
758 && !TREE_STATIC (decl)
759 && !TREE_PUBLIC (decl)
760 && !DECL_EXTERNAL (decl)
761 && !DECL_REGISTER (decl)))
762 abort ();
763 /* And that we were not given a type or a label. */
764 else if (TREE_CODE (decl) == TYPE_DECL
765 || TREE_CODE (decl) == LABEL_DECL)
766 abort ();
767
768 /* For a duplicate declaration, we can be called twice on the
769 same DECL node. Don't discard the RTL already made. */
770 if (DECL_RTL_SET_P (decl))
771 {
772 /* If the old RTL had the wrong mode, fix the mode. */
773 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
774 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
775 DECL_MODE (decl), 0));
776
777 /* ??? Another way to do this would be to maintain a hashed
778 table of such critters. Instead of adding stuff to a DECL
779 to give certain attributes to it, we could use an external
780 hash map from DECL to set of attributes. */
781
782 /* Let the target reassign the RTL if it wants.
783 This is necessary, for example, when one machine specific
784 decl attribute overrides another. */
785 (* targetm.encode_section_info) (decl, DECL_RTL (decl), false);
786 return;
787 }
788
789 reg_number = decode_reg_name (asmspec);
790 if (reg_number == -2)
791 {
792 /* ASMSPEC is given, and not the name of a register. Mark the
793 name with a star so assemble_name won't munge it. */
794 char *starred = alloca (strlen (asmspec) + 2);
795 starred[0] = '*';
796 strcpy (starred + 1, asmspec);
797 change_decl_assembler_name (decl, get_identifier (starred));
798 }
799
800 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
801
802 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
803 {
804 /* First detect errors in declaring global registers. */
805 if (reg_number == -1)
806 error ("%Jregister name not specified for '%D'", decl, decl);
807 else if (reg_number < 0)
808 error ("%Jinvalid register name for '%D'", decl, decl);
809 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
810 error ("%Jdata type of '%D' isn't suitable for a register",
811 decl, decl);
812 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
813 error ("%Jregister specified for '%D' isn't suitable for data type",
814 decl, decl);
815 /* Now handle properly declared static register variables. */
816 else
817 {
818 int nregs;
819
820 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
821 {
822 DECL_INITIAL (decl) = 0;
823 error ("global register variable has initial value");
824 }
825 if (TREE_THIS_VOLATILE (decl))
826 warning ("volatile register variables don't work as you might wish");
827
828 /* If the user specified one of the eliminables registers here,
829 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
830 confused with that register and be eliminated. This usage is
831 somewhat suspect... */
832
833 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
834 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
835 REG_USERVAR_P (DECL_RTL (decl)) = 1;
836
837 if (TREE_STATIC (decl))
838 {
839 /* Make this register global, so not usable for anything
840 else. */
841 #ifdef ASM_DECLARE_REGISTER_GLOBAL
842 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
843 #endif
844 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
845 while (nregs > 0)
846 globalize_reg (reg_number + --nregs);
847 }
848
849 /* As a register variable, it has no section. */
850 return;
851 }
852 }
853
854 /* Now handle ordinary static variables and functions (in memory).
855 Also handle vars declared register invalidly. */
856
857 if (reg_number >= 0 || reg_number == -3)
858 error ("%Jregister name given for non-register variable '%D'", decl, decl);
859
860 /* Specifying a section attribute on a variable forces it into a
861 non-.bss section, and thus it cannot be common. */
862 if (TREE_CODE (decl) == VAR_DECL
863 && DECL_SECTION_NAME (decl) != NULL_TREE
864 && DECL_INITIAL (decl) == NULL_TREE
865 && DECL_COMMON (decl))
866 DECL_COMMON (decl) = 0;
867
868 /* Variables can't be both common and weak. */
869 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
870 DECL_COMMON (decl) = 0;
871
872 x = gen_rtx_SYMBOL_REF (Pmode, name);
873 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
874 SYMBOL_REF_DECL (x) = decl;
875
876 x = gen_rtx_MEM (DECL_MODE (decl), x);
877 if (TREE_CODE (decl) != FUNCTION_DECL)
878 set_mem_attributes (x, decl, 1);
879 SET_DECL_RTL (decl, x);
880
881 /* Optionally set flags or add text to the name to record information
882 such as that it is a function name.
883 If the name is changed, the macro ASM_OUTPUT_LABELREF
884 will have to know how to strip this information. */
885 (* targetm.encode_section_info) (decl, DECL_RTL (decl), true);
886 }
887
888 /* Make the rtl for variable VAR be volatile.
889 Use this only for static variables. */
890
891 void
892 make_var_volatile (tree var)
893 {
894 if (GET_CODE (DECL_RTL (var)) != MEM)
895 abort ();
896
897 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
898 }
899 \f
900 /* Output a string of literal assembler code
901 for an `asm' keyword used between functions. */
902
903 void
904 assemble_asm (tree string)
905 {
906 app_enable ();
907
908 if (TREE_CODE (string) == ADDR_EXPR)
909 string = TREE_OPERAND (string, 0);
910
911 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
912 }
913
914 /* Record an element in the table of global destructors. SYMBOL is
915 a SYMBOL_REF of the function to be called; PRIORITY is a number
916 between 0 and MAX_INIT_PRIORITY. */
917
918 void
919 default_stabs_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
920 {
921 /* Tell GNU LD that this is part of the static destructor set.
922 This will work for any system that uses stabs, most usefully
923 aout systems. */
924 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
925 assemble_name (asm_out_file, XSTR (symbol, 0));
926 fputc ('\n', asm_out_file);
927 }
928
929 void
930 default_named_section_asm_out_destructor (rtx symbol, int priority)
931 {
932 const char *section = ".dtors";
933 char buf[16];
934
935 /* ??? This only works reliably with the GNU linker. */
936 if (priority != DEFAULT_INIT_PRIORITY)
937 {
938 sprintf (buf, ".dtors.%.5u",
939 /* Invert the numbering so the linker puts us in the proper
940 order; constructors are run from right to left, and the
941 linker sorts in increasing order. */
942 MAX_INIT_PRIORITY - priority);
943 section = buf;
944 }
945
946 named_section_flags (section, SECTION_WRITE);
947 assemble_align (POINTER_SIZE);
948 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
949 }
950
951 #ifdef DTORS_SECTION_ASM_OP
952 void
953 dtors_section (void)
954 {
955 if (in_section != in_dtors)
956 {
957 in_section = in_dtors;
958 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
959 fputc ('\n', asm_out_file);
960 }
961 }
962
963 void
964 default_dtor_section_asm_out_destructor (rtx symbol,
965 int priority ATTRIBUTE_UNUSED)
966 {
967 dtors_section ();
968 assemble_align (POINTER_SIZE);
969 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
970 }
971 #endif
972
973 /* Likewise for global constructors. */
974
975 void
976 default_stabs_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
977 {
978 /* Tell GNU LD that this is part of the static destructor set.
979 This will work for any system that uses stabs, most usefully
980 aout systems. */
981 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
982 assemble_name (asm_out_file, XSTR (symbol, 0));
983 fputc ('\n', asm_out_file);
984 }
985
986 void
987 default_named_section_asm_out_constructor (rtx symbol, int priority)
988 {
989 const char *section = ".ctors";
990 char buf[16];
991
992 /* ??? This only works reliably with the GNU linker. */
993 if (priority != DEFAULT_INIT_PRIORITY)
994 {
995 sprintf (buf, ".ctors.%.5u",
996 /* Invert the numbering so the linker puts us in the proper
997 order; constructors are run from right to left, and the
998 linker sorts in increasing order. */
999 MAX_INIT_PRIORITY - priority);
1000 section = buf;
1001 }
1002
1003 named_section_flags (section, SECTION_WRITE);
1004 assemble_align (POINTER_SIZE);
1005 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1006 }
1007
1008 #ifdef CTORS_SECTION_ASM_OP
1009 void
1010 ctors_section (void)
1011 {
1012 if (in_section != in_ctors)
1013 {
1014 in_section = in_ctors;
1015 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1016 fputc ('\n', asm_out_file);
1017 }
1018 }
1019
1020 void
1021 default_ctor_section_asm_out_constructor (rtx symbol,
1022 int priority ATTRIBUTE_UNUSED)
1023 {
1024 ctors_section ();
1025 assemble_align (POINTER_SIZE);
1026 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1027 }
1028 #endif
1029 \f
1030 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1031 a nonzero value if the constant pool should be output before the
1032 start of the function, or a zero value if the pool should output
1033 after the end of the function. The default is to put it before the
1034 start. */
1035
1036 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1037 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1038 #endif
1039
1040 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1041 to be output to assembler.
1042 Set first_global_object_name and weak_global_object_name as appropriate. */
1043
1044 void
1045 notice_global_symbol (tree decl)
1046 {
1047 const char **type = &first_global_object_name;
1048
1049 if (first_global_object_name
1050 || !TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
1051 || !DECL_NAME (decl)
1052 || (TREE_CODE (decl) != FUNCTION_DECL
1053 && (TREE_CODE (decl) != VAR_DECL
1054 || (DECL_COMMON (decl)
1055 && (DECL_INITIAL (decl) == 0
1056 || DECL_INITIAL (decl) == error_mark_node))))
1057 || GET_CODE (DECL_RTL (decl)) != MEM)
1058 return;
1059
1060 /* We win when global object is found, but it is usefull to know about weak
1061 symbol as well so we can produce nicer unique names. */
1062 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl))
1063 type = &weak_global_object_name;
1064
1065 if (!*type)
1066 {
1067 const char *p;
1068 char *name;
1069 rtx decl_rtl = DECL_RTL (decl);
1070
1071 p = (* targetm.strip_name_encoding) (XSTR (XEXP (decl_rtl, 0), 0));
1072 name = xstrdup (p);
1073
1074 *type = name;
1075 }
1076 }
1077
1078 /* Output assembler code for the constant pool of a function and associated
1079 with defining the name of the function. DECL describes the function.
1080 NAME is the function's name. For the constant pool, we use the current
1081 constant pool data. */
1082
1083 void
1084 assemble_start_function (tree decl, const char *fnname)
1085 {
1086 int align;
1087
1088 /* The following code does not need preprocessing in the assembler. */
1089
1090 app_disable ();
1091
1092 if (CONSTANT_POOL_BEFORE_FUNCTION)
1093 output_constant_pool (fnname, decl);
1094
1095 resolve_unique_section (decl, 0, flag_function_sections);
1096 function_section (decl);
1097
1098 /* Tell assembler to move to target machine's alignment for functions. */
1099 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1100 if (align < force_align_functions_log)
1101 align = force_align_functions_log;
1102 if (align > 0)
1103 {
1104 ASM_OUTPUT_ALIGN (asm_out_file, align);
1105 }
1106
1107 /* Handle a user-specified function alignment.
1108 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1109 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1110 if (align_functions_log > align
1111 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1112 {
1113 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1114 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1115 align_functions_log, align_functions - 1);
1116 #else
1117 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1118 #endif
1119 }
1120
1121 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1122 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1123 #endif
1124
1125 (*debug_hooks->begin_function) (decl);
1126
1127 /* Make function name accessible from other files, if appropriate. */
1128
1129 if (TREE_PUBLIC (decl))
1130 {
1131 notice_global_symbol (decl);
1132
1133 globalize_decl (decl);
1134
1135 maybe_assemble_visibility (decl);
1136 }
1137
1138 /* Do any machine/system dependent processing of the function name */
1139 #ifdef ASM_DECLARE_FUNCTION_NAME
1140 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1141 #else
1142 /* Standard thing is just output label for the function. */
1143 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1144 #endif /* ASM_DECLARE_FUNCTION_NAME */
1145 }
1146
1147 /* Output assembler code associated with defining the size of the
1148 function. DECL describes the function. NAME is the function's name. */
1149
1150 void
1151 assemble_end_function (tree decl, const char *fnname)
1152 {
1153 #ifdef ASM_DECLARE_FUNCTION_SIZE
1154 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1155 #endif
1156 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1157 {
1158 output_constant_pool (fnname, decl);
1159 function_section (decl); /* need to switch back */
1160 }
1161 }
1162 \f
1163 /* Assemble code to leave SIZE bytes of zeros. */
1164
1165 void
1166 assemble_zeros (unsigned HOST_WIDE_INT size)
1167 {
1168 /* Do no output if -fsyntax-only. */
1169 if (flag_syntax_only)
1170 return;
1171
1172 #ifdef ASM_NO_SKIP_IN_TEXT
1173 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1174 so we must output 0s explicitly in the text section. */
1175 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1176 {
1177 unsigned HOST_WIDE_INT i;
1178 for (i = 0; i < size; i++)
1179 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1180 }
1181 else
1182 #endif
1183 if (size > 0)
1184 ASM_OUTPUT_SKIP (asm_out_file, size);
1185 }
1186
1187 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1188
1189 void
1190 assemble_align (int align)
1191 {
1192 if (align > BITS_PER_UNIT)
1193 {
1194 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1195 }
1196 }
1197
1198 /* Assemble a string constant with the specified C string as contents. */
1199
1200 void
1201 assemble_string (const char *p, int size)
1202 {
1203 int pos = 0;
1204 int maximum = 2000;
1205
1206 /* If the string is very long, split it up. */
1207
1208 while (pos < size)
1209 {
1210 int thissize = size - pos;
1211 if (thissize > maximum)
1212 thissize = maximum;
1213
1214 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1215
1216 pos += thissize;
1217 p += thissize;
1218 }
1219 }
1220
1221 \f
1222 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1223 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1224 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1225 #else
1226 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1227 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1228 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1229 #else
1230 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1231 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1232 #endif
1233 #endif
1234
1235 #if defined ASM_OUTPUT_ALIGNED_BSS
1236 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1237 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1238 #else
1239 #if defined ASM_OUTPUT_BSS
1240 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1241 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1242 #else
1243 #undef ASM_EMIT_BSS
1244 #endif
1245 #endif
1246
1247 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1248 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1249 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1250 #else
1251 #if defined ASM_OUTPUT_ALIGNED_COMMON
1252 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1253 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1254 #else
1255 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1256 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1257 #endif
1258 #endif
1259
1260 static bool
1261 asm_emit_uninitialised (tree decl, const char *name,
1262 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1263 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1264 {
1265 enum
1266 {
1267 asm_dest_common,
1268 asm_dest_bss,
1269 asm_dest_local
1270 }
1271 destination = asm_dest_local;
1272
1273 /* ??? We should handle .bss via select_section mechanisms rather than
1274 via special target hooks. That would eliminate this special case. */
1275 if (TREE_PUBLIC (decl))
1276 {
1277 if (!DECL_COMMON (decl))
1278 #ifdef ASM_EMIT_BSS
1279 destination = asm_dest_bss;
1280 #else
1281 return false;
1282 #endif
1283 else
1284 destination = asm_dest_common;
1285 }
1286
1287 if (destination == asm_dest_bss)
1288 globalize_decl (decl);
1289 resolve_unique_section (decl, 0, flag_data_sections);
1290
1291 if (flag_shared_data)
1292 {
1293 switch (destination)
1294 {
1295 #ifdef ASM_OUTPUT_SHARED_BSS
1296 case asm_dest_bss:
1297 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1298 return;
1299 #endif
1300 #ifdef ASM_OUTPUT_SHARED_COMMON
1301 case asm_dest_common:
1302 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1303 return;
1304 #endif
1305 #ifdef ASM_OUTPUT_SHARED_LOCAL
1306 case asm_dest_local:
1307 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1308 return;
1309 #endif
1310 default:
1311 break;
1312 }
1313 }
1314
1315 switch (destination)
1316 {
1317 #ifdef ASM_EMIT_BSS
1318 case asm_dest_bss:
1319 ASM_EMIT_BSS (decl, name, size, rounded);
1320 break;
1321 #endif
1322 case asm_dest_common:
1323 ASM_EMIT_COMMON (decl, name, size, rounded);
1324 break;
1325 case asm_dest_local:
1326 ASM_EMIT_LOCAL (decl, name, size, rounded);
1327 break;
1328 default:
1329 abort ();
1330 }
1331
1332 return true;
1333 }
1334
1335 /* Assemble everything that is needed for a variable or function declaration.
1336 Not used for automatic variables, and not used for function definitions.
1337 Should not be called for variables of incomplete structure type.
1338
1339 TOP_LEVEL is nonzero if this variable has file scope.
1340 AT_END is nonzero if this is the special handling, at end of compilation,
1341 to define things that have had only tentative definitions.
1342 DONT_OUTPUT_DATA if nonzero means don't actually output the
1343 initial value (that will be done by the caller). */
1344
1345 void
1346 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1347 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1348 {
1349 const char *name;
1350 unsigned int align;
1351 int reloc = 0;
1352 rtx decl_rtl;
1353
1354 if (lang_hooks.decls.prepare_assemble_variable)
1355 (*lang_hooks.decls.prepare_assemble_variable) (decl);
1356
1357 last_assemble_variable_decl = 0;
1358
1359 /* Normally no need to say anything here for external references,
1360 since assemble_external is called by the language-specific code
1361 when a declaration is first seen. */
1362
1363 if (DECL_EXTERNAL (decl))
1364 return;
1365
1366 /* Output no assembler code for a function declaration.
1367 Only definitions of functions output anything. */
1368
1369 if (TREE_CODE (decl) == FUNCTION_DECL)
1370 return;
1371
1372 /* Do nothing for global register variables. */
1373 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1374 {
1375 TREE_ASM_WRITTEN (decl) = 1;
1376 return;
1377 }
1378
1379 /* If type was incomplete when the variable was declared,
1380 see if it is complete now. */
1381
1382 if (DECL_SIZE (decl) == 0)
1383 layout_decl (decl, 0);
1384
1385 /* Still incomplete => don't allocate it; treat the tentative defn
1386 (which is what it must have been) as an `extern' reference. */
1387
1388 if (!dont_output_data && DECL_SIZE (decl) == 0)
1389 {
1390 error ("%Jstorage size of `%D' isn't known", decl, decl);
1391 TREE_ASM_WRITTEN (decl) = 1;
1392 return;
1393 }
1394
1395 /* The first declaration of a variable that comes through this function
1396 decides whether it is global (in C, has external linkage)
1397 or local (in C, has internal linkage). So do nothing more
1398 if this function has already run. */
1399
1400 if (TREE_ASM_WRITTEN (decl))
1401 return;
1402
1403 /* Make sure targetm.encode_section_info is invoked before we set
1404 ASM_WRITTEN. */
1405 decl_rtl = DECL_RTL (decl);
1406
1407 TREE_ASM_WRITTEN (decl) = 1;
1408
1409 /* Do no output if -fsyntax-only. */
1410 if (flag_syntax_only)
1411 return;
1412
1413 app_disable ();
1414
1415 if (! dont_output_data
1416 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1417 {
1418 error ("%Jsize of variable '%D' is too large", decl, decl);
1419 return;
1420 }
1421
1422 name = XSTR (XEXP (decl_rtl, 0), 0);
1423 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1424 notice_global_symbol (decl);
1425
1426 /* Compute the alignment of this data. */
1427
1428 align = DECL_ALIGN (decl);
1429
1430 /* In the case for initialing an array whose length isn't specified,
1431 where we have not yet been able to do the layout,
1432 figure out the proper alignment now. */
1433 if (dont_output_data && DECL_SIZE (decl) == 0
1434 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1435 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1436
1437 /* Some object file formats have a maximum alignment which they support.
1438 In particular, a.out format supports a maximum alignment of 4. */
1439 #ifndef MAX_OFILE_ALIGNMENT
1440 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1441 #endif
1442 if (align > MAX_OFILE_ALIGNMENT)
1443 {
1444 warning ("%Jalignment of '%D' is greater than maximum object "
1445 "file alignment. Using %d", decl, decl,
1446 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1447 align = MAX_OFILE_ALIGNMENT;
1448 }
1449
1450 /* On some machines, it is good to increase alignment sometimes. */
1451 if (! DECL_USER_ALIGN (decl))
1452 {
1453 #ifdef DATA_ALIGNMENT
1454 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1455 #endif
1456 #ifdef CONSTANT_ALIGNMENT
1457 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1458 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1459 #endif
1460 }
1461
1462 /* Reset the alignment in case we have made it tighter, so we can benefit
1463 from it in get_pointer_alignment. */
1464 DECL_ALIGN (decl) = align;
1465 set_mem_align (decl_rtl, align);
1466
1467 if (TREE_PUBLIC (decl))
1468 maybe_assemble_visibility (decl);
1469
1470 /* Output any data that we will need to use the address of. */
1471 if (DECL_INITIAL (decl) == error_mark_node)
1472 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1473 else if (DECL_INITIAL (decl))
1474 {
1475 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1476 output_addressed_constants (DECL_INITIAL (decl));
1477 }
1478 resolve_unique_section (decl, reloc, flag_data_sections);
1479
1480 /* Handle uninitialized definitions. */
1481
1482 /* If the decl has been given an explicit section name, then it
1483 isn't common, and shouldn't be handled as such. */
1484 if (DECL_SECTION_NAME (decl) || dont_output_data)
1485 ;
1486 /* We don't implement common thread-local data at present. */
1487 else if (DECL_THREAD_LOCAL (decl))
1488 {
1489 if (DECL_COMMON (decl))
1490 sorry ("thread-local COMMON data not implemented");
1491 }
1492 else if (DECL_INITIAL (decl) == 0
1493 || DECL_INITIAL (decl) == error_mark_node
1494 || (flag_zero_initialized_in_bss
1495 /* Leave constant zeroes in .rodata so they can be shared. */
1496 && !TREE_READONLY (decl)
1497 && initializer_zerop (DECL_INITIAL (decl))))
1498 {
1499 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1500 unsigned HOST_WIDE_INT rounded = size;
1501
1502 /* Don't allocate zero bytes of common,
1503 since that means "undefined external" in the linker. */
1504 if (size == 0)
1505 rounded = 1;
1506
1507 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1508 so that each uninitialized object starts on such a boundary. */
1509 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1510 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1511 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1512
1513 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1514 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1515 warning ("%Jrequested alignment for '%D' is greater than "
1516 "implemented alignment of %d", decl, decl, rounded);
1517 #endif
1518
1519 /* If the target cannot output uninitialized but not common global data
1520 in .bss, then we have to use .data, so fall through. */
1521 if (asm_emit_uninitialised (decl, name, size, rounded))
1522 return;
1523 }
1524
1525 /* Handle initialized definitions.
1526 Also handle uninitialized global definitions if -fno-common and the
1527 target doesn't support ASM_OUTPUT_BSS. */
1528
1529 /* First make the assembler name(s) global if appropriate. */
1530 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1531 globalize_decl (decl);
1532
1533 /* Switch to the appropriate section. */
1534 variable_section (decl, reloc);
1535
1536 /* dbxout.c needs to know this. */
1537 if (in_text_section ())
1538 DECL_IN_TEXT_SECTION (decl) = 1;
1539
1540 /* Output the alignment of this data. */
1541 if (align > BITS_PER_UNIT)
1542 {
1543 ASM_OUTPUT_ALIGN (asm_out_file,
1544 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1545 }
1546
1547 /* Do any machine/system dependent processing of the object. */
1548 #ifdef ASM_DECLARE_OBJECT_NAME
1549 last_assemble_variable_decl = decl;
1550 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1551 #else
1552 /* Standard thing is just output label for the object. */
1553 ASM_OUTPUT_LABEL (asm_out_file, name);
1554 #endif /* ASM_DECLARE_OBJECT_NAME */
1555
1556 if (!dont_output_data)
1557 {
1558 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
1559 /* Output the actual data. */
1560 output_constant (DECL_INITIAL (decl),
1561 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1562 align);
1563 else
1564 /* Leave space for it. */
1565 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1566 }
1567 }
1568
1569 /* Return 1 if type TYPE contains any pointers. */
1570
1571 static int
1572 contains_pointers_p (tree type)
1573 {
1574 switch (TREE_CODE (type))
1575 {
1576 case POINTER_TYPE:
1577 case REFERENCE_TYPE:
1578 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1579 so I'll play safe and return 1. */
1580 case OFFSET_TYPE:
1581 return 1;
1582
1583 case RECORD_TYPE:
1584 case UNION_TYPE:
1585 case QUAL_UNION_TYPE:
1586 {
1587 tree fields;
1588 /* For a type that has fields, see if the fields have pointers. */
1589 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1590 if (TREE_CODE (fields) == FIELD_DECL
1591 && contains_pointers_p (TREE_TYPE (fields)))
1592 return 1;
1593 return 0;
1594 }
1595
1596 case ARRAY_TYPE:
1597 /* An array type contains pointers if its element type does. */
1598 return contains_pointers_p (TREE_TYPE (type));
1599
1600 default:
1601 return 0;
1602 }
1603 }
1604
1605 #ifdef ASM_OUTPUT_EXTERNAL
1606 /* True if DECL is a function decl for which no out-of-line copy exists.
1607 It is assumed that DECL's assembler name has been set. */
1608
1609 static bool
1610 incorporeal_function_p (tree decl)
1611 {
1612 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1613 {
1614 const char *name;
1615
1616 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
1617 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
1618 return true;
1619
1620 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1621 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
1622 return true;
1623 }
1624 return false;
1625 }
1626 #endif
1627
1628 /* Output something to declare an external symbol to the assembler.
1629 (Most assemblers don't need this, so we normally output nothing.)
1630 Do nothing if DECL is not external. */
1631
1632 void
1633 assemble_external (tree decl ATTRIBUTE_UNUSED)
1634 {
1635 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1636 main body of this code is only rarely exercised. To provide some
1637 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1638 open. If it's not, we should not be calling this function. */
1639 if (!asm_out_file)
1640 abort ();
1641
1642 #ifdef ASM_OUTPUT_EXTERNAL
1643 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1644 {
1645 rtx rtl = DECL_RTL (decl);
1646
1647 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1648 && !SYMBOL_REF_USED (XEXP (rtl, 0))
1649 && !incorporeal_function_p (decl))
1650 {
1651 /* Some systems do require some output. */
1652 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1653 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1654 }
1655 }
1656 #endif
1657 }
1658
1659 /* Similar, for calling a library function FUN. */
1660
1661 void
1662 assemble_external_libcall (rtx fun)
1663 {
1664 /* Declare library function name external when first used, if nec. */
1665 if (! SYMBOL_REF_USED (fun))
1666 {
1667 SYMBOL_REF_USED (fun) = 1;
1668 (*targetm.asm_out.external_libcall) (fun);
1669 }
1670 }
1671
1672 /* Assemble a label named NAME. */
1673
1674 void
1675 assemble_label (const char *name)
1676 {
1677 ASM_OUTPUT_LABEL (asm_out_file, name);
1678 }
1679
1680 /* Set the symbol_referenced flag for ID and notify callgraph code. */
1681 void
1682 mark_referenced (tree id)
1683 {
1684 if (!TREE_SYMBOL_REFERENCED (id))
1685 {
1686 struct cgraph_node *node;
1687 struct cgraph_varpool_node *vnode;
1688
1689 if (!cgraph_global_info_ready)
1690 {
1691 node = cgraph_node_for_identifier (id);
1692 if (node)
1693 cgraph_mark_needed_node (node);
1694 }
1695
1696 vnode = cgraph_varpool_node_for_identifier (id);
1697 if (vnode)
1698 cgraph_varpool_mark_needed_node (vnode);
1699 }
1700 TREE_SYMBOL_REFERENCED (id) = 1;
1701 }
1702
1703 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1704 If NAME starts with a *, the rest of NAME is output verbatim.
1705 Otherwise NAME is transformed in an implementation-defined way
1706 (usually by the addition of an underscore).
1707 Many macros in the tm file are defined to call this function. */
1708
1709 void
1710 assemble_name (FILE *file, const char *name)
1711 {
1712 const char *real_name;
1713 tree id;
1714
1715 real_name = (* targetm.strip_name_encoding) (name);
1716
1717 id = maybe_get_identifier (real_name);
1718 if (id)
1719 mark_referenced (id);
1720
1721 if (name[0] == '*')
1722 fputs (&name[1], file);
1723 else
1724 ASM_OUTPUT_LABELREF (file, name);
1725 }
1726
1727 /* Allocate SIZE bytes writable static space with a gensym name
1728 and return an RTX to refer to its address. */
1729
1730 rtx
1731 assemble_static_space (unsigned HOST_WIDE_INT size)
1732 {
1733 char name[12];
1734 const char *namestring;
1735 rtx x;
1736
1737 #if 0
1738 if (flag_shared_data)
1739 data_section ();
1740 #endif
1741
1742 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1743 ++const_labelno;
1744 namestring = ggc_strdup (name);
1745
1746 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1747 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
1748
1749 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1750 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1751 BIGGEST_ALIGNMENT);
1752 #else
1753 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1754 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1755 #else
1756 {
1757 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1758 so that each uninitialized object starts on such a boundary. */
1759 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1760 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1761 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1762 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1763 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1764 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1765 }
1766 #endif
1767 #endif
1768 return x;
1769 }
1770
1771 /* Assemble the static constant template for function entry trampolines.
1772 This is done at most once per compilation.
1773 Returns an RTX for the address of the template. */
1774
1775 #ifdef TRAMPOLINE_TEMPLATE
1776 rtx
1777 assemble_trampoline_template (void)
1778 {
1779 char label[256];
1780 const char *name;
1781 int align;
1782 rtx symbol;
1783
1784 /* By default, put trampoline templates in read-only data section. */
1785
1786 #ifdef TRAMPOLINE_SECTION
1787 TRAMPOLINE_SECTION ();
1788 #else
1789 readonly_data_section ();
1790 #endif
1791
1792 /* Write the assembler code to define one. */
1793 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1794 if (align > 0)
1795 {
1796 ASM_OUTPUT_ALIGN (asm_out_file, align);
1797 }
1798
1799 (*targetm.asm_out.internal_label) (asm_out_file, "LTRAMP", 0);
1800 TRAMPOLINE_TEMPLATE (asm_out_file);
1801
1802 /* Record the rtl to refer to it. */
1803 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1804 name = ggc_strdup (label);
1805 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
1806 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
1807
1808 return symbol;
1809 }
1810 #endif
1811 \f
1812 /* A and B are either alignments or offsets. Return the minimum alignment
1813 that may be assumed after adding the two together. */
1814
1815 static inline unsigned
1816 min_align (unsigned int a, unsigned int b)
1817 {
1818 return (a | b) & -(a | b);
1819 }
1820
1821 /* Return the assembler directive for creating a given kind of integer
1822 object. SIZE is the number of bytes in the object and ALIGNED_P
1823 indicates whether it is known to be aligned. Return NULL if the
1824 assembly dialect has no such directive.
1825
1826 The returned string should be printed at the start of a new line and
1827 be followed immediately by the object's initial value. */
1828
1829 const char *
1830 integer_asm_op (int size, int aligned_p)
1831 {
1832 struct asm_int_op *ops;
1833
1834 if (aligned_p)
1835 ops = &targetm.asm_out.aligned_op;
1836 else
1837 ops = &targetm.asm_out.unaligned_op;
1838
1839 switch (size)
1840 {
1841 case 1:
1842 return targetm.asm_out.byte_op;
1843 case 2:
1844 return ops->hi;
1845 case 4:
1846 return ops->si;
1847 case 8:
1848 return ops->di;
1849 case 16:
1850 return ops->ti;
1851 default:
1852 return NULL;
1853 }
1854 }
1855
1856 /* Use directive OP to assemble an integer object X. Print OP at the
1857 start of the line, followed immediately by the value of X. */
1858
1859 void
1860 assemble_integer_with_op (const char *op, rtx x)
1861 {
1862 fputs (op, asm_out_file);
1863 output_addr_const (asm_out_file, x);
1864 fputc ('\n', asm_out_file);
1865 }
1866
1867 /* The default implementation of the asm_out.integer target hook. */
1868
1869 bool
1870 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
1871 unsigned int size ATTRIBUTE_UNUSED,
1872 int aligned_p ATTRIBUTE_UNUSED)
1873 {
1874 const char *op = integer_asm_op (size, aligned_p);
1875 return op && (assemble_integer_with_op (op, x), true);
1876 }
1877
1878 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1879 the alignment of the integer in bits. Return 1 if we were able to output
1880 the constant, otherwise 0. If FORCE is nonzero, abort if we can't output
1881 the constant. */
1882
1883 bool
1884 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
1885 {
1886 int aligned_p;
1887
1888 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
1889
1890 /* See if the target hook can handle this kind of object. */
1891 if ((*targetm.asm_out.integer) (x, size, aligned_p))
1892 return true;
1893
1894 /* If the object is a multi-byte one, try splitting it up. Split
1895 it into words it if is multi-word, otherwise split it into bytes. */
1896 if (size > 1)
1897 {
1898 enum machine_mode omode, imode;
1899 unsigned int subalign;
1900 unsigned int subsize, i;
1901
1902 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
1903 subalign = MIN (align, subsize * BITS_PER_UNIT);
1904 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
1905 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1906
1907 for (i = 0; i < size; i += subsize)
1908 {
1909 rtx partial = simplify_subreg (omode, x, imode, i);
1910 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
1911 break;
1912 }
1913 if (i == size)
1914 return true;
1915
1916 /* If we've printed some of it, but not all of it, there's no going
1917 back now. */
1918 if (i > 0)
1919 abort ();
1920 }
1921
1922 if (force)
1923 abort ();
1924
1925 return false;
1926 }
1927 \f
1928 void
1929 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
1930 {
1931 long data[4];
1932 int i;
1933 int bitsize, nelts, nunits, units_per;
1934
1935 /* This is hairy. We have a quantity of known size. real_to_target
1936 will put it into an array of *host* longs, 32 bits per element
1937 (even if long is more than 32 bits). We need to determine the
1938 number of array elements that are occupied (nelts) and the number
1939 of *target* min-addressable units that will be occupied in the
1940 object file (nunits). We cannot assume that 32 divides the
1941 mode's bitsize (size * BITS_PER_UNIT) evenly.
1942
1943 size * BITS_PER_UNIT is used here to make sure that padding bits
1944 (which might appear at either end of the value; real_to_target
1945 will include the padding bits in its output array) are included. */
1946
1947 nunits = GET_MODE_SIZE (mode);
1948 bitsize = nunits * BITS_PER_UNIT;
1949 nelts = CEIL (bitsize, 32);
1950 units_per = 32 / BITS_PER_UNIT;
1951
1952 real_to_target (data, &d, mode);
1953
1954 /* Put out the first word with the specified alignment. */
1955 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
1956 nunits -= units_per;
1957
1958 /* Subsequent words need only 32-bit alignment. */
1959 align = min_align (align, 32);
1960
1961 for (i = 1; i < nelts; i++)
1962 {
1963 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
1964 nunits -= units_per;
1965 }
1966 }
1967 \f
1968 /* Given an expression EXP with a constant value,
1969 reduce it to the sum of an assembler symbol and an integer.
1970 Store them both in the structure *VALUE.
1971 Abort if EXP does not reduce. */
1972
1973 struct addr_const GTY(())
1974 {
1975 rtx base;
1976 HOST_WIDE_INT offset;
1977 };
1978
1979 static void
1980 decode_addr_const (tree exp, struct addr_const *value)
1981 {
1982 tree target = TREE_OPERAND (exp, 0);
1983 int offset = 0;
1984 rtx x;
1985
1986 while (1)
1987 {
1988 if (TREE_CODE (target) == COMPONENT_REF
1989 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
1990
1991 {
1992 offset += int_byte_position (TREE_OPERAND (target, 1));
1993 target = TREE_OPERAND (target, 0);
1994 }
1995 else if (TREE_CODE (target) == ARRAY_REF
1996 || TREE_CODE (target) == ARRAY_RANGE_REF)
1997 {
1998 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
1999 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2000 target = TREE_OPERAND (target, 0);
2001 }
2002 else
2003 break;
2004 }
2005
2006 switch (TREE_CODE (target))
2007 {
2008 case VAR_DECL:
2009 case FUNCTION_DECL:
2010 x = DECL_RTL (target);
2011 break;
2012
2013 case LABEL_DECL:
2014 x = gen_rtx_MEM (FUNCTION_MODE,
2015 gen_rtx_LABEL_REF (VOIDmode, force_label_rtx (target)));
2016 break;
2017
2018 case REAL_CST:
2019 case STRING_CST:
2020 case COMPLEX_CST:
2021 case CONSTRUCTOR:
2022 case INTEGER_CST:
2023 x = output_constant_def (target, 1);
2024 break;
2025
2026 default:
2027 abort ();
2028 }
2029
2030 if (GET_CODE (x) != MEM)
2031 abort ();
2032 x = XEXP (x, 0);
2033
2034 value->base = x;
2035 value->offset = offset;
2036 }
2037 \f
2038 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */
2039 enum kind { RTX_UNKNOWN, RTX_DOUBLE, RTX_VECTOR, RTX_INT, RTX_UNSPEC };
2040 struct rtx_const GTY(())
2041 {
2042 ENUM_BITFIELD(kind) kind : 16;
2043 ENUM_BITFIELD(machine_mode) mode : 16;
2044 union rtx_const_un {
2045 REAL_VALUE_TYPE GTY ((tag ("4"))) du;
2046 struct rtx_const_u_addr {
2047 rtx base;
2048 const char *symbol;
2049 HOST_WIDE_INT offset;
2050 } GTY ((tag ("1"))) addr;
2051 struct rtx_const_u_di {
2052 HOST_WIDE_INT high;
2053 HOST_WIDE_INT low;
2054 } GTY ((tag ("0"))) di;
2055
2056 /* The max vector size we have is 16 wide; two variants for
2057 integral and floating point vectors. */
2058 struct rtx_const_int_vec {
2059 HOST_WIDE_INT high;
2060 HOST_WIDE_INT low;
2061 } GTY ((tag ("2"))) int_vec[16];
2062
2063 REAL_VALUE_TYPE GTY ((tag ("3"))) fp_vec[8];
2064
2065 } GTY ((desc ("%1.kind >= RTX_INT"), descbits ("1"))) un;
2066 };
2067
2068 /* Uniquize all constants that appear in memory.
2069 Each constant in memory thus far output is recorded
2070 in `const_hash_table'. */
2071
2072 struct constant_descriptor_tree GTY(())
2073 {
2074 /* A MEM for the constant. */
2075 rtx rtl;
2076
2077 /* The value of the constant. */
2078 tree value;
2079 };
2080
2081 static GTY((param_is (struct constant_descriptor_tree)))
2082 htab_t const_desc_htab;
2083
2084 static struct constant_descriptor_tree * build_constant_desc (tree);
2085 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2086
2087 /* Compute a hash code for a constant expression. */
2088
2089 static hashval_t
2090 const_desc_hash (const void *ptr)
2091 {
2092 return const_hash_1 (((struct constant_descriptor_tree *)ptr)->value);
2093 }
2094
2095 static hashval_t
2096 const_hash_1 (const tree exp)
2097 {
2098 const char *p;
2099 hashval_t hi;
2100 int len, i;
2101 enum tree_code code = TREE_CODE (exp);
2102
2103 /* Either set P and LEN to the address and len of something to hash and
2104 exit the switch or return a value. */
2105
2106 switch (code)
2107 {
2108 case INTEGER_CST:
2109 p = (char *) &TREE_INT_CST (exp);
2110 len = sizeof TREE_INT_CST (exp);
2111 break;
2112
2113 case REAL_CST:
2114 return real_hash (TREE_REAL_CST_PTR (exp));
2115
2116 case STRING_CST:
2117 p = TREE_STRING_POINTER (exp);
2118 len = TREE_STRING_LENGTH (exp);
2119 break;
2120 case COMPLEX_CST:
2121 return (const_hash_1 (TREE_REALPART (exp)) * 5
2122 + const_hash_1 (TREE_IMAGPART (exp)));
2123
2124 case CONSTRUCTOR:
2125 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2126 {
2127 char *tmp;
2128
2129 len = int_size_in_bytes (TREE_TYPE (exp));
2130 tmp = alloca (len);
2131 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2132 p = tmp;
2133 break;
2134 }
2135 else
2136 {
2137 tree link;
2138
2139 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2140
2141 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2142 if (TREE_VALUE (link))
2143 hi = hi * 603 + const_hash_1 (TREE_VALUE (link));
2144
2145 return hi;
2146 }
2147
2148 case ADDR_EXPR:
2149 case FDESC_EXPR:
2150 {
2151 struct addr_const value;
2152
2153 decode_addr_const (exp, &value);
2154 if (GET_CODE (value.base) == SYMBOL_REF)
2155 {
2156 /* Don't hash the address of the SYMBOL_REF;
2157 only use the offset and the symbol name. */
2158 hi = value.offset;
2159 p = XSTR (value.base, 0);
2160 for (i = 0; p[i] != 0; i++)
2161 hi = ((hi * 613) + (unsigned) (p[i]));
2162 }
2163 else if (GET_CODE (value.base) == LABEL_REF)
2164 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2165 else
2166 abort ();
2167 }
2168 return hi;
2169
2170 case PLUS_EXPR:
2171 case MINUS_EXPR:
2172 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2173 + const_hash_1 (TREE_OPERAND (exp, 1)));
2174
2175 case NOP_EXPR:
2176 case CONVERT_EXPR:
2177 case NON_LVALUE_EXPR:
2178 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2179
2180 default:
2181 /* A language specific constant. Just hash the code. */
2182 return code;
2183 }
2184
2185 /* Compute hashing function. */
2186 hi = len;
2187 for (i = 0; i < len; i++)
2188 hi = ((hi * 613) + (unsigned) (p[i]));
2189
2190 return hi;
2191 }
2192
2193 /* Wrapper of compare_constant, for the htab interface. */
2194 static int
2195 const_desc_eq (const void *p1, const void *p2)
2196 {
2197 return compare_constant (((struct constant_descriptor_tree *)p1)->value,
2198 ((struct constant_descriptor_tree *)p2)->value);
2199 }
2200
2201 /* Compare t1 and t2, and return 1 only if they are known to result in
2202 the same bit pattern on output. */
2203
2204 static int
2205 compare_constant (const tree t1, const tree t2)
2206 {
2207 enum tree_code typecode;
2208
2209 if (t1 == NULL_TREE)
2210 return t2 == NULL_TREE;
2211 if (t2 == NULL_TREE)
2212 return 0;
2213
2214 if (TREE_CODE (t1) != TREE_CODE (t2))
2215 return 0;
2216
2217 switch (TREE_CODE (t1))
2218 {
2219 case INTEGER_CST:
2220 /* Integer constants are the same only if the same width of type. */
2221 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2222 return 0;
2223 return tree_int_cst_equal (t1, t2);
2224
2225 case REAL_CST:
2226 /* Real constants are the same only if the same width of type. */
2227 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2228 return 0;
2229
2230 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2231
2232 case STRING_CST:
2233 if (flag_writable_strings)
2234 return 0;
2235
2236 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2237 return 0;
2238
2239 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2240 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2241 TREE_STRING_LENGTH (t1)));
2242
2243 case COMPLEX_CST:
2244 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2245 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2246
2247 case CONSTRUCTOR:
2248 typecode = TREE_CODE (TREE_TYPE (t1));
2249 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2250 return 0;
2251
2252 if (typecode == SET_TYPE)
2253 {
2254 int len = int_size_in_bytes (TREE_TYPE (t2));
2255 unsigned char *tmp1, *tmp2;
2256
2257 if (int_size_in_bytes (TREE_TYPE (t1)) != len)
2258 return 0;
2259
2260 tmp1 = alloca (len);
2261 tmp2 = alloca (len);
2262
2263 if (get_set_constructor_bytes (t1, tmp1, len) != NULL_TREE)
2264 return 0;
2265 if (get_set_constructor_bytes (t2, tmp2, len) != NULL_TREE)
2266 return 0;
2267
2268 return memcmp (tmp1, tmp2, len) == 0;
2269 }
2270 else
2271 {
2272 tree l1, l2;
2273
2274 if (typecode == ARRAY_TYPE)
2275 {
2276 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2277 /* For arrays, check that the sizes all match. */
2278 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2279 || size_1 == -1
2280 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2281 return 0;
2282 }
2283 else
2284 {
2285 /* For record and union constructors, require exact type
2286 equality. */
2287 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2288 return 0;
2289 }
2290
2291 for (l1 = CONSTRUCTOR_ELTS (t1), l2 = CONSTRUCTOR_ELTS (t2);
2292 l1 && l2;
2293 l1 = TREE_CHAIN (l1), l2 = TREE_CHAIN (l2))
2294 {
2295 /* Check that each value is the same... */
2296 if (! compare_constant (TREE_VALUE (l1), TREE_VALUE (l2)))
2297 return 0;
2298 /* ... and that they apply to the same fields! */
2299 if (typecode == ARRAY_TYPE)
2300 {
2301 if (! compare_constant (TREE_PURPOSE (l1),
2302 TREE_PURPOSE (l2)))
2303 return 0;
2304 }
2305 else
2306 {
2307 if (TREE_PURPOSE (l1) != TREE_PURPOSE (l2))
2308 return 0;
2309 }
2310 }
2311
2312 return l1 == NULL_TREE && l2 == NULL_TREE;
2313 }
2314
2315 case ADDR_EXPR:
2316 case FDESC_EXPR:
2317 {
2318 struct addr_const value1, value2;
2319
2320 decode_addr_const (t1, &value1);
2321 decode_addr_const (t2, &value2);
2322 return (value1.offset == value2.offset
2323 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2324 }
2325
2326 case PLUS_EXPR:
2327 case MINUS_EXPR:
2328 case RANGE_EXPR:
2329 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2330 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2331
2332 case NOP_EXPR:
2333 case CONVERT_EXPR:
2334 case NON_LVALUE_EXPR:
2335 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2336
2337 default:
2338 {
2339 tree nt1, nt2;
2340 nt1 = (*lang_hooks.expand_constant) (t1);
2341 nt2 = (*lang_hooks.expand_constant) (t2);
2342 if (nt1 != t1 || nt2 != t2)
2343 return compare_constant (nt1, nt2);
2344 else
2345 return 0;
2346 }
2347 }
2348
2349 /* Should not get here. */
2350 abort ();
2351 }
2352 \f
2353 /* Make a copy of the whole tree structure for a constant. This
2354 handles the same types of nodes that compare_constant handles. */
2355
2356 static tree
2357 copy_constant (tree exp)
2358 {
2359 switch (TREE_CODE (exp))
2360 {
2361 case ADDR_EXPR:
2362 /* For ADDR_EXPR, we do not want to copy the decl whose address
2363 is requested. We do want to copy constants though. */
2364 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2365 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2366 copy_constant (TREE_OPERAND (exp, 0)));
2367 else
2368 return copy_node (exp);
2369
2370 case INTEGER_CST:
2371 case REAL_CST:
2372 case STRING_CST:
2373 return copy_node (exp);
2374
2375 case COMPLEX_CST:
2376 return build_complex (TREE_TYPE (exp),
2377 copy_constant (TREE_REALPART (exp)),
2378 copy_constant (TREE_IMAGPART (exp)));
2379
2380 case PLUS_EXPR:
2381 case MINUS_EXPR:
2382 return build (TREE_CODE (exp), TREE_TYPE (exp),
2383 copy_constant (TREE_OPERAND (exp, 0)),
2384 copy_constant (TREE_OPERAND (exp, 1)));
2385
2386 case NOP_EXPR:
2387 case CONVERT_EXPR:
2388 case NON_LVALUE_EXPR:
2389 case VIEW_CONVERT_EXPR:
2390 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2391 copy_constant (TREE_OPERAND (exp, 0)));
2392
2393 case CONSTRUCTOR:
2394 {
2395 tree copy = copy_node (exp);
2396 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2397 tree tail;
2398
2399 CONSTRUCTOR_ELTS (copy) = list;
2400 for (tail = list; tail; tail = TREE_CHAIN (tail))
2401 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2402 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2403 for (tail = list; tail; tail = TREE_CHAIN (tail))
2404 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2405
2406 return copy;
2407 }
2408
2409 default:
2410 {
2411 tree t;
2412 t = (*lang_hooks.expand_constant) (exp);
2413 if (t != exp)
2414 return copy_constant (t);
2415 else
2416 abort ();
2417 }
2418 }
2419 }
2420 \f
2421 /* Subroutine of output_constant_def:
2422 No constant equal to EXP is known to have been output.
2423 Make a constant descriptor to enter EXP in the hash table.
2424 Assign the label number and construct RTL to refer to the
2425 constant's location in memory.
2426 Caller is responsible for updating the hash table. */
2427
2428 static struct constant_descriptor_tree *
2429 build_constant_desc (tree exp)
2430 {
2431 rtx symbol;
2432 rtx rtl;
2433 char label[256];
2434 int labelno;
2435 struct constant_descriptor_tree *desc;
2436
2437 desc = ggc_alloc (sizeof (*desc));
2438 desc->value = copy_constant (exp);
2439
2440 /* Create a string containing the label name, in LABEL. */
2441 labelno = const_labelno++;
2442 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2443
2444 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2445 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2446 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2447 SYMBOL_REF_DECL (symbol) = desc->value;
2448 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2449
2450 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2451 set_mem_attributes (rtl, exp, 1);
2452 set_mem_alias_set (rtl, 0);
2453 set_mem_alias_set (rtl, const_alias_set);
2454
2455 /* Set flags or add text to the name to record information, such as
2456 that it is a local symbol. If the name is changed, the macro
2457 ASM_OUTPUT_LABELREF will have to know how to strip this
2458 information. This call might invalidate our local variable
2459 SYMBOL; we can't use it afterward. */
2460
2461 (*targetm.encode_section_info) (exp, rtl, true);
2462
2463 desc->rtl = rtl;
2464
2465 return desc;
2466 }
2467
2468 /* Return an rtx representing a reference to constant data in memory
2469 for the constant expression EXP.
2470
2471 If assembler code for such a constant has already been output,
2472 return an rtx to refer to it.
2473 Otherwise, output such a constant in memory
2474 and generate an rtx for it.
2475
2476 If DEFER is nonzero, this constant can be deferred and output only
2477 if referenced in the function after all optimizations.
2478
2479 The const_hash_table records which constants already have label strings. */
2480
2481 rtx
2482 output_constant_def (tree exp, int defer)
2483 {
2484 struct constant_descriptor_tree *desc;
2485 struct constant_descriptor_tree key;
2486 void **loc;
2487
2488 /* Look up EXP in the table of constant descriptors. If we didn't find
2489 it, create a new one. */
2490 key.value = exp;
2491 loc = htab_find_slot (const_desc_htab, &key, INSERT);
2492
2493 desc = *loc;
2494 if (desc == 0)
2495 {
2496 desc = build_constant_desc (exp);
2497 *loc = desc;
2498 }
2499
2500 maybe_output_constant_def_contents (desc, defer);
2501 return desc->rtl;
2502 }
2503
2504 /* Subroutine of output_constant_def: Decide whether or not we need to
2505 output the constant DESC now, and if so, do it. */
2506 static void
2507 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
2508 int defer)
2509 {
2510 rtx symbol = XEXP (desc->rtl, 0);
2511 tree exp = desc->value;
2512
2513 if (flag_syntax_only)
2514 return;
2515
2516 if (TREE_ASM_WRITTEN (exp))
2517 /* Already output; don't do it again. */
2518 return;
2519
2520 /* The only constants that cannot safely be deferred, assuming the
2521 context allows it, are strings under flag_writable_strings. */
2522 if (defer && (TREE_CODE (exp) != STRING_CST || !flag_writable_strings))
2523 {
2524 /* Increment n_deferred_constants if it exists. It needs to be at
2525 least as large as the number of constants actually referred to
2526 by the function. If it's too small we'll stop looking too early
2527 and fail to emit constants; if it's too large we'll only look
2528 through the entire function when we could have stopped earlier. */
2529 if (cfun)
2530 n_deferred_constants++;
2531 return;
2532 }
2533
2534 output_constant_def_contents (symbol);
2535 }
2536
2537 /* We must output the constant data referred to by SYMBOL; do so. */
2538
2539 static void
2540 output_constant_def_contents (rtx symbol)
2541 {
2542 tree exp = SYMBOL_REF_DECL (symbol);
2543 const char *label = XSTR (symbol, 0);
2544 HOST_WIDE_INT size;
2545
2546 /* Make sure any other constants whose addresses appear in EXP
2547 are assigned label numbers. */
2548 int reloc = compute_reloc_for_constant (exp);
2549
2550 /* Align the location counter as required by EXP's data type. */
2551 int align = TYPE_ALIGN (TREE_TYPE (exp));
2552 #ifdef CONSTANT_ALIGNMENT
2553 align = CONSTANT_ALIGNMENT (exp, align);
2554 #endif
2555
2556 output_addressed_constants (exp);
2557
2558 /* We are no longer deferring this constant. */
2559 TREE_ASM_WRITTEN (exp) = 1;
2560
2561 if (IN_NAMED_SECTION (exp))
2562 named_section (exp, NULL, reloc);
2563 else
2564 (*targetm.asm_out.select_section) (exp, reloc, align);
2565
2566 if (align > BITS_PER_UNIT)
2567 {
2568 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2569 }
2570
2571 size = int_size_in_bytes (TREE_TYPE (exp));
2572 if (TREE_CODE (exp) == STRING_CST)
2573 size = MAX (TREE_STRING_LENGTH (exp), size);
2574
2575 /* Do any machine/system dependent processing of the constant. */
2576 #ifdef ASM_DECLARE_CONSTANT_NAME
2577 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
2578 #else
2579 /* Standard thing is just output label for the constant. */
2580 ASM_OUTPUT_LABEL (asm_out_file, label);
2581 #endif /* ASM_DECLARE_CONSTANT_NAME */
2582
2583 /* Output the value of EXP. */
2584 output_constant (exp, size, align);
2585 }
2586
2587 /* A constant which was deferred in its original location has been
2588 inserted by the RTL inliner into a different function. The
2589 current function's deferred constant count must be incremented. */
2590 void
2591 notice_rtl_inlining_of_deferred_constant (void)
2592 {
2593 n_deferred_constants++;
2594 }
2595
2596 /* Look up EXP in the table of constant descriptors. Return the rtl
2597 if it has been emitted, else null. */
2598
2599 rtx
2600 lookup_constant_def (tree exp)
2601 {
2602 struct constant_descriptor_tree *desc;
2603 struct constant_descriptor_tree key;
2604
2605 key.value = exp;
2606 desc = htab_find (const_desc_htab, &key);
2607
2608 return (desc ? desc->rtl : NULL_RTX);
2609 }
2610 \f
2611 /* Used in the hash tables to avoid outputting the same constant
2612 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2613 are output once per function, not once per file; there seems
2614 to be no reason for the difference. */
2615
2616 struct constant_descriptor_rtx GTY(())
2617 {
2618 /* More constant_descriptors with the same hash code. */
2619 struct constant_descriptor_rtx *next;
2620
2621 /* A MEM for the constant. */
2622 rtx rtl;
2623
2624 /* The value of the constant. */
2625 struct rtx_const value;
2626 };
2627
2628 /* Structure to represent sufficient information about a constant so that
2629 it can be output when the constant pool is output, so that function
2630 integration can be done, and to simplify handling on machines that reference
2631 constant pool as base+displacement. */
2632
2633 struct pool_constant GTY(())
2634 {
2635 struct constant_descriptor_rtx *desc;
2636 struct pool_constant *next;
2637 struct pool_constant *next_sym;
2638 rtx constant;
2639 enum machine_mode mode;
2640 int labelno;
2641 unsigned int align;
2642 HOST_WIDE_INT offset;
2643 int mark;
2644 };
2645
2646 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2647 The argument is XSTR (... , 0) */
2648
2649 #define SYMHASH(LABEL) (((unsigned long) (LABEL)) % MAX_RTX_HASH_TABLE)
2650 \f
2651 /* Initialize constant pool hashing for a new function. */
2652
2653 void
2654 init_varasm_status (struct function *f)
2655 {
2656 struct varasm_status *p;
2657 p = ggc_alloc (sizeof (struct varasm_status));
2658 f->varasm = p;
2659 p->x_const_rtx_hash_table
2660 = ggc_alloc_cleared (MAX_RTX_HASH_TABLE
2661 * sizeof (struct constant_descriptor_rtx *));
2662 p->x_const_rtx_sym_hash_table
2663 = ggc_alloc_cleared (MAX_RTX_HASH_TABLE
2664 * sizeof (struct pool_constant *));
2665
2666 p->x_first_pool = p->x_last_pool = 0;
2667 p->x_pool_offset = 0;
2668 p->deferred_constants = 0;
2669 }
2670 \f
2671
2672 /* Express an rtx for a constant integer (perhaps symbolic)
2673 as the sum of a symbol or label plus an explicit integer.
2674 They are stored into VALUE. */
2675
2676 static void
2677 decode_rtx_const (enum machine_mode mode, rtx x, struct rtx_const *value)
2678 {
2679 /* Clear the whole structure, including any gaps. */
2680 memset (value, 0, sizeof (struct rtx_const));
2681
2682 value->kind = RTX_INT; /* Most usual kind. */
2683 value->mode = mode;
2684
2685 switch (GET_CODE (x))
2686 {
2687 case CONST_DOUBLE:
2688 value->kind = RTX_DOUBLE;
2689 if (GET_MODE (x) != VOIDmode)
2690 {
2691 const REAL_VALUE_TYPE *r = CONST_DOUBLE_REAL_VALUE (x);
2692
2693 value->mode = GET_MODE (x);
2694
2695 /* Copy the REAL_VALUE_TYPE by members so that we don't
2696 copy garbage from the original structure into our
2697 carefully cleaned hashing structure. */
2698 value->un.du.class = r->class;
2699 value->un.du.sign = r->sign;
2700 switch (r->class)
2701 {
2702 case rvc_zero:
2703 case rvc_inf:
2704 break;
2705 case rvc_normal:
2706 value->un.du.exp = r->exp;
2707 /* FALLTHRU */
2708 case rvc_nan:
2709 memcpy (value->un.du.sig, r->sig, sizeof (r->sig));
2710 break;
2711 default:
2712 abort ();
2713 }
2714 }
2715 else
2716 {
2717 value->un.di.low = CONST_DOUBLE_LOW (x);
2718 value->un.di.high = CONST_DOUBLE_HIGH (x);
2719 }
2720 break;
2721
2722 case CONST_VECTOR:
2723 {
2724 int units, i;
2725
2726 units = CONST_VECTOR_NUNITS (x);
2727 value->kind = RTX_VECTOR;
2728 value->mode = mode;
2729
2730 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
2731 {
2732 for (i = 0; i < units; ++i)
2733 {
2734 rtx elt = CONST_VECTOR_ELT (x, i);
2735 if (GET_CODE (elt) == CONST_INT)
2736 {
2737 value->un.int_vec[i].low = INTVAL (elt);
2738 value->un.int_vec[i].high = 0;
2739 }
2740 else
2741 {
2742 value->un.int_vec[i].low = CONST_DOUBLE_LOW (elt);
2743 value->un.int_vec[i].high = CONST_DOUBLE_HIGH (elt);
2744 }
2745 }
2746 }
2747 else if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
2748 {
2749 for (i = 0; i < units; ++i)
2750 {
2751 const REAL_VALUE_TYPE *r
2752 = CONST_DOUBLE_REAL_VALUE (CONST_VECTOR_ELT (x, i));
2753 REAL_VALUE_TYPE *d = &value->un.fp_vec[i];
2754
2755 /* Copy the REAL_VALUE_TYPE by members so that we don't
2756 copy garbage from the original structure into our
2757 carefully cleaned hashing structure. */
2758 d->class = r->class;
2759 d->sign = r->sign;
2760 switch (r->class)
2761 {
2762 case rvc_zero:
2763 case rvc_inf:
2764 break;
2765 case rvc_normal:
2766 d->exp = r->exp;
2767 /* FALLTHRU */
2768 case rvc_nan:
2769 memcpy (d->sig, r->sig, sizeof (r->sig));
2770 break;
2771 default:
2772 abort ();
2773 }
2774 }
2775 }
2776 else
2777 abort ();
2778 }
2779 break;
2780
2781 case CONST_INT:
2782 value->un.addr.offset = INTVAL (x);
2783 break;
2784
2785 case SYMBOL_REF:
2786 case LABEL_REF:
2787 case PC:
2788 value->un.addr.base = x;
2789 break;
2790
2791 case CONST:
2792 x = XEXP (x, 0);
2793 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
2794 {
2795 value->un.addr.base = XEXP (x, 0);
2796 value->un.addr.offset = INTVAL (XEXP (x, 1));
2797 }
2798 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
2799 {
2800 value->un.addr.base = XEXP (x, 0);
2801 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2802 }
2803 else
2804 {
2805 value->un.addr.base = x;
2806 value->un.addr.offset = 0;
2807 }
2808 break;
2809
2810 default:
2811 value->kind = RTX_UNKNOWN;
2812 break;
2813 }
2814
2815 if (value->kind == RTX_INT && value->un.addr.base != 0
2816 && GET_CODE (value->un.addr.base) == UNSPEC)
2817 {
2818 /* For a simple UNSPEC, the base is set to the
2819 operand, the kind field is set to the index of
2820 the unspec expression.
2821 Together with the code below, in case that
2822 the operand is a SYMBOL_REF or LABEL_REF,
2823 the address of the string or the code_label
2824 is taken as base. */
2825 if (XVECLEN (value->un.addr.base, 0) == 1)
2826 {
2827 value->kind = RTX_UNSPEC + XINT (value->un.addr.base, 1);
2828 value->un.addr.base = XVECEXP (value->un.addr.base, 0, 0);
2829 }
2830 }
2831
2832 if (value->kind >= RTX_INT && value->un.addr.base != 0)
2833 switch (GET_CODE (value->un.addr.base))
2834 {
2835 case SYMBOL_REF:
2836 /* Use the string's address, not the SYMBOL_REF's address,
2837 for the sake of addresses of library routines. */
2838 value->un.addr.symbol = XSTR (value->un.addr.base, 0);
2839 value->un.addr.base = NULL_RTX;
2840 break;
2841
2842 case LABEL_REF:
2843 /* For a LABEL_REF, compare labels. */
2844 value->un.addr.base = XEXP (value->un.addr.base, 0);
2845
2846 default:
2847 break;
2848 }
2849 }
2850
2851 /* Given a MINUS expression, simplify it if both sides
2852 include the same symbol. */
2853
2854 rtx
2855 simplify_subtraction (rtx x)
2856 {
2857 struct rtx_const val0, val1;
2858
2859 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2860 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2861
2862 if (val0.kind >= RTX_INT
2863 && val0.kind == val1.kind
2864 && val0.un.addr.base == val1.un.addr.base
2865 && val0.un.addr.symbol == val1.un.addr.symbol)
2866 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2867
2868 return x;
2869 }
2870
2871 /* Compute a hash code for a constant RTL expression. */
2872
2873 static unsigned int
2874 const_hash_rtx (enum machine_mode mode, rtx x)
2875 {
2876 union {
2877 struct rtx_const value;
2878 unsigned int data[sizeof(struct rtx_const) / sizeof (unsigned int)];
2879 } u;
2880
2881 unsigned int hi;
2882 size_t i;
2883
2884 decode_rtx_const (mode, x, &u.value);
2885
2886 /* Compute hashing function. */
2887 hi = 0;
2888 for (i = 0; i < ARRAY_SIZE (u.data); i++)
2889 hi = hi * 613 + u.data[i];
2890
2891 return hi % MAX_RTX_HASH_TABLE;
2892 }
2893
2894 /* Compare a constant rtl object X with a constant-descriptor DESC.
2895 Return 1 if DESC describes a constant with the same value as X. */
2896
2897 static int
2898 compare_constant_rtx (enum machine_mode mode, rtx x,
2899 struct constant_descriptor_rtx *desc)
2900 {
2901 struct rtx_const value;
2902
2903 decode_rtx_const (mode, x, &value);
2904
2905 /* Compare constant contents. */
2906 return memcmp (&value, &desc->value, sizeof (struct rtx_const)) == 0;
2907 }
2908
2909 /* Construct a constant descriptor for the rtl-expression X.
2910 It is up to the caller to enter the descriptor in the hash table. */
2911
2912 static struct constant_descriptor_rtx *
2913 record_constant_rtx (enum machine_mode mode, rtx x)
2914 {
2915 struct constant_descriptor_rtx *ptr;
2916
2917 ptr = ggc_alloc (sizeof (*ptr));
2918 decode_rtx_const (mode, x, &ptr->value);
2919
2920 return ptr;
2921 }
2922 \f
2923 /* Given a constant rtx X, make (or find) a memory constant for its value
2924 and return a MEM rtx to refer to it in memory. */
2925
2926 rtx
2927 force_const_mem (enum machine_mode mode, rtx x)
2928 {
2929 int hash;
2930 struct constant_descriptor_rtx *desc;
2931 char label[256];
2932 rtx def, symbol;
2933 struct pool_constant *pool;
2934 unsigned int align;
2935
2936 /* If we're not allowed to drop X into the constant pool, don't. */
2937 if ((*targetm.cannot_force_const_mem) (x))
2938 return NULL_RTX;
2939
2940 /* Compute hash code of X. Search the descriptors for that hash code
2941 to see if any of them describes X. If yes, we have an rtx to use. */
2942 hash = const_hash_rtx (mode, x);
2943 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2944 if (compare_constant_rtx (mode, x, desc))
2945 return copy_rtx (desc->rtl);
2946
2947 /* No constant equal to X is known to have been output.
2948 Make a constant descriptor to enter X in the hash table
2949 and make a MEM for it. */
2950 desc = record_constant_rtx (mode, x);
2951 desc->next = const_rtx_hash_table[hash];
2952 const_rtx_hash_table[hash] = desc;
2953
2954 /* Align the location counter as required by EXP's data type. */
2955 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
2956 #ifdef CONSTANT_ALIGNMENT
2957 {
2958 tree type = (*lang_hooks.types.type_for_mode) (mode, 0);
2959 if (type != NULL_TREE)
2960 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
2961 }
2962 #endif
2963
2964 pool_offset += (align / BITS_PER_UNIT) - 1;
2965 pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
2966
2967 if (GET_CODE (x) == LABEL_REF)
2968 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
2969
2970 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2971 pool = ggc_alloc (sizeof (struct pool_constant));
2972 pool->desc = desc;
2973 pool->constant = x;
2974 pool->mode = mode;
2975 pool->labelno = const_labelno;
2976 pool->align = align;
2977 pool->offset = pool_offset;
2978 pool->mark = 1;
2979 pool->next = 0;
2980
2981 if (last_pool == 0)
2982 first_pool = pool;
2983 else
2984 last_pool->next = pool;
2985
2986 last_pool = pool;
2987 pool_offset += GET_MODE_SIZE (mode);
2988
2989 /* Create a string containing the label name, in LABEL. */
2990 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2991
2992 ++const_labelno;
2993
2994 /* Construct the SYMBOL_REF and the MEM. */
2995
2996 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2997 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2998
2999 pool->desc->rtl = def = gen_rtx_MEM (mode, symbol);
3000 set_mem_attributes (def, (*lang_hooks.types.type_for_mode) (mode, 0), 1);
3001 RTX_UNCHANGING_P (def) = 1;
3002
3003 /* Add label to symbol hash table. */
3004 hash = SYMHASH (XSTR (symbol, 0));
3005 pool->next_sym = const_rtx_sym_hash_table[hash];
3006 const_rtx_sym_hash_table[hash] = pool;
3007
3008 /* Mark the symbol_ref as belonging to this constants pool. */
3009 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3010 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
3011 current_function_uses_const_pool = 1;
3012
3013 return copy_rtx (def);
3014 }
3015 \f
3016 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3017 the corresponding pool_constant structure. */
3018
3019 static struct pool_constant *
3020 find_pool_constant (struct function *f, rtx addr)
3021 {
3022 struct pool_constant *pool;
3023 const char *label = XSTR (addr, 0);
3024
3025 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3026 pool = pool->next_sym)
3027 if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label)
3028 return pool;
3029
3030 abort ();
3031 }
3032
3033 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3034
3035 rtx
3036 get_pool_constant (rtx addr)
3037 {
3038 return (find_pool_constant (cfun, addr))->constant;
3039 }
3040
3041 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3042 and whether it has been output or not. */
3043
3044 rtx
3045 get_pool_constant_mark (rtx addr, bool *pmarked)
3046 {
3047 struct pool_constant *pool = find_pool_constant (cfun, addr);
3048 *pmarked = (pool->mark != 0);
3049 return pool->constant;
3050 }
3051
3052 /* Likewise, but for the constant pool of a specific function. */
3053
3054 rtx
3055 get_pool_constant_for_function (struct function *f, rtx addr)
3056 {
3057 return (find_pool_constant (f, addr))->constant;
3058 }
3059
3060 /* Similar, return the mode. */
3061
3062 enum machine_mode
3063 get_pool_mode (rtx addr)
3064 {
3065 return (find_pool_constant (cfun, addr))->mode;
3066 }
3067
3068 enum machine_mode
3069 get_pool_mode_for_function (struct function *f, rtx addr)
3070 {
3071 return (find_pool_constant (f, addr))->mode;
3072 }
3073
3074 /* Similar, return the offset in the constant pool. */
3075
3076 int
3077 get_pool_offset (rtx addr)
3078 {
3079 return (find_pool_constant (cfun, addr))->offset;
3080 }
3081
3082 /* Return the size of the constant pool. */
3083
3084 int
3085 get_pool_size (void)
3086 {
3087 return pool_offset;
3088 }
3089 \f
3090 /* Write all the constants in the constant pool. */
3091
3092 void
3093 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3094 tree fndecl ATTRIBUTE_UNUSED)
3095 {
3096 struct pool_constant *pool;
3097 rtx x;
3098 REAL_VALUE_TYPE r;
3099
3100 /* It is possible for gcc to call force_const_mem and then to later
3101 discard the instructions which refer to the constant. In such a
3102 case we do not need to output the constant. */
3103 mark_constant_pool ();
3104
3105 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3106 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3107 #endif
3108
3109 for (pool = first_pool; pool; pool = pool->next)
3110 {
3111 rtx tmp;
3112
3113 x = pool->constant;
3114
3115 if (! pool->mark)
3116 continue;
3117
3118 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3119 whose CODE_LABEL has been deleted. This can occur if a jump table
3120 is eliminated by optimization. If so, write a constant of zero
3121 instead. Note that this can also happen by turning the
3122 CODE_LABEL into a NOTE. */
3123 /* ??? This seems completely and utterly wrong. Certainly it's
3124 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3125 functioning even with INSN_DELETED_P and friends. */
3126
3127 tmp = x;
3128 switch (GET_CODE (x))
3129 {
3130 case CONST:
3131 if (GET_CODE (XEXP (x, 0)) != PLUS
3132 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3133 break;
3134 tmp = XEXP (XEXP (x, 0), 0);
3135 /* FALLTHRU */
3136
3137 case LABEL_REF:
3138 tmp = XEXP (x, 0);
3139 if (INSN_DELETED_P (tmp)
3140 || (GET_CODE (tmp) == NOTE
3141 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
3142 {
3143 abort ();
3144 x = const0_rtx;
3145 }
3146 break;
3147
3148 default:
3149 break;
3150 }
3151
3152 /* First switch to correct section. */
3153 (*targetm.asm_out.select_rtx_section) (pool->mode, x, pool->align);
3154
3155 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3156 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3157 pool->align, pool->labelno, done);
3158 #endif
3159
3160 assemble_align (pool->align);
3161
3162 /* Output the label. */
3163 (*targetm.asm_out.internal_label) (asm_out_file, "LC", pool->labelno);
3164
3165 /* Output the value of the constant itself. */
3166 switch (GET_MODE_CLASS (pool->mode))
3167 {
3168 case MODE_FLOAT:
3169 if (GET_CODE (x) != CONST_DOUBLE)
3170 abort ();
3171
3172 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3173 assemble_real (r, pool->mode, pool->align);
3174 break;
3175
3176 case MODE_INT:
3177 case MODE_PARTIAL_INT:
3178 assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
3179 break;
3180
3181 case MODE_VECTOR_FLOAT:
3182 {
3183 int i, units;
3184 rtx elt;
3185
3186 if (GET_CODE (x) != CONST_VECTOR)
3187 abort ();
3188
3189 units = CONST_VECTOR_NUNITS (x);
3190
3191 for (i = 0; i < units; i++)
3192 {
3193 elt = CONST_VECTOR_ELT (x, i);
3194 REAL_VALUE_FROM_CONST_DOUBLE (r, elt);
3195 assemble_real (r, GET_MODE_INNER (pool->mode), pool->align);
3196 }
3197 }
3198 break;
3199
3200 case MODE_VECTOR_INT:
3201 {
3202 int i, units;
3203 rtx elt;
3204
3205 if (GET_CODE (x) != CONST_VECTOR)
3206 abort ();
3207
3208 units = CONST_VECTOR_NUNITS (x);
3209
3210 for (i = 0; i < units; i++)
3211 {
3212 elt = CONST_VECTOR_ELT (x, i);
3213 assemble_integer (elt, GET_MODE_UNIT_SIZE (pool->mode),
3214 pool->align, 1);
3215 }
3216 }
3217 break;
3218
3219 default:
3220 abort ();
3221 }
3222
3223 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3224 sections have proper size. */
3225 if (pool->align > GET_MODE_BITSIZE (pool->mode)
3226 && in_section == in_named
3227 && get_named_section_flags (in_named_name) & SECTION_MERGE)
3228 assemble_align (pool->align);
3229
3230 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3231 done: ;
3232 #endif
3233 }
3234
3235 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3236 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3237 #endif
3238
3239 /* Done with this pool. */
3240 first_pool = last_pool = 0;
3241 }
3242
3243 /* Look through the instructions for this function, and mark all the
3244 entries in the constant pool which are actually being used. Emit
3245 deferred constants which have indeed been used. */
3246
3247 static void
3248 mark_constant_pool (void)
3249 {
3250 rtx insn;
3251 rtx link;
3252 struct pool_constant *pool;
3253
3254 if (first_pool == 0 && n_deferred_constants == 0)
3255 return;
3256
3257 for (pool = first_pool; pool; pool = pool->next)
3258 pool->mark = 0;
3259
3260 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3261 if (INSN_P (insn))
3262 mark_constants (PATTERN (insn));
3263
3264 for (link = current_function_epilogue_delay_list;
3265 link;
3266 link = XEXP (link, 1))
3267 {
3268 insn = XEXP (link, 0);
3269
3270 if (INSN_P (insn))
3271 mark_constants (PATTERN (insn));
3272 }
3273 }
3274
3275 /* Look through appropriate parts of X, marking all entries in the
3276 constant pool which are actually being used. Entries that are only
3277 referenced by other constants are also marked as used. Emit
3278 deferred strings that are used. */
3279
3280 static void
3281 mark_constants (rtx x)
3282 {
3283 int i;
3284 const char *format_ptr;
3285
3286 if (x == 0)
3287 return;
3288
3289 if (GET_CODE (x) == SYMBOL_REF)
3290 {
3291 mark_constant (&x, NULL);
3292 return;
3293 }
3294
3295 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3296 insns, not any notes that may be attached. We don't want to mark
3297 a constant just because it happens to appear in a REG_EQUIV note. */
3298 if (INSN_P (x))
3299 {
3300 mark_constants (PATTERN (x));
3301 return;
3302 }
3303
3304 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3305
3306 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3307 {
3308 switch (*format_ptr++)
3309 {
3310 case 'e':
3311 mark_constants (XEXP (x, i));
3312 break;
3313
3314 case 'E':
3315 if (XVEC (x, i) != 0)
3316 {
3317 int j;
3318
3319 for (j = 0; j < XVECLEN (x, i); j++)
3320 mark_constants (XVECEXP (x, i, j));
3321 }
3322 break;
3323
3324 case 'S':
3325 case 's':
3326 case '0':
3327 case 'i':
3328 case 'w':
3329 case 'n':
3330 case 'u':
3331 case 'B':
3332 break;
3333
3334 default:
3335 abort ();
3336 }
3337 }
3338 }
3339
3340 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3341 to as used. Emit referenced deferred strings. This function can
3342 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3343
3344 static int
3345 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3346 {
3347 rtx x = *current_rtx;
3348
3349 if (x == NULL_RTX)
3350 return 0;
3351
3352 else if (GET_CODE (x) == SYMBOL_REF)
3353 {
3354 if (CONSTANT_POOL_ADDRESS_P (x))
3355 {
3356 struct pool_constant *pool = find_pool_constant (cfun, x);
3357 if (pool->mark == 0)
3358 {
3359 pool->mark = 1;
3360 for_each_rtx (&(pool->constant), &mark_constant, NULL);
3361 }
3362 else
3363 return -1;
3364 }
3365 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3366 {
3367 tree exp = SYMBOL_REF_DECL (x);
3368 if (!TREE_ASM_WRITTEN (exp))
3369 {
3370 n_deferred_constants--;
3371 output_constant_def_contents (x);
3372 }
3373 }
3374 }
3375 return 0;
3376 }
3377 \f
3378 /* Determine what kind of relocations EXP may need. */
3379
3380 int
3381 compute_reloc_for_constant (tree exp)
3382 {
3383 int reloc = 0, reloc2;
3384 tree tem;
3385
3386 /* Give the front-end a chance to convert VALUE to something that
3387 looks more like a constant to the back-end. */
3388 exp = (*lang_hooks.expand_constant) (exp);
3389
3390 switch (TREE_CODE (exp))
3391 {
3392 case ADDR_EXPR:
3393 case FDESC_EXPR:
3394 /* Go inside any operations that get_inner_reference can handle and see
3395 if what's inside is a constant: no need to do anything here for
3396 addresses of variables or functions. */
3397 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3398 tem = TREE_OPERAND (tem, 0))
3399 ;
3400
3401 if (TREE_PUBLIC (tem))
3402 reloc |= 2;
3403 else
3404 reloc |= 1;
3405 break;
3406
3407 case PLUS_EXPR:
3408 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3409 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3410 break;
3411
3412 case MINUS_EXPR:
3413 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3414 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3415 /* The difference of two local labels is computable at link time. */
3416 if (reloc == 1 && reloc2 == 1)
3417 reloc = 0;
3418 else
3419 reloc |= reloc2;
3420 break;
3421
3422 case NOP_EXPR:
3423 case CONVERT_EXPR:
3424 case NON_LVALUE_EXPR:
3425 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3426 break;
3427
3428 case CONSTRUCTOR:
3429 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3430 if (TREE_VALUE (tem) != 0)
3431 reloc |= compute_reloc_for_constant (TREE_VALUE (tem));
3432
3433 break;
3434
3435 default:
3436 break;
3437 }
3438 return reloc;
3439 }
3440
3441 /* Find all the constants whose addresses are referenced inside of EXP,
3442 and make sure assembler code with a label has been output for each one.
3443 Indicate whether an ADDR_EXPR has been encountered. */
3444
3445 static void
3446 output_addressed_constants (tree exp)
3447 {
3448 tree tem;
3449
3450 /* Give the front-end a chance to convert VALUE to something that
3451 looks more like a constant to the back-end. */
3452 exp = (*lang_hooks.expand_constant) (exp);
3453
3454 switch (TREE_CODE (exp))
3455 {
3456 case ADDR_EXPR:
3457 case FDESC_EXPR:
3458 /* Go inside any operations that get_inner_reference can handle and see
3459 if what's inside is a constant: no need to do anything here for
3460 addresses of variables or functions. */
3461 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3462 tem = TREE_OPERAND (tem, 0))
3463 ;
3464
3465 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
3466 || TREE_CODE (tem) == CONSTRUCTOR)
3467 output_constant_def (tem, 0);
3468 break;
3469
3470 case PLUS_EXPR:
3471 case MINUS_EXPR:
3472 output_addressed_constants (TREE_OPERAND (exp, 1));
3473 /* Fall through. */
3474
3475 case NOP_EXPR:
3476 case CONVERT_EXPR:
3477 case NON_LVALUE_EXPR:
3478 output_addressed_constants (TREE_OPERAND (exp, 0));
3479 break;
3480
3481 case CONSTRUCTOR:
3482 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3483 if (TREE_VALUE (tem) != 0)
3484 output_addressed_constants (TREE_VALUE (tem));
3485
3486 break;
3487
3488 default:
3489 break;
3490 }
3491 }
3492 \f
3493 /* Return nonzero if VALUE is a valid constant-valued expression
3494 for use in initializing a static variable; one that can be an
3495 element of a "constant" initializer.
3496
3497 Return null_pointer_node if the value is absolute;
3498 if it is relocatable, return the variable that determines the relocation.
3499 We assume that VALUE has been folded as much as possible;
3500 therefore, we do not need to check for such things as
3501 arithmetic-combinations of integers. */
3502
3503 tree
3504 initializer_constant_valid_p (tree value, tree endtype)
3505 {
3506 /* Give the front-end a chance to convert VALUE to something that
3507 looks more like a constant to the back-end. */
3508 value = (*lang_hooks.expand_constant) (value);
3509
3510 switch (TREE_CODE (value))
3511 {
3512 case CONSTRUCTOR:
3513 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
3514 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
3515 && TREE_CONSTANT (value)
3516 && CONSTRUCTOR_ELTS (value))
3517 {
3518 tree elt;
3519 bool absolute = true;
3520
3521 for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt))
3522 {
3523 tree reloc;
3524 value = TREE_VALUE (elt);
3525 reloc = initializer_constant_valid_p (value, TREE_TYPE (value));
3526 if (!reloc)
3527 return NULL_TREE;
3528 if (reloc != null_pointer_node)
3529 absolute = false;
3530 }
3531 /* For a non-absolute relocation, there is no single
3532 variable that can be "the variable that determines the
3533 relocation." */
3534 return absolute ? null_pointer_node : error_mark_node;
3535 }
3536
3537 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
3538
3539 case INTEGER_CST:
3540 case VECTOR_CST:
3541 case REAL_CST:
3542 case STRING_CST:
3543 case COMPLEX_CST:
3544 return null_pointer_node;
3545
3546 case ADDR_EXPR:
3547 case FDESC_EXPR:
3548 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
3549
3550 case VIEW_CONVERT_EXPR:
3551 case NON_LVALUE_EXPR:
3552 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3553
3554 case CONVERT_EXPR:
3555 case NOP_EXPR:
3556 /* Allow conversions between pointer types. */
3557 if (POINTER_TYPE_P (TREE_TYPE (value))
3558 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3559 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3560
3561 /* Allow conversions between real types. */
3562 if (FLOAT_TYPE_P (TREE_TYPE (value))
3563 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3564 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3565
3566 /* Allow length-preserving conversions between integer types. */
3567 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3568 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3569 && (TYPE_PRECISION (TREE_TYPE (value))
3570 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3571 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3572
3573 /* Allow conversions between other integer types only if
3574 explicit value. */
3575 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3576 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3577 {
3578 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3579 endtype);
3580 if (inner == null_pointer_node)
3581 return null_pointer_node;
3582 break;
3583 }
3584
3585 /* Allow (int) &foo provided int is as wide as a pointer. */
3586 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3587 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3588 && (TYPE_PRECISION (TREE_TYPE (value))
3589 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3590 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3591 endtype);
3592
3593 /* Likewise conversions from int to pointers, but also allow
3594 conversions from 0. */
3595 if (POINTER_TYPE_P (TREE_TYPE (value))
3596 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3597 {
3598 if (integer_zerop (TREE_OPERAND (value, 0)))
3599 return null_pointer_node;
3600 else if (TYPE_PRECISION (TREE_TYPE (value))
3601 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
3602 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3603 endtype);
3604 }
3605
3606 /* Allow conversions to union types if the value inside is okay. */
3607 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
3608 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3609 endtype);
3610 break;
3611
3612 case PLUS_EXPR:
3613 if (! INTEGRAL_TYPE_P (endtype)
3614 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3615 {
3616 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3617 endtype);
3618 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3619 endtype);
3620 /* If either term is absolute, use the other terms relocation. */
3621 if (valid0 == null_pointer_node)
3622 return valid1;
3623 if (valid1 == null_pointer_node)
3624 return valid0;
3625 }
3626 break;
3627
3628 case MINUS_EXPR:
3629 if (! INTEGRAL_TYPE_P (endtype)
3630 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3631 {
3632 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3633 endtype);
3634 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3635 endtype);
3636 /* Win if second argument is absolute. */
3637 if (valid1 == null_pointer_node)
3638 return valid0;
3639 /* Win if both arguments have the same relocation.
3640 Then the value is absolute. */
3641 if (valid0 == valid1 && valid0 != 0)
3642 return null_pointer_node;
3643
3644 /* Since GCC guarantees that string constants are unique in the
3645 generated code, a subtraction between two copies of the same
3646 constant string is absolute. */
3647 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
3648 valid1 && TREE_CODE (valid1) == STRING_CST &&
3649 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
3650 return null_pointer_node;
3651 }
3652
3653 /* Support differences between labels. */
3654 if (INTEGRAL_TYPE_P (endtype))
3655 {
3656 tree op0, op1;
3657 op0 = TREE_OPERAND (value, 0);
3658 op1 = TREE_OPERAND (value, 1);
3659
3660 /* Like STRIP_NOPS except allow the operand mode to widen.
3661 This works around a feature of fold that simplifies
3662 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3663 that the narrower operation is cheaper. */
3664
3665 while (TREE_CODE (op0) == NOP_EXPR
3666 || TREE_CODE (op0) == CONVERT_EXPR
3667 || TREE_CODE (op0) == NON_LVALUE_EXPR)
3668 {
3669 tree inner = TREE_OPERAND (op0, 0);
3670 if (inner == error_mark_node
3671 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3672 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3673 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3674 break;
3675 op0 = inner;
3676 }
3677
3678 while (TREE_CODE (op1) == NOP_EXPR
3679 || TREE_CODE (op1) == CONVERT_EXPR
3680 || TREE_CODE (op1) == NON_LVALUE_EXPR)
3681 {
3682 tree inner = TREE_OPERAND (op1, 0);
3683 if (inner == error_mark_node
3684 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3685 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3686 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3687 break;
3688 op1 = inner;
3689 }
3690
3691 if (TREE_CODE (op0) == ADDR_EXPR
3692 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
3693 && TREE_CODE (op1) == ADDR_EXPR
3694 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
3695 return null_pointer_node;
3696 }
3697 break;
3698
3699 default:
3700 break;
3701 }
3702
3703 return 0;
3704 }
3705 \f
3706 /* Output assembler code for constant EXP to FILE, with no label.
3707 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3708 Assumes output_addressed_constants has been done on EXP already.
3709
3710 Generate exactly SIZE bytes of assembler data, padding at the end
3711 with zeros if necessary. SIZE must always be specified.
3712
3713 SIZE is important for structure constructors,
3714 since trailing members may have been omitted from the constructor.
3715 It is also important for initialization of arrays from string constants
3716 since the full length of the string constant might not be wanted.
3717 It is also needed for initialization of unions, where the initializer's
3718 type is just one member, and that may not be as long as the union.
3719
3720 There a case in which we would fail to output exactly SIZE bytes:
3721 for a structure constructor that wants to produce more than SIZE bytes.
3722 But such constructors will never be generated for any possible input.
3723
3724 ALIGN is the alignment of the data in bits. */
3725
3726 void
3727 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
3728 {
3729 enum tree_code code;
3730 unsigned HOST_WIDE_INT thissize;
3731
3732 /* Some front-ends use constants other than the standard language-independent
3733 varieties, but which may still be output directly. Give the front-end a
3734 chance to convert EXP to a language-independent representation. */
3735 exp = (*lang_hooks.expand_constant) (exp);
3736
3737 if (size == 0 || flag_syntax_only)
3738 return;
3739
3740 /* Eliminate any conversions since we'll be outputting the underlying
3741 constant. */
3742 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3743 || TREE_CODE (exp) == NON_LVALUE_EXPR
3744 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
3745 exp = TREE_OPERAND (exp, 0);
3746
3747 code = TREE_CODE (TREE_TYPE (exp));
3748 thissize = int_size_in_bytes (TREE_TYPE (exp));
3749
3750 /* Allow a constructor with no elements for any data type.
3751 This means to fill the space with zeros. */
3752 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3753 {
3754 assemble_zeros (size);
3755 return;
3756 }
3757
3758 if (TREE_CODE (exp) == FDESC_EXPR)
3759 {
3760 #ifdef ASM_OUTPUT_FDESC
3761 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
3762 tree decl = TREE_OPERAND (exp, 0);
3763 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
3764 #else
3765 abort ();
3766 #endif
3767 return;
3768 }
3769
3770 /* Now output the underlying data. If we've handling the padding, return.
3771 Otherwise, break and ensure THISSIZE is the size written. */
3772 switch (code)
3773 {
3774 case CHAR_TYPE:
3775 case BOOLEAN_TYPE:
3776 case INTEGER_TYPE:
3777 case ENUMERAL_TYPE:
3778 case POINTER_TYPE:
3779 case REFERENCE_TYPE:
3780 case OFFSET_TYPE:
3781 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3782 EXPAND_INITIALIZER),
3783 size, align, 0))
3784 error ("initializer for integer value is too complicated");
3785 break;
3786
3787 case REAL_TYPE:
3788 if (TREE_CODE (exp) != REAL_CST)
3789 error ("initializer for floating value is not a floating constant");
3790
3791 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
3792 break;
3793
3794 case COMPLEX_TYPE:
3795 output_constant (TREE_REALPART (exp), thissize / 2, align);
3796 output_constant (TREE_IMAGPART (exp), thissize / 2,
3797 min_align (align, BITS_PER_UNIT * (thissize / 2)));
3798 break;
3799
3800 case ARRAY_TYPE:
3801 case VECTOR_TYPE:
3802 if (TREE_CODE (exp) == CONSTRUCTOR)
3803 {
3804 output_constructor (exp, size, align);
3805 return;
3806 }
3807 else if (TREE_CODE (exp) == STRING_CST)
3808 {
3809 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
3810 size);
3811 assemble_string (TREE_STRING_POINTER (exp), thissize);
3812 }
3813 else if (TREE_CODE (exp) == VECTOR_CST)
3814 {
3815 int elt_size;
3816 tree link;
3817 unsigned int nalign;
3818 enum machine_mode inner;
3819
3820 inner = GET_MODE_INNER (TYPE_MODE (TREE_TYPE (exp)));
3821 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
3822
3823 elt_size = GET_MODE_UNIT_SIZE (TYPE_MODE (TREE_TYPE (exp)));
3824
3825 link = TREE_VECTOR_CST_ELTS (exp);
3826 output_constant (TREE_VALUE (link), elt_size, align);
3827 while ((link = TREE_CHAIN (link)) != NULL)
3828 output_constant (TREE_VALUE (link), elt_size, nalign);
3829 }
3830 else
3831 abort ();
3832 break;
3833
3834 case RECORD_TYPE:
3835 case UNION_TYPE:
3836 if (TREE_CODE (exp) == CONSTRUCTOR)
3837 output_constructor (exp, size, align);
3838 else
3839 abort ();
3840 return;
3841
3842 case SET_TYPE:
3843 if (TREE_CODE (exp) == INTEGER_CST)
3844 assemble_integer (expand_expr (exp, NULL_RTX,
3845 VOIDmode, EXPAND_INITIALIZER),
3846 thissize, align, 1);
3847 else if (TREE_CODE (exp) == CONSTRUCTOR)
3848 {
3849 unsigned char *buffer = alloca (thissize);
3850 if (get_set_constructor_bytes (exp, buffer, thissize))
3851 abort ();
3852 assemble_string ((char *) buffer, thissize);
3853 }
3854 else
3855 error ("unknown set constructor type");
3856 return;
3857
3858 case ERROR_MARK:
3859 return;
3860
3861 default:
3862 abort ();
3863 }
3864
3865 if (size > thissize)
3866 assemble_zeros (size - thissize);
3867 }
3868
3869 \f
3870 /* Subroutine of output_constructor, used for computing the size of
3871 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3872 type with an unspecified upper bound. */
3873
3874 static unsigned HOST_WIDE_INT
3875 array_size_for_constructor (tree val)
3876 {
3877 tree max_index, i;
3878
3879 /* This code used to attempt to handle string constants that are not
3880 arrays of single-bytes, but nothing else does, so there's no point in
3881 doing it here. */
3882 if (TREE_CODE (val) == STRING_CST)
3883 return TREE_STRING_LENGTH (val);
3884
3885 max_index = NULL_TREE;
3886 for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i))
3887 {
3888 tree index = TREE_PURPOSE (i);
3889
3890 if (TREE_CODE (index) == RANGE_EXPR)
3891 index = TREE_OPERAND (index, 1);
3892 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
3893 max_index = index;
3894 }
3895
3896 if (max_index == NULL_TREE)
3897 return 0;
3898
3899 /* Compute the total number of array elements. */
3900 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
3901 convert (sizetype,
3902 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
3903 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
3904
3905 /* Multiply by the array element unit size to find number of bytes. */
3906 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
3907
3908 return tree_low_cst (i, 1);
3909 }
3910
3911 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3912 Generate at least SIZE bytes, padding if necessary. */
3913
3914 static void
3915 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
3916 unsigned int align)
3917 {
3918 tree type = TREE_TYPE (exp);
3919 tree link, field = 0;
3920 tree min_index = 0;
3921 /* Number of bytes output or skipped so far.
3922 In other words, current position within the constructor. */
3923 HOST_WIDE_INT total_bytes = 0;
3924 /* Nonzero means BYTE contains part of a byte, to be output. */
3925 int byte_buffer_in_use = 0;
3926 int byte = 0;
3927
3928 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3929 abort ();
3930
3931 if (TREE_CODE (type) == RECORD_TYPE)
3932 field = TYPE_FIELDS (type);
3933
3934 if (TREE_CODE (type) == ARRAY_TYPE
3935 && TYPE_DOMAIN (type) != 0)
3936 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
3937
3938 /* As LINK goes through the elements of the constant,
3939 FIELD goes through the structure fields, if the constant is a structure.
3940 if the constant is a union, then we override this,
3941 by getting the field from the TREE_LIST element.
3942 But the constant could also be an array. Then FIELD is zero.
3943
3944 There is always a maximum of one element in the chain LINK for unions
3945 (even if the initializer in a source program incorrectly contains
3946 more one). */
3947 for (link = CONSTRUCTOR_ELTS (exp);
3948 link;
3949 link = TREE_CHAIN (link),
3950 field = field ? TREE_CHAIN (field) : 0)
3951 {
3952 tree val = TREE_VALUE (link);
3953 tree index = 0;
3954
3955 /* The element in a union constructor specifies the proper field
3956 or index. */
3957 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
3958 || TREE_CODE (type) == QUAL_UNION_TYPE)
3959 && TREE_PURPOSE (link) != 0)
3960 field = TREE_PURPOSE (link);
3961
3962 else if (TREE_CODE (type) == ARRAY_TYPE)
3963 index = TREE_PURPOSE (link);
3964
3965 #ifdef ASM_COMMENT_START
3966 if (field && flag_verbose_asm)
3967 fprintf (asm_out_file, "%s %s:\n",
3968 ASM_COMMENT_START,
3969 DECL_NAME (field)
3970 ? IDENTIFIER_POINTER (DECL_NAME (field))
3971 : "<anonymous>");
3972 #endif
3973
3974 /* Eliminate the marker that makes a cast not be an lvalue. */
3975 if (val != 0)
3976 STRIP_NOPS (val);
3977
3978 if (index && TREE_CODE (index) == RANGE_EXPR)
3979 {
3980 unsigned HOST_WIDE_INT fieldsize
3981 = int_size_in_bytes (TREE_TYPE (type));
3982 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
3983 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
3984 HOST_WIDE_INT index;
3985 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
3986
3987 for (index = lo_index; index <= hi_index; index++)
3988 {
3989 /* Output the element's initial value. */
3990 if (val == 0)
3991 assemble_zeros (fieldsize);
3992 else
3993 output_constant (val, fieldsize, align2);
3994
3995 /* Count its size. */
3996 total_bytes += fieldsize;
3997 }
3998 }
3999 else if (field == 0 || !DECL_BIT_FIELD (field))
4000 {
4001 /* An element that is not a bit-field. */
4002
4003 unsigned HOST_WIDE_INT fieldsize;
4004 /* Since this structure is static,
4005 we know the positions are constant. */
4006 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4007 unsigned int align2;
4008
4009 if (index != 0)
4010 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4011 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4012
4013 /* Output any buffered-up bit-fields preceding this element. */
4014 if (byte_buffer_in_use)
4015 {
4016 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4017 total_bytes++;
4018 byte_buffer_in_use = 0;
4019 }
4020
4021 /* Advance to offset of this element.
4022 Note no alignment needed in an array, since that is guaranteed
4023 if each element has the proper size. */
4024 if ((field != 0 || index != 0) && pos != total_bytes)
4025 {
4026 assemble_zeros (pos - total_bytes);
4027 total_bytes = pos;
4028 }
4029
4030 /* Find the alignment of this element. */
4031 align2 = min_align (align, BITS_PER_UNIT * pos);
4032
4033 /* Determine size this element should occupy. */
4034 if (field)
4035 {
4036 fieldsize = 0;
4037
4038 /* If this is an array with an unspecified upper bound,
4039 the initializer determines the size. */
4040 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4041 but we cannot do this until the deprecated support for
4042 initializing zero-length array members is removed. */
4043 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4044 && TYPE_DOMAIN (TREE_TYPE (field))
4045 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4046 {
4047 fieldsize = array_size_for_constructor (val);
4048 /* Given a non-empty initialization, this field had
4049 better be last. */
4050 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4051 abort ();
4052 }
4053 else if (DECL_SIZE_UNIT (field))
4054 {
4055 /* ??? This can't be right. If the decl size overflows
4056 a host integer we will silently emit no data. */
4057 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4058 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4059 }
4060 }
4061 else
4062 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4063
4064 /* Output the element's initial value. */
4065 if (val == 0)
4066 assemble_zeros (fieldsize);
4067 else
4068 output_constant (val, fieldsize, align2);
4069
4070 /* Count its size. */
4071 total_bytes += fieldsize;
4072 }
4073 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4074 error ("invalid initial value for member `%s'",
4075 IDENTIFIER_POINTER (DECL_NAME (field)));
4076 else
4077 {
4078 /* Element that is a bit-field. */
4079
4080 HOST_WIDE_INT next_offset = int_bit_position (field);
4081 HOST_WIDE_INT end_offset
4082 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4083
4084 if (val == 0)
4085 val = integer_zero_node;
4086
4087 /* If this field does not start in this (or, next) byte,
4088 skip some bytes. */
4089 if (next_offset / BITS_PER_UNIT != total_bytes)
4090 {
4091 /* Output remnant of any bit field in previous bytes. */
4092 if (byte_buffer_in_use)
4093 {
4094 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4095 total_bytes++;
4096 byte_buffer_in_use = 0;
4097 }
4098
4099 /* If still not at proper byte, advance to there. */
4100 if (next_offset / BITS_PER_UNIT != total_bytes)
4101 {
4102 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4103 total_bytes = next_offset / BITS_PER_UNIT;
4104 }
4105 }
4106
4107 if (! byte_buffer_in_use)
4108 byte = 0;
4109
4110 /* We must split the element into pieces that fall within
4111 separate bytes, and combine each byte with previous or
4112 following bit-fields. */
4113
4114 /* next_offset is the offset n fbits from the beginning of
4115 the structure to the next bit of this element to be processed.
4116 end_offset is the offset of the first bit past the end of
4117 this element. */
4118 while (next_offset < end_offset)
4119 {
4120 int this_time;
4121 int shift;
4122 HOST_WIDE_INT value;
4123 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4124 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4125
4126 /* Advance from byte to byte
4127 within this element when necessary. */
4128 while (next_byte != total_bytes)
4129 {
4130 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4131 total_bytes++;
4132 byte = 0;
4133 }
4134
4135 /* Number of bits we can process at once
4136 (all part of the same byte). */
4137 this_time = MIN (end_offset - next_offset,
4138 BITS_PER_UNIT - next_bit);
4139 if (BYTES_BIG_ENDIAN)
4140 {
4141 /* On big-endian machine, take the most significant bits
4142 first (of the bits that are significant)
4143 and put them into bytes from the most significant end. */
4144 shift = end_offset - next_offset - this_time;
4145
4146 /* Don't try to take a bunch of bits that cross
4147 the word boundary in the INTEGER_CST. We can
4148 only select bits from the LOW or HIGH part
4149 not from both. */
4150 if (shift < HOST_BITS_PER_WIDE_INT
4151 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4152 {
4153 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4154 shift = HOST_BITS_PER_WIDE_INT;
4155 }
4156
4157 /* Now get the bits from the appropriate constant word. */
4158 if (shift < HOST_BITS_PER_WIDE_INT)
4159 value = TREE_INT_CST_LOW (val);
4160 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4161 {
4162 value = TREE_INT_CST_HIGH (val);
4163 shift -= HOST_BITS_PER_WIDE_INT;
4164 }
4165 else
4166 abort ();
4167
4168 /* Get the result. This works only when:
4169 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4170 byte |= (((value >> shift)
4171 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4172 << (BITS_PER_UNIT - this_time - next_bit));
4173 }
4174 else
4175 {
4176 /* On little-endian machines,
4177 take first the least significant bits of the value
4178 and pack them starting at the least significant
4179 bits of the bytes. */
4180 shift = next_offset - int_bit_position (field);
4181
4182 /* Don't try to take a bunch of bits that cross
4183 the word boundary in the INTEGER_CST. We can
4184 only select bits from the LOW or HIGH part
4185 not from both. */
4186 if (shift < HOST_BITS_PER_WIDE_INT
4187 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4188 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4189
4190 /* Now get the bits from the appropriate constant word. */
4191 if (shift < HOST_BITS_PER_WIDE_INT)
4192 value = TREE_INT_CST_LOW (val);
4193 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4194 {
4195 value = TREE_INT_CST_HIGH (val);
4196 shift -= HOST_BITS_PER_WIDE_INT;
4197 }
4198 else
4199 abort ();
4200
4201 /* Get the result. This works only when:
4202 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4203 byte |= (((value >> shift)
4204 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4205 << next_bit);
4206 }
4207
4208 next_offset += this_time;
4209 byte_buffer_in_use = 1;
4210 }
4211 }
4212 }
4213
4214 if (byte_buffer_in_use)
4215 {
4216 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4217 total_bytes++;
4218 }
4219
4220 if ((unsigned HOST_WIDE_INT)total_bytes < size)
4221 assemble_zeros (size - total_bytes);
4222 }
4223
4224 /* This TREE_LIST contains any weak symbol declarations waiting
4225 to be emitted. */
4226 static GTY(()) tree weak_decls;
4227
4228 /* Mark DECL as weak. */
4229
4230 static void
4231 mark_weak (tree decl)
4232 {
4233 DECL_WEAK (decl) = 1;
4234
4235 if (DECL_RTL_SET_P (decl)
4236 && GET_CODE (DECL_RTL (decl)) == MEM
4237 && XEXP (DECL_RTL (decl), 0)
4238 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4239 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4240 }
4241
4242 /* Merge weak status between NEWDECL and OLDDECL. */
4243
4244 void
4245 merge_weak (tree newdecl, tree olddecl)
4246 {
4247 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4248 return;
4249
4250 if (DECL_WEAK (newdecl))
4251 {
4252 tree wd;
4253
4254 /* NEWDECL is weak, but OLDDECL is not. */
4255
4256 /* If we already output the OLDDECL, we're in trouble; we can't
4257 go back and make it weak. This error cannot caught in
4258 declare_weak because the NEWDECL and OLDDECL was not yet
4259 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4260 if (TREE_ASM_WRITTEN (olddecl))
4261 error ("%Jweak declaration of '%D' must precede definition",
4262 newdecl, newdecl);
4263
4264 /* If we've already generated rtl referencing OLDDECL, we may
4265 have done so in a way that will not function properly with
4266 a weak symbol. */
4267 else if (TREE_USED (olddecl)
4268 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4269 warning ("%Jweak declaration of '%D' after first use results "
4270 "in unspecified behavior", newdecl, newdecl);
4271
4272 if (SUPPORTS_WEAK)
4273 {
4274 /* We put the NEWDECL on the weak_decls list at some point.
4275 Replace it with the OLDDECL. */
4276 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4277 if (TREE_VALUE (wd) == newdecl)
4278 {
4279 TREE_VALUE (wd) = olddecl;
4280 break;
4281 }
4282 /* We may not find the entry on the list. If NEWDECL is a
4283 weak alias, then we will have already called
4284 globalize_decl to remove the entry; in that case, we do
4285 not need to do anything. */
4286 }
4287
4288 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4289 mark_weak (olddecl);
4290 }
4291 else
4292 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4293 weak. Just update NEWDECL to indicate that it's weak too. */
4294 mark_weak (newdecl);
4295 }
4296
4297 /* Declare DECL to be a weak symbol. */
4298
4299 void
4300 declare_weak (tree decl)
4301 {
4302 if (! TREE_PUBLIC (decl))
4303 error ("%Jweak declaration of '%D' must be public", decl, decl);
4304 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4305 error ("%Jweak declaration of '%D' must precede definition", decl, decl);
4306 else if (SUPPORTS_WEAK)
4307 {
4308 if (! DECL_WEAK (decl))
4309 weak_decls = tree_cons (NULL, decl, weak_decls);
4310 }
4311 else
4312 warning ("%Jweak declaration of '%D' not supported", decl, decl);
4313
4314 mark_weak (decl);
4315 }
4316
4317 /* Emit any pending weak declarations. */
4318
4319 void
4320 weak_finish (void)
4321 {
4322 tree t;
4323
4324 for (t = weak_decls; t; t = TREE_CHAIN (t))
4325 {
4326 tree decl = TREE_VALUE (t);
4327 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4328 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4329 #endif
4330
4331 if (! TREE_USED (decl))
4332 continue;
4333
4334 #ifdef ASM_WEAKEN_DECL
4335 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4336 #else
4337 #ifdef ASM_WEAKEN_LABEL
4338 ASM_WEAKEN_LABEL (asm_out_file, name);
4339 #else
4340 #ifdef ASM_OUTPUT_WEAK_ALIAS
4341 warning ("only weak aliases are supported in this configuration");
4342 return;
4343 #endif
4344 #endif
4345 #endif
4346 }
4347 }
4348
4349 /* Emit the assembly bits to indicate that DECL is globally visible. */
4350
4351 static void
4352 globalize_decl (tree decl)
4353 {
4354 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4355
4356 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4357 if (DECL_WEAK (decl))
4358 {
4359 tree *p, t;
4360
4361 #ifdef ASM_WEAKEN_DECL
4362 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4363 #else
4364 ASM_WEAKEN_LABEL (asm_out_file, name);
4365 #endif
4366
4367 /* Remove this function from the pending weak list so that
4368 we do not emit multiple .weak directives for it. */
4369 for (p = &weak_decls; (t = *p) ; )
4370 {
4371 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4372 *p = TREE_CHAIN (t);
4373 else
4374 p = &TREE_CHAIN (t);
4375 }
4376 return;
4377 }
4378 #endif
4379
4380 (*targetm.asm_out.globalize_label) (asm_out_file, name);
4381 }
4382
4383 /* Emit an assembler directive to make the symbol for DECL an alias to
4384 the symbol for TARGET. */
4385
4386 void
4387 assemble_alias (tree decl, tree target ATTRIBUTE_UNUSED)
4388 {
4389 const char *name;
4390
4391 /* We must force creation of DECL_RTL for debug info generation, even though
4392 we don't use it here. */
4393 make_decl_rtl (decl, NULL);
4394
4395 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4396
4397 #ifdef ASM_OUTPUT_DEF
4398 /* Make name accessible from other files, if appropriate. */
4399
4400 if (TREE_PUBLIC (decl))
4401 {
4402 globalize_decl (decl);
4403 maybe_assemble_visibility (decl);
4404 }
4405
4406 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4407 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4408 #else
4409 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4410 #endif
4411 #else /* !ASM_OUTPUT_DEF */
4412 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4413 if (! DECL_WEAK (decl))
4414 warning ("only weak aliases are supported in this configuration");
4415
4416 #ifdef ASM_WEAKEN_DECL
4417 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4418 #else
4419 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4420 #endif
4421 #else
4422 warning ("alias definitions not supported in this configuration; ignored");
4423 #endif
4424 #endif
4425
4426 TREE_USED (decl) = 1;
4427 TREE_ASM_WRITTEN (decl) = 1;
4428 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4429 }
4430
4431 /* Emit an assembler directive to set symbol for DECL visibility to
4432 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4433
4434 void
4435 default_assemble_visibility (tree decl, int vis)
4436 {
4437 static const char * const visibility_types[] = {
4438 NULL, "internal", "hidden", "protected"
4439 };
4440
4441 const char *name, *type;
4442
4443 name = (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4444 type = visibility_types[vis];
4445
4446 #ifdef HAVE_GAS_HIDDEN
4447 fprintf (asm_out_file, "\t.%s\t", type);
4448 assemble_name (asm_out_file, name);
4449 fprintf (asm_out_file, "\n");
4450 #else
4451 warning ("visibility attribute not supported in this configuration; ignored");
4452 #endif
4453 }
4454
4455 /* A helper function to call assemble_visibility when needed for a decl. */
4456
4457 static void
4458 maybe_assemble_visibility (tree decl)
4459 {
4460 enum symbol_visibility vis = DECL_VISIBILITY (decl);
4461
4462 if (vis != VISIBILITY_DEFAULT)
4463 (* targetm.asm_out.visibility) (decl, vis);
4464 }
4465
4466 /* Returns 1 if the target configuration supports defining public symbols
4467 so that one of them will be chosen at link time instead of generating a
4468 multiply-defined symbol error, whether through the use of weak symbols or
4469 a target-specific mechanism for having duplicates discarded. */
4470
4471 int
4472 supports_one_only (void)
4473 {
4474 if (SUPPORTS_ONE_ONLY)
4475 return 1;
4476 return SUPPORTS_WEAK;
4477 }
4478
4479 /* Set up DECL as a public symbol that can be defined in multiple
4480 translation units without generating a linker error. */
4481
4482 void
4483 make_decl_one_only (tree decl)
4484 {
4485 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4486 abort ();
4487
4488 TREE_PUBLIC (decl) = 1;
4489
4490 if (TREE_CODE (decl) == VAR_DECL
4491 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4492 DECL_COMMON (decl) = 1;
4493 else if (SUPPORTS_ONE_ONLY)
4494 {
4495 #ifdef MAKE_DECL_ONE_ONLY
4496 MAKE_DECL_ONE_ONLY (decl);
4497 #endif
4498 DECL_ONE_ONLY (decl) = 1;
4499 }
4500 else if (SUPPORTS_WEAK)
4501 DECL_WEAK (decl) = 1;
4502 else
4503 abort ();
4504 }
4505
4506 void
4507 init_varasm_once (void)
4508 {
4509 in_named_htab = htab_create_ggc (31, in_named_entry_hash,
4510 in_named_entry_eq, NULL);
4511 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
4512 const_desc_eq, NULL);
4513
4514 const_alias_set = new_alias_set ();
4515 }
4516
4517 enum tls_model
4518 decl_tls_model (tree decl)
4519 {
4520 enum tls_model kind;
4521 tree attr = lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl));
4522 bool is_local;
4523
4524 if (attr)
4525 {
4526 attr = TREE_VALUE (TREE_VALUE (attr));
4527 if (TREE_CODE (attr) != STRING_CST)
4528 abort ();
4529 if (!strcmp (TREE_STRING_POINTER (attr), "local-exec"))
4530 kind = TLS_MODEL_LOCAL_EXEC;
4531 else if (!strcmp (TREE_STRING_POINTER (attr), "initial-exec"))
4532 kind = TLS_MODEL_INITIAL_EXEC;
4533 else if (!strcmp (TREE_STRING_POINTER (attr), "local-dynamic"))
4534 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
4535 else if (!strcmp (TREE_STRING_POINTER (attr), "global-dynamic"))
4536 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4537 else
4538 abort ();
4539 return kind;
4540 }
4541
4542 is_local = (*targetm.binds_local_p) (decl);
4543 if (!flag_pic)
4544 {
4545 if (is_local)
4546 kind = TLS_MODEL_LOCAL_EXEC;
4547 else
4548 kind = TLS_MODEL_INITIAL_EXEC;
4549 }
4550 /* Local dynamic is inefficient when we're not combining the
4551 parts of the address. */
4552 else if (optimize && is_local)
4553 kind = TLS_MODEL_LOCAL_DYNAMIC;
4554 else
4555 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4556 if (kind < flag_tls_default)
4557 kind = flag_tls_default;
4558
4559 return kind;
4560 }
4561
4562 /* Select a set of attributes for section NAME based on the properties
4563 of DECL and whether or not RELOC indicates that DECL's initializer
4564 might contain runtime relocations.
4565
4566 We make the section read-only and executable for a function decl,
4567 read-only for a const data decl, and writable for a non-const data decl. */
4568
4569 unsigned int
4570 default_section_type_flags (tree decl, const char *name, int reloc)
4571 {
4572 return default_section_type_flags_1 (decl, name, reloc, flag_pic);
4573 }
4574
4575 unsigned int
4576 default_section_type_flags_1 (tree decl, const char *name, int reloc,
4577 int shlib)
4578 {
4579 unsigned int flags;
4580
4581 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4582 flags = SECTION_CODE;
4583 else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
4584 flags = 0;
4585 else
4586 flags = SECTION_WRITE;
4587
4588 if (decl && DECL_ONE_ONLY (decl))
4589 flags |= SECTION_LINKONCE;
4590
4591 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4592 flags |= SECTION_TLS | SECTION_WRITE;
4593
4594 if (strcmp (name, ".bss") == 0
4595 || strncmp (name, ".bss.", 5) == 0
4596 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
4597 || strcmp (name, ".sbss") == 0
4598 || strncmp (name, ".sbss.", 6) == 0
4599 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0
4600 || strcmp (name, ".tbss") == 0
4601 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4602 flags |= SECTION_BSS;
4603
4604 if (strcmp (name, ".tdata") == 0
4605 || strcmp (name, ".tbss") == 0
4606 || strncmp (name, ".gnu.linkonce.td.", 17) == 0
4607 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4608 flags |= SECTION_TLS;
4609
4610 /* These three sections have special ELF types. They are neither
4611 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4612 want to print a section type (@progbits or @nobits). If someone
4613 is silly enough to emit code or TLS variables to one of these
4614 sections, then don't handle them specially. */
4615 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
4616 && (strcmp (name, ".init_array") == 0
4617 || strcmp (name, ".fini_array") == 0
4618 || strcmp (name, ".preinit_array") == 0))
4619 flags |= SECTION_NOTYPE;
4620
4621 return flags;
4622 }
4623
4624 /* Output assembly to switch to section NAME with attribute FLAGS.
4625 Four variants for common object file formats. */
4626
4627 void
4628 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
4629 unsigned int flags ATTRIBUTE_UNUSED)
4630 {
4631 /* Some object formats don't support named sections at all. The
4632 front-end should already have flagged this as an error. */
4633 abort ();
4634 }
4635
4636 void
4637 default_elf_asm_named_section (const char *name, unsigned int flags)
4638 {
4639 char flagchars[10], *f = flagchars;
4640
4641 if (! named_section_first_declaration (name))
4642 {
4643 fprintf (asm_out_file, "\t.section\t%s\n", name);
4644 return;
4645 }
4646
4647 if (!(flags & SECTION_DEBUG))
4648 *f++ = 'a';
4649 if (flags & SECTION_WRITE)
4650 *f++ = 'w';
4651 if (flags & SECTION_CODE)
4652 *f++ = 'x';
4653 if (flags & SECTION_SMALL)
4654 *f++ = 's';
4655 if (flags & SECTION_MERGE)
4656 *f++ = 'M';
4657 if (flags & SECTION_STRINGS)
4658 *f++ = 'S';
4659 if (flags & SECTION_TLS)
4660 *f++ = 'T';
4661 *f = '\0';
4662
4663 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
4664
4665 if (!(flags & SECTION_NOTYPE))
4666 {
4667 const char *type;
4668
4669 if (flags & SECTION_BSS)
4670 type = "nobits";
4671 else
4672 type = "progbits";
4673
4674 fprintf (asm_out_file, ",@%s", type);
4675
4676 if (flags & SECTION_ENTSIZE)
4677 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
4678 }
4679
4680 putc ('\n', asm_out_file);
4681 }
4682
4683 void
4684 default_coff_asm_named_section (const char *name, unsigned int flags)
4685 {
4686 char flagchars[8], *f = flagchars;
4687
4688 if (flags & SECTION_WRITE)
4689 *f++ = 'w';
4690 if (flags & SECTION_CODE)
4691 *f++ = 'x';
4692 *f = '\0';
4693
4694 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
4695 }
4696
4697 void
4698 default_pe_asm_named_section (const char *name, unsigned int flags)
4699 {
4700 default_coff_asm_named_section (name, flags);
4701
4702 if (flags & SECTION_LINKONCE)
4703 {
4704 /* Functions may have been compiled at various levels of
4705 optimization so we can't use `same_size' here.
4706 Instead, have the linker pick one. */
4707 fprintf (asm_out_file, "\t.linkonce %s\n",
4708 (flags & SECTION_CODE ? "discard" : "same_size"));
4709 }
4710 }
4711 \f
4712 /* The lame default section selector. */
4713
4714 void
4715 default_select_section (tree decl, int reloc,
4716 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4717 {
4718 bool readonly = false;
4719
4720 if (DECL_P (decl))
4721 {
4722 if (decl_readonly_section (decl, reloc))
4723 readonly = true;
4724 }
4725 else if (TREE_CODE (decl) == CONSTRUCTOR)
4726 {
4727 if (! ((flag_pic && reloc)
4728 || !TREE_READONLY (decl)
4729 || TREE_SIDE_EFFECTS (decl)
4730 || !TREE_CONSTANT (decl)))
4731 readonly = true;
4732 }
4733 else if (TREE_CODE (decl) == STRING_CST)
4734 readonly = !flag_writable_strings;
4735 else if (! (flag_pic && reloc))
4736 readonly = true;
4737
4738 if (readonly)
4739 readonly_data_section ();
4740 else
4741 data_section ();
4742 }
4743
4744 /* A helper function for default_elf_select_section and
4745 default_elf_unique_section. Categorizes the DECL. */
4746
4747 enum section_category
4748 {
4749 SECCAT_TEXT,
4750
4751 SECCAT_RODATA,
4752 SECCAT_RODATA_MERGE_STR,
4753 SECCAT_RODATA_MERGE_STR_INIT,
4754 SECCAT_RODATA_MERGE_CONST,
4755 SECCAT_SRODATA,
4756
4757 SECCAT_DATA,
4758
4759 /* To optimize loading of shared programs, define following subsections
4760 of data section:
4761 _REL Contains data that has relocations, so they get grouped
4762 together and dynamic linker will visit fewer pages in memory.
4763 _RO Contains data that is otherwise read-only. This is useful
4764 with prelinking as most relocations won't be dynamically
4765 linked and thus stay read only.
4766 _LOCAL Marks data containing relocations only to local objects.
4767 These relocations will get fully resolved by prelinking. */
4768 SECCAT_DATA_REL,
4769 SECCAT_DATA_REL_LOCAL,
4770 SECCAT_DATA_REL_RO,
4771 SECCAT_DATA_REL_RO_LOCAL,
4772
4773 SECCAT_SDATA,
4774 SECCAT_TDATA,
4775
4776 SECCAT_BSS,
4777 SECCAT_SBSS,
4778 SECCAT_TBSS
4779 };
4780
4781 static enum section_category
4782 categorize_decl_for_section (tree, int, int);
4783
4784 static enum section_category
4785 categorize_decl_for_section (tree decl, int reloc, int shlib)
4786 {
4787 enum section_category ret;
4788
4789 if (TREE_CODE (decl) == FUNCTION_DECL)
4790 return SECCAT_TEXT;
4791 else if (TREE_CODE (decl) == STRING_CST)
4792 {
4793 if (flag_writable_strings)
4794 return SECCAT_DATA;
4795 else
4796 return SECCAT_RODATA_MERGE_STR;
4797 }
4798 else if (TREE_CODE (decl) == VAR_DECL)
4799 {
4800 if (DECL_INITIAL (decl) == NULL
4801 || DECL_INITIAL (decl) == error_mark_node)
4802 ret = SECCAT_BSS;
4803 else if (! TREE_READONLY (decl)
4804 || TREE_SIDE_EFFECTS (decl)
4805 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
4806 {
4807 if (shlib && (reloc & 2))
4808 ret = SECCAT_DATA_REL;
4809 else if (shlib && reloc)
4810 ret = SECCAT_DATA_REL_LOCAL;
4811 else
4812 ret = SECCAT_DATA;
4813 }
4814 else if (shlib && (reloc & 2))
4815 ret = SECCAT_DATA_REL_RO;
4816 else if (shlib && reloc)
4817 ret = SECCAT_DATA_REL_RO_LOCAL;
4818 else if (reloc || flag_merge_constants < 2)
4819 /* C and C++ don't allow different variables to share the same
4820 location. -fmerge-all-constants allows even that (at the
4821 expense of not conforming). */
4822 ret = SECCAT_RODATA;
4823 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
4824 ret = SECCAT_RODATA_MERGE_STR_INIT;
4825 else
4826 ret = SECCAT_RODATA_MERGE_CONST;
4827 }
4828 else if (TREE_CODE (decl) == CONSTRUCTOR)
4829 {
4830 if ((shlib && reloc)
4831 || TREE_SIDE_EFFECTS (decl)
4832 || ! TREE_CONSTANT (decl))
4833 ret = SECCAT_DATA;
4834 else
4835 ret = SECCAT_RODATA;
4836 }
4837 else
4838 ret = SECCAT_RODATA;
4839
4840 /* There are no read-only thread-local sections. */
4841 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4842 {
4843 if (ret == SECCAT_BSS)
4844 ret = SECCAT_TBSS;
4845 else
4846 ret = SECCAT_TDATA;
4847 }
4848
4849 /* If the target uses small data sections, select it. */
4850 else if ((*targetm.in_small_data_p) (decl))
4851 {
4852 if (ret == SECCAT_BSS)
4853 ret = SECCAT_SBSS;
4854 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
4855 ret = SECCAT_SRODATA;
4856 else
4857 ret = SECCAT_SDATA;
4858 }
4859
4860 return ret;
4861 }
4862
4863 bool
4864 decl_readonly_section (tree decl, int reloc)
4865 {
4866 return decl_readonly_section_1 (decl, reloc, flag_pic);
4867 }
4868
4869 bool
4870 decl_readonly_section_1 (tree decl, int reloc, int shlib)
4871 {
4872 switch (categorize_decl_for_section (decl, reloc, shlib))
4873 {
4874 case SECCAT_RODATA:
4875 case SECCAT_RODATA_MERGE_STR:
4876 case SECCAT_RODATA_MERGE_STR_INIT:
4877 case SECCAT_RODATA_MERGE_CONST:
4878 case SECCAT_SRODATA:
4879 return true;
4880 break;
4881 default:
4882 return false;
4883 break;
4884 }
4885 }
4886
4887 /* Select a section based on the above categorization. */
4888
4889 void
4890 default_elf_select_section (tree decl, int reloc,
4891 unsigned HOST_WIDE_INT align)
4892 {
4893 default_elf_select_section_1 (decl, reloc, align, flag_pic);
4894 }
4895
4896 void
4897 default_elf_select_section_1 (tree decl, int reloc,
4898 unsigned HOST_WIDE_INT align, int shlib)
4899 {
4900 switch (categorize_decl_for_section (decl, reloc, shlib))
4901 {
4902 case SECCAT_TEXT:
4903 /* We're not supposed to be called on FUNCTION_DECLs. */
4904 abort ();
4905 case SECCAT_RODATA:
4906 readonly_data_section ();
4907 break;
4908 case SECCAT_RODATA_MERGE_STR:
4909 mergeable_string_section (decl, align, 0);
4910 break;
4911 case SECCAT_RODATA_MERGE_STR_INIT:
4912 mergeable_string_section (DECL_INITIAL (decl), align, 0);
4913 break;
4914 case SECCAT_RODATA_MERGE_CONST:
4915 mergeable_constant_section (DECL_MODE (decl), align, 0);
4916 break;
4917 case SECCAT_SRODATA:
4918 named_section (NULL_TREE, ".sdata2", reloc);
4919 break;
4920 case SECCAT_DATA:
4921 data_section ();
4922 break;
4923 case SECCAT_DATA_REL:
4924 named_section (NULL_TREE, ".data.rel", reloc);
4925 break;
4926 case SECCAT_DATA_REL_LOCAL:
4927 named_section (NULL_TREE, ".data.rel.local", reloc);
4928 break;
4929 case SECCAT_DATA_REL_RO:
4930 named_section (NULL_TREE, ".data.rel.ro", reloc);
4931 break;
4932 case SECCAT_DATA_REL_RO_LOCAL:
4933 named_section (NULL_TREE, ".data.rel.ro.local", reloc);
4934 break;
4935 case SECCAT_SDATA:
4936 named_section (NULL_TREE, ".sdata", reloc);
4937 break;
4938 case SECCAT_TDATA:
4939 named_section (NULL_TREE, ".tdata", reloc);
4940 break;
4941 case SECCAT_BSS:
4942 #ifdef BSS_SECTION_ASM_OP
4943 bss_section ();
4944 #else
4945 named_section (NULL_TREE, ".bss", reloc);
4946 #endif
4947 break;
4948 case SECCAT_SBSS:
4949 named_section (NULL_TREE, ".sbss", reloc);
4950 break;
4951 case SECCAT_TBSS:
4952 named_section (NULL_TREE, ".tbss", reloc);
4953 break;
4954 default:
4955 abort ();
4956 }
4957 }
4958
4959 /* Construct a unique section name based on the decl name and the
4960 categorization performed above. */
4961
4962 void
4963 default_unique_section (tree decl, int reloc)
4964 {
4965 default_unique_section_1 (decl, reloc, flag_pic);
4966 }
4967
4968 void
4969 default_unique_section_1 (tree decl, int reloc, int shlib)
4970 {
4971 bool one_only = DECL_ONE_ONLY (decl);
4972 const char *prefix, *name;
4973 size_t nlen, plen;
4974 char *string;
4975
4976 switch (categorize_decl_for_section (decl, reloc, shlib))
4977 {
4978 case SECCAT_TEXT:
4979 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
4980 break;
4981 case SECCAT_RODATA:
4982 case SECCAT_RODATA_MERGE_STR:
4983 case SECCAT_RODATA_MERGE_STR_INIT:
4984 case SECCAT_RODATA_MERGE_CONST:
4985 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
4986 break;
4987 case SECCAT_SRODATA:
4988 prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
4989 break;
4990 case SECCAT_DATA:
4991 case SECCAT_DATA_REL:
4992 case SECCAT_DATA_REL_LOCAL:
4993 case SECCAT_DATA_REL_RO:
4994 case SECCAT_DATA_REL_RO_LOCAL:
4995 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
4996 break;
4997 case SECCAT_SDATA:
4998 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
4999 break;
5000 case SECCAT_BSS:
5001 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
5002 break;
5003 case SECCAT_SBSS:
5004 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
5005 break;
5006 case SECCAT_TDATA:
5007 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
5008 break;
5009 case SECCAT_TBSS:
5010 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
5011 break;
5012 default:
5013 abort ();
5014 }
5015 plen = strlen (prefix);
5016
5017 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5018 name = (* targetm.strip_name_encoding) (name);
5019 nlen = strlen (name);
5020
5021 string = alloca (nlen + plen + 1);
5022 memcpy (string, prefix, plen);
5023 memcpy (string + plen, name, nlen + 1);
5024
5025 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
5026 }
5027
5028 void
5029 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
5030 rtx x,
5031 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5032 {
5033 if (flag_pic)
5034 switch (GET_CODE (x))
5035 {
5036 case CONST:
5037 case SYMBOL_REF:
5038 case LABEL_REF:
5039 data_section ();
5040 return;
5041
5042 default:
5043 break;
5044 }
5045
5046 readonly_data_section ();
5047 }
5048
5049 void
5050 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
5051 unsigned HOST_WIDE_INT align)
5052 {
5053 /* ??? Handle small data here somehow. */
5054
5055 if (flag_pic)
5056 switch (GET_CODE (x))
5057 {
5058 case CONST:
5059 case SYMBOL_REF:
5060 named_section (NULL_TREE, ".data.rel.ro", 3);
5061 return;
5062
5063 case LABEL_REF:
5064 named_section (NULL_TREE, ".data.rel.ro.local", 1);
5065 return;
5066
5067 default:
5068 break;
5069 }
5070
5071 mergeable_constant_section (mode, align, 0);
5072 }
5073
5074 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5075
5076 void
5077 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
5078 {
5079 rtx symbol;
5080 int flags;
5081
5082 /* Careful not to prod global register variables. */
5083 if (GET_CODE (rtl) != MEM)
5084 return;
5085 symbol = XEXP (rtl, 0);
5086 if (GET_CODE (symbol) != SYMBOL_REF)
5087 return;
5088
5089 flags = 0;
5090 if (TREE_CODE (decl) == FUNCTION_DECL)
5091 flags |= SYMBOL_FLAG_FUNCTION;
5092 if ((*targetm.binds_local_p) (decl))
5093 flags |= SYMBOL_FLAG_LOCAL;
5094 if ((*targetm.in_small_data_p) (decl))
5095 flags |= SYMBOL_FLAG_SMALL;
5096 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
5097 flags |= decl_tls_model (decl) << SYMBOL_FLAG_TLS_SHIFT;
5098 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5099 being PUBLIC, the thing *must* be defined in this translation unit.
5100 Prevent this buglet from being propagated into rtl code as well. */
5101 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
5102 flags |= SYMBOL_FLAG_EXTERNAL;
5103
5104 SYMBOL_REF_FLAGS (symbol) = flags;
5105 }
5106
5107 /* By default, we do nothing for encode_section_info, so we need not
5108 do anything but discard the '*' marker. */
5109
5110 const char *
5111 default_strip_name_encoding (const char *str)
5112 {
5113 return str + (*str == '*');
5114 }
5115
5116 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5117 wrt cross-module name binding. */
5118
5119 bool
5120 default_binds_local_p (tree exp)
5121 {
5122 return default_binds_local_p_1 (exp, flag_shlib);
5123 }
5124
5125 bool
5126 default_binds_local_p_1 (tree exp, int shlib)
5127 {
5128 bool local_p;
5129
5130 /* A non-decl is an entry in the constant pool. */
5131 if (!DECL_P (exp))
5132 local_p = true;
5133 /* Static variables are always local. */
5134 else if (! TREE_PUBLIC (exp))
5135 local_p = true;
5136 /* A variable is local if the user tells us so. */
5137 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5138 local_p = true;
5139 /* Otherwise, variables defined outside this object may not be local. */
5140 else if (DECL_EXTERNAL (exp))
5141 local_p = false;
5142 /* Linkonce and weak data are never local. */
5143 else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
5144 local_p = false;
5145 /* If PIC, then assume that any global name can be overridden by
5146 symbols resolved from other modules. */
5147 else if (shlib)
5148 local_p = false;
5149 /* Uninitialized COMMON variable may be unified with symbols
5150 resolved from other modules. */
5151 else if (DECL_COMMON (exp)
5152 && (DECL_INITIAL (exp) == NULL
5153 || DECL_INITIAL (exp) == error_mark_node))
5154 local_p = false;
5155 /* Otherwise we're left with initialized (or non-common) global data
5156 which is of necessity defined locally. */
5157 else
5158 local_p = true;
5159
5160 return local_p;
5161 }
5162
5163 /* Determine whether or not a pointer mode is valid. Assume defaults
5164 of ptr_mode or Pmode - can be overridden. */
5165 bool
5166 default_valid_pointer_mode (enum machine_mode mode)
5167 {
5168 return (mode == ptr_mode || mode == Pmode);
5169 }
5170
5171 /* Default function to output code that will globalize a label. A
5172 target must define GLOBAL_ASM_OP or provide it's own function to
5173 globalize a label. */
5174 #ifdef GLOBAL_ASM_OP
5175 void
5176 default_globalize_label (FILE * stream, const char *name)
5177 {
5178 fputs (GLOBAL_ASM_OP, stream);
5179 assemble_name (stream, name);
5180 putc ('\n', stream);
5181 }
5182 #endif /* GLOBAL_ASM_OP */
5183
5184 /* This is how to output an internal numbered label where PREFIX is
5185 the class of label and LABELNO is the number within the class. */
5186
5187 void
5188 default_internal_label (FILE *stream, const char *prefix,
5189 unsigned long labelno)
5190 {
5191 char *const buf = alloca (40 + strlen (prefix));
5192 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
5193 ASM_OUTPUT_LABEL (stream, buf);
5194 }
5195
5196 /* This is the default behavior at the beginning of a file. It's
5197 controlled by two other target-hook toggles. */
5198 void
5199 default_file_start (void)
5200 {
5201 if (targetm.file_start_app_off && !flag_verbose_asm)
5202 fputs (ASM_APP_OFF, asm_out_file);
5203
5204 if (targetm.file_start_file_directive)
5205 output_file_directive (asm_out_file, main_input_filename);
5206 }
5207
5208 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5209 which emits a special section directive used to indicate whether or
5210 not this object file needs an executable stack. This is primarily
5211 a GNU extension to ELF but could be used on other targets. */
5212 void
5213 file_end_indicate_exec_stack (void)
5214 {
5215 unsigned int flags = SECTION_DEBUG;
5216 if (trampolines_created)
5217 flags |= SECTION_CODE;
5218
5219 named_section_flags (".note.GNU-stack", flags);
5220 }
5221
5222 #include "gt-varasm.h"