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