Line data Source code
1 : /* Output variables, constants and external declarations, for GNU compiler.
2 : Copyright (C) 1987-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify it under
7 : the terms of the GNU General Public License as published by the Free
8 : Software Foundation; either version 3, or (at your option) any later
9 : version.
10 :
11 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 :
21 : /* This file handles generation of all the assembler code
22 : *except* the instructions of a function.
23 : This includes declarations of variables and their initial values.
24 :
25 : We also output the assembler code for constants stored in memory
26 : and are responsible for combining constants with the same value. */
27 :
28 : #include "config.h"
29 : #include "system.h"
30 : #include "coretypes.h"
31 : #include "backend.h"
32 : #include "target.h"
33 : #include "rtl.h"
34 : #include "tree.h"
35 : #include "predict.h"
36 : #include "memmodel.h"
37 : #include "tm_p.h"
38 : #include "stringpool.h"
39 : #include "regs.h"
40 : #include "emit-rtl.h"
41 : #include "cgraph.h"
42 : #include "diagnostic-core.h"
43 : #include "fold-const.h"
44 : #include "stor-layout.h"
45 : #include "varasm.h"
46 : #include "version.h"
47 : #include "flags.h"
48 : #include "stmt.h"
49 : #include "expr.h"
50 : #include "expmed.h"
51 : #include "optabs.h"
52 : #include "output.h"
53 : #include "langhooks.h"
54 : #include "debug.h"
55 : #include "common/common-target.h"
56 : #include "attribs.h"
57 : #include "asan.h"
58 : #include "rtl-iter.h"
59 : #include "file-prefix-map.h" /* remap_debug_filename() */
60 : #include "alloc-pool.h"
61 : #include "toplev.h"
62 : #include "opts.h"
63 : #include "recog.h"
64 : #include "gimple-expr.h"
65 :
66 : /* The (assembler) name of the first globally-visible object output. */
67 : extern GTY(()) const char *first_global_object_name;
68 : extern GTY(()) const char *weak_global_object_name;
69 :
70 : const char *first_global_object_name;
71 : const char *weak_global_object_name;
72 :
73 : class addr_const;
74 : class constant_descriptor_rtx;
75 : struct rtx_constant_pool;
76 :
77 : #define n_deferred_constants (crtl->varasm.deferred_constants)
78 :
79 : /* Number for making the label on the next
80 : constant that is stored in memory. */
81 :
82 : static GTY(()) int const_labelno;
83 :
84 : /* Carry information from ASM_DECLARE_OBJECT_NAME
85 : to ASM_FINISH_DECLARE_OBJECT. */
86 :
87 : int size_directive_output;
88 :
89 : /* The last decl for which assemble_variable was called,
90 : if it did ASM_DECLARE_OBJECT_NAME.
91 : If the last call to assemble_variable didn't do that,
92 : this holds 0. */
93 :
94 : tree last_assemble_variable_decl;
95 :
96 : /* The following global variable indicates if the first basic block
97 : in a function belongs to the cold partition or not. */
98 :
99 : bool first_function_block_is_cold;
100 :
101 : /* Whether we saw any functions with no_split_stack. */
102 :
103 : static bool saw_no_split_stack;
104 :
105 : static const char *strip_reg_name (const char *);
106 : static bool contains_pointers_p (tree);
107 : #ifdef ASM_OUTPUT_EXTERNAL
108 : static bool incorporeal_function_p (tree);
109 : #endif
110 : static void decode_addr_const (tree, class addr_const *);
111 : static hashval_t const_hash_1 (const tree);
112 : static bool compare_constant (const tree, const tree);
113 : static void output_constant_def_contents (rtx);
114 : static void output_addressed_constants (tree, int);
115 : static unsigned HOST_WIDE_INT output_constant (tree, unsigned HOST_WIDE_INT,
116 : unsigned int, bool, bool);
117 : static void globalize_decl (tree);
118 : static bool decl_readonly_section_1 (enum section_category);
119 : #ifdef BSS_SECTION_ASM_OP
120 : #ifdef ASM_OUTPUT_ALIGNED_BSS
121 : static void asm_output_aligned_bss (FILE *, tree, const char *,
122 : unsigned HOST_WIDE_INT, int)
123 : ATTRIBUTE_UNUSED;
124 : #endif
125 : #endif /* BSS_SECTION_ASM_OP */
126 : static void mark_weak (tree);
127 : static void output_constant_pool (const char *, tree);
128 : static void handle_vtv_comdat_section (section *, const_tree);
129 :
130 : /* Well-known sections, each one associated with some sort of *_ASM_OP. */
131 : section *text_section;
132 : section *data_section;
133 : section *readonly_data_section;
134 : section *sdata_section;
135 : section *ctors_section;
136 : section *dtors_section;
137 : section *bss_section;
138 : section *sbss_section;
139 :
140 : /* Various forms of common section. All are guaranteed to be nonnull. */
141 : section *tls_comm_section;
142 : section *comm_section;
143 : section *lcomm_section;
144 :
145 : /* A SECTION_NOSWITCH section used for declaring global BSS variables.
146 : May be null. */
147 : section *bss_noswitch_section;
148 :
149 : /* The section that holds the main exception table, when known. The section
150 : is set either by the target's init_sections hook or by the first call to
151 : switch_to_exception_section. */
152 : section *exception_section;
153 :
154 : /* The section that holds the DWARF2 frame unwind information, when known.
155 : The section is set either by the target's init_sections hook or by the
156 : first call to switch_to_eh_frame_section. */
157 : section *eh_frame_section;
158 :
159 : /* asm_out_file's current section. This is NULL if no section has yet
160 : been selected or if we lose track of what the current section is. */
161 : section *in_section;
162 :
163 : /* True if code for the current function is currently being directed
164 : at the cold section. */
165 : bool in_cold_section_p;
166 :
167 : /* The following global holds the "function name" for the code in the
168 : cold section of a function, if hot/cold function splitting is enabled
169 : and there was actually code that went into the cold section. A
170 : pseudo function name is needed for the cold section of code for some
171 : debugging tools that perform symbolization. */
172 : tree cold_function_name = NULL_TREE;
173 :
174 : /* A linked list of all the unnamed sections. */
175 : static GTY(()) section *unnamed_sections;
176 :
177 : /* Return a nonzero value if DECL has a section attribute. */
178 : #define IN_NAMED_SECTION(DECL) \
179 : (VAR_OR_FUNCTION_DECL_P (DECL) && DECL_SECTION_NAME (DECL) != NULL)
180 :
181 : struct section_hasher : ggc_ptr_hash<section>
182 : {
183 : typedef const char *compare_type;
184 :
185 : static hashval_t hash (section *);
186 : static bool equal (section *, const char *);
187 : };
188 :
189 : /* Hash table of named sections. */
190 : static GTY(()) hash_table<section_hasher> *section_htab;
191 :
192 : struct object_block_hasher : ggc_ptr_hash<object_block>
193 : {
194 : typedef const section *compare_type;
195 :
196 : static hashval_t hash (object_block *);
197 : static bool equal (object_block *, const section *);
198 : };
199 :
200 : /* A table of object_blocks, indexed by section. */
201 : static GTY(()) hash_table<object_block_hasher> *object_block_htab;
202 :
203 : /* The next number to use for internal anchor labels. */
204 : static GTY(()) int anchor_labelno;
205 :
206 : /* A pool of constants that can be shared between functions. */
207 : static GTY(()) struct rtx_constant_pool *shared_constant_pool;
208 :
209 : /* Helper routines for maintaining section_htab. */
210 :
211 : bool
212 478601120 : section_hasher::equal (section *old, const char *new_name)
213 : {
214 478601120 : return strcmp (old->named.name, new_name) == 0;
215 : }
216 :
217 : hashval_t
218 342318462 : section_hasher::hash (section *old)
219 : {
220 342318462 : return htab_hash_string (old->named.name);
221 : }
222 :
223 : /* Return a hash value for section SECT. */
224 :
225 : static hashval_t
226 0 : hash_section (section *sect)
227 : {
228 0 : if (sect->common.flags & SECTION_NAMED)
229 0 : return htab_hash_string (sect->named.name);
230 0 : return sect->common.flags & ~SECTION_DECLARED;
231 : }
232 :
233 : /* Helper routines for maintaining object_block_htab. */
234 :
235 : inline bool
236 0 : object_block_hasher::equal (object_block *old, const section *new_section)
237 : {
238 0 : return old->sect == new_section;
239 : }
240 :
241 : hashval_t
242 0 : object_block_hasher::hash (object_block *old)
243 : {
244 0 : return hash_section (old->sect);
245 : }
246 :
247 : /* Return a new unnamed section with the given fields. */
248 :
249 : section *
250 1158564 : get_unnamed_section (unsigned int flags, void (*callback) (const char *),
251 : const char *data)
252 : {
253 1158564 : section *sect;
254 :
255 1158564 : sect = ggc_alloc<section> ();
256 1158564 : sect->unnamed.common.flags = flags | SECTION_UNNAMED;
257 1158564 : sect->unnamed.callback = callback;
258 1158564 : sect->unnamed.data = data;
259 1158564 : sect->unnamed.next = unnamed_sections;
260 :
261 1158564 : unnamed_sections = sect;
262 1158564 : return sect;
263 : }
264 :
265 : /* Return a SECTION_NOSWITCH section with the given fields. */
266 :
267 : static section *
268 1158564 : get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
269 : {
270 1158564 : section *sect;
271 :
272 0 : sect = ggc_alloc<section> ();
273 1158564 : sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
274 1158564 : sect->noswitch.callback = callback;
275 :
276 1158564 : return sect;
277 : }
278 :
279 : /* Return the named section structure associated with NAME. Create
280 : a new section with the given fields if no such structure exists.
281 : When NOT_EXISTING, then fail if the section already exists. Return
282 : the existing section if the SECTION_RETAIN bit doesn't match. Set
283 : the SECTION_WRITE | SECTION_RELRO bits on the existing section
284 : if one of the section flags is SECTION_WRITE | SECTION_RELRO and the
285 : other has none of these flags in named sections and either the section
286 : hasn't been declared yet or has been declared as writable. */
287 :
288 : section *
289 73481956 : get_section (const char *name, unsigned int flags, tree decl,
290 : bool not_existing)
291 : {
292 73481956 : section *sect, **slot;
293 :
294 73481956 : slot = section_htab->find_slot_with_hash (name, htab_hash_string (name),
295 : INSERT);
296 73481956 : flags |= SECTION_NAMED;
297 73481956 : if (decl != nullptr
298 71444251 : && DECL_P (decl)
299 144926207 : && lookup_attribute ("retain", DECL_ATTRIBUTES (decl)))
300 458 : flags |= SECTION_RETAIN;
301 73481956 : if (*slot == NULL)
302 : {
303 3519601 : sect = ggc_alloc<section> ();
304 3519601 : sect->named.common.flags = flags;
305 3519601 : sect->named.name = ggc_strdup (name);
306 3519601 : sect->named.decl = decl;
307 3519601 : *slot = sect;
308 : }
309 : else
310 : {
311 69962355 : if (not_existing)
312 0 : internal_error ("section already exists: %qs", name);
313 :
314 69962355 : sect = *slot;
315 : /* It is fine if one of the sections has SECTION_NOTYPE as long as
316 : the other has none of the contrary flags (see the logic at the end
317 : of default_section_type_flags, below). */
318 69962355 : if (((sect->common.flags ^ flags) & SECTION_NOTYPE)
319 5 : && !((sect->common.flags | flags)
320 5 : & (SECTION_CODE | SECTION_BSS | SECTION_TLS | SECTION_ENTSIZE
321 : | (HAVE_COMDAT_GROUP ? SECTION_LINKONCE : 0))))
322 : {
323 3 : sect->common.flags |= SECTION_NOTYPE;
324 3 : flags |= SECTION_NOTYPE;
325 : }
326 69962355 : if ((sect->common.flags & ~SECTION_DECLARED) != flags
327 54 : && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
328 : {
329 : /* It is fine if one of the section flags is
330 : SECTION_WRITE | SECTION_RELRO and the other has none of these
331 : flags (i.e. read-only) in named sections and either the
332 : section hasn't been declared yet or has been declared as writable.
333 : In that case just make sure the resulting flags are
334 : SECTION_WRITE | SECTION_RELRO, ie. writable only because of
335 : relocations. */
336 50 : if (((sect->common.flags ^ flags) & (SECTION_WRITE | SECTION_RELRO))
337 : == (SECTION_WRITE | SECTION_RELRO)
338 8 : && (sect->common.flags
339 8 : & ~(SECTION_DECLARED | SECTION_WRITE | SECTION_RELRO))
340 8 : == (flags & ~(SECTION_WRITE | SECTION_RELRO))
341 8 : && ((sect->common.flags & SECTION_DECLARED) == 0
342 2 : || (sect->common.flags & SECTION_WRITE)))
343 : {
344 8 : sect->common.flags |= (SECTION_WRITE | SECTION_RELRO);
345 8 : return sect;
346 : }
347 : /* If the SECTION_RETAIN bit doesn't match, return and switch
348 : to a new section later. */
349 42 : if ((sect->common.flags & SECTION_RETAIN)
350 42 : != (flags & SECTION_RETAIN))
351 : return sect;
352 : /* Sanity check user variables for flag changes. */
353 2 : if (sect->named.decl != NULL
354 2 : && DECL_P (sect->named.decl)
355 2 : && decl != sect->named.decl)
356 : {
357 2 : if (decl != NULL && DECL_P (decl))
358 2 : error ("%+qD causes a section type conflict with %qD"
359 : " in section %qs",
360 : decl, sect->named.decl, name);
361 : else
362 0 : error ("section type conflict with %qD in section %qs",
363 : sect->named.decl, name);
364 2 : inform (DECL_SOURCE_LOCATION (sect->named.decl),
365 : "%qD was declared here", sect->named.decl);
366 : }
367 0 : else if (decl != NULL && DECL_P (decl))
368 0 : error ("%+qD causes a section type conflict for section %qs",
369 : decl, name);
370 : else
371 0 : error ("section type conflict for section %qs", name);
372 : /* Make sure we don't error about one section multiple times. */
373 2 : sect->common.flags |= SECTION_OVERRIDE;
374 : }
375 : }
376 : return sect;
377 : }
378 :
379 : /* Return true if the current compilation mode benefits from having
380 : objects grouped into blocks. */
381 :
382 : static bool
383 10393712 : use_object_blocks_p (void)
384 : {
385 10393712 : return flag_section_anchors;
386 : }
387 :
388 : /* Return the object_block structure for section SECT. Create a new
389 : structure if we haven't created one already. Return null if SECT
390 : itself is null. Return also null for mergeable sections since
391 : section anchors can't be used in mergeable sections anyway,
392 : because the linker might move objects around, and using the
393 : object blocks infrastructure in that case is both a waste and a
394 : maintenance burden. */
395 :
396 : static struct object_block *
397 0 : get_block_for_section (section *sect)
398 : {
399 0 : struct object_block *block;
400 :
401 0 : if (sect == NULL)
402 : return NULL;
403 :
404 0 : if (sect->common.flags & SECTION_MERGE)
405 : return NULL;
406 :
407 0 : object_block **slot
408 0 : = object_block_htab->find_slot_with_hash (sect, hash_section (sect),
409 : INSERT);
410 0 : block = *slot;
411 0 : if (block == NULL)
412 : {
413 0 : block = ggc_cleared_alloc<object_block> ();
414 0 : block->sect = sect;
415 0 : *slot = block;
416 : }
417 : return block;
418 : }
419 :
420 : /* Create a symbol with label LABEL and place it at byte offset
421 : OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
422 : is not yet known. LABEL must be a garbage-collected string. */
423 :
424 : static rtx
425 0 : create_block_symbol (const char *label, struct object_block *block,
426 : HOST_WIDE_INT offset)
427 : {
428 0 : rtx symbol;
429 0 : unsigned int size;
430 :
431 : /* Create the extended SYMBOL_REF. */
432 0 : size = RTX_HDR_SIZE + sizeof (struct block_symbol);
433 0 : symbol = (rtx) ggc_internal_alloc (size);
434 :
435 : /* Initialize the normal SYMBOL_REF fields. */
436 0 : memset (symbol, 0, size);
437 0 : PUT_CODE (symbol, SYMBOL_REF);
438 0 : PUT_MODE (symbol, Pmode);
439 0 : XSTR (symbol, 0) = label;
440 0 : SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
441 :
442 : /* Initialize the block_symbol stuff. */
443 0 : SYMBOL_REF_BLOCK (symbol) = block;
444 0 : SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
445 :
446 0 : return symbol;
447 : }
448 :
449 : /* Return a section with a particular name and with whatever SECTION_*
450 : flags section_type_flags deems appropriate. The name of the section
451 : is taken from NAME if nonnull, otherwise it is taken from DECL's
452 : DECL_SECTION_NAME. DECL is the decl associated with the section
453 : (see the section comment for details) and RELOC is as for
454 : section_type_flags. */
455 :
456 : section *
457 71263498 : get_named_section (tree decl, const char *name, int reloc)
458 : {
459 71263498 : unsigned int flags;
460 :
461 71263498 : if (name == NULL)
462 : {
463 63476371 : gcc_assert (decl && DECL_P (decl) && DECL_SECTION_NAME (decl));
464 63476371 : name = DECL_SECTION_NAME (decl);
465 : }
466 :
467 71263498 : flags = targetm.section_type_flags (decl, name, reloc);
468 71263498 : return get_section (name, flags, decl);
469 : }
470 :
471 : /* Worker for resolve_unique_section. */
472 :
473 : static bool
474 1863026 : set_implicit_section (struct symtab_node *n, void *data ATTRIBUTE_UNUSED)
475 : {
476 1863026 : n->implicit_section = true;
477 1863026 : return false;
478 : }
479 :
480 : /* If required, set DECL_SECTION_NAME to a unique name. */
481 :
482 : void
483 7524430 : resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
484 : int flag_function_or_data_sections)
485 : {
486 7524430 : if (DECL_SECTION_NAME (decl) == NULL
487 4644819 : && targetm_common.have_named_sections
488 12169249 : && (flag_function_or_data_sections
489 2953675 : || lookup_attribute ("retain", DECL_ATTRIBUTES (decl))
490 2953557 : || DECL_COMDAT_GROUP (decl)))
491 : {
492 1819498 : targetm.asm_out.unique_section (decl, reloc);
493 1819498 : if (DECL_SECTION_NAME (decl))
494 1819498 : symtab_node::get (decl)->call_for_symbol_and_aliases
495 1819498 : (set_implicit_section, NULL, true);
496 : }
497 7524430 : }
498 :
499 : #ifdef BSS_SECTION_ASM_OP
500 :
501 : #ifdef ASM_OUTPUT_ALIGNED_BSS
502 :
503 : /* Utility function for targets to use in implementing
504 : ASM_OUTPUT_ALIGNED_BSS.
505 : ??? It is believed that this function will work in most cases so such
506 : support is localized here. */
507 :
508 : static void
509 0 : asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
510 : const char *name, unsigned HOST_WIDE_INT size,
511 : int align)
512 : {
513 0 : switch_to_section (bss_section);
514 0 : ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
515 : #ifdef ASM_DECLARE_OBJECT_NAME
516 0 : last_assemble_variable_decl = decl;
517 0 : ASM_DECLARE_OBJECT_NAME (file, name, decl);
518 : #else
519 : /* Standard thing is just output label for the object. */
520 : ASM_OUTPUT_LABEL (file, name);
521 : #endif /* ASM_DECLARE_OBJECT_NAME */
522 0 : ASM_OUTPUT_SKIP (file, size ? size : 1);
523 0 : }
524 :
525 : #endif
526 :
527 : #endif /* BSS_SECTION_ASM_OP */
528 :
529 : #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
530 : /* Return the hot section for function DECL. Return text_section for
531 : null DECLs. */
532 :
533 : static section *
534 85552081 : hot_function_section (tree decl)
535 : {
536 85552081 : if (decl != NULL_TREE
537 85552081 : && DECL_SECTION_NAME (decl) != NULL
538 146049104 : && targetm_common.have_named_sections)
539 60497023 : return get_named_section (decl, NULL, 0);
540 : else
541 25055058 : return text_section;
542 : }
543 : #endif
544 :
545 : /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
546 : is NULL.
547 :
548 : When DECL_SECTION_NAME is non-NULL and it is implicit section and
549 : NAMED_SECTION_SUFFIX is non-NULL, then produce section called
550 : concatenate the name with NAMED_SECTION_SUFFIX.
551 : Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
552 :
553 : section *
554 7781741 : get_named_text_section (tree decl,
555 : const char *text_section_name,
556 : const char *named_section_suffix)
557 : {
558 7781741 : if (decl && DECL_SECTION_NAME (decl))
559 : {
560 6815393 : if (named_section_suffix)
561 : {
562 0 : const char *dsn = DECL_SECTION_NAME (decl);
563 0 : const char *stripped_name;
564 0 : char *name, *buffer;
565 :
566 0 : name = (char *) alloca (strlen (dsn) + 1);
567 0 : memcpy (name, dsn,
568 0 : strlen (dsn) + 1);
569 :
570 0 : stripped_name = targetm.strip_name_encoding (name);
571 :
572 0 : buffer = ACONCAT ((stripped_name, named_section_suffix, NULL));
573 0 : return get_named_section (decl, buffer, 0);
574 : }
575 6815393 : else if (symtab_node::get (decl)->implicit_section)
576 : {
577 6815372 : const char *name;
578 :
579 : /* Do not try to split gnu_linkonce functions. This gets somewhat
580 : slipperly. */
581 6815372 : if (DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP)
582 : return NULL;
583 6815372 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
584 6815372 : name = targetm.strip_name_encoding (name);
585 6815372 : return get_named_section (decl, ACONCAT ((text_section_name, ".",
586 6815372 : name, NULL)), 0);
587 : }
588 : else
589 : return NULL;
590 : }
591 966348 : return get_named_section (decl, text_section_name, 0);
592 : }
593 :
594 : /* Choose named function section based on its frequency. */
595 :
596 : section *
597 93333801 : default_function_section (tree decl, enum node_frequency freq,
598 : bool startup, bool exit)
599 : {
600 : #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
601 : /* Old GNU linkers have buggy --gc-section support, which sometimes
602 : results in .gcc_except_table* sections being garbage collected. */
603 : if (decl
604 : && symtab_node::get (decl)->implicit_section)
605 : return NULL;
606 : #endif
607 :
608 93333801 : if (!flag_reorder_functions
609 90903075 : || !targetm_common.have_named_sections)
610 : return NULL;
611 : /* Startup code should go to startup subsection unless it is
612 : unlikely executed (this happens especially with function splitting
613 : where we can split away unnecessary parts of static constructors. */
614 90903075 : if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
615 : {
616 : /* During LTO the tp_first_run profiling will naturally place all
617 : initialization code first. Using separate section is counter-productive
618 : because startup only code may call functions which are no longer
619 : startup only. */
620 1611757 : if (!in_lto_p
621 39126 : || !cgraph_node::get (decl)->tp_first_run
622 1611767 : || !opt_for_fn (decl, flag_profile_reorder_functions))
623 1611747 : return get_named_text_section (decl, ".text.startup", NULL);
624 : else
625 : return NULL;
626 : }
627 :
628 : /* Similarly for exit. */
629 89291318 : if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
630 4134 : return get_named_text_section (decl, ".text.exit", NULL);
631 :
632 : /* Group cold functions together, similarly for hot code. */
633 89287184 : switch (freq)
634 : {
635 6165151 : case NODE_FREQUENCY_UNLIKELY_EXECUTED:
636 6165151 : return get_named_text_section (decl, ".text.unlikely", NULL);
637 709 : case NODE_FREQUENCY_HOT:
638 709 : return get_named_text_section (decl, ".text.hot", NULL);
639 : /* FALLTHRU */
640 : default:
641 : return NULL;
642 : }
643 : }
644 :
645 : /* Return the section for function DECL.
646 :
647 : If DECL is NULL_TREE, return the text section. We can be passed
648 : NULL_TREE under some circumstances by dbxout.cc at least.
649 :
650 : If FORCE_COLD is true, return cold function section ignoring
651 : the frequency info of cgraph_node. */
652 :
653 : static section *
654 93333801 : function_section_1 (tree decl, bool force_cold)
655 : {
656 93333801 : section *section = NULL;
657 93333801 : enum node_frequency freq = NODE_FREQUENCY_NORMAL;
658 93333801 : bool startup = false, exit = false;
659 :
660 93333801 : if (decl)
661 : {
662 93333801 : struct cgraph_node *node = cgraph_node::get (decl);
663 :
664 93333801 : if (node)
665 : {
666 93333801 : freq = node->frequency;
667 93333801 : startup = node->only_called_at_startup;
668 93333801 : exit = node->only_called_at_exit;
669 : }
670 : }
671 93333801 : if (force_cold)
672 5965883 : freq = NODE_FREQUENCY_UNLIKELY_EXECUTED;
673 :
674 : #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
675 : if (decl != NULL_TREE
676 : && DECL_SECTION_NAME (decl) != NULL)
677 : {
678 : if (targetm.asm_out.function_section)
679 : section = targetm.asm_out.function_section (decl, freq,
680 : startup, exit);
681 : if (section)
682 : return section;
683 : return get_named_section (decl, NULL, 0);
684 : }
685 : else
686 : return targetm.asm_out.select_section
687 : (decl, freq == NODE_FREQUENCY_UNLIKELY_EXECUTED,
688 : symtab_node::get (decl)->definition_alignment ());
689 : #else
690 93333801 : if (targetm.asm_out.function_section)
691 93333801 : section = targetm.asm_out.function_section (decl, freq, startup, exit);
692 93333801 : if (section)
693 : return section;
694 85552081 : return hot_function_section (decl);
695 : #endif
696 : }
697 :
698 : /* Return the section for function DECL.
699 :
700 : If DECL is NULL_TREE, return the text section. We can be passed
701 : NULL_TREE under some circumstances by dbxout.cc at least. */
702 :
703 : section *
704 3742823 : function_section (tree decl)
705 : {
706 : /* Handle cases where function splitting code decides
707 : to put function entry point into unlikely executed section
708 : despite the fact that the function itself is not cold
709 : (i.e. it is called rarely but contains a hot loop that is
710 : better to live in hot subsection for the code locality). */
711 3742823 : return function_section_1 (decl,
712 3742823 : first_function_block_is_cold);
713 : }
714 :
715 : /* Return the section for the current function, take IN_COLD_SECTION_P
716 : into account. */
717 :
718 : section *
719 89451184 : current_function_section (void)
720 : {
721 89451184 : return function_section_1 (current_function_decl, in_cold_section_p);
722 : }
723 :
724 : /* Tell assembler to switch to unlikely-to-be-executed text section. */
725 :
726 : section *
727 139794 : unlikely_text_section (void)
728 : {
729 139794 : return function_section_1 (current_function_decl, true);
730 : }
731 :
732 : /* When called within a function context, return true if the function
733 : has been assigned a cold text section and if SECT is that section.
734 : When called outside a function context, return true if SECT is the
735 : default cold section. */
736 :
737 : bool
738 0 : unlikely_text_section_p (section *sect)
739 : {
740 0 : return sect == function_section_1 (current_function_decl, true);
741 : }
742 :
743 : /* Switch to the other function partition (if inside of hot section
744 : into cold section, otherwise into the hot section). */
745 :
746 : void
747 0 : switch_to_other_text_partition (void)
748 : {
749 0 : in_cold_section_p = !in_cold_section_p;
750 0 : switch_to_section (current_function_section ());
751 0 : }
752 :
753 : /* Return the read-only or relocated read-only data section
754 : associated with function DECL. */
755 :
756 : section *
757 638023 : default_function_rodata_section (tree decl, bool relocatable)
758 : {
759 638023 : const char* sname;
760 638023 : unsigned int flags;
761 :
762 638023 : flags = 0;
763 :
764 638023 : if (relocatable)
765 : {
766 : sname = ".data.rel.ro.local";
767 : flags = (SECTION_WRITE | SECTION_RELRO);
768 : }
769 : else
770 638023 : sname = ".rodata";
771 :
772 638023 : if (decl && DECL_SECTION_NAME (decl))
773 : {
774 125618 : const char *name = DECL_SECTION_NAME (decl);
775 :
776 125618 : if (DECL_COMDAT_GROUP (decl) && HAVE_COMDAT_GROUP)
777 : {
778 38862 : const char *dot;
779 38862 : size_t len;
780 38862 : char* rname;
781 :
782 38862 : dot = strchr (name + 1, '.');
783 38862 : if (!dot)
784 0 : dot = name;
785 38862 : len = strlen (dot) + strlen (sname) + 1;
786 38862 : rname = (char *) alloca (len);
787 :
788 38862 : strcpy (rname, sname);
789 38862 : strcat (rname, dot);
790 38862 : return get_section (rname, (SECTION_LINKONCE | flags), decl);
791 : }
792 : /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo or
793 : .gnu.linkonce.d.rel.ro.local.foo if the jump table is relocatable. */
794 86756 : else if (DECL_COMDAT_GROUP (decl)
795 86756 : && startswith (name, ".gnu.linkonce.t."))
796 : {
797 0 : size_t len;
798 0 : char *rname;
799 :
800 0 : if (relocatable)
801 : {
802 0 : len = strlen (name) + strlen (".rel.ro.local") + 1;
803 0 : rname = (char *) alloca (len);
804 :
805 0 : strcpy (rname, ".gnu.linkonce.d.rel.ro.local");
806 0 : strcat (rname, name + 15);
807 : }
808 : else
809 : {
810 0 : len = strlen (name) + 1;
811 0 : rname = (char *) alloca (len);
812 :
813 0 : memcpy (rname, name, len);
814 0 : rname[14] = 'r';
815 : }
816 0 : return get_section (rname, (SECTION_LINKONCE | flags), decl);
817 : }
818 : /* For .text.foo we want to use .rodata.foo. */
819 86752 : else if (flag_function_sections && flag_data_sections
820 173508 : && startswith (name, ".text."))
821 : {
822 86752 : size_t len = strlen (name) + 1;
823 86752 : char *rname = (char *) alloca (len + strlen (sname) - 5);
824 :
825 86752 : memcpy (rname, sname, strlen (sname));
826 86752 : memcpy (rname + strlen (sname), name + 5, len - 5);
827 86752 : return get_section (rname, flags, decl);
828 : }
829 : }
830 :
831 512409 : if (relocatable)
832 0 : return get_section (sname, flags, decl);
833 : else
834 512409 : return readonly_data_section;
835 : }
836 :
837 : /* Return the read-only data section associated with function DECL
838 : for targets where that section should be always the single
839 : readonly data section. */
840 :
841 : section *
842 0 : default_no_function_rodata_section (tree, bool)
843 : {
844 0 : return readonly_data_section;
845 : }
846 :
847 : /* A subroutine of mergeable_string_section and mergeable_constant_section. */
848 :
849 : static const char *
850 623089 : function_mergeable_rodata_prefix (void)
851 : {
852 623089 : section *s = targetm.asm_out.function_rodata_section (current_function_decl,
853 : false);
854 623089 : if (SECTION_STYLE (s) == SECTION_NAMED)
855 117252 : return s->named.name;
856 : else
857 505837 : return targetm.asm_out.mergeable_rodata_prefix;
858 : }
859 :
860 : /* Return the section to use for string merging. */
861 :
862 : static section *
863 1252061 : mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
864 : unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
865 : unsigned int flags ATTRIBUTE_UNUSED)
866 : {
867 1252061 : HOST_WIDE_INT len;
868 :
869 1252061 : if (HAVE_GAS_SHF_MERGE && flag_merge_constants
870 1063507 : && TREE_CODE (decl) == STRING_CST
871 1063507 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
872 1063507 : && align <= MAX_MERGEABLE_BITSIZE
873 1063507 : && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
874 2315432 : && TREE_STRING_LENGTH (decl) == len)
875 : {
876 416624 : scalar_int_mode mode;
877 416624 : unsigned int modesize;
878 416624 : const char *str;
879 416624 : HOST_WIDE_INT i;
880 416624 : int j, unit;
881 416624 : const char *prefix = function_mergeable_rodata_prefix ();
882 416624 : char *name = (char *) alloca (strlen (prefix) + 30);
883 :
884 416624 : mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
885 416624 : modesize = GET_MODE_BITSIZE (mode);
886 416624 : if (modesize >= 8 && modesize <= MAX_MERGEABLE_BITSIZE
887 416624 : && (modesize & (modesize - 1)) == 0)
888 : {
889 416624 : if (align < modesize)
890 : align = modesize;
891 :
892 416624 : str = TREE_STRING_POINTER (decl);
893 416624 : unit = GET_MODE_SIZE (mode);
894 :
895 : /* Check for embedded NUL characters. */
896 116599156 : for (i = 0; i < len; i += unit)
897 : {
898 116955351 : for (j = 0; j < unit; j++)
899 116575679 : if (str[i + j] != '\0')
900 : break;
901 116562204 : if (j == unit)
902 : break;
903 : }
904 416624 : if (i == len - unit || (unit == 1 && i == len))
905 : {
906 412840 : sprintf (name, "%s.str%d.%d", prefix,
907 412840 : modesize / BITS_PER_UNIT, (int) (align / BITS_PER_UNIT));
908 412840 : flags |= (modesize / BITS_PER_UNIT) | SECTION_MERGE | SECTION_STRINGS;
909 412840 : return get_section (name, flags, NULL);
910 : }
911 : }
912 : }
913 :
914 839221 : return readonly_data_section;
915 : }
916 :
917 : /* Return the section to use for constant merging. */
918 :
919 : section *
920 250546 : mergeable_constant_section (unsigned HOST_WIDE_INT size_bits,
921 : unsigned HOST_WIDE_INT align,
922 : unsigned int flags)
923 : {
924 250546 : unsigned HOST_WIDE_INT newsize;
925 250546 : newsize = HOST_WIDE_INT_1U << ceil_log2 (size_bits);
926 250546 : if (HAVE_GAS_SHF_MERGE && flag_merge_constants
927 210858 : && newsize <= MAX_MERGEABLE_BITSIZE
928 210858 : && align >= 8
929 206465 : && align <= newsize
930 206465 : && (align & (align - 1)) == 0)
931 : {
932 206465 : const char *prefix = function_mergeable_rodata_prefix ();
933 206465 : char *name = (char *) alloca (strlen (prefix) + 30);
934 :
935 206465 : sprintf (name, "%s.cst%d", prefix, (int) (newsize / BITS_PER_UNIT));
936 206465 : flags |= (newsize / BITS_PER_UNIT) | SECTION_MERGE;
937 206465 : return get_section (name, flags, NULL);
938 : }
939 44081 : return readonly_data_section;
940 : }
941 :
942 :
943 : /* Return the section to use for constant merging. Like the above
944 : but the size stored as a tree. */
945 : static section *
946 480 : mergeable_constant_section (tree size_bits,
947 : unsigned HOST_WIDE_INT align,
948 : unsigned int flags)
949 : {
950 480 : if (!size_bits || !tree_fits_uhwi_p (size_bits))
951 0 : return readonly_data_section;
952 480 : return mergeable_constant_section (tree_to_uhwi (size_bits), align, flags);
953 : }
954 :
955 :
956 : /* Return the section to use for constant merging. Like the above
957 : but given a mode rather than the size. */
958 :
959 : section *
960 250066 : mergeable_constant_section (machine_mode mode,
961 : unsigned HOST_WIDE_INT align,
962 : unsigned int flags)
963 : {
964 : /* If the mode is unknown (BLK or VOID), then return a non mergeable section. */
965 250066 : if (mode == BLKmode || mode == VOIDmode)
966 0 : return readonly_data_section;
967 250066 : unsigned HOST_WIDE_INT size;
968 500132 : if (!GET_MODE_BITSIZE (mode).is_constant (&size))
969 : return readonly_data_section;
970 250066 : return mergeable_constant_section (size, align, flags);
971 : }
972 :
973 :
974 : /* Given NAME, a putative register name, discard any customary prefixes. */
975 :
976 : static const char *
977 12605542 : strip_reg_name (const char *name)
978 : {
979 : #ifdef REGISTER_PREFIX
980 : if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
981 : name += strlen (REGISTER_PREFIX);
982 : #endif
983 12604918 : if (name[0] == '%' || name[0] == '#')
984 624 : name++;
985 12605542 : return name;
986 : }
987 :
988 : /* The user has asked for a DECL to have a particular name. Set (or
989 : change) it in such a way that we don't prefix an underscore to
990 : it. */
991 : void
992 2919379 : set_user_assembler_name (tree decl, const char *name)
993 : {
994 2919379 : char *starred = (char *) alloca (strlen (name) + 2);
995 2919379 : starred[0] = '*';
996 2919379 : strcpy (starred + 1, name);
997 2919379 : symtab->change_decl_assembler_name (decl, get_identifier (starred));
998 2919379 : SET_DECL_RTL (decl, NULL_RTX);
999 2919379 : }
1000 :
1001 : /* Decode an `asm' spec for a declaration as a register name.
1002 : Return the register number, or -1 if nothing specified,
1003 : or -2 if the ASMSPEC is not `cc' or `memory' or `redzone' and is not
1004 : recognized,
1005 : or -3 if ASMSPEC is `cc' and is not recognized,
1006 : or -4 if ASMSPEC is `memory' and is not recognized,
1007 : or -5 if ASMSPEC is `redzone' and is not recognized.
1008 : Accept an exact spelling or a decimal number.
1009 : Prefixes such as % are optional. */
1010 :
1011 : int
1012 167707 : decode_reg_name_and_count (const char *asmspec, int *pnregs)
1013 : {
1014 : /* Presume just one register is clobbered. */
1015 167707 : *pnregs = 1;
1016 :
1017 167707 : if (asmspec != 0)
1018 : {
1019 167707 : int i;
1020 :
1021 : /* Get rid of confusing prefixes. */
1022 167707 : asmspec = strip_reg_name (asmspec);
1023 :
1024 : /* Allow a decimal number as a "register name". */
1025 167707 : if (ISDIGIT (asmspec[0]))
1026 : {
1027 60 : char *pend;
1028 60 : errno = 0;
1029 60 : unsigned long j = strtoul (asmspec, &pend, 10);
1030 60 : if (*pend == '\0')
1031 : {
1032 54 : static_assert (FIRST_PSEUDO_REGISTER <= INT_MAX, "");
1033 54 : if (errno != ERANGE
1034 51 : && j < FIRST_PSEUDO_REGISTER
1035 36 : && reg_names[j][0])
1036 54 : return j;
1037 : else
1038 : return -2;
1039 : }
1040 : }
1041 :
1042 12540889 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1043 12437835 : if (reg_names[i][0]
1044 24875670 : && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1045 : return i;
1046 :
1047 : #ifdef OVERLAPPING_REGISTER_NAMES
1048 : {
1049 : static const struct
1050 : {
1051 : const char *const name;
1052 : const int number;
1053 : const int nregs;
1054 : } table[] = OVERLAPPING_REGISTER_NAMES;
1055 :
1056 : for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1057 : if (table[i].name[0]
1058 : && ! strcmp (asmspec, table[i].name))
1059 : {
1060 : *pnregs = table[i].nregs;
1061 : return table[i].number;
1062 : }
1063 : }
1064 : #endif /* OVERLAPPING_REGISTER_NAMES */
1065 :
1066 : #ifdef ADDITIONAL_REGISTER_NAMES
1067 : {
1068 : static const struct { const char *const name; const int number; } table[]
1069 : = ADDITIONAL_REGISTER_NAMES;
1070 :
1071 7739927 : for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1072 7659741 : if (table[i].name[0]
1073 7659741 : && ! strcmp (asmspec, table[i].name)
1074 22868 : && reg_names[table[i].number][0])
1075 : return table[i].number;
1076 : }
1077 : #endif /* ADDITIONAL_REGISTER_NAMES */
1078 :
1079 80186 : if (!strcmp (asmspec, "redzone"))
1080 : return -5;
1081 :
1082 80182 : if (!strcmp (asmspec, "memory"))
1083 : return -4;
1084 :
1085 969 : if (!strcmp (asmspec, "cc"))
1086 : return -3;
1087 :
1088 51 : return -2;
1089 : }
1090 :
1091 : return -1;
1092 : }
1093 :
1094 : int
1095 85271 : decode_reg_name (const char *name)
1096 : {
1097 85271 : int count;
1098 85271 : return decode_reg_name_and_count (name, &count);
1099 : }
1100 :
1101 :
1102 : /* Return true if DECL's initializer is suitable for a BSS section. */
1103 :
1104 : bool
1105 6514333 : bss_initializer_p (const_tree decl, bool named)
1106 : {
1107 : /* Do not put non-common constants into the .bss section, they belong in
1108 : a readonly section, except when NAMED is true. */
1109 11198072 : return ((!TREE_READONLY (decl) || DECL_COMMON (decl) || named)
1110 6537967 : && (DECL_INITIAL (decl) == NULL
1111 : /* In LTO we have no errors in program; error_mark_node is used
1112 : to mark offlined constructors. */
1113 686115 : || (DECL_INITIAL (decl) == error_mark_node
1114 4 : && !in_lto_p)
1115 686111 : || (flag_zero_initialized_in_bss
1116 686053 : && initializer_zerop (DECL_INITIAL (decl))
1117 : /* A decl with the "persistent" attribute applied and
1118 : explicitly initialized to 0 should not be treated as a BSS
1119 : variable. */
1120 40475 : && !DECL_PERSISTENT_P (decl))));
1121 : }
1122 :
1123 : /* Compute the alignment of variable specified by DECL.
1124 : DONT_OUTPUT_DATA is from assemble_variable. */
1125 :
1126 : void
1127 5992166 : align_variable (tree decl, bool dont_output_data)
1128 : {
1129 5992166 : unsigned int align = DECL_ALIGN (decl);
1130 :
1131 : /* In the case for initialing an array whose length isn't specified,
1132 : where we have not yet been able to do the layout,
1133 : figure out the proper alignment now. */
1134 3630 : if (dont_output_data && DECL_SIZE (decl) == 0
1135 5992166 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1136 0 : align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1137 :
1138 : /* Some object file formats have a maximum alignment which they support.
1139 : In particular, a.out format supports a maximum alignment of 4. */
1140 0 : if (align > MAX_OFILE_ALIGNMENT)
1141 : {
1142 : error ("alignment of %q+D is greater than maximum object "
1143 : "file alignment %d", decl,
1144 : MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1145 : align = MAX_OFILE_ALIGNMENT;
1146 : }
1147 :
1148 5992166 : if (! DECL_USER_ALIGN (decl))
1149 : {
1150 : #ifdef DATA_ABI_ALIGNMENT
1151 5862467 : unsigned int data_abi_align
1152 5862467 : = DATA_ABI_ALIGNMENT (TREE_TYPE (decl), align);
1153 : /* For backwards compatibility, don't assume the ABI alignment for
1154 : TLS variables. */
1155 5862559 : if (! DECL_THREAD_LOCAL_P (decl) || data_abi_align <= BITS_PER_WORD)
1156 : align = data_abi_align;
1157 : #endif
1158 :
1159 : /* On some machines, it is good to increase alignment sometimes.
1160 : But as DECL_ALIGN is used both for actually emitting the variable
1161 : and for code accessing the variable as guaranteed alignment, we
1162 : can only increase the alignment if it is a performance optimization
1163 : if the references to it must bind to the current definition. */
1164 5862467 : if (decl_binds_to_current_def_p (decl)
1165 5862467 : && !DECL_VIRTUAL_P (decl))
1166 : {
1167 : #ifdef DATA_ALIGNMENT
1168 5241053 : unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1169 : /* Don't increase alignment too much for TLS variables - TLS space
1170 : is too precious. */
1171 5241121 : if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1172 : align = data_align;
1173 : #endif
1174 5241053 : if (DECL_INITIAL (decl) != 0
1175 : /* In LTO we have no errors in program; error_mark_node is used
1176 : to mark offlined constructors. */
1177 5241053 : && (in_lto_p || DECL_INITIAL (decl) != error_mark_node))
1178 : {
1179 3285052 : unsigned int const_align
1180 3285052 : = targetm.constant_alignment (DECL_INITIAL (decl), align);
1181 : /* Don't increase alignment too much for TLS variables - TLS
1182 : space is too precious. */
1183 3285058 : if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1184 : align = const_align;
1185 : }
1186 : }
1187 : }
1188 :
1189 : /* Reset the alignment in case we have made it tighter, so we can benefit
1190 : from it in get_pointer_alignment. */
1191 5992166 : SET_DECL_ALIGN (decl, align);
1192 5992166 : }
1193 :
1194 : /* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1195 : beyond what align_variable returned. */
1196 :
1197 : static unsigned int
1198 5855022 : get_variable_align (tree decl)
1199 : {
1200 5855022 : unsigned int align = DECL_ALIGN (decl);
1201 :
1202 : /* For user aligned vars or static vars align_variable already did
1203 : everything. */
1204 5855022 : if (DECL_USER_ALIGN (decl) || !TREE_PUBLIC (decl))
1205 : return align;
1206 :
1207 : #ifdef DATA_ABI_ALIGNMENT
1208 2895395 : if (DECL_THREAD_LOCAL_P (decl))
1209 6190 : align = DATA_ABI_ALIGNMENT (TREE_TYPE (decl), align);
1210 : #endif
1211 :
1212 : /* For decls that bind to the current definition, align_variable
1213 : did also everything, except for not assuming ABI required alignment
1214 : of TLS variables. For other vars, increase the alignment here
1215 : as an optimization. */
1216 2895395 : if (!decl_binds_to_current_def_p (decl))
1217 : {
1218 : /* On some machines, it is good to increase alignment sometimes. */
1219 : #ifdef DATA_ALIGNMENT
1220 601628 : unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1221 : /* Don't increase alignment too much for TLS variables - TLS space
1222 : is too precious. */
1223 601649 : if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1224 : align = data_align;
1225 : #endif
1226 601628 : if (DECL_INITIAL (decl) != 0
1227 : /* In LTO we have no errors in program; error_mark_node is used
1228 : to mark offlined constructors. */
1229 601628 : && (in_lto_p || DECL_INITIAL (decl) != error_mark_node))
1230 : {
1231 586611 : unsigned int const_align
1232 586611 : = targetm.constant_alignment (DECL_INITIAL (decl), align);
1233 : /* Don't increase alignment too much for TLS variables - TLS space
1234 : is too precious. */
1235 586616 : if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1236 : align = const_align;
1237 : }
1238 : }
1239 :
1240 : return align;
1241 : }
1242 :
1243 : /* Compute reloc for get_variable_section. The return value
1244 : is a mask for which bit 1 indicates a global relocation, and bit 0
1245 : indicates a local relocation. */
1246 :
1247 : int
1248 4528423 : compute_reloc_for_var (tree decl)
1249 : {
1250 4528423 : int reloc;
1251 :
1252 4528423 : if (DECL_INITIAL (decl) == error_mark_node)
1253 1146612 : reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1254 4528421 : else if (DECL_INITIAL (decl))
1255 3381811 : reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1256 : else
1257 : reloc = 0;
1258 :
1259 4528423 : return reloc;
1260 : }
1261 :
1262 : /* Return the section into which the given VAR_DECL or CONST_DECL
1263 : should be placed. PREFER_NOSWITCH_P is true if a noswitch
1264 : section should be used wherever possible. */
1265 :
1266 : section *
1267 4529847 : get_variable_section (tree decl, bool prefer_noswitch_p)
1268 : {
1269 4529847 : addr_space_t as = ADDR_SPACE_GENERIC;
1270 4529847 : int reloc;
1271 4529847 : varpool_node *vnode = varpool_node::get (decl);
1272 4529847 : if (vnode)
1273 : {
1274 4529832 : vnode = vnode->ultimate_alias_target ();
1275 4529832 : decl = vnode->decl;
1276 : }
1277 :
1278 4529847 : if (TREE_TYPE (decl) != error_mark_node)
1279 4529847 : as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1280 :
1281 : /* We need the constructor to figure out reloc flag. */
1282 4529847 : if (vnode)
1283 4529832 : vnode->get_constructor ();
1284 :
1285 4529847 : if (DECL_COMMON (decl)
1286 4529847 : && !lookup_attribute ("retain", DECL_ATTRIBUTES (decl)))
1287 : {
1288 : /* If the decl has been given an explicit section name, or it resides
1289 : in a non-generic address space, then it isn't common, and shouldn't
1290 : be handled as such. */
1291 1424 : gcc_assert (DECL_SECTION_NAME (decl) == NULL
1292 : && ADDR_SPACE_GENERIC_P (as));
1293 1424 : if (DECL_THREAD_LOCAL_P (decl))
1294 60 : return tls_comm_section;
1295 1364 : else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1296 1364 : return comm_section;
1297 : }
1298 :
1299 4528423 : reloc = compute_reloc_for_var (decl);
1300 :
1301 4528423 : resolve_unique_section (decl, reloc, flag_data_sections);
1302 4528423 : if (IN_NAMED_SECTION (decl))
1303 : {
1304 2975680 : section *sect = get_named_section (decl, NULL, reloc);
1305 :
1306 2975680 : if ((sect->common.flags & SECTION_BSS)
1307 2975680 : && !bss_initializer_p (decl, true))
1308 : {
1309 2 : if (flag_zero_initialized_in_bss)
1310 2 : error_at (DECL_SOURCE_LOCATION (decl),
1311 : "only zero initializers are allowed in section %qs",
1312 : sect->named.name);
1313 : else
1314 0 : error_at (DECL_SOURCE_LOCATION (decl),
1315 : "no initializers are allowed in section %qs",
1316 : sect->named.name);
1317 2 : DECL_INITIAL (decl) = error_mark_node;
1318 : }
1319 : return sect;
1320 : }
1321 :
1322 1552743 : if (ADDR_SPACE_GENERIC_P (as)
1323 1552737 : && !DECL_THREAD_LOCAL_P (decl)
1324 1549096 : && !DECL_NOINIT_P (decl)
1325 1549096 : && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1326 3101839 : && bss_initializer_p (decl))
1327 : {
1328 1155896 : if (!TREE_PUBLIC (decl)
1329 1156086 : && !((flag_sanitize & SANITIZE_ADDRESS)
1330 190 : && asan_protect_global (decl)))
1331 158982 : return lcomm_section;
1332 996914 : if (bss_noswitch_section)
1333 : return bss_noswitch_section;
1334 : }
1335 :
1336 396847 : return targetm.asm_out.select_section (decl, reloc,
1337 793694 : get_variable_align (decl));
1338 : }
1339 :
1340 : /* Return the block into which object_block DECL should be placed. */
1341 :
1342 : static struct object_block *
1343 0 : get_block_for_decl (tree decl)
1344 : {
1345 0 : section *sect;
1346 :
1347 0 : if (VAR_P (decl))
1348 : {
1349 : /* The object must be defined in this translation unit. */
1350 0 : if (DECL_EXTERNAL (decl))
1351 : return NULL;
1352 :
1353 : /* There's no point using object blocks for something that is
1354 : isolated by definition. */
1355 0 : if (DECL_COMDAT_GROUP (decl))
1356 : return NULL;
1357 : }
1358 :
1359 : /* We can only calculate block offsets if the decl has a known
1360 : constant size. */
1361 0 : if (DECL_SIZE_UNIT (decl) == NULL)
1362 : return NULL;
1363 0 : if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl)))
1364 : return NULL;
1365 :
1366 : /* Find out which section should contain DECL. We cannot put it into
1367 : an object block if it requires a standalone definition. */
1368 0 : if (VAR_P (decl))
1369 0 : align_variable (decl, 0);
1370 0 : sect = get_variable_section (decl, true);
1371 0 : if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1372 : return NULL;
1373 :
1374 0 : if (bool (lookup_attribute ("retain", DECL_ATTRIBUTES (decl)))
1375 0 : != bool (sect->common.flags & SECTION_RETAIN))
1376 : return NULL;
1377 :
1378 0 : return get_block_for_section (sect);
1379 : }
1380 :
1381 : /* Make sure block symbol SYMBOL is in block BLOCK. */
1382 :
1383 : static void
1384 0 : change_symbol_block (rtx symbol, struct object_block *block)
1385 : {
1386 0 : if (block != SYMBOL_REF_BLOCK (symbol))
1387 : {
1388 0 : gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1389 0 : SYMBOL_REF_BLOCK (symbol) = block;
1390 : }
1391 0 : }
1392 :
1393 : /* Return true if it is possible to put DECL in an object_block. */
1394 :
1395 : static bool
1396 0 : use_blocks_for_decl_p (tree decl)
1397 : {
1398 0 : struct symtab_node *snode;
1399 :
1400 : /* Don't create object blocks if each DECL is placed into a separate
1401 : section because that will uselessly create a section anchor for
1402 : each DECL. */
1403 0 : if (flag_data_sections)
1404 : return false;
1405 :
1406 : /* Only data DECLs can be placed into object blocks. */
1407 0 : if (!VAR_P (decl) && TREE_CODE (decl) != CONST_DECL)
1408 : return false;
1409 :
1410 : /* DECL_INITIAL (decl) set to decl is a hack used for some decls that
1411 : are never used from code directly and we never want object block handling
1412 : for those. */
1413 0 : if (DECL_INITIAL (decl) == decl)
1414 : return false;
1415 :
1416 : /* If this decl is an alias, then we don't want to emit a
1417 : definition. */
1418 0 : if (VAR_P (decl)
1419 0 : && (snode = symtab_node::get (decl)) != NULL
1420 0 : && snode->alias)
1421 : return false;
1422 :
1423 0 : return targetm.use_blocks_for_decl_p (decl);
1424 : }
1425 :
1426 : /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1427 : until we find an identifier that is not itself a transparent alias.
1428 : Modify the alias passed to it by reference (and all aliases on the
1429 : way to the ultimate target), such that they do not have to be
1430 : followed again, and return the ultimate target of the alias
1431 : chain. */
1432 :
1433 : static inline tree
1434 37613301 : ultimate_transparent_alias_target (tree *alias)
1435 : {
1436 37613301 : tree target = *alias;
1437 :
1438 37613301 : if (IDENTIFIER_TRANSPARENT_ALIAS (target))
1439 : {
1440 0 : gcc_assert (TREE_CHAIN (target));
1441 0 : target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
1442 0 : gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
1443 : && ! TREE_CHAIN (target));
1444 0 : *alias = target;
1445 : }
1446 :
1447 37613301 : return target;
1448 : }
1449 :
1450 : /* Return true if REGNUM is mentioned in ELIMINABLE_REGS as a from
1451 : register number. */
1452 :
1453 : static bool
1454 0 : eliminable_regno_p (int regnum)
1455 : {
1456 0 : static const struct
1457 : {
1458 : const int from;
1459 : const int to;
1460 : } eliminables[] = ELIMINABLE_REGS;
1461 13 : for (size_t i = 0; i < ARRAY_SIZE (eliminables); i++)
1462 13 : if (regnum == eliminables[i].from)
1463 : return true;
1464 : return false;
1465 : }
1466 :
1467 : /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1468 : have static storage duration. In other words, it should not be an
1469 : automatic variable, including PARM_DECLs.
1470 :
1471 : There is, however, one exception: this function handles variables
1472 : explicitly placed in a particular register by the user.
1473 :
1474 : This is never called for PARM_DECL nodes. */
1475 :
1476 : void
1477 8759985 : make_decl_rtl (tree decl)
1478 : {
1479 8759985 : const char *name = 0;
1480 8759985 : int reg_number;
1481 8759985 : tree id;
1482 8759985 : rtx x;
1483 :
1484 : /* Check that we are not being given an automatic variable. */
1485 8759985 : gcc_assert (TREE_CODE (decl) != PARM_DECL
1486 : && TREE_CODE (decl) != RESULT_DECL);
1487 :
1488 : /* A weak alias has TREE_PUBLIC set but not the other bits. */
1489 8759985 : gcc_assert (!VAR_P (decl)
1490 : || TREE_STATIC (decl)
1491 : || TREE_PUBLIC (decl)
1492 : || DECL_EXTERNAL (decl)
1493 : || DECL_REGISTER (decl));
1494 :
1495 : /* And that we were not given a type or a label. */
1496 8759985 : gcc_assert (TREE_CODE (decl) != TYPE_DECL
1497 : && TREE_CODE (decl) != LABEL_DECL);
1498 :
1499 : /* For a duplicate declaration, we can be called twice on the
1500 : same DECL node. Don't discard the RTL already made. */
1501 8759985 : if (DECL_RTL_SET_P (decl))
1502 : {
1503 : /* If the old RTL had the wrong mode, fix the mode. */
1504 13371 : x = DECL_RTL (decl);
1505 13371 : if (GET_MODE (x) != DECL_MODE (decl))
1506 0 : SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1507 :
1508 13371 : if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1509 : return;
1510 :
1511 : /* ??? Another way to do this would be to maintain a hashed
1512 : table of such critters. Instead of adding stuff to a DECL
1513 : to give certain attributes to it, we could use an external
1514 : hash map from DECL to set of attributes. */
1515 :
1516 : /* Let the target reassign the RTL if it wants.
1517 : This is necessary, for example, when one machine specific
1518 : decl attribute overrides another. */
1519 13302 : targetm.encode_section_info (decl, DECL_RTL (decl), false);
1520 :
1521 : /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1522 : on the new decl information. */
1523 13302 : if (MEM_P (x)
1524 13302 : && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1525 26604 : && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1526 0 : change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1527 :
1528 : return;
1529 : }
1530 :
1531 : /* If this variable belongs to the global constant pool, retrieve the
1532 : pre-computed RTL or recompute it in LTO mode. */
1533 8746614 : if (VAR_P (decl) && DECL_IN_CONSTANT_POOL (decl))
1534 : {
1535 6356 : SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1536 6356 : return;
1537 : }
1538 :
1539 8740258 : id = DECL_ASSEMBLER_NAME (decl);
1540 8740258 : name = IDENTIFIER_POINTER (id);
1541 :
1542 8675326 : if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1543 11922707 : && DECL_REGISTER (decl))
1544 : {
1545 13 : error ("register name not specified for %q+D", decl);
1546 : }
1547 8740245 : else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1548 : {
1549 1230 : const char *asmspec = name+1;
1550 1230 : machine_mode mode = DECL_MODE (decl);
1551 1230 : reg_number = decode_reg_name (asmspec);
1552 : /* First detect errors in declaring global registers. */
1553 1230 : if (reg_number == -1)
1554 0 : error ("register name not specified for %q+D", decl);
1555 1230 : else if (reg_number < 0)
1556 28 : error ("invalid register name for %q+D", decl);
1557 1202 : else if (mode == BLKmode)
1558 5 : error ("data type of %q+D isn%'t suitable for a register",
1559 : decl);
1560 1197 : else if (!in_hard_reg_set_p (accessible_reg_set, mode, reg_number))
1561 2 : error ("the register specified for %q+D cannot be accessed"
1562 : " by the current target", decl);
1563 1195 : else if (!in_hard_reg_set_p (operand_reg_set, mode, reg_number))
1564 0 : error ("the register specified for %q+D is not general enough"
1565 : " to be used as a register variable", decl);
1566 1195 : else if (!targetm.hard_regno_mode_ok (reg_number, mode))
1567 3 : error ("register specified for %q+D isn%'t suitable for data type",
1568 : decl);
1569 1192 : else if (reg_number != HARD_FRAME_POINTER_REGNUM
1570 1186 : && (reg_number == FRAME_POINTER_REGNUM
1571 : #ifdef RETURN_ADDRESS_POINTER_REGNUM
1572 : || reg_number == RETURN_ADDRESS_POINTER_REGNUM
1573 : #endif
1574 1186 : || reg_number == ARG_POINTER_REGNUM)
1575 1197 : && eliminable_regno_p (reg_number))
1576 5 : error ("register specified for %q+D is an internal GCC "
1577 : "implementation detail", decl);
1578 : /* Now handle properly declared static register variables. */
1579 : else
1580 : {
1581 1187 : int nregs;
1582 :
1583 1187 : if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1584 : {
1585 0 : DECL_INITIAL (decl) = 0;
1586 0 : error ("global register variable has initial value");
1587 : }
1588 1187 : if (TREE_THIS_VOLATILE (decl))
1589 11 : warning (OPT_Wvolatile_register_var,
1590 : "optimization may eliminate reads and/or "
1591 : "writes to register variables");
1592 :
1593 : /* If the user specified one of the eliminables registers here,
1594 : e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1595 : confused with that register and be eliminated. This usage is
1596 : somewhat suspect... */
1597 :
1598 1187 : SET_DECL_RTL (decl, gen_raw_REG (mode, reg_number));
1599 1187 : ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1600 1187 : REG_USERVAR_P (DECL_RTL (decl)) = 1;
1601 :
1602 1187 : if (TREE_STATIC (decl))
1603 : {
1604 : /* Make this register global, so not usable for anything
1605 : else. */
1606 : #ifdef ASM_DECLARE_REGISTER_GLOBAL
1607 : name = IDENTIFIER_POINTER (DECL_NAME (decl));
1608 : ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1609 : #endif
1610 110 : nregs = hard_regno_nregs (reg_number, mode);
1611 220 : while (nregs > 0)
1612 110 : globalize_reg (decl, reg_number + --nregs);
1613 : }
1614 :
1615 : /* As a register variable, it has no section. */
1616 : return;
1617 : }
1618 : /* Avoid internal errors from invalid register
1619 : specifications. */
1620 43 : SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
1621 43 : DECL_HARD_REGISTER (decl) = 0;
1622 : /* Also avoid SSA inconsistencies by pretending this is an external
1623 : decl now. */
1624 43 : DECL_EXTERNAL (decl) = 1;
1625 43 : return;
1626 : }
1627 : /* Now handle ordinary static variables and functions (in memory).
1628 : Also handle vars declared register invalidly. */
1629 : else if (name[0] == '*')
1630 : {
1631 : #ifdef REGISTER_PREFIX
1632 : if (strlen (REGISTER_PREFIX) != 0)
1633 : {
1634 : reg_number = decode_reg_name (name);
1635 : if (reg_number >= 0 || reg_number == -3)
1636 : error ("register name given for non-register variable %q+D", decl);
1637 : }
1638 : #endif
1639 : }
1640 :
1641 : /* Specifying a section attribute on a variable forces it into a
1642 : non-.bss section, and thus it cannot be common. */
1643 : /* FIXME: In general this code should not be necessary because
1644 : visibility pass is doing the same work. But notice_global_symbol
1645 : is called early and it needs to make DECL_RTL to get the name.
1646 : we take care of recomputing the DECL_RTL after visibility is changed. */
1647 8739028 : if (VAR_P (decl)
1648 3227536 : && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
1649 3227536 : && DECL_SECTION_NAME (decl) != NULL
1650 1436891 : && DECL_INITIAL (decl) == NULL_TREE
1651 8739158 : && DECL_COMMON (decl))
1652 0 : DECL_COMMON (decl) = 0;
1653 :
1654 : /* Variables can't be both common and weak. */
1655 8739028 : if (VAR_P (decl) && DECL_WEAK (decl))
1656 338109 : DECL_COMMON (decl) = 0;
1657 :
1658 8739028 : if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1659 0 : x = create_block_symbol (name, get_block_for_decl (decl), -1);
1660 : else
1661 : {
1662 8739028 : machine_mode address_mode = Pmode;
1663 8739028 : if (TREE_TYPE (decl) != error_mark_node)
1664 : {
1665 8739028 : addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1666 8739028 : address_mode = targetm.addr_space.address_mode (as);
1667 : }
1668 8739028 : x = gen_rtx_SYMBOL_REF (address_mode, name);
1669 : }
1670 8739028 : SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1671 8739028 : SET_SYMBOL_REF_DECL (x, decl);
1672 :
1673 8739028 : x = gen_rtx_MEM (DECL_MODE (decl), x);
1674 8739028 : if (TREE_CODE (decl) != FUNCTION_DECL)
1675 3227536 : set_mem_attributes (x, decl, 1);
1676 8739028 : SET_DECL_RTL (decl, x);
1677 :
1678 : /* Optionally set flags or add text to the name to record information
1679 : such as that it is a function name.
1680 : If the name is changed, the macro ASM_OUTPUT_LABELREF
1681 : will have to know how to strip this information. */
1682 8739028 : targetm.encode_section_info (decl, DECL_RTL (decl), true);
1683 : }
1684 :
1685 : /* Like make_decl_rtl, but inhibit creation of new alias sets when
1686 : calling make_decl_rtl. Also, reset DECL_RTL before returning the
1687 : rtl. */
1688 :
1689 : rtx
1690 47226 : make_decl_rtl_for_debug (tree decl)
1691 : {
1692 47226 : unsigned int save_aliasing_flag;
1693 47226 : rtx rtl;
1694 :
1695 47226 : if (DECL_RTL_SET_P (decl))
1696 0 : return DECL_RTL (decl);
1697 :
1698 : /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1699 : call new_alias_set. If running with -fcompare-debug, sometimes
1700 : we do not want to create alias sets that will throw the alias
1701 : numbers off in the comparison dumps. So... clearing
1702 : flag_strict_aliasing will keep new_alias_set() from creating a
1703 : new set. */
1704 47226 : save_aliasing_flag = flag_strict_aliasing;
1705 47226 : flag_strict_aliasing = 0;
1706 :
1707 47226 : rtl = DECL_RTL (decl);
1708 : /* Reset DECL_RTL back, as various parts of the compiler expects
1709 : DECL_RTL set meaning it is actually going to be output. */
1710 47226 : SET_DECL_RTL (decl, NULL);
1711 :
1712 47226 : flag_strict_aliasing = save_aliasing_flag;
1713 47226 : return rtl;
1714 : }
1715 :
1716 : /* Output a string of literal assembler code
1717 : for an `asm' keyword used between functions. */
1718 :
1719 : void
1720 12485 : assemble_asm (tree asm_str)
1721 : {
1722 12485 : const char *p;
1723 :
1724 12485 : if (TREE_CODE (asm_str) != ASM_EXPR)
1725 : {
1726 12420 : app_enable ();
1727 12420 : if (TREE_CODE (asm_str) == ADDR_EXPR)
1728 0 : asm_str = TREE_OPERAND (asm_str, 0);
1729 :
1730 12420 : p = TREE_STRING_POINTER (asm_str);
1731 24805 : fprintf (asm_out_file, "%s%s\n", p[0] == '\t' ? "" : "\t", p);
1732 : }
1733 : else
1734 : {
1735 65 : location_t save_loc = input_location;
1736 65 : int save_reload_completed = reload_completed;
1737 65 : int save_cse_not_expected = cse_not_expected;
1738 65 : input_location = EXPR_LOCATION (asm_str);
1739 65 : int noutputs = list_length (ASM_OUTPUTS (asm_str));
1740 65 : int ninputs = list_length (ASM_INPUTS (asm_str));
1741 65 : const char **constraints = NULL;
1742 65 : int i;
1743 65 : tree tail;
1744 65 : bool allows_mem, allows_reg, is_inout;
1745 65 : rtx *ops = NULL;
1746 65 : if (noutputs + ninputs > MAX_RECOG_OPERANDS)
1747 : {
1748 0 : error ("more than %d operands in %<asm%>", MAX_RECOG_OPERANDS);
1749 0 : goto done;
1750 : }
1751 65 : constraints = XALLOCAVEC (const char *, noutputs + ninputs);
1752 65 : ops = XALLOCAVEC (rtx, noutputs + ninputs);
1753 65 : recog_data.n_operands = ninputs + noutputs;
1754 65 : recog_data.n_dups = 0;
1755 65 : recog_data.n_alternatives = 0;
1756 65 : recog_data.is_asm = true;
1757 65 : reload_completed = 0;
1758 65 : cse_not_expected = 1;
1759 69 : for (i = 0, tail = ASM_OUTPUTS (asm_str); tail;
1760 4 : ++i, tail = TREE_CHAIN (tail))
1761 : {
1762 16 : tree output = TREE_VALUE (tail);
1763 16 : if (output == error_mark_node)
1764 0 : goto done;
1765 32 : constraints[i]
1766 16 : = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
1767 16 : if (!parse_output_constraint (&constraints[i], i, ninputs, noutputs,
1768 : &allows_mem, &allows_reg, &is_inout,
1769 : nullptr))
1770 0 : goto done;
1771 16 : if (is_inout)
1772 : {
1773 4 : error ("%qc in output operand outside of a function", '+');
1774 4 : goto done;
1775 : }
1776 12 : if (strchr (constraints[i], '&'))
1777 : {
1778 4 : error ("%qc in output operand outside of a function", '&');
1779 4 : goto done;
1780 : }
1781 8 : if (strchr (constraints[i], '%'))
1782 : {
1783 4 : error ("%qc in output operand outside of a function", '%');
1784 4 : goto done;
1785 : }
1786 4 : output_addressed_constants (output, 0);
1787 4 : if (!is_gimple_addressable (output))
1788 : {
1789 0 : error ("output number %d not directly addressable", i);
1790 0 : goto done;
1791 : }
1792 4 : ops[i] = expand_expr (build_fold_addr_expr (output), NULL_RTX,
1793 : VOIDmode, EXPAND_INITIALIZER);
1794 4 : ops[i] = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (output)), ops[i]);
1795 :
1796 4 : recog_data.operand[i] = ops[i];
1797 4 : recog_data.operand_loc[i] = &ops[i];
1798 4 : recog_data.constraints[i] = constraints[i];
1799 4 : recog_data.operand_mode[i] = TYPE_MODE (TREE_TYPE (output));
1800 : }
1801 186 : for (i = 0, tail = ASM_INPUTS (asm_str); tail;
1802 133 : ++i, tail = TREE_CHAIN (tail))
1803 : {
1804 137 : tree input = TREE_VALUE (tail);
1805 137 : if (input == error_mark_node)
1806 0 : goto done;
1807 274 : constraints[i + noutputs]
1808 137 : = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
1809 137 : if (!parse_input_constraint (&constraints[i + noutputs], i,
1810 : ninputs, noutputs, 0, constraints,
1811 : &allows_mem, &allows_reg, nullptr))
1812 0 : goto done;
1813 137 : if (strchr (constraints[i], '%'))
1814 : {
1815 4 : error ("%qc in input operand outside of a function", '%');
1816 4 : goto done;
1817 : }
1818 133 : const char *constraint = constraints[i + noutputs];
1819 133 : size_t c_len = strlen (constraint);
1820 298 : for (size_t j = 0; j < c_len;
1821 165 : j += CONSTRAINT_LEN (constraint[j], constraint + j))
1822 165 : if (constraint[j] >= '0' && constraint[j] <= '9')
1823 : {
1824 0 : error ("matching constraint outside of a function");
1825 0 : goto done;
1826 : }
1827 133 : output_addressed_constants (input, 0);
1828 133 : if (allows_mem && is_gimple_addressable (input))
1829 : {
1830 8 : ops[i + noutputs]
1831 8 : = expand_expr (build_fold_addr_expr (input), NULL_RTX,
1832 : VOIDmode, EXPAND_INITIALIZER);
1833 8 : ops[i + noutputs] = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (input)),
1834 : ops[i + noutputs]);
1835 : }
1836 : else
1837 125 : ops[i + noutputs] = expand_expr (input, NULL_RTX, VOIDmode,
1838 : EXPAND_INITIALIZER);
1839 133 : if (asm_operand_ok (ops[i + noutputs], constraint, NULL) <= 0)
1840 : {
1841 0 : if (!allows_mem)
1842 0 : warning (0, "%<asm%> operand %d probably does not "
1843 : "match constraints", i + noutputs);
1844 : }
1845 133 : recog_data.operand[i + noutputs] = ops[i + noutputs];
1846 133 : recog_data.operand_loc[i + noutputs] = &ops[i + noutputs];
1847 133 : recog_data.constraints[i + noutputs] = constraints[i + noutputs];
1848 266 : recog_data.operand_mode[i + noutputs]
1849 133 : = TYPE_MODE (TREE_TYPE (input));
1850 : }
1851 49 : if (recog_data.n_operands > 0)
1852 : {
1853 49 : const char *p = recog_data.constraints[0];
1854 49 : recog_data.n_alternatives = 1;
1855 102 : while (*p)
1856 53 : recog_data.n_alternatives += (*p++ == ',');
1857 : }
1858 186 : for (i = 0; i < recog_data.n_operands; i++)
1859 : {
1860 137 : recog_data.operand_type[i]
1861 137 : = recog_data.constraints[i][0] == '=' ? OP_OUT : OP_IN;
1862 137 : recog_data.is_operator[i] = false;
1863 : }
1864 49 : reload_completed = 1;
1865 49 : constrain_operands (1, ALL_ALTERNATIVES);
1866 49 : if (which_alternative < 0)
1867 : {
1868 0 : error ("impossible constraint in %<asm%>");
1869 0 : goto done;
1870 : }
1871 49 : this_is_asm_operands = make_insn_raw (gen_nop ());
1872 49 : insn_noperands = recog_data.n_operands;
1873 49 : if (TREE_STRING_POINTER (ASM_STRING (asm_str))[0])
1874 : {
1875 49 : app_enable ();
1876 49 : output_asm_insn (TREE_STRING_POINTER (ASM_STRING (asm_str)), ops);
1877 : }
1878 49 : insn_noperands = 0;
1879 49 : this_is_asm_operands = NULL;
1880 :
1881 65 : done:
1882 65 : input_location = save_loc;
1883 65 : reload_completed = save_reload_completed;
1884 65 : cse_not_expected = save_cse_not_expected;
1885 : }
1886 12485 : }
1887 :
1888 : /* Write the address of the entity given by SYMBOL to SEC. */
1889 : void
1890 25008 : assemble_addr_to_section (rtx symbol, section *sec)
1891 : {
1892 25008 : switch_to_section (sec);
1893 25417 : assemble_align (POINTER_SIZE);
1894 25826 : assemble_integer (symbol, POINTER_SIZE_UNITS, POINTER_SIZE, 1);
1895 25008 : }
1896 :
1897 : /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1898 : not) section for PRIORITY. */
1899 : section *
1900 0 : get_cdtor_priority_section (int priority, bool constructor_p)
1901 : {
1902 : /* Buffer conservatively large enough for the full range of a 32-bit
1903 : int plus the text below. */
1904 0 : char buf[18];
1905 :
1906 : /* ??? This only works reliably with the GNU linker. */
1907 0 : sprintf (buf, "%s.%.5u",
1908 : constructor_p ? ".ctors" : ".dtors",
1909 : /* Invert the numbering so the linker puts us in the proper
1910 : order; constructors are run from right to left, and the
1911 : linker sorts in increasing order. */
1912 : MAX_INIT_PRIORITY - priority);
1913 0 : return get_section (buf, SECTION_WRITE, NULL);
1914 : }
1915 :
1916 : void
1917 0 : default_named_section_asm_out_destructor (rtx symbol, int priority)
1918 : {
1919 0 : section *sec;
1920 :
1921 0 : if (priority != DEFAULT_INIT_PRIORITY)
1922 0 : sec = get_cdtor_priority_section (priority,
1923 : /*constructor_p=*/false);
1924 : else
1925 0 : sec = get_section (".dtors", SECTION_WRITE, NULL);
1926 :
1927 0 : assemble_addr_to_section (symbol, sec);
1928 0 : }
1929 :
1930 : #ifdef DTORS_SECTION_ASM_OP
1931 : void
1932 : default_dtor_section_asm_out_destructor (rtx symbol,
1933 : int priority ATTRIBUTE_UNUSED)
1934 : {
1935 : assemble_addr_to_section (symbol, dtors_section);
1936 : }
1937 : #endif
1938 :
1939 : void
1940 0 : default_named_section_asm_out_constructor (rtx symbol, int priority)
1941 : {
1942 0 : section *sec;
1943 :
1944 0 : if (priority != DEFAULT_INIT_PRIORITY)
1945 0 : sec = get_cdtor_priority_section (priority,
1946 : /*constructor_p=*/true);
1947 : else
1948 0 : sec = get_section (".ctors", SECTION_WRITE, NULL);
1949 :
1950 0 : assemble_addr_to_section (symbol, sec);
1951 0 : }
1952 :
1953 : #ifdef CTORS_SECTION_ASM_OP
1954 : void
1955 : default_ctor_section_asm_out_constructor (rtx symbol,
1956 : int priority ATTRIBUTE_UNUSED)
1957 : {
1958 : assemble_addr_to_section (symbol, ctors_section);
1959 : }
1960 : #endif
1961 :
1962 : /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1963 : a nonzero value if the constant pool should be output before the
1964 : start of the function, or a zero value if the pool should output
1965 : after the end of the function. The default is to put it before the
1966 : start. */
1967 :
1968 : #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1969 : #define CONSTANT_POOL_BEFORE_FUNCTION 1
1970 : #endif
1971 :
1972 : /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1973 : to be output to assembler.
1974 : Set first_global_object_name and weak_global_object_name as appropriate. */
1975 :
1976 : void
1977 128605759 : notice_global_symbol (tree decl)
1978 : {
1979 244459 : const char **t = &first_global_object_name;
1980 :
1981 128605759 : if (first_global_object_name
1982 86854948 : || !TREE_PUBLIC (decl)
1983 85950662 : || DECL_EXTERNAL (decl)
1984 23457264 : || !DECL_NAME (decl)
1985 23457186 : || (VAR_P (decl) && DECL_HARD_REGISTER (decl))
1986 152062905 : || (TREE_CODE (decl) != FUNCTION_DECL
1987 16185029 : && (!VAR_P (decl)
1988 16185029 : || (DECL_COMMON (decl)
1989 9069 : && (DECL_INITIAL (decl) == 0
1990 8773 : || DECL_INITIAL (decl) == error_mark_node)))))
1991 : return;
1992 :
1993 : /* We win when global object is found, but it is useful to know about weak
1994 : symbol as well so we can produce nicer unique names. */
1995 23456850 : if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1996 23212391 : t = &weak_global_object_name;
1997 :
1998 23456850 : if (!*t)
1999 : {
2000 283384 : tree id = DECL_ASSEMBLER_NAME (decl);
2001 283384 : ultimate_transparent_alias_target (&id);
2002 283384 : *t = ggc_strdup (targetm.strip_name_encoding (IDENTIFIER_POINTER (id)));
2003 : }
2004 : }
2005 :
2006 : /* If not using flag_reorder_blocks_and_partition, decide early whether the
2007 : current function goes into the cold section, so that targets can use
2008 : current_function_section during RTL expansion. DECL describes the
2009 : function. */
2010 :
2011 : void
2012 1523694 : decide_function_section (tree decl)
2013 : {
2014 1523694 : first_function_block_is_cold = false;
2015 :
2016 1523694 : if (DECL_SECTION_NAME (decl))
2017 : {
2018 8135 : struct cgraph_node *node = cgraph_node::get (current_function_decl);
2019 : /* Calls to function_section rely on first_function_block_is_cold
2020 : being accurate. */
2021 8135 : first_function_block_is_cold = (node
2022 8135 : && node->frequency
2023 8135 : == NODE_FREQUENCY_UNLIKELY_EXECUTED);
2024 : }
2025 :
2026 1523694 : in_cold_section_p = first_function_block_is_cold;
2027 1523694 : }
2028 :
2029 : /* Get the function's name, as described by its RTL. This may be
2030 : different from the DECL_NAME name used in the source file. */
2031 : const char *
2032 1597086 : get_fnname_from_decl (tree decl)
2033 : {
2034 1597086 : rtx x = DECL_RTL (decl);
2035 1597086 : gcc_assert (MEM_P (x));
2036 1597086 : x = XEXP (x, 0);
2037 1597086 : gcc_assert (GET_CODE (x) == SYMBOL_REF);
2038 1597086 : return XSTR (x, 0);
2039 : }
2040 :
2041 : /* Output function label, possibly with accompanying metadata. No additional
2042 : code or data is output after the label. */
2043 :
2044 : void
2045 1588069 : assemble_function_label_raw (FILE *file, const char *name)
2046 : {
2047 1588069 : ASM_OUTPUT_LABEL (file, name);
2048 1588069 : assemble_function_label_final ();
2049 1588069 : }
2050 :
2051 : /* Finish outputting function label. Needs to be called when outputting
2052 : function label without using assemble_function_label_raw (). */
2053 :
2054 : void
2055 1588069 : assemble_function_label_final (void)
2056 : {
2057 1588069 : if ((flag_sanitize & SANITIZE_ADDRESS)
2058 : /* Notify ASAN only about the first function label. */
2059 6603 : && (in_cold_section_p == first_function_block_is_cold)
2060 : /* Do not notify ASAN when called from, e.g., code_end (). */
2061 6428 : && cfun)
2062 6428 : asan_function_start ();
2063 1588069 : }
2064 :
2065 : /* Output assembler code for the constant pool of a function and associated
2066 : with defining the name of the function. DECL describes the function.
2067 : NAME is the function's name. For the constant pool, we use the current
2068 : constant pool data. */
2069 :
2070 : void
2071 1519033 : assemble_start_function (tree decl, const char *fnname)
2072 : {
2073 1519033 : int align;
2074 1519033 : char tmp_label[100];
2075 1519033 : bool hot_label_written = false;
2076 :
2077 1519033 : if (crtl->has_bb_partition)
2078 : {
2079 65368 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
2080 65368 : crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
2081 65368 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
2082 65368 : crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
2083 65368 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
2084 65368 : crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
2085 65368 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
2086 65368 : crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
2087 65368 : const_labelno++;
2088 65368 : cold_function_name = NULL_TREE;
2089 : }
2090 : else
2091 : {
2092 1453665 : crtl->subsections.hot_section_label = NULL;
2093 1453665 : crtl->subsections.cold_section_label = NULL;
2094 1453665 : crtl->subsections.hot_section_end_label = NULL;
2095 1453665 : crtl->subsections.cold_section_end_label = NULL;
2096 : }
2097 :
2098 : /* The following code does not need preprocessing in the assembler. */
2099 :
2100 1519033 : app_disable ();
2101 :
2102 1519033 : if (CONSTANT_POOL_BEFORE_FUNCTION)
2103 1519033 : output_constant_pool (fnname, decl);
2104 :
2105 1519033 : align = symtab_node::get (decl)->definition_alignment ();
2106 :
2107 : /* Make sure the not and cold text (code) sections are properly
2108 : aligned. This is necessary here in the case where the function
2109 : has both hot and cold sections, because we don't want to re-set
2110 : the alignment when the section switch happens mid-function. */
2111 :
2112 1519033 : if (crtl->has_bb_partition)
2113 : {
2114 65368 : first_function_block_is_cold = false;
2115 :
2116 65368 : switch_to_section (unlikely_text_section ());
2117 65368 : assemble_align (align);
2118 65368 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
2119 :
2120 : /* When the function starts with a cold section, we need to explicitly
2121 : align the hot section and write out the hot section label.
2122 : But if the current function is a thunk, we do not have a CFG. */
2123 65368 : if (!cfun->is_thunk
2124 65368 : && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb) == BB_COLD_PARTITION)
2125 : {
2126 0 : switch_to_section (text_section);
2127 0 : assemble_align (align);
2128 0 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
2129 0 : hot_label_written = true;
2130 0 : first_function_block_is_cold = true;
2131 : }
2132 65368 : in_cold_section_p = first_function_block_is_cold;
2133 : }
2134 :
2135 :
2136 : /* Switch to the correct text section for the start of the function. */
2137 :
2138 1519033 : switch_to_section (function_section (decl), decl);
2139 1519033 : if (crtl->has_bb_partition && !hot_label_written)
2140 65368 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
2141 :
2142 : /* Tell assembler to move to target machine's alignment for functions. */
2143 1519033 : align = floor_log2 (align / BITS_PER_UNIT);
2144 : /* Handle forced alignment. This really ought to apply to all functions,
2145 : since it is used by patchable entries. */
2146 1519033 : if (flag_min_function_alignment)
2147 0 : align = MAX (align, floor_log2 (flag_min_function_alignment));
2148 :
2149 1519033 : if (align > 0)
2150 : {
2151 173931 : ASM_OUTPUT_ALIGN (asm_out_file, align);
2152 : }
2153 :
2154 : /* Handle a user-specified function alignment.
2155 : Note that we still need to align to DECL_ALIGN, as above,
2156 : because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
2157 1519033 : if (! DECL_USER_ALIGN (decl)
2158 1518999 : && align_functions.levels[0].log > align
2159 2454677 : && optimize_function_for_speed_p (cfun))
2160 : {
2161 : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2162 917007 : int align_log = align_functions.levels[0].log;
2163 : #endif
2164 917007 : int max_skip = align_functions.levels[0].maxskip;
2165 917007 : if (flag_limit_function_alignment && crtl->max_insn_address > 0
2166 1 : && max_skip >= crtl->max_insn_address)
2167 1 : max_skip = crtl->max_insn_address - 1;
2168 :
2169 : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2170 917007 : ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file, align_log, max_skip);
2171 917007 : if (max_skip == align_functions.levels[0].maxskip)
2172 917006 : ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
2173 : align_functions.levels[1].log,
2174 : align_functions.levels[1].maxskip);
2175 : #else
2176 : ASM_OUTPUT_ALIGN (asm_out_file, align_functions.levels[0].log);
2177 : #endif
2178 : }
2179 :
2180 : #ifdef ASM_OUTPUT_FUNCTION_PREFIX
2181 : ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
2182 : #endif
2183 :
2184 1519033 : if (!DECL_IGNORED_P (decl))
2185 1512262 : (*debug_hooks->begin_function) (decl);
2186 :
2187 : /* Make function name accessible from other files, if appropriate. */
2188 :
2189 1519033 : if (TREE_PUBLIC (decl))
2190 : {
2191 1240642 : notice_global_symbol (decl);
2192 :
2193 1240642 : globalize_decl (decl);
2194 :
2195 1240642 : maybe_assemble_visibility (decl);
2196 : }
2197 :
2198 1519033 : if (DECL_PRESERVE_P (decl))
2199 5126 : targetm.asm_out.mark_decl_preserved (fnname);
2200 :
2201 1519033 : unsigned short patch_area_size = crtl->patch_area_size;
2202 1519033 : unsigned short patch_area_entry = crtl->patch_area_entry;
2203 :
2204 : /* Emit the patching area before the entry label, if any. */
2205 1519033 : if (patch_area_entry > 0)
2206 8 : targetm.asm_out.print_patchable_function_entry (asm_out_file,
2207 : patch_area_entry, true);
2208 :
2209 : /* Do any machine/system dependent processing of the function name. */
2210 : #ifdef ASM_DECLARE_FUNCTION_NAME
2211 1519033 : ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
2212 : #else
2213 : /* Standard thing is just output label for the function. */
2214 : ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
2215 : #endif /* ASM_DECLARE_FUNCTION_NAME */
2216 :
2217 : /* And the area after the label. Record it if we haven't done so yet. */
2218 1519033 : if (patch_area_size > patch_area_entry)
2219 51 : targetm.asm_out.print_patchable_function_entry (asm_out_file,
2220 51 : patch_area_size
2221 51 : - patch_area_entry,
2222 : patch_area_entry == 0);
2223 :
2224 1519033 : if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))
2225 2458 : saw_no_split_stack = true;
2226 1519033 : }
2227 :
2228 : /* Output assembler code associated with defining the size of the
2229 : function. DECL describes the function. NAME is the function's name. */
2230 :
2231 : void
2232 1519033 : assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
2233 : {
2234 : #ifdef ASM_DECLARE_FUNCTION_SIZE
2235 : /* We could have switched section in the middle of the function. */
2236 1519033 : if (crtl->has_bb_partition)
2237 65368 : switch_to_section (function_section (decl));
2238 1519033 : ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
2239 : #endif
2240 1519033 : if (! CONSTANT_POOL_BEFORE_FUNCTION)
2241 : {
2242 : output_constant_pool (fnname, decl);
2243 : switch_to_section (function_section (decl)); /* need to switch back */
2244 : }
2245 : /* Output labels for end of hot/cold text sections (to be used by
2246 : debug info.) */
2247 1519033 : if (crtl->has_bb_partition)
2248 : {
2249 65368 : section *save_text_section;
2250 :
2251 65368 : save_text_section = in_section;
2252 65368 : switch_to_section (unlikely_text_section ());
2253 : #ifdef ASM_DECLARE_COLD_FUNCTION_SIZE
2254 65368 : if (cold_function_name != NULL_TREE)
2255 65368 : ASM_DECLARE_COLD_FUNCTION_SIZE (asm_out_file,
2256 : IDENTIFIER_POINTER (cold_function_name),
2257 : decl);
2258 : #endif
2259 65368 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
2260 65368 : if (first_function_block_is_cold)
2261 0 : switch_to_section (text_section);
2262 : else
2263 65368 : switch_to_section (function_section (decl));
2264 65368 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
2265 65368 : switch_to_section (save_text_section);
2266 : }
2267 1519033 : }
2268 :
2269 : /* Assemble code to leave SIZE bytes of zeros. */
2270 :
2271 : void
2272 1053511 : assemble_zeros (unsigned HOST_WIDE_INT size)
2273 : {
2274 : /* Do no output if -fsyntax-only. */
2275 1053511 : if (flag_syntax_only)
2276 : return;
2277 :
2278 : #ifdef ASM_NO_SKIP_IN_TEXT
2279 : /* The `space' pseudo in the text section outputs nop insns rather than 0s,
2280 : so we must output 0s explicitly in the text section. */
2281 1053511 : if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
2282 : {
2283 : unsigned HOST_WIDE_INT i;
2284 0 : for (i = 0; i < size; i++)
2285 0 : assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
2286 : }
2287 : else
2288 : #endif
2289 1053511 : if (size > 0)
2290 981905 : ASM_OUTPUT_SKIP (asm_out_file, size);
2291 : }
2292 :
2293 : /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
2294 :
2295 : void
2296 391531 : assemble_align (unsigned int align)
2297 : {
2298 391531 : if (align > BITS_PER_UNIT)
2299 : {
2300 331532 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2301 : }
2302 391531 : }
2303 :
2304 : /* Assemble a string constant with the specified C string as contents. */
2305 :
2306 : void
2307 33796436 : assemble_string (const char *p, int size)
2308 : {
2309 33796436 : int pos = 0;
2310 : #if defined(BASE64_ASM_OP) \
2311 : && BITS_PER_UNIT == 8 \
2312 : && CHAR_BIT == 8 \
2313 : && 'A' == 65 \
2314 : && 'a' == 97 \
2315 : && '0' == 48 \
2316 : && '+' == 43 \
2317 : && '/' == 47 \
2318 : && '=' == 61
2319 33796436 : int maximum = 16384;
2320 : #else
2321 : int maximum = 2000;
2322 : #endif
2323 :
2324 : /* If the string is very long, split it up. */
2325 :
2326 67588938 : while (pos < size)
2327 : {
2328 33792502 : int thissize = size - pos;
2329 33792502 : if (thissize > maximum)
2330 : thissize = maximum;
2331 :
2332 33792502 : ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
2333 :
2334 33792502 : pos += thissize;
2335 33792502 : p += thissize;
2336 : }
2337 33796436 : }
2338 :
2339 :
2340 : /* A noswitch_section_callback for lcomm_section. */
2341 :
2342 : static bool
2343 158978 : emit_local (tree decl ATTRIBUTE_UNUSED,
2344 : const char *name ATTRIBUTE_UNUSED,
2345 : unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2346 : unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2347 : {
2348 : #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
2349 158978 : unsigned int align = symtab_node::get (decl)->definition_alignment ();
2350 158978 : ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
2351 : size, align);
2352 158978 : return true;
2353 : #elif defined ASM_OUTPUT_ALIGNED_LOCAL
2354 : unsigned int align = symtab_node::get (decl)->definition_alignment ();
2355 : ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, align);
2356 : return true;
2357 : #else
2358 : ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2359 : return false;
2360 : #endif
2361 : }
2362 :
2363 : /* A noswitch_section_callback for bss_noswitch_section. */
2364 :
2365 : #if defined ASM_OUTPUT_ALIGNED_BSS
2366 : static bool
2367 772456 : emit_bss (tree decl ATTRIBUTE_UNUSED,
2368 : const char *name ATTRIBUTE_UNUSED,
2369 : unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2370 : unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2371 : {
2372 772456 : ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
2373 : get_variable_align (decl));
2374 772456 : return true;
2375 : }
2376 : #endif
2377 :
2378 : /* A noswitch_section_callback for comm_section. */
2379 :
2380 : static bool
2381 1302 : emit_common (tree decl ATTRIBUTE_UNUSED,
2382 : const char *name ATTRIBUTE_UNUSED,
2383 : unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2384 : unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2385 : {
2386 : #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
2387 1302 : ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
2388 1302 : size, get_variable_align (decl));
2389 1302 : return true;
2390 : #elif defined ASM_OUTPUT_ALIGNED_COMMON
2391 : ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
2392 : get_variable_align (decl));
2393 : return true;
2394 : #else
2395 : ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
2396 : return false;
2397 : #endif
2398 : }
2399 :
2400 : /* A noswitch_section_callback for tls_comm_section. */
2401 :
2402 : static bool
2403 60 : emit_tls_common (tree decl ATTRIBUTE_UNUSED,
2404 : const char *name ATTRIBUTE_UNUSED,
2405 : unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2406 : unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2407 : {
2408 : #ifdef ASM_OUTPUT_TLS_COMMON
2409 60 : ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
2410 60 : return true;
2411 : #else
2412 : sorry ("thread-local COMMON data not implemented");
2413 : return true;
2414 : #endif
2415 : }
2416 :
2417 : /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2418 : NAME is the name of DECL's SYMBOL_REF. */
2419 :
2420 : static void
2421 932796 : assemble_noswitch_variable (tree decl, const char *name, section *sect,
2422 : unsigned int align)
2423 : {
2424 932796 : unsigned HOST_WIDE_INT size, rounded;
2425 :
2426 932796 : size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
2427 932796 : rounded = size;
2428 :
2429 932796 : if ((flag_sanitize & SANITIZE_ADDRESS) && asan_protect_global (decl))
2430 1966 : size += asan_red_zone_size (size);
2431 :
2432 : /* Don't allocate zero bytes of common,
2433 : since that means "undefined external" in the linker. */
2434 932796 : if (size == 0)
2435 1605 : rounded = 1;
2436 :
2437 : /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2438 : so that each uninitialized object starts on such a boundary. */
2439 932796 : rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
2440 932796 : rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2441 932796 : * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2442 :
2443 932796 : if (!sect->noswitch.callback (decl, name, size, rounded)
2444 932796 : && (unsigned HOST_WIDE_INT) (align / BITS_PER_UNIT) > rounded)
2445 0 : error ("requested alignment for %q+D is greater than "
2446 : "implemented alignment of %wu", decl, rounded);
2447 932796 : }
2448 :
2449 : /* A subroutine of assemble_variable. Output the label and contents of
2450 : DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2451 : is as for assemble_variable. */
2452 :
2453 : static void
2454 1925510 : assemble_variable_contents (tree decl, const char *name,
2455 : bool dont_output_data, bool merge_strings)
2456 : {
2457 : /* Do any machine/system dependent processing of the object. */
2458 : #ifdef ASM_DECLARE_OBJECT_NAME
2459 1925510 : last_assemble_variable_decl = decl;
2460 1925510 : ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
2461 : #else
2462 : /* Standard thing is just output label for the object. */
2463 : ASM_OUTPUT_LABEL (asm_out_file, name);
2464 : #endif /* ASM_DECLARE_OBJECT_NAME */
2465 :
2466 1925510 : if (!dont_output_data)
2467 : {
2468 : /* Caller is supposed to use varpool_get_constructor when it wants
2469 : to output the body. */
2470 1921880 : gcc_assert (!in_lto_p || DECL_INITIAL (decl) != error_mark_node);
2471 1921880 : if (DECL_INITIAL (decl)
2472 1909394 : && DECL_INITIAL (decl) != error_mark_node
2473 3831272 : && !initializer_zerop (DECL_INITIAL (decl)))
2474 : /* Output the actual data. */
2475 3652222 : output_constant (DECL_INITIAL (decl),
2476 1826111 : tree_to_uhwi (DECL_SIZE_UNIT (decl)),
2477 : get_variable_align (decl),
2478 : false, merge_strings);
2479 : else
2480 : /* Leave space for it. */
2481 95769 : assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl)));
2482 : /* For mergeable section, make sure the section is zero filled up to
2483 : the entity size of the section. */
2484 1921880 : if (in_section
2485 1921880 : && (in_section->common.flags & SECTION_MERGE)
2486 106 : && tree_fits_uhwi_p (DECL_SIZE_UNIT (decl))
2487 1921880 : && ((in_section->common.flags & SECTION_ENTSIZE)
2488 106 : > tree_to_uhwi (DECL_SIZE_UNIT (decl))))
2489 : {
2490 70 : unsigned HOST_WIDE_INT entsize, declsize;
2491 70 : entsize = (in_section->common.flags & SECTION_ENTSIZE);
2492 70 : declsize = tree_to_uhwi (DECL_SIZE_UNIT (decl));
2493 70 : assemble_zeros (entsize - declsize);
2494 : }
2495 1921880 : targetm.asm_out.decl_end ();
2496 : }
2497 1925510 : }
2498 :
2499 : /* Write out assembly for the variable DECL, which is not defined in
2500 : the current translation unit. */
2501 : void
2502 295947 : assemble_undefined_decl (tree decl)
2503 : {
2504 295947 : const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2505 295947 : targetm.asm_out.assemble_undefined_decl (asm_out_file, name, decl);
2506 295947 : }
2507 :
2508 : /* Assemble everything that is needed for a variable or function declaration.
2509 : Not used for automatic variables, and not used for function definitions.
2510 : Should not be called for variables of incomplete structure type.
2511 :
2512 : TOP_LEVEL is nonzero if this variable has file scope.
2513 : AT_END is nonzero if this is the special handling, at end of compilation,
2514 : to define things that have had only tentative definitions.
2515 : DONT_OUTPUT_DATA if nonzero means don't actually output the
2516 : initial value (that will be done by the caller). */
2517 :
2518 : void
2519 2862843 : assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2520 : int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2521 : {
2522 2862843 : const char *name;
2523 2862843 : rtx decl_rtl, symbol;
2524 2862843 : section *sect;
2525 2862843 : unsigned int align;
2526 2862843 : bool asan_protected = false;
2527 :
2528 : /* This function is supposed to handle VARIABLES. Ensure we have one. */
2529 2862843 : gcc_assert (VAR_P (decl));
2530 :
2531 : /* Emulated TLS had better not get this far. */
2532 2862843 : gcc_checking_assert (targetm.have_tls || !DECL_THREAD_LOCAL_P (decl));
2533 :
2534 2862843 : last_assemble_variable_decl = 0;
2535 :
2536 : /* Normally no need to say anything here for external references,
2537 : since assemble_external is called by the language-specific code
2538 : when a declaration is first seen. */
2539 :
2540 2862843 : if (DECL_EXTERNAL (decl))
2541 : return;
2542 :
2543 : /* Do nothing for global register variables. */
2544 2860429 : if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2545 : {
2546 0 : TREE_ASM_WRITTEN (decl) = 1;
2547 0 : return;
2548 : }
2549 :
2550 : /* If type was incomplete when the variable was declared,
2551 : see if it is complete now. */
2552 :
2553 2860429 : if (DECL_SIZE (decl) == 0)
2554 1 : layout_decl (decl, 0);
2555 :
2556 : /* Still incomplete => don't allocate it; treat the tentative defn
2557 : (which is what it must have been) as an `extern' reference. */
2558 :
2559 2860429 : if (!dont_output_data && DECL_SIZE (decl) == 0)
2560 : {
2561 1 : error ("storage size of %q+D isn%'t known", decl);
2562 1 : TREE_ASM_WRITTEN (decl) = 1;
2563 1 : return;
2564 : }
2565 :
2566 : /* The first declaration of a variable that comes through this function
2567 : decides whether it is global (in C, has external linkage)
2568 : or local (in C, has internal linkage). So do nothing more
2569 : if this function has already run. */
2570 :
2571 2860428 : if (TREE_ASM_WRITTEN (decl))
2572 : return;
2573 :
2574 : /* Make sure targetm.encode_section_info is invoked before we set
2575 : ASM_WRITTEN. */
2576 2860428 : decl_rtl = DECL_RTL (decl);
2577 :
2578 2860428 : TREE_ASM_WRITTEN (decl) = 1;
2579 :
2580 : /* Do no output if -fsyntax-only. */
2581 2860428 : if (flag_syntax_only)
2582 : return;
2583 :
2584 2860428 : if (! dont_output_data
2585 2860428 : && ! valid_constant_size_p (DECL_SIZE_UNIT (decl)))
2586 : {
2587 2 : error ("size of variable %q+D is too large", decl);
2588 2 : return;
2589 : }
2590 :
2591 2860426 : gcc_assert (MEM_P (decl_rtl));
2592 2860426 : gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2593 2860426 : symbol = XEXP (decl_rtl, 0);
2594 :
2595 : /* If this symbol belongs to the tree constant pool, output the constant
2596 : if it hasn't already been written. */
2597 2860426 : if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2598 : {
2599 2120 : tree decl = SYMBOL_REF_DECL (symbol);
2600 2120 : if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2601 1438 : output_constant_def_contents (symbol);
2602 : return;
2603 : }
2604 :
2605 2858306 : app_disable ();
2606 :
2607 2858306 : name = XSTR (symbol, 0);
2608 2858306 : if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2609 1421791 : notice_global_symbol (decl);
2610 :
2611 : /* Compute the alignment of this data. */
2612 :
2613 2858306 : align_variable (decl, dont_output_data);
2614 :
2615 2858306 : if ((flag_sanitize & SANITIZE_ADDRESS)
2616 2858306 : && asan_protect_global (decl))
2617 : {
2618 2496 : asan_protected = true;
2619 2496 : SET_DECL_ALIGN (decl, MAX (DECL_ALIGN (decl),
2620 : ASAN_RED_ZONE_SIZE * BITS_PER_UNIT));
2621 : }
2622 :
2623 2858306 : set_mem_align (decl_rtl, DECL_ALIGN (decl));
2624 :
2625 2858306 : align = get_variable_align (decl);
2626 :
2627 2858306 : if (TREE_PUBLIC (decl))
2628 1422346 : maybe_assemble_visibility (decl);
2629 :
2630 2858306 : if (DECL_PRESERVE_P (decl))
2631 972 : targetm.asm_out.mark_decl_preserved (name);
2632 :
2633 : /* First make the assembler name(s) global if appropriate. */
2634 2858306 : sect = get_variable_section (decl, false);
2635 2858306 : if (TREE_PUBLIC (decl)
2636 1422346 : && (sect->common.flags & SECTION_COMMON) == 0)
2637 1420984 : globalize_decl (decl);
2638 :
2639 : /* Output any data that we will need to use the address of. */
2640 2858306 : if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2641 1935127 : output_addressed_constants (DECL_INITIAL (decl), 0);
2642 :
2643 : /* dbxout.cc needs to know this. */
2644 2858306 : if (sect && (sect->common.flags & SECTION_CODE) != 0)
2645 0 : DECL_IN_TEXT_SECTION (decl) = 1;
2646 :
2647 : /* If the decl is part of an object_block, make sure that the decl
2648 : has been positioned within its block, but do not write out its
2649 : definition yet. output_object_blocks will do that later. */
2650 2858306 : if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2651 : {
2652 0 : gcc_assert (!dont_output_data);
2653 0 : place_block_symbol (symbol);
2654 : }
2655 2858306 : else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2656 932796 : assemble_noswitch_variable (decl, name, sect, align);
2657 : else
2658 : {
2659 : /* Special-case handling of vtv comdat sections. */
2660 1925510 : if (SECTION_STYLE (sect) == SECTION_NAMED
2661 1539757 : && (strcmp (sect->named.name, ".vtable_map_vars") == 0))
2662 3 : handle_vtv_comdat_section (sect, decl);
2663 : else
2664 1925507 : switch_to_section (sect, decl);
2665 1925510 : if (align > BITS_PER_UNIT)
2666 1838849 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2667 1925510 : assemble_variable_contents (decl, name, dont_output_data,
2668 1925510 : (sect->common.flags & SECTION_MERGE)
2669 106 : && (sect->common.flags & SECTION_STRINGS));
2670 1925510 : if (asan_protected)
2671 : {
2672 1462 : unsigned HOST_WIDE_INT int size
2673 1462 : = tree_to_uhwi (DECL_SIZE_UNIT (decl));
2674 2770 : assemble_zeros (asan_red_zone_size (size));
2675 : }
2676 : }
2677 : }
2678 :
2679 : /* Return true if type TYPE contains any pointers. */
2680 :
2681 : static bool
2682 2 : contains_pointers_p (tree type)
2683 : {
2684 2 : switch (TREE_CODE (type))
2685 : {
2686 : case POINTER_TYPE:
2687 : case REFERENCE_TYPE:
2688 : /* I'm not sure whether OFFSET_TYPE needs this treatment,
2689 : so I'll play safe and return 1. */
2690 : case OFFSET_TYPE:
2691 : return true;
2692 :
2693 0 : case RECORD_TYPE:
2694 0 : case UNION_TYPE:
2695 0 : case QUAL_UNION_TYPE:
2696 0 : {
2697 0 : tree fields;
2698 : /* For a type that has fields, see if the fields have pointers. */
2699 0 : for (fields = TYPE_FIELDS (type); fields; fields = DECL_CHAIN (fields))
2700 0 : if (TREE_CODE (fields) == FIELD_DECL
2701 0 : && contains_pointers_p (TREE_TYPE (fields)))
2702 : return true;
2703 : return false;
2704 : }
2705 :
2706 0 : case ARRAY_TYPE:
2707 : /* An array type contains pointers if its element type does. */
2708 0 : return contains_pointers_p (TREE_TYPE (type));
2709 :
2710 : default:
2711 : return false;
2712 : }
2713 : }
2714 :
2715 : /* We delay assemble_external processing until
2716 : the compilation unit is finalized. This is the best we can do for
2717 : right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2718 : it all the way to final. See PR 17982 for further discussion. */
2719 : static GTY(()) tree pending_assemble_externals;
2720 :
2721 : /* A similar list of pending libcall symbols. We only want to declare
2722 : symbols that are actually used in the final assembly. */
2723 : static GTY(()) rtx pending_libcall_symbols;
2724 :
2725 : #ifdef ASM_OUTPUT_EXTERNAL
2726 : /* Some targets delay some output to final using TARGET_ASM_FILE_END.
2727 : As a result, assemble_external can be called after the list of externals
2728 : is processed and the pointer set destroyed. */
2729 : static bool pending_assemble_externals_processed;
2730 :
2731 : /* Avoid O(external_decls**2) lookups in the pending_assemble_externals
2732 : TREE_LIST in assemble_external. */
2733 : static hash_set<tree> *pending_assemble_externals_set;
2734 :
2735 : /* True if DECL is a function decl for which no out-of-line copy exists.
2736 : It is assumed that DECL's assembler name has been set. */
2737 :
2738 : static bool
2739 1826462 : incorporeal_function_p (tree decl)
2740 : {
2741 1826462 : if (TREE_CODE (decl) == FUNCTION_DECL && fndecl_built_in_p (decl))
2742 : {
2743 203623 : const char *name;
2744 :
2745 203623 : if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2746 203623 : && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl)))
2747 : return true;
2748 :
2749 203618 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2750 : /* Atomic or sync builtins which have survived this far will be
2751 : resolved externally and therefore are not incorporeal. */
2752 203618 : if (startswith (name, "__builtin_"))
2753 : return true;
2754 : }
2755 : return false;
2756 : }
2757 :
2758 : /* Actually do the tests to determine if this is necessary, and invoke
2759 : ASM_OUTPUT_EXTERNAL. */
2760 : static void
2761 1838288 : assemble_external_real (tree decl)
2762 : {
2763 1838288 : rtx rtl = DECL_RTL (decl);
2764 :
2765 1838288 : if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2766 1838288 : && !SYMBOL_REF_USED (XEXP (rtl, 0))
2767 3664750 : && !incorporeal_function_p (decl))
2768 : {
2769 : /* Some systems do require some output. */
2770 1826457 : SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2771 1826457 : ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2772 : }
2773 1838288 : }
2774 : #endif
2775 :
2776 : void
2777 239445 : process_pending_assemble_externals (void)
2778 : {
2779 : #ifdef ASM_OUTPUT_EXTERNAL
2780 239445 : tree list;
2781 2077733 : for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2782 1838288 : assemble_external_real (TREE_VALUE (list));
2783 :
2784 266904 : for (rtx list = pending_libcall_symbols; list; list = XEXP (list, 1))
2785 : {
2786 27459 : rtx symbol = XEXP (list, 0);
2787 27459 : const char *name = targetm.strip_name_encoding (XSTR (symbol, 0));
2788 27459 : tree id = get_identifier (name);
2789 27459 : if (TREE_SYMBOL_REFERENCED (id))
2790 27393 : targetm.asm_out.external_libcall (symbol);
2791 : }
2792 :
2793 239445 : pending_assemble_externals = 0;
2794 239445 : pending_assemble_externals_processed = true;
2795 239445 : pending_libcall_symbols = NULL_RTX;
2796 478890 : delete pending_assemble_externals_set;
2797 239445 : pending_assemble_externals_set = nullptr;
2798 : #endif
2799 239445 : }
2800 :
2801 : /* This TREE_LIST contains any weak symbol declarations waiting
2802 : to be emitted. */
2803 : static GTY(()) tree weak_decls;
2804 :
2805 : /* Output something to declare an external symbol to the assembler,
2806 : and qualifiers such as weakness. (Most assemblers don't need
2807 : extern declaration, so we normally output nothing.) Do nothing if
2808 : DECL is not external. */
2809 :
2810 : void
2811 42002031 : assemble_external (tree decl ATTRIBUTE_UNUSED)
2812 : {
2813 : /* Make sure that the ASM_OUT_FILE is open.
2814 : If it's not, we should not be calling this function. */
2815 42002031 : gcc_assert (asm_out_file);
2816 :
2817 : /* In a perfect world, the following condition would be true.
2818 : Sadly, the Go front end emit assembly *from the front end*,
2819 : bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2820 : #if 0
2821 : /* This function should only be called if we are expanding, or have
2822 : expanded, to RTL.
2823 : Ideally, only final.cc would be calling this function, but it is
2824 : not clear whether that would break things somehow. See PR 17982
2825 : for further discussion. */
2826 : gcc_assert (state == EXPANSION
2827 : || state == FINISHED);
2828 : #endif
2829 :
2830 42002031 : if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2831 : return;
2832 :
2833 : /* We want to output annotation for weak and external symbols at
2834 : very last to check if they are references or not. */
2835 :
2836 18227334 : if (TARGET_SUPPORTS_WEAK
2837 18227334 : && DECL_WEAK (decl)
2838 : /* TREE_STATIC is a weird and abused creature which is not
2839 : generally the right test for whether an entity has been
2840 : locally emitted, inlined or otherwise not-really-extern, but
2841 : for declarations that can be weak, it happens to be
2842 : match. */
2843 12984 : && !TREE_STATIC (decl)
2844 5315 : && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2845 18232186 : && value_member (decl, weak_decls) == NULL_TREE)
2846 1012 : weak_decls = tree_cons (NULL, decl, weak_decls);
2847 :
2848 : #ifdef ASM_OUTPUT_EXTERNAL
2849 18227334 : if (pending_assemble_externals_processed)
2850 : {
2851 0 : assemble_external_real (decl);
2852 0 : return;
2853 : }
2854 :
2855 18227334 : if (! pending_assemble_externals_set->add (decl))
2856 1838334 : pending_assemble_externals = tree_cons (NULL, decl,
2857 : pending_assemble_externals);
2858 : #endif
2859 : }
2860 :
2861 : /* Similar, for calling a library function FUN. */
2862 :
2863 : void
2864 204305 : assemble_external_libcall (rtx fun)
2865 : {
2866 : /* Declare library function name external when first used, if nec. */
2867 204305 : if (! SYMBOL_REF_USED (fun))
2868 : {
2869 : #ifdef ASM_OUTPUT_EXTERNAL
2870 27469 : gcc_assert (!pending_assemble_externals_processed);
2871 : #endif
2872 27469 : SYMBOL_REF_USED (fun) = 1;
2873 : /* Make sure the libcall symbol is in the symtab so any
2874 : reference to it will mark its tree node as referenced, via
2875 : assemble_name_resolve. These are eventually emitted, if
2876 : used, in process_pending_assemble_externals. */
2877 27469 : const char *name = targetm.strip_name_encoding (XSTR (fun, 0));
2878 27469 : get_identifier (name);
2879 27469 : pending_libcall_symbols = gen_rtx_EXPR_LIST (VOIDmode, fun,
2880 : pending_libcall_symbols);
2881 : }
2882 204305 : }
2883 :
2884 : /* Assemble a label named NAME. */
2885 :
2886 : void
2887 1285609 : assemble_label (FILE *file, const char *name)
2888 : {
2889 1285609 : ASM_OUTPUT_LABEL (file, name);
2890 1285609 : }
2891 :
2892 : /* Set the symbol_referenced flag for ID. */
2893 : void
2894 35334964 : mark_referenced (tree id)
2895 : {
2896 35334964 : TREE_SYMBOL_REFERENCED (id) = 1;
2897 35334964 : }
2898 :
2899 : /* Set the symbol_referenced flag for DECL and notify callgraph. */
2900 : void
2901 5854 : mark_decl_referenced (tree decl)
2902 : {
2903 5854 : if (TREE_CODE (decl) == FUNCTION_DECL)
2904 : {
2905 : /* Extern inline functions don't become needed when referenced.
2906 : If we know a method will be emitted in other TU and no new
2907 : functions can be marked reachable, just use the external
2908 : definition. */
2909 5852 : struct cgraph_node *node = cgraph_node::get_create (decl);
2910 5852 : if (!DECL_EXTERNAL (decl)
2911 5852 : && !node->definition)
2912 12 : node->mark_force_output ();
2913 : }
2914 2 : else if (VAR_P (decl))
2915 : {
2916 2 : varpool_node *node = varpool_node::get_create (decl);
2917 : /* C++ frontend use mark_decl_references to force COMDAT variables
2918 : to be output that might appear dead otherwise. */
2919 2 : node->force_output = true;
2920 : }
2921 : /* else do nothing - we can get various sorts of CST nodes here,
2922 : which do not need to be marked. */
2923 5854 : }
2924 :
2925 :
2926 : /* Output to FILE (an assembly file) a reference to NAME. If NAME
2927 : starts with a *, the rest of NAME is output verbatim. Otherwise
2928 : NAME is transformed in a target-specific way (usually by the
2929 : addition of an underscore). */
2930 :
2931 : void
2932 491351286 : assemble_name_raw (FILE *file, const char *name)
2933 : {
2934 491351286 : if (name[0] == '*')
2935 455696204 : fputs (&name[1], file);
2936 : else
2937 35655082 : ASM_OUTPUT_LABELREF (file, name);
2938 491351286 : }
2939 :
2940 : /* Return NAME that should actually be emitted, looking through
2941 : transparent aliases. If NAME refers to an entity that is also
2942 : represented as a tree (like a function or variable), mark the entity
2943 : as referenced. */
2944 : const char *
2945 413875043 : assemble_name_resolve (const char *name)
2946 : {
2947 413875043 : const char *real_name = targetm.strip_name_encoding (name);
2948 413875043 : tree id = maybe_get_identifier (real_name);
2949 :
2950 413875043 : if (id)
2951 : {
2952 35334964 : tree id_orig = id;
2953 :
2954 35334964 : mark_referenced (id);
2955 35334964 : ultimate_transparent_alias_target (&id);
2956 35334964 : if (id != id_orig)
2957 0 : name = IDENTIFIER_POINTER (id);
2958 35334964 : gcc_assert (!IDENTIFIER_TRANSPARENT_ALIAS (id));
2959 : }
2960 :
2961 413875043 : return name;
2962 : }
2963 :
2964 : /* Like assemble_name_raw, but should be used when NAME might refer to
2965 : an entity that is also represented as a tree (like a function or
2966 : variable). If NAME does refer to such an entity, that entity will
2967 : be marked as referenced. */
2968 :
2969 : void
2970 284754140 : assemble_name (FILE *file, const char *name)
2971 : {
2972 284754140 : assemble_name_raw (file, assemble_name_resolve (name));
2973 284754140 : }
2974 :
2975 : /* Allocate SIZE bytes writable static space with a gensym name
2976 : and return an RTX to refer to its address. */
2977 :
2978 : rtx
2979 0 : assemble_static_space (unsigned HOST_WIDE_INT size)
2980 : {
2981 0 : char name[17];
2982 0 : const char *namestring;
2983 0 : rtx x;
2984 :
2985 0 : ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2986 0 : ++const_labelno;
2987 0 : namestring = ggc_strdup (name);
2988 :
2989 0 : x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2990 0 : SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2991 :
2992 : #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2993 0 : ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2994 : BIGGEST_ALIGNMENT);
2995 : #else
2996 : #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2997 : ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2998 : #else
2999 : {
3000 : /* Round size up to multiple of BIGGEST_ALIGNMENT bits
3001 : so that each uninitialized object starts on such a boundary. */
3002 : /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
3003 : unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
3004 : = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
3005 : / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3006 : * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
3007 : ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
3008 : }
3009 : #endif
3010 : #endif
3011 0 : return x;
3012 : }
3013 :
3014 : /* Assemble the static constant template for function entry trampolines.
3015 : This is done at most once per compilation.
3016 : Returns an RTX for the address of the template. */
3017 :
3018 : static GTY(()) rtx initial_trampoline;
3019 :
3020 : rtx
3021 0 : assemble_trampoline_template (void)
3022 : {
3023 0 : char label[256];
3024 0 : const char *name;
3025 0 : int align;
3026 0 : rtx symbol;
3027 :
3028 0 : gcc_assert (targetm.asm_out.trampoline_template != NULL);
3029 :
3030 0 : if (initial_trampoline)
3031 : return initial_trampoline;
3032 :
3033 : /* By default, put trampoline templates in read-only data section. */
3034 :
3035 : #ifdef TRAMPOLINE_SECTION
3036 : switch_to_section (TRAMPOLINE_SECTION);
3037 : #else
3038 0 : switch_to_section (readonly_data_section);
3039 : #endif
3040 :
3041 : /* Write the assembler code to define one. */
3042 0 : align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
3043 0 : if (align > 0)
3044 0 : ASM_OUTPUT_ALIGN (asm_out_file, align);
3045 :
3046 0 : targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
3047 0 : targetm.asm_out.trampoline_template (asm_out_file);
3048 :
3049 : /* Record the rtl to refer to it. */
3050 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
3051 0 : name = ggc_strdup (label);
3052 0 : symbol = gen_rtx_SYMBOL_REF (Pmode, name);
3053 0 : SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
3054 :
3055 0 : initial_trampoline = gen_const_mem (BLKmode, symbol);
3056 0 : set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
3057 0 : set_mem_size (initial_trampoline, TRAMPOLINE_SIZE);
3058 :
3059 0 : return initial_trampoline;
3060 : }
3061 :
3062 : /* A and B are either alignments or offsets. Return the minimum alignment
3063 : that may be assumed after adding the two together. */
3064 :
3065 : static inline unsigned
3066 15271156 : min_align (unsigned int a, unsigned int b)
3067 : {
3068 15271156 : return least_bit_hwi (a | b);
3069 : }
3070 :
3071 : /* Return the assembler directive for creating a given kind of integer
3072 : object. SIZE is the number of bytes in the object and ALIGNED_P
3073 : indicates whether it is known to be aligned. Return NULL if the
3074 : assembly dialect has no such directive.
3075 :
3076 : The returned string should be printed at the start of a new line and
3077 : be followed immediately by the object's initial value. */
3078 :
3079 : const char *
3080 470194750 : integer_asm_op (int size, int aligned_p)
3081 : {
3082 470194750 : struct asm_int_op *ops;
3083 :
3084 470194750 : if (aligned_p)
3085 : ops = &targetm.asm_out.aligned_op;
3086 : else
3087 455703743 : ops = &targetm.asm_out.unaligned_op;
3088 :
3089 470194750 : switch (size)
3090 : {
3091 239261863 : case 1:
3092 239261863 : return targetm.asm_out.byte_op;
3093 24176847 : case 2:
3094 24176847 : return ops->hi;
3095 0 : case 3:
3096 0 : return ops->psi;
3097 166826315 : case 4:
3098 166826315 : return ops->si;
3099 0 : case 5:
3100 0 : case 6:
3101 0 : case 7:
3102 0 : return ops->pdi;
3103 39902903 : case 8:
3104 39902903 : return ops->di;
3105 0 : case 9:
3106 0 : case 10:
3107 0 : case 11:
3108 0 : case 12:
3109 0 : case 13:
3110 0 : case 14:
3111 0 : case 15:
3112 0 : return ops->pti;
3113 26175 : case 16:
3114 26175 : return ops->ti;
3115 : default:
3116 : return NULL;
3117 : }
3118 : }
3119 :
3120 : /* Use directive OP to assemble an integer object X. Print OP at the
3121 : start of the line, followed immediately by the value of X. */
3122 :
3123 : void
3124 14220700 : assemble_integer_with_op (const char *op, rtx x)
3125 : {
3126 14220700 : fputs (op, asm_out_file);
3127 14220700 : output_addr_const (asm_out_file, x);
3128 14220700 : fputc ('\n', asm_out_file);
3129 14220700 : }
3130 :
3131 : /* The default implementation of the asm_out.integer target hook. */
3132 :
3133 : bool
3134 14519387 : default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
3135 : unsigned int size ATTRIBUTE_UNUSED,
3136 : int aligned_p ATTRIBUTE_UNUSED)
3137 : {
3138 14519387 : const char *op = integer_asm_op (size, aligned_p);
3139 : /* Avoid GAS bugs for large values. Specifically negative values whose
3140 : absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
3141 19508304 : if (size > UNITS_PER_WORD && size > POINTER_SIZE_UNITS)
3142 : return false;
3143 14220700 : return op && (assemble_integer_with_op (op, x), true);
3144 : }
3145 :
3146 : /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
3147 : the alignment of the integer in bits. Return 1 if we were able to output
3148 : the constant, otherwise 0. We must be able to output the constant,
3149 : if FORCE is nonzero. */
3150 :
3151 : bool
3152 14519387 : assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
3153 : {
3154 14519387 : int aligned_p;
3155 :
3156 14519387 : aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
3157 :
3158 : /* See if the target hook can handle this kind of object. */
3159 14519387 : if (targetm.asm_out.integer (x, size, aligned_p))
3160 : return true;
3161 :
3162 : /* If the object is a multi-byte one, try splitting it up. Split
3163 : it into words it if is multi-word, otherwise split it into bytes. */
3164 298687 : if (size > 1)
3165 : {
3166 298687 : machine_mode omode, imode;
3167 298687 : unsigned int subalign;
3168 298687 : unsigned int subsize, i;
3169 298687 : enum mode_class mclass;
3170 :
3171 573717 : subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
3172 298687 : subalign = MIN (align, subsize * BITS_PER_UNIT);
3173 298687 : if (GET_CODE (x) == CONST_FIXED)
3174 0 : mclass = GET_MODE_CLASS (GET_MODE (x));
3175 : else
3176 : mclass = MODE_INT;
3177 :
3178 298687 : omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0).require ();
3179 298687 : imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0).require ();
3180 :
3181 899943 : for (i = 0; i < size; i += subsize)
3182 : {
3183 601256 : rtx partial = simplify_subreg (omode, x, imode, i);
3184 601256 : if (!partial || !assemble_integer (partial, subsize, subalign, 0))
3185 : break;
3186 : }
3187 298687 : if (i == size)
3188 14519387 : return true;
3189 :
3190 : /* If we've printed some of it, but not all of it, there's no going
3191 : back now. */
3192 0 : gcc_assert (!i);
3193 : }
3194 :
3195 0 : gcc_assert (!force);
3196 :
3197 : return false;
3198 : }
3199 :
3200 : /* Assemble the floating-point constant D into an object of size MODE. ALIGN
3201 : is the alignment of the constant in bits. If REVERSE is true, D is output
3202 : in reverse storage order. */
3203 :
3204 : void
3205 809810 : assemble_real (REAL_VALUE_TYPE d, scalar_float_mode mode, unsigned int align,
3206 : bool reverse)
3207 : {
3208 809810 : long data[4] = {0, 0, 0, 0};
3209 809810 : int bitsize, nelts, nunits, units_per;
3210 809810 : rtx elt;
3211 :
3212 : /* This is hairy. We have a quantity of known size. real_to_target
3213 : will put it into an array of *host* longs, 32 bits per element
3214 : (even if long is more than 32 bits). We need to determine the
3215 : number of array elements that are occupied (nelts) and the number
3216 : of *target* min-addressable units that will be occupied in the
3217 : object file (nunits). We cannot assume that 32 divides the
3218 : mode's bitsize (size * BITS_PER_UNIT) evenly.
3219 :
3220 : size * BITS_PER_UNIT is used here to make sure that padding bits
3221 : (which might appear at either end of the value; real_to_target
3222 : will include the padding bits in its output array) are included. */
3223 :
3224 809810 : nunits = GET_MODE_SIZE (mode);
3225 809810 : bitsize = nunits * BITS_PER_UNIT;
3226 809810 : nelts = CEIL (bitsize, 32);
3227 809810 : units_per = 32 / BITS_PER_UNIT;
3228 :
3229 809810 : real_to_target (data, &d, mode);
3230 :
3231 : /* Put out the first word with the specified alignment. */
3232 809810 : unsigned int chunk_nunits = MIN (nunits, units_per);
3233 809810 : if (reverse)
3234 72 : elt = flip_storage_order (SImode, gen_int_mode (data[nelts - 1], SImode));
3235 : else
3236 809738 : elt = GEN_INT (sext_hwi (data[0], chunk_nunits * BITS_PER_UNIT));
3237 809810 : assemble_integer (elt, chunk_nunits, align, 1);
3238 809810 : nunits -= chunk_nunits;
3239 :
3240 : /* Subsequent words need only 32-bit alignment. */
3241 809810 : align = min_align (align, 32);
3242 :
3243 1219820 : for (int i = 1; i < nelts; i++)
3244 : {
3245 410010 : chunk_nunits = MIN (nunits, units_per);
3246 410010 : if (reverse)
3247 18 : elt = flip_storage_order (SImode,
3248 18 : gen_int_mode (data[nelts - 1 - i], SImode));
3249 : else
3250 409992 : elt = GEN_INT (sext_hwi (data[i], chunk_nunits * BITS_PER_UNIT));
3251 410010 : assemble_integer (elt, chunk_nunits, align, 1);
3252 410010 : nunits -= chunk_nunits;
3253 : }
3254 809810 : }
3255 :
3256 : /* Given an expression EXP with a constant value,
3257 : reduce it to the sum of an assembler symbol and an integer.
3258 : Store them both in the structure *VALUE.
3259 : EXP must be reducible. */
3260 :
3261 : class addr_const {
3262 : public:
3263 : rtx base;
3264 : poly_int64 offset;
3265 : };
3266 :
3267 : static void
3268 30094 : decode_addr_const (tree exp, class addr_const *value)
3269 : {
3270 30094 : tree target = TREE_OPERAND (exp, 0);
3271 30094 : poly_int64 offset = 0;
3272 30546 : rtx x;
3273 :
3274 30998 : while (1)
3275 : {
3276 30546 : poly_int64 bytepos;
3277 30546 : if (TREE_CODE (target) == COMPONENT_REF
3278 30546 : && poly_int_tree_p (byte_position (TREE_OPERAND (target, 1)),
3279 : &bytepos))
3280 : {
3281 438 : offset += bytepos;
3282 438 : target = TREE_OPERAND (target, 0);
3283 : }
3284 30108 : else if (TREE_CODE (target) == ARRAY_REF
3285 30108 : || TREE_CODE (target) == ARRAY_RANGE_REF)
3286 : {
3287 : /* Truncate big offset. */
3288 14 : offset
3289 14 : += (TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (target)))
3290 28 : * wi::to_poly_widest (TREE_OPERAND (target, 1)).force_shwi ());
3291 14 : target = TREE_OPERAND (target, 0);
3292 : }
3293 30094 : else if (TREE_CODE (target) == MEM_REF
3294 30094 : && TREE_CODE (TREE_OPERAND (target, 0)) == ADDR_EXPR)
3295 : {
3296 0 : offset += mem_ref_offset (target).force_shwi ();
3297 0 : target = TREE_OPERAND (TREE_OPERAND (target, 0), 0);
3298 : }
3299 30094 : else if (INDIRECT_REF_P (target)
3300 0 : && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
3301 30094 : && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
3302 : == ADDR_EXPR)
3303 0 : target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
3304 : else
3305 : break;
3306 452 : }
3307 :
3308 30094 : switch (TREE_CODE (target))
3309 : {
3310 29992 : case VAR_DECL:
3311 29992 : case FUNCTION_DECL:
3312 29992 : x = DECL_RTL (target);
3313 : break;
3314 :
3315 0 : case LABEL_DECL:
3316 0 : x = gen_rtx_MEM (FUNCTION_MODE,
3317 0 : gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
3318 0 : break;
3319 :
3320 0 : case REAL_CST:
3321 0 : case FIXED_CST:
3322 0 : case STRING_CST:
3323 0 : case COMPLEX_CST:
3324 0 : case CONSTRUCTOR:
3325 0 : case INTEGER_CST:
3326 0 : x = lookup_constant_def (target);
3327 : /* Should have been added by output_addressed_constants. */
3328 0 : gcc_assert (x);
3329 : break;
3330 :
3331 0 : case INDIRECT_REF:
3332 : /* This deals with absolute addresses. */
3333 0 : offset += tree_to_shwi (TREE_OPERAND (target, 0));
3334 0 : x = gen_rtx_MEM (QImode,
3335 0 : gen_rtx_SYMBOL_REF (Pmode, "origin of addresses"));
3336 0 : break;
3337 :
3338 102 : case COMPOUND_LITERAL_EXPR:
3339 102 : gcc_assert (COMPOUND_LITERAL_EXPR_DECL (target));
3340 102 : x = DECL_RTL (COMPOUND_LITERAL_EXPR_DECL (target));
3341 : break;
3342 :
3343 0 : default:
3344 0 : gcc_unreachable ();
3345 : }
3346 :
3347 30094 : gcc_assert (MEM_P (x));
3348 30094 : x = XEXP (x, 0);
3349 :
3350 30094 : value->base = x;
3351 30094 : value->offset = offset;
3352 30094 : }
3353 :
3354 : static GTY(()) hash_table<tree_descriptor_hasher> *const_desc_htab;
3355 :
3356 : static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
3357 :
3358 : /* Constant pool accessor function. */
3359 :
3360 : hash_table<tree_descriptor_hasher> *
3361 2491 : constant_pool_htab (void)
3362 : {
3363 2491 : return const_desc_htab;
3364 : }
3365 :
3366 : /* Compute a hash code for a constant expression. */
3367 :
3368 : hashval_t
3369 9269216 : tree_descriptor_hasher::hash (constant_descriptor_tree *ptr)
3370 : {
3371 9269216 : return ptr->hash;
3372 : }
3373 :
3374 : static hashval_t
3375 5545063 : const_hash_1 (const tree exp)
3376 : {
3377 5819500 : const char *p;
3378 5819500 : hashval_t hi;
3379 5819500 : int len, i;
3380 5819500 : enum tree_code code = TREE_CODE (exp);
3381 :
3382 : /* Either set P and LEN to the address and len of something to hash and
3383 : exit the switch or return a value. */
3384 :
3385 5819500 : switch (code)
3386 : {
3387 699625 : case INTEGER_CST:
3388 699625 : p = (char *) &TREE_INT_CST_ELT (exp, 0);
3389 699625 : len = TREE_INT_CST_NUNITS (exp) * sizeof (HOST_WIDE_INT);
3390 699625 : break;
3391 :
3392 42711 : case REAL_CST:
3393 42711 : return real_hash (TREE_REAL_CST_PTR (exp));
3394 :
3395 0 : case FIXED_CST:
3396 0 : return fixed_hash (TREE_FIXED_CST_PTR (exp));
3397 :
3398 4546833 : case STRING_CST:
3399 4546833 : p = TREE_STRING_POINTER (exp);
3400 4546833 : len = TREE_STRING_LENGTH (exp);
3401 4546833 : break;
3402 :
3403 19523 : case COMPLEX_CST:
3404 19523 : return (const_hash_1 (TREE_REALPART (exp)) * 5
3405 19523 : + const_hash_1 (TREE_IMAGPART (exp)));
3406 :
3407 0 : case VECTOR_CST:
3408 0 : {
3409 0 : hi = 7 + VECTOR_CST_NPATTERNS (exp);
3410 0 : hi = hi * 563 + VECTOR_CST_NELTS_PER_PATTERN (exp);
3411 0 : unsigned int count = vector_cst_encoded_nelts (exp);
3412 0 : for (unsigned int i = 0; i < count; ++i)
3413 0 : hi = hi * 563 + const_hash_1 (VECTOR_CST_ENCODED_ELT (exp, i));
3414 : return hi;
3415 : }
3416 :
3417 163 : case RAW_DATA_CST:
3418 163 : p = RAW_DATA_POINTER (exp);
3419 163 : len = RAW_DATA_LENGTH (exp);
3420 163 : break;
3421 :
3422 225642 : case CONSTRUCTOR:
3423 225642 : {
3424 225642 : unsigned HOST_WIDE_INT idx;
3425 225642 : tree value;
3426 :
3427 225642 : hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
3428 :
3429 1202891 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
3430 977249 : if (value)
3431 977249 : hi = hi * 603 + const_hash_1 (value);
3432 :
3433 : return hi;
3434 : }
3435 :
3436 125146 : case ADDR_EXPR:
3437 125146 : if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3438 95058 : return const_hash_1 (TREE_OPERAND (exp, 0));
3439 :
3440 : /* Fallthru. */
3441 30088 : case FDESC_EXPR:
3442 30088 : {
3443 30088 : class addr_const value;
3444 :
3445 30088 : decode_addr_const (exp, &value);
3446 30088 : switch (GET_CODE (value.base))
3447 : {
3448 30088 : case SYMBOL_REF:
3449 : /* Don't hash the address of the SYMBOL_REF;
3450 : only use the offset and the symbol name. */
3451 30088 : hi = value.offset.coeffs[0];
3452 30088 : p = XSTR (value.base, 0);
3453 1127764 : for (i = 0; p[i] != 0; i++)
3454 1097676 : hi = ((hi * 613) + (unsigned) (p[i]));
3455 : break;
3456 :
3457 0 : case LABEL_REF:
3458 0 : hi = (value.offset.coeffs[0]
3459 0 : + CODE_LABEL_NUMBER (label_ref_label (value.base)) * 13);
3460 0 : break;
3461 :
3462 0 : default:
3463 0 : gcc_unreachable ();
3464 : }
3465 : }
3466 30088 : return hi;
3467 :
3468 24 : case PLUS_EXPR:
3469 24 : case POINTER_PLUS_EXPR:
3470 24 : case MINUS_EXPR:
3471 24 : return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
3472 24 : + const_hash_1 (TREE_OPERAND (exp, 1)));
3473 :
3474 159832 : CASE_CONVERT:
3475 159832 : return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
3476 :
3477 : default:
3478 : /* A language specific constant. Just hash the code. */
3479 : return code;
3480 : }
3481 :
3482 : /* Compute hashing function. */
3483 5246621 : hi = len;
3484 335820634 : for (i = 0; i < len; i++)
3485 330574013 : hi = ((hi * 613) + (unsigned) (p[i]));
3486 :
3487 : return hi;
3488 : }
3489 :
3490 : /* Wrapper of compare_constant, for the htab interface. */
3491 : bool
3492 13024939 : tree_descriptor_hasher::equal (constant_descriptor_tree *c1,
3493 : constant_descriptor_tree *c2)
3494 : {
3495 13024939 : if (c1->hash != c2->hash)
3496 : return false;
3497 3072723 : return compare_constant (c1->value, c2->value);
3498 : }
3499 :
3500 : /* Compare t1 and t2, and return true only if they are known to result in
3501 : the same bit pattern on output. */
3502 :
3503 : static bool
3504 3535141 : compare_constant (const tree t1, const tree t2)
3505 : {
3506 3538341 : enum tree_code typecode;
3507 :
3508 3538341 : if (t1 == NULL_TREE)
3509 28674 : return t2 == NULL_TREE;
3510 3509667 : if (t2 == NULL_TREE)
3511 : return false;
3512 :
3513 3509667 : if (TREE_CODE (t1) != TREE_CODE (t2))
3514 : return false;
3515 :
3516 3509639 : switch (TREE_CODE (t1))
3517 : {
3518 425011 : case INTEGER_CST:
3519 : /* Integer constants are the same only if the same width of type. */
3520 425011 : if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3521 : return false;
3522 414620 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3523 : return false;
3524 414548 : return tree_int_cst_equal (t1, t2);
3525 :
3526 39165 : case REAL_CST:
3527 : /* Real constants are the same only if the same width of type. In
3528 : addition to the same width, we need to check whether the modes are the
3529 : same. There might be two floating point modes that are the same size
3530 : but have different representations, such as the PowerPC that has 2
3531 : different 128-bit floating point types (IBM extended double and IEEE
3532 : 128-bit floating point). */
3533 39165 : if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3534 : return false;
3535 26353 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3536 : return false;
3537 26353 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
3538 :
3539 0 : case FIXED_CST:
3540 : /* Fixed constants are the same only if the same width of type. */
3541 0 : if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3542 : return false;
3543 :
3544 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3545 :
3546 2987898 : case STRING_CST:
3547 2987898 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3548 5975796 : || int_size_in_bytes (TREE_TYPE (t1))
3549 2987898 : != int_size_in_bytes (TREE_TYPE (t2)))
3550 : return false;
3551 :
3552 2987846 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3553 2987846 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3554 2987846 : TREE_STRING_LENGTH (t1)));
3555 :
3556 25487 : case COMPLEX_CST:
3557 25487 : return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3558 40185 : && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3559 :
3560 0 : case VECTOR_CST:
3561 0 : {
3562 0 : if (VECTOR_CST_NPATTERNS (t1)
3563 0 : != VECTOR_CST_NPATTERNS (t2))
3564 : return false;
3565 :
3566 0 : if (VECTOR_CST_NELTS_PER_PATTERN (t1)
3567 0 : != VECTOR_CST_NELTS_PER_PATTERN (t2))
3568 : return false;
3569 :
3570 0 : unsigned int count = vector_cst_encoded_nelts (t1);
3571 0 : for (unsigned int i = 0; i < count; ++i)
3572 0 : if (!compare_constant (VECTOR_CST_ENCODED_ELT (t1, i),
3573 0 : VECTOR_CST_ENCODED_ELT (t2, i)))
3574 : return false;
3575 :
3576 : return true;
3577 : }
3578 :
3579 75 : case RAW_DATA_CST:
3580 75 : return (RAW_DATA_LENGTH (t1) == RAW_DATA_LENGTH (t2)
3581 75 : && ! memcmp (RAW_DATA_POINTER (t1), RAW_DATA_POINTER (t2),
3582 75 : RAW_DATA_LENGTH (t1)));
3583 :
3584 28800 : case CONSTRUCTOR:
3585 28800 : {
3586 28800 : vec<constructor_elt, va_gc> *v1, *v2;
3587 28800 : unsigned HOST_WIDE_INT idx;
3588 :
3589 28800 : typecode = TREE_CODE (TREE_TYPE (t1));
3590 28800 : if (typecode != TREE_CODE (TREE_TYPE (t2)))
3591 : return false;
3592 :
3593 28800 : if (typecode == ARRAY_TYPE)
3594 : {
3595 833 : HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3596 : /* For arrays, check that mode, size and storage order match. */
3597 833 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3598 833 : || size_1 == -1
3599 833 : || size_1 != int_size_in_bytes (TREE_TYPE (t2))
3600 1666 : || TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t1))
3601 833 : != TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t2)))
3602 : return false;
3603 : }
3604 : else
3605 : {
3606 : /* For record and union constructors, require exact type
3607 : equality. */
3608 27967 : if (TREE_TYPE (t1) != TREE_TYPE (t2))
3609 : return false;
3610 : }
3611 :
3612 28792 : v1 = CONSTRUCTOR_ELTS (t1);
3613 28792 : v2 = CONSTRUCTOR_ELTS (t2);
3614 86376 : if (vec_safe_length (v1) != vec_safe_length (v2))
3615 : return false;
3616 :
3617 282509 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
3618 : {
3619 253726 : constructor_elt *c1 = &(*v1)[idx];
3620 253726 : constructor_elt *c2 = &(*v2)[idx];
3621 :
3622 : /* Check that each value is the same... */
3623 253726 : if (!compare_constant (c1->value, c2->value))
3624 : return false;
3625 : /* ... and that they apply to the same fields! */
3626 253717 : if (typecode == ARRAY_TYPE)
3627 : {
3628 168507 : if (!compare_constant (c1->index, c2->index))
3629 : return false;
3630 : }
3631 : else
3632 : {
3633 85210 : if (c1->index != c2->index)
3634 : return false;
3635 : }
3636 : }
3637 :
3638 : return true;
3639 : }
3640 :
3641 3 : case ADDR_EXPR:
3642 3 : case FDESC_EXPR:
3643 3 : {
3644 3 : class addr_const value1, value2;
3645 3 : enum rtx_code code;
3646 3 : bool ret;
3647 :
3648 3 : decode_addr_const (t1, &value1);
3649 3 : decode_addr_const (t2, &value2);
3650 :
3651 3 : if (maybe_ne (value1.offset, value2.offset))
3652 : return false;
3653 :
3654 3 : code = GET_CODE (value1.base);
3655 3 : if (code != GET_CODE (value2.base))
3656 : return false;
3657 :
3658 3 : switch (code)
3659 : {
3660 3 : case SYMBOL_REF:
3661 3 : ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3662 3 : break;
3663 :
3664 0 : case LABEL_REF:
3665 0 : ret = (CODE_LABEL_NUMBER (label_ref_label (value1.base))
3666 0 : == CODE_LABEL_NUMBER (label_ref_label (value2.base)));
3667 0 : break;
3668 :
3669 0 : default:
3670 0 : gcc_unreachable ();
3671 : }
3672 : return ret;
3673 : }
3674 :
3675 0 : case PLUS_EXPR:
3676 0 : case POINTER_PLUS_EXPR:
3677 0 : case MINUS_EXPR:
3678 0 : case RANGE_EXPR:
3679 0 : return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3680 0 : && compare_constant (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3681 :
3682 3200 : CASE_CONVERT:
3683 3200 : case VIEW_CONVERT_EXPR:
3684 3200 : return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3685 :
3686 : default:
3687 : return false;
3688 : }
3689 : }
3690 :
3691 : /* Return the section into which constant EXP should be placed. */
3692 :
3693 : static section *
3694 1285609 : get_constant_section (tree exp, unsigned int align)
3695 : {
3696 1285609 : return targetm.asm_out.select_section (exp,
3697 : compute_reloc_for_constant (exp),
3698 1285609 : align);
3699 : }
3700 :
3701 : /* Return the size of constant EXP in bytes. */
3702 :
3703 : static HOST_WIDE_INT
3704 1287323 : get_constant_size (tree exp)
3705 : {
3706 1287323 : HOST_WIDE_INT size;
3707 :
3708 1287323 : size = int_size_in_bytes (TREE_TYPE (exp));
3709 1287323 : gcc_checking_assert (size >= 0);
3710 1287323 : gcc_checking_assert (TREE_CODE (exp) != STRING_CST
3711 : || size >= TREE_STRING_LENGTH (exp));
3712 1287323 : return size;
3713 : }
3714 :
3715 : /* Subroutine of output_constant_def:
3716 : No constant equal to EXP is known to have been output.
3717 : Make a constant descriptor to enter EXP in the hash table.
3718 : Assign the label number and construct RTL to refer to the
3719 : constant's location in memory.
3720 : Caller is responsible for updating the hash table. */
3721 :
3722 : static struct constant_descriptor_tree *
3723 1293926 : build_constant_desc (tree exp)
3724 : {
3725 1293926 : struct constant_descriptor_tree *desc;
3726 1293926 : rtx symbol, rtl;
3727 1293926 : char label[256];
3728 1293926 : int labelno;
3729 1293926 : tree decl;
3730 :
3731 1293926 : desc = ggc_alloc<constant_descriptor_tree> ();
3732 1293926 : desc->value = exp;
3733 :
3734 : /* Create a string containing the label name, in LABEL. */
3735 1293926 : labelno = const_labelno++;
3736 1293926 : ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3737 :
3738 : /* Construct the VAR_DECL associated with the constant. */
3739 1293926 : decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3740 1293926 : TREE_TYPE (exp));
3741 1293926 : DECL_ARTIFICIAL (decl) = 1;
3742 1293926 : DECL_IGNORED_P (decl) = 1;
3743 1293926 : TREE_READONLY (decl) = 1;
3744 1293926 : TREE_STATIC (decl) = 1;
3745 1293926 : TREE_ADDRESSABLE (decl) = 1;
3746 : /* We don't set the RTL yet as this would cause varpool to assume that the
3747 : variable is referenced. Moreover, it would just be dropped in LTO mode.
3748 : Instead we set the flag that will be recognized in make_decl_rtl. */
3749 1293926 : DECL_IN_CONSTANT_POOL (decl) = 1;
3750 1293926 : DECL_INITIAL (decl) = desc->value;
3751 : /* ??? targetm.constant_alignment hasn't been updated for vector types on
3752 : most architectures so use DATA_ALIGNMENT as well, except for strings. */
3753 1293926 : if (TREE_CODE (exp) == STRING_CST)
3754 1260921 : SET_DECL_ALIGN (decl, targetm.constant_alignment (exp, DECL_ALIGN (decl)));
3755 : else
3756 : {
3757 33005 : align_variable (decl, 0);
3758 33005 : if (DECL_ALIGN (decl) < GET_MODE_ALIGNMENT (DECL_MODE (decl))
3759 33005 : && ((optab_handler (movmisalign_optab, DECL_MODE (decl))
3760 : != CODE_FOR_nothing)
3761 0 : || targetm.slow_unaligned_access (DECL_MODE (decl),
3762 0 : DECL_ALIGN (decl))))
3763 0 : SET_DECL_ALIGN (decl, GET_MODE_ALIGNMENT (DECL_MODE (decl)));
3764 : }
3765 :
3766 : /* Now construct the SYMBOL_REF and the MEM. */
3767 1293926 : if (use_object_blocks_p ())
3768 : {
3769 0 : int align = (TREE_CODE (decl) == CONST_DECL
3770 0 : || (VAR_P (decl) && DECL_IN_CONSTANT_POOL (decl))
3771 0 : ? DECL_ALIGN (decl)
3772 0 : : symtab_node::get (decl)->definition_alignment ());
3773 0 : section *sect = get_constant_section (exp, align);
3774 0 : symbol = create_block_symbol (ggc_strdup (label),
3775 : get_block_for_section (sect), -1);
3776 : }
3777 : else
3778 1590742 : symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3779 1293926 : SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3780 1293926 : SET_SYMBOL_REF_DECL (symbol, decl);
3781 1293926 : TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3782 :
3783 1293926 : rtl = gen_const_mem (TYPE_MODE (TREE_TYPE (exp)), symbol);
3784 1293926 : set_mem_alias_set (rtl, 0);
3785 :
3786 : /* Putting EXP into the literal pool might have imposed a different
3787 : alignment which should be visible in the RTX as well. */
3788 1293926 : set_mem_align (rtl, DECL_ALIGN (decl));
3789 :
3790 : /* We cannot share RTX'es in pool entries.
3791 : Mark this piece of RTL as required for unsharing. */
3792 1293926 : RTX_FLAG (rtl, used) = 1;
3793 :
3794 : /* Set flags or add text to the name to record information, such as
3795 : that it is a local symbol. If the name is changed, the macro
3796 : ASM_OUTPUT_LABELREF will have to know how to strip this
3797 : information. This call might invalidate our local variable
3798 : SYMBOL; we can't use it afterward. */
3799 1293926 : targetm.encode_section_info (exp, rtl, true);
3800 :
3801 1293926 : desc->rtl = rtl;
3802 :
3803 1293926 : return desc;
3804 : }
3805 :
3806 : /* Subroutine of output_constant_def and tree_output_constant_def:
3807 : Add a constant to the hash table that tracks which constants
3808 : already have labels. */
3809 :
3810 : static constant_descriptor_tree *
3811 4065507 : add_constant_to_table (tree exp, int defer)
3812 : {
3813 : /* The hash table methods may call output_constant_def for addressed
3814 : constants, so handle them first. */
3815 4065507 : output_addressed_constants (exp, defer);
3816 :
3817 : /* Sanity check to catch recursive insertion. */
3818 4065507 : static bool inserting;
3819 4065507 : gcc_assert (!inserting);
3820 4065507 : inserting = true;
3821 :
3822 : /* Look up EXP in the table of constant descriptors. If we didn't
3823 : find it, create a new one. */
3824 4065507 : struct constant_descriptor_tree key;
3825 4065507 : key.value = exp;
3826 4065507 : key.hash = const_hash_1 (exp);
3827 4065507 : constant_descriptor_tree **loc
3828 4065507 : = const_desc_htab->find_slot_with_hash (&key, key.hash, INSERT);
3829 :
3830 4065507 : inserting = false;
3831 :
3832 4065507 : struct constant_descriptor_tree *desc = *loc;
3833 4065507 : if (!desc)
3834 : {
3835 1293926 : desc = build_constant_desc (exp);
3836 1293926 : desc->hash = key.hash;
3837 1293926 : *loc = desc;
3838 : }
3839 :
3840 4065507 : return desc;
3841 : }
3842 :
3843 : /* Return an rtx representing a reference to constant data in memory
3844 : for the constant expression EXP.
3845 :
3846 : If assembler code for such a constant has already been output,
3847 : return an rtx to refer to it.
3848 : Otherwise, output such a constant in memory
3849 : and generate an rtx for it.
3850 :
3851 : If DEFER is nonzero, this constant can be deferred and output only
3852 : if referenced in the function after all optimizations.
3853 :
3854 : `const_desc_table' records which constants already have label strings. */
3855 :
3856 : rtx
3857 4054956 : output_constant_def (tree exp, int defer)
3858 : {
3859 4054956 : struct constant_descriptor_tree *desc = add_constant_to_table (exp, defer);
3860 4054956 : maybe_output_constant_def_contents (desc, defer);
3861 4054956 : return desc->rtl;
3862 : }
3863 :
3864 : /* Subroutine of output_constant_def: Decide whether or not we need to
3865 : output the constant DESC now, and if so, do it. */
3866 : static void
3867 4054956 : maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3868 : int defer)
3869 : {
3870 4054956 : rtx symbol = XEXP (desc->rtl, 0);
3871 4054956 : tree exp = desc->value;
3872 :
3873 4054956 : if (flag_syntax_only)
3874 : return;
3875 :
3876 4054956 : if (TREE_ASM_WRITTEN (exp))
3877 : /* Already output; don't do it again. */
3878 : return;
3879 :
3880 : /* We can always defer constants as long as the context allows
3881 : doing so. */
3882 1453257 : if (defer)
3883 : {
3884 : /* Increment n_deferred_constants if it exists. It needs to be at
3885 : least as large as the number of constants actually referred to
3886 : by the function. If it's too small we'll stop looking too early
3887 : and fail to emit constants; if it's too large we'll only look
3888 : through the entire function when we could have stopped earlier. */
3889 176770 : if (cfun)
3890 108646 : n_deferred_constants++;
3891 : return;
3892 : }
3893 :
3894 1276487 : output_constant_def_contents (symbol);
3895 : }
3896 :
3897 : /* Subroutine of output_constant_def_contents. Output the definition
3898 : of constant EXP, which is pointed to by label LABEL. ALIGN is the
3899 : constant's alignment in bits. */
3900 :
3901 : static void
3902 1285609 : assemble_constant_contents (tree exp, const char *label, unsigned int align,
3903 : bool merge_strings)
3904 : {
3905 1285609 : HOST_WIDE_INT size;
3906 :
3907 1285609 : size = get_constant_size (exp);
3908 :
3909 : /* Do any machine/system dependent processing of the constant. */
3910 1285609 : targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3911 :
3912 : /* Output the value of EXP. */
3913 1285609 : output_constant (exp, size, align, false, merge_strings);
3914 :
3915 1285609 : targetm.asm_out.decl_end ();
3916 1285609 : }
3917 :
3918 : /* We must output the constant data referred to by SYMBOL; do so. */
3919 :
3920 : static void
3921 1285609 : output_constant_def_contents (rtx symbol)
3922 : {
3923 1285609 : tree decl = SYMBOL_REF_DECL (symbol);
3924 1285609 : tree exp = DECL_INITIAL (decl);
3925 1285609 : bool asan_protected = false;
3926 :
3927 : /* Make sure any other constants whose addresses appear in EXP
3928 : are assigned label numbers. */
3929 1285609 : output_addressed_constants (exp, 0);
3930 :
3931 : /* We are no longer deferring this constant. */
3932 1285609 : TREE_ASM_WRITTEN (decl) = TREE_ASM_WRITTEN (exp) = 1;
3933 :
3934 1285609 : if ((flag_sanitize & SANITIZE_ADDRESS)
3935 3435 : && TREE_CODE (exp) == STRING_CST
3936 1289010 : && asan_protect_global (exp))
3937 : {
3938 1714 : asan_protected = true;
3939 1714 : SET_DECL_ALIGN (decl, MAX (DECL_ALIGN (decl),
3940 : ASAN_RED_ZONE_SIZE * BITS_PER_UNIT));
3941 : }
3942 :
3943 : /* If the constant is part of an object block, make sure that the
3944 : decl has been positioned within its block, but do not write out
3945 : its definition yet. output_object_blocks will do that later. */
3946 1285609 : if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3947 0 : place_block_symbol (symbol);
3948 : else
3949 : {
3950 1285609 : int align = (TREE_CODE (decl) == CONST_DECL
3951 1285609 : || (VAR_P (decl) && DECL_IN_CONSTANT_POOL (decl))
3952 2571218 : ? DECL_ALIGN (decl)
3953 1285609 : : symtab_node::get (decl)->definition_alignment ());
3954 1285609 : section *sect = get_constant_section (exp, align);
3955 1285609 : switch_to_section (sect);
3956 1285609 : if (align > BITS_PER_UNIT)
3957 403804 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3958 1285609 : assemble_constant_contents (exp, XSTR (symbol, 0), align,
3959 1285609 : (sect->common.flags & SECTION_MERGE)
3960 412829 : && (sect->common.flags & SECTION_STRINGS));
3961 1285609 : if (asan_protected)
3962 : {
3963 1714 : HOST_WIDE_INT size = get_constant_size (exp);
3964 3387 : assemble_zeros (asan_red_zone_size (size));
3965 : }
3966 : }
3967 1285609 : }
3968 :
3969 : /* Look up EXP in the table of constant descriptors. Return the rtl
3970 : if it has been emitted, else null. */
3971 :
3972 : rtx
3973 482760 : lookup_constant_def (tree exp)
3974 : {
3975 482760 : struct constant_descriptor_tree key;
3976 :
3977 482760 : key.value = exp;
3978 482760 : key.hash = const_hash_1 (exp);
3979 482760 : constant_descriptor_tree *desc
3980 482760 : = const_desc_htab->find_with_hash (&key, key.hash);
3981 :
3982 482760 : return (desc ? desc->rtl : NULL_RTX);
3983 : }
3984 :
3985 : /* Return a tree representing a reference to constant data in memory
3986 : for the constant expression EXP.
3987 :
3988 : This is the counterpart of output_constant_def at the Tree level. */
3989 :
3990 : tree
3991 10551 : tree_output_constant_def (tree exp)
3992 : {
3993 10551 : struct constant_descriptor_tree *desc = add_constant_to_table (exp, 1);
3994 10551 : tree decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3995 10551 : varpool_node::finalize_decl (decl);
3996 10551 : return decl;
3997 : }
3998 :
3999 4331662 : class GTY((chain_next ("%h.next"), for_user)) constant_descriptor_rtx {
4000 : public:
4001 : class constant_descriptor_rtx *next;
4002 : rtx mem;
4003 : rtx sym;
4004 : rtx constant;
4005 : HOST_WIDE_INT offset;
4006 : hashval_t hash;
4007 : fixed_size_mode mode;
4008 : unsigned int align;
4009 : int labelno;
4010 : int mark;
4011 : };
4012 :
4013 : struct const_rtx_desc_hasher : ggc_ptr_hash<constant_descriptor_rtx>
4014 : {
4015 : static hashval_t hash (constant_descriptor_rtx *);
4016 : static bool equal (constant_descriptor_rtx *, constant_descriptor_rtx *);
4017 : };
4018 :
4019 : /* Used in the hash tables to avoid outputting the same constant
4020 : twice. Unlike 'struct constant_descriptor_tree', RTX constants
4021 : are output once per function, not once per file. */
4022 : /* ??? Only a few targets need per-function constant pools. Most
4023 : can use one per-file pool. Should add a targetm bit to tell the
4024 : difference. */
4025 :
4026 : struct GTY(()) rtx_constant_pool {
4027 : /* Pointers to first and last constant in pool, as ordered by offset. */
4028 : class constant_descriptor_rtx *first;
4029 : class constant_descriptor_rtx *last;
4030 :
4031 : /* Hash facility for making memory-constants from constant rtl-expressions.
4032 : It is used on RISC machines where immediate integer arguments and
4033 : constant addresses are restricted so that such constants must be stored
4034 : in memory. */
4035 : hash_table<const_rtx_desc_hasher> *const_rtx_htab;
4036 :
4037 : /* Current offset in constant pool (does not include any
4038 : machine-specific header). */
4039 : HOST_WIDE_INT offset;
4040 : };
4041 :
4042 : /* Hash and compare functions for const_rtx_htab. */
4043 :
4044 : hashval_t
4045 17147961 : const_rtx_desc_hasher::hash (constant_descriptor_rtx *desc)
4046 : {
4047 17147961 : return desc->hash;
4048 : }
4049 :
4050 : bool
4051 21419906 : const_rtx_desc_hasher::equal (constant_descriptor_rtx *x,
4052 : constant_descriptor_rtx *y)
4053 : {
4054 21419906 : if (x->mode != y->mode)
4055 : return false;
4056 11437432 : return rtx_equal_p (x->constant, y->constant);
4057 : }
4058 :
4059 : /* Hash one component of a constant. */
4060 :
4061 : static hashval_t
4062 16714456 : const_rtx_hash_1 (const_rtx x)
4063 : {
4064 16714456 : unsigned HOST_WIDE_INT hwi;
4065 16714456 : machine_mode mode;
4066 16714456 : enum rtx_code code;
4067 16714456 : hashval_t h;
4068 16714456 : int i;
4069 :
4070 16714456 : code = GET_CODE (x);
4071 16714456 : mode = GET_MODE (x);
4072 16714456 : h = (hashval_t) code * 1048573 + mode;
4073 :
4074 16714456 : switch (code)
4075 : {
4076 11184684 : case CONST_INT:
4077 11184684 : hwi = INTVAL (x);
4078 :
4079 11306077 : fold_hwi:
4080 11306077 : {
4081 11306077 : int shift = sizeof (hashval_t) * CHAR_BIT;
4082 11306077 : const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
4083 :
4084 11306077 : h ^= (hashval_t) hwi;
4085 22612154 : for (i = 1; i < n; ++i)
4086 : {
4087 11306077 : hwi >>= shift;
4088 11306077 : h ^= (hashval_t) hwi;
4089 : }
4090 : }
4091 : break;
4092 :
4093 : case CONST_WIDE_INT:
4094 : hwi = 0;
4095 : {
4096 374883 : for (i = 0; i < CONST_WIDE_INT_NUNITS (x); i++)
4097 253490 : hwi ^= CONST_WIDE_INT_ELT (x, i);
4098 121393 : goto fold_hwi;
4099 : }
4100 :
4101 2931419 : case CONST_DOUBLE:
4102 2931419 : if (TARGET_SUPPORTS_WIDE_INT == 0 && mode == VOIDmode)
4103 : {
4104 : hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
4105 : goto fold_hwi;
4106 : }
4107 : else
4108 2931419 : h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
4109 2931419 : break;
4110 :
4111 0 : case CONST_FIXED:
4112 0 : h ^= fixed_hash (CONST_FIXED_VALUE (x));
4113 0 : break;
4114 :
4115 89838 : case SYMBOL_REF:
4116 89838 : h ^= htab_hash_string (XSTR (x, 0));
4117 89838 : break;
4118 :
4119 38 : case LABEL_REF:
4120 38 : h = h * 251 + CODE_LABEL_NUMBER (label_ref_label (x));
4121 38 : break;
4122 :
4123 0 : case UNSPEC:
4124 0 : case UNSPEC_VOLATILE:
4125 0 : h = h * 251 + XINT (x, 1);
4126 0 : break;
4127 :
4128 : default:
4129 : break;
4130 : }
4131 :
4132 16714456 : return h;
4133 : }
4134 :
4135 : /* Compute a hash value for X, which should be a constant. */
4136 :
4137 : static hashval_t
4138 4310435 : const_rtx_hash (rtx x)
4139 : {
4140 4310435 : hashval_t h = 0;
4141 4310435 : subrtx_iterator::array_type array;
4142 21024891 : FOR_EACH_SUBRTX (iter, array, x, ALL)
4143 16714456 : h = h * 509 + const_rtx_hash_1 (*iter);
4144 4310435 : return h;
4145 4310435 : }
4146 :
4147 :
4148 : /* Create and return a new rtx constant pool. */
4149 :
4150 : static struct rtx_constant_pool *
4151 2035585 : create_constant_pool (void)
4152 : {
4153 2035585 : struct rtx_constant_pool *pool;
4154 :
4155 2035585 : pool = ggc_alloc<rtx_constant_pool> ();
4156 2035585 : pool->const_rtx_htab = hash_table<const_rtx_desc_hasher>::create_ggc (31);
4157 2035585 : pool->first = NULL;
4158 2035585 : pool->last = NULL;
4159 2035585 : pool->offset = 0;
4160 2035585 : return pool;
4161 : }
4162 :
4163 : /* Initialize constant pool hashing for a new function. */
4164 :
4165 : void
4166 1745944 : init_varasm_status (void)
4167 : {
4168 1745944 : crtl->varasm.pool = create_constant_pool ();
4169 1745944 : crtl->varasm.deferred_constants = 0;
4170 1745944 : }
4171 :
4172 : /* Given a MINUS expression, simplify it if both sides
4173 : include the same symbol. */
4174 :
4175 : rtx
4176 5168269 : simplify_subtraction (rtx x)
4177 : {
4178 5168269 : rtx r = simplify_rtx (x);
4179 5168269 : return r ? r : x;
4180 : }
4181 :
4182 : /* Given a constant rtx X, make (or find) a memory constant for its value
4183 : and return a MEM rtx to refer to it in memory. IN_MODE is the mode
4184 : of X. */
4185 :
4186 : rtx
4187 4331662 : force_const_mem (machine_mode in_mode, rtx x)
4188 : {
4189 4331662 : class constant_descriptor_rtx *desc, tmp;
4190 4331662 : struct rtx_constant_pool *pool;
4191 4331662 : char label[256];
4192 4331662 : rtx def, symbol;
4193 4331662 : hashval_t hash;
4194 4331662 : unsigned int align;
4195 4331662 : constant_descriptor_rtx **slot;
4196 4331662 : fixed_size_mode mode;
4197 :
4198 : /* We can't force variable-sized objects to memory. */
4199 4331662 : if (!is_a <fixed_size_mode> (in_mode, &mode))
4200 : return NULL_RTX;
4201 :
4202 : /* If we're not allowed to drop X into the constant pool, don't. */
4203 4331662 : if (targetm.cannot_force_const_mem (mode, x))
4204 : return NULL_RTX;
4205 :
4206 : /* Record that this function has used a constant pool entry. */
4207 4310435 : crtl->uses_const_pool = 1;
4208 :
4209 : /* Decide which pool to use. */
4210 8620870 : pool = (targetm.use_blocks_for_constant_p (mode, x)
4211 4310435 : ? shared_constant_pool
4212 : : crtl->varasm.pool);
4213 :
4214 : /* Lookup the value in the hashtable. */
4215 4310435 : tmp.constant = x;
4216 4310435 : tmp.mode = mode;
4217 4310435 : hash = const_rtx_hash (x);
4218 4310435 : slot = pool->const_rtx_htab->find_slot_with_hash (&tmp, hash, INSERT);
4219 4310435 : desc = *slot;
4220 :
4221 : /* If the constant was already present, return its memory. */
4222 4310435 : if (desc)
4223 3949768 : return copy_rtx (desc->mem);
4224 :
4225 : /* Otherwise, create a new descriptor. */
4226 360667 : desc = ggc_alloc<constant_descriptor_rtx> ();
4227 360667 : *slot = desc;
4228 :
4229 : /* Align the location counter as required by EXP's data type. */
4230 360667 : machine_mode align_mode = (mode == VOIDmode ? word_mode : mode);
4231 360667 : align = targetm.static_rtx_alignment (align_mode);
4232 :
4233 360667 : pool->offset += (align / BITS_PER_UNIT) - 1;
4234 360667 : pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
4235 :
4236 360667 : desc->next = NULL;
4237 360667 : desc->constant = copy_rtx (tmp.constant);
4238 360667 : desc->offset = pool->offset;
4239 360667 : desc->hash = hash;
4240 360667 : desc->mode = mode;
4241 360667 : desc->align = align;
4242 360667 : desc->labelno = const_labelno;
4243 360667 : desc->mark = 0;
4244 :
4245 360667 : pool->offset += GET_MODE_SIZE (mode);
4246 360667 : if (pool->last)
4247 314477 : pool->last->next = desc;
4248 : else
4249 46190 : pool->first = pool->last = desc;
4250 360667 : pool->last = desc;
4251 :
4252 : /* Create a string containing the label name, in LABEL. */
4253 360667 : ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4254 360667 : ++const_labelno;
4255 :
4256 : /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
4257 : the constants pool. */
4258 360667 : if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
4259 : {
4260 0 : section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
4261 0 : symbol = create_block_symbol (ggc_strdup (label),
4262 : get_block_for_section (sect), -1);
4263 : }
4264 : else
4265 392856 : symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
4266 360667 : desc->sym = symbol;
4267 360667 : SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
4268 360667 : CONSTANT_POOL_ADDRESS_P (symbol) = 1;
4269 360667 : SET_SYMBOL_REF_CONSTANT (symbol, desc);
4270 :
4271 : /* Construct the MEM. */
4272 360667 : desc->mem = def = gen_const_mem (mode, symbol);
4273 360667 : set_mem_align (def, align);
4274 :
4275 : /* If we're dropping a label to the constant pool, make sure we
4276 : don't delete it. */
4277 360667 : if (GET_CODE (x) == LABEL_REF)
4278 38 : LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
4279 :
4280 360667 : return copy_rtx (def);
4281 : }
4282 :
4283 : /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
4284 :
4285 : rtx
4286 12574397 : get_pool_constant (const_rtx addr)
4287 : {
4288 12574397 : return SYMBOL_REF_CONSTANT (addr)->constant;
4289 : }
4290 :
4291 : /* Given a constant pool SYMBOL_REF, return the corresponding constant
4292 : and whether it has been output or not. */
4293 :
4294 : rtx
4295 0 : get_pool_constant_mark (rtx addr, bool *pmarked)
4296 : {
4297 0 : class constant_descriptor_rtx *desc;
4298 :
4299 0 : desc = SYMBOL_REF_CONSTANT (addr);
4300 0 : *pmarked = (desc->mark != 0);
4301 0 : return desc->constant;
4302 : }
4303 :
4304 : /* Similar, return the mode. */
4305 :
4306 : fixed_size_mode
4307 5496884 : get_pool_mode (const_rtx addr)
4308 : {
4309 5496884 : return SYMBOL_REF_CONSTANT (addr)->mode;
4310 : }
4311 :
4312 : /* Return TRUE if and only if the constant pool has no entries. Note
4313 : that even entries we might end up choosing not to emit are counted
4314 : here, so there is the potential for missed optimizations. */
4315 :
4316 : bool
4317 0 : constant_pool_empty_p (void)
4318 : {
4319 0 : return crtl->varasm.pool->first == NULL;
4320 : }
4321 :
4322 : /* Worker function for output_constant_pool_1. Emit assembly for X
4323 : in MODE with known alignment ALIGN. */
4324 :
4325 : static void
4326 673320 : output_constant_pool_2 (fixed_size_mode mode, rtx x, unsigned int align)
4327 : {
4328 673320 : switch (GET_MODE_CLASS (mode))
4329 : {
4330 208582 : case MODE_FLOAT:
4331 208582 : case MODE_DECIMAL_FLOAT:
4332 208582 : {
4333 208582 : gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x));
4334 208582 : assemble_real (*CONST_DOUBLE_REAL_VALUE (x),
4335 : as_a <scalar_float_mode> (mode), align, false);
4336 208582 : break;
4337 : }
4338 :
4339 371337 : case MODE_INT:
4340 371337 : case MODE_PARTIAL_INT:
4341 371337 : case MODE_FRACT:
4342 371337 : case MODE_UFRACT:
4343 371337 : case MODE_ACCUM:
4344 371337 : case MODE_UACCUM:
4345 371337 : assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
4346 371337 : break;
4347 :
4348 0 : case MODE_VECTOR_BOOL:
4349 0 : {
4350 0 : gcc_assert (GET_CODE (x) == CONST_VECTOR);
4351 :
4352 0 : auto_vec<target_unit, 128> buffer;
4353 0 : buffer.reserve (GET_MODE_SIZE (mode));
4354 :
4355 0 : bool ok = native_encode_rtx (mode, x, buffer, 0, GET_MODE_SIZE (mode));
4356 0 : gcc_assert (ok);
4357 :
4358 0 : for (unsigned i = 0; i < GET_MODE_SIZE (mode); i++)
4359 : {
4360 0 : unsigned HOST_WIDE_INT value = buffer[i];
4361 0 : output_constant_pool_2 (byte_mode, gen_int_mode (value, byte_mode),
4362 : i == 0 ? align : 1);
4363 : }
4364 0 : break;
4365 0 : }
4366 93401 : case MODE_VECTOR_FLOAT:
4367 93401 : case MODE_VECTOR_INT:
4368 93401 : case MODE_VECTOR_FRACT:
4369 93401 : case MODE_VECTOR_UFRACT:
4370 93401 : case MODE_VECTOR_ACCUM:
4371 93401 : case MODE_VECTOR_UACCUM:
4372 93401 : {
4373 93401 : int i, units;
4374 93401 : scalar_mode submode = GET_MODE_INNER (mode);
4375 280203 : unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
4376 :
4377 93401 : gcc_assert (GET_CODE (x) == CONST_VECTOR);
4378 93401 : units = GET_MODE_NUNITS (mode);
4379 :
4380 516389 : for (i = 0; i < units; i++)
4381 : {
4382 422988 : rtx elt = CONST_VECTOR_ELT (x, i);
4383 516389 : output_constant_pool_2 (submode, elt, i ? subalign : align);
4384 : }
4385 : }
4386 : break;
4387 :
4388 0 : default:
4389 0 : gcc_unreachable ();
4390 : }
4391 673320 : }
4392 :
4393 : /* Worker function for output_constant_pool. Emit constant DESC,
4394 : giving it ALIGN bits of alignment. */
4395 :
4396 : static void
4397 250332 : output_constant_pool_1 (class constant_descriptor_rtx *desc,
4398 : unsigned int align)
4399 : {
4400 250332 : rtx x, tmp;
4401 :
4402 250332 : x = desc->constant;
4403 :
4404 : /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
4405 : whose CODE_LABEL has been deleted. This can occur if a jump table
4406 : is eliminated by optimization. If so, write a constant of zero
4407 : instead. Note that this can also happen by turning the
4408 : CODE_LABEL into a NOTE. */
4409 : /* ??? This seems completely and utterly wrong. Certainly it's
4410 : not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
4411 : functioning even with rtx_insn::deleted and friends. */
4412 :
4413 250332 : tmp = x;
4414 250332 : switch (GET_CODE (tmp))
4415 : {
4416 3653 : case CONST:
4417 3653 : if (GET_CODE (XEXP (tmp, 0)) != PLUS
4418 3653 : || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
4419 : break;
4420 : tmp = XEXP (XEXP (tmp, 0), 0);
4421 : /* FALLTHRU */
4422 :
4423 38 : case LABEL_REF:
4424 38 : {
4425 38 : rtx_insn *insn = label_ref_label (tmp);
4426 38 : gcc_assert (!insn->deleted ());
4427 38 : gcc_assert (!NOTE_P (insn)
4428 : || NOTE_KIND (insn) != NOTE_INSN_DELETED);
4429 : break;
4430 : }
4431 :
4432 : default:
4433 : break;
4434 : }
4435 :
4436 : #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4437 : ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
4438 : align, desc->labelno, done);
4439 : #endif
4440 :
4441 250332 : assemble_align (align);
4442 :
4443 : /* Output the label. */
4444 250332 : targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
4445 :
4446 : /* Output the data.
4447 : Pass actual alignment value while emitting string constant to asm code
4448 : as function 'output_constant_pool_1' explicitly passes the alignment as 1
4449 : assuming that the data is already aligned which prevents the generation
4450 : of fix-up table entries. */
4451 250332 : output_constant_pool_2 (desc->mode, x, desc->align);
4452 :
4453 : /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
4454 : sections have proper size. */
4455 250332 : if (in_section
4456 250332 : && (in_section->common.flags & SECTION_MERGE)
4457 250332 : && ((in_section->common.flags & SECTION_ENTSIZE)
4458 412716 : > GET_MODE_SIZE (desc->mode)))
4459 : {
4460 99 : unsigned HOST_WIDE_INT entsize, constsize;
4461 99 : entsize = (in_section->common.flags & SECTION_ENTSIZE);
4462 99 : constsize = GET_MODE_SIZE (desc->mode);
4463 99 : assemble_zeros (entsize - constsize);
4464 : }
4465 :
4466 : #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4467 : done:
4468 : #endif
4469 250332 : return;
4470 : }
4471 :
4472 : /* Recompute the offsets of entries in POOL, and the overall size of
4473 : POOL. Do this after calling mark_constant_pool to ensure that we
4474 : are computing the offset values for the pool which we will actually
4475 : emit. */
4476 :
4477 : static void
4478 1519033 : recompute_pool_offsets (struct rtx_constant_pool *pool)
4479 : {
4480 1519033 : class constant_descriptor_rtx *desc;
4481 1519033 : pool->offset = 0;
4482 :
4483 1519033 : for (desc = pool->first; desc ; desc = desc->next)
4484 0 : if (desc->mark)
4485 : {
4486 : /* Recalculate offset. */
4487 0 : unsigned int align = desc->align;
4488 0 : pool->offset += (align / BITS_PER_UNIT) - 1;
4489 0 : pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
4490 0 : desc->offset = pool->offset;
4491 0 : pool->offset += GET_MODE_SIZE (desc->mode);
4492 : }
4493 1519033 : }
4494 :
4495 : /* Mark all constants that are referenced by SYMBOL_REFs in X.
4496 : Emit referenced deferred strings. */
4497 :
4498 : static void
4499 39450413 : mark_constants_in_pattern (rtx_insn *insn)
4500 : {
4501 39450413 : subrtx_iterator::array_type array;
4502 263766829 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL)
4503 : {
4504 224316416 : const_rtx x = *iter;
4505 224316416 : if (GET_CODE (x) == SYMBOL_REF)
4506 : {
4507 7857482 : if (CONSTANT_POOL_ADDRESS_P (x))
4508 : {
4509 780024 : class constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
4510 780024 : if (desc->mark == 0)
4511 : {
4512 258982 : desc->mark = 1;
4513 258982 : iter.substitute (desc->constant);
4514 : }
4515 : }
4516 7077458 : else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
4517 : {
4518 758564 : tree decl = SYMBOL_REF_DECL (x);
4519 758564 : if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
4520 : {
4521 7684 : n_deferred_constants--;
4522 7684 : output_constant_def_contents (const_cast<rtx> (x));
4523 : }
4524 : }
4525 : }
4526 : }
4527 39450413 : }
4528 :
4529 : /* Look through appropriate parts of INSN, marking all entries in the
4530 : constant pool which are actually being used. Entries that are only
4531 : referenced by other constants are also marked as used. Emit
4532 : deferred strings that are used. */
4533 :
4534 : static void
4535 90410623 : mark_constants (rtx_insn *insn)
4536 : {
4537 90410623 : if (!INSN_P (insn))
4538 : return;
4539 :
4540 : /* Insns may appear inside a SEQUENCE. Only check the patterns of
4541 : insns, not any notes that may be attached. We don't want to mark
4542 : a constant just because it happens to appear in a REG_EQUIV note. */
4543 39450413 : if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
4544 : {
4545 0 : int i, n = seq->len ();
4546 0 : for (i = 0; i < n; ++i)
4547 : {
4548 0 : rtx_insn *subinsn = seq->insn (i);
4549 0 : if (INSN_P (subinsn))
4550 0 : mark_constants_in_pattern (subinsn);
4551 : }
4552 : }
4553 : else
4554 39450413 : mark_constants_in_pattern (insn);
4555 : }
4556 :
4557 : /* Look through the instructions for this function, and mark all the
4558 : entries in POOL which are actually being used. Emit deferred constants
4559 : which have indeed been used. */
4560 :
4561 : static void
4562 1519033 : mark_constant_pool (void)
4563 : {
4564 1519033 : rtx_insn *insn;
4565 :
4566 1519033 : if (!crtl->uses_const_pool && n_deferred_constants == 0)
4567 : return;
4568 :
4569 90593085 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4570 90410623 : mark_constants (insn);
4571 : }
4572 :
4573 : /* Write all the constants in POOL. */
4574 :
4575 : static void
4576 1758478 : output_constant_pool_contents (struct rtx_constant_pool *pool)
4577 : {
4578 1758478 : class constant_descriptor_rtx *desc;
4579 :
4580 2119116 : for (desc = pool->first; desc ; desc = desc->next)
4581 360638 : if (desc->mark < 0)
4582 : {
4583 : #ifdef ASM_OUTPUT_DEF
4584 8650 : gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
4585 :
4586 8650 : const char *name = XSTR (desc->sym, 0);
4587 8650 : char label[256];
4588 8650 : char buffer[256 + 32];
4589 8650 : const char *p;
4590 :
4591 8650 : ASM_GENERATE_INTERNAL_LABEL (label, "LC", ~desc->mark);
4592 8650 : p = label;
4593 8650 : if (desc->offset)
4594 : {
4595 2882 : sprintf (buffer, "%s+" HOST_WIDE_INT_PRINT_DEC, p, desc->offset);
4596 2882 : p = buffer;
4597 : }
4598 8650 : ASM_OUTPUT_DEF (asm_out_file, name, p);
4599 : #else
4600 : gcc_unreachable ();
4601 : #endif
4602 : }
4603 351988 : else if (desc->mark)
4604 : {
4605 : /* If the constant is part of an object_block, make sure that
4606 : the constant has been positioned within its block, but do not
4607 : write out its definition yet. output_object_blocks will do
4608 : that later. */
4609 250332 : if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4610 250332 : && SYMBOL_REF_BLOCK (desc->sym))
4611 0 : place_block_symbol (desc->sym);
4612 : else
4613 : {
4614 250332 : switch_to_section (targetm.asm_out.select_rtx_section
4615 250332 : (desc->mode, desc->constant, desc->align));
4616 250332 : output_constant_pool_1 (desc, desc->align);
4617 : }
4618 : }
4619 1758478 : }
4620 :
4621 : struct constant_descriptor_rtx_data {
4622 : constant_descriptor_rtx *desc;
4623 : target_unit *bytes;
4624 : unsigned short size;
4625 : unsigned short offset;
4626 : unsigned int hash;
4627 : };
4628 :
4629 : /* qsort callback to sort constant_descriptor_rtx_data * vector by
4630 : decreasing size. */
4631 :
4632 : static int
4633 3851512 : constant_descriptor_rtx_data_cmp (const void *p1, const void *p2)
4634 : {
4635 3851512 : constant_descriptor_rtx_data *const data1
4636 : = *(constant_descriptor_rtx_data * const *) p1;
4637 3851512 : constant_descriptor_rtx_data *const data2
4638 : = *(constant_descriptor_rtx_data * const *) p2;
4639 3851512 : if (data1->size > data2->size)
4640 : return -1;
4641 3554621 : if (data1->size < data2->size)
4642 : return 1;
4643 3330248 : if (data1->hash < data2->hash)
4644 : return -1;
4645 1725684 : gcc_assert (data1->hash > data2->hash);
4646 : return 1;
4647 : }
4648 :
4649 : struct const_rtx_data_hasher : nofree_ptr_hash<constant_descriptor_rtx_data>
4650 : {
4651 : static hashval_t hash (constant_descriptor_rtx_data *);
4652 : static bool equal (constant_descriptor_rtx_data *,
4653 : constant_descriptor_rtx_data *);
4654 : };
4655 :
4656 : /* Hash and compare functions for const_rtx_data_htab. */
4657 :
4658 : hashval_t
4659 2202468 : const_rtx_data_hasher::hash (constant_descriptor_rtx_data *data)
4660 : {
4661 2202468 : return data->hash;
4662 : }
4663 :
4664 : bool
4665 2404319 : const_rtx_data_hasher::equal (constant_descriptor_rtx_data *x,
4666 : constant_descriptor_rtx_data *y)
4667 : {
4668 2404319 : if (x->hash != y->hash || x->size != y->size)
4669 : return false;
4670 159128 : unsigned int align1 = x->desc->align;
4671 159128 : unsigned int align2 = y->desc->align;
4672 159128 : unsigned int offset1 = (x->offset * BITS_PER_UNIT) & (align1 - 1);
4673 159128 : unsigned int offset2 = (y->offset * BITS_PER_UNIT) & (align2 - 1);
4674 159128 : if (offset1)
4675 78261 : align1 = least_bit_hwi (offset1);
4676 159128 : if (offset2)
4677 112838 : align2 = least_bit_hwi (offset2);
4678 159128 : if (align2 > align1)
4679 : return false;
4680 136160 : if (memcmp (x->bytes, y->bytes, x->size * sizeof (target_unit)) != 0)
4681 0 : return false;
4682 : return true;
4683 : }
4684 :
4685 : /* Attempt to optimize constant pool POOL. If it contains both CONST_VECTOR
4686 : constants and scalar constants with the values of CONST_VECTOR elements,
4687 : try to alias the scalar constants with the CONST_VECTOR elements. */
4688 :
4689 : static void
4690 155281 : optimize_constant_pool (struct rtx_constant_pool *pool)
4691 : {
4692 155281 : auto_vec<target_unit, 128> buffer;
4693 155281 : auto_vec<constant_descriptor_rtx_data *, 128> vec;
4694 155281 : object_allocator<constant_descriptor_rtx_data>
4695 155281 : data_pool ("constant_descriptor_rtx_data_pool");
4696 155281 : int idx = 0;
4697 155281 : size_t size = 0;
4698 472825 : for (constant_descriptor_rtx *desc = pool->first; desc; desc = desc->next)
4699 317544 : if (desc->mark > 0
4700 317544 : && ! (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4701 0 : && SYMBOL_REF_BLOCK (desc->sym)))
4702 : {
4703 219555 : buffer.truncate (0);
4704 439110 : buffer.reserve (GET_MODE_SIZE (desc->mode));
4705 219555 : if (native_encode_rtx (desc->mode, desc->constant, buffer, 0,
4706 439110 : GET_MODE_SIZE (desc->mode)))
4707 : {
4708 191439 : constant_descriptor_rtx_data *data = data_pool.allocate ();
4709 191439 : data->desc = desc;
4710 191439 : data->bytes = NULL;
4711 191439 : data->size = GET_MODE_SIZE (desc->mode);
4712 191439 : data->offset = 0;
4713 191439 : data->hash = idx++;
4714 191439 : size += data->size;
4715 191439 : vec.safe_push (data);
4716 : }
4717 : }
4718 155281 : if (idx)
4719 : {
4720 28943 : vec.qsort (constant_descriptor_rtx_data_cmp);
4721 28943 : unsigned min_size = vec.last ()->size;
4722 28943 : target_unit *bytes = XNEWVEC (target_unit, size);
4723 28943 : unsigned int i;
4724 28943 : constant_descriptor_rtx_data *data;
4725 28943 : hash_table<const_rtx_data_hasher> * htab
4726 28943 : = new hash_table<const_rtx_data_hasher> (31);
4727 28943 : size = 0;
4728 278268 : FOR_EACH_VEC_ELT (vec, i, data)
4729 : {
4730 191439 : buffer.truncate (0);
4731 191439 : native_encode_rtx (data->desc->mode, data->desc->constant,
4732 191439 : buffer, 0, data->size);
4733 191439 : memcpy (bytes + size, buffer.address (), data->size);
4734 191439 : data->bytes = bytes + size;
4735 382878 : data->hash = iterative_hash (data->bytes,
4736 191439 : data->size * sizeof (target_unit), 0);
4737 191439 : size += data->size;
4738 191439 : constant_descriptor_rtx_data **slot
4739 191439 : = htab->find_slot_with_hash (data, data->hash, INSERT);
4740 191439 : if (*slot)
4741 : {
4742 8650 : data->desc->mark = ~(*slot)->desc->labelno;
4743 8650 : data->desc->offset = (*slot)->offset;
4744 : }
4745 : else
4746 : {
4747 182789 : unsigned int sz = 1 << floor_log2 (data->size);
4748 :
4749 182789 : *slot = data;
4750 268184 : for (sz >>= 1; sz >= min_size; sz >>= 1)
4751 380058 : for (unsigned off = 0; off + sz <= data->size; off += sz)
4752 : {
4753 294663 : constant_descriptor_rtx_data tmp;
4754 294663 : tmp.desc = data->desc;
4755 294663 : tmp.bytes = data->bytes + off;
4756 294663 : tmp.size = sz;
4757 294663 : tmp.offset = off;
4758 294663 : tmp.hash = iterative_hash (tmp.bytes,
4759 : sz * sizeof (target_unit), 0);
4760 294663 : slot = htab->find_slot_with_hash (&tmp, tmp.hash, INSERT);
4761 294663 : if (*slot == NULL)
4762 : {
4763 167153 : *slot = data_pool.allocate ();
4764 167153 : **slot = tmp;
4765 : }
4766 : }
4767 : }
4768 : }
4769 28943 : delete htab;
4770 28943 : XDELETE (bytes);
4771 : }
4772 155281 : data_pool.release ();
4773 155281 : }
4774 :
4775 : /* Mark all constants that are used in the current function, then write
4776 : out the function's private constant pool. */
4777 :
4778 : static void
4779 1519033 : output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
4780 : tree fndecl ATTRIBUTE_UNUSED)
4781 : {
4782 1519033 : struct rtx_constant_pool *pool = crtl->varasm.pool;
4783 :
4784 : /* It is possible for gcc to call force_const_mem and then to later
4785 : discard the instructions which refer to the constant. In such a
4786 : case we do not need to output the constant. */
4787 1519033 : mark_constant_pool ();
4788 :
4789 : /* Having marked the constant pool entries we'll actually emit, we
4790 : now need to rebuild the offset information, which may have become
4791 : stale. */
4792 1519033 : recompute_pool_offsets (pool);
4793 :
4794 : #ifdef ASM_OUTPUT_POOL_PROLOGUE
4795 : ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
4796 : #endif
4797 :
4798 1519033 : output_constant_pool_contents (pool);
4799 :
4800 : #ifdef ASM_OUTPUT_POOL_EPILOGUE
4801 : ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
4802 : #endif
4803 1519033 : }
4804 :
4805 : /* Write the contents of the shared constant pool. */
4806 :
4807 : void
4808 239445 : output_shared_constant_pool (void)
4809 : {
4810 239445 : if (optimize
4811 : && TARGET_SUPPORTS_ALIASES)
4812 155281 : optimize_constant_pool (shared_constant_pool);
4813 :
4814 239445 : output_constant_pool_contents (shared_constant_pool);
4815 239445 : }
4816 :
4817 : /* Determine what kind of relocations EXP may need. */
4818 :
4819 : int
4820 35605446 : compute_reloc_for_constant (tree exp)
4821 : {
4822 38091292 : int reloc = 0, reloc2;
4823 38091292 : tree tem;
4824 :
4825 38091292 : switch (TREE_CODE (exp))
4826 : {
4827 10117198 : case ADDR_EXPR:
4828 10117198 : case FDESC_EXPR:
4829 : /* Go inside any operations that get_inner_reference can handle and see
4830 : if what's inside is a constant: no need to do anything here for
4831 : addresses of variables or functions. */
4832 10191798 : for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4833 74600 : tem = TREE_OPERAND (tem, 0))
4834 : ;
4835 :
4836 10117198 : if (TREE_CODE (tem) == MEM_REF
4837 10117198 : && TREE_CODE (TREE_OPERAND (tem, 0)) == ADDR_EXPR)
4838 : {
4839 59650 : reloc = compute_reloc_for_constant (TREE_OPERAND (tem, 0));
4840 59650 : break;
4841 : }
4842 :
4843 10057548 : if (!targetm.binds_local_p (tem))
4844 : reloc |= 2;
4845 : else
4846 7727569 : reloc |= 1;
4847 : break;
4848 :
4849 19441 : case PLUS_EXPR:
4850 19441 : case POINTER_PLUS_EXPR:
4851 19441 : reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4852 19441 : reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4853 19441 : break;
4854 :
4855 26 : case MINUS_EXPR:
4856 26 : reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4857 26 : reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4858 : /* The difference of two local labels is computable at link time. */
4859 26 : if (reloc == 1 && reloc2 == 1)
4860 : reloc = 0;
4861 : else
4862 0 : reloc |= reloc2;
4863 : break;
4864 :
4865 2426196 : CASE_CONVERT:
4866 2426196 : case VIEW_CONVERT_EXPR:
4867 2426196 : reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4868 2426196 : break;
4869 :
4870 : case CONSTRUCTOR:
4871 : {
4872 : unsigned HOST_WIDE_INT idx;
4873 37735443 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4874 29766073 : if (tem != 0)
4875 29766073 : reloc |= compute_reloc_for_constant (tem);
4876 : }
4877 : break;
4878 :
4879 : default:
4880 : break;
4881 : }
4882 35605446 : return reloc;
4883 : }
4884 :
4885 : /* Find all the constants whose addresses are referenced inside of EXP,
4886 : and make sure assembler code with a label has been output for each one.
4887 : Indicate whether an ADDR_EXPR has been encountered. */
4888 :
4889 : static void
4890 22755389 : output_addressed_constants (tree exp, int defer)
4891 : {
4892 23250687 : tree tem;
4893 :
4894 23250687 : switch (TREE_CODE (exp))
4895 : {
4896 4587702 : case ADDR_EXPR:
4897 4587702 : case FDESC_EXPR:
4898 : /* Go inside any operations that get_inner_reference can handle and see
4899 : if what's inside is a constant: no need to do anything here for
4900 : addresses of variables or functions. */
4901 4662515 : for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4902 74813 : tem = TREE_OPERAND (tem, 0))
4903 : ;
4904 :
4905 : /* If we have an initialized CONST_DECL, retrieve the initializer. */
4906 4587702 : if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4907 0 : tem = DECL_INITIAL (tem);
4908 :
4909 4587702 : if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4910 989355 : output_constant_def (tem, defer);
4911 :
4912 4587702 : if (TREE_CODE (tem) == MEM_REF)
4913 55087 : output_addressed_constants (TREE_OPERAND (tem, 0), defer);
4914 : break;
4915 :
4916 16983 : case PLUS_EXPR:
4917 16983 : case POINTER_PLUS_EXPR:
4918 16983 : case MINUS_EXPR:
4919 16983 : output_addressed_constants (TREE_OPERAND (exp, 1), defer);
4920 440211 : gcc_fallthrough ();
4921 :
4922 440211 : CASE_CONVERT:
4923 440211 : case VIEW_CONVERT_EXPR:
4924 440211 : output_addressed_constants (TREE_OPERAND (exp, 0), defer);
4925 440211 : break;
4926 :
4927 : case CONSTRUCTOR:
4928 : {
4929 : unsigned HOST_WIDE_INT idx;
4930 19564240 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4931 15452026 : if (tem != 0)
4932 15452026 : output_addressed_constants (tem, defer);
4933 : }
4934 : break;
4935 :
4936 : default:
4937 : break;
4938 : }
4939 22755389 : }
4940 :
4941 : /* Whether a constructor CTOR is a valid static constant initializer if all
4942 : its elements are. This used to be internal to initializer_constant_valid_p
4943 : and has been exposed to let other functions like categorize_ctor_elements
4944 : evaluate the property while walking a constructor for other purposes. */
4945 :
4946 : bool
4947 14633783 : constructor_static_from_elts_p (const_tree ctor)
4948 : {
4949 14633783 : return (TREE_CONSTANT (ctor)
4950 14633783 : && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4951 13983085 : || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE
4952 1488916 : || TREE_CODE (TREE_TYPE (ctor)) == ARRAY_TYPE));
4953 : }
4954 :
4955 : static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4956 : tree *cache);
4957 :
4958 : /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4959 : PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4960 : which are valid when ENDTYPE is an integer of any size; in
4961 : particular, this does not accept a pointer minus a constant. This
4962 : returns null_pointer_node if the VALUE is an absolute constant
4963 : which can be used to initialize a static variable. Otherwise it
4964 : returns NULL. */
4965 :
4966 : static tree
4967 1128734 : narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4968 : {
4969 1128734 : tree op0, op1;
4970 :
4971 1128734 : if (!INTEGRAL_TYPE_P (endtype))
4972 : return NULL_TREE;
4973 :
4974 1032048 : op0 = TREE_OPERAND (value, 0);
4975 1032048 : op1 = TREE_OPERAND (value, 1);
4976 :
4977 : /* Like STRIP_NOPS except allow the operand mode to widen. This
4978 : works around a feature of fold that simplifies (int)(p1 - p2) to
4979 : ((int)p1 - (int)p2) under the theory that the narrower operation
4980 : is cheaper. */
4981 :
4982 2047686 : while (CONVERT_EXPR_P (op0)
4983 2389402 : || TREE_CODE (op0) == NON_LVALUE_EXPR)
4984 : {
4985 377305 : tree inner = TREE_OPERAND (op0, 0);
4986 754610 : if (inner == error_mark_node
4987 377305 : || ! INTEGRAL_TYPE_P (TREE_TYPE (op0))
4988 372924 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op0)))
4989 372924 : || ! INTEGRAL_TYPE_P (TREE_TYPE (inner))
4990 372768 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4991 750073 : || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op0)))
4992 771537 : > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner)))))
4993 : break;
4994 : op0 = inner;
4995 : }
4996 :
4997 1021481 : while (CONVERT_EXPR_P (op1)
4998 2257347 : || TREE_CODE (op1) == NON_LVALUE_EXPR)
4999 : {
5000 253135 : tree inner = TREE_OPERAND (op1, 0);
5001 506270 : if (inner == error_mark_node
5002 253135 : || ! INTEGRAL_TYPE_P (TREE_TYPE (op1))
5003 253009 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op1)))
5004 253009 : || ! INTEGRAL_TYPE_P (TREE_TYPE (inner))
5005 252923 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
5006 506058 : || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op1)))
5007 536107 : > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner)))))
5008 : break;
5009 : op1 = inner;
5010 : }
5011 :
5012 1032048 : op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
5013 1032048 : if (!op0)
5014 : return NULL_TREE;
5015 :
5016 927 : op1 = initializer_constant_valid_p_1 (op1, endtype,
5017 : cache ? cache + 2 : NULL);
5018 : /* Both initializers must be known. */
5019 927 : if (op1)
5020 : {
5021 201 : if (op0 == op1
5022 30 : && (op0 == null_pointer_node
5023 11 : || TREE_CODE (value) == MINUS_EXPR))
5024 : return null_pointer_node;
5025 :
5026 : /* Support differences between labels. */
5027 182 : if (TREE_CODE (op0) == LABEL_DECL
5028 169 : && TREE_CODE (op1) == LABEL_DECL)
5029 169 : return null_pointer_node;
5030 :
5031 13 : if (TREE_CODE (op0) == STRING_CST
5032 0 : && TREE_CODE (op1) == STRING_CST
5033 13 : && operand_equal_p (op0, op1, 1))
5034 0 : return null_pointer_node;
5035 : }
5036 :
5037 : return NULL_TREE;
5038 : }
5039 :
5040 : /* Helper function of initializer_constant_valid_p.
5041 : Return nonzero if VALUE is a valid constant-valued expression
5042 : for use in initializing a static variable; one that can be an
5043 : element of a "constant" initializer.
5044 :
5045 : Return null_pointer_node if the value is absolute;
5046 : if it is relocatable, return the variable that determines the relocation.
5047 : We assume that VALUE has been folded as much as possible;
5048 : therefore, we do not need to check for such things as
5049 : arithmetic-combinations of integers.
5050 :
5051 : Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
5052 :
5053 : static tree
5054 1378767922 : initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
5055 : {
5056 1433799814 : tree ret;
5057 :
5058 1433799814 : switch (TREE_CODE (value))
5059 : {
5060 13077067 : case CONSTRUCTOR:
5061 13077067 : if (constructor_static_from_elts_p (value))
5062 : {
5063 13065788 : unsigned HOST_WIDE_INT idx;
5064 13065788 : tree elt;
5065 13065788 : bool absolute = true;
5066 :
5067 13065788 : if (cache && cache[0] == value)
5068 0 : return cache[1];
5069 122001558 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
5070 : {
5071 108936174 : tree reloc;
5072 108936174 : reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
5073 : NULL);
5074 108936174 : if (!reloc
5075 : /* An absolute value is required with reverse SSO. */
5076 108936174 : || (reloc != null_pointer_node
5077 10144267 : && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (value))
5078 1 : && !AGGREGATE_TYPE_P (TREE_TYPE (elt))))
5079 : {
5080 404 : if (cache)
5081 : {
5082 0 : cache[0] = value;
5083 0 : cache[1] = NULL_TREE;
5084 : }
5085 : return NULL_TREE;
5086 : }
5087 108935770 : if (reloc != null_pointer_node)
5088 10144266 : absolute = false;
5089 : }
5090 : /* For a non-absolute relocation, there is no single
5091 : variable that can be "the variable that determines the
5092 : relocation." */
5093 13065384 : if (cache)
5094 : {
5095 0 : cache[0] = value;
5096 0 : cache[1] = absolute ? null_pointer_node : error_mark_node;
5097 : }
5098 13065384 : return absolute ? null_pointer_node : error_mark_node;
5099 : }
5100 :
5101 11279 : return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
5102 :
5103 1287114530 : case INTEGER_CST:
5104 1287114530 : case VECTOR_CST:
5105 1287114530 : case REAL_CST:
5106 1287114530 : case FIXED_CST:
5107 1287114530 : case STRING_CST:
5108 1287114530 : case COMPLEX_CST:
5109 1287114530 : case RAW_DATA_CST:
5110 1287114530 : return null_pointer_node;
5111 :
5112 53330201 : case ADDR_EXPR:
5113 53330201 : case FDESC_EXPR:
5114 53330201 : {
5115 53330201 : tree op0 = staticp (TREE_OPERAND (value, 0));
5116 53330201 : if (op0)
5117 : {
5118 : /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
5119 : to be a constant, this is old-skool offsetof-like nonsense. */
5120 50528503 : if (TREE_CODE (op0) == INDIRECT_REF
5121 50528503 : && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
5122 46 : return null_pointer_node;
5123 : /* Taking the address of a nested function involves a trampoline,
5124 : unless we don't need or want one. */
5125 50528457 : if (TREE_CODE (op0) == FUNCTION_DECL
5126 9318050 : && DECL_STATIC_CHAIN (op0)
5127 50528472 : && !TREE_NO_TRAMPOLINE (value))
5128 : return NULL_TREE;
5129 : /* "&{...}" requires a temporary to hold the constructed
5130 : object. */
5131 50528442 : if (TREE_CODE (op0) == CONSTRUCTOR)
5132 0 : return NULL_TREE;
5133 : }
5134 : return op0;
5135 : }
5136 :
5137 1174359 : case NON_LVALUE_EXPR:
5138 1174359 : return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
5139 1174359 : endtype, cache);
5140 :
5141 2299970 : case VIEW_CONVERT_EXPR:
5142 2299970 : {
5143 2299970 : tree src = TREE_OPERAND (value, 0);
5144 2299970 : tree src_type = TREE_TYPE (src);
5145 2299970 : tree dest_type = TREE_TYPE (value);
5146 :
5147 : /* Allow view-conversions from aggregate to non-aggregate type only
5148 : if the bit pattern is fully preserved afterwards; otherwise, the
5149 : RTL expander won't be able to apply a subsequent transformation
5150 : to the underlying constructor. */
5151 2299970 : if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
5152 : {
5153 0 : if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
5154 : return initializer_constant_valid_p_1 (src, endtype, cache);
5155 : else
5156 : return NULL_TREE;
5157 : }
5158 :
5159 : /* Allow all other kinds of view-conversion. */
5160 : return initializer_constant_valid_p_1 (src, endtype, cache);
5161 : }
5162 :
5163 52096495 : CASE_CONVERT:
5164 52096495 : {
5165 52096495 : tree src = TREE_OPERAND (value, 0);
5166 52096495 : tree src_type = TREE_TYPE (src);
5167 52096495 : tree dest_type = TREE_TYPE (value);
5168 :
5169 : /* Allow conversions between pointer types and offset types. */
5170 52096495 : if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
5171 2657426 : || (TREE_CODE (dest_type) == OFFSET_TYPE
5172 85 : && TREE_CODE (src_type) == OFFSET_TYPE))
5173 : return initializer_constant_valid_p_1 (src, endtype, cache);
5174 :
5175 : /* Allow length-preserving conversions between integer types and
5176 : floating-point types. */
5177 2395089 : if (((INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
5178 334601 : || (SCALAR_FLOAT_TYPE_P (dest_type)
5179 66252 : && SCALAR_FLOAT_TYPE_P (src_type)))
5180 5046369 : && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
5181 : return initializer_constant_valid_p_1 (src, endtype, cache);
5182 :
5183 : /* Allow conversions between other integer types only if
5184 : explicit value. Don't allow sign-extension to a type larger
5185 : than word and pointer, there aren't relocations that would
5186 : allow to sign extend it to a wider type. */
5187 729116 : if (INTEGRAL_TYPE_P (dest_type)
5188 530505 : && INTEGRAL_TYPE_P (src_type)
5189 1187290 : && (TYPE_UNSIGNED (src_type)
5190 141464 : || TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type)
5191 80699 : || TYPE_PRECISION (dest_type) <= BITS_PER_WORD
5192 757 : || TYPE_PRECISION (dest_type) <= POINTER_SIZE))
5193 : {
5194 457778 : tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
5195 457778 : if (inner == null_pointer_node)
5196 377 : return null_pointer_node;
5197 : break;
5198 : }
5199 :
5200 : /* Allow (int) &foo provided int is as wide as a pointer. */
5201 72727 : if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
5202 343654 : && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
5203 : return initializer_constant_valid_p_1 (src, endtype, cache);
5204 :
5205 : /* Likewise conversions from int to pointers, but also allow
5206 : conversions from 0. */
5207 199208 : if ((POINTER_TYPE_P (dest_type)
5208 121123 : || TREE_CODE (dest_type) == OFFSET_TYPE)
5209 78103 : && INTEGRAL_TYPE_P (src_type))
5210 : {
5211 565 : if (TREE_CODE (src) == INTEGER_CST
5212 565 : && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
5213 16 : return null_pointer_node;
5214 549 : if (integer_zerop (src))
5215 0 : return null_pointer_node;
5216 549 : else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
5217 : return initializer_constant_valid_p_1 (src, endtype, cache);
5218 : }
5219 :
5220 : /* Allow conversions to struct or union types if the value
5221 : inside is okay. */
5222 198643 : if (TREE_CODE (dest_type) == RECORD_TYPE
5223 198643 : || TREE_CODE (dest_type) == UNION_TYPE)
5224 : return initializer_constant_valid_p_1 (src, endtype, cache);
5225 : }
5226 : break;
5227 :
5228 7351615 : case POINTER_PLUS_EXPR:
5229 7351615 : case PLUS_EXPR:
5230 : /* Any valid floating-point constants will have been folded by now;
5231 : with -frounding-math we hit this with addition of two constants. */
5232 7351615 : if (TREE_CODE (endtype) == REAL_TYPE)
5233 : return NULL_TREE;
5234 6355254 : if (cache && cache[0] == value)
5235 133193 : return cache[1];
5236 6222061 : if (! INTEGRAL_TYPE_P (endtype)
5237 743099 : || ! INTEGRAL_TYPE_P (TREE_TYPE (value))
5238 6964500 : || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
5239 : {
5240 6203419 : tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
5241 6203419 : tree valid0
5242 6203419 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
5243 : endtype, ncache);
5244 6203419 : tree valid1
5245 6203419 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
5246 : endtype, ncache + 2);
5247 : /* If either term is absolute, use the other term's relocation. */
5248 6203419 : if (valid0 == null_pointer_node)
5249 : ret = valid1;
5250 6201946 : else if (valid1 == null_pointer_node)
5251 : ret = valid0;
5252 : /* Support narrowing pointer differences. */
5253 : else
5254 442764 : ret = narrowing_initializer_constant_valid_p (value, endtype,
5255 : ncache);
5256 : }
5257 : else
5258 : /* Support narrowing pointer differences. */
5259 18642 : ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
5260 6222061 : if (cache)
5261 : {
5262 148039 : cache[0] = value;
5263 148039 : cache[1] = ret;
5264 : }
5265 : return ret;
5266 :
5267 1534104 : case POINTER_DIFF_EXPR:
5268 1534104 : case MINUS_EXPR:
5269 1534104 : if (TREE_CODE (endtype) == REAL_TYPE)
5270 : return NULL_TREE;
5271 1032094 : if (cache && cache[0] == value)
5272 160478 : return cache[1];
5273 871616 : if (! INTEGRAL_TYPE_P (endtype)
5274 871521 : || ! INTEGRAL_TYPE_P (TREE_TYPE (value))
5275 1743134 : || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
5276 : {
5277 837582 : tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
5278 837582 : tree valid0
5279 837582 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
5280 : endtype, ncache);
5281 837582 : tree valid1
5282 837582 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
5283 : endtype, ncache + 2);
5284 : /* Win if second argument is absolute. */
5285 837582 : if (valid1 == null_pointer_node)
5286 : ret = valid0;
5287 : /* Win if both arguments have the same relocation.
5288 : Then the value is absolute. */
5289 633294 : else if (valid0 == valid1 && valid0 != 0)
5290 : ret = null_pointer_node;
5291 : /* Since GCC guarantees that string constants are unique in the
5292 : generated code, a subtraction between two copies of the same
5293 : constant string is absolute. */
5294 794 : else if (valid0 && TREE_CODE (valid0) == STRING_CST
5295 0 : && valid1 && TREE_CODE (valid1) == STRING_CST
5296 633294 : && operand_equal_p (valid0, valid1, 1))
5297 0 : ret = null_pointer_node;
5298 : /* Support narrowing differences. */
5299 : else
5300 633294 : ret = narrowing_initializer_constant_valid_p (value, endtype,
5301 : ncache);
5302 : }
5303 : else
5304 : /* Support narrowing differences. */
5305 34034 : ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
5306 871616 : if (cache)
5307 : {
5308 162354 : cache[0] = value;
5309 162354 : cache[1] = ret;
5310 : }
5311 : return ret;
5312 :
5313 : default:
5314 : break;
5315 : }
5316 :
5317 : return NULL_TREE;
5318 : }
5319 :
5320 : /* Return nonzero if VALUE is a valid constant-valued expression
5321 : for use in initializing a static variable; one that can be an
5322 : element of a "constant" initializer.
5323 :
5324 : Return null_pointer_node if the value is absolute;
5325 : if it is relocatable, return the variable that determines the relocation.
5326 : We assume that VALUE has been folded as much as possible;
5327 : therefore, we do not need to check for such things as
5328 : arithmetic-combinations of integers. */
5329 : tree
5330 1254258993 : initializer_constant_valid_p (tree value, tree endtype, bool reverse)
5331 : {
5332 1254258993 : tree reloc = initializer_constant_valid_p_1 (value, endtype, NULL);
5333 :
5334 : /* An absolute value is required with reverse storage order. */
5335 1254258993 : if (reloc
5336 1235815155 : && reloc != null_pointer_node
5337 47183116 : && reverse
5338 1 : && !AGGREGATE_TYPE_P (endtype)
5339 1 : && !VECTOR_TYPE_P (endtype))
5340 1254258993 : reloc = NULL_TREE;
5341 :
5342 1254258993 : return reloc;
5343 : }
5344 :
5345 : /* Return true if VALUE is a valid constant-valued expression
5346 : for use in initializing a static bit-field; one that can be
5347 : an element of a "constant" initializer. */
5348 :
5349 : bool
5350 885 : initializer_constant_valid_for_bitfield_p (const_tree value)
5351 : {
5352 : /* For bitfields we support integer constants or possibly nested aggregates
5353 : of such. */
5354 885 : switch (TREE_CODE (value))
5355 : {
5356 : case CONSTRUCTOR:
5357 : {
5358 : unsigned HOST_WIDE_INT idx;
5359 : const_tree elt;
5360 :
5361 957 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
5362 696 : if (!initializer_constant_valid_for_bitfield_p (elt))
5363 : return false;
5364 : return true;
5365 : }
5366 :
5367 : case INTEGER_CST:
5368 : case REAL_CST:
5369 : return true;
5370 :
5371 0 : case VIEW_CONVERT_EXPR:
5372 0 : case NON_LVALUE_EXPR:
5373 0 : return
5374 0 : initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
5375 :
5376 : default:
5377 : break;
5378 : }
5379 :
5380 : return false;
5381 : }
5382 :
5383 : /* Check if a STRING_CST fits into the field.
5384 : Tolerate only the case when the NUL termination
5385 : does not fit into the field. */
5386 :
5387 : static bool
5388 1337192 : check_string_literal (tree string, unsigned HOST_WIDE_INT size)
5389 : {
5390 1337192 : tree type = TREE_TYPE (string);
5391 1337192 : tree eltype = TREE_TYPE (type);
5392 1337192 : unsigned HOST_WIDE_INT elts = tree_to_uhwi (TYPE_SIZE_UNIT (eltype));
5393 1337192 : unsigned HOST_WIDE_INT mem_size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
5394 1337192 : int len = TREE_STRING_LENGTH (string);
5395 :
5396 1337192 : if (elts != 1 && elts != 2 && elts != 4)
5397 : return false;
5398 1337192 : if (len < 0 || len % elts != 0)
5399 : return false;
5400 1337192 : if (size < (unsigned)len)
5401 : return false;
5402 1337192 : if (mem_size != size)
5403 0 : return false;
5404 : return true;
5405 : }
5406 :
5407 : /* output_constructor outer state of relevance in recursive calls, typically
5408 : for nested aggregate bitfields. */
5409 :
5410 : struct oc_outer_state {
5411 : unsigned int bit_offset; /* current position in ... */
5412 : int byte; /* ... the outer byte buffer. */
5413 : };
5414 :
5415 : static unsigned HOST_WIDE_INT
5416 : output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int, bool,
5417 : oc_outer_state *);
5418 :
5419 : /* Output assembler code for constant EXP, with no label.
5420 : This includes the pseudo-op such as ".int" or ".byte", and a newline.
5421 : Assumes output_addressed_constants has been done on EXP already.
5422 :
5423 : Generate at least SIZE bytes of assembler data, padding at the end
5424 : with zeros if necessary. SIZE must always be specified. The returned
5425 : value is the actual number of bytes of assembler data generated, which
5426 : may be bigger than SIZE if the object contains a variable length field.
5427 :
5428 : SIZE is important for structure constructors,
5429 : since trailing members may have been omitted from the constructor.
5430 : It is also important for initialization of arrays from string constants
5431 : since the full length of the string constant might not be wanted.
5432 : It is also needed for initialization of unions, where the initializer's
5433 : type is just one member, and that may not be as long as the union.
5434 :
5435 : There a case in which we would fail to output exactly SIZE bytes:
5436 : for a structure constructor that wants to produce more than SIZE bytes.
5437 : But such constructors will never be generated for any possible input.
5438 :
5439 : ALIGN is the alignment of the data in bits.
5440 :
5441 : If REVERSE is true, EXP is output in reverse storage order. */
5442 :
5443 : static unsigned HOST_WIDE_INT
5444 18024010 : output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align,
5445 : bool reverse, bool merge_strings)
5446 : {
5447 18024010 : enum tree_code code;
5448 18024010 : unsigned HOST_WIDE_INT thissize;
5449 18024010 : rtx cst;
5450 :
5451 18024010 : if (size == 0 || flag_syntax_only)
5452 : return size;
5453 :
5454 : /* See if we're trying to initialize a pointer in a non-default mode
5455 : to the address of some declaration somewhere. If the target says
5456 : the mode is valid for pointers, assume the target has a way of
5457 : resolving it. */
5458 18023763 : if (TREE_CODE (exp) == NOP_EXPR
5459 192 : && POINTER_TYPE_P (TREE_TYPE (exp))
5460 18023909 : && targetm.addr_space.valid_pointer_mode
5461 18023763 : (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp)),
5462 146 : TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
5463 : {
5464 146 : tree saved_type = TREE_TYPE (exp);
5465 :
5466 : /* Peel off any intermediate conversions-to-pointer for valid
5467 : pointer modes. */
5468 146 : while (TREE_CODE (exp) == NOP_EXPR
5469 146 : && POINTER_TYPE_P (TREE_TYPE (exp))
5470 438 : && targetm.addr_space.valid_pointer_mode
5471 146 : (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp)),
5472 146 : TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
5473 146 : exp = TREE_OPERAND (exp, 0);
5474 :
5475 : /* If what we're left with is the address of something, we can
5476 : convert the address to the final type and output it that
5477 : way. */
5478 146 : if (TREE_CODE (exp) == ADDR_EXPR)
5479 11 : exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
5480 : /* Likewise for constant ints. */
5481 135 : else if (TREE_CODE (exp) == INTEGER_CST)
5482 135 : exp = fold_convert (saved_type, exp);
5483 :
5484 : }
5485 :
5486 : /* Eliminate any conversions since we'll be outputting the underlying
5487 : constant. */
5488 18027032 : while (CONVERT_EXPR_P (exp)
5489 18026993 : || TREE_CODE (exp) == NON_LVALUE_EXPR
5490 36054071 : || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
5491 : {
5492 3321 : HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
5493 3321 : HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
5494 :
5495 : /* Make sure eliminating the conversion is really a no-op, except with
5496 : VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
5497 : union types to allow for Ada unchecked unions. */
5498 3321 : if (type_size > op_size
5499 6 : && TREE_CODE (exp) != VIEW_CONVERT_EXPR
5500 3327 : && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
5501 : /* Keep the conversion. */
5502 : break;
5503 : else
5504 3315 : exp = TREE_OPERAND (exp, 0);
5505 : }
5506 :
5507 18023763 : code = TREE_CODE (TREE_TYPE (exp));
5508 18023763 : thissize = int_size_in_bytes (TREE_TYPE (exp));
5509 :
5510 : /* Allow a constructor with no elements for any data type.
5511 : This means to fill the space with zeros. */
5512 18023763 : if (TREE_CODE (exp) == CONSTRUCTOR
5513 18023763 : && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp)))
5514 : {
5515 3099 : assemble_zeros (size);
5516 3099 : return size;
5517 : }
5518 :
5519 18020664 : if (TREE_CODE (exp) == FDESC_EXPR)
5520 : {
5521 : #ifdef ASM_OUTPUT_FDESC
5522 : HOST_WIDE_INT part = tree_to_shwi (TREE_OPERAND (exp, 1));
5523 : tree decl = TREE_OPERAND (exp, 0);
5524 : ASM_OUTPUT_FDESC (asm_out_file, decl, part);
5525 : #else
5526 0 : gcc_unreachable ();
5527 : #endif
5528 : return size;
5529 : }
5530 :
5531 : /* Now output the underlying data. If we've handling the padding, return.
5532 : Otherwise, break and ensure SIZE is the size written. */
5533 18020664 : switch (code)
5534 : {
5535 21457 : case ENUMERAL_TYPE:
5536 21457 : if (BITINT_TYPE_P (TREE_TYPE (exp)))
5537 14 : goto do_bitint;
5538 : /* FALLTHRU */
5539 12247595 : case BOOLEAN_TYPE:
5540 12247595 : case INTEGER_TYPE:
5541 12247595 : case POINTER_TYPE:
5542 12247595 : case REFERENCE_TYPE:
5543 12247595 : case OFFSET_TYPE:
5544 12247595 : case FIXED_POINT_TYPE:
5545 12247595 : case NULLPTR_TYPE:
5546 12247595 : cst = expand_expr (exp, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
5547 12247595 : if (reverse)
5548 558 : cst = flip_storage_order (TYPE_MODE (TREE_TYPE (exp)), cst);
5549 12247595 : if (!assemble_integer (cst, MIN (size, thissize), align, 0))
5550 0 : error ("initializer for integer/fixed-point value is too complicated");
5551 : break;
5552 :
5553 601229 : case REAL_TYPE:
5554 601229 : gcc_assert (size == thissize);
5555 601229 : if (TREE_CODE (exp) != REAL_CST)
5556 1 : error ("initializer for floating value is not a floating constant");
5557 : else
5558 601228 : assemble_real (TREE_REAL_CST (exp),
5559 601228 : SCALAR_FLOAT_TYPE_MODE (TREE_TYPE (exp)),
5560 : align, reverse);
5561 : break;
5562 :
5563 12142 : case COMPLEX_TYPE:
5564 12142 : output_constant (TREE_REALPART (exp), thissize / 2, align,
5565 : reverse, false);
5566 12142 : output_constant (TREE_IMAGPART (exp), thissize / 2,
5567 : min_align (align, BITS_PER_UNIT * (thissize / 2)),
5568 : reverse, false);
5569 12142 : break;
5570 :
5571 8997 : case BITINT_TYPE:
5572 8997 : do_bitint:
5573 8997 : if (TREE_CODE (exp) != INTEGER_CST)
5574 0 : error ("initializer for %<_BitInt(%d)%> value is not an integer "
5575 0 : "constant", TYPE_PRECISION (TREE_TYPE (exp)));
5576 : else
5577 : {
5578 8997 : struct bitint_info info;
5579 8997 : tree type = TREE_TYPE (exp);
5580 8997 : bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info);
5581 8997 : gcc_assert (ok);
5582 8997 : scalar_int_mode limb_mode
5583 8997 : = as_a <scalar_int_mode> (info.abi_limb_mode);
5584 8997 : if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode))
5585 : {
5586 511 : cst = expand_expr (exp, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
5587 511 : if (reverse)
5588 0 : cst = flip_storage_order (TYPE_MODE (TREE_TYPE (exp)), cst);
5589 511 : if (!assemble_integer (cst, MIN (size, thissize), align, 0))
5590 0 : error ("initializer for integer/fixed-point value is too "
5591 : "complicated");
5592 511 : break;
5593 : }
5594 8486 : int prec = GET_MODE_PRECISION (limb_mode);
5595 8486 : int cnt = CEIL (TYPE_PRECISION (type), prec);
5596 8486 : tree limb_type = build_nonstandard_integer_type (prec, 1);
5597 8486 : int elt_size = GET_MODE_SIZE (limb_mode);
5598 8486 : unsigned int nalign = MIN (align, GET_MODE_ALIGNMENT (limb_mode));
5599 8486 : thissize = 0;
5600 8486 : if (prec == HOST_BITS_PER_WIDE_INT)
5601 104552 : for (int i = 0; i < cnt; i++)
5602 : {
5603 96066 : int idx = (info.big_endian ^ reverse) ? cnt - 1 - i : i;
5604 96066 : tree c;
5605 96066 : if (idx >= TREE_INT_CST_EXT_NUNITS (exp))
5606 36211 : c = build_int_cst (limb_type,
5607 69917 : tree_int_cst_sgn (exp) < 0 ? -1 : 0);
5608 : else
5609 59855 : c = build_int_cst (limb_type,
5610 59855 : TREE_INT_CST_ELT (exp, idx));
5611 96066 : output_constant (c, elt_size, nalign, reverse, false);
5612 96066 : thissize += elt_size;
5613 : }
5614 : else
5615 0 : for (int i = 0; i < cnt; i++)
5616 : {
5617 0 : int idx = (info.big_endian ^ reverse) ? cnt - 1 - i : i;
5618 0 : wide_int w = wi::rshift (wi::to_wide (exp), idx * prec,
5619 0 : TYPE_SIGN (TREE_TYPE (exp)));
5620 0 : tree c = wide_int_to_tree (limb_type,
5621 0 : wide_int::from (w, prec, UNSIGNED));
5622 0 : output_constant (c, elt_size, nalign, reverse, false);
5623 0 : thissize += elt_size;
5624 0 : }
5625 : }
5626 : break;
5627 :
5628 1923166 : case ARRAY_TYPE:
5629 1923166 : case VECTOR_TYPE:
5630 1923166 : switch (TREE_CODE (exp))
5631 : {
5632 573679 : case CONSTRUCTOR:
5633 573679 : return output_constructor (exp, size, align, reverse, NULL);
5634 1337192 : case STRING_CST:
5635 1337192 : thissize = (unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp);
5636 1337192 : if (merge_strings
5637 1337192 : && (thissize == 0
5638 412832 : || TREE_STRING_POINTER (exp) [thissize - 1] != '\0'))
5639 34438 : thissize++;
5640 1337192 : gcc_checking_assert (check_string_literal (exp, size));
5641 1337192 : assemble_string (TREE_STRING_POINTER (exp), thissize);
5642 1337192 : break;
5643 12295 : case VECTOR_CST:
5644 12295 : {
5645 12295 : scalar_mode inner = SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
5646 12295 : unsigned int nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
5647 12295 : int elt_size = GET_MODE_SIZE (inner);
5648 12295 : output_constant (VECTOR_CST_ELT (exp, 0), elt_size, align,
5649 : reverse, false);
5650 12295 : thissize = elt_size;
5651 : /* Static constants must have a fixed size. */
5652 12295 : unsigned int nunits = VECTOR_CST_NELTS (exp).to_constant ();
5653 69538 : for (unsigned int i = 1; i < nunits; i++)
5654 : {
5655 57243 : output_constant (VECTOR_CST_ELT (exp, i), elt_size, nalign,
5656 : reverse, false);
5657 57243 : thissize += elt_size;
5658 : }
5659 : break;
5660 : }
5661 0 : default:
5662 0 : gcc_unreachable ();
5663 : }
5664 : break;
5665 :
5666 3227535 : case RECORD_TYPE:
5667 3227535 : case UNION_TYPE:
5668 3227535 : gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
5669 3227535 : return output_constructor (exp, size, align, reverse, NULL);
5670 :
5671 : case ERROR_MARK:
5672 : return 0;
5673 :
5674 0 : default:
5675 0 : gcc_unreachable ();
5676 : }
5677 :
5678 14219450 : if (size > thissize)
5679 719355 : assemble_zeros (size - thissize);
5680 :
5681 : return size;
5682 : }
5683 :
5684 : /* Subroutine of output_constructor, used for computing the size of
5685 : arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
5686 : type with an unspecified upper bound. */
5687 :
5688 : static unsigned HOST_WIDE_INT
5689 5538 : array_size_for_constructor (tree val)
5690 : {
5691 5538 : tree max_index;
5692 5538 : unsigned HOST_WIDE_INT cnt;
5693 5538 : tree index, value, tmp;
5694 5538 : offset_int i;
5695 :
5696 : /* This code used to attempt to handle string constants that are not
5697 : arrays of single-bytes, but nothing else does, so there's no point in
5698 : doing it here. */
5699 5538 : if (TREE_CODE (val) == STRING_CST)
5700 5363 : return TREE_STRING_LENGTH (val);
5701 :
5702 : max_index = NULL_TREE;
5703 491 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
5704 : {
5705 316 : if (TREE_CODE (index) == RANGE_EXPR)
5706 0 : index = TREE_OPERAND (index, 1);
5707 316 : if (value && TREE_CODE (value) == RAW_DATA_CST)
5708 8 : index = size_binop (PLUS_EXPR, index,
5709 : build_int_cst (TREE_TYPE (index),
5710 : RAW_DATA_LENGTH (value) - 1));
5711 316 : if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
5712 : max_index = index;
5713 : }
5714 :
5715 175 : if (max_index == NULL_TREE)
5716 : return 0;
5717 :
5718 : /* Compute the total number of array elements. */
5719 136 : tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
5720 136 : i = wi::to_offset (max_index) - wi::to_offset (tmp) + 1;
5721 :
5722 : /* Multiply by the array element unit size to find number of bytes. */
5723 136 : i *= wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
5724 :
5725 136 : gcc_assert (wi::fits_uhwi_p (i));
5726 136 : return i.to_uhwi ();
5727 : }
5728 :
5729 : /* Other datastructures + helpers for output_constructor. */
5730 :
5731 : /* output_constructor local state to support interaction with helpers. */
5732 :
5733 : struct oc_local_state {
5734 :
5735 : /* Received arguments. */
5736 : tree exp; /* Constructor expression. */
5737 : tree type; /* Type of constructor expression. */
5738 : unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
5739 : unsigned int align; /* Known initial alignment. */
5740 : tree min_index; /* Lower bound if specified for an array. */
5741 :
5742 : /* Output processing state. */
5743 : HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
5744 : int byte; /* Part of a bitfield byte yet to be output. */
5745 : int last_relative_index; /* Implicit or explicit index of the last
5746 : array element output within a bitfield. */
5747 : bool byte_buffer_in_use; /* Whether BYTE is in use. */
5748 : bool reverse; /* Whether reverse storage order is in use. */
5749 :
5750 : /* Current element. */
5751 : tree field; /* Current field decl in a record. */
5752 : tree val; /* Current element value. */
5753 : tree index; /* Current element index. */
5754 :
5755 : };
5756 :
5757 : /* Helper for output_constructor. From the current LOCAL state, output a
5758 : RANGE_EXPR element. */
5759 :
5760 : static void
5761 957 : output_constructor_array_range (oc_local_state *local)
5762 : {
5763 : /* Perform the index calculation in modulo arithmetic but
5764 : sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5765 : but we are using an unsigned sizetype. */
5766 957 : unsigned prec = TYPE_PRECISION (sizetype);
5767 957 : offset_int idx = wi::sext (wi::to_offset (TREE_OPERAND (local->index, 0))
5768 1914 : - wi::to_offset (local->min_index), prec);
5769 957 : tree valtype = TREE_TYPE (local->val);
5770 957 : HOST_WIDE_INT fieldpos
5771 957 : = (idx * wi::to_offset (TYPE_SIZE_UNIT (valtype))).to_short_addr ();
5772 :
5773 : /* Advance to offset of this element. */
5774 957 : if (fieldpos > local->total_bytes)
5775 : {
5776 8 : assemble_zeros (fieldpos - local->total_bytes);
5777 8 : local->total_bytes = fieldpos;
5778 : }
5779 : else
5780 : /* Must not go backwards. */
5781 949 : gcc_assert (fieldpos == local->total_bytes);
5782 :
5783 957 : unsigned HOST_WIDE_INT fieldsize
5784 957 : = int_size_in_bytes (TREE_TYPE (local->type));
5785 :
5786 957 : HOST_WIDE_INT lo_index
5787 957 : = tree_to_shwi (TREE_OPERAND (local->index, 0));
5788 957 : HOST_WIDE_INT hi_index
5789 957 : = tree_to_shwi (TREE_OPERAND (local->index, 1));
5790 957 : HOST_WIDE_INT index;
5791 :
5792 957 : unsigned int align2
5793 957 : = min_align (local->align, fieldsize * BITS_PER_UNIT);
5794 :
5795 275554 : for (index = lo_index; index <= hi_index; index++)
5796 : {
5797 : /* Output the element's initial value. */
5798 274597 : if (local->val == NULL_TREE)
5799 0 : assemble_zeros (fieldsize);
5800 : else
5801 274597 : fieldsize = output_constant (local->val, fieldsize, align2,
5802 : local->reverse, false);
5803 :
5804 : /* Count its size. */
5805 274597 : local->total_bytes += fieldsize;
5806 : }
5807 957 : }
5808 :
5809 : /* Helper for output_constructor. From the current LOCAL state, output a
5810 : field element that is not true bitfield or part of an outer one. */
5811 :
5812 : static void
5813 14448247 : output_constructor_regular_field (oc_local_state *local)
5814 : {
5815 : /* Field size and position. Since this structure is static, we know the
5816 : positions are constant. */
5817 14448247 : unsigned HOST_WIDE_INT fieldsize;
5818 14448247 : HOST_WIDE_INT fieldpos;
5819 :
5820 14448247 : unsigned int align2;
5821 :
5822 : /* Output any buffered-up bit-fields preceding this element. */
5823 14448247 : if (local->byte_buffer_in_use)
5824 : {
5825 500 : assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5826 500 : local->total_bytes++;
5827 500 : local->byte_buffer_in_use = false;
5828 : }
5829 :
5830 14448247 : if (local->index != NULL_TREE)
5831 : {
5832 : /* Perform the index calculation in modulo arithmetic but
5833 : sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5834 : but we are using an unsigned sizetype. */
5835 4021345 : unsigned prec = TYPE_PRECISION (sizetype);
5836 4021345 : offset_int idx = wi::sext (wi::to_offset (local->index)
5837 8042690 : - wi::to_offset (local->min_index), prec);
5838 4021345 : fieldpos = (idx * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local->val))))
5839 4021345 : .to_short_addr ();
5840 : }
5841 10426902 : else if (local->field != NULL_TREE)
5842 9568058 : fieldpos = int_byte_position (local->field);
5843 : else
5844 : fieldpos = 0;
5845 :
5846 : /* Advance to offset of this element.
5847 : Note no alignment needed in an array, since that is guaranteed
5848 : if each element has the proper size. */
5849 14448247 : if (local->field != NULL_TREE || local->index != NULL_TREE)
5850 : {
5851 13589403 : if (fieldpos > local->total_bytes)
5852 : {
5853 179543 : assemble_zeros (fieldpos - local->total_bytes);
5854 179543 : local->total_bytes = fieldpos;
5855 : }
5856 : else
5857 : /* Must not go backwards. */
5858 13409860 : gcc_assert (fieldpos == local->total_bytes);
5859 : }
5860 :
5861 : /* Find the alignment of this element. */
5862 14448247 : align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
5863 :
5864 : /* Determine size this element should occupy. */
5865 14448247 : if (local->field)
5866 : {
5867 9568058 : fieldsize = 0;
5868 :
5869 : /* If this is an array with an unspecified upper bound,
5870 : the initializer determines the size. */
5871 : /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5872 : but we cannot do this until the deprecated support for
5873 : initializing zero-length array members is removed. */
5874 9568058 : if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
5875 9568058 : && (!TYPE_DOMAIN (TREE_TYPE (local->field))
5876 182891 : || !TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field)))))
5877 : {
5878 5538 : unsigned HOST_WIDE_INT fldsize
5879 5538 : = array_size_for_constructor (local->val);
5880 5538 : fieldsize = int_size_in_bytes (TREE_TYPE (local->val));
5881 : /* In most cases fieldsize == fldsize as the size of the initializer
5882 : determines how many elements the flexible array member has. For
5883 : C++ fldsize can be smaller though, if the last or several last or
5884 : all initializers of the flexible array member have side-effects
5885 : and the FE splits them into dynamic initialization. */
5886 5538 : gcc_checking_assert (fieldsize >= fldsize);
5887 : /* Given a non-empty initialization, this field had better
5888 : be last except in unions. Given a flexible array member, the next
5889 : field on the chain is a TYPE_DECL of the enclosing struct. */
5890 5538 : const_tree next = DECL_CHAIN (local->field);
5891 5538 : gcc_assert (!fieldsize
5892 : || !next
5893 : || TREE_CODE (next) != FIELD_DECL
5894 : || TREE_CODE (local->type) == UNION_TYPE);
5895 : }
5896 : else
5897 9562520 : fieldsize = tree_to_uhwi (DECL_SIZE_UNIT (local->field));
5898 : }
5899 : else
5900 4880189 : fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
5901 :
5902 : /* Output the element's initial value. */
5903 14448247 : if (local->val == NULL_TREE)
5904 0 : assemble_zeros (fieldsize);
5905 14448247 : else if (local->val && TREE_CODE (local->val) == RAW_DATA_CST)
5906 : {
5907 442 : fieldsize *= RAW_DATA_LENGTH (local->val);
5908 442 : assemble_string (RAW_DATA_POINTER (local->val),
5909 442 : RAW_DATA_LENGTH (local->val));
5910 : }
5911 : else
5912 14447805 : fieldsize = output_constant (local->val, fieldsize, align2,
5913 : local->reverse, false);
5914 :
5915 : /* Count its size. */
5916 14448247 : local->total_bytes += fieldsize;
5917 14448247 : }
5918 :
5919 : /* Helper for output_constructor. From the LOCAL state, output an element
5920 : that is a true bitfield or part of an outer one. BIT_OFFSET is the offset
5921 : from the start of a possibly ongoing outer byte buffer. */
5922 :
5923 : static void
5924 9774 : output_constructor_bitfield (oc_local_state *local, unsigned int bit_offset)
5925 : {
5926 : /* Bit size of this element. */
5927 9774 : HOST_WIDE_INT ebitsize
5928 9774 : = (local->field
5929 9774 : ? tree_to_uhwi (DECL_SIZE (local->field))
5930 9774 : : tree_to_uhwi (TYPE_SIZE (TREE_TYPE (local->type))));
5931 :
5932 : /* Relative index of this element if this is an array component. */
5933 9774 : HOST_WIDE_INT relative_index
5934 : = (local->field
5935 9774 : ? 0
5936 0 : : (local->index
5937 0 : ? tree_to_uhwi (local->index) - tree_to_uhwi (local->min_index)
5938 0 : : local->last_relative_index + 1));
5939 :
5940 : /* Bit position of this element from the start of the containing
5941 : constructor. */
5942 9774 : HOST_WIDE_INT constructor_relative_ebitpos
5943 : = (local->field
5944 9774 : ? int_bit_position (local->field)
5945 0 : : ebitsize * relative_index);
5946 :
5947 : /* Bit position of this element from the start of a possibly ongoing
5948 : outer byte buffer. */
5949 9774 : HOST_WIDE_INT byte_relative_ebitpos
5950 9774 : = bit_offset + constructor_relative_ebitpos;
5951 :
5952 : /* From the start of a possibly ongoing outer byte buffer, offsets to
5953 : the first bit of this element and to the first bit past the end of
5954 : this element. */
5955 9774 : HOST_WIDE_INT next_offset = byte_relative_ebitpos;
5956 9774 : HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
5957 :
5958 9774 : local->last_relative_index = relative_index;
5959 :
5960 9774 : if (local->val == NULL_TREE)
5961 0 : local->val = integer_zero_node;
5962 :
5963 9774 : while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
5964 9774 : || TREE_CODE (local->val) == NON_LVALUE_EXPR)
5965 0 : local->val = TREE_OPERAND (local->val, 0);
5966 :
5967 9774 : if (TREE_CODE (local->val) != INTEGER_CST
5968 0 : && TREE_CODE (local->val) != CONSTRUCTOR)
5969 : {
5970 0 : error ("invalid initial value for member %qE", DECL_NAME (local->field));
5971 0 : return;
5972 : }
5973 :
5974 : /* If this field does not start in this (or next) byte, skip some bytes. */
5975 9774 : if (next_offset / BITS_PER_UNIT != local->total_bytes)
5976 : {
5977 : /* Output remnant of any bit field in previous bytes. */
5978 1300 : if (local->byte_buffer_in_use)
5979 : {
5980 1271 : assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5981 1271 : local->total_bytes++;
5982 1271 : local->byte_buffer_in_use = false;
5983 : }
5984 :
5985 : /* If still not at proper byte, advance to there. */
5986 1300 : if (next_offset / BITS_PER_UNIT != local->total_bytes)
5987 : {
5988 120 : gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
5989 120 : assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
5990 120 : local->total_bytes = next_offset / BITS_PER_UNIT;
5991 : }
5992 : }
5993 :
5994 : /* Set up the buffer if necessary. */
5995 9774 : if (!local->byte_buffer_in_use)
5996 : {
5997 4168 : local->byte = 0;
5998 4168 : if (ebitsize > 0)
5999 4168 : local->byte_buffer_in_use = true;
6000 : }
6001 :
6002 : /* If this is nested constructor, recurse passing the bit offset and the
6003 : pending data, then retrieve the new pending data afterwards. */
6004 9774 : if (TREE_CODE (local->val) == CONSTRUCTOR)
6005 : {
6006 0 : oc_outer_state temp_state;
6007 0 : temp_state.bit_offset = next_offset % BITS_PER_UNIT;
6008 0 : temp_state.byte = local->byte;
6009 0 : local->total_bytes
6010 0 : += output_constructor (local->val, 0, 0, local->reverse, &temp_state);
6011 0 : local->byte = temp_state.byte;
6012 0 : return;
6013 : }
6014 :
6015 : /* Otherwise, we must split the element into pieces that fall within
6016 : separate bytes, and combine each byte with previous or following
6017 : bit-fields. */
6018 40761 : while (next_offset < end_offset)
6019 : {
6020 30987 : int this_time;
6021 30987 : int shift;
6022 30987 : unsigned HOST_WIDE_INT value;
6023 30987 : HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
6024 30987 : HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
6025 :
6026 : /* Advance from byte to byte within this element when necessary. */
6027 51656 : while (next_byte != local->total_bytes)
6028 : {
6029 20669 : assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
6030 20669 : local->total_bytes++;
6031 20669 : local->byte = 0;
6032 : }
6033 :
6034 : /* Number of bits we can process at once (all part of the same byte). */
6035 30987 : this_time = MIN (end_offset - next_offset, BITS_PER_UNIT - next_bit);
6036 30987 : if (local->reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
6037 : {
6038 : /* For big-endian data, take the most significant bits (of the
6039 : bits that are significant) first and put them into bytes from
6040 : the most significant end. */
6041 778 : shift = end_offset - next_offset - this_time;
6042 :
6043 : /* Don't try to take a bunch of bits that cross
6044 : the word boundary in the INTEGER_CST. We can
6045 : only select bits from one element. */
6046 778 : if ((shift / HOST_BITS_PER_WIDE_INT)
6047 778 : != ((shift + this_time - 1) / HOST_BITS_PER_WIDE_INT))
6048 : {
6049 0 : const int end = shift + this_time - 1;
6050 0 : shift = end & -HOST_BITS_PER_WIDE_INT;
6051 0 : this_time = end - shift + 1;
6052 : }
6053 :
6054 : /* Now get the bits we want to insert. */
6055 778 : value = wi::extract_uhwi (wi::to_widest (local->val),
6056 : shift, this_time);
6057 :
6058 : /* Get the result. This works only when:
6059 : 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
6060 778 : local->byte |= value << (BITS_PER_UNIT - this_time - next_bit);
6061 : }
6062 : else
6063 : {
6064 : /* On little-endian machines, take the least significant bits of
6065 : the value first and pack them starting at the least significant
6066 : bits of the bytes. */
6067 30209 : shift = next_offset - byte_relative_ebitpos;
6068 :
6069 : /* Don't try to take a bunch of bits that cross
6070 : the word boundary in the INTEGER_CST. We can
6071 : only select bits from one element. */
6072 30209 : if ((shift / HOST_BITS_PER_WIDE_INT)
6073 30209 : != ((shift + this_time - 1) / HOST_BITS_PER_WIDE_INT))
6074 544 : this_time
6075 544 : = HOST_BITS_PER_WIDE_INT - (shift & (HOST_BITS_PER_WIDE_INT - 1));
6076 :
6077 : /* Now get the bits we want to insert. */
6078 30209 : value = wi::extract_uhwi (wi::to_widest (local->val),
6079 : shift, this_time);
6080 :
6081 : /* Get the result. This works only when:
6082 : 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
6083 30209 : local->byte |= value << next_bit;
6084 : }
6085 :
6086 30987 : next_offset += this_time;
6087 30987 : local->byte_buffer_in_use = true;
6088 : }
6089 : }
6090 :
6091 : /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
6092 : Generate at least SIZE bytes, padding if necessary. OUTER designates the
6093 : caller output state of relevance in recursive invocations. */
6094 :
6095 : static unsigned HOST_WIDE_INT
6096 3801214 : output_constructor (tree exp, unsigned HOST_WIDE_INT size, unsigned int align,
6097 : bool reverse, oc_outer_state *outer)
6098 : {
6099 3801214 : unsigned HOST_WIDE_INT cnt;
6100 3801214 : constructor_elt *ce;
6101 3801214 : oc_local_state local;
6102 :
6103 : /* Setup our local state to communicate with helpers. */
6104 3801214 : local.exp = exp;
6105 3801214 : local.type = TREE_TYPE (exp);
6106 3801214 : local.size = size;
6107 3801214 : local.align = align;
6108 3801214 : if (TREE_CODE (local.type) == ARRAY_TYPE && TYPE_DOMAIN (local.type))
6109 573679 : local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
6110 : else
6111 3227535 : local.min_index = integer_zero_node;
6112 :
6113 3801214 : local.total_bytes = 0;
6114 3801214 : local.byte_buffer_in_use = outer != NULL;
6115 3801214 : local.byte = outer ? outer->byte : 0;
6116 3801214 : local.last_relative_index = -1;
6117 : /* The storage order is specified for every aggregate type. */
6118 3801214 : if (AGGREGATE_TYPE_P (local.type))
6119 3801214 : local.reverse = TYPE_REVERSE_STORAGE_ORDER (local.type);
6120 : else
6121 : local.reverse = reverse;
6122 :
6123 3801214 : gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
6124 :
6125 : /* As CE goes through the elements of the constant, FIELD goes through the
6126 : structure fields if the constant is a structure. If the constant is a
6127 : union, we override this by getting the field from the TREE_LIST element.
6128 : But the constant could also be an array. Then FIELD is zero.
6129 :
6130 : There is always a maximum of one element in the chain LINK for unions
6131 : (even if the initializer in a source program incorrectly contains
6132 : more one). */
6133 :
6134 3801214 : if (TREE_CODE (local.type) == RECORD_TYPE)
6135 3206890 : local.field = TYPE_FIELDS (local.type);
6136 : else
6137 : local.field = NULL_TREE;
6138 :
6139 3801214 : for (cnt = 0;
6140 18260192 : vec_safe_iterate (CONSTRUCTOR_ELTS (exp), cnt, &ce);
6141 14458978 : cnt++, local.field = local.field ? DECL_CHAIN (local.field) : 0)
6142 : {
6143 14458978 : local.val = ce->value;
6144 14458978 : local.index = NULL_TREE;
6145 :
6146 : /* The element in a union constructor specifies the proper field
6147 : or index. */
6148 14458978 : if (RECORD_OR_UNION_TYPE_P (local.type) && ce->index != NULL_TREE)
6149 9378782 : local.field = ce->index;
6150 :
6151 5080196 : else if (TREE_CODE (local.type) == ARRAY_TYPE)
6152 4881146 : local.index = ce->index;
6153 :
6154 14458978 : if (local.field && flag_verbose_asm)
6155 0 : fprintf (asm_out_file, "%s %s:\n",
6156 : ASM_COMMENT_START,
6157 0 : DECL_NAME (local.field)
6158 0 : ? IDENTIFIER_POINTER (DECL_NAME (local.field))
6159 : : "<anonymous>");
6160 :
6161 : /* Eliminate the marker that makes a cast not be an lvalue. */
6162 14458978 : if (local.val != NULL_TREE)
6163 14458978 : STRIP_NOPS (local.val);
6164 :
6165 : /* Output the current element, using the appropriate helper ... */
6166 :
6167 : /* For an array slice not part of an outer bitfield. */
6168 14458978 : if (!outer
6169 14458978 : && local.index != NULL_TREE
6170 4022302 : && TREE_CODE (local.index) == RANGE_EXPR)
6171 957 : output_constructor_array_range (&local);
6172 :
6173 : /* For a field that is neither a true bitfield nor part of an outer one,
6174 : known to be at least byte aligned and multiple-of-bytes long. */
6175 14458021 : else if (!outer
6176 14458021 : && (local.field == NULL_TREE
6177 9577832 : || !CONSTRUCTOR_BITFIELD_P (local.field)))
6178 14448247 : output_constructor_regular_field (&local);
6179 :
6180 : /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
6181 : supported for scalar fields, so we may need to convert first. */
6182 : else
6183 : {
6184 9774 : if (TREE_CODE (local.val) == REAL_CST)
6185 0 : local.val
6186 0 : = fold_unary (VIEW_CONVERT_EXPR,
6187 : build_nonstandard_integer_type
6188 : (TYPE_PRECISION (TREE_TYPE (local.val)), 0),
6189 : local.val);
6190 9774 : output_constructor_bitfield (&local, outer ? outer->bit_offset : 0);
6191 : }
6192 : }
6193 :
6194 : /* If we are not at toplevel, save the pending data for our caller.
6195 : Otherwise output the pending data and padding zeros as needed. */
6196 3801214 : if (outer)
6197 0 : outer->byte = local.byte;
6198 : else
6199 : {
6200 3801214 : if (local.byte_buffer_in_use)
6201 : {
6202 2397 : assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
6203 2397 : local.total_bytes++;
6204 : }
6205 :
6206 3801214 : if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
6207 : {
6208 52272 : assemble_zeros (local.size - local.total_bytes);
6209 52272 : local.total_bytes = local.size;
6210 : }
6211 : }
6212 :
6213 3801214 : return local.total_bytes;
6214 : }
6215 :
6216 : /* Mark DECL as weak. */
6217 :
6218 : static void
6219 128239 : mark_weak (tree decl)
6220 : {
6221 128239 : if (DECL_WEAK (decl))
6222 : return;
6223 :
6224 128225 : struct symtab_node *n = symtab_node::get (decl);
6225 128225 : if (n && n->refuse_visibility_changes)
6226 3 : error ("%qD declared weak after being used", decl);
6227 128225 : DECL_WEAK (decl) = 1;
6228 :
6229 128225 : if (DECL_RTL_SET_P (decl)
6230 0 : && MEM_P (DECL_RTL (decl))
6231 0 : && XEXP (DECL_RTL (decl), 0)
6232 128225 : && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
6233 0 : SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
6234 : }
6235 :
6236 : /* Merge weak status between NEWDECL and OLDDECL. */
6237 :
6238 : void
6239 21426988 : merge_weak (tree newdecl, tree olddecl)
6240 : {
6241 21426988 : if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
6242 : {
6243 21408968 : if (DECL_WEAK (newdecl) && TARGET_SUPPORTS_WEAK)
6244 : {
6245 : tree *pwd;
6246 : /* We put the NEWDECL on the weak_decls list at some point
6247 : and OLDDECL as well. Keep just OLDDECL on the list. */
6248 158 : for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
6249 0 : if (TREE_VALUE (*pwd) == newdecl)
6250 : {
6251 0 : *pwd = TREE_CHAIN (*pwd);
6252 0 : break;
6253 : }
6254 : }
6255 : return;
6256 : }
6257 :
6258 18020 : if (DECL_WEAK (newdecl))
6259 : {
6260 295 : tree wd;
6261 :
6262 : /* NEWDECL is weak, but OLDDECL is not. */
6263 :
6264 : /* If we already output the OLDDECL, we're in trouble; we can't
6265 : go back and make it weak. This should never happen in
6266 : unit-at-a-time compilation. */
6267 295 : gcc_assert (!TREE_ASM_WRITTEN (olddecl));
6268 :
6269 : /* If we've already generated rtl referencing OLDDECL, we may
6270 : have done so in a way that will not function properly with
6271 : a weak symbol. Again in unit-at-a-time this should be
6272 : impossible. */
6273 295 : gcc_assert (!TREE_USED (olddecl)
6274 : || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)));
6275 :
6276 : /* PR 49899: You cannot convert a static function into a weak, public function. */
6277 295 : if (! TREE_PUBLIC (olddecl) && TREE_PUBLIC (newdecl))
6278 1 : error ("weak declaration of %q+D being applied to a already "
6279 : "existing, static definition", newdecl);
6280 :
6281 295 : if (TARGET_SUPPORTS_WEAK)
6282 : {
6283 : /* We put the NEWDECL on the weak_decls list at some point.
6284 : Replace it with the OLDDECL. */
6285 295 : for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
6286 0 : if (TREE_VALUE (wd) == newdecl)
6287 : {
6288 0 : TREE_VALUE (wd) = olddecl;
6289 0 : break;
6290 : }
6291 : /* We may not find the entry on the list. If NEWDECL is a
6292 : weak alias, then we will have already called
6293 : globalize_decl to remove the entry; in that case, we do
6294 : not need to do anything. */
6295 : }
6296 :
6297 : /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
6298 295 : mark_weak (olddecl);
6299 : }
6300 : else
6301 : /* OLDDECL was weak, but NEWDECL was not explicitly marked as
6302 : weak. Just update NEWDECL to indicate that it's weak too. */
6303 17725 : mark_weak (newdecl);
6304 : }
6305 :
6306 : /* Declare DECL to be a weak symbol. */
6307 :
6308 : void
6309 110224 : declare_weak (tree decl)
6310 : {
6311 : /* With -fsyntax-only, TREE_ASM_WRITTEN might be set on certain function
6312 : decls earlier than normally, but as with -fsyntax-only nothing is really
6313 : emitted, there is no harm in marking it weak later. */
6314 110224 : gcc_assert (TREE_CODE (decl) != FUNCTION_DECL
6315 : || !TREE_ASM_WRITTEN (decl)
6316 : || flag_syntax_only);
6317 110224 : if (! TREE_PUBLIC (decl))
6318 : {
6319 5 : error ("weak declaration of %q+D must be public", decl);
6320 5 : return;
6321 : }
6322 110219 : else if (!TARGET_SUPPORTS_WEAK)
6323 : warning (0, "weak declaration of %q+D not supported", decl);
6324 :
6325 110219 : mark_weak (decl);
6326 110219 : if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
6327 110205 : DECL_ATTRIBUTES (decl)
6328 220410 : = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
6329 : }
6330 :
6331 : static void
6332 1012 : weak_finish_1 (tree decl)
6333 : {
6334 : #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
6335 1012 : const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6336 : #endif
6337 :
6338 1012 : if (! TREE_USED (decl))
6339 : return;
6340 :
6341 : #ifdef ASM_WEAKEN_DECL
6342 : ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
6343 : #else
6344 : #ifdef ASM_WEAKEN_LABEL
6345 1012 : ASM_WEAKEN_LABEL (asm_out_file, name);
6346 : #else
6347 : #ifdef ASM_OUTPUT_WEAK_ALIAS
6348 : {
6349 : static bool warn_once = 0;
6350 : if (! warn_once)
6351 : {
6352 : warning (0, "only weak aliases are supported in this configuration");
6353 : warn_once = 1;
6354 : }
6355 : return;
6356 : }
6357 : #endif
6358 : #endif
6359 : #endif
6360 : }
6361 :
6362 : /* Fiven an assembly name, find the decl it is associated with. */
6363 : static tree
6364 0 : find_decl (tree target)
6365 : {
6366 0 : symtab_node *node = symtab_node::get_for_asmname (target);
6367 0 : if (node)
6368 0 : return node->decl;
6369 : return NULL_TREE;
6370 : }
6371 :
6372 : /* This TREE_LIST contains weakref targets. */
6373 :
6374 : static GTY(()) tree weakref_targets;
6375 :
6376 : /* Emit any pending weak declarations. */
6377 :
6378 : void
6379 239445 : weak_finish (void)
6380 : {
6381 239445 : tree t;
6382 :
6383 239545 : for (t = weakref_targets; t; t = TREE_CHAIN (t))
6384 : {
6385 100 : tree alias_decl = TREE_PURPOSE (t);
6386 100 : tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
6387 :
6388 100 : if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl))
6389 200 : || TREE_SYMBOL_REFERENCED (target))
6390 : /* Remove alias_decl from the weak list, but leave entries for
6391 : the target alone. */
6392 : target = NULL_TREE;
6393 : #ifndef ASM_OUTPUT_WEAKREF
6394 : else if (! TREE_SYMBOL_REFERENCED (target))
6395 : {
6396 : /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
6397 : defined, otherwise we and weak_finish_1 would use
6398 : different macros. */
6399 : # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
6400 : ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
6401 : # else
6402 : tree decl = find_decl (target);
6403 :
6404 : if (! decl)
6405 : {
6406 : decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
6407 : TREE_CODE (alias_decl), target,
6408 : TREE_TYPE (alias_decl));
6409 :
6410 : DECL_EXTERNAL (decl) = 1;
6411 : TREE_PUBLIC (decl) = 1;
6412 : DECL_ARTIFICIAL (decl) = 1;
6413 : TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
6414 : TREE_USED (decl) = 1;
6415 : }
6416 :
6417 : weak_finish_1 (decl);
6418 : # endif
6419 : }
6420 : #endif
6421 :
6422 100 : {
6423 100 : tree *p;
6424 100 : tree t2;
6425 :
6426 : /* Remove the alias and the target from the pending weak list
6427 : so that we do not emit any .weak directives for the former,
6428 : nor multiple .weak directives for the latter. */
6429 168 : for (p = &weak_decls; (t2 = *p) ; )
6430 : {
6431 68 : if (TREE_VALUE (t2) == alias_decl
6432 68 : || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
6433 0 : *p = TREE_CHAIN (t2);
6434 : else
6435 68 : p = &TREE_CHAIN (t2);
6436 : }
6437 :
6438 : /* Remove other weakrefs to the same target, to speed things up. */
6439 212 : for (p = &TREE_CHAIN (t); (t2 = *p) ; )
6440 : {
6441 112 : if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
6442 0 : *p = TREE_CHAIN (t2);
6443 : else
6444 112 : p = &TREE_CHAIN (t2);
6445 : }
6446 : }
6447 : }
6448 :
6449 240457 : for (t = weak_decls; t; t = TREE_CHAIN (t))
6450 : {
6451 1012 : tree decl = TREE_VALUE (t);
6452 :
6453 1012 : weak_finish_1 (decl);
6454 : }
6455 239445 : }
6456 :
6457 : /* Emit the assembly bits to indicate that DECL is globally visible. */
6458 :
6459 : static void
6460 2709451 : globalize_decl (tree decl)
6461 : {
6462 :
6463 : #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
6464 2709451 : if (DECL_WEAK (decl))
6465 : {
6466 548920 : const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6467 548920 : tree *p, t;
6468 :
6469 : #ifdef ASM_WEAKEN_DECL
6470 : ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
6471 : #else
6472 548920 : ASM_WEAKEN_LABEL (asm_out_file, name);
6473 : #endif
6474 :
6475 : /* Remove this function from the pending weak list so that
6476 : we do not emit multiple .weak directives for it. */
6477 1102834 : for (p = &weak_decls; (t = *p) ; )
6478 : {
6479 4994 : if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
6480 0 : *p = TREE_CHAIN (t);
6481 : else
6482 4994 : p = &TREE_CHAIN (t);
6483 : }
6484 :
6485 : /* Remove weakrefs to the same target from the pending weakref
6486 : list, for the same reason. */
6487 548920 : for (p = &weakref_targets; (t = *p) ; )
6488 : {
6489 0 : if (DECL_ASSEMBLER_NAME (decl)
6490 0 : == ultimate_transparent_alias_target (&TREE_VALUE (t)))
6491 0 : *p = TREE_CHAIN (t);
6492 : else
6493 0 : p = &TREE_CHAIN (t);
6494 : }
6495 :
6496 : return;
6497 : }
6498 : #endif
6499 :
6500 2160531 : targetm.asm_out.globalize_decl_name (asm_out_file, decl);
6501 : }
6502 :
6503 : vec<alias_pair, va_gc> *alias_pairs;
6504 :
6505 : /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
6506 : or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
6507 : tree node is DECL to have the value of the tree node TARGET. */
6508 :
6509 : void
6510 68655 : do_assemble_alias (tree decl, tree target)
6511 : {
6512 68655 : tree id;
6513 :
6514 : /* Emulated TLS had better not get this var. */
6515 68655 : gcc_assert (!(!targetm.have_tls
6516 : && VAR_P (decl)
6517 : && DECL_THREAD_LOCAL_P (decl)));
6518 :
6519 68655 : if (TREE_ASM_WRITTEN (decl))
6520 127 : return;
6521 :
6522 68655 : id = DECL_ASSEMBLER_NAME (decl);
6523 68655 : ultimate_transparent_alias_target (&id);
6524 68655 : ultimate_transparent_alias_target (&target);
6525 :
6526 : /* We must force creation of DECL_RTL for debug info generation, even though
6527 : we don't use it here. */
6528 68655 : make_decl_rtl (decl);
6529 :
6530 68655 : TREE_ASM_WRITTEN (decl) = 1;
6531 68655 : TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
6532 68655 : TREE_ASM_WRITTEN (id) = 1;
6533 :
6534 68655 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
6535 : {
6536 127 : if (!TREE_SYMBOL_REFERENCED (target))
6537 100 : weakref_targets = tree_cons (decl, target, weakref_targets);
6538 :
6539 : #ifdef ASM_OUTPUT_WEAKREF
6540 127 : ASM_OUTPUT_WEAKREF (asm_out_file, decl,
6541 : IDENTIFIER_POINTER (id),
6542 : IDENTIFIER_POINTER (target));
6543 : #else
6544 : if (!TARGET_SUPPORTS_WEAK)
6545 : {
6546 : error_at (DECL_SOURCE_LOCATION (decl),
6547 : "%qs is not supported in this configuration", "weakref ");
6548 : return;
6549 : }
6550 : #endif
6551 127 : return;
6552 : }
6553 :
6554 : #ifdef ASM_OUTPUT_DEF
6555 68528 : tree orig_decl = decl;
6556 :
6557 : /* Make name accessible from other files, if appropriate. */
6558 :
6559 68528 : if (TREE_PUBLIC (decl) || TREE_PUBLIC (orig_decl))
6560 : {
6561 47825 : globalize_decl (decl);
6562 47825 : maybe_assemble_visibility (decl);
6563 : }
6564 68528 : if (TREE_CODE (decl) == FUNCTION_DECL
6565 68528 : && cgraph_node::get (decl)->ifunc_resolver)
6566 : {
6567 : #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
6568 286 : if (targetm.has_ifunc_p ())
6569 286 : ASM_OUTPUT_TYPE_DIRECTIVE
6570 : (asm_out_file, IDENTIFIER_POINTER (id),
6571 : IFUNC_ASM_TYPE);
6572 : else
6573 : #endif
6574 0 : error_at (DECL_SOURCE_LOCATION (decl),
6575 : "%qs is not supported on this target", "ifunc");
6576 : }
6577 :
6578 : # ifdef ASM_OUTPUT_DEF_FROM_DECLS
6579 : ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
6580 : # else
6581 68528 : ASM_OUTPUT_DEF (asm_out_file,
6582 : IDENTIFIER_POINTER (id),
6583 : IDENTIFIER_POINTER (target));
6584 : # endif
6585 : /* If symbol aliases aren't actually supported... */
6586 68528 : if (!TARGET_SUPPORTS_ALIASES
6587 : # ifdef ACCEL_COMPILER
6588 : /* ..., and unless special-cased... */
6589 : && !lookup_attribute ("symbol alias handled", DECL_ATTRIBUTES (decl))
6590 : # endif
6591 : )
6592 : /* ..., 'ASM_OUTPUT_DEF{,_FROM_DECLS}' better have raised an error. */
6593 : gcc_checking_assert (seen_error ());
6594 : #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
6595 : {
6596 : const char *name;
6597 : tree *p, t;
6598 :
6599 : name = IDENTIFIER_POINTER (id);
6600 : # ifdef ASM_WEAKEN_DECL
6601 : ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
6602 : # else
6603 : ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
6604 : # endif
6605 : /* Remove this function from the pending weak list so that
6606 : we do not emit multiple .weak directives for it. */
6607 : for (p = &weak_decls; (t = *p) ; )
6608 : if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t))
6609 : || id == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
6610 : *p = TREE_CHAIN (t);
6611 : else
6612 : p = &TREE_CHAIN (t);
6613 :
6614 : /* Remove weakrefs to the same target from the pending weakref
6615 : list, for the same reason. */
6616 : for (p = &weakref_targets; (t = *p) ; )
6617 : {
6618 : if (id == ultimate_transparent_alias_target (&TREE_VALUE (t)))
6619 : *p = TREE_CHAIN (t);
6620 : else
6621 : p = &TREE_CHAIN (t);
6622 : }
6623 : }
6624 : #endif
6625 : }
6626 :
6627 : /* Output .symver directive. */
6628 :
6629 : void
6630 2 : do_assemble_symver (tree decl, tree target)
6631 : {
6632 2 : tree id = DECL_ASSEMBLER_NAME (decl);
6633 2 : ultimate_transparent_alias_target (&id);
6634 2 : ultimate_transparent_alias_target (&target);
6635 : #ifdef ASM_OUTPUT_SYMVER_DIRECTIVE
6636 2 : ASM_OUTPUT_SYMVER_DIRECTIVE (asm_out_file,
6637 : IDENTIFIER_POINTER (target),
6638 : IDENTIFIER_POINTER (id));
6639 : #else
6640 : error ("symver is only supported on ELF platforms");
6641 : #endif
6642 2 : }
6643 :
6644 : /* Emit an assembler directive to make the symbol for DECL an alias to
6645 : the symbol for TARGET. */
6646 :
6647 : void
6648 5713 : assemble_alias (tree decl, tree target)
6649 : {
6650 5713 : tree target_decl;
6651 :
6652 5713 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
6653 : {
6654 460 : tree alias = DECL_ASSEMBLER_NAME (decl);
6655 :
6656 460 : ultimate_transparent_alias_target (&target);
6657 :
6658 460 : if (alias == target)
6659 0 : error ("%qs symbol %q+D ultimately targets itself", "weakref", decl);
6660 460 : if (TREE_PUBLIC (decl))
6661 1 : error ("%qs symbol %q+D must have static linkage", "weakref", decl);
6662 : }
6663 : else if (!TARGET_SUPPORTS_ALIASES)
6664 : {
6665 : # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
6666 : error_at (DECL_SOURCE_LOCATION (decl),
6667 : "alias definitions not supported in this configuration");
6668 : TREE_ASM_WRITTEN (decl) = 1;
6669 : return;
6670 : # else
6671 : if (!DECL_WEAK (decl))
6672 : {
6673 : /* NB: ifunc_resolver isn't set when an error is detected. */
6674 : if (TREE_CODE (decl) == FUNCTION_DECL
6675 : && lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
6676 : error_at (DECL_SOURCE_LOCATION (decl),
6677 : "%qs is not supported in this configuration", "ifunc");
6678 : else
6679 : error_at (DECL_SOURCE_LOCATION (decl),
6680 : "only weak aliases are supported in this configuration");
6681 : TREE_ASM_WRITTEN (decl) = 1;
6682 : return;
6683 : }
6684 : # endif
6685 : gcc_unreachable ();
6686 : }
6687 5713 : TREE_USED (decl) = 1;
6688 :
6689 : /* Allow aliases to aliases. */
6690 5713 : symtab_node::get_create (decl)->alias = true;
6691 :
6692 : /* If the target has already been emitted, we don't have to queue the
6693 : alias. This saves a tad of memory. */
6694 5713 : if (symtab->global_info_ready)
6695 0 : target_decl = find_decl (target);
6696 : else
6697 : target_decl= NULL;
6698 0 : if ((target_decl && TREE_ASM_WRITTEN (target_decl))
6699 5713 : || symtab->state >= EXPANSION)
6700 0 : do_assemble_alias (decl, target);
6701 : else
6702 : {
6703 5713 : alias_pair p = {decl, target};
6704 5713 : vec_safe_push (alias_pairs, p);
6705 : }
6706 : }
6707 :
6708 : /* Record and output a table of translations from original function
6709 : to its transaction aware clone. Note that tm_pure functions are
6710 : considered to be their own clone. */
6711 :
6712 : struct tm_clone_hasher : ggc_cache_ptr_hash<tree_map>
6713 : {
6714 193 : static hashval_t hash (tree_map *m) { return tree_map_hash (m); }
6715 223 : static bool equal (tree_map *a, tree_map *b) { return tree_map_eq (a, b); }
6716 :
6717 : static int
6718 0 : keep_cache_entry (tree_map *&e)
6719 : {
6720 0 : return ggc_marked_p (e->base.from);
6721 : }
6722 : };
6723 :
6724 : static GTY((cache)) hash_table<tm_clone_hasher> *tm_clone_hash;
6725 :
6726 : void
6727 463 : record_tm_clone_pair (tree o, tree n)
6728 : {
6729 463 : struct tree_map **slot, *h;
6730 :
6731 463 : if (tm_clone_hash == NULL)
6732 165 : tm_clone_hash = hash_table<tm_clone_hasher>::create_ggc (32);
6733 :
6734 463 : h = ggc_alloc<tree_map> ();
6735 463 : h->hash = htab_hash_pointer (o);
6736 463 : h->base.from = o;
6737 463 : h->to = n;
6738 :
6739 463 : slot = tm_clone_hash->find_slot_with_hash (h, h->hash, INSERT);
6740 463 : *slot = h;
6741 463 : }
6742 :
6743 : tree
6744 7 : get_tm_clone_pair (tree o)
6745 : {
6746 7 : if (tm_clone_hash)
6747 : {
6748 7 : struct tree_map *h, in;
6749 :
6750 7 : in.base.from = o;
6751 7 : in.hash = htab_hash_pointer (o);
6752 7 : h = tm_clone_hash->find_with_hash (&in, in.hash);
6753 7 : if (h)
6754 0 : return h->to;
6755 : }
6756 : return NULL_TREE;
6757 : }
6758 :
6759 : struct tm_alias_pair
6760 : {
6761 : unsigned int uid;
6762 : tree from;
6763 : tree to;
6764 : };
6765 :
6766 :
6767 : /* Dump the actual pairs to the .tm_clone_table section. */
6768 :
6769 : static void
6770 148 : dump_tm_clone_pairs (vec<tm_alias_pair> tm_alias_pairs)
6771 : {
6772 148 : unsigned i;
6773 148 : tm_alias_pair *p;
6774 148 : bool switched = false;
6775 :
6776 565 : FOR_EACH_VEC_ELT (tm_alias_pairs, i, p)
6777 : {
6778 417 : tree src = p->from;
6779 417 : tree dst = p->to;
6780 417 : struct cgraph_node *src_n = cgraph_node::get (src);
6781 417 : struct cgraph_node *dst_n = cgraph_node::get (dst);
6782 :
6783 : /* The function ipa_tm_create_version() marks the clone as needed if
6784 : the original function was needed. But we also mark the clone as
6785 : needed if we ever called the clone indirectly through
6786 : TM_GETTMCLONE. If neither of these are true, we didn't generate
6787 : a clone, and we didn't call it indirectly... no sense keeping it
6788 : in the clone table. */
6789 417 : if (!dst_n || !dst_n->definition)
6790 135 : continue;
6791 :
6792 : /* This covers the case where we have optimized the original
6793 : function away, and only access the transactional clone. */
6794 282 : if (!src_n || !src_n->definition)
6795 9 : continue;
6796 :
6797 273 : if (!switched)
6798 : {
6799 120 : switch_to_section (targetm.asm_out.tm_clone_table_section ());
6800 120 : assemble_align (POINTER_SIZE);
6801 120 : switched = true;
6802 : }
6803 :
6804 546 : assemble_integer (XEXP (DECL_RTL (src), 0),
6805 546 : POINTER_SIZE_UNITS, POINTER_SIZE, 1);
6806 546 : assemble_integer (XEXP (DECL_RTL (dst), 0),
6807 546 : POINTER_SIZE_UNITS, POINTER_SIZE, 1);
6808 : }
6809 148 : }
6810 :
6811 : /* Provide a default for the tm_clone_table section. */
6812 :
6813 : section *
6814 120 : default_clone_table_section (void)
6815 : {
6816 120 : return get_named_section (NULL, ".tm_clone_table", 3);
6817 : }
6818 :
6819 : /* Helper comparison function for qsorting by the DECL_UID stored in
6820 : alias_pair->emitted_diags. */
6821 :
6822 : static int
6823 3537 : tm_alias_pair_cmp (const void *x, const void *y)
6824 : {
6825 3537 : const tm_alias_pair *p1 = (const tm_alias_pair *) x;
6826 3537 : const tm_alias_pair *p2 = (const tm_alias_pair *) y;
6827 3537 : if (p1->uid < p2->uid)
6828 : return -1;
6829 1609 : if (p1->uid > p2->uid)
6830 1609 : return 1;
6831 : return 0;
6832 : }
6833 :
6834 : void
6835 239445 : finish_tm_clone_pairs (void)
6836 : {
6837 239445 : vec<tm_alias_pair> tm_alias_pairs = vNULL;
6838 :
6839 239445 : if (tm_clone_hash == NULL)
6840 239297 : return;
6841 :
6842 : /* We need a deterministic order for the .tm_clone_table, otherwise
6843 : we will get bootstrap comparison failures, so dump the hash table
6844 : to a vector, sort it, and dump the vector. */
6845 :
6846 : /* Dump the hashtable to a vector. */
6847 148 : tree_map *map;
6848 148 : hash_table<tm_clone_hasher>::iterator iter;
6849 565 : FOR_EACH_HASH_TABLE_ELEMENT (*tm_clone_hash, map, tree_map *, iter)
6850 : {
6851 417 : tm_alias_pair p = {DECL_UID (map->base.from), map->base.from, map->to};
6852 417 : tm_alias_pairs.safe_push (p);
6853 : }
6854 : /* Sort it. */
6855 148 : tm_alias_pairs.qsort (tm_alias_pair_cmp);
6856 :
6857 : /* Dump it. */
6858 148 : dump_tm_clone_pairs (tm_alias_pairs);
6859 :
6860 148 : tm_clone_hash->empty ();
6861 148 : tm_clone_hash = NULL;
6862 148 : tm_alias_pairs.release ();
6863 : }
6864 :
6865 :
6866 : /* Emit an assembler directive to set symbol for DECL visibility to
6867 : the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
6868 :
6869 : void
6870 33804 : default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
6871 : int vis ATTRIBUTE_UNUSED)
6872 : {
6873 : #ifdef HAVE_GAS_HIDDEN
6874 33804 : static const char * const visibility_types[] = {
6875 : NULL, "protected", "hidden", "internal"
6876 : };
6877 :
6878 33804 : const char *name, *type;
6879 33804 : tree id;
6880 :
6881 33804 : id = DECL_ASSEMBLER_NAME (decl);
6882 33804 : ultimate_transparent_alias_target (&id);
6883 33804 : name = IDENTIFIER_POINTER (id);
6884 :
6885 33804 : type = visibility_types[vis];
6886 :
6887 33804 : fprintf (asm_out_file, "\t.%s\t", type);
6888 33804 : assemble_name (asm_out_file, name);
6889 33804 : fprintf (asm_out_file, "\n");
6890 : #else
6891 : if (!DECL_ARTIFICIAL (decl))
6892 : warning (OPT_Wattributes, "visibility attribute not supported "
6893 : "in this configuration; ignored");
6894 : #endif
6895 33804 : }
6896 :
6897 : /* A helper function to call assemble_visibility when needed for a decl. */
6898 :
6899 : bool
6900 2906919 : maybe_assemble_visibility (tree decl)
6901 : {
6902 2906919 : enum symbol_visibility vis = DECL_VISIBILITY (decl);
6903 2906919 : if (vis != VISIBILITY_DEFAULT)
6904 : {
6905 32497 : targetm.asm_out.assemble_visibility (decl, vis);
6906 32497 : return true;
6907 : }
6908 : else
6909 : return false;
6910 : }
6911 :
6912 : /* Returns true if the target configuration supports defining public symbols
6913 : so that one of them will be chosen at link time instead of generating a
6914 : multiply-defined symbol error, whether through the use of weak symbols or
6915 : a target-specific mechanism for having duplicates discarded. */
6916 :
6917 : bool
6918 100969 : supports_one_only (void)
6919 : {
6920 100969 : if (SUPPORTS_ONE_ONLY)
6921 100969 : return true;
6922 : if (TARGET_SUPPORTS_WEAK)
6923 : return true;
6924 : return false;
6925 : }
6926 :
6927 : /* Set up DECL as a public symbol that can be defined in multiple
6928 : translation units without generating a linker error. */
6929 :
6930 : void
6931 112834423 : make_decl_one_only (tree decl, tree comdat_group)
6932 : {
6933 112834423 : struct symtab_node *symbol;
6934 112834423 : gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
6935 :
6936 112834423 : TREE_PUBLIC (decl) = 1;
6937 :
6938 112834423 : symbol = symtab_node::get_create (decl);
6939 :
6940 112834423 : if (SUPPORTS_ONE_ONLY)
6941 : {
6942 : #ifdef MAKE_DECL_ONE_ONLY
6943 112834423 : MAKE_DECL_ONE_ONLY (decl);
6944 : #endif
6945 112834423 : symbol->set_comdat_group (comdat_group);
6946 : }
6947 : else if (VAR_P (decl)
6948 : && (DECL_INITIAL (decl) == 0
6949 : || (!in_lto_p && DECL_INITIAL (decl) == error_mark_node)))
6950 : DECL_COMMON (decl) = 1;
6951 : else
6952 : {
6953 : gcc_assert (TARGET_SUPPORTS_WEAK);
6954 : DECL_WEAK (decl) = 1;
6955 : }
6956 112834423 : }
6957 :
6958 : void
6959 289641 : init_varasm_once (void)
6960 : {
6961 289641 : section_htab = hash_table<section_hasher>::create_ggc (31);
6962 289641 : object_block_htab = hash_table<object_block_hasher>::create_ggc (31);
6963 289641 : const_desc_htab = hash_table<tree_descriptor_hasher>::create_ggc (1009);
6964 :
6965 289641 : shared_constant_pool = create_constant_pool ();
6966 :
6967 : #ifdef TEXT_SECTION_ASM_OP
6968 289641 : text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
6969 : TEXT_SECTION_ASM_OP);
6970 : #endif
6971 :
6972 : #ifdef DATA_SECTION_ASM_OP
6973 289641 : data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6974 : DATA_SECTION_ASM_OP);
6975 : #endif
6976 :
6977 : #ifdef SDATA_SECTION_ASM_OP
6978 : sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6979 : SDATA_SECTION_ASM_OP);
6980 : #endif
6981 :
6982 : #ifdef READONLY_DATA_SECTION_ASM_OP
6983 289641 : readonly_data_section = get_unnamed_section (0, output_section_asm_op,
6984 : READONLY_DATA_SECTION_ASM_OP);
6985 : #endif
6986 :
6987 : #ifdef CTORS_SECTION_ASM_OP
6988 : ctors_section = get_unnamed_section (0, output_section_asm_op,
6989 : CTORS_SECTION_ASM_OP);
6990 : #endif
6991 :
6992 : #ifdef DTORS_SECTION_ASM_OP
6993 : dtors_section = get_unnamed_section (0, output_section_asm_op,
6994 : DTORS_SECTION_ASM_OP);
6995 : #endif
6996 :
6997 : #ifdef BSS_SECTION_ASM_OP
6998 289641 : bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6999 : output_section_asm_op,
7000 : BSS_SECTION_ASM_OP);
7001 : #endif
7002 :
7003 : #ifdef SBSS_SECTION_ASM_OP
7004 : sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
7005 : output_section_asm_op,
7006 : SBSS_SECTION_ASM_OP);
7007 : #endif
7008 :
7009 289641 : tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
7010 : | SECTION_COMMON, emit_tls_common);
7011 289641 : lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
7012 : | SECTION_COMMON, emit_local);
7013 289641 : comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
7014 : | SECTION_COMMON, emit_common);
7015 :
7016 : #if defined ASM_OUTPUT_ALIGNED_BSS
7017 289641 : bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
7018 : emit_bss);
7019 : #endif
7020 :
7021 289641 : targetm.asm_out.init_sections ();
7022 :
7023 289641 : if (readonly_data_section == NULL)
7024 0 : readonly_data_section = text_section;
7025 :
7026 : #ifdef ASM_OUTPUT_EXTERNAL
7027 289641 : pending_assemble_externals_set = new hash_set<tree>;
7028 : #endif
7029 289641 : }
7030 :
7031 : /* Determine whether SYMBOL is used in any optimized function. */
7032 :
7033 : static bool
7034 180 : have_optimized_refs (struct symtab_node *symbol)
7035 : {
7036 180 : struct ipa_ref *ref;
7037 :
7038 204 : for (int i = 0; symbol->iterate_referring (i, ref); i++)
7039 : {
7040 220 : cgraph_node *cnode = dyn_cast <cgraph_node *> (ref->referring);
7041 :
7042 196 : if (cnode && opt_for_fn (cnode->decl, optimize))
7043 : return true;
7044 : }
7045 :
7046 : return false;
7047 : }
7048 :
7049 : /* Check if promoting general-dynamic TLS access model to local-dynamic is
7050 : desirable for DECL. */
7051 :
7052 : static bool
7053 327 : optimize_dyn_tls_for_decl_p (const_tree decl)
7054 : {
7055 327 : if (cfun)
7056 30 : return optimize;
7057 297 : return symtab->state >= IPA && have_optimized_refs (symtab_node::get (decl));
7058 : }
7059 :
7060 :
7061 : enum tls_model
7062 28968 : decl_default_tls_model (const_tree decl)
7063 : {
7064 28968 : enum tls_model kind;
7065 28968 : bool is_local;
7066 :
7067 28968 : is_local = targetm.binds_local_p (decl);
7068 28968 : if (!flag_shlib)
7069 : {
7070 26526 : if (is_local)
7071 : kind = TLS_MODEL_LOCAL_EXEC;
7072 : else
7073 20478 : kind = TLS_MODEL_INITIAL_EXEC;
7074 : }
7075 :
7076 : /* Local dynamic is inefficient when we're not combining the
7077 : parts of the address. */
7078 2442 : else if (is_local && optimize_dyn_tls_for_decl_p (decl))
7079 : kind = TLS_MODEL_LOCAL_DYNAMIC;
7080 : else
7081 : kind = TLS_MODEL_GLOBAL_DYNAMIC;
7082 28968 : if (kind < flag_tls_default)
7083 182 : kind = flag_tls_default;
7084 :
7085 28968 : return kind;
7086 : }
7087 :
7088 : /* Select a set of attributes for section NAME based on the properties
7089 : of DECL and whether or not RELOC indicates that DECL's initializer
7090 : might contain runtime relocations.
7091 :
7092 : We make the section read-only and executable for a function decl,
7093 : read-only for a const data decl, and writable for a non-const data decl. */
7094 :
7095 : unsigned int
7096 71263498 : default_section_type_flags (tree decl, const char *name, int reloc)
7097 : {
7098 71263498 : unsigned int flags;
7099 :
7100 71263498 : if (decl && TREE_CODE (decl) == FUNCTION_DECL)
7101 : flags = SECTION_CODE;
7102 2981087 : else if (strcmp (name, ".data.rel.ro") == 0
7103 2980966 : || strcmp (name, ".data.rel.ro.local") == 0)
7104 : flags = SECTION_WRITE | SECTION_RELRO;
7105 2980591 : else if (decl)
7106 : {
7107 2980471 : enum section_category category
7108 2980471 : = categorize_decl_for_section (decl, reloc);
7109 6608476 : if (decl_readonly_section_1 (category))
7110 : flags = 0;
7111 647038 : else if (category == SECCAT_DATA_REL_RO
7112 647038 : || category == SECCAT_DATA_REL_RO_LOCAL)
7113 : flags = SECTION_WRITE | SECTION_RELRO;
7114 : else
7115 2980967 : flags = SECTION_WRITE;
7116 : }
7117 : else
7118 : flags = SECTION_WRITE;
7119 :
7120 71263378 : if (decl && DECL_P (decl) && DECL_COMDAT_GROUP (decl))
7121 39345715 : flags |= SECTION_LINKONCE;
7122 :
7123 71263498 : if (strcmp (name, ".vtable_map_vars") == 0)
7124 6 : flags |= SECTION_LINKONCE;
7125 :
7126 71263498 : if (decl && VAR_P (decl) && DECL_THREAD_LOCAL_P (decl))
7127 3874 : flags |= SECTION_TLS | SECTION_WRITE;
7128 :
7129 71263498 : if (strcmp (name, ".bss") == 0
7130 71263498 : || startswith (name, ".bss.")
7131 71248857 : || startswith (name, ".gnu.linkonce.b.")
7132 71248857 : || strcmp (name, ".persistent.bss") == 0
7133 71248857 : || strcmp (name, ".sbss") == 0
7134 71248857 : || startswith (name, ".sbss.")
7135 142512355 : || startswith (name, ".gnu.linkonce.sb."))
7136 14641 : flags |= SECTION_BSS;
7137 :
7138 71263498 : if (strcmp (name, ".tdata") == 0
7139 71263184 : || startswith (name, ".tdata.")
7140 142526643 : || startswith (name, ".gnu.linkonce.td."))
7141 353 : flags |= SECTION_TLS;
7142 :
7143 71263498 : if (strcmp (name, ".tbss") == 0
7144 71260171 : || startswith (name, ".tbss.")
7145 142523481 : || startswith (name, ".gnu.linkonce.tb."))
7146 3515 : flags |= SECTION_TLS | SECTION_BSS;
7147 :
7148 71263498 : if (strcmp (name, ".noinit") == 0)
7149 0 : flags |= SECTION_WRITE | SECTION_BSS | SECTION_NOTYPE;
7150 :
7151 71263498 : if (strcmp (name, ".persistent") == 0)
7152 0 : flags |= SECTION_WRITE | SECTION_NOTYPE;
7153 :
7154 : /* Various sections have special ELF types that the assembler will
7155 : assign by default based on the name. They are neither SHT_PROGBITS
7156 : nor SHT_NOBITS, so when changing sections we don't want to print a
7157 : section type (@progbits or @nobits). Rather than duplicating the
7158 : assembler's knowledge of what those special name patterns are, just
7159 : let the assembler choose the type if we don't know a specific
7160 : reason to set it to something other than the default. SHT_PROGBITS
7161 : is the default for sections whose name is not specially known to
7162 : the assembler, so it does no harm to leave the choice to the
7163 : assembler when @progbits is the best thing we know to use. If
7164 : someone is silly enough to emit code or TLS variables to one of
7165 : these sections, then don't handle them specially.
7166 :
7167 : default_elf_asm_named_section (below) handles the BSS, TLS, ENTSIZE, and
7168 : LINKONCE cases when NOTYPE is not set, so leave those to its logic. */
7169 71263498 : if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS | SECTION_ENTSIZE))
7170 2962572 : && !(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)))
7171 2407810 : flags |= SECTION_NOTYPE;
7172 :
7173 71263498 : return flags;
7174 : }
7175 :
7176 : /* Return true if the target supports some form of global BSS,
7177 : either through bss_noswitch_section, or by selecting a BSS
7178 : section in TARGET_ASM_SELECT_SECTION. */
7179 :
7180 : bool
7181 0 : have_global_bss_p (void)
7182 : {
7183 0 : return bss_noswitch_section || targetm.have_switchable_bss_sections;
7184 : }
7185 :
7186 : /* Output assembly to switch to section NAME with attribute FLAGS.
7187 : Four variants for common object file formats. */
7188 :
7189 : void
7190 0 : default_no_named_section (const char *name ATTRIBUTE_UNUSED,
7191 : unsigned int flags ATTRIBUTE_UNUSED,
7192 : tree decl ATTRIBUTE_UNUSED)
7193 : {
7194 : /* Some object formats don't support named sections at all. The
7195 : front-end should already have flagged this as an error. */
7196 0 : gcc_unreachable ();
7197 : }
7198 :
7199 : #ifndef TLS_SECTION_ASM_FLAG
7200 : #define TLS_SECTION_ASM_FLAG 'T'
7201 : #endif
7202 :
7203 : void
7204 3666127 : default_elf_asm_named_section (const char *name, unsigned int flags,
7205 : tree decl)
7206 : {
7207 3666127 : char flagchars[11], *f = flagchars;
7208 3666127 : unsigned int numeric_value = 0;
7209 :
7210 : /* If we have already declared this section, we can use an
7211 : abbreviated form to switch back to it -- unless this section is
7212 : part of a COMDAT groups or with SHF_GNU_RETAIN or with SHF_LINK_ORDER,
7213 : in which case GAS requires the full declaration every time. */
7214 3666127 : if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
7215 3077741 : && !(flags & (SECTION_RETAIN | SECTION_LINK_ORDER))
7216 3077441 : && (flags & SECTION_DECLARED))
7217 : {
7218 395729 : fprintf (asm_out_file, "\t.section\t%s\n", name);
7219 395729 : return;
7220 : }
7221 :
7222 : /* If we have a machine specific flag, then use the numeric value to pass
7223 : this on to GAS. */
7224 3270398 : if (targetm.asm_out.elf_flags_numeric (flags, &numeric_value))
7225 0 : snprintf (f, sizeof (flagchars), "0x%08x", numeric_value);
7226 : else
7227 : {
7228 3270398 : if (!(flags & SECTION_DEBUG))
7229 2157077 : *f++ = 'a';
7230 : #if HAVE_GAS_SECTION_EXCLUDE
7231 3270398 : if (flags & SECTION_EXCLUDE)
7232 470631 : *f++ = 'e';
7233 : #endif
7234 3270398 : if (flags & SECTION_WRITE)
7235 358973 : *f++ = 'w';
7236 3270398 : if (flags & SECTION_CODE)
7237 399779 : *f++ = 'x';
7238 3270398 : if (flags & SECTION_SMALL)
7239 0 : *f++ = 's';
7240 3270398 : if (flags & SECTION_MERGE)
7241 225522 : *f++ = 'M';
7242 3270398 : if (flags & SECTION_STRINGS)
7243 185277 : *f++ = 'S';
7244 3270398 : if (flags & SECTION_TLS)
7245 1245 : *f++ = TLS_SECTION_ASM_FLAG;
7246 3270398 : if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
7247 588386 : *f++ = 'G';
7248 3270398 : if (flags & SECTION_RETAIN)
7249 259 : *f++ = 'R';
7250 3270398 : if (flags & SECTION_LINK_ORDER)
7251 53 : *f++ = 'o';
7252 : #ifdef MACH_DEP_SECTION_ASM_FLAG
7253 3270398 : if (flags & SECTION_MACH_DEP)
7254 12 : *f++ = MACH_DEP_SECTION_ASM_FLAG;
7255 : #endif
7256 3270398 : *f = '\0';
7257 : }
7258 :
7259 3270398 : fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
7260 :
7261 : /* default_section_type_flags (above) knows which flags need special
7262 : handling here, and sets NOTYPE when none of these apply so that the
7263 : assembler's logic for default types can apply to user-chosen
7264 : section names. */
7265 3270398 : if (!(flags & SECTION_NOTYPE))
7266 : {
7267 2017386 : const char *type;
7268 2017386 : const char *format;
7269 :
7270 2017386 : if (flags & SECTION_BSS)
7271 : type = "nobits";
7272 : else
7273 2003652 : type = "progbits";
7274 :
7275 2017386 : format = ",@%s";
7276 : /* On platforms that use "@" as the assembly comment character,
7277 : use "%" instead. */
7278 2017386 : if (strcmp (ASM_COMMENT_START, "@") == 0)
7279 : format = ",%%%s";
7280 2017386 : fprintf (asm_out_file, format, type);
7281 :
7282 2017386 : if (flags & SECTION_ENTSIZE)
7283 225522 : fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
7284 2017386 : if (flags & SECTION_LINK_ORDER)
7285 : {
7286 : /* For now, only section "__patchable_function_entries"
7287 : adopts flag SECTION_LINK_ORDER, internal label LPFE*
7288 : was emitted in default_print_patchable_function_entry,
7289 : just place it here for linked_to section. */
7290 53 : gcc_assert (!strcmp (name, "__patchable_function_entries"));
7291 53 : fprintf (asm_out_file, ",");
7292 53 : char buf[256];
7293 53 : ASM_GENERATE_INTERNAL_LABEL (buf, "LPFE",
7294 : current_function_funcdef_no);
7295 53 : assemble_name_raw (asm_out_file, buf);
7296 : }
7297 2017386 : if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
7298 : {
7299 588386 : if (TREE_CODE (decl) == IDENTIFIER_NODE)
7300 1640 : fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
7301 : else
7302 1173492 : fprintf (asm_out_file, ",%s,comdat",
7303 586746 : IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
7304 : }
7305 : }
7306 :
7307 3270398 : putc ('\n', asm_out_file);
7308 : }
7309 :
7310 : void
7311 0 : default_coff_asm_named_section (const char *name, unsigned int flags,
7312 : tree decl ATTRIBUTE_UNUSED)
7313 : {
7314 0 : char flagchars[8], *f = flagchars;
7315 :
7316 0 : if (flags & SECTION_WRITE)
7317 0 : *f++ = 'w';
7318 0 : if (flags & SECTION_CODE)
7319 0 : *f++ = 'x';
7320 0 : *f = '\0';
7321 :
7322 0 : fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
7323 0 : }
7324 :
7325 : void
7326 0 : default_pe_asm_named_section (const char *name, unsigned int flags,
7327 : tree decl)
7328 : {
7329 0 : default_coff_asm_named_section (name, flags, decl);
7330 :
7331 0 : if (flags & SECTION_LINKONCE)
7332 : {
7333 : /* Functions may have been compiled at various levels of
7334 : optimization so we can't use `same_size' here.
7335 : Instead, have the linker pick one. */
7336 0 : fprintf (asm_out_file, "\t.linkonce %s\n",
7337 0 : (flags & SECTION_CODE ? "discard" : "same_size"));
7338 : }
7339 0 : }
7340 :
7341 : /* The lame default section selector. */
7342 :
7343 : section *
7344 0 : default_select_section (tree decl, int reloc,
7345 : unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
7346 : {
7347 0 : if (DECL_P (decl))
7348 : {
7349 0 : if (decl_readonly_section (decl, reloc))
7350 0 : return readonly_data_section;
7351 : }
7352 0 : else if (TREE_CODE (decl) == CONSTRUCTOR)
7353 : {
7354 0 : if (! ((flag_pic && reloc)
7355 0 : || !TREE_READONLY (decl)
7356 0 : || !TREE_CONSTANT (decl)))
7357 0 : return readonly_data_section;
7358 : }
7359 0 : else if (TREE_CODE (decl) == STRING_CST)
7360 0 : return readonly_data_section;
7361 0 : else if (! (flag_pic && reloc))
7362 0 : return readonly_data_section;
7363 :
7364 0 : return data_section;
7365 : }
7366 :
7367 : enum section_category
7368 6509983 : categorize_decl_for_section (const_tree decl, int reloc)
7369 : {
7370 6509983 : enum section_category ret;
7371 :
7372 6509983 : if (TREE_CODE (decl) == FUNCTION_DECL)
7373 : return SECCAT_TEXT;
7374 6255808 : else if (TREE_CODE (decl) == STRING_CST)
7375 : {
7376 1274922 : if ((flag_sanitize & SANITIZE_ADDRESS)
7377 1274922 : && asan_protect_global (const_cast<tree> (decl)))
7378 : /* or !flag_merge_constants */
7379 : return SECCAT_RODATA;
7380 : else
7381 1273178 : return SECCAT_RODATA_MERGE_STR;
7382 : }
7383 4980886 : else if (VAR_P (decl))
7384 : {
7385 4949041 : tree d = const_cast<tree> (decl);
7386 4949041 : if (bss_initializer_p (decl))
7387 : ret = SECCAT_BSS;
7388 4912539 : else if (! TREE_READONLY (decl)
7389 4912539 : || (DECL_INITIAL (decl)
7390 4576582 : && ! TREE_CONSTANT (DECL_INITIAL (decl))))
7391 : {
7392 : /* Here the reloc_rw_mask is not testing whether the section should
7393 : be read-only or not, but whether the dynamic link will have to
7394 : do something. If so, we wish to segregate the data in order to
7395 : minimize cache misses inside the dynamic linker. */
7396 341177 : if (reloc & targetm.asm_out.reloc_rw_mask ())
7397 11809 : ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
7398 : else
7399 : ret = SECCAT_DATA;
7400 : }
7401 4571362 : else if (reloc & targetm.asm_out.reloc_rw_mask ())
7402 922271 : ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
7403 750221 : else if (reloc || (flag_merge_constants < 2 && !DECL_MERGEABLE (decl))
7404 3651574 : || ((flag_sanitize & SANITIZE_ADDRESS)
7405 : /* PR 81697: for architectures that use section anchors we
7406 : need to ignore DECL_RTL_SET_P (decl) for string constants
7407 : inside this asan_protect_global call because otherwise
7408 : we'll wrongly put them into SECCAT_RODATA_MERGE_CONST
7409 : section, set DECL_RTL (decl) later on and add DECL to
7410 : protected globals via successive asan_protect_global
7411 : calls. In this scenario we'll end up with wrong
7412 : alignment of these strings at runtime and possible ASan
7413 : false positives. */
7414 182 : && asan_protect_global (d, use_object_blocks_p ()
7415 0 : && use_blocks_for_decl_p (d))))
7416 : /* C and C++ don't allow different variables to share the same
7417 : location. -fmerge-all-constants allows even that (at the
7418 : expense of not conforming). */
7419 : ret = SECCAT_RODATA;
7420 2404 : else if (DECL_INITIAL (decl)
7421 2404 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
7422 : ret = SECCAT_RODATA_MERGE_STR_INIT;
7423 : else
7424 : ret = SECCAT_RODATA_MERGE_CONST;
7425 : }
7426 31845 : else if (TREE_CODE (decl) == CONSTRUCTOR)
7427 : {
7428 1548 : if ((reloc & targetm.asm_out.reloc_rw_mask ())
7429 1548 : || ! TREE_CONSTANT (decl))
7430 : ret = SECCAT_DATA;
7431 : else
7432 : ret = SECCAT_RODATA;
7433 : }
7434 : else
7435 : ret = SECCAT_RODATA;
7436 :
7437 : /* There are no read-only thread-local sections. */
7438 4980886 : if (VAR_P (decl) && DECL_THREAD_LOCAL_P (decl))
7439 : {
7440 : /* Note that this would be *just* SECCAT_BSS, except that there's
7441 : no concept of a read-only thread-local-data section. */
7442 7740 : if (ret == SECCAT_BSS
7443 712 : || DECL_INITIAL (decl) == NULL
7444 8446 : || (flag_zero_initialized_in_bss
7445 706 : && initializer_zerop (DECL_INITIAL (decl))))
7446 : ret = SECCAT_TBSS;
7447 : else
7448 : ret = SECCAT_TDATA;
7449 : }
7450 :
7451 : /* If the target uses small data sections, select it. */
7452 4973146 : else if (targetm.in_small_data_p (decl))
7453 : {
7454 0 : if (ret == SECCAT_BSS)
7455 : ret = SECCAT_SBSS;
7456 0 : else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
7457 : ret = SECCAT_SRODATA;
7458 : else
7459 0 : ret = SECCAT_SDATA;
7460 : }
7461 :
7462 : return ret;
7463 : }
7464 :
7465 : static bool
7466 3004266 : decl_readonly_section_1 (enum section_category category)
7467 : {
7468 2980471 : switch (category)
7469 : {
7470 : case SECCAT_RODATA:
7471 : case SECCAT_RODATA_MERGE_STR:
7472 : case SECCAT_RODATA_MERGE_STR_INIT:
7473 : case SECCAT_RODATA_MERGE_CONST:
7474 : case SECCAT_SRODATA:
7475 : return true;
7476 649551 : default:
7477 649551 : return false;
7478 : }
7479 : }
7480 :
7481 : bool
7482 23795 : decl_readonly_section (const_tree decl, int reloc)
7483 : {
7484 23795 : return decl_readonly_section_1 (categorize_decl_for_section (decl, reloc));
7485 : }
7486 :
7487 : /* Select a section based on the above categorization. */
7488 :
7489 : section *
7490 1682450 : default_elf_select_section (tree decl, int reloc,
7491 : unsigned HOST_WIDE_INT align)
7492 : {
7493 1682450 : const char *sname;
7494 :
7495 1682450 : switch (categorize_decl_for_section (decl, reloc))
7496 : {
7497 0 : case SECCAT_TEXT:
7498 : /* We're not supposed to be called on FUNCTION_DECLs. */
7499 0 : gcc_unreachable ();
7500 137818 : case SECCAT_RODATA:
7501 137818 : return readonly_data_section;
7502 1252047 : case SECCAT_RODATA_MERGE_STR:
7503 1252047 : return mergeable_string_section (decl, align, 0);
7504 14 : case SECCAT_RODATA_MERGE_STR_INIT:
7505 14 : return mergeable_string_section (DECL_INITIAL (decl), align, 0);
7506 480 : case SECCAT_RODATA_MERGE_CONST:
7507 480 : return mergeable_constant_section (DECL_SIZE (decl), align, 0);
7508 : case SECCAT_SRODATA:
7509 : sname = ".sdata2";
7510 : break;
7511 287056 : case SECCAT_DATA:
7512 287056 : if (DECL_P (decl) && DECL_PERSISTENT_P (decl))
7513 : {
7514 : sname = ".persistent";
7515 : break;
7516 : }
7517 287056 : return data_section;
7518 146 : case SECCAT_DATA_REL:
7519 146 : sname = ".data.rel";
7520 146 : break;
7521 1005 : case SECCAT_DATA_REL_LOCAL:
7522 1005 : sname = ".data.rel.local";
7523 1005 : break;
7524 107 : case SECCAT_DATA_REL_RO:
7525 107 : sname = ".data.rel.ro";
7526 107 : break;
7527 131 : case SECCAT_DATA_REL_RO_LOCAL:
7528 131 : sname = ".data.rel.ro.local";
7529 131 : break;
7530 0 : case SECCAT_SDATA:
7531 0 : sname = ".sdata";
7532 0 : break;
7533 314 : case SECCAT_TDATA:
7534 314 : sname = ".tdata";
7535 314 : break;
7536 5 : case SECCAT_BSS:
7537 5 : if (DECL_P (decl) && DECL_NOINIT_P (decl))
7538 : {
7539 : sname = ".noinit";
7540 : break;
7541 : }
7542 5 : if (bss_section)
7543 : return bss_section;
7544 : sname = ".bss";
7545 : break;
7546 0 : case SECCAT_SBSS:
7547 0 : sname = ".sbss";
7548 0 : break;
7549 3327 : case SECCAT_TBSS:
7550 3327 : sname = ".tbss";
7551 3327 : break;
7552 0 : default:
7553 0 : gcc_unreachable ();
7554 : }
7555 :
7556 5030 : return get_named_section (decl, sname, reloc);
7557 : }
7558 :
7559 : /* Construct a unique section name based on the decl name and the
7560 : categorization performed above. */
7561 :
7562 : void
7563 1823163 : default_unique_section (tree decl, int reloc)
7564 : {
7565 : /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
7566 1823163 : bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
7567 1823163 : const char *prefix, *name, *linkonce;
7568 1823163 : char *string;
7569 1823163 : tree id;
7570 :
7571 1823163 : switch (categorize_decl_for_section (decl, reloc))
7572 : {
7573 : case SECCAT_TEXT:
7574 : prefix = one_only ? ".t" : ".text";
7575 : break;
7576 1210707 : case SECCAT_RODATA:
7577 1210707 : case SECCAT_RODATA_MERGE_STR:
7578 1210707 : case SECCAT_RODATA_MERGE_STR_INIT:
7579 1210707 : case SECCAT_RODATA_MERGE_CONST:
7580 1210707 : prefix = one_only ? ".r" : ".rodata";
7581 : break;
7582 0 : case SECCAT_SRODATA:
7583 0 : prefix = one_only ? ".s2" : ".sdata2";
7584 : break;
7585 15396 : case SECCAT_DATA:
7586 15396 : prefix = one_only ? ".d" : ".data";
7587 15396 : if (DECL_P (decl) && DECL_PERSISTENT_P (decl))
7588 : {
7589 : prefix = one_only ? ".p" : ".persistent";
7590 : break;
7591 : }
7592 : break;
7593 1137 : case SECCAT_DATA_REL:
7594 1137 : prefix = one_only ? ".d.rel" : ".data.rel";
7595 : break;
7596 3641 : case SECCAT_DATA_REL_LOCAL:
7597 3641 : prefix = one_only ? ".d.rel.local" : ".data.rel.local";
7598 : break;
7599 156084 : case SECCAT_DATA_REL_RO:
7600 156084 : prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
7601 : break;
7602 168634 : case SECCAT_DATA_REL_RO_LOCAL:
7603 168634 : prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
7604 : break;
7605 0 : case SECCAT_SDATA:
7606 0 : prefix = one_only ? ".s" : ".sdata";
7607 : break;
7608 13165 : case SECCAT_BSS:
7609 13165 : if (DECL_P (decl) && DECL_NOINIT_P (decl))
7610 : {
7611 : prefix = one_only ? ".n" : ".noinit";
7612 : break;
7613 : }
7614 : prefix = one_only ? ".b" : ".bss";
7615 : break;
7616 0 : case SECCAT_SBSS:
7617 0 : prefix = one_only ? ".sb" : ".sbss";
7618 : break;
7619 39 : case SECCAT_TDATA:
7620 39 : prefix = one_only ? ".td" : ".tdata";
7621 : break;
7622 186 : case SECCAT_TBSS:
7623 186 : prefix = one_only ? ".tb" : ".tbss";
7624 : break;
7625 0 : default:
7626 0 : gcc_unreachable ();
7627 : }
7628 :
7629 1823163 : id = DECL_ASSEMBLER_NAME (decl);
7630 1823163 : ultimate_transparent_alias_target (&id);
7631 1823163 : name = IDENTIFIER_POINTER (id);
7632 1823163 : name = targetm.strip_name_encoding (name);
7633 :
7634 : /* If we're using one_only, then there needs to be a .gnu.linkonce
7635 : prefix to the section name. */
7636 1823163 : linkonce = one_only ? ".gnu.linkonce" : "";
7637 :
7638 1823163 : string = ACONCAT ((linkonce, prefix, ".", name, NULL));
7639 :
7640 1823163 : set_decl_section_name (decl, string);
7641 1823163 : }
7642 :
7643 : /* Subroutine of compute_reloc_for_rtx for leaf rtxes. */
7644 :
7645 : static int
7646 39075 : compute_reloc_for_rtx_1 (const_rtx x)
7647 : {
7648 39075 : switch (GET_CODE (x))
7649 : {
7650 28078 : case SYMBOL_REF:
7651 28078 : return SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
7652 : case LABEL_REF:
7653 : return 1;
7654 : default:
7655 : return 0;
7656 : }
7657 : }
7658 :
7659 : /* Like compute_reloc_for_constant, except for an RTX. The return value
7660 : is a mask for which bit 1 indicates a global relocation, and bit 0
7661 : indicates a local relocation. Used by default_select_rtx_section
7662 : and default_elf_select_rtx_section. */
7663 :
7664 : static int
7665 250332 : compute_reloc_for_rtx (const_rtx x)
7666 : {
7667 250332 : switch (GET_CODE (x))
7668 : {
7669 24463 : case SYMBOL_REF:
7670 24463 : case LABEL_REF:
7671 24463 : return compute_reloc_for_rtx_1 (x);
7672 :
7673 3653 : case CONST:
7674 3653 : {
7675 3653 : int reloc = 0;
7676 3653 : subrtx_iterator::array_type array;
7677 18265 : FOR_EACH_SUBRTX (iter, array, x, ALL)
7678 14612 : reloc |= compute_reloc_for_rtx_1 (*iter);
7679 3653 : return reloc;
7680 3653 : }
7681 :
7682 : default:
7683 : return 0;
7684 : }
7685 : }
7686 :
7687 : section *
7688 0 : default_select_rtx_section (machine_mode mode ATTRIBUTE_UNUSED,
7689 : rtx x,
7690 : unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
7691 : {
7692 0 : if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
7693 0 : return data_section;
7694 : else
7695 0 : return readonly_data_section;
7696 : }
7697 :
7698 : section *
7699 250332 : default_elf_select_rtx_section (machine_mode mode, rtx x,
7700 : unsigned HOST_WIDE_INT align)
7701 : {
7702 250332 : int reloc = compute_reloc_for_rtx (x);
7703 250332 : tree decl = nullptr;
7704 250332 : const char *prefix = nullptr;
7705 250332 : int flags = 0;
7706 :
7707 : /* If it is a private COMDAT function symbol reference, call
7708 : function_rodata_section for the read-only or relocated read-only
7709 : data section associated with function DECL so that the COMDAT
7710 : section will be used for the private COMDAT function symbol. */
7711 250332 : if (HAVE_COMDAT_GROUP)
7712 : {
7713 250332 : if (GET_CODE (x) == CONST
7714 3653 : && GET_CODE (XEXP (x, 0)) == PLUS
7715 3653 : && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
7716 3653 : x = XEXP (XEXP (x, 0), 0);
7717 :
7718 250332 : if (GET_CODE (x) == SYMBOL_REF)
7719 : {
7720 28078 : decl = SYMBOL_REF_DECL (x);
7721 28078 : if (decl
7722 28078 : && (TREE_CODE (decl) != FUNCTION_DECL
7723 7396 : || !DECL_COMDAT_GROUP (decl)
7724 5337 : || TREE_PUBLIC (decl)))
7725 : decl = nullptr;
7726 : }
7727 : }
7728 :
7729 : /* ??? Handle small data here somehow. */
7730 :
7731 250332 : if (reloc & targetm.asm_out.reloc_rw_mask ())
7732 : {
7733 250 : if (decl)
7734 : {
7735 0 : prefix = reloc == 1 ? ".data.rel.ro.local" : ".data.rel.ro";
7736 : flags = SECTION_WRITE | SECTION_RELRO;
7737 : }
7738 250 : else if (reloc == 1)
7739 244 : return get_named_section (NULL, ".data.rel.ro.local", 1);
7740 : else
7741 6 : return get_named_section (NULL, ".data.rel.ro", 3);
7742 : }
7743 :
7744 250082 : if (decl)
7745 : {
7746 16 : const char *comdat = IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl));
7747 16 : if (!prefix)
7748 16 : prefix = ".rodata";
7749 16 : size_t prefix_len = strlen (prefix);
7750 16 : size_t comdat_len = strlen (comdat);
7751 16 : size_t len = prefix_len + sizeof (".pool.") + comdat_len;
7752 16 : char *name = XALLOCAVEC (char, len);
7753 16 : memcpy (name, prefix, prefix_len);
7754 16 : memcpy (name + prefix_len, ".pool.", sizeof (".pool.") - 1);
7755 16 : memcpy (name + prefix_len + sizeof (".pool.") - 1, comdat,
7756 : comdat_len + 1);
7757 16 : return get_section (name, flags | SECTION_LINKONCE, decl);
7758 : }
7759 :
7760 250066 : return mergeable_constant_section (mode, align, 0);
7761 : }
7762 :
7763 : /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
7764 :
7765 : void
7766 10089554 : default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
7767 : {
7768 10089554 : rtx symbol;
7769 10089554 : int flags;
7770 :
7771 : /* Careful not to prod global register variables. */
7772 10089554 : if (!MEM_P (rtl))
7773 : return;
7774 10089554 : symbol = XEXP (rtl, 0);
7775 10089554 : if (GET_CODE (symbol) != SYMBOL_REF)
7776 : return;
7777 :
7778 10089554 : flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
7779 10089554 : if (TREE_CODE (decl) == FUNCTION_DECL)
7780 5519060 : flags |= SYMBOL_FLAG_FUNCTION;
7781 10089554 : if (targetm.binds_local_p (decl))
7782 5715438 : flags |= SYMBOL_FLAG_LOCAL;
7783 10089554 : if (VAR_P (decl) && DECL_THREAD_LOCAL_P (decl))
7784 4608 : flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
7785 10084946 : else if (targetm.in_small_data_p (decl))
7786 0 : flags |= SYMBOL_FLAG_SMALL;
7787 : /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
7788 : being PUBLIC, the thing *must* be defined in this translation unit.
7789 : Prevent this buglet from being propagated into rtl code as well. */
7790 10089554 : if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
7791 4213098 : flags |= SYMBOL_FLAG_EXTERNAL;
7792 :
7793 10089554 : SYMBOL_REF_FLAGS (symbol) = flags;
7794 : }
7795 :
7796 : /* By default, we do nothing for encode_section_info, so we need not
7797 : do anything but discard the '*' marker. */
7798 :
7799 : const char *
7800 423414142 : default_strip_name_encoding (const char *str)
7801 : {
7802 423414142 : return str + (*str == '*');
7803 : }
7804 :
7805 : #ifdef ASM_OUTPUT_DEF
7806 : /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
7807 : anchor relative to ".", the current section position. */
7808 :
7809 : void
7810 0 : default_asm_output_anchor (rtx symbol)
7811 : {
7812 0 : gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
7813 :
7814 0 : char buffer[100];
7815 :
7816 0 : sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
7817 : SYMBOL_REF_BLOCK_OFFSET (symbol));
7818 0 : ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
7819 0 : }
7820 : #endif
7821 :
7822 : /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
7823 :
7824 : bool
7825 0 : default_use_anchors_for_symbol_p (const_rtx symbol)
7826 : {
7827 0 : tree decl;
7828 0 : section *sect = SYMBOL_REF_BLOCK (symbol)->sect;
7829 :
7830 : /* This function should only be called with non-zero SYMBOL_REF_BLOCK,
7831 : furthermore get_block_for_section should not create object blocks
7832 : for mergeable sections. */
7833 0 : gcc_checking_assert (sect && !(sect->common.flags & SECTION_MERGE));
7834 :
7835 : /* Don't use anchors for small data sections. The small data register
7836 : acts as an anchor for such sections. */
7837 0 : if (sect->common.flags & SECTION_SMALL)
7838 : return false;
7839 :
7840 0 : decl = SYMBOL_REF_DECL (symbol);
7841 0 : if (decl && DECL_P (decl))
7842 : {
7843 : /* Don't use section anchors for decls that might be defined or
7844 : usurped by other modules. */
7845 0 : if (TREE_PUBLIC (decl) && !decl_binds_to_current_def_p (decl))
7846 : return false;
7847 :
7848 : /* Don't use section anchors for decls that will be placed in a
7849 : small data section. */
7850 : /* ??? Ideally, this check would be redundant with the SECTION_SMALL
7851 : one above. The problem is that we only use SECTION_SMALL for
7852 : sections that should be marked as small in the section directive. */
7853 0 : if (targetm.in_small_data_p (decl))
7854 : return false;
7855 :
7856 : /* Don't use section anchors for decls that won't fit inside a single
7857 : anchor range to reduce the amount of instructions required to refer
7858 : to the entire declaration. */
7859 0 : if (DECL_SIZE_UNIT (decl) == NULL_TREE
7860 0 : || !tree_fits_uhwi_p (DECL_SIZE_UNIT (decl))
7861 0 : || (tree_to_uhwi (DECL_SIZE_UNIT (decl))
7862 0 : >= (unsigned HOST_WIDE_INT) targetm.max_anchor_offset))
7863 0 : return false;
7864 :
7865 : }
7866 : return true;
7867 : }
7868 :
7869 : /* Return true when RESOLUTION indicate that symbol will be bound to the
7870 : definition provided by current .o file. */
7871 :
7872 : static bool
7873 306737598 : resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution)
7874 : {
7875 306737598 : return (resolution == LDPR_PREVAILING_DEF
7876 306737598 : || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
7877 0 : || resolution == LDPR_PREVAILING_DEF_IRONLY);
7878 : }
7879 :
7880 : /* Return true when RESOLUTION indicate that symbol will be bound locally
7881 : within current executable or DSO. */
7882 :
7883 : static bool
7884 305716344 : resolution_local_p (enum ld_plugin_symbol_resolution resolution)
7885 : {
7886 305716344 : return (resolution == LDPR_PREVAILING_DEF
7887 305716344 : || resolution == LDPR_PREVAILING_DEF_IRONLY
7888 305716344 : || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
7889 : || resolution == LDPR_PREEMPTED_REG
7890 305716344 : || resolution == LDPR_PREEMPTED_IR
7891 : || resolution == LDPR_RESOLVED_IR
7892 611432680 : || resolution == LDPR_RESOLVED_EXEC);
7893 : }
7894 :
7895 : /* COMMON_LOCAL_P is true means that the linker can guarantee that an
7896 : uninitialized common symbol in the executable will still be defined
7897 : (through COPY relocation) in the executable. */
7898 :
7899 : bool
7900 807938118 : default_binds_local_p_3 (const_tree exp, bool shlib, bool weak_dominate,
7901 : bool extern_protected_data, bool common_local_p)
7902 : {
7903 : /* A non-decl is an entry in the constant pool. */
7904 807938118 : if (!DECL_P (exp))
7905 : return true;
7906 :
7907 : /* Weakrefs may not bind locally, even though the weakref itself is always
7908 : static and therefore local. Similarly, the resolver for ifunc functions
7909 : might resolve to a non-local function.
7910 : FIXME: We can resolve the weakref case more carefully by looking at the
7911 : weakref alias. */
7912 804402581 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp))
7913 804402581 : || (!targetm.ifunc_ref_local_ok ()
7914 54904736 : && TREE_CODE (exp) == FUNCTION_DECL
7915 21566917 : && cgraph_node::get (exp)
7916 20527313 : && cgraph_node::get (exp)->ifunc_resolver))
7917 : return false;
7918 :
7919 : /* Static variables are always local. */
7920 804394816 : if (! TREE_PUBLIC (exp))
7921 : return true;
7922 :
7923 : /* With resolution file in hand, take look into resolutions.
7924 : We can't just return true for resolved_locally symbols,
7925 : because dynamic linking might overwrite symbols
7926 : in shared libraries. */
7927 652454168 : bool resolved_locally = false;
7928 :
7929 652454168 : bool uninited_common = (DECL_COMMON (exp)
7930 652454168 : && (DECL_INITIAL (exp) == NULL
7931 236417 : || (!in_lto_p
7932 236417 : && DECL_INITIAL (exp) == error_mark_node)));
7933 :
7934 : /* A non-external variable is defined locally only if it isn't
7935 : uninitialized COMMON variable or common_local_p is true. */
7936 652454168 : bool defined_locally = (!DECL_EXTERNAL (exp)
7937 652454168 : && (!uninited_common || common_local_p));
7938 652454168 : if (symtab_node *node = symtab_node::get (exp))
7939 : {
7940 635098388 : if (node->in_other_partition)
7941 3932 : defined_locally = true;
7942 635098388 : if (node->can_be_discarded_p ())
7943 : ;
7944 306236135 : else if (resolution_to_local_definition_p (node->resolution))
7945 : defined_locally = resolved_locally = true;
7946 305716344 : else if (resolution_local_p (node->resolution))
7947 652454168 : resolved_locally = true;
7948 : }
7949 652454168 : if (defined_locally && weak_dominate && !shlib)
7950 652454168 : resolved_locally = true;
7951 :
7952 : /* Undefined weak symbols are never defined locally. */
7953 652454168 : if (DECL_WEAK (exp) && !defined_locally)
7954 : return false;
7955 :
7956 : /* A symbol is local if the user has said explicitly that it will be,
7957 : or if we have a definition for the symbol. We cannot infer visibility
7958 : for undefined symbols. */
7959 652347805 : if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT
7960 11533164 : && (TREE_CODE (exp) == FUNCTION_DECL
7961 1023625 : || !extern_protected_data
7962 1023577 : || DECL_VISIBILITY (exp) != VISIBILITY_PROTECTED)
7963 663880927 : && (DECL_VISIBILITY_SPECIFIED (exp) || defined_locally))
7964 : return true;
7965 :
7966 : /* If PIC, then assume that any global name can be overridden by
7967 : symbols resolved from other modules. */
7968 646860571 : if (shlib)
7969 : return false;
7970 :
7971 : /* Variables defined outside this object might not be local. */
7972 548917107 : if (DECL_EXTERNAL (exp) && !resolved_locally)
7973 : return false;
7974 :
7975 : /* Non-dominant weak symbols are not defined locally. */
7976 317838642 : if (DECL_WEAK (exp) && !resolved_locally)
7977 : return false;
7978 :
7979 : /* Uninitialized COMMON variable may be unified with symbols
7980 : resolved from other modules. */
7981 317838642 : if (uninited_common && !resolved_locally)
7982 47 : return false;
7983 :
7984 : /* Otherwise we're left with initialized (or non-common) global data
7985 : which is of necessity defined locally. */
7986 : return true;
7987 : }
7988 :
7989 : /* Assume ELF-ish defaults, since that's pretty much the most liberal
7990 : wrt cross-module name binding. */
7991 :
7992 : bool
7993 0 : default_binds_local_p (const_tree exp)
7994 : {
7995 0 : return default_binds_local_p_3 (exp, flag_shlib != 0, true, false, false);
7996 : }
7997 :
7998 : /* Similar to default_binds_local_p, but common symbol may be local and
7999 : extern protected data is non-local. */
8000 :
8001 : bool
8002 0 : default_binds_local_p_2 (const_tree exp)
8003 : {
8004 0 : return default_binds_local_p_3 (exp, flag_shlib != 0, true, true,
8005 0 : !flag_pic);
8006 : }
8007 :
8008 : bool
8009 0 : default_binds_local_p_1 (const_tree exp, int shlib)
8010 : {
8011 0 : return default_binds_local_p_3 (exp, shlib != 0, false, false, false);
8012 : }
8013 :
8014 : /* Return true when references to DECL must bind to current definition in
8015 : final executable.
8016 :
8017 : The condition is usually equivalent to whether the function binds to the
8018 : current module (shared library or executable), that is to binds_local_p.
8019 : We use this fact to avoid need for another target hook and implement
8020 : the logic using binds_local_p and just special cases where
8021 : decl_binds_to_current_def_p is stronger than binds_local_p. In particular
8022 : the weak definitions (that can be overwritten at linktime by other
8023 : definition from different object file) and when resolution info is available
8024 : we simply use the knowledge passed to us by linker plugin. */
8025 : bool
8026 785615168 : decl_binds_to_current_def_p (const_tree decl)
8027 : {
8028 785615168 : gcc_assert (DECL_P (decl));
8029 785615168 : if (!targetm.binds_local_p (decl))
8030 : return false;
8031 465291122 : if (!TREE_PUBLIC (decl))
8032 : return true;
8033 :
8034 : /* When resolution is available, just use it. */
8035 318002490 : if (symtab_node *node = symtab_node::get (decl))
8036 : {
8037 317995017 : if (node->resolution != LDPR_UNKNOWN
8038 317995017 : && !node->can_be_discarded_p ())
8039 501463 : return resolution_to_local_definition_p (node->resolution);
8040 : }
8041 :
8042 : /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
8043 : binds locally but still can be overwritten), DECL_COMMON (can be merged
8044 : with a non-common definition somewhere in the same module) or
8045 : DECL_EXTERNAL.
8046 : This rely on fact that binds_local_p behave as decl_replaceable_p
8047 : for all other declaration types. */
8048 317501027 : if (DECL_WEAK (decl))
8049 : return false;
8050 240903599 : if (DECL_COMDAT_GROUP (decl))
8051 : return false;
8052 240899486 : if (DECL_COMMON (decl)
8053 240899486 : && (DECL_INITIAL (decl) == NULL
8054 6 : || (!in_lto_p && DECL_INITIAL (decl) == error_mark_node)))
8055 : return false;
8056 240026731 : if (DECL_EXTERNAL (decl))
8057 2417936 : return false;
8058 : return true;
8059 : }
8060 :
8061 : /* A replaceable function or variable is one which may be replaced
8062 : at link-time with an entirely different definition, provided that the
8063 : replacement has the same type. For example, functions declared
8064 : with __attribute__((weak)) on most systems are replaceable.
8065 : If SEMANTIC_INTERPOSITION_P is false allow interposition only on
8066 : symbols explicitly declared weak.
8067 :
8068 : COMDAT functions are not replaceable, since all definitions of the
8069 : function must be equivalent. It is important that COMDAT functions
8070 : not be treated as replaceable so that use of C++ template
8071 : instantiations is not penalized. */
8072 :
8073 : bool
8074 241468567 : decl_replaceable_p (tree decl, bool semantic_interposition_p)
8075 : {
8076 241468567 : gcc_assert (DECL_P (decl));
8077 241468567 : if (!TREE_PUBLIC (decl) || DECL_COMDAT (decl))
8078 : return false;
8079 177485083 : if (!semantic_interposition_p
8080 177485083 : && !DECL_WEAK (decl))
8081 : return false;
8082 177294713 : return !decl_binds_to_current_def_p (decl);
8083 : }
8084 :
8085 : /* Default function to output code that will globalize a label. A
8086 : target must define GLOBAL_ASM_OP or provide its own function to
8087 : globalize a label. */
8088 : #ifdef GLOBAL_ASM_OP
8089 : void
8090 2191592 : default_globalize_label (FILE * stream, const char *name)
8091 : {
8092 2191592 : fputs (GLOBAL_ASM_OP, stream);
8093 2191592 : assemble_name (stream, name);
8094 2191592 : putc ('\n', stream);
8095 2191592 : }
8096 : #endif /* GLOBAL_ASM_OP */
8097 :
8098 : /* Default function to output code that will globalize a declaration. */
8099 : void
8100 2160531 : default_globalize_decl_name (FILE * stream, tree decl)
8101 : {
8102 2160531 : const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
8103 2160531 : targetm.asm_out.globalize_label (stream, name);
8104 2160531 : }
8105 :
8106 : /* Default function to output a label for unwind information. The
8107 : default is to do nothing. A target that needs nonlocal labels for
8108 : unwind information must provide its own function to do this. */
8109 : void
8110 52 : default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
8111 : tree decl ATTRIBUTE_UNUSED,
8112 : int for_eh ATTRIBUTE_UNUSED,
8113 : int empty ATTRIBUTE_UNUSED)
8114 : {
8115 52 : }
8116 :
8117 : /* Default function to output a label to divide up the exception table.
8118 : The default is to do nothing. A target that needs/wants to divide
8119 : up the table must provide it's own function to do this. */
8120 : void
8121 79957 : default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
8122 : {
8123 79957 : }
8124 :
8125 : /* This is how to output an internal numbered label where PREFIX is
8126 : the class of label and LABELNO is the number within the class. */
8127 :
8128 : void
8129 4622 : default_generate_internal_label (char *buf, const char *prefix,
8130 : unsigned long labelno)
8131 : {
8132 4622 : ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
8133 4622 : }
8134 :
8135 : /* This is how to output an internal numbered label where PREFIX is
8136 : the class of label and LABELNO is the number within the class. */
8137 :
8138 : void
8139 77475911 : default_internal_label (FILE *stream, const char *prefix,
8140 : unsigned long labelno)
8141 : {
8142 77475911 : char *const buf = (char *) alloca (40 + strlen (prefix));
8143 77475911 : ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
8144 77475911 : ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
8145 77475911 : }
8146 :
8147 :
8148 : /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
8149 :
8150 : void
8151 1285609 : default_asm_declare_constant_name (FILE *file, const char *name,
8152 : const_tree exp ATTRIBUTE_UNUSED,
8153 : HOST_WIDE_INT size ATTRIBUTE_UNUSED)
8154 : {
8155 1285609 : assemble_label (file, name);
8156 1285609 : }
8157 :
8158 : /* This is the default behavior at the beginning of a file. It's
8159 : controlled by two other target-hook toggles. */
8160 : void
8161 281222 : default_file_start (void)
8162 : {
8163 281222 : if (targetm.asm_file_start_app_off
8164 0 : && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
8165 0 : fputs (ASM_APP_OFF, asm_out_file);
8166 :
8167 281222 : if (targetm.asm_file_start_file_directive)
8168 : {
8169 : /* LTO produced units have no meaningful main_input_filename. */
8170 281222 : if (in_lto_p)
8171 13173 : output_file_directive (asm_out_file, "<artificial>");
8172 : else
8173 268049 : output_file_directive (asm_out_file, main_input_filename);
8174 : }
8175 281222 : }
8176 :
8177 : /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
8178 : which emits a special section directive used to indicate whether or
8179 : not this object file needs an executable stack. This is primarily
8180 : a GNU extension to ELF but could be used on other targets. */
8181 :
8182 : int trampolines_created;
8183 :
8184 : void
8185 251787 : file_end_indicate_exec_stack (void)
8186 : {
8187 251787 : unsigned int flags = SECTION_DEBUG;
8188 251787 : if (trampolines_created)
8189 242 : flags |= SECTION_CODE;
8190 :
8191 251787 : switch_to_section (get_section (".note.GNU-stack", flags, NULL));
8192 251787 : }
8193 :
8194 : /* Emit a special section directive to indicate that this object file
8195 : was compiled with -fsplit-stack. This is used to let the linker
8196 : detect calls between split-stack code and non-split-stack code, so
8197 : that it can modify the split-stack code to allocate a sufficiently
8198 : large stack. We emit another special section if there are any
8199 : functions in this file which have the no_split_stack attribute, to
8200 : prevent the linker from warning about being unable to convert the
8201 : functions if they call non-split-stack code. */
8202 :
8203 : void
8204 4712 : file_end_indicate_split_stack (void)
8205 : {
8206 4712 : if (flag_split_stack)
8207 : {
8208 4712 : switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG,
8209 : NULL));
8210 4712 : if (saw_no_split_stack)
8211 399 : switch_to_section (get_section (".note.GNU-no-split-stack",
8212 : SECTION_DEBUG, NULL));
8213 : }
8214 4712 : }
8215 :
8216 : /* Output DIRECTIVE (a C string) followed by a newline. This is used as
8217 : a get_unnamed_section callback. */
8218 :
8219 : void
8220 1830066 : output_section_asm_op (const char *directive)
8221 : {
8222 1830066 : fprintf (asm_out_file, "%s\n", directive);
8223 1830066 : }
8224 :
8225 : /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
8226 : the current section is NEW_SECTION. */
8227 :
8228 : void
8229 102610776 : switch_to_section (section *new_section, tree decl)
8230 : {
8231 102610776 : bool retain_p;
8232 102610776 : if ((new_section->common.flags & SECTION_NAMED)
8233 75008990 : && decl != nullptr
8234 1867659 : && DECL_P (decl)
8235 104478435 : && ((retain_p = !!lookup_attribute ("retain",
8236 1867659 : DECL_ATTRIBUTES (decl)))
8237 1867659 : != !!(new_section->common.flags & SECTION_RETAIN)))
8238 : {
8239 : /* If the SECTION_RETAIN bit doesn't match, switch to a new
8240 : section. */
8241 24 : tree used_decl, no_used_decl;
8242 :
8243 24 : if (retain_p)
8244 : {
8245 12 : new_section->common.flags |= SECTION_RETAIN;
8246 12 : used_decl = decl;
8247 12 : no_used_decl = new_section->named.decl;
8248 : }
8249 : else
8250 : {
8251 12 : new_section->common.flags &= ~(SECTION_RETAIN
8252 : | SECTION_DECLARED);
8253 12 : used_decl = new_section->named.decl;
8254 12 : no_used_decl = decl;
8255 : }
8256 24 : if (no_used_decl != used_decl)
8257 : {
8258 24 : warning (OPT_Wattributes,
8259 : "%+qD without %<retain%> attribute and %qD with "
8260 : "%<retain%> attribute are placed in a section with "
8261 : "the same name", no_used_decl, used_decl);
8262 24 : inform (DECL_SOURCE_LOCATION (used_decl),
8263 : "%qD was declared here", used_decl);
8264 : }
8265 : }
8266 102610752 : else if (in_section == new_section)
8267 : return;
8268 :
8269 5494541 : in_section = new_section;
8270 :
8271 5494541 : switch (SECTION_STYLE (new_section))
8272 : {
8273 3664475 : case SECTION_NAMED:
8274 3664475 : targetm.asm_out.named_section (new_section->named.name,
8275 : new_section->named.common.flags,
8276 : new_section->named.decl);
8277 3664475 : break;
8278 :
8279 1830066 : case SECTION_UNNAMED:
8280 1830066 : new_section->unnamed.callback (new_section->unnamed.data);
8281 1830066 : break;
8282 :
8283 0 : case SECTION_NOSWITCH:
8284 0 : gcc_unreachable ();
8285 5494541 : break;
8286 : }
8287 :
8288 5494541 : new_section->common.flags |= SECTION_DECLARED;
8289 : }
8290 :
8291 : /* If block symbol SYMBOL has not yet been assigned an offset, place
8292 : it at the end of its block. */
8293 :
8294 : void
8295 0 : place_block_symbol (rtx symbol)
8296 : {
8297 0 : unsigned HOST_WIDE_INT size, mask, offset;
8298 0 : class constant_descriptor_rtx *desc;
8299 0 : unsigned int alignment;
8300 0 : struct object_block *block;
8301 0 : tree decl;
8302 :
8303 0 : gcc_assert (SYMBOL_REF_BLOCK (symbol));
8304 0 : if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
8305 : return;
8306 :
8307 : /* Work out the symbol's size and alignment. */
8308 0 : if (CONSTANT_POOL_ADDRESS_P (symbol))
8309 : {
8310 0 : desc = SYMBOL_REF_CONSTANT (symbol);
8311 0 : alignment = desc->align;
8312 0 : size = GET_MODE_SIZE (desc->mode);
8313 : }
8314 0 : else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
8315 : {
8316 0 : decl = SYMBOL_REF_DECL (symbol);
8317 0 : gcc_checking_assert (DECL_IN_CONSTANT_POOL (decl));
8318 0 : alignment = DECL_ALIGN (decl);
8319 0 : size = get_constant_size (DECL_INITIAL (decl));
8320 0 : if ((flag_sanitize & SANITIZE_ADDRESS)
8321 0 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8322 0 : && asan_protect_global (DECL_INITIAL (decl)))
8323 : {
8324 0 : size += asan_red_zone_size (size);
8325 0 : alignment = MAX (alignment,
8326 : ASAN_RED_ZONE_SIZE * BITS_PER_UNIT);
8327 : }
8328 : }
8329 : else
8330 : {
8331 0 : struct symtab_node *snode;
8332 0 : decl = SYMBOL_REF_DECL (symbol);
8333 :
8334 0 : snode = symtab_node::get (decl);
8335 0 : if (snode->alias)
8336 : {
8337 0 : rtx target = DECL_RTL (snode->ultimate_alias_target ()->decl);
8338 :
8339 0 : gcc_assert (MEM_P (target)
8340 : && GET_CODE (XEXP (target, 0)) == SYMBOL_REF
8341 : && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (target, 0)));
8342 0 : target = XEXP (target, 0);
8343 0 : place_block_symbol (target);
8344 0 : SYMBOL_REF_BLOCK_OFFSET (symbol) = SYMBOL_REF_BLOCK_OFFSET (target);
8345 0 : return;
8346 : }
8347 0 : alignment = get_variable_align (decl);
8348 0 : size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
8349 0 : if ((flag_sanitize & SANITIZE_ADDRESS)
8350 0 : && asan_protect_global (decl))
8351 : {
8352 0 : size += asan_red_zone_size (size);
8353 0 : alignment = MAX (alignment,
8354 : ASAN_RED_ZONE_SIZE * BITS_PER_UNIT);
8355 : }
8356 : }
8357 :
8358 : /* Calculate the object's offset from the start of the block. */
8359 0 : block = SYMBOL_REF_BLOCK (symbol);
8360 0 : mask = alignment / BITS_PER_UNIT - 1;
8361 0 : offset = (block->size + mask) & ~mask;
8362 0 : SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
8363 :
8364 : /* Record the block's new alignment and size. */
8365 0 : block->alignment = MAX (block->alignment, alignment);
8366 0 : block->size = offset + size;
8367 :
8368 0 : vec_safe_push (block->objects, symbol);
8369 : }
8370 :
8371 : /* Return the anchor that should be used to address byte offset OFFSET
8372 : from the first object in BLOCK. MODEL is the TLS model used
8373 : to access it. */
8374 :
8375 : rtx
8376 0 : get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
8377 : enum tls_model model)
8378 : {
8379 0 : char label[100];
8380 0 : unsigned int begin, middle, end;
8381 0 : unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
8382 0 : rtx anchor;
8383 :
8384 : /* Work out the anchor's offset. Use an offset of 0 for the first
8385 : anchor so that we don't pessimize the case where we take the address
8386 : of a variable at the beginning of the block. This is particularly
8387 : useful when a block has only one variable assigned to it.
8388 :
8389 : We try to place anchors RANGE bytes apart, so there can then be
8390 : anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
8391 : a ptr_mode offset. With some target settings, the lowest such
8392 : anchor might be out of range for the lowest ptr_mode offset;
8393 : likewise the highest anchor for the highest offset. Use anchors
8394 : at the extreme ends of the ptr_mode range in such cases.
8395 :
8396 : All arithmetic uses unsigned integers in order to avoid
8397 : signed overflow. */
8398 0 : max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
8399 0 : min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
8400 0 : range = max_offset - min_offset + 1;
8401 0 : if (range == 0)
8402 : offset = 0;
8403 : else
8404 : {
8405 0 : bias = HOST_WIDE_INT_1U << (GET_MODE_BITSIZE (ptr_mode) - 1);
8406 0 : if (offset < 0)
8407 : {
8408 0 : delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
8409 0 : delta -= delta % range;
8410 0 : if (delta > bias)
8411 : delta = bias;
8412 0 : offset = (HOST_WIDE_INT) (-delta);
8413 : }
8414 : else
8415 : {
8416 0 : delta = (unsigned HOST_WIDE_INT) offset - min_offset;
8417 0 : delta -= delta % range;
8418 0 : if (delta > bias - 1)
8419 : delta = bias - 1;
8420 0 : offset = (HOST_WIDE_INT) delta;
8421 : }
8422 : }
8423 :
8424 : /* Do a binary search to see if there's already an anchor we can use.
8425 : Set BEGIN to the new anchor's index if not. */
8426 0 : begin = 0;
8427 0 : end = vec_safe_length (block->anchors);
8428 0 : while (begin != end)
8429 : {
8430 0 : middle = (end + begin) / 2;
8431 0 : anchor = (*block->anchors)[middle];
8432 0 : if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
8433 : end = middle;
8434 0 : else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
8435 0 : begin = middle + 1;
8436 0 : else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
8437 : end = middle;
8438 0 : else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
8439 0 : begin = middle + 1;
8440 : else
8441 : return anchor;
8442 : }
8443 :
8444 : /* Create a new anchor with a unique label. */
8445 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
8446 0 : anchor = create_block_symbol (ggc_strdup (label), block, offset);
8447 0 : SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
8448 0 : SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
8449 :
8450 : /* Insert it at index BEGIN. */
8451 0 : vec_safe_insert (block->anchors, begin, anchor);
8452 0 : return anchor;
8453 : }
8454 :
8455 : /* Output the objects in BLOCK. */
8456 :
8457 : static void
8458 0 : output_object_block (struct object_block *block)
8459 : {
8460 0 : class constant_descriptor_rtx *desc;
8461 0 : unsigned int i;
8462 0 : HOST_WIDE_INT offset;
8463 0 : tree decl;
8464 0 : rtx symbol;
8465 :
8466 0 : if (!block->objects)
8467 0 : return;
8468 :
8469 : /* Switch to the section and make sure that the first byte is
8470 : suitably aligned. */
8471 : /* Special case VTV comdat sections similar to assemble_variable. */
8472 0 : if (SECTION_STYLE (block->sect) == SECTION_NAMED
8473 0 : && block->sect->named.name
8474 0 : && (strcmp (block->sect->named.name, ".vtable_map_vars") == 0))
8475 0 : handle_vtv_comdat_section (block->sect, block->sect->named.decl);
8476 : else
8477 0 : switch_to_section (block->sect, SYMBOL_REF_DECL ((*block->objects)[0]));
8478 :
8479 0 : gcc_checking_assert (!(block->sect->common.flags & SECTION_MERGE));
8480 0 : assemble_align (block->alignment);
8481 :
8482 : /* Define the values of all anchors relative to the current section
8483 : position. */
8484 0 : FOR_EACH_VEC_SAFE_ELT (block->anchors, i, symbol)
8485 0 : targetm.asm_out.output_anchor (symbol);
8486 :
8487 : /* Output the objects themselves. */
8488 : offset = 0;
8489 0 : FOR_EACH_VEC_ELT (*block->objects, i, symbol)
8490 : {
8491 : /* Move to the object's offset, padding with zeros if necessary. */
8492 0 : assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
8493 0 : offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
8494 0 : if (CONSTANT_POOL_ADDRESS_P (symbol))
8495 : {
8496 0 : desc = SYMBOL_REF_CONSTANT (symbol);
8497 : /* Pass 1 for align as we have already laid out everything in the block.
8498 : So aligning shouldn't be necessary. */
8499 0 : output_constant_pool_1 (desc, 1);
8500 0 : offset += GET_MODE_SIZE (desc->mode);
8501 : }
8502 0 : else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
8503 : {
8504 0 : HOST_WIDE_INT size;
8505 0 : decl = SYMBOL_REF_DECL (symbol);
8506 0 : assemble_constant_contents (DECL_INITIAL (decl), XSTR (symbol, 0),
8507 0 : DECL_ALIGN (decl), false);
8508 :
8509 0 : size = get_constant_size (DECL_INITIAL (decl));
8510 0 : offset += size;
8511 0 : if ((flag_sanitize & SANITIZE_ADDRESS)
8512 0 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8513 0 : && asan_protect_global (DECL_INITIAL (decl)))
8514 : {
8515 0 : size = asan_red_zone_size (size);
8516 0 : assemble_zeros (size);
8517 0 : offset += size;
8518 : }
8519 : }
8520 : else
8521 : {
8522 0 : HOST_WIDE_INT size;
8523 0 : decl = SYMBOL_REF_DECL (symbol);
8524 0 : assemble_variable_contents (decl, XSTR (symbol, 0), false, false);
8525 0 : size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
8526 0 : offset += size;
8527 0 : if ((flag_sanitize & SANITIZE_ADDRESS)
8528 0 : && asan_protect_global (decl))
8529 : {
8530 0 : size = asan_red_zone_size (size);
8531 0 : assemble_zeros (size);
8532 0 : offset += size;
8533 : }
8534 : }
8535 : }
8536 : }
8537 :
8538 : /* A callback for qsort to compare object_blocks. */
8539 :
8540 : static int
8541 0 : output_object_block_compare (const void *x, const void *y)
8542 : {
8543 0 : object_block *p1 = *(object_block * const*)x;
8544 0 : object_block *p2 = *(object_block * const*)y;
8545 :
8546 0 : if (p1->sect->common.flags & SECTION_NAMED
8547 0 : && !(p2->sect->common.flags & SECTION_NAMED))
8548 : return 1;
8549 :
8550 0 : if (!(p1->sect->common.flags & SECTION_NAMED)
8551 0 : && p2->sect->common.flags & SECTION_NAMED)
8552 : return -1;
8553 :
8554 0 : if (p1->sect->common.flags & SECTION_NAMED
8555 0 : && p2->sect->common.flags & SECTION_NAMED)
8556 0 : return strcmp (p1->sect->named.name, p2->sect->named.name);
8557 :
8558 0 : unsigned f1 = p1->sect->common.flags;
8559 0 : unsigned f2 = p2->sect->common.flags;
8560 0 : if (f1 == f2)
8561 : return 0;
8562 0 : return f1 < f2 ? -1 : 1;
8563 : }
8564 :
8565 : /* Output the definitions of all object_blocks. */
8566 :
8567 : void
8568 239445 : output_object_blocks (void)
8569 : {
8570 239445 : vec<object_block *, va_heap> v;
8571 239445 : v.create (object_block_htab->elements ());
8572 239445 : object_block *obj;
8573 239445 : hash_table<object_block_hasher>::iterator hi;
8574 :
8575 239445 : FOR_EACH_HASH_TABLE_ELEMENT (*object_block_htab, obj, object_block *, hi)
8576 0 : v.quick_push (obj);
8577 :
8578 : /* Sort them in order to output them in a deterministic manner,
8579 : otherwise we may get .rodata sections in different orders with
8580 : and without -g. */
8581 239445 : v.qsort (output_object_block_compare);
8582 239445 : unsigned i;
8583 239445 : FOR_EACH_VEC_ELT (v, i, obj)
8584 0 : output_object_block (obj);
8585 :
8586 239445 : v.release ();
8587 239445 : }
8588 :
8589 : /* This function provides a possible implementation of the
8590 : TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
8591 : by -frecord-gcc-switches it creates a new mergeable, string section in the
8592 : assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
8593 : contains the switches in ASCII format.
8594 :
8595 : FIXME: This code does not correctly handle double quote characters
8596 : that appear inside strings, (it strips them rather than preserving them).
8597 : FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
8598 : characters - instead it treats them as sub-string separators. Since
8599 : we want to emit NUL strings terminators into the object file we have to use
8600 : ASM_OUTPUT_SKIP. */
8601 :
8602 : void
8603 0 : elf_record_gcc_switches (const char *options)
8604 : {
8605 0 : section *sec = get_section (targetm.asm_out.record_gcc_switches_section,
8606 : SECTION_DEBUG | SECTION_MERGE
8607 : | SECTION_STRINGS | (SECTION_ENTSIZE & 1), NULL);
8608 0 : switch_to_section (sec);
8609 0 : ASM_OUTPUT_ASCII (asm_out_file, options, strlen (options) + 1);
8610 0 : }
8611 :
8612 : /* Emit text to declare externally defined symbols. It is needed to
8613 : properly support non-default visibility. */
8614 : void
8615 1826457 : default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
8616 : tree decl,
8617 : const char *name ATTRIBUTE_UNUSED)
8618 : {
8619 : /* We output the name if and only if TREE_SYMBOL_REFERENCED is
8620 : set in order to avoid putting out names that are never really
8621 : used. Always output visibility specified in the source. */
8622 1826457 : if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
8623 1826457 : && (DECL_VISIBILITY_SPECIFIED (decl)
8624 1619975 : || targetm.binds_local_p (decl)))
8625 196106 : maybe_assemble_visibility (decl);
8626 1826457 : }
8627 :
8628 : /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
8629 :
8630 : void
8631 281222 : default_asm_output_source_filename (FILE *file, const char *name)
8632 : {
8633 : #ifdef ASM_OUTPUT_SOURCE_FILENAME
8634 : ASM_OUTPUT_SOURCE_FILENAME (file, name);
8635 : #else
8636 281222 : fprintf (file, "\t.file\t");
8637 281222 : output_quoted_string (file, name);
8638 281222 : putc ('\n', file);
8639 : #endif
8640 281222 : }
8641 :
8642 : /* Output a file name in the form wanted by System V. */
8643 :
8644 : void
8645 281222 : output_file_directive (FILE *asm_file, const char *input_name)
8646 : {
8647 281222 : int len;
8648 281222 : const char *na;
8649 :
8650 281222 : if (input_name == NULL)
8651 : input_name = "<stdin>";
8652 : else
8653 281222 : input_name = remap_debug_filename (input_name);
8654 :
8655 281222 : len = strlen (input_name);
8656 281222 : na = input_name + len;
8657 :
8658 : /* NA gets INPUT_NAME sans directory names. */
8659 4027427 : while (na > input_name)
8660 : {
8661 3997421 : if (IS_DIR_SEPARATOR (na[-1]))
8662 : break;
8663 3746205 : na--;
8664 : }
8665 :
8666 281222 : targetm.asm_out.output_source_filename (asm_file, na);
8667 281222 : }
8668 :
8669 : /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
8670 : EXP. */
8671 : rtx
8672 303427 : make_debug_expr_from_rtl (const_rtx exp)
8673 : {
8674 303427 : tree ddecl = make_node (DEBUG_EXPR_DECL), type;
8675 303427 : machine_mode mode = GET_MODE (exp);
8676 303427 : rtx dval;
8677 :
8678 303427 : DECL_ARTIFICIAL (ddecl) = 1;
8679 303427 : if (REG_P (exp) && REG_EXPR (exp))
8680 243881 : type = TREE_TYPE (REG_EXPR (exp));
8681 64261 : else if (MEM_P (exp) && MEM_EXPR (exp))
8682 4715 : type = TREE_TYPE (MEM_EXPR (exp));
8683 : else
8684 : type = NULL_TREE;
8685 248596 : if (type && TYPE_MODE (type) == mode)
8686 198481 : TREE_TYPE (ddecl) = type;
8687 : else
8688 104946 : TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
8689 303427 : SET_DECL_MODE (ddecl, mode);
8690 303427 : dval = gen_rtx_DEBUG_EXPR (mode);
8691 303427 : DEBUG_EXPR_TREE_DECL (dval) = ddecl;
8692 303427 : SET_DECL_RTL (ddecl, dval);
8693 303427 : return dval;
8694 : }
8695 :
8696 : #ifdef ELF_ASCII_ESCAPES
8697 : /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
8698 :
8699 : void
8700 26771612 : default_elf_asm_output_limited_string (FILE *f, const char *s)
8701 : {
8702 26771612 : int escape;
8703 26771612 : unsigned char c;
8704 :
8705 26771612 : fputs (STRING_ASM_OP "\"", f);
8706 845906251 : while (*s != '\0')
8707 : {
8708 792363027 : c = *s;
8709 792363027 : escape = ELF_ASCII_ESCAPES[c];
8710 792363027 : switch (escape)
8711 : {
8712 792131671 : case 0:
8713 792131671 : putc (c, f);
8714 792131671 : break;
8715 118084 : case 1:
8716 118084 : putc ('\\', f);
8717 118084 : putc ('0'+((c>>6)&7), f);
8718 118084 : putc ('0'+((c>>3)&7), f);
8719 118084 : putc ('0'+(c&7), f);
8720 118084 : break;
8721 113272 : default:
8722 113272 : putc ('\\', f);
8723 113272 : putc (escape, f);
8724 113272 : break;
8725 : }
8726 792363027 : s++;
8727 : }
8728 26771612 : putc ('\"', f);
8729 26771612 : putc ('\n', f);
8730 26771612 : }
8731 :
8732 : /* Default ASM_OUTPUT_ASCII for ELF targets. */
8733 :
8734 : void
8735 37030363 : default_elf_asm_output_ascii (FILE *f, const char *s, unsigned int len)
8736 : {
8737 37030363 : const char *limit = s + len;
8738 37030363 : const char *last_null = NULL;
8739 37030363 : const char *last_base64 = s;
8740 37030363 : unsigned bytes_in_chunk = 0;
8741 37030363 : unsigned char c;
8742 37030363 : int escape;
8743 37030363 : bool prev_base64 = false;
8744 :
8745 305749674 : for (; s < limit; s++)
8746 : {
8747 268719311 : const char *p;
8748 :
8749 268719311 : if (bytes_in_chunk >= 60)
8750 : {
8751 3393010 : putc ('\"', f);
8752 3393010 : putc ('\n', f);
8753 3393010 : bytes_in_chunk = 0;
8754 : }
8755 :
8756 268719311 : if ((uintptr_t) s > (uintptr_t) last_null)
8757 : {
8758 1126692022 : for (p = s; p < limit && *p != '\0'; p++)
8759 1089338122 : continue;
8760 : last_null = p;
8761 : }
8762 : else
8763 : p = last_null;
8764 :
8765 : #if defined(BASE64_ASM_OP) \
8766 : && BITS_PER_UNIT == 8 \
8767 : && CHAR_BIT == 8 \
8768 : && 'A' == 65 \
8769 : && 'a' == 97 \
8770 : && '0' == 48 \
8771 : && '+' == 43 \
8772 : && '/' == 47 \
8773 : && '=' == 61
8774 268719311 : if (s >= last_base64)
8775 : {
8776 : unsigned cnt = 0;
8777 : unsigned char prev_c = ' ';
8778 : const char *t;
8779 1188778347 : for (t = s; t < limit && (t - s) < (long) ELF_STRING_LIMIT - 1; t++)
8780 : {
8781 1175371981 : if (t == p && t != s)
8782 : {
8783 25875116 : if (cnt <= ((unsigned) (t - s) + 1 + 2) / 3 * 4
8784 24901253 : && (!prev_base64 || (t - s) >= 16)
8785 24895654 : && ((t - s) > 1 || cnt <= 2))
8786 : {
8787 24802584 : last_base64 = p;
8788 24802584 : goto no_base64;
8789 : }
8790 : }
8791 1150569397 : c = *t;
8792 1150569397 : escape = ELF_ASCII_ESCAPES[c];
8793 1150569397 : switch (escape)
8794 : {
8795 1058540789 : case 0:
8796 1058540789 : ++cnt;
8797 1058540789 : break;
8798 86726038 : case 1:
8799 86726038 : if (c == 0)
8800 : {
8801 11089846 : if (prev_c == 0
8802 5740507 : && t + 1 < limit
8803 4878698 : && (t + 1 - s) < (long) ELF_STRING_LIMIT - 1)
8804 : break;
8805 6213162 : cnt += 2 + strlen (STRING_ASM_OP) + 1;
8806 : }
8807 : else
8808 75636192 : cnt += 4;
8809 : break;
8810 5302570 : default:
8811 5302570 : cnt += 2;
8812 5302570 : break;
8813 : }
8814 1150569397 : prev_c = c;
8815 : }
8816 13406366 : if (cnt > ((unsigned) (t - s) + 2) / 3 * 4 && (t - s) >= 3)
8817 : {
8818 1810646 : if (bytes_in_chunk > 0)
8819 : {
8820 576 : putc ('\"', f);
8821 576 : putc ('\n', f);
8822 576 : bytes_in_chunk = 0;
8823 : }
8824 :
8825 1810646 : unsigned char buf[(ELF_STRING_LIMIT + 2) / 3 * 4 + 3];
8826 1810646 : unsigned j = 0;
8827 1810646 : static const char base64_enc[] =
8828 : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
8829 : "0123456789+/";
8830 :
8831 1810646 : fputs (BASE64_ASM_OP "\"", f);
8832 46695118 : while (s < t)
8833 : {
8834 44384179 : unsigned char a = *s;
8835 44384179 : unsigned char b = 0, c = 0;
8836 44384179 : if (s < t - 1)
8837 43793246 : b = s[1];
8838 44384179 : if (s < t - 2)
8839 43073826 : c = s[2];
8840 44384179 : unsigned long v = ((((unsigned long) a) << 16)
8841 44384179 : | (((unsigned long) b) << 8)
8842 44384179 : | c);
8843 44384179 : buf[j++] = base64_enc[(v >> 18) & 63];
8844 44384179 : buf[j++] = base64_enc[(v >> 12) & 63];
8845 44384179 : buf[j++] = base64_enc[(v >> 6) & 63];
8846 44384179 : buf[j++] = base64_enc[v & 63];
8847 44384179 : if (s >= t - 2)
8848 : {
8849 1310353 : buf[j - 1] = '=';
8850 1310353 : if (s >= t - 1)
8851 590933 : buf[j - 2] = '=';
8852 : break;
8853 : }
8854 43073826 : s += 3;
8855 : }
8856 1810646 : memcpy (buf + j, "\"\n", 3);
8857 1810646 : fputs ((const char *) buf, f);
8858 1810646 : s = t - 1;
8859 1810646 : prev_base64 = true;
8860 1810646 : continue;
8861 1810646 : }
8862 : last_base64 = t;
8863 266908665 : no_base64:
8864 : prev_base64 = false;
8865 : }
8866 : #else
8867 : (void) last_base64;
8868 : (void) prev_base64;
8869 : #endif
8870 :
8871 266908665 : if (p < limit && (p - s) <= (long) ELF_STRING_LIMIT)
8872 : {
8873 26773429 : if (bytes_in_chunk > 0)
8874 : {
8875 217163 : putc ('\"', f);
8876 217163 : putc ('\n', f);
8877 217163 : bytes_in_chunk = 0;
8878 : }
8879 :
8880 26773429 : if (p == s && p + 1 < limit && p[1] == '\0')
8881 : {
8882 35739 : for (p = s + 2; p < limit && *p == '\0'; p++)
8883 33922 : continue;
8884 1817 : ASM_OUTPUT_SKIP (f, (unsigned HOST_WIDE_INT) (p - s));
8885 1817 : s = p - 1;
8886 : }
8887 : else
8888 : {
8889 26771612 : default_elf_asm_output_limited_string (f, s);
8890 26771612 : s = p;
8891 : }
8892 : }
8893 : else
8894 : {
8895 240135236 : if (bytes_in_chunk == 0)
8896 12503154 : fputs (ASCII_DATA_ASM_OP "\"", f);
8897 :
8898 240135236 : c = *s;
8899 240135236 : escape = ELF_ASCII_ESCAPES[c];
8900 240135236 : switch (escape)
8901 : {
8902 237362114 : case 0:
8903 237362114 : putc (c, f);
8904 237362114 : bytes_in_chunk++;
8905 237362114 : break;
8906 1070873 : case 1:
8907 1070873 : putc ('\\', f);
8908 1070873 : putc ('0'+((c>>6)&7), f);
8909 1070873 : putc ('0'+((c>>3)&7), f);
8910 1070873 : putc ('0'+(c&7), f);
8911 1070873 : bytes_in_chunk += 4;
8912 1070873 : break;
8913 1702249 : default:
8914 1702249 : putc ('\\', f);
8915 1702249 : putc (escape, f);
8916 1702249 : bytes_in_chunk += 2;
8917 1702249 : break;
8918 : }
8919 :
8920 : }
8921 : }
8922 :
8923 37030363 : if (bytes_in_chunk > 0)
8924 : {
8925 8892405 : putc ('\"', f);
8926 8892405 : putc ('\n', f);
8927 : }
8928 37030363 : }
8929 : #endif
8930 :
8931 : static GTY(()) section *elf_init_array_section;
8932 : static GTY(()) section *elf_fini_array_section;
8933 :
8934 : static section *
8935 25008 : get_elf_initfini_array_priority_section (int priority,
8936 : bool constructor_p)
8937 : {
8938 25008 : section *sec;
8939 25008 : if (priority != DEFAULT_INIT_PRIORITY)
8940 : {
8941 5030 : char buf[18];
8942 5030 : sprintf (buf, "%s.%.5u",
8943 : constructor_p ? ".init_array" : ".fini_array",
8944 : priority);
8945 5030 : sec = get_section (buf, SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
8946 : }
8947 : else
8948 : {
8949 19978 : if (constructor_p)
8950 : {
8951 19919 : if (elf_init_array_section == NULL)
8952 19090 : elf_init_array_section
8953 19090 : = get_section (".init_array",
8954 : SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
8955 19919 : sec = elf_init_array_section;
8956 : }
8957 : else
8958 : {
8959 59 : if (elf_fini_array_section == NULL)
8960 51 : elf_fini_array_section
8961 51 : = get_section (".fini_array",
8962 : SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
8963 59 : sec = elf_fini_array_section;
8964 : }
8965 : }
8966 25008 : return sec;
8967 : }
8968 :
8969 : /* Use .init_array section for constructors. */
8970 :
8971 : void
8972 23347 : default_elf_init_array_asm_out_constructor (rtx symbol, int priority)
8973 : {
8974 23347 : section *sec = get_elf_initfini_array_priority_section (priority,
8975 : true);
8976 23347 : assemble_addr_to_section (symbol, sec);
8977 23347 : }
8978 :
8979 : /* Use .fini_array section for destructors. */
8980 :
8981 : void
8982 1661 : default_elf_fini_array_asm_out_destructor (rtx symbol, int priority)
8983 : {
8984 1661 : section *sec = get_elf_initfini_array_priority_section (priority,
8985 : false);
8986 1661 : assemble_addr_to_section (symbol, sec);
8987 1661 : }
8988 :
8989 : /* Default TARGET_ASM_OUTPUT_IDENT hook.
8990 :
8991 : This is a bit of a cheat. The real default is a no-op, but this
8992 : hook is the default for all targets with a .ident directive. */
8993 :
8994 : void
8995 243678 : default_asm_output_ident_directive (const char *ident_str)
8996 : {
8997 243678 : const char *ident_asm_op = "\t.ident\t";
8998 :
8999 : /* If we are still in the front end, do not write out the string
9000 : to asm_out_file. Instead, add a fake top-level asm statement.
9001 : This allows the front ends to use this hook without actually
9002 : writing to asm_out_file, to handle #ident or Pragma Ident. */
9003 243678 : if (symtab->state == PARSING)
9004 : {
9005 27 : char *buf = ACONCAT ((ident_asm_op, "\"", ident_str, "\"\n", NULL));
9006 27 : symtab->finalize_toplevel_asm (build_string (strlen (buf), buf));
9007 : }
9008 : else
9009 243651 : fprintf (asm_out_file, "%s\"%s\"\n", ident_asm_op, ident_str);
9010 243678 : }
9011 :
9012 : /* Switch to a COMDAT section with COMDAT name of decl.
9013 :
9014 : FIXME: resolve_unique_section needs to deal better with
9015 : decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
9016 : that is fixed, this if-else statement can be replaced with
9017 : a single call to "switch_to_section (sect)". */
9018 :
9019 : void
9020 15 : switch_to_comdat_section (section *sect, tree decl)
9021 : {
9022 : #if defined (OBJECT_FORMAT_ELF)
9023 15 : targetm.asm_out.named_section (sect->named.name,
9024 15 : sect->named.common.flags
9025 : | SECTION_LINKONCE,
9026 : decl);
9027 15 : in_section = sect;
9028 : #else
9029 : /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
9030 : Therefore the following check is used.
9031 : In case a the target is PE or COFF a comdat group section
9032 : is created, e.g. .vtable_map_vars$foo. The linker places
9033 : everything in .vtable_map_vars at the end.
9034 :
9035 : A fix could be made in
9036 : gcc/config/i386/winnt.cc: mingw_pe_unique_section. */
9037 : if (TARGET_PECOFF)
9038 : {
9039 : char *name;
9040 :
9041 : if (TREE_CODE (decl) == IDENTIFIER_NODE)
9042 : name = ACONCAT ((sect->named.name, "$",
9043 : IDENTIFIER_POINTER (decl), NULL));
9044 : else
9045 : name = ACONCAT ((sect->named.name, "$",
9046 : IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)),
9047 : NULL));
9048 :
9049 : targetm.asm_out.named_section (name,
9050 : sect->named.common.flags
9051 : | SECTION_LINKONCE,
9052 : decl);
9053 : in_section = sect;
9054 : }
9055 : else
9056 : switch_to_section (sect);
9057 : #endif
9058 15 : }
9059 :
9060 : /* This function ensures that vtable_map variables are not only
9061 : in the comdat section, but that each variable has its own unique
9062 : comdat name. Without this the variables end up in the same section
9063 : with a single comdat name. */
9064 :
9065 : static void
9066 3 : handle_vtv_comdat_section (section *sect, const_tree decl ATTRIBUTE_UNUSED)
9067 : {
9068 3 : switch_to_comdat_section(sect, DECL_NAME (decl));
9069 3 : }
9070 :
9071 : void
9072 266934 : varasm_cc_finalize ()
9073 : {
9074 266934 : first_global_object_name = nullptr;
9075 266934 : weak_global_object_name = nullptr;
9076 :
9077 266934 : const_labelno = 0;
9078 266934 : size_directive_output = 0;
9079 :
9080 266934 : last_assemble_variable_decl = NULL_TREE;
9081 266934 : first_function_block_is_cold = false;
9082 266934 : saw_no_split_stack = false;
9083 266934 : text_section = nullptr;
9084 266934 : data_section = nullptr;
9085 266934 : readonly_data_section = nullptr;
9086 266934 : sdata_section = nullptr;
9087 266934 : ctors_section = nullptr;
9088 266934 : dtors_section = nullptr;
9089 266934 : bss_section = nullptr;
9090 266934 : sbss_section = nullptr;
9091 266934 : tls_comm_section = nullptr;
9092 266934 : comm_section = nullptr;
9093 266934 : lcomm_section = nullptr;
9094 266934 : bss_noswitch_section = nullptr;
9095 266934 : exception_section = nullptr;
9096 266934 : eh_frame_section = nullptr;
9097 266934 : in_section = nullptr;
9098 266934 : in_cold_section_p = false;
9099 266934 : cold_function_name = NULL_TREE;
9100 266934 : unnamed_sections = nullptr;
9101 266934 : section_htab = nullptr;
9102 266934 : object_block_htab = nullptr;
9103 266934 : anchor_labelno = 0;
9104 266934 : shared_constant_pool = nullptr;
9105 266934 : pending_assemble_externals = NULL_TREE;
9106 266934 : pending_libcall_symbols = nullptr;
9107 :
9108 : #ifdef ASM_OUTPUT_EXTERNAL
9109 266934 : pending_assemble_externals_processed = false;
9110 287947 : delete pending_assemble_externals_set;
9111 266934 : pending_assemble_externals_set = nullptr;
9112 : #endif
9113 :
9114 266934 : weak_decls = NULL_TREE;
9115 266934 : initial_trampoline = nullptr;
9116 266934 : const_desc_htab = nullptr;
9117 266934 : weakref_targets = NULL_TREE;
9118 266934 : alias_pairs = nullptr;
9119 266934 : tm_clone_hash = nullptr;
9120 266934 : trampolines_created = 0;
9121 266934 : elf_init_array_section = nullptr;
9122 266934 : elf_fini_array_section = nullptr;
9123 266934 : }
9124 :
9125 : #include "gt-varasm.h"
|